2024-08-05 13:32:36 +00:00
|
|
|
module.exports = Self => {
|
|
|
|
Self.remoteMethod('getStockBoughtDetail', {
|
|
|
|
description: 'Returns the detail of stock bought for a given date and a worker',
|
|
|
|
accessType: 'READ',
|
|
|
|
accepts: [{
|
|
|
|
arg: 'workerFk',
|
|
|
|
type: 'number',
|
|
|
|
description: 'The worker to filter',
|
|
|
|
required: true,
|
|
|
|
}, {
|
|
|
|
arg: 'dated',
|
|
|
|
type: 'string',
|
|
|
|
description: 'The date to filter',
|
|
|
|
}
|
|
|
|
],
|
|
|
|
returns: {
|
|
|
|
type: ['object'],
|
|
|
|
root: true
|
|
|
|
},
|
|
|
|
http: {
|
|
|
|
path: `/getStockBoughtDetail`,
|
|
|
|
verb: 'GET'
|
|
|
|
}
|
|
|
|
});
|
|
|
|
|
2024-09-11 05:56:08 +00:00
|
|
|
Self.getStockBoughtDetail = async(workerFk, dated) => {
|
|
|
|
if (!dated) {
|
|
|
|
dated = Date.vnNew();
|
|
|
|
dated.setHours(0, 0, 0, 0);
|
|
|
|
}
|
2024-08-05 13:32:36 +00:00
|
|
|
return Self.rawSql(
|
|
|
|
`SELECT e.id entryFk,
|
|
|
|
i.id itemFk,
|
|
|
|
i.longName itemName,
|
|
|
|
b.quantity,
|
|
|
|
ROUND((ac.conversionCoefficient *
|
|
|
|
(b.quantity / b.packing) *
|
|
|
|
buy_getVolume(b.id)
|
|
|
|
) / (vc.trolleyM3 * 1000000),
|
|
|
|
2
|
|
|
|
) volume,
|
|
|
|
b.packagingFk,
|
|
|
|
b.packing
|
|
|
|
FROM entry e
|
|
|
|
JOIN travel t ON t.id = e.travelFk
|
|
|
|
JOIN buy b ON b.entryFk = e.id
|
|
|
|
JOIN item i ON i.id = b.itemFk
|
|
|
|
JOIN itemType it ON it.id = i.typeFk
|
|
|
|
JOIN worker w ON w.id = it.workerFk
|
|
|
|
JOIN auctionConfig ac
|
|
|
|
JOIN volumeConfig vc
|
|
|
|
WHERE t.warehouseInFk = ac.warehouseFk
|
|
|
|
AND it.workerFk = ?
|
2024-09-11 05:56:08 +00:00
|
|
|
AND t.shipped = util.VN_CURDATE()`,
|
|
|
|
[workerFk]
|
2024-08-05 13:32:36 +00:00
|
|
|
);
|
|
|
|
};
|
|
|
|
};
|