Skip to content
New issue

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

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

Already on GitHub? Sign in to your account

Extend all testing #7

Merged
merged 5 commits into from
Jun 2, 2019
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion examples/Activity.php
Original file line number Diff line number Diff line change
Expand Up @@ -69,7 +69,7 @@
*
*/

//List all with pattern "A*", field 0 (= search code or number), firstRow 1, maxRows 10, options -> accessrules = 0
//List all with pattern "A*", field 0 (= search code or name), firstRow 1, maxRows 10, options -> accessrules = 0
if ($executeListAllWithFilter) {
$options = array('accessrules' => 0);

Expand Down
2 changes: 1 addition & 1 deletion examples/Article.php
Original file line number Diff line number Diff line change
Expand Up @@ -60,7 +60,7 @@
*
*/

//List all with pattern "O*", field 0 (= search code or number), firstRow 1, maxRows 10, options -> vat = 'inclusive'
//List all with pattern "O*", field 0 (= search code or name), firstRow 1, maxRows 10, options -> vat = 'inclusive'
if ($executeListAllWithFilter) {
$options = array('vat' => 'inclusive');

Expand Down
2 changes: 1 addition & 1 deletion examples/CashBankBook.php
Original file line number Diff line number Diff line change
Expand Up @@ -45,7 +45,7 @@
* Usage: $options['banktype'] = -1;
*/

//List all with pattern "BNK", field 0 (= search code or number), firstRow 1, maxRows 10, options -> banktype = 0
//List all with pattern "BNK", field 0 (= search code or name), firstRow 1, maxRows 10, options -> banktype = 0
if ($executeListAllWithFilter) {
$options = array('banktype' => 0);

Expand Down
2 changes: 1 addition & 1 deletion examples/CostCenter.php
Original file line number Diff line number Diff line change
Expand Up @@ -65,7 +65,7 @@
* Usage: $options['group'] = 'DimensionGroup';
*/

//List all with pattern "Apeldoorn", field 0 (= search code or number), firstRow 1, maxRows 10, options -> modifiedsince = '20190101100000', group = 'DimensionGroup'
//List all with pattern "Apeldoorn", field 0 (= search code or name), firstRow 1, maxRows 10, options -> modifiedsince = '20190101100000', group = 'DimensionGroup'
if ($executeListAllWithFilter) {
$options = array('modifiedsince' => '20190101100000', 'group' => 'DimensionGroup');

Expand Down
2 changes: 1 addition & 1 deletion examples/Country.php
Original file line number Diff line number Diff line change
Expand Up @@ -41,7 +41,7 @@
* Usage: $options['office'] = 'SomeOfficeCode';
*/

//List all with pattern "NL", field 0 (= search code or number), firstRow 1, maxRows 10
//List all with pattern "NL", field 0 (= search code or name), firstRow 1, maxRows 10
if ($executeListAllWithFilter) {
try {
$countries = $countryApiConnector->listAll('NL', 0, 1, 10);
Expand Down
2 changes: 1 addition & 1 deletion examples/Currency.php
Original file line number Diff line number Diff line change
Expand Up @@ -54,7 +54,7 @@
* Usage: $options['office'] = 'SomeOfficeCode';
*/

//List all with pattern "EUR", field 0 (= search code or number), firstRow 1, maxRows 10, options []
//List all with pattern "EUR", field 0 (= search code or name), firstRow 1, maxRows 10, options []
if ($executeListAllWithFilter) {
try {
$currencies = $currencyApiConnector->listAll("EUR", 0, 1, 10);
Expand Down
2 changes: 1 addition & 1 deletion examples/DimensionGroup.php
Original file line number Diff line number Diff line change
Expand Up @@ -62,7 +62,7 @@
*
*/

//List all with pattern "*", field 0 (= search code or number), firstRow 1, maxRows 10, options -> dimtype = 'BAS'
//List all with pattern "*", field 0 (= search code or name), firstRow 1, maxRows 10, options -> dimtype = 'BAS'
if ($executeListAllWithFilter) {
$options = array('dimtype' => 'BAS');

Expand Down
2 changes: 1 addition & 1 deletion examples/DimensionType.php
Original file line number Diff line number Diff line change
Expand Up @@ -60,7 +60,7 @@
*
*/

//List all with pattern "*", field 0 (= search code or number), firstRow 1, maxRows 10, options -> finlevel = 2
//List all with pattern "*", field 0 (= search code or name), firstRow 1, maxRows 10, options -> finlevel = 2
if ($executeListAllWithFilter) {
$options = array('finlevel' => 2);

Expand Down
2 changes: 1 addition & 1 deletion examples/Invoice.php
Original file line number Diff line number Diff line change
Expand Up @@ -64,7 +64,7 @@
*
*/

//List all with pattern "2019*", field 0 (= search code or number), firstRow 1, maxRows 10, options -> openvalue = 50.25
//List all with pattern "2019*", field 0 (= search code or name), firstRow 1, maxRows 10, options -> openvalue = 50.25
if ($executeListAllWithFilter) {
$options = array('openvalue' => 50.25);

Expand Down
4 changes: 2 additions & 2 deletions examples/InvoiceType.php
Original file line number Diff line number Diff line change
Expand Up @@ -35,7 +35,7 @@
* to add multiple options. An option name may be used once, specifying an option multiple
* times will cause an error.
*
* Available options: office
* Available options: office, vat
*
* office Sets the office code.
* Usage: $options['office'] = 'SomeOfficeCode';
Expand All @@ -45,7 +45,7 @@
* Usage: $options['vat'] = 'inclusive';
*/

//List all with pattern "INV*", field 0 (= search code or number), firstRow 1, maxRows 10, options, options -> vat = 'exclusive'
//List all with pattern "INV*", field 0 (= search code or name), firstRow 1, maxRows 10, options, options -> vat = 'exclusive'
if ($executeListAllWithFilter) {
$options = array('vat' => 'exclusive');

Expand Down
157 changes: 157 additions & 0 deletions examples/Office.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,157 @@
<?php

/* Office
* Twinfield UI: https://accounting.twinfield.com/UI/#/Companies/All
* API Documentation: https://c3.twinfield.com/webservices/documentation/#/ApiReference/Masters/Offices
*/

//Optionally declare the namespace PhpTwinfield so u can call classes without prepending \PhpTwinfield\
namespace PhpTwinfield;

// Use the ResponseException class to handle errors when listing, getting and sending objects to/from Twinfield
use PhpTwinfield\Response\ResponseException;

require_once('vendor/autoload.php');

// Retrieve an OAuth 2 connection
require_once('Connection.php');

/* Office API Connector
* \PhpTwinfield\ApiConnectors\OfficeApiConnector
* Available methods: get, listAll, listAllWithoutOfficeCode
*/

// Run all or only some of the following examples
$executeListAllWithoutOfficeCode = false;
$executeListAllWithFilter = false;
$executeListAllWithoutFilter = true;
$executeRead = true;

$officeApiConnector = new \PhpTwinfield\ApiConnectors\OfficeApiConnector($connection);

// Office code
$officeCode = "SomeOfficeCode";

// Create a new Office object from the $officeCode
$defaultOffice = \PhpTwinfield\Office::fromCode($officeCode);

/* List all offices
* @param string $pattern The search pattern. May contain wildcards * and ?
* @param int $field The search field determines which field or fields will be searched. The available fields
* depends on the finder type. Passing a value outside the specified values will cause an
* error.
* @param int $firstRow First row to return, useful for paging
* @param int $maxRows Maximum number of rows to return, useful for paging
* @param array $options The Finder options. Passing an unsupported name or value causes an error. It's possible
* to add multiple options. An option name may be used once, specifying an option multiple
* times will cause an error.
*
* Available options: office, consolidate, withouttaxgroup
*
* office Sets the office code.
* Usage: $options['office'] = 'SomeOfficeCode';
*
* consolidate Shows offices for which the consolidate option is true of false.
* Available values: 0 = false, 1 = true
* Usage: $options['consolidate'] = 0;
*
* withouttaxgroup If set to 1, the list of offices is limited to offices that are not part of a tax group and those offices don't contain VAT returns which are not approved yet.
* Available values: 0 = false, 1 = true
* Usage: $options['consolidate'] = 0;
*/

//List all offices without knowing any of the office codes, only available when using OAuth 2 login
if ($executeListAllWithoutOfficeCode) {
try {
$offices = $officeApiConnector->listAllWithoutOfficeCode();
} catch (ResponseException $e) {
$offices = $e->getReturnedObject();
}

echo "<pre>";
print_r($offices);
echo "</pre>";
}

//List all with pattern "NL*", field 0 (= search code or name), firstRow 1, maxRows 10, options -> consolidate = 0
if ($executeListAllWithFilter) {
$options = array('consolidate' => 0);

try {
$offices = $officeApiConnector->listAll("NL*", 0, 1, 10, $options);
} catch (ResponseException $e) {
$offices = $e->getReturnedObject();
}

echo "<pre>";
print_r($offices);
echo "</pre>";
}

//List all with default settings (pattern '*', field 0, firstRow 1, maxRows 100, options [])
if ($executeListAllWithoutFilter) {
try {
$offices = $officeApiConnector->listAll();
} catch (ResponseException $e) {
$offices = $e->getReturnedObject();
}

echo "<pre>";
print_r($offices);
echo "</pre>";
}

/* Office
* \PhpTwinfield\Office
* Available getters: __toString, getCode, getCountryCode, getCountryCodeToString, getCreated, getCreatedToString, getMessages, getModified, getModifiedToString, getName, getResult, getShortName, getStatus, getTouched, getUser, getUserToString, getVatFirstQuarterStartsIn, getVatPeriod, hasMessages
* Available setters: fromCode, setCode, setCountryCode, setCountryCodeFromString, setName, setShortName, setStatus, setStatusFromString, setVatFirstQuarterStartsIn,setVatPeriod
*/

if ($executeListAllWithoutOfficeCode || $executeListAllWithFilter || $executeListAllWithoutFilter) {
foreach ($offices as $key => $office) {
echo "Office {$key}<br />";
echo "Code: {$office->getCode()}<br />";
echo "Name: {$office->getName()}<br /><br />";
echo "CountryCode (\\PhpTwinfield\\Country): <pre>" . print_r($office->getCountryCode(), true) . "</pre><br />";
echo "CountryCode (string): {$office->getCountryCodeToString()}<br />";
echo "VatFirstQuarterStartsIn: {$office->getVatFirstQuarterStartsIn()}<br />";
echo "VatPeriod: {$office->getVatPeriod()}<br />";
}
}

// Read an Office based off the passed in code and optionally the office.
if ($executeRead) {
try {
$office = $officeApiConnector->get("NLA000001", $defaultOffice);
} catch (ResponseException $e) {
$office = $e->getReturnedObject();
}

echo "<pre>";
print_r($office);
echo "</pre>";

echo "Office<br />";
echo "Code: {$office}<br />"; // string|null
echo "Code: {$office->getCode()}<br />"; // string|null
//echo "CountryCode (\\PhpTwinfield\\Country): <pre>" . print_r($office->getCountryCode(), true) . "</pre><br />"; // Country|null
//echo "CountryCode (string): {$office->getCountryCodeToString()}<br />"; // string|null
echo "Created (\\DateTimeInterface): <pre>" . print_r($office->getCreated(), true) . "</pre><br />"; // \DateTimeInterface|null The date/time the office was created.
echo "Created (string): {$office->getCreatedToString()}<br />"; // string|null

if ($office->hasMessages()) { // bool Object contains (error) messages true/false.
echo "Messages: " . print_r($office->getMessages(), true) . "<br />"; // Array|null (Error) messages.
}

echo "Modified (\\DateTimeInterface): <pre>" . print_r($office->getModified(), true) . "</pre><br />"; // \DateTimeInterface|null The date/time the office was modified.
echo "Modified (string): {$office->getModifiedToString()}<br />"; // string|null
echo "Name: {$office->getName()}<br />"; // string|null
echo "Result: {$office->getResult()}<br />"; // int|null Result (0 = error, 1 or empty = success).
echo "ShortName: {$office->getShortName()}<br />"; // string|null
echo "Status: {$office->getStatus()}<br />"; // Status|null
echo "Touched: {$office->getTouched()}<br />"; // int|null The number of times the office is modified.
echo "User (\\PhpTwinfield\\User): <pre>" . print_r($office->getUser(), true) . "</pre><br />"; // User|null The code of the user who created or modified the Office.
echo "User (string): {$office->getUserToString()}<br />"; // string|null
//echo "VatFirstQuarterStartsIn: {$office->getVatFirstQuarterStartsIn()}<br />"; // string|null
//echo "VatPeriod: {$office->getVatPeriod()}<br />"; // string|null
}
2 changes: 1 addition & 1 deletion examples/PayCode.php
Original file line number Diff line number Diff line change
Expand Up @@ -45,7 +45,7 @@
* Usage: $options['paytype'] = 'pay';
*/

//List all with pattern "SEPA*", field 0 (= search code or number), firstRow 1, maxRows 10, options -> paytype = pay
//List all with pattern "SEPA*", field 0 (= search code or name), firstRow 1, maxRows 10, options -> paytype = pay
if ($executeListAllWithFilter) {
$options = array('paytype' => 'pay');

Expand Down
2 changes: 1 addition & 1 deletion examples/Project.php
Original file line number Diff line number Diff line change
Expand Up @@ -69,7 +69,7 @@
*
*/

//List all with pattern "P*", field 0 (= search code or number), firstRow 1, maxRows 10, options -> accessrules = 0
//List all with pattern "P*", field 0 (= search code or name), firstRow 1, maxRows 10, options -> accessrules = 0
if ($executeListAllWithFilter) {
$options = array('accessrules' => 0);

Expand Down
4 changes: 2 additions & 2 deletions examples/Rate.php
Original file line number Diff line number Diff line change
Expand Up @@ -48,7 +48,7 @@
* to add multiple options. An option name may be used once, specifying an option multiple
* times will cause an error.
*
* Available options: office
* Available options: office, ratetype
*
* office Sets the office code.
* Usage: $options['office'] = 'SomeOfficeCode';
Expand All @@ -58,7 +58,7 @@
* Usage: $options['ratetype'] = 'quantity';
*/

//List all with pattern "DIR*", field 0 (= search code or number), firstRow 1, maxRows 10, options -> ratetype = 'quantity'
//List all with pattern "DIR*", field 0 (= search code or name), firstRow 1, maxRows 10, options -> ratetype = 'quantity'
if ($executeListAllWithFilter) {
$options = array('ratetype' => 'time');

Expand Down
2 changes: 1 addition & 1 deletion examples/UserRole.php
Original file line number Diff line number Diff line change
Expand Up @@ -41,7 +41,7 @@
* Usage: $options['office'] = 'SomeOfficeCode';
*/

//List all with pattern "LVL1*", field 0 (= search code or number), firstRow 1, maxRows 10
//List all with pattern "LVL1*", field 0 (= search code or name), firstRow 1, maxRows 10
if ($executeListAllWithFilter) {
try {
$userRoles = $userRoleApiConnector->listAll("LVL1*", 0, 1, 10);
Expand Down
2 changes: 1 addition & 1 deletion examples/VatCode.php
Original file line number Diff line number Diff line change
Expand Up @@ -59,7 +59,7 @@
*
*/

//List all with pattern "V*", field 0 (= search code or number), firstRow 1, maxRows 10, options -> vattype = 'sales'
//List all with pattern "V*", field 0 (= search code or name), firstRow 1, maxRows 10, options -> vattype = 'sales'
if ($executeListAllWithFilter) {
$options = array('vattype' => 'sales');

Expand Down
2 changes: 1 addition & 1 deletion examples/VatGroup.php
Original file line number Diff line number Diff line change
Expand Up @@ -41,7 +41,7 @@
* Usage: $options['office'] = 'SomeOfficeCode';
*/

//List all with pattern "1*", field 0 (= search code or number), firstRow 1, maxRows 10
//List all with pattern "1*", field 0 (= search code or name), firstRow 1, maxRows 10
if ($executeListAllWithFilter) {
try {
$vatGroups = $vatGroupApiConnector->listAll("1*", 0, 1, 10);
Expand Down
2 changes: 1 addition & 1 deletion examples/VatGroupCountry.php
Original file line number Diff line number Diff line change
Expand Up @@ -44,7 +44,7 @@
* Usage: $options['country'] = 'NL';
*/

//List all with pattern "*", field 0 (= search code or number), firstRow 1, maxRows 10, options -> country = NL
//List all with pattern "*", field 0 (= search code or name), firstRow 1, maxRows 10, options -> country = NL
if ($executeListAllWithFilter) {
$options = array('country' => 'NL');

Expand Down
2 changes: 1 addition & 1 deletion src/DomDocuments/TransactionsDocument.php
Original file line number Diff line number Diff line change
Expand Up @@ -11,10 +11,10 @@
use PhpTwinfield\Fields\FreeText1Field;
use PhpTwinfield\Fields\FreeText2Field;
use PhpTwinfield\Fields\FreeText3Field;
use PhpTwinfield\Fields\InvoiceNumberField;
use PhpTwinfield\Fields\PerformanceDateField;
use PhpTwinfield\Fields\PerformanceTypeField;
use PhpTwinfield\Fields\Transaction\CloseAndStartValueFields;
use PhpTwinfield\Fields\Transaction\InvoiceNumberField;
use PhpTwinfield\Fields\Transaction\PaymentReferenceField;
use PhpTwinfield\Fields\Transaction\RegimeField;
use PhpTwinfield\Fields\Transaction\StatementNumberField;
Expand Down
Loading