<?php
// Manage Data Rekap Dokter dan Instansi ---------------------------------------------------------------------------------------------------------------------------------------------------------------------------------
if ($_GET[module]=='rekapdokter'){
	echo "<div class='post_title' style='margin-bottom:10px; position:relative;'><b>List atau Daftar Rekap Dokter<hr></b></div>";
				
	echo " <div style='float:right;'>
					<form style='margin-right:10px' method=POST action=''>
							Periode : <select name='bulan'>
									<option value=0 selected>- Pilih Bulan -</option>";
									$tampil=mysql_query("SELECT substring(tanggal_pesan,6,2) as bulan FROM rb_orders GROUP BY substring(tanggal_pesan,6,2)");
									while($r=mysql_fetch_array($tampil)){
									$bulan = Bulan($r[bulan]);
										if ($_POST[bulan]==$r[bulan]){
										  	echo "<option value=$r[bulan] selected>$bulan</option>";
										}else{
											echo "<option value=$r[bulan]>$bulan</option>";
										}
									}	
							echo "</select>
							<select name='tahun'>
									<option value=0 selected>- Pilih Tahun -</option>";
									$tampil=mysql_query("SELECT substring(tanggal_pesan,1,4) as tahun FROM rb_orders GROUP BY substring(tanggal_pesan,1,4)");
									while($r=mysql_fetch_array($tampil)){
										if ($_POST[tahun]==$r[tahun]){
									  		echo "<option value=$r[tahun] selected>$r[tahun]</option>";
										}else{
											echo "<option value=$r[tahun]>$r[tahun]</option>";
										}
									}
							echo "</select>
						<input type='submit' name='submit2' class='submitt' value='Lihat'>
					</form>
					</div><br><br>

					<div style='float:right;'>
					<form style='margin-top:-5px; margin-right:10px' method=POST action=''>
					Nama Dokter : <input type='text' name='a'>
						<input type='submit' name='submit3' class='submitt' value='Lihat'>
					</form>
				</div>	

			<div id='container'>
			<div id='demo'>
<table class='display' id='example'>
	<thead>
          <tr bgcolor='#2e2e2e'>
			<th width=40px>No</th>
			<th>Nama Dokter</th>
			<th>Jumlah Resep</th>
			<th>Total</th>
		</tr>
	</thead>
	<tfoot>
		<tr style='border: 2px solid #e3e3e3;'>
			<th style='border: none;'>No</th>
			<th style='border: none;'>Nama Dokter</th>
			<th style='border: none;'>Jumlah Resep</th>
			<th style='border: none;'>Total</th>
		</tr>
	</tfoot>";
	echo "<tbody>";
	$no=1;
	if (isset($_POST[submit3])){
		$tampil = mysql_query("SELECT * FROM rb_dokter where nama_dokter LIKE '%$_POST[a]%' ORDER BY id_dokter ASC");
	}else{
		$tampil = mysql_query("SELECT * FROM rb_dokter ORDER BY id_dokter ASC");
	}
    while($r=mysql_fetch_array($tampil)){
	  if(($no % 2)==0){ $warna="#ffffff"; }else{ $warna="#E1E1E1"; }
	  	if (isset($_POST[submit2])){
	  	$periode = $_POST[tahun].'-'.$_POST[bulan];
		 	$total = mysql_num_rows(mysql_query("SELECT a.id_dokter, a.tanggal_selesai,  b.* FROM `rb_orders` a JOIN rb_resep b ON a.id_orders=b.id_orders where (R_SPH!='SPH' OR L_SPH!='SPH' OR R_CYL!='CYL' OR L_CYL!='CYL' OR R_AXS!='AXS' OR L_AXS!='AXS' OR R_ADD!='ADD' OR L_ADD!='ADD') AND a.id_dokter='$r[id_dokter]' AND tanggal_pesan LIKE '$periode%'"));
       	}else{
       		$total = mysql_num_rows(mysql_query("SELECT a.id_dokter, b.* FROM `rb_orders` a JOIN rb_resep b ON a.id_orders=b.id_orders where (R_SPH!='SPH' OR L_SPH!='SPH' OR R_CYL!='CYL' OR L_CYL!='CYL' OR R_AXS!='AXS' OR L_AXS!='AXS' OR R_ADD!='ADD' OR L_ADD!='ADD') AND a.id_dokter='$r[id_dokter]'"));
       	}
       echo "<tr bgcolor=$warna>
             <td class='read_only'>$no</td>
		     <td>$r[nama_dokter]</td>
		     <td>$total</td>
			 <td>Rp ".format_rupiah($total*$r[resep_rp])."</td>
			 </tr>";
			 $no++;
		}

	  if (isset($_POST[submit2])){
	  	$periode = $_POST[tahun].'-'.$_POST[bulan];
	  	$jr = mysql_num_rows(mysql_query("SELECT a.id_dokter, b.* FROM `rb_orders` a JOIN rb_resep b ON a.id_orders=b.id_orders where (R_SPH!='SPH' OR L_SPH!='SPH' OR R_CYL!='CYL' OR L_CYL!='CYL' OR R_AXS!='AXS' OR L_AXS!='AXS' OR R_ADD!='ADD' OR L_ADD!='ADD') AND tanggal_pesan LIKE '$periode%'"));
	  	$rp = mysql_fetch_array(mysql_query("SELECT sum(resep_rp) as totalresep FROM `rb_orders` a JOIN rb_dokter c ON a.id_dokter=c.id_dokter JOIN rb_resep b ON a.id_orders=b.id_orders where (R_SPH!='SPH' OR L_SPH!='SPH' OR R_CYL!='CYL' OR L_CYL!='CYL' OR R_AXS!='AXS' OR L_AXS!='AXS' OR R_ADD!='ADD' OR L_ADD!='ADD') AND tanggal_pesan LIKE '$periode%'"));
	  }else{
		$jr = mysql_num_rows(mysql_query("SELECT a.id_dokter, b.* FROM `rb_orders` a JOIN rb_resep b ON a.id_orders=b.id_orders where (R_SPH!='SPH' OR L_SPH!='SPH' OR R_CYL!='CYL' OR L_CYL!='CYL' OR R_AXS!='AXS' OR L_AXS!='AXS' OR R_ADD!='ADD' OR L_ADD!='ADD')"));
		$rp = mysql_fetch_array(mysql_query("SELECT sum(resep_rp) as totalresep FROM `rb_orders` a JOIN rb_dokter c ON a.id_dokter=c.id_dokter JOIN rb_resep b ON a.id_orders=b.id_orders where (R_SPH!='SPH' OR L_SPH!='SPH' OR R_CYL!='CYL' OR L_CYL!='CYL' OR R_AXS!='AXS' OR L_AXS!='AXS' OR R_ADD!='ADD' OR L_ADD!='ADD')"));
	  }

if (!isset($_POST[submit3])){
echo "	<tr style='border:1px solid $warna;'>
			<td style='background:$warna; color:$warna'>X</td>
			<td style='color:red; font-weight:bold;'>Total</td>
			<td style='color:red; font-weight:bold;'>$jr</td>
			<td style='color:red; font-weight:bold;'>Rp ".format_rupiah($rp[totalresep])."</td>
		</tr>";
}
	echo "</tbody>
 </table>
</div></div>";
}