<?php 
$getpage =$_SERVER['QUERY_STRING']; 
//echo $getpage;
$explode= explode('=',$getpage);
$pagenew=$explode[2];

$query="SELECT order_no,reference,ord_date,contact_phone,contact_email,deliver_to,delivery_date,total,b.debtor_no,b.name,b.address FROM ".$prefix."sales_orders AS a,".$prefix."debtors_master AS b WHERE a.debtor_no=b.debtor_no  AND a.order_no=$pagenew";

$resultBill=mysqli_query($linkid,$query);
$getbilling=mysqli_fetch_array($resultBill);
$debtor=$getbilling['debtor_no'];


$query="SELECT SUM(total) FROM ".$prefix."sales_orders AS a,".$prefix."debtors_master AS b WHERE a.debtor_no=b.debtor_no  AND a.debtor_no=$debtor";
$result=mysqli_query($linkid,$query);
$getOrderTotal=mysqli_fetch_row($result);

//Bsnk accounts///////////////////////////////////
$query="SELECT id,bank_account_name FROM ".$prefix."bank_accounts";
$resultBank=mysqli_query($linkid,$query);

//Bsnk accounts///////////////////////////////////
$query="SELECT ref FROM ".$prefix."bank_trans order by id DESC LIMIT 0,1";
$resultRef=mysqli_query($linkid,$query);
$getRef=mysqli_fetch_row($resultRef);
$myval=explode("-",$getRef[0]);
$getreference=$myval[1];
if($myval[1]=="")
$countRef=1;
else
$countRef=$myval[1]+1;


$orderid=$pagenew;

$query="SELECT SUM(paid) FROM ".$prefix2."order_payment WHERE order_no=$orderid";
$result=mysqli_query($linkid,$query);
$getdata=mysqli_fetch_row($result);
$paid=$getdata[0];

$query="SELECT SUM(paid) FROM ".$prefix2."order_payment WHERE debtor_no=$debtor";
$result=mysqli_query($linkid,$query);
$getdata=mysqli_fetch_row($result);
$paidTotal=$getdata[0];





$advancePaid= $getOrderTotal[0] - $paidTotal;
$advance=$getbilling['total']-$advancePaid;
$pendingBalance = $getbilling['total'] - $advance;
//echo $advancePaid;exit;
?>

?>
<div id="loading_layer" style="display:none"><img src="img/ajax_loader.gif" alt="" /></div>
<?php include "templates/stylechange.php";?>
<div id="maincontainer" class="clearfix">
  <!-- header -->
  <?php include "templates/header.php"?>
  <!-- main content -->
  <?php include "modules/accounts/order-payment-edit.php"?>
  <!-- sidebar -->
  <a href="javascript:void(0)" class="sidebar_switch on_switch ttip_r" title="Hide Sidebar">Sidebar switch</a>
  <?php include "templates/sidebar.php" ?>
  <script src="js/jquery.min.js"></script>
  <script src="js/jquery-migrate.min.js"></script>
  <!-- smart resize event -->
  <script src="js/jquery.debouncedresize.min.js"></script>
  <!-- hidden elements width/height -->
  <script src="js/jquery.actual.min.js"></script>
  <!-- js cookie plugin -->
  <script src="js/jquery_cookie.min.js"></script>
  <!-- main bootstrap js -->
  <script src="bootstrap/js/bootstrap.min.js"></script>
  <!-- bootstrap plugins -->
  <script src="js/bootstrap.plugins.min.js"></script>
  <!-- tooltips -->
  <script src="lib/qtip2/jquery.qtip.min.js"></script>
  <!-- jBreadcrumbs -->
  <script src="lib/jBreadcrumbs/js/jquery.jBreadCrumb.1.1.min.js"></script>
  <!-- sticky messages -->
  <script src="lib/sticky/sticky.min.js"></script>
  <!-- fix for ios orientation change -->
  <script src="js/ios-orientationchange-fix.js"></script>
  <!-- scrollbar -->
  <script src="lib/antiscroll/antiscroll.js"></script>
  <script src="lib/antiscroll/jquery-mousewheel.js"></script>
  <!-- lightbox -->
  <script src="lib/colorbox/jquery.colorbox.min.js"></script>
  <!-- mobile nav -->
  <script src="js/selectNav.js"></script>
  <!-- common functions -->
  <script src="js/gebo_common.js"></script>
  <!-- validation -->
  <script src="lib/validation/jquery.validate.min.js"></script>
  <!-- validation functions -->
  <script src="js/gebo_validation_customer_payment.js"></script>
  	<link type="text/css" href="themes/base/ui.all.css" rel="stylesheet" />
			<script type="text/javascript" src="javascript/ui.core.js"></script>
			<script type="text/javascript" src="javascript/ui.datepicker.js"></script>
			<script type="text/javascript" src="javascript/stockcheck.js"></script>
			<script type="text/javascript" src="javascript/transchecktoherfees.js"></script>
			<script type="text/javascript">
			$(function() {
				$('#mydate').datepicker({
					changeMonth: true,
					changeYear: true
				});
			
								
			});
			</script>
  <script>
				$(document).ready(function() {
					//* show all elements & remove preloader
					setTimeout('$("html").removeClass("js")',1000);
				});
			</script>
</div>
