Commit fe794bbe authored by faisalhamdi's avatar faisalhamdi

FAM MR

parent e2763b47
......@@ -257,6 +257,7 @@ const create = (type = "") => {
const getHierarkiMontlyReportOI = (body) => api.post('transaction/monthly_report_oi/get_report_hierarki', body)
const getHierarkiMontlyReportTP = (body) => api.post('transaction/monthly_report_tp/get_report_hierarki', body)
const getHierarkiMontlyReportLOCF = (body) => api.post('transaction/monthly_report_locf/get_report_hierarki', body)
const getHierarkiMontlyReportFAM = (body) => api.post('transaction/monthly_report/fam/get_report_hierarki', body)
const getLastPeriodMonthly = (idCompany) => api.get(`transaction/monthly_report/get_last_periode/${idCompany}`)
const checkApproverMonthly = () => api.get('transaction/monthly_report/is_approver')
const getCompanySubmittedMonthly = (body) => api.post('transaction/monthly_report/get_company_submitted', body)
......@@ -266,7 +267,7 @@ const create = (type = "") => {
const deleteAttachmentMonthly = (id) => api.post(`transaction/monthly_report/delete_attachment/${id}`)
const createMonthlyReportBS = (body) => api.post('transaction/monthly_report_bs/create_monthly_report', body)
const createMonthlyReportTP = (body) => api.post('transaction/monthly_report_tp/create_monthly_report', body)
const getHierarkiMontlyReportFAM = (body) => api.post('transaction/monthly_report/fam/get_report_hierarki', body)
const createMonthlyReportFAM = (body) => api.post('transaction/monthly_report/fam/create_monthly_report', body)
const checkUploadMonthlyReportTP = (body) => api.post('transaction/monthly_report_tp/check_import', body)
......@@ -407,6 +408,7 @@ const create = (type = "") => {
createMonthlyReportBS,
createMonthlyReportTP,
createMonthlyReportPL,
createMonthlyReportFAM,
getSubmission,
checkUploadMB,
getAllOperatingInd,
......
import React, { Component } from 'react';
import { Typography, Paper, createMuiTheme, MuiThemeProvider, TableCell, Tooltip, withStyles } from '@material-ui/core';
import { createMuiTheme, FormControlLabel, MuiThemeProvider, Paper, TableCell, Tooltip, Typography, withStyles } from '@material-ui/core';
import MUIDataTable from 'mui-datatables';
import api from '../../api';
import Images from '../../assets/Images';
import ReactTooltip from 'react-tooltip';
import NumberFormat from 'react-number-format';
const LightTooltip = withStyles((theme) => ({
tooltip: {
......@@ -109,7 +110,7 @@ export default class FixedAssetsMovementMR extends Component {
item.fixed_asset_movement.act_vs_mb_percent === "" ? "0.0" : item.fixed_asset_movement.act_vs_mb_percent,
item.fixed_asset_movement.act_vs_rb_amount === "" ? "0.0" : item.fixed_asset_movement.act_vs_rb_amount,
item.fixed_asset_movement.act_vs_rb_percent === "" ? "0.0" : item.fixed_asset_movement.act_vs_rb_percent,
item.ordert_vs_rb_percent === "" ? "0.0" : item.fixed_asset_movement.act_vs_rb_percent,
item.fixed_asset_movement.ordert_vs_rb_percent === "" ? "0.0" : item.fixed_asset_movement.act_vs_rb_percent,
item.order
])
if (item.children !== null) {
......@@ -121,14 +122,103 @@ export default class FixedAssetsMovementMR extends Component {
}
})
console.log(dataTable);
this.setState({ dataTable, loading: false, buttonError: true, editable: true })
this.setState({ dataTable, loading: false })
}
})
}
downloadTemplate = async () => {
let res = await fetch(
`https://tia.eksad.com/tia-reporting-dev/public/transaction/monthly_report/fam/download_template?report_id=${this.props.report_id}&&company_id=${this.props.company.company_id}&&year=${this.props.periode}`
)
res = await res.blob()
console.log(res);
if (res.size > 0) {
let url = window.URL.createObjectURL(res);
let a = document.createElement('a');
a.href = url;
a.download = 'Template Monthly Report Fixed Assets Movement.xlsx'
a.click();
}
}
async downloadAllData() {
let url = `https://tia.eksad.com/tia-reporting-dev/public/transaction/monthly_report/fam/export_monthly_report?monthly_report_id=${this.props.monthlyReportId}&&report_id=${this.props.report_id}&&company_id=${this.props.company.company_id}&&year=${this.props.periode}&&revision=${this.props.revision}&&months=${this.props.month.month_id}`
console.log(url);
let res = await fetch(
`https://tia.eksad.com/tia-reporting-dev/public/transaction/monthly_report_bs/export_monthly_report?monthly_report_id=${this.props.monthlyReportId === null ? "" : this.props.monthlyReportId}&&report_id=${this.props.report_id}&&company_id=${this.props.company.company_id}&&year=${this.props.periode}&&revision=${this.props.revision}&&months=${this.props.month.month_id}`
)
if (res.size > 0) {
let url = window.URL.createObjectURL(res);
let a = document.createElement('a');
a.href = url;
a.download = 'Monthly Report Fixed Assets Movement.xlsx';
a.click();
}
}
backToMonthlyReport(type) {
console.log(this.state.dataTable);
let data = []
this.state.dataTable.map(i => {
data.push({
item_report_id: i[1],
mtd_mb: String(Number(i[6]).toFixed(1)),
mtd_rb: String(Number(i[7]).toFixed(1)),
mtd_actual: String(Number(i[8]).toFixed(1)),
act_previous_month: String(Number(i[9]).toFixed(1)),
act_vs_prev_month_amount: String(Number(i[10]).toFixed(1)),
act_vs_prev_month_percent: String(Number(i[11]).toFixed(1)),
act_vs_mb_amount: String(Number(i[12]).toFixed(1)),
act_vs_mb_percent: String(Number(i[13]).toFixed(1)),
act_vs_rb_amount: String(Number(i[14]).toFixed(1)),
act_vs_rb_percent: String(Number(i[15]).toFixed(1))
})
})
let payload = {
"monthly_report_id": this.props.submissionID,
"company_id": this.props.company.company_id,
"periode": this.props.periode,
"report_id": this.props.report_id,
"status": type,
"months": this.props.month.month_id,
"fixed_asset_movement": data
}
api.create('UPLOAD').createMonthlyReportFAM(payload).then(response => {
console.log(response);
if (response.data) {
if (response.data.status === "success") {
this.props.saveToMonthlyReport()
} else {
this.setState({ loading: false }, () => {
this.props.saveToMonthlyReport()
})
}
} else {
this.setState({ dataTable, loading: false, buttonError: true, editable: true })
this.setState({ loading: false }, () => {
this.getSubmission()
document.body.style.overflow = 'unset';
})
}
})
}
render() {
let dataTable2 = this.state.dataTable
const handleValueFormula = (data, type) => {
let total = 0
dataTable2.map((item, index) => {
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])
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
}
let columns = [
{
name: "",
......@@ -222,15 +312,60 @@ export default class FixedAssetsMovementMR extends Component {
</th>
),
setCellProps: () => ({ style2 }),
customBodyRender: (val, tableMeta, updateValue) => {
customBodyRender: (value, tableMeta, updateValue) => {
return (
<div>
<div className="grid grid-3x content-center">
<div className="col-1">
<div style={{ textAlign: 'right', width: 90 }}>
{tableMeta.rowData[0] === 1 ?
{tableMeta.rowData[0] === 1 || tableMeta.rowData[0] === 4 ?
null :
tableMeta.rowData[6]
tableMeta.rowData[0] === 3 ?
<div style={{ flex: 1 }}>
<FormControlLabel
style={{ margin: 0 }}
value={value}
control={
<NumberFormat
thousandSeparator={true}
style={{ fontSize: 12, textAlign: 'right', borderColor: 'transparent', margin: 0, width: 90, backgroundColor: 'transparent' }}
type="text"
placeholder=""
disabled={true}
value={Number(tableMeta.rowData[7]).toFixed(1)}
/>
}
/>
</div> :
tableMeta.rowData[0] === 5 ?
<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(handleValueFormula(tableMeta, 0)).toFixed(1)}
/>
</span>
:
tableMeta.rowData[0] === 4 ?
null
:
tableMeta.rowData[0] === 6 ?
<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, 0)).toFixed(1)}
/>
:
tableMeta.rowData[0] === 1 ?
null
:
null
}
</div>
</div>
......@@ -465,7 +600,7 @@ export default class FixedAssetsMovementMR extends Component {
borderColor: 'transparent',
margin: 5
}}
onClick={() => null}
onClick={() => this.downloadTemplate() }
>
<img src={Images.template} />
</button>
......@@ -493,7 +628,12 @@ export default class FixedAssetsMovementMR extends Component {
borderColor: 'transparent',
margin: 5
}}
onClick={() => null}
onClick={() =>
this.setState({ loading: true }, () => {
setTimeout(() => {
this.downloadAllData()
}, 100);
})}
>
<img src={Images.download} />
</button>
......
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