fix: Corriger récupération des emails de notification et améliorer labels de templates
- Modifier l'API GET /staff/facturation/[id] pour inclure organization_details avec emails - Retourner les infos complètes de l'organisation (email_notifs, email_notifs_cc) - Améliorer les noms de templates de factures : * 'Facture (type non défini)' au lieu de 'Invoice générique' * Retirer 'Invoice' des noms de templates * Afficher le type personnalisé si non reconnu - Les factures auront maintenant leurs emails correctement affichés dans le modal
This commit is contained in:
parent
0b453b272e
commit
13d844921e
2 changed files with 21 additions and 18 deletions
|
|
@ -63,10 +63,20 @@ export async function GET(req: Request, { params }: { params: { id: string } })
|
|||
return NextResponse.json({ error: 'forbidden', message: 'Staff access required' }, { status: 403 });
|
||||
}
|
||||
|
||||
// Récupérer la facture
|
||||
// Récupérer la facture avec les informations de l'organisation
|
||||
const { data: invoice, error } = await supabase
|
||||
.from('invoices')
|
||||
.select('*')
|
||||
.select(`
|
||||
*,
|
||||
organizations!inner(
|
||||
id,
|
||||
structure_api,
|
||||
organization_details!inner(
|
||||
email_notifs,
|
||||
email_notifs_cc
|
||||
)
|
||||
)
|
||||
`)
|
||||
.eq('id', params.id)
|
||||
.single();
|
||||
|
||||
|
|
@ -78,16 +88,8 @@ export async function GET(req: Request, { params }: { params: { id: string } })
|
|||
return NextResponse.json({ error: 'supabase_error', detail: error.message }, { status: 500 });
|
||||
}
|
||||
|
||||
// Récupérer le nom de l'organisation
|
||||
let organizationName = null;
|
||||
if (invoice.org_id) {
|
||||
const { data: orgData } = await supabase
|
||||
.from('organizations')
|
||||
.select('structure_api')
|
||||
.eq('id', invoice.org_id)
|
||||
.single();
|
||||
organizationName = orgData?.structure_api || null;
|
||||
}
|
||||
// Le nom de l'organisation est déjà inclus dans la requête
|
||||
const organizationName = invoice.organizations?.structure_api || null;
|
||||
|
||||
// Presign S3 URL for PDF
|
||||
let signedPdfUrl: string | null = null;
|
||||
|
|
@ -128,6 +130,7 @@ export async function GET(req: Request, { params }: { params: { id: string } })
|
|||
created_at: invoice.created_at,
|
||||
updated_at: invoice.updated_at,
|
||||
notes: invoice.notes || null,
|
||||
organizations: invoice.organizations, // Inclure les infos complètes de l'organisation
|
||||
};
|
||||
|
||||
return NextResponse.json(result);
|
||||
|
|
|
|||
|
|
@ -28,19 +28,19 @@ const fmtEUR = new Intl.NumberFormat("fr-FR", { style: "currency", currency: "EU
|
|||
|
||||
// Obtenir le nom du template selon le type de facture
|
||||
function getInvoiceTemplateName(invoiceType: string | null | undefined, paymentMethod?: string | null): string {
|
||||
if (!invoiceType) return 'Invoice générique';
|
||||
if (!invoiceType) return 'Facture (type non défini)';
|
||||
|
||||
switch (invoiceType) {
|
||||
case 'paie_mensuelle':
|
||||
return paymentMethod === 'virement' ? 'Invoice Paie Mensuelle (Virement)' : 'Invoice Paie Mensuelle (SEPA)';
|
||||
return paymentMethod === 'virement' ? 'Paie Mensuelle (Virement)' : 'Paie Mensuelle (SEPA)';
|
||||
case 'paie_ouverture':
|
||||
return 'Invoice Paie Ouverture';
|
||||
return 'Paie Ouverture';
|
||||
case 'studio_site_web':
|
||||
return paymentMethod === 'virement' ? 'Invoice Studio Site Web (Virement)' : 'Invoice Studio Site Web (SEPA)';
|
||||
return paymentMethod === 'virement' ? 'Studio Site Web (Virement)' : 'Studio Site Web (SEPA)';
|
||||
case 'studio_renouvellement':
|
||||
return paymentMethod === 'virement' ? 'Invoice Studio Renouvellement (Virement)' : 'Invoice Studio Renouvellement (SEPA)';
|
||||
return paymentMethod === 'virement' ? 'Studio Renouvellement (Virement)' : 'Studio Renouvellement (SEPA)';
|
||||
default:
|
||||
return 'Invoice générique';
|
||||
return `Type personnalisé : ${invoiceType}`;
|
||||
}
|
||||
}
|
||||
|
||||
|
|
|
|||
Loading…
Reference in a new issue