added short invoice calculator and timesheet invoice template #104 (#105)

This commit is contained in:
Kevin Papst
2018-01-23 22:30:41 +01:00
committed by GitHub
parent 50b5e93a10
commit 7f5b5ac254
10 changed files with 215 additions and 5 deletions

View File

@@ -231,6 +231,17 @@ class InvoiceController extends AbstractController
]);
}
/**
* @param InvoiceModel $model
* @return \Symfony\Component\HttpFoundation\Response
*/
public function timesheetAction(InvoiceModel $model)
{
return $this->render('invoice/timesheet.html.twig', [
'model' => $model,
]);
}
/**
* @param InvoiceQuery $query
* @return \Symfony\Component\Form\FormInterface

View File

@@ -44,6 +44,7 @@ class CustomerEditForm extends AbstractType
])
->add('number', TextType::class, [
'label' => 'label.customer_number',
'required' => false,
])
->add('comment', TextareaType::class, [
'label' => 'label.comment',

View File

@@ -11,6 +11,7 @@
namespace App\Invoice;
use App\Entity\Timesheet;
use App\Model\InvoiceModel;
/**
@@ -22,26 +23,43 @@ interface CalculatorInterface
{
/**
* Return the timesheet records that will be displayed on the invoice.
*
* @return Timesheet[]
*/
public function getEntries();
/**
* Set the invoice model and can be used to fetch the customer.
*
* @param InvoiceModel $model
*/
public function setModel(InvoiceModel $model);
/**
* Returns the subtotal before taxes.
*
* @return float
*/
public function getSubtotal(): float;
/**
* Returns the tax amount for this invoice.
*
* @return float
*/
public function getTax(): float;
/**
* Returns the total amount for this invoice including taxes.
*
* @return float
*/
public function getTotal(): float;
/**
* Returns the currency for the invoices amounts.
*
* @return string
*/
public function getCurrency(): string;

View File

@@ -11,6 +11,7 @@
namespace App\Invoice;
use App\Entity\Timesheet;
use App\Model\InvoiceModel;
/**
@@ -34,6 +35,14 @@ class DefaultCalculator implements CalculatorInterface
*/
protected $model;
/**
* @return Timesheet[]
*/
public function getEntries()
{
return $this->model->getEntries();
}
/**
* @param InvoiceModel $model
*/

View File

@@ -0,0 +1,43 @@
<?php
/*
* This file is part of the Kimai package.
*
* (c) Kevin Papst <kevin@kevinpapst.de>
*
* For the full copyright and license information, please view the LICENSE
* file that was distributed with this source code.
*/
namespace App\Invoice;
use App\Entity\Timesheet;
/**
* A calculator that sums up all timesheet records from the model and returns only one
* entry for a compact invoice version.
*
* @author Kevin Papst <kevin@kevinpapst.de>
*/
class ShortInvoiceCalculator extends DefaultCalculator
{
/**
* @return Timesheet[]
*/
public function getEntries()
{
$timesheet = new Timesheet();
foreach ($this->model->getEntries() as $entry) {
$timesheet->setDuration($timesheet->getDuration() + $entry->getDuration());
if ($timesheet->getActivity() === null) {
$timesheet->setActivity($entry->getActivity());
$timesheet->setEnd($entry->getEnd());
}
$timesheet->setBegin($entry->getBegin());
}
return [$timesheet];
}
}