<?php include 'connection.php';
date_default_timezone_set('Asia/Calcutta');
$today = date("Y-m-d");
$current_month=date("m");
$query2job = "select * from check_month";
$resultjob = mysql_query($query2job,$conn);
while($rowmonth=mysql_fetch_array($resultjob))
{
$check_month = $rowmonth['check_month'];
}

?>

<? 										   
													   							  
$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;?>
<?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'];
													  $full_name = $row['full_name'];
													   $full_name11 = $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'];
													  //echo $Branch;
													  }	
													   ?>			

<!DOCTYPE html>
<html>
<head>
  <meta charset="utf-8">
  <meta http-equiv="X-UA-Compatible" content="IE=edge">
  <title>Shipping :: CRM Software</title>
  <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">
  <!-- 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">
 <link rel="stylesheet" href="public/css/default.css" type="text/css">
 <script src="jquery.min.js"></script>
<script src="jquery-ui.js"></script>

<link rel="stylesheet" href="jquery-ui.css">
<style>table {
  border: 1px solid #ccc;
  border-collapse: collapse;
  margin: 0;
  padding: 0;
  width: 100%;
  table-layout: fixed;
}
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: .85em;
  letter-spacing: .0em;
  text-transform: uppercase;
}
@media screen and (max-width: 600px) {
  table {
    border: 0;
  }
  table caption {
    font-size: 1.3em;
  }
  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: .6em;
    text-align: right;
  }
  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;
  }
}

</style>												   


</head>
<body class="hold-transition skin-blue sidebar-mini"  onLoad="calendarSetup()">
<div class="wrapper">

<?php  include 'header.php'; ?>

<?php


$uploadedStatus = 0;

if ( isset($_POST["submit"]) ) {
if ( isset($_FILES["file"])) {
//if there was an error uploading the file
if ($_FILES["file"]["error"] > 0) {
echo "Return Code: " . $_FILES["file"]["error"] . "<br />";
}
else {
if (file_exists($_FILES["file"]["name"])) {
unlink($_FILES["file"]["name"]);
}
$storagename = "discussdesk.xlsx";
move_uploaded_file($_FILES["file"]["tmp_name"],  $storagename);
$uploadedStatus = 1;
}
} else {
echo "No file selected <br />";
}
}

?>

 
<!-- Content Wrapper. Contains page content -->
  <div class="content-wrapper">
    <!-- Content Header (Page header) -->
   
    <!-- Main content -->
    <section class="content">
      			 <?php												
$query2 = "select * from company_info where name = '".$_REQUEST['our_company_name']."'";
$result2 = mysql_query($query2,$conn);	
while($row = mysql_fetch_array($result2))
{
$full_name_com = $row['full_name_com'];
}
?>
<?php												
$query2 = "select * from customer_master where customer_id = '".$_REQUEST['customer_id']."'";
$result2 = mysql_query($query2,$conn);	
while($row = mysql_fetch_array($result2))
{
$billing_address = $row['billing_address'];
$bgst_no = $row['bgst_no'];
$customer_name = $row['customer_name'];
$bstate_code = $row['bstate_code'];

}
?>
<?php
$str = $_REQUEST['trans_inv_no'];
				$resultset = explode("/",$str);
				
			 $transport_name = current($resultset);
				
				?>
				
				<?php 
$query2tm = "select * from transport_master where short_form = '$transport_name'";
$result2tm = mysql_query($query2tm,$conn);	
while($row = mysql_fetch_array($result2tm))
{
$full_name = $row['transport_name'];
}
?>

<?php 
$queryac = "select * from  tax_transtax where trans_inv_no='".$_REQUEST['trans_inv_no']."' and customer_id='".$_REQUEST['customer_id']."'";
$resultac = mysql_query($queryac,$conn);	
while($row = mysql_fetch_array($resultac))
{
$an_ac_of = $row['an_ac_of'];
$challan_no_book=$row['challan_no_book'];
$delivery_date=$row['delivery_date'];

}
?>
<?php 


$queryac = "select * from  tax_servicetax where inv_no='$inv_no' and customer_id='".$_REQUEST['customer_id']."'and final_job_no='$final_job_no'";
$resultac = mysql_query($queryac,$conn);	
while($row = mysql_fetch_array($resultac))
{
$billing_address_tax=$row['billing_address'];	
$gst_no_tax = $row['gst_no'];
$state_code = $row['state_code'];
}
$querytax = "select * from  transporter_details_expenses where trans_inv_no='".$_REQUEST['trans_inv_no']."'  and customer_id='".$_REQUEST['customer_id']."'";
		//echo $querytax;
		                 $resulttax = mysql_query($querytax,$conn);	
						  while($row=mysql_fetch_array($resulttax))
						  {
						  $customer_name_direct=$row['customer_name'];	
$address_direct = $row['address'];
$pan_no_direct = $row['pan_no'];
$trans_inv_date = $row['trans_inv_date'];
$account_of = $row['account_of'];
						  
						  }
						  
					


?>

	  

      <div class="row">
	  
	
        <div class="col-md-12">
          <div class="box box-danger">
            <div class="box-header with-border">
               <h3 class="box-title" style="color:#000; font-family:Calibri; font-weight:bold;">Make Bill for Job: <?php echo $final_job_no?> </h3>
            </div>
            <!-- /.box-header -->
            <div class="box-body">
              <div class="row">
			              <div class="box-body">
			
			<form name="deptdetail" id="deptdetail" action="update_tranexp.php" method="post" enctype="multipart/form-data">
			<input  type="hidden" name="customer_id" value="<?php echo $_REQUEST['customer_id'];?>" />
			<input  type="hidden" name="inv_no" value="<?php echo $_REQUEST['inv_no'];?>" />
			<input  type="hidden" name="inv_date" value="<?php echo $_REQUEST['inv_date'];?>" />
			<input  type="hidden" name="our_company_name" value="<?php echo $account_of;?>" />
			<input  type="hidden" name="trans_inv_no" value="<?php echo $_REQUEST['trans_inv_no'];?>" />
			<input  type="hidden" name="Job_No" value="<?php echo $_REQUEST['Job_No'];?>" />
			<input  type="hidden" name="inv_type" value="<?php echo $_REQUEST['inv_type'];?>" />

<input type="hidden" name="trans_no" value="<? echo $_REQUEST['trans_no']?>">



<table class="table table-bordered">
  <tr>
    <td width="52%"><table width="100%"   style="border-collapse:collapse">
      <tr>
        <td><div align="left" style="padding:3px;">M/S</div></td>
        <td><div align="left" style="padding:3px;">
          <? if($customer_name_direct!='') { ?>
          <? echo $customer_name_direct; ?>
            <? }else { ?>
          <?php echo $customer_name?>
            <? } ?>
        </div></td>
      </tr>
      <tr>
        <td width="17%"><div align="left" style="padding:3px;">Add</div></td>
        <td width="83%"><div align="left" style="padding:3px;">
          <?php if($address_direct!='') { ?>
            <? echo $address_direct; ?>
            <? } else { ?>
          <? if($billing_address_tax!=''){echo $billing_address_tax;}else { echo $billing_address; }
				}?>
        </div></td>
      </tr>
      <tr>
        <td><div align="left" style="padding:3px;">
          <? if($pan_no_direct!='') { ?>
          PAN No
          <? } else { ?>
          GST No.
          <? } ?>
          : </div></td>
        <td><div align="left" style="padding:3px;">
          <? if($pan_no_direct!='') { ?>
            <? echo $pan_no_direct;?>
            <? } else { ?>
          <? if($gst_no_tax!='') { echo $gst_no_tax; } else { ?>
          <?php echo $bgst_no?>
            <? } }?>
        </div></td>
      </tr>
    </table></td>
    <td width="48%" valign="top"><table width="100%">
      <tr>
        <td width="15%">Bill No. : </td>
        <td width="42%"><input class="form-control" id="trans_inv_no" name="trans_inv_no" value="<?php echo $_REQUEST['trans_inv_no']?>" readonly="readonly" type="text"></td>
      </tr>
      <tr>
        <td>Bill Date: </td>
        <td colspan="2"><input type="text" class="datepicker1 form-control"  name="trans_inv_date" value="<?php echo $trans_inv_date?>"   ></td>
      </tr>
	        <tr>
			<td colspan="3">

	  
                                                        <label>Challan No</label>
														<input type="text" name="challan_no_book"  class="form-control" value="<?php echo $challan_no_book?>" />
														
												
                                                        <label>Delivery  Date</label>
                                                        <input type="text" class="form-control"  name="delivery_date" value="<?php echo $delivery_date?>"  >
</td>
													</tr>
      <tr>
        <td>A/C of </td>
        <td colspan="2"><input type="text" class="form-control"  name="an_ac_of"  <?php if($an_ac_of==''){?>value="Threestar Solutions & Services Pvt. Ltd." <?php } else {?> value="<?php echo $an_ac_of?>"<?php }?>></td>
      </tr>
      
    </table></td>
  </tr>
  <tr>
    <td colspan="2"> <a class="btn bg-btn-new" style="cursor:pointer; margin-left:20px" onClick="callAddContact2();" title="Click to add Contacts">
									<span class="glyphicon glyphicon-plus"></span>&nbsp;Add Services
								</a><a class="btn bg-btn-new" style="cursor:pointer; margin-left:20px" onClick="delRow();" title="Click to remove">
								  <span class="glyphicon glyphicon-remove"></span>&nbsp;Del				</td>
  </tr><table class="table table-bordered" id="cntTable2">
							
								<tr bgcolor="#C5DFFA" >
								
								
									<td width="100px" height="28"valign="middle" nowrap="nowrap" ><div align="left" style="padding-left:5px;"><strong>Sr.No.</strong></div></td>
									<td  height="28"valign="middle" nowrap="nowrap" ><div align="left" style="padding-left:5px;"><strong>Particular</strong></div></td>
									
									<td  height="28"valign="middle" nowrap="nowrap" ><div align="left" style="padding-left:5px;"><strong> 	
Vehicle no</strong></div> </td>


									<td  height="28"valign="middle" nowrap="nowrap" ><div align="left" style="padding-left:5px;"><strong>Amount</strong></div> </td>

									
									
							</tr>
							</thead>
							<tbody> <input id="allcontypes" name="allcontypes" value="Decision Maker~^~Influencer~^~Recommender~^~User~^~Purchase Officer" type="hidden">
						<input name="cntlnos" id="cntlnos" value="" type="hidden">
						<input name="cntcount2" id="cntcount2" value="" type="hidden">
						<input name="cntdelids" id="cntdelids" value="" type="hidden">

							</tbody>
						</table>
  <tr>
    <td colspan="2">
	
				

	<div >
			  <table class="table table-bordered" >
							
								
							</thead>
							<tbody> <? 
							$i=0;
$query2tm = "select * from 	transporter_details_expenses where trans_inv_no = '".$_REQUEST['trans_inv_no']."' and customer_id='".$_REQUEST['customer_id']."'";
$result2tm = mysql_query($query2tm,$conn);	
while($row = mysql_fetch_array($result2tm))
{

$particular = $row['particular'];
$vehicle_no = $row['vehicle_no'];
$trans_no = $row['trans_no'];
$detail_id = $row['detail_id'];
$chargable_amount = $row['chargable_amount'];


$i++;
					?>
					<input type="hidden" name="detail_id<? echo $detail_id?>" value="<? echo $detail_id?>" >
					<tr>
					<td width="100px"><? echo $i?>
					
					<a href="delete_more_expenses.php?detail_id=<?php echo $detail_id;?>&&trans_inv_no=<?php echo $_REQUEST['trans_inv_no'];?>&&customer_id=<?php echo $_REQUEST['customer_id']?>" class="btn bg-btn-new" >X</a></td>
					<td><input class="form-control" id="particular" name="particular<? echo $detail_id?>" value="<?php echo $particular?>" type="text"><br>
					<input class="form-control" name="vehicle_no<? echo $detail_id?>" value="<?php echo $vehicle_no?>" type="text">
					</td>
					<td><input class="form-control" id="chargable_amount" name="chargable_amount<? echo $detail_id?>" value="<?php echo $chargable_amount?>" type="text"></td>
					
					</tr>
					<? } ?>	
							</tbody>
						</table>
			  </div>
			  <div align="right" class="col-sm-12">
						
	          				 <input type="submit" name="Submit" value="Save" class="btn bg-btn-save">
					</div>			  </td>
  </tr>
</table>
              </form>
</div> 
                <!-- /.col -->
                
                <!-- /.col -->
              </div>
              <!-- /.row -->
            </div>
            <!-- ./box-body -->
            
            <!-- /.box-footer -->
          </div>
          <!-- /.box -->
        </div>
        <!-- /.col -->
		
		
		
      </div>
    </section>
    <!-- /.content -->
  </div>
  <!-- /.content-wrapper -->
  <script type="text/Javascript">
	function callAddContact2()
	{
	
   var tbl = document.getElementById('cntTable2');
	 var lastRow = tbl.rows.length;
	 // if there's no header row in the table, then iteration = lastRow + 1
	 var iteration = lastRow;
	 var row = tbl.insertRow(lastRow);
	 var node1;
	 var lineno = lastRow;
	 // cell 0
	 var cellLeft = row.insertCell(0);
	 cellLeft.className = "center";
		var node = document.createElement('span');
		node.className = "glyphicon glyphicon-remove";
		node.title="Delete line";
		var link = document.createElement("a");
		link.className = "btn bg-btn-delete";
		link.style.padding = "0px 2px";
		link.href="javascript:callRemoveContact("+lineno+");";
		link.appendChild(node);
		//cellLeft.appendChild(link);
	 
	 node = document.createElement("input");
	 node.type = 'hidden';
	 node.name = 'cid'+lineno;
	 node.value = '';
	 node.id = 'cid'+lineno;
	 cellLeft.appendChild(node);
	 node = document.createElement("input");
	 node.type = 'text';
	 node.style.width = "50px";
	
	 node.name = 'clinenum'+lineno;
	 node.value = lineno;
	 node.readOnly = true;
	 node.id = 'clinenum'+lineno;
	 cellLeft.appendChild(node);
	 
	 
	 
	  var cell1 = row.insertCell(1);
	  
	 node = document.createElement("textarea");
	 node.className = 'form-control';
	 node.type = 'text';	
	 node.name = 'particular_a'+lineno;
	 node.placeholder='';
	 node.value = "";
	 node.id = '';
	 cell1.appendChild(node);
	 
	
	 
	  var cell2 = row.insertCell(2);
	 node = document.createElement("input");
	 node.className = 'form-control';
	 node.type = 'text';	
	 node.name = 'vehicle_no_a'+lineno;
	 node.placeholder='Vehicle No';
	 node.value = "";
	 node.id = '';
	 cell2.appendChild(node);
	 
	 
	 
	  var cell3 = row.insertCell(3);
	  
	 node = document.createElement("input");
	 node.className = 'form-control';
	 node.type = 'text';	
	 node.name = 'chargable_amount_a'+lineno;
	 node.placeholder='Amount';
	 node.value = "";
	 node.id = '';
	 cell3.appendChild(node);
	 
	 
	 
	
	
		
		
	document.getElementById('cntcount2').value = lineno;
	document.getElementById('sigthseeing').style.visibility='visible';
	
}function delRow()
{

    var tableName = document.getElementById('cntTable2');

    var prev = tableName.rows.length;

    if(prev > 1)

{
    

/////////////////////////////////////////////////////////////////////////////////////
   
	 // if there's no header row in the table, then iteration = lastRow + 1
	
	 var row = document.getElementById('cntTable2').deleteRow(prev-1);
	 
	 }
	 var node1;
	  var iteration = lastRow;
	 var lastRow = tableName.rows.length;
	 var lineno = lastRow;
document.getElementById('cntcount2').value = lineno-1;




}

</script>
<script>$( ".datepicker1y").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> 

	
 </form>
    <? include'footer.php'; ?>

