added basic invoice rendering #97 #93 (#99)

This commit is contained in:
Kevin Papst
2018-01-21 22:50:46 +01:00
committed by GitHub
parent 9a161b8fd9
commit 4cbc5391c0
73 changed files with 2986 additions and 918 deletions

View File

@@ -12,17 +12,23 @@
namespace App\DataFixtures;
use App\Entity\User;
use App\Entity\UserPreference;
use Doctrine\Bundle\FixturesBundle\Fixture;
use Doctrine\Common\Persistence\ObjectManager;
use Symfony\Component\Security\Core\Encoder\UserPasswordEncoderInterface;
/**
* Sample data to load in the database when running tests or for development
* Defines the sample data to load in the database when running the unit and
* functional tests or while development.
*
* Execute this command to load the data:
* $ php bin/console doctrine:fixtures:load
*
* @author Kevin Papst <kevin@kevinpapst.de>
*/
class AppFixtures extends Fixture
{
use FixturesTrait;
const DEFAULT_PASSWORD = 'kitten';
@@ -31,6 +37,10 @@ class AppFixtures extends Fixture
*/
private $encoder;
/**
* AppFixtures constructor.
* @param UserPasswordEncoderInterface $encoder
*/
public function __construct(UserPasswordEncoderInterface $encoder)
{
$this->encoder = $encoder;
@@ -44,117 +54,53 @@ class AppFixtures extends Fixture
$this->loadUsers($manager);
}
/**
* @param ObjectManager $manager
*/
private function loadUsers(ObjectManager $manager)
{
$passwordEncoder = $this->encoder;
$claraCustomer = new User();
$claraCustomer
->setAlias('Clara Haynes')
->setTitle('CFO')
->setUsername('clara_customer')
->setEmail('clara_customer@example.com')
->setRoles(['ROLE_CUSTOMER'])
->setAvatar('https://www.gravatar.com/avatar/00000000000000000000000000000000?d=monsterid&f=y')
->setPassword($passwordEncoder->encodePassword($claraCustomer, self::DEFAULT_PASSWORD))
;
$manager->persist($claraCustomer);
foreach ($this->getUserDefinition() as $userData) {
$user = new User();
$user
->setAlias($userData[0])
->setTitle($userData[1])
->setUsername($userData[2])
->setEmail($userData[3])
->setRoles([$userData[4]])
->setAvatar($userData[5])
->setActive($userData[6])
->setPassword($passwordEncoder->encodePassword($user, self::DEFAULT_PASSWORD))
;
$johnUser = new User();
$johnUser
->setAlias('John Doe')
->setTitle('Developer')
->setUsername('john_user')
->setEmail('john_user@example.com')
->setRoles(['ROLE_USER'])
->setAvatar('https://www.gravatar.com/avatar/00000000000000000000000000000000?d=retro&f=y')
->setPassword($passwordEncoder->encodePassword($claraCustomer, self::DEFAULT_PASSWORD))
;
$manager->persist($johnUser);
$preference = new UserPreference();
$preference->setName(UserPreference::HOURLY_RATE);
$preference->setValue(rand(0, 100));
$preference->setUser($user);
$user->setPreferences([$preference]);
$deactiveUser = new User();
$deactiveUser
->setAlias('Chris Deactive')
->setTitle('Developer (left company)')
->setUsername('chris_user')
->setEmail('chris_user@example.com')
->setRoles(['ROLE_USER'])
->setAvatar('https://www.gravatar.com/avatar/00000000000000000000000000000000?d=retro&f=y')
->setPassword($passwordEncoder->encodePassword($claraCustomer, self::DEFAULT_PASSWORD))
// inactive for testing user login and UI
->setActive(false)
;
$manager->persist($deactiveUser);
$tonyTeamlead = new User();
$tonyTeamlead
->setAlias('Tony Maier')
->setTitle('Head of Development')
->setUsername('tony_teamlead')
->setEmail('tony_teamlead@example.com')
->setRoles(['ROLE_TEAMLEAD'])
->setAvatar('https://en.gravatar.com/userimage/3533186/bf2163b1dd23f3107a028af0195624e9.jpeg')
->setPassword($passwordEncoder->encodePassword($claraCustomer, self::DEFAULT_PASSWORD))
;
$manager->persist($tonyTeamlead);
$annaAdmin = new User();
$annaAdmin
->setAlias('Anna Smith')
->setTitle('Administrator')
->setUsername('anna_admin')
->setEmail('anna_admin@example.com')
->setRoles(['ROLE_ADMIN'])
// no avatar to test default image!
->setPassword($passwordEncoder->encodePassword($claraCustomer, self::DEFAULT_PASSWORD))
;
$manager->persist($annaAdmin);
$susanSuper = new User();
$susanSuper
// no alias to test the username macros
->setTitle('Super Administrator')
->setUsername('susan_super')
->setEmail('susan_super@example.com')
->setRoles(['ROLE_SUPER_ADMIN'])
->setAvatar('/bundles/avanzuadmintheme/img/avatar.png')
->setPassword($passwordEncoder->encodePassword($claraCustomer, self::DEFAULT_PASSWORD))
;
$manager->persist($susanSuper);
$manager->persist($user);
}
$manager->flush();
}
protected function getPhrases()
/**
* @return []
*/
protected function getUserDefinition()
{
return [
'Lorem ipsum dolor sit amet consectetur adipiscing elit',
'Pellentesque vitae velit ex',
'Mauris dapibus risus quis suscipit vulputate',
'Eros diam egestas libero eu vulputate risus',
'In hac habitasse platea dictumst',
'Morbi tempus commodo mattis',
'Ut suscipit posuere justo at vulputate',
'Ut eleifend mauris et risus ultrices egestas',
'Aliquam sodales odio id eleifend tristique',
'Urna nisl sollicitudin id varius orci quam id turpis',
'Nulla porta lobortis ligula vel egestas',
'Curabitur aliquam euismod dolor non ornare',
'Sed varius a risus eget aliquam',
'Nunc viverra elit ac laoreet suscipit',
'Pellentesque et sapien pulvinar consectetur',
['Clara Haynes', 'CFO', 'clara_customer', 'clara_customer@example.com', 'ROLE_CUSTOMER', 'https://www.gravatar.com/avatar/00000000000000000000000000000000?d=monsterid&f=y', true],
['John Doe', 'Developer', 'john_user', 'john_user@example.com', 'ROLE_USER', 'https://www.gravatar.com/avatar/00000000000000000000000000000000?d=retro&f=y', true],
// inactive user to test login
['Chris Deactive', 'Developer (left company)', 'chris_user', 'chris_user@example.com', 'ROLE_USER', 'https://www.gravatar.com/avatar/00000000000000000000000000000000?d=retro&f=y', false],
['Tony Maier', 'Head of Development', 'tony_teamlead', 'tony_teamlead@example.com', 'ROLE_TEAMLEAD', 'https://en.gravatar.com/userimage/3533186/bf2163b1dd23f3107a028af0195624e9.jpeg', true],
// no avatar to test default image macro
['Anna Smith', 'Administrator', 'anna_admin', 'anna_admin@example.com', 'ROLE_ADMIN', null, true],
// no alias to test twig username macro
[null, 'Super Administrator', 'susan_super', 'susan_super@example.com', 'ROLE_SUPER_ADMIN', '/bundles/avanzuadmintheme/img/avatar.png', true]
];
}
protected function getRandomPhrase()
{
return $this->getRandomPostTitle();
}
private function getRandomPostTitle()
{
$titles = $this->getPhrases();
return $titles[array_rand($titles)];
}
}

View File

@@ -0,0 +1,53 @@
<?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\DataFixtures;
/**
* Defines reusable sample data.
*
* @author Kevin Papst <kevin@kevinpapst.de>
*/
trait FixturesTrait
{
/**
* @return string[]
*/
protected function getPhrases()
{
return [
'Lorem ipsum dolor sit amet consectetur adipiscing elit',
'Pellentesque vitae velit ex',
'Mauris dapibus risus quis suscipit vulputate',
'Eros diam egestas libero eu vulputate risus',
'In hac habitasse platea dictumst',
'Morbi tempus commodo mattis',
'Ut suscipit posuere justo at vulputate',
'Ut eleifend mauris et risus ultrices egestas',
'Aliquam sodales odio id eleifend tristique',
'Urna nisl sollicitudin id varius orci quam id turpis',
'Nulla porta lobortis ligula vel egestas',
'Curabitur aliquam euismod dolor non ornare',
'Sed varius a risus eget aliquam',
'Nunc viverra elit ac laoreet suscipit',
'Pellentesque et sapien pulvinar consectetur',
];
}
/**
* @return string
*/
protected function getRandomPhrase()
{
$phrases = $this->getPhrases();
return $phrases[array_rand($phrases)];
}
}

View File

@@ -0,0 +1,65 @@
<?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\DataFixtures;
use App\Entity\InvoiceTemplate;
use Doctrine\Bundle\FixturesBundle\Fixture;
use Doctrine\Common\Persistence\ObjectManager;
/**
* Defines the sample data to load in the database when running the unit and
* functional tests or while development.
*
* Execute this command to load the data:
* $ php bin/console doctrine:fixtures:load
*
* @author Kevin Papst <kevin@kevinpapst.de>
*/
class InvoiceFixtures extends Fixture
{
/**
* {@inheritdoc}
*/
public function load(ObjectManager $manager)
{
$this->loadInvoiceTemplates($manager);
}
/**
* @param ObjectManager $manager
*/
private function loadInvoiceTemplates(ObjectManager $manager)
{
$template = new InvoiceTemplate();
$template
->setName('Invoice')
->setTitle('Your company name')
->setCompany('Kimai, Inc.')
->setVat(19)
->setDueDays(14)
->setPaymentTerms(
'I would like to thank you for your confidence and will gladly be there for you in the future.
Please transfer the total amount within 14 days to the given account and use the invoice number as reference.'
)
->setAddress(
'795 Folsom Ave, Suite 600
San Francisco, CA 94107
Phone: (804) 123-5432
Email: info@almasaeedstudio.com'
)
;
$manager->persist($template);
$manager->flush();
}
}

View File

@@ -16,18 +16,22 @@ use App\Entity\Activity;
use App\Entity\Customer;
use App\Entity\Project;
use App\Entity\Timesheet;
use Doctrine\Bundle\FixturesBundle\Fixture;
use Doctrine\Common\Persistence\ObjectManager;
/**
* Defines the sample data to load in the database when running the unit and
* functional tests. Execute this command to load the data:
* functional tests or while development.
*
* $ php bin/console doctrine:fixtures:load
* Execute this command to load the data:
* $ php bin/console doctrine:fixtures:load
*
* @author Kevin Papst <kevin@kevinpapst.de>
*/
class TimesheetFixtures extends AppFixtures
class TimesheetFixtures extends Fixture
{
use FixturesTrait;
const AMOUNT_TIMESHEET = 5000; // timesheet entries total
const RATE_MIN = 10; // minimum rate for one hour
const RATE_MAX = 80; // maximum rate for one hour
@@ -185,11 +189,11 @@ class TimesheetFixtures extends AppFixtures
$entry = new Customer();
$entry
->setCurrency($this->getRandomCurrency())
->setVat(rand(0, 30))
->setName($customerName . ($visible ? '' : '.'))
->setAddress($this->getRandomLocation())
->setComment($this->getRandomPhrase())
->setVisible($visible)
->setNumber('C0815-42-' . $i)
->setCountry('DE') // TODO randomize country ?
->setTimezone($allTimezones[rand(1, $amountTimezone)]);