<?php $stmt = $GLOBALS['con']->prepare("SELECT `clientnumber`,`clientname`,`address1`,`address2`,`town`,`county`,`postcode` FROM `clientdetails` WHERE `contractor`='".$_REQUEST['contractor_number']."' AND `statuslive`='1'")or
die(mysqli_error($GLOBALS['con']));
$stmt->execute();$cc=$stmt->get_result();$stmt->close();
?>
<script>
$('#navBox').html(
    '<li class="breadcrumb-item"><a href="index.php?t=includes/master&p=contractor.php&view=list">Contractors</a><i class="fad fa-angle-double-right mx-2 mt-1" aria-hidden="true"></i></li><li class="breadcrumb-item active">Contractor List</li>'
)
</script>
<div class="row mb-4">
    <div class="col col-md-6 note note-secondary">
        Contractor Assignments: <small class="muted">Manage assignments of your contractors.</small>
    </div>
    <div class="col col-md-6 text-end">
        <!--<a href="index.php?t=includes/master&p=contractor.php&contractor_number=<?=$_REQUEST['contractor_number']?>&view=assign" class="btn btn-secondary btn-sm"><i class="fad fa-plus" aria-hidden="true"></i> Assign Contractor</a>-->
        <a href="index.php?t=includes/master&p=contractor.php&contractor_number=<?=$_REQUEST['contractor_number']?>&view=edit" class="btn btn-secondary btn-sm">Contractor Details</a>
    </div>
</div>
<div class="row">
    <div class="col text-end">

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

    </div>
</div>


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

<table id="datatable" class="table table-striped table-sm table-bordered table-hover 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>

<?php 
$table="datatable";
        $dateTarget="5";        
        $length="25";
        $sortTarget="1";
        $sortCell="";
        $logo="yes";
        $scroller="";
        $printTarget='exportDiv';
        $printHeader='Outstanding Payments';
        $popup="false";
 require(ROOT_URL.'/includes/tables/single_table.php');?>