feat: enhance order sales inventory workflows
This commit is contained in:
@@ -11,24 +11,23 @@ class BagInventory extends BaseController
|
||||
{
|
||||
helper('admin');
|
||||
$lgIdx = admin_effective_lg_idx();
|
||||
if (!$lgIdx) return redirect()->to(site_url('admin'))->with('error', '지자체를 선택해 주세요.');
|
||||
if (! $lgIdx) {
|
||||
return redirect()->to(work_area_home_url())->with('error', '지자체를 선택해 주세요.');
|
||||
}
|
||||
|
||||
$invModel = model(BagInventoryModel::class);
|
||||
$list = $invModel->where('bi_lg_idx', $lgIdx)->orderBy('bi_bag_code', 'ASC')->paginate(20);
|
||||
$pager = $invModel->pager;
|
||||
$list = $invModel->where('bi_lg_idx', $lgIdx)->orderBy('bi_bag_code', 'ASC')->paginate(20);
|
||||
$pager = $invModel->pager;
|
||||
|
||||
return view('admin/layout', [
|
||||
'title' => '재고 현황',
|
||||
'content' => view('admin/bag_inventory/index', ['list' => $list, 'pager' => $pager]),
|
||||
]);
|
||||
return $this->renderWorkPage('재고 현황', 'admin/bag_inventory/index', ['list' => $list, 'pager' => $pager]);
|
||||
}
|
||||
|
||||
public function export()
|
||||
{
|
||||
helper(['admin', 'export']);
|
||||
$lgIdx = admin_effective_lg_idx();
|
||||
if (!$lgIdx) {
|
||||
return redirect()->to(site_url('admin/bag-inventory'))->with('error', '지자체를 선택해 주세요.');
|
||||
if (! $lgIdx) {
|
||||
return redirect()->to(mgmt_url('bag-inventory'))->with('error', '지자체를 선택해 주세요.');
|
||||
}
|
||||
|
||||
$list = model(BagInventoryModel::class)->where('bi_lg_idx', $lgIdx)->orderBy('bi_bag_code', 'ASC')->findAll();
|
||||
|
||||
@@ -21,33 +21,34 @@ class BagIssue extends BaseController
|
||||
{
|
||||
helper('admin');
|
||||
$lgIdx = admin_effective_lg_idx();
|
||||
if (!$lgIdx) return redirect()->to(site_url('admin'))->with('error', '지자체를 선택해 주세요.');
|
||||
if (! $lgIdx) {
|
||||
return redirect()->to(work_area_home_url())->with('error', '지자체를 선택해 주세요.');
|
||||
}
|
||||
|
||||
$builder = $this->issueModel->where('bi2_lg_idx', $lgIdx);
|
||||
$startDate = $this->request->getGet('start_date');
|
||||
$endDate = $this->request->getGet('end_date');
|
||||
if ($startDate) $builder->where('bi2_issue_date >=', $startDate);
|
||||
if ($endDate) $builder->where('bi2_issue_date <=', $endDate);
|
||||
if ($startDate) {
|
||||
$builder->where('bi2_issue_date >=', $startDate);
|
||||
}
|
||||
if ($endDate) {
|
||||
$builder->where('bi2_issue_date <=', $endDate);
|
||||
}
|
||||
|
||||
$list = $builder->orderBy('bi2_issue_date', 'DESC')->orderBy('bi2_idx', 'DESC')->paginate(20);
|
||||
$list = $builder->orderBy('bi2_issue_date', 'DESC')->orderBy('bi2_idx', 'DESC')->paginate(20);
|
||||
$pager = $this->issueModel->pager;
|
||||
|
||||
return view('admin/layout', [
|
||||
'title' => '무료용 불출 관리',
|
||||
'content' => view('admin/bag_issue/index', compact('list', 'startDate', 'endDate', 'pager')),
|
||||
]);
|
||||
return $this->renderWorkPage('무료용 불출 관리', 'admin/bag_issue/index', compact('list', 'startDate', 'endDate', 'pager'));
|
||||
}
|
||||
|
||||
public function create()
|
||||
{
|
||||
helper('admin');
|
||||
$kind = model(CodeKindModel::class)->where('ck_code', 'O')->first();
|
||||
$bagCodes = $kind ? model(CodeDetailModel::class)->getByKind((int) $kind->ck_idx, true) : [];
|
||||
$lgIdx = admin_effective_lg_idx();
|
||||
$kind = model(CodeKindModel::class)->where('ck_code', 'O')->first();
|
||||
$bagCodes = $kind ? model(CodeDetailModel::class)->getByKind((int) $kind->ck_idx, true, $lgIdx) : [];
|
||||
|
||||
return view('admin/layout', [
|
||||
'title' => '무료용 불출 처리',
|
||||
'content' => view('admin/bag_issue/create', compact('bagCodes')),
|
||||
]);
|
||||
return $this->renderWorkPage('무료용 불출 처리', 'admin/bag_issue/create', compact('bagCodes'));
|
||||
}
|
||||
|
||||
public function store()
|
||||
@@ -71,8 +72,8 @@ class BagIssue extends BaseController
|
||||
$bagCode = $this->request->getPost('bi2_bag_code');
|
||||
$qty = (int) $this->request->getPost('bi2_qty');
|
||||
|
||||
$kindO = model(CodeKindModel::class)->where('ck_code', 'O')->first();
|
||||
$detail = $kindO ? model(CodeDetailModel::class)->where('cd_ck_idx', $kindO->ck_idx)->where('cd_code', $bagCode)->first() : null;
|
||||
$kindO = model(CodeKindModel::class)->where('ck_code', 'O')->first();
|
||||
$detail = $kindO ? model(CodeDetailModel::class)->findResolvedByKindAndCode((int) $kindO->ck_idx, (string) $bagCode, $lgIdx) : null;
|
||||
$bagName = $detail ? $detail->cd_name : '';
|
||||
|
||||
$db = \Config\Database::connect();
|
||||
@@ -95,24 +96,22 @@ class BagIssue extends BaseController
|
||||
$this->issueModel->insert($issueData);
|
||||
$bi2Idx = (int) $this->issueModel->getInsertID();
|
||||
|
||||
// CT-05: 감사 로그
|
||||
helper('audit');
|
||||
audit_log('create', 'bag_issue', $bi2Idx, null, array_merge($issueData, ['bi2_idx' => $bi2Idx]));
|
||||
|
||||
// 재고 감산
|
||||
model(BagInventoryModel::class)->adjustQty($lgIdx, $bagCode, $bagName, -$qty);
|
||||
|
||||
$db->transComplete();
|
||||
|
||||
return redirect()->to(site_url('admin/bag-issues'))->with('success', '불출 처리되었습니다.');
|
||||
return redirect()->to(mgmt_url('bag-issues'))->with('success', '불출 처리되었습니다.');
|
||||
}
|
||||
|
||||
public function cancel(int $id)
|
||||
{
|
||||
helper('admin');
|
||||
$item = $this->issueModel->find($id);
|
||||
if (!$item || (int) $item->bi2_lg_idx !== admin_effective_lg_idx()) {
|
||||
return redirect()->to(site_url('admin/bag-issues'))->with('error', '불출 내역을 찾을 수 없습니다.');
|
||||
if (! $item || (int) $item->bi2_lg_idx !== admin_effective_lg_idx()) {
|
||||
return redirect()->to(mgmt_url('bag-issues'))->with('error', '불출 내역을 찾을 수 없습니다.');
|
||||
}
|
||||
|
||||
$db = \Config\Database::connect();
|
||||
@@ -120,14 +119,12 @@ class BagIssue extends BaseController
|
||||
|
||||
$before = (array) $item;
|
||||
$this->issueModel->update($id, ['bi2_status' => 'cancelled']);
|
||||
// CT-05: 감사 로그
|
||||
helper('audit');
|
||||
audit_log('update', 'bag_issue', $id, $before, ['bi2_status' => 'cancelled']);
|
||||
// 재고 복원
|
||||
model(BagInventoryModel::class)->adjustQty((int) $item->bi2_lg_idx, $item->bi2_bag_code, $item->bi2_bag_name, (int) $item->bi2_qty);
|
||||
|
||||
$db->transComplete();
|
||||
|
||||
return redirect()->to(site_url('admin/bag-issues'))->with('success', '불출이 취소되었습니다.');
|
||||
return redirect()->to(mgmt_url('bag-issues'))->with('success', '불출이 취소되었습니다.');
|
||||
}
|
||||
}
|
||||
|
||||
@@ -11,8 +11,6 @@ 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;
|
||||
@@ -28,8 +26,8 @@ class BagOrder extends BaseController
|
||||
{
|
||||
helper('admin');
|
||||
$lgIdx = admin_effective_lg_idx();
|
||||
if (!$lgIdx) {
|
||||
return redirect()->to(site_url('admin'))->with('error', '지자체를 선택해 주세요.');
|
||||
if (! $lgIdx) {
|
||||
return redirect()->to(work_area_home_url())->with('error', '지자체를 선택해 주세요.');
|
||||
}
|
||||
|
||||
$builder = $this->orderModel->where('bo_lg_idx', $lgIdx);
|
||||
@@ -57,20 +55,19 @@ class BagOrder extends BaseController
|
||||
// 제작업체/대행소 이름 매핑
|
||||
$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;
|
||||
foreach (model(SalesAgencyModel::class)->where('sa_lg_idx', $lgIdx)->orderForDisplay()->findAll() as $a) {
|
||||
$agencyMap[$a->sa_idx] = '[' . ($a->sa_kind ?? '') . '] ' . ($a->sa_code ?? '') . ' — ' . ($a->sa_name ?? '');
|
||||
}
|
||||
|
||||
return view('admin/layout', [
|
||||
'title' => '발주 현황',
|
||||
'content' => view('admin/bag_order/index', compact('list', 'itemSummary', 'companyMap', 'agencyMap', 'startDate', 'endDate', 'status', 'pager')),
|
||||
]);
|
||||
return $this->renderWorkPage('발주 현황', 'admin/bag_order/index', compact('list', 'itemSummary', 'companyMap', 'agencyMap', 'startDate', 'endDate', 'status', 'pager'));
|
||||
}
|
||||
|
||||
public function export()
|
||||
{
|
||||
helper(['admin', 'export']);
|
||||
$lgIdx = admin_effective_lg_idx();
|
||||
if (!$lgIdx) {
|
||||
return redirect()->to(site_url('admin/bag-orders'))->with('error', '지자체를 선택해 주세요.');
|
||||
if (! $lgIdx) {
|
||||
return redirect()->to(mgmt_url('bag-orders'))->with('error', '지자체를 선택해 주세요.');
|
||||
}
|
||||
|
||||
$builder = $this->orderModel->where('bo_lg_idx', $lgIdx);
|
||||
@@ -115,20 +112,19 @@ class BagOrder extends BaseController
|
||||
{
|
||||
helper('admin');
|
||||
$lgIdx = admin_effective_lg_idx();
|
||||
if (!$lgIdx) return redirect()->to(site_url('admin/bag-orders'))->with('error', '지자체를 선택해 주세요.');
|
||||
if (! $lgIdx) {
|
||||
return redirect()->to(mgmt_url('bag-orders'))->with('error', '지자체를 선택해 주세요.');
|
||||
}
|
||||
|
||||
// 봉투 종류 + 단가 + 포장단위
|
||||
$kind = model(CodeKindModel::class)->where('ck_code', 'O')->first();
|
||||
$bagCodes = $kind ? model(CodeDetailModel::class)->getByKind((int) $kind->ck_idx, true) : [];
|
||||
$kind = model(CodeKindModel::class)->where('ck_code', 'O')->first();
|
||||
$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();
|
||||
$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();
|
||||
$agencies = model(SalesAgencyModel::class)->where('sa_lg_idx', $lgIdx)->orderForDisplay()->findAll();
|
||||
|
||||
return view('admin/layout', [
|
||||
'title' => '발주 등록',
|
||||
'content' => view('admin/bag_order/create', compact('bagCodes', 'prices', 'units', 'companies', 'agencies')),
|
||||
]);
|
||||
return $this->renderWorkPage('발주 등록', 'admin/bag_order/create', compact('bagCodes', 'prices', 'units', 'companies', 'agencies'));
|
||||
}
|
||||
|
||||
public function store()
|
||||
@@ -200,8 +196,8 @@ class BagOrder extends BaseController
|
||||
$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;
|
||||
$kindO = model(CodeKindModel::class)->where('ck_code', 'O')->first();
|
||||
$detail = $kindO ? model(CodeDetailModel::class)->findResolvedByKindAndCode((int) $kindO->ck_idx, (string) $code, $lgIdx) : null;
|
||||
|
||||
$this->itemModel->insert([
|
||||
'boi_bo_idx' => $boIdx,
|
||||
@@ -216,7 +212,7 @@ class BagOrder extends BaseController
|
||||
|
||||
$db->transComplete();
|
||||
|
||||
return redirect()->to(site_url('admin/bag-orders'))->with('success', '발주가 등록되었습니다. LOT: ' . $lotNo);
|
||||
return redirect()->to(mgmt_url('bag-orders'))->with('success', '발주가 등록되었습니다. LOT: ' . $lotNo);
|
||||
}
|
||||
|
||||
public function detail(int $id)
|
||||
@@ -224,7 +220,7 @@ class BagOrder extends BaseController
|
||||
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', '발주를 찾을 수 없습니다.');
|
||||
return redirect()->to(mgmt_url('bag-orders'))->with('error', '발주를 찾을 수 없습니다.');
|
||||
}
|
||||
|
||||
$items = $this->itemModel->where('boi_bo_idx', $id)->findAll();
|
||||
@@ -237,13 +233,12 @@ class BagOrder extends BaseController
|
||||
$agencyName = '';
|
||||
if ($order->bo_agency_idx) {
|
||||
$a = model(SalesAgencyModel::class)->find($order->bo_agency_idx);
|
||||
$agencyName = $a ? $a->sa_name : '';
|
||||
if ($a) {
|
||||
$agencyName = '[' . ($a->sa_kind ?? '') . '] ' . ($a->sa_code ?? '') . ' — ' . ($a->sa_name ?? '');
|
||||
}
|
||||
}
|
||||
|
||||
return view('admin/layout', [
|
||||
'title' => '발주 상세 — ' . $order->bo_lot_no,
|
||||
'content' => view('admin/bag_order/detail', compact('order', 'items', 'companyName', 'agencyName')),
|
||||
]);
|
||||
return $this->renderWorkPage('발주 상세 — ' . $order->bo_lot_no, 'admin/bag_order/detail', compact('order', 'items', 'companyName', 'agencyName'));
|
||||
}
|
||||
|
||||
public function cancel(int $id)
|
||||
@@ -251,14 +246,15 @@ class BagOrder extends BaseController
|
||||
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', '발주를 찾을 수 없습니다.');
|
||||
return redirect()->to(mgmt_url('bag-orders'))->with('error', '발주를 찾을 수 없습니다.');
|
||||
}
|
||||
|
||||
$before = (array) $order;
|
||||
$this->orderModel->update($id, ['bo_status' => 'cancelled', 'bo_moddate' => date('Y-m-d H:i:s')]);
|
||||
helper('audit');
|
||||
audit_log('update', 'bag_order', $id, $before, ['bo_status' => 'cancelled']);
|
||||
return redirect()->to(site_url('admin/bag-orders'))->with('success', '발주가 취소되었습니다.');
|
||||
|
||||
return redirect()->to(mgmt_url('bag-orders'))->with('success', '발주가 취소되었습니다.');
|
||||
}
|
||||
|
||||
public function delete(int $id)
|
||||
@@ -266,13 +262,14 @@ class BagOrder extends BaseController
|
||||
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', '발주를 찾을 수 없습니다.');
|
||||
return redirect()->to(mgmt_url('bag-orders'))->with('error', '발주를 찾을 수 없습니다.');
|
||||
}
|
||||
|
||||
$before = (array) $order;
|
||||
$this->orderModel->update($id, ['bo_status' => 'deleted', 'bo_moddate' => date('Y-m-d H:i:s')]);
|
||||
helper('audit');
|
||||
audit_log('delete', 'bag_order', $id, $before, ['bo_status' => 'deleted']);
|
||||
return redirect()->to(site_url('admin/bag-orders'))->with('success', '발주가 삭제 처리되었습니다.');
|
||||
|
||||
return redirect()->to(mgmt_url('bag-orders'))->with('success', '발주가 삭제 처리되었습니다.');
|
||||
}
|
||||
}
|
||||
|
||||
@@ -22,36 +22,37 @@ class BagReceiving extends BaseController
|
||||
{
|
||||
helper('admin');
|
||||
$lgIdx = admin_effective_lg_idx();
|
||||
if (!$lgIdx) return redirect()->to(site_url('admin'))->with('error', '지자체를 선택해 주세요.');
|
||||
if (! $lgIdx) {
|
||||
return redirect()->to(work_area_home_url())->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);
|
||||
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);
|
||||
$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')),
|
||||
]);
|
||||
return $this->renderWorkPage('입고 현황', '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', '지자체를 선택해 주세요.');
|
||||
if (! $lgIdx) {
|
||||
return redirect()->to(mgmt_url('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')),
|
||||
]);
|
||||
return $this->renderWorkPage('입고 처리', 'admin/bag_receiving/create', compact('orders'));
|
||||
}
|
||||
|
||||
public function store()
|
||||
@@ -73,14 +74,12 @@ class BagReceiving extends BaseController
|
||||
$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;
|
||||
$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;
|
||||
$kindO = model(\App\Models\CodeKindModel::class)->where('ck_code', 'O')->first();
|
||||
$detail = $kindO ? model(\App\Models\CodeDetailModel::class)->findResolvedByKindAndCode((int) $kindO->ck_idx, (string) $bagCode, $lgIdx) : null;
|
||||
$bagName = $detail ? $detail->cd_name : '';
|
||||
|
||||
$db = \Config\Database::connect();
|
||||
@@ -100,11 +99,10 @@ class BagReceiving extends BaseController
|
||||
'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 . '박스)');
|
||||
return redirect()->to(mgmt_url('bag-receivings'))->with('success', '입고 처리되었습니다. (' . $bagName . ' ' . $qtyBox . '박스)');
|
||||
}
|
||||
}
|
||||
|
||||
@@ -23,45 +23,56 @@ class BagSale extends BaseController
|
||||
{
|
||||
helper('admin');
|
||||
$lgIdx = admin_effective_lg_idx();
|
||||
if (!$lgIdx) return redirect()->to(site_url('admin'))->with('error', '지자체를 선택해 주세요.');
|
||||
|
||||
$builder = $this->saleModel->where('bs_lg_idx', $lgIdx);
|
||||
$startDate = $this->request->getGet('start_date');
|
||||
$endDate = $this->request->getGet('end_date');
|
||||
$type = $this->request->getGet('type');
|
||||
if ($startDate) $builder->where('bs_sale_date >=', $startDate);
|
||||
if ($endDate) $builder->where('bs_sale_date <=', $endDate);
|
||||
if ($type) $builder->where('bs_type', $type);
|
||||
|
||||
$list = $builder->orderBy('bs_sale_date', 'DESC')->orderBy('bs_idx', 'DESC')->paginate(20);
|
||||
$pager = $this->saleModel->pager;
|
||||
|
||||
return view('admin/layout', [
|
||||
'title' => '판매/반품 관리',
|
||||
'content' => view('admin/bag_sale/index', compact('list', 'startDate', 'endDate', 'type', 'pager')),
|
||||
]);
|
||||
}
|
||||
|
||||
public function export()
|
||||
{
|
||||
helper(['admin', 'export']);
|
||||
$lgIdx = admin_effective_lg_idx();
|
||||
if (!$lgIdx) {
|
||||
return redirect()->to(site_url('admin/bag-sales'))->with('error', '지자체를 선택해 주세요.');
|
||||
if (! $lgIdx) {
|
||||
return redirect()->to(work_area_home_url())->with('error', '지자체를 선택해 주세요.');
|
||||
}
|
||||
|
||||
$builder = $this->saleModel->where('bs_lg_idx', $lgIdx);
|
||||
$startDate = $this->request->getGet('start_date');
|
||||
$endDate = $this->request->getGet('end_date');
|
||||
$type = $this->request->getGet('type');
|
||||
if ($startDate) $builder->where('bs_sale_date >=', $startDate);
|
||||
if ($endDate) $builder->where('bs_sale_date <=', $endDate);
|
||||
if ($type) $builder->where('bs_type', $type);
|
||||
if ($startDate) {
|
||||
$builder->where('bs_sale_date >=', $startDate);
|
||||
}
|
||||
if ($endDate) {
|
||||
$builder->where('bs_sale_date <=', $endDate);
|
||||
}
|
||||
if ($type) {
|
||||
$builder->where('bs_type', $type);
|
||||
}
|
||||
|
||||
$list = $builder->orderBy('bs_sale_date', 'DESC')->orderBy('bs_idx', 'DESC')->paginate(20);
|
||||
$pager = $this->saleModel->pager;
|
||||
|
||||
return $this->renderWorkPage('판매/반품 관리', 'admin/bag_sale/index', compact('list', 'startDate', 'endDate', 'type', 'pager'));
|
||||
}
|
||||
|
||||
public function export()
|
||||
{
|
||||
helper(['admin', 'export']);
|
||||
$lgIdx = admin_effective_lg_idx();
|
||||
if (! $lgIdx) {
|
||||
return redirect()->to(mgmt_url('bag-sales'))->with('error', '지자체를 선택해 주세요.');
|
||||
}
|
||||
|
||||
$builder = $this->saleModel->where('bs_lg_idx', $lgIdx);
|
||||
$startDate = $this->request->getGet('start_date');
|
||||
$endDate = $this->request->getGet('end_date');
|
||||
$type = $this->request->getGet('type');
|
||||
if ($startDate) {
|
||||
$builder->where('bs_sale_date >=', $startDate);
|
||||
}
|
||||
if ($endDate) {
|
||||
$builder->where('bs_sale_date <=', $endDate);
|
||||
}
|
||||
if ($type) {
|
||||
$builder->where('bs_type', $type);
|
||||
}
|
||||
|
||||
$list = $builder->orderBy('bs_sale_date', 'DESC')->orderBy('bs_idx', 'DESC')->findAll();
|
||||
|
||||
$typeMap = ['sale' => '판매', 'return' => '반품', 'cancel' => '취소'];
|
||||
$rows = [];
|
||||
$rows = [];
|
||||
foreach ($list as $row) {
|
||||
$rows[] = [
|
||||
$row->bs_idx,
|
||||
@@ -87,16 +98,15 @@ class BagSale extends BaseController
|
||||
{
|
||||
helper('admin');
|
||||
$lgIdx = admin_effective_lg_idx();
|
||||
if (!$lgIdx) return redirect()->to(site_url('admin/bag-sales'))->with('error', '지자체를 선택해 주세요.');
|
||||
if (! $lgIdx) {
|
||||
return redirect()->to(mgmt_url('bag-sales'))->with('error', '지자체를 선택해 주세요.');
|
||||
}
|
||||
|
||||
$shops = model(DesignatedShopModel::class)->where('ds_lg_idx', $lgIdx)->where('ds_state', 1)->findAll();
|
||||
$kind = model(CodeKindModel::class)->where('ck_code', 'O')->first();
|
||||
$bagCodes = $kind ? model(CodeDetailModel::class)->getByKind((int) $kind->ck_idx, true) : [];
|
||||
$kind = model(CodeKindModel::class)->where('ck_code', 'O')->first();
|
||||
$bagCodes = $kind ? model(CodeDetailModel::class)->getByKind((int) $kind->ck_idx, true, $lgIdx) : [];
|
||||
|
||||
return view('admin/layout', [
|
||||
'title' => '판매 등록',
|
||||
'content' => view('admin/bag_sale/create', compact('shops', 'bagCodes')),
|
||||
]);
|
||||
return $this->renderWorkPage('판매 등록', 'admin/bag_sale/create', compact('shops', 'bagCodes'));
|
||||
}
|
||||
|
||||
public function store()
|
||||
@@ -120,10 +130,10 @@ class BagSale extends BaseController
|
||||
$qty = (int) $this->request->getPost('bs_qty');
|
||||
$type = $this->request->getPost('bs_type');
|
||||
|
||||
$shop = model(DesignatedShopModel::class)->find($dsIdx);
|
||||
$kindO = model(CodeKindModel::class)->where('ck_code', 'O')->first();
|
||||
$detail = $kindO ? model(CodeDetailModel::class)->where('cd_ck_idx', $kindO->ck_idx)->where('cd_code', $bagCode)->first() : null;
|
||||
$price = model(BagPriceModel::class)->where('bp_lg_idx', $lgIdx)->where('bp_bag_code', $bagCode)->where('bp_state', 1)->first();
|
||||
$shop = model(DesignatedShopModel::class)->find($dsIdx);
|
||||
$kindO = model(CodeKindModel::class)->where('ck_code', 'O')->first();
|
||||
$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();
|
||||
$unitPrice = $price ? (float) $price->bp_consumer : 0;
|
||||
|
||||
$actualQty = ($type === 'return') ? -$qty : $qty;
|
||||
@@ -132,31 +142,30 @@ class BagSale extends BaseController
|
||||
$db->transStart();
|
||||
|
||||
$saleData = [
|
||||
'bs_lg_idx' => $lgIdx,
|
||||
'bs_ds_idx' => $dsIdx,
|
||||
'bs_ds_name' => $shop ? $shop->ds_name : '',
|
||||
'bs_sale_date' => $this->request->getPost('bs_sale_date'),
|
||||
'bs_bag_code' => $bagCode,
|
||||
'bs_bag_name' => $detail ? $detail->cd_name : '',
|
||||
'bs_qty' => $actualQty,
|
||||
'bs_unit_price'=> $unitPrice,
|
||||
'bs_amount' => $unitPrice * abs($actualQty),
|
||||
'bs_type' => $type,
|
||||
'bs_regdate' => date('Y-m-d H:i:s'),
|
||||
'bs_lg_idx' => $lgIdx,
|
||||
'bs_ds_idx' => $dsIdx,
|
||||
'bs_ds_name' => $shop ? $shop->ds_name : '',
|
||||
'bs_sale_date' => $this->request->getPost('bs_sale_date'),
|
||||
'bs_bag_code' => $bagCode,
|
||||
'bs_bag_name' => $detail ? $detail->cd_name : '',
|
||||
'bs_qty' => $actualQty,
|
||||
'bs_unit_price' => $unitPrice,
|
||||
'bs_amount' => $unitPrice * abs($actualQty),
|
||||
'bs_type' => $type,
|
||||
'bs_regdate' => date('Y-m-d H:i:s'),
|
||||
];
|
||||
$this->saleModel->insert($saleData);
|
||||
$bsIdx = (int) $this->saleModel->getInsertID();
|
||||
|
||||
// CT-05: 감사 로그
|
||||
helper('audit');
|
||||
audit_log('create', 'bag_sale', $bsIdx, null, array_merge($saleData, ['bs_idx' => $bsIdx]));
|
||||
|
||||
// 재고 감산(판매) / 가산(반품)
|
||||
model(BagInventoryModel::class)->adjustQty($lgIdx, $bagCode, $detail ? $detail->cd_name : '', -$actualQty);
|
||||
|
||||
$db->transComplete();
|
||||
|
||||
$msg = ($type === 'sale') ? '판매 처리되었습니다.' : '반품 처리되었습니다.';
|
||||
return redirect()->to(site_url('admin/bag-sales'))->with('success', $msg);
|
||||
|
||||
return redirect()->to(mgmt_url('bag-sales'))->with('success', $msg);
|
||||
}
|
||||
}
|
||||
|
||||
@@ -17,7 +17,9 @@ class SalesReport extends BaseController
|
||||
{
|
||||
helper('admin');
|
||||
$lgIdx = admin_effective_lg_idx();
|
||||
if (!$lgIdx) return redirect()->to(site_url('admin'))->with('error', '지자체를 선택해 주세요.');
|
||||
if (! $lgIdx) {
|
||||
return redirect()->to(work_area_home_url())->with('error', '지자체를 선택해 주세요.');
|
||||
}
|
||||
|
||||
$startDate = $this->request->getGet('start_date') ?? date('Y-m-01');
|
||||
$endDate = $this->request->getGet('end_date') ?? date('Y-m-d');
|
||||
@@ -50,10 +52,7 @@ class SalesReport extends BaseController
|
||||
", [$lgIdx, $startDate, $endDate])->getResult();
|
||||
}
|
||||
|
||||
return view('admin/layout', [
|
||||
'title' => '판매 대장',
|
||||
'content' => view('admin/sales_report/sales_ledger', compact('result', 'startDate', 'endDate', 'mode')),
|
||||
]);
|
||||
return $this->renderWorkPage('판매 대장', 'admin/sales_report/sales_ledger', compact('result', 'startDate', 'endDate', 'mode'));
|
||||
}
|
||||
|
||||
/**
|
||||
@@ -63,7 +62,9 @@ class SalesReport extends BaseController
|
||||
{
|
||||
helper('admin');
|
||||
$lgIdx = admin_effective_lg_idx();
|
||||
if (!$lgIdx) return redirect()->to(site_url('admin'))->with('error', '지자체를 선택해 주세요.');
|
||||
if (! $lgIdx) {
|
||||
return redirect()->to(work_area_home_url())->with('error', '지자체를 선택해 주세요.');
|
||||
}
|
||||
|
||||
$date = $this->request->getGet('date') ?? date('Y-m-d');
|
||||
$db = \Config\Database::connect();
|
||||
@@ -91,10 +92,7 @@ class SalesReport extends BaseController
|
||||
ORDER BY bs_bag_code
|
||||
", [$lgIdx, $monthStart, $date])->getResult();
|
||||
|
||||
return view('admin/layout', [
|
||||
'title' => '일계표',
|
||||
'content' => view('admin/sales_report/daily_summary', compact('daily', 'monthly', 'date')),
|
||||
]);
|
||||
return $this->renderWorkPage('일계표', 'admin/sales_report/daily_summary', compact('daily', 'monthly', 'date'));
|
||||
}
|
||||
|
||||
/**
|
||||
@@ -104,7 +102,9 @@ class SalesReport extends BaseController
|
||||
{
|
||||
helper('admin');
|
||||
$lgIdx = admin_effective_lg_idx();
|
||||
if (!$lgIdx) return redirect()->to(site_url('admin'))->with('error', '지자체를 선택해 주세요.');
|
||||
if (! $lgIdx) {
|
||||
return redirect()->to(work_area_home_url())->with('error', '지자체를 선택해 주세요.');
|
||||
}
|
||||
|
||||
$startDate = $this->request->getGet('start_date') ?? date('Y-m-01');
|
||||
$endDate = $this->request->getGet('end_date') ?? date('Y-m-d');
|
||||
@@ -122,10 +122,7 @@ class SalesReport extends BaseController
|
||||
ORDER BY bs_bag_code
|
||||
", [$lgIdx, $startDate, $endDate])->getResult();
|
||||
|
||||
return view('admin/layout', [
|
||||
'title' => '기간별 판매현황',
|
||||
'content' => view('admin/sales_report/period_sales', compact('result', 'startDate', 'endDate')),
|
||||
]);
|
||||
return $this->renderWorkPage('기간별 판매현황', 'admin/sales_report/period_sales', compact('result', 'startDate', 'endDate'));
|
||||
}
|
||||
|
||||
/**
|
||||
@@ -135,7 +132,9 @@ class SalesReport extends BaseController
|
||||
{
|
||||
helper('admin');
|
||||
$lgIdx = admin_effective_lg_idx();
|
||||
if (!$lgIdx) return redirect()->to(site_url('admin'))->with('error', '지자체를 선택해 주세요.');
|
||||
if (! $lgIdx) {
|
||||
return redirect()->to(work_area_home_url())->with('error', '지자체를 선택해 주세요.');
|
||||
}
|
||||
|
||||
$year = $this->request->getGet('year') ?? date('Y');
|
||||
$db = \Config\Database::connect();
|
||||
@@ -161,10 +160,7 @@ class SalesReport extends BaseController
|
||||
ORDER BY bs_bag_code
|
||||
", [$lgIdx, $year])->getResult();
|
||||
|
||||
return view('admin/layout', [
|
||||
'title' => '년 판매 현황',
|
||||
'content' => view('admin/sales_report/yearly_sales', compact('result', 'year')),
|
||||
]);
|
||||
return $this->renderWorkPage('년 판매 현황', 'admin/sales_report/yearly_sales', compact('result', 'year'));
|
||||
}
|
||||
|
||||
/**
|
||||
@@ -174,7 +170,9 @@ class SalesReport extends BaseController
|
||||
{
|
||||
helper('admin');
|
||||
$lgIdx = admin_effective_lg_idx();
|
||||
if (!$lgIdx) return redirect()->to(site_url('admin'))->with('error', '지자체를 선택해 주세요.');
|
||||
if (! $lgIdx) {
|
||||
return redirect()->to(work_area_home_url())->with('error', '지자체를 선택해 주세요.');
|
||||
}
|
||||
|
||||
$startDate = $this->request->getGet('start_date') ?? date('Y-m-01');
|
||||
$endDate = $this->request->getGet('end_date') ?? date('Y-m-d');
|
||||
@@ -192,10 +190,7 @@ class SalesReport extends BaseController
|
||||
ORDER BY bs_ds_name
|
||||
", [$lgIdx, $startDate, $endDate])->getResult();
|
||||
|
||||
return view('admin/layout', [
|
||||
'title' => '지정판매소별 판매현황',
|
||||
'content' => view('admin/sales_report/shop_sales', compact('result', 'startDate', 'endDate')),
|
||||
]);
|
||||
return $this->renderWorkPage('지정판매소별 판매현황', 'admin/sales_report/shop_sales', compact('result', 'startDate', 'endDate'));
|
||||
}
|
||||
|
||||
/**
|
||||
@@ -205,7 +200,9 @@ class SalesReport extends BaseController
|
||||
{
|
||||
helper(['admin', 'export']);
|
||||
$lgIdx = admin_effective_lg_idx();
|
||||
if (!$lgIdx) return redirect()->to(site_url('admin'))->with('error', '지자체를 선택해 주세요.');
|
||||
if (! $lgIdx) {
|
||||
return redirect()->to(work_area_home_url())->with('error', '지자체를 선택해 주세요.');
|
||||
}
|
||||
|
||||
$startDate = $this->request->getGet('start_date') ?? date('Y-m-01');
|
||||
$endDate = $this->request->getGet('end_date') ?? date('Y-m-d');
|
||||
@@ -257,7 +254,9 @@ class SalesReport extends BaseController
|
||||
{
|
||||
helper('admin');
|
||||
$lgIdx = admin_effective_lg_idx();
|
||||
if (!$lgIdx) return redirect()->to(site_url('admin'))->with('error', '지자체를 선택해 주세요.');
|
||||
if (! $lgIdx) {
|
||||
return redirect()->to(work_area_home_url())->with('error', '지자체를 선택해 주세요.');
|
||||
}
|
||||
|
||||
$startDate = $this->request->getGet('start_date') ?? date('Y-m-01');
|
||||
$endDate = $this->request->getGet('end_date') ?? date('Y-m-d');
|
||||
@@ -271,10 +270,7 @@ class SalesReport extends BaseController
|
||||
ORDER BY bs_sale_date DESC, bs_ds_name
|
||||
", [$lgIdx, $startDate, $endDate])->getResult();
|
||||
|
||||
return view('admin/layout', [
|
||||
'title' => '반품/파기 현황',
|
||||
'content' => view('admin/sales_report/returns', compact('result', 'startDate', 'endDate')),
|
||||
]);
|
||||
return $this->renderWorkPage('반품/파기 현황', 'admin/sales_report/returns', compact('result', 'startDate', 'endDate'));
|
||||
}
|
||||
|
||||
/**
|
||||
@@ -284,7 +280,9 @@ class SalesReport extends BaseController
|
||||
{
|
||||
helper('admin');
|
||||
$lgIdx = admin_effective_lg_idx();
|
||||
if (!$lgIdx) return redirect()->to(site_url('admin'))->with('error', '지자체를 선택해 주세요.');
|
||||
if (! $lgIdx) {
|
||||
return redirect()->to(work_area_home_url())->with('error', '지자체를 선택해 주세요.');
|
||||
}
|
||||
|
||||
$lotNo = $this->request->getGet('lot_no') ?? '';
|
||||
$order = null;
|
||||
@@ -300,10 +298,7 @@ class SalesReport extends BaseController
|
||||
}
|
||||
}
|
||||
|
||||
return view('admin/layout', [
|
||||
'title' => 'LOT 수불 조회',
|
||||
'content' => view('admin/sales_report/lot_flow', compact('lotNo', 'order', 'items', 'receivings')),
|
||||
]);
|
||||
return $this->renderWorkPage('LOT 수불 조회', 'admin/sales_report/lot_flow', compact('lotNo', 'order', 'items', 'receivings'));
|
||||
}
|
||||
|
||||
/**
|
||||
@@ -313,7 +308,9 @@ class SalesReport extends BaseController
|
||||
{
|
||||
helper('admin');
|
||||
$lgIdx = admin_effective_lg_idx();
|
||||
if (!$lgIdx) return redirect()->to(site_url('admin'))->with('error', '지자체를 선택해 주세요.');
|
||||
if (! $lgIdx) {
|
||||
return redirect()->to(work_area_home_url())->with('error', '지자체를 선택해 주세요.');
|
||||
}
|
||||
|
||||
$startDate = $this->request->getGet('start_date') ?? date('Y-m-01');
|
||||
$endDate = $this->request->getGet('end_date') ?? date('Y-m-d');
|
||||
@@ -332,12 +329,9 @@ class SalesReport extends BaseController
|
||||
|
||||
// 봉투 코드 목록
|
||||
$kindO = model(\App\Models\CodeKindModel::class)->where('ck_code', 'O')->first();
|
||||
$bagCodes = $kindO ? model(\App\Models\CodeDetailModel::class)->getByKind((int) $kindO->ck_idx, true) : [];
|
||||
$bagCodes = $kindO ? model(\App\Models\CodeDetailModel::class)->getByKind((int) $kindO->ck_idx, true, $lgIdx) : [];
|
||||
|
||||
return view('admin/layout', [
|
||||
'title' => '기타 입출고',
|
||||
'content' => view('admin/sales_report/misc_flow', compact('result', 'startDate', 'endDate', 'bagCodes', 'tableExists')),
|
||||
]);
|
||||
return $this->renderWorkPage('기타 입출고', 'admin/sales_report/misc_flow', compact('result', 'startDate', 'endDate', 'bagCodes', 'tableExists'));
|
||||
}
|
||||
|
||||
/**
|
||||
@@ -347,7 +341,7 @@ class SalesReport extends BaseController
|
||||
{
|
||||
helper('admin');
|
||||
$lgIdx = admin_effective_lg_idx();
|
||||
if (!$lgIdx) return redirect()->to(site_url('admin/reports/misc-flow'))->with('error', '지자체를 선택해 주세요.');
|
||||
if (!$lgIdx) return redirect()->to(mgmt_url('reports/misc-flow'))->with('error', '지자체를 선택해 주세요.');
|
||||
|
||||
$rules = [
|
||||
'bmf_type' => 'required|in_list[in,out]',
|
||||
@@ -366,7 +360,7 @@ class SalesReport extends BaseController
|
||||
|
||||
// 봉투명 조회
|
||||
$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;
|
||||
$detail = $kindO ? model(\App\Models\CodeDetailModel::class)->findResolvedByKindAndCode((int) $kindO->ck_idx, (string) $bagCode, $lgIdx) : null;
|
||||
$bagName = $detail ? $detail->cd_name : '';
|
||||
|
||||
$db = \Config\Database::connect();
|
||||
@@ -383,7 +377,7 @@ class SalesReport extends BaseController
|
||||
|
||||
$db->transComplete();
|
||||
|
||||
return redirect()->to(site_url('admin/reports/misc-flow'))->with('success', '기타 입출고가 등록되었습니다.');
|
||||
return redirect()->to(mgmt_url('reports/misc-flow'))->with('success', '기타 입출고가 등록되었습니다.');
|
||||
}
|
||||
|
||||
/**
|
||||
@@ -393,7 +387,9 @@ class SalesReport extends BaseController
|
||||
{
|
||||
helper('admin');
|
||||
$lgIdx = admin_effective_lg_idx();
|
||||
if (!$lgIdx) return redirect()->to(site_url('admin'))->with('error', '지자체를 선택해 주세요.');
|
||||
if (! $lgIdx) {
|
||||
return redirect()->to(work_area_home_url())->with('error', '지자체를 선택해 주세요.');
|
||||
}
|
||||
|
||||
$startDate = $this->request->getGet('start_date') ?? date('Y-m-01');
|
||||
$endDate = $this->request->getGet('end_date') ?? date('Y-m-d');
|
||||
@@ -430,9 +426,6 @@ class SalesReport extends BaseController
|
||||
// 현재 재고
|
||||
$inventory = model(BagInventoryModel::class)->where('bi_lg_idx', $lgIdx)->findAll();
|
||||
|
||||
return view('admin/layout', [
|
||||
'title' => '봉투 수불 현황',
|
||||
'content' => view('admin/sales_report/supply_demand', compact('receiving', 'sales', 'issues', 'inventory', 'startDate', 'endDate')),
|
||||
]);
|
||||
return $this->renderWorkPage('봉투 수불 현황', 'admin/sales_report/supply_demand', compact('receiving', 'sales', 'issues', 'inventory', 'startDate', 'endDate'));
|
||||
}
|
||||
}
|
||||
|
||||
@@ -26,37 +26,39 @@ class ShopOrder extends BaseController
|
||||
{
|
||||
helper('admin');
|
||||
$lgIdx = admin_effective_lg_idx();
|
||||
if (!$lgIdx) return redirect()->to(site_url('admin'))->with('error', '지자체를 선택해 주세요.');
|
||||
if (! $lgIdx) {
|
||||
return redirect()->to(work_area_home_url())->with('error', '지자체를 선택해 주세요.');
|
||||
}
|
||||
|
||||
$builder = $this->orderModel->where('so_lg_idx', $lgIdx);
|
||||
$startDate = $this->request->getGet('start_date');
|
||||
$endDate = $this->request->getGet('end_date');
|
||||
if ($startDate) $builder->where('so_delivery_date >=', $startDate);
|
||||
if ($endDate) $builder->where('so_delivery_date <=', $endDate);
|
||||
if ($startDate) {
|
||||
$builder->where('so_delivery_date >=', $startDate);
|
||||
}
|
||||
if ($endDate) {
|
||||
$builder->where('so_delivery_date <=', $endDate);
|
||||
}
|
||||
|
||||
$list = $builder->orderBy('so_idx', 'DESC')->paginate(20);
|
||||
$list = $builder->orderBy('so_idx', 'DESC')->paginate(20);
|
||||
$pager = $this->orderModel->pager;
|
||||
|
||||
return view('admin/layout', [
|
||||
'title' => '주문 접수 관리',
|
||||
'content' => view('admin/shop_order/index', compact('list', 'startDate', 'endDate', 'pager')),
|
||||
]);
|
||||
return $this->renderWorkPage('주문 접수 관리', 'admin/shop_order/index', compact('list', 'startDate', 'endDate', 'pager'));
|
||||
}
|
||||
|
||||
public function create()
|
||||
{
|
||||
helper('admin');
|
||||
$lgIdx = admin_effective_lg_idx();
|
||||
if (!$lgIdx) return redirect()->to(site_url('admin/shop-orders'))->with('error', '지자체를 선택해 주세요.');
|
||||
if (! $lgIdx) {
|
||||
return redirect()->to(mgmt_url('shop-orders'))->with('error', '지자체를 선택해 주세요.');
|
||||
}
|
||||
|
||||
$shops = model(DesignatedShopModel::class)->where('ds_lg_idx', $lgIdx)->where('ds_state', 1)->findAll();
|
||||
$kind = model(CodeKindModel::class)->where('ck_code', 'O')->first();
|
||||
$bagCodes = $kind ? model(CodeDetailModel::class)->getByKind((int) $kind->ck_idx, true) : [];
|
||||
$kind = model(CodeKindModel::class)->where('ck_code', 'O')->first();
|
||||
$bagCodes = $kind ? model(CodeDetailModel::class)->getByKind((int) $kind->ck_idx, true, $lgIdx) : [];
|
||||
|
||||
return view('admin/layout', [
|
||||
'title' => '주문 접수',
|
||||
'content' => view('admin/shop_order/create', compact('shops', 'bagCodes')),
|
||||
]);
|
||||
return $this->renderWorkPage('주문 접수', 'admin/shop_order/create', compact('shops', 'bagCodes'));
|
||||
}
|
||||
|
||||
public function store()
|
||||
@@ -65,9 +67,9 @@ class ShopOrder extends BaseController
|
||||
$lgIdx = admin_effective_lg_idx();
|
||||
|
||||
$rules = [
|
||||
'so_ds_idx' => 'required|is_natural_no_zero',
|
||||
'so_delivery_date'=> 'required|valid_date[Y-m-d]',
|
||||
'so_payment_type' => 'required|in_list[이체,가상계좌]',
|
||||
'so_ds_idx' => 'required|is_natural_no_zero',
|
||||
'so_delivery_date' => 'required|valid_date[Y-m-d]',
|
||||
'so_payment_type' => 'required|in_list[이체,가상계좌]',
|
||||
];
|
||||
if (! $this->validate($rules)) {
|
||||
return redirect()->back()->withInput()->with('errors', $this->validator->getErrors());
|
||||
@@ -77,57 +79,62 @@ class ShopOrder extends BaseController
|
||||
$db->transStart();
|
||||
|
||||
$dsIdx = (int) $this->request->getPost('so_ds_idx');
|
||||
$shop = model(DesignatedShopModel::class)->find($dsIdx);
|
||||
$shop = model(DesignatedShopModel::class)->find($dsIdx);
|
||||
|
||||
$this->orderModel->insert([
|
||||
'so_lg_idx' => $lgIdx,
|
||||
'so_ds_idx' => $dsIdx,
|
||||
'so_ds_name' => $shop ? $shop->ds_name : '',
|
||||
'so_order_date' => date('Y-m-d'),
|
||||
'so_delivery_date'=> $this->request->getPost('so_delivery_date'),
|
||||
'so_payment_type' => $this->request->getPost('so_payment_type'),
|
||||
'so_status' => 'normal',
|
||||
'so_orderer_idx' => session()->get('mb_idx'),
|
||||
'so_regdate' => date('Y-m-d H:i:s'),
|
||||
'so_lg_idx' => $lgIdx,
|
||||
'so_ds_idx' => $dsIdx,
|
||||
'so_ds_name' => $shop ? $shop->ds_name : '',
|
||||
'so_order_date' => date('Y-m-d'),
|
||||
'so_delivery_date' => $this->request->getPost('so_delivery_date'),
|
||||
'so_payment_type' => $this->request->getPost('so_payment_type'),
|
||||
'so_status' => 'normal',
|
||||
'so_orderer_idx' => session()->get('mb_idx'),
|
||||
'so_regdate' => date('Y-m-d H:i:s'),
|
||||
]);
|
||||
$soIdx = (int) $this->orderModel->getInsertID();
|
||||
|
||||
$bagCodes = $this->request->getPost('item_bag_code') ?? [];
|
||||
$qtys = $this->request->getPost('item_qty') ?? [];
|
||||
$totalQty = 0; $totalAmt = 0;
|
||||
$totalQty = 0;
|
||||
$totalAmt = 0;
|
||||
|
||||
foreach ($bagCodes as $i => $code) {
|
||||
if (empty($code) || empty($qtys[$i])) continue;
|
||||
if (empty($code) || empty($qtys[$i])) {
|
||||
continue;
|
||||
}
|
||||
$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)->where('bp_lg_idx', $lgIdx)->where('bp_bag_code', $code)->where('bp_state', 1)->first();
|
||||
$unitPrice = $price ? (float) $price->bp_consumer : 0;
|
||||
$amount = $unitPrice * $qty;
|
||||
$amount = $unitPrice * $qty;
|
||||
|
||||
$unit = model(PackagingUnitModel::class)->where('pu_lg_idx', $lgIdx)->where('pu_bag_code', $code)->where('pu_state', 1)->first();
|
||||
$boxCount = 0; $packCount = 0; $sheetCount = $qty;
|
||||
$boxCount = 0;
|
||||
$packCount = 0;
|
||||
$sheetCount = $qty;
|
||||
if ($unit && (int) $unit->pu_total_per_box > 0) {
|
||||
$boxCount = intdiv($qty, (int) $unit->pu_total_per_box);
|
||||
$remainder = $qty % (int) $unit->pu_total_per_box;
|
||||
$boxCount = intdiv($qty, (int) $unit->pu_total_per_box);
|
||||
$remainder = $qty % (int) $unit->pu_total_per_box;
|
||||
if ((int) $unit->pu_pack_per_sheet > 0) {
|
||||
$packCount = intdiv($remainder, (int) $unit->pu_pack_per_sheet);
|
||||
$packCount = intdiv($remainder, (int) $unit->pu_pack_per_sheet);
|
||||
$sheetCount = $remainder % (int) $unit->pu_pack_per_sheet;
|
||||
}
|
||||
}
|
||||
|
||||
$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;
|
||||
$kindO = model(CodeKindModel::class)->where('ck_code', 'O')->first();
|
||||
$detail = $kindO ? model(CodeDetailModel::class)->findResolvedByKindAndCode((int) $kindO->ck_idx, (string) $code, $lgIdx) : null;
|
||||
|
||||
$this->itemModel->insert([
|
||||
'soi_so_idx' => $soIdx,
|
||||
'soi_bag_code' => $code,
|
||||
'soi_bag_name' => $detail ? $detail->cd_name : '',
|
||||
'soi_unit_price' => $unitPrice,
|
||||
'soi_qty' => $qty,
|
||||
'soi_amount' => $amount,
|
||||
'soi_box_count' => $boxCount,
|
||||
'soi_pack_count' => $packCount,
|
||||
'soi_sheet_count'=> $sheetCount,
|
||||
'soi_so_idx' => $soIdx,
|
||||
'soi_bag_code' => $code,
|
||||
'soi_bag_name' => $detail ? $detail->cd_name : '',
|
||||
'soi_unit_price' => $unitPrice,
|
||||
'soi_qty' => $qty,
|
||||
'soi_amount' => $amount,
|
||||
'soi_box_count' => $boxCount,
|
||||
'soi_pack_count' => $packCount,
|
||||
'soi_sheet_count' => $sheetCount,
|
||||
]);
|
||||
|
||||
$totalQty += $qty;
|
||||
@@ -137,18 +144,19 @@ class ShopOrder extends BaseController
|
||||
$this->orderModel->update($soIdx, ['so_total_qty' => $totalQty, 'so_total_amount' => $totalAmt]);
|
||||
$db->transComplete();
|
||||
|
||||
return redirect()->to(site_url('admin/shop-orders'))->with('success', '주문이 접수되었습니다.');
|
||||
return redirect()->to(mgmt_url('shop-orders'))->with('success', '주문이 접수되었습니다.');
|
||||
}
|
||||
|
||||
public function cancel(int $id)
|
||||
{
|
||||
helper('admin');
|
||||
$order = $this->orderModel->find($id);
|
||||
if (!$order || (int) $order->so_lg_idx !== admin_effective_lg_idx()) {
|
||||
return redirect()->to(site_url('admin/shop-orders'))->with('error', '주문을 찾을 수 없습니다.');
|
||||
if (! $order || (int) $order->so_lg_idx !== admin_effective_lg_idx()) {
|
||||
return redirect()->to(mgmt_url('shop-orders'))->with('error', '주문을 찾을 수 없습니다.');
|
||||
}
|
||||
|
||||
$this->orderModel->update($id, ['so_status' => 'cancelled']);
|
||||
return redirect()->to(site_url('admin/shop-orders'))->with('success', '주문이 취소되었습니다.');
|
||||
|
||||
return redirect()->to(mgmt_url('shop-orders'))->with('success', '주문이 취소되었습니다.');
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user