<?php
session_name("AUTHENUSER");
session_start();
$USERNAME = $_SESSION['SES_USERNAME'];
if(!session_name("AUTHENUSER"))
	{
?>
						<script language="javascript">
						 alert("Waktu Login telah habis.Silahkan Login Kembali");
						document.location="index.php";
						</script>
<?php
	}
if(!$USERNAME)
	{
?>
						<script language="javascript">
						 alert("Harap Login Dahulu.");
						document.location="index.php";
						</script>
<?php
	}
	?>
	<?php include "common/config.php";
	include "include/head.php"; ?>
    <?php
	$act  = $_REQUEST['act'];
	?>

<body>
<?php include "include/head2.php"; ?>
<?php include "include/leftmenu.php"; ?>
<?php include "include/top.php"; ?>
   
  <h1><i class="icon-list-alt"></i> History Consignment</h1>
</div>


   <div class="main-content">
   
            <div class="widget">
            <div class="widget-content-white glossed">
                    <div class="padded">
                      <form role="form" class="form-horizontal" method="post" action="history_consigment.php?act=1">
                         <div class="form-group">
                         <div class="col-md-6"> 
                          <label class="control-label">Tanggal Consignment</label>
                           <input type="text" class="inputDate" name="inputDate"  value="<?php echo date('d-m-Y'); ?>" id="inputDate" >
                           </label class="control-label">
                            - <input type="text" class="inputDate2" name="inputDate2"  value="<?php echo date('d-m-Y'); ?>" id="inputDate2" >
                            </div>
                        </div>
                        <button class="btn btn-primary" type="submit">Submit</button>
                        <button class="btn btn-default" type="reset">Reset</button>
                      </form>
                    </div>
             </div>
              <?php if($act == 1) { ?>
              <div class="widget-content-white glossed">
                <div class="padded">
                <table class="table table-striped table-bordered table-hover">
                   <thead>
                        <tr>
                       		<th>Tanggal Consignment</th>
                            <th>Kode Consignment</th>
                            <th>From Branch</th>
                            <th>To Branch</th>
                            <th>User Receive</th>
                            <th>Date Receive</th>
                        </tr>
                    </thead>
                    <tbody>
                   <?php
					list($d, $e, $f)=split ("[-]", $_REQUEST['inputDate']);
						$datepicker=$f."-".$e."-".$d;
						list($d, $e, $f)=split ("[-]", $_REQUEST['inputDate2']);
						$datepicker1=$f."-".$e."-".$d;
						if(strtotime($datepicker1) < strtotime($datepicker))
						{
						?>
						<script language="javascript">
										 alert("Date From < Date To");
										document.location="history_consigment.php";
										</script>
						<?php
						}
						else
						{
							//echo $datepicker; exit;
						$sql = mysql_query("select * from  inventory_consigment 
						where status_consigment  = 1  
						and tgl_consigment between '$datepicker' and '$datepicker1' 
						and user_receive <> ''
						order by tgl_consigment ");
						while($fetch = mysql_fetch_array($sql))
						{
								$id_consigment = $fetch['id_consigment'];
								$kode_consigment = $fetch['kode_consigment'];
								list($d, $e, $f)=split ("[-]", $fetch['tgl_consigment']);
								$tgl_consigment   =$f."-".$e."-".$d;
								list($d, $e, $f)=split ("[-]", $fetch['receive_date']);
								$receive_date   =$f."-".$e."-".$d;$id_branchto = $fetch['id_branchto'];
								$id_branchfrom = $fetch['id_branchfrom'];
								if($id_branchto == 0)
								{
									$branchto = 'Head Office';
								}
								else
								{
									$id_branchto = $fetch['id_branchto'];
									$fetch3 = mysql_fetch_array(mysql_query("select * from tbl_branch where id_branch = '$id_branchto'"));
									$branchto = $fetch3['nama_branch'];
								}
								if($id_branchfrom == 0)
								{
									$branchfrom = 'Head Office';
								}
								else
								{
									$id_branchfrom = $fetch['id_branchfrom'];
									$fetch3 = mysql_fetch_array(mysql_query("select * from tbl_branch where id_branch = '$id_branchfrom'"));
									$branchfrom = $fetch3['nama_branch'];
								}
								
					?>
                      <tr class="gradeX">
                        <td><?php echo $tgl_consigment; ?></td>
                          <td ><a href="view_consigment.php?id_consigment=<?php echo $id_consigment; ?>"><?php echo $fetch['kode_consigment']; ?></a></td>
                          <td align="center"><?php echo $branchfrom; ?></td>
                          <td align="center"><?php  echo $branchto; ?></td>
                             <td align="center"><?php echo $fetch['user_receive']; ?></td>
                              <td ><?php echo $receive_date; ?></td>
                       </tr>
                       <?php
						}
						}
						?>
                  </tbody>
                </table>
                </div>
              </div>
              <?php
			  }
			  ?>
            </div>
          </div>
        </div>
      </div>

    </div>
  </div>
</div>       

<?php include "include/foot.php"; ?>
<script src='assets/js/for_pages/dashboard.js'></script>
</body>

</html>