<?php include ("header1.php");
 $querylogin = "select * from  mst_users where user_name = '". $_SESSION["LOGIN_NAME"]."' AND password = '".$_SESSION["EMPLOYEE_PASSWORD"]."'";
$resultlogin = mysqli_query($conn,$querylogin);
while($row=mysqli_fetch_array($resultlogin))
{
$user_name = $row['user_name'];
$user_id = $row['user_id'];
$first_name = $row['first_name'];
 $login_type_admin=$row['login_type'];
}
 

?>
 <script src="//ajax.googleapis.com/ajax/libs/jquery/2.2.4/jquery.min.js"></script>
<script src="jquery.table2excel.min.js"></script>

<?php
	require_once("perpage.php");	
	require_once("dbcontroller.php");
	$db_handle = new DBController();
	
	
	$datepicker = "";
	$datepicker1 = "";
	$material_name="";
	
	$queryCondition = "";
	if(!empty($_POST["search"])) {
		foreach($_POST["search"] as $k=>$v){
			if(!empty($v)) {

$queryCases = array("datepicker","datepicker1","material_name");
				if(in_array($k,$queryCases)) {
					if(!empty($queryCondition)) {
						$queryCondition .= " AND ";
						
					} else {
						$queryCondition .= " WHERE ";
					}
				}
				switch($k) {
					
						case "material_name":
						$material_name = $v;
						$queryCondition .= "material_name LIKE '%" . $v . "%'";
						break;
						
						
						
						case "datepicker":
						$datepicker = $v;
						$queryCondition .= "entry_date BETWEEN";
						case "datepicker1":
						$datepicker1 = $v;
						$queryCondition .= "'" . $v . "'";
						break;
						
				}
			}
		}
	}
	if(!empty($queryCondition)) {
	
	$orderby = " ORDER BY cust_more_row_id   "; 
	$sql = "SELECT * FROM  delivery_challan_more_product_02   " . $queryCondition ." " ;
	}else{
	 $sql= "SELECT * FROM  delivery_challan_more_product_02";
	}
	 $sql ;
	$href = 'view_all_delivery_detalils.php';					
	
	$perPage = 5000; 
	$page = 1;
	if(isset($_POST['page'])){
		$page = $_POST['page'];
	}
	$start = ($page-1)*$perPage;
	if($start < 0) $start = 0;
		
	$query =  $sql . $orderby .  " limit " . $start . "," . $perPage; 
	$result = $db_handle->runQuery($query);
	
	if(empty($result)) {
		
	$result["perpage"] = showperpage($sql, $perPage, $href);
	}
	else{ 
	$result["perpage"] = showperpage($sql, $perPage, $href); }
	
?>

  <div class="content-page">
    <div class="content">
      <div class="container">
        <div class="row">
          <div class="col-sm-12">
            <div class="page-header-title">
			<button type="button" class="btn btn-dark  waves-effect waves-light" onclick="location.href='customer_po.php'">BACK</button>
			
              <div class="clearfix"></div>
            </div>
          </div>
        </div>
     <form name="chkForm" id="chkForm" action="view_all_delivery_detalils.php"  method="post" >
                    <div class="row">
                        <div class="col-sm-12">
                            <div class="panel panel-primary">
                                <div class="panel-heading">
                                    <h3 class="panel-title">Search Inward
									</h3></div>
									
									
									
									
                                <div class="panel-body">
                                    <div class="row">
                                      
													
													
                                                   
													
													
													<div class="col-sm-3 col-xs-12"><div class="form-group">
                                                        <label>Material Name</label>
                                                        <input type="text" class="form-control"  name="search[material_name]" value="<?php echo $material_name?>"/>
                                                    </div>
                                                    </div>
													
												
														<div class="col-sm-3 col-xs-12"><div class="form-group">
                                                        <label>From Date</label><div class="input-group">
                            <input type="text" class="form-control" placeholder="yyyy-mm-dd" id="datepicker" name="search[datepicker]" value="<?php echo $datepicker; ?>">
														<span class="input-group-addon bg-custom b-0"><i class="mdi mdi-calendar text-white"></i></span></div>
														
                                                    </div></div>
													<div class="col-sm-3 col-xs-12"><div class="form-group">
                                                        <label>To Date</label><div class="input-group">
                          <input type="text" class="form-control" placeholder="yyyy-mm-dd" id="datepicker-autoclose" name="search[datepicker1]"value="<?php echo $datepicker1; ?>" >
													   <span class="input-group-addon bg-custom b-0"><i class="mdi mdi-calendar text-white"></i></span></div>
														
                                                    </div>
                                                    </div>
													
													
													
													
													
													
													
												
                                                    <div class="col-sm-12 col-xs-12">
                                           
                                            <div class="m-t-20">
                                                    <div class="form-group">
                                                        <div>
                                                            <button type="submit" class="btn btn-primary waves-effect waves-light"> Submit </button>
							<input type="reset" class="btn btn-primary " value="Reset" onClick="window.location='view_all_delivery_detalils.php'">
															
                                                           
                                                        </div>
                                                    </div>
                                               
                                            </div>
                                        </div>
                                        
                                    </div>
                                </div>
                            </div>
                        </div>
                    </div>
					
					
					</form>
        
        <div class="row">
          <div class="col-md-12">
            <div class="panel panel-primary">
              <div class="panel-heading">
                <h3 class="panel-title"> VIEW ALL Inward </h3>
              </div>
              <div class="panel-body">
                <table border="1" class="table2excel table no-margin" style="font-size:16px; border-collapse:collapse;" data-tableName="Test Table 1">
                  <thead>

<?php /*?><tr>
<th colspan="8">
<div align="left" style="padding:3px; font-size:20px; font-weight:bold;">Bombay Metal &amp; Steel Traders</div></th>
</tr>
<?php */?><tr>
<th colspan="3"><div align="left" style="padding:3px; font-size:20px; font-weight:bold;">
Delivery Detail as Per Challan </div></th>
<th colspan="5"><div align="right"><span style="padding:3px; font-size:20px; font-weight:bold;">Date-<?php echo $datepicker; ?></span></div></th>
</tr>
<tr>
</tr>
<tr>
                    
			    <th>BMST Challan Date</th>
				<th>BMST Challan No.</th>
				<th>DINESH Challan No.</th>
				<th>COMPONANT</th>
				<th>P.O.No.</th>
				<th>QTY</th>
				<th>RATE OF P.O.</th>
				<th>TOTAL AMOUNT </th>
					</tr>
                  <tbody>
				  <? 
				 foreach($result as $k=>$v) {
						if(is_numeric($k)) {
									$totalqty += $result[$k]["qty"];
									$sumoftotal+=$result[$k]["total"];
									$cust_more_row_id = $result[$k]["cust_more_row_id"];
									$row_id = $result[$k]["row_id"];

$qry97 = "select * from cust_inward_more_row_02 where row_id='$row_id' and cust_more_row_id='$cust_more_row_id'";
$re97 = mysqli_query($conn,$qry97);
while($row=mysqli_fetch_array($re97))
{
$challan_no = $row['challan_no'];
$challan_date = $row['challan_date'];

}				
													?>  <tr>
                    	
                        <td><?php echo $challan_date?></td>
					    <td><?php echo $result[$k]["inward_challan_no"]?></td>
						<td><?php echo $result[$k]["delivery_challan_no"]?></td>
						<td><?php echo $result[$k]["componant"]?></td>
						<td><?php echo $result[$k]["cust_po"]?></td>
						<td><?php echo $result[$k]["qty"]?></td>
						<td><?php echo $result[$k]["rate_of_po"]?></td>
						<td><?php echo $result[$k]["total"]?></td>
						</tr>  <?php }}?>
<tr>
<td>&nbsp;</td>
<td>&nbsp;</td>
<td>&nbsp;</td>
<td>&nbsp;</td>
<td><div align="right">Total</div></td>
<td><?php echo $totalqty?></td>
<td>&nbsp;</td>
<td><?php echo $sumoftotal?></td>
</tr>
                  </tbody>
                </table> 
<?php if($datepicker!='' and $datepicker1!=''){?>
<script>
			$(function() {
				$(".table2excel").table2excel({
					exclude: ".noExl",
					name: "Excel Document Name",
					filename: "BMTS-<?php echo $datepicker?>",
					fileext: ".xlsx",
					exclude_img: false,
					exclude_links: true,
					exclude_inputs: true
				});
			});
		</script><?php } ?>
              </div>
            </div>
          </div>
        </div>
        
      </div>
    </div>
	<?php include 'footer1aa.php';?>