diff --git a/logtrans.txt b/logtrans.txt
index 52a9990..4a186f1 100644
--- a/logtrans.txt
+++ b/logtrans.txt
@@ -140,4 +140,16 @@ piuchebuono: 1124.7799999999997 €]
Ven 16/02 ORE 14:05: [Euro]: Inviate Monete da Loabati a piuchebuono 6 € [causale: Pagato Ordine n.174]
Saldi:
Loabati: -24.6 €]
-piuchebuono: 1130.7799999999997 €]
\ No newline at end of file
+piuchebuono: 1130.7799999999997 €]
+Sab 17/02 ORE 14:04: [Circuito RIS Bologna]: Inviate Monete da paoloar77 a SuryaArena 5 RIS [causale: ]
+Saldi:
+paoloar77: 31 RIS]
+SuryaArena: 5 RIS]
+Sab 17/02 ORE 14:10: [Circuito RIS Bologna]: Inviate Monete da SuryaArena a paoloar77 4 RIS [causale: Per Paolo]
+Saldi:
+SuryaArena: 1 RIS]
+paoloar77: 35 RIS]
+Sab 17/02 ORE 14:11: [Circuito RIS Bologna]: Inviate Monete da paoloar77 a SuryaArena 6 RIS [causale: Per Surya]
+Saldi:
+paoloar77: 29 RIS]
+SuryaArena: 7 RIS]
\ No newline at end of file
diff --git a/src/server/models/account.js b/src/server/models/account.js
index ef26a2b..56deab9 100755
--- a/src/server/models/account.js
+++ b/src/server/models/account.js
@@ -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;
diff --git a/src/server/models/circuit.js b/src/server/models/circuit.js
index 4698578..129880d 100755
--- a/src/server/models/circuit.js
+++ b/src/server/models/circuit.js
@@ -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);
}
diff --git a/src/server/models/orderscart.js b/src/server/models/orderscart.js
index fd769a0..6ba6f63 100755
--- a/src/server/models/orderscart.js
+++ b/src/server/models/orderscart.js
@@ -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 : '') + '
Totale = ' + ord.order.TotalPriceProduct + '€';
+ msg += '✅ [' + qtystr + '] ' + ord.order.product.productInfo.name + ' a ' + ord.order.price + '€ ' + (ord.order.after_price ? ord.order.after_price : '') + '
Totale = ' + ord.order.TotalPriceProduct.toFixed(2) + '€';
}
msg += '
';
@@ -1156,7 +1156,7 @@ module.exports.getmsgorderTelegram = async function (ordersCart) {
let totqta = ordersCart.totalQty + ordersCart.totalQtyPreordered;
msg += '
Totale Prodotti: ' + totqta;
- msg += '
Totale Ordine: ' + ordersCart.totalPrice + ' € 💰';
+ msg += '
Totale Ordine: ' + ordersCart.totalPrice.toFixed(2) + ' € 💰';
diff --git a/src/server/router/users_router.js b/src/server/router/users_router.js
index d983f2d..59faabc 100755
--- a/src/server/router/users_router.js
+++ b/src/server/router/users_router.js
@@ -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: [
diff --git a/src/server/tools/general.js b/src/server/tools/general.js
index ff443f0..9c828ad 100755
--- a/src/server/tools/general.js
+++ b/src/server/tools/general.js
@@ -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)