diff --git a/app/Http/Controllers/Admin/StatisticsController.php b/app/Http/Controllers/Admin/StatisticsController.php index 964c459..83c0f03 100755 --- a/app/Http/Controllers/Admin/StatisticsController.php +++ b/app/Http/Controllers/Admin/StatisticsController.php @@ -142,7 +142,10 @@ class StatisticsController extends CommonController ->whereHas("order", function ($query) use ($project_id) { $query->where("project_id", $project_id); })->sum("money"); - $this_month_balances = Balance::whereRaw("UNIX_TIMESTAMP(`created_at`) >= " . $start_timestamp . " and UNIX_TIMESTAMP(`created_at`) < " . $end_timestamp)->get(); + $this_month_balances = Balance::whereRaw("UNIX_TIMESTAMP(`created_at`) >= " . $start_timestamp . " and UNIX_TIMESTAMP(`created_at`) < " . $end_timestamp) + ->whereHas("order", function ($query) use ($project_id) { + $query->where("project_id", $project_id); + })->get(); return view($this->urlPrefix . "/overview", compact("project_id", "month", "project", "prev_month_balance", "this_month_balance", "this_month_balances")); } @@ -199,8 +202,20 @@ class StatisticsController extends CommonController $month = request()->month ?? date("Y-m"); $months = $this->_getMonths(); - $recharges = Recharge::with(["manager", "order", "patient"])->withCount("refunds")->whereNotNull("paid_at")->whereRaw("DATE_FORMAT(`paid_at`,'%Y-%m') = '{$month}'")->get(); - $refunds = Refund::whereNotNull("paid_at")->whereRaw("DATE_FORMAT(`paid_at`,'%Y-%m') = '{$month}'")->get(); + $recharges = Recharge::with(["manager", "order", "patient"]) + ->withCount("refunds") + ->whereNotNull("paid_at") + ->whereRaw("DATE_FORMAT(`paid_at`,'%Y-%m') = '{$month}'") + ->whereHas("order", function ($query) use ($project_id) { + $query->where("project_id", $project_id); + }) + ->get(); + $refunds = Refund::whereNotNull("paid_at") + ->whereRaw("DATE_FORMAT(`paid_at`,'%Y-%m') = '{$month}'") + ->whereHas("order", function ($query) use ($project_id) { + $query->where("project_id", $project_id); + }) + ->get(); return view($this->bladePath . ".finance", compact("recharges", "refunds", "projects", "project_id", "months", "month")); } diff --git a/app/Models/OrderItems.php b/app/Models/OrderItems.php index a8a27b9..d9aa41e 100755 --- a/app/Models/OrderItems.php +++ b/app/Models/OrderItems.php @@ -58,22 +58,22 @@ class OrderItems extends SoftDeletesModel public function bed() { - return $this->belongsTo(Bed::class); + return $this->belongsTo(Bed::class)->withTrashed(); } public function room() { - return $this->hasOneThrough(Room::class, Bed::class, "id", "id", "bed_id", "room_id"); + return $this->hasOneThrough(Room::class, Bed::class, "id", "id", "bed_id", "room_id")->withTrashed(); } public function building() { - return $this->hasOneThrough(Building::class, Bed::class, "id", "id", "bed_id", "building_id"); + return $this->hasOneThrough(Building::class, Bed::class, "id", "id", "bed_id", "building_id")->withTrashed(); } public function area() { - return $this->hasOneThrough(Area::class, Bed::class, "id", "id", "bed_id", "area_id"); + return $this->hasOneThrough(Area::class, Bed::class, "id", "id", "bed_id", "area_id")->withTrashed(); } public function paramedic() diff --git a/resources/views/admin/statistics/salary.blade.php b/resources/views/admin/statistics/salary.blade.php index 8d693d5..c304918 100755 --- a/resources/views/admin/statistics/salary.blade.php +++ b/resources/views/admin/statistics/salary.blade.php @@ -105,7 +105,7 @@