fix(seeders): fix holiday bank_code and week_start logics to match Sunday to Saturday
This commit is contained in:
parent
a88aaf34f0
commit
d1c41ea1bd
|
|
@ -6,17 +6,19 @@ const prisma = new PrismaClient();
|
||||||
const PREVIOUS_WEEKS = 16; // nombre de semaines à créer (passé)
|
const PREVIOUS_WEEKS = 16; // nombre de semaines à créer (passé)
|
||||||
const INCLUDE_CURRENT = false; // true si tu veux aussi la semaine courante
|
const INCLUDE_CURRENT = false; // true si tu veux aussi la semaine courante
|
||||||
|
|
||||||
// Lundi (UTC) de la semaine courante
|
// Dimanche (UTC) de la semaine courante
|
||||||
function mondayOfThisWeekUTC(now = new Date()) {
|
function sundayOfThisWeekUTC(now = new Date()) {
|
||||||
|
// normalise à minuit UTC du jour courant
|
||||||
const d = new Date(Date.UTC(now.getUTCFullYear(), now.getUTCMonth(), now.getUTCDate()));
|
const d = new Date(Date.UTC(now.getUTCFullYear(), now.getUTCMonth(), now.getUTCDate()));
|
||||||
const day = d.getUTCDay(); // 0=Dim, 1=Lun, ...
|
const day = d.getUTCDay(); // 0=Dim, 1=Lun, ... 6=Sam
|
||||||
const diffToMonday = (day + 6) % 7; // 0 si lundi
|
// recule jusqu'au dimanche de cette semaine
|
||||||
d.setUTCDate(d.getUTCDate() - diffToMonday);
|
d.setUTCDate(d.getUTCDate() - day);
|
||||||
d.setUTCHours(0, 0, 0, 0);
|
d.setUTCHours(0, 0, 0, 0);
|
||||||
return d;
|
return d;
|
||||||
}
|
}
|
||||||
function mondayNWeeksBefore(monday: Date, n: number) {
|
|
||||||
const d = new Date(monday);
|
function sundayNWeeksBefore(sunday: Date, n: number) {
|
||||||
|
const d = new Date(sunday);
|
||||||
d.setUTCDate(d.getUTCDate() - n * 7);
|
d.setUTCDate(d.getUTCDate() - n * 7);
|
||||||
return d;
|
return d;
|
||||||
}
|
}
|
||||||
|
|
@ -28,21 +30,21 @@ async function main() {
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
// Construit la liste des lundis (1 par semaine)
|
// Construit la liste des dimanches (1 par semaine)
|
||||||
const mondays: Date[] = [];
|
const sundays: Date[] = [];
|
||||||
const mondayThisWeek = mondayOfThisWeekUTC();
|
const sundayThisWeek = sundayOfThisWeekUTC();
|
||||||
if (INCLUDE_CURRENT) mondays.push(mondayThisWeek);
|
if (INCLUDE_CURRENT) sundays.push(sundayThisWeek);
|
||||||
for (let n = 1; n <= PREVIOUS_WEEKS; n++) {
|
for (let n = 1; n <= PREVIOUS_WEEKS; n++) {
|
||||||
mondays.push(mondayNWeeksBefore(mondayThisWeek, n));
|
sundays.push(sundayNWeeksBefore(sundayThisWeek, n));
|
||||||
}
|
}
|
||||||
|
|
||||||
// Prépare les lignes (1 timesheet / employé / semaine)
|
// Prépare les lignes (1 timesheet / employé / semaine)
|
||||||
const rows: Prisma.TimesheetsCreateManyInput[] = [];
|
const rows: Prisma.TimesheetsCreateManyInput[] = [];
|
||||||
for (const e of employees) {
|
for (const e of employees) {
|
||||||
for (const monday of mondays) {
|
for (const sunday of sundays) {
|
||||||
rows.push({
|
rows.push({
|
||||||
employee_id: e.id,
|
employee_id: e.id,
|
||||||
start_date: monday,
|
start_date: sunday,
|
||||||
is_approved: Math.random() < 0.3,
|
is_approved: Math.random() < 0.3,
|
||||||
} as Prisma.TimesheetsCreateManyInput);
|
} as Prisma.TimesheetsCreateManyInput);
|
||||||
}
|
}
|
||||||
|
|
|
||||||
|
|
@ -71,7 +71,7 @@ async function getOrCreateTimesheet(employee_id: number, start_date: Date) {
|
||||||
|
|
||||||
async function main() {
|
async function main() {
|
||||||
// --- Bank codes (pondérés: surtout G1 = régulier) ---
|
// --- Bank codes (pondérés: surtout G1 = régulier) ---
|
||||||
const BANKS = ['G1', 'G56', 'G48', 'G700', 'G105', 'G305'] as const;
|
const BANKS = ['G1', 'G56', 'G48','G105','G104', 'G305'] as const;
|
||||||
const WEIGHTED_CODES = [
|
const WEIGHTED_CODES = [
|
||||||
'G1','G1','G1','G1','G1','G1','G1','G1','G1','G1','G1','G1',
|
'G1','G1','G1','G1','G1','G1','G1','G1','G1','G1','G1','G1',
|
||||||
'G56','G48','G104','G105','G305','G1','G1','G1','G1','G1','G1'
|
'G56','G48','G104','G105','G305','G1','G1','G1','G1','G1','G1'
|
||||||
|
|
@ -181,7 +181,7 @@ async function main() {
|
||||||
data: {
|
data: {
|
||||||
timesheet_id: ts.id,
|
timesheet_id: ts.id,
|
||||||
bank_code_id: bcMorningId,
|
bank_code_id: bcMorningId,
|
||||||
comment: `Matin J${di + 1} (sem ${monday.toISOString().slice(0, 10)}) emp ${e.id} — ${bcMorningCode}`,
|
comment: `Matin J${di + 1} (sem ${monday.toISOString().slice(0, 10)}) emp ${e.id} - ${bcMorningCode}`,
|
||||||
date,
|
date,
|
||||||
start_time: timeAt(startH, startM),
|
start_time: timeAt(startH, startM),
|
||||||
end_time: timeAt(lunchStartHM.h, lunchStartHM.m),
|
end_time: timeAt(lunchStartHM.h, lunchStartHM.m),
|
||||||
|
|
|
||||||
Loading…
Reference in New Issue
Block a user