From 5224632fbf366dde98ebbd4acb432cd5a9f3ad0e Mon Sep 17 00:00:00 2001 From: Mikkel Ricky Date: Thu, 13 Jun 2024 14:45:11 +0200 Subject: [PATCH] 1635: Updated invoice description --- .env | 3 +++ config/services.yaml | 1 + src/Service/InvoiceHelper.php | 8 ++++++++ src/Service/ProjectBillingService.php | 12 ++++++++++++ 4 files changed, 24 insertions(+) diff --git a/.env b/.env index 88e541be..845f2a4e 100644 --- a/.env +++ b/.env @@ -96,3 +96,6 @@ INVOICE_ENTRY_ACCOUNTS='{ # If true, project billing will generate one invoice per issue per client. # Otherwise, all issues will be added to a single invoice per client. INVOICE_ONE_INVOICE_PER_ISSUE=false + +# If true, the invoice description is set based on issue name andinvoice entries. +SET_INVOICE_DESCRIPTION_FROM_ENTRIES=false diff --git a/config/services.yaml b/config/services.yaml index e1d726ca..5097783e 100644 --- a/config/services.yaml +++ b/config/services.yaml @@ -59,3 +59,4 @@ services: $options: accounts: '%env(json:INVOICE_ENTRY_ACCOUNTS)%' one_invoice_per_issue: '%env(bool:INVOICE_ONE_INVOICE_PER_ISSUE)%' + set_invoice_description_from_entries: '%env(bool:SET_INVOICE_DESCRIPTION_FROM_ENTRIES)%' diff --git a/src/Service/InvoiceHelper.php b/src/Service/InvoiceHelper.php index 37b6c0e8..9ed3944f 100644 --- a/src/Service/InvoiceHelper.php +++ b/src/Service/InvoiceHelper.php @@ -22,6 +22,11 @@ public function getOneInvoicePerIssue() return $this->options['one_invoice_per_issue']; } + public function getSetInvoiceDescriptionFromEntries() + { + return $this->options['set_invoice_description_from_entries']; + } + /** * Get all configured accounts. * @@ -189,6 +194,9 @@ private function resolveOptions(array $options): array ->setDefault('one_invoice_per_issue', false) ->setAllowedTypes('one_invoice_per_issue', 'bool') + ->setDefault('set_invoice_description_from_entries', false) + ->setAllowedTypes('set_invoice_description_from_entries', 'bool') + ->resolve($options); } } diff --git a/src/Service/ProjectBillingService.php b/src/Service/ProjectBillingService.php index 04baa5ca..b2b437a2 100644 --- a/src/Service/ProjectBillingService.php +++ b/src/Service/ProjectBillingService.php @@ -305,6 +305,18 @@ public function createProjectBilling(int $projectBillingId): void continue; } + if ($this->invoiceEntryHelper->getSetInvoiceDescriptionFromEntries()) { + $description = array_merge( + [ + $issue->getName(), + 'Ordrelinjer:', + ], + $invoice->getInvoiceEntries()->map(static fn (InvoiceEntry $entry) => preg_replace('/^[A-Z0-9-]+: /', '', $entry->getDescription()))->toArray() + ); + + $invoice->setDescription(join(' ', $description)); + } + $projectBilling->addInvoice($invoice); $this->entityManager->persist($invoice); }