- filtro se GAS o Prodotti

This commit is contained in:
Surya Paolo
2023-12-28 21:00:02 +01:00
parent ca6d29414a
commit c001587702
7 changed files with 95 additions and 32 deletions

View File

@@ -79,6 +79,7 @@ html
tr tr
td(class="sectionContent", valign="top") td(class="sectionContent", valign="top")
p Gas Ordine: #{gasordine} p Gas Ordine: #{gasordine}
p  
tr tr
td(class="sectionContentTitle boldhigh", valign="top") td(class="sectionContentTitle boldhigh", valign="top")
p #{descr} p #{descr}

View File

@@ -80,6 +80,7 @@ html
tr tr
td(class="sectionContent", valign="top") td(class="sectionContent", valign="top")
p Gas Ordine: #{gasordine} p Gas Ordine: #{gasordine}
p  
tr tr
td(class="sectionContentTitle boldhigh", valign="top") td(class="sectionContentTitle boldhigh", valign="top")
p #{descr} p #{descr}

View File

@@ -122,7 +122,10 @@ const orderSchema = new Schema({
}, },
notes: { notes: {
type: String type: String
} },
modify_at: {
type: Date
},
}); });
var Order = module.exports = mongoose.model('Order', orderSchema); var Order = module.exports = mongoose.model('Order', orderSchema);
@@ -270,7 +273,7 @@ module.exports.createOrder = async function (order) {
module.exports.updateStatusOrders = async function (arrOrders, status) { module.exports.updateStatusOrders = async function (arrOrders, status) {
for (const order of arrOrders) { for (const order of arrOrders) {
const ret = await this.findOneAndUpdate({ _id: order._id }, { $set: status }); let ret = await Order.updateOne({ _id: order.order._id }, { $set: { status } });
} }
} }
@@ -278,7 +281,7 @@ module.exports.updateStatusOrders = async function (arrOrders, status) {
module.exports.updateStatusOrdersElements = async function (arrOrders, myelements) { module.exports.updateStatusOrdersElements = async function (arrOrders, myelements) {
for (const order of arrOrders) { for (const order of arrOrders) {
const ret = await this.findOneAndUpdate({ _id: order._id }, { $set: myelements }); const ret = await Order.findOneAndUpdate({ _id: order.order._id }, { $set: myelements });
} }
} }
@@ -292,6 +295,7 @@ module.exports.updateTotals = function (order) {
let mypricecalc = 0; let mypricecalc = 0;
order.TotalPriceProduct = 0; order.TotalPriceProduct = 0;
order.modify_at = new Date();
// Calcolo Sconto // Calcolo Sconto
let sconti_da_applicare = []; let sconti_da_applicare = [];
@@ -461,10 +465,25 @@ module.exports.getTotalOrderById = async function (id) {
$expr: { $expr: {
$and: [ $and: [
{ $eq: ['$idProduct', '$$productId'] }, { $eq: ['$idProduct', '$$productId'] },
{ $lt: ['$status', shared_consts.OrderStatus.ORDER_CONFIRMED] } {
$or: [
{
$eq: ['$status', shared_consts.OrderStatus.CHECKOUT_SENT]
},
{
$and: [{ $lt: ['$status', shared_consts.OrderStatus.CHECKOUT_SENT] },
{
$gt: [
'$modify_at',
{ $subtract: [new Date(), 60 * 60 * 1000] } // 1 hour in milliseconds 60 * 60
]
}]
}
]
}
] ]
} }
} },
}, },
{ {
$group: { $group: {
@@ -486,7 +505,22 @@ module.exports.getTotalOrderById = async function (id) {
$expr: { $expr: {
$and: [ $and: [
{ $eq: ['$idProduct', '$$productId'] }, { $eq: ['$idProduct', '$$productId'] },
{ $lt: ['$status', shared_consts.OrderStatus.ORDER_CONFIRMED] } {
$or: [
{
$eq: ['$status', shared_consts.OrderStatus.CHECKOUT_SENT]
},
{
$and: [{ $lt: ['$status', shared_consts.OrderStatus.CHECKOUT_SENT] },
{
$gt: [
'$modify_at',
{ $subtract: [new Date(), 60 * 60 * 1000] } // 1 hour in milliseconds 60 * 60
]
}]
}
]
}
] ]
} }
} }

View File

@@ -188,73 +188,67 @@ module.exports.getOrdersCartByQuery = async function (query) {
path: 'items.order', path: 'items.order',
populate: { populate: {
path: 'idProduct', path: 'idProduct',
model: 'Product' model: 'Product',
},
})
.populate({
path: 'items.order',
populate: {
path: 'idProduct',
populate: { populate: {
path: 'idProductInfo', path: 'idProductInfo',
model: 'ProductInfo' model: 'ProductInfo'
}, }
}, }
}) })
.populate({ .populate({
path: 'items.order', path: 'items.order',
populate: { populate: {
path: 'idProducer', path: 'idProducer',
model: 'Producer' model: 'Producer'
}, }
}) })
.populate({ .populate({
path: 'items.order', path: 'items.order',
populate: { populate: {
path: 'idProvider', path: 'idProvider',
model: 'Provider' model: 'Provider'
}, }
}) })
.populate({ .populate({
path: 'items.order', path: 'items.order',
populate: { populate: {
path: 'idGasordine', path: 'idGasordine',
model: 'Gasordine' model: 'Gasordine'
}, }
}) })
.populate({ .populate({
path: 'items.order', path: 'items.order',
populate: { populate: {
path: 'idStorehouse', path: 'idStorehouse',
model: 'Storehouse' model: 'Storehouse'
}, }
}) })
.populate({ .populate({
path: 'items.order', path: 'items.order',
populate: { populate: {
path: 'idScontisticas', path: 'idScontisticas',
model: 'Scontistica' model: 'Scontistica'
}, }
}) })
.populate({ .populate({
path: 'userId', path: 'userId',
model: 'User', model: 'User',
select: '_id name surname username profile', // Specify the fields you want to retrieve select: '_id name surname username profile'
}) })
.lean(); .lean();
myorderscart = myorderscart.map(order => { myorderscart = myorderscart.map(order => {
order.user = order.userId order.user = order.userId;
order.userId = order.user._id order.userId = order.user._id;
order.items = order.items.map(item => { order.items = order.items.map(item => {
if (item.order) { if (item.order) {
try { try {
item.order.product = item.order.idProduct; if (item.order.idProduct) {
item.order.idProduct = item.order.product ? item.order.product._id : ''; item.order.idProduct.productInfo = item.order.idProduct.productInfo ? item.order.idProduct.productInfo : {...item.order.idProduct.idProductInfo};
if (item.order.product.idProductInfo) { item.order.idProduct.idProductInfo = item.order.idProduct.productInfo ? item.order.idProduct.productInfo._id : '';
item.order.product.productInfo = item.order.product.idProductInfo;
item.order.product.idProductInfo = item.order.product ? item.order.product.productInfo._id : '';
} }
item.order.product = {...item.order.idProduct};
item.order.idProduct = item.order.product ? item.order.product._id : '';
item.order.producer = item.order.idProducer; item.order.producer = item.order.idProducer;
item.order.idProducer = item.order.producer ? item.order.producer._id : ''; item.order.idProducer = item.order.producer ? item.order.producer._id : '';
item.order.storehouse = item.order.idStorehouse; item.order.storehouse = item.order.idStorehouse;
@@ -274,6 +268,7 @@ module.exports.getOrdersCartByQuery = async function (query) {
return order; return order;
}); });
return myorderscart; return myorderscart;
} }

View File

@@ -295,7 +295,22 @@ module.exports.findAllIdApp = async function (idapp, code, id) {
$expr: { $expr: {
$and: [ $and: [
{ $eq: ['$idProduct', '$$productId'] }, { $eq: ['$idProduct', '$$productId'] },
{ $lt: ['$status', shared_consts.OrderStatus.ORDER_CONFIRMED] } {
$or: [
{
$eq: ['$status', shared_consts.OrderStatus.CHECKOUT_SENT]
},
{
$and: [{ $lt: ['$status', shared_consts.OrderStatus.CHECKOUT_SENT] },
{
$gt: [
'$modify_at',
{ $subtract: [new Date(), 60 * 60 * 1000] } // 1 hour in milliseconds 60 * 60
]
}]
}
]
}
] ]
} }
} }
@@ -320,7 +335,22 @@ module.exports.findAllIdApp = async function (idapp, code, id) {
$expr: { $expr: {
$and: [ $and: [
{ $eq: ['$idProduct', '$$productId'] }, { $eq: ['$idProduct', '$$productId'] },
{ $lt: ['$status', shared_consts.OrderStatus.ORDER_CONFIRMED] } {
$or: [
{
$eq: ['$status', shared_consts.OrderStatus.CHECKOUT_SENT]
},
{
$and: [{ $lt: ['$status', shared_consts.OrderStatus.CHECKOUT_SENT] },
{
$gt: [
'$modify_at',
{ $subtract: [new Date(), 60 * 60 * 1000] } // 1 hour in milliseconds 60 * 60
]
}]
}
]
}
] ]
} }
} }

View File

@@ -90,6 +90,8 @@ class Cart {
myitem.order.quantitypreordered += step; myitem.order.quantitypreordered += step;
} }
myitem.order.modify_at = new Date();
this.updatetotals(); this.updatetotals();
await Order.findOneAndUpdate({ _id: myitem.order._id }, { $set: myitem.order }, { new: false }); await Order.findOneAndUpdate({ _id: myitem.order._id }, { $set: myitem.order }, { new: false });
return myitem.order; return myitem.order;

View File

@@ -362,8 +362,8 @@ module.exports = {
value: 2, value: 2,
}, },
{ {
label: 'Litri (L)', label: 'Litri (Lt)',
short: 'L', short: 'Lt',
value: 3, value: 3,
}, },
{ {