Skip to content

Commit

Permalink
Feature/notes (#7)
Browse files Browse the repository at this point in the history
* ✨ Allow adding notes to invoice

* ✅ Update test to include notes
  • Loading branch information
SimonJnsson authored Jan 29, 2024
1 parent 8bc7058 commit ba44f72
Show file tree
Hide file tree
Showing 4 changed files with 68 additions and 0 deletions.
26 changes: 26 additions & 0 deletions src/DTOs/Note.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,26 @@
<?php

namespace Morningtrain\Economic\DTOs;

use Morningtrain\Economic\Abstracts\Resource;

class Note extends Resource
{
public ?string $heading;

public ?string $textLine1;

public ?string $textLine2;

public static function new(
?string $heading = null,
?string $textLine1 = null,
?string $textLine2 = null,
): static {
return new static([
'heading' => $heading,
'textLine1' => $textLine1,
'textLine2' => $textLine2,
]);
}
}
1 change: 1 addition & 0 deletions src/Resources/Invoice/DraftInvoice.php
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,7 @@ public function create()
'date' => $this->date->format('Y-m-d'),
'recipient' => $this->recipient,
'lines' => $this->lines ?? null,
'notes' => $this->notes ?? null,
]);
}

Expand Down
5 changes: 5 additions & 0 deletions src/Resources/Invoice/Invoice.php
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@

use DateTime;
use Morningtrain\Economic\Abstracts\Resource;
use Morningtrain\Economic\DTOs\Note;
use Morningtrain\Economic\DTOs\Recipient;
use Morningtrain\Economic\Resources\Currency;
use Morningtrain\Economic\Resources\Customer;
Expand Down Expand Up @@ -33,13 +34,16 @@ class Invoice extends Resource

public Recipient $recipient;

public ?Note $notes;

public static function new(
Customer|int $customer,
Layout|int $layout,
Currency|string $currency,
PaymentTerm|int $paymentTerms,
DateTime $date,
Recipient $recipient,
?Note $notes = null,
): static {
return new static([
'customer' => $customer,
Expand All @@ -48,6 +52,7 @@ public static function new(
'paymentTerms' => $paymentTerms,
'date' => $date,
'recipient' => $recipient,
'notes' => $notes,
]);
}
}
36 changes: 36 additions & 0 deletions tests/Unit/InvoiceTest.php
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
<?php

use Morningtrain\Economic\Classes\EconomicResponse;
use Morningtrain\Economic\DTOs\Note;
use Morningtrain\Economic\DTOs\Recipient;
use Morningtrain\Economic\Enums\PaymentTermsType;
use Morningtrain\Economic\Resources\Invoice\BookedInvoice;
Expand Down Expand Up @@ -43,6 +44,11 @@
'unitNetPrice' => 500,
],
],
'notes' => [
'heading' => 'Heading',
'textLine1' => 'Text line 1',
'textLine2' => 'Text line 2',
],
];
})
->once()
Expand All @@ -68,6 +74,11 @@
Recipient::new(
'John Doe',
new VatZone(1),
),
Note::new(
heading: 'Heading',
textLine1: 'Text line 1',
textLine2: 'Text line 2'
)
)
->addLine(ProductLine::new(
Expand Down Expand Up @@ -221,3 +232,28 @@
)
->create();
});

it('can add notes', function () {
$invoice = DraftInvoice::new(
1,
1,
'DKK',
1,
DateTime::createFromFormat('Y-m-d', '2021-01-01'),
new Recipient(
'John Doe',
new VatZone(1),
),
Note::new(
heading: 'Heading',
textLine1: 'Text line 1',
textLine2: 'Text line 2'
)
);

expect($invoice->notes)
->toBeInstanceOf(Note::class)
->heading->toBe('Heading')
->textLine1->toBe('Text line 1')
->textLine2->toBe('Text line 2');
});

0 comments on commit ba44f72

Please sign in to comment.