Gestione Ordini: evaso...
This commit is contained in:
@@ -31,6 +31,41 @@ const OrdersCartSchema = new Schema({
|
||||
type: Number,
|
||||
Default: 0,
|
||||
},
|
||||
evaso: { // e quindi è stato tolto dal magazzino (aggiornando il campo StockQty)
|
||||
type: Boolean,
|
||||
default: false,
|
||||
},
|
||||
date_evaso: {
|
||||
type: Date
|
||||
},
|
||||
pagato: {
|
||||
type: Boolean,
|
||||
default: false,
|
||||
},
|
||||
date_pagato: {
|
||||
type: Date
|
||||
},
|
||||
spedito: {
|
||||
type: Boolean,
|
||||
default: false,
|
||||
},
|
||||
date_spedito: {
|
||||
type: Date
|
||||
},
|
||||
completed: {
|
||||
type: Boolean,
|
||||
default: false,
|
||||
},
|
||||
date_completed: {
|
||||
type: Date
|
||||
},
|
||||
consegnato: {
|
||||
type: Boolean,
|
||||
default: false,
|
||||
},
|
||||
date_consegnato: {
|
||||
type: Date
|
||||
},
|
||||
note: {
|
||||
type: String
|
||||
},
|
||||
@@ -67,20 +102,15 @@ module.exports.getFieldsForSearch = function () {
|
||||
};
|
||||
|
||||
|
||||
module.exports.getNewNumOrder = async function (uid, idapp) {
|
||||
module.exports.getLastNumOrder = async function (uid, idapp) {
|
||||
let query = { userId: uid, idapp, deleted: false }
|
||||
let numorder = 1;
|
||||
let numorderrec = await OrdersCart.find(query).sort({ numorder: -1 }).limit(1);
|
||||
if (numorderrec.length <= 0)
|
||||
numorder = 1;
|
||||
else
|
||||
|
||||
if (numorderrec && numorderrec.length > 0)
|
||||
numorder = numorderrec[0].numorder;
|
||||
|
||||
if (numorder) {
|
||||
numorder++
|
||||
} else {
|
||||
numorder = 1;
|
||||
}
|
||||
else
|
||||
numorder = 0;
|
||||
|
||||
return numorder;
|
||||
|
||||
@@ -100,6 +130,25 @@ module.exports.getStatusCartByUserId = async function (uid, idapp, numorder) {
|
||||
else
|
||||
return shared_consts.OrderStatus.NONE
|
||||
|
||||
}
|
||||
|
||||
module.exports.getRecCartByUserId = async function (uid, idapp, numorder) {
|
||||
let query = { userId: uid, idapp, status: { $gte: shared_consts.OrderStatus.CHECKOUT_SENT } }
|
||||
let myorderscart = null;
|
||||
if (numorder > 0) {
|
||||
query = { userId: uid, idapp, numorder, status: { $gte: shared_consts.OrderStatus.CHECKOUT_SENT } }
|
||||
}
|
||||
|
||||
myorderscart = await OrdersCart.findOne(query).lean();
|
||||
|
||||
return myorderscart
|
||||
}
|
||||
|
||||
module.exports.getOrdersCartById = async function (id) {
|
||||
let query = { _id: id };
|
||||
|
||||
return await OrdersCart.findOne(query);
|
||||
|
||||
}
|
||||
module.exports.getOrdersCartByUserId = async function (uid, idapp, numorder) {
|
||||
|
||||
@@ -223,7 +272,7 @@ module.exports.updateOrdersCartById = function (id, newOrdersCart, callback) {
|
||||
|
||||
//exist cart in databse
|
||||
if (c.length > 0) {
|
||||
OrdersCart.findOneAndUpdate(
|
||||
return OrdersCart.findOneAndUpdate(
|
||||
{ _id: id },
|
||||
{
|
||||
$set: {
|
||||
@@ -242,14 +291,111 @@ module.exports.updateOrdersCartById = function (id, newOrdersCart, callback) {
|
||||
)
|
||||
} else {
|
||||
//no cart in database
|
||||
newOrdersCart.save(callback)
|
||||
return newOrdersCart.save(callback)
|
||||
}
|
||||
})
|
||||
}
|
||||
|
||||
module.exports.setEvasoById = async function (id, evaso) {
|
||||
|
||||
return await OrdersCart.findOneAndUpdate(
|
||||
{ _id: id },
|
||||
{
|
||||
$set: {
|
||||
evaso,
|
||||
date_evaso: new Date(),
|
||||
}
|
||||
},
|
||||
{ new: false }
|
||||
)
|
||||
}
|
||||
|
||||
module.exports.setConsegnatoById = async function (id, consegnato) {
|
||||
|
||||
return await OrdersCart.findOneAndUpdate(
|
||||
{ _id: id },
|
||||
{
|
||||
$set: {
|
||||
consegnato,
|
||||
date_consegnato: new Date(),
|
||||
}
|
||||
},
|
||||
{ new: false }
|
||||
)
|
||||
}
|
||||
|
||||
module.exports.setSpeditoById = async function (id, spedito) {
|
||||
|
||||
return await OrdersCart.findOneAndUpdate(
|
||||
{ _id: id },
|
||||
{
|
||||
$set: {
|
||||
spedito,
|
||||
date_spedito: new Date(),
|
||||
}
|
||||
},
|
||||
{ new: false }
|
||||
)
|
||||
}
|
||||
|
||||
module.exports.setPagatoById = async function (id, pagato) {
|
||||
|
||||
return await OrdersCart.findOneAndUpdate(
|
||||
{ _id: id },
|
||||
{
|
||||
$set: {
|
||||
pagato,
|
||||
date_pagato: new Date(),
|
||||
}
|
||||
},
|
||||
{ new: false }
|
||||
)
|
||||
}
|
||||
|
||||
module.exports.setCompletatoById = async function (id, completato) {
|
||||
|
||||
return await OrdersCart.findOneAndUpdate(
|
||||
{ _id: id },
|
||||
{
|
||||
$set: {
|
||||
completato,
|
||||
date_completato: new Date(),
|
||||
}
|
||||
},
|
||||
{ new: false }
|
||||
)
|
||||
}
|
||||
|
||||
module.exports.createOrdersCart = async function (newOrdersCart) {
|
||||
return await newOrdersCart.save()
|
||||
}
|
||||
module.exports.updateCmd = async function (idorderscart, cmd, value) {
|
||||
|
||||
let myOrderCart = await OrdersCart.findOne({ _id: idorderscart });
|
||||
|
||||
try {
|
||||
if (!!myOrderCart) {
|
||||
const id = myOrderCart._id;
|
||||
if (cmd === shared_consts.OrderStatus.ORDER_CONFIRMED) {
|
||||
ris = await OrdersCart.setEvasoById(id, value);
|
||||
} else if (cmd === shared_consts.OrderStatus.DELIVERED) {
|
||||
ris = await OrdersCart.setConsegnatoById(id, value);
|
||||
} else if (cmd === shared_consts.OrderStatus.SHIPPED) {
|
||||
ris = await OrdersCart.setSpeditoById(id, value);
|
||||
} else if (cmd === shared_consts.OrderStatus.PAYED) {
|
||||
ris = await OrdersCart.setPagatoById(id, value);
|
||||
} else if (cmd === shared_consts.OrderStatus.COMPLETED) {
|
||||
ris = await OrdersCart.setCompletatoById(id, value);
|
||||
}
|
||||
|
||||
// myOrderCart = await OrdersCart.findOne({ _id: idorderscart });
|
||||
|
||||
}
|
||||
} catch (e) {
|
||||
console.error('Err:', e)
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
OrdersCartSchema.pre('save', async function (next) {
|
||||
|
||||
|
||||
Reference in New Issue
Block a user