
USE `inventory`;

-- Dumping structure for procedure laporan.LaporanTransaksiPenerimaanResidu
DROP PROCEDURE IF EXISTS `inventory`.`getExpiredDate`;
DELIMITER //
CREATE DEFINER=`root`@`localhost` FUNCTION `inventory`.`getExpiredDate`(`PBARANG` INT, `PTANGGAL` DATETIME) RETURNS varchar(75) CHARSET latin1
    DETERMINISTIC
BEGIN
   DECLARE HASIL DATE;
   
	SELECT MASA_BERLAKU INTO HASIL
	FROM (SELECT MASA_BERLAKU
				FROM inventory.penerimaan_barang_detil a 
				WHERE a.BARANG=PBARANG AND MASA_BERLAKU > PTANGGAL
				ORDER BY MASA_BERLAKU
				LIMIT 2) ab
	 ORDER BY MASA_BERLAKU DESC
	 LIMIT 1;
 
  RETURN HASIL;
END//
DELIMITER ;