From e622718f4d46bb3554154d4da61a808f24958f0f Mon Sep 17 00:00:00 2001 From: iranl Date: Wed, 3 Jul 2019 18:36:10 +0200 Subject: [PATCH 1/5] Update readme.md --- readme.md | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/readme.md b/readme.md index 40aeed4e..5965207d 100644 --- a/readme.md +++ b/readme.md @@ -57,7 +57,7 @@ support for another resource. [Cash Transactions](https://c3.twinfield.com/webservices/documentation/#/ApiReference/Transactions/CashTransactions) | :white_check_mark: | | :white_check_mark: | :white_check_mark: | :white_check_mark: | [Cash Transaction](examples/CashTransaction.php) | [Journal Transactions](https://c3.twinfield.com/webservices/documentation/#/ApiReference/Transactions/JournalTransactions) | :white_check_mark: | | :white_check_mark: | :white_check_mark: | :white_check_mark: | [Journal Transaction](examples/JournalTransaction.php) | [Purchase Transactions](https://c3.twinfield.com/webservices/documentation/#/ApiReference/PurchaseTransactions) | :white_check_mark: | | :white_check_mark: | :white_check_mark: | :white_check_mark: | [Purchase Transaction](examples/PurchaseTransaction.php) | -[Sale Transactions](https://c3.twinfield.com/webservices/documentation/#/ApiReference/SalesTransactions) | :white_check_mark: | | :white_check_mark: | :white_check_mark: | :white_check_mark: | [Sales Transaction](examples/SalesTransaction.php) | +[Sales Transactions](https://c3.twinfield.com/webservices/documentation/#/ApiReference/SalesTransactions) | :white_check_mark: | | :white_check_mark: | :white_check_mark: | :white_check_mark: | [Sales Transaction](examples/SalesTransaction.php) | | | | | | | | | | [Users](https://c3.twinfield.com/webservices/documentation/#/ApiReference/Masters/Users) | :white_check_mark: | :white_check_mark: | | | :white_check_mark: | [User](examples/User.php) | | User Roles | | :white_check_mark: | | | :white_check_mark: | [User Role](examples/UserRole.php) | From 58b219285f3efe7d51410ce8407d69255d3eb6dd Mon Sep 17 00:00:00 2001 From: iranl Date: Wed, 3 Jul 2019 20:07:09 +0200 Subject: [PATCH 2/5] Upload --- src/Mappers/TransactionMapper.php | 3 ++- src/SalesTransactionLine.php | 4 +++- 2 files changed, 5 insertions(+), 2 deletions(-) diff --git a/src/Mappers/TransactionMapper.php b/src/Mappers/TransactionMapper.php index 02a934fd..75fea63b 100644 --- a/src/Mappers/TransactionMapper.php +++ b/src/Mappers/TransactionMapper.php @@ -148,6 +148,8 @@ public static function map(string $transactionClassName, Response $response, Aut $transactionLine = new $transactionLineClassName(); $lineType = $lineElement->getAttribute('type'); + + $transactionLine->setLineType(self::parseEnumAttribute(\PhpTwinfield\Enums\LineType::class, $lineType)); $transactionLine ->setBaseValue(self::parseMoneyAttribute(self::getField($lineElement, 'basevalue', $transactionLine), $currencies['base'])) @@ -158,7 +160,6 @@ public static function map(string $transactionClassName, Response $response, Aut ->setDestOffice(self::parseObjectAttribute(\PhpTwinfield\Office::class, $transactionLine, $lineElement, 'destoffice')) ->setDim1(self::parseObjectAttribute(null, $transactionLine, $lineElement, 'dim1', array('name' => 'setName', 'shortname' => 'setShortName', 'dimensiontype' => 'setTypeFromString'))) ->setId($lineElement->getAttribute('id')) - ->setLineType(self::parseEnumAttribute(\PhpTwinfield\Enums\LineType::class, $lineType)) ->setMatchStatus(self::parseEnumAttribute(\PhpTwinfield\Enums\MatchStatus::class, self::getField($lineElement, 'matchstatus', $transactionLine))) ->setRate(self::getField($lineElement, 'rate', $transactionLine)) ->setRepRate(self::getField($lineElement, 'reprate', $transactionLine)) diff --git a/src/SalesTransactionLine.php b/src/SalesTransactionLine.php index fcefdf5c..1366e501 100644 --- a/src/SalesTransactionLine.php +++ b/src/SalesTransactionLine.php @@ -160,6 +160,7 @@ public function setMatchLevel(?int $matchLevel): parent /* * Payment status of the transaction. If line type detail or vat always notmatchable. Read-only attribute. + * NOTE: The above statement from the Twinfield API documentation is incorrect as detail lines can also have other match statuses than notmatchable * * @param MatchStatus|null $matchStatus * @return $this @@ -167,7 +168,8 @@ public function setMatchLevel(?int $matchLevel): parent */ public function setMatchStatus(?MatchStatus $matchStatus): parent { - if ($matchStatus !== null && in_array($this->getLineType(), [LineType::DETAIL(), LineType::VAT()]) && $matchStatus != MatchStatus::NOTMATCHABLE()) { + //if ($matchStatus !== null && in_array($this->getLineType(), [LineType::DETAIL(), LineType::VAT()]) && $matchStatus != MatchStatus::NOTMATCHABLE()) { + if ($matchStatus !== null && in_array($this->getLineType(), [LineType::VAT()]) && $matchStatus != MatchStatus::NOTMATCHABLE()) { throw Exception::invalidMatchStatusForLineType($matchStatus, $this); } From 20f10eccd4c51ff3ab75c1509b5473c81234aa13 Mon Sep 17 00:00:00 2001 From: iranl Date: Thu, 4 Jul 2019 20:00:34 +0200 Subject: [PATCH 3/5] Upload --- src/ApiConnectors/ArticleApiConnector.php | 23 +++++++++++++++- src/ApiConnectors/AssetMethodApiConnector.php | 23 +++++++++++++++- src/ApiConnectors/BaseApiConnector.php | 26 ++++++++++++++++--- src/ApiConnectors/CurrencyApiConnector.php | 12 ++++++++- src/ApiConnectors/HasEqualInterface.php | 3 +++ src/ApiConnectors/RateApiConnector.php | 23 +++++++++++++++- src/ApiConnectors/VatCodeApiConnector.php | 22 +++++++++++++++- src/Mappers/TransactionMapper.php | 2 +- 8 files changed, 125 insertions(+), 9 deletions(-) diff --git a/src/ApiConnectors/ArticleApiConnector.php b/src/ApiConnectors/ArticleApiConnector.php index 5dc41c30..d4ba546d 100644 --- a/src/ApiConnectors/ArticleApiConnector.php +++ b/src/ApiConnectors/ArticleApiConnector.php @@ -9,6 +9,7 @@ use PhpTwinfield\Mappers\ArticleMapper; use PhpTwinfield\Office; use PhpTwinfield\Request as Request; +use PhpTwinfield\Response\IndividualMappedResponse; use PhpTwinfield\Response\MappedResponseCollection; use PhpTwinfield\Response\Response; use PhpTwinfield\Response\ResponseException; @@ -120,7 +121,7 @@ public function testEqual(HasMessageInterface $returnedObject, HasMessageInterfa foreach ($returnedLines as $key => $returnedLine) { $id = $returnedLine->getID(); - if (!in_array($id, $idArray)) { + if (!in_array($id, $idArray) && $returnedLine->getStatus() != 'deleted') { $returnedLine->setStatus(\PhpTwinfield\Enums\Status::DELETED()); $equal = false; } @@ -129,6 +130,26 @@ public function testEqual(HasMessageInterface $returnedObject, HasMessageInterfa return [$equal, $returnedObject]; } + /** + * @param HasMessageInterface $returnedObject + * @return IndividualMappedResponse + */ + public function getMappedResponse(HasMessageInterface $returnedObject, HasMessageInterface $sentObject): IndividualMappedResponse + { + Assert::IsInstanceOf($returnedObject, Article::class); + + $request_article = new Request\Read\Article(); + $request_article->setOffice($returnedObject->getOffice()) + ->setCode($returnedObject->getCode()); + $response = $this->sendXmlDocument($request_article); + + $mappedResponseCollection = $this->getProcessXmlService()->mapAll([$response], "article", function(Response $response): Article { + return ArticleMapper::map($response, $this->getConnection()); + }); + + return ($mappedResponseCollection[0]); + } + /** * List all articles. * diff --git a/src/ApiConnectors/AssetMethodApiConnector.php b/src/ApiConnectors/AssetMethodApiConnector.php index ae31646c..823b3920 100644 --- a/src/ApiConnectors/AssetMethodApiConnector.php +++ b/src/ApiConnectors/AssetMethodApiConnector.php @@ -9,6 +9,7 @@ use PhpTwinfield\Mappers\AssetMethodMapper; use PhpTwinfield\Office; use PhpTwinfield\Request as Request; +use PhpTwinfield\Response\IndividualMappedResponse; use PhpTwinfield\Response\MappedResponseCollection; use PhpTwinfield\Response\Response; use PhpTwinfield\Response\ResponseException; @@ -122,7 +123,7 @@ public function testEqual(HasMessageInterface $returnedObject, HasMessageInterfa foreach ($returnedFreeTexts as $key => $returnedFreeText) { $id = $returnedFreeText->getID(); - if (!in_array($id, $idArray)) { + if (!in_array($id, $idArray) && (!empty($returnedFreeText->getElementValue()) || $returnedFreeText->getType() != 'text')) { $returnedFreeText->setType(\PhpTwinfield\Enums\FreeTextType::TEXT()); $returnedFreeText->setElementValue(''); $equal = false; @@ -132,6 +133,26 @@ public function testEqual(HasMessageInterface $returnedObject, HasMessageInterfa return [$equal, $returnedObject]; } + /** + * @param HasMessageInterface $returnedObject + * @return IndividualMappedResponse + */ + public function getMappedResponse(HasMessageInterface $returnedObject, HasMessageInterface $sentObject): IndividualMappedResponse + { + Assert::IsInstanceOf($returnedObject, AssetMethod::class); + + $request_assetMethod = new Request\AssetMethod(); + $request_assetMethod->setOffice($returnedObject->getOffice()) + ->setCode($returnedObject->getCode()); + $response = $this->sendXmlDocument($request_assetMethod); + + $mappedResponseCollection = $this->getProcessXmlService()->mapAll([$response], "assetmethod", function(Response $response): AssetMethod { + return AssetMethodMapper::map($response); + }); + + return ($mappedResponseCollection[0]); + } + /** * List all asset methods. * diff --git a/src/ApiConnectors/BaseApiConnector.php b/src/ApiConnectors/BaseApiConnector.php index 735318fe..1a1872cc 100644 --- a/src/ApiConnectors/BaseApiConnector.php +++ b/src/ApiConnectors/BaseApiConnector.php @@ -262,9 +262,29 @@ public function testSentEqualsResponse(HasEqualInterface $apiConnector, array $s $returnedObject = $testResult[1]; if (!$equal) { - $apiConnector->sendAll([$returnedObject], true)[0]; - sleep(2); - $individualMappedResponse = $apiConnector->sendAll([$sentObjects[$key]], true)[0]; + $tempMappedResponse = $apiConnector->sendAll([$returnedObject], true)[0]; + $tempReturnedObject = $tempMappedResponse->unwrap(); + + if ($tempReturnedObject->getResult() == 1) { + $individualMappedResponse = $tempMappedResponse; + $returnedObject = $tempReturnedObject; + + $testResult = $apiConnector->testEqual($returnedObject, $sentObjects[$key]); + $equal = $testResult[0]; + $returnedObject = $testResult[1]; + + if (!$equal || is_a($returnedObject, \PhpTwinfield\Currency::class)) { + sleep(2); + + $tempMappedResponse = $apiConnector->getMappedResponse($returnedObject, $sentObjects[$key]); + $tempReturnedObject = $tempMappedResponse->unwrap(); + + if ($returnedObject->getResult() == 1) { + $individualMappedResponse = $tempMappedResponse; + $returnedObject = $tempReturnedObject; + } + } + } } } diff --git a/src/ApiConnectors/CurrencyApiConnector.php b/src/ApiConnectors/CurrencyApiConnector.php index ab29165b..42188182 100644 --- a/src/ApiConnectors/CurrencyApiConnector.php +++ b/src/ApiConnectors/CurrencyApiConnector.php @@ -9,6 +9,7 @@ use PhpTwinfield\Mappers\CurrencyMapper; use PhpTwinfield\Office; use PhpTwinfield\Request as Request; +use PhpTwinfield\Response\IndividualMappedResponse; use PhpTwinfield\Response\MappedResponseCollection; use PhpTwinfield\Response\Response; use PhpTwinfield\Response\ResponseException; @@ -160,7 +161,7 @@ public function testEqual(HasMessageInterface $returnedObject, HasMessageInterfa foreach ($returnedRates as $returnedRate) { $date = Util::formatDate($returnedRate->getStartDate()); - if (!in_array($date, $dateArray)) { + if (!in_array($date, $dateArray) && $returnedRate->getStatus() != 'deleted') { $returnedRate->setStatus(\PhpTwinfield\Enums\Status::DELETED()); $equal = false; } @@ -169,6 +170,15 @@ public function testEqual(HasMessageInterface $returnedObject, HasMessageInterfa return [$equal, $returnedObject]; } + /** + * @param HasMessageInterface $returnedObject + * @return IndividualMappedResponse + */ + public function getMappedResponse(HasMessageInterface $returnedObject, HasMessageInterface $sentObject): IndividualMappedResponse + { + return $this->sendAll([$sentObject], true)[0]; + } + /** * List all currencies. * diff --git a/src/ApiConnectors/HasEqualInterface.php b/src/ApiConnectors/HasEqualInterface.php index 08fb75d9..8b2dbfd8 100644 --- a/src/ApiConnectors/HasEqualInterface.php +++ b/src/ApiConnectors/HasEqualInterface.php @@ -3,6 +3,7 @@ namespace PhpTwinfield\ApiConnectors; use PhpTwinfield\HasMessageInterface; +use PhpTwinfield\Response\IndividualMappedResponse; use PhpTwinfield\Response\MappedResponseCollection; /** @@ -14,4 +15,6 @@ interface HasEqualInterface public function testEqual(HasMessageInterface $returnedObject, HasMessageInterface $sentObject): array; public function sendAll(array $objects, bool $reSend): MappedResponseCollection; + + public function getMappedResponse(HasMessageInterface $returnedObject, HasMessageInterface $sentObject): IndividualMappedResponse; } diff --git a/src/ApiConnectors/RateApiConnector.php b/src/ApiConnectors/RateApiConnector.php index 191ca2fe..9ad8300c 100644 --- a/src/ApiConnectors/RateApiConnector.php +++ b/src/ApiConnectors/RateApiConnector.php @@ -9,6 +9,7 @@ use PhpTwinfield\Office; use PhpTwinfield\Rate; use PhpTwinfield\Request as Request; +use PhpTwinfield\Response\IndividualMappedResponse; use PhpTwinfield\Response\MappedResponseCollection; use PhpTwinfield\Response\Response; use PhpTwinfield\Response\ResponseException; @@ -121,7 +122,7 @@ public function testEqual(HasMessageInterface $returnedObject, HasMessageInterfa foreach ($returnedRateChanges as $key => $returnedRateChange) { $id = $returnedRateChange->getID(); - if (!in_array($id, $idArray)) { + if (!in_array($id, $idArray) && $returnedRateChange->getStatus() != 'deleted') { $returnedRateChange->setStatus(\PhpTwinfield\Enums\Status::DELETED()); $equal = false; } @@ -130,6 +131,26 @@ public function testEqual(HasMessageInterface $returnedObject, HasMessageInterfa return [$equal, $returnedObject]; } + /** + * @param HasMessageInterface $returnedObject + * @return IndividualMappedResponse + */ + public function getMappedResponse(HasMessageInterface $returnedObject, HasMessageInterface $sentObject): IndividualMappedResponse + { + Assert::IsInstanceOf($returnedObject, Rate::class); + + $request_rate = new Request\Read\Rate(); + $request_rate->setOffice($returnedObject->getOffice()) + ->setCode($returnedObject->getCode()); + $response = $this->sendXmlDocument($request_rate); + + $mappedResponseCollection = $this->getProcessXmlService()->mapAll([$response], "projectrate", function(Response $response): Rate { + return RateMapper::map($response); + }); + + return ($mappedResponseCollection[0]); + } + /** * List all rates. * diff --git a/src/ApiConnectors/VatCodeApiConnector.php b/src/ApiConnectors/VatCodeApiConnector.php index 79f1a0ad..79b24c88 100644 --- a/src/ApiConnectors/VatCodeApiConnector.php +++ b/src/ApiConnectors/VatCodeApiConnector.php @@ -8,6 +8,7 @@ use PhpTwinfield\Mappers\VatCodeMapper; use PhpTwinfield\Office; use PhpTwinfield\Request as Request; +use PhpTwinfield\Response\IndividualMappedResponse; use PhpTwinfield\Response\MappedResponseCollection; use PhpTwinfield\Response\Response; use PhpTwinfield\Response\ResponseException; @@ -122,7 +123,7 @@ public function testEqual(HasMessageInterface $returnedObject, HasMessageInterfa foreach ($returnedPercentages as $key => $returnedPercentage) { $date = Util::formatDate($returnedPercentage->getDate()); - if (!in_array($date, $dateArray)) { + if (!in_array($date, $dateArray) && $returnedPercentage->getStatus() != 'deleted') { $returnedPercentage->setStatus(\PhpTwinfield\Enums\Status::DELETED()); $equal = false; } @@ -131,6 +132,25 @@ public function testEqual(HasMessageInterface $returnedObject, HasMessageInterfa return [$equal, $returnedObject]; } + /** + * @param HasMessageInterface $returnedObject + * @return IndividualMappedResponse + */ + public function getMappedResponse(HasMessageInterface $returnedObject, HasMessageInterface $sentObject): IndividualMappedResponse + { + Assert::IsInstanceOf($returnedObject, VatCode::class); + + $request_vatCode = new Request\Read\VatCode(); + $request_vatCode->setCode($returnedObject->getCode()); + $response = $this->sendXmlDocument($request_vatCode); + + $mappedResponseCollection = $this->getProcessXmlService()->mapAll([$response], "vat", function(Response $response): VatCode { + return VatCodeMapper::map($response); + }); + + return ($mappedResponseCollection[0]); + } + /** * List all VAT codes. * diff --git a/src/Mappers/TransactionMapper.php b/src/Mappers/TransactionMapper.php index 75fea63b..c3a113c1 100644 --- a/src/Mappers/TransactionMapper.php +++ b/src/Mappers/TransactionMapper.php @@ -148,7 +148,7 @@ public static function map(string $transactionClassName, Response $response, Aut $transactionLine = new $transactionLineClassName(); $lineType = $lineElement->getAttribute('type'); - + $transactionLine->setLineType(self::parseEnumAttribute(\PhpTwinfield\Enums\LineType::class, $lineType)); $transactionLine From 9b629458de1f63f87af0cc766759758660dbc89d Mon Sep 17 00:00:00 2001 From: iranl Date: Sat, 6 Jul 2019 21:50:03 +0200 Subject: [PATCH 4/5] Upload --- examples/Activity.php | 4 +- examples/Article.php | 4 +- examples/AssetMethod.php | 4 +- examples/Authorization.php | 3 + examples/BankTransaction.php | 344 ++++++++++++++++++ examples/BrowseData.php | 4 +- examples/CashBankBook.php | 4 +- examples/CashTransaction.php | 344 ++++++++++++++++++ examples/Connection.php | 3 + examples/CostCenter.php | 4 +- examples/Country.php | 4 +- examples/Currency.php | 4 +- examples/Customer.php | 4 +- examples/DimensionGroup.php | 4 +- examples/DimensionType.php | 4 +- examples/FixedAsset.php | 4 +- examples/GeneralLedger.php | 4 +- examples/Invoice.php | 10 +- examples/InvoiceType.php | 4 +- examples/Office.php | 4 +- examples/PayCode.php | 4 +- examples/Project.php | 4 +- examples/Rate.php | 4 +- examples/RenewAccessToken.php | 3 + examples/RenewAuthorization.php | 3 + examples/Supplier.php | 4 +- examples/User.php | 4 +- examples/UserRole.php | 4 +- examples/VatCode.php | 4 +- examples/VatGroup.php | 4 +- examples/VatGroupCountry.php | 4 +- src/BaseObject.php | 4 + .../Transaction/CloseAndStartValueFields.php | 15 +- src/InvoiceLine.php | 1 + src/Mappers/BaseMapper.php | 6 + src/Mappers/TransactionMapper.php | 14 +- 36 files changed, 807 insertions(+), 39 deletions(-) create mode 100644 examples/BankTransaction.php create mode 100644 examples/CashTransaction.php diff --git a/examples/Activity.php b/examples/Activity.php index e4623ec2..0252d4e6 100644 --- a/examples/Activity.php +++ b/examples/Activity.php @@ -1,5 +1,4 @@ get(\PhpTwinfield\BankTransaction::class, "BNK", 201900011, $office); + } catch (ResponseException $e) { + $bankTransaction = $e->getReturnedObject(); + } + + echo "
";
+    print_r($bankTransaction);
+    echo "
"; + + echo "BankTransaction
"; + echo "AutoBalanceVat (bool): {$bankTransaction->getAutoBalanceVat()}
"; // bool|null Should VAT be rounded true or not false? Rounding will only be done with a maximum of two cents. + echo "AutoBalanceVat (string): " . Util::formatBoolean($bankTransaction->getAutoBalanceVat()) . "
"; // string|null + echo "BookingReference (\\PhpTwinfield\\BookingReference):
" . print_r($bankTransaction->getBookingReference(), true) . "

"; // BookingReference|null The Booking reference + echo "CloseValue (\\Money\\Money):
" . print_r($bankTransaction->getCloseValue(), true) . "

"; // Money|null Closing balance. If not provided, the closing balance is set to zero. + echo "CloseValue (string): " . Util::formatMoney($bankTransaction->getCloseValue()) . "
"; // string|null + echo "Code: {$bankTransaction->getCode()}
"; // string|null Transaction type code. + echo "Currency (\\PhpTwinfield\\Currency):
" . print_r($bankTransaction->getCurrency(), true) . "

"; // Currency|null Currency code. + echo "Currency (string): " . Util::objectToStr($bankTransaction->getCurrency()) . "
"; // string|null + echo "Date (\\DateTimeInterface):
" . print_r($bankTransaction->getDate(), true) . "

"; // DateTimeInterface|null Transaction date. + echo "Date (string): " . Util::formatDate($bankTransaction->getDate()) . "
"; // string|null + echo "DateRaiseWarning (bool): {$bankTransaction->getDateRaiseWarning()}
"; // bool|null Optionally, it is possible to suppress warnings about 'date out of range for the given period' by adding the raisewarning attribute and set its value to false. + echo "DateRaiseWarning (string): {$bankTransaction->getDateRaiseWarningToString()}
"; // string|null This overwrites the value of the raisewarning attribute as set on the root element. + echo "Destiny: {$bankTransaction->getDestiny()}
"; // Destiny|null Attribute to indicate the destiny of the bank transaction. Only used in the request XML. temporary = bank transaction will be saved as provisional. final = bank transaction will be saved as final. + echo "FreeText1: {$bankTransaction->getFreeText1()}
"; // string|null Free text field 1 as entered on the transaction type. + echo "FreeText2: {$bankTransaction->getFreeText2()}
"; // string|null Free text field 2 as entered on the transaction type. + echo "FreeText3: {$bankTransaction->getFreeText3()}
"; // string|null Free text field 3 as entered on the transaction type. + echo "InputDate (\\DateTimeInterface):
" . print_r($bankTransaction->getInputDate(), true) . "

"; // DateTimeInterface|null The date/time on which the transaction was created. Read-only attribute. + echo "InputDate (string): " . Util::formatDate($bankTransaction->getInputDate()) . "
"; // string|null + + if ($bankTransaction->hasMessages()) { // bool Object contains (error) messages true/false. + echo "Messages: " . print_r($bankTransaction->getMessages(), true) . "
"; // Array|null (Error) messages. + } + + echo "ModificationDate (\\DateTimeInterface):
" . print_r($bankTransaction->getModificationDate(), true) . "

"; // DateTimeInterface|null The date/time on which the bank transaction was modified the last time. Read-only attribute. + echo "ModificationDate (string): " . Util::formatDate($bankTransaction->getModificationDate()) . "
"; // string|null + echo "Number: {$bankTransaction->getNumber()}
"; // int|null Transaction number. When creating a new bank transaction, don't include this tag as the transaction number is determined by the system. When updating a bank transaction, the related transaction number should be provided. + echo "Office (\\PhpTwinfield\\Office):
" . print_r($bankTransaction->getOffice(), true) . "

"; // Office|null Office code. + echo "Office (string): " . Util::objectToStr($bankTransaction->getOffice()) . "
"; // string|null + echo "Origin: {$bankTransaction->getOrigin()}
"; // string|null The bank transaction origin. Read-only attribute. + echo "Period: {$bankTransaction->getPeriod()}
"; // string|null Period in YYYY/PP format. If this tag is not included or if it is left empty, the period is determined by the system based on the provided transaction date. + echo "RaiseWarning (bool): {$bankTransaction->getRaiseWarning()}
"; // bool|null Should warnings be given true or not false? Default true. + echo "RaiseWarning (string): " . Util::formatBoolean($bankTransaction->getRaiseWarning()) . "
"; // string|null + echo "Result: {$bankTransaction->getResult()}
"; // int|null Result (0 = error, 1 or empty = success). + echo "StartValue (\\Money\\Money):
" . print_r($bankTransaction->getStartValue(), true) . "

"; // Money|null Opening balance. If not provided, the opening balance is set to zero. + echo "StartValue (string): " . Util::formatMoney($bankTransaction->getStartValue()) . "
"; // string|null + echo "StatementNumber: {$bankTransaction->getStatementNumber()}
"; // int|null Number of the bank statement. Don't confuse this number with the transaction number. + + $bankTransactionLines = $bankTransaction->getLines(); // array|null Array of BankTransactionLine objects. + + foreach ($bankTransactionLines as $key => $bankTransactionLine) { + echo "BankTransactionLine {$key}
"; + + echo "BaseValue (\\Money\\Money):
" . print_r($bankTransactionLine->getBaseValue(), true) . "

"; // Money|null Amount in the base currency. + echo "BaseValue (string): " . Util::formatMoney($bankTransactionLine->getBaseValue()) . "
"; // string|null + echo "BaseValueOpen (\\Money\\Money):
" . print_r($bankTransactionLine->getBaseValueOpen(), true) . "

"; // Money|null Only if line type is detail. The amount still owed in base currency. Read-only attribute. + echo "BaseValueOpen (string): " . Util::formatMoney($bankTransactionLine->getBaseValueOpen()) . "
"; // string|null + echo "Comment: {$bankTransactionLine->getComment()}
"; // string|null Comment set on the transaction line. + echo "CurrencyDate (\\DateTimeInterface):
" . print_r($bankTransactionLine->getCurrencyDate(), true) . "

"; // DateTimeInterface|null Only if line type is detail. The line date. Only allowed if the line date in the bank book is set to Allowed or Mandatory. + echo "CurrencyDate (string): " . Util::formatDate($bankTransactionLine->getCurrencyDate()) . "
"; // string|null + echo "DebitCredit: {$bankTransactionLine->getDebitCredit()}
"; // DebitCredit|null If line type = total, based on the sum of the individual bank transaction lines. In case of a bank addition debit. In case of a bank withdrawal credit. If line type = detail, credit in case money is received and debit in case money is paid. If line type = vat, based on the sum of the vat amounts of the individual bank transaction lins. In case of a bank addition credit. In case of a bank withdrawal debit. + echo "Description: {$bankTransactionLine->getDescription()}
"; // string|null Description of the transaction line. + echo "DestOffice (\\PhpTwinfield\\Office):
" . print_r($bankTransactionLine->getDestOffice(), true) . "

"; // Office|null Office code. Used for inter company transactions – here you define in which company the transaction line should be posted. + echo "DestOffice (string): " . Util::objectToStr($bankTransactionLine->getDestOffice()) . "
"; // string|null + echo "Dim1:
" . print_r($bankTransactionLine->getDim1(), true) . "

"; // object|null If line type = total the bank balance account. If line type = detail the customer or supplier balance account or profit and loss account. + echo "Dim1 (string): " . Util::objectToStr($bankTransactionLine->getDim1()) . "
"; // string|null If line type = vat the VAT balance account. When an empty dim1 is entered, by default the general ledger account will be taken as entered at the VAT code in Twinfield. + echo "Dim2:
" . print_r($bankTransactionLine->getDim2(), true) . "

"; // object|null If line type = total empty. If line type = detail the customer or supplier or the cost center or empty. + echo "Dim2 (string): " . Util::objectToStr($bankTransactionLine->getDim2()) . "
"; // string|null If line type = vat empty. + echo "Dim3:
" . print_r($bankTransactionLine->getDim2(), true) . "

"; // object|null If line type = total empty. If line type = detail the project or asset or empty. + echo "Dim3 (string): " . Util::objectToStr($bankTransactionLine->getDim3()) . "
"; // string|null If line type = vat empty. + echo "FreeChar: {$bankTransactionLine->getFreeChar()}
"; // string|null Free character field. + echo "ID: {$bankTransactionLine->getID()}
"; // int|null Line ID. + echo "LineType: {$bankTransactionLine->getLineType()}
"; // LineType|null Line type. + echo "MatchLevel: {$bankTransactionLine->getMatchLevel()}
"; // int|null Only if line type is detail. The level of the matchable dimension. Read-only attribute. + echo "MatchStatus: {$bankTransactionLine->getMatchStatus()}
"; // MatchStatus|null Payment status of the bank transaction. If line type total or vat always notmatchable. Read-only attribute. + + if ($bankTransactionLine->hasMessages()) { // bool Object contains (error) messages true/false. + echo "Messages: " . print_r($bankTransactionLine->getMessages(), true) . "
"; // Array|null (Error) messages. + } + + echo "PerformanceCountry (\\PhpTwinfield\\Country):
" . print_r($bankTransactionLine->getPerformanceCountry(), true) . "

"; // Country|null Only if line type is detail or vat. Mandatory in case of an ICT VAT code. The ISO country codes are used. If not added to the request, by default the country code of the customer will be taken. + echo "PerformanceCountry (string): " . Util::objectToStr($bankTransactionLine->getPerformanceCountry()) . "
"; // string|null + echo "PerformanceDate (\\DateTimeInterface):
" . print_r($bankTransactionLine->getPerformanceDate(), true) . "

"; // DateTimeInterface|null Only if line type is detail or vat. Mandatory in case of an ICT VAT code but only if performancetype is services. + echo "PerformanceDate (string): " . Util::formatDate($bankTransactionLine->getPerformanceDate()) . "
"; // string|null + echo "PerformanceType: {$bankTransactionLine->getPerformanceType()}
"; // PerformanceType|null Only if line type is detail or vat. Mandatory in case of an ICT VAT code. The performance type. + echo "PerformanceVatNumber: {$bankTransactionLine->getPerformanceVatNumber()}
"; // string|null Only if line type is detail or vat. Mandatory in case of an ICT VAT code. If not added to the request, by default the VAT number of the customer will be taken. + echo "Rate: {$bankTransactionLine->getRate()}
"; // float|null The exchange rate used for the calculation of the base amount. + echo "Reference (\\PhpTwinfield\\MatchReference):
" . print_r($bankTransactionLine->getReference(), true) . "

"; // MatchReference|null Match reference + echo "Relation: {$bankTransactionLine->getRelation()}
"; // int|null Only if line type is detail. Read-only attribute. + echo "RepRate: {$bankTransactionLine->getRepRate()}
"; // float|null The exchange rate used for the calculation of the reporting amount. + echo "RepValue (\\Money\\Money):
" . print_r($bankTransactionLine->getRepValue(), true) . "

"; // Money|null Amount in the reporting currency. + echo "RepValue (string): " . Util::formatMoney($bankTransactionLine->getRepValue()) . "
"; // string|null + echo "RepValueOpen (\\Money\\Money):
" . print_r($bankTransactionLine->getRepValueOpen(), true) . "

"; // Money|null Only if line type is detail. The amount still owed in reporting currency. Read-only attribute. + echo "RepValueOpen (string): " . Util::formatMoney($bankTransactionLine->getRepValueOpen()) . "
"; // string|null + echo "Result: {$bankTransactionLine->getResult()}
"; // int|null Result (0 = error, 1 or empty = success). + echo "SignedValue (\\Money\\Money):
" . print_r($bankTransactionLine->getSignedValue(), true) . "

"; // Money|null + echo "SignedValue (string): " . Util::formatMoney($bankTransactionLine->getSignedValue()) . "
"; // string|null + echo "Value (\\Money\\Money):
" . print_r($bankTransactionLine->getValue(), true) . "

"; // Money|null If line type = total amount including VAT. If line type = detail amount without VAT. If line type = vat VAT amount. + echo "Value (string): " . Util::formatMoney($bankTransactionLine->getValue()) . "
"; // string|null + echo "VatBaseTotal (\\Money\\Money):
" . print_r($bankTransactionLine->getVatBaseTotal(), true) . "

"; // Money|null Only if line type is total. The total VAT amount in base currency. + echo "VatBaseTotal (string): " . Util::formatMoney($bankTransactionLine->getVatBaseTotal()) . "
"; // string|null + echo "VatBaseTurnover (\\Money\\Money):
" . print_r($bankTransactionLine->getVatBaseTurnover(), true) . "

"; // Money|null Only if line type is vat. Amount on which VAT was calculated in base currency. + echo "VatBaseTurnover (string): " . Util::formatMoney($bankTransactionLine->getVatBaseTurnover()) . "
"; // string|null + echo "VatBaseValue (\\Money\\Money):
" . print_r($bankTransactionLine->getVatBaseValue(), true) . "

"; // Money|null Only if line type is detail. VAT amount in base currency. + echo "VatBaseValue (string): " . Util::formatMoney($bankTransactionLine->getVatBaseValue()) . "
"; // string|null + echo "VatCode (\\PhpTwinfield\\VatCode):
" . print_r($bankTransactionLine->getVatCode(), true) . "

"; // VatCode|null Only if line type is detail or vat. VAT code. + echo "VatCode (string): " . Util::objectToStr($bankTransactionLine->getVatCode()) . "
"; // string|null + echo "VatRepTotal (\\Money\\Money):
" . print_r($bankTransactionLine->getVatRepTotal(), true) . "

"; // Money|null Only if line type is detail. VAT amount in reporting currency. + echo "VatRepTotal (string): " . Util::formatMoney($bankTransactionLine->getVatRepTotal()) . "
"; // string|null + echo "VatRepTurnover (\\Money\\Money):
" . print_r($bankTransactionLine->getVatRepTurnover(), true) . "

"; // Money|null Only if line type is vat. Amount on which VAT was calculated in reporting currency. + echo "VatRepTurnover (string): " . Util::formatMoney($bankTransactionLine->getVatRepTurnover()) . "
"; // string|null + echo "VatRepValue (\\Money\\Money):
" . print_r($bankTransactionLine->getVatRepValue(), true) . "

"; // Money|null Only if line type is detail. VAT amount in reporting currency. + echo "VatRepValue (string): " . Util::formatMoney($bankTransactionLine->getVatRepValue()) . "
"; // string|null + echo "VatTotal (\\Money\\Money):
" . print_r($bankTransactionLine->getVatTotal(), true) . "

"; // Money|null Only if line type is total. The total VAT amount in the currency of the bank transaction. + echo "VatTotal (string): " . Util::formatMoney($bankTransactionLine->getVatTotal()) . "
"; // string|null + echo "VatTurnover (\\Money\\Money):
" . print_r($bankTransactionLine->getVatTurnover(), true) . "

"; // Money|null Only if line type is vat. Amount on which VAT was calculated in the currency of the bank transaction. + echo "VatTurnover (string): " . Util::formatMoney($bankTransactionLine->getVatTurnover()) . "
"; // string|null + echo "VatValue (\\Money\\Money):
" . print_r($bankTransactionLine->getVatValue(), true) . "

"; // Money|null Only if line type is detail. VAT amount in the currency of the bank transaction. + echo "VatValue (string): " . Util::formatMoney($bankTransactionLine->getVatValue()) . "
"; // string|null + } +} + +// Copy an existing BankTransaction to a new entity +if ($executeCopy) { + try { + $bankTransaction = $transactionApiConnector->get(\PhpTwinfield\BankTransaction::class, "BNK", 201900011, $office); + } catch (ResponseException $e) { + $bankTransaction = $e->getReturnedObject(); + } + + $bankTransaction->setNumber(null); + + //Optional, but recommended so your copy is not posted to final immediately + $bankTransaction->setDestiny(\PhpTwinfield\Enums\Destiny::TEMPORARY()); + + try { + $bankTransactionCopy = $transactionApiConnector->send($bankTransaction); + } catch (ResponseException $e) { + $bankTransactionCopy = $e->getReturnedObject(); + } + + echo "
";
+    print_r($bankTransactionCopy);
+    echo "
"; + + echo "Result of copy process: {$bankTransactionCopy->getResult()}
"; + echo "Number of copied BankTransaction: {$bankTransactionCopy->getNumber()}
"; +} + +// Create a new BankTransaction from scratch, alternatively read an existing BankTransaction as shown above and than modify the values in the same way as shown below +if ($executeNew) { + $bankTransaction = new \PhpTwinfield\BankTransaction; + + // Required values for creating a new BankTransaction + $bankTransaction->setCode('BNK'); // string|null Transaction type code. + $currency = new \PhpTwinfield\Currency; + $currency->setCode('EUR'); + $bankTransaction->setCurrency($currency); // Currency|null Currency code. + //$bankTransaction->setCurrency(\PhpTwinfield\Currency::fromCode("EUR")); // string|null + $bankTransaction->setDestiny(\PhpTwinfield\Enums\Destiny::TEMPORARY()); // Destiny|null Attribute to indicate the destiny of the bank transaction. Only used in the request XML. temporary = bank transaction will be saved as provisional. + //$bankTransaction->setDestiny(\PhpTwinfield\Enums\Destiny::FINAL()); // Destiny|null final = bank transaction will be saved as final. + $bankTransaction->setOffice($office); // Office|null Office code. + $bankTransaction->setOffice(\PhpTwinfield\Office::fromCode($officeCode)); // string|null + + // Optional values for creating a new BankTransaction + $bankTransaction->setAutoBalanceVat(true); // bool|null Should VAT be rounded true or not false? Rounding will only be done with a maximum of two cents. + $date = \DateTime::createFromFormat('d-m-Y', '01-09-2019'); + $bankTransaction->setDate($date); // DateTimeInterface|null Transaction date. Optionally, it is possible to suppress warnings about 'date out of range for the given period' by adding the raisewarning attribute and set its value to false. + $bankTransaction->setDate(Util::parseDate("20190901")); // string|null This overwrites the value of the raisewarning attribute as set on the root element. + $bankTransaction->setDateRaiseWarning(false); // bool|null + //$bankTransaction->setFreeText1('Example FreeText 1'); // string|null Free text field 1 as entered on the transaction type. + //$bankTransaction->setFreeText2('Example FreeText 2'); // string|null Free text field 2 as entered on the transaction type. + //$bankTransaction->setFreeText3('Example FreeText 3'); // string|null Free text field 3 as entered on the transaction type. + //$bankTransaction->setNumber(201900011); // int|null Transaction number. When creating a new bank transaction, don't include this tag as the transaction number is determined by the system. When updating a bank transaction, the related transaction number should be provided. + //$bankTransaction->setPeriod("2019/07"); // string|null Period in YYYY/PP format. If this tag is not included or if it is left empty, the period is determined by the system based on the provided transaction date. + $bankTransaction->setRaiseWarning(true); // bool|null Should warnings be given true or not false? Default true. + //$bankTransactionLine->setStartValue(\Money\Money::EUR(1000)); // Money|null Opening balance. If not provided, the opening balance is set to zero. (Equals 10.00 EUR) + $bankTransaction->setStatementNumber(20); // int|null Number of the bank statement. Don't confuse this number with the transaction number. + + // The minimum amount of BankTransactionLines linked to an BankTransaction object is 2 (1 total, 1 detail) + $bankTransactionLine1 = new \PhpTwinfield\BankTransactionLine; + $bankTransactionLine1->setLineType(\PhpTwinfield\Enums\LineType::TOTAL()); // LineType|null Line type. + + $dim1 = new \PhpTwinfield\GeneralLedger; + $dim1->setCode('1010'); + $bankTransactionLine1->setDim1($dim1); // object|null If line type = total the bank balance account. If line type = detail the customer or supplier balance account or profit and loss account. + $bankTransactionLine1->setDim1(\PhpTwinfield\GeneralLedger::fromCode('1010')); // string|null If line type = vat the VAT balance account. When an empty dim1 is entered, by default the general ledger account will be taken as entered at the VAT code in Twinfield. + $bankTransactionLine1->setID(1); // int|null Line ID. + $bankTransactionLine1->setValue(\Money\Money::EUR(-10000)); // Money|null If line type = total amount including VAT. If line type = detail amount without VAT. If line type = vat VAT amount. + //$bankTransactionLine1->setVatBaseTotal(\Money\Money::EUR(-10000)); // Money|null Only if line type is total. The total VAT amount in base currency. + //$bankTransactionLine1->setVatRepTotal(\Money\Money::EUR(-10000)); // Money|null Only if line type is total. The total VAT amount in reporting currency. + //$bankTransactionLine1->setVatTotal(\Money\Money::EUR(-10000)); // Money|null Only if line type is total. The total VAT amount in the currency of the bank transaction. + + $bankTransaction->addLine($bankTransactionLine1); // BankTransactionLine Add a BankTransactionLine object to the BankTransaction object + + $bankTransactionLine2 = new \PhpTwinfield\BankTransactionLine; + $bankTransactionLine2->setLineType(\PhpTwinfield\Enums\LineType::DETAIL()); // LineType|null Line type. + + $bankTransactionLine2->setBaseValue(\Money\Money::EUR(10000)); // Money|null Amount in the base currency. + $bankTransactionLine2->setDescription("Example Description on line with ID 2"); // string|null Description of the transaction line. + $dim1 = new \PhpTwinfield\GeneralLedger; + $dim1->setCode('2500'); + $bankTransactionLine2->setDim1($dim1); // object|null If line type = total the bank balance account. If line type = detail the customer or supplier balance account or profit and loss account. + $bankTransactionLine2->setDim1(\PhpTwinfield\GeneralLedger::fromCode('2500')); // string|null If line type = vat the VAT balance account. When an empty dim1 is entered, by default the general ledger account will be taken as entered at the VAT code in Twinfield. + $bankTransactionLine2->setID(2); // int|null Line ID. + $bankTransactionLine2->setValue(\Money\Money::EUR(-10000)); // Money|null If line type = total amount including VAT. If line type = detail amount without VAT. If line type = vat VAT amount. + + //$bankTransactionLine2->setComment('Example Comments'); // string|null Comment set on the transaction line. + $currencyDate = \DateTime::createFromFormat('d-m-Y', '01-09-2019'); + //$bankTransaction->setCurrencyDate($currencyDate); // DateTimeInterface|null Only if line type is detail. The line date. Only allowed if the line date in the bank book is set to Allowed or Mandatory. + //$bankTransaction->setCurrencyDate(Util::parseDate("20190901")); // string|null + $destOffice = new \PhpTwinfield\Office; + $destOffice->setCode('1234'); + //$bankTransaction->setDestOffice($destOffice); // Office|null Office code. Used for inter company transactions – here you define in which company the transaction line should be posted. + //$bankTransaction->setDestOffice(\PhpTwinfield\Office::fromCode('1234')); // string|null + $dim2 = new \PhpTwinfield\Customer; + $dim2->setCode('1001'); + //$bankTransactionLine2->setDim2($dim2); // object|null If line type = total empty. If line type = detail the customer or supplier or the cost center or empty. If line type = vat empty. + //$bankTransactionLine2->setDim2(\PhpTwinfield\Customer::fromCode('1001')); // string|null + $dim3 = new \PhpTwinfield\Project; + $dim3->setCode('P0000'); + //$bankTransactionLine2->setDim3($dim3); // object|null If line type = total empty. If line type = detail the project or asset or empty. If line type = vat empty. + //$bankTransactionLine2->setDim3(\PhpTwinfield\Project::fromCode('P0000')); // string|null + //$bankTransactionLine2->setFreeChar('A'); // string|null Free character field. + $performanceCountry = new \PhpTwinfield\Country; + $performanceCountry->setCode('NL'); + //$bankTransactionLine2->setPerformanceCountry($performanceCountry); // Country|null Only if line type is detail or vat. Mandatory in case of an ICT VAT code. The ISO country codes are used. If not added to the request, by default the country code of the customer will be taken. + //$bankTransactionLine2->setPerformanceCountry(\PhpTwinfield\Country::fromCode('NL')); // string|null + $performanceDate = \DateTime::createFromFormat('d-m-Y', '01-09-2019'); + //$bankTransactionLine2->setPerformanceDate($performanceDate); // DateTimeInterface|null Only if line type is detail or vat. Mandatory in case of an ICT VAT code but only if performancetype is services. + //$bankTransactionLine2->setPerformanceDate(Util::parseDate("20190901")); // string|null + //$bankTransactionLine2->setPerformanceType(\PhpTwinfield\Enums\PerformanceType::SERVICES()); // PerformanceType|null Only if line type is detail or vat. Mandatory in case of an ICT VAT code. The performance type. + //$bankTransactionLine2->setPerformanceVatNumber('NL1234567890B01'); // string|null Only if line type is detail or vat. Mandatory in case of an ICT VAT code. If not added to the request, by default the VAT number of the customer will be taken. + //$bankTransactionLine2->setRepValue(\Money\Money::EUR(-10000)); // Money|null Amount in the reporting currency. + //$bankTransactionLine2->setRate(1); // float|null The exchange rate used for the calculation of the base amount. + //$bankTransactionLine2->setRepRate(1); // float|null The exchange rate used for the calculation of the reporting amount. + //$bankTransactionLine2->setVatBaseValue(\Money\Money::EUR(-10000)); // Money|null Only if line type is detail. VAT amount in base currency. + $vatCode = new \PhpTwinfield\VatCode; + $vatCode->setCode('VN'); + //$bankTransactionLine2->setVatCode($vatCode); // VatCode|null Only if line type is detail or vat. VAT code. + //$bankTransactionLine2->setVatCode(\PhpTwinfield\VatCode::fromCode('VN')); // string|null + //$bankTransactionLine2->setVatRepValue(\Money\Money::EUR(-10000)); // Money|null Only if line type is detail. VAT amount in reporting currency. + //$bankTransactionLine2->setVatValue(\Money\Money::EUR(-10000)); // Money|null Only if line type is detail. VAT amount in the currency of the bank transaction. + + $bankTransaction->addLine($bankTransactionLine2); + + //$bankTransactionLine3 = new \PhpTwinfield\BankTransactionLine; + //$bankTransactionLine3->setLineType(\PhpTwinfield\Enums\LineType::VAT()); // LineType|null Line type. + //$bankTransactionLine3->setVatBaseTurnover(\Money\Money::EUR(-10000)); // Money|null Only if line type is vat. Amount on which VAT was calculated in base currency. + //$bankTransactionLine3->setVatRepTurnover(\Money\Money::EUR(-10000)); // Money|null Only if line type is vat. Amount on which VAT was calculated in reporting currency. + //$bankTransactionLine3->setVatTurnover(\Money\Money::EUR(-10000)); // Money|null Only if line type is vat. Amount on which VAT was calculated in the currency of the bank transaction. + + try { + $bankTransactionNew = $transactionApiConnector->send($bankTransaction); + } catch (ResponseException $e) { + $bankTransactionNew = $e->getReturnedObject(); + } + + echo "
";
+    print_r($bankTransactionNew);
+    echo "
"; + + echo "Result of creation process: {$bankTransactionNew->getResult()}
"; + echo "Number of new BankTransaction: {$bankTransactionNew->getNumber()}
"; +} + +// Delete a BrankTransaction based off the passed in office, code, number and given reason +if ($executeDelete) { + $bookingReference = new \PhpTwinfield\BookingReference($office, 'BNK', 201900026); + + try { + $bankTransactionDeleted = $transactionApiConnector->delete($bookingReference, 'Example reason'); + } catch (ResponseException $e) { + $bankTransactionDeleted = $e->getReturnedObject(); + } + + echo "
";
+    print_r($bankTransactionDeleted);
+    echo "
"; +} diff --git a/examples/BrowseData.php b/examples/BrowseData.php index a2d31964..c33fe90d 100644 --- a/examples/BrowseData.php +++ b/examples/BrowseData.php @@ -1,5 +1,4 @@ get(\PhpTwinfield\CashTransaction::class, "KAS", 201900011, $office); + } catch (ResponseException $e) { + $cashTransaction = $e->getReturnedObject(); + } + + echo "
";
+    print_r($cashTransaction);
+    echo "
"; + + echo "CashTransaction
"; + echo "AutoBalanceVat (bool): {$cashTransaction->getAutoBalanceVat()}
"; // bool|null Should VAT be rounded true or not false? Rounding will only be done with a maximum of two cents. + echo "AutoBalanceVat (string): " . Util::formatBoolean($cashTransaction->getAutoBalanceVat()) . "
"; // string|null + echo "BookingReference (\\PhpTwinfield\\BookingReference):
" . print_r($cashTransaction->getBookingReference(), true) . "

"; // BookingReference|null The Booking reference + echo "CloseValue (\\Money\\Money):
" . print_r($cashTransaction->getCloseValue(), true) . "

"; // Money|null Closing balance. If not provided, the closing balance is set to zero. + echo "CloseValue (string): " . Util::formatMoney($cashTransaction->getCloseValue()) . "
"; // string|null + echo "Code: {$cashTransaction->getCode()}
"; // string|null Transaction type code. + echo "Currency (\\PhpTwinfield\\Currency):
" . print_r($cashTransaction->getCurrency(), true) . "

"; // Currency|null Currency code. + echo "Currency (string): " . Util::objectToStr($cashTransaction->getCurrency()) . "
"; // string|null + echo "Date (\\DateTimeInterface):
" . print_r($cashTransaction->getDate(), true) . "

"; // DateTimeInterface|null Transaction date. + echo "Date (string): " . Util::formatDate($cashTransaction->getDate()) . "
"; // string|null + echo "DateRaiseWarning (bool): {$cashTransaction->getDateRaiseWarning()}
"; // bool|null Optionally, it is possible to suppress warnings about 'date out of range for the given period' by adding the raisewarning attribute and set its value to false. + echo "DateRaiseWarning (string): {$cashTransaction->getDateRaiseWarningToString()}
"; // string|null This overwrites the value of the raisewarning attribute as set on the root element. + echo "Destiny: {$cashTransaction->getDestiny()}
"; // Destiny|null Attribute to indicate the destiny of the cash transaction. Only used in the request XML. temporary = cash transaction will be saved as provisional. final = cash transaction will be saved as final. + echo "FreeText1: {$cashTransaction->getFreeText1()}
"; // string|null Free text field 1 as entered on the transaction type. + echo "FreeText2: {$cashTransaction->getFreeText2()}
"; // string|null Free text field 2 as entered on the transaction type. + echo "FreeText3: {$cashTransaction->getFreeText3()}
"; // string|null Free text field 3 as entered on the transaction type. + echo "InputDate (\\DateTimeInterface):
" . print_r($cashTransaction->getInputDate(), true) . "

"; // DateTimeInterface|null The date/time on which the transaction was created. Read-only attribute. + echo "InputDate (string): " . Util::formatDate($cashTransaction->getInputDate()) . "
"; // string|null + + if ($cashTransaction->hasMessages()) { // bool Object contains (error) messages true/false. + echo "Messages: " . print_r($cashTransaction->getMessages(), true) . "
"; // Array|null (Error) messages. + } + + echo "ModificationDate (\\DateTimeInterface):
" . print_r($cashTransaction->getModificationDate(), true) . "

"; // DateTimeInterface|null The date/time on which the cash transaction was modified the last time. Read-only attribute. + echo "ModificationDate (string): " . Util::formatDate($cashTransaction->getModificationDate()) . "
"; // string|null + echo "Number: {$cashTransaction->getNumber()}
"; // int|null Transaction number. When creating a new cash transaction, don't include this tag as the transaction number is determined by the system. When updating a cash transaction, the related transaction number should be provided. + echo "Office (\\PhpTwinfield\\Office):
" . print_r($cashTransaction->getOffice(), true) . "

"; // Office|null Office code. + echo "Office (string): " . Util::objectToStr($cashTransaction->getOffice()) . "
"; // string|null + echo "Origin: {$cashTransaction->getOrigin()}
"; // string|null The cash transaction origin. Read-only attribute. + echo "Period: {$cashTransaction->getPeriod()}
"; // string|null Period in YYYY/PP format. If this tag is not included or if it is left empty, the period is determined by the system based on the provided transaction date. + echo "RaiseWarning (bool): {$cashTransaction->getRaiseWarning()}
"; // bool|null Should warnings be given true or not false? Default true. + echo "RaiseWarning (string): " . Util::formatBoolean($cashTransaction->getRaiseWarning()) . "
"; // string|null + echo "Result: {$cashTransaction->getResult()}
"; // int|null Result (0 = error, 1 or empty = success). + echo "StartValue (\\Money\\Money):
" . print_r($cashTransaction->getStartValue(), true) . "

"; // Money|null Opening balance. If not provided, the opening balance is set to zero. + echo "StartValue (string): " . Util::formatMoney($cashTransaction->getStartValue()) . "
"; // string|null + echo "StatementNumber: {$cashTransaction->getStatementNumber()}
"; // int|null Number of the cash statement. Don't confuse this number with the transaction number. + + $cashTransactionLines = $cashTransaction->getLines(); // array|null Array of CashTransactionLine objects. + + foreach ($cashTransactionLines as $key => $cashTransactionLine) { + echo "CashTransactionLine {$key}
"; + + echo "BaseValue (\\Money\\Money):
" . print_r($cashTransactionLine->getBaseValue(), true) . "

"; // Money|null Amount in the base currency. + echo "BaseValue (string): " . Util::formatMoney($cashTransactionLine->getBaseValue()) . "
"; // string|null + echo "BaseValueOpen (\\Money\\Money):
" . print_r($cashTransactionLine->getBaseValueOpen(), true) . "

"; // Money|null Only if line type is detail. The amount still owed in base currency. Read-only attribute. + echo "BaseValueOpen (string): " . Util::formatMoney($cashTransactionLine->getBaseValueOpen()) . "
"; // string|null + echo "Comment: {$cashTransactionLine->getComment()}
"; // string|null Comment set on the transaction line. + echo "CurrencyDate (\\DateTimeInterface):
" . print_r($cashTransactionLine->getCurrencyDate(), true) . "

"; // DateTimeInterface|null Only if line type is detail. The line date. Only allowed if the line date in the cash book is set to Allowed or Mandatory. + echo "CurrencyDate (string): " . Util::formatDate($cashTransactionLine->getCurrencyDate()) . "
"; // string|null + echo "DebitCredit: {$cashTransactionLine->getDebitCredit()}
"; // DebitCredit|null If line type = total, based on the sum of the individual cash transaction lines. In case of a cash addition debit. In case of a cash withdrawal credit. If line type = detail, credit in case money is received and debit in case money is paid. If line type = vat, based on the sum of the vat amounts of the individual cash transaction lins. In case of a cash addition credit. In case of a cash withdrawal debit. + echo "Description: {$cashTransactionLine->getDescription()}
"; // string|null Description of the transaction line. + echo "DestOffice (\\PhpTwinfield\\Office):
" . print_r($cashTransactionLine->getDestOffice(), true) . "

"; // Office|null Office code. Used for inter company transactions – here you define in which company the transaction line should be posted. + echo "DestOffice (string): " . Util::objectToStr($cashTransactionLine->getDestOffice()) . "
"; // string|null + echo "Dim1:
" . print_r($cashTransactionLine->getDim1(), true) . "

"; // object|null If line type = total the cash balance account. If line type = detail the customer or supplier balance account or profit and loss account. + echo "Dim1 (string): " . Util::objectToStr($cashTransactionLine->getDim1()) . "
"; // string|null If line type = vat the VAT balance account. When an empty dim1 is entered, by default the general ledger account will be taken as entered at the VAT code in Twinfield. + echo "Dim2:
" . print_r($cashTransactionLine->getDim2(), true) . "

"; // object|null If line type = total empty. If line type = detail the customer or supplier or the cost center or empty. + echo "Dim2 (string): " . Util::objectToStr($cashTransactionLine->getDim2()) . "
"; // string|null If line type = vat empty. + echo "Dim3:
" . print_r($cashTransactionLine->getDim2(), true) . "

"; // object|null If line type = total empty. If line type = detail the project or asset or empty. + echo "Dim3 (string): " . Util::objectToStr($cashTransactionLine->getDim3()) . "
"; // string|null If line type = vat empty. + echo "FreeChar: {$cashTransactionLine->getFreeChar()}
"; // string|null Free character field. + echo "ID: {$cashTransactionLine->getID()}
"; // int|null Line ID. + echo "LineType: {$cashTransactionLine->getLineType()}
"; // LineType|null Line type. + echo "MatchLevel: {$cashTransactionLine->getMatchLevel()}
"; // int|null Only if line type is detail. The level of the matchable dimension. Read-only attribute. + echo "MatchStatus: {$cashTransactionLine->getMatchStatus()}
"; // MatchStatus|null Payment status of the cash transaction. If line type total or vat always notmatchable. Read-only attribute. + + if ($cashTransactionLine->hasMessages()) { // bool Object contains (error) messages true/false. + echo "Messages: " . print_r($cashTransactionLine->getMessages(), true) . "
"; // Array|null (Error) messages. + } + + echo "PerformanceCountry (\\PhpTwinfield\\Country):
" . print_r($cashTransactionLine->getPerformanceCountry(), true) . "

"; // Country|null Only if line type is detail or vat. Mandatory in case of an ICT VAT code. The ISO country codes are used. If not added to the request, by default the country code of the customer will be taken. + echo "PerformanceCountry (string): " . Util::objectToStr($cashTransactionLine->getPerformanceCountry()) . "
"; // string|null + echo "PerformanceDate (\\DateTimeInterface):
" . print_r($cashTransactionLine->getPerformanceDate(), true) . "

"; // DateTimeInterface|null Only if line type is detail or vat. Mandatory in case of an ICT VAT code but only if performancetype is services. + echo "PerformanceDate (string): " . Util::formatDate($cashTransactionLine->getPerformanceDate()) . "
"; // string|null + echo "PerformanceType: {$cashTransactionLine->getPerformanceType()}
"; // PerformanceType|null Only if line type is detail or vat. Mandatory in case of an ICT VAT code. The performance type. + echo "PerformanceVatNumber: {$cashTransactionLine->getPerformanceVatNumber()}
"; // string|null Only if line type is detail or vat. Mandatory in case of an ICT VAT code. If not added to the request, by default the VAT number of the customer will be taken. + echo "Rate: {$cashTransactionLine->getRate()}
"; // float|null The exchange rate used for the calculation of the base amount. + echo "Reference (\\PhpTwinfield\\MatchReference):
" . print_r($cashTransactionLine->getReference(), true) . "

"; // MatchReference|null Match reference + echo "Relation: {$cashTransactionLine->getRelation()}
"; // int|null Only if line type is detail. Read-only attribute. + echo "RepRate: {$cashTransactionLine->getRepRate()}
"; // float|null The exchange rate used for the calculation of the reporting amount. + echo "RepValue (\\Money\\Money):
" . print_r($cashTransactionLine->getRepValue(), true) . "

"; // Money|null Amount in the reporting currency. + echo "RepValue (string): " . Util::formatMoney($cashTransactionLine->getRepValue()) . "
"; // string|null + echo "RepValueOpen (\\Money\\Money):
" . print_r($cashTransactionLine->getRepValueOpen(), true) . "

"; // Money|null Only if line type is detail. The amount still owed in reporting currency. Read-only attribute. + echo "RepValueOpen (string): " . Util::formatMoney($cashTransactionLine->getRepValueOpen()) . "
"; // string|null + echo "Result: {$cashTransactionLine->getResult()}
"; // int|null Result (0 = error, 1 or empty = success). + echo "SignedValue (\\Money\\Money):
" . print_r($cashTransactionLine->getSignedValue(), true) . "

"; // Money|null + echo "SignedValue (string): " . Util::formatMoney($cashTransactionLine->getSignedValue()) . "
"; // string|null + echo "Value (\\Money\\Money):
" . print_r($cashTransactionLine->getValue(), true) . "

"; // Money|null If line type = total amount including VAT. If line type = detail amount without VAT. If line type = vat VAT amount. + echo "Value (string): " . Util::formatMoney($cashTransactionLine->getValue()) . "
"; // string|null + echo "VatBaseTotal (\\Money\\Money):
" . print_r($cashTransactionLine->getVatBaseTotal(), true) . "

"; // Money|null Only if line type is total. The total VAT amount in base currency. + echo "VatBaseTotal (string): " . Util::formatMoney($cashTransactionLine->getVatBaseTotal()) . "
"; // string|null + echo "VatBaseTurnover (\\Money\\Money):
" . print_r($cashTransactionLine->getVatBaseTurnover(), true) . "

"; // Money|null Only if line type is vat. Amount on which VAT was calculated in base currency. + echo "VatBaseTurnover (string): " . Util::formatMoney($cashTransactionLine->getVatBaseTurnover()) . "
"; // string|null + echo "VatBaseValue (\\Money\\Money):
" . print_r($cashTransactionLine->getVatBaseValue(), true) . "

"; // Money|null Only if line type is detail. VAT amount in base currency. + echo "VatBaseValue (string): " . Util::formatMoney($cashTransactionLine->getVatBaseValue()) . "
"; // string|null + echo "VatCode (\\PhpTwinfield\\VatCode):
" . print_r($cashTransactionLine->getVatCode(), true) . "

"; // VatCode|null Only if line type is detail or vat. VAT code. + echo "VatCode (string): " . Util::objectToStr($cashTransactionLine->getVatCode()) . "
"; // string|null + echo "VatRepTotal (\\Money\\Money):
" . print_r($cashTransactionLine->getVatRepTotal(), true) . "

"; // Money|null Only if line type is detail. VAT amount in reporting currency. + echo "VatRepTotal (string): " . Util::formatMoney($cashTransactionLine->getVatRepTotal()) . "
"; // string|null + echo "VatRepTurnover (\\Money\\Money):
" . print_r($cashTransactionLine->getVatRepTurnover(), true) . "

"; // Money|null Only if line type is vat. Amount on which VAT was calculated in reporting currency. + echo "VatRepTurnover (string): " . Util::formatMoney($cashTransactionLine->getVatRepTurnover()) . "
"; // string|null + echo "VatRepValue (\\Money\\Money):
" . print_r($cashTransactionLine->getVatRepValue(), true) . "

"; // Money|null Only if line type is detail. VAT amount in reporting currency. + echo "VatRepValue (string): " . Util::formatMoney($cashTransactionLine->getVatRepValue()) . "
"; // string|null + echo "VatTotal (\\Money\\Money):
" . print_r($cashTransactionLine->getVatTotal(), true) . "

"; // Money|null Only if line type is total. The total VAT amount in the currency of the cash transaction. + echo "VatTotal (string): " . Util::formatMoney($cashTransactionLine->getVatTotal()) . "
"; // string|null + echo "VatTurnover (\\Money\\Money):
" . print_r($cashTransactionLine->getVatTurnover(), true) . "

"; // Money|null Only if line type is vat. Amount on which VAT was calculated in the currency of the cash transaction. + echo "VatTurnover (string): " . Util::formatMoney($cashTransactionLine->getVatTurnover()) . "
"; // string|null + echo "VatValue (\\Money\\Money):
" . print_r($cashTransactionLine->getVatValue(), true) . "

"; // Money|null Only if line type is detail. VAT amount in the currency of the cash transaction. + echo "VatValue (string): " . Util::formatMoney($cashTransactionLine->getVatValue()) . "
"; // string|null + } +} + +// Copy an existing CashTransaction to a new entity +if ($executeCopy) { + try { + $cashTransaction = $transactionApiConnector->get(\PhpTwinfield\CashTransaction::class, "KAS", 201900011, $office); + } catch (ResponseException $e) { + $cashTransaction = $e->getReturnedObject(); + } + + $cashTransaction->setNumber(null); + + //Optional, but recommended so your copy is not posted to final immediately + $cashTransaction->setDestiny(\PhpTwinfield\Enums\Destiny::TEMPORARY()); + + try { + $cashTransactionCopy = $transactionApiConnector->send($cashTransaction); + } catch (ResponseException $e) { + $cashTransactionCopy = $e->getReturnedObject(); + } + + echo "
";
+    print_r($cashTransactionCopy);
+    echo "
"; + + echo "Result of copy process: {$cashTransactionCopy->getResult()}
"; + echo "Number of copied CashTransaction: {$cashTransactionCopy->getNumber()}
"; +} + +// Create a new CashTransaction from scratch, alternatively read an existing CashTransaction as shown above and than modify the values in the same way as shown below +if ($executeNew) { + $cashTransaction = new \PhpTwinfield\CashTransaction; + + // Required values for creating a new CashTransaction + $cashTransaction->setCode('KAS'); // string|null Transaction type code. + $currency = new \PhpTwinfield\Currency; + $currency->setCode('EUR'); + $cashTransaction->setCurrency($currency); // Currency|null Currency code. + //$cashTransaction->setCurrency(\PhpTwinfield\Currency::fromCode("EUR")); // string|null + $cashTransaction->setDestiny(\PhpTwinfield\Enums\Destiny::TEMPORARY()); // Destiny|null Attribute to indicate the destiny of the cash transaction. Only used in the request XML. temporary = cash transaction will be saved as provisional. + //$cashTransaction->setDestiny(\PhpTwinfield\Enums\Destiny::FINAL()); // Destiny|null final = cash transaction will be saved as final. + $cashTransaction->setOffice($office); // Office|null Office code. + $cashTransaction->setOffice(\PhpTwinfield\Office::fromCode($officeCode)); // string|null + + // Optional values for creating a new CashTransaction + $cashTransaction->setAutoBalanceVat(true); // bool|null Should VAT be rounded true or not false? Rounding will only be done with a maximum of two cents. + $date = \DateTime::createFromFormat('d-m-Y', '01-09-2019'); + $cashTransaction->setDate($date); // DateTimeInterface|null Transaction date. Optionally, it is possible to suppress warnings about 'date out of range for the given period' by adding the raisewarning attribute and set its value to false. + $cashTransaction->setDate(Util::parseDate("20190901")); // string|null This overwrites the value of the raisewarning attribute as set on the root element. + $cashTransaction->setDateRaiseWarning(false); // bool|null + //$cashTransaction->setFreeText1('Example FreeText 1'); // string|null Free text field 1 as entered on the transaction type. + //$cashTransaction->setFreeText2('Example FreeText 2'); // string|null Free text field 2 as entered on the transaction type. + //$cashTransaction->setFreeText3('Example FreeText 3'); // string|null Free text field 3 as entered on the transaction type. + //$cashTransaction->setNumber(201900011); // int|null Transaction number. When creating a new cash transaction, don't include this tag as the transaction number is determined by the system. When updating a cash transaction, the related transaction number should be provided. + //$cashTransaction->setPeriod("2019/07"); // string|null Period in YYYY/PP format. If this tag is not included or if it is left empty, the period is determined by the system based on the provided transaction date. + $cashTransaction->setRaiseWarning(true); // bool|null Should warnings be given true or not false? Default true. + //$cashTransactionLine->setStartValue(\Money\Money::EUR(1000)); // Money|null Opening balance. If not provided, the opening balance is set to zero. (Equals 10.00 EUR) + $cashTransaction->setStatementNumber(20); // int|null Number of the cash statement. Don't confuse this number with the transaction number. + + // The minimum amount of CashTransactionLines linked to an CashTransaction object is 2 (1 total, 1 detail) + $cashTransactionLine1 = new \PhpTwinfield\CashTransactionLine; + $cashTransactionLine1->setLineType(\PhpTwinfield\Enums\LineType::TOTAL()); // LineType|null Line type. + + $dim1 = new \PhpTwinfield\GeneralLedger; + $dim1->setCode('1010'); + $cashTransactionLine1->setDim1($dim1); // object|null If line type = total the cash balance account. If line type = detail the customer or supplier balance account or profit and loss account. + $cashTransactionLine1->setDim1(\PhpTwinfield\GeneralLedger::fromCode('1010')); // string|null If line type = vat the VAT balance account. When an empty dim1 is entered, by default the general ledger account will be taken as entered at the VAT code in Twinfield. + $cashTransactionLine1->setID(1); // int|null Line ID. + $cashTransactionLine1->setValue(\Money\Money::EUR(-10000)); // Money|null If line type = total amount including VAT. If line type = detail amount without VAT. If line type = vat VAT amount. + //$cashTransactionLine1->setVatBaseTotal(\Money\Money::EUR(-10000)); // Money|null Only if line type is total. The total VAT amount in base currency. + //$cashTransactionLine1->setVatRepTotal(\Money\Money::EUR(-10000)); // Money|null Only if line type is total. The total VAT amount in reporting currency. + //$cashTransactionLine1->setVatTotal(\Money\Money::EUR(-10000)); // Money|null Only if line type is total. The total VAT amount in the currency of the cash transaction. + + $cashTransaction->addLine($cashTransactionLine1); // CashTransactionLine Add a CashTransactionLine object to the CashTransaction object + + $cashTransactionLine2 = new \PhpTwinfield\CashTransactionLine; + $cashTransactionLine2->setLineType(\PhpTwinfield\Enums\LineType::DETAIL()); // LineType|null Line type. + + $cashTransactionLine2->setBaseValue(\Money\Money::EUR(10000)); // Money|null Amount in the base currency. + $cashTransactionLine2->setDescription("Example Description on line with ID 2"); // string|null Description of the transaction line. + $dim1 = new \PhpTwinfield\GeneralLedger; + $dim1->setCode('2500'); + $cashTransactionLine2->setDim1($dim1); // object|null If line type = total the cash balance account. If line type = detail the customer or supplier balance account or profit and loss account. + $cashTransactionLine2->setDim1(\PhpTwinfield\GeneralLedger::fromCode('2500')); // string|null If line type = vat the VAT balance account. When an empty dim1 is entered, by default the general ledger account will be taken as entered at the VAT code in Twinfield. + $cashTransactionLine2->setID(2); // int|null Line ID. + $cashTransactionLine2->setValue(\Money\Money::EUR(-10000)); // Money|null If line type = total amount including VAT. If line type = detail amount without VAT. If line type = vat VAT amount. + + //$cashTransactionLine2->setComment('Example Comments'); // string|null Comment set on the transaction line. + $currencyDate = \DateTime::createFromFormat('d-m-Y', '01-09-2019'); + //$cashTransaction->setCurrencyDate($currencyDate); // DateTimeInterface|null Only if line type is detail. The line date. Only allowed if the line date in the cash book is set to Allowed or Mandatory. + //$cashTransaction->setCurrencyDate(Util::parseDate("20190901")); // string|null + $destOffice = new \PhpTwinfield\Office; + $destOffice->setCode('1234'); + //$cashTransaction->setDestOffice($destOffice); // Office|null Office code. Used for inter company transactions – here you define in which company the transaction line should be posted. + //$cashTransaction->setDestOffice(\PhpTwinfield\Office::fromCode('1234')); // string|null + $dim2 = new \PhpTwinfield\Customer; + $dim2->setCode('1001'); + //$cashTransactionLine2->setDim2($dim2); // object|null If line type = total empty. If line type = detail the customer or supplier or the cost center or empty. If line type = vat empty. + //$cashTransactionLine2->setDim2(\PhpTwinfield\Customer::fromCode('1001')); // string|null + $dim3 = new \PhpTwinfield\Project; + $dim3->setCode('P0000'); + //$cashTransactionLine2->setDim3($dim3); // object|null If line type = total empty. If line type = detail the project or asset or empty. If line type = vat empty. + //$cashTransactionLine2->setDim3(\PhpTwinfield\Project::fromCode('P0000')); // string|null + //$cashTransactionLine2->setFreeChar('A'); // string|null Free character field. + $performanceCountry = new \PhpTwinfield\Country; + $performanceCountry->setCode('NL'); + //$cashTransactionLine2->setPerformanceCountry($performanceCountry); // Country|null Only if line type is detail or vat. Mandatory in case of an ICT VAT code. The ISO country codes are used. If not added to the request, by default the country code of the customer will be taken. + //$cashTransactionLine2->setPerformanceCountry(\PhpTwinfield\Country::fromCode('NL')); // string|null + $performanceDate = \DateTime::createFromFormat('d-m-Y', '01-09-2019'); + //$cashTransactionLine2->setPerformanceDate($performanceDate); // DateTimeInterface|null Only if line type is detail or vat. Mandatory in case of an ICT VAT code but only if performancetype is services. + //$cashTransactionLine2->setPerformanceDate(Util::parseDate("20190901")); // string|null + //$cashTransactionLine2->setPerformanceType(\PhpTwinfield\Enums\PerformanceType::SERVICES()); // PerformanceType|null Only if line type is detail or vat. Mandatory in case of an ICT VAT code. The performance type. + //$cashTransactionLine2->setPerformanceVatNumber('NL1234567890B01'); // string|null Only if line type is detail or vat. Mandatory in case of an ICT VAT code. If not added to the request, by default the VAT number of the customer will be taken. + //$cashTransactionLine2->setRepValue(\Money\Money::EUR(-10000)); // Money|null Amount in the reporting currency. + //$cashTransactionLine2->setRate(1); // float|null The exchange rate used for the calculation of the base amount. + //$cashTransactionLine2->setRepRate(1); // float|null The exchange rate used for the calculation of the reporting amount. + //$cashTransactionLine2->setVatBaseValue(\Money\Money::EUR(-10000)); // Money|null Only if line type is detail. VAT amount in base currency. + $vatCode = new \PhpTwinfield\VatCode; + $vatCode->setCode('VN'); + //$cashTransactionLine2->setVatCode($vatCode); // VatCode|null Only if line type is detail or vat. VAT code. + //$cashTransactionLine2->setVatCode(\PhpTwinfield\VatCode::fromCode('VN')); // string|null + //$cashTransactionLine2->setVatRepValue(\Money\Money::EUR(-10000)); // Money|null Only if line type is detail. VAT amount in reporting currency. + //$cashTransactionLine2->setVatValue(\Money\Money::EUR(-10000)); // Money|null Only if line type is detail. VAT amount in the currency of the cash transaction. + + $cashTransaction->addLine($cashTransactionLine2); + + //$cashTransactionLine3 = new \PhpTwinfield\CashTransactionLine; + //$cashTransactionLine3->setLineType(\PhpTwinfield\Enums\LineType::VAT()); // LineType|null Line type. + //$cashTransactionLine3->setVatBaseTurnover(\Money\Money::EUR(-10000)); // Money|null Only if line type is vat. Amount on which VAT was calculated in base currency. + //$cashTransactionLine3->setVatRepTurnover(\Money\Money::EUR(-10000)); // Money|null Only if line type is vat. Amount on which VAT was calculated in reporting currency. + //$cashTransactionLine3->setVatTurnover(\Money\Money::EUR(-10000)); // Money|null Only if line type is vat. Amount on which VAT was calculated in the currency of the cash transaction. + + try { + $cashTransactionNew = $transactionApiConnector->send($cashTransaction); + } catch (ResponseException $e) { + $cashTransactionNew = $e->getReturnedObject(); + } + + echo "
";
+    print_r($cashTransactionNew);
+    echo "
"; + + echo "Result of creation process: {$cashTransactionNew->getResult()}
"; + echo "Number of new CashTransaction: {$cashTransactionNew->getNumber()}
"; +} + +// Delete a BrankTransaction based off the passed in office, code, number and given reason +if ($executeDelete) { + $bookingReference = new \PhpTwinfield\BookingReference($office, 'KAS', 201900026); + + try { + $cashTransactionDeleted = $transactionApiConnector->delete($bookingReference, 'Example reason'); + } catch (ResponseException $e) { + $cashTransactionDeleted = $e->getReturnedObject(); + } + + echo "
";
+    print_r($cashTransactionDeleted);
+    echo "
"; +} diff --git a/examples/Connection.php b/examples/Connection.php index 78db7813..0430c415 100644 --- a/examples/Connection.php +++ b/examples/Connection.php @@ -1,5 +1,8 @@ getMessages(), true) . "
"; // Array|null (Error) messages. } + echo "Office (\\PhpTwinfield\\Office):
" . print_r($invoice->getOffice(), true) . "

"; // Office|null Office code. + echo "Office (string): " . Util::objectToStr($invoice->getOffice()) . "
"; // string|null echo "PaymentMethod: {$invoice->getPaymentMethod()}
"; // PaymentMethod|null The payment method. echo "PerformanceDate (\\DateTimeInterface):
" . print_r($invoice->getPerformanceDate(), true) . "

"; // DateTimeInterface|null Performance date, when set-up on the invoice header. echo "PerformanceDate (string): " . Util::formatDate($invoice->getPerformanceDate()) . "
"; // string|null echo "Period: {$invoice->getPeriod()}
"; // string|null Period in YYYY/PP format. - echo "Office (\\PhpTwinfield\\Office):
" . print_r($invoice->getOffice(), true) . "

"; // Office|null Office code. - echo "Office (string): " . Util::objectToStr($invoice->getOffice()) . "
"; // string|null echo "Result: {$invoice->getResult()}
"; // int|null Result (0 = error, 1 or empty = success). echo "Status: {$invoice->getStatus()}
"; // Status|null Status of the invoice. @@ -368,7 +370,7 @@ //$invoiceLine->setUnitsPriceInc(\Money\Money::EUR(1210)); // Money|null Only valid for invoice types with VAT inclusive units prices. Only add this tag to an XML request if the setting Prices can be changed on an item is set to true. Otherwise, the price will be determined by the system. (Equals 12.10 EUR) $vatCode = new \PhpTwinfield\VatCode; $vatCode->setCode('VH'); - //$invoiceLine->getVatCode($vatCode); // VatCode|null VAT code. + //$invoiceLine->setVatCode($vatCode); // VatCode|null VAT code. //$invoiceLine->setVatCode(\PhpTwinfield\VatCode::fromCode('VH')); // string|null $invoice->addLine($invoiceLine); // InvoiceLine Add an InvoiceLine object to the Invoice object diff --git a/examples/InvoiceType.php b/examples/InvoiceType.php index 9ebf23e7..964c3d71 100644 --- a/examples/InvoiceType.php +++ b/examples/InvoiceType.php @@ -1,10 +1,12 @@ messages)) { + return false; + } + return count($this->messages) > 0; } } diff --git a/src/Fields/Transaction/CloseAndStartValueFields.php b/src/Fields/Transaction/CloseAndStartValueFields.php index 9f57fe80..350c3787 100644 --- a/src/Fields/Transaction/CloseAndStartValueFields.php +++ b/src/Fields/Transaction/CloseAndStartValueFields.php @@ -63,16 +63,23 @@ public function getStartValue(): ?Money */ public function setStartValue(?Money $startValue): void { - $currency = new Currency(); - $currency->setCode($startValue->getCurrency()); + if (!empty($startValue->getCurrency())) { + $currency = \PhpTwinfield\Currency::fromCode($startValue->getCurrency()); + $this->currency = $currency; + } - $this->currency = $currency; $this->startValue = $startValue; $this->closeValue = $startValue; } public function getCloseValue(): Money { - return $this->closeValue ?? new Money(0, new \Money\Currency($this->getCurrency()->getCode())); + if (!empty($this->getCurrency())) { + $currencyCode = $this->getCurrency()->getCode(); + } else { + $currencyCode = 'EUR'; + } + + return $this->closeValue ?? new Money(0, new \Money\Currency($currencyCode)); } } diff --git a/src/InvoiceLine.php b/src/InvoiceLine.php index 44ebc6f4..6f40558f 100644 --- a/src/InvoiceLine.php +++ b/src/InvoiceLine.php @@ -53,5 +53,6 @@ public function __construct($quantity = null, $article = null, $freeText1 = null $this->article = $article; $this->setFreeText1($freeText1); $this->setFreeText2($freeText2); + $this->setAllowDiscountOrPremium(true); } } diff --git a/src/Mappers/BaseMapper.php b/src/Mappers/BaseMapper.php index c0494389..a294358b 100644 --- a/src/Mappers/BaseMapper.php +++ b/src/Mappers/BaseMapper.php @@ -120,6 +120,8 @@ protected static function parseUnknownEntity(HasMessageInterface $object, \DOMEl { if (is_a($object, \PhpTwinfield\DimensionGroupDimension::class)) { $type = self::getField($element, "type", $object); + } elseif (is_a($object, \PhpTwinfield\TransactionLineInterface::class)) { + $type = self::getAttribute($element, $fieldTagName, "type"); } else { $type = self::getAttribute($element, $fieldTagName, "dimensiontype"); } @@ -142,6 +144,10 @@ protected static function parseUnknownEntity(HasMessageInterface $object, \DOMEl case "PRJ": return \PhpTwinfield\Project::class; default: + if (is_a($object, \PhpTwinfield\TransactionLineInterface::class)) { + return \PhpTwinfield\GeneralLedger::class; + } + throw new \InvalidArgumentException("parseUnknownEntity function was unable to determine class name from \"{$type}\""); } } diff --git a/src/Mappers/TransactionMapper.php b/src/Mappers/TransactionMapper.php index c3a113c1..3ef2773d 100644 --- a/src/Mappers/TransactionMapper.php +++ b/src/Mappers/TransactionMapper.php @@ -158,7 +158,7 @@ public static function map(string $transactionClassName, Response $response, Aut ->setDebitCredit(self::parseEnumAttribute(\PhpTwinfield\Enums\DebitCredit::class, self::getField($lineElement, 'debitcredit', $transactionLine))) ->setDescription(self::getField($lineElement, 'description', $transactionLine)) ->setDestOffice(self::parseObjectAttribute(\PhpTwinfield\Office::class, $transactionLine, $lineElement, 'destoffice')) - ->setDim1(self::parseObjectAttribute(null, $transactionLine, $lineElement, 'dim1', array('name' => 'setName', 'shortname' => 'setShortName', 'dimensiontype' => 'setTypeFromString'))) + ->setDim1(self::parseObjectAttribute(null, $transactionLine, $lineElement, 'dim1', array('name' => 'setName', 'shortname' => 'setShortName', 'type' => 'setTypeFromString'))) ->setId($lineElement->getAttribute('id')) ->setMatchStatus(self::parseEnumAttribute(\PhpTwinfield\Enums\MatchStatus::class, self::getField($lineElement, 'matchstatus', $transactionLine))) ->setRate(self::getField($lineElement, 'rate', $transactionLine)) @@ -179,8 +179,8 @@ public static function map(string $transactionClassName, Response $response, Aut $transactionLine->setBaseValueOpen(self::parseMoneyAttribute($baseValueOpen, $currencies['base'])); } - $transactionLine->setDim2(self::parseObjectAttribute(null, $transactionLine, $lineElement, 'dim2', array('name' => 'setName', 'shortname' => 'setShortName', 'dimensiontype' => 'setTypeFromString'))); - $transactionLine->setDim3(self::parseObjectAttribute(null, $transactionLine, $lineElement, 'dim3', array('name' => 'setName', 'shortname' => 'setShortName', 'dimensiontype' => 'setTypeFromString'))); + $transactionLine->setDim2(self::parseObjectAttribute(null, $transactionLine, $lineElement, 'dim2', array('name' => 'setName', 'shortname' => 'setShortName', 'type' => 'setTypeFromString'))); + $transactionLine->setDim3(self::parseObjectAttribute(null, $transactionLine, $lineElement, 'dim3', array('name' => 'setName', 'shortname' => 'setShortName', 'type' => 'setTypeFromString'))); $transactionLine->setMatchLevel(self::getField($lineElement, 'matchlevel', $transactionLine)); $transactionLine->setRelation(self::getField($lineElement, 'relation', $transactionLine)); $transactionLine->setRepValueOpen(self::parseMoneyAttribute(self::getField($lineElement, 'repvalueopen', $transactionLine), $currencies['reporting'])); @@ -189,12 +189,12 @@ public static function map(string $transactionClassName, Response $response, Aut if ($transaction instanceof PurchaseTransaction || $transaction instanceof SalesTransaction) { if ($lineType == LineType::DETAIL()) { - $transactionLine->setDim2(self::parseObjectAttribute(null, $transactionLine, $lineElement, 'dim2', array('name' => 'setName', 'shortname' => 'setShortName', 'dimensiontype' => 'setTypeFromString'))); - $transactionLine->setDim3(self::parseObjectAttribute(null, $transactionLine, $lineElement, 'dim3', array('name' => 'setName', 'shortname' => 'setShortName', 'dimensiontype' => 'setTypeFromString'))); + $transactionLine->setDim2(self::parseObjectAttribute(null, $transactionLine, $lineElement, 'dim2', array('name' => 'setName', 'shortname' => 'setShortName', 'type' => 'setTypeFromString'))); + $transactionLine->setDim3(self::parseObjectAttribute(null, $transactionLine, $lineElement, 'dim3', array('name' => 'setName', 'shortname' => 'setShortName', 'type' => 'setTypeFromString'))); } elseif ($transaction instanceof PurchaseTransaction && $lineType == LineType::VAT()) { - $transactionLine->setDim3(self::parseObjectAttribute(null, $transactionLine, $lineElement, 'dim3', array('name' => 'setName', 'shortname' => 'setShortName', 'dimensiontype' => 'setTypeFromString'))); + $transactionLine->setDim3(self::parseObjectAttribute(null, $transactionLine, $lineElement, 'dim3', array('name' => 'setName', 'shortname' => 'setShortName', 'type' => 'setTypeFromString'))); } elseif ($lineType == LineType::TOTAL()) { - $transactionLine->setDim2(self::parseObjectAttribute(null, $transactionLine, $lineElement, 'dim2', array('name' => 'setName', 'shortname' => 'setShortName', 'dimensiontype' => 'setTypeFromString'))); + $transactionLine->setDim2(self::parseObjectAttribute(null, $transactionLine, $lineElement, 'dim2', array('name' => 'setName', 'shortname' => 'setShortName', 'type' => 'setTypeFromString'))); $baseValueOpen = self::getField($lineElement, 'basevalueopen', $transactionLine) ?: self::getField($lineElement, 'openbasevalue', $transactionLine); From a366c7716a7b76dc77d41c827a5c5c3cf89de6c6 Mon Sep 17 00:00:00 2001 From: iranl Date: Tue, 9 Jul 2019 18:24:59 +0200 Subject: [PATCH 5/5] Upload --- src/ApiConnectors/ArticleApiConnector.php | 21 --------------- src/ApiConnectors/AssetMethodApiConnector.php | 21 --------------- src/ApiConnectors/BaseApiConnector.php | 27 +++---------------- src/ApiConnectors/CurrencyApiConnector.php | 10 ------- src/ApiConnectors/HasEqualInterface.php | 3 --- src/ApiConnectors/RateApiConnector.php | 21 --------------- src/ApiConnectors/VatCodeApiConnector.php | 20 -------------- 7 files changed, 4 insertions(+), 119 deletions(-) diff --git a/src/ApiConnectors/ArticleApiConnector.php b/src/ApiConnectors/ArticleApiConnector.php index d4ba546d..b397edfb 100644 --- a/src/ApiConnectors/ArticleApiConnector.php +++ b/src/ApiConnectors/ArticleApiConnector.php @@ -9,7 +9,6 @@ use PhpTwinfield\Mappers\ArticleMapper; use PhpTwinfield\Office; use PhpTwinfield\Request as Request; -use PhpTwinfield\Response\IndividualMappedResponse; use PhpTwinfield\Response\MappedResponseCollection; use PhpTwinfield\Response\Response; use PhpTwinfield\Response\ResponseException; @@ -130,26 +129,6 @@ public function testEqual(HasMessageInterface $returnedObject, HasMessageInterfa return [$equal, $returnedObject]; } - /** - * @param HasMessageInterface $returnedObject - * @return IndividualMappedResponse - */ - public function getMappedResponse(HasMessageInterface $returnedObject, HasMessageInterface $sentObject): IndividualMappedResponse - { - Assert::IsInstanceOf($returnedObject, Article::class); - - $request_article = new Request\Read\Article(); - $request_article->setOffice($returnedObject->getOffice()) - ->setCode($returnedObject->getCode()); - $response = $this->sendXmlDocument($request_article); - - $mappedResponseCollection = $this->getProcessXmlService()->mapAll([$response], "article", function(Response $response): Article { - return ArticleMapper::map($response, $this->getConnection()); - }); - - return ($mappedResponseCollection[0]); - } - /** * List all articles. * diff --git a/src/ApiConnectors/AssetMethodApiConnector.php b/src/ApiConnectors/AssetMethodApiConnector.php index 823b3920..cba801be 100644 --- a/src/ApiConnectors/AssetMethodApiConnector.php +++ b/src/ApiConnectors/AssetMethodApiConnector.php @@ -9,7 +9,6 @@ use PhpTwinfield\Mappers\AssetMethodMapper; use PhpTwinfield\Office; use PhpTwinfield\Request as Request; -use PhpTwinfield\Response\IndividualMappedResponse; use PhpTwinfield\Response\MappedResponseCollection; use PhpTwinfield\Response\Response; use PhpTwinfield\Response\ResponseException; @@ -133,26 +132,6 @@ public function testEqual(HasMessageInterface $returnedObject, HasMessageInterfa return [$equal, $returnedObject]; } - /** - * @param HasMessageInterface $returnedObject - * @return IndividualMappedResponse - */ - public function getMappedResponse(HasMessageInterface $returnedObject, HasMessageInterface $sentObject): IndividualMappedResponse - { - Assert::IsInstanceOf($returnedObject, AssetMethod::class); - - $request_assetMethod = new Request\AssetMethod(); - $request_assetMethod->setOffice($returnedObject->getOffice()) - ->setCode($returnedObject->getCode()); - $response = $this->sendXmlDocument($request_assetMethod); - - $mappedResponseCollection = $this->getProcessXmlService()->mapAll([$response], "assetmethod", function(Response $response): AssetMethod { - return AssetMethodMapper::map($response); - }); - - return ($mappedResponseCollection[0]); - } - /** * List all asset methods. * diff --git a/src/ApiConnectors/BaseApiConnector.php b/src/ApiConnectors/BaseApiConnector.php index 1a1872cc..c70cc81d 100644 --- a/src/ApiConnectors/BaseApiConnector.php +++ b/src/ApiConnectors/BaseApiConnector.php @@ -262,29 +262,10 @@ public function testSentEqualsResponse(HasEqualInterface $apiConnector, array $s $returnedObject = $testResult[1]; if (!$equal) { - $tempMappedResponse = $apiConnector->sendAll([$returnedObject], true)[0]; - $tempReturnedObject = $tempMappedResponse->unwrap(); - - if ($tempReturnedObject->getResult() == 1) { - $individualMappedResponse = $tempMappedResponse; - $returnedObject = $tempReturnedObject; - - $testResult = $apiConnector->testEqual($returnedObject, $sentObjects[$key]); - $equal = $testResult[0]; - $returnedObject = $testResult[1]; - - if (!$equal || is_a($returnedObject, \PhpTwinfield\Currency::class)) { - sleep(2); - - $tempMappedResponse = $apiConnector->getMappedResponse($returnedObject, $sentObjects[$key]); - $tempReturnedObject = $tempMappedResponse->unwrap(); - - if ($returnedObject->getResult() == 1) { - $individualMappedResponse = $tempMappedResponse; - $returnedObject = $tempReturnedObject; - } - } - } + $apiConnector->sendAll([$returnedObject], true)[0]; + sleep(2); + $sentObjects[$key]->setCode($returnedObject->getCode()); + $individualMappedResponse = $apiConnector->sendAll([$sentObjects[$key]], true)[0]; } } diff --git a/src/ApiConnectors/CurrencyApiConnector.php b/src/ApiConnectors/CurrencyApiConnector.php index 42188182..acbe5bf3 100644 --- a/src/ApiConnectors/CurrencyApiConnector.php +++ b/src/ApiConnectors/CurrencyApiConnector.php @@ -9,7 +9,6 @@ use PhpTwinfield\Mappers\CurrencyMapper; use PhpTwinfield\Office; use PhpTwinfield\Request as Request; -use PhpTwinfield\Response\IndividualMappedResponse; use PhpTwinfield\Response\MappedResponseCollection; use PhpTwinfield\Response\Response; use PhpTwinfield\Response\ResponseException; @@ -170,15 +169,6 @@ public function testEqual(HasMessageInterface $returnedObject, HasMessageInterfa return [$equal, $returnedObject]; } - /** - * @param HasMessageInterface $returnedObject - * @return IndividualMappedResponse - */ - public function getMappedResponse(HasMessageInterface $returnedObject, HasMessageInterface $sentObject): IndividualMappedResponse - { - return $this->sendAll([$sentObject], true)[0]; - } - /** * List all currencies. * diff --git a/src/ApiConnectors/HasEqualInterface.php b/src/ApiConnectors/HasEqualInterface.php index 8b2dbfd8..08fb75d9 100644 --- a/src/ApiConnectors/HasEqualInterface.php +++ b/src/ApiConnectors/HasEqualInterface.php @@ -3,7 +3,6 @@ namespace PhpTwinfield\ApiConnectors; use PhpTwinfield\HasMessageInterface; -use PhpTwinfield\Response\IndividualMappedResponse; use PhpTwinfield\Response\MappedResponseCollection; /** @@ -15,6 +14,4 @@ interface HasEqualInterface public function testEqual(HasMessageInterface $returnedObject, HasMessageInterface $sentObject): array; public function sendAll(array $objects, bool $reSend): MappedResponseCollection; - - public function getMappedResponse(HasMessageInterface $returnedObject, HasMessageInterface $sentObject): IndividualMappedResponse; } diff --git a/src/ApiConnectors/RateApiConnector.php b/src/ApiConnectors/RateApiConnector.php index 9ad8300c..c4895c2c 100644 --- a/src/ApiConnectors/RateApiConnector.php +++ b/src/ApiConnectors/RateApiConnector.php @@ -9,7 +9,6 @@ use PhpTwinfield\Office; use PhpTwinfield\Rate; use PhpTwinfield\Request as Request; -use PhpTwinfield\Response\IndividualMappedResponse; use PhpTwinfield\Response\MappedResponseCollection; use PhpTwinfield\Response\Response; use PhpTwinfield\Response\ResponseException; @@ -131,26 +130,6 @@ public function testEqual(HasMessageInterface $returnedObject, HasMessageInterfa return [$equal, $returnedObject]; } - /** - * @param HasMessageInterface $returnedObject - * @return IndividualMappedResponse - */ - public function getMappedResponse(HasMessageInterface $returnedObject, HasMessageInterface $sentObject): IndividualMappedResponse - { - Assert::IsInstanceOf($returnedObject, Rate::class); - - $request_rate = new Request\Read\Rate(); - $request_rate->setOffice($returnedObject->getOffice()) - ->setCode($returnedObject->getCode()); - $response = $this->sendXmlDocument($request_rate); - - $mappedResponseCollection = $this->getProcessXmlService()->mapAll([$response], "projectrate", function(Response $response): Rate { - return RateMapper::map($response); - }); - - return ($mappedResponseCollection[0]); - } - /** * List all rates. * diff --git a/src/ApiConnectors/VatCodeApiConnector.php b/src/ApiConnectors/VatCodeApiConnector.php index 79b24c88..5bf33578 100644 --- a/src/ApiConnectors/VatCodeApiConnector.php +++ b/src/ApiConnectors/VatCodeApiConnector.php @@ -8,7 +8,6 @@ use PhpTwinfield\Mappers\VatCodeMapper; use PhpTwinfield\Office; use PhpTwinfield\Request as Request; -use PhpTwinfield\Response\IndividualMappedResponse; use PhpTwinfield\Response\MappedResponseCollection; use PhpTwinfield\Response\Response; use PhpTwinfield\Response\ResponseException; @@ -132,25 +131,6 @@ public function testEqual(HasMessageInterface $returnedObject, HasMessageInterfa return [$equal, $returnedObject]; } - /** - * @param HasMessageInterface $returnedObject - * @return IndividualMappedResponse - */ - public function getMappedResponse(HasMessageInterface $returnedObject, HasMessageInterface $sentObject): IndividualMappedResponse - { - Assert::IsInstanceOf($returnedObject, VatCode::class); - - $request_vatCode = new Request\Read\VatCode(); - $request_vatCode->setCode($returnedObject->getCode()); - $response = $this->sendXmlDocument($request_vatCode); - - $mappedResponseCollection = $this->getProcessXmlService()->mapAll([$response], "vat", function(Response $response): VatCode { - return VatCodeMapper::map($response); - }); - - return ($mappedResponseCollection[0]); - } - /** * List all VAT codes. *