From 3db065ae5333b0412dcfb7f174300710efc749ec Mon Sep 17 00:00:00 2001 From: ygbanzato Date: Sat, 3 Jun 2023 19:01:17 +0100 Subject: [PATCH] updating best practices in project models and controllers, and linking tables. - Creation of controller : CreateProject, for creation of the company works. - Controller : ProjectDatacontroller to manage data of the equipments and installations in general. --- .../Controllers/CreateProjectController.php | 313 +++++++- .../CustomRegistrationController.php | 4 +- .../Controllers/EquipamentsController.php | 17 - .../Controllers/Pending_UserController.php | 8 +- .../Controllers/ProjectoDatacontroller.php | 38 + app/Http/Controllers/userController.php | 12 +- app/Http/Middleware/CheckSuperAdmin.php | 2 +- app/Http/Middleware/VerifyCsrfToken.php | 6 +- ...bits_equipment.php => AmbitsEquipment.php} | 7 +- .../{installation.php => CompanyProject.php} | 5 +- app/Models/Equipment.php | 41 + app/Models/EquipmentType.php | 23 + app/Models/GeneralAttributesEquipment.php | 20 + ...mpany_project.php => PendingEquipment.php} | 6 +- .../{pending_user.php => PendingUser.php} | 6 +- app/Models/Plant.php | 29 + .../SpecificAttributesEquipmentType.php | 31 + app/Models/TypeUser.php | 6 +- app/Models/Unit.php | 19 + app/Models/User.php | 18 +- app/Models/equipament.php | 16 - app/Models/equipament_Type.php | 11 - app/Models/factorie.php | 11 - .../specific_Attributes_Equipament_Type.php | 11 - composer.json | 1 + composer.lock | 468 ++++++++++- .../Admin/CrudUsers/listCompany.blade.php | 87 +++ .../views/Admin/CrudUsers/listUsers.blade.php | 143 ++-- .../DataManagement/manageassets.blade.php | 724 ++++++++++++++++++ .../DataManagement/showEquipament.blade.php | 61 ++ .../views/Templates/templateAdmin.blade.php | 41 +- resources/views/createProject.blade.php | 194 ----- resources/views/createProjectExcel.blade.php | 179 +++++ .../projectsClients/createProject.blade.php | 566 ++++++++------ resources/views/test.blade.php | 557 ++++++++++++++ resources/views/test2.blade.php | 164 ++++ routes/web.php | 273 ++++--- 37 files changed, 3354 insertions(+), 764 deletions(-) delete mode 100644 app/Http/Controllers/EquipamentsController.php create mode 100644 app/Http/Controllers/ProjectoDatacontroller.php rename app/Models/{ambits_equipment.php => AmbitsEquipment.php} (58%) rename app/Models/{installation.php => CompanyProject.php} (58%) create mode 100644 app/Models/Equipment.php create mode 100644 app/Models/EquipmentType.php create mode 100644 app/Models/GeneralAttributesEquipment.php rename app/Models/{company_project.php => PendingEquipment.php} (57%) rename app/Models/{pending_user.php => PendingUser.php} (83%) create mode 100644 app/Models/Plant.php create mode 100644 app/Models/SpecificAttributesEquipmentType.php create mode 100644 app/Models/Unit.php delete mode 100644 app/Models/equipament.php delete mode 100644 app/Models/equipament_Type.php delete mode 100644 app/Models/factorie.php delete mode 100644 app/Models/specific_Attributes_Equipament_Type.php create mode 100644 resources/views/Admin/CrudUsers/listCompany.blade.php create mode 100644 resources/views/Admin/DataManagement/manageassets.blade.php create mode 100644 resources/views/Admin/DataManagement/showEquipament.blade.php delete mode 100644 resources/views/createProject.blade.php create mode 100644 resources/views/createProjectExcel.blade.php create mode 100644 resources/views/test.blade.php create mode 100644 resources/views/test2.blade.php diff --git a/app/Http/Controllers/CreateProjectController.php b/app/Http/Controllers/CreateProjectController.php index 1edea80b..0afe3ec1 100644 --- a/app/Http/Controllers/CreateProjectController.php +++ b/app/Http/Controllers/CreateProjectController.php @@ -1,88 +1,323 @@ get(); - return view ('projectsClients/createProject', ['companies' => $companies]); + + // Nao vinculado ao project ainda + + public function index() + { + // $results = DB::table('equipaments') + // ->join('specific_attributes_equipament_types', 'equipaments.equipment_ID', '=', 'specific_attributes_equipament_types.tb_equipament_id') + // ->join('general_attributes_equipaments', 'specific_attributes_equipament_types.specific_Attributes_Equipment_Type_ID', '=', 'general_attributes_equipaments.general_Attributes_Equipment_ID') + // ->select('equipaments.tag', 'general_attributes_equipaments.description', 'specific_attributes_equipament_types.value') + // ->get(); + + $results = DB::table('equipments') + ->join('specific_attributes_equipament_types', 'equipments.equipment_id', '=', 'specific_attributes_equipament_types.equipment_id') + ->join('general_attributes_equipaments', 'specific_attributes_equipament_types.specific_attributes_equipment_type_id', '=', 'general_attributes_equipaments.general_attributes_equipment_id') + ->select('equipments.equipment_tag', 'general_attributes_equipaments.general_attributes_equipment_description', 'specific_attributes_equipament_types.specific_attributes_value') + ->get(); + + + dd($results); + + $groupedEquipments = []; + + foreach ($results as $result) { + if (!isset($groupedEquipments[$result->tag])) { + $groupedEquipments[$result->tag] = []; + } + + $groupedEquipments[$result->tag][] = [ + 'description' => $result->description, + 'value' => $result->value + ]; + } + + $equipments = DB::table('equipments')->get(); + + foreach ($equipments as $equipment) { + if (isset($groupedEquipments[$equipment->tag])) { + $equipment->specific_attributes = $groupedEquipments[$equipment->tag]; + } + } + $allPossibleAttributes = GeneralAttributesEquipment::all()->pluck('description')->toArray(); + + return view('test2', ['equipments' => $equipments, 'allAttributes' => $allPossibleAttributes]); + // Retorne a view com os dados + // return view('test', ['equipments' => $equipments]); } - public function createProject(Request $request){ - // dd($request); - - // Validação... - $installationId = $request->input('installation_id'); + public function listCompanies() + { + $companies = User::where('type_users', 3)->get(); + return view('projectsClients/createProject', ['companies' => $companies]); + // return view('projectsClients/createProject', ['companies' => $companies]); + } + + + public function createProject(Request $request) + { + + // Validação... + $installationId = $request->input('installation_id'); if ($installationId == 'new_install') { // Criar uma nova instalação... - $newInstallation = new Installation; + $newInstallation = new Unit; $newInstallation->installation_name = $request->input('new_company_name'); $newInstallation->address = $request->input('new_company_address'); $newInstallation->user_id = $request->input('user_id'); - + $newInstallation->save(); - + // Use o id da nova instalação. $installationId = $newInstallation->id; // dd($installationId); - } + } - $project = new company_project; + $project = new CompanyProject; $project->description_project = $request->input('description_project'); $project->n_project_ispt = $request->input('n_project_ispt'); $project->responsible_project_ispt = $request->input('responsible_project_ispt'); $project->responsible_project_company = $request->input('responsible_project_company'); $project->date_started = $request->input('date_started'); - - $project->installation_ID = $installationId; - + + $project->installation_id = $installationId; + $project->save(); - return redirect()->route('testExcel')->with('success', 'Dados guardados com sucesso'); + return redirect()->route('createProject')->with('success', 'Dados guardados com sucesso'); } - public function storeProject(Request $request) -{ - if ($request->input('company_id') == 'new') { - $company = new company_project; // Substitua "Company" pelo nome do seu modelo de empresas - $company->name = $request->input('new_company_name'); - $company->save(); + { + if ($request->input('company_id') == 'new') { + $company = new CompanyProject; // Substitua "Company" pelo nome do seu modelo de empresas + $company->name = $request->input('new_company_name'); + $company->save(); - $company_id = $company->id; - } else { - $company_id = $request->input('company_id'); + $company_id = $company->id; + } else { + $company_id = $request->input('company_id'); + } + + // Agora, você pode usar $company_id ao criar o projeto } - // Agora, você pode usar $company_id ao criar o projeto -} - - public function getByUserNif (Request $request){ + public function getByUserNif(Request $request) + { // dd(Installation::where('user_id', $request->input('user_id'))->get()); $user_id = $request->input('user_id'); //Check - $installations = Installation::where('user_id', $user_id)->get(); + $installations = Unit::where('user_id', $user_id)->get(); return response()->json($installations); } - public function createEquipamentProject (Request $request){ - - dd($request->input('data')); - // $data = $request->input('data'); - } - + // public function createEquipamentProject(Request $request) + // { + // $file = $request->file('documento'); + + // // Certifique-se de que um arquivo foi enviado + // if ($file) { + // // Carregue o arquivo Excel + // $spreadsheet = IOFactory::load($file->path()); + + // // Obtenha a primeira planilha + // $worksheet = $spreadsheet->getSheet(0); + + // // Transforme os dados da planilha em um array + // $data = $worksheet->toArray(); + + // $nomesColunas = $data[0]; + + // $dadosLinha6 = $data[6]; + + // $juntarArrays = array_combine($nomesColunas, $dadosLinha6); + + // $datas = array_filter($juntarArrays, function ($chave) { + // return !empty($chave); + // }, ARRAY_FILTER_USE_KEY); + + // $equipamentType = equipament_type::where('equipment_type_name', $datas['tipo_equipamento'])->first(); + // $checkFactory = factorie::where('factories_name', $datas['fabrica'])->first(); + + + // $newEquipament = new equipament; + // //Primeiro tem de derificar se a fabrica existe, senao cria uma. + // $newEquipament->factory_id = $checkFactory->factories_id; + // $newEquipament->equipament_type_id = $equipamentType->equipament_type_id; + // $newEquipament->equipment_Description = $datas['equipment_Description']; + // $newEquipament->tag = $datas['tag']; + // $newEquipament->serial_number = $datas['n_serie']; + // $newEquipament->model = $datas['modelo']; + + // $newEquipament->save(); + + + // $receveEquipment_ID = $newEquipament->id; + // $receveEquipament_type_ID = $newEquipament->equipament_type_id; + + + // // Atributos que você quer buscar e inserir + // $attributes = ["dimension", "dn_ent", "p&id", "n_sap", "isolation", "scaffolding", "grua", "interlocks"]; + + // // $attributes = array_slice($data[0], 7); + + // foreach ($attributes as $attribute) { + + // // Buscar o atributo na tabela general_attributes_equipament + // $generalAttribute = general_attributes_equipament::where('description', $attribute)->first(); + + + // // Se o atributo foi encontrado + // if (!is_null($generalAttribute)) { + // // Criar um novo registro em specific_attributes_equipament_Types + // $specificAttribute = new specific_attributes_equipament_type; + + // $specificAttribute->tb_equipament_id = $receveEquipment_ID; + // $specificAttribute->equipament_Type_id = $receveEquipament_type_ID; + // $specificAttribute->specific_attributes_equipment_type_id = $generalAttribute->general_attributes_equipment_id; + // $specificAttribute->value = $datas[$attribute]; + + // $specificAttribute->save(); + // } + // } + // $listValves = equipament::all(); + + // return redirect()->route('testExcel')->with('success', 'Dados guardados com sucesso')->with('listValves', $listValves); + // } + // } + + public function createEquipamentProject(Request $request) + { + $file = $request->file('documento'); + + // Certifique-se de que um arquivo foi enviado + if ($file) { + // Carregue o arquivo Excel + $spreadsheet = IOFactory::load($file->path()); + + // Obtenha a primeira planilha + $worksheet = $spreadsheet->getSheet(0); + + // Transforme os dados da planilha em um array + $data = $worksheet->toArray(); + + $nomesColunas = $data[0]; + + // Atributos que você quer buscar e inserir + $attributes = ["dimension", "dn_ent", "p&id", "n_sap", "isolation", "scaffolding", "grua", "interlocks"]; + + // Comece a partir da sexta linha + for ($i = 6; $i < count($data); $i++) { + $dadosLinha = $data[$i]; + + //Se nao preencher o campo $dadosLinha[0], nao cria um novo equipamento + //Trocar pelos 5 primeiros + if (empty($dadosLinha[0])) { + continue; + } + + $juntarArrays = array_combine($nomesColunas, $dadosLinha); + + $datas = array_filter($juntarArrays, function ($chave) { + return !empty($chave); + }, ARRAY_FILTER_USE_KEY); + + $equipmentType = EquipmentType::where('equipment_type_name', $datas['tipo_equipamento'])->first(); + + $checkFactory = Unit::where('unit_name', $datas['fabrica'])->first(); + + + // Antes de criar o novo equipamento, verifique se já existe um equipamento + // com o mesmo factory_id e tag. + $existingEquipment = Equipment::where('unit_id', $checkFactory->unit_id) + ->where('equipment_tag', $datas['tag']) + ->first(); + + if ($existingEquipment) { + // Se o equipamento existir, crie o novo equipamento na tabela pending_equipaments. + $pendingEquipament = new PendingEquipment; + // Defina os atributos do pendingEquipament conforme necessário. + $pendingEquipament->pending_equipment_unit_id = $checkFactory->unit_id; + $pendingEquipament->pending_equipment_type_id = $equipmentType->equipment_type_id; + $pendingEquipament->pending_equipment_tag = $datas['tag']; + $pendingEquipament->pending_equipment_description = $datas['equipment_Description']; + $pendingEquipament->pending_equipment_serial_number = $datas['n_serie']; + $pendingEquipament->pending_equipment_brand = $datas['modelo']; + + $pendingEquipament->save(); + + // Continue com o próximo loop. + continue; + } + + $newEquipament = new Equipment; + + $newEquipament->unit_id = $checkFactory->unit_id; + $newEquipament->equipment_type_id = $equipmentType->equipment_type_id; + $newEquipament->equipment_Description = $datas['equipment_Description']; + $newEquipament->equipment_tag = $datas['tag']; + $newEquipament->equipment_serial_number = $datas['n_serie']; + $newEquipament->equipment_model = $datas['modelo']; + + $newEquipament->save(); + + $receveEquipment_ID = $newEquipament->equipment_id; + + $receveEquipament_type_ID = $newEquipament->equipment_type_id; + + + foreach ($attributes as $attribute) { + + $generalAttribute = GeneralAttributesEquipment::where('general_attributes_equipment_description', $attribute)->first(); + + + + if (!is_null($generalAttribute)) { + + $specificAttribute = new SpecificAttributesEquipmentType; + + $specificAttribute->equipment_id = $receveEquipment_ID; + $specificAttribute->equipment_type_id = $receveEquipament_type_ID; + $specificAttribute->specific_attributes_equipment_type_id = $generalAttribute->general_attributes_equipment_id; + $specificAttribute->specific_attributes_value = $datas[$attribute]; + + $specificAttribute->save(); + + } + } + } + + $listValves = Equipment::all(); + return redirect()->route('createProject')->with('success', 'Dados guardados com sucesso')->with('listValves', $listValves); + } + + } } diff --git a/app/Http/Controllers/CustomRegistrationController.php b/app/Http/Controllers/CustomRegistrationController.php index b4a5c4f0..2ba13fa2 100644 --- a/app/Http/Controllers/CustomRegistrationController.php +++ b/app/Http/Controllers/CustomRegistrationController.php @@ -15,7 +15,7 @@ use Illuminate\Auth\Events\Verified; use App\Models\User; -use App\Models\pending_user; +use App\Models\PendingUser; use App\Mail\NewUserNotification; use Illuminate\Support\Facades\Mail; @@ -33,7 +33,7 @@ public function store(Request $request): RedirectResponse // // Auth::login($user); - $pendingUser = pending_user::where('pending_email', $user->email)->first(); + $pendingUser = PendingUser::where('pending_email', $user->email)->first(); if ($pendingUser) { $pendingUser->delete(); } diff --git a/app/Http/Controllers/EquipamentsController.php b/app/Http/Controllers/EquipamentsController.php deleted file mode 100644 index c3ac5201..00000000 --- a/app/Http/Controllers/EquipamentsController.php +++ /dev/null @@ -1,17 +0,0 @@ -get('name') . ' ' . $request->get('lastName'); - $pendingUser = new pending_user([ + $pendingUser = new PendingUser([ 'pending_name' => $joinName, 'pending_email' => $request->get('pending_email'), 'pending_phone' => $request->get('pending_phone'), diff --git a/app/Http/Controllers/ProjectoDatacontroller.php b/app/Http/Controllers/ProjectoDatacontroller.php new file mode 100644 index 00000000..1c7accf9 --- /dev/null +++ b/app/Http/Controllers/ProjectoDatacontroller.php @@ -0,0 +1,38 @@ +join('units', 'plants.plant_id', '=', 'units.plant_id') + ->join('users', 'plants.user_id', '=', 'users.user_id') + ->select('plants.*', 'units.unit_name', 'users.user_name as user_name') + ->get(); + + // $equipaments = DB::table('equipaments') + // ->join('factories','equipaments.factory_id', '=', 'factories.factories_id') + // ->join('equipament_types', 'equipaments.equipament_type_id', '=' , 'equipament_types.equipament_type_id') + // ->select('equipaments.*', 'factories.factories_name', 'equipament_types.equipment_type_name') + // ->get(); + + // return view('Admin/DataManagement/manageassets', compact('units','equipaments')); + return view('Admin/DataManagement/manageassets', compact('units')); + } + + public function showUnit($id) + { + + $equipaments = Equipment::where('equipment_id', $id)->firstOrFail(); + return view('Admin/DataManagement/showEquipament', compact('equipaments')); + } +} diff --git a/app/Http/Controllers/userController.php b/app/Http/Controllers/userController.php index 55e5c3fd..1c035208 100644 --- a/app/Http/Controllers/userController.php +++ b/app/Http/Controllers/userController.php @@ -2,6 +2,7 @@ namespace App\Http\Controllers; +use App\Models\TypeUser; use Illuminate\Support\Facades\Hash; use Illuminate\Support\Facades\Auth; @@ -73,9 +74,18 @@ public static function authenticateAndRedirect(Request $request) } + public function ListCompanies() + { + $users = User::with('userType')->where('user_type', '=', 3)->get(); + + return view('Admin.CrudUsers.listCompany', compact('users')); + } + + //Busca Todos os utilizadores Exeto as 'Empresas' public function ListUsers() { - $users = User::all(); + $users = User::with('userType')->where('user_type', '<>', 3)->get(); + return view('Admin.CrudUsers.listUsers', compact('users')); } diff --git a/app/Http/Middleware/CheckSuperAdmin.php b/app/Http/Middleware/CheckSuperAdmin.php index 6ec668cd..c77afe74 100644 --- a/app/Http/Middleware/CheckSuperAdmin.php +++ b/app/Http/Middleware/CheckSuperAdmin.php @@ -15,7 +15,7 @@ class CheckSuperAdmin */ public function handle(Request $request, Closure $next): Response { - if (auth()->user() && auth()->user()->userType->type == 'Super_Administrador') { + if (auth()->user() && auth()->user()->userType->type_user == 'Super_Administrador') { return $next($request); } diff --git a/app/Http/Middleware/VerifyCsrfToken.php b/app/Http/Middleware/VerifyCsrfToken.php index 47390301..8166b168 100644 --- a/app/Http/Middleware/VerifyCsrfToken.php +++ b/app/Http/Middleware/VerifyCsrfToken.php @@ -11,7 +11,7 @@ class VerifyCsrfToken extends Middleware * * @var array */ - protected $except = [ - '/create-equipament-project', - ]; + // protected $except = [ + // '/create-equipament-project', + // ]; } diff --git a/app/Models/ambits_equipment.php b/app/Models/AmbitsEquipment.php similarity index 58% rename from app/Models/ambits_equipment.php rename to app/Models/AmbitsEquipment.php index f2ccc282..5e100ff6 100644 --- a/app/Models/ambits_equipment.php +++ b/app/Models/AmbitsEquipment.php @@ -5,10 +5,15 @@ use Illuminate\Database\Eloquent\Factories\HasFactory; use Illuminate\Database\Eloquent\Model; -class ambits_equipment extends Model +class AmbitsEquipment extends Model { use HasFactory; + protected $table = 'ambits_equipments'; + protected $primaryKey = 'ambits_equipment_id'; + + + public $timestamps = false; } diff --git a/app/Models/installation.php b/app/Models/CompanyProject.php similarity index 58% rename from app/Models/installation.php rename to app/Models/CompanyProject.php index a4d139b8..43d09b60 100644 --- a/app/Models/installation.php +++ b/app/Models/CompanyProject.php @@ -5,9 +5,12 @@ use Illuminate\Database\Eloquent\Factories\HasFactory; use Illuminate\Database\Eloquent\Model; -class installation extends Model +class CompanyProject extends Model { use HasFactory; + protected $table = 'company_projects'; + + protected $primaryKey = 'company_projects_id'; public $timestamps = false; } diff --git a/app/Models/Equipment.php b/app/Models/Equipment.php new file mode 100644 index 00000000..e8cfb116 --- /dev/null +++ b/app/Models/Equipment.php @@ -0,0 +1,41 @@ +belongsTo(Unit::class, 'unit_id', 'unit_id'); + } + + public function equipmentType() + { + return $this->belongsTo(EquipmentType::class, 'equipment_type_id', 'equipment_type_id'); + } + + public function specificAttributes() + { + return $this->hasMany(SpecificAttributesEquipmentType::class, 'equipment_id', 'equipment_id'); + } + + + + +} diff --git a/app/Models/EquipmentType.php b/app/Models/EquipmentType.php new file mode 100644 index 00000000..0c8754f0 --- /dev/null +++ b/app/Models/EquipmentType.php @@ -0,0 +1,23 @@ +hasMany(Equipment::class, 'equipment_type_id', 'equipment_type_id'); + } + + public function specificAttributesEquipamentTypes(){ + return $this->hasMany(SpecificAttributesEquipmentType::class, 'equipment_type_id', 'equipment_type_id'); + } +} diff --git a/app/Models/GeneralAttributesEquipment.php b/app/Models/GeneralAttributesEquipment.php new file mode 100644 index 00000000..4de27217 --- /dev/null +++ b/app/Models/GeneralAttributesEquipment.php @@ -0,0 +1,20 @@ +hasMany(SpecificAttributesEquipmentType::class, 'specific_attributes_equipment_type_id', 'general_attributes_equipment_id'); + } +} diff --git a/app/Models/company_project.php b/app/Models/PendingEquipment.php similarity index 57% rename from app/Models/company_project.php rename to app/Models/PendingEquipment.php index b06dbd2f..2ab62af9 100644 --- a/app/Models/company_project.php +++ b/app/Models/PendingEquipment.php @@ -5,9 +5,13 @@ use Illuminate\Database\Eloquent\Factories\HasFactory; use Illuminate\Database\Eloquent\Model; -class company_project extends Model +class PendingEquipment extends Model { use HasFactory; public $timestamps = false; + + protected $table = 'pending_equipments'; + + protected $primaryKey = 'pending_equipment_id'; } diff --git a/app/Models/pending_user.php b/app/Models/PendingUser.php similarity index 83% rename from app/Models/pending_user.php rename to app/Models/PendingUser.php index 83e59923..62006144 100644 --- a/app/Models/pending_user.php +++ b/app/Models/PendingUser.php @@ -5,10 +5,14 @@ use Illuminate\Database\Eloquent\Factories\HasFactory; use Illuminate\Database\Eloquent\Model; -class pending_user extends Model +class PendingUser extends Model { use HasFactory; + protected $table = 'pending_users'; + + protected $primaryKey = 'pending_user_id'; + /** * The attributes that are mass assignable. * diff --git a/app/Models/Plant.php b/app/Models/Plant.php new file mode 100644 index 00000000..d042062a --- /dev/null +++ b/app/Models/Plant.php @@ -0,0 +1,29 @@ +belongsTo(User::class, 'user_id', 'user_id'); + } + + public function companyProjects(){ + return $this->hasMany(CompanyProject::class, 'plant_id', 'plant_id'); + } + + public function units(){ + return $this->hasMany(Unit::class, 'plant_id', 'plant_id'); + } +} diff --git a/app/Models/SpecificAttributesEquipmentType.php b/app/Models/SpecificAttributesEquipmentType.php new file mode 100644 index 00000000..035b3cf5 --- /dev/null +++ b/app/Models/SpecificAttributesEquipmentType.php @@ -0,0 +1,31 @@ +belongsTo(EquipmentType::class,'equipment_type_id', 'equipment_type_id'); + } + + public function equipment() + { + return $this->belongsTo(Equipment::class, 'equipment_id', 'equipment_id'); + } + + public function generalAttribute() + { + return $this->belongsTo(GeneralAttributesEquipment::class, 'specific_attributes_equipment_type_id', 'general_attributes_equipment_id'); + } + + +} diff --git a/app/Models/TypeUser.php b/app/Models/TypeUser.php index 2e84a017..ed364677 100644 --- a/app/Models/TypeUser.php +++ b/app/Models/TypeUser.php @@ -9,8 +9,12 @@ class TypeUser extends Model { use HasFactory; + protected $table = 'type_users'; + + protected $primaryKey = 'type_user_id'; + public function users() { - return $this->hasMany(User::class, 'user_type', 'id'); + return $this->hasMany(User::class, 'type_users', 'type_user_id'); } } diff --git a/app/Models/Unit.php b/app/Models/Unit.php new file mode 100644 index 00000000..907627d1 --- /dev/null +++ b/app/Models/Unit.php @@ -0,0 +1,19 @@ +hasMany(Equipment::class, 'unit_id', 'unit_id'); + } +} diff --git a/app/Models/User.php b/app/Models/User.php index d1f7cec1..e0d82cc8 100644 --- a/app/Models/User.php +++ b/app/Models/User.php @@ -17,6 +17,10 @@ class User extends Authenticatable { use HasApiTokens, HasFactory, Notifiable; + protected $table = 'users'; + + protected $primaryKey = 'user_id'; + /** * The attributes that are mass assignable. * @@ -51,8 +55,16 @@ class User extends Authenticatable 'email_verified_at' => 'datetime', ]; - public function userType() - { - return $this->belongsTo(TypeUser::class, 'user_type', 'id'); + // public function typeUser(){ + // return $this->belongsTo(TypeUser::class, 'type_users', 'type_user_id'); + // } + + public function userType() { + return $this->belongsTo(TypeUser::class, 'type_users', 'type_user_id'); } + + public function plants(){ + return $this->hasMany(Plant::class,'user_id', 'user_id'); + } + } diff --git a/app/Models/equipament.php b/app/Models/equipament.php deleted file mode 100644 index 56b2fbf5..00000000 --- a/app/Models/equipament.php +++ /dev/null @@ -1,16 +0,0 @@ - + +
+ @if (session('success')) +
+ {{ session('success') }} +
+ @endif +
+
+
+

Tabela Empresas

+ +
+
+ + +
+ +
+
+
+
+ +
+ + + + + + + + + + + + @foreach ($users as $user) + + + + + {{-- --}} + + + + + @endforeach + +
IDNomeEmailTipo de UsuárioAções
{{ $user->id }}{{ $user->name }}{{ $user->email }}{{ $user->user_type }}{{ optional(\App\Models\TypeUser::find($user->user_type))->type }} + + + + + + + {{-- + + --}} +
+ @csrf + @method('DELETE') + +
+
+
+ +
+ + + + + +
+ {{-- /.container-fluid" --}} + + + +@endsection diff --git a/resources/views/Admin/CrudUsers/listUsers.blade.php b/resources/views/Admin/CrudUsers/listUsers.blade.php index 4c1b3b7d..f5584f0f 100644 --- a/resources/views/Admin/CrudUsers/listUsers.blade.php +++ b/resources/views/Admin/CrudUsers/listUsers.blade.php @@ -1,89 +1,88 @@ @extends('Templates/templateAdmin') @section('Main-content') - +
-
+
+ @if (session('success')) +
+ {{ session('success') }} +
+ @endif +
+
+
+

Tabela Utilizadores

-
-

Algum Titulo

- @if (session('success')) -
- {{ session('success') }} -
- @endif -
-
-

Tabela Utilizadores

+
+
+ -
-
- - -
- -
+
+
- -
- - + + +
+
+ + + + + + + + + + + @foreach ($users as $user) - - - - - - - - - @foreach ($users as $user) - - - - - - + + + {{-- --}} + + + - - @endforeach - -
IDNomeEmailTipo de UsuárioAções
IDNomeEmailTipo de UsuárioAções
{{ $user->id }}{{ $user->name }}{{ $user->email }}{{ $user->user_type }} - - - - - - - {{-- + {{ $user->id }}{{ $user->name }}{{ $user->email }}{{ $user->user_type }}{{ optional(\App\Models\TypeUser::find($user->user_type))->type }} + + + + + + + + {{-- --}} -
- @csrf - @method('DELETE') - -
-
-
- +
+ @csrf + @method('DELETE') + +
+ + + @endforeach + +
- - - - - +
- {{-- /.container-fluid" --}} + -
- + + + + {{-- /.container-fluid" --}} + + +
@endsection diff --git a/resources/views/Admin/DataManagement/manageassets.blade.php b/resources/views/Admin/DataManagement/manageassets.blade.php new file mode 100644 index 00000000..feeffa1d --- /dev/null +++ b/resources/views/Admin/DataManagement/manageassets.blade.php @@ -0,0 +1,724 @@ +@extends('Templates/templateAdmin') + +@section('Main-content') +
+ +
+
+
+
+

Gestão de ativos

+
+
+ +
+
+
+
+ + + + +
+
+ +
+
+
+

Instalações

+ +
+ +
+ +
+ +
+ +
+
+

Inserir nova instalação

+ +
+ +
+ +
+ +
+
+ + +
+
+ + +
+
+ + +
+
+ + +
+ +
+ + + + + + + + + + + @foreach ($units as $unit) + + + + + + + + @endforeach + +
InstalaçãoFábricaClienteEditar
{{ $unit->unit_name }}{{ $unit->plant_name }}{{ $unit->user_name }} + + + + + +
+
+ +
+
+ +
+ + + + +
+
+
+

Equipamentos

+ +
+ +
+ +
+ +
+ +
+
+

Inserir novo equipamento

+ +
+ +
+
+
+ +
+ + +
+ +
+ + +
+ + +
+
+

PSV

+
+ +
+
+
+
+ + +
+
+
+
+ + +
+
+
+ +
+
+
+ + +
+
+
+
+ + +
+
+
+ +
+
+
+ + +
+
+
+
+ + +
+
+
+
+
+
+ + +
+
+
+
+ + +
+
+
+
+ +
+ + +
+
+

Válvula de isolamento

+
+ +
+
+
+
+ + +
+
+
+
+ + +
+
+
+ +
+
+
+ + +
+
+
+
+ + +
+
+
+ +
+
+
+ + +
+
+
+
+ + +
+
+
+
+
+
+ + +
+
+
+
+ + +
+
+
+
+ +
+ +
+
+

Válvula de controlo

+
+ +
+
+
+
+ + +
+
+
+
+ + +
+
+
+ +
+
+
+ + +
+
+
+
+ + +
+
+
+ +
+
+
+ + +
+
+
+
+ + +
+
+
+
+
+
+ + +
+
+
+
+ + +
+
+
+
+
+
+ + +
+
+
+
+ + +
+
+
+
+ + +
+
+
+ +
+
+
+ + +
+
+
+
+ + +
+
+
+
+
+ +
+ +
+
+ + +
+
+
+ +
+ + +
+ + +
+ + + + + + + + + + + + + + + + {{-- + @foreach ($equipaments as $equipament) + + + + + + + + + + + + + + @endforeach + --}} +
ID equipamentotagFabricaTipo equipamentoDescricao equipamentoNumero de Serie MarcaModeloActivoEdicao
{{ $equipament->equipment_id }}{{ $equipament->tag }}{{ $equipament->factories_name }}{{ $equipament->equipment_type_name }}{{ $equipament->equipment_description }}{{ $equipament->serial_number }}{{ $equipament->brand }}{{ $equipament->model }}{{ $equipament->Is_active }} + + + + + + + + +
+
+ + +
+
+
+ + +
+
+ + + + + + + + + + + + + + + + + + + + + +
+@endsection diff --git a/resources/views/Admin/DataManagement/showEquipament.blade.php b/resources/views/Admin/DataManagement/showEquipament.blade.php new file mode 100644 index 00000000..05360bc7 --- /dev/null +++ b/resources/views/Admin/DataManagement/showEquipament.blade.php @@ -0,0 +1,61 @@ +@extends('Templates/templateAdmin') + +@section('Main-content') + +
+ +
+

Detalhes Equipamento

+
+
+ Detalhes do Equipamento :: {{ $equipaments->tag }}
+
+
+ + + + + + + + + + + + + + + + + + + + + + + + + + +
ID Equipamento{{ $equipaments->equipment_id }}
Tag{{ $equipaments->tag }}
Instalacao{{ $equipaments->factory_id }}
Tipo de equipamento {{ $equipaments->equipament_type_id }}
Descricao de equipamento {{ $equipaments->equipment_description }}
Numero de Serie{{ $equipaments->serial_number }}
+
+
+
+
+
+ {{-- --}} +
+ +
+
+ {{-- /.container-fluid --}} + +
+{{-- /.content --}} + + + +@endsection \ No newline at end of file diff --git a/resources/views/Templates/templateAdmin.blade.php b/resources/views/Templates/templateAdmin.blade.php index ab72d852..60c34931 100644 --- a/resources/views/Templates/templateAdmin.blade.php +++ b/resources/views/Templates/templateAdmin.blade.php @@ -35,7 +35,7 @@ - + @@ -92,11 +92,11 @@ class="fas fa-bars"> @@ -127,13 +127,13 @@ class="fas fa-bars"> - + @@ -150,7 +150,7 @@ class="fas fa-bars">