<?= $this->extend('layouts/owner') ?>

<?= $this->section('content') ?>

<div class="container-fluid">

    <div class="row mb-3">

        <div class="col-md-6">

            <h3>

                <i class="fas fa-industry"></i>

                Produksi

            </h3>

        </div>

        <div class="col-md-6 text-end">

            <a href="<?= base_url('owner/production/history') ?>"
               class="btn btn-secondary">

                <i class="fas fa-history"></i>

                History

            </a>

            <a href="<?= base_url('owner/production/limit') ?>"
               class="btn btn-warning">

                <i class="fas fa-sliders-h"></i>

                Limit PO

            </a>

        </div>

    </div>

    <div class="row mb-4">

        <div class="col-md-3">

            <div class="card border-warning shadow">

                <div class="card-body text-center">

                    <h6>Waiting</h6>

                    <h2><?= $waiting ?></h2>

                </div>

            </div>

        </div>

        <div class="col-md-3">

            <div class="card border-primary shadow">

                <div class="card-body text-center">

                    <h6>Process</h6>

                    <h2><?= $process ?></h2>

                </div>

            </div>

        </div>

        <div class="col-md-3">

            <div class="card border-success shadow">

                <div class="card-body text-center">

                    <h6>Completed</h6>

                    <h2><?= $completed ?></h2>

                </div>

            </div>

        </div>

        <div class="col-md-3">

            <div class="card border-danger shadow">

                <div class="card-body text-center">

                    <h6>Total Queue</h6>

                    <h2><?= count($queues) ?></h2>

                </div>

            </div>

        </div>

    </div>

    <div class="card shadow">

        <div class="card-header bg-dark text-white">

            Queue Produksi

        </div>

        <div class="card-body">

            <table class="table table-bordered table-hover">

                <thead class="table-dark">

                <tr>

                    <th>No</th>

                    <th>No Order</th>

                    <th>Qty</th>

                    <th>Hari Ini</th>

                    <th>Sisa</th>

                    <th>Periode</th>

                    <th>Tanggal</th>

                    <th>Status</th>

                    <th width="300">Aksi</th>

                </tr>

                </thead>

                <tbody>

                <?php $no=1; ?>

                <?php foreach($queues as $row): ?>

                <tr>

                    <td><?= $no++ ?></td>

                    <td><?= esc($row['order_number'] ?? '-') ?></td>

                    <td><?= $row['qty_order'] ?></td>

                    <td><?= $row['qty_hari_ini'] ?></td>

                    <td><?= $row['qty_sisa'] ?></td>

                    <td><?= !empty($row['tanggal_produksi']) ? esc(date('m/Y', strtotime($row['tanggal_produksi']))) : '-' ?></td>

                    <td><?= $row['tanggal_produksi'] ?></td>

                    <td>

                        <?php

                        if($row['status']=='antrian'){

                            echo '<span class="badge bg-warning">Waiting</span>';

                        }elseif($row['status']=='produksi'){

                            echo '<span class="badge bg-primary">Process</span>';

                        }else{

                            echo '<span class="badge bg-success">Completed</span>';

                        }

                        ?>

                    </td>

                    <td>

                        <a href="<?= base_url('owner/production/detail/'.$row['id_queue']) ?>"

                           class="btn btn-info btn-sm">

                            Detail

                        </a>

                        <?php $futureBatch = !empty($row['tanggal_produksi']) && date('Y-m-01', strtotime($row['tanggal_produksi'])) > date('Y-m-01'); ?>
                        <?php if ($futureBatch): ?>
                            <span class="badge bg-secondary">Batch mendatang</span>
                        <?php else: ?>
                            <a href="<?= base_url('owner/production/process/'.$row['id_queue']) ?>"
                               class="btn btn-primary btn-sm">
                                Process
                            </a>

                            <a href="<?= base_url('owner/production/finish/'.$row['id_queue']) ?>"
                               class="btn btn-success btn-sm">
                                Finish
                            </a>
                        <?php endif; ?>

                    </td>

                </tr>

                <?php endforeach; ?>

                </tbody>

            </table>

        </div>

    </div>

</div>

<?= $this->endSection() ?>
