addtocash using sendcoins Circuit
This commit is contained in:
@@ -105,7 +105,6 @@ module.exports.createMovementCashByOrdersCart = async function (ordersCart, user
|
|||||||
fromUsername: ordersCart.user.username,
|
fromUsername: ordersCart.user.username,
|
||||||
toUsername: usernameStore,
|
toUsername: usernameStore,
|
||||||
causale: 'Pagato Ordine n.' + ordersCart.numorder,
|
causale: 'Pagato Ordine n.' + ordersCart.numorder,
|
||||||
date_payment: new Date(),
|
|
||||||
price: ordersCart.totalPrice,
|
price: ordersCart.totalPrice,
|
||||||
internal,
|
internal,
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -708,7 +708,7 @@ CircuitSchema.statics.sendCoins = async function (onlycheck, idapp, usernameOrig
|
|||||||
if (!onlycheck) {
|
if (!onlycheck) {
|
||||||
// Add a Transaction !
|
// Add a Transaction !
|
||||||
if (ris.cansend) {
|
if (ris.cansend) {
|
||||||
ris.rec = await Movement.addMov(idapp, accountorigTable, accountdestTable, myqty, extrarec.causal, extrarec.notifId);
|
ris.rec = await Movement.addMov(idapp, accountorigTable, accountdestTable, myqty, extrarec.causal, extrarec.notifId, null);
|
||||||
}
|
}
|
||||||
|
|
||||||
if (ris.cansend && ris.rec) {
|
if (ris.cansend && ris.rec) {
|
||||||
@@ -1225,6 +1225,26 @@ CircuitSchema.statics.setFido = async function (idapp, username, circuitName, gr
|
|||||||
return null;
|
return null;
|
||||||
};
|
};
|
||||||
|
|
||||||
|
CircuitSchema.statics.addMovementByOrdersCart = async function (idapp, ordersCart, usernameDest, groupDest) {
|
||||||
|
|
||||||
|
const { User } = require('../models/user');
|
||||||
|
|
||||||
|
let extrarec = {
|
||||||
|
causale: 'Pagato Ordine n.' + ordersCart.numorder,
|
||||||
|
circuitname: 'Euro',
|
||||||
|
idOrdersCart: ordersCart._id,
|
||||||
|
qty: ordersCart.totalPrice,
|
||||||
|
dest: usernameDest,
|
||||||
|
groupdest: groupDest,
|
||||||
|
contoComDest: '',
|
||||||
|
};
|
||||||
|
|
||||||
|
const usernameOrig = await User.getUsernameById(idapp, userId);
|
||||||
|
|
||||||
|
return this.sendCoins(false, idapp, usernameOrig, extrarec);
|
||||||
|
|
||||||
|
};
|
||||||
|
|
||||||
const Circuit = mongoose.model('Circuit', CircuitSchema);
|
const Circuit = mongoose.model('Circuit', CircuitSchema);
|
||||||
|
|
||||||
Circuit.createIndexes((err) => {
|
Circuit.createIndexes((err) => {
|
||||||
|
|||||||
@@ -36,6 +36,7 @@ const MovementSchema = new Schema({
|
|||||||
accountToId: {
|
accountToId: {
|
||||||
type: String,
|
type: String,
|
||||||
},
|
},
|
||||||
|
idOrdersCart: { type: Schema.Types.ObjectId, ref: 'OrdersCart' },
|
||||||
causal_table: {
|
causal_table: {
|
||||||
type: String,
|
type: String,
|
||||||
},
|
},
|
||||||
@@ -56,6 +57,10 @@ const MovementSchema = new Schema({
|
|||||||
expiringDate: {
|
expiringDate: {
|
||||||
type: Date,
|
type: Date,
|
||||||
},
|
},
|
||||||
|
confirmed: {
|
||||||
|
type: Boolean,
|
||||||
|
default: false,
|
||||||
|
},
|
||||||
});
|
});
|
||||||
|
|
||||||
MovementSchema.statics.findAllIdApp = async function (idapp) {
|
MovementSchema.statics.findAllIdApp = async function (idapp) {
|
||||||
@@ -90,7 +95,7 @@ MovementSchema.statics.executeQueryTable = function (idapp, params) {
|
|||||||
return tools.executeQueryTable(this, 0, params);
|
return tools.executeQueryTable(this, 0, params);
|
||||||
};
|
};
|
||||||
|
|
||||||
MovementSchema.statics.addMov = async function (idapp, accountFromIdTable, accountToIdTable, amount, causal, notifId) {
|
MovementSchema.statics.addMov = async function (idapp, accountFromIdTable, accountToIdTable, amount, causal, notifId, idOrdersCart) {
|
||||||
|
|
||||||
try {
|
try {
|
||||||
// Only positive values
|
// Only positive values
|
||||||
@@ -102,6 +107,7 @@ MovementSchema.statics.addMov = async function (idapp, accountFromIdTable, accou
|
|||||||
transactionDate: new Date(),
|
transactionDate: new Date(),
|
||||||
accountFromId: accountFromIdTable._id,
|
accountFromId: accountFromIdTable._id,
|
||||||
accountToId: accountToIdTable._id,
|
accountToId: accountToIdTable._id,
|
||||||
|
idOrdersCart: idOrdersCart._id ?? null,
|
||||||
amount,
|
amount,
|
||||||
causal,
|
causal,
|
||||||
residual: 0,
|
residual: 0,
|
||||||
|
|||||||
@@ -13,6 +13,8 @@ const Product = require('../models/product');
|
|||||||
const Cash = require('../models/cash');
|
const Cash = require('../models/cash');
|
||||||
const ProductInfo = require('../models/productInfo');
|
const ProductInfo = require('../models/productInfo');
|
||||||
|
|
||||||
|
const { Circuit } = require('../models/circuit');
|
||||||
|
|
||||||
const tools = require('../tools/general');
|
const tools = require('../tools/general');
|
||||||
|
|
||||||
const { ObjectID } = require('mongodb');
|
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 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) {
|
} catch (e) {
|
||||||
console.error('Err', 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) {
|
module.exports.updateStockQtaDalMagazzinoOrdineConfermato = async function (idorderscart) {
|
||||||
|
|
||||||
try {
|
try {
|
||||||
@@ -507,40 +544,7 @@ module.exports.updateStockQtaDalMagazzinoOrdineConfermato = async function (idor
|
|||||||
$inc: {
|
$inc: {
|
||||||
maxbookableGASQty: -order.quantitypreordered,
|
maxbookableGASQty: -order.quantitypreordered,
|
||||||
bookableGASBloccatiQty: order.quantitypreordered,
|
bookableGASBloccatiQty: order.quantitypreordered,
|
||||||
bookedGASQtyOrdered: order.quantitypreordered,
|
bookedGASQtyConfirmed: 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,
|
|
||||||
}
|
}
|
||||||
};
|
};
|
||||||
await Product.findOneAndUpdate({ _id: order.idProduct }, update, { new: false });
|
await Product.findOneAndUpdate({ _id: order.idProduct }, update, { new: false });
|
||||||
@@ -613,6 +617,11 @@ module.exports.updateStockQtaPerCancellazioneOrdine = async function (idordersca
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
fieldstoUpdate = {
|
||||||
|
...fieldstoUpdate,
|
||||||
|
bookedQtyOrdered,
|
||||||
|
}
|
||||||
|
|
||||||
update = {
|
update = {
|
||||||
$inc: fieldstoUpdate,
|
$inc: fieldstoUpdate,
|
||||||
};
|
};
|
||||||
@@ -627,10 +636,15 @@ module.exports.updateStockQtaPerCancellazioneOrdine = async function (idordersca
|
|||||||
...fieldstoUpdate,
|
...fieldstoUpdate,
|
||||||
maxbookableGASQty: order.quantitypreordered,
|
maxbookableGASQty: order.quantitypreordered,
|
||||||
bookableGASBloccatiQty: -order.quantitypreordered,
|
bookableGASBloccatiQty: -order.quantitypreordered,
|
||||||
bookedGASQtyOrdered: -order.quantitypreordered,
|
bookedGASQtyConfirmed: -order.quantitypreordered,
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
fieldstoUpdate = {
|
||||||
|
...fieldstoUpdate,
|
||||||
|
bookedGASQtyOrdered,
|
||||||
|
}
|
||||||
|
|
||||||
update = {
|
update = {
|
||||||
$inc: fieldstoUpdate,
|
$inc: fieldstoUpdate,
|
||||||
};
|
};
|
||||||
@@ -649,7 +663,7 @@ module.exports.updateStockQtaPerCancellazioneOrdine = async function (idordersca
|
|||||||
|
|
||||||
module.exports.updateCmd = async function (ordersCart, status, value, req, options) {
|
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 })
|
let myOrderCart = await OrdersCart.findOne({ _id: ordersCart._id })
|
||||||
.populate('items.order').lean();
|
.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) {
|
} else if (status === shared_consts.OrderStatus.PAYED) {
|
||||||
|
|
||||||
if (value) {
|
if (value) {
|
||||||
await OrdersCart.addOrderToCash(id, usernameStore, req);
|
await OrdersCart.addOrderToCash(id, usernameStore, req);
|
||||||
}
|
}
|
||||||
|
|
||||||
ris = await OrdersCart.setPagatoById(value, myOrderCart);
|
ris = await OrdersCart.setPagatoById(value, myOrderCart);
|
||||||
|
|||||||
@@ -84,6 +84,10 @@ const productSchema = new Schema({
|
|||||||
type: Number,
|
type: Number,
|
||||||
default: 0,
|
default: 0,
|
||||||
},
|
},
|
||||||
|
bookedQtyOrdered: { // Quantità Prenotate ordinate (in Lavorazione)
|
||||||
|
type: Number,
|
||||||
|
default: 0,
|
||||||
|
},
|
||||||
bookedQtyConfirmed: { // Quantità Prenotate Confermate Totali
|
bookedQtyConfirmed: { // Quantità Prenotate Confermate Totali
|
||||||
type: Number,
|
type: Number,
|
||||||
default: 0,
|
default: 0,
|
||||||
@@ -98,7 +102,11 @@ const productSchema = new Schema({
|
|||||||
type: Number,
|
type: Number,
|
||||||
default: 0,
|
default: 0,
|
||||||
},
|
},
|
||||||
bookedGASQtyOrdered: { // Quantità Ordine GAS Prenotate Confermate Totali
|
bookedGASQtyOrdered: { // Quantità Ordine GAS Prenotate Totali
|
||||||
|
type: Number,
|
||||||
|
default: 0,
|
||||||
|
},
|
||||||
|
bookedGASQtyConfirmed: { // Quantità Ordine GAS Confermate Totali
|
||||||
type: Number,
|
type: Number,
|
||||||
default: 0,
|
default: 0,
|
||||||
},
|
},
|
||||||
@@ -548,6 +556,7 @@ module.exports.singlerecconvert_AfterImport_AndSave = async function (idapp, pro
|
|||||||
maxBookableSinglePersQty: 0,
|
maxBookableSinglePersQty: 0,
|
||||||
bookedGASQtyOrdered: 0,
|
bookedGASQtyOrdered: 0,
|
||||||
bookableGASBloccatiQty: 0,
|
bookableGASBloccatiQty: 0,
|
||||||
|
bookedGASQtyConfirmed: 0,
|
||||||
// qtyToReachForGas: 0,
|
// qtyToReachForGas: 0,
|
||||||
// maxbookableGASQty: 0,
|
// maxbookableGASQty: 0,
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -17,6 +17,7 @@ const _ = require('lodash');
|
|||||||
const Product = require('../models/product');
|
const Product = require('../models/product');
|
||||||
const Order = require('../models/order');
|
const Order = require('../models/order');
|
||||||
const Variant = require('../models/variant');
|
const Variant = require('../models/variant');
|
||||||
|
const { User } = require('../models/user');
|
||||||
|
|
||||||
/*const Department = require('../models/Department')
|
/*const Department = require('../models/Department')
|
||||||
const Category = require('../models/Category')
|
const Category = require('../models/Category')
|
||||||
@@ -255,6 +256,8 @@ router.post('/:userId/createorderscart', authenticate, async function (req, res,
|
|||||||
let numorder = await OrdersCart.getLastNumOrder(idapp);
|
let numorder = await OrdersCart.getLastNumOrder(idapp);
|
||||||
let numord_pers = await OrdersCart.getLastNumOrdPers(userId, idapp);
|
let numord_pers = await OrdersCart.getLastNumOrdPers(userId, idapp);
|
||||||
|
|
||||||
|
const userDest = await User.getUserById(idapp, userId);
|
||||||
|
|
||||||
// Esiste l'ordine ?
|
// Esiste l'ordine ?
|
||||||
let myorderCart = await OrdersCart.getRecCartByUserId(userId, idapp, numorder);
|
let myorderCart = await OrdersCart.getRecCartByUserId(userId, idapp, numorder);
|
||||||
if (!myorderCart) {
|
if (!myorderCart) {
|
||||||
@@ -306,7 +309,7 @@ router.post('/:userId/createorderscart', authenticate, async function (req, res,
|
|||||||
await OrdersCart.updateCmd(orders[0], status, true, req, options);
|
await OrdersCart.updateCmd(orders[0], status, true, req, options);
|
||||||
|
|
||||||
// Invia la email dell'Ordine
|
// Invia la email dell'Ordine
|
||||||
sendemail.sendEmail_OrderProduct(user.lang, idapp, orders[0], user)
|
sendemail.sendEmail_OrderProduct(userDest.lang, idapp, orders[0], userDest)
|
||||||
.then(async (ris) => {
|
.then(async (ris) => {
|
||||||
myorderCart = await OrdersCart.findById(idordercart).lean();
|
myorderCart = await OrdersCart.findById(idordercart).lean();
|
||||||
return res.send({
|
return res.send({
|
||||||
@@ -356,6 +359,8 @@ router.post('/:userId/ordercartstatus', authenticate, async function (req, res,
|
|||||||
|
|
||||||
const { User } = require('../models/user');
|
const { User } = require('../models/user');
|
||||||
|
|
||||||
|
const userDest = await User.getUserById(userId);
|
||||||
|
|
||||||
let orderCart = await OrdersCart.findOne({ idapp, _id: order_id }).lean();
|
let orderCart = await OrdersCart.findOne({ idapp, _id: order_id }).lean();
|
||||||
|
|
||||||
if ((userId !== String(req.user._id)) && !User.isManager(req.user.perm)) {
|
if ((userId !== String(req.user._id)) && !User.isManager(req.user.perm)) {
|
||||||
@@ -388,7 +393,7 @@ router.post('/:userId/ordercartstatus', authenticate, async function (req, res,
|
|||||||
}
|
}
|
||||||
|
|
||||||
if (ordertype !== '') {
|
if (ordertype !== '') {
|
||||||
sendemail.sendEmail_Order(user.lang, idapp, orderCart, user, ordertype, status)
|
sendemail.sendEmail_Order(userDest.lang, idapp, orderCart, userDest, ordertype, status)
|
||||||
.then((ris) => {
|
.then((ris) => {
|
||||||
|
|
||||||
})
|
})
|
||||||
|
|||||||
Reference in New Issue
Block a user