aggiornamento scontistica, corretto errori
This commit is contained in:
@@ -4,7 +4,10 @@ module.exports = {
|
|||||||
name: "FreePlanetServerSide",
|
name: "FreePlanetServerSide",
|
||||||
script: "./src/server/server.js",
|
script: "./src/server/server.js",
|
||||||
ignore_watch : ["node_modules"],
|
ignore_watch : ["node_modules"],
|
||||||
|
interpreter: "/root/.nvm/versions/node/v16.19.0/bin/node",
|
||||||
watch: false,
|
watch: false,
|
||||||
|
//autorestart: true,
|
||||||
|
instances: 1,
|
||||||
env: {
|
env: {
|
||||||
"PORT": 3000,
|
"PORT": 3000,
|
||||||
"NODE_ENV": "development",
|
"NODE_ENV": "development",
|
||||||
@@ -17,9 +20,9 @@ module.exports = {
|
|||||||
"PORT": 3000,
|
"PORT": 3000,
|
||||||
"NODE_ENV": "production",
|
"NODE_ENV": "production",
|
||||||
},
|
},
|
||||||
log_file: "combined.outerr.log",
|
log_file: "logs/combined.outerr.log",
|
||||||
error_file: "err.log",
|
error_file: "logs/err.log",
|
||||||
out_file: "out.log",
|
out_file: "logs/out.log",
|
||||||
merge_logs: true,
|
merge_logs: true,
|
||||||
log_date_format: "YYYY-MM-DD HH:mm:ss.SSSS Z"
|
log_date_format: "YYYY-MM-DD HH:mm:ss.SSSS Z"
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -14,7 +14,7 @@
|
|||||||
"test-watch": "nodemon --exec 'npm test'"
|
"test-watch": "nodemon --exec 'npm test'"
|
||||||
},
|
},
|
||||||
"engines": {
|
"engines": {
|
||||||
"node": "^18.17.0"
|
"node": "^18.19.0"
|
||||||
},
|
},
|
||||||
"author": "Paolo Arena",
|
"author": "Paolo Arena",
|
||||||
"license": "MIT",
|
"license": "MIT",
|
||||||
|
|||||||
@@ -25,6 +25,7 @@ const orderSchema = new Schema({
|
|||||||
idProduct: { type: Schema.Types.ObjectId, ref: 'Product' },
|
idProduct: { type: Schema.Types.ObjectId, ref: 'Product' },
|
||||||
idProducer: { type: Schema.Types.ObjectId, ref: 'Producer' },
|
idProducer: { type: Schema.Types.ObjectId, ref: 'Producer' },
|
||||||
idStorehouse: { type: Schema.Types.ObjectId, ref: 'StoreHouse' },
|
idStorehouse: { type: Schema.Types.ObjectId, ref: 'StoreHouse' },
|
||||||
|
idScontisticas: [{ type: Schema.Types.ObjectId, ref: 'Scontistica' }],
|
||||||
idProvider: { type: Schema.Types.ObjectId, ref: 'Provider' },
|
idProvider: { type: Schema.Types.ObjectId, ref: 'Provider' },
|
||||||
price: {
|
price: {
|
||||||
type: Number
|
type: Number
|
||||||
@@ -167,13 +168,23 @@ module.exports.findAllIdApp = async function (idapp) {
|
|||||||
},
|
},
|
||||||
{
|
{
|
||||||
$unwind: {
|
$unwind: {
|
||||||
path: '$scontistica',
|
path: '$product',
|
||||||
preserveNullAndEmptyArrays: true,
|
preserveNullAndEmptyArrays: true,
|
||||||
},
|
},
|
||||||
},
|
},
|
||||||
{ $unwind: '$product' },
|
{
|
||||||
{ $unwind: '$producer' },
|
$unwind: {
|
||||||
{ $unwind: '$provider' },
|
path: '$producer',
|
||||||
|
preserveNullAndEmptyArrays: true,
|
||||||
|
},
|
||||||
|
},
|
||||||
|
{
|
||||||
|
$unwind: {
|
||||||
|
path: '$provider',
|
||||||
|
preserveNullAndEmptyArrays: true,
|
||||||
|
},
|
||||||
|
}
|
||||||
|
|
||||||
];
|
];
|
||||||
|
|
||||||
return await Order.aggregate(query)
|
return await Order.aggregate(query)
|
||||||
@@ -263,19 +274,33 @@ module.exports.getTotalOrderById = async function (id) {
|
|||||||
from: 'scontisticas',
|
from: 'scontisticas',
|
||||||
localField: 'idScontisticas',
|
localField: 'idScontisticas',
|
||||||
foreignField: '_id',
|
foreignField: '_id',
|
||||||
as: 'scontistica'
|
as: 'scontisticas'
|
||||||
}
|
}
|
||||||
},
|
},
|
||||||
{
|
{
|
||||||
$unwind: {
|
$unwind: {
|
||||||
path: '$scontistica',
|
path: '$product',
|
||||||
preserveNullAndEmptyArrays: true,
|
preserveNullAndEmptyArrays: true,
|
||||||
},
|
},
|
||||||
},
|
},
|
||||||
{ $unwind: '$product' },
|
{
|
||||||
{ $unwind: '$producer' },
|
$unwind: {
|
||||||
{ $unwind: '$storehouse' },
|
path: '$producer',
|
||||||
{ $unwind: '$provider' },
|
preserveNullAndEmptyArrays: true,
|
||||||
|
},
|
||||||
|
},
|
||||||
|
{
|
||||||
|
$unwind: {
|
||||||
|
path: '$storehouse',
|
||||||
|
preserveNullAndEmptyArrays: true,
|
||||||
|
},
|
||||||
|
},
|
||||||
|
{
|
||||||
|
$unwind: {
|
||||||
|
path: '$provider',
|
||||||
|
preserveNullAndEmptyArrays: true,
|
||||||
|
},
|
||||||
|
}
|
||||||
];
|
];
|
||||||
|
|
||||||
return await Order.aggregate(query);
|
return await Order.aggregate(query);
|
||||||
|
|||||||
@@ -223,6 +223,13 @@ module.exports.getOrdersCartByUserId = async function (uid, idapp, numorder) {
|
|||||||
model: 'Storehouse'
|
model: 'Storehouse'
|
||||||
},
|
},
|
||||||
})
|
})
|
||||||
|
.populate({
|
||||||
|
path: 'items.order',
|
||||||
|
populate: {
|
||||||
|
path: 'idScontisticas',
|
||||||
|
model: 'Scontistica'
|
||||||
|
},
|
||||||
|
})
|
||||||
.populate({
|
.populate({
|
||||||
path: 'userId',
|
path: 'userId',
|
||||||
model: 'User',
|
model: 'User',
|
||||||
@@ -237,13 +244,15 @@ module.exports.getOrdersCartByUserId = async function (uid, idapp, numorder) {
|
|||||||
if (item.order) {
|
if (item.order) {
|
||||||
try {
|
try {
|
||||||
item.order.product = item.order.idProduct;
|
item.order.product = item.order.idProduct;
|
||||||
item.order.idProduct = item.order.product._id;
|
item.order.idProduct = item.order.product ? item.order.product._id : '';
|
||||||
item.order.producer = item.order.idProducer;
|
item.order.producer = item.order.idProducer;
|
||||||
item.order.idProducer = item.order.producer._id;
|
item.order.idProducer = item.order.producer ? item.order.producer._id : '';
|
||||||
item.order.storehouse = item.order.idStorehouse;
|
item.order.storehouse = item.order.idStorehouse;
|
||||||
item.order.idStorehouse = item.order.storehouse._id;
|
item.order.idStorehouse = item.order.storehouse ? item.order.storehouse._id : '';
|
||||||
item.order.provider = item.order.idProvider;
|
item.order.provider = item.order.idProvider;
|
||||||
item.order.idProvider = item.order.provider._id;
|
item.order.idProvider = item.order.provider ? item.order.provider._id : '';
|
||||||
|
item.order.scontisticas = item.order.scontisticas;
|
||||||
|
item.order.idScontisticas = item.order.idScontisticas ? item.order.idScontisticas._id : '';
|
||||||
} catch (e) {
|
} catch (e) {
|
||||||
console.error('Err: ', e);
|
console.error('Err: ', e);
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -206,6 +206,9 @@ module.exports.findAllIdApp = async function (idapp, code, id) {
|
|||||||
query.push(myqueryadd);
|
query.push(myqueryadd);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// DA TOGLIEREE
|
||||||
|
// myfind = { ...myfind, code: '4012824406094' };
|
||||||
|
|
||||||
// return await Product.find(myfind);
|
// return await Product.find(myfind);
|
||||||
|
|
||||||
query.push(
|
query.push(
|
||||||
@@ -243,15 +246,9 @@ module.exports.findAllIdApp = async function (idapp, code, id) {
|
|||||||
from: 'scontisticas',
|
from: 'scontisticas',
|
||||||
localField: 'idScontisticas',
|
localField: 'idScontisticas',
|
||||||
foreignField: '_id',
|
foreignField: '_id',
|
||||||
as: 'scontistica'
|
as: 'scontisticas'
|
||||||
}
|
}
|
||||||
},
|
},
|
||||||
{
|
|
||||||
$unwind: {
|
|
||||||
path: '$scontistica',
|
|
||||||
preserveNullAndEmptyArrays: true,
|
|
||||||
},
|
|
||||||
},
|
|
||||||
{
|
{
|
||||||
$lookup: {
|
$lookup: {
|
||||||
from: 'storehouses',
|
from: 'storehouses',
|
||||||
@@ -372,9 +369,9 @@ module.exports.convertAfterImport = async function (idapp, dataObjects) {
|
|||||||
let recproducer = await Producer.findOne({ idapp, name: prod.producer_name }).lean();
|
let recproducer = await Producer.findOne({ idapp, name: prod.producer_name }).lean();
|
||||||
if (!recproducer) {
|
if (!recproducer) {
|
||||||
// Non esiste questo produttore, quindi lo creo !
|
// Non esiste questo produttore, quindi lo creo !
|
||||||
recproducer = await Producer.create({ idapp, name: prod.producer_name }, (err, recordCreato) => {
|
recproducer = new Producer({ idapp, name: prod.producer_name });
|
||||||
return recordCreato
|
ris = await recproducer.save();
|
||||||
})
|
recproducer = await Producer.findOne({ idapp, name: prod.producer_name }).lean();
|
||||||
}
|
}
|
||||||
|
|
||||||
if (recproducer) {
|
if (recproducer) {
|
||||||
@@ -391,9 +388,9 @@ module.exports.convertAfterImport = async function (idapp, dataObjects) {
|
|||||||
let recstorehouse = await Storehouse.findOne({ idapp, name: prod.magazzino_name }).lean();
|
let recstorehouse = await Storehouse.findOne({ idapp, name: prod.magazzino_name }).lean();
|
||||||
if (!recstorehouse) {
|
if (!recstorehouse) {
|
||||||
// Non esiste questo produttore, quindi lo creo !
|
// Non esiste questo produttore, quindi lo creo !
|
||||||
recstorehouse = await Storehouse.create({ idapp, name: prod.magazzino_name }, (err, recordCreato) => {
|
recstorehouse = new Storehouse({ idapp, name: prod.magazzino_name });
|
||||||
return recordCreato
|
ris = await recstorehouse.save();
|
||||||
})
|
recstorehouse = await Storehouse.findOne({ idapp, name: prod.magazzino_name }).lean();
|
||||||
}
|
}
|
||||||
|
|
||||||
if (recstorehouse) {
|
if (recstorehouse) {
|
||||||
@@ -409,10 +406,10 @@ module.exports.convertAfterImport = async function (idapp, dataObjects) {
|
|||||||
// Cerca il produttore
|
// Cerca il produttore
|
||||||
let recprovider = await Provider.findOne({ idapp, name: prod.provider_name }).lean();
|
let recprovider = await Provider.findOne({ idapp, name: prod.provider_name }).lean();
|
||||||
if (!recprovider) {
|
if (!recprovider) {
|
||||||
|
recprovider = new Provider({ idapp, name: prod.provider_name });
|
||||||
// Non esiste questo produttore, quindi lo creo !
|
// Non esiste questo produttore, quindi lo creo !
|
||||||
recprovider = await Provider.create({ idapp, name: prod.provider_name }, (err, recordCreato) => {
|
ris = await recprovider.save();
|
||||||
return recordCreato
|
recprovider = await Provider.findOne({ idapp, name: prod.provider_name }).lean();
|
||||||
})
|
|
||||||
}
|
}
|
||||||
|
|
||||||
if (recprovider) {
|
if (recprovider) {
|
||||||
|
|||||||
@@ -40,7 +40,10 @@ const scontisticaSchema = new Schema({
|
|||||||
var Scontistica = module.exports = mongoose.model('Scontistica', scontisticaSchema);
|
var Scontistica = module.exports = mongoose.model('Scontistica', scontisticaSchema);
|
||||||
|
|
||||||
module.exports.getFieldsForSearch = function () {
|
module.exports.getFieldsForSearch = function () {
|
||||||
return [{ field: 'name', type: tools.FieldType.string }]
|
return [
|
||||||
|
{ field: 'code', type: tools.FieldType.string },
|
||||||
|
{ field: 'description', type: tools.FieldType.string }
|
||||||
|
]
|
||||||
};
|
};
|
||||||
|
|
||||||
module.exports.executeQueryTable = function (idapp, params) {
|
module.exports.executeQueryTable = function (idapp, params) {
|
||||||
|
|||||||
@@ -338,7 +338,8 @@ module.exports.createFirstUserAdmin = async function () {
|
|||||||
const numusers = await User.countDocuments({ idapp: mysite.idapp });
|
const numusers = await User.countDocuments({ idapp: mysite.idapp });
|
||||||
if (numusers === 0) {
|
if (numusers === 0) {
|
||||||
// Non esistono utenti, quindi creo quello di Admin
|
// Non esistono utenti, quindi creo quello di Admin
|
||||||
const utenteadmin = await User.findOne({ idapp: '13', username: telegrambot.ADMIN_USER_SERVER }).lean()
|
|
||||||
|
const utenteadmin = { idapp: '13', username: telegrambot.ADMIN_USER_SERVER };
|
||||||
|
|
||||||
const newuser = new User(utenteadmin);
|
const newuser = new User(utenteadmin);
|
||||||
newuser._id = new ObjectID();
|
newuser._id = new ObjectID();
|
||||||
|
|||||||
@@ -5378,6 +5378,7 @@ UserSchema.statics.addNewSite = async function (idappPass, body) {
|
|||||||
// cerca un IdApp Libero
|
// cerca un IdApp Libero
|
||||||
let idapp = await Site.generateNewSite_IdApp(idappPass, body, true);
|
let idapp = await Site.generateNewSite_IdApp(idappPass, body, true);
|
||||||
|
|
||||||
|
|
||||||
if (idapp) {
|
if (idapp) {
|
||||||
let arrSite = await Site.find({ idapp }).lean();
|
let arrSite = await Site.find({ idapp }).lean();
|
||||||
let numutenti = 0;
|
let numutenti = 0;
|
||||||
@@ -5385,7 +5386,7 @@ UserSchema.statics.addNewSite = async function (idappPass, body) {
|
|||||||
numutenti = await User.countDocuments({ idapp });
|
numutenti = await User.countDocuments({ idapp });
|
||||||
};
|
};
|
||||||
|
|
||||||
if (arrSite && arrSite.length === 1 && numutenti === 0) {
|
if (arrSite && arrSite.length === 1 && numutenti < 2) {
|
||||||
// Nessun Sito Installato e Nessun Utente installato !
|
// Nessun Sito Installato e Nessun Utente installato !
|
||||||
let myuser = new User();
|
let myuser = new User();
|
||||||
myuser._id = new ObjectID();
|
myuser._id = new ObjectID();
|
||||||
|
|||||||
@@ -99,9 +99,59 @@ class Cart {
|
|||||||
order = this.items[rec];
|
order = this.items[rec];
|
||||||
}
|
}
|
||||||
this.totalQty += order.quantity;
|
this.totalQty += order.quantity;
|
||||||
this.totalPrice += order.price * order.quantity;
|
|
||||||
}
|
|
||||||
|
|
||||||
|
// Calcolo Sconto
|
||||||
|
let sconti_da_applicare = [];
|
||||||
|
let mypricecalc = 0;
|
||||||
|
if (order.scontisticas) {
|
||||||
|
|
||||||
|
let qtadascontare = order.quantity
|
||||||
|
let qtanonscontata = 0
|
||||||
|
|
||||||
|
while (qtadascontare > 0) {
|
||||||
|
let scontoapplicato = null
|
||||||
|
for (const sconto of order.scontisticas.filter((rec) => !rec.cumulativo)) {
|
||||||
|
if (qtadascontare >= sconto.qta) {
|
||||||
|
scontoapplicato = sconto
|
||||||
|
scontoapplicato.qtadascontare = sconto.qta
|
||||||
|
}
|
||||||
|
}
|
||||||
|
if (scontoapplicato && scontoapplicato.qtadascontare > 0) {
|
||||||
|
sconti_da_applicare.push(scontoapplicato)
|
||||||
|
qtadascontare -= scontoapplicato.qtadascontare
|
||||||
|
} else {
|
||||||
|
qtanonscontata = qtadascontare
|
||||||
|
qtadascontare = 0
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
/*for (const sconto of order.scontisticas.filter((rec) => rec.cumulativo)) {
|
||||||
|
if ((sconto.qta % order.quantity) === 0) {
|
||||||
|
sconti_da_applicare.push(sconto)
|
||||||
|
}
|
||||||
|
}*/
|
||||||
|
|
||||||
|
mypricecalc = order.price * order.quantity;
|
||||||
|
|
||||||
|
if (sconti_da_applicare.length > 0) {
|
||||||
|
mypricecalc = 0
|
||||||
|
for (const sconto of sconti_da_applicare) {
|
||||||
|
if (sconto.perc_sconto > 0) {
|
||||||
|
mypricecalc += (sconto.qtadascontare * order.price) * (1 - (sconto.perc_sconto / 100))
|
||||||
|
} else {
|
||||||
|
mypricecalc += sconto.price
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
if (qtanonscontata > 0) {
|
||||||
|
mypricecalc += order.price * qtanonscontata;
|
||||||
|
}
|
||||||
|
|
||||||
|
} else {
|
||||||
|
mypricecalc = order.price * order.quantity;
|
||||||
|
}
|
||||||
|
this.totalPrice += mypricecalc;
|
||||||
|
}
|
||||||
this.totalPrice = parseFloat(this.totalPrice.toFixed(2))
|
this.totalPrice = parseFloat(this.totalPrice.toFixed(2))
|
||||||
} catch (e) {
|
} catch (e) {
|
||||||
console.error('Err: ', e);
|
console.error('Err: ', e);
|
||||||
|
|||||||
@@ -1434,7 +1434,7 @@ function load(req, res, version) {
|
|||||||
let workers = User.getusersWorkersList(idapp);
|
let workers = User.getusersWorkersList(idapp);
|
||||||
let storehouses = Storehouse.findAllIdApp(idapp);
|
let storehouses = Storehouse.findAllIdApp(idapp);
|
||||||
let providers = Provider.findAllIdApp(idapp);
|
let providers = Provider.findAllIdApp(idapp);
|
||||||
let scontistica = Scontistica.findAllIdApp(idapp);
|
let scontisticas = Scontistica.findAllIdApp(idapp);
|
||||||
let departments = Department.findAllIdApp(idapp);
|
let departments = Department.findAllIdApp(idapp);
|
||||||
let categories = Category.findAllIdApp(idapp);
|
let categories = Category.findAllIdApp(idapp);
|
||||||
|
|
||||||
@@ -1522,7 +1522,7 @@ function load(req, res, version) {
|
|||||||
myelems, // 38
|
myelems, // 38
|
||||||
categories, // 39
|
categories, // 39
|
||||||
providers,
|
providers,
|
||||||
scontistica,
|
scontisticas,
|
||||||
]).then((arrdata) => {
|
]).then((arrdata) => {
|
||||||
// console.table(arrdata);
|
// console.table(arrdata);
|
||||||
let myuser = req.user;
|
let myuser = req.user;
|
||||||
@@ -1606,7 +1606,7 @@ function load(req, res, version) {
|
|||||||
myelems: arrdata[38],
|
myelems: arrdata[38],
|
||||||
categories: arrdata[39],
|
categories: arrdata[39],
|
||||||
providers: arrdata[40],
|
providers: arrdata[40],
|
||||||
scontistica: arrdata[41],
|
scontisticas: arrdata[41],
|
||||||
});
|
});
|
||||||
|
|
||||||
const prova = 1;
|
const prova = 1;
|
||||||
|
|||||||
@@ -566,8 +566,7 @@ router.post('/login', (req, res) => {
|
|||||||
// tools.mylog("CREDENZIALI ! ");
|
// tools.mylog("CREDENZIALI ! ");
|
||||||
if (!user) {
|
if (!user) {
|
||||||
await tools.snooze(3000);
|
await tools.snooze(3000);
|
||||||
const msg = 'Tentativo di Login ERRATO [' + body.username + ' , ' +
|
const msg = 'Tentativo di Login ERRATO [' + body.username + ' , ' + ']\n' + '[IP: ' + tools.getiPAddressUser(req) +
|
||||||
body.password + ']\n' + '[IP: ' + tools.getiPAddressUser(req) +
|
|
||||||
']';
|
']';
|
||||||
tools.mylogshow(msg);
|
tools.mylogshow(msg);
|
||||||
await telegrambot.sendMsgTelegramToTheAdmin(user.idapp, msg, true);
|
await telegrambot.sendMsgTelegramToTheAdmin(user.idapp, msg, true);
|
||||||
|
|||||||
Reference in New Issue
Block a user