From e225d28908a43f3d24573fb32fb9cd8cd0d8652c Mon Sep 17 00:00:00 2001 From: yael-miller Date: Sun, 8 Mar 2026 18:27:52 +0000 Subject: [PATCH 1/4] update reporting logic for transportation delays and approved absences --- .../StudentView/student-event-report.jsx | 178 +++++++++++++----- server/src/yemot-handler.service.ts | 22 ++- 2 files changed, 144 insertions(+), 56 deletions(-) diff --git a/client/src/components/StudentView/student-event-report.jsx b/client/src/components/StudentView/student-event-report.jsx index 79f1dfb0..ee64a092 100644 --- a/client/src/components/StudentView/student-event-report.jsx +++ b/client/src/components/StudentView/student-event-report.jsx @@ -9,25 +9,28 @@ import { useResetStore, useDataProvider, useGetOne, + useGetList, Create, SimpleForm, FormDataConsumer, Loading, + ArrayInput, + SimpleFormIterator } from 'react-admin'; import { filterByUserIdAndYear } from '@shared/components/fields/CommonReferenceInputFilter'; import CommonReferenceInput from '@shared/components/fields/CommonReferenceInput'; import { defaultYearFilter, yearChoices } from '@shared/utils/yearFilter'; import CommonAutocompleteInput from '@shared/components/fields/CommonAutocompleteInput'; import { handleActionSuccess, handleError } from '@shared/utils/notifyUtil'; +import SignatureInput from '@shared/components/fields/signature/SignatureInput'; import { useObjectStore } from "src/utils/storeUtil"; const DynamicFields = ({ absenceType, isLoading }) => { - if (isLoading) return ; if (!absenceType?.requiredLabels?.length) return null; return (
- {absenceType.requiredLabels.map((label, index) => ( + {absenceType.requiredLabels.map((label) => ( { ); }; -const formatPayload = (values, userId, studentId, absenceType) => { +const extractBasePayload = (rootValues, reportValues, userId, studentId, absenceType) => { const allowedLabels = absenceType?.requiredLabels || []; - - const extraInfo = Object.keys(values) - .filter(key => { - if (!key.startsWith('dynamic_')) return false; - const label = key.replace('dynamic_', ''); - return allowedLabels.includes(label) && values[key]; - }) - .map(key => { - const label = key.replace('dynamic_', ''); - return `${label}: ${values[key]}`; - }) + const extraInfo = Object.keys(rootValues) + .filter(key => key.startsWith('dynamic_') && allowedLabels.includes(key.replace('dynamic_', '')) && rootValues[key]) + .map(key => `${key.replace('dynamic_', '')}: ${rootValues[key]}`) .join(' | '); - const cleanValues = { ...values }; - Object.keys(cleanValues).forEach(key => { - if (key.startsWith('dynamic_')) delete cleanValues[key]; - }); - return { - ...cleanValues, userId: userId, studentReferenceId: studentId, year: parseInt(defaultYearFilter.year), - reportDate: cleanValues.reportDate, - absnceCount: parseFloat(cleanValues.absnceCount) || 1, + reportDate: reportValues.reportDate, isApproved: true, - reason: cleanValues.reason ? `${cleanValues.reason} [${extraInfo}]` : extraInfo, + reason: extraInfo || "", + absenceTypeId: rootValues.absenceTypeId }; }; @@ -78,40 +67,100 @@ const StudentEventReport = (props) => { const reset = useResetStore(); const { value: student, clear } = useObjectStore("student"); const [selectedAbsenceTypeId, setSelectedAbsenceTypeId] = React.useState(null); + const { data: absenceType, isLoading } = useGetOne( 'absence_type', { id: selectedAbsenceTypeId }, { enabled: !!selectedAbsenceTypeId } ); + const { data: existingAbsences } = useGetList( + 'known_absence', + { + pagination: { page: 1, perPage: 1000 }, + filter: { + studentReferenceId: student?.id, + absenceTypeId: selectedAbsenceTypeId, + year: parseInt(defaultYearFilter.year) + } + }, + { enabled: !!selectedAbsenceTypeId && !!student?.id } + ); + + const uniqueDates = new Set(); + if (existingAbsences) { + existingAbsences.forEach(item => { + if (item.reportDate) { + uniqueDates.add(new Date(item.reportDate).toISOString().split('T')[0]); + } + }); + } + const utilizedDays = uniqueDates.size; + const handleSave = async (values) => { try { + const reports = values.reports || []; + if (reports.length === 0) { + notify("יש להזין לפחות דיווח אחד", { type: 'warning' }); + return; + } + const quota = absenceType?.quota; if (quota) { - const { data: existingAbsences } = await dataProvider.getList('known_absence', { - pagination: { page: 1, perPage: 1000 }, - filter: { - studentReferenceId: student.id, - absenceTypeId: values.absenceTypeId, - year: values.year - }, - }); + const newDates = new Set(uniqueDates); - const currentTotal = existingAbsences.reduce((sum, item) => sum + (parseFloat(item.absnceCount) || 0), 0); - const requestedAmount = parseFloat(values.absnceCount || 1); + reports.forEach(report => { + if (report.reportDate) { + newDates.add(new Date(report.reportDate).toISOString().split('T')[0]); + } + }); - if (currentTotal + requestedAmount > quota) { + if (newDates.size > quota) { notify( - `חריגה מהמכסה! המכסה היא ${quota}. נוצלו ${currentTotal}, ניסיון להוסיף ${requestedAmount}.`, + `חריגה מהמכסה! המכסה היא ${quota} ימים. עם הדיווחים החדשים את מנסה לנצל ${newDates.size} ימים שונים.`, { type: 'error', autoHideDuration: 10000 } ); return; } } - const formattedData = formatPayload(values, student.userId, student.id, absenceType) - const response = await dataProvider.create('known_absence', { data: formattedData }); + let payloadsToCreate = []; + + reports.forEach(report => { + const basePayload = extractBasePayload(values, report, student.userId, student.id, absenceType); + + if (report.homeroomKlassId && (parseFloat(report.homeroomAbsnceCount) > 0)) { + payloadsToCreate.push({ + ...basePayload, + klassReferenceId: report.homeroomKlassId, + absnceCount: parseFloat(report.homeroomAbsnceCount) + }); + } + + if (report.specializationKlassId && (parseFloat(report.specializationAbsnceCount) > 0)) { + payloadsToCreate.push({ + ...basePayload, + klassReferenceId: report.specializationKlassId, + absnceCount: parseFloat(report.specializationAbsnceCount) + }); + } + + if (report.extraKlassId && (parseFloat(report.extraAbsnceCount) > 0)) { + payloadsToCreate.push({ + ...basePayload, + klassReferenceId: report.extraKlassId, + absnceCount: parseFloat(report.extraAbsnceCount) + }); + } + }); + + if (payloadsToCreate.length === 0) { + notify("יש להזין שעות היעדרות לפחות עבור כיתה אחת באחד הדיווחים", { type: 'warning' }); + return; + } + + const response = await dataProvider.createMany('known_absence', payloadsToCreate); handleActionSuccess(notify)(response); clear(); reset(); @@ -121,22 +170,53 @@ const StudentEventReport = (props) => { }; return ( - - - - setSelectedAbsenceTypeId(e?.target?.value ?? e)} /> + + + setSelectedAbsenceTypeId(e?.target?.value ?? e)} /> + {absenceType?.quota !== undefined && ( +
+ שימי לב: המכסה השנתית לאירוע זה היא {absenceType.quota} ימים. עד כה ניצלת {utilizedDays} ימים. באפשרותך לדווח על {Math.max(0, absenceType.quota - utilizedDays)} ימים במקביל. מלאי את השדות הנדרשים מטה. +
+ )} - {() => ( - - )} + {() => } - - - - + + + + +
+
+ +
+
+ +
+
+ +
+
+ +
+
+ +
+
+ +
+
+ +
+
+ +
+
+
+
+ +
); diff --git a/server/src/yemot-handler.service.ts b/server/src/yemot-handler.service.ts index 023f7372..9a7c7d3a 100644 --- a/server/src/yemot-handler.service.ts +++ b/server/src/yemot-handler.service.ts @@ -16,7 +16,7 @@ export class YemotHandlerService extends BaseYemotHandlerService { override async processCall(): Promise { await this.getUserByDidPhone(); this.logger.log(`Processing call with ID: ${this.call.callId} from phone: ${this.call.phone}`); - const student = await this.getStudentByPhone() + const student = await this.getStudentByInput() if (!student) return; const alreadyReported = await this.hasReportedToday(student.id); if (alreadyReported) { @@ -35,15 +35,23 @@ export class YemotHandlerService extends BaseYemotHandlerService { } } - private async getStudentByPhone(): Promise { + private async getStudentByInput(): Promise { + let student = null; + while (!student) { + student = await this.getStudentById(); + + if (!student) { + await this.sendMessage('מספר תז לא תקין נסי שוב'); + } + } + return student; + } + private async getStudentById(): Promise { + const id = await this.askForInput('הקישי מספר תז'); const student = await this.dataSource.getRepository(Student).findOneBy({ userId: this.user.id, - phone: this.call.phone, + tz: id, }); - if (!student) { - await this.hangupWithMessage('הטלפון לא קיים במערכת'); - return null - } return student; } From 173ff42ed7752bf234acf3ca41d822af3696291a Mon Sep 17 00:00:00 2001 From: yael-miller Date: Sun, 8 Mar 2026 20:07:58 +0000 Subject: [PATCH 2/4] remove code duplication in StudentEventReport --- .../StudentView/student-event-report.jsx | 133 ++++++++---------- server/src/yemot-handler.service.ts | 8 +- 2 files changed, 66 insertions(+), 75 deletions(-) diff --git a/client/src/components/StudentView/student-event-report.jsx b/client/src/components/StudentView/student-event-report.jsx index ee64a092..d1d4a5bb 100644 --- a/client/src/components/StudentView/student-event-report.jsx +++ b/client/src/components/StudentView/student-event-report.jsx @@ -53,7 +53,7 @@ const extractBasePayload = (rootValues, reportValues, userId, studentId, absence return { userId: userId, studentReferenceId: studentId, - year: parseInt(defaultYearFilter.year), + year: defaultYearFilter.year, reportDate: reportValues.reportDate, isApproved: true, reason: extraInfo || "", @@ -81,93 +81,85 @@ const StudentEventReport = (props) => { filter: { studentReferenceId: student?.id, absenceTypeId: selectedAbsenceTypeId, - year: parseInt(defaultYearFilter.year) + year: defaultYearFilter.year } }, { enabled: !!selectedAbsenceTypeId && !!student?.id } ); - const uniqueDates = new Set(); - if (existingAbsences) { - existingAbsences.forEach(item => { + const uniqueDates = React.useMemo(() => { + const datesSet = new Set(); + + existingAbsences?.forEach(item => { if (item.reportDate) { - uniqueDates.add(new Date(item.reportDate).toISOString().split('T')[0]); + datesSet.add(new Date(item.reportDate).toISOString().split('T')[0]); } }); - } + + return datesSet; + }, [existingAbsences]); const utilizedDays = uniqueDates.size; - const handleSave = async (values) => { - try { - const reports = values.reports || []; - if (reports.length === 0) { - notify("יש להזין לפחות דיווח אחד", { type: 'warning' }); + const handleSave = async (values) => { + try { + const reports = values.reports || []; + if (reports.length === 0) { + notify("יש להזין לפחות דיווח אחד", { type: 'warning' }); + return; + } + + const quota = absenceType?.quota; + if (quota) { + const newDates = new Set(uniqueDates); + reports.forEach(report => { + if (report.reportDate) { + newDates.add(new Date(report.reportDate).toISOString().split('T')[0]); + } + }); + + if (newDates.size > quota) { + notify( + `חריגה מהמכסה! המכסה היא ${quota} ימים. עם הדיווחים החדשים את מנסה לנצל ${newDates.size} ימים שונים.`, + { type: 'error', autoHideDuration: 10000 } + ); return; } + } - const quota = absenceType?.quota; - - if (quota) { - const newDates = new Set(uniqueDates); + let payloadsToCreate = []; - reports.forEach(report => { - if (report.reportDate) { - newDates.add(new Date(report.reportDate).toISOString().split('T')[0]); - } + const addPayloadIfValid = (base, klassId, count) => { + const parsedCount = parseFloat(count); + if (klassId && parsedCount > 0) { + payloadsToCreate.push({ + ...base, + klassReferenceId: klassId, + absnceCount: parsedCount }); - - if (newDates.size > quota) { - notify( - `חריגה מהמכסה! המכסה היא ${quota} ימים. עם הדיווחים החדשים את מנסה לנצל ${newDates.size} ימים שונים.`, - { type: 'error', autoHideDuration: 10000 } - ); - return; - } } + }; - let payloadsToCreate = []; - - reports.forEach(report => { - const basePayload = extractBasePayload(values, report, student.userId, student.id, absenceType); - - if (report.homeroomKlassId && (parseFloat(report.homeroomAbsnceCount) > 0)) { - payloadsToCreate.push({ - ...basePayload, - klassReferenceId: report.homeroomKlassId, - absnceCount: parseFloat(report.homeroomAbsnceCount) - }); - } + reports.forEach(report => { + const basePayload = extractBasePayload(values, report, student.userId, student.id, absenceType); - if (report.specializationKlassId && (parseFloat(report.specializationAbsnceCount) > 0)) { - payloadsToCreate.push({ - ...basePayload, - klassReferenceId: report.specializationKlassId, - absnceCount: parseFloat(report.specializationAbsnceCount) - }); - } - - if (report.extraKlassId && (parseFloat(report.extraAbsnceCount) > 0)) { - payloadsToCreate.push({ - ...basePayload, - klassReferenceId: report.extraKlassId, - absnceCount: parseFloat(report.extraAbsnceCount) - }); - } - }); - - if (payloadsToCreate.length === 0) { - notify("יש להזין שעות היעדרות לפחות עבור כיתה אחת באחד הדיווחים", { type: 'warning' }); - return; - } + addPayloadIfValid(basePayload, report.homeroomKlassId, report.homeroomAbsnceCount); + addPayloadIfValid(basePayload, report.specializationKlassId, report.specializationAbsnceCount); + addPayloadIfValid(basePayload, report.extraKlassId, report.extraAbsnceCount); + }); - const response = await dataProvider.createMany('known_absence', payloadsToCreate); - handleActionSuccess(notify)(response); - clear(); - reset(); - } catch (error) { - handleError(notify)(error); + if (payloadsToCreate.length === 0) { + notify("יש להזין שעות היעדרות לפחות עבור כיתה אחת באחד הדיווחים", { type: 'warning' }); + return; } - }; + + const response = await dataProvider.createMany('known_absence', payloadsToCreate); + handleActionSuccess(notify)(response); + clear(); + reset(); + } catch (error) { + handleError(notify)(error); + } +}; return ( @@ -178,9 +170,8 @@ const StudentEventReport = (props) => { שימי לב: המכסה השנתית לאירוע זה היא {absenceType.quota} ימים. עד כה ניצלת {utilizedDays} ימים. באפשרותך לדווח על {Math.max(0, absenceType.quota - utilizedDays)} ימים במקביל. מלאי את השדות הנדרשים מטה.
)} - - {() => } - + + diff --git a/server/src/yemot-handler.service.ts b/server/src/yemot-handler.service.ts index 9a7c7d3a..ddc3e267 100644 --- a/server/src/yemot-handler.service.ts +++ b/server/src/yemot-handler.service.ts @@ -38,7 +38,7 @@ export class YemotHandlerService extends BaseYemotHandlerService { private async getStudentByInput(): Promise { let student = null; while (!student) { - student = await this.getStudentById(); + student = await this.getStudentByTz(); if (!student) { await this.sendMessage('מספר תז לא תקין נסי שוב'); @@ -46,11 +46,11 @@ export class YemotHandlerService extends BaseYemotHandlerService { } return student; } - private async getStudentById(): Promise { - const id = await this.askForInput('הקישי מספר תז'); + private async getStudentByTz(): Promise { + const tz = await this.askForInput('הקישי מספר תז'); const student = await this.dataSource.getRepository(Student).findOneBy({ userId: this.user.id, - tz: id, + tz: tz, }); return student; } From dfbdba5891694c81c56c40c9f5fd179a405ac842 Mon Sep 17 00:00:00 2001 From: yael-miller Date: Sun, 8 Mar 2026 20:44:05 +0000 Subject: [PATCH 3/4] clean: streamline unique dates calculation logic --- .../StudentView/student-event-report.jsx | 113 +++++++++--------- 1 file changed, 55 insertions(+), 58 deletions(-) diff --git a/client/src/components/StudentView/student-event-report.jsx b/client/src/components/StudentView/student-event-report.jsx index d1d4a5bb..e6e3e2c0 100644 --- a/client/src/components/StudentView/student-event-report.jsx +++ b/client/src/components/StudentView/student-event-report.jsx @@ -87,79 +87,76 @@ const StudentEventReport = (props) => { { enabled: !!selectedAbsenceTypeId && !!student?.id } ); - const uniqueDates = React.useMemo(() => { + const uniqueDates = React.useMemo(() => { const datesSet = new Set(); - existingAbsences?.forEach(item => { - if (item.reportDate) { - datesSet.add(new Date(item.reportDate).toISOString().split('T')[0]); - } + datesSet.add(new Date(item.reportDate).toISOString().split('T')[0]); }); - + return datesSet; - }, [existingAbsences]); + }, [existingAbsences]); const utilizedDays = uniqueDates.size; - const handleSave = async (values) => { - try { - const reports = values.reports || []; - if (reports.length === 0) { - notify("יש להזין לפחות דיווח אחד", { type: 'warning' }); - return; - } - - const quota = absenceType?.quota; - if (quota) { - const newDates = new Set(uniqueDates); - reports.forEach(report => { - if (report.reportDate) { - newDates.add(new Date(report.reportDate).toISOString().split('T')[0]); - } - }); - - if (newDates.size > quota) { - notify( - `חריגה מהמכסה! המכסה היא ${quota} ימים. עם הדיווחים החדשים את מנסה לנצל ${newDates.size} ימים שונים.`, - { type: 'error', autoHideDuration: 10000 } - ); + const handleSave = async (values) => { + try { + const reports = values.reports || []; + if (reports.length === 0) { + notify("יש להזין לפחות דיווח אחד", { type: 'warning' }); return; } - } - let payloadsToCreate = []; - - const addPayloadIfValid = (base, klassId, count) => { - const parsedCount = parseFloat(count); - if (klassId && parsedCount > 0) { - payloadsToCreate.push({ - ...base, - klassReferenceId: klassId, - absnceCount: parsedCount + const quota = absenceType?.quota; + if (quota) { + const newDates = new Set(uniqueDates); + reports.forEach(report => { + if (report.reportDate) { + newDates.add(new Date(report.reportDate).toISOString().split('T')[0]); + } }); + + if (newDates.size > quota) { + notify( + `חריגה מהמכסה! המכסה היא ${quota} ימים. עם הדיווחים החדשים את מנסה לנצל ${newDates.size} ימים שונים.`, + { type: 'error', autoHideDuration: 10000 } + ); + return; + } } - }; - reports.forEach(report => { - const basePayload = extractBasePayload(values, report, student.userId, student.id, absenceType); + let payloadsToCreate = []; - addPayloadIfValid(basePayload, report.homeroomKlassId, report.homeroomAbsnceCount); - addPayloadIfValid(basePayload, report.specializationKlassId, report.specializationAbsnceCount); - addPayloadIfValid(basePayload, report.extraKlassId, report.extraAbsnceCount); - }); + const addPayloadIfValid = (base, klassId, count) => { + const parsedCount = parseFloat(count); + if (klassId && parsedCount > 0) { + payloadsToCreate.push({ + ...base, + klassReferenceId: klassId, + absnceCount: parsedCount + }); + } + }; - if (payloadsToCreate.length === 0) { - notify("יש להזין שעות היעדרות לפחות עבור כיתה אחת באחד הדיווחים", { type: 'warning' }); - return; - } + reports.forEach(report => { + const basePayload = extractBasePayload(values, report, student.userId, student.id, absenceType); - const response = await dataProvider.createMany('known_absence', payloadsToCreate); - handleActionSuccess(notify)(response); - clear(); - reset(); - } catch (error) { - handleError(notify)(error); - } -}; + addPayloadIfValid(basePayload, report.homeroomKlassId, report.homeroomAbsnceCount); + addPayloadIfValid(basePayload, report.specializationKlassId, report.specializationAbsnceCount); + addPayloadIfValid(basePayload, report.extraKlassId, report.extraAbsnceCount); + }); + + if (payloadsToCreate.length === 0) { + notify("יש להזין שעות היעדרות לפחות עבור כיתה אחת באחד הדיווחים", { type: 'warning' }); + return; + } + + const response = await dataProvider.createMany('known_absence', payloadsToCreate); + handleActionSuccess(notify)(response); + clear(); + reset(); + } catch (error) { + handleError(notify)(error); + } + }; return ( From 9167c52f376e27a15792cae615a776b548fff9c4 Mon Sep 17 00:00:00 2001 From: yael-miller Date: Sun, 8 Mar 2026 21:57:21 +0000 Subject: [PATCH 4/4] remove redundant checks for mandatory reportDate in save logic --- client/src/components/StudentView/student-event-report.jsx | 4 +--- 1 file changed, 1 insertion(+), 3 deletions(-) diff --git a/client/src/components/StudentView/student-event-report.jsx b/client/src/components/StudentView/student-event-report.jsx index e6e3e2c0..465a0c6e 100644 --- a/client/src/components/StudentView/student-event-report.jsx +++ b/client/src/components/StudentView/student-event-report.jsx @@ -109,9 +109,7 @@ const StudentEventReport = (props) => { if (quota) { const newDates = new Set(uniqueDates); reports.forEach(report => { - if (report.reportDate) { - newDates.add(new Date(report.reportDate).toISOString().split('T')[0]); - } + newDates.add(new Date(report.reportDate).toISOString().split('T')[0]); }); if (newDates.size > quota) {