2023-09-01 10:34:33 +00:00
|
|
|
DELIMITER $$
|
2024-01-15 11:31:03 +00:00
|
|
|
CREATE OR REPLACE DEFINER=`root`@`localhost` PROCEDURE `vn`.`itemTrash`(
|
|
|
|
vItemFk INT,
|
2023-09-01 10:34:33 +00:00
|
|
|
vWarehouseFk INT,
|
|
|
|
vQuantity INT,
|
2024-01-15 11:31:03 +00:00
|
|
|
vIsTrash BOOLEAN)
|
2023-09-01 10:34:33 +00:00
|
|
|
BEGIN
|
|
|
|
DECLARE vTicketFk INT;
|
|
|
|
DECLARE vClientFk INT;
|
2024-01-15 11:31:03 +00:00
|
|
|
DECLARE vCompanyVnlFk INT DEFAULT 442;
|
2023-09-01 10:34:33 +00:00
|
|
|
DECLARE vCalc INT;
|
|
|
|
|
|
|
|
SELECT barcodeToItem(vItemFk) INTO vItemFk;
|
|
|
|
|
2024-01-15 11:31:03 +00:00
|
|
|
SELECT IF(vIsTrash, 200, 400) INTO vClientFk;
|
2023-09-01 10:34:33 +00:00
|
|
|
|
|
|
|
SELECT t.id INTO vTicketFk
|
|
|
|
FROM ticket t
|
2024-01-15 11:31:03 +00:00
|
|
|
JOIN address a ON a.id=t.addressFk
|
2023-09-01 10:34:33 +00:00
|
|
|
WHERE t.warehouseFk = vWarehouseFk
|
2024-01-15 11:31:03 +00:00
|
|
|
AND t.clientFk = vClientFk
|
|
|
|
AND DATE(t.shipped) = util.VN_CURDATE()
|
|
|
|
AND a.isDefaultAddress
|
|
|
|
LIMIT 1;
|
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,
|
2024-01-15 11:31:03 +00:00
|
|
|
NULL,
|
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,
|
2024-01-15 11:31:03 +00:00
|
|
|
CONCAT(longName,' ',worker_getCode(), ' ', LEFT(CAST(util.VN_NOW() AS TIME),5)),
|
2023-09-01 10:34:33 +00:00
|
|
|
vQuantity
|
|
|
|
FROM item
|
|
|
|
WHERE id = vItemFk;
|
|
|
|
|
|
|
|
UPDATE cache.visible
|
|
|
|
SET visible = visible - vQuantity
|
|
|
|
WHERE calc_id = vCalc
|
|
|
|
AND item_id = vItemFk;
|
|
|
|
END$$
|
|
|
|
DELIMITER ;
|