feat: [stock,client,status-board] 날짜 필터 및 조건 보완
- StockController/StockService: 입출고 이력 기반 날짜 범위 필터 추가 - ClientService: 등록일 기간 필터(start_date/end_date) 추가 - StatusBoardService: 부실채권 현황에 is_active 조건 추가 (목록 페이지 일치) Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com>
This commit is contained in:
@@ -29,6 +29,8 @@ public function index(Request $request): JsonResponse
|
||||
'sort_dir',
|
||||
'per_page',
|
||||
'page',
|
||||
'start_date',
|
||||
'end_date',
|
||||
]);
|
||||
|
||||
$stocks = $this->service->index($params);
|
||||
|
||||
@@ -22,6 +22,8 @@ public function index(array $params)
|
||||
$q = trim((string) ($params['q'] ?? ''));
|
||||
$onlyActive = $params['only_active'] ?? null;
|
||||
$clientType = $params['client_type'] ?? null;
|
||||
$startDate = $params['start_date'] ?? null;
|
||||
$endDate = $params['end_date'] ?? null;
|
||||
|
||||
$query = Client::query()->where('tenant_id', $tenantId);
|
||||
|
||||
@@ -43,6 +45,14 @@ public function index(array $params)
|
||||
$query->whereIn('client_type', $types);
|
||||
}
|
||||
|
||||
// 등록일 기간 필터
|
||||
if ($startDate) {
|
||||
$query->whereDate('created_at', '>=', $startDate);
|
||||
}
|
||||
if ($endDate) {
|
||||
$query->whereDate('created_at', '<=', $endDate);
|
||||
}
|
||||
|
||||
$query->orderBy('client_code')->orderBy('id');
|
||||
|
||||
$paginator = $query->paginate($size, ['*'], 'page', $page);
|
||||
|
||||
@@ -70,6 +70,7 @@ private function getBadDebtStatus(int $tenantId): array
|
||||
$count = BadDebt::query()
|
||||
->where('tenant_id', $tenantId)
|
||||
->where('status', BadDebt::STATUS_COLLECTING) // 추심 진행 중
|
||||
->where('is_active', true) // 활성 채권만 (목록 페이지와 일치)
|
||||
->count();
|
||||
|
||||
return [
|
||||
|
||||
@@ -88,6 +88,20 @@ public function index(array $params): LengthAwarePaginator
|
||||
});
|
||||
}
|
||||
|
||||
// 날짜 범위 필터 (해당 기간에 입출고 이력이 있는 품목만)
|
||||
if (! empty($params['start_date']) || ! empty($params['end_date'])) {
|
||||
$query->whereHas('stock', function ($stockQuery) use ($params) {
|
||||
$stockQuery->whereHas('transactions', function ($txQuery) use ($params) {
|
||||
if (! empty($params['start_date'])) {
|
||||
$txQuery->whereDate('created_at', '>=', $params['start_date']);
|
||||
}
|
||||
if (! empty($params['end_date'])) {
|
||||
$txQuery->whereDate('created_at', '<=', $params['end_date']);
|
||||
}
|
||||
});
|
||||
});
|
||||
}
|
||||
|
||||
// 정렬
|
||||
$sortBy = $params['sort_by'] ?? 'code';
|
||||
$sortDir = $params['sort_dir'] ?? 'asc';
|
||||
|
||||
Reference in New Issue
Block a user