-- --------------------------------------------------------
-- Server OS:                    Linux
-- HeidiSQL Version:             11.0.0.5919
-- --------------------------------------------------------

USE inventory;
-- Dumping structure for trigger inventory.purchase_order_detil_after_update
DROP TRIGGER IF EXISTS `purchase_order_detil_after_update`;
SET @OLDTMP_SQL_MODE=@@SQL_MODE, SQL_MODE='NO_ENGINE_SUBSTITUTION';
DELIMITER //
CREATE TRIGGER `purchase_order_detil_after_update` AFTER UPDATE ON `purchase_order_detil` FOR EACH ROW BEGIN
	IF OLD.STATUS != NEW.STATUS AND NEW.STATUS = 2 THEN
		UPDATE inventory.purchase_order
		   SET STATUS = 2
		 WHERE NO_PO = OLD.ID_PO
		   AND STATUS = 1;
		   
		-- INSERT KE TABLE PENERIMAAN PO TEMP   
		INSERT INTO inventory.penerimaan_po_temp (ID_PO_DETIL, BARANG, JUMLAH_PESAN, BONUS, JUMLAH_TERIMA, STATUS)
		VALUES(OLD.ID, OLD.BARANG, OLD.JUMLAH, OLD.JUMLAH_BONUS, 0, 1);
		-- ******* ---
		
	END IF;
END//
DELIMITER ;

