++ fix: use months for assignment PDF link TTL instead of hours
This commit is contained in:
56
app/Http/Controllers/AssignmentPdfController.php
Normal file
56
app/Http/Controllers/AssignmentPdfController.php
Normal file
@@ -0,0 +1,56 @@
|
|||||||
|
<?php
|
||||||
|
|
||||||
|
namespace App\Http\Controllers;
|
||||||
|
|
||||||
|
use App\Models\Assegnazione;
|
||||||
|
use Carbon\Carbon;
|
||||||
|
use Illuminate\Contracts\View\View;
|
||||||
|
use Illuminate\Http\Request;
|
||||||
|
use Illuminate\Support\Facades\Storage;
|
||||||
|
use Illuminate\Support\Facades\URL;
|
||||||
|
use Symfony\Component\HttpFoundation\StreamedResponse;
|
||||||
|
|
||||||
|
class AssignmentPdfController extends Controller
|
||||||
|
{
|
||||||
|
public function viewer(Request $request, Assegnazione $assignment, string $code): View
|
||||||
|
{
|
||||||
|
$this->validateAccess($request, $assignment, $code);
|
||||||
|
|
||||||
|
$expiresAt = Carbon::createFromTimestamp((int) $request->query('expires'));
|
||||||
|
$pdfUrl = URL::temporarySignedRoute(
|
||||||
|
'assignments.pdf.file',
|
||||||
|
$expiresAt,
|
||||||
|
['assignment' => $assignment->id, 'code' => $code]
|
||||||
|
);
|
||||||
|
|
||||||
|
return view('assignments.pdf-viewer', [
|
||||||
|
'assignment' => $assignment,
|
||||||
|
'pdfUrl' => $pdfUrl,
|
||||||
|
]);
|
||||||
|
}
|
||||||
|
|
||||||
|
public function file(Request $request, Assegnazione $assignment, string $code): StreamedResponse
|
||||||
|
{
|
||||||
|
$this->validateAccess($request, $assignment, $code);
|
||||||
|
|
||||||
|
$pdfPath = $assignment->territorio?->pdf_path;
|
||||||
|
abort_unless($pdfPath && Storage::disk('public')->exists($pdfPath), 404);
|
||||||
|
|
||||||
|
return Storage::disk('public')->response(
|
||||||
|
$pdfPath,
|
||||||
|
'territorio-' . $assignment->territorio?->numero . '.pdf',
|
||||||
|
[
|
||||||
|
'Content-Type' => 'application/pdf',
|
||||||
|
'Content-Disposition' => 'inline; filename="territorio-' . $assignment->territorio?->numero . '.pdf"',
|
||||||
|
]
|
||||||
|
);
|
||||||
|
}
|
||||||
|
|
||||||
|
protected function validateAccess(Request $request, Assegnazione $assignment, string $code): void
|
||||||
|
{
|
||||||
|
abort_unless($request->hasValidSignature(), 403);
|
||||||
|
abort_unless($assignment->pdf_access_code && hash_equals($assignment->pdf_access_code, $code), 404);
|
||||||
|
abort_unless($assignment->is_aperta, 403);
|
||||||
|
abort_unless($assignment->territorio?->pdf_path, 404);
|
||||||
|
}
|
||||||
|
}
|
||||||
@@ -15,6 +15,8 @@ class Home extends Component
|
|||||||
public function render()
|
public function render()
|
||||||
{
|
{
|
||||||
$settings = Setting::instance();
|
$settings = Setting::instance();
|
||||||
|
$homeLimit = max(1, (int) ($settings->home_limit_list ?? 10));
|
||||||
|
$priorityThreshold = (int) ($settings->giorni_giacenza_prioritari ?? 180);
|
||||||
$annoCorrente = AnnoTeocratico::corrente();
|
$annoCorrente = AnnoTeocratico::corrente();
|
||||||
$campagnaAttiva = Campagna::attiva();
|
$campagnaAttiva = Campagna::attiva();
|
||||||
|
|
||||||
@@ -52,14 +54,33 @@ class Home extends Component
|
|||||||
$territoriDaAssegnare = Territorio::inReparto()
|
$territoriDaAssegnare = Territorio::inReparto()
|
||||||
->with('zona', 'tipologia', 'ultimaAssegnazione')
|
->with('zona', 'tipologia', 'ultimaAssegnazione')
|
||||||
->get()
|
->get()
|
||||||
|
->map(function (Territorio $territorio) use ($priorityThreshold) {
|
||||||
|
$ultima = $territorio->ultimaAssegnazione;
|
||||||
|
|
||||||
|
if ($ultima && $ultima->returned_at) {
|
||||||
|
$giorniGiacenza = $ultima->returned_at->startOfDay()->diffInDays(today());
|
||||||
|
} elseif (! $ultima) {
|
||||||
|
$giorniGiacenza = $territorio->created_at->startOfDay()->diffInDays(today());
|
||||||
|
} else {
|
||||||
|
$giorniGiacenza = 0;
|
||||||
|
}
|
||||||
|
|
||||||
|
$territorio->setAttribute('home_giorni_giacenza', $giorniGiacenza);
|
||||||
|
$territorio->setAttribute(
|
||||||
|
'home_is_prioritario',
|
||||||
|
(bool) $territorio->prioritario || $giorniGiacenza > $priorityThreshold
|
||||||
|
);
|
||||||
|
|
||||||
|
return $territorio;
|
||||||
|
})
|
||||||
->sort(function (Territorio $left, Territorio $right) {
|
->sort(function (Territorio $left, Territorio $right) {
|
||||||
$priorityComparison = (int) $right->is_prioritario <=> (int) $left->is_prioritario;
|
$priorityComparison = (int) $right->home_is_prioritario <=> (int) $left->home_is_prioritario;
|
||||||
|
|
||||||
if ($priorityComparison !== 0) {
|
if ($priorityComparison !== 0) {
|
||||||
return $priorityComparison;
|
return $priorityComparison;
|
||||||
}
|
}
|
||||||
|
|
||||||
$giacenzaComparison = $right->giorni_giacenza <=> $left->giorni_giacenza;
|
$giacenzaComparison = $right->home_giorni_giacenza <=> $left->home_giorni_giacenza;
|
||||||
|
|
||||||
if ($giacenzaComparison !== 0) {
|
if ($giacenzaComparison !== 0) {
|
||||||
return $giacenzaComparison;
|
return $giacenzaComparison;
|
||||||
@@ -67,12 +88,12 @@ class Home extends Component
|
|||||||
|
|
||||||
return strnatcasecmp((string) $left->numero, (string) $right->numero);
|
return strnatcasecmp((string) $left->numero, (string) $right->numero);
|
||||||
})
|
})
|
||||||
->take(10)
|
->take($homeLimit)
|
||||||
->values();
|
->values();
|
||||||
|
|
||||||
$daRientrare = Territorio::daRientrare()
|
$daRientrare = Territorio::daRientrare()
|
||||||
->with(['zona', 'assegnazioneCorrente.proclamatore'])
|
->with(['zona', 'assegnazioneCorrente.proclamatore'])
|
||||||
->take(10)
|
->take($homeLimit)
|
||||||
->get();
|
->get();
|
||||||
|
|
||||||
return view('livewire.home', [
|
return view('livewire.home', [
|
||||||
@@ -84,6 +105,7 @@ class Home extends Component
|
|||||||
'territoriPercorsi' => $territoriPercorsi,
|
'territoriPercorsi' => $territoriPercorsi,
|
||||||
'mediaPercorrenzaMensile' => $mediaPercorrenzaMensile,
|
'mediaPercorrenzaMensile' => $mediaPercorrenzaMensile,
|
||||||
'campagnaStats' => $campagnaStats,
|
'campagnaStats' => $campagnaStats,
|
||||||
|
'homeLimit' => $homeLimit,
|
||||||
'territoriDaAssegnare' => $territoriDaAssegnare,
|
'territoriDaAssegnare' => $territoriDaAssegnare,
|
||||||
'daRientrare' => $daRientrare,
|
'daRientrare' => $daRientrare,
|
||||||
]);
|
]);
|
||||||
|
|||||||
@@ -151,7 +151,7 @@ class Registro extends Component
|
|||||||
|
|
||||||
public function render()
|
public function render()
|
||||||
{
|
{
|
||||||
$query = Assegnazione::with(['territorio.zona', 'proclamatore', 'annoTeocratico', 'campagna']);
|
$query = Assegnazione::with(['territorio.zona', 'territorio.assegnazioneCorrente', 'proclamatore', 'annoTeocratico', 'campagna']);
|
||||||
|
|
||||||
if ($this->filtroAnno) {
|
if ($this->filtroAnno) {
|
||||||
$query->where('anno_teocratico_id', $this->filtroAnno);
|
$query->where('anno_teocratico_id', $this->filtroAnno);
|
||||||
|
|||||||
@@ -12,6 +12,7 @@ class SettingsEdit extends Component
|
|||||||
public int $giorni_giacenza_prioritari = 180;
|
public int $giorni_giacenza_prioritari = 180;
|
||||||
public int $giorni_per_smarrito = 120;
|
public int $giorni_per_smarrito = 120;
|
||||||
public int $home_limit_list = 10;
|
public int $home_limit_list = 10;
|
||||||
|
public int $assignment_link_ttl_months = 1;
|
||||||
public int $audit_retention_days = 365;
|
public int $audit_retention_days = 365;
|
||||||
|
|
||||||
public function mount()
|
public function mount()
|
||||||
@@ -22,6 +23,7 @@ class SettingsEdit extends Component
|
|||||||
$this->giorni_giacenza_prioritari = $settings->giorni_giacenza_prioritari ?? 180;
|
$this->giorni_giacenza_prioritari = $settings->giorni_giacenza_prioritari ?? 180;
|
||||||
$this->giorni_per_smarrito = $settings->giorni_per_smarrito ?? 120;
|
$this->giorni_per_smarrito = $settings->giorni_per_smarrito ?? 120;
|
||||||
$this->home_limit_list = $settings->home_limit_list ?? 10;
|
$this->home_limit_list = $settings->home_limit_list ?? 10;
|
||||||
|
$this->assignment_link_ttl_months = $settings->assignment_link_ttl_hours ?? 1;
|
||||||
$this->audit_retention_days = $settings->audit_retention_days ?? 365;
|
$this->audit_retention_days = $settings->audit_retention_days ?? 365;
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -33,6 +35,7 @@ class SettingsEdit extends Component
|
|||||||
'giorni_giacenza_prioritari' => 'required|integer|min:1|max:730',
|
'giorni_giacenza_prioritari' => 'required|integer|min:1|max:730',
|
||||||
'giorni_per_smarrito' => 'required|integer|min:30|max:365',
|
'giorni_per_smarrito' => 'required|integer|min:30|max:365',
|
||||||
'home_limit_list' => 'required|integer|min:1|max:100',
|
'home_limit_list' => 'required|integer|min:1|max:100',
|
||||||
|
'assignment_link_ttl_months' => 'required|integer|min:1|max:24',
|
||||||
'audit_retention_days' => 'required|integer|min:30|max:3650',
|
'audit_retention_days' => 'required|integer|min:30|max:3650',
|
||||||
];
|
];
|
||||||
}
|
}
|
||||||
@@ -48,6 +51,7 @@ class SettingsEdit extends Component
|
|||||||
'giorni_giacenza_prioritari' => $this->giorni_giacenza_prioritari,
|
'giorni_giacenza_prioritari' => $this->giorni_giacenza_prioritari,
|
||||||
'giorni_per_smarrito' => $this->giorni_per_smarrito,
|
'giorni_per_smarrito' => $this->giorni_per_smarrito,
|
||||||
'home_limit_list' => $this->home_limit_list,
|
'home_limit_list' => $this->home_limit_list,
|
||||||
|
'assignment_link_ttl_hours' => $this->assignment_link_ttl_months,
|
||||||
'audit_retention_days' => $this->audit_retention_days,
|
'audit_retention_days' => $this->audit_retention_days,
|
||||||
]);
|
]);
|
||||||
|
|
||||||
|
|||||||
@@ -118,6 +118,7 @@ class XmlExchange extends Component
|
|||||||
'giorni_giacenza_prioritari' => (int) ($settingsNode->giorni_giacenza_prioritari ?? 180),
|
'giorni_giacenza_prioritari' => (int) ($settingsNode->giorni_giacenza_prioritari ?? 180),
|
||||||
'giorni_per_smarrito' => (int) ($settingsNode->giorni_per_smarrito ?? 120),
|
'giorni_per_smarrito' => (int) ($settingsNode->giorni_per_smarrito ?? 120),
|
||||||
'home_limit_list' => (int) ($settingsNode->home_limit_list ?? 10),
|
'home_limit_list' => (int) ($settingsNode->home_limit_list ?? 10),
|
||||||
|
'assignment_link_ttl_hours' => (int) ($settingsNode->assignment_link_ttl_months ?? $settingsNode->assignment_link_ttl_hours ?? 1),
|
||||||
'audit_retention_days' => (int) ($settingsNode->audit_retention_days ?? 730),
|
'audit_retention_days' => (int) ($settingsNode->audit_retention_days ?? 730),
|
||||||
'setup_completed' => true,
|
'setup_completed' => true,
|
||||||
]);
|
]);
|
||||||
@@ -387,6 +388,7 @@ class XmlExchange extends Component
|
|||||||
'giorni_giacenza_prioritari' => (int) ($settings->giorni_giacenza_prioritari ?? 180),
|
'giorni_giacenza_prioritari' => (int) ($settings->giorni_giacenza_prioritari ?? 180),
|
||||||
'giorni_per_smarrito' => (int) ($settings->giorni_per_smarrito ?? 120),
|
'giorni_per_smarrito' => (int) ($settings->giorni_per_smarrito ?? 120),
|
||||||
'home_limit_list' => (int) ($settings->home_limit_list ?? 10),
|
'home_limit_list' => (int) ($settings->home_limit_list ?? 10),
|
||||||
|
'assignment_link_ttl_months' => (int) ($settings->assignment_link_ttl_hours ?? 1),
|
||||||
'audit_retention_days' => (int) ($settings->audit_retention_days ?? 730),
|
'audit_retention_days' => (int) ($settings->audit_retention_days ?? 730),
|
||||||
],
|
],
|
||||||
'zones' => Zona::query()->orderBy('id')->get(['id', 'nome', 'attivo'])->toArray(),
|
'zones' => Zona::query()->orderBy('id')->get(['id', 'nome', 'attivo'])->toArray(),
|
||||||
@@ -412,6 +414,7 @@ class XmlExchange extends Component
|
|||||||
'giorni_giacenza_prioritari' => (int) ($impostazioni[1] ?? 180),
|
'giorni_giacenza_prioritari' => (int) ($impostazioni[1] ?? 180),
|
||||||
'giorni_per_smarrito' => (int) ($impostazioni[3] ?? 120),
|
'giorni_per_smarrito' => (int) ($impostazioni[3] ?? 120),
|
||||||
'home_limit_list' => (int) ($impostazioni[2] ?? 10),
|
'home_limit_list' => (int) ($impostazioni[2] ?? 10),
|
||||||
|
'assignment_link_ttl_months' => 1,
|
||||||
'audit_retention_days' => 730,
|
'audit_retention_days' => 730,
|
||||||
];
|
];
|
||||||
|
|
||||||
|
|||||||
@@ -5,7 +5,7 @@ namespace App\Livewire\Territori;
|
|||||||
use Livewire\Component;
|
use Livewire\Component;
|
||||||
use App\Models\Territorio;
|
use App\Models\Territorio;
|
||||||
use App\Models\Assegnazione;
|
use App\Models\Assegnazione;
|
||||||
use App\Models\AnnoTeocratico;
|
use App\Models\Setting;
|
||||||
|
|
||||||
class TerritorioShow extends Component
|
class TerritorioShow extends Component
|
||||||
{
|
{
|
||||||
@@ -13,7 +13,7 @@ class TerritorioShow extends Component
|
|||||||
|
|
||||||
public function mount(Territorio $territorio)
|
public function mount(Territorio $territorio)
|
||||||
{
|
{
|
||||||
$this->territorio = $territorio->load(['zona', 'tipologia']);
|
$this->territorio = $territorio->load(['zona', 'tipologia', 'assegnazioneCorrente.proclamatore', 'ultimaAssegnazione']);
|
||||||
}
|
}
|
||||||
|
|
||||||
public function render()
|
public function render()
|
||||||
@@ -25,6 +25,8 @@ class TerritorioShow extends Component
|
|||||||
->groupBy(fn($a) => $a->annoTeocratico->label);
|
->groupBy(fn($a) => $a->annoTeocratico->label);
|
||||||
|
|
||||||
return view('livewire.territori.territorio-show', [
|
return view('livewire.territori.territorio-show', [
|
||||||
|
'activeAssignment' => $this->territorio->assegnazioneCorrente,
|
||||||
|
'assignmentLinkTtlMonths' => (int) Setting::getValue('assignment_link_ttl_hours', 1),
|
||||||
'assegnazioniPerAnno' => $assegnazioni,
|
'assegnazioniPerAnno' => $assegnazioni,
|
||||||
]);
|
]);
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -4,6 +4,8 @@ namespace App\Models;
|
|||||||
|
|
||||||
use Carbon\Carbon;
|
use Carbon\Carbon;
|
||||||
use Illuminate\Database\Eloquent\Model;
|
use Illuminate\Database\Eloquent\Model;
|
||||||
|
use Illuminate\Support\Facades\URL;
|
||||||
|
use Illuminate\Support\Str;
|
||||||
|
|
||||||
class Assegnazione extends Model
|
class Assegnazione extends Model
|
||||||
{
|
{
|
||||||
@@ -17,6 +19,7 @@ class Assegnazione extends Model
|
|||||||
'returned_at',
|
'returned_at',
|
||||||
'counted_in_campaign',
|
'counted_in_campaign',
|
||||||
'campaign_id',
|
'campaign_id',
|
||||||
|
'pdf_access_code',
|
||||||
'note',
|
'note',
|
||||||
'created_by',
|
'created_by',
|
||||||
'returned_by',
|
'returned_by',
|
||||||
@@ -79,6 +82,39 @@ class Assegnazione extends Model
|
|||||||
return is_null($this->returned_at);
|
return is_null($this->returned_at);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
public function ensurePdfAccessCode(): string
|
||||||
|
{
|
||||||
|
if ($this->pdf_access_code) {
|
||||||
|
return $this->pdf_access_code;
|
||||||
|
}
|
||||||
|
|
||||||
|
do {
|
||||||
|
$code = strtoupper(Str::random(12));
|
||||||
|
} while (static::query()->where('pdf_access_code', $code)->exists());
|
||||||
|
|
||||||
|
$this->forceFill(['pdf_access_code' => $code])->saveQuietly();
|
||||||
|
|
||||||
|
return $code;
|
||||||
|
}
|
||||||
|
|
||||||
|
public function temporaryPdfViewerUrl(): ?string
|
||||||
|
{
|
||||||
|
if (! $this->is_aperta || ! $this->territorio?->pdf_path) {
|
||||||
|
return null;
|
||||||
|
}
|
||||||
|
|
||||||
|
$months = max(1, (int) Setting::getValue('assignment_link_ttl_hours', 1));
|
||||||
|
|
||||||
|
return URL::temporarySignedRoute(
|
||||||
|
'assignments.pdf.viewer',
|
||||||
|
now()->addMonths($months),
|
||||||
|
[
|
||||||
|
'assignment' => $this->id,
|
||||||
|
'code' => $this->ensurePdfAccessCode(),
|
||||||
|
]
|
||||||
|
);
|
||||||
|
}
|
||||||
|
|
||||||
// ─── Scopes ─────────────────────────────────────────────────
|
// ─── Scopes ─────────────────────────────────────────────────
|
||||||
|
|
||||||
public function scopeAperte($query)
|
public function scopeAperte($query)
|
||||||
|
|||||||
@@ -6,6 +6,8 @@ use Illuminate\Database\Eloquent\Model;
|
|||||||
|
|
||||||
class Setting extends Model
|
class Setting extends Model
|
||||||
{
|
{
|
||||||
|
protected static ?self $cachedInstance = null;
|
||||||
|
|
||||||
protected $fillable = [
|
protected $fillable = [
|
||||||
'congregazione_nome',
|
'congregazione_nome',
|
||||||
'logo_path',
|
'logo_path',
|
||||||
@@ -13,6 +15,7 @@ class Setting extends Model
|
|||||||
'giorni_giacenza_prioritari',
|
'giorni_giacenza_prioritari',
|
||||||
'giorni_per_smarrito',
|
'giorni_per_smarrito',
|
||||||
'home_limit_list',
|
'home_limit_list',
|
||||||
|
'assignment_link_ttl_hours',
|
||||||
'audit_retention_days',
|
'audit_retention_days',
|
||||||
'setup_completed',
|
'setup_completed',
|
||||||
];
|
];
|
||||||
@@ -25,22 +28,41 @@ class Setting extends Model
|
|||||||
'giorni_giacenza_prioritari' => 'integer',
|
'giorni_giacenza_prioritari' => 'integer',
|
||||||
'giorni_per_smarrito' => 'integer',
|
'giorni_per_smarrito' => 'integer',
|
||||||
'home_limit_list' => 'integer',
|
'home_limit_list' => 'integer',
|
||||||
|
'assignment_link_ttl_hours' => 'integer',
|
||||||
'audit_retention_days' => 'integer',
|
'audit_retention_days' => 'integer',
|
||||||
];
|
];
|
||||||
}
|
}
|
||||||
|
|
||||||
|
protected static function booted(): void
|
||||||
|
{
|
||||||
|
static::saved(function (): void {
|
||||||
|
static::$cachedInstance = null;
|
||||||
|
});
|
||||||
|
|
||||||
|
static::deleted(function (): void {
|
||||||
|
static::$cachedInstance = null;
|
||||||
|
});
|
||||||
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Get the singleton settings instance (first row).
|
* Get the singleton settings instance (first row).
|
||||||
*/
|
*/
|
||||||
public static function instance(): static
|
public static function instance(): static
|
||||||
{
|
{
|
||||||
return static::firstOrCreate([], [
|
if (static::$cachedInstance instanceof static) {
|
||||||
|
return static::$cachedInstance;
|
||||||
|
}
|
||||||
|
|
||||||
|
static::$cachedInstance = static::firstOrCreate([], [
|
||||||
'giorni_giacenza_da_assegnare' => 120,
|
'giorni_giacenza_da_assegnare' => 120,
|
||||||
'giorni_giacenza_prioritari' => 180,
|
'giorni_giacenza_prioritari' => 180,
|
||||||
'giorni_per_smarrito' => 120,
|
'giorni_per_smarrito' => 120,
|
||||||
'home_limit_list' => 10,
|
'home_limit_list' => 10,
|
||||||
|
'assignment_link_ttl_hours' => 1,
|
||||||
'audit_retention_days' => 730,
|
'audit_retention_days' => 730,
|
||||||
]);
|
]);
|
||||||
|
|
||||||
|
return static::$cachedInstance;
|
||||||
}
|
}
|
||||||
|
|
||||||
public static function isSetupComplete(): bool
|
public static function isSetupComplete(): bool
|
||||||
|
|||||||
@@ -107,11 +107,11 @@ class Territorio extends Model
|
|||||||
$ultima = $this->ultimaAssegnazione;
|
$ultima = $this->ultimaAssegnazione;
|
||||||
|
|
||||||
if ($ultima && $ultima->returned_at) {
|
if ($ultima && $ultima->returned_at) {
|
||||||
return Carbon::parse($ultima->returned_at)->diffInDays(now());
|
return Carbon::parse($ultima->returned_at)->startOfDay()->diffInDays(today());
|
||||||
}
|
}
|
||||||
|
|
||||||
if (!$ultima) {
|
if (!$ultima) {
|
||||||
return $this->created_at->diffInDays(now());
|
return $this->created_at->startOfDay()->diffInDays(today());
|
||||||
}
|
}
|
||||||
|
|
||||||
// Currently assigned, no giacenza concept
|
// Currently assigned, no giacenza concept
|
||||||
|
|||||||
@@ -0,0 +1,22 @@
|
|||||||
|
<?php
|
||||||
|
|
||||||
|
use Illuminate\Database\Migrations\Migration;
|
||||||
|
use Illuminate\Database\Schema\Blueprint;
|
||||||
|
use Illuminate\Support\Facades\Schema;
|
||||||
|
|
||||||
|
return new class extends Migration
|
||||||
|
{
|
||||||
|
public function up(): void
|
||||||
|
{
|
||||||
|
Schema::table('settings', function (Blueprint $table) {
|
||||||
|
$table->unsignedInteger('assignment_link_ttl_hours')->default(24)->after('home_limit_list');
|
||||||
|
});
|
||||||
|
}
|
||||||
|
|
||||||
|
public function down(): void
|
||||||
|
{
|
||||||
|
Schema::table('settings', function (Blueprint $table) {
|
||||||
|
$table->dropColumn('assignment_link_ttl_hours');
|
||||||
|
});
|
||||||
|
}
|
||||||
|
};
|
||||||
@@ -0,0 +1,23 @@
|
|||||||
|
<?php
|
||||||
|
|
||||||
|
use Illuminate\Database\Migrations\Migration;
|
||||||
|
use Illuminate\Database\Schema\Blueprint;
|
||||||
|
use Illuminate\Support\Facades\Schema;
|
||||||
|
|
||||||
|
return new class extends Migration
|
||||||
|
{
|
||||||
|
public function up(): void
|
||||||
|
{
|
||||||
|
Schema::table('assegnazioni', function (Blueprint $table) {
|
||||||
|
$table->string('pdf_access_code', 32)->nullable()->unique()->after('campaign_id');
|
||||||
|
});
|
||||||
|
}
|
||||||
|
|
||||||
|
public function down(): void
|
||||||
|
{
|
||||||
|
Schema::table('assegnazioni', function (Blueprint $table) {
|
||||||
|
$table->dropUnique(['pdf_access_code']);
|
||||||
|
$table->dropColumn('pdf_access_code');
|
||||||
|
});
|
||||||
|
}
|
||||||
|
};
|
||||||
@@ -0,0 +1,25 @@
|
|||||||
|
<?php
|
||||||
|
|
||||||
|
use Illuminate\Database\Migrations\Migration;
|
||||||
|
use Illuminate\Support\Facades\DB;
|
||||||
|
|
||||||
|
return new class extends Migration
|
||||||
|
{
|
||||||
|
public function up(): void
|
||||||
|
{
|
||||||
|
DB::table('settings')
|
||||||
|
->whereNotNull('assignment_link_ttl_hours')
|
||||||
|
->update([
|
||||||
|
'assignment_link_ttl_hours' => DB::raw('GREATEST(1, CEIL(assignment_link_ttl_hours / 720))'),
|
||||||
|
]);
|
||||||
|
}
|
||||||
|
|
||||||
|
public function down(): void
|
||||||
|
{
|
||||||
|
DB::table('settings')
|
||||||
|
->whereNotNull('assignment_link_ttl_hours')
|
||||||
|
->update([
|
||||||
|
'assignment_link_ttl_hours' => DB::raw('assignment_link_ttl_hours * 720'),
|
||||||
|
]);
|
||||||
|
}
|
||||||
|
};
|
||||||
44
resources/views/assignments/pdf-viewer.blade.php
Normal file
44
resources/views/assignments/pdf-viewer.blade.php
Normal file
@@ -0,0 +1,44 @@
|
|||||||
|
<!DOCTYPE html>
|
||||||
|
<html lang="it">
|
||||||
|
<head>
|
||||||
|
<meta charset="utf-8">
|
||||||
|
<meta name="viewport" content="width=device-width, initial-scale=1">
|
||||||
|
<title>PDF territorio {{ $assignment->territorio?->numero }}</title>
|
||||||
|
<style>
|
||||||
|
html, body {
|
||||||
|
margin: 0;
|
||||||
|
height: 100%;
|
||||||
|
background: #111827;
|
||||||
|
}
|
||||||
|
|
||||||
|
.viewer {
|
||||||
|
width: 100%;
|
||||||
|
height: 100%;
|
||||||
|
border: 0;
|
||||||
|
display: block;
|
||||||
|
background: #111827;
|
||||||
|
}
|
||||||
|
|
||||||
|
.fallback {
|
||||||
|
position: fixed;
|
||||||
|
right: 12px;
|
||||||
|
bottom: 12px;
|
||||||
|
z-index: 10;
|
||||||
|
display: inline-flex;
|
||||||
|
align-items: center;
|
||||||
|
justify-content: center;
|
||||||
|
padding: 10px 14px;
|
||||||
|
border-radius: 999px;
|
||||||
|
background: rgba(17, 24, 39, 0.9);
|
||||||
|
color: #fff;
|
||||||
|
text-decoration: none;
|
||||||
|
font: 600 14px/1 system-ui, sans-serif;
|
||||||
|
box-shadow: 0 10px 30px rgba(0, 0, 0, 0.25);
|
||||||
|
}
|
||||||
|
</style>
|
||||||
|
</head>
|
||||||
|
<body>
|
||||||
|
<iframe class="viewer" src="{{ $pdfUrl }}#toolbar=0&navpanes=0&scrollbar=0" title="PDF territorio {{ $assignment->territorio?->numero }}"></iframe>
|
||||||
|
<a class="fallback" href="{{ $pdfUrl }}" target="_blank" rel="noopener noreferrer">Apri PDF</a>
|
||||||
|
</body>
|
||||||
|
</html>
|
||||||
@@ -59,14 +59,14 @@
|
|||||||
<div>
|
<div>
|
||||||
<div class="flex items-center gap-2">
|
<div class="flex items-center gap-2">
|
||||||
<a href="{{ route('territori.show', $t) }}" class="text-sm font-semibold text-gray-900 hover:text-indigo-600">N° {{ $t->numero }}</a>
|
<a href="{{ route('territori.show', $t) }}" class="text-sm font-semibold text-gray-900 hover:text-indigo-600">N° {{ $t->numero }}</a>
|
||||||
@if($t->is_prioritario)
|
@if($t->home_is_prioritario)
|
||||||
<span class="inline-flex items-center rounded-full bg-amber-100 px-2 py-0.5 text-[10px] font-semibold uppercase tracking-wide text-amber-800">Prioritario</span>
|
<span class="inline-flex items-center rounded-full bg-amber-100 px-2 py-0.5 text-[10px] font-semibold uppercase tracking-wide text-amber-800">Prioritario</span>
|
||||||
@endif
|
@endif
|
||||||
</div>
|
</div>
|
||||||
<p class="text-xs text-gray-500">
|
<p class="text-xs text-gray-500">
|
||||||
{{ $t->zona?->nome }} — {{ $t->tipologia?->nome }}
|
{{ $t->zona?->nome }} — {{ $t->tipologia?->nome }}
|
||||||
@if($t->giorni_giacenza > 0)
|
@if($t->home_giorni_giacenza > 0)
|
||||||
— in reparto da {{ $t->giorni_giacenza }} giorni
|
— in reparto da {{ $t->home_giorni_giacenza }} giorni
|
||||||
@endif
|
@endif
|
||||||
</p>
|
</p>
|
||||||
</div>
|
</div>
|
||||||
@@ -78,7 +78,7 @@
|
|||||||
<li class="px-4 py-4 text-sm text-gray-400 text-center">Tutti assegnati</li>
|
<li class="px-4 py-4 text-sm text-gray-400 text-center">Tutti assegnati</li>
|
||||||
@endforelse
|
@endforelse
|
||||||
</ul>
|
</ul>
|
||||||
@if($territoriDaAssegnare->count() >= 10)
|
@if($territoriDaAssegnare->count() >= $homeLimit)
|
||||||
<div class="px-4 py-2 bg-gray-50 border-t text-center">
|
<div class="px-4 py-2 bg-gray-50 border-t text-center">
|
||||||
<a href="{{ route('territori.index') }}?filtroStato=in_reparto" class="text-xs text-indigo-600 hover:text-indigo-800">Vedi tutti →</a>
|
<a href="{{ route('territori.index') }}?filtroStato=in_reparto" class="text-xs text-indigo-600 hover:text-indigo-800">Vedi tutti →</a>
|
||||||
</div>
|
</div>
|
||||||
@@ -111,7 +111,7 @@
|
|||||||
<li class="px-4 py-4 text-sm text-gray-400 text-center">Nessun territorio da rientrare</li>
|
<li class="px-4 py-4 text-sm text-gray-400 text-center">Nessun territorio da rientrare</li>
|
||||||
@endforelse
|
@endforelse
|
||||||
</ul>
|
</ul>
|
||||||
@if($daRientrare->count() >= 10)
|
@if($daRientrare->count() >= $homeLimit)
|
||||||
<div class="px-4 py-2 bg-gray-50 border-t text-center">
|
<div class="px-4 py-2 bg-gray-50 border-t text-center">
|
||||||
<a href="{{ route('territori.index') }}?filtroStato=da_rientrare" class="text-xs text-indigo-600 hover:text-indigo-800">Vedi tutti →</a>
|
<a href="{{ route('territori.index') }}?filtroStato=da_rientrare" class="text-xs text-indigo-600 hover:text-indigo-800">Vedi tutti →</a>
|
||||||
</div>
|
</div>
|
||||||
|
|||||||
@@ -65,6 +65,7 @@
|
|||||||
<tbody class="divide-y divide-gray-100">
|
<tbody class="divide-y divide-gray-100">
|
||||||
@forelse($assegnazioni as $a)
|
@forelse($assegnazioni as $a)
|
||||||
<tr class="hover:bg-gray-50">
|
<tr class="hover:bg-gray-50">
|
||||||
|
@php($temporaryPdfUrl = !$a->returned_at ? $a->temporaryPdfViewerUrl() : null)
|
||||||
<td class="px-3 py-2">
|
<td class="px-3 py-2">
|
||||||
<div class="flex items-center gap-2">
|
<div class="flex items-center gap-2">
|
||||||
@if($a->territorio?->thumbnail_path)
|
@if($a->territorio?->thumbnail_path)
|
||||||
@@ -98,6 +99,14 @@
|
|||||||
</td>
|
</td>
|
||||||
@can('settings.manage')
|
@can('settings.manage')
|
||||||
<td class="px-3 py-2 whitespace-nowrap">
|
<td class="px-3 py-2 whitespace-nowrap">
|
||||||
|
@can('territori.assign')
|
||||||
|
@if($a->territorio?->attivo && !$a->territorio?->assegnazioneCorrente)
|
||||||
|
<a href="{{ route('assegnazioni.assegna', ['territorioId' => $a->territorio_id]) }}"
|
||||||
|
class="inline-block text-xs font-medium text-emerald-600 hover:text-emerald-800 mr-3">
|
||||||
|
Assegna
|
||||||
|
</a>
|
||||||
|
@endif
|
||||||
|
@endcan
|
||||||
@can('territori.return')
|
@can('territori.return')
|
||||||
@if(!$a->returned_at)
|
@if(!$a->returned_at)
|
||||||
<a href="{{ route('assegnazioni.rientra', ['assegnazione' => $a->id]) }}"
|
<a href="{{ route('assegnazioni.rientra', ['assegnazione' => $a->id]) }}"
|
||||||
@@ -106,6 +115,14 @@
|
|||||||
</a>
|
</a>
|
||||||
@endif
|
@endif
|
||||||
@endcan
|
@endcan
|
||||||
|
@if($temporaryPdfUrl)
|
||||||
|
<a href="{{ $temporaryPdfUrl }}"
|
||||||
|
target="_blank"
|
||||||
|
rel="noopener noreferrer"
|
||||||
|
class="inline-block text-xs font-medium text-indigo-600 hover:text-indigo-800 mr-3">
|
||||||
|
PDF
|
||||||
|
</a>
|
||||||
|
@endif
|
||||||
<button wire:click="openEdit({{ $a->id }})"
|
<button wire:click="openEdit({{ $a->id }})"
|
||||||
style="background:#e0e7ff;color:#4338ca;border:none;border-radius:6px;padding:4px 10px;font-size:12px;cursor:pointer;margin-right:4px;">
|
style="background:#e0e7ff;color:#4338ca;border:none;border-radius:6px;padding:4px 10px;font-size:12px;cursor:pointer;margin-right:4px;">
|
||||||
Modifica
|
Modifica
|
||||||
|
|||||||
@@ -56,6 +56,13 @@
|
|||||||
@error('home_limit_list') <p class="text-red-500 text-xs mt-1">{{ $message }}</p> @enderror
|
@error('home_limit_list') <p class="text-red-500 text-xs mt-1">{{ $message }}</p> @enderror
|
||||||
</div>
|
</div>
|
||||||
|
|
||||||
|
<div>
|
||||||
|
<label for="assignment_link_ttl_months" class="block text-sm font-medium text-gray-700">Validità link PDF assegnazione (mesi)</label>
|
||||||
|
<p class="text-xs text-gray-500 mb-1">Durata del link temporaneo condivisibile per il PDF dell'assegnazione attiva.</p>
|
||||||
|
<input wire:model="assignment_link_ttl_months" type="number" min="1" max="24" id="assignment_link_ttl_months" class="mt-1 block w-full rounded-lg border-gray-300 shadow-sm focus:ring-indigo-500 focus:border-indigo-500 text-sm">
|
||||||
|
@error('assignment_link_ttl_months') <p class="text-red-500 text-xs mt-1">{{ $message }}</p> @enderror
|
||||||
|
</div>
|
||||||
|
|
||||||
<div>
|
<div>
|
||||||
<label for="audit_retention_days" class="block text-sm font-medium text-gray-700">Conservazione Audit (giorni)</label>
|
<label for="audit_retention_days" class="block text-sm font-medium text-gray-700">Conservazione Audit (giorni)</label>
|
||||||
<p class="text-xs text-gray-500 mb-1">I log più vecchi di questo periodo verranno cancellati automaticamente.</p>
|
<p class="text-xs text-gray-500 mb-1">I log più vecchi di questo periodo verranno cancellati automaticamente.</p>
|
||||||
|
|||||||
@@ -128,6 +128,11 @@
|
|||||||
</td>
|
</td>
|
||||||
<td class="px-4 py-3 text-sm text-right space-x-1">
|
<td class="px-4 py-3 text-sm text-right space-x-1">
|
||||||
<a href="{{ route('territori.show', $territorio) }}" class="text-indigo-600 hover:text-indigo-800 text-xs font-medium">Dettaglio</a>
|
<a href="{{ route('territori.show', $territorio) }}" class="text-indigo-600 hover:text-indigo-800 text-xs font-medium">Dettaglio</a>
|
||||||
|
@can('territori.assign')
|
||||||
|
@if(!$territorio->assegnazioneCorrente && $territorio->attivo)
|
||||||
|
<a href="{{ route('assegnazioni.assegna', ['territorioId' => $territorio->id]) }}" class="text-emerald-600 hover:text-emerald-800 text-xs font-medium">Assegna</a>
|
||||||
|
@endif
|
||||||
|
@endcan
|
||||||
@can('territori.return')
|
@can('territori.return')
|
||||||
@if($territorio->assegnazioneCorrente)
|
@if($territorio->assegnazioneCorrente)
|
||||||
<a href="{{ route('assegnazioni.rientra', ['assegnazione' => $territorio->assegnazioneCorrente->id]) }}" class="text-red-600 hover:text-red-800 text-xs font-medium">Rientra</a>
|
<a href="{{ route('assegnazioni.rientra', ['assegnazione' => $territorio->assegnazioneCorrente->id]) }}" class="text-red-600 hover:text-red-800 text-xs font-medium">Rientra</a>
|
||||||
|
|||||||
@@ -5,6 +5,11 @@
|
|||||||
<a href="{{ route('territori.index') }}" class="text-sm text-indigo-600 hover:text-indigo-800">← Torna alla lista</a>
|
<a href="{{ route('territori.index') }}" class="text-sm text-indigo-600 hover:text-indigo-800">← Torna alla lista</a>
|
||||||
</div>
|
</div>
|
||||||
<div class="flex items-center gap-2">
|
<div class="flex items-center gap-2">
|
||||||
|
@can('territori.assign')
|
||||||
|
@if(!$territorio->assegnazioneCorrente && $territorio->attivo)
|
||||||
|
<a href="{{ route('assegnazioni.assegna', ['territorioId' => $territorio->id]) }}" class="px-4 py-2 text-sm font-medium text-white bg-emerald-600 rounded-lg hover:bg-emerald-700 transition">Assegna</a>
|
||||||
|
@endif
|
||||||
|
@endcan
|
||||||
@can('territori.return')
|
@can('territori.return')
|
||||||
@if($territorio->assegnazioneCorrente)
|
@if($territorio->assegnazioneCorrente)
|
||||||
<a href="{{ route('assegnazioni.rientra', ['assegnazione' => $territorio->assegnazioneCorrente->id]) }}" class="px-4 py-2 text-sm font-medium text-white bg-red-600 rounded-lg hover:bg-red-700 transition">Rientra</a>
|
<a href="{{ route('assegnazioni.rientra', ['assegnazione' => $territorio->assegnazioneCorrente->id]) }}" class="px-4 py-2 text-sm font-medium text-white bg-red-600 rounded-lg hover:bg-red-700 transition">Rientra</a>
|
||||||
@@ -63,6 +68,48 @@
|
|||||||
@endif
|
@endif
|
||||||
</div>
|
</div>
|
||||||
|
|
||||||
|
@if($activeAssignment)
|
||||||
|
@php($temporaryPdfUrl = $activeAssignment->temporaryPdfViewerUrl())
|
||||||
|
<div class="bg-white rounded-xl shadow-sm border border-gray-200 p-6 mb-6" x-data="{ copied: false }">
|
||||||
|
<div class="flex flex-col gap-4 lg:flex-row lg:items-start lg:justify-between">
|
||||||
|
<div>
|
||||||
|
<h2 class="text-lg font-semibold text-gray-900">Assegnazione attiva</h2>
|
||||||
|
<p class="mt-1 text-sm text-gray-600">
|
||||||
|
{{ $activeAssignment->proclamatore?->nome_completo ?? 'N/A' }}
|
||||||
|
— assegnato il {{ $activeAssignment->assigned_at->format('d/m/Y') }}
|
||||||
|
— {{ $activeAssignment->giorni }} giorni
|
||||||
|
</p>
|
||||||
|
</div>
|
||||||
|
<div class="flex flex-wrap gap-2">
|
||||||
|
@can('territori.return')
|
||||||
|
<a href="{{ route('assegnazioni.rientra', ['assegnazione' => $activeAssignment->id]) }}" class="inline-flex items-center rounded-lg bg-red-600 px-4 py-2 text-sm font-medium text-white hover:bg-red-700 transition">Rientra</a>
|
||||||
|
@endcan
|
||||||
|
</div>
|
||||||
|
</div>
|
||||||
|
|
||||||
|
@if($temporaryPdfUrl)
|
||||||
|
<div class="mt-4 rounded-xl border border-indigo-100 bg-indigo-50/70 p-4">
|
||||||
|
<div class="flex flex-col gap-3 sm:flex-row sm:items-center sm:justify-between">
|
||||||
|
<div>
|
||||||
|
<div class="text-sm font-medium text-indigo-900">Link PDF temporaneo</div>
|
||||||
|
<div class="mt-1 text-xs text-indigo-700">Valido per {{ $assignmentLinkTtlMonths }} {{ $assignmentLinkTtlMonths === 1 ? 'mese' : 'mesi' }} o fino al rientro del territorio.</div>
|
||||||
|
</div>
|
||||||
|
<a href="{{ $temporaryPdfUrl }}" target="_blank" rel="noopener noreferrer" class="inline-flex items-center justify-center rounded-lg border border-indigo-200 bg-white px-3 py-2 text-sm font-medium text-indigo-700 hover:bg-indigo-100 transition">Apri viewer</a>
|
||||||
|
</div>
|
||||||
|
<div class="mt-3 flex flex-col gap-2 sm:flex-row">
|
||||||
|
<input x-ref="assignmentPdfLink" type="text" readonly value="{{ $temporaryPdfUrl }}" class="block w-full rounded-lg border border-indigo-200 bg-white px-3 py-2 text-sm text-gray-700 focus:border-indigo-500 focus:ring-indigo-500">
|
||||||
|
<button type="button" @click="navigator.clipboard.writeText($refs.assignmentPdfLink.value); copied = true; setTimeout(() => copied = false, 1800);" class="inline-flex items-center justify-center rounded-lg bg-indigo-600 px-4 py-2 text-sm font-medium text-white hover:bg-indigo-700 transition">Copia link</button>
|
||||||
|
</div>
|
||||||
|
<p x-show="copied" x-cloak class="mt-2 text-xs font-medium text-green-700">Link copiato.</p>
|
||||||
|
</div>
|
||||||
|
@elseif($territorio->pdf_path)
|
||||||
|
<div class="mt-4 rounded-lg border border-amber-200 bg-amber-50 px-4 py-3 text-sm text-amber-800">
|
||||||
|
Il link PDF temporaneo è disponibile solo per assegnazioni attive con PDF associato.
|
||||||
|
</div>
|
||||||
|
@endif
|
||||||
|
</div>
|
||||||
|
@endif
|
||||||
|
|
||||||
{{-- PDF viewer --}}
|
{{-- PDF viewer --}}
|
||||||
@if($territorio->pdf_path)
|
@if($territorio->pdf_path)
|
||||||
<div class="bg-white rounded-xl shadow-sm border border-gray-200 p-4 mb-6">
|
<div class="bg-white rounded-xl shadow-sm border border-gray-200 p-4 mb-6">
|
||||||
|
|||||||
@@ -2,6 +2,7 @@
|
|||||||
|
|
||||||
use Illuminate\Support\Facades\Route;
|
use Illuminate\Support\Facades\Route;
|
||||||
use App\Http\Controllers\Settings\TerritoryPdfImportController;
|
use App\Http\Controllers\Settings\TerritoryPdfImportController;
|
||||||
|
use App\Http\Controllers\AssignmentPdfController;
|
||||||
use App\Http\Controllers\Auth\LoginController;
|
use App\Http\Controllers\Auth\LoginController;
|
||||||
use App\Livewire\Home;
|
use App\Livewire\Home;
|
||||||
use App\Livewire\Territori\TerritorioIndex;
|
use App\Livewire\Territori\TerritorioIndex;
|
||||||
@@ -47,6 +48,11 @@ Route::post('logout', function () {
|
|||||||
return redirect('/login');
|
return redirect('/login');
|
||||||
})->middleware('auth')->name('logout');
|
})->middleware('auth')->name('logout');
|
||||||
|
|
||||||
|
Route::get('assegnazioni/pdf/{assignment}/{code}', [AssignmentPdfController::class, 'viewer'])
|
||||||
|
->name('assignments.pdf.viewer');
|
||||||
|
Route::get('assegnazioni/pdf/{assignment}/{code}/file', [AssignmentPdfController::class, 'file'])
|
||||||
|
->name('assignments.pdf.file');
|
||||||
|
|
||||||
/*
|
/*
|
||||||
|--------------------------------------------------------------------------
|
|--------------------------------------------------------------------------
|
||||||
| Authenticated Routes
|
| Authenticated Routes
|
||||||
|
|||||||
Reference in New Issue
Block a user