Browse Source

fix endline

pull/1/head
wahyu 1 year ago
parent
commit
cd698c92f8
  1. 492
      src/views/SimproV2/CreatedProyek/FormAsignHr.js

492
src/views/SimproV2/CreatedProyek/FormAsignHr.js

@ -1,246 +1,246 @@
import React, { useEffect, useState } from 'react' import React, { useEffect, useState } from 'react'
import { Modal, ModalHeader, ModalBody, ModalFooter } from 'reactstrap'; import { Modal, ModalHeader, ModalBody, ModalFooter } from 'reactstrap';
import { Button, Form, FormGroup, Label, Input, Col, Row } from 'reactstrap'; import { Button, Form, FormGroup, Label, Input, Col, Row } from 'reactstrap';
import { DatePicker, Select } from 'antd'; import { DatePicker, Select } from 'antd';
import 'antd/dist/antd.css'; import 'antd/dist/antd.css';
import { formatNumber } from '../../../const/CustomFunc'; import { formatNumber } from '../../../const/CustomFunc';
const { Option } = Select const { Option } = Select
const FormAsignHr = ({ openDialog, closeDialog, toggleDialog, idTask, dataEdit, dataHr, dataCurrentHr, dataRole }) => { const FormAsignHr = ({ openDialog, closeDialog, toggleDialog, idTask, dataEdit, dataHr, dataCurrentHr, dataRole }) => {
const [id, setId] = useState(null) const [id, setId] = useState(null)
const [typeForm, setTypeForm] = useState('add') const [typeForm, setTypeForm] = useState('add')
const [user, setUser] = useState(null) const [user, setUser] = useState(null)
const [rbs, setRbs] = useState("") const [rbs, setRbs] = useState("")
const [projectRole, setProjectRole] = useState(null) const [projectRole, setProjectRole] = useState(null)
const [groupR, setGroupR] = useState("") const [groupR, setGroupR] = useState("")
const [maxUsed, setMaxUsed] = useState("") const [maxUsed, setMaxUsed] = useState("")
const [standartRate, setStandartRate] = useState("") const [standartRate, setStandartRate] = useState("")
const [uomStandartRate, setUomStandartRate] = useState(null) const [uomStandartRate, setUomStandartRate] = useState(null)
const [overTimeRate, setOverTimeRate] = useState("") const [overTimeRate, setOverTimeRate] = useState("")
const [overTimeRateUom, setOverTimeRateUom] = useState(null) const [overTimeRateUom, setOverTimeRateUom] = useState(null)
const [costPerUsed, setCostPerUsed] = useState("") const [costPerUsed, setCostPerUsed] = useState("")
const [accrue, setAccrue] = useState("") const [accrue, setAccrue] = useState("")
const [baseCalender, setBaseCalender] = useState("") const [baseCalender, setBaseCalender] = useState("")
const [listHr, setListHr] = useState([]) const [listHr, setListHr] = useState([])
const [isCustomer, setIsCustomer] = useState(false) const [isCustomer, setIsCustomer] = useState(false)
const handleClearData = () => { const handleClearData = () => {
setUser(null) setUser(null)
setRbs("") setRbs("")
setProjectRole(null) setProjectRole(null)
setGroupR("") setGroupR("")
setMaxUsed("") setMaxUsed("")
setIsCustomer(false) setIsCustomer(false)
setStandartRate("") setStandartRate("")
setUomStandartRate(null) setUomStandartRate(null)
setOverTimeRate("") setOverTimeRate("")
setOverTimeRateUom(null) setOverTimeRateUom(null)
setCostPerUsed("") setCostPerUsed("")
setAccrue("") setAccrue("")
setBaseCalender("") setBaseCalender("")
} }
useEffect(() => { useEffect(() => {
let data = dataHr || [] let data = dataHr || []
let availableHr = [] let availableHr = []
data.map((val, index) => { data.map((val, index) => {
if(dataEdit && dataEdit.user_id){ if(dataEdit && dataEdit.user_id){
if(parseInt(val.id)===parseInt(dataEdit.user_id)){ if(parseInt(val.id)===parseInt(dataEdit.user_id)){
availableHr.push(val); availableHr.push(val);
} }
} }
let check = dataCurrentHr.some(function (x) { let check = dataCurrentHr.some(function (x) {
return parseInt(val.id)==parseInt(x.user_id) return parseInt(val.id)==parseInt(x.user_id)
}); });
if(!check){ if(!check){
availableHr.push(val); availableHr.push(val);
} }
}); });
setListHr(availableHr) setListHr(availableHr)
}, [dataHr, dataCurrentHr, dataEdit]) }, [dataHr, dataCurrentHr, dataEdit])
useEffect(() => { useEffect(() => {
if (idTask && idTask > 0) { if (idTask && idTask > 0) {
if(dataEdit && dataEdit!=""){ if(dataEdit && dataEdit!=""){
setTypeForm('edit') setTypeForm('edit')
setId(dataEdit.id) setId(dataEdit.id)
setUser(dataEdit.user_id) setUser(dataEdit.user_id)
setRbs(dataEdit.rbs) setRbs(dataEdit.rbs)
setProjectRole(dataEdit.project_role) setProjectRole(dataEdit.project_role)
setGroupR(dataEdit.group_r) setGroupR(dataEdit.group_r)
setMaxUsed(dataEdit.max_used ? formatNumber(dataEdit.max_used.toString()) : '') setMaxUsed(dataEdit.max_used ? formatNumber(dataEdit.max_used.toString()) : '')
setIsCustomer(dataEdit.is_customer) setIsCustomer(dataEdit.is_customer)
setStandartRate(dataEdit.standart_rate ? formatNumber(dataEdit.standart_rate.toString()) : '') setStandartRate(dataEdit.standart_rate ? formatNumber(dataEdit.standart_rate.toString()) : '')
setUomStandartRate(dataEdit.uom_standart_rate) setUomStandartRate(dataEdit.uom_standart_rate)
setOverTimeRate(dataEdit.overtime_rate ? formatNumber(dataEdit.overtime_rate.toString()) : '') setOverTimeRate(dataEdit.overtime_rate ? formatNumber(dataEdit.overtime_rate.toString()) : '')
setOverTimeRateUom(dataEdit.uom_overtime_rate) setOverTimeRateUom(dataEdit.uom_overtime_rate)
setCostPerUsed(dataEdit.cost_per_used) setCostPerUsed(dataEdit.cost_per_used)
setAccrue(dataEdit.accrue_at) setAccrue(dataEdit.accrue_at)
setBaseCalender(dataEdit.base_calender) setBaseCalender(dataEdit.base_calender)
}else{ }else{
handleClearData() handleClearData()
setTypeForm('add') setTypeForm('add')
} }
} else { } else {
handleClearData() handleClearData()
} }
}, [openDialog]) }, [openDialog])
const handleSave = () => { const handleSave = () => {
let data = ''; let data = '';
if (typeForm=="edit") { if (typeForm=="edit") {
data = { data = {
id, id,
proyek_id: idTask, proyek_id: idTask,
user_id:user, user_id:user,
project_role:projectRole, project_role:projectRole,
is_customer: isCustomer, is_customer: isCustomer,
max_used:maxUsed.replaceAll(".", ""), max_used:maxUsed.replaceAll(".", ""),
standart_rate:standartRate.replaceAll(".", ""), standart_rate:standartRate.replaceAll(".", ""),
uom_standart_rate:uomStandartRate, uom_standart_rate:uomStandartRate,
overtime_rate:overTimeRate.replaceAll(".", ""), overtime_rate:overTimeRate.replaceAll(".", ""),
uom_overtime_rate:overTimeRateUom, uom_overtime_rate:overTimeRateUom,
} }
closeDialog('edit', data); closeDialog('edit', data);
} else { } else {
data = { data = {
proyek_id: idTask, proyek_id: idTask,
user_id:user, user_id:user,
project_role:projectRole, project_role:projectRole,
is_customer: isCustomer, is_customer: isCustomer,
max_used:maxUsed.replaceAll(".", ""), max_used:maxUsed.replaceAll(".", ""),
standart_rate:standartRate.replaceAll(".", ""), standart_rate:standartRate.replaceAll(".", ""),
uom_standart_rate:uomStandartRate, uom_standart_rate:uomStandartRate,
overtime_rate:overTimeRate.replaceAll(".", ""), overtime_rate:overTimeRate.replaceAll(".", ""),
uom_overtime_rate:overTimeRateUom, uom_overtime_rate:overTimeRateUom,
} }
closeDialog('add', data); closeDialog('add', data);
} }
handleClearData() handleClearData()
} }
const handleCancel = () => { const handleCancel = () => {
closeDialog('cancel', 'none') closeDialog('cancel', 'none')
handleClearData() handleClearData()
} }
const renderForm = () => { const renderForm = () => {
return ( return (
<Form> <Form>
<Row> <Row>
<Col> <Col>
<FormGroup> <FormGroup>
<Label>Human Resource</Label> <Label>Human Resource</Label>
<Select showSearch value={user} onChange={(val) => setUser(val)} placeholder="Select Human Resource" filterOption={(input, option) => <Select showSearch value={user} onChange={(val) => setUser(val)} placeholder="Select Human Resource" filterOption={(input, option) =>
option.children.toLowerCase().indexOf(input.toLowerCase()) >= 0 option.children.toLowerCase().indexOf(input.toLowerCase()) >= 0
} style={{ width: '100%' }}> } style={{ width: '100%' }}>
{listHr && listHr.map(res => ( {listHr && listHr.map(res => (
<Option key={res.id} value={res.id}>{`${res.name}`}</Option> <Option key={res.id} value={res.id}>{`${res.name}`}</Option>
))} ))}
</Select> </Select>
</FormGroup> </FormGroup>
</Col> </Col>
<Col> <Col>
<FormGroup> <FormGroup>
<Label>Role Human Resource</Label> <Label>Role Human Resource</Label>
<Select showSearch value={projectRole} onChange={(val) => setProjectRole(val)} <Select showSearch value={projectRole} onChange={(val) => setProjectRole(val)}
placeholder="Select Role Human Resource" placeholder="Select Role Human Resource"
filterOption={(input, option) => option.children.toLowerCase().indexOf(input.toLowerCase()) >= 0} filterOption={(input, option) => option.children.toLowerCase().indexOf(input.toLowerCase()) >= 0}
tyle={{ width: '100%' }}> tyle={{ width: '100%' }}>
{dataRole && dataRole.map(res => ( {dataRole && dataRole.map(res => (
<Option key={res.id} value={res.id}>{`${res.name}`}</Option> <Option key={res.id} value={res.id}>{`${res.name}`}</Option>
))} ))}
</Select> </Select>
</FormGroup> </FormGroup>
</Col> </Col>
<Col> <Col>
<FormGroup> <FormGroup>
<Label>Percentage Available User</Label> <Label>Percentage Available User</Label>
<Input type="text" onChange={(e) => setMaxUsed(formatNumber(e.target.value))} value={maxUsed} placeholder='' required/> <Input type="text" onChange={(e) => setMaxUsed(formatNumber(e.target.value))} value={maxUsed} placeholder='' required/>
</FormGroup> </FormGroup>
</Col> </Col>
</Row> </Row>
<Row> <Row>
<Col> <Col>
<FormGroup> <FormGroup>
<Label>Customer</Label> <Label>Customer</Label>
<div> <div>
<Select <Select
value={isCustomer} value={isCustomer}
defaultValue={false} defaultValue={false}
style={{ style={{
width: 235, width: 235,
}} }}
onChange={(val) => setIsCustomer(val)} onChange={(val) => setIsCustomer(val)}
options={[ options={[
{ {
value: true, value: true,
label: 'Yes', label: 'Yes',
}, },
{ {
value: false, value: false,
label: 'No', label: 'No',
} }
]} ]}
/> />
</div> </div>
</FormGroup> </FormGroup>
</Col> </Col>
</Row> </Row>
<div style={{widht:"100%",display:"flex",flexDirection:"row",justifyContent:"space-between",alignItems:"center"}}> <div style={{widht:"100%",display:"flex",flexDirection:"row",justifyContent:"space-between",alignItems:"center"}}>
<FormGroup style={{flexBasis:"49%"}}> <FormGroup style={{flexBasis:"49%"}}>
<Label>Standart Rate</Label> <Label>Standart Rate</Label>
<Input type="text" onChange={(e) => setStandartRate(formatNumber(e.target.value))} value={standartRate} placeholder='1.000...' /> <Input type="text" onChange={(e) => setStandartRate(formatNumber(e.target.value))} value={standartRate} placeholder='1.000...' />
</FormGroup> </FormGroup>
<div style={{flexBasis:"2%",height:"100%",display:"flex",justifyContent:"center",alignItems:"center"}}> <div style={{flexBasis:"2%",height:"100%",display:"flex",justifyContent:"center",alignItems:"center"}}>
/ /
</div> </div>
<FormGroup style={{flexBasis:"49%"}}> <FormGroup style={{flexBasis:"49%"}}>
<Label>UOM Standart Rate</Label> <Label>UOM Standart Rate</Label>
<Select value={uomStandartRate} onChange={(val) => setUomStandartRate(val)} style={{ width: '100%' }} placeholder="Select UOM"> <Select value={uomStandartRate} onChange={(val) => setUomStandartRate(val)} style={{ width: '100%' }} placeholder="Select UOM">
<Option value={"Day"}>Day</Option> <Option value={"Day"}>Day</Option>
<Option value={"Hour"}>Hour</Option> <Option value={"Hour"}>Hour</Option>
</Select> </Select>
</FormGroup> </FormGroup>
</div> </div>
<div style={{widht:"100%",display:"flex",flexDirection:"row",justifyContent:"space-between",alignItems:"center"}}> <div style={{widht:"100%",display:"flex",flexDirection:"row",justifyContent:"space-between",alignItems:"center"}}>
<FormGroup style={{flexBasis:"49%"}}> <FormGroup style={{flexBasis:"49%"}}>
<Label>Overtime Rate</Label> <Label>Overtime Rate</Label>
<Input type="text" onChange={(e) => setOverTimeRate(formatNumber(e.target.value))} value={overTimeRate} placeholder='1.000...' /> <Input type="text" onChange={(e) => setOverTimeRate(formatNumber(e.target.value))} value={overTimeRate} placeholder='1.000...' />
</FormGroup> </FormGroup>
<div style={{flexBasis:"2%",height:"100%",display:"flex",justifyContent:"center",alignItems:"center"}}> <div style={{flexBasis:"2%",height:"100%",display:"flex",justifyContent:"center",alignItems:"center"}}>
/ /
</div> </div>
<FormGroup style={{flexBasis:"49%"}}> <FormGroup style={{flexBasis:"49%"}}>
<Label>UOM Overtime Rate</Label> <Label>UOM Overtime Rate</Label>
<Select value={overTimeRateUom} onChange={(val) => setOverTimeRateUom(val)} style={{ width: '100%' }} placeholder="Select UOM"> <Select value={overTimeRateUom} onChange={(val) => setOverTimeRateUom(val)} style={{ width: '100%' }} placeholder="Select UOM">
<Option value={"Day"}>Day</Option> <Option value={"Day"}>Day</Option>
<Option value={"Hour"}>Hour</Option> <Option value={"Hour"}>Hour</Option>
</Select> </Select>
</FormGroup> </FormGroup>
</div> </div>
</Form> </Form>
) )
} }
return ( return (
<> <>
<Modal size="lg" isOpen={openDialog} toggle={toggleDialog}> <Modal size="lg" isOpen={openDialog} toggle={toggleDialog}>
<ModalHeader className="capitalize" toggle={closeDialog}>{typeForm=="add" ? "Add" : "Edit" } Assign Human Resource</ModalHeader> <ModalHeader className="capitalize" toggle={closeDialog}>{typeForm=="add" ? "Add" : "Edit" } Assign Human Resource</ModalHeader>
<ModalBody> <ModalBody>
{renderForm()} {renderForm()}
</ModalBody> </ModalBody>
<ModalFooter> <ModalFooter>
<Button color="primary" onClick={() => handleSave()}>{typeForm=="add" ? "Add" : "Edit" }</Button>{' '} <Button color="primary" onClick={() => handleSave()}>{typeForm=="add" ? "Add" : "Edit" }</Button>{' '}
<Button className="capitalize" color="secondary" onClick={() => handleCancel()}>Cancel</Button> <Button className="capitalize" color="secondary" onClick={() => handleCancel()}>Cancel</Button>
</ModalFooter> </ModalFooter>
</Modal> </Modal>
</> </>
) )
} }
export default FormAsignHr; export default FormAsignHr;

Loading…
Cancel
Save