Ajuste les mentions et numeros de facture

This commit is contained in:
Michael committed 2026-07-17 00:37:12 +02:00
1 parent dd1053491b
commit fc1dffd940
2 files changed
+11 -5

No files matched your search

+5 -3
View File
@@ -40,7 +40,7 @@ export function sanitizeLegalMentions(value) {
.join('\n'); .join('\n');
} }
function collectPdf(draw, options = {}) { function collectPdf(draw, { pageNumbers = true, ...options } = {}) {
return new Promise((resolve, reject) => { return new Promise((resolve, reject) => {
const doc = new PDFDocument({ size: 'A4', margin: 48, bufferPages: true, ...options }); const doc = new PDFDocument({ size: 'A4', margin: 48, bufferPages: true, ...options });
const chunks = []; const chunks = [];
@@ -48,6 +48,7 @@ function collectPdf(draw, options = {}) {
doc.on('end', () => resolve(Buffer.concat(chunks))); doc.on('end', () => resolve(Buffer.concat(chunks)));
doc.on('error', reject); doc.on('error', reject);
draw(doc); draw(doc);
if (pageNumbers) {
const range = doc.bufferedPageRange(); const range = doc.bufferedPageRange();
for (let page = range.start; page < range.start + range.count; page += 1) { for (let page = range.start; page < range.start + range.count; page += 1) {
doc.switchToPage(page); doc.switchToPage(page);
@@ -61,6 +62,7 @@ function collectPdf(draw, options = {}) {
); );
doc.page.margins.bottom = bottomMargin; doc.page.margins.bottom = bottomMargin;
} }
}
doc.end(); doc.end();
}); });
} }
@@ -129,7 +131,7 @@ export function buildInvoicePdf(invoice) {
? `Facture réglée le ${dateFr(invoice.paid_at)} par ${paymentLabel(invoice.payment_method).toLowerCase()}.` ? `Facture réglée le ${dateFr(invoice.paid_at)} par ${paymentLabel(invoice.payment_method).toLowerCase()}.`
: invoice.status === 'annulee' : invoice.status === 'annulee'
? 'Facture annulée.' ? 'Facture annulée.'
: `Paiement attendu avant le ${dateFr(invoice.due_date)} par virement, chèque ou carte bleue.`; : `Paiement attendu avant le ${dateFr(invoice.due_date)} par virement ou chèque.`;
doc.font('Helvetica').fontSize(8.5).fillColor(GRAY).text(paymentStatus, 48, 655, { width: 499 }); doc.font('Helvetica').fontSize(8.5).fillColor(GRAY).text(paymentStatus, 48, 655, { width: 499 });
const ribValues = [issuer.iban, issuer.bic, issuer.rib_account_holder, issuer.rib_bank_name, const ribValues = [issuer.iban, issuer.bic, issuer.rib_account_holder, issuer.rib_bank_name,
issuer.rib_bank_code, issuer.rib_branch_code, issuer.rib_account_number, issuer.rib_key]; issuer.rib_bank_code, issuer.rib_branch_code, issuer.rib_account_number, issuer.rib_key];
@@ -175,7 +177,7 @@ export function buildInvoicePdf(invoice) {
doc.moveTo(48, 84).lineTo(547, 84).lineWidth(2).strokeColor(RED).stroke(); doc.moveTo(48, 84).lineTo(547, 84).lineWidth(2).strokeColor(RED).stroke();
doc.font('Helvetica').fontSize(9).fillColor(GRAY).text(legalMentions, 48, 108, { width: 499, lineGap: 3 }); doc.font('Helvetica').fontSize(9).fillColor(GRAY).text(legalMentions, 48, 108, { width: 499, lineGap: 3 });
} }
}, { info: { Title: `Facture ${invoice.invoice_number}`, Author: text(invoice.issuer_snapshot?.association_name) } }); }, { pageNumbers: false, info: { Title: `Facture ${invoice.invoice_number}`, Author: text(invoice.issuer_snapshot?.association_name) } });
} }
export function buildPaidMembersPdf({ season, rows }) { export function buildPaidMembersPdf({ season, rows }) {
+6 -2
View File
@@ -219,8 +219,12 @@ billingRouter.post('/seasons/:season/invoices', validate(billingSeasonParam, 'pa
? settings.sluc_partner_amount_ht ? settings.sluc_partner_amount_ht
: settings.non_partner_amount_ht; : settings.non_partner_amount_ht;
const amountNet = Math.round(amountHt * 100) / 100; const amountNet = Math.round(amountHt * 100) / 100;
const sequence = await client.query(`SELECT nextval('billing_invoice_number_seq') AS n`); const sequence = await client.query(
const invoiceNumber = `FAC-${req.params.season.slice(0, 4)}-${String(sequence.rows[0].n).padStart(5, '0')}`; `SELECT nextval('billing_invoice_number_seq') AS n,
to_char(CURRENT_DATE, 'YYYY') AS year,
to_char(CURRENT_DATE, 'MM') AS month`
);
const invoiceNumber = `FAC-${sequence.rows[0].year}-${sequence.rows[0].month}-${String(sequence.rows[0].n).padStart(5, '0')}`;
await client.query( await client.query(
`INSERT INTO membership_invoices `INSERT INTO membership_invoices
(season, member_id, invoice_number, due_date, member_name, member_address, member_email, (season, member_id, invoice_number, due_date, member_name, member_address, member_email,