66 lines
1.9 KiB
TypeScript
66 lines
1.9 KiB
TypeScript
// // 13-expenses-archive.ts
|
|
// import { PrismaClient, Expenses } from '@prisma/client';
|
|
|
|
// if (process.env.SKIP_LEAVE_REQUESTS === 'true') {
|
|
// console.log("⏭ Seed leave-requests ignoré (SKIP_LEAVE_REQUESTS=true)");
|
|
// process.exit(0);
|
|
// }
|
|
|
|
// const prisma = new PrismaClient();
|
|
|
|
// function daysAgo(n:number) {
|
|
// const d = new Date();
|
|
// d.setUTCDate(d.getUTCDate() - n);
|
|
// d.setUTCHours(0,0,0,0);
|
|
// return d;
|
|
// }
|
|
|
|
// async function main() {
|
|
// const expenseCodes = await prisma.bankCodes.findMany({ where: { categorie: 'EXPENSE' }, select: { id: true } });
|
|
// const timesheets = await prisma.timesheets.findMany({ select: { id: true } });
|
|
|
|
// // ✅ typer pour éviter never[]
|
|
// const created: Expenses[] = [];
|
|
|
|
// for (let i = 0; i < 4; i++) {
|
|
// const ts = timesheets[i % timesheets.length];
|
|
// const bc = expenseCodes[i % expenseCodes.length];
|
|
|
|
// const exp = await prisma.expenses.create({
|
|
// data: {
|
|
// timesheet_id: ts.id,
|
|
// bank_code_id: bc.id,
|
|
// date: daysAgo(60 + i),
|
|
// amount: (20 + i * 3.5).toFixed(2), // ok: Decimal accepte string
|
|
// attachment: null,
|
|
// comment: `Old expense #${i + 1}`,
|
|
// is_approved: true,
|
|
// supervisor_comment: null,
|
|
// },
|
|
// });
|
|
|
|
// created.push(exp);
|
|
// }
|
|
|
|
// for (const e of created) {
|
|
// await prisma.expensesArchive.create({
|
|
// data: {
|
|
// expense_id: e.id,
|
|
// timesheet_id: e.timesheet_id,
|
|
// bank_code_id: e.bank_code_id,
|
|
// date: e.date,
|
|
// amount: e.amount,
|
|
// attachment: e.attachment,
|
|
// comment: e.comment,
|
|
// is_approved: e.is_approved,
|
|
// supervisor_comment: e.supervisor_comment,
|
|
// },
|
|
// });
|
|
// }
|
|
|
|
// const total = await prisma.expensesArchive.count();
|
|
// console.log(`✓ ExpensesArchive: ${total} total rows (added ${created.length})`);
|
|
// }
|
|
|
|
// main().finally(() => prisma.$disconnect());
|