aggiornamento scontistica, corretto errori
This commit is contained in:
@@ -99,9 +99,59 @@ class Cart {
|
||||
order = this.items[rec];
|
||||
}
|
||||
this.totalQty += order.quantity;
|
||||
this.totalPrice += order.price * order.quantity;
|
||||
}
|
||||
|
||||
// Calcolo Sconto
|
||||
let sconti_da_applicare = [];
|
||||
let mypricecalc = 0;
|
||||
if (order.scontisticas) {
|
||||
|
||||
let qtadascontare = order.quantity
|
||||
let qtanonscontata = 0
|
||||
|
||||
while (qtadascontare > 0) {
|
||||
let scontoapplicato = null
|
||||
for (const sconto of order.scontisticas.filter((rec) => !rec.cumulativo)) {
|
||||
if (qtadascontare >= sconto.qta) {
|
||||
scontoapplicato = sconto
|
||||
scontoapplicato.qtadascontare = sconto.qta
|
||||
}
|
||||
}
|
||||
if (scontoapplicato && scontoapplicato.qtadascontare > 0) {
|
||||
sconti_da_applicare.push(scontoapplicato)
|
||||
qtadascontare -= scontoapplicato.qtadascontare
|
||||
} else {
|
||||
qtanonscontata = qtadascontare
|
||||
qtadascontare = 0
|
||||
}
|
||||
}
|
||||
|
||||
/*for (const sconto of order.scontisticas.filter((rec) => rec.cumulativo)) {
|
||||
if ((sconto.qta % order.quantity) === 0) {
|
||||
sconti_da_applicare.push(sconto)
|
||||
}
|
||||
}*/
|
||||
|
||||
mypricecalc = order.price * order.quantity;
|
||||
|
||||
if (sconti_da_applicare.length > 0) {
|
||||
mypricecalc = 0
|
||||
for (const sconto of sconti_da_applicare) {
|
||||
if (sconto.perc_sconto > 0) {
|
||||
mypricecalc += (sconto.qtadascontare * order.price) * (1 - (sconto.perc_sconto / 100))
|
||||
} else {
|
||||
mypricecalc += sconto.price
|
||||
}
|
||||
}
|
||||
}
|
||||
if (qtanonscontata > 0) {
|
||||
mypricecalc += order.price * qtanonscontata;
|
||||
}
|
||||
|
||||
} else {
|
||||
mypricecalc = order.price * order.quantity;
|
||||
}
|
||||
this.totalPrice += mypricecalc;
|
||||
}
|
||||
this.totalPrice = parseFloat(this.totalPrice.toFixed(2))
|
||||
} catch (e) {
|
||||
console.error('Err: ', e);
|
||||
|
||||
Reference in New Issue
Block a user