Skip to content

Commit

Permalink
JE-403: Added check for invoice entries with amount 0 when putting in…
Browse files Browse the repository at this point in the history
…voice on record.
  • Loading branch information
tuj committed Dec 21, 2023
1 parent a4aca46 commit 0c1e29f
Show file tree
Hide file tree
Showing 3 changed files with 10 additions and 7 deletions.
1 change: 1 addition & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,7 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0

* Changed InvoiceEntry material number and account to be set only at the invoice level.
* Added default account to invoices from environment variable.
* Added check for invoice entries with amount 0 when putting invoice on record.

## [1.1.2]

Expand Down
14 changes: 9 additions & 5 deletions src/Controller/InvoiceController.php
Original file line number Diff line number Diff line change
Expand Up @@ -109,7 +109,6 @@ public function edit(Request $request, Invoice $invoice, InvoiceRepository $invo
'attr' => [
'class' => 'form-element',
'data-choices-target' => 'choices',
'data-account-selector-target' => 'field',
],
'choices' => $paidByAccountChoices,
'help' => 'invoices.payer_account_helptext',
Expand All @@ -123,7 +122,6 @@ public function edit(Request $request, Invoice $invoice, InvoiceRepository $invo
'attr' => [
'class' => 'form-element',
'data-choices-target' => 'choices',
'data-account-selector-target' => 'field',
],
'choices' => $defaultReceiverAccountChoices,
'help' => 'invoices.default_receiver_account_helptext',
Expand Down Expand Up @@ -213,7 +211,7 @@ public function delete(Request $request, Invoice $invoice, InvoiceRepository $in
* @throws \Exception
*/
#[Route('/{id}/record', name: 'app_invoices_record', methods: ['GET', 'POST'])]
public function record(Request $request, Invoice $invoice, InvoiceRepository $invoiceRepository, BillingService $billingService): Response
public function record(Request $request, Invoice $invoice, BillingService $billingService): Response
{
$recordData = new ConfirmData();
$form = $this->createForm(InvoiceRecordType::class, $recordData);
Expand All @@ -226,6 +224,12 @@ public function record(Request $request, Invoice $invoice, InvoiceRepository $in
throw new HttpException(400, 'Invoice is a part of a project billing, cannot be put on record.');
}

foreach ($invoice->getInvoiceEntries() as $invoiceEntry) {
if (empty($invoiceEntry->getAmount())) {
throw new HttpException(400, 'Invoice cannot be put on record, when it contains invoice entries where amount is not set.');
}
}

if ($recordData->confirmed) {
$billingService->recordInvoice($invoice);
}
Expand All @@ -246,7 +250,7 @@ public function record(Request $request, Invoice $invoice, InvoiceRepository $in
* @throws \PhpOffice\PhpSpreadsheet\Writer\Exception
*/
#[Route('/{id}/show-export', name: 'app_invoices_show_export', methods: ['GET'])]
public function showExport(Request $request, Invoice $invoice, InvoiceRepository $invoiceRepository, BillingService $billingService): Response
public function showExport(Invoice $invoice, BillingService $billingService): Response
{
$spreadsheet = $billingService->exportInvoicesToSpreadsheet([$invoice->getId()]);

Expand Down Expand Up @@ -286,7 +290,7 @@ public function showExport(Request $request, Invoice $invoice, InvoiceRepository
* @throws \PhpOffice\PhpSpreadsheet\Writer\Exception
*/
#[Route('/{id}/export', name: 'app_invoices_export', methods: ['GET'])]
public function export(Request $request, Invoice $invoice, InvoiceRepository $invoiceRepository, BillingService $billingService): Response
public function export(Invoice $invoice, InvoiceRepository $invoiceRepository, BillingService $billingService): Response
{
if (!$invoice->isRecorded()) {
throw new HttpException(400, 'Invoice cannot be exported before it is on record.');
Expand Down
2 changes: 0 additions & 2 deletions src/Form/InvoiceType.php
Original file line number Diff line number Diff line change
Expand Up @@ -47,7 +47,6 @@ public function buildForm(FormBuilderInterface $builder, array $options): void
'row_attr' => ['class' => 'form-row form-choices'],
'attr' => [
'class' => 'form-element',
'data-account-selector-target' => 'field',
],
'help' => 'invoices.payer_account_helptext',
])
Expand All @@ -58,7 +57,6 @@ public function buildForm(FormBuilderInterface $builder, array $options): void
'row_attr' => ['class' => 'form-row form-choices'],
'attr' => [
'class' => 'form-element',
'data-account-selector-target' => 'field',
],
'help' => 'invoices.default_receiver_account_helptext',
])
Expand Down

0 comments on commit 0c1e29f

Please sign in to comment.