Initial commit - Facturation SANTINOVA
This commit is contained in:
102
frontend/src/utils/helpers.ts
Normal file
102
frontend/src/utils/helpers.ts
Normal file
@@ -0,0 +1,102 @@
|
||||
export function formatCurrency(amount: string | number | undefined | null): string {
|
||||
if (amount === undefined || amount === null || amount === '') return '0,00 €';
|
||||
const num = typeof amount === 'string' ? parseFloat(amount) : amount;
|
||||
if (isNaN(num)) return '0,00 €';
|
||||
return new Intl.NumberFormat('fr-FR', { style: 'currency', currency: 'EUR' }).format(num);
|
||||
}
|
||||
|
||||
export function formatDate(date: string | undefined | null): string {
|
||||
if (!date) return '-';
|
||||
try {
|
||||
return new Intl.DateTimeFormat('fr-FR', { day: '2-digit', month: '2-digit', year: 'numeric' }).format(new Date(date));
|
||||
} catch {
|
||||
return '-';
|
||||
}
|
||||
}
|
||||
|
||||
export function formatDateTime(date: string | undefined | null): string {
|
||||
if (!date) return '-';
|
||||
try {
|
||||
return new Intl.DateTimeFormat('fr-FR', {
|
||||
day: '2-digit', month: '2-digit', year: 'numeric',
|
||||
hour: '2-digit', minute: '2-digit',
|
||||
}).format(new Date(date));
|
||||
} catch {
|
||||
return '-';
|
||||
}
|
||||
}
|
||||
|
||||
export const statusLabels: Record<string, string> = {
|
||||
recue: 'Reçue',
|
||||
en_verification: 'En vérification',
|
||||
validee: 'Validée',
|
||||
approuvee: 'Approuvée',
|
||||
payee: 'Payée',
|
||||
rejetee: 'Rejetée',
|
||||
archivee: 'Archivée',
|
||||
};
|
||||
|
||||
export const statusColors: Record<string, string> = {
|
||||
recue: 'bg-blue-100 text-blue-800',
|
||||
en_verification: 'bg-yellow-100 text-yellow-800',
|
||||
validee: 'bg-indigo-100 text-indigo-800',
|
||||
approuvee: 'bg-green-100 text-green-800',
|
||||
payee: 'bg-emerald-100 text-emerald-800',
|
||||
rejetee: 'bg-red-100 text-red-800',
|
||||
archivee: 'bg-gray-100 text-gray-800',
|
||||
};
|
||||
|
||||
export const sourceLabels: Record<string, string> = {
|
||||
upload: 'Upload',
|
||||
email: 'Email',
|
||||
portail: 'Portail',
|
||||
scan: 'Scan',
|
||||
};
|
||||
|
||||
export const matchingLabels: Record<string, string> = {
|
||||
non_rapproche: 'Non rapproché',
|
||||
rapproche: 'Rapproché',
|
||||
ecart_detecte: 'Écart détecté',
|
||||
};
|
||||
|
||||
export const matchingColors: Record<string, string> = {
|
||||
non_rapproche: 'bg-gray-100 text-gray-800',
|
||||
rapproche: 'bg-green-100 text-green-800',
|
||||
ecart_detecte: 'bg-orange-100 text-orange-800',
|
||||
};
|
||||
|
||||
export const poStatusLabels: Record<string, string> = {
|
||||
brouillon: 'Brouillon',
|
||||
envoyee: 'Envoyée',
|
||||
recue: 'Reçue',
|
||||
facturee: 'Facturée',
|
||||
annulee: 'Annulée',
|
||||
};
|
||||
|
||||
export const poStatusColors: Record<string, string> = {
|
||||
brouillon: 'bg-gray-100 text-gray-800',
|
||||
envoyee: 'bg-blue-100 text-blue-800',
|
||||
recue: 'bg-green-100 text-green-800',
|
||||
facturee: 'bg-purple-100 text-purple-800',
|
||||
annulee: 'bg-red-100 text-red-800',
|
||||
};
|
||||
|
||||
export const roleLabels: Record<string, string> = {
|
||||
admin: 'Administrateur',
|
||||
approbateur: 'Approbateur',
|
||||
validateur: 'Validateur',
|
||||
operateur: 'Opérateur',
|
||||
};
|
||||
|
||||
export function isOverdue(dueDate: string | undefined | null, status: string): boolean {
|
||||
if (!dueDate || ['payee', 'archivee', 'rejetee'].includes(status)) return false;
|
||||
return new Date(dueDate) < new Date();
|
||||
}
|
||||
|
||||
export function isDueSoon(dueDate: string | undefined | null, status: string, days: number = 7): boolean {
|
||||
if (!dueDate || ['payee', 'archivee', 'rejetee'].includes(status)) return false;
|
||||
const due = new Date(dueDate);
|
||||
const now = new Date();
|
||||
const future = new Date(now.getTime() + days * 24 * 60 * 60 * 1000);
|
||||
return due >= now && due <= future;
|
||||
}
|
||||
Reference in New Issue
Block a user