Pohoda XML communication

v2.1.0 2024-12-23 01:01 UTC

This package is auto-updated.

Last update: 2024-12-23 01:13:37 UTC


README

Build Status Scrutinizer Code Quality Latest Stable Version Minimum PHP Version Total Downloads Software License Code Coverage

Library for manipulation with data, which came as XML from Pohoda mServer.

Pohoda is an accounting software for Czech Republic, Slovakia and probably few other countries.

What is different:

Usage of phpunit, extended tests, phpstan 1.12, deeper type checking

Installation

Add to composer.json:

composer.phar require alex-kalanis/pohoda

Example of order imports

Examples of importing each type - more in spec folder.

use Riesenia\Pohoda;

$pohoda = new Pohoda('ICO');

// create file
$pohoda->open($filename, 'i_obj1', 'Import orders');

// create order
$order = $pohoda->createOrder([
    'numberOrder' => $order_number,
    'isReserved' => true,
    'date' => $created,
    'text' => '...',
    'partnerIdentity' => [
        'address' => [
            'name' => $billing_name,
            'street' => $billing_street,
            'city' => $billing_city,
            'zip' => $billing_zip,
            'email' => $email,
            'phone' => $phone
        ],
        'shipToAddress' => [
            'name' => $shipping_name,
            'street' => $shipping_street,
            'city' => $shipping_city,
            'zip' => $shipping_zip,
            'email' => $email,
            'phone' => $phone
        ]
    ]
]);

// add items
foreach ($items as $item) {
    $order->addItem([
        'code' => $item->code,
        'text' => $item->text,
        'quantity' => $item->quantity,
        'payVAT' => false,
        'rateVAT' => $item->rate,
        'homeCurrency' => [
            'unitPrice' => $item->unit_price
        ],
        'stockItem' => [
            'stockItem' => [
                'id' => $item->pohoda_id
            ]
        ]
    ]);
}

// add summary
$order->addSummary([
    'roundingDocument' => 'none'
]);

// add order to import (identified by $order_number)
$pohoda->addItem($order_number, $order);

// finish import file
$pohoda->close();

Exporting stored goods

The creation of request to export goods is realized by creating ListRequest.

use Riesenia\Pohoda;

$pohoda = new Pohoda('ICO');

// create request for export
$pohoda->open($filename, 'e_zas1', 'Export stock');

$request = $pohoda->createListRequest([
    'type' => 'Stock'
]);

// optional filter
$request->addUserFilterName('MyFilter');

$pohoda->addItem('Export 001', $request);

$pohoda->close();

The rest of the processing itself is simple - just call next and got SimpleXMLElement with entity.

// load file
$pohoda->loadStock($filename);

while ($stock = $pohoda->next()) {
    // access header
    $header = $stock->children('stk', true)->stockHeader;

    // ...
}

Example of deleting stock

When you delete stock you need to create an agenda with empty data and set them delete actionType.

use Riesenia\Pohoda;

$pohoda = new Pohoda('ICO');

// create request for deletion
$pohoda->open($filename, 'd_zas1', 'Delete stock');

$stock = $pohoda->createStock([]);

$stock->addActionType('delete', [
    'code' => $code
]);

$pohoda->addItem($code, $stock);

$pohoda->close();

Using ValueTransformer for value update

With interface ValueTransformer you can implement the transformation, which changes all the values. Example for change all values to uppercase:

use Riesenia\Pohoda;

class Capitalizer implements \Riesenia\Pohoda\ValueTransformer\ValueTransformerInterface
{
    public function transform(string $value): string
    {
        return \strtoupper($value);
    }
}

$pohoda = new Pohoda('ICO');

// Register the capitalizer to be used to capitalize values
$pohoda->getTransformerListing()->addTransformer(new Capitalizer());

...