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


USE `cssd`;

-- Dumping structure for trigger cssd.pengembalian_alat_after_update
SET @OLDTMP_SQL_MODE=@@SQL_MODE, SQL_MODE='NO_ENGINE_SUBSTITUTION';
DELIMITER //
CREATE TRIGGER `pengembalian_alat_after_update` AFTER UPDATE ON `pengembalian_alat` FOR EACH ROW BEGIN

	IF NEW.STATUS = 0 THEN
		UPDATE cssd.pengembalian_alat_detil pad 
		   SET pad.STATUS = 0
		 WHERE pad.PENGEMBALIAN_ALAT = OLD.NOMOR;
		 
		UPDATE cssd.pengembalian_alat_detil_barangruangan padbr
		   SET padbr.STATUS = 0
		 WHERE padbr.PENGEMBALIAN_ALAT = OLD.NOMOR;
	END IF;

	IF NEW.STATUS = 2 THEN
		UPDATE cssd.pengembalian_alat_detil pad 
		   SET pad.STATUS = 2
		 WHERE pad.PENGEMBALIAN_ALAT = OLD.NOMOR;
		 
		UPDATE cssd.pengembalian_alat_detil_barangruangan padbr
		   SET padbr.STATUS = 2
		 WHERE padbr.PENGEMBALIAN_ALAT = OLD.NOMOR;
		 
		/*UPDATE cssd.penerimaan_alat_kotor pak
		   SET pak.STATUS = 2, pak.KEMBALI = 2
		 WHERE pak.NOMOR = OLD.PENERIMAAN_ALAT_KOTOR;*/
	END IF;
	
END//
DELIMITER ;

-- Dumping structure for trigger cssd.petugas_kegiatan_after_update
SET @OLDTMP_SQL_MODE=@@SQL_MODE, SQL_MODE='NO_ENGINE_SUBSTITUTION';
DELIMITER //
CREATE TRIGGER `petugas_kegiatan_after_update` AFTER UPDATE ON `petugas_kegiatan` FOR EACH ROW BEGIN

	IF NEW.STATUS = 2 THEN
		UPDATE cssd.penerimaan_alat_kotor pak 
		   SET pak.KEMBALI = 2
		 WHERE pak.NOMOR = OLD.PENERIMAAN_ALAT_KOTOR;
	END IF;

END//
DELIMITER ;

