Browse Source

change filter by is_customer

pull/2/head
wahyuun 1 year ago
parent
commit
78e14529e9
  1. 609
      src/views/SimproV2/CreatedProyek/AsignHrProject.js

609
src/views/SimproV2/CreatedProyek/AsignHrProject.js

@ -1,304 +1,305 @@
import React, { useEffect, useState, useMemo } from 'react' import React, { useEffect, useState, useMemo } from 'react'
import { Modal, ModalHeader, ModalBody, ModalFooter } from 'reactstrap'; import { Modal, ModalHeader, ModalBody, ModalFooter } from 'reactstrap';
import { Button, Form } from 'reactstrap'; import { Button, Form } from 'reactstrap';
import { Table, Tooltip } from 'antd'; import { Table, Tooltip } from 'antd';
import 'antd/dist/antd.css'; import 'antd/dist/antd.css';
import moment from 'moment'; import moment from 'moment';
import { API_ADW, TOKEN_ADW, ASSIGN_HR_PROJECT_SEARCH, ASSIGN_HR_PROJECT_DELETE, USER_LIST, PROJECT_ROLE_SEARCH, ASSIGN_HR_PROJECT_ADD, ASSIGN_HR_PROJECT_EDIT } from '../../../const/ApiConst'; import { API_ADW, TOKEN_ADW, ASSIGN_HR_PROJECT_SEARCH, ASSIGN_HR_PROJECT_DELETE, USER_LIST, PROJECT_ROLE_SEARCH, ASSIGN_HR_PROJECT_ADD, ASSIGN_HR_PROJECT_EDIT } from '../../../const/ApiConst';
import axios from "../../../const/interceptorApi" import axios from "../../../const/interceptorApi"
import { NotificationContainer, NotificationManager } from 'react-notifications'; import { NotificationContainer, NotificationManager } from 'react-notifications';
import SweetAlert from 'react-bootstrap-sweetalert'; import SweetAlert from 'react-bootstrap-sweetalert';
import FormAsignHr from './FormAsignHr'; import FormAsignHr from './FormAsignHr';
import { formatThousand } from '../../../const/CustomFunc'; import { formatThousand } from '../../../const/CustomFunc';
const AssignHrProject = ({ openDialog, closeDialog, toggleDialog, idTask, toolsResource, proyekName }) => { const AssignHrProject = ({ openDialog, closeDialog, toggleDialog, idTask, toolsResource, proyekName }) => {
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 [dataUserToProject, setdataUserToProject] = useState([]) const [dataUserToProject, setdataUserToProject] = useState([])
const [alertDelete, setAlertDelete] = useState(false) const [alertDelete, setAlertDelete] = useState(false)
const [idDelete, setIdDelete] = useState(0) const [idDelete, setIdDelete] = useState(0)
const [openDialogFormTools, setOpenDialogFormTools] = useState(false) const [openDialogFormTools, setOpenDialogFormTools] = useState(false)
const [dataEdit, setDataEdit] = useState(null) const [dataEdit, setDataEdit] = useState(null)
const [listUser, setListUser] = useState([]) const [listUser, setListUser] = useState([])
const [listRole, setListRole] = useState([]) const [listRole, setListRole] = useState([])
useEffect(() => { useEffect(() => {
if (idTask > 0) { if (idTask > 0) {
getDataAssignHr(); getDataAssignHr();
} }
}, [openDialog]); }, [openDialog]);
useEffect(() => { useEffect(() => {
if (openDialog) { if (openDialog) {
getDataProjectRole(); getDataProjectRole();
getDataUser(); getDataUser();
} }
}, [dataUserToProject]) }, [dataUserToProject])
const getDataAssignHr = async () => { const getDataAssignHr = async () => {
const payload = { const payload = {
"paging": { "paging": {
"start": 0, "start": 0,
"length": -1 "length": -1
}, },
"columns": [ "columns": [
{ "name": "name", "logic_operator": "ilike", "value": "", "table_name": "m_users" }, { "name": "name", "logic_operator": "ilike", "value": "", "table_name": "m_users" },
{ "name": "proyek_id", "logic_operator": "=", "value": idTask } { "name": "proyek_id", "logic_operator": "=", "value": idTask },
], { "name": "is_customer", "logic_operator": "=", "value": "false" }
"joins": [ ],
{ "name": "m_users", "column_join": "user_id", "column_results": ["name"] }, "joins": [
{ "name": "m_role_proyek", "column_join": "project_role", "column_results": ["name"] }, { "name": "m_users", "column_join": "user_id", "column_results": ["name"] },
], { "name": "m_role_proyek", "column_join": "project_role", "column_results": ["name"] },
"orders": { ],
"columns": [ "orders": {
"id" "columns": [
], "id"
"ascending": false ],
} "ascending": false
} }
const URL = ASSIGN_HR_PROJECT_SEARCH }
const result = await axios const URL = ASSIGN_HR_PROJECT_SEARCH
.post(URL, payload, HEADER) const result = await axios
.then(res => res) .post(URL, payload, HEADER)
.catch((error) => error.response); .then(res => res)
.catch((error) => error.response);
if (result && result.data && result.data.code == 200) {
let dataRes = result.data.data || [] if (result && result.data && result.data.code == 200) {
let dataRes = result.data.data || []
setdataUserToProject(dataRes);
} else { setdataUserToProject(dataRes);
NotificationManager.error('Gagal Mengambil Data!!', 'Failed'); } else {
} NotificationManager.error('Gagal Mengambil Data!!', 'Failed');
} }
}
const getDataUser = async () => {
const HEADER_ADW = { const getDataUser = async () => {
headers: { const HEADER_ADW = {
"Authorization": `${TOKEN_ADW}` headers: {
} "Authorization": `${TOKEN_ADW}`
} }
const result = await axios }
// .get(`${API_ADW}employees`, HEADER_ADW) const result = await axios
.get(USER_LIST, HEADER) // .get(`${API_ADW}employees`, HEADER_ADW)
.then(res => res) .get(USER_LIST, HEADER)
.catch((error) => error.response); .then(res => res)
if (result && result.data && result.data.data.length != 0) { .catch((error) => error.response);
let dataRes = result.data.data if (result && result.data && result.data.data.length != 0) {
setListUser(dataRes) let dataRes = result.data.data
} setListUser(dataRes)
} }
}
const getDataProjectRole = async () => {
const payload = { const getDataProjectRole = async () => {
"paging": { const payload = {
"start": 0, "paging": {
"length": -1 "start": 0,
}, "length": -1
"columns": [ },
{ "name": "created_by", "logic_operator": "ilike", "value": "" }, "columns": [
], { "name": "created_by", "logic_operator": "ilike", "value": "" },
"joins": [], ],
"orders": { "joins": [],
"columns": [ "orders": {
"id" "columns": [
], "id"
"ascending": false ],
} "ascending": false
} }
}
const result = await axios
.post(PROJECT_ROLE_SEARCH, payload, HEADER) const result = await axios
.then(res => res) .post(PROJECT_ROLE_SEARCH, payload, HEADER)
.catch((error) => error.response); .then(res => res)
.catch((error) => error.response);
if (result && result.data && result.data.code == 200) {
let dataRes = result.data.data || [] if (result && result.data && result.data.code == 200) {
setListRole(dataRes); let dataRes = result.data.data || []
} else { setListRole(dataRes);
} } else {
} }
}
const handleDelete = (id) => {
setIdDelete(id) const handleDelete = (id) => {
setAlertDelete(true) setIdDelete(id)
} setAlertDelete(true)
}
const cancelDelete = () => {
setAlertDelete(false) const cancelDelete = () => {
setIdDelete(0) setAlertDelete(false)
} setIdDelete(0)
}
const onConfirmDelete = async () => {
let urlDel = ASSIGN_HR_PROJECT_DELETE(idDelete) const onConfirmDelete = async () => {
const result = await axios.delete(urlDel, HEADER) let urlDel = ASSIGN_HR_PROJECT_DELETE(idDelete)
.then(res => res) const result = await axios.delete(urlDel, HEADER)
.catch((error) => error.response); .then(res => res)
.catch((error) => error.response);
if (result && result.data && result.data.code === 200) {
getDataAssignHr() if (result && result.data && result.data.code === 200) {
setIdDelete(0) getDataAssignHr()
setAlertDelete(false) setIdDelete(0)
NotificationManager.success(`Data assign human resource berhasil dihapus`, 'Success!!'); setAlertDelete(false)
} else { NotificationManager.success(`Data assign human resource berhasil dihapus`, 'Success!!');
setIdDelete(0) } else {
setAlertDelete(false) setIdDelete(0)
NotificationManager.error(`Data assign human resource gagal dihapus`, 'Failed!!'); setAlertDelete(false)
} NotificationManager.error(`Data assign human resource gagal dihapus`, 'Failed!!');
} }
}
const handleEdit = async (data) => {
await setDataEdit(data) const handleEdit = async (data) => {
setOpenDialogFormTools(true) await setDataEdit(data)
} setOpenDialogFormTools(true)
}
const handleOpenDialogFormTools = () => {
setOpenDialogFormTools(true) const handleOpenDialogFormTools = () => {
} setOpenDialogFormTools(true)
}
const handleCancel = () => {
closeDialog('cancel', 'none') const handleCancel = () => {
} closeDialog('cancel', 'none')
}
const RenderTable = useMemo(() => {
const columns = [ const RenderTable = useMemo(() => {
{ const columns = [
title: 'Action', {
dataIndex: '', title: 'Action',
key: 'x', dataIndex: '',
className: "nowrap", key: 'x',
render: (text, record) => <><Tooltip title="Delete Request Resource"> className: "nowrap",
<Button size={"sm"} color='danger' onClick={() => handleDelete(text.id)}><i className="fa fa-trash"></i></Button> render: (text, record) => <><Tooltip title="Delete Request Resource">
</Tooltip>{" "}<Tooltip title="Edit Request Resource"> <Button size={"sm"} color='danger' onClick={() => handleDelete(text.id)}><i className="fa fa-trash"></i></Button>
<Button size={"sm"} color='primary' onClick={() => handleEdit(text)}><i className="fa fa-edit"></i></Button> </Tooltip>{" "}<Tooltip title="Edit Request Resource">
</Tooltip></>, <Button size={"sm"} color='primary' onClick={() => handleEdit(text)}><i className="fa fa-edit"></i></Button>
}, </Tooltip></>,
{ title: 'Name Human Resource', dataIndex: 'join_first_name', key: 'join_first_name', className: "nowrap" }, },
{ title: 'Role Human Resource', dataIndex: 'join_second_name', key: 'join_second_name', className: "nowrap" }, { title: 'Name Human Resource', dataIndex: 'join_first_name', key: 'join_first_name', className: "nowrap" },
{ title: 'Percentage Available User', dataIndex: 'max_used', key: 'max_used', className: "nowrap", render: (text, record) => record.max_used ? formatThousand(record.max_used) : '-' }, { title: 'Role Human Resource', dataIndex: 'join_second_name', key: 'join_second_name', className: "nowrap" },
{ title: 'Standard Rate', dataIndex: 'standart_rate', key: 'standart_rate', className: "nowrap", render: (text, record) => record.standart_rate ? formatThousand(record.standart_rate) : '-' }, { title: 'Percentage Available User', dataIndex: 'max_used', key: 'max_used', className: "nowrap", render: (text, record) => record.max_used ? formatThousand(record.max_used) : '-' },
{ title: 'UOM Standard Rate', dataIndex: 'uom_standart_rate', key: 'uom_standart_rate', className: "nowrap" }, { title: 'Standard Rate', dataIndex: 'standart_rate', key: 'standart_rate', className: "nowrap", render: (text, record) => record.standart_rate ? formatThousand(record.standart_rate) : '-' },
{ title: 'Overtime Rate', dataIndex: 'overtime_rate', key: 'overtime_rate', className: "nowrap", render: (text, record) => record.overtime_rate ? formatThousand(record.overtime_rate) : '-' }, { title: 'UOM Standard Rate', dataIndex: 'uom_standart_rate', key: 'uom_standart_rate', className: "nowrap" },
{ title: 'UOM Overtime Rate', dataIndex: 'uom_overtime_rate', key: 'uom_overtime_rate', className: "nowrap" }, { title: 'Overtime Rate', dataIndex: 'overtime_rate', key: 'overtime_rate', className: "nowrap", render: (text, record) => record.overtime_rate ? formatThousand(record.overtime_rate) : '-' },
{ title: 'UOM Overtime Rate', dataIndex: 'uom_overtime_rate', key: 'uom_overtime_rate', className: "nowrap" },
];
];
return (
<Table return (
size="small" <Table
columns={columns} size="small"
dataSource={dataUserToProject} columns={columns}
pagination={{ position: ["bottomLeft"] }} dataSource={dataUserToProject}
/> pagination={{ position: ["bottomLeft"] }}
) />
}, [dataUserToProject]) )
}, [dataUserToProject])
const renderForm = () => {
return ( const renderForm = () => {
<div style={{"overflowX":"scroll"}}> return (
{RenderTable} <div style={{"overflowX":"scroll"}}>
</div> {RenderTable}
) </div>
} )
}
const handleCloseDialogFormTools = (type, data) => {
if(type=="add"){ const handleCloseDialogFormTools = (type, data) => {
addDataAssignHr(data); if(type=="add"){
}else if(type=="edit"){ addDataAssignHr(data);
editDataAssignHr(data); }else if(type=="edit"){
}else{ editDataAssignHr(data);
setDataEdit(null) }else{
setOpenDialogFormTools(false) setDataEdit(null)
} setOpenDialogFormTools(false)
} }
}
const addDataAssignHr = async (payload) => {
const result = await axios const addDataAssignHr = async (payload) => {
.post(ASSIGN_HR_PROJECT_ADD, payload, HEADER) const result = await axios
.then(res => res) .post(ASSIGN_HR_PROJECT_ADD, payload, HEADER)
.catch((error) => error.response); .then(res => res)
.catch((error) => error.response);
if (result && result.data && result.data.code == 200) {
getDataAssignHr(); if (result && result.data && result.data.code == 200) {
NotificationManager.success('assign human resource berhasil!!', 'Success'); getDataAssignHr();
setDataEdit(null) NotificationManager.success('assign human resource berhasil!!', 'Success');
setOpenDialogFormTools(false) setDataEdit(null)
} else { setOpenDialogFormTools(false)
NotificationManager.error('assign human resource gagal!!', 'Failed'); } else {
} NotificationManager.error('assign human resource gagal!!', 'Failed');
} }
}
const editDataAssignHr = async (payload) => {
let url = ASSIGN_HR_PROJECT_EDIT(payload.id) const editDataAssignHr = async (payload) => {
const result = await axios let url = ASSIGN_HR_PROJECT_EDIT(payload.id)
.put(url, payload, HEADER) const result = await axios
.then(res => res) .put(url, payload, HEADER)
.catch((error) => error.response); .then(res => res)
.catch((error) => error.response);
if (result && result.data && result.data.code == 200) {
getDataAssignHr(); if (result && result.data && result.data.code == 200) {
NotificationManager.success('assign human resource berhasil diedit!!', 'Success'); getDataAssignHr();
setDataEdit(null) NotificationManager.success('assign human resource berhasil diedit!!', 'Success');
setOpenDialogFormTools(false) setDataEdit(null)
} else { setOpenDialogFormTools(false)
NotificationManager.error('assign human resource gagal diedit!!', 'Failed'); } else {
} NotificationManager.error('assign human resource gagal diedit!!', 'Failed');
} }
}
const toogleDialogFormTools = () => {
if (openDialogFormTools) { const toogleDialogFormTools = () => {
setDataEdit(null) if (openDialogFormTools) {
} setDataEdit(null)
setOpenDialogFormTools(!openDialogFormTools) }
} setOpenDialogFormTools(!openDialogFormTools)
}
return (
<> return (
<NotificationContainer /> <>
<SweetAlert <NotificationContainer />
show={alertDelete} <SweetAlert
warning show={alertDelete}
showCancel warning
confirmBtnText="Delete" showCancel
confirmBtnBsStyle="danger" confirmBtnText="Delete"
title={`Are you sure?`} confirmBtnBsStyle="danger"
onConfirm={onConfirmDelete} title={`Are you sure?`}
onCancel={() => cancelDelete()} onConfirm={onConfirmDelete}
focusCancelBtn onCancel={() => cancelDelete()}
> focusCancelBtn
Delete this data >
</SweetAlert> Delete this data
<Modal size="xl" isOpen={openDialog} toggle={toggleDialog}> </SweetAlert>
<ModalHeader className="capitalize withBtn" toggle={closeDialog}> <Modal size="xl" isOpen={openDialog} toggle={toggleDialog}>
<ModalHeader className="capitalize withBtn" toggle={closeDialog}>
<div>Assign Human Resource - {proyekName}</div> <Button onClick={handleOpenDialogFormTools} size='sm' color="primary"><i className='fa fa-plus'></i></Button>
</ModalHeader> <div>Assign Human Resource - {proyekName}</div> <Button onClick={handleOpenDialogFormTools} size='sm' color="primary"><i className='fa fa-plus'></i></Button>
<ModalBody> </ModalHeader>
{renderForm()} <ModalBody>
</ModalBody> {renderForm()}
{/* <ModalFooter> </ModalBody>
<Button className="capitalize" color="secondary" onClick={() => handleCancel()}>Close</Button> {/* <ModalFooter>
</ModalFooter> */} <Button className="capitalize" color="secondary" onClick={() => handleCancel()}>Close</Button>
</Modal> </ModalFooter> */}
<FormAsignHr </Modal>
openDialog={openDialogFormTools} <FormAsignHr
closeDialog={handleCloseDialogFormTools} openDialog={openDialogFormTools}
toggleDialog={toogleDialogFormTools} closeDialog={handleCloseDialogFormTools}
idTask={idTask} toggleDialog={toogleDialogFormTools}
dataEdit={dataEdit} idTask={idTask}
dataHr={listUser} dataEdit={dataEdit}
dataRole={listRole} dataHr={listUser}
dataCurrentHr={dataUserToProject} dataRole={listRole}
/> dataCurrentHr={dataUserToProject}
</> />
) </>
)
}
}
export default AssignHrProject;
export default AssignHrProject;

Loading…
Cancel
Save