Skip to content

Commit 0f7f8f7

Browse files
authored
Merge pull request #188 from Discobluff/fix/invoice-parser
Fix/invoice parser
2 parents 3ef9c18 + f4e29ba commit 0f7f8f7

1 file changed

Lines changed: 18 additions & 16 deletions

File tree

frontend/src/lib/components/random/invoiceParser.svelte

Lines changed: 18 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -9,7 +9,7 @@
99
}
1010
1111
export function restockAuchanDrive(input: string): Array<{ reference: number; name: string; quantity: number; unitPriceHT: number; tvaRate: number }> {
12-
const splitPage = "Référence Caractéristiques produit Prix U. (HT) € Remises U. (HT) € Qte. Prix total (HT) € Taux TVA % Cagnotte WAAOH! Prix total (TTC) € "
12+
const splitPage = "Référence Caractéristiques produit Prix U. (HT) € Remises U. (HT) € Qte. Prix total Net (HT) € Taux TVA % Cagnotte WAAOH! Prix total Net (TTC) € "
1313
const splitLine = " ";
1414
const endPage1 = "Votre commande :";
1515
const endPage2 = "Taux TVA";
@@ -62,9 +62,9 @@
6262
}
6363
6464
export function restockAuchan(input: string): Array<{ reference: number; name: string; quantity: number; unitPriceHT: number; tvaRate: number }> {
65-
const splitPage = "Référence Caractéristiques produit Prix U. (HT) € Remises U. (HT) € Qte. Prix total (HT) € Taux TVA % Prix total (TTC) € ";
65+
const splitPage = "Référence Caractéristiques produit Prix U. (HT) € Remises U. (HT) € Qte. Prix total Net (HT) € Taux TVA % Prix total Net (TTC) € ";
6666
const splitLine = " ";
67-
const splitNameQuantity = " Dont éco-participation : ";
67+
const ecoPart = "Eco-participation :";
6868
const endPage1 = "Votre commande :";
6969
const endPage2 = "TVA déjà collectée Mode de paiement";
7070
const endPage3 = "Taux TVA (%)";
@@ -76,6 +76,10 @@
7676
if (pageSplit[j].includes(endPage1) || pageSplit[j].includes(endPage2) || pageSplit[j].includes(endPage3)) {
7777
break;
7878
}
79+
if (pageSplit[j].includes(ecoPart)){
80+
j+= 3;
81+
continue;
82+
}
7983
let reference;
8084
if (pageSplit[j].includes(" ")){
8185
reference = parseInt(pageSplit[j].split(" ").slice(-1)[0]);
@@ -84,25 +88,23 @@
8488
reference = parseInt(pageSplit[j].split(" ").slice(-1)[0]);
8589
}
8690
j++;
87-
const splitEcoPart = pageSplit[j].split(splitNameQuantity);
88-
const name = splitEcoPart[0];
89-
let unitPriceHT;
90-
if (splitEcoPart.length > 1){
91-
unitPriceHT = parseFloat(splitEcoPart[1].replace(",","."));
92-
}
93-
else{
94-
j++;
95-
unitPriceHT = parseFloat(pageSplit[j].replace(",","."));
96-
}
91+
const name = pageSplit[j];
9792
j++;
98-
if (isPrice(pageSplit[j])){ // Check if there is a discount
99-
unitPriceHT -= parseFloat(pageSplit[j].replace(",","."));
93+
let unitPriceHT = parseFloat(pageSplit[j].replace(',','.'));
94+
j++;
95+
//Check for discount
96+
if (pageSplit[j].includes(',')){
97+
unitPriceHT -= parseFloat(pageSplit[j].replace(',','.'));
10098
j++;
10199
}
102100
const quantity = parseInt(pageSplit[j]);
103-
j += 2;
101+
j += 2 ;
104102
const tvaRate = parseFloat(pageSplit[j].replace(',','.'));
105103
j++;
104+
105+
if (pageSplit[j].includes(ecoPart)){
106+
j += 3;
107+
}
106108
itemsList.push({
107109
reference,
108110
name,

0 commit comments

Comments
 (0)