added pdf template and other invoice improvements (#1693)

This commit is contained in:
Kevin Papst
2020-05-10 16:19:59 +02:00
committed by GitHub
parent 4e1ffedc20
commit e3749c8e8f
45 changed files with 561 additions and 89 deletions

View File

@@ -16,6 +16,7 @@ use App\Entity\Project;
use App\Invoice\ServiceInvoice;
use App\Repository\CustomerRepository;
use App\Repository\InvoiceTemplateRepository;
use App\Repository\ProjectRepository;
use App\Repository\Query\InvoiceQuery;
use App\Repository\Query\TimesheetQuery;
use App\Repository\TimesheetRepository;
@@ -46,6 +47,10 @@ class InvoiceCreateCommand extends Command
* @var CustomerRepository
*/
private $customerRepository;
/**
* @var ProjectRepository
*/
private $projectRepository;
/**
* @var InvoiceTemplateRepository
*/
@@ -67,6 +72,7 @@ class InvoiceCreateCommand extends Command
ServiceInvoice $serviceInvoice,
TimesheetRepository $timesheetRepository,
CustomerRepository $customerRepository,
ProjectRepository $projectRepository,
InvoiceTemplateRepository $invoiceTemplateRepository,
UserRepository $userRepository,
EventDispatcherInterface $eventDispatcher
@@ -74,6 +80,7 @@ class InvoiceCreateCommand extends Command
$this->serviceInvoice = $serviceInvoice;
$this->timesheetRepository = $timesheetRepository;
$this->customerRepository = $customerRepository;
$this->projectRepository = $projectRepository;
$this->invoiceTemplateRepository = $invoiceTemplateRepository;
$this->userRepository = $userRepository;
$this->eventDispatcher = $eventDispatcher;
@@ -94,6 +101,7 @@ class InvoiceCreateCommand extends Command
->addOption('end', null, InputOption::VALUE_OPTIONAL, 'End date (format: 2020-01-31, default: end of the month)', null)
->addOption('timezone', null, InputOption::VALUE_OPTIONAL, 'Timezone for start and end date query', date_default_timezone_get())
->addOption('customer', null, InputOption::VALUE_OPTIONAL, 'Comma separated list of customer IDs', null)
->addOption('project', null, InputOption::VALUE_OPTIONAL, 'Comma separated list of project IDs', null)
->addOption('by-customer', null, InputOption::VALUE_NONE, 'If set, one invoice for each active customer in the given timerange is created')
->addOption('by-project', null, InputOption::VALUE_NONE, 'If set, one invoice for each active project in the given timerange is created')
->addOption('set-exported', null, InputOption::VALUE_NONE, 'Whether the invoice items should be marked as exported')
@@ -168,8 +176,9 @@ class InvoiceCreateCommand extends Command
}
$customersIDs = $input->getOption('customer');
if (!$byActiveCustomer && !$byActiveProject && empty($customersIDs)) {
$io->error('Could not determine generation mode, you need to set one of: customer, by-customer, by-project');
$projectIDs = $input->getOption('project');
if (!$byActiveCustomer && !$byActiveProject && empty($customersIDs) && empty($projectIDs)) {
$io->error('Could not determine generation mode, you need to set one of: customer, project, by-customer, by-project');
return 1;
}
@@ -235,15 +244,15 @@ class InvoiceCreateCommand extends Command
$defaultQuery->setCurrentUser($user);
$defaultQuery->setSearchTerm($searchTerm);
$defaultQuery->setMarkAsExported($markAsExported);
$defaultQuery->setState($exportedFilter);
$defaultQuery->setExported($exportedFilter);
/** @var Invoice[] $invoices */
$invoices = [];
/** @var Customer[] $customers */
$customers = [];
if (!empty($customersIDs)) {
/** @var Customer[] $customers */
$customers = [];
$customersIDs = explode(',', $customersIDs);
foreach ($customersIDs as $id) {
$tmp = $this->customerRepository->find($id);
@@ -255,6 +264,21 @@ class InvoiceCreateCommand extends Command
$customers[] = $tmp;
}
$invoices = $this->createInvoicesForCustomer($customers, $defaultQuery, $input, $output);
} elseif (!empty($projectIDs)) {
/** @var Project[] $projects */
$projects = [];
$projectIDs = explode(',', $projectIDs);
foreach ($projectIDs as $id) {
$tmp = $this->projectRepository->find($id);
if (null === $tmp) {
$io->error('Unknown project ID: ' . $id);
return 1;
}
$projects[] = $tmp;
}
$invoices = $this->createInvoicesForProjects($projects, $defaultQuery, $input, $output);
} elseif ($byActiveCustomer) {
$customers = $this->getActiveCustomers($start, $end);
$invoices = $this->createInvoicesForCustomer($customers, $defaultQuery, $input, $output);