Skip to content

Commit 5b33fa9

Browse files
author
Willem Stuursma-Ruwen
authored
Merge pull request #101 from RickJeroen/master
Added support for Free character field
2 parents 3ae21d3 + fb5d434 commit 5b33fa9

File tree

4 files changed

+50
-27
lines changed

4 files changed

+50
-27
lines changed

src/BaseTransactionLine.php

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,7 @@
66
use PhpTwinfield\Enums\LineType;
77
use PhpTwinfield\Transactions\TransactionLine;
88
use PhpTwinfield\Transactions\TransactionLineFields\CommentField;
9+
use PhpTwinfield\Transactions\TransactionLineFields\FreeCharField;
910
use PhpTwinfield\Transactions\TransactionLineFields\ThreeDimFields;
1011
use PhpTwinfield\Transactions\TransactionLineFields\ValueFields;
1112
use PhpTwinfield\Transactions\TransactionLineFields\VatTurnoverFields;
@@ -16,7 +17,6 @@
1617
* @todo $vatBaseValue Only if line type is detail. VAT amount in base currency.
1718
* @todo $vatRepValue Only if line type is detail. VAT amount in reporting currency.
1819
* @todo $destOffice Office code. Used for inter company transactions.
19-
* @todo $freeChar Free character field. Meaning differs per transaction type.
2020
* @todo $comment Comment set on the transaction line.
2121
* @todo $matches Contains matching information. Read-only attribute.
2222
*
@@ -28,6 +28,7 @@ abstract class BaseTransactionLine implements TransactionLine
2828
use ThreeDimFields;
2929
use VatTurnoverFields;
3030
use CommentField;
31+
use FreeCharField;
3132

3233
public const MATCHSTATUS_AVAILABLE = 'available';
3334
public const MATCHSTATUS_MATCHED = 'matched';

src/DomDocuments/TransactionsDocument.php

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -9,6 +9,7 @@
99
use PhpTwinfield\Transactions\TransactionFields\DueDateField;
1010
use PhpTwinfield\Transactions\TransactionFields\InvoiceNumberField;
1111
use PhpTwinfield\Transactions\TransactionFields\PaymentReferenceField;
12+
use PhpTwinfield\Transactions\TransactionLineFields\FreeCharField;
1213
use PhpTwinfield\Transactions\TransactionLineFields\PerformanceFields;
1314
use PhpTwinfield\Transactions\TransactionLineFields\VatTotalFields;
1415
use PhpTwinfield\Util;
@@ -147,6 +148,15 @@ public function addTransaction(BaseTransaction $transaction)
147148
}
148149
}
149150

151+
if (Util::objectUses(FreeCharField::class, $transactionLine)) {
152+
/** @var FreeCharField $transactionLine */
153+
$freeChar = $transactionLine->getFreeChar();
154+
if (!empty($freeChar)) {
155+
$freeCharElement = $this->createNodeWithTextContent('freechar', $freeChar);
156+
$lineElement->appendChild($freeCharElement);
157+
}
158+
}
159+
150160
if (Util::objectUses(VatTotalFields::class, $transactionLine)) {
151161
/** @var VatTotalFields $transactionLine */
152162
$vatTotal = $transactionLine->getVatTotal();

src/Transactions/BankTransactionLine/Base.php

Lines changed: 3 additions & 26 deletions
Original file line numberDiff line numberDiff line change
@@ -10,6 +10,7 @@
1010
use PhpTwinfield\Transactions\TransactionFields\InvoiceNumberField;
1111
use PhpTwinfield\Transactions\TransactionLine;
1212
use PhpTwinfield\Transactions\TransactionLineFields\CommentField;
13+
use PhpTwinfield\Transactions\TransactionLineFields\FreeCharField;
1314
use PhpTwinfield\Transactions\TransactionLineFields\ThreeDimFields;
1415
use PhpTwinfield\Transactions\TransactionLineFields\ValueFields;
1516
use Webmozart\Assert\Assert;
@@ -19,6 +20,7 @@ abstract class Base implements TransactionLine
1920
use ValueFields;
2021
use ThreeDimFields;
2122
use CommentField;
23+
use FreeCharField;
2224

2325
/**
2426
* Note that the field is not in the documentation but it is in all the examples.
@@ -48,13 +50,6 @@ abstract class Base implements TransactionLine
4850
*/
4951
private $destOffice;
5052

51-
/**
52-
* Free character field. (1 char)
53-
*
54-
* @var string
55-
*/
56-
private $freeChar;
57-
5853
/**
5954
* @var BankTransaction
6055
*/
@@ -136,24 +131,6 @@ public function setDestOffice(Office $destOffice)
136131
return $this;
137132
}
138133

139-
/**
140-
* @return string
141-
*/
142-
public function getFreeChar(): ?string
143-
{
144-
return $this->freeChar;
145-
}
146-
147-
/**
148-
* @param string $freeChar
149-
* @return $this
150-
*/
151-
public function setFreeChar(string $freeChar)
152-
{
153-
$this->freeChar = $freeChar;
154-
return $this;
155-
}
156-
157134
public function getId(): ?int
158135
{
159136
return $this->id;
@@ -185,4 +162,4 @@ protected function isIncomingTransactionType(): bool
185162
{
186163
return true;
187164
}
188-
}
165+
}
Lines changed: 35 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,35 @@
1+
<?php
2+
3+
namespace PhpTwinfield\Transactions\TransactionLineFields;
4+
5+
use Webmozart\Assert\Assert;
6+
7+
trait FreeCharField
8+
{
9+
/**
10+
* If line type is total and filled with N the sales invoice is excluded from direct debit runs done in Twinfield.
11+
*
12+
* @var string|null
13+
*/
14+
private $freeChar;
15+
16+
/**
17+
* @return string|null
18+
*/
19+
public function getFreeChar(): ?string
20+
{
21+
return $this->freeChar;
22+
}
23+
24+
/**
25+
* @param string|null $freeChar
26+
* @return $this
27+
*/
28+
public function setFreeChar(?string $freeChar): self
29+
{
30+
Assert::length($freeChar, 1);
31+
$this->freeChar = $freeChar;
32+
33+
return $this;
34+
}
35+
}

0 commit comments

Comments
 (0)