DROP FUNCTION IF EXISTS sakti.getDetailBarangTkdn;

DELIMITER //
CREATE DEFINER=`root`@`localhost` FUNCTION `sakti`.`getDetailBarangTkdn`(`PHEADER` INT, `PJENIS` INT) RETURNS longtext CHARSET latin1
    DETERMINISTIC
BEGIN
	DECLARE VTEXT LONGTEXT;
	SELECT
		GROUP_CONCAT(CONCAT(
			IF(s.KODE_BARANG IS NULL,"",s.KODE_BARANG), "|"
			, s.HARGA_SATUAN, "|"
			, s.JUMLAH_BARANG, "|"
			, s.KODE_UAKPB
			, s.KET_TKDN
			, s.NILAI_TKDN
			, s.JENIS_TKDN
		) SEPARATOR "\r\n") INTO VTEXT
	FROM sakti.sakti_barang_detail s
	WHERE s.HEADER = PHEADER 
	AND s.JENIS_TKDN > 0;
	

	RETURN VTEXT;
END//
DELIMITER ;