- Fix: saldo pendenze e totali Transati.

This commit is contained in:
Surya Paolo
2024-02-17 14:13:39 +01:00
parent e6fd8e1fed
commit 8c471c0e81
6 changed files with 105 additions and 20 deletions

View File

@@ -141,3 +141,15 @@ Ven 16/02 ORE 14:05: [<b>Euro</b>]: Inviate Monete da Loabati a piuchebuono 6
Saldi:
Loabati: -24.6 €]
piuchebuono: 1130.7799999999997 €]
Sab 17/02 ORE 14:04: [<b>Circuito RIS Bologna</b>]: Inviate Monete da paoloar77 a SuryaArena 5 RIS [causale: ]
Saldi:
paoloar77: 31 RIS]
SuryaArena: 5 RIS]
Sab 17/02 ORE 14:10: [<b>Circuito RIS Bologna</b>]: Inviate Monete da SuryaArena a paoloar77 4 RIS [causale: Per Paolo]
Saldi:
SuryaArena: 1 RIS]
paoloar77: 35 RIS]
Sab 17/02 ORE 14:11: [<b>Circuito RIS Bologna</b>]: Inviate Monete da paoloar77 a SuryaArena 6 RIS [causale: Per Surya]
Saldi:
paoloar77: 29 RIS]
SuryaArena: 7 RIS]

View File

@@ -252,8 +252,8 @@ AccountSchema.statics.addtoSaldo = async function (myaccount, amount, mitt) {
$set: myaccountupdate
});
await myaccount.calcPending(mitt);
// Calcola Saldo Pendente !
await myaccount.calcPending(true);
return ris;

View File

@@ -1230,19 +1230,27 @@ CircuitSchema.statics.setFido = async function (idapp, username, circuitName, gr
return null;
};
CircuitSchema.statics.CheckTransazioniCircuiti = async function () {
CircuitSchema.statics.CheckTransazioniCircuiti = async function (correggi) {
const { User } = require('../models/user');
const { MyGroup } = require('../models/mygroup');
const { SendNotif } = require('../models/sendnotif');
try {
console.log('--------- INIZIO CONTROLLO CheckTransazioniCircuiti -----------')
console.log('--------- INIZIO CONTROLLO CheckTransazioniCircuiti -----------');
if (correggi)
console.log('CORREZIONE !');
else
console.log('SOLO VERIFICA');
let numtransazionitot = 0;
const arrcircuits = await Circuit.find({ idapp }).lean();
for (const circuit of arrcircuits) {
let strusersnotinaCircuit = '';
let strusersnotExist = '';
numtransazionitot = 0;
let numtransazionitot = 0;
let qta = 0;
let mystr = ''
@@ -1285,8 +1293,11 @@ CircuitSchema.statics.CheckTransazioniCircuiti = async function () {
let arrgroups_byprofile = risgroups ? risgroups.map(group => group.groupname) : [];
let arrusers_byaccounts = [];
let ind = 0
let stracc = '';
for (const account of accounts) {
let aggiorna = false;
if (account.username && !arrusers_byaccounts.includes(account.username)) {
arrusers_byaccounts.push(account.username);
@@ -1310,34 +1321,86 @@ CircuitSchema.statics.CheckTransazioniCircuiti = async function () {
$group: {
_id: null,
numtransactions: { $sum: 1 },
totTransato: { $sum: { $abs: "$saldo" } }
totTransato: { $sum: { $abs: "$amount" } },
saldo: {
$sum: {
$cond: [
{ $eq: ["$accountToId", account._id] },
"$amount",
{
$cond: [
{ $eq: ["$accountFromId", account._id] },
{ $multiply: ["$amount", -1] },
0
]
}
]
}
}
}
}
]);
let numtransactions = result && result.length > 0 ? result[0].numtransactions : 0;
let totTransato = result && result.length > 0 ? result[0].totTransato : 0;
let saldo = result && result.length > 0 ? result[0].saldo : 0;
// TRANSAZIONI PENDENTI:
let saldo_pend = 0;
let pendingtransactionsMittente = await SendNotif.getSumPendingTransactionsMittente(account.idapp, account.username, circuit.name, account.groupname);
if (pendingtransactionsMittente.length > 0) {
let saldopendingMitt = pendingtransactionsMittente.reduce((sum, rec) => sum + rec.extrarec.qty, 0);
// transatopending = pendingtransactionsMittente.reduce((sum, rec) => sum + Math.abs(rec.extrarec.qty), 0);
saldo_pend = saldo - saldopendingMitt;
} else {
saldo_pend = saldo;
}
let strtemp = '';
if (numtransactions > 0) {
await Account.findOneAndUpdate({ _id: account._id }, { $set: { numtransactions } })
if (correggi)
await Account.findOneAndUpdate({ _id: account._id }, { $set: { numtransactions } })
}
if (saldo !== account.saldo) {
aggiorna = true;
strtemp += ' SALDO DIFFERENTE ! => ' + '\nPRIMA: ' + account.saldo + '\nDOPO: ' + saldo;
if (correggi)
await Account.findOneAndUpdate({ _id: account._id }, { $set: { saldo } })
}
if (account.saldo_pend === undefined) {
await Account.findOneAndUpdate({ _id: account._id }, { $set: { saldo_pend: 0 } })
}
if (saldo_pend !== account.saldo_pend) {
aggiorna = true;
strtemp += ' SALDO_PENDENTE DIFF. ! => ' + '\nPRIMA: ' + account.saldo_pend + '\nDOPO: ' + saldo_pend;
if (correggi)
await Account.findOneAndUpdate({ _id: account._id }, { $set: { saldo_pend } })
}
if (!account.totTransato || (totTransato !== account.totTransato)) {
await Account.findOneAndUpdate({ _id: account._id }, { $set: { totTransato } })
if (totTransato > account.totTransato || account.totTransato === undefined)
if (correggi)
await Account.findOneAndUpdate({ _id: account._id }, { $set: { totTransato } })
}
saldotot += account.saldo;
if (!account.totTransato)
mystr += 'TOTTRANSATO => ' + account.totTransato;
// if (account.totTransato === NaN || account.totTransato === undefined)
// stracc += ' TOTTRANSATO => ' + account.totTransato;
if (account.totTransato)
qta += account.totTransato;
if (account.numtransactions)
numtransazionitot += account.numtransactions;
// await account.calcPending();
}
if (aggiorna && strtemp) {
stracc += '\n ** Account ' + account.username + '\n' + strtemp;
}
// await account.calcPending();
ind++;
}
let numaccounts = accounts.length;
let esistecontocom = accounts.find((rec) => (rec.hasOwnProperty('contocom') && rec.contocom !== ''));
@@ -1356,18 +1419,26 @@ CircuitSchema.statics.CheckTransazioniCircuiti = async function () {
saldotot = saldotot.toFixed(2);
mystr += ' numaccounts=' + numaccounts;
// mystr += ' numaccounts=' + numaccounts;
if (strusersnotinaCircuit)
mystr += ' Utenti non presenti nel Circuito ! => ' + strusersnotinaCircuit;
if (strusersnotExist)
mystr += ' Utenti non più esistenti ! => ' + strusersnotExist;
// Verifica se saldotot è uguale a ZERO
if (saldotot != 0) {
console.log('*** ATTENZIONE! ' + circuit.name + ' ha come somma un saldo di ' + saldotot, 'qta=' + qta, 'numtransazionitot', numtransazionitot, mystr);
mystr += '*** ATTENZIONE! ' + circuit.name + ' ha come somma un saldo di ' + saldotot + ' invece che ZERO';
} else {
if (numtransazionitot)
console.log(circuit.name + ' qta=', qta, 'numtransazionitot', numtransazionitot, mystr);
mystr += ' qta=' + qta + ' numtransazionitot ' + numtransazionitot;
}
if (mystr || stracc) {
console.log('************************* ' + circuit.name + ':');
console.log(mystr);
if (stracc)
console.log(stracc);
}

View File

@@ -1148,7 +1148,7 @@ module.exports.getmsgorderTelegram = async function (ordersCart) {
if (ord.order.quantitypreordered > 0)
qtystr += ' Pre-Ordinati';
msg += '✅ [' + qtystr + '] ' + ord.order.product.productInfo.name + ' a ' + ord.order.price + '€ ' + (ord.order.after_price ? ord.order.after_price : '') + '<br>Totale = ' + ord.order.TotalPriceProduct + '€';
msg += '✅ [' + qtystr + '] ' + ord.order.product.productInfo.name + ' a ' + ord.order.price + '€ ' + (ord.order.after_price ? ord.order.after_price : '') + '<br>Totale = ' + ord.order.TotalPriceProduct.toFixed(2) + '€';
}
msg += '<br>';
@@ -1156,7 +1156,7 @@ module.exports.getmsgorderTelegram = async function (ordersCart) {
let totqta = ordersCart.totalQty + ordersCart.totalQtyPreordered;
msg += '<br>Totale Prodotti: ' + totqta;
msg += '<br>Totale Ordine: ' + ordersCart.totalPrice + ' € 💰';
msg += '<br>Totale Ordine: ' + ordersCart.totalPrice.toFixed(2) + ' € 💰';

View File

@@ -1250,7 +1250,9 @@ async function eseguiDbOp(idapp, mydata, locale, req, res) {
} else if (mydata.dbop === 'RemoveDeletedOrdersInOrderscart') {
await Order.RemoveDeletedOrdersInOrderscart();
} else if (mydata.dbop === 'CheckTransazioniCircuiti') {
await Circuit.CheckTransazioniCircuiti();
await Circuit.CheckTransazioniCircuiti(false);
} else if (mydata.dbop === 'CorreggiTransazioniCircuiti') {
await Circuit.CheckTransazioniCircuiti(true);
} else if (mydata.dbop === 'AbilitaNewsletterALL') {
await User.updateMany({
$or: [

View File

@@ -4081,7 +4081,7 @@ module.exports = {
msg = msg.replace('{name}', user.name ? user.name : user.username);
msg = msg.replace('{surname}', user.surname ? user.surname : '');
let out = myvar.replace('{urlunsubscribe_user}', this.getUnsubsribeUrl_User(user));
msg = msg.replace('{urlunsubscribe_user}', this.getUnsubsribeUrl_User(user));
msg = msg.replace('{aportador_solidario}', user.aportador_solidario ? user.aportador_solidario : '');
if (!!user.profile.link_payment)