USE `inventory`;
DROP TRIGGER IF EXISTS `barang_before_update`;
SET @OLDTMP_SQL_MODE=@@SQL_MODE, SQL_MODE='NO_ENGINE_SUBSTITUTION';
DELIMITER //
CREATE TRIGGER `barang_before_update` BEFORE UPDATE ON `barang` FOR EACH ROW BEGIN
	IF OLD.KODE_PSEDIA = '0' THEN
		SET NEW.KODE_PSEDIA = (SELECT generatorKodePersediaan(NEW.KLP_PSEDIA, OLD.ID));
	END IF;
END//
DELIMITER ;
SET SQL_MODE=@OLDTMP_SQL_MODE;