<?php
set_time_limit(3600);
//includes "config/conn.php";
$query_pos=mysql_query("select * from m_lokasi WHERE id_bbws=17 AND id_tipe='PDA'");

$sql_debit="select `x`.`thn_value` AS `thn_value`,`x`.`tgl_value` AS `tgl_value`,`x`.`bln_value` AS `bln_value`,(select distinct format(((sum(`a`.`WLevel`) / 24) / 100),2) from (`".$_POST['namapos']."` `a` join `m_jam` `b` on((date_format(`a`.`ReceivedTime`,'%H:00') = date_format(`b`.`jam_value`,'%H:00')))) where (`a`.`ReceivedDate` = concat(`x`.`thn_value`,'-',`x`.`bln_value`,'-',`x`.`tgl_value`))) AS `Debit` from `m_tanggal_debit` `x` where (select distinct format(((sum(`a`.`WLevel`) / 24) / 100),2) from (`".$_POST['namapos']."` `a` join `m_jam` `b` on((date_format(`a`.`ReceivedTime`,'%H:00') = date_format(`b`.`jam_value`,'%H:00'))))) AND x.thn_value='".$_POST['tahun']."'";
echo $sql_debit;
$result = mysql_query($sql_debit);
$result_list = array();
while($row = mysql_fetch_array($result)) {
   $result_list[] = $row;
}

foreach($result_list as $row) {
			$productitems[] = array(
//			   $row['bln_value'],
//			   $row['thn_value'],
			   $row['Debit']
			);
}
//echo json_encode($productitems);
//$data=var_dump($productitems);
?>
<article class="module width_4_quarter">
<header>
<h3 class="tabs_involved" style="background-image:url(images/icons/datastore.gif); background-repeat:no-repeat; padding-left:30px; margin-left:5px;"> Data Debit <?php echo strtoupper($_POST['namapos']);?></h3>
		<form action="" method="post">
        <p style="right:auto">
        	&nbsp;Nama Pos : 
            <select id="namapos" name="namapos" onchange="">
                <option value="">-Pilih Pos-</option>
                <?php 
				while($rp=mysql_fetch_array($query_pos)){
                ?>
       	<option value="<?php echo $rp['nama_lokasi']; ?>" <?php if ($rp['nama_lokasi']==$_POST['namapos']) { echo 'selected="selected"';} ?>>
                <?php echo $rp['nama_lokasi']; ?>
                </option>
                <?php } ?>
             </select>
             &nbsp;Tahun : 
             &nbsp;&nbsp;Nama Pos : 
            <select id="tahun" name="tahun" onchange="">
                <option value="">-Pilih Tahun-</option>
                <?php for($i=2010; $i<=2020;$i++){?>
                <option value="<?php echo $i;?>" <?php if ($i==$_POST['tahun']) { echo 'selected="selected"';} ?>><?php echo $i;?></option>
				<?php }?>
             </select>
            	<input type="submit" id="btntambah" name="btntambah" value="Search" />	
        </p>
        </form>
		</header>
		<div class="tab_container">
<table class="tablesorter" cellspacing="0" border="1" width="100%">
                                   <thead>
                                        <tr>
                                            <th>Tanggal</th>
                                            <?php 
											if ($ibln=="") { $x=1;$jmlbln=12; } else { $x=$ibln; $jmlbln=$ibln;}
											for ($i=$x; $i<=$jmlbln; $i++) { 
												if ($i==1) { $bln="Jan"; } else
												if ($i==2) { $bln="Feb"; } else
												if ($i==3) { $bln="Mar"; } else
												if ($i==4) { $bln="Apr"; } else
												if ($i==5) { $bln="Mei"; } else
												if ($i==6) { $bln="Jun"; } else
												if ($i==7) { $bln="Jul"; } else
												if ($i==8) { $bln="Agst"; } else
												if ($i==9) { $bln="Sept"; } else
												if ($i==10) { $bln="Okt"; } else
												if ($i==11) { $bln="Nov"; } else
												if ($i==12) { $bln="Des"; }
											?>
                                            <th><!--i class="fa fa-plus-square-o"></i--> <?php echo strtoupper($bln);?></a></th>
                                            <?php } ?>
                                       </tr >
                                    </thead>
									<?php
                                    $brs=31;
                                    $col=12;
                                    for($i=1;$i<=$brs;$i++){
                                        echo "<tr>";
                                        echo "<td style='background-image:url(images/bgWarning.png); background-repeat:no-repeat; padding-left:17px;'>
										<strong>ke - ".$i."</strong></td>";
                                        for($j=0;$j<$col;$j++){
                                            $ii=($j*$brs)+$i;
											if($productitems[$ii][0]!='')
											{ $color="blue"; }
											else { $color="red"; }
											
                                            echo "<td align='center'><font color='".$color."'>".number_format($productitems[$ii][0],2)."</font></td>";
                                        }
                                        echo "</tr>";
                                    }
                                    ?>
									</table>
                        </div><!-- end of .tab_container -->
		</article><!-- end of content manager article -->        
        
