Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
22 changes: 22 additions & 0 deletions readme.md
Original file line number Diff line number Diff line change
Expand Up @@ -328,6 +328,28 @@ support for another resource.

* [Twinfield API Documentation site](https://accounting.twinfield.com/webservices/documentation/)

## Development

Clone the repository:

```bash
git clone [email protected]:php-twinfield/twinfield.git
# navigate to cloned repository
cd twinfield
```

To set up the development environment, run:

```bash
composer install
```

To run the tests, use:

```bash
vendor/bin/phpunit
```


## Authors

Expand Down
22 changes: 22 additions & 0 deletions src/Customer.php
Original file line number Diff line number Diff line change
Expand Up @@ -58,6 +58,7 @@ class Customer
private $creditManagement;
private $addresses = array();
private $banks = array();
private $postingRules = array();
private $groups;

public function getCode()
Expand Down Expand Up @@ -395,6 +396,27 @@ public function removeBank($index)
}
}

public function getPostingRules()
{
return $this->postingRules;
}

public function addPostingRule(CustomerPostingRule $postingrule)
{
$this->postingRules[$postingrule->getID()] = $postingrule;
return $this;
}

public function removePostingRule($index)
{
if (array_key_exists($index, $this->postingRules)) {
unset($this->postingRules[$index]);
return true;
} else {
return false;
}
}

public function getGroups()
{
return $this->groups;
Expand Down
92 changes: 92 additions & 0 deletions src/CustomerPostingRule.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,92 @@
<?php

namespace PhpTwinfield;

use Money\Currency;

class CustomerPostingRule
{
private $id;
private $status;
private $currency;
private $amount;
private $description;
private $lines = [];

public function getID()
{
return $this->id;
}

public function setID($id): self
{
$this->id = $id;
return $this;
}

public function getStatus()
{
return $this->status;
}

public function setStatus($status): self
{
$this->status = $status;
return $this;
}

public function getCurrency()
{
return $this->currency;
}

public function setCurrency(?Currency $currency): self
{
$this->currency = $currency;
return $this;
}

public function getAmount()
{
return $this->amount;
}

public function setAmount($amount): self
{
$this->amount = $amount;
return $this;
}

public function getDescription()
{
return $this->description;
}

public function setDescription($description): self
{
$this->description = $description;
return $this;
}

public function getLines()
{
return $this->lines;
}

public function addLine($line): self
{
$this->lines[] = $line;
return $this;
}

public function removeLine($index): bool
{
if (array_key_exists($index, $this->lines)) {
unset($this->lines[$index]);
return true;
} else {
return false;
}
}

}
91 changes: 91 additions & 0 deletions src/Customers/Line.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,91 @@
<?php

namespace PhpTwinfield\Customers;

class Line
{
private $office;
private $dimension1;
private $dimension2;
private $dimension3;
private $ratio;
private $vatCode;
private $description;

public function getOffice()
{
return $this->office;
}

public function setOffice($office): self
{
$this->office = $office;
return $this;
}

public function getDimension1()
{
return $this->dimension1;
}

public function setDimension1($dimension1): self
{
$this->dimension1 = $dimension1;
return $this;
}

public function getDimension2()
{
return $this->dimension2;
}

public function setDimension2($dimension2): self
{
$this->dimension2 = $dimension2;
return $this;
}

public function getDimension3()
{
return $this->dimension3;
}

public function setDimension3($dimension3): self
{
$this->dimension3 = $dimension3;
return $this;
}

public function getRatio()
{
return $this->ratio;
}

public function setRatio($ratio): self
{
$this->ratio = $ratio;
return $this;
}

public function getVatCode()
{
return $this->vatCode;
}

public function setVatCode($vatCode): self
{
$this->vatCode = $vatCode;
return $this;
}

public function getDescription()
{
return $this->description;
}

public function setDescription($description): self
{
$this->description = $description;
return $this;
}
}
67 changes: 67 additions & 0 deletions src/DomDocuments/CustomersDocument.php
Original file line number Diff line number Diff line change
Expand Up @@ -309,6 +309,73 @@ public function addCustomer(Customer $customer): void
}
}

$postingRules = $customer->getPostingRules();
if (!empty($postingRules)) {
$postingrulesElement = $this->createElement('postingrules');
$customerEl->appendChild($postingrulesElement);

foreach ($postingRules as $postingRule) {
$postingRuleElement = $this->createElement('postingrule');
$postingrulesElement->appendChild($postingRuleElement);

$postingRuleElement->setAttribute("id", $postingRule->getID());
$postingRuleElement->setAttribute("status", $postingRule->getStatus());

$postingRuleTags = array(
'currency' => 'getCurrency',
'amount' => 'getAmount',
'description' => 'getDescription',
);

foreach ($postingRuleTags as $tag => $method) {

// Make the text node for the method value
$node = $this->createTextNode($postingRule->$method() ?? '');

// Make the actual element and assign the text node
$element = $this->createElement($tag);
$element->appendChild($node);

// Add the completed element
$postingRuleElement->appendChild($element);
}

$lines = $postingRule->getLines();
if (!empty($lines)) {
$linesElement = $this->createElement('lines');
$postingRuleElement->appendChild($linesElement);

foreach ($lines as $line) {
$lineElement = $this->createElement('line');
$linesElement->appendChild($lineElement);

$lineTags = array(
'office' => 'getOffice',
'dimension1' => 'getDimension1',
'dimension2' => 'getDimension2',
'dimension3' => 'getDimension3',
'ratio' => 'getRatio',
'vatcode' => 'getVatCode',
'description' => 'getDescription',
);

foreach ($lineTags as $tag => $method) {

// Make the text node for the method value
$node = $this->createTextNode($line->$method() ?? '');

// Make the actual element and assign the text node
$element = $this->createElement($tag);
$element->appendChild($node);

// Add the completed element
$lineElement->appendChild($element);
}
}
}
}
}

$this->rootElement->appendChild($customerEl);
}
}
12 changes: 12 additions & 0 deletions tests/IntegrationTests/CustomerIntegrationTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -2,11 +2,14 @@

namespace PhpTwinfield\IntegrationTests;

use Money\Currency;
use PhpTwinfield\ApiConnectors\CustomerApiConnector;
use PhpTwinfield\Customer;
use PhpTwinfield\CustomerAddress;
use PhpTwinfield\CustomerBank;
use PhpTwinfield\CustomerCollectMandate;
use PhpTwinfield\CustomerPostingRule;
use PhpTwinfield\Customers\Line;
use PhpTwinfield\DomDocuments\CustomersDocument;
use PhpTwinfield\Enums\CollectionSchema;
use PhpTwinfield\Enums\MeansOfPayment;
Expand Down Expand Up @@ -218,6 +221,15 @@ public function testSendCustomerWorks()

$customer->setCollectionSchema(CollectionSchema::CORE());

$rule = new CustomerPostingRule();
$rule->setID(1);
$rule->setStatus('active');
$rule->setCurrency(new Currency('EUR'));
$line = new Line();
$line->setDimension1(1300);
$rule->addLine($line);
$customer->addPostingRule($rule);

$this->processXmlService
->expects($this->once())
->method("sendDocument")
Expand Down
18 changes: 18 additions & 0 deletions tests/IntegrationTests/resources/customerSendRequest.xml
Original file line number Diff line number Diff line change
Expand Up @@ -54,5 +54,23 @@
</address>
</bank>
</banks>
<postingrules>
<postingrule id="1" status="active">
<currency>EUR</currency>
<amount></amount>
<description></description>
<lines>
<line>
<office></office>
<dimension1>1300</dimension1>
<dimension2></dimension2>
<dimension3></dimension3>
<ratio></ratio>
<vatcode></vatcode>
<description></description>
</line>
</lines>
</postingrule>
</postingrules>
</dimension>
</dimensions>