<?php $stmt = $GLOBALS['con']->prepare("SELECT `clientnumber`,`clientname`,`address1`,`address2`,`town`,`county`,`postcode` FROM `clientdetails` WHERE `broker_number`='".$_REQUEST['broker_number']."' AND `statuslive`='1'")or
die(mysqli_error($GLOBALS['con']));
$stmt->execute();$cc=$stmt->get_result();$stmt->close();
?>

<div class="row mb-3">
    <div class="note note-secondary mb-3">
        <strong>Broker Client List:</strong> Clients that has been setup as agent managed and attributed to <?= $_REQUEST['agent_name']?>
    </div>


    <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="">Broker Client List</a> : <?= $_REQUEST['broker_name']?></p>
    </div>

</div>


<style>
#datatable>tbody>tr>td {
    vertical-align: middle
}
</style>

<div class="row">
    <div class="col-12">
        <table id="datatable" class="table table-striped table-sm table-bordered table-hover table-responsive" width="100%">
            <thead class="table-dark">
                <tr>
                    <th>Due Date</th>
                    <th>Client Name</th>
                    <th>Address 1</th>
                    <th>Address 2</th>
                    <th>Town</th>
                    <th>County</th>
                    <th>Post Code</th>
                </tr>
            </thead>
            <tbody>
                <?php while($cd=mysqli_fetch_array($cc)){
$stmt2 = $GLOBALS['con']->prepare("SELECT `duedate` FROM `itemdetails` WHERE `clientnumber`='".$cd['clientnumber']."' AND `statuslive`='1' AND `duedate`!='' ORDER BY abs(duedate) DESC LIMIT 1")or die(mysqli_error($GLOBALS['con']));
$stmt2->execute();$ics=$stmt2->get_result();$stmt2->close();
$lid=mysqli_fetch_array($ics);
?>
                <tr>
                    <td><?php if($lid['duedate']!=""){?><span style="display:none"><?= date('Y-m-d',$lid['duedate'])?></span><?= date('d-m-Y',$lid['duedate']); }?></td>
                    <td><?= $cd['clientname']?></td>
                    <td><?= $cd['address1']?></td>
                    <td><?= $cd['address2']?></td>
                    <td><?= $cd['town']?></td>
                    <td><?= $cd['county']?></td>
                    <td><?= $cd['postcode']?></td>
                </tr>
                <?php }?>
            </tbody>
        </table>
    </div>
</div>
<script>
document.getElementById('navBox').innerHTML =
    '<li class="breadcrumb-item"><a href="index.php?t=includes/master&p=broker.php&view=list">Brokers</a><i class="fad fa-angle-double-right mx-2 mt-1"" aria-hidden="true"></i></li><li class="breadcrumb-item active">Client List</li>';
</script>

<?php 
$table="datatable";

$dateTarget="";
$sortTarget="1";
$length="25";
$sortCell="nth-child(2)";
$logo="yes";
$scroller="";
require (ROOT_URL."/includes/tables/single_table.php");
?>