2023-12-13 07:52:43 +00:00
|
|
|
module.exports = Self => {
|
2024-01-16 13:50:09 +00:00
|
|
|
Self.remoteMethodCtx('getFromSectorCollection', {
|
2024-01-04 15:00:25 +00:00
|
|
|
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-16 13:50:09 +00:00
|
|
|
Self.getFromSectorCollection = async(ctx, sectorCollectionFk, sectorFk, options) => {
|
2023-12-13 07:52:43 +00:00
|
|
|
const myOptions = {};
|
2024-01-16 13:50:09 +00:00
|
|
|
const userId = ctx.req.accessToken.userId;
|
2023-12-13 07:52:43 +00:00
|
|
|
|
|
|
|
if (typeof options == 'object') Object.assign(myOptions, options);
|
|
|
|
|
2024-01-16 13:50:09 +00:00
|
|
|
const sales = await Self.rawSql(
|
|
|
|
`SELECT s.ticketFk,
|
|
|
|
s.itemFk,
|
|
|
|
i.longName,
|
|
|
|
itemPackingTypeFk,
|
|
|
|
subName,
|
|
|
|
s.quantity,
|
|
|
|
w.code workerCode,
|
|
|
|
sgd.saleFk,
|
|
|
|
iss.quantity pickedQuantity,
|
|
|
|
c.salesPersonFk
|
|
|
|
FROM vn.sale s
|
|
|
|
JOIN item i ON i.id = s.itemFk
|
|
|
|
JOIN saleGroupDetail sgd ON sgd.saleFk = s.id
|
|
|
|
JOIN sectorCollectionSaleGroup scsg ON scsg.saleGroupFk = sgd.saleGroupFk
|
|
|
|
JOIN saleTracking st ON st.saleFk = s.id
|
|
|
|
JOIN state stt ON stt.id = st.stateFk AND stt.code = 'PREVIOUS_PREPARATION'
|
|
|
|
JOIN worker w ON w.id = st.workerFk
|
|
|
|
JOIN ticket t ON t.id= s.ticketFk
|
|
|
|
JOIN client c ON c.id=t.clientFk
|
|
|
|
LEFT JOIN itemShelvingSaleSum iss ON iss.saleFk = s.id
|
|
|
|
WHERE scsg.sectorCollectionFk = ?
|
|
|
|
AND st.workerFk = ?;`, [sectorCollectionFk, userId]);
|
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,
|
2024-01-17 11:14:38 +00:00
|
|
|
quantity: sale.quantity,
|
|
|
|
saldo: sale.quantity,
|
2023-12-13 07:52:43 +00:00
|
|
|
trabajador: sale.workerCode,
|
|
|
|
idMovimiento: sale.saleFk,
|
|
|
|
salesPersonFk: sale.salesPersonFk,
|
|
|
|
picked: sale.pickedQuantity,
|
|
|
|
carros
|
|
|
|
});
|
|
|
|
}
|
|
|
|
|
|
|
|
return itemShelvings;
|
|
|
|
};
|
|
|
|
};
|