瀏覽代碼

sconto e allineamenti

FabioFratini 8 月之前
父節點
當前提交
6f10c6a431

File diff suppressed because it is too large
+ 233 - 249
app/Http/Livewire/RecordIN.php


+ 1 - 0
app/Models/Record.php

@@ -29,6 +29,7 @@ class Record extends Model
         'numero_fattura',
         //'attachment'
         'is_paid',
+        'prediscount_amount',
     ];
 
     public function member()

+ 3 - 1
app/Models/RecordRow.php

@@ -24,7 +24,9 @@ class RecordRow extends Model
         'imposta',
         'divisa',
         'quantita',
-        'numero_linea'
+        'numero_linea',
+        'sconto',
+        'prediscount_amount',
     ];
 
     public function causal()

+ 35 - 0
database/migrations/2025_05_19_000000_add_field_sconto_to_records_rows_table.php

@@ -0,0 +1,35 @@
+<?php
+
+use Illuminate\Database\Migrations\Migration;
+use Illuminate\Database\Schema\Blueprint;
+use Illuminate\Support\Facades\Schema;
+
+return new class extends Migration
+{
+    /**
+     * Run the migrations.
+     *
+     * @return void
+     */
+    public function up()
+    {
+        Schema::table('records_rows', function (Blueprint $table) {
+            $table->decimal('sconto', 8, 2)->nullable();
+
+        });
+    }
+
+    /**
+     * Reverse the migrations.
+     *
+     * @return void
+     */
+    public function down()
+    {
+        Schema::table('records_rows', function (Blueprint $table) {
+            $table->dropColumn([
+                'sconto',
+            ]);
+        });
+    }
+};

+ 32 - 0
database/migrations/2025_05_19_000001_add_field_totale_presconto_to_records_rows_table.php

@@ -0,0 +1,32 @@
+<?php
+
+use Illuminate\Database\Migrations\Migration;
+use Illuminate\Database\Schema\Blueprint;
+use Illuminate\Support\Facades\Schema;
+
+return new class extends Migration
+{
+        /**
+     * Run the migrations.
+     *
+     * @return void
+     */
+    public function up()
+    {
+        Schema::table('records_rows', function (Blueprint $table) {
+            $table->decimal('prediscount_amount', 10, 2)->nullable()->after('sconto');
+        });
+    }
+
+    /**
+     * Reverse the migrations.
+     *
+     * @return void
+     */
+    public function down()
+    {
+        Schema::table('records_rows', function (Blueprint $table) {
+            $table->dropColumn('prediscount_amount');
+        });
+    }
+};

+ 32 - 0
database/migrations/2025_05_19_000002_add_field_totale_presconto_to_records_table.php

@@ -0,0 +1,32 @@
+<?php
+
+use Illuminate\Database\Migrations\Migration;
+use Illuminate\Database\Schema\Blueprint;
+use Illuminate\Support\Facades\Schema;
+
+return new class extends Migration
+{
+        /**
+     * Run the migrations.
+     *
+     * @return void
+     */
+    public function up()
+    {
+        Schema::table('records', function (Blueprint $table) {
+            $table->decimal('prediscount_amount', 10, 2)->nullable();
+        });
+    }
+
+    /**
+     * Reverse the migrations.
+     *
+     * @return void
+     */
+    public function down()
+    {
+        Schema::table('records', function (Blueprint $table) {
+            $table->dropColumn('prediscount_amount');
+        });
+    }
+};

+ 89 - 25
resources/views/livewire/records_in.blade.php

@@ -355,7 +355,7 @@
                                 <div class="row gx-2 mt-3">
                                     <span class="title-form d-block w-100">Dettaglio causale</span>
                                     <div class="col-md-6">
-                                        <input class="form-control " id="causal_detail_{{$idx}}" type="text" placeholder="Dettaglio causale" wire:model="rows.{{$idx}}.note" {{$this->dataId > 0 && !$isDuplicate ? 'disabled' : ''}}>
+                                        <textarea class="form-control" id="causal_detail_{{$idx}}" style ="background-color: #E9F0F5 !important;" placeholder="Dettaglio causale" wire:model="rows.{{$idx}}.note" {{$this->dataId > 0 && !$isDuplicate ? 'disabled' : ''}}></textarea>
                                     </div>
                                 </div>
 
@@ -386,10 +386,36 @@
                                             <span style="argin-top: 0.25rem; font-size: 0.875em; color: var(--bs-form-invalid-color);">{{ $message }}</span>
                                         @enderror
                                     </div>
-
                                 </div>
-
-                                <div class="row gx-2 mt-3 align-items-center">
+                                @if(!$corrispettivo_fiscale)
+                                    <div class="row gx-2 mt-3 align-items-center">
+                                        <div class="col-md-6">
+                                            <span class="total primary">Sconto</span>
+                                        </div>
+                                        <div class="col-md-3"></div>
+                                        <div class="col-md-3">
+                                            @if($add)
+                                                <input type="text" class="form-control totalInput text-end" id="rows.{{$idx}}.sconto"
+                                                    wire:model="rows.{{$idx}}.sconto"
+                                                    onkeyup="onlyNumberAmount(this)"
+                                                    onchange="updateSconto(this)"
+                                                    placeholder="€ 0,00"
+                                                    {{$this->dataId > 0 && !$isDuplicate ? '' : ''}}
+                                                >
+                                            @endif
+                                            @if($update)
+                                                <input type="text" class="form-control totalInput text-end" id="rows.{{$idx}}.sconto"
+                                                    wire:model="rows.{{$idx}}.sconto"
+                                                    onkeyup="onlyNumberAmount(this)"
+                                                    onchange="updateSconto(this)"
+                                                    placeholder="€ 0,00"
+                                                    {{$this->dataId > 0 && !$isDuplicate ? 'disabled' : ''}}
+                                                >
+                                            @endif
+                                        </div>
+                                    </div>
+                                @endif
+                                 <div class="row gx-2 mt-3 align-items-center">
                                     <div class="col-md-4">
                                         <span class="total primary comp">Competenza</span>
                                     </div>
@@ -466,8 +492,28 @@
                                                         </div>
                                                     </div>
                                                     <div class="col-md-3">
-                                                    <span class="title-form d-block w-100">Valore</span>
-                                                        <span class="netprice_p total--wrapper_netprice"><b>{{$this->currencyToDouble($rows[$idx]["amount"]) > 0 ? formatPrice(($this->currencyToDouble($rows[$idx]["amount"]) + getVatValue($this->currencyToDouble($rows[$idx]["amount"]), $rows[$idx]["vat_id"])) / sizeof($rows[$idx]["when"])) : ""}}</b></span>
+                                                        <span class="title-form d-block w-100">Valore</span>
+                                                        <span class="netprice_p total--wrapper_netprice">
+                                                            <b>
+                                                            @php
+                                                                $rowAmount = $this->currencyToDouble($rows[$idx]["amount"]);
+                                                                $rowSconto = isset($rows[$idx]["sconto"]) ? $this->currencyToDouble($rows[$idx]["sconto"]) : 0;
+                                                                $totalValue = $rowAmount; // Use original amount for display
+
+                                                                // Add VAT if applicable
+                                                                if ($rows[$idx]["vat_id"] > 0) {
+                                                                    // Use amount after sconto for VAT calculation
+                                                                    $netAmount = max(0, $rowAmount - $rowSconto);
+                                                                    $vatAmount = getVatValue($netAmount, $rows[$idx]["vat_id"]);
+                                                                    $totalValue = $rowAmount + $vatAmount;
+                                                                }
+
+                                                                // Calculate per period
+                                                                $valuePerPeriod = sizeof($rows[$idx]["when"]) > 0 ? $totalValue / sizeof($rows[$idx]["when"]) : 0;
+                                                            @endphp
+                                                            {{ $rowAmount > 0 ? formatPrice($valuePerPeriod) : "" }}
+                                                            </b>
+                                                        </span>
                                                     </div>
                                                     <div class="col-md-2"><br>
                                                         @if($this->dataId == 0)
@@ -674,26 +720,35 @@
 
                     <footer>
                         <div class="total--wrapper">
+                        <div class="total--wrapper_amount d-flex align-items-center justify-content-between w-100 mb-3">
+                            <span class="amount_p"><strong>Importo</strong></span>
+                            <span class="amount_data"><strong>{{$this->getPrice()}}</strong></span>
+                        </div>
+                        @php
+                            $totalSconto = 0;
+                            foreach ($this->rows as $row) {
+                                if (isset($row['sconto']) && $row['sconto'] != null && $row['sconto'] != "") {
+                                    $totalSconto += $this->currencyToDouble($row['sconto']);
+                                }
+                            }
+                        @endphp
+                        @if($totalSconto > 0)
+                        <div class="total--wrapper_amount d-flex align-items-center justify-content-between w-100 mb-3" style="color: #d9534f;">
+                            <span class="amount_p"><strong>Sconto</strong></span>
+                            <span class="amount_data"><strong>- {{formatPrice($totalSconto)}}</strong></span>
+                        </div>
+                        @endif
+                        @foreach($this->getVats() as $k => $v)
                             <div class="total--wrapper_amount d-flex align-items-center justify-content-between w-100 mb-3">
-                                <span class="amount_p"><strong>Importo</strong></span><span class="amount_data"><strong>{{$this->getPrice()}}</strong></span>
-                            </div>
-                            @if(false)
-                                <div class="total--wrapper_amount d-flex align-items-center justify-content-between w-100 mb-3">
-                                    <span class="amount_p"><strong>Iva</strong></span><span class="amount_data"><strong>{{$this->getVat()}}</strong></span>
-                                </div>
-                            @endif
-                            @foreach($this->getVats() as $k => $v)
-                                <div class="total--wrapper_amount d-flex align-items-center justify-content-between w-100 mb-3">
-                                    <span class="amount_p"><strong>{{$k}}</strong></span><span class="amount_data"><strong>{{formatPrice($v)}}</strong></span>
-                                </div>
-                            @endforeach
-                            <!--<div class="total--wrapper_tax d-flex align-items-center justify-content-between w-100 mb-2 pb-3">
-                                <span class="taxt_p">Ritenuta d’acconto (20%):</span><span class="tax_data">€ 20,00</span>
-                            </div>-->
-                            <div class="total--wrapper_netprice d-flex align-items-center justify-content-between w-100">
-                                <span class="netprice_p"><strong>Totale</strong></span><span class="netprice_data"><strong>{{$this->getTotal()}}</strong></span>
+                                <span class="amount_p"><strong>{{$k}}</strong></span>
+                                <span class="amount_data"><strong>{{formatPrice($v)}}</strong></span>
                             </div>
+                        @endforeach
+                        <div class="total--wrapper_netprice d-flex align-items-center justify-content-between w-100">
+                            <span class="netprice_p"><strong>Totale</strong></span>
+                            <span class="netprice_data"><strong>{{$this->getTotal()}}</strong></span>
                         </div>
+                    </div>
 
                         @if($update && !$isDuplicate && !$deleted)
                             @if($currentReceip)
@@ -1009,6 +1064,10 @@
             let v = input.value.replace(/\D+/g, '');
             if (v.length > 14) v = v.slice(0, 14);
             input.value = "€ " + v.replace(/(\d)(\d\d)$/, "$1,$2").replace(/(^\d{1,3}|\d{3})(?=(?:\d{3})+(?:,|$))/g, '$1.');
+
+            if (input.id.includes("sconto")) {
+                window.livewire.emit('scontoChanged');
+            }
         }
 
         function setChangedAmount() {
@@ -1387,7 +1446,6 @@
         window.onbeforeunload = function(){
             if (isEdit)
                 return 'Cambiando pagina le eventuali modifiche andranno perse';
-
         };
 
         function setCommercialType(t)
@@ -1399,7 +1457,6 @@
 
         Livewire.on('goToAnchor', () =>
         {
-            console.log("aaa");
             window.location.href = "#top";
         });
 
@@ -1408,6 +1465,13 @@
             @this.setYear(idx, xxx);
         }
 
+        function setChangedAmount() {
+            @this.setAmount();
+        }
+
+        function updateSconto(input) {
+            window.livewire.emit('scontoChanged');
+        }
 
     </script>
 

+ 9 - 10
resources/views/livewire/records_out.blade.php

@@ -213,7 +213,7 @@
 
                             <div class="col-md-12">
                                 <span class="title-form d-block w-100">Tipologia</span>
-                                <div class="input-group mb-12">
+                                <div class="input-group mb-3">
                                     <div class="check--invoice d-flex align-items-center">
                                         <div class="form-check me-3">
                                             <input class="form-check-input" type="radio" value="1" wire:model="commercial" id="commercial_1">
@@ -227,6 +227,13 @@
                                 </div>
                             </div>
 
+                            <span class="title-form d-block w-100">N° Fattura</span>
+                            <div class="input-group mb-3">
+                                <div class="col-md-6">
+                                    <input class="form-control " type="text" placeholder="Numero fattura" wire:model="numero_fattura">
+                                </div>
+                            </div>
+
                             <div class="col-md-6">
                                 <span class="title-form d-block w-100">Data</span>
                                 <div class="input-group mb-3">
@@ -272,14 +279,6 @@
                             </div>
                         </div>
 
-                        <div class="row gx-2 mt-5">
-                            <span class="title-form d-block w-100">N° Fattura</span>
-                            <div class="col-md-12">
-                                <input class="form-control " type="text" placeholder="Numero fattura" wire:model="numero_fattura">
-                            </div>
-                        </div>
-
-
                         @foreach($rows as $idx => $row)
 
                             <div class="row gx-2 mt-5" wire:ignore.self>
@@ -310,7 +309,7 @@
                             <div class="row gx-2 mt-5">
                                 <span class="title-form d-block w-100">Dettaglio causale</span>
                                 <div class="col-md-12">
-                                    <input class="form-control " type="text" placeholder="Dettaglio causale" wire:model="rows.{{$idx}}.note">
+                                    <textarea class="form-control" style ="background-color: #E9F0F5 !important;" placeholder="Dettaglio causale" wire:model="rows.{{$idx}}.note"></textarea>
                                 </div>
                             </div>
 

Some files were not shown because too many files changed in this diff