Browse Source

Bug fixing export excel

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

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

@ -9,7 +9,7 @@ import { Card, CardBody, CardHeader, Col, Row, Input } from 'reactstrap';
import { DownloadOutlined } from '@ant-design/icons';
import { NotificationContainer, NotificationManager } from 'react-notifications';
import { PROJECT_TYPE_ADD, PROJECT_TYPE_EDIT, PROJECT_TYPE_DELETE, PROJECT_TYPE_SEARCH } from '../../../const/ApiConst';
import { Pagination, Button, Tooltip, Table} from 'antd';
import { Pagination, Button, Tooltip, Table } from 'antd';
const url = "";
const proyek_id = localStorage.getItem('proyek_id');
@ -19,8 +19,8 @@ const token = window.localStorage.getItem('token');
const config = {
headers:
{
Authorization : `Bearer ${token}`,
"Content-type" : `application/json`
Authorization: `Bearer ${token}`,
"Content-type": `application/json`
}
};
@ -29,7 +29,7 @@ const column = [
{ name: "Deskripsi" },
]
const ProjectType = ({params}) => {
const ProjectType = ({ params }) => {
const token = localStorage.getItem("token")
const HEADER = {
headers: {
@ -77,10 +77,10 @@ const ProjectType = ({params}) => {
const payload = {
"columns": [
{
"name":"name",
"logic_operator":"like",
"value":search,
"operator":"AND"
"name": "name",
"logic_operator": "like",
"value": search,
"operator": "AND"
}
],
"orders": {
@ -96,14 +96,14 @@ const ProjectType = ({params}) => {
}
const result = await axios
.post(PROJECT_TYPE_SEARCH, payload, config)
.post(PROJECT_TYPE_SEARCH, payload, config, HEADER)
.then(res => res)
.catch((error) => error.response);
if(result && result.data && result.data.code == 200){
if (result && result.data && result.data.code == 200) {
setDatatable(result.data.data);
setTotalPage(result.data.totalRecord);
}else{
} else {
NotificationManager.error('Gagal Mengambil Data!!', 'Failed');
}
}
@ -122,17 +122,34 @@ const ProjectType = ({params}) => {
const handleExportExcel = async () => {
let start = 0;
if (currentPage !== 1 && currentPage > 1) {
start = (currentPage * rowsPerPage) - rowsPerPage
}
const payload = {
"paging": { "start": start, "length": -1 },
"columns": [
{ "name": "name", "logic_operator": "ilike", "value": search, "operator": "AND" }
{
"name": "name",
"logic_operator": "like",
"value": search,
"operator": "AND"
}
],
"joins": [],
"orders": { "columns": ["id"], "ascending": false }
"orders": {
"ascending": true,
"columns": [
'id'
]
},
"paging": {
"length": rowsPerPage,
"start": start
}
}
const result = await axios
.post(PROJECT_TYPE_SEARCH, payload)
.post(PROJECT_TYPE_SEARCH, payload, HEADER)
.then(res => res)
.catch((error) => error.response);
@ -227,7 +244,7 @@ const ProjectType = ({params}) => {
}
const toggleDialogIG = () => {
if(openDialogIG){
if (openDialogIG) {
setIdTypeProject(0)
}
setOpenDialogIG(!openDialogIG);
@ -236,7 +253,7 @@ const ProjectType = ({params}) => {
const onConfirmDelete = async () => {
let url = PROJECT_TYPE_DELETE(idDelete);
const result = await axios.delete(url,config)
const result = await axios.delete(url, config)
.then(res => res)
.catch((error) => error.response);
@ -266,7 +283,7 @@ const ProjectType = ({params}) => {
}
const dataNotAvailable = () => {
if(dataTable.length===0){
if (dataTable.length === 0) {
return (
<tr>
<td align="center" colSpan="3">Tidak ada data project type</td>
@ -281,7 +298,7 @@ const ProjectType = ({params}) => {
title: 'Action',
dataIndex: '',
key: 'x',
className:'nowrap',
className: 'nowrap',
render: (text, record) => <>
<Tooltip title="Delete">
<i className="fa fa-trash" style={{ color: 'red', marginRight: '10px', cursor: "pointer" }} onClick={() => handleDelete(text.id)}></i>
@ -294,7 +311,7 @@ const ProjectType = ({params}) => {
</Tooltip>
</>,
},
{ title: 'Nama Role', dataIndex: 'name', key: 'name', className:"nowrap" },
{ title: 'Nama Role', dataIndex: 'name', key: 'name', className: "nowrap" },
{ title: 'Description', dataIndex: 'description', key: 'description' },
];
return (
@ -359,7 +376,7 @@ const ProjectType = ({params}) => {
<CardBody>
{renderTable}
<Pagination
style={{marginTop:"25px"}}
style={{ marginTop: "25px" }}
showSizeChanger
onShowSizeChange={onShowSizeChange}
onChange={onPagination}

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

@ -46,6 +46,9 @@ const ResourceWorker = ({ params }) => {
const [dataDeliveryTools, setDataDeliveryTools] = useState([]);
const [dataEdit, setDataEdit] = useState(null)
const [dataExport, setDataExport] = useState([])
const [dataExportToolsRequest, setDataExportToolsRequest] = useState([])
const [dataExportToolsDelivery, setDataExportToolsDelivery] = useState([])
const [dataReqTools, setDataReqTools] = useState([]);
const [dataTable, setDatatable] = useState([])
const [idDelete, setIdDelete] = useState(0)
@ -68,6 +71,27 @@ const ResourceWorker = ({ params }) => {
getDataTools()
}, [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) => {
setRowsPerPage(pageSize)
}
@ -220,7 +244,7 @@ const ResourceWorker = ({ params }) => {
setTypeDialog(type)
}
const handleExportExcel = async () => {
const handleExportExcelToolsResource = async () => {
const payload = {
"paging": { "start": 0, "length": -1 },
@ -244,12 +268,11 @@ const ResourceWorker = ({ params }) => {
const excelData = [];
resData.map((n, index) => {
let dataRow = {
"Nama Proyek": n.nama,
"Biaya": n.biaya,
"Color Progress": n.color_progress,
"Jumlah Pekerja": n.jumlah_pekerja,
"Tanggal Mulai": n.mulai_proyek ? moment(n.mulai_proyek).format(format) : "-",
"Tanggal Selesai": n.akhir_proyek ? moment(n.akhir_proyek).format(format) : "-",
"Nama": n.name,
"Tipe Asset": n.asset_type,
"Deskripsi": n.description,
"Quantity": n.qty,
"UOM": n.uom
}
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) => {
setDataEdit(data)
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>
</Tooltip>
<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>
</Col>
</Row>
@ -467,7 +634,7 @@ const ResourceWorker = ({ params }) => {
</Col>
<Col>
<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>
</Col>
</Row>
@ -498,7 +665,7 @@ const ResourceWorker = ({ params }) => {
</Col>
<Col>
<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>
</Col>
</Row>

4
src/views/SimproV2/ResourceWorker/DialogForm.js

@ -115,7 +115,7 @@ const DialogForm = ({ openDialog, closeDialog, toggleDialog, typeDialog, dataEdi
status_resource: statusResource
}
if(birthDate && birthDate!=""){
if (birthDate && birthDate != "") {
data['birth_date'] = birthDate;
}
@ -157,7 +157,7 @@ const DialogForm = ({ openDialog, closeDialog, toggleDialog, typeDialog, dataEdi
status_resource: statusResource
}
if(birthDate && birthDate!=""){
if (birthDate && birthDate != "") {
data['birth_date'] = birthDate;
}

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

@ -62,6 +62,13 @@ const ResourceWorker = ({ params }) => {
getDataUser()
}, [search, rowsPerPage, currentPage])
useEffect(() => {
const cekData = dataExport || []
if (cekData.length > 0) {
exportExcel()
}
}, [dataExport])
const onShowSizeChange = (current, 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) => {
setDataEdit(data)
handleOpenDialog('Edit');

Loading…
Cancel
Save