Merge pull request 'fix: refs #7266 Created buy_getLastWihoutInventory proc' (!3267) from 7266-buyGetLastWihoutInventory into master
gitea/salix/pipeline/head This commit looks good
Details
gitea/salix/pipeline/head This commit looks good
Details
Reviewed-on: #3267 Reviewed-by: Sergio De la torre <sergiodt@verdnatura.es>
This commit is contained in:
commit
ef5522b2b3
|
@ -0,0 +1,32 @@
|
||||||
|
DELIMITER $$
|
||||||
|
CREATE OR REPLACE DEFINER=`vn`@`localhost` FUNCTION `vn`.`buy_getLastWithoutInventory`(
|
||||||
|
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 buy b
|
||||||
|
JOIN entry e ON e.id = b.entryFk
|
||||||
|
JOIN travel t ON t.id = e.travelFk
|
||||||
|
WHERE e.id <> (SELECT defaultEntry FROM entryConfig)
|
||||||
|
AND e.supplierFk <> (SELECT supplierFk FROM 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 ;
|
Loading…
Reference in New Issue