USE `sakti`;

DROP PROCEDURE IF EXISTS `sakti`.`onHitungUlangTotalDetailBarang`;
DELIMITER //
CREATE DEFINER=`root`@`localhost` PROCEDURE `sakti`.`getAdk`(IN `PNOMOR` INT)
BEGIN
	SET @idAdk:=1;
	SELECT
			CONCAT(
				s.KODE_SATKER, "|"
				, s.KODE_TAHUN_ANGGARAN, "|"
				, s.NO_DOKUMEN, "|"
				, s.TGL_BUKU, ".00|"
				, s.TGL_DOKUMEN, ".00|"
				, s.URAIAN_DOKUMEN, "|"
				, s.KATEGORI, "|"
				, s.NAMA_PENERIMA, "|"
				, s.NO_REKENING, "|"
				, s.KODE_MATA_UANG, "|"
				, s.NILAI_BAST, "|"
				, s.NO_DIPA, "|"
				, s.TGL_DIPA, ".00|"
				, s.NILAI_KURS, "|"
				, s.KODE_COA, "|"
				, s.NPWP
			) header_txt
			, (SELECT `getDataCoa`(s.ID)) coa_txt
			, (SELECT `getDetailBarang`(s.ID)) barang_txt
			, @idAdk:=(SELECT `generateIdAdk`(s.KODE_SATKER,s.ID, date(NOW()))) id_adk, s.FLAG_ADK
	FROM sakti.sakti_header s, sakti.sakti_coa c, sakti.sakti_barang_detail d
	WHERE d.HEADER = s.ID AND c.HEADER = s.ID AND s.ID = PNOMOR
	GROUP BY s.ID;
	
	UPDATE sakti_header SET NO_URUT_ADK = CONCAT("BAST",@idAdk), FLAG_ADK = 2, IS_CUSTOM_ITEM = 0 WHERE ID = PNOMOR;
END//
DELIMITER ;