<?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'];
}
 

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

$queryCases = array("datepicker","datepicker1","material_name","challan_no");
				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 "challan_no":
						$challan_no = $v;
						$queryCondition .= "challan_no LIKE '%" . $v . "%'";
						break;
						
						
						case "datepicker":
						$datepicker = $v;
						$queryCondition .= "challan_date BETWEEN";
						case "datepicker1":
						$datepicker1 = $v;
						$queryCondition .= "'" . $v . "'";
						break;
						
						
						
						
				}
			}
		}
	}
	if(!empty($queryCondition)) {
	
	$orderby = " ORDER BY cust_more_row_id desc   "; 
	$sql = "SELECT * FROM  cust_inward_more_row_02   " . $queryCondition ." " ;
	}else{
	 $sql= "SELECT * FROM  cust_inward_more_row_02 ORDER BY cust_more_row_id desc ";
	}
	 $sql ;
	$href = 'view_all_inwards_customer.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_inwards_customer.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 Challan
									</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>Challan No</label>
                                                        <input type="text" class="form-control"  name="search[challan_no]" value="<?php echo $challan_no?>"/>
                                                    </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_inwards_customer.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  id="datatable-buttons" class="table table-striped table-bordered">
                  <thead>
                    <tr>
					<th>#</th>
                    
									 <th>Sr No</th>
									 <th>GRN No.</th>
									<th>Material  Name </th>
									<th>Bar Size</th>
									<th>Description</th>

									<th>Customer Name</th>
										<th>Qty</th
										><th>Weight</th>
									<th>Rate</th>
									
										<th>Challan No</th>
									
									<th>Challan Date</th>
										<th>Bal Weight</th>
										<th>Close</th>
										
									<th>#</th>
									
								
									
                    <th>Attachment</th>
</tr>
                  </thead>
                  <tbody>
				  <? 
				 foreach($result as $k=>$v) {
						if(is_numeric($k)) {
				$customer_inward_id  = 	$result[$k]["customer_inward_id"];
								$customer_id  = 	$result[$k]["customer_id"];
															$cust_more_row_id  = 	$result[$k]["cust_more_row_id"];
															$GRN_NO=$result[$k]["GRN_NO"];

$qry3z = "select * from cust_raw_inward where  customer_inward_id ='$customer_inward_id'";
$re3z= mysqli_query($conn,$qry3z);
while($row=mysqli_fetch_array($re3z))
{  
$cpo_attachment = $row['cpo_attachment'];
}							
											
													
													?>  <tr>
													<td>#</td>
                    	
                        <td><?php echo $k+1;?></td>
						<td><?php echo $GRN_NO;?></td>
						<td><?php echo $result[$k]["material_name"]?></td>
					  <td><?php echo $result[$k]["bar_size"]?></td>
					  					  <td><?php echo $result[$k]["description"]?></td>

						<td><?php echo $result[$k]["customer_name"]?></td><td>
						<?php echo $result[$k]["qty"]?></td>
						 <td><?php echo $result[$k]["weight"]?></td>
					
						<td><?php echo $result[$k]["rate"]?></td>
						<td><?php echo $result[$k]["challan_no"]?></td>
						<td><?php echo $result[$k]["challan_date"]?></td>
						<td><?php echo $bal_weight=$result[$k]["bal_weight"]?></td>
						
						  <td><?php if($bal_weight!='0') {?><a href="close_weight.php?cust_more_row_id=<?php echo $cust_more_row_id?>&&customer_inward_id=<?php echo $customer_inward_id;?>&&customer_id=<?php echo $customer_id;?>" class="btn-xs waves-light" style="float:right; background-color:#65bd77; color: #FFFFFF"> Close  </a> <?php } ?></td>

						
                      <td><?php if($bal_weight!='0') {?><a href="delete_inwards_material.php?cust_more_row_id=<?php echo $cust_more_row_id?>&&customer_inward_id=<?php echo $customer_inward_id;?>&&customer_id=<?php echo $customer_id;?>" class="btn-xs waves-light" style="float:right; background-color:#65bd77; color: #FFFFFF"> Delete</a> <?php } ?></td>


                       	 
                    <td><a href="rmpo_copy/<?php echo $cpo_attachment;?>" target="_blank"><? echo $cpo_attachment;?></a></td>
</tr>
                     <?php }}?>
                  </tbody>
                </table>
              </div>
            </div>
          </div>
        </div>
        
      </div>
    </div>
	<?php include 'footer1a.php';?>