fix(seeders): minor data fix and added Decimal to mileage

This commit is contained in:
Matthieu Haineault 2025-10-09 10:39:17 -04:00
parent 7c7edea768
commit fba3c02f48
5 changed files with 82 additions and 24 deletions

View File

@ -1134,6 +1134,45 @@
"SchedulePresets"
]
}
},
"/schedule-presets/apply-presets/{email}": {
"post": {
"operationId": "SchedulePresetsController_applyPresets",
"parameters": [
{
"name": "email",
"required": true,
"in": "path",
"schema": {
"type": "string"
}
},
{
"name": "preset",
"required": true,
"in": "query",
"schema": {
"type": "string"
}
},
{
"name": "start",
"required": true,
"in": "query",
"schema": {
"type": "string"
}
}
],
"responses": {
"201": {
"description": ""
}
},
"tags": [
"SchedulePresets"
]
}
}
},
"info": {

View File

@ -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);

View File

@ -10,13 +10,13 @@ async function main() {
['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'],
['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'],
['HOLIDAY' ,'SHIFT' , 2.0 , 'G700'],
];
await prisma.bankCodes.createMany({

View File

@ -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,
},

View File

@ -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")
}