Просмотр исходного кода

causali e metodi nascosti, supllier anonimizzati

FabioFratini 7 месяцев назад
Родитель
Сommit
f666178913

+ 100 - 33
app/Http/Livewire/Causal.php

@@ -5,6 +5,7 @@ namespace App\Http\Livewire;
 use Illuminate\Support\Facades\Auth;
 use Livewire\Component;
 use App\Http\Middleware\TenantMiddleware;
+
 class Causal extends Component
 {
     public $recordsIn, $recordsOut, $parent_id,  $name, $enabled, $corrispettivo_fiscale, $no_receipt, $money, $user_status, $no_first, $no_records, $type, $dataId, $update = false, $add = false;
@@ -12,6 +13,7 @@ class Causal extends Component
     public $corrispettivo_causal_id = 0;
 
     public $parent = '';
+    public $showHidden = false;
 
     protected $rules = [
         'name' => 'required',
@@ -21,22 +23,92 @@ class Causal extends Component
     protected $messages = [
         'name.required' => 'Il nome è obbligatorio'
     ];
+
     public function boot()
     {
         app(TenantMiddleware::class)->setupTenantConnection();
     }
-    public function mount(){
 
-        if(Auth::user()->level != env('LEVEL_ADMIN', 0))
-            return redirect()->to('/dashboard');
+    public function mount()
+    {
+        $this->loadRecords();
+    }
 
-        $fisc = \App\Models\Causal::where('corrispettivo_fiscale', true)->first();
-        if ($fisc)
-            $this->corrispettivo_causal_id = $fisc->id;
+    public function hide($id)
+    {
+        try {
+            \App\Models\Causal::whereId($id)->update(['hidden' => true]);
+            session()->flash('success', 'Causale nascosta');
+            $this->loadRecords(); // Refresh the data
+        } catch (\Exception $ex) {
+            session()->flash('error', 'Errore (' . $ex->getMessage() . ')');
+        }
+    }
 
+    public function show($id)
+    {
+        try {
+            \App\Models\Causal::whereId($id)->update(['hidden' => false]);
+            session()->flash('success', 'Causale ripristinata');
+            $this->loadRecords(); // Refresh the data
+        } catch (\Exception $ex) {
+            session()->flash('error', 'Errore (' . $ex->getMessage() . ')');
+        }
     }
 
-    public function resetFields(){
+    public function toggleHidden()
+    {
+        $this->showHidden = !$this->showHidden;
+        $this->loadRecords();
+    }
+
+    public function loadRecords()
+    {
+        if ($this->showHidden) {
+            // Show all records including hidden ones
+            $this->recordsIn = \App\Models\Causal::where('type', 'IN')
+                ->where('parent_id', null)
+                ->with(['childs'])
+                ->orderBy('name')
+                ->get();
+
+            $this->recordsOut = \App\Models\Causal::where('type', 'OUT')
+                ->where('parent_id', null)
+                ->with(['childs'])
+                ->orderBy('name')
+                ->get();
+        } else {
+            // Show only non-hidden records
+            $this->recordsIn = \App\Models\Causal::where('type', 'IN')
+                ->where('parent_id', null)
+                ->where(function ($query) {
+                    $query->where('hidden', false)->orWhereNull('hidden');
+                })
+                ->with(['childs' => function ($query) {
+                    $query->where(function ($q) {
+                        $q->where('hidden', false)->orWhereNull('hidden');
+                    });
+                }])
+                ->orderBy('name')
+                ->get();
+
+            $this->recordsOut = \App\Models\Causal::where('type', 'OUT')
+                ->where('parent_id', null)
+                ->where(function ($query) {
+                    $query->where('hidden', false)->orWhereNull('hidden');
+                })
+                ->with(['childs' => function ($query) {
+                    $query->where(function ($q) {
+                        $q->where('hidden', false)->orWhereNull('hidden');
+                    });
+                }])
+                ->orderBy('name')
+                ->get();
+        }
+    }
+
+    public function resetFields()
+    {
         $this->name = '';
         $this->parent_id = null;
         $this->parent = '';
@@ -52,8 +124,12 @@ class Causal extends Component
 
     public function render()
     {
-        $this->recordsIn = \App\Models\Causal::where('parent_id', null)->where('type', 'IN')->get();
-        $this->recordsOut = \App\Models\Causal::where('parent_id', null)->where('type', 'OUT')->get();
+        // Remove the duplicate queries - loadRecords() already handles this
+        // and make sure it respects the showHidden state
+        if (!isset($this->recordsIn) || !isset($this->recordsOut)) {
+            $this->loadRecords();
+        }
+
         return view('livewire.causal');
     }
 
@@ -91,19 +167,21 @@ class Causal extends Component
                 'no_records' => $this->no_records,
                 'enabled' => $this->enabled
             ]);
-            session()->flash('success','Causale creata');
+            session()->flash('success', 'Causale creata');
             $this->resetFields();
             $this->add = false;
+            $this->loadRecords();
         } catch (\Exception $ex) {
-            session()->flash('error','Errore (' . $ex->getMessage() . ')');
+            session()->flash('error', 'Errore (' . $ex->getMessage() . ')');
         }
     }
 
-    public function edit($id){
+    public function edit($id)
+    {
         try {
             $causal = \App\Models\Causal::findOrFail($id);
-            if( !$causal) {
-                session()->flash('error','Causale non trovata');
+            if (!$causal) {
+                session()->flash('error', 'Causale non trovata');
             } else {
                 $this->name = $causal->name;
                 $this->money = $causal->money;
@@ -112,6 +190,7 @@ class Causal extends Component
                 $this->no_first = $causal->no_first;
                 $this->no_records = $causal->no_records;
                 $this->enabled = $causal->enabled;
+                $this->corrispettivo_fiscale = $causal->corrispettivo_fiscale;
                 $this->type = $causal->type;
                 $this->parent_id = $causal->parent_id;
                 $this->dataId = $causal->id;
@@ -119,7 +198,7 @@ class Causal extends Component
                 $this->add = false;
             }
         } catch (\Exception $ex) {
-            session()->flash('error','Errore (' . $ex->getMessage() . ')');
+            session()->flash('error', 'Errore (' . $ex->getMessage() . ')');
         }
     }
 
@@ -139,11 +218,12 @@ class Causal extends Component
                 'corrispettivo_fiscale' => $this->corrispettivo_fiscale,
                 'enabled' => $this->enabled
             ]);
-            session()->flash('success','Tessera aggiornata');
+            session()->flash('success', 'Causale aggiornata');
             $this->resetFields();
             $this->update = false;
+            $this->loadRecords();
         } catch (\Exception $ex) {
-            session()->flash('error','Errore (' . $ex->getMessage() . ')');
+            session()->flash('error', 'Errore (' . $ex->getMessage() . ')');
         }
     }
 
@@ -154,17 +234,6 @@ class Causal extends Component
         $this->resetFields();
     }
 
-    public function delete($id)
-    {
-        try{
-            \App\Models\Causal::find($id)->delete();
-            session()->flash('success',"Tessera eliminata");
-            return redirect(request()->header('Referer'));
-        }catch(\Exception $e){
-            session()->flash('error','Errore (' . $e->getMessage() . ')');
-        }
-    }
-
     public function duplicate($id)
     {
         $old = \App\Models\Causal::find($id);
@@ -173,25 +242,23 @@ class Causal extends Component
         $new->save();
 
         $this->duplicateRecursive($old, $new);
+        $this->loadRecords(); // Refresh after duplicate
     }
 
     public function duplicateRecursive($old, $new)
     {
-        foreach($old->childs as $c)
-        {
+        foreach ($old->childs as $c) {
             $old1 = \App\Models\Causal::find($c->id);
             $new1 = $old1->replicate();
             $new1->parent_id = $new->id;
             $new1->save();
 
             $this->duplicateRecursive($old1, $new1);
-
         }
     }
 
     public function reorder()
     {
-
+        $this->loadRecords(); // Refresh after reorder
     }
-
 }

+ 59 - 27
app/Http/Livewire/Causals.php

@@ -1,7 +1,10 @@
 <?php
+
 namespace App\Http\Livewire;
+
 use Livewire\Component;
 use App\Http\Middleware\TenantMiddleware;
+
 class Causals extends Component
 {
     public $level_1 = [];
@@ -20,77 +23,106 @@ class Causals extends Component
     {
         app(TenantMiddleware::class)->setupTenantConnection();
     }
+
     public function mount($type, $idx, $causal_id)
     {
         $this->type = $type;
         $this->idx = $idx;
         $this->causal_id = $causal_id;
-        if ($this->causal_id != null)
-        {
+
+        if ($this->causal_id != null) {
             $c = \App\Models\Causal::findOrFail($this->causal_id);
             $ids = array_reverse($c->recursiveParent($c->parent_id, [$c->id]));
-            foreach($ids as $ii => $i)
-            {
-                if ($ii == 0)
-                {
+
+            foreach($ids as $ii => $i) {
+                if ($ii == 0) {
                     $this->level_1_id = $i;
                 }
-                if ($ii == 1)
-                {
+                if ($ii == 1) {
                     $this->level_2_id = $i;
                 }
-                if ($ii == 2)
-                {
+                if ($ii == 2) {
                     $this->level_3_id = $i;
                 }
             }
-
         }
     }
 
-    public function updatedLevel1Id() {
+    public function updatedLevel1Id()
+    {
         $this->emit($this->emit, null, $this->idx);
         $this->level_2_id = 0;
         $this->level_2 = [];
         $this->level_3_id = 0;
         $this->level_3 = [];
     }
-    public function updatedLevel2Id() {
+
+    public function updatedLevel2Id()
+    {
         $this->emit($this->emit, null, $this->idx);
         $this->level_3_id = 0;
         $this->level_3 = [];
     }
-    public function updatedLevel3Id() {
+
+    public function updatedLevel3Id()
+    {
         $this->emit($this->emit, null, $this->idx);
     }
 
     public function render()
     {
         $reset = false;
-        if ($this->level_1_id > 0)
-        {
-            $this->level_2 = \App\Models\Causal::where('parent_id', $this->level_1_id)->where('type', $this->type)->orderBy('name')->get();
-            if (sizeof($this->level_2) == 0)
-            {
+
+        // Build query with visibility filter
+        $visibilityFilter = function($query) {
+            if (!$this->showHidden) {
+                return $query->where('hidden', '!=', true);
+            }
+            return $query;
+        };
+
+        if ($this->level_1_id > 0) {
+            $this->level_2 = \App\Models\Causal::where('parent_id', $this->level_1_id)
+                ->where('type', $this->type)
+                ->where(function($query) use ($visibilityFilter) {
+                    return $visibilityFilter($query);
+                })
+                ->orderBy('name')
+                ->get();
+
+            if (sizeof($this->level_2) == 0) {
                 $this->emit($this->emit, $this->level_1_id, $this->idx);
                 $reset = true;
             }
         }
-        if ($this->level_2_id > 0)
-        {
-            $this->level_3 = \App\Models\Causal::where('parent_id', $this->level_2_id)->where('type', $this->type)->orderBy('name')->get();
-            if (sizeof($this->level_3) == 0)
-            {
+
+        if ($this->level_2_id > 0) {
+            $this->level_3 = \App\Models\Causal::where('parent_id', $this->level_2_id)
+                ->where('type', $this->type)
+                ->where(function($query) use ($visibilityFilter) {
+                    return $visibilityFilter($query);
+                })
+                ->orderBy('name')
+                ->get();
+
+            if (sizeof($this->level_3) == 0) {
                 $this->emit($this->emit, $this->level_2_id, $this->idx);
                 $reset = true;
             }
         }
-        if ($this->level_3_id > 0)
-        {
+
+        if ($this->level_3_id > 0) {
             $this->emit($this->emit, $this->level_3_id, $this->idx);
             $reset = true;
         }
-        $this->level_1 = \App\Models\Causal::where('parent_id', null)->where('type', $this->type)->orderBy('name')->get();
+
+        $this->level_1 = \App\Models\Causal::where('parent_id', null)
+            ->where('type', $this->type)
+            ->where(function($query) use ($visibilityFilter) {
+                return $visibilityFilter($query);
+            })
+            ->orderBy('name')
+            ->get();
 
         return view('livewire.causals');
     }

+ 43 - 24
app/Http/Livewire/PaymentMethod.php

@@ -4,11 +4,13 @@ namespace App\Http\Livewire;
 use Livewire\Component;
 use Illuminate\Support\Facades\Auth;
 use App\Http\Middleware\TenantMiddleware;
+
 class PaymentMethod extends Component
 {
     public $records, $name, $enabled, $money, $type, $corrispettivo_fiscale, $dataId, $bank_id, $update = false, $add = false;
     public $paymentMethods = [];
     public $banks = array();
+    public $showHidden = false;
 
     protected $rules = [
         'name' => 'required'
@@ -20,14 +22,15 @@ class PaymentMethod extends Component
 
     public $sortField ='name';
     public $sortAsc = true;
+
     public function boot()
     {
         app(TenantMiddleware::class)->setupTenantConnection();
     }
+
     public function sortBy($field)
     {
-        if($this->sortField === $field)
-        {
+        if($this->sortField === $field) {
             $this->sortAsc = ! $this->sortAsc;
         } else {
             $this->sortAsc = true;
@@ -46,26 +49,53 @@ class PaymentMethod extends Component
     }
 
     public function mount(){
-
         if(Auth::user()->level != env('LEVEL_ADMIN', 0))
             return redirect()->to('/dashboard');
 
-            $this->banks = \App\Models\Bank::select('id', 'name')->get();
+        $this->banks = \App\Models\Bank::select('id', 'name')->get();
+
+        $this->loadPaymentMethodOptions();
+    }
+
+    public function hide($id)
+    {
+        try {
+            \App\Models\PaymentMethod::whereId($id)->update(['hidden' => true]);
+            session()->flash('success', 'Metodo pagamento nascosto');
+        } catch (\Exception $ex) {
+            session()->flash('error', 'Errore (' . $ex->getMessage() . ')');
+        }
+    }
+
+    public function show($id)
+    {
+        try {
+            \App\Models\PaymentMethod::whereId($id)->update(['hidden' => false]);
+            session()->flash('success', 'Metodo pagamento ripristinato');
+        } catch (\Exception $ex) {
+            session()->flash('error', 'Errore (' . $ex->getMessage() . ')');
+        }
+    }
 
-            // Load predefined payment methods from database
-            $this->loadPaymentMethodOptions();    }
+    public function toggleShowHidden()
+    {
+        $this->showHidden = !$this->showHidden;
+    }
 
     public function render()
     {
-        $this->records = \App\Models\PaymentMethod::all();
-        foreach($this->records as $r)
-        {
+        if ($this->showHidden) {
+            $this->records = \App\Models\PaymentMethod::all();
+        } else {
+            $this->records = \App\Models\PaymentMethod::where(function ($query) {
+                $query->where('hidden', false)->orWhereNull('hidden');
+            })->get();
+        }
+
+        foreach($this->records as $r) {
             $r->bank = $r->bank ? $r->bank->name : '';
         }
-        /*if ($this->sortAsc)
-            $this->records = $this->records->sortBy($this->sortField);
-        else
-            $this->records = $this->records->sortByDesc($this->sortField);*/
+
         return view('livewire.payment_method');
     }
 
@@ -144,17 +174,6 @@ class PaymentMethod extends Component
         $this->resetFields();
     }
 
-    public function delete($id)
-    {
-        try{
-            \App\Models\PaymentMethod::find($id)->delete();
-            session()->flash('success',"Metodo pagamento eliminato");
-            return redirect(request()->header('Referer'));
-        }catch(\Exception $e){
-            session()->flash('error','Errore (' . $e->getMessage() . ')');
-        }
-    }
-
     protected function loadPaymentMethodOptions()
     {
         $this->paymentMethods = [

+ 29 - 6
app/Http/Livewire/Supplier.php

@@ -27,7 +27,6 @@ class Supplier extends Component
         'fiscal_code.unique' => 'Un fornitore con questo Codice Fiscale esiste già'
     ];
 
-
     public function resetFields()
     {
         $this->name = '';
@@ -67,7 +66,6 @@ class Supplier extends Component
 
     public function mount()
     {
-
         if (Auth::user()->level != env('LEVEL_ADMIN', 0))
             return redirect()->to('/dashboard');
 
@@ -82,6 +80,7 @@ class Supplier extends Component
             $this->showReset = true;
         }
     }
+
     public function resetSearch()
     {
         $this->showReset = false;
@@ -119,6 +118,7 @@ class Supplier extends Component
         $this->vat = trim($this->vat) === '' ? null : trim($this->vat);
         $this->fiscal_code = trim($this->fiscal_code) === '' ? null : trim($this->fiscal_code);
     }
+
     public function store()
     {
         $this->validate();
@@ -229,11 +229,35 @@ class Supplier extends Component
         $this->resetFields();
     }
 
-    public function delete($id)
+    // Replace delete method with anonymize method
+    public function anonymize($id)
     {
         try {
-            \App\Models\Supplier::find($id)->delete();
-            session()->flash('success', "Fornitore eliminato");
+            $supplier = \App\Models\Supplier::findOrFail($id);
+
+            // Anonymize all fields
+            $supplier->update([
+                'name' => 'Fornitore Anonimizzato',
+                'fiscal_code' => null,
+                'vat' => null,
+                'address' => null,
+                'zip_code' => null,
+                'nation_id' => null,
+                'province_id' => null,
+                'city_id' => null,
+                'referent' => null,
+                'website' => null,
+                'phone' => null,
+                'email' => null,
+                'referent_first_name' => null,
+                'referent_last_name' => null,
+                'referent_email' => null,
+                'referent_phone' => null,
+                'referent_mobile' => null,
+                'enabled' => false // Also disable the supplier
+            ]);
+
+            session()->flash('success', "Fornitore anonimizzato");
             return redirect(request()->header('Referer'));
         } catch (\Exception $e) {
             session()->flash('error', 'Errore (' . $e->getMessage() . ')');
@@ -276,7 +300,6 @@ class Supplier extends Component
         ];
     }
 
-    // Updated update method
     public function update()
     {
         // Clean empty fields first

+ 1 - 0
app/Models/Causal.php

@@ -13,6 +13,7 @@ class Causal extends Model
         'parent_id',
         'name',
         'type',
+        'hidden',
         'money',
         'corrispettivo_fiscale',
         'no_receipt',

+ 1 - 0
app/Models/PaymentMethod.php

@@ -13,6 +13,7 @@ class PaymentMethod extends Model
         'name',
         'money',
         'type',
+        'hidden',
         'corrispettivo_fiscale',
         'enabled',
         'bank_id'

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

@@ -0,0 +1,34 @@
+<?php
+
+use App\Database\Migrations\TenantMigration;
+use Illuminate\Database\Migrations\Migration;
+use Illuminate\Database\Schema\Blueprint;
+use Illuminate\Support\Facades\Schema;
+
+return new class extends TenantMigration
+{
+    /**
+     * Run the migrations.
+     *
+     * @return void
+     */
+    public function up()
+    {
+        Schema::table('causals', function (Blueprint $table) {
+            $table->boolean('hidden')->default(false)->after('type');
+            $table->index('hidden'); // Add index for better performance
+        });
+    }
+
+    /**
+     * Reverse the migrations.
+     *
+     * @return void
+     */
+    public function down()
+    {
+        Schema::table('causals', function (Blueprint $table) {
+            $table->dropColumn('hidden');
+        });
+    }
+};

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

@@ -0,0 +1,34 @@
+<?php
+
+use App\Database\Migrations\TenantMigration;
+use Illuminate\Database\Migrations\Migration;
+use Illuminate\Database\Schema\Blueprint;
+use Illuminate\Support\Facades\Schema;
+
+return new class extends TenantMigration
+{
+    /**
+     * Run the migrations.
+     *
+     * @return void
+     */
+    public function up()
+    {
+        Schema::table('payment_methods', function (Blueprint $table) {
+            $table->boolean('hidden')->default(false)->after('type');
+            $table->index('hidden');
+        });
+    }
+
+    /**
+     * Reverse the migrations.
+     *
+     * @return void
+     */
+    public function down()
+    {
+        Schema::table('payment_methods', function (Blueprint $table) {
+            $table->dropColumn('hidden');
+        });
+    }
+};

+ 29 - 5
resources/views/livewire/causal.blade.php

@@ -25,7 +25,15 @@
             <div class="compare--chart_wrapper d-none"></div>
 
             <h1>Entrata</h1>
-
+            <div class="mb-3">
+                <button type="button" class="btn btn-outline-secondary btn-sm" wire:click="toggleHidden()">
+                    @if($showHidden)
+                        <i class="fa-regular fa-eye-slash"></i> Nascondi elementi nascosti
+                    @else
+                        <i class="fa-regular fa-eye"></i> Mostra elementi nascosti
+                    @endif
+                </button>
+            </div>
             <table class="table tablesaw tableHead tablesaw-stack" id="tablesaw-350" width="100%">
                 <thead>
                     <tr>
@@ -45,7 +53,11 @@
                                 <button type="button" class="btn btn-outline-success btn-sm" wire:click="addLevel({{ $record->id }})">Aggiungi livello</button>
                                 <button type="button" class="btn btn-outline-success btn-sm" wire:click="duplicate({{ $record->id }})">Duplica</button>
                                 <button type="button" class="btn" wire:click="edit({{ $record->id }})" data-bs-toggle="popover"  data-bs-trigger="hover focus" data-bs-placement="bottom" data-bs-content="Modifica"><i class="fa-regular fa-pen-to-square"></i></button>
-                                <button type="button" class="btn" onclick="confirm('Sei sicuro?') || event.stopImmediatePropagation()" wire:click="delete({{ $record->id }})" data-bs-toggle="popover" data-bs-trigger="hover focus" data-bs-placement="bottom" data-bs-content="Elimina"><i class="fa-regular fa-trash-can"></i></button>
+                                @if($record->hidden)
+                                    <button type="button" class="btn btn-success" wire:click="show({{ $record->id }})" data-bs-toggle="popover" data-bs-trigger="hover focus" data-bs-placement="bottom" data-bs-content="Ripristina"><i class="fa-regular fa-eye"></i></button>
+                                @else
+                                    <button type="button" class="btn btn-warning" onclick="confirm('Sei sicuro di voler nascondere questo elemento?') || event.stopImmediatePropagation()" wire:click="hide({{ $record->id }})" data-bs-toggle="popover" data-bs-trigger="hover focus" data-bs-placement="bottom" data-bs-content="Nascondi"><i class="fa-regular fa-eye-slash"></i></button>
+                                @endif
                             </td>
                         </tr>
                         @if(count($record->childs))
@@ -58,7 +70,15 @@
 
             <br>
             <h1>Uscita</h1>
-
+            <div class="mb-3">
+                <button type="button" class="btn btn-outline-secondary btn-sm" wire:click="toggleHidden()">
+                    @if($showHidden)
+                        <i class="fa-regular fa-eye-slash"></i> Nascondi elementi nascosti
+                    @else
+                        <i class="fa-regular fa-eye"></i> Mostra elementi nascosti
+                    @endif
+                </button>
+            </div>
             <table class="table tablesaw tableHead tablesaw-stack" id="tablesaw-350" width="100%">
                 <thead>
                     <tr>
@@ -86,8 +106,12 @@
                                 <button type="button" class="btn btn-outline-success btn-sm" wire:click="addLevel({{ $record->id }})">Aggiungi livello</button>
                                 <button type="button" class="btn btn-outline-success btn-sm" wire:click="duplicate({{ $record->id }})">Duplica</button>
                                 <button type="button" class="btn" wire:click="edit({{ $record->id }})" data-bs-toggle="popover" data-bs-trigger="hover focus" data-bs-placement="bottom" data-bs-content="Modifica"><i class="fa-regular fa-pen-to-square"></i></button>
-                                <button type="button" class="btn" onclick="confirm('Sei sicuro?') || event.stopImmediatePropagation()" wire:click="delete({{ $record->id }})" data-bs-toggle="popover" data-bs-trigger="hover focus" data-bs-placement="bottom" data-bs-content="Elimina"><i class="fa-regular fa-trash-can"></i></button>
-                            </td>
+                                @if($record->hidden)
+                                    <button type="button" class="btn btn-success" wire:click="show({{ $record->id }})" data-bs-toggle="popover" data-bs-trigger="hover focus" data-bs-placement="bottom" data-bs-content="Ripristina"><i class="fa-regular fa-eye"></i></button>
+                                @else
+                                    <button type="button" class="btn btn-warning" onclick="confirm('Sei sicuro di voler nascondere questo elemento?') || event.stopImmediatePropagation()" wire:click="hide({{ $record->id }})" data-bs-toggle="popover" data-bs-trigger="hover focus" data-bs-placement="bottom" data-bs-content="Nascondi"><i class="fa-regular fa-eye-slash"></i></button>
+                                @endif
+                                </td>
                         </tr>
                         @if(count($record->childs))
                             @include('livewire/causal_child',['records' => $record->childs, 'indentation' => 1])

+ 26 - 27
resources/views/livewire/causal_child.blade.php

@@ -1,31 +1,30 @@
 @foreach($records as $record)
-    <tr class="record-level-{{$indentation}}">
-        <td>
-            <div class="level-wrapper level-{{$indentation}}">
-                @for ($i = 0; $i < $indentation; $i++)
-                    <span class="level-dot"></span>
-                @endfor
-                <span class="level-indicator">
-                    {{$record->name}}
+    @if($showHidden || (!$record->hidden && $record->hidden !== null))
+        <tr class="record-level-{{ $indentation }}" style="padding-left: {{ $indentation * 20 }}px;">
+            <td style="padding-left: {{ $indentation * 20 }}px;">
+                {{ str_repeat('— ', $indentation) }}{{ $record->name }}
+            </td>
+            <td>{{ $record->type == 'IN' ? 'Entrata' : 'Uscita' }}</td>
+            <td>
+                <span class="badge tessera-badge {{ $record->enabled ? 'active' : 'suspended' }}">
+                    {{ $record->enabled ? 'attivo' : 'disattivo' }}
                 </span>
-            </div>
-        </td>
-        <td>{{$record->type == 'IN' ? 'Entrata' : 'Uscita'}}</td>
-        <td>
-            <span class="tablesaw-cell-content">
-                <span class="badge tessera-badge {{$record->enabled ? 'active' : 'suspended'}}">
-                    {{$record->enabled ? 'attivo' : 'disattivo'}}
-                </span>
-            </span>
-        </td>
-        <td>
-            <button type="button" class="btn btn-outline-success btn-sm" wire:click="addLevel({{ $record->id }})">Aggiungi livello</button>
-            <button type="button" class="btn btn-outline-success btn-sm" wire:click="duplicate({{ $record->id }})">Duplica</button>
-            <button type="button" class="btn" wire:click="edit({{ $record->id }})" data-bs-toggle="popover" data-bs-trigger="hover focus" data-bs-placement="bottom" data-bs-content="Modifica"><i class="fa-regular fa-pen-to-square"></i></button>
-            <button type="button" class="btn" onclick="confirm('Sei sicuro?') || event.stopImmediatePropagation()" wire:click="delete({{ $record->id }})" data-bs-toggle="popover" data-bs-trigger="hover focus" data-bs-placement="bottom" data-bs-content="Elimina"><i class="fa-regular fa-trash-can"></i></button>
-        </td>
-    </tr>
-    @if(count($record->childs))
-        @include('livewire/causal_child',['records' => $record->childs, 'indentation' => $indentation + 1])
+            </td>
+            <td>
+                <button type="button" class="btn btn-outline-success btn-sm" wire:click="addLevel({{ $record->id }})">Aggiungi livello</button>
+                <button type="button" class="btn btn-outline-success btn-sm" wire:click="duplicate({{ $record->id }})">Duplica</button>
+                <button type="button" class="btn btn-sm" wire:click="edit({{ $record->id }})"><i class="fa-regular fa-pen-to-square"></i></button>
+
+                @if($record->hidden)
+                    <button type="button" class="btn btn-success btn-sm" wire:click="show({{ $record->id }})"><i class="fa-regular fa-eye"></i></button>
+                @else
+                    <button type="button" class="btn btn-warning btn-sm" onclick="confirm('Sei sicuro di voler nascondere questo elemento?') || event.stopImmediatePropagation()" wire:click="hide({{ $record->id }})"><i class="fa-regular fa-eye-slash"></i></button>
+                @endif
+            </td>
+        </tr>
+
+        @if(count($record->childs))
+            @include('livewire/causal_child', ['records' => $record->childs, 'indentation' => $indentation + 1])
+        @endif
     @endif
 @endforeach

+ 49 - 43
resources/views/livewire/payment_method.blade.php

@@ -1,7 +1,5 @@
 <div class="col card--ui" id="card--dashboard">
 
-
-
     @if(!$add && !$update)
 
     <header id="title--section" style="display:none !important"  class="d-flex align-items-center justify-content-between">
@@ -25,6 +23,17 @@
         <section id="resume-table">
             <div class="compare--chart_wrapper d-none"></div>
 
+            <!-- Toggle button to show/hide hidden items -->
+            <div class="mb-3 mt-3">
+                <button type="button" class="btn btn-outline-secondary btn-sm" wire:click="toggleShowHidden">
+                    @if($showHidden)
+                        <i class="fa-regular fa-eye-slash"></i> Nascondi elementi nascosti
+                    @else
+                        <i class="fa-regular fa-eye"></i> Mostra elementi nascosti
+                    @endif
+                </button>
+            </div>
+
             <table class="table tablesaw tableHead tablesaw-stack" id="tablesaw-350" width="100%">
                 <thead>
                     <tr>
@@ -37,9 +46,14 @@
                 </thead>
                 <tbody id="checkall-target">
                     @foreach($records as $record)
-                        <tr>
+                        <tr @if(isset($record->hidden) && $record->hidden) style="opacity: 0.6; font-style: italic;" @endif>
                             <td>{{$record->bank ? $record->bank : ''}}</td>
-                            <td>{{$record->name}}</td>
+                            <td>
+                                {{$record->name}}
+                                @if(isset($record->hidden) && $record->hidden)
+                                    <span class="text-muted">(nascosto)</span>
+                                @endif
+                            </td>
                             <td>
                                 @php
                                 switch ($record->type) {
@@ -58,37 +72,16 @@
                             <td> <span class="tablesaw-cell-content"><span class="badge tessera-badge {{$record->enabled ? 'active' : 'suspended'}}">{{$record->enabled ? 'attivo' : 'disattivo'}}</span></span></td>
                             <td>
                                 <button type="button" class="btn" wire:click="edit({{ $record->id }})" data-bs-toggle="popover"  data-bs-trigger="hover focus" data-bs-placement="bottom" data-bs-content="Modifica"><i class="fa-regular fa-pen-to-square"></i></button>
-                                <button type="button" class="btn" onclick="confirm('Sei sicuro?') || event.stopImmediatePropagation()" wire:click="delete({{ $record->id }})" data-bs-toggle="popover" data-bs-trigger="hover focus" data-bs-placement="bottom" data-bs-content="Elimina"><i class="fa-regular fa-trash-can"></i></button>
+                                @if(isset($record->hidden) && $record->hidden)
+                                    <button type="button" class="btn btn-success" wire:click="show({{ $record->id }})" data-bs-toggle="popover" data-bs-trigger="hover focus" data-bs-placement="bottom" data-bs-content="Mostra"><i class="fa-regular fa-eye"></i></button>
+                                @else
+                                    <button type="button" class="btn btn-secondary" onclick="confirm('Sei sicuro di voler nascondere questo metodo di pagamento?') || event.stopImmediatePropagation()" wire:click="hide({{ $record->id }})" data-bs-toggle="popover" data-bs-trigger="hover focus" data-bs-placement="bottom" data-bs-content="Nascondi"><i class="fa-regular fa-eye-slash"></i></button>
+                                @endif
                             </td>
                         </tr>
                     @endforeach
                 </tbody>
             </table>
-            <!--
-            <div class="paginator d-flex justify-content-center">
-                <nav aria-label="Page navigation example">
-                    <ul class="pagination">
-                        <li class="page-item">
-                        <a class="page-link" href="#" aria-label="Previous">
-                            <span aria-hidden="true"></span>
-                        </a>
-                        </li>
-                        <li class="page-item"><a class="page-link" href="#">1</a></li>
-                        <li class="page-item"><a class="page-link" href="#">2</a></li>
-                        <li class="page-item"><a class="page-link" href="#">3</a></li>
-                        <li class="page-item"><a class="page-link" href="#">3</a></li>
-
-                        <li class="page-item"><span class="more-page">...</span></li>
-
-                        <li class="page-item">
-                        <a class="page-link" href="#" aria-label="Next">
-                            <span aria-hidden="true"></span>
-                        </a>
-                        </li>
-                    </ul>
-                    </nav>
-            </div>
-            -->
         </section>
 
     @else
@@ -127,9 +120,9 @@
                             <div class="col">
                                 <label for="bank_id" class="form-label">Banca</label>
                                 <select name="bank_id" class="form-select" aria-label="Seleziona una banca" wire:model="bank_id">
-                                    <option value="">--Seleziona--
+                                    <option value="">--Seleziona--</option>
                                     @foreach($banks as $bank)
-                                        <option value="{{$bank->id}}">{{$bank->name}}
+                                        <option value="{{$bank->id}}">{{$bank->name}}</option>
                                     @endforeach
                                 </select>
                             </div>
@@ -138,18 +131,18 @@
                             <div class="col-md-6">
                                 <label for="type" class="form-label">Tipologia</label>
                                 <select name="type" class="form-select" aria-label="Seleziona una tipologia" wire:model="type">
-                                    <option value="ALL">Entrate/Uscite
-                                    <option value="IN">Entrate
-                                    <option value="OUT">Uscite
+                                    <option value="ALL">Entrate/Uscite</option>
+                                    <option value="IN">Entrate</option>
+                                    <option value="OUT">Uscite</option>
                                 </select>
                             </div>
                         </div>
 
                         <div class="form--item mb-3">
                             <div class="form--item">
-                                    <label for="enabled" class="form-label">Abilitato</label>
-                                    <input class="form-check-input form-control" style="width:22px; height:22px;" type="checkbox" id="enabled" wire:model="enabled">
-                                </div>
+                                <label for="enabled" class="form-label">Abilitato</label>
+                                <input class="form-check-input form-control" style="width:22px; height:22px;" type="checkbox" id="enabled" wire:model="enabled">
+                            </div>
                         </div>
 
                         <div class="form--item mb-3">
@@ -166,8 +159,6 @@
                             </div>
                         </div>
 
-                        <!-- // inline input field -->
-
                         <div class="form--item">
                             <button type="button" class="btn--ui lightGrey" wire:click="cancel()">Annulla</button>
                             @if($add)
@@ -186,6 +177,20 @@
     @endif
 </div>
 
+@if (session()->has('success'))
+    <div class="alert alert-success alert-dismissible fade show mt-3" role="alert">
+        {{ session()->get('success') }}
+        <button type="button" class="btn-close" data-bs-dismiss="alert" aria-label="Close"></button>
+    </div>
+@endif
+
+@if (session()->has('error'))
+    <div class="alert alert-danger alert-dismissible fade show mt-3" role="alert">
+        {{ session()->get('error') }}
+        <button type="button" class="btn-close" data-bs-dismiss="alert" aria-label="Close"></button>
+    </div>
+@endif
+
 @push('scripts')
     <link href="/css/datatables.css" rel="stylesheet" />
     <script src="https://code.jquery.com/jquery-2.2.4.min.js" integrity="sha256-BbhdlvQf/xTY9gja0Dq3HiwQF8LaCRTXxZKRutelT44=" crossorigin="anonymous"></script>
@@ -201,16 +206,17 @@
 
         $(document).ready(function() {
             loadDataTable();
-        } );
+        });
 
         Livewire.on('load-data-table', () => {
             loadDataTable();
         });
 
         function loadDataTable(){
-            if ( $.fn.DataTable.isDataTable('#tablesaw-350') ) {
+            if ($.fn.DataTable.isDataTable('#tablesaw-350')) {
                 $('#tablesaw-350').DataTable().destroy();
             }
+
             $('#tablesaw-350').DataTable({
                 thead: {
                 'th': {'background-color': 'blue'}
@@ -274,7 +280,7 @@
                 $(document).on("click",".addData",function() {
                     $(".title--section_addButton").trigger("click")
                 });
-            } );
+            });
 
         }
 

+ 2 - 13
resources/views/livewire/supplier.blade.php

@@ -1,8 +1,5 @@
-
 <div class="col card--ui" id="card--dashboard">
 
-
-
     <header id="title--section" style="display:none !important"  class="d-flex align-items-center justify-content-between">
         <div class="title--section_name d-flex align-items-center justify-content-between">
             <i class="ico--ui title_section utenti me-2"></i>
@@ -43,7 +40,7 @@
                             <td> <span class="tablesaw-cell-content"><span class="badge tessera-badge {{$record->enabled ? 'active' : 'suspended'}}">{{$record->enabled ? 'attivo' : 'disattivo'}}</span></span></td>
                             <td>
                                 <button type="button" class="btn" wire:click="edit({{ $record->id }})" data-bs-toggle="popover"  data-bs-trigger="hover focus" data-bs-placement="bottom" data-bs-content="Modifica"><i class="fa-regular fa-pen-to-square"></i></button>
-                                <button type="button" class="btn" onclick="confirm('Sei sicuro?') || event.stopImmediatePropagation()" wire:click="delete({{ $record->id }})" data-bs-toggle="popover" data-bs-trigger="hover focus" data-bs-placement="bottom" data-bs-content="Elimina"><i class="fa-regular fa-trash-can"></i></button>
+                                <button type="button" class="btn" onclick="confirm('Sei sicuro di voler archiviare questo fornitore?') || event.stopImmediatePropagation()" wire:click="anonymize({{ $record->id }})" data-bs-toggle="popover" data-bs-trigger="hover focus" data-bs-placement="bottom" data-bs-content="Archivia"><i class="fa-regular fa-folder-closed"></i></button>
                             </td>
                         </tr>
                     @endforeach
@@ -210,7 +207,6 @@
                             <div class="col"></div>
                         </div>
 
-
                         <div class="row mb-3">
                             <div class="col">
                                 <div class="form--item">
@@ -222,10 +218,6 @@
                             </div>
                         </div>
 
-
-
-                        <!-- // inline input field -->
-
                         <div class="form--item">
                             <button type="button" class="btn--ui lightGrey" onclick="annulla()">Annulla</button>
                         @if($add)
@@ -376,9 +368,7 @@
 
         function loadDataTable(){
             if ( $.fn.DataTable.isDataTable('#tablesaw-350') ) {
-                $('#tablesaw-350').DataTable().destroy();
-            }
-            $('#tablesaw-350').DataTable({
+                $('#tablesaw-350').DataTable({
                 thead: {
                 'th': {'background-color': 'blue'}
                 },
@@ -449,4 +439,3 @@
         }
 
     </script>
-@endpush