wahyuun
1 year ago
3 changed files with 292 additions and 292 deletions
@ -1,239 +1,239 @@
|
||||
import React, { useEffect, useState, useMemo } from 'react' |
||||
import { Modal, ModalHeader, ModalBody, ModalFooter } from 'reactstrap'; |
||||
import { Button } from 'reactstrap'; |
||||
import { Table, Tooltip } from 'antd'; |
||||
import 'antd/dist/antd.css'; |
||||
import moment from 'moment'; |
||||
import SweetAlert from 'react-bootstrap-sweetalert'; |
||||
import { REQUEST_MATERIAL_SEARCH, REQUEST_MATERIAL_ADD, REQUEST_MATERIAL_DELETE, REQUEST_MATERIAL_EDIT } from '../../../const/ApiConst'; |
||||
import axios from "../../../const/interceptorApi" |
||||
import { NotificationContainer, NotificationManager } from 'react-notifications'; |
||||
import DialogRequest from './FormRequestMaterial'; |
||||
import { renderLabelStatus } from '../../../const/CustomFunc'; |
||||
const DialogFormMaterial = ({ openDialog, closeDialog, toggleDialog, idTask, materialResource, proyekName }) => { |
||||
const token = localStorage.getItem("token") |
||||
const HEADER = { |
||||
headers: { |
||||
"Content-Type": "application/json", |
||||
"Authorization": `Bearer ${token}` |
||||
} |
||||
} |
||||
const [dataResource, setDataResource] = useState([]) |
||||
const [openDialogReq, setOpenDialogReq] = useState(false) |
||||
const [alertDelete, setAlertDelete] = useState(false) |
||||
const [idDelete, setIdDelete] = useState(0) |
||||
const [dataEdit, setDataEdit] = useState(null) |
||||
|
||||
useEffect(() => { |
||||
if (idTask > 0) { |
||||
getDataRequestMaterial(); |
||||
} |
||||
}, [idTask]) |
||||
|
||||
useEffect(() => { |
||||
if (!openDialog) { |
||||
setDataResource([]); |
||||
} else { |
||||
|
||||
} |
||||
}, [openDialog]) |
||||
|
||||
|
||||
const getDataRequestMaterial = async () => { |
||||
const payload = { |
||||
"columns": [ |
||||
{ "name": "description", "logic_operator": "ilike", "value": "", "operator": "AND" }, |
||||
{ "name": "proyek_id", "logic_operator": "=", "value": idTask, "operator": "AND" } |
||||
], |
||||
"joins": [], |
||||
"orders": { "columns": ["id"], "ascending": true }, |
||||
"paging": { "start": 0, "length": 25 } |
||||
} |
||||
|
||||
const result = await axios |
||||
.post(REQUEST_MATERIAL_SEARCH, payload, HEADER) |
||||
.then(res => res) |
||||
.catch((error) => error.response); |
||||
console.log("result", result) |
||||
if (result && result.status == 200) { |
||||
setDataResource(result.data.data); |
||||
} else { |
||||
|
||||
} |
||||
} |
||||
|
||||
const handleCancel = () => { |
||||
setDataResource([]); |
||||
setDataEdit(null) |
||||
closeDialog('cancel', 'none') |
||||
} |
||||
|
||||
const handleDelete = (id) => { |
||||
setIdDelete(id) |
||||
setAlertDelete(true) |
||||
} |
||||
|
||||
const handleEdit = async (data) => { |
||||
await setDataEdit(data) |
||||
setOpenDialogReq(true) |
||||
} |
||||
|
||||
const RenderTable = useMemo(() => { |
||||
const columns = [ |
||||
{ |
||||
title: 'Action', |
||||
dataIndex: '', |
||||
key: 'id', |
||||
className: "nowrap", |
||||
render: (text, record) => <> |
||||
|
||||
{text.status == "fom" ? <><Tooltip title="Delete Request Resource"> |
||||
<Button size="small" size={"sm"} color='danger' onClick={() => handleDelete(text.id)}><i className="fa fa-trash"></i></Button> |
||||
</Tooltip>{" "}<Tooltip title="Edit Request Resource"> |
||||
<Button size="small" size={"sm"} color='primary' onClick={() => handleEdit(text)}><i className="fa fa-edit"></i></Button> |
||||
</Tooltip></> : "-"} |
||||
</>, |
||||
}, |
||||
{ title: 'Status', dataIndex: 'status', key: 'status', render: (text, record) => renderLabelStatus(text) }, |
||||
{ title: 'Description', dataIndex: 'description', key: 'description' }, |
||||
{ title: 'Required Date', dataIndex: 'required_date', key: 'required_date', className: "nowrap", render: (text, record) => (<div style={{ whiteSpace: "nowrap" }}>{moment(text).format("D-M-YYYY")}</div>) }, |
||||
{ title: 'QTY', dataIndex: 'qty', key: 'qty', render: (text, record) => (<div style={{ whiteSpace: "nowrap" }}>{text ? text : "-"}</div>) }, |
||||
{ title: 'UOM', dataIndex: 'uom', key: 'uom', render: (text, record) => (<div style={{ whiteSpace: "nowrap" }}>{text ? text : "-"}</div>) }, |
||||
{ title: 'QTY Received', dataIndex: 'qty_received', key: 'qty_received', className: "nowrap", render: (text, record) => (<div style={{ whiteSpace: "nowrap" }}>{text ? text : "-"}</div>) }, |
||||
{ title: 'FOM Date', dataIndex: 'fom_date', key: 'fom_date', className: "nowrap", render: (text, record) => (<div style={{ whiteSpace: "nowrap" }}>{moment(text).format("D-M-YYYY")}</div>) }, |
||||
{ title: 'PR Date', dataIndex: 'pr_date', key: 'pr_date', className: "nowrap", render: (text, record) => (<div style={{ whiteSpace: "nowrap" }}>{text ? moment(text).format("D-M-YYYY") : "-"}</div>) }, |
||||
{ title: 'PO Date', dataIndex: 'po_date', key: 'po_date', className: "nowrap", render: (text, record) => (<div style={{ whiteSpace: "nowrap" }}>{text ? moment(text).format("D-M-YYYY") : "-"}</div>) }, |
||||
{ title: 'Received Date', dataIndex: 'received_date', key: 'received_date', className: "nowrap", render: (text, record) => (<div style={{ whiteSpace: "nowrap" }}>{text ? moment(text).format("D-M-YYYY") : "-"}</div>) }, |
||||
{ title: 'Delivery Date', dataIndex: 'delivery_date', key: 'delivery_date', className: "nowrap", render: (text, record) => (<div style={{ whiteSpace: "nowrap" }}>{text ? moment(text).format("D-M-YYYY") : "-"}</div>) }, |
||||
]; |
||||
|
||||
return ( |
||||
<Table |
||||
size="small" |
||||
columns={columns} |
||||
rowKey={"id"} |
||||
dataSource={dataResource} |
||||
pagination={{ position: ["bottomLeft"] }} |
||||
/> |
||||
) |
||||
}, [dataResource]) |
||||
|
||||
const closeDialogReq = (type, data) => { |
||||
if (type == "add") { |
||||
saveRequestMaterial(data); |
||||
} else if (type == "edit") { |
||||
updateRequestMaterial(data); |
||||
} else { |
||||
setOpenDialogReq(false); |
||||
setDataEdit(null) |
||||
} |
||||
|
||||
} |
||||
|
||||
const toggleDialogReq = () => { |
||||
setOpenDialogReq(!openDialogReq) |
||||
} |
||||
|
||||
const openDialogRequest = () => { |
||||
setOpenDialogReq(true) |
||||
} |
||||
|
||||
const saveRequestMaterial = async (data) => { |
||||
const result = await axios |
||||
.post(REQUEST_MATERIAL_ADD, data, HEADER) |
||||
.then(res => res) |
||||
.catch((error) => error.response); |
||||
|
||||
if (result && result.data && result.data.code == 200) { |
||||
getDataRequestMaterial(); |
||||
NotificationManager.success('Data request material berhasill ditambahkan!!', 'Success'); |
||||
setOpenDialogReq(false); |
||||
setDataEdit(null) |
||||
} else { |
||||
NotificationManager.error('Data request material gagal ditambahkan!!', 'Failed'); |
||||
} |
||||
} |
||||
|
||||
const updateRequestMaterial = async (data) => { |
||||
let url = REQUEST_MATERIAL_EDIT(data.id) |
||||
const result = await axios |
||||
.put(url, data, HEADER) |
||||
.then(res => res) |
||||
.catch((error) => error.response); |
||||
|
||||
if (result && result.data && result.data.code == 200) { |
||||
getDataRequestMaterial(); |
||||
NotificationManager.success('Data request material berhasill diedit!!', 'Success'); |
||||
setOpenDialogReq(false); |
||||
setDataEdit(null) |
||||
} else { |
||||
NotificationManager.error('Data request material gagal diedit!!', 'Failed'); |
||||
} |
||||
} |
||||
|
||||
const cancelDelete = () => { |
||||
setAlertDelete(false) |
||||
setIdDelete(0) |
||||
} |
||||
|
||||
const onConfirmDelete = async () => { |
||||
let urlDel = REQUEST_MATERIAL_DELETE(idDelete) |
||||
const result = await axios.delete(urlDel, HEADER) |
||||
.then(res => res) |
||||
.catch((error) => error.response); |
||||
|
||||
if (result && result.data && result.data.code === 200) { |
||||
getDataRequestMaterial() |
||||
setIdDelete(0) |
||||
setAlertDelete(false) |
||||
NotificationManager.success(`Data request material berhasil dihapus`, 'Success!!'); |
||||
} else { |
||||
setIdDelete(0) |
||||
setAlertDelete(false) |
||||
NotificationManager.error(`Data request material gagal dihapus`, 'Failed!!'); |
||||
} |
||||
} |
||||
|
||||
return ( |
||||
<> |
||||
<Modal size="xl" isOpen={openDialog} toggle={toggleDialog}> |
||||
<ModalHeader className="capitalize withBtn" toggle={closeDialog} style={{ width: "100%" }}> |
||||
<div>Request Material Resource - {proyekName}</div> <Button onClick={openDialogRequest} size='sm' color="primary"><i className='fa fa-plus'></i></Button> |
||||
</ModalHeader> |
||||
<ModalBody> |
||||
<div style={{ width: '100%', overflow: "auto" }}> |
||||
{RenderTable} |
||||
</div> |
||||
</ModalBody> |
||||
{/* <ModalFooter> |
||||
<Button className="capitalize" color="secondary" onClick={() => handleCancel()}>Batal</Button> |
||||
</ModalFooter> */} |
||||
</Modal> |
||||
<NotificationContainer /> |
||||
<SweetAlert |
||||
show={alertDelete} |
||||
warning |
||||
showCancel |
||||
confirmBtnText="Delete" |
||||
confirmBtnBsStyle="danger" |
||||
title={`Are you sure?`} |
||||
onConfirm={onConfirmDelete} |
||||
onCancel={() => cancelDelete()} |
||||
focusCancelBtn |
||||
> |
||||
Delete this data |
||||
</SweetAlert> |
||||
<DialogRequest |
||||
openDialog={openDialogReq} |
||||
closeDialog={closeDialogReq} |
||||
toggleDialog={toggleDialogReq} |
||||
idTask={idTask} |
||||
dataEdit={dataEdit} |
||||
materialResource={materialResource} |
||||
/> |
||||
</> |
||||
) |
||||
|
||||
} |
||||
|
||||
export default DialogFormMaterial; |
||||
import React, { useEffect, useState, useMemo } from 'react' |
||||
import { Modal, ModalHeader, ModalBody, ModalFooter } from 'reactstrap'; |
||||
import { Button } from 'reactstrap'; |
||||
import { Table, Tooltip } from 'antd'; |
||||
import 'antd/dist/antd.css'; |
||||
import moment from 'moment'; |
||||
import SweetAlert from 'react-bootstrap-sweetalert'; |
||||
import { REQUEST_MATERIAL_SEARCH, REQUEST_MATERIAL_ADD, REQUEST_MATERIAL_DELETE, REQUEST_MATERIAL_EDIT } from '../../../const/ApiConst'; |
||||
import axios from "../../../const/interceptorApi" |
||||
import { NotificationContainer, NotificationManager } from 'react-notifications'; |
||||
import DialogRequest from './FormRequestMaterial'; |
||||
import { renderLabelStatus } from '../../../const/CustomFunc'; |
||||
const DialogFormMaterial = ({ openDialog, closeDialog, toggleDialog, idTask, materialResource, proyekName }) => { |
||||
const token = localStorage.getItem("token") |
||||
const HEADER = { |
||||
headers: { |
||||
"Content-Type": "application/json", |
||||
"Authorization": `Bearer ${token}` |
||||
} |
||||
} |
||||
const [dataResource, setDataResource] = useState([]) |
||||
const [openDialogReq, setOpenDialogReq] = useState(false) |
||||
const [alertDelete, setAlertDelete] = useState(false) |
||||
const [idDelete, setIdDelete] = useState(0) |
||||
const [dataEdit, setDataEdit] = useState(null) |
||||
|
||||
useEffect(() => { |
||||
if (idTask > 0) { |
||||
// getDataRequestMaterial();
|
||||
} |
||||
}, [idTask]) |
||||
|
||||
useEffect(() => { |
||||
if (!openDialog) { |
||||
setDataResource([]); |
||||
} else { |
||||
|
||||
} |
||||
}, [openDialog]) |
||||
|
||||
|
||||
const getDataRequestMaterial = async () => { |
||||
const payload = { |
||||
"columns": [ |
||||
{ "name": "description", "logic_operator": "ilike", "value": "", "operator": "AND" }, |
||||
{ "name": "proyek_id", "logic_operator": "=", "value": idTask, "operator": "AND" } |
||||
], |
||||
"joins": [], |
||||
"orders": { "columns": ["id"], "ascending": true }, |
||||
"paging": { "start": 0, "length": 25 } |
||||
} |
||||
|
||||
const result = await axios |
||||
.post(REQUEST_MATERIAL_SEARCH, payload, HEADER) |
||||
.then(res => res) |
||||
.catch((error) => error.response); |
||||
console.log("result", result) |
||||
if (result && result.status == 200) { |
||||
setDataResource(result.data.data); |
||||
} else { |
||||
|
||||
} |
||||
} |
||||
|
||||
const handleCancel = () => { |
||||
setDataResource([]); |
||||
setDataEdit(null) |
||||
closeDialog('cancel', 'none') |
||||
} |
||||
|
||||
const handleDelete = (id) => { |
||||
setIdDelete(id) |
||||
setAlertDelete(true) |
||||
} |
||||
|
||||
const handleEdit = async (data) => { |
||||
await setDataEdit(data) |
||||
setOpenDialogReq(true) |
||||
} |
||||
|
||||
const RenderTable = useMemo(() => { |
||||
const columns = [ |
||||
{ |
||||
title: 'Action', |
||||
dataIndex: '', |
||||
key: 'id', |
||||
className: "nowrap", |
||||
render: (text, record) => <> |
||||
|
||||
{text.status == "fom" ? <><Tooltip title="Delete Request Resource"> |
||||
<Button size="small" size={"sm"} color='danger' onClick={() => handleDelete(text.id)}><i className="fa fa-trash"></i></Button> |
||||
</Tooltip>{" "}<Tooltip title="Edit Request Resource"> |
||||
<Button size="small" size={"sm"} color='primary' onClick={() => handleEdit(text)}><i className="fa fa-edit"></i></Button> |
||||
</Tooltip></> : "-"} |
||||
</>, |
||||
}, |
||||
{ title: 'Status', dataIndex: 'status', key: 'status', render: (text, record) => renderLabelStatus(text) }, |
||||
{ title: 'Description', dataIndex: 'description', key: 'description' }, |
||||
{ title: 'Required Date', dataIndex: 'required_date', key: 'required_date', className: "nowrap", render: (text, record) => (<div style={{ whiteSpace: "nowrap" }}>{moment(text).format("D-M-YYYY")}</div>) }, |
||||
{ title: 'QTY', dataIndex: 'qty', key: 'qty', render: (text, record) => (<div style={{ whiteSpace: "nowrap" }}>{text ? text : "-"}</div>) }, |
||||
{ title: 'UOM', dataIndex: 'uom', key: 'uom', render: (text, record) => (<div style={{ whiteSpace: "nowrap" }}>{text ? text : "-"}</div>) }, |
||||
{ title: 'QTY Received', dataIndex: 'qty_received', key: 'qty_received', className: "nowrap", render: (text, record) => (<div style={{ whiteSpace: "nowrap" }}>{text ? text : "-"}</div>) }, |
||||
{ title: 'FOM Date', dataIndex: 'fom_date', key: 'fom_date', className: "nowrap", render: (text, record) => (<div style={{ whiteSpace: "nowrap" }}>{moment(text).format("D-M-YYYY")}</div>) }, |
||||
{ title: 'PR Date', dataIndex: 'pr_date', key: 'pr_date', className: "nowrap", render: (text, record) => (<div style={{ whiteSpace: "nowrap" }}>{text ? moment(text).format("D-M-YYYY") : "-"}</div>) }, |
||||
{ title: 'PO Date', dataIndex: 'po_date', key: 'po_date', className: "nowrap", render: (text, record) => (<div style={{ whiteSpace: "nowrap" }}>{text ? moment(text).format("D-M-YYYY") : "-"}</div>) }, |
||||
{ title: 'Received Date', dataIndex: 'received_date', key: 'received_date', className: "nowrap", render: (text, record) => (<div style={{ whiteSpace: "nowrap" }}>{text ? moment(text).format("D-M-YYYY") : "-"}</div>) }, |
||||
{ title: 'Delivery Date', dataIndex: 'delivery_date', key: 'delivery_date', className: "nowrap", render: (text, record) => (<div style={{ whiteSpace: "nowrap" }}>{text ? moment(text).format("D-M-YYYY") : "-"}</div>) }, |
||||
]; |
||||
|
||||
return ( |
||||
<Table |
||||
size="small" |
||||
columns={columns} |
||||
rowKey={"id"} |
||||
dataSource={dataResource} |
||||
pagination={{ position: ["bottomLeft"] }} |
||||
/> |
||||
) |
||||
}, [dataResource]) |
||||
|
||||
const closeDialogReq = (type, data) => { |
||||
if (type == "add") { |
||||
saveRequestMaterial(data); |
||||
} else if (type == "edit") { |
||||
updateRequestMaterial(data); |
||||
} else { |
||||
setOpenDialogReq(false); |
||||
setDataEdit(null) |
||||
} |
||||
|
||||
} |
||||
|
||||
const toggleDialogReq = () => { |
||||
setOpenDialogReq(!openDialogReq) |
||||
} |
||||
|
||||
const openDialogRequest = () => { |
||||
setOpenDialogReq(true) |
||||
} |
||||
|
||||
const saveRequestMaterial = async (data) => { |
||||
const result = await axios |
||||
.post(REQUEST_MATERIAL_ADD, data, HEADER) |
||||
.then(res => res) |
||||
.catch((error) => error.response); |
||||
|
||||
if (result && result.data && result.data.code == 200) { |
||||
getDataRequestMaterial(); |
||||
NotificationManager.success('Data request material berhasill ditambahkan!!', 'Success'); |
||||
setOpenDialogReq(false); |
||||
setDataEdit(null) |
||||
} else { |
||||
NotificationManager.error('Data request material gagal ditambahkan!!', 'Failed'); |
||||
} |
||||
} |
||||
|
||||
const updateRequestMaterial = async (data) => { |
||||
let url = REQUEST_MATERIAL_EDIT(data.id) |
||||
const result = await axios |
||||
.put(url, data, HEADER) |
||||
.then(res => res) |
||||
.catch((error) => error.response); |
||||
|
||||
if (result && result.data && result.data.code == 200) { |
||||
getDataRequestMaterial(); |
||||
NotificationManager.success('Data request material berhasill diedit!!', 'Success'); |
||||
setOpenDialogReq(false); |
||||
setDataEdit(null) |
||||
} else { |
||||
NotificationManager.error('Data request material gagal diedit!!', 'Failed'); |
||||
} |
||||
} |
||||
|
||||
const cancelDelete = () => { |
||||
setAlertDelete(false) |
||||
setIdDelete(0) |
||||
} |
||||
|
||||
const onConfirmDelete = async () => { |
||||
let urlDel = REQUEST_MATERIAL_DELETE(idDelete) |
||||
const result = await axios.delete(urlDel, HEADER) |
||||
.then(res => res) |
||||
.catch((error) => error.response); |
||||
|
||||
if (result && result.data && result.data.code === 200) { |
||||
getDataRequestMaterial() |
||||
setIdDelete(0) |
||||
setAlertDelete(false) |
||||
NotificationManager.success(`Data request material berhasil dihapus`, 'Success!!'); |
||||
} else { |
||||
setIdDelete(0) |
||||
setAlertDelete(false) |
||||
NotificationManager.error(`Data request material gagal dihapus`, 'Failed!!'); |
||||
} |
||||
} |
||||
|
||||
return ( |
||||
<> |
||||
<Modal size="xl" isOpen={openDialog} toggle={toggleDialog}> |
||||
<ModalHeader className="capitalize withBtn" toggle={closeDialog} style={{ width: "100%" }}> |
||||
<div>Request Material Resource - {proyekName}</div> <Button onClick={openDialogRequest} size='sm' color="primary"><i className='fa fa-plus'></i></Button> |
||||
</ModalHeader> |
||||
<ModalBody> |
||||
<div style={{ width: '100%', overflow: "auto" }}> |
||||
{RenderTable} |
||||
</div> |
||||
</ModalBody> |
||||
{/* <ModalFooter> |
||||
<Button className="capitalize" color="secondary" onClick={() => handleCancel()}>Batal</Button> |
||||
</ModalFooter> */} |
||||
</Modal> |
||||
<NotificationContainer /> |
||||
<SweetAlert |
||||
show={alertDelete} |
||||
warning |
||||
showCancel |
||||
confirmBtnText="Delete" |
||||
confirmBtnBsStyle="danger" |
||||
title={`Are you sure?`} |
||||
onConfirm={onConfirmDelete} |
||||
onCancel={() => cancelDelete()} |
||||
focusCancelBtn |
||||
> |
||||
Delete this data |
||||
</SweetAlert> |
||||
<DialogRequest |
||||
openDialog={openDialogReq} |
||||
closeDialog={closeDialogReq} |
||||
toggleDialog={toggleDialogReq} |
||||
idTask={idTask} |
||||
dataEdit={dataEdit} |
||||
materialResource={materialResource} |
||||
/> |
||||
</> |
||||
) |
||||
|
||||
} |
||||
|
||||
export default DialogFormMaterial; |
||||
|
Loading…
Reference in new issue