<?php switch($_REQUEST['view']){
default:?>
<?php break;
case 'new':
require_once('includes/asset/asset_functions.php');
?>
<script>$('#navBox').html('<a href="javascript:void(0)" class="s1">Schedules</a><a href="javascript:void(0)" class="sa">New Client</a>')</script>
<form id="clientForm" class="form-horizontal">
<fieldset>
<?php
require_once('includes/forms/elements/client_details.frm');
require_once('includes/forms/elements/client_contacts.frm');
require_once('includes/forms/elements/client_additional.frm');
require_once('includes/forms/elements/client_billing.frm');
require_once('includes/forms/elements/client_other.frm');
?>
<div class="spacer"></div>
<input type="hidden" name="FUNCTION" value="insert">
</fieldset>

<div class="col-12 col-md-12 text-center">

<input id="btn_reset" type="reset" value="Reset Form" style="display:none"/>
<input  id="btn_create" type="submit" name="submit" value="Submit"  style="display:none" />

</div>
</form>
<script>
function setBilling(){
$('#billing_name').val($('#clientname').val())
$('#billing1').val($('#address1').val())
$('#billing2').val($('#address2').val())
$('#billing3').val('')
$('#billing_town').val($('#town').val())
$('#billing_county').val($('#county').val())
$('#billing_postcode').val($('#postcode').val())
	
}
$( document ).ready(function() {
$('#footerControls').html('<button class="btn btn-default" onclick="triggerAction(\'btn_reset\')">RESET</button> <button class="btn btn-info" onclick="triggerAction(\'btn_create\')">CREATE</button>')
})
</script>
<?php break;
case 'edit_base':
require_once('includes/asset/asset_functions.php');?>
<div class="col-md-12">
<blockquote class="blockquote">You can create a new asset directly by first selecting your client and site</blockquote>
</div>
<div class="col-md-3">
<div class="card">
<div class="card-header">Client</div>
<div class="card-block">
<br>
<div class="top_search">
<input class="form-control form-control-sm" id="clientOpt" placeholder="(1) Select Client">
</div>
<br>
</div>
</div>
</div>

<div class="clearfix"></div>

<div id="confirmbox" style="display:none">
<h2 class="alert alert-info text-center">You want to edit <strong><span id="clientNotice"></span></strong></h2>

<div id="confirmlink" class="col-md-12 text-center"><button class="btn btn-default" type="submit"> Confirm </button></div>


</div>
<script>
$('#navBox').html('<a href="javascript:void(0)" class="s1">Schedules</a><a href="javascript:void(0)" class="sa">Edit Client</a>');
<?= listClient("","client","ajax")?>

$(document).ready(function() {
	$("#clientOpt").autocomplete({
	source: clientList,
	select: function(event, ui) {

$('#clientNotice').text(ui.item.value)
$('#confirmlink').html('<a class="btn btn-default" href="index.php?t=includes/master&p=client.php&clientnumber='+ui.item.name+'&view=edit"> Confirm </a>')
$('#confirmbox').css('display','block')
	}
	});
	})
</script>
<?php break;

case 'edit':
require_once('includes/asset/asset_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);
?>
<script>$('#navBox').html('<a href="index.php?t=includes/master&p=client.php&view=list" class="s1">Client List</a><a href="index.php?t=includes/master&p=client.php&clientnumber=<?= $_REQUEST['clientnumber']?>&view=edit" class="s2">Edit Client</a><a href="javascript:void(0)" class="sa"><?= $cd['clientname']?></a>')</script>

<div class="col-12 col-md-12">
<div class="pull-right"><a id="phone" href="tel:<?= $cd['phone1']?>" class="btn btn-secondary noprint"><i class="fa fa-phone"></i></a> <a href="index.php?t=includes/master&p=client.php&clientnumber=<?= $_REQUEST['clientnumber']?>&view=load" class="btn btn-secondary"><i class="fa fa-id-card-o"></i></a> <a href="#" class="btn btn-secondary"><i class="fa fa-envelope"></i></a> <a href="#" class="btn btn-secondary"><i class="fa fa-archive"></i></a></div>
</div>
<div class="clearfix"></div>
<form id="clientForm" class="form-horizontal">

<div class="row">
<?php
require_once('includes/forms/elements/client_details.frm');
require_once('includes/forms/elements/client_contacts.frm');
require_once('includes/forms/elements/client_additional.frm');
require_once('includes/forms/elements/client_billing.frm');
require_once('includes/forms/elements/client_other.frm');
?>
<input type="hidden" name="clientnumber" value="<?= $_REQUEST['clientnumber']?>">
<input type="hidden" name="FUNCTION" value="update">

<input id="btn_update" type="submit" name="submit" value="Update" style="display:none">
</form>
<?php
require_once('includes/forms/elements/client_image.frm');
?>
</div>
<div class="spacer"></div>

<script>
function setBilling(){
$('#billing_name').val($('#clientname').val())
$('#billing1').val($('#address1').val())
$('#billing2').val($('#address2').val())
$('#billing3').val('')
$('#billing_town').val($('#town').val())
$('#billing_county').val($('#county').val())
$('#billing_postcode').val($('#postcode').val())
	
}

$( document ).ready(function() {
$('#footerControls').html('<button class="btn btn-info" onclick="triggerAction(\'btn_update\')">UPDATE</button>')

})
</script>

<?php
break;

case"load":
$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);?>
<div id="printbox">
<div class="row">
<script>$('#navBox').html('<a href="index.php?t=includes/master&p=client.php&view=list" class="s1">Client List</a><a href="index.php?t=includes/master&p=client.php&clientnumber=<?= $_REQUEST['clientnumber']?>&view=load" class="s2"><?= $cd['clientname']?></a><a href="javascript:void(0)" class="sa">View Client</a>')</script>
<div class="col-12 col-md-12">
<div class="pull-right"><a id="phone" href="tel:<?= $cd['phone1']?>" class="btn btn-secondary noprint"><i class="fa fa-phone"></i></a> <a href="index.php?t=includes/master&p=client.php&clientnumber=<?= $_REQUEST['clientnumber']?>&view=edit" class="btn btn-secondary noprint"><i class="fa fa-gear"></i></a> <a href="#" class="btn btn-secondary noprint"><i class="fa fa-envelope"></i></a> <a id="print" href="#" class="btn btn-secondary noprint"><i class="fa fa-print"></i></a> <a href="#" class="btn btn-secondary noprint"><i class="fa fa-archive"></i></a></div>
</div>
</div>


<div class="col-12 col-md-9">

<div class="col-12 col-md-12">
<div class="card">
<div class="card-header">Client Details</div>
<div class="card-block">
<div class="col-12 col-md-6">
<div class="row"><div class="col-12 col-md-3 title">Clientname</div><div class="col-12 col-md-9"><?= $cd['clientname']?></div></div>
<div class="row"><div class="col-12 col-md-3 title">Address1</div><div class="col-12 col-md-9"><?= $cd['address1']?></div></div>
<div class="row"><div class="col-12 col-md-3 title">Address2</div><div class="col-12 col-md-9"><?= $cd['address2']?></div></div>
<div class="row"><div class="col-12 col-md-3 title">Town</div><div class="col-12 col-md-9"><?= $cd['town']?></div></div>
<div class="row"><div class="col-12 col-md-3 title">County</div><div class="col-12 col-md-9"><?= $cd['county']?></div></div>
<div class="row"><div class="col-12 col-md-3 title">Postcode</div><div class="col-12 col-md-9"><?= $cd['postcode']?></div></div>
</div>
<div class="col-12 col-md-6">
<div class="row"><div class="col-12 col-md-3 title">Phone1</div><div class="col-12 col-md-9"><?= $cd['phone1']?></div></div>
<div class="row"><div class="col-12 col-md-3 title">Phone2</div><div class="col-12 col-md-9"><?= $cd['phone2']?></div></div>
<div class="row"><div class="col-12 col-md-3 title">Mobile</div><div class="col-12 col-md-9"><?= $cd['mobile']?></div></div>
<div class="row"><div class="col-12 col-md-3 title">Fax</div><div class="col-12 col-md-9"><?= $cd['fax']?></div></div>
<div class="row"><div class="col-12 col-md-3 title">Email</div><div class="col-12 col-md-9"><?= $cd['email']?></div></div>
</div>
</div></div></div>

<div class="spacer">&nbsp;</div>

<div class="col-12 col-md-6">
<div class="card">
<div class="card-header">Primary Contact</div>
<div class="card-block">
<div class="row"><div class="col-12 col-md-3 title">Pri Contact Name</div><div class="col-12 col-md-9"><?= $cd['pri_contact_name']?></div></div>
<div class="row"><div class="col-12 col-md-3 title">Pri Contact Position</div><div class="col-12 col-md-9"><?= $cd['pri_contact_position']?></div></div>
<div class="row"><div class="col-12 col-md-3 title">Pri Contact Tel</div><div class="col-12 col-md-9"><?= $cd['pri_contact_tel']?></div></div>
<div class="row"><div class="col-12 col-md-3 title">Pri Contact Mob</div><div class="col-12 col-md-9"><?= $cd['pri_contact_mob']?></div></div>
<div class="row"><div class="col-12 col-md-3 title">Pri Contact Email</div><div class="col-12 col-md-9"><?= $cd['pri_contact_email']?></div></div>
</div></div></div>

<div class="col-12 col-md-6">
<div class="card">
<div class="card-header">Secondary Contact</div>
<div class="card-block">
<div class="row"><div class="col-12 col-md-3 title">Sec Contact Name</div><div class="col-12 col-md-9"><?= $cd['sec_contact_name']?></div></div>
<div class="row"><div class="col-12 col-md-3 title">Sec Contact Position</div><div class="col-12 col-md-9"><?= $cd['sec_contact_position']?></div></div>
<div class="row"><div class="col-12 col-md-3 title">Sec Contact Tel</div><div class="col-12 col-md-9"><?= $cd['sec_contact_tel']?></div></div>
<div class="row"><div class="col-12 col-md-3 title">Sec Contact Mob</div><div class="col-12 col-md-9"><?= $cd['sec_contact_mob']?></div></div>
<div class="row"><div class="col-12 col-md-3 title">Sec Contact Email</div><div class="col-12 col-md-9"><?= $cd['sec_contact_email']?></div></div>
</div></div></div>

<div class="spacer">&nbsp;</div>

<div class="col-12 col-md-12">
<div class="card">
<div class="card-header">Blas</div>
<div class="card-block">
<div class="col-12 col-sm-6 col-md-6">
<div class="row"><div class="col-12 col-md-3 title">Rate Per Hour</div><div class="col-12 col-md-9"><?= $cd['rate_per_hour']?></div></div>
<div class="row"><div class="col-12 col-md-3 title">Vat Rate</div><div class="col-12 col-md-9"><?= $cd['vat_rate']?></div></div>
<div class="row"><div class="col-12 col-md-3 title">Commission</div><div class="col-12 col-md-9"><?= $cd['commission']?></div></div>
<div class="row"><div class="col-12 col-md-3 title">Clientnotes</div><div class="col-12 col-md-9"><?= $cd['clientnotes']?></div></div>
</div>
<div class="col-12 col-sm-6 col-md-6">
<div class="row"><div class="col-12 col-md-3 title">Statuslive</div><div class="col-12 col-md-9"><?= $cd['statuslive']?></div></div>
<div class="row"><div class="col-12 col-md-3 title">Agent Number</div><div class="col-12 col-md-9"><?= $cd['agent_number']?></div></div>
<div class="row"><div class="col-12 col-md-3 title">Account Handler</div><div class="col-12 col-md-9"><?= $cd['account_handler']?></div></div>
<div class="row"><div class="col-12 col-md-3 title">Contract Number</div><div class="col-12 col-md-9"><?= $cd['contract_number']?></div></div>
<div class="row"><div class="col-12 col-md-3 title">Incepton Date</div><div class="col-12 col-md-9"><?= $cd['incepton_date']?></div></div>
<div class="row"><div class="col-12 col-md-3 title">Term Years</div><div class="col-12 col-md-9"><?= $cd['term_years']?></div></div>
</div>
</div></div></div>

<div class="spacer">&nbsp;</div>

<div class="col-12 col-md-6">
<div class="card">
<div class="card-header">Billing Information</div>
<div class="card-block">
<div class="row"><div class="col-12 col-md-3 title">Billing Name</div><div class="col-12 col-md-9"><?= $cd['billing_name']?></div></div>
<div class="row"><div class="col-12 col-md-3 title">Billing1</div><div class="col-12 col-md-9"><?= $cd['billing1']?></div></div>
<div class="row"><div class="col-12 col-md-3 title">Billing2</div><div class="col-12 col-md-9"><?= $cd['billing2']?></div></div>
<div class="row"><div class="col-12 col-md-3 title">Billing3</div><div class="col-12 col-md-9"><?= $cd['billing3']?></div></div>
<div class="row"><div class="col-12 col-md-3 title">Billing Town</div><div class="col-12 col-md-9"><?= $cd['billing_town']?></div></div>
<div class="row"><div class="col-12 col-md-3 title">Billing County</div><div class="col-12 col-md-9"><?= $cd['billing_county']?></div></div>
<div class="row"><div class="col-12 col-md-3 title">Billing Postcode</div><div class="col-12 col-md-9"><?= $cd['billing_postcode']?></div></div>
</div></div></div>

<div class="col-12 col-md-6">
<div class="card">
<div class="card-header">Other</div>
<div class="card-block">
<div class="row"><div class="col-12 col-md-3 title">Renewal Date</div><div class="col-12 col-md-9"><?php $cd['renewal_date']="23-11-2017"; echo $cd['renewal_date']?></div></div>
<div class="row"><div class="col-12 col-md-3 title">Renewal Status</div><div class="col-12 col-md-9"><?= $cd['renewal_status']?></div></div>
<div class="row"><div class="col-12 col-md-3 title">Business Type</div><div class="col-12 col-md-9"><?= $cd['business_type']?></div></div>
</div></div></div>
</div>


<div class="hidden-sm-down col-md-3">
<?php
$stmt = $GLOBALS['con']->prepare("SELECT `locnumber`,`locname` FROM `locations` WHERE `clientnumber`=?")or die(mysqli_error("LOCCOUNT: ".$GLOBALS['con']));
$stmt->bind_param('i',$_REQUEST['clientnumber']);$stmt->execute();$lc=$stmt->get_result();$stmt->close();
$ln=mysqli_num_rows($lc);
$items=0;
while($ld=mysqli_fetch_array($lc)){
$stmt = $GLOBALS['con']->prepare("SELECT `itemnumber`,`desc` FROM `itemdetails` WHERE `locnumber`=?")or die(mysqli_error("ITEMCOUNT: ".$GLOBALS['con']));
$stmt->bind_param('i',$ld['locnumber']);$stmt->execute();$ic=$stmt->get_result();$stmt->close();
$in=mysqli_num_rows($ic);
$items=$items+$in;	
}
$stmt = $GLOBALS['con']->prepare("SELECT locnumber, COUNT(locnumber) AS occurrence FROM itemdetails GROUP BY locnumber")or die(mysqli_error("EXTRA: ".$GLOBALS['con']));
$stmt->execute();$cc=$stmt->get_result();$stmt->close();
while($cdx=mysqli_fetch_array($cc)){
//echo $cd['locnumber']." | ".$cd['occurrence']."<br>";	
}
?>
<div class="card">
<div class="card-header">Details</div>
<div class="card-block">
<ul class="list-group">
<li class="list-group-item"><a class="btn-block" href="index.php?t=includes/master&p=locations.php&clientnumber=<?= $_REQUEST['clientnumber']?>&clientname=<?= $cd['clientname']?>">Locations:<?= $ln?></a></li>
<li class="list-group-item"><a class="btn-block" href="index.php?t=includes/master&p=client.php&clientnumber=<?= $_REQUEST['clientnumber']?>&clientname=<?= $cd['clientname']?>&view=asset">Items: <?= $items?></a></li>
<li class="list-group-item"><a class="btn-block" href="#"><?= checkItemDate($cdx['renewal_date'])?></a></li>
</ul>
</div></div>
</div></div>



<div class="clearfix"></div>

<?php break;

case "list":
if($_REQUEST['filter']=="" || $_REQUEST['filter']=="current"){$filter="WHERE `statuslive`='1'";}
if($_REQUEST['filter']=="archive"){$filter="WHERE `statuslive`='0'";}	
echo $filter;
$stmt = $GLOBALS['con']->prepare("SELECT `clientnumber`,`clientname`,`phone1`,`email`,`pri_contact_name`,`account_handler`,`contract_number` FROM `clientdetails` $filter ORDER BY `clientname` DESC")or die(mysqli_error("LIST: ".$GLOBALS['con']));
$stmt->execute();$cc=$stmt->get_result();$stmt->close();
?>
<div class="row">
<div class="col text-end"><a href="index.php?t=includes/master&p=client.php&view=new" class="btn btn-secondary btn-sm"><i class="fa fa-plus" aria-hidden="true"></i> New Client</a>
<?php if($_REQUEST['filter']=="" || $_REQUEST['filter']=="current"){?>
<script>$('#navBox').html('<a href="javascript:void(0)" class="s1">Client List</a><a href="javascript:void(0)" class="sa">Active Clients</a>')</script>
<a href="index.php?t=includes/master&p=client.php&view=list&filter=archive" class="btn btn-secondary btn-sm">View Archived Clients</a>
<div id="exportTitle" style="display:none">
<p style="font-size:14px; font-weight:bold">EnRep Reporting System</p>
<p style="font-size:12px"><a href="">Client List</a> : <a href="">Active Clients</a></p>
</div>

<?php }
if($_REQUEST['filter']=="archive"){?>
<script>$('#navBox').html('<a href="javascript:void(0)" class="s1">Client List</a><a href="javascript:void(0)" class="sa">Archived Clients</a>')</script>
<a href="index.php?t=includes/master&p=client.php&view=list&filter=current" class="btn btn-secondary btn-sm">View Active Clients</a>
<div id="exportTitle" style="display:none">
<p style="font-size:14px; font-weight:bold">EnRep Reporting System</p>
<p style="font-size:12px"><a href="">Client List</a> : <a href="">Archived Clients</a></p>
</div>

<?php }?>

</div>
</div>
<?php require_once('includes/table.engine');?>
<div class="container">
<table id="datatable" class="table table-striped table-sm table-bordered table-hover responsive" width="100%">
<thead>
<tr><th>Client Number</th><th>Client Name</th><th>Contact Name</th><th>Account Handler</th><th>Phone</th><th>Email</th><th></th></tr>
</thead>
<tbody>

<?php while($cd=mysqli_fetch_array($cc)){?>
<tr><td><?= $cd['clientnumber']?></td><td><?= $cd['clientname']?></td><td><?= $cd['pri_contact_name']?></td><td><?= $cd['account_handler']?></td><td><?= $cd['phone1']?></td><td><?= $cd['email']?></td>
<td>
<div class="btn-group" role="group">
<a href="index.php?t=includes/master&p=client.php&clientnumber=<?= $cd['clientnumber']?>&view=asset" class="btn btn-secondary noprint"><i class="fa fa-th-list"></i></a>
<?php if($cd['phone1']!=""){?><a id="phone" href="tel:<?= $cd['phone1']?>" class="btn btn-secondary noprint"><i class="fa fa-phone"></i></a><?php }?>
<?php if(!filter_var($cd['email'], FILTER_VALIDATE_EMAIL) === false) {?><a href="#" class="btn btn-secondary noprint emailButton" data-values="<?= $cd['clientnumber']?>|<?= $cd['pri_contact_name']?>|<?= $cd['email']?>|<?= $cd['clientname']?>" data-href="includes/master/mailer.php"><i class="fa fa-envelope"></i></a><?php }?>
<a href="index.php?t=includes/master&p=client.php&clientnumber=<?= $cd['clientnumber']?>&view=load" class="btn btn-secondary noprint"><i class="fa fa-id-card-o"></i></a>
</div>
</td>
</tr>
<?php }?>
</tbody>
</table>
<div class="clearfix"></div>
</div>

<script>
$(".emailButton").click(function(){
var target = $(this).data('href');
var string = $(this).data('values');
var dest=encodeURI(target+"?data="+string)
$('#popupBox').modal('show');
$('#popupBox .modal-body').load(dest);
})
</script>


<?php break;

case "asset":
require_once('includes/master/form_functions.php');
if($_REQUEST['filter']=="" || $_REQUEST['filter']=="current"){$filter="AND `statuslive`='1'";}
if($_REQUEST['filter']=="archive"){$filter="AND `statuslive`='0'";}	
$stmt = $GLOBALS['con']->prepare("SELECT `locnumber`,`locname` FROM `locations` WHERE `clientnumber`=? ")or die(mysqli_error("GETASSET: ".$GLOBALS['con']));
$stmt->bind_param('i',$_REQUEST['clientnumber']);$stmt->execute();$lc=$stmt->get_result();$stmt->close();
$sites=getsites($_REQUEST['clientnumber']);
if($_REQUEST['site']!=""){$filterSite=" AND `locnumber`='".$_REQUEST['site']."'";}
?>
<div class="row">
<div class="col-md-2 pull-left"><?= $sites;?></div>
<div class="col text-end">
<?php if($_REQUEST['filter']=="" || $_REQUEST['filter']=="current"){?>
<div id="exportTitle" style="display:none">
<p style="font-size:14px; font-weight:bold">EnRep Reporting System</p>
<p style="font-size:12px"><a href="">Client List</a> : <a href=""><?= getClientName($_REQUEST['clientnumber'])?></a> : <a href="" >Schedule</a> : <a href="">Active Items</a></p>
</div>

<a href="javascript:void(0)" class="btn btn-secondary btn-sm formButton" data-values="<?= $_REQUEST['clientnumber']?>|<?= $ld['locnumber']?>|<?= $id['itemnumber']?>" data-href="includes/master/formnew.php"><i class="fa fa-plus" aria-hidden="true"></i> New Asset</a>
<a href="index.php?t=includes/master&p=client.php&clientnumber=<?= $_REQUEST['clientnumber']?>&view=asset&filter=archive" class="btn btn-secondary btn-sm">View Archived Items</a>
<script>
$('#navBox').html('<a href="index.php?t=includes/master&p=client.php&view=list" class="s1">Client List</a><a href="index.php?t=includes/master&p=client.php&clientnumber=<?= $_REQUEST['clientnumber']?>&view=load" class="s2"><?= getClientName($_REQUEST['clientnumber'])?></a><a href="javascript:void(0)" class="s3">Schedule</a><a href="javascript:void(0)" class="sa">Active Items</a>');
</script>
<?php }
if($_REQUEST['filter']=="archive"){?>
<div id="exportTitle" style="display:none">
<p style="font-size:14px; font-weight:bold">EnRep Reporting System</p>
<p style="font-size:12px"><a href="">Client List</a> : <a href=""><?= getClientName($_REQUEST['clientnumber'])?></a> : <a href="" >Schedule</a> : <a href="">Archived Items</a></p>
</div>

<a href="index.php?t=includes/master&p=client.php&clientnumber=<?= $_REQUEST['clientnumber']?>&view=asset&filter=current" class="btn btn-secondary btn-sm">View Active Items</a>
<script>
$('#navBox').html('<a href="index.php?t=includes/master&p=client.php&view=list" class="s1">Client List</a><a href="index.php?t=includes/master&p=client.php&clientnumber=<?= $_REQUEST['clientnumber']?>&view=load" class="s2"><?= getClientName($_REQUEST['clientnumber'])?></a><a href="javascript:void(0)" class="s3">Schedule</a><a href="javascript:void(0)" class="sa">Archvied Items</a>');
</script>
<?php }?>
</div>
</div>
<div class="container">
<table id="datatable" class="table table-striped table-sm table-bordered table-hover responsive" width="100%">
<thead>
<tr><th class="no-sort"></th><th>Item ID</th><th>Description</th><th>Plant Number</th><th>Serial Number</th><th>Location</th><th>Due Date</th><th></th></tr>
</thead>
<tbody>
<?php while($ld=mysqli_fetch_array($lc)){
$stmt = $GLOBALS['con']->prepare("SELECT `itemnumber`,`desc`, `plantnumber`,`serialnumber`,`duedate` FROM `itemdetails` WHERE `locnumber`=? $filter $filterSite")or die(mysqli_error("GETASSET: ".$GLOBALS['con']));
$stmt->bind_param('i',$ld['locnumber']);$stmt->execute();$ic=$stmt->get_result();$stmt->close();
while($id=mysqli_fetch_array($ic)){
	
if($id['duedate']<strtotime('now')){$stat="color bg-red";$statTitle="Overdue";}
if($id['duedate']>strtotime('now') && $id['duedate']<strtotime('now +1 month')){$stat="color bg-orange";$statTitle="Pending";}
if($id['duedate']>strtotime('now +1 month')){$stat="color bg-green";$statTitle="Not Due";}
?>
<tr>
<td class="status_colour"><div class="<?= $stat?>" title="<?= $statTitle?>" style="font-size:0px"><?= $statTitle?></div></td>
<td><?= $id['itemnumber']?></td><td><?= $id['desc']?></td><td><?= $id['plantnumber']?></td><td><?= $id['serialnumber']?></td>
<td><?= getItemLocation($id['itemnumber'],'name')?></td>
<td class="prod_color"><?php if(empty($id['duedate'])){echo "No date stored";}else{echo date('d-m-Y',$id['duedate']);}?></td>
<td class="text-center">
<div class="btn-group" role="group">
<a href="javascript:void(0)" class="btn btn-secondary noprint formButton" data-values="<?= $_REQUEST['clientnumber']?>|<?= $ld['locnumber']?>|<?= $id['itemnumber']?>" data-href="includes/master/form.php"><i class="fa fa-file-text-o" aria-hidden="true"></i></a>

<a href="index.php?t=includes/master&p=items.php&data=<?= $_REQUEST['clientnumber']?>|<?= $ld['locnumber']?>|<?= $id['itemnumber']?>&view=list" class="btn btn-secondary noprint filesButton" data-values="<?= $_REQUEST['clientnumber']?>|<?= $ld['locnumber']?>|<?= $id['itemnumber']?>" data-href="includes/master/files.php"><i class="fa fa-files-o" aria-hidden="true"></i></a>

<a href="javascript:void(0)" class="btn btn-secondary noprint transferButton" data-values="<?= $_REQUEST['clientnumber']?>|<?= $ld['locnumber']?>|<?= $id['itemnumber']?>" data-href="includes/master/transfer.php"><i class="fa fa-exchange" aria-hidden="true"></i></a>

<?php if($_REQUEST['filter']=="" || $_REQUEST['filter']=="current"){?>
<a href="javascript:void(0)" class="btn btn-secondary noprint archiveButton" data-values="<?= $_REQUEST['clientnumber']?>|<?= $id['locnumber']?>|<?= $id['itemnumber']?>|archive" data-href="includes/master/archive.php"><i class="fa fa-archive" aria-hidden="true"></i></a>
<?php }?>
<?php if($_REQUEST['filter']=="archive"){?>
<a href="javascript:void(0)" class="btn btn-secondary noprint archiveButton" data-values="<?= $_REQUEST['clientnumber']?>|<?= $id['locnumber']?>|<?= $id['itemnumber']?>|activate" data-href="includes/master/archive.php"><i class="fa fa-upload" aria-hidden="true"></i></a>
<?php }?>

<a href="index.php?t=includes/master&p=asset.php&view=edit_attached&data=<?= $_REQUEST['clientnumber']?>|<?= $ld['locnumber']?>|<?= $id['itemnumber']?>" class="btn btn-secondary noprint" ><i class="fa fa-cog" aria-hidden="true"></i></i></a>
</div>
</td>
</tr>

<?php }}?>
</tbody>
</table>
<div class="clearfix"></div>
<div class="row">
<div class="col-md-6">
<div class="btn-group" role="group" aria-label="filters">
<button type="button"  class="btn color bg-red filterButtons" onClick="addSearch('Overdue',0)">&nbsp;Overdue&nbsp;</button> <button type="button"  class="btn color bg-orange filterButtons" onClick="addSearch('Pending',0)">&nbsp;Pending&nbsp;</button> <button type="button"  class="btn color bg-green filterButtons" onClick="addSearch('Not Due',0)">&nbsp;Not Due&nbsp;</button> <button type="button"  class="btn color bg-white filterButtons" onClick="clearSearch()">&nbsp;<i class="fa fa-refresh" aria-hidden="true"></i> Reset Filters&nbsp;</button>
</div>
</div>
</div>

<script>
$(".formButton,.transferButton,.archiveButton").click(function(){
var target = $(this).data('href');
var string = $(this).data('values');
var dest=encodeURI(target+"?data="+string)
$('#popupBox').modal('show');
$('#popupBox .modal-body').load(dest);
})
$( document ).ready(function() {
$('#siteList').select2()
})

$("#siteList").select2().change(function(){
var table = $('#datatable').dataTable().api();
var n=$('#siteList option:selected').val();
if($.trim(n)=="reset"){
clearSearch(n)
}
else{
drawSearch(n,5)
}
})



</script>
<?php require_once('includes/table.engine');?>

<?php break;
}?>

<script src="src/js/printer.js"></script>
<script>


$("#clientForm input[type='submit']").click(function(event){
event.preventDefault();
$.ajax({
url:'includes/client/client_functions.php',
type:'POST',
data:$('#clientForm').serialize(),
success:function(result){
if($.trim(result)=="success"){
$('#response').html('<div class="alert alert-success text-center"><p>Your changes have been saved successfully</p></div>')	
$('#response').delay(3000).fadeOut(1000, function(){
$('#response').html('')
$('#response').fadeIn('slow');
});
}
else{
window.location.href='index.php?t=includes/master&p=client.php&clientnumber='+result+'&view=edit'
}
}
});
});


$( document ).ready(function() {
$('#datatable_filter input').addClass('form-control form-control-sm');
$('#datatable_length select').addClass('form-control form-control-sm');
})


</script>
<div class="clearfix"></div>
