<?php include 'header1f.php';?>
<?php
	require_once("perpage.php");	
	require_once("dbcontroller.php");
	$db_handle = new DBController();
	
	$our_company_name = "";
	$datepicker = "";
	$datepicker1 = "";
	$customer_name = "";
	$trans_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","trans_inv_no","inv_type");
				if(in_array($k,$queryCases)) {
					if(!empty($queryCondition)) {
						$queryCondition .= " AND ";
						
					} else {
						$queryCondition .= " WHERE ";
					}
				}
				switch($k) {
						
						
						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 "trans_inv_no":
						$trans_inv_no = $v;
						$queryCondition .= "trans_inv_no LIKE '%" . $v . "%'";
						break;
						
						
						
				}
			}
		}
	}	
	?>
	<? 
if(!empty($queryCondition)) {
//$orderby = "ORDER BY convert(`auto_trans_inv_no`, decimal) DESC"; 
$sql = "SELECT * FROM  transporter_details_expenses" . $queryCondition ." AND trans_inv_no != '' group by trans_inv_no  order by detail_id desc" ;
} else { 
$sql= "SELECT * FROM transporter_details_expenses where trans_inv_no != '' group by trans_inv_no order by detail_id desc";	
//echo $sql;
}



$result2 = mysql_query($sql,$conn);

	$num_rows2 = mysql_num_rows($result2);
	
	
	//echo $sql ;
	$href = 'view_all_dircttransinv.php';					
if(!empty($queryCondition)) {
$perPage = $num_rows2;

	}else {				
$perPage = 200;
}  
	$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='qtn_status.php'">BACK </button>
              <div class="clearfix"></div>
            </div>
          </div>
        </div>
	  
	  <form name="chkForm" id="chkForm" action="view_all_dircttransinv.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  Invoice</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>B/E No.</label>
                                                         <input type="text" placeholder="B/E No." name="search[b_e_no]" class="form-control" value="<?php echo $b_e_no; ?>"	/>
                                                    </div>
													</div>
													
													 <div class="col-sm-3 col-xs-12"><div class="form-group">
                                                        <label>S/B No. </label>
                                                          <input type="text" placeholder="S/B No." name="search[s_b_no]" class="form-control" value="<?php echo $s_b_no; ?>"	/>                                                    </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_dircttransinv.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  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>&nbsp;</th>
					  <th>&nbsp;</th>
					  <th>Invoice No.</th>
									<th>Date</th>
									<th>Customer</th>
									<th>Total Amount</th>
									
									<th>Transport INV NO</th>
									<th>Date</th>
									<th>Transport Amount</th>
									<th>LR No</th>
								  </tr>    
                  </thead>
                  <tbody>
                    <?php
					$i=1;
					
						
foreach($result as $k=>$v) {
						if(is_numeric($k)) {
							?>
<?php
$querycust = "select * from  customer_master where customer_id = '".$result[$k]["customer_id"]."'";
echo $queryopp;
$resultcust = mysql_query($querycust);
while($row=mysql_fetch_array($resultcust))
{
$credittime = $row['credittime'];
$customer_name = $row['customer_name'];
}



 
$querycust = "select * from  tax_transtax where customer_id = '".$result[$k]["customer_id"]."' and trans_inv_no='".$result[$k]["trans_inv_no"]."'";
//echo $queryopp;
$resultcust = mysql_query($querycust);
while($row=mysql_fetch_array($resultcust))
{
$transport_name = $row['transport_name'];
$transport_inv_no = $row['trans_inv_no'];
$transport_date = $row['transport_date'];

$transport_amount = $row['transport_amount'];

$lr_no=$row['lr_no'];
$trans_no=$row['trans_no'];
}

 
?>

	<?php

$interval = 0;
$trans_inv_date01 = $result[$k]["trans_inv_date"];
$return_filled_date1=date('Y-m-d', strtotime($result[$k]["trans_inv_date"]));
//$return_due_date1=date('Y-m-d', strtotime($today)); 
//echo $return_filled_date1;
//echo $today2;

$date1=date_create("$return_filled_date1");
$date2=date_create("$today2");
$diff=date_diff($date1,$date2);
$diff->format('%R%a');


?>	

	
		 <tr>
    <td>&nbsp;		<?php if($department_name=='Admin'){?>
<a href="dtransport_edit_details.php?trans_inv_no=<?php echo $result[$k]["trans_inv_no"]?>&&customer_id=<?php echo $result[$k]["customer_id"]?>&&Job_No=<?php echo $result[$k]["job_no"]?>&&trans_no=<?php echo $result[$k]["trans_no"]?>&&trans_inv_date=<?php echo $result[$k]["trans_inv_date"]?>&&inv_type=<? echo $result[$k]["inv_type"]?>&&inv_no=<? echo $result[$k]["inv_no"]?>" class="btn">Edit</a>

<? } ?></td><td><?php if($transport_name==''){?>
	 <form action="add_trans_name.php" method="post">
        <input type="hidden" value="<?php echo $trans_no?>" name="trans_no" />
		<input type="hidden" value="<?php echo $trans_inv_no; ?>" name="trans_inv_no" />
        <div class="login-fields">
          <div class="field">
           <?php 
		   $query2tv = "select * from transport_vendor ";
		   $result2tv = mysql_query($query2tv,$conn);		
		   ?>
   <select name="transport_name" class="form-control" style="margin-top:5px;">
    <option value="" selected="selected">Select</option>                       
                        <?php
													  while($row=mysql_fetch_array($result2tv))
	                                              	{
													$transport_name = $row['transport_name'];
													
													  ?>
                        <option value="<?php echo $transport_name ?>"><?php echo $transport_name ?></option>
                        <?php
														
														 } ?>
                      </select>
					  
          </div>
		  
		  <div class="field">
          <input type="text" name="trans_inv_no" class="form-control" placeholder="Transport Invoice No" style="margin-top:5px;" >
		  
					  
          </div>
		   <div class="field">
          <input type="text" name="trans_date" class="form-control datepicker_y4"  placeholder="Date" style="margin-top:5px;">
		  <script>$(".datepicker_y4").datepicker({
  inline: true,
  
  nextText: '&rarr;',
  prevText: '&larr;',
  showOtherMonths: true,
  changeMonth: true,
        changeYear: true,
  dateFormat: 'dd-mm-yy',
  dayNamesMin: ['Sun', 'Mon', 'Tue', 'Wed', 'Thu', 'Fri', 'Sat'],
      showAnim: "slide"
 });</script> 
					  
          </div>
		   <div class="field">
          <input type="text" name="trans_amount" class="form-control" placeholder="Transport Amount" style="margin-top:5px;" >
		            <input type="text" name="lr_no" class="form-control" placeholder=" LR No " style="margin-top:5px;">

					  
          </div>
        </div>
        <!-- /.field -->
        <button class="button btn btn-large btn-primary btn-madmin" type="submit" style="margin-top:5px;">ADD</button>
        <!-- /.login-actions -->
      </form>
	
<?php } else { echo $transport_name; } ?>	
	
	
</td>
    <td><a href="print_transinv.php?trans_inv_no=<?php echo $result[$k]["trans_inv_no"]?>&&customer_id=<?php echo $result[$k]["customer_id"]?>&&main_id=<?php echo $result[$k]["main_id"]?>&&trans_inv_date=<?php echo $result[$k]["trans_inv_date"]?>&&our_company_name=<?php echo $result[$k]["account_of"]?>" target="_blank"><?php echo $result[$k]["trans_inv_no"]?></a></td>
    <td><?php echo $result[$k]["trans_inv_date"]?></td>
    <td><?php echo $customer_name?></td>
    <td><?php 
	$sumamt+=$result[$k]["chargable_amount"];
	
	 echo $result[$k]["chargable_amount"]?></td>
     <td><? echo $transport_inv_no;?> </td>
    <td><? echo $transport_date;?></td>
	    <td><? echo $transport_amount;?></td>
		  <td><? echo $lr_no;?></td>
  </tr>		
					<?php } }?>
                  </tbody>
                </table>
              </div>
            </div>
          </div>
        </div>
      </div>
    </div>
   	<?php include 'footer1a.php';?>
