選択できるのは25トピックまでです。 トピックは、先頭が英数字で、英数字とダッシュ('-')を使用した35文字以内のものにしてください。

158 行
5.5 KiB

  1. // material-ui
  2. import {
  3. Grid,
  4. Typography,
  5. Stack
  6. } from '@mui/material';
  7. import MainCard from "components/MainCard";
  8. import * as UrlUtils from "utils/ApiPathConst";
  9. import * as React from "react";
  10. import * as HttpUtils from "utils/HttpUtils";
  11. import * as DateUtils from "utils/DateUtils";
  12. import Loadable from 'components/Loadable';
  13. const LoadingComponent = Loadable(React.lazy(() => import('pages/extra-pages/LoadingComponent')));
  14. const SearchForm = Loadable(React.lazy(() => import('./SearchForm')));
  15. const EventTable = Loadable(React.lazy(() => import('./DataGrid')));
  16. import titleBackgroundImg from 'assets/images/dashboard/gazette-bar.png'
  17. const BackgroundHead = {
  18. backgroundImage: `url(${titleBackgroundImg})`,
  19. width: '100%',
  20. height: '100%',
  21. backgroundSize:'contain',
  22. backgroundRepeat: 'no-repeat',
  23. backgroundColor: '#0C489E',
  24. backgroundPosition: 'right'
  25. }
  26. // ==============================|| DASHBOARD - DEFAULT ||============================== //
  27. const Index = () => {
  28. const [record,setRecord] = React.useState([]);
  29. const [searchCriteria, setSearchCriteria] = React.useState({
  30. dateTo: DateUtils.dateStr(new Date()),
  31. dateFrom: DateUtils.dateStr(new Date().setDate(new Date().getDate()-14)),
  32. });
  33. const [onReady, setOnReady] = React.useState(false);
  34. React.useEffect(() => {
  35. setOnReady(true);
  36. }, [record]);
  37. React.useEffect(() => {
  38. // console.log(searchCriteria)
  39. loadGrid();
  40. }, [searchCriteria]);
  41. function loadGrid(){
  42. HttpUtils.get({
  43. url: UrlUtils.GFIMIS_LIST,
  44. params: searchCriteria,
  45. onSuccess: function(responseData){
  46. setRecord(responseData);
  47. }
  48. });
  49. }
  50. function downloadXML(input) {
  51. // console.log(input)
  52. HttpUtils.get({
  53. url: UrlUtils.GEN_GFMIS_XML + "/today",
  54. params:{dateTo: input.dateTo,
  55. dateFrom: input.dateFrom,
  56. },
  57. onSuccess: (responseData) => {
  58. console.log(responseData)
  59. const parser = new DOMParser();
  60. const xmlDoc = parser.parseFromString(responseData, 'application/xml');
  61. // Get the DCBHeader element
  62. const dcbHeader = xmlDoc.querySelector("DCBHeader");
  63. // Get the Receipt and Allocation elements
  64. const receiptElement = dcbHeader.querySelector("Receipt");
  65. const allocationElement = dcbHeader.querySelector("Allocation");
  66. const paymentMethodElements = Array.from(dcbHeader.querySelectorAll("PaymentMethod"));
  67. // Remove existing elements from DCBHeader
  68. dcbHeader.innerHTML = "";
  69. dcbHeader.appendChild(receiptElement);
  70. dcbHeader.appendChild(allocationElement);
  71. if (paymentMethodElements) {
  72. paymentMethodElements.forEach((paymentMethodElement) => {
  73. dcbHeader.appendChild(paymentMethodElement);
  74. });
  75. }
  76. const updatedXmlString = new XMLSerializer().serializeToString(xmlDoc);
  77. const filename = xmlDoc.querySelector('FileHeader').getAttribute('H_Filename');
  78. console.log(updatedXmlString)
  79. const blob = new Blob([updatedXmlString], { type: 'application/xml' });
  80. // Create a download link
  81. const link = document.createElement('a');
  82. link.href = URL.createObjectURL(blob);
  83. link.download = filename+'.xml';
  84. // Append the link to the document body
  85. document.body.appendChild(link);
  86. // Programmatically click the link to trigger the download
  87. link.click();
  88. // Clean up the link
  89. document.body.removeChild(link);
  90. }
  91. });
  92. // open(UrlUtils.GEN_GFMIS_XML + "/today?online=true")
  93. }
  94. function applySearch(input) {
  95. setSearchCriteria(input);
  96. }
  97. function generateXML(input) {
  98. downloadXML(input);
  99. }
  100. return (
  101. !onReady ?
  102. <LoadingComponent/>
  103. :
  104. <Grid container sx={{ backgroundColor: 'backgroundColor.default'}} direction="column">
  105. <Grid item xs={12}>
  106. <div style={BackgroundHead}>
  107. <Stack direction="row" height='70px' justifyContent="flex-start" alignItems="center">
  108. <Typography ml={15} color='#FFF' variant="h4">GFMIS</Typography>
  109. </Stack>
  110. </div>
  111. </Grid>
  112. {/*row 1*/}
  113. <Grid item xs={12} md={12} lg={12} sx={{mb:-1}}>
  114. <SearchForm
  115. applySearch={applySearch}
  116. generateXML={generateXML}
  117. searchCriteria={searchCriteria}
  118. />
  119. </Grid>
  120. {/*row 2*/}
  121. <Grid item xs={12} md={12} lg={12}>
  122. <MainCard elevation={0}
  123. border={false}
  124. content={false}
  125. sx={{width: "-webkit-fill-available"}}
  126. >
  127. <EventTable
  128. recordList={record}
  129. />
  130. </MainCard>
  131. </Grid>
  132. </Grid>
  133. );
  134. };
  135. export default Index;