From 479067f946ed53f9ed2228e544d04b58d90a46a2 Mon Sep 17 00:00:00 2001 From: iranl Date: Sun, 21 Jul 2019 16:48:59 +0200 Subject: [PATCH] Upload --- examples/Activity.php | 2 +- examples/BankTransaction.php | 4 +- examples/CashTransaction.php | 2 +- examples/JournalTransaction.php | 336 ++++++++++++++++++++ examples/PurchaseTransaction.php | 347 ++++++++++++++++++++ examples/SalesTransaction.php | 352 +++++++++++++++++++++ src/ApiConnectors/ActivityApiConnector.php | 2 +- src/Mappers/TransactionMapper.php | 2 +- 8 files changed, 1041 insertions(+), 6 deletions(-) create mode 100644 examples/JournalTransaction.php create mode 100644 examples/PurchaseTransaction.php create mode 100644 examples/SalesTransaction.php diff --git a/examples/Activity.php b/examples/Activity.php index 0252d4e6..d71dcb1f 100644 --- a/examples/Activity.php +++ b/examples/Activity.php @@ -309,7 +309,7 @@ $activityProjects->setValidTill($validTill); // DateTimeInterface|null An activity can be set to only be valid for certain dates. Users will then only be able to book hours to the activity during these dates. $activityProjects->setValidTill(Util::parseDate('20191231')); // string|null - // The minimum amount of ActivityQuantities linked to a ActivityProjects object is 0, the maximum amount is 4 + // The minimum amount of ActivityQuantities linked to an ActivityProjects object is 0, the maximum amount is 4 $activityQuantity = new \PhpTwinfield\ActivityQuantity; $activityQuantity->setBillable(false); // bool|null Is the quantity line billable or not. $activityQuantity->setBillableLocked(false); // bool|null diff --git a/examples/BankTransaction.php b/examples/BankTransaction.php index 6ac74606..f1df5c80 100644 --- a/examples/BankTransaction.php +++ b/examples/BankTransaction.php @@ -57,7 +57,7 @@ */ /* Read a BankTransaction based off the passed in bank day book code, transaction number and optionally the office. - * The used transaction type, in the example below BNK depends on the administration. It is possible that there are multiple bank day book codes in an administration. + * The used transaction type, in the example below BNK, depends on the administration. It is possible that there are multiple bank day book codes in an administration. * See https://accounting.twinfield.com/UI/#/Settings/Company/TransactionTypes for available codes for (bank) day books in your office */ @@ -267,7 +267,7 @@ $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->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'); diff --git a/examples/CashTransaction.php b/examples/CashTransaction.php index 68166452..ca7ffce7 100644 --- a/examples/CashTransaction.php +++ b/examples/CashTransaction.php @@ -57,7 +57,7 @@ */ /* Read a CashTransaction based off the passed in cash day book code, transaction number and optionally the office. - * The used transaction type, in the example below KAS depends on the administration. It is possible that there are multiple cash day book codes in an administration. + * The used transaction type, in the example below KAS, depends on the administration. It is possible that there are multiple cash day book codes in an administration. * See https://accounting.twinfield.com/UI/#/Settings/Company/TransactionTypes for available codes for (cash) day books in your office */ diff --git a/examples/JournalTransaction.php b/examples/JournalTransaction.php new file mode 100644 index 00000000..863fea75 --- /dev/null +++ b/examples/JournalTransaction.php @@ -0,0 +1,336 @@ +get(\PhpTwinfield\JournalTransaction::class, "MEMO", 201900003, $office); + } catch (ResponseException $e) { + $journalTransaction = $e->getReturnedObject(); + } + + echo "
";
+    print_r($journalTransaction);
+    echo "
"; + + echo "JournalTransaction
"; + echo "AutoBalanceVat (bool): {$journalTransaction->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($journalTransaction->getAutoBalanceVat()) . "
"; // string|null + echo "BookingReference (\\PhpTwinfield\\BookingReference):
" . print_r($journalTransaction->getBookingReference(), true) . "

"; // BookingReference|null The Booking reference + echo "Code: {$journalTransaction->getCode()}
"; // string|null Transaction type code. + echo "Currency (\\PhpTwinfield\\Currency):
" . print_r($journalTransaction->getCurrency(), true) . "

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

"; // DateTimeInterface|null Transaction date. + echo "Date (string): " . Util::formatDate($journalTransaction->getDate()) . "
"; // string|null + echo "DateRaiseWarning (bool): {$journalTransaction->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): {$journalTransaction->getDateRaiseWarningToString()}
"; // string|null This overwrites the value of the raisewarning attribute as set on the root element. + echo "Destiny: {$journalTransaction->getDestiny()}
"; // Destiny|null Attribute to indicate the destiny of the journal transaction. Only used in the request XML. temporary = journal transaction will be saved as provisional. final = journal transaction will be saved as final. + echo "FreeText1: {$journalTransaction->getFreeText1()}
"; // string|null Free text field 1 as entered on the transaction type. + echo "FreeText2: {$journalTransaction->getFreeText2()}
"; // string|null Free text field 2 as entered on the transaction type. + echo "FreeText3: {$journalTransaction->getFreeText3()}
"; // string|null Free text field 3 as entered on the transaction type. + echo "InputDate (\\DateTimeInterface):
" . print_r($journalTransaction->getInputDate(), true) . "

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

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

"; // Office|null Office code. + echo "Office (string): " . Util::objectToStr($journalTransaction->getOffice()) . "
"; // string|null + echo "Origin: {$journalTransaction->getOrigin()}
"; // string|null The journal transaction origin. Read-only attribute. + echo "Period: {$journalTransaction->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): {$journalTransaction->getRaiseWarning()}
"; // bool|null Should warnings be given true or not false? Default true. + echo "RaiseWarning (string): " . Util::formatBoolean($journalTransaction->getRaiseWarning()) . "
"; // string|null + echo "Regime: {$journalTransaction->getRegime()}
"; // Regime|null Type of regime. You can post transactions as 'Fiscal', 'Commercial', 'Economic' or 'Generic'. The default regime is 'Generic'. 'Generic' means that the transaction is visible for all regimes. + echo "Result: {$journalTransaction->getResult()}
"; // int|null Result (0 = error, 1 or empty = success). + + $journalTransactionLines = $journalTransaction->getLines(); // array|null Array of JournalTransactionLine objects. + + foreach ($journalTransactionLines as $key => $journalTransactionLine) { + echo "JournalTransactionLine {$key}
"; + + echo "Baseline: {$journalTransactionLine->getBaseline()}
"; // int|null Only if line type is vat. The value of the baseline tag is a reference to the line ID of the VAT rate. + echo "BaseValue (\\Money\\Money):
" . print_r($journalTransactionLine->getBaseValue(), true) . "

"; // Money|null Amount in the base currency. + echo "BaseValue (string): " . Util::formatMoney($journalTransactionLine->getBaseValue()) . "
"; // string|null + echo "BaseValueOpen (\\Money\\Money):
" . print_r($journalTransactionLine->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($journalTransactionLine->getBaseValueOpen()) . "
"; // string|null + echo "Comment: {$journalTransactionLine->getComment()}
"; // string|null Comment set on the transaction line. + echo "CurrencyDate (\\DateTimeInterface):
" . print_r($journalTransactionLine->getCurrencyDate(), true) . "

"; // DateTimeInterface|null Only if line type is detail. The line date. Only allowed if the line date in the journal book is set to Allowed or Mandatory. + echo "CurrencyDate (string): " . Util::formatDate($journalTransactionLine->getCurrencyDate()) . "
"; // string|null + echo "DebitCredit: {$journalTransactionLine->getDebitCredit()}
"; // DebitCredit|null The debit/credit indicator of the journal transaction line. + echo "Description: {$journalTransactionLine->getDescription()}
"; // string|null Description of the transaction line. + echo "DestOffice (\\PhpTwinfield\\Office):
" . print_r($journalTransactionLine->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($journalTransactionLine->getDestOffice()) . "
"; // string|null + echo "Dim1:
" . print_r($journalTransactionLine->getDim1(), true) . "

"; // object|null If line type = detail the journal balance account or profit and loss account. + echo "Dim1 (string): " . Util::objectToStr($journalTransactionLine->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($journalTransactionLine->getDim2(), true) . "

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

"; // object|null If line type = detail the project or asset or empty. + echo "Dim3 (string): " . Util::objectToStr($journalTransactionLine->getDim3()) . "
"; // string|null If line type = vat empty. + echo "FreeChar: {$journalTransactionLine->getFreeChar()}
"; // string|null Free character field. + echo "ID: {$journalTransactionLine->getID()}
"; // int|null Line ID. + echo "InvoiceNumber: {$journalTransactionLine->getInvoiceNumber()}
"; // string|null Invoice number. Only if line type is detail. + echo "LineType: {$journalTransactionLine->getLineType()}
"; // LineType|null Line type. + echo "MatchLevel: {$journalTransactionLine->getMatchLevel()}
"; // int|null Only if line type is detail. The level of the matchable dimension. Read-only attribute. + echo "MatchStatus: {$journalTransactionLine->getMatchStatus()}
"; // MatchStatus|null Payment status of the journal transaction. If line type vat always notmatchable. Read-only attribute. + + if ($journalTransactionLine->hasMessages()) { // bool Object contains (error) messages true/false. + echo "Messages: " . print_r($journalTransactionLine->getMessages(), true) . "
"; // Array|null (Error) messages. + } + + echo "PerformanceCountry (\\PhpTwinfield\\Country):
" . print_r($journalTransactionLine->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($journalTransactionLine->getPerformanceCountry()) . "
"; // string|null + echo "PerformanceDate (\\DateTimeInterface):
" . print_r($journalTransactionLine->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($journalTransactionLine->getPerformanceDate()) . "
"; // string|null + echo "PerformanceType: {$journalTransactionLine->getPerformanceType()}
"; // PerformanceType|null Only if line type is detail or vat. Mandatory in case of an ICT VAT code. The performance type. + echo "PerformanceVatNumber: {$journalTransactionLine->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: {$journalTransactionLine->getRate()}
"; // float|null The exchange rate used for the calculation of the base amount. + echo "Reference (\\PhpTwinfield\\MatchReference):
" . print_r($journalTransactionLine->getReference(), true) . "

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

"; // Money|null Amount in the reporting currency. + echo "RepValue (string): " . Util::formatMoney($journalTransactionLine->getRepValue()) . "
"; // string|null + echo "RepValueOpen (\\Money\\Money):
" . print_r($journalTransactionLine->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($journalTransactionLine->getRepValueOpen()) . "
"; // string|null + echo "Result: {$journalTransactionLine->getResult()}
"; // int|null Result (0 = error, 1 or empty = success). + echo "SignedValue (\\Money\\Money):
" . print_r($journalTransactionLine->getSignedValue(), true) . "

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

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

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

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

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

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

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

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

"; // Money|null Only if line type is detail. VAT amount in the currency of the journal transaction. + echo "VatValue (string): " . Util::formatMoney($journalTransactionLine->getVatValue()) . "
"; // string|null + } +} + +// Copy an existing JournalTransaction to a new entity +if ($executeCopy) { + try { + $journalTransaction = $transactionApiConnector->get(\PhpTwinfield\JournalTransaction::class, "MEMO", 201900003, $office); + } catch (ResponseException $e) { + $journalTransaction = $e->getReturnedObject(); + } + + $journalTransaction->setNumber(null); + + //Optional, but recommended so your copy is not posted to final immediately + $journalTransaction->setDestiny(\PhpTwinfield\Enums\Destiny::TEMPORARY()); + + try { + $journalTransactionCopy = $transactionApiConnector->send($journalTransaction); + } catch (ResponseException $e) { + $journalTransactionCopy = $e->getReturnedObject(); + } + + echo "
";
+    print_r($journalTransactionCopy);
+    echo "
"; + + echo "Result of copy process: {$journalTransactionCopy->getResult()}
"; + echo "Number of copied JournalTransaction: {$journalTransactionCopy->getNumber()}
"; +} + +// Create a new JournalTransaction from scratch, alternatively read an existing JournalTransaction as shown above and than modify the values in the same way as shown below +if ($executeNew) { + $journalTransaction = new \PhpTwinfield\JournalTransaction; + + // Required values for creating a new JournalTransaction + $journalTransaction->setCode('MEMO'); // string|null Transaction type code. + $currency = new \PhpTwinfield\Currency; + $currency->setCode('EUR'); + $journalTransaction->setCurrency($currency); // Currency|null Currency code. + //$journalTransaction->setCurrency(\PhpTwinfield\Currency::fromCode("EUR")); // string|null + $journalTransaction->setDestiny(\PhpTwinfield\Enums\Destiny::TEMPORARY()); // Destiny|null Attribute to indicate the destiny of the journal transaction. Only used in the request XML. temporary = journal transaction will be saved as provisional. + //$journalTransaction->setDestiny(\PhpTwinfield\Enums\Destiny::FINAL()); // Destiny|null final = journal transaction will be saved as final. + $journalTransaction->setOffice($office); // Office|null Office code. + $journalTransaction->setOffice(\PhpTwinfield\Office::fromCode($officeCode)); // string|null + + // Optional values for creating a new JournalTransaction + $journalTransaction->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'); + $journalTransaction->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. + $journalTransaction->setDate(Util::parseDate("20190901")); // string|null This overwrites the value of the raisewarning attribute as set on the root element. + $journalTransaction->setDateRaiseWarning(false); // bool|null + //$journalTransaction->setFreeText1('Example FreeText 1'); // string|null Free text field 1 as entered on the transaction type. + //$journalTransaction->setFreeText2('Example FreeText 2'); // string|null Free text field 2 as entered on the transaction type. + //$journalTransaction->setFreeText3('Example FreeText 3'); // string|null Free text field 3 as entered on the transaction type. + //$journalTransaction->setNumber(201900011); // int|null Transaction number. When creating a new journal transaction, don't include this tag as the transaction number is determined by the system. When updating a journal transaction, the related transaction number should be provided. + //$journalTransaction->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. + $journalTransaction->setRaiseWarning(true); // bool|null Should warnings be given true or not false? Default true. + //$journalTransaction->setRegime(\PhpTwinfield\Enums\Regime::GENERIC()); // Regime|null Type of regime. You can post transactions as 'Fiscal', 'Commercial', 'Economic' or 'Generic'. The default regime is 'Generic'. 'Generic' means that the transaction is visible for all regimes. + + // The minimum amount of JournalTransactionLines linked to an JournalTransaction object is 2 + $journalTransactionLine1 = new \PhpTwinfield\JournalTransactionLine; + $journalTransactionLine1->setLineType(\PhpTwinfield\Enums\LineType::DETAIL()); // LineType|null Line type. + + $journalTransactionLine1->setBaseValue(\Money\Money::EUR(10000)); // Money|null Amount in the base currency. + $journalTransactionLine1->setDescription("Example Description on line with ID 1"); // string|null Description of the transaction line. + $dim1 = new \PhpTwinfield\GeneralLedger; + $dim1->setCode('2500'); + $journalTransactionLine1->setDim1($dim1); // object|null If line type = detail the journal balance account or profit and loss account. + $journalTransactionLine1->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. + $journalTransactionLine1->setID(1); // int|null Line ID. + $journalTransactionLine1->setValue(\Money\Money::EUR(10000)); // Money|null If line type = detail amount without VAT. If line type = vat VAT amount. + + $journalTransaction->addLine($journalTransactionLine1); // JournalTransactionLine Add a JournalTransactionLine object to the JournalTransaction object + + $journalTransactionLine2 = new \PhpTwinfield\JournalTransactionLine; + $journalTransactionLine2->setLineType(\PhpTwinfield\Enums\LineType::DETAIL()); // LineType|null Line type. + + $journalTransactionLine2->setBaseValue(\Money\Money::EUR(10000)); // Money|null Amount in the base currency. + $journalTransactionLine2->setDescription("Example Description on line with ID 2"); // string|null Description of the transaction line. + $dim1 = new \PhpTwinfield\GeneralLedger; + $dim1->setCode('2500'); + $journalTransactionLine2->setDim1($dim1); // object|null If line type = detail the journal balance account or profit and loss account. + $journalTransactionLine2->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. + $journalTransactionLine2->setID(2); // int|null Line ID. + $journalTransactionLine2->setValue(\Money\Money::EUR(-10000)); // Money|null If line type = detail amount without VAT. If line type = vat VAT amount. + + //$journalTransactionLine2->setInvoiceNumber(201900001); // string|null Invoice number. Only if line type is detail. + //$journalTransactionLine2->setComment('Example Comments'); // string|null Comment set on the transaction line. + $currencyDate = \DateTime::createFromFormat('d-m-Y', '01-09-2019'); + //$journalTransaction->setCurrencyDate($currencyDate); // DateTimeInterface|null Only if line type is detail. The line date. Only allowed if the line date in the journal book is set to Allowed or Mandatory. + //$journalTransaction->setCurrencyDate(Util::parseDate("20190901")); // string|null + $destOffice = new \PhpTwinfield\Office; + $destOffice->setCode('1234'); + //$journalTransaction->setDestOffice($destOffice); // Office|null Office code. Used for inter company transactions – here you define in which company the transaction line should be posted. + //$journalTransaction->setDestOffice(\PhpTwinfield\Office::fromCode('1234')); // string|null + $dim2 = new \PhpTwinfield\Customer; + $dim2->setCode('1001'); + //$journalTransactionLine2->setDim2($dim2); // object|null If line type = detail the customer or supplier or the cost center or empty. If line type = vat empty. + //$journalTransactionLine2->setDim2(\PhpTwinfield\Customer::fromCode('1001')); // string|null + $dim3 = new \PhpTwinfield\Project; + $dim3->setCode('P0000'); + //$journalTransactionLine2->setDim3($dim3); // object|null If line type = detail the project or asset or empty. If line type = vat empty. + //$journalTransactionLine2->setDim3(\PhpTwinfield\Project::fromCode('P0000')); // string|null + //$journalTransactionLine2->setFreeChar('A'); // string|null Free character field. + $performanceCountry = new \PhpTwinfield\Country; + $performanceCountry->setCode('NL'); + //$journalTransactionLine2->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. + //$journalTransactionLine2->setPerformanceCountry(\PhpTwinfield\Country::fromCode('NL')); // string|null + $performanceDate = \DateTime::createFromFormat('d-m-Y', '01-09-2019'); + //$journalTransactionLine2->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. + //$journalTransactionLine2->setPerformanceDate(Util::parseDate("20190901")); // string|null + //$journalTransactionLine2->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. + //$journalTransactionLine2->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. + //$journalTransactionLine2->setRepValue(\Money\Money::EUR(-10000)); // Money|null Amount in the reporting currency. + //$journalTransactionLine2->setRate(1); // float|null The exchange rate used for the calculation of the base amount. + //$journalTransactionLine2->setRepRate(1); // float|null The exchange rate used for the calculation of the reporting amount. + //$journalTransactionLine2->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'); + //$journalTransactionLine2->setVatCode($vatCode); // VatCode|null Only if line type is detail or vat. VAT code. + //$journalTransactionLine2->setVatCode(\PhpTwinfield\VatCode::fromCode('VN')); // string|null + //$journalTransactionLine2->setVatRepValue(\Money\Money::EUR(-10000)); // Money|null Only if line type is detail. VAT amount in reporting currency. + //$journalTransactionLine2->setVatValue(\Money\Money::EUR(-10000)); // Money|null Only if line type is detail. VAT amount in the currency of the journal transaction. + + $journalTransaction->addLine($journalTransactionLine2); + + //$journalTransactionLine3 = new \PhpTwinfield\JournalTransactionLine; + //$journalTransactionLine3->setLineType(\PhpTwinfield\Enums\LineType::VAT()); // LineType|null Line type. + //$journalTransactionLine3->setBaseline(1); // int|null Only if line type is vat. The value of the baseline tag is a reference to the line ID of the VAT rate. + //$journalTransactionLine3->setVatBaseTurnover(\Money\Money::EUR(-10000)); // Money|null Only if line type is vat. Amount on which VAT was calculated in base currency. + //$journalTransactionLine3->setVatRepTurnover(\Money\Money::EUR(-10000)); // Money|null Only if line type is vat. Amount on which VAT was calculated in reporting currency. + //$journalTransactionLine3->setVatTurnover(\Money\Money::EUR(-10000)); // Money|null Only if line type is vat. Amount on which VAT was calculated in the currency of the journal transaction. + + try { + $journalTransactionNew = $transactionApiConnector->send($journalTransaction); + } catch (ResponseException $e) { + $journalTransactionNew = $e->getReturnedObject(); + } + + echo "
";
+    print_r($journalTransactionNew);
+    echo "
"; + + echo "Result of creation process: {$journalTransactionNew->getResult()}
"; + echo "Number of new JournalTransaction: {$journalTransactionNew->getNumber()}
"; +} + +// Delete a BrankTransaction based off the passed in office, code, number and given reason +if ($executeDelete) { + $bookingReference = new \PhpTwinfield\BookingReference($office, 'MEMO', 201900005); + + try { + $journalTransactionDeleted = $transactionApiConnector->delete($bookingReference, 'Example reason'); + } catch (ResponseException $e) { + $journalTransactionDeleted = $e->getReturnedObject(); + } + + echo "
";
+    print_r($journalTransactionDeleted);
+    echo "
"; +} \ No newline at end of file diff --git a/examples/PurchaseTransaction.php b/examples/PurchaseTransaction.php new file mode 100644 index 00000000..0186475d --- /dev/null +++ b/examples/PurchaseTransaction.php @@ -0,0 +1,347 @@ +get(\PhpTwinfield\PurchaseTransaction::class, "INK", 201900003, $office); + } catch (ResponseException $e) { + $purchaseTransaction = $e->getReturnedObject(); + } + + echo "
";
+    print_r($purchaseTransaction);
+    echo "
"; + + echo "PurchaseTransaction
"; + echo "AutoBalanceVat (bool): {$purchaseTransaction->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($purchaseTransaction->getAutoBalanceVat()) . "
"; // string|null + echo "BookingReference (\\PhpTwinfield\\BookingReference):
" . print_r($purchaseTransaction->getBookingReference(), true) . "

"; // BookingReference|null The Booking reference + echo "Code: {$purchaseTransaction->getCode()}
"; // string|null Transaction type code. + echo "Currency (\\PhpTwinfield\\Currency):
" . print_r($purchaseTransaction->getCurrency(), true) . "

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

"; // DateTimeInterface|null Transaction date. + echo "Date (string): " . Util::formatDate($purchaseTransaction->getDate()) . "
"; // string|null + echo "DateRaiseWarning (bool): {$purchaseTransaction->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): {$purchaseTransaction->getDateRaiseWarningToString()}
"; // string|null This overwrites the value of the raisewarning attribute as set on the root element. + echo "Destiny: {$purchaseTransaction->getDestiny()}
"; // Destiny|null Attribute to indicate the destiny of the purchase transaction. Only used in the request XML. temporary = purchase transaction will be saved as provisional. final = purchase transaction will be saved as final + echo "DueDate (\\DateTimeInterface):
" . print_r($purchaseTransaction->getDueDate(), true) . "

"; // DateTimeInterface|null Due date. + echo "DueDate (string): " . Util::formatDate($purchaseTransaction->getDueDate()) . "
"; // string|null + echo "FreeText1: {$purchaseTransaction->getFreeText1()}
"; // string|null Free text field 1 as entered on the transaction type. + echo "FreeText2: {$purchaseTransaction->getFreeText2()}
"; // string|null Free text field 2 as entered on the transaction type. + echo "FreeText3: {$purchaseTransaction->getFreeText3()}
"; // string|null Free text field 3 as entered on the transaction type. + echo "InputDate (\\DateTimeInterface):
" . print_r($purchaseTransaction->getInputDate(), true) . "

"; // DateTimeInterface|null The date/time on which the transaction was created. Read-only attribute. + echo "InputDate (string): " . Util::formatDate($purchaseTransaction->getInputDate()) . "
"; // string|null + echo "InvoiceNumber: {$purchaseTransaction->getInvoiceNumber()}
"; // string|null Invoice number. + echo "InvoiceNumberRaiseWarning (bool): {$purchaseTransaction->getInvoiceNumberRaiseWarning()}
"; // bool|null Optionally, it is possible to suppress warnings about 'double invoice numbers' by adding the raisewarning attribute and set its value to false. + echo "InvoiceNumberRaiseWarning (string): {$purchaseTransaction->getInvoiceNumberRaiseWarningToString()}
"; // string|null This overwrites the value of the raisewarning attribute as set on the root element. + + if ($purchaseTransaction->hasMessages()) { // bool Object contains (error) messages true/false. + echo "Messages: " . print_r($purchaseTransaction->getMessages(), true) . "
"; // Array|null (Error) messages. + } + + echo "ModificationDate (\\DateTimeInterface):
" . print_r($purchaseTransaction->getModificationDate(), true) . "

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

"; // Office|null Office code. + echo "Office (string): " . Util::objectToStr($purchaseTransaction->getOffice()) . "
"; // string|null + echo "Origin: {$purchaseTransaction->getOrigin()}
"; // string|null The purchase transaction origin. Read-only attribute. + echo "PaymentReference: {$purchaseTransaction->getPaymentReference()}
"; // string|null Payment reference of the transaction. If payment reference is not specified, the paymentreference section must be omitted + echo "Period: {$purchaseTransaction->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): {$purchaseTransaction->getRaiseWarning()}
"; // bool|null Should warnings be given true or not false? Default true. + echo "RaiseWarning (string): " . Util::formatBoolean($purchaseTransaction->getRaiseWarning()) . "
"; // string|null + echo "Result: {$purchaseTransaction->getResult()}
"; // int|null Result (0 = error, 1 or empty = success). + + $purchaseTransactionLines = $purchaseTransaction->getLines(); // array|null Array of PurchaseTransactionLine objects. + + foreach ($purchaseTransactionLines as $key => $purchaseTransactionLine) { + echo "PurchaseTransactionLine {$key}
"; + + echo "Baseline: {$purchaseTransactionLine->getBaseline()}
"; // int|null Only if line type is vat. The value of the baseline tag is a reference to the line ID of the VAT rate. + echo "BaseValue (\\Money\\Money):
" . print_r($purchaseTransactionLine->getBaseValue(), true) . "

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

"; // Money|null Only if line type is total. The amount still to be paid in base currency. Read-only attribute. + echo "BaseValueOpen (string): " . Util::formatMoney($purchaseTransactionLine->getBaseValueOpen()) . "
"; // string|null + echo "Comment: {$purchaseTransactionLine->getComment()}
"; // string|null Comment set on the transaction line. + echo "DebitCredit: {$purchaseTransactionLine->getDebitCredit()}
"; // DebitCredit|null If line type = total. In case of a 'normal' purchase transaction credit. In case of a credit purchase transaction debit. If line type = detail or vat. In case of a 'normal' purchase transaction debit. In case of a credit purchase transaction credit. + echo "Description: {$purchaseTransactionLine->getDescription()}
"; // string|null Description of the transaction line. + echo "DestOffice (\\PhpTwinfield\\Office):
" . print_r($purchaseTransactionLine->getDestOffice(), true) . "

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

"; // object|null If line type = total the accounts payable balance account. When dim1 is omitted, by default the general ledger account will be taken as entered at the supplier in Twinfield. If line type = detail the profit and loss account. + echo "Dim1 (string): " . Util::objectToStr($purchaseTransactionLine->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($purchaseTransactionLine->getDim2(), true) . "

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

"; // object|null If line type = total empty. If line type = detail the project or asset or empty. + echo "Dim3 (string): " . Util::objectToStr($purchaseTransactionLine->getDim3()) . "
"; // string|null If line type = vat the project or asset or empty. + echo "FreeChar: {$purchaseTransactionLine->getFreeChar()}
"; // string|null Free character field. If line type is total and filled with N the purchase invoice is excluded from payment runs done in Twinfield. + echo "ID: {$purchaseTransactionLine->getID()}
"; // int|null Line ID. + echo "LineType: {$purchaseTransactionLine->getLineType()}
"; // LineType|null Line type. + echo "MatchDate (\\DateTimeInterface):
" . print_r($purchaseTransactionLine->getMatchDate(), true) . "

"; // DateTimeInterface|null Only if line type is total. The date on which the purchase invoice is matched. Read-only attribute. + echo "MatchDate (string): " . Util::formatDate($purchaseTransactionLine->getMatchDate()) . "
"; // string|null + echo "MatchLevel: {$purchaseTransactionLine->getMatchLevel()}
"; // int|null Only if line type is total. The level of the matchable dimension. Read-only attribute. + echo "MatchStatus: {$purchaseTransactionLine->getMatchStatus()}
"; // MatchStatus|null Payment status of the purchase transaction. If line type detail or vat always notmatchable. Read-only attribute. + + if ($purchaseTransactionLine->hasMessages()) { // bool Object contains (error) messages true/false. + echo "Messages: " . print_r($purchaseTransactionLine->getMessages(), true) . "
"; // Array|null (Error) messages. + } + + echo "Rate: {$purchaseTransactionLine->getRate()}
"; // float|null The exchange rate used for the calculation of the base amount. + echo "Reference (\\PhpTwinfield\\MatchReference):
" . print_r($purchaseTransactionLine->getReference(), true) . "

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

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

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

"; // Money|null + echo "SignedValue (string): " . Util::formatMoney($purchaseTransactionLine->getSignedValue()) . "
"; // string|null + echo "Value (\\Money\\Money):
" . print_r($purchaseTransactionLine->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($purchaseTransactionLine->getValue()) . "
"; // string|null + echo "ValueOpen (\\Money\\Money):
" . print_r($purchaseTransactionLine->getValueOpen(), true) . "

"; // Money|null Only if line type is total. The amount still to be paid in the currency of the purchase transaction. Read-only attribute. + echo "ValueOpen (string): " . Util::formatMoney($purchaseTransactionLine->getValueOpen()) . "
"; // string|null + echo "VatBaseTotal (\\Money\\Money):
" . print_r($purchaseTransactionLine->getVatBaseTotal(), true) . "

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

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

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

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

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

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

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

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

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

"; // Money|null Only if line type is detail. VAT amount in the currency of the purchase transaction. + echo "VatValue (string): " . Util::formatMoney($purchaseTransactionLine->getVatValue()) . "
"; // string|null + } +} + +// Copy an existing PurchaseTransaction to a new entity +if ($executeCopy) { + try { + $purchaseTransaction = $transactionApiConnector->get(\PhpTwinfield\PurchaseTransaction::class, "INK", 201900003, $office); + } catch (ResponseException $e) { + $purchaseTransaction = $e->getReturnedObject(); + } + + $purchaseTransaction->setNumber(null); + + //Optional, but recommended so your copy is not posted to final immediately + $purchaseTransaction->setDestiny(\PhpTwinfield\Enums\Destiny::TEMPORARY()); + + try { + $purchaseTransactionCopy = $transactionApiConnector->send($purchaseTransaction); + } catch (ResponseException $e) { + $purchaseTransactionCopy = $e->getReturnedObject(); + } + + echo "
";
+    print_r($purchaseTransactionCopy);
+    echo "
"; + + echo "Result of copy process: {$purchaseTransactionCopy->getResult()}
"; + echo "Number of copied PurchaseTransaction: {$purchaseTransactionCopy->getNumber()}
"; +} + +// Create a new PurchaseTransaction from scratch, alternatively read an existing PurchaseTransaction as shown above and than modify the values in the same way as shown below +if ($executeNew) { + $purchaseTransaction = new \PhpTwinfield\PurchaseTransaction; + + // Required values for creating a new PurchaseTransaction + $purchaseTransaction->setCode('INK'); // string|null Transaction type code. + $currency = new \PhpTwinfield\Currency; + $currency->setCode('EUR'); + $purchaseTransaction->setCurrency($currency); // Currency|null Currency code. + //$purchaseTransaction->setCurrency(\PhpTwinfield\Currency::fromCode("EUR")); // string|null + $purchaseTransaction->setDestiny(\PhpTwinfield\Enums\Destiny::TEMPORARY()); // Destiny|null Attribute to indicate the destiny of the purchase transaction. Only used in the request XML. + //$purchaseTransaction->setDestiny(\PhpTwinfield\Enums\Destiny::FINAL()); // Destiny|null temporary = purchase transaction will be saved as provisional. final = purchase transaction will be saved as final. + $purchaseTransaction->setInvoiceNumber(201900011); // string|null Invoice number. + $purchaseTransaction->setOffice($office); // Office|null Office code. + $purchaseTransaction->setOffice(\PhpTwinfield\Office::fromCode($officeCode)); // string|null + + // Optional values for creating a new PurchaseTransaction + $purchaseTransaction->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'); + $purchaseTransaction->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. + $purchaseTransaction->setDate(Util::parseDate("20190901")); // string|null This overwrites the value of the raisewarning attribute as set on the root element. + $purchaseTransaction->setDateRaiseWarning(false); // bool|null + $dueDate = \DateTime::createFromFormat('d-m-Y', '01-10-2019'); + $purchaseTransaction->setDueDate($dueDate); // DateTimeInterface|null Due date. + $purchaseTransaction->setDueDate(Util::parseDate("20191001")); // string|null + //$purchaseTransaction->setFreeText1('Example FreeText 1'); // string|null Free text field 1 as entered on the transaction type. + //$purchaseTransaction->setFreeText2('Example FreeText 2'); // string|null Free text field 2 as entered on the transaction type. + //$purchaseTransaction->setFreeText3('Example FreeText 3'); // string|null Free text field 3 as entered on the transaction type. + $purchaseTransaction->setInvoiceNumberRaiseWarning(false); // bool|null Optionally, it is possible to suppress warnings about 'double invoice numbers' by adding the raisewarning attribute and set its value to false. This overwrites the value of the raisewarning attribute as set on the root element. + //$purchaseTransaction->setNumber(201900011); // int|null Transaction number. When creating a new purchase transaction, don't include this tag as the transaction number is determined by the system. When updating a purchase transaction, the related transaction number should be provided. + //$purchaseTransaction->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. + $purchaseTransaction->setRaiseWarning(true); // bool|null Should warnings be given true or not false? Default true. + + // The minimum amount of PurchaseTransactionLines linked to an PurchaseTransaction object is 2 (1 total, 1 detail) + $purchaseTransactionLine1 = new \PhpTwinfield\PurchaseTransactionLine; + $purchaseTransactionLine1->setLineType(\PhpTwinfield\Enums\LineType::TOTAL()); // LineType|null Line type. + + $dim1 = new \PhpTwinfield\GeneralLedger; + $dim1->setCode('1600'); + $purchaseTransactionLine1->setDim1($dim1); // object|null If line type = total the accounts payable balance account. When dim1 is omitted, by default the general ledger account will be taken as entered at the supplier in Twinfield. If line type = detail the profit and loss account. + $purchaseTransactionLine1->setDim1(\PhpTwinfield\GeneralLedger::fromCode('1600')); // 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. + $dim2 = new \PhpTwinfield\Supplier; + $dim2->setCode('2000'); + $purchaseTransactionLine1->setDim2($dim2); // object|null If line type = total the account payable. If line type = detail the cost center or empty. If line type = vat the cost center or empty. + $purchaseTransactionLine1->setDim2(\PhpTwinfield\Supplier::fromCode('2000')); // string|null + $purchaseTransactionLine1->setID(1); // int|null Line ID. + $purchaseTransactionLine1->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. + //$purchaseTransactionLine1->setVatBaseTotal(\Money\Money::EUR(-10000)); // Money|null Only if line type is total. The total VAT amount in base currency. + //$purchaseTransactionLine1->setVatRepTotal(\Money\Money::EUR(-10000)); // Money|null Only if line type is total. The total VAT amount in reporting currency. + //$purchaseTransactionLine1->setVatTotal(\Money\Money::EUR(-10000)); // Money|null Only if line type is total. The total VAT amount in the currency of the purchase transaction. + + $purchaseTransaction->addLine($purchaseTransactionLine1); // PurchaseTransactionLine Add a PurchaseTransactionLine object to the PurchaseTransaction object + + $purchaseTransactionLine2 = new \PhpTwinfield\PurchaseTransactionLine; + $purchaseTransactionLine2->setLineType(\PhpTwinfield\Enums\LineType::DETAIL()); // LineType|null Line type. + + $purchaseTransactionLine2->setBaseValue(\Money\Money::EUR(10000)); // Money|null Amount in the base currency. + $purchaseTransactionLine2->setDescription("Example Description on line with ID 2"); // string|null Description of the transaction line. + $dim1 = new \PhpTwinfield\GeneralLedger; + $dim1->setCode('2500'); + $purchaseTransactionLine2->setDim1($dim1); // object|null If line type = total the accounts payable balance account. When dim1 is omitted, by default the general ledger account will be taken as entered at the supplier in Twinfield. If line type = detail the profit and loss account. + $purchaseTransactionLine2->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. + $purchaseTransactionLine2->setID(2); // int|null Line ID. + $purchaseTransactionLine2->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. + + //$purchaseTransactionLine2->setComment('Example Comments'); // string|null Comment set on the transaction line. + $destOffice = new \PhpTwinfield\Office; + $destOffice->setCode('1234'); + //$purchaseTransaction->setDestOffice($destOffice); // Office|null Only if line type is detail. Office code. Used for inter company transactions – here you define in which company the transaction line should be posted. + //$purchaseTransaction->setDestOffice(\PhpTwinfield\Office::fromCode('1234')); // string|null + $dim2 = new \PhpTwinfield\Customer; + $dim2->setCode('1001'); + //$purchaseTransactionLine2->setDim2($dim2); // object|null If line type = total the account payable. If line type = detail the cost center or empty. If line type = vat the cost center or empty. + //$purchaseTransactionLine2->setDim2(\PhpTwinfield\Customer::fromCode('1001')); // string|null + $dim3 = new \PhpTwinfield\Project; + $dim3->setCode('P0000'); + //$purchaseTransactionLine2->setDim3($dim3); // object|null If line type = total empty. If line type = detail the project or asset or empty. If line type = vat the project or asset or empty. + //$purchaseTransactionLine2->setDim3(\PhpTwinfield\Project::fromCode('P0000')); // string|null + //$purchaseTransactionLine2->setFreeChar('A'); // string|null Free character field. If line type is total and filled with N the purchase invoice is excluded from payment runs done in Twinfield. + $performanceCountry = new \PhpTwinfield\Country; + $performanceCountry->setCode('NL'); + //$purchaseTransactionLine2->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. + //$purchaseTransactionLine2->setPerformanceCountry(\PhpTwinfield\Country::fromCode('NL')); // string|null + $performanceDate = \DateTime::createFromFormat('d-m-Y', '01-09-2019'); + //$purchaseTransactionLine2->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. + //$purchaseTransactionLine2->setPerformanceDate(Util::parseDate("20190901")); // string|null + //$purchaseTransactionLine2->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. + //$purchaseTransactionLine2->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. + //$purchaseTransactionLine2->setRepValue(\Money\Money::EUR(-10000)); // Money|null Amount in the reporting currency. + //$purchaseTransactionLine2->setRate(1); // float|null The exchange rate used for the calculation of the base amount. + //$purchaseTransactionLine2->setRepRate(1); // float|null The exchange rate used for the calculation of the reporting amount. + //$purchaseTransactionLine2->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'); + //$purchaseTransactionLine2->setVatCode($vatCode); // VatCode|null Only if line type is detail or vat. VAT code. + //$purchaseTransactionLine2->setVatCode(\PhpTwinfield\VatCode::fromCode('VN')); // string|null + //$purchaseTransactionLine2->setVatRepValue(\Money\Money::EUR(-10000)); // Money|null Only if line type is detail. VAT amount in reporting currency. + //$purchaseTransactionLine2->setVatValue(\Money\Money::EUR(-10000)); // Money|null Only if line type is detail. VAT amount in the currency of the purchase transaction. + + $purchaseTransaction->addLine($purchaseTransactionLine2); + + //$purchaseTransactionLine3 = new \PhpTwinfield\PurchaseTransactionLine; + //$purchaseTransactionLine3->setLineType(\PhpTwinfield\Enums\LineType::VAT()); // LineType|null Line type. + //$purchaseTransactionLine3->setBaseline(1); // int|null Only if line type is vat. The value of the baseline tag is a reference to the line ID of the VAT rate. + //$purchaseTransactionLine3->setVatBaseTurnover(\Money\Money::EUR(-10000)); // Money|null Only if line type is vat. Amount on which VAT was calculated in base currency. + //$purchaseTransactionLine3->setVatRepTurnover(\Money\Money::EUR(-10000)); // Money|null Only if line type is vat. Amount on which VAT was calculated in reporting currency. + //$purchaseTransactionLine3->setVatTurnover(\Money\Money::EUR(-10000)); // Money|null Only if line type is vat. Amount on which VAT was calculated in the currency of the purchase transaction. + + try { + $purchaseTransactionNew = $transactionApiConnector->send($purchaseTransaction); + } catch (ResponseException $e) { + $purchaseTransactionNew = $e->getReturnedObject(); + } + + echo "
";
+    print_r($purchaseTransactionNew);
+    echo "
"; + + echo "Result of creation process: {$purchaseTransactionNew->getResult()}
"; + echo "Number of new PurchaseTransaction: {$purchaseTransactionNew->getNumber()}
"; +} + +// Delete a BrankTransaction based off the passed in office, code, number and given reason +if ($executeDelete) { + $bookingReference = new \PhpTwinfield\BookingReference($office, 'INK', 201900004); + + try { + $purchaseTransactionDeleted = $transactionApiConnector->delete($bookingReference, 'Example reason'); + } catch (ResponseException $e) { + $purchaseTransactionDeleted = $e->getReturnedObject(); + } + + echo "
";
+    print_r($purchaseTransactionDeleted);
+    echo "
"; +} \ No newline at end of file diff --git a/examples/SalesTransaction.php b/examples/SalesTransaction.php new file mode 100644 index 00000000..5d11b2d3 --- /dev/null +++ b/examples/SalesTransaction.php @@ -0,0 +1,352 @@ +get(\PhpTwinfield\SalesTransaction::class, "VRK", 201900011, $office); + } catch (ResponseException $e) { + $salesTransaction = $e->getReturnedObject(); + } + + echo "
";
+    print_r($salesTransaction);
+    echo "
"; + + echo "SalesTransaction
"; + echo "AutoBalanceVat (bool): {$salesTransaction->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($salesTransaction->getAutoBalanceVat()) . "
"; // string|null + echo "BookingReference (\\PhpTwinfield\\BookingReference):
" . print_r($salesTransaction->getBookingReference(), true) . "

"; // BookingReference|null The Booking reference + echo "Code: {$salesTransaction->getCode()}
"; // string|null Transaction type code. + echo "Currency (\\PhpTwinfield\\Currency):
" . print_r($salesTransaction->getCurrency(), true) . "

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

"; // DateTimeInterface|null Transaction date. + echo "Date (string): " . Util::formatDate($salesTransaction->getDate()) . "
"; // string|null + echo "DateRaiseWarning (bool): {$salesTransaction->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): {$salesTransaction->getDateRaiseWarningToString()}
"; // string|null This overwrites the value of the raisewarning attribute as set on the root element. + echo "Destiny: {$salesTransaction->getDestiny()}
"; // Destiny|null Attribute to indicate the destiny of the sales transaction. Only used in the request XML. temporary = sales transaction will be saved as provisional. final = sales transaction will be saved as final + echo "DueDate (\\DateTimeInterface):
" . print_r($salesTransaction->getDueDate(), true) . "

"; // DateTimeInterface|null Due date. + echo "DueDate (string): " . Util::formatDate($salesTransaction->getDueDate()) . "
"; // string|null + echo "FreeText1: {$salesTransaction->getFreeText1()}
"; // string|null Free text field 1 as entered on the transaction type. + echo "FreeText2: {$salesTransaction->getFreeText2()}
"; // string|null Free text field 2 as entered on the transaction type. + echo "FreeText3: {$salesTransaction->getFreeText3()}
"; // string|null Free text field 3 as entered on the transaction type. + echo "InputDate (\\DateTimeInterface):
" . print_r($salesTransaction->getInputDate(), true) . "

"; // DateTimeInterface|null The date/time on which the transaction was created. Read-only attribute. + echo "InputDate (string): " . Util::formatDate($salesTransaction->getInputDate()) . "
"; // string|null + echo "InvoiceNumber: {$salesTransaction->getInvoiceNumber()}
"; // string|null Invoice number. + echo "InvoiceNumberRaiseWarning (bool): {$salesTransaction->getInvoiceNumberRaiseWarning()}
"; // bool|null Optionally, it is possible to suppress warnings about 'double invoice numbers' by adding the raisewarning attribute and set its value to false. + echo "InvoiceNumberRaiseWarning (string): {$salesTransaction->getInvoiceNumberRaiseWarningToString()}
"; // string|null This overwrites the value of the raisewarning attribute as set on the root element. + + if ($salesTransaction->hasMessages()) { // bool Object contains (error) messages true/false. + echo "Messages: " . print_r($salesTransaction->getMessages(), true) . "
"; // Array|null (Error) messages. + } + + echo "ModificationDate (\\DateTimeInterface):
" . print_r($salesTransaction->getModificationDate(), true) . "

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

"; // Office|null Office code. + echo "Office (string): " . Util::objectToStr($salesTransaction->getOffice()) . "
"; // string|null + echo "Origin: {$salesTransaction->getOrigin()}
"; // string|null The sales transaction origin. Read-only attribute. + echo "OriginReference: {$salesTransaction->getOriginReference()}
"; // string|null The sales transaction origin reference (id). Provided in form of Guid. Read-only attribute. + echo "PaymentReference: {$salesTransaction->getPaymentReference()}
"; // string|null Payment reference of the transaction. If payment reference is not specified, the paymentreference section must be omitted + echo "Period: {$salesTransaction->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): {$salesTransaction->getRaiseWarning()}
"; // bool|null Should warnings be given true or not false? Default true. + echo "RaiseWarning (string): " . Util::formatBoolean($salesTransaction->getRaiseWarning()) . "
"; // string|null + echo "Result: {$salesTransaction->getResult()}
"; // int|null Result (0 = error, 1 or empty = success). + + $salesTransactionLines = $salesTransaction->getLines(); // array|null Array of SalesTransactionLine objects. + + foreach ($salesTransactionLines as $key => $salesTransactionLine) { + echo "SalesTransactionLine {$key}
"; + + echo "Baseline: {$salesTransactionLine->getBaseline()}
"; // int|null Only if line type is vat. The value of the baseline tag is a reference to the line ID of the VAT rate. + echo "BaseValue (\\Money\\Money):
" . print_r($salesTransactionLine->getBaseValue(), true) . "

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

"; // Money|null Only if line type is total. The amount still owed in base currency. Read-only attribute. + echo "BaseValueOpen (string): " . Util::formatMoney($salesTransactionLine->getBaseValueOpen()) . "
"; // string|null + echo "Comment: {$salesTransactionLine->getComment()}
"; // string|null Comment set on the transaction line. + echo "DebitCredit: {$salesTransactionLine->getDebitCredit()}
"; // DebitCredit|null If line type = total. In case of a 'normal' sales transaction debit. In case of a credit sales transaction credit. If line type = detail or vat. In case of a 'normal' sales transaction credit. In case of a credit sales transaction debit. + echo "Description: {$salesTransactionLine->getDescription()}
"; // string|null Description of the transaction line. + echo "DestOffice (\\PhpTwinfield\\Office):
" . print_r($salesTransactionLine->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($salesTransactionLine->getDestOffice()) . "
"; // string|null + echo "Dim1:
" . print_r($salesTransactionLine->getDim1(), true) . "

"; // object|null If line type = total the accounts receivable balance account. When dim1 is omitted, by default the general ledger account will be taken as entered at the customer in Twinfield. If line type = detail the profit and loss account. + echo "Dim1 (string): " . Util::objectToStr($salesTransactionLine->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($salesTransactionLine->getDim2(), true) . "

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

"; // object|null If line type = total empty. If line type = detail the project or asset or empty. + echo "Dim3 (string): " . Util::objectToStr($salesTransactionLine->getDim3()) . "
"; // string|null If line type = vat empty. + echo "FreeChar: {$salesTransactionLine->getFreeChar()}
"; // string|null Free character field. If line type is total and filled with N the sales invoice is excluded from direct debit runs done in Twinfield. + echo "ID: {$salesTransactionLine->getID()}
"; // int|null Line ID. + echo "LineType: {$salesTransactionLine->getLineType()}
"; // LineType|null Line type. + echo "MatchLevel: {$salesTransactionLine->getMatchLevel()}
"; // int|null Only if line type is total. The level of the matchable dimension. Read-only attribute. + echo "MatchStatus: {$salesTransactionLine->getMatchStatus()}
"; // MatchStatus|null Payment status of the sales transaction. If line type detail or vat always notmatchable. Read-only attribute. + + if ($salesTransactionLine->hasMessages()) { // bool Object contains (error) messages true/false. + echo "Messages: " . print_r($salesTransactionLine->getMessages(), true) . "
"; // Array|null (Error) messages. + } + + echo "PerformanceCountry (\\PhpTwinfield\\Country):
" . print_r($salesTransactionLine->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($salesTransactionLine->getPerformanceCountry()) . "
"; // string|null + echo "PerformanceDate (\\DateTimeInterface):
" . print_r($salesTransactionLine->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($salesTransactionLine->getPerformanceDate()) . "
"; // string|null + echo "PerformanceType: {$salesTransactionLine->getPerformanceType()}
"; // PerformanceType|null Only if line type is detail or vat. Mandatory in case of an ICT VAT code. The performance type. + echo "PerformanceVatNumber: {$salesTransactionLine->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: {$salesTransactionLine->getRate()}
"; // float|null The exchange rate used for the calculation of the base amount. + echo "Reference (\\PhpTwinfield\\MatchReference):
" . print_r($salesTransactionLine->getReference(), true) . "

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

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

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

"; // Money|null + echo "SignedValue (string): " . Util::formatMoney($salesTransactionLine->getSignedValue()) . "
"; // string|null + echo "Value (\\Money\\Money):
" . print_r($salesTransactionLine->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($salesTransactionLine->getValue()) . "
"; // string|null + echo "ValueOpen (\\Money\\Money):
" . print_r($salesTransactionLine->getValueOpen(), true) . "

"; // Money|null Only if line type is total. The amount still owed in the currency of the sales transaction. Read-only attribute. + echo "ValueOpen (string): " . Util::formatMoney($salesTransactionLine->getValueOpen()) . "
"; // string|null + echo "VatBaseTotal (\\Money\\Money):
" . print_r($salesTransactionLine->getVatBaseTotal(), true) . "

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

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

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

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

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

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

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

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

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

"; // Money|null Only if line type is detail. VAT amount in the currency of the sales transaction. + echo "VatValue (string): " . Util::formatMoney($salesTransactionLine->getVatValue()) . "
"; // string|null + } +} + +// Copy an existing SalesTransaction to a new entity +if ($executeCopy) { + try { + $salesTransaction = $transactionApiConnector->get(\PhpTwinfield\SalesTransaction::class, "VRK", 201900011, $office); + } catch (ResponseException $e) { + $salesTransaction = $e->getReturnedObject(); + } + + $salesTransaction->setNumber(null); + + //Optional, but recommended so your copy is not posted to final immediately + $salesTransaction->setDestiny(\PhpTwinfield\Enums\Destiny::TEMPORARY()); + + try { + $salesTransactionCopy = $transactionApiConnector->send($salesTransaction); + } catch (ResponseException $e) { + $salesTransactionCopy = $e->getReturnedObject(); + } + + echo "
";
+    print_r($salesTransactionCopy);
+    echo "
"; + + echo "Result of copy process: {$salesTransactionCopy->getResult()}
"; + echo "Number of copied SalesTransaction: {$salesTransactionCopy->getNumber()}
"; +} + +// Create a new SalesTransaction from scratch, alternatively read an existing SalesTransaction as shown above and than modify the values in the same way as shown below +if ($executeNew) { + $salesTransaction = new \PhpTwinfield\SalesTransaction; + + // Required values for creating a new SalesTransaction + $salesTransaction->setCode('VRK'); // string|null Transaction type code. + $currency = new \PhpTwinfield\Currency; + $currency->setCode('EUR'); + $salesTransaction->setCurrency($currency); // Currency|null Currency code. + //$salesTransaction->setCurrency(\PhpTwinfield\Currency::fromCode("EUR")); // string|null + $salesTransaction->setDestiny(\PhpTwinfield\Enums\Destiny::TEMPORARY()); // Destiny|null Attribute to indicate the destiny of the sales transaction. Only used in the request XML. + //$salesTransaction->setDestiny(\PhpTwinfield\Enums\Destiny::FINAL()); // Destiny|null temporary = sales transaction will be saved as provisional. final = sales transaction will be saved as final. + $salesTransaction->setInvoiceNumber(201900011); // string|null Invoice number. + $salesTransaction->setOffice($office); // Office|null Office code. + $salesTransaction->setOffice(\PhpTwinfield\Office::fromCode($officeCode)); // string|null + + // Optional values for creating a new SalesTransaction + $salesTransaction->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'); + $salesTransaction->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. + $salesTransaction->setDate(Util::parseDate("20190901")); // string|null This overwrites the value of the raisewarning attribute as set on the root element. + $salesTransaction->setDateRaiseWarning(false); // bool|null + $dueDate = \DateTime::createFromFormat('d-m-Y', '01-10-2019'); + $salesTransaction->setDueDate($dueDate); // DateTimeInterface|null Due date. + $salesTransaction->setDueDate(Util::parseDate("20191001")); // string|null + //$salesTransaction->setFreeText1('Example FreeText 1'); // string|null Free text field 1 as entered on the transaction type. + //$salesTransaction->setFreeText2('Example FreeText 2'); // string|null Free text field 2 as entered on the transaction type. + //$salesTransaction->setFreeText3('Example FreeText 3'); // string|null Free text field 3 as entered on the transaction type. + $salesTransaction->setInvoiceNumberRaiseWarning(false); // bool|null Optionally, it is possible to suppress warnings about 'double invoice numbers' by adding the raisewarning attribute and set its value to false. This overwrites the value of the raisewarning attribute as set on the root element. + //$salesTransaction->setNumber(201900011); // int|null Transaction number. When creating a new sales transaction, don't include this tag as the transaction number is determined by the system. When updating a sales transaction, the related transaction number should be provided. + //$salesTransaction->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. + $salesTransaction->setRaiseWarning(true); // bool|null Should warnings be given true or not false? Default true. + + // The minimum amount of SalesTransactionLines linked to an SalesTransaction object is 2 (1 total, 1 detail) + $salesTransactionLine1 = new \PhpTwinfield\SalesTransactionLine; + $salesTransactionLine1->setLineType(\PhpTwinfield\Enums\LineType::TOTAL()); // LineType|null Line type. + + $dim1 = new \PhpTwinfield\GeneralLedger; + $dim1->setCode('1300'); + $salesTransactionLine1->setDim1($dim1); // object|null If line type = total the accounts receivable balance account. When dim1 is omitted, by default the general ledger account will be taken as entered at the customer in Twinfield. If line type = detail the profit and loss account. + $salesTransactionLine1->setDim1(\PhpTwinfield\GeneralLedger::fromCode('1300')); // 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. + $dim2 = new \PhpTwinfield\Customer; + $dim2->setCode('1000'); + $salesTransactionLine1->setDim2($dim2); // object|null If line type = total the account receivable. If line type = detail the cost center or empty. If line type = vat empty. + $salesTransactionLine1->setDim2(\PhpTwinfield\Customer::fromCode('1000')); // string|null + $salesTransactionLine1->setID(1); // int|null Line ID. + $salesTransactionLine1->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. + //$salesTransactionLine1->setVatBaseTotal(\Money\Money::EUR(-10000)); // Money|null Only if line type is total. The total VAT amount in base currency. + //$salesTransactionLine1->setVatRepTotal(\Money\Money::EUR(-10000)); // Money|null Only if line type is total. The total VAT amount in reporting currency. + //$salesTransactionLine1->setVatTotal(\Money\Money::EUR(-10000)); // Money|null Only if line type is total. The total VAT amount in the currency of the sales transaction. + + $salesTransaction->addLine($salesTransactionLine1); // SalesTransactionLine Add a SalesTransactionLine object to the SalesTransaction object + + $salesTransactionLine2 = new \PhpTwinfield\SalesTransactionLine; + $salesTransactionLine2->setLineType(\PhpTwinfield\Enums\LineType::DETAIL()); // LineType|null Line type. + + $salesTransactionLine2->setBaseValue(\Money\Money::EUR(10000)); // Money|null Amount in the base currency. + $salesTransactionLine2->setDescription("Example Description on line with ID 2"); // string|null Description of the transaction line. + $dim1 = new \PhpTwinfield\GeneralLedger; + $dim1->setCode('2500'); + $salesTransactionLine2->setDim1($dim1); // object|null If line type = total the accounts receivable balance account. When dim1 is omitted, by default the general ledger account will be taken as entered at the customer in Twinfield. If line type = detail the profit and loss account. + $salesTransactionLine2->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. + $salesTransactionLine2->setID(2); // int|null Line ID. + $salesTransactionLine2->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. + + //$salesTransactionLine2->setComment('Example Comments'); // string|null Comment set on the transaction line. + $destOffice = new \PhpTwinfield\Office; + $destOffice->setCode('1234'); + //$salesTransaction->setDestOffice($destOffice); // Office|null Office code. Used for inter company transactions – here you define in which company the transaction line should be posted. + //$salesTransaction->setDestOffice(\PhpTwinfield\Office::fromCode('1234')); // string|null + $dim2 = new \PhpTwinfield\Customer; + $dim2->setCode('1001'); + //$salesTransactionLine2->setDim2($dim2); // object|null If line type = total the account receivable. If line type = detail the cost center or empty. If line type = vat empty. + //$salesTransactionLine2->setDim2(\PhpTwinfield\Customer::fromCode('1001')); // string|null + $dim3 = new \PhpTwinfield\Project; + $dim3->setCode('P0000'); + //$salesTransactionLine2->setDim3($dim3); // object|null If line type = total empty. If line type = detail the project or asset or empty. If line type = vat empty. + //$salesTransactionLine2->setDim3(\PhpTwinfield\Project::fromCode('P0000')); // string|null + //$salesTransactionLine2->setFreeChar('A'); // string|null Free character field. If line type is total and filled with N the sales invoice is excluded from direct debit runs done in Twinfield. + $performanceCountry = new \PhpTwinfield\Country; + $performanceCountry->setCode('NL'); + //$salesTransactionLine2->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. + //$salesTransactionLine2->setPerformanceCountry(\PhpTwinfield\Country::fromCode('NL')); // string|null + $performanceDate = \DateTime::createFromFormat('d-m-Y', '01-09-2019'); + //$salesTransactionLine2->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. + //$salesTransactionLine2->setPerformanceDate(Util::parseDate("20190901")); // string|null + //$salesTransactionLine2->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. + //$salesTransactionLine2->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. + //$salesTransactionLine2->setRepValue(\Money\Money::EUR(-10000)); // Money|null Amount in the reporting currency. + //$salesTransactionLine2->setRate(1); // float|null The exchange rate used for the calculation of the base amount. + //$salesTransactionLine2->setRepRate(1); // float|null The exchange rate used for the calculation of the reporting amount. + //$salesTransactionLine2->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'); + //$salesTransactionLine2->setVatCode($vatCode); // VatCode|null Only if line type is detail or vat. VAT code. + //$salesTransactionLine2->setVatCode(\PhpTwinfield\VatCode::fromCode('VN')); // string|null + //$salesTransactionLine2->setVatRepValue(\Money\Money::EUR(-10000)); // Money|null Only if line type is detail. VAT amount in reporting currency. + //$salesTransactionLine2->setVatValue(\Money\Money::EUR(-10000)); // Money|null Only if line type is detail. VAT amount in the currency of the sales transaction. + + $salesTransaction->addLine($salesTransactionLine2); + + //$salesTransactionLine3 = new \PhpTwinfield\SalesTransactionLine; + //$salesTransactionLine3->setLineType(\PhpTwinfield\Enums\LineType::VAT()); // LineType|null Line type. + //$salesTransactionLine3->setBaseline(1); // int|null Only if line type is vat. The value of the baseline tag is a reference to the line ID of the VAT rate. + //$salesTransactionLine3->setVatBaseTurnover(\Money\Money::EUR(-10000)); // Money|null Only if line type is vat. Amount on which VAT was calculated in base currency. + //$salesTransactionLine3->setVatRepTurnover(\Money\Money::EUR(-10000)); // Money|null Only if line type is vat. Amount on which VAT was calculated in reporting currency. + //$salesTransactionLine3->setVatTurnover(\Money\Money::EUR(-10000)); // Money|null Only if line type is vat. Amount on which VAT was calculated in the currency of the sales transaction. + + try { + $salesTransactionNew = $transactionApiConnector->send($salesTransaction); + } catch (ResponseException $e) { + $salesTransactionNew = $e->getReturnedObject(); + } + + echo "
";
+    print_r($salesTransactionNew);
+    echo "
"; + + echo "Result of creation process: {$salesTransactionNew->getResult()}
"; + echo "Number of new SalesTransaction: {$salesTransactionNew->getNumber()}
"; +} + +// Delete a BrankTransaction based off the passed in office, code, number and given reason +if ($executeDelete) { + $bookingReference = new \PhpTwinfield\BookingReference($office, 'VRK', 201900012); + + try { + $salesTransactionDeleted = $transactionApiConnector->delete($bookingReference, 'Example reason'); + } catch (ResponseException $e) { + $salesTransactionDeleted = $e->getReturnedObject(); + } + + echo "
";
+    print_r($salesTransactionDeleted);
+    echo "
"; +} \ No newline at end of file diff --git a/src/ApiConnectors/ActivityApiConnector.php b/src/ApiConnectors/ActivityApiConnector.php index fa4cd6aa..8e26cc42 100644 --- a/src/ApiConnectors/ActivityApiConnector.php +++ b/src/ApiConnectors/ActivityApiConnector.php @@ -49,7 +49,7 @@ public function get(string $code, Office $office): Activity } /** - * Sends a Activity instance to Twinfield to update or add. + * Sends an Activity instance to Twinfield to update or add. * * @param Activity $activity * @return Activity diff --git a/src/Mappers/TransactionMapper.php b/src/Mappers/TransactionMapper.php index 3ef2773d..af97f32e 100644 --- a/src/Mappers/TransactionMapper.php +++ b/src/Mappers/TransactionMapper.php @@ -124,7 +124,7 @@ public static function map(string $transactionClassName, Response $response, Aut } if (Util::objectUses(RegimeField::class, $transaction)) { - $transaction->setRegime(self::getField($transactionElement, 'regime', $transaction)); + $transaction->setRegime(self::parseEnumAttribute(\PhpTwinfield\Enums\Regime::class, self::getField($transactionElement, 'regime', $transaction))); } if (Util::objectUses(StatementNumberField::class, $transaction)) {