salix/modules/ticket/back/methods/sale/getFromSectorCollection.js

62 lines
1.8 KiB
JavaScript
Raw Permalink Normal View History

2024-03-14 07:36:19 +00:00
module.exports = Self => {
Self.remoteMethodCtx('getFromSectorCollection', {
description: 'Get sales from sector collection',
accessType: 'READ',
accepts: [
{
arg: 'sectorCollectionFk',
type: 'number',
required: true,
},
{
arg: 'sectorFk',
type: 'number',
required: true
}
],
returns: {
type: ['object'],
root: true
},
http: {
path: `/getFromSectorCollection`,
verb: 'GET'
},
});
Self.getFromSectorCollection = async(ctx, sectorCollectionFk, sectorFk, options) => {
const userId = ctx.req.accessToken.userId;
const myOptions = {userId};
if (typeof options == 'object') Object.assign(myOptions, options);
const [sales] = await Self.rawSql('CALL sectorCollection_getSale(?)', [sectorCollectionFk], myOptions);
const itemShelvings = [];
for (let sale of sales) {
const [carros] = await Self.rawSql(
'CALL vn.itemPlacementSupplyStockGetTargetList(?, ?)',
[sale.itemFk, sectorFk],
myOptions
);
itemShelvings.push({
id: sale.ticketFk,
itemFk: sale.itemFk,
longName: sale.longName,
packingType: sale.itemPackingTypeFk,
subName: sale.subName,
quantity: sale.quantity,
saldo: sale.quantity,
trabajador: sale.workerCode,
idMovimiento: sale.saleFk,
salesPersonFk: sale.salesPersonFk,
picked: sale.pickedQuantity,
carros
});
}
return itemShelvings;
};
};