riesenia / pohoda
Pohoda XML communication
Installs: 71 921
Dependents: 1
Suggesters: 0
Security: 0
Stars: 34
Watchers: 7
Forks: 29
Open Issues: 5
Requires
- php: ^7.1 || ^8.0
- symfony/options-resolver: ^4.0 || ^5.0 || ^6.0
Requires (Dev)
- friends-of-phpspec/phpspec-expect: *
- friendsofphp/php-cs-fixer: ^2.0
- phpspec/phpspec: ^5.0 || ^6.0 || ^7.0
- rshop/php-cs-fixer-config: ^2.0
- dev-master
- v1.21.0
- v1.20.0
- v1.19.2
- v1.19.1
- v1.19.0
- v1.18.3
- v1.18.2
- v1.18.1
- v1.18.0
- v1.17.2
- v1.17.1
- v1.17.0
- v1.16.4
- v1.16.3
- v1.16.2
- v1.16.1
- v1.16.0
- v1.15.1
- v1.15.0
- v1.14.1
- v1.14.0
- v1.13.0
- v1.12.3
- v1.12.2
- v1.12.1
- v1.12.0
- v1.11.0
- v1.10.0
- v1.9.0
- v1.8.1
- v1.8.0
- v1.7.0
- v1.6.2
- v1.6.1
- v1.6.0
- v1.5.1
- v1.5
- v1.4.12
- v1.4.11
- v1.4.10
- v1.4.9
- v1.4.8
- v1.4.7
- v1.4.6
- v1.4.5
- v1.4.4
- v1.4.3
- v1.4.2
- v1.4.1
- v1.4.0
- v1.3.4
- v1.3.3
- v1.3.2
- v1.3.1
- v1.3.0
- v1.2.1
- v1.2.0
- v1.1.3
- v1.1.2
- v1.1.1
- v1.1.0
- v1.0.0
- v0.1.1
- v0.1.0
- dev-old
This package is auto-updated.
Last update: 2024-10-27 12:26:34 UTC
README
Inštalácia
Pridaním do composer.json:
{ "require": { "riesenia/pohoda": "~1.0" } }
Príkazom:
composer require 'riesenia/pohoda:~1.0'
Príklad importu objednávok
Príklady pre import jednotlivých typov viď. 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();
Príklad exportu zásob
Vytvorenie príkazu na export sa realizuje prostredníctvom vytvorenia 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();
Samotné spracovanie dát je riešené jednoducho - volanie next
vracia SimpleXMLElement s danou entitou.
// load file $pohoda->loadStock($filename); while ($stock = $pohoda->next()) { // access header $header = $stock->children('stk', true)->stockHeader; // ... }
Príklad zmazania zásoby
Pri mazaní je potrebné vytvoriť agendu s prázdnymi dátami a nastaviť jej 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();
Použitie ValueTransformer pre úpravu hodnôt
Pomocou rozhrania ValueTransformer môžeme implementovať transformátor, ktorý zmení všetky údaje. Príklad pre úpravu všetkých hodnôt na veľké písmena:
use Riesenia\Pohoda; class Capitalizer implements \Riesenia\Pohoda\ValueTransformer\ValueTransformer { public function transform(string $value): string { return \strtoupper($value); } } // Register the capitalizer to be used to capitalize values Pohoda::$transformers[] = new Capitalizer(); $pohoda = new Pohoda('ICO'); ...