Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Allow meansofpayment to be set on suppliers #210

Merged
merged 2 commits into from
May 23, 2022
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
6 changes: 6 additions & 0 deletions src/DomDocuments/SuppliersDocument.php
Original file line number Diff line number Diff line change
Expand Up @@ -116,6 +116,12 @@ public function addSupplier(Supplier $supplier)
// Add the full element
$financialElement->appendChild($element);
}
$meansOfPayment = $supplier->getMeansOfPayment();

if ($meansOfPayment !== null) {
$meansOfPaymentElement = $this->createElement('meansofpayment', $meansOfPayment->getValue());
$financialElement->appendChild($meansOfPaymentElement);
}
}


Expand Down
8 changes: 8 additions & 0 deletions src/Mappers/SupplierMapper.php
Original file line number Diff line number Diff line change
@@ -1,10 +1,12 @@
<?php
namespace PhpTwinfield\Mappers;

use PhpTwinfield\Enums\MeansOfPayment;
use PhpTwinfield\Response\Response;
use PhpTwinfield\Supplier;
use PhpTwinfield\SupplierAddress;
use PhpTwinfield\SupplierBank;
use PhpTwinfield\Util;

/**
* Maps a response DOMDocument to the corresponding entity.
Expand Down Expand Up @@ -85,6 +87,12 @@ public static function map(Response $response)
$supplier->$method($value);
}
}

$meansOfPaymentValue = self::getField($financialElement, 'meansofpayment');

if (MeansOfPayment::isValid($meansOfPaymentValue)) {
$supplier->setMeansOfPayment(MeansOfPayment::from($meansOfPaymentValue));
}
}

$addressesDOMTag = $responseDOM->getElementsByTagName('addresses');
Expand Down
13 changes: 13 additions & 0 deletions src/Supplier.php
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@

namespace PhpTwinfield;

use PhpTwinfield\Enums\MeansOfPayment;
use PhpTwinfield\Transactions\TransactionFields\OfficeField;
use PhpTwinfield\Transactions\TransactionLineFields\VatCodeField;

Expand Down Expand Up @@ -39,6 +40,7 @@ class Supplier
private $editDimensionName;
private $dueDays = 0;
private $payAvailable = false;
private $meansOfPayment;
private $payCode;
private $eBilling = false;
private $eBillMail;
Expand Down Expand Up @@ -260,6 +262,17 @@ public function setPayAvailable(bool $payAvailable): self
return $this;
}

public function getMeansOfPayment(): ?MeansOfPayment
{
return $this->meansOfPayment;
}

public function setMeansOfPayment(?MeansOfPayment $meansOfPayment): self
{
$this->meansOfPayment = $meansOfPayment;
return $this;
}

public function getPayCode()
{
return $this->payCode;
Expand Down
203 changes: 203 additions & 0 deletions tests/IntegrationTests/SupplierIntegrationTest.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,203 @@
<?php

namespace PhpTwinfield\IntegrationTests;

use PhpTwinfield\ApiConnectors\SupplierApiConnector;
use PhpTwinfield\Enums\MeansOfPayment;
use PhpTwinfield\Supplier;
use PhpTwinfield\SupplierAddress;
use PhpTwinfield\SupplierBank;
use PhpTwinfield\DomDocuments\SuppliersDocument;
use PhpTwinfield\Mappers\SupplierMapper;
use PhpTwinfield\Office;
use PhpTwinfield\Response\Response;

/**
* @covers Supplier
* @covers SupplierAddress
* @covers SupplierBank
* @covers SuppliersDocument
* @covers SupplierMapper
* @covers SupplierApiConnector
*/
class SupplierIntegrationTest extends BaseIntegrationTest
{
/**
* @var SupplierApiConnector|\PHPUnit_Framework_MockObject_MockObject
*/
private $supplierApiConnector;

protected function setUp(): void
{
parent::setUp();

$this->supplierApiConnector = new SupplierApiConnector($this->connection);
}

public function testGetSupplierWorks()
{
$response = Response::fromString(file_get_contents(__DIR__ . '/resources/supplierGetResponse.xml'));

$this->processXmlService
->expects($this->once())
->method("sendDocument")
->with($this->isInstanceOf(\PhpTwinfield\Request\Read\Supplier::class))
->willReturn($response);

$supplier = $this->supplierApiConnector->get('CODE', $this->office);

$this->assertInstanceOf(Supplier::class, $supplier);
$this->assertSame('001', $supplier->getOffice()->getCode());
$this->assertSame('CRD', $supplier->getType());
$this->assertSame('Supplier 0', $supplier->getName());
$this->assertSame('http://www.example.com', $supplier->getWebsite());

// Financials
$this->assertSame('1', $supplier->getDueDays());
$this->assertSame(true, $supplier->getPayAvailable());
$this->assertSame('SEPANLCT', $supplier->getPayCode());
$this->assertSame(false, $supplier->getEBilling());

// Addresses
$addresses = $supplier->getAddresses();
$this->assertCount(1, $addresses);
$this->assertArrayHasKey('1', $addresses);

/** @var SupplierAddress $address */
$address = $addresses['1'];

$this->assertSame('1', $address->getID());
$this->assertSame('invoice', $address->getType());
$this->assertSame('true', $address->getDefault());
$this->assertSame('Supplier 0', $address->getName());
$this->assertSame('NL', $address->getCountry());
$this->assertSame('Place 2000', $address->getCity());
$this->assertSame('2000', $address->getPostcode());
$this->assertSame('010-123452000', $address->getTelephone());
$this->assertSame('010-12342000', $address->getFax());
$this->assertSame('info@example.com', $address->getEmail());
$this->assertSame('', $address->getContact());
$this->assertSame('supplier 2000', $address->getField1());
$this->assertSame('Streetname part 1 - 2000', $address->getField2());
$this->assertSame('Streetname part 2000', $address->getField3());
$this->assertSame('155676842B01', $address->getField4());
$this->assertSame('', $address->getField5());
$this->assertSame('', $address->getField6());

// Banks
$banks = $supplier->getBanks();
$this->assertCount(1, $banks);
$this->assertArrayHasKey('1', $banks);

/** @var SupplierBank $bank */
$bank = $banks['1'];

$this->assertSame('1', $bank->getID());
$this->assertSame('true', $bank->getDefault());
$this->assertSame('Supplier 2000', $bank->getAscription());
$this->assertSame('123456789', $bank->getAccountnumber());
$this->assertSame('', $bank->getBankname());
$this->assertSame('TESTNL2A', $bank->getBiccode());
$this->assertSame('Place 2000', $bank->getCity());
$this->assertSame('NL', $bank->getCountry());
$this->assertSame('NL13TEST0123456789', $bank->getIban());
$this->assertSame('', $bank->getNatbiccode());
$this->assertSame('', $bank->getPostcode());
$this->assertSame('', $bank->getState());
$this->assertSame('', $bank->getAddressField2());
$this->assertSame('', $bank->getAddressField3());

$this->assertSame('2000', $supplier->getCode());
$this->assertSame('c6c05844-c075-4b51-a4ca-6f30f45d5a12', $supplier->getUID());
$this->assertSame('true', $supplier->getInUse());
$this->assertSame('normal', $supplier->getBehaviour());
$this->assertSame('4', $supplier->getTouched());
$this->assertSame('0', $supplier->getBeginPeriod());
$this->assertNull($supplier->getBeginYear());
$this->assertSame('0', $supplier->getEndPeriod());
$this->assertSame('0', $supplier->getEndYear());
$this->assertSame('false', $supplier->getEditDimensionName());
}

public function testListAllSuppliersWorks()
{
$response = Response::fromString(file_get_contents(__DIR__ . '/resources/supplierListResponse.xml'));

$this->processXmlService
->expects($this->once())
->method("sendDocument")
->with($this->isInstanceOf(\PhpTwinfield\Request\Catalog\Dimension::class))
->willReturn($response);

$suppliers = $this->supplierApiConnector->listAll($this->office);

$this->assertCount(3, $suppliers);

$this->assertArrayHasKey('1000', $suppliers);
$this->assertSame('John Doe', $suppliers['1000']['name']);

$this->assertArrayHasKey('1001', $suppliers);
$this->assertSame('B. Terwel', $suppliers['1001']['name']);

$this->assertArrayHasKey('1002', $suppliers);
$this->assertSame('Hr E G H Küppers en/of MW M.J. Küppers-Veeneman', $suppliers['1002']['name']);
}

public function testSendSupplierWorks()
{
$supplier = new Supplier();
$supplier->setOffice(Office::fromCode('001'));
$supplier->setName('Supplier 0');
$supplier->setDueDays('30');
$supplier->setPayAvailable(true);
$supplier->setPayCode('SEPANLDD');
$supplier->setMeansOfPayment(MeansOfPayment::PAYMENTFILE());

$address = new SupplierAddress();
$address->setID('1');
$address->setType('invoice');
$address->setDefault(true);
$address->setName('Supplier 0');
$address->setCountry('NL');
$address->setCity('Place');
$address->setPostcode('1000');
$address->setTelephone('010-123452000');
$address->setFax('010-12342000');
$address->setEmail('info@example.com');
$address->setField1('Supplier 1');
$address->setField2('Streetname part 1 - 1');
$address->setField3('Streetname part 1 - 2');
$supplier->addAddress($address);

$bank = new SupplierBank();
$bank->setDefault(true);
$bank->setAscription('Supplier 1');
$bank->setAccountnumber('123456789');
$bank->setAddressField2('');
$bank->setAddressField3('');
$bank->setBankname('ABN Amro');
$bank->setBiccode('ABNANL2A');
$bank->setCity('Place');
$bank->setCountry('NL');
$bank->setIban('NL02ABNA0123456789');
$bank->setNatbiccode('');
$bank->setPostcode('');
$bank->setState('');
$supplier->addBank($bank);

$this->processXmlService
->expects($this->once())
->method("sendDocument")
->with($this->isInstanceOf(SuppliersDocument::class))
->willReturnCallback(function (SuppliersDocument $suppliersDocument): Response {
$this->assertXmlStringEqualsXmlString(
file_get_contents(__DIR__ . '/resources/supplierSendRequest.xml'),
$suppliersDocument->saveXML()
);

return $this->getSuccessfulResponse();
});

$this->supplierApiConnector->send($supplier);
}
}
89 changes: 89 additions & 0 deletions tests/IntegrationTests/resources/supplierGetResponse.xml
Original file line number Diff line number Diff line change
@@ -0,0 +1,89 @@
<dimension status="active" result="1">
<office name="001" shortname="001">001</office>
<type name="Crediteuren" shortname="Crediteuren">CRD</type>
<code>2000</code>
<uid>c6c05844-c075-4b51-a4ca-6f30f45d5a12</uid>
<name>Supplier 0</name>
<shortname></shortname>
<inuse>true</inuse>
<behaviour>normal</behaviour>
<touched>4</touched>
<beginperiod>0</beginperiod>
<beginyear>0</beginyear>
<endperiod>0</endperiod>
<endyear>0</endyear>
<website>http://www.example.com</website>
<cocnumber></cocnumber>
<vatnumber></vatnumber>
<editdimensionname>false</editdimensionname>
<financials>
<matchtype>customersupplier</matchtype>
<accounttype>inherit</accounttype>
<subanalyse>false</subanalyse>
<duedays>1</duedays>
<level>2</level>
<payavailable>true</payavailable>
<paycode name="SEPANLCT" shortname="SEPA NL Excasso">SEPANLCT</paycode>
<meansofpayment>paymentfile</meansofpayment>
<ebilling>false</ebilling>
<ebillmail></ebillmail>
<substitutionlevel>1</substitutionlevel>
<substitutewith name="Crediteuren" shortname="Crediteuren" dimensiontype="BAS">1600</substitutewith>
<relationsreference>2000</relationsreference>
<vattype name="" shortname=""></vattype>
<vatcode/>
<vatobligatory>false</vatobligatory>
<performancetype/>
<collectmandate>
<id></id>
<signaturedate></signaturedate>
<firstrundate></firstrundate>
</collectmandate>
<collectionschema/>
</financials>
<addresses>
<address id="1" type="invoice" default="true">
<name>Supplier 0</name>
<country name="Nederland" shortname="">NL</country>
<city>Place 2000</city>
<postcode>2000</postcode>
<telephone>010-123452000</telephone>
<telefax>010-12342000</telefax>
<email>info@example.com</email>
<contact></contact>
<field1>supplier 2000</field1>
<field2>Streetname part 1 - 2000</field2>
<field3>Streetname part 2000</field3>
<field4>155676842B01</field4>
<field5></field5>
<field6></field6>
</address>
</addresses>
<banks>
<bank default="true" id="1">
<ascription>Supplier 2000</ascription>
<accountnumber>123456789</accountnumber>
<address>
<field2></field2>
<field3></field3>
</address>
<bankname></bankname>
<biccode>TESTNL2A</biccode>
<city>Place 2000</city>
<country name="Nederland" shortname="">NL</country>
<iban>NL13TEST0123456789</iban>
<natbiccode></natbiccode>
<postcode></postcode>
<state></state>
</bank>
</banks>
<groups>
<group shortname="Relaties" name="Relaties">2REL</group>
</groups>
<paymentconditions>
<paymentcondition>
<discountdays>5</discountdays>
<discountpercentage>2.75</discountpercentage>
</paymentcondition>
</paymentconditions>
</dimension>
7 changes: 7 additions & 0 deletions tests/IntegrationTests/resources/supplierListResponse.xml
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
<?xml version="1.0"?>
<dimensions office="DEV1000" type="CRD" result="1">
<dimension name="John Doe" shortname="">1000</dimension>
<dimension name="B. Terwel" shortname="">1001</dimension>
<dimension name="Hr E G H K&#xFC;ppers en/of MW M.J. K&#xFC;ppers-Veeneman" shortname="">1002</dimension>
<dimension name="" shortname="">CRD</dimension>
</dimensions>
Loading