-- --------------------------------------------------------
-- Host:                         192.168.137.8
-- Server version:               8.0.23 - MySQL Community Server - GPL
-- Server OS:                    Linux
-- HeidiSQL Version:             11.2.0.6213
-- --------------------------------------------------------

/*!40101 SET @OLD_CHARACTER_SET_CLIENT=@@CHARACTER_SET_CLIENT */;
/*!40101 SET NAMES utf8 */;
/*!50503 SET NAMES utf8mb4 */;
/*!40014 SET @OLD_FOREIGN_KEY_CHECKS=@@FOREIGN_KEY_CHECKS, FOREIGN_KEY_CHECKS=0 */;
/*!40101 SET @OLD_SQL_MODE=@@SQL_MODE, SQL_MODE='NO_AUTO_VALUE_ON_ZERO' */;
/*!40111 SET @OLD_SQL_NOTES=@@SQL_NOTES, SQL_NOTES=0 */;

-- Dumping database structure for mutu
USE `mutu`;

-- Dumping structure for procedure mutu.cetakAnalisaDanPDSA
DROP PROCEDURE IF EXISTS `cetakAnalisaDanPDSA`;
DELIMITER //
CREATE PROCEDURE `cetakAnalisaDanPDSA`(
	IN `PINDIKATOR` INT,
	IN `PRUANGAN` CHAR(20),
	IN `PTGL_AWAL` VARCHAR(50),
	IN `PTGL_AKHIR` VARCHAR(50)
)
BEGIN
	SET @idanalisa = null;
	SET @deskpds = null;
	SET @numan = 0;
	SET @numpdsa = 0;
	
	SELECT 
		IF(@idanalisa = an.ID, '' , @numan := @numan + 1) NO_ANALISA,
		IF(@idanalisa = an.ID, '', @desk:= an.ANALISA) ANALISA,
		IF(@idanalisa = an.ID, '', CONCAT('P.Awal : ',an.TANGGAL_AWAL,' P.Akhir : ',an.TANGGAL_AKHIR)) PERIODE,
		IF(@deskpds = pd.ID , '', IF(@idanalisa = an.ID, @numpdsa := @numpdsa + 1 , @numpdsa := 1)) NO_PDSA,
		IF(@idanalisa = an.ID, @idanalisa, @idanalisa:= an.ID) ID_ANALISA,
		IF(@deskpds = pd.ID, @deskpds, @deskpds := pd.ID) IDPDSA, 
		pd.PLAN,
		pd.`DO`,
		pd.STUDY,
		pd.`ACTION` 
	FROM 
		mutu.analisa an
	LEFT JOIN 
		mutu.pdsa pd ON pd.ANALISA = an.ID
	WHERE an.INDIKATOR = PINDIKATOR
	AND an.RUANGAN = PRUANGAN
	AND an.TANGGAL_AWAL >= PTGL_AWAL
	AND an.TANGGAL_AKHIR <= PTGL_AKHIR
	AND an.`STATUS` != 0
	;
END//
DELIMITER ;

/*!40101 SET SQL_MODE=IFNULL(@OLD_SQL_MODE, '') */;
/*!40014 SET FOREIGN_KEY_CHECKS=IFNULL(@OLD_FOREIGN_KEY_CHECKS, 1) */;
/*!40101 SET CHARACTER_SET_CLIENT=@OLD_CHARACTER_SET_CLIENT */;
/*!40111 SET SQL_NOTES=IFNULL(@OLD_SQL_NOTES, 1) */;
