- Gestore Ordini GAS (aggiornato)
- Possibilità di modificare un record, click sulla matita rossa. - corretto altre sistemazioni sui valori di minimo e massimo quantità.
This commit is contained in:
@@ -144,22 +144,27 @@ async function filterValidItems(mycart) {
|
||||
mycart.newitems = [];
|
||||
let haschanged = false;
|
||||
for (let item of mycart.items) {
|
||||
if (
|
||||
item.order &&
|
||||
item.order.hasOwnProperty('idapp') &&
|
||||
(item.order.quantity > 0 || item.order.quantitypreordered > 0) &&
|
||||
(await checkIfExistProduct(item.order.product.productInfo.code))
|
||||
) {
|
||||
mycart.newitems.push(item);
|
||||
} else {
|
||||
const Order = require('./order');
|
||||
const OrdersCart = require('./orderscart');
|
||||
try {
|
||||
if (
|
||||
item.order &&
|
||||
item.order.hasOwnProperty('idapp') &&
|
||||
item.order.product.productInfo &&
|
||||
(item.order.quantity > 0 || item.order.quantitypreordered > 0) &&
|
||||
(await checkIfExistProduct(item.order.product.productInfo.code))
|
||||
) {
|
||||
mycart.newitems.push(item);
|
||||
} else {
|
||||
const Order = require('./order');
|
||||
const OrdersCart = require('./orderscart');
|
||||
|
||||
// Cancella l'ordine su Order e OrderCart e cancella il record su Cart
|
||||
await OrdersCart.deleteOrderById(item.order._id.toString());
|
||||
await Order.deleteOrderById(item.order._id.toString());
|
||||
// Cancella l'ordine su Order e OrderCart e cancella il record su Cart
|
||||
await OrdersCart.deleteOrderById(item.order._id.toString());
|
||||
await Order.deleteOrderById(item.order._id.toString());
|
||||
|
||||
haschanged = true;
|
||||
haschanged = true;
|
||||
}
|
||||
} catch (e) {
|
||||
console.log('err', e);
|
||||
}
|
||||
}
|
||||
mycart.items = [...mycart.newitems];
|
||||
|
||||
@@ -329,7 +329,7 @@ module.exports.updateTotals = async function (order, codice_sconto) {
|
||||
|
||||
module.exports.getTotalOrderById = async function (id) {
|
||||
const query = [
|
||||
{ $match: { _id: new ObjectId(id) } },
|
||||
{ $match: { _id: new mongoose.Types.ObjectId(id) } },
|
||||
{
|
||||
$lookup: {
|
||||
from: 'products',
|
||||
|
||||
@@ -204,7 +204,7 @@ module.exports.getRecCartByUserId = async function (uid, idapp, numorder) {
|
||||
|
||||
module.exports.getOrdersCartById = async function (id) {
|
||||
|
||||
let query = { _id: new ObjectId(id) };
|
||||
let query = { _id: new mongoose.Types.ObjectId(id) };
|
||||
|
||||
const arrris = await OrdersCart.getOrdersCartByQuery(query);
|
||||
let myrec = arrris && arrris.length > 0 ? arrris[0] : null;
|
||||
@@ -274,13 +274,6 @@ module.exports.getOrdersCartByQuery = async function (query) {
|
||||
order.items = order.items.map(item => {
|
||||
if (item.order) {
|
||||
try {
|
||||
if (item.order.idProduct) {
|
||||
item.order.idProduct.productInfo = item.order.idProduct.productInfo ? item.order.idProduct.productInfo : { ...item.order.idProduct.idProductInfo };
|
||||
item.order.idProduct.productInfo.unitstr = tools.getUnitsMeasure(item.order.idProduct.productInfo.unit, true);
|
||||
// item.order.idProduct.idProductInfo = item.order.idProduct.productInfo ? item.order.idProduct.productInfo._id : '';
|
||||
}
|
||||
const myid = item.order._id;
|
||||
// console.log('ID ORD', order.numorder, myid, order.user.name);
|
||||
item.order.product = { ...item.order.idProduct };
|
||||
item.order.idProduct = item.order.product ? item.order.product._id : '';
|
||||
item.order.producer = item.order.idProducer;
|
||||
|
||||
@@ -308,6 +308,7 @@ const productSchema = new Schema({
|
||||
maxBookableSinglePersQty: {
|
||||
// quantità massima Pre-ordinabile (singolarmente)
|
||||
type: Number,
|
||||
default: 1,
|
||||
},
|
||||
stockQty: {
|
||||
// in magazzino
|
||||
@@ -318,6 +319,7 @@ const productSchema = new Schema({
|
||||
stockBloccatiQty: {
|
||||
// Prenotati Bloccati
|
||||
type: Number,
|
||||
default: 0,
|
||||
},
|
||||
bookedQtyOrdered: {
|
||||
// Quantità Prenotate ordinate (in Lavorazione)
|
||||
@@ -326,12 +328,14 @@ const productSchema = new Schema({
|
||||
bookedQtyConfirmed: {
|
||||
// Quantità Prenotate Confermate Totali
|
||||
type: Number,
|
||||
default: 0,
|
||||
},
|
||||
|
||||
// GAS:
|
||||
qtyToReachForGas: {
|
||||
// Quantità minima da raggiungere per fare l'ordine GAS
|
||||
type: Number,
|
||||
default: 0,
|
||||
},
|
||||
maxbookableGASQty: {
|
||||
// Quantità massima (ancora disponibile) Ordine GAS prenotabile (Complessivamente tra tutti gli ordini)
|
||||
@@ -341,10 +345,12 @@ const productSchema = new Schema({
|
||||
bookedGASQtyOrdered: {
|
||||
// Quantità Ordine GAS Prenotate Totali
|
||||
type: Number,
|
||||
default: 0,
|
||||
},
|
||||
bookedGASQtyConfirmed: {
|
||||
// Quantità Ordine GAS Confermate Totali
|
||||
type: Number,
|
||||
default: 0,
|
||||
},
|
||||
bookableGASBloccatiQty: {
|
||||
// Quantità Prenotate Bloccate GAS
|
||||
@@ -354,6 +360,7 @@ const productSchema = new Schema({
|
||||
quantityLow: {
|
||||
//Soglia disponibilità bassa
|
||||
type: Number,
|
||||
default: 0,
|
||||
},
|
||||
visibilityProductOutOfStock: {
|
||||
// Visibilità prodotto "esaurito"
|
||||
@@ -1173,7 +1180,7 @@ module.exports.singlerecconvert_AfterImport_AndSave = async function (idapp, pro
|
||||
}
|
||||
|
||||
if (!tools.isObjectEmpty(objtoset)) {
|
||||
ris = await Product.findOneAndUpdate({ _id: new ObjectId(prod._id) }, { $set: objtoset });
|
||||
ris = await Product.findOneAndUpdate({ _id: prod._id }, { $set: objtoset });
|
||||
|
||||
const objDelete = {
|
||||
cat_name: 1,
|
||||
@@ -1186,7 +1193,7 @@ module.exports.singlerecconvert_AfterImport_AndSave = async function (idapp, pro
|
||||
gas_name: 1,
|
||||
};
|
||||
|
||||
ris = await Product.updateOne({ _id: new ObjectId(prod._id) }, { $unset: objDelete });
|
||||
ris = await Product.updateOne({ _id: prod._id }, { $unset: objDelete });
|
||||
|
||||
if (ris && ris.modifiedCount > 0) {
|
||||
console.log('Modificato: ', objtoset.name);
|
||||
|
||||
Reference in New Issue
Block a user