diff --git a/client/src/App.jsx b/client/src/App.jsx
index 9e33eef7..30399a52 100644
--- a/client/src/App.jsx
+++ b/client/src/App.jsx
@@ -38,6 +38,7 @@ import studentKlass from "src/entities/student-klass";
import student from "src/entities/student";
import teacher from "src/entities/teacher";
import transportation from 'src/entities/transportation';
+import absenceType from 'src/entities/absenceType';
import studentKlassesReport from "src/entities/student-klasses-report";
import reportMonth from "src/entities/report-month";
import teacherReportStatus from "src/entities/teacher-report-status";
@@ -67,7 +68,7 @@ import paymentTrack from '@shared/components/common-entities/payment-track';
import yemotCall from '@shared/components/common-entities/yemot-call';
import { isShowUsersData, isEditPagesData, isEditPaymentTracksData, isAdmin } from "@shared/utils/permissionsUtil";
-import { isLessonSignature, isOnlyInLessonReport, isTeacherView, isTransportation } from 'src/utils/appPermissions';
+import { isLessonSignature, isOnlyInLessonReport, isTeacherView, isTransportation, isAbsenceType } from 'src/utils/appPermissions';
import YemotSimulator from "@shared/components/views/YemotSimulator";
import { RegisterPage } from '@shared/components/layout/RegisterPage';
import { LoginPage } from '@shared/components/layout/LoginPage';
@@ -108,6 +109,7 @@ import MonetizationOnIcon from '@mui/icons-material/MonetizationOn';
import LocalAtmIcon from '@mui/icons-material/LocalAtm';
import AdminPanelSettingsIcon from '@mui/icons-material/AdminPanelSettings';
import DirectionsBusIcon from '@mui/icons-material/DirectionsBus';
+import CelebrationIcon from '@mui/icons-material/Celebration';
const i18nProvider = getI18nProvider(domainTranslations);
@@ -162,6 +164,7 @@ const App = () => (
{(isTransportation(permissions) || isAdmin(permissions)) && }
+ {(isAbsenceType(permissions) || isAdmin(permissions)) && }
diff --git a/client/src/domainTranslations.js b/client/src/domainTranslations.js
index 1a6f2815..45972b2b 100644
--- a/client/src/domainTranslations.js
+++ b/client/src/domainTranslations.js
@@ -141,6 +141,7 @@ export default {
reason: 'סיבה',
comment: 'הערה',
isApproved: 'מאושר',
+ absenceTypeId: 'סוג אירוע',
}
},
lesson: {
@@ -208,6 +209,15 @@ export default {
description: 'תיאור נסיעה',
}
},
+ absence_type: {
+ name: 'אירוע |||| אירועים',
+ fields: {
+ ...generalResourceFieldsTranslation,
+ name: 'שם האירוע',
+ quota: 'מכסה שנתית',
+ requiredLabels: 'שדות חובה לדיווח',
+ }
+ },
text: {
name: 'הודעה |||| הודעות - טבלת אדמין',
fields: {
diff --git a/client/src/entities/absenceType.jsx b/client/src/entities/absenceType.jsx
new file mode 100644
index 00000000..dfb876c0
--- /dev/null
+++ b/client/src/entities/absenceType.jsx
@@ -0,0 +1,87 @@
+import {
+ DateField,
+ DateTimeInput,
+ ReferenceField,
+ required,
+ TextField,
+ TextInput,
+ NumberInput,
+ maxLength,
+ SelectField,
+ ArrayInput,
+ SimpleFormIterator,
+} from "react-admin";
+import { CommonDatagrid } from "@shared/components/crudContainers/CommonList";
+import { getResourceComponents } from "@shared/components/crudContainers/CommonEntity";
+import CommonReferenceInput from "@shared/components/fields/CommonReferenceInput";
+import { useUnique } from "@shared/utils/useUnique";
+import { commonAdminFilters } from "@shared/components/fields/PermissionFilter";
+import { defaultYearFilter, yearChoices } from "@shared/utils/yearFilter";
+import CommonAutocompleteInput from "@shared/components/fields/CommonAutocompleteInput";
+
+const filters = [
+ ...commonAdminFilters,
+ ,
+ ,
+];
+
+const filterDefaultValues = {
+ year: defaultYearFilter.year,
+};
+
+const Datagrid = ({ isAdmin, children, ...props }) => {
+ return (
+
+ {children}
+ {isAdmin && }
+ {isAdmin && }
+
+
+
+
+
+
+
+ {isAdmin && }
+ {isAdmin && }
+
+ );
+};
+
+const Inputs = ({ isCreate, isAdmin }) => {
+ const unique = useUnique();
+ return (
+ <>
+ {!isCreate && isAdmin && }
+ {isAdmin && ( )}
+
+
+
+
+
+
+
+
+
+ {!isCreate && isAdmin && }
+ {!isCreate && isAdmin && }
+ >
+ );
+};
+
+const Representation = 'name';
+
+const importer = {
+ fields: ["name", "quota", "requiredLabels", "year"],
+};
+
+const entity = {
+ Datagrid,
+ Inputs,
+ Representation,
+ filters,
+ filterDefaultValues,
+ importer,
+};
+
+export default getResourceComponents(entity);
\ No newline at end of file
diff --git a/client/src/entities/known-absence.jsx b/client/src/entities/known-absence.jsx
index 20f66309..964c1d00 100644
--- a/client/src/entities/known-absence.jsx
+++ b/client/src/entities/known-absence.jsx
@@ -24,6 +24,7 @@ const filters = [
,
,
,
+ ,
];
const filterDefaultValues = {
@@ -39,6 +40,9 @@ const Datagrid = ({ isAdmin, children, ...props }) => {
+
+
+
@@ -63,6 +67,7 @@ const Inputs = ({ isCreate, isAdmin }) => {
+
@@ -77,7 +82,7 @@ const Inputs = ({ isCreate, isAdmin }) => {
}
const importer = {
- fields: ['studentTz', 'klassId', 'lessonId', 'reportDate', 'absnceCount', 'absnceCode', 'senderName', 'reason', 'comment', 'isApproved'],
+ fields: ['studentTz', 'klassId', 'lessonId', 'absenceTypeId', 'reportDate', 'absnceCount', 'absnceCode', 'senderName', 'reason', 'comment', 'isApproved'],
}
const additionalListActions = [
diff --git a/client/src/utils/appPermissions.js b/client/src/utils/appPermissions.js
index eef789d7..c938a286 100644
--- a/client/src/utils/appPermissions.js
+++ b/client/src/utils/appPermissions.js
@@ -11,6 +11,7 @@ export const appPermissions = {
approvedAbsencesBulk: 'approvedAbsencesBulk',
teacherView: 'teacherView',
transportation: 'transportation',
+ absenceType: 'absenceType',
};
export const isScannerUpload = (permissions) => hasPermissionLogic(permissions, appPermissions.scannerUpload);
@@ -43,3 +44,6 @@ export const useIsTeacherView = () => useHasPermission(appPermissions.teacherVie
export const isTransportation = (permissions) => hasPermissionLogic(permissions, appPermissions.transportation);
export const useIsTransportation = () => useHasPermission(appPermissions.transportation);
+export const isAbsenceType = (permissions) => hasPermissionLogic(permissions, appPermissions.absenceType);
+export const useIsisAbsenceType = () => useHasPermission(appPermissions.absenceType);
+
diff --git a/server/src/db/entities/AbsenceType.entity.ts b/server/src/db/entities/AbsenceType.entity.ts
new file mode 100644
index 00000000..40d67e60
--- /dev/null
+++ b/server/src/db/entities/AbsenceType.entity.ts
@@ -0,0 +1,67 @@
+import {
+ Column,
+ Entity,
+ Index,
+ JoinColumn,
+ PrimaryGeneratedColumn,
+ BeforeInsert,
+ BeforeUpdate,
+} from 'typeorm';
+import { IHasUserId } from '@shared/base-entity/interface';
+import { User } from 'src/db/entities/User.entity';
+import { IsOptional, Min } from 'class-validator';
+import { CrudValidationGroups } from '@dataui/crud';
+import { IsNotEmpty, IsUniqueCombination, MaxLength, IsNumber } from '@shared/utils/validation/class-validator-he';
+import { StringType, NumberType } from '@shared/utils/entity/class-transformer';
+import { fillDefaultYearValue } from "@shared/utils/entity/year.util";
+import { CreatedAtColumn, UpdatedAtColumn } from '@shared/utils/entity/column-types.util';
+
+@Index('absenceTypes_users_idx', ['userId'], {})
+@Index(['userId', 'name', 'year'], { unique: true })
+@Entity('absenceTypes')
+export class AbsenceType implements IHasUserId {
+ @BeforeInsert()
+ @BeforeUpdate()
+ async fillFields() {
+ fillDefaultYearValue(this);
+ }
+
+ @PrimaryGeneratedColumn({ type: 'int', name: 'id' })
+ id: number;
+
+ @Column('int', { name: 'user_id' })
+ userId: number;
+
+ @Column({ nullable: true })
+ year: number;
+
+ @IsNotEmpty({ groups: [CrudValidationGroups.CREATE] })
+ @StringType
+ @MaxLength(100, { always: true })
+ @Column('varchar', { name: 'name', length: 100 })
+ name: string;
+
+ @IsNumber({ maxDecimalPlaces: 1 }, { always: true })
+ @IsNotEmpty({ groups: [CrudValidationGroups.CREATE] })
+ @Min(0, { always: true })
+ @NumberType
+ @Column('decimal', { name: 'quota', precision: 5, scale: 1 })
+ quota: number;
+
+ @IsOptional({ always: true })
+ @Column({
+ type: 'simple-array',
+ name: 'required_labels',
+ nullable: true,
+ })
+ requiredLabels: string[] | null;
+
+ @CreatedAtColumn()
+ createdAt: Date;
+
+ @UpdatedAtColumn()
+ updatedAt: Date;
+
+ @JoinColumn([{ name: 'user_id', referencedColumnName: 'id' }])
+ user: User;
+}
\ No newline at end of file
diff --git a/server/src/db/entities/KnownAbsence.entity.ts b/server/src/db/entities/KnownAbsence.entity.ts
index b5c345d4..0471011b 100644
--- a/server/src/db/entities/KnownAbsence.entity.ts
+++ b/server/src/db/entities/KnownAbsence.entity.ts
@@ -22,6 +22,7 @@ import { Klass } from "./Klass.entity";
import { Lesson } from "./Lesson.entity";
import { KlassType } from "./KlassType.entity";
import { Teacher } from "./Teacher.entity";
+import { AbsenceType } from "./AbsenceType.entity";
import { DateType, NumberType, StringType } from "@shared/utils/entity/class-transformer";
import { LessonKlassName } from "../view-entities/LessonKlassName.entity";
import { CreatedAtColumn, UpdatedAtColumn } from "@shared/utils/entity/column-types.util";
@@ -39,7 +40,7 @@ export class KnownAbsence implements IHasUserId {
let dataSource: DataSource;
try {
- dataSource = await getDataSource([Student, User, Klass, KlassType, Lesson, Teacher, LessonKlassName]);
+ dataSource = await getDataSource([Student, User, Klass, KlassType, Lesson, Teacher, LessonKlassName, AbsenceType]);
this.studentReferenceId = await findOneAndAssignReferenceId(
dataSource, Student, { tz: this.studentTz }, this.userId, this.studentReferenceId, this.studentTz
@@ -139,6 +140,13 @@ export class KnownAbsence implements IHasUserId {
@Column({ default: true })
isApproved: boolean;
+ @IsOptional({ always: true })
+ @NumberType
+ @IsNumber({ maxDecimalPlaces: 0 }, { always: true })
+ @Column("int", { name: "absence_type_id", nullable: true })
+ absenceTypeId: number | null;
+
+
@CreatedAtColumn()
createdAt: Date;
@@ -163,4 +171,9 @@ export class KnownAbsence implements IHasUserId {
@ManyToOne(() => Klass, { createForeignKeyConstraints: false })
@JoinColumn({ name: 'klassReferenceId' })
klass: Klass;
+
+ @ManyToOne(() => AbsenceType, { createForeignKeyConstraints: false })
+ @JoinColumn({ name: 'absence_type_id' })
+ absenceType: AbsenceType;
+
}
diff --git a/server/src/entities.module.ts b/server/src/entities.module.ts
index 2b475933..8da52e17 100644
--- a/server/src/entities.module.ts
+++ b/server/src/entities.module.ts
@@ -43,6 +43,7 @@ import { AttendanceName } from "./db/entities/AttendanceName.entity";
import reportGroupConfig from "./entity-modules/report-group.config";
import reportGroupSessionConfig from "./entity-modules/report-group-session.config";
import transportationConfig from './entity-modules/transportation.config';
+import absenceTypeConfig from "./entity-modules/absenceType.config";
import { Student } from "./db/entities/Student.entity";
import { Teacher } from "./db/entities/Teacher.entity";
import { registerEntityNameMap } from '@shared/entities/configs/import-file.config';
@@ -103,6 +104,7 @@ registerEntityNameMap({
BaseEntityModule.register({ entity: AbsCountEffectByUser }),
BaseEntityModule.register({ entity: LessonKlassName }),
BaseEntityModule.register(transportationConfig),
+ BaseEntityModule.register(absenceTypeConfig)
]
})
export class EntitiesModule { }
diff --git a/server/src/entity-modules/absenceType.config.ts b/server/src/entity-modules/absenceType.config.ts
new file mode 100644
index 00000000..0f46cc72
--- /dev/null
+++ b/server/src/entity-modules/absenceType.config.ts
@@ -0,0 +1,21 @@
+import { BaseEntityModuleOptions } from '@shared/base-entity/interface';
+import { IHeader } from '@shared/utils/exporter/types';
+import { AbsenceType } from 'src/db/entities/AbsenceType.entity';
+
+function getConfig(): BaseEntityModuleOptions {
+ return {
+ entity: AbsenceType,
+ exporter: {
+ getExportHeaders(): IHeader[] {
+ return [
+ { value: 'name', label: 'סוג חיסור' },
+ { value: 'year', label: 'שנה' },
+ { value: 'quota', label: 'מכסה שנתית' },
+ { value: 'requiredLabels', label: 'שדות חובה לדיווח' },
+ ];
+ },
+ },
+ };
+}
+
+export default getConfig();
\ No newline at end of file
diff --git a/server/src/entity-modules/known-absence.config.ts b/server/src/entity-modules/known-absence.config.ts
index e88187f8..83bce94a 100644
--- a/server/src/entity-modules/known-absence.config.ts
+++ b/server/src/entity-modules/known-absence.config.ts
@@ -11,12 +11,14 @@ function getConfig(): BaseEntityModuleOptions {
student: { eager: false },
lesson: { eager: false },
klass: { eager: false },
+ absenceType: { eager: false },
}
},
exporter: {
processReqForExport(req: CrudRequest, innerFunc) {
req.options.query.join = {
student: { eager: true },
+ absenceType: { eager: true },
};
return innerFunc(req);
},
@@ -25,6 +27,7 @@ function getConfig(): BaseEntityModuleOptions {
{ value: 'student.name', label: 'תלמידה' },
{ value: 'klass.name', label: 'כיתה' },
{ value: 'lesson.name', label: 'שיעור' },
+ { value: 'absenceType.name', label: 'סוג אירוע' },
{ value: 'reportDate', label: 'תאריך דיווח' },
{ value: 'absnceCount', label: 'מספר היעדרויות' },
{ value: 'absnceCode', label: 'קוד היעדרות' },
diff --git a/server/src/migrations/1770908593578-AddAbsenceTypeSupport.ts b/server/src/migrations/1770908593578-AddAbsenceTypeSupport.ts
new file mode 100644
index 00000000..3faf4c42
--- /dev/null
+++ b/server/src/migrations/1770908593578-AddAbsenceTypeSupport.ts
@@ -0,0 +1,43 @@
+import { MigrationInterface, QueryRunner } from "typeorm";
+
+export class AddAbsenceTypeSupport1770908593578 implements MigrationInterface {
+ name = 'AddAbsenceTypeSupport1770908593578'
+
+ public async up(queryRunner: QueryRunner): Promise {
+ await queryRunner.query(`
+ CREATE TABLE \`absenceTypes\` (
+ \`id\` int NOT NULL AUTO_INCREMENT,
+ \`user_id\` int NOT NULL,
+ \`year\` int NULL,
+ \`name\` varchar(100) NOT NULL,
+ \`quota\` decimal(5, 1) NOT NULL,
+ \`required_labels\` text NULL,
+ \`created_at\` timestamp(6) NOT NULL DEFAULT CURRENT_TIMESTAMP(6),
+ \`updated_at\` timestamp(6) NOT NULL DEFAULT CURRENT_TIMESTAMP(6) ON UPDATE CURRENT_TIMESTAMP(6),
+ UNIQUE INDEX \`IDX_351f1bb198705b306e16462dcc\` (\`user_id\`, \`name\`, \`year\`),
+ INDEX \`absenceTypes_users_idx\` (\`user_id\`),
+ PRIMARY KEY (\`id\`)
+ ) ENGINE = InnoDB
+ `);
+ await queryRunner.query(`
+ ALTER TABLE \`known_absences\`
+ ADD \`absence_type_id\` int NULL
+ `);
+ }
+
+ public async down(queryRunner: QueryRunner): Promise {
+ await queryRunner.query(`
+ ALTER TABLE \`known_absences\` DROP COLUMN \`absence_type_id\`
+ `);
+ await queryRunner.query(`
+ DROP INDEX \`absenceTypes_users_idx\` ON \`absenceTypes\`
+ `);
+ await queryRunner.query(`
+ DROP INDEX \`IDX_351f1bb198705b306e16462dcc\` ON \`absenceTypes\`
+ `);
+ await queryRunner.query(`
+ DROP TABLE \`absenceTypes\`
+ `);
+ }
+
+}