feat: update filename formatting of booking confirmation pdf
This commit is contained in:
@@ -11,7 +11,6 @@ use Dompdf\Options;
|
||||
use Symfony\Component\DependencyInjection\Attribute\Autowire;
|
||||
use Symfony\Component\HttpFoundation\Response;
|
||||
use Symfony\Component\HttpFoundation\ResponseHeaderBag;
|
||||
use Symfony\Component\String\Slugger\AsciiSlugger;
|
||||
use Twig\Environment;
|
||||
|
||||
/**
|
||||
@@ -81,10 +80,6 @@ class AccommodationBookingPdfGenerator
|
||||
return $response;
|
||||
}
|
||||
|
||||
/**
|
||||
* Named after arrival date and group rather than the entity id, which is a local
|
||||
* detail with no counterpart in BusPro and would read as a booking number.
|
||||
*/
|
||||
/**
|
||||
* @throws \RuntimeException when the booking carries no price information
|
||||
*/
|
||||
@@ -95,14 +90,13 @@ class AccommodationBookingPdfGenerator
|
||||
|
||||
private function buildFilename(AccommodationBooking $booking): string
|
||||
{
|
||||
$groupName = (new AsciiSlugger('de'))->slug((string) $booking->getGroupName())->lower()->toString();
|
||||
$parts = array_filter([
|
||||
$booking->getDateFrom()?->format('Y-m-d'),
|
||||
$booking->getAccommodation()?->getCalendarCode(),
|
||||
'Buchung',
|
||||
]);
|
||||
|
||||
return sprintf(
|
||||
'%s-%s%s.pdf',
|
||||
mb_strtolower($booking->recordLabel()),
|
||||
$booking->getDateFrom()?->format('Y-m-d') ?? 'ohne-datum',
|
||||
'' !== $groupName ? '-'.$groupName : ''
|
||||
);
|
||||
return implode(' ', $parts).'.pdf';
|
||||
}
|
||||
|
||||
private function logoDataUri(): string
|
||||
|
||||
@@ -27,26 +27,26 @@ class AccommodationBookingPdfGeneratorTest extends TestCase
|
||||
self::assertSame(1, $this->pageCount($pdf));
|
||||
}
|
||||
|
||||
public function testTheDownloadIsAnAttachmentNamedAfterTheGroup(): void
|
||||
public function testTheDownloadIsAnAttachmentNamedAfterArrivalDateAndHotel(): void
|
||||
{
|
||||
$response = $this->createGenerator($this->breakdown())->createDownloadResponse($this->booking());
|
||||
|
||||
self::assertSame('application/pdf', $response->headers->get('Content-Type'));
|
||||
self::assertStringContainsString('attachment;', (string) $response->headers->get('Content-Disposition'));
|
||||
self::assertStringContainsString('buchung-2026-07-06-schulklasse-7b.pdf', (string) $response->headers->get('Content-Disposition'));
|
||||
self::assertStringContainsString('2026-07-06 BERGBLICK Buchung.pdf', (string) $response->headers->get('Content-Disposition'));
|
||||
}
|
||||
|
||||
public function testADocumentForAnUnacceptedOfferIsNamedAsOne(): void
|
||||
public function testADocumentForAnUnacceptedOfferKeepsTheSameFilename(): void
|
||||
{
|
||||
// The document describes whatever the record is at the time it is produced, so it
|
||||
// must not call an offer nobody has accepted a booking.
|
||||
// 'Buchung' in the filename is a literal, not the record label: the office files
|
||||
// these documents by date and house, and a second spelling would break that order.
|
||||
$booking = $this->booking();
|
||||
$booking->setAcceptedAt(null);
|
||||
$booking->setConfirmedAt(null);
|
||||
|
||||
$response = $this->createGenerator($this->breakdown())->createDownloadResponse($booking);
|
||||
|
||||
self::assertStringContainsString('angebot-2026-07-06-schulklasse-7b.pdf', (string) $response->headers->get('Content-Disposition'));
|
||||
self::assertStringContainsString('2026-07-06 BERGBLICK Buchung.pdf', (string) $response->headers->get('Content-Disposition'));
|
||||
}
|
||||
|
||||
public function testABookingWithoutPricesCannotBeRendered(): void
|
||||
@@ -74,6 +74,7 @@ class AccommodationBookingPdfGeneratorTest extends TestCase
|
||||
{
|
||||
$accommodation = new Accommodation();
|
||||
$accommodation->setName('Haus Bergblick');
|
||||
$accommodation->setCalendarCode('BERGBLICK');
|
||||
$accommodation->setMaxAdolescentAge(11);
|
||||
$accommodation->setCurrency('EUR');
|
||||
|
||||
|
||||
Reference in New Issue
Block a user