resolutionano
This commit is contained in:
@@ -129,7 +129,13 @@ export function preparerLignesPDF(lignesParsed, tarifKm = 0.697) {
|
||||
const km = parseFloat(l.km) || 0;
|
||||
const cv = parseInt(l.chevaux) || 7;
|
||||
|
||||
const indemniteKm = isKm ? getIndemniteKm(km, cv) : 0;
|
||||
const indemniteKm = isKm ? (() => {
|
||||
const b = BAREME_KM[cv];
|
||||
if (!b || km <= 0) return 0;
|
||||
if (km <= 5000) return parseFloat((km * b.t1).toFixed(2));
|
||||
if (km <= 20000) return parseFloat((km * b.t2_a + b.t2_b).toFixed(2));
|
||||
return parseFloat((km * b.t3).toFixed(2));
|
||||
})() : 0;
|
||||
const tarifKmAffiche = isKm ? (km > 0 ? parseFloat((indemniteKm / km).toFixed(3)) : tarifKm) : 0;
|
||||
|
||||
const montantAjuste = l.montantAjuste === true;
|
||||
@@ -208,6 +214,7 @@ export function preparerLignesPDF(lignesParsed, tarifKm = 0.697) {
|
||||
// generateFicheSignee
|
||||
// ─────────────────────────────────────────────────────────────────────────────
|
||||
export async function generateFicheSignee(note, signatures = []) {
|
||||
console.log('🔍 generateFicheSignee montantServeur reçu =', note.montant);
|
||||
const tarifKm = parseFloat(note.tarifKm) || 0.697;
|
||||
|
||||
let lignesPDF = [];
|
||||
@@ -244,22 +251,23 @@ export async function generateFicheSignee(note, signatures = []) {
|
||||
mois = m.charAt(0).toUpperCase() + m.slice(1);
|
||||
}
|
||||
|
||||
return _buildPDF({
|
||||
reference: note.reference || '',
|
||||
nomPrenom: note.nomPrenom || note.collaborateur || '',
|
||||
mois,
|
||||
departement: note.departement || '',
|
||||
lignes: lignesPDF,
|
||||
tarifKm,
|
||||
signatures,
|
||||
statut: note.statut || 'enattente',
|
||||
});
|
||||
return _buildPDF({
|
||||
reference: note.reference || '',
|
||||
nomPrenom: note.nomPrenom || note.collaborateur || '',
|
||||
mois,
|
||||
departement: note.departement || '',
|
||||
lignes: lignesPDF,
|
||||
tarifKm,
|
||||
signatures,
|
||||
statut: note.statut || 'enattente',
|
||||
montantServeur: note.montant ? parseFloat(note.montant) : null,
|
||||
});
|
||||
}
|
||||
|
||||
// ─────────────────────────────────────────────────────────────────────────────
|
||||
// _buildPDF
|
||||
// ─────────────────────────────────────────────────────────────────────────────
|
||||
function _buildPDF({ reference, nomPrenom, mois, departement, lignes, tarifKm, signatures }) {
|
||||
function _buildPDF({ reference, nomPrenom, mois, departement, lignes, tarifKm, signatures, montantServeur }) {
|
||||
return new Promise((resolve, reject) => {
|
||||
const doc = new PDFDocument({
|
||||
size: 'A4', layout: 'landscape', margin: 0,
|
||||
@@ -367,7 +375,7 @@ function _buildPDF({ reference, nomPrenom, mois, departement, lignes, tarifKm, s
|
||||
lib: libelleAffiche,
|
||||
km: km > 0 ? f2(km) : '',
|
||||
tarifKm: tarif > 0 ? f3(tarif) : '',
|
||||
sousKm: sousKm > 0 ? f2(sousKm) : '',
|
||||
sousKm: sousKm > 0 ? f2(sousKm) + ' €' : '',
|
||||
ttc: f2(ttc),
|
||||
tva21: f2(t21), tva55: f2(t55),
|
||||
tva10: f2(t10), tva20: f2(t20),
|
||||
@@ -426,7 +434,7 @@ function _buildPDF({ reference, nomPrenom, mois, departement, lignes, tarifKm, s
|
||||
const totMap = {
|
||||
km: totKm > 0 ? f2(totKm) : '',
|
||||
tarifKm: '',
|
||||
sousKm: totSousKm > 0 ? f2(totSousKm) : '',
|
||||
sousKm: totSousKm > 0 ? f2(totSousKm) + ' €' : '',
|
||||
ttc: f2(totTTC),
|
||||
tva21: f2(totT21), tva55: f2(totT55),
|
||||
tva10: f2(totT10), tva20: f2(totT20),
|
||||
@@ -444,7 +452,7 @@ function _buildPDF({ reference, nomPrenom, mois, departement, lignes, tarifKm, s
|
||||
|
||||
// ── Zone bas ─────────────────────────────────────────────────
|
||||
const footY = totalY + ROW_H + 12;
|
||||
const montantR = parseFloat((totTTC + totSousKm).toFixed(2));
|
||||
const montantR = parseFloat((totTTC + totSousKm).toFixed(2));
|
||||
const bw = 64;
|
||||
|
||||
// ✅ Légende proratisation si au moins une ligne ajustée
|
||||
@@ -469,18 +477,32 @@ function _buildPDF({ reference, nomPrenom, mois, departement, lignes, tarifKm, s
|
||||
|
||||
const labelOffsetY = hasProrata ? 16 : 0;
|
||||
|
||||
doc.font('Helvetica-Bold').fontSize(9).fillColor(C.dark)
|
||||
.text('Montant total à rembourser', MARGIN, footY + 4 + labelOffsetY, { lineBreak: false });
|
||||
drawRect(doc, MARGIN + 180, footY + labelOffsetY, bw + 10, 18, C.amountBg, C.border, 0.5);
|
||||
doc.font('Helvetica-Bold').fontSize(11).fillColor(C.blue)
|
||||
.text(f2(montantR) + ' €',
|
||||
MARGIN + 182, footY + 3.5 + labelOffsetY,
|
||||
{ width: bw + 6, align: 'right', lineBreak: false });
|
||||
// APRÈS
|
||||
doc.font('Helvetica-Bold').fontSize(9).fillColor(C.dark)
|
||||
.text('Montant total à rembourser', MARGIN, footY + 4 + labelOffsetY, { lineBreak: false });
|
||||
|
||||
// Détail calcul km + dépenses
|
||||
doc.font('Helvetica').fontSize(7.5).fillColor(C.grey)
|
||||
.text(
|
||||
totSousKm > 0 && totTTC > 0
|
||||
? `${f2(totSousKm)} € (km) + ${f2(totTTC)} € (dépenses) =`
|
||||
: totSousKm > 0
|
||||
? `${f2(totSousKm)} € (indemnités kilométriques) =`
|
||||
: `${f2(totTTC)} € (dépenses) =`,
|
||||
MARGIN, footY + 17 + labelOffsetY,
|
||||
{ lineBreak: false }
|
||||
);
|
||||
|
||||
drawRect(doc, MARGIN + 220, footY + 13 + labelOffsetY, bw + 10, 18, C.amountBg, C.border, 0.5);
|
||||
doc.font('Helvetica-Bold').fontSize(11).fillColor(C.blue)
|
||||
.text(f2(montantR) + ' €',
|
||||
MARGIN + 222, footY + 16.5 + labelOffsetY,
|
||||
{ width: bw + 6, align: 'right', lineBreak: false });
|
||||
|
||||
doc.font('Helvetica').fontSize(6.5).fillColor(C.grey)
|
||||
.text(
|
||||
`Tarif km appliqué : ${tarifKm.toFixed(3)} €/km — Sous-total km : ${f2(totSousKm)} € — TTC hors km : ${f2(totTTC)} €`,
|
||||
MARGIN, footY + 24 + labelOffsetY, { lineBreak: false }
|
||||
` Sous-total km : ${f2(totSousKm)} € — TTC hors km : ${f2(totTTC)} € — Total : ${f2(totSousKm)} € + ${f2(totTTC)} € = ${f2(montantR)} €`,
|
||||
MARGIN, footY + 34 + labelOffsetY, { lineBreak: false }
|
||||
);
|
||||
|
||||
// ── Signatures ────────────────────────────────────────────────
|
||||
|
||||
Reference in New Issue
Block a user