Merge branch 'Dev_PDB1' of ssh://risosrv:5522/~/repository/freeplanet_serverside into Dev_PDB1
This commit is contained in:
File diff suppressed because one or more lines are too long
@@ -45,6 +45,7 @@ html
|
|||||||
- var price = product.order.price
|
- var price = product.order.price
|
||||||
- var after_price = product.order.after_price
|
- var after_price = product.order.after_price
|
||||||
- var qty = product.order.quantity
|
- var qty = product.order.quantity
|
||||||
|
- var qtypreordered = product.order.quantitypreordered
|
||||||
- index = index + 1
|
- index = index + 1
|
||||||
|
|
||||||
table(cellpadding="0", cellspacing="0", width="100%", summary="", border="0", align="center")
|
table(cellpadding="0", cellspacing="0", width="100%", summary="", border="0", align="center")
|
||||||
@@ -66,9 +67,14 @@ html
|
|||||||
tr
|
tr
|
||||||
td(class="sectionContent", valign="top")
|
td(class="sectionContent", valign="top")
|
||||||
p Prezzo: #{price} € #{after_price}
|
p Prezzo: #{price} € #{after_price}
|
||||||
tr
|
if (qty > 0)
|
||||||
td(class="sectionContent", valign="top")
|
tr
|
||||||
p Quantità: #{qty}
|
td(class="sectionContent", valign="top")
|
||||||
|
p Quantità: #{qty}
|
||||||
|
if (qtypreordereded > 0)
|
||||||
|
tr
|
||||||
|
td(class="sectionContent", valign="top")
|
||||||
|
p Quantità Prenotata: #{qtypreorder}
|
||||||
|
|
||||||
p Note Aggiuntive: #{note}
|
p Note Aggiuntive: #{note}
|
||||||
|
|
||||||
|
|||||||
@@ -45,6 +45,7 @@ html
|
|||||||
- var price = product.order.product.price
|
- var price = product.order.product.price
|
||||||
- var after_price = product.order.product.after_price
|
- var after_price = product.order.product.after_price
|
||||||
- var qty = product.order.product.quantity
|
- var qty = product.order.product.quantity
|
||||||
|
- var qtypreordered = product.order.quantitypreordered
|
||||||
- index = index + 1
|
- index = index + 1
|
||||||
|
|
||||||
table(cellpadding="0", cellspacing="0", width="100%", summary="", border="0", align="center")
|
table(cellpadding="0", cellspacing="0", width="100%", summary="", border="0", align="center")
|
||||||
@@ -66,9 +67,14 @@ html
|
|||||||
tr
|
tr
|
||||||
td(class="sectionContent", valign="top")
|
td(class="sectionContent", valign="top")
|
||||||
p Prezzo: #{price} € #{after_price}
|
p Prezzo: #{price} € #{after_price}
|
||||||
tr
|
if (qty > 0)
|
||||||
td(class="sectionContent", valign="top")
|
tr
|
||||||
p Quantità: #{qty}
|
td(class="sectionContent", valign="top")
|
||||||
|
p Quantità: #{qty}
|
||||||
|
if (qtypreordered > 0)
|
||||||
|
tr
|
||||||
|
td(class="sectionContent", valign="top")
|
||||||
|
p Quantità Prenotata: #{qtypreordered}
|
||||||
|
|
||||||
p Note Aggiuntive: #{note}
|
p Note Aggiuntive: #{note}
|
||||||
|
|
||||||
|
|||||||
72
src/server/models/gasordine.js
Executable file
72
src/server/models/gasordine.js
Executable file
@@ -0,0 +1,72 @@
|
|||||||
|
mongoose = require('mongoose').set('debug', false)
|
||||||
|
const Schema = mongoose.Schema;
|
||||||
|
|
||||||
|
const tools = require('../tools/general');
|
||||||
|
|
||||||
|
mongoose.Promise = global.Promise;
|
||||||
|
mongoose.level = "F";
|
||||||
|
|
||||||
|
|
||||||
|
// Resolving error Unknown modifier: $pushAll
|
||||||
|
mongoose.plugin(schema => {
|
||||||
|
schema.options.usePushEach = true
|
||||||
|
});
|
||||||
|
|
||||||
|
const gasordineSchema = new Schema({
|
||||||
|
active: {
|
||||||
|
type: Boolean,
|
||||||
|
},
|
||||||
|
idapp: {
|
||||||
|
type: String,
|
||||||
|
},
|
||||||
|
name: {
|
||||||
|
type: String,
|
||||||
|
},
|
||||||
|
description: {
|
||||||
|
type: String,
|
||||||
|
},
|
||||||
|
referente: {
|
||||||
|
type: String,
|
||||||
|
},
|
||||||
|
city: {
|
||||||
|
type: String,
|
||||||
|
},
|
||||||
|
img: {
|
||||||
|
type: String,
|
||||||
|
},
|
||||||
|
dataora_chiusura: {
|
||||||
|
type: Date,
|
||||||
|
},
|
||||||
|
dataora_ritiro: {
|
||||||
|
type: Date,
|
||||||
|
},
|
||||||
|
});
|
||||||
|
|
||||||
|
var Gasordine = module.exports = mongoose.model('Gasordine', gasordineSchema);
|
||||||
|
|
||||||
|
module.exports.getFieldsForSearch = function () {
|
||||||
|
return [
|
||||||
|
{field: 'name', type: tools.FieldType.string},
|
||||||
|
{field: 'description', type: tools.FieldType.string},
|
||||||
|
]
|
||||||
|
};
|
||||||
|
|
||||||
|
module.exports.executeQueryTable = function (idapp, params) {
|
||||||
|
params.fieldsearch = this.getFieldsForSearch();
|
||||||
|
return tools.executeQueryTable(this, idapp, params);
|
||||||
|
};
|
||||||
|
|
||||||
|
module.exports.findAllIdApp = async function (idapp) {
|
||||||
|
const myfind = { idapp };
|
||||||
|
|
||||||
|
return await Gasordine.find(myfind);
|
||||||
|
};
|
||||||
|
|
||||||
|
|
||||||
|
module.exports.getGasordineByID = function (id, callback) {
|
||||||
|
Gasordine.findById(id, callback);
|
||||||
|
}
|
||||||
|
|
||||||
|
module.exports.createIndexes((err) => {
|
||||||
|
if (err) throw err;
|
||||||
|
});
|
||||||
@@ -2,6 +2,7 @@
|
|||||||
const mongoose = require('mongoose').set('debug', false)
|
const mongoose = require('mongoose').set('debug', false)
|
||||||
const Schema = mongoose.Schema;
|
const Schema = mongoose.Schema;
|
||||||
|
|
||||||
|
const shared_consts = require('../tools/shared_nodejs');
|
||||||
|
|
||||||
const { ObjectID } = require('mongodb');
|
const { ObjectID } = require('mongodb');
|
||||||
|
|
||||||
@@ -27,6 +28,7 @@ const orderSchema = new Schema({
|
|||||||
idStorehouse: { type: Schema.Types.ObjectId, ref: 'StoreHouse' },
|
idStorehouse: { type: Schema.Types.ObjectId, ref: 'StoreHouse' },
|
||||||
idScontisticas: [{ type: Schema.Types.ObjectId, ref: 'Scontistica' }],
|
idScontisticas: [{ type: Schema.Types.ObjectId, ref: 'Scontistica' }],
|
||||||
idProvider: { type: Schema.Types.ObjectId, ref: 'Provider' },
|
idProvider: { type: Schema.Types.ObjectId, ref: 'Provider' },
|
||||||
|
idGasordine: { type: Schema.Types.ObjectId, ref: 'Gasordine' },
|
||||||
price: {
|
price: {
|
||||||
type: Number,
|
type: Number,
|
||||||
default: 0,
|
default: 0,
|
||||||
@@ -44,11 +46,15 @@ const orderSchema = new Schema({
|
|||||||
type: Number,
|
type: Number,
|
||||||
default: 0,
|
default: 0,
|
||||||
},
|
},
|
||||||
|
quantitypreordered: {
|
||||||
|
type: Number,
|
||||||
|
default: 0,
|
||||||
|
},
|
||||||
TotalPriceProduct: {
|
TotalPriceProduct: {
|
||||||
type: Number,
|
type: Number,
|
||||||
default: 0,
|
default: 0,
|
||||||
},
|
},
|
||||||
evaso: { // e quindi è stato tolto dal magazzino (aggiornando il campo StockQty)
|
evaso: { // e quindi è stato tolto dal magazzino (aggiornando il campo stockQty)
|
||||||
type: Boolean,
|
type: Boolean,
|
||||||
default: false,
|
default: false,
|
||||||
},
|
},
|
||||||
@@ -164,6 +170,14 @@ module.exports.findAllIdApp = async function (idapp) {
|
|||||||
as: 'provider'
|
as: 'provider'
|
||||||
}
|
}
|
||||||
},
|
},
|
||||||
|
{
|
||||||
|
$lookup: {
|
||||||
|
from: 'gasordines',
|
||||||
|
localField: 'idGasordine',
|
||||||
|
foreignField: '_id',
|
||||||
|
as: 'gasordine'
|
||||||
|
}
|
||||||
|
},
|
||||||
{
|
{
|
||||||
$lookup: {
|
$lookup: {
|
||||||
from: 'scontisticas',
|
from: 'scontisticas',
|
||||||
@@ -189,6 +203,12 @@ module.exports.findAllIdApp = async function (idapp) {
|
|||||||
path: '$provider',
|
path: '$provider',
|
||||||
preserveNullAndEmptyArrays: true,
|
preserveNullAndEmptyArrays: true,
|
||||||
},
|
},
|
||||||
|
},
|
||||||
|
{
|
||||||
|
$unwind: {
|
||||||
|
path: '$gasordine',
|
||||||
|
preserveNullAndEmptyArrays: true,
|
||||||
|
},
|
||||||
}
|
}
|
||||||
|
|
||||||
];
|
];
|
||||||
@@ -255,7 +275,7 @@ module.exports.updateTotals = function (order) {
|
|||||||
let sconti_da_applicare = [];
|
let sconti_da_applicare = [];
|
||||||
if (order.scontisticas) {
|
if (order.scontisticas) {
|
||||||
|
|
||||||
let qtadascontare = order.quantity
|
let qtadascontare = order.quantity + order.quantitypreordered
|
||||||
let qtanonscontata = 0
|
let qtanonscontata = 0
|
||||||
|
|
||||||
while (qtadascontare > 0) {
|
while (qtadascontare > 0) {
|
||||||
@@ -295,7 +315,7 @@ module.exports.updateTotals = function (order) {
|
|||||||
}
|
}
|
||||||
|
|
||||||
} else {
|
} else {
|
||||||
mypricecalc = order.price * order.quantity;
|
mypricecalc = (order.price * order.quantity) + (order.price * order.quantitypreordered);
|
||||||
}
|
}
|
||||||
order.TotalPriceProduct += mypricecalc;
|
order.TotalPriceProduct += mypricecalc;
|
||||||
|
|
||||||
@@ -341,6 +361,14 @@ module.exports.getTotalOrderById = async function (id) {
|
|||||||
as: 'provider'
|
as: 'provider'
|
||||||
}
|
}
|
||||||
},
|
},
|
||||||
|
{
|
||||||
|
$lookup: {
|
||||||
|
from: 'gasordines',
|
||||||
|
localField: 'idGasordine',
|
||||||
|
foreignField: '_id',
|
||||||
|
as: 'gasordine'
|
||||||
|
}
|
||||||
|
},
|
||||||
{
|
{
|
||||||
$lookup: {
|
$lookup: {
|
||||||
from: 'scontisticas',
|
from: 'scontisticas',
|
||||||
@@ -372,7 +400,108 @@ module.exports.getTotalOrderById = async function (id) {
|
|||||||
path: '$provider',
|
path: '$provider',
|
||||||
preserveNullAndEmptyArrays: true,
|
preserveNullAndEmptyArrays: true,
|
||||||
},
|
},
|
||||||
}
|
},
|
||||||
|
{
|
||||||
|
$unwind: {
|
||||||
|
path: '$gasordine',
|
||||||
|
preserveNullAndEmptyArrays: true,
|
||||||
|
},
|
||||||
|
},
|
||||||
|
{
|
||||||
|
$lookup: {
|
||||||
|
from: 'orders',
|
||||||
|
let: { productId: '$product._id' },
|
||||||
|
pipeline: [
|
||||||
|
{
|
||||||
|
$match: {
|
||||||
|
$expr: {
|
||||||
|
$and: [
|
||||||
|
{ $eq: ['$idProduct', '$$productId'] },
|
||||||
|
{ $lt: ['$status', shared_consts.OrderStatus.ORDER_CONFIRMED] }
|
||||||
|
]
|
||||||
|
}
|
||||||
|
}
|
||||||
|
},
|
||||||
|
{
|
||||||
|
$group: {
|
||||||
|
_id: null,
|
||||||
|
totalQty: { $sum: '$quantity' },
|
||||||
|
}
|
||||||
|
}
|
||||||
|
],
|
||||||
|
as: 'productOrders'
|
||||||
|
}
|
||||||
|
},
|
||||||
|
{
|
||||||
|
$lookup: {
|
||||||
|
from: 'orders',
|
||||||
|
let: { productId: '$product._id' },
|
||||||
|
pipeline: [
|
||||||
|
{
|
||||||
|
$match: {
|
||||||
|
$expr: {
|
||||||
|
$and: [
|
||||||
|
{ $eq: ['$idProduct', '$$productId'] },
|
||||||
|
{ $lt: ['$status', shared_consts.OrderStatus.ORDER_CONFIRMED] }
|
||||||
|
]
|
||||||
|
}
|
||||||
|
}
|
||||||
|
},
|
||||||
|
{
|
||||||
|
$group: {
|
||||||
|
_id: null,
|
||||||
|
totalQtyPreordered: { $sum: '$quantitypreordered' }
|
||||||
|
}
|
||||||
|
}
|
||||||
|
],
|
||||||
|
as: 'productPreOrders'
|
||||||
|
}
|
||||||
|
},
|
||||||
|
{
|
||||||
|
$addFields: {
|
||||||
|
'product.QuantitaOrdinateInAttesa': {
|
||||||
|
$ifNull: [
|
||||||
|
{
|
||||||
|
$cond: {
|
||||||
|
if: { $isArray: '$productOrders' },
|
||||||
|
then: { $arrayElemAt: ['$productOrders.totalQty', 0] },
|
||||||
|
else: 0
|
||||||
|
}
|
||||||
|
},
|
||||||
|
0
|
||||||
|
]
|
||||||
|
},
|
||||||
|
'product.QuantitaPrenotateInAttesa': {
|
||||||
|
$ifNull: [
|
||||||
|
{
|
||||||
|
$cond: {
|
||||||
|
if: { $isArray: '$productPreOrders' },
|
||||||
|
then: { $arrayElemAt: ['$productPreOrders.totalQtyPreordered', 0] },
|
||||||
|
else: 0
|
||||||
|
}
|
||||||
|
},
|
||||||
|
0
|
||||||
|
]
|
||||||
|
},
|
||||||
|
},
|
||||||
|
},
|
||||||
|
{
|
||||||
|
$addFields: {
|
||||||
|
'product.quantityAvailable': {
|
||||||
|
$subtract: ["$product.stockQty", "$product.QuantitaOrdinateInAttesa"],
|
||||||
|
},
|
||||||
|
'product.bookableAvailableQty': {
|
||||||
|
$subtract: ["$product.bookableQty", "$product.QuantitaPrenotateInAttesa"],
|
||||||
|
}
|
||||||
|
}
|
||||||
|
},
|
||||||
|
{
|
||||||
|
$unset: 'productOrders'
|
||||||
|
},
|
||||||
|
{
|
||||||
|
$unset: 'productPreOrders'
|
||||||
|
},
|
||||||
|
|
||||||
];
|
];
|
||||||
|
|
||||||
return await Order.aggregate(query);
|
return await Order.aggregate(query);
|
||||||
|
|||||||
@@ -8,6 +8,7 @@ var { User } = require('../models/user');
|
|||||||
|
|
||||||
const Storehouse = require('../models/storehouse');
|
const Storehouse = require('../models/storehouse');
|
||||||
const Provider = require('../models/provider');
|
const Provider = require('../models/provider');
|
||||||
|
const Gasordine = require('../models/gasordine');
|
||||||
const Product = require('../models/product');
|
const Product = require('../models/product');
|
||||||
|
|
||||||
const tools = require('../tools/general');
|
const tools = require('../tools/general');
|
||||||
@@ -22,7 +23,7 @@ const OrdersCartSchema = new Schema({
|
|||||||
numord_pers: { type: Number },
|
numord_pers: { type: Number },
|
||||||
userId: { type: Schema.Types.ObjectId, ref: 'User' },
|
userId: { type: Schema.Types.ObjectId, ref: 'User' },
|
||||||
totalQty: { type: Number, default: 0 },
|
totalQty: { type: Number, default: 0 },
|
||||||
TotalPriceProduct: { type: Number, default: 0 },
|
totalQtyPreordered: { type: Number, default: 0 },
|
||||||
totalPrice: { type: Number, default: 0 },
|
totalPrice: { type: Number, default: 0 },
|
||||||
department: {
|
department: {
|
||||||
type: String, ref: 'Department'
|
type: String, ref: 'Department'
|
||||||
@@ -129,10 +130,10 @@ module.exports.getLastNumOrder = async function (idapp) {
|
|||||||
module.exports.getLastNumOrdPers = async function (uid, idapp) {
|
module.exports.getLastNumOrdPers = async function (uid, idapp) {
|
||||||
let query = { userId: uid, idapp, deleted: false }
|
let query = { userId: uid, idapp, deleted: false }
|
||||||
let numorder = 1;
|
let numorder = 1;
|
||||||
let numorderrec = await OrdersCart.find(query).sort({ numorder: -1 }).limit(1);
|
let numorderrec = await OrdersCart.find(query).sort({ numord_pers: -1 }).limit(1);
|
||||||
|
|
||||||
if (numorderrec && numorderrec.length > 0)
|
if (numorderrec && numorderrec.length > 0)
|
||||||
numorder = numorderrec[0].numorder;
|
numorder = numorderrec[0].numord_pers;
|
||||||
else
|
else
|
||||||
numorder = 0;
|
numorder = 0;
|
||||||
|
|
||||||
@@ -177,7 +178,7 @@ module.exports.getOrdersCartById = async function (id) {
|
|||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
module.exports.getOrdersCartByQuery = async function (query) {
|
module.exports.getOLDOrdersCartByQuery = async function (query) {
|
||||||
|
|
||||||
let myorderscart = await OrdersCart.find(query)
|
let myorderscart = await OrdersCart.find(query)
|
||||||
.populate('items.order')
|
.populate('items.order')
|
||||||
@@ -202,6 +203,13 @@ module.exports.getOrdersCartByQuery = async function (query) {
|
|||||||
model: 'Provider'
|
model: 'Provider'
|
||||||
},
|
},
|
||||||
})
|
})
|
||||||
|
.populate({
|
||||||
|
path: 'items.order',
|
||||||
|
populate: {
|
||||||
|
path: 'idGasordine',
|
||||||
|
model: 'Gasordine'
|
||||||
|
},
|
||||||
|
})
|
||||||
.populate({
|
.populate({
|
||||||
path: 'items.order',
|
path: 'items.order',
|
||||||
populate: {
|
populate: {
|
||||||
@@ -237,6 +245,8 @@ module.exports.getOrdersCartByQuery = async function (query) {
|
|||||||
item.order.idStorehouse = item.order.storehouse ? 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 ? item.order.provider._id : '';
|
item.order.idProvider = item.order.provider ? item.order.provider._id : '';
|
||||||
|
item.order.gasordine = item.order.idGasordine;
|
||||||
|
item.order.idGasordine = item.order.gasordine ? item.order.gasordine._id : '';
|
||||||
item.order.scontisticas = item.order.scontisticas;
|
item.order.scontisticas = item.order.scontisticas;
|
||||||
item.order.idScontisticas = item.order.idScontisticas ? item.order.idScontisticas._id : '';
|
item.order.idScontisticas = item.order.idScontisticas ? item.order.idScontisticas._id : '';
|
||||||
} catch (e) {
|
} catch (e) {
|
||||||
@@ -251,10 +261,95 @@ module.exports.getOrdersCartByQuery = async function (query) {
|
|||||||
return myorderscart;
|
return myorderscart;
|
||||||
|
|
||||||
}
|
}
|
||||||
module.exports.getOrdersCartByUserId = async function (uid, idapp, numorder) {
|
|
||||||
|
|
||||||
|
module.exports.getOrdersCartByQuery = async function (query) {
|
||||||
|
|
||||||
|
let myorderscart = await OrdersCart.find(query)
|
||||||
|
.populate('items.order')
|
||||||
|
.populate({
|
||||||
|
path: 'items.order',
|
||||||
|
populate: {
|
||||||
|
path: 'idProduct',
|
||||||
|
model: 'Product'
|
||||||
|
},
|
||||||
|
})
|
||||||
|
.populate({
|
||||||
|
path: 'items.order',
|
||||||
|
populate: {
|
||||||
|
path: 'idProducer',
|
||||||
|
model: 'Producer'
|
||||||
|
},
|
||||||
|
})
|
||||||
|
.populate({
|
||||||
|
path: 'items.order',
|
||||||
|
populate: {
|
||||||
|
path: 'idProvider',
|
||||||
|
model: 'Provider'
|
||||||
|
},
|
||||||
|
})
|
||||||
|
.populate({
|
||||||
|
path: 'items.order',
|
||||||
|
populate: {
|
||||||
|
path: 'idGasordine',
|
||||||
|
model: 'Gasordine'
|
||||||
|
},
|
||||||
|
})
|
||||||
|
.populate({
|
||||||
|
path: 'items.order',
|
||||||
|
populate: {
|
||||||
|
path: 'idStorehouse',
|
||||||
|
model: 'Storehouse'
|
||||||
|
},
|
||||||
|
})
|
||||||
|
.populate({
|
||||||
|
path: 'items.order',
|
||||||
|
populate: {
|
||||||
|
path: 'idScontisticas',
|
||||||
|
model: 'Scontistica'
|
||||||
|
},
|
||||||
|
})
|
||||||
|
.populate({
|
||||||
|
path: 'userId',
|
||||||
|
model: 'User',
|
||||||
|
select: '_id name surname username profile', // Specify the fields you want to retrieve
|
||||||
|
})
|
||||||
|
.lean();
|
||||||
|
|
||||||
|
myorderscart = myorderscart.map(order => {
|
||||||
|
order.user = order.userId
|
||||||
|
order.userId = order.user._id
|
||||||
|
order.items = order.items.map(item => {
|
||||||
|
if (item.order) {
|
||||||
|
try {
|
||||||
|
item.order.product = item.order.idProduct;
|
||||||
|
item.order.idProduct = item.order.product ? item.order.product._id : '';
|
||||||
|
item.order.producer = item.order.idProducer;
|
||||||
|
item.order.idProducer = item.order.producer ? item.order.producer._id : '';
|
||||||
|
item.order.storehouse = item.order.idStorehouse;
|
||||||
|
item.order.idStorehouse = item.order.storehouse ? item.order.storehouse._id : '';
|
||||||
|
item.order.provider = item.order.idProvider;
|
||||||
|
item.order.idProvider = item.order.provider ? item.order.provider._id : '';
|
||||||
|
item.order.gasordine = item.order.idGasordine;
|
||||||
|
item.order.idGasordine = item.order.gasordine ? item.order.gasordine._id : '';
|
||||||
|
item.order.scontisticas = item.order.scontisticas;
|
||||||
|
item.order.idScontisticas = item.order.idScontisticas ? item.order.idScontisticas._id : '';
|
||||||
|
} catch (e) {
|
||||||
|
console.error('Err: ', e);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
return item;
|
||||||
|
});
|
||||||
|
return order;
|
||||||
|
});
|
||||||
|
|
||||||
|
return myorderscart;
|
||||||
|
}
|
||||||
|
|
||||||
|
module.exports.getOrdersCartByUserId = async function (uid, idapp, numorder, filterStatus) {
|
||||||
|
|
||||||
try {
|
try {
|
||||||
let query = { idapp, status: { $gte: shared_consts.OrderStatus.CHECKOUT_SENT }, deleted: false }
|
let query = { idapp, deleted: false }
|
||||||
let myorderscart = null;
|
let myorderscart = null;
|
||||||
if (numorder > 0) {
|
if (numorder > 0) {
|
||||||
query.numorder = numorder;
|
query.numorder = numorder;
|
||||||
@@ -264,6 +359,10 @@ module.exports.getOrdersCartByUserId = async function (uid, idapp, numorder) {
|
|||||||
query.userId = uid;
|
query.userId = uid;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
if (filterStatus) {
|
||||||
|
query.status = { $gte: shared_consts.OrderStatus.CHECKOUT_SENT };
|
||||||
|
}
|
||||||
|
|
||||||
myorderscart = await OrdersCart.getOrdersCartByQuery(query);
|
myorderscart = await OrdersCart.getOrdersCartByQuery(query);
|
||||||
|
|
||||||
|
|
||||||
@@ -299,8 +398,8 @@ module.exports.updateOrdersCartById = function (id, newOrdersCart, callback) {
|
|||||||
$set: {
|
$set: {
|
||||||
items: newOrdersCart.items,
|
items: newOrdersCart.items,
|
||||||
totalQty: newOrdersCart.totalQty,
|
totalQty: newOrdersCart.totalQty,
|
||||||
|
totalQtyPreordered: newOrdersCart.totalQtyPreordered,
|
||||||
totalPrice: newOrdersCart.totalPrice,
|
totalPrice: newOrdersCart.totalPrice,
|
||||||
totalPriceProduct: newOrdersCart.totalPriceProduct,
|
|
||||||
userId: userId,
|
userId: userId,
|
||||||
status: newOrdersCart.status,
|
status: newOrdersCart.status,
|
||||||
numorder: newOrdersCart.numorder,
|
numorder: newOrdersCart.numorder,
|
||||||
@@ -432,15 +531,18 @@ module.exports.updateStockQtaDalMagazzino = async function (idorderscart) {
|
|||||||
let order = myorderscart.items[idkey].order;
|
let order = myorderscart.items[idkey].order;
|
||||||
|
|
||||||
if (!order.evaso) {
|
if (!order.evaso) {
|
||||||
const update = {
|
let update = {
|
||||||
$inc: {
|
$inc: {
|
||||||
stockQty: -order.quantity
|
stockQty: -order.quantity
|
||||||
}
|
}
|
||||||
};
|
};
|
||||||
const ris = await Product.findOneAndUpdate({ _id: order.idProduct }, update, { new: false });
|
await Product.findOneAndUpdate({ _id: order.idProduct }, update, { new: false });
|
||||||
if (ris) {
|
update = {
|
||||||
|
$inc: {
|
||||||
}
|
bookableQty: -order.quantitypreordered
|
||||||
|
}
|
||||||
|
};
|
||||||
|
await Product.findOneAndUpdate({ _id: order.idProduct }, update, { new: false });
|
||||||
}
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
@@ -546,12 +648,17 @@ module.exports.getmsgorderTelegram = async function (ordersCart) {
|
|||||||
msg += '<br><br>Lista Prodotti:';
|
msg += '<br><br>Lista Prodotti:';
|
||||||
for (const ord of ordersCart.items) {
|
for (const ord of ordersCart.items) {
|
||||||
msg += '<br>';
|
msg += '<br>';
|
||||||
msg += '✅ [' + ord.order.quantity + '] ' + ord.order.product.name + ' (' + ord.order.price + ' € ' + (ord.order.after_price ? ord.order.after_price : '') + ' Tot=' + ord.order.TotalPriceProduct + '€ )';
|
let qtystr = ''
|
||||||
|
if (ord.order.quantity > 0)
|
||||||
|
qtystr += 'Ordinate: ' + ord.order.quantity
|
||||||
|
if (ord.order.quantitypreordered > 0)
|
||||||
|
qtystr += ' Pre-Ordinate: ' + ord.order.quantitypreordered
|
||||||
|
msg += '✅ [' + qtystr + '] ' + ord.order.product.name + ' (' + ord.order.price + ' € ' + (ord.order.after_price ? ord.order.after_price : '') + ' Tot=' + ord.order.TotalPriceProduct + '€ )';
|
||||||
}
|
}
|
||||||
|
|
||||||
msg += '<br>';
|
msg += '<br>';
|
||||||
|
|
||||||
msg += '<br>Totale Prodotti: ' + ordersCart.totalQty;
|
msg += '<br>Totale Prodotti: ' + ordersCart.totalQty + ordersCart.totalQtyPreordered;
|
||||||
msg += '<br>Totale Ordine: ' + ordersCart.totalPrice + ' € 💰';
|
msg += '<br>Totale Ordine: ' + ordersCart.totalPrice + ' € 💰';
|
||||||
|
|
||||||
|
|
||||||
|
|||||||
@@ -6,6 +6,7 @@ const tools = require('../tools/general');
|
|||||||
const Producer = require('../models/producer');
|
const Producer = require('../models/producer');
|
||||||
const Storehouse = require('../models/storehouse');
|
const Storehouse = require('../models/storehouse');
|
||||||
const Provider = require('../models/provider');
|
const Provider = require('../models/provider');
|
||||||
|
const Gasordine = require('../models/gasordine');
|
||||||
const Scontistica = require('../models/scontistica');
|
const Scontistica = require('../models/scontistica');
|
||||||
|
|
||||||
const shared_consts = require('../tools/shared_nodejs');
|
const shared_consts = require('../tools/shared_nodejs');
|
||||||
@@ -96,6 +97,10 @@ const productSchema = new Schema({
|
|||||||
type: Number,
|
type: Number,
|
||||||
default: 0,
|
default: 0,
|
||||||
},
|
},
|
||||||
|
bookableQty: { // Quantità prenotabili
|
||||||
|
type: Number,
|
||||||
|
default: 0,
|
||||||
|
},
|
||||||
quantityLow: { //Soglia disponibilità bassa
|
quantityLow: { //Soglia disponibilità bassa
|
||||||
type: Number,
|
type: Number,
|
||||||
default: 0,
|
default: 0,
|
||||||
@@ -275,27 +280,82 @@ module.exports.findAllIdApp = async function (idapp, code, id) {
|
|||||||
{
|
{
|
||||||
$group: {
|
$group: {
|
||||||
_id: null,
|
_id: null,
|
||||||
totalQty: { $sum: '$quantity' }
|
totalQty: { $sum: '$quantity' },
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
],
|
],
|
||||||
as: 'productOrders'
|
as: 'productOrders'
|
||||||
}
|
}
|
||||||
},
|
},
|
||||||
|
{
|
||||||
|
$lookup: {
|
||||||
|
from: 'orders',
|
||||||
|
let: { productId: '$_id' },
|
||||||
|
pipeline: [
|
||||||
|
{
|
||||||
|
$match: {
|
||||||
|
$expr: {
|
||||||
|
$and: [
|
||||||
|
{ $eq: ['$idProduct', '$$productId'] },
|
||||||
|
{ $lt: ['$status', shared_consts.OrderStatus.ORDER_CONFIRMED] }
|
||||||
|
]
|
||||||
|
}
|
||||||
|
}
|
||||||
|
},
|
||||||
|
{
|
||||||
|
$group: {
|
||||||
|
_id: null,
|
||||||
|
totalQtyPreordered: { $sum: '$quantitypreordered' }
|
||||||
|
}
|
||||||
|
}
|
||||||
|
],
|
||||||
|
as: 'productPreOrders'
|
||||||
|
}
|
||||||
|
},
|
||||||
{
|
{
|
||||||
$addFields: {
|
$addFields: {
|
||||||
QuantitaOrdinateInAttesa: {
|
QuantitaOrdinateInAttesa: {
|
||||||
$cond: {
|
$ifNull: [
|
||||||
if: { $isArray: '$productOrders' },
|
{
|
||||||
then: { $arrayElemAt: ['$productOrders.totalQty', 0] },
|
$cond: {
|
||||||
else: 0
|
if: { $isArray: '$productOrders' },
|
||||||
}
|
then: { $arrayElemAt: ['$productOrders.totalQty', 0] },
|
||||||
|
else: 0
|
||||||
|
}
|
||||||
|
},
|
||||||
|
0
|
||||||
|
]
|
||||||
|
},
|
||||||
|
QuantitaPrenotateInAttesa: {
|
||||||
|
$ifNull: [
|
||||||
|
{
|
||||||
|
$cond: {
|
||||||
|
if: { $isArray: '$productPreOrders' },
|
||||||
|
then: { $arrayElemAt: ['$productPreOrders.totalQtyPreordered', 0] },
|
||||||
|
else: 0
|
||||||
|
}
|
||||||
|
},
|
||||||
|
0
|
||||||
|
]
|
||||||
|
},
|
||||||
|
},
|
||||||
|
},
|
||||||
|
{
|
||||||
|
$addFields: {
|
||||||
|
quantityAvailable: {
|
||||||
|
$subtract: ["$stockQty", "$QuantitaOrdinateInAttesa"],
|
||||||
|
},
|
||||||
|
bookableAvailableQty: {
|
||||||
|
$subtract: ["$bookableQty", "$QuantitaPrenotateInAttesa"],
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
},
|
},
|
||||||
{
|
{
|
||||||
$unset: 'productOrders'
|
$unset: 'productOrders'
|
||||||
},
|
},
|
||||||
|
{
|
||||||
|
$unset: 'productPreOrders'
|
||||||
|
},
|
||||||
|
|
||||||
);
|
);
|
||||||
|
|
||||||
@@ -352,6 +412,14 @@ module.exports.getProductByID = function (id, callback) {
|
|||||||
Product.findById(id, callback);
|
Product.findById(id, callback);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
module.exports.updateProductInOrder = async function (order) {
|
||||||
|
|
||||||
|
if (order.product)
|
||||||
|
order.product = await Product.getProductById(order.product._id);
|
||||||
|
|
||||||
|
return order;
|
||||||
|
}
|
||||||
|
|
||||||
module.exports.createIndexes((err) => {
|
module.exports.createIndexes((err) => {
|
||||||
if (err) throw err;
|
if (err) throw err;
|
||||||
});
|
});
|
||||||
|
|||||||
@@ -6,18 +6,25 @@ const { ObjectID } = require('mongodb');
|
|||||||
const Order = require('../models/order');
|
const Order = require('../models/order');
|
||||||
|
|
||||||
class Cart {
|
class Cart {
|
||||||
constructor(order) {
|
constructor(order, arrorders) {
|
||||||
this.items = {};
|
|
||||||
if (!!order) {
|
|
||||||
this.idapp = order.idapp || 0;
|
|
||||||
this.items[order._id] = order;
|
|
||||||
this.userId = order.userId || "";
|
|
||||||
}
|
|
||||||
this.modify_at = new Date();
|
this.modify_at = new Date();
|
||||||
|
|
||||||
|
this.items = {};
|
||||||
|
if (!!order) {
|
||||||
|
this.initializeFromOrder(order);
|
||||||
|
} else if (!!arrorders) {
|
||||||
|
for (const ord of arrorders) {
|
||||||
|
this.items.push(ord)
|
||||||
|
}
|
||||||
|
}
|
||||||
this.updatetotals();
|
this.updatetotals();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
initializeFromOrder(order) {
|
||||||
|
this.idapp = order.idapp || 0;
|
||||||
|
this.userId = order.userId || "";
|
||||||
|
this.items[order._id] = order;
|
||||||
|
}
|
||||||
static constructByCart(cart) {
|
static constructByCart(cart) {
|
||||||
try {
|
try {
|
||||||
const mynewcart = new Cart(null);
|
const mynewcart = new Cart(null);
|
||||||
@@ -34,26 +41,49 @@ class Cart {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
isAvailableByOrder(order) {
|
||||||
|
if (order && order.product) {
|
||||||
|
return (order.product.quantityAvailable > 0)
|
||||||
|
}
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
|
||||||
|
isInPreorderByOrder(order) {
|
||||||
|
if (order && order.product) {
|
||||||
|
return (order.product.bookableAvailableQty > 0)
|
||||||
|
}
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
|
||||||
async addqty(itemorder) {
|
async addqty(itemorder) {
|
||||||
const myitem = this.items.find((rec) => rec.order._id.toString() === itemorder._id)
|
const myitem = this.items.find((rec) => rec.order._id.toString() === itemorder._id)
|
||||||
if (!!myitem) {
|
if (!!myitem) {
|
||||||
myitem.order.quantity++;
|
if (this.isAvailableByOrder(myitem.order)) {
|
||||||
myitem.order = Order.updateTotals(myitem.order);
|
myitem.order.quantity++;
|
||||||
|
} else {
|
||||||
|
myitem.order.quantitypreordered++;
|
||||||
|
}
|
||||||
|
|
||||||
this.updatetotals();
|
this.updatetotals();
|
||||||
await Order.findOneAndUpdate({ _id: myitem.order._id }, { $set: myitem.order }, { new: false });
|
await Order.findOneAndUpdate({ _id: myitem.order._id }, { $set: myitem.order }, { new: false });
|
||||||
return myitem.order.quantity;
|
return myitem.order;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
async subqty(itemorder) {
|
async subqty(itemorder) {
|
||||||
try {
|
try {
|
||||||
const myitem = this.items.find((rec) => rec.order._id.toString() === itemorder._id)
|
const myitem = this.items.find((rec) => rec.order._id.toString() === itemorder._id)
|
||||||
if (!!myitem && myitem.order.quantity > 0) {
|
if (!!myitem) {
|
||||||
myitem.order.quantity--;
|
if (myitem.order.quantitypreordered > 0) {
|
||||||
myitem.order = Order.updateTotals(myitem.order);
|
myitem.order.quantitypreordered--;
|
||||||
|
} else {
|
||||||
|
if (myitem.order.quantity > 0) {
|
||||||
|
myitem.order.quantity--;
|
||||||
|
}
|
||||||
|
}
|
||||||
this.updatetotals();
|
this.updatetotals();
|
||||||
await Order.findOneAndUpdate({ _id: myitem.order._id }, { $set: myitem.order }, { new: false });
|
await Order.findOneAndUpdate({ _id: myitem.order._id }, { $set: myitem.order }, { new: false });
|
||||||
return myitem.order.quantity;
|
return myitem.order;
|
||||||
}
|
}
|
||||||
} catch (e) {
|
} catch (e) {
|
||||||
console.error('Err: ', e);
|
console.error('Err: ', e);
|
||||||
@@ -79,30 +109,86 @@ class Cart {
|
|||||||
}
|
}
|
||||||
|
|
||||||
generateModel() {
|
generateModel() {
|
||||||
let newCart = new cartModel({
|
try {
|
||||||
idapp: this.idapp,
|
let newCart = new cartModel({
|
||||||
items: this.generateArray(),
|
idapp: this.idapp,
|
||||||
totalQty: this.totalQty,
|
items: this.generateArray(),
|
||||||
totalPrice: this.totalPrice,
|
totalQty: this.totalQty,
|
||||||
userId: this.userId,
|
totalPrice: this.totalPrice,
|
||||||
department: this.department,
|
userId: this.userId,
|
||||||
note: this.note,
|
department: this.department,
|
||||||
modify_at: this.modify_at
|
note: this.note,
|
||||||
})
|
modify_at: this.modify_at
|
||||||
|
})
|
||||||
return newCart
|
return newCart
|
||||||
|
} catch (e) {
|
||||||
|
console.error('Err', e);
|
||||||
|
}
|
||||||
|
return null;
|
||||||
}
|
}
|
||||||
|
|
||||||
updatetotals() {
|
updatetotals() {
|
||||||
try {
|
try {
|
||||||
this.totalQty = 0;
|
this.totalQty = 0;
|
||||||
this.totalPrice = 0;
|
this.totalPrice = 0;
|
||||||
if (this.items && this.items.length > 0) {
|
for (const rec in this.items) {
|
||||||
for (const rec of this.items) {
|
let mypricecalc = 0;
|
||||||
let ord = Order.updateTotals(rec.order);
|
|
||||||
this.totalQty += ord.quantity;
|
let order = this.items[rec].order;
|
||||||
this.totalPrice += ord.TotalPriceProduct;
|
if (!order) {
|
||||||
|
order = this.items[rec];
|
||||||
}
|
}
|
||||||
|
order.TotalPriceProduct = 0;
|
||||||
|
this.totalQty += order.quantity + order.quantitypreordered;
|
||||||
|
|
||||||
|
// Calcolo Sconto
|
||||||
|
let sconti_da_applicare = [];
|
||||||
|
if (order.scontisticas) {
|
||||||
|
|
||||||
|
let qtadascontare = order.quantity + order.quantitypreordered
|
||||||
|
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)
|
||||||
|
}
|
||||||
|
}*/
|
||||||
|
|
||||||
|
if (sconti_da_applicare.length > 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) + (order.price * order.quantitypreordered);
|
||||||
|
}
|
||||||
|
order.TotalPriceProduct += mypricecalc;
|
||||||
|
this.totalPrice += order.TotalPriceProduct;
|
||||||
}
|
}
|
||||||
this.totalPrice = parseFloat(this.totalPrice.toFixed(2))
|
this.totalPrice = parseFloat(this.totalPrice.toFixed(2))
|
||||||
} catch (e) {
|
} catch (e) {
|
||||||
|
|||||||
@@ -72,7 +72,6 @@ router.post('/:userId', authenticate, async function (req, res, next) {
|
|||||||
let cart = null;
|
let cart = null;
|
||||||
let product = null;
|
let product = null;
|
||||||
// no cart save empty cart to database then return response
|
// no cart save empty cart to database then return response
|
||||||
let myqty = 0;
|
|
||||||
let nuovo = false;
|
let nuovo = false;
|
||||||
if (!mycart) {
|
if (!mycart) {
|
||||||
let oldCart = new CartClass(order)
|
let oldCart = new CartClass(order)
|
||||||
@@ -83,16 +82,21 @@ router.post('/:userId', authenticate, async function (req, res, next) {
|
|||||||
}
|
}
|
||||||
|
|
||||||
let newCart = CartClass.constructByCart(mycart);
|
let newCart = CartClass.constructByCart(mycart);
|
||||||
|
// order = await Product.updateProductInOrder(order);
|
||||||
if (!nuovo) {
|
if (!nuovo) {
|
||||||
if (addqty) {
|
if (addqty) {
|
||||||
myqty = await newCart.addqty(order);
|
myord = await newCart.addqty(order);
|
||||||
} else if (subqty) {
|
} else if (subqty) {
|
||||||
myqty = await newCart.subqty(order);
|
myord = await newCart.subqty(order);
|
||||||
} else {
|
} else {
|
||||||
const ind = newCart.addItem(order);
|
const ind = newCart.addItem(order);
|
||||||
|
const arrord = await Order.getTotalOrderById(order._id);
|
||||||
|
myord = arrord ? arrord[0] : null;
|
||||||
}
|
}
|
||||||
} else {
|
} else {
|
||||||
await newCart.updatetotals();
|
await newCart.updatetotals();
|
||||||
|
const arrord = await Order.getTotalOrderById(order._id);
|
||||||
|
myord = arrord ? arrord[0] : null;
|
||||||
}
|
}
|
||||||
cart = await Cart.updateCartByCartId(mycart._id, newCart.generateModel());
|
cart = await Cart.updateCartByCartId(mycart._id, newCart.generateModel());
|
||||||
|
|
||||||
@@ -103,9 +107,10 @@ router.post('/:userId', authenticate, async function (req, res, next) {
|
|||||||
product = await Product.getProductById(order.idProduct);
|
product = await Product.getProductById(order.idProduct);
|
||||||
else if (order.product)
|
else if (order.product)
|
||||||
product = await Product.getProductById(order.product._id);
|
product = await Product.getProductById(order.product._id);
|
||||||
return res.send({ code: server_constants.RIS_CODE_OK, cart: carttot, qty: myqty, product });
|
return res.send({ code: server_constants.RIS_CODE_OK, cart: carttot, myord, product });
|
||||||
} else {
|
} else {
|
||||||
return res.send({ code: server_constants.RIS_CODE_ERR, cart: null });
|
console.error('Err:', err);
|
||||||
|
return res.send({ code: server_constants.RIS_CODE_ERR, cart: null, myord: null });
|
||||||
}
|
}
|
||||||
|
|
||||||
/*
|
/*
|
||||||
@@ -308,6 +313,15 @@ router.post('/:userId/createorderscart', authenticate, async function (req, res,
|
|||||||
})
|
})
|
||||||
}
|
}
|
||||||
})
|
})
|
||||||
|
} else if (status < shared_consts.OrderStatus.CHECKOUT_SENT) {
|
||||||
|
// Aggiorna il carrello !
|
||||||
|
|
||||||
|
/*const cartpao = await Cart.getCartByUserId(userId, idapp);
|
||||||
|
let newCart = CartClass.constructByCart(cartpao);
|
||||||
|
if (newCart)
|
||||||
|
await newCart.updatetotals();
|
||||||
|
newCart;*/
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
@@ -377,9 +391,9 @@ router.post('/:userId/ordercartstatus', authenticate, async function (req, res,
|
|||||||
|
|
||||||
if (User.isManager(user.perm)) {
|
if (User.isManager(user.perm)) {
|
||||||
// Prende Tutti gli Ordini !
|
// Prende Tutti gli Ordini !
|
||||||
orderscart = await OrdersCart.getOrdersCartByUserId('ALL', idapp, 0);
|
orderscart = await OrdersCart.getOrdersCartByUserId('ALL', idapp, 0, false);
|
||||||
} else {
|
} else {
|
||||||
orderscart = await OrdersCart.getOrdersCartByUserId(req.user.id, idapp, 0);
|
orderscart = await OrdersCart.getOrdersCartByUserId(req.user.id, idapp, 0, false);
|
||||||
}
|
}
|
||||||
|
|
||||||
return res.send({ code: server_constants.RIS_CODE_OK, status, orders: orderscart });
|
return res.send({ code: server_constants.RIS_CODE_OK, status, orders: orderscart });
|
||||||
|
|||||||
@@ -66,6 +66,7 @@ const Cart = require('../models/cart');
|
|||||||
const OrdersCart = require('../models/orderscart');
|
const OrdersCart = require('../models/orderscart');
|
||||||
const Storehouse = require('../models/storehouse');
|
const Storehouse = require('../models/storehouse');
|
||||||
const Provider = require('../models/provider');
|
const Provider = require('../models/provider');
|
||||||
|
const Gasordine = require('../models/gasordine');
|
||||||
const Scontistica = require('../models/scontistica');
|
const Scontistica = require('../models/scontistica');
|
||||||
const Department = require('../models/department');
|
const Department = require('../models/department');
|
||||||
const { Category } = require('../models/category');
|
const { Category } = require('../models/category');
|
||||||
@@ -1434,6 +1435,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 gasordines = Gasordine.findAllIdApp(idapp);
|
||||||
let scontisticas = 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);
|
||||||
@@ -1466,9 +1468,9 @@ function load(req, res, version) {
|
|||||||
cart = Cart.getCartByUserId(req.user.id, idapp);
|
cart = Cart.getCartByUserId(req.user.id, idapp);
|
||||||
if (User.isManager(req.user.perm)) {
|
if (User.isManager(req.user.perm)) {
|
||||||
// Prende Tutti gli Ordini !
|
// Prende Tutti gli Ordini !
|
||||||
orderscart = OrdersCart.getOrdersCartByUserId('ALL', idapp, 0);
|
orderscart = OrdersCart.getOrdersCartByUserId('ALL', idapp, 0, false);
|
||||||
} else {
|
} else {
|
||||||
orderscart = OrdersCart.getOrdersCartByUserId(req.user.id, idapp, 0);
|
orderscart = OrdersCart.getOrdersCartByUserId(req.user.id, idapp, 0, false);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
let askedfriends = [];
|
let askedfriends = [];
|
||||||
@@ -1523,6 +1525,7 @@ function load(req, res, version) {
|
|||||||
categories, // 39
|
categories, // 39
|
||||||
providers,
|
providers,
|
||||||
scontisticas,
|
scontisticas,
|
||||||
|
gasordines,
|
||||||
]).then((arrdata) => {
|
]).then((arrdata) => {
|
||||||
// console.table(arrdata);
|
// console.table(arrdata);
|
||||||
let myuser = req.user;
|
let myuser = req.user;
|
||||||
@@ -1607,6 +1610,7 @@ function load(req, res, version) {
|
|||||||
categories: arrdata[39],
|
categories: arrdata[39],
|
||||||
providers: arrdata[40],
|
providers: arrdata[40],
|
||||||
scontisticas: arrdata[41],
|
scontisticas: arrdata[41],
|
||||||
|
gasordines: arrdata[42],
|
||||||
});
|
});
|
||||||
|
|
||||||
const prova = 1;
|
const prova = 1;
|
||||||
|
|||||||
@@ -30,14 +30,15 @@ const OrdersCart = require('../models/orderscart');
|
|||||||
router.get('/:userId', authenticate, function (req, res, next) {
|
router.get('/:userId', authenticate, function (req, res, next) {
|
||||||
let userId = req.body.userId
|
let userId = req.body.userId
|
||||||
let idapp = req.body.idapp
|
let idapp = req.body.idapp
|
||||||
OrdersCart.getOrdersCartByUserId(userId, idapp, 0, function (err, cart) {
|
OrdersCart.getOrdersCartByUserId(userId, idapp, 0, false)
|
||||||
if (err) return next(err)
|
.then((cart) => {
|
||||||
|
|
||||||
|
if (cart)
|
||||||
|
res.send({ code: server_constants.RIS_CODE_OK, cart });
|
||||||
|
else
|
||||||
|
res.status(400).send(e);
|
||||||
|
})
|
||||||
|
|
||||||
if (cart)
|
|
||||||
res.send({ code: server_constants.RIS_CODE_OK, cart });
|
|
||||||
else
|
|
||||||
res.status(400).send(e);
|
|
||||||
})
|
|
||||||
})
|
})
|
||||||
|
|
||||||
module.exports = router;
|
module.exports = router;
|
||||||
|
|||||||
@@ -36,9 +36,9 @@ router.post('/', auth_default, async function (req, res, next) {
|
|||||||
let orders = null;
|
let orders = null;
|
||||||
if (await User.isManagerById(userId)) {
|
if (await User.isManagerById(userId)) {
|
||||||
// Prende Tutti gli Ordini !
|
// Prende Tutti gli Ordini !
|
||||||
orders = await OrdersCart.getOrdersCartByUserId('ALL', idapp, 0);
|
orders = await OrdersCart.getOrdersCartByUserId('ALL', idapp, 0, false);
|
||||||
} else {
|
} else {
|
||||||
orders = await OrdersCart.getOrdersCartByUserId(userId, idapp, 0);
|
orders = await OrdersCart.getOrdersCartByUserId(userId, idapp, 0, false);
|
||||||
}
|
}
|
||||||
|
|
||||||
if (products)
|
if (products)
|
||||||
|
|||||||
@@ -61,6 +61,7 @@ const Cart = require('../models/cart');
|
|||||||
const OrdersCart = require('../models/orderscart');
|
const OrdersCart = require('../models/orderscart');
|
||||||
const Storehouse = require('../models/storehouse');
|
const Storehouse = require('../models/storehouse');
|
||||||
const Provider = require('../models/provider');
|
const Provider = require('../models/provider');
|
||||||
|
const Gasordine = require('../models/gasordine');
|
||||||
const Scontistica = require('../models/scontistica');
|
const Scontistica = require('../models/scontistica');
|
||||||
const Department = require('../models/department');
|
const Department = require('../models/department');
|
||||||
const { Category } = require('../models/category');
|
const { Category } = require('../models/category');
|
||||||
@@ -108,6 +109,8 @@ module.exports = {
|
|||||||
mytable = Storehouse;
|
mytable = Storehouse;
|
||||||
else if (tablename === 'providers')
|
else if (tablename === 'providers')
|
||||||
mytable = Provider;
|
mytable = Provider;
|
||||||
|
else if (tablename === 'gasordines')
|
||||||
|
mytable = Gasordine;
|
||||||
else if (tablename === 'scontisticas')
|
else if (tablename === 'scontisticas')
|
||||||
mytable = Scontistica;
|
mytable = Scontistica;
|
||||||
else if (tablename === 'departments')
|
else if (tablename === 'departments')
|
||||||
|
|||||||
Reference in New Issue
Block a user