<style>.spk-summary{padding:12px 16px;color:#667085;font-size:13px}.spk-table{margin:0}.spk-table thead th{border:0;background:#f7f9fc;color:#687386;font-size:11px;text-transform:uppercase;letter-spacing:.04em;padding:11px 14px}.spk-table td{padding:14px;border-color:#edf0f4;vertical-align:middle}.spk-order{font-weight:700;color:#202a3b}.spk-client{font-weight:600;color:#344054}.spk-client small{display:block;color:#8a94a6;font-weight:400}.spk-product{font-weight:600}.spk-product small{display:block;color:#7b8495;font-weight:400;margin-top:3px}.spk-badge{display:inline-block;border-radius:20px;padding:5px 9px;font-size:11px;font-weight:700}.spk-baru{background:#f0f2f5;color:#606b7c}.spk-desain{background:#eaf0ff;color:#3e63c7}.spk-proses{background:#e5f7fb;color:#177a8b}.spk-selesai{background:#e8f7ef;color:#237a4b}.spk-foot{display:flex;justify-content:space-between;align-items:center;padding:13px 16px;border-top:1px solid #edf0f4}.spk-foot nav{margin-left:auto}.spk-foot .pagination{margin:0}.spk-empty{text-align:center;padding:65px 20px}.spk-empty i{font-size:34px;color:#c5ccd7;margin-bottom:12px}.spk-empty h5{color:#344054}.spk-empty p{color:#8791a2;margin:0}@media(max-width:768px){.spk-hide-sm{display:none}.spk-table td,.spk-table thead th{padding:11px 9px}.spk-foot{flex-direction:column;gap:10px}.spk-foot nav{margin:auto}}
</style>
<?php if (empty($rows)): ?><div class="spk-empty"><i class="fa fa-folder-open-o"></i><h5>Data SPK belum ditemukan</h5><p>Coba ubah kata kunci atau rentang tanggal.</p></div>
<?php else: ?><div class="spk-summary">Menampilkan <?=count($rows);?> dari <?=number_format($total);?> order</div><div class="table-responsive"><table class="table spk-table"><thead><tr><th>Order</th><th>Pelanggan</th><th class="spk-hide-sm">Jadwal</th><th>Item Produksi</th><th>Status</th><th class="text-right">Aksi</th></tr></thead><tbody>
<?php foreach($rows as $row): $items=isset($details[(int)$row['id_invoice']])?$details[(int)$row['id_invoice']]:[]; $first=reset($items); $count=count($items); $status=$first?(int)$first['status']:0; $statusMeta=job_status_meta($status); $token=encrypt_url($row['id_invoice']); ?>
<tr><td><div class="spk-order"><?=html_escape($row['id_transaksi']);?></div><small class="text-muted"><?=html_escape(dtimes($row['tgl_trx'],false,false));?></small></td><td><div class="spk-client"><?=html_escape($row['nama']);?><small><?=html_escape($row['no_hp']);?></small></div></td><td class="spk-hide-sm"><small class="text-muted">Selesai</small><br><?=html_escape(dtimes($row['tgl_ambil'],true,false));?></td><td><?php if($first): ?><div class="spk-product"><?=html_escape($first['produk']);?><small><?=number_format((float)$first['jumlah'],0,',','.');?> pcs · <?=html_escape($first['bahan']);?><?=$count>1?' · +'.($count-1).' item':'';?></small></div><?php else: ?>-<?php endif;?></td><td><span class="spk-badge" style="background-color:<?=html_escape($statusMeta['color']);?>;color:#fff"><?=html_escape($statusMeta['label']);?></span></td><td class="text-right"><button type="button" class="btn btn-sm btn-outline-primary open-spk-form" data-id="<?=html_escape($token);?>"><i class="fa fa-pencil mr-1"></i> Cetak SPK</button></td></tr>
<?php endforeach; ?></tbody></table></div><div class="spk-foot"><small class="text-muted">Data dimuat per halaman agar tetap ringan.</small><nav><?=$this->ajax_pagination->create_links();?></nav></div><?php endif; ?>
