<?php if(file_exists('../../../'.$_REQUEST['tenant'].'/config.php')){require_once('../../../'.$_REQUEST['tenant'].'/config.php'); }
if(file_exists('/config.php')){require_once('/config.php'); }


?>

<table id="dataTable" class="dt-print-table table table-striped table-sm table-bordered table-hover responsive" width="100%" style="width:100%;">
    <thead>
        <tr>
            <th>Company Name</th>
            <th>Reports Outstanding</th>
            <th>View</th>
        </tr>
    </thead>
    <tbody>
        <?php
                    // Prepare and execute the query for reports not sent
                    $stmt = $GLOBALS['con']->prepare("
                        SELECT COUNT(a.repitem) AS count,
                               a.clientnumber,
                               b.clientname,
                               b.contractor
                        FROM reportitems a
                        JOIN clientdetails b ON a.clientnumber = b.clientnumber
                        WHERE a.delivery = '0'
                        GROUP BY a.clientnumber
                        ORDER BY b.clientname ASC
                    ");
                    $stmt->execute();
                    $items = $stmt->get_result();
                    $stmt->close();

                    while ($idata = $items->fetch_assoc()) {
                        if (empty($_SESSION['contractorNumber']) || $idata['contractor'] == $_SESSION['contractorNumber']) {
                            $clientName = htmlspecialchars(preg_replace("/[^a-zA-Z]/", " ", $idata['clientname']));
                            $clientNumber = htmlspecialchars($idata['clientnumber']);
                            echo "<tr id='R$clientNumber'>";
                            echo "<th>$clientName</th>";
                            echo "<td>{$idata['count']}</td>";
                            echo "<td><a href='index.php?t=includes/master/&p=reports_outstanding.php&clientnumber=$clientNumber' class='btn btn-secondary m-0 px-3 py-2 waves-effect float-end' data-mdb-tooltip-init data-mdb-placement='bottom' title='View Reports'><i class='fad fa-eye'></i></a></td>";
                            echo "</tr>";
                        }
                    }
                    ?>
    </tbody>
</table>
<?php  
$table="dataTable";
$dateTarget="8";
$sortTarget="1";
$length="25";
$sortCell="nth-child(2)";
$logo="no";
$scroller="";

?>
<?php require_once("../tables/single_table.php");?>