<?php
$this->load->view('report_pdf/pdf_header');
$this->load->helper('report');
$show_title = !isset($show_title) ? true : (bool) $show_title;
$start_price = isset($start_price) ? $start_price : '';
$end_price = isset($end_price) ? $end_price : '';
$itype_label = isset($itype_label) ? $itype_label : (isset($itype) ? $itype : 'All');
$row_limit = isset($row_limit) ? $row_limit : '';
$cost_total = isset($cost_total) ? (float) $cost_total : 0;
$report = isset($report) ? $report : array();
$columns = isset($columns) && is_array($columns) && !empty($columns)
    ? $columns
    : report_catalogue_columns('book');
?>

<?php if ($show_title) { ?>
<style>
    @page { margin: 22px 18px 36px 18px; }
</style>
<p style="text-align:center;font-size:14px;margin:5px 0;">
    <b>Price Range Report</b>
</p>

<p style="text-align:right;font-size:13px;margin:5px 0;">
    Date: <?php echo date("d/m/Y", strtotime($today)); ?>
</p>

<p style="text-align:left;font-size:13px;margin:5px 0;">
    Total Records : <?php echo report_pdf_total_rows($report, isset($pdf_total_rows) ? $pdf_total_rows : null); ?>
    &nbsp;&nbsp;|&nbsp;&nbsp;
    Total Cost : <b><?php echo number_format($cost_total, 2); ?></b>
</p>
<br><br>
<?php } ?>

<div id="content">
<table style="border-collapse: collapse;width:100%;table-layout:fixed;text-align:left;" border="1" class="table">
    <tr>
        <?php foreach ($columns as $label => $key) { ?>
        <th><?php echo htmlspecialchars($label); ?></th>
        <?php } ?>
    </tr>
    <?php foreach ($report as $row) {
        $title_val = (string) report_cell($row, 'Title');
        $is_total = (strcasecmp(trim($title_val), 'TOTAL') === 0);
        $cell_style = $is_total ? 'font-weight:bold;' : '';
        ?>
        <tr<?php echo $is_total ? ' style="font-weight:bold;background:#f3f3f3;"' : ''; ?>>
            <?php foreach ($columns as $label => $key) { ?>
            <td style="<?php echo $cell_style; ?>"><?php echo htmlspecialchars((string) report_cell($row, $key)); ?></td>
            <?php } ?>
        </tr>
    <?php } ?>
</table>
</div>
