Creating Participation refunds
This commit is contained in:
@@ -2,47 +2,38 @@
|
||||
|
||||
namespace App\Domains\Admin\Controllers;
|
||||
|
||||
use App\Domains\ParticipantInvoice\ParticipantInvoiceTokens;
|
||||
use App\Models\DocumentAsset;
|
||||
use App\Models\DocumentTemplate;
|
||||
use App\Models\DocumentTypeCatalog;
|
||||
use App\Scopes\CommonController;
|
||||
use Illuminate\Http\JsonResponse;
|
||||
use Illuminate\Http\Request;
|
||||
|
||||
class DocumentTemplatesGetController extends CommonController
|
||||
{
|
||||
/** Blöcke, die Layout-HTML bzw. CSS enthalten und deshalb im Quelltext-Editor gepflegt werden. */
|
||||
private const array SOURCE_BLOCKS = [
|
||||
DocumentTemplate::BLOCK_LAYOUT,
|
||||
DocumentTemplate::BLOCK_STYLE,
|
||||
];
|
||||
|
||||
private const array BLOCK_LABELS = [
|
||||
DocumentTemplate::BLOCK_LAYOUT => 'Seitengerüst',
|
||||
DocumentTemplate::BLOCK_STYLE => 'Gestaltung (CSS)',
|
||||
'header_sender_return' => 'Rücksendezeile',
|
||||
'header_recipient' => 'Empfängeranschrift',
|
||||
'emblem' => 'Emblem',
|
||||
'logo' => 'Logo',
|
||||
'sender_data' => 'Absenderangaben',
|
||||
'subject' => 'Betreff und Referenzdaten',
|
||||
DocumentTemplate::BLOCK_BODY => 'Rechnungsinhalt',
|
||||
'footer' => 'Grußformel und Fußnote',
|
||||
];
|
||||
|
||||
public function __invoke(): JsonResponse
|
||||
public function __invoke(Request $request): JsonResponse
|
||||
{
|
||||
$blocks = DocumentTemplate::forType(DocumentTemplate::TYPE_PARTICIPANT_INVOICE)
|
||||
$documentType = (string) $request->input('type', DocumentTypeCatalog::default());
|
||||
|
||||
if (!DocumentTypeCatalog::has($documentType)) {
|
||||
abort(422, 'Unbekannte Dokumentart.');
|
||||
}
|
||||
|
||||
$blocks = DocumentTemplate::forType($documentType)
|
||||
->values()
|
||||
->map(fn(DocumentTemplate $block): array => [
|
||||
'block' => $block->block,
|
||||
'label' => self::BLOCK_LABELS[$block->block] ?? $block->block,
|
||||
'label' => DocumentTypeCatalog::blockLabel($documentType, $block->block),
|
||||
'content' => (string) $block->content,
|
||||
'editable' => $block->editable,
|
||||
'source' => in_array($block->block, self::SOURCE_BLOCKS, true),
|
||||
'source' => in_array($block->block, DocumentTypeCatalog::SOURCE_BLOCKS, true),
|
||||
]);
|
||||
|
||||
return response()->json([
|
||||
'documentType' => $documentType,
|
||||
'documentTypes' => DocumentTypeCatalog::options(),
|
||||
'blocks' => $blocks,
|
||||
// Die Bilder gelten für alle Dokumentarten -- sie hängen nicht am Typ.
|
||||
'assets' => DocumentAsset::orderBy('name')->get()->map(fn(DocumentAsset $asset): array => [
|
||||
'name' => $asset->name,
|
||||
'label' => $asset->label,
|
||||
@@ -50,7 +41,7 @@ class DocumentTemplatesGetController extends CommonController
|
||||
'token' => '{asset:' . $asset->name . '}',
|
||||
'preview' => $asset->toDataUri(),
|
||||
]),
|
||||
'tokenGroups' => ParticipantInvoiceTokens::groups(),
|
||||
'tokenGroups' => DocumentTypeCatalog::tokenGroups($documentType),
|
||||
]);
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user