invoice: money fields without currency, title cleanup (#1254)

This commit is contained in:
Kevin Papst
2019-11-15 18:54:08 +01:00
committed by GitHub
parent 94c28ebbc5
commit 2287c9951c
5 changed files with 29 additions and 10 deletions

View File

@@ -46,7 +46,13 @@ abstract class AbstractSpreadsheetRenderer extends AbstractRenderer
$this->addTemplateRows($worksheet, $invoiceItemCount); $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; $entryRow = 0;

View File

@@ -10,7 +10,6 @@
namespace App\Invoice\Renderer; namespace App\Invoice\Renderer;
use App\Entity\InvoiceDocument; use App\Entity\InvoiceDocument;
use App\Entity\UserPreference;
use App\Invoice\InvoiceItem; use App\Invoice\InvoiceItem;
use App\Invoice\InvoiceModel; use App\Invoice\InvoiceModel;
use Symfony\Component\HttpFoundation\BinaryFileResponse; use Symfony\Component\HttpFoundation\BinaryFileResponse;
@@ -57,7 +56,7 @@ trait RendererTrait
/** /**
* @param int $amount * @param int $amount
* @param string $currency * @param string|null $currency
* @return mixed * @return mixed
*/ */
abstract protected function getFormattedMoney($amount, $currency); abstract protected function getFormattedMoney($amount, $currency);
@@ -90,18 +89,24 @@ trait RendererTrait
$project = $model->getQuery()->getProject(); $project = $model->getQuery()->getProject();
$activity = $model->getQuery()->getActivity(); $activity = $model->getQuery()->getActivity();
$currency = $model->getCalculator()->getCurrency(); $currency = $model->getCalculator()->getCurrency();
$tax = $model->getCalculator()->getTax();
$total = $model->getCalculator()->getTotal();
$subtotal = $model->getCalculator()->getSubtotal();
$values = [ $values = [
'invoice.due_date' => $this->getFormattedDateTime($model->getDueDate()), 'invoice.due_date' => $this->getFormattedDateTime($model->getDueDate()),
'invoice.date' => $this->getFormattedDateTime($model->getInvoiceDate()), 'invoice.date' => $this->getFormattedDateTime($model->getInvoiceDate()),
'invoice.number' => $model->getNumberGenerator()->getInvoiceNumber(), 'invoice.number' => $model->getNumberGenerator()->getInvoiceNumber(),
'invoice.currency' => $model->getCalculator()->getCurrency(), 'invoice.currency' => $currency,
'invoice.vat' => $model->getCalculator()->getVat(), '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.total_time' => $this->getFormattedDuration($model->getCalculator()->getTimeWorked()),
'invoice.duration_decimal' => $this->getFormattedDecimalDuration($model->getCalculator()->getTimeWorked()), 'invoice.duration_decimal' => $this->getFormattedDecimalDuration($model->getCalculator()->getTimeWorked()),
'invoice.total' => $this->getFormattedMoney($model->getCalculator()->getTotal(), $currency), 'invoice.total' => $this->getFormattedMoney($total, $currency),
'invoice.subtotal' => $this->getFormattedMoney($model->getCalculator()->getSubtotal(), $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.name' => $model->getTemplate()->getName(),
'template.company' => $model->getTemplate()->getCompany(), 'template.company' => $model->getTemplate()->getCompany(),
@@ -205,8 +210,9 @@ trait RendererTrait
$user = $invoiceItem->getUser(); $user = $invoiceItem->getUser();
// this should never happen!
if (empty($hourlyRate)) { if (empty($hourlyRate)) {
$hourlyRate = $user->getPreferenceValue(UserPreference::HOURLY_RATE); $hourlyRate = 0;
} }
$activity = $invoiceItem->getActivity(); $activity = $invoiceItem->getActivity();
@@ -222,7 +228,9 @@ trait RendererTrait
'entry.description' => $description, 'entry.description' => $description,
'entry.amount' => $amount, 'entry.amount' => $amount,
'entry.rate' => $this->getFormattedMoney($hourlyRate, $currency), 'entry.rate' => $this->getFormattedMoney($hourlyRate, $currency),
'entry.rate_nc' => $this->getFormattedMoney($hourlyRate, null),
'entry.total' => $this->getFormattedMoney($rate, $currency), 'entry.total' => $this->getFormattedMoney($rate, $currency),
'entry.total_nc' => $this->getFormattedMoney($rate, null),
'entry.currency' => $currency, 'entry.currency' => $currency,
'entry.duration' => $invoiceItem->getDuration(), 'entry.duration' => $invoiceItem->getDuration(),
'entry.duration_decimal' => $this->getFormattedDecimalDuration($invoiceItem->getDuration()), 'entry.duration_decimal' => $this->getFormattedDecimalDuration($invoiceItem->getDuration()),

View File

@@ -60,10 +60,13 @@ class DebugRendererTest extends TestCase
'invoice.currency', 'invoice.currency',
'invoice.vat', 'invoice.vat',
'invoice.tax', 'invoice.tax',
'invoice.tax_nc',
'invoice.total_time', 'invoice.total_time',
'invoice.duration_decimal', 'invoice.duration_decimal',
'invoice.total', 'invoice.total',
'invoice.total_nc',
'invoice.subtotal', 'invoice.subtotal',
'invoice.subtotal_nc',
'template.name', 'template.name',
'template.company', 'template.company',
'template.address', 'template.address',
@@ -123,7 +126,9 @@ class DebugRendererTest extends TestCase
'entry.description', 'entry.description',
'entry.amount', 'entry.amount',
'entry.rate', 'entry.rate',
'entry.rate_nc',
'entry.total', 'entry.total',
'entry.total_nc',
'entry.currency', 'entry.currency',
'entry.duration', 'entry.duration',
'entry.duration_decimal', 'entry.duration_decimal',

View File

@@ -89,7 +89,7 @@ trait RendererTestTrait
$customer->setMetaField((new CustomerMeta())->setName('foo-customer')->setValue('bar-customer')->setIsVisible(true)); $customer->setMetaField((new CustomerMeta())->setName('foo-customer')->setValue('bar-customer')->setIsVisible(true));
$template = new InvoiceTemplate(); $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); $template->setVat(19);
$project = new Project(); $project = new Project();

View File

@@ -63,7 +63,7 @@ class TwigRendererTest extends KernelTestCase
$content = $response->getContent(); $content = $response->getContent();
$this->assertStringContainsString('<h2 class="page-header"> $this->assertStringContainsString('<h2 class="page-header">
<span contenteditable="true">a test invoice template title</span> <span contenteditable="true">a very *long* test invoice / template title with [special] character</span>
</h2>', $content); </h2>', $content);
$this->assertEquals(5, substr_count($content, 'activity description')); $this->assertEquals(5, substr_count($content, 'activity description'));
} }