Explorar el Código

Inizio gestione company e fix vari

Luca Parisio hace 5 meses
padre
commit
6559ff20eb
Se han modificado 43 ficheros con 946 adiciones y 22 borrados
  1. 26 0
      app/Console/Commands/MigrateMaster.php
  2. 30 0
      app/Console/Commands/MigrateTenants.php
  3. 38 0
      app/Helpers/helpers.php
  4. 7 2
      app/Http/Middleware/TenantMiddleware.php
  5. 100 0
      app/Livewire/Company.php
  6. 92 0
      app/Livewire/CompanyActivity.php
  7. 23 0
      app/Livewire/CompanyRate.php
  8. 23 0
      app/Livewire/CompanyService.php
  9. 14 0
      app/Livewire/Dashboard.php
  10. 1 0
      app/Livewire/Index.php
  11. 43 0
      app/Livewire/Login.php
  12. 20 0
      app/Livewire/Onboarding.php
  13. 9 0
      app/Livewire/Registration.php
  14. 25 0
      app/Models/City.php
  15. 67 0
      app/Models/Company.php
  16. 25 0
      app/Models/CompanyActivity.php
  17. 27 0
      app/Models/CompanyRate.php
  18. 25 0
      app/Models/CompanyService.php
  19. 19 0
      app/Models/Country.php
  20. 4 1
      app/Providers/AppServiceProvider.php
  21. 1 1
      app/Services/MigrationService.php
  22. 2 1
      bootstrap/app.php
  23. 4 1
      composer.json
  24. 1 0
      config/livewire.php
  25. 1 0
      database/migrations/0001_01_01_000000_create_users_table.php
  26. 1 0
      database/migrations/0001_01_01_000001_create_cache_table.php
  27. 1 0
      database/migrations/0001_01_01_000002_create_jobs_table.php
  28. 5 6
      database/migrations/2025_08_04_100000_add_fields_to_users_table.php
  29. 31 0
      database/migrations/2025_08_08_101404_create_countries_table.php
  30. 33 0
      database/migrations/2025_08_08_101413_create_cities_table.php
  31. 48 0
      database/migrations/2025_08_08_102010_create_companies_table.php
  32. 34 0
      database/migrations/2025_08_08_102231_create_company_services_table.php
  33. 34 0
      database/migrations/2025_18_08_161031_create_company_activities_table.php
  34. 36 0
      database/migrations/2025_18_08_161031_create_company_rates_table.php
  35. 9 3
      database/seeders/DatabaseSeeder.php
  36. 1 1
      resources/views/layouts/admin.blade.php
  37. 12 0
      resources/views/livewire/company.blade.php
  38. 34 0
      resources/views/livewire/company_activity.blade.php
  39. 4 0
      resources/views/livewire/company_rate.blade.php
  40. 4 0
      resources/views/livewire/company_service.blade.php
  41. 6 0
      resources/views/livewire/dashboard.blade.php
  42. 11 5
      resources/views/livewire/login.blade.php
  43. 15 1
      routes/web.php

+ 26 - 0
app/Console/Commands/MigrateMaster.php

@@ -0,0 +1,26 @@
+<?php
+namespace App\Console\Commands;
+
+use Illuminate\Console\Command;
+use App\Services\MigrationService;
+
+class MigrateMaster extends Command
+{
+    protected $signature = 'migrate:master {--rollback} {--step=1}';
+    protected $description = 'Run migrations on master database only';
+
+    public function handle(MigrationService $migrationService)
+    {
+        if ($this->option('rollback')) {
+            $result = $migrationService->rollbackMasterMigrations($this->option('step'));
+            $this->info($result['message']);
+            $this->line($result['output']);
+        } else {
+            $result = $migrationService->runMasterMigrations();
+            $this->info($result['message']);
+            if (!empty($result['migrations'])) {
+                $this->table(['Master Migrations'], array_map(fn($m) => [$m], $result['migrations']));
+            }
+        }
+    }
+}

+ 30 - 0
app/Console/Commands/MigrateTenants.php

@@ -0,0 +1,30 @@
+<?php
+namespace App\Console\Commands;
+
+use Illuminate\Console\Command;
+use App\Services\MigrationService;
+
+class MigrateTenants extends Command
+{
+    protected $signature = 'migrate:tenants {--rollback} {--step=1}';
+    protected $description = 'Run migrations on all tenant databases';
+
+    public function handle(MigrationService $migrationService)
+    {
+        if ($this->option('rollback')) {
+            $result = $migrationService->rollbackTenantMigrations($this->option('step'));
+        } else {
+            $result = $migrationService->runTenantMigrations();
+        }
+
+        $this->info($result['message']);
+
+        if (!empty($result['results'])) {
+            $tableData = [];
+            foreach ($result['results'] as $r) {
+                $tableData[] = [$r['tenant'], $r['status'], $r['message']];
+            }
+            $this->table(['Tenant Database', 'Status', 'Message'], $tableData);
+        }
+    }
+}

+ 38 - 0
app/Helpers/helpers.php

@@ -0,0 +1,38 @@
+<?php
+
+if (! function_exists('setTenant')) {
+    function setTenant()
+    {
+        $user = auth()->user();
+
+        if ($user) {
+            Log::info('Setting database connection', [
+                'database' => $user->tenant_database,
+                'username' => $user->tenant_username,
+                'password' => $user->tenant_password
+            ]);
+
+            $connection = [
+                'driver' => 'mysql',
+                'host' => '127.0.0.1',
+                'port' => '3306',
+                'database' => $user->tenant_database,
+                'username' => $user->tenant_username,
+                'password' => $user->tenant_password,
+            ];
+
+            config(['database.connections.tenant' => $connection]);
+
+            config(['database.default' => 'tenant']);
+            DB::purge('tenant');
+            DB::reconnect('tenant');
+
+            session(['currentClient' => $user->tenant_database]);
+
+            session(['db_connection' => $connection]);
+
+            Log::info('Current database after setup: ' . DB::connection()->getDatabaseName());
+            Log::info('Current default connection: ' . DB::getDefaultConnection());
+        }
+    }
+}

+ 7 - 2
app/Http/Middleware/TenantMiddleware.php

@@ -15,6 +15,7 @@ class TenantMiddleware
      */
     public function handle(Request $request, Closure $next): Response
     {
+
         if (! $request->user()) {
             return redirect('/');
         }
@@ -38,14 +39,16 @@ class TenantMiddleware
                 'password' => $user->tenant_password
             ]);
 
-            config(['database.connections.tenant' => [
+            $connection = [
                 'driver' => 'mysql',
                 'host' => '127.0.0.1',
                 'port' => '3306',
                 'database' => $user->tenant_database,
                 'username' => $user->tenant_username,
                 'password' => $user->tenant_password,
-            ]]);
+            ];
+
+            config(['database.connections.tenant' => $connection]);
 
             config(['database.default' => 'tenant']);
             DB::purge('tenant');
@@ -53,6 +56,8 @@ class TenantMiddleware
 
             session(['currentClient' => $user->tenant_database]);
 
+            session(['db_connection' => $connection]);
+
             Log::info('Current database after setup: ' . DB::connection()->getDatabaseName());
             Log::info('Current default connection: ' . DB::getDefaultConnection());
         }

+ 100 - 0
app/Livewire/Company.php

@@ -0,0 +1,100 @@
+<?php
+
+namespace App\Livewire;
+
+use Livewire\Component;
+use Livewire\Attributes\Validate;
+
+class Company extends Component
+{
+
+    #[Validate('required')] 
+    public $name = '';
+    public $business_name = '';
+    public $logo = '';
+    public $phone = '';
+    public $email = '';
+    public $pec = '';
+    public $costitution_date = null;
+    public $address = '';
+    public $zip = '';
+    public $city_id = null;
+    public $country_id = null;
+    public $operational_headquarters = '';
+    public $fiscal_code = '';
+    public $vat = ''; 
+    public $sdi_code = '';
+    public $ateco_code = '';
+    public $enabled = true;
+
+    public $current_company = null;
+
+    public $is_edit = false;
+
+    public function render()
+    {
+
+        // Get Company
+        $this->current_company = \App\Models\Company::first();
+
+        if ($this->current_company != null)
+        {
+
+            $this->name = $this->current_company->name;
+            $this->business_name = $this->current_company->business_name;
+            $this->logo = $this->current_company->logo;
+            $this->phone = $this->current_company->phone;
+            $this->email = $this->current_company->email;
+            $this->pec = $this->current_company->pec;
+            $this->costitution_date = $this->current_company->pec;
+            $this->address = $this->current_company->address;
+            $this->zip = $this->current_company->zip;
+            $this->city_id = $this->current_company->city_id;
+            $this->country_id = $this->current_company->country_id;
+            $this->operational_headquarters = $this->current_company->operational_headquarters;
+            $this->fiscal_code = $this->current_company->fiscal_code;
+            $this->vat = $this->current_company-> vat;
+            $this->sdi_code = $this->current_company->sdi_code;
+            $this->ateco_code = $this->current_company->ateco_code;
+            $this->enabled = $this->current_company->enabled;
+
+        }
+
+        return view('livewire.company');
+    }
+
+    public function update()
+    {
+
+        $this->validate();
+
+        try {
+            $this->current_company->update([
+                'name' => $this->name,
+                'business_name' => $this->business_name,
+                'logo' => $this->logo,
+                'phone' => $this->phone,
+                'email' => $this->email,
+                'pec' => $this->pec,
+                'costitution_date' => $this->pec,
+                'address' => $this->address,
+                'zip' => $this->zip,
+                'city_id' => $this->city_id,
+                'country_id' => $this->country_id,
+                'operational_headquarters' => $this->operational_headquarters,
+                'fiscal_code' => $this->fiscal_code,
+                'vat' => $this-> vat,
+                'sdi_code' => $this->sdi_code,
+                'ateco_code' => $this->ateco_code,
+                'enabled' => $this->enabled,
+            ]);
+            session()->flash('success','Dato aggiornato');
+            //$this->resetFields();
+            $this->is_edit = false;
+        } catch (\Exception $ex) {
+            session()->flash('error','Errore (' . $ex->getMessage() . ')');
+        }
+
+    }
+
+}

+ 92 - 0
app/Livewire/CompanyActivity.php

@@ -0,0 +1,92 @@
+<?php
+
+namespace App\Livewire;
+use Illuminate\Support\Facades\Log;
+use Illuminate\Support\Facades\DB;
+use Livewire\Attributes\Validate;
+use Livewire\Component;
+use Livewire\Attributes\Layout;
+
+class CompanyActivity extends Component
+{
+
+    public $company;
+
+    public $current_company_activity = null;
+
+    public $company_activities = [];
+
+    #[Validate('required')] 
+    public $name = '';
+    public $description = '';
+    public $enabled = 1;
+
+    public $is_edit = false;
+
+    public function resetFields(){
+        $this->name = '';
+        $this->description = '';
+        $this->enabled = 1;
+    }
+
+    public function render()
+    {
+        $this->company_activities = $this->company->activities;
+        return view('livewire.company_activity');
+    }
+
+    public function add()
+    {
+        $this->resetFields();
+        $this->is_edit = true;
+        $this->current_company_activity = null;
+    }
+
+    public function edit($id)
+    {
+        $this->resetFields();
+        $this->is_edit = true;
+        $this->current_company_activity = \App\Models\CompanyActivity::findOrFail($id);
+        $this->name = $this->current_company_activity->name;
+        $this->description = $this->current_company_activity->description;
+        $this->enabled = $this->current_company_activity->enabled == 1;
+    }
+
+    public function save()
+    {
+        $this->validate();
+        try 
+        {
+            if ($this->current_company_activity == null)
+            {
+                \App\Models\CompanyActivity::create([
+                    'company_id' => $this->company->id,
+                    'name' => $this->name,
+                    'description' => $this->description,
+                    'enabled' => $this->enabled
+                ]);
+            }
+            else
+            {
+                $this->current_company_activity->update([
+                    'name' => $this->name,
+                    'description' => $this->description,
+                    'enabled' => $this->enabled ? 1 : 0,
+                ]);
+            }
+            session()->flash('success','Dati salvati con successo');
+            $this->resetFields();
+            $this->is_edit = false;
+        } catch (\Exception $ex) {
+            session()->flash('error','Errore (' . $ex->getMessage() . ')');
+        }
+    }
+
+    public function cancel()
+    {
+        $this->resetFields();
+        $this->is_edit = false;
+        $this->current_company_activity = null;
+    }
+
+}

+ 23 - 0
app/Livewire/CompanyRate.php

@@ -0,0 +1,23 @@
+<?php
+
+namespace App\Livewire;
+use Illuminate\Support\Facades\Log;
+use Illuminate\Support\Facades\DB;
+use Livewire\Attributes\Validate;
+use Livewire\Component;
+use Livewire\Attributes\Layout;
+
+class CompanyRate extends Component
+{
+
+    public $company;
+
+    #[Validate('required')] 
+    public $name = '';
+
+    public function render()
+    {
+        return view('livewire.company_rate');
+    }
+
+}

+ 23 - 0
app/Livewire/CompanyService.php

@@ -0,0 +1,23 @@
+<?php
+
+namespace App\Livewire;
+use Illuminate\Support\Facades\Log;
+use Illuminate\Support\Facades\DB;
+use Livewire\Attributes\Validate;
+use Livewire\Component;
+use Livewire\Attributes\Layout;
+
+class CompanyService extends Component
+{
+
+    public $company;
+
+    #[Validate('required')] 
+    public $name = '';
+
+    public function render()
+    {
+        return view('livewire.company_service');
+    }
+
+}

+ 14 - 0
app/Livewire/Dashboard.php

@@ -0,0 +1,14 @@
+<?php
+
+namespace App\Livewire;
+
+use Livewire\Component;
+
+class Dashboard extends Component
+{
+
+    public function render()
+    {
+        return view('livewire.dashboard');
+    }
+}

+ 1 - 0
app/Livewire/Index.php

@@ -3,6 +3,7 @@
 namespace App\Livewire;
 
 use Livewire\Component;
+use Livewire\Attributes\Layout;
 
 class Index extends Component
 {

+ 43 - 0
app/Livewire/Login.php

@@ -3,12 +3,55 @@
 namespace App\Livewire;
 
 use Livewire\Component;
+use Livewire\Attributes\Layout;
 
 class Login extends Component
 {
+
+    public $email;
+    public $password;
+
+    protected $rules = [
+        'email' => 'required',
+        'password' => 'required',
+    ];
+
+    protected $messages = [
+        'email.required' => 'La mail è obbligatoria',
+        'password.required' => 'La password è obbligatoria',
+    ];
+
+    public $error = '';
+
     #[Layout('layouts.frontend')]
     public function render()
     {
         return view('livewire.login');
     }
+
+    public function login()
+    {
+
+        $this->validate();
+        
+        if (\Auth::attempt(['email' => $this->email, 'password' => $this->password])) 
+        {
+        
+            $user = \Auth::user();
+
+            /*if (!$user->first_login_completed) 
+            {
+                $user->first_login_at = now();
+                $user->save();
+
+                return redirect('/first-login');
+            }*/
+
+            return redirect()->route('dashboard');
+        } 
+        else 
+        {
+            $this->error = 'ERRORE';
+        }
+    }
 }

+ 20 - 0
app/Livewire/Onboarding.php

@@ -3,9 +3,29 @@
 namespace App\Livewire;
 
 use Livewire\Component;
+use Livewire\Attributes\Layout;
 
 class Onboarding extends Component
 {
+
+    // step 1
+    public $name;
+    public $businessName;
+    public $sector;
+    public $activity;
+    public $logo;
+
+    // step 2
+    public $calendarTypology;
+    public $slotInterval;
+    public $startHourView;
+    public $endHourView;
+
+    // step 3
+    public $slotApprovalWorkflow;
+    public $costsApprovalWorkflow;
+    public $absenceApprovalWorkflow;
+
     #[Layout('layouts.frontend')]
     public function render()
     {

+ 9 - 0
app/Livewire/Registration.php

@@ -3,9 +3,18 @@
 namespace App\Livewire;
 
 use Livewire\Component;
+use Livewire\Attributes\Layout;
 
 class Registration extends Component
 {
+
+    public $firstName;
+    public $lastName;
+    public $company;
+    public $email;
+    public $password;
+    public $passwordConfirm;
+
     #[Layout('layouts.frontend')]
     public function render()
     {

+ 25 - 0
app/Models/City.php

@@ -0,0 +1,25 @@
+<?php
+
+namespace App\Models;
+
+use Illuminate\Database\Eloquent\Factories\HasFactory;
+use Illuminate\Database\Eloquent\Model;
+use Illuminate\Database\Eloquent\SoftDeletes;
+
+class City extends Model
+{
+    use HasFactory;
+    use SoftDeletes;
+
+    protected $fillable = [
+        'country_id',
+        'name',
+        'enabled',
+    ];
+
+    public function country()
+    {
+        return $this->belongsTo(\App\Models\Country::class);
+    }
+
+}

+ 67 - 0
app/Models/Company.php

@@ -0,0 +1,67 @@
+<?php
+
+namespace App\Models;
+
+use Illuminate\Database\Eloquent\Factories\HasFactory;
+use Illuminate\Database\Eloquent\Model;
+use Illuminate\Database\Eloquent\SoftDeletes;
+use Illuminate\Support\Facades\Log;
+use Illuminate\Support\Facades\DB;
+
+
+class Company extends Model
+{
+    use HasFactory;
+    use SoftDeletes;
+
+    public function __construct()
+    {
+        setTenant();
+    }
+
+    protected $fillable = [
+        'name',
+        'business_name',
+        'logo',
+        'phone',
+        'email',
+        'pec',
+        'costitution_date',
+        'address',
+        'zip',
+        'city_id',
+        'country_id',
+        'operational_headquarters',
+        'fiscal_code',
+        'vat',           
+        'sdi_code',
+        'ateco_code',            
+        'enabled',
+    ];
+
+    public function country()
+    {
+        return $this->belongsTo(\App\Models\Country::class);
+    }
+
+    public function city()
+    {
+        return $this->belongsTo(\App\Models\City::class);
+    }
+
+    public function activities()
+    {
+        return $this->hasMany(\App\Models\CompanyActivity::class);
+    }
+
+    public function rates()
+    {
+        return $this->hasMany(\App\Models\CompanyActivity::class);
+    }
+
+    public function services()
+    {
+        return $this->hasMany(\App\Models\CompanyActivity::class);
+    }
+
+}

+ 25 - 0
app/Models/CompanyActivity.php

@@ -0,0 +1,25 @@
+<?php
+
+namespace App\Models;
+
+use Illuminate\Database\Eloquent\Factories\HasFactory;
+use Illuminate\Database\Eloquent\Model;
+use Illuminate\Database\Eloquent\SoftDeletes;
+
+class CompanyActivity extends Model
+{
+    use HasFactory;
+    use SoftDeletes;
+
+    protected $fillable = [
+        'company_id',
+        'name',
+        'description',
+        'enabled',
+    ];
+
+    public function country()
+    {
+        return $this->belongsTo(\App\Models\Company::class);
+    }
+}

+ 27 - 0
app/Models/CompanyRate.php

@@ -0,0 +1,27 @@
+<?php
+
+namespace App\Models;
+
+use Illuminate\Database\Eloquent\Factories\HasFactory;
+use Illuminate\Database\Eloquent\Model;
+use Illuminate\Database\Eloquent\SoftDeletes;
+
+class CompanyRate extends Model
+{
+    use HasFactory;
+    use SoftDeletes;
+
+    protected $fillable = [
+        'company_id',
+        'amount',
+        'type',
+        'group',
+        'description',
+        'enabled',
+    ];
+
+    public function country()
+    {
+        return $this->belongsTo(\App\Models\Company::class);
+    }
+}

+ 25 - 0
app/Models/CompanyService.php

@@ -0,0 +1,25 @@
+<?php
+
+namespace App\Models;
+
+use Illuminate\Database\Eloquent\Factories\HasFactory;
+use Illuminate\Database\Eloquent\Model;
+use Illuminate\Database\Eloquent\SoftDeletes;
+
+class CompanyService extends Model
+{
+    use HasFactory;
+    use SoftDeletes;
+
+    protected $fillable = [
+        'company_id',
+        'name',
+        'description',
+        'enabled',
+    ];
+
+    public function country()
+    {
+        return $this->belongsTo(\App\Models\Company::class);
+    }
+}

+ 19 - 0
app/Models/Country.php

@@ -0,0 +1,19 @@
+<?php
+
+namespace App\Models;
+
+use Illuminate\Database\Eloquent\Factories\HasFactory;
+use Illuminate\Database\Eloquent\Model;
+use Illuminate\Database\Eloquent\SoftDeletes;
+
+class Country extends Model
+{
+    use HasFactory;
+    use SoftDeletes;
+
+    protected $fillable = [
+        'name',
+        'enabled',
+    ];
+
+}

+ 4 - 1
app/Providers/AppServiceProvider.php

@@ -3,6 +3,7 @@
 namespace App\Providers;
 
 use Illuminate\Support\ServiceProvider;
+use Livewire;
 
 class AppServiceProvider extends ServiceProvider
 {
@@ -19,6 +20,8 @@ class AppServiceProvider extends ServiceProvider
      */
     public function boot(): void
     {
-        //
+        /*Livewire::addPersistentMiddleware([ 
+            App\Http\Middleware\TenantMiddleware::class,
+        ]);*/
     }
 }

+ 1 - 1
app/Services/MigrationService.php

@@ -10,7 +10,7 @@ use App\Database\Migrations\TenantMigration;
 
 class MigrationService
 {
-    protected $masterDatabase = 'easia_tenant';
+    protected $masterDatabase = 'easia_master';
 
     public function runMasterMigrations()
     {

+ 2 - 1
bootstrap/app.php

@@ -3,6 +3,7 @@
 use Illuminate\Foundation\Application;
 use Illuminate\Foundation\Configuration\Exceptions;
 use Illuminate\Foundation\Configuration\Middleware;
+use App\Http\Middleware\TenantMiddleware;
 
 return Application::configure(basePath: dirname(__DIR__))
     ->withRouting(
@@ -11,7 +12,7 @@ return Application::configure(basePath: dirname(__DIR__))
         health: '/up',
     )
     ->withMiddleware(function (Middleware $middleware): void {
-        //
+        //$middleware->append(TenantMiddleware::class);
     })
     ->withExceptions(function (Exceptions $exceptions): void {
         //

+ 4 - 1
composer.json

@@ -25,7 +25,10 @@
             "App\\": "app/",
             "Database\\Factories\\": "database/factories/",
             "Database\\Seeders\\": "database/seeders/"
-        }
+        },
+        "files": [
+            "app/Helpers/helpers.php"
+        ]
     },
     "autoload-dev": {
         "psr-4": {

+ 1 - 0
config/livewire.php

@@ -157,4 +157,5 @@ return [
     */
 
     'pagination_theme' => 'tailwind',
+    
 ];

+ 1 - 0
database/migrations/0001_01_01_000000_create_users_table.php

@@ -3,6 +3,7 @@
 use Illuminate\Database\Migrations\Migration;
 use Illuminate\Database\Schema\Blueprint;
 use Illuminate\Support\Facades\Schema;
+use App\Database\Migrations\MasterMigration;
 
 return new class extends MasterMigration
 {

+ 1 - 0
database/migrations/0001_01_01_000001_create_cache_table.php

@@ -3,6 +3,7 @@
 use Illuminate\Database\Migrations\Migration;
 use Illuminate\Database\Schema\Blueprint;
 use Illuminate\Support\Facades\Schema;
+use App\Database\Migrations\MasterMigration;
 
 return new class extends MasterMigration
 {

+ 1 - 0
database/migrations/0001_01_01_000002_create_jobs_table.php

@@ -3,6 +3,7 @@
 use Illuminate\Database\Migrations\Migration;
 use Illuminate\Database\Schema\Blueprint;
 use Illuminate\Support\Facades\Schema;
+use App\Database\Migrations\MasterMigration;
 
 return new class extends MasterMigration
 {

+ 5 - 6
database/migrations/2025_08_04_100000_add_fields_to_users_table.php

@@ -3,6 +3,7 @@
 use Illuminate\Database\Migrations\Migration;
 use Illuminate\Database\Schema\Blueprint;
 use Illuminate\Support\Facades\Schema;
+use App\Database\Migrations\MasterMigration;
 
 return new class extends MasterMigration
 {
@@ -16,9 +17,8 @@ return new class extends MasterMigration
         Schema::table('users', function (Blueprint $table) {
             $table->integer('level')->default(0);
             $table->integer('enabled')->default(1);
-            $table->string('cellulare')->nullable();
-            $table->string('telefono')->nullable();
-            $table->string('cognome')->nullable();
+            $table->string('first_name')->nullable();
+            $table->string('last_name')->nullable();
             $table->boolean('first_login_completed')->default(false);
             $table->timestamp('first_login_at')->nullable();
             $table->string('tenant_host')->nullable();
@@ -38,9 +38,8 @@ return new class extends MasterMigration
         Schema::table('users', function (Blueprint $table) {
             $table->dropColumn('level');
             $table->dropColumn('enabled');
-            $table->dropColumn('cellulare');
-            $table->dropColumn('telefono');
-            $table->dropColumn('cognome');
+            $table->dropColumn('first_name');
+            $table->dropColumn('last_name');
             $table->dropColumn('first_login_completed');
             $table->dropColumn('first_login_at');
             $table->dropColumn('tenant_host');

+ 31 - 0
database/migrations/2025_08_08_101404_create_countries_table.php

@@ -0,0 +1,31 @@
+<?php
+
+use Illuminate\Database\Migrations\Migration;
+use Illuminate\Database\Schema\Blueprint;
+use Illuminate\Support\Facades\Schema;
+use App\Database\Migrations\TenantMigration;
+
+return new class extends TenantMigration
+{
+    /**
+     * Run the migrations.
+     */
+    public function up(): void
+    {
+        Schema::create('countries', function (Blueprint $table) {
+            $table->id();
+            $table->string('name');
+            $table->boolean('enabled')->default(1);
+            $table->softDeletes();
+            $table->timestamps();
+        });
+    }
+
+    /**
+     * Reverse the migrations.
+     */
+    public function down(): void
+    {
+        Schema::dropIfExists('countries');
+    }
+};

+ 33 - 0
database/migrations/2025_08_08_101413_create_cities_table.php

@@ -0,0 +1,33 @@
+<?php
+
+use Illuminate\Database\Migrations\Migration;
+use Illuminate\Database\Schema\Blueprint;
+use Illuminate\Support\Facades\Schema;
+use App\Database\Migrations\TenantMigration;
+
+return new class extends TenantMigration
+{
+    /**
+     * Run the migrations.
+     */
+    public function up(): void
+    {
+        Schema::create('cities', function (Blueprint $table) {
+            $table->id();
+            $table->unsignedBigInteger('country_id')->nullable();
+            $table->foreign('country_id')->nullable()->references('id')->on('countries')->onUpdate('cascade')->onDelete('cascade');
+            $table->string('name');
+            $table->boolean('enabled')->default(1);
+            $table->softDeletes();
+            $table->timestamps();
+        });
+    }
+
+    /**
+     * Reverse the migrations.
+     */
+    public function down(): void
+    {
+        Schema::dropIfExists('cities');
+    }
+};

+ 48 - 0
database/migrations/2025_08_08_102010_create_companies_table.php

@@ -0,0 +1,48 @@
+<?php
+
+use Illuminate\Database\Migrations\Migration;
+use Illuminate\Database\Schema\Blueprint;
+use Illuminate\Support\Facades\Schema;
+use App\Database\Migrations\TenantMigration;
+
+return new class extends TenantMigration
+{
+    /**
+     * Run the migrations.
+     */
+    public function up(): void
+    {
+        Schema::create('companies', function (Blueprint $table) {
+            $table->id();
+            $table->string('name');
+            $table->string('business_name')->nullable();
+            $table->string('logo')->nullable();
+            $table->string('phone')->nullable();
+            $table->string('email')->nullable();
+            $table->string('pec')->nullable();
+            $table->date('costitution_date')->nullable();
+            $table->string('address')->nullable();
+            $table->string('zip')->nullable();
+            $table->unsignedBigInteger('city_id')->nullable();
+            $table->foreign('city_id')->nullable()->references('id')->on('cities')->onUpdate('cascade')->onDelete('cascade');
+            $table->unsignedBigInteger('country_id')->nullable();
+            $table->foreign('country_id')->nullable()->references('id')->on('countries')->onUpdate('cascade')->onDelete('cascade');
+            $table->string('operational_headquarters')->nullable();
+            $table->string('fiscal_code')->nullable();
+            $table->string('vat')->nullable();           
+            $table->string('sdi_code')->nullable();
+            $table->string('ateco_code')->nullable();            
+            $table->boolean('enabled')->default(1);
+            $table->softDeletes();
+            $table->timestamps();
+        });
+    }
+
+    /**
+     * Reverse the migrations.
+     */
+    public function down(): void
+    {
+        Schema::dropIfExists('companies');
+    }
+};

+ 34 - 0
database/migrations/2025_08_08_102231_create_company_services_table.php

@@ -0,0 +1,34 @@
+<?php
+
+use Illuminate\Database\Migrations\Migration;
+use Illuminate\Database\Schema\Blueprint;
+use Illuminate\Support\Facades\Schema;
+use App\Database\Migrations\TenantMigration;
+
+return new class extends TenantMigration
+{
+    /**
+     * Run the migrations.
+     */
+    public function up(): void
+    {
+        Schema::create('company_services', function (Blueprint $table) {
+            $table->id();
+            $table->unsignedBigInteger('company_id')->nullable();
+            $table->foreign('company_id')->nullable()->references('id')->on('companies')->onUpdate('cascade')->onDelete('cascade');
+            $table->string('name');
+            $table->text('description')->nullable();
+            $table->boolean('enabled')->default(1);
+            $table->softDeletes();
+            $table->timestamps();
+        });
+    }
+
+    /**
+     * Reverse the migrations.
+     */
+    public function down(): void
+    {
+        Schema::dropIfExists('company_services');
+    }
+};

+ 34 - 0
database/migrations/2025_18_08_161031_create_company_activities_table.php

@@ -0,0 +1,34 @@
+<?php
+
+use Illuminate\Database\Migrations\Migration;
+use Illuminate\Database\Schema\Blueprint;
+use Illuminate\Support\Facades\Schema;
+use App\Database\Migrations\TenantMigration;
+
+return new class extends TenantMigration
+{
+    /**
+     * Run the migrations.
+     */
+    public function up(): void
+    {
+        Schema::create('company_activities', function (Blueprint $table) {
+            $table->id();
+            $table->unsignedBigInteger('company_id')->nullable();
+            $table->foreign('company_id')->nullable()->references('id')->on('companies')->onUpdate('cascade')->onDelete('cascade');
+            $table->string('name');
+            $table->text('description')->nullable();
+            $table->boolean('enabled')->default(1);
+            $table->softDeletes();
+            $table->timestamps();
+        });
+    }
+
+    /**
+     * Reverse the migrations.
+     */
+    public function down(): void
+    {
+        Schema::dropIfExists('company_activities');
+    }
+};

+ 36 - 0
database/migrations/2025_18_08_161031_create_company_rates_table.php

@@ -0,0 +1,36 @@
+<?php
+
+use Illuminate\Database\Migrations\Migration;
+use Illuminate\Database\Schema\Blueprint;
+use Illuminate\Support\Facades\Schema;
+use App\Database\Migrations\TenantMigration;
+
+return new class extends TenantMigration
+{
+    /**
+     * Run the migrations.
+     */
+    public function up(): void
+    {
+        Schema::create('company_rates', function (Blueprint $table) {
+            $table->id();
+            $table->unsignedBigInteger('company_id')->nullable();
+            $table->foreign('company_id')->nullable()->references('id')->on('companies')->onUpdate('cascade')->onDelete('cascade');
+            $table->decimal('amount', total: 8, places: 2);
+            $table->string('type')->nullable();
+            $table->string('group')->nullable();
+            $table->text('description')->nullable();
+            $table->boolean('enabled')->default(1);
+            $table->softDeletes();
+            $table->timestamps();
+        });
+    }
+
+    /**
+     * Reverse the migrations.
+     */
+    public function down(): void
+    {
+        Schema::dropIfExists('company_rates');
+    }
+};

+ 9 - 3
database/seeders/DatabaseSeeder.php

@@ -15,9 +15,15 @@ class DatabaseSeeder extends Seeder
     {
         // User::factory(10)->create();
 
-        User::factory()->create([
-            'name' => 'Test User',
-            'email' => 'test@example.com',
+        \App\Models\User::factory()->create([
+            'name' => 'Easia',
+            'email' => 'easia@easia.com',
+            'password' => bcrypt('easia'),
+            'level' => 1,
+            'tenant_host' => '127.0.0.1',
+            'tenant_database' => 'easia_tenant',
+            'tenant_username' => 'root',
+            'tenant_password' => '_brUce80!'
         ]);
     }
 }

+ 1 - 1
resources/views/layouts/admin.blade.php

@@ -32,7 +32,7 @@
 		<div class="loader-wrapper">
 			<div class="loader"><span></span><span></span><span></span><span></span><span></span></div>
 		</div>
-
+		
 		{{ $slot }}
 
 		@livewireScripts

+ 12 - 0
resources/views/livewire/company.blade.php

@@ -0,0 +1,12 @@
+<div>
+    COMPANY
+    <br>
+    {{$name}}
+    <br><br>
+    <livewire:company-service :company="$current_company"/>
+    <br><br>
+    <livewire:company-rate :company="$current_company"/>
+    <br><br>
+    <livewire:company-activity :company="$current_company"/>
+    <br><br>
+</div>

+ 34 - 0
resources/views/livewire/company_activity.blade.php

@@ -0,0 +1,34 @@
+<div>
+    COMPANY activity
+    <br>    
+    @if($is_edit)
+        Nome<br>
+        <input type="text" wire:model="name"><br>
+        @error('name')
+            {{ $message }}
+        @enderror
+        <br>
+        Descrizione<br>
+        <input type="text" wire:model="description"><br><br>
+        Enable<br>
+        <input type="checkbox" wire:model="enabled"><br><br>
+        <a wire:click="save()">Salva</a>
+        <a wire:click="cancel()">Annulla</a>
+    @else
+        <table border="1">
+            <tr>
+                <td>Nome</td>
+                <td>
+
+                </td>
+            </tr>
+            @foreach($company_activities as $c)
+                <tr>
+                    <td>{{$c->name}}</td>
+                    <td><a wire:click="edit({{$c->id}})">Modifica</a></td>
+                </tr>
+            @endforeach
+        </table>
+        <a wire:click="add()">Aggiungi</a>
+    @endif
+</div>

+ 4 - 0
resources/views/livewire/company_rate.blade.php

@@ -0,0 +1,4 @@
+<div>
+    COMPANY rate
+    <br>    
+</div>

+ 4 - 0
resources/views/livewire/company_service.blade.php

@@ -0,0 +1,4 @@
+<div>
+    COMPANY service
+    <br>    
+</div>

+ 6 - 0
resources/views/livewire/dashboard.blade.php

@@ -0,0 +1,6 @@
+<div>
+    DASHBOARD
+    <ul>
+        <li><a href="{{ route('company') }}">Company</li>
+    </ul>
+</div>

+ 11 - 5
resources/views/livewire/login.blade.php

@@ -6,19 +6,25 @@
                     <div class="login-main bg-primary d-flex justify-content-center">
                         <div class="login-inner w-100">
                             <img class="d-block img-fluid m-auto mb-5 form-logo" src="/assets/images/logo_white.png" alt="logo" />
-                            <form class="theme-form" name="login" method="POST" action="#">
+                            
                                 <div class="row">
                                     <div class="col-md-12 mb-3">
                                         <div class="form-group">
                                             <label for="email">Email</label>
-                                            <input class="form-control input-white" id="email" name="email" type="email" required="" placeholder="Inserisci" />
+                                            <input class="form-control input-white @error('email') is-invalid @enderror" id="email" name="email" type="email" required="" placeholder="Inserisci" wire:model="email" />
+                                            @error('email')
+                                                <div class="invalid-feedback">{{ $message }}</div>
+                                            @enderror
                                         </div>
                                     </div>
                                     <div class="col-md-12 mb-3">
                                         <div class="form-group">
                                             <label for="password">Password</label>
                                             <div class="form-input position-relative">
-                                                <input class="form-control input-white" id="password" name="password" type="password" required="" placeholder="Inserisci" />
+                                                <input class="form-control input-white @error('password') is-invalid @enderror" id="password" name="password" type="password" required="" placeholder="Inserisci" wire:model="password" />
+                                                @error('password')
+                                                    <div class="invalid-feedback">{{ $message }}</div>
+                                                @enderror
                                                 <div class="show-hide"><span class="show text-white"> </span></div>
                                             </div>
                                             <a class="link text-secondary d-inline-block mt-2 f-w-300" href="/forget-password">Hai dimenticato la password?</a>
@@ -31,13 +37,13 @@
                                 </div>
                                 <div class="form-group mb-0 checkbox-checked">
                                     <div class="text-center mt-4">
-                                        <button class="btn btn-secondary btn-block text-uppercase fw-bold btn-large" type="submit">Accedi</button>
+                                        <button class="btn btn-secondary btn-block text-uppercase fw-bold btn-large" type="button" wire:click="login()">Accedi</button>
                                     </div>
                                 </div>
                                 <div class="text-center mt-3">
                                     <a class="text-secondary text-uppercase text-underline fw-bold" href="/registration">Registrati</a>
                                 </div>
-                            </form>
+                            
                         </div>
                     </div>
                 </div>

+ 15 - 1
routes/web.php

@@ -1,8 +1,22 @@
 <?php
 
 use Illuminate\Support\Facades\Route;
+use App\Http\Middleware\TenantMiddleware;
 
 Route::get('/', \App\Livewire\Index::class);
 Route::get('/login', \App\Livewire\Login::class);
 Route::get('/registration', \App\Livewire\Registration::class);
-Route::get('/onboarding', \App\Livewire\Onboarding::class);
+Route::get('/onboarding', \App\Livewire\Onboarding::class);
+
+//Route::group(['middleware' => 'auth'], function () {
+Route::middleware([TenantMiddleware::class])->group(function () {
+
+    Route::group(['prefix'=>'admin'],function (){
+
+        Route::get('/dashboard', \App\Livewire\Dashboard::class)->name('dashboard');
+        Route::get('/company', \App\Livewire\Company::class)->name('company');
+        //Route::get('/company_service', \App\Livewire\CompanyService::class)->name('company_service');
+
+    });
+
+});