Commit e288c640 authored by Riri Novita's avatar Riri Novita

chcm

parent 61b9db66
......@@ -492,6 +492,8 @@ const create = (type = "") => {
const getDetailDocument = (id) => api.get(`document/get_document_by_id/${id}`)
const deleteDocument = (id) => api.post(`document/delete_document/${id}`)
const uploadCarfmDocument = (body) => api.post('document/upload_cafrm_document', body)
const getChcmDocumentBySubmenu = (body) => api.post('document/get_chcm_document_by_submenu', body);
const uploadChcmDocument = (body) => api.post('document/upload_chcm_document', body)
// Monitoring
......@@ -673,6 +675,8 @@ const create = (type = "") => {
getAllDocument,
uploadDocument,
uploadCarfmDocument,
getChcmDocumentBySubmenu,
uploadChcmDocument,
updateDocument,
downloadDocument,
getPerusahaanUserActive,
......
......@@ -149,7 +149,7 @@ export default class CafrmDocument extends Component {
let compActive = []
let userCompActive = []
this.state.userCompany.map((item, index) => {
if (index !== -1 && String(data[index].status).toLocaleLowerCase() == 'active'){
if (index !== -1 && String(data[index]?.status).toLocaleLowerCase() == 'active'){
userCompActive.push(item)
}
})
......
import React, { Component } from 'react'
import { withStyles } from '@material-ui/core/styles';
import { Paper, Snackbar, Typography } from '@material-ui/core';
import MuiAlert from '@material-ui/lab/Alert';
import Constant from '../../library/Constant';
import Images from '../../assets/Images';
import ReactTooltip from 'react-tooltip';
import api from '../../api';
import PropagateLoader from "react-spinners/PropagateLoader"
import TableChcmDocument from "./TableChcmDocument";
import CreateChcmDoc from "./CreateChcmDocument";
const Alert = withStyles({})((props) => <MuiAlert elevation={6} variant="filled" {...props} />);
export default class ChcmDocument extends Component {
constructor(props) {
super(props);
this.state = {
alert: false,
listData: [],
id: 0,
load: false,
name: '',
userCompActive: [],
submenu_id : 0,
submenu_name: "",
menu_title: "",
loading: false
}
}
componentDidMount() {
this.getMenuName();
}
getMenuName(){
api.create().getMenuByUser().then(
response => {
if(response.data){
if(response.data.status === 'success'){
response.data.data.map(
(item) => {
let arr = window.location.href.split('/');
if (item.class_id == arr.slice(-1)[0]){
this.setState({
submenu_id : item.menu_id,
submenu_name : item.menu_name.toLowerCase(),
menu_title : item.menu_name.replace(/\b\w/g, c => c.toUpperCase())
}, () => {
this.getPermission(this.state.submenu_name)
// this.getDataCarfm();
this.getDetailUser();
})
}
}
)
}
}
}
)
}
// getDataCarfm(create){
// let payload = {
// submenu_id : this.state.submenu_id
// }
// api.create().getCarfmDocumentBySubmenu(payload).then(
// response => {
// if(response){
// if(response.data.status === 'success'){
// let dataList = []
// response.data.data.map((item, index) => {
// dataList.push(item)
// })
// this.setState({
// listData: dataList,
// refresh: create == undefined ? '' : create,
// loading: false
// })
// } else {
// this.setState({ alert: true, messageAlert: response.data.message, tipeAlert: 'warning', loading: false }, () => {
// if (response.data.message.includes("Someone Logged In") || response.data.message.includes("Token Expired")) {
// setTimeout(() => {
// localStorage.removeItem(Constant.TOKEN)
// window.location.reload();
// }, 1000);
// }
// })
// }
// }else {
// this.setState({ alert: true, messageAlert: response.problem, tipeAlert: 'error', loading: false })
// }
// }
// )
// }
getPermission(subMenu) {
let payload = {
menu: subMenu
}
api.create().getPermission(payload).then(response => {
if (response.data) {
console.log(`status get permission ${response.data.status}`);
if (response.data.status === "success") {
this.setState({
btncreate: response.data.data.create,
btnview: response.data.data.view,
btndownload: response.data.data.download,
load: true,
})
console.log("btn create " + this.state.btncreate);
} else {
this.setState({
load: true
})
}
} else {
this.setState({ load: true })
}
})
}
getDetailUser() {
let userId = localStorage.getItem(Constant.USER)
api.create().getDetailUser(userId).then((response) => {
if (response.data) {
if (response.ok) {
if (response.data.status === 'success') {
this.setState({ userCompany: response.data.data.company, visibleTrue: false }, () => {
this.getCompanyActive()
// console.log(this.state.userCompany);
})
}
}
}
})
}
getCompanyActive() {
api.create().getPerusahaanActive().then((response) => {
console.log("getcompanyactive start");
// console.log(response.data.data);
console.log("getcompanyactive stop");
if (response.data) {
if (response.data.status === 'success') {
let data = response.data.data
let compActive = []
let userCompActive = []
this.state.userCompany.map((item, index) => {
if (index !== -1 && String(data[index]?.status).toLocaleLowerCase() == 'active'){
userCompActive.push(item)
}
})
data.map(( item, index ) => {
if (String(item.status).toLocaleLowerCase() == 'active') {
compActive.push(item)
}
})
if (compActive.length == userCompActive.length){
this.setState({ btnadd: true})
} else {
this.setState({ btnadd: false})
}
this.setState({ userCompActive, visibleTrue: true })
console.log("usercompactive")
// console.log(userCompActive)
} else {
this.setState({ alert: true, messageAlert: response.data.message, tipeAlert: 'warning', visibleTrue: true }, () => {
if (response.data.message.includes("Someone Logged In") || response.data.message.includes("Token Expired")) {
setTimeout(() => {
localStorage.removeItem(Constant.TOKEN)
window.location.reload();
}, 1000);
}
})
}
} else {
console.log("error di getcompany active")
this.setState({ alert: true, messageAlert: response.problem, tipeAlert: 'error', listCompany: null, company: null, visibleTrue: true })
}
})
}
createDocument(payload) { //upload apinya disini
this.setState({ loading: true, visibleTrue: false })
api.create().uploadChcmDocument(payload).then(response => {
// console.log(response)
if (response.data) {
if (response.ok) {
if (response.data.message === "Data was Saved Successfully") {
console.log("tes123");
this.setState({ visibleCreate: false, visibleTrue: true, loading: false, alert: true, messageAlert: response.data.message, tipeAlert: 'success'}, () => {
// window.location.reload();
})
// this.getDataCarfm('create')
}
else {
this.setState({ visibleCreate: false, visibleTrue: true, alert: true, messageAlert: response.data.message, tipeAlert: 'warning', loading: false }, () => {
if (response.data.message.includes("Someone Logged In") || response.data.message.includes("Token Expired")) {
setTimeout(() => {
localStorage.removeItem(Constant.TOKEN)
window.location.reload();
}, 1000);
}
})
}
} else {
this.setState({ visibleCreate: false, visibleTrue: true, alert: true, messageAlert: response.data.message, tipeAlert: 'error', loading: false })
}
} else {
this.setState({ visibleCreate: false, visibleTrue: true, alert: true, messageAlert: response.problem, tipeAlert: 'error', loading: false })
}
})
}
closeAlert() {
this.setState({alert: false})
}
handleLoading(tipe) {
this.setState({loading: tipe == 0 ? false : true})
}
render() {
const loadingComponent = (
<div style={{
position: 'absolute',
zIndex: 1500,
top: 0,
left: 0,
width: '100%',
height: '100%',
display: 'flex',
justifyContent: 'center',
alignItems: 'center',
background: 'rgba(255,255,255,0.8)'
}}>
<PropagateLoader
// css={override}
size={20}
color={"#274B80"}
loading={this.state.loading}
/>
</div>
);
return (
<div style={{height: this.props.height, backgroundColor: '#f8f8f8'}}>
<Snackbar open={this.state.alert} autoHideDuration={6000} onClose={() => this.closeAlert()}>
<Alert onClose={() => this.closeAlert()} severity={this.state.tipeAlert}>
{this.state.messageAlert}
</Alert>
</Snackbar>
<div className={"main-color"} style={{ height: 78, display: 'flex', alignItems: 'center', paddingLeft: 20 }}>
<Typography style={{ fontSize: '16px', color: 'white' }}>{this.state.menu_title}</Typography>
</div>
<div style={{padding: 20}}>
{this.state.loading && loadingComponent}
{this.state.btnview && (
<Paper style={{padding: 20}}>
<div style={{display: 'flex', justifyContent: 'flex-end'}}>
{/* {console.log("renderbtn" + this.state.btncreate)} */}
{(this.state.btncreate) && (
<span>
<a data-tip={'Add'} data-for="add">
<div style={{display: 'grid', justifyContent: 'flex-end'}}>
<button
type="button"
onClick={() => this.setState({visibleCreate: true, refresh: ''})}
style={{marginRight: 25, background: 'transparent'}}
>
<img src={Images.add}/>
</button>
</div>
</a>
<ReactTooltip border={true} id="add" place="bottom" type="light" effect="solid"/>
</span>
)}
</div>
<div style={{display: 'flex'}}>
{this.state.visibleTrue && (
<TableChcmDocument
data={this.state.listData}
refresh={this.state.refresh}
load={this.state.load}
userCompActive={this.state.userCompActive}
handleLoading={this.handleLoading.bind(this)}
name={this.state.name}
submenu_id={this.state.submenu_id}
btndownload = {this.state.btndownload}
/>)}
</div>
</Paper>
)}
</div>
{this.state.visibleCreate && (
<CreateChcmDoc
onClickClose={() => this.setState({ visibleCreate: false })}
// getDataDocument={this.getDataDocument.bind(this)}
createDocument={this.createDocument.bind(this)}
handleLoading={this.handleLoading.bind(this)}
submenu_id={this.state.submenu_id}
menuName={this.state.menu_title}
/>
)}
</div>
);
}
}
import React, { Component } from 'react'
import Images from '../../assets/Images'
import { TextField, withStyles, Snackbar } from '@material-ui/core'
import MuiAlert from '@material-ui/lab/Alert';
import api from '../../api'
import Autocomplete from '@material-ui/lab/Autocomplete'
import Constant from '../../library/Constant'
import { format } from 'date-fns';
import UploadFile from "../../library/Upload";
import { ExcelRenderer } from 'react-excel-renderer';
import * as R from 'ramda'
import PropagateLoader from "react-spinners/PropagateLoader"
const Alert = withStyles({
})((props) => <MuiAlert elevation={6} variant="filled" {...props} />);
export default class CreateChcmDoc extends Component {
constructor(props) {
super(props)
this.state = {
perusahaan: null,
perusahaanData: null,
getPerusahaan: null,
errorPerusahaan: false,
msgErrorPerusahaan: '',
document: null,
documentData: null,
getDocument: null,
errorDocument: false,
msgErrorDocument: '',
listPeriode: null,
periode: null,
errorPeriode: false,
msgErrorPeriode: '',
listMonth: null,
monthId: null,
errorMonth: false,
msgErrorMonth: '',
description: '',
errorDesc: false,
msgErrorDesc: '',
file: null,
alert: false,
tipeAlert: '',
messageAlert: '',
fileType: '',
docId: '',
sizeUpload: "1",
isClickSave: 0
}
}
componentDidMount() {
this.getDataCompany()
this.getPeriode()
this.getMonth()
this.getFileSize()
}
getFileSize() {
let body = {
group: 'MAX_FILE_SIZE',
company_id: 0,
type: 'MAX_FILE_SIZE'
}
api.create().getAllSettingByType(body).then(response => {
// console.log(response);
if (response.data) {
if (response.data.status === "success") {
if (response.data.data.length == 0) {
this.setState({
sizeUpload: "1"
})
} else {
this.setState({
sizeUpload: response.data.data[0].value
})
}
// sizeUpload: response.data.data[0] ? response.data.data[0].value === undefined ? "1" : response.data.data[0].value : "1"
} else {
this.setState({ alert: true, messageAlert: response.data.message, tipeAlert: 'warning', loading: false }, () => {
if (response.data.message.includes("Someone Logged In") || response.data.message.includes("Token Expired")) {
setTimeout(() => {
localStorage.removeItem(Constant.TOKEN)
window.location.reload();
}, 1000);
}
})
}
}
})
}
getDataCompany() {
api.create().getPerusahaanUserActive().then((response) => {
if (response.data) {
if (response.data.status == 'success') {
let data = response.data.data
let typeData = data.map((item) => {
return {
company_id: item.company_id,
company_name: item.company_name
}
})
// typeData.push({
// company_id: 0,
// company_name: 'Default'
// })
let typeProps = {
options: typeData.sort((a, b) => a.company_name - b.company_name),
getOptionLabel: (option) => option.company_name,
};
this.setState({ perusahaan: typeProps })
} else {
this.setState({ alert: true, messageAlert: response.data.message, tipeAlert: 'warning' }, () => {
if (response.data.message.includes("Someone Logged In") || response.data.message.includes("Token Expired")) {
setTimeout(() => {
localStorage.removeItem(Constant.TOKEN)
window.location.reload();
}, 1000);
}
})
}
} else {
this.setState({ alert: true, messageAlert: response.problem, tipeAlert: 'error' })
}
})
}
getPeriode() {
api.create().getPeriodeTransaction().then(response => {
let dateNow = new Date
let year = format(dateNow, 'yyyy')
if (response.data) {
if (response.data.status === "success") {
let data = response.data.data
let periodeData = data.map((item) => {
return {
periode: item,
}
})
let defaultProps = {
options: periodeData,
getOptionLabel: (option) => option.periode,
};
let index = data.sort((a, b) => a - b).findIndex((val) => val == year)
this.setState({ listPeriode: defaultProps, periode: index == -1 ? periodeData[0] : periodeData[index] })
} else {
this.setState({ alert: true, messageAlert: response.data.message, tipeAlert: 'warning', loading: false }, () => {
if (response.data.message.includes("Someone Logged In") || response.data.message.includes("Token Expired")) {
setTimeout(() => {
localStorage.removeItem(Constant.TOKEN)
window.location.reload();
}, 1000);
}
})
}
}
})
}
getMonth() {
api.create().getMonthTransaction().then(response => {
let dateNow = new Date
// let bulan = format(dateNow, 'MMMM')
if (response.data) {
if (response.data.status === "success") {
let data = response.data.data
let monthData = data.map((item) => {
return {
month_id: item.month_id,
month_name: item.month_name
}
})
let defaultProps = {
options: monthData,
getOptionLabel: (option) => option.month_name,
};
// let index = data.sort((a, b) => a - b).findIndex((val) => val == bulan)
// this.setState({ listMonth: defaultProps, month: index == -1 ? monthData[0] : monthData[index] })
this.setState({ listMonth: defaultProps })
} else {
this.setState({ alert: true, messageAlert: response.data.message, tipeAlert: 'warning', loading: false }, () => {
if (response.data.message.includes("Someone Logged In") || response.data.message.includes("Token Expired")) {
setTimeout(() => {
localStorage.removeItem(Constant.TOKEN)
window.location.reload();
}, 1000);
}
})
}
}
})
}
clearMessage() {
this.setState({
errorPerusahaan: false,
msgErrorPerusahaan: '',
errorDocument: false,
msgErrorDocument: '',
errorMonth: false,
msgErrorMonth: '',
errorPeriode: false,
msgErrorPeriode: '',
})
}
fileHandler = (event) => {
let fileObj = event
let length = event.name.split(".").length
let fileType = event.name.split(".")[length - 1]
if (fileType === 'zip' || 'rar') {
this.setState({ file: event, fileType: String(fileType) })
} else {
ExcelRenderer(fileObj, (err, resp) => {
// console.log(fileType)
if (err) {
// console.log(err);
}
else {
this.setState({ file: event, fileType: String(fileType) })
}
})
}
}
validasi() {
if (R.isNil(this.state.getPerusahaan)) {
this.setState({ errorPerusahaan: true, msgErrorPerusahaan: 'Company Cannot be Empty', saveDisable: false })
}else if (R.isNil(this.state.periode)) {
this.setState({ errorPeriode: true, msgErrorPeriode: 'Period Cannot be Empty', saveDisable: false })
} else if (R.isNil(this.state.monthId)) {
this.setState({ errorMonth: true, msgErrorMonth: 'Month Cannot be Empty', saveDisable: false })
}
else if (R.isNil(this.state.file)) {
this.setState({ alert: true, messageAlert: 'File Cannot be Empty', tipeAlert: 'warning', saveDisable: false })
} else {
console.log(this.state.isClickSave + " ===> di luar");
const formData = new FormData();
formData.append("file", this.state.file);
formData.append("companyId", this.state.getPerusahaan.company_id);
formData.append("submenuId", this.props.submenu_id);
formData.append("description", this.state.description);
formData.append("extension", this.state.fileType);
formData.append("documentPeriode", this.state.periode.periode);
formData.append("documentMonth", this.state.monthId.month_id);
this.setState({ formData }, () => {
this.props.createDocument(this.state.formData)
})
}
}
deleteFile(e) {
this.setState({ file: null })
}
closeAlert() {
this.setState({ alert: false })
}
render() {
const loadingComponent = (
<div style={{ position: 'absolute', zIndex: 110, top: 0, left: 0, width: '100%', height: '100%', display: 'flex', justifyContent: 'center', alignItems: 'center', background: 'rgba(255,255,255,0.8)' }}>
<PropagateLoader
// css={override}
size={20}
color={"#274B80"}
loading={this.state.loading}
/>
</div>
);
return (
<div>
<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' }}>Create</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.props.onClickClose()}
>
<img src={Images.close} />
</button>
</div>
</div>
<div className="grid grid-2x grid-mobile-none gap-15px" style={{ paddingLeft: 20, paddingRight: 20, paddingTop: 20 }}>
<div className="column-1">
<div style={{ padding: 10, borderRadius: 5 }}>
<Autocomplete
{...this.state.perusahaan}
// debug
clearOnEscape
id="tipe"
onChange={(event, newInputValue) => this.setState({ getPerusahaan: newInputValue }, () => this.clearMessage())}
renderInput={(params) =>
<TextField {...params}
error={this.state.errorPerusahaan}
helperText={this.state.msgErrorPerusahaan}
InputProps={{ ...params.InputProps, style: { fontSize: 11 } }}
InputLabelProps={{ style: { fontSize: 11, color: '#7e8085' } }}
label="Company Name" />}
value={this.state.getPerusahaan}
/>
</div>
</div>
<div className="column-2">
<div style={{ padding: 10, borderRadius: 5, marginTop: "1.2em" }}>
<TextField
value={this.props.menuName}
InputProps={{ style: { fontSize: 11 } }}
InputLabelProps={{ style: { fontSize: 11, color: '#7e8085' } }}
placeholder="Category"
disabled
size="medium"
fullWidth={true}
/>
</div>
</div>
<div className="column-1">
<div style={{ padding: 10, borderRadius: 5 }}>
<Autocomplete
{...this.state.listMonth}
// debug
clearOnEscape
id="month"
onChange={(event, newInputValue) => this.setState({ monthId: newInputValue }, () => this.clearMessage())}
style={{ width: 250 }}
renderInput={(params) =>
<TextField {...params} label="Period Month" margin="normal" style={{ marginTop: 7 }}
InputProps={{ ...params.InputProps, style: { fontSize: 11 } }}
InputLabelProps={{ style: { fontSize: 11, color: '#7e8085' } }}
error={this.state.errorMonth}
helperText={this.state.msgErrorMonth}
/>}
value={this.state.monthId}
/>
</div>
</div>
<div className="column-2">
<div style={{ padding: 10, borderRadius: 5 }}>
<Autocomplete
{...this.state.listPeriode}
// debug
clearOnEscape
id="periode"
onChange={(event, newInputValue) => this.setState({ periode: newInputValue }, () => this.clearMessage())}
style={{ width: 250 }}
renderInput={(params) =>
<TextField {...params} label="Period Year" margin="normal" style={{ marginTop: 7 }}
InputProps={{ ...params.InputProps, style: { fontSize: 11 } }}
InputLabelProps={{ style: { fontSize: 11, color: '#7e8085' } }}
error={this.state.errorPeriode}
helperText={this.state.msgErrorPeriode}
/>}
value={this.state.periode}
/>
</div>
</div>
</div>
<div style={{ paddingLeft: 30, paddingRight: 30, paddingTop: 10 }}>
<UploadFile
type={this.state.uploadStatus}
percentage={this.state.percentage}
result={this.state.result}
acceptedFiles={["xls", "xlsx", "pdf", "PDF", "docx", "doc", "pptx", "ppt", "ods", "odf", "txt", "csv", "zip", "rar"]}
intent={"management"}
onHandle={(dt) => {
this.fileHandler(dt)
this.setState({ uploadStatus: 'idle', percentage: '0' })
}}
onDelete={(e) => {
this.deleteFile(e)
}}
onUpload={() => alert('sukses')}
sizeUpload={Number(this.state.sizeUpload)}
/>
</div>
<div className="margin-top-10px" style={{ paddingLeft: 30, paddingRight: 30, borderRadius: 5, paddingBottom: 20 }}>
<TextField
style={{ width: '100%' }}
id="description"
label="Description"
value={this.state.decription}
inputProps={{
min: 0,
style: {
fontSize: 11
}
}}
InputLabelProps={{
style: {
fontSize: 11,
color: '#7e8085'
}
}}
name="Description"
onChange={(e) => {
this.setState({
description: e.target.value
})
this.clearMessage()
}}
error={this.state.errorDesc}
helperText={this.state.msgErrorDesc}
>
</TextField>
</div>
<div className="border-top grid grid-2x" style={{ height: 56, backgroundColor: '#f5f5f5', paddingLeft: 20, paddingRight: 20 }}>
<div className="column-1" style={{ alignSelf: 'center' }}>
<button
type="button"
onClick={() => this.props.onClickClose()}
>
<div style={{ width: 102, height: 30, border: 'solid 1px #354960', borderRadius: 5, alignItems: 'center', display: 'flex', justifyContent: 'center' }}>
<span style={{ color: '#354960', fontSize: 11 }}>Cancel</span>
</div>
</button>
</div>
<div className="column-2" style={{ display: 'flex', justifyContent: 'flex-end', alignItems: 'center' }}>
{!this.state.saveDisable && <button
disabled={this.state.saveDisable}
type="button"
onClick={() =>
this.state.isClickSave == 1 ? null :
this.setState({ isClickSave: 1 }, () => {
this.validasi()
})
}
>
<div style={{ width: 102, height: 30, backgroundColor: '#354960', borderRadius: 5, alignItems: 'center', display: 'flex', justifyContent: 'center' }}>
<span style={{ color: '#fff', fontSize: 11 }}>Save</span>
</div>
</button>}
</div>
</div>
</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>
</div>
)
}
}
import React, {Component} from 'react';
import api from "../../api";
import Constant from "../../library/Constant";
import Images from "../../assets/Images";
import ReactTooltip from "react-tooltip";
import PropagateLoader from "react-spinners/PropagateLoader";
import {createMuiTheme, MuiThemeProvider, Snackbar} from "@material-ui/core";
import MUIDataTable from "mui-datatables";
import {withStyles} from "@material-ui/core/styles";
import MuiAlert from "@material-ui/lab/Alert";
var ct = require("../../library/CustomTable");
const getMuiTheme = () => createMuiTheme(ct.customTable());
const options = ct.customOptionsManagementDocument();
const Alert = withStyles({
})((props) => <MuiAlert elevation={6} variant="filled" {...props} />);
export default class TableChcmDocument extends Component {
constructor(props) {
super(props)
this.state = {
dataTable: [],
visibleCreate: false,
refresh: '',
alert: false,
}
}
componentDidMount() {
this.getData()
}
componentWillReceiveProps(props) {
// console.log(props);
const {refresh} = this.props;
if (props.refresh !== refresh) {
this.getData()
}
}
getData() {
let payload = {
"submenu_id": this.props.submenu_id
}
this.setState({ loading: true })
api.create().getChcmDocumentBySubmenu(payload).then(response => {
// console.log("table document carfm");
console.log(response)
// console.log("table document carfm stop")
if (response.data) {
if (response.ok) {
if (response.data.status == 'success') {
let dataTable = []
response.data.data.map((item, index) => {
let indexId = this.props.userCompActive.findIndex((val) => val == item.company_id)
if (indexId !== -1) {
dataTable.push( [
index,
item.document_name,
item.description,
item.company_name,
item.document_month,
item.document_periode,
item.document_type,
String(Number(item.document_size) / 1000 + ' KB'),
item.created_by,
item.created_at,
item.values
])
}
})
let docPath = response.data.data.map((item) => {
return [
item.document_filepath
]
})
let docId = response.data.data.map((item) => {
return [
item.document_id
]
})
// console.log(dataTable)
this.setState({ dataTable, docPath, docId, loading: false })
} else {
this.setState({ alert: true, messageAlert: response.data.message, tipeAlert: 'warning', loading: false }, () => {
if (response.data.message.includes("Someone Logged In") || response.data.message.includes("Token Expired")) {
setTimeout(() => {
localStorage.removeItem(Constant.TOKEN)
window.location.reload();
}, 1000);
}
})
}
} else {
console.log("error di table document getcarfm 1");
this.setState({ alert: true, messageAlert: response.data.message, tipeAlert: 'error', loading: false })
}
} else {
console.log("error di table document getcarfm 2");
this.setState({ alert: true, messageAlert: response.problem, tipeAlert: 'error', loading: false })
}
})
}
openPopUp = async (index, val, type) =>{
// console.log(index)
if (type === 'download') {
let res = await fetch(
`${process.env.REACT_APP_URL_MAIN_BE}/public/document/download_chcm_document?documentName=`+this.state.docPath[val]+"&&fileType="+index[6]
)
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 = (String(index[3]).includes(":") ? String(index[3]).replace(":", " (") + ` )` : String(index[3])) +" - "+index[4]+" - "+index[5]+" - "+index[10]+"."+index[6];
a.click();
}
}
}
closeAlert() {
this.setState({ alert: false })
}
render() {
let columns = [{
name: "Action",
options: {
filter: false,
sort: false,
customBodyRender: (val, tableMeta) => {
return (
<div style={{ display: 'flex' }}>
{this.props.btndownload && <a data-tip={'Download'} data-for="download">
<button
style={{
backgroundColor: 'transparent',
cursor: 'pointer',
borderColor: 'transparent',
marginRight: 15
}}
onClick={() => this.openPopUp(tableMeta.rowData, val, 'download')}
>
<img src={Images.download} />
</button>
</a>}
<ReactTooltip border={true} id="download" place="bottom" type="light" effect="solid" />
</div >
);
}
}
},
{
name: "File Name",
options: {
display: false
}
},
"Description", "Company Name", "Period Month", "Period Year",
"Type", "File Size", "Created By", "Created Date",
{
name: "Category",
options: {
display: false
}
},
]
const loadingComponent = (
<div style={{ position: 'absolute', zIndex: 110, top: 0, left: 0, width: '100%', height: '100%', display: 'flex', justifyContent: 'center', alignItems: 'center', background: 'rgba(255,255,255,0.8)' }}>
<PropagateLoader
// css={override}
size={20}
color={"#274B80"}
loading={this.state.loading}
/>
</div>
);
return (
<div style={{ width: '100%' }}>
{this.props.load && (
<div style={{ padding: 25 }}>
<Snackbar open={this.state.alert} autoHideDuration={6000} onClose={() => this.closeAlert()}>
<Alert onClose={() => this.closeAlert()} severity={this.state.tipeAlert}>
{this.state.messageAlert}
</Alert>
</Snackbar>
{this.state.loading && loadingComponent}
<MuiThemeProvider theme={getMuiTheme()}>
<MUIDataTable
// theme={getMuiTheme()}
data={this.state.dataTable}
columns={columns}
options={options}
/>
</MuiThemeProvider>
</div>
)}
</div>
)
}
}
......@@ -25,6 +25,7 @@ import CafrmDocument from "../container/CAFRM/CafrmDocument";
import ReportCafrm from "../container/ReportCarfm/RepotrCafrm";
import Maintenance from "../container/Auth/Maintenance";
import DownloadReport from "../container/DownloadReport/DownloadReport"
import ChcmDocument from '../container/CHCM/ChcmDocument';
const routes = [
{
......@@ -139,6 +140,14 @@ const routes = [
path: "/home/download-report",
main: DownloadReport
},
{
path: "/home/report-talent-management-tm",
main: ChcmDocument
},
{
path: "/home/report-trec",
main: ChcmDocument
},
{
path: "*",
main: screen404
......
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