<?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 .= "inv_date 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 main_id Desc  "; 
	$sql = "SELECT * FROM main_job_details " . $queryCondition ."";
	} else {
		$sql = "SELECT * FROM main_job_details ORDER BY main_id Desc";
	}
	
	$resultnote = mysql_query($sql);

	$num_rownote = mysql_num_rows($resultnote);

	//echo $sql ;
	$href = 'view_all_jobs.php';					
		
	$perPage = 500; 
	$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>
	  
	  
        
        <div class="row">
          <div class="col-md-12">
            <div class="panel panel-primary">
              <div class="panel-heading">
                <h3 class="panel-title">View all  Invoice</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>Customer Name</th>
	 <th>Main Job No</th>
	 <th>Job Date</th>
	 <th>Ref No.</th>
	 <th>Account Of</th>
	  <th>Inv Type</th>
	  <th>#</th><th>#</th>
								  </tr>    
                  </thead>
                  <tbody>
                    <?php
					$i=1;
					
						
foreach($result as $k=>$v) {
						if(is_numeric($k)) {
							$customer_id =$result[$k]['customer_id'];
$main_job_no=$result[$k]['main_job_no'];
$ref_no =$result[$k]['ref_no'];
$account_of =$result[$k]['account_of'];
$inv_type =$result[$k]['inv_type'];
$job_date =$result[$k]['job_date'];


?>	

	
		 <tr>
    <td><?php echo wordwrap($result[$k]["customer_name"],15,"<br>\n");?></td>
    <td><?php echo $result[$k]["main_job_no"]; ?></td>
	  <td><?php echo $result[$k]["job_date"]; ?></td>
	
    <td><?php echo $result[$k]["ref_no"]; ?></td>
      
  <td><?php echo $result[$k]["account_of"]; ?></td>

   
     <td><?php echo $result[$k]["inv_type"]; ?></td>
    <td>  <a href="make_challan_master.php?main_id=<?php echo $result[$k]["main_id"]?>" target="_blank" class="btn btn-primary waves-effect waves-light"> Make Challan </a>   </td>
    <td> <a href="make_direct_trans_step1.php?main_id=<?php echo $result[$k]["main_id"]?>" target="_blank" class="btn btn-danger waves-effect waves-light">Make Transport Invoice</a> </td>
  </tr>		
					<?php } }?>
                  </tbody>
                </table>
              </div>
            </div>
          </div>
        </div>
      </div>
    </div>
   	<?php include 'footer1a.php';?>
