aggio gasordine
This commit is contained in:
@@ -38,9 +38,7 @@ const productSchema = new Schema({
|
|||||||
idStorehouses: [
|
idStorehouses: [
|
||||||
{ type: Schema.Types.ObjectId, ref: 'Storehouse' }
|
{ type: Schema.Types.ObjectId, ref: 'Storehouse' }
|
||||||
],
|
],
|
||||||
idGasordines: [
|
idGasordine: { type: Schema.Types.ObjectId, ref: 'Gasordine' },
|
||||||
{ type: Schema.Types.ObjectId, ref: 'Gasordine' }
|
|
||||||
],
|
|
||||||
idScontisticas: [
|
idScontisticas: [
|
||||||
{ type: Schema.Types.ObjectId, ref: 'Scontistica' }
|
{ type: Schema.Types.ObjectId, ref: 'Scontistica' }
|
||||||
],
|
],
|
||||||
@@ -200,7 +198,7 @@ module.exports.findAllIdApp = async function (idapp, code, id, all) {
|
|||||||
|
|
||||||
try {
|
try {
|
||||||
|
|
||||||
if (idapp){
|
if (idapp) {
|
||||||
myfind = { idapp };
|
myfind = { idapp };
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -266,36 +264,36 @@ module.exports.findAllIdApp = async function (idapp, code, id, all) {
|
|||||||
{
|
{
|
||||||
$lookup: {
|
$lookup: {
|
||||||
from: 'gasordines',
|
from: 'gasordines',
|
||||||
localField: 'idGasordines',
|
localField: 'idGasordine',
|
||||||
foreignField: '_id',
|
foreignField: '_id',
|
||||||
as: 'gasordines'
|
as: 'gasordine'
|
||||||
}
|
}
|
||||||
},
|
},
|
||||||
{
|
{
|
||||||
$unwind: {
|
$unwind: {
|
||||||
path: '$gasordines',
|
path: '$gasordine',
|
||||||
preserveNullAndEmptyArrays: true,
|
preserveNullAndEmptyArrays: true,
|
||||||
},
|
},
|
||||||
},
|
},
|
||||||
{
|
{
|
||||||
$match: {
|
$match: {
|
||||||
$or: [
|
$or: [
|
||||||
{ 'gasordines.active': true }, // Include documents where gasordines.active is true
|
{ 'gasordine.active': true }, // Include documents where gasordines.active is true
|
||||||
{ 'gasordines': { $exists: false } } // Include documents where gasordines array doesn't exist
|
{ 'gasordine': { $exists: false } } // Include documents where gasordines array doesn't exist
|
||||||
]
|
]
|
||||||
}
|
}
|
||||||
},
|
},
|
||||||
{
|
{
|
||||||
$group: {
|
$group: {
|
||||||
_id: '$_id',
|
_id: '$_id',
|
||||||
gasordines: { $push: '$gasordines' },
|
gasordine: { $first: '$gasordine' },
|
||||||
originalFields: { $first: '$$ROOT' } // Preserve all existing fields
|
originalFields: { $first: '$$ROOT' } // Preserve all existing fields
|
||||||
}
|
}
|
||||||
},
|
},
|
||||||
{
|
{
|
||||||
$replaceRoot: {
|
$replaceRoot: {
|
||||||
newRoot: {
|
newRoot: {
|
||||||
$mergeObjects: ['$originalFields', { gasordines: '$gasordines' }]
|
$mergeObjects: ['$originalFields', { gasordine: '$gasordine' }]
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
},
|
},
|
||||||
@@ -649,7 +647,7 @@ module.exports.singlerecconvert_AfterImport_AndSave = async function (idapp, pro
|
|||||||
if (rec) {
|
if (rec) {
|
||||||
objtoset = {
|
objtoset = {
|
||||||
...objtoset,
|
...objtoset,
|
||||||
idGasordines: [rec._id],
|
idGasordine: rec._id,
|
||||||
}
|
}
|
||||||
setta = true;
|
setta = true;
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -144,7 +144,24 @@ router.post('/import', authenticate, async (req, res) => {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
let recProductExist = await Product.findOne({ idProductInfo: product.idProductInfo }).lean();
|
// Cerca il GAS
|
||||||
|
let recGas = null;
|
||||||
|
if (prod.gas_name) {
|
||||||
|
// Cerca il GAS
|
||||||
|
recGas = await Gasordine.findOne({ idapp, name: prod.gas_name }).lean();
|
||||||
|
}
|
||||||
|
|
||||||
|
let recProductExist = null;
|
||||||
|
let queryprod = { idProductInfo: product.idProductInfo };
|
||||||
|
|
||||||
|
if (recGas) {
|
||||||
|
queryprod = {...queryprod, gas}
|
||||||
|
} else {
|
||||||
|
recProductExist = await Product.findOne().lean();
|
||||||
|
}
|
||||||
|
|
||||||
|
recProductExist = await Product.findOne({ queryprod }).lean();
|
||||||
|
|
||||||
if (!recProductExist) {
|
if (!recProductExist) {
|
||||||
isnuovo = true;
|
isnuovo = true;
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -50,7 +50,7 @@ router.post('/', auth_default, async function (req, res, next) {
|
|||||||
if (products)
|
if (products)
|
||||||
res.send({ code: server_constants.RIS_CODE_OK, products, orders });
|
res.send({ code: server_constants.RIS_CODE_OK, products, orders });
|
||||||
else
|
else
|
||||||
res.status(400).send(e);
|
res.status(400).send({ code: server_constants.RIS_CODE_OK, products, orders });
|
||||||
|
|
||||||
/*
|
/*
|
||||||
const { query, order } = tools.categorizeQueryString(req.query)
|
const { query, order } = tools.categorizeQueryString(req.query)
|
||||||
|
|||||||
@@ -1330,6 +1330,16 @@ async function eseguiDbOp(idapp, mydata, locale, req, res) {
|
|||||||
} catch (e) {
|
} catch (e) {
|
||||||
console.error('Err:', e);
|
console.error('Err:', e);
|
||||||
}
|
}
|
||||||
|
} else if (mydata.dbop === 'SistemaGasOrdine') {
|
||||||
|
const arrrec = await Product.find({}).lean();
|
||||||
|
for (const rec of arrrec) {
|
||||||
|
if (tools.isArray(rec.idGasordines) && rec.idGasordines.length > 0) {
|
||||||
|
await Product.findByIdAndUpdate(rec._id, { $set: { idGasordine: rec.idGasordines[0] } })
|
||||||
|
} else {
|
||||||
|
await Product.findByIdAndUpdate(rec._id, { $set: { idGasordine: null } })
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
} else if (mydata.dbop === 'CopyPriceToCalc') {
|
} else if (mydata.dbop === 'CopyPriceToCalc') {
|
||||||
|
|
||||||
try {
|
try {
|
||||||
|
|||||||
Reference in New Issue
Block a user