alex-kalanis / pohoda
Pohoda XML communication
Requires
- php: >=8.1
- ext-dom: *
- ext-iconv: *
- ext-intl: *
- ext-mbstring: *
- ext-simplexml: *
- ext-xmlreader: *
- ext-xmlwriter: *
- symfony/options-resolver: ^6.0 || ^7.0
Requires (Dev)
- friends-of-phpspec/phpspec-expect: *
- friendsofphp/php-cs-fixer: ^3.0
- phpspec/phpspec: ^7.0
- phpstan/phpstan: ^1.0
- phpstan/phpstan-phpunit: ^1.0
- phpunit/phpunit: >=10.0 <11
- shipmonk/composer-dependency-analyser: ^1.4
README
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()); ...
Sources
- XML Import
- XML Export
- Schemas
- Checker - Win 32bit