Enth\u00e4lt gemischt: Laravel-10-Upgrade + Phase 1 (Contacts-Modul, Duplicats-Commands, Soft-Delete+Merge-Fields) + Phase 2 Code-Umstellungen (inquiry_id, $table='contacts'/'inquiries') + Offers-Modul (Migrationen, Models, offer_id in Booking, offer-Disk in filesystems.php). Phase 2 + Offers werden im folgenden Commit nach dev/backups/phase2-offers-2026-04-17/ verschoben, damit der Workspace auf Phase-1-only (= Test-System-Stand) reduziert ist und direkt auf Live deploybar wird. Tarball-Backup zus\u00e4tzlich unter: ../backups-safety/workspace-pre-phase1-rollback-2026-04-17.tar.gz Made-with: Cursor
99 lines
2.6 KiB
PHP
99 lines
2.6 KiB
PHP
<?php
|
|
|
|
namespace App\Models;
|
|
|
|
use Carbon\Carbon;
|
|
use Illuminate\Database\Eloquent\Factories\HasFactory;
|
|
use Illuminate\Database\Eloquent\Model;
|
|
use Illuminate\Database\Eloquent\Relations\BelongsTo;
|
|
|
|
/**
|
|
* Datei-Anhang einer Angebotsversion (Modul 6).
|
|
*
|
|
* Struktur ist bewusst an {@see BookingFile} angelehnt (identifier,
|
|
* filename, dir, original_name, ext, mine, size), damit der vorhandene
|
|
* `FileRepository::store()` 1:1 wiederverwendet werden kann. `mine`
|
|
* bleibt so geschrieben (statt `mime`) zur Konsistenz mit der
|
|
* booking_files-Konvention.
|
|
*
|
|
* @property int $id
|
|
* @property int $offer_version_id
|
|
* @property string|null $identifier
|
|
* @property string $filename
|
|
* @property string $dir
|
|
* @property string $original_name
|
|
* @property string $ext
|
|
* @property string $mine
|
|
* @property int $size
|
|
* @property bool $include_in_pdf
|
|
* @property Carbon $created_at
|
|
* @property Carbon $updated_at
|
|
* @property-read OfferVersion $version
|
|
*/
|
|
class OfferFile extends Model
|
|
{
|
|
use HasFactory;
|
|
|
|
protected $table = 'offer_files';
|
|
|
|
protected $fillable = [
|
|
'offer_version_id',
|
|
'identifier',
|
|
'filename',
|
|
'dir',
|
|
'original_name',
|
|
'ext',
|
|
'mine',
|
|
'size',
|
|
'include_in_pdf',
|
|
];
|
|
|
|
protected $casts = [
|
|
'offer_version_id' => 'int',
|
|
'size' => 'int',
|
|
'include_in_pdf' => 'bool',
|
|
];
|
|
|
|
public static array $iconExt = [
|
|
'default' => 'fa fa-file',
|
|
'pdf' => 'fa fa-file-pdf',
|
|
'jpg' => 'fa fa-file-image',
|
|
'jpeg' => 'fa fa-file-image',
|
|
'png' => 'fa fa-file-image',
|
|
'doc' => 'fa fa-file-word',
|
|
'docx' => 'fa fa-file-word',
|
|
];
|
|
|
|
public function version(): BelongsTo
|
|
{
|
|
return $this->belongsTo(OfferVersion::class, 'offer_version_id');
|
|
}
|
|
|
|
public function getIconExt(): string
|
|
{
|
|
return self::$iconExt[$this->ext] ?? self::$iconExt['default'];
|
|
}
|
|
|
|
public function getURL(bool|string $do = false): string
|
|
{
|
|
return route('storage_file', [$this->id, 'offer', $do]);
|
|
}
|
|
|
|
public function getPath(): string
|
|
{
|
|
return \Storage::disk('offer')->path($this->dir . $this->filename);
|
|
}
|
|
|
|
public function formatBytes(int $precision = 2): string
|
|
{
|
|
$size = $this->size;
|
|
if ($size <= 0) {
|
|
return (string) $size;
|
|
}
|
|
|
|
$base = log($size) / log(1024);
|
|
$suffixes = [' bytes', ' KB', ' MB', ' GB', ' TB'];
|
|
|
|
return round(1024 ** ($base - floor($base)), $precision) . $suffixes[floor($base)];
|
|
}
|
|
}
|