DROP PROCEDURE IF EXISTS sakti.setDetailBarang;

DELIMITER //
CREATE DEFINER=`root`@`localhost` PROCEDURE `sakti`.`setDetailBarang`(IN `PHEADER` BIGINT, IN `PNOMOR` BIGINT)
BEGIN
	INSERT INTO sakti_barang_detail (HEADER, KODE_BARANG, HARGA_SATUAN, JUMLAH_BARANG, JENIS_TKDN, NILAI_TKDN, KET_TKDN)
	(
		SELECT
			PHEADER HEADER, br.KODE_PSEDIA, pd.HARGA, pd.JUMLAH, pd.IDJENISBARANG, pd.TKDN, '-'
		FROM sakti.sakti_bast_realisasi sba
		, inventory.penerimaan_barang pb
		, inventory.penerimaan_barang_detil pd
		, inventory.barang br
		WHERE br.ID = pd.BARANG AND pd.PENERIMAAN = pb.ID AND pd.`STATUS` = 2
		AND pb.ID = sba.REF AND sba.ID = PNOMOR
	);
END//
DELIMITER ;