コード例 #1
0
	function simpan_langsung_bayar($val) {
		$kon = new Konek;
		$objResponse = new xajaxResponse;
		$kon->sql = "SELECT kb.id as id, kb.bayar_bhp as bayar_bhp, kb.bayar_jasa as bayar_jasa FROM kunjungan_bayar kb LEFT JOIN kwitansi_detil kwd ON (kwd.kunjungan_bayar_id = kb.id) WHERE kb.kunjungan_kamar_id = '".$val[lb_id_kunjungan_kamar]."' AND kwd.kwitansi_id IS NULL";
		$kon->execute();
		$data = $kon->getAll();
		if(!empty($data)) {
			if($val[lb_mampu_bayar] < $val[lb_kurang]) $status = "ANGSUR";
			else $status = "LUNAS";
			$id_kwitansi = bikinKwitansi("IRD", $val[lb_mampu_bayar], $status);
			$mampu = round($val[lb_mampu_bayar]/$val[lb_kurang], 2);
			$tot = 0;
			for($i=0;$i<sizeof($data);$i++) {
				$data[$i][mampu_bayar_bhp] = round($data[$i][bayar_bhp] * $mampu);
				$data[$i][mampu_bayar_jasa] = round($data[$i][bayar_jasa] * $mampu);
				$tot += $data[$i][mampu_bayar_bhp] + $data[$i][mampu_bayar_jasa];
			}
			$selisih = $val[lb_mampu_bayar] - $tot;
			if($data[0][mampu_bayar_jasa]) $data[0][mampu_bayar_jasa] += $selisih;
			else $data[0][mampu_bayar_bhp] += $selisih;

			for($i=0;$i<sizeof($data);$i++) {
				$kon->sql = "UPDATE kunjungan_bayar SET mampu_bayar_bhp = '".$data[$i][mampu_bayar_bhp]."', mampu_bayar_jasa = '".$data[$i][mampu_bayar_jasa]."', kwid = '".$id_kwitansi."' WHERE id = '".$data[$i][id]."'";
				$kon->execute();
				//pembayaran angsuran
				$kon->sql = "INSERT INTO kwitansi_detil(kunjungan_bayar_id, kwitansi_id, angsuran_bhp, angsuran_jasa) VALUES ('".$data[$i][id]."', '".$id_kwitansi."', '".$data[$i][mampu_bayar_bhp]."', '".$data[$i][mampu_bayar_jasa]."')";
				$kon->execute();
			}
			$id_kwitansi = tambahNol($id_kwitansi, 20);
			$objResponse->addScriptCall("cetak_kwitansi", "IRD-" . $id_kwitansi);
			$objResponse->addScriptCall("show_status_simpan");
		} else {
			$objResponse->addAlert("Data Pembayaran Tidak Dapat Dirubah, karena : \n1. Kwitansi Sudah Dibuat atau\n2. Belum Terjadi Transaksi!");
		}
		$objResponse->addScriptCall("tutup_modal_lb");
		//$objResponse->addAssign("debug", "innerHTML", $sql);
		return $objResponse;
	}
コード例 #2
0
	function simpan_langsung_bayar($val) {
		$kon = new Konek;
		$objResponse = new xajaxResponse;
		$kon->sql = "SELECT kb.id as id, kb.bayar_bhp as bayar_bhp, kb.bayar_jasa as bayar_jasa, kb.mampu_bayar_bhp as mampu_bayar_bhp, kb.mampu_bayar_jasa as mampu_bayar_jasa FROM kunjungan_bayar kb JOIN kunjungan_kamar kk ON (kk.id = kb.kunjungan_kamar_id) JOIN kwitansi_detil kwd ON (kwd.kunjungan_bayar_id = kb.id) WHERE kk.kunjungan_id = '".$val[lb_id_kunjungan]."' AND kwd.kwitansi_id = '".$val[lb_id_kwitansi]."'";
		$kon->execute();
		$data = $kon->getAll();
		if(!empty($data)) {
			if($val[lb_mampu_bayar] < $val[lb_kurang]) $status = "ANGSUR";
			else $status = "LUNAS";
			$id_kwitansi = bikinKwitansi("KASIR", $val[lb_mampu_bayar], $status);
			$mampu = round($val[lb_mampu_bayar]/$val[lb_kurang], 2);
			//$objResponse->addAppend("debug", "innerHTML", $mampu . "<br />");
			$tot = 0;
			for($i=0;$i<sizeof($data);$i++) {
				$data[$i][angsuran_bhp] = round($data[$i][bayar_bhp] * $mampu);
				$data[$i][angsuran_jasa] = round($data[$i][bayar_jasa] * $mampu);
				$data[$i][pertambahan_bhp] += $data[$i][angsuran_bhp]-$data[$i][mampu_bayar_bhp];
				$data[$i][pertambahan_jasa] += $data[$i][angsuran_jasa]-$data[$i][mampu_bayar_jasa];
				$tot += $data[$i][angsuran_bhp] + $data[$i][angsuran_jasa];
				//$objResponse->addAppend("debug", "innerHTML", $data[$i][angsuran_bhp] . " - " . $data[$i][angsuran_jasa] . ", tot : ".$tot."<br />");
			}
			$selisih = ($val[lb_mampu_bayar]+$val[lb_sudah_dibayar]) - $tot;
			//$objResponse->addAppend("debug", "innerHTML", "selisih : " . $selisih . ", mampu bayar : " .$val[lb_mampu_bayar]. ", tot : ".$tot."<br />");
			if($data[0][angsuran_jasa]) {
				$data[0][angsuran_jasa] += $selisih;
			} else {
				$data[0][angsuran_bhp] += $selisih;
			}

			for($i=0;$i<sizeof($data);$i++) {
				$sql = "UPDATE kunjungan_bayar kb, kwitansi_detil kwd SET kb.mampu_bayar_bhp = '".$data[$i][angsuran_bhp]."', kb.mampu_bayar_jasa = '".$data[$i][angsuran_jasa]."' WHERE kwd.kunjungan_bayar_id = kb.id AND kb.id = '".$data[$i][id]."' AND kwd.kwitansi_id = '".$val[lb_id_kwitansi]."'";
				//$objResponse->addAppend("debug", "innerHTML", nl2br($sql) . "<br />");
				$kon->sql = $sql;
				$kon->execute();
				//pembayaran angsuran
				$sql = "INSERT INTO kwitansi_detil(kunjungan_bayar_id, kwitansi_id, angsuran_bhp, angsuran_jasa) VALUES ('".$data[$i][id]."', '".$id_kwitansi."', '".$data[$i][pertambahan_bhp]."', '".$data[$i][pertambahan_jasa]."')";
				//$objResponse->addAppend("debug", "innerHTML", nl2br($sql) . "<br />");
				$kon->sql = $sql;
				$kon->execute();
			}
			$id_kwitansi = tambahNol($id_kwitansi, 20);
			$objResponse->addScriptCall("cetak_kwitansi", "KASIR-" . $id_kwitansi);
			$objResponse->addScriptCall("show_status_simpan");
		} else {
			$objResponse->addAlert("Data Pembayaran Tidak Dapat Dirubah, karena : \n1. Kwitansi Sudah Dibuat atau\n2. Belum Terjadi Transaksi!");
		}
		$objResponse->addScriptCall("tutup_modal_lb");
		//$objResponse->addAssign("debug", "innerHTML", $sql);
		return $objResponse;
	}
コード例 #3
0
	function simpan_kunjungan($value, $langsung_bayar = false, $tutup_modal = true) {
		$cleaner = new FormCleaner;
		$cleaner->setValue($value);
		$cleaner->clean();
		$val = $cleaner->getValue();
		$kon = new Konek;
		//update
		$kon->sql = "
			UPDATE
				kunjungan
			SET 
				keadaan_keluar = '".$val[input_keadaan_keluar]."'
			WHERE
				id = '".$val[input_id_kunjungan]."'
		";
		$kon->execute();

		//update
		$sql = "
			UPDATE
				kunjungan_kamar
			SET
				dokter_id = NULLIF('".$val[input_dokter_id]."', ''),
				kelanjutan = NULLIF('".$val[input_kelanjutan]."',''),
				diagnosa_utama_id = NULLIF('".$val[input_diagnosa_utama]."', ''),
				tgl_keluar = '".$val[input_tgl_keluar_thn]."-".$val[input_tgl_keluar_bln]."-".$val[input_tgl_keluar_tgl]." ".$val[input_tgl_keluar_jam].":".$val[input_tgl_keluar_mnt].":00'
			WHERE
				id = '".$val[input_id_kunjungan_kamar]."'
		";

		$kon->sql = $sql;
		$kon->execute();
		$afek = $kon->affected_rows;
		$objResponse = new xajaxResponse();
//LANGSUNG BAYAR
		if($langsung_bayar == true) {
			$id_kwitansi = bikinKwitansi();
			$mampu_bayar = @round($val[mampu]/$val[total]);
		} else {
			$id_kwitansi = NULL;
			$mampu_bayar = 1;
		}
		//$objResponse->addAlert(print_r($val));
		//$objResponse->addAppend("debug", "innerHTML", $mampu_bayar);
//INSERT UPDATE KARCIS
		for($i=0;$i<sizeof($val[input_karcis]);$i++) {
			$kunci = key($val[input_karcis]);
			//get
/*
			$kon->sql = "SELECT * FROM karcis WHERE id = '".$val[input_karcis][$kunci]."'";
			$kon->execute();
			$data_karcis[$i] = $kon->getOne();

			$jasa_p[$i] = $data_karcis[$i][jasa_p] * $val[input_karcis_bayar][$kunci];
			$jasa_rs[$i] = $data_karcis[$i][jasa_rs] * $val[input_karcis_bayar][$kunci];
			$jasa_rs_op[$i] = $data_karcis[$i][jasa_rs_op] * $val[input_karcis_bayar][$kunci];
			$jasa_rs_kembang[$i] = $data_karcis[$i][jasa_rs_kembang] * $val[input_karcis_bayar][$kunci];
			$jasa_rs_adm[$i] = $data_karcis[$i][jasa_rs_adm] * $val[input_karcis_bayar][$kunci];
			$jasa_rs_sdm[$i] = $data_karcis[$i][jasa_rs_sdm] * $val[input_karcis_bayar][$kunci];
			$spesialis[$i] = $data_karcis[$i][spesialis] * $val[input_karcis_bayar][$kunci] * $data_karcis[$i][netto];
			$spesialis_pendamping[$i] = $data_karcis[$i][spesialis_pendamping] * $val[input_karcis_bayar][$kunci] * $data_karcis[$i][netto];
			$ugp[$i] = $data_karcis[$i][ugp] * $val[input_karcis_bayar][$kunci] * $data_karcis[$i][netto];
			$grabaf[$i] = $data_karcis[$i][grabaf] * $val[input_karcis_bayar][$kunci] * $data_karcis[$i][netto];
			$perawat[$i] = $data_karcis[$i][perawat] * $val[input_karcis_bayar][$kunci] * $data_karcis[$i][netto];
			$penunjang[$i] = $data_karcis[$i][penunjang] * $val[input_karcis_bayar][$kunci] * $data_karcis[$i][netto];
			$zakat[$i] = $data_karcis[$i][zakat] * $val[input_karcis_bayar][$kunci] * $data_karcis[$i][netto];
			$pajak[$i] = $data_karcis[$i][pajak] * ($val[input_karcis_bayar][$kunci] - ($jasa_p[$i] + $jasa_rs_op[$i] + $jasa_rs_kembang[$i] + $jasa_rs_adm[$i] + $jasa_rs_sdm[$i]));
			//$objResponse->addAlert("pajak : " . $pajak[$i]);
*/			
			if(!$val[input_kunjungan_karcis_id][$kunci]) {
				//insert
				$sql = "
				INSERT INTO 
					kunjungan_bayar (
						nama,
						kunjungan_kamar_id, 
						karcis_id, 
						hak_id, 
						biaya,
						jumlah, 
						bayar,
						mampu_bayar,
						jasa_p,
						jasa_rs,
						jasa_rs_op,
						jasa_rs_kembang,
						jasa_rs_adm,
						jasa_rs_sdm,
						spesialis,
						spesialis_pendamping,
						ugp,
						grabaf,
						perawat,
						penunjang,
						zakat,
						pajak
					)	SELECT
							'".$val[input_karcis_nama][$i]."', 
							'".$val[input_id_kunjungan_kamar]."', 
							'".$val[input_karcis][$kunci]."', 
							'".$val[input_karcis_hak][$kunci]."', 
							'".$val[input_karcis_biaya][$kunci]."',
							'".$val[input_karcis_jml][$kunci]."', 
							'".$val[input_karcis_bayar][$kunci]."',
							'".($val[input_karcis_bayar][$kunci]*$mampu_bayar)."',
							jasa_p,
							jasa_rs,
							jasa_rs_op,
							jasa_rs_kembang,
							jasa_rs_adm,
							jasa_rs_sdm,
							spesialis,
							spesialis_pendamping,
							ugp,
							grabaf,
							perawat,
							penunjang,
							zakat,
							pajak 
						FROM
							karcis
						WHERE 
							id = '".$val[input_karcis][$kunci]."'
					";
				$kon->sql = $sql;
				$kon->execute();
			} else {
				//update
				$sql = "
				UPDATE 
					kunjungan_bayar 
				SET 
					hak_id = '".$val[input_karcis_hak][$kunci]."', 
					biaya = '".$val[input_karcis_biaya][$kunci]."', 
					jumlah = '".$val[input_karcis_jml][$kunci]."', 
					bayar = '".$val[input_karcis_bayar][$kunci]."',
					mampu_bayar = '".($val[input_karcis_bayar][$kunci]*$mampu_bayar)."'
				WHERE 
					id = '".$val[input_kunjungan_karcis_id][$kunci]."'";
				$kon->sql = $sql;
				$kon->execute();
				//$objResponse->addAppend("debug", "innerHTML", $sql);
			}
			//$objResponse->addAppend("debug", "innerHTML", $sql);
			next($val[input_karcis]);
		}

//TINDAKAN
		for($i=0;$i<sizeof($val[input_icopim]);$i++) {
			$kunci = key($val[input_icopim]);
			$parent = $val[input_icopim_parent][$i];
			//get
			if(!$val[input_kunjungan_icopim_id][$kunci] && $val[input_icopim][$kunci]) {
				//insert
				$sql = "INSERT INTO kunjungan_kamar_icopim (kunjungan_kamar_id, icopim_id, nama) VALUES ('".$val[input_id_kunjungan_kamar]."', '".$val[input_icopim][$kunci]."', '".$val[input_icopim_nama][$kunci]."')";
				$kon->sql = $sql;
				$kon->execute();
				$id_kki = $kon->last_id;
				//$objResponse->addAppend("debug", "innerHTML", $parent . "<br /><br />");
/*diinsert satu satu*/
				for($j=0;$j<sizeof($val[input_icopim_detil_field][$parent]);$j++) {
					$field = "";
					$field = $val[input_icopim_detil_field][$parent][$j];
/*
					$netto = $val[input_icopim_detil_bayar][$parent][$field] * $val[input_icopim_detil_netto][$parent];
					$zakat = $val[input_icopim_detil_bayar][$parent][$field] * $val[input_icopim_detil_netto][$parent] * $val[input_icopim_detil_zakat][$parent];
					$pajak = $val[input_icopim_detil_bayar][$parent][$field] * $val[input_icopim_detil_pajak][$parent];
*/
					//$objResponse->addAppend("debug", "innerHTML", $field . " => " . $val[input_icopim_detil_bayar][$parent][$field] . "<br />");
					if($field == "jasa_rumah_sakit") {
						$sql = "INSERT INTO kunjungan_bayar (nama, kunjungan_kamar_id, kunjungan_kamar_icopim_id, icopim_detil_id, hak_id, biaya, sifat, jumlah, bayar, mampu_bayar, jasa_p, jasa_rs, jasa_rs_op, jasa_rs_kembang, jasa_rs_adm, jasa_rs_sdm) SELECT '".$field."', '".$val[input_id_kunjungan_kamar]."', '".$id_kki."', '".$val[input_icopim_detil][$parent]."', '".$val[input_icopim_detil_hak][$parent][$j]."', '".$val[input_icopim_detil_biaya][$parent][$j]."',  '".$val[input_icopim_detil_sifat][$parent][$j]."', '".$val[input_icopim_detil_jml][$parent][$j]."', '".$val[input_icopim_detil_bayar][$parent][$j]."', '".($val[input_icopim_detil_bayar][$parent][$j]*$mampu_bayar)."', jasa_p, jasa_rs, jasa_rs_op, jasa_rs_kembang, jasa_rs_adm, jasa_rs_sdm FROM icopim_detil WHERE id = '".$val[input_icopim_detil][$parent]."'";

					} elseif($field == "spesialis") {
						$sql = "INSERT INTO kunjungan_bayar (nama, kunjungan_kamar_id, kunjungan_kamar_icopim_id, icopim_detil_id, hak_id, biaya, sifat, jumlah, bayar, mampu_bayar, spesialis, pajak, zakat) SELECT '".$field."', '".$val[input_id_kunjungan_kamar]."', '".$id_kki."', '".$val[input_icopim_detil][$parent]."', '".$val[input_icopim_detil_hak][$parent][$j]."', '".$val[input_icopim_detil_biaya][$parent][$j]."', '".$val[input_icopim_detil_sifat][$parent][$j]."', '".$val[input_icopim_detil_jml][$parent][$j]."', '".$val[input_icopim_detil_bayar][$parent][$j]."', '".($val[input_icopim_detil_bayar][$parent][$j]*$mampu_bayar)."', netto, pajak, zakat FROM icopim_detil WHERE id = '".$val[input_icopim_detil][$parent]."'";

					} elseif($field == "spesialis_pendamping") {
						$sql = "INSERT INTO kunjungan_bayar (nama, kunjungan_kamar_id, kunjungan_kamar_icopim_id, icopim_detil_id, hak_id, biaya, sifat, jumlah, bayar, mampu_bayar, spesialis_pendamping, pajak, zakat) SELECT '".$field."', '".$val[input_id_kunjungan_kamar]."', '".$id_kki."', '".$val[input_icopim_detil][$parent]."', '".$val[input_icopim_detil_hak][$parent][$j]."', '".$val[input_icopim_detil_biaya][$parent][$j]."', '".$val[input_icopim_detil_sifat][$parent][$j]."', '".$val[input_icopim_detil_jml][$parent][$j]."', '".$val[input_icopim_detil_bayar][$parent][$j]."', '".($val[input_icopim_detil_bayar][$parent][$j]*$mampu_bayar)."', netto, pajak, zakat FROM icopim_detil WHERE id = '".$val[input_icopim_detil][$parent]."'";
					
					} elseif($field == "perawat_perinatologi") {
						$sql = "INSERT INTO kunjungan_bayar (nama, kunjungan_kamar_id, kunjungan_kamar_icopim_id, icopim_detil_id, hak_id, biaya, sifat, jumlah, bayar, mampu_bayar, perawat_perinatologi, pajak, zakat) SELECT '".$field."', '".$val[input_id_kunjungan_kamar]."', '".$id_kki."', '".$val[input_icopim_detil][$parent]."', '".$val[input_icopim_detil_hak][$parent][$j]."', '".$val[input_icopim_detil_biaya][$parent][$j]."', '".$val[input_icopim_detil_sifat][$parent][$j]."', '".$val[input_icopim_detil_jml][$parent][$j]."', '".$val[input_icopim_detil_bayar][$parent][$j]."', '".($val[input_icopim_detil_bayar][$parent][$j]*$mampu_bayar)."', netto, pajak, zakat FROM icopim_detil WHERE id = '".$val[input_icopim_detil][$parent]."'";
					
					} elseif($field == "dr_umum") {
						$sql = "INSERT INTO kunjungan_bayar (nama, kunjungan_kamar_id, kunjungan_kamar_icopim_id, icopim_detil_id, hak_id, biaya, sifat, jumlah, bayar, mampu_bayar, dr_umum, pajak, zakat) SELECT '".$field."', '".$val[input_id_kunjungan_kamar]."', '".$id_kki."', '".$val[input_icopim_detil][$parent]."', '".$val[input_icopim_detil_hak][$parent][$j]."', '".$val[input_icopim_detil_biaya][$parent][$j]."', '".$val[input_icopim_detil_sifat][$parent][$j]."', '".$val[input_icopim_detil_jml][$parent][$j]."', '".$val[input_icopim_detil_bayar][$parent][$j]."', '".($val[input_icopim_detil_bayar][$parent][$j]*$mampu_bayar)."', netto, pajak, zakat FROM icopim_detil WHERE id = '".$val[input_icopim_detil][$parent]."'";
					
					} elseif($field == "dr_gigi") {
						$sql = "INSERT INTO kunjungan_bayar (nama, kunjungan_kamar_id, kunjungan_kamar_icopim_id, icopim_detil_id, hak_id, biaya, sifat, jumlah, bayar, mampu_bayar, dr_gigi, pajak, zakat) SELECT '".$field."', '".$val[input_id_kunjungan_kamar]."', '".$id_kki."', '".$val[input_icopim_detil][$parent]."', '".$val[input_icopim_detil_hak][$parent][$j]."', '".$val[input_icopim_detil_biaya][$parent][$j]."', '".$val[input_icopim_detil_sifat][$parent][$j]."', '".$val[input_icopim_detil_jml][$parent][$j]."', '".$val[input_icopim_detil_bayar][$parent][$j]."', '".($val[input_icopim_detil_bayar][$parent][$j]*$mampu_bayar)."', netto, pajak, zakat FROM icopim_detil WHERE id = '".$val[input_icopim_detil][$parent]."'";
					
					} elseif($field == "assisten_non_dokter") {
						$sql = "INSERT INTO kunjungan_bayar (nama, kunjungan_kamar_id, kunjungan_kamar_icopim_id, icopim_detil_id, hak_id, biaya, sifat, jumlah, bayar, mampu_bayar, assisten_non_dokter, pajak, zakat) SELECT '".$field."', '".$val[input_id_kunjungan_kamar]."', '".$id_kki."', '".$val[input_icopim_detil][$parent]."', '".$val[input_icopim_detil_hak][$parent][$j]."', '".$val[input_icopim_detil_biaya][$parent][$j]."', '".$val[input_icopim_detil_sifat][$parent][$j]."', '".$val[input_icopim_detil_jml][$parent][$j]."', '".$val[input_icopim_detil_bayar][$parent][$j]."', '".($val[input_icopim_detil_bayar][$parent][$j]*$mampu_bayar)."', netto, pajak, zakat FROM icopim_detil WHERE id = '".$val[input_icopim_detil][$parent]."'";
					
					} elseif($field == "spesialis_anestesi") {
						$sql = "INSERT INTO kunjungan_bayar (nama, kunjungan_kamar_id, kunjungan_kamar_icopim_id, icopim_detil_id, hak_id, biaya, sifat, jumlah, bayar, mampu_bayar, spesialis_anestesi, pajak, zakat) SELECT '".$field."', '".$val[input_id_kunjungan_kamar]."', '".$id_kki."', '".$val[input_icopim_detil][$parent]."', '".$val[input_icopim_detil_hak][$parent][$j]."', '".$val[input_icopim_detil_biaya][$parent][$j]."', '".$val[input_icopim_detil_sifat][$parent][$j]."', '".$val[input_icopim_detil_jml][$parent][$j]."', '".$val[input_icopim_detil_bayar][$parent][$j]."', '".($val[input_icopim_detil_bayar][$parent][$j]*$mampu_bayar)."', netto, pajak, zakat FROM icopim_detil WHERE id = '".$val[input_icopim_detil][$parent]."'";
					
					} elseif($field == "aknest") {
						$sql = "INSERT INTO kunjungan_bayar (nama, kunjungan_kamar_id, kunjungan_kamar_icopim_id, icopim_detil_id, hak_id, biaya, sifat, jumlah, bayar, mampu_bayar, aknest, pajak, zakat) SELECT '".$field."', '".$val[input_id_kunjungan_kamar]."', '".$id_kki."', '".$val[input_icopim_detil][$parent]."', '".$val[input_icopim_detil_hak][$parent][$j]."', '".$val[input_icopim_detil_biaya][$parent][$j]."', '".$val[input_icopim_detil_sifat][$parent][$j]."', '".$val[input_icopim_detil_jml][$parent][$j]."', '".$val[input_icopim_detil_bayar][$parent][$j]."', '".($val[input_icopim_detil_bayar][$parent][$j]*$mampu_bayar)."', netto, pajak, zakat FROM icopim_detil WHERE id = '".$val[input_icopim_detil][$parent]."'";
					
					} elseif($field == "gizi") {
						$sql = "INSERT INTO kunjungan_bayar (nama, kunjungan_kamar_id, kunjungan_kamar_icopim_id, icopim_detil_id, hak_id, biaya, sifat, jumlah, bayar, mampu_bayar, gizi, pajak, zakat) SELECT '".$field."', '".$val[input_id_kunjungan_kamar]."', '".$id_kki."', '".$val[input_icopim_detil][$parent]."', '".$val[input_icopim_detil_hak][$parent][$j]."', '".$val[input_icopim_detil_biaya][$parent][$j]."', '".$val[input_icopim_detil_sifat][$parent][$j]."', '".$val[input_icopim_detil_jml][$parent][$j]."', '".$val[input_icopim_detil_bayar][$parent][$j]."', '".($val[input_icopim_detil_bayar][$parent][$j]*$mampu_bayar)."', netto, pajak, zakat FROM icopim_detil WHERE id = '".$val[input_icopim_detil][$parent]."'";
					
					} elseif($field == "fisioterapi") {
						$sql = "INSERT INTO kunjungan_bayar (nama, kunjungan_kamar_id, kunjungan_kamar_icopim_id, icopim_detil_id, hak_id, biaya, sifat, jumlah, bayar, mampu_bayar, fisioterapi, pajak, zakat) SELECT '".$field."', '".$val[input_id_kunjungan_kamar]."', '".$id_kki."', '".$val[input_icopim_detil][$parent]."', '".$val[input_icopim_detil_hak][$parent][$j]."', '".$val[input_icopim_detil_biaya][$parent][$j]."', '".$val[input_icopim_detil_sifat][$parent][$j]."', '".$val[input_icopim_detil_jml][$parent][$j]."', '".$val[input_icopim_detil_bayar][$parent][$j]."', '".($val[input_icopim_detil_bayar][$parent][$j]*$mampu_bayar)."', netto, pajak, zakat FROM icopim_detil WHERE id = '".$val[input_icopim_detil][$parent]."'";
					
					} elseif($field == "analis_pa") {
						$sql = "INSERT INTO kunjungan_bayar (nama, kunjungan_kamar_id, kunjungan_kamar_icopim_id, icopim_detil_id, hak_id, biaya, sifat, jumlah, bayar, mampu_bayar, analis_pa, pajak, zakat) SELECT '".$field."', '".$val[input_id_kunjungan_kamar]."', '".$id_kki."', '".$val[input_icopim_detil][$parent]."', '".$val[input_icopim_detil_hak][$parent][$j]."', '".$val[input_icopim_detil_biaya][$parent][$j]."', '".$val[input_icopim_detil_sifat][$parent][$j]."', '".$val[input_icopim_detil_jml][$parent][$j]."', '".$val[input_icopim_detil_bayar][$parent][$j]."', '".($val[input_icopim_detil_bayar][$parent][$j]*$mampu_bayar)."', netto, pajak, zakat FROM icopim_detil WHERE id = '".$val[input_icopim_detil][$parent]."'";
					
					} elseif($field == "bidan") {
						$sql = "INSERT INTO kunjungan_bayar (nama, kunjungan_kamar_id, kunjungan_kamar_icopim_id, icopim_detil_id, hak_id, biaya, sifat, jumlah, bayar, mampu_bayar, bidan, pajak, zakat) SELECT '".$field."', '".$val[input_id_kunjungan_kamar]."', '".$id_kki."', '".$val[input_icopim_detil][$parent]."', '".$val[input_icopim_detil_hak][$parent][$j]."', '".$val[input_icopim_detil_biaya][$parent][$j]."', '".$val[input_icopim_detil_sifat][$parent][$j]."', '".$val[input_icopim_detil_jml][$parent][$j]."', '".$val[input_icopim_detil_bayar][$parent][$j]."', '".($val[input_icopim_detil_bayar][$parent][$j]*$mampu_bayar)."', netto, pajak, zakat FROM icopim_detil WHERE id = '".$val[input_icopim_detil][$parent]."'";
					
					} elseif($field == "perawat") {
						$sql = "INSERT INTO kunjungan_bayar (nama, kunjungan_kamar_id, kunjungan_kamar_icopim_id, icopim_detil_id, hak_id, biaya, sifat, jumlah, bayar, mampu_bayar, perawat, pajak, zakat) SELECT '".$field."', '".$val[input_id_kunjungan_kamar]."', '".$id_kki."', '".$val[input_icopim_detil][$parent]."', '".$val[input_icopim_detil_hak][$parent][$j]."', '".$val[input_icopim_detil_biaya][$parent][$j]."', '".$val[input_icopim_detil_sifat][$parent][$j]."', '".$val[input_icopim_detil_jml][$parent][$j]."', '".$val[input_icopim_detil_bayar][$parent][$j]."', '".($val[input_icopim_detil_bayar][$parent][$j]*$mampu_bayar)."', netto, pajak, zakat FROM icopim_detil WHERE id = '".$val[input_icopim_detil][$parent]."'";
					
					} elseif($field == "penunjang") {
						$sql = "INSERT INTO kunjungan_bayar (nama, kunjungan_kamar_id, kunjungan_kamar_icopim_id, icopim_detil_id, hak_id, biaya, sifat, jumlah, bayar, mampu_bayar, penunjang, pajak, zakat) SELECT '".$field."', '".$val[input_id_kunjungan_kamar]."', '".$id_kki."', '".$val[input_icopim_detil][$parent]."', '".$val[input_icopim_detil_hak][$parent][$j]."', '".$val[input_icopim_detil_biaya][$parent][$j]."', '".$val[input_icopim_detil_sifat][$parent][$j]."', '".$val[input_icopim_detil_jml][$parent][$j]."', '".$val[input_icopim_detil_bayar][$parent][$j]."', '".($val[input_icopim_detil_bayar][$parent][$j]*$mampu_bayar)."', netto, pajak, zakat FROM icopim_detil WHERE id = '".$val[input_icopim_detil][$parent]."'";
					
					} else {
						//lain-lain
					}
					//$objResponse->addAppend("debug", "innerHTML", $sql . "<br /><br />");
					$kon->sql = $sql;
					$kon->execute();
				}

			} else {
				//UPDATE
/*diinsert satu satu*/
				for($j=0;$j<sizeof($val[input_icopim_detil_field][$parent]);$j++) {
					$field = "";
					$field = $val[input_icopim_detil_field][$parent][$j];
					/*
					$netto = $val[input_icopim_detil_bayar][$parent][$field] * $val[input_icopim_detil_netto][$parent];
					$zakat = $val[input_icopim_detil_bayar][$parent][$field] * $val[input_icopim_detil_netto][$parent] * $val[input_icopim_detil_zakat][$parent];
					$pajak = $val[input_icopim_detil_bayar][$parent][$field] * $val[input_icopim_detil_pajak][$parent];
					*/

					//$objResponse->addAppend("debug", "innerHTML", $field . " => " . $val[input_icopim_detil_bayar][$parent][$field] . "<br />");
					if($field == "jasa_rumah_sakit") {
						$sql = "UPDATE kunjungan_bayar SET hak_id = '".$val[input_icopim_detil_hak][$parent][$j]."', biaya = '".$val[input_icopim_detil_biaya][$parent][$j]."', sifat = '".$val[input_icopim_detil_sifat][$parent][$j]."', jumlah = '".$val[input_icopim_detil_jml][$parent][$j]."', bayar = '".$val[input_icopim_detil_bayar][$parent][$j]."', mampu_bayar = '".($val[input_icopim_detil_bayar][$parent][$j]*$mampu_bayar)."' WHERE id = '".$val[input_kunjungan_icopim_detil_id][$parent][$j]."'";

					} elseif($field == "spesialis") {
						$sql = "UPDATE kunjungan_bayar SET hak_id = '".$val[input_icopim_detil_hak][$parent][$j]."', biaya = '".$val[input_icopim_detil_biaya][$parent][$j]."', sifat = '".$val[input_icopim_detil_sifat][$parent][$j]."',jumlah = '".$val[input_icopim_detil_jml][$parent][$j]."', bayar = '".$val[input_icopim_detil_bayar][$parent][$j]."', mampu_bayar = '".($val[input_icopim_detil_bayar][$parent][$j]*$mampu_bayar)."' WHERE id = '".$val[input_kunjungan_icopim_detil_id][$parent][$j]."'";

					} elseif($field == "spesialis_pendamping") {
						$sql = "UPDATE kunjungan_bayar SET hak_id = '".$val[input_icopim_detil_hak][$parent][$j]."', biaya = '".$val[input_icopim_detil_biaya][$parent][$j]."', sifat = '".$val[input_icopim_detil_sifat][$parent][$j]."',jumlah = '".$val[input_icopim_detil_jml][$parent][$j]."', bayar = '".$val[input_icopim_detil_bayar][$parent][$j]."', mampu_bayar = '".($val[input_icopim_detil_bayar][$parent][$j]*$mampu_bayar)."' WHERE id = '".$val[input_kunjungan_icopim_detil_id][$parent][$j]."'";
					
					} elseif($field == "perawat_perinatologi") {
						$sql = "UPDATE kunjungan_bayar SET hak_id = '".$val[input_icopim_detil_hak][$parent][$j]."', biaya = '".$val[input_icopim_detil_biaya][$parent][$j]."', sifat = '".$val[input_icopim_detil_sifat][$parent][$j]."',jumlah = '".$val[input_icopim_detil_jml][$parent][$j]."', bayar = '".$val[input_icopim_detil_bayar][$parent][$j]."', mampu_bayar = '".($val[input_icopim_detil_bayar][$parent][$j]*$mampu_bayar)."' WHERE id = '".$val[input_kunjungan_icopim_detil_id][$parent][$j]."'";
					
					} elseif($field == "dr_umum") {
						$sql = "UPDATE kunjungan_bayar SET hak_id = '".$val[input_icopim_detil_hak][$parent][$j]."', biaya = '".$val[input_icopim_detil_biaya][$parent][$j]."', sifat = '".$val[input_icopim_detil_sifat][$parent][$j]."',jumlah = '".$val[input_icopim_detil_jml][$parent][$j]."', bayar = '".$val[input_icopim_detil_bayar][$parent][$j]."', mampu_bayar = '".($val[input_icopim_detil_bayar][$parent][$j]*$mampu_bayar)."' WHERE id = '".$val[input_kunjungan_icopim_detil_id][$parent][$j]."'";
					
					} elseif($field == "dr_gigi") {
						$sql = "UPDATE kunjungan_bayar SET hak_id = '".$val[input_icopim_detil_hak][$parent][$j]."', biaya = '".$val[input_icopim_detil_biaya][$parent][$j]."', sifat = '".$val[input_icopim_detil_sifat][$parent][$j]."',jumlah = '".$val[input_icopim_detil_jml][$parent][$j]."', bayar = '".$val[input_icopim_detil_bayar][$parent][$j]."', mampu_bayar = '".($val[input_icopim_detil_bayar][$parent][$j]*$mampu_bayar)."' WHERE id = '".$val[input_kunjungan_icopim_detil_id][$parent][$j]."'";
					
					} elseif($field == "assisten_non_dokter") {
						$sql = "UPDATE kunjungan_bayar SET hak_id = '".$val[input_icopim_detil_hak][$parent][$j]."', biaya = '".$val[input_icopim_detil_biaya][$parent][$j]."', sifat = '".$val[input_icopim_detil_sifat][$parent][$j]."',jumlah = '".$val[input_icopim_detil_jml][$parent][$j]."', bayar = '".$val[input_icopim_detil_bayar][$parent][$j]."', mampu_bayar = '".($val[input_icopim_detil_bayar][$parent][$j]*$mampu_bayar)."' WHERE id = '".$val[input_kunjungan_icopim_detil_id][$parent][$j]."'";
					
					} elseif($field == "spesialis_anestesi") {
						$sql = "UPDATE kunjungan_bayar SET hak_id = '".$val[input_icopim_detil_hak][$parent][$j]."', biaya = '".$val[input_icopim_detil_biaya][$parent][$j]."', sifat = '".$val[input_icopim_detil_sifat][$parent][$j]."',jumlah = '".$val[input_icopim_detil_jml][$parent][$j]."', bayar = '".$val[input_icopim_detil_bayar][$parent][$j]."', mampu_bayar = '".($val[input_icopim_detil_bayar][$parent][$j]*$mampu_bayar)."' WHERE id = '".$val[input_kunjungan_icopim_detil_id][$parent][$j]."'";
					
					} elseif($field == "aknest") {
						$sql = "UPDATE kunjungan_bayar SET hak_id = '".$val[input_icopim_detil_hak][$parent][$j]."', biaya = '".$val[input_icopim_detil_biaya][$parent][$j]."', sifat = '".$val[input_icopim_detil_sifat][$parent][$j]."',jumlah = '".$val[input_icopim_detil_jml][$parent][$j]."', bayar = '".$val[input_icopim_detil_bayar][$parent][$j]."', mampu_bayar = '".($val[input_icopim_detil_bayar][$parent][$j]*$mampu_bayar)."' WHERE id = '".$val[input_kunjungan_icopim_detil_id][$parent][$j]."'";
					
					} elseif($field == "gizi") {
						$sql = "UPDATE kunjungan_bayar SET hak_id = '".$val[input_icopim_detil_hak][$parent][$j]."', biaya = '".$val[input_icopim_detil_biaya][$parent][$j]."', sifat = '".$val[input_icopim_detil_sifat][$parent][$j]."',jumlah = '".$val[input_icopim_detil_jml][$parent][$j]."', bayar = '".$val[input_icopim_detil_bayar][$parent][$j]."', mampu_bayar = '".($val[input_icopim_detil_bayar][$parent][$j]*$mampu_bayar)."' WHERE id = '".$val[input_kunjungan_icopim_detil_id][$parent][$j]."'";
					
					} elseif($field == "fisioterapi") {
						$sql = "UPDATE kunjungan_bayar SET hak_id = '".$val[input_icopim_detil_hak][$parent][$j]."', biaya = '".$val[input_icopim_detil_biaya][$parent][$j]."', sifat = '".$val[input_icopim_detil_sifat][$parent][$j]."',jumlah = '".$val[input_icopim_detil_jml][$parent][$j]."', bayar = '".$val[input_icopim_detil_bayar][$parent][$j]."', mampu_bayar = '".($val[input_icopim_detil_bayar][$parent][$j]*$mampu_bayar)."' WHERE id = '".$val[input_kunjungan_icopim_detil_id][$parent][$j]."'";
					
					} elseif($field == "analis_pa") {
						$sql = "UPDATE kunjungan_bayar SET hak_id = '".$val[input_icopim_detil_hak][$parent][$j]."', biaya = '".$val[input_icopim_detil_biaya][$parent][$j]."', sifat = '".$val[input_icopim_detil_sifat][$parent][$j]."',jumlah = '".$val[input_icopim_detil_jml][$parent][$j]."', bayar = '".$val[input_icopim_detil_bayar][$parent][$j]."', mampu_bayar = '".($val[input_icopim_detil_bayar][$parent][$j]*$mampu_bayar)."' WHERE id = '".$val[input_kunjungan_icopim_detil_id][$parent][$j]."'";
					
					} elseif($field == "bidan") {
						$sql = "UPDATE kunjungan_bayar SET hak_id = '".$val[input_icopim_detil_hak][$parent][$j]."', biaya = '".$val[input_icopim_detil_biaya][$parent][$j]."', sifat = '".$val[input_icopim_detil_sifat][$parent][$j]."',jumlah = '".$val[input_icopim_detil_jml][$parent][$j]."', bayar = '".$val[input_icopim_detil_bayar][$parent][$j]."', mampu_bayar = '".($val[input_icopim_detil_bayar][$parent][$j]*$mampu_bayar)."' WHERE id = '".$val[input_kunjungan_icopim_detil_id][$parent][$j]."'";
					
					} elseif($field == "perawat") {
						$sql = "UPDATE kunjungan_bayar SET hak_id = '".$val[input_icopim_detil_hak][$parent][$j]."', biaya = '".$val[input_icopim_detil_biaya][$parent][$j]."', sifat = '".$val[input_icopim_detil_sifat][$parent][$j]."',jumlah = '".$val[input_icopim_detil_jml][$parent][$j]."', bayar = '".$val[input_icopim_detil_bayar][$parent][$j]."', mampu_bayar = '".($val[input_icopim_detil_bayar][$parent][$j]*$mampu_bayar)."' WHERE id = '".$val[input_kunjungan_icopim_detil_id][$parent][$j]."'";
					
					} elseif($field == "penunjang") {
						//penunjang
						$sql = "UPDATE kunjungan_bayar SET hak_id = '".$val[input_icopim_detil_hak][$parent][$j]."', biaya = '".$val[input_icopim_detil_biaya][$parent][$j]."', sifat = '".$val[input_icopim_detil_sifat][$parent][$j]."',jumlah = '".$val[input_icopim_detil_jml][$parent][$j]."', bayar = '".$val[input_icopim_detil_bayar][$parent][$j]."', mampu_bayar = '".($val[input_icopim_detil_bayar][$parent][$j]*$mampu_bayar)."' WHERE id = '".$val[input_kunjungan_icopim_detil_id][$parent][$j]."'";
					
					} else {
						//lain-lain
					}
					//$objResponse->addAppend("debug", "innerHTML", $field . " => " . $sql . "<br /><br />");
					$kon->sql = $sql;
					$kon->execute();
				} //endfor

			}
			next($val[input_icopim]);
		}

//BHP
		for($i=0;$i<sizeof($val[input_bhp]);$i++) {
			$kunci = key($val[input_bhp]);
/*
			//get
			$sql = "SELECT * FROM bhp WHERE id = '".$val[input_bhp][$kunci]."'";
			$kon->sql = $sql;
			$kon->execute();
			$data_bhp[$i] = $kon->getOne();
			
			//$objResponse->addAssign("debug", "innerHTML", $sql);
			
			$bhp_p[$i] = $data_bhp[$i][bhp_p] * $val[input_bhp_bayar][$kunci];
			$bhp_rs[$i] = $data_bhp[$i][bhp_rs] * $val[input_bhp_bayar][$kunci];
			$bhp_rs_adm[$i] = $data_bhp[$i][bhp_rs_adm] * $val[input_bhp_bayar][$kunci];
			$bhp_rs_op[$i] = $data_bhp[$i][bhp_rs_op] * $val[input_bhp_bayar][$kunci];
*/			
			if(!$val[input_kunjungan_bhp_id][$kunci]) {
				//insert
				$sql = "
				INSERT INTO 
					kunjungan_bayar (
						nama,
						kunjungan_kamar_id, 
						bhp_id, 
						hak_id, 
						biaya,
						sifat,
						jumlah, 
						bayar,
						mampu_bayar,
						bhp_p,
						bhp_rs,
						bhp_rs_adm,
						bhp_rs_op
					)	SELECT 
							'".$val[input_bhp_nama][$i]."', 
							'".$val[input_id_kunjungan_kamar]."', 
							'".$val[input_bhp][$kunci]."', 
							'".$val[input_bhp_hak][$kunci]."', 
							'".$val[input_bhp_biaya][$kunci]."',
							'".$val[input_bhp_sifat][$kunci]."', 
							'".$val[input_bhp_jml][$kunci]."', 
							'".$val[input_bhp_bayar][$kunci]."',
							'".($val[input_bhp_bayar][$kunci]*$mampu_bayar)."',
							bhp_p,
							bhp_rs,
							bhp_rs_adm,
							bhp_rs_op
						FROM 
							bhp
						WHERE
							id = '".$val[input_bhp][$kunci]."'
					";
				$kon->sql = $sql;
				$kon->execute();
			} else {
				//update
				$sql = "
				UPDATE 
					kunjungan_bayar 
				SET 
					hak_id = '".$val[input_bhp_hak][$kunci]."', 
					biaya = '".$val[input_bhp_biaya][$kunci]."', 
					sifat = '".$val[input_bhp_sifat][$kunci]."', 
					jumlah = '".$val[input_bhp_jml][$kunci]."', 
					bayar = '".$val[input_bhp_bayar][$kunci]."',
					mampu_bayar = '".($val[input_bhp_bayar][$kunci]*$mampu_bayar)."'
				WHERE 
					id = '".$val[input_kunjungan_bhp_id][$kunci]."'";
				$kon->sql = $sql;
				//$objResponse->addAssign("debug", "innerHTML", $sql);
				$kon->execute();
			}
			next($val[input_bhp]);
		}
		
		if($tutup_modal == true) {
			if($afek < 0) {
				$objResponse->addAlert("Data Kunjungan Tidak Dapat Disimpan\nHubungi Bagian SIM.");
			} else {
				$objResponse->addScriptCall("list_data", "0");
				$objResponse->addScriptCall("tutup_kunjungan");
				$objResponse->addScriptCall("show_status_simpan");
			}
		} else {
			$objResponse->addScriptCall("xajax_buka_kunjungan", $val[input_id_kunjungan_kamar]);
			//$objResponse->addScriptCall("get_total", false);
		}
		return $objResponse;
	}