	<?php
	$sql3 = 
	"select * from kontak_dagang_header, 
	kontak_dagang_transaksi, form_element_value " . 
	"where valueID = to_negara and header_id = to_kontak_dagang_header  
	and tgl_transaksi >= '".$date_start."' and tgl_transaksi <= '".$date_end." ' 
	AND remark = '0' order by to_negara ";
	//echo $sql3;
	if ($hasil3 = mysql_query($sql3)) {
		$cek = 0;
		$total_negara = 0;
		$total_transaksi = 0;
		$negara = array();
		while ($data3 = mysql_fetch_array($hasil3)) {
			if ($cek != $data3["to_negara"]) {
				if ($cek != 0) {
					FindData($cek, "form_element_value", $dataTitle, $dataRecord);
					$negara [$dataRecord] = $total_negara;
					$total_negara = 0;	
				}
				$total_transaksi = $total_transaksi + $data3["estimasi_kontrak"];
				$total_negara = $total_negara + $data3["estimasi_kontrak"];
				$cek = $data3["to_negara"];
			} else {
				$total_transaksi = $total_transaksi + $data3["estimasi_kontrak"];
				$total_negara = $total_negara + $data3["estimasi_kontrak"];
			}
		}
		FindData($cek, "form_element_value", $dataTitle, $dataRecord);
		$negara [$dataRecord] = $total_negara;
		
		//
		//foreach ($negara as $key => $row) {
		//	$nmNegara  [$key] = $row[$key];
		//	$transaksi [$key] = $row['jmNegara'];
		//}
		//array_multisort($jmNegara, SORT_DESC, $nmNegara, SORT_ASC, $negara);
		arsort($negara);
		$total_persen = 100;
		$counter = 0;
		//var_dump ($negara);
	}
	echo '
	<p>
		<h3 style="margin-bottom:3px">
		TRANSAKSI TEI 2017 BERDASARKAN NEGARA DAN KELOMPOK PRODUK TERBESAR</h3>
		Periode: '.indonesian_date($date_start).' sampai dengan '.indonesian_date($date_end).'
	</p>	
	<div class="tabel font15">
		<div class="head-column border-both">
			<div class="tabel10 padding10 alignCenter">
				<strong>No</strong>
			</div>
			<div class="tabel45 border-left padding10">
				<strong>Negara / Produk</strong>
			</div>
			<div class="tabel25 border-left padding10" style="text-align:right">
				<strong>Nilai (US $)</strong>
			</div>
			<div class="tabel20 border-left padding10" style="text-align:right">
				<strong>Persentase (%)</strong>
			</div>
		</div>
		<div class="content-column border-bottom border-left">
			<div class="tabel55 padding10 alignRight">
				<strong>Total</strong>
			</div>
			<div class="tabel25 border-left padding10 alignRight">
				<strong>'.number_format($total_transaksi, 2).'</strong>
			</div>
			<div class="tabel20 border-left padding10 alignRight">
				<strong>'.number_format($total_persen, 2).'</strong>
			</div>
		</div>';
		foreach ($negara as $key => $value) {
			$counter++;
			echo '
			<div id="" style="background-color:'.$bgColor.'" class="content-column border-right border-bottom border-left">
				<div class="tabel10 padding10 alignCenter alignCenter">
					'.$counter.'
				</div>
				<div class="tabel45 border-left padding10 alignLeft">
					'.$key.'
				</div>
				<div class="tabel25 border-left padding10 alignRight">
					'.number_format($value, 2).'
				</div>
				<div class="tabel20 border-left padding10 alignRight">';
					$percenPernegara = round(($value/$total_transaksi)*100, 2);
					//echo floor((250 / 434) * 100);  //Round down
					echo $percenPernegara;
					echo '	
				</div>
			</div>';
			
		}
		echo '
	</div>
	';

	?>