- Categorie
- ProductInfo
This commit is contained in:
@@ -39,14 +39,19 @@ html
|
|||||||
- var note = orders.note
|
- var note = orders.note
|
||||||
- var index = 0
|
- var index = 0
|
||||||
|
|
||||||
each product in orders.items
|
each rec in orders.items
|
||||||
- var descr = product.order.product.name
|
- var descr = rec.order.product.productInfo.name
|
||||||
- var img = product.order.product.img
|
- var img = rec.order.product.productInfo.img
|
||||||
- var price = product.order.price
|
- var price = rec.order.price
|
||||||
- var after_price = product.order.after_price
|
- var after_price = rec.order.after_price
|
||||||
- var gasordine = product.order.gasordine.name
|
- var TotalPriceProduct = rec.order.TotalPriceProduct
|
||||||
- var qty = product.order.quantity
|
if (rec.order.gasordine)
|
||||||
- var qtypreordered = product.order.quantitypreordered
|
- var gasordine = rec.order.gasordine.name
|
||||||
|
else
|
||||||
|
- var gasordine = ''
|
||||||
|
|
||||||
|
- var qty = rec.order.quantity
|
||||||
|
- var qtypreordered = rec.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")
|
||||||
@@ -62,7 +67,7 @@ html
|
|||||||
td(class="column", valign="top")
|
td(class="column", valign="top")
|
||||||
|
|
||||||
table(cellpadding="0", cellspacing="0", summary="", border="0")
|
table(cellpadding="0", cellspacing="0", summary="", border="0")
|
||||||
if (qtypreordereded > 0)
|
if (qtypreordered > 0)
|
||||||
tr
|
tr
|
||||||
td(class="sectionContent", valign="top")
|
td(class="sectionContent", valign="top")
|
||||||
p Gas Ordine: #{gasordine}
|
p Gas Ordine: #{gasordine}
|
||||||
@@ -73,13 +78,14 @@ html
|
|||||||
td(class="sectionContent", valign="top")
|
td(class="sectionContent", valign="top")
|
||||||
p Prezzo: #{price} € #{after_price}
|
p Prezzo: #{price} € #{after_price}
|
||||||
if (qty > 0)
|
if (qty > 0)
|
||||||
tr
|
td(class="sectionContent", valign="top")
|
||||||
td(class="sectionContent", valign="top")
|
p Quantità: #{qty}
|
||||||
p Quantità: #{qty}
|
if (qtypreordered > 0)
|
||||||
if (qtypreordereded > 0)
|
td(class="sectionContent", valign="top")
|
||||||
tr
|
p Quantità Prenotata: #{qtypreordered}
|
||||||
td(class="sectionContent", valign="top")
|
tr
|
||||||
p Quantità Prenotata: #{qtypreorder}
|
td(class="sectionContent", valign="top")
|
||||||
|
p Totale: #{TotalPriceProduct} €
|
||||||
|
|
||||||
p Note Aggiuntive: #{note}
|
p Note Aggiuntive: #{note}
|
||||||
|
|
||||||
|
|||||||
@@ -39,14 +39,18 @@ html
|
|||||||
- var note = orders.note
|
- var note = orders.note
|
||||||
- var index = 0
|
- var index = 0
|
||||||
|
|
||||||
each product in orders.items
|
each rec in orders.items
|
||||||
- var descr = product.order.product.name
|
- var descr = rec.order.product.productInfo.name
|
||||||
- var img = product.order.product.img
|
- var img = rec.order.product.productInfo.img
|
||||||
- var price = product.order.product.price
|
- var price = rec.order.product.price
|
||||||
- var after_price = product.order.product.after_price
|
- var after_price = rec.order.product.after_price
|
||||||
- var gasordine = product.order.gasordine.name
|
if (rec.order.gasordine)
|
||||||
- var qty = product.order.product.quantity
|
- var gasordine = rec.order.gasordine.name
|
||||||
- var qtypreordered = product.order.quantitypreordered
|
else
|
||||||
|
- var gasordine = ''
|
||||||
|
- var qty = rec.order.product.quantity
|
||||||
|
- var qtypreordered = rec.order.quantitypreordered
|
||||||
|
- var TotalPriceProduct = rec.order.TotalPriceProduct
|
||||||
- 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")
|
||||||
@@ -62,7 +66,7 @@ html
|
|||||||
td(class="column", valign="top")
|
td(class="column", valign="top")
|
||||||
|
|
||||||
table(cellpadding="0", cellspacing="0", summary="", border="0")
|
table(cellpadding="0", cellspacing="0", summary="", border="0")
|
||||||
if (qtypreordereded > 0)
|
if (qtypreordered > 0)
|
||||||
tr
|
tr
|
||||||
td(class="sectionContent", valign="top")
|
td(class="sectionContent", valign="top")
|
||||||
p Gas Ordine: #{gasordine}
|
p Gas Ordine: #{gasordine}
|
||||||
@@ -80,6 +84,9 @@ html
|
|||||||
tr
|
tr
|
||||||
td(class="sectionContent", valign="top")
|
td(class="sectionContent", valign="top")
|
||||||
p Quantità Prenotata: #{qtypreordered}
|
p Quantità Prenotata: #{qtypreordered}
|
||||||
|
tr
|
||||||
|
td(class="sectionContent", valign="top")
|
||||||
|
p Totale: #{TotalPriceProduct} €
|
||||||
|
|
||||||
p Note Aggiuntive: #{note}
|
p Note Aggiuntive: #{note}
|
||||||
|
|
||||||
|
|||||||
56
src/server/models/catprod.js
Executable file
56
src/server/models/catprod.js
Executable file
@@ -0,0 +1,56 @@
|
|||||||
|
|
||||||
|
const mongoose = require('mongoose').set('debug', false)
|
||||||
|
const Schema = mongoose.Schema;
|
||||||
|
|
||||||
|
mongoose.Promise = global.Promise;
|
||||||
|
mongoose.level = "F";
|
||||||
|
|
||||||
|
const tools = require('../tools/general');
|
||||||
|
|
||||||
|
// Resolving error Unknown modifier: $pushAll
|
||||||
|
mongoose.plugin(schema => {
|
||||||
|
schema.options.usePushEach = true
|
||||||
|
});
|
||||||
|
|
||||||
|
const CatProdSchema = new Schema({
|
||||||
|
idapp: {
|
||||||
|
type: String,
|
||||||
|
},
|
||||||
|
name: {
|
||||||
|
type: String,
|
||||||
|
},
|
||||||
|
img: {
|
||||||
|
type: String,
|
||||||
|
},
|
||||||
|
});
|
||||||
|
|
||||||
|
CatProdSchema.statics.getAllCategories = function (callback) {
|
||||||
|
CatProd.find(callback)
|
||||||
|
}
|
||||||
|
|
||||||
|
CatProdSchema.statics.getCatProdById = function (id, callback) {
|
||||||
|
CatProd.findById(id, callback);
|
||||||
|
}
|
||||||
|
|
||||||
|
CatProdSchema.statics.getFieldsForSearch = function () {
|
||||||
|
return [{ field: 'name', type: tools.FieldType.string }]
|
||||||
|
};
|
||||||
|
|
||||||
|
CatProdSchema.statics.executeQueryTable = function (idapp, params) {
|
||||||
|
return tools.executeQueryTable(this, idapp, params);
|
||||||
|
};
|
||||||
|
|
||||||
|
CatProdSchema.statics.findAllIdApp = async function (idapp) {
|
||||||
|
const myfind = { idapp };
|
||||||
|
|
||||||
|
return await CatProd.find(myfind).sort({ name: 1 });
|
||||||
|
};
|
||||||
|
|
||||||
|
const CatProd = mongoose.model('CatProd', CatProdSchema);
|
||||||
|
|
||||||
|
CatProd.createIndexes((err) => {
|
||||||
|
if (err) throw err;
|
||||||
|
});
|
||||||
|
|
||||||
|
|
||||||
|
module.exports = CatProd;
|
||||||
@@ -34,6 +34,7 @@ const gasordineSchema = new Schema({
|
|||||||
img: {
|
img: {
|
||||||
type: String,
|
type: String,
|
||||||
},
|
},
|
||||||
|
|
||||||
dataora_chiusura_ordini: {
|
dataora_chiusura_ordini: {
|
||||||
type: Date,
|
type: Date,
|
||||||
},
|
},
|
||||||
@@ -43,6 +44,7 @@ const gasordineSchema = new Schema({
|
|||||||
dataora_termine_pagamento: {
|
dataora_termine_pagamento: {
|
||||||
type: Date,
|
type: Date,
|
||||||
},
|
},
|
||||||
|
|
||||||
});
|
});
|
||||||
|
|
||||||
var Gasordine = module.exports = mongoose.model('Gasordine', gasordineSchema);
|
var Gasordine = module.exports = mongoose.model('Gasordine', gasordineSchema);
|
||||||
|
|||||||
@@ -154,10 +154,24 @@ module.exports.findAllIdApp = async function (idapp) {
|
|||||||
as: 'product'
|
as: 'product'
|
||||||
}
|
}
|
||||||
},
|
},
|
||||||
|
{
|
||||||
|
$lookup: {
|
||||||
|
from: 'productinfos',
|
||||||
|
localField: 'product.idProduct',
|
||||||
|
foreignField: '_id',
|
||||||
|
as: 'product.productInfo'
|
||||||
|
}
|
||||||
|
},
|
||||||
|
{
|
||||||
|
$unwind: {
|
||||||
|
path: '$product.productInfo',
|
||||||
|
preserveNullAndEmptyArrays: true,
|
||||||
|
},
|
||||||
|
},
|
||||||
{
|
{
|
||||||
$lookup: {
|
$lookup: {
|
||||||
from: 'producers',
|
from: 'producers',
|
||||||
localField: 'idProducer',
|
localField: 'product.idProducer',
|
||||||
foreignField: '_id',
|
foreignField: '_id',
|
||||||
as: 'producer'
|
as: 'producer'
|
||||||
}
|
}
|
||||||
@@ -165,7 +179,7 @@ module.exports.findAllIdApp = async function (idapp) {
|
|||||||
{
|
{
|
||||||
$lookup: {
|
$lookup: {
|
||||||
from: 'providers',
|
from: 'providers',
|
||||||
localField: 'idProvider',
|
localField: 'product.idProvider',
|
||||||
foreignField: '_id',
|
foreignField: '_id',
|
||||||
as: 'provider'
|
as: 'provider'
|
||||||
}
|
}
|
||||||
@@ -178,15 +192,24 @@ module.exports.findAllIdApp = async function (idapp) {
|
|||||||
as: 'gasordine'
|
as: 'gasordine'
|
||||||
}
|
}
|
||||||
},
|
},
|
||||||
|
{
|
||||||
|
$unwind: {
|
||||||
|
path: '$gasordine',
|
||||||
|
preserveNullAndEmptyArrays: true,
|
||||||
|
},
|
||||||
|
},
|
||||||
{
|
{
|
||||||
$match: {
|
$match: {
|
||||||
'gasordine.active': true
|
$or: [
|
||||||
|
{ 'gasordine': { $exists: false } },
|
||||||
|
{ 'gasordine.active': true }
|
||||||
|
]
|
||||||
}
|
}
|
||||||
},
|
},
|
||||||
{
|
{
|
||||||
$lookup: {
|
$lookup: {
|
||||||
from: 'scontisticas',
|
from: 'scontisticas',
|
||||||
localField: 'idScontisticas',
|
localField: 'product.idScontisticas',
|
||||||
foreignField: '_id',
|
foreignField: '_id',
|
||||||
as: 'scontistica'
|
as: 'scontistica'
|
||||||
}
|
}
|
||||||
@@ -209,12 +232,6 @@ module.exports.findAllIdApp = async function (idapp) {
|
|||||||
preserveNullAndEmptyArrays: true,
|
preserveNullAndEmptyArrays: true,
|
||||||
},
|
},
|
||||||
},
|
},
|
||||||
{
|
|
||||||
$unwind: {
|
|
||||||
path: '$gasordine',
|
|
||||||
preserveNullAndEmptyArrays: true,
|
|
||||||
},
|
|
||||||
}
|
|
||||||
|
|
||||||
];
|
];
|
||||||
|
|
||||||
@@ -270,9 +287,9 @@ module.exports.updateTotals = function (order) {
|
|||||||
|
|
||||||
try {
|
try {
|
||||||
if (!order) {
|
if (!order) {
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
let mypricecalc = 0;
|
let mypricecalc = 0;
|
||||||
order.TotalPriceProduct = 0;
|
order.TotalPriceProduct = 0;
|
||||||
|
|
||||||
@@ -342,10 +359,30 @@ module.exports.getTotalOrderById = async function (id) {
|
|||||||
as: 'product'
|
as: 'product'
|
||||||
}
|
}
|
||||||
},
|
},
|
||||||
|
{
|
||||||
|
$unwind: {
|
||||||
|
path: '$product',
|
||||||
|
preserveNullAndEmptyArrays: true,
|
||||||
|
},
|
||||||
|
},
|
||||||
|
{
|
||||||
|
$lookup: {
|
||||||
|
from: 'productinfos',
|
||||||
|
localField: 'product.idProductInfo',
|
||||||
|
foreignField: '_id',
|
||||||
|
as: 'product.productInfo'
|
||||||
|
}
|
||||||
|
},
|
||||||
|
{
|
||||||
|
$unwind: {
|
||||||
|
path: '$product.productInfo',
|
||||||
|
preserveNullAndEmptyArrays: true,
|
||||||
|
},
|
||||||
|
},
|
||||||
{
|
{
|
||||||
$lookup: {
|
$lookup: {
|
||||||
from: 'producers',
|
from: 'producers',
|
||||||
localField: 'idProducer',
|
localField: 'product.idProducer',
|
||||||
foreignField: '_id',
|
foreignField: '_id',
|
||||||
as: 'producer'
|
as: 'producer'
|
||||||
}
|
}
|
||||||
@@ -361,7 +398,7 @@ module.exports.getTotalOrderById = async function (id) {
|
|||||||
{
|
{
|
||||||
$lookup: {
|
$lookup: {
|
||||||
from: 'providers',
|
from: 'providers',
|
||||||
localField: 'idProvider',
|
localField: 'product.idProvider',
|
||||||
foreignField: '_id',
|
foreignField: '_id',
|
||||||
as: 'provider'
|
as: 'provider'
|
||||||
}
|
}
|
||||||
@@ -374,25 +411,28 @@ module.exports.getTotalOrderById = async function (id) {
|
|||||||
as: 'gasordine'
|
as: 'gasordine'
|
||||||
}
|
}
|
||||||
},
|
},
|
||||||
|
{
|
||||||
|
$unwind: {
|
||||||
|
path: '$gasordine',
|
||||||
|
preserveNullAndEmptyArrays: true,
|
||||||
|
},
|
||||||
|
},
|
||||||
{
|
{
|
||||||
$match: {
|
$match: {
|
||||||
'gasordine.active': true
|
$or: [
|
||||||
|
{ 'gasordine': { $exists: false } },
|
||||||
|
{ 'gasordine.active': true }
|
||||||
|
]
|
||||||
}
|
}
|
||||||
},
|
},
|
||||||
{
|
{
|
||||||
$lookup: {
|
$lookup: {
|
||||||
from: 'scontisticas',
|
from: 'scontisticas',
|
||||||
localField: 'idScontisticas',
|
localField: 'product.idScontisticas',
|
||||||
foreignField: '_id',
|
foreignField: '_id',
|
||||||
as: 'scontisticas'
|
as: 'scontisticas'
|
||||||
}
|
}
|
||||||
},
|
},
|
||||||
{
|
|
||||||
$unwind: {
|
|
||||||
path: '$product',
|
|
||||||
preserveNullAndEmptyArrays: true,
|
|
||||||
},
|
|
||||||
},
|
|
||||||
{
|
{
|
||||||
$unwind: {
|
$unwind: {
|
||||||
path: '$producer',
|
path: '$producer',
|
||||||
@@ -411,12 +451,6 @@ module.exports.getTotalOrderById = async function (id) {
|
|||||||
preserveNullAndEmptyArrays: true,
|
preserveNullAndEmptyArrays: true,
|
||||||
},
|
},
|
||||||
},
|
},
|
||||||
{
|
|
||||||
$unwind: {
|
|
||||||
path: '$gasordine',
|
|
||||||
preserveNullAndEmptyArrays: true,
|
|
||||||
},
|
|
||||||
},
|
|
||||||
{
|
{
|
||||||
$lookup: {
|
$lookup: {
|
||||||
from: 'orders',
|
from: 'orders',
|
||||||
|
|||||||
@@ -10,6 +10,7 @@ const Storehouse = require('../models/storehouse');
|
|||||||
const Provider = require('../models/provider');
|
const Provider = require('../models/provider');
|
||||||
const Gasordine = require('../models/gasordine');
|
const Gasordine = require('../models/gasordine');
|
||||||
const Product = require('../models/product');
|
const Product = require('../models/product');
|
||||||
|
const ProductInfo = require('../models/productinfo');
|
||||||
|
|
||||||
const tools = require('../tools/general');
|
const tools = require('../tools/general');
|
||||||
|
|
||||||
@@ -178,90 +179,6 @@ module.exports.getOrdersCartById = async function (id) {
|
|||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
module.exports.getOLDOrdersCartByQuery = 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.getOrdersCartByQuery = async function (query) {
|
module.exports.getOrdersCartByQuery = async function (query) {
|
||||||
|
|
||||||
@@ -274,6 +191,16 @@ module.exports.getOrdersCartByQuery = async function (query) {
|
|||||||
model: 'Product'
|
model: 'Product'
|
||||||
},
|
},
|
||||||
})
|
})
|
||||||
|
.populate({
|
||||||
|
path: 'items.order',
|
||||||
|
populate: {
|
||||||
|
path: 'idProduct',
|
||||||
|
populate: {
|
||||||
|
path: 'idProductInfo',
|
||||||
|
model: 'ProductInfo'
|
||||||
|
},
|
||||||
|
},
|
||||||
|
})
|
||||||
.populate({
|
.populate({
|
||||||
path: 'items.order',
|
path: 'items.order',
|
||||||
populate: {
|
populate: {
|
||||||
@@ -324,6 +251,10 @@ module.exports.getOrdersCartByQuery = async function (query) {
|
|||||||
try {
|
try {
|
||||||
item.order.product = item.order.idProduct;
|
item.order.product = item.order.idProduct;
|
||||||
item.order.idProduct = item.order.product ? item.order.product._id : '';
|
item.order.idProduct = item.order.product ? item.order.product._id : '';
|
||||||
|
if (item.order.product.idProductInfo) {
|
||||||
|
item.order.product.productInfo = item.order.product.idProductInfo;
|
||||||
|
item.order.product.idProductInfo = item.order.product ? item.order.product.productInfo._id : '';
|
||||||
|
}
|
||||||
item.order.producer = item.order.idProducer;
|
item.order.producer = item.order.idProducer;
|
||||||
item.order.idProducer = item.order.producer ? 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;
|
||||||
@@ -653,7 +584,7 @@ module.exports.getmsgorderTelegram = async function (ordersCart) {
|
|||||||
qtystr += 'Ordinate: ' + ord.order.quantity
|
qtystr += 'Ordinate: ' + ord.order.quantity
|
||||||
if (ord.order.quantitypreordered > 0)
|
if (ord.order.quantitypreordered > 0)
|
||||||
qtystr += ' Pre-Ordinate: ' + ord.order.quantitypreordered
|
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 += '✅ [' + qtystr + '] ' + ord.order.product.productInfo.name + ' (' + ord.order.price + ' € ' + (ord.order.after_price ? ord.order.after_price : '') + ' Tot=' + ord.order.TotalPriceProduct + '€ )';
|
||||||
}
|
}
|
||||||
|
|
||||||
msg += '<br>';
|
msg += '<br>';
|
||||||
|
|||||||
@@ -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 CatProd = require('../models/catprod');
|
||||||
const Gasordine = require('../models/gasordine');
|
const Gasordine = require('../models/gasordine');
|
||||||
const Scontistica = require('../models/scontistica');
|
const Scontistica = require('../models/scontistica');
|
||||||
|
|
||||||
@@ -31,6 +32,7 @@ const productSchema = new Schema({
|
|||||||
type: Boolean,
|
type: Boolean,
|
||||||
default: true,
|
default: true,
|
||||||
},
|
},
|
||||||
|
idProductInfo: { type: Schema.Types.ObjectId, ref: 'ProductInfo' },
|
||||||
idProducer: { type: Schema.Types.ObjectId, ref: 'Producer' },
|
idProducer: { type: Schema.Types.ObjectId, ref: 'Producer' },
|
||||||
idStorehouses: [
|
idStorehouses: [
|
||||||
{ type: Schema.Types.ObjectId, ref: 'Storehouse' }
|
{ type: Schema.Types.ObjectId, ref: 'Storehouse' }
|
||||||
@@ -42,29 +44,6 @@ const productSchema = new Schema({
|
|||||||
{ type: Schema.Types.ObjectId, ref: 'Scontistica' }
|
{ type: Schema.Types.ObjectId, ref: 'Scontistica' }
|
||||||
],
|
],
|
||||||
idProvider: { type: Schema.Types.ObjectId, ref: 'Provider' },
|
idProvider: { type: Schema.Types.ObjectId, ref: 'Provider' },
|
||||||
code: {
|
|
||||||
type: String,
|
|
||||||
unique: true,
|
|
||||||
required: true,
|
|
||||||
},
|
|
||||||
codice_EAN: {
|
|
||||||
type: String,
|
|
||||||
},
|
|
||||||
barcode: {
|
|
||||||
type: String,
|
|
||||||
},
|
|
||||||
name: {
|
|
||||||
type: String,
|
|
||||||
},
|
|
||||||
description: {
|
|
||||||
type: String,
|
|
||||||
},
|
|
||||||
department: {
|
|
||||||
type: String, ref: 'Department'
|
|
||||||
},
|
|
||||||
category: {
|
|
||||||
type: Array,
|
|
||||||
},
|
|
||||||
prezzo_ivato: { // Con IVA
|
prezzo_ivato: { // Con IVA
|
||||||
type: Number
|
type: Number
|
||||||
},
|
},
|
||||||
@@ -82,26 +61,15 @@ const productSchema = new Schema({
|
|||||||
after_price: {
|
after_price: {
|
||||||
type: String
|
type: String
|
||||||
},
|
},
|
||||||
color: {
|
|
||||||
type: String
|
|
||||||
},
|
|
||||||
size: {
|
|
||||||
type: String
|
|
||||||
},
|
|
||||||
weight: {
|
|
||||||
type: Number
|
|
||||||
},
|
|
||||||
vegan: {
|
|
||||||
type: Boolean
|
|
||||||
},
|
|
||||||
unit: {
|
|
||||||
type: Number
|
|
||||||
},
|
|
||||||
minBuyQty: { // quantità minima acquistabile
|
minBuyQty: { // quantità minima acquistabile
|
||||||
type: Number,
|
type: Number,
|
||||||
default: 1,
|
default: 1,
|
||||||
required: true,
|
required: true,
|
||||||
},
|
},
|
||||||
|
maxBookableQty: { // quantità massima Pre-ordinabile (singolarmente)
|
||||||
|
type: Number,
|
||||||
|
default: 0,
|
||||||
|
},
|
||||||
stockQty: { // in magazzino
|
stockQty: { // in magazzino
|
||||||
type: Number,
|
type: Number,
|
||||||
default: 0,
|
default: 0,
|
||||||
@@ -133,30 +101,6 @@ const productSchema = new Schema({
|
|||||||
dateAvailableFrom: {
|
dateAvailableFrom: {
|
||||||
type: Date
|
type: Date
|
||||||
},
|
},
|
||||||
icon: {
|
|
||||||
type: String,
|
|
||||||
},
|
|
||||||
img: {
|
|
||||||
type: String,
|
|
||||||
},
|
|
||||||
link: {
|
|
||||||
type: String,
|
|
||||||
},
|
|
||||||
img2: {
|
|
||||||
type: String,
|
|
||||||
},
|
|
||||||
img3: {
|
|
||||||
type: String,
|
|
||||||
},
|
|
||||||
ingredienti: {
|
|
||||||
type: String,
|
|
||||||
},
|
|
||||||
valori_nutrizionali: {
|
|
||||||
type: String,
|
|
||||||
},
|
|
||||||
note: {
|
|
||||||
type: String,
|
|
||||||
},
|
|
||||||
producer_name: {
|
producer_name: {
|
||||||
type: String,
|
type: String,
|
||||||
},
|
},
|
||||||
@@ -166,6 +110,9 @@ const productSchema = new Schema({
|
|||||||
magazzino_name: {
|
magazzino_name: {
|
||||||
type: String,
|
type: String,
|
||||||
},
|
},
|
||||||
|
cat_name: {
|
||||||
|
type: String,
|
||||||
|
},
|
||||||
});
|
});
|
||||||
|
|
||||||
var Product = module.exports = mongoose.model('Product', productSchema);
|
var Product = module.exports = mongoose.model('Product', productSchema);
|
||||||
@@ -244,6 +191,20 @@ module.exports.findAllIdApp = async function (idapp, code, id) {
|
|||||||
preserveNullAndEmptyArrays: true,
|
preserveNullAndEmptyArrays: true,
|
||||||
},
|
},
|
||||||
},
|
},
|
||||||
|
{
|
||||||
|
$lookup: {
|
||||||
|
from: 'productinfos',
|
||||||
|
localField: 'idProductInfo',
|
||||||
|
foreignField: '_id',
|
||||||
|
as: 'productInfo'
|
||||||
|
}
|
||||||
|
},
|
||||||
|
{
|
||||||
|
$unwind: {
|
||||||
|
path: '$productInfo',
|
||||||
|
preserveNullAndEmptyArrays: true,
|
||||||
|
},
|
||||||
|
},
|
||||||
{
|
{
|
||||||
$lookup: {
|
$lookup: {
|
||||||
from: 'gasordines',
|
from: 'gasordines',
|
||||||
@@ -300,6 +261,14 @@ module.exports.findAllIdApp = async function (idapp, code, id) {
|
|||||||
preserveNullAndEmptyArrays: true,
|
preserveNullAndEmptyArrays: true,
|
||||||
},
|
},
|
||||||
},
|
},
|
||||||
|
{
|
||||||
|
$lookup: {
|
||||||
|
from: 'catprods',
|
||||||
|
localField: 'idCatProds',
|
||||||
|
foreignField: '_id',
|
||||||
|
as: 'catprods'
|
||||||
|
}
|
||||||
|
},
|
||||||
{
|
{
|
||||||
$lookup: {
|
$lookup: {
|
||||||
from: 'scontisticas',
|
from: 'scontisticas',
|
||||||
@@ -410,7 +379,11 @@ module.exports.findAllIdApp = async function (idapp, code, id) {
|
|||||||
{
|
{
|
||||||
$unset: 'productPreOrders'
|
$unset: 'productPreOrders'
|
||||||
},
|
},
|
||||||
|
{
|
||||||
|
$sort: {
|
||||||
|
'productInfo.name': 1 // 1 for ascending order, -1 for descending order
|
||||||
|
}
|
||||||
|
},
|
||||||
);
|
);
|
||||||
|
|
||||||
// console.log('query=', query);
|
// console.log('query=', query);
|
||||||
@@ -436,7 +409,7 @@ module.exports.getProductByDepartment = function (query, sort, callback) {
|
|||||||
Product.find(query, null, sort, callback)
|
Product.find(query, null, sort, callback)
|
||||||
}
|
}
|
||||||
|
|
||||||
module.exports.getProductByCategory = function (query, sort, callback) {
|
module.exports.getProductByCatProd = function (query, sort, callback) {
|
||||||
Product.find(query, null, sort, callback)
|
Product.find(query, null, sort, callback)
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -450,9 +423,9 @@ module.exports.filterProductByDepartment = function (department, callback) {
|
|||||||
Product.find(query, callback)
|
Product.find(query, callback)
|
||||||
}
|
}
|
||||||
|
|
||||||
module.exports.filterProductByCategory = function (category, callback) {
|
module.exports.filterProductByCatProd = function (catprod, callback) {
|
||||||
let regexp = new RegExp(`^${category}$`, 'i')
|
let regexp = new RegExp(`^${catprod}$`, 'i')
|
||||||
var query = { category: { $regex: regexp } };
|
var query = { catprod: { $regex: regexp } };
|
||||||
Product.find(query, callback);
|
Product.find(query, callback);
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -487,16 +460,20 @@ module.exports.convertAfterImport = async function (idapp, dataObjects) {
|
|||||||
|
|
||||||
};
|
};
|
||||||
|
|
||||||
module.exports.singlerecconvert_AfterImport = async function (idapp, prod) {
|
module.exports.singlerecconvert_AfterImport = async function (idapp, prod, isnuovo) {
|
||||||
|
|
||||||
let setta = false;
|
let setta = false;
|
||||||
|
|
||||||
try {
|
try {
|
||||||
|
let objtoset = {}
|
||||||
|
|
||||||
// Impostazioni Base:
|
// Impostazioni Base:
|
||||||
let objtoset = {
|
if (isnuovo) {
|
||||||
idapp,
|
objtoset = {
|
||||||
img: 'upload/products/' + prod.code + '.jpg',
|
idapp,
|
||||||
minBuyQty: 1,
|
minBuyQty: 1,
|
||||||
|
maxBookableQty: 0,
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
if (prod.producer_name) {
|
if (prod.producer_name) {
|
||||||
@@ -569,8 +546,17 @@ module.exports.singlerecconvert_AfterImport = async function (idapp, prod) {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
if (setta) {
|
if (!tools.isObjectEmpty(objtoset)) {
|
||||||
const ris = await Product.findOneAndUpdate({ _id: ObjectID(prod._id) }, { $set: objtoset })
|
ris = await Product.findOneAndUpdate({ _id: ObjectID(prod._id) }, { $set: objtoset })
|
||||||
|
|
||||||
|
const objDelete = {
|
||||||
|
cat_name: 1,
|
||||||
|
producer_name: 1,
|
||||||
|
provider_name: 1,
|
||||||
|
magazzino_name: 1,
|
||||||
|
};
|
||||||
|
|
||||||
|
ris = await Product.updateOne({ _id: ObjectID(prod._id) }, { $unset: objDelete })
|
||||||
|
|
||||||
if (ris) {
|
if (ris) {
|
||||||
console.log('ris', ris);
|
console.log('ris', ris);
|
||||||
|
|||||||
156
src/server/models/productInfo.js
Executable file
156
src/server/models/productInfo.js
Executable file
@@ -0,0 +1,156 @@
|
|||||||
|
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 productInfoSchema = new Schema({
|
||||||
|
idapp: {
|
||||||
|
type: String,
|
||||||
|
},
|
||||||
|
department: {
|
||||||
|
type: String, ref: 'Department'
|
||||||
|
},
|
||||||
|
code: {
|
||||||
|
type: String,
|
||||||
|
unique: true,
|
||||||
|
required: true,
|
||||||
|
},
|
||||||
|
codice_EAN: {
|
||||||
|
type: String,
|
||||||
|
},
|
||||||
|
barcode: {
|
||||||
|
type: String,
|
||||||
|
},
|
||||||
|
name: {
|
||||||
|
type: String,
|
||||||
|
},
|
||||||
|
description: {
|
||||||
|
type: String,
|
||||||
|
},
|
||||||
|
idCatProds: [{ type: Schema.Types.ObjectId, ref: 'CatProd' }],
|
||||||
|
color: {
|
||||||
|
type: String
|
||||||
|
},
|
||||||
|
size: {
|
||||||
|
type: String
|
||||||
|
},
|
||||||
|
weight: {
|
||||||
|
type: Number
|
||||||
|
},
|
||||||
|
vegan: {
|
||||||
|
type: Boolean
|
||||||
|
},
|
||||||
|
unit: {
|
||||||
|
type: Number
|
||||||
|
},
|
||||||
|
icon: {
|
||||||
|
type: String,
|
||||||
|
},
|
||||||
|
img: {
|
||||||
|
type: String,
|
||||||
|
},
|
||||||
|
link: {
|
||||||
|
type: String,
|
||||||
|
},
|
||||||
|
img2: {
|
||||||
|
type: String,
|
||||||
|
},
|
||||||
|
img3: {
|
||||||
|
type: String,
|
||||||
|
},
|
||||||
|
ingredienti: {
|
||||||
|
type: String,
|
||||||
|
},
|
||||||
|
valori_nutrizionali: {
|
||||||
|
type: String,
|
||||||
|
},
|
||||||
|
note: {
|
||||||
|
type: String,
|
||||||
|
},
|
||||||
|
|
||||||
|
});
|
||||||
|
|
||||||
|
var productInfo = module.exports = mongoose.model('ProductInfo', productInfoSchema);
|
||||||
|
|
||||||
|
module.exports.getFieldsForSearch = function () {
|
||||||
|
return [{ field: 'name', 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, code, id) {
|
||||||
|
let myfind = {};
|
||||||
|
let myqueryadd = {};
|
||||||
|
let query = [];
|
||||||
|
|
||||||
|
try {
|
||||||
|
|
||||||
|
if (idapp)
|
||||||
|
myfind = { idapp };
|
||||||
|
|
||||||
|
if (code) {
|
||||||
|
myfind = { ...myfind, code }
|
||||||
|
}
|
||||||
|
if (id) {
|
||||||
|
myqueryadd = {
|
||||||
|
$addFields: {
|
||||||
|
myId1: {
|
||||||
|
$toObjectId: id,
|
||||||
|
},
|
||||||
|
},
|
||||||
|
}
|
||||||
|
myfind = {
|
||||||
|
$expr: {
|
||||||
|
$eq: ["$_id", "$myId1"],
|
||||||
|
},
|
||||||
|
}
|
||||||
|
|
||||||
|
query.push(myqueryadd);
|
||||||
|
}
|
||||||
|
|
||||||
|
query.push(
|
||||||
|
{ $match: myfind },
|
||||||
|
{
|
||||||
|
$lookup: {
|
||||||
|
from: 'catprods',
|
||||||
|
localField: 'idCatProds',
|
||||||
|
foreignField: '_id',
|
||||||
|
as: 'catprods'
|
||||||
|
}
|
||||||
|
},
|
||||||
|
{
|
||||||
|
$sort: {
|
||||||
|
name: 1 // 1 for ascending order, -1 for descending order
|
||||||
|
}
|
||||||
|
},
|
||||||
|
);
|
||||||
|
|
||||||
|
let ris = await productInfo.aggregate(query)
|
||||||
|
|
||||||
|
return ris;
|
||||||
|
|
||||||
|
} catch (e) {
|
||||||
|
console.error('E', e);
|
||||||
|
}
|
||||||
|
|
||||||
|
};
|
||||||
|
|
||||||
|
module.exports.getProductByCode = function (idapp, code) {
|
||||||
|
return productInfo.findAllIdApp(idapp, code);
|
||||||
|
}
|
||||||
|
|
||||||
|
module.exports.createIndexes((err) => {
|
||||||
|
if (err) throw err;
|
||||||
|
});
|
||||||
@@ -40,12 +40,21 @@ const storehouseSchema = new Schema({
|
|||||||
website: {
|
website: {
|
||||||
type: String,
|
type: String,
|
||||||
},
|
},
|
||||||
|
stockQty: { // in magazzino
|
||||||
|
type: Number,
|
||||||
|
default: 0,
|
||||||
|
},
|
||||||
|
bookableQty: { // Quantità prenotabili
|
||||||
|
type: Number,
|
||||||
|
default: 0,
|
||||||
|
},
|
||||||
|
|
||||||
});
|
});
|
||||||
|
|
||||||
var Storehouse = module.exports = mongoose.model('Storehouse', storehouseSchema);
|
var Storehouse = module.exports = mongoose.model('Storehouse', storehouseSchema);
|
||||||
|
|
||||||
module.exports.getFieldsForSearch = function () {
|
module.exports.getFieldsForSearch = function () {
|
||||||
return [{field: 'name', type: tools.FieldType.string}]
|
return [{ field: 'name', type: tools.FieldType.string }]
|
||||||
};
|
};
|
||||||
|
|
||||||
module.exports.executeQueryTable = function (idapp, params) {
|
module.exports.executeQueryTable = function (idapp, params) {
|
||||||
|
|||||||
@@ -61,16 +61,16 @@ class Cart {
|
|||||||
let step = 1;
|
let step = 1;
|
||||||
if (this.isAvailableByOrder(myitem.order)) {
|
if (this.isAvailableByOrder(myitem.order)) {
|
||||||
if (myitem.order.quantity === 0)
|
if (myitem.order.quantity === 0)
|
||||||
step = myitem.order.minBuyQty
|
step = myitem.order.product.minBuyQty | 1
|
||||||
else if (myitem.order.quantity >= 10)
|
else if (myitem.order.quantity >= 10)
|
||||||
step = 2
|
step = 2
|
||||||
else if (myitem.order.quantity >= 20)
|
else if (myitem.order.quantity >= 20)
|
||||||
step = 5
|
step = 5
|
||||||
|
|
||||||
myitem.order.quantity += step;
|
myitem.order.quantity += step;
|
||||||
} else {
|
} else {
|
||||||
if (myitem.order.quantitypreordered === 0)
|
if (myitem.order.quantitypreordered === 0)
|
||||||
step = myitem.order.minBuyQty
|
step = myitem.order.product.minBuyQty | 1
|
||||||
else if (myitem.order.quantitypreordered >= 10)
|
else if (myitem.order.quantitypreordered >= 10)
|
||||||
step = 2
|
step = 2
|
||||||
else if (myitem.order.quantitypreordered >= 20)
|
else if (myitem.order.quantitypreordered >= 20)
|
||||||
@@ -90,7 +90,7 @@ class Cart {
|
|||||||
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) {
|
||||||
if (myitem.order.quantitypreordered > 0) {
|
if (myitem.order.quantitypreordered > 0) {
|
||||||
myitem.order.quantitypreordered -= myitem.order.product.minBuyQty | 1;
|
myitem.order.quantitypreordered--;
|
||||||
} else {
|
} else {
|
||||||
if (myitem.order.quantity > 0) {
|
if (myitem.order.quantity > 0) {
|
||||||
myitem.order.quantity--;
|
myitem.order.quantity--;
|
||||||
@@ -108,6 +108,7 @@ class Cart {
|
|||||||
|
|
||||||
addItem(itemorder) {
|
addItem(itemorder) {
|
||||||
// this.items.push(itemorder);
|
// this.items.push(itemorder);
|
||||||
|
|
||||||
let ind = this.items.length;
|
let ind = this.items.length;
|
||||||
this.items[ind] = {};
|
this.items[ind] = {};
|
||||||
this.items[ind].order = itemorder;
|
this.items[ind].order = itemorder;
|
||||||
|
|||||||
@@ -9,6 +9,8 @@ const tools = require('../tools/general');
|
|||||||
|
|
||||||
const { City } = require('../models/city');
|
const { City } = require('../models/city');
|
||||||
const Product = require('../models/product');
|
const Product = require('../models/product');
|
||||||
|
const ProductInfo = require('../models/productinfo');
|
||||||
|
const CatProd = require('../models/catprod');
|
||||||
|
|
||||||
var { authenticate } = require('../middleware/authenticate');
|
var { authenticate } = require('../middleware/authenticate');
|
||||||
|
|
||||||
@@ -55,32 +57,90 @@ router.post('/import', authenticate, async (req, res) => {
|
|||||||
let errors = 0;
|
let errors = 0;
|
||||||
|
|
||||||
for (const product of dataObjects) {
|
for (const product of dataObjects) {
|
||||||
|
let isnuovo = false
|
||||||
|
let setta = false
|
||||||
|
|
||||||
|
let productInfo = {
|
||||||
|
idapp: product.idapp,
|
||||||
|
code: product.code,
|
||||||
|
name: product.name,
|
||||||
|
link: product.link,
|
||||||
|
idCatProds: [],
|
||||||
|
img: 'upload/products/' + product.code + '.jpg',
|
||||||
|
}
|
||||||
|
|
||||||
|
if (product.cat_name) {
|
||||||
|
// Cerca la Categoria
|
||||||
|
let reccateg = await CatProd.findOne({ idapp, name: product.cat_name }).lean();
|
||||||
|
if (!reccateg) {
|
||||||
|
// Non esiste questo produttore, quindi lo creo !
|
||||||
|
reccateg = new CatProd({ idapp, name: product.cat_name });
|
||||||
|
ris = await reccateg.save();
|
||||||
|
reccateg = await CatProd.findOne({ idapp, name: product.cat_name }).lean();
|
||||||
|
}
|
||||||
|
|
||||||
|
if (reccateg) {
|
||||||
|
productInfo.idCatProds.push(reccateg._id);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
if (!product.hasOwnProperty('active')) {
|
if (!product.hasOwnProperty('active')) {
|
||||||
product.active = true;
|
product.active = true;
|
||||||
}
|
}
|
||||||
let risrec = await Product.findOneAndUpdate({ code: product.code }, { $set: product }, { new: true, upsert: true });
|
|
||||||
|
|
||||||
let recnew = await Product.findOne({ code: product.code }).lean();
|
delete product.code;
|
||||||
|
delete product.name;
|
||||||
|
delete product.link;
|
||||||
|
|
||||||
if (risrec) {
|
// Update ProductInfo
|
||||||
if (risrec._id) {
|
let risrecInfo = await ProductInfo.findOneAndUpdate({ code: productInfo.code }, { $set: productInfo }, { new: true, upsert: true });
|
||||||
|
if (risrecInfo) {
|
||||||
|
product.idProductInfo = risrecInfo._id;
|
||||||
|
|
||||||
|
recnewInfo = await ProductInfo.findOne({ code: productInfo.code }).lean();
|
||||||
|
|
||||||
|
if (risrecInfo._id) {
|
||||||
// Record existed, so it was updated
|
// Record existed, so it was updated
|
||||||
let arrfieldchange = tools.differentObjects(product, recnew);
|
let arrfieldchange = tools.differentObjects(productInfo, recnewInfo);
|
||||||
if (arrfieldchange.length > 0) {
|
if (arrfieldchange.length > 0) {
|
||||||
updated++;
|
// updated++;
|
||||||
console.log('Changed: ', product.name + ': ' + arrfieldchange);
|
console.log('Changed: ', recnewInfo.name + ': ' + arrfieldchange);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
let recProductExist = await Product.findOne({ idProductInfo: product.idProductInfo }).lean();
|
||||||
|
if (!recProductExist) {
|
||||||
|
isnuovo = true;
|
||||||
|
}
|
||||||
|
|
||||||
|
let risrec = await Product.findOneAndUpdate({ idProductInfo: product.idProductInfo }, { $set: product }, { new: true, upsert: true });
|
||||||
|
|
||||||
|
let recnew = await Product.findOne({ idProductInfo: product.idProductInfo }).lean();
|
||||||
|
|
||||||
|
if (risrec) {
|
||||||
|
if (risrec._id) {
|
||||||
|
// Record existed, so it was updated
|
||||||
|
let arrfieldchange = tools.differentObjects(product, recnew);
|
||||||
|
if (arrfieldchange.length > 0) {
|
||||||
|
updated++;
|
||||||
|
console.log('Changed: ', product.idProductInfo + ': ' + arrfieldchange);
|
||||||
|
}
|
||||||
|
} else {
|
||||||
|
// Record didn't exist, so it was created
|
||||||
|
imported++;
|
||||||
}
|
}
|
||||||
} else {
|
} else {
|
||||||
// Record didn't exist, so it was created
|
// risrec is null or undefined, indicating an error
|
||||||
imported++;
|
console.error('Error: ', product.productInfo.name);
|
||||||
|
errors++;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
await Product.singlerecconvert_AfterImport(idapp, recnew, isnuovo);
|
||||||
} else {
|
} else {
|
||||||
// risrec is null or undefined, indicating an error
|
console.error('Error ProductInfo: ', product.code);
|
||||||
console.error('Error: ', product.name);
|
|
||||||
errors++;
|
errors++;
|
||||||
}
|
}
|
||||||
|
|
||||||
await Product.singlerecconvert_AfterImport(idapp, recnew);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
// L'opzione ordered: false gestisce gli errori senza interrompere l'inserimento
|
// L'opzione ordered: false gestisce gli errori senza interrompere l'inserimento
|
||||||
|
|||||||
@@ -57,6 +57,7 @@ router.post('/:userId', authenticate, async function (req, res, next) {
|
|||||||
try {
|
try {
|
||||||
let mycart = await Cart.getCartByUserId(userId, idapp);
|
let mycart = await Cart.getCartByUserId(userId, idapp);
|
||||||
|
|
||||||
|
|
||||||
if (!order) {
|
if (!order) {
|
||||||
return res.send({ code: server_constants.RIS_CODE_OK, cart: null });
|
return res.send({ code: server_constants.RIS_CODE_OK, cart: null });
|
||||||
}
|
}
|
||||||
@@ -272,7 +273,6 @@ router.post('/:userId/createorderscart', authenticate, async function (req, res,
|
|||||||
})
|
})
|
||||||
}
|
}
|
||||||
statusOrderCart = myorderCart.status;
|
statusOrderCart = myorderCart.status;
|
||||||
|
|
||||||
const idordercart = myorderCart._id;
|
const idordercart = myorderCart._id;
|
||||||
|
|
||||||
if (!!mycart) {
|
if (!!mycart) {
|
||||||
|
|||||||
@@ -66,7 +66,9 @@ 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 CatProd = require('../models/catprod');
|
||||||
const Gasordine = require('../models/gasordine');
|
const Gasordine = require('../models/gasordine');
|
||||||
|
const ProductInfo = require('../models/productinfo');
|
||||||
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');
|
||||||
@@ -1435,7 +1437,9 @@ 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 catprods = CatProd.findAllIdApp(idapp);
|
||||||
let gasordines = Gasordine.findAllIdApp(idapp);
|
let gasordines = Gasordine.findAllIdApp(idapp);
|
||||||
|
let productInfos = ProductInfo.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);
|
||||||
@@ -1526,6 +1530,8 @@ function load(req, res, version) {
|
|||||||
providers,
|
providers,
|
||||||
scontisticas,
|
scontisticas,
|
||||||
gasordines,
|
gasordines,
|
||||||
|
productInfos,
|
||||||
|
catprods,
|
||||||
]).then((arrdata) => {
|
]).then((arrdata) => {
|
||||||
// console.table(arrdata);
|
// console.table(arrdata);
|
||||||
let myuser = req.user;
|
let myuser = req.user;
|
||||||
@@ -1611,6 +1617,8 @@ function load(req, res, version) {
|
|||||||
providers: arrdata[40],
|
providers: arrdata[40],
|
||||||
scontisticas: arrdata[41],
|
scontisticas: arrdata[41],
|
||||||
gasordines: arrdata[42],
|
gasordines: arrdata[42],
|
||||||
|
productInfos: arrdata[43],
|
||||||
|
catprods: arrdata[44],
|
||||||
});
|
});
|
||||||
|
|
||||||
const prova = 1;
|
const prova = 1;
|
||||||
|
|||||||
@@ -36,6 +36,8 @@ const { authenticate, authenticate_noerror } = require('../middleware/authentica
|
|||||||
const Cart = require('../models/cart');
|
const Cart = require('../models/cart');
|
||||||
const CartClass = require('../modules/Cart');
|
const CartClass = require('../modules/Cart');
|
||||||
const Product = require('../models/product');
|
const Product = require('../models/product');
|
||||||
|
const Order = require('../models/order');
|
||||||
|
const OrdersCart = require('../models/orderscart');
|
||||||
const Variant = require('../models/variant');
|
const Variant = require('../models/variant');
|
||||||
const TypedError = require('../modules/ErrorHandler');
|
const TypedError = require('../modules/ErrorHandler');
|
||||||
|
|
||||||
@@ -1303,6 +1305,25 @@ async function eseguiDbOp(idapp, mydata, locale, req, res) {
|
|||||||
|
|
||||||
ris = populate.popolaTabelleNuove();
|
ris = populate.popolaTabelleNuove();
|
||||||
|
|
||||||
|
} else if (mydata.dbop === 'dropProducts') {
|
||||||
|
|
||||||
|
ris = Product.collection.drop();
|
||||||
|
ris = ProductInfo.collection.drop();
|
||||||
|
|
||||||
|
} else if (mydata.dbop === 'dropAllOrders') {
|
||||||
|
|
||||||
|
try {
|
||||||
|
ris = Order.collection.drop();
|
||||||
|
ris = OrdersCart.collection.drop();
|
||||||
|
ris = Cart.collection.drop();
|
||||||
|
} catch (e) {
|
||||||
|
console.error('Err:', e);
|
||||||
|
}
|
||||||
|
|
||||||
|
} else if (mydata.dbop === 'dropAllCarts') {
|
||||||
|
|
||||||
|
ris = Cart.collection.drop();
|
||||||
|
|
||||||
} else if (mydata.dbop === 'RewriteCitiesTable') {
|
} else if (mydata.dbop === 'RewriteCitiesTable') {
|
||||||
|
|
||||||
ris = populate.rewriteTable('cities');
|
ris = populate.rewriteTable('cities');
|
||||||
|
|||||||
@@ -4364,6 +4364,9 @@ module.exports = {
|
|||||||
}
|
}
|
||||||
},
|
},
|
||||||
|
|
||||||
|
isObjectEmpty(obj) {
|
||||||
|
return Object.keys(obj).length === 0;
|
||||||
|
},
|
||||||
|
|
||||||
|
|
||||||
};
|
};
|
||||||
|
|||||||
@@ -56,6 +56,7 @@ const { Permission } = require('../models/permission');
|
|||||||
const { MsgTemplate } = require('../models/msg_template');
|
const { MsgTemplate } = require('../models/msg_template');
|
||||||
const { Graduatoria } = require('../models/graduatoria');
|
const { Graduatoria } = require('../models/graduatoria');
|
||||||
const Product = require('../models/product');
|
const Product = require('../models/product');
|
||||||
|
const ProductInfo = require('../models/productinfo');
|
||||||
const Producer = require('../models/producer');
|
const Producer = require('../models/producer');
|
||||||
const Cart = require('../models/cart');
|
const Cart = require('../models/cart');
|
||||||
const OrdersCart = require('../models/orderscart');
|
const OrdersCart = require('../models/orderscart');
|
||||||
@@ -64,6 +65,7 @@ const Provider = require('../models/provider');
|
|||||||
const Gasordine = require('../models/gasordine');
|
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 CatProd = require('../models/catprod');
|
||||||
const { Category } = require('../models/category');
|
const { Category } = require('../models/category');
|
||||||
const ShareWithUs = require('../models/sharewithus');
|
const ShareWithUs = require('../models/sharewithus');
|
||||||
const Site = require('../models/site');
|
const Site = require('../models/site');
|
||||||
@@ -105,6 +107,8 @@ module.exports = {
|
|||||||
mytable = Operator;
|
mytable = Operator;
|
||||||
else if (tablename === 'products')
|
else if (tablename === 'products')
|
||||||
mytable = Product;
|
mytable = Product;
|
||||||
|
else if (tablename === 'productinfos')
|
||||||
|
mytable = ProductInfo;
|
||||||
else if (tablename === 'storehouses')
|
else if (tablename === 'storehouses')
|
||||||
mytable = Storehouse;
|
mytable = Storehouse;
|
||||||
else if (tablename === 'providers')
|
else if (tablename === 'providers')
|
||||||
@@ -117,6 +121,8 @@ module.exports = {
|
|||||||
mytable = Department;
|
mytable = Department;
|
||||||
else if (tablename === 'categorys')
|
else if (tablename === 'categorys')
|
||||||
mytable = Category;
|
mytable = Category;
|
||||||
|
else if (tablename === 'catprods')
|
||||||
|
mytable = CatProd;
|
||||||
else if (tablename === 'sharewithus')
|
else if (tablename === 'sharewithus')
|
||||||
mytable = ShareWithUs;
|
mytable = ShareWithUs;
|
||||||
else if (tablename === 'sites')
|
else if (tablename === 'sites')
|
||||||
|
|||||||
Reference in New Issue
Block a user