|
|
@@ -5,6 +5,7 @@ namespace App\Http\Livewire;
|
|
|
use App\Helpers\DateHelper;
|
|
|
use App\Models\Anagrafica;
|
|
|
use App\Models\ReportDataPedoni;
|
|
|
+use Illuminate\Support\Facades\Log;
|
|
|
use Livewire\Component;
|
|
|
|
|
|
class Istat extends Component
|
|
|
@@ -189,7 +190,9 @@ class Istat extends Component
|
|
|
|
|
|
public function export()
|
|
|
{
|
|
|
-
|
|
|
+ Log::info('Export ISTAT');
|
|
|
+ Log::info('From: '.$this->from);
|
|
|
+ Log::info('To: '.$this->to);
|
|
|
$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')
|
|
|
@@ -199,18 +202,16 @@ class Istat extends Component
|
|
|
})
|
|
|
->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')
|
|
|
- /*->where(function ($query) {
|
|
|
- $query->where('fcf_reports_reports.verificatosi_in_data', '>=', $this->from)
|
|
|
- ->where('fcf_reports_reports.verificatosi_in_data', '<=', $this->to);
|
|
|
- })*/
|
|
|
->orderBy('fcf_reports_reports.verificatosi_in_data')
|
|
|
->get();
|
|
|
|
|
|
$txt = array();
|
|
|
|
|
|
+ Log::info('Items: '.count($items));
|
|
|
+
|
|
|
foreach($items as $item)
|
|
|
{
|
|
|
-
|
|
|
+ Log::info('Item: '.$item->id);
|
|
|
$report = \App\Models\Report::findOrFail($item->id);
|
|
|
|
|
|
$item_data = '';
|
|
|
@@ -235,7 +236,7 @@ class Istat extends Component
|
|
|
$item_data .= '4';
|
|
|
$item_data .= str_repeat(' ',5);
|
|
|
$item_data .= ' ';
|
|
|
-
|
|
|
+ Log::info('Item Data 1 - 10: '.$item_data);
|
|
|
//11-20
|
|
|
if($item->localizzazione_incidente == Istat::LOCALIZZAZIONE_INCIDENTE_IN)
|
|
|
{
|
|
|
@@ -259,7 +260,6 @@ class Istat extends Component
|
|
|
|
|
|
$tipo_strada = ' ';
|
|
|
$types_saved = \App\Models\ReportTipoStrada::where('report_id', $report->id)->select('tipo_strada_id')->get()->toArray();
|
|
|
- // $types_saved = $report->getReportTipoStrada();
|
|
|
if($types_saved)
|
|
|
{
|
|
|
if(in_array(3,$types_saved) && in_array(1,$types_saved))
|
|
|
@@ -345,11 +345,11 @@ class Istat extends Component
|
|
|
$item_data .= $fon;
|
|
|
$item_data .= $seg;
|
|
|
$item_data .= $met;
|
|
|
+ Log::info('Item Data 11 - 20: '.$item_data);
|
|
|
|
|
|
//21-30
|
|
|
$tipo_urto = str_repeat(' ',2);
|
|
|
$types_saved = \App\Models\ReportTipoUrto::where('report_id', $report->id)->select('tipo_urto_id')->get()->toArray();
|
|
|
- // $types_saved = $report->getReportTipoUrto();
|
|
|
if($types_saved)
|
|
|
{
|
|
|
if(in_array(1,$types_saved))
|
|
|
@@ -451,12 +451,12 @@ class Istat extends Component
|
|
|
elseif($data_veicolo["drug_test"] && $data_veicolo["drug_test_esito"] == Istat::ESITO_POSITIVO)
|
|
|
$stato_psico_fisico = '94';
|
|
|
|
|
|
- $conducente = \App\Models\Anagrafica::findOrFail($data_veicolo["conducenti"]);
|
|
|
+ $conducente = Anagrafica::findOrFail($data_veicolo["conducenti"]);
|
|
|
|
|
|
$eta_conducente = '00';
|
|
|
if($conducente->birth_date != '' && $report->verificatosi_in_data != '')
|
|
|
{
|
|
|
- $eta_conducente = 0;// * * * DateHelper::calculateAge($conducente->birth_date,$report->verificatosi_in_data);
|
|
|
+ $eta_conducente = 0;
|
|
|
if($eta_conducente > 100 || $eta_conducente < 0) $eta_conducente = 0;
|
|
|
$eta_conducente = str_pad($eta_conducente,2,'0',STR_PAD_LEFT);
|
|
|
}
|
|
|
@@ -524,7 +524,7 @@ class Istat extends Component
|
|
|
if($passeggero_infortunato != Istat::INFORTUNATO_INCOLUME)
|
|
|
{
|
|
|
|
|
|
- $passeggero_anagrafica = \App\Models\Anagrafica::findOrFail($passeggero);
|
|
|
+ $passeggero_anagrafica = Anagrafica::findOrFail($passeggero);
|
|
|
|
|
|
$eta_passeggero = '00';
|
|
|
if($passeggero_anagrafica->birth_date && $report->verificatosi_in_data)
|
|
|
@@ -597,7 +597,7 @@ class Istat extends Component
|
|
|
}
|
|
|
$p_data = '';
|
|
|
|
|
|
- $datiPedoni = \App\Models\ReportDataPedoni::where('report_id', $report->id)->get()->toArray();
|
|
|
+ $datiPedoni = ReportDataPedoni::where('report_id', $report->id)->get()->toArray();
|
|
|
for($j = 0; $j < 4; $j++)
|
|
|
{
|
|
|
|
|
|
@@ -670,93 +670,16 @@ class Istat extends Component
|
|
|
$item_data .= str_pad(count($feriti),2,'0',STR_PAD_LEFT);
|
|
|
$item_data .= str_repeat(' ',9);
|
|
|
|
|
|
- /*
|
|
|
-
|
|
|
- $location_description = Helper::getStradarioAddressById($report->get('localita_due'));
|
|
|
- if($report->get('intersezione_con'))
|
|
|
- $location_description .= ' ' . sprintf(__('ISTAT_INTERSEZIONE_CON', 'reports'),Helper::getStradarioAddressById($report->get('intersezione_con')));
|
|
|
-
|
|
|
- if($report->get('prossimita_civico'))
|
|
|
- $location_description .= ' ' . sprintf(__('ISTAT_PROSSIMITA_CIVICO', 'reports'),$report->get('prossimita_civico'));
|
|
|
-
|
|
|
- if($report->get('prossimita_chilometro'))
|
|
|
- $location_description .= ' ' . sprintf(__('ISTAT_PROSSIMITA_CHILOMETRO', 'reports'),$report->get('prossimita_chilometro'));
|
|
|
-
|
|
|
- $item_data .= str_pad(substr(preg_replace('[^A-Za-z-0-9 ]','',strtoupper($location_description)),0,57),57,' ');
|
|
|
-
|
|
|
- $item_data .= str_repeat(' ',100);
|
|
|
-
|
|
|
- $deceduti = array_merge($deceduti_24h, $deceduti_30gg);
|
|
|
- for($i = 0; $i < 4; $i++)
|
|
|
- {
|
|
|
- $deceduto = ArrayHelper::getValue($deceduti, $i);
|
|
|
-
|
|
|
- $deceduto_data = str_repeat(' ',60);
|
|
|
- if($deceduto) $deceduto_data = sprintf('%s%s',
|
|
|
- str_pad(substr($deceduto['firstname'],0,30),30,' '),
|
|
|
- str_pad(substr($deceduto['lastname'],0,30),30,' ')
|
|
|
- );
|
|
|
-
|
|
|
- $item_data .= $deceduto_data;
|
|
|
- }
|
|
|
-
|
|
|
- for($i = 0; $i < 8; $i++)
|
|
|
- {
|
|
|
- $ferito = ArrayHelper::getValue($feriti, $i);
|
|
|
-
|
|
|
- $ferito_data = str_repeat(' ',90);
|
|
|
- if($ferito) $ferito_data = sprintf('%s%s%s',
|
|
|
- str_pad(substr($ferito['firstname'],0,30),30,' '),
|
|
|
- str_pad(substr($ferito['lastname'],0,30),30,' '),
|
|
|
- str_pad(substr($ferito['ospedale'],0,30),30,' ')
|
|
|
- );
|
|
|
-
|
|
|
- $item_data .= $ferito_data;
|
|
|
- }
|
|
|
-
|
|
|
- $item_data .= str_repeat(' ',10);
|
|
|
- $item_data .= str_repeat(' ',102);
|
|
|
- $item_data .= str_repeat(' ',8);
|
|
|
-
|
|
|
- $ora = $report->get('verificatosi_in_data_ora');
|
|
|
- $ora = $ora === '' ? '25' : str_pad(substr($ora,0,2),2,'0',STR_PAD_LEFT);
|
|
|
- $item_data .= $ora;
|
|
|
-
|
|
|
- $minuti = (int) $report->get('verificatosi_in_data_minuti');
|
|
|
- if($ora == '25') $minuti = ' ';
|
|
|
- $item_data .= str_pad(substr($minuti,0,2),2,'0',STR_PAD_LEFT);
|
|
|
-
|
|
|
- $item_data .= str_repeat(' ',30);
|
|
|
- $item_data .= str_repeat('0',7);
|
|
|
- $item_data .= str_repeat(' ',15);
|
|
|
- $item_data .= str_repeat(' ',4);
|
|
|
- $item_data .= str_repeat(' ',100);
|
|
|
-
|
|
|
- $item_data .= str_pad(substr(LocationHelper::getTown($report->get('localita_uno'))->title,0,40),40,' ');
|
|
|
-
|
|
|
- $item_data .= str_repeat(' ',40);
|
|
|
- $item_data .= str_repeat(' ',10);
|
|
|
-
|
|
|
- $item_data .= $v_data['cittadinanza_conducente'];
|
|
|
- */
|
|
|
-
|
|
|
$txt[] = $item_data;
|
|
|
+ Log::info('Item Data: '.$item_data);
|
|
|
}
|
|
|
+ Log::info('Fuori loop');
|
|
|
|
|
|
$txt_data = implode("\n", $txt);
|
|
|
-
|
|
|
+ Log::info('TXT Data: '.$txt_data);
|
|
|
return response()->streamDownload(function () use($txt_data) {
|
|
|
echo $txt_data;
|
|
|
}, 'istat_' . $this->from . "_" . $this->to . '.txt');
|
|
|
-
|
|
|
- /*$txt_filename = sprintf(__('ISTAT_TXT_FILENAME', $mainframe->getOption()),
|
|
|
- $model->getState('filter_date_from'),
|
|
|
- $model->getState('filter_date_to')
|
|
|
- );*/
|
|
|
- // return view('livewire.istat');
|
|
|
-
|
|
|
-
|
|
|
-
|
|
|
}
|
|
|
|
|
|
}
|