Neustrukturierung Customer / Lead / Booking Phase 2
This commit is contained in:
parent
313f0dbf4e
commit
6df9c401af
69 changed files with 3809 additions and 374 deletions
100
app/Repositories/OfferFileRepository.php
Normal file
100
app/Repositories/OfferFileRepository.php
Normal file
|
|
@ -0,0 +1,100 @@
|
|||
<?php
|
||||
|
||||
namespace App\Repositories;
|
||||
|
||||
use App\Models\OfferFile;
|
||||
use Illuminate\Http\JsonResponse;
|
||||
use Illuminate\Support\Facades\Response;
|
||||
|
||||
/**
|
||||
* Datei-Repository für Angebots-Anhänge.
|
||||
*
|
||||
* Bewusst API-kompatibel mit {@see BookingFileRepository} gehalten:
|
||||
* identische JSON-Response-Struktur, so dass die Dropzone-/Upload-
|
||||
* Frontends aus dem Booking-Modul ohne Anpassung geteilt werden können.
|
||||
*
|
||||
* Unterschiede:
|
||||
* - Persistiert in `offer_files` mit `offer_version_id` statt `booking_id`.
|
||||
* - Zusätzliches Feld `include_in_pdf` (bool, default true) — steuert, ob
|
||||
* der Anhang in der PDF-Generierung mitgeführt wird (Ticket B5).
|
||||
*/
|
||||
class OfferFileRepository extends FileRepository
|
||||
{
|
||||
/** @var OfferFile|null Nach save() gesetzt. */
|
||||
protected $offer_file;
|
||||
|
||||
protected $offer_version_id;
|
||||
|
||||
protected $identifier;
|
||||
|
||||
protected bool $include_in_pdf = true;
|
||||
|
||||
public function __construct(OfferFile $model)
|
||||
{
|
||||
parent::__construct();
|
||||
$this->model = $model;
|
||||
|
||||
/**
|
||||
* Offer-Upload erlaubt zusätzlich gängige Dokument-Formate
|
||||
* (Reise-Exposés als doc/docx, Kalkulationen als xlsx).
|
||||
*/
|
||||
$this->rules = [
|
||||
'file' => 'required|mimes:pdf,jpeg,jpg,png,doc,docx,xls,xlsx|max:32768',
|
||||
];
|
||||
$this->messages = [
|
||||
'file.mimes' => 'Datei ist kein PDF/JPG/PNG/DOC/XLS Format',
|
||||
'file.required' => 'Datei wird benötigt',
|
||||
];
|
||||
}
|
||||
|
||||
public function save(): void
|
||||
{
|
||||
$this->offer_file = OfferFile::create([
|
||||
'offer_version_id' => $this->offer_version_id,
|
||||
'identifier' => $this->identifier,
|
||||
'filename' => $this->allowed_filename,
|
||||
'dir' => $this->dir,
|
||||
'original_name' => $this->originalName,
|
||||
'ext' => $this->extension,
|
||||
'mine' => $this->mine,
|
||||
'size' => $this->size,
|
||||
'include_in_pdf' => $this->include_in_pdf,
|
||||
]);
|
||||
}
|
||||
|
||||
public function response(): JsonResponse
|
||||
{
|
||||
return Response::json([
|
||||
'error' => false,
|
||||
'filename' => $this->allowed_filename,
|
||||
'file_id' => $this->offer_file->id,
|
||||
'file_data' => $this->extension,
|
||||
'file_icon' => $this->offer_file->getIconExt(),
|
||||
'file_format_bytes' => $this->offer_file->formatBytes(),
|
||||
'file_url' => $this->offer_file->getURL(),
|
||||
'include_in_pdf' => $this->offer_file->include_in_pdf,
|
||||
'redirect' => '',
|
||||
'code' => 200,
|
||||
], 200);
|
||||
}
|
||||
|
||||
/**
|
||||
* Aktualisiert das `include_in_pdf`-Flag (für den Toggle in der UI).
|
||||
* Nur erlaubt, wenn die Version noch editierbar ist (Draft).
|
||||
*/
|
||||
public function toggleIncludeInPdf(OfferFile $file, bool $include): OfferFile
|
||||
{
|
||||
$version = $file->offerVersion;
|
||||
if ($version && ! $version->isEditable()) {
|
||||
throw new \DomainException(
|
||||
"OfferFile #{$file->id} gehört zu einer eingefrorenen Version "
|
||||
. "(status={$version->status}) und kann nicht mehr geändert werden."
|
||||
);
|
||||
}
|
||||
|
||||
$file->include_in_pdf = $include;
|
||||
$file->save();
|
||||
|
||||
return $file;
|
||||
}
|
||||
}
|
||||
Loading…
Add table
Add a link
Reference in a new issue