Quando accedi al Circuito RIS Nazionale, ti imposta il Fido e QtaMax DOPPIA rispetto al tuo Circuito Locale
This commit is contained in:
@@ -80,6 +80,9 @@ const CircuitSchema = new Schema({
|
||||
totCircolante: {
|
||||
type: Number,
|
||||
},
|
||||
showAlways: {
|
||||
type: Boolean,
|
||||
},
|
||||
totTransato: {
|
||||
type: Number,
|
||||
},
|
||||
@@ -212,6 +215,10 @@ const CircuitSchema = new Schema({
|
||||
type: Number,
|
||||
default: 0,
|
||||
},
|
||||
showAlways: {
|
||||
type: Boolean,
|
||||
default: false,
|
||||
},
|
||||
status: {
|
||||
type: Number,
|
||||
default: 0,
|
||||
@@ -276,6 +283,7 @@ CircuitSchema.statics.getWhatToShow = function (idapp, username) {
|
||||
fido_scoperto_default_grp: 1,
|
||||
qta_max_default_grp: 1,
|
||||
deperimento: 1,
|
||||
showAlways: 1,
|
||||
transactionsEnabled: 1,
|
||||
status: 1,
|
||||
valuta_per_euro: 1,
|
||||
@@ -331,6 +339,7 @@ CircuitSchema.statics.getWhatToShow_Unknown = function (idapp, username) {
|
||||
longdescr: 1,
|
||||
regulation: 1,
|
||||
numMembers: 1,
|
||||
showAlways: 1,
|
||||
systemUserId: 1,
|
||||
founderUserId: 1,
|
||||
nome_valuta: 1,
|
||||
@@ -936,6 +945,7 @@ CircuitSchema.statics.createCircuitIfNotExist = async function (req, idapp, prov
|
||||
photos: [],
|
||||
color: '#ff5500',
|
||||
deperimento: false,
|
||||
showAlways: false,
|
||||
transactionsEnabled: true, // Abilita cmq il circuito dall'inizio
|
||||
status: shared_consts.CIRCUIT_STATUS.FASE1_CREAZIONE_GRUPPO,
|
||||
symbol: 'RIS',
|
||||
@@ -1031,7 +1041,7 @@ CircuitSchema.statics.getListCircuitsByUsername = async function (idapp, usernam
|
||||
const useraccounts = await Account.getUserAccounts(idapp, username);
|
||||
const groupsaccounts = await Account.getGroupAccounts(idapp, groupname);
|
||||
|
||||
|
||||
|
||||
|
||||
for (let account of useraccounts) {
|
||||
if (myuser.profile.mycircuits.find((rec) => (rec.circuitname === account.circuit.name))) {
|
||||
@@ -1092,16 +1102,56 @@ CircuitSchema.statics.setFido = async function (idapp, username, circuitName, gr
|
||||
mycircuit = await Circuit.findOne({ idapp, name: circuitName });
|
||||
if (mycircuit) {
|
||||
const circuitId = mycircuit._id;
|
||||
let account = null;
|
||||
let fido = 0;
|
||||
let qtamax = 0;
|
||||
|
||||
const account = await Account.getAccountByUsernameAndCircuitId(idapp, username, circuitId, true, true, groupname, '');
|
||||
if (account) {
|
||||
let fido = 0;
|
||||
if (mycircuit.showAlways) {
|
||||
|
||||
const { User } = require('../models/user');
|
||||
|
||||
const myuser = await User.getUserByUsername(idapp, username);
|
||||
|
||||
// Se è il circuito Nazionale, allora prende i valori dal proprio Circuito Locale:
|
||||
const accountsuser = await Account.getUserAccounts(idapp, username);
|
||||
if (accountsuser) {
|
||||
// Se lo trovo della mia provincia, prendo quello
|
||||
account = accountsuser.find((account) => account.circuit.strProv === myuser.profile.resid_province)
|
||||
if (!account && accountsuser.length > 0) {
|
||||
// Se non lo trovo, prendo il primo in cui sono entrato !
|
||||
account = accountsuser[0];
|
||||
}
|
||||
if (account && account.circuit) {
|
||||
if (groupname) {
|
||||
qtamax = account.circuit.qta_max_default_grp * shared_consts.CIRCUIT_CFG.MULT_FIDO_GROUP;
|
||||
fido = account.circuit.fido_scoperto_default_grp * shared_consts.CIRCUIT_CFG.MULT_FIDO_GROUP;
|
||||
} else {
|
||||
qtamax = account.circuit.qta_max_default * shared_consts.CIRCUIT_CFG.MULT_FIDO_USER;
|
||||
fido = account.circuit.fido_scoperto_default * shared_consts.CIRCUIT_CFG.MULT_FIDO_USER;
|
||||
}
|
||||
}
|
||||
} else {
|
||||
// Se non ho Circuiti locali, non applico il Fido !
|
||||
return false;
|
||||
}
|
||||
|
||||
} else {
|
||||
account = await Account.getAccountByUsernameAndCircuitId(idapp, username, circuitId, true, true, groupname, '');
|
||||
if (groupname)
|
||||
fido = mycircuit.fido_scoperto_default_grp;
|
||||
else
|
||||
fido = mycircuit.fido_scoperto_default;
|
||||
}
|
||||
|
||||
return await Account.updateFido(idapp, username, groupname, circuitId, fido);
|
||||
if (account) {
|
||||
if (qtamax > 0) {
|
||||
await Account.updateQtaMax(idapp, username, groupname, circuitId, qtamax);
|
||||
}
|
||||
|
||||
const ris = await Account.updateFido(idapp, username, groupname, circuitId, fido);
|
||||
if (ris) {
|
||||
return { qta_maxConcessa: qtamax, fidoConcesso: fido };
|
||||
}
|
||||
}
|
||||
}
|
||||
return false;
|
||||
|
||||
Reference in New Issue
Block a user