PHP code example of masmerise / scrada-php-sdk

1. Go to this page and download the library: Download masmerise/scrada-php-sdk 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/ */

    

masmerise / scrada-php-sdk example snippets


use Scrada\Authentication\Credentials;
use Scrada\Scrada;

$credentials = Credentials::present(
    key: '4844a45c-33d1-4937-83f4-366d36449eaf', 
    password: 'SajA1NOEphxVMwTTFzrDswj3AQkEGCCJ',
); 

$scrada = Scrada::authenticate($credentials);

use Scrada\Company\Type\Primitive\CompanyId;

$company = CompanyId::fromString('4ccc0005-0bdd-430b-8f45-264c3f1a2a02'); 
$company = $scrada->company->get($company);

use Scrada\CashBook\Type\Primitive\CashBookId;
use Scrada\CashBook\Type\Primitive\CodaGenerationPeriod;
use Scrada\CashBook\Type\Primitive\Name;
use Scrada\CashBook\Update\UpdateCashBook;
use Scrada\Company\Type\Primitive\CompanyId;

$companyId = CompanyId::fromString('4ccc0005-0bdd-430b-8f45-264c3f1a2a02');

$cashBookId = CashBookId::fromString('d84835b0-7125-4f8f-b10a-957a0cc73089');

$data = UpdateCashBook::parameters(
    name: Name::fromString('Acme Inc.'),
    codaGenerationPeriodType: CodaGenerationPeriod::EveryDay,
);

$scrada->cashBook->update($companyId, $cashBookId, $data);

use Scrada\Company\Get\Failure\CouldNotGetCompany;

try {
    $company = $scrada->company->get($id);
} catch (CouldNotGetCompany $ex) {
    $logger->log($ex->getMessage());
}

use Scrada\Company\Get\Failure\CouldNotGetCompany;

try {
    $company = $scrada->company->get($id);
} catch (CouldNotGetCompany $ex) {
    $scradaError = $ex->error;

    $logger->log($scradaError->defaultFormat); // Localized error text
}

$store = Container::getInstance()->get('cache');

$scrada = Scrada::authenticate(
    Credentials::present(...)
)->withStore($store);

$scrada->useDutch();

$scrada->useEnglish();

$scrada->useFrench();

$scrada->useProduction();

$scrada->useTest();
bash
composer