|
|
|
@ -1,7 +1,7 @@
|
|
|
|
|
import React, { useEffect, useState } from 'react' |
|
|
|
|
import { |
|
|
|
|
Modal, ModalHeader, ModalBody, ModalFooter, |
|
|
|
|
Button, Form, FormGroup, Label, Input, Col, Row |
|
|
|
|
Modal, ModalHeader, ModalBody, ModalFooter, |
|
|
|
|
Button, Form, FormGroup, Label, Input, Col, Row |
|
|
|
|
} from 'reactstrap'; |
|
|
|
|
import { DatePicker, Tooltip, Select } from 'antd'; |
|
|
|
|
import { formatRupiah, formatNumber } from '../../../const/CustomFunc' |
|
|
|
@ -9,7 +9,7 @@ import moment from 'moment';
|
|
|
|
|
import 'antd/dist/antd.css'; |
|
|
|
|
const { Option } = Select |
|
|
|
|
|
|
|
|
|
const DialogForm = ({openDialog, closeDialog, toggleDialog, typeDialog, dataEdit}) => { |
|
|
|
|
const DialogForm = ({ openDialog, closeDialog, toggleDialog, typeDialog, dataEdit, dataUom }) => { |
|
|
|
|
const [id, setId] = useState(0) |
|
|
|
|
const [materialName, setMaterialName] = useState('') |
|
|
|
|
const [uom, setUom] = useState('') |
|
|
|
@ -30,8 +30,8 @@ const DialogForm = ({openDialog, closeDialog, toggleDialog, typeDialog, dataEdit
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
useEffect(()=> { |
|
|
|
|
if(typeDialog==="Edit"){ |
|
|
|
|
useEffect(() => { |
|
|
|
|
if (typeDialog === "Edit") { |
|
|
|
|
console.log("cel data Edit", dataEdit) |
|
|
|
|
setId(dataEdit.id) |
|
|
|
|
setQty(dataEdit.qty) |
|
|
|
@ -73,75 +73,75 @@ const DialogForm = ({openDialog, closeDialog, toggleDialog, typeDialog, dataEdit
|
|
|
|
|
setReceivedDate(dataEdit.received_date ? moment(dataEdit.received_date) : null) |
|
|
|
|
setDeliveryDate(dataEdit.delivery_date ? moment(dataEdit.delivery_date) : null) |
|
|
|
|
} |
|
|
|
|
else if (typeDialog === 'Save'){ |
|
|
|
|
else if (typeDialog === 'Save') { |
|
|
|
|
setId(0) |
|
|
|
|
} |
|
|
|
|
},[dataEdit,openDialog]) |
|
|
|
|
}, [dataEdit, openDialog]) |
|
|
|
|
|
|
|
|
|
const handleSave = () => { |
|
|
|
|
let data = ''; |
|
|
|
|
if(typeDialog==="Save"){ |
|
|
|
|
data = { |
|
|
|
|
name: materialName, |
|
|
|
|
qty, |
|
|
|
|
uom, |
|
|
|
|
description, |
|
|
|
|
unit_price: typeof(unitPrice) === 'string' && unitPrice !== '' && unitPrice.includes('.') ? parseInt(unitPrice.replace(/\./g,'')) : unitPrice, |
|
|
|
|
status |
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
closeDialog('save', data); |
|
|
|
|
let data = ''; |
|
|
|
|
if (typeDialog === "Save") { |
|
|
|
|
data = { |
|
|
|
|
name: materialName, |
|
|
|
|
qty, |
|
|
|
|
uom, |
|
|
|
|
description, |
|
|
|
|
unit_price: typeof (unitPrice) === 'string' && unitPrice !== '' && unitPrice.includes('.') ? parseInt(unitPrice.replace(/\./g, '')) : unitPrice, |
|
|
|
|
status |
|
|
|
|
} |
|
|
|
|
else if (typeDialog === 'Edit') { |
|
|
|
|
console.log('typeof', typeof(unitPrice)); |
|
|
|
|
data = { |
|
|
|
|
id, |
|
|
|
|
name: materialName, |
|
|
|
|
qty, |
|
|
|
|
uom, |
|
|
|
|
description, |
|
|
|
|
unit_price: typeof(unitPrice) === 'string' && unitPrice !== '' && unitPrice.includes('.') ? parseInt(unitPrice.replace(/\./g,'')) : unitPrice, |
|
|
|
|
status |
|
|
|
|
} |
|
|
|
|
closeDialog('edit', data); |
|
|
|
|
|
|
|
|
|
closeDialog('save', data); |
|
|
|
|
} |
|
|
|
|
else if (typeDialog === 'Edit') { |
|
|
|
|
console.log('typeof', typeof (unitPrice)); |
|
|
|
|
data = { |
|
|
|
|
id, |
|
|
|
|
name: materialName, |
|
|
|
|
qty, |
|
|
|
|
uom, |
|
|
|
|
description, |
|
|
|
|
unit_price: typeof (unitPrice) === 'string' && unitPrice !== '' && unitPrice.includes('.') ? parseInt(unitPrice.replace(/\./g, '')) : unitPrice, |
|
|
|
|
status |
|
|
|
|
} |
|
|
|
|
else if (typeDialog === 'EditMatReq') { |
|
|
|
|
data = { |
|
|
|
|
id, |
|
|
|
|
uom, |
|
|
|
|
description, |
|
|
|
|
status, |
|
|
|
|
required_date: requiredDate, |
|
|
|
|
qty, |
|
|
|
|
qty_received: qtyReceived, |
|
|
|
|
fom_date: fomDate, |
|
|
|
|
pr_date: prDate, |
|
|
|
|
po_date: poDate, |
|
|
|
|
received_date: receivedDate, |
|
|
|
|
delivery_date: deliveryDate, |
|
|
|
|
price: typeof(priceReq) === 'string' && priceReq !== '' && priceReq.includes('.') ? parseInt(priceReq.replace(/\./g,'')) : priceReq, |
|
|
|
|
} |
|
|
|
|
closeDialog('EditMatReq', data); |
|
|
|
|
closeDialog('edit', data); |
|
|
|
|
} |
|
|
|
|
else if (typeDialog === 'EditMatReq') { |
|
|
|
|
data = { |
|
|
|
|
id, |
|
|
|
|
uom, |
|
|
|
|
description, |
|
|
|
|
status, |
|
|
|
|
required_date: requiredDate, |
|
|
|
|
qty, |
|
|
|
|
qty_received: qtyReceived, |
|
|
|
|
fom_date: fomDate, |
|
|
|
|
pr_date: prDate, |
|
|
|
|
po_date: poDate, |
|
|
|
|
received_date: receivedDate, |
|
|
|
|
delivery_date: deliveryDate, |
|
|
|
|
price: typeof (priceReq) === 'string' && priceReq !== '' && priceReq.includes('.') ? parseInt(priceReq.replace(/\./g, '')) : priceReq, |
|
|
|
|
} |
|
|
|
|
else if (typeDialog === 'EditMatDelv') { |
|
|
|
|
data = { |
|
|
|
|
id, |
|
|
|
|
uom, |
|
|
|
|
description, |
|
|
|
|
status, |
|
|
|
|
required_date: requiredDate, |
|
|
|
|
qty, |
|
|
|
|
qty_received: qtyReceived, |
|
|
|
|
fom_date: fomDate, |
|
|
|
|
pr_date: prDate, |
|
|
|
|
po_date: poDate, |
|
|
|
|
received_date: receivedDate, |
|
|
|
|
delivery_date: deliveryDate |
|
|
|
|
} |
|
|
|
|
closeDialog('EditMatDelv', data); |
|
|
|
|
closeDialog('EditMatReq', data); |
|
|
|
|
} |
|
|
|
|
else if (typeDialog === 'EditMatDelv') { |
|
|
|
|
data = { |
|
|
|
|
id, |
|
|
|
|
uom, |
|
|
|
|
description, |
|
|
|
|
status, |
|
|
|
|
required_date: requiredDate, |
|
|
|
|
qty, |
|
|
|
|
qty_received: qtyReceived, |
|
|
|
|
fom_date: fomDate, |
|
|
|
|
pr_date: prDate, |
|
|
|
|
po_date: poDate, |
|
|
|
|
received_date: receivedDate, |
|
|
|
|
delivery_date: deliveryDate |
|
|
|
|
} |
|
|
|
|
setId(0) |
|
|
|
|
setDescription('') |
|
|
|
|
closeDialog('EditMatDelv', data); |
|
|
|
|
} |
|
|
|
|
setId(0) |
|
|
|
|
setDescription('') |
|
|
|
|
|
|
|
|
|
} |
|
|
|
|
|
|
|
|
@ -151,58 +151,74 @@ const DialogForm = ({openDialog, closeDialog, toggleDialog, typeDialog, dataEdit
|
|
|
|
|
setDescription('') |
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
const setupSelectUom = () => { |
|
|
|
|
return ( |
|
|
|
|
<> |
|
|
|
|
{dataUom.map((val, index) => { |
|
|
|
|
return ( |
|
|
|
|
<Option key={index} value={val.id}>{val.name}</Option> |
|
|
|
|
) |
|
|
|
|
})} |
|
|
|
|
</> |
|
|
|
|
) |
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
const renderForm = () => { |
|
|
|
|
if (typeDialog === 'Save' || typeDialog === 'Edit') { |
|
|
|
|
return( |
|
|
|
|
return ( |
|
|
|
|
<Form> |
|
|
|
|
<Row> |
|
|
|
|
<Col md={12}> |
|
|
|
|
<FormGroup> |
|
|
|
|
<Label className="capitalize">Material Name</Label> |
|
|
|
|
<Input type="text" value={materialName} onChange={(e)=> setMaterialName(e.target.value)} placeholder={`Input material name...`}/> |
|
|
|
|
</FormGroup> |
|
|
|
|
</Col> |
|
|
|
|
<Col md={12}> |
|
|
|
|
<FormGroup> |
|
|
|
|
<Label className="capitalize">Material Name</Label> |
|
|
|
|
<Input type="text" value={materialName} onChange={(e) => setMaterialName(e.target.value)} placeholder={`Input material name...`} /> |
|
|
|
|
</FormGroup> |
|
|
|
|
</Col> |
|
|
|
|
</Row> |
|
|
|
|
<Row> |
|
|
|
|
<Col md={6}> |
|
|
|
|
<FormGroup> |
|
|
|
|
<Label className="capitalize">QTY</Label> |
|
|
|
|
<Input type="number" value={qty} onChange={(e) => setQty(e.target.value)} placeholder={`Input qty...`} /> |
|
|
|
|
</FormGroup> |
|
|
|
|
</Col> |
|
|
|
|
<Col md={6}> |
|
|
|
|
<FormGroup> |
|
|
|
|
<Label className="capitalize">UOM</Label> |
|
|
|
|
|
|
|
|
|
<Select showSearch defaultValue={uom} onChange={(val) => setUom(val)} placeholder="Select Uom" style={{ width: '100%' }}> |
|
|
|
|
{setupSelectUom()} |
|
|
|
|
</Select> |
|
|
|
|
</FormGroup> |
|
|
|
|
<Col md={6}> |
|
|
|
|
<FormGroup> |
|
|
|
|
<Label className="capitalize">QTY</Label> |
|
|
|
|
<Input type="text" value={qty} onChange={(e)=> setQty(e.target.value)} placeholder={`Input qty...`} /> |
|
|
|
|
</FormGroup> |
|
|
|
|
</Col> |
|
|
|
|
<Col md={6}> |
|
|
|
|
<FormGroup> |
|
|
|
|
<Label className="capitalize">UOM</Label> |
|
|
|
|
<Input type="text" value={uom} onChange={(e)=> setUom(e.target.value)} placeholder={`Input uom...`} /> |
|
|
|
|
</FormGroup> |
|
|
|
|
|
|
|
|
|
</Col> |
|
|
|
|
</Col> |
|
|
|
|
</Row> |
|
|
|
|
<Row> |
|
|
|
|
<Col md={6}> |
|
|
|
|
<FormGroup> |
|
|
|
|
<Label className="capitalize">Unit Price</Label> |
|
|
|
|
<Input type="text" value={unitPrice} onChange={(e)=> setUnitPrice(formatNumber(e.target.value))} placeholder={`Unit Price...`} /> |
|
|
|
|
</FormGroup> |
|
|
|
|
</Col> |
|
|
|
|
<Col md={6}> |
|
|
|
|
<FormGroup> |
|
|
|
|
<Label className="capitalize">Status</Label> |
|
|
|
|
<Input type="text" value={status} onChange={(e)=> setStatus(e.target.value)} placeholder={`Status ...`} /> |
|
|
|
|
</FormGroup> |
|
|
|
|
</Col> |
|
|
|
|
<Col md={6}> |
|
|
|
|
<FormGroup> |
|
|
|
|
<Label className="capitalize">Unit Price</Label> |
|
|
|
|
<Input type="text" value={unitPrice} onChange={(e) => setUnitPrice(formatNumber(e.target.value))} placeholder={`Unit Price...`} /> |
|
|
|
|
</FormGroup> |
|
|
|
|
</Col> |
|
|
|
|
<Col md={6}> |
|
|
|
|
<FormGroup> |
|
|
|
|
<Label className="capitalize">Status</Label> |
|
|
|
|
<Input type="text" value={status} onChange={(e) => setStatus(e.target.value)} placeholder={`Status ...`} /> |
|
|
|
|
</FormGroup> |
|
|
|
|
</Col> |
|
|
|
|
</Row> |
|
|
|
|
<Row> |
|
|
|
|
<Col md={12}> |
|
|
|
|
<FormGroup> |
|
|
|
|
<Label className="capitalize">Description</Label> |
|
|
|
|
<Input row="2" type="textarea" value={description} onChange={(e)=> setDescription(e.target.value)} placeholder={`Description ...`} /> |
|
|
|
|
</FormGroup> |
|
|
|
|
</Col> |
|
|
|
|
<Col md={12}> |
|
|
|
|
<FormGroup> |
|
|
|
|
<Label className="capitalize">Description</Label> |
|
|
|
|
<Input row="2" type="textarea" value={description} onChange={(e) => setDescription(e.target.value)} placeholder={`Description ...`} /> |
|
|
|
|
</FormGroup> |
|
|
|
|
</Col> |
|
|
|
|
</Row> |
|
|
|
|
</Form> |
|
|
|
|
) |
|
|
|
@ -236,7 +252,7 @@ const DialogForm = ({openDialog, closeDialog, toggleDialog, typeDialog, dataEdit
|
|
|
|
|
<Col md={6}> |
|
|
|
|
<FormGroup> |
|
|
|
|
<Label className="capitalize">Description</Label> |
|
|
|
|
<Input row="2" type="textarea" value={description} onChange={(e)=> setDescription(e.target.value)} placeholder={`Description ...`} /> |
|
|
|
|
<Input row="2" type="textarea" value={description} onChange={(e) => setDescription(e.target.value)} placeholder={`Description ...`} /> |
|
|
|
|
</FormGroup> |
|
|
|
|
</Col> |
|
|
|
|
<Col md={6}> |
|
|
|
@ -250,7 +266,7 @@ const DialogForm = ({openDialog, closeDialog, toggleDialog, typeDialog, dataEdit
|
|
|
|
|
<Col md={6}> |
|
|
|
|
<FormGroup> |
|
|
|
|
<Label className="capitalize">QTY</Label> |
|
|
|
|
<Input type="number" value={qty} onChange={(e) => setQty(e.target.value)} placeholder={`Input QTY...`} disabled /> |
|
|
|
|
<Input type="number" min="0" value={qty} onChange={(e) => setQty(e.target.value)} placeholder={`Input QTY...`} disabled /> |
|
|
|
|
</FormGroup> |
|
|
|
|
</Col> |
|
|
|
|
<Col md={6}> |
|
|
|
@ -324,7 +340,7 @@ const DialogForm = ({openDialog, closeDialog, toggleDialog, typeDialog, dataEdit
|
|
|
|
|
<Col md={6}> |
|
|
|
|
<FormGroup> |
|
|
|
|
<Label className="capitalize">Description</Label> |
|
|
|
|
<Input row="2" type="textarea" value={description} onChange={(e)=> setDescription(e.target.value)} placeholder={`Description ...`} /> |
|
|
|
|
<Input row="2" type="textarea" value={description} onChange={(e) => setDescription(e.target.value)} placeholder={`Description ...`} /> |
|
|
|
|
</FormGroup> |
|
|
|
|
</Col> |
|
|
|
|
<Col md={6}> |
|
|
|
@ -398,18 +414,18 @@ const DialogForm = ({openDialog, closeDialog, toggleDialog, typeDialog, dataEdit
|
|
|
|
|
|
|
|
|
|
return ( |
|
|
|
|
<> |
|
|
|
|
<Modal size="lg" isOpen={openDialog} toggle={toggleDialog}> |
|
|
|
|
<ModalHeader className="capitalize" toggle={closeDialog}>{typeDialog=="Save" ? `Add` : "Edit"} Resource</ModalHeader> |
|
|
|
|
<ModalBody> |
|
|
|
|
<Modal size="lg" isOpen={openDialog} toggle={toggleDialog}> |
|
|
|
|
<ModalHeader className="capitalize" toggle={closeDialog}>{typeDialog == "Save" ? `Add` : "Edit"} Resource</ModalHeader> |
|
|
|
|
<ModalBody> |
|
|
|
|
{renderForm()} |
|
|
|
|
</ModalBody> |
|
|
|
|
<ModalFooter> |
|
|
|
|
<Button color="primary" onClick={() => handleSave()}>{typeDialog === 'Save' ? 'Save' : 'Edit'}</Button>{' '} |
|
|
|
|
<Button className="capitalize" color="secondary" onClick={() => handleCancel()}>Batal</Button> |
|
|
|
|
</ModalFooter> |
|
|
|
|
</Modal> |
|
|
|
|
</ModalBody> |
|
|
|
|
<ModalFooter> |
|
|
|
|
<Button color="primary" onClick={() => handleSave()}>{typeDialog === 'Save' ? 'Save' : 'Edit'}</Button>{' '} |
|
|
|
|
<Button className="capitalize" color="secondary" onClick={() => handleCancel()}>Batal</Button> |
|
|
|
|
</ModalFooter> |
|
|
|
|
</Modal> |
|
|
|
|
|
|
|
|
|
{/* <DialogMap |
|
|
|
|
{/* <DialogMap |
|
|
|
|
openDialog={openDialogMap} |
|
|
|
|
closeDialog={handleCloseDialogMap} |
|
|
|
|
toggleDialog={() => toggleMapDialog} |
|
|
|
|