Commit eb0f3a3c authored by Faisal Hamdi's avatar Faisal Hamdi

Merge branch 'faisal' into 'master'

upload mr fam

See merge request !710
parents 50068e1d 136be28d
......@@ -271,6 +271,7 @@ const create = (type = "") => {
const createMonthlyReportFAM = (body) => api.post('transaction/monthly_report/fam/create_monthly_report', body)
const createMonthlyReportOI = (body) => api.post('transaction/monthly_report_oi/create_monthly_report', body)
const checkUploadMonthlyReportTP = (body) => api.post('transaction/monthly_report_tp/check_import', body)
const checkUploadMonthlyReportFAM = (body) => api.post('transaction/monthly_report/fam/check_import', body)
// MonthlyPL
......@@ -484,6 +485,7 @@ const create = (type = "") => {
getHierarkiMontlyReportLOCF,
getHierarkiMontlyReportFAM,
checkUploadMonthlyReportTP,
checkUploadMonthlyReportFAM,
getMonthlyReport
}
}
......
......@@ -6,6 +6,8 @@ import Images from '../../assets/Images';
import ReactTooltip from 'react-tooltip';
import NumberFormat from 'react-number-format';
import { PropagateLoader } from 'react-spinners';
import UploadFile from '../../library/Upload';
import { ExcelRenderer } from 'react-excel-renderer';
const LightTooltip = withStyles((theme) => ({
tooltip: {
......@@ -41,6 +43,7 @@ export default class FixedAssetsMovementMR extends Component {
dataTable: [],
loading: true
}
this.fileHandler = this.fileHandler.bind(this);
}
componentDidMount() {
......@@ -158,6 +161,92 @@ export default class FixedAssetsMovementMR extends Component {
}
}
fileHandler = (event) => {
let fileObj = event
ExcelRenderer(fileObj, (err, resp) => {
console.log(resp)
if (err) {
console.log(err);
}
else {
let isi = resp.rows.slice(3)
console.log(isi);
let payload = []
let reg = /^[-+]?(?:[0-9]+,)*[0-9]+(?:\.[0-9]+)?$/;
isi.map((i, index) => {
if (i.length > 0) {
payload.push({
item_report_id: i[1] === undefined ? "" : String(i[1]).trim(),
item_report: i[2] === undefined ? "" : String(i[2]).trim(),
mtd_mb: i[3] === undefined ? "0" : reg.test(String(i[3])) === false ? "0" : String(i[3]).trim()
})
}
})
let body = {
company_id: this.props.company.company_id,
periode: this.props.periode,
report_id: this.props.report_id,
fixed_asset_movement: payload,
months: this.props.month.month_id
}
console.log(body)
this.setState({ payload: body, judul: resp.rows[1][0], judulColumn: resp.rows[2] })
}
});
}
checkUpload() {
api.create().checkUploadMonthlyReportFAM(this.state.payload).then(response => {
console.log(JSON.stringify(this.state.payload));
console.log(this.state.payload)
console.log(response)
if (response.data) {
if (response.data.status === 'success') {
this.setState({ visibleUpload: false, loading: true })
// let dataTable = response.data.data.map((item, index) => {
// return [
// item.type_report_id,
// item.item_report_id,
// item.parent,
// item.formula,
// item.level,
// item.item_report,
// item.total_actual_before,
// item.type_report_id == 5 || item.type_report_id == 6 ? { value: item.january, formula: item.january_formula } : Number(item.january).toFixed(1),
// item.type_report_id == 5 || item.type_report_id == 6 ? { value: item.february, formula: item.february_formula } : Number(item.february).toFixed(1),
// item.type_report_id == 5 || item.type_report_id == 6 ? { value: item.march, formula: item.march_formula } : Number(item.march).toFixed(1),
// item.type_report_id == 5 || item.type_report_id == 6 ? { value: item.april, formula: item.april_formula } : Number(item.april).toFixed(1),
// item.type_report_id == 5 || item.type_report_id == 6 ? { value: item.may, formula: item.may_formula } : Number(item.may).toFixed(1),
// item.type_report_id == 5 || item.type_report_id == 6 ? { value: item.june, formula: item.june_formula } : Number(item.june).toFixed(1),
// item.type_report_id == 5 || item.type_report_id == 6 ? { value: item.july, formula: item.july_formula } : Number(item.july).toFixed(1),
// item.type_report_id == 5 || item.type_report_id == 6 ? { value: item.august, formula: item.august_formula } : Number(item.august).toFixed(1),
// item.type_report_id == 5 || item.type_report_id == 6 ? { value: item.september, formula: item.september_formula } : Number(item.september).toFixed(1),
// item.type_report_id == 5 || item.type_report_id == 6 ? { value: item.october, formula: item.october_formula } : Number(item.october).toFixed(1),
// item.type_report_id == 5 || item.type_report_id == 6 ? { value: item.november, formula: item.november_formula } : Number(item.november).toFixed(1),
// item.type_report_id == 5 || item.type_report_id == 6 ? { value: item.december, formula: item.december_formula } : Number(item.december).toFixed(1),
// Number(item.total_current_year).toFixed(1),
// Number(item.total_next_year).toFixed(1),
// Number(item.total_more_year).toFixed(1),
// item.orders,
// item.forecast_formula,
// item.before_formula,
// item.error
// ]
// })
// this.setState({ dataTable, dataLoaded: true, loading: false, buttonError: false, editable: true, saveDraft: true }, () => {
// this.state.dataTable.map(item => {
// if (item[12].length > 0) {
// // console.log('masuk')
// this.setState({ buttonError: true, errorPreview: true, editable: true, saveDraft: true })
// }
// })
// // console.log(this.state.dataTable);
// })
}
}
})
}
backToMonthlyReport(type) {
console.log(this.state.dataTable);
let data = []
......@@ -478,7 +567,7 @@ export default class FixedAssetsMovementMR extends Component {
<span style={{ fontSize: 12, textAlign: 'right' }}>
<NumberFormat
thousandSeparator={true}
style={{ fontSize: 12, textAlign: 'right', borderColor: 'transparent', margin: 0, width: 90, backgroundColor: 'transparent' }}
style={{ fontSize: 12, textAlign: 'right', borderColor: 'transparent', margin: 0, width: 96, backgroundColor: 'transparent' }}
type="text"
placeholder=""
disabled={true}
......@@ -930,7 +1019,7 @@ export default class FixedAssetsMovementMR extends Component {
borderColor: 'transparent',
margin: 5
}}
onClick={() => null}
onClick={() => this.setState({ visibleUpload: true })}
>
<img src={Images.upload} />
</button>
......@@ -1008,7 +1097,8 @@ export default class FixedAssetsMovementMR extends Component {
onClick={() => {
this.setState({ loading: true }, () => {
setTimeout(() => {
this.handleValidate()
this.setState({ loading: false })
// this.handleValidate()
}, 100);
})
}}
......@@ -1068,6 +1158,43 @@ export default class FixedAssetsMovementMR extends Component {
</div>
</Paper>
</div>
{this.state.visibleUpload && (
<div className="test app-popup-show">
<div className="popup-content background-white border-radius" style={{ borderRadius: 8 }}>
<div className="popup-panel grid grid-2x main-color" style={{ height: 64, borderTopRightRadius: 8, borderTopLeftRadius: 8 }}>
<div className="col-1" style={{ maxWidth: "inherit", display: 'flex', alignItems: 'center' }}>
<div className="popup-title">
<span style={{ color: '#fff', fontSize: 16, fontWeight: 'bold' }}>Upload File</span>
</div>
</div>
<div className="col-2 content-right" style={{ maxWidth: "inherit", alignSelf: 'center' }}>
<button
type="button"
className="btn btn-circle btn-white"
onClick={() => this.setState({ visibleUpload: false })}
>
<img src={Images.close} />
</button>
</div>
</div>
<UploadFile
type={this.state.uploadStatus}
percentage={this.state.percentage}
result={this.state.result}
acceptedFiles={["xlsx"]}
onHandle={(dt) => {
this.fileHandler(dt)
this.setState({ uploadStatus: 'idle', percentage: '0' })
}}
onUpload={() => {
String(this.state.judul).includes("MONTHLY REPORT - FIXED ASSETS MOVEMENT") ?
this.checkUpload() :
this.setState({ alert: true, messageAlert: "Invalid Template", tipeAlert: 'warning' })
}}
/>
</div>
</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