您最多选择25个主题 主题必须以字母或数字开头,可以包含连字符 (-),并且长度不得超过35个字符
 
 

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