Feat: Impmlement invoice pdf rendering
This commit is contained in:
Binary file not shown.
@@ -8,10 +8,12 @@ class ContractRenderer extends AbstractPdfRenderer
|
||||
{
|
||||
public function render(Disposition $disposition): Pdf
|
||||
{
|
||||
$teamer = $disposition->getTeamer();
|
||||
|
||||
$pdf = new Pdf();
|
||||
|
||||
$pdf->SetAuthor('Continentale', true);
|
||||
$pdf->SetCreator('Continentale', true);
|
||||
$pdf->SetAuthor($teamer->getFullName(), true);
|
||||
$pdf->SetCreator($teamer->getFullName(), true);
|
||||
|
||||
// Load template
|
||||
$pdfTemplate = sprintf('%s/assets/pdf/contract.pdf', $this->config['project_dir']);
|
||||
@@ -20,7 +22,6 @@ class ContractRenderer extends AbstractPdfRenderer
|
||||
|
||||
$pdf->SetFont('Arial', '', 10);
|
||||
|
||||
$teamer = $disposition->getTeamer();
|
||||
$assignment = $disposition->getAssignment();
|
||||
$destination = $assignment->getDestination();
|
||||
|
||||
|
||||
@@ -0,0 +1,58 @@
|
||||
<?php
|
||||
|
||||
namespace App\Service\Pdf;
|
||||
|
||||
use App\Entity\Disposition;
|
||||
|
||||
class InvoiceRenderer extends AbstractPdfRenderer
|
||||
{
|
||||
public function render(Disposition $disposition): Pdf
|
||||
{
|
||||
$teamer = $disposition->getTeamer();
|
||||
|
||||
$pdf = new Pdf();
|
||||
|
||||
$pdf->SetAuthor($teamer->getFullName(), true);
|
||||
$pdf->SetCreator($teamer->getFullName(), true);
|
||||
|
||||
// Load template
|
||||
$pdfTemplate = sprintf('%s/assets/pdf/invoice.pdf', $this->config['project_dir']);
|
||||
$pdf->appendPdf($pdfTemplate);
|
||||
$pdf->setPage(1);
|
||||
|
||||
$pdf->SetFont('Arial', '', 10);
|
||||
|
||||
$assignment = $disposition->getAssignment();
|
||||
|
||||
// Name
|
||||
$pdf->Text(135,28.5, utf8_decode($teamer->getFullName()));
|
||||
|
||||
// Address
|
||||
$address = $teamer->getAddress();
|
||||
$pdf->Text(135,39, utf8_decode($address->getStreet()));
|
||||
$pdf->Text(135,51, utf8_decode($address->getPostCode(). ' '.$address->getCity()));
|
||||
|
||||
// Tax ID
|
||||
$pdf->Text(144,62, utf8_decode($teamer->getTaxId()));
|
||||
|
||||
// Invoice number
|
||||
$pdf->SetFont('Arial', '', 12);
|
||||
$number = $assignment->getTotalPeriod()->start->format('d/m/Y');
|
||||
$pdf->Text(85,116, $number);
|
||||
|
||||
$pdf->SetFont('Arial', '', 10);
|
||||
|
||||
// Bank account
|
||||
$bankAccount = $teamer->getBankAccount();
|
||||
$pdf->Text(36,233.5, utf8_decode($bankAccount->getIban()));
|
||||
$pdf->Text(36,241, utf8_decode($bankAccount->getBic()));
|
||||
$pdf->Text(36,248.5, utf8_decode($bankAccount->getBank()));
|
||||
|
||||
|
||||
// Current date
|
||||
$date = (new \DateTimeImmutable())->format('d.m.Y');
|
||||
$pdf->Text(38,264, utf8_decode($date));
|
||||
|
||||
return $pdf;
|
||||
}
|
||||
}
|
||||
@@ -18,7 +18,7 @@ use Symfony\Contracts\Translation\TranslatorInterface;
|
||||
|
||||
class ContractRendererTest extends WebTestCase
|
||||
{
|
||||
public function testRendersCard(): void
|
||||
public function testRendersContract(): void
|
||||
{
|
||||
$projectDir = static::getContainer()->getParameter('kernel.project_dir');
|
||||
$translator = $this->createMock(TranslatorInterface::class);
|
||||
|
||||
@@ -0,0 +1,94 @@
|
||||
<?php
|
||||
|
||||
namespace App\Tests\Service\Pdf;
|
||||
|
||||
use App\Entity\Application;
|
||||
use App\Entity\Assignment;
|
||||
use App\Entity\Destination;
|
||||
use App\Entity\Disposition;
|
||||
use App\Entity\Embeddable\Address;
|
||||
use App\Entity\Embeddable\BankAccount;
|
||||
use App\Entity\Embeddable\Communication;
|
||||
use App\Entity\JobProfile;
|
||||
use App\Entity\Teamer;
|
||||
use App\Entity\User;
|
||||
use App\Service\Pdf\InvoiceRenderer;
|
||||
use App\Service\Pdf\Pdf;
|
||||
use Symfony\Bundle\FrameworkBundle\Test\WebTestCase;
|
||||
use Symfony\Contracts\Translation\TranslatorInterface;
|
||||
|
||||
class InvoiceRendererTest extends WebTestCase
|
||||
{
|
||||
public function testRendersInvoice(): void
|
||||
{
|
||||
$projectDir = static::getContainer()->getParameter('kernel.project_dir');
|
||||
$translator = $this->createMock(TranslatorInterface::class);
|
||||
$renderer = new InvoiceRenderer($translator, ['project_dir' => $projectDir]);
|
||||
|
||||
$address = new Address();
|
||||
$address
|
||||
->setStreet('Testweg 1')
|
||||
->setCity('Teststadt')
|
||||
->setPostCode('12345')
|
||||
;
|
||||
|
||||
$communication = new Communication();
|
||||
$communication
|
||||
->setEmail('[email protected]')
|
||||
->setPhone('123456789')
|
||||
->setMobile('0123-456789')
|
||||
;
|
||||
|
||||
$bankAccount = new BankAccount();
|
||||
$bankAccount
|
||||
->setIban('DE88100900001234567892')
|
||||
->setBic('ABCDEF1')
|
||||
->setBank('ACME Bank')
|
||||
->setHolder('Isolde Duschen')
|
||||
;
|
||||
|
||||
$teamer = new Teamer();
|
||||
$teamer
|
||||
->setFirstName('Isolde')
|
||||
->setLastName('Duschen')
|
||||
->setTaxId('123/456/789')
|
||||
->setAddress($address)
|
||||
->setCommunication($communication)
|
||||
->setBankAccount($bankAccount)
|
||||
;
|
||||
|
||||
$destination = new Destination();
|
||||
$destination
|
||||
->setProduct('Skireise')
|
||||
->setHotel('Unterkunft')
|
||||
->setCode('ABC123')
|
||||
->setDateFrom(new \DateTimeImmutable('2023-12-01'))
|
||||
->setDateTo(new \DateTimeImmutable('2023-12-08'))
|
||||
;
|
||||
|
||||
$jobProfile = new JobProfile();
|
||||
$jobProfile->setName('Allrounder');
|
||||
|
||||
$contact = new User();
|
||||
$contact
|
||||
->setFirstName('Carmen')
|
||||
->setLastName('Bär')
|
||||
->setEmail('[email protected]')
|
||||
;
|
||||
|
||||
$assignment = new Assignment();
|
||||
$assignment
|
||||
->setDestination($destination)
|
||||
->setJobProfile($jobProfile)
|
||||
->setContact($contact)
|
||||
;
|
||||
|
||||
$application = new Application($assignment, $teamer);
|
||||
$disposition = new Disposition($application);
|
||||
|
||||
$pdf = $renderer->render($disposition);
|
||||
$this->assertInstanceOf(Pdf::class, $pdf);
|
||||
|
||||
$pdf->Output('F', $projectDir.'/temp/Honorarnote.pdf');
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user