diff --git a/config/packages/kimai.yaml b/config/packages/kimai.yaml index 4f615126..24bee135 100644 --- a/config/packages/kimai.yaml +++ b/config/packages/kimai.yaml @@ -154,3 +154,10 @@ kimai: activeUsersYear: { title: stats.userActiveYear, query: users, begin: '01 january this year 00:00:00', end: '31 december this year 23:59:59', icon: user, color: yellow } activeUsersTotal: { title: stats.userActiveTotal, query: users, icon: user, color: red } activeRecordings: { title: stats.activeRecordings, query: active, icon: duration, color: red } + + # Default settings used to populate forms + #defaults: + # customer: + # timezone: Europe/Berlin + # country: DE + # currency: EUR \ No newline at end of file diff --git a/config/services.yaml b/config/services.yaml index 84adba09..93ff2f4a 100644 --- a/config/services.yaml +++ b/config/services.yaml @@ -54,6 +54,10 @@ services: arguments: $timesheetAsMarkdown: "%kimai.timesheet.markdown%" + App\Controller\Admin\CustomerController: + arguments: + $defaults: "%kimai.defaults%" + # ================================================================================ # DATABASE # ================================================================================ diff --git a/src/Controller/Admin/CustomerController.php b/src/Controller/Admin/CustomerController.php index eb7634a4..3fe061a2 100644 --- a/src/Controller/Admin/CustomerController.php +++ b/src/Controller/Admin/CustomerController.php @@ -28,6 +28,19 @@ use Symfony\Component\Routing\Annotation\Route; */ class CustomerController extends AbstractController { + /** + * @var array + */ + private $defaults; + + /** + * @param array $defaults + */ + public function __construct(array $defaults) + { + $this->defaults = $defaults; + } + /** * @return \App\Repository\CustomerRepository */ @@ -67,7 +80,12 @@ class CustomerController extends AbstractController */ public function createAction(Request $request) { - return $this->renderCustomerForm(new Customer(), $request); + $customer = new Customer(); + $customer->setCountry($this->defaults['customer']['country']); + $customer->setCurrency($this->defaults['customer']['currency']); + $customer->setTimezone($this->defaults['customer']['timezone']); + + return $this->renderCustomerForm($customer, $request); } /** diff --git a/src/DependencyInjection/AppExtension.php b/src/DependencyInjection/AppExtension.php index e2a5a766..6878c602 100644 --- a/src/DependencyInjection/AppExtension.php +++ b/src/DependencyInjection/AppExtension.php @@ -39,6 +39,7 @@ class AppExtension extends Extension implements PrependExtensionInterface $container->setParameter('kimai.dashboard', $config['dashboard']); $container->setParameter('kimai.widgets', $config['widgets']); $container->setParameter('kimai.invoice.documents', $config['invoice']['documents']); + $container->setParameter('kimai.defaults', $config['defaults']); $this->createUserParameter($config, $container); $this->createTimesheetParameter($config, $container); diff --git a/src/DependencyInjection/Configuration.php b/src/DependencyInjection/Configuration.php index 00cda4af..57416f6e 100644 --- a/src/DependencyInjection/Configuration.php +++ b/src/DependencyInjection/Configuration.php @@ -39,6 +39,7 @@ class Configuration implements ConfigurationInterface ->append($this->getThemeNode()) ->append($this->getDashboardNode()) ->append($this->getWidgetsNode()) + ->append($this->getDefaultsNode()) ->end() ->end(); @@ -303,4 +304,26 @@ class Configuration implements ConfigurationInterface return $node; } + + protected function getDefaultsNode() + { + $builder = new TreeBuilder(); + $node = $builder->root('defaults'); + + $node + ->addDefaultsIfNotSet() + ->children() + ->arrayNode('customer') + ->addDefaultsIfNotSet() + ->children() + ->scalarNode('timezone')->defaultValue('Europe/Berlin')->end() + ->scalarNode('country')->defaultValue('DE')->end() + ->scalarNode('currency')->defaultValue('EUR')->end() + ->end() + ->end() + ->end() + ; + + return $node; + } } diff --git a/tests/Controller/Admin/CustomerControllerTest.php b/tests/Controller/Admin/CustomerControllerTest.php index 912ee638..ee8010e5 100644 --- a/tests/Controller/Admin/CustomerControllerTest.php +++ b/tests/Controller/Admin/CustomerControllerTest.php @@ -38,6 +38,16 @@ class CustomerControllerTest extends ControllerBaseTest $client = $this->getClientForAuthenticatedUser(User::ROLE_ADMIN); $this->assertAccessIsGranted($client, '/admin/customer/create'); $form = $client->getCrawler()->filter('form[name=customer_edit_form]')->form(); + + $kernel = self::bootKernel(); + $container = $kernel->getContainer(); + $defaults = $container->getParameter('kimai.defaults')['customer']; + + $editForm = $client->getCrawler()->filter('form[name=customer_edit_form]')->form(); + $this->assertEquals($defaults['country'], $editForm->get('customer_edit_form[country]')->getValue()); + $this->assertEquals($defaults['currency'], $editForm->get('customer_edit_form[currency]')->getValue()); + $this->assertEquals($defaults['timezone'], $editForm->get('customer_edit_form[timezone]')->getValue()); + $client->submit($form, [ 'customer_edit_form' => [ 'name' => 'Test Customer', diff --git a/var/docs/configurations.md b/var/docs/configurations.md index 1310513e..13ddb54c 100644 --- a/var/docs/configurations.md +++ b/var/docs/configurations.md @@ -232,3 +232,19 @@ kimai: days: ['saturday','sunday'] factor: 1.5 ``` + +## Forms (kimai.yaml) + +You can set some defaults for various forms within Kimai, to easify the creation process. + +### Customer creation + +Define the default values for a customer like this: +```yaml +kimai: + defaults: + customer: + timezone: Europe/London + country: GB + currency: GBP +``` \ No newline at end of file