<?php defined('BASEPATH') or exit('No direct script access allowed'); ?>
<?php init_head(); ?>
<div id="wrapper">
    <div class="content">
        <div class="row">
            <div class="col-md-3">
                <div class="pc-card-stat">
                    <h3><?php echo (int)$stats['total_projects']; ?></h3>
                    <p>Total Projects</p>
                </div>
            </div>
            <div class="col-md-3">
                <div class="pc-card-stat">
                    <h3><?php echo (int)$stats['pending_finance']; ?></h3>
                    <p>Pending Finance Review</p>
                </div>
            </div>
            <div class="col-md-3">
                <div class="pc-card-stat">
                    <h3><?php echo (int)$stats['pending_hod']; ?></h3>
                    <p>Pending HOD Approval</p>
                </div>
            </div>
            <div class="col-md-3">
                <div class="pc-card-stat">
                    <h3><?php echo (int)$stats['approved_projects']; ?></h3>
                    <p>Approved Projects</p>
                </div>
            </div>
        </div>

        <div class="panel_s">
            <div class="panel-body">
                <h4 class="no-margin"><?php echo _l('project_costing_dashboard'); ?></h4>
                <hr class="hr-panel-heading" />

               <div class="table-responsive">
    <table class="table table-bordered table-striped">
        <thead>
            <tr>
                <th>#</th>
                <th>Proposal Name</th>
                <th>Client</th>
                <th>Client Category</th>
                <th>Engagement Type</th>
                <th>Mode</th>
                <th>Submitted By</th>
                <th>Finance Reviewer</th>
                <th>HOD Approver</th>
                <th>Overall Status</th>
                <th>Total</th>
                <th>Date Created</th>
                <th width="140">Action</th>
            </tr>
        </thead>
        <tbody>
            <?php if (!empty($projects)) { ?>
                <?php foreach ($projects as $project) { ?>
                    <tr>
                        <td><?php echo $project['id']; ?></td>
                        <td><?php echo html_escape($project['proposal_name']); ?></td>
                        <td><?php echo html_escape($project['client_name']); ?></td>
                        <td><?php echo html_escape($project['client_category_name']); ?></td>
                        <td><?php echo html_escape($project['engagement_type_name']); ?></td>
                        <td><?php echo html_escape($project['engagement_mode']); ?></td>
                        <td><?php echo html_escape(trim(($project['submitter_firstname'] ?? '') . ' ' . ($project['submitter_lastname'] ?? ''))); ?></td>
                        <td><?php echo html_escape(trim(($project['finance_firstname'] ?? '') . ' ' . ($project['finance_lastname'] ?? ''))); ?></td>
                        <td><?php echo html_escape(trim(($project['hod_firstname'] ?? '') . ' ' . ($project['hod_lastname'] ?? ''))); ?></td>
                        <td>
                            <span class="label label-<?php echo $project['overall_status'] == 'approved' ? 'success' : ($project['overall_status'] == 'rejected' ? 'danger' : 'warning'); ?>">
                                <?php echo ucfirst($project['overall_status']); ?>
                            </span>
                        </td>
                        <td>RM <?php echo number_format((float)$project['overall_total'], 2); ?></td>
                        <td><?php echo _dt($project['datecreated']); ?></td>
                        <td>
                            <a href="<?php echo admin_url('project_costing/project_costing/view/' . $project['id']); ?>" class="btn btn-default btn-icon"><i class="fa fa-eye"></i></a>
                            <a href="<?php echo admin_url('project_costing/project_costing/edit/' . $project['id']); ?>" class="btn btn-primary btn-icon"><i class="fa fa-pencil"></i></a>
                            <a href="<?php echo admin_url('project_costing/project_costing_admin/delete_project/' . $project['id']); ?>" class="btn btn-danger btn-icon _delete"><i class="fa fa-remove"></i></a>
                        </td>
                    </tr>
                <?php } ?>
            <?php } else { ?>
                <tr>
                    <td colspan="13" class="text-center">No costing records found yet.</td>
                </tr>
            <?php } ?>
        </tbody>
    </table>
</div>

            </div>
        </div>
    </div>
</div>
<?php init_tail(); ?>