Compare commits

..

2 Commits

Author SHA1 Message Date
taekyoungc
5c89c963ee 단가 기간이 겹칠 때 최신 등록 단가를 우선 적용한다.
단가 조회 공통 로직을 모델로 통합하고 발주·판매·주문·사이트 화면의 단가 계산이 모두 최신 등록 순서(bp_regdate, bp_idx DESC)를 따르도록 맞춘다.

Made-with: Cursor
2026-04-22 15:35:36 +09:00
taekyoungc
05c479397b 업체·담당자·단가·지정판매소 관리 화면의 조회 및 표시를 개선한다.
관리 화면에서 유형별 조회와 순번 표기를 통일하고, 지정판매소 주소/구군 표시와 포장단위 이력 표현을 사용자 관점으로 정리한다.

Made-with: Cursor
2026-04-22 15:35:28 +09:00
21 changed files with 2421 additions and 193 deletions

View File

@@ -9,8 +9,11 @@ use App\Models\BagPriceModel;
use App\Models\PackagingUnitModel; use App\Models\PackagingUnitModel;
use App\Models\CompanyModel; use App\Models\CompanyModel;
use App\Models\SalesAgencyModel; use App\Models\SalesAgencyModel;
use App\Models\BagReceivingModel;
use App\Models\CodeKindModel; use App\Models\CodeKindModel;
use App\Models\CodeDetailModel; use App\Models\CodeDetailModel;
use App\Models\LocalGovernmentModel;
use App\Libraries\Blockchain\SqlLedger;
class BagOrder extends BaseController class BagOrder extends BaseController
{ {
private BagOrderModel $orderModel; private BagOrderModel $orderModel;
@@ -30,36 +33,76 @@ class BagOrder extends BaseController
return redirect()->to(work_area_home_url())->with('error', '지자체를 선택해 주세요.'); return redirect()->to(work_area_home_url())->with('error', '지자체를 선택해 주세요.');
} }
$builder = $this->orderModel->where('bo_lg_idx', $lgIdx); $startMonth = (string) ($this->request->getGet('start_month') ?? date('Y-m'));
$endMonth = (string) ($this->request->getGet('end_month') ?? date('Y-m'));
// 기간 필터 if (! preg_match('/^\d{4}-\d{2}$/', $startMonth)) {
$startDate = $this->request->getGet('start_date'); $startMonth = date('Y-m');
$endDate = $this->request->getGet('end_date'); }
$status = $this->request->getGet('status'); if (! preg_match('/^\d{4}-\d{2}$/', $endMonth)) {
if ($startDate) $builder->where('bo_order_date >=', $startDate); $endMonth = $startMonth;
if ($endDate) $builder->where('bo_order_date <=', $endDate); }
if ($status) $builder->where('bo_status', $status); if (strtotime($startMonth . '-01') > strtotime($endMonth . '-01')) {
[$startMonth, $endMonth] = [$endMonth, $startMonth];
$list = $builder->orderBy('bo_order_date', 'DESC')->orderBy('bo_idx', 'DESC')->paginate(20);
$pager = $this->orderModel->pager;
// 발주별 품목 합계
$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)];
} }
// 제작업체/대행소 이름 매핑 $companyIdx = (int) ($this->request->getGet('company_idx') ?? 0);
$companyMap = []; $agencyMap = []; $bagCode = trim((string) ($this->request->getGet('bag_code') ?? ''));
foreach (model(CompanyModel::class)->where('cp_lg_idx', $lgIdx)->findAll() as $c) $companyMap[$c->cp_idx] = $c->cp_name; $receiveType = (string) ($this->request->getGet('receive_type') ?? 'all');
foreach (model(SalesAgencyModel::class)->where('sa_lg_idx', $lgIdx)->orderForDisplay()->findAll() as $a) { if (! in_array($receiveType, ['all', 'received', 'pending'], true)) {
$agencyMap[$a->sa_idx] = '[' . ($a->sa_kind ?? '') . '] ' . ($a->sa_code ?? '') . ' — ' . ($a->sa_name ?? ''); $receiveType = 'all';
} }
return $this->renderWorkPage('발주 현황', 'admin/bag_order/index', compact('list', 'itemSummary', 'companyMap', 'agencyMap', 'startDate', 'endDate', 'status', 'pager')); $companies = model(CompanyModel::class)
->where('cp_lg_idx', $lgIdx)
->where('cp_type', '제작업체')
->where('cp_state', 1)
->orderBy('cp_name', 'ASC')
->findAll();
$companyMap = [];
foreach ($companies as $company) {
$companyMap[(int) $company->cp_idx] = (string) $company->cp_name;
}
$agencyMap = [];
foreach (model(SalesAgencyModel::class)->where('sa_lg_idx', $lgIdx)->orderForDisplay()->findAll() as $agency) {
$agencyMap[(int) $agency->sa_idx] = (string) ($agency->sa_name ?? '');
}
$kind = model(CodeKindModel::class)->where('ck_code', 'O')->first();
$bagCodes = $kind ? model(CodeDetailModel::class)->getByKind((int) $kind->ck_idx, true, $lgIdx) : [];
$bagNameMap = [];
foreach ($bagCodes as $code) {
$bagNameMap[(string) $code->cd_code] = (string) $code->cd_name;
}
$reportData = $this->buildOrderStatusRows(
$lgIdx,
$startMonth,
$endMonth,
$companyIdx,
$bagCode,
$receiveType,
$companyMap,
$agencyMap,
$bagNameMap
);
return $this->renderWorkPage(
'발주 현황',
'admin/bag_order/index',
[
'startMonth' => $startMonth,
'endMonth' => $endMonth,
'companyIdx' => $companyIdx,
'bagCode' => $bagCode,
'receiveType' => $receiveType,
'companyOptions' => $companies,
'bagCodeOptions' => $bagCodes,
'rows' => $reportData['rows'],
'groupRows' => $reportData['groupRows'],
'grandTotals' => $reportData['grandTotals'],
]
);
} }
public function export() public function export()
@@ -70,44 +113,240 @@ class BagOrder extends BaseController
return redirect()->to(mgmt_url('bag-orders'))->with('error', '지자체를 선택해 주세요.'); return redirect()->to(mgmt_url('bag-orders'))->with('error', '지자체를 선택해 주세요.');
} }
$builder = $this->orderModel->where('bo_lg_idx', $lgIdx); $startMonth = (string) ($this->request->getGet('start_month') ?? date('Y-m'));
$startDate = $this->request->getGet('start_date'); $endMonth = (string) ($this->request->getGet('end_month') ?? date('Y-m'));
$endDate = $this->request->getGet('end_date'); if (! preg_match('/^\d{4}-\d{2}$/', $startMonth)) {
$status = $this->request->getGet('status'); $startMonth = date('Y-m');
if ($startDate) $builder->where('bo_order_date >=', $startDate); }
if ($endDate) $builder->where('bo_order_date <=', $endDate); if (! preg_match('/^\d{4}-\d{2}$/', $endMonth)) {
if ($status) $builder->where('bo_status', $status); $endMonth = $startMonth;
}
if (strtotime($startMonth . '-01') > strtotime($endMonth . '-01')) {
[$startMonth, $endMonth] = [$endMonth, $startMonth];
}
$list = $builder->orderBy('bo_order_date', 'DESC')->orderBy('bo_idx', 'DESC')->findAll(); $companyIdx = (int) ($this->request->getGet('company_idx') ?? 0);
$bagCode = trim((string) ($this->request->getGet('bag_code') ?? ''));
$receiveType = (string) ($this->request->getGet('receive_type') ?? 'all');
if (! in_array($receiveType, ['all', 'received', 'pending'], true)) {
$receiveType = 'all';
}
$companyMap = [];
foreach (model(CompanyModel::class)->where('cp_lg_idx', $lgIdx)->where('cp_type', '제작업체')->findAll() as $company) {
$companyMap[(int) $company->cp_idx] = (string) $company->cp_name;
}
$agencyMap = [];
foreach (model(SalesAgencyModel::class)->where('sa_lg_idx', $lgIdx)->orderForDisplay()->findAll() as $agency) {
$agencyMap[(int) $agency->sa_idx] = (string) ($agency->sa_name ?? '');
}
$kind = model(CodeKindModel::class)->where('ck_code', 'O')->first();
$bagCodes = $kind ? model(CodeDetailModel::class)->getByKind((int) $kind->ck_idx, true, $lgIdx) : [];
$bagNameMap = [];
foreach ($bagCodes as $code) {
$bagNameMap[(string) $code->cd_code] = (string) $code->cd_name;
}
$reportData = $this->buildOrderStatusRows(
$lgIdx,
$startMonth,
$endMonth,
$companyIdx,
$bagCode,
$receiveType,
$companyMap,
$agencyMap,
$bagNameMap
);
$rows = []; $rows = [];
$statusMap = ['normal' => '정상', 'cancelled' => '취소', 'deleted' => '삭제']; foreach ($reportData['rows'] as $row) {
foreach ($list as $row) { if (! empty($row['is_subtotal'])) {
$items = $this->itemModel->where('boi_bo_idx', $row->bo_idx)->findAll(); $rows[] = [
$totalQty = 0; '',
$totalAmt = 0; '',
foreach ($items as $it) { (string) ($row['label'] ?? '소계'),
$totalQty += (int) $it->boi_qty_sheet; (int) ($row['order_qty'] ?? 0),
$totalAmt += (float) $it->boi_amount; (int) ($row['received_qty'] ?? 0),
(int) ($row['pending_qty'] ?? 0),
(float) ($row['amount'] ?? 0),
'',
];
continue;
} }
$rows[] = [ $rows[] = [
$row->bo_idx, (string) ($row['order_date'] ?? ''),
$row->bo_lot_no, (string) ($row['company_name'] ?? ''),
$row->bo_order_date, (string) ($row['bag_name'] ?? ''),
count($items), (int) ($row['order_qty'] ?? 0),
$totalQty, (int) ($row['received_qty'] ?? 0),
$totalAmt, (int) ($row['pending_qty'] ?? 0),
$statusMap[$row->bo_status] ?? $row->bo_status, (float) ($row['amount'] ?? 0),
(string) ($row['agency_name'] ?? ''),
'',
]; ];
} }
export_csv( $gt = $reportData['grandTotals'] ?? [];
'발주현황_' . date('Ymd') . '.csv', $rows[] = [
['번호', 'LOT번호', '발주일', '품목수', '총수량', '총금액', '상태'], '',
'',
'총계',
(int) ($gt['order_qty'] ?? 0),
(int) ($gt['received_qty'] ?? 0),
(int) ($gt['pending_qty'] ?? 0),
(float) ($gt['amount'] ?? 0),
'',
'',
];
export_xlsx(
'발주현황_' . date('Ymd'),
'발주현황',
['발주일자', '제작업체', '품명', '발주수량', '입고수량', '미입고수량', '발주금액', '입고처', '비고'],
$rows $rows
); );
} }
/**
* 발주 현황(품목 기준) 행 및 소계를 만든다.
*/
private function buildOrderStatusRows(
int $lgIdx,
string $startMonth,
string $endMonth,
int $companyIdx,
string $bagCode,
string $receiveType,
array $companyMap,
array $agencyMap,
array $bagNameMap
): array {
$startDate = $startMonth . '-01';
$endDate = date('Y-m-t', strtotime($endMonth . '-01 00:00:00'));
$builder = $this->orderModel
->where('bo_lg_idx', $lgIdx)
->whereLatestHead($lgIdx)
->where('bo_order_date >=', $startDate)
->where('bo_order_date <=', $endDate)
->whereIn('bo_status', ['normal', 'cancelled'])
->orderBy('bo_order_date', 'DESC')
->orderBy('bo_idx', 'DESC');
if ($companyIdx > 0) {
$builder->where('bo_company_idx', $companyIdx);
}
$orders = $builder->findAll();
if (empty($orders)) {
return ['rows' => [], 'groupRows' => [], 'grandTotals' => ['order_qty' => 0, 'received_qty' => 0, 'pending_qty' => 0, 'amount' => 0]];
}
$orderIds = array_map(static fn($order) => (int) $order->bo_idx, $orders);
$itemsByOrder = [];
if (! empty($orderIds)) {
$allItems = $this->itemModel
->whereIn('boi_bo_idx', $orderIds)
->orderBy('boi_bo_idx', 'DESC')
->orderBy('boi_idx', 'ASC')
->findAll();
foreach ($allItems as $item) {
$boIdx = (int) ($item->boi_bo_idx ?? 0);
if (! isset($itemsByOrder[$boIdx])) {
$itemsByOrder[$boIdx] = [];
}
$itemsByOrder[$boIdx][] = $item;
}
}
$receivedMap = [];
$receivingRows = model(BagReceivingModel::class)
->select('br_bo_idx, br_bag_code, SUM(br_qty_sheet) as recv_qty')
->where('br_lg_idx', $lgIdx)
->whereIn('br_bo_idx', $orderIds)
->groupBy('br_bo_idx, br_bag_code')
->findAll();
foreach ($receivingRows as $received) {
$key = (int) ($received->br_bo_idx ?? 0) . '|' . (string) ($received->br_bag_code ?? '');
$receivedMap[$key] = (int) ($received->recv_qty ?? 0);
}
$rows = [];
$groupRows = [];
$grandTotals = ['order_qty' => 0, 'received_qty' => 0, 'pending_qty' => 0, 'amount' => 0.0];
foreach ($orders as $order) {
$boIdx = (int) ($order->bo_idx ?? 0);
$items = $itemsByOrder[$boIdx] ?? [];
$groupCount = 0;
$groupTotalOrder = 0;
$groupTotalReceived = 0;
$groupTotalPending = 0;
$groupTotalAmount = 0.0;
foreach ($items as $item) {
$itemBagCode = (string) ($item->boi_bag_code ?? '');
if ($bagCode !== '' && $itemBagCode !== $bagCode) {
continue;
}
$orderQty = (int) ($item->boi_qty_sheet ?? 0);
$recvQty = (int) ($receivedMap[$boIdx . '|' . $itemBagCode] ?? 0);
if ($recvQty > $orderQty) {
$recvQty = $orderQty;
}
$pendingQty = max(0, $orderQty - $recvQty);
if ($receiveType === 'received' && $recvQty <= 0) {
continue;
}
if ($receiveType === 'pending' && $pendingQty <= 0) {
continue;
}
$amount = (float) ($item->boi_amount ?? 0);
$rows[] = [
'bo_idx' => $boIdx,
'order_date' => (string) ($order->bo_order_date ?? ''),
'company_name' => (string) ($companyMap[(int) ($order->bo_company_idx ?? 0)] ?? ''),
'bag_name' => (string) ($item->boi_bag_name ?? ($bagNameMap[$itemBagCode] ?? $itemBagCode)),
'order_qty' => $orderQty,
'received_qty' => $recvQty,
'pending_qty' => $pendingQty,
'amount' => $amount,
'agency_name' => (string) ($agencyMap[(int) ($order->bo_agency_idx ?? 0)] ?? ''),
];
$groupCount++;
$groupTotalOrder += $orderQty;
$groupTotalReceived += $recvQty;
$groupTotalPending += $pendingQty;
$groupTotalAmount += $amount;
}
if ($groupCount > 0) {
$groupRows[$boIdx] = $groupCount;
$rows[] = [
'bo_idx' => $boIdx,
'is_subtotal' => true,
'label' => '소계',
'order_qty' => $groupTotalOrder,
'received_qty' => $groupTotalReceived,
'pending_qty' => $groupTotalPending,
'amount' => $groupTotalAmount,
];
$grandTotals['order_qty'] += $groupTotalOrder;
$grandTotals['received_qty'] += $groupTotalReceived;
$grandTotals['pending_qty'] += $groupTotalPending;
$grandTotals['amount'] += $groupTotalAmount;
}
}
return ['rows' => $rows, 'groupRows' => $groupRows, 'grandTotals' => $grandTotals];
}
public function create() public function create()
{ {
helper('admin'); helper('admin');
@@ -119,18 +358,105 @@ class BagOrder extends BaseController
// 봉투 종류 + 단가 + 포장단위 // 봉투 종류 + 단가 + 포장단위
$kind = model(CodeKindModel::class)->where('ck_code', 'O')->first(); $kind = model(CodeKindModel::class)->where('ck_code', 'O')->first();
$bagCodes = $kind ? model(CodeDetailModel::class)->getByKind((int) $kind->ck_idx, true, $lgIdx) : []; $bagCodes = $kind ? model(CodeDetailModel::class)->getByKind((int) $kind->ck_idx, true, $lgIdx) : [];
$prices = model(BagPriceModel::class)->where('bp_lg_idx', $lgIdx)->where('bp_state', 1)->findAll(); $priceMapRows = model(BagPriceModel::class)->latestActiveMapByBagCode($lgIdx);
$units = model(PackagingUnitModel::class)->where('pu_lg_idx', $lgIdx)->where('pu_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)->orderForDisplay()->findAll();
return $this->renderWorkPage('발주 등록', 'admin/bag_order/create', compact('bagCodes', 'prices', 'units', 'companies', 'agencies')); $companies = model(CompanyModel::class)->where('cp_lg_idx', $lgIdx)->where('cp_type', '제작업체')->where('cp_state', 1)->findAll();
$associations = 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)->orderForDisplay()->findAll();
$companyMap = [];
foreach (model(CompanyModel::class)->where('cp_lg_idx', $lgIdx)->findAll() as $company) {
$companyMap[(int) $company->cp_idx] = (string) $company->cp_name;
}
$agencyMap = [];
foreach ($agencies as $agency) {
$agencyMap[(int) $agency->sa_idx] = '[' . ($agency->sa_kind ?? '') . '] ' . ($agency->sa_code ?? '') . ' — ' . ($agency->sa_name ?? '');
}
$recentOrders = $this->orderModel
->where('bo_lg_idx', $lgIdx)
->whereLatestHead($lgIdx)
->orderBy('bo_order_date', 'DESC')
->orderBy('bo_idx', 'DESC')
->findAll(12);
$bagNameMap = [];
foreach ($bagCodes as $codeDetail) {
$bagNameMap[(string) $codeDetail->cd_code] = (string) $codeDetail->cd_name;
}
$priceMap = [];
foreach ($priceMapRows as $bagCode => $price) {
$priceMap[(string) $bagCode] = (float) ($price->bp_order_price ?? 0);
}
$unitMap = [];
foreach ($units as $unit) {
$unitMap[(string) $unit->pu_bag_code] = [
'boxPerPack' => (int) $unit->pu_box_per_pack,
'packPerSheet' => (int) $unit->pu_pack_per_sheet,
'totalPerBox' => (int) $unit->pu_total_per_box,
];
}
$bagReferenceRows = [];
foreach ($bagCodes as $codeDetail) {
$bagCode = (string) $codeDetail->cd_code;
$unit = $unitMap[$bagCode] ?? ['boxPerPack' => 0, 'packPerSheet' => 0, 'totalPerBox' => 0];
$bagReferenceRows[] = [
'code' => $bagCode,
'name' => (string) ($bagNameMap[$bagCode] ?? ''),
'orderPrice' => (float) ($priceMap[$bagCode] ?? 0),
'boxPerPack' => (int) $unit['boxPerPack'],
'packPerSheet' => (int) $unit['packPerSheet'],
'totalPerBox' => (int) $unit['totalPerBox'],
];
}
return $this->renderWorkPage(
'발주 등록',
'admin/bag_order/create',
compact(
'bagCodes',
'units',
'companies',
'associations',
'agencies',
'recentOrders',
'companyMap',
'agencyMap',
'bagReferenceRows'
)
);
}
public function revise(int $id)
{
helper('admin');
$lgIdx = admin_effective_lg_idx();
$order = $this->orderModel->find($id);
if (! $order || (int) $order->bo_lg_idx !== $lgIdx) {
return redirect()->to(mgmt_url('bag-orders'))->with('error', '발주를 찾을 수 없습니다.');
}
return redirect()->to(site_url('bag/order/revise/' . $id));
} }
public function store() public function store()
{ {
helper('admin'); helper('admin');
$lgIdx = admin_effective_lg_idx(); $lgIdx = admin_effective_lg_idx();
if ($lgIdx === null || $lgIdx <= 0) {
return redirect()->back()->withInput()->with('error', '지자체를 선택해 주세요.');
}
$sourceIdx = (int) ($this->request->getPost('bo_source_idx') ?? 0);
$sourceOrder = null;
if ($sourceIdx > 0) {
$sourceOrder = $this->orderModel->find($sourceIdx);
if (! $sourceOrder || (int) $sourceOrder->bo_lg_idx !== $lgIdx) {
return redirect()->back()->withInput()->with('error', '수정 대상 발주를 찾을 수 없습니다.');
}
}
$rules = [ $rules = [
'bo_order_date' => 'required|valid_date[Y-m-d]', 'bo_order_date' => 'required|valid_date[Y-m-d]',
@@ -141,65 +467,114 @@ class BagOrder extends BaseController
return redirect()->back()->withInput()->with('errors', $this->validator->getErrors()); return redirect()->back()->withInput()->with('errors', $this->validator->getErrors());
} }
$bagCodes = $this->request->getPost('item_bag_code') ?? [];
$qtySheets = $this->request->getPost('item_qty_sheet') ?? [];
$qtyBoxes = $this->request->getPost('item_qty_box') ?? []; // 구 화면 호환
$postedUnitPrices = $this->request->getPost('item_unit_price');
$changeKind = (string) ($this->request->getPost('bo_change_mode') ?? 'meta');
if (! in_array($changeKind, ['price', 'meta', 'delete'], true)) {
$changeKind = 'meta';
}
$itemCount = count($bagCodes);
$normalizedItems = [];
for ($i = 0; $i < $itemCount; $i++) {
$code = trim((string) ($bagCodes[$i] ?? ''));
$qtySheet = (int) ($qtySheets[$i] ?? 0);
$qtyBox = (int) ($qtyBoxes[$i] ?? 0);
if ($code === '' || ($qtySheet <= 0 && $qtyBox <= 0)) {
continue;
}
$normalizedItems[] = ['code' => $code, 'qtySheet' => $qtySheet, 'qtyBox' => $qtyBox];
}
if (empty($normalizedItems)) {
return redirect()->back()->withInput()->with('error', '최소 1개 이상의 봉투 수량을 입력해 주세요.');
}
$priceByCode = [];
if ($sourceOrder !== null && $changeKind === 'price' && is_array($postedUnitPrices)) {
for ($pi = 0; $pi < count($bagCodes); $pi++) {
$c = trim((string) ($bagCodes[$pi] ?? ''));
if ($c === '') {
continue;
}
$raw = $postedUnitPrices[$pi] ?? null;
if ($raw !== null && $raw !== '' && is_numeric($raw)) {
$priceByCode[$c] = round((float) $raw, 2);
}
}
}
$db = \Config\Database::connect(); $db = \Config\Database::connect();
$db->transStart(); $db->transStart();
// UUID 생성 try {
$uuid = sprintf('%04x%04x-%04x-%04x-%04x-%04x%04x%04x', if ($sourceOrder) {
mt_rand(0, 0xffff), mt_rand(0, 0xffff), mt_rand(0, 0xffff), $uuid = (string) $sourceOrder->bo_uuid;
mt_rand(0, 0x0fff) | 0x4000, mt_rand(0, 0x3fff) | 0x8000, $maxVerRow = $this->orderModel->selectMax('bo_version')->where('bo_uuid', $uuid)->first();
mt_rand(0, 0xffff), mt_rand(0, 0xffff), mt_rand(0, 0xffff)); $latestVersion = ($maxVerRow !== null && isset($maxVerRow->bo_version)) ? (int) $maxVerRow->bo_version : 0;
$version = $latestVersion + 1;
// LOT 번호 생성 $lotNo = (string) $sourceOrder->bo_lot_no;
$lotNo = 'LOT-' . date('Ymd') . '-' . strtoupper(substr(md5($uuid), 0, 6)); } else {
$uuid = $this->generateUuidV4();
$version = 1;
$lotNo = $this->generateLotNo6();
}
$orderData = [ $orderData = [
'bo_uuid' => $uuid, 'bo_uuid' => $uuid,
'bo_version' => 1, 'bo_version' => $version,
'bo_lg_idx' => $lgIdx, 'bo_lg_idx' => $lgIdx,
'bo_gugun_code' => $this->request->getPost('bo_gugun_code') ?? '', 'bo_gugun_code' => $this->resolveGugunCodeFromLg($lgIdx),
'bo_dong_code' => $this->request->getPost('bo_dong_code') ?? '', 'bo_dong_code' => '',
'bo_company_idx' => $this->request->getPost('bo_company_idx') ?: null, 'bo_company_idx' => $this->request->getPost('bo_company_idx') ?: null,
'bo_agency_idx' => $this->request->getPost('bo_agency_idx') ?: null, 'bo_agency_idx' => $this->request->getPost('bo_agency_idx') ?: null,
'bo_fee_rate' => (float) ($this->request->getPost('bo_fee_rate') ?: 0), 'bo_fee_rate' => (float) ($this->request->getPost('bo_fee_rate') ?: 0),
'bo_order_date' => $this->request->getPost('bo_order_date'), 'bo_order_date' => $this->request->getPost('bo_order_date'),
'bo_bag_types' => '',
'bo_unit_prices' => '',
'bo_qty_boxes' => '',
'bo_lot_no' => $lotNo, 'bo_lot_no' => $lotNo,
'bo_status' => 'normal', 'bo_status' => 'normal',
'bo_orderer_idx' => session()->get('mb_idx'), 'bo_orderer_idx' => session()->get('mb_idx'),
'bo_regdate' => date('Y-m-d H:i:s'), 'bo_regdate' => date('Y-m-d H:i:s'),
]; ];
// SHA-256 해시 // 품목 입력 후 최종 payload 기준으로 해시를 계산하므로 우선 빈값으로 생성
$orderData['bo_hash'] = hash('sha256', json_encode($orderData)); $orderData['bo_hash'] = '';
$this->orderModel->insert($orderData); $this->orderModel->insert($orderData);
$boIdx = (int) $this->orderModel->getInsertID(); $boIdx = (int) $this->orderModel->getInsertID();
// CT-05: 감사 로그
helper('audit');
audit_log('create', 'bag_order', $boIdx, null, array_merge($orderData, ['bo_idx' => $boIdx]));
// 품목 저장 // 품목 저장
$bagCodes = $this->request->getPost('item_bag_code') ?? []; $hashItems = [];
$qtyBoxes = $this->request->getPost('item_qty_box') ?? []; $bagTypesForHeader = [];
foreach ($bagCodes as $i => $code) { $unitPricesForHeader = [];
if (empty($code) || empty($qtyBoxes[$i])) continue; $qtyBoxesForHeader = [];
$qtyBox = (int) $qtyBoxes[$i]; foreach ($normalizedItems as $item) {
$code = $item['code'];
$qtySheetInput = (int) ($item['qtySheet'] ?? 0);
$qtyBoxInput = (int) ($item['qtyBox'] ?? 0);
// 포장단위에서 낱장 환산 // 포장단위에서 낱장 환산
$unit = model(PackagingUnitModel::class)->where('pu_lg_idx', $lgIdx)->where('pu_bag_code', $code)->where('pu_state', 1)->first(); $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; $totalPerBox = $unit ? max(1, (int) $unit->pu_total_per_box) : 1;
$qtySheet = $qtyBox * $totalPerBox; $qtySheet = $qtySheetInput > 0 ? $qtySheetInput : ($qtyBoxInput * $totalPerBox);
if ($qtySheet <= 0) {
continue;
}
$qtyBox = intdiv($qtySheet, $totalPerBox);
// 단가 // 단가 (발주 변경·단가 구분 시 POST 단가 우선)
$price = model(BagPriceModel::class)->where('bp_lg_idx', $lgIdx)->where('bp_bag_code', $code)->where('bp_state', 1)->first(); $price = model(BagPriceModel::class)->latestActiveByBagCode($lgIdx, $code);
$unitPrice = $price ? (float) $price->bp_order_price : 0; $unitPrice = $price ? (float) $price->bp_order_price : 0;
if ($sourceOrder !== null && isset($priceByCode[$code])) {
$unitPrice = $priceByCode[$code];
}
// 봉투명 // 봉투명
$kindO = model(CodeKindModel::class)->where('ck_code', 'O')->first(); $kindO = model(CodeKindModel::class)->where('ck_code', 'O')->first();
$detail = $kindO ? model(CodeDetailModel::class)->findResolvedByKindAndCode((int) $kindO->ck_idx, (string) $code, $lgIdx) : null; $detail = $kindO ? model(CodeDetailModel::class)->findResolvedByKindAndCode((int) $kindO->ck_idx, (string) $code, $lgIdx) : null;
$this->itemModel->insert([ $itemData = [
'boi_bo_idx' => $boIdx, 'boi_bo_idx' => $boIdx,
'boi_bag_code' => $code, 'boi_bag_code' => $code,
'boi_bag_name' => $detail ? $detail->cd_name : '', 'boi_bag_name' => $detail ? $detail->cd_name : '',
@@ -207,14 +582,204 @@ class BagOrder extends BaseController
'boi_qty_box' => $qtyBox, 'boi_qty_box' => $qtyBox,
'boi_qty_sheet' => $qtySheet, 'boi_qty_sheet' => $qtySheet,
'boi_amount' => $unitPrice * $qtySheet, 'boi_amount' => $unitPrice * $qtySheet,
]); ];
$this->itemModel->insert($itemData);
$hashItems[] = $itemData;
$bagTypesForHeader[] = [
'code' => $itemData['boi_bag_code'],
'name' => $itemData['boi_bag_name'],
];
$unitPricesForHeader[] = [
'code' => $itemData['boi_bag_code'],
'unit_price' => $itemData['boi_unit_price'],
];
$qtyBoxesForHeader[] = [
'code' => $itemData['boi_bag_code'],
'qty_box' => $itemData['boi_qty_box'],
];
} }
$db->transComplete(); $orderData['bo_bag_types'] = json_encode($bagTypesForHeader, JSON_UNESCAPED_UNICODE | JSON_UNESCAPED_SLASHES) ?: '[]';
$orderData['bo_unit_prices'] = json_encode($unitPricesForHeader, JSON_UNESCAPED_UNICODE | JSON_UNESCAPED_SLASHES) ?: '[]';
$orderData['bo_qty_boxes'] = json_encode($qtyBoxesForHeader, JSON_UNESCAPED_UNICODE | JSON_UNESCAPED_SLASHES) ?: '[]';
// 최종 발주 데이터(헤더+품목) 해시
$hashPayload = $orderData;
$hashPayload['bo_idx'] = $boIdx;
$hashPayload['items'] = $hashItems;
$hashJson = json_encode($hashPayload, JSON_UNESCAPED_UNICODE | JSON_UNESCAPED_SLASHES);
$orderHash = hash('sha256', $hashJson !== false ? $hashJson : (string) $boIdx);
$this->orderModel->update($boIdx, [
'bo_bag_types' => $orderData['bo_bag_types'],
'bo_unit_prices' => $orderData['bo_unit_prices'],
'bo_qty_boxes' => $orderData['bo_qty_boxes'],
'bo_hash' => $orderHash,
]);
$beforeHash = $sourceOrder ? (string) ($sourceOrder->bo_hash ?? '') : '';
$seedFilePath = $this->generateBarcodeSeedFile($uuid, $version, $lotNo, $orderData, $hashItems, $orderHash);
$blockPayload = [
'bo_idx' => $boIdx,
'bo_uuid' => $uuid,
'bo_version' => $version,
'bo_lot_no' => $lotNo,
'bo_hash' => $orderHash,
'seed_file' => $seedFilePath,
'hash_chain' => $beforeHash !== '' ? [$beforeHash, $orderHash] : [$orderHash],
'order' => $orderData,
'items' => $hashItems,
];
$ledger = new SqlLedger();
$ledger->appendBlock(
$sourceOrder ? 'ORDER_UPDATE' : 'ORDER_CREATE',
$blockPayload,
$uuid,
$version,
session()->get('mb_idx') ? (int) session()->get('mb_idx') : null,
$lgIdx
);
// CT-05: 감사 로그
helper('audit');
if ($sourceOrder) {
audit_log(
'update',
'bag_order',
$boIdx,
['bo_idx' => (int) $sourceOrder->bo_idx, 'bo_hash' => $beforeHash, 'bo_version' => (int) $sourceOrder->bo_version],
array_merge($orderData, ['bo_idx' => $boIdx, 'bo_hash' => $orderHash, 'items' => $hashItems, 'seed_file' => $seedFilePath])
);
} else {
audit_log('create', 'bag_order', $boIdx, null, array_merge($orderData, ['bo_idx' => $boIdx, 'bo_hash' => $orderHash, 'items' => $hashItems, 'seed_file' => $seedFilePath]));
}
if (! $db->transComplete()) {
throw new \RuntimeException('Transaction did not complete');
}
} catch (\Throwable $e) {
$db->transRollback();
log_message('error', 'BagOrder::store: ' . $e->getMessage() . ' @ ' . $e->getFile() . ':' . $e->getLine());
return redirect()->back()->withInput()->with('error', '발주 저장 중 오류가 발생했습니다. 잠시 후 다시 시도하거나 관리자에게 문의하세요.');
}
return redirect()->to(mgmt_url('bag-orders'))->with('success', '발주가 등록되었습니다. LOT: ' . $lotNo); return redirect()->to(mgmt_url('bag-orders'))->with('success', '발주가 등록되었습니다. LOT: ' . $lotNo);
} }
/** 효과 지자체(`local_government`)의 행정 구·군 코드(lg_code) */
private function resolveGugunCodeFromLg(int $lgIdx): string
{
$lg = model(LocalGovernmentModel::class)->find($lgIdx);
return $lg ? trim((string) ($lg->lg_code ?? '')) : '';
}
private function generateUuidV4(): string
{
$bytes = random_bytes(16);
$bytes[6] = chr((ord($bytes[6]) & 0x0f) | 0x40);
$bytes[8] = chr((ord($bytes[8]) & 0x3f) | 0x80);
return vsprintf('%s%s-%s-%s-%s-%s%s%s', str_split(bin2hex($bytes), 4));
}
private function generateLotNo6(): string
{
// 문서의 "LOT 번호 6 Byte" 요구를 맞추기 위해 영숫자 6자리로 생성한다.
// 충돌 가능성을 낮추기 위해 최대 20회 재시도 후 timestamp 기반으로 fallback.
$chars = '0123456789ABCDEFGHIJKLMNOPQRSTUVWXYZ';
for ($attempt = 0; $attempt < 20; $attempt++) {
$lot = '';
for ($i = 0; $i < 6; $i++) {
$lot .= $chars[random_int(0, strlen($chars) - 1)];
}
$exists = $this->orderModel->where('bo_lot_no', $lot)->countAllResults() > 0;
if (! $exists) {
return $lot;
}
}
return strtoupper(substr(base_convert((string) time(), 10, 36), -6));
}
/**
* @param array<string,mixed> $orderData
* @param array<int,array<string,mixed>> $items
*/
private function generateBarcodeSeedFile(string $uuid, int $version, string $lotNo, array $orderData, array $items, string $orderHash): string
{
$baseDir = WRITEPATH . 'barcode-seeds';
if (! is_dir($baseDir)) {
mkdir($baseDir, 0775, true);
}
$keyDir = WRITEPATH . 'keys';
if (! is_dir($keyDir)) {
mkdir($keyDir, 0775, true);
}
$privateKeyPath = $keyDir . DIRECTORY_SEPARATOR . 'barcode_seed_private.pem';
$publicKeyPath = $keyDir . DIRECTORY_SEPARATOR . 'barcode_seed_public.pem';
if (! is_file($privateKeyPath) || ! is_file($publicKeyPath)) {
$config = [
'private_key_bits' => 2048,
'private_key_type' => OPENSSL_KEYTYPE_RSA,
];
$resource = openssl_pkey_new($config);
if ($resource !== false) {
$privatePem = '';
openssl_pkey_export($resource, $privatePem);
$details = openssl_pkey_get_details($resource);
$publicPem = $details['key'] ?? '';
if ($privatePem !== '' && $publicPem !== '') {
file_put_contents($privateKeyPath, $privatePem);
file_put_contents($publicKeyPath, $publicPem);
}
}
}
$payload = [
'uuid' => $uuid,
'version' => $version,
'lot_no' => $lotNo,
'order_hash' => $orderHash,
'order' => $orderData,
'items' => $items,
];
$payloadJson = json_encode($payload, JSON_UNESCAPED_UNICODE | JSON_UNESCAPED_SLASHES) ?: '{}';
$aesKey = random_bytes(32);
$iv = random_bytes(16);
$cipherRaw = openssl_encrypt($payloadJson, 'AES-256-CBC', $aesKey, OPENSSL_RAW_DATA, $iv);
if ($cipherRaw === false) {
$cipherRaw = $payloadJson;
}
$encryptedKey = '';
$publicPem = is_file($publicKeyPath) ? file_get_contents($publicKeyPath) : '';
if (is_string($publicPem) && $publicPem !== '') {
openssl_public_encrypt($aesKey, $encryptedKey, $publicPem, OPENSSL_PKCS1_OAEP_PADDING);
}
$seed = [
'algorithm' => ['symmetric' => 'AES-256-CBC', 'asymmetric' => 'RSA-2048'],
'lot_no' => $lotNo,
'uuid' => $uuid,
'version' => $version,
'iv_b64' => base64_encode($iv),
'key_b64' => $encryptedKey !== '' ? base64_encode($encryptedKey) : '',
'cipher_b64' => base64_encode((string) $cipherRaw),
'payload_hash' => hash('sha256', $payloadJson),
'created_at' => date('c'),
];
$fileName = $lotNo . '_v' . $version . '.seed.json';
$fullPath = $baseDir . DIRECTORY_SEPARATOR . $fileName;
file_put_contents($fullPath, json_encode($seed, JSON_PRETTY_PRINT | JSON_UNESCAPED_UNICODE | JSON_UNESCAPED_SLASHES));
return $fullPath;
}
public function detail(int $id) public function detail(int $id)
{ {
helper('admin'); helper('admin');
@@ -250,9 +815,11 @@ class BagOrder extends BaseController
} }
$before = (array) $order; $before = (array) $order;
$this->orderModel->update($id, ['bo_status' => 'cancelled', 'bo_moddate' => date('Y-m-d H:i:s')]); $beforeHash = (string) ($order->bo_hash ?? '');
$this->appendLedgerForStatusChange($order, $id, 'ORDER_CANCEL', 'cancelled', $beforeHash);
$after = (array) $this->orderModel->find($id);
helper('audit'); helper('audit');
audit_log('update', 'bag_order', $id, $before, ['bo_status' => 'cancelled']); audit_log('update', 'bag_order', $id, $before, $after);
return redirect()->to(mgmt_url('bag-orders'))->with('success', '발주가 취소되었습니다.'); return redirect()->to(mgmt_url('bag-orders'))->with('success', '발주가 취소되었습니다.');
} }
@@ -266,10 +833,117 @@ class BagOrder extends BaseController
} }
$before = (array) $order; $before = (array) $order;
$this->orderModel->update($id, ['bo_status' => 'deleted', 'bo_moddate' => date('Y-m-d H:i:s')]); $beforeHash = (string) ($order->bo_hash ?? '');
$this->appendLedgerForStatusChange($order, $id, 'ORDER_DELETE', 'deleted', $beforeHash);
$after = (array) $this->orderModel->find($id);
helper('audit'); helper('audit');
audit_log('delete', 'bag_order', $id, $before, ['bo_status' => 'deleted']); audit_log('delete', 'bag_order', $id, $before, $after);
return redirect()->to(mgmt_url('bag-orders'))->with('success', '발주가 삭제 처리되었습니다.'); return redirect()->to(mgmt_url('bag-orders'))->with('success', '발주가 삭제 처리되었습니다.');
} }
/**
* 상태 변경 시(취소/삭제) 무결성 검증을 위해 bo_hash 재계산 후
* SQL-Ledger(append-only)에 블록을 추가한다.
*
* @param object $order
* @param int $boIdx
* @param string $txType ORDER_CANCEL|ORDER_DELETE
* @param string $newStatus cancelled|deleted
* @param string $previousHash
*/
private function appendLedgerForStatusChange(object $order, int $boIdx, string $txType, string $newStatus, string $previousHash): void
{
// 품목은 상태 변경 시 그대로이므로, 동일 payload 형태로 items array를 만든다.
$items = $this->itemModel->where('boi_bo_idx', $boIdx)->findAll();
$hashItems = [];
foreach ($items as $it) {
$hashItems[] = [
'boi_bo_idx' => (int) $it->boi_bo_idx,
'boi_bag_code' => (string) $it->boi_bag_code,
'boi_bag_name' => (string) ($it->boi_bag_name ?? ''),
'boi_unit_price' => (float) $it->boi_unit_price,
'boi_qty_box' => (int) $it->boi_qty_box,
'boi_qty_sheet' => (int) $it->boi_qty_sheet,
'boi_amount' => (float) $it->boi_amount,
];
}
$newOrder = $order;
$newOrder->bo_status = $newStatus;
$newHash = $this->computeOrderHash($boIdx, $newOrder, $hashItems);
$actorIdx = session()->get('mb_idx') ? (int) session()->get('mb_idx') : null;
$lgIdx = (int) ($order->bo_lg_idx ?? 0);
$seedFilePath = '';
$ledgerPayload = [
'bo_idx' => $boIdx,
'bo_uuid' => (string) $order->bo_uuid,
'bo_version' => (int) $order->bo_version,
'bo_lot_no' => (string) $order->bo_lot_no,
'bo_hash' => $newHash,
'seed_file' => $seedFilePath,
'hash_chain' => [$previousHash, $newHash],
'order' => [
'bo_status' => $newStatus,
'bo_hash' => $newHash,
],
'items' => $hashItems,
];
$ledger = new SqlLedger();
$ledger->appendBlock(
$txType,
$ledgerPayload,
(string) $order->bo_uuid,
(int) $order->bo_version,
$actorIdx,
$lgIdx
);
// order row에 hash 반영
$this->orderModel->update($boIdx, [
'bo_status' => $newStatus,
'bo_moddate' => date('Y-m-d H:i:s'),
'bo_hash' => $newHash,
]);
}
/**
* store()에서 생성하는 bo_hash와 동일한 "헤더+items" 규격을 사용해 SHA-256을 계산한다.
*
* @param int $boIdx
* @param object $order
* @param array<int,array<string,mixed>> $hashItems
*/
private function computeOrderHash(int $boIdx, object $order, array $hashItems): string
{
$orderData = [
'bo_uuid' => (string) $order->bo_uuid,
'bo_version' => (int) $order->bo_version,
'bo_lg_idx' => (int) $order->bo_lg_idx,
'bo_gugun_code' => (string) ($order->bo_gugun_code ?? ''),
'bo_dong_code' => (string) ($order->bo_dong_code ?? ''),
'bo_company_idx' => $order->bo_company_idx !== null ? (int) $order->bo_company_idx : null,
'bo_agency_idx' => $order->bo_agency_idx !== null ? (int) $order->bo_agency_idx : null,
'bo_fee_rate' => (float) ($order->bo_fee_rate ?? 0),
'bo_order_date' => (string) $order->bo_order_date,
'bo_bag_types' => (string) ($order->bo_bag_types ?? ''),
'bo_unit_prices' => (string) ($order->bo_unit_prices ?? ''),
'bo_qty_boxes' => (string) ($order->bo_qty_boxes ?? ''),
'bo_lot_no' => (string) $order->bo_lot_no,
'bo_hash' => '',
'bo_status' => (string) $order->bo_status,
'bo_orderer_idx' => $order->bo_orderer_idx !== null ? (int) $order->bo_orderer_idx : null,
'bo_regdate' => (string) ($order->bo_regdate ?? ''),
];
$hashPayload = $orderData;
$hashPayload['bo_idx'] = $boIdx;
$hashPayload['items'] = $hashItems;
$hashJson = json_encode($hashPayload, JSON_UNESCAPED_UNICODE | JSON_UNESCAPED_SLASHES);
return hash('sha256', $hashJson !== false ? $hashJson : (string) $boIdx);
}
} }

View File

@@ -27,14 +27,143 @@ class BagPrice extends BaseController
return redirect()->to(work_area_home_url())->with('error', '지자체를 선택해 주세요.'); return redirect()->to(work_area_home_url())->with('error', '지자체를 선택해 주세요.');
} }
$list = $this->priceModel->where('bp_lg_idx', $lgIdx) $get = $this->request->getGet();
$readSrc = static function (array $src, string $key): ?string {
if (! array_key_exists($key, $src)) {
return null;
}
$v = $src[$key];
if ($v === null || is_array($v)) {
return null;
}
$s = trim((string) $v);
return $s === '' ? null : $s;
};
$sy = $readSrc($get, 'start_y');
$sm = $readSrc($get, 'start_m');
$sd = $readSrc($get, 'start_d');
$ey = $readSrc($get, 'end_y');
$em = $readSrc($get, 'end_m');
$ed = $readSrc($get, 'end_d');
$startDate = null;
if ($sy !== null && $sy !== '' && $sm !== null && $sm !== '' && $sd !== null && $sd !== '') {
$startDate = parse_ymd_from_triple($sy, $sm, $sd);
}
if ($startDate === null) {
$legacyStart = $readSrc($get, 'start_date');
$startDate = ($legacyStart !== null && $legacyStart !== '') ? $legacyStart : null;
}
$endDate = null;
if ($ey !== null && $ey !== '' && $em !== null && $em !== '' && $ed !== null && $ed !== '') {
$endDate = parse_ymd_from_triple($ey, $em, $ed);
}
if ($endDate === null) {
$legacyEnd = $readSrc($get, 'end_date');
$endDate = ($legacyEnd !== null && $legacyEnd !== '') ? $legacyEnd : null;
}
$startParts = ['y' => '', 'm' => '', 'd' => ''];
$endParts = ['y' => '', 'm' => '', 'd' => ''];
if ($startDate !== null && preg_match('/^(\d{4})-(\d{2})-(\d{2})$/', $startDate, $m)) {
$startParts = ['y' => $m[1], 'm' => (int) $m[2], 'd' => (int) $m[3]];
}
if ($endDate !== null && preg_match('/^(\d{4})-(\d{2})-(\d{2})$/', $endDate, $m)) {
$endParts = ['y' => $m[1], 'm' => (int) $m[2], 'd' => (int) $m[3]];
}
$bagKindE = $readSrc($get, 'bag_kind_e');
$bagCode = $readSrc($get, 'bag_code');
$builder = $this->priceModel->where('bp_lg_idx', $lgIdx);
if (($startDate !== null && $startDate !== '') || ($endDate !== null && $endDate !== '')) {
$qStart = ($startDate !== null && $startDate !== '') ? $startDate : $endDate;
$qEnd = ($endDate !== null && $endDate !== '') ? $endDate : $startDate;
if (strcmp((string) $qStart, (string) $qEnd) > 0) {
[$qStart, $qEnd] = [$qEnd, $qStart];
}
$builder->where('bp_start_date <=', $qEnd);
$builder->groupStart()
->where('bp_end_date IS NULL')
->orWhere('bp_end_date >=', $qStart)
->groupEnd();
}
if ($bagKindE !== null && $bagKindE !== '') {
$kindE = model(CodeKindModel::class)->where('ck_code', 'E')->first();
if ($kindE) {
$detailE = model(CodeDetailModel::class)
->where('cd_ck_idx', (int) $kindE->ck_idx)
->where('cd_code', $bagKindE)
->where('cd_state', 1)
->first();
if ($detailE !== null) {
$builder->like('bp_bag_code', $bagKindE, 'after');
}
}
}
if ($bagCode !== null && $bagCode !== '') {
$kindO = model(CodeKindModel::class)->where('ck_code', 'O')->first();
if ($kindO) {
$detailO = model(CodeDetailModel::class)->findResolvedByKindAndCode((int) $kindO->ck_idx, $bagCode, $lgIdx);
if ($detailO !== null) {
$builder->where('bp_bag_code', $bagCode);
}
}
}
$list = $builder
->orderBy('bp_bag_code', 'ASC') ->orderBy('bp_bag_code', 'ASC')
->orderBy('bp_start_date', 'DESC') ->orderBy('bp_start_date', 'DESC')
->paginate(20); ->paginate(20);
$queryForPager = [];
if ($sy !== null && $sm !== null && $sd !== null && $sy !== '' && $sm !== '' && $sd !== '') {
$queryForPager['start_y'] = $sy;
$queryForPager['start_m'] = $sm;
$queryForPager['start_d'] = $sd;
}
if ($ey !== null && $em !== null && $ed !== null && $ey !== '' && $em !== '' && $ed !== '') {
$queryForPager['end_y'] = $ey;
$queryForPager['end_m'] = $em;
$queryForPager['end_d'] = $ed;
}
if ($bagKindE !== null && $bagKindE !== '') {
$queryForPager['bag_kind_e'] = $bagKindE;
}
if ($bagCode !== null && $bagCode !== '') {
$queryForPager['bag_code'] = $bagCode;
}
$pagerPath = mgmt_url('bag-prices');
if ($queryForPager !== []) {
$pagerPath .= '?' . http_build_query($queryForPager);
}
$this->priceModel->pager->setPath($pagerPath);
$kindO = model(CodeKindModel::class)->where('ck_code', 'O')->first();
$bagCodes = $kindO
? model(CodeDetailModel::class)->getByKind((int) $kindO->ck_idx, true, $lgIdx)
: [];
$kindE = model(CodeKindModel::class)->where('ck_code', 'E')->first();
$bagKindOptions = $kindE
? model(CodeDetailModel::class)->getByKind((int) $kindE->ck_idx, true, null)
: [];
return $this->renderWorkPage('봉투 단가 관리', 'admin/bag_price/index', [ return $this->renderWorkPage('봉투 단가 관리', 'admin/bag_price/index', [
'list' => $list, 'list' => $list,
'pager' => $this->priceModel->pager, 'pager' => $this->priceModel->pager,
'startParts' => $startParts,
'endParts' => $endParts,
'dateYearMin' => (int) date('Y') - 12,
'dateYearMax' => (int) date('Y') + 2,
'bag_kind_e' => $bagKindE,
'bag_code' => $bagCode,
'bag_codes' => $bagCodes,
'bag_kind_options' => $bagKindOptions,
]); ]);
} }

View File

@@ -133,7 +133,7 @@ class BagSale extends BaseController
$shop = model(DesignatedShopModel::class)->find($dsIdx); $shop = model(DesignatedShopModel::class)->find($dsIdx);
$kindO = model(CodeKindModel::class)->where('ck_code', 'O')->first(); $kindO = model(CodeKindModel::class)->where('ck_code', 'O')->first();
$detail = $kindO ? model(CodeDetailModel::class)->findResolvedByKindAndCode((int) $kindO->ck_idx, (string) $bagCode, $lgIdx) : null; $detail = $kindO ? model(CodeDetailModel::class)->findResolvedByKindAndCode((int) $kindO->ck_idx, (string) $bagCode, $lgIdx) : null;
$price = model(BagPriceModel::class)->where('bp_lg_idx', $lgIdx)->where('bp_bag_code', $bagCode)->where('bp_state', 1)->first(); $price = model(BagPriceModel::class)->latestActiveByBagCode($lgIdx, (string) $bagCode);
$unitPrice = $price ? (float) $price->bp_consumer : 0; $unitPrice = $price ? (float) $price->bp_consumer : 0;
$actualQty = ($type === 'return') ? -$qty : $qty; $actualQty = ($type === 'return') ? -$qty : $qty;

View File

@@ -9,6 +9,11 @@ class Company extends BaseController
{ {
private CompanyModel $model; private CompanyModel $model;
private function companyTypeOptions(): array
{
return ['협회', '제작업체', '회수업체'];
}
public function __construct() public function __construct()
{ {
$this->model = model(CompanyModel::class); $this->model = model(CompanyModel::class);
@@ -22,10 +27,33 @@ class Company extends BaseController
return redirect()->to(work_area_home_url())->with('error', '지자체를 선택해 주세요.'); return redirect()->to(work_area_home_url())->with('error', '지자체를 선택해 주세요.');
} }
$list = $this->model->where('cp_lg_idx', $lgIdx)->orderBy('cp_idx', 'DESC')->paginate(20); $companyType = trim((string) ($this->request->getGet('cp_type') ?? ''));
$typeOptions = $this->companyTypeOptions();
$builder = $this->model->where('cp_lg_idx', $lgIdx);
if ($companyType !== '' && in_array($companyType, $typeOptions, true)) {
$builder->where('cp_type', $companyType);
}
$list = $builder->orderBy('cp_idx', 'DESC')->paginate(20);
$pager = $this->model->pager; $pager = $this->model->pager;
return $this->renderWorkPage('업체 관리', 'admin/company/index', ['list' => $list, 'pager' => $pager]); $queryForPager = [];
if ($companyType !== '' && in_array($companyType, $typeOptions, true)) {
$queryForPager['cp_type'] = $companyType;
}
$pagerPath = mgmt_url('companies');
if ($queryForPager !== []) {
$pagerPath .= '?' . http_build_query($queryForPager);
}
$pager->setPath($pagerPath);
return $this->renderWorkPage('업체 관리', 'admin/company/index', [
'list' => $list,
'pager' => $pager,
'cpType' => $companyType,
'typeOptions' => $typeOptions,
]);
} }
public function create() public function create()

View File

@@ -227,6 +227,9 @@ class DesignatedShop extends BaseController
*/ */
private function buildDesignatedShopDetailPayload(array $list, array $lgMap): array private function buildDesignatedShopDetailPayload(array $list, array $lgMap): array
{ {
helper('admin');
$lgIdx = admin_effective_lg_idx() ?? 0;
$gugunMap = $lgIdx > 0 ? $this->gugunCodeNameMap($lgIdx) : [];
$payload = []; $payload = [];
foreach ($list as $row) { foreach ($list as $row) {
$sn = (string) ($row->ds_shop_no ?? ''); $sn = (string) ($row->ds_shop_no ?? '');
@@ -263,6 +266,7 @@ class DesignatedShop extends BaseController
'ds_rep_phone' => (string) ($row->ds_rep_phone ?? ''), 'ds_rep_phone' => (string) ($row->ds_rep_phone ?? ''),
'ds_email' => (string) ($row->ds_email ?? ''), 'ds_email' => (string) ($row->ds_email ?? ''),
'ds_gugun_code' => (string) ($row->ds_gugun_code ?? ''), 'ds_gugun_code' => (string) ($row->ds_gugun_code ?? ''),
'gugun_name' => $gugunMap[(string) ($row->ds_gugun_code ?? '')] ?? (string) ($row->ds_gugun_code ?? ''),
'ds_zone_code' => $this->designatedShopScalar($row, 'ds_zone_code'), 'ds_zone_code' => $this->designatedShopScalar($row, 'ds_zone_code'),
'ds_branch_no' => $this->designatedShopScalar($row, 'ds_branch_no'), 'ds_branch_no' => $this->designatedShopScalar($row, 'ds_branch_no'),
'ds_designated_at' => $daOut, 'ds_designated_at' => $daOut,
@@ -306,6 +310,7 @@ class DesignatedShop extends BaseController
} }
$stateCounts = $this->countDesignatedShopsByState($lgIdx, $dsName, $dsGugunCode, $dsState); $stateCounts = $this->countDesignatedShopsByState($lgIdx, $dsName, $dsGugunCode, $dsState);
$gugunNameMap = $this->gugunCodeNameMap($lgIdx);
$detailRows = $this->buildDesignatedShopDetailPayload($list, $lgMap); $detailRows = $this->buildDesignatedShopDetailPayload($list, $lgMap);
// 구군코드 목록 (검색 필터용) // 구군코드 목록 (검색 필터용)
@@ -321,6 +326,7 @@ class DesignatedShop extends BaseController
'dsState' => $dsState ?? '', 'dsState' => $dsState ?? '',
'gugunCodes' => $gugunCodes, 'gugunCodes' => $gugunCodes,
'stateCounts' => $stateCounts, 'stateCounts' => $stateCounts,
'gugunNameMap' => $gugunNameMap,
'detailRowsJson' => json_encode($detailRows, JSON_HEX_TAG | JSON_HEX_APOS | JSON_HEX_QUOT | JSON_UNESCAPED_UNICODE), 'detailRowsJson' => json_encode($detailRows, JSON_HEX_TAG | JSON_HEX_APOS | JSON_HEX_QUOT | JSON_UNESCAPED_UNICODE),
'kakaoJavascriptKey' => $this->kakaoJavascriptKey(), 'kakaoJavascriptKey' => $this->kakaoJavascriptKey(),
]; ];
@@ -336,6 +342,7 @@ class DesignatedShop extends BaseController
return redirect()->to(work_area_home_url()) return redirect()->to(work_area_home_url())
->with('error', '작업할 지자체가 선택되지 않았습니다. 지자체를 선택해 주세요.'); ->with('error', '작업할 지자체가 선택되지 않았습니다. 지자체를 선택해 주세요.');
} }
$data['readOnly'] = false;
return $this->renderWorkPage('지정판매소 관리', 'admin/designated_shop/index', $data); return $this->renderWorkPage('지정판매소 관리', 'admin/designated_shop/index', $data);
} }
@@ -352,7 +359,7 @@ class DesignatedShop extends BaseController
} }
$data['readOnly'] = true; $data['readOnly'] = true;
return $this->renderWorkPage('지정판매소 조회', 'admin/designated_shop/index', $data); return $this->renderWorkPage('지정판매소 조회', 'admin/designated_shop/manage', $data);
} }
/** /**

View File

@@ -25,6 +25,15 @@ class Manager extends BaseController
return $kind ? model(CodeDetailModel::class)->getByKind((int) $kind->ck_idx, true, $lgIdx) : []; return $kind ? model(CodeDetailModel::class)->getByKind((int) $kind->ck_idx, true, $lgIdx) : [];
} }
private function managerCategoryOptions(): array
{
return [
'company' => '제작업체',
'district' => '구·군',
'agency' => '대행소',
];
}
public function index() public function index()
{ {
helper('admin'); helper('admin');
@@ -35,16 +44,29 @@ class Manager extends BaseController
return redirect()->to(work_area_home_url())->with('error', '지자체를 선택해 주세요.'); return redirect()->to(work_area_home_url())->with('error', '지자체를 선택해 주세요.');
} }
$list = $this->model->where('mg_lg_idx', $lgIdx)->orderBy('mg_idx', 'DESC')->paginate(20); $category = (string) ($this->request->getGet('category') ?? '');
$categories = $this->managerCategoryOptions();
$builder = $this->model->where('mg_lg_idx', $lgIdx);
if ($category !== '' && isset($categories[$category])) {
$builder->where('mg_dept_code', $category);
}
$list = $builder->orderBy('mg_idx', 'DESC')->paginate(20);
$pager = $this->model->pager; $pager = $this->model->pager;
return $this->renderWorkPage('담당자 관리', 'admin/manager/index', ['list' => $list, 'pager' => $pager]); return $this->renderWorkPage('담당자 관리', 'admin/manager/index', [
'list' => $list,
'pager' => $pager,
'categories' => $categories,
'category' => $category,
]);
} }
public function create() public function create()
{ {
return $this->renderWorkPage('담당자 등록', 'admin/manager/create', [ return $this->renderWorkPage('담당자 등록', 'admin/manager/create', [
'deptCodes' => $this->getCodeOptions('S'), 'categories' => $this->managerCategoryOptions(),
'positionCodes' => $this->getCodeOptions('T'), 'positionCodes' => $this->getCodeOptions('T'),
]); ]);
} }
@@ -54,6 +76,7 @@ class Manager extends BaseController
helper(['admin', 'url']); helper(['admin', 'url']);
$rules = [ $rules = [
'mg_name' => 'required|max_length[50]', 'mg_name' => 'required|max_length[50]',
'mg_category' => 'required|in_list[company,district,agency]',
'mg_tel' => 'permit_empty|max_length[20]', 'mg_tel' => 'permit_empty|max_length[20]',
'mg_phone' => 'permit_empty|max_length[20]', 'mg_phone' => 'permit_empty|max_length[20]',
'mg_email' => 'permit_empty|valid_email|max_length[100]', 'mg_email' => 'permit_empty|valid_email|max_length[100]',
@@ -65,7 +88,7 @@ class Manager extends BaseController
$this->model->insert([ $this->model->insert([
'mg_lg_idx' => admin_effective_lg_idx(), 'mg_lg_idx' => admin_effective_lg_idx(),
'mg_name' => $this->request->getPost('mg_name'), 'mg_name' => $this->request->getPost('mg_name'),
'mg_dept_code' => $this->request->getPost('mg_dept_code') ?? '', 'mg_dept_code' => (string) ($this->request->getPost('mg_category') ?? ''),
'mg_position_code' => $this->request->getPost('mg_position_code') ?? '', 'mg_position_code' => $this->request->getPost('mg_position_code') ?? '',
'mg_tel' => $this->request->getPost('mg_tel') ?? '', 'mg_tel' => $this->request->getPost('mg_tel') ?? '',
'mg_phone' => $this->request->getPost('mg_phone') ?? '', 'mg_phone' => $this->request->getPost('mg_phone') ?? '',
@@ -87,7 +110,7 @@ class Manager extends BaseController
return $this->renderWorkPage('담당자 수정', 'admin/manager/edit', [ return $this->renderWorkPage('담당자 수정', 'admin/manager/edit', [
'item' => $item, 'item' => $item,
'deptCodes' => $this->getCodeOptions('S'), 'categories' => $this->managerCategoryOptions(),
'positionCodes' => $this->getCodeOptions('T'), 'positionCodes' => $this->getCodeOptions('T'),
]); ]);
} }
@@ -102,6 +125,7 @@ class Manager extends BaseController
$rules = [ $rules = [
'mg_name' => 'required|max_length[50]', 'mg_name' => 'required|max_length[50]',
'mg_category' => 'required|in_list[company,district,agency]',
'mg_state' => 'required|in_list[0,1]', 'mg_state' => 'required|in_list[0,1]',
]; ];
if (! $this->validate($rules)) { if (! $this->validate($rules)) {
@@ -110,7 +134,7 @@ class Manager extends BaseController
$this->model->update($id, [ $this->model->update($id, [
'mg_name' => $this->request->getPost('mg_name'), 'mg_name' => $this->request->getPost('mg_name'),
'mg_dept_code' => $this->request->getPost('mg_dept_code') ?? '', 'mg_dept_code' => (string) ($this->request->getPost('mg_category') ?? ''),
'mg_position_code' => $this->request->getPost('mg_position_code') ?? '', 'mg_position_code' => $this->request->getPost('mg_position_code') ?? '',
'mg_tel' => $this->request->getPost('mg_tel') ?? '', 'mg_tel' => $this->request->getPost('mg_tel') ?? '',
'mg_phone' => $this->request->getPost('mg_phone') ?? '', 'mg_phone' => $this->request->getPost('mg_phone') ?? '',

View File

@@ -143,14 +143,31 @@ class PackagingUnit extends BaseController
$db = \Config\Database::connect(); $db = \Config\Database::connect();
$db->transStart(); $db->transStart();
$trackFields = ['pu_box_per_pack', 'pu_pack_per_sheet']; $trackFields = ['pu_box_per_pack', 'pu_pack_per_sheet', 'pu_start_date', 'pu_end_date', 'pu_state'];
$fieldLabels = [
'pu_box_per_pack' => '박스당 팩 수',
'pu_pack_per_sheet' => '팩당 낱장 수',
'pu_start_date' => '적용시작일',
'pu_end_date' => '적용종료일',
'pu_state' => '상태',
];
foreach ($trackFields as $field) { foreach ($trackFields as $field) {
$oldVal = (string) $item->$field; $oldRaw = $item->$field;
$newVal = (string) $this->request->getPost($field); $newRaw = $this->request->getPost($field);
if ($field === 'pu_end_date') {
$oldRaw = $oldRaw ?: '';
$newRaw = $newRaw ?: '';
}
if ($field === 'pu_state') {
$oldRaw = (int) $oldRaw === 1 ? '사용' : '미사용';
$newRaw = (int) $newRaw === 1 ? '사용' : '미사용';
}
$oldVal = (string) $oldRaw;
$newVal = (string) $newRaw;
if ($oldVal !== $newVal) { if ($oldVal !== $newVal) {
$this->historyModel->insert([ $this->historyModel->insert([
'puh_pu_idx' => $id, 'puh_pu_idx' => $id,
'puh_field' => $field, 'puh_field' => $fieldLabels[$field] ?? $field,
'puh_old_value' => $oldVal, 'puh_old_value' => $oldVal,
'puh_new_value' => $newVal, 'puh_new_value' => $newVal,
'puh_changed_at' => date('Y-m-d H:i:s'), 'puh_changed_at' => date('Y-m-d H:i:s'),

View File

@@ -105,7 +105,7 @@ class ShopOrder extends BaseController
} }
$qty = (int) $qtys[$i]; $qty = (int) $qtys[$i];
$price = model(BagPriceModel::class)->where('bp_lg_idx', $lgIdx)->where('bp_bag_code', $code)->where('bp_state', 1)->first(); $price = model(BagPriceModel::class)->latestActiveByBagCode($lgIdx, (string) $code);
$unitPrice = $price ? (float) $price->bp_consumer : 0; $unitPrice = $price ? (float) $price->bp_consumer : 0;
$amount = $unitPrice * $qty; $amount = $unitPrice * $qty;

File diff suppressed because it is too large Load Diff

View File

@@ -16,4 +16,45 @@ class BagPriceModel extends Model
'bp_start_date', 'bp_end_date', 'bp_state', 'bp_start_date', 'bp_end_date', 'bp_state',
'bp_regdate', 'bp_moddate', 'bp_reg_mb_idx', 'bp_regdate', 'bp_moddate', 'bp_reg_mb_idx',
]; ];
/**
* 같은 봉투코드에 단가 기간이 겹쳐도 "나중 등록 단가"가 우선되도록
* 활성 단가를 등록일/PK 역순으로 정렬해 봉투코드별 1건만 남긴다.
*
* @return array<string, object>
*/
public function latestActiveMapByBagCode(int $lgIdx): array
{
$rows = $this->where('bp_lg_idx', $lgIdx)
->where('bp_state', 1)
->orderBy('bp_regdate', 'DESC')
->orderBy('bp_idx', 'DESC')
->findAll();
$map = [];
foreach ($rows as $row) {
$code = (string) ($row->bp_bag_code ?? '');
if ($code === '' || isset($map[$code])) {
continue;
}
$map[$code] = $row;
}
return $map;
}
public function latestActiveByBagCode(int $lgIdx, string $bagCode): ?object
{
$bagCode = trim($bagCode);
if ($bagCode === '') {
return null;
}
return $this->where('bp_lg_idx', $lgIdx)
->where('bp_bag_code', $bagCode)
->where('bp_state', 1)
->orderBy('bp_regdate', 'DESC')
->orderBy('bp_idx', 'DESC')
->first();
}
} }

View File

@@ -1,4 +1,4 @@
<?= view('components/print_header', ['printTitle' => '봉투 단가 관리']) ?> <?= view('components/print_header', ['printTitle' => '봉투 단가 관리', 'printShowApproval' => false]) ?>
<style> <style>
@media print { @media print {
.no-print { display: none !important; } .no-print { display: none !important; }
@@ -9,12 +9,91 @@
<span class="text-sm font-bold text-gray-700">봉투 단가 관리</span> <span class="text-sm font-bold text-gray-700">봉투 단가 관리</span>
<div class="flex items-center gap-2 no-print"> <div class="flex items-center gap-2 no-print">
<button onclick="window.print()" class="border border-btn-print-border text-gray-600 px-3 py-1 rounded-sm text-sm hover:bg-gray-50 transition">인쇄</button> <button onclick="window.print()" class="border border-btn-print-border text-gray-600 px-3 py-1 rounded-sm text-sm hover:bg-gray-50 transition">인쇄</button>
<a href="<?= base_url('bag/prices') ?>" class="text-blue-600 hover:underline text-sm">단가 조회·검색</a>
<a href="<?= mgmt_url('bag-prices/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> <a href="<?= mgmt_url('bag-prices/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> </div>
</div> </div>
</section> </section>
<p class="text-xs text-gray-500 mt-2 no-print">목록·등록·수정·삭제는 이 화면에서, <strong>기간·봉투별 조회·인쇄</strong>는 <a href="<?= base_url('bag/prices') ?>" class="text-blue-600 hover:underline">봉투 단가(조회)</a>에서 이용하세요.</p> <section class="no-print border border-gray-200 rounded-lg bg-white p-3 mt-2">
<form method="get" action="<?= mgmt_url('bag-prices') ?>" class="flex flex-wrap items-end gap-3" autocomplete="off">
<div class="flex flex-col gap-0.5">
<label class="text-xs text-gray-500">봉투구분</label>
<select name="bag_kind_e" class="border border-gray-300 rounded px-2 py-1.5 text-sm min-w-[9rem]">
<option value="">전체</option>
<?php foreach ($bag_kind_options ?? [] as $cd): ?>
<option value="<?= esc($cd->cd_code) ?>" <?= (string) ($cd->cd_code ?? '') === (string) ($bag_kind_e ?? '') ? 'selected' : '' ?>>
<?= esc($cd->cd_name) ?>
</option>
<?php endforeach; ?>
</select>
</div>
<div class="flex flex-col gap-0.5">
<label class="text-xs text-gray-500">봉투코드</label>
<select name="bag_code" class="border border-gray-300 rounded px-2 py-1.5 text-sm min-w-[11rem]">
<option value="">전체</option>
<?php foreach ($bag_codes ?? [] as $cd): ?>
<option value="<?= esc($cd->cd_code) ?>" <?= (string) ($cd->cd_code ?? '') === (string) ($bag_code ?? '') ? 'selected' : '' ?>>
<?= esc($cd->cd_code) ?> — <?= esc($cd->cd_name) ?>
</option>
<?php endforeach; ?>
</select>
</div>
<div class="flex flex-col gap-0.5">
<label class="text-xs text-gray-500">조회 기간 (적용기간 겹침)</label>
<?php
$sp = $startParts ?? ['y' => '', 'm' => '', 'd' => ''];
$ep = $endParts ?? ['y' => '', 'm' => '', 'd' => ''];
$ymin = (int) ($dateYearMin ?? ((int) date('Y') - 12));
$ymax = (int) ($dateYearMax ?? ((int) date('Y') + 2));
?>
<div class="flex flex-wrap items-center gap-1">
<span class="text-xs text-gray-500 mr-0.5">시작</span>
<select name="start_y" class="border border-gray-300 rounded px-1.5 py-1.5 text-sm min-w-[4.5rem]">
<option value="">연도</option>
<?php for ($yy = $ymin; $yy <= $ymax; $yy++): ?>
<option value="<?= $yy ?>" <?= (string) ($sp['y'] ?? '') === (string) $yy ? 'selected' : '' ?>><?= $yy ?></option>
<?php endfor; ?>
</select>
<select name="start_m" class="border border-gray-300 rounded px-1.5 py-1.5 text-sm min-w-[3.75rem]">
<option value="">월</option>
<?php for ($mi = 1; $mi <= 12; $mi++): ?>
<option value="<?= $mi ?>" <?= isset($sp['m']) && (int) $sp['m'] === $mi ? 'selected' : '' ?>><?= $mi ?>월</option>
<?php endfor; ?>
</select>
<select name="start_d" class="border border-gray-300 rounded px-1.5 py-1.5 text-sm min-w-[3.75rem]">
<option value="">일</option>
<?php for ($di = 1; $di <= 31; $di++): ?>
<option value="<?= $di ?>" <?= isset($sp['d']) && (int) $sp['d'] === $di ? 'selected' : '' ?>><?= $di ?>일</option>
<?php endfor; ?>
</select>
<span class="text-sm text-gray-500 mx-0.5">~</span>
<span class="text-xs text-gray-500 mr-0.5">종료</span>
<select name="end_y" class="border border-gray-300 rounded px-1.5 py-1.5 text-sm min-w-[4.5rem]">
<option value="">연도</option>
<?php for ($yy = $ymin; $yy <= $ymax; $yy++): ?>
<option value="<?= $yy ?>" <?= (string) ($ep['y'] ?? '') === (string) $yy ? 'selected' : '' ?>><?= $yy ?></option>
<?php endfor; ?>
</select>
<select name="end_m" class="border border-gray-300 rounded px-1.5 py-1.5 text-sm min-w-[3.75rem]">
<option value="">월</option>
<?php for ($mi = 1; $mi <= 12; $mi++): ?>
<option value="<?= $mi ?>" <?= isset($ep['m']) && (int) $ep['m'] === $mi ? 'selected' : '' ?>><?= $mi ?>월</option>
<?php endfor; ?>
</select>
<select name="end_d" class="border border-gray-300 rounded px-1.5 py-1.5 text-sm min-w-[3.75rem]">
<option value="">일</option>
<?php for ($di = 1; $di <= 31; $di++): ?>
<option value="<?= $di ?>" <?= isset($ep['d']) && (int) $ep['d'] === $di ? 'selected' : '' ?>><?= $di ?>일</option>
<?php endfor; ?>
</select>
</div>
</div>
<div class="flex items-center gap-2 pb-0.5">
<button type="submit" class="bg-btn-search text-white px-4 py-1.5 rounded-sm text-sm">조회</button>
<a href="<?= mgmt_url('bag-prices') ?>" class="text-sm text-gray-500 hover:underline">초기화</a>
<button type="button" onclick="window.print()" class="border border-gray-300 text-gray-700 px-3 py-1.5 rounded-sm text-sm hover:bg-gray-50">인쇄</button>
</div>
</form>
</section>
<div class="border border-gray-300 overflow-auto mt-2"> <div class="border border-gray-300 overflow-auto mt-2">
<table class="w-full data-table"> <table class="w-full data-table">
<thead> <thead>
@@ -32,9 +111,17 @@
</tr> </tr>
</thead> </thead>
<tbody class="text-right"> <tbody class="text-right">
<?php foreach ($list as $row): ?> <?php
$startNo = 1;
if (isset($pager) && method_exists($pager, 'getCurrentPage') && method_exists($pager, 'getPerPage')) {
$currentPage = (int) $pager->getCurrentPage();
$perPage = (int) $pager->getPerPage();
$startNo = (($currentPage > 0 ? $currentPage : 1) - 1) * ($perPage > 0 ? $perPage : 20) + 1;
}
?>
<?php foreach (($list ?? []) as $idx => $row): ?>
<tr> <tr>
<td class="text-center"><?= esc($row->bp_idx) ?></td> <td class="text-center"><?= (int) $startNo + (int) $idx ?></td>
<td class="text-center font-mono"><?= esc($row->bp_bag_code) ?></td> <td class="text-center font-mono"><?= esc($row->bp_bag_code) ?></td>
<td class="text-left pl-2"><?= esc($row->bp_bag_name) ?></td> <td class="text-left pl-2"><?= esc($row->bp_bag_name) ?></td>
<td><?= number_format((float) $row->bp_order_price) ?></td> <td><?= number_format((float) $row->bp_order_price) ?></td>

View File

@@ -8,6 +8,19 @@
</div> </div>
</div> </div>
</section> </section>
<section class="p-2 bg-white border-b border-gray-200 no-print">
<form method="GET" action="<?= mgmt_url('companies') ?>" class="flex flex-wrap items-center gap-2">
<label class="text-sm text-gray-600">업체유형</label>
<select name="cp_type" class="border border-gray-300 rounded px-2 py-1 text-sm w-44">
<option value="">전 체</option>
<?php foreach (($typeOptions ?? []) as $type): ?>
<option value="<?= esc($type) ?>" <?= (string) ($cpType ?? '') === (string) $type ? 'selected' : '' ?>><?= esc($type) ?></option>
<?php endforeach; ?>
</select>
<button type="submit" class="bg-btn-search text-white px-4 py-1 rounded-sm text-sm">조회</button>
<a href="<?= mgmt_url('companies') ?>" class="text-sm text-gray-500 hover:underline">초기화</a>
</form>
</section>
<div class="border border-gray-300 overflow-auto mt-2"> <div class="border border-gray-300 overflow-auto mt-2">
<table class="w-full data-table"> <table class="w-full data-table">
<thead> <thead>
@@ -24,9 +37,17 @@
</tr> </tr>
</thead> </thead>
<tbody> <tbody>
<?php foreach ($list as $row): ?> <?php
$startNo = 1;
if (isset($pager) && method_exists($pager, 'getCurrentPage') && method_exists($pager, 'getPerPage')) {
$currentPage = (int) $pager->getCurrentPage();
$perPage = (int) $pager->getPerPage();
$startNo = (($currentPage > 0 ? $currentPage : 1) - 1) * ($perPage > 0 ? $perPage : 20) + 1;
}
?>
<?php foreach (($list ?? []) as $idx => $row): ?>
<tr> <tr>
<td class="text-center"><?= esc($row->cp_idx) ?></td> <td class="text-center"><?= (int) $startNo + (int) $idx ?></td>
<td class="text-center"><?= esc($row->cp_type) ?></td> <td class="text-center"><?= esc($row->cp_type) ?></td>
<td class="text-left pl-2"><?= esc($row->cp_name) ?></td> <td class="text-left pl-2"><?= esc($row->cp_name) ?></td>
<td class="text-center"><?= esc($row->cp_biz_no) ?></td> <td class="text-center"><?= esc($row->cp_biz_no) ?></td>

View File

@@ -1,4 +1,14 @@
<?php $readOnly = ! empty($readOnly); ?> <?php
helper('admin');
$currentPath = current_nav_request_path();
if ($currentPath === 'bag/designated-shops') {
$readOnly = false;
} elseif ($currentPath === 'bag/designated-shops/browse') {
$readOnly = true;
} else {
$readOnly = ! empty($readOnly);
}
?>
<?= view('components/print_header', ['printTitle' => $readOnly ? '지정판매소 조회 목록' : '지정판매소 목록']) ?> <?= view('components/print_header', ['printTitle' => $readOnly ? '지정판매소 조회 목록' : '지정판매소 목록']) ?>
<style> <style>
/* 목록 위 → 지정판매소 정보 아래 (가로 2열 없음) */ /* 목록 위 → 지정판매소 정보 아래 (가로 2열 없음) */
@@ -181,11 +191,12 @@ $listBasePath = $readOnly ? 'designated-shops/browse' : 'designated-shops';
<span class="text-sm font-semibold text-gray-700 mr-1">지정판매소 검색</span> <span class="text-sm font-semibold text-gray-700 mr-1">지정판매소 검색</span>
<label class="text-sm text-gray-600">상호명</label> <label class="text-sm text-gray-600">상호명</label>
<input type="text" name="ds_name" value="<?= esc($dsName ?? '') ?>" placeholder="상호명" class="border border-gray-300 rounded px-2 py-1 text-sm w-36"/> <input type="text" name="ds_name" value="<?= esc($dsName ?? '') ?>" placeholder="상호명" class="border border-gray-300 rounded px-2 py-1 text-sm w-36"/>
<label class="text-sm text-gray-600">구코드</label> <label class="text-sm text-gray-600">구·군 코드</label>
<select name="ds_gugun_code" class="border border-gray-300 rounded px-2 py-1 text-sm"> <select name="ds_gugun_code" class="border border-gray-300 rounded px-2 py-1 text-sm min-w-[14rem]">
<option value="">전체</option> <option value="">전체</option>
<?php foreach (($gugunCodes ?? []) as $gc): ?> <?php foreach (($gugunCodes ?? []) as $gc): ?>
<option value="<?= esc($gc->ds_gugun_code) ?>" <?= ($dsGugunCode ?? '') === $gc->ds_gugun_code ? 'selected' : '' ?>><?= esc($gc->ds_gugun_code) ?></option> <?php $gCode = (string) ($gc->ds_gugun_code ?? ''); ?>
<option value="<?= esc($gCode) ?>" <?= ($dsGugunCode ?? '') === $gCode ? 'selected' : '' ?>><?= esc((string) (($gugunNameMap[$gCode] ?? '') !== '' ? $gugunNameMap[$gCode] : $gCode)) ?></option>
<?php endforeach; ?> <?php endforeach; ?>
</select> </select>
<label class="text-sm text-gray-600">상태</label> <label class="text-sm text-gray-600">상태</label>
@@ -223,7 +234,6 @@ $sc = $stateCounts ?? ['total' => 0, 1 => 0, 2 => 0, 3 => 0];
<th class="ds-col-tight">상호명</th> <th class="ds-col-tight">상호명</th>
<th class="ds-col-zip">우편번호</th> <th class="ds-col-zip">우편번호</th>
<th class="text-left">주소</th> <th class="text-left">주소</th>
<th class="text-left">상세주소</th>
<th class="w-28">사업자번호</th> <th class="w-28">사업자번호</th>
<th class="w-28">전화</th> <th class="w-28">전화</th>
<th class="w-16">상태</th> <th class="w-16">상태</th>
@@ -242,7 +252,8 @@ $sc = $stateCounts ?? ['total' => 0, 1 => 0, 2 => 0, 3 => 0];
} }
$st = (int) ($row->ds_state ?? 1); $st = (int) ($row->ds_state ?? 1);
$stLabel = $st === 1 ? '' : ($st === 2 ? '폐업' : '해지'); $stLabel = $st === 1 ? '' : ($st === 2 ? '폐업' : '해지');
$ggLabel = (string) ($row->ds_gugun_code ?? ''); $ggCode = (string) ($row->ds_gugun_code ?? '');
$ggLabel = (string) (($gugunNameMap[$ggCode] ?? '') !== '' ? $gugunNameMap[$ggCode] : $ggCode);
$da = $row->ds_designated_at ?? null; $da = $row->ds_designated_at ?? null;
$daDisp = ($da !== null && $da !== '' && (string) $da !== '0000-00-00') ? substr((string) $da, 0, 10) : ''; $daDisp = ($da !== null && $da !== '' && (string) $da !== '0000-00-00') ? substr((string) $da, 0, 10) : '';
$zone = (string) ($row->ds_zone_code ?? ''); $zone = (string) ($row->ds_zone_code ?? '');
@@ -251,6 +262,10 @@ $sc = $stateCounts ?? ['total' => 0, 1 => 0, 2 => 0, 3 => 0];
$jibunL = trim((string) ($row->ds_addr_jibun ?? '')); $jibunL = trim((string) ($row->ds_addr_jibun ?? ''));
$addrMainList = $roadL !== '' ? $roadL : $jibunL; $addrMainList = $roadL !== '' ? $roadL : $jibunL;
$addrDetailList = trim((string) ($row->ds_addr_detail ?? '')); $addrDetailList = trim((string) ($row->ds_addr_detail ?? ''));
$addrCombinedList = trim($addrMainList . ' ' . $addrDetailList);
if ($addrCombinedList === '') {
$addrCombinedList = $addrMainList;
}
?> ?>
<tr class="ds-list-row cursor-pointer" data-row-index="<?= (int) $i ?>" role="button" tabindex="0"> <tr class="ds-list-row cursor-pointer" data-row-index="<?= (int) $i ?>" role="button" tabindex="0">
<td class="text-center"><?= esc($shortNo) ?></td> <td class="text-center"><?= esc($shortNo) ?></td>
@@ -260,8 +275,7 @@ $sc = $stateCounts ?? ['total' => 0, 1 => 0, 2 => 0, 3 => 0];
<td class="text-left pl-1 text-xs ds-col-tight" title="<?= esc($row->ds_rep_name ?? '') ?>"><?= esc($row->ds_rep_name ?? '') ?></td> <td class="text-left pl-1 text-xs ds-col-tight" title="<?= esc($row->ds_rep_name ?? '') ?>"><?= esc($row->ds_rep_name ?? '') ?></td>
<td class="text-left pl-1 text-xs ds-col-tight" title="<?= esc($row->ds_name ?? '') ?>"><?= esc($row->ds_name ?? '') ?></td> <td class="text-left pl-1 text-xs ds-col-tight" title="<?= esc($row->ds_name ?? '') ?>"><?= esc($row->ds_name ?? '') ?></td>
<td class="text-center text-xs ds-col-zip" title="<?= esc($zipList) ?>"><?= esc($zipList) ?></td> <td class="text-center text-xs ds-col-zip" title="<?= esc($zipList) ?>"><?= esc($zipList) ?></td>
<td class="text-left pl-1 text-xs ds-col-addr-list" title="<?= esc($addrMainList) ?>"><?= esc($addrMainList) ?></td> <td class="text-left pl-1 text-xs ds-col-addr-list" title="<?= esc($addrCombinedList) ?>"><?= esc($addrCombinedList) ?></td>
<td class="text-left pl-1 text-xs ds-col-detail-list" title="<?= esc($addrDetailList) ?>"><?= esc($addrDetailList) ?></td>
<td class="text-left pl-1 text-xs"><?= esc($row->ds_biz_no ?? '') ?></td> <td class="text-left pl-1 text-xs"><?= esc($row->ds_biz_no ?? '') ?></td>
<td class="text-left pl-1 text-xs"><?= esc($row->ds_tel ?? '') ?></td> <td class="text-left pl-1 text-xs"><?= esc($row->ds_tel ?? '') ?></td>
<td class="text-center <?= $st === 2 ? 'text-pink-600 font-medium' : ($st === 3 ? 'text-orange-700' : '') ?>"><?= esc($stLabel) ?></td> <td class="text-center <?= $st === 2 ? 'text-pink-600 font-medium' : ($st === 3 ? 'text-orange-700' : '') ?>"><?= esc($stLabel) ?></td>
@@ -296,7 +310,7 @@ $sc = $stateCounts ?? ['total' => 0, 1 => 0, 2 => 0, 3 => 0];
<th>지번주소</th> <th>지번주소</th>
<th>상세주소</th> <th>상세주소</th>
<th>개인전화</th> <th>개인전화</th>
<th>구코드</th> <th>구·군</th>
<th>구역</th> <th>구역</th>
<th>가상계좌(은행)</th> <th>가상계좌(은행)</th>
<th>계좌번호</th> <th>계좌번호</th>
@@ -325,7 +339,7 @@ $sc = $stateCounts ?? ['total' => 0, 1 => 0, 2 => 0, 3 => 0];
<td class="text-left" data-ro="ds_addr_jibun">—</td> <td class="text-left" data-ro="ds_addr_jibun">—</td>
<td class="text-left" data-ro="ds_addr_detail">—</td> <td class="text-left" data-ro="ds_addr_detail">—</td>
<td class="text-left" data-ro="ds_rep_phone">—</td> <td class="text-left" data-ro="ds_rep_phone">—</td>
<td class="text-left" data-ro="ds_gugun_code">—</td> <td class="text-left" data-ro="gugun_name">—</td>
<td class="text-left" data-ro="ds_zone_code">—</td> <td class="text-left" data-ro="ds_zone_code">—</td>
<td class="text-left" data-ro="ds_va_bank">—</td> <td class="text-left" data-ro="ds_va_bank">—</td>
<td class="text-left" data-ro="ds_va_account">—</td> <td class="text-left" data-ro="ds_va_account">—</td>
@@ -492,7 +506,6 @@ $sc = $stateCounts ?? ['total' => 0, 1 => 0, 2 => 0, 3 => 0];
<th>상호명</th> <th>상호명</th>
<th>우편번호</th> <th>우편번호</th>
<th>주소</th> <th>주소</th>
<th>상세주소</th>
<th>사업자번호</th> <th>사업자번호</th>
<th>전화</th> <th>전화</th>
<th>판매소번호</th> <th>판매소번호</th>
@@ -521,18 +534,22 @@ $sc = $stateCounts ?? ['total' => 0, 1 => 0, 2 => 0, 3 => 0];
$jibP = trim((string) ($row->ds_addr_jibun ?? '')); $jibP = trim((string) ($row->ds_addr_jibun ?? ''));
$addrP = $roadP !== '' ? $roadP : $jibP; $addrP = $roadP !== '' ? $roadP : $jibP;
$detP = trim((string) ($row->ds_addr_detail ?? '')); $detP = trim((string) ($row->ds_addr_detail ?? ''));
$addrCombinedP = trim($addrP . ' ' . $detP);
if ($addrCombinedP === '') {
$addrCombinedP = $addrP;
}
?> ?>
<tr> <tr>
<td class="text-center"><?= esc($shortNoP) ?></td> <td class="text-center"><?= esc($shortNoP) ?></td>
<td class="text-left"><?= esc($lgMap[$row->ds_lg_idx] ?? '') ?></td> <td class="text-left"><?= esc($lgMap[$row->ds_lg_idx] ?? '') ?></td>
<td class="text-left"><?= esc($row->ds_gugun_code ?? '') ?></td> <?php $gCodeP = (string) ($row->ds_gugun_code ?? ''); ?>
<td class="text-left"><?= esc((string) (($gugunNameMap[$gCodeP] ?? '') !== '' ? $gugunNameMap[$gCodeP] : $gCodeP)) ?></td>
<td class="text-center"><?= esc($daDispP) ?></td> <td class="text-center"><?= esc($daDispP) ?></td>
<td class="text-left"><?= esc($row->ds_zone_code ?? '') ?></td> <td class="text-left"><?= esc($row->ds_zone_code ?? '') ?></td>
<td class="text-left"><?= esc($row->ds_rep_name ?? '') ?></td> <td class="text-left"><?= esc($row->ds_rep_name ?? '') ?></td>
<td class="text-left"><?= esc($row->ds_name ?? '') ?></td> <td class="text-left"><?= esc($row->ds_name ?? '') ?></td>
<td class="text-left"><?= esc($zipP) ?></td> <td class="text-left"><?= esc($zipP) ?></td>
<td class="text-left"><?= esc($addrP) ?></td> <td class="text-left"><?= esc($addrCombinedP) ?></td>
<td class="text-left"><?= esc($detP) ?></td>
<td class="text-left"><?= esc($row->ds_biz_no ?? '') ?></td> <td class="text-left"><?= esc($row->ds_biz_no ?? '') ?></td>
<td class="text-left"><?= esc($row->ds_tel ?? '') ?></td> <td class="text-left"><?= esc($row->ds_tel ?? '') ?></td>
<td class="text-left"><?= esc($row->ds_shop_no) ?></td> <td class="text-left"><?= esc($row->ds_shop_no) ?></td>

View File

@@ -16,7 +16,6 @@
<th>대상자명</th> <th>대상자명</th>
<th>연락처</th> <th>연락처</th>
<th>주소</th> <th>주소</th>
<th>동코드</th>
<th>비고</th> <th>비고</th>
<th>종료일</th> <th>종료일</th>
<th class="w-20">상태</th> <th class="w-20">상태</th>
@@ -30,7 +29,6 @@
<td class="text-left pl-2"><?= esc($row->fr_name) ?></td> <td class="text-left pl-2"><?= esc($row->fr_name) ?></td>
<td class="text-center"><?= esc($row->fr_phone) ?></td> <td class="text-center"><?= esc($row->fr_phone) ?></td>
<td class="text-left pl-2"><?= esc($row->fr_addr) ?></td> <td class="text-left pl-2"><?= esc($row->fr_addr) ?></td>
<td class="text-center"><?= esc($row->fr_dong_code) ?></td>
<td class="text-left pl-2"><?= esc($row->fr_note) ?></td> <td class="text-left pl-2"><?= esc($row->fr_note) ?></td>
<td class="text-center"><?= esc($row->fr_end_date) ?></td> <td class="text-center"><?= esc($row->fr_end_date) ?></td>
<td class="text-center"><?= (int) $row->fr_state === 1 ? '사용' : '미사용' ?></td> <td class="text-center"><?= (int) $row->fr_state === 1 ? '사용' : '미사용' ?></td>
@@ -45,7 +43,7 @@
<?php endforeach; ?> <?php endforeach; ?>
<?php if (empty($list)): ?> <?php if (empty($list)): ?>
<tr> <tr>
<td colspan="9" class="text-center text-gray-500 py-4 text-sm space-y-1"> <td colspan="8" class="text-center text-gray-500 py-4 text-sm space-y-1">
<p>등록된 데이터가 없습니다.</p> <p>등록된 데이터가 없습니다.</p>
<p class="text-gray-400">다른 지자체를 선택 중이면 해당 지자체 기준으로만 조회됩니다. Super Admin 은 상단에서 작업 지자체를 바꿔 보세요.</p> <p class="text-gray-400">다른 지자체를 선택 중이면 해당 지자체 기준으로만 조회됩니다. Super Admin 은 상단에서 작업 지자체를 바꿔 보세요.</p>
</td> </td>

View File

@@ -11,28 +11,18 @@
</div> </div>
<div class="flex flex-wrap items-center gap-2"> <div class="flex flex-wrap items-center gap-2">
<label class="block text-sm font-bold text-gray-700 w-28">소속</label> <label class="block text-sm font-bold text-gray-700 w-28">담당자 구분 <span class="text-red-500">*</span></label>
<select class="border border-gray-300 rounded px-3 py-1.5 text-sm w-60" name="mg_dept_code"> <select class="border border-gray-300 rounded px-3 py-1.5 text-sm w-60" name="mg_category" required>
<option value="">선택</option> <option value="">선택</option>
<?php foreach ($deptCodes as $cd): ?> <?php foreach (($categories ?? []) as $key => $label): ?>
<option value="<?= esc($cd->cd_code) ?>" <?= old('mg_dept_code') === $cd->cd_code ? 'selected' : '' ?>> <option value="<?= esc($key) ?>" <?= old('mg_category') === $key ? 'selected' : '' ?>>
<?= esc($cd->cd_name) ?> <?= esc($label) ?>
</option> </option>
<?php endforeach; ?> <?php endforeach; ?>
</select> </select>
</div> </div>
<div class="flex flex-wrap items-center gap-2"> <input type="hidden" name="mg_position_code" value="<?= esc(old('mg_position_code', '')) ?>"/>
<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="mg_position_code">
<option value="">선택</option>
<?php foreach ($positionCodes as $cd): ?>
<option value="<?= esc($cd->cd_code) ?>" <?= old('mg_position_code') === $cd->cd_code ? 'selected' : '' ?>>
<?= esc($cd->cd_name) ?>
</option>
<?php endforeach; ?>
</select>
</div>
<div class="flex flex-wrap items-center gap-2"> <div class="flex flex-wrap items-center gap-2">
<label class="block text-sm font-bold text-gray-700 w-28">전화</label> <label class="block text-sm font-bold text-gray-700 w-28">전화</label>

View File

@@ -11,28 +11,18 @@
</div> </div>
<div class="flex flex-wrap items-center gap-2"> <div class="flex flex-wrap items-center gap-2">
<label class="block text-sm font-bold text-gray-700 w-28">소속</label> <label class="block text-sm font-bold text-gray-700 w-28">담당자 구분 <span class="text-red-500">*</span></label>
<select class="border border-gray-300 rounded px-3 py-1.5 text-sm w-60" name="mg_dept_code"> <select class="border border-gray-300 rounded px-3 py-1.5 text-sm w-60" name="mg_category" required>
<option value="">선택</option> <option value="">선택</option>
<?php foreach ($deptCodes as $cd): ?> <?php foreach (($categories ?? []) as $key => $label): ?>
<option value="<?= esc($cd->cd_code) ?>" <?= old('mg_dept_code', $item->mg_dept_code) === $cd->cd_code ? 'selected' : '' ?>> <option value="<?= esc($key) ?>" <?= old('mg_category', (string) ($item->mg_dept_code ?? '')) === $key ? 'selected' : '' ?>>
<?= esc($cd->cd_name) ?> <?= esc($label) ?>
</option> </option>
<?php endforeach; ?> <?php endforeach; ?>
</select> </select>
</div> </div>
<div class="flex flex-wrap items-center gap-2"> <input type="hidden" name="mg_position_code" value="<?= esc(old('mg_position_code', $item->mg_position_code)) ?>"/>
<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="mg_position_code">
<option value="">선택</option>
<?php foreach ($positionCodes as $cd): ?>
<option value="<?= esc($cd->cd_code) ?>" <?= old('mg_position_code', $item->mg_position_code) === $cd->cd_code ? 'selected' : '' ?>>
<?= esc($cd->cd_name) ?>
</option>
<?php endforeach; ?>
</select>
</div>
<div class="flex flex-wrap items-center gap-2"> <div class="flex flex-wrap items-center gap-2">
<label class="block text-sm font-bold text-gray-700 w-28">전화</label> <label class="block text-sm font-bold text-gray-700 w-28">전화</label>

View File

@@ -8,14 +8,26 @@
</div> </div>
</div> </div>
</section> </section>
<section class="p-2 bg-white border-b border-gray-200 no-print">
<form method="GET" action="<?= mgmt_url('managers') ?>" class="flex flex-wrap items-center gap-2">
<label class="text-sm text-gray-600">카테고리</label>
<select name="category" class="border border-gray-300 rounded px-2 py-1 text-sm w-44">
<option value="">전 체</option>
<?php foreach (($categories ?? []) as $key => $label): ?>
<option value="<?= esc($key) ?>" <?= ($category ?? '') === $key ? 'selected' : '' ?>><?= esc($label) ?></option>
<?php endforeach; ?>
</select>
<button type="submit" class="bg-btn-search text-white px-4 py-1 rounded-sm text-sm">조회</button>
<a href="<?= mgmt_url('managers') ?>" class="text-sm text-gray-500 hover:underline">초기화</a>
</form>
</section>
<div class="border border-gray-300 overflow-auto mt-2"> <div class="border border-gray-300 overflow-auto mt-2">
<table class="w-full data-table"> <table class="w-full data-table">
<thead> <thead>
<tr> <tr>
<th class="w-16">번호</th> <th class="w-16">번호</th>
<th>담당자명</th> <th>담당자명</th>
<th>소속</th> <th>카테고리</th>
<th>직위</th>
<th>전화</th> <th>전화</th>
<th>휴대전화</th> <th>휴대전화</th>
<th>이메일</th> <th>이메일</th>
@@ -28,8 +40,13 @@
<tr> <tr>
<td class="text-center"><?= esc($row->mg_idx) ?></td> <td class="text-center"><?= esc($row->mg_idx) ?></td>
<td class="text-center"><?= esc($row->mg_name) ?></td> <td class="text-center"><?= esc($row->mg_name) ?></td>
<td class="text-center"><?= esc($row->mg_dept_code) ?></td> <td class="text-center">
<td class="text-center"><?= esc($row->mg_position_code) ?></td> <?php
$cat = (string) ($row->mg_dept_code ?? '');
$catLabel = $categories[$cat] ?? $cat;
echo esc($catLabel);
?>
</td>
<td class="text-center"><?= esc($row->mg_tel) ?></td> <td class="text-center"><?= esc($row->mg_tel) ?></td>
<td class="text-center"><?= esc($row->mg_phone) ?></td> <td class="text-center"><?= esc($row->mg_phone) ?></td>
<td class="text-center"><?= esc($row->mg_email) ?></td> <td class="text-center"><?= esc($row->mg_email) ?></td>
@@ -44,7 +61,7 @@
</tr> </tr>
<?php endforeach; ?> <?php endforeach; ?>
<?php if (empty($list)): ?> <?php if (empty($list)): ?>
<tr><td colspan="9" class="text-center text-gray-400 py-4">등록된 데이터가 없습니다.</td></tr> <tr><td colspan="8" class="text-center text-gray-400 py-4">등록된 데이터가 없습니다.</td></tr>
<?php endif; ?> <?php endif; ?>
</tbody> </tbody>
</table> </table>

View File

@@ -25,7 +25,7 @@
<div class="flex flex-wrap items-center gap-2"> <div class="flex flex-wrap items-center gap-2">
<label class="block text-sm font-bold text-gray-700 w-32">적용시작일 <span class="text-red-500">*</span></label> <label class="block text-sm font-bold text-gray-700 w-32">적용시작일 <span class="text-red-500">*</span></label>
<input class="border border-gray-300 rounded px-3 py-1.5 text-sm w-44" name="pu_start_date" type="date" value="<?= esc(old('pu_start_date', $item->pu_start_date)) ?>" required/> <input class="border border-gray-300 rounded px-3 py-1.5 text-sm w-44" name="pu_start_date" type="date" value="<?= esc(old('pu_start_date', date('Y-m-d'))) ?>" required/>
</div> </div>
<div class="flex flex-wrap items-center gap-2"> <div class="flex flex-wrap items-center gap-2">

View File

@@ -6,11 +6,20 @@
</div> </div>
</section> </section>
<div class="border border-gray-300 overflow-auto mt-2"> <div class="border border-gray-300 overflow-auto mt-2">
<?php
$fieldLabelMap = [
'pu_box_per_pack' => '박스당 팩 수',
'pu_pack_per_sheet' => '팩당 낱장 수',
'pu_start_date' => '적용시작일',
'pu_end_date' => '적용종료일',
'pu_state' => '상태',
];
?>
<table class="w-full data-table"> <table class="w-full data-table">
<thead> <thead>
<tr> <tr>
<th class="w-16">번호</th> <th class="w-16">번호</th>
<th>변경 필드</th> <th>변경 내용</th>
<th>이전 값</th> <th>이전 값</th>
<th>변경 값</th> <th>변경 값</th>
<th>변경일시</th> <th>변경일시</th>
@@ -20,7 +29,7 @@
<?php foreach ($list as $row): ?> <?php foreach ($list as $row): ?>
<tr> <tr>
<td class="text-center"><?= esc($row->puh_idx) ?></td> <td class="text-center"><?= esc($row->puh_idx) ?></td>
<td class="text-left pl-2"><?= esc($row->puh_field) ?></td> <td class="text-left pl-2"><?= esc($fieldLabelMap[(string) $row->puh_field] ?? $row->puh_field) ?></td>
<td><?= esc($row->puh_old_value) ?></td> <td><?= esc($row->puh_old_value) ?></td>
<td><?= esc($row->puh_new_value) ?></td> <td><?= esc($row->puh_new_value) ?></td>
<td class="text-center"><?= esc($row->puh_changed_at) ?></td> <td class="text-center"><?= esc($row->puh_changed_at) ?></td>

View File

@@ -35,9 +35,17 @@
</tr> </tr>
</thead> </thead>
<tbody class="text-right"> <tbody class="text-right">
<?php foreach ($list as $row): ?> <?php
$startNo = 1;
if (isset($pager) && method_exists($pager, 'getCurrentPage') && method_exists($pager, 'getPerPage')) {
$currentPage = (int) $pager->getCurrentPage();
$perPage = (int) $pager->getPerPage();
$startNo = (($currentPage > 0 ? $currentPage : 1) - 1) * ($perPage > 0 ? $perPage : 20) + 1;
}
?>
<?php foreach (($list ?? []) as $idx => $row): ?>
<tr> <tr>
<td class="text-center"><?= esc($row->pu_idx) ?></td> <td class="text-center"><?= (int) $startNo + (int) $idx ?></td>
<td class="text-center font-mono"><?= esc($row->pu_bag_code) ?></td> <td class="text-center font-mono"><?= esc($row->pu_bag_code) ?></td>
<td class="text-left pl-2"><?= esc($row->pu_bag_name) ?></td> <td class="text-left pl-2"><?= esc($row->pu_bag_name) ?></td>
<td><?= number_format((int) $row->pu_box_per_pack) ?></td> <td><?= number_format((int) $row->pu_box_per_pack) ?></td>

View File

@@ -44,9 +44,17 @@
</tr> </tr>
</thead> </thead>
<tbody> <tbody>
<?php foreach ($list as $row): ?> <?php
$startNo = 1;
if (isset($pager) && method_exists($pager, 'getCurrentPage') && method_exists($pager, 'getPerPage')) {
$currentPage = (int) $pager->getCurrentPage();
$perPage = (int) $pager->getPerPage();
$startNo = (($currentPage > 0 ? $currentPage : 1) - 1) * ($perPage > 0 ? $perPage : 20) + 1;
}
?>
<?php foreach (($list ?? []) as $idx => $row): ?>
<tr> <tr>
<td class="text-center"><?= esc($row->sa_idx) ?></td> <td class="text-center"><?= (int) $startNo + (int) $idx ?></td>
<td class="text-left pl-2"><?= esc($row->sa_kind ?? '') ?></td> <td class="text-left pl-2"><?= esc($row->sa_kind ?? '') ?></td>
<td class="text-center"><?= esc($row->sa_code ?? '') ?></td> <td class="text-center"><?= esc($row->sa_code ?? '') ?></td>
<td class="text-left pl-2"><?= esc($row->sa_name) ?></td> <td class="text-left pl-2"><?= esc($row->sa_name) ?></td>