Files
sam-api/app/Services/Stats/QuoteStatService.php
권혁성 bd500a87bd feat: 품질관리·대시보드·결재 양식 개선
- 품질관리 수주선택 필터링 + 검사 상태 자동 재계산
- 제품검사 요청서 Document(EAV) 자동생성 및 동기화
- 현황판 결재 카드 approvalOnly 스코프 + sub_label 추가
- 캘린더 어음 만기일 일정 연동
- QuoteStatService codebridge DB 커넥션 연결
- 테넌트 부트스트랩 기본 결재 양식 자동 시딩
2026-03-10 11:29:56 +09:00

73 lines
2.8 KiB
PHP

<?php
namespace App\Services\Stats;
use App\Models\Stats\Daily\StatQuotePipelineDaily;
use Carbon\Carbon;
use Illuminate\Support\Facades\DB;
class QuoteStatService implements StatDomainServiceInterface
{
public function aggregateDaily(int $tenantId, Carbon $date): int
{
$dateStr = $date->format('Y-m-d');
// 견적 (quotes)
$quoteStats = DB::connection('mysql')
->table('quotes')
->where('tenant_id', $tenantId)
->where('registration_date', $dateStr)
->whereNull('deleted_at')
->selectRaw("
COUNT(*) as created_count,
COALESCE(SUM(total_amount), 0) as total_amount,
SUM(CASE WHEN status = 'approved' THEN 1 ELSE 0 END) as approved_count,
SUM(CASE WHEN status = 'rejected' THEN 1 ELSE 0 END) as rejected_count,
SUM(CASE WHEN order_id IS NOT NULL THEN 1 ELSE 0 END) as conversion_count
")
->first();
$createdCount = $quoteStats->created_count ?? 0;
$conversionCount = $quoteStats->conversion_count ?? 0;
$conversionRate = $createdCount > 0 ? ($conversionCount / $createdCount) * 100 : 0;
// 입찰 (biddings)
$biddingStats = DB::connection('mysql')
->table('biddings')
->where('tenant_id', $tenantId)
->where('bidding_date', $dateStr)
->whereNull('deleted_at')
->selectRaw("
COUNT(*) as cnt,
SUM(CASE WHEN status = 'won' THEN 1 ELSE 0 END) as won_count,
COALESCE(SUM(bidding_amount), 0) as total_amount
")
->first();
// sales_prospect_consultations, sales_prospects는 codebridge DB에 이관되었고
// tenant_id가 없어 테넌트별 집계 불가 → 제외
StatQuotePipelineDaily::updateOrCreate(
['tenant_id' => $tenantId, 'stat_date' => $dateStr],
[
'quote_created_count' => $createdCount,
'quote_amount' => $quoteStats->total_amount ?? 0,
'quote_approved_count' => $quoteStats->approved_count ?? 0,
'quote_rejected_count' => $quoteStats->rejected_count ?? 0,
'quote_conversion_count' => $conversionCount,
'quote_conversion_rate' => $conversionRate,
'bidding_count' => $biddingStats->cnt ?? 0,
'bidding_won_count' => $biddingStats->won_count ?? 0,
'bidding_amount' => $biddingStats->total_amount ?? 0,
]
);
return 1;
}
public function aggregateMonthly(int $tenantId, int $year, int $month): int
{
// 견적 도메인은 일간 테이블만 운영 (월간은 Phase 4에서 필요시 추가)
return 0;
}
}