diff --git a/src/Invoice/Renderer/DocxRenderer.php b/src/Invoice/Renderer/DocxRenderer.php index 8ed22f3a..92c07582 100644 --- a/src/Invoice/Renderer/DocxRenderer.php +++ b/src/Invoice/Renderer/DocxRenderer.php @@ -13,6 +13,7 @@ use App\Entity\InvoiceDocument; use App\Invoice\RendererInterface; use App\Model\InvoiceModel; use PhpOffice\PhpWord\Escaper\Xml; +use PhpOffice\PhpWord\Exception\Exception as OfficeException; use PhpOffice\PhpWord\TemplateProcessor; use Symfony\Component\HttpFoundation\File\Stream; use Symfony\Component\HttpFoundation\Response; @@ -40,7 +41,12 @@ class DocxRenderer extends AbstractRenderer implements RendererInterface $template->setValue($search, $replace); } - $template->cloneRow('entry.description', count($model->getCalculator()->getEntries())); + try { + $template->cloneRow('entry.description', count($model->getCalculator()->getEntries())); + } catch (OfficeException $ex) { + $template->cloneRow('entry.row', count($model->getCalculator()->getEntries())); + } + $i = 1; foreach ($model->getCalculator()->getEntries() as $entry) { $values = $this->timesheetToArray($entry); diff --git a/src/Invoice/Renderer/RendererTrait.php b/src/Invoice/Renderer/RendererTrait.php index db362b0a..98f3f6ec 100644 --- a/src/Invoice/Renderer/RendererTrait.php +++ b/src/Invoice/Renderer/RendererTrait.php @@ -161,6 +161,7 @@ trait RendererTrait $end = $timesheet->getEnd(); return [ + 'entry.row' => '', 'entry.description' => $description, 'entry.amount' => $amount, 'entry.rate' => $this->getFormattedMoney($hourlyRate), diff --git a/tests/Invoice/Renderer/DebugRendererTest.php b/tests/Invoice/Renderer/DebugRendererTest.php index b1b3ba2b..b042b809 100644 --- a/tests/Invoice/Renderer/DebugRendererTest.php +++ b/tests/Invoice/Renderer/DebugRendererTest.php @@ -95,6 +95,7 @@ class DebugRendererTest extends AbstractRendererTest protected function assertEntryStructure(array $model) { $keys = [ + 'entry.row', 'entry.description', 'entry.amount', 'entry.rate', diff --git a/var/docs/invoices.md b/var/docs/invoices.md index 8247053a..54610f44 100644 --- a/var/docs/invoices.md +++ b/var/docs/invoices.md @@ -67,8 +67,11 @@ GitHub to find out which variables can be used or debug it with: Docx templates are powered by [PHPWord](https://github.com/PHPOffice/PHPWord) and its `TemplateProcessor`. -**Important:** The variable `${entry.description}` has to be set in one table row, otherwise no timesheet records will be rendered! -This row will then be cloned for every timesheet entry. +**Important:** You have to add one of the variables - either `${entry.description}` or `${entry.row}` - in one table row, +otherwise the rendering process will fail! The row containing this variable will be cloned for every included timesheet record. + +If you do not use `${entry.description}` then a fallback for `${entry.row}` is used and will be removed in the rendering process, +it will not show up in the generated invoice. See below in `Template variables` to find out which variables you can use in your template. @@ -144,6 +147,7 @@ For each timesheet entry you can use the variables from the following table. | Key | Description | Example | |---|---|---| +| ${entry.row} | An empty string, used as template row for docx | | | ${entry.description} | The entries description | _foo bar_ | | ${entry.amount} | The format duration/amount for this entry | 02:47 h | | ${entry.rate} | The rate for one unit of the entry (normally one hour) | 100 |