feat(pdf): let payment receipts and reports be overridden too (#731)

Only invoices and estimates could be customised. Payment receipts and all five
reports were hardcoded to app.pdf.*, so changing them meant editing files inside
the image -- and losing the edit on the next upgrade.

Those documents have no template picker and no design to choose between, so
overriding one is not a selection: it is a same-named file in
storage/app/templates/pdf/{type}/ winning over the built-in. PdfTemplateUtils::
resolveView() is that rule, and it needs no setting, no column and no UI.

resolveView asks View::exists rather than checking the storage disk. The disk and
the view namespace are registered separately and could disagree about where
custom templates live; asking the thing that will actually render removes that
possibility.

make:template covers the new types. Their names are not free, since an override
replaces one specific document, so it validates against the real list -- 'payment'
for payments, and the five report names -- and reports what is available when the
name is wrong. Neither type gets a preview image written, having no picker to
show one in.

The payment preview route also went through the built-in view directly rather
than the service, so ?preview ignored an override and rendered with none of the
shared data. It goes through the service now, like invoices and estimates.

Claude-Session: https://claude.ai/code/session_01QmECndmNZwzN65Zz9P87dF
This commit is contained in:
Darko Gjorgjijoski
2026-08-01 13:01:15 +02:00
committed by GitHub
parent 8ab860a1ae
commit 05e8acc3b1
11 changed files with 258 additions and 35 deletions

View File

@@ -63,15 +63,42 @@ test('the new template shows up in the picker', function () {
/**
* --type was never checked against the supported list. An unsupported value
* skipped the interactive prompt and then died on an uncaught
* FileNotFoundException looking for e.g. payment1.blade.php.
* FileNotFoundException looking for a file that does not exist.
*/
test('an unsupported type is refused with a message rather than a stack trace', function () {
$exit = Artisan::call('make:template', ['name' => 'receipt', '--type' => 'payment']);
$exit = Artisan::call('make:template', ['name' => 'thing', '--type' => 'purchase-order']);
expect($exit)->toBe(Command::INVALID)
->and(Artisan::output())->toContain('Unsupported template type');
});
/**
* Payments and reports have no picker: a custom template replaces one specific
* document, so its name is not free.
*/
test('an override must be named after the document it replaces', function () {
$exit = Artisan::call('make:template', ['name' => 'my-receipt', '--type' => 'payment']);
expect($exit)->toBe(Command::INVALID)
->and(Artisan::output())->toContain('is not a payment document');
});
test('it clones a payment receipt for overriding', function () {
$exit = Artisan::call('make:template', ['name' => 'payment', '--type' => 'payment']);
expect($exit)->toBe(Command::SUCCESS)
->and(File::exists(customTemplatePath('payment', 'payment.blade.php')))->toBeTrue()
// No picker, so no preview is written.
->and(File::exists(customTemplatePath('payment', 'payment.png')))->toBeFalse();
});
test('it clones each report for overriding', function (string $report) {
$exit = Artisan::call('make:template', ['name' => $report, '--type' => 'reports']);
expect($exit)->toBe(Command::SUCCESS)
->and(File::exists(customTemplatePath('reports', "{$report}.blade.php")))->toBeTrue();
})->with(['expenses', 'profit-loss', 'sales-customers', 'sales-items', 'tax-summary']);
test('a name that would escape the templates directory is refused', function (string $name) {
$exit = Artisan::call('make:template', ['name' => $name, '--type' => 'invoice']);