<?php

include "../../classes/autoload.php";

$html = new html("JOB CARDS");
$app = new inner_app();
$app->quick_bar("/app/job_cards");
$app->app_start();
$app_functions = new app_features();

$table = new table("job_cards");

exit;

?>
<table>
    <thead>
        <tr>
            <th>DATE REQUIRED</th>
            <th>J.C. NO</th>
            <th>COMPANY</th>
            <th>PROJECT</th>
            <th>COSTING</th>
            <th>PROGRESS</th>
            <th>Q. AM.</th>
            <th>ORIGINATOR</th>
            <th>ACTION</th>
            <th>DOC.</th>
            <th>FILES</th>
        </tr>
    </thead>
    <tbody>
        <?php
        $res = $db->query("job_cards", "SELECT * FROM job_cards ORDER BY record_id DESC");
        while ($row = $res->fetch_assoc()) {
            ?>
            <tr>
                <td><?php echo $row['date_required']; ?></td>
                <td><?php echo $row['job_card_no']; ?></td>
                <td><?php echo $row['company_name']; ?></td>
                <td><?php echo $row['project_name']; ?></td>
                <td>R <?php echo number_format((float) $row['costing'], 2); ?></td>
                <td>
                 
                </td>
                <td>R <?php echo number_format((float) $row['quote_amount'], 2); ?></td>
                <td><?php echo $app_functions->get_username($row['rep_originator']); ?></td>
                <td><button
                        onclick="window.location.href ='edit_job_cards.php?record_id=<?php echo $row['record_id']; ?>'">OPEN</button>
                </td>
                <td><button
                        onclick="open_iframe('job_card.pdf.php?record_id=<?php echo $row['record_id']; ?>')">PDF</button>
                </td>
                <td>
                    <?php
                    // job card attachemnt accounts
                    $attachments = $db->query("job_card_attachments", "SELECT * FROM job_card_attachments WHERE job_card_id = " . $row['record_id']);
                    if ($attachments->num_rows > 0) {

                        ?>
                        <div onclick="open_iframe('job_card_attachments.php?record_id=<?php echo $row['record_id']; ?>')">
                            <?php
                            echo $attachments->num_rows;
                            ?>
                            <i class="fa fa-paperclip" aria-hidden="true"></i>
                        </div>
                    <?php } else { ?>
                        <?php
                        echo $attachments->num_rows;
                        ?>
                        <i class="fa fa-paperclip" aria-hidden="true"></i>
                    <?php } ?>
                </td>
            </tr>
            <?php

        }
        ?>

    </tbody>
</table>
<!-- <div class="iframe_background" id="iframe_bg" style="display: none;"></div>
<iframe class="popup_iframe" id='iframe_popup' src="job_card_attachments.php" style="display: none;"></iframe>
<i class="fa fa-times-circle iframe_close" id='iframe_close' style="display: none;" onclick="close_iframe()"></i>
<script>
    function open_iframe(url) {
        document.querySelector(".popup_iframe").style.display = "block";
        document.querySelector(".iframe_close").style.display = "block";
        document.querySelector(".iframe_background").style.display = "block";
        document.querySelector(".popup_iframe").src = url;
    }
    function close_iframe() {
        document.querySelector(".popup_iframe").style.display = "none";
        document.querySelector(".iframe_close").style.display = "none";
        document.querySelector(".iframe_background").style.display = "none";


    }
</script> -->


<?php

$iframe_popup = new iframe_popup();
// $app->app_end();