From 6952ae966792863dd360b29f075dabe7635a90e0 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=EA=B6=8C=ED=98=81=EC=84=B1?= Date: Thu, 19 Mar 2026 20:19:05 +0900 Subject: [PATCH] =?UTF-8?q?fix:=20[stat]=20=EC=B6=9C=ED=95=98=20=EC=A7=91?= =?UTF-8?q?=EA=B3=84=20shipping=5Fcost=20=EC=BB=AC=EB=9F=BC=20=EC=B0=B8?= =?UTF-8?q?=EC=A1=B0=20=EC=98=A4=EB=A5=98=20=EC=88=98=EC=A0=95?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit - shipments.shipping_cost 컬럼이 3/18 배차 분리 시 삭제되었으나 집계 코드 미수정 - shipment_vehicle_dispatches.options->total_amount JOIN으로 변경 --- app/Services/Stats/SalesStatService.php | 19 +++++++++++-------- 1 file changed, 11 insertions(+), 8 deletions(-) diff --git a/app/Services/Stats/SalesStatService.php b/app/Services/Stats/SalesStatService.php index e3654a11..53743f5b 100644 --- a/app/Services/Stats/SalesStatService.php +++ b/app/Services/Stats/SalesStatService.php @@ -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();