Files
jongryangje/app/Controllers/Admin/BagReceiving.php
javamon1174 704141a1f0 CT-01/02/03 공통 컴포넌트 구현 — 페이지네이션/엑셀/인쇄
CT-01: 페이지네이션
- 커스텀 Tailwind 페이저 뷰 (components/pager.php)
- 18개 admin 컨트롤러 findAll() → paginate(20) 전환
- Bag 컨트롤러 7개 리스트도 paginate 적용
- 19개 admin index 뷰에 페이저 링크 추가

CT-02: 엑셀 저장
- export_helper.php (UTF-8 BOM CSV)
- 발주/판매/지정판매소/재고 4개 엑셀 내보내기 라우트+메서드
- 해당 뷰에 "엑셀저장" 버튼 추가

CT-03: 인쇄
- print_header.php (지자체명/제목/결재란 컴포넌트)
- admin/bag 레이아웃에 @media print CSS 추가
- 23개 뷰에 인쇄 버튼 + print_header 추가

Co-Authored-By: Claude Opus 4.6 (1M context) <noreply@anthropic.com>
2026-03-26 16:40:49 +09:00

111 lines
4.2 KiB
PHP

<?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')->paginate(20);
$pager = $this->recvModel->pager;
return view('admin/layout', [
'title' => '입고 현황',
'content' => view('admin/bag_receiving/index', compact('list', 'startDate', 'endDate', 'pager')),
]);
}
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 . '박스)');
}
}