57 lines
2.1 KiB
PHP
57 lines
2.1 KiB
PHP
<?php
|
|
|
|
namespace App\Domains\Admin\Controllers;
|
|
|
|
use App\Domains\ParticipantInvoice\ParticipantInvoiceTokens;
|
|
use App\Models\DocumentAsset;
|
|
use App\Models\DocumentTemplate;
|
|
use App\Scopes\CommonController;
|
|
use Illuminate\Http\JsonResponse;
|
|
|
|
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
|
|
{
|
|
$blocks = DocumentTemplate::forType(DocumentTemplate::TYPE_PARTICIPANT_INVOICE)
|
|
->values()
|
|
->map(fn(DocumentTemplate $block): array => [
|
|
'block' => $block->block,
|
|
'label' => self::BLOCK_LABELS[$block->block] ?? $block->block,
|
|
'content' => (string) $block->content,
|
|
'editable' => $block->editable,
|
|
'source' => in_array($block->block, self::SOURCE_BLOCKS, true),
|
|
]);
|
|
|
|
return response()->json([
|
|
'blocks' => $blocks,
|
|
'assets' => DocumentAsset::orderBy('name')->get()->map(fn(DocumentAsset $asset): array => [
|
|
'name' => $asset->name,
|
|
'label' => $asset->label,
|
|
'mime' => $asset->mime,
|
|
'token' => '{asset:' . $asset->name . '}',
|
|
'preview' => $asset->toDataUri(),
|
|
]),
|
|
'tokenGroups' => ParticipantInvoiceTokens::groups(),
|
|
]);
|
|
}
|
|
}
|