diff --git a/prisma/migrations/20251009141338_change_type_mileage/migration.sql b/prisma/migrations/20251009141338_change_type_mileage/migration.sql new file mode 100644 index 0000000..f43e8de --- /dev/null +++ b/prisma/migrations/20251009141338_change_type_mileage/migration.sql @@ -0,0 +1,12 @@ +/* + Warnings: + + - You are about to alter the column `mileage` on the `expenses` table. The data in that column could be lost. The data in that column will be cast from `Decimal(65,30)` to `Decimal(12,2)`. + - You are about to alter the column `mileage` on the `expenses_archive` table. The data in that column could be lost. The data in that column will be cast from `Decimal(65,30)` to `Decimal(12,2)`. + +*/ +-- AlterTable +ALTER TABLE "expenses" ALTER COLUMN "mileage" SET DATA TYPE DECIMAL(12,2); + +-- AlterTable +ALTER TABLE "expenses_archive" ALTER COLUMN "mileage" SET DATA TYPE DECIMAL(12,2); diff --git a/prisma/mock-seeds-scripts/01-bankCodes.ts b/prisma/mock-seeds-scripts/01-bankCodes.ts index 320db5d..2b1ade9 100644 --- a/prisma/mock-seeds-scripts/01-bankCodes.ts +++ b/prisma/mock-seeds-scripts/01-bankCodes.ts @@ -4,19 +4,19 @@ const prisma = new PrismaClient(); async function main() { const presets = [ - // type, categorie, modifier, bank_code - ['REGULAR' ,'SHIFT' , 1.0 , 'G1' ], - ['OVERTIME' ,'SHIFT' , 2 , 'G43' ], - ['EMERGENCY' ,'SHIFT' , 2 , 'G48' ], - ['EVENING' ,'SHIFT' , 1.25, 'G56' ], - ['SICK' ,'SHIFT' , 1.0 , 'G105'], - ['PRIME_DISPO','EXPENSE', 1.0 , 'G202'], - ['COMMISSION' ,'EXPENSE', 1.0 , 'G234'], - ['VACATION' ,'SHIFT' , 1.0 , 'G305'], - ['PER_DIEM' ,'EXPENSE', 1.0 , 'G502'], - ['MILEAGE' ,'EXPENSE', 0.72, 'G503'], - ['EXPENSES' ,'EXPENSE', 1.0 , 'G517'], - ['HOLIDAY' ,'SHIFT' , 2.0 , 'G700'], + // type, categorie, modifier, bank_code + ['REGULAR' ,'SHIFT' , 1.0 , 'G1' ], + ['OVERTIME' ,'SHIFT' , 2 , 'G43' ], + ['EMERGENCY' ,'SHIFT' , 2 , 'G48' ], + ['EVENING' ,'SHIFT' , 1.25 , 'G56' ], + ['SICK' ,'SHIFT' , 1.0 , 'G105'], + ['HOLIDAY' ,'SHIFT' , 1.0 , 'G104'], + ['VACATION' ,'SHIFT' , 1.0 , 'G305'], + ['ON_CALL' ,'EXPENSE' , 1.0 , 'G202'], + ['COMMISSION' ,'EXPENSE' , 1.0 , 'G234'], + ['PER_DIEM' ,'EXPENSE' , 1.0 , 'G502'], + ['MILEAGE' ,'EXPENSE' , 0.72 , 'G503'], + ['EXPENSES' ,'EXPENSE' , 1.0 , 'G517'], ]; await prisma.bankCodes.createMany({ diff --git a/prisma/mock-seeds-scripts/12-expenses.ts b/prisma/mock-seeds-scripts/12-expenses.ts index 622b30d..926a52f 100644 --- a/prisma/mock-seeds-scripts/12-expenses.ts +++ b/prisma/mock-seeds-scripts/12-expenses.ts @@ -43,6 +43,11 @@ function centsToAmountString(cents: number): string { return `${sign}${dollars}.${c.toString().padStart(2, '0')}`; } +function to2(value: string): string { + // normalise au cas où (sécurité) + return (Math.round(parseFloat(value) * 100) / 100).toFixed(2); +} + // Tire un multiple de STEP_CENTS entre minCents et maxCents (inclus) function rndQuantizedCents(minCents: number, maxCents: number, step = STEP_CENTS): number { const qmin = Math.ceil(minCents / step); @@ -118,20 +123,21 @@ async function main() { const bank_code_id = bcMap.get(code)!; // Montants (cents) quantisés à 25¢ => aucun flottant binaire plus tard - let amount: string; + let amount: string = '0.00'; + let mileage: string = '0.00'; switch (code) { case 'G503': // kilométrage - amount = rndAmount(1000, 7500); // 10.00 à 75.00 + mileage = to2(rndAmount(1000, 7500)); // 10.00 à 75.00 break; case 'G502': // per_diem - amount = rndAmount(1500, 3000); // 15.00 à 30.00 + amount = to2(rndAmount(1500, 3000)); // 15.00 à 30.00 break; - case 'G202': // allowance /prime de garde - amount = rndAmount(2000, 15000); // 20.00 à 150.00 + case 'G202': // on_call /prime de garde + amount = to2(rndAmount(2000, 15000)); // 20.00 à 150.00 break; case 'G517': // expenses default: - amount = rndAmount(500, 5000); // 5.00 à 50.00 + amount = to2(rndAmount(500, 5000)); // 5.00 à 50.00 break; } @@ -140,9 +146,10 @@ async function main() { timesheet_id: ts.id, bank_code_id, date, - amount, // string "xx.yy" (2 décimales exactes) + amount, + mileage, attachment: null, - comment: `Expense ${code} ${amount}$ (emp ${e.id})`, + comment: `Expense ${code} (emp ${e.id})`, is_approved: Math.random() < 0.65, supervisor_comment: Math.random() < 0.25 ? 'OK' : null, }, diff --git a/prisma/schema.prisma b/prisma/schema.prisma index b223fa3..dd489c2 100644 --- a/prisma/schema.prisma +++ b/prisma/schema.prisma @@ -289,7 +289,7 @@ model Expenses { date DateTime @db.Date amount Decimal @db.Money - mileage Decimal? + mileage Decimal? @db.Decimal(12,2) comment String supervisor_comment String? is_approved Boolean @default(false) @@ -311,7 +311,7 @@ model ExpensesArchive { bank_code_id Int date DateTime @db.Date amount Decimal? @db.Money - mileage Decimal? + mileage Decimal? @db.Decimal(12,2) comment String? is_approved Boolean supervisor_comment String? @@ -380,7 +380,7 @@ model Preferences { dark_mode Boolean @default(false) lang_switch Boolean @default(false) lefty_mode Boolean @default(false) - +// TODO: change BOOLEAN to use 0 or 1 in case there is more than 2 options for each preferences @@map("preferences") }