Bladeren bron

patment_methods - aggiunto origine/destinazione + modifica corrispettivo fiscale entrate

ferrari 1 maand geleden
bovenliggende
commit
d36afa27c4

+ 13 - 7
app/Http/Livewire/PaymentMethod.php

@@ -6,9 +6,10 @@ use Livewire\Component;
 
 
 class PaymentMethod extends Component
 class PaymentMethod extends Component
 {
 {
-    public $records, $name, $enabled, $money, $type, $corrispettivo_fiscale, $dataId, $bank_id, $update = false, $add = false;
+    public $records, $name, $enabled, $money, $type, $corrispettivo_fiscale, $dataId, $origin_id, $destination_id, $update = false, $add = false;
 
 
-    public $banks = array();
+    public $origins = [];
+    public $destinations = [];
 
 
     protected $rules = [
     protected $rules = [
         'name' => 'required'
         'name' => 'required'
@@ -47,7 +48,8 @@ class PaymentMethod extends Component
         if(\Auth::user()->level != env('LEVEL_ADMIN', 0))
         if(\Auth::user()->level != env('LEVEL_ADMIN', 0))
             return redirect()->to('/dashboard');
             return redirect()->to('/dashboard');
 
 
-        $this->banks = \App\Models\Bank::select('id', 'name')->get();
+        $this->origins = \App\Models\Bank::select('id', 'name')->where('enabled', true)->whereIn('visibility', ['OUT', 'ALL'])->get();
+        $this->destinations = \App\Models\Bank::select('id', 'name')->where('enabled', true)->whereIn('visibility', ['IN', 'ALL'])->get();
     }
     }
 
 
     public function render()
     public function render()
@@ -55,7 +57,8 @@ class PaymentMethod extends Component
         $this->records = \App\Models\PaymentMethod::all();
         $this->records = \App\Models\PaymentMethod::all();
         foreach($this->records as $r)
         foreach($this->records as $r)
         {
         {
-            $r->bank = $r->bank ? $r->bank->name : '';
+            $r->origin = $r->origin ? $r->origin->name : '';
+            $r->destination = $r->destination ? $r->destination->name : '';
         }
         }
         /*if ($this->sortAsc)
         /*if ($this->sortAsc)
             $this->records = $this->records->sortBy($this->sortField);
             $this->records = $this->records->sortBy($this->sortField);
@@ -77,7 +80,8 @@ class PaymentMethod extends Component
         try {
         try {
             \App\Models\PaymentMethod::create([
             \App\Models\PaymentMethod::create([
                 'name' => $this->name,
                 'name' => $this->name,
-                'bank_id' => $this->bank_id,
+                'origin_id' => $this->origin_id != "" ? $this->origin_id : null,
+                'destination_id' => $this->destination_id != "" ? $this->destination_id : null,
                 'money' => $this->money,
                 'money' => $this->money,
                 'type' => $this->type,
                 'type' => $this->type,
                 'corrispettivo_fiscale' => $this->corrispettivo_fiscale,
                 'corrispettivo_fiscale' => $this->corrispettivo_fiscale,
@@ -102,7 +106,8 @@ class PaymentMethod extends Component
                 $this->corrispettivo_fiscale = $payment_method->corrispettivo_fiscale;
                 $this->corrispettivo_fiscale = $payment_method->corrispettivo_fiscale;
                 $this->money = $payment_method->money;
                 $this->money = $payment_method->money;
                 $this->type = $payment_method->type;
                 $this->type = $payment_method->type;
-                $this->bank_id = $payment_method->bank_id;
+                $this->origin_id = $payment_method->origin_id;
+                $this->destination_id = $payment_method->destination_id;
                 $this->dataId = $payment_method->id;
                 $this->dataId = $payment_method->id;
                 $this->update = true;
                 $this->update = true;
                 $this->add = false;
                 $this->add = false;
@@ -118,7 +123,8 @@ class PaymentMethod extends Component
         try {
         try {
             \App\Models\PaymentMethod::whereId($this->dataId)->update([
             \App\Models\PaymentMethod::whereId($this->dataId)->update([
                 'name' => $this->name,
                 'name' => $this->name,
-                'bank_id' => $this->bank_id,
+                'origin_id' => $this->origin_id != "" ? $this->origin_id : null,
+                'destination_id' => $this->destination_id != "" ? $this->destination_id : null,
                 'money' => $this->money,
                 'money' => $this->money,
                 'type' => $this->type,
                 'type' => $this->type,
                 'corrispettivo_fiscale' => $this->corrispettivo_fiscale,
                 'corrispettivo_fiscale' => $this->corrispettivo_fiscale,

+ 30 - 0
app/Http/Livewire/RecordIN.php

@@ -68,6 +68,7 @@ class RecordIN extends Component
     $commercial, $update = false, $add = false;
     $commercial, $update = false, $add = false;
 
 
     public $corrispettivo = [];
     public $corrispettivo = [];
+    public $corrispettivo_destination = [];
 
 
     public $currentReceip;
     public $currentReceip;
 
 
@@ -162,9 +163,25 @@ class RecordIN extends Component
 
 
     public function updatedPaymentMethodId() {
     public function updatedPaymentMethodId() {
         //$this->emit('refresh');
         //$this->emit('refresh');
+
+        if ($this->payment_method_id) {
+            $payment_method = \App\Models\PaymentMethod::findOrFail($this->payment_method_id);
+            $this->destination_id = $payment_method->destination_id ?? null;
+        }
+
         $this->canSave = $this->checkCanSave();
         $this->canSave = $this->checkCanSave();
     }
     }
 
 
+    public function updatedCorrispettivoFiscale() {
+        if ($this->corrispettivo_fiscale) {
+            foreach ($this->payments as $payment) {
+                if ($payment->corrispettivo_fiscale) {
+                    $this->corrispettivo_destination[$payment->id] = $payment->destination_id;
+                }
+            }
+        }
+    }
+
     public function updatedAmount() {
     public function updatedAmount() {
         // $this->emit('refresh');
         // $this->emit('refresh');
         $this->canSave = $this->checkCanSave();
         $this->canSave = $this->checkCanSave();
@@ -268,6 +285,7 @@ class RecordIN extends Component
         $this->rows = array();
         $this->rows = array();
         $this->rows[] = array('causal_id' => isset($_GET["causalId"]) ? $_GET["causalId"] : null, 'when' => array(array('month' => date("n"), 'year' => date("Y"), 'period' => '')),  'amount' => null, 'vat_id' => null, 'note' => '', 'commercial' => 0);
         $this->rows[] = array('causal_id' => isset($_GET["causalId"]) ? $_GET["causalId"] : null, 'when' => array(array('month' => date("n"), 'year' => date("Y"), 'period' => '')),  'amount' => null, 'vat_id' => null, 'note' => '', 'commercial' => 0);
         $this->corrispettivo = [];
         $this->corrispettivo = [];
+        $this->corrispettivo_destination = [];
         $this->emit('load-data-table');
         $this->emit('load-data-table');
     }
     }
 
 
@@ -311,6 +329,16 @@ class RecordIN extends Component
         return $ret;
         return $ret;
     }
     }
 
 
+    public function getBankName($bank_id)
+    {
+        $ret = '';
+        if ($bank_id > 0)
+        {
+            $ret = \App\Models\Bank::findOrFail($bank_id)->name;
+        }
+        return $ret;
+    }
+
     function buildTree($records, $parentId = 0) {
     function buildTree($records, $parentId = 0) {
         $this->causals = array();
         $this->causals = array();
 
 
@@ -523,6 +551,7 @@ class RecordIN extends Component
             if ($p->corrispettivo_fiscale)
             if ($p->corrispettivo_fiscale)
             {
             {
                 $price = isset($this->corrispettivo[$p->id]) ? $this->currencyToDouble($this->corrispettivo[$p->id]) : 0;
                 $price = isset($this->corrispettivo[$p->id]) ? $this->currencyToDouble($this->corrispettivo[$p->id]) : 0;
+                $destination_id = isset($this->corrispettivo_destination[$p->id]) ? $this->corrispettivo_destination[$p->id] : null;
 
 
                 if ($price > 0)
                 if ($price > 0)
                 {
                 {
@@ -531,6 +560,7 @@ class RecordIN extends Component
                         'member_id' => $this->member_id,
                         'member_id' => $this->member_id,
                         'supplier_id' => null,
                         'supplier_id' => null,
                         'payment_method_id' => $p->id,
                         'payment_method_id' => $p->id,
+                        'destination_id' => $destination_id,
                         'commercial' => $this->commercial,
                         'commercial' => $this->commercial,
                         'corrispettivo_fiscale' => $this->corrispettivo_fiscale,
                         'corrispettivo_fiscale' => $this->corrispettivo_fiscale,
                         'date' => $this->date,
                         'date' => $this->date,

+ 7 - 0
app/Http/Livewire/RecordOUT.php

@@ -163,6 +163,13 @@ class RecordOUT extends Component
         $this->banks = \App\Models\Bank::select('id', 'name')->where('enabled', true)->whereIn('visibility', array('ALL', 'OUT'))->orderBy('name')->get();
         $this->banks = \App\Models\Bank::select('id', 'name')->where('enabled', true)->whereIn('visibility', array('ALL', 'OUT'))->orderBy('name')->get();
     }
     }
 
 
+    public function updatedPaymentMethodId() {
+        if ($this->payment_method_id) {
+            $payment_method = \App\Models\PaymentMethod::findOrFail($this->payment_method_id);
+            $this->origin_id = $payment_method->origin_id ?? null;
+        }
+    }
+
     public function getCausal($causal)
     public function getCausal($causal)
     {
     {
         $ret = '';
         $ret = '';

+ 1 - 1
app/Models/Bank.php

@@ -19,7 +19,7 @@ class Bank extends Model
 
 
     public function canDelete()
     public function canDelete()
     {
     {
-        return \App\Models\PaymentMethod::where('bank_id', $this->id)->count() == 0;
+        return \App\Models\PaymentMethod::where('origin_id', $this->id)->orWhere('destination_id', $this->id)->count() == 0;
     }
     }
 
 
     public function getVisibility()
     public function getVisibility()

+ 8 - 3
app/Models/PaymentMethod.php

@@ -15,12 +15,17 @@ class PaymentMethod extends Model
         'type',
         'type',
         'corrispettivo_fiscale',
         'corrispettivo_fiscale',
         'enabled',
         'enabled',
-        'bank_id'
+        'origin_id',
+        'destination_id'
     ];
     ];
 
 
-    public function bank()
+    public function origin()
     {
     {
-        return $this->belongsTo(\App\Models\Bank::class);
+        return $this->belongsTo(\App\Models\Bank::class, 'origin_id', 'id');
     }
     }
 
 
+    public function destination()
+    {
+        return $this->belongsTo(\App\Models\Bank::class, 'destination_id', 'id');
+    }
 }
 }

+ 41 - 0
database/migrations/2025_12_10_094113_add_origin_destination_to_payment_methods_table.php

@@ -0,0 +1,41 @@
+<?php
+
+use Illuminate\Database\Migrations\Migration;
+use Illuminate\Database\Schema\Blueprint;
+use Illuminate\Support\Facades\Schema;
+use Illuminate\Support\Facades\DB;
+
+return new class extends Migration
+{
+    public function up()
+    {
+        Schema::table('payment_methods', function (Blueprint $table) {
+            $table->dropForeign('payment_methods_bank_id_foreign');
+        });
+
+        DB::statement('ALTER TABLE `payment_methods` CHANGE `bank_id` `origin_id` BIGINT(20) UNSIGNED NULL');
+
+        Schema::table('payment_methods', function (Blueprint $table) {
+            $table->unsignedBigInteger('destination_id')->nullable()->after('origin_id');
+
+            $table->foreign('origin_id', 'payment_methods_origin_id_foreign')->references('id')->on('banks')->onUpdate('cascade')->onDelete('cascade');
+
+            $table->foreign('destination_id', 'payment_methods_destination_id_foreign')->references('id')->on('banks')->onUpdate('cascade')->onDelete('cascade');
+        });
+    }
+
+    public function down()
+    {
+        Schema::table('payment_methods', function (Blueprint $table) {
+            $table->dropForeign('payment_methods_destination_id_foreign');
+            $table->dropForeign('payment_methods_origin_id_foreign');
+            $table->dropColumn('destination_id');
+        });
+
+        DB::statement('ALTER TABLE `payment_methods`CHANGE `origin_id` `bank_id` BIGINT(20) UNSIGNED NULL');
+
+        Schema::table('payment_methods', function (Blueprint $table) {
+            $table->foreign('bank_id', 'payment_methods_bank_id_foreign')->references('id')->on('banks')->onUpdate('cascade')->onDelete('cascade');
+        });
+    }
+};

+ 29 - 14
resources/views/livewire/payment_method.blade.php

@@ -28,7 +28,8 @@
             <table class="table tablesaw tableHead tablesaw-stack" id="tablesaw-350" width="100%">
             <table class="table tablesaw tableHead tablesaw-stack" id="tablesaw-350" width="100%">
                 <thead>
                 <thead>
                     <tr>
                     <tr>
-                        <th scope="col">Banca</th>
+                        <th scope="col">Origine</th>
+                        <th scope="col">Destinazione</th>
                         <th scope="col">Nome</th>
                         <th scope="col">Nome</th>
                         <th scope="col">Tipo</th>
                         <th scope="col">Tipo</th>
                         <th scope="col">Abilitato</th>
                         <th scope="col">Abilitato</th>
@@ -38,7 +39,8 @@
                 <tbody id="checkall-target">
                 <tbody id="checkall-target">
                     @foreach($records as $record)
                     @foreach($records as $record)
                         <tr>
                         <tr>
-                            <td>{{$record->bank ? $record->bank : ''}}</td>
+                            <td>{{$record->origin ? $record->origin : ''}}</td>
+                            <td>{{$record->destination ? $record->destination : ''}}</td>
                             <td>{{$record->name}}</td>
                             <td>{{$record->name}}</td>
                             <td>
                             <td>
                                 @php
                                 @php
@@ -118,18 +120,6 @@
                                     @enderror
                                     @enderror
                                 </div>
                                 </div>
                             </div>
                             </div>
-
-                            <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--
-                                    @foreach($banks as $bank)
-                                        <option value="{{$bank->id}}">{{$bank->name}}
-                                    @endforeach
-                                </select>
-                            </div>
-                        </div>
-                        <div class="row mb-3">
                             <div class="col-md-6">
                             <div class="col-md-6">
                                 <label for="type" class="form-label">Tipologia</label>
                                 <label for="type" class="form-label">Tipologia</label>
                                 <select name="type" class="form-select" aria-label="Seleziona una tipologia" wire:model="type">
                                 <select name="type" class="form-select" aria-label="Seleziona una tipologia" wire:model="type">
@@ -139,6 +129,28 @@
                                 </select>
                                 </select>
                             </div>
                             </div>
                         </div>
                         </div>
+                        <div class="row mb-3">
+
+                            <div class="col">
+                                <label for="origin_id" class="form-label">Origine</label>
+                                <select name="origin_id" class="form-select" aria-label="Seleziona un'origine" wire:model="origin_id">
+                                    <option value="">--Seleziona--
+                                    @foreach($origins as $origin)
+                                        <option value="{{$origin->id}}">{{$origin->name}}
+                                    @endforeach
+                                </select>
+                            </div>
+
+                            <div class="col">
+                                <label for="destination_id" class="form-label">Destinazione</label>
+                                <select name="destination_id" class="form-select" aria-label="Seleziona una destinazione" wire:model="destination_id">
+                                    <option value="">--Seleziona--
+                                    @foreach($destinations as $destination)
+                                        <option value="{{$destination->id}}">{{$destination->name}}
+                                    @endforeach
+                                </select>
+                            </div>
+                        </div>
 
 
                         <div class="form--item mb-3">
                         <div class="form--item mb-3">
                             <div class="form--item">
                             <div class="form--item">
@@ -210,6 +222,9 @@
                 thead: {
                 thead: {
                 'th': {'background-color': 'blue'}
                 'th': {'background-color': 'blue'}
                 },
                 },
+                order: [
+                    [2, 'asc']
+                ],
                 layout: {
                 layout: {
                     topStart : null,
                     topStart : null,
                     topEnd : null,
                     topEnd : null,

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

@@ -282,9 +282,12 @@
 
 
                             @if ($this->dataId > 0)
                             @if ($this->dataId > 0)
                                 <div class="row">
                                 <div class="row">
-                                    <div class="col-md-9 mt-3">
+                                    <div class="col-md-6 mt-3">
                                         {{$this->getPaymentMethod($payment_method_id)}}
                                         {{$this->getPaymentMethod($payment_method_id)}}
                                     </div>
                                     </div>
+                                    <div class="col-md-3 mt-3">
+                                        {{$this->getBankName($destination_id)}}
+                                    </div>
                                     <div class="col-md-3 mt-3">
                                     <div class="col-md-3 mt-3">
                                         {{formatPrice($amount)}}
                                         {{formatPrice($amount)}}
                                     </div>
                                     </div>
@@ -293,9 +296,17 @@
                                 @foreach($payments as $payment)
                                 @foreach($payments as $payment)
                                     @if($payment->corrispettivo_fiscale)
                                     @if($payment->corrispettivo_fiscale)
                                         <div class="row">
                                         <div class="row">
-                                            <div class="col-md-9 mt-3">
+                                            <div class="col-md-6 mt-3">
                                                 {{$payment->name}}
                                                 {{$payment->name}}
                                             </div>
                                             </div>
+                                            <div class="col-md-3 mt-3">                                                
+                                                <select id="corrispettivo_destination_{{$payment->id}}" name="corrispettivo_destination_{{$payment->id}}" wire:model="corrispettivo_destination.{{$payment->id}}" class="form-select" aria-label="Seleziona una destinazione" style="width:100%">
+                                                    <option value="">--Seleziona--
+                                                    @foreach($banks as $bank)
+                                                        <option value="{{$bank->id}}">{{$bank->name}}
+                                                    @endforeach
+                                                </select>
+                                            </div>
                                             <div class="col-md-3 mt-3">
                                             <div class="col-md-3 mt-3">
                                                 <input type="text" class="form-control totalInput text-end" id="corrispettivo_{{$payment->id}}" wire:model="corrispettivo.{{$payment->id}}" onkeyup="onlyNumberAmount(this)" placeholder="€ 0,00">
                                                 <input type="text" class="form-control totalInput text-end" id="corrispettivo_{{$payment->id}}" wire:model="corrispettivo.{{$payment->id}}" onkeyup="onlyNumberAmount(this)" placeholder="€ 0,00">
                                             </div>
                                             </div>