Checkpoint: Automatismes séparé en onglets Import et Export. Les règles d’export ciblent un destinataire ou une ventilation, avec destination locale, Teams ou SharePoint et ouverture navigateur optionnelle. La validation BAP unique ou en masse applique la première règle active par priorité puis conserve le paramétrage historique comme repli. Paramètres d’export déplacés vers Automatismes et page renommée Paramètres. Migration additive, tests, TypeScript, build et contrôles visuels validés.
This commit is contained in:
32
shared/exportAutomation.ts
Normal file
32
shared/exportAutomation.ts
Normal file
@@ -0,0 +1,32 @@
|
||||
/** Valeurs nécessaires pour déterminer une destination d’export. */
|
||||
export type ExportableInvoice = {
|
||||
recipientName?: string | null;
|
||||
ventilationComptable?: string | null;
|
||||
};
|
||||
|
||||
export type ExportRuleCandidate = {
|
||||
isActive: number;
|
||||
priority: number;
|
||||
conditionField: "recipientName" | "ventilationComptable";
|
||||
conditionValue: string;
|
||||
};
|
||||
|
||||
/**
|
||||
* Sélectionne la première règle active par priorité. Les comparaisons sont
|
||||
* volontairement insensibles à la casse et aux espaces superflus.
|
||||
*/
|
||||
export function findMatchingExportRule<T extends ExportRuleCandidate>(
|
||||
rules: T[],
|
||||
invoice: ExportableInvoice,
|
||||
): T | undefined {
|
||||
const normalized = (value: string | null | undefined) => value?.trim().toLocaleLowerCase("fr-FR") || "";
|
||||
const ordered = [...rules].sort((a, b) => a.priority - b.priority || a.conditionValue.localeCompare(b.conditionValue, "fr-FR"));
|
||||
|
||||
return ordered.find((rule) => {
|
||||
if (rule.isActive !== 1) return false;
|
||||
const invoiceValue = rule.conditionField === "recipientName"
|
||||
? invoice.recipientName
|
||||
: invoice.ventilationComptable;
|
||||
return normalized(invoiceValue) === normalized(rule.conditionValue);
|
||||
});
|
||||
}
|
||||
Reference in New Issue
Block a user