Commit e6998687 authored by Rifka Kurnia's avatar Rifka Kurnia

Merge branch 'rifka' into 'master'

create bs rolling outlook

See merge request !1243
parents 747ac531 74f6bf31
......@@ -243,6 +243,7 @@ const create = (type = "") => {
// Rolling Outlook
const getRollingOutlookID = (body) => api.post('transaction/rolling_outlook/get_rolling_outlook_id', body)
const getRollingOutlookBS = (body) => api.post('transaction/balance_sheet/rolling_outlook/get_report_hierarki', body)
const createRollingOutlookBS = (body) => api.post('transaction/balance_sheet/rolling_outlook/create_rolling_outlook', body)
const getRollingOutlookPL = (body) => api.post('transaction/profit_loss/rolling_outlook/get_report_hierarki', body)
......@@ -695,6 +696,7 @@ const create = (type = "") => {
getHierarkiCronJobMRRatio,
getRollingOutlookID,
getRollingOutlookBS,
createRollingOutlookBS,
getAllMasterDataCat,
getParentItemReport,
saveMasterDataCat,
......
......@@ -54,6 +54,7 @@ export default class BalanceSheetRO extends Component {
componentDidMount() {
this.getItemHierarki()
console.log(this.props.isApprover)
console.log(this.state.get_for)
}
getItemHierarki() {
......@@ -144,7 +145,7 @@ export default class BalanceSheetRO extends Component {
}
}
})
// console.log(dataTable)
console.log(dataTable)
this.setState({ dataTable, loading: false, buttonError: true, editable: true })
} else {
this.setState({ loading: false, alert: true, messageAlert: response.data.message, tipeAlert: 'warning' }, () => {
......@@ -197,6 +198,7 @@ export default class BalanceSheetRO extends Component {
}
handleGetFor(type) {
console.log(type)
this.setState({get_for: type}, () => {
// this.getSettingControl()
// this.getLatestUpdate()
......@@ -204,8 +206,453 @@ export default class BalanceSheetRO extends Component {
})
}
backToRollingOutlook(type) {
this.setState({ loading: true })
let data = []
this.state.dataTable.map(i => {
data.push({
"item_report_id": i[1],
"total_december_last_year": String(Number(i[6]).toFixed(1)),
"january": String(Number(i[7]).toFixed(1)),
"february": String(Number(i[8]).toFixed(1)),
"march": String(Number(i[9]).toFixed(1)),
"april": String(Number(i[10]).toFixed(1)),
"may": String(Number(i[11]).toFixed(1)),
"june": String(Number(i[12]).toFixed(1)),
"july": String(Number(i[13]).toFixed(1)),
"august": String(Number(i[14]).toFixed(1)),
"september": String(Number(i[15]).toFixed(1)),
"october": String(Number(i[16]).toFixed(1)),
"november": String(Number(i[17]).toFixed(1)),
"december": String(Number(i[18]).toFixed(1)),
"total_december_year": String(Number(i[19]).toFixed(1))
})
})
let payload = {
"rolling_outlook_id": this.props.rollingOutlookID,
"company_id": this.props.company.company_id,
"periode": this.props.periode,
"report_id": this.props.report_id,
// "months": this.props.month.month_id,
"months": 0,
"status": type,
"balance_sheet": data
}
api.create('UPLOAD').createRollingOutlookBS(payload).then(response => {
console.log(payload);
console.log(response);
// console.log(JSON.stringify(payload))
if (response.data) {
if (response.data.status === "success") {
if (type == 'submitted') {
// this.props.saveToMonthlyReport('BS')
this.props.onClickClose()
} else {
// this.props.saveToMonthlyReport()
this.props.onClickClose()
}
} else {
this.setState({ loading: false, handleTekTekTek: 0 }, () => {
// this.props.saveToMonthlyReport()
this.props.onClickClose()
})
}
} else {
this.setState({ loading: false, handleTekTekTek: 0 })
}
})
}
handleValidate() {
let data = []
let err = false
let errorContrl = false
let editAble = this.state.editAble
let dataTable = this.state.dataTable
let kansas = this.state.kansas
console.log(dataTable[dataTable.length-1])
// dataTable.map((i, index) => {
// if(i[0] === 3) {
// if ( i[18] === "" && (Number(i[14]) < this.state.minValue || Number(i[14]) > this.state.maxValue)) {
// console.log('msk 2');
// err = true
// }
// }
// if (String(i[5]) == "Control (should be nil)") {
// if (Number(i[9]) < this.state.minValue || Number(i[9]) > this.state.maxValue ) {
// errorContrl = true
// editAble = true
// }
// }
// data.push({
// "item_report_id": i[1],
// "rolling_outlook": i[6],
// "master_budget": i[7],
// "rolling_budget": i[8],
// "actual": i[9],
// "actual_previous_month": i[10],
// "amount_act_vs_previous_month": i[11],
// "percent_act_vs_previous_month": i[12],
// "amount_act_vs_mb": i[13],
// "percent_act_vs_mb": i[14],
// "amount_act_vs_rb": i[15],
// "percent_act_vs_rb": i[16],
// "mtd_vs_previous_month": i[17],
// "mtd_vs_mb": i[18],
// "mtd_vs_rb": i[19]
// })
// })
// let payload = {
// "monthly_report_id": this.props.monthlyReportId,
// "company_id": this.props.company.company_id,
// "periode": this.props.periode,
// "report_id": this.props.report_id,
// "status": "submitted",
// "months": this.props.month.month_id,
// "balance_sheet": data
// }
// api.create().validateSubmitReportBS(payload).then((response) => {
// console.log(response.data.data.result)
// console.log(err);
// console.log(errorContrl);
// if (response.data) {
// if (response.data.status === "success") {
// if (response.data.data.result && err === false && errorContrl === false ) {
this.setState({ loading: false, buttonError: false, editable: false, saveDraft: false })
// if (kansas == 0) {
// this.setState({kansas: 1, loading: true}, () => {
// this.handleValidate()
// })
// } else {
// this.setState({kansas: 0})
// }
// } else {
// this.setState({ loading: false, buttonError: true, editable: true, saveDraft: false })
// if (kansas == 0) {
// this.setState({kansas: 1, loading: true}, () => {
// this.handleValidate()
// })
// } else {
// this.setState({kansas: 0})
// }
// }
// } else {
// this.setState({ alert: true, messageAlert: response.data.message, tipeAlert: 'warning', loading: false }, () => {
// if (response.data.message.includes("Someone Logged In")) {
// setTimeout(() => {
// localStorage.removeItem(Constant.TOKEN)
// window.location.reload();
// }, 1000);
// }
// })
// }
// } else {
// this.setState({ alert: true, messageAlert: response.problem, tipeAlert: 'error', loading: false })
// }
// })
}
closeAlert() {
this.setState({ alert: false })
}
render() {
let dataTable2 = this.state.dataTable
const handleChange = (value, tableMeta, type) => {
let val = String(value).split(",").join("")
if (type === "actual") {
console.log('masuk')
dataTable2[tableMeta.rowIndex][tableMeta.columnIndex] = Number(val).toFixed(1)
} else {
console.log('masuk2')
let indexParent = dataTable2.findIndex((val) => val[1] === dataTable2[tableMeta.rowIndex][2])
if (indexParent > 0) {
// console.log(indexParent)
let a = 0
if (type == 'r/e') {
// console.log('masuk8')
a = dataTable2[tableMeta.rowIndex][tableMeta.columnIndex].value = Number(val).toFixed(1)
} else {
// console.log('masuk9')
a = dataTable2[tableMeta.rowIndex][tableMeta.columnIndex] = Number(val).toFixed(1)
}
let jagain = dataTable2[indexParent][tableMeta.columnIndex]
a = dataTable2[indexParent][tableMeta.columnIndex] = jagain === undefined ? (0 + Number(val)).toFixed(1) : Number(jagain + Number(val)).toFixed(1)
} else {
// console.log('masuk3')
if (type == 'r/e') {
// console.log('masuk4')
dataTable2[tableMeta.rowIndex][tableMeta.columnIndex].value = Number(val).toFixed(1)
} else {
// console.log('masuk5')
dataTable2[tableMeta.rowIndex][tableMeta.columnIndex] = Number(val).toFixed(1)
}
}
}
}
const handleValue = (data, type) => {
let total = 0
dataTable2.map((item, index) => {
// if (item[2] !== null) {
if (data.rowData[1] === item[2]) {
// let itemVal = item[data.columnIndex + type].value !== undefined ? Number(item[data.columnIndex + type].value) : Number(item[data.columnIndex + type])
let itemVal = Number(item[data.columnIndex + type])
total = item[data.columnIndex + type] === undefined ? Number(total) + 0 : Number(total) + itemVal
}
// }
})
let indexParent = dataTable2.findIndex((val) => val[1] === dataTable2[data.rowIndex][2])
dataTable2[data.rowIndex][data.columnIndex + type] = Number(total).toFixed(1)
// console.log(indexParent);
return total
}
const handleValueFormula = (tableMeta, colIdx) => {
// loading = true
let splitFormula = String(tableMeta.rowData[3]).split(/([()@])/)
let baru = []
let anjay = []
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)
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))
}
}
})
baru.map((item, index) => {
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]', '')
// let indexID = dataTable2.findIndex((val) => val[21] == tst)
let data = tableMeta.rowData[20] == null? [] : tableMeta.rowData[20]
let indexID = data.findIndex((val) => val.item_formula == String(`${item}`))
if (indexID !== -1) {
let valuezz = data[indexID].value
anjay.push(valuezz == "" ? 0 : valuezz)
}
} else {
let data = tableMeta.rowData[20] == null? [] : tableMeta.rowData[20]
let indexID = data.findIndex((val) => val.item_formula == String(`@${item}`))
if (indexID !== -1) {
// console.log(tableMeta)
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 = dataTable2.findIndex((val) => val[21] == tst)
if (indexID !== -1) {
let valuezz = dataTable2[indexID][10]
if (item == dataTable2[tableMeta.rowIndex][21]) {
anjay.push(0)
} else {
anjay.push(valuezz == "" ? 0 : valuezz)
}
}
} else {
console.log("masuk formula")
console.log(dataTable2)
let indexID = dataTable2.findIndex((val) => val[20] == item)
if (indexID !== -1) {
let valuezz = dataTable2[indexID][colIdx]
if (item == dataTable2[tableMeta.rowIndex][20]) {
anjay.push(0)
} else {
anjay.push(valuezz == "" ? 0 : valuezz)
}
} else {
if (item === '(-1)') {
anjay.push(-1)
}
}
}
}
}
})
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
let optPrev = ""
anjay2.map((item, index) => {
if (Array.isArray(item)) {
prio = true
optPrev = opt
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) {
if (optPrev == "tambah") {
total = Number(total) + Number(totalPrio)
} else if (optPrev == "kurang") {
total = Number(total) - Number(totalPrio)
} else if (optPrev == "kali") {
total = Number(total) * Number(totalPrio)
} else if (optPrev == "bagi") {
total = Number(total) / Number(totalPrio) == NaN ? 0 : Number(total) / Number(totalPrio)
} else {
total += Number(totalPrio)
}
prio = false
totalPrio = 0
optPrio = ""
}
} else if (item == "-") {
opt = "kurang"
if (prio) {
if (optPrev == "tambah") {
total = Number(total) + Number(totalPrio)
} else if (optPrev == "kurang") {
total = Number(total) - Number(totalPrio)
} else if (optPrev == "kali") {
total = Number(total) * Number(totalPrio)
} else if (optPrev == "bagi") {
total = Number(total) / Number(totalPrio) == NaN ? 0 : Number(total) / Number(totalPrio)
} else {
total += Number(totalPrio)
}
prio = false
totalPrio = 0
optPrio = ""
}
} else if (item == "*") {
opt = "kali"
if (prio) {
if (optPrev == "tambah") {
total = Number(total) + Number(totalPrio)
} else if (optPrev == "kurang") {
total = Number(total) - Number(totalPrio)
} else if (optPrev == "kali") {
total = Number(total) * Number(totalPrio)
} else if (optPrev == "bagi") {
total = Number(total) / Number(totalPrio) == NaN ? 0 : Number(total) / Number(totalPrio)
} else {
total += Number(totalPrio)
}
prio = false
totalPrio = 0
optPrio = ""
}
} else if (item == "/") {
opt = "bagi"
if (prio) {
if (optPrev == "tambah") {
total = Number(total) + Number(totalPrio)
} else if (optPrev == "kurang") {
total = Number(total) - Number(totalPrio)
} else if (optPrev == "kali") {
total = Number(total) * Number(totalPrio)
} else if (optPrev == "bagi") {
total = Number(total) / Number(totalPrio) == NaN ? 0 : Number(total) / Number(totalPrio)
} else {
total += Number(totalPrio)
}
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)
}
}
}
})
total = R.equals(total, NaN) ? "0.0" : total
dataTable2[tableMeta.rowIndex][colIdx] = total
return total
}
let columns = [
{
name: "",
......@@ -295,22 +742,108 @@ export default class BalanceSheetRO extends Component {
value={Number(val).toFixed(1)}
/>
:
<div style={{ flex: 1 }}>
<FormControlLabel
style={{ margin: 0 }}
value={val}
control={
<NumberFormat
thousandSeparator={true}
style={{ fontSize: 12, textAlign: 'right', borderColor: 'transparent', margin: 0, width: 96, backgroundColor: 'transparent' }}
type="text"
placeholder=""
disabled={true}
value={Number(val).toFixed(1)}
tableMeta.rowData[0] === 2 ?
<span style={{ fontSize: 12, textAlign: 'right' }}>
<NumberFormat
thousandSeparator={true}
style={{ fontSize: 12, textAlign: 'right', borderColor: 'transparent', margin: 0, width: 96, backgroundColor: 'transparent' }}
type="text"
placeholder=""
disabled={true}
value={Number(handleValue(tableMeta, 0)).toFixed(1)}
/>
</span>
:
tableMeta.rowData[0] === 3 ?
<div style={{ flex: 1 }}>
<FormControlLabel
style={{ margin: 0 }}
value={val}
control={
<NumberFormat
thousandSeparator={true}
style={{ color: "#5198ea", fontSize: 12, textAlign: 'right', borderColor: 'transparent', margin: 0, width: 96, backgroundColor: 'transparent' }}
type="text"
placeholder=""
// disabled={this.props.isApprover? true : (this.state.get_for == 'view'? true : false)}
disabled={false}
value={Number(val).toFixed(1)}
onBlur={(event) => {
handleChange(event.target.value, tableMeta)
}}
/>
}
/>
}
/>
</div>
</div> :
tableMeta.rowData[0] === 5 || tableMeta.rowData[0] === 6 ?
<div style={{ flex: 1 }}>
<FormControlLabel
style={{ margin: 0 }}
value={val}
control={
<NumberFormat
thousandSeparator={true}
style={{ fontSize: 12, textAlign: 'right', borderColor: 'transparent', margin: 0, width: 96, backgroundColor: 'transparent' }}
type="text"
placeholder=""
disabled={true}
value={Number(handleValueFormula(tableMeta, 6)).toFixed(1)}
/>
}
/>
</div> :
// tableMeta.rowData[0] === 7 ?
// (Number(handleValueFormula(tableMeta, 7)).toFixed(1) >= Number(this.state.minValue) && Number(handleValueFormula(tableMeta, 7)).toFixed(1) <= Number(this.state.maxValue)) ?
// <NumberFormat
// thousandSeparator={true}
// style={{
// fontSize: 12,
// textAlign: 'right',
// borderColor: 'transparent',
// margin: 0,
// width: 96,
// backgroundColor: 'transparent'
// }}
// type="text"
// placeholder=""
// disabled={true}
// value={Number(handleValueFormula(tableMeta, 7)).toFixed(1)}
// /> :
// <LightTooltip title={this.state.minValue === null ? `Value Should be ${tableMeta.rowData[23]}` : `Value Should be (${this.state.minValue}) up to (${this.state.maxValue})`} arrow>
// <NumberFormat
// thousandSeparator={true}
// style={{
// fontSize: 12,
// textAlign: 'right',
// borderColor: 'transparent',
// margin: 0,
// width: 96,
// backgroundColor: 'transparent',
// color: 'red'
// }}
// type="text"
// placeholder=""
// disabled={true}
// value={Number(handleValueFormula(tableMeta, 7)).toFixed(1)}
// />
// </LightTooltip>
// :
<div style={{ flex: 1 }}>
<FormControlLabel
style={{ margin: 0 }}
value={val}
control={
<NumberFormat
thousandSeparator={true}
style={{ fontSize: 12, textAlign: 'right', borderColor: 'transparent', margin: 0, width: 96, backgroundColor: 'transparent' }}
type="text"
placeholder=""
disabled={true}
value={Number(val).toFixed(1)}
/>
}
/>
</div>
}
</div>
)
......@@ -921,6 +1454,11 @@ export default class BalanceSheetRO extends Component {
<div className={"main-color"} style={{ height: 78, flex: 1, display: 'flex', alignItems: 'center', paddingLeft: 20 }}>
<Typography style={{ fontSize: '16px', color: 'white' }}>Rolling Outlook & Revision CAT</Typography>
</div>
<Snackbar open={this.state.alert} autoHideDuration={6000} onClose={() => this.closeAlert()}>
<Alert onClose={() => this.closeAlert()} severity={this.state.tipeAlert}>
{this.state.messageAlert}
</Alert>
</Snackbar>
<div style={{ flex: 1, padding: 20, width: '100%' }}>
<Paper style={{ paddingTop: 10, paddingBottom: 20 }}>
<div style={{ borderBottom: 'solid 1px #c4c4c4' }} >
......@@ -1110,7 +1648,7 @@ export default class BalanceSheetRO extends Component {
:
this.state.handleTekTekTek == 1 ? null :
this.setState({ handleTekTekTek: 1, loading: true }, () => {
this.backToMonthlyReport('draft')
this.backToRollingOutlook('draft')
})
}
>
......@@ -1127,7 +1665,7 @@ export default class BalanceSheetRO extends Component {
:
this.state.handleTekTekTek == 1 ? null :
this.setState({ handleTekTekTek: 1 }, () => {
this.backToMonthlyReport('submitted')
this.backToRollingOutlook('submitted')
})}
style={{
backgroundColor: 'transparent',
......
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