Explorar el Código

entrate - modificato campo anno in data ricevuta

ferrari hace 3 días
padre
commit
4a398cf67f

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

@@ -63,6 +63,8 @@ class RecordIN extends Component
         $date,
         $month,
         $year,
+        $receipt_date,
+        $data_ricevuta_old = false,
         $type,
         $deleted,
         $financial_movement,
@@ -218,6 +220,12 @@ class RecordIN extends Component
         $this->canSave = $this->checkCanSave();
     }
 
+    public function updatedReceiptDate()
+    {
+        $this->year = date("Y", strtotime($this->receipt_date));
+        $this->data_ricevuta_old = \App\Models\Receipt::where('receipt_date', '>', $this->receipt_date)->exists();
+    }
+
     public function updatedCommercial($value)
     {
         $this->emitSelf('refreshMembers');
@@ -285,6 +293,8 @@ class RecordIN extends Component
         $this->commercial = 0;
         $this->corrispettivo_fiscale = false;
         $this->date = date("Y-m-d");
+        $this->receipt_date = date("Y-m-d");
+        $this->data_ricevuta_old = false;
         $this->year = date("Y");
         $this->type = 'IN';
         $this->deleted = false;
@@ -669,6 +679,7 @@ class RecordIN extends Component
                         'commercial' => $this->commercial,
                         'corrispettivo_fiscale' => $this->corrispettivo_fiscale,
                         'date' => $this->date,
+                        'receipt_date' => $this->receipt_date,
                         'year' => $this->year,
                         'type' => $this->type,
                         'amount' => $price,
@@ -782,6 +793,7 @@ class RecordIN extends Component
                 'commercial' => $this->commercial,
                 'corrispettivo_fiscale' => $this->corrispettivo_fiscale,
                 'date' => $this->date,
+                'receipt_date' => $this->receipt_date,
                 'year' => $this->year,
                 'type' => $this->type,
                 'amount' => $totalNet,
@@ -938,6 +950,7 @@ class RecordIN extends Component
                 $this->commercial = $record->commercial;
                 $this->corrispettivo_fiscale = $record->corrispettivo_fiscale;
                 $this->date = date("Y-m-d", strtotime($record->date));
+                $this->receipt_date = date("Y-m-d", strtotime($record->receipt_date));
                 $this->year = $record->year;
                 $this->type = $record->type;
                 $this->deleted = $record->deleted;
@@ -1123,6 +1136,7 @@ class RecordIN extends Component
                 'commercial' => $this->commercial,
                 'corrispettivo_fiscale' => $this->corrispettivo_fiscale,
                 'date' => date("Y-m-d", strtotime($this->date)),
+                'receipt_date' => date("Y-m-d", strtotime($this->receipt_date)),
                 'year' => $this->year,
                 'type' => $this->type,
                 'financial_movement' => $this->financial_movement,
@@ -1206,6 +1220,7 @@ class RecordIN extends Component
             $record = \App\Models\Record::findOrFail($this->dataId);
             $newRecord = $record->replicate();
             $newRecord->date = date("Y-m-d");
+            $newRecord->receipt_date = date("Y-m-d");
             $newRecord->save();
 
             $recordRows = \App\Models\RecordRow::where('record_id', $this->dataId)->get();
@@ -1404,6 +1419,7 @@ class RecordIN extends Component
                     'payment_method_id' => $this->payment_method_id,
                     'number' => $number,
                     'date' => $this->date,
+                    'receipt_date' => $this->receipt_date,
                     'year' => $this->year,
                     'type' => $this->type,
                     'parent' => $this->parent,

+ 1 - 0
app/Models/Receipt.php

@@ -17,6 +17,7 @@ class Receipt extends Model
         'payment_method_id',
         'number',
         'date',
+        'receipt_date',
         'month',
         'year',
         'type',

+ 1 - 0
app/Models/Record.php

@@ -17,6 +17,7 @@ class Record extends Model
         'destination_id',
         'origin_id',
         'date',
+        'receipt_date',
         'year',
         'data_pagamento',
         //'month',

+ 32 - 0
database/migrations/2026_01_26_095939_add_receipt_date_to_records.php

@@ -0,0 +1,32 @@
+<?php
+
+use App\Database\Migrations\TenantMigration;
+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('records', function (Blueprint $table) {
+            $table->datetime('receipt_date')->nullable()->after('date');
+        });
+    }
+
+    /**
+     * Reverse the migrations.
+     *
+     * @return void
+     */
+    public function down()
+    {
+        Schema::table('records', function (Blueprint $table) {
+            $table->dropColumn('receipt_date');
+        });
+    }
+};

+ 32 - 0
database/migrations/2026_01_26_120324_add_receipt_date_to_receipts.php

@@ -0,0 +1,32 @@
+<?php
+
+use App\Database\Migrations\TenantMigration;
+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('receipts', function (Blueprint $table) {
+            $table->datetime('receipt_date')->nullable()->after('date');
+        });
+    }
+
+    /**
+     * Reverse the migrations.
+     *
+     * @return void
+     */
+    public function down()
+    {
+        Schema::table('receipts', function (Blueprint $table) {
+            $table->dropColumn('receipt_date');
+        });
+    }
+};

+ 3 - 0
resources/views/livewire/receipt.blade.php

@@ -379,6 +379,9 @@
                 thead: {
                     'th': { 'background-color': 'blue' }
                 },
+                order: [
+                    [1, 'desc']
+                ],
                 columns: [
                     { data: 'id', visible: false, searchable: false },
                     {

+ 14 - 5
resources/views/livewire/records_in.blade.php

@@ -259,18 +259,27 @@
                                 </div>
                             </div>
 
+                            @if (!is_null($receipt_date) && $receipt_date != "1970-01-01")
                             <div class="col-md-6 mt-3">
-                                <span class="title-form d-block w-100">Data pagamento</span>
+                                <span class="title-form d-block w-100">Data ricevuta</span>
                                 <div class="input-group mb-3">
-                                    <input id="date" type="date" class="form-control"  wire:model="date" {{$this->dataId > 0 && !$isDuplicate ? 'disabled' : ''}}>
+                                    <input id="receipt_date" type="date" class="form-control" wire:model="receipt_date" {{$this->dataId > 0 && !$isDuplicate ? 'disabled' : ''}}>
                                 </div>
+                                @if ($data_ricevuta_old)
+                                    <div class="alert alert-warning">Attenzione, sono presenti ricevute con una data più recente di quella inserita</div>
+                                @endif
                             </div>
+                            @endif
+
                             <div class="col-md-6 mt-3">
-                                <span class="title-form d-block w-100">Anno</span>
+                                <span class="title-form d-block w-100">Data pagamento</span>
                                 <div class="input-group mb-3">
-                                    <input id="year" type="year" class="form-control" wire:model="year" {{$this->dataId > 0 && !$isDuplicate ? 'disabled' : ''}}>
+                                    <input id="date" type="date" class="form-control"  wire:model="date" {{$this->dataId > 0 && !$isDuplicate ? 'disabled' : ''}}>
                                 </div>
                             </div>
+                            @if (is_null($receipt_date) || $receipt_date == "1970-01-01")
+                            <div class="col-md-6"></div>
+                            @endif
 
 
                             <div class="col-md-6">
@@ -734,7 +743,7 @@
                     <div class="username d-flex align-items-center gap-2">
                         {{-- <i class="ico--ui accountingResume me-2"></i> --}}
                         <i class="fa-solid fa-2x fa-file-invoice-dollar"></i>
-                        <div class="user--resume_name d-flex flex-column"><span class="primary">{{!$commercial ? 'Ricevuta' : 'Promemoria pagamento'}} {{$currentReceip ? $currentReceip->number . "/" . $currentReceip->year : ''}} {{$currentReceip != null ? ' del ' . date("d/m/Y", strtotime($currentReceip->created_at)) : ''}}</span></div></div>
+                        <div class="user--resume_name d-flex flex-column"><span class="primary">{{!$commercial ? 'Ricevuta' : 'Promemoria pagamento'}} {{$currentReceip ? $currentReceip->number . "/" . $currentReceip->year : ''}} {{$currentReceip != null ? ' del ' . date("d/m/Y", strtotime($currentReceip->receipt_date ?? $currentReceip->date)) : ''}}</span></div></div>
                 </header>
 
                 <div class="resume--body d-flex justify-content-between flex-column">

+ 8 - 3
resources/views/receipt.blade.php

@@ -26,6 +26,11 @@
         $azienda = App\Models\Azienda::first();
         $logoService = app(App\Services\LogoUploadServices::class);
         $logoUrl = $azienda ? $logoService->getLogoUrl($azienda) : null;
+
+        $display_date = $receipt->created_at;
+        if ($receipt->receipt_date) {
+            $display_date = $receipt->receipt_date;
+        }
     @endphp
 
     {{-- Display logo from database/Wasabi instead of env --}}
@@ -39,7 +44,7 @@
     @endif
 
     <br><br><br>
-    <div align="right"><b>RICEVUTA DI PAGAMENTO N. {{$receipt->number . "/" . $receipt->year}} del {{date("d/m/Y", strtotime($receipt->created_at))}}</b></div><br><br>
+    <div align="right"><b>RICEVUTA DI PAGAMENTO N. {{$receipt->number . "/" . $receipt->year}} del {{date("d/m/Y", strtotime($display_date))}}</b></div><br><br>
 
     @if($receipt->status == 99)
         <div align="right"><b style="color:red">ANNULLATA</b></div><br><br>
@@ -184,9 +189,9 @@
                     ]);
                     $location = implode(' ', $locationParts);
                 @endphp
-                {{ $location ?: 'Sede legale' }} li {{date("d/m/Y", strtotime($receipt->created_at))}}
+                {{ $location ?: 'Sede legale' }} li {{date("d/m/Y", strtotime($display_date))}}
             @else
-                {{date("d/m/Y", strtotime($receipt->created_at))}}
+                {{date("d/m/Y", strtotime($display_date))}}
             @endif
         </small>
     </footer>

+ 10 - 8
routes/web.php

@@ -2402,7 +2402,7 @@ Route::group(['middleware' => 'tenant'], function () {
                 'receipts.number',
                 'receipts.status',
                 'receipts.date',
-                'receipts.created_at',
+                DB::raw('IF(receipts.receipt_date IS NOT NULL, receipts.receipt_date, receipts.created_at) as display_receipt_date'),
                 'receipts.record_id',
                 'members.first_name',
                 'members.last_name',
@@ -2416,7 +2416,7 @@ Route::group(['middleware' => 'tenant'], function () {
                 'receipts.year',
                 'receipts.number',
                 'receipts.status',
-                'receipts.created_at',
+                'display_receipt_date',
                 'receipts.record_id',
                 'members.first_name',
                 'members.last_name'
@@ -2427,16 +2427,18 @@ Route::group(['middleware' => 'tenant'], function () {
             if ($_GET["order"][0]["column"] == 0)
                 $column = 'receipts.year';
             if ($_GET["order"][0]["column"] == 1)
-                $column = 'receipts.number';
+                $column = 'display_receipt_date';
             if ($_GET["order"][0]["column"] == 2)
-                $column = 'members.last_name';
+                $column = 'receipts.number';
             if ($_GET["order"][0]["column"] == 3)
-                $column = 'members.first_name';
+                $column = 'members.last_name';
             if ($_GET["order"][0]["column"] == 4)
-                $column = 'receipts.status';
+                $column = 'members.first_name';
             if ($_GET["order"][0]["column"] == 5)
-                $column = 'receipts.created_at';
+                $column = 'receipts.status';
             if ($_GET["order"][0]["column"] == 6)
+                $column = 'date';
+            if ($_GET["order"][0]["column"] == 7)
                 $column = 'totals';
 
             if ($column != '')
@@ -2463,7 +2465,7 @@ Route::group(['middleware' => 'tenant'], function () {
                 'first_name' => $r->first_name ?? '',
                 'status' => $r->status,
                 'date' => date("d/m/Y", strtotime($r->date)),
-                'created_at' => date("d/m/Y", strtotime($r->created_at)),
+                'created_at' => date("d/m/Y", strtotime($r->display_receipt_date)),
                 'totals' => formatPrice($r->totals),
                 'action' => $ids
             );