aggiornamento...
This commit is contained in:
@@ -168,9 +168,86 @@ module.exports.getRecCartByUserId = async function (uid, idapp, numorder) {
|
|||||||
}
|
}
|
||||||
|
|
||||||
module.exports.getOrdersCartById = async function (id) {
|
module.exports.getOrdersCartById = async function (id) {
|
||||||
let query = { _id: id };
|
|
||||||
|
|
||||||
return await OrdersCart.findOne(query);
|
let query = { _id: ObjectID(id) };
|
||||||
|
|
||||||
|
const arrris = await OrdersCart.getOrdersCartByQuery(query);
|
||||||
|
return arrris && arrris.length > 0 ? arrris[0] : null;
|
||||||
|
|
||||||
|
}
|
||||||
|
|
||||||
|
module.exports.getOrdersCartByQuery = async function (query) {
|
||||||
|
|
||||||
|
let myorderscart = await OrdersCart.find(query)
|
||||||
|
.populate('items.order')
|
||||||
|
.populate({
|
||||||
|
path: 'items.order',
|
||||||
|
populate: {
|
||||||
|
path: 'idProduct',
|
||||||
|
model: 'Product'
|
||||||
|
},
|
||||||
|
})
|
||||||
|
.populate({
|
||||||
|
path: 'items.order',
|
||||||
|
populate: {
|
||||||
|
path: 'idProducer',
|
||||||
|
model: 'Producer'
|
||||||
|
},
|
||||||
|
})
|
||||||
|
.populate({
|
||||||
|
path: 'items.order',
|
||||||
|
populate: {
|
||||||
|
path: 'idProvider',
|
||||||
|
model: 'Provider'
|
||||||
|
},
|
||||||
|
})
|
||||||
|
.populate({
|
||||||
|
path: 'items.order',
|
||||||
|
populate: {
|
||||||
|
path: 'idStorehouse',
|
||||||
|
model: 'Storehouse'
|
||||||
|
},
|
||||||
|
})
|
||||||
|
.populate({
|
||||||
|
path: 'items.order',
|
||||||
|
populate: {
|
||||||
|
path: 'idScontisticas',
|
||||||
|
model: 'Scontistica'
|
||||||
|
},
|
||||||
|
})
|
||||||
|
.populate({
|
||||||
|
path: 'userId',
|
||||||
|
model: 'User',
|
||||||
|
select: '_id name surname username profile', // Specify the fields you want to retrieve
|
||||||
|
})
|
||||||
|
.lean();
|
||||||
|
|
||||||
|
myorderscart = myorderscart.map(order => {
|
||||||
|
order.user = order.userId
|
||||||
|
order.userId = order.user._id
|
||||||
|
order.items = order.items.map(item => {
|
||||||
|
if (item.order) {
|
||||||
|
try {
|
||||||
|
item.order.product = item.order.idProduct;
|
||||||
|
item.order.idProduct = item.order.product ? item.order.product._id : '';
|
||||||
|
item.order.producer = item.order.idProducer;
|
||||||
|
item.order.idProducer = item.order.producer ? item.order.producer._id : '';
|
||||||
|
item.order.storehouse = item.order.idStorehouse;
|
||||||
|
item.order.idStorehouse = item.order.storehouse ? item.order.storehouse._id : '';
|
||||||
|
item.order.provider = item.order.idProvider;
|
||||||
|
item.order.idProvider = item.order.provider ? item.order.provider._id : '';
|
||||||
|
item.order.scontisticas = item.order.scontisticas;
|
||||||
|
item.order.idScontisticas = item.order.idScontisticas ? item.order.idScontisticas._id : '';
|
||||||
|
} catch (e) {
|
||||||
|
console.error('Err: ', e);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
return item;
|
||||||
|
});
|
||||||
|
return order;
|
||||||
|
});
|
||||||
|
|
||||||
|
return myorderscart;
|
||||||
|
|
||||||
}
|
}
|
||||||
module.exports.getOrdersCartByUserId = async function (uid, idapp, numorder) {
|
module.exports.getOrdersCartByUserId = async function (uid, idapp, numorder) {
|
||||||
@@ -186,6 +263,12 @@ module.exports.getOrdersCartByUserId = async function (uid, idapp, numorder) {
|
|||||||
query.userId = uid;
|
query.userId = uid;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
myorderscart = await OrdersCart.getOrdersCartByQuery(query);
|
||||||
|
|
||||||
|
if (myorderscart)
|
||||||
|
console.log('*** Num myorderscart ', myorderscart.length);
|
||||||
|
|
||||||
|
|
||||||
/*transform: function(doc, populated) {
|
/*transform: function(doc, populated) {
|
||||||
// Rinomina 'idProduct' a 'product' nei risultati della popolazione
|
// Rinomina 'idProduct' a 'product' nei risultati della popolazione
|
||||||
populated.product = populated.idProduct;
|
populated.product = populated.idProduct;
|
||||||
@@ -193,76 +276,7 @@ module.exports.getOrdersCartByUserId = async function (uid, idapp, numorder) {
|
|||||||
return populated;
|
return populated;
|
||||||
},*/
|
},*/
|
||||||
|
|
||||||
myorderscart = await OrdersCart.find(query)
|
|
||||||
.populate('items.order')
|
|
||||||
.populate({
|
|
||||||
path: 'items.order',
|
|
||||||
populate: {
|
|
||||||
path: 'idProduct',
|
|
||||||
model: 'Product'
|
|
||||||
},
|
|
||||||
})
|
|
||||||
.populate({
|
|
||||||
path: 'items.order',
|
|
||||||
populate: {
|
|
||||||
path: 'idProducer',
|
|
||||||
model: 'Producer'
|
|
||||||
},
|
|
||||||
})
|
|
||||||
.populate({
|
|
||||||
path: 'items.order',
|
|
||||||
populate: {
|
|
||||||
path: 'idProvider',
|
|
||||||
model: 'Provider'
|
|
||||||
},
|
|
||||||
})
|
|
||||||
.populate({
|
|
||||||
path: 'items.order',
|
|
||||||
populate: {
|
|
||||||
path: 'idStorehouse',
|
|
||||||
model: 'Storehouse'
|
|
||||||
},
|
|
||||||
})
|
|
||||||
.populate({
|
|
||||||
path: 'items.order',
|
|
||||||
populate: {
|
|
||||||
path: 'idScontisticas',
|
|
||||||
model: 'Scontistica'
|
|
||||||
},
|
|
||||||
})
|
|
||||||
.populate({
|
|
||||||
path: 'userId',
|
|
||||||
model: 'User',
|
|
||||||
select: '_id name surname username profile', // Specify the fields you want to retrieve
|
|
||||||
})
|
|
||||||
.lean();
|
|
||||||
|
|
||||||
myorderscart = myorderscart.map(order => {
|
|
||||||
order.user = order.userId
|
|
||||||
order.userId = order.user._id
|
|
||||||
order.items = order.items.map(item => {
|
|
||||||
if (item.order) {
|
|
||||||
try {
|
|
||||||
item.order.product = item.order.idProduct;
|
|
||||||
item.order.idProduct = item.order.product ? item.order.product._id : '';
|
|
||||||
item.order.producer = item.order.idProducer;
|
|
||||||
item.order.idProducer = item.order.producer ? item.order.producer._id : '';
|
|
||||||
item.order.storehouse = item.order.idStorehouse;
|
|
||||||
item.order.idStorehouse = item.order.storehouse ? item.order.storehouse._id : '';
|
|
||||||
item.order.provider = item.order.idProvider;
|
|
||||||
item.order.idProvider = item.order.provider ? item.order.provider._id : '';
|
|
||||||
item.order.scontisticas = item.order.scontisticas;
|
|
||||||
item.order.idScontisticas = item.order.idScontisticas ? item.order.idScontisticas._id : '';
|
|
||||||
} catch (e) {
|
|
||||||
console.error('Err: ', e);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
return item;
|
|
||||||
});
|
|
||||||
return order;
|
|
||||||
});
|
|
||||||
|
|
||||||
console.log('*** Num myorderscart ', myorderscart.length);
|
|
||||||
return myorderscart
|
return myorderscart
|
||||||
} catch (e) {
|
} catch (e) {
|
||||||
console.error('Err:', e);
|
console.error('Err:', e);
|
||||||
@@ -438,7 +452,8 @@ module.exports.updateStockQtaDalMagazzino = async function (idorderscart) {
|
|||||||
module.exports.updateCmd = async function (ordersCart, status, value) {
|
module.exports.updateCmd = async function (ordersCart, status, value) {
|
||||||
|
|
||||||
|
|
||||||
let myOrderCart = await OrdersCart.findOne({ _id: ordersCart._id }).populate('items.order').lean();
|
let myOrderCart = await OrdersCart.findOne({ _id: ordersCart._id })
|
||||||
|
.populate('items.order').lean();
|
||||||
|
|
||||||
try {
|
try {
|
||||||
if (!!myOrderCart) {
|
if (!!myOrderCart) {
|
||||||
@@ -466,7 +481,7 @@ module.exports.updateCmd = async function (ordersCart, status, value) {
|
|||||||
|
|
||||||
await OrdersCart.setFieldInOrdersById({ status }, myOrderCart);
|
await OrdersCart.setFieldInOrdersById({ status }, myOrderCart);
|
||||||
|
|
||||||
myOrderCart = await OrdersCart.findOne({ _id: ordersCart._id }).populate('items.order').lean();
|
myOrderCart = await OrdersCart.getOrdersCartById(ordersCart._id)
|
||||||
// myOrderCart = await OrdersCart.findOne({ _id: idorderscart });
|
// myOrderCart = await OrdersCart.findOne({ _id: idorderscart });
|
||||||
|
|
||||||
return myOrderCart;
|
return myOrderCart;
|
||||||
@@ -513,6 +528,39 @@ OrdersCartSchema.pre('save', async function (next) {
|
|||||||
}
|
}
|
||||||
});
|
});
|
||||||
|
|
||||||
|
module.exports.getmsgorderTelegram = async function (ordersCart) {
|
||||||
|
try {
|
||||||
|
const statusstr = shared_consts.getStatusStr(ordersCart.status);
|
||||||
|
|
||||||
|
let msg = '🟢✍️ Ordine n. ' + ordersCart.numorder
|
||||||
|
|
||||||
|
msg += '<br>Stato: ' + statusstr;
|
||||||
|
|
||||||
|
msg += '<br>🙎🏻♂️ ' + tools.getNomeCognomeEUserNameByUser(ordersCart.user)
|
||||||
|
if (ordersCart.note)
|
||||||
|
msg += '<br>Note: ' + ordersCart.note;
|
||||||
|
|
||||||
|
|
||||||
|
msg += '<br><br>Lista Prodotti:';
|
||||||
|
for (const ord of ordersCart.items) {
|
||||||
|
msg += '<br>';
|
||||||
|
msg += '✅ [' + ord.order.quantity + '] ' + ord.order.product.name + ' (' + ord.order.price + ' € ' + (ord.order.after_price ? ord.order.after_price : '') + ')';
|
||||||
|
}
|
||||||
|
|
||||||
|
msg += '<br>';
|
||||||
|
|
||||||
|
msg += '<br>Totale Prodotti: ' + ordersCart.totalQty;
|
||||||
|
msg += '<br>Totale Ordine: ' + ordersCart.totalPrice + ' € 💰';
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
return msg;
|
||||||
|
|
||||||
|
} catch (e) {
|
||||||
|
console.error('Err', e);
|
||||||
|
}
|
||||||
|
};
|
||||||
|
|
||||||
module.exports.createIndexes((err) => {
|
module.exports.createIndexes((err) => {
|
||||||
if (err) throw err;
|
if (err) throw err;
|
||||||
});
|
});
|
||||||
|
|||||||
@@ -299,8 +299,12 @@ module.exports.findAllIdApp = async function (idapp, code, id) {
|
|||||||
|
|
||||||
);
|
);
|
||||||
|
|
||||||
|
// console.log('query=', query);
|
||||||
|
|
||||||
let ris = await Product.aggregate(query)
|
let ris = await Product.aggregate(query)
|
||||||
|
|
||||||
|
// console.table('ris', ris);
|
||||||
|
|
||||||
return ris;
|
return ris;
|
||||||
|
|
||||||
} catch (e) {
|
} catch (e) {
|
||||||
|
|||||||
@@ -743,12 +743,13 @@ module.exports = {
|
|||||||
sendEmail_OrderProduct: async function (lang, idapp, orders, user) {
|
sendEmail_OrderProduct: async function (lang, idapp, orders, user) {
|
||||||
|
|
||||||
try {
|
try {
|
||||||
const msginizio = 'Ordine n: ' + orders.numorder + ' ' + user.name + ' ' + user.surname;
|
const msg = await OrdersCart.getmsgorderTelegram(orders);
|
||||||
|
const msginizio = msg;
|
||||||
console.log(msginizio);
|
console.log(msginizio);
|
||||||
|
|
||||||
if (process.env.SEND_EMAIL_ORDERS === '1') {
|
await telegrambot.sendMsgTelegramToTheManagers(idapp, msginizio);
|
||||||
|
|
||||||
await telegrambot.sendMsgTelegramToTheManagers(idapp, msginizio);
|
if (process.env.SEND_EMAIL_ORDERS === '1') {
|
||||||
|
|
||||||
let mylocalsconf = {
|
let mylocalsconf = {
|
||||||
idapp,
|
idapp,
|
||||||
@@ -776,12 +777,13 @@ module.exports = {
|
|||||||
sendEmail_Order: async function (lang, idapp, orders, user, ordertype, status) {
|
sendEmail_Order: async function (lang, idapp, orders, user, ordertype, status) {
|
||||||
|
|
||||||
try {
|
try {
|
||||||
const msginizio = 'INIZIO - sendEmail_Order ' + ordertype + ': ' + tools.getNomeAppByIdApp(idapp);
|
const msg = await OrdersCart.getmsgorderTelegram(orders);
|
||||||
|
const msginizio = msg;
|
||||||
console.log(msginizio);
|
console.log(msginizio);
|
||||||
|
|
||||||
if (process.env.SEND_EMAIL_ORDERS === '1') {
|
await telegrambot.sendMsgTelegramToTheManagers(idapp, msginizio);
|
||||||
|
|
||||||
await telegrambot.sendMsgTelegramToTheManagers(idapp, msginizio);
|
if (process.env.SEND_EMAIL_ORDERS === '1') {
|
||||||
|
|
||||||
let mylocalsconf = {
|
let mylocalsconf = {
|
||||||
idapp,
|
idapp,
|
||||||
|
|||||||
@@ -707,10 +707,20 @@ const MyTelegramBot = {
|
|||||||
|
|
||||||
getAppTelegram: function () {
|
getAppTelegram: function () {
|
||||||
if (process.env.appTelegram) {
|
if (process.env.appTelegram) {
|
||||||
return JSON.parse(process.env.appTelegram);
|
arrTeleg = JSON.parse(process.env.appTelegram);
|
||||||
} else {
|
} else {
|
||||||
return appTelegram;
|
arrTeleg = appTelegram;
|
||||||
}
|
}
|
||||||
|
if (process.env.NODE_ENV === 'development')
|
||||||
|
arrTeleg = appTelegram_DEVELOP;
|
||||||
|
else if (process.env.NODE_ENV === 'test')
|
||||||
|
arrTeleg = MyTelegramBot.getAppTelegramTest();
|
||||||
|
|
||||||
|
const arrTelegFromSite = tools.getArrTelegramFromSite();
|
||||||
|
if (arrTelegFromSite.length > 0) {
|
||||||
|
arrTeleg = arrTelegFromSite;
|
||||||
|
}
|
||||||
|
return arrTeleg;
|
||||||
|
|
||||||
},
|
},
|
||||||
|
|
||||||
@@ -3437,14 +3447,14 @@ class Telegram {
|
|||||||
|
|
||||||
if (!msg.from.username) {
|
if (!msg.from.username) {
|
||||||
// Non ha l'Username:
|
// Non ha l'Username:
|
||||||
|
|
||||||
// Chiedi l'username sul Bot:
|
// Chiedi l'username sul Bot:
|
||||||
if (tools.getConfSiteOptionEnabledByIdApp(this.idapp, shared_consts.ConfSite.AskUsernameSulBot)) {
|
if (tools.getConfSiteOptionEnabledByIdApp(this.idapp, shared_consts.ConfSite.AskUsernameSulBot)) {
|
||||||
rec.status = Status.WAITFOR_USERNAME_TELEGRAM;
|
rec.status = Status.WAITFOR_USERNAME_TELEGRAM;
|
||||||
}
|
}
|
||||||
} else {
|
} else {
|
||||||
// Ha l'Username
|
// Ha l'Username
|
||||||
|
|
||||||
// Chiedi l'invitante ?
|
// Chiedi l'invitante ?
|
||||||
if (tools.getConfSiteOptionEnabledByIdApp(this.idapp, shared_consts.ConfSite.AskInvitantesulBot)) {
|
if (tools.getConfSiteOptionEnabledByIdApp(this.idapp, shared_consts.ConfSite.AskInvitantesulBot)) {
|
||||||
rec.status = Status.WAITFOR_USERNAME_INVITANTE;
|
rec.status = Status.WAITFOR_USERNAME_INVITANTE;
|
||||||
@@ -4072,15 +4082,6 @@ function getclTelegByidapp(idapp) {
|
|||||||
//if (!tools.testing() || true) {
|
//if (!tools.testing() || true) {
|
||||||
if (true) {
|
if (true) {
|
||||||
let arrTeleg = MyTelegramBot.getAppTelegram();
|
let arrTeleg = MyTelegramBot.getAppTelegram();
|
||||||
if (process.env.NODE_ENV === 'development')
|
|
||||||
arrTeleg = appTelegram_DEVELOP;
|
|
||||||
else if (process.env.NODE_ENV === 'test')
|
|
||||||
arrTeleg = MyTelegramBot.getAppTelegramTest();
|
|
||||||
|
|
||||||
const arrTelegFromSite = tools.getArrTelegramFromSite();
|
|
||||||
if (arrTelegFromSite.length > 0) {
|
|
||||||
arrTeleg = arrTelegFromSite;
|
|
||||||
}
|
|
||||||
|
|
||||||
var internetAvailable = require('internet-available');
|
var internetAvailable = require('internet-available');
|
||||||
|
|
||||||
|
|||||||
@@ -407,6 +407,50 @@ module.exports = {
|
|||||||
CANCELLATI: { label: 'Cancellati', value: 10, icon: 'delete', color: 'text-red' }, //CANCELED
|
CANCELLATI: { label: 'Cancellati', value: 10, icon: 'delete', color: 'text-red' }, //CANCELED
|
||||||
},
|
},
|
||||||
|
|
||||||
|
OrderStatusStr: [
|
||||||
|
{
|
||||||
|
label: 'Nessuno',
|
||||||
|
value: 0,
|
||||||
|
},
|
||||||
|
{
|
||||||
|
label: 'In Carrello',
|
||||||
|
value: 1,
|
||||||
|
},
|
||||||
|
{
|
||||||
|
label: 'Ordine in Lavorazione',
|
||||||
|
value: 2,
|
||||||
|
},
|
||||||
|
{
|
||||||
|
label: 'Ordine Confermato',
|
||||||
|
value: 3,
|
||||||
|
},
|
||||||
|
{
|
||||||
|
label: 'Pagato',
|
||||||
|
value: 4,
|
||||||
|
},
|
||||||
|
{
|
||||||
|
label: 'Consegnato',
|
||||||
|
value: 5,
|
||||||
|
},
|
||||||
|
{
|
||||||
|
label: 'Spedito',
|
||||||
|
value: 6,
|
||||||
|
},
|
||||||
|
{
|
||||||
|
label: 'Ricevuto',
|
||||||
|
value: 7,
|
||||||
|
},
|
||||||
|
{
|
||||||
|
label: 'Completato',
|
||||||
|
value: 8,
|
||||||
|
},
|
||||||
|
{
|
||||||
|
label: 'Cancellato',
|
||||||
|
value: 10,
|
||||||
|
},
|
||||||
|
|
||||||
|
],
|
||||||
|
|
||||||
OrderStatusView: {
|
OrderStatusView: {
|
||||||
CHECKOUT_SENT: 2,
|
CHECKOUT_SENT: 2,
|
||||||
ORDER_CONFIRMED: 3,
|
ORDER_CONFIRMED: 3,
|
||||||
@@ -864,5 +908,9 @@ module.exports = {
|
|||||||
|
|
||||||
return ''
|
return ''
|
||||||
},
|
},
|
||||||
|
getStatusStr(status) {
|
||||||
|
const trovatorec = this.OrderStatusStr.find((rec) => rec.value === status)
|
||||||
|
return (trovatorec) ? trovatorec.label : ''
|
||||||
|
},
|
||||||
|
|
||||||
};
|
};
|
||||||
|
|||||||
Reference in New Issue
Block a user