feat(API): 입금/출금 알림 Observer 추가 및 LoanController 수정

- DepositIssueObserver, WithdrawalIssueObserver 신규 추가
- TodayIssueObserverService에 입금/출금 핸들러 및 디버그 로그 추가
- TodayIssue 모델에 입금/출금 상수 추가
- AppServiceProvider에 Observer 등록
- ApprovalService에 기존 결재선 사용 시 수동 알림 트리거 추가
- LoanController ApiResponse::handle() → ApiResponse::success() 수정

Co-Authored-By: Claude <noreply@anthropic.com>
This commit is contained in:
2026-01-23 10:05:50 +09:00
parent fabf302e1f
commit d75f6f5bd1
9 changed files with 232 additions and 22 deletions

View File

@@ -8,9 +8,11 @@
use App\Models\Orders\Order;
use App\Models\PushDeviceToken;
use App\Models\Tenants\ApprovalStep;
use App\Models\Tenants\Deposit;
use App\Models\Tenants\ExpectedExpense;
use App\Models\Tenants\Stock;
use App\Models\Tenants\TodayIssue;
use App\Models\Tenants\Withdrawal;
use App\Services\Fcm\FcmSender;
use Carbon\Carbon;
use Illuminate\Support\Facades\Log;
@@ -261,6 +263,92 @@ public function handleClientDeleted(Client $client): void
TodayIssue::removeBySource($client->tenant_id, TodayIssue::SOURCE_CLIENT, $client->id);
}
/**
* 입금 등록 이슈 생성
*/
public function handleDepositCreated(Deposit $deposit): void
{
Log::info('TodayIssue: Deposit created detected', [
'deposit_id' => $deposit->id,
'tenant_id' => $deposit->tenant_id,
'amount' => $deposit->amount,
]);
$clientName = $deposit->display_client_name ?: __('message.today_issue.unknown_client');
$amount = number_format($deposit->amount ?? 0);
Log::info('TodayIssue: Creating deposit issue', [
'deposit_id' => $deposit->id,
'client' => $clientName,
'amount' => $amount,
]);
$this->createIssueWithFcm(
tenantId: $deposit->tenant_id,
sourceType: TodayIssue::SOURCE_DEPOSIT,
sourceId: $deposit->id,
badge: TodayIssue::BADGE_DEPOSIT,
content: __('message.today_issue.deposit_registered', [
'client' => $clientName,
'amount' => $amount,
]),
path: '/accounting/deposit-management',
needsApproval: false,
expiresAt: Carbon::now()->addDays(7)
);
}
/**
* 입금 삭제 시 이슈 삭제
*/
public function handleDepositDeleted(Deposit $deposit): void
{
TodayIssue::removeBySource($deposit->tenant_id, TodayIssue::SOURCE_DEPOSIT, $deposit->id);
}
/**
* 출금 등록 이슈 생성
*/
public function handleWithdrawalCreated(Withdrawal $withdrawal): void
{
Log::info('TodayIssue: Withdrawal created detected', [
'withdrawal_id' => $withdrawal->id,
'tenant_id' => $withdrawal->tenant_id,
'amount' => $withdrawal->amount,
]);
$clientName = $withdrawal->display_client_name ?: $withdrawal->merchant_name ?: __('message.today_issue.unknown_client');
$amount = number_format($withdrawal->amount ?? 0);
Log::info('TodayIssue: Creating withdrawal issue', [
'withdrawal_id' => $withdrawal->id,
'client' => $clientName,
'amount' => $amount,
]);
$this->createIssueWithFcm(
tenantId: $withdrawal->tenant_id,
sourceType: TodayIssue::SOURCE_WITHDRAWAL,
sourceId: $withdrawal->id,
badge: TodayIssue::BADGE_WITHDRAWAL,
content: __('message.today_issue.withdrawal_registered', [
'client' => $clientName,
'amount' => $amount,
]),
path: '/accounting/withdrawal-management',
needsApproval: false,
expiresAt: Carbon::now()->addDays(7)
);
}
/**
* 출금 삭제 시 이슈 삭제
*/
public function handleWithdrawalDeleted(Withdrawal $withdrawal): void
{
TodayIssue::removeBySource($withdrawal->tenant_id, TodayIssue::SOURCE_WITHDRAWAL, $withdrawal->id);
}
/**
* 세금 신고 이슈 업데이트 (스케줄러에서 호출)
* 이 메서드는 일일 스케줄러에서 호출하여 세금 신고 이슈를 업데이트합니다.