From c74e2927ada9f1e646d8e335fb57ffcbd934c577 Mon Sep 17 00:00:00 2001 From: omair saleh Date: Sat, 2 Oct 2021 15:15:27 +0800 Subject: [PATCH] customer report --- app/Http/Controllers/Reports/MonthlyReportController.php | 6 ++++-- 1 file changed, 4 insertions(+), 2 deletions(-) diff --git a/app/Http/Controllers/Reports/MonthlyReportController.php b/app/Http/Controllers/Reports/MonthlyReportController.php index abc55895..eb158c62 100644 --- a/app/Http/Controllers/Reports/MonthlyReportController.php +++ b/app/Http/Controllers/Reports/MonthlyReportController.php @@ -6,13 +6,15 @@ use App\Classes\ValueObjects\Constants\HttpStatus; use App\Classes\ValueObjects\Response\ApiResponseObject; use App\Models\Container; use App\Models\Order; +use Carbon\Carbon; use Illuminate\Http\JsonResponse; use Illuminate\Http\Request; class MonthlyReportController { public function report(Request $request): JsonResponse { - $containers = Container::whereMonth('loading_date', '=', '09')->whereYear('loading_date', '=', '2021')->orderBy('loading_date')->get(); + $month = Carbon::now()->subMonth(); + $containers = Container::whereMonth('loading_date', $month->format('m'))->whereYear('loading_date', '=', '2021')->orderBy('loading_date')->get(); $total = 0; $customers = collect(); @@ -56,7 +58,7 @@ class MonthlyReportController 'packages' => $customers->sum(function($customer){ return $customer['packages']; }), - 'total_orders' => Order::whereMonth('created_at', 9)->whereHas('packingLists')->count() + 'total_orders' => Order::whereMonth('created_at', $month->format('m'))->count() ]]))->handler(); } }