Commit 72839e64 authored by d.arizona's avatar d.arizona

update CF

parent bf35abb2
......@@ -288,6 +288,7 @@ const create = (type = "") => {
const createMonthlyReportFAM = (body) => api.post('transaction/fam/monthly_report/create_monthly_report', body)
const createMonthlyReportOI = (body) => api.post('transaction/operating_indicator/monthly_report/create_monthly_report', body)
const createMonthlyReportCAT = (body) => api.post('transaction/cat/monthly_report/create_monthly_report', body)
const createMonthlyReportCF = (body) => api.post('transaction/cash_flow/monthly_report/create_monthly_report', body)
// const checkUploadMonthlyReportTP = (body) => api.post('transaction/monthly_report_tp/check_import', body)
const checkUploadMonthlyReportTP = (body) => api.post('transaction/tax_planning/monthly_report/check_import', body)
const checkUploadMonthlyReportFAM = (body) => api.post('transaction/fam/monthly_report/check_import', body)
......@@ -568,7 +569,8 @@ const create = (type = "") => {
createPeriodeRevisionMonthly,
getListUserSubcoMB,
getListUserSubcoMR,
validateSubmitReportFAM
validateSubmitReportFAM,
createMonthlyReportCF
}
}
......
......@@ -69,7 +69,8 @@ export default class MonthlyReport extends Component {
selectedStatus: [],
detailRevisiCheck: [],
isApprovedMB: false,
textRevision: ''
textRevision: '',
dbCF: []
}
this.myRef = React.createRef()
this.fileHandler = this.fileHandler.bind(this);
......@@ -599,6 +600,7 @@ export default class MonthlyReport extends Component {
// // console.log(this.state.lastStatus);
this.historyApproval()
this.getLatestPeriodSubmit()
this.getCashFlow()
// this.getReport()
// this.getReportAttachment()
api.create().checkApproverMonthly().then(response => {
......@@ -991,10 +993,366 @@ export default class MonthlyReport extends Component {
if (type == 'revision') {
api.create().createPeriodeRevisionMonthly(payload).then((res))
}
if (type == "approve") {
this.createCashFlow()
}
this.getMonthlyReportID()
})
}
getCashFlow() {
let payload = {
"report_id": 13,
"revision": Number(this.state.lastRevision),
"periode": this.state.periode.periode,
"company_id": this.state.company.company_id,
"monthly_report_id": this.state.monthlyReportId,
"months": this.state.month.month_id,
"get_for": "edit"
}
api.create().getHierarkiMontlyReportCF(payload).then(response => {
console.log(response);
let dataTable = []
if (response.data) {
let res = response.data.data
const handlePushChild = (item) => {
let indexIDzz = dataTable.findIndex((val) => val[1] === item.id)
if (indexIDzz === -1) {
dataTable.push([
item.type_report_id,
item.id,
item.parent,
item.formula,
item.level,
item.description,
{ value: item.cash_flow.actual, formula: item.cash_flow.actual_formula },
item.order,
false
])
}
if (item.children !== null) {
if (item.children.length > 0) {
item.children.map((items, indexs) => {
handlePushChild(items)
})
}
}
}
res.map((item, index) => {
dataTable.push([
item.type_report_id,
item.id,
item.parent,
item.formula,
item.level,
item.description,
{ value: item.cash_flow.actual, formula: item.cash_flow.actual_formula },
item.order,
false
])
if (item.children !== null) {
if (item.children.length > 0) {
item.children.map((items, indexs) => {
handlePushChild(items)
})
}
}
})
console.log(dataTable)
this.setState({ dbCF: dataTable, loading: false }, () => {
this.olahDataCashFlow(this.state.dbCF)
})
}
})
}
handleValueFormula = (item, indexS) => {
// loading = true
// console.log(tableMeta);
// "@44[M-1]#BS"
let dbCF = this.state.dbCF
let splitFormula = String(item[3]).split(/([()@])/)
let baru = []
let anjay = []
// console.log(splitFormula);
splitFormula.map((item, index) => {
let items = String(item).substr(Number(String(item).length) - 1, 1)
let subForm = String(item).substr(0, Number(String(item).length) - 1)
// console.log(item);
// console.log(items);
// console.log(subForm);
let re = /^[a-zA-Z0-9_]+$/;
if (item !== "") {
if (items == ']') {
baru.push(String(item))
} else if (!re.test(items)) {
baru.push(subForm)
baru.push(items)
} else {
baru.push(String(item))
}
}
})
// console.log(baru);
let tambahan = false
let opet = ""
let itung2x = ''
baru.map((item, index) => {
if (item == 'X') {
tambahan = true
} else if (item == '-' || item == '+' || item == '/' || item == '*' || item == '(' || item == ')') {
anjay.push(item)
} else {
if (String(item).includes('#')) {
if (String(item).includes('[M-1]')) {
let tst = '@' + String(item).replace('[M-1]', '[M1]')
// console.log(dbCF[tableMeta.rowIndex]);
// console.log(tableMeta);
// console.log(tst);
let indexID = dbCF[indexS][6].formula.findIndex((val) => val.item_formula == tst)
// console.log(indexID);
if (indexID !== -1) {
let valuezz = dbCF[indexS][6].formula[indexID].value
anjay.push(valuezz == "" ? 0 : valuezz)
// console.log(valuezz);
}
} else {
let data = dbCF[indexS][6].formula == null? [] : dbCF[indexS][6].formula
// console.log(data)
let indexID = data.findIndex((val) => val.item_formula == String(`@${item}`))
if (indexID !== -1) {
let valuezz = data[indexID].value
anjay.push(valuezz == "" ? 0 : valuezz)
}
}
} else {
if (String(item).includes('[M-1]')) {
let tst = String(item).replace('[M-1]', '')
let indexID = dbCF.findIndex((val) => val[7] == tst)
if (indexID !== -1) {
let valuezz = dbCF[indexID][8]
anjay.push(valuezz == "" ? 0 : valuezz)
}
} else {
let indexID = dbCF.findIndex((val) => val[7] == item)
if (item == 'X-1') {
anjay.push(-1)
} else if (tambahan) {
if (item == '-' || item == '+' || item == '/' || item == '*') {
opet = item
} else {
anjay.push(opet == ''? Number(item) : Number(String(opet + String(item))))
tambahan = false
opet = ""
}
} else {
if (indexID !== -1) {
let valuezz = dbCF[indexID][6].value
if (item == dbCF[indexS][7]) {
anjay.push(0)
} else {
anjay.push(valuezz == "" ? 0 : valuezz)
}
} else {
if (item === '(-1)') {
anjay.push(-1)
}
}
}
}
}
}
})
// console.log(item[5])
// console.log(splitFormula)
// console.log(baru)
// console.log(anjay)
let anjay2 = []
let kurung = false
let item1 = []
anjay.map((item, index) => {
if (item == "(") {
kurung = true
} else if (item == ")") {
kurung = false
anjay2.push(item1)
item1 = []
} else {
if (kurung) {
item1.push(item)
} else {
anjay2.push(item)
}
}
})
let total = 0
let opt = ""
let totalPrio = 0
let optPrio = ""
let prio = false
anjay2.map((item, index) => {
if (Array.isArray(item)) {
prio = true
item.map((items, indexs) => {
if (items == "+") {
optPrio = "tambah"
} else if (items == "-") {
optPrio = "kurang"
} else if (items == "*") {
optPrio = "kali"
} else if (items == "/") {
optPrio = "bagi"
} else {
if (optPrio == "tambah") {
totalPrio = Number(totalPrio) + Number(items)
} else if (optPrio == "kurang") {
totalPrio = Number(totalPrio) - Number(items)
} else if (optPrio == "kali") {
totalPrio = Number(totalPrio) * Number(items)
} else if (optPrio == "bagi") {
totalPrio = Number(totalPrio) / Number(items) == NaN ? 0 : Number(totalPrio) / Number(items)
} else {
totalPrio += Number(items)
}
}
})
if (index == anjay2.length - 1) {
if (opt == "tambah") {
total = Number(total) + Number(totalPrio)
} else if (opt == "kurang") {
total = Number(total) - Number(totalPrio)
} else if (opt == "kali") {
total = Number(total) * Number(totalPrio)
} else if (opt == "bagi") {
total = Number(total) / Number(totalPrio) == NaN ? 0 : Number(total) / Number(totalPrio)
} else {
total += Number(totalPrio)
}
}
} else {
if (item == "+") {
opt = "tambah"
if (prio) {
total = Number(Number(totalPrio) + Number(total))
prio = false
totalPrio = 0
optPrio = ""
}
} else if (item == "-") {
opt = "kurang"
if (prio) {
total = Number(Number(totalPrio) + Number(total))
prio = false
totalPrio = 0
optPrio = ""
}
} else if (item == "*") {
opt = "kali"
if (prio) {
total = Number(Number(totalPrio) + Number(total))
prio = false
totalPrio = 0
optPrio = ""
}
} else if (item == "/") {
opt = "bagi"
if (prio) {
total = Number(Number(totalPrio) + Number(total))
prio = false
totalPrio = 0
optPrio = ""
}
} 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 = Number(total) / Number(item) == NaN ? 0 : Number(total) / Number(item)
} else {
total += Number(item)
}
}
}
})
// dataTable2[tableMeta.rowIndex][6].value = total
return total
}
olahDataCashFlow(dbCF) {
dbCF.map((item,index) => {
if(item[0] == 5 || item[0] == 6) {
item[6].value = this.handleValueFormula(item,index)
}
})
// console.log(dbCF)
this.setState({dbCF}, () => {
this.payloadCF()
})
}
payloadCF() {
let listCF = []
this.state.dbCF.map((item,index) => {
if (item[6].value == "" || item[6].value == 0 || item[6].value == "0.0") {
item[6].value = this.handleValueFormula(item,index)
listCF.push({
"item_report_id": item[1],
"actual": item[0] == 1? "" : Number(item[6].value).toFixed(1)
})
} else {
listCF.push({
"item_report_id": item[1],
"actual": item[0] == 1? "" : Number(item[6].value).toFixed(1)
})
}
})
// console.log(listCF)
this.setState({dbCF: listCF})
}
createCashFlow() {
let payload = {
"monthly_report_id": this.state.monthlyReportId,
"company_id": this.state.company.company_id,
"periode": this.state.periode.periode,
"report_id": 13,
"status": "submitted",
"months": this.state.month.month_id,
"cash_flow": this.state.dbCF
}
api.create().createMonthlyReportCF(payload).then((res) => {
console.log(res)
// if (response.data) {
// if (response.data.status === "success") {
// this.props.saveToMonthlyReport()
// } else {
// this.setState({ loading: false }, () => {
// this.props.saveToMonthlyReport()
// })
// }
// } else {
// this.setState({ loading: false }, () => {
// // this.getSubmission()
// document.body.style.overflow = 'unset';
// })
// }
})
}
render() {
const columns = ["#", "Report Type",
{
......
......@@ -492,7 +492,7 @@ export default class CashFlowMR extends Component {
type="text"
placeholder=""
disabled={true}
value={Number(handleValueFormula(tableMeta, 6)).toFixed(1)}
value={this.props.status == 'approved'? Number(tableMeta.rowData[6].value) : Number(handleValueFormula(tableMeta, 6)).toFixed(1)}
/>
</span>
:
......@@ -522,7 +522,7 @@ export default class CashFlowMR extends Component {
type="text"
placeholder=""
disabled={true}
value={Number(handleValueFormula(tableMeta, 6)).toFixed(1)}
value={this.props.status == 'approved'? Number(tableMeta.rowData[6].value) :Number(handleValueFormula(tableMeta, 6)).toFixed(1)}
/> :
<LightTooltip title={this.state.minValue === null ? null : `Value Should be (${this.state.minValue}) up to (${this.state.maxValue})`} arrow>
<NumberFormat
......@@ -539,7 +539,7 @@ export default class CashFlowMR extends Component {
type="text"
placeholder=""
disabled={true}
value={Number(handleValueFormula(tableMeta, 6)).toFixed(1)}
value={this.props.status == 'approved'? Number(tableMeta.rowData[6].value) :Number(handleValueFormula(tableMeta, 6)).toFixed(1)}
/>
</LightTooltip>
: null}
......
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