targo-backend/src/time-and-attendance/exports/services/csv-builder.service.ts
2026-03-17 07:52:18 -04:00

34 lines
1.2 KiB
TypeScript

import { Injectable } from "@nestjs/common";
import { CsvRow } from "src/time-and-attendance/exports/export-csv-options.dto";
@Injectable()
export class CsvGeneratorService {
//csv builder and "mise en page"
generateCsv(
rows: CsvRow[]
): Buffer {
const body = rows.map(row => {
const quantity_hours = (typeof row.quantite_hre === 'number' && row.montant !== 0) ? row.quantite_hre.toFixed(2) : '';
const amount = (typeof row.montant === 'number' && row.montant !== 0) ? row.montant.toFixed(2) : '';
return [
row.compagnie_no,
row.employee_matricule,
row.releve ?? '',
row.type_transaction,
row.code,
quantity_hours,
row.taux_horaire ?? '',
amount,
row.semaine_no,
row.division_no ?? '',
row.service_no ?? '',
row.departem_no ?? '',
row.sous_departem_no ?? '',
row.date_transaction,
row.premier_jour_absence ?? '',
row.dernier_jour_absence ?? '',
].join(';');
}).join('\n');
return Buffer.from('\uFEFF' + body, 'utf8');
}
}