fix: [stat] 출하 집계 shipping_cost 컬럼 참조 오류 수정

- shipments.shipping_cost 컬럼이 3/18 배차 분리 시 삭제되었으나 집계 코드 미수정
- shipment_vehicle_dispatches.options->total_amount JOIN으로 변경
This commit is contained in:
2026-03-19 20:19:05 +09:00
parent 0680564164
commit 6952ae9667

View File

@@ -61,16 +61,19 @@ public function aggregateDaily(int $tenantId, Carbon $date): int
->distinct('client_id')
->count('client_id');
// 출하 집계 (shipments)
// 출하 집계 (shipments + vehicle_dispatches 운송비)
$shipmentStats = DB::connection('mysql')
->table('shipments')
->where('tenant_id', $tenantId)
->where('scheduled_date', $dateStr)
->where('status', 'completed')
->whereNull('deleted_at')
->table('shipments as s')
->leftJoin('shipment_vehicle_dispatches as d', function ($join) {
$join->on('d.shipment_id', '=', 's.id')->whereNull('d.deleted_at');
})
->where('s.tenant_id', $tenantId)
->where('s.scheduled_date', $dateStr)
->where('s.status', 'completed')
->whereNull('s.deleted_at')
->selectRaw('
COUNT(*) as shipment_count,
COALESCE(SUM(shipping_cost), 0) as shipment_amount
COUNT(DISTINCT s.id) as shipment_count,
COALESCE(SUM(CAST(JSON_UNQUOTE(JSON_EXTRACT(d.options, "$.total_amount")) AS DECIMAL(12,0))), 0) as shipment_amount
')
->first();