<div class="row">
    <div class="col-12 col-md-6">
        <p class="blockquote">You have <span id="counter"></span> Reports outstanding for delivery.<br><span class="small">You can choose to deliver the documents individually or as a batch using the main delivery system.</span></p>

    </div>
    <?php $_SESSION['contractorNumber'];if(empty($_SESSION['contractorNumber'])){?>
    <div class="col-12 col-md-6">
        <a class="btn btn-secondary float-end" href="javascript:void(0)" onClick="deliverAll()"><i class="fad fa-share-square"></i> Deliver all outstanding reports to <?= getClientName($_REQUEST['clientnumber'],'name')?></a>
    </div>
    <?php }?>
</div>

<div class="col-12 text-center">
    <div id="loadingObject">
        <h1 class="text-center"><i class="fad fa-cog fa-spin fa-3x fa-fw" style="--fa-primary-color: #0055A6; --fa-secondary-color: gray;"></i></h1>
        <h1>Loading Reports <br><small>Please wait</small></h1>
    </div>
</div>
<div id="exportTitle" style="display: none">Reports Outstanding - <?= getClientName($_REQUEST['clientnumber'],'name')?> - <?= date('d-m-Y')?></div>
<div class="col-md-12">

    <table id="datatable" class="table table-striped" style="display: none; width:100%">
        <thead>
            <tr>
                <th class="no-sort p-0" width="5px" style="max-width:5px"></th>
                <th>Item ID</th>
                <th>Report ID</th>
                <th>Client Name</th>
                <th>Item Descrition</th>
                <th>Plant Number</th>
                <th>Serial Number</th>
                <th>Location</th>
                <th>Date of Examination</th>
                <th class="no-sort"></th>
                <th class="no-sort p-0" width="5px" style="max-width:5px"></th>
            </tr>
        </thead>
        <tbody>
            <?php
unset($_SESSION['itemlist']);
$stmt = $GLOBALS['con']->prepare("SELECT
a.clientnumber,
a.repitem,
a.repnumber,
a.itemnumber,
a.delivery,
a.insdate,
a.result,
a.reptype,
b.clientnumber,
b.clientname,
b.statuslive
FROM reportitems a JOIN clientdetails b ON a.clientnumber=b.clientnumber
WHERE a.delivery='0' AND a.clientnumber='".$_REQUEST['clientnumber']."'")or die(mysqli_error($GLOBALS['con']));
$stmt->execute();$items=$stmt->get_result();$stmt->close();
$itemCount=0;
while($list=mysqli_fetch_array($items)){
    if($id['duedate']<strtotime('now')){$stat="status_colour color danger-color-dark";$statTitle="Overdue";}
    if($id['duedate']>strtotime('now') && $id['duedate']<strtotime('now +1 month')){$stat="status_colour color warning-color-dark";$statTitle="Pending";}
    if($id['duedate']>strtotime('now +1 month')){$stat="status_colour color success-color-dark";$statTitle="Not_Due"; $statFTitle="Not Due";}
?>
            <tr id="R<?= $list['repitem']?>">
                <td class="<?= $stat?> p-0" width="5px" style="max-width:5px">
                    <div class="<?= $stat?>" style="font-size:0px"><?= $list['itemnumber']?></div>
                </td>
                <td><?= $list['itemnumber']?></td>
                <td><?= $list['repnumber']?></td>
                <td><?= getClientName($_REQUEST['clientnumber'],'name')?></td>
                <td><?= getItemDetails($list['itemnumber'],'name')?></td>
                <td><?= getItemPlant($list['itemnumber'],'name')?></td>
                <td><?= getItemSerial($list['itemnumber'],'name')?></td>
                <td><?= getItemLocation($list['itemnumber'],'name')?></td>
                <td><?= date('d-m-Y',$list['insdate'])?></td>
                <td class="text-end">
                    <a href="index.php?t=includes/master&amp;p=items.php&amp;view=view&amp;repnumber=<?= $list['repnumber']?>&amp;path=outstanding&amp;data=<?= $_REQUEST['clientnumber']?>|19|<?= $list['itemnumber'] ?>"
                       class="btn btn-secondary" data-mdb-tooltip-init data-mdb-placement="bottom" data-mdb-trigger="hover" data-mtitle title="" title="View  Report"><i class="fad fa-eye"></i></a>
                    <a href="index.php?t=includes/master&amp;p=formgen.php&amp;mode=reload&amp;formnumber=<?= $list['reptype']?>&amp;repnumber=<?= $list['repnumber']?>&amp;data=<?= $list['clientnumber']?>|19|<?= $list['itemnumber'] ?>&amp;path=outstanding&amp;savemode=edit"
                       class="btn btn-secondary" data-mdb-tooltip-init data-mdb-placement="bottom" data-mdb-trigger="hover" data-mtitle title="" title="Edit  Report"><i class="fad fa-pencil"></i></a>
                    <!--<a class="btn btn-secondary" href="javascript:void(0)">E</a>
<a class="btn btn-secondary" href="javascript:void(0)">S</a>-->
                </td>
                <td class="<?= $stat?> p-0" width="5px" style="max-width:5px">
                    <div class="<?= $stat?>" style="font-size:0px"><?= $list['itemnumber']?></div>
                </td>
            </tr>
            <?php 
$itemlist[]=$list['repitem'];
$counter++;
}?>
        </tbody>
    </table>
</div>

<?php 
 $_SESSION['returnLanding']='index.php?t=includes/master/&p=reports_outstanding.php&clientnumber='.$_REQUEST['clientnumber'];
$_SESSION['items']=$itemlist;
$table="datatable";
require_once(ROOT_URL.'/includes/tables/single_table.php');?>
<script>
$('#counter').text('<?= $counter?>')

$('#navBox').html(
    '<li class="breadcrumb-item"><a href="index.php?t=includes/master&p=client.php&view=list">Clients</a><i class="fad fa-angle-double-right mx-2 mt-1"" aria-hidden="true"></i></li><li class="breadcrumb-item"><a href="index.php?t=includes/master&p=client.php&clientnumber=<?= $_REQUEST['clientnumber']?>&view=asset"><?= getClientName($_REQUEST['clientnumber'])?></a><i class="fad fa-angle-double-right mx-2 mt-1"" aria-hidden="true"></i></li><li class="breadcrumb-item active">Undelivered Reports</li>'
)

function deliverAll() {
    window.location.href = 'index.php?t=includes/master&p=delivery.php&clientnumber=<?= $_REQUEST['clientnumber']?>&items=session'

}
</script>