- DB: bag_order, bag_order_item, bag_receiving, bag_inventory 테이블 - 발주: UUID v4, SHA-256 해시, LOT번호 자동생성, 봉투별 품목 관리 - 포장단위 연동 (박스→낱장 자동 환산), 단가 연동 (금액 자동 계산) - 발주 현황 (기간/상태 필터), 상세 조회, 취소/삭제 (상태 변경) - 입고: 발주건 기반 입고 처리, 박스→낱장 환산, 재고 자동 가산 - 재고: 지자체별 봉투 종류별 현재 재고 조회 - E2E 테스트 7개 전체 통과 Co-Authored-By: Claude Opus 4.6 (1M context) <noreply@anthropic.com>
39 lines
1.1 KiB
PHP
39 lines
1.1 KiB
PHP
<?php
|
|
|
|
namespace App\Models;
|
|
|
|
use CodeIgniter\Model;
|
|
|
|
class BagInventoryModel extends Model
|
|
{
|
|
protected $table = 'bag_inventory';
|
|
protected $primaryKey = 'bi_idx';
|
|
protected $returnType = 'object';
|
|
protected $useTimestamps = false;
|
|
protected $allowedFields = [
|
|
'bi_lg_idx', 'bi_bag_code', 'bi_bag_name', 'bi_qty', 'bi_updated_at',
|
|
];
|
|
|
|
/**
|
|
* 재고 증감 (upsert)
|
|
*/
|
|
public function adjustQty(int $lgIdx, string $bagCode, string $bagName, int $delta): void
|
|
{
|
|
$existing = $this->where('bi_lg_idx', $lgIdx)->where('bi_bag_code', $bagCode)->first();
|
|
if ($existing) {
|
|
$this->update($existing->bi_idx, [
|
|
'bi_qty' => max(0, (int) $existing->bi_qty + $delta),
|
|
'bi_updated_at' => date('Y-m-d H:i:s'),
|
|
]);
|
|
} else {
|
|
$this->insert([
|
|
'bi_lg_idx' => $lgIdx,
|
|
'bi_bag_code' => $bagCode,
|
|
'bi_bag_name' => $bagName,
|
|
'bi_qty' => max(0, $delta),
|
|
'bi_updated_at'=> date('Y-m-d H:i:s'),
|
|
]);
|
|
}
|
|
}
|
|
}
|