diff --git a/src/Invoice/InvoiceFilename.php b/src/Invoice/InvoiceFilename.php index e20a7abf..40179d6b 100644 --- a/src/Invoice/InvoiceFilename.php +++ b/src/Invoice/InvoiceFilename.php @@ -9,6 +9,7 @@ namespace App\Invoice; +use App\Entity\Project; use Symfony\Component\String\UnicodeString; final class InvoiceFilename @@ -34,6 +35,17 @@ final class InvoiceFilename $filename .= '-' . $uCompany->ascii()->snake(); } + if (null !== $model->getQuery()) { + $projects = $model->getQuery()->getProjects(); + if (\count($projects) === 1) { + $pName = $projects[0]; + if ($pName instanceof Project) { + $uProject = new UnicodeString($pName->getName()); + $filename .= '-' . $uProject->ascii()->snake(); + } + } + } + $this->filename = $filename; } diff --git a/tests/Invoice/InvoiceFilenameTest.php b/tests/Invoice/InvoiceFilenameTest.php index f4eca948..2706e0ec 100644 --- a/tests/Invoice/InvoiceFilenameTest.php +++ b/tests/Invoice/InvoiceFilenameTest.php @@ -11,9 +11,11 @@ namespace App\Tests\Invoice; use App\Entity\Customer; use App\Entity\InvoiceTemplate; +use App\Entity\Project; use App\Invoice\InvoiceFilename; use App\Invoice\InvoiceModel; use App\Invoice\NumberGenerator\DateNumberGenerator; +use App\Repository\Query\InvoiceQuery; use PHPUnit\Framework\TestCase; /** @@ -57,5 +59,16 @@ class InvoiceFilenameTest extends TestCase $customer->setCompany('\"#+ß.!$%&/()=?\\n=/*-+´_<>@' . "\n"); $sut = new InvoiceFilename($model); self::assertEquals($datePrefix . '-ss_n', $sut->getFilename()); + + $project = new Project(); + $project->setName('Demo ProjecT1'); + + $query = new InvoiceQuery(); + $query->addProject($project); + $model->setQuery($query); + + $customer->setCompany('\"#+ß.!$%&/()=?\\n=/*-+´_<>@' . "\n"); + $sut = new InvoiceFilename($model); + self::assertEquals($datePrefix . '-ss_n-demo_projec_t1', $sut->getFilename()); } }