Browse Source

remove comments

pull/2/head
Muhammad Sulaiman Yusuf 2 years ago
parent
commit
783d75fcd1
  1. 344
      src/views/Master/ConfigAlert/index.js
  2. 309
      src/views/Master/MasterBroadcast/index.js
  3. 124
      src/views/Master/MasterMenu/index.js
  4. 921
      src/views/Master/MasterRoles/index.js
  5. 765
      src/views/Master/RoleProject/index.js
  6. 53
      src/views/SimproV2/ChecklistK3/index.js
  7. 167
      src/views/SimproV2/Closing/index.js
  8. 13
      src/views/SimproV2/ControlMonitoring/index.js
  9. 141
      src/views/SimproV2/CreatedProyek/index.js
  10. 674
      src/views/SimproV2/Divisi/index.js
  11. 105
      src/views/SimproV2/PanicButton/index.js
  12. 770
      src/views/SimproV2/ProjectType/index.js
  13. 100
      src/views/SimproV2/ResourceMaterial/index.js
  14. 80
      src/views/SimproV2/ResourceTools/index.js
  15. 117
      src/views/SimproV2/ResourceWorker/index.js
  16. 669
      src/views/SimproV2/Satuan/index.js

344
src/views/Master/ConfigAlert/index.js

@ -1,194 +1,172 @@
import Bell from '@iconify/icons-ion/notifications-outline';
import BellOff from '@iconify/icons-ion/notifications-off-outline';
import React, { useState, useEffect } from 'react'; import React, { useState, useEffect } from 'react';
import { Card, CardBody, CardHeader, Input } from 'reactstrap';
import axios from 'axios'; import axios from 'axios';
import { NotificationContainer, NotificationManager } from 'react-notifications';
import { Card as ACard,Row, Col, Switch } from 'antd';
import { CALERTUSER_SEARCH,CONFIGALERT_SEARCH,CALERTUSER_DELETE, CALERTUSER_ADD } from '../../../const/ApiConst.js'; import { CALERTUSER_SEARCH,CONFIGALERT_SEARCH,CALERTUSER_DELETE, CALERTUSER_ADD } from '../../../const/ApiConst.js';
import { Card as ACard,Row, Col, Switch } from 'antd';
import { Card, CardBody, CardHeader, Input } from 'reactstrap';
import { Icon } from '@iconify/react'; import { Icon } from '@iconify/react';
import Bell from '@iconify/icons-ion/notifications-outline'; import { NotificationContainer, NotificationManager } from 'react-notifications';
import BellOff from '@iconify/icons-ion/notifications-off-outline';
const token = window.localStorage.getItem('token'); const token = window.localStorage.getItem('token');
const userID = window.localStorage.getItem('user_id'); const userID = window.localStorage.getItem('user_id');
const Index = ({params}) => { const Index = ({params}) => {
const [dataTable, setDatatable] = useState([])
const [alertUser, setAlertUser] = useState([]) const [alertUser, setAlertUser] = useState([])
const [checked, setChecked] = useState({}) const [checked, setChecked] = useState({})
const [onSetSwitch, setOnSetSwitch] = useState(false) const [dataTable, setDatatable] = useState([])
const pageName = params.name; const [onSetSwitch, setOnSetSwitch] = useState(false)
const pageName = params.name;
const config = {
headers: const config = {
{ headers:
Authorization : `Bearer ${token}`, {
"Content-type" : `application/json` Authorization : `Bearer ${token}`,
} "Content-type" : `application/json`
}; }
};
useEffect(()=> { useEffect(()=> {
getDataConfigAlert(); getDataConfigAlert();
// getDataConfigAlertUser(); },[])
},[])
useEffect(() => {
useEffect(() => { getDataConfigAlertUser();
getDataConfigAlertUser(); },[dataTable])
},[dataTable])
const getDataConfigAlert = async () => {
const payload = {
"paging": {"start": 0, "length": -1},
const getDataConfigAlert = async () => { "columns": [
const payload = { {"name": "nama", "logic_operator": "like", "value": "", "operator": "AND"}
"paging": {"start": 0, "length": -1}, ],
"columns": [ "joins": [],
{"name": "nama", "logic_operator": "like", "value": "", "operator": "AND"} "orders": {"columns": ["id"], "ascending": false}
], }
"joins": [],
"orders": {"columns": ["id"], "ascending": false} const result = await axios
} .post(CONFIGALERT_SEARCH, payload, config)
.then(res => res)
.catch((error) => error.response);
const result = await axios if(result && result.data && result.data.code == 200){
.post(CONFIGALERT_SEARCH, payload, config) let resData = result.data.data
.then(res => res) let checkedAlert = {}
.catch((error) => error.response); resData.map((val, index) => {
checkedAlert[val.id] = false
// console.log(result) });
setChecked(checkedAlert);
if(result && result.data && result.data.code == 200){ setDatatable(resData);
let resData = result.data.data }else{
let checkedAlert = {} NotificationManager.error('Gagal Mengambil Data!!', 'Failed');
resData.map((val, index) => { }
checkedAlert[val.id] = false }
});
setChecked(checkedAlert); const getDataConfigAlertUser = async () => {
setDatatable(resData); const payload = {
// getDataConfigAlertUser(); "paging": {"start": 0, "length": -1},
}else{ "columns": [
NotificationManager.error('Gagal Mengambil Data!!', 'Failed'); {"name": "user_id", "logic_operator": "=", "value": localStorage.getItem('user_id'), "operator": "AND"}
} ],
} "joins": [],
"orders": {"columns": ["id"], "ascending": false}
const getDataConfigAlertUser = async () => { }
const payload = {
"paging": {"start": 0, "length": -1}, const result = await axios
"columns": [ .post(CALERTUSER_SEARCH, payload, config)
{"name": "user_id", "logic_operator": "=", "value": localStorage.getItem('user_id'), "operator": "AND"} .then(res => res)
], .catch((error) => error.response);
"joins": [],
"orders": {"columns": ["id"], "ascending": false} if(result && result.data && result.data.code == 200){
} let resData = result.data.data
let configAlert = [];
const result = await axios resData.map((val, index) => {
.post(CALERTUSER_SEARCH, payload, config) configAlert.push(val.config_alert_id);
.then(res => res) let indexRes = dataTable.findIndex(x => x.id === val.config_alert_id);
.catch((error) => error.response); if(indexRes >= 0){
let id = dataTable[indexRes].id;
let tempChecked = checked;
tempChecked[id] = true;
if(result && result.data && result.data.code == 200){ setChecked(tempChecked);
let resData = result.data.data }
// console.log("resData", resData) });
// console.log("dataTable", dataTable) window.localStorage.setItem('userConfigAlert', configAlert.join());
let configAlert = []; setOnSetSwitch(false)
resData.map((val, index) => { setAlertUser(result.data.data);
configAlert.push(val.config_alert_id); }else{
let indexRes = dataTable.findIndex(x => x.id === val.config_alert_id); NotificationManager.error('Gagal Mengambil Data!!', 'Failed');
// console.log("indexRes", indexRes) }
if(indexRes >= 0){ }
let id = dataTable[indexRes].id;
let tempChecked = checked; const onChange = (checked, id) => {
tempChecked[id] = true; setOnSetSwitch(true)
// console.log("tempChecked", tempChecked) if(checked){
setChecked(tempChecked); addConfigAlertUser(id);
} }else{
}); setDeleteConfigAlertUser(id)
window.localStorage.setItem('userConfigAlert', configAlert.join()); }
console.log("configAlert.join()", configAlert.join()) }
setOnSetSwitch(false)
setAlertUser(result.data.data); const addConfigAlertUser = async (id) => {
}else{ const formData = {
NotificationManager.error('Gagal Mengambil Data!!', 'Failed'); "user_id":parseInt(localStorage.getItem('user_id')),
} "config_alert_id":id
} }
const onChange = (checked, id) => { const result = await axios.post(CALERTUSER_ADD, formData, config)
setOnSetSwitch(true) .then(res => res)
// console.log(`switch to ${checked} ${id}`); .catch((error) => error.response);
if(checked){
addConfigAlertUser(id); if(result && result.data && result.data.code===200){
}else{ getDataConfigAlertUser();
setDeleteConfigAlertUser(id) }
} }
}
const setDeleteConfigAlertUser = async (id) => {
const addConfigAlertUser = async (id) => { let indexCek = alertUser.findIndex(x => x.user_id === parseInt(localStorage.getItem('user_id')) && x.config_alert_id === id);
const formData = { if(indexCek >= 0){
"user_id":parseInt(localStorage.getItem('user_id')), let idAlert = alertUser[indexCek].id
"config_alert_id":id deleteConfigAlertUser(idAlert)
} }
}
const result = await axios.post(CALERTUSER_ADD, formData, config)
.then(res => res) const deleteConfigAlertUser = async (id) => {
.catch((error) => error.response); const url = CALERTUSER_DELETE(id)
const result = await axios.delete(url, config)
if(result && result.data && result.data.code===200){ .then(res => res)
getDataConfigAlertUser(); .catch((error) => error.response);
// NotificationManager.success(`Data menu berhasil ditambah`, 'Success!!'); if (result && result.data && result.data.code === 200) {
} getDataConfigAlert();
} }
}
const setDeleteConfigAlertUser = async (id) => {
let indexCek = alertUser.findIndex(x => x.user_id === parseInt(localStorage.getItem('user_id')) && x.config_alert_id === id); return (
// console.log("cekcekckecke", indexCek) <div>
if(indexCek >= 0){ <NotificationContainer />
let idAlert = alertUser[indexCek].id <Card>
// console.log("cek idAlert", idAlert); <CardHeader style={{ display: "flex", justifyContent: "space-between" }}>
deleteConfigAlertUser(idAlert) <h4 className="capitalize">{pageName}</h4>
} </CardHeader>
} <CardBody>
<Row gutter={16}>
const deleteConfigAlertUser = async (id) => { {dataTable.map((val, index) => (
const url = CALERTUSER_DELETE(id) <Col key={index} md={{span:5,offset:1}} xs={{span:11,offset:1}}>
<ACard style={{height:"100%"}} actions={[
const result = await axios.delete(url, config) <Switch checked={checked[val.id] ? true : false} onChange={(checked) => onChange(checked, val.id)} disabled={onSetSwitch} />,
.then(res => res) ]}>
.catch((error) => error.response); <div style={{height:'100%',width:'100%',display:'flex',justifyContent:'center', alignItems:'center', textAlign:'center', flexDirection:'column'}}>
<i style={{marginBottom:"25px"}}><Icon icon={checked[val.id] ? Bell : BellOff} color="black" width="100" height="100" /></i>
if (result && result.data && result.data.code === 200) { <p style={{marginBottom:"0"}}>{val.nama}</p>
getDataConfigAlert(); </div>
} </ACard>
} </Col>
))}
</Row>
return ( </CardBody>
<div> </Card>
<NotificationContainer /> </div>
<Card> )
<CardHeader style={{ display: "flex", justifyContent: "space-between" }}>
<h4 className="capitalize">{pageName}</h4>
</CardHeader>
<CardBody>
<Row gutter={16}>
{dataTable.map((val, index) => (
<Col key={index} md={{span:5,offset:1}} xs={{span:11,offset:1}}>
<ACard style={{height:"100%"}} actions={[
<Switch checked={checked[val.id] ? true : false} onChange={(checked) => onChange(checked, val.id)} disabled={onSetSwitch} />,
]}>
<div style={{height:'100%',width:'100%',display:'flex',justifyContent:'center', alignItems:'center', textAlign:'center', flexDirection:'column'}}>
<i style={{marginBottom:"25px"}}><Icon icon={checked[val.id] ? Bell : BellOff} color="black" width="100" height="100" /></i>
<p style={{marginBottom:"0"}}>{val.nama}</p>
</div>
</ACard>
</Col>
))}
</Row>
</CardBody>
</Card>
</div>
)
} }
export default Index; export default Index;

309
src/views/Master/MasterBroadcast/index.js

@ -1,22 +1,21 @@
import { DatePicker, Pagination } from 'antd'; import * as XLSX from 'xlsx';
import axios from 'axios'; import DialogDetail from './DialogDetail';
import moment from 'moment'; import DialogForm from './DialogForm';
import React, { Component } from 'react'; import React, { Component } from 'react';
import SweetAlert from 'react-bootstrap-sweetalert'; import SweetAlert from 'react-bootstrap-sweetalert';
import { NotificationContainer, NotificationManager } from 'react-notifications'; import axios from 'axios';
import { Button, Card, CardBody, CardHeader, DropdownItem, DropdownMenu, DropdownToggle, Input, InputGroup, InputGroupButtonDropdown, Table, Row, Col } from 'reactstrap'; import moment from 'moment';
import * as XLSX from 'xlsx';
import { API_BROADCAST_SIMPRO, BASE_SIMPRO, BASE_URL_GEOHR_API2 } from '../../../const/ApiConst'; import { API_BROADCAST_SIMPRO, BASE_SIMPRO, BASE_URL_GEOHR_API2 } from '../../../const/ApiConst';
import DialogForm from './DialogForm'; import { Button, Card, CardBody, CardHeader, DropdownItem, DropdownMenu, DropdownToggle, Input, InputGroup, InputGroupButtonDropdown, Table, Row, Col } from 'reactstrap';
import DialogDetail from './DialogDetail'; import { DatePicker, Pagination } from 'antd';
import { NotificationContainer, NotificationManager } from 'react-notifications';
import { Tooltip } from 'reactstrap'; import { Tooltip } from 'reactstrap';
const { RangePicker } = DatePicker; const { RangePicker } = DatePicker;
const token = window.localStorage.getItem('token'); const token = window.localStorage.getItem('token');
const config = { const config = {
headers: headers:
{ {
Authorization : `Bearer ${token}`, Authorization : `Bearer ${token}`,
"Content-type" : `application/json` "Content-type" : `application/json`
} }
@ -27,7 +26,6 @@ const roleName = window.localStorage.getItem('role_name');
const column = [ const column = [
{ name: "Aksi" }, { name: "Aksi" },
{ name: "Judul" }, { name: "Judul" },
{ name: "Pesan" }, { name: "Pesan" },
{ name: "Deskripsi" }, { name: "Deskripsi" },
@ -41,40 +39,40 @@ export default class index extends Component {
constructor(props) { constructor(props) {
super(props) super(props)
this.state = { this.state = {
dataTable: [], alertBroadcast: false,
dataExport: [],
openDialog: false,
typeDialog: 'Save',
dataEdit: null,
alertDelete: false, alertDelete: false,
idDelete: 0, currentDay: 'today',
currentPage: 1,
dataDetail:[],
dataEdit: null,
dataExport: [],
dataExport:[],
dataGs: [], dataGs: [],
dataIdHo: [], dataIdHo: [],
search: "", dataTable: [],
endDate: moment(moment().format("YYYY-M-D")),
idDelete: 0,
idSend: 0,
openDialog: false,
openDialogDetail: false,
page: 0, page: 0,
rowsPerPage: LENGTH_DATA, rowsPerPage: LENGTH_DATA,
currentPage: 1, search: "",
totalPage: 0,
tooltipEdit: false,
tooltipDelete: false,
typeClock: "All",
startDate: moment(moment().format("YYYY-M-D")),
endDate: moment(moment().format("YYYY-M-D")),
dataExport:[],
currentDay: 'today',
searchDetail: "Judul", searchDetail: "Judul",
searchDetailField: "title_notif", searchDetailField: "title_notif",
splitButtonOpen: false, splitButtonOpen: false,
alertBroadcast: false, startDate: moment(moment().format("YYYY-M-D")),
statusSend: '', statusSend: '',
idSend: 0,
dataDetail:[],
openDialogDetail: false,
toltipDetail:false, toltipDetail:false,
tooltipDelete: false,
tooltipEdit: false,
tooltipExport:false,
tooltipTambah:false,
tooltipresend:false, tooltipresend:false,
tooltipsend:false, tooltipsend:false,
tooltipTambah:false, totalPage: 0,
tooltipExport:false, typeClock: "All",
typeDialog: 'Save',
} }
} }
@ -94,7 +92,6 @@ export default class index extends Component {
}; };
getDataBroadcast = async () => { getDataBroadcast = async () => {
// let url = `${API_BROADCAST}/search`;
let url = BASE_SIMPRO + `/broadcast/search`; let url = BASE_SIMPRO + `/broadcast/search`;
const { searchDetail } = this.state const { searchDetail } = this.state
@ -134,42 +131,9 @@ export default class index extends Component {
} }
} }
// const formData = new FormData();
// formData.append("start", start);
// formData.append("id_org", id_org);
// formData.append("length", this.state.rowsPerPage);
// formData.append("startDate", dateStart.format("YYYY-M-D")+" 00:00:00");
// formData.append("endDate", dateEnd.format("YYYY-M-D")+" 23:59:59");
// formData.append('field', this.state.searchDetailField);
if(this.state.search!=="" && this.state.search!==null){ if(this.state.search!=="" && this.state.search!==null){
// formData.append('value', this.state.search);
} }
// const param = {
// "paging": { "start": start, "length": this.state.rowsPerPage },
// ...searchDetail === "Semua" &&
// {
// "filter_columns": [
// { "name": "title_notif", "value": this.state.search.toString() },
// { "name": "message_notif", "value": this.state.search.toString() },
// { "name": "description", "value": this.state.search.toString() },
// { "name": "status_send", "value": this.state.search.toString() },
// ],
// },
// ...searchDetail !== "Semua" &&
// {
// "columns": [
// { "name": this.state.searchDetailField, "logic_operator": "like", "operator": "and", "value": this.state.search.toString() }
// ]
// },
// "orders": { "columns": ["created_date"], "descending": true }
// }
// const result = await axios
// .post(url, param)
// .then(res => res)
// .catch((error) => error.response);
const result = await axios const result = await axios
.post(url, payload, config) .post(url, payload, config)
.then(res => res) .then(res => res)
@ -183,15 +147,6 @@ export default class index extends Component {
} else { } else {
NotificationManager.error('Failed retreiving data!!', 'Failed'); NotificationManager.error('Failed retreiving data!!', 'Failed');
} }
// console.log("data result", result)
// if(result && result.data){
// if (result.status === 200) {
// this.setState({ dataTable: result.data.data, totalPage: result.data.totalRecord });
// } else {
// NotificationManager.error('Gagal Menerima Data!!', 'Failed');
// }
// }
} }
handleOpenDialog = (type) => { handleOpenDialog = (type) => {
@ -232,26 +187,19 @@ export default class index extends Component {
} }
saveBroadcast = async (type, data) => { saveBroadcast = async (type, data) => {
// let url = `${API_BROADCAST}/add`;
let url = BASE_SIMPRO + `/broadcast/add`; let url = BASE_SIMPRO + `/broadcast/add`;
// const param = {
// "title_notif": data.title,
// "message_notif": data.message,
// "description": data.description,
// "status_send": type
// }
const param = { const param = {
"title_notif": data.title, "title_notif": data.title,
"status_send": type, "status_send": type,
"send_to_type": "all", "send_to_type": "all",
"message_notif": data.message, "message_notif": data.message,
"description": data.description, "description": data.description,
} }
const paramRoles = { const paramRoles = {
"title_notif": data.title, "title_notif": data.title,
"status_send": type, "status_send": type,
"send_to_type": "roles", "send_to_type": "roles",
"message_notif": data.message, "message_notif": data.message,
"description": data.description, "description": data.description,
@ -259,106 +207,69 @@ export default class index extends Component {
} }
const paramUsers = { const paramUsers = {
"title_notif": data.title, "title_notif": data.title,
"status_send": type, "status_send": type,
"send_to_type": "users", "send_to_type": "users",
"message_notif": data.message, "message_notif": data.message,
"description": data.description, "description": data.description,
"send_to_id": data.id.map((id, index) => id) "send_to_id": data.id.map((id, index) => id)
} }
// const formData = new FormData();
// formData.append("title", data.title); if(data.send_to_type === "all") {
// formData.append("message", data.message); const result = await axios.post(url, param, config)
// formData.append("description", data.description); .then(res => res)
// formData.append("send_to_type", data.send_to_type); .catch((error) => error.response);
// if(type==="send"){ if (result) {
// formData.append('status_send', "complete"); if(result.data){
// }else{ if(result.data.code===200){
// formData.append('status_send', "registered"); this.getDataBroadcast();
// } NotificationManager.success('Broadcast berhasil terkirimkan', 'Success!!');
}else{
NotificationManager.error(`${result.data.message}`, 'Failed!!');
// if(data.send_to_type==="roles"){ }
// formData.append('id', data.id); }else{
// }else if(data.send_to_type==="users"){ NotificationManager.error(`${result.data.message}`, 'Failed!!');
// data.id.map((id, index)=> { }
// formData.append('id[]', id); }else{
// console.log("test", id); NotificationManager.error(`${result.data.message}`, 'Failed!!');
// }) }
// }else{ } else if(data.send_to_type === "roles") {
// formData.append('id', "all"); const result = await axios.post(url, paramRoles, config)
// } .then(res => res)
// const param = { .catch((error) => error.response);
// "title_notif": data.title, if (result) {
// "message_notif": data.message, if(result.data){
// "description": data.description, if(result.data.code===200){
// "status_send": type, this.getDataBroadcast();
// "send_to_type": data.send_to_type, NotificationManager.success('Broadcast berhasil terkirimkan', 'Success!!');
// "send_to_id": data.id }else{
// } NotificationManager.error(`${result.data.message}`, 'Failed!!');
// console.log("cek param", param) }
}else{
if(data.send_to_type === "all") { NotificationManager.error(`${result.data.message}`, 'Failed!!');
const result = await axios.post(url, param, config) }
.then(res => res) }else{
.catch((error) => error.response); NotificationManager.error(`${result.data.message}`, 'Failed!!');
}
if (result) { } else if(data.send_to_type === "users") {
if(result.data){ const result = await axios.post(url, paramUsers, config)
if(result.data.code===200){ .then(res => res)
this.getDataBroadcast(); .catch((error) => error.response);
NotificationManager.success('Broadcast berhasil terkirimkan', 'Success!!'); if (result) {
}else{ if(result.data){
NotificationManager.error(`${result.data.message}`, 'Failed!!'); if(result.data.code === 200){
} this.getDataBroadcast();
}else{ NotificationManager.success('Broadcast berhasil terkirimkan', 'Success!!');
NotificationManager.error(`${result.data.message}`, 'Failed!!'); }else{
} NotificationManager.error(`${result.data.message}`, 'Failed!!');
}else{ }
NotificationManager.error(`${result.data.message}`, 'Failed!!'); }else{
} NotificationManager.error(`${result.data.message}`, 'Failed!!');
}
} else if(data.send_to_type === "roles") { }else{
const result = await axios.post(url, paramRoles, config) NotificationManager.error(`${result.data.message}`, 'Failed!!');
.then(res => res) }
.catch((error) => error.response); }
console.log('test result broadcast all', result)
if (result) {
if(result.data){
if(result.data.code===200){
this.getDataBroadcast();
NotificationManager.success('Broadcast berhasil terkirimkan', 'Success!!');
}else{
NotificationManager.error(`${result.data.message}`, 'Failed!!');
}
}else{
NotificationManager.error(`${result.data.message}`, 'Failed!!');
}
}else{
NotificationManager.error(`${result.data.message}`, 'Failed!!');
}
} else if(data.send_to_type === "users") {
const result = await axios.post(url, paramUsers, config)
.then(res => res)
.catch((error) => error.response);
if (result) {
if(result.data){
if(result.data.code === 200){
this.getDataBroadcast();
NotificationManager.success('Broadcast berhasil terkirimkan', 'Success!!');
}else{
NotificationManager.error(`${result.data.message}`, 'Failed!!');
}
}else{
NotificationManager.error(`${result.data.message}`, 'Failed!!');
}
}else{
NotificationManager.error(`${result.data.message}`, 'Failed!!');
}
}
} }
@ -438,21 +349,14 @@ export default class index extends Component {
this.exportExcel(); this.exportExcel();
}); });
}else{ }else{
// NotificationManager.error('Failed retreiving data!!', 'Failed');
} }
} else { } else {
// NotificationManager.error('Failed retreiving data!!', 'Failed');
} }
} }
exportExcel = () => { exportExcel = () => {
const dataExcel = this.state.dataExport || []; const dataExcel = this.state.dataExport || [];
const dataExport = []; const dataExport = [];
// <td>{n.title_notif}</td>
// <td>{n.message_notif !== "" ? n.message_notif : "-"}</td>
// <td>{n.description !== "" ? n.description : "-"}</td>
// <td>{n.status_send !== "" ? n.status_send : "-"}</td>
// <td>{n.created_date !== "" ? moment.utc(n.created_date).for
dataExcel.map((val) => { dataExcel.map((val) => {
let row = { let row = {
"Tanggal Broadcast": moment(val.created_date).format("YYYY-MM-DD HH:mm:ss"), "Tanggal Broadcast": moment(val.created_date).format("YYYY-MM-DD HH:mm:ss"),
@ -493,7 +397,6 @@ export default class index extends Component {
renderBtnResend = (n) => { renderBtnResend = (n) => {
return ( return (
<Col> <Col>
{/* <Button onClick={() => this.handleEdit(n.id, 'resend')} color="warning">Kirim Ulang</Button> */}
<i id="Tooltipresend" className="cil-reload fa-lg" style={{ color: 'orange', cursor: "pointer" }} onClick={() => this.handleEdit(n, 'resend')}></i> <i id="Tooltipresend" className="cil-reload fa-lg" style={{ color: 'orange', cursor: "pointer" }} onClick={() => this.handleEdit(n, 'resend')}></i>
<Tooltip placement="right" isOpen={this.state.tooltipresend} target="Tooltipresend" toggle={() => this.toggleTooltip("resend")}> <Tooltip placement="right" isOpen={this.state.tooltipresend} target="Tooltipresend" toggle={() => this.toggleTooltip("resend")}>
Kirim Ulang Kirim Ulang
@ -503,7 +406,6 @@ export default class index extends Component {
} }
renderBtnSend = (n) => { renderBtnSend = (n) => {
// <Button onClick={() => this.handleEdit(n.id, 'send')} color="warning" >Kirim</Button>
return ( return (
<Col> <Col>
<i id="TooltipSend" className="cil-send fa-lg" style={{ color: 'orange', cursor: "pointer" }} onClick={() => this.handleEdit(n, 'send')}></i> <i id="TooltipSend" className="cil-send fa-lg" style={{ color: 'orange', cursor: "pointer" }} onClick={() => this.handleEdit(n, 'send')}></i>
@ -567,31 +469,28 @@ export default class index extends Component {
const val = e.target.value; const val = e.target.value;
this.setState({ currentDay:val }); this.setState({ currentDay:val });
if(val==="today"){ if(val==="today"){
// console.log("test 1 test",val);
this.setState({ this.setState({
startDate:moment(moment().format("YYYY-M-D")), startDate:moment(moment().format("YYYY-M-D")),
endDate:moment(moment().format("YYYY-M-D")), endDate:moment(moment().format("YYYY-M-D")),
currentPage: 1 currentPage: 1
}) })
}else if(val==="3 day"){ }else if(val==="3 day"){
// console.log("test test",val);
this.setState({ this.setState({
startDate:moment(moment().subtract(3, "days").format("YYYY-M-D")), startDate:moment(moment().subtract(3, "days").format("YYYY-M-D")),
endDate:moment(moment().format("YYYY-M-D")), endDate:moment(moment().format("YYYY-M-D")),
currentPage: 1 currentPage: 1
}) })
}else if(val==="7 day"){ }else if(val==="7 day"){
// console.log("test test",val);
this.setState({ this.setState({
startDate:moment(moment().subtract(7, "days").format("YYYY-M-D")), startDate:moment(moment().subtract(7, "days").format("YYYY-M-D")),
endDate:moment(moment().format("YYYY-M-D")), endDate:moment(moment().format("YYYY-M-D")),
currentPage: 1 currentPage: 1
}) })
}else{ }else{
console.log("test 2 test",val); console.log("test 2 test",val);
this.setState({ this.setState({
startDate:moment(moment().format("YYYY-M-D")), startDate:moment(moment().format("YYYY-M-D")),
endDate:moment(moment().format("YYYY-M-D")), endDate:moment(moment().format("YYYY-M-D")),
currentPage: 1 currentPage: 1
}) })
} }
@ -625,7 +524,7 @@ export default class index extends Component {
showDialog={showDialog => this.showChildDialog = showDialog} showDialog={showDialog => this.showChildDialog = showDialog}
dataHs={this.state.dataIdHo} dataHs={this.state.dataIdHo}
/> />
<DialogDetail <DialogDetail
openDialog={this.state.openDialogDetail} openDialog={this.state.openDialogDetail}
closeDialog={this.handleCloseDetail} closeDialog={this.handleCloseDetail}
toggleDialog={() => this.toggleDialogDetail} toggleDialog={() => this.toggleDialogDetail}
@ -639,7 +538,6 @@ export default class index extends Component {
<Col > <Col >
<Button id="TooltipTambah" color="success" onClick={() => this.handleOpenDialog('Save')}><i className="fa fa-plus"></i></Button> <Button id="TooltipTambah" color="success" onClick={() => this.handleOpenDialog('Save')}><i className="fa fa-plus"></i></Button>
<Button style={{marginLeft:"5px"}} id="TooltipExport" color="primary" onClick={()=> this.handleExportExcel()}><i className="fa fa-print"></i></Button> <Button style={{marginLeft:"5px"}} id="TooltipExport" color="primary" onClick={()=> this.handleExportExcel()}><i className="fa fa-print"></i></Button>
{/* <Button color="primary" onClick={() => this.handleOpenDialog('Save')}>Tambah Divisi Karyawan</Button> */}
<Tooltip placement="right" isOpen={tooltipTambah} target="TooltipTambah" toggle={() => this.toggle("tambah")}> <Tooltip placement="right" isOpen={tooltipTambah} target="TooltipTambah" toggle={() => this.toggle("tambah")}>
Tambah Broadcast Tambah Broadcast
</Tooltip> </Tooltip>
@ -672,11 +570,6 @@ export default class index extends Component {
> >
<DropdownToggle split outline /> <DropdownToggle split outline />
<DropdownMenu> <DropdownMenu>
{/* <DropdownItem onClick={
() => this.setState({
searchDetail: "Nama Karyawan",
searchDetailField: "name"
})}>Nama Karyawan</DropdownItem> */}
<DropdownItem onClick={ <DropdownItem onClick={
() => this.setState({ () => this.setState({
searchDetail: "Judul", searchDetail: "Judul",

124
src/views/Master/MasterMenu/index.js

@ -1,13 +1,13 @@
import React, { useState, useEffect, useMemo } from 'react';
import { Card, CardBody, CardHeader, Col, Row, Input } from 'reactstrap';
import { Button } from 'reactstrap';
import axios from 'axios';
import * as XLSX from 'xlsx'; import * as XLSX from 'xlsx';
import SweetAlert from 'react-bootstrap-sweetalert';
import DialogForm from './DialogForm'; import DialogForm from './DialogForm';
import React, { useState, useEffect, useMemo } from 'react';
import SweetAlert from 'react-bootstrap-sweetalert';
import axios from 'axios';
import { Button } from 'reactstrap';
import { Card, CardBody, CardHeader, Col, Row, Input } from 'reactstrap';
import { MENU_ADD,MENU_SEARCH,MENU_EDIT,MENU_DELETE } from '../../../const/ApiConst.js';
import { NotificationContainer, NotificationManager } from 'react-notifications'; import { NotificationContainer, NotificationManager } from 'react-notifications';
import { Pagination, Tooltip, Table } from 'antd'; import { Pagination, Tooltip, Table } from 'antd';
import { MENU_ADD,MENU_SEARCH,MENU_EDIT,MENU_DELETE } from '../../../const/ApiConst.js';
const token = window.localStorage.getItem('token'); const token = window.localStorage.getItem('token');
@ -21,29 +21,29 @@ const column = [
] ]
const Index = ({params}) => { const Index = ({params}) => {
const [dataTable, setDatatable] = useState([])
const [search, setSearch] = useState('')
const [currentPage, setCurrentPage] = useState(1)
const [totalPage, setTotalPage] = useState(0)
const [openDialog, setOpenDialog] = useState(false)
const [typeDialog, setTypeDialog] = useState('Save')
const [idDelete, setIdDelete] = useState(0)
const [alertDelete, setAlertDelete] = useState(false) const [alertDelete, setAlertDelete] = useState(false)
const [allDataMenu, setAllDataMenu] = useState([])
const [clickOpenModal, setClickOpenModal] = useState(false)
const [currentPage, setCurrentPage] = useState(1)
const [dataEdit, setDataEdit] = useState([]) const [dataEdit, setDataEdit] = useState([])
const [dataExport, setDataExport] = useState([])
const [dataTable, setDatatable] = useState([])
const [idDelete, setIdDelete] = useState(0)
const [openDialog, setOpenDialog] = useState(false)
const [rowsPerPage, setRowsPerPage] = useState(10) const [rowsPerPage, setRowsPerPage] = useState(10)
const [search, setSearch] = useState('')
const [tooltipDelete, setTooltipDelete] = useState(false) const [tooltipDelete, setTooltipDelete] = useState(false)
const [tooltipEdit, setTooltipEdit] = useState(false) const [tooltipEdit, setTooltipEdit] = useState(false)
const [tooltipTambah, setTooltipTambah] = useState(false)
const [tooltipExport, setTooltipExport] = useState(false) const [tooltipExport, setTooltipExport] = useState(false)
const [clickOpenModal, setClickOpenModal] = useState(false) const [tooltipTambah, setTooltipTambah] = useState(false)
const [dataExport, setDataExport] = useState([]) const [totalPage, setTotalPage] = useState(0)
const [allDataMenu, setAllDataMenu] = useState([]) const [typeDialog, setTypeDialog] = useState('Save')
const pageName = params.name; const pageName = params.name;
const config = { const config = {
headers: headers:
{ {
Authorization : `Bearer ${token}`, Authorization : `Bearer ${token}`,
"Content-type" : `application/json` "Content-type" : `application/json`
} }
@ -51,10 +51,8 @@ const Index = ({params}) => {
useEffect(()=> { useEffect(()=> {
// for select in form add or edit
getDataMenu(); getDataMenu();
getDataAllMenu(); getDataAllMenu();
console.log("cek config", config)
},[]) },[])
useEffect(()=> { useEffect(()=> {
@ -75,7 +73,6 @@ const Index = ({params}) => {
}; };
const getDataAllMenu = async () => { const getDataAllMenu = async () => {
const payload = { const payload = {
"paging": {"start": 0, "length": -1}, "paging": {"start": 0, "length": -1},
"columns": [ "columns": [
@ -84,26 +81,18 @@ const Index = ({params}) => {
"joins": [], "joins": [],
"orders": {"columns": ["id"], "ascending": false} "orders": {"columns": ["id"], "ascending": false}
} }
const result = await axios const result = await axios
.post(MENU_SEARCH, payload, config) .post(MENU_SEARCH, payload, config)
.then(res => res) .then(res => res)
.catch((error) => error.response); .catch((error) => error.response);
// console.log(result)
if(result && result.data && result.data.code == 200){ if(result && result.data && result.data.code == 200){
setAllDataMenu(result.data.data); setAllDataMenu(result.data.data);
}else{ }else{
// NotificationManager.error('Gagal Mengambil Data!!', 'Failed');
} }
} }
const getDataMenu = async () => { const getDataMenu = async () => {
let start = 0; let start = 0;
if (currentPage !== 1 && currentPage > 1) { if (currentPage !== 1 && currentPage > 1) {
@ -124,19 +113,14 @@ const Index = ({params}) => {
}], }],
"orders": {"columns": ["id"], "ascending": false} "orders": {"columns": ["id"], "ascending": false}
} }
const result = await axios const result = await axios
.post(MENU_SEARCH, payload, config) .post(MENU_SEARCH, payload, config)
.then(res => res) .then(res => res)
.catch((error) => error.response); .catch((error) => error.response);
// console.log(result)
if(result && result.data && result.data.code == 200){ if(result && result.data && result.data.code == 200){
setDatatable(result.data.data); setDatatable(result.data.data);
console.log("resdata", result.data.data)
setTotalPage(result.data.totalRecord); setTotalPage(result.data.totalRecord);
}else{ }else{
NotificationManager.error('Gagal Mengambil Data!!', 'Failed'); NotificationManager.error('Gagal Mengambil Data!!', 'Failed');
@ -163,13 +147,10 @@ const Index = ({params}) => {
} }
const onConfirmDelete = async () => { const onConfirmDelete = async () => {
const url = MENU_DELETE(idDelete) const url = MENU_DELETE(idDelete)
const result = await axios.delete(url, config) const result = await axios.delete(url, config)
.then(res => res) .then(res => res)
.catch((error) => error.response); .catch((error) => error.response);
if (result && result.data && result.data.code === 200) { if (result && result.data && result.data.code === 200) {
getDataMenu() getDataMenu()
setIdDelete(0) setIdDelete(0)
@ -182,42 +163,38 @@ const Index = ({params}) => {
} }
} }
const saveMenu = async (data) => { const saveMenu = async (data) => {
const formData = data const formData = data
const result = await axios.post(MENU_ADD, formData, config) const result = await axios.post(MENU_ADD, formData, config)
.then(res => res) .then(res => res)
.catch((error) => error.response); .catch((error) => error.response);
if(result && result.data && result.data.code===200){ if(result && result.data && result.data.code===200){
getDataMenu(); getDataMenu();
getDataAllMenu(); getDataAllMenu();
NotificationManager.success(`Data menu berhasil ditambah`, 'Success!!'); NotificationManager.success(`Data menu berhasil ditambah`, 'Success!!');
} else { } else {
NotificationManager.error(`${result.data.message}`, 'Failed!!'); NotificationManager.error(`${result.data.message}`, 'Failed!!');
} }
} }
const editMenu = async (data) => { const editMenu = async (data) => {
console.log("cek data edit", data)
const formData = data const formData = data
const url = MENU_EDIT(data.id) const url = MENU_EDIT(data.id)
const result = await axios.put(url, formData, config) const result = await axios.put(url, formData, config)
.then(res => res) .then(res => res)
.catch((error) => error.response); .catch((error) => error.response);
if(result && result.data && result.data.code===200){ if(result && result.data && result.data.code===200){
getDataMenu(); getDataMenu();
NotificationManager.success(`Data menu berhasil diedit`, 'Success!!'); NotificationManager.success(`Data menu berhasil diedit`, 'Success!!');
} else { } else {
NotificationManager.error(`Data menu gagal di edit`, `Failed!!`); NotificationManager.error(`Data menu gagal di edit`, `Failed!!`);
} }
} }
const handleEdit = (data) => { const handleEdit = (data) => {
setDataEdit(data) setDataEdit(data)
handleOpenDialog('Edit'); handleOpenDialog('Edit');
@ -249,7 +226,6 @@ const Index = ({params}) => {
} }
const handleExportExcel = async () => { const handleExportExcel = async () => {
const payload = { const payload = {
"paging": {"start": 0, "length": -1}, "paging": {"start": 0, "length": -1},
"columns": [ "columns": [
@ -264,19 +240,14 @@ const Index = ({params}) => {
}], }],
"orders": {"columns": ["id"], "ascending": false} "orders": {"columns": ["id"], "ascending": false}
} }
const result = await axios const result = await axios
.post(MENU_SEARCH, payload, config) .post(MENU_SEARCH, payload, config)
.then(res => res) .then(res => res)
.catch((error) => error.response); .catch((error) => error.response);
// console.log(result)
if(result && result.data && result.data.code == 200){ if(result && result.data && result.data.code == 200){
let resData = result.data.data; let resData = result.data.data;
console.log("resdata", resData)
const excelData = []; const excelData = [];
resData.map((val, index) => { resData.map((val, index) => {
let dataRow = { let dataRow = {
@ -289,12 +260,10 @@ const Index = ({params}) => {
} }
excelData.push(dataRow) excelData.push(dataRow)
}) })
// console.log("cek excel data", excelData)
await setDataExport(excelData); await setDataExport(excelData);
// exportExcel();
}else{ }else{
NotificationManager.error('Gagal Export Data!!', 'Failed'); NotificationManager.error('Gagal Export Data!!', 'Failed');
} }
} }
const exportExcel = () => { const exportExcel = () => {
@ -303,7 +272,6 @@ const Index = ({params}) => {
const ws = XLSX.utils.json_to_sheet(dataExcel); const ws = XLSX.utils.json_to_sheet(dataExcel);
const wb = XLSX.utils.book_new(); const wb = XLSX.utils.book_new();
XLSX.utils.book_append_sheet(wb, ws, `Data ${pageName}`); XLSX.utils.book_append_sheet(wb, ws, `Data ${pageName}`);
XLSX.writeFile(wb, fileName); XLSX.writeFile(wb, fileName);
setDataExport([]) setDataExport([])
} }
@ -345,7 +313,7 @@ const Index = ({params}) => {
/> />
) )
}, [dataTable]) }, [dataTable])
return ( return (
<div> <div>
<NotificationContainer /> <NotificationContainer />
@ -389,44 +357,6 @@ const Index = ({params}) => {
</Row> </Row>
</CardHeader> </CardHeader>
<CardBody> <CardBody>
{/* <Table responsive striped hover>
<thead>
<tr>
<th className="capitalize">{`Aksi`}</th>
{column.map((i, index) => {
return (
<th key={index} scope="row">{i.name}</th>
)
})}
</tr>
</thead>
<tbody>
{dataTable.length<=0 ?
<tr>
<td colSpan="7" align="center">No Data Available</td>
</tr> : null}
{dataTable.map((n, index) => {
return (
<tr key={index}>
<td>
<Tooltip title="Delete">
<i id="TooltipDelete" className="fa fa-trash" style={{ color: 'red', marginRight: '10px', cursor: "pointer" }} onClick={() => handleDelete(n.id)}></i>
</Tooltip>
<Tooltip title="Edit">
<i id="TooltipEdit" className="fa fa-pencil" style={{ color: 'green', cursor: "pointer" }} onClick={() => handleEdit(n)}></i>
</Tooltip>
</td>
<td>{n.name}</td>
<td>{n.url}</td>
<td>{n.icon}</td>
<td>{n.alias_name}</td>
<td>{n.sequence}</td>
<td>{n.join_first_name ? n.join_first_name : "-"}</td>
</tr>
)
})}
</tbody>
</Table> */}
{renderTable} {renderTable}
<Pagination <Pagination
style={{marginTop:"25px"}} style={{marginTop:"25px"}}
@ -444,4 +374,4 @@ const Index = ({params}) => {
) )
} }
export default Index; export default Index;

921
src/views/Master/MasterRoles/index.js

@ -1,14 +1,13 @@
import React, { Component, useMemo } from 'react';
import { Card, CardBody, CardHeader, Col, Row, Input } from 'reactstrap';
import { Button } from 'reactstrap';
import axios from 'axios';
import * as XLSX from 'xlsx'; import * as XLSX from 'xlsx';
import SweetAlert from 'react-bootstrap-sweetalert';
import DialogForm from './DialogForm'; import DialogForm from './DialogForm';
import DialogMenuRoles from './DialogMenuRoles'; import DialogMenuRoles from './DialogMenuRoles';
import React, { Component, useMemo } from 'react';
import SweetAlert from 'react-bootstrap-sweetalert';
import axios from 'axios';
import { Button } from 'reactstrap';
import { Card, CardBody, CardHeader, Col, Row, Input } from 'reactstrap';
import { NotificationContainer, NotificationManager } from 'react-notifications'; import { NotificationContainer, NotificationManager } from 'react-notifications';
import { Pagination, Tooltip, Table } from 'antd'; import { Pagination, Tooltip, Table } from 'antd';
import { ROLE_ADD, ROLE_SEARCH, ROLE_EDIT, ROLE_DELETE, ROLEMENU_ADD, ROLEMENU_SEARCH, ROLEMENU_DELETE_ROLE } from '../../../const/ApiConst.js'; import { ROLE_ADD, ROLE_SEARCH, ROLE_EDIT, ROLE_DELETE, ROLEMENU_ADD, ROLEMENU_SEARCH, ROLEMENU_DELETE_ROLE } from '../../../const/ApiConst.js';
const token = window.localStorage.getItem('token'); const token = window.localStorage.getItem('token');
@ -16,503 +15,435 @@ const token = window.localStorage.getItem('token');
const BASE_URL = "http://siopas.co.id/custom-php/api/geohr/"; const BASE_URL = "http://siopas.co.id/custom-php/api/geohr/";
const config = { const config = {
headers: headers:
{ {
Authorization : `Bearer ${token}`, Authorization : `Bearer ${token}`,
"Content-type" : `application/json` "Content-type" : `application/json`
} }
}; };
const momentFormat = 'HH:mm'; const momentFormat = 'HH:mm';
const LENGTH_DATA = 10 const LENGTH_DATA = 10
export default class index extends Component { export default class index extends Component {
constructor(props) { constructor(props) {
super(props) super(props)
this.state = { this.state = {
dataTable: [], alertDelete: false,
openDialog: false, alertNotDelete: false,
dialogMenuForm: false, currentPage: 1,
typeDialog: 'Save', dataEdit: null,
dataEdit: null, dataExport:[],
alertDelete: false, dataGs: [],
alertNotDelete: false, dataIdHo: [],
idDelete: 0, dataTable: [],
dataGs: [], dialogMenuForm: false,
dataIdHo: [], idDelete: 0,
search: "", idRoles:0,
page: 0, menuRoles:[],
rowsPerPage: LENGTH_DATA, openDialog: false,
currentPage: 1, page: 0,
totalPage: 0, rowsPerPage: LENGTH_DATA,
tooltipEdit: false, search: "",
tooltipDelete: false, tooltipDelete: false,
tooltipMenu: false, tooltipEdit: false,
idRoles:0, tooltipExport:false,
menuRoles:[], tooltipImport:false,
tooltipTambah:false, tooltipMenu: false,
tooltipImport:false, tooltipTambah:false,
tooltipExport:false, totalPage: 0,
dataExport:[] typeDialog: 'Save',
} }
this.columns = [ this.columns = [
{ {
title: 'Action', title: 'Action',
dataIndex: '', dataIndex: '',
key: 'x', key: 'x',
className:'nowrap', className:'nowrap',
render: (text, record) => <> render: (text, record) => <>
<Tooltip title="Roles Menu"> <Tooltip title="Roles Menu">
<i className="cil-menu fa-lg" style={{ color: 'green', marginRight: 10, cursor: "pointer" }} onClick={() => this.handleMenuRoles(text.id)}></i> <i className="cil-menu fa-lg" style={{ color: 'green', marginRight: 10, cursor: "pointer" }} onClick={() => this.handleMenuRoles(text.id)}></i>
</Tooltip> </Tooltip>
<Tooltip title="Hapus"> <Tooltip title="Hapus">
<i className="cil-trash fa-lg" style={{ color: 'red', marginRight: 10, cursor: "pointer" }} onClick={() => this.handleDelete(text.id)}></i> <i className="cil-trash fa-lg" style={{ color: 'red', marginRight: 10, cursor: "pointer" }} onClick={() => this.handleDelete(text.id)}></i>
</Tooltip> </Tooltip>
<Tooltip title="Edit"> <Tooltip title="Edit">
<i className="fa fa-edit fa-lg" style={{ color: 'green', cursor: "pointer" }} onClick={() => this.handleEdit(text)}></i> <i className="fa fa-edit fa-lg" style={{ color: 'green', cursor: "pointer" }} onClick={() => this.handleEdit(text)}></i>
</Tooltip> </Tooltip>
</>, </>,
}, },
{ title: 'Nama Role', dataIndex: 'name', key: 'name', className:"nowrap" }, { title: 'Nama Role', dataIndex: 'name', key: 'name', className:"nowrap" },
{ title: 'Description', dataIndex: 'description', key: 'description' }, { title: 'Description', dataIndex: 'description', key: 'description' },
] ]
} }
async componentDidMount() { async componentDidMount() {
this.getDataRoles(); this.getDataRoles();
} }
async componentDidUpdate(prevProps, prevState) { async componentDidUpdate(prevProps, prevState) {
const { search } = this.state const { search } = this.state
if (search !== prevState.search) this.getDataRoles() if (search !== prevState.search) this.getDataRoles()
} }
handleSearch = e => { handleSearch = e => {
const value = e.target.value const value = e.target.value
this.setState({ search: value, currentPage: 1 }) this.setState({ search: value, currentPage: 1 })
}; };
getDataRoles = async () => { getDataRoles = async () => {
let start = 0;
let start = 0; if (this.state.currentPage !== 1 && this.state.currentPage > 1) {
start = (this.state.currentPage * this.state.rowsPerPage) - this.state.rowsPerPage
if (this.state.currentPage !== 1 && this.state.currentPage > 1) { }
start = (this.state.currentPage * this.state.rowsPerPage) - this.state.rowsPerPage
} const formData = {
"paging": {"start": start, "length": this.state.rowsPerPage},
const formData = { "columns": [
"paging": {"start": start, "length": this.state.rowsPerPage}, {"name": "name", "logic_operator": "like", "value": this.state.search, "operator": "AND"}
"columns": [ ],
{"name": "name", "logic_operator": "like", "value": this.state.search, "operator": "AND"} "joins": [],
], "orders": {"columns": ["id"], "ascending": false}
"joins": [], }
"orders": {"columns": ["id"], "ascending": false}
} const result = await axios
.post(ROLE_SEARCH, formData, config)
const result = await axios .then(res => res)
.post(ROLE_SEARCH, formData, config) .catch((error) => error.response);
.then(res => res)
.catch((error) => error.response); if(result && result.data && result.data.code == 200){
// console.log(result) this.setState({ dataTable: result.data.data, totalPage: result.data.totalRecord });
}else{
if(result && result.data && result.data.code == 200){ NotificationManager.error('Gagal Mengambil Data!!', 'Failed');
this.setState({ dataTable: result.data.data, totalPage: result.data.totalRecord }); }
}else{ }
NotificationManager.error('Gagal Mengambil Data!!', 'Failed');
} handleOpenDialog = (type) => {
} this.setState({ openDialog: true, typeDialog: type })
this.showChildDialog();
handleOpenDialog = (type) => { }
this.setState({ openDialog: true, typeDialog: type })
this.showChildDialog(); handleCloseDialog = (type, data) => {
} if (type === "save") {
this.saveRole(data);
} else if (type === "edit") {
this.editRole(data);
handleCloseDialog = (type, data) => { }
if (type === "save") { this.setState({ openDialog: false })
this.saveRole(data); }
} else if (type === "edit") {
this.editRole(data); handleOpenDialogMr = () => {
} this.setState({ dialogMenuForm: true })
this.showMenuRolesDialog();
this.setState({ openDialog: false }) }
}
handleCloseDialogMr = (type, data) => {
if(type==="save"){
handleOpenDialogMr = () => { this.saveMenuRoles(data)
this.setState({ dialogMenuForm: true }) }
this.showMenuRolesDialog(); this.setState({ dialogMenuForm: false })
} }
handleCloseDialogMr = (type, data) => {
if(type==="save"){ toggleAddDialog = () => {
this.saveMenuRoles(data) this.setState({ openDialog: !this.state.openDialog })
} }
this.setState({ dialogMenuForm: false })
} onConfirmDelete = async () => {
const { idDelete } = this.state
toggleAddDialog = () => { const url = ROLE_DELETE(idDelete)
this.setState({ openDialog: !this.state.openDialog })
} const result = await axios.delete(url, config)
.then(res => res)
onConfirmDelete = async () => { .catch((error) => error.response);
const { idDelete } = this.state
const url = ROLE_DELETE(idDelete) if (result && result.data && result.data.code === 200) {
this.deleteCurrentRoleMenu(idDelete)
const result = await axios.delete(url, config) this.getDataRoles()
.then(res => res) this.setState({ idDelete: 0, alertDelete: false })
.catch((error) => error.response); NotificationManager.success(`Data role berhasil dihapus`, 'Success!!');
} else {
if (result && result.data && result.data.code === 200) { this.setState({ idDelete: 0, alertDelete: false })
this.deleteCurrentRoleMenu(idDelete) NotificationManager.error(`Data role gagal dihapus`, 'Failed!!');
this.getDataRoles() }
this.setState({ idDelete: 0, alertDelete: false }) }
NotificationManager.success(`Data role berhasil dihapus`, 'Success!!');
} else { saveRole = async (data) => {
this.setState({ idDelete: 0, alertDelete: false })
NotificationManager.error(`Data role gagal dihapus`, 'Failed!!'); const formData = {
} name:data.name,
} description:data.description
}
saveRole = async (data) => {
const result = await axios.post(ROLE_ADD, formData, config)
const formData = { .then(res => res)
name:data.name, .catch((error) => error.response);
description:data.description
} if(result && result.data && result.data.code===200){
this.getDataRoles();
const result = await axios.post(ROLE_ADD, formData, config) NotificationManager.success(`Data role berhasil ditambah`, 'Success!!');
.then(res => res) } else {
.catch((error) => error.response); NotificationManager.error(`${result.data.message}`, 'Failed!!');
}
if(result && result.data && result.data.code===200){
this.getDataRoles(); }
NotificationManager.success(`Data role berhasil ditambah`, 'Success!!');
} else { editRole = async (data) => {
NotificationManager.error(`${result.data.message}`, 'Failed!!'); const formData = {
} name:data.name,
description:data.description
} }
const url = ROLE_EDIT(data.id)
editRole = async (data) => { const result = await axios.put(url, formData, config)
.then(res => res)
const formData = { .catch((error) => error.response);
name:data.name,
description:data.description if(result && result.data && result.data.code===200){
} this.getDataRoles();
const url = ROLE_EDIT(data.id) NotificationManager.success(`Data role berhasil diedit`, 'Success!!');
const result = await axios.put(url, formData, config) } else {
.then(res => res) NotificationManager.error(`Data role gagal di edit`, `Failed!!`);
.catch((error) => error.response); }
}
if(result && result.data && result.data.code===200){
this.getDataRoles(); handleEdit = (data) => {
NotificationManager.success(`Data role berhasil diedit`, 'Success!!'); this.setState({ dataEdit: data });
} else { this.handleOpenDialog('Edit');
NotificationManager.error(`Data role gagal di edit`, `Failed!!`); }
}
handleDelete = (id) => {
} id == '1' ? this.setState({ alertNotDelete: true }) :
this.setState({ alertDelete: true, idDelete: id });
}
handleEdit = (data) => {
this.setState({ dataEdit: data }); onShowSizeChange = (current, pageSize) => {
this.handleOpenDialog('Edit'); this.setState({ rowsPerPage: pageSize }, () => {
} this.getDataRoles();
})
handleDelete = (id) => { }
id == '1' ? this.setState({ alertNotDelete: true }) :
this.setState({ alertDelete: true, idDelete: id }); onPagination = (current, pageSize) => {
} this.setState({ currentPage: current, page: (current - 1) * pageSize }, () => {
this.getDataRoles();
onShowSizeChange = (current, pageSize) => { })
this.setState({ rowsPerPage: pageSize }, () => { }
this.getDataRoles();
}) toggle = (param) => {
} if (param === "edit") {
this.setState(prevState => ({ tooltipEdit: !prevState.tooltipEdit }))
onPagination = (current, pageSize) => { } else if (param === "delete") {
this.setState({ currentPage: current, page: (current - 1) * pageSize }, () => { this.setState(prevState => ({ tooltipDelete: !prevState.tooltipDelete }))
this.getDataRoles(); } else if(param === "menu"){
}) this.setState(prevState => ({ tooltipMenu: !prevState.tooltipMenu }))
} } else if (param === "tambah") {
this.setState(prevState => ({ tooltipTambah: !prevState.tooltipTambah }))
toggle = (param) => { } else if (param === "export") {
if (param === "edit") { this.setState(prevState => ({ tooltipExport: !prevState.tooltipExport }))
this.setState(prevState => ({ tooltipEdit: !prevState.tooltipEdit })) }
} else if (param === "delete") { }
this.setState(prevState => ({ tooltipDelete: !prevState.tooltipDelete }))
} else if(param === "menu"){ dataNotAvailable = () => {
this.setState(prevState => ({ tooltipMenu: !prevState.tooltipMenu })) if(this.state.dataTable.length===0){
} else if (param === "tambah") { return (
this.setState(prevState => ({ tooltipTambah: !prevState.tooltipTambah })) <tr>
} else if (param === "export") { <td align="center" colSpan="3">Not Data Available</td>
this.setState(prevState => ({ tooltipExport: !prevState.tooltipExport })) </tr>
} )
} }
}
dataNotAvailable = () => {
if(this.state.dataTable.length===0){ handleMenuRoles = async (id) => {
return ( const formData = {
<tr> "paging": {"start": 0, "length": -1},
<td align="center" colSpan="3">Not Data Available</td> "columns": [
</tr> {"name": "role_id", "logic_operator": "=", "value": `${id}`, "operator": "AND"}
) ],
} "joins": [],
} "orders": {"columns": ["id"], "ascending": false}
}
handleMenuRoles = async (id) => {
const result = await axios
const formData = { .post(ROLEMENU_SEARCH, formData, config)
"paging": {"start": 0, "length": -1}, .then(res => res)
"columns": [ .catch((error) => error.response);
{"name": "role_id", "logic_operator": "=", "value": `${id}`, "operator": "AND"} if (result && result.data && result.data.code == 200) {
], this.setState({ menuRoles:result.data.data,idRoles:id },() => {
"joins": [], this.handleOpenDialogMr();
"orders": {"columns": ["id"], "ascending": false} });
} } else {
}
const result = await axios }
.post(ROLEMENU_SEARCH, formData, config)
.then(res => res) saveMenuRoles = async (dataArray) => {
.catch((error) => error.response); let payloadArray = dataArray || []
// console.log(result) if(payloadArray.length > 0){
if (result && result.data && result.data.code == 200) { await this.deleteCurrentRoleMenu(payloadArray[0].roles_id)
this.setState({ menuRoles:result.data.data,idRoles:id },() => { }
this.handleOpenDialogMr(); let promises = []
}); let result = []
} else { dataArray.map((val, index)=> {
// NotificationManager.error('Gagal Mengambil Data!!', 'Failed'); if(val.checked===true){
} const formData = {
} menu_id:val.menu_id,
role_id:val.roles_id
saveMenuRoles = async (dataArray) => { }
let payloadArray = dataArray || [] promises.push(axios.post(ROLEMENU_ADD, formData, config)
// console.log("cek", payloadArray[0]) .then(res => result.push(res)))
if(payloadArray.length > 0){ }
await this.deleteCurrentRoleMenu(payloadArray[0].roles_id) })
}
let promises = [] await Promise.all(promises);
let result = [] if(result){
console.log("test test", dataArray) if(result.length > 0){
dataArray.map((val, index)=> { if (result[0].data.code === 200) {
if(val.checked===true){ this.getDataRoles();
const formData = { NotificationManager.success('Data roles berhasil ditambahkan!!', 'Success!!');
menu_id:val.menu_id, } else {
role_id:val.roles_id NotificationManager.error(`${result[0].data.message}`, 'Failed!!');
} }
promises.push(axios.post(ROLEMENU_ADD, formData, config) }
.then(res => result.push(res))) }
} }
})
deleteCurrentRoleMenu = async (id) => {
await Promise.all(promises); let urlDel = ROLEMENU_DELETE_ROLE(id)
if(result){ const result = await axios.delete(urlDel, config)
if(result.length > 0){ .then(res => res)
if (result[0].data.code === 200) { .catch((error) => error.response);
this.getDataRoles(); if (result && result.data && result.data.code === 200) {
NotificationManager.success('Data roles berhasil ditambahkan!!', 'Success!!'); return true
} else { } else {
NotificationManager.error(`${result[0].data.message}`, 'Failed!!'); return false
} }
} }
}
handleExportExcel = async () => {
} let start = 0;
let end = "ALL";
deleteCurrentRoleMenu = async (id) => { let url = BASE_URL + "roles.php?act=get_data";
let urlDel = ROLEMENU_DELETE_ROLE(id) const formData = new FormData();
const result = await axios.delete(urlDel, config) formData.append('field', 'name');
.then(res => res) if(this.state.search !== ""){
.catch((error) => error.response); formData.append('value', this.state.search);
}
if (result && result.data && result.data.code === 200) { const result = await axios
return true .post(url,formData)
} else { .then(res => res)
return false .catch((error) => error.response);
} if (result && result.data && result.statusText == "OK") {
} const dataRes = result.data.data|| [];
const dataExport = [];
handleExportExcel = async () => { dataRes.map((val,index)=> {
let start = 0; let row = {
let end = "ALL"; Nama:val.name,
let url = BASE_URL + "roles.php?act=get_data"; Deskripsi:val.description
const formData = new FormData(); }
formData.append('field', 'name'); dataExport.push(row);
if(this.state.search !== ""){ })
formData.append('value', this.state.search); this.setState({ dataExport:dataExport },()=> {
} this.exportExcel();
// console.log("test", url); });
const result = await axios } else {
.post(url,formData) NotificationManager.error('Failed retreiving data!!', 'Failed');
.then(res => res) }
.catch((error) => error.response); }
// console.log("result", result);
if (result && result.data && result.statusText == "OK") { exportExcel = () => {
const dataRes = result.data.data|| []; const dataExcel = this.state.dataExport || [];
console.log("data result", dataRes); const fileName = "Data Roles.xlsx";
const dataExport = []; const ws = XLSX.utils.json_to_sheet(dataExcel);
// <td>{n.name}</td>
// <td>{n.url}</td>
// <td>{n.alias_name}</td>
// <td>{n.icon}</td>
// <td>{n.parent_name || "-"}</td>
dataRes.map((val,index)=> {
let row = {
Nama:val.name,
Deskripsi:val.description
}
dataExport.push(row);
})
console.log("data Export", dataExport);
this.setState({ dataExport:dataExport },()=> {
this.exportExcel();
});
} else {
NotificationManager.error('Failed retreiving data!!', 'Failed');
}
}
exportExcel = () => {
const dataExcel = this.state.dataExport || [];
const fileName = "Data Roles.xlsx";
const ws = XLSX.utils.json_to_sheet(dataExcel);
const wb = XLSX.utils.book_new(); const wb = XLSX.utils.book_new();
XLSX.utils.book_append_sheet(wb, ws, 'Data Roles'); XLSX.utils.book_append_sheet(wb, ws, 'Data Roles');
XLSX.writeFile(wb, fileName); XLSX.writeFile(wb, fileName);
} }
render() { render() {
const { tooltipTambah,tooltipExport,dialogMenuForm, dataTable, openDialog, currentPage, rowsPerPage, totalPage, search, tooltipEdit, tooltipDelete,tooltipMenu } = this.state const { tooltipTambah,tooltipExport,dialogMenuForm, dataTable, openDialog, currentPage, rowsPerPage, totalPage, search, tooltipEdit, tooltipDelete,tooltipMenu } = this.state
let noSeq = 0; let noSeq = 0;
return ( return (
<div> <div>
<NotificationContainer /> <NotificationContainer />
<SweetAlert <SweetAlert
show={this.state.alertDelete} show={this.state.alertDelete}
warning warning
showCancel showCancel
confirmBtnText="Delete" confirmBtnText="Delete"
confirmBtnBsStyle="danger" confirmBtnBsStyle="danger"
title="Are you sure?" title="Are you sure?"
onConfirm={this.onConfirmDelete} onConfirm={this.onConfirmDelete}
onCancel={() => this.setState({ alertDelete: false, idDelete: 0 })} onCancel={() => this.setState({ alertDelete: false, idDelete: 0 })}
focusCancelBtn focusCancelBtn
> >
Data tipe roles akan terhapus!! Data tipe roles akan terhapus!!
</SweetAlert> </SweetAlert>
<SweetAlert <SweetAlert
show={this.state.alertNotDelete} show={this.state.alertNotDelete}
warning warning
// showCancel confirmBtnText="Can't Delete"
confirmBtnText="Can't Delete" confirmBtnBsStyle="danger"
confirmBtnBsStyle="danger" title="Data can't be delete!"
title="Data can't be delete!" onConfirm={() => this.setState({ alertNotDelete: false})}
onConfirm={() => this.setState({ alertNotDelete: false})} >
// focusCancelBtn Data tipe roles tidak dapat di hapus!!
> </SweetAlert>
Data tipe roles tidak dapat di hapus!! <DialogForm
</SweetAlert> openDialog={openDialog}
<DialogForm closeDialog={this.handleCloseDialog}
openDialog={openDialog} toggleDialog={() => this.toggleAddDialog}
closeDialog={this.handleCloseDialog} typeDialog={this.state.typeDialog}
toggleDialog={() => this.toggleAddDialog} dataEdit={this.state.dataEdit}
typeDialog={this.state.typeDialog} showDialog={showDialog => this.showChildDialog = showDialog}
dataEdit={this.state.dataEdit} dataHs={this.state.dataIdHo}
showDialog={showDialog => this.showChildDialog = showDialog} />
dataHs={this.state.dataIdHo} <DialogMenuRoles
/> openDialog={dialogMenuForm}
<DialogMenuRoles closeDialog={this.handleCloseDialogMr}
openDialog={dialogMenuForm} idRoles={this.state.idRoles}
closeDialog={this.handleCloseDialogMr} showDialog={showDialog => this.showMenuRolesDialog = showDialog}
idRoles={this.state.idRoles} menuRoles={this.state.menuRoles}
showDialog={showDialog => this.showMenuRolesDialog = showDialog} />
menuRoles={this.state.menuRoles} <Card>
<CardHeader style={{ display: "flex", justifyContent: "space-between" }}>
/> <h4>{this.props.params.name}</h4>
<Card> <Row>
<CardHeader style={{ display: "flex", justifyContent: "space-between" }}> <Col>
<h4>{this.props.params.name}</h4> <Input onChange={this.handleSearch} value={search} type="text" name="search" id="search" placeholder="Cari Nama Roles" />
<Row> </Col>
<Col> <Col>
<Input onChange={this.handleSearch} value={search} type="text" name="search" id="search" placeholder="Cari Nama Roles" /> <Tooltip title="Tambah Roles">
</Col> <Button id="TooltipTambah" color="success" onClick={() => this.handleOpenDialog('Save')}><i className="fa fa-plus"></i></Button>
<Col> </Tooltip>
<Tooltip title="Tambah Roles"> <Tooltip title="Export Excel">
<Button id="TooltipTambah" color="success" onClick={() => this.handleOpenDialog('Save')}><i className="fa fa-plus"></i></Button> <Button style={{marginLeft:"5px"}} id="TooltipExport" color="primary" onClick={()=> this.handleExportExcel()}><i className="fa fa-print"></i></Button>
</Tooltip> </Tooltip>
<Tooltip title="Export Excel"> </Col>
<Button style={{marginLeft:"5px"}} id="TooltipExport" color="primary" onClick={()=> this.handleExportExcel()}><i className="fa fa-print"></i></Button> </Row>
</Tooltip> </CardHeader>
</Col> <CardBody>
</Row> <Table
</CardHeader> rowKey="id"
<CardBody> size="small"
<Table columns={this.columns}
rowKey="id" dataSource={dataTable}
size="small" pagination={false}
columns={this.columns} bordered={false}
dataSource={dataTable} />
pagination={false} <Pagination
bordered={false} style={{marginTop:"25px"}}
/> showSizeChanger
{/* <Table responsive striped hover> onShowSizeChange={this.onShowSizeChange}
<thead> onChange={this.onPagination}
<tr> defaultCurrent={currentPage}
<th>Aksi</th> pageSize={rowsPerPage}
{column.map((i, index) => { total={totalPage}
return ( pageSizeOptions={["10", "15", "20", "25", "30", "35", "40"]}
<th key={index} scope="row">{i.name}</th> />
) </CardBody>
})} </Card>
</tr> </div>
</thead> )
<tbody> }
{this.dataNotAvailable()}
{dataTable.map((n, index) => {
return (
<tr key={n.id}>
<td>
<Tooltip title="Roles Menu">
<i id={`TooltipMenu-${n.id}`} className="cil-menu fa-lg" style={{ color: 'green', marginRight: 10, cursor: "pointer" }} onClick={() => this.handleMenuRoles(n.id)}></i>
</Tooltip>
<Tooltip title="Hapus">
<i id="TooltipDelete" className="cil-trash fa-lg" style={{ color: 'red', marginRight: 10, cursor: "pointer" }} onClick={() => this.handleDelete(n.id)}></i>
</Tooltip>
<Tooltip title="Edit">
<i id="TooltipEdit" className="cil-pencil fa-lg" style={{ color: 'green', cursor: "pointer" }} onClick={() => this.handleEdit(n)}></i>
</Tooltip>
</td>
<td>{n.name}</td>
<td>{n.description}</td>
</tr>
)
})}
</tbody>
</Table> */}
<Pagination
style={{marginTop:"25px"}}
showSizeChanger
onShowSizeChange={this.onShowSizeChange}
onChange={this.onPagination}
defaultCurrent={currentPage}
pageSize={rowsPerPage}
total={totalPage}
pageSizeOptions={["10", "15", "20", "25", "30", "35", "40"]}
/>
</CardBody>
</Card>
</div>
)
}
} }

765
src/views/Master/RoleProject/index.js

@ -1,440 +1,379 @@
import React, { Component } from 'react';
import { Card, CardBody, CardHeader, Col, Row, Input } from 'reactstrap';
import { Button } from 'reactstrap';
import axios from 'axios';
import * as XLSX from 'xlsx'; import * as XLSX from 'xlsx';
import SweetAlert from 'react-bootstrap-sweetalert';
import DialogForm from './DialogForm'; import DialogForm from './DialogForm';
import React, { Component } from 'react';
import SweetAlert from 'react-bootstrap-sweetalert';
import axios from 'axios';
import { Button } from 'reactstrap';
import { Card, CardBody, CardHeader, Col, Row, Input } from 'reactstrap';
import { NotificationContainer, NotificationManager } from 'react-notifications'; import { NotificationContainer, NotificationManager } from 'react-notifications';
import { Pagination, Tooltip, Table } from 'antd';
import { PROJECT_ROLE_ADD, PROJECT_ROLE_SEARCH, PROJECT_ROLE_EDIT, PROJECT_ROLE_DELETE, ROLEMENU_ADD, ROLEMENU_SEARCH, ROLEMENU_DELETE_ROLE } from '../../../const/ApiConst.js'; import { PROJECT_ROLE_ADD, PROJECT_ROLE_SEARCH, PROJECT_ROLE_EDIT, PROJECT_ROLE_DELETE, ROLEMENU_ADD, ROLEMENU_SEARCH, ROLEMENU_DELETE_ROLE } from '../../../const/ApiConst.js';
import { Pagination, Tooltip, Table } from 'antd';
const token = window.localStorage.getItem('token'); const token = window.localStorage.getItem('token');
const BASE_URL = "http://siopas.co.id/custom-php/api/geohr/"; const BASE_URL = "http://siopas.co.id/custom-php/api/geohr/";
const config = { const config = {
headers: headers:
{ {
Authorization : `Bearer ${token}`, Authorization : `Bearer ${token}`,
"Content-type" : `application/json` "Content-type" : `application/json`
} }
}; };
const columns = [ const columns = [
{ {
title: 'Action', title: 'Action',
dataIndex: '', dataIndex: '',
key: 'x', key: 'x',
className:'nowrap', className:'nowrap',
render: (text, record) => <> render: (text, record) => <>
<Tooltip title="Hapus"> <Tooltip title="Hapus">
<i className="cil-trash fa-lg" style={{ color: 'red', marginRight: 10, cursor: "pointer" }} onClick={() => this.handleDelete(text.id)}></i> <i className="cil-trash fa-lg" style={{ color: 'red', marginRight: 10, cursor: "pointer" }} onClick={() => this.handleDelete(text.id)}></i>
</Tooltip> </Tooltip>
<Tooltip title="Edit"> <Tooltip title="Edit">
<i className="fa fa-edit fa-lg" style={{ color: 'green', cursor: "pointer" }} onClick={() => this.handleEdit(text)}></i> <i className="fa fa-edit fa-lg" style={{ color: 'green', cursor: "pointer" }} onClick={() => this.handleEdit(text)}></i>
</Tooltip> </Tooltip>
</>, </>,
}, },
{ title: 'Nama Role', dataIndex: 'name', key: 'name', className:"nowrap" }, { title: 'Nama Role', dataIndex: 'name', key: 'name', className:"nowrap" },
{ title: 'Description', dataIndex: 'description', key: 'description' }, { title: 'Description', dataIndex: 'description', key: 'description' },
]; ];
const momentFormat = 'HH:mm'; const momentFormat = 'HH:mm';
const column = [ const column = [
{ name: "Nama" }, { name: "Nama" },
{ name: "Deskripsi" }, { name: "Deskripsi" },
] ]
const LENGTH_DATA = 10 const LENGTH_DATA = 10
export default class index extends Component { export default class index extends Component {
constructor(props) { constructor(props) {
super(props) super(props)
this.state = { this.state = {
dataTable: [], alertDelete: false,
openDialog: false, alertNotDelete: false,
dialogMenuForm: false, currentPage: 1,
typeDialog: 'Save', dataEdit: null,
dataEdit: null, dataExport:[],
alertDelete: false, dataGs: [],
alertNotDelete: false, dataIdHo: [],
idDelete: 0, dataTable: [],
dataGs: [], dialogMenuForm: false,
dataIdHo: [], idDelete: 0,
search: "", idRoles:0,
page: 0, menuRoles:[],
rowsPerPage: LENGTH_DATA, openDialog: false,
currentPage: 1, page: 0,
totalPage: 0, rowsPerPage: LENGTH_DATA,
tooltipEdit: false, search: "",
tooltipDelete: false, tooltipDelete: false,
tooltipMenu: false, tooltipEdit: false,
idRoles:0, tooltipExport:false,
menuRoles:[], tooltipImport:false,
tooltipTambah:false, tooltipMenu: false,
tooltipImport:false, tooltipTambah:false,
tooltipExport:false, totalPage: 0,
dataExport:[] typeDialog: 'Save',
} }
} }
async componentDidMount() { async componentDidMount() {
this.getDataRoles(); this.getDataRoles();
} }
async componentDidUpdate(prevProps, prevState) { async componentDidUpdate(prevProps, prevState) {
const { search } = this.state const { search } = this.state
if (search !== prevState.search) this.getDataRoles() if (search !== prevState.search) this.getDataRoles()
} }
handleSearch = e => { handleSearch = e => {
const value = e.target.value const value = e.target.value
this.setState({ search: value, currentPage: 1 }) this.setState({ search: value, currentPage: 1 })
}; };
getDataRoles = async () => { getDataRoles = async () => {
let start = 0;
let start = 0; if (this.state.currentPage !== 1 && this.state.currentPage > 1) {
start = (this.state.currentPage * this.state.rowsPerPage) - this.state.rowsPerPage
if (this.state.currentPage !== 1 && this.state.currentPage > 1) { }
start = (this.state.currentPage * this.state.rowsPerPage) - this.state.rowsPerPage
} const formData = {
"paging": {"start": start, "length": this.state.rowsPerPage},
const formData = { "columns": [
"paging": {"start": start, "length": this.state.rowsPerPage}, {"name": "name", "logic_operator": "like", "value": this.state.search, "operator": "AND"}
"columns": [ ],
{"name": "name", "logic_operator": "like", "value": this.state.search, "operator": "AND"} "joins": [],
], "orders": {"columns": ["id"], "ascending": false}
"joins": [], }
"orders": {"columns": ["id"], "ascending": false}
} const result = await axios
.post(PROJECT_ROLE_SEARCH, formData, config)
const result = await axios .then(res => res)
.post(PROJECT_ROLE_SEARCH, formData, config) .catch((error) => error.response);
.then(res => res)
.catch((error) => error.response); if(result && result.data && result.data.code == 200){
// console.log(result) this.setState({ dataTable: result.data.data, totalPage: result.data.totalRecord });
}else{
if(result && result.data && result.data.code == 200){ NotificationManager.error('Gagal Mengambil Data!!', 'Failed');
this.setState({ dataTable: result.data.data, totalPage: result.data.totalRecord }); }
}else{ }
NotificationManager.error('Gagal Mengambil Data!!', 'Failed');
} handleOpenDialog = (type) => {
} this.setState({ openDialog: true, typeDialog: type })
this.showChildDialog();
handleOpenDialog = (type) => { }
this.setState({ openDialog: true, typeDialog: type })
this.showChildDialog(); handleCloseDialog = (type, data) => {
} if (type === "save") {
this.saveRole(data);
} else if (type === "edit") {
this.editRole(data);
}
handleCloseDialog = (type, data) => { this.setState({ openDialog: false })
if (type === "save") { }
this.saveRole(data);
} else if (type === "edit") {
this.editRole(data); handleOpenDialogMr = () => {
} this.setState({ dialogMenuForm: true })
this.showMenuRolesDialog();
this.setState({ openDialog: false }) }
} handleCloseDialogMr = (type, data) => {
if(type==="save"){
this.saveMenuRoles(data)
handleOpenDialogMr = () => { }
this.setState({ dialogMenuForm: true }) this.setState({ dialogMenuForm: false })
this.showMenuRolesDialog(); }
}
handleCloseDialogMr = (type, data) => { toggleAddDialog = () => {
if(type==="save"){ this.setState({ openDialog: !this.state.openDialog })
this.saveMenuRoles(data) }
}
this.setState({ dialogMenuForm: false }) onConfirmDelete = async () => {
} const { idDelete } = this.state
const url = PROJECT_ROLE_DELETE(idDelete)
toggleAddDialog = () => {
this.setState({ openDialog: !this.state.openDialog }) const result = await axios.delete(url, config)
} .then(res => res)
.catch((error) => error.response);
onConfirmDelete = async () => {
const { idDelete } = this.state if (result && result.data && result.data.code === 200) {
const url = PROJECT_ROLE_DELETE(idDelete) this.getDataRoles()
this.setState({ idDelete: 0, alertDelete: false })
const result = await axios.delete(url, config) NotificationManager.success(`Data project role berhasil dihapus`, 'Success!!');
.then(res => res) } else {
.catch((error) => error.response); this.setState({ idDelete: 0, alertDelete: false })
NotificationManager.error(`Data project role gagal dihapus`, 'Failed!!');
if (result && result.data && result.data.code === 200) { }
this.getDataRoles() }
this.setState({ idDelete: 0, alertDelete: false })
NotificationManager.success(`Data project role berhasil dihapus`, 'Success!!'); saveRole = async (data) => {
} else {
this.setState({ idDelete: 0, alertDelete: false }) const formData = {
NotificationManager.error(`Data project role gagal dihapus`, 'Failed!!'); name:data.name,
} description:data.description
} }
saveRole = async (data) => { const result = await axios.post(PROJECT_ROLE_ADD, formData, config)
.then(res => res)
const formData = { .catch((error) => error.response);
name:data.name,
description:data.description if(result && result.data && result.data.code===200){
} this.getDataRoles();
NotificationManager.success(`Data project role berhasil ditambah`, 'Success!!');
const result = await axios.post(PROJECT_ROLE_ADD, formData, config) } else {
.then(res => res) NotificationManager.error(`${result.data.message}`, 'Failed!!');
.catch((error) => error.response); }
if(result && result.data && result.data.code===200){ }
this.getDataRoles();
NotificationManager.success(`Data project role berhasil ditambah`, 'Success!!'); editRole = async (data) => {
} else {
NotificationManager.error(`${result.data.message}`, 'Failed!!'); const formData = {
} name:data.name,
description:data.description
} }
const url = PROJECT_ROLE_EDIT(data.id)
editRole = async (data) => { const result = await axios.put(url, formData, config)
.then(res => res)
const formData = { .catch((error) => error.response);
name:data.name,
description:data.description if(result && result.data && result.data.code===200){
} this.getDataRoles();
const url = PROJECT_ROLE_EDIT(data.id) NotificationManager.success(`Data project role berhasil diedit`, 'Success!!');
const result = await axios.put(url, formData, config) } else {
.then(res => res) NotificationManager.error(`Data project role gagal di edit`, `Failed!!`);
.catch((error) => error.response); }
if(result && result.data && result.data.code===200){ }
this.getDataRoles();
NotificationManager.success(`Data project role berhasil diedit`, 'Success!!');
} else { handleEdit = (data) => {
NotificationManager.error(`Data project role gagal di edit`, `Failed!!`); this.setState({ dataEdit: data });
} this.handleOpenDialog('Edit');
}
}
handleDelete = (id) => {
this.setState({ alertDelete: true, idDelete: id });
handleEdit = (data) => { }
this.setState({ dataEdit: data });
this.handleOpenDialog('Edit'); onShowSizeChange = (current, pageSize) => {
} this.setState({ rowsPerPage: pageSize }, () => {
this.getDataRoles();
handleDelete = (id) => { })
this.setState({ alertDelete: true, idDelete: id }); }
}
onPagination = (current, pageSize) => {
onShowSizeChange = (current, pageSize) => { this.setState({ currentPage: current, page: (current - 1) * pageSize }, () => {
this.setState({ rowsPerPage: pageSize }, () => { this.getDataRoles();
this.getDataRoles(); })
}) }
}
toggle = (param) => {
onPagination = (current, pageSize) => { if (param === "edit") {
this.setState({ currentPage: current, page: (current - 1) * pageSize }, () => { this.setState(prevState => ({ tooltipEdit: !prevState.tooltipEdit }))
this.getDataRoles(); } else if (param === "delete") {
}) this.setState(prevState => ({ tooltipDelete: !prevState.tooltipDelete }))
} } else if(param === "menu"){
this.setState(prevState => ({ tooltipMenu: !prevState.tooltipMenu }))
toggle = (param) => { } else if (param === "tambah") {
if (param === "edit") { this.setState(prevState => ({ tooltipTambah: !prevState.tooltipTambah }))
this.setState(prevState => ({ tooltipEdit: !prevState.tooltipEdit })) } else if (param === "export") {
} else if (param === "delete") { this.setState(prevState => ({ tooltipExport: !prevState.tooltipExport }))
this.setState(prevState => ({ tooltipDelete: !prevState.tooltipDelete })) }
} else if(param === "menu"){ }
this.setState(prevState => ({ tooltipMenu: !prevState.tooltipMenu }))
} else if (param === "tambah") { dataNotAvailable = () => {
this.setState(prevState => ({ tooltipTambah: !prevState.tooltipTambah })) if(this.state.dataTable.length===0){
} else if (param === "export") { return (
this.setState(prevState => ({ tooltipExport: !prevState.tooltipExport })) <tr>
} <td align="center" colSpan="3">Tidak ada data project role</td>
} </tr>
)
dataNotAvailable = () => { }
if(this.state.dataTable.length===0){ }
return (
<tr> handleExportExcel = async () => {
<td align="center" colSpan="3">Tidak ada data project role</td> const payload = {
</tr> "paging": {"start": 0, "length": -1},
) "columns": [
} {"name": "name", "logic_operator": "like", "value": this.state.search, "operator": "AND"}
} ],
"joins": [],
handleExportExcel = async () => { "orders": {"columns": ["id"], "ascending": false}
const payload = { }
"paging": {"start": 0, "length": -1}, const result = await axios
"columns": [ .post(PROJECT_ROLE_SEARCH, payload)
{"name": "name", "logic_operator": "like", "value": this.state.search, "operator": "AND"} .then(res => res)
], .catch((error) => error.response);
"joins": [], if (result && result.data && result.statusText == "OK") {
"orders": {"columns": ["id"], "ascending": false} const dataRes = result.data.data|| [];
} console.log("data result", dataRes);
// console.log("test", url); const dataExport = [];
const result = await axios dataRes.map((val,index)=> {
.post(PROJECT_ROLE_SEARCH, payload) let row = {
.then(res => res) Nama:val.name,
.catch((error) => error.response); Deskripsi:val.description
// console.log("result", result); }
if (result && result.data && result.statusText == "OK") { dataExport.push(row);
const dataRes = result.data.data|| []; })
console.log("data result", dataRes); this.setState({ dataExport:dataExport },()=> {
const dataExport = []; this.exportExcel();
// <td>{n.name}</td> });
// <td>{n.url}</td> } else {
// <td>{n.alias_name}</td> NotificationManager.error('Failed retreiving data!!', 'Failed');
// <td>{n.icon}</td> }
// <td>{n.parent_name || "-"}</td> }
dataRes.map((val,index)=> {
let row = { exportExcel = () => {
Nama:val.name, const dataExcel = this.state.dataExport || [];
Deskripsi:val.description const fileName = "Data Project Role.xlsx";
} const ws = XLSX.utils.json_to_sheet(dataExcel);
dataExport.push(row);
})
console.log("data Export", dataExport);
this.setState({ dataExport:dataExport },()=> {
this.exportExcel();
});
} else {
NotificationManager.error('Failed retreiving data!!', 'Failed');
}
}
exportExcel = () => {
const dataExcel = this.state.dataExport || [];
const fileName = "Data Project Role.xlsx";
const ws = XLSX.utils.json_to_sheet(dataExcel);
const wb = XLSX.utils.book_new(); const wb = XLSX.utils.book_new();
XLSX.utils.book_append_sheet(wb, ws, 'Data Project Role'); XLSX.utils.book_append_sheet(wb, ws, 'Data Project Role');
XLSX.writeFile(wb, fileName); XLSX.writeFile(wb, fileName);
} }
render() { render() {
const { tooltipTambah,tooltipExport,dialogMenuForm, dataTable, openDialog, currentPage, rowsPerPage, totalPage, search, tooltipEdit, tooltipDelete,tooltipMenu } = this.state const { tooltipTambah,tooltipExport,dialogMenuForm, dataTable, openDialog, currentPage, rowsPerPage, totalPage, search, tooltipEdit, tooltipDelete,tooltipMenu } = this.state
let noSeq = 0; let noSeq = 0;
return ( return (
<div> <div>
<NotificationContainer /> <NotificationContainer />
<SweetAlert <SweetAlert
show={this.state.alertDelete} show={this.state.alertDelete}
warning warning
showCancel showCancel
confirmBtnText="Delete" confirmBtnText="Delete"
confirmBtnBsStyle="danger" confirmBtnBsStyle="danger"
title="Are you sure?" title="Are you sure?"
onConfirm={this.onConfirmDelete} onConfirm={this.onConfirmDelete}
onCancel={() => this.setState({ alertDelete: false, idDelete: 0 })} onCancel={() => this.setState({ alertDelete: false, idDelete: 0 })}
focusCancelBtn focusCancelBtn
> >
Data project role akan terhapus!! Data project role akan terhapus!!
</SweetAlert> </SweetAlert>
<SweetAlert <SweetAlert
show={this.state.alertNotDelete} show={this.state.alertNotDelete}
warning warning
// showCancel confirmBtnText="Can't Delete"
confirmBtnText="Can't Delete" confirmBtnBsStyle="danger"
confirmBtnBsStyle="danger" title="Data can't be delete!"
title="Data can't be delete!" onConfirm={() => this.setState({ alertNotDelete: false})}
onConfirm={() => this.setState({ alertNotDelete: false})} >
// focusCancelBtn Data project role tidak dapat di hapus!!
> </SweetAlert>
Data project role tidak dapat di hapus!! <DialogForm
</SweetAlert> openDialog={openDialog}
<DialogForm closeDialog={this.handleCloseDialog}
openDialog={openDialog} toggleDialog={() => this.toggleAddDialog}
closeDialog={this.handleCloseDialog} typeDialog={this.state.typeDialog}
toggleDialog={() => this.toggleAddDialog} dataEdit={this.state.dataEdit}
typeDialog={this.state.typeDialog} showDialog={showDialog => this.showChildDialog = showDialog}
dataEdit={this.state.dataEdit} dataHs={this.state.dataIdHo}
showDialog={showDialog => this.showChildDialog = showDialog} />
dataHs={this.state.dataIdHo} <Card>
/> <CardHeader style={{ display: "flex", justifyContent: "space-between" }}>
{/* <DialogMenuRoles <h4>{this.props.params.name}</h4>
openDialog={dialogMenuForm} <Row>
closeDialog={this.handleCloseDialogMr} <Col>
idRoles={this.state.idRoles} <Input onChange={this.handleSearch} value={search} type="text" name="search" id="search" placeholder="Cari Nama Project Role" />
showDialog={showDialog => this.showMenuRolesDialog = showDialog} </Col>
menuRoles={this.state.menuRoles} <Col>
<Tooltip title="Tambah Roles">
/> */} <Button id="TooltipTambah" color="success" onClick={() => this.handleOpenDialog('Save')}><i className="fa fa-plus"></i></Button>
<Card> </Tooltip>
<CardHeader style={{ display: "flex", justifyContent: "space-between" }}> <Tooltip title="Export Excel">
<h4>{this.props.params.name}</h4> <Button style={{marginLeft:"5px"}} id="TooltipExport" color="primary" onClick={()=> this.handleExportExcel()}><i className="fa fa-print"></i></Button>
<Row> </Tooltip>
<Col> </Col>
<Input onChange={this.handleSearch} value={search} type="text" name="search" id="search" placeholder="Cari Nama Project Role" /> </Row>
</Col> </CardHeader>
<Col> <CardBody>
<Tooltip title="Tambah Roles"> <Table
<Button id="TooltipTambah" color="success" onClick={() => this.handleOpenDialog('Save')}><i className="fa fa-plus"></i></Button> rowKey="id"
</Tooltip> size="small"
<Tooltip title="Export Excel"> columns={columns}
<Button style={{marginLeft:"5px"}} id="TooltipExport" color="primary" onClick={()=> this.handleExportExcel()}><i className="fa fa-print"></i></Button> dataSource={dataTable}
</Tooltip> pagination={false}
</Col> bordered={false}
</Row> />
</CardHeader> <Pagination
<CardBody> style={{marginTop:"25px"}}
{/* <Table responsive striped hover> showSizeChanger
<thead> onShowSizeChange={this.onShowSizeChange}
<tr> onChange={this.onPagination}
<th>Aksi</th> defaultCurrent={currentPage}
{column.map((i, index) => { pageSize={rowsPerPage}
return ( total={totalPage}
<th key={index} scope="row">{i.name}</th> pageSizeOptions={["10", "15", "20", "25", "30", "35", "40"]}
) />
})} </CardBody>
</tr> </Card>
</thead> </div>
<tbody> )
{this.dataNotAvailable()} }
{dataTable.map((n, index) => {
return (
<tr key={n.id}>
<td className='nowrap'>
<Tooltip title="Hapus">
<i id="TooltipDelete" className="cil-trash fa-lg" style={{ color: 'red', marginRight: 10, cursor: "pointer" }} onClick={() => this.handleDelete(n.id)}></i>
</Tooltip>
<Tooltip title="Edit">
<i id="TooltipEdit" className="cil-pencil fa-lg" style={{ color: 'green', cursor: "pointer" }} onClick={() => this.handleEdit(n)}></i>
</Tooltip>
</td>
<td>{n.name}</td>
<td>{n.description}</td>
</tr>
)
})}
</tbody>
</Table> */}
<Table
rowKey="id"
size="small"
columns={columns}
dataSource={dataTable}
pagination={false}
bordered={false}
/>
<Pagination
style={{marginTop:"25px"}}
showSizeChanger
onShowSizeChange={this.onShowSizeChange}
onChange={this.onPagination}
defaultCurrent={currentPage}
pageSize={rowsPerPage}
total={totalPage}
pageSizeOptions={["10", "15", "20", "25", "30", "35", "40"]}
/>
</CardBody>
</Card>
</div>
)
}
} }

53
src/views/SimproV2/ChecklistK3/index.js

@ -1,9 +1,9 @@
import React, { useState, useEffect, useMemo } from 'react';
import { Card, CardBody, CardHeader, Col, Row, Input, Table } from 'reactstrap';
import axios from "../../../const/interceptorApi"
import * as XLSX from 'xlsx'; import * as XLSX from 'xlsx';
import SweetAlert from 'react-bootstrap-sweetalert';
import DialogForm from './DialogForm'; import DialogForm from './DialogForm';
import React, { useState, useEffect, useMemo } from 'react';
import SweetAlert from 'react-bootstrap-sweetalert';
import axios from "../../../const/interceptorApi"
import { Card, CardBody, CardHeader, Col, Row, Input, Table } from 'reactstrap';
import { NotificationContainer, NotificationManager } from 'react-notifications'; import { NotificationContainer, NotificationManager } from 'react-notifications';
import { Pagination, Button, Tooltip } from 'antd'; import { Pagination, Button, Tooltip } from 'antd';
import { import {
@ -18,12 +18,10 @@ const config = {
"Content-type": `application/json` "Content-type": `application/json`
} }
}; };
const column = [ const column = [
{ name: "Nama" }, { name: "Nama" },
{ name: "Deskripsi" }, { name: "Deskripsi" },
] ]
const ChecklistK3 = ({ params }) => { const ChecklistK3 = ({ params }) => {
const token = localStorage.getItem("token") const token = localStorage.getItem("token")
const HEADER = { const HEADER = {
@ -32,20 +30,21 @@ const ChecklistK3 = ({ params }) => {
"Authorization": `Bearer ${token}` "Authorization": `Bearer ${token}`
} }
} }
const pageName = params.name; const pageName = params.name;
const [search, setSearch] = useState('') const [alertDelete, setAlertDelete] = useState(false)
const [allDataMenu, setAllDataMenu] = useState([])
const [clickOpenModal, setClickOpenModal] = useState(false)
const [currentPage, setCurrentPage] = useState(1) const [currentPage, setCurrentPage] = useState(1)
const [openDialog, setOpenDialog] = useState(false)
const [typeDialog, setTypeDialog] = useState('Save')
const [dataExport, setDataExport] = useState([])
const [rowsPerPage, setRowsPerPage] = useState(10)
const [dataEdit, setDataEdit] = useState([]) const [dataEdit, setDataEdit] = useState([])
const [alertDelete, setAlertDelete] = useState(false) const [dataExport, setDataExport] = useState([])
const [idDelete, setIdDelete] = useState(0)
const [dataTable, setDatatable] = useState([]) const [dataTable, setDatatable] = useState([])
const [clickOpenModal, setClickOpenModal] = useState(false) const [idDelete, setIdDelete] = useState(0)
const [allDataMenu, setAllDataMenu] = useState([]) const [openDialog, setOpenDialog] = useState(false)
const [rowsPerPage, setRowsPerPage] = useState(10)
const [search, setSearch] = useState('')
const [totalPage, setTotalPage] = useState(0) const [totalPage, setTotalPage] = useState(0)
const [typeDialog, setTypeDialog] = useState('Save')
useEffect(() => { useEffect(() => {
getDataChecklistK3() getDataChecklistK3()
@ -86,17 +85,12 @@ const ChecklistK3 = ({ params }) => {
"start": start "start": start
} }
} }
// console.log("payload ", payload)
const result = await axios const result = await axios
.post(CHECKLIST_K3_SEARCH, payload, config) .post(CHECKLIST_K3_SEARCH, payload, config)
.then(res => res) .then(res => res)
.catch((error) => error.response); .catch((error) => error.response);
if (result && result.data && result.data.code == 200) { if (result && result.data && result.data.code == 200) {
console.log("get data ", result.data)
setDatatable(result.data.data); setDatatable(result.data.data);
setTotalPage(result.data.totalRecord); setTotalPage(result.data.totalRecord);
} else { } else {
@ -116,7 +110,6 @@ const ChecklistK3 = ({ params }) => {
} }
const handleExportExcel = async () => { const handleExportExcel = async () => {
console.log("cek cek cek cke")
const payload = { const payload = {
"paging": { "start": 0, "length": -1 }, "paging": { "start": 0, "length": -1 },
"columns": [ "columns": [
@ -126,15 +119,11 @@ const ChecklistK3 = ({ params }) => {
"orders": { "columns": ["id"], "ascending": false } "orders": { "columns": ["id"], "ascending": false }
} }
const result = await axios const result = await axios
.post(CHECKLIST_K3_SEARCH, payload, config) .post(CHECKLIST_K3_SEARCH, payload, config)
.then(res => res) .then(res => res)
.catch((error) => error.response); .catch((error) => error.response);
// console.log(result)
if (result && result.data && result.data.code == 200) { if (result && result.data && result.data.code == 200) {
let resData = result.data.data; let resData = result.data.data;
const excelData = []; const excelData = [];
@ -145,9 +134,7 @@ const ChecklistK3 = ({ params }) => {
} }
excelData.push(dataRow) excelData.push(dataRow)
}) })
// console.log("cek excel data", resData)
await setDataExport(excelData); await setDataExport(excelData);
// exportExcel();
} else { } else {
NotificationManager.error('Gagal Export Data!!', 'Failed'); NotificationManager.error('Gagal Export Data!!', 'Failed');
} }
@ -155,7 +142,6 @@ const ChecklistK3 = ({ params }) => {
const exportExcel = () => { const exportExcel = () => {
const dataExcel = dataExport || []; const dataExcel = dataExport || [];
console.log("cek data excel", dataExcel)
const fileName = `Data ${pageName}.xlsx`; const fileName = `Data ${pageName}.xlsx`;
const ws = XLSX.utils.json_to_sheet(dataExcel); const ws = XLSX.utils.json_to_sheet(dataExcel);
const wb = XLSX.utils.book_new(); const wb = XLSX.utils.book_new();
@ -191,7 +177,7 @@ const ChecklistK3 = ({ params }) => {
.catch((error) => error.response); .catch((error) => error.response);
if (result && result.data && result.data.code === 200) { if (result && result.data && result.data.code === 200) {
getDataChecklistK3() getDataChecklistK3()
NotificationManager.success(`Data project type berhasil ditambah`, 'Success!!'); NotificationManager.success(`Data project type berhasil ditambah`, 'Success!!');
} else { } else {
NotificationManager.error(`${result.data.message}`, 'Failed!!'); NotificationManager.error(`${result.data.message}`, 'Failed!!');
@ -202,9 +188,6 @@ const ChecklistK3 = ({ params }) => {
let urlEdit = CHECKLIST_K3_EDIT(data.id) let urlEdit = CHECKLIST_K3_EDIT(data.id)
const formData = data const formData = data
console.log("from data edit ", formData)
const result = await axios.put(urlEdit, formData, HEADER) const result = await axios.put(urlEdit, formData, HEADER)
.then(res => res) .then(res => res)
.catch((error) => error.response); .catch((error) => error.response);
@ -263,8 +246,6 @@ const ChecklistK3 = ({ params }) => {
} }
} }
return ( return (
<div> <div>
<NotificationContainer /> <NotificationContainer />
@ -325,11 +306,9 @@ const ChecklistK3 = ({ params }) => {
return ( return (
<tr key={n.id}> <tr key={n.id}>
<td className='nowrap'> <td className='nowrap'>
<Tooltip title="Hapus"> <Tooltip title="Hapus">
<i id="TooltipDelete" className="cil-trash fa-lg" style={{ color: 'red', marginRight: 10, cursor: "pointer" }} onClick={() => handleDelete(n.id)}></i> <i id="TooltipDelete" className="cil-trash fa-lg" style={{ color: 'red', marginRight: 10, cursor: "pointer" }} onClick={() => handleDelete(n.id)}></i>
</Tooltip> </Tooltip>
<Tooltip title="Edit"> <Tooltip title="Edit">
<i id="TooltipEdit" className="cil-pencil fa-lg" style={{ color: 'green', cursor: "pointer" }} onClick={() => handleEdit(n)}></i> <i id="TooltipEdit" className="cil-pencil fa-lg" style={{ color: 'green', cursor: "pointer" }} onClick={() => handleEdit(n)}></i>
</Tooltip> </Tooltip>
@ -356,4 +335,4 @@ const ChecklistK3 = ({ params }) => {
) )
} }
export default ChecklistK3; export default ChecklistK3;

167
src/views/SimproV2/Closing/index.js

@ -1,15 +1,15 @@
import * as XLSX from 'xlsx';
import DialogForm from './DialogForm';
import React, { useState, useEffect, useMemo } from 'react'; import React, { useState, useEffect, useMemo } from 'react';
import SweetAlert from 'react-bootstrap-sweetalert';
import axios from "../../../const/interceptorApi";
import moment from 'moment'
import { BASE_SIMPRO, PROYEK_ADD, PROYEK_SEARCH, PROYEK_EDIT, PROYEK_DELETE } from '../../../const/ApiConst';
import { Card, CardBody, CardHeader, Col, Row, Input } from 'reactstrap'; import { Card, CardBody, CardHeader, Col, Row, Input } from 'reactstrap';
import { DownloadOutlined } from '@ant-design/icons'; import { DownloadOutlined } from '@ant-design/icons';
import axios from "../../../const/interceptorApi";
import * as XLSX from 'xlsx';
import SweetAlert from 'react-bootstrap-sweetalert';
import DialogForm from './DialogForm';
import { NotificationContainer, NotificationManager } from 'react-notifications'; import { NotificationContainer, NotificationManager } from 'react-notifications';
import { Pagination, Table, Button, Tooltip } from 'antd'; import { Pagination, Table, Button, Tooltip } from 'antd';
import { BASE_SIMPRO, PROYEK_ADD, PROYEK_SEARCH, PROYEK_EDIT, PROYEK_DELETE } from '../../../const/ApiConst';
import { formatRupiah } from '../../../const/CustomFunc' import { formatRupiah } from '../../../const/CustomFunc'
import moment from 'moment'
const url = ""; const url = "";
const proyek_id = localStorage.getItem('proyek_id'); const proyek_id = localStorage.getItem('proyek_id');
@ -25,29 +25,29 @@ const Closing = ({ params, ...props }) => {
} }
} }
const [idTask, setidTask] = useState(0); const [alertClose, setAlertClose] = useState(false)
const [dataTable, setDatatable] = useState([]) const [alertDelete, setAlertDelete] = useState(false)
const [search, setSearch] = useState('') const [allDataMenu, setAllDataMenu] = useState([])
const [clickOpenModal, setClickOpenModal] = useState(false)
const [currentPage, setCurrentPage] = useState(1) const [currentPage, setCurrentPage] = useState(1)
const [totalPage, setTotalPage] = useState(0) const [dataCharter, setDataCharter] = useState(null)
const [dataEdit, setDataEdit] = useState([])
const [dataEditSub, setDataEditSub] = useState([])
const [dataExport, setDataExport] = useState([])
const [dataTable, setDatatable] = useState([])
const [dataView, setDataView] = useState([])
const [idDelete, setIdDelete] = useState(0)
const [idTask, setidTask] = useState(0);
const [openDialog, setOpenDialog] = useState(false) const [openDialog, setOpenDialog] = useState(false)
const [openDialogMap, setOpenDialogMap] = useState(false)
const [openDialogResource, setOpenDialogResource] = useState(false) const [openDialogResource, setOpenDialogResource] = useState(false)
const [openDialogViewDetail, setOpenDialogViewDetail] = useState(false) const [openDialogViewDetail, setOpenDialogViewDetail] = useState(false)
const [openDialogMap, setOpenDialogMap] = useState(false) const [rowsPerPage, setRowsPerPage] = useState(10)
const [search, setSearch] = useState('')
const [totalPage, setTotalPage] = useState(0)
const [typeDialog, setTypeDialog] = useState('Save'); const [typeDialog, setTypeDialog] = useState('Save');
const [typeDialogSub, setTypeDialogSub] = useState('Save') const [typeDialogSub, setTypeDialogSub] = useState('Save')
const [idDelete, setIdDelete] = useState(0)
const [alertDelete, setAlertDelete] = useState(false)
const [alertClose, setAlertClose] = useState(false)
const [dataEdit, setDataEdit] = useState([])
const [dataEditSub, setDataEditSub] = useState([])
const [rowsPerPage, setRowsPerPage] = useState(10)
const [clickOpenModal, setClickOpenModal] = useState(false)
const [dataExport, setDataExport] = useState([])
const [allDataMenu, setAllDataMenu] = useState([])
const [userProyek, setUserProyek] = useState([]); const [userProyek, setUserProyek] = useState([]);
const [dataCharter, setDataCharter] = useState(null)
const [dataView, setDataView] = useState([])
const pageName = params.name; const pageName = params.name;
useEffect(() => { useEffect(() => {
@ -62,7 +62,6 @@ const Closing = ({ params, ...props }) => {
const getDataProyek = async () => { const getDataProyek = async () => {
let start = 0; let start = 0;
if (currentPage !== 1 && currentPage > 1) { if (currentPage !== 1 && currentPage > 1) {
@ -76,7 +75,6 @@ const Closing = ({ params, ...props }) => {
"joins": [ "joins": [
{ "name": "m_users", "column_join": "pm_id", "column_results": ["name", "username"] }, { "name": "m_users", "column_join": "pm_id", "column_results": ["name", "username"] },
{ "name": "m_type_proyek", "column_join": "type_proyek_id", "column_results": ["name", "description"] }, { "name": "m_type_proyek", "column_join": "type_proyek_id", "column_results": ["name", "description"] },
// { "name": "subproyeks.m_subproyek", "column_join": "parent_id", "column_results": ["nama", "biaya", "color_progress", "jumlah_pekerja", "pic", "mulai_proyek", "akhir_proyek", "biaya_actual", "persentase_progress_plan", "persentase_progress_actual"] }
], ],
"orders": { "columns": ["id"], "ascending": true }, "orders": { "columns": ["id"], "ascending": true },
"paging": { "start": 0, "length": 25 } "paging": { "start": 0, "length": 25 }
@ -89,18 +87,13 @@ const Closing = ({ params, ...props }) => {
] ]
} }
// console.log("cek payload", payload)
const URL = `${BASE_SIMPRO}/proyek/search-detail` const URL = `${BASE_SIMPRO}/proyek/search-detail`
const result = await axios const result = await axios
.post(URL, payload, HEADER) .post(URL, payload, HEADER)
.then(res => res) .then(res => res)
.catch((error) => error.response); .catch((error) => error.response);
// console.log("data sub proyek", result)
if (result && result.data && result.data.code == 200) { if (result && result.data && result.data.code == 200) {
console.log("cek proyek", result.data.data)
let dataRes = result.data.data || [] let dataRes = result.data.data || []
setDatatable(dataRes); setDatatable(dataRes);
@ -122,7 +115,6 @@ const Closing = ({ params, ...props }) => {
} }
const handleOpenDialogViewDetail = (data) => { const handleOpenDialogViewDetail = (data) => {
console.log('handleOpenDialogViewDetail', data);
setOpenDialogViewDetail(true) setOpenDialogViewDetail(true)
setidTask(data.id) setidTask(data.id)
setDataView(data) setDataView(data)
@ -138,18 +130,10 @@ const Closing = ({ params, ...props }) => {
} }
const handleCloseDialogResource = (type, payload) => { const handleCloseDialogResource = (type, payload) => {
// if (type === "add") saveProyek(payload);
// if (type === "edit") editProyek(payload);
setOpenDialogResource(false) setOpenDialogResource(false)
} }
const handleCloseDialogView = (type, payload) => { const handleCloseDialogView = (type, payload) => {
// if (type === "add") saveProyek(payload);
// if (type === "edit") editProyek(payload);
setOpenDialogViewDetail(false) setOpenDialogViewDetail(false)
} }
@ -164,7 +148,6 @@ const Closing = ({ params, ...props }) => {
const result = await axios.delete(urlDel, HEADER) const result = await axios.delete(urlDel, HEADER)
.then(res => res) .then(res => res)
.catch((error) => error.response); .catch((error) => error.response);
if (result && result.data && result.data.code === 200) { if (result && result.data && result.data.code === 200) {
getDataProyek() getDataProyek()
setIdDelete(0) setIdDelete(0)
@ -178,21 +161,6 @@ const Closing = ({ params, ...props }) => {
} }
const onConfirmClose = async () => { const onConfirmClose = async () => {
// let urlDel = PROYEK_DELETE(idDelete)
// const result = await axios.delete(urlDel, HEADER)
// .then(res => res)
// .catch((error) => error.response);
// if (result && result.data && result.data.code === 200) {
// getDataProyek()
// setIdDelete(0)
// setAlertDelete(false)
// NotificationManager.success(`Data proyek berhasil dihapus`, 'Success!!');
// } else {
// setIdDelete(0)
// setAlertDelete(false)
// NotificationManager.error(`Data proyek gagal dihapus`, 'Failed!!');
// }
setIdDelete(0) setIdDelete(0)
setAlertClose(false) setAlertClose(false)
NotificationManager.success(`Data proyek berhasil diclose`, 'Success!!'); NotificationManager.success(`Data proyek berhasil diclose`, 'Success!!');
@ -215,7 +183,6 @@ const Closing = ({ params, ...props }) => {
} }
const editProyek = async (data) => { const editProyek = async (data) => {
let urlEdit = PROYEK_EDIT(data.id) let urlEdit = PROYEK_EDIT(data.id)
const formData = data const formData = data
@ -229,19 +196,14 @@ const Closing = ({ params, ...props }) => {
} else { } else {
NotificationManager.error(`Data proyek gagal di edit`, `Failed!!`); NotificationManager.error(`Data proyek gagal di edit`, `Failed!!`);
} }
} }
const handleDelete = async (id) => { const handleDelete = async (id) => {
// console.log('Delete')
await setAlertDelete(true) await setAlertDelete(true)
await setIdDelete(id) await setIdDelete(id)
} }
const handleCloseProject = async (id) => { const handleCloseProject = async (id) => {
// console.log('Delete')
await setAlertClose(true) await setAlertClose(true)
await setIdDelete(id) await setIdDelete(id)
} }
@ -258,9 +220,6 @@ const Closing = ({ params, ...props }) => {
const payload = { const payload = {
"paging": { "start": 0, "length": -1 }, "paging": { "start": 0, "length": -1 },
// "columns": [
// { "name": "nama", "logic_operator": "like", "value": search, "operator": "AND" }
// ],
"joins": [], "joins": [],
"orders": { "columns": ["id"], "ascending": false } "orders": { "columns": ["id"], "ascending": false }
} }
@ -271,25 +230,14 @@ const Closing = ({ params, ...props }) => {
] ]
} }
const result = await axios const result = await axios
.post(PROYEK_SEARCH, payload, HEADER) .post(PROYEK_SEARCH, payload, HEADER)
.then(res => res) .then(res => res)
.catch((error) => error.response); .catch((error) => error.response);
// console.log(result)
if (result && result.data && result.data.code == 200) { if (result && result.data && result.data.code == 200) {
let resData = result.data.data; let resData = result.data.data;
const excelData = []; const excelData = [];
// <td>{n.nama}</td>
// <td>{n.biaya}</td>
// <td style={{textAlign:"center"}}><div style={{borderRadius:"50%",height:"25px",width:"25px",backgroundColor:n.color_progress}}></div></td>
// <td>{n.jumlah_pekerja}</td>
// <td>{n.pic}</td>
// <td>{n.mulai_proyek ? moment(n.mulai_proyek).format("DD-MM-YYYY") : "-"}</td>
// <td>{n.akhir_proyek ? moment(n.akhir_proyek).format("DD-MM-YYYY") : "-"}</td>
resData.map((n, index) => { resData.map((n, index) => {
let dataRow = { let dataRow = {
"Nama Proyek": n.nama, "Nama Proyek": n.nama,
@ -301,9 +249,7 @@ const Closing = ({ params, ...props }) => {
} }
excelData.push(dataRow) excelData.push(dataRow)
}) })
// console.log("cek excel data", excelData)
await setDataExport(excelData); await setDataExport(excelData);
// exportExcel();
} else { } else {
NotificationManager.error('Gagal Export Data!!', 'Failed'); NotificationManager.error('Gagal Export Data!!', 'Failed');
} }
@ -339,10 +285,8 @@ const Closing = ({ params, ...props }) => {
} }
const handleClickGantt = (id) => { const handleClickGantt = (id) => {
// props.history.push("/gantt")
props.history.push({ props.history.push({
pathname: '/gantt', pathname: '/gantt',
// search: `?proyek_id=${id}`,
state: { proyek_id: id } state: { proyek_id: id }
}) })
} }
@ -354,24 +298,6 @@ const Closing = ({ params, ...props }) => {
dataIndex: '', dataIndex: '',
key: 'x', key: 'x',
render: (text, record) => <> render: (text, record) => <>
{/* <Tooltip title="View Project">
<Button size="small" type="link" style={{ color: 'blue' }} onClick={() => handleOpenDialogViewDetail(text)}><i className="fa fa-eye"></i></Button>
</Tooltip>
<Tooltip title="Add Resources">
<Button size="small" type="link" style={{ color: 'green' }} onClick={() => handleOpenDialogResource(text)}><i className="fa fa-plus"></i></Button>
</Tooltip>
<Tooltip title="Gantt">
<Button size="small" type="link" style={{ color: 'lightblue' }} onClick={() => handleClickGantt(text.id)}><i className="fa fa-bars"></i></Button>
</Tooltip>
<Tooltip title="Edit Proyek">
<Button size="small" type="link" style={{ color: 'orange' }} onClick={() => handleOpenDialog(text.id)}><i className="fa fa-edit"></i></Button>
</Tooltip>
<Tooltip title="Hapus Proyek">
<Button size="small" type="link" style={{ color: 'red' }} onClick={() => handleDelete(text.id)}><i className="fa fa-trash"></i></Button>
</Tooltip> */}
{/* <Tooltip title="Close">
<Button size="small" type="link" style={{ color: 'green' }} onClick={() => handleCloseProject(text.id)}><i className="fa fa-close"></i></Button>
</Tooltip> */}
<Tooltip title="Report"> <Tooltip title="Report">
<Button size="small" type="link" style={{ color: 'orange' }} onClick={() => handleOpenDialog(text.id)}><i className="fa fa-print"></i></Button> <Button size="small" type="link" style={{ color: 'orange' }} onClick={() => handleOpenDialog(text.id)}><i className="fa fa-print"></i></Button>
</Tooltip> </Tooltip>
@ -406,10 +332,6 @@ const Closing = ({ params, ...props }) => {
<Table <Table
size="small" size="small"
columns={columns} columns={columns}
// expandable={{
// expandedRowRender: record => <SubProyekComp getDataProyek={getDataProyek} idParentTask={record.id} nameProyek={record.nama} data={record.subproyeks2} />,
// rowExpandable: record => record.subproyeks2,
// }}
dataSource={dataTable} dataSource={dataTable}
/> />
) )
@ -424,43 +346,9 @@ const Closing = ({ params, ...props }) => {
/> />
), [openDialog]) ), [openDialog])
// const RenderDialogFormResources = useMemo(() => (
// <DialogFormResource
// openDialog={openDialogResource}
// closeDialog={handleCloseDialogResource}
// toggleDialog={() => toggleAddDialogResource}
// idTask={idTask}
// userProyek={userProyek}
// />
// ), [openDialogResource])
// const ViewProyek = useMemo(() => (
// <ViewProject
// openDialog={openDialogViewDetail}
// closeDialog={handleCloseDialogView}
// toggleDialog={() => toggleAddDialogView}
// idTask={idTask}
// dataView={dataView}
// dataCharter={dataCharter}
// />
// ), [openDialogViewDetail])
return ( return (
<div> <div>
<NotificationContainer /> <NotificationContainer />
{/* <SweetAlert
show={alertDelete}
warning
showCancel
confirmBtnText="Delete"
confirmBtnBsStyle="danger"
title={`Are you sure?`}
onConfirm={onConfirmDelete}
onCancel={() => cancelDelete()}
focusCancelBtn
>
Delete this data
</SweetAlert> */}
<SweetAlert <SweetAlert
show={alertClose} show={alertClose}
warning warning
@ -482,18 +370,9 @@ const Closing = ({ params, ...props }) => {
<Col> <Col>
<Input onChange={handleSearch} value={search} type="text" name="search" id="search" placeholder={`Cari nama proyek`} /> <Input onChange={handleSearch} value={search} type="text" name="search" id="search" placeholder={`Cari nama proyek`} />
</Col> </Col>
{/* <Col>
<Tooltip title="Tambah Proyek">
<Button style={{ background: "#4caf50", color: "#fff" }} onClick={() => handleOpenDialog(0)}><i className="fa fa-plus"></i></Button>
</Tooltip>
<Tooltip title="Export Excel">
<Button style={{ marginLeft: "5px" }} onClick={() => handleExportExcel()}><i className="fa fa-print"></i></Button>
</Tooltip>
</Col> */}
</Row> </Row>
</CardHeader> </CardHeader>
<CardBody> <CardBody>
{RenderTable} {RenderTable}
</CardBody> </CardBody>
</Card> </Card>
@ -501,4 +380,4 @@ const Closing = ({ params, ...props }) => {
) )
} }
export default Closing; export default Closing;

13
src/views/SimproV2/ControlMonitoring/index.js

@ -1,11 +1,11 @@
import * as XLSX from 'xlsx';
import React, { useState, useEffect, useMemo } from 'react'; import React, { useState, useEffect, useMemo } from 'react';
import SweetAlert from 'react-bootstrap-sweetalert';
import axios from "../../../const/interceptorApi";
import moment from 'moment'
import { Card, CardBody, CardHeader, Col, Row, Input } from 'reactstrap'; import { Card, CardBody, CardHeader, Col, Row, Input } from 'reactstrap';
import { DownloadOutlined } from '@ant-design/icons'; import { DownloadOutlined } from '@ant-design/icons';
import axios from "../../../const/interceptorApi";
import * as XLSX from 'xlsx';
import SweetAlert from 'react-bootstrap-sweetalert';
import { NotificationContainer, NotificationManager } from 'react-notifications'; import { NotificationContainer, NotificationManager } from 'react-notifications';
import moment from 'moment'
const ControlMonitoring = ({params}) => { const ControlMonitoring = ({params}) => {
const token = localStorage.getItem("token") const token = localStorage.getItem("token")
@ -18,12 +18,11 @@ const ControlMonitoring = ({params}) => {
useEffect(() => { useEffect(() => {
}, []) }, [])
return ( return (
<div> <div>
<NotificationContainer /> <NotificationContainer />
</div> </div>
) )
} }
export default ControlMonitoring; export default ControlMonitoring;

141
src/views/SimproV2/CreatedProyek/index.js

@ -1,12 +1,24 @@
import React, { useState, useEffect, useMemo } from 'react';
import { Card, CardBody, CardHeader, Col, Row, Input } from 'reactstrap';
import axios from "../../../const/interceptorApi"
import * as XLSX from 'xlsx'; import * as XLSX from 'xlsx';
import SweetAlert from 'react-bootstrap-sweetalert'; import AssignHrProject from './AsignHrProject';
import AssignK3Project from './AssignK3Project';
import DialogDocument from './DialogDocument';
import DialogForm from './DialogForm'; import DialogForm from './DialogForm';
import DialogFormMaterial from './DataRequestMaterial';
import DialogFormProyek from './DialogFormProyek'; import DialogFormProyek from './DialogFormProyek';
import DialogGantt from './DialogGantt';
import DialogInitDocument from './DialogInitDocument';
import DialogTableTools from './DialogTableTools';
import React, { useState, useEffect, useMemo } from 'react';
import SweetAlert from 'react-bootstrap-sweetalert';
import ViewProject from './ViewProject';
import axios from "../../../const/interceptorApi"
import moment from 'moment'
import { Card, CardBody, CardHeader, Col, Row, Input } from 'reactstrap';
import { Icon } from '@iconify/react';
import { Link } from 'react-router-dom';
import { NotificationContainer, NotificationManager } from 'react-notifications'; import { NotificationContainer, NotificationManager } from 'react-notifications';
import { Pagination, Table, Button, Tooltip, Popover, Skeleton, Divider } from 'antd'; import { Pagination, Table, Button, Tooltip, Popover, Skeleton, Divider } from 'antd';
import { formatNumber, formatRupiah, formatThousand, renderFormatRupiah } from '../../../const/CustomFunc'
import { import {
PROJECT_APPROVAL_ADD, PROJECT_APPROVAL_EDIT, PROJECT_PARTICIPANT_ADD, PROJECT_PARTICIPANT_EDIT, PROJECT_APPROVAL_ADD, PROJECT_APPROVAL_EDIT, PROJECT_PARTICIPANT_ADD, PROJECT_PARTICIPANT_EDIT,
PROJECT_MILESTONE_ADD, PROJECT_MILESTONE_EDIT, PROJECT_PARTICIPANT_DELETE_BY_PROYEK, PROJECT_MILESTONE_DELETE_BY_PROYEK, PROJECT_APPROVAL_DELETE_BY_PROYEK, PROJECT_MILESTONE_ADD, PROJECT_MILESTONE_EDIT, PROJECT_PARTICIPANT_DELETE_BY_PROYEK, PROJECT_MILESTONE_DELETE_BY_PROYEK, PROJECT_APPROVAL_DELETE_BY_PROYEK,
@ -14,18 +26,6 @@ import {
PROYEK_GET_ID, PROJECT_MILESTONE_SEARCH, PROJECT_PARTICIPANT_SEARCH, PROJECT_APPROVAL_SEARCH, CHECKLIST_K3_LIST, PROYEK_GET_ID, PROJECT_MILESTONE_SEARCH, PROJECT_PARTICIPANT_SEARCH, PROJECT_APPROVAL_SEARCH, CHECKLIST_K3_LIST,
VERSION_GANTT_SEARCH VERSION_GANTT_SEARCH
} from '../../../const/ApiConst'; } from '../../../const/ApiConst';
import { formatNumber, formatRupiah, formatThousand, renderFormatRupiah } from '../../../const/CustomFunc'
import moment from 'moment'
import DialogFormMaterial from './DataRequestMaterial';
import DialogTableTools from './DialogTableTools';
import DialogDocument from './DialogDocument';
import DialogInitDocument from './DialogInitDocument';
import DialogGantt from './DialogGantt';
import AssignHrProject from './AsignHrProject';
import AssignK3Project from './AssignK3Project';
import ViewProject from './ViewProject';
import { Icon } from '@iconify/react';
import { Link } from 'react-router-dom';
const url = ""; const url = "";
const proyek_id = localStorage.getItem('proyek_id'); const proyek_id = localStorage.getItem('proyek_id');
@ -41,35 +41,35 @@ const CreatedProyek = ({ params, ...props }) => {
} }
} }
const [idTask, setidTask] = useState(0);
const [dataTable, setDatatable] = useState([])
const [search, setSearch] = useState('')
const [currentPage, setCurrentPage] = useState(1)
const [totalPage, setTotalPage] = useState(0)
const [openDialog, setOpenDialog] = useState(false)
const [openDialogViewDetail, setOpenDialogViewDetail] = useState(false)
const [openDialogMaterial, setOpenDialogMaterial] = useState(false)
const [openDialogTools, setOpenDialogTools] = useState(false)
const [openDialogGantt, setOpenDialogGantt] = useState(false)
const [openDialogAsignHR, setOpenDialogAsignHR] = useState(false)
const [openDialogAssignK3, setOpenDialogAssignK3] = useState(false)
const [dataK3, setDataK3] = useState([]) // transfer list
const [idDelete, setIdDelete] = useState(0)
const [alertDelete, setAlertDelete] = useState(false) const [alertDelete, setAlertDelete] = useState(false)
const [rowsPerPage, setRowsPerPage] = useState(10) const [currentPage, setCurrentPage] = useState(1)
const [dataExport, setDataExport] = useState([])
const [userProyek, setUserProyek] = useState([])
const [materialProyek, setMaterialProyek] = useState([])
const [dataCharter, setDataCharter] = useState(null) const [dataCharter, setDataCharter] = useState(null)
const [dataExport, setDataExport] = useState([])
const [dataK3, setDataK3] = useState([])
const [dataPm, setDataPM] = useState([])
const [dataTable, setDatatable] = useState([])
const [dataTypeProyek, setDataTypeProyek] = useState([])
const [dataView, setDataView] = useState([]) const [dataView, setDataView] = useState([])
const [idDelete, setIdDelete] = useState(0)
const [idTask, setidTask] = useState(0);
const [materialProyek, setMaterialProyek] = useState([])
const [materialResource, setMaterialResource] = useState([]) const [materialResource, setMaterialResource] = useState([])
const [toolsResource, setToolsResource] = useState([]) const [openDialog, setOpenDialog] = useState(false)
const [dataTypeProyek, setDataTypeProyek] = useState([]) const [openDialogAsignHR, setOpenDialogAsignHR] = useState(false)
const [dataPm, setDataPM] = useState([]) const [openDialogAssignK3, setOpenDialogAssignK3] = useState(false)
const [openDialogDoc, setOpenDialogDoc] = useState(false) const [openDialogDoc, setOpenDialogDoc] = useState(false)
const [proyekName, setProyekName] = useState(""); const [openDialogGantt, setOpenDialogGantt] = useState(false)
const [openDialogMaterial, setOpenDialogMaterial] = useState(false)
const [openDialogProyek, setOpenDialogProyek] = useState(false) const [openDialogProyek, setOpenDialogProyek] = useState(false)
// project charter const [openDialogTools, setOpenDialogTools] = useState(false)
const [openDialogViewDetail, setOpenDialogViewDetail] = useState(false)
const [proyekName, setProyekName] = useState("");
const [rowsPerPage, setRowsPerPage] = useState(10)
const [search, setSearch] = useState('')
const [toolsResource, setToolsResource] = useState([])
const [totalPage, setTotalPage] = useState(0)
const [userProyek, setUserProyek] = useState([])
const [projectCharter, setProjectCharter] = useState(null) const [projectCharter, setProjectCharter] = useState(null)
const [projectParticipant, setProjectParticipant] = useState(null) const [projectParticipant, setProjectParticipant] = useState(null)
const [projectMilestone, setProjectMilestone] = useState(null) const [projectMilestone, setProjectMilestone] = useState(null)
@ -81,7 +81,6 @@ const CreatedProyek = ({ params, ...props }) => {
const pageName = params.name; const pageName = params.name;
useEffect(() => { useEffect(() => {
// getDataUserResource()
getDataMaterialResource() getDataMaterialResource()
getDataToolsResource() getDataToolsResource()
handleGetTipeProject() handleGetTipeProject()
@ -113,7 +112,6 @@ const CreatedProyek = ({ params, ...props }) => {
const handleGetTipeProject = async () => { const handleGetTipeProject = async () => {
const result = await axios.get(TYPE_PROYEK, HEADER).then(res => res).catch(err => err.response) const result = await axios.get(TYPE_PROYEK, HEADER).then(res => res).catch(err => err.response)
console.log(result)
if (result && result.data && result.data.code === 200) { if (result && result.data && result.data.code === 200) {
setDataTypeProyek(result.data.data); setDataTypeProyek(result.data.data);
} else { } else {
@ -123,7 +121,6 @@ const CreatedProyek = ({ params, ...props }) => {
const handleGetDataPm = async () => { const handleGetDataPm = async () => {
const result = await axios.get(USER_LIST, HEADER).then(res => res).catch(err => err.response) const result = await axios.get(USER_LIST, HEADER).then(res => res).catch(err => err.response)
console.log(result)
if (result && result.data && result.data.code === 200) { if (result && result.data && result.data.code === 200) {
setDataPM(result.data.data) setDataPM(result.data.data)
} else { } else {
@ -147,7 +144,6 @@ const CreatedProyek = ({ params, ...props }) => {
"joins": [ "joins": [
{ "name": "m_users", "column_join": "pm_id", "column_results": ["name", "username"] }, { "name": "m_users", "column_join": "pm_id", "column_results": ["name", "username"] },
{ "name": "m_type_proyek", "column_join": "type_proyek_id", "column_results": ["name", "description"] }, { "name": "m_type_proyek", "column_join": "type_proyek_id", "column_results": ["name", "description"] },
// { "name": "subproyeks.m_subproyek", "column_join": "parent_id", "column_results": ["nama", "biaya", "color_progress", "jumlah_pekerja", "pic", "mulai_proyek", "akhir_proyek", "biaya_actual", "persentase_progress_plan", "persentase_progress_actual"] }
], ],
"orders": { "columns": ["id"], "ascending": false }, "orders": { "columns": ["id"], "ascending": false },
"paging": { "start": start, "length": rowsPerPage } "paging": { "start": start, "length": rowsPerPage }
@ -160,17 +156,14 @@ const CreatedProyek = ({ params, ...props }) => {
] ]
} }
// console.log("cek payload", payload)
const result = await axios const result = await axios
.post(PROYEK_SEARCH, payload, HEADER) .post(PROYEK_SEARCH, payload, HEADER)
.then(res => res) .then(res => res)
.catch((error) => error.response); .catch((error) => error.response);
// console.log("data sub proyek", result)
if (result && result.data && result.data.code == 200) { if (result && result.data && result.data.code == 200) {
// console.log("cek proyek", result)
let dataRes = result.data.data || [] let dataRes = result.data.data || []
setDatatable(dataRes); setDatatable(dataRes);
@ -187,7 +180,6 @@ const CreatedProyek = ({ params, ...props }) => {
.catch((error) => error.response); .catch((error) => error.response);
if (result && result.data && result.data.code == 200) { if (result && result.data && result.data.code == 200) {
console.log("cek material resource", result.data.data)
let dataRes = result.data.data || [] let dataRes = result.data.data || []
setMaterialResource(dataRes); setMaterialResource(dataRes);
} else { } else {
@ -222,7 +214,6 @@ const CreatedProyek = ({ params, ...props }) => {
.catch((error) => error.response); .catch((error) => error.response);
if (result && result.data && result.data.code == 200) { if (result && result.data && result.data.code == 200) {
console.log("cek tools resource", result.data.data)
let dataRes = result.data.data || [] let dataRes = result.data.data || []
setToolsResource(dataRes); setToolsResource(dataRes);
} else { } else {
@ -237,7 +228,6 @@ const CreatedProyek = ({ params, ...props }) => {
.catch((error) => error.response); .catch((error) => error.response);
if (result && result.data && result.data.code == 200) { if (result && result.data && result.data.code == 200) {
console.log("cek k3 list", result.data.data)
let dataRes = result.data.data || [] let dataRes = result.data.data || []
const finalData = [] const finalData = []
if (dataRes.length > 0) { if (dataRes.length > 0) {
@ -261,7 +251,6 @@ const CreatedProyek = ({ params, ...props }) => {
} }
const handleOpenDialogProyek = (id) => { const handleOpenDialogProyek = (id) => {
console.log('handleOpenDialogProyek', id);
setOpenDialogProyek(true) setOpenDialogProyek(true)
setidTask(id) setidTask(id)
} }
@ -301,21 +290,17 @@ const CreatedProyek = ({ params, ...props }) => {
const handleOpenDialogTools = (data) => { const handleOpenDialogTools = (data) => {
setOpenDialogTools(true) setOpenDialogTools(true)
console.log('handleOpenDialogTools', data);
setidTask(data.id) setidTask(data.id)
setProyekName(data.nama) setProyekName(data.nama)
setUserProyek(data.user_proyeks) setUserProyek(data.user_proyeks)
} }
const handleOpenDialogViewDetail = async (data) => { const handleOpenDialogViewDetail = async (data) => {
// console.log('handleOpenDialogViewDetail', data);
setidTask(data.id) setidTask(data.id)
// setDataView(data)
await getDataProject(data.id) await getDataProject(data.id)
await getProjectMilestone(data.id) await getProjectMilestone(data.id)
await getProjectParticipant(data.id) await getProjectParticipant(data.id)
await getProjectApproval(data.id) await getProjectApproval(data.id)
// await getDataProjectCharter(data.id);
setOpenDialogViewDetail(true) setOpenDialogViewDetail(true)
} }
@ -329,7 +314,6 @@ const CreatedProyek = ({ params, ...props }) => {
if (result && result.data && result.data.code == 200) { if (result && result.data && result.data.code == 200) {
let dataRes = result.data.data; let dataRes = result.data.data;
setProjectCharter(dataRes); setProjectCharter(dataRes);
// console.log("cek project-charter resource", dataRes);
} else { } else {
NotificationManager.error('Gagal Mengambil Data!!', 'Failed'); NotificationManager.error('Gagal Mengambil Data!!', 'Failed');
} }
@ -344,7 +328,6 @@ const CreatedProyek = ({ params, ...props }) => {
"orders": { "columns": ["id"], "ascending": true }, "orders": { "columns": ["id"], "ascending": true },
"paging": { "start": 0, "length": -1 } "paging": { "start": 0, "length": -1 }
} }
// const url = PROJECT_MI(proyek_id)
const result = await axios const result = await axios
.post(PROJECT_MILESTONE_SEARCH, payload, HEADER) .post(PROJECT_MILESTONE_SEARCH, payload, HEADER)
.then(res => res) .then(res => res)
@ -353,7 +336,6 @@ const CreatedProyek = ({ params, ...props }) => {
if (result && result.data && result.data.code == 200) { if (result && result.data && result.data.code == 200) {
let dataRes = result.data.data; let dataRes = result.data.data;
setProjectMilestone(dataRes); setProjectMilestone(dataRes);
// console.log("cek project milestone", dataRes);
} else { } else {
NotificationManager.error('Gagal Mengambil Data!!', 'Failed'); NotificationManager.error('Gagal Mengambil Data!!', 'Failed');
} }
@ -368,7 +350,6 @@ const CreatedProyek = ({ params, ...props }) => {
"orders": { "columns": ["id"], "ascending": true }, "orders": { "columns": ["id"], "ascending": true },
"paging": { "start": 0, "length": -1 } "paging": { "start": 0, "length": -1 }
} }
// const url = PROJECT_MI(proyek_id)
const result = await axios const result = await axios
.post(PROJECT_PARTICIPANT_SEARCH, payload, HEADER) .post(PROJECT_PARTICIPANT_SEARCH, payload, HEADER)
.then(res => res) .then(res => res)
@ -378,7 +359,6 @@ const CreatedProyek = ({ params, ...props }) => {
let dataRes = result.data.data; let dataRes = result.data.data;
setProjectParticipant(dataRes); setProjectParticipant(dataRes);
// console.log("cek project participant", dataRes);
} else { } else {
NotificationManager.error('Gagal Mengambil Data!!', 'Failed'); NotificationManager.error('Gagal Mengambil Data!!', 'Failed');
} }
@ -393,7 +373,6 @@ const CreatedProyek = ({ params, ...props }) => {
"orders": { "columns": ["id"], "ascending": true }, "orders": { "columns": ["id"], "ascending": true },
"paging": { "start": 0, "length": -1 } "paging": { "start": 0, "length": -1 }
} }
// const url = PROJECT_MI(proyek_id)
const result = await axios const result = await axios
.post(PROJECT_APPROVAL_SEARCH, payload, HEADER) .post(PROJECT_APPROVAL_SEARCH, payload, HEADER)
.then(res => res) .then(res => res)
@ -402,7 +381,6 @@ const CreatedProyek = ({ params, ...props }) => {
if (result && result.data && result.data.code == 200) { if (result && result.data && result.data.code == 200) {
let dataRes = result.data.data; let dataRes = result.data.data;
setProjectApproval(dataRes); setProjectApproval(dataRes);
// console.log("cek project approval", dataRes);
} else { } else {
NotificationManager.error('Gagal Mengambil Data!!', 'Failed'); NotificationManager.error('Gagal Mengambil Data!!', 'Failed');
} }
@ -471,15 +449,12 @@ const CreatedProyek = ({ params, ...props }) => {
const result = await axios.post(PROYEK_ADD, formData, HEADER) const result = await axios.post(PROYEK_ADD, formData, HEADER)
.then(res => res) .then(res => res)
.catch((error) => error.response); .catch((error) => error.response);
console.log(result)
if (result && result.data && result.data.code === 200) { if (result && result.data && result.data.code === 200) {
const { participants, milestones, approval } = data.projectCharter const { participants, milestones, approval } = data.projectCharter
const resultParticipant = await saveParticipant(result.data.data_result.id, participants) const resultParticipant = await saveParticipant(result.data.data_result.id, participants)
const resultMilestone = await saveMilestone(result.data.data_result.id, milestones) const resultMilestone = await saveMilestone(result.data.data_result.id, milestones)
const resultApproval = await saveApproval(result.data.data_result.id, approval) const resultApproval = await saveApproval(result.data.data_result.id, approval)
console.log({ resultApproval, resultMilestone, resultParticipant })
if (resultParticipant === "berhasil" && resultMilestone === "berhasil" && resultApproval === "berhasil") { if (resultParticipant === "berhasil" && resultMilestone === "berhasil" && resultApproval === "berhasil") {
// getDataProyek();
NotificationManager.success(`Data proyek berhasil ditambah`, 'Success!!'); NotificationManager.success(`Data proyek berhasil ditambah`, 'Success!!');
} else { } else {
NotificationManager.success(`${result.data.message}`, 'Success!!'); NotificationManager.success(`${result.data.message}`, 'Success!!');
@ -502,9 +477,7 @@ const CreatedProyek = ({ params, ...props }) => {
} }
return axios.post(PROJECT_PARTICIPANT_ADD, payload, HEADER) return axios.post(PROJECT_PARTICIPANT_ADD, payload, HEADER)
}) })
console.log(request)
const arr = await Promise.all(request).then(values => values).catch(err => err.response); const arr = await Promise.all(request).then(values => values).catch(err => err.response);
console.log('result participant', arr)
const result = arr.map(res => res.data.code == 200) const result = arr.map(res => res.data.code == 200)
if (result.length > 0) { if (result.length > 0) {
return "gagal" return "gagal"
@ -523,9 +496,7 @@ const CreatedProyek = ({ params, ...props }) => {
} }
return axios.post(PROJECT_MILESTONE_ADD, payload, HEADER) return axios.post(PROJECT_MILESTONE_ADD, payload, HEADER)
}) })
console.log(request)
const arr = await Promise.all(request).then(values => values).catch(err => err.response); const arr = await Promise.all(request).then(values => values).catch(err => err.response);
console.log('result milestone', arr)
const result = arr.map(res => res.data.code !== 200) const result = arr.map(res => res.data.code !== 200)
if (result.length > 0) { if (result.length > 0) {
return "gagal" return "gagal"
@ -545,9 +516,7 @@ const CreatedProyek = ({ params, ...props }) => {
} }
return axios.post(PROJECT_APPROVAL_ADD, payload, HEADER) return axios.post(PROJECT_APPROVAL_ADD, payload, HEADER)
}) })
console.log(request)
const arr = await Promise.all(request).then(values => values).catch(err => err.response); const arr = await Promise.all(request).then(values => values).catch(err => err.response);
console.log('result approval', arr)
const result = arr.map(res => res.data.code !== 200) const result = arr.map(res => res.data.code !== 200)
if (result.length > 0) { if (result.length > 0) {
return "gagal" return "gagal"
@ -565,7 +534,6 @@ const CreatedProyek = ({ params, ...props }) => {
const result = await axios.put(urlEdit, formData, HEADER) const result = await axios.put(urlEdit, formData, HEADER)
.then(res => res) .then(res => res)
.catch((error) => error.response); .catch((error) => error.response);
console.log("cek result", result)
const resultParticipant = await editParticipant(data.id, participants) const resultParticipant = await editParticipant(data.id, participants)
const resultMilestone = await editMilestone(data.id, milestones) const resultMilestone = await editMilestone(data.id, milestones)
const resultApproval = await editApproval(data.id, approval) const resultApproval = await editApproval(data.id, approval)
@ -580,7 +548,6 @@ const CreatedProyek = ({ params, ...props }) => {
const editParticipant = async (id, data) => { const editParticipant = async (id, data) => {
await axios.delete(PROJECT_PARTICIPANT_DELETE_BY_PROYEK(id), HEADER) await axios.delete(PROJECT_PARTICIPANT_DELETE_BY_PROYEK(id), HEADER)
// if (restDelete){
const request = data.map(res => { const request = data.map(res => {
const payload = { const payload = {
proyek_id: parseInt(id), proyek_id: parseInt(id),
@ -589,10 +556,7 @@ const CreatedProyek = ({ params, ...props }) => {
} }
return axios.post(PROJECT_PARTICIPANT_ADD, payload, HEADER) return axios.post(PROJECT_PARTICIPANT_ADD, payload, HEADER)
}) })
console.log(request)
const arr = await Promise.all(request).then(values => values).catch(err => err.response); const arr = await Promise.all(request).then(values => values).catch(err => err.response);
console.log('result participant', arr)
// let dataTittle = arr.data.tittle
const result = arr.map(res => res.data.code !== 200) const result = arr.map(res => res.data.code !== 200)
if (result.length > 0) { if (result.length > 0) {
return "gagal" return "gagal"
@ -604,7 +568,6 @@ const CreatedProyek = ({ params, ...props }) => {
const editMilestone = async (id, data) => { const editMilestone = async (id, data) => {
await axios.delete(PROJECT_MILESTONE_DELETE_BY_PROYEK(id), HEADER) await axios.delete(PROJECT_MILESTONE_DELETE_BY_PROYEK(id), HEADER)
console.log("res due", data)
const request = data.map(res => { const request = data.map(res => {
const payload = { const payload = {
proyek_id: parseInt(id), proyek_id: parseInt(id),
@ -614,9 +577,7 @@ const CreatedProyek = ({ params, ...props }) => {
} }
return axios.post(PROJECT_MILESTONE_ADD, payload, HEADER) return axios.post(PROJECT_MILESTONE_ADD, payload, HEADER)
}) })
console.log(request)
const arr = await Promise.all(request).then(values => values).catch(err => err.response); const arr = await Promise.all(request).then(values => values).catch(err => err.response);
console.log('result milestone', arr)
const result = arr.map(res => res.data.code !== 200) const result = arr.map(res => res.data.code !== 200)
if (result.length > 0) { if (result.length > 0) {
return "gagal" return "gagal"
@ -625,7 +586,6 @@ const CreatedProyek = ({ params, ...props }) => {
} }
const editApproval = async (id, data) => { const editApproval = async (id, data) => {
console.log("cek data edit approval", data)
await axios.delete(PROJECT_APPROVAL_DELETE_BY_PROYEK(id), HEADER) await axios.delete(PROJECT_APPROVAL_DELETE_BY_PROYEK(id), HEADER)
const request = data.map(res => { const request = data.map(res => {
const payload = { const payload = {
@ -636,20 +596,11 @@ const CreatedProyek = ({ params, ...props }) => {
} }
return axios.post(PROJECT_APPROVAL_ADD, payload, HEADER) return axios.post(PROJECT_APPROVAL_ADD, payload, HEADER)
}) })
console.log(request)
const arr = await Promise.all(request).then(values => values).catch(err => err.response); const arr = await Promise.all(request).then(values => values).catch(err => err.response);
console.log('result approval', arr)
// if(arr)
// const result = arr.map(res => res.data.code !== 200)
// if (result.length > 0) {
// return "gagal"
// }
// return "berhasil"
} }
const handleDelete = async (id) => { const handleDelete = async (id) => {
// console.log('Delete')
await setAlertDelete(true) await setAlertDelete(true)
await setIdDelete(id) await setIdDelete(id)
} }
@ -666,9 +617,6 @@ const CreatedProyek = ({ params, ...props }) => {
const payload = { const payload = {
"paging": { "start": 0, "length": -1 }, "paging": { "start": 0, "length": -1 },
// "columns": [
// { "name": "nama", "logic_operator": "like", "value": search, "operator": "AND" }
// ],
"joins": [], "joins": [],
"orders": { "columns": ["id"], "ascending": false } "orders": { "columns": ["id"], "ascending": false }
} }
@ -686,11 +634,9 @@ const CreatedProyek = ({ params, ...props }) => {
.then(res => res) .then(res => res)
.catch((error) => error.response); .catch((error) => error.response);
// console.log(result)
if (result && result.data && result.data.code == 200) { if (result && result.data && result.data.code == 200) {
let resData = result.data.data; let resData = result.data.data;
console.log("resData", resData);
const excelData = []; const excelData = [];
resData.map((n, index) => { resData.map((n, index) => {
let dataRow = { let dataRow = {
@ -709,9 +655,7 @@ const CreatedProyek = ({ params, ...props }) => {
} }
excelData.push(dataRow) excelData.push(dataRow)
}) })
// console.log("cek excel data", excelData)
await setDataExport(excelData); await setDataExport(excelData);
// exportExcel();
} else { } else {
NotificationManager.error('Gagal Export Data!!', 'Failed'); NotificationManager.error('Gagal Export Data!!', 'Failed');
} }
@ -836,7 +780,6 @@ const CreatedProyek = ({ params, ...props }) => {
title: 'Budget', title: 'Budget',
dataIndex: 'rencana_biaya', dataIndex: 'rencana_biaya',
key: 'rencana_biaya', key: 'rencana_biaya',
// render: (text, record) => { return renderFormatRupiah(text, "Rp") }
render: (text, record) => { return record.currency_symbol ? `${record.currency_symbol} ${formatThousand(text)}` : `${formatThousand(text)}` } render: (text, record) => { return record.currency_symbol ? `${record.currency_symbol} ${formatThousand(text)}` : `${formatThousand(text)}` }
}, },
{ {
@ -937,7 +880,6 @@ const CreatedProyek = ({ params, ...props }) => {
/> />
), [openDialogTools]) ), [openDialogTools])
// DialogAsignHr
const RenderDialogAsignHr = useMemo(() => ( const RenderDialogAsignHr = useMemo(() => (
<AssignHrProject <AssignHrProject
openDialog={openDialogAsignHR} openDialog={openDialogAsignHR}
@ -950,7 +892,6 @@ const CreatedProyek = ({ params, ...props }) => {
), [openDialogAsignHR]) ), [openDialogAsignHR])
// DialogAssignK3
const RenderDialogAssignK3 = useMemo(() => ( const RenderDialogAssignK3 = useMemo(() => (
<AssignK3Project <AssignK3Project
openDialog={openDialogAssignK3} openDialog={openDialogAssignK3}
@ -1061,4 +1002,4 @@ const CreatedProyek = ({ params, ...props }) => {
) )
} }
export default CreatedProyek; export default CreatedProyek;

674
src/views/SimproV2/Divisi/index.js

@ -1,18 +1,15 @@
import * as XLSX from 'xlsx';
import DialogForm from './DialogForm';
import React, { useState, useEffect, useMemo } from 'react'; import React, { useState, useEffect, useMemo } from 'react';
import SweetAlert from 'react-bootstrap-sweetalert';
import axios from "../../../const/interceptorApi"
import moment from 'moment'
import { Card, CardBody, CardHeader, Col, Row, Input, Table } from 'reactstrap'; import { Card, CardBody, CardHeader, Col, Row, Input, Table } from 'reactstrap';
import { DIVISI_ADD, DIVISI_EDIT, DIVISI_DELETE, DIVISI_SEARCH} from '../../../const/ApiConst';
import { DownloadOutlined } from '@ant-design/icons'; import { DownloadOutlined } from '@ant-design/icons';
import axios from "../../../const/interceptorApi"
import * as XLSX from 'xlsx';
import SweetAlert from 'react-bootstrap-sweetalert';
import DialogForm from './DialogForm';
import { NotificationContainer, NotificationManager } from 'react-notifications'; import { NotificationContainer, NotificationManager } from 'react-notifications';
import { Pagination, Button, Tooltip } from 'antd'; import { Pagination, Button, Tooltip } from 'antd';
import { formatRupiah, formatNumber } from '../../../const/CustomFunc' import { formatRupiah, formatNumber } from '../../../const/CustomFunc'
import {
DIVISI_ADD, DIVISI_EDIT, DIVISI_DELETE,
DIVISI_SEARCH
} from '../../../const/ApiConst';
import moment from 'moment'
const url = ""; const url = "";
const proyek_id = localStorage.getItem('proyek_id'); const proyek_id = localStorage.getItem('proyek_id');
@ -20,352 +17,329 @@ const role_id = localStorage.getItem('role_id');
const format = "DD-MM-YYYY"; const format = "DD-MM-YYYY";
const token = window.localStorage.getItem('token'); const token = window.localStorage.getItem('token');
const config = { const config = {
headers: headers:
{ {
Authorization: `Bearer ${token}`, Authorization: `Bearer ${token}`,
"Content-type": `application/json` "Content-type": `application/json`
} }
}; };
const column = [ const column = [
{ name: "Nama" }, { name: "Nama" },
{ name: "Deskripsi" }, { name: "Deskripsi" },
] ]
const ProjectType = ({ params }) => { const ProjectType = ({ params }) => {
const token = localStorage.getItem("token") const token = localStorage.getItem("token")
const HEADER = { const HEADER = {
headers: { headers: {
"Content-Type": "application/json", "Content-Type": "application/json",
"Authorization": `Bearer ${token}` "Authorization": `Bearer ${token}`
} }
} }
const pageName = params.name; const pageName = params.name;
const [search, setSearch] = useState('')
const [currentPage, setCurrentPage] = useState(1) const [alertDelete, setAlertDelete] = useState(false)
const [openDialog, setOpenDialog] = useState(false) const [allDataMenu, setAllDataMenu] = useState([])
const [typeDialog, setTypeDialog] = useState('Save') const [clickOpenModal, setClickOpenModal] = useState(false)
const [dataExport, setDataExport] = useState([]) const [currentPage, setCurrentPage] = useState(1)
const [rowsPerPage, setRowsPerPage] = useState(10) const [dataEdit, setDataEdit] = useState([])
const [dataEdit, setDataEdit] = useState([]) const [dataExport, setDataExport] = useState([])
const [alertDelete, setAlertDelete] = useState(false) const [dataTable, setDatatable] = useState([])
const [idDelete, setIdDelete] = useState(0) const [idDelete, setIdDelete] = useState(0)
const [dataTable, setDatatable] = useState([]) const [openDialog, setOpenDialog] = useState(false)
const [clickOpenModal, setClickOpenModal] = useState(false) const [rowsPerPage, setRowsPerPage] = useState(10)
const [allDataMenu, setAllDataMenu] = useState([]) const [search, setSearch] = useState('')
const [totalPage, setTotalPage] = useState(0) const [totalPage, setTotalPage] = useState(0)
const [typeDialog, setTypeDialog] = useState('Save')
useEffect(() => {
getDataProjectType() useEffect(() => {
}, [currentPage, rowsPerPage, search]) getDataProjectType()
}, [currentPage, rowsPerPage, search])
useEffect(() => {
const cekData = dataExport || [] useEffect(() => {
if (cekData.length > 0) { const cekData = dataExport || []
exportExcel() if (cekData.length > 0) {
} exportExcel()
}, [dataExport]) }
}, [dataExport])
const getDataProjectType = async () => {
const getDataProjectType = async () => {
let start = 0;
let start = 0;
if (currentPage !== 1 && currentPage > 1) {
start = (currentPage * rowsPerPage) - rowsPerPage if (currentPage !== 1 && currentPage > 1) {
} start = (currentPage * rowsPerPage) - rowsPerPage
}
const payload = {
"columns": [ const payload = {
{ "columns": [
"name": "name", {
"logic_operator": "like", "name": "name",
"value": search, "logic_operator": "like",
"operator": "AND" "value": search,
} "operator": "AND"
], }
"orders": { ],
"ascending": true, "orders": {
"columns": [ "ascending": true,
'id' "columns": [
] 'id'
}, ]
"paging": { },
"length": rowsPerPage, "paging": {
"start": start "length": rowsPerPage,
} "start": start
} }
}
// console.log("payload ", payload)
const result = await axios const result = await axios
.post(DIVISI_SEARCH, payload, config) .post(DIVISI_SEARCH, payload, config)
.then(res => res) .then(res => res)
.catch((error) => error.response); .catch((error) => error.response);
if (result && result.data && result.data.code == 200) {
setDatatable(result.data.data);
if (result && result.data && result.data.code == 200) { setTotalPage(result.data.totalRecord);
console.log("get data ", result.data) } else {
setDatatable(result.data.data); NotificationManager.error('Gagal Mengambil Data!!', 'Failed');
setTotalPage(result.data.totalRecord); }
} else { }
NotificationManager.error('Gagal Mengambil Data!!', 'Failed');
} const handleSearch = e => {
} const value = e.target.value
setSearch(value);
const handleSearch = e => { setCurrentPage(1)
const value = e.target.value };
setSearch(value);
setCurrentPage(1) const handleOpenDialog = (type) => {
}; setOpenDialog(true)
setTypeDialog(type)
const handleOpenDialog = (type) => { }
setOpenDialog(true)
setTypeDialog(type) const handleExportExcel = async () => {
} let start = 0;
const payload = {
const handleExportExcel = async () => { "paging": { "start": start, "length": -1 },
"columns": [
let start = 0; { "name": "name", "logic_operator": "like", "value": search, "operator": "AND" }
],
const payload = { "joins": [],
"paging": { "start": start, "length": -1 }, "orders": { "columns": ["id"], "ascending": false }
"columns": [ }
{ "name": "name", "logic_operator": "like", "value": search, "operator": "AND" }
], const result = await axios
"joins": [], .post(DIVISI_SEARCH, payload)
"orders": { "columns": ["id"], "ascending": false } .then(res => res)
} .catch((error) => error.response);
if (result && result.data && result.data.code == 200) {
let resData = result.data.data;
const result = await axios const excelData = [];
.post(DIVISI_SEARCH, payload) resData.map((val, index) => {
.then(res => res) let dataRow = {
.catch((error) => error.response); "Nama": val.name,
"Deskripsi": val.description,
// console.log(result) }
excelData.push(dataRow)
if (result && result.data && result.data.code == 200) { })
let resData = result.data.data; await setDataExport(excelData);
const excelData = []; } else {
resData.map((val, index) => { NotificationManager.error('Gagal Export Data!!', 'Failed');
let dataRow = { }
"Nama": val.name, }
"Deskripsi": val.description,
} const exportExcel = () => {
excelData.push(dataRow) const dataExcel = dataExport || [];
}) const fileName = `Data ${pageName}.xlsx`;
// console.log("cek excel data", excelData) const ws = XLSX.utils.json_to_sheet(dataExcel);
await setDataExport(excelData); const wb = XLSX.utils.book_new();
// exportExcel(); XLSX.utils.book_append_sheet(wb, ws, `Data ${pageName}`);
} else { XLSX.writeFile(wb, fileName);
NotificationManager.error('Gagal Export Data!!', 'Failed'); setDataExport([])
} }
}
const handleEdit = (data) => {
const exportExcel = () => { setDataEdit(data)
const dataExcel = dataExport || []; handleOpenDialog('Edit');
const fileName = `Data ${pageName}.xlsx`; }
const ws = XLSX.utils.json_to_sheet(dataExcel);
const wb = XLSX.utils.book_new(); const handleDelete = async (id) => {
XLSX.utils.book_append_sheet(wb, ws, `Data ${pageName}`); await setAlertDelete(true)
await setIdDelete(id)
XLSX.writeFile(wb, fileName); }
setDataExport([])
} const handleCloseDialog = (type, data) => {
if (type === "save") {
const handleEdit = (data) => { saveProjectType(data);
setDataEdit(data) } else if (type === "edit") {
handleOpenDialog('Edit'); editMaterialR(data);
} }
setDataEdit([])
const handleDelete = async (id) => { setOpenDialog(false)
await setAlertDelete(true) }
await setIdDelete(id)
} const saveProjectType = async (data) => {
const formData = data
const handleCloseDialog = (type, data) => { const result = await axios.post(DIVISI_ADD, formData, HEADER)
if (type === "save") { .then(res => res)
saveProjectType(data); .catch((error) => error.response);
} else if (type === "edit") { if (result && result.data && result.data.code === 200) {
editMaterialR(data); getDataProjectType()
} NotificationManager.success(`Data project type berhasil ditambah`, 'Success!!');
setDataEdit([]) } else {
setOpenDialog(false) NotificationManager.error(`${result.data.message}`, 'Failed!!');
} }
}
const saveProjectType = async (data) => {
const formData = data const editMaterialR = async (data) => {
const result = await axios.post(DIVISI_ADD, formData, HEADER) let urlEdit = DIVISI_EDIT(data.id)
.then(res => res) const formData = data
.catch((error) => error.response); const result = await axios.put(urlEdit, formData, HEADER)
.then(res => res)
if (result && result.data && result.data.code === 200) { .catch((error) => error.response);
getDataProjectType() if (result && result.data && result.data.code === 200) {
// console.log("data material s ", formData) getDataProjectType();
NotificationManager.success(`Data project type berhasil ditambah`, 'Success!!'); NotificationManager.success(`Data project type berhasil diedit`, 'Success!!');
} else { } else {
// console.log("data material fail ", formData) NotificationManager.error(`Data project type gagal di edit`, `Failed!!`);
NotificationManager.error(`${result.data.message}`, 'Failed!!'); }
} }
}
const toggleAddDialog = () => {
const editMaterialR = async (data) => { setOpenDialog(!openDialog)
}
let urlEdit = DIVISI_EDIT(data.id)
const formData = data const onConfirmDelete = async () => {
let url = DIVISI_DELETE(idDelete);
console.log("from data edit ", formData) const result = await axios.delete(url, config)
.then(res => res)
const result = await axios.put(urlEdit, formData, HEADER) .catch((error) => error.response);
.then(res => res)
.catch((error) => error.response); if (result && result.data && result.data.code === 200) {
getDataProjectType()
if (result && result.data && result.data.code === 200) { setIdDelete(0)
getDataProjectType(); setAlertDelete(false)
NotificationManager.success(`Data project type berhasil diedit`, 'Success!!'); NotificationManager.success(`Data project type berhasil dihapus!`, 'Success!!');
} else { } else {
NotificationManager.error(`Data project type gagal di edit`, `Failed!!`); setIdDelete(0)
} setAlertDelete(false)
} NotificationManager.error(`Data project type gagal dihapus!}`, 'Failed!!');
}
const toggleAddDialog = () => { }
setOpenDialog(!openDialog)
} const cancelDelete = () => {
setAlertDelete(false)
const onConfirmDelete = async () => { setIdDelete(0)
let url = DIVISI_DELETE(idDelete); }
const result = await axios.delete(url, config) const onShowSizeChange = (current, pageSize) => {
.then(res => res) setRowsPerPage(pageSize)
.catch((error) => error.response); }
if (result && result.data && result.data.code === 200) { const onPagination = (current, pageSize) => {
getDataProjectType() setCurrentPage(current)
setIdDelete(0) }
setAlertDelete(false)
NotificationManager.success(`Data project type berhasil dihapus!`, 'Success!!'); const dataNotAvailable = () => {
} else { if (dataTable.length === 0) {
setIdDelete(0) return (
setAlertDelete(false) <tr>
NotificationManager.error(`Data project type gagal dihapus!}`, 'Failed!!'); <td align="center" colSpan="3">Tidak ada data project type</td>
} </tr>
} )
}
const cancelDelete = () => { }
setAlertDelete(false)
setIdDelete(0) return (
} <div>
<NotificationContainer />
const onShowSizeChange = (current, pageSize) => { <SweetAlert
setRowsPerPage(pageSize) show={alertDelete}
} warning
showCancel
const onPagination = (current, pageSize) => { confirmBtnText="Delete"
setCurrentPage(current) confirmBtnBsStyle="danger"
} title={`Are you sure?`}
onConfirm={onConfirmDelete}
const dataNotAvailable = () => { onCancel={() => cancelDelete()}
if (dataTable.length === 0) { focusCancelBtn
return ( >
<tr> Delete this data
<td align="center" colSpan="3">Tidak ada data project type</td> </SweetAlert>
</tr> <DialogForm
) openDialog={openDialog}
} closeDialog={handleCloseDialog}
} toggleDialog={() => toggleAddDialog}
typeDialog={typeDialog}
dataEdit={dataEdit}
clickOpenModal={clickOpenModal}
return ( dataParent={allDataMenu}
<div> />
<NotificationContainer /> <Card>
<SweetAlert <CardHeader style={{ display: "flex", justifyContent: "space-between" }}>
show={alertDelete} <h4 className="capitalize">{pageName}</h4>
warning <Row>
showCancel <Col>
confirmBtnText="Delete" <Input onChange={handleSearch} value={search} type="text" name="search" id="search" placeholder={`Search divisi...`} />
confirmBtnBsStyle="danger" </Col>
title={`Are you sure?`} <Col>
onConfirm={onConfirmDelete} <Tooltip title="Add Material Resource">
onCancel={() => cancelDelete()} <Button style={{ background: "#4caf50", color: "#fff" }} onClick={() => handleOpenDialog('Save')}><i className="fa fa-plus"></i></Button>
focusCancelBtn </Tooltip>
> <Tooltip title="Export Excel">
Delete this data <Button style={{ marginLeft: "5px" }} onClick={() => handleExportExcel()}><i className="fa fa-print"></i></Button>
</SweetAlert> </Tooltip>
<DialogForm </Col>
openDialog={openDialog} </Row>
closeDialog={handleCloseDialog} </CardHeader>
toggleDialog={() => toggleAddDialog} <CardBody>
typeDialog={typeDialog} <Table responsive striped hover>
dataEdit={dataEdit} <thead>
clickOpenModal={clickOpenModal} <tr>
dataParent={allDataMenu} <th>Aksi</th>
/> {column.map((i, index) => {
<Card> return (
<CardHeader style={{ display: "flex", justifyContent: "space-between" }}> <th key={index} scope="row">{i.name}</th>
<h4 className="capitalize">{pageName}</h4> )
<Row> })}
<Col> </tr>
<Input onChange={handleSearch} value={search} type="text" name="search" id="search" placeholder={`Search divisi...`} /> </thead>
</Col> <tbody>
<Col> {dataNotAvailable()}
<Tooltip title="Add Material Resource"> {dataTable.map((n, index) => {
<Button style={{ background: "#4caf50", color: "#fff" }} onClick={() => handleOpenDialog('Save')}><i className="fa fa-plus"></i></Button> return (
</Tooltip> <tr key={n.id}>
<Tooltip title="Export Excel"> <td className='nowrap'>
<Button style={{ marginLeft: "5px" }} onClick={() => handleExportExcel()}><i className="fa fa-print"></i></Button>
</Tooltip> <Tooltip title="Hapus">
</Col> <i id="TooltipDelete" className="cil-trash fa-lg" style={{ color: 'red', marginRight: 10, cursor: "pointer" }} onClick={() => handleDelete(n.id)}></i>
</Row> </Tooltip>
</CardHeader>
<CardBody> <Tooltip title="Edit">
<Table responsive striped hover> <i id="TooltipEdit" className="cil-pencil fa-lg" style={{ color: 'green', cursor: "pointer" }} onClick={() => handleEdit(n)}></i>
<thead> </Tooltip>
<tr> </td>
<th>Aksi</th> <td>{n.name}</td>
{column.map((i, index) => { <td>{n.description}</td>
return ( </tr>
<th key={index} scope="row">{i.name}</th> )
) })}
})} </tbody>
</tr> </Table>
</thead> <Pagination
<tbody> showSizeChanger
{dataNotAvailable()} onShowSizeChange={onShowSizeChange}
{dataTable.map((n, index) => { onChange={onPagination}
return ( defaultCurrent={currentPage}
<tr key={n.id}> pageSize={rowsPerPage}
<td className='nowrap'> total={totalPage}
pageSizeOptions={["10", "15", "20", "25", "30", "35", "40"]}
<Tooltip title="Hapus"> />
<i id="TooltipDelete" className="cil-trash fa-lg" style={{ color: 'red', marginRight: 10, cursor: "pointer" }} onClick={() => handleDelete(n.id)}></i> </CardBody>
</Tooltip> </Card>
</div>
<Tooltip title="Edit"> )
<i id="TooltipEdit" className="cil-pencil fa-lg" style={{ color: 'green', cursor: "pointer" }} onClick={() => handleEdit(n)}></i>
</Tooltip>
</td>
<td>{n.name}</td>
<td>{n.description}</td>
</tr>
)
})}
</tbody>
</Table>
<Pagination
showSizeChanger
onShowSizeChange={onShowSizeChange}
onChange={onPagination}
defaultCurrent={currentPage}
pageSize={rowsPerPage}
total={totalPage}
pageSizeOptions={["10", "15", "20", "25", "30", "35", "40"]}
/>
</CardBody>
</Card>
</div>
)
} }
export default ProjectType; export default ProjectType;

105
src/views/SimproV2/PanicButton/index.js

@ -1,32 +1,31 @@
import * as XLSX from 'xlsx';
import DialogEdit from './DialogEdit';
import DialogForm from './DialogForm';
import React, { Component } from 'react'; import React, { Component } from 'react';
import { Card, CardBody, CardHeader, Col, Row, Table, Input, InputGroup } from 'reactstrap'; import SweetAlert from 'react-bootstrap-sweetalert';
import { Button } from 'reactstrap';
import axios from 'axios'; import axios from 'axios';
import moment from 'moment'; import moment from 'moment';
import SweetAlert from 'react-bootstrap-sweetalert'; import { Button } from 'reactstrap';
import DialogForm from './DialogForm'; import { Card, CardBody, CardHeader, Col, Row, Table, Input, InputGroup } from 'reactstrap';
import DialogEdit from './DialogEdit';
import { NotificationContainer, NotificationManager } from 'react-notifications';
import { Pagination, Tooltip } from 'antd';
import { DatePicker } from 'antd'; import { DatePicker } from 'antd';
import * as XLSX from 'xlsx'; import { NotificationContainer, NotificationManager } from 'react-notifications';
import { PANIC_BUTTON_UPDATE, PANIC_BUTTON_SEARCH } from '../../../const/ApiConst'; import { PANIC_BUTTON_UPDATE, PANIC_BUTTON_SEARCH } from '../../../const/ApiConst';
import { Pagination, Tooltip } from 'antd';
const id_org = window.localStorage.getItem('id_org'); const id_org = window.localStorage.getItem('id_org');
const roleName = window.localStorage.getItem('role_name'); const roleName = window.localStorage.getItem('role_name');
const token = window.localStorage.getItem('token'); const token = window.localStorage.getItem('token');
const config = { const config = {
headers: headers:
{ {
Authorization : `Bearer ${token}`, Authorization : `Bearer ${token}`,
"Content-type" : `application/json` "Content-type" : `application/json`
} }
}; };
const { RangePicker } = DatePicker; const { RangePicker } = DatePicker;
const momentFormat = 'HH:mm'; const momentFormat = 'HH:mm';
const column = [ const column = [
@ -42,29 +41,29 @@ export default class index extends Component {
constructor(props) { constructor(props) {
super(props) super(props)
this.state = { this.state = {
dataTable: [],
dataExport: [],
openDialog: false,
openDialogEdit:false,
typeDialog: 'Save',
dataEdit: null,
alertDelete: false, alertDelete: false,
idDelete: 0, currentDay: 'today',
currentPage: 1,
dataEdit: null,
dataExport: [],
dataGs: [], dataGs: [],
dataIdHo: [], dataIdHo: [],
search: "", dataMap:"",
dataTable: [],
endDate:moment(moment().format("YYYY-M-D")),
idDelete: 0,
openDialog: false,
openDialogEdit:false,
page: 0, page: 0,
rowsPerPage: LENGTH_DATA, rowsPerPage: LENGTH_DATA,
currentPage: 1, search: "",
totalPage: 0,
tooltipMap: false,
tooltipDelete: false,
typeClock: "All",
startDate:moment(moment().format("YYYY-M-D")), startDate:moment(moment().format("YYYY-M-D")),
endDate:moment(moment().format("YYYY-M-D")), tooltipDelete: false,
currentDay: 'today',
dataMap:"",
tooltipExport:false, tooltipExport:false,
tooltipMap: false,
totalPage: 0,
typeClock: "All",
typeDialog: 'Save',
} }
} }
@ -84,8 +83,6 @@ export default class index extends Component {
}; };
getDataPanicButton = async () => { getDataPanicButton = async () => {
// let url = BASE_URL + `panic_button.php?act=get_data&role_name=${roleName}`;
let start = 0; let start = 0;
if (this.state.currentPage !== 1) { if (this.state.currentPage !== 1) {
start = (this.state.currentPage * this.state.rowsPerPage) - this.state.rowsPerPage start = (this.state.currentPage * this.state.rowsPerPage) - this.state.rowsPerPage
@ -131,7 +128,6 @@ export default class index extends Component {
.post(PANIC_BUTTON_SEARCH, payload, config) .post(PANIC_BUTTON_SEARCH, payload, config)
.then(res => res) .then(res => res)
.catch((error) => error.response); .catch((error) => error.response);
console.log('test panic button', result);
if(result && result.data){ if(result && result.data){
if (result && result.data && result.data.code == 200) { if (result && result.data && result.data.code == 200) {
this.setState({ dataTable: result.data.data, totalPage: result.data.totalRecord,dataExport:result.data.data_export }); this.setState({ dataTable: result.data.data, totalPage: result.data.totalRecord,dataExport:result.data.data_export });
@ -149,7 +145,7 @@ export default class index extends Component {
this.setState({ openDialogEdit: true }) this.setState({ openDialogEdit: true })
this.showDialogEdit(); this.showDialogEdit();
} }
} }
handleCloseDialog = () => { handleCloseDialog = () => {
@ -243,8 +239,6 @@ export default class index extends Component {
} }
updateStatusResponse = async (data) => { updateStatusResponse = async (data) => {
console.log('test data', data)
let url = PANIC_BUTTON_UPDATE(data.id); let url = PANIC_BUTTON_UPDATE(data.id);
let payload = { let payload = {
"user_id" : data.user_id, "user_id" : data.user_id,
@ -255,18 +249,10 @@ export default class index extends Component {
} }
// let url = BASE_URL + `panic_button.php?act=edit&id=${data.id}`;
// const formData = new FormData();
// formData.append("lat", data.lat);
// formData.append("lon", data.lon);
// formData.append("status_response", data.status_response);
const result = await axios const result = await axios
.put(url, payload, config) .put(url, payload, config)
.then(res => res) .then(res => res)
.catch((error) => error.response); .catch((error) => error.response);
// console.log(result)
if(result && result.data){ if(result && result.data){
if (result.data.code == 200) { if (result.data.code == 200) {
this.getDataPanicButton() this.getDataPanicButton()
@ -285,10 +271,6 @@ export default class index extends Component {
return ( return (
<tr key={n.id}> <tr key={n.id}>
<td> <td>
{/* <i id="TooltipDelete" className="cil-trash fa-lg" style={{ color: 'red', marginRight: '10px', cursor: "pointer" }} onClick={() => this.handleDelete(n.id)}></i>
<Tooltip placement="right" isOpen={this.state.tooltipDelete} target="TooltipDelete" toggle={() => this.toggle("delete")}>
Delete
</Tooltip>*/}
<Tooltip title="Edit"> <Tooltip title="Edit">
<i id="TooltipEdit" className="cil-pencil fa-lg" style={{ color: 'green', cursor: "pointer", marginRight: 15 }} onClick={() => this.handleEdit(n)}></i> <i id="TooltipEdit" className="cil-pencil fa-lg" style={{ color: 'green', cursor: "pointer", marginRight: 15 }} onClick={() => this.handleEdit(n)}></i>
</Tooltip> </Tooltip>
@ -299,13 +281,12 @@ export default class index extends Component {
<td>{ n.created_date!==null ? moment(n.created_at).format("DD-MM-YYYY HH:mm:ss") : "-" }</td> <td>{ n.created_date!==null ? moment(n.created_at).format("DD-MM-YYYY HH:mm:ss") : "-" }</td>
<td>{ n.join_first_name !==null ? n.join_first_name : "-" }</td> <td>{ n.join_first_name !==null ? n.join_first_name : "-" }</td>
<td>{ n.status_response!==null ? n.status_response : "-" }</td> <td>{ n.status_response!==null ? n.status_response : "-" }</td>
{/* <td>{ n.clock_out_time!==null ? moment(n.clock_out_time).format("HH:mm:ss") : "-" }</td> */}
</tr> </tr>
) )
}) : <tr> }) : <tr>
<td colSpan="4" align="center">No Data Available</td> <td colSpan="4" align="center">No Data Available</td>
</tr> </tr>
} }
</tbody> </tbody>
) )
} }
@ -314,31 +295,27 @@ export default class index extends Component {
const val = e.target.value; const val = e.target.value;
this.setState({ currentDay:val }); this.setState({ currentDay:val });
if(val==="today"){ if(val==="today"){
console.log("test 1 test",val);
this.setState({ this.setState({
startDate:moment(moment().format("YYYY-M-D")), startDate:moment(moment().format("YYYY-M-D")),
endDate:moment(moment().format("YYYY-M-D")), endDate:moment(moment().format("YYYY-M-D")),
currentPage: 1 currentPage: 1
}) })
}else if(val==="3 day"){ }else if(val==="3 day"){
console.log("test test",val);
this.setState({ this.setState({
startDate:moment(moment().subtract(3, "days").format("YYYY-M-D")), startDate:moment(moment().subtract(3, "days").format("YYYY-M-D")),
endDate:moment(moment().format("YYYY-M-D")), endDate:moment(moment().format("YYYY-M-D")),
currentPage: 1 currentPage: 1
}) })
}else if(val==="7 day"){ }else if(val==="7 day"){
console.log("test test",val);
this.setState({ this.setState({
startDate:moment(moment().subtract(7, "days").format("YYYY-M-D")), startDate:moment(moment().subtract(7, "days").format("YYYY-M-D")),
endDate:moment(moment().format("YYYY-M-D")), endDate:moment(moment().format("YYYY-M-D")),
currentPage: 1 currentPage: 1
}) })
}else{ }else{
console.log("test 2 test",val);
this.setState({ this.setState({
startDate:moment(moment().format("YYYY-M-D")), startDate:moment(moment().format("YYYY-M-D")),
endDate:moment(moment().format("YYYY-M-D")), endDate:moment(moment().format("YYYY-M-D")),
currentPage: 1 currentPage: 1
}) })
} }
@ -349,19 +326,6 @@ export default class index extends Component {
return ( return (
<div> <div>
<NotificationContainer /> <NotificationContainer />
{/* <SweetAlert
show={this.state.alertDelete}
warning
showCancel
confirmBtnText="Delete"
confirmBtnBsStyle="danger"
title="Are you sure?"
onConfirm={this.onConfirmDelete}
onCancel={() => this.setState({ alertDelete: false, idDelete: 0 })}
focusCancelBtn
>
Data tipe karyawan akan terhapus!!
</SweetAlert> */}
<DialogForm <DialogForm
openDialog={openDialog} openDialog={openDialog}
closeDialog={this.handleCloseDialog} closeDialog={this.handleCloseDialog}
@ -380,7 +344,6 @@ export default class index extends Component {
<CardHeader style={{ display: "flex", justifyContent: "space-between" }}> <CardHeader style={{ display: "flex", justifyContent: "space-between" }}>
<h4>Panic Button</h4> <h4>Panic Button</h4>
<div> <div>
{/* <Button color="primary" onClick={() => this.handleOpenDialog('Save')}>Tambah Broadcast</Button>{' '} */}
<Tooltip title="Export Excel"> <Tooltip title="Export Excel">
<Button id="TooltipExport" color="primary" onClick={()=> this.handleExportExcel()}><i className="fa fa-print"></i></Button> <Button id="TooltipExport" color="primary" onClick={()=> this.handleExportExcel()}><i className="fa fa-print"></i></Button>
</Tooltip> </Tooltip>
@ -401,12 +364,10 @@ export default class index extends Component {
<Button color="primary" onClick={() => this.getDataPanicButton()}>Cari</Button> <Button color="primary" onClick={() => this.getDataPanicButton()}>Cari</Button>
</div> </div>
</div> </div>
{/* <Input onChange={this.handleSearch} value={search} type="text" name="search" id="search" placeholder="Cari nama karyawan" style={{ maxWidth: "200px", marginBottom: "20px" }} /> */}
</div> </div>
<Table responsive striped hover> <Table responsive striped hover>
<thead> <thead>
<tr> <tr>
{/* <th>Actions</th> */}
{column.map((i, index) => { {column.map((i, index) => {
return ( return (
<th key={index} scope="row">{i.name}</th> <th key={index} scope="row">{i.name}</th>

770
src/views/SimproV2/ProjectType/index.js

@ -1,16 +1,15 @@
import * as XLSX from 'xlsx';
import DialogForm from './DialogForm';
import DialogInitialGantt from './DialogInitialGantt';
import React, { useState, useEffect, useMemo } from 'react'; import React, { useState, useEffect, useMemo } from 'react';
import SweetAlert from 'react-bootstrap-sweetalert';
import axios from "../../../const/interceptorApi"
import moment from 'moment'
import { Card, CardBody, CardHeader, Col, Row, Input } from 'reactstrap'; import { Card, CardBody, CardHeader, Col, Row, Input } from 'reactstrap';
import { DownloadOutlined } from '@ant-design/icons'; import { DownloadOutlined } from '@ant-design/icons';
import axios from "../../../const/interceptorApi"
import * as XLSX from 'xlsx';
import SweetAlert from 'react-bootstrap-sweetalert';
import DialogForm from './DialogForm';
import { NotificationContainer, NotificationManager } from 'react-notifications'; import { NotificationContainer, NotificationManager } from 'react-notifications';
import { PROJECT_TYPE_ADD, PROJECT_TYPE_EDIT, PROJECT_TYPE_DELETE, PROJECT_TYPE_SEARCH } from '../../../const/ApiConst';
import { Pagination, Button, Tooltip, Table} from 'antd'; import { Pagination, Button, Tooltip, Table} from 'antd';
import DialogInitialGantt from './DialogInitialGantt';
import { PROJECT_TYPE_ADD, PROJECT_TYPE_EDIT, PROJECT_TYPE_DELETE,
PROJECT_TYPE_SEARCH } from '../../../const/ApiConst';
import moment from 'moment'
const url = ""; const url = "";
const proyek_id = localStorage.getItem('proyek_id'); const proyek_id = localStorage.getItem('proyek_id');
@ -18,412 +17,361 @@ const role_id = localStorage.getItem('role_id');
const format = "DD-MM-YYYY"; const format = "DD-MM-YYYY";
const token = window.localStorage.getItem('token'); const token = window.localStorage.getItem('token');
const config = { const config = {
headers: headers:
{ {
Authorization : `Bearer ${token}`, Authorization : `Bearer ${token}`,
"Content-type" : `application/json` "Content-type" : `application/json`
} }
}; };
const column = [ const column = [
{ name: "Nama" }, { name: "Nama" },
{ name: "Deskripsi" }, { name: "Deskripsi" },
] ]
const ProjectType = ({params}) => { const ProjectType = ({params}) => {
const token = localStorage.getItem("token") const token = localStorage.getItem("token")
const HEADER = { const HEADER = {
headers: { headers: {
"Content-Type": "application/json", "Content-Type": "application/json",
"Authorization": `Bearer ${token}` "Authorization": `Bearer ${token}`
} }
} }
const pageName = params.name; const pageName = params.name;
const [search, setSearch] = useState('')
const [currentPage, setCurrentPage] = useState(1) const [alertDelete, setAlertDelete] = useState(false)
const [openDialog, setOpenDialog] = useState(false) const [allDataMenu, setAllDataMenu] = useState([])
const [typeDialog, setTypeDialog] = useState('Save') const [clickOpenModal, setClickOpenModal] = useState(false)
const [dataExport, setDataExport] = useState([]) const [currentPage, setCurrentPage] = useState(1)
const [rowsPerPage, setRowsPerPage] = useState(10) const [dataEdit, setDataEdit] = useState([])
const [dataEdit, setDataEdit] = useState([]) const [dataExport, setDataExport] = useState([])
const [alertDelete, setAlertDelete] = useState(false) const [dataTable, setDatatable] = useState([])
const [idDelete, setIdDelete] = useState(0) const [idDelete, setIdDelete] = useState(0)
const [dataTable, setDatatable] = useState([]) const [idTypeProject, setIdTypeProject] = useState(0)
const [clickOpenModal, setClickOpenModal] = useState(false) const [openDialog, setOpenDialog] = useState(false)
const [allDataMenu, setAllDataMenu] = useState([]) const [openDialogIG, setOpenDialogIG] = useState(false)
const [totalPage, setTotalPage] = useState(0) const [rowsPerPage, setRowsPerPage] = useState(10)
const [openDialogIG, setOpenDialogIG] = useState(false) const [search, setSearch] = useState('')
const [idTypeProject, setIdTypeProject] = useState(0) const [totalPage, setTotalPage] = useState(0)
const [typeDialog, setTypeDialog] = useState('Save')
useEffect(() => {
getDataProjectType() useEffect(() => {
}, [currentPage, rowsPerPage, search]) getDataProjectType()
}, [currentPage, rowsPerPage, search])
useEffect(() => {
const cekData = dataExport || [] useEffect(() => {
if (cekData.length > 0) { const cekData = dataExport || []
exportExcel() if (cekData.length > 0) {
} exportExcel()
}, [dataExport]) }
}, [dataExport])
const getDataProjectType = async () => {
const getDataProjectType = async () => {
let start = 0;
let start = 0;
if (currentPage !== 1 && currentPage > 1) {
start = (currentPage * rowsPerPage) - rowsPerPage if (currentPage !== 1 && currentPage > 1) {
} start = (currentPage * rowsPerPage) - rowsPerPage
}
const payload = {
"columns": [ const payload = {
{ "columns": [
"name":"name", {
"logic_operator":"like", "name":"name",
"value":search, "logic_operator":"like",
"operator":"AND" "value":search,
} "operator":"AND"
], }
"orders": { ],
"ascending": true, "orders": {
"columns": [ "ascending": true,
'id' "columns": [
] 'id'
}, ]
"paging": { },
"length": rowsPerPage, "paging": {
"start": start "length": rowsPerPage,
} "start": start
} }
}
// console.log("payload ", payload)
const result = await axios const result = await axios
.post(PROJECT_TYPE_SEARCH, payload, config) .post(PROJECT_TYPE_SEARCH, payload, config)
.then(res => res) .then(res => res)
.catch((error) => error.response); .catch((error) => error.response);
if(result && result.data && result.data.code == 200){
setDatatable(result.data.data);
if(result && result.data && result.data.code == 200){ setTotalPage(result.data.totalRecord);
console.log("get data ", result.data) }else{
setDatatable(result.data.data); NotificationManager.error('Gagal Mengambil Data!!', 'Failed');
setTotalPage(result.data.totalRecord); }
}else{ }
NotificationManager.error('Gagal Mengambil Data!!', 'Failed');
} const handleSearch = e => {
} const value = e.target.value
setSearch(value);
const handleSearch = e => { setCurrentPage(1)
const value = e.target.value };
setSearch(value);
setCurrentPage(1) const handleOpenDialog = (type) => {
}; setOpenDialog(true)
setTypeDialog(type)
const handleOpenDialog = (type) => { }
setOpenDialog(true)
setTypeDialog(type) const handleExportExcel = async () => {
} let start = 0;
const handleExportExcel = async () => { const payload = {
"paging": { "start": start, "length": -1 },
let start = 0; "columns": [
{ "name": "name", "logic_operator": "like", "value": search, "operator": "AND" }
const payload = { ],
"paging": { "start": start, "length": -1 }, "joins": [],
"columns": [ "orders": { "columns": ["id"], "ascending": false }
{ "name": "name", "logic_operator": "like", "value": search, "operator": "AND" } }
],
"joins": [], const result = await axios
"orders": { "columns": ["id"], "ascending": false } .post(PROJECT_TYPE_SEARCH, payload)
} .then(res => res)
.catch((error) => error.response);
if (result && result.data && result.data.code == 200) {
const result = await axios let resData = result.data.data;
.post(PROJECT_TYPE_SEARCH, payload) const excelData = [];
.then(res => res) resData.map((val, index) => {
.catch((error) => error.response); let dataRow = {
"Nama": val.name,
// console.log(result) "Deskripsi": val.description,
}
if (result && result.data && result.data.code == 200) { excelData.push(dataRow)
let resData = result.data.data; })
const excelData = []; await setDataExport(excelData);
resData.map((val, index) => { } else {
let dataRow = { NotificationManager.error('Gagal Export Data!!', 'Failed');
"Nama": val.name, }
"Deskripsi": val.description, }
}
excelData.push(dataRow) const exportExcel = () => {
}) const dataExcel = dataExport || [];
// console.log("cek excel data", excelData) const fileName = `Data ${pageName}.xlsx`;
await setDataExport(excelData); const ws = XLSX.utils.json_to_sheet(dataExcel);
// exportExcel(); const wb = XLSX.utils.book_new();
} else { XLSX.utils.book_append_sheet(wb, ws, `Data ${pageName}`);
NotificationManager.error('Gagal Export Data!!', 'Failed'); XLSX.writeFile(wb, fileName);
} setDataExport([])
} }
const exportExcel = () => { const handleEdit = (data) => {
const dataExcel = dataExport || []; setDataEdit(data)
const fileName = `Data ${pageName}.xlsx`; handleOpenDialog('Edit');
const ws = XLSX.utils.json_to_sheet(dataExcel); }
const wb = XLSX.utils.book_new();
XLSX.utils.book_append_sheet(wb, ws, `Data ${pageName}`); const handleDelete = async (id) => {
await setAlertDelete(true)
XLSX.writeFile(wb, fileName); await setIdDelete(id)
setDataExport([]) }
}
const handleCloseDialog = (type, data) => {
const handleEdit = (data) => { if (type === "save") {
setDataEdit(data) saveProjectType(data);
handleOpenDialog('Edit'); } else if (type === "edit") {
} editMaterialR(data);
}
const handleDelete = async (id) => { setDataEdit([])
await setAlertDelete(true) setOpenDialog(false)
await setIdDelete(id) }
}
const saveProjectType = async (data) => {
const handleCloseDialog = (type, data) => { const formData = data
if (type === "save") { const result = await axios.post(PROJECT_TYPE_ADD, formData, HEADER)
saveProjectType(data); .then(res => res)
} else if (type === "edit") { .catch((error) => error.response);
editMaterialR(data);
} if (result && result.data && result.data.code === 200) {
setDataEdit([]) getDataProjectType()
setOpenDialog(false) NotificationManager.success(`Data project type berhasil ditambah`, 'Success!!');
} } else {
NotificationManager.error(`${result.data.message}`, 'Failed!!');
const saveProjectType = async (data) => { }
const formData = data }
const result = await axios.post(PROJECT_TYPE_ADD, formData, HEADER)
.then(res => res) const editMaterialR = async (data) => {
.catch((error) => error.response); let urlEdit = PROJECT_TYPE_EDIT(data.id)
const formData = data
if (result && result.data && result.data.code === 200) {
getDataProjectType() const result = await axios.put(urlEdit, formData, HEADER)
// console.log("data material s ", formData) .then(res => res)
NotificationManager.success(`Data project type berhasil ditambah`, 'Success!!'); .catch((error) => error.response);
} else {
// console.log("data material fail ", formData) if (result && result.data && result.data.code === 200) {
NotificationManager.error(`${result.data.message}`, 'Failed!!'); getDataProjectType();
} NotificationManager.success(`Data project type berhasil diedit`, 'Success!!');
} } else {
NotificationManager.error(`Data project type gagal di edit`, `Failed!!`);
const editMaterialR = async (data) => { }
}
let urlEdit = PROJECT_TYPE_EDIT(data.id)
const formData = data const toggleAddDialog = () => {
setOpenDialog(!openDialog)
console.log("from data edit ", formData) }
const result = await axios.put(urlEdit, formData, HEADER) const handleDialogIg = (id) => {
.then(res => res) setIdTypeProject(id)
.catch((error) => error.response); setOpenDialogIG(true)
}
if (result && result.data && result.data.code === 200) {
getDataProjectType(); const closeDialogIG = () => {
NotificationManager.success(`Data project type berhasil diedit`, 'Success!!'); setIdTypeProject(0)
} else { setOpenDialogIG(false)
NotificationManager.error(`Data project type gagal di edit`, `Failed!!`); }
}
} const toggleDialogIG = () => {
if(openDialogIG){
const toggleAddDialog = () => { setIdTypeProject(0)
setOpenDialog(!openDialog) }
} setOpenDialogIG(!openDialogIG);
}
const handleDialogIg = (id) => {
setIdTypeProject(id) const onConfirmDelete = async () => {
setOpenDialogIG(true) let url = PROJECT_TYPE_DELETE(idDelete);
}
const result = await axios.delete(url,config)
const closeDialogIG = () => { .then(res => res)
setIdTypeProject(0) .catch((error) => error.response);
setOpenDialogIG(false)
} if (result && result.data && result.data.code === 200) {
getDataProjectType()
const toggleDialogIG = () => { setIdDelete(0)
if(openDialogIG){ setAlertDelete(false)
setIdTypeProject(0) NotificationManager.success(`Data project type berhasil dihapus!`, 'Success!!');
} } else {
setOpenDialogIG(!openDialogIG); setIdDelete(0)
} setAlertDelete(false)
NotificationManager.error(`Data project type gagal dihapus!}`, 'Failed!!');
const onConfirmDelete = async () => { }
let url = PROJECT_TYPE_DELETE(idDelete); }
const result = await axios.delete(url,config) const cancelDelete = () => {
.then(res => res) setAlertDelete(false)
.catch((error) => error.response); setIdDelete(0)
}
if (result && result.data && result.data.code === 200) {
getDataProjectType() const onShowSizeChange = (current, pageSize) => {
setIdDelete(0) setRowsPerPage(pageSize)
setAlertDelete(false) }
NotificationManager.success(`Data project type berhasil dihapus!`, 'Success!!');
} else { const onPagination = (current, pageSize) => {
setIdDelete(0) setCurrentPage(current)
setAlertDelete(false) }
NotificationManager.error(`Data project type gagal dihapus!}`, 'Failed!!');
} const dataNotAvailable = () => {
} if(dataTable.length===0){
return (
const cancelDelete = () => { <tr>
setAlertDelete(false) <td align="center" colSpan="3">Tidak ada data project type</td>
setIdDelete(0) </tr>
} )
}
const onShowSizeChange = (current, pageSize) => { }
setRowsPerPage(pageSize)
} const renderTable = useMemo(() => {
const columns = [
const onPagination = (current, pageSize) => { {
setCurrentPage(current) title: 'Action',
} dataIndex: '',
key: 'x',
const dataNotAvailable = () => { className:'nowrap',
if(dataTable.length===0){ render: (text, record) => <>
return ( <Tooltip title="Delete">
<tr> <i className="fa fa-trash" style={{ color: 'red', marginRight: '10px', cursor: "pointer" }} onClick={() => handleDelete(text.id)}></i>
<td align="center" colSpan="3">Tidak ada data project type</td> </Tooltip>
</tr> <Tooltip title="Edit">
) <i className="fa fa-edit" style={{ color: 'green', cursor: "pointer" }} onClick={() => handleEdit(text)}></i>
} </Tooltip>{" "}
} <Tooltip title="Template Gantt">
<i className="fa fa-gears" style={{ color: 'blue', cursor: "pointer" }} onClick={() => handleDialogIg(text.id)}></i>
const renderTable = useMemo(() => { </Tooltip>
const columns = [ </>,
{ },
title: 'Action', { title: 'Nama Role', dataIndex: 'name', key: 'name', className:"nowrap" },
dataIndex: '', { title: 'Description', dataIndex: 'description', key: 'description' },
key: 'x', ];
className:'nowrap', return (
render: (text, record) => <> <Table
<Tooltip title="Delete"> rowKey="id"
<i className="fa fa-trash" style={{ color: 'red', marginRight: '10px', cursor: "pointer" }} onClick={() => handleDelete(text.id)}></i> size="small"
</Tooltip> columns={columns}
<Tooltip title="Edit"> dataSource={dataTable}
<i className="fa fa-edit" style={{ color: 'green', cursor: "pointer" }} onClick={() => handleEdit(text)}></i> pagination={false}
</Tooltip>{" "} />
<Tooltip title="Template Gantt"> )
<i className="fa fa-gears" style={{ color: 'blue', cursor: "pointer" }} onClick={() => handleDialogIg(text.id)}></i> }, [dataTable])
</Tooltip>
</>, return (
}, <div>
{ title: 'Nama Role', dataIndex: 'name', key: 'name', className:"nowrap" }, <NotificationContainer />
{ title: 'Description', dataIndex: 'description', key: 'description' }, <SweetAlert
]; show={alertDelete}
return ( warning
<Table showCancel
rowKey="id" confirmBtnText="Delete"
size="small" confirmBtnBsStyle="danger"
columns={columns} title={`Are you sure?`}
dataSource={dataTable} onConfirm={onConfirmDelete}
pagination={false} onCancel={() => cancelDelete()}
/> focusCancelBtn
) >
}, [dataTable]) Delete this data
</SweetAlert>
<DialogForm
openDialog={openDialog}
return ( closeDialog={handleCloseDialog}
<div> toggleDialog={() => toggleAddDialog}
<NotificationContainer /> typeDialog={typeDialog}
<SweetAlert dataEdit={dataEdit}
show={alertDelete} clickOpenModal={clickOpenModal}
warning dataParent={allDataMenu}
showCancel />
confirmBtnText="Delete" <DialogInitialGantt
confirmBtnBsStyle="danger" openDialog={openDialogIG}
title={`Are you sure?`} closeDialog={closeDialogIG}
onConfirm={onConfirmDelete} toggleDialog={toggleDialogIG}
onCancel={() => cancelDelete()} idTypeProject={idTypeProject}
focusCancelBtn />
> <Card>
Delete this data <CardHeader style={{ display: "flex", justifyContent: "space-between" }}>
</SweetAlert> <h4 className="capitalize">{pageName}</h4>
<DialogForm <Row>
openDialog={openDialog} <Col>
closeDialog={handleCloseDialog} <Input onChange={handleSearch} value={search} type="text" name="search" id="search" placeholder={`Search project type...`} />
toggleDialog={() => toggleAddDialog} </Col>
typeDialog={typeDialog} <Col>
dataEdit={dataEdit} <Tooltip title="Add Material Resource">
clickOpenModal={clickOpenModal} <Button style={{ background: "#4caf50", color: "#fff" }} onClick={() => handleOpenDialog('Save')}><i className="fa fa-plus"></i></Button>
dataParent={allDataMenu} </Tooltip>
/> <Tooltip title="Export Excel">
<DialogInitialGantt <Button style={{ marginLeft: "5px" }} onClick={() => handleExportExcel()}><i className="fa fa-print"></i></Button>
openDialog={openDialogIG} </Tooltip>
closeDialog={closeDialogIG} </Col>
toggleDialog={toggleDialogIG} </Row>
idTypeProject={idTypeProject} </CardHeader>
/> <CardBody>
<Card> {renderTable}
<CardHeader style={{ display: "flex", justifyContent: "space-between" }}> <Pagination
<h4 className="capitalize">{pageName}</h4> style={{marginTop:"25px"}}
<Row> showSizeChanger
<Col> onShowSizeChange={onShowSizeChange}
<Input onChange={handleSearch} value={search} type="text" name="search" id="search" placeholder={`Search project type...`} /> onChange={onPagination}
</Col> defaultCurrent={currentPage}
<Col> pageSize={rowsPerPage}
<Tooltip title="Add Material Resource"> total={totalPage}
<Button style={{ background: "#4caf50", color: "#fff" }} onClick={() => handleOpenDialog('Save')}><i className="fa fa-plus"></i></Button> pageSizeOptions={["10", "15", "20", "25", "30", "35", "40"]}
</Tooltip> />
<Tooltip title="Export Excel"> </CardBody>
<Button style={{ marginLeft: "5px" }} onClick={() => handleExportExcel()}><i className="fa fa-print"></i></Button> </Card>
</Tooltip> </div>
</Col> )
</Row> }
</CardHeader>
<CardBody> export default ProjectType;
{/* <Table responsive striped hover>
<thead>
<tr>
<th>Aksi</th>
{column.map((i, index) => {
return (
<th key={index} scope="row">{i.name}</th>
)
})}
</tr>
</thead>
<tbody>
{dataNotAvailable()}
{dataTable.map((n, index) => {
return (
<tr key={n.id}>
<td className='nowrap'>
<Tooltip title="Hapus">
<i id="TooltipDelete" className="cil-trash fa-lg" style={{ color: 'red', marginRight: 10, cursor: "pointer" }} onClick={() => handleDelete(n.id)}></i>
</Tooltip>
<Tooltip title="Edit">
<i id="TooltipEdit" className="cil-pencil fa-lg" style={{ color: 'green', cursor: "pointer" }} onClick={() => handleEdit(n)}></i>
</Tooltip>
</td>
<td>{n.name}</td>
<td>{n.description}</td>
</tr>
)
})}
</tbody>
</Table> */}
{renderTable}
<Pagination
style={{marginTop:"25px"}}
showSizeChanger
onShowSizeChange={onShowSizeChange}
onChange={onPagination}
defaultCurrent={currentPage}
pageSize={rowsPerPage}
total={totalPage}
pageSizeOptions={["10", "15", "20", "25", "30", "35", "40"]}
/>
</CardBody>
</Card>
</div>
)
}
export default ProjectType;

100
src/views/SimproV2/ResourceMaterial/index.js

@ -1,9 +1,11 @@
import * as XLSX from 'xlsx';
import DialogForm from './DialogForm';
import React, { useState, useEffect, useMemo } from 'react'; import React, { useState, useEffect, useMemo } from 'react';
import SweetAlert from 'react-bootstrap-sweetalert';
import axios from "../../../const/interceptorApi"
import moment from 'moment'
import { Card, CardBody, CardHeader, Col, Row, Input } from 'reactstrap'; import { Card, CardBody, CardHeader, Col, Row, Input } from 'reactstrap';
import { DownloadOutlined } from '@ant-design/icons'; import { DownloadOutlined } from '@ant-design/icons';
import * as XLSX from 'xlsx';
import SweetAlert from 'react-bootstrap-sweetalert';
import DialogForm from './DialogForm';
import { NotificationContainer, NotificationManager } from 'react-notifications'; import { NotificationContainer, NotificationManager } from 'react-notifications';
import { Pagination, Table, Button, Tooltip, Tabs, Collapse } from 'antd'; import { Pagination, Table, Button, Tooltip, Tabs, Collapse } from 'antd';
import { formatRupiah, formatNumber, renderLabelStatus } from '../../../const/CustomFunc' import { formatRupiah, formatNumber, renderLabelStatus } from '../../../const/CustomFunc'
@ -14,8 +16,6 @@ import {
REQUEST_MATERIAL_SEARCH, REQUEST_MATERIAL_EDIT, REQUEST_MATERIAL_SEARCH, REQUEST_MATERIAL_EDIT,
REQUEST_MATERIAL_UPDATE_WAREHOUSE_SITE REQUEST_MATERIAL_UPDATE_WAREHOUSE_SITE
} from '../../../const/ApiConst'; } from '../../../const/ApiConst';
import moment from 'moment'
import axios from "../../../const/interceptorApi"
const { TabPane } = Tabs; const { TabPane } = Tabs;
const { Panel } = Collapse; const { Panel } = Collapse;
@ -26,15 +26,12 @@ const role_id = localStorage.getItem('role_id');
const format = "DD-MM-YYYY"; const format = "DD-MM-YYYY";
const groupBy = (array, key) => { const groupBy = (array, key) => {
// Return the end result
return array.reduce((result, currentValue) => { return array.reduce((result, currentValue) => {
// If an array already present for key, push it to the array. Else create an array and push the object
(result[currentValue[key]] = result[currentValue[key]] || []).push( (result[currentValue[key]] = result[currentValue[key]] || []).push(
currentValue currentValue
); );
// Return the current iteration `result` value, this will be taken as next iteration `result` value and accumulate
return result; return result;
}, {}); // empty object is the initial value for result object }, {});
}; };
const Resource = ({ params }) => { const Resource = ({ params }) => {
@ -45,22 +42,23 @@ const Resource = ({ params }) => {
"Authorization": `Bearer ${token}` "Authorization": `Bearer ${token}`
} }
} }
const pageName = params.name;
const [search, setSearch] = useState('') const [alertDelete, setAlertDelete] = useState(false)
const [allDataMenu, setAllDataMenu] = useState([])
const [clickOpenModal, setClickOpenModal] = useState(false)
const [currentPage, setCurrentPage] = useState(1) const [currentPage, setCurrentPage] = useState(1)
const [openDialog, setOpenDialog] = useState(false) const [dataDelvMaterial, setDataDelvMaterial] = useState([])
const [typeDialog, setTypeDialog] = useState('Save')
const [dataExport, setDataExport] = useState([])
const [rowsPerPage, setRowsPerPage] = useState(10)
const [dataEdit, setDataEdit] = useState([]) const [dataEdit, setDataEdit] = useState([])
const [alertDelete, setAlertDelete] = useState(false) const [dataExport, setDataExport] = useState([])
const [idDelete, setIdDelete] = useState(0) const [dataReqMaterial, setDataReqMaterial] = useState([])
const [dataTable, setDatatable] = useState([]) const [dataTable, setDatatable] = useState([])
const [clickOpenModal, setClickOpenModal] = useState(false) const [idDelete, setIdDelete] = useState(0)
const [allDataMenu, setAllDataMenu] = useState([]) const [openDialog, setOpenDialog] = useState(false)
const [rowsPerPage, setRowsPerPage] = useState(10)
const [search, setSearch] = useState('')
const [totalPage, setTotalPage] = useState(0) const [totalPage, setTotalPage] = useState(0)
const [dataReqMaterial, setDataReqMaterial] = useState([]) const [typeDialog, setTypeDialog] = useState('Save')
const [dataDelvMaterial, setDataDelvMaterial] = useState([]) const pageName = params.name;
useEffect(() => { useEffect(() => {
getDataReqMaterial() getDataReqMaterial()
@ -99,16 +97,12 @@ const Resource = ({ params }) => {
} }
} }
// console.log("payload ", payload)
const result = await axios const result = await axios
.post(MATERIAL_RESOURCE_SEARCH, payload, HEADER) .post(MATERIAL_RESOURCE_SEARCH, payload, HEADER)
.then(res => res) .then(res => res)
.catch((error) => error.response); .catch((error) => error.response);
if (result && result.data && result.data.code == 200) { if (result && result.data && result.data.code == 200) {
console.log("get data ", result.data)
setDatatable(result.data.data); setDatatable(result.data.data);
setTotalPage(result.data.totalRecord); setTotalPage(result.data.totalRecord);
} else { } else {
@ -120,7 +114,6 @@ const Resource = ({ params }) => {
const payload = { const payload = {
"columns": [ "columns": [
{ "name": "description", "logic_operator": "like", "value": "", "operator": "AND" }, { "name": "description", "logic_operator": "like", "value": "", "operator": "AND" },
// { "name": "proyek_id", "logic_operator": "=", "value": idTask, "operator": "AND" }
], ],
"joins": [ "joins": [
{ "name": "m_proyek", "column_join": "proyek_id", "column_results": ["kode_sortname", "nama"] } { "name": "m_proyek", "column_join": "proyek_id", "column_results": ["kode_sortname", "nama"] }
@ -133,7 +126,6 @@ const Resource = ({ params }) => {
.post(REQUEST_MATERIAL_SEARCH, payload, HEADER) .post(REQUEST_MATERIAL_SEARCH, payload, HEADER)
.then(res => res) .then(res => res)
.catch((error) => error.response); .catch((error) => error.response);
console.log("result getDataReqMaterial", result)
if (result && result.status == 200) { if (result && result.status == 200) {
if (result.data.data && result.data.data.length > 0) { if (result.data.data && result.data.data.length > 0) {
@ -149,9 +141,6 @@ const Resource = ({ params }) => {
} }
}) })
// const groupedProject = groupBy(result.data.data, 'proyek_id');
// console.log('dataReqMaterial', groupedProject);
const groupedProjectReq = groupBy(filtered_matReq, 'proyek_id'); const groupedProjectReq = groupBy(filtered_matReq, 'proyek_id');
const groupedProjectDelv = groupBy(filtered_matDelv, 'proyek_id'); const groupedProjectDelv = groupBy(filtered_matDelv, 'proyek_id');
@ -178,9 +167,6 @@ const Resource = ({ params }) => {
const payload = { const payload = {
"paging": { "start": 0, "length": -1 }, "paging": { "start": 0, "length": -1 },
// "columns": [
// { "name": "nama", "logic_operator": "like", "value": search, "operator": "AND" }
// ],
"joins": [], "joins": [],
"orders": { "columns": ["id"], "ascending": false } "orders": { "columns": ["id"], "ascending": false }
} }
@ -196,18 +182,10 @@ const Resource = ({ params }) => {
.then(res => res) .then(res => res)
.catch((error) => error.response); .catch((error) => error.response);
// console.log(result)
if (result && result.data && result.data.code == 200) { if (result && result.data && result.data.code == 200) {
let resData = result.data.data; let resData = result.data.data;
const excelData = []; const excelData = [];
// <td>{n.nama}</td>
// <td>{n.biaya}</td>
// <td style={{textAlign:"center"}}><div style={{borderRadius:"50%",height:"25px",width:"25px",backgroundColor:n.color_progress}}></div></td>
// <td>{n.jumlah_pekerja}</td>
// <td>{n.pic}</td>
// <td>{n.mulai_proyek ? moment(n.mulai_proyek).format("DD-MM-YYYY") : "-"}</td>
// <td>{n.akhir_proyek ? moment(n.akhir_proyek).format("DD-MM-YYYY") : "-"}</td>
resData.map((n, index) => { resData.map((n, index) => {
let dataRow = { let dataRow = {
"Nama Proyek": n.nama, "Nama Proyek": n.nama,
@ -219,9 +197,7 @@ const Resource = ({ params }) => {
} }
excelData.push(dataRow) excelData.push(dataRow)
}) })
// console.log("cek excel data", excelData)
await setDataExport(excelData); await setDataExport(excelData);
// exportExcel();
} else { } else {
NotificationManager.error('Gagal Export Data!!', 'Failed'); NotificationManager.error('Gagal Export Data!!', 'Failed');
} }
@ -261,23 +237,14 @@ const Resource = ({ params }) => {
const saveMaterialResource = async (data) => { const saveMaterialResource = async (data) => {
const formData = data const formData = data
// {
// 'name': data.materialName,
// 'description': data.description,
// 'unit_price': parseInt(data.unitPrice),
// 'uom': data.uom
// }
// console.log("data material ", formData)
const result = await axios.post(MATERIAL_RESOURCE_ADD, formData, HEADER) const result = await axios.post(MATERIAL_RESOURCE_ADD, formData, HEADER)
.then(res => res) .then(res => res)
.catch((error) => error.response); .catch((error) => error.response);
if (result && result.data && result.data.code === 200) { if (result && result.data && result.data.code === 200) {
getDataMaterialR() getDataMaterialR()
// console.log("data material s ", formData)
NotificationManager.success(`Data material resource berhasil ditambah`, 'Success!!'); NotificationManager.success(`Data material resource berhasil ditambah`, 'Success!!');
} else { } else {
// console.log("data material fail ", formData)
NotificationManager.error(`${result.data.message}`, 'Failed!!'); NotificationManager.error(`${result.data.message}`, 'Failed!!');
} }
} }
@ -287,7 +254,6 @@ const Resource = ({ params }) => {
let urlEdit = MATERIAL_RESOURCE_EDIT(data.id) let urlEdit = MATERIAL_RESOURCE_EDIT(data.id)
const formData = data const formData = data
console.log("from data edit ", formData)
const result = await axios.put(urlEdit, formData, HEADER) const result = await axios.put(urlEdit, formData, HEADER)
.then(res => res) .then(res => res)
@ -305,7 +271,6 @@ const Resource = ({ params }) => {
let urlEdit = REQUEST_MATERIAL_EDIT(data.id) let urlEdit = REQUEST_MATERIAL_EDIT(data.id)
const formData = data const formData = data
console.log("from data edit ", formData)
const result = await axios.put(urlEdit, formData, HEADER) const result = await axios.put(urlEdit, formData, HEADER)
.then(res => res) .then(res => res)
@ -323,7 +288,6 @@ const Resource = ({ params }) => {
let urlEdit = REQUEST_MATERIAL_EDIT(data.id) let urlEdit = REQUEST_MATERIAL_EDIT(data.id)
const formData = data const formData = data
console.log("from data edit ", formData)
const result = await axios.put(urlEdit, formData, HEADER) const result = await axios.put(urlEdit, formData, HEADER)
.then(res => res) .then(res => res)
@ -392,10 +356,6 @@ const Resource = ({ params }) => {
{ title: 'Material Name', dataIndex: 'name', key: 'name' }, { title: 'Material Name', dataIndex: 'name', key: 'name' },
{ title: 'QTY', dataIndex: 'qty', key: 'qty' }, { title: 'QTY', dataIndex: 'qty', key: 'qty' },
{ title: 'UOM', dataIndex: 'uom', key: 'uom' }, { title: 'UOM', dataIndex: 'uom', key: 'uom' },
// {
// title: 'Unit Price', dataIndex: 'unit_price', key: 'unit_price',
// render: (text, record) => { return renderFormatNumber(text, "Rp") }
// },
{ title: 'Description', dataIndex: 'description', key: 'description' }, { title: 'Description', dataIndex: 'description', key: 'description' },
{ title: 'Status', dataIndex: 'status', key: 'status' } { title: 'Status', dataIndex: 'status', key: 'status' }
]; ];
@ -417,14 +377,6 @@ const Resource = ({ params }) => {
dataIndex: '', dataIndex: '',
key: 'id', key: 'id',
className: "nowrap", className: "nowrap",
// render: (text, record) => <>
// {text.status=="fom" ? <><Tooltip title="Delete Request Resource">
// <Button size="small" type="link" style={{color:'red'}} onClick={() => handleDelete(text.id)}><i className="fa fa-trash"></i></Button>
// </Tooltip>{" "}<Tooltip title="Edit Request Resource">
// <Button size="small" type="link" style={{color:'orange'}} onClick={() => handleEdit(text, 'EditMatReq')}><i className="fa fa-edit"></i></Button>
// </Tooltip></> : "-"}
// </>,
render: (text, record) => <> render: (text, record) => <>
<Tooltip title="Edit Request Resource"> <Tooltip title="Edit Request Resource">
<Button size="small" type="link" style={{ color: 'orange' }} onClick={() => handleEdit(text, 'EditMatReq')}><i className="fa fa-edit"></i></Button> <Button size="small" type="link" style={{ color: 'orange' }} onClick={() => handleEdit(text, 'EditMatReq')}><i className="fa fa-edit"></i></Button>
@ -451,9 +403,7 @@ const Resource = ({ params }) => {
let componentGroup = []; let componentGroup = [];
for (const proyek_id in dataReqMaterial) { for (const proyek_id in dataReqMaterial) {
// console.log('proyek_id', proyek_id);
const title = `${dataReqMaterial[proyek_id][0]['join_first_kode_sortname']} - ${dataReqMaterial[proyek_id][0]['join_first_nama']}`; const title = `${dataReqMaterial[proyek_id][0]['join_first_kode_sortname']} - ${dataReqMaterial[proyek_id][0]['join_first_nama']}`;
// console.log('title', title);
componentGroup.push( componentGroup.push(
<Panel header={title} key={proyek_id}> <Panel header={title} key={proyek_id}>
<Table <Table
@ -466,7 +416,6 @@ const Resource = ({ params }) => {
) )
} }
// console.log('componentGroup', componentGroup);
return componentGroup.map((item, index) => { return componentGroup.map((item, index) => {
return item; return item;
}) })
@ -507,9 +456,7 @@ const Resource = ({ params }) => {
let componentGroup = []; let componentGroup = [];
for (const proyek_id in dataDelvMaterial) { for (const proyek_id in dataDelvMaterial) {
// console.log('proyek_id', proyek_id);
const title = `${dataDelvMaterial[proyek_id][0]['join_first_kode_sortname']} - ${dataDelvMaterial[proyek_id][0]['join_first_nama']}`; const title = `${dataDelvMaterial[proyek_id][0]['join_first_kode_sortname']} - ${dataDelvMaterial[proyek_id][0]['join_first_nama']}`;
// console.log('title', title);
componentGroup.push( componentGroup.push(
<Panel header={title} key={proyek_id}> <Panel header={title} key={proyek_id}>
<Table <Table
@ -522,7 +469,6 @@ const Resource = ({ params }) => {
) )
} }
// console.log('componentGroup', componentGroup);
return componentGroup.map((item, index) => { return componentGroup.map((item, index) => {
return item; return item;
}) })
@ -574,9 +520,6 @@ const Resource = ({ params }) => {
<Input onChange={handleSearch} value={search} type="text" name="search" id="search" placeholder={`Search...`} /> <Input onChange={handleSearch} value={search} type="text" name="search" id="search" placeholder={`Search...`} />
</Col> </Col>
<Col> <Col>
{/* <Tooltip title="Add Material Resource">
<Button style={{ background: "#4caf50", color: "#fff" }} onClick={() => handleOpenDialog('Save')}><i className="fa fa-plus"></i></Button>
</Tooltip> */}
<Tooltip title="Export Excel"> <Tooltip title="Export Excel">
<Button style={{ marginLeft: "5px" }} onClick={() => handleExportExcel()}><i className="fa fa-print"></i></Button> <Button style={{ marginLeft: "5px" }} onClick={() => handleExportExcel()}><i className="fa fa-print"></i></Button>
</Tooltip> </Tooltip>
@ -602,9 +545,6 @@ const Resource = ({ params }) => {
<Input onChange={handleSearch} value={search} type="text" name="search" id="search" placeholder={`Search...`} /> <Input onChange={handleSearch} value={search} type="text" name="search" id="search" placeholder={`Search...`} />
</Col> </Col>
<Col> <Col>
{/* <Tooltip title="Add Material Resource">
<Button style={{ background: "#4caf50", color: "#fff" }} onClick={() => handleOpenDialog('Save')}><i className="fa fa-plus"></i></Button>
</Tooltip> */}
<Tooltip title="Export Excel"> <Tooltip title="Export Excel">
<Button style={{ marginLeft: "5px" }} onClick={() => handleExportExcel()}><i className="fa fa-print"></i></Button> <Button style={{ marginLeft: "5px" }} onClick={() => handleExportExcel()}><i className="fa fa-print"></i></Button>
</Tooltip> </Tooltip>
@ -660,4 +600,4 @@ const Resource = ({ params }) => {
) )
} }
export default Resource; export default Resource;

80
src/views/SimproV2/ResourceTools/index.js

@ -1,20 +1,19 @@
import * as XLSX from 'xlsx';
import DialogForm from './DialogForm';
import DialogTools from './DialogEditReqTools';
import React, { useState, useEffect, useMemo } from 'react'; import React, { useState, useEffect, useMemo } from 'react';
import SweetAlert from 'react-bootstrap-sweetalert';
import _, { initial } from 'underscore'
import axios from "../../../const/interceptorApi"
import moment from 'moment'
import { Card, CardBody, CardHeader, Col, Row, Input } from 'reactstrap'; import { Card, CardBody, CardHeader, Col, Row, Input } from 'reactstrap';
import { DownloadOutlined } from '@ant-design/icons'; import { DownloadOutlined } from '@ant-design/icons';
import * as XLSX from 'xlsx';
import SweetAlert from 'react-bootstrap-sweetalert';
import DialogForm from './DialogForm';
import { NotificationContainer, NotificationManager } from 'react-notifications'; import { NotificationContainer, NotificationManager } from 'react-notifications';
import { Pagination, Table, Button, Tooltip, Tabs, Collapse } from 'antd'; import { Pagination, Table, Button, Tooltip, Tabs, Collapse } from 'antd';
import { renderLabelStatus } from '../../../const/CustomFunc';
import { import {
// AXIOS,
TOOLS_RESOURCE_ADD, TOOLS_RESOURCE_SEARCH, REQUEST_TOOLS_SEARCH, TOOLS_RESOURCE_EDIT, TOOLS_RESOURCE_DELETE TOOLS_RESOURCE_ADD, TOOLS_RESOURCE_SEARCH, REQUEST_TOOLS_SEARCH, TOOLS_RESOURCE_EDIT, TOOLS_RESOURCE_DELETE
} from '../../../const/ApiConst'; } from '../../../const/ApiConst';
import moment from 'moment'
import _, { initial } from 'underscore'
import DialogTools from './DialogEditReqTools';
import axios from "../../../const/interceptorApi"
import { renderLabelStatus } from '../../../const/CustomFunc';
const { TabPane } = Tabs; const { TabPane } = Tabs;
const { Panel } = Collapse; const { Panel } = Collapse;
@ -40,24 +39,25 @@ const ResourceWorker = ({ params }) => {
"Authorization": `Bearer ${token}` "Authorization": `Bearer ${token}`
} }
} }
const pageName = params.name;
const [search, setSearch] = useState('')
const [currentPage, setCurrentPage] = useState(1)
const [openDialog, setOpenDialog] = useState(false)
const [typeDialog, setTypeDialog] = useState('Save')
const [dataExport, setDataExport] = useState([])
const [rowsPerPage, setRowsPerPage] = useState(10)
const [dataEdit, setDataEdit] = useState(null)
const [alertDelete, setAlertDelete] = useState(false) const [alertDelete, setAlertDelete] = useState(false)
const [idDelete, setIdDelete] = useState(0)
const [dataTable, setDatatable] = useState([])
const [clickOpenModal, setClickOpenModal] = useState(false) const [clickOpenModal, setClickOpenModal] = useState(false)
const [totalPage, setTotalPage] = useState(0) const [currentPage, setCurrentPage] = useState(1)
const [roleList, setRoleList] = useState([])
const [dataReqTools, setDataReqTools] = useState([]);
const [dataDeliveryTools, setDataDeliveryTools] = useState([]); const [dataDeliveryTools, setDataDeliveryTools] = useState([]);
const [openDialogFormTools, setOpenDialogFormTools] = useState(false); const [dataEdit, setDataEdit] = useState(null)
const [dataExport, setDataExport] = useState([])
const [dataReqTools, setDataReqTools] = useState([]);
const [dataTable, setDatatable] = useState([])
const [idDelete, setIdDelete] = useState(0)
const [idTask, setIdTask] = useState(0); const [idTask, setIdTask] = useState(0);
const [openDialog, setOpenDialog] = useState(false)
const [openDialogFormTools, setOpenDialogFormTools] = useState(false);
const [roleList, setRoleList] = useState([])
const [rowsPerPage, setRowsPerPage] = useState(10)
const [search, setSearch] = useState('')
const [totalPage, setTotalPage] = useState(0)
const [typeDialog, setTypeDialog] = useState('Save')
const pageName = params.name;
useEffect(() => { useEffect(() => {
getDataReqTools() getDataReqTools()
@ -112,7 +112,6 @@ const ResourceWorker = ({ params }) => {
.catch((error) => error.response); .catch((error) => error.response);
if (result && result.data && result.data.code == 200) { if (result && result.data && result.data.code == 200) {
console.log(result.data.data)
setDatatable(result.data.data); setDatatable(result.data.data);
setTotalPage(result.data.totalRecord); setTotalPage(result.data.totalRecord);
} else { } else {
@ -155,12 +154,10 @@ const ResourceWorker = ({ params }) => {
.catch((error) => error.response); .catch((error) => error.response);
if (result && result.data && result.data.code == 200) { if (result && result.data && result.data.code == 200) {
// console.log(result.data.data)
const group = _.chain(result.data.data) const group = _.chain(result.data.data)
.groupBy("join_first_nama") .groupBy("join_first_nama")
.map((value, key) => ({ header: key, data: value })) .map((value, key) => ({ header: key, data: value }))
.value() .value()
console.log("req tools", group)
setDataReqTools(group); setDataReqTools(group);
} else { } else {
NotificationManager.error('Gagal Mengambil Data!!', 'Failed'); NotificationManager.error('Gagal Mengambil Data!!', 'Failed');
@ -206,7 +203,6 @@ const ResourceWorker = ({ params }) => {
.groupBy("join_first_nama") .groupBy("join_first_nama")
.map((value, key) => ({ header: key, data: value })) .map((value, key) => ({ header: key, data: value }))
.value() .value()
console.log("delivery tools", group)
setDataDeliveryTools(group); setDataDeliveryTools(group);
} else { } else {
NotificationManager.error('Gagal Mengambil Data!!', 'Failed'); NotificationManager.error('Gagal Mengambil Data!!', 'Failed');
@ -228,9 +224,6 @@ const ResourceWorker = ({ params }) => {
const payload = { const payload = {
"paging": { "start": 0, "length": -1 }, "paging": { "start": 0, "length": -1 },
// "columns": [
// { "name": "nama", "logic_operator": "like", "value": search, "operator": "AND" }
// ],
"joins": [], "joins": [],
"orders": { "columns": ["id"], "ascending": false } "orders": { "columns": ["id"], "ascending": false }
} }
@ -245,18 +238,10 @@ const ResourceWorker = ({ params }) => {
.then(res => res) .then(res => res)
.catch((error) => error.response); .catch((error) => error.response);
// console.log(result)
if (result && result.data && result.data.code == 200) { if (result && result.data && result.data.code == 200) {
let resData = result.data.data; let resData = result.data.data;
const excelData = []; const excelData = [];
// <td>{n.nama}</td>
// <td>{n.biaya}</td>
// <td style={{textAlign:"center"}}><div style={{borderRadius:"50%",height:"25px",width:"25px",backgroundColor:n.color_progress}}></div></td>
// <td>{n.jumlah_pekerja}</td>
// <td>{n.pic}</td>
// <td>{n.mulai_proyek ? moment(n.mulai_proyek).format("DD-MM-YYYY") : "-"}</td>
// <td>{n.akhir_proyek ? moment(n.akhir_proyek).format("DD-MM-YYYY") : "-"}</td>
resData.map((n, index) => { resData.map((n, index) => {
let dataRow = { let dataRow = {
"Nama Proyek": n.nama, "Nama Proyek": n.nama,
@ -268,9 +253,7 @@ const ResourceWorker = ({ params }) => {
} }
excelData.push(dataRow) excelData.push(dataRow)
}) })
// console.log("cek excel data", excelData)
await setDataExport(excelData); await setDataExport(excelData);
// exportExcel();
} else { } else {
NotificationManager.error('Gagal Export Data!!', 'Failed'); NotificationManager.error('Gagal Export Data!!', 'Failed');
} }
@ -363,10 +346,7 @@ const ResourceWorker = ({ params }) => {
key: 'x', key: 'x',
className: 'nowrap', className: 'nowrap',
render: (text, record) => <> render: (text, record) => <>
{/* <Tooltip title="Tambah Sub"> <Tooltip titl="Edit">
<Button size="small" type="link" style={{color:'green'}} onClick={() => handleOpenDialogSub('Save', text)}><i className="fa fa-plus"></i></Button>
</Tooltip> */}
<Tooltip title="Edit">
<Button size="small" type="link" style={{ color: 'orange' }} onClick={() => handleEdit(text)}><i className="fa fa-edit"></i></Button> <Button size="small" type="link" style={{ color: 'orange' }} onClick={() => handleEdit(text)}><i className="fa fa-edit"></i></Button>
</Tooltip> </Tooltip>
<Tooltip title="Hapus"> <Tooltip title="Hapus">
@ -380,7 +360,6 @@ const ResourceWorker = ({ params }) => {
{ title: 'QTY', dataIndex: 'qty', key: 'qty' }, { title: 'QTY', dataIndex: 'qty', key: 'qty' },
{ title: 'Description', dataIndex: 'description', key: 'description' }, { title: 'Description', dataIndex: 'description', key: 'description' },
]; ];
// console.log("columns", columns)
return ( return (
<Table <Table
rowKey="id" rowKey="id"
@ -461,7 +440,6 @@ const ResourceWorker = ({ params }) => {
{ title: 'Asset Type', dataIndex: 'asset_type', key: 'asset_type' }, { title: 'Asset Type', dataIndex: 'asset_type', key: 'asset_type' },
{ title: 'UOM', dataIndex: 'uom', key: 'uom' }, { title: 'UOM', dataIndex: 'uom', key: 'uom' },
{ title: 'QTY', dataIndex: 'qty', key: 'qty' }, { title: 'QTY', dataIndex: 'qty', key: 'qty' },
// { title: 'Description', dataIndex: 'description', key: 'description' },
]; ];
if (type === 'request') { if (type === 'request') {
@ -470,8 +448,6 @@ const ResourceWorker = ({ params }) => {
columns.push({ title: 'Ownership Status', dataIndex: 'ownership_status', key: 'ownership_status' }); columns.push({ title: 'Ownership Status', dataIndex: 'ownership_status', key: 'ownership_status' });
columns.push({ title: 'Ownership Name', dataIndex: 'ownership_name', key: 'ownership_name' }); columns.push({ title: 'Ownership Name', dataIndex: 'ownership_name', key: 'ownership_name' });
// console.log("columns", columns)
return ( return (
<Table <Table
rowKey="id" rowKey="id"
@ -490,9 +466,6 @@ const ResourceWorker = ({ params }) => {
<Input onChange={handleSearch} value={search} type="text" name="search" id="search" placeholder={`Search...`} /> <Input onChange={handleSearch} value={search} type="text" name="search" id="search" placeholder={`Search...`} />
</Col> </Col>
<Col> <Col>
{/* <Tooltip title="Add Resource">
<Button style={{ background: "#4caf50", color: "#fff" }} onClick={() => handleOpenDialog('Save')}><i className="fa fa-plus"></i></Button>
</Tooltip> */}
<Tooltip title="Export Excel"> <Tooltip title="Export Excel">
<Button style={{ marginLeft: "5px" }} onClick={() => handleExportExcel()}><i className="fa fa-print"></i></Button> <Button style={{ marginLeft: "5px" }} onClick={() => handleExportExcel()}><i className="fa fa-print"></i></Button>
</Tooltip> </Tooltip>
@ -524,9 +497,6 @@ const ResourceWorker = ({ params }) => {
<Input onChange={handleSearch} value={search} type="text" name="search" id="search" placeholder={`Search...`} /> <Input onChange={handleSearch} value={search} type="text" name="search" id="search" placeholder={`Search...`} />
</Col> </Col>
<Col> <Col>
{/* <Tooltip title="Add Resource">
<Button style={{ background: "#4caf50", color: "#fff" }} onClick={() => handleOpenDialog('Save')}><i className="fa fa-plus"></i></Button>
</Tooltip> */}
<Tooltip title="Export Excel"> <Tooltip title="Export Excel">
<Button style={{ marginLeft: "5px" }} onClick={() => handleExportExcel()}><i className="fa fa-print"></i></Button> <Button style={{ marginLeft: "5px" }} onClick={() => handleExportExcel()}><i className="fa fa-print"></i></Button>
</Tooltip> </Tooltip>
@ -604,4 +574,4 @@ const ResourceWorker = ({ params }) => {
) )
} }
export default ResourceWorker; export default ResourceWorker;

117
src/views/SimproV2/ResourceWorker/index.js

@ -1,17 +1,17 @@
import React, { useState, useEffect, useMemo } from 'react';
import { Card, CardBody, CardHeader, Col, Row, Input } from 'reactstrap';
import { DownloadOutlined } from '@ant-design/icons';
import axios from "../../../const/interceptorApi"
import * as XLSX from 'xlsx'; import * as XLSX from 'xlsx';
import SweetAlert from 'react-bootstrap-sweetalert';
import DialogForm from './DialogForm'; import DialogForm from './DialogForm';
import DialogFormUserShift from './DialogFormUserShift'; import DialogFormUserShift from './DialogFormUserShift';
import React, { useState, useEffect, useMemo } from 'react';
import SweetAlert from 'react-bootstrap-sweetalert';
import axios from "../../../const/interceptorApi"
import moment from 'moment'
import { Card, CardBody, CardHeader, Col, Row, Input } from 'reactstrap';
import { DownloadOutlined } from '@ant-design/icons';
import { NotificationContainer, NotificationManager } from 'react-notifications'; import { NotificationContainer, NotificationManager } from 'react-notifications';
import { Pagination, Table, Button, Tooltip } from 'antd'; import { Pagination, Table, Button, Tooltip } from 'antd';
import { import {
PROYEK_SEARCH, USER_ADD, USER_SEARCH, USER_EDIT, USER_DELETE, ROLE_SEARCH, DIVISI_SEARCH, USER_SHIFT_ADD PROYEK_SEARCH, USER_ADD, USER_SEARCH, USER_EDIT, USER_DELETE, ROLE_SEARCH, DIVISI_SEARCH, USER_SHIFT_ADD
} from '../../../const/ApiConst'; } from '../../../const/ApiConst';
import moment from 'moment'
const url = ""; const url = "";
const proyek_id = localStorage.getItem('proyek_id'); const proyek_id = localStorage.getItem('proyek_id');
@ -34,24 +34,24 @@ const ResourceWorker = ({ params }) => {
"Authorization": `Bearer ${token}` "Authorization": `Bearer ${token}`
} }
} }
const pageName = params.name; const [alertDelete, setAlertDelete] = useState(false)
const [search, setSearch] = useState('') const [clickOpenModal, setClickOpenModal] = useState(false)
const [clickOpenModalShift, setClickOpenModalShift] = useState(false)
const [currentPage, setCurrentPage] = useState(1) const [currentPage, setCurrentPage] = useState(1)
const [dataEdit, setDataEdit] = useState([])
const [dataExport, setDataExport] = useState([])
const [dataTable, setDatatable] = useState([])
const [divisiList, setDivisiList] = useState([])
const [idDelete, setIdDelete] = useState(0)
const [openDialog, setOpenDialog] = useState(false) const [openDialog, setOpenDialog] = useState(false)
const [openDialogShift, setOpenDialogShift] = useState(false) const [openDialogShift, setOpenDialogShift] = useState(false)
const [typeDialog, setTypeDialog] = useState('Save') const [roleList, setRoleList] = useState([])
const [typeDialogShift, setTypeDialogShift] = useState('Save')
const [dataExport, setDataExport] = useState([])
const [rowsPerPage, setRowsPerPage] = useState(10) const [rowsPerPage, setRowsPerPage] = useState(10)
const [dataEdit, setDataEdit] = useState([]) const [search, setSearch] = useState('')
const [alertDelete, setAlertDelete] = useState(false)
const [idDelete, setIdDelete] = useState(0)
const [dataTable, setDatatable] = useState([])
const [clickOpenModal, setClickOpenModal] = useState(false)
const [clickOpenModalShift, setClickOpenModalShift] = useState(false)
const [totalPage, setTotalPage] = useState(0) const [totalPage, setTotalPage] = useState(0)
const [roleList, setRoleList] = useState([]) const [typeDialog, setTypeDialog] = useState('Save')
const [divisiList, setDivisiList] = useState([]) const [typeDialogShift, setTypeDialogShift] = useState('Save')
const pageName = params.name;
useEffect(() => { useEffect(() => {
getRoleList() getRoleList()
@ -60,7 +60,6 @@ const ResourceWorker = ({ params }) => {
useEffect(() => { useEffect(() => {
getDataUser() getDataUser()
console.log("cek token", token)
}, [search, rowsPerPage, currentPage]) }, [search, rowsPerPage, currentPage])
const onShowSizeChange = (current, pageSize) => { const onShowSizeChange = (current, pageSize) => {
@ -81,7 +80,6 @@ const ResourceWorker = ({ params }) => {
.post(ROLE_SEARCH, formData, config) .post(ROLE_SEARCH, formData, config)
.then(res => res) .then(res => res)
.catch((error) => error.response); .catch((error) => error.response);
// console.log(result)
if (result && result.data && result.data.code == 200) { if (result && result.data && result.data.code == 200) {
setRoleList(result.data.data); setRoleList(result.data.data);
@ -100,7 +98,6 @@ const ResourceWorker = ({ params }) => {
.post(DIVISI_SEARCH, formData, config) .post(DIVISI_SEARCH, formData, config)
.then(res => res) .then(res => res)
.catch((error) => error.response); .catch((error) => error.response);
// console.log(result)
if (result && result.data && result.data.code == 200) { if (result && result.data && result.data.code == 200) {
setDivisiList(result.data.data); setDivisiList(result.data.data);
@ -117,44 +114,6 @@ const ResourceWorker = ({ params }) => {
start = (currentPage * rowsPerPage) - rowsPerPage start = (currentPage * rowsPerPage) - rowsPerPage
} }
// const payload = {
// "paging": {
// "start": start,
// "length": rowsPerPage
// },
// "columns": [
// {
// "name": "name",
// "logic_operator": "like",
// "value": search,
// "operator": "AND"
// }
// ],
// "joins": [
// {
// "name": "m_roles",
// "column_join": "role_id",
// "column_results": [
// "name",
// "description"
// ]
// },
// {
// "name": "m_divisi",
// "column_join": "divisi_id",
// "column_results": [
// "name",
// ]
// }
// ],
// "orders": {
// "columns": [
// "id"
// ],
// "ascending": false
// }
// }
const payload = { const payload = {
"paging": { "paging": {
"start": start, "start": start,
@ -240,7 +199,6 @@ const ResourceWorker = ({ params }) => {
.catch((error) => error.response); .catch((error) => error.response);
if (result && result.data && result.data.code == 200) { if (result && result.data && result.data.code == 200) {
console.log("cek resource", result.data.data)
setDatatable(result.data.data); setDatatable(result.data.data);
setTotalPage(result.data.totalRecord); setTotalPage(result.data.totalRecord);
} else { } else {
@ -288,18 +246,9 @@ const ResourceWorker = ({ params }) => {
.then(res => res) .then(res => res)
.catch((error) => error.response); .catch((error) => error.response);
// console.log(result)
if (result && result.data && result.data.code == 200) { if (result && result.data && result.data.code == 200) {
let resData = result.data.data; let resData = result.data.data;
const excelData = []; const excelData = [];
// <td>{n.nama}</td>
// <td>{n.biaya}</td>
// <td style={{textAlign:"center"}}><div style={{borderRadius:"50%",height:"25px",width:"25px",backgroundColor:n.color_progress}}></div></td>
// <td>{n.jumlah_pekerja}</td>
// <td>{n.pic}</td>
// <td>{n.mulai_proyek ? moment(n.mulai_proyek).format("DD-MM-YYYY") : "-"}</td>
// <td>{n.akhir_proyek ? moment(n.akhir_proyek).format("DD-MM-YYYY") : "-"}</td>
resData.map((n, index) => { resData.map((n, index) => {
let dataRow = { let dataRow = {
"Nama Proyek": n.nama, "Nama Proyek": n.nama,
@ -311,9 +260,7 @@ const ResourceWorker = ({ params }) => {
} }
excelData.push(dataRow) excelData.push(dataRow)
}) })
// console.log("cek excel data", excelData)
await setDataExport(excelData); await setDataExport(excelData);
// exportExcel();
} else { } else {
NotificationManager.error('Gagal Export Data!!', 'Failed'); NotificationManager.error('Gagal Export Data!!', 'Failed');
} }
@ -350,13 +297,9 @@ const ResourceWorker = ({ params }) => {
} }
const handleCloseDialogShift = (type, data) => { const handleCloseDialogShift = (type, data) => {
console.log(data)
if (type === "save") { if (type === "save") {
saveUserShift(data); saveUserShift(data);
} }
// else if (type === "edit") {
// editUser(data);
// }
setDataEdit([]) setDataEdit([])
setOpenDialogShift(false) setOpenDialogShift(false)
} }
@ -393,7 +336,6 @@ const ResourceWorker = ({ params }) => {
let urlEdit = USER_EDIT(data.id) let urlEdit = USER_EDIT(data.id)
const formData = data const formData = data
console.log("cek form data", formData)
const result = await axios.put(urlEdit, formData, HEADER) const result = await axios.put(urlEdit, formData, HEADER)
.then(res => res) .then(res => res)
@ -446,9 +388,6 @@ const ResourceWorker = ({ params }) => {
dataIndex: '', dataIndex: '',
key: 'x', key: 'x',
render: (text, record) => <> render: (text, record) => <>
{/* <Tooltip title="Tambah Sub">
<Button size="small" type="link" style={{color:'green'}} onClick={() => handleOpenDialogSub('Save', text)}><i className="fa fa-plus"></i></Button>
</Tooltip> */}
<Tooltip title="Edit"> <Tooltip title="Edit">
<Button size="small" type="link" style={{ color: 'orange' }} onClick={() => handleEdit(text)}><i className="fa fa-edit"></i></Button> <Button size="small" type="link" style={{ color: 'orange' }} onClick={() => handleEdit(text)}><i className="fa fa-edit"></i></Button>
</Tooltip> </Tooltip>
@ -459,9 +398,6 @@ const ResourceWorker = ({ params }) => {
<Tooltip title="Set User"> <Tooltip title="Set User">
<Button size="small" type="link" style={{ color: 'lightblue' }} onClick={() => handleSetWorker(text)}><i className="fa fa-key"></i></Button> <Button size="small" type="link" style={{ color: 'lightblue' }} onClick={() => handleSetWorker(text)}><i className="fa fa-key"></i></Button>
</Tooltip> </Tooltip>
{/* <Tooltip title="Set Shift">
<Button size="small" type="link" style={{ color: '#0080ff' }} onClick={() => handleSetUserShift(text)}><i className="cil-alarm"></i></Button>
</Tooltip> */}
</>, </>,
}, },
@ -478,20 +414,7 @@ const ResourceWorker = ({ params }) => {
{ title: 'Phone No.', dataIndex: 'phone_number', key: 'phone_number' }, { title: 'Phone No.', dataIndex: 'phone_number', key: 'phone_number' },
{ title: 'Email', dataIndex: 'email', key: 'email' }, { title: 'Email', dataIndex: 'email', key: 'email' },
{ title: 'Status', dataIndex: 'status_resource', key: 'status_status' } { title: 'Status', dataIndex: 'status_resource', key: 'status_status' }
// {
// title: 'Aktifitas Mulai',
// dataIndex: 'mulai_proyek',
// key: 'mulai_proyek',
// render: (text, record) => <>{moment(text).format(format)}</>,
// },
// {
// title: 'Aktifitas Selesai',
// dataIndex: 'akhir_proyek',
// key: 'akhir_proyek',
// render: (text, record) => <>{moment(text).format(format)}</>,
// },
]; ];
// console.log("columns", columns)
return ( return (
<Table <Table
rowKey="id" rowKey="id"
@ -572,4 +495,4 @@ const ResourceWorker = ({ params }) => {
) )
} }
export default ResourceWorker; export default ResourceWorker;

669
src/views/SimproV2/Satuan/index.js

@ -1,361 +1,338 @@
import React, { useState, useEffect, useMemo } from 'react';
import { Card, CardBody, CardHeader, Col, Row, Input, Table } from 'reactstrap';
import axios from "../../../const/interceptorApi"
import * as XLSX from 'xlsx'; import * as XLSX from 'xlsx';
import SweetAlert from 'react-bootstrap-sweetalert';
import DialogForm from './DialogForm'; import DialogForm from './DialogForm';
import React, { useState, useEffect, useMemo } from 'react';
import SweetAlert from 'react-bootstrap-sweetalert';
import axios from "../../../const/interceptorApi"
import { Card, CardBody, CardHeader, Col, Row, Input, Table } from 'reactstrap';
import { NotificationContainer, NotificationManager } from 'react-notifications'; import { NotificationContainer, NotificationManager } from 'react-notifications';
import { Pagination, Button, Tooltip } from 'antd'; import { Pagination, Button, Tooltip } from 'antd';
import { import { SATUAN_ADD, SATUAN_EDIT, SATUAN_DELETE,SATUAN_SEARCH} from '../../../const/ApiConst';
SATUAN_ADD, SATUAN_EDIT, SATUAN_DELETE,SATUAN_SEARCH
} from '../../../const/ApiConst';
const token = window.localStorage.getItem('token'); const token = window.localStorage.getItem('token');
const config = { const config = {
headers: headers:
{ {
Authorization: `Bearer ${token}`, Authorization: `Bearer ${token}`,
"Content-type": `application/json` "Content-type": `application/json`
} }
}; };
const column = [ const column = [
{ name: "Nama" }, { name: "Nama" },
{ name: "Deskripsi" }, { name: "Deskripsi" },
] ]
const Satuan = ({ params }) => { const Satuan = ({ params }) => {
const token = localStorage.getItem("token") const token = localStorage.getItem("token")
const HEADER = { const HEADER = {
headers: { headers: {
"Content-Type": "application/json", "Content-Type": "application/json",
"Authorization": `Bearer ${token}` "Authorization": `Bearer ${token}`
} }
} }
const pageName = params.name; const pageName = params.name;
const [search, setSearch] = useState('')
const [currentPage, setCurrentPage] = useState(1) const [alertDelete, setAlertDelete] = useState(false)
const [openDialog, setOpenDialog] = useState(false) const [allDataMenu, setAllDataMenu] = useState([])
const [typeDialog, setTypeDialog] = useState('Save') const [clickOpenModal, setClickOpenModal] = useState(false)
const [dataExport, setDataExport] = useState([]) const [currentPage, setCurrentPage] = useState(1)
const [rowsPerPage, setRowsPerPage] = useState(10) const [dataEdit, setDataEdit] = useState([])
const [dataEdit, setDataEdit] = useState([]) const [dataExport, setDataExport] = useState([])
const [alertDelete, setAlertDelete] = useState(false) const [dataTable, setDatatable] = useState([])
const [idDelete, setIdDelete] = useState(0) const [idDelete, setIdDelete] = useState(0)
const [dataTable, setDatatable] = useState([]) const [openDialog, setOpenDialog] = useState(false)
const [clickOpenModal, setClickOpenModal] = useState(false) const [rowsPerPage, setRowsPerPage] = useState(10)
const [allDataMenu, setAllDataMenu] = useState([]) const [search, setSearch] = useState('')
const [totalPage, setTotalPage] = useState(0) const [totalPage, setTotalPage] = useState(0)
const [typeDialog, setTypeDialog] = useState('Save')
useEffect(() => {
getDataSatuan() useEffect(() => {
}, [currentPage, rowsPerPage, search]) getDataSatuan()
}, [currentPage, rowsPerPage, search])
useEffect(() => {
const cekData = dataExport || [] useEffect(() => {
if (cekData.length > 0) { const cekData = dataExport || []
exportExcel() if (cekData.length > 0) {
} exportExcel()
}, [dataExport]) }
}, [dataExport])
const getDataSatuan = async () => {
const getDataSatuan = async () => {
let start = 0;
let start = 0;
if (currentPage !== 1 && currentPage > 1) {
start = (currentPage * rowsPerPage) - rowsPerPage if (currentPage !== 1 && currentPage > 1) {
} start = (currentPage * rowsPerPage) - rowsPerPage
}
const payload = {
"columns": [ const payload = {
{ "columns": [
"name": "name", {
"logic_operator": "like", "name": "name",
"value": search, "logic_operator": "like",
"operator": "AND" "value": search,
} "operator": "AND"
], }
"orders": { ],
"ascending": true, "orders": {
"columns": [ "ascending": true,
'id' "columns": [
] 'id'
}, ]
"paging": { },
"length": rowsPerPage, "paging": {
"start": start "length": rowsPerPage,
} "start": start
} }
}
// console.log("payload ", payload)
const result = await axios const result = await axios
.post(SATUAN_SEARCH, payload, config) .post(SATUAN_SEARCH, payload, config)
.then(res => res) .then(res => res)
.catch((error) => error.response); .catch((error) => error.response);
if (result && result.data && result.data.code == 200) {
setDatatable(result.data.data);
setTotalPage(result.data.totalRecord);
if (result && result.data && result.data.code == 200) { } else {
console.log("get data ", result.data) NotificationManager.error('Gagal Mengambil Data!!', 'Failed');
setDatatable(result.data.data); }
setTotalPage(result.data.totalRecord); }
} else {
NotificationManager.error('Gagal Mengambil Data!!', 'Failed'); const handleSearch = e => {
} const value = e.target.value
} setSearch(value);
setCurrentPage(1)
const handleSearch = e => { };
const value = e.target.value
setSearch(value); const handleOpenDialog = (type) => {
setCurrentPage(1) setOpenDialog(true)
}; setTypeDialog(type)
}
const handleOpenDialog = (type) => {
setOpenDialog(true) const handleExportExcel = async () => {
setTypeDialog(type) const payload = {
} "paging": { "start": 0, "length": -1 },
"columns": [
const handleExportExcel = async () => { { "name": "name", "logic_operator": "like", "value": search, "operator": "AND" }
console.log("cek cek cek cke") ],
const payload = { "joins": [],
"paging": { "start": 0, "length": -1 }, "orders": { "columns": ["id"], "ascending": false }
"columns": [ }
{ "name": "name", "logic_operator": "like", "value": search, "operator": "AND" } const result = await axios
], .post(SATUAN_SEARCH, payload, config)
"joins": [], .then(res => res)
"orders": { "columns": ["id"], "ascending": false } .catch((error) => error.response);
} if (result && result.data && result.data.code == 200) {
let resData = result.data.data;
const excelData = [];
resData.map((val, index) => {
const result = await axios let dataRow = {
.post(SATUAN_SEARCH, payload, config) "Nama": val.name,
.then(res => res) "Deskripsi": val.description,
.catch((error) => error.response); }
excelData.push(dataRow)
// console.log(result) })
await setDataExport(excelData);
if (result && result.data && result.data.code == 200) { } else {
let resData = result.data.data; NotificationManager.error('Gagal Export Data!!', 'Failed');
const excelData = []; }
resData.map((val, index) => { }
let dataRow = {
"Nama": val.name, const exportExcel = () => {
"Deskripsi": val.description, const dataExcel = dataExport || [];
} const fileName = `Data ${pageName}.xlsx`;
excelData.push(dataRow) const ws = XLSX.utils.json_to_sheet(dataExcel);
}) const wb = XLSX.utils.book_new();
// console.log("cek excel data", resData) XLSX.utils.book_append_sheet(wb, ws, `Data ${pageName}`);
await setDataExport(excelData); XLSX.writeFile(wb, fileName);
// exportExcel(); setDataExport([])
} else { }
NotificationManager.error('Gagal Export Data!!', 'Failed');
} const handleEdit = (data) => {
} setDataEdit(data)
handleOpenDialog('Edit');
const exportExcel = () => { }
const dataExcel = dataExport || [];
console.log("cek data excel", dataExcel) const handleDelete = async (id) => {
const fileName = `Data ${pageName}.xlsx`; await setAlertDelete(true)
const ws = XLSX.utils.json_to_sheet(dataExcel); await setIdDelete(id)
const wb = XLSX.utils.book_new(); }
XLSX.utils.book_append_sheet(wb, ws, `Data ${pageName}`);
XLSX.writeFile(wb, fileName); const handleCloseDialog = (type, data) => {
setDataExport([]) if (type === "save") {
} saveSatuan(data);
} else if (type === "edit") {
const handleEdit = (data) => { editMaterialR(data);
setDataEdit(data) }
handleOpenDialog('Edit'); setDataEdit([])
} setOpenDialog(false)
}
const handleDelete = async (id) => {
await setAlertDelete(true) const saveSatuan = async (data) => {
await setIdDelete(id) const formData = data
} const result = await axios.post(SATUAN_ADD, formData, HEADER)
.then(res => res)
const handleCloseDialog = (type, data) => { .catch((error) => error.response);
if (type === "save") {
saveSatuan(data); if (result && result.data && result.data.code === 200) {
} else if (type === "edit") { getDataSatuan()
editMaterialR(data); NotificationManager.success(`Data project type berhasil ditambah`, 'Success!!');
} } else {
setDataEdit([]) NotificationManager.error(`${result.data.message}`, 'Failed!!');
setOpenDialog(false) }
} }
const saveSatuan = async (data) => { const editMaterialR = async (data) => {
const formData = data let urlEdit = SATUAN_EDIT(data.id)
const result = await axios.post(SATUAN_ADD, formData, HEADER) const formData = data
.then(res => res)
.catch((error) => error.response); const result = await axios.put(urlEdit, formData, HEADER)
.then(res => res)
if (result && result.data && result.data.code === 200) { .catch((error) => error.response);
getDataSatuan()
// console.log("data material s ", formData) if (result && result.data && result.data.code === 200) {
NotificationManager.success(`Data project type berhasil ditambah`, 'Success!!'); getDataSatuan();
} else { NotificationManager.success(`Data project type berhasil diedit`, 'Success!!');
// console.log("data material fail ", formData) } else {
NotificationManager.error(`${result.data.message}`, 'Failed!!'); NotificationManager.error(`Data project type gagal di edit`, `Failed!!`);
} }
} }
const editMaterialR = async (data) => { const toggleAddDialog = () => {
setOpenDialog(!openDialog)
let urlEdit = SATUAN_EDIT(data.id) }
const formData = data
const onConfirmDelete = async () => {
console.log("from data edit ", formData) let url = SATUAN_DELETE(idDelete);
const result = await axios.put(urlEdit, formData, HEADER) const result = await axios.delete(url, config)
.then(res => res) .then(res => res)
.catch((error) => error.response); .catch((error) => error.response);
if (result && result.data && result.data.code === 200) { if (result && result.data && result.data.code === 200) {
getDataSatuan(); getDataSatuan()
NotificationManager.success(`Data project type berhasil diedit`, 'Success!!'); setIdDelete(0)
} else { setAlertDelete(false)
NotificationManager.error(`Data project type gagal di edit`, `Failed!!`); NotificationManager.success(`Data project type berhasil dihapus!`, 'Success!!');
} } else {
} setIdDelete(0)
setAlertDelete(false)
const toggleAddDialog = () => { NotificationManager.error(`Data project type gagal dihapus!}`, 'Failed!!');
setOpenDialog(!openDialog) }
} }
const onConfirmDelete = async () => { const cancelDelete = () => {
let url = SATUAN_DELETE(idDelete); setAlertDelete(false)
setIdDelete(0)
const result = await axios.delete(url, config) }
.then(res => res)
.catch((error) => error.response); const onShowSizeChange = (current, pageSize) => {
setRowsPerPage(pageSize)
if (result && result.data && result.data.code === 200) { }
getDataSatuan()
setIdDelete(0) const onPagination = (current, pageSize) => {
setAlertDelete(false) setCurrentPage(current)
NotificationManager.success(`Data project type berhasil dihapus!`, 'Success!!'); }
} else {
setIdDelete(0) const dataNotAvailable = () => {
setAlertDelete(false) if (dataTable.length === 0) {
NotificationManager.error(`Data project type gagal dihapus!}`, 'Failed!!'); return (
} <tr>
} <td align="center" colSpan="3">Tidak ada data project type</td>
</tr>
const cancelDelete = () => { )
setAlertDelete(false) }
setIdDelete(0) }
}
return (
const onShowSizeChange = (current, pageSize) => { <div>
setRowsPerPage(pageSize) <NotificationContainer />
} <SweetAlert
show={alertDelete}
const onPagination = (current, pageSize) => { warning
setCurrentPage(current) showCancel
} confirmBtnText="Delete"
confirmBtnBsStyle="danger"
const dataNotAvailable = () => { title={`Are you sure?`}
if (dataTable.length === 0) { onConfirm={onConfirmDelete}
return ( onCancel={() => cancelDelete()}
<tr> focusCancelBtn
<td align="center" colSpan="3">Tidak ada data project type</td> >
</tr> Delete this data
) </SweetAlert>
} <DialogForm
} openDialog={openDialog}
closeDialog={handleCloseDialog}
toggleDialog={() => toggleAddDialog}
typeDialog={typeDialog}
return ( dataEdit={dataEdit}
<div> clickOpenModal={clickOpenModal}
<NotificationContainer /> dataParent={allDataMenu}
<SweetAlert />
show={alertDelete} <Card>
warning <CardHeader style={{ display: "flex", justifyContent: "space-between" }}>
showCancel <h4 className="capitalize">{pageName}</h4>
confirmBtnText="Delete" <Row>
confirmBtnBsStyle="danger" <Col>
title={`Are you sure?`} <Input onChange={handleSearch} value={search} type="text" name="search" id="search" placeholder={`Search divisi...`} />
onConfirm={onConfirmDelete} </Col>
onCancel={() => cancelDelete()} <Col>
focusCancelBtn <Tooltip title="Add UOM">
> <Button style={{ background: "#4caf50", color: "#fff" }} onClick={() => handleOpenDialog('Save')}><i className="fa fa-plus"></i></Button>
Delete this data </Tooltip>
</SweetAlert> <Tooltip title="Export Excel">
<DialogForm <Button style={{marginLeft:"5px"}} color="primary" onClick={()=> handleExportExcel()}><i className="fa fa-print"></i></Button>
openDialog={openDialog} </Tooltip>
closeDialog={handleCloseDialog} </Col>
toggleDialog={() => toggleAddDialog} </Row>
typeDialog={typeDialog} </CardHeader>
dataEdit={dataEdit} <CardBody>
clickOpenModal={clickOpenModal} <Table responsive striped hover>
dataParent={allDataMenu} <thead>
/> <tr>
<Card> <th>Aksi</th>
<CardHeader style={{ display: "flex", justifyContent: "space-between" }}> {column.map((i, index) => {
<h4 className="capitalize">{pageName}</h4> return (
<Row> <th key={index} scope="row">{i.name}</th>
<Col> )
<Input onChange={handleSearch} value={search} type="text" name="search" id="search" placeholder={`Search divisi...`} /> })}
</Col> </tr>
<Col> </thead>
<Tooltip title="Add UOM"> <tbody>
<Button style={{ background: "#4caf50", color: "#fff" }} onClick={() => handleOpenDialog('Save')}><i className="fa fa-plus"></i></Button> {dataNotAvailable()}
</Tooltip> {dataTable.map((n, index) => {
<Tooltip title="Export Excel"> return (
<Button style={{marginLeft:"5px"}} color="primary" onClick={()=> handleExportExcel()}><i className="fa fa-print"></i></Button> <tr key={n.id}>
</Tooltip> <td className='nowrap'>
</Col>
</Row> <Tooltip title="Hapus">
</CardHeader> <i id="TooltipDelete" className="cil-trash fa-lg" style={{ color: 'red', marginRight: 10, cursor: "pointer" }} onClick={() => handleDelete(n.id)}></i>
<CardBody> </Tooltip>
<Table responsive striped hover>
<thead> <Tooltip title="Edit">
<tr> <i id="TooltipEdit" className="cil-pencil fa-lg" style={{ color: 'green', cursor: "pointer" }} onClick={() => handleEdit(n)}></i>
<th>Aksi</th> </Tooltip>
{column.map((i, index) => { </td>
return ( <td>{n.name}</td>
<th key={index} scope="row">{i.name}</th> <td>{n.description}</td>
) </tr>
})} )
</tr> })}
</thead> </tbody>
<tbody> </Table>
{dataNotAvailable()} <Pagination
{dataTable.map((n, index) => { showSizeChanger
return ( onShowSizeChange={onShowSizeChange}
<tr key={n.id}> onChange={onPagination}
<td className='nowrap'> defaultCurrent={currentPage}
pageSize={rowsPerPage}
<Tooltip title="Hapus"> total={totalPage}
<i id="TooltipDelete" className="cil-trash fa-lg" style={{ color: 'red', marginRight: 10, cursor: "pointer" }} onClick={() => handleDelete(n.id)}></i> pageSizeOptions={["10", "15", "20", "25", "30", "35", "40"]}
</Tooltip> />
</CardBody>
<Tooltip title="Edit"> </Card>
<i id="TooltipEdit" className="cil-pencil fa-lg" style={{ color: 'green', cursor: "pointer" }} onClick={() => handleEdit(n)}></i> </div>
</Tooltip> )
</td>
<td>{n.name}</td>
<td>{n.description}</td>
</tr>
)
})}
</tbody>
</Table>
<Pagination
showSizeChanger
onShowSizeChange={onShowSizeChange}
onChange={onPagination}
defaultCurrent={currentPage}
pageSize={rowsPerPage}
total={totalPage}
pageSizeOptions={["10", "15", "20", "25", "30", "35", "40"]}
/>
</CardBody>
</Card>
</div>
)
} }
export default Satuan; export default Satuan;

Loading…
Cancel
Save