2024-01-15 11:31:03 +00:00
|
|
|
DELIMITER $$
|
2024-07-22 09:52:42 +00:00
|
|
|
CREATE OR REPLACE DEFINER=`vn-admin`@`localhost` PROCEDURE `vn`.`entry_splitMisfit`(vSelf INT)
|
2024-01-15 11:31:03 +00:00
|
|
|
BEGIN
|
|
|
|
|
|
|
|
/* Divide una entrada, pasando los registros que ha insertado vn.entry_fixMisfit de la entrada original
|
|
|
|
* a la nueva
|
|
|
|
*/
|
|
|
|
|
|
|
|
DECLARE vNewEntryFk INT;
|
|
|
|
DECLARE vBuyFk INT;
|
|
|
|
|
|
|
|
SELECT MAX(b.id) INTO vBuyFk
|
|
|
|
FROM vn.buy b
|
|
|
|
JOIN vn.item i ON i.id = b.itemFk
|
|
|
|
WHERE b.entryFk = vSelf
|
|
|
|
AND i.description = 'MISFIT';
|
|
|
|
|
|
|
|
INSERT INTO vn.entry(supplierFk, dated, travelFk, currencyFk, companyFk)
|
|
|
|
SELECT supplierFk, dated, travelFk, currencyFk, companyFk
|
|
|
|
FROM vn.entry e
|
|
|
|
WHERE e.id = vSelf;
|
|
|
|
|
|
|
|
SET vNewEntryFk = LAST_INSERT_ID();
|
|
|
|
|
|
|
|
UPDATE vn.buy b
|
|
|
|
SET b.entryFk = vNewEntryFk
|
|
|
|
WHERE b.entryFk = vSelf
|
|
|
|
AND b.id > vBuyFk;
|
|
|
|
|
|
|
|
SELECT vNewEntryFk;
|
|
|
|
|
|
|
|
|
|
|
|
END$$
|
|
|
|
DELIMITER ;
|