|
|
@@ -9,7 +9,9 @@ use Livewire\WithPagination;
|
|
|
use Livewire\WithFileUploads;
|
|
|
|
|
|
use Barryvdh\DomPDF\Facade\Pdf;
|
|
|
-
|
|
|
+use App\Models\ReportDataPartiCoinvolte;
|
|
|
+use App\Models\ReportDataVeicoli;
|
|
|
+use App\Models\Vehicle;
|
|
|
class Report extends Component
|
|
|
{
|
|
|
|
|
|
@@ -1821,73 +1823,201 @@ class Report extends Component
|
|
|
$this->allegatiDocumenti = \App\Models\ReportAllegatiGallery::where('report_id', $this->dataId)->where('file_type', 1)->orderBy('name')->get();
|
|
|
}
|
|
|
|
|
|
- public function addParteCoinvolta($type = 'pedone')
|
|
|
- {
|
|
|
- $count = \App\Models\ReportDataPartiCoinvolte::where('report_id', $this->dataId)->count();
|
|
|
- $progressive = $count == 0 ? 0 : $count;
|
|
|
-
|
|
|
- \App\Models\ReportDataPartiCoinvolte::create([
|
|
|
- 'report_id' => $this->dataId,
|
|
|
- 'progressive' => $progressive,
|
|
|
- 'progressive_type' => $progressive,
|
|
|
- 'conducente_o_pedone' => $type === 'veicolo' ? 2 : 1
|
|
|
- ]);
|
|
|
-
|
|
|
- $this->parti_coinvolte = \App\Models\ReportDataPartiCoinvolte::where('report_id', $this->dataId)->get();
|
|
|
- }
|
|
|
|
|
|
public function changeAnagType($type)
|
|
|
{
|
|
|
$this->anag_type = $type;
|
|
|
}
|
|
|
|
|
|
+ private function recalculateProgressives()
|
|
|
+ {
|
|
|
+ $parti = ReportDataPartiCoinvolte::where('report_id', $this->dataId)
|
|
|
+ ->orderBy('progressive')
|
|
|
+ ->get();
|
|
|
+
|
|
|
+ foreach($parti as $index => $parte) {
|
|
|
+ if($parte->progressive != $index) {
|
|
|
+ $parte->progressive = $index;
|
|
|
+ $parte->save();
|
|
|
+
|
|
|
+ // Update corresponding vehicle data if exists
|
|
|
+ ReportDataVeicoli::where('report_id', $this->dataId)
|
|
|
+ ->where('progressive', $parte->progressive)
|
|
|
+ ->update(['progressive' => $index]);
|
|
|
+ }
|
|
|
+ }
|
|
|
+ }
|
|
|
+
|
|
|
public function updateConducentePedoneParteCoinvolta($conducente_o_pedone, $progressive)
|
|
|
{
|
|
|
- \App\Models\ReportDataPartiCoinvolte::where('report_id', $this->dataId)->where('progressive', $progressive)->update([
|
|
|
- 'conducente_o_pedone' => $conducente_o_pedone
|
|
|
- ]);
|
|
|
- $this->parti_coinvolte = \App\Models\ReportDataPartiCoinvolte::where('report_id', $this->dataId)->get();
|
|
|
+ // Update parti coinvolte
|
|
|
+ ReportDataPartiCoinvolte::where('report_id', $this->dataId)
|
|
|
+ ->where('progressive', $progressive)
|
|
|
+ ->update(['conducente_o_pedone' => $conducente_o_pedone]);
|
|
|
|
|
|
+ // If switching to conducente (2), create vehicle record
|
|
|
+ if ($conducente_o_pedone === 2) {
|
|
|
+ ReportDataVeicoli::updateOrCreate(
|
|
|
+ [
|
|
|
+ 'report_id' => $this->dataId,
|
|
|
+ 'progressive' => $progressive,
|
|
|
+ ],
|
|
|
+ [
|
|
|
+ 'conducente_uguale_proprietario' => false
|
|
|
+ ]
|
|
|
+ );
|
|
|
+ }
|
|
|
+ // If switching to pedone (1), remove vehicle record
|
|
|
+ else {
|
|
|
+ ReportDataVeicoli::where('report_id', $this->dataId)
|
|
|
+ ->where('progressive', $progressive)
|
|
|
+ ->delete();
|
|
|
+ }
|
|
|
+
|
|
|
+ $this->parti_coinvolte = ReportDataPartiCoinvolte::where('report_id', $this->dataId)->get();
|
|
|
}
|
|
|
|
|
|
public function updateAnagraficaParteCoinvolta($anagrafica, $progressive)
|
|
|
{
|
|
|
- \App\Models\ReportDataPartiCoinvolte::where('report_id', $this->dataId)->where('progressive', $progressive)->update([
|
|
|
- 'anagrafica' => $anagrafica
|
|
|
- ]);
|
|
|
- $this->parti_coinvolte = \App\Models\ReportDataPartiCoinvolte::where('report_id', $this->dataId)->get();
|
|
|
+ $parte = ReportDataPartiCoinvolte::where('report_id', $this->dataId)
|
|
|
+ ->where('progressive', $progressive)
|
|
|
+ ->first();
|
|
|
+
|
|
|
+ if ($parte) {
|
|
|
+ $parte->update(['anagrafica' => $anagrafica]);
|
|
|
+
|
|
|
+ // Only update vehicle data if it's a conducente
|
|
|
+ if ($parte->conducente_o_pedone == 2) {
|
|
|
+ ReportDataVeicoli::updateOrCreate(
|
|
|
+ [
|
|
|
+ 'report_id' => $this->dataId,
|
|
|
+ 'progressive' => $progressive,
|
|
|
+ ],
|
|
|
+ [
|
|
|
+ 'conducenti' => $anagrafica
|
|
|
+ ]
|
|
|
+ );
|
|
|
+ }
|
|
|
+ }
|
|
|
|
|
|
+ $this->parti_coinvolte = ReportDataPartiCoinvolte::where('report_id', $this->dataId)->get();
|
|
|
}
|
|
|
|
|
|
public function removeAnagraficaParteCoinvolta($progressive)
|
|
|
{
|
|
|
- \App\Models\ReportDataPartiCoinvolte::where('report_id', $this->dataId)->where('progressive', $progressive)->update([
|
|
|
- 'anagrafica' => 0
|
|
|
- ]);
|
|
|
- $this->parti_coinvolte = \App\Models\ReportDataPartiCoinvolte::where('report_id', $this->dataId)->get();
|
|
|
+ $parte = ReportDataPartiCoinvolte::where('report_id', $this->dataId)
|
|
|
+ ->where('progressive', $progressive)
|
|
|
+ ->first();
|
|
|
+
|
|
|
+ if ($parte) {
|
|
|
+ $parte->update(['anagrafica' => 0]);
|
|
|
+
|
|
|
+ // Only update vehicle data if it's a conducente
|
|
|
+ if ($parte->conducente_o_pedone == 2) {
|
|
|
+ ReportDataVeicoli::where('report_id', $this->dataId)
|
|
|
+ ->where('progressive', $progressive)
|
|
|
+ ->update([
|
|
|
+ 'conducenti' => null,
|
|
|
+ 'conducente_uguale_proprietario' => null
|
|
|
+ ]);
|
|
|
+ }
|
|
|
+ }
|
|
|
+
|
|
|
+ $this->parti_coinvolte = ReportDataPartiCoinvolte::where('report_id', $this->dataId)->get();
|
|
|
}
|
|
|
|
|
|
public function updateVeicoloParteCoinvolta($veicolo, $progressive)
|
|
|
{
|
|
|
- \App\Models\ReportDataPartiCoinvolte::where('report_id', $this->dataId)->where('progressive', $progressive)->update([
|
|
|
- 'veicolo' => $veicolo
|
|
|
- ]);
|
|
|
- $this->parti_coinvolte = \App\Models\ReportDataPartiCoinvolte::where('report_id', $this->dataId)->get();
|
|
|
+ $parte = ReportDataPartiCoinvolte::where('report_id', $this->dataId)
|
|
|
+ ->where('progressive', $progressive)
|
|
|
+ ->first();
|
|
|
+
|
|
|
+ if ($parte && $parte->conducente_o_pedone == 2) {
|
|
|
+ $parte->update(['veicolo' => $veicolo]);
|
|
|
+
|
|
|
+ $vehicleInfo = Vehicle::find($veicolo);
|
|
|
+ if ($vehicleInfo) {
|
|
|
+ ReportDataVeicoli::updateOrCreate(
|
|
|
+ [
|
|
|
+ 'report_id' => $this->dataId,
|
|
|
+ 'progressive' => $progressive,
|
|
|
+ ],
|
|
|
+ [
|
|
|
+ 'veicoli' => $veicolo,
|
|
|
+ ]
|
|
|
+ );
|
|
|
+ }
|
|
|
+ }
|
|
|
|
|
|
+ $this->parti_coinvolte = ReportDataPartiCoinvolte::where('report_id', $this->dataId)->get();
|
|
|
}
|
|
|
|
|
|
public function removeVeicoloParteCoinvolta($progressive)
|
|
|
{
|
|
|
- \App\Models\ReportDataPartiCoinvolte::where('report_id', $this->dataId)->where('progressive', $progressive)->update([
|
|
|
- 'veicolo' => 0
|
|
|
- ]);
|
|
|
- $this->parti_coinvolte = \App\Models\ReportDataPartiCoinvolte::where('report_id', $this->dataId)->get();
|
|
|
+ $parte = ReportDataPartiCoinvolte::where('report_id', $this->dataId)
|
|
|
+ ->where('progressive', $progressive)
|
|
|
+ ->first();
|
|
|
+
|
|
|
+ if ($parte) {
|
|
|
+ $parte->update(['veicolo' => 0]);
|
|
|
+
|
|
|
+ if ($parte->conducente_o_pedone == 2) {
|
|
|
+ ReportDataVeicoli::where('report_id', $this->dataId)
|
|
|
+ ->where('progressive', $progressive)
|
|
|
+ ->update([
|
|
|
+ 'veicoli' => null,
|
|
|
+ 'conducenti' => null,
|
|
|
+ 'conducente_uguale_proprietario' => null
|
|
|
+ ]);
|
|
|
+ }
|
|
|
+ }
|
|
|
+
|
|
|
+ $this->parti_coinvolte = ReportDataPartiCoinvolte::where('report_id', $this->dataId)->get();
|
|
|
}
|
|
|
|
|
|
public function removeParteCoinvolta($progressive)
|
|
|
{
|
|
|
- \App\Models\ReportDataPartiCoinvolte::where('report_id', $this->dataId)->where('progressive', $progressive)->delete();
|
|
|
- $this->parti_coinvolte = \App\Models\ReportDataPartiCoinvolte::where('report_id', $this->dataId)->get();
|
|
|
+ $parte = ReportDataPartiCoinvolte::where('report_id', $this->dataId)
|
|
|
+ ->where('progressive', $progressive)
|
|
|
+ ->first();
|
|
|
+
|
|
|
+ if ($parte) {
|
|
|
+ // Delete the parti coinvolte record
|
|
|
+ $parte->delete();
|
|
|
+
|
|
|
+ // Delete corresponding vehicle data if exists
|
|
|
+ ReportDataVeicoli::where('report_id', $this->dataId)
|
|
|
+ ->where('progressive', $progressive)
|
|
|
+ ->delete();
|
|
|
+
|
|
|
+ // Recalculate progressives
|
|
|
+ $this->recalculateProgressives();
|
|
|
+ }
|
|
|
+
|
|
|
+ $this->parti_coinvolte = ReportDataPartiCoinvolte::where('report_id', $this->dataId)->get();
|
|
|
+ }
|
|
|
+
|
|
|
+ public function addParteCoinvolta($type = 'pedone')
|
|
|
+ {
|
|
|
+ $count = ReportDataPartiCoinvolte::where('report_id', $this->dataId)->count();
|
|
|
+ $progressive = $count == 0 ? 0 : $count;
|
|
|
+
|
|
|
+ ReportDataPartiCoinvolte::create([
|
|
|
+ 'report_id' => $this->dataId,
|
|
|
+ 'progressive' => $progressive,
|
|
|
+ 'progressive_type' => $progressive,
|
|
|
+ 'conducente_o_pedone' => $type === 'veicolo' ? 2 : 1
|
|
|
+ ]);
|
|
|
+
|
|
|
+ // Only create vehicle record if it's a veicolo type
|
|
|
+ if ($type === 'veicolo') {
|
|
|
+ ReportDataVeicoli::create([
|
|
|
+ 'report_id' => $this->dataId,
|
|
|
+ 'progressive' => $progressive
|
|
|
+ ]);
|
|
|
+ }
|
|
|
+
|
|
|
+ $this->parti_coinvolte = ReportDataPartiCoinvolte::where('report_id', $this->dataId)->get();
|
|
|
}
|
|
|
|
|
|
public function editAnagraficaParte($progressive)
|