diff --git a/package-lock.json b/package-lock.json
index 9521dd04..3043e932 100644
--- a/package-lock.json
+++ b/package-lock.json
@@ -18,8 +18,11 @@
"dateformat": "^4.5.1",
"dexie": "^3.0.3",
"dexie-export-import": "^1.0.3",
+ "docx": "^7.3.0",
"downloadjs": "^1.4.7",
+ "file-saver": "^2.0.5",
"file-select-dialog": "^1.5.4",
+ "fs": "^0.0.1-security",
"html-react-parser": "^1.2.7",
"html2pdf.js": "^0.10.1",
"i18next": "^21.6.0",
@@ -5137,9 +5140,9 @@
"integrity": "sha512-jhuKLIRrhvCPLqwPcx6INqmKeiA5EWrsCOPhrlFSrbrmU4ZMPjj5Ul/oLCMDO98XRUIwVm78xICz4EPCektzeQ=="
},
"node_modules/@types/node": {
- "version": "16.4.3",
- "resolved": "https://registry.npmjs.org/@types/node/-/node-16.4.3.tgz",
- "integrity": "sha512-GKM4FLMkWDc0sfx7tXqPWkM6NBow1kge0fgQh0bOnlqo4iT1kvTvMEKE0c1RtUGnbLlGRXiAA8SumE//90uKAg=="
+ "version": "17.0.8",
+ "resolved": "https://registry.npmjs.org/@types/node/-/node-17.0.8.tgz",
+ "integrity": "sha512-YofkM6fGv4gDJq78g4j0mMuGMkZVxZDgtU0JRdx6FgiJDG+0fY0GKVolOV8WqVmEhLCXkQRjwDdKyPxJp/uucg=="
},
"node_modules/@types/normalize-package-data": {
"version": "2.4.1",
@@ -10354,6 +10357,32 @@
"node": ">=6.0.0"
}
},
+ "node_modules/docx": {
+ "version": "7.3.0",
+ "resolved": "https://registry.npmjs.org/docx/-/docx-7.3.0.tgz",
+ "integrity": "sha512-OkSGlDNWMRFY07OEhUTx1ouuzYi8s1b67JDI6m5/5ek4xoshtP+/Rx8eRdY8LbhvpFkngvUantvTsxY4XW8Heg==",
+ "dependencies": {
+ "@types/node": "^17.0.0",
+ "jszip": "^3.1.5",
+ "nanoid": "^3.1.20",
+ "xml": "^1.0.1",
+ "xml-js": "^1.6.8"
+ },
+ "engines": {
+ "node": ">=10"
+ }
+ },
+ "node_modules/docx/node_modules/jszip": {
+ "version": "3.7.1",
+ "resolved": "https://registry.npmjs.org/jszip/-/jszip-3.7.1.tgz",
+ "integrity": "sha512-ghL0tz1XG9ZEmRMcEN2vt7xabrDdqHHeykgARpmZ0BiIctWxM47Vt63ZO2dnp4QYt/xJVLLy5Zv1l/xRdh2byg==",
+ "dependencies": {
+ "lie": "~3.3.0",
+ "pako": "~1.0.2",
+ "readable-stream": "~2.3.6",
+ "set-immediate-shim": "~1.0.1"
+ }
+ },
"node_modules/dom-converter": {
"version": "0.2.0",
"resolved": "https://registry.npmjs.org/dom-converter/-/dom-converter-0.2.0.tgz",
@@ -12503,6 +12532,11 @@
"url": "https://opencollective.com/webpack"
}
},
+ "node_modules/file-saver": {
+ "version": "2.0.5",
+ "resolved": "https://registry.npmjs.org/file-saver/-/file-saver-2.0.5.tgz",
+ "integrity": "sha512-P9bmyZ3h/PRG+Nzga+rbdI4OEpNDzAVyy74uVO9ATgzLK6VtAsYybF/+TOCvrc0MO793d6+42lLyZTw7/ArVzA=="
+ },
"node_modules/file-select-dialog": {
"version": "1.5.4",
"resolved": "https://registry.npmjs.org/file-select-dialog/-/file-select-dialog-1.5.4.tgz",
@@ -12987,6 +13021,11 @@
}
]
},
+ "node_modules/fs": {
+ "version": "0.0.1-security",
+ "resolved": "https://registry.npmjs.org/fs/-/fs-0.0.1-security.tgz",
+ "integrity": "sha1-invTcYa23d84E/I4WLV+yq9eQdQ="
+ },
"node_modules/fs-extra": {
"version": "9.1.0",
"resolved": "https://registry.npmjs.org/fs-extra/-/fs-extra-9.1.0.tgz",
@@ -14403,6 +14442,11 @@
"integrity": "sha1-SMptcvbGo68Aqa1K5odr44ieKwk=",
"optional": true
},
+ "node_modules/immediate": {
+ "version": "3.0.6",
+ "resolved": "https://registry.npmjs.org/immediate/-/immediate-3.0.6.tgz",
+ "integrity": "sha1-nbHb0Pr43m++D13V5Wu2BigN5ps="
+ },
"node_modules/immer": {
"version": "8.0.1",
"resolved": "https://registry.npmjs.org/immer/-/immer-8.0.1.tgz",
@@ -17976,6 +18020,14 @@
"node": ">= 0.8.0"
}
},
+ "node_modules/lie": {
+ "version": "3.3.0",
+ "resolved": "https://registry.npmjs.org/lie/-/lie-3.3.0.tgz",
+ "integrity": "sha512-UaiMJzeWRlEujzAuw5LokY1L5ecNQYZKfmyZ9L7wDHb/p5etKaxXhohBcrw0EYby+G/NA52vRSN4N39dxHAIwQ==",
+ "dependencies": {
+ "immediate": "~3.0.5"
+ }
+ },
"node_modules/lines-and-columns": {
"version": "1.1.6",
"resolved": "https://registry.npmjs.org/lines-and-columns/-/lines-and-columns-1.1.6.tgz",
@@ -27475,6 +27527,14 @@
"resolved": "https://registry.npmjs.org/set-blocking/-/set-blocking-2.0.0.tgz",
"integrity": "sha1-BF+XgtARrppoA93TgrJDkrPYkPc="
},
+ "node_modules/set-immediate-shim": {
+ "version": "1.0.1",
+ "resolved": "https://registry.npmjs.org/set-immediate-shim/-/set-immediate-shim-1.0.1.tgz",
+ "integrity": "sha1-SysbJ+uAip+NzEgaWOXlb1mfP2E=",
+ "engines": {
+ "node": ">=0.10.0"
+ }
+ },
"node_modules/set-value": {
"version": "2.0.1",
"resolved": "https://registry.npmjs.org/set-value/-/set-value-2.0.1.tgz",
@@ -32825,6 +32885,22 @@
"resolved": "https://registry.npmjs.org/commander/-/commander-2.17.1.tgz",
"integrity": "sha512-wPMUt6FnH2yzG95SA6mzjQOEKUU3aLaDEmzs1ti+1E9h+CsrZghRlqEM/EJ4KscsQVG8uNN4uVreUeT8+drlgg=="
},
+ "node_modules/xml": {
+ "version": "1.0.1",
+ "resolved": "https://registry.npmjs.org/xml/-/xml-1.0.1.tgz",
+ "integrity": "sha1-eLpyAgApxbyHuKgaPPzXS0ovweU="
+ },
+ "node_modules/xml-js": {
+ "version": "1.6.11",
+ "resolved": "https://registry.npmjs.org/xml-js/-/xml-js-1.6.11.tgz",
+ "integrity": "sha512-7rVi2KMfwfWFl+GpPg6m80IVMWXLRjO+PxTq7V2CDhoGak0wzYzFgUY2m4XJ47OGdXd8eLE8EmwfAmdjw7lC1g==",
+ "dependencies": {
+ "sax": "^1.2.4"
+ },
+ "bin": {
+ "xml-js": "bin/cli.js"
+ }
+ },
"node_modules/xml-name-validator": {
"version": "3.0.0",
"resolved": "https://registry.npmjs.org/xml-name-validator/-/xml-name-validator-3.0.0.tgz",
@@ -36541,9 +36617,9 @@
"integrity": "sha512-jhuKLIRrhvCPLqwPcx6INqmKeiA5EWrsCOPhrlFSrbrmU4ZMPjj5Ul/oLCMDO98XRUIwVm78xICz4EPCektzeQ=="
},
"@types/node": {
- "version": "16.4.3",
- "resolved": "https://registry.npmjs.org/@types/node/-/node-16.4.3.tgz",
- "integrity": "sha512-GKM4FLMkWDc0sfx7tXqPWkM6NBow1kge0fgQh0bOnlqo4iT1kvTvMEKE0c1RtUGnbLlGRXiAA8SumE//90uKAg=="
+ "version": "17.0.8",
+ "resolved": "https://registry.npmjs.org/@types/node/-/node-17.0.8.tgz",
+ "integrity": "sha512-YofkM6fGv4gDJq78g4j0mMuGMkZVxZDgtU0JRdx6FgiJDG+0fY0GKVolOV8WqVmEhLCXkQRjwDdKyPxJp/uucg=="
},
"@types/normalize-package-data": {
"version": "2.4.1",
@@ -40660,6 +40736,31 @@
"esutils": "^2.0.2"
}
},
+ "docx": {
+ "version": "7.3.0",
+ "resolved": "https://registry.npmjs.org/docx/-/docx-7.3.0.tgz",
+ "integrity": "sha512-OkSGlDNWMRFY07OEhUTx1ouuzYi8s1b67JDI6m5/5ek4xoshtP+/Rx8eRdY8LbhvpFkngvUantvTsxY4XW8Heg==",
+ "requires": {
+ "@types/node": "^17.0.0",
+ "jszip": "^3.1.5",
+ "nanoid": "^3.1.20",
+ "xml": "^1.0.1",
+ "xml-js": "^1.6.8"
+ },
+ "dependencies": {
+ "jszip": {
+ "version": "3.7.1",
+ "resolved": "https://registry.npmjs.org/jszip/-/jszip-3.7.1.tgz",
+ "integrity": "sha512-ghL0tz1XG9ZEmRMcEN2vt7xabrDdqHHeykgARpmZ0BiIctWxM47Vt63ZO2dnp4QYt/xJVLLy5Zv1l/xRdh2byg==",
+ "requires": {
+ "lie": "~3.3.0",
+ "pako": "~1.0.2",
+ "readable-stream": "~2.3.6",
+ "set-immediate-shim": "~1.0.1"
+ }
+ }
+ }
+ },
"dom-converter": {
"version": "0.2.0",
"resolved": "https://registry.npmjs.org/dom-converter/-/dom-converter-0.2.0.tgz",
@@ -42231,6 +42332,11 @@
}
}
},
+ "file-saver": {
+ "version": "2.0.5",
+ "resolved": "https://registry.npmjs.org/file-saver/-/file-saver-2.0.5.tgz",
+ "integrity": "sha512-P9bmyZ3h/PRG+Nzga+rbdI4OEpNDzAVyy74uVO9ATgzLK6VtAsYybF/+TOCvrc0MO793d6+42lLyZTw7/ArVzA=="
+ },
"file-select-dialog": {
"version": "1.5.4",
"resolved": "https://registry.npmjs.org/file-select-dialog/-/file-select-dialog-1.5.4.tgz",
@@ -42599,6 +42705,11 @@
"integrity": "sha512-cHEpEQHUg0f8XdtZCc2ZAhrHzKzT0MrFUTcvx+hfxYu7rGMDc5SKoXFh+n4YigxsHXRzc6OrCshdR1bWH6HHyg==",
"dev": true
},
+ "fs": {
+ "version": "0.0.1-security",
+ "resolved": "https://registry.npmjs.org/fs/-/fs-0.0.1-security.tgz",
+ "integrity": "sha1-invTcYa23d84E/I4WLV+yq9eQdQ="
+ },
"fs-extra": {
"version": "9.1.0",
"resolved": "https://registry.npmjs.org/fs-extra/-/fs-extra-9.1.0.tgz",
@@ -43722,6 +43833,11 @@
"integrity": "sha1-SMptcvbGo68Aqa1K5odr44ieKwk=",
"optional": true
},
+ "immediate": {
+ "version": "3.0.6",
+ "resolved": "https://registry.npmjs.org/immediate/-/immediate-3.0.6.tgz",
+ "integrity": "sha1-nbHb0Pr43m++D13V5Wu2BigN5ps="
+ },
"immer": {
"version": "8.0.1",
"resolved": "https://registry.npmjs.org/immer/-/immer-8.0.1.tgz",
@@ -46390,6 +46506,14 @@
"type-check": "~0.4.0"
}
},
+ "lie": {
+ "version": "3.3.0",
+ "resolved": "https://registry.npmjs.org/lie/-/lie-3.3.0.tgz",
+ "integrity": "sha512-UaiMJzeWRlEujzAuw5LokY1L5ecNQYZKfmyZ9L7wDHb/p5etKaxXhohBcrw0EYby+G/NA52vRSN4N39dxHAIwQ==",
+ "requires": {
+ "immediate": "~3.0.5"
+ }
+ },
"lines-and-columns": {
"version": "1.1.6",
"resolved": "https://registry.npmjs.org/lines-and-columns/-/lines-and-columns-1.1.6.tgz",
@@ -53645,6 +53769,11 @@
"resolved": "https://registry.npmjs.org/set-blocking/-/set-blocking-2.0.0.tgz",
"integrity": "sha1-BF+XgtARrppoA93TgrJDkrPYkPc="
},
+ "set-immediate-shim": {
+ "version": "1.0.1",
+ "resolved": "https://registry.npmjs.org/set-immediate-shim/-/set-immediate-shim-1.0.1.tgz",
+ "integrity": "sha1-SysbJ+uAip+NzEgaWOXlb1mfP2E="
+ },
"set-value": {
"version": "2.0.1",
"resolved": "https://registry.npmjs.org/set-value/-/set-value-2.0.1.tgz",
@@ -57928,6 +58057,19 @@
}
}
},
+ "xml": {
+ "version": "1.0.1",
+ "resolved": "https://registry.npmjs.org/xml/-/xml-1.0.1.tgz",
+ "integrity": "sha1-eLpyAgApxbyHuKgaPPzXS0ovweU="
+ },
+ "xml-js": {
+ "version": "1.6.11",
+ "resolved": "https://registry.npmjs.org/xml-js/-/xml-js-1.6.11.tgz",
+ "integrity": "sha512-7rVi2KMfwfWFl+GpPg6m80IVMWXLRjO+PxTq7V2CDhoGak0wzYzFgUY2m4XJ47OGdXd8eLE8EmwfAmdjw7lC1g==",
+ "requires": {
+ "sax": "^1.2.4"
+ }
+ },
"xml-name-validator": {
"version": "3.0.0",
"resolved": "https://registry.npmjs.org/xml-name-validator/-/xml-name-validator-3.0.0.tgz",
diff --git a/package.json b/package.json
index 206a9696..753f42e3 100644
--- a/package.json
+++ b/package.json
@@ -14,8 +14,11 @@
"dateformat": "^4.5.1",
"dexie": "^3.0.3",
"dexie-export-import": "^1.0.3",
+ "docx": "^7.3.0",
"downloadjs": "^1.4.7",
+ "file-saver": "^2.0.5",
"file-select-dialog": "^1.5.4",
+ "fs": "^0.0.1-security",
"html-react-parser": "^1.2.7",
"html2pdf.js": "^0.10.1",
"i18next": "^21.6.0",
diff --git a/src/App.js b/src/App.js
index a3a04da3..593b58b8 100644
--- a/src/App.js
+++ b/src/App.js
@@ -19,6 +19,7 @@ const Settings = lazy(() => import('./pages/Settings'));
const SourceMaterial = lazy(() => import('./pages/SourceMaterial'));
const Students = lazy(() => import('./pages/Students'));
const ScheduleTemplate = lazy(() => import('./template/ScheduleTemplate'));
+const S89Template = lazy(() => import('./template/S89Template'));
const Administration = lazy(() => import('./pages/Administration'));
const theme = createTheme({
@@ -89,6 +90,9 @@ const App = () => {
+
+
+
diff --git a/src/appStates/appSchedule.js b/src/appStates/appSchedule.js
index 1e5efed0..4e6324dd 100644
--- a/src/appStates/appSchedule.js
+++ b/src/appStates/appSchedule.js
@@ -64,3 +64,8 @@ export const isReloadScheduleState = atom({
key: 'isReloadSchedule',
default: false,
});
+
+export const s89DataState = atom({
+ key: 's89Data',
+ default: [],
+});
diff --git a/src/components/schedule/S89.js b/src/components/schedule/S89.js
index c5e8edb3..4df05bfa 100644
--- a/src/components/schedule/S89.js
+++ b/src/components/schedule/S89.js
@@ -1,237 +1,151 @@
-import { useEffect, useState } from "react";
-import { PDFDocument, TextAlignment } from 'pdf-lib';
+import { useEffect, useState } from 'react';
+import { useHistory } from 'react-router-dom';
+import { useRecoilValue, useSetRecoilState } from 'recoil';
+import { useTranslation } from 'react-i18next';
import Box from '@mui/material/Box';
-import Button from "@mui/material/Button";
+import Button from '@mui/material/Button';
import CircularProgress from '@mui/material/CircularProgress';
import Container from '@mui/material/Container';
-import PictureAsPdfIcon from '@mui/icons-material/PictureAsPdf';
import PlayArrowIcon from '@mui/icons-material/PlayArrow';
-import Typography from "@mui/material/Typography";
+import Typography from '@mui/material/Typography';
import WarningIcon from '@mui/icons-material/Warning';
-import { dbGetS89ItemData, dbGetS89WeekList } from "../../indexedDb/dbAssignment";
-import pdfS89 from '../../template/S-89_MG.pdf';
-import TreeViewCheckbox from "../reusable/TreeViewCheckbox";
-
-const S89 = (props) => {
- const [currentSchedule, setCurrentSchedule] = useState("");
- const [data, setData] = useState({});
- const [selected, setSelected] = useState([]);
- const [loading, setLoading] = useState(true);
- const [createPDF, setCreatePDF] = useState(false);
- const [disablePDF, setDisablePDF] = useState(false);
- const [pdfData64, setPdfData64] = useState(null);
-
- useEffect(() => {
- if (props.currentSchedule !== "") {
- setCurrentSchedule(props.currentSchedule);
- }
- }, [props.currentSchedule])
-
- useEffect(() => {
- const getDataS89 = async () => {
- const data = await dbGetS89WeekList(currentSchedule);
- setData(data);
- setLoading(false);
- }
- if (currentSchedule !== "") {
- getDataS89();
- }
- }, [currentSchedule])
-
- const handleGeneratePDF = async () => {
- const realData = selected.filter(item => item.length > 10);
- realData.sort((a, b) => {
- return a > b ? 1 : -1;
- });
-
- setCreatePDF(true);
- setPdfData64(null);
-
- const s89PdfBytes = await fetch(pdfS89).then(res => res.arrayBuffer());
- const s89Doc = await PDFDocument.create();
-
- for(let i = 0; i < realData.length; i++) {
- const week = realData[i].split("-")[0];
- const assType = realData[i].split("@")[1].split("-")[0];
- const classLabel = realData[i].split("-")[2];
-
- const data = await dbGetS89ItemData(week, assType, classLabel);
-
- const pdfDoc = await PDFDocument.load(s89PdfBytes);
- const form = pdfDoc.getForm();
- // PDFTextField: 900_1_Text - Student
- const mainStuField = form.getTextField("900_1_Text");
- mainStuField.setText(data.studentName);
- mainStuField.setFontSize(9);
- // PDFTextField: 900_2_Text - Assistant
- const assistantField = form.getTextField("900_2_Text");
- assistantField.setText(data.assistantName);
- assistantField.setFontSize(9);
- // PDFTextField: 900_3_Text - Date
- const dateAssignment = form.getTextField("900_3_Text");
- dateAssignment.setText(data.assignmentDate);
- dateAssignment.setFontSize(10);
- dateAssignment.setAlignment(TextAlignment.Center);
- // PDFCheckBox: 900_4_CheckBox - Bible Reading
- if (data.isBRead === true) {
- const checkBRead = form.getCheckBox("900_4_CheckBox");
- checkBRead.check();
- }
- // PDFCheckBox: 900_5_CheckBox - Initial Call
- if (data.isInitialCall === true) {
- const checkIniCall = form.getCheckBox("900_5_CheckBox");
- checkIniCall.check();
- }
- // PDFTextField: 900_6_Text - Initial Call indice
- const iniCallSpec = form.getTextField("900_6_Text");
- iniCallSpec.setText(data.initialCallSpec);
- iniCallSpec.setFontSize(8);
- // PDFCheckBox: 900_7_CheckBox - RV
- if (data.isReturnVisit === true) {
- const checkRV = form.getCheckBox("900_7_CheckBox");
- checkRV.check();
- }
- // PDFTextField: 900_8_Text - RV indice
- const rvSpec = form.getTextField("900_8_Text");
- rvSpec.setText(data.returnVisitSpec);
- rvSpec.setFontSize(8);
- // PDFCheckBox: 900_9_CheckBox - Bible Study
- if (data.isBibleStudy === true) {
- const checkBS = form.getCheckBox("900_9_CheckBox");
- checkBS.check();
- }
- // PDFCheckBox: 900_10_CheckBox - Talk
- if (data.isTalk === true) {
- const checkTalk = form.getCheckBox("900_10_CheckBox");
- checkTalk.check();
- }
- // PDFCheckBox: 900_11_CheckBox - Other
- // PDFTextField: 900_12_Text - Other indice
- // PDFCheckBox: 900_13_CheckBox - Main Hall
- if (data.isMainHall === true) {
- const checkMainHall = form.getCheckBox("900_13_CheckBox");
- checkMainHall.check();
- }
- // PDFCheckBox: 900_14_CheckBox - Aux Class 1
- if (data.isAuxClass === true) {
- const checkAuxClass = form.getCheckBox("900_14_CheckBox");
- checkAuxClass.check();
- }
- // PDFCheckBox: 900_15_CheckBox - Aux Class 2
-
- form.flatten();
- await pdfDoc.save();
- const [temp] = await s89Doc.copyPages(pdfDoc, [0]);
- await s89Doc.addPage(temp);
- await s89Doc.save();
- }
- const pdfUri = await s89Doc.saveAsBase64({ dataUri: true });
- setCreatePDF(false);
- setPdfData64(pdfUri);
- };
-
- const handleDownloadS89 = () => {
- const a = document.createElement('a');
- a.href = pdfData64;
- a.download = "S89.pdf";
- document.body.appendChild(a);
- a.click();
- document.body.removeChild(a);
- }
-
- useEffect(() => {
- setPdfData64(null);
- const realData = selected.filter(item => item.length > 10);
- if (realData.length === 0) {
- setDisablePDF(true);
- } else {
- setDisablePDF(false);
- }
- }, [selected])
-
- return (
-
- {loading && (
-
- )}
- {!loading && (
- <>
- {Object.keys(data).length > 2 && (
- <>
- {data.children.length > 0 && (
- <>
-
- }
- disabled={disablePDF}
- onClick={() => handleGeneratePDF()}
- sx={{marginRight: '10px'}}
- >
- PDF
-
- {createPDF && (
-
- )}
- {pdfData64 !== null && (
- }
- onClick={() => handleDownloadS89()}
- >
- Haka PDF
-
- )}
-
- setSelected(value)}
- defaultExpanded={["S89"]}
- />
- >
- )}
- {data.children.length === 0 && (
-
-
-
- Tsy misy anjara azo atao pirinty ao amin’io fandaharana io
-
-
- )}
- >
- )}
- >
- )}
-
- );
-}
-
-export default S89;
\ No newline at end of file
+import {
+ dbGetS89ItemData,
+ dbGetS89WeekList,
+} from '../../indexedDb/dbAssignment';
+import TreeViewCheckbox from '../reusable/TreeViewCheckbox';
+import {
+ currentScheduleState,
+ s89DataState,
+} from '../../appStates/appSchedule';
+
+const S89 = () => {
+ const { t } = useTranslation();
+ let history = useHistory();
+
+ const [data, setData] = useState({});
+ const [selected, setSelected] = useState([]);
+ const [loading, setLoading] = useState(true);
+ const [disablePDF, setDisablePDF] = useState(false);
+
+ const setS89Data = useSetRecoilState(s89DataState);
+
+ const currentSchedule = useRecoilValue(currentScheduleState);
+
+ useEffect(() => {
+ const getDataS89 = async () => {
+ const data = await dbGetS89WeekList(currentSchedule);
+ setData(data);
+ setLoading(false);
+ };
+ if (currentSchedule !== '') {
+ getDataS89();
+ }
+ }, [currentSchedule]);
+
+ const handlePreviewS89 = async () => {
+ const realData = selected.filter((item) => item.length > 10);
+ realData.sort((a, b) => {
+ return a > b ? 1 : -1;
+ });
+
+ let s89Data = [];
+
+ for (let i = 0; i < realData.length; i++) {
+ const week = realData[i].split('-')[0];
+ const assType = realData[i].split('@')[1].split('-')[0];
+ const classLabel = realData[i].split('-')[2];
+
+ const data = await dbGetS89ItemData(week, assType, classLabel);
+
+ let obj = {};
+ obj.id = realData[i];
+
+ s89Data.push({ ...obj, ...data });
+ }
+
+ setS89Data(s89Data);
+
+ history.push({
+ pathname: '/S89Template',
+ });
+ };
+
+ useEffect(() => {
+ const realData = selected.filter((item) => item.length > 10);
+ if (realData.length === 0) {
+ setDisablePDF(true);
+ } else {
+ setDisablePDF(false);
+ }
+ }, [selected]);
+
+ return (
+
+ {loading && (
+
+ )}
+ {!loading && (
+ <>
+ {Object.keys(data).length > 2 && (
+ <>
+ {data.children.length > 0 && (
+ <>
+
+ }
+ disabled={disablePDF}
+ onClick={() => handlePreviewS89()}
+ sx={{ marginRight: '10px' }}
+ >
+ {t('global.preview')}
+
+
+ setSelected(value)}
+ defaultExpanded={['S89']}
+ />
+ >
+ )}
+ {data.children.length === 0 && (
+
+
+
+ {t('schedule.s89NoData')}
+
+
+ )}
+ >
+ )}
+ >
+ )}
+
+ );
+};
+
+export default S89;
diff --git a/src/components/schedule/ScheduleDetails.js b/src/components/schedule/ScheduleDetails.js
index b4ee9659..25df7156 100644
--- a/src/components/schedule/ScheduleDetails.js
+++ b/src/components/schedule/ScheduleDetails.js
@@ -428,7 +428,7 @@ const ScheduleDetails = (props) => {
)}
{isS89 && (
)}
diff --git a/src/indexedDb/dbAssignment.js b/src/indexedDb/dbAssignment.js
index c751164f..c3b3859d 100644
--- a/src/indexedDb/dbAssignment.js
+++ b/src/indexedDb/dbAssignment.js
@@ -1,497 +1,601 @@
+import { getI18n } from 'react-i18next';
+import { promiseGetRecoil } from 'recoil-outside';
import { dbGetAppSettings } from './dbAppSettings';
import { dbGetStudentDetails } from './dbPersons';
import { dbGetScheduleData } from './dbSchedule';
import { dbGetSourceMaterial, dbGetWeekListBySched } from './dbSourceMaterial';
import appDb from './mainDb';
+import { assTypeLocalState } from '../appStates/appSourceMaterial';
+
+const dateFormat = require('dateformat');
+
+const { t } = getI18n();
export const dbGetAssType = async (assType, appLang) => {
- var srcAssType = "";
- if (assType === "") {
- return srcAssType;
- } else {
- var i = parseInt(assType, 10);
- const appData = await appDb.table("ass_type").get(i);
- srcAssType = appData.ass_type_name[appLang];
- return srcAssType;
- }
+ var srcAssType = '';
+ if (assType === '') {
+ return srcAssType;
+ } else {
+ var i = parseInt(assType, 10);
+ const appData = await appDb.table('ass_type').get(i);
+ srcAssType = appData.ass_type_name[appLang];
+ return srcAssType;
+ }
};
export const dbGetAssTypeId = async (assType, appLang) => {
- var srcAssType = "";
- if (assType === "") {
- return srcAssType;
- } else {
- const appData = await appDb.table("ass_type").get({"ass_type_name": assType});
- if (typeof appData === "undefined") {
- return "";
- } else {
- srcAssType = appData.id_type;
- return srcAssType;
- };
- }
+ var srcAssType = '';
+ if (assType === '') {
+ return srcAssType;
+ } else {
+ const appData = await appDb
+ .table('ass_type')
+ .get({ ass_type_name: assType });
+ if (typeof appData === 'undefined') {
+ return '';
+ } else {
+ srcAssType = appData.id_type;
+ return srcAssType;
+ }
+ }
};
export const dbGetListAssType = async () => {
- var assType = [];
- var obj = {};
- const appData = await appDb.table("ass_type").reverse().reverse().sortBy("id_type");
-
- for(let i=0; i < appData.length; i++) {
- obj = {};
- obj.id_type = appData[i].id_type;
- obj.ass_type_name = appData[i].ass_type_name;
- assType.push(obj);
- }
- return assType;
+ var assType = [];
+ var obj = {};
+ const appData = await appDb
+ .table('ass_type')
+ .reverse()
+ .reverse()
+ .sortBy('id_type');
+
+ for (let i = 0; i < appData.length; i++) {
+ obj = {};
+ obj.id_type = appData[i].id_type;
+ obj.ass_type_name = appData[i].ass_type_name;
+ assType.push(obj);
+ }
+ return assType;
};
export const dbSaveAss = async (weekOf, stuID, varSave, idAss) => {
- const appData = await appDb.table("sched_MM").get({"weekOf": weekOf});
- const stuPrev = appData[varSave];
+ const appData = await appDb.table('sched_MM').get({ weekOf: weekOf });
+ const stuPrev = appData[varSave];
- var obj = {};
- obj[varSave] = stuID;
+ var obj = {};
+ obj[varSave] = stuID;
- await appDb.table("sched_MM").update(weekOf, {...obj});
- await dbRefreshStudentHistory(stuPrev, stuID, idAss);
+ await appDb.table('sched_MM').update(weekOf, { ...obj });
+ await dbRefreshStudentHistory(stuPrev, stuID, idAss);
};
export const dbHistoryAssignment = async () => {
- const appData = await appDb.table("sched_MM").toArray();
- var dbHistory = [];
- var histID = 0;
- for(let i=0; i < appData.length; i++) {
- var person = {};
-
- const weekData = await dbGetSourceMaterial(appData[i].weekOf);
- var dateFormat = require("dateformat");
- const [varMonth, varDay, varYear] = appData[i].weekOf.split("/");
- const lDate = new Date(varYear, varMonth - 1, varDay);
- const dateFormatted = dateFormat(lDate, "dd/mm/yyyy");
- const cnAss = [{iAss: 1}, {iAss: 2}, {iAss: 3}, {iAss: 4}];
- const varClasses = [{classLabel: "A"}, {classLabel: "B"}];
-
- //Bible Reading History
- for(let a=0; a < varClasses.length; a++) {
- const fldName = "bRead_stu_" + varClasses[a].classLabel;
- if (typeof appData[i][fldName] !== "undefined") {
- person.ID = histID;
- person.weekOf = appData[i].weekOf;
- person.weekOfFormatted = dateFormatted;
- person.studentID = appData[i][fldName];
- const stuDetails = await dbGetStudentDetails(person.studentID);
- person.studentName = stuDetails.person_displayName;
- person.assignmentID = 0;
- person.assignmentName = "Famakiana Baiboly";
- person.class = varClasses[a].classLabel;
- dbHistory.push(person);
- person = {};
- histID++;
- }
- }
-
- //AYF Assigment History
- for(let b=0; b < cnAss.length; b++) {
- var weekFld = "ass" + cnAss[b].iAss + "_type";
- const assType = weekData[weekFld];
-
- for(let a=0; a < varClasses.length; a++) {
- var fldName = "ass" + cnAss[b].iAss + "_stu_" + varClasses[a].classLabel;
- if (typeof appData[i][fldName] !== "undefined") {
- person.ID = histID;
- person.weekOf = appData[i].weekOf;
- person.weekOfFormatted = dateFormatted;
- person.studentID = appData[i][fldName];
- const stuDetails = await dbGetStudentDetails(person.studentID);
- person.studentName = stuDetails.person_displayName;
- person.assignmentID = assType;
- if (assType === 1) {
- person.assignmentName = "Fitoriana";
- } else if (assType === 2) {
- person.assignmentName = "Fiverenana Mitsidika";
- } else if (assType === 3) {
- person.assignmentName = "Fampianarana Baiboly";
- } else if (assType === 4) {
- person.assignmentName = "Lahateny";
- }
- person.class = varClasses[a].classLabel;
- dbHistory.push(person);
- person = {};
- histID++;
- }
-
- fldName = "ass" + cnAss[b].iAss + "_ass_" + varClasses[a].classLabel;
- if (typeof appData[i][fldName] !== "undefined") {
- person.ID = histID;
- person.weekOf = appData[i].weekOf;
- person.weekOfFormatted = dateFormatted;
- person.studentID = appData[i][fldName];
- const stuDetails = await dbGetStudentDetails(person.studentID);
- person.studentName = stuDetails.person_displayName;
- person.assignmentID = 8;
- person.assignmentName = "Mpanampy";
- person.class = varClasses[a].classLabel;
- dbHistory.push(person);
- person = {};
- histID++;
- }
- }
- }
- }
- dbHistory.sort((a, b) => {
- var dateA = a.weekOf.split("/")[2] + "/" + a.weekOf.split("/")[0] + "/" + a.weekOf.split("/")[1];
- var dateB = b.weekOf.split("/")[2] + "/" + b.weekOf.split("/")[0] + "/" + b.weekOf.split("/")[1];
- return dateA < dateB ? 1 : -1;
- });
- return dbHistory;
+ const appData = await appDb.table('sched_MM').toArray();
+ var dbHistory = [];
+ var histID = 0;
+ for (let i = 0; i < appData.length; i++) {
+ var person = {};
+
+ const weekData = await dbGetSourceMaterial(appData[i].weekOf);
+ var dateFormat = require('dateformat');
+ const [varMonth, varDay, varYear] = appData[i].weekOf.split('/');
+ const lDate = new Date(varYear, varMonth - 1, varDay);
+ const dateFormatted = dateFormat(lDate, 'dd/mm/yyyy');
+ const cnAss = [{ iAss: 1 }, { iAss: 2 }, { iAss: 3 }, { iAss: 4 }];
+ const varClasses = [{ classLabel: 'A' }, { classLabel: 'B' }];
+
+ //Bible Reading History
+ for (let a = 0; a < varClasses.length; a++) {
+ const fldName = 'bRead_stu_' + varClasses[a].classLabel;
+ if (typeof appData[i][fldName] !== 'undefined') {
+ person.ID = histID;
+ person.weekOf = appData[i].weekOf;
+ person.weekOfFormatted = dateFormatted;
+ person.studentID = appData[i][fldName];
+ const stuDetails = await dbGetStudentDetails(person.studentID);
+ person.studentName = stuDetails.person_displayName;
+ person.assignmentID = 0;
+ person.assignmentName = 'Famakiana Baiboly';
+ person.class = varClasses[a].classLabel;
+ dbHistory.push(person);
+ person = {};
+ histID++;
+ }
+ }
+
+ //AYF Assigment History
+ for (let b = 0; b < cnAss.length; b++) {
+ var weekFld = 'ass' + cnAss[b].iAss + '_type';
+ const assType = weekData[weekFld];
+
+ for (let a = 0; a < varClasses.length; a++) {
+ var fldName =
+ 'ass' + cnAss[b].iAss + '_stu_' + varClasses[a].classLabel;
+ if (typeof appData[i][fldName] !== 'undefined') {
+ person.ID = histID;
+ person.weekOf = appData[i].weekOf;
+ person.weekOfFormatted = dateFormatted;
+ person.studentID = appData[i][fldName];
+ const stuDetails = await dbGetStudentDetails(person.studentID);
+ person.studentName = stuDetails.person_displayName;
+ person.assignmentID = assType;
+ if (assType === 1) {
+ person.assignmentName = 'Fitoriana';
+ } else if (assType === 2) {
+ person.assignmentName = 'Fiverenana Mitsidika';
+ } else if (assType === 3) {
+ person.assignmentName = 'Fampianarana Baiboly';
+ } else if (assType === 4) {
+ person.assignmentName = 'Lahateny';
+ }
+ person.class = varClasses[a].classLabel;
+ dbHistory.push(person);
+ person = {};
+ histID++;
+ }
+
+ fldName = 'ass' + cnAss[b].iAss + '_ass_' + varClasses[a].classLabel;
+ if (typeof appData[i][fldName] !== 'undefined') {
+ person.ID = histID;
+ person.weekOf = appData[i].weekOf;
+ person.weekOfFormatted = dateFormatted;
+ person.studentID = appData[i][fldName];
+ const stuDetails = await dbGetStudentDetails(person.studentID);
+ person.studentName = stuDetails.person_displayName;
+ person.assignmentID = 8;
+ person.assignmentName = 'Mpanampy';
+ person.class = varClasses[a].classLabel;
+ dbHistory.push(person);
+ person = {};
+ histID++;
+ }
+ }
+ }
+ }
+ dbHistory.sort((a, b) => {
+ var dateA =
+ a.weekOf.split('/')[2] +
+ '/' +
+ a.weekOf.split('/')[0] +
+ '/' +
+ a.weekOf.split('/')[1];
+ var dateB =
+ b.weekOf.split('/')[2] +
+ '/' +
+ b.weekOf.split('/')[0] +
+ '/' +
+ b.weekOf.split('/')[1];
+ return dateA < dateB ? 1 : -1;
+ });
+ return dbHistory;
};
export const dbLastBRead = async (stuID) => {
- stuID = parseInt(stuID, 10);
- const appData = await dbHistoryAssignment();
- const lastBRead = appData.filter(data => data.assignmentID === 0 & data.studentID === stuID);
-
- var dLast;
- if (lastBRead.length > 0) {
- dLast = lastBRead[0].weekOf;
- }
- return dLast;
-}
+ stuID = parseInt(stuID, 10);
+ const appData = await dbHistoryAssignment();
+ const lastBRead = appData.filter(
+ (data) => (data.assignmentID === 0) & (data.studentID === stuID)
+ );
+
+ var dLast;
+ if (lastBRead.length > 0) {
+ dLast = lastBRead[0].weekOf;
+ }
+ return dLast;
+};
export const dbLastIniCall = async (stuID) => {
- stuID = parseInt(stuID, 10);
- const appData = await dbHistoryAssignment();
- const lastIniCall = appData.filter(data => data.assignmentID === 1 & data.studentID === stuID);
-
- var dLast;
- if (lastIniCall.length > 0) {
- dLast = lastIniCall[0].weekOf;
- }
- return dLast;
-}
+ stuID = parseInt(stuID, 10);
+ const appData = await dbHistoryAssignment();
+ const lastIniCall = appData.filter(
+ (data) => (data.assignmentID === 1) & (data.studentID === stuID)
+ );
+
+ var dLast;
+ if (lastIniCall.length > 0) {
+ dLast = lastIniCall[0].weekOf;
+ }
+ return dLast;
+};
export const dbLastRV = async (stuID) => {
- stuID = parseInt(stuID, 10);
- const appData = await dbHistoryAssignment();
- const lastRV = appData.filter(data => data.assignmentID === 2 & data.studentID === stuID);
-
- var dLast;
- if (lastRV.length > 0) {
- dLast = lastRV[0].weekOf;
- }
- return dLast;
-}
+ stuID = parseInt(stuID, 10);
+ const appData = await dbHistoryAssignment();
+ const lastRV = appData.filter(
+ (data) => (data.assignmentID === 2) & (data.studentID === stuID)
+ );
+
+ var dLast;
+ if (lastRV.length > 0) {
+ dLast = lastRV[0].weekOf;
+ }
+ return dLast;
+};
export const dbLastBibleStudy = async (stuID) => {
- stuID = parseInt(stuID, 10);
- const appData = await dbHistoryAssignment();
- const lastBibleStudy = appData.filter(data => data.assignmentID === 3 & data.studentID === stuID);
-
- var dLast;
- if (lastBibleStudy.length > 0) {
- dLast = lastBibleStudy[0].weekOf;
- }
- return dLast;
-}
+ stuID = parseInt(stuID, 10);
+ const appData = await dbHistoryAssignment();
+ const lastBibleStudy = appData.filter(
+ (data) => (data.assignmentID === 3) & (data.studentID === stuID)
+ );
+
+ var dLast;
+ if (lastBibleStudy.length > 0) {
+ dLast = lastBibleStudy[0].weekOf;
+ }
+ return dLast;
+};
export const dbLastTalk = async (stuID) => {
- stuID = parseInt(stuID, 10);
- const appData = await dbHistoryAssignment();
- const lastTalk = appData.filter(data => data.assignmentID === 4 & data.studentID === stuID);
-
- var dLast;
- if (lastTalk.length > 0) {
- dLast = lastTalk[0].weekOf;
- }
- return dLast;
-}
+ stuID = parseInt(stuID, 10);
+ const appData = await dbHistoryAssignment();
+ const lastTalk = appData.filter(
+ (data) => (data.assignmentID === 4) & (data.studentID === stuID)
+ );
+
+ var dLast;
+ if (lastTalk.length > 0) {
+ dLast = lastTalk[0].weekOf;
+ }
+ return dLast;
+};
export const dbLastAssistant = async (stuID) => {
- stuID = parseInt(stuID, 10);
- const appData = await dbHistoryAssignment();
- const lastAssistant = appData.filter(data => data.assignmentID === 8 & data.studentID === stuID);
- var dLast;
- if (lastAssistant.length > 0) {
- dLast = lastAssistant[0].weekOf;
- }
- return dLast;
-}
+ stuID = parseInt(stuID, 10);
+ const appData = await dbHistoryAssignment();
+ const lastAssistant = appData.filter(
+ (data) => (data.assignmentID === 8) & (data.studentID === stuID)
+ );
+ var dLast;
+ if (lastAssistant.length > 0) {
+ dLast = lastAssistant[0].weekOf;
+ }
+ return dLast;
+};
export const dbLastAssignment = async (stuID) => {
- stuID = parseInt(stuID, 10);
- const appData = await dbHistoryAssignment();
- const lastAssignment = appData.filter(data => data.studentID === stuID);
- var dLast;
- if (lastAssignment.length > 0) {
- dLast = lastAssignment[0].weekOf;
- }
- return dLast;
+ stuID = parseInt(stuID, 10);
+ const appData = await dbHistoryAssignment();
+ const lastAssignment = appData.filter((data) => data.studentID === stuID);
+ var dLast;
+ if (lastAssignment.length > 0) {
+ dLast = lastAssignment[0].weekOf;
+ }
+ return dLast;
};
export const dbRefreshStudentHistory = async (varPrev, varNew, varAss) => {
- let varPers;
- for(let a=1; a <= 2; a++) {
- if (a === 1) {
- varPers = varPrev;
- } else {
- varPers = varNew;
- }
-
- if ((typeof varPers !== "undefined") & (varPers !== "")) {
- const stuBRead = await dbLastBRead(varPers);
- const stuIniCall = await dbLastIniCall(varPers);
- const stuRV = await dbLastRV(varPers);
- const stuBS = await dbLastBibleStudy(varPers);
- const stuAssistant = await dbLastAssistant(varPers);
- const stuTalk = await dbLastTalk(varPers);
- const stuAssignment = await dbLastAssignment(varPers);
-
- var fldToUpdate;
- var newValue;
-
- if (varAss === 0) {
- fldToUpdate = "lastBRead";
- newValue = stuBRead;
- } else if (varAss === 1) {
- fldToUpdate = "lastInitialCall";
- newValue = stuIniCall;
- } else if (varAss === 2) {
- fldToUpdate = "lastReturnVisit";
- newValue = stuRV;
- } else if (varAss === 3) {
- fldToUpdate = "lastBibleStudy";
- newValue = stuBS;
- } else if (varAss === 4) {
- fldToUpdate = "lastTalk";
- newValue = stuTalk;
- } else if (varAss === 8) {
- fldToUpdate = "lastAssistant";
- newValue = stuAssistant;
- }
-
- const idPers = parseInt(varPers, 10);
- var obj = {};
- obj[fldToUpdate] = newValue;
- obj.lastAssignment = stuAssignment;
- await appDb.table("persons").update(idPers, {...obj});
- }
- }
+ let varPers;
+ for (let a = 1; a <= 2; a++) {
+ if (a === 1) {
+ varPers = varPrev;
+ } else {
+ varPers = varNew;
+ }
+
+ if ((typeof varPers !== 'undefined') & (varPers !== '')) {
+ const stuBRead = await dbLastBRead(varPers);
+ const stuIniCall = await dbLastIniCall(varPers);
+ const stuRV = await dbLastRV(varPers);
+ const stuBS = await dbLastBibleStudy(varPers);
+ const stuAssistant = await dbLastAssistant(varPers);
+ const stuTalk = await dbLastTalk(varPers);
+ const stuAssignment = await dbLastAssignment(varPers);
+
+ var fldToUpdate;
+ var newValue;
+
+ if (varAss === 0) {
+ fldToUpdate = 'lastBRead';
+ newValue = stuBRead;
+ } else if (varAss === 1) {
+ fldToUpdate = 'lastInitialCall';
+ newValue = stuIniCall;
+ } else if (varAss === 2) {
+ fldToUpdate = 'lastReturnVisit';
+ newValue = stuRV;
+ } else if (varAss === 3) {
+ fldToUpdate = 'lastBibleStudy';
+ newValue = stuBS;
+ } else if (varAss === 4) {
+ fldToUpdate = 'lastTalk';
+ newValue = stuTalk;
+ } else if (varAss === 8) {
+ fldToUpdate = 'lastAssistant';
+ newValue = stuAssistant;
+ }
+
+ const idPers = parseInt(varPers, 10);
+ var obj = {};
+ obj[fldToUpdate] = newValue;
+ obj.lastAssignment = stuAssignment;
+ await appDb.table('persons').update(idPers, { ...obj });
+ }
+ }
};
export const dbGetS89WeekList = async (scheduleName) => {
- var s89Data = [];
- const allWeeks = await dbGetWeekListBySched(scheduleName);
- for (let i=0; i < allWeeks.length; i++) {
- const week = allWeeks[i].value;
- const scheduleData = await dbGetScheduleData(week);
- if (!scheduleData.noMeeting) {
- var parentWeek = {};
- parentWeek.value = week;
- const day = week.split("/")[1];
- const month = week.split("/")[0];
- const year = week.split("/")[2];
- const weekDateFormatted = day + "/" + month + "/" + year;
- parentWeek.label = weekDateFormatted;
- parentWeek.children = [];
-
- const sourceData = await dbGetSourceMaterial(week);
-
- if (scheduleData.bRead_stu_A !== "" || scheduleData.bRead_stu_B !== "") {
- var assType = {};
- assType.label = "Famakiana Baiboly";
- assType.value = week + "-0@bRead-A";
- if (scheduleData.bRead_stu_A !== "" && scheduleData.bRead_stu_B !== "") {
- assType.children = [];
- var assClass = {};
- assClass.value = week + "-0@bRead-A";
- assClass.label = "Kilasy A"
- assType.children.push(assClass);
- assClass.value = week + "-0@bRead-B";
- assClass.label = "Kilasy B"
- assType.children.push(assClass);
- }
- parentWeek.children.push(assType);
- }
-
- for(let i=1; i <= 4; i++) {
- const fldStuA = "ass" + i + "_stu_A";
- const fldStuB = "ass" + i + "_stu_B";
- const fldAss = "ass" + i + "_type";
- if (scheduleData[fldStuA] !== undefined || scheduleData[fldStuB] !== undefined) {
- if (scheduleData[fldStuA] !== "" || scheduleData[fldStuB] !== "") {
- assType = {};
- assType.label = await dbGetAssType(sourceData[fldAss]);
- assType.value = week + "-" + i + "@ass" + i + "-A";
- if (scheduleData[fldStuA] !== "" && scheduleData[fldStuB] !== "") {
- assType.children = [];
- assClass = {};
- assClass.value = week + "-" + i + "@ass" + i + "-A";
- assClass.label = "Kilasy A"
- assType.children.push(assClass);
- assClass.value = week + "-" + i + "@ass" + i + "-B";
- assClass.label = "Kilasy B"
- assType.children.push(assClass);
- }
- parentWeek.children.push(assType);
- }
- }
- }
- if (parentWeek.children.length > 0) {
- s89Data.push(parentWeek);
- }
- }
-
- }
- var obj = {};
- obj.value = "S89";
- obj.label = "Herinandro Rehetra";
- obj.children = s89Data;
- return obj;
-}
+ var s89Data = [];
+ const allWeeks = await dbGetWeekListBySched(scheduleName);
+ for (let i = 0; i < allWeeks.length; i++) {
+ const week = allWeeks[i].value;
+ const scheduleData = await dbGetScheduleData(week);
+ if (!scheduleData.noMeeting) {
+ var parentWeek = {};
+ parentWeek.value = week;
+ const dateW = new Date(week);
+ const weekDateFormatted = dateFormat(dateW, t('global.shortDateFormat'));
+ parentWeek.label = weekDateFormatted;
+ parentWeek.children = [];
+
+ const sourceData = await dbGetSourceMaterial(week);
+
+ if (scheduleData.bRead_stu_A !== '' || scheduleData.bRead_stu_B !== '') {
+ var assType = {};
+ assType.label = t('global.bibleReading');
+ assType.value = week + '-0@bRead-A';
+ if (
+ scheduleData.bRead_stu_A !== '' &&
+ scheduleData.bRead_stu_B !== ''
+ ) {
+ assType.children = [];
+ var assClass = {};
+ assClass.value = week + '-0@bRead-A';
+ assClass.label = t('global.mainHall');
+ assType.children.push(assClass);
+ assClass.value = week + '-0@bRead-B';
+ assClass.label = t('global.auxClass1');
+ assType.children.push(assClass);
+ }
+ parentWeek.children.push(assType);
+ }
+
+ const assTypeList = await promiseGetRecoil(assTypeLocalState);
+ for (let i = 1; i <= 4; i++) {
+ const fldStuA = 'ass' + i + '_stu_A';
+ const fldStuB = 'ass' + i + '_stu_B';
+ const fldAss = 'ass' + i + '_type';
+ if (
+ scheduleData[fldStuA] !== undefined ||
+ scheduleData[fldStuB] !== undefined
+ ) {
+ if (scheduleData[fldStuA] !== '' || scheduleData[fldStuB] !== '') {
+ assType = {};
+ let indexType;
+ indexType = assTypeList.findIndex(
+ (type) => type.value === sourceData[fldAss]
+ );
+ assType.label = indexType >= 0 ? assTypeList[indexType].label : '';
+ assType.value = week + '-' + i + '@ass' + i + '-A';
+ if (scheduleData[fldStuA] !== '' && scheduleData[fldStuB] !== '') {
+ assType.children = [];
+ assClass = {};
+ assClass.value = week + '-' + i + '@ass' + i + '-A';
+ assClass.label = t('global.mainHall');
+ assType.children.push(assClass);
+ assClass.value = week + '-' + i + '@ass' + i + '-B';
+ assClass.label = t('global.auxClass1');
+ assType.children.push(assClass);
+ }
+ parentWeek.children.push(assType);
+ }
+ }
+ }
+ if (parentWeek.children.length > 0) {
+ s89Data.push(parentWeek);
+ }
+ }
+ }
+ var obj = {};
+ obj.value = 'S89';
+ obj.label = t('global.allWeeks');
+ obj.children = s89Data;
+ return obj;
+};
export const dbGetS89ItemData = async (week, assName, classLabel) => {
- var stuFld = "";
- var assFld = "";
- var assTimeFld = "";
- var assTypeFld = 0;
-
- if (assName === "bRead") {
- stuFld = "bRead_stu_" + classLabel;
- } else if (assName === "ass1") {
- stuFld = "ass1_stu_" + classLabel;
- assFld = "ass1_ass_" + classLabel;
- assTypeFld = "ass1_type";
- assTimeFld = "ass1_time";
- } else if (assName === "ass2") {
- stuFld = "ass2_stu_" + classLabel;
- assFld = "ass2_ass_" + classLabel;
- assTypeFld = "ass2_type";
- assTimeFld = "ass2_time";
- } else if (assName === "ass3") {
- stuFld = "ass3_stu_" + classLabel;
- assFld = "ass3_ass_" + classLabel;
- assTypeFld = "ass3_type";
- assTimeFld = "ass3_time";
- } else if (assName === "ass4") {
- stuFld = "ass4_stu_" + classLabel;
- assFld = "ass4_ass_" + classLabel;
- assTypeFld = "ass4_type";
- assTimeFld = "ass4_time";
- };
-
- const appSettings = await dbGetAppSettings();
- var midDay = parseInt(appSettings.meeting_day, 10);
-
- var dateFormat = require("dateformat");
- const [varMonth, varDay, varYear] = week.split("/");
- midDay = parseInt(varDay, 10) + midDay - 1;
- const lDate = new Date(varYear, varMonth - 1, midDay);
- const dateFormatted = dateFormat(lDate, "dd/mm/yyyy");
-
- const sourceData = await dbGetSourceMaterial(week);
- const scheduleData = await dbGetScheduleData(week);
-
- var s89Data = {};
- const stuID = scheduleData[stuFld];
- const { person_name } = await dbGetStudentDetails(stuID);
- s89Data.studentName = person_name;
- s89Data.assistantName = "";
- s89Data.isBRead = false;
- s89Data.isInitialCall = false;
- s89Data.initialCallSpec = "";
- s89Data.isReturnVisit = false;
- s89Data.returnVisitSpec = "";
- s89Data.isBibleStudy = false;
- s89Data.bibleStudySpec = "";
- s89Data.isTalk = false;
- s89Data.assignmentDate = dateFormatted;
-
- if (assName === "ass1" || assName === "ass2" || assName === "ass3" || assName === "ass4") {
- const assType = sourceData[assTypeFld];
- if ((assType === 1) || (assType === 2) || (assType === 3)) {
- const assID = scheduleData[assFld];
- if (typeof assID !== "undefined" && assID !== "") {
- const assInfo = await dbGetStudentDetails(assID);
- s89Data.assistantName = assInfo.person_name;
- }
- }
-
- const ass1Type = sourceData["ass1_type"];
- const ass2Type = sourceData["ass2_type"];
- const ass3Type = sourceData["ass3_type"];
- const ass4Type = sourceData["ass4_type"];
- const assTime = sourceData[assTimeFld];
-
- if (assType === 1) {
- s89Data.isInitialCall = true;
- if (assName === "ass1") {
- if (ass1Type === ass2Type || ass1Type === ass3Type || ass1Type === ass4Type) {
- s89Data.initialCallSpec = "Anjara 1 (" + assTime + " min.)";
- }
- } else if (assName === "ass2") {
- if (ass2Type === ass1Type || ass2Type === ass3Type || ass2Type === ass4Type) {
- s89Data.initialCallSpec = "Anjara 2 (" + assTime + " min.)";
- }
- } else if (assName === "ass3") {
- if (ass3Type === ass1Type || ass3Type === ass2Type || ass3Type === ass4Type) {
- s89Data.initialCallSpec = "Anjara 3 (" + assTime + " min.)";
- }
- } else if (assName === "ass4") {
- if (ass4Type === ass1Type || ass4Type === ass2Type || ass4Type === ass3Type) {
- s89Data.initialCallSpec = "Anjara 3 (" + assTime + " min.)";
- }
- }
- } else if (assType === 2) {
- s89Data.isReturnVisit = true;
- if (assName === "ass1") {
- if (ass1Type === ass2Type || ass1Type === ass3Type || ass1Type === ass4Type) {
- s89Data.returnVisitSpec = "Anjara 1 (" + assTime + " min.)";
- }
- } else if (assName === "ass2") {
- if (ass2Type === ass1Type || ass2Type === ass3Type || ass2Type === ass4Type) {
- s89Data.returnVisitSpec = "Anjara 2 (" + assTime + " min.)";
- }
- } else if (assName === "ass3") {
- if (ass3Type === ass1Type || ass3Type === ass2Type || ass3Type === ass4Type) {
- s89Data.returnVisitSpec = "Anjara 3 (" + assTime + " min.)";
- }
- } else if (assName === "ass4") {
- if (ass4Type === ass1Type || ass4Type === ass2Type || ass4Type === ass3Type) {
- s89Data.returnVisitSpec = "Anjara 3 (" + assTime + " min.)";
- }
- }
- } else if (assType === 3) {
- s89Data.isBibleStudy = true;
- } else if (assType === 4) {
- s89Data.isTalk = true;
- }
- } else {
- s89Data.isBRead = true;
- }
-
- if (classLabel === "A") {
- s89Data.isMainHall = true;
- s89Data.isAuxClass = false;
- } else {
- s89Data.isMainHall = false;
- s89Data.isAuxClass = true;
- }
-
- return s89Data;
+ var stuFld = '';
+ var assFld = '';
+ var assTimeFld = '';
+ var assTypeFld = 0;
+
+ if (assName === 'bRead') {
+ stuFld = 'bRead_stu_' + classLabel;
+ } else if (assName === 'ass1') {
+ stuFld = 'ass1_stu_' + classLabel;
+ assFld = 'ass1_ass_' + classLabel;
+ assTypeFld = 'ass1_type';
+ assTimeFld = 'ass1_time';
+ } else if (assName === 'ass2') {
+ stuFld = 'ass2_stu_' + classLabel;
+ assFld = 'ass2_ass_' + classLabel;
+ assTypeFld = 'ass2_type';
+ assTimeFld = 'ass2_time';
+ } else if (assName === 'ass3') {
+ stuFld = 'ass3_stu_' + classLabel;
+ assFld = 'ass3_ass_' + classLabel;
+ assTypeFld = 'ass3_type';
+ assTimeFld = 'ass3_time';
+ } else if (assName === 'ass4') {
+ stuFld = 'ass4_stu_' + classLabel;
+ assFld = 'ass4_ass_' + classLabel;
+ assTypeFld = 'ass4_type';
+ assTimeFld = 'ass4_time';
+ }
+
+ const appSettings = await dbGetAppSettings();
+ var midDay = parseInt(appSettings.meeting_day, 10);
+
+ const [varMonth, varDay, varYear] = week.split('/');
+ midDay = parseInt(varDay, 10) + midDay - 1;
+ const lDate = new Date(varYear, varMonth - 1, midDay);
+ const dateFormatted = dateFormat(lDate, t('global.shortDateFormat'));
+
+ const sourceData = await dbGetSourceMaterial(week);
+ const scheduleData = await dbGetScheduleData(week);
+
+ var s89Data = {};
+ const stuID = scheduleData[stuFld];
+ const { person_name } = await dbGetStudentDetails(stuID);
+ s89Data.studentName = person_name;
+ s89Data.assistantName = '';
+ s89Data.isBRead = false;
+ s89Data.isInitialCall = false;
+ s89Data.initialCallSpec = '';
+ s89Data.isReturnVisit = false;
+ s89Data.returnVisitSpec = '';
+ s89Data.isBibleStudy = false;
+ s89Data.bibleStudySpec = '';
+ s89Data.isTalk = false;
+ s89Data.assignmentDate = dateFormatted;
+
+ if (
+ assName === 'ass1' ||
+ assName === 'ass2' ||
+ assName === 'ass3' ||
+ assName === 'ass4'
+ ) {
+ const assType = sourceData[assTypeFld];
+ if (assType === 1 || assType === 2 || assType === 3) {
+ const assID = scheduleData[assFld];
+ if (typeof assID !== 'undefined' && assID !== '') {
+ const assInfo = await dbGetStudentDetails(assID);
+ s89Data.assistantName = assInfo.person_name;
+ }
+ }
+
+ const ass1Type = sourceData['ass1_type'];
+ const ass2Type = sourceData['ass2_type'];
+ const ass3Type = sourceData['ass3_type'];
+ const ass4Type = sourceData['ass4_type'];
+ const assTime = sourceData[assTimeFld];
+
+ if (assType === 1) {
+ s89Data.isInitialCall = true;
+ if (assName === 'ass1') {
+ if (
+ ass1Type === ass2Type ||
+ ass1Type === ass3Type ||
+ ass1Type === ass4Type
+ ) {
+ s89Data.initialCallSpec = t('schedule.assignmentPart', {
+ id: 1,
+ time: assTime,
+ });
+ }
+ } else if (assName === 'ass2') {
+ if (
+ ass2Type === ass1Type ||
+ ass2Type === ass3Type ||
+ ass2Type === ass4Type
+ ) {
+ s89Data.initialCallSpec = t('schedule.assignmentPart', {
+ id: 2,
+ time: assTime,
+ });
+ }
+ } else if (assName === 'ass3') {
+ if (
+ ass3Type === ass1Type ||
+ ass3Type === ass2Type ||
+ ass3Type === ass4Type
+ ) {
+ s89Data.initialCallSpec = t('schedule.assignmentPart', {
+ id: 3,
+ time: assTime,
+ });
+ }
+ } else if (assName === 'ass4') {
+ if (
+ ass4Type === ass1Type ||
+ ass4Type === ass2Type ||
+ ass4Type === ass3Type
+ ) {
+ s89Data.initialCallSpec = t('schedule.assignmentPart', {
+ id: 4,
+ time: assTime,
+ });
+ }
+ }
+ } else if (assType === 2) {
+ s89Data.isReturnVisit = true;
+ if (assName === 'ass1') {
+ if (
+ ass1Type === ass2Type ||
+ ass1Type === ass3Type ||
+ ass1Type === ass4Type
+ ) {
+ s89Data.returnVisitSpec = t('schedule.assignmentPart', {
+ id: 1,
+ time: assTime,
+ });
+ }
+ } else if (assName === 'ass2') {
+ if (
+ ass2Type === ass1Type ||
+ ass2Type === ass3Type ||
+ ass2Type === ass4Type
+ ) {
+ s89Data.returnVisitSpec = t('schedule.assignmentPart', {
+ id: 2,
+ time: assTime,
+ });
+ }
+ } else if (assName === 'ass3') {
+ if (
+ ass3Type === ass1Type ||
+ ass3Type === ass2Type ||
+ ass3Type === ass4Type
+ ) {
+ s89Data.returnVisitSpec = t('schedule.assignmentPart', {
+ id: 3,
+ time: assTime,
+ });
+ }
+ } else if (assName === 'ass4') {
+ if (
+ ass4Type === ass1Type ||
+ ass4Type === ass2Type ||
+ ass4Type === ass3Type
+ ) {
+ s89Data.returnVisitSpec = t('schedule.assignmentPart', {
+ id: 4,
+ time: assTime,
+ });
+ }
+ }
+ } else if (assType === 3) {
+ s89Data.isBibleStudy = true;
+ } else if (assType === 4) {
+ s89Data.isTalk = true;
+ }
+ } else {
+ s89Data.isBRead = true;
+ }
+
+ if (classLabel === 'A') {
+ s89Data.isMainHall = true;
+ s89Data.isAuxClass = false;
+ } else {
+ s89Data.isMainHall = false;
+ s89Data.isAuxClass = true;
+ }
+
+ return s89Data;
};
export const dbGetScheduleForPrint = async (scheduleName) => {
- var data = [];
- const allWeeks = await dbGetWeekListBySched(scheduleName);
- for (let i=0; i < allWeeks.length; i++) {
- const week = allWeeks[i].value;
- const scheduleData = await dbGetScheduleData(week);
- const sourceData = await dbGetSourceMaterial(week);
- var obj = {};
- obj.week = week;
- obj.scheduleData = scheduleData;
- obj.sourceData = sourceData;
- data.push(obj);
- }
- return data;
-}
\ No newline at end of file
+ var data = [];
+ const allWeeks = await dbGetWeekListBySched(scheduleName);
+ for (let i = 0; i < allWeeks.length; i++) {
+ const week = allWeeks[i].value;
+ const scheduleData = await dbGetScheduleData(week);
+ const sourceData = await dbGetSourceMaterial(week);
+ var obj = {};
+ obj.week = week;
+ obj.scheduleData = scheduleData;
+ obj.sourceData = sourceData;
+ data.push(obj);
+ }
+ return data;
+};
diff --git a/src/locales/e.json b/src/locales/e.json
index 454a80fd..98fdfa3f 100644
--- a/src/locales/e.json
+++ b/src/locales/e.json
@@ -86,6 +86,12 @@
"global.assignment": "Assignment",
"global.assistant": "Assistant",
"global.pleaseWait": "Please wait ...",
+ "global.download": "Download",
+ "global.mainHall": "Main Hall",
+ "global.auxClass1": "Auxiliary Classroom 1",
+ "global.auxClass2": "Auxiliary Classroom 2",
+ "global.allWeeks": "All weeks",
+ "global.preview": "Preview",
"startup.welcomeTitle": "Welcome to LMM-OA",
"startup.welcomeDescription": "LMM-OA (or Life and Ministry Meeting Overseer Assistant) is an application designed for the Life and Ministry Meeting Overseer.",
@@ -185,6 +191,12 @@
"schedule.deleteAllLabel": "All weeks",
"schedule.deleteWeekOnlyLabel": "{{ currentWeek }} only",
"schedule.assistantHistory": "{{ currentStudent }} (Assistant History)",
+ "schedule.s89NoData": "There is no assignment to be printed for this schedule",
+ "schedule.assignmentPart": "Part {{ id }} ({{ time }}.)",
+
+ "s89.title": "OUR CHRISTIAN LIFE AND MINISTRY
MEETING ASSIGNMENT",
+ "s89.toBeGiven": "To be given in:",
+ "s89.descFooter": "Note to student: The source material and study point for your assignment can be found in the Life and Ministry Meeting Workbook. Please work on the listed study point, which is discussed in the Teaching brochure.",
"about.description": "LMM-OA (Life and Ministry Meeting Overseer Assistant) is an application to coordinate and manage students assignment schedule for Midweek Meeting."
}
\ No newline at end of file
diff --git a/src/locales/mg.json b/src/locales/mg.json
index ece08817..d43125d2 100644
--- a/src/locales/mg.json
+++ b/src/locales/mg.json
@@ -86,6 +86,12 @@
"global.assignment": "Anjara",
"global.assistant": "Mpanampy",
"global.pleaseWait": "Miandrasa kely ...",
+ "global.download": "Haka",
+ "global.mainHall": "Efitrano lehibe",
+ "global.auxClass1": "Efitrano faharoa",
+ "global.auxClass2": "Efitrano fahatelo",
+ "global.allWeeks": "Herinandro rehetra",
+ "global.preview": "Hijery mialoha",
"startup.welcomeTitle": "Tongasoa eto amin’ny LMM-OA",
"startup.welcomeDescription": "Programa natao ho ampiasain’ny Mpiandraikitra ny Fivoriana Momba ny Fiainantsika sy ny Fanompoana ny LMM-OA (na Life and Ministry Meeting Overseer Assistant).",
@@ -185,6 +191,12 @@
"schedule.deleteAllLabel": "Herinandro rehetra",
"schedule.deleteWeekOnlyLabel": "{{ currentWeek }} ihany",
"schedule.assistantHistory": "{{ currentStudent }} (Mpanampy efa niaraka taminy)",
+ "schedule.s89NoData": "Tsy misy anjara azo atao pirinty ao amin’io fandaharana io",
+ "schedule.assignmentPart": "Anjara {{ id }} ({{ time }}.)",
+
+ "s89.title": "ANJARA AMIN’NY FIVORIANA MOMBA
NY FIAINANTSIKA SY NY FANOMPOANA",
+ "s89.toBeGiven": "Hatao ao amin’ny:",
+ "s89.descFooter": "Ho an’ny mpianatra: Hita ao amin’ny Tari-dalana ho An’ny Fiainantsika sy ny Fanompoana ny loharanon-kevitra sy ny lesona ho an’ny anjaranao. Omano mifanaraka amin’ireo lesona ao amin’ny bokikely Miezaha izany.",
"about.description": "Programa fandaminana anjaran’ny mpianatra amin’ny fivoriana andavanandro ny LMM-OA (Life and Ministry Meeting Overseer Assistant)."
}
\ No newline at end of file
diff --git a/src/pages/Schedule.js b/src/pages/Schedule.js
index c755b818..40d59815 100644
--- a/src/pages/Schedule.js
+++ b/src/pages/Schedule.js
@@ -128,6 +128,7 @@ const Schedule = () => {
}
};
+ setIsS89(false);
if (mounted && years.length > 0) {
getSchedules();
}
@@ -135,7 +136,7 @@ const Schedule = () => {
return () => {
mounted = false;
};
- }, [years, currentYear]);
+ }, [years, currentYear, setIsS89]);
useEffect(() => {
const getScheduleByYear = async () => {
diff --git a/src/template/S-89_MG.pdf b/src/template/S-89_MG.pdf
deleted file mode 100644
index a3c6c571..00000000
Binary files a/src/template/S-89_MG.pdf and /dev/null differ
diff --git a/src/template/S89Template.js b/src/template/S89Template.js
new file mode 100644
index 00000000..b6c62d23
--- /dev/null
+++ b/src/template/S89Template.js
@@ -0,0 +1,764 @@
+import { useEffect } from 'react';
+import { useHistory } from 'react-router-dom';
+import { useRecoilValue } from 'recoil';
+import { useTranslation } from 'react-i18next';
+import parse from 'html-react-parser';
+import Box from '@mui/material/Box';
+import Button from '@mui/material/Button';
+import Checkbox from '@mui/material/Checkbox';
+import SaveAltIcon from '@mui/icons-material/SaveAlt';
+import Table from '@mui/material/Table';
+import TableBody from '@mui/material/TableBody';
+import TableCell from '@mui/material/TableCell';
+import TableContainer from '@mui/material/TableContainer';
+import TableRow from '@mui/material/TableRow';
+import Typography from '@mui/material/Typography';
+import { s89DataState } from '../appStates/appSchedule';
+import { appLangState } from '../appStates/appSettings';
+
+const sharedStyles = {
+ tblData: {
+ padding: 0,
+ borderBottom: 'none',
+ },
+};
+
+const S89Template = () => {
+ let history = useHistory();
+ const { t } = useTranslation();
+
+ const appLang = useRecoilValue(appLangState);
+ const s89Data = useRecoilValue(s89DataState);
+
+ const savePDF = () => {
+ const html2pdf = require('html2pdf.js');
+ const element = document.getElementById('S89-wrapper');
+ var opt = {
+ filename: 'Anjara_Mpianatra.pdf',
+ image: { type: 'jpeg', quality: 0.98 },
+ html2canvas: { scale: 2 },
+ jsPDF: { unit: 'in', format: [3.35, 4.45], orientation: 'portrait' },
+ };
+ html2pdf().set(opt).from(element).save();
+ };
+
+ useEffect(() => {
+ console.log(s89Data);
+ if (s89Data.length === 0) {
+ history.push({
+ pathname: '/Schedule',
+ });
+ }
+ }, [history, s89Data]);
+
+ return (
+
+ {s89Data.length > 0 && (
+ <>
+ }
+ sx={{ margin: '0 2px 2px 0' }}
+ onClick={savePDF}
+ >
+ PDF
+
+
+ {s89Data.map((data) => (
+
+
+
+
+
+
+
+
+ {parse(t('s89.title'))}
+
+
+
+
+
+
+
+
+
+
+
+
+ {t('global.name')}:
+
+
+
+
+ {data.studentName}
+
+
+
+
+
+
+
+
+
+
+
+
+ {t('global.assistant')}:
+
+
+
+
+ {data.assistantName}
+
+
+
+
+
+
+
+
+
+
+
+
+ {t('global.date')}:
+
+
+
+
+ {data.assignmentDate}
+
+
+
+
+
+
+
+ {t('global.assignment')}:
+
+
+
+
+
+
+ {}}
+ />
+
+
+
+ {t('global.bibleReading')}
+
+
+
+ {}}
+ />
+
+
+
+ {t('global.bibleStudy')}
+
+
+
+
+
+ {}}
+ />
+
+
+
+ {t('global.initialCall')}
+
+
+
+ {}}
+ />
+
+
+
+ {t('global.talk')}
+
+
+
+
+
+
+
+
+
+
+
+
+
+ {data.isInitialCallSpec}
+
+
+
+
+
+
+
+ {t('global.otherPart')}:
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+ {}}
+ />
+
+
+
+ {t('global.returnVisit')}
+
+
+
+
+
+
+
+
+
+
+
+
+
+ {data.returnVisitSpec}
+
+
+
+
+
+
+
+ {t('s89.toBeGiven')}
+
+
+
+
+
+
+ {}}
+ />
+
+
+
+ {t('global.mainHall')}
+
+
+
+
+
+ {}}
+ />
+
+
+
+ {t('global.auxClass1')}
+
+
+
+
+
+
+
+
+
+ {t('global.auxClass2')}
+
+
+
+
+
+
+
+
+ {parse(t('s89.descFooter'))}
+
+
+
+
+ S-89-{appLang.toUpperCase()}
+
+
+ 11/20
+
+
+
+
+
+ ))}
+
+ >
+ )}
+
+ );
+};
+
+export default S89Template;
diff --git a/src/template/ScheduleTemplate.js b/src/template/ScheduleTemplate.js
index 437eb066..8bb762c1 100644
--- a/src/template/ScheduleTemplate.js
+++ b/src/template/ScheduleTemplate.js
@@ -1,5 +1,5 @@
import { useEffect, useState } from 'react';
-import { Redirect } from "react-router-dom";
+import { Redirect } from 'react-router-dom';
import Box from '@mui/material/Box';
import Button from '@mui/material/Button';
import SaveAltIcon from '@mui/icons-material/SaveAlt';
@@ -8,462 +8,540 @@ import { dbGetScheduleForPrint } from '../indexedDb/dbAssignment';
import { dbGetAppSettings } from '../indexedDb/dbAppSettings';
const ScheduleTemplate = (props) => {
- const [data, setData] = useState([]);
- const [classCount, setClassCount]= useState(1);
- const [congName, setCongName] = useState("");
- const [congNumber, setCongNumber] = useState("");
+ const [data, setData] = useState([]);
+ const [classCount, setClassCount] = useState(1);
+ const [congName, setCongName] = useState('');
+ const [congNumber, setCongNumber] = useState('');
- let currentSchedule;
- if (props.location.state !== undefined) {
- currentSchedule = props.location.state.currentSchedule;
- };
+ let currentSchedule;
+ if (props.location.state !== undefined) {
+ currentSchedule = props.location.state.currentSchedule;
+ }
- const savePDF = () => {
- var html2pdf = require("html2pdf.js")
- const element = document.getElementById("schedule_template");
- var opt = {
- margin: [0.2, 0.5, 0.2, 0.5],
- filename: 'Anjara_Mpianatra.pdf',
- image: { type: 'jpeg', quality: 0.5 },
- html2canvas: { scale: 2 },
- jsPDF: { unit: 'in', format: 'a4', orientation: 'portrait' }
- };
- html2pdf().set(opt).from(element).save();
- }
+ const savePDF = () => {
+ var html2pdf = require('html2pdf.js');
+ const element = document.getElementById('schedule_template');
+ var opt = {
+ margin: [0.2, 0.5, 0.2, 0.5],
+ filename: 'Anjara_Mpianatra.pdf',
+ image: { type: 'jpeg', quality: 0.5 },
+ html2canvas: { scale: 2 },
+ jsPDF: { unit: 'in', format: 'a4', orientation: 'portrait' },
+ };
+ html2pdf().set(opt).from(element).save();
+ };
- useEffect(() => {
- const getData = async () => {
- const data = await dbGetScheduleForPrint(currentSchedule);
- setData(data);
- }
- getData();
- }, [currentSchedule])
+ useEffect(() => {
+ const getData = async () => {
+ const data = await dbGetScheduleForPrint(currentSchedule);
+ setData(data);
+ };
+ getData();
+ }, [currentSchedule]);
- const loadSettings = async () => {
- const appSettings = await dbGetAppSettings();
- setClassCount(appSettings.class_count);
- setCongName(appSettings.cong_name);
- setCongNumber(appSettings.cong_number);
- };
- loadSettings();
+ const loadSettings = async () => {
+ const appSettings = await dbGetAppSettings();
+ setClassCount(appSettings.class_count);
+ setCongName(appSettings.cong_name);
+ setCongNumber(appSettings.cong_number);
+ };
+ loadSettings();
- if (props.location.state === undefined) {
- return
- }
+ if (props.location.state === undefined) {
+ return (
+
+ );
+ }
- return (
- <>
- {data.length > 0 && (
-
- }
- sx={{margin: '0 2px 2px 0'}}
- onClick={savePDF}
- >
- PDF
-
-
-
-
-
- {congName !== "" && congNumber !== "" ? `${congName.toUpperCase()} (${congNumber.toUpperCase()})`: ''}
-
-
- Anjaran’ny mpianatra
-
-
- {data.map(weekItem => {
- const month = weekItem.week.split("/")[0];
- var monthName = "";
-
- if (month === "01") {
- monthName = "Janoary"
- } else if (month === "02") {
- monthName = "Febroary"
- } else if (month === "03") {
- monthName = "Martsa"
- } else if (month === "04") {
- monthName = "Aprily"
- } else if (month === "05") {
- monthName = "Mey"
- } else if (month === "06") {
- monthName = "Jona"
- } else if (month === "07") {
- monthName = "Jolay"
- } else if (month === "08") {
- monthName = "Aogositra"
- } else if (month === "09") {
- monthName = "Septambra"
- } else if (month === "10") {
- monthName = "Oktobra"
- } else if (month === "11") {
- monthName = "Novambra"
- } else if (month === "12") {
- monthName = "Desambra"
- }
+ return (
+ <>
+ {data.length > 0 && (
+
+ }
+ sx={{ margin: '0 2px 2px 0' }}
+ onClick={savePDF}
+ >
+ PDF
+
+
+
+
+
+ {congName !== '' && congNumber !== ''
+ ? `${congName.toUpperCase()} (${congNumber.toUpperCase()})`
+ : ''}
+
+
+ Anjaran’ny mpianatra
+
+
+ {data.map((weekItem) => {
+ const month = weekItem.week.split('/')[0];
+ var monthName = '';
- const dateV = weekItem.week.split("/")[1] + " " + monthName.toUpperCase();
+ if (month === '01') {
+ monthName = 'Janoary';
+ } else if (month === '02') {
+ monthName = 'Febroary';
+ } else if (month === '03') {
+ monthName = 'Martsa';
+ } else if (month === '04') {
+ monthName = 'Aprily';
+ } else if (month === '05') {
+ monthName = 'Mey';
+ } else if (month === '06') {
+ monthName = 'Jona';
+ } else if (month === '07') {
+ monthName = 'Jolay';
+ } else if (month === '08') {
+ monthName = 'Aogositra';
+ } else if (month === '09') {
+ monthName = 'Septambra';
+ } else if (month === '10') {
+ monthName = 'Oktobra';
+ } else if (month === '11') {
+ monthName = 'Novambra';
+ } else if (month === '12') {
+ monthName = 'Desambra';
+ }
- return (
-
-
- {dateV}
-
- {weekItem.scheduleData.noMeeting && (
-
- Tsy misy fivoriana
-
- )}
- {weekItem.scheduleData.week_type !== 1 && (
-
- {weekItem.scheduleData.week_type_name.toUpperCase()}
-
- )}
- {(!weekItem.scheduleData.noMeeting && weekItem.scheduleData.week_type !== 3) && (
- <>
-
-
- HARENA AVY AO AMIN’NY TENIN’ANDRIAMANITRA
-
-
- {classCount === 1 ? '' : 'Efitrano faharoa'}
-
-
- Efitrano Lehibe
-
-
-
-
-
-
- -
-
- Famakiana Baiboly(4 min. na latsaka)
-
-
-
-
-
- Mpianatra:
-
-
-
- {classCount === 1 ? '' : weekItem.scheduleData.bRead_stu_B_dispName}
-
-
- {weekItem.scheduleData.bRead_stu_A_dispName}
-
-
-
-
- FAMPIOFANANA AMIN’NY FANOMPOANA
-
-
- {classCount === 1 ? '' : 'Efitrano faharoa'}
-
-
- Efitrano Lehibe
-
-
- {[1, 2, 3, 4].map(index => {
- const fldTypeName = "ass" + index + "_type_name";
- const fldType = "ass" + index + "_type";
- const fldTime = "ass" + index + "_time";
- const fldSrc = "ass" + index + "_src";
- const fldStuA = "ass" + index + "_stu_A_dispName";
- const fldAssA = "ass" + index + "_ass_A_dispName";
- const fldStuB = "ass" + index + "_stu_B_dispName";
- const fldAssB = "ass" + index + "_ass_B_dispName";
+ const dateV =
+ weekItem.week.split('/')[1] + ' ' + monthName.toUpperCase();
- return (
- <>
- {weekItem.sourceData[fldType] !== "" && (
-
-
-
-
- -
-
- {weekItem.sourceData[fldType] === 7 ? weekItem.sourceData[fldSrc].split(": (")[0] : weekItem.sourceData[fldTypeName]}
-
- {(weekItem.sourceData[fldType] === 5 || weekItem.sourceData[fldType] === 6) && (
- <>
- ({weekItem.sourceData[fldTime]} min.)
- >
- )}
- {(weekItem.sourceData[fldType] === 1 || weekItem.sourceData[fldType] === 2 || weekItem.sourceData[fldType] === 3 || weekItem.sourceData[fldType] === 4) && (
- <>
- ({weekItem.sourceData[fldTime]} min. na latsaka)
- >
- )}
- {(weekItem.sourceData[fldType] === 7) && (
- <>
- ({weekItem.sourceData[fldSrc].split(": (")[1].split(" ")[0]} min.)
- >
- )}
-
-
-
-
-
- {(weekItem.sourceData[fldType] === 1 || weekItem.sourceData[fldType] === 2 || weekItem.sourceData[fldType] === 3) && (
-
- Mpianatra/Mpanampy:
-
- )}
- {(weekItem.sourceData[fldType] === 4) && (
-
- Mpianatra:
-
- )}
-
-
- {classCount === 2 && (
- <>
- {(weekItem.sourceData[fldType] === 1 || weekItem.sourceData[fldType] === 2 || weekItem.sourceData[fldType] === 3 || weekItem.sourceData[fldType] === 4) && (
- <>
- {weekItem.scheduleData[fldStuB]}{weekItem.scheduleData[fldAssB] === '' ? '' : `/${weekItem.scheduleData[fldAssB]}`}
- >
- )}
- >
- )}
-
-
- <>
- {(weekItem.sourceData[fldType] === 1 || weekItem.sourceData[fldType] === 2 || weekItem.sourceData[fldType] === 3 || weekItem.sourceData[fldType] === 4) && (
- <>
- {weekItem.scheduleData[fldStuA]}{weekItem.scheduleData[fldAssA] === '' ? '' : `/${weekItem.scheduleData[fldAssA]}`}
- >
- )}
- >
-
-
- )}
- >
- );
- })}
- >
- )}
-
- )
- })}
-
-
-
- )}
- >
- );
-}
-
-export default ScheduleTemplate;
\ No newline at end of file
+ return (
+
+
+ {dateV}
+
+ {weekItem.scheduleData.noMeeting && (
+
+ Tsy misy fivoriana
+
+ )}
+ {weekItem.scheduleData.week_type !== 1 && (
+
+ {weekItem.scheduleData.week_type_name.toUpperCase()}
+
+ )}
+ {!weekItem.scheduleData.noMeeting &&
+ weekItem.scheduleData.week_type !== 3 && (
+ <>
+
+
+ HARENA AVY AO AMIN’NY TENIN’ANDRIAMANITRA
+
+
+ {classCount === 1 ? '' : 'Efitrano faharoa'}
+
+
+ Efitrano Lehibe
+
+
+
+
+
+
+ -
+
+ Famakiana Baiboly
+
+ (4 min. na latsaka)
+
+
+
+
+
+
+ Mpianatra:
+
+
+
+ {classCount === 1
+ ? ''
+ : weekItem.scheduleData.bRead_stu_B_dispName}
+
+
+ {weekItem.scheduleData.bRead_stu_A_dispName}
+
+
+
+
+ FAMPIOFANANA AMIN’NY FANOMPOANA
+
+
+ {classCount === 1 ? '' : 'Efitrano faharoa'}
+
+
+ Efitrano Lehibe
+
+
+ {[1, 2, 3, 4].map((index) => {
+ const fldTypeName = 'ass' + index + '_type_name';
+ const fldType = 'ass' + index + '_type';
+ const fldTime = 'ass' + index + '_time';
+ const fldSrc = 'ass' + index + '_src';
+ const fldStuA = 'ass' + index + '_stu_A_dispName';
+ const fldAssA = 'ass' + index + '_ass_A_dispName';
+ const fldStuB = 'ass' + index + '_stu_B_dispName';
+ const fldAssB = 'ass' + index + '_ass_B_dispName';
+
+ return (
+ <>
+ {weekItem.sourceData[fldType] !== '' && (
+
+
+
+
+ -
+
+ {weekItem.sourceData[fldType] ===
+ 7
+ ? weekItem.sourceData[
+ fldSrc
+ ].split(': (')[0]
+ : weekItem.sourceData[
+ fldTypeName
+ ]}
+
+ {(weekItem.sourceData[
+ fldType
+ ] === 5 ||
+ weekItem.sourceData[
+ fldType
+ ] === 6) && (
+ <>
+ (
+ {
+ weekItem.sourceData[
+ fldTime
+ ]
+ }{' '}
+ min.)
+ >
+ )}
+ {(weekItem.sourceData[
+ fldType
+ ] === 1 ||
+ weekItem.sourceData[
+ fldType
+ ] === 2 ||
+ weekItem.sourceData[
+ fldType
+ ] === 3 ||
+ weekItem.sourceData[
+ fldType
+ ] === 4) && (
+ <>
+ (
+ {
+ weekItem.sourceData[
+ fldTime
+ ]
+ }{' '}
+ min. na latsaka)
+ >
+ )}
+ {weekItem.sourceData[
+ fldType
+ ] === 7 && (
+ <>
+ (
+ {
+ weekItem.sourceData[
+ fldSrc
+ ]
+ .split(': (')[1]
+ .split(' ')[0]
+ }{' '}
+ min.)
+ >
+ )}
+
+
+
+
+
+ {(weekItem.sourceData[fldType] === 1 ||
+ weekItem.sourceData[fldType] === 2 ||
+ weekItem.sourceData[fldType] === 3) && (
+
+ Mpianatra/Mpanampy:
+
+ )}
+ {weekItem.sourceData[fldType] === 4 && (
+
+ Mpianatra:
+
+ )}
+
+
+ {classCount === 2 && (
+ <>
+ {(weekItem.sourceData[fldType] ===
+ 1 ||
+ weekItem.sourceData[fldType] ===
+ 2 ||
+ weekItem.sourceData[fldType] ===
+ 3 ||
+ weekItem.sourceData[fldType] ===
+ 4) && (
+ <>
+ {weekItem.scheduleData[fldStuB]}
+ {weekItem.scheduleData[
+ fldAssB
+ ] === ''
+ ? ''
+ : `/${weekItem.scheduleData[fldAssB]}`}
+ >
+ )}
+ >
+ )}
+
+
+ <>
+ {(weekItem.sourceData[fldType] === 1 ||
+ weekItem.sourceData[fldType] === 2 ||
+ weekItem.sourceData[fldType] === 3 ||
+ weekItem.sourceData[fldType] ===
+ 4) && (
+ <>
+ {weekItem.scheduleData[fldStuA]}
+ {weekItem.scheduleData[fldAssA] ===
+ ''
+ ? ''
+ : `/${weekItem.scheduleData[fldAssA]}`}
+ >
+ )}
+ >
+
+
+ )}
+ >
+ );
+ })}
+ >
+ )}
+
+ );
+ })}
+
+
+
+ )}
+ >
+ );
+};
+
+export default ScheduleTemplate;