salix/db/changes/233801/00-item_setVisibleDiscard.sql

63 lines
1.3 KiB
MySQL
Raw Normal View History

2023-09-01 10:34:33 +00:00
DELIMITER $$
CREATE OR REPLACE DEFINER=`root`@`localhost` PROCEDURE `vn`.`item_setVisibleDiscard`(
vItemFk INT,
vWarehouseFk INT,
vQuantity INT,
vAddressFk INT)
BEGIN
DECLARE vTicketFk INT;
DECLARE vClientFk INT;
DECLARE vCompanyVnlFk INT;
DECLARE vCalc INT;
SELECT barcodeToItem(vItemFk) INTO vItemFk;
2023-09-14 05:47:10 +00:00
SELECT DEFAULT(companyFk) INTO vCompanyVnlFk
FROM vn.ticket LIMIT 1;
2023-09-01 10:34:33 +00:00
SELECT c.id INTO vClientFk
FROM client c
JOIN address a ON a.clientFk = c.id
WHERE a.id = vAddressFk;
SELECT t.id INTO vTicketFk
FROM ticket t
JOIN address a ON a.id = t.addressFk
WHERE t.warehouseFk = vWarehouseFk
2023-09-14 05:47:10 +00:00
AND a.id = vAddressFk
AND DATE(t.shipped) = util.VN_CURDATE();
2023-09-01 10:34:33 +00:00
CALL cache.visible_refresh(vCalc, TRUE, vWarehouseFk);
IF vTicketFk IS NULL THEN
CALL ticket_add(
vClientFk,
util.VN_CURDATE(),
vWarehouseFk,
vCompanyVnlFk,
2023-09-14 05:47:10 +00:00
vAddressFk,
2023-09-01 10:34:33 +00:00
NULL,
NULL,
util.VN_CURDATE(),
account.myUser_getId(),
FALSE,
vTicketFk);
END IF;
INSERT INTO sale(ticketFk, itemFk, concept, quantity)
SELECT vTicketFk,
vItemFk,
CONCAT(longName,' ', getWorkerCode(), ' ', LEFT(CAST(util.VN_NOW() AS TIME),5)),
vQuantity
FROM item
WHERE id = vItemFk;
UPDATE cache.visible
SET visible = visible - vQuantity
WHERE calc_id = vCalc
AND item_id = vItemFk;
END$$
DELIMITER ;