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

$queryCases = array("our_company_name","datepicker","datepicker1","customer_name","inv_no","inv_type");
				if(in_array($k,$queryCases)) {
					if(!empty($queryCondition)) {
						$queryCondition .= " AND ";
						
					} else {
						$queryCondition .= " WHERE ";
					}
				}
				switch($k) {
						case "our_company_name":
						$our_company_name = $v;
						$queryCondition .= "our_company_name LIKE '" . $v . "%'";
						break;
						
						case "datepicker":
						$datepicker = $v;
						$queryCondition .= "STR_TO_DATE(trans_inv_date,'%d/%m/%Y') BETWEEN";
						case "datepicker1":
						$datepicker1 = $v;
						$queryCondition .= "'" . $v . "'";
						break;
						
												
												
						case "customer_name":
						$customer_name = $v;
						$queryCondition .= "customer_name LIKE '%" . $v . "%'";
						break;
						
						
						case "inv_type":
						$inv_type = $v;
						$queryCondition .= "inv_type LIKE '" . $v . "%'";
						break;
						
						case "inv_no":
						$inv_no = $v;
						$queryCondition .= "inv_no LIKE '%" . $v . "%'";
						break;
						
						
						
				}
			}
		}
	}
	
	?>
	<? 
if($queryCondition!='') { 
	$orderby = "  ORDER BY challan_id Desc  "; 
	$sql = "SELECT * FROM challan_master " . $queryCondition ."";
	} else {
		$sql = "SELECT * FROM challan_master ORDER BY challan_id Desc";
	}
	//echo $sql;
	$resultnote = mysql_query($sql);

	$num_rownote = mysql_num_rows($resultnote);

	//echo $sql ;
	$href = 'view_all_challan_master.php';					
		
	$perPage = 50; 
	$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);
	}
?>  <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='qtn_status.php'">BACK </button>
              <div class="clearfix"></div>
            </div>
          </div>
        </div>
	  
	  <form name="chkForm" id="chkForm" action="view_all_challan_master.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 Challan</h3></div>
                                <div class="panel-body">
                                    <div class="row">
                                                    <div class="col-sm-3 col-xs-12"><div class="form-group">
                                                        <label>Invoice No. </label>
                                                          <input type="text" placeholder="INV No." name="search[inv_no]" class="form-control" value="<?php echo $inv_no; ?>"	/>
                                                    </div>
													</div>
													
												 <div class="col-sm-3 col-xs-12"><div class="form-group">
                                                        <label>Account Name</label>
                                                          <input type="text" placeholder="Account Name" name="search[customer_name]" class="form-control" value="<?php echo $customer_name; ?>"	/>
                                                    </div>
													</div>
													
													 <div class="col-sm-3 col-xs-12"><div class="form-group">
                                                        <label>Invoice Type</label>
                                                       <select class="form-control" id="lsrc" name="search[inv_type]"> 
  <option value="">Select Invoice Type</option>
   <?php if($inv_type!=''){?><option value="<?php echo $inv_type?>" selected="selected"><?php echo $inv_type?></option><?php }?>

 <option value="EXP">EXPORT</option>
  <option value="IMP">IMPORT</option>

                        
                      </select>
                                                    </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-3 col-xs-12"><div class="form-group">
                                                        <label>Invoice type</label>
                                                          <select class="form-control" id="lsrc" name="search[inv_type]"> 
  <option value="">Select Invoice Type</option>
   <?php if($inv_type!=''){?><option value="<?php echo $inv_type?>" selected="selected"><?php echo $inv_type?></option><?php }?>

 <option value="EXP">EXPORT</option>
  <option value="IMP">IMPORT</option>

                        
                      </select>

                                                    </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_challan_master.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 Challan</h3>
              </div>
              <div class="panel-body">
                <table id="datatable-responsive" class="table table-striped table-bordered dt-responsive nowrap" cellspacing="0" width="100%">
                  <thead>
                    <tr>
					  <th>Challan No</th>
	 <th>Job No</th>
			          <th>Consignor Name</th>
							        <th>Consignee</th>
								    <th>Consignee GST No</th>
							            
								       
								    <th>Transportations Service </th>
								    <th>View Print Details </th>
								 
								  </tr>    
                  </thead>
                  <tbody>
                    <?php
					$i=1;
					
						
foreach($result as $k=>$v) {
						if(is_numeric($k)) {
						$dir_inv_id=$result[$k]["dir_inv_id"];
												$type_note=$result[$k]["type_note"];

?>	

	
		 <tr>
    <td><?php echo $result[$k]["challan_no"]; ?></td>
	<td><?php echo $result[$k]["main_job_no"]; ?></td>
    <td><?php echo wordwrap($result[$k]["consignor"],15,"<br>\n");?></td>
    <td><?php echo wordwrap($result[$k]["consignee"],15,"<br>\n");?></td>
    <td><?php echo $result[$k]["consignee_gst_no"]; ?></td>
     <td><?php echo $result[$k]["transportations_service"]; ?></td>
    <td>  <a href="print_challan.php?challan_id=<?php echo $result[$k]["challan_id"]?>" target="_blank">View print Details</a> <br>
	<?php $trans_inv_no= $result[$k]["trans_inv_no"]; if($trans_inv_no=='') { ?>  <? } else {?>
	<? echo $trans_inv_no;?>
	<? } ?>
	</td>
  </tr>		
					<?php } }?>
                  </tbody>
                </table>
              </div>
            </div>
          </div>
        </div>
      </div>
    </div>
   	<?php include 'footer1a.php';?>
