addtocash using sendcoins Circuit
This commit is contained in:
@@ -105,7 +105,6 @@ module.exports.createMovementCashByOrdersCart = async function (ordersCart, user
|
||||
fromUsername: ordersCart.user.username,
|
||||
toUsername: usernameStore,
|
||||
causale: 'Pagato Ordine n.' + ordersCart.numorder,
|
||||
date_payment: new Date(),
|
||||
price: ordersCart.totalPrice,
|
||||
internal,
|
||||
}
|
||||
|
||||
@@ -708,7 +708,7 @@ CircuitSchema.statics.sendCoins = async function (onlycheck, idapp, usernameOrig
|
||||
if (!onlycheck) {
|
||||
// Add a Transaction !
|
||||
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) {
|
||||
@@ -1225,6 +1225,26 @@ CircuitSchema.statics.setFido = async function (idapp, username, circuitName, gr
|
||||
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);
|
||||
|
||||
Circuit.createIndexes((err) => {
|
||||
|
||||
@@ -36,6 +36,7 @@ const MovementSchema = new Schema({
|
||||
accountToId: {
|
||||
type: String,
|
||||
},
|
||||
idOrdersCart: { type: Schema.Types.ObjectId, ref: 'OrdersCart' },
|
||||
causal_table: {
|
||||
type: String,
|
||||
},
|
||||
@@ -56,6 +57,10 @@ const MovementSchema = new Schema({
|
||||
expiringDate: {
|
||||
type: Date,
|
||||
},
|
||||
confirmed: {
|
||||
type: Boolean,
|
||||
default: false,
|
||||
},
|
||||
});
|
||||
|
||||
MovementSchema.statics.findAllIdApp = async function (idapp) {
|
||||
@@ -90,7 +95,7 @@ MovementSchema.statics.executeQueryTable = function (idapp, 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 {
|
||||
// Only positive values
|
||||
@@ -102,6 +107,7 @@ MovementSchema.statics.addMov = async function (idapp, accountFromIdTable, accou
|
||||
transactionDate: new Date(),
|
||||
accountFromId: accountFromIdTable._id,
|
||||
accountToId: accountToIdTable._id,
|
||||
idOrdersCart: idOrdersCart._id ?? null,
|
||||
amount,
|
||||
causal,
|
||||
residual: 0,
|
||||
|
||||
@@ -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);
|
||||
|
||||
@@ -84,6 +84,10 @@ const productSchema = new Schema({
|
||||
type: Number,
|
||||
default: 0,
|
||||
},
|
||||
bookedQtyOrdered: { // Quantità Prenotate ordinate (in Lavorazione)
|
||||
type: Number,
|
||||
default: 0,
|
||||
},
|
||||
bookedQtyConfirmed: { // Quantità Prenotate Confermate Totali
|
||||
type: Number,
|
||||
default: 0,
|
||||
@@ -98,7 +102,11 @@ const productSchema = new Schema({
|
||||
type: Number,
|
||||
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,
|
||||
default: 0,
|
||||
},
|
||||
@@ -548,6 +556,7 @@ module.exports.singlerecconvert_AfterImport_AndSave = async function (idapp, pro
|
||||
maxBookableSinglePersQty: 0,
|
||||
bookedGASQtyOrdered: 0,
|
||||
bookableGASBloccatiQty: 0,
|
||||
bookedGASQtyConfirmed: 0,
|
||||
// qtyToReachForGas: 0,
|
||||
// maxbookableGASQty: 0,
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user