- aggiornato carrello e bottoni sul catalogo
This commit is contained in:
@@ -28,6 +28,9 @@ const MyPageSchema = new Schema({
|
|||||||
subtitle: {
|
subtitle: {
|
||||||
type: String,
|
type: String,
|
||||||
},
|
},
|
||||||
|
isTemplate: {
|
||||||
|
type: Boolean,
|
||||||
|
},
|
||||||
icon: {
|
icon: {
|
||||||
type: String,
|
type: String,
|
||||||
},
|
},
|
||||||
|
|||||||
@@ -6,6 +6,7 @@ const shared_consts = require('../tools/shared_nodejs');
|
|||||||
const { ObjectId } = require('mongodb');
|
const { ObjectId } = require('mongodb');
|
||||||
|
|
||||||
const Scontistica = require('../models/scontistica');
|
const Scontistica = require('../models/scontistica');
|
||||||
|
const OrderClass = require('../modules/OrderClass');
|
||||||
|
|
||||||
mongoose.Promise = global.Promise;
|
mongoose.Promise = global.Promise;
|
||||||
mongoose.level = 'F';
|
mongoose.level = 'F';
|
||||||
@@ -300,81 +301,13 @@ module.exports.updateOrderByParams = async function (idOrder, paramstoupdate) {
|
|||||||
return myorder;
|
return myorder;
|
||||||
};
|
};
|
||||||
|
|
||||||
function initOrderTotals(order) {
|
|
||||||
order.TotalPriceProduct = 0;
|
|
||||||
order.TotalPriceProductCalc = 0;
|
|
||||||
order.modify_at = new Date();
|
|
||||||
}
|
|
||||||
|
|
||||||
function getNonCumulativeDiscounts(discounts) {
|
|
||||||
return discounts.filter((rec) => !rec.cumulativo);
|
|
||||||
}
|
|
||||||
|
|
||||||
function applyNonCumulativeDiscounts(order, discounts) {
|
|
||||||
let qtadascontare = order.quantity + order.quantitypreordered;
|
|
||||||
let qtanonscontata = 0;
|
|
||||||
let sconti_da_applicare = [];
|
|
||||||
|
|
||||||
while (qtadascontare > 0) {
|
|
||||||
let scontoapplicato = null;
|
|
||||||
|
|
||||||
// Filtriamo gli sconti non cumulativi
|
|
||||||
for (const sconto of getNonCumulativeDiscounts(discounts)) {
|
|
||||||
if (qtadascontare >= sconto.qta) {
|
|
||||||
// Se la quantità da scontare è maggiore o uguale alla quantità dello sconto, applica lo sconto completo
|
|
||||||
scontoapplicato = { ...sconto, qtadascontare: sconto.qta };
|
|
||||||
break; // Esci dal ciclo, abbiamo trovato lo sconto applicabile
|
|
||||||
} else if (qtadascontare > 0) {
|
|
||||||
// Se la quantità da scontare è inferiore allo sconto, applica solo la quantità disponibile
|
|
||||||
scontoapplicato = { ...sconto, qtadascontare: qtadascontare };
|
|
||||||
qtadascontare = 0; // Abbiamo finito le quantità da scontare
|
|
||||||
break;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
// Se c'è uno sconto applicato, aggiungilo alla lista e riduci la quantità
|
|
||||||
if (scontoapplicato && scontoapplicato.qtadascontare > 0) {
|
|
||||||
sconti_da_applicare.push(scontoapplicato);
|
|
||||||
qtadascontare -= scontoapplicato.qtadascontare;
|
|
||||||
} else {
|
|
||||||
// Se non ci sono più sconti da applicare, la quantità rimasta è non scontata
|
|
||||||
qtanonscontata = qtadascontare;
|
|
||||||
qtadascontare = 0;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
return { sconti_da_applicare, qtanonscontata };
|
|
||||||
}
|
|
||||||
|
|
||||||
function calculateDiscountedPrice(order, sconti_da_applicare, qtanonscontata) {
|
|
||||||
let total = 0;
|
|
||||||
|
|
||||||
for (const sconto of sconti_da_applicare) {
|
|
||||||
if (sconto.perc_sconto > 0) {
|
|
||||||
total += sconto.qtadascontare * order.price * (1 - sconto.perc_sconto / 100);
|
|
||||||
} else {
|
|
||||||
total += sconto.price;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
if (qtanonscontata > 0) {
|
|
||||||
total += order.price * qtanonscontata;
|
|
||||||
}
|
|
||||||
|
|
||||||
return total;
|
|
||||||
}
|
|
||||||
|
|
||||||
function calculateFullPrice(order) {
|
|
||||||
return order.price * order.quantity + order.price * order.quantitypreordered;
|
|
||||||
}
|
|
||||||
|
|
||||||
module.exports.updateTotals = async function (order, codice_sconto) {
|
module.exports.updateTotals = async function (order, codice_sconto) {
|
||||||
try {
|
try {
|
||||||
const CartClass = require('../modules/Cart');
|
const CartClass = require('../modules/Cart');
|
||||||
|
|
||||||
if (!order) return;
|
if (!order) return;
|
||||||
|
|
||||||
initOrderTotals(order);
|
OrderClass.initOrderTotals(order);
|
||||||
|
|
||||||
let total = 0;
|
let total = 0;
|
||||||
|
|
||||||
@@ -388,13 +321,13 @@ module.exports.updateTotals = async function (order, codice_sconto) {
|
|||||||
|
|
||||||
// Se ha inserito una scontistica che esiste...
|
// Se ha inserito una scontistica che esiste...
|
||||||
if (recscontisticheTrovate && recscontisticheTrovate.length > 0) {
|
if (recscontisticheTrovate && recscontisticheTrovate.length > 0) {
|
||||||
const { sconti_da_applicare, qtanonscontata } = applyNonCumulativeDiscounts(order, recscontisticheTrovate);
|
const { sconti_da_applicare, qtanonscontata } = OrderClass.applyNonCumulativeDiscounts(order, recscontisticheTrovate);
|
||||||
total = calculateDiscountedPrice(order, sconti_da_applicare, qtanonscontata);
|
total = OrderClass.calculateDiscountedPrice(order, sconti_da_applicare, qtanonscontata);
|
||||||
} else if (order.scontisticas && order.scontisticas.length > 0) {
|
} else if (order.scontisticas && order.scontisticas.length > 0) {
|
||||||
const { sconti_da_applicare, qtanonscontata } = applyNonCumulativeDiscounts(order, order.scontisticas);
|
const { sconti_da_applicare, qtanonscontata } = OrderClass.applyNonCumulativeDiscounts(order, order.scontisticas);
|
||||||
total = calculateDiscountedPrice(order, sconti_da_applicare, qtanonscontata);
|
total = OrderClass.calculateDiscountedPrice(order, sconti_da_applicare, qtanonscontata);
|
||||||
} else {
|
} else {
|
||||||
total = calculateFullPrice(order);
|
total = OrderClass.calculateFullPrice(order);
|
||||||
}
|
}
|
||||||
|
|
||||||
order.TotalPriceProductCalc += total;
|
order.TotalPriceProductCalc += total;
|
||||||
|
|||||||
@@ -6,6 +6,7 @@ const { ObjectId } = require('mongodb');
|
|||||||
const Gasordine = require('../models/gasordine');
|
const Gasordine = require('../models/gasordine');
|
||||||
|
|
||||||
const Order = require('../models/order');
|
const Order = require('../models/order');
|
||||||
|
const OrderClass = require('../modules/orderclass');
|
||||||
|
|
||||||
const Scontistica = require('../models/scontistica');
|
const Scontistica = require('../models/scontistica');
|
||||||
|
|
||||||
@@ -264,47 +265,9 @@ class Cart {
|
|||||||
return order.price * qtyTotale;
|
return order.price * qtyTotale;
|
||||||
}
|
}
|
||||||
|
|
||||||
let scontiApplicati = [];
|
const { sconti_da_applicare, qtanonscontata } = OrderClass.applyNonCumulativeDiscounts(order, sconti);
|
||||||
let qtaRimanente = qtyTotale;
|
|
||||||
let qtaNonScontata = 0;
|
|
||||||
|
|
||||||
// Applica sconti non cumulativi
|
const prezzoTotale = OrderClass.calculateDiscountedPrice(order, sconti_da_applicare, qtanonscontata);
|
||||||
while (qtaRimanente > 0) {
|
|
||||||
let scontoScelto = null;
|
|
||||||
let scontoVantaggioso = 0;
|
|
||||||
for (const sconto of sconti.filter((s) => !s.cumulativo)) {
|
|
||||||
if (qtaRimanente >= sconto.qta) {
|
|
||||||
const scontoApplicato =
|
|
||||||
sconto.perc_sconto > 0 ? qtaRimanente * order.price * (1 - sconto.perc_sconto / 100) : sconto.price;
|
|
||||||
if (scontoApplicato > scontoVantaggioso) {
|
|
||||||
scontoVantaggioso = scontoApplicato;
|
|
||||||
scontoScelto = { ...sconto, qtadascontare: qtaRimanente };
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
if (scontoScelto) {
|
|
||||||
scontiApplicati.push(scontoScelto);
|
|
||||||
qtaRimanente -= scontoScelto.qtadascontare;
|
|
||||||
} else {
|
|
||||||
qtaNonScontata = qtaRimanente;
|
|
||||||
qtaRimanente = 0;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
let prezzoTotale = 0;
|
|
||||||
|
|
||||||
for (const sconto of scontiApplicati) {
|
|
||||||
if (sconto.perc_sconto > 0) {
|
|
||||||
prezzoTotale += sconto.qtadascontare * order.price * (1 - sconto.perc_sconto / 100);
|
|
||||||
} else if (sconto.price > 0) {
|
|
||||||
prezzoTotale += sconto.price;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
if (qtaNonScontata > 0) {
|
|
||||||
prezzoTotale += qtaNonScontata * order.price;
|
|
||||||
}
|
|
||||||
|
|
||||||
return prezzoTotale;
|
return prezzoTotale;
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -48,7 +48,7 @@ class GenPdf {
|
|||||||
}
|
}
|
||||||
|
|
||||||
async autoScroll(page) {
|
async autoScroll(page) {
|
||||||
console.log('inizia a scrollare');
|
console.log('inizia a scrollare...');
|
||||||
|
|
||||||
// Esegui lo scroll fino a quando tutta la pagina non è stata scrollata
|
// Esegui lo scroll fino a quando tutta la pagina non è stata scrollata
|
||||||
await page.evaluate(async () => {
|
await page.evaluate(async () => {
|
||||||
@@ -97,9 +97,11 @@ class GenPdf {
|
|||||||
await tools.attendiNSecondi(6);
|
await tools.attendiNSecondi(6);
|
||||||
let success = false;
|
let success = false;
|
||||||
let numTentativi1 = 0;
|
let numTentativi1 = 0;
|
||||||
|
console.log(`Cerco .pdf-section...`);
|
||||||
while (numTentativi1 < maxTentativi) {
|
while (numTentativi1 < maxTentativi) {
|
||||||
try {
|
try {
|
||||||
await page.waitForSelector('.pdf-section', { timeout: 10000 });
|
await page.waitForSelector('.pdf-section', { timeout: 10000 });
|
||||||
|
console.log(` .pdf-section trovato !...`);
|
||||||
success = true;
|
success = true;
|
||||||
break;
|
break;
|
||||||
} catch (e) {
|
} catch (e) {
|
||||||
|
|||||||
84
src/server/modules/OrderClass.js
Executable file
84
src/server/modules/OrderClass.js
Executable file
@@ -0,0 +1,84 @@
|
|||||||
|
const shared_consts = require('../tools/shared_nodejs');
|
||||||
|
const cartModel = require('../models/cart');
|
||||||
|
|
||||||
|
const { ObjectId } = require('mongodb');
|
||||||
|
|
||||||
|
const Gasordine = require('../models/gasordine');
|
||||||
|
|
||||||
|
const Order = require('../models/order');
|
||||||
|
|
||||||
|
const Scontistica = require('../models/scontistica');
|
||||||
|
|
||||||
|
class OrderClass {
|
||||||
|
constructor() {}
|
||||||
|
|
||||||
|
static initOrderTotals(order) {
|
||||||
|
order.TotalPriceProduct = 0;
|
||||||
|
order.TotalPriceProductCalc = 0;
|
||||||
|
order.modify_at = new Date();
|
||||||
|
}
|
||||||
|
|
||||||
|
static getNonCumulativeDiscounts(discounts) {
|
||||||
|
return discounts.filter((rec) => !rec.cumulativo);
|
||||||
|
}
|
||||||
|
|
||||||
|
static applyNonCumulativeDiscounts(order, discounts) {
|
||||||
|
let qtadascontare = order.quantity + order.quantitypreordered;
|
||||||
|
let qtanonscontata = 0;
|
||||||
|
let sconti_da_applicare = [];
|
||||||
|
|
||||||
|
while (qtadascontare > 0) {
|
||||||
|
let scontoapplicato = null;
|
||||||
|
|
||||||
|
// Filtriamo gli sconti non cumulativi
|
||||||
|
for (const sconto of OrderClass.getNonCumulativeDiscounts(discounts)) {
|
||||||
|
if (qtadascontare >= sconto.qta && sconto.qta > 0) {
|
||||||
|
// Se la quantità da scontare è maggiore o uguale alla quantità dello sconto, applica lo sconto completo
|
||||||
|
scontoapplicato = { ...sconto, qtadascontare: sconto.qta };
|
||||||
|
break; // Esci dal ciclo, abbiamo trovato lo sconto applicabile
|
||||||
|
} else if (qtadascontare > 0) {
|
||||||
|
// Se la quantità da scontare è inferiore allo sconto, applica solo la quantità disponibile
|
||||||
|
scontoapplicato = { ...sconto, qtadascontare: qtadascontare };
|
||||||
|
qtadascontare = 0; // Abbiamo finito le quantità da scontare
|
||||||
|
break;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
// Se c'è uno sconto applicato, aggiungilo alla lista e riduci la quantità
|
||||||
|
if (scontoapplicato && scontoapplicato.qtadascontare > 0) {
|
||||||
|
sconti_da_applicare.push(scontoapplicato);
|
||||||
|
qtadascontare -= scontoapplicato.qtadascontare;
|
||||||
|
} else {
|
||||||
|
// Se non ci sono più sconti da applicare, la quantità rimasta è non scontata
|
||||||
|
qtanonscontata = qtadascontare;
|
||||||
|
qtadascontare = 0;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
return { sconti_da_applicare, qtanonscontata };
|
||||||
|
}
|
||||||
|
|
||||||
|
static calculateDiscountedPrice(order, sconti_da_applicare, qtanonscontata) {
|
||||||
|
let total = 0;
|
||||||
|
|
||||||
|
for (const sconto of sconti_da_applicare) {
|
||||||
|
if (sconto.perc_sconto > 0) {
|
||||||
|
total += sconto.qtadascontare * order.price * (1 - sconto.perc_sconto / 100);
|
||||||
|
} else {
|
||||||
|
total += sconto.price;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
if (qtanonscontata > 0) {
|
||||||
|
total += order.price * qtanonscontata;
|
||||||
|
}
|
||||||
|
|
||||||
|
return total;
|
||||||
|
}
|
||||||
|
|
||||||
|
static calculateFullPrice(order) {
|
||||||
|
return order.price * order.quantity + order.price * order.quantitypreordered;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
module.exports = OrderClass;
|
||||||
@@ -430,7 +430,7 @@ router.post('/settable', authenticate, async (req, res) => {
|
|||||||
} else {
|
} else {
|
||||||
if (
|
if (
|
||||||
(mydata['_id'] === undefined || mydata['_id'] === '' || (mytablerec.isNew && mydata['_id'] === 0)) &&
|
(mydata['_id'] === undefined || mydata['_id'] === '' || (mytablerec.isNew && mydata['_id'] === 0)) &&
|
||||||
(mytablerec._id === undefined || mytablerec._id === '0')
|
(mytablerec._id === undefined || mytablerec._id === '0'|| mytablerec._id === 0)
|
||||||
) {
|
) {
|
||||||
mytablerec._id = new ObjectId();
|
mytablerec._id = new ObjectId();
|
||||||
mydata._id = new ObjectId();
|
mydata._id = new ObjectId();
|
||||||
|
|||||||
@@ -1 +1 @@
|
|||||||
1.2.53
|
1.2.54
|
||||||
Reference in New Issue
Block a user