aggio2
This commit is contained in:
@@ -1161,62 +1161,66 @@ CircuitSchema.statics.SetDefMinMaxCollettivi = async function (idapp, valmin, va
|
||||
|
||||
CircuitSchema.statics.setFido = async function (idapp, username, circuitName, groupname) {
|
||||
|
||||
mycircuit = await Circuit.findOne({ idapp, name: circuitName }).lean();
|
||||
if (mycircuit) {
|
||||
const circuitId = mycircuit._id;
|
||||
let account = null;
|
||||
let fido = 0;
|
||||
let qtamax = 0;
|
||||
try {
|
||||
mycircuit = await Circuit.findOne({ idapp, name: circuitName }).lean();
|
||||
if (mycircuit) {
|
||||
const circuitId = mycircuit._id;
|
||||
let account = null;
|
||||
let fido = 0;
|
||||
let qtamax = 0;
|
||||
|
||||
if (mycircuit.showAlways) {
|
||||
if (mycircuit.showAlways) {
|
||||
|
||||
const { User } = require('../models/user');
|
||||
const { User } = require('../models/user');
|
||||
|
||||
const myuser = await User.getUserByUsername(idapp, username);
|
||||
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 && ((account.circuit.card === myuser.profile.resid_card) || !myuser.profile.resid_card))
|
||||
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;
|
||||
// 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 && ((account.circuit.card === myuser.profile.resid_card) || !myuser.profile.resid_card))
|
||||
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 null;
|
||||
}
|
||||
|
||||
} else {
|
||||
// Se non ho Circuiti locali, non applico il Fido !
|
||||
return false;
|
||||
account = await Account.getAccountByUsernameAndCircuitId(idapp, username, circuitId, true, true, groupname, '');
|
||||
if (groupname)
|
||||
fido = mycircuit.fido_scoperto_default_grp;
|
||||
else
|
||||
fido = mycircuit.fido_scoperto_default;
|
||||
}
|
||||
|
||||
} 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;
|
||||
}
|
||||
if (account) {
|
||||
if (qtamax > 0) {
|
||||
await Account.updateQtaMax(idapp, username, groupname, circuitId, qtamax);
|
||||
}
|
||||
|
||||
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 };
|
||||
const ris = await Account.updateFido(idapp, username, groupname, circuitId, fido);
|
||||
if (ris) {
|
||||
return { qta_maxConcessa: qtamax, fidoConcesso: fido };
|
||||
}
|
||||
}
|
||||
}
|
||||
} catch (e) {
|
||||
console.error('Err:', e);
|
||||
}
|
||||
return false;
|
||||
return null;
|
||||
};
|
||||
|
||||
const Circuit = mongoose.model('Circuit', CircuitSchema);
|
||||
|
||||
Reference in New Issue
Block a user