2023-12-13 07:52:43 +00:00
|
|
|
module.exports = Self => {
|
2024-01-04 15:00:25 +00:00
|
|
|
Self.remoteMethod('getFromSectorCollection', {
|
|
|
|
description: 'Get sales from sector collection',
|
|
|
|
accessType: 'READ',
|
2023-12-13 07:52:43 +00:00
|
|
|
accepts: [
|
|
|
|
{
|
|
|
|
arg: 'sectorCollectionFk',
|
|
|
|
type: 'number',
|
|
|
|
required: true,
|
|
|
|
},
|
|
|
|
{
|
|
|
|
arg: 'sectorFk',
|
|
|
|
type: 'number',
|
|
|
|
required: true
|
|
|
|
}
|
|
|
|
],
|
|
|
|
returns: {
|
|
|
|
type: ['object'],
|
|
|
|
root: true
|
|
|
|
},
|
|
|
|
http: {
|
2024-01-04 15:00:25 +00:00
|
|
|
path: `/getFromSectorCollection`,
|
2023-12-13 07:52:43 +00:00
|
|
|
verb: 'GET'
|
|
|
|
},
|
|
|
|
});
|
|
|
|
|
2024-01-04 15:00:25 +00:00
|
|
|
Self.getFromSectorCollection = async(sectorCollectionFk, sectorFk, options) => {
|
2023-12-13 07:52:43 +00:00
|
|
|
const myOptions = {};
|
|
|
|
|
|
|
|
if (typeof options == 'object') Object.assign(myOptions, options);
|
|
|
|
|
2023-12-13 08:45:01 +00:00
|
|
|
const [sales] = await Self.rawSql('CALL vn.sectorCollection_getSale(?)', [sectorCollectionFk]);
|
2023-12-13 07:52:43 +00:00
|
|
|
|
|
|
|
const itemShelvings = [];
|
|
|
|
for (let sale of sales) {
|
|
|
|
const [carros] = await Self.rawSql(
|
|
|
|
'CALL vn.itemPlacementSupplyStockGetTargetList(?, ?)',
|
|
|
|
[sale.itemFk, sectorFk]
|
|
|
|
);
|
|
|
|
|
|
|
|
itemShelvings.push({
|
|
|
|
id: sale.ticketFk,
|
|
|
|
itemFk: sale.itemFk,
|
|
|
|
longName: sale.longName,
|
|
|
|
packingType: sale.itemPackingTypeFk,
|
|
|
|
subName: sale.subName,
|
|
|
|
quantity: {saldo: sale.quantity},
|
|
|
|
trabajador: sale.workerCode,
|
|
|
|
idMovimiento: sale.saleFk,
|
|
|
|
salesPersonFk: sale.salesPersonFk,
|
|
|
|
picked: sale.pickedQuantity,
|
|
|
|
carros
|
|
|
|
});
|
|
|
|
}
|
|
|
|
|
|
|
|
return itemShelvings;
|
|
|
|
};
|
|
|
|
};
|