<?php 
$total_order = 0;
$total_booked = 0;
$total_intransit = 0;
$total_fad = 0;
$total_rad = 0;
$total_rto = 0;
?>
<table class="table listTable table-bordered">
    <thead style="position:sticky;top:-1px">
        <tr>
            <th class="text-center">S.N.</th>
            <th class="text-left"><?php echo $type_title ?></th>
            <th class="text-end">Total Orders</th>
            <th class="text-end">Booked</th>
            <th class="text-end">In Transit</th>
            <th class="text-end">FAD</th>
            <th class="text-end">RAD</th>
            <th class="text-end">RTO</th>
        </tr>
    </thead>
    <tbody>
        <?php 
            if(!empty($records)) {
                $sn = 1;
                foreach($records as $row) {
                    $total_order += (int) $row['Total_Orders'];
                    $total_booked += (int) $row['Booked'];
                    $total_intransit += (int) $row['In_transit'];
                    $total_fad += (int) $row['FAD'];
                    $total_rad += (int) $row['RAD'];
                    $total_rto += (int) $row['RTO'];
                    echo "<tr>";
                    echo "<td class='text-center'>" . $sn++ . "</td>";
                    echo "<td class='text-left'>" . $row[$type_key] . "</td>";
                    echo "<td class='text-end'>" . $row['Total_Orders'] . "</td>";
                    echo "<td class='text-end'>" . $row['Booked'] . "</td>";
                    echo "<td class='text-end'>" . $row['In_transit'] . "</td>";
                    echo "<td class='text-end'>" . $row['FAD'] . "</td>";
                    echo "<td class='text-end'>" . $row['RAD'] . "</td>";
                    echo "<td class='text-end'>" . $row['RTO'] . "</td>";
                    echo "</tr>";
                }
            } else {
                echo "<tr><td colspan='8'>No data available</td></tr>";
            }
        ?>
    </tbody>
    <?php if(!empty($records)) { ?>
    <tfoot>
        <tr>
            <th colspan="2" class="text-center">Total</th>
            <th class="text-end"><?php echo $total_order; ?></th>
            <th class="text-end"><?php echo $total_booked; ?></th>
            <th class="text-end"><?php echo $total_intransit; ?></th>
            <th class="text-end"><?php echo $total_fad; ?></th>
            <th class="text-end"><?php echo $total_rad; ?></th>
            <th class="text-end"><?php echo $total_rto; ?></th>
        </tr>
    </tfoot>
    <?php } ?>
</table>