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("═══════════════════════════════════════════════════════════");
|
console.log("═══════════════════════════════════════════════════════════");
|
||||||
|
|
||||||
// Build line items for payslips
|
// Build line items for payslips
|
||||||
const lineItems = (payslips || []).map((p: any) => {
|
const lineItems = (payslips || [])
|
||||||
const contract = p.cddu_contracts;
|
.map((p: any) => {
|
||||||
const salarie = contract?.salaries;
|
const contract = p.cddu_contracts;
|
||||||
|
const salarie = contract?.salaries;
|
||||||
// Get employee name
|
|
||||||
const employee_name = `${salarie?.prenom || ""} ${salarie?.nom || ""}`.trim();
|
// Get employee name in format "NOM Prénom"
|
||||||
|
const nom = (salarie?.nom || "").trim().toUpperCase();
|
||||||
// Utiliser le montant personnalisé si disponible, sinon le montant de la paie
|
const prenom = (salarie?.prenom || "").trim();
|
||||||
const montant = p.custom_amount !== null && p.custom_amount !== undefined
|
const employee_name = nom && prenom ? `${nom} ${prenom}` : (nom || prenom || "");
|
||||||
? parseFloat(p.custom_amount)
|
|
||||||
: parseFloat(p.net_after_withholding || p.net_amount || 0);
|
// Utiliser le montant personnalisé si disponible, sinon le montant de la paie
|
||||||
|
const montant = p.custom_amount !== null && p.custom_amount !== undefined
|
||||||
console.log("[generate-pdf] 👤 Processing payslip:", {
|
? parseFloat(p.custom_amount)
|
||||||
payslip_id: p.id,
|
: parseFloat(p.net_after_withholding || p.net_amount || 0);
|
||||||
has_contract: !!contract,
|
|
||||||
has_salarie: !!salarie,
|
console.log("[generate-pdf] 👤 Processing payslip:", {
|
||||||
employee_name,
|
payslip_id: p.id,
|
||||||
net_amount: p.net_amount,
|
has_contract: !!contract,
|
||||||
net_after_withholding: p.net_after_withholding,
|
has_salarie: !!salarie,
|
||||||
custom_amount: p.custom_amount,
|
employee_name,
|
||||||
final_montant: montant
|
net_amount: p.net_amount,
|
||||||
});
|
net_after_withholding: p.net_after_withholding,
|
||||||
|
custom_amount: p.custom_amount,
|
||||||
return {
|
final_montant: montant
|
||||||
employee_name,
|
});
|
||||||
matricule: contract?.employee_matricule || "",
|
|
||||||
contrat: contract?.contract_number || "",
|
return {
|
||||||
montant,
|
employee_name,
|
||||||
analytique: contract?.analytique || "",
|
nom_for_sorting: nom, // Utilisé pour le tri
|
||||||
profession: contract?.profession || "",
|
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");
|
console.log("[generate-pdf] ✅ Line items built:", lineItems.length, "items");
|
||||||
if (lineItems.length > 0) {
|
if (lineItems.length > 0) {
|
||||||
|
|
|
||||||
Loading…
Reference in a new issue