addtocash using sendcoins Circuit
This commit is contained in:
@@ -13,6 +13,8 @@ const Product = require('../models/product');
|
||||
const Cash = require('../models/cash');
|
||||
const ProductInfo = require('../models/productInfo');
|
||||
|
||||
const { Circuit } = require('../models/circuit');
|
||||
|
||||
const tools = require('../tools/general');
|
||||
|
||||
const { ObjectID } = require('mongodb');
|
||||
@@ -477,13 +479,48 @@ module.exports.addOrderToCash = async function (idorderscart, usernameStore, req
|
||||
|
||||
const myorderscart = await OrdersCart.findOne({ _id: idorderscart }).populate('items.order').lean();
|
||||
|
||||
const mycash = await Cash.createMovementCashByOrdersCart(myorderscart, usernameStore, req);
|
||||
const mymov = await Circuit.addMovementByOrdersCart(id, myOrderCart, usernameStore, '');
|
||||
// const mycash = await Cash.createMovementCashByOrdersCart(myorderscart, usernameStore, req);
|
||||
|
||||
} catch (e) {
|
||||
console.error('Err', e);
|
||||
}
|
||||
}
|
||||
|
||||
module.exports.updateMagazzinoOrdineInLavorazione = async function (idorderscart) {
|
||||
|
||||
try {
|
||||
|
||||
const myorderscart = await OrdersCart.findOne({ _id: idorderscart }).populate('items.order').lean();
|
||||
|
||||
if (myorderscart) {
|
||||
for (const idkey in myorderscart.items) {
|
||||
let order = myorderscart.items[idkey].order;
|
||||
|
||||
if (!order.confermato) { // Se ancora non è stato confermato:
|
||||
let update = {
|
||||
$inc: {
|
||||
bookedQtyOrdered: order.quantity,
|
||||
}
|
||||
};
|
||||
await Product.findOneAndUpdate({ _id: order.idProduct }, update, { new: false });
|
||||
|
||||
update = {
|
||||
$inc: {
|
||||
bookedGASQtyOrdered: order.quantitypreordered,
|
||||
}
|
||||
};
|
||||
await Product.findOneAndUpdate({ _id: order.idProduct }, update, { new: false });
|
||||
}
|
||||
|
||||
}
|
||||
}
|
||||
} catch (e) {
|
||||
console.error('Err', e);
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
module.exports.updateStockQtaDalMagazzinoOrdineConfermato = async function (idorderscart) {
|
||||
|
||||
try {
|
||||
@@ -507,40 +544,7 @@ module.exports.updateStockQtaDalMagazzinoOrdineConfermato = async function (idor
|
||||
$inc: {
|
||||
maxbookableGASQty: -order.quantitypreordered,
|
||||
bookableGASBloccatiQty: order.quantitypreordered,
|
||||
bookedGASQtyOrdered: order.quantitypreordered,
|
||||
}
|
||||
};
|
||||
await Product.findOneAndUpdate({ _id: order.idProduct }, update, { new: false });
|
||||
}
|
||||
|
||||
}
|
||||
}
|
||||
} catch (e) {
|
||||
console.error('Err', e);
|
||||
}
|
||||
|
||||
}
|
||||
module.exports.updateMagazzinoOrdineInLavorazione = async function (idorderscart) {
|
||||
|
||||
try {
|
||||
|
||||
const myorderscart = await OrdersCart.findOne({ _id: idorderscart }).populate('items.order').lean();
|
||||
|
||||
if (myorderscart) {
|
||||
for (const idkey in myorderscart.items) {
|
||||
let order = myorderscart.items[idkey].order;
|
||||
|
||||
if (!order.confermato) { // Se ancora non è stato confermato:
|
||||
let update = {
|
||||
$inc: {
|
||||
bookedQtyConfirmed: order.quantity,
|
||||
}
|
||||
};
|
||||
await Product.findOneAndUpdate({ _id: order.idProduct }, update, { new: false });
|
||||
|
||||
update = {
|
||||
$inc: {
|
||||
bookedGASQtyOrdered: order.quantitypreordered,
|
||||
bookedGASQtyConfirmed: order.quantitypreordered,
|
||||
}
|
||||
};
|
||||
await Product.findOneAndUpdate({ _id: order.idProduct }, update, { new: false });
|
||||
@@ -613,6 +617,11 @@ module.exports.updateStockQtaPerCancellazioneOrdine = async function (idordersca
|
||||
}
|
||||
}
|
||||
|
||||
fieldstoUpdate = {
|
||||
...fieldstoUpdate,
|
||||
bookedQtyOrdered,
|
||||
}
|
||||
|
||||
update = {
|
||||
$inc: fieldstoUpdate,
|
||||
};
|
||||
@@ -627,10 +636,15 @@ module.exports.updateStockQtaPerCancellazioneOrdine = async function (idordersca
|
||||
...fieldstoUpdate,
|
||||
maxbookableGASQty: order.quantitypreordered,
|
||||
bookableGASBloccatiQty: -order.quantitypreordered,
|
||||
bookedGASQtyOrdered: -order.quantitypreordered,
|
||||
bookedGASQtyConfirmed: -order.quantitypreordered,
|
||||
}
|
||||
}
|
||||
|
||||
fieldstoUpdate = {
|
||||
...fieldstoUpdate,
|
||||
bookedGASQtyOrdered,
|
||||
}
|
||||
|
||||
update = {
|
||||
$inc: fieldstoUpdate,
|
||||
};
|
||||
@@ -649,7 +663,7 @@ module.exports.updateStockQtaPerCancellazioneOrdine = async function (idordersca
|
||||
|
||||
module.exports.updateCmd = async function (ordersCart, status, value, req, options) {
|
||||
|
||||
const usernameStore = options.usernameStore ?? null;
|
||||
const usernameStore = (options && options.usernameStore) ?? null;
|
||||
|
||||
let myOrderCart = await OrdersCart.findOne({ _id: ordersCart._id })
|
||||
.populate('items.order').lean();
|
||||
@@ -675,7 +689,7 @@ module.exports.updateCmd = async function (ordersCart, status, value, req, optio
|
||||
} else if (status === shared_consts.OrderStatus.PAYED) {
|
||||
|
||||
if (value) {
|
||||
await OrdersCart.addOrderToCash(id, usernameStore, req);
|
||||
await OrdersCart.addOrderToCash(id, usernameStore, req);
|
||||
}
|
||||
|
||||
ris = await OrdersCart.setPagatoById(value, myOrderCart);
|
||||
|
||||
Reference in New Issue
Block a user