Phase 3 발주/입고/재고 관리 구현

- DB: bag_order, bag_order_item, bag_receiving, bag_inventory 테이블
- 발주: UUID v4, SHA-256 해시, LOT번호 자동생성, 봉투별 품목 관리
  - 포장단위 연동 (박스→낱장 자동 환산), 단가 연동 (금액 자동 계산)
  - 발주 현황 (기간/상태 필터), 상세 조회, 취소/삭제 (상태 변경)
- 입고: 발주건 기반 입고 처리, 박스→낱장 환산, 재고 자동 가산
- 재고: 지자체별 봉투 종류별 현재 재고 조회
- E2E 테스트 7개 전체 통과

Co-Authored-By: Claude Opus 4.6 (1M context) <noreply@anthropic.com>
This commit is contained in:
javamon1174
2026-03-25 18:13:01 +09:00
parent c2840a9e34
commit d9d3ef46c1
17 changed files with 1002 additions and 12 deletions

View File

@@ -81,6 +81,22 @@ $routes->group('admin', ['filter' => 'adminAuth'], static function ($routes): vo
$routes->post('bag-prices/delete/(:num)', 'Admin\BagPrice::delete/$1');
$routes->get('bag-prices/history/(:num)', 'Admin\BagPrice::history/$1');
// 발주 관리 (P3-01~05)
$routes->get('bag-orders', 'Admin\BagOrder::index');
$routes->get('bag-orders/create', 'Admin\BagOrder::create');
$routes->post('bag-orders/store', 'Admin\BagOrder::store');
$routes->get('bag-orders/detail/(:num)', 'Admin\BagOrder::detail/$1');
$routes->post('bag-orders/cancel/(:num)', 'Admin\BagOrder::cancel/$1');
$routes->post('bag-orders/delete/(:num)', 'Admin\BagOrder::delete/$1');
// 입고 관리 (P3-06~09)
$routes->get('bag-receivings', 'Admin\BagReceiving::index');
$routes->get('bag-receivings/create', 'Admin\BagReceiving::create');
$routes->post('bag-receivings/store', 'Admin\BagReceiving::store');
// 재고 현황 (P3-10)
$routes->get('bag-inventory', 'Admin\BagInventory::index');
// 포장 단위 관리 (P2-05/06)
$routes->get('packaging-units', 'Admin\PackagingUnit::index');
$routes->get('packaging-units/create', 'Admin\PackagingUnit::create');

View File

@@ -0,0 +1,23 @@
<?php
namespace App\Controllers\Admin;
use App\Controllers\BaseController;
use App\Models\BagInventoryModel;
class BagInventory extends BaseController
{
public function index()
{
helper('admin');
$lgIdx = admin_effective_lg_idx();
if (!$lgIdx) return redirect()->to(site_url('admin'))->with('error', '지자체를 선택해 주세요.');
$list = model(BagInventoryModel::class)->where('bi_lg_idx', $lgIdx)->orderBy('bi_bag_code', 'ASC')->findAll();
return view('admin/layout', [
'title' => '재고 현황',
'content' => view('admin/bag_inventory/index', ['list' => $list]),
]);
}
}

View File

@@ -0,0 +1,221 @@
<?php
namespace App\Controllers\Admin;
use App\Controllers\BaseController;
use App\Models\BagOrderModel;
use App\Models\BagOrderItemModel;
use App\Models\BagPriceModel;
use App\Models\PackagingUnitModel;
use App\Models\CompanyModel;
use App\Models\SalesAgencyModel;
use App\Models\CodeKindModel;
use App\Models\CodeDetailModel;
use Ramsey\Uuid\Uuid;
class BagOrder extends BaseController
{
private BagOrderModel $orderModel;
private BagOrderItemModel $itemModel;
public function __construct()
{
$this->orderModel = model(BagOrderModel::class);
$this->itemModel = model(BagOrderItemModel::class);
}
public function index()
{
helper('admin');
$lgIdx = admin_effective_lg_idx();
if (!$lgIdx) {
return redirect()->to(site_url('admin'))->with('error', '지자체를 선택해 주세요.');
}
$builder = $this->orderModel->where('bo_lg_idx', $lgIdx);
// 기간 필터
$startDate = $this->request->getGet('start_date');
$endDate = $this->request->getGet('end_date');
$status = $this->request->getGet('status');
if ($startDate) $builder->where('bo_order_date >=', $startDate);
if ($endDate) $builder->where('bo_order_date <=', $endDate);
if ($status) $builder->where('bo_status', $status);
$list = $builder->orderBy('bo_order_date', 'DESC')->orderBy('bo_idx', 'DESC')->findAll();
// 발주별 품목 합계
$itemSummary = [];
foreach ($list as $order) {
$items = $this->itemModel->where('boi_bo_idx', $order->bo_idx)->findAll();
$totalQty = 0; $totalAmt = 0;
foreach ($items as $it) { $totalQty += (int) $it->boi_qty_sheet; $totalAmt += (float) $it->boi_amount; }
$itemSummary[$order->bo_idx] = ['qty' => $totalQty, 'amount' => $totalAmt, 'count' => count($items)];
}
// 제작업체/대행소 이름 매핑
$companyMap = []; $agencyMap = [];
foreach (model(CompanyModel::class)->where('cp_lg_idx', $lgIdx)->findAll() as $c) $companyMap[$c->cp_idx] = $c->cp_name;
foreach (model(SalesAgencyModel::class)->where('sa_lg_idx', $lgIdx)->findAll() as $a) $agencyMap[$a->sa_idx] = $a->sa_name;
return view('admin/layout', [
'title' => '발주 현황',
'content' => view('admin/bag_order/index', compact('list', 'itemSummary', 'companyMap', 'agencyMap', 'startDate', 'endDate', 'status')),
]);
}
public function create()
{
helper('admin');
$lgIdx = admin_effective_lg_idx();
if (!$lgIdx) return redirect()->to(site_url('admin/bag-orders'))->with('error', '지자체를 선택해 주세요.');
// 봉투 종류 + 단가 + 포장단위
$kind = model(CodeKindModel::class)->where('ck_code', 'O')->first();
$bagCodes = $kind ? model(CodeDetailModel::class)->getByKind((int) $kind->ck_idx, true) : [];
$prices = model(BagPriceModel::class)->where('bp_lg_idx', $lgIdx)->where('bp_state', 1)->findAll();
$units = model(PackagingUnitModel::class)->where('pu_lg_idx', $lgIdx)->where('pu_state', 1)->findAll();
$companies = model(CompanyModel::class)->where('cp_lg_idx', $lgIdx)->where('cp_type', '제작업체')->where('cp_state', 1)->findAll();
$agencies = model(SalesAgencyModel::class)->where('sa_lg_idx', $lgIdx)->where('sa_state', 1)->findAll();
return view('admin/layout', [
'title' => '발주 등록',
'content' => view('admin/bag_order/create', compact('bagCodes', 'prices', 'units', 'companies', 'agencies')),
]);
}
public function store()
{
helper('admin');
$lgIdx = admin_effective_lg_idx();
$rules = [
'bo_order_date' => 'required|valid_date[Y-m-d]',
'bo_company_idx' => 'permit_empty|is_natural_no_zero',
'bo_agency_idx' => 'permit_empty|is_natural_no_zero',
];
if (! $this->validate($rules)) {
return redirect()->back()->withInput()->with('errors', $this->validator->getErrors());
}
$db = \Config\Database::connect();
$db->transStart();
// UUID 생성
$uuid = sprintf('%04x%04x-%04x-%04x-%04x-%04x%04x%04x',
mt_rand(0, 0xffff), mt_rand(0, 0xffff), mt_rand(0, 0xffff),
mt_rand(0, 0x0fff) | 0x4000, mt_rand(0, 0x3fff) | 0x8000,
mt_rand(0, 0xffff), mt_rand(0, 0xffff), mt_rand(0, 0xffff));
// LOT 번호 생성
$lotNo = 'LOT-' . date('Ymd') . '-' . strtoupper(substr(md5($uuid), 0, 6));
$orderData = [
'bo_uuid' => $uuid,
'bo_version' => 1,
'bo_lg_idx' => $lgIdx,
'bo_gugun_code' => $this->request->getPost('bo_gugun_code') ?? '',
'bo_dong_code' => $this->request->getPost('bo_dong_code') ?? '',
'bo_company_idx' => $this->request->getPost('bo_company_idx') ?: null,
'bo_agency_idx' => $this->request->getPost('bo_agency_idx') ?: null,
'bo_fee_rate' => (float) ($this->request->getPost('bo_fee_rate') ?: 0),
'bo_order_date' => $this->request->getPost('bo_order_date'),
'bo_lot_no' => $lotNo,
'bo_status' => 'normal',
'bo_orderer_idx' => session()->get('mb_idx'),
'bo_regdate' => date('Y-m-d H:i:s'),
];
// SHA-256 해시
$orderData['bo_hash'] = hash('sha256', json_encode($orderData));
$this->orderModel->insert($orderData);
$boIdx = (int) $this->orderModel->getInsertID();
// 품목 저장
$bagCodes = $this->request->getPost('item_bag_code') ?? [];
$qtyBoxes = $this->request->getPost('item_qty_box') ?? [];
foreach ($bagCodes as $i => $code) {
if (empty($code) || empty($qtyBoxes[$i])) continue;
$qtyBox = (int) $qtyBoxes[$i];
// 포장단위에서 낱장 환산
$unit = model(PackagingUnitModel::class)->where('pu_lg_idx', $lgIdx)->where('pu_bag_code', $code)->where('pu_state', 1)->first();
$totalPerBox = $unit ? (int) $unit->pu_total_per_box : 1;
$qtySheet = $qtyBox * $totalPerBox;
// 단가
$price = model(BagPriceModel::class)->where('bp_lg_idx', $lgIdx)->where('bp_bag_code', $code)->where('bp_state', 1)->first();
$unitPrice = $price ? (float) $price->bp_order_price : 0;
// 봉투명
$kindO = model(CodeKindModel::class)->where('ck_code', 'O')->first();
$detail = $kindO ? model(CodeDetailModel::class)->where('cd_ck_idx', $kindO->ck_idx)->where('cd_code', $code)->first() : null;
$this->itemModel->insert([
'boi_bo_idx' => $boIdx,
'boi_bag_code' => $code,
'boi_bag_name' => $detail ? $detail->cd_name : '',
'boi_unit_price' => $unitPrice,
'boi_qty_box' => $qtyBox,
'boi_qty_sheet' => $qtySheet,
'boi_amount' => $unitPrice * $qtySheet,
]);
}
$db->transComplete();
return redirect()->to(site_url('admin/bag-orders'))->with('success', '발주가 등록되었습니다. LOT: ' . $lotNo);
}
public function detail(int $id)
{
helper('admin');
$order = $this->orderModel->find($id);
if (!$order || (int) $order->bo_lg_idx !== admin_effective_lg_idx()) {
return redirect()->to(site_url('admin/bag-orders'))->with('error', '발주를 찾을 수 없습니다.');
}
$items = $this->itemModel->where('boi_bo_idx', $id)->findAll();
$companyName = '';
if ($order->bo_company_idx) {
$c = model(CompanyModel::class)->find($order->bo_company_idx);
$companyName = $c ? $c->cp_name : '';
}
$agencyName = '';
if ($order->bo_agency_idx) {
$a = model(SalesAgencyModel::class)->find($order->bo_agency_idx);
$agencyName = $a ? $a->sa_name : '';
}
return view('admin/layout', [
'title' => '발주 상세 — ' . $order->bo_lot_no,
'content' => view('admin/bag_order/detail', compact('order', 'items', 'companyName', 'agencyName')),
]);
}
public function cancel(int $id)
{
helper('admin');
$order = $this->orderModel->find($id);
if (!$order || (int) $order->bo_lg_idx !== admin_effective_lg_idx()) {
return redirect()->to(site_url('admin/bag-orders'))->with('error', '발주를 찾을 수 없습니다.');
}
$this->orderModel->update($id, ['bo_status' => 'cancelled', 'bo_moddate' => date('Y-m-d H:i:s')]);
return redirect()->to(site_url('admin/bag-orders'))->with('success', '발주가 취소되었습니다.');
}
public function delete(int $id)
{
helper('admin');
$order = $this->orderModel->find($id);
if (!$order || (int) $order->bo_lg_idx !== admin_effective_lg_idx()) {
return redirect()->to(site_url('admin/bag-orders'))->with('error', '발주를 찾을 수 없습니다.');
}
$this->orderModel->update($id, ['bo_status' => 'deleted', 'bo_moddate' => date('Y-m-d H:i:s')]);
return redirect()->to(site_url('admin/bag-orders'))->with('success', '발주가 삭제 처리되었습니다.');
}
}

View File

@@ -0,0 +1,109 @@
<?php
namespace App\Controllers\Admin;
use App\Controllers\BaseController;
use App\Models\BagReceivingModel;
use App\Models\BagOrderModel;
use App\Models\BagOrderItemModel;
use App\Models\BagInventoryModel;
use App\Models\CompanyModel;
class BagReceiving extends BaseController
{
private BagReceivingModel $recvModel;
public function __construct()
{
$this->recvModel = model(BagReceivingModel::class);
}
public function index()
{
helper('admin');
$lgIdx = admin_effective_lg_idx();
if (!$lgIdx) return redirect()->to(site_url('admin'))->with('error', '지자체를 선택해 주세요.');
$builder = $this->recvModel->where('br_lg_idx', $lgIdx);
$startDate = $this->request->getGet('start_date');
$endDate = $this->request->getGet('end_date');
if ($startDate) $builder->where('br_receive_date >=', $startDate);
if ($endDate) $builder->where('br_receive_date <=', $endDate);
$list = $builder->orderBy('br_receive_date', 'DESC')->orderBy('br_idx', 'DESC')->findAll();
return view('admin/layout', [
'title' => '입고 현황',
'content' => view('admin/bag_receiving/index', compact('list', 'startDate', 'endDate')),
]);
}
public function create()
{
helper('admin');
$lgIdx = admin_effective_lg_idx();
if (!$lgIdx) return redirect()->to(site_url('admin/bag-receivings'))->with('error', '지자체를 선택해 주세요.');
// 미입고 발주 목록
$orders = model(BagOrderModel::class)->where('bo_lg_idx', $lgIdx)->where('bo_status', 'normal')->orderBy('bo_order_date', 'DESC')->findAll();
return view('admin/layout', [
'title' => '입고 처리',
'content' => view('admin/bag_receiving/create', compact('orders')),
]);
}
public function store()
{
helper('admin');
$lgIdx = admin_effective_lg_idx();
$rules = [
'br_bo_idx' => 'required|is_natural_no_zero',
'br_bag_code' => 'required|max_length[50]',
'br_qty_box' => 'required|is_natural_no_zero',
'br_receive_date' => 'required|valid_date[Y-m-d]',
];
if (! $this->validate($rules)) {
return redirect()->back()->withInput()->with('errors', $this->validator->getErrors());
}
$boIdx = (int) $this->request->getPost('br_bo_idx');
$bagCode = $this->request->getPost('br_bag_code');
$qtyBox = (int) $this->request->getPost('br_qty_box');
// 포장단위로 낱장 환산
$unit = model(\App\Models\PackagingUnitModel::class)->where('pu_lg_idx', $lgIdx)->where('pu_bag_code', $bagCode)->where('pu_state', 1)->first();
$totalPerBox = $unit ? (int) $unit->pu_total_per_box : 1;
$qtySheet = $qtyBox * $totalPerBox;
// 봉투명
$kindO = model(\App\Models\CodeKindModel::class)->where('ck_code', 'O')->first();
$detail = $kindO ? model(\App\Models\CodeDetailModel::class)->where('cd_ck_idx', $kindO->ck_idx)->where('cd_code', $bagCode)->first() : null;
$bagName = $detail ? $detail->cd_name : '';
$db = \Config\Database::connect();
$db->transStart();
$this->recvModel->insert([
'br_bo_idx' => $boIdx,
'br_lg_idx' => $lgIdx,
'br_bag_code' => $bagCode,
'br_bag_name' => $bagName,
'br_qty_box' => $qtyBox,
'br_qty_sheet' => $qtySheet,
'br_receive_date' => $this->request->getPost('br_receive_date'),
'br_receiver_idx' => session()->get('mb_idx'),
'br_sender_name' => $this->request->getPost('br_sender_name') ?? '',
'br_type' => $this->request->getPost('br_type') ?? 'batch',
'br_regdate' => date('Y-m-d H:i:s'),
]);
// 재고 가산
model(BagInventoryModel::class)->adjustQty($lgIdx, $bagCode, $bagName, $qtySheet);
$db->transComplete();
return redirect()->to(site_url('admin/bag-receivings'))->with('success', '입고 처리되었습니다. (' . $bagName . ' ' . $qtyBox . '박스)');
}
}

View File

@@ -0,0 +1,38 @@
<?php
namespace App\Models;
use CodeIgniter\Model;
class BagInventoryModel extends Model
{
protected $table = 'bag_inventory';
protected $primaryKey = 'bi_idx';
protected $returnType = 'object';
protected $useTimestamps = false;
protected $allowedFields = [
'bi_lg_idx', 'bi_bag_code', 'bi_bag_name', 'bi_qty', 'bi_updated_at',
];
/**
* 재고 증감 (upsert)
*/
public function adjustQty(int $lgIdx, string $bagCode, string $bagName, int $delta): void
{
$existing = $this->where('bi_lg_idx', $lgIdx)->where('bi_bag_code', $bagCode)->first();
if ($existing) {
$this->update($existing->bi_idx, [
'bi_qty' => max(0, (int) $existing->bi_qty + $delta),
'bi_updated_at' => date('Y-m-d H:i:s'),
]);
} else {
$this->insert([
'bi_lg_idx' => $lgIdx,
'bi_bag_code' => $bagCode,
'bi_bag_name' => $bagName,
'bi_qty' => max(0, $delta),
'bi_updated_at'=> date('Y-m-d H:i:s'),
]);
}
}
}

View File

@@ -0,0 +1,17 @@
<?php
namespace App\Models;
use CodeIgniter\Model;
class BagOrderItemModel extends Model
{
protected $table = 'bag_order_item';
protected $primaryKey = 'boi_idx';
protected $returnType = 'object';
protected $useTimestamps = false;
protected $allowedFields = [
'boi_bo_idx', 'boi_bag_code', 'boi_bag_name',
'boi_unit_price', 'boi_qty_box', 'boi_qty_sheet', 'boi_amount',
];
}

View File

@@ -0,0 +1,19 @@
<?php
namespace App\Models;
use CodeIgniter\Model;
class BagOrderModel extends Model
{
protected $table = 'bag_order';
protected $primaryKey = 'bo_idx';
protected $returnType = 'object';
protected $useTimestamps = false;
protected $allowedFields = [
'bo_uuid', 'bo_version', 'bo_lg_idx', 'bo_gugun_code', 'bo_dong_code',
'bo_company_idx', 'bo_agency_idx', 'bo_fee_rate', 'bo_order_date',
'bo_lot_no', 'bo_hash', 'bo_status', 'bo_orderer_idx',
'bo_regdate', 'bo_moddate',
];
}

View File

@@ -0,0 +1,18 @@
<?php
namespace App\Models;
use CodeIgniter\Model;
class BagReceivingModel extends Model
{
protected $table = 'bag_receiving';
protected $primaryKey = 'br_idx';
protected $returnType = 'object';
protected $useTimestamps = false;
protected $allowedFields = [
'br_bo_idx', 'br_lg_idx', 'br_bag_code', 'br_bag_name',
'br_qty_box', 'br_qty_sheet', 'br_receive_date',
'br_receiver_idx', 'br_sender_name', 'br_type', 'br_regdate',
];
}

View File

@@ -0,0 +1,30 @@
<section class="border-b border-gray-300 p-2 shrink-0 bg-control-panel">
<span class="text-sm font-bold text-gray-700">재고 현황</span>
</section>
<div class="border border-gray-300 overflow-auto mt-2">
<table class="w-full data-table">
<thead>
<tr>
<th class="w-16">번호</th>
<th>봉투코드</th>
<th>봉투명</th>
<th>현재재고(낱장)</th>
<th>최종갱신</th>
</tr>
</thead>
<tbody class="text-right">
<?php foreach ($list as $row): ?>
<tr>
<td class="text-center"><?= esc($row->bi_idx) ?></td>
<td class="text-center font-mono"><?= esc($row->bi_bag_code) ?></td>
<td class="text-left pl-2"><?= esc($row->bi_bag_name) ?></td>
<td class="font-bold"><?= number_format((int) $row->bi_qty) ?></td>
<td class="text-center"><?= esc($row->bi_updated_at) ?></td>
</tr>
<?php endforeach; ?>
<?php if (empty($list)): ?>
<tr><td colspan="5" class="text-center text-gray-400 py-4">등록된 재고가 없습니다.</td></tr>
<?php endif; ?>
</tbody>
</table>
</div>

View File

@@ -0,0 +1,83 @@
<section class="border-b border-gray-300 p-2 shrink-0 bg-control-panel">
<span class="text-sm font-bold text-gray-700">발주 등록</span>
</section>
<div class="border border-gray-300 p-4 mt-2 bg-white max-w-4xl">
<form action="<?= base_url('admin/bag-orders/store') ?>" method="POST" class="space-y-4">
<?= csrf_field() ?>
<div class="flex flex-wrap items-center gap-2">
<label class="block text-sm font-bold text-gray-700 w-28">발주일 <span class="text-red-500">*</span></label>
<input class="border border-gray-300 rounded px-3 py-1.5 text-sm w-44" name="bo_order_date" type="date" value="<?= esc(old('bo_order_date', date('Y-m-d'))) ?>" required/>
</div>
<div class="flex flex-wrap items-center gap-2">
<label class="block text-sm font-bold text-gray-700 w-28">수수료율</label>
<input class="border border-gray-300 rounded px-3 py-1.5 text-sm w-32 text-right" name="bo_fee_rate" type="number" step="0.01" value="<?= esc(old('bo_fee_rate', '0')) ?>"/>
<span class="text-sm text-gray-500">%</span>
</div>
<div class="flex flex-wrap items-center gap-2">
<label class="block text-sm font-bold text-gray-700 w-28">제작업체</label>
<select class="border border-gray-300 rounded px-3 py-1.5 text-sm w-60" name="bo_company_idx">
<option value="">선택</option>
<?php foreach ($companies as $cp): ?>
<option value="<?= esc($cp->cp_idx) ?>" <?= (int) old('bo_company_idx') === (int) $cp->cp_idx ? 'selected' : '' ?>>
<?= esc($cp->cp_name) ?>
</option>
<?php endforeach; ?>
</select>
</div>
<div class="flex flex-wrap items-center gap-2">
<label class="block text-sm font-bold text-gray-700 w-28">입고처</label>
<select class="border border-gray-300 rounded px-3 py-1.5 text-sm w-60" name="bo_agency_idx">
<option value="">선택</option>
<?php foreach ($agencies as $ag): ?>
<option value="<?= esc($ag->sa_idx) ?>" <?= (int) old('bo_agency_idx') === (int) $ag->sa_idx ? 'selected' : '' ?>>
<?= esc($ag->sa_name) ?>
</option>
<?php endforeach; ?>
</select>
</div>
<div class="mt-4">
<label class="block text-sm font-bold text-gray-700 mb-2">발주 품목</label>
<div class="border border-gray-300 overflow-auto">
<table class="w-full data-table">
<thead>
<tr>
<th class="w-16">순번</th>
<th>봉투</th>
<th class="w-32">박스수</th>
</tr>
</thead>
<tbody>
<?php for ($i = 0; $i < 3; $i++): ?>
<tr>
<td class="text-center"><?= $i + 1 ?></td>
<td>
<select class="border border-gray-300 rounded px-2 py-1 text-sm w-full" name="item_bag_code[]">
<option value="">선택</option>
<?php foreach ($bagCodes as $cd): ?>
<option value="<?= esc($cd->cd_code) ?>">
<?= esc($cd->cd_code) ?> — <?= esc($cd->cd_name) ?>
</option>
<?php endforeach; ?>
</select>
</td>
<td>
<input class="border border-gray-300 rounded px-2 py-1 text-sm w-full text-right" name="item_qty_box[]" type="number" min="0" value="0"/>
</td>
</tr>
<?php endfor; ?>
</tbody>
</table>
</div>
</div>
<div class="flex gap-2 pt-2">
<button type="submit" class="bg-btn-search text-white px-6 py-1.5 rounded-sm text-sm shadow hover:opacity-90 transition">등록</button>
<a href="<?= base_url('admin/bag-orders') ?>" class="bg-gray-200 text-gray-700 px-6 py-1.5 rounded-sm text-sm hover:bg-gray-300 transition">취소</a>
</div>
</form>
</div>

View File

@@ -0,0 +1,102 @@
<section class="border-b border-gray-300 p-2 shrink-0 bg-control-panel">
<div class="flex items-center gap-2">
<a href="<?= base_url('admin/bag-orders') ?>" class="text-blue-600 hover:underline text-sm">&larr; 발주 목록</a>
<span class="text-gray-400">|</span>
<span class="text-sm font-bold text-gray-700">발주 상세 <?= esc($order->bo_lot_no) ?></span>
</div>
</section>
<div class="border border-gray-300 p-4 mt-2 bg-white max-w-4xl">
<table class="w-full text-sm">
<tbody>
<tr class="border-b">
<th class="text-left py-2 pr-4 text-gray-600 w-28">UUID</th>
<td class="py-2 font-mono"><?= esc($order->bo_uuid) ?></td>
</tr>
<tr class="border-b">
<th class="text-left py-2 pr-4 text-gray-600 w-28">버전</th>
<td class="py-2"><?= esc($order->bo_version) ?></td>
</tr>
<tr class="border-b">
<th class="text-left py-2 pr-4 text-gray-600 w-28">발주일</th>
<td class="py-2"><?= esc($order->bo_order_date) ?></td>
</tr>
<tr class="border-b">
<th class="text-left py-2 pr-4 text-gray-600 w-28">제작업체</th>
<td class="py-2"><?= esc($companyName ?? '') ?></td>
</tr>
<tr class="border-b">
<th class="text-left py-2 pr-4 text-gray-600 w-28">입고처</th>
<td class="py-2"><?= esc($agencyName ?? '') ?></td>
</tr>
<tr class="border-b">
<th class="text-left py-2 pr-4 text-gray-600 w-28">LOT번호</th>
<td class="py-2 font-mono"><?= esc($order->bo_lot_no) ?></td>
</tr>
<tr class="border-b">
<th class="text-left py-2 pr-4 text-gray-600 w-28">수수료율</th>
<td class="py-2"><?= esc($order->bo_fee_rate) ?>%</td>
</tr>
<tr class="border-b">
<th class="text-left py-2 pr-4 text-gray-600 w-28">상태</th>
<td class="py-2">
<?php
$statusMap = ['normal' => '정상', 'cancelled' => '취소', 'deleted' => '삭제'];
echo esc($statusMap[$order->bo_status] ?? $order->bo_status);
?>
</td>
</tr>
<tr>
<th class="text-left py-2 pr-4 text-gray-600 w-28">해시</th>
<td class="py-2 font-mono text-xs"><?= esc($order->bo_hash) ?></td>
</tr>
</tbody>
</table>
</div>
<div class="border border-gray-300 overflow-auto mt-4">
<table class="w-full data-table">
<thead>
<tr>
<th>봉투코드</th>
<th>봉투명</th>
<th>단가</th>
<th>박스수</th>
<th>낱장수</th>
<th>금액</th>
</tr>
</thead>
<tbody class="text-right">
<?php
$totalQtyBox = 0;
$totalQtySheet = 0;
$totalAmount = 0;
?>
<?php foreach ($items as $item): ?>
<tr>
<td class="text-center font-mono"><?= esc($item->boi_bag_code) ?></td>
<td class="text-left pl-2"><?= esc($item->boi_bag_name) ?></td>
<td><?= number_format((float) $item->boi_unit_price) ?></td>
<td><?= number_format((int) $item->boi_qty_box) ?></td>
<td><?= number_format((int) $item->boi_qty_sheet) ?></td>
<td><?= number_format((float) $item->boi_amount) ?></td>
</tr>
<?php
$totalQtyBox += (int) $item->boi_qty_box;
$totalQtySheet += (int) $item->boi_qty_sheet;
$totalAmount += (float) $item->boi_amount;
?>
<?php endforeach; ?>
<?php if (empty($items)): ?>
<tr><td colspan="6" class="text-center text-gray-400 py-4">등록된 품목이 없습니다.</td></tr>
<?php endif; ?>
</tbody>
<tfoot class="bg-gray-50 font-bold text-right">
<tr>
<td colspan="3" class="text-center">합계</td>
<td><?= number_format($totalQtyBox) ?></td>
<td><?= number_format($totalQtySheet) ?></td>
<td><?= number_format($totalAmount) ?></td>
</tr>
</tfoot>
</table>
</div>

View File

@@ -0,0 +1,75 @@
<section class="border-b border-gray-300 p-2 shrink-0 bg-control-panel">
<div class="flex flex-wrap items-center justify-between gap-y-2">
<span class="text-sm font-bold text-gray-700">발주 현황</span>
<a href="<?= base_url('admin/bag-orders/create') ?>" class="bg-btn-search text-white px-4 py-1.5 rounded-sm flex items-center gap-1 text-sm shadow hover:opacity-90 transition border border-transparent">발주 등록</a>
</div>
</section>
<section class="p-2 bg-white border-b border-gray-200">
<form method="GET" action="<?= base_url('admin/bag-orders') ?>" class="flex flex-wrap items-center gap-2">
<label class="text-sm text-gray-600">발주일</label>
<input type="date" name="start_date" value="<?= esc($startDate ?? '') ?>" class="border border-gray-300 rounded px-2 py-1 text-sm"/>
<label class="text-sm text-gray-600">~</label>
<input type="date" name="end_date" value="<?= esc($endDate ?? '') ?>" class="border border-gray-300 rounded px-2 py-1 text-sm"/>
<label class="text-sm text-gray-600">상태</label>
<select name="status" class="border border-gray-300 rounded px-2 py-1 text-sm">
<option value="">전체</option>
<option value="normal" <?= ($status ?? '') === 'normal' ? 'selected' : '' ?>>정상</option>
<option value="cancelled" <?= ($status ?? '') === 'cancelled' ? 'selected' : '' ?>>취소</option>
<option value="deleted" <?= ($status ?? '') === 'deleted' ? 'selected' : '' ?>>삭제</option>
</select>
<button type="submit" class="bg-btn-search text-white px-4 py-1 rounded-sm text-sm">조회</button>
<a href="<?= base_url('admin/bag-orders') ?>" class="text-sm text-gray-500 hover:underline">초기화</a>
</form>
</section>
<div class="border border-gray-300 overflow-auto mt-2">
<table class="w-full data-table">
<thead>
<tr>
<th class="w-16">번호</th>
<th>LOT번호</th>
<th>발주일</th>
<th>제작업체</th>
<th>입고처</th>
<th>품목수</th>
<th>총수량</th>
<th>총금액</th>
<th class="w-20">상태</th>
<th class="w-44">작업</th>
</tr>
</thead>
<tbody class="text-right">
<?php foreach ($list as $row): ?>
<tr>
<td class="text-center"><?= esc($row->bo_idx) ?></td>
<td class="text-center font-mono"><?= esc($row->bo_lot_no) ?></td>
<td class="text-center"><?= esc($row->bo_order_date) ?></td>
<td class="text-left pl-2"><?= esc($companyMap[$row->bo_company_idx] ?? '') ?></td>
<td class="text-left pl-2"><?= esc($agencyMap[$row->bo_agency_idx] ?? '') ?></td>
<td><?= number_format((int) ($itemSummary[$row->bo_idx]['count'] ?? 0)) ?></td>
<td><?= number_format((int) ($itemSummary[$row->bo_idx]['qty'] ?? 0)) ?></td>
<td><?= number_format((int) ($itemSummary[$row->bo_idx]['amount'] ?? 0)) ?></td>
<td class="text-center">
<?php
$statusMap = ['normal' => '정상', 'cancelled' => '취소', 'deleted' => '삭제'];
echo esc($statusMap[$row->bo_status] ?? $row->bo_status);
?>
</td>
<td class="text-center">
<a href="<?= base_url('admin/bag-orders/detail/' . (int) $row->bo_idx) ?>" class="text-blue-600 hover:underline text-sm mr-1">상세</a>
<form action="<?= base_url('admin/bag-orders/cancel/' . (int) $row->bo_idx) ?>" method="POST" class="inline" onsubmit="return confirm('취소하시겠습니까?');">
<?= csrf_field() ?>
<button type="submit" class="text-orange-600 hover:underline text-sm mr-1">취소</button>
</form>
<form action="<?= base_url('admin/bag-orders/delete/' . (int) $row->bo_idx) ?>" method="POST" class="inline" onsubmit="return confirm('삭제하시겠습니까?');">
<?= csrf_field() ?>
<button type="submit" class="text-red-600 hover:underline text-sm">삭제</button>
</form>
</td>
</tr>
<?php endforeach; ?>
<?php if (empty($list)): ?>
<tr><td colspan="10" class="text-center text-gray-400 py-4">등록된 발주가 없습니다.</td></tr>
<?php endif; ?>
</tbody>
</table>
</div>

View File

@@ -0,0 +1,53 @@
<section class="border-b border-gray-300 p-2 shrink-0 bg-control-panel">
<span class="text-sm font-bold text-gray-700">입고 처리</span>
</section>
<div class="border border-gray-300 p-4 mt-2 bg-white max-w-3xl">
<form action="<?= base_url('admin/bag-receivings/store') ?>" method="POST" class="space-y-4">
<?= csrf_field() ?>
<div class="flex flex-wrap items-center gap-2">
<label class="block text-sm font-bold text-gray-700 w-28">발주건</label>
<select class="border border-gray-300 rounded px-3 py-1.5 text-sm w-72" name="br_bo_idx">
<option value="">선택</option>
<?php foreach ($orders as $od): ?>
<option value="<?= esc($od->bo_idx) ?>" <?= (int) old('br_bo_idx') === (int) $od->bo_idx ? 'selected' : '' ?>>
<?= esc($od->bo_lot_no) ?> (<?= esc($od->bo_order_date) ?>)
</option>
<?php endforeach; ?>
</select>
</div>
<div class="flex flex-wrap items-center gap-2">
<label class="block text-sm font-bold text-gray-700 w-28">봉투코드</label>
<input class="border border-gray-300 rounded px-3 py-1.5 text-sm w-44" name="br_bag_code" type="text" value="<?= esc(old('br_bag_code')) ?>"/>
</div>
<div class="flex flex-wrap items-center gap-2">
<label class="block text-sm font-bold text-gray-700 w-28">박스수 <span class="text-red-500">*</span></label>
<input class="border border-gray-300 rounded px-3 py-1.5 text-sm w-32 text-right" name="br_qty_box" type="number" min="0" value="<?= esc(old('br_qty_box', '0')) ?>" required/>
</div>
<div class="flex flex-wrap items-center gap-2">
<label class="block text-sm font-bold text-gray-700 w-28">입고일 <span class="text-red-500">*</span></label>
<input class="border border-gray-300 rounded px-3 py-1.5 text-sm w-44" name="br_receive_date" type="date" value="<?= esc(old('br_receive_date', date('Y-m-d'))) ?>" required/>
</div>
<div class="flex flex-wrap items-center gap-2">
<label class="block text-sm font-bold text-gray-700 w-28">보내는분</label>
<input class="border border-gray-300 rounded px-3 py-1.5 text-sm w-44" name="br_sender_name" type="text" value="<?= esc(old('br_sender_name')) ?>"/>
</div>
<div class="flex flex-wrap items-center gap-2">
<label class="block text-sm font-bold text-gray-700 w-28">구분</label>
<select class="border border-gray-300 rounded px-3 py-1.5 text-sm w-44" name="br_type">
<option value="batch" <?= old('br_type') === 'batch' ? 'selected' : '' ?>>batch</option>
<option value="scanner" <?= old('br_type') === 'scanner' ? 'selected' : '' ?>>scanner</option>
</select>
</div>
<div class="flex gap-2 pt-2">
<button type="submit" class="bg-btn-search text-white px-6 py-1.5 rounded-sm text-sm shadow hover:opacity-90 transition">등록</button>
<a href="<?= base_url('admin/bag-receivings') ?>" class="bg-gray-200 text-gray-700 px-6 py-1.5 rounded-sm text-sm hover:bg-gray-300 transition">취소</a>
</div>
</form>
</div>

View File

@@ -0,0 +1,49 @@
<section class="border-b border-gray-300 p-2 shrink-0 bg-control-panel">
<div class="flex flex-wrap items-center justify-between gap-y-2">
<span class="text-sm font-bold text-gray-700">입고 현황</span>
<a href="<?= base_url('admin/bag-receivings/create') ?>" class="bg-btn-search text-white px-4 py-1.5 rounded-sm flex items-center gap-1 text-sm shadow hover:opacity-90 transition border border-transparent">입고 처리</a>
</div>
</section>
<section class="p-2 bg-white border-b border-gray-200">
<form method="GET" action="<?= base_url('admin/bag-receivings') ?>" class="flex flex-wrap items-center gap-2">
<label class="text-sm text-gray-600">입고일</label>
<input type="date" name="start_date" value="<?= esc($startDate ?? '') ?>" class="border border-gray-300 rounded px-2 py-1 text-sm"/>
<label class="text-sm text-gray-600">~</label>
<input type="date" name="end_date" value="<?= esc($endDate ?? '') ?>" class="border border-gray-300 rounded px-2 py-1 text-sm"/>
<button type="submit" class="bg-btn-search text-white px-4 py-1 rounded-sm text-sm">조회</button>
<a href="<?= base_url('admin/bag-receivings') ?>" class="text-sm text-gray-500 hover:underline">초기화</a>
</form>
</section>
<div class="border border-gray-300 overflow-auto mt-2">
<table class="w-full data-table">
<thead>
<tr>
<th class="w-16">번호</th>
<th>봉투코드</th>
<th>봉투명</th>
<th>박스수</th>
<th>낱장수</th>
<th>입고일</th>
<th>구분</th>
<th>등록일</th>
</tr>
</thead>
<tbody class="text-right">
<?php foreach ($list as $row): ?>
<tr>
<td class="text-center"><?= esc($row->br_idx) ?></td>
<td class="text-center font-mono"><?= esc($row->br_bag_code) ?></td>
<td class="text-left pl-2"><?= esc($row->br_bag_name) ?></td>
<td><?= number_format((int) $row->br_qty_box) ?></td>
<td><?= number_format((int) $row->br_qty_sheet) ?></td>
<td class="text-center"><?= esc($row->br_receive_date) ?></td>
<td class="text-center"><?= esc($row->br_type) ?></td>
<td class="text-center"><?= esc($row->br_regdate) ?></td>
</tr>
<?php endforeach; ?>
<?php if (empty($list)): ?>
<tr><td colspan="8" class="text-center text-gray-400 py-4">등록된 입고가 없습니다.</td></tr>
<?php endif; ?>
</tbody>
</table>
</div>