<?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-bar-chart"></i> Report Sales</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="report_sales.php?act=1">
                        <div class="form-group">
                            <label>Inventory</label>
                               <select name="inventory" id="inventory" class="form-control">
                                <option value="inventory">Inventory</option>
                                 <option value="services">Services</option>
                     <!--          <option value="All Inventory" <?php if($inventory == "0") { ?> selected="selected" <?php } ?>>All Inventory</option>
                              <option value="Diamond" <?php if($inventory == "Diamond") { ?> selected="selected" <?php } ?>>Diamond</option>
                              <option value="Gold" <?php if($inventory == "Gold") { ?> selected="selected" <?php } ?>>Gold</option>
                              <option value="LogamMulia" <?php if($inventory == "LogamMulia") { ?> selected="selected" <?php } ?>>LogamMulia</option>
                               <option value="ReadyItem" <?php if($inventory == "ReadyItem") { ?> selected="selected" <?php } ?>>ReadyItem</option>
                              <option value="Services" <?php if($inventory == "Services") { ?> selected="selected" <?php } ?>>Services</option>
                                <option value="Cincin" <?php if($inventory == "Cincin") { ?> selected="selected" <?php } ?>>Cincin</option>
                           <option value="Mastura" <?php if($inventory == "Mastura") { ?> selected="selected" <?php } ?>>Mastura</option>
                           <option value="Liontin" <?php if($inventory == "Liontin") { ?> selected="selected" <?php } ?>>Liontin</option>
                            <option value="Kerabu" <?php if($inventory == "Kerabu") { ?> selected="selected" <?php } ?>>Kerabu</option>
                           <option value="GKGR" <?php if($inventory == "GKGR") { ?> selected="selected" <?php } ?>>Gelang Kaku Gelang Rantai</option>
                           <option value="Rangka" <?php if($inventory == "Rangka") { ?> selected="selected" <?php } ?>>Rangka</option>-->
                            </select>
                        </div>
                          <div class="form-group">
                         <div class="col-md-6"> 
                          <label class="control-label">Invoice Date</label>
                           <input type="text" class="inputDate" name="inputDate"  value="<?php echo date('d-m-Y'); ?>" id="inputDate" >
                           </label class="control-label">
                            until <input type="text" class="inputDate2" name="inputDate2"  value="<?php echo date('d-m-Y'); ?>" id="inputDate2" >
                            </div>
                        </div>
                         <div class="form-group">
                          <label>Branch</label>
                            <select class="form-control" name="branch" id="branch">
                              <?php
                                              $sql3 = "select * from tbl_branch where status_branch=1 order by nama_branch";
                                              $rs3 = mysql_query($sql3);
                                              while($fetch3 = mysql_fetch_array($rs3))
                                              {
                                               ?>
                                          <option  value="<?php echo $fetch3['kode_branch']; ?>"><?php echo $fetch3['nama_branch']; ?></option>
                                                      <?php
                                              }
                                             ?>
                            </select>
                        </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>Invoice No.</th>
                            <th>Invoice Date</th>
                            <th>Customer</th>
                            <th>Sales Name</th>
                        </tr>
                    </thead>
                    <tbody>
                    <?php
						$branch  = $_REQUEST['branch'];
						$inventory  = $_REQUEST['inventory'];
						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="report_sales.php";
										</script>
						<?php
						}
						else
						{
							
							$sql = mysql_query("select * from  sales a
							inner join tbl_customer b on a.id_customer  =b.id_customer
							where status_sales  <> 2 and inventory = '$inventory'
							and invoice_date between '$datepicker' and '$datepicker1'  and inventory='$inventory' and invoice like '%$branch%'
							order by id_sales "); //echo $sql; exit;
							
						while($fetch = mysql_fetch_array($sql))
						{
								$invoice = $fetch['invoice'];
								$kode_customer = $fetch['kode_customer'];
								$nama_customer = $fetch['nama_customer'];
								$term = $fetch['term'];
								$nominal = $fetch['nominal'];
								list($d, $e, $f)=split ("[-]", $fetch['payment_date']);
								$payment_date   =$f."-".$e."-".$d;
								list($d, $e, $f)=split ("[-]", $fetch['invoice_date']);
								$invoice_date   =$f."-".$e."-".$d;
								$inventory = $fetch['inventory'];
								$cicilan = $fetch['cicilan'];
								$nominalreturn = $fetch['nominalreturn'];
								$notes = $fetch['notes'];
								$id_sales = $fetch['id_sales'];
								$user_update = $fetch['user_update'];
								
						
								
					?>
                      <tr class="gradeX">
                        <td><a href="view_sales2.php?id_sales=<?php echo $id_sales; ?>"><?php echo $invoice; ?></a></td>
                          <td ><?php echo $invoice_date; ?></td>
                          <td align="center"><?php echo $kode_customer; ?> - <?php echo $nama_customer; ?></td>
                          <td align="center"><?php  echo $user_update; ?></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>