agiornamento, sistemazioni varie PCB

This commit is contained in:
Surya Paolo
2024-01-23 00:10:40 +01:00
parent e4504bcf9e
commit aeabf96efe
8 changed files with 144 additions and 38 deletions

View File

@@ -19,6 +19,7 @@ const Cart = require('../models/cart');
const tools = require('../tools/general');
const { ObjectID } = require('mongodb');
const OrdersCartSchema = new Schema({
@@ -521,6 +522,24 @@ module.exports.addOrderToMovement = async function (myOrderCart, usernameStore,
}
}
module.exports.checkQtaIfIsLow_SendAlert = async function (idapp, idProduct) {
try {
const telegrambot = require('../telegram/telegrambot');
const isLow = await Product.isLowQuantityInStockById(idProduct);
const instock = await Product.getInStockById(idProduct);
const myprod = await Product.getProductById(idProduct);
if (isLow && myprod) {
let msg = `Il Prodotto '${myprod.productInfo.name}' è rimasto a ${instock} quantità !`;
await telegrambot.sendMsgTelegramToTheManagers(idapp, msg);
}
} catch (e) {
console.error('Err;', e);
}
}
module.exports.updateMagazzinoOrdineInLavorazione = async function (idorderscart) {
try {
@@ -545,6 +564,8 @@ module.exports.updateMagazzinoOrdineInLavorazione = async function (idorderscart
}
};
await Product.findOneAndUpdate({ _id: order.idProduct }, update, { new: false });
await OrdersCart.checkQtaIfIsLow_SendAlert(myorderscart.idapp, order.idProduct)
}
}
@@ -555,6 +576,7 @@ module.exports.updateMagazzinoOrdineInLavorazione = async function (idorderscart
}
module.exports.updateStockQtaDalMagazzinoOrdineConfermato = async function (idorderscart) {
try {
@@ -653,7 +675,7 @@ module.exports.updateStockQtaPerCancellazioneOrdine = async function (idordersca
fieldstoUpdate = {
...fieldstoUpdate,
bookedQtyOrdered,
bookedQtyOrdered: -order.quantity,
}
update = {
@@ -676,7 +698,7 @@ module.exports.updateStockQtaPerCancellazioneOrdine = async function (idordersca
fieldstoUpdate = {
...fieldstoUpdate,
bookedGASQtyOrdered,
bookedGASQtyOrdered: -order.quantitypreordered,
}
update = {

View File

@@ -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;

View File

@@ -56,18 +56,21 @@ class Cart {
}
isSameStorehouse(itemorder) {
if (this.items.length > 0) {
const mystorehouse = this.items[0].order.idStorehouse
return (mystorehouse ? mystorehouse._id.toString() === itemorder.idStorehouse : true);
} else {
return true;
try {
if (this.items.length > 0) {
const mystorehouse = this.items[0].order.idStorehouse
return (mystorehouse ? mystorehouse._id.toString() === itemorder.idStorehouse : true);
} else {
return true;
}
} catch (e) {
return false;
}
}
async addqty(itemorder) {
const myitem = this.items.find((rec) => rec.order._id.toString() === itemorder._id)
if (!!myitem) {
let stepmin = myitem.order.product.minStepQty;

View File

@@ -1440,7 +1440,8 @@ function load(req, res, version) {
let workers = User.getusersWorkersList(idapp);
let storehouses = Storehouse.findAllIdApp(idapp);
let providers = Provider.findAllIdApp(idapp);
let catprods = CatProd.findAllIdApp(idapp);
let catprods = Product.getArrCatProds(idapp, shared_consts.PROD.BOTTEGA);
let catprods_gas = Product.getArrCatProds(idapp, shared_consts.PROD.GAS);
let subcatprods = SubCatProd.findAllIdApp(idapp);
let gasordines = Gasordine.findAllIdApp(idapp);
let ismanager = false;
@@ -1455,6 +1456,7 @@ function load(req, res, version) {
let departments = Department.findAllIdApp(idapp);
let categories = Category.findAllIdApp(idapp);
// SKILLS:
let levels = Level.findAllIdApp(idapp);
let adtypes = AdType.findAllIdApp(idapp);
@@ -1545,6 +1547,7 @@ function load(req, res, version) {
productInfos,
catprods,
subcatprods,
catprods_gas,
]).then((arrdata) => {
// console.table(arrdata);
let myuser = req.user;
@@ -1634,6 +1637,7 @@ function load(req, res, version) {
productInfos: arrdata[44],
catprods: arrdata[45],
subcatprods: arrdata[46],
catprods_gas: arrdata[47],
});
const prova = 1;

View File

@@ -4395,8 +4395,9 @@ if (true) {
console.error('Error Telegram LOOP : ' + e.message);
}
}
}).catch(() => {
}).catch((e) => {
arrTeleg = [];
console.error('Error internetAvailable:' + e);
});
}