Commit 14ddd029 authored by Julien Ait azzouzene's avatar Julien Ait azzouzene
Browse files
parents 53e2ad80 060ea8df
Loading
Loading
Loading
Loading
+34 −0
Original line number Diff line number Diff line
<?php

namespace App\Http\Controllers;

use Illuminate\Http\Request;
use App\Models\DivingSession;
use App\Models\DivingLocation;
use App\Models\Boat;
use App\Models\Prerogative;
use App\Models\User;

class DiveCreation extends Controller
{
    public static function index(Request $request)
    {
        $pre = DiveSessionCreation::add($request);

        error_log($pre);

        if(is_string($pre))
        {
            return view('create_dive', ['locations' => DivingLocation::all(),  'boats' => Boat::all(), 'levels' => Prerogative::all()->skip(3), 'users' => User::all(), 'error' => $pre, 'previousDives' => session()->get('previousDives')]);
        }
        else
        {
            $previousDives = session('previousDives', []);
            $previousDives[] = $pre;

            session(['previousDives' => $previousDives]);
            return view('create_dive',  ['locations' => DivingLocation::all(),  'boats' => Boat::all(), 'levels' => Prerogative::all()->skip(3), 'users' => User::all(), 'precedent' => $pre, 'previousDives' => $previousDives]);
        }

    }
}
+23 −0
Original line number Diff line number Diff line
<?php

namespace App\Http\Controllers;

use Illuminate\Http\Request;

class DiveDeletion extends Controller
{

    public static function delete($id)
    {
        DiveSessionDelete::update($id);
        $previousDives = session('previousDives', []);

        $indexToRemove = array_search($id, array_column($previousDives, 'DS_CODE'));

        if ($indexToRemove !== false) {
            unset($previousDives[$indexToRemove]);
            $previousDives = array_values($previousDives);
            session(['previousDives' => $previousDives]);
        }
    }
}
+0 −2
Original line number Diff line number Diff line
@@ -17,8 +17,6 @@ public static function update($request, $id)
        $dv->BO_ID = $request->boat;
        $dv->US_ID_CAR_SECURE = $request->security;
        $dv->US_ID_CAR_DIRECT = $request->manager;
        $dv->DS_DATE = $request->day;
        $dv->CAR_SCHEDULE = $request->hour;
        $dv->DS_MAX_DEPTH = $request->maxDepth;
        $dv->DS_ACTIVE = 1;
        $dv->DS_MAX_DIVERS = $request->max;
+23 −0
Original line number Diff line number Diff line
@@ -20,4 +20,27 @@ function index(): View
        $user = session()->get('user');
        return view('dives', ['dives' => $dives, 'userPre' => Prerogative::find($user->PRE_CODE)]);
    }

    function show($id) {
        $divingSession = DivingSession::join('CAR_DIVING_LOCATION', 'CAR_DIVING_SESSION.DL_ID', '=', 'CAR_DIVING_LOCATION.DL_ID')
            ->join('CAR_BOAT', 'CAR_DIVING_SESSION.BO_ID', '=', 'CAR_BOAT.BO_ID')
            ->where('DS_CODE', '=', $id)
            ->first();
        if($divingSession === null) return redirect()->route('homepage');
        $creator = User::find($divingSession->US_ID);
        $security = User::find($divingSession->US_ID_CAR_SECURE);
        $director = User::find($divingSession->US_ID_CAR_DIRECT);
        $divingSession->DS_DATE = strftime('%d/%m/%Y', strtotime($divingSession->DS_DATE));
        return view('dive_infos_palanque', ['dive' => $divingSession, 'divers' => $divingSession->getParticipants(), 'creator' => $creator, 'security' => $security, 'director' => $director]);
    }

    function showManagementList() {
        $userID = session('user')->US_ID;
        $dives = DivingSession::select('DS_CODE', 'DS_ACTIVE', 'CAR_DIVING_SESSION.DL_ID', 'DS_DATE', 'DL_DEPTH', 'CAR_SCHEDULE', 'DL_NAME', 'DS_MAX_DEPTH')
            ->join('CAR_DIVING_LOCATION', 'CAR_DIVING_SESSION.DL_ID', '=', 'CAR_DIVING_LOCATION.DL_ID')
            ->where('DS_ACTIVE', '=', 1, 'and', 'DS_DATE', '>=', date('Y-m-d'), 'and', 'US_ID_CAR_DIRECT', '=', $userID)
            ->orderBy('DS_DATE', 'asc')
            ->get();
        return view('dives_list_management', ['dives' => $dives]);
    }
}
+35 −35
Original line number Diff line number Diff line
@@ -19,24 +19,24 @@ public function index(): View
            $userId = NULL;
        }

        $dateDives = DivingNumberModel::join('car_registration', 'car_user.us_id', '=', 'car_registration.us_id')
        ->join('car_diving_session','car_registration.ds_code','=','car_diving_session.ds_code')
        ->join('car_diving_location','car_diving_session.dl_id','=','car_diving_location.dl_id')
        ->join('car_role_attribution','car_user.us_id','=','car_role_attribution.Us_id')
        ->join('car_role','car_role_attribution.rol_code','=','car_role.rol_code')
        $dateDives = DivingNumberModel::join('CAR_REGISTRATION', 'CAR_USER.us_id', '=', 'CAR_REGISTRATION.us_id')
        ->join('CAR_DIVING_SESSION','CAR_REGISTRATION.ds_code','=','CAR_DIVING_SESSION.ds_code')
        ->join('CAR_DIVING_LOCATION','CAR_DIVING_SESSION.dl_id','=','CAR_DIVING_LOCATION.dl_id')
        ->join('CAR_ROLE_ATTRIBUTION','CAR_USER.us_id','=','CAR_ROLE_ATTRIBUTION.Us_id')
        ->join('CAR_ROLE','CAR_ROLE_ATTRIBUTION.rol_code','=','CAR_ROLE.rol_code')

        ->where('car_user.US_ID',$userId)
        ->where('CAR_USER.US_ID',$userId)
        ->get();


        $usersCount = DivingNumberModel::join('car_registration', 'car_user.us_id', '=', 'car_registration.us_id')
            ->join('car_diving_group', function ($dg) {
                $dg->on('car_registration.ds_code', '=', 'car_diving_group.ds_code')
                    ->on('car_registration.dg_number', '=', 'car_diving_group.dg_number');
        $usersCount = DivingNumberModel::join('CAR_REGISTRATION', 'CAR_USER.us_id', '=', 'CAR_REGISTRATION.us_id')
            ->join('CAR_DIVING_GROUP', function ($dg) {
                $dg->on('CAR_REGISTRATION.ds_code', '=', 'CAR_DIVING_GROUP.ds_code')
                    ->on('CAR_REGISTRATION.dg_number', '=', 'CAR_DIVING_GROUP.dg_number');
            })
            ->join('car_diving_session','car_registration.ds_code','=','car_diving_session.ds_code')
            ->where('car_diving_session.ds_date','>=',date("Y").'-00-00')
            ->where('car_user.US_ID', $userId)
            ->join('CAR_DIVING_SESSION','CAR_REGISTRATION.ds_code','=','CAR_DIVING_SESSION.ds_code')
            ->where('CAR_DIVING_SESSION.ds_date','>=',date("Y").'-00-00')
            ->where('CAR_USER.US_ID', $userId)
            ->orderBy('ds_date','desc')
            ->count();
        $usersCount = 99 - $usersCount ;
@@ -57,13 +57,13 @@ public function allIndex(Request $request): View
            return DivingNumberController::before($request['beforethe']);
        }

        $usersDatas = DivingNumberModel::selectRaw('COUNT(*) as aggregate, car_user.US_FIRST_NAME, car_user.US_NAME')
    ->join('car_registration', 'car_user.us_id', '=', 'car_registration.us_id')
    ->join('car_diving_group', function ($join) {
        $join->on('car_registration.ds_code', '=', 'car_diving_group.ds_code')
            ->on('car_registration.dg_number', '=', 'car_diving_group.dg_number');
        $usersDatas = DivingNumberModel::selectRaw('COUNT(*) as aggregate, CAR_USER.US_FIRST_NAME, CAR_USER.US_NAME')
    ->join('CAR_REGISTRATION', 'CAR_USER.us_id', '=', 'CAR_REGISTRATION.us_id')
    ->join('CAR_DIVING_GROUP', function ($join) {
        $join->on('CAR_REGISTRATION.ds_code', '=', 'CAR_DIVING_GROUP.ds_code')
            ->on('CAR_REGISTRATION.dg_number', '=', 'CAR_DIVING_GROUP.dg_number');
    })
    ->groupBy('car_user.us_id', 'car_user.US_NAME', 'car_user.US_FIRST_NAME')
    ->groupBy('CAR_USER.us_id', 'CAR_USER.US_NAME', 'CAR_USER.US_FIRST_NAME')
    ->get();

        return view('alldiversactivities', ['datas' => $usersDatas]);
@@ -74,12 +74,12 @@ public function afterAndBefore(string $after, string $before): View
    {


        $usersDatas = DivingNumberModel::selectRaw('COUNT(*) as aggregate, car_user.US_FIRST_NAME, car_user.US_NAME')
        ->join('car_registration', 'car_user.us_id', '=', 'car_registration.us_id')
        ->join('car_diving_session', 'car_registration.DS_CODE', '=', 'car_diving_session.DS_CODE')
        ->where('car_diving_session.DS_DATE', '>=', $after)
                ->where('car_diving_session.DS_DATE', '<=', $before)
        ->groupBy('car_user.us_id', 'car_user.US_NAME', 'car_user.US_FIRST_NAME')
        $usersDatas = DivingNumberModel::selectRaw('COUNT(*) as aggregate, CAR_USER.US_FIRST_NAME, CAR_USER.US_NAME')
        ->join('CAR_REGISTRATION', 'CAR_USER.us_id', '=', 'CAR_REGISTRATION.us_id')
        ->join('CAR_DIVING_SESSION', 'CAR_REGISTRATION.DS_CODE', '=', 'CAR_DIVING_SESSION.DS_CODE')
        ->where('CAR_DIVING_SESSION.DS_DATE', '>=', $after)
                ->where('CAR_DIVING_SESSION.DS_DATE', '<=', $before)
        ->groupBy('CAR_USER.us_id', 'CAR_USER.US_NAME', 'CAR_USER.US_FIRST_NAME')
        ->get();


@@ -92,11 +92,11 @@ public function after(string $after): View
    {


        $usersDatas = DivingNumberModel::selectRaw('COUNT(*) as aggregate, car_user.US_FIRST_NAME, car_user.US_NAME')
        ->join('car_registration', 'car_user.us_id', '=', 'car_registration.us_id')
        ->join('car_diving_session', 'car_registration.DS_CODE', '=', 'car_diving_session.DS_CODE')
        ->where('car_diving_session.DS_DATE', '>=', $after)
        ->groupBy('car_user.us_id', 'car_user.US_NAME', 'car_user.US_FIRST_NAME')
        $usersDatas = DivingNumberModel::selectRaw('COUNT(*) as aggregate, CAR_USER.US_FIRST_NAME, CAR_USER.US_NAME')
        ->join('CAR_REGISTRATION', 'CAR_USER.us_id', '=', 'CAR_REGISTRATION.us_id')
        ->join('CAR_DIVING_SESSION', 'CAR_REGISTRATION.DS_CODE', '=', 'CAR_DIVING_SESSION.DS_CODE')
        ->where('CAR_DIVING_SESSION.DS_DATE', '>=', $after)
        ->groupBy('CAR_USER.us_id', 'CAR_USER.US_NAME', 'CAR_USER.US_FIRST_NAME')
        ->get();


@@ -109,11 +109,11 @@ public function before(string $before): View
    {


        $usersDatas = DivingNumberModel::selectRaw('COUNT(*) as aggregate, car_user.US_FIRST_NAME, car_user.US_NAME')
        ->join('car_registration', 'car_user.us_id', '=', 'car_registration.us_id')
        ->join('car_diving_session', 'car_registration.DS_CODE', '=', 'car_diving_session.DS_CODE')
        ->where('car_diving_session.DS_DATE', '<=', $before)
        ->groupBy('car_user.us_id', 'car_user.US_NAME', 'car_user.US_FIRST_NAME')
        $usersDatas = DivingNumberModel::selectRaw('COUNT(*) as aggregate, CAR_USER.US_FIRST_NAME, CAR_USER.US_NAME')
        ->join('CAR_REGISTRATION', 'CAR_USER.us_id', '=', 'CAR_REGISTRATION.us_id')
        ->join('CAR_DIVING_SESSION', 'CAR_REGISTRATION.DS_CODE', '=', 'CAR_DIVING_SESSION.DS_CODE')
        ->where('CAR_DIVING_SESSION.DS_DATE', '<=', $before)
        ->groupBy('CAR_USER.us_id', 'CAR_USER.US_NAME', 'CAR_USER.US_FIRST_NAME')
        ->get();


Loading