<?php require_once('../includes/connection.php');require_once('../includes/master/finance_functions.php');
$stmt = $GLOBALS['con']->prepare("SELECT * FROM `clientdetails` WHERE `clientnumber`=? ")or die(mysqli_error($GLOBALS['con']));
$stmt->bind_param('i',$_REQUEST['clientnumber']);$stmt->execute();$cr=$stmt->get_result();$stmt->close();
$cd=mysqli_fetch_array($cr);
$day=date('d',$cd['incepton_date']);
$month=date('m',$cd['incepton_date']);
$year=date('Y',$cd['incepton_date']);

$renewalDate=$day."-".$month."-".date('Y');

$fee=number_format($cd['rate_per_hour'],2);
$vat=$fee*0.2;
$total=$fee+$vat;

if($_REQUEST['mode']=="agent"){
$stmt = $GLOBALS['con']->prepare("SELECT * FROM `agents` WHERE `agent_number`=? ")or die(mysqli_error($GLOBALS['con']));
$stmt->bind_param('i',$cd['agent_number']);$stmt->execute();$ca=$stmt->get_result();$stmt->close();
$ad=mysqli_fetch_array($ca);
$dName=$ad['agent_name'];
$a1=$ad['address1'];
$a2=$ad['address2'];
$a3=$ad['town'];
$a4=$ad['county'];
$a4=$ad['post'];
}

if($_REQUEST['mode']=="client"){
$a1=$cd['billing1'];
$a2=$cd['billing2'];
$a3=$cd['billing_town'];
$a4=$cd['billing_county'];
$a5=$cd['billing_post'];
}
?>
<div class="col-md-6">
<table id="particulars" class="table">
<h2>Details</h2>
<tr><th>Contract Number:</th><td><?= $cd['contract_number']?></td></tr>
<tr><th>Becomes due for Renewal:</th><td><?= $renewalDate?></td></tr>
<tr><th>Renewal Fee:</th><td>&pound;<?= number_format($fee,2)?></td></tr>
<tr><th>VAT:</th><td>&pound;<?= number_format($vat,2)?></td></tr>
<tr><th>Total:</th><td>&pound;<?= number_format($total,2)?></td></tr>
</table>
</div>

<div class="col-md-6">
<h2>Billing Address</h2>
<table id="destination" class="table">
<tr><th><?= $dName?></td></tr>
<tr><th><?= $a1?></td></tr>
<tr><th><?= $a2?></td></tr>
<tr><th><?= $a3?></td></tr>
<tr><th><?= $a4?></td></tr>
<tr><th><?= $a5?></td></tr>
</table>
</div>
<div class="clearfiix spacer"></div>

<div class="col-md-12 text-center">
<button class="btn btn-info"><i class="fad fa-envelope"></i> SEND</button> <button class="btn btn-secondary"><i class="fad fa-print"></i> PRINT</button> 
</div>

<script>
$('#popupBox .modal-header').html('<a href="javascript:void(0)" class="sa">Renewal Notification <?= $_REQUEST['mode']?></a>');
$('#popupBox .modal-footer').html('');
$("#btnCancel").click(function(){$('#popupBox').modal('hide');})
</script>