Browse Source

Bug fixing export excel

pull/2/head
nurkomalasari 2 years ago
parent
commit
70d6c38539
  1. 29
      src/views/SimproV2/ProjectType/index.js
  2. 187
      src/views/SimproV2/ResourceTools/index.js
  3. 17
      src/views/SimproV2/ResourceWorker/index.js

29
src/views/SimproV2/ProjectType/index.js

@ -96,7 +96,7 @@ const ProjectType = ({params}) => {
} }
const result = await axios const result = await axios
.post(PROJECT_TYPE_SEARCH, payload, config) .post(PROJECT_TYPE_SEARCH, payload, config, HEADER)
.then(res => res) .then(res => res)
.catch((error) => error.response); .catch((error) => error.response);
@ -122,17 +122,34 @@ const ProjectType = ({params}) => {
const handleExportExcel = async () => { const handleExportExcel = async () => {
let start = 0; let start = 0;
if (currentPage !== 1 && currentPage > 1) {
start = (currentPage * rowsPerPage) - rowsPerPage
}
const payload = { const payload = {
"paging": { "start": start, "length": -1 },
"columns": [ "columns": [
{ "name": "name", "logic_operator": "ilike", "value": search, "operator": "AND" } {
"name": "name",
"logic_operator": "like",
"value": search,
"operator": "AND"
}
], ],
"joins": [], "orders": {
"orders": { "columns": ["id"], "ascending": false } "ascending": true,
"columns": [
'id'
]
},
"paging": {
"length": rowsPerPage,
"start": start
} }
}
const result = await axios const result = await axios
.post(PROJECT_TYPE_SEARCH, payload) .post(PROJECT_TYPE_SEARCH, payload, HEADER)
.then(res => res) .then(res => res)
.catch((error) => error.response); .catch((error) => error.response);

187
src/views/SimproV2/ResourceTools/index.js

@ -46,6 +46,9 @@ const ResourceWorker = ({ params }) => {
const [dataDeliveryTools, setDataDeliveryTools] = useState([]); const [dataDeliveryTools, setDataDeliveryTools] = useState([]);
const [dataEdit, setDataEdit] = useState(null) const [dataEdit, setDataEdit] = useState(null)
const [dataExport, setDataExport] = useState([]) const [dataExport, setDataExport] = useState([])
const [dataExportToolsRequest, setDataExportToolsRequest] = useState([])
const [dataExportToolsDelivery, setDataExportToolsDelivery] = useState([])
const [dataReqTools, setDataReqTools] = useState([]); const [dataReqTools, setDataReqTools] = useState([]);
const [dataTable, setDatatable] = useState([]) const [dataTable, setDatatable] = useState([])
const [idDelete, setIdDelete] = useState(0) const [idDelete, setIdDelete] = useState(0)
@ -68,6 +71,27 @@ const ResourceWorker = ({ params }) => {
getDataTools() getDataTools()
}, [search, rowsPerPage, currentPage]) }, [search, rowsPerPage, currentPage])
useEffect(() => {
const cekData = dataExport || []
if (cekData.length > 0) {
exportExcel()
}
}, [dataExport])
useEffect(() => {
const cekData = dataExportToolsRequest || []
if (cekData.length > 0) {
exportExcelToolsRequest()
}
}, [dataExportToolsRequest])
useEffect(() => {
const cekData = dataExportToolsDelivery || []
if (cekData.length > 0) {
exportExcelToolsDilevery()
}
}, [dataExportToolsDelivery])
const onShowSizeChange = (current, pageSize) => { const onShowSizeChange = (current, pageSize) => {
setRowsPerPage(pageSize) setRowsPerPage(pageSize)
} }
@ -220,7 +244,7 @@ const ResourceWorker = ({ params }) => {
setTypeDialog(type) setTypeDialog(type)
} }
const handleExportExcel = async () => { const handleExportExcelToolsResource = async () => {
const payload = { const payload = {
"paging": { "start": 0, "length": -1 }, "paging": { "start": 0, "length": -1 },
@ -244,12 +268,11 @@ const ResourceWorker = ({ params }) => {
const excelData = []; const excelData = [];
resData.map((n, index) => { resData.map((n, index) => {
let dataRow = { let dataRow = {
"Nama Proyek": n.nama, "Nama": n.name,
"Biaya": n.biaya, "Tipe Asset": n.asset_type,
"Color Progress": n.color_progress, "Deskripsi": n.description,
"Jumlah Pekerja": n.jumlah_pekerja, "Quantity": n.qty,
"Tanggal Mulai": n.mulai_proyek ? moment(n.mulai_proyek).format(format) : "-", "UOM": n.uom
"Tanggal Selesai": n.akhir_proyek ? moment(n.akhir_proyek).format(format) : "-",
} }
excelData.push(dataRow) excelData.push(dataRow)
}) })
@ -259,6 +282,150 @@ const ResourceWorker = ({ params }) => {
} }
} }
const handleExportExcelToolsRequest = async () => {
const payload = {
"paging": {
"start": 0,
"length": 10
},
"columns": [
{
"name": "asset_type",
"logic_operator": "ilike",
"value": "",
"operator": "AND"
},
{
"name": "status",
"logic_operator": "<>",
"value": "receipt to site",
"operator": "AND"
}
],
"joins": [{ "name": "m_proyek", "column_join": "proyek_id", "column_results": ["kode_sortname", "nama"] }],
"orders": {
"columns": [
"id"
],
"ascending": false
}
}
const result = await axios.post(REQUEST_TOOLS_SEARCH, payload, HEADER)
.then(res => res)
.catch((error) => error.response);
if (result && result.data && result.data.code == 200) {
let resData = result.data.data;
const excelData = [];
resData.map((n, index) => {
let dataRow = {
"Company Name": n.join_first_nama ? null : "-",
"Asset Name": n.asset_name,
"Asset Type": n.asset_type,
"Description": n.description,
"Quantity": n.qty,
"UOM": n.uom,
"Status": n.status,
}
console.log('Tools Request', resData)
excelData.push(dataRow)
})
await setDataExportToolsRequest(excelData);
} else {
NotificationManager.error('Gagal Export Data!!', 'Failed');
}
}
const handleExportExcelToolsDeliver = async () => {
const payload = {
"paging": {
"start": 0,
"length": 10
},
"columns": [
{
"name": "asset_type",
"logic_operator": "ilike",
"value": "",
"operator": "AND"
},
{
"name": "status",
"logic_operator": "=",
"value": "receipt to site",
"operator": "AND"
}
],
"joins": [{ "name": "m_proyek", "column_join": "proyek_id", "column_results": ["kode_sortname", "nama"] }],
"orders": {
"columns": [
"id"
],
"ascending": false
}
}
const result = await axios.post(TOOLS_RESOURCE_SEARCH, payload, HEADER)
.then(res => res)
.catch((error) => error.response);
if (result && result.data && result.data.code == 200) {
let resData = result.data.data;
const excelData = [];
resData.map((n, index) => {
let dataRow = {
"Nama": n.name,
"Tipe Asset": n.asset_type,
"Deskripsi": n.description,
"Quantity": n.qty,
"UOM": n.uom
}
excelData.push(dataRow)
})
await setDataExportToolsDelivery(excelData);
} else {
NotificationManager.error('Gagal Export Data!!', 'Failed');
}
}
const exportExcel = () => {
const dataExcel = dataExport || [];
const fileName = `Data ${pageName}.xlsx`;
const ws = XLSX.utils.json_to_sheet(dataExcel);
const wb = XLSX.utils.book_new();
XLSX.utils.book_append_sheet(wb, ws, `Data ${pageName}`);
XLSX.writeFile(wb, fileName);
setDataExport([])
}
const exportExcelToolsRequest = () => {
const dataExcel = dataExportToolsRequest || [];
const fileName = `Data Tools Request.xlsx`;
const ws = XLSX.utils.json_to_sheet(dataExcel);
const wb = XLSX.utils.book_new();
XLSX.utils.book_append_sheet(wb, ws, `Data Tools Request`);
XLSX.writeFile(wb, fileName);
setDataExportToolsRequest([])
}
const exportExcelToolsDilevery = () => {
const dataExcel = dataExportToolsDelivery || [];
const fileName = `Data Tools Dilevery.xlsx`;
const ws = XLSX.utils.json_to_sheet(dataExcel);
const wb = XLSX.utils.book_new();
XLSX.utils.book_append_sheet(wb, ws, `Data Tools Dilevery`);
XLSX.writeFile(wb, fileName);
setDataExportToolsDelivery([])
}
const handleEdit = (data) => { const handleEdit = (data) => {
setDataEdit(data) setDataEdit(data)
handleOpenDialog('Edit'); handleOpenDialog('Edit');
@ -383,7 +550,7 @@ const ResourceWorker = ({ params }) => {
<Button style={{ background: "#4caf50", color: "#fff" }} onClick={() => handleOpenDialog('Save')}><i className="fa fa-plus"></i></Button> <Button style={{ background: "#4caf50", color: "#fff" }} onClick={() => handleOpenDialog('Save')}><i className="fa fa-plus"></i></Button>
</Tooltip> </Tooltip>
<Tooltip title="Export Excel"> <Tooltip title="Export Excel">
<Button style={{ marginLeft: "5px" }} onClick={() => handleExportExcel()}><i className="fa fa-print"></i></Button> <Button style={{ marginLeft: "5px" }} onClick={() => handleExportExcelToolsResource()}><i className="fa fa-print"></i></Button>
</Tooltip> </Tooltip>
</Col> </Col>
</Row> </Row>
@ -467,7 +634,7 @@ const ResourceWorker = ({ params }) => {
</Col> </Col>
<Col> <Col>
<Tooltip title="Export Excel"> <Tooltip title="Export Excel">
<Button style={{ marginLeft: "5px" }} onClick={() => handleExportExcel()}><i className="fa fa-print"></i></Button> <Button style={{ marginLeft: "5px" }} onClick={() => handleExportExcelToolsRequest()}><i className="fa fa-print"></i></Button>
</Tooltip> </Tooltip>
</Col> </Col>
</Row> </Row>
@ -498,7 +665,7 @@ const ResourceWorker = ({ params }) => {
</Col> </Col>
<Col> <Col>
<Tooltip title="Export Excel"> <Tooltip title="Export Excel">
<Button style={{ marginLeft: "5px" }} onClick={() => handleExportExcel()}><i className="fa fa-print"></i></Button> <Button style={{ marginLeft: "5px" }} onClick={() => handleExportExcelToolsDeliver()}><i className="fa fa-print"></i></Button>
</Tooltip> </Tooltip>
</Col> </Col>
</Row> </Row>

17
src/views/SimproV2/ResourceWorker/index.js

@ -62,6 +62,13 @@ const ResourceWorker = ({ params }) => {
getDataUser() getDataUser()
}, [search, rowsPerPage, currentPage]) }, [search, rowsPerPage, currentPage])
useEffect(() => {
const cekData = dataExport || []
if (cekData.length > 0) {
exportExcel()
}
}, [dataExport])
const onShowSizeChange = (current, pageSize) => { const onShowSizeChange = (current, pageSize) => {
setRowsPerPage(pageSize) setRowsPerPage(pageSize)
} }
@ -264,6 +271,16 @@ const ResourceWorker = ({ params }) => {
} }
} }
const exportExcel = () => {
const dataExcel = dataExport || [];
const fileName = `Data ${pageName}.xlsx`;
const ws = XLSX.utils.json_to_sheet(dataExcel);
const wb = XLSX.utils.book_new();
XLSX.utils.book_append_sheet(wb, ws, `Data ${pageName}`);
XLSX.writeFile(wb, fileName);
setDataExport([])
}
const handleEdit = (data) => { const handleEdit = (data) => {
setDataEdit(data) setDataEdit(data)
handleOpenDialog('Edit'); handleOpenDialog('Edit');

Loading…
Cancel
Save