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(); } }