diff --git a/src/Invoice/Renderer/AbstractSpreadsheetRenderer.php b/src/Invoice/Renderer/AbstractSpreadsheetRenderer.php index 7cb1e554..b6690d53 100644 --- a/src/Invoice/Renderer/AbstractSpreadsheetRenderer.php +++ b/src/Invoice/Renderer/AbstractSpreadsheetRenderer.php @@ -46,7 +46,13 @@ abstract class AbstractSpreadsheetRenderer extends AbstractRenderer $this->addTemplateRows($worksheet, $invoiceItemCount); } - $worksheet->setTitle($model->getTemplate()->getTitle()); + // cleanup the title, PHP Office doesn't allow arbitrary strings + $title = substr($model->getTemplate()->getTitle(), 0, 31); + foreach (Worksheet::getInvalidCharacters() as $char) { + $title = str_replace($char, ' ', $title); + } + + $worksheet->setTitle($title); $entryRow = 0; diff --git a/src/Invoice/Renderer/RendererTrait.php b/src/Invoice/Renderer/RendererTrait.php index 93a4af05..5e15a0c5 100644 --- a/src/Invoice/Renderer/RendererTrait.php +++ b/src/Invoice/Renderer/RendererTrait.php @@ -10,7 +10,6 @@ namespace App\Invoice\Renderer; use App\Entity\InvoiceDocument; -use App\Entity\UserPreference; use App\Invoice\InvoiceItem; use App\Invoice\InvoiceModel; use Symfony\Component\HttpFoundation\BinaryFileResponse; @@ -57,7 +56,7 @@ trait RendererTrait /** * @param int $amount - * @param string $currency + * @param string|null $currency * @return mixed */ abstract protected function getFormattedMoney($amount, $currency); @@ -90,18 +89,24 @@ trait RendererTrait $project = $model->getQuery()->getProject(); $activity = $model->getQuery()->getActivity(); $currency = $model->getCalculator()->getCurrency(); + $tax = $model->getCalculator()->getTax(); + $total = $model->getCalculator()->getTotal(); + $subtotal = $model->getCalculator()->getSubtotal(); $values = [ 'invoice.due_date' => $this->getFormattedDateTime($model->getDueDate()), 'invoice.date' => $this->getFormattedDateTime($model->getInvoiceDate()), 'invoice.number' => $model->getNumberGenerator()->getInvoiceNumber(), - 'invoice.currency' => $model->getCalculator()->getCurrency(), + 'invoice.currency' => $currency, 'invoice.vat' => $model->getCalculator()->getVat(), - 'invoice.tax' => $this->getFormattedMoney($model->getCalculator()->getTax(), $currency), + 'invoice.tax' => $this->getFormattedMoney($tax, $currency), + 'invoice.tax_nc' => $this->getFormattedMoney($tax, null), 'invoice.total_time' => $this->getFormattedDuration($model->getCalculator()->getTimeWorked()), 'invoice.duration_decimal' => $this->getFormattedDecimalDuration($model->getCalculator()->getTimeWorked()), - 'invoice.total' => $this->getFormattedMoney($model->getCalculator()->getTotal(), $currency), - 'invoice.subtotal' => $this->getFormattedMoney($model->getCalculator()->getSubtotal(), $currency), + 'invoice.total' => $this->getFormattedMoney($total, $currency), + 'invoice.total_nc' => $this->getFormattedMoney($total, null), + 'invoice.subtotal' => $this->getFormattedMoney($subtotal, $currency), + 'invoice.subtotal_nc' => $this->getFormattedMoney($subtotal, null), 'template.name' => $model->getTemplate()->getName(), 'template.company' => $model->getTemplate()->getCompany(), @@ -205,8 +210,9 @@ trait RendererTrait $user = $invoiceItem->getUser(); + // this should never happen! if (empty($hourlyRate)) { - $hourlyRate = $user->getPreferenceValue(UserPreference::HOURLY_RATE); + $hourlyRate = 0; } $activity = $invoiceItem->getActivity(); @@ -222,7 +228,9 @@ trait RendererTrait 'entry.description' => $description, 'entry.amount' => $amount, 'entry.rate' => $this->getFormattedMoney($hourlyRate, $currency), + 'entry.rate_nc' => $this->getFormattedMoney($hourlyRate, null), 'entry.total' => $this->getFormattedMoney($rate, $currency), + 'entry.total_nc' => $this->getFormattedMoney($rate, null), 'entry.currency' => $currency, 'entry.duration' => $invoiceItem->getDuration(), 'entry.duration_decimal' => $this->getFormattedDecimalDuration($invoiceItem->getDuration()), diff --git a/tests/Invoice/Renderer/DebugRendererTest.php b/tests/Invoice/Renderer/DebugRendererTest.php index ca0a9f9f..e6f61609 100644 --- a/tests/Invoice/Renderer/DebugRendererTest.php +++ b/tests/Invoice/Renderer/DebugRendererTest.php @@ -60,10 +60,13 @@ class DebugRendererTest extends TestCase 'invoice.currency', 'invoice.vat', 'invoice.tax', + 'invoice.tax_nc', 'invoice.total_time', 'invoice.duration_decimal', 'invoice.total', + 'invoice.total_nc', 'invoice.subtotal', + 'invoice.subtotal_nc', 'template.name', 'template.company', 'template.address', @@ -123,7 +126,9 @@ class DebugRendererTest extends TestCase 'entry.description', 'entry.amount', 'entry.rate', + 'entry.rate_nc', 'entry.total', + 'entry.total_nc', 'entry.currency', 'entry.duration', 'entry.duration_decimal', diff --git a/tests/Invoice/Renderer/RendererTestTrait.php b/tests/Invoice/Renderer/RendererTestTrait.php index 4c3f4876..ae7059a9 100644 --- a/tests/Invoice/Renderer/RendererTestTrait.php +++ b/tests/Invoice/Renderer/RendererTestTrait.php @@ -89,7 +89,7 @@ trait RendererTestTrait $customer->setMetaField((new CustomerMeta())->setName('foo-customer')->setValue('bar-customer')->setIsVisible(true)); $template = new InvoiceTemplate(); - $template->setTitle('a test invoice template title'); + $template->setTitle('a very *long* test invoice / template title with [special] character'); $template->setVat(19); $project = new Project(); diff --git a/tests/Invoice/Renderer/TwigRendererTest.php b/tests/Invoice/Renderer/TwigRendererTest.php index 46a3c825..7b621845 100644 --- a/tests/Invoice/Renderer/TwigRendererTest.php +++ b/tests/Invoice/Renderer/TwigRendererTest.php @@ -63,7 +63,7 @@ class TwigRendererTest extends KernelTestCase $content = $response->getContent(); $this->assertStringContainsString('