PHP code example of whitecube / winbooks-on-web-php-client

1. Go to this page and download the library: Download whitecube/winbooks-on-web-php-client library. Choose the download type require.

2. Extract the ZIP file and open the index.php.

3. Add this code to the index.php.
    
        
<?php
require_once('vendor/autoload.php');

/* Start to develop here. Best regards https://php-download.com/ */

    

whitecube / winbooks-on-web-php-client example snippets


use Whitecube\Winbooks\Winbooks;

// $access_token and $refresh_token can be null if you do not have them yet
$winbooks = new Winbooks($access_token, $refresh_token);

if(! $winbooks->authenticated()) {
    [$access_token, $refresh_token] = $winbooks->authenticate($email, $exchange_token);
    // Store the tokens somewhere safe
}

// Now you can start using the API

$winbooks->folder('TEST_FOLDER');

$winbooks->get(/*...*/)

$customers = $winbooks->all('Customers');

$vlad = $winbooks->get('Customer', 'VLADIMIR');
// With ID
$vlad = $winbooks->get('Customer', '4713a22f-ebc0-ea11-80c7-0050s68cc4a2');

$vlad = $winbooks->get('Customer', 'VLADIMIR', 3);

$results = $winbooks->query('Customers', function($query) {
    // Build your query...
    $query->select('Id', 'Code')->orderBy('Created', 'desc')->paginate(20);
});

$query->select('Id', 'VatApplicable', 'Memo');

use Whitecube\Winbooks\Query\Operator;

$query->selectOperator(Operator::distinct(), 'Id', 'VatApplicable', 'Memo');

$query->where('Id', '4713a22f-ebc0-ea11-80c7-0050s68cc4a2');

$query->where('Amount', '>=', 1000.00);

use Whitecube\Winbooks\Query\Operator;

$query->where('Name', 'like', '%Vlad%');
// or
$query->where('Name', Operator::having(), 'something');

use Whitecube\Winbooks\Query;

$query->where('Code', '=', Query::property('Id'));

$query->orderBy('Amount', 'desc');

$query->with('third');

$query->with('third', function($join) {
    $join->on('Third_Id', 'Id')->owner('something')->alias('person');
});

use Whitecube\Winbooks\Models\Logistics\DocumentHeader;

$query->join(DocumentHeader::class, function($join) {
    $join->on('DocumentHeader_Id', '=', 'Some_Property')->alias('header');
});

$query->take(50);

$query->skip(50);

// Only take 50 results to display on the first page
$query->paginate(50);
// Query the 50 next results (on page 2)
$query->paginate(50, 2);

$winbooks->add('Customer', 'VLADIMIR', [
    'Memo' => 'A Memo for Vladimir',
    // ...
]);

// You can also add multiple objects at once:

$winbooks->addMany('Customers', [
    [
        'Code' => 'VLADIMIR',
        'Memo' => 'A Memo for Vladimir',
        // ...
    ],
    [
        'Code' => 'ALICE',
        'Memo' => 'A Memo for Alice',
        // ...
    ]
]);

use Whitecube\Winbooks\Models\Customer;

$vlad = new Customer(['Code' => 'VLADIMIR']);
$alice = new Customer(['Code' => 'ALICE']);

$winbooks->addModel($vlad);
// or multiple
$winbooks->addModels([$vlad, $alice]);

$winbooks->update('Customer', 'ALICE', [
    'Memo' => 'This is an updated memo for Alice',
]);

// Or multiple

$winbooks->updateMany('Customers', [
    [
        'Code' => 'VLADIMIR',
        'Memo' => 'This is an updated memo for Vladimir',
    ],
    [
        'Code' => 'ALICE',
        'Memo' => 'This is an updated memo for Alice',
    ]
]);

$winbooks->delete('Customer', 'VLADIMIR');