feat: Tri alphabétique et format NOM Prénom pour appels à virement
This commit is contained in:
parent
4000883fab
commit
8e9d628e5e
1 changed files with 38 additions and 32 deletions
|
|
@ -311,38 +311,44 @@ export async function POST(req: NextRequest) {
|
|||
console.log("═══════════════════════════════════════════════════════════");
|
||||
|
||||
// Build line items for payslips
|
||||
const lineItems = (payslips || []).map((p: any) => {
|
||||
const contract = p.cddu_contracts;
|
||||
const salarie = contract?.salaries;
|
||||
|
||||
// Get employee name
|
||||
const employee_name = `${salarie?.prenom || ""} ${salarie?.nom || ""}`.trim();
|
||||
|
||||
// Utiliser le montant personnalisé si disponible, sinon le montant de la paie
|
||||
const montant = p.custom_amount !== null && p.custom_amount !== undefined
|
||||
? parseFloat(p.custom_amount)
|
||||
: parseFloat(p.net_after_withholding || p.net_amount || 0);
|
||||
|
||||
console.log("[generate-pdf] 👤 Processing payslip:", {
|
||||
payslip_id: p.id,
|
||||
has_contract: !!contract,
|
||||
has_salarie: !!salarie,
|
||||
employee_name,
|
||||
net_amount: p.net_amount,
|
||||
net_after_withholding: p.net_after_withholding,
|
||||
custom_amount: p.custom_amount,
|
||||
final_montant: montant
|
||||
});
|
||||
|
||||
return {
|
||||
employee_name,
|
||||
matricule: contract?.employee_matricule || "",
|
||||
contrat: contract?.contract_number || "",
|
||||
montant,
|
||||
analytique: contract?.analytique || "",
|
||||
profession: contract?.profession || "",
|
||||
};
|
||||
});
|
||||
const lineItems = (payslips || [])
|
||||
.map((p: any) => {
|
||||
const contract = p.cddu_contracts;
|
||||
const salarie = contract?.salaries;
|
||||
|
||||
// Get employee name in format "NOM Prénom"
|
||||
const nom = (salarie?.nom || "").trim().toUpperCase();
|
||||
const prenom = (salarie?.prenom || "").trim();
|
||||
const employee_name = nom && prenom ? `${nom} ${prenom}` : (nom || prenom || "");
|
||||
|
||||
// Utiliser le montant personnalisé si disponible, sinon le montant de la paie
|
||||
const montant = p.custom_amount !== null && p.custom_amount !== undefined
|
||||
? parseFloat(p.custom_amount)
|
||||
: parseFloat(p.net_after_withholding || p.net_amount || 0);
|
||||
|
||||
console.log("[generate-pdf] 👤 Processing payslip:", {
|
||||
payslip_id: p.id,
|
||||
has_contract: !!contract,
|
||||
has_salarie: !!salarie,
|
||||
employee_name,
|
||||
net_amount: p.net_amount,
|
||||
net_after_withholding: p.net_after_withholding,
|
||||
custom_amount: p.custom_amount,
|
||||
final_montant: montant
|
||||
});
|
||||
|
||||
return {
|
||||
employee_name,
|
||||
nom_for_sorting: nom, // Utilisé pour le tri
|
||||
matricule: contract?.employee_matricule || "",
|
||||
contrat: contract?.contract_number || "",
|
||||
montant,
|
||||
analytique: contract?.analytique || "",
|
||||
profession: contract?.profession || "",
|
||||
};
|
||||
})
|
||||
.sort((a, b) => a.nom_for_sorting.localeCompare(b.nom_for_sorting, 'fr')) // Tri alphabétique par nom
|
||||
.map(({ nom_for_sorting, ...item }) => item); // Retirer le champ de tri temporaire
|
||||
|
||||
console.log("[generate-pdf] ✅ Line items built:", lineItems.length, "items");
|
||||
if (lineItems.length > 0) {
|
||||
|
|
|
|||
Loading…
Reference in a new issue