chore : modification de la fonction pour pouvoir parse les facture metro #5
This commit is contained in:
@@ -59,7 +59,7 @@ async function pdf_parse(travel: string) {
|
|||||||
date = "non trouvé"
|
date = "non trouvé"
|
||||||
}
|
}
|
||||||
|
|
||||||
// Découpage en lines pour l'analyse
|
// Découpage en lignes pour l'analyse et cration d'un tableau de toutes les lignes
|
||||||
const lines = text.split('\n').map(l => l.trim()).filter(l => l.length > 0);
|
const lines = text.split('\n').map(l => l.trim()).filter(l => l.length > 0);
|
||||||
|
|
||||||
// Algorithme de recherche verticale pour Auchan
|
// Algorithme de recherche verticale pour Auchan
|
||||||
@@ -80,16 +80,47 @@ async function pdf_parse(travel: string) {
|
|||||||
}
|
}
|
||||||
|
|
||||||
} else {
|
} else {
|
||||||
supplier = "Metro";
|
supplier = "METRO";
|
||||||
|
|
||||||
// on regarde la date d'achat avec une expression reguliere pour metro
|
// on regarde la date d'achat avec une expression reguliere pour metro
|
||||||
const regex_date = /(\d{2})-(\d{2})-(\d{4})/;
|
const regex_date = /(\d{2})-(\d{2})-(\d{4})/;
|
||||||
const corres = text.match(regex_date);
|
const corres = text.match(regex_date);
|
||||||
if (corres) {
|
if (corres) {
|
||||||
date = corres[0]
|
date = corres[0];
|
||||||
} else {
|
} else {
|
||||||
date = "non trouvé"
|
date = "non trouvé";
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// Découpage en lignes pour l'analyse et cration d'un tableau de toutes les lignes
|
||||||
|
const lines = text.split('\n').map(l => l.trim()).filter(l => l.length > 0);
|
||||||
|
|
||||||
|
// Algorithme de recherche verticale pour metro
|
||||||
|
for (let i = 0; i < lines.length; i++) {
|
||||||
|
// Si la ligne correspond exactement à un code-barres à 13 chiffres
|
||||||
|
if (/^\d{13}$/.test(lines[i])) {
|
||||||
|
const product_name = lines[i + 1];
|
||||||
|
const qte = lines[i + 4];
|
||||||
|
const price = lines[i + 5];
|
||||||
|
const tva = lines[i + 6];
|
||||||
|
|
||||||
|
let tva_final = "";
|
||||||
|
|
||||||
|
if (tva == "B"){
|
||||||
|
tva_final = "5.5%";
|
||||||
|
}
|
||||||
|
|
||||||
|
else {
|
||||||
|
tva_final = "20%";
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
product_list[product_name] = {
|
||||||
|
quantity: parseInt(qte, 10),
|
||||||
|
price_ht: parseFloat(price.replace(',', '.')),
|
||||||
|
tva: tva_final
|
||||||
|
};
|
||||||
|
}
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
// Construction de l'objet final
|
// Construction de l'objet final
|
||||||
|
|||||||
Reference in New Issue
Block a user