|
|
@@ -0,0 +1,550 @@
|
|
|
+<?php
|
|
|
+
|
|
|
+namespace App\Http\Livewire;
|
|
|
+
|
|
|
+use App\Helpers\DateHelper;
|
|
|
+use App\Models\Anagrafica;
|
|
|
+use App\Models\ReportDataPedoni;
|
|
|
+use Illuminate\Support\Facades\Log;
|
|
|
+use Livewire\Component;
|
|
|
+use PhpOffice\PhpSpreadsheet\Spreadsheet;
|
|
|
+use PhpOffice\PhpSpreadsheet\Writer\Xlsx;
|
|
|
+
|
|
|
+class Prefettura extends Component
|
|
|
+{
|
|
|
+
|
|
|
+ const LOCALIZZAZIONE_INCIDENTE_IN = 1;
|
|
|
+ const LOCALIZZAZIONE_INCIDENTE_OUT = 2;
|
|
|
+
|
|
|
+ const VISIBILITA_BUONA = 1;
|
|
|
+ const VISIBILITA_LIMITATA = 2;
|
|
|
+
|
|
|
+ const FONDO_STRADALE_SPECIFICA_OPTION_VALUE = 5;
|
|
|
+ const PARTICOLARITA_STRADA_SPECIFICA_OPTION_VALUE = 5;
|
|
|
+
|
|
|
+ const TRAFFICO_NORMALE = 1;
|
|
|
+ const TRAFFICO_SCARSO = 2;
|
|
|
+ const TRAFFICO_INTENSO = 3;
|
|
|
+
|
|
|
+ const TIPO_STRADA_ALTRO_OPTION_VALUE = 8;
|
|
|
+
|
|
|
+ const SEGNALETICA_ASSENTE = 1;
|
|
|
+ const SEGNALETICA_VERTICALE = 2;
|
|
|
+ const SEGNALETICA_ORIZZONTALE = 3;
|
|
|
+ const SEGNALETICA_VERTICALE_ORIZZONTALE = 4;
|
|
|
+ const SEGNALETICA_TEMPORANEA_CANTIERE = 5;
|
|
|
+
|
|
|
+ const SEGNALETICA_VERTICALE_LIMITE_VELOCITA_OPTION_VALUE = 21;
|
|
|
+ const SEGNALETICA_VERTICALE_PANNELLO_INTEGRATIVO_OPTION_VALUE = 22;
|
|
|
+ const SEGNALETICA_VERTICALE_ALTRO_OPTION_VALUE = 23;
|
|
|
+
|
|
|
+
|
|
|
+ const LINEA_CONTINUA = 1;
|
|
|
+ const LINEA_TRATTEGGIATA = 2;
|
|
|
+ const LINEA_TRATTEGGIATA_IN_CORRISPONDENZA = 3;
|
|
|
+ const SEGNALETICA_ORIZZONTALE_LINEA_ASSENTE = 4;
|
|
|
+
|
|
|
+ const MAX_PARTI_COINVOLTE = 10;
|
|
|
+ const MAX_VEHICLES = 4;
|
|
|
+ const MAX_PASSEGGERI = 4;
|
|
|
+ const MAX_INFORTUNATI = 4;
|
|
|
+ const MAX_PEDONI = 4;
|
|
|
+ const MAX_TESTI_OCULARI = 4;
|
|
|
+
|
|
|
+ const STATO_VEICOLO_MARCIA = 1;
|
|
|
+ const STATO_VEICOLO_SOSTA = 2;
|
|
|
+ const STATO_VEICOLO_NON_PRESENTE = 3;
|
|
|
+
|
|
|
+ const POSIZIONE_STATICA_FINALE_DOCUMENTAZIONE_FOTOGRAFICA = 1;
|
|
|
+ const POSIZIONE_STATICA_FINALE_RILIEVO_PLANIMETRICO = 2;
|
|
|
+ const POSIZIONE_STATICA_FINALE_SCHIZZO_VISTA_NO_SCALA = 3;
|
|
|
+ const POSIZIONE_STATICA_FINALE_GIA_RIMOSSO = 4;
|
|
|
+
|
|
|
+ const DESTINAZIONE_VEICOLO_RIMOSSO_SENSI_ART_2028_CC = 1;
|
|
|
+ const DESTINAZIONE_VEICOLO_SEQUESTRO_ART_354_CPP = 2;
|
|
|
+ const DESTINAZIONE_VEICOLO_SEQUESTRO_ART_321_CPP = 3;
|
|
|
+ const DESTINAZIONE_VEICOLO_SEQUESTRO = 4;
|
|
|
+ const DESTINAZIONE_VEICOLO_SEQUESTRO_AMMINISTRATIVO = 5;
|
|
|
+ const DESTINAZIONE_VEICOLO_FERMO_AMMINISTRATIVO = 6;
|
|
|
+ const DESTINAZIONE_VEICOLO_RITIRATO_DAL_CONDUCENTE = 7;
|
|
|
+
|
|
|
+ const STATO_PNEUMATICI_REGOLAMENTARE = 1;
|
|
|
+ const STATO_PNEUMATICI_BUONO = 2;
|
|
|
+ const STATO_PNEUMATICI_SUFFICIENTE = 3;
|
|
|
+ const STATO_PNEUMATICI_INSUFFICIENTE = 4;
|
|
|
+ const STATO_PNEUMATICI_NON_RILEVATO = 5;
|
|
|
+
|
|
|
+ const STATO_PRESENTE = 1;
|
|
|
+ const STATO_NON_PRESENTE = 2;
|
|
|
+ const STATO_FUNZIONANTE = 1;
|
|
|
+ const STATO_NON_FUNZIONANTE = 2;
|
|
|
+ const STATO_NON_RILEVATO = 3;
|
|
|
+
|
|
|
+ const YES = 1;
|
|
|
+ const NO = 0;
|
|
|
+
|
|
|
+ const SI_RISERVA = 3;
|
|
|
+
|
|
|
+ const PATENTE_AL_SEGUITO_NON_PREVISTA = 3;
|
|
|
+
|
|
|
+ const CONDUCENTE_GENERALIZZATO_LUOGO = 1;
|
|
|
+ const CONDUCENTE_GENERALIZZATO_OSPEDALE = 2;
|
|
|
+ const CONDUCENTE_GENERALIZZATO_ALTRO = 3;
|
|
|
+
|
|
|
+ const INFORTUNATO_INCOLUME = 0;
|
|
|
+ const INFORTUNATO_FERITO = 1;
|
|
|
+ const INFORTUNATO_DECEDUTO_24H = 2;
|
|
|
+ const INFORTUNATO_DECEDUTO_30GG = 3;
|
|
|
+
|
|
|
+ const MARCIA_OPTION_N = 0;
|
|
|
+ const MARCIA_OPTION_1 = 1;
|
|
|
+ const MARCIA_OPTION_2 = 2;
|
|
|
+ const MARCIA_OPTION_3 = 3;
|
|
|
+ const MARCIA_OPTION_4 = 4;
|
|
|
+ const MARCIA_OPTION_5 = 5;
|
|
|
+ const MARCIA_OPTION_6 = 6;
|
|
|
+ const MARCIA_OPTION_R = 7;
|
|
|
+ const MARCIA_NON_RILEVATA = 8;
|
|
|
+ const MARCIA_OPTION_AUTO = 9;
|
|
|
+
|
|
|
+ const CRISTALLO_OPTION_INTERNO = 1;
|
|
|
+ const CRISTALLO_OPTION_ESTERNO = 2;
|
|
|
+ const CRISTALLO_OPTION_ALTRO = 3;
|
|
|
+
|
|
|
+ const ESITO_NEGATIVO = 1;
|
|
|
+ const ESITO_POSITIVO = 2;
|
|
|
+
|
|
|
+ const DOCUMENTO_CI = 1;
|
|
|
+ const DOCUMENTO_PAT = 2;
|
|
|
+ const DOCUMENTO_PP = 3;
|
|
|
+ const DOCUMENTO_ALTRO = 4;
|
|
|
+
|
|
|
+ const PEDONE_PRESENTE_E_POSIZIONE = 1;
|
|
|
+ const PEDONE_SOCCORSO_E_PRESSO = 2;
|
|
|
+
|
|
|
+ const TESTE_PRESENTE_MOMENTO_RILIEVO = 1;
|
|
|
+ const TESTE_NON_PRESENTE_MOMENTO_RILIEVO = 2;
|
|
|
+ const TESTE_DICHIARA_LUOGO_INCIDENTE = 3;
|
|
|
+ const TESTE_DICHIARA_PRONTO_SOCCORSO = 4;
|
|
|
+ const TESTE_DICHIARA_PROSEGUO_TEMPO = 5;
|
|
|
+
|
|
|
+ const PATENTE_CATEGORIA_AM = 'AM';
|
|
|
+ const PATENTE_CATEGORIA_A1 = 'A1';
|
|
|
+ const PATENTE_CATEGORIA_A1B = 'A1B';
|
|
|
+ const PATENTE_CATEGORIA_A2 = 'A2';
|
|
|
+ const PATENTE_CATEGORIA_A = 'A';
|
|
|
+ const PATENTE_CATEGORIA_AB = 'AB';
|
|
|
+ const PATENTE_CATEGORIA_B1 = 'B1';
|
|
|
+ const PATENTE_CATEGORIA_B = 'B';
|
|
|
+ const PATENTE_CATEGORIA_BE = 'BE';
|
|
|
+ const PATENTE_CATEGORIA_C1 = 'C1';
|
|
|
+ const PATENTE_CATEGORIA_C1E = 'C1E';
|
|
|
+ const PATENTE_CATEGORIA_C = 'C';
|
|
|
+ const PATENTE_CATEGORIA_CE = 'CE';
|
|
|
+ const PATENTE_CATEGORIA_D1 = 'D1';
|
|
|
+ const PATENTE_CATEGORIA_D1E = 'D1E';
|
|
|
+ const PATENTE_CATEGORIA_DE = 'DE';
|
|
|
+ const PATENTE_CATEGORIA_E = 'E';
|
|
|
+
|
|
|
+ const PATENTE_ABILITAZIONI_CQC = 1;
|
|
|
+ const PATENTE_ABILITAZIONI_CAP = 2;
|
|
|
+ const PATENTE_ABILITAZIONI_CFC = 3;
|
|
|
+
|
|
|
+ const DOCUMENTO_RILASCIATO_COMUNE = 1;
|
|
|
+ const DOCUMENTO_RILASCIATO_MOTORIZZAZIONE_CIVILE = 2;
|
|
|
+ const DOCUMENTO_RILASCIATO_ALTRO = 3;
|
|
|
+ const DOCUMENTO_RILASCIATO_MCTC = 4;
|
|
|
+ const DOCUMENTO_RILASCIATO_MIT = 5;
|
|
|
+ const DOCUMENTO_RILASCIATO_UCO = 6;
|
|
|
+ const DOCUMENTO_RILASCIATO_PREFETTURA = 7;
|
|
|
+
|
|
|
+ const PATENTE_PRESCRIZIONI_OBBLIGO_LENTI = 1;
|
|
|
+ const PATENTE_PRESCRIZIONI_APPARECCHIO_ACUSTICO = 2;
|
|
|
+ const PATENTE_PRESCRIZIONI_LIMITAZIONI_ART_117 = 3;
|
|
|
+
|
|
|
+ const PROTOCOLLO_NUM_LENGTH = 3;
|
|
|
+
|
|
|
+ protected $paginationTheme = 'bootstrap';
|
|
|
+
|
|
|
+ public $title = 'Prefettura';
|
|
|
+
|
|
|
+ public $from, $to;
|
|
|
+
|
|
|
+ public function mount()
|
|
|
+ {
|
|
|
+ // Initialize $from with today's date in Y-m-d format
|
|
|
+ $this->from = now()->format('Y-m-d');
|
|
|
+ }
|
|
|
+
|
|
|
+ protected $rules = [
|
|
|
+ 'from' => 'required',
|
|
|
+ 'to' => 'required',
|
|
|
+ ];
|
|
|
+
|
|
|
+ protected $messages = [
|
|
|
+ 'from.required' => 'La data inizio è obbligatoria',
|
|
|
+ 'to.required' => 'La data fine è obbligatoria',
|
|
|
+ ];
|
|
|
+
|
|
|
+ public function resetFields()
|
|
|
+ {
|
|
|
+ $this->from = '';
|
|
|
+ $this->to = '';
|
|
|
+ }
|
|
|
+
|
|
|
+ public function render()
|
|
|
+ {
|
|
|
+ return view('livewire.prefettura');
|
|
|
+ }
|
|
|
+
|
|
|
+ public function export()
|
|
|
+ {
|
|
|
+ Log::info('Export file prefettura');
|
|
|
+ Log::info('From: ' . $this->from);
|
|
|
+ Log::info('To: ' . $this->to);
|
|
|
+ try {
|
|
|
+ $items = \DB::table('fcf_reports_reports')
|
|
|
+ ->leftjoin('fcf_users', 'fcf_reports_reports.created_by', '=', 'fcf_users.id')
|
|
|
+ ->selectRaw('fcf_reports_reports.*, CONCAT(fcf_users.firstname," ",fcf_users.lastname) AS display_name')
|
|
|
+ ->where(function ($query) {
|
|
|
+ $query->where('fcf_reports_reports.incidente_con_feriti', '1')
|
|
|
+ ->orWhere('fcf_reports_reports.incidente_mortale', '=', '1');
|
|
|
+ })
|
|
|
+ ->where('fcf_reports_reports.verificatosi_in_data', '>=', $this->from != '' ? $this->from : '2000-01-01')
|
|
|
+ ->where('fcf_reports_reports.verificatosi_in_data', '<=', $this->to != '' ? $this->to : '2050-01-01')
|
|
|
+ ->orderBy('fcf_reports_reports.verificatosi_in_data')
|
|
|
+ ->get();
|
|
|
+
|
|
|
+ Log::info('Items: ' . count($items));
|
|
|
+
|
|
|
+ $spreadsheet = new Spreadsheet();
|
|
|
+ $activeWorksheet = $spreadsheet->getActiveSheet();
|
|
|
+
|
|
|
+ $activeWorksheet->setCellValue('A1', "IDIncidenti");
|
|
|
+ $activeWorksheet->setCellValue('B1', "Data");
|
|
|
+ $activeWorksheet->setCellValue('C1', "Ora");
|
|
|
+ $activeWorksheet->setCellValue('D1', "IDProv");
|
|
|
+ $activeWorksheet->setCellValue('E1', "IDCom");
|
|
|
+ $activeWorksheet->setCellValue('F1', "IDTipoIncidente");
|
|
|
+ $activeWorksheet->setCellValue('G1', "IDTipoStrada");
|
|
|
+ $activeWorksheet->setCellValue('H1', "CentroAbitato");
|
|
|
+ $activeWorksheet->setCellValue('I1', "IDPolizia");
|
|
|
+ $activeWorksheet->setCellValue('J1', "IDCaratteristiche");
|
|
|
+ $activeWorksheet->setCellValue('K1', "CantiereStradale");
|
|
|
+ $activeWorksheet->setCellValue('L1', "N_Autovettura");
|
|
|
+ $activeWorksheet->setCellValue('M1', "N_Autocarro fino 3,5t");
|
|
|
+ $activeWorksheet->setCellValue('N1', "N_Autocarro > 3,5t");
|
|
|
+ $activeWorksheet->setCellValue('O1', "N_Autotreno");
|
|
|
+ $activeWorksheet->setCellValue('P1', "N_Autoarticolato");
|
|
|
+ $activeWorksheet->setCellValue('Q1', "N_Autobus");
|
|
|
+ $activeWorksheet->setCellValue('R1', "N_Tram");
|
|
|
+ $activeWorksheet->setCellValue('S1', "N_Treno");
|
|
|
+ $activeWorksheet->setCellValue('T1', "N_Motociclo");
|
|
|
+ $activeWorksheet->setCellValue('U1', "N_Ciclomotore");
|
|
|
+ $activeWorksheet->setCellValue('V1', "N_Velocipede");
|
|
|
+ $activeWorksheet->setCellValue('W1', "N_Bicicletta a pedala assistita");
|
|
|
+ $activeWorksheet->setCellValue('X1', "N_Monopattini elettrici");
|
|
|
+ $activeWorksheet->setCellValue('Y1', "N_Altri dispositivi micromobilita'");
|
|
|
+ $activeWorksheet->setCellValue('Z1', "N_AltrIVeicoli");
|
|
|
+ $activeWorksheet->setCellValue('AA1', "Trasportanti merci pericolose");
|
|
|
+ $activeWorksheet->setCellValue('AB1', "N_Pedoni");
|
|
|
+ $activeWorksheet->setCellValue('AC1', "N_Deceduti");
|
|
|
+ $activeWorksheet->setCellValue('AD1', "N_Feriti");
|
|
|
+ $activeWorksheet->setCellValue('AE1', "Numero Nome Strada");
|
|
|
+ $activeWorksheet->setCellValue('AF1', "KM");
|
|
|
+ $activeWorksheet->setCellValue('AG1', "Metri");
|
|
|
+ $activeWorksheet->setCellValue('AH1', "Carreggiata");
|
|
|
+ $activeWorksheet->setCellValue('AI1', "Omissione");
|
|
|
+ $activeWorksheet->setCellValue('AJ1', "Contromano");
|
|
|
+ $activeWorksheet->setCellValue('AK1', "DettaglioPersone");
|
|
|
+ $activeWorksheet->setCellValue('AL1', "idPositivita");
|
|
|
+ $activeWorksheet->setCellValue('AM1', "ArtCds");
|
|
|
+ $activeWorksheet->setCellValue('AN1', "Coordinata X");
|
|
|
+ $activeWorksheet->setCellValue('AO1', "Coordinata Y");
|
|
|
+
|
|
|
+
|
|
|
+ $activeWorksheet->getStyle('A1:AO1')->getFont()->setBold(true);
|
|
|
+
|
|
|
+ // Character counting variables
|
|
|
+ $charCounts = [];
|
|
|
+ $sectionCounts = [];
|
|
|
+ $idx = 2;
|
|
|
+ foreach ($items as $item) {
|
|
|
+
|
|
|
+ try {
|
|
|
+ Log::info('Item: ' . $item->id);
|
|
|
+ $report = \App\Models\Report::findOrFail($item->id);
|
|
|
+
|
|
|
+ //$activeWorksheet->setCellValue('A' . $idx, str_pad($report->protocollo_num, 3, '0', STR_PAD_LEFT) . "/" . date('Y', strtotime($item->verificatosi_in_data)));
|
|
|
+ $activeWorksheet->setCellValue('A' . $idx, $item->id);
|
|
|
+ $activeWorksheet->setCellValue('B' . $idx, date('d/m/Y', strtotime($item->verificatosi_in_data)));
|
|
|
+ $activeWorksheet->setCellValue('C' . $idx, $item->verificatosi_in_data_ora . ":" . $item->verificatosi_in_data_minuti);
|
|
|
+ $town_code = $prov_code = '000';
|
|
|
+ $town = \App\Models\LocationTown::findOrFail($item->localita_uno);
|
|
|
+ if ($town) {
|
|
|
+ if ($town->istat_code) $town_code = $town->istat_code;
|
|
|
+ $prov = \App\Models\LocationProvince::where('code', $town->prov)->first();
|
|
|
+ if ($prov && $prov->istat_code) $prov_code = $prov->istat_code;
|
|
|
+ }
|
|
|
+ $activeWorksheet->setCellValue('D' . $idx, $prov_code);
|
|
|
+ $activeWorksheet->setCellValue('E' . $idx, $town_code);
|
|
|
+ $activeWorksheet->setCellValue('F' . $idx, "???");
|
|
|
+ $tipo_strada = ' ';
|
|
|
+ $types_saved = \App\Models\ReportTipoStrada::where('report_id', $report->id)
|
|
|
+ ->pluck('tipo_strada_id')
|
|
|
+ ->toArray();
|
|
|
+
|
|
|
+ if (!empty($types_saved)) {
|
|
|
+ if (in_array(3, $types_saved) && in_array(1, $types_saved))
|
|
|
+ $tipo_strada = 1;
|
|
|
+ elseif (in_array(3, $types_saved) && (in_array(11, $types_saved) || in_array(2, $types_saved)))
|
|
|
+ $tipo_strada = 2;
|
|
|
+ elseif (in_array(4, $types_saved))
|
|
|
+ $tipo_strada = 3;
|
|
|
+ }
|
|
|
+ $activeWorksheet->setCellValue('G' . $idx, $tipo_strada);
|
|
|
+
|
|
|
+ if ($report->localizzazione_incidente == Prefettura::LOCALIZZAZIONE_INCIDENTE_IN) {
|
|
|
+ switch ($report->nomenclatura_strada) {
|
|
|
+ case 2:
|
|
|
+ $loc = 2;
|
|
|
+ break;
|
|
|
+ case 3:
|
|
|
+ $loc = 0;
|
|
|
+ break;
|
|
|
+ case 4:
|
|
|
+ $loc = 3;
|
|
|
+ break;
|
|
|
+ default:
|
|
|
+ $loc = 1;
|
|
|
+ }
|
|
|
+ } elseif ($report->localizzazione_incidente == Prefettura::LOCALIZZAZIONE_INCIDENTE_OUT) {
|
|
|
+ switch ($report->nomenclatura_strada) {
|
|
|
+ case 2:
|
|
|
+ $loc = 5;
|
|
|
+ break;
|
|
|
+ case 3:
|
|
|
+ $loc = 9;
|
|
|
+ break;
|
|
|
+ case 4:
|
|
|
+ $loc = 6;
|
|
|
+ break;
|
|
|
+ default:
|
|
|
+ $loc = 4;
|
|
|
+ }
|
|
|
+ } else $loc = ' ';
|
|
|
+
|
|
|
+ $activeWorksheet->setCellValue('H' . $idx, $loc);
|
|
|
+
|
|
|
+ $int = ' ';
|
|
|
+ switch ($report->particolarita_strada) {
|
|
|
+ case 1:
|
|
|
+ $int = '07';
|
|
|
+ break;
|
|
|
+ case 2:
|
|
|
+ $int = '01';
|
|
|
+ break;
|
|
|
+ case 3:
|
|
|
+ $int = '08';
|
|
|
+ break;
|
|
|
+ case 4:
|
|
|
+ $int = '02';
|
|
|
+ break;
|
|
|
+ case 5:
|
|
|
+ $int = '10';
|
|
|
+ break;
|
|
|
+ case 6:
|
|
|
+ case 10:
|
|
|
+ $int = '09';
|
|
|
+ break;
|
|
|
+ case 7:
|
|
|
+ $int = '06';
|
|
|
+ break;
|
|
|
+ case 12:
|
|
|
+ $int = '04';
|
|
|
+ break;
|
|
|
+ }
|
|
|
+
|
|
|
+ $activeWorksheet->setCellValue('I' . $idx, $int);
|
|
|
+ $activeWorksheet->setCellValue('J' . $idx, $report->condizione_strada == 2 ? "S" : "N");
|
|
|
+ $activeWorksheet->setCellValue('K' . $idx, "N");
|
|
|
+
|
|
|
+ $deceduti = 0;
|
|
|
+ $feriti = 0;
|
|
|
+ $pedoni = 0;
|
|
|
+
|
|
|
+ $autovetture = 0;
|
|
|
+ $autotreno = 0;
|
|
|
+ $autoarticolato = 0;
|
|
|
+ $autobus = 0;
|
|
|
+ $tram = 0;
|
|
|
+ $treno = 0;
|
|
|
+ $motociclo = 0;
|
|
|
+ $ciclomotore = 0;
|
|
|
+ $velocipede = 0;
|
|
|
+ $bicicletta = 0;
|
|
|
+ $monopattino = 0;
|
|
|
+ $altri_micro = 0;
|
|
|
+ $altri = 0;
|
|
|
+
|
|
|
+ $data_veicoli = \App\Models\ReportDataVeicoli::where('report_id', $report->id)->get()->toArray();
|
|
|
+
|
|
|
+ for ($i = 0; $i < 3; $i++) {
|
|
|
+ $data_veicolo = isset($data_veicoli[$i]) ? $data_veicoli[$i] : false;
|
|
|
+ if ($data_veicolo)
|
|
|
+ {
|
|
|
+ if ($data_veicolo["veicoli"] > 0)
|
|
|
+ {
|
|
|
+ $veicolo = \App\Models\Vehicle::findOrFail($data_veicolo["veicoli"]);
|
|
|
+ switch ($veicolo->tipo_id) {
|
|
|
+ case \App\Models\Vehicle::AUTOVETTURA:
|
|
|
+ $autovetture += 1;
|
|
|
+ break;
|
|
|
+ case \App\Models\Vehicle::CICLO_MOTORE:
|
|
|
+ $ciclomotore += 1;
|
|
|
+ break;
|
|
|
+ case \App\Models\Vehicle::QUADRICICLO:
|
|
|
+ $altri += 1;
|
|
|
+ break;
|
|
|
+ case \App\Models\Vehicle::MOTOCICLO:
|
|
|
+ $motociclo += 1;
|
|
|
+ break;
|
|
|
+ case \App\Models\Vehicle::VELOCIPEDE:
|
|
|
+ $velocipede += 1;
|
|
|
+ break;
|
|
|
+ case \App\Models\Vehicle::AUTOBUS:
|
|
|
+ $autobus += 1;
|
|
|
+ break;
|
|
|
+ case \App\Models\Vehicle::TRATTORE_SEMIRIMORCHIO:
|
|
|
+ $altri += 1;
|
|
|
+ break;
|
|
|
+ case \App\Models\Vehicle::AUTOTURISMO:
|
|
|
+ $autobus += 1;
|
|
|
+ break;
|
|
|
+ case \App\Models\Vehicle::RIMORCHIO:
|
|
|
+ $altri += 1;
|
|
|
+ break;
|
|
|
+ case \App\Models\Vehicle::AUTOCARRO:
|
|
|
+ $altri += 1;
|
|
|
+ break;
|
|
|
+ case \App\Models\Vehicle::AUTOVETTURA_CON_RIMORCHIO:
|
|
|
+ $autovetture += 1;
|
|
|
+ break;
|
|
|
+ case \App\Models\Vehicle::AUTOSNODATO_O_AUTOARTICOLATO:
|
|
|
+ $autotreno += 1;
|
|
|
+ break;
|
|
|
+ case \App\Models\Vehicle::MOTOCARRO_O_MOTOFURGONE:
|
|
|
+ $motociclo += 1;
|
|
|
+ break;
|
|
|
+ case \App\Models\Vehicle::AUTOTRENO_CON_RIMORCHIO:
|
|
|
+ $autotreno += 1;
|
|
|
+ break;
|
|
|
+ }
|
|
|
+
|
|
|
+ }
|
|
|
+ switch ($data_veicolo["infortunato"]) {
|
|
|
+ case Prefettura::INFORTUNATO_DECEDUTO_30GG:
|
|
|
+ $deceduti += 1;
|
|
|
+ break;
|
|
|
+ case Prefettura::INFORTUNATO_DECEDUTO_24H:
|
|
|
+ $deceduti += 1;
|
|
|
+ break;
|
|
|
+ case Prefettura::INFORTUNATO_FERITO:
|
|
|
+ $feriti += 1;
|
|
|
+ break;
|
|
|
+ }
|
|
|
+ }
|
|
|
+ }
|
|
|
+
|
|
|
+ $datiPedoni = ReportDataPedoni::where('report_id', $report->id)->get()->toArray();
|
|
|
+ for ($j = 0; $j < 4; $j++) {
|
|
|
+
|
|
|
+ $pedone_data = str_repeat(' ', 6);
|
|
|
+
|
|
|
+ if (isset($datiPedoni[$j])) {
|
|
|
+ $pedoni += 1;
|
|
|
+ }
|
|
|
+ }
|
|
|
+
|
|
|
+ $activeWorksheet->setCellValue('L' . $idx, $autovetture);
|
|
|
+ $activeWorksheet->setCellValue('M' . $idx, "0");
|
|
|
+ $activeWorksheet->setCellValue('N' . $idx, "0");
|
|
|
+ $activeWorksheet->setCellValue('O' . $idx, $autotreno);
|
|
|
+ $activeWorksheet->setCellValue('P' . $idx, $autoarticolato);
|
|
|
+ $activeWorksheet->setCellValue('Q' . $idx, $autobus);
|
|
|
+ $activeWorksheet->setCellValue('R' . $idx, $tram);
|
|
|
+ $activeWorksheet->setCellValue('S' . $idx, $treno);
|
|
|
+ $activeWorksheet->setCellValue('T' . $idx, $motociclo);
|
|
|
+ $activeWorksheet->setCellValue('U' . $idx, $ciclomotore);
|
|
|
+ $activeWorksheet->setCellValue('V' . $idx, $velocipede);
|
|
|
+ $activeWorksheet->setCellValue('W' . $idx, $bicicletta);
|
|
|
+ $activeWorksheet->setCellValue('X' . $idx, $monopattino);
|
|
|
+ $activeWorksheet->setCellValue('Y' . $idx, $altri_micro);
|
|
|
+ $activeWorksheet->setCellValue('Z' . $idx, $altri);
|
|
|
+
|
|
|
+ $activeWorksheet->setCellValue('AA' . $idx, "???");
|
|
|
+
|
|
|
+ $activeWorksheet->setCellValue('AB' . $idx, $pedoni);
|
|
|
+ $activeWorksheet->setCellValue('AC' . $idx, $deceduti);
|
|
|
+ $activeWorksheet->setCellValue('AD' . $idx, $feriti);
|
|
|
+
|
|
|
+ $stradario_due = \App\Models\Stradario::find($report->localita_due);
|
|
|
+ $location_description = $stradario_due ?
|
|
|
+ (($stradario_due['TOPONIMO'] ?? '') . ' ' . ($stradario_due['DESCRIZIONE'] ?? '')) :
|
|
|
+ '';
|
|
|
+
|
|
|
+ $activeWorksheet->setCellValue('AE' . $idx, $location_description);
|
|
|
+
|
|
|
+ $km = '';
|
|
|
+ $metri = '';
|
|
|
+ if ($report->prossimita_chilometro != '')
|
|
|
+ {
|
|
|
+ try
|
|
|
+ {
|
|
|
+ list($km, $metri) = explode("+", $report->prossimita_chilometro);
|
|
|
+ } catch (\Exception $ex) {
|
|
|
+
|
|
|
+ }
|
|
|
+ try
|
|
|
+ {
|
|
|
+ list($km, $metri) = explode(".", $report->prossimita_chilometro);
|
|
|
+ } catch (\Exception $ex) {
|
|
|
+
|
|
|
+ }
|
|
|
+ try
|
|
|
+ {
|
|
|
+ list($km, $metri) = explode(",", $report->prossimita_chilometro);
|
|
|
+ } catch (\Exception $ex) {
|
|
|
+
|
|
|
+ }
|
|
|
+ }
|
|
|
+
|
|
|
+ $activeWorksheet->setCellValue('AF' . $idx, $km);
|
|
|
+ $activeWorksheet->setCellValue('AG' . $idx, $metri);
|
|
|
+ $activeWorksheet->setCellValue('AH' . $idx, "");
|
|
|
+ $activeWorksheet->setCellValue('AI' . $idx, "");
|
|
|
+ $activeWorksheet->setCellValue('AJ' . $idx, "");
|
|
|
+ $activeWorksheet->setCellValue('AK' . $idx, "???");
|
|
|
+ $activeWorksheet->setCellValue('AL' . $idx, "???");
|
|
|
+ $activeWorksheet->setCellValue('AM' . $idx, $report->cds);
|
|
|
+ $activeWorksheet->setCellValue('AN' . $idx, $item->latitude);
|
|
|
+ $activeWorksheet->setCellValue('AO' . $idx, $item->longitude);
|
|
|
+
|
|
|
+ $idx += 1;
|
|
|
+
|
|
|
+ } catch (\Exception $e) {
|
|
|
+ Log::error('Error for item ' . $item->id . ': ' . $e->getMessage());
|
|
|
+ }
|
|
|
+
|
|
|
+ }
|
|
|
+
|
|
|
+ $writer = new Xlsx($spreadsheet);
|
|
|
+ $writer->save($path = storage_path('prefettura' . date("YmdHis") . '.xlsx'));
|
|
|
+ return response()->download($path)->deleteFileAfterSend();
|
|
|
+
|
|
|
+ } catch (\Exception $e) {
|
|
|
+ Log::error('Fatal error in export: ' . $e->getMessage());
|
|
|
+ return response()->json(['error' => 'Export failed: ' . $e->getMessage()], 500);
|
|
|
+ }
|
|
|
+ }
|
|
|
+}
|