improved invoices with new renderer (#306)
* added docx renderer and demo template * added csv renderer and demo template * added xlsx renderer and demo template * added ods renderer and demo template * added user calculator * added invoice documentation
This commit is contained in:
@@ -10,7 +10,6 @@
|
||||
namespace App\DependencyInjection;
|
||||
|
||||
use Symfony\Component\Config\Definition\Exception\InvalidConfigurationException;
|
||||
use Symfony\Component\Config\Definition\Exception\InvalidDefinitionException;
|
||||
use Symfony\Component\DependencyInjection\ContainerBuilder;
|
||||
use Symfony\Component\DependencyInjection\Extension\PrependExtensionInterface;
|
||||
use Symfony\Component\HttpKernel\DependencyInjection\Extension;
|
||||
@@ -39,10 +38,10 @@ class AppExtension extends Extension implements PrependExtensionInterface
|
||||
$container->setParameter('kimai.theme', $config['theme']);
|
||||
$container->setParameter('kimai.dashboard', $config['dashboard']);
|
||||
$container->setParameter('kimai.widgets', $config['widgets']);
|
||||
$container->setParameter('kimai.invoice.documents', $config['invoice']['documents']);
|
||||
|
||||
$this->createUserParameter($config, $container);
|
||||
$this->createTimesheetParameter($config, $container);
|
||||
$this->createInvoiceParameter($config, $container);
|
||||
}
|
||||
|
||||
/**
|
||||
@@ -78,25 +77,6 @@ class AppExtension extends Extension implements PrependExtensionInterface
|
||||
$container->setParameter('kimai.timesheet.markdown', $config['timesheet']['markdown_content']);
|
||||
}
|
||||
|
||||
/**
|
||||
* @param array $config
|
||||
* @param ContainerBuilder $container
|
||||
*/
|
||||
private function createInvoiceParameter(array $config, ContainerBuilder $container)
|
||||
{
|
||||
$keys = ['renderer', 'calculator', 'number_generator'];
|
||||
|
||||
foreach ($keys as $key) {
|
||||
if (!isset($config['invoice'][$key]) || 0 === count($config['invoice'][$key])) {
|
||||
throw new InvalidDefinitionException('Missing invoice configuration: kimai.invoice.' . $key);
|
||||
}
|
||||
|
||||
$container->setParameter('kimai.invoice.' . $key, $config['invoice'][$key]);
|
||||
}
|
||||
|
||||
$container->setParameter('kimai.invoice', $config['invoice']);
|
||||
}
|
||||
|
||||
/**
|
||||
* @param ContainerBuilder $container
|
||||
*/
|
||||
|
||||
@@ -0,0 +1,51 @@
|
||||
<?php
|
||||
|
||||
/*
|
||||
* This file is part of the Kimai time-tracking app.
|
||||
*
|
||||
* For the full copyright and license information, please view the LICENSE
|
||||
* file that was distributed with this source code.
|
||||
*/
|
||||
|
||||
namespace App\DependencyInjection\Compiler;
|
||||
|
||||
use App\Invoice\ServiceInvoice;
|
||||
use App\Kernel;
|
||||
use Symfony\Component\DependencyInjection\Compiler\CompilerPassInterface;
|
||||
use Symfony\Component\DependencyInjection\ContainerBuilder;
|
||||
use Symfony\Component\DependencyInjection\Reference;
|
||||
|
||||
/**
|
||||
* Dynamically adds all dependencies to the InvoiceService.
|
||||
*/
|
||||
class InvoiceServiceCompilerPass implements CompilerPassInterface
|
||||
{
|
||||
/**
|
||||
* @param ContainerBuilder $container
|
||||
* @throws \Exception
|
||||
*/
|
||||
public function process(ContainerBuilder $container)
|
||||
{
|
||||
// always first check if the primary service is defined
|
||||
if (!$container->has(ServiceInvoice::class)) {
|
||||
return;
|
||||
}
|
||||
|
||||
$definition = $container->findDefinition(ServiceInvoice::class);
|
||||
|
||||
$taggedRenderer = $container->findTaggedServiceIds(Kernel::TAG_INVOICE_RENDERER);
|
||||
foreach ($taggedRenderer as $id => $tags) {
|
||||
$definition->addMethodCall('addRenderer', [new Reference($id)]);
|
||||
}
|
||||
|
||||
$taggedGenerator = $container->findTaggedServiceIds(Kernel::TAG_INVOICE_NUMBER_GENERATOR);
|
||||
foreach ($taggedGenerator as $id => $tags) {
|
||||
$definition->addMethodCall('addNumberGenerator', [new Reference($id)]);
|
||||
}
|
||||
|
||||
$taggedCalculator = $container->findTaggedServiceIds(Kernel::TAG_INVOICE_CALCULATOR);
|
||||
foreach ($taggedCalculator as $id => $tags) {
|
||||
$definition->addMethodCall('addCalculator', [new Reference($id)]);
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -29,5 +29,17 @@ class TwigContextCompilerPass implements CompilerPassInterface
|
||||
|
||||
$twig->addMethodCall('addGlobal', ['kimai_context', $theme]);
|
||||
$twig->addMethodCall('addGlobal', ['duration_only', $durationOnly]);
|
||||
|
||||
if ($container->hasDefinition('twig.loader.native_filesystem')) {
|
||||
$definition = $container->getDefinition('twig.loader.native_filesystem');
|
||||
|
||||
$path = dirname(dirname(dirname(__DIR__))) . DIRECTORY_SEPARATOR;
|
||||
foreach ($container->getParameter('kimai.invoice.documents') as $invoicePath) {
|
||||
if (!is_dir($path . $invoicePath)) {
|
||||
continue;
|
||||
}
|
||||
$definition->addMethodCall('addPath', [$path . $invoicePath, 'invoice']);
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@@ -99,6 +99,12 @@ class Configuration implements ConfigurationInterface
|
||||
->floatNode('factor')
|
||||
->isRequired()
|
||||
->defaultValue(1)
|
||||
->validate()
|
||||
->ifTrue(function ($value) {
|
||||
return $value <= 0;
|
||||
})
|
||||
->thenInvalid('A rate factor smaller or equals 0 is not allowed')
|
||||
->end()
|
||||
->end()
|
||||
->end()
|
||||
->end()
|
||||
@@ -116,32 +122,15 @@ class Configuration implements ConfigurationInterface
|
||||
$node = $builder->root('invoice');
|
||||
|
||||
$node
|
||||
->addDefaultsIfNotSet()
|
||||
->children()
|
||||
->arrayNode('renderer')
|
||||
->arrayNode('documents')
|
||||
->requiresAtLeastOneElement()
|
||||
->useAttributeAsKey('key')
|
||||
->isRequired()
|
||||
->prototype('scalar')->end()
|
||||
->scalarPrototype()->end()
|
||||
->defaultValue([
|
||||
'default' => 'App\Controller\InvoiceController::invoiceAction',
|
||||
])
|
||||
->end()
|
||||
->arrayNode('calculator')
|
||||
->requiresAtLeastOneElement()
|
||||
->useAttributeAsKey('key')
|
||||
->isRequired()
|
||||
->prototype('scalar')->end()
|
||||
->defaultValue([
|
||||
'default' => 'App\Invoice\DefaultCalculator',
|
||||
])
|
||||
->end()
|
||||
->arrayNode('number_generator')
|
||||
->requiresAtLeastOneElement()
|
||||
->useAttributeAsKey('key')
|
||||
->isRequired()
|
||||
->prototype('scalar')->end()
|
||||
->defaultValue([
|
||||
'default' => 'App\Invoice\DateNumberGenerator',
|
||||
'var/invoices/',
|
||||
'templates/invoice/renderer/'
|
||||
])
|
||||
->end()
|
||||
->end()
|
||||
|
||||
Reference in New Issue
Block a user