Bläddra i källkod

Gestione iva e sponsors

Luca Parisio 1 år sedan
förälder
incheckning
45707ee04f

+ 1 - 0
app/Http/Livewire/Record.php

@@ -229,6 +229,7 @@ class Record extends Component
             {
 
                 $amount = $data->amount;
+                $amount += getVatValue($amount, $data->vat_id);
 
                 /*$when = sizeof(json_decode($data->when));
 

+ 79 - 56
app/Http/Livewire/RecordIN.php

@@ -18,6 +18,12 @@ class RecordIN extends Component
     public $typeIN = "IN";
 
     public $isDuplicate = false;
+    public $multiP = false;
+
+    public $multiMonthTo = 0;
+    public $multiYearTo = 0;
+    public $multiMonthFrom = 0;
+    public $multiYearFrom = 0;
 
     public function sortBy($field)
     {
@@ -39,6 +45,7 @@ class RecordIN extends Component
     $year,
     $type,
     $amount,
+    $vat,
     $virtual,
     $note,
     $commercial, $update = false, $add = false;
@@ -71,6 +78,7 @@ class RecordIN extends Component
     public $causals = array();
     public $payments = array();
     public $members = array();
+    public $vats = array();
 
     public $rows = array();
 
@@ -154,7 +162,7 @@ class RecordIN extends Component
         $this->newMemberFiscalCodeExist = false;
         $this->currentReceip = null;
         $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, '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);
     }
 
     public function getMemberProperty()
@@ -220,12 +228,18 @@ class RecordIN extends Component
 
         $this->causals = array();
 
+        $this->multiMonthFrom = date("n");
+        $this->multiYearFrom = date("Y");
+        $this->multiMonthTo = date("n");
+        $this->multiYearTo = date("Y");
+
         $this->getCausale(\App\Models\Causal::select('id', 'name')->where('parent_id', null)->where('type', 'IN')->get(), 0);
 
         //$this->buildTree(\App\Models\Causal::all(), null);
 
         $this->members = \App\Models\Member::select(['id', 'first_name', 'last_name', 'fiscal_code'])->orderBy('last_name')->orderBy('first_name')->get();
         $this->payments = \App\Models\PaymentMethod::select('id', 'name')->orderBy('name')->get();
+        $this->vats = \App\Models\Vat::select('id', 'name', 'value')->orderBy('value')->get();
 
         if ($this->first)
         {
@@ -317,6 +331,8 @@ class RecordIN extends Component
                 foreach($r->rows as $rr)
                 {
                     $this->total += $rr->amount;
+                    if ($rr->vat_id > 0)
+                        $this->total += getVatValue($rr->amount, $rr->vat_id);
                 }
             }
 
@@ -431,7 +447,7 @@ class RecordIN extends Component
         $f = false;
         foreach($this->rows as $row)
         {
-            if (!$row["commercial"]) $f = true;
+            if ($row["commercial"]) $f = true;
         }
         if ($f)
             $rules["member_id"] = 'required';
@@ -442,20 +458,15 @@ class RecordIN extends Component
             $record = \App\Models\Record::create([
                 'member_id' => $this->member_id,
                 'supplier_id' => $this->supplier_id,
-                // 'causal_id' => $this->causal_id,
                 'payment_method_id' => $this->payment_method_id,
                 'date' => $this->date,
-                // 'month' => $this->month,
-                // 'year' => $this->year,
-                // 'note' => $this->note,
                 'type' => $this->type,
-                // 'amount' => $this->currencyToDouble($this->amount),
-                // 'commercial' => $this->commercial,
             ]);
             $this->dataId = $record->id;
 
             // Inserisco le righe
             $tot = 0;
+            $vat = 0;
             foreach($this->rows as $row)
             {
                 foreach($row["when"] as $x => $y)
@@ -467,10 +478,12 @@ class RecordIN extends Component
                     'causal_id' => $row["causal_id"],
                     'note' => $row["note"],
                     'amount' => $this->currencyToDouble($row["amount"]),
+                    'vat_id' => $row["vat_id"],
                     'commercial' => $row["commercial"],
                     'when' => json_encode($row["when"])
                 ]);
                 $tot += $this->currencyToDouble($row["amount"]);
+                $vat += getVatValue($this->currencyToDouble($row["amount"]), $row["vat_id"]);
             }
             $record->amount = $tot;
             $record->save();
@@ -512,23 +525,18 @@ class RecordIN extends Component
             } else {
                 $this->member_id = $record->member_id;
                 $this->supplier_id = $record->supplier_id;
-                // $this->causal_id = $record->causal_id;
                 $this->payment_method_id = $record->payment_method_id;
                 $this->date = date("Y-m-d", strtotime($record->date));
-                // $this->month = $record->month;
-                // $this->year = $record->year;
-                // $this->note = $record->note;
                 $this->type = $record->type;
-                // $this->amount = formatPrice($record->amount);
-                // $this->commercial = $record->commercial;
                 $this->dataId = $record->id;
                 $this->update = true;
                 $this->add = false;
 
-                $this->rows = \App\Models\RecordRow::where('record_id', $this->dataId)->select('causal_id', 'note', 'commercial', 'when', 'amount')->get()->toArray();
+                $this->rows = \App\Models\RecordRow::where('record_id', $this->dataId)->select('causal_id', 'note', 'commercial', 'when', 'amount', 'vat_id')->get()->toArray();
                 foreach($this->rows as $i => $r)
                 {
                     $this->rows[$i]['amount'] = formatPrice($this->rows[$i]['amount']);
+                    $this->rows[$i]['vat_id'] = $this->rows[$i]['vat_id'];
                     $this->rows[$i]['when'] = json_decode($this->rows[$i]['when']);
                 }
 
@@ -553,7 +561,7 @@ class RecordIN extends Component
         $f = false;
         foreach($this->rows as $row)
         {
-            if (!$row["commercial"]) $f = true;
+            if ($row["commercial"]) $f = true;
         }
         if ($f)
             $rules["member_id"] = 'required';
@@ -565,18 +573,13 @@ class RecordIN extends Component
             \App\Models\Record::whereId($this->dataId)->update([
                 'member_id' => $this->member_id,
                 'supplier_id' => $this->supplier_id,
-                // 'causal_id' => $this->causal_id,
                 'payment_method_id' => $this->payment_method_id,
                 'date' => date("Y-m-d", strtotime($this->date)),
-                // 'month' => $this->month,
-                // 'year' => $this->year,
-                // 'note' => $this->note,
                 'type' => $this->type,
-                // 'amount' => $this->currencyToDouble($this->amount),
-                //'commercial' => $this->commercial,
             ]);
 
             $tot = 0;
+            $vat = 0;
             // Elimino le righe
             \App\Models\RecordRow::where('record_id', $this->dataId)->delete();
             // Inserisco le righe
@@ -590,11 +593,13 @@ class RecordIN extends Component
                     'record_id' => $this->dataId,
                     'causal_id' => $row["causal_id"],
                     'note' => $row["note"],
+                    'vat_id' => $row["vat_id"],
                     'amount' => $this->currencyToDouble($row["amount"]),
                     'commercial' => $row["commercial"],
                     'when' => json_encode($row["when"])
                 ]);
                 $tot += $this->currencyToDouble($row["amount"]);
+                $vat += getVatValue($this->currencyToDouble($row["amount"]), $row["vat_id"]);
             }
 
             $rec = \App\Models\Record::findOrFail($this->dataId);
@@ -727,15 +732,11 @@ class RecordIN extends Component
                 'record_id' => $this->dataId,
                 'member_id' => $this->member_id,
                 'supplier_id' => $this->supplier_id,
-                //'causal_id' => $this->causal_id,
                 'payment_method_id' => $this->payment_method_id,
                 'number' => $number,
                 'date' => $this->date,
-                //'month' => $this->month,
                 'year' => date("Y"),
                 'type' => $this->type,
-                //'amount' => $this->currencyToDouble($this->amount),
-                //'commercial' => $this->commercial,
                 'status' => 1,
             ]);
 
@@ -745,6 +746,7 @@ class RecordIN extends Component
                     'receip_id' => $receipt->id,
                     'causal_id' => $row["causal_id"],
                     'note' => $row["note"],
+                    'vat_id' => $row["vat_id"],
                     'amount' => $this->currencyToDouble($row["amount"]),
                     'commercial' => $row["commercial"],
                     'when' => json_encode($row["when"])
@@ -777,7 +779,7 @@ class RecordIN extends Component
 
     public function addRow()
     {
-        $this->rows[] = array('causal_id' => null, 'when' => array(array('month' => date("n"), 'year' => date("Y"), 'period' => '')),  'amount' => null, 'note' => '', 'commercial' => 0);
+        $this->rows[] = array('causal_id' => null, 'when' => array(array('month' => date("n"), 'year' => date("Y"), 'period' => '')),  'amount' => null, 'vat_id' => null, 'note' => '', 'commercial' => 0);
         $this->emit('load-select');
     }
 
@@ -789,7 +791,9 @@ class RecordIN extends Component
 
     public function addPeriod($idx)
     {
-        $this->rows[$idx]['when'][] = array('month' => date("n"), 'year' => date("Y"), 'period' => '');
+        $x = sizeof($this->rows[$idx]['when']) - 1;
+        $newDate = \Carbon\Carbon::create($this->rows[$idx]['when'][$x]["year"] . "-" . $this->rows[$idx]['when'][$x]["month"] . '-01')->addMonth();
+        $this->rows[$idx]['when'][] = array('month' => $newDate->format("n"), 'year' => $newDate->format("Y"), 'period' => '');
     }
 
     public function delPeriod($idx, $xxx)
@@ -799,6 +803,22 @@ class RecordIN extends Component
     }
 
     public function getTotal()
+    {
+        $total = 0.00;
+        foreach($this->rows as $r)
+        {
+            if ($r["amount"] != null && $r["amount"] != "")
+            {
+                $total += $this->currencyToDouble($r["amount"]);
+                if ($r["vat_id"] > 0)
+                    $total += getVatValue($this->currencyToDouble($r["amount"]), $r["vat_id"]);
+            }
+        }
+        return formatPrice($total);
+        // $this->emit('load-select');
+    }
+
+    public function getPrice()
     {
         $total = 0.00;
         foreach($this->rows as $r)
@@ -810,6 +830,18 @@ class RecordIN extends Component
         // $this->emit('load-select');
     }
 
+    public function getVat()
+    {
+        $total = 0.00;
+        foreach($this->rows as $r)
+        {
+            if ($r["amount"] != null && $r["amount"] != "" && $r["vat_id"] > 0)
+                $total += getVatValue($this->currencyToDouble($r["amount"]), $r["vat_id"]);
+        }
+        return formatPrice($total);
+        // $this->emit('load-select');
+    }
+
     public function setCausal($id, $idx)
     {
         $this->rows[$idx]["causal_id"] = $id;
@@ -828,32 +860,23 @@ class RecordIN extends Component
         }, 'test.pdf');*/
     }
 
-}
+    public function multiPeriod()
+    {
+        $this->multiP = true;
+    }
 
-/*
-<!--<table width="100%" cellpadding="7">
-      <tr>
-        <td><b>Cliente</b></td>
-        <td><b>Data/ora ingresso</b></td>
-        <td><b>Data/ora uscita</b></td>
-      </tr>
-      @foreach ($datas as $data)
-      <tr>
-        <td>{{ $data["cliente"] }}</td>
-        <td>
-            @if($data["ingresso"] != '')
-                <span style="color:green">{{ date("d/m/Y H:i:s", strtotime($data["ingresso"])) }}</span>
-            @endif
-        </td>
-        <td>
-            @if($data["uscita"] != '')
-                <span style="color:red">{{ date("d/m/Y H:i:s", strtotime($data["uscita"])) }}</span>
-            @endif
-        </td>
-      </tr>
-      @endforeach
-    </table>-->
-    <footer>
-        <small>{{date("d/m/Y H:i:s")}}</small>
-    </footer>
-    */
+    public function multiPeriodCreate($idx)
+    {
+
+        $period = \Carbon\CarbonPeriod::create($this->multiYearFrom . '-' . $this->multiMonthFrom . '-01', '1 month', $this->multiYearTo . '-' . $this->multiMonthTo . '-01');
+
+        foreach ($period as $dt) {
+            if (!in_array(array('month' => $dt->format("n"), 'year' => $dt->format("Y"), 'period' => ''), $this->rows[$idx]['when']))
+                $this->rows[$idx]['when'][] = array('month' => $dt->format("n"), 'year' => $dt->format("Y"), 'period' => '');
+        }
+
+        $this->multiP = false;
+
+    }
+
+}

+ 6 - 3
app/Http/Livewire/RecordINOUT.php

@@ -89,7 +89,7 @@ class RecordINOUT extends Component
     {
         //list($m, $y) = explode("_", $dt);
 
-        if ($m != "" && $y != "")
+        if ($m != "" && $y != "" && !in_array($m . "-" . $y, $this->datas))
             $this->datas[] = $m . "-" . $y;
 
         $this->columns = array();
@@ -113,6 +113,7 @@ class RecordINOUT extends Component
                 foreach($records as $record)
                 {
                     $amount = $record->amount;
+                    $amount += getVatValue($amount, $record->vat_id);
                     $when = sizeof(json_decode($record->when));
                     if ($when > 1)
                     {
@@ -137,6 +138,7 @@ class RecordINOUT extends Component
                 foreach($records as $record)
                 {
                     $amount = $record->amount;
+                    $amount += getVatValue($amount, $record->vat_id);
                     $when = sizeof(json_decode($record->when));
                     if ($when > 1)
                     {
@@ -310,14 +312,14 @@ class RecordINOUT extends Component
 
     }
 
-    public function exportYear()
+    public function exportYear($year)
     {
         $records_in = [];
         $records_out = [];
         $datas = [];
         for($m=1;$m<=12;$m++)
         {
-            $datas[] = $m . "-" . $this->year;
+            $datas[] = $m . "-" . $year;
         }
         foreach($datas as $filter)
         {
@@ -333,6 +335,7 @@ class RecordINOUT extends Component
             foreach($records as $record)
             {
                 $amount = $record->amount;
+                $amount += getVatValue($amount, $record->vat_id);
                 $when = sizeof(json_decode($record->when));
                 if ($when > 1)
                 {

+ 35 - 1
app/Http/Livewire/RecordOUT.php

@@ -13,6 +13,13 @@ class RecordOUT extends Component
 
     public $typeOUT = "OUT";
 
+    public $multiP = false;
+
+    public $multiMonthTo = 0;
+    public $multiYearTo = 0;
+    public $multiMonthFrom = 0;
+    public $multiYearFrom = 0;
+
     public function sortBy($field)
     {
         if($this->sortField === $field)
@@ -126,6 +133,11 @@ class RecordOUT extends Component
     public function mount()
     {
 
+        $this->multiMonthFrom = date("n");
+        $this->multiYearFrom = date("Y");
+        $this->multiMonthTo = date("n");
+        $this->multiYearTo = date("Y");
+
         if (isset($_GET["new"]))
             $this->add();
 
@@ -531,7 +543,10 @@ class RecordOUT extends Component
 
     public function addPeriod($idx)
     {
-        $this->rows[$idx]['when'][] = array('month' => date("n"), 'year' => date("Y"), 'period' => '');
+        $x = sizeof($this->rows[$idx]['when']) - 1;
+        $newDate = \Carbon\Carbon::create($this->rows[$idx]['when'][$x]["year"] . "-" . $this->rows[$idx]['when'][$x]["month"] . '-01')->addMonth();
+        $this->rows[$idx]['when'][] = array('month' => $newDate->format("n"), 'year' => $newDate->format("Y"), 'period' => '');
+        //$this->rows[$idx]['when'][] = array('month' => date("n"), 'year' => date("Y"), 'period' => '');
     }
 
     public function delPeriod($idx, $xxx)
@@ -556,4 +571,23 @@ class RecordOUT extends Component
         $this->rows[$idx]["causal_id"] = $id;
     }
 
+    public function multiPeriod()
+    {
+        $this->multiP = true;
+    }
+
+    public function multiPeriodCreate($idx)
+    {
+
+        $period = \Carbon\CarbonPeriod::create($this->multiYearFrom . '-' . $this->multiMonthFrom . '-01', '1 month', $this->multiYearTo . '-' . $this->multiMonthTo . '-01');
+
+        foreach ($period as $dt) {
+            if (!in_array(array('month' => $dt->format("n"), 'year' => $dt->format("Y"), 'period' => ''), $this->rows[$idx]['when']))
+                $this->rows[$idx]['when'][] = array('month' => $dt->format("n"), 'year' => $dt->format("Y"), 'period' => '');
+        }
+
+        $this->multiP = false;
+
+    }
+
 }

+ 369 - 0
app/Http/Livewire/Sponsor.php

@@ -0,0 +1,369 @@
+<?php
+
+namespace App\Http\Livewire;
+use Livewire\Component;
+use Livewire\WithFileUploads;
+
+class Sponsor extends Component
+{
+
+    use WithFileUploads;
+
+    public $records, $name, $fiscal_code, $vat, $address, $zip_code,$nation_id,$province_id,$city_id,$phone,$email,$enabled, $dataId, $update = false, $add = false;
+    public $first_name, $last_name;
+    public $from_date, $to_date, $subscription_date, $amount, $file, $file_old, $updateContract = false, $addContract = false, $contractId;
+    public $isItaly = true;
+
+    public $searchTxt;
+    public $search;
+
+    public $contracts = array();
+
+    protected $rules = [
+        'name' => 'required'
+    ];
+
+    protected $messages = [
+        'name.required' => 'Il nome è obbligatorio'
+    ];
+
+    public function resetFields(){
+        $this->name = '';
+        $this->first_name = '';
+        $this->last_name = '';
+        $this->fiscal_code = '';
+        $this->vat = '';
+        $this->address = '';
+        $this->zip_code = '';
+        $this->nation_id = null;
+        $this->province_id = null;
+        $this->city_id = null;
+        $this->phone = '';
+        $this->email = '';
+        $this->enabled = true;
+        $this->contracts = array();
+    }
+
+    public function resetContract(){
+        $this->from_date = '';
+        $this->to_date = '';
+        $this->subscription_date = '';
+        $this->amount = 0;
+        $this->file = '';
+        $this->file_old = '';
+    }
+
+    public $sortField ='name';
+    public $sortAsc = true;
+
+    public function sortBy($field)
+    {
+        if($this->sortField === $field)
+        {
+            $this->sortAsc = ! $this->sortAsc;
+        } else {
+            $this->sortAsc = true;
+        }
+
+        $this->sortField = $field;
+    }
+
+    public function mount()
+    {
+
+        if (isset($_GET["new"]))
+            $this->add();
+
+    }
+
+    public function search()
+    {
+        if ($this->searchTxt != '')
+        {
+            $this->search = $this->searchTxt;
+            $this->showReset = true;
+        }
+    }
+    public function resetSearch()
+    {
+        $this->showReset = false;
+        $this->searchTxt = '';
+        $this->search = $this->searchTxt;
+    }
+
+    public function render()
+    {
+        if ($this->search != '')
+            $this->records = \App\Models\Sponsor::where('name', 'LIKE', '%' . $this->search . '%')->orWhere('first_name', 'LIKE', '%' . $this->search . '%')->orWhere('last_name', 'LIKE', '%' . $this->search . '%')->orderBy($this->sortField, $this->sortAsc ? 'asc' : 'desc')->get();
+        else
+            $this->records = \App\Models\Sponsor::orderBy($this->sortField, $this->sortAsc ? 'asc' : 'desc')->get();
+
+        $this->contracts = array();
+        if ($this->dataId > 0)
+            $this->contracts = \App\Models\SponsorContract::where('sponsor_id', $this->dataId)->orderBy('from_date', 'asc')->get();
+
+        return view('livewire.sponsor');
+    }
+
+    public function hydrate()
+    {
+        $this->emit('load-select');
+    }
+
+    public function checkIsItaly()
+    {
+        $n = \App\Models\Nation::findOrFail($this->nation_id);
+        $this->isItaly = $n->is_italy;
+    }
+
+    public function add()
+    {
+        $this->resetFields();
+        $this->resetContract();
+        $this->emit('load-select');
+        $this->add = true;
+        $this->update = false;
+    }
+
+    public function store()
+    {
+        $this->validate();
+        try {
+            \App\Models\Sponsor::create([
+                'name' => $this->name,
+                'first_name' => $this->first_name,
+                'last_name' => $this->last_name,
+                'fiscal_code' => $this->fiscal_code,
+                'vat' => $this->vat,
+                'address' => $this->address,
+                'zip_code' => $this->zip_code,
+                'nation_id' => $this->nation_id,
+                'province_id' => $this->province_id,
+                'city_id' => $this->city_id,
+                'phone' => $this->phone,
+                'email' => $this->email,
+                'enabled' => $this->enabled
+            ]);
+            session()->flash('success','Sponsor creato');
+            $this->resetFields();
+            $this->add = false;
+        } catch (\Exception $ex) {
+            session()->flash('error','Errore (' . $ex->getMessage() . ')');
+        }
+    }
+
+    public function edit($id){
+        $this->emit('load-select');
+        try {
+            $sponsor = \App\Models\Sponsor::findOrFail($id);
+            if( !$sponsor) {
+                session()->flash('error','Sponsor non trovato');
+            } else {
+                $this->name = $sponsor->name;
+                $this->first_name = $sponsor->first_name;
+                $this->last_name = $sponsor->last_name;
+                $this->fiscal_code = $sponsor->fiscal_code;
+                $this->vat = $sponsor->vat;
+                $this->address = $sponsor->address;
+                $this->zip_code = $sponsor->zip_code;
+                $this->nation_id = $sponsor->nation_id;
+                $this->province_id = $sponsor->province_id;
+                $this->city_id = $sponsor->city_id;
+                $this->phone = $sponsor->phone;
+                $this->email = $sponsor->email;
+                $this->enabled = $sponsor->enabled;
+                $this->dataId = $sponsor->id;
+                $this->update = true;
+                $this->add = false;
+                $this->emit('load-provinces', $this->nation_id, 'provinceClass');
+                $this->emit('load-cities', $this->province_id, 'cityClass');
+            }
+        } catch (\Exception $ex) {
+            session()->flash('error','Errore (' . $ex->getMessage() . ')');
+        }
+    }
+
+    public function update()
+    {
+        $this->validate();
+        try {
+            \App\Models\Sponsor::whereId($this->dataId)->update([
+                'name' => $this->name,
+                'first_name' => $this->first_name,
+                'last_name' => $this->last_name,
+                'fiscal_code' => $this->fiscal_code,
+                'vat' => $this->vat,
+                'address' => $this->address,
+                'zip_code' => $this->zip_code,
+                'nation_id' => $this->nation_id,
+                'province_id' => $this->province_id,
+                'city_id' => $this->city_id,
+                'phone' => $this->phone,
+                'email' => $this->email,
+                'enabled' => $this->enabled
+            ]);
+            session()->flash('success','Sponsor aggiornato');
+            $this->resetFields();
+            $this->update = false;
+        } catch (\Exception $ex) {
+            session()->flash('error','Errore (' . $ex->getMessage() . ')');
+        }
+    }
+
+    public function cancel()
+    {
+        $this->add = false;
+        $this->update = false;
+        $this->resetFields();
+    }
+
+    public function delete($id)
+    {
+        try{
+            \App\Models\Sponsor::find($id)->delete();
+            session()->flash('success',"Sponsor eliminato");
+        }catch(\Exception $e){
+            session()->flash('error','Errore (' . $ex->getMessage() . ')');
+        }
+    }
+
+    public function addContract()
+    {
+        $this->resetContract();
+        $this->addContract = true;
+        $this->updateContract = false;
+    }
+
+    public function storeContract()
+    {
+        $this->validate();
+        try {
+
+            $name = '';
+            try{
+
+                if ($this->file)
+                {
+                    $name = md5($this->file . microtime()).'.'.$this->file->extension();
+                    $this->file->storeAs('public', $name);
+                }
+            } catch (\Exception $ex) {
+                //session()->flash('error','Errore (' . $ex->getMessage() . ')');
+            }
+
+            \App\Models\SponsorContract::create([
+                'sponsor_id' => $this->dataId,
+                'from_date' => $this->from_date,
+                'to_date' => $this->to_date,
+                'subscription_date' => $this->subscription_date,
+                'amount' => $this->amount,
+                'file' => $name
+            ]);
+            session()->flash('success','Contratto creato');
+            $this->resetContract();
+            $this->addContract = false;
+        } catch (\Exception $ex) {
+            session()->flash('error','Errore (' . $ex->getMessage() . ')');
+        }
+    }
+
+    public function editContract($id){
+        // $this->emit('load-select');
+        try {
+            $sponsorContract = \App\Models\SponsorContract::findOrFail($id);
+            if( !$sponsorContract) {
+                session()->flash('error','Contratto non trovato');
+            } else {
+                $this->from_date = $sponsorContract->from_date ? date("Y-m-d", strtotime($sponsorContract->from_date)) : "";
+                $this->to_date = $sponsorContract->to_date ? date("Y-m-d", strtotime($sponsorContract->to_date)) : "";
+                $this->subscription_date = $sponsorContract->subscription_date ? date("Y-m-d", strtotime($sponsorContract->subscription_date)) : "";
+                $this->amount = $sponsorContract->amount;
+                $this->file_old = $sponsorContract->file;
+                $this->contractId = $sponsorContract->id;
+                $this->updateContract = true;
+                $this->addContract = false;
+            }
+        } catch (\Exception $ex) {
+            session()->flash('error','Errore (' . $ex->getMessage() . ')');
+        }
+    }
+
+    public function updateContract()
+    {
+        $this->validate();
+        try {
+
+            $name = '';
+            try{
+
+                if ($this->file)
+                {
+                    $name = md5($this->file . microtime()).'.'.$this->file->extension();
+                    $this->file->storeAs('public', $name);
+                }
+            } catch (\Exception $ex) {
+                //session()->flash('error','Errore (' . $ex->getMessage() . ')');
+            }
+
+            \App\Models\SponsorContract::whereId($this->contractId)->update([
+                'from_date' => $this->from_date,
+                'to_date' => $this->to_date,
+                'subscription_date' => $this->subscription_date,
+                'amount' => $this->amount,
+                'file' => $name != '' ? $name : $this->file_old,
+            ]);
+            session()->flash('success','Contratto aggiornato');
+            $this->resetContract();
+            $this->updateContract = false;
+        } catch (\Exception $ex) {
+            session()->flash('error','Errore (' . $ex->getMessage() . ')');
+        }
+    }
+
+    public function cancelContract()
+    {
+        $this->addContract = false;
+        $this->updateContract = false;
+        $this->resetContract();
+    }
+
+    public function deleteContract($id)
+    {
+        try{
+            \App\Models\SponsorContract::find($id)->delete();
+            session()->flash('success',"Contratto eliminato");
+        }catch(\Exception $e){
+            session()->flash('error','Errore (' . $ex->getMessage() . ')');
+        }
+    }
+
+    public function getNation($nation)
+    {
+        if ($nation > 0)
+        {
+            $ret = \App\Models\Nation::findOrFail($nation);
+            return $ret->name;
+        }
+        return "";
+    }
+
+    public function getProvince($province)
+    {
+        if ($province > 0)
+        {
+            $ret = \App\Models\Province::findOrFail($province);
+            return $ret->name;
+        }
+        return "";
+    }
+
+    public function getCity($city)
+    {
+        if ($city > 0)
+        {
+            $ret = \App\Models\City::findOrFail($city);
+            return $ret->name;
+        }
+        return "";
+    }
+}

+ 122 - 0
app/Http/Livewire/Vat.php

@@ -0,0 +1,122 @@
+<?php
+
+namespace App\Http\Livewire;
+
+use Livewire\Component;
+
+class Vat extends Component
+{
+    public $records, $name, $value, $enabled, $dataId, $update = false, $add = false;
+
+    protected $rules = [
+        'name' => 'required',
+        'value' => 'required'
+    ];
+
+    protected $messages = [
+        'name.required' => 'Il nome è obbligatorio',
+        'value.required' => 'Il valore è obbligatorio',
+    ];
+
+    public $sortField ='name';
+    public $sortAsc = true;
+
+    public function sortBy($field)
+    {
+        if($this->sortField === $field)
+        {
+            $this->sortAsc = ! $this->sortAsc;
+        } else {
+            $this->sortAsc = true;
+        }
+
+        $this->sortField = $field;
+    }
+
+    public function resetFields(){
+        $this->name = '';
+        $this->enabled = true;
+    }
+
+    public function render()
+    {
+        $this->records = \App\Models\Vat::select('id', 'name', 'value', 'enabled')->orderBy($this->sortField, $this->sortAsc ? 'asc' : 'desc')->get();
+        return view('livewire.vat');
+    }
+
+    public function add()
+    {
+        $this->resetFields();
+        $this->add = true;
+        $this->update = false;
+    }
+
+    public function store()
+    {
+        $this->validate();
+        try {
+            \App\Models\Vat::create([
+                'name' => $this->name,
+                'value' => $this->value,
+                'enabled' => $this->enabled
+            ]);
+            session()->flash('success','IVA creata');
+            $this->resetFields();
+            $this->add = false;
+        } catch (\Exception $ex) {
+            session()->flash('error','Errore (' . $ex->getMessage() . ')');
+        }
+    }
+
+    public function edit($id){
+        try {
+            $vat = \App\Models\Vat::findOrFail($id);
+            if( !$vat) {
+                session()->flash('error','IVA non trovata');
+            } else {
+                $this->name = $vat->name;
+                $this->value = $vat->value;
+                $this->enabled = $vat->enabled;
+                $this->dataId = $vat->id;
+                $this->update = true;
+                $this->add = false;
+            }
+        } catch (\Exception $ex) {
+            session()->flash('error','Errore (' . $ex->getMessage() . ')');
+        }
+    }
+
+    public function update()
+    {
+        $this->validate();
+        try {
+            \App\Models\Vat::whereId($this->dataId)->update([
+                'name' => $this->name,
+                'value' => $this->value,
+                'enabled' => $this->enabled
+            ]);
+            session()->flash('success','IVA aggiornata');
+            $this->resetFields();
+            $this->update = false;
+        } catch (\Exception $ex) {
+            session()->flash('error','Errore (' . $ex->getMessage() . ')');
+        }
+    }
+
+    public function cancel()
+    {
+        $this->add = false;
+        $this->update = false;
+        $this->resetFields();
+    }
+
+    public function delete($id)
+    {
+        try{
+            \App\Models\Vat::find($id)->delete();
+            session()->flash('success',"IVA eliminata");
+        }catch(\Exception $e){
+            session()->flash('error','Errore (' . $ex->getMessage() . ')');
+        }
+    }
+}

+ 11 - 1
app/Models/Record.php

@@ -45,7 +45,17 @@ class Record extends Model
 
     public function getTotal()
     {
-        return $this->rows->sum('amount');
+        $vat = 0;
+        foreach($this->rows as $r)
+        {
+            if ($r->vat_id > 0)
+            {
+                $v = \App\Models\Vat::where('id', $r->vat_id)->first();
+                if ($v && $v->value > 0)
+                    $vat += $r->amount / 100 * $v->value;
+            }
+        }
+        return $this->rows->sum('amount') + $vat;
     }
 
 }

+ 1 - 0
app/Models/RecordRow.php

@@ -16,6 +16,7 @@ class RecordRow extends Model
         'causal_id',
         'when',
         'amount',
+        'vat_id',
         'note',
         'commercial',
     ];

+ 43 - 0
app/Models/Sponsor.php

@@ -0,0 +1,43 @@
+<?php
+
+namespace App\Models;
+
+use Illuminate\Database\Eloquent\Factories\HasFactory;
+use Illuminate\Database\Eloquent\Model;
+
+class Sponsor extends Model
+{
+    use HasFactory;
+
+    protected $fillable = [
+        'name',
+        'first_name',
+        'last_name',
+        'fiscal_code',
+        'vat',
+        'address',
+        'zip_code',
+        'nation_id',
+        'province_id',
+        'city_id',
+        'phone',
+        'email',
+        'enabled'
+    ];
+
+    public function nation()
+    {
+        return $this->belongsTo(\App\Models\Nation::class);
+    }
+
+    public function province()
+    {
+        return $this->belongsTo(\App\Models\Province::class);
+    }
+
+    public function city()
+    {
+        return $this->belongsTo(\App\Models\City::class);
+    }
+
+}

+ 20 - 0
app/Models/SponsorContract.php

@@ -0,0 +1,20 @@
+<?php
+
+namespace App\Models;
+
+use Illuminate\Database\Eloquent\Factories\HasFactory;
+use Illuminate\Database\Eloquent\Model;
+
+class SponsorContract extends Model
+{
+    use HasFactory;
+
+    protected $fillable = [
+        'sponsor_id',
+        'from_date',
+        'to_date',
+        'subscription_date',
+        'amount',
+        'file'
+    ];
+}

+ 23 - 0
app/Models/Vat.php

@@ -0,0 +1,23 @@
+<?php
+
+namespace App\Models;
+
+use Illuminate\Database\Eloquent\Factories\HasFactory;
+use Illuminate\Database\Eloquent\Model;
+
+class Vat extends Model
+{
+    use HasFactory;
+
+    protected $fillable = [
+        'name',
+        'value',
+        'enabled',
+    ];
+
+    public function canDelete()
+    {
+        return true;//\App\Models\PaymentMethod::where('bank_id', $this->id)->count() == 0;
+    }
+
+}

+ 28 - 0
app/helpers.php

@@ -14,3 +14,31 @@ function formatPrice($price)
 {
     return "€ " . number_format($price, 2, ",", ".");
 }
+
+function getVatValue($v, $i)
+{
+    $vats = \App\Models\Vat::select('id', 'name', 'value')->orderBy('value')->get();
+    $vat = 0;
+    if ($i > 0)
+    {
+        $iv = 0;
+        foreach($vats as $vv)
+        {
+            if ($vv->id == $i)
+            {
+                $iv = $vv->value;
+                break;
+            }
+        }
+        if ($iv > 0)
+            $vat = $v / 100 * $iv;
+    }
+    return $vat;
+}
+
+function mysqlToDate($dt)
+{
+    list($date, $hour) = explode(" ", $dt);
+    list($year, $month, $day) = explode("-", $date);
+    return $day . "/" . $month . "/" . $year;
+}

+ 35 - 0
database/migrations/2024_04_09_100000_create_vats_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::create('vats', function (Blueprint $table) {
+            $table->id();
+            $table->string('name');
+            $table->integer('value');
+            $table->integer('enabled')->default(1);
+            $table->softDeletes();
+            $table->timestamps();
+        });
+    }
+
+    /**
+     * Reverse the migrations.
+     *
+     * @return void
+     */
+    public function down()
+    {
+        Schema::dropIfExists('vats');
+    }
+};

+ 53 - 0
database/migrations/2024_04_09_112300_create_sponsors_table.php

@@ -0,0 +1,53 @@
+<?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::create('sponsors', function (Blueprint $table) {
+            $table->id();
+            $table->string('name');
+            $table->string('first_name')->nullable();
+            $table->string('last_name')->nullable();
+            $table->string('fiscal_code', 16)->nullable();
+            $table->string('vat', 16)->nullable();
+            $table->string('address')->nullable();
+            $table->string('zip_code', 5)->nullable();
+            $table->unsignedBigInteger('nation_id')->nullable();
+            $table->foreign('nation_id')->nullable()->references('id')->on('nations')->onUpdate('cascade')->onDelete('cascade');
+            $table->unsignedBigInteger('province_id')->nullable();
+            $table->foreign('province_id')->nullable()->references('id')->on('provinces')->onUpdate('cascade')->onDelete('cascade');
+            $table->unsignedBigInteger('city_id')->nullable();
+            $table->foreign('city_id')->nullable()->references('id')->on('cities')->onUpdate('cascade')->onDelete('cascade');
+
+            $table->string('phone')->nullable();
+            $table->string('email')->nullable();
+
+            $table->integer('enabled')->default(1);
+
+
+
+
+            $table->softDeletes();
+            $table->timestamps();
+        });
+    }
+
+    /**
+     * Reverse the migrations.
+     *
+     * @return void
+     */
+    public function down()
+    {
+        Schema::dropIfExists('sponsors');
+    }
+};

+ 38 - 0
database/migrations/2024_04_09_112500_create_sponsor_contracts_table.php

@@ -0,0 +1,38 @@
+<?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::create('sponsor_contracts', function (Blueprint $table) {
+            $table->id();
+            $table->unsignedBigInteger('sponsor_id')->nullable();
+            $table->foreign('sponsor_id')->nullable()->references('id')->on('sponsors')->onUpdate('cascade')->onDelete('cascade');
+            $table->datetime('from_date');
+            $table->datetime('to_date');
+            $table->datetime('subscription_date');
+            $table->decimal('amount', $precision = 8, $scale = 2);
+            $table->string('file')->nullable();
+            $table->softDeletes();
+            $table->timestamps();
+        });
+    }
+
+    /**
+     * Reverse the migrations.
+     *
+     * @return void
+     */
+    public function down()
+    {
+        Schema::dropIfExists('sponsor_contracts');
+    }
+};

+ 33 - 0
database/migrations/2024_04_10_083444_add_vat_id_to_records_rows_table.php

@@ -0,0 +1,33 @@
+<?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->unsignedBigInteger('vat_id')->nullable();
+            $table->foreign('vat_id')->nullable()->references('id')->on('vats')->onUpdate('cascade')->onDelete('cascade');
+        });
+    }
+
+    /**
+     * Reverse the migrations.
+     *
+     * @return void
+     */
+    public function down()
+    {
+        Schema::table('records_rows', function (Blueprint $table) {
+            $table->dropColumn('vat_id');
+        });
+    }
+};

+ 5 - 0
resources/views/layouts/app.blade.php

@@ -43,6 +43,11 @@
                             <i class="ico--ui ico--ui_menu fornitori"></i> <span class="ms-3 d-none d-md-inline">Fornitori</span>
                         </a>
                     </li>
+                    <li class="nav-item sponsors">
+                        <a href="/sponsors" class="nav-link d-flex align-items-center">
+                            <i class="ico--ui ico--ui_menu  primanota"></i> <span class="ms-3 d-none d-md-inline">Sponsor</span>
+                        </a>
+                    </li>
                 </ul>
 
                 <ul class="nav nav-pills flex-column align-items-center align-items-sm-start w-100" id="menu-contabilita">

+ 117 - 35
resources/views/livewire/records_in.blade.php

@@ -393,7 +393,7 @@
                                         <div class="col-md-6">
                                             <span class="total primary">Importo</span>
                                         </div>
-                                        <div class="col-md-6">
+                                        <div class="col-md-3">
                                             @if($add)
                                                 <input type="text" class="form-control totalInput text-end @error('amount') is-invalid @enderror" id="rows.{{$idx}}.amount" wire:model="rows.{{$idx}}.amount" wire:keydown.enter="store(false)" onkeyup="onlyNumberAmount(this)" placeholder="€ 0,00">
                                             @endif
@@ -404,6 +404,16 @@
                                                 <div class="invalid-feedback">{{ $message }}</div>
                                             @enderror
                                         </div>
+                                        @if ($rows[$idx]["commercial"])
+                                            <div class="col-md-3">
+                                                <select id="rows.{{$idx}}.vat_id" class="form-select"  wire:model="rows.{{$idx}}.vat_id">
+                                                    <option value="0">
+                                                    @foreach($vats as $vat)
+                                                        <option value="{{$vat->id}}">{{$vat->name}}
+                                                    @endforeach
+                                                </select>
+                                            </div>
+                                        @endif
                                     </div>
 
                                     <div class="row gx-2 mt-5 align-items-center">
@@ -412,41 +422,110 @@
                                         </div>
                                         <div class="col-md-8">
                                             <div class="row">
-                                                @foreach($row["when"] as $xxx => $w)
-                                                    <div class="col-md-5">
-                                                        <span class="title-form d-block w-100">Mese</span>
-                                                        <div class="input-group mb-3">
-                                                            <select class="form-select form-select-lg me-1"  wire:model="rows.{{$idx}}.when.{{$xxx}}.month">
-                                                                <option value="1">Gennaio</option>
-                                                                <option value="2">Febbraio</option>
-                                                                <option value="3">Marzo</option>
-                                                                <option value="4">Aprile</option>
-                                                                <option value="5">Maggio</option>
-                                                                <option value="6">Giugno</option>
-                                                                <option value="7">Luglio</option>
-                                                                <option value="8">Agosto</option>
-                                                                <option value="9">Settembre</option>
-                                                                <option value="10">Ottobre</option>
-                                                                <option value="11">Novembre</option>
-                                                                <option value="12">Dicembre</option>
-                                                            </select>
+
+                                                @if($multiP)
+                                                    <div class="row">
+                                                        <div class="col-md-3">
+                                                            <span class="title-form d-block w-100">Dal mese</span>
+                                                            <div class="input-group mb-3">
+                                                                <select class="form-select form-select-lg me-1"  wire:model="multiMonthFrom">
+                                                                    <option value="1">Gennaio</option>
+                                                                    <option value="2">Febbraio</option>
+                                                                    <option value="3">Marzo</option>
+                                                                    <option value="4">Aprile</option>
+                                                                    <option value="5">Maggio</option>
+                                                                    <option value="6">Giugno</option>
+                                                                    <option value="7">Luglio</option>
+                                                                    <option value="8">Agosto</option>
+                                                                    <option value="9">Settembre</option>
+                                                                    <option value="10">Ottobre</option>
+                                                                    <option value="11">Novembre</option>
+                                                                    <option value="12">Dicembre</option>
+                                                                </select>
+                                                            </div>
                                                         </div>
-                                                    </div>
-                                                    <div class="col-md-5">
-                                                        <span class="title-form d-block w-100">Anno</span>
-                                                        <div class="input-group mb-3">
-                                                            <input type="number" class="form-control"  wire:model="rows.{{$idx}}.when.{{$xxx}}.year" >
+                                                        <div class="col-md-3">
+                                                            <span class="title-form d-block w-100">Anno</span>
+                                                            <div class="input-group mb-3">
+                                                                <input type="number" class="form-control"  wire:model="multiYearFrom" >
+                                                            </div>
+                                                        </div>
+                                                        <div class="col-md-3">
+                                                            <span class="title-form d-block w-100">Dal mese</span>
+                                                            <div class="input-group mb-3">
+                                                                <select class="form-select form-select-lg me-1"  wire:model="multiMonthTo">
+                                                                    <option value="1">Gennaio</option>
+                                                                    <option value="2">Febbraio</option>
+                                                                    <option value="3">Marzo</option>
+                                                                    <option value="4">Aprile</option>
+                                                                    <option value="5">Maggio</option>
+                                                                    <option value="6">Giugno</option>
+                                                                    <option value="7">Luglio</option>
+                                                                    <option value="8">Agosto</option>
+                                                                    <option value="9">Settembre</option>
+                                                                    <option value="10">Ottobre</option>
+                                                                    <option value="11">Novembre</option>
+                                                                    <option value="12">Dicembre</option>
+                                                                </select>
+                                                            </div>
+                                                        </div>
+                                                        <div class="col-md-3">
+                                                            <span class="title-form d-block w-100">Anno</span>
+                                                            <div class="input-group mb-3">
+                                                                <input type="number" class="form-control"  wire:model="multiYearTo" >
+                                                            </div>
                                                         </div>
                                                     </div>
-                                                    <div class="col-md-2"><br>
-                                                        <button type="button" class="btn--ui primary" wire:click.prevent="delPeriod({{$idx}}, {{$xxx}})" style="float:right">
-                                                            -
-                                                        </button>
-                                                    </div>
-                                                @endforeach
-                                                <button type="button" class="btn--ui primary" wire:click.prevent="addPeriod({{$idx}})">
-                                                    Aggiungi periodo
-                                                </button>
+                                                    <button type="button" class="btn--ui primary" wire:click.prevent="multiPeriodCreate({{$idx}})" style="margin-top:20px">
+                                                        Crea multi periodo
+                                                    </button>
+                                                @else
+
+                                                    @foreach($row["when"] as $xxx => $w)
+                                                        <div class="col-md-4">
+                                                            <span class="title-form d-block w-100">Mese</span>
+                                                            <div class="input-group mb-3">
+                                                                <select class="form-select form-select-lg me-1"  wire:model="rows.{{$idx}}.when.{{$xxx}}.month">
+                                                                    <option value="1">Gennaio</option>
+                                                                    <option value="2">Febbraio</option>
+                                                                    <option value="3">Marzo</option>
+                                                                    <option value="4">Aprile</option>
+                                                                    <option value="5">Maggio</option>
+                                                                    <option value="6">Giugno</option>
+                                                                    <option value="7">Luglio</option>
+                                                                    <option value="8">Agosto</option>
+                                                                    <option value="9">Settembre</option>
+                                                                    <option value="10">Ottobre</option>
+                                                                    <option value="11">Novembre</option>
+                                                                    <option value="12">Dicembre</option>
+                                                                </select>
+                                                            </div>
+                                                        </div>
+                                                        <div class="col-md-3">
+                                                            <span class="title-form d-block w-100">Anno</span>
+                                                            <div class="input-group mb-3">
+                                                                <input type="number" class="form-control"  wire:model="rows.{{$idx}}.when.{{$xxx}}.year" >
+                                                            </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>
+                                                        </div>
+                                                        <div class="col-md-2"><br>
+                                                            <button type="button" class="btn--ui primary" wire:click.prevent="delPeriod({{$idx}}, {{$xxx}})" style="float:right">
+                                                                -
+                                                            </button>
+                                                        </div>
+                                                    @endforeach
+                                                    <button type="button" class="btn--ui primary" wire:click.prevent="addPeriod({{$idx}})">
+                                                        Aggiungi periodo
+                                                    </button>
+
+                                                    <button type="button" class="btn--ui primary" wire:click.prevent="multiPeriod()" style="margin-top:20px">
+                                                        Imposta multi periodo
+                                                    </button>
+                                                @endif
+
                                             </div>
                                         </div>
                                     </div>
@@ -528,13 +607,16 @@
                             <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->getTotal()}}</strong></span>
+                                        <span class="amount_p"><strong>Importo</strong></span><span class="amount_data"><strong>{{$this->getPrice()}}</strong></span>
+                                    </div>
+                                    <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>
                                     <!--<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 Netto</strong></span><span class="netprice_data"><strong>{{$this->getTotal()}}</strong></span>
+                                        <span class="netprice_p"><strong>Totale</strong></span><span class="netprice_data"><strong>{{$this->getTotal()}}</strong></span>
                                     </div>
                                 </div>
 

+ 6 - 1
resources/views/livewire/records_in_out.blade.php

@@ -47,7 +47,7 @@
                 <button class="btn--ui reset" wire:click="clear()" style="margin-left:5px;">reset</button>
                 @if($showData)
                     <button class="btn--ui reset" wire:click="export()" style="margin-left:5px;">esporta</button>
-                    <button class="btn--ui reset" wire:click="exportYear()" style="margin-left:5px;">esporta anno selezionato</button>
+                    <button class="btn--ui reset exportYear"  style="margin-left:5px;">esporta anno selezionato</button>
                 @endif
 
             </section>
@@ -270,6 +270,11 @@
             @this.show(m, y);
         });
 
+        $(document).on("click", ".exportYear", function () {
+            var y = $('#year').val();
+            @this.exportYear(y);
+        });
+
     </script>
 
 @endpush

+ 83 - 15
resources/views/livewire/records_out.blade.php

@@ -375,12 +375,13 @@
                                             <span class="total primary">Periodo</span>
                                         </div>
                                         <div class="col-md-8">
-                                            <div class="row">
-                                                @foreach($row["when"] as $xxx => $w)
-                                                    <div class="col-md-5">
-                                                        <span class="title-form d-block w-100">Mese</span>
+
+                                            @if($multiP)
+                                                <div class="row">
+                                                    <div class="col-md-3">
+                                                        <span class="title-form d-block w-100">Dal mese</span>
                                                         <div class="input-group mb-3">
-                                                            <select class="form-select form-select-lg me-1"  wire:model="rows.{{$idx}}.when.{{$xxx}}.month">
+                                                            <select class="form-select form-select-lg me-1"  wire:model="multiMonthFrom">
                                                                 <option value="1">Gennaio</option>
                                                                 <option value="2">Febbraio</option>
                                                                 <option value="3">Marzo</option>
@@ -396,22 +397,89 @@
                                                             </select>
                                                         </div>
                                                     </div>
-                                                    <div class="col-md-5">
+                                                    <div class="col-md-3">
                                                         <span class="title-form d-block w-100">Anno</span>
                                                         <div class="input-group mb-3">
-                                                            <input type="number" class="form-control"  wire:model="rows.{{$idx}}.when.{{$xxx}}.year" >
+                                                            <input type="number" class="form-control"  wire:model="multiYearFrom" >
                                                         </div>
                                                     </div>
-                                                    <div class="col-md-2"><br>
-                                                        <button type="button" class="btn--ui primary" wire:click.prevent="delPeriod({{$idx}}, {{$xxx}})" style="float:right">
-                                                            -
-                                                        </button>
+                                                    <div class="col-md-3">
+                                                        <span class="title-form d-block w-100">Dal mese</span>
+                                                        <div class="input-group mb-3">
+                                                            <select class="form-select form-select-lg me-1"  wire:model="multiMonthTo">
+                                                                <option value="1">Gennaio</option>
+                                                                <option value="2">Febbraio</option>
+                                                                <option value="3">Marzo</option>
+                                                                <option value="4">Aprile</option>
+                                                                <option value="5">Maggio</option>
+                                                                <option value="6">Giugno</option>
+                                                                <option value="7">Luglio</option>
+                                                                <option value="8">Agosto</option>
+                                                                <option value="9">Settembre</option>
+                                                                <option value="10">Ottobre</option>
+                                                                <option value="11">Novembre</option>
+                                                                <option value="12">Dicembre</option>
+                                                            </select>
+                                                        </div>
                                                     </div>
-                                                @endforeach
-                                                <button type="button" class="btn--ui primary" wire:click.prevent="addPeriod({{$idx}})">
-                                                    Aggiungi periodo
+                                                    <div class="col-md-3">
+                                                        <span class="title-form d-block w-100">Anno</span>
+                                                        <div class="input-group mb-3">
+                                                            <input type="number" class="form-control"  wire:model="multiYearTo" >
+                                                        </div>
+                                                    </div>
+                                                </div>
+                                                <button type="button" class="btn--ui primary" wire:click.prevent="multiPeriodCreate({{$idx}})" style="margin-top:20px">
+                                                    Crea multi periodo
                                                 </button>
-                                            </div>
+                                            @else
+
+                                                <div class="row">
+                                                    @foreach($row["when"] as $xxx => $w)
+                                                        <div class="col-md-4">
+                                                            <span class="title-form d-block w-100">Mese</span>
+                                                            <div class="input-group mb-3">
+                                                                <select class="form-select form-select-lg me-1"  wire:model="rows.{{$idx}}.when.{{$xxx}}.month">
+                                                                    <option value="1">Gennaio</option>
+                                                                    <option value="2">Febbraio</option>
+                                                                    <option value="3">Marzo</option>
+                                                                    <option value="4">Aprile</option>
+                                                                    <option value="5">Maggio</option>
+                                                                    <option value="6">Giugno</option>
+                                                                    <option value="7">Luglio</option>
+                                                                    <option value="8">Agosto</option>
+                                                                    <option value="9">Settembre</option>
+                                                                    <option value="10">Ottobre</option>
+                                                                    <option value="11">Novembre</option>
+                                                                    <option value="12">Dicembre</option>
+                                                                </select>
+                                                            </div>
+                                                        </div>
+                                                        <div class="col-md-3">
+                                                            <span class="title-form d-block w-100">Anno</span>
+                                                            <div class="input-group mb-3">
+                                                                <input type="number" class="form-control"  wire:model="rows.{{$idx}}.when.{{$xxx}}.year" >
+                                                            </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"]) / sizeof($rows[$idx]["when"])) : ""}}</b></span>
+                                                        </div>
+
+                                                        <div class="col-md-2"><br>
+                                                            <button type="button" class="btn--ui primary" wire:click.prevent="delPeriod({{$idx}}, {{$xxx}})" style="float:right">
+                                                                -
+                                                            </button>
+                                                        </div>
+                                                    @endforeach
+                                                    <button type="button" class="btn--ui primary" wire:click.prevent="addPeriod({{$idx}})">
+                                                        Aggiungi periodo
+                                                    </button>
+                                                    <button type="button" class="btn--ui primary" wire:click.prevent="multiPeriod()" style="margin-top:20px">
+                                                        Imposta multi periodo
+                                                    </button>
+                                                </div>
+                                            @endif
                                         </div>
                                     </div>
 

+ 5 - 0
resources/views/livewire/settings.blade.php

@@ -56,6 +56,11 @@
                     <i class="ico--ui ico--ui_menu primanota"></i> <span class="ms-3 d-none d-md-inline">Causali</span>
                 </a>
             </div>
+            <div class="col-md-3 p-3">
+                <a href="/vats" class="nav-link d-flex align-items-center">
+                    <i class="ico--ui ico--ui_menu primanota"></i> <span class="ms-3 d-none d-md-inline">IVA</span>
+                </a>
+            </div>
         </div>
     </div>
 

+ 479 - 0
resources/views/livewire/sponsor.blade.php

@@ -0,0 +1,479 @@
+
+<div class="col card--ui" id="card--dashboard">
+
+    <header id="title--section" 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>
+            <h2 class="primary">@if(!$add && !$update)Elenco Sponsor @else Inserimento/modifica sponsor @endif</h2>
+        </div>
+
+        @if(!$add && !$update)
+            <div class="title--section_addButton"  wire:click="add()" style="cursor: pointer;">
+                <div class="card--ui card--ui_btnAddHeaderUser entrata d-flex justify-items-between">
+                    <header class="d-flex justify-content-between"><div class="card-title d-flex align-items-start"><h2>Aggiungi&nbsp;&nbsp;&nbsp;</h2></div><a href="#" wire:click="add()"><i class="ico--ui big add primary"></i></a></header>
+                </div>
+            </div>
+        @endif
+
+    </header>
+
+    @if(!$add && !$update)
+
+        <section id="subheader" class="d-flex align-items-center justify-content-between">
+
+            <form action="" class="search--form d-flex align-items-center">
+                <div class="input-group mb-3">
+                    <input type="text" class="form-control" placeholder="Cerca sponsor" aria-label="cerca utent" aria-describedby="button-addon2" wire:model="search">
+                    @if(false)
+                        @if($showReset)
+                            <button class="btn--ui" type="button" id="button-addon2" wire:click="resetSearch()"><i class="ico--ui search"></i>Reset</button>
+                        @else
+                            <button class="btn--ui" type="button" id="button-addon2" wire:click="search()"><i class="ico--ui search"></i>Cerca</button>
+                        @endif
+                    @endif
+                </div>
+            </form>
+        </section>
+
+        <section id="resume-table">
+            <div class="compare--chart_wrapper d-none"></div>
+
+            <table class="table tablesaw tablesaw-stack" data-tablesaw="" id="tablesaw-350">
+                <thead>
+                    <tr>
+                        <th scope="col" wire:click.prevent="sortBy('name')" style="cursor:pointer">Ragione sociale&nbsp;&nbsp;&nbsp;<i class="fa fa-sort"></i></th>
+                        <th scope="col" wire:click.prevent="sortBy('first_name')" style="cursor:pointer">Nome&nbsp;&nbsp;&nbsp;<i class="fa fa-sort"></i></th>
+                        <th scope="col" wire:click.prevent="sortBy('last_name')" style="cursor:pointer">Cognome&nbsp;&nbsp;&nbsp;<i class="fa fa-sort"></i></th>
+                        <th scope="col" wire:click.prevent="sortBy('address')" style="cursor:pointer">Indirizzo&nbsp;&nbsp;&nbsp;<i class="fa fa-sort"></i></th>
+                        <th scope="col" wire:click.prevent="sortBy('email')" style="cursor:pointer">Email&nbsp;&nbsp;&nbsp;<i class="fa fa-sort"></i></th>
+                        <th scope="col" wire:click.prevent="sortBy('enabled')" style="cursor:pointer">Abilitato&nbsp;&nbsp;&nbsp;<i class="fa fa-sort"></i></th>
+                        <th scope="col">...</th>
+                    </tr>
+                </thead>
+                <tbody id="checkall-target">
+                    @foreach($records as $record)
+                        <tr>
+                            <td>{{$record->name}}</td>
+                            <td>{{$record->first_name}}</td>
+                            <td>{{$record->last_name}}</td>
+                            <td>{{$record->address}}</td>
+                            <td>{{$record->email}}</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-primary btn-sm" wire:click="edit({{ $record->id }})">Modifica</button>
+                                <button type="button" class="btn btn-outline-danger btn-sm" onclick="confirm('Sei sicuro?') || event.stopImmediatePropagation()" wire:click="delete({{ $record->id }})">Elimina</button>
+                            </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
+
+
+
+            @if (session()->has('error'))
+                <div class="alert alert-danger" role="alert">
+                    {{ session()->get('error') }}
+                </div>
+            @endif
+
+            <section id="card--container" class="">
+
+                <div id="card--nuovoUtente">
+                    <ul class="nav nav-tabs" id="myTab" role="tablist">
+                        <li class="nav-item" role="presentation">
+                        <button wire:ignore.self class="nav-link active" id="home-tab" data-bs-toggle="tab" data-bs-target="#home-tab-pane" type="button" role="tab" aria-controls="home-tab-pane" aria-selected="true">INFO GENERICHE</button>
+                        </li>
+                        <li class="nav-item" role="presentation">
+                        <button wire:ignore.self class="nav-link" id="profile-tab" data-bs-toggle="tab" data-bs-target="#profile-tab-pane" type="button" role="tab" aria-controls="profile-tab-pane" aria-selected="false">CONTRATTI</button>
+                        </li>
+                    </ul>
+                    <div class="tab-content card--ui" id="myTabContent">
+
+                        <!-- TAB INFO GENERICHE -->
+                        <div class="tab-pane fade show active info-tab" id="home-tab-pane" role="tabpanel" aria-labelledby="home-tab" tabindex="0" wire:ignore.self>
+                            <div class="form--wrapper">
+                                <form class="form--utente">
+                                    <div class="">
+                                        <div class="row g-3">
+                                            <div class="col">
+                                                <div class="form--item">
+                                                    <label for="inputName" class="form-label">Ragione sociale</label>
+                                                    <input class="form-control js-keyupTitle @error('name') is-invalid @enderror" type="text" id="name" placeholder="Ragione sociale" wire:model="name">
+                                                    @error('name')
+                                                        <div class="invalid-feedback">{{ $message }}</div>
+                                                    @enderror
+                                                </div>
+                                            </div>
+
+                                        </div>
+
+                                        <div class="row mb-3">
+                                            <div class="col">
+                                                <div class="form--item">
+                                                    <label for="first_name" class="form-label">Nome</label>
+                                                    <input class="form-control" type="text" id="first_name" placeholder="Nome" wire:model="first_name">
+                                                </div>
+                                            </div>
+                                            <div class="col">
+                                                <div class="form--item">
+                                                    <label for="last_name" class="form-label">Cognome</label>
+                                                    <input class="form-control" type="text" id="last_name" placeholder="Cognome" wire:model="last_name">
+                                                </div>
+                                            </div>
+                                        </div>
+
+                                        <div class="row mb-3">
+                                            <div class="col">
+                                                <div class="form--item">
+                                                    <label for="address" class="form-label">Indirizzo</label>
+                                                    <input class="form-control" type="text" id="address" placeholder="Indirizzo" wire:model="address">
+                                                </div>
+                                            </div>
+                                            <div class="col">
+                                                <div class="form--item">
+                                                    <label for="zip_code" class="form-label">CAP</label>
+                                                    <input class="form-control" type="text" id="zip_code" placeholder="CAP" wire:model="zip_code">
+                                                </div>
+                                            </div>
+                                        </div>
+
+                                        <div class="row mb-3">
+                                            <div class="col">
+                                                <label for="nation_id" class="form-label">Nazione</label>
+                                                <select name="nation_id" class="form-select nationClass" aria-label="Seleziona una nazione" wire:model="nation_id">
+                                                    <option value="{{$nation_id}}">{{$this->getNation($nation_id)}}
+                                                </select>
+                                            </div>
+                                            @if($isItaly)
+                                                <div class="col">
+                                                    <label for="province_id" class="form-label">Provincia</label>
+                                                    <select name="province_id" class="form-select provinceClass" aria-label="Seleziona una provincia" wire:model="province_id">
+                                                        <option value="{{$province_id}}">{{$this->getProvince($province_id)}}
+                                                    </select>
+                                                </div>
+                                                <div class="col">
+                                                    <label for="city_id" class="form-label">Comune</label>
+                                                    <select name="city_id" class="form-select cityClass" aria-label="Seleziona un comune" wire:model="city_id">
+                                                        <option value="{{$city_id}}">{{$this->getCity($city_id)}}
+                                                    </select>
+                                                </div>
+                                            @else
+                                                <div class="col"></div>
+                                                <div class="col"></div>
+                                            @endif
+                                        </div>
+
+                                        <div class="row mb-3">
+                                            <div class="col">
+                                                <div class="form--item">
+                                                    <label for="fiscal_code" class="form-label">Codice fiscale</label>
+                                                    <input class="form-control" type="text" id="fiscal_code" placeholder="Codice fiscale" wire:model="fiscal_code">
+                                                </div>
+                                            </div>
+                                            <div class="col">
+                                                <div class="form--item">
+                                                    <label for="vat" class="form-label">Partita iva</label>
+                                                    <input class="form-control" type="text" id="vat" placeholder="Partita iva" wire:model="vat">
+                                                </div>
+                                            </div>
+                                        </div>
+
+                                        <div class="row mb-3">
+
+                                            <div class="col">
+                                                <div class="form--item">
+                                                    <label for="phone" class="form-label">Telefono</label>
+                                                    <input class="form-control" type="text" id="phone" placeholder="Telefono" wire:model="phone">
+                                                </div>
+                                            </div>
+                                            <div class="col">
+                                                <div class="form--item">
+                                                    <label for="email" class="form-label">Email</label>
+                                                    <input class="form-control" type="text" id="email" placeholder="Email" wire:model="email">
+                                                </div>
+                                            </div>
+                                        </div>
+
+                                        <span class="title-form primary d-block w-100">Contratti</span>
+
+                                        <div class="row mb-3">
+                                            <div class="col">
+                                                <div class="form--item">
+                                                    <div class="form-check form-check-inline">
+                                                        <input class="form-check-input" type="checkbox" id="enabled" wire:model="enabled">
+                                                        <label class="form-check-label" for="enabled">Abilitato</label>
+                                                    </div>
+                                                </div>
+                                            </div>
+                                        </div>
+                                    </div>
+                                </form>
+                            </div>
+                        </div>
+
+                        <div class="tab-pane fade tasseramento-tab" id="profile-tab-pane" role="tabpanel" aria-labelledby="profile-tab" tabindex="0" wire:ignore.self>
+
+                            @if(!$addContract && !$updateContract)
+
+
+                                <section id="resume-table">
+                                    <div class="compare--chart_wrapper d-none"></div>
+
+                                    <table class="table tablesaw tablesaw-stack" data-tablesaw="" id="tablesaw-350">
+                                        <thead>
+                                            <tr>
+                                                <th scope="col">Data inizio</th>
+                                                <th scope="col">Data fine</th>
+                                                <th scope="col">Data sottoscrizione</th>
+                                                <th scope="col">Valore</th>
+                                                <th scope="col">Contratto</th>
+                                                <th scope="col">...</th>
+                                            </tr>
+                                        </thead>
+                                        <tbody id="checkall-target">
+                                            @foreach($contracts as $contract)
+                                                <tr>
+                                                    <td>{{date("d/m/Y", strtotime($contract->from_date))}}</td>
+                                                    <td>{{date("d/m/Y", strtotime($contract->to_date))}}</td>
+                                                    <td>{{date("d/m/Y", strtotime($contract->subscription_date))}}</td>
+                                                    <td>{{$contract->amount}}</td>
+                                                    <td>{!!$contract->file != '' ? '<a href="/storage/app/public/' . $contract->file . '" target="_blank">Visualizza</a>' : ''!!}</td>
+                                                    <td>
+                                                        <button type="button" class="btn btn-outline-primary btn-sm" wire:click="editContract({{ $contract->id }})">Modifica</button>
+                                                        <button type="button" class="btn btn-outline-danger btn-sm" onclick="confirm('Sei sicuro?') || event.stopImmediatePropagation()" wire:click="deleteContract({{ $contract->id }})">Elimina</button>
+                                                    </td>
+                                                </tr>
+                                            @endforeach
+
+                                        </tbody>
+                                    </table>
+
+                                    <button type="submit" class="btn--ui" wire:click.prevent="addContract()">Aggiungi</button>
+
+                                </section>
+
+                            @else
+
+                                <div class="container">
+
+                                    <div class="row">
+                                        <div class="col">
+
+                                            <form action="">
+
+                                                <div class="row mb-3">
+                                                    <div class="col">
+                                                        <div class="form--item">
+                                                            <label class="form-label">Data inizio</label>
+                                                            <input class="form-control @error('from_date') is-invalid @enderror" type="date"  wire:model="from_date">
+                                                            @error('from_date')
+                                                                <div class="invalid-feedback">{{ $message }}</div>
+                                                            @enderror
+                                                        </div>
+                                                    </div>
+                                                    <div class="col">
+                                                        <div class="form--item">
+                                                            <label class="form-label">Data fine</label>
+                                                            <input class="form-control js-keyupTitle @error('to_date') is-invalid @enderror" type="date"  placeholder="Data fine" wire:model="to_date">
+                                                            @error('to_date')
+                                                                <div class="invalid-feedback">{{ $message }}</div>
+                                                            @enderror
+                                                        </div>
+                                                    </div>
+                                                    <div class="col">
+                                                        <div class="form--item">
+                                                            <label class="form-label">Data sottoscrizione</label>
+                                                            <input class="form-control js-keyupTitle @error('subscription_date') is-invalid @enderror" type="date" id="subscription_date" placeholder="Data sottoscrizione" wire:model="subscription_date">
+                                                            @error('subscription_date')
+                                                                <div class="invalid-feedback">{{ $message }}</div>
+                                                            @enderror
+                                                        </div>
+                                                    </div>
+                                                    <div class="col">
+                                                        <div class="form--item">
+                                                            <label class="form-label">Importo</label>
+                                                            <input class="form-control js-keyupTitle @error('amount') is-invalid @enderror" type="text" id="amount" placeholder="Importo" wire:model="amount">
+                                                            @error('amount')
+                                                                <div class="invalid-feedback">{{ $message }}</div>
+                                                            @enderror
+                                                        </div>
+                                                    </div>
+                                                    <div class="col">
+                                                        <div class="form--item">
+                                                            <label class="form-label">Contratto</label>
+                                                            <input class="form-control" type="file" wire:model="file">
+                                                            {!!$file_old != '' ? '<br><a href="/storage/app/public/' . $file_old . '" target="_blank">Visualizza</a>' : ''!!}
+                                                        </div>
+                                                    </div>
+                                                </div>
+
+                                                <div class="form--item">
+                                                    @if($addContract)
+                                                        <button type="submit" class="btn--ui" wire:click.prevent="storeContract()">Salva</button>
+                                                    @endif
+                                                    @if($updateContract)
+                                                        <button type="submit" class="btn--ui" wire:click.prevent="updateContract()">Salva</button>
+                                                    @endif
+                                                    <button type="button" class="btn--ui lightGrey" wire:click="cancelContract()">Annulla</button>
+                                                </div>
+
+                                            </form>
+                                        </div>
+                                    </div>
+                                </div>
+
+                            @endif
+
+                        </div>
+                    </div>
+                </div>
+
+            </section>
+
+            <section class="save--section d-flex justify-content-start">
+                @if($add)
+                    <button type="submit" class="btn--ui" wire:click.prevent="store()">Salva</button>
+                @endif
+                @if($update)
+                    <button type="submit" class="btn--ui" wire:click.prevent="update()">Salva</button>
+                @endif
+                <button type="button" class="btn--ui lightGrey" wire:click="cancel()">Annulla</button>
+            </section>
+
+
+
+    @endif
+</div>
+
+@push('scripts')
+    <link href="https://cdn.jsdelivr.net/npm/select2@4.1.0-rc.0/dist/css/select2.min.css" rel="stylesheet" />
+    <style>
+        .select2-container--default .select2-selection--single{
+            background-color: #E9F0F5;
+            border: 0.0625rem solid #DFE5EB;
+            font-size: 0.75rem;
+        }
+        .select2-selection
+        {
+            height: 38px !important;
+        }
+        .select2-selection__rendered
+        {
+            padding-top:3px;
+        }
+    </style>
+    <script src="https://code.jquery.com/jquery-2.2.4.min.js" integrity="sha256-BbhdlvQf/xTY9gja0Dq3HiwQF8LaCRTXxZKRutelT44=" crossorigin="anonymous"></script>
+    <script src="https://cdn.jsdelivr.net/npm/select2@4.1.0-rc.0/dist/js/select2.min.js"></script>
+@endpush
+
+@push('scripts')
+    <script>
+        function matchStart(params, data) {
+            params.term = params.term || '';
+            if (data.text.toUpperCase().indexOf(params.term.toUpperCase()) == 0) {
+                return data;
+            }
+            return false;
+        }
+        var nation_id = 0;
+        var province_id = 0;
+
+        Livewire.on('load-select', () => {
+
+            $('.nationClass').select2({
+                ajax: {
+                    url: '/nations',
+                    dataType: 'json'
+                }
+            });
+
+            $('.nationClass').on('change', function (e) {
+                nation_id = $('.nationClass').select2("val");
+                province_id = 0;
+                @this.set('nation_id', nation_id);
+                @this.set('province_id', 0);
+                @this.set('city_id', 0);
+                @this.checkIsItaly();
+            });
+
+            $('.provinceClass').select2({
+                ajax: {
+                    url: '/provinces/' + nation_id,
+                    dataType: 'json'
+                }
+            });
+            $('.provinceClass').on('change', function (e) {
+                province_id = $('.provinceClass').select2("val");
+                @this.set('province_id', province_id);
+                @this.set('city_id', 0);
+            });
+
+            $('.cityClass').select2({
+                ajax: {
+                    url: '/cities/' + province_id,
+                    dataType: 'json'
+                }
+            });
+            $('.cityClass').on('change', function (e) {
+                var data = $('.cityClass').select2("val");
+                @this.set('city_id', data);
+
+            });
+
+            $('.nationBirthClass').select2({
+                ajax: {
+                    url: '/nations',
+                    dataType: 'json'
+                }
+            });
+
+        });
+
+        Livewire.on('load-provinces', (nation_id, element) => {
+            $('.' + element).select2({
+                ajax: {
+                    url: '/provinces/' + nation_id,
+                    dataType: 'json'
+                }
+            });
+        });
+
+        Livewire.on('load-cities', (province_id, element) => {
+            $('.' + element).select2({
+                ajax: {
+                    url: '/cities/' + province_id,
+                    dataType: 'json'
+                }
+            });
+        });
+
+    </script>
+
+
+@endpush

+ 108 - 0
resources/views/livewire/vat.blade.php

@@ -0,0 +1,108 @@
+<div class="col card--ui" id="card--dashboard">
+    @if(!$add && !$update)
+
+        <header id="title--section" 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>
+                <h2 class="primary">Elenco IVA</h2>
+            </div>
+
+            <div class="title--section_addButton"  wire:click="add()" style="cursor: pointer;">
+                <div class="card--ui card--ui_btnAddHeaderUser entrata d-flex justify-items-between">
+                    <header class="d-flex justify-content-between"><div class="card-title d-flex align-items-start"><h2>Aggiungi&nbsp;&nbsp;&nbsp;</h2></div><a href="#" wire:click="add()"><i class="ico--ui big add primary"></i></a></header>
+                </div>
+            </div>
+
+        </header>
+
+        <section id="resume-table">
+            <div class="compare--chart_wrapper d-none"></div>
+
+            <table class="table tablesaw tablesaw-stack" data-tablesaw="" id="tablesaw-350">
+                <thead>
+                    <tr>
+                        <th scope="col" wire:click.prevent="sortBy('name')" style="cursor:pointer">Nome&nbsp;&nbsp;&nbsp;<i class="fa fa-sort"></i></th>
+                        <th scope="col" wire:click.prevent="sortBy('value')" style="cursor:pointer">IVA&nbsp;&nbsp;&nbsp;<i class="fa fa-sort"></i></th>
+                        <th scope="col" wire:click.prevent="sortBy('enabled')" style="cursor:pointer">Abilitato&nbsp;&nbsp;&nbsp;<i class="fa fa-sort"></i></th>
+                        <th scope="col">...</th>
+                    </tr>
+                </thead>
+                <tbody id="checkall-target">
+                    @foreach($records as $record)
+                        <tr>
+                            <td>{{$record->name}}</td>
+                            <td>{{$record->value}}</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-primary btn-sm" wire:click="edit({{ $record->id }})">Modifica</button>
+                                <button type="button" class="btn btn-outline-danger btn-sm" onclick="confirm('Sei sicuro?') || event.stopImmediatePropagation()" wire:click="delete({{ $record->id }})">Elimina</button>
+                            </td>
+                        </tr>
+                    @endforeach
+
+                </tbody>
+            </table>
+
+        </section>
+
+    @else
+
+        <div class="container">
+
+            @if (session()->has('error'))
+                <div class="alert alert-danger" role="alert">
+                    {{ session()->get('error') }}
+                </div>
+            @endif
+
+            <div class="row">
+                <div class="col">
+
+                    <form action="">
+
+                        <div class="row mb-3">
+                            <div class="col">
+                                <div class="form--item">
+                                    <label for="inputName" class="form-label">Nome</label>
+                                    <input class="form-control js-keyupTitle @error('name') is-invalid @enderror" type="text" id="name" placeholder="Nome" wire:model="name">
+                                    @error('name')
+                                        <div class="invalid-feedback">{{ $message }}</div>
+                                    @enderror
+                                </div>
+                            </div>
+                            <div class="col">
+                                <div class="form--item">
+                                    <label for="inputValue" class="form-label">Valore</label>
+                                    <input class="form-control js-keyupTitle @error('value') is-invalid @enderror" type="text" id="value" placeholder="Valore" wire:model="value">
+                                    @error('value')
+                                        <div class="invalid-feedback">{{ $message }}</div>
+                                    @enderror
+                                </div>
+                            </div>
+                            <div class="col">
+                                <div class="form-check form-check-inline">
+                                    <input class="form-check-input" type="checkbox" id="enabled" wire:model="enabled">
+                                    <label class="form-check-label" for="enabled">Abilitato</label>
+                                </div>
+                            </div>
+                        </div>
+
+                        <!-- // inline input field -->
+
+                        <div class="form--item">
+                            @if($add)
+                                <button type="submit" class="btn--ui" wire:click.prevent="store()">Salva</button>
+                            @endif
+                            @if($update)
+                                <button type="submit" class="btn--ui" wire:click.prevent="update()">Salva</button>
+                            @endif
+                            <button type="button" class="btn--ui lightGrey" wire:click="cancel()">Annulla</button>
+                        </div>
+
+                    </form>
+                </div>
+            </div>
+        </div>
+
+    @endif
+</div>

+ 2 - 0
routes/web.php

@@ -26,11 +26,13 @@ Route::get('/nations_list', \App\Http\Livewire\Nation::class);
 Route::get('/provinces', \App\Http\Livewire\Province::class);
 Route::get('/cities', \App\Http\Livewire\City::class);
 Route::get('/banks', \App\Http\Livewire\Bank::class);
+Route::get('/vats', \App\Http\Livewire\Vat::class);
 Route::get('/cards', \App\Http\Livewire\Card::class);
 Route::get('/causals', \App\Http\Livewire\Causal::class);
 Route::get('/payment_methods', \App\Http\Livewire\PaymentMethod::class);
 Route::get('/members', \App\Http\Livewire\Member::class);
 Route::get('/suppliers', \App\Http\Livewire\Supplier::class);
+Route::get('/sponsors', \App\Http\Livewire\Sponsor::class);
 Route::get('/records', \App\Http\Livewire\Record::class);
 Route::get('/reminders', \App\Http\Livewire\Reminder::class);
 Route::get('/in', \App\Http\Livewire\RecordIN::class);