You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
 
 

276 lines
11 KiB

  1. // material-ui
  2. import {
  3. Grid,
  4. Typography,
  5. Stack,
  6. Button,
  7. Dialog, DialogTitle, DialogContent, DialogActions,
  8. } from '@mui/material';
  9. import MainCard from "components/MainCard";
  10. import {GEN_GFMIS_XML} from "utils/ApiPathConst";
  11. import * as React from "react";
  12. import * as HttpUtils from "utils/HttpUtils";
  13. import * as DateUtils from "utils/DateUtils";
  14. import {DatePicker} from "@mui/x-date-pickers/DatePicker";
  15. import dayjs from "dayjs";
  16. import {DemoItem} from "@mui/x-date-pickers/internals/demo";
  17. import {LocalizationProvider} from "@mui/x-date-pickers/LocalizationProvider";
  18. import {AdapterDayjs} from "@mui/x-date-pickers/AdapterDayjs";
  19. import Loadable from 'components/Loadable';
  20. const LoadingComponent = Loadable(React.lazy(() => import('pages/extra-pages/LoadingComponent')));
  21. const SearchForm = Loadable(React.lazy(() => import('./SearchForm')));
  22. const EventTable = Loadable(React.lazy(() => import('./DataGrid')));
  23. const TransactionTable = Loadable(React.lazy(() => import('./TransactionDataGrid')));
  24. import titleBackgroundImg from 'assets/images/dashboard/gazette-bar.png'
  25. const BackgroundHead = {
  26. backgroundImage: `url(${titleBackgroundImg})`,
  27. width: '100%',
  28. height: '100%',
  29. backgroundSize:'contain',
  30. backgroundRepeat: 'no-repeat',
  31. backgroundColor: '#0C489E',
  32. backgroundPosition: 'right'
  33. }
  34. // ==============================|| DASHBOARD - DEFAULT ||============================== //
  35. const Index = () => {
  36. const [searchCriteria, setSearchCriteria] = React.useState({
  37. dateTo: DateUtils.dateValue(new Date()),
  38. dateFrom: DateUtils.dateValue(new Date().setDate(new Date().getDate()-14)),
  39. });
  40. const [previewSearchCriteria, setPreviewSearchCriteria] = React.useState({
  41. dateTo: DateUtils.dateValue(new Date()),
  42. dateFrom: DateUtils.dateValue(new Date().setDate(new Date().getDate()-14)),
  43. });
  44. const [onReady, setOnReady] = React.useState(false);
  45. const [onGridReady, setGridOnReady] = React.useState(false);
  46. const [isPreviewLoading, setIsPreviewLoading] = React.useState(false);
  47. const [isPopUp, setIsPopUp] = React.useState(false);
  48. const [downloadInput, setDownloadInput] = React.useState();
  49. const [selectedIds, setSelectedIds] = React.useState([]);
  50. const [inputDate, setInputDate] = React.useState(searchCriteria.dateTo);
  51. const [inputDateValue, setInputDateValue] = React.useState("dd / mm / yyyy");
  52. React.useEffect(() => {
  53. setInputDateValue(inputDate);
  54. }, [inputDate]);
  55. React.useEffect(() => {
  56. setOnReady(true);
  57. }, [searchCriteria]);
  58. function downloadXML() {
  59. console.log(selectedIds.join(','))
  60. setIsPopUp(false)
  61. let sentDateFrom = "";
  62. if (inputDateValue != "dd / mm / yyyy") {
  63. sentDateFrom = DateUtils.dateValue(inputDateValue)
  64. }
  65. HttpUtils.get({
  66. url: GEN_GFMIS_XML + "/today",
  67. params:{
  68. dateTo: downloadInput.dateTo,
  69. dateFrom: downloadInput.dateFrom,
  70. inputDate: sentDateFrom,
  71. paymentId: selectedIds.join(',')
  72. },
  73. onSuccess: (responseData) => {
  74. // console.log(responseData)
  75. const parser = new DOMParser();
  76. const xmlDoc = parser.parseFromString(responseData, 'application/xml');
  77. // Get the DCBHeader element
  78. const dcbHeader = xmlDoc.querySelector("DCBHeader");
  79. // Get the Receipt and Allocation elements
  80. const receiptElement = dcbHeader.querySelector("Receipt");
  81. const allocationElement = dcbHeader.querySelector("Allocation");
  82. const paymentMethodElements = Array.from(dcbHeader.querySelectorAll("PaymentMethod"));
  83. // Remove existing elements from DCBHeader
  84. dcbHeader.innerHTML = "";
  85. dcbHeader.appendChild(receiptElement);
  86. dcbHeader.appendChild(allocationElement);
  87. if (paymentMethodElements) {
  88. paymentMethodElements.forEach((paymentMethodElement) => {
  89. dcbHeader.appendChild(paymentMethodElement);
  90. });
  91. }
  92. const updatedXmlString = new XMLSerializer().serializeToString(xmlDoc);
  93. const filename = xmlDoc.querySelector('FileHeader').getAttribute('H_Filename');
  94. // console.log(updatedXmlString)
  95. const blob = new Blob([updatedXmlString], { type: 'application/xml' });
  96. // Create a download link
  97. const link = document.createElement('a');
  98. link.href = URL.createObjectURL(blob);
  99. link.download = filename+'.xml';
  100. // Append the link to the document body
  101. document.body.appendChild(link);
  102. // Programmatically click the link to trigger the download
  103. link.click();
  104. // Clean up the link
  105. document.body.removeChild(link);
  106. }
  107. });
  108. // open(UrlUtils.GEN_GFMIS_XML + "/today?online=true")
  109. }
  110. function applySearch(input) {
  111. setGridOnReady(true)
  112. setSearchCriteria(input);
  113. setInputDate(input.dateFrom)
  114. }
  115. function previewSearch() {
  116. // trigger reload even if criteria object is identical
  117. const withToken = { ...searchCriteria, __ts: Date.now() };
  118. setIsPopUp(false);
  119. setIsPreviewLoading(true);
  120. setPreviewSearchCriteria(withToken);
  121. }
  122. function onPreviewGridOnReady(isLoading) {
  123. // FiDataGrid calls this with true/false
  124. setIsPreviewLoading(isLoading);
  125. }
  126. function applyGridOnReady(input) {
  127. setGridOnReady(input);
  128. }
  129. function generateXML(input) {
  130. setDownloadInput(input);
  131. setIsPopUp(true)
  132. }
  133. return (
  134. !onReady ?
  135. <LoadingComponent/>
  136. :
  137. <Grid container sx={{minHeight: '87vh', backgroundColor: 'backgroundColor.default'}} direction="column">
  138. <Grid item xs={12}>
  139. <div style={BackgroundHead}>
  140. <Stack direction="row" height='70px' justifyContent="flex-start" alignItems="center">
  141. <Typography ml={15} color='#FFF' variant="h4" sx={{ "textShadow": "0px 0px 25px #0C489E" }}>
  142. GFMIS Generate XML
  143. </Typography>
  144. </Stack>
  145. </div>
  146. </Grid>
  147. {/*row 1*/}
  148. <Grid item xs={12} md={12} lg={12} sx={{mb:-1}}>
  149. <SearchForm
  150. applySearch={applySearch}
  151. generateXML={generateXML}
  152. searchCriteria={searchCriteria}
  153. onGridReady={onGridReady}
  154. selectedIds={selectedIds}
  155. />
  156. </Grid>
  157. {/*row 2*/}
  158. <Grid item xs={12} md={12} lg={12}>
  159. <MainCard elevation={0}
  160. border={false}
  161. content={false}
  162. sx={{width: "-webkit-fill-available"}}
  163. >
  164. <TransactionTable
  165. searchCriteria={searchCriteria}
  166. applyGridOnReady={applyGridOnReady}
  167. applySearch={applySearch}
  168. selectedIds={selectedIds}
  169. onSelectionChange={setSelectedIds}
  170. />
  171. </MainCard>
  172. </Grid>
  173. <Grid item xs={12} md={12} lg={12} sx={{ml:2}}>
  174. <Button
  175. variant="contained"
  176. onClick={previewSearch}
  177. disabled={isPreviewLoading || selectedIds.length === 0}
  178. >
  179. Preview
  180. </Button>
  181. </Grid>
  182. <Grid item xs={12} md={12} lg={12}>
  183. <MainCard elevation={0}
  184. border={false}
  185. content={false}
  186. sx={{width: "-webkit-fill-available"}}
  187. >
  188. <EventTable
  189. previewSearchCriteria={previewSearchCriteria}
  190. onPreviewGridOnReady={onPreviewGridOnReady}
  191. selectedIds={selectedIds}
  192. />
  193. </MainCard>
  194. </Grid>
  195. <Dialog
  196. open={isPopUp}
  197. onClose={() => setIsPopUp(false)}
  198. PaperProps={{
  199. sx: {
  200. minWidth: '40vw',
  201. maxWidth: { xs: '90vw', s: '90vw', m: '70vw', lg: '70vw' },
  202. maxHeight: { xs: '90vh', s: '70vh', m: '70vh', lg: '60vh' }
  203. }
  204. }}
  205. >
  206. <DialogTitle> Bank Statement Collection Date </DialogTitle>
  207. <DialogContent style={{ display: 'flex', }}>
  208. <LocalizationProvider dateAdapter={AdapterDayjs}>
  209. <DemoItem components={['DatePicker']}>
  210. <DatePicker
  211. id="dateFrom"
  212. // onError={(newError) => setReceiptFromError(newError)}
  213. slotProps={{
  214. field: { readOnly: true, },
  215. // textField: {
  216. // helperText: receiptFromErrorMessage,
  217. // },
  218. }}
  219. format="DD/MM/YYYY"
  220. // label="Credit Date"
  221. value={inputDate === null ? null : dayjs(inputDate)}
  222. maxDate={searchCriteria.dateTo === null ? null : dayjs(searchCriteria.dateTo)}
  223. minDate={searchCriteria.dateFrom === null ? null : dayjs(searchCriteria.dateFrom)}
  224. onChange={(newValue) => {
  225. // console.log(newValue)
  226. if(newValue!=null){
  227. setInputDate(newValue);
  228. }
  229. }}
  230. />
  231. </DemoItem >
  232. </LocalizationProvider>
  233. </DialogContent>
  234. <DialogActions>
  235. <Button onClick={() => setIsPopUp(false)}><Typography variant="h5">Cancel</Typography></Button>
  236. <Button onClick={() => downloadXML()}><Typography variant="h5">Confirm</Typography></Button>
  237. </DialogActions>
  238. </Dialog>
  239. </Grid>
  240. );
  241. };
  242. export default Index;