<?php include 'connection.php';
session_start();
if (!isset($_SESSION['is_logged_in'])) {
    header("Location:login.php");
    die();
    }
	$query2job = "select * from check_month";
$resultjob = mysql_query($query2job,$conn);
while($rowmonth=mysql_fetch_array($resultjob))
{
$check_month = $rowmonth['check_month'];
}

date_default_timezone_set('Asia/Calcutta');
$today = date("d/m/Y");
$today2 = date("Y-m-d");
$today1 = date("d/m");
$currentmonth = date(m);
date_default_timezone_set('Asia/Calcutta');
$today = date("Y-m-d");
 
							  
$month1=date("m");
if($month1>$check_month)
  {
  $currentyear = date("Y");
 $curr_full_year=date("Y");
$curr_short_year=date("y");
$future=$curr_short_year+1;
} else {
$currentyear1 = date("Y");
$currentyear = $currentyear1-1;
$curr_full_year1=date("Y");
 $curr_full_year=$curr_full_year1-1;
 $curr_short_year1=date("y");

$curr_short_year=$curr_short_year1-1;
$future=$curr_short_year+1;
}
?>


<?   $curr_fy=$currentyear .'-'. $future;?>

 <? include('sahavas_dropdown_function.php');?>

 <!DOCTYPE html>
<html>
<head>
  <meta charset="utf-8">
  <meta http-equiv="X-UA-Compatible" content="IE=edge">
  <title>shigmoda.com</title>
  <!-- Tell the browser to be responsive to screen width -->
 <meta content="width=device-width, initial-scale=1, maximum-scale=1, user-scalable=no" name="viewport">
  <!-- Bootstrap 3.3.6 -->
  <link rel="stylesheet" href="bootstrap/css/bootstrap.min.css"><link rel="stylesheet" href="bootstrap/css/bootstrap.min.css">
  <!-- Font Awesome -->
  <link rel="stylesheet" href="https://cdnjs.cloudflare.com/ajax/libs/font-awesome/4.5.0/css/font-awesome.min.css">
  <!-- Ionicons -->
  <link rel="stylesheet" href="https://cdnjs.cloudflare.com/ajax/libs/ionicons/2.0.1/css/ionicons.min.css">
  <!-- daterange picker -->
  <link rel="stylesheet" href="plugins/daterangepicker/daterangepicker.css">
  <!-- bootstrap datepicker -->
  <link rel="stylesheet" href="plugins/datepicker/datepicker3.css">
  <!-- iCheck for checkboxes and radio inputs -->
  <link rel="stylesheet" href="plugins/iCheck/all.css">
  <!-- Bootstrap Color Picker -->
  <link rel="stylesheet" href="plugins/colorpicker/bootstrap-colorpicker.min.css">
  <!-- Bootstrap time Picker -->
  <link rel="stylesheet" href="plugins/timepicker/bootstrap-timepicker.min.css">
  <!-- Select2 -->
  <link rel="stylesheet" href="plugins/select2/select2.min.css">
  <!-- Theme style -->
  <link rel="stylesheet" href="dist/css/AdminLTE.min.css">
  <!-- AdminLTE Skins. Choose a skin from the css/skins
       folder instead of downloading all of them to reduce the load. -->
  <link rel="stylesheet" href="dist/css/skins/_all-skins.min.css">
<script src="https://ajax.googleapis.com/ajax/libs/jquery/2.2.4/jquery.min.js"></script>
		<script src="jquery.table2excel.min.js"></script><link rel="stylesheet" href="jquery-ui.css">

  <script src="jquery-ui.js"></script>
  <?php 

$query = "select * from users where username = '". $_SESSION["LOGIN_NAME"]."' AND password = '".$_SESSION["EMPLOYEE_PASSWORD"]."'";
//echo $query;
$result = mysql_query($query,$conn);
while($row=mysql_fetch_array($result))
	                                              	{
													  $staff_name = $row['full_name'];$staff_name = $row['full_name'];
													  $full_name = $row['full_name'];
													  $avatar = $row['avatar'];
													  $department_name = $row['department_name'];
													  $staff_id  = $row['id'];
													  $username = $row['username'];
													  $our_company = $row['our_company'];
													  $designation = $row['designation'];
													  $sales_group = $row['sales_group'];
													  $head = $row['head'];
													  $region = $row['region'];
													  $district = $row['district'];
													  $email = $row['email'];
													  $mobile_no = $row['mobile_no'];
													  $staff_id_self  = $row['id'];
													  $sales_region = $row['region'];
													  
													  $back_office_login=$row['back_office_login'];
													  $back_office_head=$row['back_office_head'];
													  $back_office_region=$row['back_office_region'];
													  $back_office_group=$row['back_office_group'];
													  $active_login = $row['active_login'];

													  
													  //echo $Branch;
													  }	
													   ?>	
<?php $querylogin = "select * from staff_login where username = '". $_SESSION["LOGIN_NAME"]."' AND password = '".$_SESSION["EMPLOYEE_PASSWORD"]."'";
$resultlogin = mysql_query($querylogin,$conn);
while($row=mysql_fetch_array($resultlogin))
{
$Designation = $row['designation'];
$staff_name = $row['staff_name'];

}
?>
<?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); }
	
?>

   <style>
  table {
  border: 1px solid #ccc;
  border-collapse: collapse;
  margin: 0;
  padding: 0;
 
}
table caption {
  font-size: 1.2em;
  margin: .5em 0 .75em;
}
table tr {
  
  border: 1px solid #ddd;
  padding: .35em;
}
table th,
table td {
  padding: .625em;
  
}
table th {
  font-size: 13px;;
  letter-spacing: 0em;
  text-transform: capitalize; margin-right:5px;
}
@media screen and (max-width: 600px) {
  table {
    border: 0;
  }
  table caption {
    font-size: 1.8em;
  }
  table thead {
    border: none;
    clip: rect(0 0 0 0);
    height: 1px;
    margin: -1px;
    overflow: hidden;
    padding: 0;
    position: absolute;
    width: 1px;
  }
  table tr {
    border-bottom: 3px solid #ddd;
    display: block;
    margin-bottom: .625em;
  }
  table td {
    border-bottom: 1px solid #ddd;
    display: block;
    font-size: .9em;
    
  }
  table td:before {
    /*
    * aria-label has no advantage, it won't be read inside a table
    content: attr(aria-label);
    */
    content: attr(data-label);
    float: left;
    font-weight: bold;
    text-transform: uppercase;
  }
  table td:last-child {
    border-bottom: 0;
  }
}

  .style1 {color: #000066}
  </style> 


</head><link rel="stylesheet" href="jquery-ui.css">
<body class="hold-transition skin-blue sidebar-mini">
<div class="wrapper">
<?php depat_check($department_name,$designation);?>

	
<div class="content-wrapper">
    <!-- Content Header (Page header) --->

<section class="content-header">
      <h1>
Invoice  Report  &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp;<? back_toindex($department_name,$designation);?>&nbsp;&nbsp;&nbsp;&nbsp;     </h1>
  </section>
   
	
			
<section class="content"> 
<div class="row">
 <div>
		
					
			<div class="col-sm-12" id="squareboxcontent1" style="">
				<div class="filter-view">
					<div class="table-responsive">
						<form name="frmSearch" method="post" action="view_all_dircttransinv.php">
						<div class="search-box">
						
			
						<table class="table table-striped table-bordered table-hover">
						
						
						    <tbody>
							<div class="col-xs-12" style="background:#3C8DBC;">
							<h5 style="color:#FFFFFF"><span class="glyphicon glyphicon-list"></span>&nbsp;&nbsp;Search View - Invoice &nbsp;</h5>
					  </div>
						      <tr>
								<td><div class="form-group"><label for="acccode">Sales Invoice No. </label><br />
<input type="text" placeholder="INV No." name="search[trans_inv_no]" class="form-control" value="<?php echo $trans_inv_no; ?>"	/></div>			</td>
			<td><div class="form-group"><label for="acccode">Invoice Date</label><br />
			<input type="text" placeholder="From Date" name="search[datepicker]"  class="datepicker_y form-control" value="<?php echo $datepicker; ?>"	/>
			
			
			&nbsp;&nbsp;<input type="text" placeholder="To Date" name="search[datepicker1]"  class="datepicker_y form-control" value="<?php echo $datepicker1; ?>"	/>
			<script>$(".datepicker_y").datepicker({
  inline: true,
  
  nextText: '&rarr;',
  prevText: '&larr;',
  showOtherMonths: true,
  changeMonth: true,
        changeYear: true,
  dateFormat: 'yy-mm-dd',
  dayNamesMin: ['Sun', 'Mon', 'Tue', 'Wed', 'Thu', 'Fri', 'Sat'],
      showAnim: "slide"
 });</script> 
			
			</div></td>
			
					
			<td><div class="form-group"><label for="acccode">Account Name</label><br />
		<input type="text" placeholder="Account Name" name="search[customer_name]" class="form-control" value="<?php echo $customer_name; ?>"	/></div></td>
		 
          
         

		 
			<td><div class="form-group">
              <label for="acccode">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></td>
					      </tr>
	 
		
		
		<tr>
						      	<td colspan="4" class="center">
			
			<input type="submit" name="go" class="btnSearch btn bg-btn-view-access" value="Search">&nbsp;&nbsp;<input type="reset" class="btnSearch btn bg-btn-view-access" value="Reset" onClick="window.location='view_all_dircttransinv.php'"></td></tr>
			</tbody>
			</table>
			</div>	</form>
			<table class="table2excel table table-striped table-bordered table-hover" data-tableName="Test Table 1">
		
			<div class="search-header" style="padding-top:3px;">
						<div><?php echo $pagination;?>
						
						<div class="col-xs-12" style="background:#3C8DBC;">
							<h5 style="color:#FFFFFF"><span class="glyphicon glyphicon-list"></span>&nbsp;&nbsp;Search View - Invoice (AMT: <? $resultjk = mysql_query($sql,$conn);
while($row=mysql_fetch_array($resultjk)) { 
$amount = $row['amount'];
 $sumamt1+=$amount;
} ?>
 <? 
 
$bascsale2= round($sumamt1,0);
echo number_format($bascsale2,2);
 
 ?>)</h5>
					  </div>
						</div>
				  </div>
			
      <thead>
	  <?php 
if(isset($result["perpage"])) {
					?>
					<tr>
					<td colspan="20" align=right> <?php echo $result["perpage"]; ?></td>
					</tr>
					<?php } ?>
  <tr>
       <th>&nbsp; </th>
	   <th></th>
								       <th colspan="3">Inv. No.</th>
								       <th colspan="2">Date</th>
									   <th colspan="3">Customer</th>
							             <th colspan="2">Total Amount</th>
								       <th colspan="2"> Transport <br>Inv_no</th>
										<th colspan="2">Date</th>
										<th colspan="2">Transport Amount</th>
										<th colspan="2">LR No</th>
                </tr>
      </thead>
				<tbody>
					<?php
						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>
    <th>&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>

<? } ?></th><th><?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; } ?>	
	
	
</th>
    <th colspan="3"><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></th>
    <th colspan="2"><?php echo $result[$k]["trans_inv_date"]?></th>
    <th colspan="3"><?php echo $customer_name?></th>
    <th colspan="2"><?php 
	$sumamt+=$result[$k]["chargable_amount"];
	
	 echo $result[$k]["chargable_amount"]?></th>
     <th colspan="2"><? echo $transport_inv_no;?> </th>
    <th colspan="2"><? echo $transport_date;?></th>
	    <th colspan="2"><? echo $transport_amount;?></th>
		  <th colspan="2"><? echo $lr_no;?></th>
  </tr>			

					<?php
						}
						}
				
					?>
				  <?php
					if(isset($result["perpage"])) {
					?>
					
					<tr>
					<td colspan="20" align=right> <?php echo $result["perpage"]; ?></td>
					</tr>
					<?php } ?>
				<tbody>
			</table>
			
			<? if(!empty($queryCondition) and $department_name!='Sales') {?>
			<script>
			$(function() {
				$(".table2excel").table2excel({
					exclude: ".noExl",
					name: "Excel Document Name",
					<?php if($datepicker !='' and $datepicker1!='' ) {?>
					filename: "invoice_report_from_date:<?php echo $datepicker?>_to_date:<?php echo $datepicker1?>",
					<?php } elseif($customer_name !='') { ?>
					filename: "invoice_report:<?php echo $customer_name?>",
					<?php }else { ?>
					filename: "invoice_report",
					<?php } ?>
					fileext: ".xlsx",
					exclude_img: true,
					exclude_links: true,
					exclude_inputs: true
				});
			});
		</script>
		<? } ?>
		
					</div>
				</div>
			</div>
</div>
	</div></section></div>
    <? include'footer.php'; ?>
