Commit bdbad4ac authored by Riri Novita's avatar Riri Novita

formula plmr

parent a71a975e
...@@ -5,6 +5,7 @@ import ReactTooltip from 'react-tooltip'; ...@@ -5,6 +5,7 @@ import ReactTooltip from 'react-tooltip';
import Images from '../../assets/Images'; import Images from '../../assets/Images';
import api from '../../api'; import api from '../../api';
import NumberFormat from 'react-number-format'; import NumberFormat from 'react-number-format';
import * as R from 'ramda';
const LightTooltip = withStyles((theme) => ({ const LightTooltip = withStyles((theme) => ({
tooltip: { tooltip: {
...@@ -98,6 +99,7 @@ export default class ProfitLossMR extends Component { ...@@ -98,6 +99,7 @@ export default class ProfitLossMR extends Component {
item.profit_loss.mtd_vs_previous_month === null ? "0.0" : item.profit_loss.mtd_vs_previous_month === "" ? "0.0" : item.profit_loss.mtd_vs_previous_month, item.profit_loss.mtd_vs_previous_month === null ? "0.0" : item.profit_loss.mtd_vs_previous_month === "" ? "0.0" : item.profit_loss.mtd_vs_previous_month,
item.profit_loss.mtd_vs_mb === null ? "0.0" : item.profit_loss.mtd_vs_mb === "" ? "0.0" : item.profit_loss.mtd_vs_mb, item.profit_loss.mtd_vs_mb === null ? "0.0" : item.profit_loss.mtd_vs_mb === "" ? "0.0" : item.profit_loss.mtd_vs_mb,
item.profit_loss.mtd_vs_rb === null ? "0.0" : item.profit_loss.mtd_vs_rb === "" ? "0.0" : item.profit_loss.mtd_vs_rb, item.profit_loss.mtd_vs_rb === null ? "0.0" : item.profit_loss.mtd_vs_rb === "" ? "0.0" : item.profit_loss.mtd_vs_rb,
item.order
]) ])
} }
if (item.children !== null) { if (item.children !== null) {
...@@ -132,6 +134,7 @@ export default class ProfitLossMR extends Component { ...@@ -132,6 +134,7 @@ export default class ProfitLossMR extends Component {
item.profit_loss.mtd_vs_previous_month === null ? "0.0" : item.profit_loss.mtd_vs_previous_month === "" ? "0.0" : item.profit_loss.mtd_vs_previous_month, item.profit_loss.mtd_vs_previous_month === null ? "0.0" : item.profit_loss.mtd_vs_previous_month === "" ? "0.0" : item.profit_loss.mtd_vs_previous_month,
item.profit_loss.mtd_vs_mb === null ? "0.0" : item.profit_loss.mtd_vs_mb === "" ? "0.0" : item.profit_loss.mtd_vs_mb, item.profit_loss.mtd_vs_mb === null ? "0.0" : item.profit_loss.mtd_vs_mb === "" ? "0.0" : item.profit_loss.mtd_vs_mb,
item.profit_loss.mtd_vs_rb === null ? "0.0" : item.profit_loss.mtd_vs_rb === "" ? "0.0" : item.profit_loss.mtd_vs_rb, item.profit_loss.mtd_vs_rb === null ? "0.0" : item.profit_loss.mtd_vs_rb === "" ? "0.0" : item.profit_loss.mtd_vs_rb,
item.order,
]) ])
if (item.children !== null) { if (item.children !== null) {
if (item.children.length > 0) { if (item.children.length > 0) {
...@@ -146,26 +149,128 @@ export default class ProfitLossMR extends Component { ...@@ -146,26 +149,128 @@ export default class ProfitLossMR extends Component {
}) })
} }
handleValidate() {
// let data = []
// console.log(JSON.stringify(this.state.dataTable))
// this.state.dataTable.map(i => {
// data.push({
// item_report_id: i[1],
// notes: i[6] == null || i[6] == "" ? "" : String(i[6]),
// total_actual_before: String(i[7]),
// january: i[0] === 3 && i[8] === "" ? "0" : String(i[8]),
// february: i[0] === 3 && i[9] === "" ? "0" : String(i[9]),
// march: i[0] === 3 && i[10] === "" ? "0" : String(i[10]),
// april: i[0] === 3 && i[11] === "" ? "0" : String(i[11]),
// may: i[0] === 3 && i[12] === "" ? "0" : String(i[12]),
// june: i[0] === 3 && i[13] === "" ? "0" : String(i[13]),
// july: i[0] === 3 && i[14] === "" ? "0" : String(i[14]),
// august: i[0] === 3 && i[15] === "" ? "0" : String(i[15]),
// september: i[0] === 3 && i[16] === "" ? "0" : String(i[16]),
// october: i[0] === 3 && i[17] === "" ? "0" : String(i[17]),
// november: i[0] === 3 && i[18] === "" ? "0" : String(i[18]),
// december: i[0] === 3 && i[19] === "" ? "0" : String(i[19]),
// total_current_year: i[0] === 3 && i[20] === "" ? "0" : String(i[20]),
// total_next_year: i[0] === 3 && i[21] === "" ? "0" : String(i[21]),
// total_more_year: i[0] === 3 && i[22] === "" ? "0" : String(i[22])
// })
// })
// let payload = {
// "submission_id": this.props.submissionID,
// "company_id": this.props.company.company_id,
// "periode": this.props.periode,
// "report_id": this.props.report_id,
// "profit_loss": data,
// "status": "submitted"
// }
// console.log(payload)
// api.create().validateSubmitReport(payload).then((response) => {
// // console.log(response)
// if (response.data.data.result) {
// this.setState({ loading: false, buttonError: false, editable: false })
// } else {
this.setState({ loading: false, buttonError: true, editable: true })
// }
// })
}
render() { render() {
let dataTable2 = this.state.dataTable let dataTable2 = this.state.dataTable
const handleNotes = (value, tableMeta) => { const handleNotes = (value, tableMeta) => {
console.log(value)
let a = dataTable2[tableMeta.rowIndex][tableMeta.columnIndex] = value let a = dataTable2[tableMeta.rowIndex][tableMeta.columnIndex] = value
console.log(dataTable2[tableMeta.rowIndex]); // console.log(dataTable2[tableMeta.rowIndex]);
} }
const handleChange = (value, tableMeta, indexChilds) => { const handleChange = (value, tableMeta, indexChilds) => {
console.log(dataTable2) console.log(dataTable2)
let val = String(value).split(",").join("") let val = String(value).split(",").join("")
dataTable2[tableMeta.rowIndex][tableMeta.columnIndex] = Number(val) dataTable2[tableMeta.rowIndex][10] = Number(val)
// if (indexChilds == 0) { }
// dataTable2[tableMeta.rowIndex][tableMeta.columnIndex] = Number(val) const handleFormula = (data, tableMeta, month, type) => {
// } let arrayFormula = tableMeta.rowData[3].match(/[a-zA-Z]+|[0-9]+|[-!$%^&*()_+|~=`{}\[\]:";'<>?,.\/]+(?:\.[0-9]+@|)/g)
// else if (indexChilds == 1) { let arrayJumlah = []
// dataTable2[tableMeta.rowIndex][tableMeta.columnIndex] = Number(val) let tambahan = false
// } let opet = ""
// else if (indexChilds == 2) { arrayFormula.map((item, indexs) => {
// dataTable2[tableMeta.rowIndex][tableMeta.columnIndex] = Number(val) if (item == 'X') {
// } tambahan = true
} else if (item == '-' || item == '+' || item == '/' || item == '*') {
arrayJumlah.push(item)
} else {
let index = dataTable2.findIndex((val) => val[22] == item)
if (tambahan) {
if (item == '-' || item == '+' || item == '/' || item == '*') {
opet = item
} else {
arrayJumlah.push(opet == '' ? Number(item) : Number(String(opet + String(item))))
tambahan = false
opet = ""
}
} else {
if (index != -1) {
arrayJumlah.push(dataTable2[index][tableMeta.columnIndex + type])
if (tableMeta.rowData[5] === 'Unit Business/ Brand/ SubCo 1') {
console.log(dataTable2[index][tableMeta.columnIndex + type]);
console.log(arrayJumlah);
}
}
}
}
})
let array = arrayJumlah
let total = 0
let opt = ""
array.map((item, index) => {
if (item == "+") {
opt = "tambah"
} else if (item == "-") {
opt = "kurang"
} else if (item == "*") {
opt = "kali"
} else if (item == "/") {
opt = "bagi"
} else {
if (opt == "tambah") {
total = Number(total) + Number(item)
} else if (opt == "kurang") {
total = Number(total) - Number(item)
} else if (opt == "kali") {
total = Number(total) * Number(item)
} else if (opt == "bagi") {
total = R.equals((Number(total) / Number(item)), NaN) ? '0' : Number(total) / Number(item)
} else {
total += item
}
}
})
let a = dataTable2[tableMeta.rowIndex][tableMeta.columnIndex + type] = Number(total)
return a
} }
let columns = [ let columns = [
{ {
...@@ -296,21 +401,21 @@ export default class ProfitLossMR extends Component { ...@@ -296,21 +401,21 @@ export default class ProfitLossMR extends Component {
{tableMeta.rowData[0] === 4 ? {tableMeta.rowData[0] === 4 ?
null : null :
<div style={{ flex: 1 }}> <div style={{ flex: 1 }}>
<FormControlLabel <FormControlLabel
style={{ margin: 0 }} style={{ margin: 0 }}
value={val} value={val}
control={ control={
<NumberFormat <NumberFormat
thousandSeparator={true} thousandSeparator={true}
style={{ fontSize: 12, textAlign: 'right', borderColor: 'transparent', margin: 0, width: 96, backgroundColor: 'transparent' }} style={{ fontSize: 12, textAlign: 'right', borderColor: 'transparent', margin: 0, width: 96, backgroundColor: 'transparent' }}
type="text" type="text"
placeholder="" placeholder=""
disabled={true} disabled={true}
value={Number(val).toFixed(1)} value={Number(val).toFixed(1)}
/> />
} }
/> />
</div> </div>
} }
</div> </div>
) )
...@@ -354,10 +459,11 @@ export default class ProfitLossMR extends Component { ...@@ -354,10 +459,11 @@ export default class ProfitLossMR extends Component {
<div style={{ textAlign: 'right', width: 90 }}> <div style={{ textAlign: 'right', width: 90 }}>
{tableMeta.rowData[0] === 4 ? {tableMeta.rowData[0] === 4 ?
null : null :
tableMeta.rowData[0] === 6 ?
<div style={{ flex: 1 }}> <div style={{ flex: 1 }}>
<FormControlLabel <FormControlLabel
style={{ margin: 0 }} style={{ margin: 0 }}
value={value} value={tableMeta.rowData[10]}
control={ control={
<NumberFormat <NumberFormat
thousandSeparator={true} thousandSeparator={true}
...@@ -365,7 +471,24 @@ export default class ProfitLossMR extends Component { ...@@ -365,7 +471,24 @@ export default class ProfitLossMR extends Component {
type="text" type="text"
placeholder="" placeholder=""
disabled={true} disabled={true}
value={Number(value).toFixed(1)} value={Number(handleFormula(value, tableMeta, 1, 0)).toFixed(1)}
/>
}
/>
</div>
:
<div style={{ flex: 1 }}>
<FormControlLabel
style={{ margin: 0 }}
value={tableMeta.rowData[8]}
control={
<NumberFormat
thousandSeparator={true}
style={{ fontSize: 12, textAlign: 'right', borderColor: 'transparent', margin: 0, width: 96, backgroundColor: 'transparent' }}
type="text"
placeholder=""
disabled={true}
value={tableMeta.rowData[8]}
/> />
} }
/> />
...@@ -377,10 +500,28 @@ export default class ProfitLossMR extends Component { ...@@ -377,10 +500,28 @@ export default class ProfitLossMR extends Component {
<div style={{ textAlign: 'right', width: 90 }}> <div style={{ textAlign: 'right', width: 90 }}>
{tableMeta.rowData[0] === 4 ? {tableMeta.rowData[0] === 4 ?
null : null :
tableMeta.rowData[0] === 6 ?
<div style={{ flex: 1 }}>
<FormControlLabel
style={{ margin: 0 }}
value={tableMeta.rowData[10]}
control={
<NumberFormat
thousandSeparator={true}
style={{ fontSize: 12, textAlign: 'right', borderColor: 'transparent', margin: 0, width: 96, backgroundColor: 'transparent' }}
type="text"
placeholder=""
disabled={true}
value={Number(handleFormula(value, tableMeta, 1, 1)).toFixed(1)}
/>
}
/>
</div>
:
<div style={{ flex: 1 }}> <div style={{ flex: 1 }}>
<FormControlLabel <FormControlLabel
style={{ margin: 0 }} style={{ margin: 0 }}
value={value} value={tableMeta.rowData[9]}
control={ control={
<NumberFormat <NumberFormat
thousandSeparator={true} thousandSeparator={true}
...@@ -388,7 +529,7 @@ export default class ProfitLossMR extends Component { ...@@ -388,7 +529,7 @@ export default class ProfitLossMR extends Component {
type="text" type="text"
placeholder="" placeholder=""
disabled={true} disabled={true}
value={Number(value).toFixed(1)} value={tableMeta.rowData[9]}
/> />
} }
/> />
...@@ -404,7 +545,7 @@ export default class ProfitLossMR extends Component { ...@@ -404,7 +545,7 @@ export default class ProfitLossMR extends Component {
<div style={{ flex: 1 }}> <div style={{ flex: 1 }}>
<FormControlLabel <FormControlLabel
style={{ margin: 0 }} style={{ margin: 0 }}
value={value} value={tableMeta.rowData[10]}
control={ control={
<NumberFormat <NumberFormat
thousandSeparator={true} thousandSeparator={true}
...@@ -412,7 +553,7 @@ export default class ProfitLossMR extends Component { ...@@ -412,7 +553,7 @@ export default class ProfitLossMR extends Component {
type="text" type="text"
placeholder="" placeholder=""
disabled={true} disabled={true}
value={Number(value).toFixed(1)} value={tableMeta.rowData[10]}
/> />
} }
/> />
...@@ -421,7 +562,7 @@ export default class ProfitLossMR extends Component { ...@@ -421,7 +562,7 @@ export default class ProfitLossMR extends Component {
<div style={{ flex: 1 }}> <div style={{ flex: 1 }}>
<FormControlLabel <FormControlLabel
style={{ margin: 0 }} style={{ margin: 0 }}
value={value} value={tableMeta.rowData[10]}
control={ control={
<NumberFormat <NumberFormat
thousandSeparator={true} thousandSeparator={true}
...@@ -429,7 +570,7 @@ export default class ProfitLossMR extends Component { ...@@ -429,7 +570,7 @@ export default class ProfitLossMR extends Component {
type="text" type="text"
placeholder="" placeholder=""
disabled={true} disabled={true}
value={Number(value).toFixed(1)} value={Number(handleFormula(value, tableMeta, 1, 2)).toFixed(1)}
/> />
} }
/> />
...@@ -440,17 +581,17 @@ export default class ProfitLossMR extends Component { ...@@ -440,17 +581,17 @@ export default class ProfitLossMR extends Component {
<div style={{ flex: 1 }}> <div style={{ flex: 1 }}>
<FormControlLabel <FormControlLabel
style={{ margin: 0 }} style={{ margin: 0 }}
value={value} value={tableMeta.rowData[10]}
control={ control={
<NumberFormat <NumberFormat
thousandSeparator={true} thousandSeparator={true}
style={{ color: "#5198ea", fontSize: 12, textAlign: 'right', borderColor: 'transparent', margin: 0, width: 96, backgroundColor: 'transparent' }} style={{ color: "#5198ea", fontSize: 12, textAlign: 'right', borderColor: 'transparent', margin: 0, width: 96, backgroundColor: 'transparent' }}
type="text" type="text"
placeholder="" placeholder=""
value={Number(value).toFixed(1)} value={tableMeta.rowData[10]}
onBlur={(event) => { onBlur={(event) => {
handleChange(event.target.value, tableMeta, 2) handleChange(event.target.value, tableMeta)
// console.log(dataTable2) console.log(dataTable2)
}} }}
/> />
} }
...@@ -572,7 +713,7 @@ export default class ProfitLossMR extends Component { ...@@ -572,7 +713,7 @@ export default class ProfitLossMR extends Component {
<div style={{ textAlign: 'right', width: 90 }}> <div style={{ textAlign: 'right', width: 90 }}>
{tableMeta.rowData[0] === 4 ? {tableMeta.rowData[0] === 4 ?
null : null :
val tableMeta.rowData[13]
} }
</div> </div>
</div> </div>
...@@ -580,7 +721,7 @@ export default class ProfitLossMR extends Component { ...@@ -580,7 +721,7 @@ export default class ProfitLossMR extends Component {
<div style={{ textAlign: 'right', width: 90 }}> <div style={{ textAlign: 'right', width: 90 }}>
{tableMeta.rowData[0] === 4 ? {tableMeta.rowData[0] === 4 ?
null : null :
val tableMeta.rowData[14]
} }
</div> </div>
</div> </div>
...@@ -592,7 +733,7 @@ export default class ProfitLossMR extends Component { ...@@ -592,7 +733,7 @@ export default class ProfitLossMR extends Component {
<div style={{ textAlign: 'right', width: 90 }}> <div style={{ textAlign: 'right', width: 90 }}>
{tableMeta.rowData[0] === 4 ? {tableMeta.rowData[0] === 4 ?
null : null :
val tableMeta.rowData[15]
} }
</div> </div>
</div> </div>
...@@ -600,7 +741,7 @@ export default class ProfitLossMR extends Component { ...@@ -600,7 +741,7 @@ export default class ProfitLossMR extends Component {
<div style={{ textAlign: 'right', width: 90 }}> <div style={{ textAlign: 'right', width: 90 }}>
{tableMeta.rowData[0] === 4 ? {tableMeta.rowData[0] === 4 ?
null : null :
val tableMeta.rowData[16]
} }
</div> </div>
</div> </div>
...@@ -612,7 +753,7 @@ export default class ProfitLossMR extends Component { ...@@ -612,7 +753,7 @@ export default class ProfitLossMR extends Component {
<div style={{ textAlign: 'right', width: 90 }}> <div style={{ textAlign: 'right', width: 90 }}>
{tableMeta.rowData[0] === 4 ? {tableMeta.rowData[0] === 4 ?
null : null :
val tableMeta.rowData[17]
} }
</div> </div>
</div> </div>
...@@ -620,7 +761,7 @@ export default class ProfitLossMR extends Component { ...@@ -620,7 +761,7 @@ export default class ProfitLossMR extends Component {
<div style={{ textAlign: 'right', width: 90 }}> <div style={{ textAlign: 'right', width: 90 }}>
{tableMeta.rowData[0] === 4 ? {tableMeta.rowData[0] === 4 ?
null : null :
val tableMeta.rowData[18]
} }
</div> </div>
</div> </div>
...@@ -668,7 +809,7 @@ export default class ProfitLossMR extends Component { ...@@ -668,7 +809,7 @@ export default class ProfitLossMR extends Component {
<div style={{ textAlign: 'right', width: 90 }}> <div style={{ textAlign: 'right', width: 90 }}>
{tableMeta.rowData[0] === 4 ? {tableMeta.rowData[0] === 4 ?
null : null :
val tableMeta.rowData[19]
} }
</div> </div>
</div> </div>
...@@ -676,7 +817,7 @@ export default class ProfitLossMR extends Component { ...@@ -676,7 +817,7 @@ export default class ProfitLossMR extends Component {
<div style={{ textAlign: 'right', width: 90 }}> <div style={{ textAlign: 'right', width: 90 }}>
{tableMeta.rowData[0] === 4 ? {tableMeta.rowData[0] === 4 ?
null : null :
val tableMeta.rowData[20]
} }
</div> </div>
</div> </div>
...@@ -684,7 +825,7 @@ export default class ProfitLossMR extends Component { ...@@ -684,7 +825,7 @@ export default class ProfitLossMR extends Component {
<div style={{ textAlign: 'right', width: 90 }}> <div style={{ textAlign: 'right', width: 90 }}>
{tableMeta.rowData[0] === 4 ? {tableMeta.rowData[0] === 4 ?
null : null :
val tableMeta.rowData[21]
} }
</div> </div>
</div> </div>
...@@ -694,6 +835,12 @@ export default class ProfitLossMR extends Component { ...@@ -694,6 +835,12 @@ export default class ProfitLossMR extends Component {
} }
} }
}, },
{
name: "",
options: {
display: false
}
}
] ]
return ( return (
...@@ -794,6 +941,83 @@ export default class ProfitLossMR extends Component { ...@@ -794,6 +941,83 @@ export default class ProfitLossMR extends Component {
</div> </div>
</button> </button>
</div> </div>
<div className="col-2" style={{ display: 'flex', justifyContent: 'flex-end', maxWidth: '100%' }}>
<button
className="button"
type="button"
disabled={this.state.buttonError}
style={{
backgroundColor: 'transparent',
cursor: this.state.buttonError === true ? 'default' : 'pointer',
borderColor: 'transparent',
outline: 'none',
marginRight: 20
}}
onClick={() => {
this.setState({ loading: true, dataTable: dataTable2, buttonDraft: false }, () => {
setTimeout(() => {
this.setState({ loading: false})
// this.handleValidate()
}, 100);
})
}}
>
<div style={{ backgroundColor: '#fff', width: 105, height: 25, borderRadius: 3, justifyContent: 'center', display: 'flex', alignItems: 'center', border: 'solid 1px #354960' }}>
<Typography style={{ fontSize: '11px', color: '#354960', textAlign: 'center' }}>Calculate</Typography>
</div>
</button>
<button
type="button"
style={{
backgroundColor: 'transparent',
cursor: this.state.editable !== true ? 'pointer' : 'default',
borderColor: 'transparent',
outline: 'none',
marginRight: 20
}}
// onClick={() =>
// this.state.editable === true ?
// null :
// this.setState({ loading: true }, () =>
// this.state.handleTekTekTek == 1 ? null :
// this.setState({ handleTekTekTek: 1 }, () => {
// setTimeout(() => {
// this.uploadProfitLoss('draft')
// }, 100);
// })
// )
// }
>
<div style={{ backgroundColor: '#354960', width: 105, height: 25, borderRadius: 3, justifyContent: 'center', display: 'flex', alignItems: 'center' }}>
<Typography style={{ fontSize: '11px', color: '#fff', textAlign: 'center' }}>Save as Draft</Typography>
</div>
</button>
<button
type="button"
style={{
backgroundColor: 'transparent',
cursor: this.state.editable !== true ? 'pointer' : 'default',
borderColor: 'transparent',
outline: 'none',
}}
// onClick={() =>
// this.state.editable === true ?
// null :
// this.setState({ loading: true }, () =>
// this.state.handleTekTekTek == 1 ? null :
// this.setState({ handleTekTekTek: 1 }, () => {
// setTimeout(() => {
// this.uploadProfitLoss('submitted')
// }, 100);
// })
// )
// }
>
<div style={{ backgroundColor: '#354960', width: 105, height: 25, borderRadius: 3, justifyContent: 'center', display: 'flex', alignItems: 'center' }}>
<Typography style={{ fontSize: '11px', color: '#fff', textAlign: 'center' }}>Save & Complete</Typography>
</div>
</button>
</div>
</div> </div>
</Paper> </Paper>
</div> </div>
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment