Poter inserire un Ordine anche per un altra persona... (Modalità Cassa)

This commit is contained in:
Surya Paolo
2024-01-16 23:00:10 +01:00
parent a2c9dcb38c
commit 3d1a330fa2
3 changed files with 13 additions and 4 deletions

View File

@@ -17,6 +17,7 @@ const CartSchema = new Schema({
userId: { type: Schema.Types.ObjectId, ref: 'User' }, userId: { type: Schema.Types.ObjectId, ref: 'User' },
totalQty: { type: Number, default: 0 }, totalQty: { type: Number, default: 0 },
totalPrice: { type: Number, default: 0 }, totalPrice: { type: Number, default: 0 },
totalPriceCalc: { type: Number, default: 0 },
department: { department: {
type: String, ref: 'Department', type: String, ref: 'Department',
}, },
@@ -88,6 +89,7 @@ module.exports.updateCartByUserId = function (userId, newCart, callback) {
items: newCart.items, items: newCart.items,
totalQty: newCart.totalQty, totalQty: newCart.totalQty,
totalPrice: newCart.totalPrice, totalPrice: newCart.totalPrice,
totalPriceCalc: newCart.totalPriceCalc,
userId: userId, userId: userId,
}, },
}, },
@@ -106,6 +108,7 @@ module.exports.updateCartByCartId = async function (cartId, newCart) {
const items = newCart.items; const items = newCart.items;
const totalQty = newCart.totalQty; const totalQty = newCart.totalQty;
const totalPrice = newCart.totalPrice; const totalPrice = newCart.totalPrice;
const totalPriceCalc = newCart.totalPriceCalc;
const note = newCart.note; const note = newCart.note;
const modify_at = new Date(); const modify_at = new Date();
@@ -114,6 +117,7 @@ module.exports.updateCartByCartId = async function (cartId, newCart) {
$set: { $set: {
items, items,
totalPrice, totalPrice,
totalPriceCalc,
totalQty, totalQty,
note, note,
modify_at: new Date(), modify_at: new Date(),

View File

@@ -245,17 +245,20 @@ class Cart {
} else { } else {
mypricecalc = (order.price * order.quantity) + (order.price * order.quantitypreordered); mypricecalc = (order.price * order.quantity) + (order.price * order.quantitypreordered);
order.TotalPriceProductCalc += mypricecalc;
if (updatecalcprice) {
order.TotalPriceProduct += mypricecalc;
}
} }
// Aggiorna Totali
order.TotalPriceProductCalc += mypricecalc;
if (updatecalcprice) {
order.TotalPriceProduct += mypricecalc;
}
// Qui lo calcolo sempre, anche se lo cambio manualmente // Qui lo calcolo sempre, anche se lo cambio manualmente
this.totalPriceCalc += mypricecalc; this.totalPriceCalc += mypricecalc;
this.totalPrice += order.TotalPriceProduct; this.totalPrice += order.TotalPriceProduct;
} }
this.totalPrice = parseFloat(this.totalPrice.toFixed(2)) this.totalPrice = parseFloat(this.totalPrice.toFixed(2))
this.totalPriceCalc = parseFloat(this.totalPriceCalc.toFixed(2))
} catch (e) { } catch (e) {
console.error('Err: ', e); console.error('Err: ', e);

View File

@@ -201,6 +201,7 @@ router.put('/:userId', authenticate, async function (req, res, next) {
items: newCart.items, items: newCart.items,
totalQty: newCart.totalQty, totalQty: newCart.totalQty,
totalPrice: newCart.totalPrice, totalPrice: newCart.totalPrice,
totalPriceCalc: newCart.totalPriceCalc,
userId: userId userId: userId
}, },
function (err, result) { function (err, result) {
@@ -213,6 +214,7 @@ router.put('/:userId', authenticate, async function (req, res, next) {
items: newCart.items, items: newCart.items,
totalQty: newCart.totalQty, totalQty: newCart.totalQty,
totalPrice: newCart.totalPrice, totalPrice: newCart.totalPrice,
totalPriceCalc: newCart.totalPriceCalc,
userId: userId userId: userId
} }
await Cart.createCart(newCartobj, function (err, resultCart) { await Cart.createCart(newCartobj, function (err, resultCart) {