refactor(ticket): advanceable code
gitea/salix/pipeline/head This commit looks good
Details
gitea/salix/pipeline/head This commit looks good
Details
This commit is contained in:
parent
b8355320f2
commit
8e1c3e107c
|
@ -2,7 +2,7 @@ DROP PROCEDURE IF EXISTS `vn`.`ticket_getAdvanceable`;
|
|||
|
||||
DELIMITER $$
|
||||
$$
|
||||
CREATE DEFINER=`root`@`%` PROCEDURE `vn`.`ticket_getAdvanceable`(vTicketFk INT, vDatedNew DATETIME)
|
||||
CREATE DEFINER=`root`@`%` PROCEDURE `vn`.`ticket_getAdvanceable`(vTicketFk INT, vDatedNew DATETIME, vWarehouseFk INT)
|
||||
BEGIN
|
||||
/**
|
||||
* Cálcula el stock avanzable para los artículos de un ticket
|
||||
|
@ -11,10 +11,9 @@ BEGIN
|
|||
* @param vDatedNew -> Nueva fecha
|
||||
* @return Sales con Avanzable
|
||||
*/
|
||||
DECLARE vWarehouseFk INT;
|
||||
DECLARE vDatedOld DATETIME;
|
||||
|
||||
SELECT t.warehouseFk, t.shipped INTO vWarehouseFk, vDatedOld
|
||||
SELECT t.shipped INTO vDatedOld
|
||||
FROM ticket t
|
||||
WHERE t.id = vTicketFk;
|
||||
|
||||
|
|
|
@ -132,17 +132,13 @@ module.exports = Self => {
|
|||
throw new UserError(error);
|
||||
}
|
||||
}
|
||||
|
||||
if (args.isWithoutNegatives) {
|
||||
const query = `CALL ticket_getAdvanceable(?,?)`;
|
||||
const params = [args.id, args.shipped];
|
||||
const query = `CALL ticket_getAdvanceable(?,?,?)`;
|
||||
const params = [args.id, args.shipped, args.warehouseFk];
|
||||
const [salesAdvanceable] = await Self.rawSql(query, params, myOptions);
|
||||
|
||||
let salesNewTicket = [];
|
||||
salesAdvanceable.forEach(sale => {
|
||||
if (sale.advanceable >= sale.quantity)
|
||||
salesNewTicket.push(sale);
|
||||
});
|
||||
|
||||
const salesNewTicket = salesAdvanceable.filter(sale => (sale.advanceable ?? 0) >= sale.quantity);
|
||||
if (salesNewTicket.length) {
|
||||
const newTicket = await models.Ticket.transferSales(ctx, args.id, null, salesNewTicket, myOptions);
|
||||
args.id = newTicket.id;
|
||||
|
|
|
@ -111,13 +111,13 @@ module.exports = Self => {
|
|||
};
|
||||
|
||||
// Get items advanceable
|
||||
let query = `CALL ticket_getAdvanceable(?,?)`;
|
||||
let params = [args.id, args.shipped];
|
||||
let query = `CALL ticket_getAdvanceable(?,?,?)`;
|
||||
let params = [args.id, args.shipped, args.warehouseId];
|
||||
const [salesAdvanceable] = await Self.rawSql(query, params, myOptions);
|
||||
|
||||
const itemAdvanceable = new Map();
|
||||
for (sale of salesAdvanceable)
|
||||
itemAdvanceable.set(sale.id, sale.advanceable);
|
||||
itemAdvanceable.set(sale.id, sale.advanceable ?? 0);
|
||||
|
||||
// Sale price component, one per sale
|
||||
query = `CALL vn.ticket_priceDifference(?, ?, ?, ?, ?)`;
|
||||
|
|
Loading…
Reference in New Issue