<h3 class="h3-teaser">
	Transaction History for Trade Expo Indonesia 
	<?php
	echo date("Y")
	?>
</h3>
<script>
jQuery(document).ready(function() {
	jQuery('#selectedField01').change(function() {
		var selectedID, keterangan = '';
		var selection = jQuery('#selectedField01').val(); 
		jQuery('#selectedField11').html('');   
		
		if (selection == "valueID") {
			selectedID = "1";
			keterangan = " Nama Negara ";
		} else if (selection == "exhibitorID") {
			selectedID = "2";
			keterangan = " Nama Perusahaan ";
		} else if (selection == "b.updated_by") {
			selectedID = "3";
			keterangan = " Nama User ";
		} else if (selection == "estimasi_kontrak") {
			selectedID = "4";
			keterangan = " Nama Produk ";
		} else if (selection == "elementSubDescription") {	
			selectedID = "5";
			keterangan = " Nilai Transaksi ";		
		}
		//alert (NMFile);
		jQuery('#selectedField11').append('<option value=""> - Pilih'+keterangan+'- </option>');
		jQuery.post(
			"listData.php", {'selectedID':selectedID}, 
			function(data, textStatus) {
			jQuery.each(data, function(index, value) {
				jQuery('#selectedField11').append('<option value="' + index + '">' + value + '</option>');
			});
		},'json');
	});
});
</script>

<style>
	.header td {
		color:#FFF;
		padding:6px;
	}
</style>
<form name="filterform" action="?" method="post">
    <h4 style="margin-bottom:3px">Filter Data by:</h4>
	<select name="selectedField01" id="selectedField01">
		<option value=""> - Pilih - </option>
        <?php
		$flr = array(
			"valueID" 				=> " Nama Negara ", 
			"exhibitorID" 			=> " Nama Perusahaan ",
			"b.updated_by" 			=> " Nama User ",
			"estimasi_kontrak" 		=> " Nama Produk ", 
			"elementSubDescription" => " Nilai Transaksi "
		);
		foreach ($flr as $key => $value) {
			echo '
			<option value="'.$key.'">'.$value.'</option>';
		}
		?>
    </select> &nbsp; with spesific &nbsp; 
	<select name="selectedField11" id="selectedField11">
		<option value=""> - Pilih - </option>
    </select>
    
    <h4 style="margin-bottom:3px">Sort Data by:</h4>
	<select name="filterby">
    	<option value=""> - Pilih - </option>
        <?php
		$flr = array(
			"Tanggal Transaksi" => "tgl_transaksi", 
			"Nama Negara" => "valueName",
			"Nama Perusahaan" => "companyName",
			"Tanggal Update" => "date_updated", 
			"Nama User" => "updated_by",
			"NIlai Transaksi" => "estimasi_kontrak", 
			"Product Category" => "elementSubDescription"			
		);
		foreach ($flr as $key => $value) {
			echo '
			<option value="'.$value.'">'.$key.'</option>';
		}
		?>
    </select>
    &nbsp; and &nbsp;
	<select name="filterby2">
    	<option value=""> - Pilih - </option>
        <?php
		$flr = array(
			"Tanggal Transaksi" => "tgl_transaksi", 
			"Nama Negara" => "valueName",
			"Nama Perusahaan" => "companyName",
			"Tanggal Update" => "date_updated", 
			"Nama User" => "updated_by",
			"NIlai Transaksi" => "estimasi_kontrak", 
			"Product Category" => "elementSubDescription"			
		);
		foreach ($flr as $key => $value) {
			echo '
			<option value="'.$value.'">'.$key.'</option>';
		}
		?>
    </select>
	<?php
	//echo "test".$month = date('m');
	?>
	<h4 style="margin-bottom:3px">From - To:</h4>
    <select name="fromMonth">
    	<option value=""> - Pilih - </option>
        <?php
		foreach ($bulan as $key => $value) {
			echo '
			<option value="'.$value.'">'.$key.'</option>';
		}
		?>
    </select> &nbsp; 
    <select name="fromDay">
    	<option value=""> - Pilih - </option>
        <?php
		for($i=1; $i<=31; $i++) {
			echo '
			<option value="'.$i.'">'.sprintf('%02d', $i).'</option>';
		}
		?>
    </select>
    &nbsp; - &nbsp;
    <select name="toDate">
    	<option value=""> - Pilih - </option>
        <?php
		$flr = array(
			"16 Oktober 2019" => "2019-10-16",
			"17 Oktober 2019" => "2019-10-17",
			"18 Oktober 2019" => "2019-10-18",
			"19 Oktober 2019" => "2019-10-19",
			"20 Oktober 2019" => "2019-10-20",
		);
		foreach ($flr as $key => $value) {
			echo '
			<option value="'.$value.'">'.$key.'</option>';
		}
		?>
    </select>
	<input type="submit" name="filterin" value="Submit" />
</form>
<div style="height:20px;"></div>
<?php
$total = $counter = 0; $list_data = "";
$sql4 = 
" SELECT tgl_transaksi, valueName, companyName, b.date_updated, ".
" b.updated_by, estimasi_kontrak, elementSubDescription ".
" FROM kontak_dagang_header as a, kontak_dagang_transaksi as b, ".
" exhibitor_list, form_element_sub, form_element_value ".
" WHERE to_exhibitor_id = exhibitorID and header_id = to_kontak_dagang_header ".
" AND valueID = to_negara AND product_category = elementSubID ";

//echo $sql4;
$selectedField01 = (isset($_POST["selectedField01"]) ? $_POST["selectedField01"] : null);
$selectedField11 = (isset($_POST["selectedField11"]) ? $_POST["selectedField11"] : null);
if ($selectedField01 && $selectedField11) {
	$sql4 .=
	" AND $selectedField01 = '$selectedField11' ";
}


$fromDate = (isset($_POST["fromDate"]) ? $_POST["fromDate"] : null);
if ($fromDate) {
	$sql4 .=
	" AND tgl_transaksi >= '$fromDate' ";
}

$toDate = (isset($_POST["fromDate"]) ? $_POST["fromDate"] : null);
if ($toDate) {
	$sql4 .=
	" AND tgl_transaksi <= '$toDate' ";
}

$filterby = (isset($_POST["filterby"]) ? $_POST["filterby"] : null);
if ($filterby) {
	$sql4 .=
	" ORDER BY $filterby ";
} else {
	$sql4 .=
	" ORDER BY tgl_transaksi, valueName, companyName, product_category ";
}

$filterby2 = (isset($_POST["filterby2"]) ? $_POST["filterby2"] : null);
if ($filterby2) {
	if ($filterby) $sql4 .= ", ";
	$sql4 .=
	" $filterby2 ";
}

//echo $sql4;


if ($hasil4 = mysqli_query($conn, $sql4)) {	
	while ($data4 = mysqli_fetch_array ($hasil4)) {
		$counter++;
		$list_data .= '
		<tr bgcolor="#FFFFFF">
			<td width="6%" align="center">'.$counter.'</td>
			<td width="12%" align="center">'.date("d M", strtotime($data4["tgl_transaksi"])).'</td>
			<td width="13%">'.$data4["valueName"].'</td>
			<td width="15%">'.$data4["companyName"].'</td>
			<td align="center" width="12%">'.date("d M", strtotime($data4["date_updated"])).'</td>
			<td align="center" width="9%">'.$data4["updated_by"].'</td>
			<td width="19%">'.$data4["elementSubDescription"].'</td>
			<td align="right" width="14%">'.number_format($data4["estimasi_kontrak"],2,".",",").'</td>
		</tr>';
	}
}
//echo $list_data;
echo '
<table width="100%" cellspacing="1" cellspacing="1" border="0" bgcolor="#CCCCCC">
	<tr class="header" bgcolor="#333333">
		<td align="center">NO</td>
		<td align="center">Trans</td>
		<td>Negara</td>
		<td>Perusahaan</td>
		<td align="center">Updated</td>
		<td align="center">User</td>
		<td>Product</td>
		<td align="right">Nilai</td>
	</tr>'.$list_data.'
</table>';?>