USE `inventory`;
-- --------------------------------------------------------
-- Versi server:                 8.0.11 - MySQL Community Server - GPL
-- OS Server:                    Win64
-- HeidiSQL Versi:               9.2.0.4947
-- --------------------------------------------------------


-- Dumping structure for trigger inventory.penerimaan_after_update
DROP TRIGGER IF EXISTS `penerimaan_after_update`;
SET @OLDTMP_SQL_MODE=@@SQL_MODE, SQL_MODE='NO_ENGINE_SUBSTITUTION';
DELIMITER //
CREATE TRIGGER `penerimaan_after_update` AFTER UPDATE ON `penerimaan` FOR EACH ROW BEGIN

	IF OLD.JENIS = 2 AND OLD.STATUS = 1 AND NEW.STATUS = 0 THEN
		UPDATE inventory.pengiriman 
		   SET STATUS = 1
		 WHERE NOMOR = NEW.REF;		 		 
	END IF;

	/* Script Ubah Tanggal Terima dan Kirim */
	IF NEW.TANGGAL != OLD.TANGGAL THEN
		UPDATE inventory.pengiriman 
		   SET TANGGAL = NEW.TANGGAL
		 WHERE NOMOR = NEW.REF;		 		 
	END IF;
END//
DELIMITER ;
