|
|
|
|
@ -5,6 +5,7 @@ namespace App\Http\Controllers\Manager;
|
|
|
|
|
use App\Models\Area;
|
|
|
|
|
use App\Models\Bed;
|
|
|
|
|
use Illuminate\Http\Request;
|
|
|
|
|
use Illuminate\Support\Facades\DB;
|
|
|
|
|
|
|
|
|
|
class StatisticsController extends CommonController
|
|
|
|
|
{
|
|
|
|
|
@ -25,16 +26,26 @@ class StatisticsController extends CommonController
|
|
|
|
|
|
|
|
|
|
public function beds(Request $request)
|
|
|
|
|
{
|
|
|
|
|
$areas = Area::with(["beds" => function ($query) use ($request) {
|
|
|
|
|
if ($request->has_ongoing_order) {
|
|
|
|
|
$query->has("onGoingOrder");
|
|
|
|
|
}
|
|
|
|
|
$query->with(["onGoingOrder" => function ($query) {
|
|
|
|
|
$query->with(["paramedic" => function ($query) {
|
|
|
|
|
$query->select("id", "name");
|
|
|
|
|
}])->select("id", "bed_id", "paramedic_id", "status");
|
|
|
|
|
}]);
|
|
|
|
|
}])->with("building")->where("project_id", $request->project_id)->orderBy("building_id")->orderBy("myindex")->get();
|
|
|
|
|
DB::enableQueryLog();
|
|
|
|
|
$areas = Area::with([
|
|
|
|
|
"beds" => function ($query) use ($request) {
|
|
|
|
|
if ($request->has_ongoing_order) {
|
|
|
|
|
$query->has("onGoingOrder");
|
|
|
|
|
}
|
|
|
|
|
$query->with(["onGoingOrder" => function ($query) {
|
|
|
|
|
$query->leftJoin("paramedic", "orders.paramedic_id", "=", "paramedic.id")
|
|
|
|
|
->select("orders.id", "orders.bed_id", "orders.paramedic_id", "orders.status", "paramedic.name as paramedic_name");
|
|
|
|
|
}])->select("bed.id", "bed.name", "bed.room_id", "bed.area_id")
|
|
|
|
|
->leftJoin("room", "bed.room_id", "=", "room.id")
|
|
|
|
|
->addSelect("room.name as room_name");
|
|
|
|
|
}])
|
|
|
|
|
->whereRaw("`area`.`project_id` = '{$request->project_id}'")
|
|
|
|
|
->orderBy("building.myindex")
|
|
|
|
|
->orderBy("area.myindex")
|
|
|
|
|
->select("area.id", "area.name", "area.building_id", "area.project_id")
|
|
|
|
|
->leftJoin("building", "area.building_id", "=", "building.id")
|
|
|
|
|
->addSelect("building.name as building_name")
|
|
|
|
|
->get();
|
|
|
|
|
|
|
|
|
|
return response()->json($areas->toArray());
|
|
|
|
|
}
|
|
|
|
|
|