agiornamento, sistemazioni varie PCB
This commit is contained in:
@@ -191,6 +191,29 @@ module.exports.getProductById = async function (id) {
|
||||
return arrris && arrris.length > 0 ? arrris[0] : null
|
||||
}
|
||||
|
||||
module.exports.getInStockById = async function (id) {
|
||||
const myprod = await Product.findOne({ _id: id });
|
||||
if (myprod) {
|
||||
let instock = 0;
|
||||
if (myprod.idGasordine) {
|
||||
instock = myprod.maxbookableGASQty;
|
||||
} else {
|
||||
instock = myprod.stockQty;
|
||||
}
|
||||
return instock
|
||||
}
|
||||
return null;
|
||||
}
|
||||
|
||||
module.exports.isLowQuantityInStockById = async function (id) {
|
||||
const instock = await Product.getInStockById(id);
|
||||
const myprod = await Product.findOne({ _id: id });
|
||||
if (instock) {
|
||||
return (instock <= (myprod.quantityLow + 1));
|
||||
}
|
||||
return false;
|
||||
}
|
||||
|
||||
module.exports.findAllIdApp = async function (idapp, code, id, all) {
|
||||
let myfind = {};
|
||||
let myqueryadd = {};
|
||||
@@ -554,6 +577,68 @@ module.exports.convertAfterImportALLPROD = async function (idapp, dataObjects) {
|
||||
|
||||
};
|
||||
|
||||
module.exports.getArrCatProds = async function (idapp, cosa) {
|
||||
|
||||
try {
|
||||
let addquery = {};
|
||||
let arr = [];
|
||||
if (cosa === shared_consts.PROD.GAS) {
|
||||
addquery = { idapp, idGasordine: { $exists: true, $ne: null, $type: 'objectId' } }
|
||||
} else if (cosa === shared_consts.PROD.BOTTEGA) {
|
||||
addquery = {
|
||||
idapp, $or: [
|
||||
{ idGasordine: { $exists: false } },
|
||||
{ idGasordine: { $exists: true, $eq: null } }
|
||||
]
|
||||
}
|
||||
} else {
|
||||
addquery = { idapp };
|
||||
}
|
||||
|
||||
let myquery = [
|
||||
{ $match: addquery },
|
||||
{
|
||||
$lookup: {
|
||||
from: "productinfos",
|
||||
localField: "idProductInfo",
|
||||
foreignField: "_id",
|
||||
as: "productInfo",
|
||||
},
|
||||
},
|
||||
{
|
||||
$lookup: {
|
||||
from: "catprods",
|
||||
localField: "productInfo.idCatProds",
|
||||
foreignField: "_id",
|
||||
as: "category"
|
||||
}
|
||||
},
|
||||
{ $unwind: "$category" },
|
||||
{ $group: { _id: "$category._id", name: { $first: "$category.name" } } },
|
||||
{ $sort: { name: 1 } }
|
||||
];
|
||||
|
||||
arr = await Product.aggregate(myquery, (err, result) => {
|
||||
if (err) {
|
||||
console.error(err);
|
||||
// Gestisci l'errore come desideri
|
||||
return [];
|
||||
} else {
|
||||
const uniqueCategories = result.map(category => category.name);
|
||||
// console.log(uniqueCategories);
|
||||
return uniqueCategories;
|
||||
// Ora uniqueCategories contiene l'array delle categorie univoche utilizzate in tutti i prodotti con active = true
|
||||
}
|
||||
});
|
||||
return arr;
|
||||
} catch (e) {
|
||||
console.error('err', e);
|
||||
return [];
|
||||
}
|
||||
|
||||
|
||||
}
|
||||
|
||||
module.exports.singlerecconvert_AfterImport_AndSave = async function (idapp, prod, isnuovo) {
|
||||
|
||||
let setta = false;
|
||||
|
||||
Reference in New Issue
Block a user