DELIMITER $$
CREATE OR REPLACE DEFINER=`root`@`localhost` TRIGGER `stock`.`inbound_afterDelete`
	AFTER DELETE ON `inbound`
	FOR EACH ROW
BEGIN
	UPDATE outbound o
		JOIN inboundPick ou ON ou.outboundFk = o.id
		SET o.lack = o.lack + ou.quantity,
			o.isSync = FALSE
		WHERE ou.inboundFk = OLD.id;

	DELETE FROM inboundPick
		WHERE inboundFk = OLD.id;

	CALL visible_log(
		OLD.isPicked,
		OLD.warehouseFk,
		OLD.itemFk,
		-OLD.quantity
	);
END$$
DELIMITER ;
