<?php
ini_set('display_errors', 0);
//error_reporting(E_ALL);
//ini_set('display_errors', 1);

session_start();
ob_start();

require_once('configuration/server_connect.php');
require_once('configuration/all_function.php');

$active_id=$_REQUEST['active_id'];
$menu_id=$_REQUEST['menu_id'];

//do_calander('#jv_date');
// Common Information

$page_title="Sales Invoice";
$page="43_customer_so.php?active_id=".$active_id."&menu_id=".$menu_id."";
$status_page="47_customer_invoice_status.php?active_id=".$active_id."&menu_id=".$menu_id."";
$table='journal_master';	
$unique='jv_no';

$request_no=$_REQUEST['request_no'];

$ms_data=mysqli_fetch_object(mysqli_query($conn,'select * from '.$table.' where jv_no="'.$request_no.'"'));

// End Common Information

if(isset($_POST['ins_master_data']))

{
//$_POST['entry_by'] = $_SESSION['user']['id'];
$status='MANUAL';
$entry_by =  $_SESSION['user']['id'];
$entry_at = $now=date('Y-m-d H:i:s');
$group_for = $_SESSION['user']['group'];
$jv_date=$_POST['invoice_date'];
$work_ref_no=$_POST['work_ref_no'];
$bill_ref_no=$_POST['bill_ref_no'];
$inv_subject=$_POST['inv_subject'];
$inv_details=$_POST['inv_details'];
$jv_special=1;
$jv_type=5;
$jv_title=find_a_field($conn,'journal_type','jv_title','id="'.$jv_type.'"');

		$YR = date('Y',strtotime($jv_date));
 		$year = date('y',strtotime($jv_date));
  		$month = date('m',strtotime($jv_date));
 		$inv_cy_id = find_a_field($conn,'journal_master','max(jv_id)','year="'.$YR.'" and jv_type="'.$jv_type.'"')+1;
  		$cy_id = sprintf("%06d", $inv_cy_id);
   		$invoice_no=''.$year.''.$month.''.$jv_type.''.$cy_id;
		$view_invoice_no=$jv_title.''.$year.''.$month.''.$jv_type.''.$cy_id;
		

$warehouse_id=$_POST['warehouse_id'];
$remarks = $_POST['remarks'];

$tr_from='Sales';

  $acc_reference=$_POST['acc_reference'];
  $reference=explode(' ::',$acc_reference);
  $ref_no=$reference[0];
  
   $employee_name = $_REQUEST['employee_name'];
   $employee=explode(' :: ',$employee_name);
   $emp_code=$employee[0];
  
$ref_sql="SELECT * FROM accounts_reference  WHERE ref_no='".$ref_no."'";
$ref_data = find_all_field_sql($conn,$ref_sql);

$master_ledger_id=$ref_data->ledger_id;
  
$acc_terms=$_POST['acc_terms'];
$address=$_POST['address'];


$grp_sql="SELECT * FROM ledger_group  WHERE group_id='".$ledger_group_id."'";
$grp_data = find_all_field_sql($conn,$grp_sql);

  $ins_sql = 'INSERT INTO  journal_master (jv_no, year, jv_id, view_jv_no, jv_type, jv_date, group_for, master_ledger_id, tr_from, remarks, status, entry_at, entry_by, ref_no, acc_terms, address, warehouse_id, emp_code, work_ref_no, bill_ref_no, inv_subject, inv_details, jv_special) VALUES

("'.$invoice_no.'", "'.$YR.'", "'.$cy_id.'", "'.$view_invoice_no.'", "'.$jv_type.'", "'.$jv_date.'", "'.$group_for.'", "'.$master_ledger_id.'", "'.$tr_from.'", "'.$remarks.'", "'.$status.'", "'.$entry_at.'", "'.$entry_by.'", "'.$ref_no.'", "'.$acc_terms.'", "'.$address.'", "'.$warehouse_id.'", "'.$emp_code.'", "'.$work_ref_no.'", "'.$bill_ref_no.'", "'.$inv_subject.'", "'.$inv_details.'", "'.$jv_special.'")';
	
mysqli_query($conn,$ins_sql);


		//if($_FILES['attached_file']['tmp_name']!=''){ 
//		$file_temp = $_FILES['attached_file']['tmp_name'];
//		$folder = "jv_attached_file";
//		move_uploaded_file($conn,$file_temp, $folder.$invoice_no.'.jpg');}


header("location:".$page.'&request_no='.$invoice_no."");

?>

<!--<script language="javascript">
window.location.href = "<?php echo $page;?>&request_no=<?=$invoice_no?>";
</script>-->

<?php

}


if(isset($_POST['up_master_data']))

{
//$_POST['entry_by'] = $_SESSION['user']['id'];
$status='MANUAL';
$entry_by =  $_SESSION['user']['id'];
$entry_at = $now=date('Y-m-d H:i:s');
$group_for = $_SESSION['user']['group'];
$jv_date=$_POST['invoice_date'];
$work_ref_no=$_POST['work_ref_no'];
$bill_ref_no=$_POST['bill_ref_no'];
$inv_subject=$_POST['inv_subject'];
$inv_details=$_POST['inv_details'];
$address=$_POST['address'];
$jv_no=$_POST['jv_no'];		

$warehouse_id=$_POST['warehouse_id'];
$remarks = $_POST['remarks'];
  
$ref_sql="SELECT * FROM accounts_reference  WHERE ref_no='".$ref_no."'";
$ref_data = find_all_field_sql($conn,$ref_sql);

$master_ledger_id=$ref_data->ledger_id;

 $up_jm='update journal_master set work_ref_no="'.$work_ref_no.'", bill_ref_no="'.$bill_ref_no.'", inv_subject="'.$inv_subject.'", inv_details="'.$inv_details.'", address="'.$address.'" where jv_no="'.$jv_no.'"';
mysqli_query($conn,$up_jm);


		//if($_FILES['attached_file']['tmp_name']!=''){ 
//		$file_temp = $_FILES['attached_file']['tmp_name'];
//		$folder = "jv_attached_file";
//		move_uploaded_file($conn,$file_temp, $folder.$invoice_no.'.jpg');}

header("location:".$page.'&request_no='.$jv_no."");

?>

<!--<script language="javascript">
window.location.href = "<?php echo $page;?>&request_no=<?=$jv_no?>";
</script>-->

<?php

}



if(isset($_POST['ins_primary_data']))

{
//$_POST['entry_by'] = $_SESSION['user']['id'];

$ms_sql="SELECT * FROM journal_master  WHERE jv_no='".$request_no."'";
$ms_data = find_all_field_sql($conn,$ms_sql);

$status='MANUAL';
$entry_by =  $_SESSION['user']['id'];
$entry_at = $now=date('Y-m-d H:i:s');

$jv_no=$ms_data->jv_no;
$jv_date=$ms_data->jv_date;
$relevant_ledger=$ms_data->master_ledger_id;
$ref_no=$ms_data->ref_no;
$tr_from=$ms_data->tr_from;
$tr_no=$ms_data->jv_no;
$cc_code=0;
$tr_id=0;
$group_for=$ms_data->group_for;
$warehouse_id=$ms_data->warehouse_id;
$emp_code=$ms_data->emp_code;

$item_name=$_POST['item_name'];

  $item=explode(' :: ',$item_name);
  $item_id=$item[0];
  
//$unit_name = find_a_field($conn,'item_info','unit_name','item_id="'.$item_id.'"');

$item_sql="SELECT * FROM item_info  WHERE item_id='".$item_id."'";
$item_data = find_all_field_sql($conn,$item_sql);

$narration=$_POST['narration'];

$total_unit=$_POST['total_unit'];
$unit_price=$_POST['unit_price'];
$total_amt=$_POST['total_amt'];


if($item_id>0){

  $ins_sql = 'INSERT INTO  sales_invoice (jv_no, jv_date, group_for, warehouse_id, ref_no, item_id, unit_name, total_unit, unit_price, total_amt, tr_from, narration, status, entry_at, entry_by, emp_code) VALUES

("'.$jv_no.'", "'.$jv_date.'", "'.$group_for.'", "'.$warehouse_id.'", "'.$ref_no.'", "'.$item_id.'", "'.$item_data->unit_name.'", "'.$total_unit.'", "'.$unit_price.'", "'.$total_amt.'", "'.$tr_from.'", "'.$narration.'", "'.$status.'", "'.$entry_at.'", "'.$entry_by.'", "'.$emp_code.'")';
	
mysqli_query($conn,$ins_sql);

}

$tr_no=mysqli_insert_id($conn);

$data_table='sales_invoice';

if($item_data->item_type==1){
journal_item_control($conn, $jv_date, $item_id, $warehouse_id, $item_in, $total_unit, $unit_price, $total_amt, $tr_from, $tr_no, $jv_no, $ref_no, $group_for, $data_table);
}

header("location:".$page.'&request_no='.$jv_no."");

?>

<!--<script language="javascript">
window.location.href = "<?php echo $page;?>&request_no=<?=$jv_no?>";
</script>-->

<?php

}



if(isset($_POST['confirm_data']))

{
//$_POST['entry_by'] = $_SESSION['user']['id'];

$ms_sql="SELECT * FROM journal_master  WHERE jv_no='".$request_no."'";
$ms_data = find_all_field_sql($conn,$ms_sql);

$status='MANUAL';
$entry_by =  $_SESSION['user']['id'];
$entry_at = $now=date('Y-m-d H:i:s');

$jv_no=$ms_data->jv_no;
$jv_date=$ms_data->jv_date;
$tr_from=$ms_data->tr_from;

$vat_amt=$_POST['vat_amt'];
$advance_amt=$_POST['advance_amt'];

$up_jm='update journal_master set vat_amt="'.$vat_amt.'", advance_amt="'.$advance_amt.'"
 where jv_no="'.$jv_no.'"';
mysqli_query($conn,$up_jm);

if($jv_no>0){
auto_insert_invoice_secoundary_journal($conn,$jv_no);
}

header("location:".$status_page);

?>

<!--<script language="javascript">
window.location.href = "<?php echo $page;?>";
</script>-->

<?php

}





if(isset($_POST['del_primary_data']))

{
//$_POST['entry_by'] = $_SESSION['user']['id'];

$ms_sql="SELECT * FROM sales_invoice  WHERE jv_no='".$request_no."'";
$ms_data = find_all_field_sql($conn,$ms_sql);

$status='MANUAL';
$entry_by = $_SESSION['user']['id'];
$entry_at = $now=date('Y-m-d H:i:s');

$jv_no=$ms_data->jv_no;
$tr_from=$ms_data->tr_from;

$del_id=$_POST['del_id'];

$sql_dels = 'delete from sales_invoice where  id="'.$del_id.'"';
mysqli_query($conn,$sql_dels);

$sql_delj = 'delete from journal_item where  tr_no="'.$del_id.'" and sr_no="'.$jv_no.'" and tr_from="'.$tr_from.'" ';
mysqli_query($conn,$sql_delj);

header("location:".$page.'&request_no='.$jv_no."");
?>

<!--<script language="javascript">
window.location.href = "<?php echo $page;?>&request_no=<?=$jv_no?>";
</script>-->

<?php

}







if(isset($_POST['cancel_data']))

{
//$_POST['entry_by'] = $_SESSION['user']['id'];

$ms_sql="SELECT * FROM journal_master  WHERE jv_no='".$request_no."'";
$ms_data = find_all_field_sql($conn,$ms_sql);

$status='MANUAL';
$entry_by = $_SESSION['user']['id'];
$entry_at = $now=date('Y-m-d H:i:s');

$jv_no=$ms_data->jv_no;
$tr_from=$ms_data->tr_from;

$sql_del1 = 'delete from journal_master where tr_from="'.$tr_from.'" and jv_no="'.$jv_no.'"';
mysqli_query($conn,$sql_del1);

$sql_del2 = 'delete from  sales_invoice where tr_from="'.$tr_from.'" and jv_no="'.$jv_no.'"';
mysqli_query($conn,$sql_del2);

$sql_del3 = 'delete from journal_item where tr_from="'.$tr_from.'" and sr_no="'.$jv_no.'"';
mysqli_query($conn,$sql_del3);

header("location:".$page);
?>

<!--<script language="javascript">
window.location.href = "<?php echo $page;?>";
</script>-->

<?php

}






?>




<!DOCTYPE html>
<html lang="en">

<!-- ======= <head> ======= -->
 <?php require_once('inc_files/inc_head.php'); ?>
<!-- ======= </head> ======= -->


  <?php
  do_calander('#invoice_date');
  create_combobox('master_ledger');
  ?>
 
 
 <script language="javascript">

function count(){



var total_unit=(document.getElementById('total_unit').value)*1; 

var unit_price=(document.getElementById('unit_price').value)*1;

document.getElementById('total_amt').value=(total_unit*unit_price);



}


function count_total_cal(){
var sub_total_amt=(document.getElementById('sub_total_amt').value)*1; 
var vat_amt=(document.getElementById('vat_amt').value)*1; 
var advance_amt=(document.getElementById('advance_amt').value)*1; 
document.getElementById('invoice_amt').value=(sub_total_amt+vat_amt)-advance_amt;

}




//window.onload = function() {
//  document.getElementById("itemin").focus();
//};






</script>

<body>

  <!-- ======= Header ======= -->
  <?php 
  require_once('inc_files/inc_header.php');
  ?><!-- End Header -->

  <!-- ======= Sidebar ======= -->
   <?php  require_once('inc_files/inc_menu.php'); ?>
   <!-- End Sidebar-->

  <main id="main" class="main">

    <div class="pagetitle">
      <h1><?php echo $page_title?></h1>
      <nav>
        <ol class="breadcrumb">
          <li class="breadcrumb-item"><a href="home.php">Home</a></li>
          <li class="breadcrumb-item">Sales Management</li>
          <li class="breadcrumb-item active"><?php echo $page_title?></li>
        </ol>
      </nav>
    </div><!-- End Page Title -->

    <section class="section">
      <div class="row">
        

        <div class="col-lg-7">

          <div class="card">
            <div class="card-body">
              
			  <br>

              <!-- General Form Elements -->
                <form class="row g-3" action="" method="post" name="form1" id="form1" onSubmit="return check()" style="font-size:12px;">
                <div class="col-md-6">
                 <label for="first_name" class="form-label"><strong>Invoice No</strong></label>
                 <input type="text" class="form-control" id="jv_no" name="jv_no" value="<?php if($request_no>0){ echo $ms_data->jv_no; } ?>" readonly="" >
			    
		<input type="hidden" class="form-control" id="warehouse_id" name="warehouse_id" value="<?php echo $_SESSION['user']['depot']; ?>" required readonly="">
                </div>
				
				<div class="col-md-6">
                 <label for="last_name" class="form-label"><strong>Invoice Date</strong></label>
                 
				<?php if($request_no>0){?> 
			    <input type="text" class="form-control" id="jv_date" name="jv_date" value="<?php echo $ms_data->jv_date; ?>" required readonly="">
			   <?php } else {?>
			   <input type="text" class="form-control" id="invoice_date" name="invoice_date" value="" required>
			   <?php }?>
				 
                </div>
				
				
				
				
				
				
				 <div class="col-md-12">
                 <label for="first_name" class="form-label"><strong>Customer</strong></label>
				 
				
			<?php if($request_no>0){?>
				 
			<select id="acc_reference" name="acc_reference"  class="form-select"  required  >
			
			<?php foreign_relation($conn,'accounts_reference','ref_no','concat(ref_no," :: ",company_name)',$_POST['acc_reference'],'ref_no="'.$ms_data->ref_no.'" ');?>
		
        	</select>
               
				<?php } else {?>
				
				<?php 
				 auto_complete_from_db_sql($conn,'SELECT concat(a.ref_no," :: ",a.company_name), concat(a.ref_no," :: ",a.company_name) FROM accounts_reference a
					 WHERE ref_type=2','acc_reference'); 
				 ?>
				
                  <input type="text" class="form-control" id="acc_reference" name="acc_reference" value="" required>
				<?php }?>	
				
				 </div>
				
				<?php /*?><div class="col-md-6">
                 <label for="last_name" class="form-label"><strong>Employee</strong></label>
				 
			<?php if($request_no>0){?>
				 
			<select id="emp_code" name="emp_code"  class="form-select"  required  >
			
			<?php foreign_relation($conn,'employee_info','emp_code','concat(emp_code," :: ",emp_name)',$_POST['emp_code'],'emp_code="'.$ms_data->emp_code.'" ');?>
		
        	</select>
               
				<?php } else {?>
				
				<?php
			 auto_complete_from_db_sql($conn,'SELECT concat(emp_code," :: ",emp_name), concat(emp_code," :: ",emp_name) FROM employee_info
			WHERE 1 order by emp_code','employee_name');	?>
                  <input type="text" class="form-control" id="employee_name" name="employee_name" value="<?php echo $_REQUEST['employee_name']?>" >	
				<?php }?>	
                </div>
				
				
				<div class="col-md-6">
                 <label for="last_name" class="form-label"><strong>Subject</strong></label>
                 
				<input type="text" class="form-control" id="inv_subject" name="inv_subject" value="<?php if($request_no>0){ echo $ms_data->inv_subject; }?>" required>
                </div><?php */?>
				
				
				
				<div class="col-md-12">
                 <label for="last_name" class="form-label"><strong>Remarks</strong></label>
                   <textarea class="form-control" style="height: 80px" id="inv_details" name="inv_details" ><?php if($request_no>0){ echo $ms_data->inv_details; } ?></textarea>
                </div>
				
				
				
                
				
                   

                <div class="text-center">
				<?php if($request_no>0) {?>
                  <button type="submit" class="btn btn-success btn-sm" name="up_master_data" id="up_master_data" >Update Data</button>
				 <?php }else {?>
				  <button type="submit" class="btn btn-primary btn-sm" name="ins_master_data" id="ins_master_data" >Initiate Entry</button>
				 <?php }?>
                 <!-- <button type="reset" class="btn btn-secondary" onClick="parent.location='<?php echo $page?>'" >Reset</button>-->
                </div>

              </form><!-- End General Form Elements -->

            </div>
          </div>
</div>


<div class="col-lg-5">

          <div class="card">
            <div class="card-body">
		    <br/>
			<table width="100%" class="table table-sm" style="font-size:12px;">
                <thead>
                  <tr style="text-transform:uppercase; color:#012970; background:#f6f9ff;  border-top: 1px solid #CCCCCC;">
                    <th width="22%" scope="col"><span class="card-title" style="font-size:10px; text-transform:uppercase;">JV No </span></th>
                    <th width="20%" scope="col"><span class="card-title" style="font-size:10px;  text-transform:uppercase;"><div style="text-align:center">JV Date</div> </span></th>
                    <th width="20%" scope="col"><span class="card-title" style="font-size:10px; text-transform:uppercase;">
                    <div style="text-align:right">Amount</div> </span></th>
                    <th width="38%" scope="col"><span class="card-title" style="font-size:10px; text-transform:uppercase;">
                    <div style="text-align:right">Entry By </div>
                    </span></th>
                  </tr>
                </thead>
                <tbody>
		<?php
			
					
		 $sql = "select user_id, fname from user_management where 1 group by user_id";
		 $query = mysqli_query($conn,$sql);
		 while($info=mysqli_fetch_object($query)){
  		 $fname[$info->user_id]=$info->fname;
		}
					
					    $sql = 'select a.jv_no, a.view_jv_no, a.jv_date, sum(j.dr_amt) as jv_amt, a.entry_by from '.$table.' a, journal j 
						 where a.jv_no=j.jv_no and a.tr_from="Sales" and a.status="CHECKED" and j.item_id=0 group by j.jv_no order by a.jv_no DESC LIMIT 8';
						$query = mysqli_query($conn,$sql);
						while ($data = mysqli_fetch_object($query)) {

					?>
			
      <tr>
      <td><a href="view_file/journal_print_view.php?jv_no=<?php echo $data->jv_no;?>" target="_blank"><?php echo $data->view_jv_no;?></a></td>
      <td align="center"><?php echo date('d-M-y',strtotime($data->jv_date));?></td>
      <td align="right"><?php echo number_format($data->jv_amt,2); ?></td>
      <td align="right"><?php echo $fname[$data->entry_by];?></td>
      </tr>
				  <?php }?>
				  
     
                </tbody>
              </table>
			</div>
		</div>
</div>


<div class="col-lg-12">

          <div class="card">
            <div class="card-body">
               <br/>
 <form  action="" method="post" name="form1" id="form1" onSubmit="return check()" style="font-size:12px;">
             <table class="table table-bordered ">
                <thead>
                  <tr style="text-transform:uppercase; color:#012970; background:#f6f9ff;  border-top: 1px solid #CCCCCC;">
                    <th width="40%" scope="col">PRODUCT Name </th>
                    <th width="15%" scope="col">Price</th>
                    <th width="15%" scope="col">Quantity</th>
                    <th width="15%" scope="col">Amount</th>
                    <th width="15%" scope="col">ACTION</th>
                  </tr>
                </thead>
                <tbody>
                  <tr>
                    <th scope="row">
					
					<?php
					if($request_no>0) {
					//auto_complete_from_db($conn,'accounts_ledger','ledger_name','concat(ledger_id,"->",ledger_name)','1','ledger_id');
					
	auto_complete_from_db_sql($conn,'SELECT concat(a.item_id," :: ",a.item_name), concat(a.item_id," :: ",a.item_name) 
	FROM item_info a, item_type g  WHERE a.item_type=g.id order by item_id','item_name');
					}
					?>
					
					
					<input type="text" class="form-control" name="item_name" id="item_name" autocomplete="off" required></th>
                    <th scope="row"><input type="text" class="form-control" name="unit_price" id="unit_price" required onKeyUp="count()"></th>
                    <th scope="row"><input type="text" class="form-control" name="total_unit" id="total_unit"  value="" required onKeyUp="count()"></th>
                    <td>
					
					
					<input type="text" class="form-control" name="total_amt" id="total_amt" required >					</td>
                    <td>  <button type="submit" class="btn btn-primary btn-sm" name="ins_primary_data" id="ins_primary_data" ><i class="bi bi-plus-lg me-1"></i>  ADD DATA</button></td>
                  </tr>
                </tbody>
              </table>
                

              </form><!-- End General Form Elements -->

            </div>
          </div>
</div>



 
 
 
          
<div class="col-lg-12">

          <div class="card">
            <div class="card-body">
              
              <br/>
              <!-- Bordered Table -->
			
              <table class="table table-bordered " style="font-size:12px;">
                <thead>
                  <tr style="text-transform:uppercase; color:#012970; background:#f6f9ff;  border-top: 1px solid #CCCCCC;">
                    <th width="3%" scope="col">SL</th>
                    <th width="27%" scope="col">PRODUCT Name </th>
                    <th width="10%" scope="col">UOM</th>
                    <th width="15%" scope="col">Price</th>
                    <th width="15%" scope="col">Quantity</th>
                    <th width="15%" scope="col"><center>AMOUNT</center></th>
                    <th width="15%" scope="col">ACTION</th>
                  </tr>
                </thead>
                <tbody>
					<?php
					
					$sl=1;
					
		
					
						 $sql = 'select s.*, i.item_name from item_info i, sales_invoice s
						where i.item_id=s.item_id and s.jv_no="'.$request_no.'" order by s.id desc';
						$query = mysqli_query($conn,$sql);
						while ($data = mysqli_fetch_object($query)) {

					?>
				
                  <tr>
                    <td scope="row"><?php echo $sl++;?></td>
                    <td><?php echo $data->item_name;?></td>
                    <td><?php echo $data->unit_name;?></td>
                    <td><?php echo $data->unit_price;?></td>
                    <td><?php echo $data->total_unit;?></td>
                    <td align="right"><?php echo number_format($data->total_amt,2); $total_inv_amt +=$data->total_amt;?>&nbsp;&nbsp;</td>
                    <td align="center">  <form  action="" method="post" name="form1" id="form1" onSubmit="return check()">
					<input type="hidden" class="form-control" id="del_id" name="del_id" value="<?php echo $data->id; ?>" required readonly="">
					<button type="submit" class="btn btn-danger btn-sm"  name="del_primary_data" id="del_primary_data" ><i class="bi bi-x-octagon"></i></button></form></td>
                  </tr>
				  
				   <?php }?>
<form action="" method="post" name="form1" id="form1" onSubmit="return check()">  
                  <tr>
                    <td colspan="5" scope="row" align="right"><div align="right">Sub Total </div></td>
                    <td align="right"><input type="text" class="form-control" name="sub_total_amt" id="sub_total_amt"  value="<?php echo $total_inv_amt;?>" onKeyUp="count_total_cal()" readonly="" style="text-align:right; font-weight:700;"></td>
                    <td align="center">&nbsp;</td>
                  </tr>
                  <tr>
                    <td colspan="5" scope="row" align="right"><div align="right">VAT</div></td>
                    <td align="right"><input type="text" class="form-control" name="vat_amt" id="vat_amt"  value="<?php echo $vat_amt;?>" 
					onKeyUp="count_total_cal()" style="text-align:right; font-weight:700;"></td>
                    <td align="center">&nbsp;</td>
                  </tr>
                  <tr>
                    <td colspan="5" scope="row" align="right"><div align="right">Advance Adjustment</div></td>
                    <td align="right"><input type="text" class="form-control" name="advance_amt" id="advance_amt" value="<?php echo $advance_amt;?>" onKeyUp="count_total_cal()" style="text-align:right; font-weight:700;"></td>
                    <td align="center">&nbsp;</td>
                  </tr>
                  <tr>
                    <td colspan="5" scope="row" align="right"><div align="right">Invoice Amt </div></td>
                    <td align="right"><input type="text" class="form-control" name="invoice_amt" id="invoice_amt" style="text-align:right; font-weight:700;"
					 value="<?php echo $invoice_amt=($total_inv_amt+$vat_amt)-$advance_amt;?>"  onKeyUp="count_total_cal()" readonly=""></td>
                    <td align="center">&nbsp;</td>
                  </tr>
               
			   
			   <?php if($total_inv_amt>0) {?>  
                  <tr>
                    <td colspan="7" scope="row" align="left">
						 <br><br><br><br><br><br> <br>  
			
 

                  <button type="submit" class="btn btn-success btn-sm" name="confirm_data" id="confirm_data" >Save &amp; Publish</button>&nbsp;&nbsp;
				 
				  <button type="reset" class="btn btn-primary btn-sm" onClick="parent.location='<?php echo $page?>'" >Save as Draft</button>&nbsp;&nbsp;
				 
                  <button type="submit" class="btn btn-danger btn-sm" name="cancel_data" id="cancel_data" >Cancel</button>					</td>
                  </tr>
                  <?php }?>
				   </form> 
                </tbody>
              </table>
			  
              <!-- End Bordered Table -->
			  

            </div>
          </div>

          

        </div>
      </div>
    </section>

  </main><!-- End #main -->

 <!-- ======= Footer ======= -->
 <?php require_once('inc_files/inc_footer.php'); ?>
<!-- ======= Footer ======= -->

</body>

</html>