feat(API): 부실채권, 재고, 입고 기능 개선
- BadDebt 컨트롤러/서비스 기능 확장 - StockService 재고 조회 로직 개선 - ProcessReceivingRequest 검증 규칙 수정 - Item, Order, CommonCode, Shipment 모델 업데이트 - TodayIssueObserverService 개선 Co-Authored-By: Claude Opus 4.5 <noreply@anthropic.com>
This commit is contained in:
@@ -18,14 +18,15 @@ public function __construct(
|
||||
) {}
|
||||
|
||||
/**
|
||||
* 악성채권 목록
|
||||
* 악성채권 목록 (거래처 기준)
|
||||
*
|
||||
* 거래처별 활성 악성채권 집계 목록을 반환
|
||||
*/
|
||||
public function index(Request $request)
|
||||
{
|
||||
$params = $request->only([
|
||||
'client_id',
|
||||
'status',
|
||||
'is_active',
|
||||
'search',
|
||||
'sort_by',
|
||||
'sort_dir',
|
||||
@@ -33,9 +34,54 @@ public function index(Request $request)
|
||||
'page',
|
||||
]);
|
||||
|
||||
$badDebts = $this->service->index($params);
|
||||
$clients = $this->service->index($params);
|
||||
|
||||
return ApiResponse::success($badDebts, __('message.fetched'));
|
||||
// 거래처 기준 응답으로 변환
|
||||
$transformedData = $clients->through(function ($client) {
|
||||
// 가장 최근 활성 악성채권 정보
|
||||
$latestBadDebt = $client->activeBadDebts->first();
|
||||
|
||||
return [
|
||||
'id' => $client->id,
|
||||
'client_id' => $client->id,
|
||||
'client_code' => $client->client_code,
|
||||
'client_name' => $client->name,
|
||||
'business_no' => $client->business_no,
|
||||
'contact_person' => $client->contact_person,
|
||||
'phone' => $client->phone,
|
||||
'mobile' => $client->mobile,
|
||||
'email' => $client->email,
|
||||
'address' => $client->address,
|
||||
'client_type' => $client->client_type,
|
||||
// 집계 데이터
|
||||
'total_debt_amount' => (float) ($client->total_debt_amount ?? 0),
|
||||
'max_overdue_days' => (int) ($client->max_overdue_days ?? 0),
|
||||
'bad_debt_count' => (int) ($client->active_bad_debt_count ?? 0),
|
||||
// 대표 상태 (가장 최근 악성채권의 상태)
|
||||
'status' => $latestBadDebt?->status ?? 'collecting',
|
||||
'is_active' => true, // 리스트에 나온 건 모두 활성
|
||||
// 담당자 (가장 최근 악성채권의 담당자)
|
||||
'assigned_user' => $latestBadDebt?->assignedUser ? [
|
||||
'id' => $latestBadDebt->assignedUser->id,
|
||||
'name' => $latestBadDebt->assignedUser->name,
|
||||
] : null,
|
||||
// 개별 악성채권 목록
|
||||
'bad_debts' => $client->activeBadDebts->map(fn ($bd) => [
|
||||
'id' => $bd->id,
|
||||
'debt_amount' => (float) $bd->debt_amount,
|
||||
'status' => $bd->status,
|
||||
'overdue_days' => $bd->overdue_days,
|
||||
'is_active' => $bd->is_active,
|
||||
'occurred_at' => $bd->occurred_at?->toDateString(),
|
||||
'assigned_user' => $bd->assignedUser ? [
|
||||
'id' => $bd->assignedUser->id,
|
||||
'name' => $bd->assignedUser->name,
|
||||
] : null,
|
||||
])->toArray(),
|
||||
];
|
||||
});
|
||||
|
||||
return ApiResponse::success($transformedData, __('message.fetched'));
|
||||
}
|
||||
|
||||
/**
|
||||
|
||||
Reference in New Issue
Block a user