Luca Parisio 1 gadu atpakaļ
vecāks
revīzija
9bc7009ff9

+ 11 - 0
app/Http/Livewire/Causal.php

@@ -8,6 +8,8 @@ class Causal extends Component
 {
     public $recordsIn, $recordsOut, $parent_id,  $name, $enabled, $corrispettivo_fiscale, $money, $user_status, $no_first, $no_records, $type, $dataId, $update = false, $add = false;
 
+    public $corrispettivo_causal_id = 0;
+
     protected $rules = [
         'name' => 'required',
         'type' => 'required'
@@ -17,6 +19,15 @@ class Causal extends Component
         'name.required' => 'Il nome è obbligatorio'
     ];
 
+    public function mount()
+    {
+
+        $fisc = \App\Models\Causal::where('corrispettivo_fiscale', true)->first();
+        if ($fisc)
+            $this->corrispettivo_causal_id = $fisc->id;
+
+    }
+
     public function resetFields(){
         $this->name = '';
         $this->parent_id = null;

+ 24 - 5
app/Http/Livewire/CourseList.php

@@ -23,7 +23,7 @@ class CourseList extends Component
     public $course_frequencies = [];
     public $course_levels = [];
 
-    public $months = array('Gen', 'Feb', 'Mar', 'Apr', 'Mag', 'Giu', 'Lug', 'Ago', 'Set', 'Ott', 'Nov', 'Dic');
+    public $months = array('Set', 'Ott', 'Nov', 'Dic', 'Gen', 'Feb', 'Mar', 'Apr', 'Mag', 'Giu', 'Lug', 'Ago');
 
     public function mount()
     {
@@ -95,6 +95,10 @@ class CourseList extends Component
         {
             $this->records[] = array(
                 $x->member_id . "§" . $x->member->first_name . "§" . $x->member->last_name,
+                $this->getColor($x->months, 9),
+                $this->getColor($x->months, 10),
+                $this->getColor($x->months, 11),
+                $this->getColor($x->months, 12),
                 $this->getColor($x->months, 1),
                 $this->getColor($x->months, 2),
                 $this->getColor($x->months, 3),
@@ -103,12 +107,9 @@ class CourseList extends Component
                 $this->getColor($x->months, 6),
                 $this->getColor($x->months, 7),
                 $this->getColor($x->months, 8),
-                $this->getColor($x->months, 9),
-                $this->getColor($x->months, 10),
-                $this->getColor($x->months, 11),
-                $this->getColor($x->months, 12),
                 $x->course_id,
                 $x->id,
+                $x->subscribed
             );
         }
 
@@ -149,9 +150,27 @@ class CourseList extends Component
 
     public function newPayment($course_id, $month, $member_id, $id)
     {
+        if ($month < 5) $month += 12;
+        if ($month >= 5) $month -= 4;
         $c = \App\Models\Course::findOrFail($course_id);
         return redirect()->to('/in?new=1&memberId=' . $member_id . '&causalId=' . $c->causal_id . '&subCausalId=' . $c->sub_causal_id . '&createSubscription=0&months=' . $month . '&price=' . $c->price . '&subscription_price=' . $c->subscription_price . "&courseId=" . $id);
 
     }
 
+    public function newSubscription($course_id, $member_id, $id)
+    {
+        $c = \App\Models\Course::findOrFail($course_id);
+        return redirect()->to('/in?new=1&memberId=' . $member_id . '&causalId=' . $c->causal_id . '&subCausalId=' . $c->sub_causal_id . '&createSubscription=1&price=0.00&subscription_price=' . $c->subscription_price . "&courseId=" . $id);
+
+    }
+
+    public function disableSearch()
+    {
+        $this->filterCourse = [];
+        $this->filterLevel = [];
+        $this->filterType = [];
+        $this->filterDuration = [];
+        $this->filterFrequency = [];
+
+    }
 }

+ 31 - 4
app/Http/Livewire/Member.php

@@ -497,8 +497,13 @@ class Member extends Component
 
     public function checkIsBirthItaly()
     {
-        $n = \App\Models\Nation::findOrFail($this->birth_nation_id);
-        $this->isBirthItaly = $n->is_italy;
+        if ($this->birth_nation_id > 0)
+        {
+            $n = \App\Models\Nation::findOrFail($this->birth_nation_id);
+            $this->isBirthItaly = $n->is_italy;
+        }
+        else
+            $this->isBirthItaly = false;
     }
 
     /*public function loadProvinces()
@@ -726,6 +731,7 @@ class Member extends Component
         $this->add = true;
         $this->update = false;
         $this->emit('setEdit', true);
+        $this->emit('setEditCorso', false);
     }
 
     public function store($close)
@@ -853,6 +859,7 @@ class Member extends Component
                 $this->edit($member->id);
             }
             $this->emit('setEdit', false);
+
         } catch (\Exception $ex) {
             session()->flash('error','Errore (' . $ex->getMessage() . ')');
         }
@@ -866,14 +873,17 @@ class Member extends Component
     }
 
     public function edit($id){
+
         $this->showDetail = false;
         $this->emit('setEdit', true);
+        $this->emit('setEditCorso', false);
         $this->emit('hide-search');
         try {
             $member = \App\Models\Member::findOrFail($id);
             if( !$member) {
                 session()->flash('error','Tesserato non trovato');
             } else {
+
                 $this->first_name = $member->first_name;
                 $this->last_name = $member->last_name;
                 $this->status = $member->status;
@@ -913,8 +923,14 @@ class Member extends Component
                 $this->image_old = $member->image;
                 $this->enabled = $member->enabled;
                 $this->dataId = $member->id;
+
                 $this->active = $member->getStatus();
 
+
+                $this->checkIsBirthItaly();
+
+
+
                 $date1 = new DateTime($this->birth_date);
                 $date2 = new DateTime("now");
                 $interval = $date1->diff($date2);
@@ -927,6 +943,8 @@ class Member extends Component
                 $this->update = true;
                 $this->add = false;
 
+                $this->emit('setIds', $this->nation_id, $this->birth_nation_id);
+
                 $this->emit('load-select');
 
                 $this->emit('load-provinces', $this->nation_id, 'provinceClass');
@@ -941,7 +959,7 @@ class Member extends Component
         }
     }
 
-    public function update($close)
+    public function updateAAA($close)
     {
 
         $this->isSaving = true;
@@ -1059,6 +1077,7 @@ class Member extends Component
                 $this->update = false;
             }
             $this->emit('setEdit', false);
+
         } catch (\Exception $ex) {
             session()->flash('error','Errore (' . $ex->getMessage() . ')');
         }
@@ -1071,6 +1090,7 @@ class Member extends Component
         $this->showDetail = false;
         $this->resetFields();
         $this->emit('setEdit', false);
+        //$this->emit('setEditCorso', false);
         $this->emit('reload');
     }
 
@@ -1280,6 +1300,7 @@ class Member extends Component
         $this->resetCourseFields();
         $this->addCourse = true;
         $this->updateCourse = false;
+        $this->emit('setEditCorso', true);
     }
 
     public function storeCourse()
@@ -1305,6 +1326,7 @@ class Member extends Component
             session()->flash('success, Corso creato');
             $this->resetCourseFields();
             $this->addCourse = false;
+            $this->emit('setEditCorso', false);
         } catch (\Exception $ex) {
             session()->flash('error','Errore (' . $ex->getMessage() . ')');
         }
@@ -1312,6 +1334,7 @@ class Member extends Component
 
     public function editCourse($id){
         try {
+
             $memberCourse = \App\Models\MemberCourse::findOrFail($id);
             if( !$memberCourse) {
                 session()->flash('error','Corso non trovato');
@@ -1367,6 +1390,7 @@ class Member extends Component
                 $this->courseDataId = $memberCourse->id;
                 $this->updateCourse = true;
                 $this->addCourse = false;
+                $this->emit('setEditCorso', true);
             }
         } catch (\Exception $ex) {
             session()->flash('error','Errore (' . $ex->getMessage() . ')');
@@ -1396,6 +1420,7 @@ class Member extends Component
             session()->flash('success','Corso aggiornato');
             $this->resetCourseFields();
             $this->updateCourse = false;
+            $this->emit('setEditCorso', false);
         } catch (\Exception $ex) {
             session()->flash('error','Errore (' . $ex->getMessage() . ')');
         }
@@ -1405,6 +1430,7 @@ class Member extends Component
     {
         $this->addCourse = false;
         $this->updateCourse = false;
+        $this->emit('setEditCorso', false);
         $this->resetCourseFields();
     }
 
@@ -1708,8 +1734,9 @@ class Member extends Component
     public function newPayment($course)
     {
         $c = \App\Models\Course::findOrFail($course["course_id"]);
+        $this->emit('setEdit', false);
+        $this->emit('setEditCorso', false);
         return redirect()->to('/in?new=1&memberId=' . $this->dataId . '&causalId=' . $c->causal_id . '&subCausalId=' . $c->sub_causal_id . '&createSubscription=' . $this->createSubscription .  (sizeof($this->payMonths) > 0 ? '&months=' . implode("|", $this->payMonths) : "") . '&price=' . $course["price"] . '&subscription_price=' . $course["subscription_price"] . "&courseId=" . $course["id"]);
-
     }
 
     public function block($course)

+ 27 - 5
app/Http/Livewire/Record.php

@@ -141,6 +141,18 @@ class Record extends Component
                     ->join('records_rows', 'records.id', '=', 'records_rows.record_id')
                     //->where('records_rows.when', 'like', '%' . date("m-Y") . '%')
                     ->whereBetween('date', [$this->fromDate, $this->toDate])
+                    ->where(function ($query)  {
+                        $query->where('type', 'OUT')
+                        ->orWhere(function ($query)  {
+                            $query->where('records.corrispettivo_fiscale', true)
+                                  ->orWhere('records.commercial', false);
+                        });
+                    })
+                    ->where(function ($query)  {
+                        $query->where('deleted', false)->orWhere('deleted', null);
+                    })
+                    ->orderBy('date', 'ASC')->orderBy('records.created_at', 'ASC')
+                    //->where('records.commercial', '=', false)
                     ->get();
 
         /*
@@ -403,7 +415,7 @@ class Record extends Component
 
     public function export()
     {
-        $letters = array('C', 'D', 'E', 'F', 'G', 'H', 'I', 'J', 'K', 'L', 'M', 'N');
+        $letters = array('E', 'F', 'G', 'H', 'I', 'J', 'K', 'L', 'M', 'N', 'O', 'P');
 
         $spreadsheet = new Spreadsheet();
         $activeWorksheet = $spreadsheet->getActiveSheet();
@@ -411,6 +423,8 @@ class Record extends Component
         //$activeWorksheet->setCellValue('A1', 'PrimaNota');
         $activeWorksheet->setCellValue('A1', "Data");
         $activeWorksheet->setCellValue('B1', "Causale");
+        $activeWorksheet->setCellValue('C1', "Dettaglio");
+        $activeWorksheet->setCellValue('D1', "Nominativo");
         $idx = 0;
         foreach($this->payments as $p)
         {
@@ -423,6 +437,8 @@ class Record extends Component
         $idx = 0;
         $activeWorksheet->setCellValue('A2', "");
         $activeWorksheet->setCellValue('B2', "");
+        $activeWorksheet->setCellValue('C2', "");
+        $activeWorksheet->setCellValue('D2', "");
         foreach($this->payments as $p)
         {
             $activeWorksheet->setCellValue($letters[$idx] . '2', "Entrate");
@@ -431,8 +447,8 @@ class Record extends Component
             $idx++;
         }
 
-        $activeWorksheet->getStyle('A1:N1')->getFont()->setBold(true);
-        $activeWorksheet->getStyle('A2:N2')->getFont()->setBold(true);
+        $activeWorksheet->getStyle('A1:P1')->getFont()->setBold(true);
+        $activeWorksheet->getStyle('A2:P2')->getFont()->setBold(true);
         // $activeWorksheet->getStyle('A1:N1')->getFill()->setFillType(\PhpOffice\PhpSpreadsheet\Style\Fill::FILL_SOLID)->getStartColor()->setARGB('00ff00');
 
         $count = 3;
@@ -443,10 +459,12 @@ class Record extends Component
         {
 
             $check = strpos($causal, "$") ? explode("$", $causal)[1] : $causal;
-            list($d, $c) = explode("§", $check);
+            list($d, $c, $j, $k) = explode("§", $check);
 
             $activeWorksheet->setCellValue('A' . $count, date("d/m/Y", strtotime($d)));
             $activeWorksheet->setCellValue('B' . $count, $c);
+            $activeWorksheet->setCellValue('C' . $count, $k);
+            $activeWorksheet->setCellValue('D' . $count, $j);
 
             $idx = 0;
             foreach($this->payments as $p)
@@ -493,6 +511,8 @@ class Record extends Component
 
         $activeWorksheet->setCellValue('A' . $count, 'Totale');
         $activeWorksheet->setCellValue('B' . $count, '');
+        $activeWorksheet->setCellValue('C' . $count, '');
+        $activeWorksheet->setCellValue('D' . $count, '');
         foreach($this->payments as $p)
         {
             if(isset($this->totals[$p->name]))
@@ -511,10 +531,12 @@ class Record extends Component
             }
         }
 
-        $activeWorksheet->getStyle('A' . $count . ':N' . $count)->getFont()->setBold(true);
+        $activeWorksheet->getStyle('A' . $count . ':P' . $count)->getFont()->setBold(true);
 
         $activeWorksheet->getColumnDimension('A')->setWidth(20);
         $activeWorksheet->getColumnDimension('B')->setWidth(40);
+        $activeWorksheet->getColumnDimension('C')->setWidth(40);
+        $activeWorksheet->getColumnDimension('D')->setWidth(40);
         foreach($letters as $l)
             $activeWorksheet->getColumnDimension($l)->setWidth(20);
 

+ 114 - 7
app/Http/Livewire/RecordIN.php

@@ -26,6 +26,8 @@ class RecordIN extends Component
     public $multiYearFrom = 0;
     public $createSubscription = 0;
 
+    public $corrispettivo_causal_id = 0;
+
     public function sortBy($field)
     {
         if($this->sortField === $field)
@@ -57,6 +59,8 @@ class RecordIN extends Component
     $corrispettivo_fiscale,
     $commercial, $update = false, $add = false;
 
+    public $corrispettivo = [];
+
     public $currentReceip;
 
     public $filterMember = 0, $filterPaymentMethod = 0, $filterCausals = 0, $filterFrom = '', $filterTo = '', $filterCommercial = 0;
@@ -157,6 +161,17 @@ class RecordIN extends Component
         return $ret;
     }
 
+    public function setAmount()
+    {
+        $tot = 0;
+        foreach($this->rows as $r)
+        {
+            $tot += $this->currencyToDouble($r["amount"]);
+        }
+        $this->amount = $tot;
+        $this->canSave = $this->checkCanSave();
+    }
+
     public function resetFields(){
         $this->member_id = null;
         $this->supplier_id = null;
@@ -176,6 +191,7 @@ class RecordIN extends Component
         $this->months = array();
         $this->rows = array();
         $this->rows[] = array('causal_id' => isset($_GET["causalId"]) ? $_GET["causalId"] : null, 'when' => array(array('month' => date("n"), 'year' => date("Y"), 'period' => '')),  'amount' => null, 'vat_id' => null, 'note' => '', 'commercial' => 0);
+        $this->corrispettivo = [];
         $this->emit('load-data-table');
     }
 
@@ -209,6 +225,16 @@ class RecordIN extends Component
         return $ret;
     }
 
+    public function getPaymentMethod($payment)
+    {
+        $ret = '';
+        if ($payment > 0)
+        {
+            $ret = \App\Models\PaymentMethod::findOrFail($payment)->name;
+        }
+        return $ret;
+    }
+
     function buildTree($records, $parentId = 0) {
         $this->causals = array();
 
@@ -247,6 +273,10 @@ class RecordIN extends Component
         $this->multiMonthTo = date("n");
         $this->multiYearTo = date("Y");
 
+        $fisc = \App\Models\Causal::where('corrispettivo_fiscale', true)->first();
+        if ($fisc)
+            $this->corrispettivo_causal_id = $fisc->id;
+
         $this->getCausale(\App\Models\Causal::select('id', 'name')->where('parent_id', null)->where('type', 'IN')->get(), 0);
 
         //$this->buildTree(\App\Models\Causal::all(), null);
@@ -363,11 +393,67 @@ class RecordIN extends Component
         //if ($this->hasFilter)
             $this->emit('hide-search');
         $this->resetFields();
+        $this->dataId = 0;
         $this->add = true;
         $this->update = false;
         $this->emit('setEdit', true);
     }
 
+    public function storeCorrispettivo()
+    {
+
+        $this->emit('refresh');
+
+        $rules = [
+            'member_id' => 'required'
+        ];
+
+        $this->validate($rules);
+
+
+
+        foreach($this->payments as $p)
+        {
+            if ($p->corrispettivo_fiscale)
+            {
+                $price = isset($this->corrispettivo[$p->id]) ? $this->currencyToDouble($this->corrispettivo[$p->id]) : 0;
+
+                if ($price > 0)
+                {
+
+                    $record = \App\Models\Record::create([
+                        'member_id' => $this->member_id,
+                        'supplier_id' => null,
+                        'payment_method_id' => $p->id,
+                        'commercial' => $this->commercial,
+                        'corrispettivo_fiscale' => $this->corrispettivo_fiscale,
+                        'date' => $this->date,
+                        'type' => $this->type,
+                        'amount' => $price,
+                        'deleted' => $this->deleted
+                    ]);
+
+                    \App\Models\RecordRow::create([
+                        'record_id' => $record->id,
+                        'causal_id' => $this->corrispettivo_causal_id,
+                        'note' => '',
+                        'amount' => $price,
+                        'vat_id' => null,
+                        'commercial' => $this->commercial,
+                        'when' => json_encode([])
+                    ]);
+                }
+
+            }
+        }
+
+        $this->resetFields();
+        $this->add = false;
+        $this->isDuplicate = false;
+        $this->emit('setEdit', false);
+
+    }
+
     public function store($generate)
     {
 
@@ -450,8 +536,13 @@ class RecordIN extends Component
                 $c->save();
             }
 
-            if ($generate)
-                $this->createReceipt();
+            $payment_method = \App\Models\PaymentMethod::findOrFail($this->payment_method_id);
+            if (!$payment_method->money)
+            {
+                if ($generate)
+                    $this->createReceipt();
+            }
+
             session()->flash('success','Movimento creato');
             $this->resetFields();
             $this->add = false;
@@ -473,8 +564,8 @@ class RecordIN extends Component
             $newRow->record_id = $newRecord->id;
             $newRow->save();
         }
-        $this->isDuplicate = true;
         $this->edit($newRecord->id);
+        $this->isDuplicate = true;
     }
 
     public function edit($id){
@@ -490,6 +581,7 @@ class RecordIN extends Component
                 $this->member_id = $record->member_id;
                 $this->supplier_id = $record->supplier_id;
                 $this->payment_method_id = $record->payment_method_id;
+                $this->amount = $record->amount;
                 $this->commercial = $record->commercial;
                 $this->corrispettivo_fiscale = $record->corrispettivo_fiscale;
                 $this->date = date("Y-m-d", strtotime($record->date));
@@ -581,8 +673,12 @@ class RecordIN extends Component
             $rec->amount = $tot;
             $rec->save();
 
-            if ($generate)
-                $this->createReceipt();
+            $payment_method = \App\Models\PaymentMethod::findOrFail($this->payment_method_id);
+            if (!$payment_method->money)
+            {
+                if ($generate)
+                    $this->createReceipt();
+            }
             session()->flash('success','Movimento aggiornato');
             $this->resetFields();
             $this->update = false;
@@ -694,8 +790,8 @@ class RecordIN extends Component
         if (!$exist)
         {
             $member = \App\Models\Member::create([
-                'first_name' => $this->newMemberFirstName,
-                'last_name' => $this->newMemberLastName,
+                'first_name' => strtoupper($this->newMemberFirstName),
+                'last_name' => strtoupper($this->newMemberLastName),
                 'fiscal_code' => $this->newMemberFiscalCode,
                 'status' => true
             ]);
@@ -840,6 +936,17 @@ class RecordIN extends Component
         // $this->emit('load-select');
     }
 
+    public function getTotalCorrispettivo()
+    {
+        $total = 0.00;
+        foreach($this->corrispettivo as $r)
+        {
+            $total += $this->currencyToDouble($r);
+        }
+        return formatPrice($total);
+        // $this->emit('load-select');
+    }
+
     public function getPrice()
     {
         $total = 0.00;

+ 12 - 0
app/Http/Livewire/RecordINOUT.php

@@ -133,6 +133,9 @@ class RecordINOUT extends Component
                 $records = \App\Models\Record::where('type', 'IN')
                     ->join('records_rows', 'records.id', '=', 'records_rows.record_id')
                     ->whereNotIn('records_rows.causal_id', $this->excludeCausals)
+                    ->where(function ($query)  {
+                        $query->where('deleted', false)->orWhere('deleted', null);
+                    })
                     ->where('records_rows.when', 'like', '%' . $f . '%')->get();
                 //$records = $records->orderBy('date', 'DESC')->get();
 
@@ -158,6 +161,9 @@ class RecordINOUT extends Component
                 $records = \App\Models\Record::where('type', 'OUT')
                     ->join('records_rows', 'records.id', '=', 'records_rows.record_id')
                     ->whereNotIn('records_rows.causal_id', $this->excludeCausals)
+                    ->where(function ($query)  {
+                        $query->where('deleted', false)->orWhere('deleted', null);
+                    })
                     ->where('records_rows.when', 'like', '%' . $f . '%')->get();
                 //$records = $records->orderBy('date', 'DESC')->get();
 
@@ -390,6 +396,9 @@ class RecordINOUT extends Component
             $records = \App\Models\Record::where('type', 'IN')
                 ->join('records_rows', 'records.id', '=', 'records_rows.record_id')
                 ->whereNotIn('records_rows.causal_id', $this->excludeCausals)
+                ->where(function ($query)  {
+                    $query->where('deleted', false)->orWhere('deleted', null);
+                })
                 ->where('records_rows.when', 'like', '%' . $filter . '%')->get();
             //$records = $records->orderBy('date', 'DESC')->get();
 
@@ -415,6 +424,9 @@ class RecordINOUT extends Component
             $records = \App\Models\Record::where('type', 'OUT')
                 ->join('records_rows', 'records.id', '=', 'records_rows.record_id')
                 ->whereNotIn('records_rows.causal_id', $this->excludeCausals)
+                ->where(function ($query)  {
+                    $query->where('deleted', false)->orWhere('deleted', null);
+                })
                 ->where('records_rows.when', 'like', '%' . $filter . '%')->get();
             //$records = $records->orderBy('date', 'DESC')->get();
 

+ 11 - 5
app/Models/Member.php

@@ -160,7 +160,7 @@ class Member extends Model
         {
             if ($card->card->use_for_user_check)
             {
-                $ret = array('status' => $card->expire_date > date("Y-m-d") ? 2 : 1, 'date' => $card->expire_date);
+                $ret = array('status' => $card->expire_date . " 23:59:59" > date("Y-m-d") ? 2 : 1, 'date' => $card->expire_date);
             }
         }
         return $ret;
@@ -174,7 +174,7 @@ class Member extends Model
         {
             if ($card->card->use_for_user_check)
             {
-                $ret = array('status' => $card->expire_date > date("Y-m-d") ? 2 : 1, 'date' => $card->expire_date, 'status_text' => $card->expire_date > date("Y-m-d") ? 'Tesserato' : 'Sospeso');
+                $ret = array('status' => $card->expire_date . " 23:59:59" > date("Y-m-d") ? 2 : 1, 'date' => $card->expire_date, 'status_text' => $card->expire_date . " 23:59:59" > date("Y-m-d") ? 'Tesserato' : 'Sospeso');
             }
         }
         return $ret;
@@ -186,7 +186,7 @@ class Member extends Model
         $certificates = \App\Models\MemberCertificate::where('member_id', $this->id)->orderBy('expire_date')->get();
         foreach($certificates as $certificate)
         {
-            $ret = array('status' => $certificate->expire_date > date("Y-m-d"), 'date' => $certificate->expire_date);
+            $ret = array('status' => $certificate->expire_date . " 23:59:59" > date("Y-m-d"), 'date' => $certificate->expire_date);
         }
         return $ret;
     }
@@ -195,7 +195,10 @@ class Member extends Model
     {
         $ret = 0;
         // Soldi virtuali caricati
-        $records = \App\Models\Record::where('member_id', $this->id)->where('type', 'IN')->get();
+        $records = \App\Models\Record::where('member_id', $this->id)->where('type', 'IN')
+        ->where(function ($query)  {
+            $query->where('deleted', false)->orWhere('deleted', null);
+        })->get();
         //->with('causal')->get();
         foreach($records as $record)
         {
@@ -208,7 +211,10 @@ class Member extends Model
             }
         }
         // Soldi virtuali spesi
-        $records = \App\Models\Record::where('member_id', $this->id)->where('type', 'IN')->with('payment_method')->get();
+        $records = \App\Models\Record::where('member_id', $this->id)->where('type', 'IN')->with('payment_method')
+        ->where(function ($query)  {
+            $query->where('deleted', false)->orWhere('deleted', null);
+        })->get();
         foreach($records as $record)
         {
             if ($record->payment_method->money == 1)

+ 3 - 0
app/Models/Record.php

@@ -21,6 +21,9 @@ class Record extends Model
         //'amount',
         //'note',
         'commercial',
+        'corrispettivo_fiscale',
+        'deleted',
+        'amount'
     ];
 
     public function member()

+ 1 - 0
public/assets/js/app.js

@@ -19,3 +19,4 @@ var app = {
     if (x.classList.contains("filterWrapper_open")) //
         x.classList.toggle("filterWrapper_open");
   }
+

+ 8 - 6
resources/views/livewire/causal.blade.php

@@ -141,14 +141,16 @@
                             </div>
                         </div>
 
-                        @if(false)
-                            <div class="form--item mb-3">
-                                <div class="form-check form-check-inline">
+                        <div class="form--item mb-3">
+                            <div class="form-check form-check-inline">
+                                @if($corrispettivo_causal_id == 0 || $corrispettivo_causal_id == $dataId)
                                     <input class="form-check-input" type="checkbox" id="corrispettivo_fiscale" wire:model="corrispettivo_fiscale">
-                                    <label class="form-check-label" for="corrispettivo_fiscale">Utilizza per corrispettivo fiscale</label>
-                                </div>
+                                @else
+                                    C'è già una causale associata al corrispettivo fiscale
+                                @endif
+                                <label class="form-check-label" for="corrispettivo_fiscale">Utilizza per corrispettivo fiscale</label>
                             </div>
-                        @endif
+                        </div>
 
                         <div class="form--item mb-3">
                             <div class="form-check form-check-inline">

+ 2 - 2
resources/views/livewire/course.blade.php

@@ -27,8 +27,8 @@
                 <thead>
                     <tr>
                         <th scope="col">Nome</th>
-                        <th scope="col">Tipologia</th>
                         <th scope="col">Livello</th>
+                        <th scope="col">Tipologia</th>
                         <th scope="col">Frequenza</th>
                         <th scope="col">Prezzo mensile</th>
                         <th scope="col">N° partecipanti</th>
@@ -39,8 +39,8 @@
                     @foreach($records as $record)
                         <tr>
                             <td>{{$record->name}}</td>
-                            <td>{{$record->type->name ?? ""}}</td>
                             <td>{{$record->level->name ?? ""}}</td>
+                            <td>{{$record->type->name ?? ""}}</td>
                             <td>{{$record->frequency->name ?? ""}}</td>
                             <td>{{formatPrice($record->price)}}</td>
                             <td>{{$record->getCount()}}</td>

+ 2 - 0
resources/views/livewire/course_list.blade.php

@@ -110,6 +110,7 @@
                 <tr>
                     <th scope="col">Cognome</th>
                     <th scope="col">Nome</th>
+                    <th scope="col">Iscrizione</th>
                     @foreach($months as $m)
                         <th scope="col">&nbsp;&nbsp;&nbsp;&nbsp;{{$m}}</th>
                     @endforeach
@@ -123,6 +124,7 @@
                         @endphp
                         <td><a href="/members?member_detail={{$id}}">{{$last_name}}</a></td>
                         <td><a href="/members?member_detail={{$id}}">{{$first_name}}</a></td>
+                        <td><a class="{{$record[15] ? 'green' : 'orange'}}" wire:click="newSubscription({{$record[13]}}, {{$id}}, {{$record[14]}})" style="cursor: pointer;">&nbsp;</a></td>
                         @for($x=1; $x<=12; $x++)
                             <td>
                                 @if($record[$x] == 'orange')

+ 96 - 16
resources/views/livewire/member.blade.php

@@ -36,10 +36,10 @@
                                         @if($cert->expire_date < date("Y-m-d"))
                                             <span class="badge tessera-badge suspended">scaduto</span>
                                         @endif
-                                        @if($cert->expire_date >= date("Y-m-d") && $cert->expire_date < date("Y-m-d", strtotime("+1 month")))
+                                        @if($cert->expire_date . " 23:59:59" >= date("Y-m-d") && $cert->expire_date < date("Y-m-d", strtotime("+1 month")))
                                             <span class="badge tessera-badge due">in scadenza</span>
                                         @endif
-                                        @if($cert->expire_date >= date("Y-m-d", strtotime("+1 month")))
+                                        @if($cert->expire_date . " 23:59:59" >= date("Y-m-d", strtotime("+1 month")))
                                             <span class="badge tessera-badge active">valido</span>
                                         @endif
                                         </span>
@@ -56,7 +56,7 @@
                                     @php
                                     // $card = $currentMember->cards[0];
                                     $active = 'active';
-                                    if ($card->expire_date != '' && $card->expire_date < date("Y-m-d"))
+                                    if ($card->expire_date != '' && $card->expire_date < date("Y-m-d  23:59:59"))
                                     {
                                         $active = 'suspended';
                                     }
@@ -104,7 +104,7 @@
 
                     <ul class="user-address mb-4 p-0">
                         <li><i class="ico--ui resume--ico phone me-2"></i><span>Tel. {{$currentMember->phone}}</span></li>
-                        <li><i class="ico--ui resume--ico birth me-2"></i><span>Nato il {{$currentMember->birth_date ? date("d/m/Y", strtotime($currentMember->birth_date)) : ''}}</span>&nbsp;({{$currentMember->getAge()}} anni)</li>
+                        <li><i class="ico--ui resume--ico birth me-2"></i><span>Nato/a il {{$currentMember->birth_date ? date("d/m/Y", strtotime($currentMember->birth_date)) : ''}}</span>&nbsp;({{$currentMember->getAge()}} anni)</li>
                         <li><i class="ico--ui resume--ico email me-2"></i><span>{{strtolower($currentMember->email)}}</span></li>
                     </ul>
                     <ul class="user-residence p-0">
@@ -363,7 +363,7 @@
                             <input type="text" class="form-control" placeholder="Cerca utente" aria-label="cerca utent" aria-describedby="button-addon2" wire:model="search">
 
                                 @if($showReset)
-                                    <button class="btn--ui" type="button" id="button-addon2" wire:click="resetSearch()"><i class="ico--ui search"></i>Reset</button>
+                                    <button class="btn--ui" type="button" id="button-addon2" onclick="reset()"><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
@@ -1323,11 +1323,11 @@
                                         <br>
                                         @if($addCourse)
                                             @if(!$course_exist)
-                                                <button class="btn--ui primary" wire:click.prevent="storeCourse()">Salva</button>
+                                                <button class="btn--ui primary" wire:click.prevent="storeCourse()">Salva corso</button>
                                             @endif
                                         @endif
                                         @if($updateCourse)
-                                            <button class="btn--ui primary" wire:click.prevent="updateCourse()">Salva</button>
+                                            <button class="btn--ui primary" wire:click.prevent="updateCourse()">Salva corso</button>
                                         @endif
                                         <button class="btn--ui primary" wire:click.prevent="cancelCourse()">Annulla</button>
 
@@ -1383,7 +1383,7 @@
                                             </div>
                                         </div>
 
-                                        @if($member_card->expire_date > date("Y-m-d"))
+                                        @if($member_card->expire_date . " 23:59:59" > date("Y-m-d"))
                                             <span class="badge tessera-badge active">attiva</span>
                                         @else
                                             <span class="badge tessera-badge suspended">scaduta</span>
@@ -1421,13 +1421,13 @@
                                             </div>
                                         </div>
 
-                                        @if($cert->expire_date < date("Y-m-d"))
+                                        @if($cert->expire_date . " 23:59:59" < date("Y-m-d"))
                                             <span class="badge tessera-badge suspended">scaduto</span>
                                         @endif
-                                        @if($cert->expire_date >= date("Y-m-d") && $cert->expire_date < date("Y-m-d", strtotime("+1 month")))
+                                        @if($cert->expire_date . " 23:59:59" >= date("Y-m-d") && $cert->expire_date < date("Y-m-d", strtotime("+1 month")))
                                             <span class="badge tessera-badge due">in scadenza</span>
                                         @endif
-                                        @if($cert->expire_date >= date("Y-m-d", strtotime("+1 month")))
+                                        @if($cert->expire_date . " 23:59:59" >= date("Y-m-d", strtotime("+1 month")))
                                             <span class="badge tessera-badge active">valido</span>
                                         @endif
                                     </div>
@@ -1501,14 +1501,14 @@
                 <!-- save & continue section -->
                 <section class="save--section d-flex justify-content-start">
                     @if($add)
-                        <button class="btn--ui primary"wire:click.prevent="store(true)">salva e chiudi</button>&nbsp;&nbsp;&nbsp;
-                        <button class="btn--ui primary"wire:click.prevent="store(false)">salva e continua</button>&nbsp;&nbsp;&nbsp;
+                        <button class="btn--ui primary" onclick="storeAction(true)">salva e chiudi</button>&nbsp;&nbsp;&nbsp;
+                        <button class="btn--ui primary" onclick="storeAction(false)">salva e continua</button>&nbsp;&nbsp;&nbsp;
                     @endif
                     @if($update)
-                        <button class="btn--ui primary"wire:click.prevent="update(true)">salva e chiudi</button>&nbsp;&nbsp;&nbsp;
-                        <button class="btn--ui primary"wire:click.prevent="update(false)">salva e continua</button>&nbsp;&nbsp;&nbsp;
+                        <button class="btn--ui primary" onclick="updateAction(true)">salva e chiudi</button>&nbsp;&nbsp;&nbsp;
+                        <button class="btn--ui primary" onclick="updateAction(false)">salva e continua</button>&nbsp;&nbsp;&nbsp;
                     @endif
-                    <button class="btn--ui lightGrey"  type="submit" wire:click.prevent="cancel()">annulla</button>
+                    <button class="btn--ui lightGrey"  type="button" onclick="cancelAction()">annulla</button>
                 </section>
 
 
@@ -1810,6 +1810,11 @@
             pcsh2();
         });
 
+        Livewire.on('setIds', (nation_id_x, birth_nation_id_x) => {
+            nation_id = nation_id_x;
+            nation_birth_id = birth_nation_id_x;
+        });
+
         function loadCombo()
         {
             $('.nationClass').select2({
@@ -1996,6 +2001,38 @@
             $('#tablesaw-350').DataTable().destroy();
         }
 
+        function reset()
+        {
+            /*$('input:checkbox.chkCard').each(function () {
+                if (this.checked)
+                {
+                    if (cards != "") cards += ",";
+                    cards += $(this).val();
+                }
+            });
+
+            $('input:checkbox.chkCategory').each(function () {
+                if (this.checked)
+                {
+                    if (categories != "") categories += ",";
+                    categories += $(this).val();
+                }
+            });
+
+            var chkCertificateNormal = $(".chkCertificateNormal").is(':checked') ? "1" : "";
+            var chkCertificateAgonistico = $(".chkCertificateAgonistico").is(':checked') ? "1" : "";
+            var chkCertificateScadenza = $(".chkCertificateScadenza").is(':checked') ? "1" : "";
+            var chkCertificateScaduti = $(".chkCertificateScaduti").is(':checked') ? "1" : "";
+
+            var status = $('input[name="chkStatus"]:checked').val();*/
+
+            $('input[name="txtFromYear"]').val('');
+            $('input[name="txtToYear"]').val('');
+
+
+            loadDataTable();
+        }
+
         function loadDataTable()
         {
 
@@ -2034,6 +2071,7 @@
 
             $('#tablesaw-350').DataTable({
                 //destroy: true,
+                serverSide: true,
                 ajax: '/get_members?cards=' + cards + "&categories=" + categories + "&chkCertificateNormal=" + chkCertificateNormal + "&chkCertificateAgonistico=" + chkCertificateAgonistico + "&chkCertificateScadenza=" + chkCertificateScadenza + "&chkCertificateScaduti=" + chkCertificateScaduti + "&status=" + status + "&fromYear=" + fromYear + "&toYear=" + toYear,
                 columns: [
                     { data: 'id' },
@@ -2165,6 +2203,7 @@
         }
 
         var isEdit = false;
+        var isEditCorso = false;
 
         Livewire.on('setEdit', (x) =>
         {
@@ -2172,6 +2211,12 @@
             console.log(isEdit);
         });
 
+        Livewire.on('setEditCorso', (x) =>
+        {
+            isEditCorso = x;
+            console.log("Edit corso" + isEditCorso);
+        });
+
         Livewire.on('setErrorMsg', (errors) =>
         {
             errors.forEach(msg);
@@ -2191,9 +2236,44 @@
             location.reload();
         });
 
+        function storeAction(type)
+        {
+            if (isEditCorso)
+            {
+                if (confirm('Non hai concluso l\' inserimento/modifica del corso, vuoi comunque procedere?'))
+                    @this.store(type);
+            }
+            else
+                @this.store(type);
+        }
+
+        function updateAction(type)
+        {
+            if (isEditCorso)
+            {
+                if (confirm('Non hai concluso l\' inserimento/modifica del corso, vuoi comunque procedere?'))
+                    @this.updateAAA(type);
+            }
+            else
+                @this.updateAAA(type);
+        }
+
+        function cancelAction()
+        {
+            if (isEditCorso)
+            {
+                if (confirm('Non hai concluso l\' inserimento/modifica del corso, vuoi comunque procedere?'))
+                    @this.cancel();
+            }
+            else
+            @this.cancel();
+        }
+
         window.onbeforeunload = function(){
             if (isEdit)
                 return 'Cambiando pagina le eventuali modifiche andranno perse';
+            if (isEditCorso)
+                return 'Devi prima salvare i dati del corso';
 
         };
 

+ 0 - 2
resources/views/livewire/payment_method.blade.php

@@ -145,14 +145,12 @@
                             </div>
                         </div>
 
-                        @if(false)
                         <div class="form--item mb-3">
                             <div class="form-check form-check-inline">
                                 <input class="form-check-input" type="checkbox" id="corrispettivo_fiscale" wire:model="corrispettivo_fiscale">
                                 <label class="form-check-label" for="corrispettivo_fiscale">Utilizza per corrispettivo fiscale</label>
                             </div>
                         </div>
-                        @endif
 
                         <!-- // inline input field -->
 

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

@@ -52,11 +52,13 @@
             <h2 class="primary">Ricevute</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>
 

+ 2 - 2
resources/views/livewire/records.blade.php

@@ -97,11 +97,11 @@
                     <tr>
                         @php
                         $check = strpos($causal, "$") ? explode("$", $causal)[1] : $causal;
-                        list($d, $c, $n, $d) = explode("§", $check);
+                        list($d, $c, $n, $det) = explode("§", $check);
                         @endphp
                         <td style="background-color:{{$count % 2 == 0 ? 'white' : '#f2f4f7'}}">{{date("d/m/Y", strtotime($d))}}</td>
                         <td style="border-left:3px solid white !important;background-color:{{$count % 2 == 0 ? 'white' : '#f2f4f7'}}">{{$c}}</td>
-                        <td style="border-left:3px solid white !important;background-color:{{$count % 2 == 0 ? 'white' : '#f2f4f7'}}">{{$d}}</td>
+                        <td style="border-left:3px solid white !important;background-color:{{$count % 2 == 0 ? 'white' : '#f2f4f7'}}">{{$det}}</td>
                         <td style="border-left:3px solid white !important;background-color:{{$count % 2 == 0 ? 'white' : '#f2f4f7'}}">{{$n}}</td>
                         @foreach($payments as $p)
                             @if(isset($record[$p->name]))

+ 286 - 201
resources/views/livewire/records_in.blade.php

@@ -14,15 +14,15 @@
 
                     <div class="filter--item_formElement">
                         <div class="form-check form-check-inline d-inline-flex align-items-center">
-                            <input class="form-check-input" type="radio" value="0" name="filterCommercial" checked>
+                            <input class="form-check-input" type="radio" value="0" name="filterCommercial" onclick="setFilterCommercial(0)">
                             <label class="form-check-label ms-2" for="inlineCheckbox1">Entrambe</label>
                         </div>
                         <div class="form-check form-check-inline d-inline-flex align-items-center">
-                            <input class="form-check-input" type="radio" value="1" name="filterCommercial" >
+                            <input class="form-check-input" type="radio" value="1" name="filterCommercial"  onclick="setFilterCommercial(1)">
                             <label class="form-check-label ms-2" for="inlineCheckbox1">Commerciale</label>
                         </div>
                         <div class="form-check form-check-inline d-inline-flex align-items-center">
-                            <input class="form-check-input" type="radio" value="2" name="filterCommercial">
+                            <input class="form-check-input" type="radio" value="2" name="filterCommercial" onclick="setFilterCommercial(2)">
                             <label class="form-check-label ms-2" for="inlineCheckbox1">Non commerciale</label>
                         </div>
                     </div>
@@ -177,11 +177,11 @@
                                         <div class="input-group mb-12">
                                             <div class="check--invoice d-flex align-items-center">
                                                 <div class="form-check me-3">
-                                                    <input class="form-check-input" type="radio" value="1" wire:model="commercial" {{$this->dataId > 0 ? 'disabled' : ''}}>
+                                                    <input class="form-check-input" type="radio" value="1" wire:model="commercial" {{$this->dataId > 0 && !$isDuplicate ? 'disabled' : ''}}>
                                                     <label class="form-check-label" for="flexCheckChecked">&nbsp;Commerciale</label>
                                                 </div>
                                                 <div class="form-check">
-                                                    <input class="form-check-input" type="radio" value="0" wire:model="commercial" {{$this->dataId > 0 ? 'disabled' : ''}}>
+                                                    <input class="form-check-input" type="radio" value="0" wire:model="commercial" {{$this->dataId > 0 && !$isDuplicate ? 'disabled' : ''}}>
                                                     <label class="form-check-label" for="flexCheck">&nbsp;Non Commerciale</label>
                                                 </div>
                                                 </div>
@@ -191,7 +191,7 @@
                                     <div class="col-md-6 mt-3">
                                         <span class="title-form d-block w-100">Data pagamento</span>
                                         <div class="input-group mb-3">
-                                            <input id="date" type="date" class="form-control"  wire:model="date" {{$this->dataId > 0 ? 'disabled' : ''}}>
+                                            <input id="date" type="date" class="form-control"  wire:model="date" {{$this->dataId > 0 && !$isDuplicate ? 'disabled' : ''}}>
                                         </div>
                                     </div>
                                     <div class="col-md-6">&nbsp;</div>
@@ -199,7 +199,7 @@
 
                                     <div class="col-md-6">
                                         <span class="title-form d-block w-100">Persona</span>
-                                        <select name="member_id" class="form-select memberClass @error('member_id') is-invalid @enderror" aria-label="Seleziona una persona" wire:model="member_id" {{$this->dataId > 0 ? 'disabled' : ''}}>
+                                        <select name="member_id" class="form-select memberClass @error('member_id') is-invalid @enderror" aria-label="Seleziona una persona" wire:model="member_id" {{$this->dataId > 0 && !$isDuplicate ? 'disabled' : ''}}>
                                             <option value="">--Seleziona--
                                             @foreach($members as $member)
                                                 <option value="{{$member->id}}">{{$member->last_name}} {{$member->first_name}} ({{$member->fiscal_code}})
@@ -209,7 +209,7 @@
                                             <div class="invalid-feedback">{{ $message }}</div>
                                         @enderror
                                         <br><br>
-                                        @if($this->dataId == 0)
+                                        @if($this->dataId == 0 && !$isDuplicate)
                                         <button type="button" class="btn--ui primary" data-bs-toggle="modal" data-bs-target="#userModal">
                                             Aggiungi
                                         </button>
@@ -234,226 +234,283 @@
                                     </div>
                                 </div>
 
-                                <div class="row gx-2 mt-3">
-                                    <span class="title-form d-block w-100">Pagamento</span>
+                                @if($commercial)
 
-                                    <div class="col-md-12" >
+                                    <br>
+                                    <div class="col-md-12">
 
-                                        <select name="payment_method_id" class="form-select paymentClass @error('payment_method_id') is-invalid @enderror" aria-label="Seleziona un metodo di pagamento" wire:model="payment_method_id" style="width:100%">
-                                            <option value="">--Seleziona--
-                                            @foreach($payments as $payment)
-                                                <option value="{{$payment->id}}">{{$payment->name}}
-                                            @endforeach
-                                        </select>
-                                        @error('payment_method_id')
-                                            <div class="invalid-feedback">{{ $message }}</div>
-                                        @enderror
+                                        <div class="input-group mb-12">
+                                            <div class="check--invoice d-flex align-items-center">
+                                                <div class="form-check me-3">
+                                                    <input class="form-check-input" id="corrispettivo_fiscale" type="checkbox" wire:model="corrispettivo_fiscale" {{$this->dataId > 0 && !$isDuplicate ? 'disabled' : ''}}>
+                                                    <label class="form-check-label" for="flexCheckChecked">&nbsp;&nbsp;&nbsp;Corrispettivo fiscale</label>
+                                                </div>
+                                            </div>
+                                        </div>
                                     </div>
-                                </div>
 
-                                @foreach($rows as $idx => $row)
+                                @endif
 
-                                    <div class="row gx-2 mt-3" >
-                                        <span class="title-form d-block w-100">Causale</span>
-                                        <div class="col-md-12">
+                                @if($corrispettivo_fiscale)
 
-                                            @if($this->dataId > 0)
-                                                {{$this->getCausal($rows[$idx]['causal_id'])}}<br>
-                                            @else
-                                                <livewire:causals :type="$typeIN" :idx="$idx" :causal_id="$rows[$idx]['causal_id']" :wire:key="$idx"/>
+                                    @if ($this->dataId > 0)
+                                        <div class="row">
+                                            <div class="col-md-9 mt-3">
+                                                {{$this->getPaymentMethod($payment_method_id)}}
+                                            </div>
+                                            <div class="col-md-3 mt-3">
+                                                {{formatPrice($amount)}}
+                                            </div>
+                                        </div>
+                                    @else
+                                        @foreach($payments as $payment)
+                                            @if($payment->corrispettivo_fiscale)
+                                                <div class="row">
+                                                    <div class="col-md-9 mt-3">
+                                                        {{$payment->name}}
+                                                    </div>
+                                                    <div class="col-md-3 mt-3">
+                                                        <input type="text" class="form-control totalInput text-end" id="corrispettivo_{{$payment->id}}" wire:model="corrispettivo.{{$payment->id}}" onkeyup="onlyNumberAmount(this)" placeholder="€ 0,00">
+                                                    </div>
+                                                </div>
                                             @endif
+                                        @endforeach
 
-                                            @error('rows.'. $idx . '.causal_id')
-                                                <span style="argin-top: 0.25rem; font-size: 0.875em; color: var(--bs-form-invalid-color);">{{ $message }}</span>
-                                            @enderror
-
+                                        <div class="row">
+                                            <div class="col-md-9 mt-3" style="font-size: 18px;font-weight: bold;">
+                                                <b>Totale</b>
+                                            </div>
+                                            <div class="col-md-3 mt-3" style="text-align:right;font-size: 18px;font-weight: bold;">
+                                                <b>{{$this->getTotalCorrispettivo()}}</b>
+                                            </div>
                                         </div>
-                                    </div>
+                                    @endif
+
+
+                                @else
 
                                     <div class="row gx-2 mt-3">
-                                        <span class="title-form d-block w-100">Dettaglio causale</span>
-                                        <div class="col-md-12">
-                                            <input class="form-control " id="causal_detail_{{$idx}}" type="text" placeholder="Dettaglio causale" wire:model="rows.{{$idx}}.note" {{$this->dataId > 0 ? 'disabled' : ''}}>
+                                        <span class="title-form d-block w-100">Pagamento</span>
+
+                                        <div class="col-md-12" >
+
+                                            <select name="payment_method_id" class="form-select paymentClass @error('payment_method_id') is-invalid @enderror" aria-label="Seleziona un metodo di pagamento" wire:model="payment_method_id" style="width:100%">
+                                                <option value="">--Seleziona--
+                                                @foreach($payments as $payment)
+                                                    <option value="{{$payment->id}}">{{$payment->name}}
+                                                @endforeach
+                                            </select>
+                                            @error('payment_method_id')
+                                                <div class="invalid-feedback">{{ $message }}</div>
+                                            @enderror
                                         </div>
                                     </div>
 
-                                    <div class="row gx-2 mt-3 align-items-center">
-                                        <div class="col-md-6">
-                                            <span class="total primary">Importo</span>
+                                    @foreach($rows as $idx => $row)
+
+                                        <div class="row gx-2 mt-3" >
+                                            <span class="title-form d-block w-100">Causale</span>
+                                            <div class="col-md-12">
+
+                                                @if($this->dataId > 0 && !$isDuplicate)
+                                                    {{$this->getCausal($rows[$idx]['causal_id'])}}<br>
+                                                @else
+                                                    <livewire:causals :type="$typeIN" :idx="$idx" :causal_id="$rows[$idx]['causal_id']" :wire:key="$idx"/>
+                                                @endif
+
+                                                @error('rows.'. $idx . '.causal_id')
+                                                    <span style="argin-top: 0.25rem; font-size: 0.875em; color: var(--bs-form-invalid-color);">{{ $message }}</span>
+                                                @enderror
+
+                                            </div>
                                         </div>
-                                        @if ($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 class="row gx-2 mt-3">
+                                            <span class="title-form d-block w-100">Dettaglio causale</span>
+                                            <div class="col-md-12">
+                                                <input class="form-control " id="causal_detail_{{$idx}}" type="text" placeholder="Dettaglio causale" wire:model="rows.{{$idx}}.note" {{$this->dataId > 0 && !$isDuplicate ? 'disabled' : ''}}>
                                             </div>
-                                        @else
-                                            <div class="col-md-3"></div>
-                                        @endif
-                                        <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" {{$this->dataId > 0 ? 'disabled' : ''}}>
-                                            @endif
-                                            @if($update)
-                                                <input type="text" class="form-control totalInput text-end @error('amount') is-invalid @enderror" id="rows.{{$idx}}.amount" placeholder="€ 0,00" wire:model="rows.{{$idx}}.amount"  onkeyup="onlyNumberAmount(this)" wire:keydown.enter="update(false)" {{$this->dataId > 0 ? 'disabled' : ''}}>
-                                            @endif
-                                            @error('rows.'. $idx . '.amount')
-                                                <span style="argin-top: 0.25rem; font-size: 0.875em; color: var(--bs-form-invalid-color);">{{ $message }}</span>
-                                            @enderror
                                         </div>
 
-                                    </div>
+                                        <div class="row gx-2 mt-3 align-items-center">
+                                            <div class="col-md-6">
+                                                <span class="total primary">Importo</span>
+                                            </div>
+                                            @if ($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>
+                                            @else
+                                                <div class="col-md-3"></div>
+                                            @endif
+                                            <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)" onchange="setChangedAmount()" placeholder="€ 0,00" {{$this->dataId > 0 && !$isDuplicate ? 'disabled' : ''}}>
+                                                @endif
+                                                @if($update)
+                                                    <input type="text" class="form-control totalInput text-end @error('amount') is-invalid @enderror" id="rows.{{$idx}}.amount" placeholder="€ 0,00" wire:model="rows.{{$idx}}.amount"  onkeyup="onlyNumberAmount(this)" onchange="setChangedAmount()" wire:keydown.enter="update(false)" {{$this->dataId > 0 && !$isDuplicate ? 'disabled' : ''}}>
+                                                @endif
+                                                @error('rows.'. $idx . '.amount')
+                                                    <span style="argin-top: 0.25rem; font-size: 0.875em; color: var(--bs-form-invalid-color);">{{ $message }}</span>
+                                                @enderror
+                                            </div>
 
-                                    <div class="row gx-2 mt-3 align-items-center">
-                                        <div class="col-md-4">
-                                            <span class="total primary">Competenza</span>
                                         </div>
-                                        <div class="col-md-8">
-                                            <div class="row">
-
-                                                @if($multiP)
-                                                    <div class="row" style="background-color:lightGrey">
-                                                        <h4>Seleziona inizio e fine multiperiodo</h4>
-                                                        <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" {{$this->dataId > 0 ? 'disabled' : ''}}>
-                                                                    <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 class="row gx-2 mt-3 align-items-center">
+                                            <div class="col-md-4">
+                                                <span class="total primary">Competenza</span>
+                                            </div>
+                                            <div class="col-md-8">
+                                                <div class="row">
+
+                                                    @if($multiP)
+                                                        <div class="row" style="background-color:lightGrey">
+                                                            <h4>Seleziona inizio e fine multiperiodo</h4>
+                                                            <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" {{$this->dataId > 0 && !$isDuplicate ? 'disabled' : ''}}>
+                                                                        <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-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"  {{$this->dataId > 0 ? 'disabled' : ''}}>
+                                                            <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"  {{$this->dataId > 0 && !$isDuplicate ? 'disabled' : ''}}>
+                                                                </div>
                                                             </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" {{$this->dataId > 0 ? 'disabled' : ''}}>
-                                                                    <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 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" {{$this->dataId > 0 && !$isDuplicate ? 'disabled' : ''}}>
+                                                                        <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-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"  {{$this->dataId > 0 ? 'disabled' : ''}}>
+                                                            <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"  {{$this->dataId > 0 && !$isDuplicate ? 'disabled' : ''}}>
+                                                                </div>
                                                             </div>
+                                                            @if($this->dataId == 0 && !$isDuplicate)
+                                                                <div class="col-md-6">
+                                                                    <button type="button" class="btn--ui primary" wire:click.prevent="multiPeriodCreate({{$idx}})" style="margin-top:20px">
+                                                                        Crea multi periodo
+                                                                    </button>
+                                                                </div>
+                                                                <div class="col-md-6">
+                                                                    <button type="button" class="btn--ui primary" wire:click.prevent="multiPeriodCancel()" style="margin-top:20px">
+                                                                        Annulla multi periodo
+                                                                    </button>
+                                                                </div>
+                                                            @endif
                                                         </div>
-                                                        @if($this->dataId == 0)
-                                                            <div class="col-md-6">
-                                                                <button type="button" class="btn--ui primary" wire:click.prevent="multiPeriodCreate({{$idx}})" style="margin-top:20px">
-                                                                    Crea multi periodo
-                                                                </button>
-                                                            </div>
-                                                            <div class="col-md-6">
-                                                                <button type="button" class="btn--ui primary" wire:click.prevent="multiPeriodCancel()" style="margin-top:20px">
-                                                                    Annulla multi periodo
-                                                                </button>
-                                                            </div>
-                                                        @endif
-                                                    </div>
 
 
-                                                @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" {{$this->dataId > 0 ? 'disabled' : ''}}>
-                                                                    <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>
+                                                    @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" {{$this->dataId > 0 && !$isDuplicate ? 'disabled' : ''}}>
+                                                                        <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-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"  {{$this->dataId > 0 ? 'disabled' : ''}}>
+                                                            <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"  {{$this->dataId > 0 && !$isDuplicate ? 'disabled' : ''}}>
+                                                                </div>
                                                             </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>
-                                                            @if($this->dataId == 0)
-                                                            <button type="button" class="btn--ui primary" wire:click.prevent="delPeriod({{$idx}}, {{$xxx}})" style="float:right">
-                                                                -
-                                                            </button>
-                                                            @endif
-                                                        </div>
-                                                    @endforeach
-                                                    @if($this->dataId == 0)
-                                                    <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 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>
+                                                                @if($this->dataId == 0)
+                                                                <button type="button" class="btn--ui primary" wire:click.prevent="delPeriod({{$idx}}, {{$xxx}})" style="float:right">
+                                                                    -
+                                                                </button>
+                                                                @endif
+                                                            </div>
+                                                        @endforeach
+                                                        @if($this->dataId == 0)
+                                                        <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
                                                     @endif
-                                                @endif
 
+                                                </div>
                                             </div>
                                         </div>
-                                    </div>
 
-                                    <br><br>
-                                    @if($this->dataId == 0)
-                                    @if($idx > 0)
-                                        <button type="button" class="btn--ui primary" wire:click.prevent="delRow({{$idx}})" style="float:right">
-                                            Rimuovi causale
-                                        </button>
                                         <br><br>
-                                    @endif
-                                    @endif
-                                    <hr size="1">
+                                        @if($this->dataId == 0)
+                                        @if($idx > 0)
+                                            <button type="button" class="btn--ui primary" wire:click.prevent="delRow({{$idx}})" style="float:right">
+                                                Rimuovi causale
+                                            </button>
+                                            <br><br>
+                                        @endif
+                                        @endif
+                                        <hr size="1">
 
-                                @endforeach
+                                    @endforeach
+
+                                    @if($this->dataId == 0)
+                                    <br>
+                                    <button type="button" class="btn--ui primary" wire:click.prevent="addRow()">
+                                        Aggiungi causale
+                                    </button>
+                                    @endif
 
-                                @if($this->dataId == 0)
-                                <br>
-                                <button type="button" class="btn--ui primary" wire:click.prevent="addRow()">
-                                    Aggiungi causale
-                                </button>
                                 @endif
 
 
@@ -463,13 +520,23 @@
                                         @if($add)
 
                                             @if($commercial)
-                                                <button class="btn--ui primary"  type="submit" wire:click.prevent="store(false)">inserisci</button>
+
+                                                @if($corrispettivo_fiscale)
+                                                    @if($corrispettivo_causal_id > 0)
+                                                        <button class="btn--ui primary"  type="submit" wire:click.prevent="storeCorrispettivo()">inserisci corrispettivo fiscale</button>
+                                                    @else
+                                                        Non hai configurato una causale per il corrispettivo fiscale
+                                                    @endif
+                                                @else
+                                                    <button class="btn--ui primary"  type="submit" wire:click.prevent="store(false)">inserisci</button>
+                                                @endif
+
                                             @else
-                                                <button class="btn--ui primary sendInvoice mt-5 d-flex ms-auto" wire:click.prevent="store(true)"><i class="ico--ui sendingBtn"></i>inserisci e genera ricevuta</button>
+                                                <button class="btn--ui primary sendInvoice mt-5 d-flex ms-auto" wire:click.prevent="store(true)"><i class="ico--ui sendingBtn"></i>inserisci {{!$commercial ? 'genera ricevuta' : ''}}</button>
                                             @endif
 
                                         @endif
-                                        @if($update)
+                                        @if($update && !$corrispettivo_fiscale)
                                             <button class="btn--ui primary"  type="submit" wire:click.prevent="update(false)">salva</button>
                                         @endif
                                     @else
@@ -479,11 +546,12 @@
                                 </div>
                     </form>
                     </div>
+                    @if(!$corrispettivo_fiscale)
                     <div class="accountingEntry_resume card--ui" style="max-height:800px;">
                         <header>
                             <div class="username d-flex align-items-start">
                                 <i class="ico--ui accountingResume me-2"></i>
-                                <div class="user--resume_name d-flex flex-column"><span class="primary">Ricevuta {{$currentReceip ? $currentReceip->number . "/" . $currentReceip->year : ''}}</span></div></div>
+                                <div class="user--resume_name d-flex flex-column"><span class="primary">{{!$commercial ? 'Ricevuta' : 'Promemoria pagamento'}} {{$currentReceip ? $currentReceip->number . "/" . $currentReceip->year : ''}}</span></div></div>
                         </header>
 
                         <div class="resume--body d-flex justify-content-between flex-column">
@@ -504,10 +572,10 @@
                                                     <select class="form-control" wire:model="parent">
                                                         <option value="">Seleziona un genitore
                                                         @if($this->member->father_name != '')
-                                                            <option value="{{$this->member->father_name}} {{$this->member->father_fiscal_code}}">{{$this->member->father_name}} {{$this->member->father_fiscal_code}}
+                                                            <option value="{{$this->member->father_name}} (C.F. {{$this->member->father_fiscal_code}})">{{$this->member->father_name}} (C.F. {{$this->member->father_fiscal_code}})
                                                         @endif
                                                         @if($this->member->mother_name != '')
-                                                            <option value="{{$this->member->mother_name}} {{$this->member->mother_fiscal_code}}">{{$this->member->mother_name}} {{$this->member->mother_fiscal_code}}
+                                                            <option value="{{$this->member->mother_name}} (C.F. {{$this->member->mother_fiscal_code}})">{{$this->member->mother_name}} (C.F. {{$this->member->mother_fiscal_code}})
                                                         @endif
                                                     </select>
                                                 </span>
@@ -598,13 +666,16 @@
                                             </div>
                                         @endif
                                     @else
-                                        <button class="btn--ui primary sendInvoice mt-5 d-flex ms-auto" wire:click.prevent="update(true)"><i class="ico--ui sendingBtn"></i>salva e genera ricevuta</button>
+                                        @if(!$corrispettivo_fiscale)
+                                            <button class="btn--ui primary sendInvoice mt-5 d-flex ms-auto" wire:click.prevent="update(true)"><i class="ico--ui sendingBtn"></i>salva {{!$commercial ? ' e genera ricevuta' : ''}}</button>
+                                        @endif
                                     @endif
                                 @endif
 
                             </footer>
                         </div>
                     </div>
+                    @endif
                 </section>
 
                 <div  wire:ignore.self class="modal fade" id="userModal" tabindex="-1" aria-labelledby="userModalLabel" aria-hidden="true">
@@ -815,6 +886,10 @@
             input.value = "€ " + v.replace(/(\d)(\d\d)$/, "$1,$2").replace(/(^\d{1,3}|\d{3})(?=(?:\d{3})+(?:,|$))/g, '$1.');
         }
 
+        function setChangedAmount() {
+            @this.setAmount();
+        }
+
     </script>
 
     <link href="/css/datatables.css" rel="stylesheet" />
@@ -831,7 +906,9 @@
             var filterCommercial = localStorage.getItem("filterCommercial");
             if (filterCommercial)
             {
-                $('input[name="filterCommercial"]').val(filterCommercial);
+                //$('input[name="filterCommercial"]').val(filterCommercial);
+                $('input[name="filterCommercial"]').filter('[value="' + filterCommercial + '"]').attr('checked', true);
+                setFilterCommercial(filterCommercial);
             }
             var filterMember = localStorage.getItem("filterMember");
             if (filterMember)
@@ -910,13 +987,20 @@
             loadDataTable();
         }
 
+        var filterCommercial = 0;
+
+        function setFilterCommercial(value)
+        {
+            filterCommercial = value;
+        }
+
         function loadDataTable(){
 
             if ( $.fn.DataTable.isDataTable('#tablesaw-350') ) {
                 $('#tablesaw-350').DataTable().destroy();
             }
 
-            var filterCommercial = $('input[name="filterCommercial"]:checked').val();
+            // filterCommercial = $('input[name="filterCommercial"]:checked').val();
             var filterMember = $('.filterMember').val();
             var filterPaymentMethod = $('.filterPaymentMethod').val();
             var filterCausals = $('.filterCausals').val();
@@ -932,7 +1016,8 @@
             localStorage.setItem("filterTo", filterTo);
 
             $('#tablesaw-350').DataTable({
-                searching: false,
+                //searching: false,
+                //serverSide: true,
                 ajax: '/get_record_in?filterCommercial=' + filterCommercial + "&filterMember=" + filterMember + "&filterPaymentMethod=" + filterPaymentMethod + "&filterCausals=" + filterCausals + "&filterFrom=" + filterFrom + "&filterTo=" + filterTo,
                 columns: [
                     //{ data: 'id' },

+ 42 - 9
resources/views/receipt.blade.php

@@ -20,27 +20,60 @@
 <body>
     <img src="{{public_path() . env('LOGO')}}" width="200">
     <br><br><br>
-    <b>Associazione</b>: {{env('RAGIONE_SOCIALE', '')}}<br><br>
-    <b>Via</b>: {{env('INDIRIZZO', '')}} {{env('LOCALITA', '')}} ({{env('PROVINCIA', '')}})<br><br>
+    <div align="right"><b>RICEVUTA DI PAGAMENTO N. {{$receipt->number . "/" . $receipt->year}}</b></div><br><br>
+    <br>
+    {{env('RAGIONE_SOCIALE', '')}}<br><br>
+    <b>Indirizzo</b>: {{env('INDIRIZZO', '')}} {{env('LOCALITA', '')}} ({{env('PROVINCIA', '')}})<br><br>
     <b>C.F.</b>: {{env('CODICE_FISCALE', '')}}<br><br>
     <b>P.IVA</b>: {{env('PARTITA_IVA', '')}}<br><br>
     <hr><br>
+
     <b>Intestata a</b><br><br>
     @if(!$receipt->member->isAdult())
         <b>Genitore</b>: {{$receipt->parent}}<br><br>
     @endif
-    <b>Cognome</b>: {{$receipt->member->last_name}}<br><br>
-    <b>Nome</b>: {{$receipt->member->first_name}}<br><br>
-    <b>Nata a</b>: {{@$receipt->member->birth_city->name}} ({{@$receipt->member->birth_province->name}}) il {{$receipt->member->birth_date ? date("d/m/Y", strtotime($receipt->member->birth_date)) : ""}}<br><br>
-    <b>Residente in</b>: {{$receipt->member->address}} {{@$receipt->member->city->name}} ({{@$receipt->member->province->name}})<br><br>
-    <b>Codice Fiscale</b>: {{$receipt->member->fiscal_code}}<br><br>
+    @if($receipt->member->last_name != '')
+        <b>Cognome</b>: {{$receipt->member->last_name}}<br><br>
+    @endif
+    @if($receipt->member->first_name != '')
+        <b>Nome</b>: {{$receipt->member->first_name}}<br><br>
+    @endif
+    @if(@$receipt->member->birth_city->name != '' || @$receipt->member->birth_province->name != '' || @$receipt->member->birth_date != '')
+        <b>Nato/a a</b>:
+            @if($receipt->member->birth_city->name != '')
+                {{@$receipt->member->birth_city->name}}
+            @endif
+            @if($receipt->member->birth_province->name != '')
+                ({{@$receipt->member->birth_province->name}})
+            @endif
+            @if($receipt->member->birth_date != '')
+                il {{$receipt->member->birth_date ? date("d/m/Y", strtotime($receipt->member->birth_date)) : ""}}
+            @endif
+        <br><br>
+    @endif
+    @if($receipt->member->address != '' || @$receipt->member->city->name != ''  || @$receipt->member->province->name != '')
+        <b>Residente in</b>:
+            @if($receipt->member->address != '')
+                {{$receipt->member->address}}
+            @endif
+            @if(@$receipt->member->city->name != '')
+                {{@$receipt->member->city->name}}
+            @endif
+            @if(@$receipt->member->province->name != '')
+                ({{@$receipt->member->province->name}})
+            @endif
+            <br><br>
+    @endif
+    @if($receipt->member->fiscal_code != '')
+        <b>Codice Fiscale</b>: {{$receipt->member->fiscal_code}}<br><br>
+    @endif
     <hr><br>
-    <b>RICEVUTA DI PAGAMENTO N. {{$receipt->number . "/" . $receipt->year}}</b><br><br>
+
     @php
     $total = 0;
     @endphp
     @foreach($receipt->rows as $row)
-        <b>Descrizione</b>: {{@$row->causal->getTree()}} ({{$row->note}})<br><br>
+        <b>Descrizione</b>: {{@$row->causal->getTree()}} {{$row->note != '' ? ('(' . $row->note . ')') : ''}}<br><br>
         <b>Importo</b>: {{formatPrice($row->amount)}}<br><br>
         @php
         $total += $row->amount;

+ 43 - 6
routes/web.php

@@ -104,6 +104,16 @@ Route::get('/get_members', function(){
 
     // $datas = \App\Models\Member::select('members.*')->where('id', '>', 0);
     $x = \App\Models\Member::select('id', 'first_name', 'last_name', 'phone', 'birth_date')->where('id', '>', 0);
+
+    if (isset($_GET["search"]["value"]))
+    {
+        $v = $_GET["search"]["value"];
+        $x = $x->where(function ($query) use ($v) {
+            $query->where('first_name', 'like', '%' . $v . '%')
+                  ->orWhere('last_name', 'like', '%' . $v . '%');
+        });
+        //where('first_name', 'like', '%' . $_GET["search"]["value"] . '%');
+    }
     if ($_GET["cards"] != "")
     {
         $card_ids = \App\Models\MemberCard::whereIn('card_id', explode(",", $_GET["cards"]))->pluck('member_id');
@@ -150,7 +160,12 @@ Route::get('/get_members', function(){
         $x = $x->whereIn('id', $certs);
     }
 
-    $x = $x->get();
+    $count = $x->count();
+
+    if (isset($_GET["start"]))
+        $x = $x->offset($_GET["start"])->limit($_GET["length"])->get();
+    else
+        $x = $x->get();
 
     $filterStatus = isset($_GET["status"]) ? $_GET["status"] : -1;
 
@@ -227,7 +242,7 @@ Route::get('/get_members', function(){
     */
 
     // $datas = $x; // ->orderBy($this->sortField, $this->sortAsc ? 'ASC' : 'DESC')->paginate(10);
-    return json_encode(array("data" => $datas));
+    return json_encode(array("data" => $datas,  "recordsTotal" => $count, "recordsFiltered" => $count));
 
 
 });
@@ -268,18 +283,40 @@ Route::get('/get_record_in', function(){
         $x = $x->where('date', '<=', $_GET["filterTo"]);
     }
 
+    if (isset($_GET["search"]["value"]))
+    {
+        $v = $_GET["search"]["value"];
+        $x = $x->where(function ($query) use ($v) {
+            $query->where('first_name', 'like', '%' . $v . '%')
+                  ->orWhere('last_name', 'like', '%' . $v . '%');
+        });
+        //where('first_name', 'like', '%' . $_GET["search"]["value"] . '%');
+    }
+
+    $start = 0;
+    $limit = 10000;
+
+    if (isset($_GET["start"]))
+    {
+        $start = $_GET["start"];
+        $limit = $_GET["length"];
+    }
+
     $total = 0;
     foreach($x->get() as $r)
     {
         foreach($r->rows as $rr)
         {
-            $total += $rr->amount;
-            if ($rr->vat_id > 0)
-                $total += getVatValue($rr->amount, $rr->vat_id);
+            if (!$r->deleted)
+            {
+                $total += $rr->amount;
+                if ($rr->vat_id > 0)
+                    $total += getVatValue($rr->amount, $rr->vat_id);
+            }
         }
     }
 
-    $x = $x->get();
+    $x = $x->offset($start)->limit($limit)->get();
 
     foreach($x as $idx => $r)
     {