- 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
td(class="sectionContent", valign="top")
p Gas Ordine: #{gasordine}
p  
tr
td(class="sectionContentTitle boldhigh", valign="top")
p #{descr}

View File

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

View File

@@ -122,7 +122,10 @@ const orderSchema = new Schema({
},
notes: {
type: String
}
},
modify_at: {
type: Date
},
});
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) {
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) {
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;
order.TotalPriceProduct = 0;
order.modify_at = new Date();
// Calcolo Sconto
let sconti_da_applicare = [];
@@ -461,10 +465,25 @@ module.exports.getTotalOrderById = async function (id) {
$expr: {
$and: [
{ $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: {
@@ -486,7 +505,22 @@ module.exports.getTotalOrderById = async function (id) {
$expr: {
$and: [
{ $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',
populate: {
path: 'idProduct',
model: 'Product'
},
})
.populate({
path: 'items.order',
populate: {
path: 'idProduct',
model: 'Product',
populate: {
path: 'idProductInfo',
model: 'ProductInfo'
},
},
}
}
})
.populate({
path: 'items.order',
populate: {
path: 'idProducer',
model: 'Producer'
},
}
})
.populate({
path: 'items.order',
populate: {
path: 'idProvider',
model: 'Provider'
},
}
})
.populate({
path: 'items.order',
populate: {
path: 'idGasordine',
model: 'Gasordine'
},
}
})
.populate({
path: 'items.order',
populate: {
path: 'idStorehouse',
model: 'Storehouse'
},
}
})
.populate({
path: 'items.order',
populate: {
path: 'idScontisticas',
model: 'Scontistica'
},
}
})
.populate({
path: 'userId',
model: 'User',
select: '_id name surname username profile', // Specify the fields you want to retrieve
select: '_id name surname username profile'
})
.lean();
myorderscart = myorderscart.map(order => {
order.user = order.userId
order.userId = order.user._id
order.user = order.userId;
order.userId = order.user._id;
order.items = order.items.map(item => {
if (item.order) {
try {
item.order.product = item.order.idProduct;
item.order.idProduct = item.order.product ? item.order.product._id : '';
if (item.order.product.idProductInfo) {
item.order.product.productInfo = item.order.product.idProductInfo;
item.order.product.idProductInfo = item.order.product ? item.order.product.productInfo._id : '';
if (item.order.idProduct) {
item.order.idProduct.productInfo = item.order.idProduct.productInfo ? item.order.idProduct.productInfo : {...item.order.idProduct.idProductInfo};
item.order.idProduct.idProductInfo = item.order.idProduct.productInfo ? item.order.idProduct.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.idProducer = item.order.producer ? item.order.producer._id : '';
item.order.storehouse = item.order.idStorehouse;
@@ -274,6 +268,7 @@ module.exports.getOrdersCartByQuery = async function (query) {
return order;
});
return myorderscart;
}

View File

@@ -295,7 +295,22 @@ module.exports.findAllIdApp = async function (idapp, code, id) {
$expr: {
$and: [
{ $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: {
$and: [
{ $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.modify_at = new Date();
this.updatetotals();
await Order.findOneAndUpdate({ _id: myitem.order._id }, { $set: myitem.order }, { new: false });
return myitem.order;

View File

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