- preordinabili corretti + altro
This commit is contained in:
@@ -1,7 +1,7 @@
|
|||||||
doctype html
|
doctype html
|
||||||
html
|
html
|
||||||
head
|
head
|
||||||
title Ordine Completato
|
title Ordine consegnato
|
||||||
|
|
||||||
//- import css/scss stylesheets
|
//- import css/scss stylesheets
|
||||||
//- these file names will be replace by gulp with proper css file paths
|
//- these file names will be replace by gulp with proper css file paths
|
||||||
@@ -29,7 +29,7 @@ html
|
|||||||
td(class="emailContainer", valign="top")
|
td(class="emailContainer", valign="top")
|
||||||
|
|
||||||
p Ciao #{name},
|
p Ciao #{name},
|
||||||
p L'ordine n. #{ordernumber} è stato Completato correttamente !
|
p L'ordine n. #{ordernumber} è stato Consegnato correttamente !
|
||||||
p Grazie Mille per aver contribuito a far crescere la Comunità
|
p Grazie Mille per aver contribuito a far crescere la Comunità
|
||||||
|
|
||||||
table.footer(cellpadding="0", cellspacing="0", width="100%", summary="", border="0", align="center")
|
table.footer(cellpadding="0", cellspacing="0", width="100%", summary="", border="0", align="center")
|
||||||
|
|||||||
@@ -1 +1 @@
|
|||||||
=`Ordine n. ${ordernumber} Completato`
|
=`Ordine n. ${ordernumber} Consegnato`
|
||||||
|
|||||||
@@ -61,6 +61,13 @@ const orderSchema = new Schema({
|
|||||||
date_evaso: {
|
date_evaso: {
|
||||||
type: Date
|
type: Date
|
||||||
},
|
},
|
||||||
|
consegnato: {
|
||||||
|
type: Boolean,
|
||||||
|
default: false,
|
||||||
|
},
|
||||||
|
date_consegnato: {
|
||||||
|
type: Date
|
||||||
|
},
|
||||||
pagato: {
|
pagato: {
|
||||||
type: Boolean,
|
type: Boolean,
|
||||||
default: false,
|
default: false,
|
||||||
@@ -75,13 +82,6 @@ const orderSchema = new Schema({
|
|||||||
date_spedito: {
|
date_spedito: {
|
||||||
type: Date
|
type: Date
|
||||||
},
|
},
|
||||||
completato: {
|
|
||||||
type: Boolean,
|
|
||||||
default: false,
|
|
||||||
},
|
|
||||||
date_completato: {
|
|
||||||
type: Date
|
|
||||||
},
|
|
||||||
consegnato: {
|
consegnato: {
|
||||||
type: Boolean,
|
type: Boolean,
|
||||||
default: false,
|
default: false,
|
||||||
|
|||||||
@@ -39,7 +39,7 @@ const OrdersCartSchema = new Schema({
|
|||||||
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 stockBloccatiQty)
|
||||||
type: Boolean,
|
type: Boolean,
|
||||||
default: false,
|
default: false,
|
||||||
},
|
},
|
||||||
@@ -60,11 +60,11 @@ const OrdersCartSchema = new Schema({
|
|||||||
date_spedito: {
|
date_spedito: {
|
||||||
type: Date
|
type: Date
|
||||||
},
|
},
|
||||||
completato: {
|
consegnato: { // e quindi è stato tolto dal magazzino (aggiornando il campo stockQty e stockBloccatiQty)
|
||||||
type: Boolean,
|
type: Boolean,
|
||||||
default: false,
|
default: false,
|
||||||
},
|
},
|
||||||
date_completato: {
|
date_consegnato: {
|
||||||
type: Date
|
type: Date
|
||||||
},
|
},
|
||||||
consegnato: {
|
consegnato: {
|
||||||
@@ -244,10 +244,10 @@ module.exports.getOrdersCartByQuery = async function (query) {
|
|||||||
if (item.order) {
|
if (item.order) {
|
||||||
try {
|
try {
|
||||||
if (item.order.idProduct) {
|
if (item.order.idProduct) {
|
||||||
item.order.idProduct.productInfo = item.order.idProduct.productInfo ? item.order.idProduct.productInfo : {...item.order.idProduct.idProductInfo};
|
item.order.idProduct.productInfo = item.order.idProduct.productInfo ? item.order.idProduct.productInfo : { ...item.order.idProduct.idProductInfo };
|
||||||
item.order.idProduct.idProductInfo = item.order.idProduct.productInfo ? item.order.idProduct.productInfo._id : '';
|
item.order.idProduct.idProductInfo = item.order.idProduct.productInfo ? item.order.idProduct.productInfo._id : '';
|
||||||
}
|
}
|
||||||
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 : '';
|
||||||
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 : '';
|
||||||
@@ -374,6 +374,23 @@ module.exports.setFieldInOrdersById = async function (objtoset, myOrderCart) {
|
|||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
|
module.exports.deleteRecsInOrdersById = async function (myOrderCart) {
|
||||||
|
|
||||||
|
try {
|
||||||
|
let ris2 = null;
|
||||||
|
// Imposta su tutti i singoli prodotti ordinati (Order)
|
||||||
|
for (const recitem of myOrderCart.items) {
|
||||||
|
ris2 = await Order.findOneAndRemove({ _id: recitem.order._id })
|
||||||
|
}
|
||||||
|
|
||||||
|
const ris = await OrdersCart.findOneAndRemove({ _id: myOrderCart._id })
|
||||||
|
|
||||||
|
} catch (e) {
|
||||||
|
console.log('Err', e);
|
||||||
|
}
|
||||||
|
|
||||||
|
}
|
||||||
|
|
||||||
module.exports.setConsegnatoById = async function (value, myOrderCart) {
|
module.exports.setConsegnatoById = async function (value, myOrderCart) {
|
||||||
|
|
||||||
let objtoset = {
|
let objtoset = {
|
||||||
@@ -411,11 +428,11 @@ module.exports.setPagatoById = async function (value, myOrderCart) {
|
|||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
module.exports.setCompletatoById = async function (value, myOrderCart) {
|
module.exports.setConsegnatoById = async function (value, myOrderCart) {
|
||||||
|
|
||||||
let objtoset = {
|
let objtoset = {
|
||||||
completato: value,
|
consegnato: value,
|
||||||
date_completato: new Date(),
|
date_consegnato: new Date(),
|
||||||
};
|
};
|
||||||
|
|
||||||
return await OrdersCart.setFieldInOrdersById(objtoset, myOrderCart);
|
return await OrdersCart.setFieldInOrdersById(objtoset, myOrderCart);
|
||||||
@@ -443,9 +460,15 @@ module.exports.setRicevutoById = async function (value, myOrderCart) {
|
|||||||
return await OrdersCart.setFieldInOrdersById(objtoset, myOrderCart);
|
return await OrdersCart.setFieldInOrdersById(objtoset, myOrderCart);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
module.exports.deleteReally = async function (value, myOrderCart) {
|
||||||
|
|
||||||
|
return await OrdersCart.deleteRecsInOrdersById(myOrderCart);
|
||||||
|
}
|
||||||
|
|
||||||
module.exports.createOrdersCart = async function (newOrdersCart) {
|
module.exports.createOrdersCart = async function (newOrdersCart) {
|
||||||
return await newOrdersCart.save()
|
return await newOrdersCart.save()
|
||||||
}
|
}
|
||||||
|
|
||||||
module.exports.updateStockQtaDalMagazzino = async function (idorderscart) {
|
module.exports.updateStockQtaDalMagazzino = async function (idorderscart) {
|
||||||
|
|
||||||
try {
|
try {
|
||||||
@@ -459,13 +482,48 @@ module.exports.updateStockQtaDalMagazzino = async function (idorderscart) {
|
|||||||
if (!order.evaso) {
|
if (!order.evaso) {
|
||||||
let update = {
|
let update = {
|
||||||
$inc: {
|
$inc: {
|
||||||
stockQty: -order.quantity
|
stockQty: -order.quantity,
|
||||||
|
stockBloccatiQty: order.quantity
|
||||||
|
}
|
||||||
|
};
|
||||||
|
await Product.findOneAndUpdate({ _id: order.idProduct }, update, { new: false });
|
||||||
|
|
||||||
|
update = {
|
||||||
|
$inc: {
|
||||||
|
bookableQty: -order.quantitypreordered,
|
||||||
|
bookableBloccatiQty: order.quantitypreordered
|
||||||
|
}
|
||||||
|
};
|
||||||
|
await Product.findOneAndUpdate({ _id: order.idProduct }, update, { new: false });
|
||||||
|
}
|
||||||
|
|
||||||
|
}
|
||||||
|
}
|
||||||
|
} catch (e) {
|
||||||
|
console.error('Err', e);
|
||||||
|
}
|
||||||
|
|
||||||
|
}
|
||||||
|
module.exports.updateStockBloccatiQtaDalMagazzino = async function (idorderscart) {
|
||||||
|
|
||||||
|
try {
|
||||||
|
|
||||||
|
const myorderscart = await OrdersCart.findOne({ _id: idorderscart }).populate('items.order').lean();
|
||||||
|
|
||||||
|
if (myorderscart) {
|
||||||
|
for (const idkey in myorderscart.items) {
|
||||||
|
let order = myorderscart.items[idkey].order;
|
||||||
|
|
||||||
|
if (!order.consegnato) {
|
||||||
|
let update = {
|
||||||
|
$inc: {
|
||||||
|
stockBloccatiQty: -order.quantity
|
||||||
}
|
}
|
||||||
};
|
};
|
||||||
await Product.findOneAndUpdate({ _id: order.idProduct }, update, { new: false });
|
await Product.findOneAndUpdate({ _id: order.idProduct }, update, { new: false });
|
||||||
update = {
|
update = {
|
||||||
$inc: {
|
$inc: {
|
||||||
bookableQty: -order.quantitypreordered
|
bookableBloccatiQty: -order.quantitypreordered
|
||||||
}
|
}
|
||||||
};
|
};
|
||||||
await Product.findOneAndUpdate({ _id: order.idProduct }, update, { new: false });
|
await Product.findOneAndUpdate({ _id: order.idProduct }, update, { new: false });
|
||||||
@@ -491,27 +549,34 @@ module.exports.updateCmd = async function (ordersCart, status, value) {
|
|||||||
const id = myOrderCart._id;
|
const id = myOrderCart._id;
|
||||||
if (status === shared_consts.OrderStatus.ORDER_CONFIRMED) {
|
if (status === shared_consts.OrderStatus.ORDER_CONFIRMED) {
|
||||||
|
|
||||||
// Aggiorna anche il Magazzino, togliendo le quantità in Stock
|
// Aggiorna anche il Magazzino, togliendo le quantità in Stock e aggiungendole su quelle bloccate
|
||||||
if (value) {
|
if (value) {
|
||||||
await OrdersCart.updateStockQtaDalMagazzino(id);
|
await OrdersCart.updateStockQtaDalMagazzino(id);
|
||||||
}
|
}
|
||||||
ris = await OrdersCart.setEvasoById(value, myOrderCart);
|
ris = await OrdersCart.setEvasoById(value, myOrderCart);
|
||||||
|
|
||||||
} else if (status === shared_consts.OrderStatus.DELIVERED) {
|
} else if (status === shared_consts.OrderStatus.PAYED) {
|
||||||
|
ris = await OrdersCart.setPagatoById(value, myOrderCart);
|
||||||
|
} else if (status === shared_consts.OrderStatus.DELIVERED) { // Consegnato
|
||||||
|
if (value) {
|
||||||
|
await OrdersCart.updateStockBloccatiQtaDalMagazzino(id);
|
||||||
|
}
|
||||||
ris = await OrdersCart.setConsegnatoById(value, myOrderCart);
|
ris = await OrdersCart.setConsegnatoById(value, myOrderCart);
|
||||||
} else if (status === shared_consts.OrderStatus.SHIPPED) {
|
} else if (status === shared_consts.OrderStatus.SHIPPED) {
|
||||||
ris = await OrdersCart.setSpeditoById(value, myOrderCart);
|
ris = await OrdersCart.setSpeditoById(value, myOrderCart);
|
||||||
} else if (status === shared_consts.OrderStatus.PAYED) {
|
|
||||||
ris = await OrdersCart.setPagatoById(value, myOrderCart);
|
|
||||||
} else if (status === shared_consts.OrderStatus.COMPLETED) {
|
|
||||||
ris = await OrdersCart.setCompletatoById(value, myOrderCart);
|
|
||||||
} else if (status === shared_consts.OrderStatus.RECEIVED) {
|
} else if (status === shared_consts.OrderStatus.RECEIVED) {
|
||||||
ris = await OrdersCart.setRicevutoById(value, myOrderCart);
|
ris = await OrdersCart.setRicevutoById(value, myOrderCart);
|
||||||
|
} else if (status === shared_consts.OrderStatus.DELETE_REALLY) {
|
||||||
|
ris = await OrdersCart.deleteReally(value, myOrderCart);
|
||||||
}
|
}
|
||||||
|
|
||||||
await OrdersCart.setFieldInOrdersById({ status }, myOrderCart);
|
if (status !== shared_consts.OrderStatus.DELETE_REALLY) {
|
||||||
|
|
||||||
myOrderCart = await OrdersCart.getOrdersCartById(ordersCart._id)
|
await OrdersCart.setFieldInOrdersById({ status }, myOrderCart);
|
||||||
|
|
||||||
|
|
||||||
|
myOrderCart = await OrdersCart.getOrdersCartById(ordersCart._id)
|
||||||
|
}
|
||||||
// myOrderCart = await OrdersCart.findOne({ _id: idorderscart });
|
// myOrderCart = await OrdersCart.findOne({ _id: idorderscart });
|
||||||
|
|
||||||
return myOrderCart;
|
return myOrderCart;
|
||||||
|
|||||||
@@ -83,6 +83,14 @@ const productSchema = new Schema({
|
|||||||
type: Number,
|
type: Number,
|
||||||
default: 0,
|
default: 0,
|
||||||
},
|
},
|
||||||
|
stockBloccatiQty: { // Prenotati
|
||||||
|
type: Number,
|
||||||
|
default: 0,
|
||||||
|
},
|
||||||
|
bookableBloccatiQty: { // Quantità Prenotati e prenotabili
|
||||||
|
type: Number,
|
||||||
|
default: 0,
|
||||||
|
},
|
||||||
quantityLow: { //Soglia disponibilità bassa
|
quantityLow: { //Soglia disponibilità bassa
|
||||||
type: Number,
|
type: Number,
|
||||||
default: 0,
|
default: 0,
|
||||||
@@ -124,6 +132,9 @@ const productSchema = new Schema({
|
|||||||
sconto2: {
|
sconto2: {
|
||||||
type: String,
|
type: String,
|
||||||
},
|
},
|
||||||
|
gas_name: {
|
||||||
|
type: String,
|
||||||
|
},
|
||||||
});
|
});
|
||||||
|
|
||||||
var Product = module.exports = mongoose.model('Product', productSchema);
|
var Product = module.exports = mongoose.model('Product', productSchema);
|
||||||
@@ -507,6 +518,7 @@ module.exports.singlerecconvert_AfterImport = async function (idapp, prod, isnuo
|
|||||||
|
|
||||||
try {
|
try {
|
||||||
let objtoset = {}
|
let objtoset = {}
|
||||||
|
let rec = null
|
||||||
|
|
||||||
// Impostazioni Base:
|
// Impostazioni Base:
|
||||||
if (isnuovo) {
|
if (isnuovo) {
|
||||||
@@ -574,6 +586,24 @@ module.exports.singlerecconvert_AfterImport = async function (idapp, prod, isnuo
|
|||||||
setta = true;
|
setta = true;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
if (prod.gas_name) {
|
||||||
|
// Cerca il GAS
|
||||||
|
rec = await Gasordine.findOne({ idapp, name: prod.gas_name }).lean();
|
||||||
|
if (!rec) {
|
||||||
|
rec = new Gasordine({ idapp, name: prod.gas_name, active: true });
|
||||||
|
// Non esiste questo GAS, quindi lo creo !
|
||||||
|
ris = await rec.save();
|
||||||
|
rec = await Gasordine.findOne({ idapp, name: prod.gas_name }).lean();
|
||||||
|
}
|
||||||
|
|
||||||
|
if (rec) {
|
||||||
|
objtoset = {
|
||||||
|
...objtoset,
|
||||||
|
idGasordines: [rec._id],
|
||||||
|
}
|
||||||
|
setta = true;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
let arrsconti = []
|
let arrsconti = []
|
||||||
|
|
||||||
@@ -638,6 +668,7 @@ module.exports.singlerecconvert_AfterImport = async function (idapp, prod, isnuo
|
|||||||
magazzino_name: 1,
|
magazzino_name: 1,
|
||||||
sconto1: 1,
|
sconto1: 1,
|
||||||
sconto2: 1,
|
sconto2: 1,
|
||||||
|
gas_name: 1,
|
||||||
};
|
};
|
||||||
|
|
||||||
ris = await Product.updateOne({ _id: ObjectID(prod._id) }, { $unset: objDelete })
|
ris = await Product.updateOne({ _id: ObjectID(prod._id) }, { $unset: objDelete })
|
||||||
|
|||||||
@@ -56,6 +56,10 @@ const storehouseSchema = new Schema({
|
|||||||
type: String,
|
type: String,
|
||||||
default: '',
|
default: '',
|
||||||
},
|
},
|
||||||
|
email_html_order_consegnato: {
|
||||||
|
type: String,
|
||||||
|
default: '',
|
||||||
|
},
|
||||||
});
|
});
|
||||||
|
|
||||||
var Storehouse = module.exports = mongoose.model('Storehouse', storehouseSchema);
|
var Storehouse = module.exports = mongoose.model('Storehouse', storehouseSchema);
|
||||||
|
|||||||
@@ -69,7 +69,7 @@ class Cart {
|
|||||||
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) {
|
||||||
let stepmin = myitem.order.product.minStepQty | 1;
|
let stepmin = myitem.order.product.minStepQty;
|
||||||
let step = stepmin;
|
let step = stepmin;
|
||||||
if (this.isAvailableByOrder(myitem.order)) {
|
if (this.isAvailableByOrder(myitem.order)) {
|
||||||
if (myitem.order.quantity === 0)
|
if (myitem.order.quantity === 0)
|
||||||
@@ -100,8 +100,8 @@ class Cart {
|
|||||||
}
|
}
|
||||||
|
|
||||||
qtaNextSub(myorder, myproduct) {
|
qtaNextSub(myorder, myproduct) {
|
||||||
let step = myproduct.minStepQty | 1
|
let step = myproduct.minStepQty
|
||||||
let minqta = myproduct.minBuyQty | 1
|
let minqta = myproduct.minBuyQty
|
||||||
if (myproduct.quantityAvailable > 0) {
|
if (myproduct.quantityAvailable > 0) {
|
||||||
if (myorder.quantity === minqta)
|
if (myorder.quantity === minqta)
|
||||||
step = minqta
|
step = minqta
|
||||||
|
|||||||
@@ -123,7 +123,7 @@ router.post('/import', authenticate, async (req, res) => {
|
|||||||
isnuovo = true;
|
isnuovo = true;
|
||||||
}
|
}
|
||||||
|
|
||||||
if (!options.aggiornaStockQta && esisteindb) {
|
if (!options.aggiornaStockQty && esisteindb) {
|
||||||
delete product.stockQty;
|
delete product.stockQty;
|
||||||
delete product.bookableQty;
|
delete product.bookableQty;
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -377,8 +377,8 @@ router.post('/:userId/ordercartstatus', authenticate, async function (req, res,
|
|||||||
|
|
||||||
if (status === shared_consts.OrderStatus.ORDER_CONFIRMED) {
|
if (status === shared_consts.OrderStatus.ORDER_CONFIRMED) {
|
||||||
ordertype = 'order_confirmed';
|
ordertype = 'order_confirmed';
|
||||||
} else if (status === shared_consts.OrderStatus.COMPLETED) {
|
} else if (status === shared_consts.OrderStatus.DELIVERED) {
|
||||||
ordertype = 'order_completed';
|
ordertype = 'order_consegnato';
|
||||||
} else if (status === shared_consts.OrderStatus.CANCELED) {
|
} else if (status === shared_consts.OrderStatus.CANCELED) {
|
||||||
ordertype = 'order_canceled';
|
ordertype = 'order_canceled';
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -36,6 +36,7 @@ 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 ProductInfo = require('../models/productInfo');
|
||||||
const Order = require('../models/order');
|
const Order = require('../models/order');
|
||||||
const OrdersCart = require('../models/orderscart');
|
const OrdersCart = require('../models/orderscart');
|
||||||
const Variant = require('../models/variant');
|
const Variant = require('../models/variant');
|
||||||
@@ -1307,8 +1308,8 @@ async function eseguiDbOp(idapp, mydata, locale, req, res) {
|
|||||||
|
|
||||||
} else if (mydata.dbop === 'dropProducts') {
|
} else if (mydata.dbop === 'dropProducts') {
|
||||||
|
|
||||||
ris = Product.collection.drop();
|
await Product.collection.drop();
|
||||||
ris = ProductInfo.collection.drop();
|
ris = await ProductInfo.collection.drop();
|
||||||
|
|
||||||
} else if (mydata.dbop === 'dropAllOrders') {
|
} else if (mydata.dbop === 'dropAllOrders') {
|
||||||
|
|
||||||
|
|||||||
@@ -401,8 +401,8 @@ module.exports = {
|
|||||||
DELIVERED: 5, // Consegnato
|
DELIVERED: 5, // Consegnato
|
||||||
SHIPPED: 6, //Spedito
|
SHIPPED: 6, //Spedito
|
||||||
RECEIVED: 7,
|
RECEIVED: 7,
|
||||||
COMPLETED: 6,
|
|
||||||
CANCELED: 10,
|
CANCELED: 10,
|
||||||
|
DELETE_REALLY: 20,
|
||||||
},
|
},
|
||||||
|
|
||||||
OrderStat: {
|
OrderStat: {
|
||||||
@@ -450,10 +450,6 @@ module.exports = {
|
|||||||
label: 'Ricevuto',
|
label: 'Ricevuto',
|
||||||
value: 7,
|
value: 7,
|
||||||
},
|
},
|
||||||
{
|
|
||||||
label: 'Completato',
|
|
||||||
value: 8,
|
|
||||||
},
|
|
||||||
{
|
{
|
||||||
label: 'Cancellato',
|
label: 'Cancellato',
|
||||||
value: 10,
|
value: 10,
|
||||||
|
|||||||
Reference in New Issue
Block a user