Skip to content

Commit

Permalink
1635: Updated invoice description
Browse files Browse the repository at this point in the history
  • Loading branch information
rimi-itk committed Jun 13, 2024
1 parent be35f38 commit 5224632
Show file tree
Hide file tree
Showing 4 changed files with 24 additions and 0 deletions.
3 changes: 3 additions & 0 deletions .env
Original file line number Diff line number Diff line change
Expand Up @@ -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
1 change: 1 addition & 0 deletions config/services.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -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)%'
8 changes: 8 additions & 0 deletions src/Service/InvoiceHelper.php
Original file line number Diff line number Diff line change
Expand Up @@ -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.
*
Expand Down Expand Up @@ -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);
}
}
12 changes: 12 additions & 0 deletions src/Service/ProjectBillingService.php
Original file line number Diff line number Diff line change
Expand Up @@ -305,6 +305,18 @@ public function createProjectBilling(int $projectBillingId): void
continue;
}

if ($this->invoiceEntryHelper->getSetInvoiceDescriptionFromEntries()) {
$description = array_merge(
[
$issue->getName(),

Check failure on line 311 in src/Service/ProjectBillingService.php

View workflow job for this annotation

GitHub Actions / Psalm static analysis (8.1)

PossiblyUndefinedVariable

src/Service/ProjectBillingService.php:311:25: PossiblyUndefinedVariable: Possibly undefined variable $issue, first seen on line 147 (see https://psalm.dev/018)
'Ordrelinjer:',
],
$invoice->getInvoiceEntries()->map(static fn (InvoiceEntry $entry) => preg_replace('/^[A-Z0-9-]+: /', '', $entry->getDescription()))->toArray()

Check failure on line 314 in src/Service/ProjectBillingService.php

View workflow job for this annotation

GitHub Actions / Psalm static analysis (8.1)

PossiblyNullArgument

src/Service/ProjectBillingService.php:314:127: PossiblyNullArgument: Argument 3 of preg_replace cannot be null, possibly null value provided (see https://psalm.dev/078)
);

$invoice->setDescription(join(' ', $description));
}

$projectBilling->addInvoice($invoice);
$this->entityManager->persist($invoice);
}
Expand Down

0 comments on commit 5224632

Please sign in to comment.