Luca Parisio 1 年間 前
コミット
85c1148a9f

+ 5 - 1
app/Http/Livewire/Member.php

@@ -46,7 +46,7 @@ class Member extends Component
         $this->sortField = $field;
     }
 
-    public $records, $first_name, $last_name, $image, $image_old, $status, $birth_place, $birth_city_id, $birth_province_id, $birth_nation_id, $birth_date, $gender, $fiscal_code, $address, $zip_code, $nation_id, $province_id, $city_id, $phone, $phone2, $phone3, $email, $enabled, $dataId, $update = false, $add = false;
+    public $records, $first_name, $last_name, $image, $image_old, $status, $birth_place, $birth_city_id, $birth_province_id, $birth_nation_id, $birth_date, $gender, $no_send_mail, $fiscal_code, $address, $zip_code, $nation_id, $province_id, $city_id, $phone, $phone2, $phone3, $email, $enabled, $dataId, $update = false, $add = false;
 
     public $isSaving = false;
 
@@ -160,6 +160,7 @@ class Member extends Component
         $this->father_doc_type = '';
         $this->mother_doc_type = '';
         $this->gender = null;
+        $this->no_send_mail = false;
         $this->fiscal_code = '';
         $this->address = '';
         $this->zip_code = '';
@@ -835,6 +836,7 @@ class Member extends Component
                 'document_expire_date' => $this->document_expire_date,
                 'document_files' => $docs,
                 'gender' => $this->gender,
+                'no_send_mail' => $this->no_send_mail,
                 'fiscal_code' => $this->fiscal_code,
                 'address' => $this->address,
                 'zip_code' => $this->zip_code,
@@ -910,6 +912,7 @@ class Member extends Component
                 $this->document_expire_date = $member->document_expire_date;
                 $this->document_files = explode("|", $member->document_files);
                 $this->gender = $member->gender;
+                $this->no_send_mail = $member->no_send_mail;
                 $this->fiscal_code = $member->fiscal_code;
                 $this->address = $member->address;
                 $this->zip_code = $member->zip_code;
@@ -1057,6 +1060,7 @@ class Member extends Component
                 'document_expire_date' => $this->document_expire_date,
                 'document_files' => $docs,
                 'gender' => $this->gender,
+                'no_send_mail' => $this->no_send_mail,
                 'fiscal_code' => $this->fiscal_code,
                 'address' => $this->address,
                 'zip_code' => $this->zip_code,

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

@@ -152,7 +152,6 @@ class Record extends Component
                         $query->where('deleted', false)->orWhere('deleted', null);
                     })
                     ->orderBy('date', 'ASC')->orderBy('records.created_at', 'ASC')
-                    //->where('records.commercial', '=', false)
                     ->get();
 
         /*

+ 44 - 15
app/Http/Livewire/RecordIN.php

@@ -4,6 +4,8 @@ namespace App\Http\Livewire;
 use Livewire\Component;
 use Livewire\WithPagination;
 use Barryvdh\DomPDF\Facade\Pdf;
+use Illuminate\Support\Facades\Storage;
+use Illuminate\Support\Facades\Mail;
 
 class RecordIN extends Component
 {
@@ -51,6 +53,7 @@ class RecordIN extends Component
     $year,
     $type,
     $deleted,
+    $financial_movement,
     $amount,
     $vat,
     $virtual,
@@ -181,6 +184,7 @@ class RecordIN extends Component
         $this->date = date("Y-m-d");
         $this->type = 'IN';
         $this->deleted = false;
+        $this->financial_movement = false;
         $this->newMemberFirstName = '';
         $this->newMemberLastName = '';
         $this->newMemberFiscalCode = '';
@@ -430,6 +434,7 @@ class RecordIN extends Component
                         'date' => $this->date,
                         'type' => $this->type,
                         'amount' => $price,
+                        'financial_movement' => $this->financial_movement,
                         'deleted' => $this->deleted
                     ]);
 
@@ -487,6 +492,7 @@ class RecordIN extends Component
                 'corrispettivo_fiscale' => $this->corrispettivo_fiscale,
                 'date' => $this->date,
                 'type' => $this->type,
+                'financial_movement' => $this->financial_movement,
                 'deleted' => $this->deleted
             ]);
             $this->dataId = $record->id;
@@ -536,11 +542,14 @@ class RecordIN extends Component
                 $c->save();
             }
 
-            $payment_method = \App\Models\PaymentMethod::findOrFail($this->payment_method_id);
-            if (!$payment_method->money)
+            if (!$this->financial_movement)
             {
-                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');
@@ -587,6 +596,7 @@ class RecordIN extends Component
                 $this->date = date("Y-m-d", strtotime($record->date));
                 $this->type = $record->type;
                 $this->deleted = $record->deleted;
+                $this->financial_movement = $record->financial_movement;
                 $this->dataId = $record->id;
                 $this->update = true;
                 $this->add = false;
@@ -620,13 +630,6 @@ class RecordIN extends Component
             'rows.*.amount' => 'required'
         ];
 
-        /*$f = false;
-        foreach($this->rows as $row)
-        {
-            if ($row["commercial"]) $f = true;
-        }
-        if ($f)
-            $rules["member_id"] = 'required';*/
         if(!$this->commercial)
             $rules["member_id"] = 'required';
 
@@ -642,6 +645,7 @@ class RecordIN extends Component
                 'corrispettivo_fiscale' => $this->corrispettivo_fiscale,
                 'date' => date("Y-m-d", strtotime($this->date)),
                 'type' => $this->type,
+                'financial_movement' => $this->financial_movement,
                 'deleted' => $this->deleted,
             ]);
 
@@ -673,11 +677,14 @@ class RecordIN extends Component
             $rec->amount = $tot;
             $rec->save();
 
-            $payment_method = \App\Models\PaymentMethod::findOrFail($this->payment_method_id);
-            if (!$payment_method->money)
+            if (!$this->financial_movement)
             {
-                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();
@@ -720,6 +727,7 @@ class RecordIN extends Component
             if($receipt)
             {
                 $receipt->status = 99;
+                sendReceiptDeleteEmail($receipt);
                 $receipt->save();
             }
 
@@ -867,6 +875,25 @@ class RecordIN extends Component
 
             $this->currentReceip = $receipt;
 
+            sendReceiptEmail($receipt);
+
+            /*
+
+            // Invio mail
+            $pdf = PDF::loadView('receipt', array('receipt' => $receipt));
+            $pdfName = "ricevuta_" . $receipt->number . "_" . $receipt->year . ".pdf";
+            Storage::put('public/pdf/' . $pdfName, $pdf->output());
+            $email = \App\Models\Member::findOrFail($receipt->member_id)->email;
+            if ($email != '')
+            {
+                Mail::to($email)->send(new \App\Mail\ReceipEmail([
+                    'pdf' => 'public/pdf/' . $pdfName,
+                    'number' => $receipt->number . "/" . $receipt->year
+                ]));
+            }
+
+            */
+
             session()->flash('receipt',"Ricevuta " . $number . "/" . date("Y") . " creata correttamente");
 
             // Apro la ricevuta
@@ -882,7 +909,9 @@ class RecordIN extends Component
         $receipt = \App\Models\Receipt::findOrFail($this->currentReceip->id);
         $receipt->status = 99;
         $receipt->save();
+        sendReceiptDeleteEmail($receipt);
         $this->currentReceip = $receipt;
+
     }
 
     function currencyToDouble($val)

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

@@ -136,6 +136,9 @@ class RecordINOUT extends Component
                     ->where(function ($query)  {
                         $query->where('deleted', false)->orWhere('deleted', null);
                     })
+                    ->where(function ($query)  {
+                        $query->where('financial_movement', false)->orWhere('financial_movement', null);
+                    })
                     ->where('records_rows.when', 'like', '%' . $f . '%')->get();
                 //$records = $records->orderBy('date', 'DESC')->get();
 
@@ -164,6 +167,9 @@ class RecordINOUT extends Component
                     ->where(function ($query)  {
                         $query->where('deleted', false)->orWhere('deleted', null);
                     })
+                    ->where(function ($query)  {
+                        $query->where('financial_movement', false)->orWhere('financial_movement', null);
+                    })
                     ->where('records_rows.when', 'like', '%' . $f . '%')->get();
                 //$records = $records->orderBy('date', 'DESC')->get();
 
@@ -399,6 +405,9 @@ class RecordINOUT extends Component
                 ->where(function ($query)  {
                     $query->where('deleted', false)->orWhere('deleted', null);
                 })
+                ->where(function ($query)  {
+                    $query->where('financial_movement', false)->orWhere('financial_movement', null);
+                })
                 ->where('records_rows.when', 'like', '%' . $filter . '%')->get();
             //$records = $records->orderBy('date', 'DESC')->get();
 
@@ -427,6 +436,9 @@ class RecordINOUT extends Component
                 ->where(function ($query)  {
                     $query->where('deleted', false)->orWhere('deleted', null);
                 })
+                ->where(function ($query)  {
+                    $query->where('financial_movement', false)->orWhere('financial_movement', null);
+                })
                 ->where('records_rows.when', 'like', '%' . $filter . '%')->get();
             //$records = $records->orderBy('date', 'DESC')->get();
 

+ 63 - 0
app/Mail/ReceipDeleteEmail.php

@@ -0,0 +1,63 @@
+<?php
+
+namespace App\Mail;
+
+use Illuminate\Bus\Queueable;
+use Illuminate\Contracts\Queue\ShouldQueue;
+use Illuminate\Mail\Mailable;
+use Illuminate\Mail\Mailables\Content;
+use Illuminate\Mail\Mailables\Envelope;
+use Illuminate\Queue\SerializesModels;
+use Illuminate\Mail\Mailables\Attachment;
+
+class ReceipDeleteEmail extends Mailable
+{
+    use Queueable, SerializesModels;
+    public $mailData;
+    /**
+     * Create a new message instance.
+     *
+     * @return void
+     */
+    public function __construct($mailData)
+    {
+        $this->mailData = $mailData;
+    }
+
+    /**
+     * Get the message envelope.
+     *
+     * @return \Illuminate\Mail\Mailables\Envelope
+     */
+    public function envelope()
+    {
+        return new Envelope(
+            subject: env('RECEIPT_DELETE_MAIL_SUBJECT', 'Centro Sportivo La Madonnella - Annullamento ricevuta di pagamento ') . $this->mailData["number"],
+        );
+    }
+
+    /**
+     * Get the message content definition.
+     *
+     * @return \Illuminate\Mail\Mailables\Content
+     */
+    public function content()
+    {
+        return new Content(
+            view: 'emails.receipt_delete',
+        );
+    }
+
+    /**
+     * Get the attachments for the message.
+     *
+     * @return array
+     */
+    public function attachments()
+    {
+        return [
+            Attachment::fromStorage($this->mailData["pdf"]),
+            //$this->mailData["pdf"]
+        ];
+    }
+}

+ 63 - 0
app/Mail/ReceipEmail.php

@@ -0,0 +1,63 @@
+<?php
+
+namespace App\Mail;
+
+use Illuminate\Bus\Queueable;
+use Illuminate\Contracts\Queue\ShouldQueue;
+use Illuminate\Mail\Mailable;
+use Illuminate\Mail\Mailables\Content;
+use Illuminate\Mail\Mailables\Envelope;
+use Illuminate\Queue\SerializesModels;
+use Illuminate\Mail\Mailables\Attachment;
+
+class ReceipEmail extends Mailable
+{
+    use Queueable, SerializesModels;
+    public $mailData;
+    /**
+     * Create a new message instance.
+     *
+     * @return void
+     */
+    public function __construct($mailData)
+    {
+        $this->mailData = $mailData;
+    }
+
+    /**
+     * Get the message envelope.
+     *
+     * @return \Illuminate\Mail\Mailables\Envelope
+     */
+    public function envelope()
+    {
+        return new Envelope(
+            subject: env('RECEIPT_MAIL_SUBJECT', 'Centro Sportivo La Madonnella - Ricevuta di pagamento ') . $this->mailData["number"],
+        );
+    }
+
+    /**
+     * Get the message content definition.
+     *
+     * @return \Illuminate\Mail\Mailables\Content
+     */
+    public function content()
+    {
+        return new Content(
+            view: 'emails.receipt',
+        );
+    }
+
+    /**
+     * Get the attachments for the message.
+     *
+     * @return array
+     */
+    public function attachments()
+    {
+        return [
+            Attachment::fromStorage($this->mailData["pdf"]),
+            //$this->mailData["pdf"]
+        ];
+    }
+}

+ 1 - 0
app/Models/Member.php

@@ -47,6 +47,7 @@ class Member extends Model
         'mother_doc_number',
         'mother_doc_type',
         'enabled',
+        'no_send_mail'
     ];
 
     public function nation()

+ 1 - 0
app/Models/Record.php

@@ -23,6 +23,7 @@ class Record extends Model
         'commercial',
         'corrispettivo_fiscale',
         'deleted',
+        'financial_movement',
         'amount'
     ];
 

+ 75 - 0
app/helpers.php

@@ -1,4 +1,8 @@
 <?php
+use Barryvdh\DomPDF\Facade\Pdf;
+use Illuminate\Support\Facades\Storage;
+use Illuminate\Support\Facades\Mail;
+
 
 function getCards()
 {
@@ -66,3 +70,74 @@ function getConfiguration($field)
     }
     return $ret;
 }
+
+function sendReceiptEmail($receipt)
+{
+    $pdf = PDF::loadView('receipt', array('receipt' => $receipt));
+    $pdfName = "Ricevuta_" . $receipt->number . "_" . $receipt->year . ".pdf";
+    Storage::put('public/pdf/' . $pdfName, $pdf->output());
+    $email = '';
+    $member = \App\Models\Member::findOrFail($receipt->member_id);
+    if ($member->no_send_mail == null || !$member->no_send_mail)
+    {
+        if ($member->isAdult())
+            $email = $member->email;
+        else
+        {
+            $check = explode(" ", $member->father_name);
+            if (str_contains($receipt->parent, $check[0]))
+            {
+                $email = $member->father_email;
+            }
+            else
+            {
+                $check = explode(" ", $member->mother_name);
+                if (str_contains($receipt->parent, $check[0]))
+                    $email = $member->mother_email;
+            }
+        }
+        if ($email != '')
+        {
+            Mail::to($email)->bcc(env('MAIL_CCN', ''))->send(new \App\Mail\ReceipEmail([
+                'pdf' => 'public/pdf/' . $pdfName,
+                'number' => $receipt->number . "/" . $receipt->year
+            ]));
+        }
+    }
+}
+
+function sendReceiptDeleteEmail($receipt)
+{
+    $pdf = PDF::loadView('receipt', array('receipt' => $receipt));
+    $pdfName = "Ricevuta_annullata_" . $receipt->number . "_" . $receipt->year . ".pdf";
+    Storage::put('public/pdf/' . $pdfName, $pdf->output());
+    $email = '';
+    $member = \App\Models\Member::findOrFail($receipt->member_id);
+    if ($member->no_send_mail == null || !$member->no_send_mail)
+    {
+        if ($member->isAdult())
+            $email = $member->email;
+        else
+        {
+            $check = explode(" ", $member->father_name);
+            if (str_contains($receipt->parent, $check[0]))
+            {
+                $email = $member->father_email;
+            }
+            else
+            {
+                $check = explode(" ", $member->mother_name);
+                if (str_contains($receipt->parent, $check[0]))
+                    $email = $member->mother_email;
+            }
+        }
+        if ($email != '')
+        {
+            Mail::to($email)->bcc(env('MAIL_CCN', ''))->send(new \App\Mail\ReceipDeleteEmail([
+                'number' => $receipt->number . "/" . $receipt->year,
+                'pdf' => 'public/pdf/' . $pdfName,
+                'date' => date("d/m/Y", strtotime($receipt->date))
+            ]));
+        }
+    }
+}

+ 32 - 0
database/migrations/2024_09_19_144000_add_financial_movement_to_records_table.php

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

+ 32 - 0
database/migrations/2024_09_20_140000_add_no_send_mail_to_members_table.php

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

+ 17 - 0
resources/views/emails/receipt.blade.php

@@ -0,0 +1,17 @@
+Gentile cliente,
+<br><br>
+si allega la ricevuta del pagamento effettuato.
+<br><br>
+<br><br>
+Cordiali saluti,
+<br><br>
+<span style="color:blue">
+La segreteria S.S.D. IAO TEAM a r.l.<br>
+contatti: 06 60674794 - sede: via di Villa Grazioli snc - 00046 Grottaferrata (RM) - c.f. 92015570580 - P. IVA 12576361005<br>
+<small>
+Avvertenze ai sensi del "Regolamento generale sulla protezione dei dati o "GDPR" (General Data Protection Regulation)<br>
+le informazioni contenute in questo messaggio di posta elettronica e/o nel/i file/s allegato/i sono da considerarsi strettamente riservate. Il loro utilizzo è consentito esclusivamente al destinatario sopra indicato. Qualora riceveste questo messaggio senza essere il destinatario Vi preghiamo cortesemente di informarci con apposito messaggio e procedere alla distruzione del messaggio stesso, cancellandolo dal Vostro sistema; costituisce comportamento contrario ai principi dettati dal "GDPR" (General Data Protection Regulation) il trattenere il messaggio stesso, divulgarlo anche in parte, distribuirlo ad altri soggetti, ovvero copiarlo.<br>
+Grazie.
+</small>
+</span>
+<br><br>

+ 21 - 0
resources/views/emails/receipt_delete.blade.php

@@ -0,0 +1,21 @@
+Gentile cliente,
+<br><br>
+la ricevuta di pagamento {{$mailData["number"]}}, emessa il {{$mailData["date"]}}, è stata annullata.
+<br><br>
+Ci scusiamo per l’eventuale inconveniente e rimaniamo a disposizione per qualsiasi chiarimento.
+<br><br>
+Grazie per la sua comprensione e collaborazione.
+<br><br>
+<br><br>
+Cordiali saluti,
+<br><br>
+<span style="color:blue">
+La segreteria S.S.D. IAO TEAM a r.l.<br>
+contatti: 06 60674794 - sede: via di Villa Grazioli snc - 00046 Grottaferrata (RM) - c.f. 92015570580 - P. IVA 12576361005<br>
+<small>
+Avvertenze ai sensi del "Regolamento generale sulla protezione dei dati o "GDPR" (General Data Protection Regulation)<br>
+le informazioni contenute in questo messaggio di posta elettronica e/o nel/i file/s allegato/i sono da considerarsi strettamente riservate. Il loro utilizzo è consentito esclusivamente al destinatario sopra indicato. Qualora riceveste questo messaggio senza essere il destinatario Vi preghiamo cortesemente di informarci con apposito messaggio e procedere alla distruzione del messaggio stesso, cancellandolo dal Vostro sistema; costituisce comportamento contrario ai principi dettati dal "GDPR" (General Data Protection Regulation) il trattenere il messaggio stesso, divulgarlo anche in parte, distribuirlo ad altri soggetti, ovvero copiarlo.<br>
+Grazie.
+</small>
+</span>
+<br><br>

+ 18 - 9
resources/views/livewire/member.blade.php

@@ -225,23 +225,25 @@
                         <span class="filter--item_title">Stato tesseramento</span>
 
                         <div class="filter--item_formElement row">
-                            <div class="col-6">
-                                <div class="form-check form-check-inline  align-items-center">
+                            <div class="col-12">
+                                <!--<div class="form-check form-check-inline  align-items-center">
                                     <input class="form-check-input " type="radio" name="chkStatus" checked value="-1">
                                     <label class="form-check-label ms-2" >Tutti</label>
-                                </div>
+                                </div>-->
                                 <div class="form-check form-check-inline  align-items-center">
-                                    <input class="form-check-input " type="radio"   name="chkStatus" value="2">
+                                    <input class="form-check-input " type="checkbox"   name="chkStatus2" value="2">
                                     <label class="form-check-label ms-2" >Attivo</label>
                                 </div>
                             </div>
-                            <div class="col-6">
+                            <div class="col-12">
                                 <div class="form-check form-check-inline  align-items-center">
-                                    <input class="form-check-input " type="radio"  name="chkStatus" value="1">
+                                    <input class="form-check-input " type="checkbox"  name="chkStatus1" value="1">
                                     <label class="form-check-label ms-2" >Sospeso</label>
                                 </div>
+                            </div>
+                            <div class="col-12">
                                 <div class="form-check form-check-inline  align-items-center">
-                                    <input class="form-check-input " type="radio"  name="chkStatus" value="0">
+                                    <input class="form-check-input " type="checkbox"  name="chkStatus0" value="0">
                                     <label class="form-check-label ms-2" >Non tesserato</label>
                                 </div>
 
@@ -666,6 +668,10 @@
 
                                                 @endif
 
+                                                <div class="col-md-12">
+                                                    <input type="checkbox" id="no_send_mail" wire:model="no_send_mail">&nbsp;<label for="birth_place" class="form-label">Non inviare mail ricevuta</label>
+                                                </div>
+
                                                 @if($dataId > 0)
                                                     <span class="title-form primary d-block w-100">Stato</span>
                                                     <div class="col-12">
@@ -2064,7 +2070,10 @@
             var chkCertificateScadenza = $(".chkCertificateScadenza").is(':checked') ? "1" : "";
             var chkCertificateScaduti = $(".chkCertificateScaduti").is(':checked') ? "1" : "";
 
-            var status = $('input[name="chkStatus"]:checked').val();
+            var chkStatus0 = $('input[name="chkStatus0"]').is(':checked') ? "1" : "0";
+            var chkStatus1 = $('input[name="chkStatus1"]').is(':checked') ? "1" : "0";
+            var chkStatus2 = $('input[name="chkStatus2"]').is(':checked') ? "1" : "0";
+            //var status2 = $('input[name="chkStatus2"]:checked').val();
 
             var fromYear = $('input[name="txtFromYear"]').val();
             var toYear = $('input[name="txtToYear"]').val();
@@ -2072,7 +2081,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,
+                ajax: '/get_members?cards=' + cards + "&categories=" + categories + "&chkCertificateNormal=" + chkCertificateNormal + "&chkCertificateAgonistico=" + chkCertificateAgonistico + "&chkCertificateScadenza=" + chkCertificateScadenza + "&chkCertificateScaduti=" + chkCertificateScaduti + "&chkStatus0=" + chkStatus0 + "&chkStatus1=" + chkStatus1 + "&chkStatus2=" + chkStatus2 + "&fromYear=" + fromYear + "&toYear=" + toYear,
                 columns: [
                     { data: 'id' },
                     {

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

@@ -94,6 +94,7 @@
                         <td>
                             <button type="button" class="btn btn-outline-primary btn-sm" onclick="document.location.href='/in?id={{$record->record_id}}'">Dettaglio</button>
                             <a target="_blank" class="btn btn-outline-primary btn-sm" href="/receipt/{{$record->id}}">Stampa</a>
+                            <a target="_blank" class="btn btn-outline-primary btn-sm" onclick="sendMail({{$record->id}})">Invia tramite mail</a>
                         </td>
                     </tr>
                 @endforeach
@@ -135,6 +136,13 @@
             $('#tablesaw-350').DataTable().destroy();
         }
 
+        function sendMail(id)
+        {
+            $.get("/receipt/mail/" + id, function(data, status){
+                alert('Mail inviata');
+            });
+        }
+
         function loadDataTable(){
             $('#tablesaw-350').DataTable({
                 thead: {

+ 42 - 6
resources/views/livewire/records_in.blade.php

@@ -184,7 +184,7 @@
                                                     <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>
+                                            </div>
                                         </div>
                                     </div>
 
@@ -230,10 +230,30 @@
                                                     <span class="title-form w-100">Certificato medico </span><span class="badge tessera-badge suspended">scaduto</span>
                                                 @endif
                                             @endif
+                                            @php
+                                            $status = $this->member->getStatus()["status"];
+                                            $class = $status > 0 ? ($status == 2 ? 'active' : 'suspended') : 'due';
+                                            $text = $status > 0 ? ($status == 2 ? 'Tesserato' : 'Sospeso') : 'Non tesserato';
+                                            @endphp
+                                            <span class="tablesaw-cell-content"><span class="badge tessera-badge {{$class}}">{{$text}}</span></span>
                                         @endif
                                     </div>
                                 </div>
 
+                                @if(false)
+                                <br>
+                                <div class="col-md-12">
+                                    <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="financial_movement" type="checkbox" wire:model="financial_movement" {{$this->dataId > 0 && !$isDuplicate ? 'disabled' : ''}}>
+                                                <label class="form-check-label" for="flexCheckChecked">&nbsp;&nbsp;&nbsp;Movimento finanziario</label>
+                                            </div>
+                                        </div>
+                                    </div>
+                                </div>
+                                @endif
+
                                 @if($commercial)
 
                                     <br>
@@ -532,12 +552,20 @@
                                                 @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 {{!$commercial ? 'genera ricevuta' : ''}}</button>
+                                                @if($this->member && !$commercial && !$this->member->isAdult() && $parent == '')
+                                                    <span style="color:red">Devi selezionare un genitore</span>
+                                                @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 {{!$commercial ? 'genera ricevuta' : ''}}</button>
+                                                @endif
                                             @endif
 
                                         @endif
                                         @if($update && !$corrispettivo_fiscale)
-                                            <button class="btn--ui primary"  type="submit" wire:click.prevent="update(false)">salva</button>
+                                            @if($this->member && !$commercial && !$this->member->isAdult() && $parent == '')
+                                                <span style="color:red">Devi selezionare un genitore</span>
+                                            @else
+                                                <button class="btn--ui primary sendInvoice mt-5 d-flex ms-auto" wire:click.prevent="update({{!$commercial}})"><i class="ico--ui sendingBtn"></i>inserisci {{!$commercial ? 'genera ricevuta' : ''}}</button>
+                                            @endif
                                         @endif
                                     @else
                                         <span style="color:red">Attenzione : non c'è credito sufficiente sul borsellino virtuale</span>
@@ -654,11 +682,15 @@
                                     </div>
                                 </div>
 
-                                @if($update)
+                                @if($update && !$isDuplicate)
                                     @if($currentReceip)
                                         @if($currentReceip->status == 99)
                                             <br><b style="float:right">Annullata</b>
-                                            <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 rigenera ricevuta</button>
+                                            @if($this->member && !$commercial && !$this->member->isAdult() && $parent == '')
+                                                <span style="color:red">Devi selezionare un genitore</span>
+                                            @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 rigenera ricevuta</button>
+                                            @endif
                                         @else
                                             <div class="mt-5">
                                                 <a target="_blank" class="btn--ui" href="/receipt/{{$currentReceip->id}}"><i class="ico--ui sendingBtn"></i>stampa ricevuta</a>
@@ -667,7 +699,11 @@
                                         @endif
                                     @else
                                         @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>
+                                            @if($this->member && !$commercial && !$this->member->isAdult() && $parent == '')
+                                                <span style="color:red">Devi selezionare un genitore</span>
+                                            @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 {{!$commercial ? ' e genera ricevuta' : ''}}</button>
+                                            @endif
                                         @endif
                                     @endif
                                 @endif

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

@@ -21,6 +21,9 @@
     <img src="{{public_path() . env('LOGO')}}" width="200">
     <br><br><br>
     <div align="right"><b>RICEVUTA DI PAGAMENTO N. {{$receipt->number . "/" . $receipt->year}}</b></div><br><br>
+    @if($receipt->status == 99)
+        <div align="right"><b style="color:red">ANNULLATA</b></div><br><br>
+    @endif
     <br>
     {{env('RAGIONE_SOCIALE', '')}}<br><br>
     <b>Indirizzo</b>: {{env('INDIRIZZO', '')}} {{env('LOCALITA', '')}} ({{env('PROVINCIA', '')}})<br><br>
@@ -40,13 +43,13 @@
     @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 != '')
+            @if(@$receipt->member->birth_city->name != '')
                 {{@$receipt->member->birth_city->name}}
             @endif
-            @if($receipt->member->birth_province->name != '')
+            @if(@$receipt->member->birth_province->name != '')
                 ({{@$receipt->member->birth_province->name}})
             @endif
-            @if($receipt->member->birth_date != '')
+            @if(@$receipt->member->birth_date != '')
                 il {{$receipt->member->birth_date ? date("d/m/Y", strtotime($receipt->member->birth_date)) : ""}}
             @endif
         <br><br>

+ 108 - 55
routes/web.php

@@ -59,6 +59,37 @@ Route::get('/receipt/{id}', function($id){
     );*/
 });
 
+Route::get('/receipt/mail/{id}', function($id){
+    $receipt = \App\Models\Receipt::findOrFail($id);
+    if ($receipt->status == 99)
+        sendReceiptDeleteEmail($receipt);
+    else
+        sendReceiptEmail($receipt);
+    /*
+    $pdf = PDF::loadView('receipt', array('receipt' => $receipt));
+    $pdfName = "ricevuta_" . $receipt->number . "_" . $receipt->year . ".pdf";
+    Storage::put('public/pdf/' . $pdfName, $pdf->output());
+    $email = \App\Models\Member::findOrFail($receipt->member_id)->email;
+    if ($email != '')
+    {
+        Mail::to($email)->send(new \App\Mail\ReceipEmail([
+            'name' => 'Luca',
+            'pdf' => 'public/pdf/' . $pdfName,
+            'number' => $receipt->number . "/" . $receipt->year
+        ]));
+    }
+        */
+
+    return true;
+    //return $pdf->stream();
+    /*return response()->streamDownload(
+        fn () => print($pdf),
+        "ricevuta_" . $receipt->number . "_" . $receipt->year . ".pdf"
+    );*/
+});
+
+
+
 Route::get('/nations', function(){
     if (isset($_GET["q"]))
         $datas = \App\Models\Nation::where('name', 'like', $_GET["q"] . '%')->orderBy('name')->get();
@@ -133,31 +164,63 @@ Route::get('/get_members', function(){
         $x = $x->where('birth_date', '>', date("Y-m-d", strtotime("-" . $_GET["toYear"] . " year", time())));
     }
 
-    $certs = [];
+    $ids = [];
 
     if ($_GET["chkCertificateNormal"] != "")
     {
         $normal = \App\Models\MemberCertificate::where('type', 'N')->pluck('member_id');
-        $x = $x->whereIn('id', $normal);;
+        $ids = array_merge($ids, $normal->toArray());
+        //$x = $x->whereIn('id', $normal);;
     }
     if ($_GET["chkCertificateAgonistico"] != "")
     {
         $agonistic = \App\Models\MemberCertificate::where('type', 'A')->pluck('member_id');
-        $x = $x->whereIn('id', $agonistic);
+        $ids = array_merge($ids, $agonistic->toArray());
+        //$x = $x->whereIn('id', $agonistic);
     }
     if ($_GET["chkCertificateScaduti"] != "")
     {
         $scaduto = \App\Models\MemberCertificate::where('expire_date', '<', date("Y-m-d"))->pluck('member_id');
-        $x = $x->whereIn('id', $scaduto);
+        $ids = array_merge($ids, $scaduto->toArray());
+        //$x = $x->whereIn('id', $scaduto);
     }
     if ($_GET["chkCertificateScadenza"] != "")
     {
         $scadenza = \App\Models\MemberCertificate::whereBetween('expire_date', [date("Y-m-d"), date("Y-m-d", strtotime("+1 month"))])->pluck('member_id');
-        $x = $x->whereIn('id', $scadenza);
+        $ids = array_merge($ids, $scadenza->toArray());
+        //$x = $x->whereIn('id', $scadenza);
+    }
+
+
+    //$filterStatus = isset($_GET["status"]) ? $_GET["status"] : -1;
+    $chkStatus = [];
+    $chkStatus0 = isset($_GET["chkStatus0"]) ? $_GET["chkStatus0"] : 0;
+    if($chkStatus0 > 0)
+        $chkStatus[] = 0;
+    $chkStatus1 = isset($_GET["chkStatus1"]) ? $_GET["chkStatus1"] : 0;
+    if($chkStatus1 > 0)
+        $chkStatus[] = 1;
+    $chkStatus2 = isset($_GET["chkStatus2"]) ? $_GET["chkStatus2"] : 0;
+    if($chkStatus2 > 0)
+        $chkStatus[] = 2;
+
+    if (sizeof($chkStatus))
+    {
+        $members = \App\Models\Member::all();
+        foreach($members as $m)
+        {
+
+            $state = $m->isActive();
+
+            if (in_array($state["status"], $chkStatus))
+                $ids[] = $m->id;
+
+        }
     }
-    if (sizeof($certs) > 0)
+
+    if (sizeof($ids) > 0)
     {
-        $x = $x->whereIn('id', $certs);
+        $x = $x->whereIn('id', $ids);
     }
 
     $count = $x->count();
@@ -167,65 +230,55 @@ Route::get('/get_members', function(){
     else
         $x = $x->get();
 
-    $filterStatus = isset($_GET["status"]) ? $_GET["status"] : -1;
-
     foreach($x as $idx => $r)
     {
+
         $status = $r->getStatus();
         $status = $status["status"];
 
         $state = $r->isActive();
 
-        $procede = true;
-        if ($filterStatus >= 0)
-        {
-            if ($state["status"] != $filterStatus)
-                $procede = false;
-        }
-
-        if ($procede)
-        {
-            $class = $status > 0 ? ($status == 2 ? 'active' : 'suspended') : 'due';
-            $text = $status > 0 ? ($status == 2 ? 'Tesserato' : 'Sospeso') : 'Non tesserato';
+        $class = $status > 0 ? ($status == 2 ? 'active' : 'suspended') : 'due';
+        $text = $status > 0 ? ($status == 2 ? 'Tesserato' : 'Sospeso') : 'Non tesserato';
 
 
-            $x = $state["status"] > 0 ? ($state["status"] == 2 ? 'active' : 'suspended') : '';
-            $x .= "|";
-            $x .= $state["status"] > 0 ? ($state["status"] == 2 ? 'Attivo' : 'Sospesa') : '';
-            $x .= "|";
-            $x .= $state["status"] ? 'Scadenza : ' : ($state["date"] != '' ? 'Scaduto : ' : '');
-            $x .= "|";
-            $x .= $state["date"] != '' ? date("d/m/Y", strtotime($state["date"])) : '';
+        $x = $state["status"] > 0 ? ($state["status"] == 2 ? 'active' : 'suspended') : '';
+        $x .= "|";
+        $x .= $state["status"] > 0 ? ($state["status"] == 2 ? 'Attivo' : 'Sospesa') : '';
+        $x .= "|";
+        $x .= $state["status"] ? 'Scadenza : ' : ($state["date"] != '' ? 'Scaduto : ' : '');
+        $x .= "|";
+        $x .= $state["date"] != '' ? date("d/m/Y", strtotime($state["date"])) : '';
 
-            $has_certificate = $r->hasCertificate();
-            $y = '';
-            if($has_certificate["date"] != '')
-            {
-                if($has_certificate["date"] < date("Y-m-d"))
-                    $y .= '0';
+        $has_certificate = $r->hasCertificate();
+        $y = '';
+        if($has_certificate["date"] != '')
+        {
+            if($has_certificate["date"] < date("Y-m-d"))
+                $y .= '0';
 
-                if($has_certificate["date"] >= date("Y-m-d") && $has_certificate["date"] < date("Y-m-d", strtotime("+1 month")))
-                    $y .= '1';
+            if($has_certificate["date"] >= date("Y-m-d") && $has_certificate["date"] < date("Y-m-d", strtotime("+1 month")))
+                $y .= '1';
 
-                if($has_certificate["date"] >= date("Y-m-d", strtotime("+1 month")))
-                    $y .= '2';
-                $y .= '|';
-                $y .= $has_certificate["date"] != '' ? date("d/m/Y", strtotime($has_certificate["date"])) : '';
-            }
-
-            $datas[] = array(
-                //'c' => $idx + 1,
-                'id' => "ID" . str_pad($r->id, 5, "0", STR_PAD_LEFT),
-                'first_name' => $r->first_name . "|" . $r->id,
-                'last_name' => $r->last_name . "|" . $r->id,
-                'phone' => $r->phone,
-                'age' => $r->getAge(),
-                'status' => $class . "|" . $text,
-                'state' => $x,
-                'certificate' => $y,
-                'action' => $r->id
-            );
+            if($has_certificate["date"] >= date("Y-m-d", strtotime("+1 month")))
+                $y .= '2';
+            $y .= '|';
+            $y .= $has_certificate["date"] != '' ? date("d/m/Y", strtotime($has_certificate["date"])) : '';
         }
+
+        $datas[] = array(
+            //'c' => $idx + 1,
+            'id' => "ID" . str_pad($r->id, 5, "0", STR_PAD_LEFT),
+            'first_name' => $r->first_name . "|" . $r->id,
+            'last_name' => $r->last_name . "|" . $r->id,
+            'phone' => $r->phone,
+            'age' => $r->getAge(),
+            'status' => $class . "|" . $text,
+            'state' => $x,
+            'certificate' => $y,
+            'action' => $r->id
+        );
+    }
         /*
         $r->age = $r->getAge();
         $active = $r->isActive();
@@ -233,7 +286,7 @@ Route::get('/get_members', function(){
         $r->date = $active["date"] . "|" . $r->hasCertificate()["date"];
         $r->state = $r->getStatus()["status"];
         $r->action = '';*/
-    }
+
     /*
     if ($this->sortAsc)
         $this->records = $this->records->sortBy($this->sortField);
@@ -333,7 +386,7 @@ Route::get('/get_record_in', function(){
             'total' => formatPrice($r->getTotal()),
             'first_name' => $r->first_name,
             'last_name' => $r->last_name,
-            'commercial' => $r->commercial ? 'SI' : 'NO',
+            'commercial' => $r->financial_movement ? 'Movimento finanziario' : ($r->commercial ? 'SI' : 'NO'),
             'causals' => $causals,
             'payment' => $r->payment_method->name,
             'status' => $r->deleted ? 'Annullato' : '',