Skip to content

Commit ff887e7

Browse files
authored
Merge pull request #138 from Sysix/pursue-vouchers
Pursue vouchers
2 parents 4d21659 + 335f3e9 commit ff887e7

15 files changed

+179
-18
lines changed

.php-cs-fixer.dist.php

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -15,6 +15,7 @@
1515
'multiline_whitespace_before_semicolons' => true,
1616
'native_type_declaration_casing' => true,
1717
'ordered_imports' => ['imports_order' => ['class', 'function', 'const'], 'sort_algorithm' => 'alpha'],
18+
'ordered_traits' => true,
1819
'no_alias_functions' => true,
1920
'no_alias_language_construct_call' => true,
2021
'no_alternative_syntax' => true,

README.md

Lines changed: 13 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -25,33 +25,34 @@ You need an [API Key](https://app.lexoffice.de/addons/public-api) for that.
2525
### Basic
2626
```php
2727
// store keys in .env file
28-
$apiKey = getenv('LEX_OFFICE_API_KEY');
28+
$apiKey = getenv('LEXOFFICE_API_KEY');
2929

3030
// in this example we are using guzzlehttp/guzzle package, it can be any PSR-18 HTTP Client
3131
// see: https://packagist.org/providers/psr/http-client-implementation
3232
$httpClient = \GuzzleHttp\Client();
3333
$api = new \Sysix\LexOffice\Api($apiKey, $httpClient);
3434
```
3535

36-
#### Optimize your HTTP Client
36+
### Optimize your HTTP Client
3737

3838
This library only prepares the `\Psr\Http\Message\RequestInterface` for the HTTP Client and returns its Response.
3939
There are almost no error checks, no caching and no rate limiting. Your PSR-18 HTTP Client should come with a way to deal with it.
4040

4141
Here is a example with `guzzlehttp/guzzle` , `kevinrob/guzzle-cache-middleware` and `spatie/guzzle-rate-limiter-middleware`:
4242

4343
```php
44-
$apiKey = getenv('LEX_OFFICE_API_KEY');
44+
$apiKey = getenv('LEXOFFICE_API_KEY');
4545

4646
$stack = \GuzzleHttp\HandlerStack();
4747
$stack->push(new \Kevinrob\GuzzleCache\CacheMiddleware\CacheMiddleware(), 'cache');
4848
$stack->push(\Spatie\GuzzleRateLimiterMiddleware\RateLimiterMiddleware\RateLimiterMiddleware::perSecond(2));
4949

5050
$httpClient = \GuzzleHttp\Client(['handler' => $stack]);
5151
$api = new \Sysix\LexOffice\Api($apiKey, $httpClient);
52-
5352
```
5453

54+
## Endpoints
55+
5556
### Contact Endpoint
5657
```php
5758

@@ -85,21 +86,22 @@ $voucherList = $api->creditNote()->getVoucherListClient(); // see VoucherlistCli
8586
$response = $api->creditNote()->get($entityId);
8687
$response = $api->creditNote()->create($data);
8788
$response = $api->creditNote()->create($data, true); // finalized
89+
$response = $api->creditNote()->pursue($precedingSalesVoucherId, $data);
90+
$response = $api->creditNote()->pursue($precedingSalesVoucherId, $data, true); // finalized
8891
$response = $api->creditNote()->document($entityId); // get document ID
8992
$response = $api->creditNote()->document($entityId, true); // get file content
9093
$response = $api->creditNote()->document($entityId, true, 'image/*'); // accept only images
91-
$response = $api->creditNote()->document($entityId, true, 'application/xml'); // get XRechung XML File (if possible)
9294
```
9395

9496
### Deliverys Notes Endpoint
9597
```php
9698
$voucherList = $api->deliveryNote()->getVoucherListClient(); // see VoucherlistClient Documentation
9799
$response = $api->deliveryNote()->get($entityId);
98100
$response = $api->deliveryNote()->create($data);
101+
$response = $api->deliveryNote()->pursue($precedingSalesVoucherId, $data);
99102
$response = $api->deliveryNote()->document($entityId); // get document ID
100103
$response = $api->deliveryNote()->document($entityId, true); // get file content
101104
$response = $api->deliveryNote()->document($entityId, true, 'image/*'); // accept only images
102-
$response = $api->deliveryNote()->document($entityId, true, 'application/xml'); // get XRechung XML File (if possible)
103105
```
104106

105107
### Down Payment Invoices Endpoint
@@ -110,7 +112,6 @@ $response = $api->downPaymentInvoice()->create($data);
110112
$response = $api->downPaymentInvoice()->document($entityId); // get document ID
111113
$response = $api->downPaymentInvoice()->document($entityId, true); // get file content
112114
$response = $api->downPaymentInvoice()->document($entityId, true, 'image/*'); // accept only images
113-
$response = $api->downPaymentInvoice()->document($entityId, true, 'application/xml'); // get XRechung XML File (if possible)
114115
```
115116

116117
### Event Subscriptions Endpooint
@@ -135,6 +136,8 @@ $voucherList = $api->invoice()->getVoucherListClient(); // see VoucherlistClient
135136
$response = $api->invoice()->get($entityId);
136137
$response = $api->invoice()->create($data);
137138
$response = $api->invoice()->create($data, true); // finalized
139+
$response = $api->invoice()->pursue($precedingSalesVoucherId, $data);
140+
$response = $api->invoice()->pursue($precedingSalesVoucherId, $data, true); // finalized
138141
$response = $api->invoice()->document($entityId); // get document ID
139142
$response = $api->invoice()->document($entityId, true); // get file content
140143
$response = $api->invoice()->document($entityId, true, 'image/*'); // accept only images
@@ -146,10 +149,10 @@ $response = $api->invoice()->document($entityId, true, 'application/xml'); // ge
146149
$voucherList = $api->orderConfirmation()->getVoucherListClient(); // see VoucherlistClient Documentation
147150
$response = $api->orderConfirmation()->get($entityId);
148151
$response = $api->orderConfirmation()->create($data);
152+
$response = $api->orderConfirmation()->pursue($precedingSalesVoucherId, $data);
149153
$response = $api->orderConfirmation()->document($entityId); // get document ID
150154
$response = $api->orderConfirmation()->document($entityId, true); // get file content
151155
$response = $api->orderConfirmation()->document($entityId, true, 'image/*'); // accept only images
152-
$response = $api->orderConfirmation()->document($entityId, true, 'application/xml'); // get XRechung XML File (if possible)
153156
```
154157

155158
### Payment Endpoint
@@ -181,7 +184,6 @@ $response = $api->quotation()->create($data, true); // finalized
181184
$response = $api->quotation()->document($entityId); // get document ID
182185
$response = $api->quotation()->document($entityId, true); // get file content
183186
$response = $api->quotation()->document($entityId, true, 'image/*'); // accept only images
184-
$response = $api->quotation()->document($entityId, true, 'application/xml'); // get XRechung XML File (if possible)
185187
```
186188

187189
### Recurring Templates Endpoint
@@ -258,6 +260,8 @@ $client->updatedDateTo = new \DateTime('2023-12-01');
258260
$response = $client->getPage(0);
259261
```
260262

263+
## Utils
264+
261265
### get JSON from Success and Error Response
262266

263267
```php

src/Clients/CreditNote.php

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -8,14 +8,16 @@
88
use Sysix\LexOffice\Clients\Traits\CreateFinalizeTrait;
99
use Sysix\LexOffice\Clients\Traits\DocumentClientTrait;
1010
use Sysix\LexOffice\Clients\Traits\GetTrait;
11+
use Sysix\LexOffice\Clients\Traits\PursueFinalizeTrait;
1112
use Sysix\LexOffice\Clients\Traits\VoucherListTrait;
1213

1314
class CreditNote extends BaseClient
1415
{
15-
use GetTrait;
1616
use CreateFinalizeTrait;
17-
use VoucherListTrait;
1817
use DocumentClientTrait;
18+
use GetTrait;
19+
use PursueFinalizeTrait;
20+
use VoucherListTrait;
1921

2022
protected string $resource = 'credit-notes';
2123

src/Clients/DeliveryNote.php

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -8,14 +8,16 @@
88
use Sysix\LexOffice\Clients\Traits\CreateTrait;
99
use Sysix\LexOffice\Clients\Traits\DocumentClientTrait;
1010
use Sysix\LexOffice\Clients\Traits\GetTrait;
11+
use Sysix\LexOffice\Clients\Traits\PursueTrait;
1112
use Sysix\LexOffice\Clients\Traits\VoucherListTrait;
1213

1314
class DeliveryNote extends BaseClient
1415
{
15-
use GetTrait;
1616
use CreateTrait;
17-
use VoucherListTrait;
1817
use DocumentClientTrait;
18+
use GetTrait;
19+
use PursueTrait;
20+
use VoucherListTrait;
1921

2022
protected string $resource = 'delivery-notes';
2123

src/Clients/DownPaymentInvoice.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -11,9 +11,9 @@
1111

1212
class DownPaymentInvoice extends BaseClient
1313
{
14+
use DocumentClientTrait;
1415
use GetTrait;
1516
use VoucherListTrait;
16-
use DocumentClientTrait;
1717

1818
protected string $resource = 'down-payment-invoices';
1919

src/Clients/Event.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -13,8 +13,8 @@
1313
class Event extends BaseClient
1414
{
1515
use CreateTrait;
16-
use GetTrait;
1716
use DeleteTrait;
17+
use GetTrait;
1818

1919
protected string $resource = 'event-subscriptions';
2020

src/Clients/Invoice.php

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -8,14 +8,16 @@
88
use Sysix\LexOffice\Clients\Traits\CreateFinalizeTrait;
99
use Sysix\LexOffice\Clients\Traits\DocumentClientTrait;
1010
use Sysix\LexOffice\Clients\Traits\GetTrait;
11+
use Sysix\LexOffice\Clients\Traits\PursueFinalizeTrait;
1112
use Sysix\LexOffice\Clients\Traits\VoucherListTrait;
1213

1314
class Invoice extends BaseClient
1415
{
1516
use CreateFinalizeTrait;
17+
use DocumentClientTrait;
1618
use GetTrait;
19+
use PursueFinalizeTrait;
1720
use VoucherListTrait;
18-
use DocumentClientTrait;
1921

2022
protected string $resource = 'invoices';
2123

src/Clients/OrderConfirmation.php

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -8,14 +8,16 @@
88
use Sysix\LexOffice\Clients\Traits\CreateTrait;
99
use Sysix\LexOffice\Clients\Traits\DocumentClientTrait;
1010
use Sysix\LexOffice\Clients\Traits\GetTrait;
11+
use Sysix\LexOffice\Clients\Traits\PursueTrait;
1112
use Sysix\LexOffice\Clients\Traits\VoucherListTrait;
1213

1314
class OrderConfirmation extends BaseClient
1415
{
1516
use CreateTrait;
17+
use DocumentClientTrait;
1618
use GetTrait;
19+
use PursueTrait;
1720
use VoucherListTrait;
18-
use DocumentClientTrait;
1921

2022
protected string $resource = 'order-confirmations';
2123

src/Clients/Quotation.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -13,9 +13,9 @@
1313
class Quotation extends BaseClient
1414
{
1515
use CreateFinalizeTrait;
16+
use DocumentClientTrait;
1617
use GetTrait;
1718
use VoucherListTrait;
18-
use DocumentClientTrait;
1919

2020
protected string $resource = 'quotations';
2121

Lines changed: 23 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,23 @@
1+
<?php
2+
3+
declare(strict_types=1);
4+
5+
namespace Sysix\LexOffice\Clients\Traits;
6+
7+
use Psr\Http\Message\ResponseInterface;
8+
use Sysix\LexOffice\Utils;
9+
10+
trait PursueFinalizeTrait
11+
{
12+
/**
13+
* @param mixed[] $data
14+
*/
15+
public function pursue(string $precedingSalesVoucherId, array $data, bool $finalized = false): ResponseInterface
16+
{
17+
$api = $this->api->newRequest('POST', $this->resource . '?precedingSalesVoucherId=' . rawurlencode($precedingSalesVoucherId) . ($finalized ? '&finalize=true' : ''));
18+
19+
$api->setRequest($api->getRequest()->withBody(Utils::createStream($data)));
20+
21+
return $api->getResponse();
22+
}
23+
}

0 commit comments

Comments
 (0)