USE `sakti`;
DROP TRIGGER IF EXISTS `sakti_bast_realisasi_after_update`;
SET @OLDTMP_SQL_MODE=@@SQL_MODE, SQL_MODE='NO_ENGINE_SUBSTITUTION';
DELIMITER //
CREATE TRIGGER `sakti_bast_realisasi_after_update` AFTER UPDATE ON `sakti_bast_realisasi` FOR EACH ROW BEGIN
	IF NEW.FLAG_HEADER != OLD.FLAG_HEADER AND NEW.FLAG_HEADER = 1 THEN
		CALL setHeader(NEW.NO_BAST, NEW.TANGGAL_BAST, NEW.NO_SP, NEW.ID);
	END IF;
	IF OLD.STATUS != NEW.STATUS AND NEW.STATUS=2 THEN
		UPDATE inventory.penerimaan_barang SET STATUS_ADK_SAKTI = 2 WHERE ID = NEW.REF AND STATUS_ADK_SAKTI = 1;
	END IF;
	
	IF NEW.STATUS=1 THEN
		UPDATE inventory.penerimaan_barang SET STATUS_ADK_SAKTI = 1 WHERE ID = NEW.REF;
	END IF;
END//
DELIMITER ;
