fix: refs #7266 Created buy_getLastWihoutInventory proc
gitea/salix/pipeline/pr-master This commit looks good Details

This commit is contained in:
Guillermo Bonet 2024-12-02 12:54:36 +01:00
parent ecd86b2b5a
commit fb58ab5bd2
1 changed files with 32 additions and 0 deletions

View File

@ -0,0 +1,32 @@
DELIMITER $$
CREATE OR REPLACE DEFINER=`vn`@`localhost` FUNCTION `vn`.`buy_getLastWihoutInventory`(
vItemFk INT,
vWarehouseFk INT
)
RETURNS int(11)
DETERMINISTIC
BEGIN
/**
* Retorna la última compra que no sea inventario.
*
* @param vItemFk Id del artículo
* @param vWarehouseFk Id del almacén
* @return Id de compra
*/
DECLARE vBuyFk INT;
SELECT b.id INTO vBuyFk
FROM vn.buy b
JOIN vn.entry e ON e.id = b.entryFk
JOIN vn.travel t ON t.id = e.travelFk
WHERE e.id <> (SELECT defaultEntry FROM vn.entryConfig)
AND e.supplierFk <> (SELECT supplierFk FROM vn.inventoryConfig)
AND e.typeFk <> 'inventory'
AND b.itemFk = vItemFk
AND (t.warehouseInFk = vWarehouseFk OR t.warehouseInFk IS NULL)
ORDER BY ABS(DATEDIFF(util.VN_CURDATE(), t.landed)), e.created DESC
LIMIT 1;
RETURN vBuyFk;
END$$
DELIMITER ;