Skip to content

Commit 84538d2

Browse files
committed
add pursue method for CreditNote, DeliveryNote, Invoice and OrderConfirmation
1 parent 29f74ae commit 84538d2

File tree

11 files changed

+162
-0
lines changed

11 files changed

+162
-0
lines changed

README.md

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -86,6 +86,8 @@ $voucherList = $api->creditNote()->getVoucherListClient(); // see VoucherlistCli
8686
$response = $api->creditNote()->get($entityId);
8787
$response = $api->creditNote()->create($data);
8888
$response = $api->creditNote()->create($data, true); // finalized
89+
$response = $api->creditNote()->pursue($precedingSalesVoucherId, $data);
90+
$response = $api->creditNote()->pursue($precedingSalesVoucherId, $data, true); // finalized
8991
$response = $api->creditNote()->document($entityId); // get document ID
9092
$response = $api->creditNote()->document($entityId, true); // get file content
9193
$response = $api->creditNote()->document($entityId, true, 'image/*'); // accept only images
@@ -96,6 +98,7 @@ $response = $api->creditNote()->document($entityId, true, 'image/*'); // accept
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
@@ -133,6 +136,8 @@ $voucherList = $api->invoice()->getVoucherListClient(); // see VoucherlistClient
133136
$response = $api->invoice()->get($entityId);
134137
$response = $api->invoice()->create($data);
135138
$response = $api->invoice()->create($data, true); // finalized
139+
$response = $api->invoice()->pursue($precedingSalesVoucherId, $data);
140+
$response = $api->invoice()->pursue($precedingSalesVoucherId, $data, true); // finalized
136141
$response = $api->invoice()->document($entityId); // get document ID
137142
$response = $api->invoice()->document($entityId, true); // get file content
138143
$response = $api->invoice()->document($entityId, true, 'image/*'); // accept only images
@@ -144,6 +149,7 @@ $response = $api->invoice()->document($entityId, true, 'application/xml'); // ge
144149
$voucherList = $api->orderConfirmation()->getVoucherListClient(); // see VoucherlistClient Documentation
145150
$response = $api->orderConfirmation()->get($entityId);
146151
$response = $api->orderConfirmation()->create($data);
152+
$response = $api->orderConfirmation()->pursue($precedingSalesVoucherId, $data);
147153
$response = $api->orderConfirmation()->document($entityId); // get document ID
148154
$response = $api->orderConfirmation()->document($entityId, true); // get file content
149155
$response = $api->orderConfirmation()->document($entityId, true, 'image/*'); // accept only images

src/Clients/CreditNote.php

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -8,13 +8,15 @@
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
{
1516
use CreateFinalizeTrait;
1617
use DocumentClientTrait;
1718
use GetTrait;
19+
use PursueFinalizeTrait;
1820
use VoucherListTrait;
1921

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

src/Clients/DeliveryNote.php

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -8,13 +8,15 @@
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
{
1516
use CreateTrait;
1617
use DocumentClientTrait;
1718
use GetTrait;
19+
use PursueTrait;
1820
use VoucherListTrait;
1921

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

src/Clients/Invoice.php

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -8,13 +8,15 @@
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;
1617
use DocumentClientTrait;
1718
use GetTrait;
19+
use PursueFinalizeTrait;
1820
use VoucherListTrait;
1921

2022
protected string $resource = 'invoices';

src/Clients/OrderConfirmation.php

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -8,13 +8,15 @@
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;
1617
use DocumentClientTrait;
1718
use GetTrait;
19+
use PursueTrait;
1820
use VoucherListTrait;
1921

2022
protected string $resource = 'order-confirmations';
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+
}

src/Clients/Traits/PursueTrait.php

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 PursueTrait
11+
{
12+
/**
13+
* @param mixed[] $data
14+
*/
15+
public function pursue(string $precedingSalesVoucherId, array $data): ResponseInterface
16+
{
17+
$api = $this->api->newRequest('POST', $this->resource . '?precedingSalesVoucherId=' . rawurlencode($precedingSalesVoucherId));
18+
19+
$api->setRequest($api->getRequest()->withBody(Utils::createStream($data)));
20+
21+
return $api->getResponse();
22+
}
23+
}

tests/Clients/CreditNoteTest.php

Lines changed: 34 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -61,6 +61,40 @@ public function testCreateFinalized(): void
6161
);
6262
}
6363

64+
public function testPursue(): void
65+
{
66+
[$api, $stub] = $this->createClientMockObject(CreditNote::class);
67+
68+
$response = $stub->pursue('resource-id', [
69+
'version' => 0
70+
]);
71+
72+
$this->assertInstanceOf(ResponseInterface::class, $response);
73+
74+
$this->assertEquals('POST', $api->getRequest()->getMethod());
75+
$this->assertEquals(
76+
$api->apiUrl . '/v1/credit-notes?precedingSalesVoucherId=resource-id',
77+
$api->getRequest()->getUri()->__toString()
78+
);
79+
}
80+
81+
public function testPursueinalized(): void
82+
{
83+
[$api, $stub] = $this->createClientMockObject(CreditNote::class);
84+
85+
$response = $stub->pursue('resource-id', [
86+
'version' => 0
87+
], true);
88+
89+
$this->assertInstanceOf(ResponseInterface::class, $response);
90+
91+
$this->assertEquals('POST', $api->getRequest()->getMethod());
92+
$this->assertEquals(
93+
$api->apiUrl . '/v1/credit-notes?precedingSalesVoucherId=resource-id&finalize=true',
94+
$api->getRequest()->getUri()->__toString()
95+
);
96+
}
97+
6498
public function testGetPage(): void
6599
{
66100
$this->expectDeprecationV1Warning('getPage');

tests/Clients/DeliveryNoteTest.php

Lines changed: 17 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -44,6 +44,23 @@ public function testCreate(): void
4444
);
4545
}
4646

47+
public function testPursue(): void
48+
{
49+
[$api, $stub] = $this->createClientMockObject(DeliveryNote::class);
50+
51+
$response = $stub->pursue('resource-id', [
52+
'version' => 0
53+
]);
54+
55+
$this->assertInstanceOf(ResponseInterface::class, $response);
56+
57+
$this->assertEquals('POST', $api->getRequest()->getMethod());
58+
$this->assertEquals(
59+
$api->apiUrl . '/v1/delivery-notes?precedingSalesVoucherId=resource-id',
60+
$api->getRequest()->getUri()->__toString()
61+
);
62+
}
63+
4764
public function testGetPage(): void
4865
{
4966
$this->expectDeprecationV1Warning('getPage');

tests/Clients/InvoiceTest.php

Lines changed: 34 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -46,6 +46,40 @@ public function testCreateFinalized(): void
4646
);
4747
}
4848

49+
public function testPursue(): void
50+
{
51+
[$api, $stub] = $this->createClientMockObject(Invoice::class);
52+
53+
$response = $stub->pursue('resource-id', [
54+
'version' => 0
55+
]);
56+
57+
$this->assertInstanceOf(ResponseInterface::class, $response);
58+
59+
$this->assertEquals('POST', $api->getRequest()->getMethod());
60+
$this->assertEquals(
61+
$api->apiUrl . '/v1/invoices?precedingSalesVoucherId=resource-id',
62+
$api->getRequest()->getUri()->__toString()
63+
);
64+
}
65+
66+
public function testPursueinalized(): void
67+
{
68+
[$api, $stub] = $this->createClientMockObject(Invoice::class);
69+
70+
$response = $stub->pursue('resource-id', [
71+
'version' => 0
72+
], true);
73+
74+
$this->assertInstanceOf(ResponseInterface::class, $response);
75+
76+
$this->assertEquals('POST', $api->getRequest()->getMethod());
77+
$this->assertEquals(
78+
$api->apiUrl . '/v1/invoices?precedingSalesVoucherId=resource-id&finalize=true',
79+
$api->getRequest()->getUri()->__toString()
80+
);
81+
}
82+
4983
public function testGet(): void
5084
{
5185
[$api, $stub] = $this->createClientMockObject(Invoice::class);

0 commit comments

Comments
 (0)