diff --git a/.vscode/launch.json b/.vscode/launch.json index c48cd73..9acd2e2 100644 --- a/.vscode/launch.json +++ b/.vscode/launch.json @@ -11,15 +11,17 @@ "runtimeArgs": [ "--inspect=9229" // Use "--inspect=0.0.0.0:9229" for remote debugging ], - "args": ["${workspaceFolder}/src/server/server.js"], // Replace with your entry file + "args": [ + "${workspaceFolder}/src/server/server.js" + ], // Replace with your entry file "cwd": "${workspaceFolder}", "autoAttachChildProcesses": true, "console": "integratedTerminal", "internalConsoleOptions": "neverOpen", "sourceMaps": true, "env": { - "NODE_ENV":"development", - "TESTING_ON":"1" + "NODE_ENV": "development", + "TESTING_ON": "1" }, }, { @@ -32,33 +34,18 @@ "runtimeArgs": [ "--trace-warnings" // Use "--inspect=0.0.0.0:9229" for remote debugging ], - "args": ["${workspaceFolder}/src/server/server.js"], // Replace with your entry file + "args": [ + "${workspaceFolder}/src/server/server.js" + ], // Replace with your entry file "cwd": "${workspaceFolder}", "autoAttachChildProcesses": true, "console": "integratedTerminal", "internalConsoleOptions": "neverOpen", "sourceMaps": true, "env": { - "NODE_ENV":"development", - "TESTING_ON":"1" + "NODE_ENV": "development", + "TESTING_ON": "1" }, - }, - { - "name": "Server Debug", - "request": "launch", - "runtimeArgs": [ - "run-script", - "start" - ], - "runtimeExecutable": "npm", - "skipFiles": [ - "/**" - ], - "env": { - "NODE_ENV":"development", - "TESTING_ON":"1" - }, - "type": "node" }, { "name": "ServerSide", @@ -69,8 +56,8 @@ ], "type": "node", "env": { - "NODE_ENV":"development", - "TESTING_ON":"1" + "NODE_ENV": "development", + "TESTING_ON": "1" } }, ] diff --git a/filelog.txt b/filelog.txt index f8e3fd7..bb6d51f 100644 --- a/filelog.txt +++ b/filelog.txt @@ -132,3 +132,5 @@ come funziona: - accedete e poi cliccate su "gruppo di acquisto". - cliccate sul carrello verde 🛒 per aggiungere i kg che desiderate. - per finire: cliccare su "procedi all'ordine" e confermate. + +Dom 21/01 ORE 19:00: USER [paoloar77]: 👉🏻 indietro diff --git a/logevents.txt b/logevents.txt index 3b03c54..403f08d 100644 --- a/logevents.txt +++ b/logevents.txt @@ -26,4 +26,6 @@ Mar 03/10 ORE 22:49: 🤖: Da Sùrya (Paolo) undefined (paoloar77): Sab 04/11 ORE 15:17: 🤖: Da Sùrya (Paolo) undefined (paoloar77): ✅ SuryaArena è stato Abilitato correttamente (da paoloar77)! Sab 02/12 ORE 14:15: 🤖: Da Sùrya (Paolo) undefined (paoloar77): -✅ SuryaArena è stato Abilitato correttamente (da paoloar77)! \ No newline at end of file +✅ SuryaArena è stato Abilitato correttamente (da paoloar77)! +Dom 21/01 ORE 19:00: 🤖: Da Sùrya (Paolo) undefined (paoloar77): +👉🏻 indietro \ No newline at end of file diff --git a/src/server/models/orderscart.js b/src/server/models/orderscart.js index 52e76f7..6438375 100755 --- a/src/server/models/orderscart.js +++ b/src/server/models/orderscart.js @@ -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 = { diff --git a/src/server/models/product.js b/src/server/models/product.js index ac05318..75db387 100755 --- a/src/server/models/product.js +++ b/src/server/models/product.js @@ -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; diff --git a/src/server/modules/Cart.js b/src/server/modules/Cart.js index 4348898..bc53719 100755 --- a/src/server/modules/Cart.js +++ b/src/server/modules/Cart.js @@ -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; diff --git a/src/server/router/index_router.js b/src/server/router/index_router.js index fbcf339..403e444 100755 --- a/src/server/router/index_router.js +++ b/src/server/router/index_router.js @@ -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; diff --git a/src/server/telegram/telegrambot.js b/src/server/telegram/telegrambot.js index 949c392..89561b5 100755 --- a/src/server/telegram/telegrambot.js +++ b/src/server/telegram/telegrambot.js @@ -4395,8 +4395,9 @@ if (true) { console.error('Error Telegram LOOP : ' + e.message); } } - }).catch(() => { + }).catch((e) => { arrTeleg = []; + console.error('Error internetAvailable:' + e); }); }