|
@@ -0,0 +1,332 @@
|
|
|
|
|
+<?php
|
|
|
|
|
+
|
|
|
|
|
+namespace App\Http\Livewire;
|
|
|
|
|
+
|
|
|
|
|
+use Livewire\Component;
|
|
|
|
|
+use Livewire\WithFileUploads;
|
|
|
|
|
+use Illuminate\Support\Str;
|
|
|
|
|
+
|
|
|
|
|
+use App\Models\Azienda as AziendaModel;
|
|
|
|
|
+
|
|
|
|
|
+class Azienda extends Component
|
|
|
|
|
+{
|
|
|
|
|
+ use WithFileUploads;
|
|
|
|
|
+
|
|
|
|
|
+ public $update = false;
|
|
|
|
|
+ public $azienda;
|
|
|
|
|
+ public $ragione_sociale;
|
|
|
|
|
+ public $nome_associazione;
|
|
|
|
|
+ public $tipologia;
|
|
|
|
|
+ public $discipline;
|
|
|
|
|
+ public $logo;
|
|
|
|
|
+ public $temp_logo;
|
|
|
|
|
+ public $sede_legale_nazione;
|
|
|
|
|
+ public $sede_legale_provincia;
|
|
|
|
|
+ public $sede_legale_comune;
|
|
|
|
|
+ public $sede_legale_indirizzo;
|
|
|
|
|
+ public $sede_legale_cap;
|
|
|
|
|
+ public $same_address = false;
|
|
|
|
|
+ public $sede_operativa_nazione;
|
|
|
|
|
+ public $sede_operativa_provincia;
|
|
|
|
|
+ public $sede_operativa_comune;
|
|
|
|
|
+ public $sede_operativa_indirizzo;
|
|
|
|
|
+ public $sede_operativa_cap;
|
|
|
|
|
+ public $email;
|
|
|
|
|
+ public $pec;
|
|
|
|
|
+ public $telefono;
|
|
|
|
|
+ public $cellulare;
|
|
|
|
|
+ public $partita_iva;
|
|
|
|
|
+ public $codice_fiscale;
|
|
|
|
|
+ public $codice_sdi;
|
|
|
|
|
+ public $chiusura_anno_fiscale;
|
|
|
|
|
+ public $scadenza_abbonamenti;
|
|
|
|
|
+ public $scadenza_pagamenti_uscita;
|
|
|
|
|
+
|
|
|
|
|
+ public $search = '';
|
|
|
|
|
+ public $selectedDisciplines = [];
|
|
|
|
|
+ public $disciplineId = '';
|
|
|
|
|
+ public $disciplines = [];
|
|
|
|
|
+ public $activeTab = 'generale';
|
|
|
|
|
+
|
|
|
|
|
+ protected $rules = [
|
|
|
|
|
+ 'ragione_sociale' => 'required|string|max:255',
|
|
|
|
|
+ 'email' => 'required|email|max:255',
|
|
|
|
|
+ 'pec' => 'required|email|max:255',
|
|
|
|
|
+ 'cellulare' => 'required|string|max:20',
|
|
|
|
|
+ ];
|
|
|
|
|
+
|
|
|
|
|
+ public function resetFields()
|
|
|
|
|
+ {
|
|
|
|
|
+ $this->ragione_sociale = null;
|
|
|
|
|
+ $this->nome_associazione = null;
|
|
|
|
|
+ $this->tipologia = null;
|
|
|
|
|
+ $this->discipline = null;
|
|
|
|
|
+ $this->temp_logo = null;
|
|
|
|
|
+
|
|
|
|
|
+ $this->sede_legale_nazione = null;
|
|
|
|
|
+ $this->sede_legale_provincia = null;
|
|
|
|
|
+ $this->sede_legale_comune = null;
|
|
|
|
|
+ $this->sede_legale_indirizzo = null;
|
|
|
|
|
+ $this->sede_legale_cap = null;
|
|
|
|
|
+
|
|
|
|
|
+ $this->same_address = false;
|
|
|
|
|
+ $this->sede_operativa_nazione = null;
|
|
|
|
|
+ $this->sede_operativa_provincia = null;
|
|
|
|
|
+ $this->sede_operativa_comune = null;
|
|
|
|
|
+ $this->sede_operativa_indirizzo = null;
|
|
|
|
|
+ $this->sede_operativa_cap = null;
|
|
|
|
|
+
|
|
|
|
|
+ $this->email = null;
|
|
|
|
|
+ $this->pec = null;
|
|
|
|
|
+ $this->telefono = null;
|
|
|
|
|
+ $this->cellulare = null;
|
|
|
|
|
+
|
|
|
|
|
+ $this->partita_iva = null;
|
|
|
|
|
+ $this->codice_fiscale = null;
|
|
|
|
|
+ $this->codice_sdi = null;
|
|
|
|
|
+
|
|
|
|
|
+ $this->chiusura_anno_fiscale = null;
|
|
|
|
|
+ $this->scadenza_abbonamenti = null;
|
|
|
|
|
+ $this->scadenza_pagamenti_uscita = null;
|
|
|
|
|
+ }
|
|
|
|
|
+
|
|
|
|
|
+ public function mount()
|
|
|
|
|
+ {
|
|
|
|
|
+ $this->azienda = AziendaModel::first();
|
|
|
|
|
+
|
|
|
|
|
+ if ($this->azienda) {
|
|
|
|
|
+ $this->ragione_sociale = $this->azienda->ragione_sociale;
|
|
|
|
|
+ $this->nome_associazione = $this->azienda->nome_associazione;
|
|
|
|
|
+ $this->tipologia = $this->azienda->tipologia;
|
|
|
|
|
+ $this->discipline = $this->azienda->discipline;
|
|
|
|
|
+ $this->logo = $this->azienda->logo;
|
|
|
|
|
+
|
|
|
|
|
+ $this->sede_legale_nazione = $this->azienda->sede_legale_nazione;
|
|
|
|
|
+ $this->sede_legale_provincia = $this->azienda->sede_legale_provincia;
|
|
|
|
|
+ $this->sede_legale_comune = $this->azienda->sede_legale_comune;
|
|
|
|
|
+ $this->sede_legale_indirizzo = $this->azienda->sede_legale_indirizzo;
|
|
|
|
|
+ $this->sede_legale_cap = $this->azienda->sede_legale_cap;
|
|
|
|
|
+
|
|
|
|
|
+ $this->sede_operativa_nazione = $this->azienda->sede_operativa_nazione;
|
|
|
|
|
+ $this->sede_operativa_provincia = $this->azienda->sede_operativa_provincia;
|
|
|
|
|
+ $this->sede_operativa_comune = $this->azienda->sede_operativa_comune;
|
|
|
|
|
+ $this->sede_operativa_indirizzo = $this->azienda->sede_operativa_indirizzo;
|
|
|
|
|
+ $this->sede_operativa_cap = $this->azienda->sede_operativa_cap;
|
|
|
|
|
+
|
|
|
|
|
+ $this->email = $this->azienda->email;
|
|
|
|
|
+ $this->pec = $this->azienda->pec;
|
|
|
|
|
+ $this->telefono = $this->azienda->telefono;
|
|
|
|
|
+ $this->cellulare = $this->azienda->cellulare;
|
|
|
|
|
+
|
|
|
|
|
+ $this->partita_iva = $this->azienda->partita_iva;
|
|
|
|
|
+ $this->codice_fiscale = $this->azienda->codice_fiscale;
|
|
|
|
|
+ $this->codice_sdi = $this->azienda->codice_sdi;
|
|
|
|
|
+
|
|
|
|
|
+ $this->chiusura_anno_fiscale = $this->azienda->chiusura_anno_fiscale;
|
|
|
|
|
+ $this->scadenza_abbonamenti = $this->azienda->scadenza_abbonamenti;
|
|
|
|
|
+ $this->scadenza_pagamenti_uscita = $this->azienda->scadenza_pagamenti_uscita;
|
|
|
|
|
+
|
|
|
|
|
+ if (
|
|
|
|
|
+ $this->sede_legale_nazione == $this->sede_operativa_nazione &&
|
|
|
|
|
+ $this->sede_legale_provincia == $this->sede_operativa_provincia &&
|
|
|
|
|
+ $this->sede_legale_comune == $this->sede_operativa_comune &&
|
|
|
|
|
+ $this->sede_legale_indirizzo == $this->sede_operativa_indirizzo &&
|
|
|
|
|
+ $this->sede_legale_cap == $this->sede_operativa_cap
|
|
|
|
|
+ ) {
|
|
|
|
|
+ $this->same_address = true;
|
|
|
|
|
+ }
|
|
|
|
|
+
|
|
|
|
|
+ if ($this->azienda && $this->azienda->disciplines) {
|
|
|
|
|
+ $this->selectedDisciplines = array_map('trim', explode(';', $this->azienda->disciplines));
|
|
|
|
|
+ }
|
|
|
|
|
+ } else {
|
|
|
|
|
+ $this->update = true;
|
|
|
|
|
+ $this->resetFields();
|
|
|
|
|
+ }
|
|
|
|
|
+ $this->loadDisciplines();
|
|
|
|
|
+ }
|
|
|
|
|
+
|
|
|
|
|
+ public function render()
|
|
|
|
|
+ {
|
|
|
|
|
+ return view('livewire.azienda');
|
|
|
|
|
+ }
|
|
|
|
|
+
|
|
|
|
|
+ public function updatedSameAddress()
|
|
|
|
|
+ {
|
|
|
|
|
+ if ($this->same_address) {
|
|
|
|
|
+ $this->sede_operativa_nazione = $this->sede_legale_nazione;
|
|
|
|
|
+ $this->sede_operativa_provincia = $this->sede_legale_provincia;
|
|
|
|
|
+ $this->sede_operativa_comune = $this->sede_legale_comune;
|
|
|
|
|
+ $this->sede_operativa_indirizzo = $this->sede_legale_indirizzo;
|
|
|
|
|
+ $this->sede_operativa_cap = $this->sede_legale_cap;
|
|
|
|
|
+ } else {
|
|
|
|
|
+ $this->sede_operativa_nazione = null;
|
|
|
|
|
+ $this->sede_operativa_provincia = null;
|
|
|
|
|
+ $this->sede_operativa_comune = null;
|
|
|
|
|
+ $this->sede_operativa_indirizzo = null;
|
|
|
|
|
+ $this->sede_operativa_cap = null;
|
|
|
|
|
+ }
|
|
|
|
|
+ }
|
|
|
|
|
+
|
|
|
|
|
+ public function updatedSedeOperativaNazione()
|
|
|
|
|
+ {
|
|
|
|
|
+ $this->checkAddressDifference();
|
|
|
|
|
+ }
|
|
|
|
|
+
|
|
|
|
|
+ public function updatedSedeOperativaProvincia()
|
|
|
|
|
+ {
|
|
|
|
|
+ $this->checkAddressDifference();
|
|
|
|
|
+ }
|
|
|
|
|
+
|
|
|
|
|
+ public function updatedSedeOperativaComune()
|
|
|
|
|
+ {
|
|
|
|
|
+ $this->checkAddressDifference();
|
|
|
|
|
+ }
|
|
|
|
|
+
|
|
|
|
|
+ public function updatedSedeOperativaIndirizzo()
|
|
|
|
|
+ {
|
|
|
|
|
+ $this->checkAddressDifference();
|
|
|
|
|
+ }
|
|
|
|
|
+
|
|
|
|
|
+ public function updatedSedeOperativaCap()
|
|
|
|
|
+ {
|
|
|
|
|
+ $this->checkAddressDifference();
|
|
|
|
|
+ }
|
|
|
|
|
+
|
|
|
|
|
+ public function checkAddressDifference()
|
|
|
|
|
+ {
|
|
|
|
|
+ if (
|
|
|
|
|
+ $this->sede_legale_nazione == $this->sede_operativa_nazione &&
|
|
|
|
|
+ $this->sede_legale_provincia == $this->sede_operativa_provincia &&
|
|
|
|
|
+ $this->sede_legale_comune == $this->sede_operativa_comune &&
|
|
|
|
|
+ $this->sede_legale_indirizzo == $this->sede_operativa_indirizzo &&
|
|
|
|
|
+ $this->sede_legale_cap == $this->sede_operativa_cap
|
|
|
|
|
+ ) {
|
|
|
|
|
+ $this->same_address = true;
|
|
|
|
|
+ } else {
|
|
|
|
|
+ $this->same_address = false;
|
|
|
|
|
+ }
|
|
|
|
|
+ }
|
|
|
|
|
+
|
|
|
|
|
+ public function setTab($tab)
|
|
|
|
|
+ {
|
|
|
|
|
+ $this->activeTab = $tab;
|
|
|
|
|
+ }
|
|
|
|
|
+
|
|
|
|
|
+ public function edit()
|
|
|
|
|
+ {
|
|
|
|
|
+ $this->update = true;
|
|
|
|
|
+ }
|
|
|
|
|
+
|
|
|
|
|
+ public function save()
|
|
|
|
|
+ {
|
|
|
|
|
+ $this->validate();
|
|
|
|
|
+
|
|
|
|
|
+ try {
|
|
|
|
|
+ $data = [
|
|
|
|
|
+ 'ragione_sociale' => $this->ragione_sociale,
|
|
|
|
|
+ 'nome_associazione' => $this->nome_associazione,
|
|
|
|
|
+ 'tipologia' => $this->tipologia,
|
|
|
|
|
+ 'disciplines' => implode('; ', $this->selectedDisciplines),
|
|
|
|
|
+
|
|
|
|
|
+ 'sede_legale_nazione' => $this->sede_legale_nazione,
|
|
|
|
|
+ 'sede_legale_provincia' => $this->sede_legale_provincia,
|
|
|
|
|
+ 'sede_legale_comune' => $this->sede_legale_comune,
|
|
|
|
|
+ 'sede_legale_indirizzo' => $this->sede_legale_indirizzo,
|
|
|
|
|
+ 'sede_legale_cap' => $this->sede_legale_cap,
|
|
|
|
|
+
|
|
|
|
|
+ 'sede_operativa_nazione' => $this->sede_operativa_nazione,
|
|
|
|
|
+ 'sede_operativa_provincia' => $this->sede_operativa_provincia,
|
|
|
|
|
+ 'sede_operativa_comune' => $this->sede_operativa_comune,
|
|
|
|
|
+ 'sede_operativa_indirizzo' => $this->sede_operativa_indirizzo,
|
|
|
|
|
+ 'sede_operativa_cap' => $this->sede_operativa_cap,
|
|
|
|
|
+
|
|
|
|
|
+ 'email' => $this->email,
|
|
|
|
|
+ 'pec' => $this->pec,
|
|
|
|
|
+ 'telefono' => $this->telefono,
|
|
|
|
|
+ 'cellulare' => $this->cellulare,
|
|
|
|
|
+
|
|
|
|
|
+ 'partita_iva' => $this->partita_iva,
|
|
|
|
|
+ 'codice_fiscale' => $this->codice_fiscale,
|
|
|
|
|
+ 'codice_sdi' => $this->codice_sdi,
|
|
|
|
|
+
|
|
|
|
|
+ 'chiusura_anno_fiscale' => $this->chiusura_anno_fiscale,
|
|
|
|
|
+ 'scadenza_abbonamenti' => $this->scadenza_abbonamenti,
|
|
|
|
|
+ 'scadenza_pagamenti_uscita' => $this->scadenza_pagamenti_uscita,
|
|
|
|
|
+ ];
|
|
|
|
|
+
|
|
|
|
|
+ if ($this->temp_logo) {
|
|
|
|
|
+ $folderName = Str::slug($this->nome_associazione);
|
|
|
|
|
+
|
|
|
|
|
+ $path = 'img/' . $folderName;
|
|
|
|
|
+ $fullPath = storage_path('app/public/' . $path);
|
|
|
|
|
+
|
|
|
|
|
+ if (!file_exists($fullPath)) {
|
|
|
|
|
+ mkdir($fullPath, 0755, true);
|
|
|
|
|
+ }
|
|
|
|
|
+
|
|
|
|
|
+ $logoPath = $this->temp_logo->store($path, 'public');
|
|
|
|
|
+ $data['logo'] = $logoPath;
|
|
|
|
|
+ }
|
|
|
|
|
+ if ($this->azienda) {
|
|
|
|
|
+ $this->azienda->update($data);
|
|
|
|
|
+ session()->flash('message', 'Dati aziendali aggiornati con successo!');
|
|
|
|
|
+ } else {
|
|
|
|
|
+ $this->azienda = AziendaModel::create($data);
|
|
|
|
|
+ session()->flash('message', 'Dati aziendali creati con successo!');
|
|
|
|
|
+ }
|
|
|
|
|
+
|
|
|
|
|
+ $this->update = false;
|
|
|
|
|
+ } catch (\Exception $ex) {
|
|
|
|
|
+ session()->flash('error', 'Errore: ' . $ex->getMessage());
|
|
|
|
|
+ }
|
|
|
|
|
+ }
|
|
|
|
|
+
|
|
|
|
|
+ public function getSelectedDisciplineNamesProperty()
|
|
|
|
|
+ {
|
|
|
|
|
+ if (empty($this->selectedDisciplines)) {
|
|
|
|
|
+ return [];
|
|
|
|
|
+ }
|
|
|
|
|
+
|
|
|
|
|
+ return \App\Models\Discipline::whereIn('id', $this->selectedDisciplines)
|
|
|
|
|
+ ->pluck('name')
|
|
|
|
|
+ ->toArray();
|
|
|
|
|
+ }
|
|
|
|
|
+
|
|
|
|
|
+ public function cancel()
|
|
|
|
|
+ {
|
|
|
|
|
+ $this->resetFields();
|
|
|
|
|
+ $this->mount();
|
|
|
|
|
+ $this->update = false;
|
|
|
|
|
+ }
|
|
|
|
|
+
|
|
|
|
|
+ public function loadDisciplines()
|
|
|
|
|
+ {
|
|
|
|
|
+ $this->disciplines = \App\Models\Discipline::select('id', 'name')->get();
|
|
|
|
|
+ }
|
|
|
|
|
+
|
|
|
|
|
+ public function addDiscipline()
|
|
|
|
|
+ {
|
|
|
|
|
+ if (!empty($this->disciplineId)) {
|
|
|
|
|
+ $discipline = \App\Models\Discipline::find($this->disciplineId);
|
|
|
|
|
+
|
|
|
|
|
+ if ($discipline && !in_array($discipline->name, $this->selectedDisciplines)) {
|
|
|
|
|
+ $this->selectedDisciplines[] = $discipline->name;
|
|
|
|
|
+ $this->disciplineId = '';
|
|
|
|
|
+ }
|
|
|
|
|
+ }
|
|
|
|
|
+ }
|
|
|
|
|
+
|
|
|
|
|
+ public function removeDiscipline($index)
|
|
|
|
|
+ {
|
|
|
|
|
+ if (isset($this->selectedDisciplines[$index])) {
|
|
|
|
|
+ unset($this->selectedDisciplines[$index]);
|
|
|
|
|
+ $this->selectedDisciplines = array_values($this->selectedDisciplines);
|
|
|
|
|
+ }
|
|
|
|
|
+ }
|
|
|
|
|
+
|
|
|
|
|
+ public function updatedSearch()
|
|
|
|
|
+ {
|
|
|
|
|
+ $this->loadDisciplines();
|
|
|
|
|
+ }
|
|
|
|
|
+}
|