// material-ui import { Grid, Typography, Stack, Button, Dialog, DialogTitle, DialogContent, DialogActions, } from '@mui/material'; import MainCard from "components/MainCard"; import {GEN_GFMIS_XML} from "utils/ApiPathConst"; import * as React from "react"; import * as HttpUtils from "utils/HttpUtils"; import * as DateUtils from "utils/DateUtils"; import {DatePicker} from "@mui/x-date-pickers/DatePicker"; import dayjs from "dayjs"; import {DemoItem} from "@mui/x-date-pickers/internals/demo"; import {LocalizationProvider} from "@mui/x-date-pickers/LocalizationProvider"; import {AdapterDayjs} from "@mui/x-date-pickers/AdapterDayjs"; import Loadable from 'components/Loadable'; const LoadingComponent = Loadable(React.lazy(() => import('pages/extra-pages/LoadingComponent'))); const SearchForm = Loadable(React.lazy(() => import('./SearchForm'))); const EventTable = Loadable(React.lazy(() => import('./DataGrid'))); const TransactionTable = Loadable(React.lazy(() => import('./TransactionDataGrid'))); import titleBackgroundImg from 'assets/images/dashboard/gazette-bar.png' const BackgroundHead = { backgroundImage: `url(${titleBackgroundImg})`, width: '100%', height: '100%', backgroundSize:'contain', backgroundRepeat: 'no-repeat', backgroundColor: '#0C489E', backgroundPosition: 'right' } // ==============================|| DASHBOARD - DEFAULT ||============================== // const Index = () => { const [searchCriteria, setSearchCriteria] = React.useState({ dateTo: DateUtils.dateValue(new Date()), dateFrom: DateUtils.dateValue(new Date().setDate(new Date().getDate()-14)), }); const [previewSearchCriteria, setPreviewSearchCriteria] = React.useState({ dateTo: DateUtils.dateValue(new Date()), dateFrom: DateUtils.dateValue(new Date().setDate(new Date().getDate()-14)), }); const [onReady, setOnReady] = React.useState(false); const [onGridReady, setGridOnReady] = React.useState(false); const [isPreviewLoading, setIsPreviewLoading] = React.useState(false); const [isPopUp, setIsPopUp] = React.useState(false); const [downloadInput, setDownloadInput] = React.useState(); const [selectedIds, setSelectedIds] = React.useState([]); const [inputDate, setInputDate] = React.useState(searchCriteria.dateTo); const [inputDateValue, setInputDateValue] = React.useState("dd / mm / yyyy"); React.useEffect(() => { setInputDateValue(inputDate); }, [inputDate]); React.useEffect(() => { setOnReady(true); }, [searchCriteria]); React.useEffect(() => { if (selectedIds.length > 0) { const withToken = { ...searchCriteria, __ts: Date.now() }; setPreviewSearchCriteria(withToken); } }, [selectedIds, searchCriteria]); function downloadXML() { console.log(selectedIds.join(',')) setIsPopUp(false) let sentDateFrom = ""; if (inputDateValue != "dd / mm / yyyy") { sentDateFrom = DateUtils.dateValue(inputDateValue) } HttpUtils.get({ url: GEN_GFMIS_XML + "/today", params:{ dateTo: downloadInput.dateTo, dateFrom: downloadInput.dateFrom, inputDate: sentDateFrom, paymentId: selectedIds.join(',') }, onSuccess: (responseData) => { // console.log(responseData) const parser = new DOMParser(); const xmlDoc = parser.parseFromString(responseData, 'application/xml'); // Get the DCBHeader element const dcbHeader = xmlDoc.querySelector("DCBHeader"); // Get the Receipt and Allocation elements const receiptElement = dcbHeader.querySelector("Receipt"); const allocationElement = dcbHeader.querySelector("Allocation"); const paymentMethodElements = Array.from(dcbHeader.querySelectorAll("PaymentMethod")); // Remove existing elements from DCBHeader dcbHeader.innerHTML = ""; dcbHeader.appendChild(receiptElement); dcbHeader.appendChild(allocationElement); if (paymentMethodElements) { paymentMethodElements.forEach((paymentMethodElement) => { dcbHeader.appendChild(paymentMethodElement); }); } const updatedXmlString = new XMLSerializer().serializeToString(xmlDoc); const filename = xmlDoc.querySelector('FileHeader').getAttribute('H_Filename'); // console.log(updatedXmlString) const blob = new Blob([updatedXmlString], { type: 'application/xml' }); // Create a download link const link = document.createElement('a'); link.href = URL.createObjectURL(blob); link.download = filename+'.xml'; // Append the link to the document body document.body.appendChild(link); // Programmatically click the link to trigger the download link.click(); // Clean up the link document.body.removeChild(link); } }); // open(UrlUtils.GEN_GFMIS_XML + "/today?online=true") } function applySearch(input) { setGridOnReady(true); setSelectedIds([]); setPreviewSearchCriteria({}); setSearchCriteria(input); setInputDate(input.dateFrom); } function previewSearch() { // trigger reload even if criteria object is identical const withToken = { ...searchCriteria, __ts: Date.now() }; setIsPopUp(false); setIsPreviewLoading(true); setPreviewSearchCriteria(withToken); } function onPreviewGridOnReady(isLoading) { // FiDataGrid calls this with true/false setIsPreviewLoading(isLoading); } function applyGridOnReady(input) { setGridOnReady(input); } function generateXML(input) { setDownloadInput(input); setIsPopUp(true) } return ( !onReady ? :
GFMIS Generate XML
{/*row 1*/} {/*row 2*/} setIsPopUp(false)} PaperProps={{ sx: { minWidth: '40vw', maxWidth: { xs: '90vw', s: '90vw', m: '70vw', lg: '70vw' }, maxHeight: { xs: '90vh', s: '70vh', m: '70vh', lg: '60vh' } } }} > Bank Statement Collection Date setReceiptFromError(newError)} slotProps={{ field: { readOnly: true, }, // textField: { // helperText: receiptFromErrorMessage, // }, }} format="DD/MM/YYYY" // label="Credit Date" value={inputDate === null ? null : dayjs(inputDate)} maxDate={searchCriteria.dateTo === null ? null : dayjs(searchCriteria.dateTo)} minDate={searchCriteria.dateFrom === null ? null : dayjs(searchCriteria.dateFrom)} onChange={(newValue) => { // console.log(newValue) if(newValue!=null){ setInputDate(newValue); } }} />
); }; export default Index;