Skip to content

Commit 5cec431

Browse files
authored
Merge pull request #53 from codebar-ag/feature-items
Feature Items
2 parents 7c8fdf2 + 7d3cd79 commit 5cec431

26 files changed

+1010
-6
lines changed

.gitbook.yaml

Lines changed: 0 additions & 5 deletions
This file was deleted.

.phpunit.cache/test-results

Lines changed: 1 addition & 1 deletion
Large diffs are not rendered by default.

README.md

Lines changed: 79 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -50,6 +50,7 @@ This package was developed to give you a quick start to the Bexio API.
5050
- [Files](#files)
5151
- [Iban Payments](#iban-payments)
5252
- [Invoices](#invoices)
53+
- [Items](#items)
5354
- [Languages](#languages)
5455
- [Manual Entries](#manual-entries)
5556
- [Notes](#notes)
@@ -682,6 +683,7 @@ We provide enums for the following values:
682683
| ContactSectors: OrderByEnum | ID(), ID_ASC(), ID_DESC(), NAME(), NAME_ASC(), NAME_DESC() |
683684
| IbanPayments: AllowanceTypeEnum | FEE_PAID_BY_SENDER(), FEE_PAID_BY_RECIPIENT(), FEE_SPLIT(), NO_FEE() |
684685
| IbanPayments: StatusEnum | OPEN(), TRANSFERRED(), DOWNLOADED(), ERROR(), CANCELLED() |
686+
| Items: OrderByEnum | ID(), ID_ASC(), ID_DESC(), INTERN_NAME(), INTERN_NAME_ASC(), INTERN_NAME_DESC() |
685687
| ManualEntries: TypeEnum | MANUAL_SINGLE_ENTRY(), MANUAL_GROUP_ENTRY(), MANUAL_COMPOUND_ENTRY() |
686688
| QrPayments: AllowanceTypeEnum | FEE_PAID_BY_SENDER(), FEE_PAID_BY_RECIPIENT(), FEE_SPLIT(), NO_FEE() |
687689
| QrPayments: StatusEnum | OPEN(), TRANSFERRED(), DOWNLOADED(), ERROR(), CANCELLED() |
@@ -725,6 +727,8 @@ We provide DTOs for the following:
725727
| InvoiceDTO |
726728
| InvoicePositionDTO |
727729
| InvoiceTaxDTO |
730+
| ItemDTO |
731+
| CreateEditItemDTO |
728732
| PdfDTO |
729733
| LanguageDTO |
730734
| AddFileDTO |
@@ -2003,6 +2007,81 @@ $title = $connector->send(new DeleteATitleRequest(
20032007
));
20042008
```
20052009

2010+
### Items
2011+
```php
2012+
/**
2013+
* Fetch A List Of Items
2014+
*/
2015+
$items = $connector->send(new FetchAListOfItemsRequest())->dto();
2016+
```
2017+
2018+
```php
2019+
/**
2020+
* Fetch An Item
2021+
*/
2022+
$item = $connector->send(new FetchAnItemRequest(
2023+
article_id: 1
2024+
))->dto();
2025+
```
2026+
2027+
```php
2028+
/**
2029+
* Search Items
2030+
*/
2031+
$items = $connector->send(new SearchItemsRequest(
2032+
searchField: 'intern_name',
2033+
searchTerm: 'Something'
2034+
))->dto();
2035+
```
2036+
2037+
```php
2038+
/**
2039+
* Create Item
2040+
*/
2041+
$item = $connector->send(new CreateItemRequest(
2042+
data: new CreateEditItemDTO(
2043+
user_id: 1,
2044+
article_type_id: 1,
2045+
intern_code: 'ITEM-001',
2046+
intern_name: 'Test Item',
2047+
intern_description: 'Item Description',
2048+
sale_price: '20.00',
2049+
purchase_price: '10.00',
2050+
currency_id: 1,
2051+
tax_income_id: 14,
2052+
tax_expense_id: 21,
2053+
unit_id: 1,
2054+
)
2055+
))->dto();
2056+
```
2057+
2058+
```php
2059+
/**
2060+
* Edit Item
2061+
*/
2062+
$item = $connector->send(new EditAnItemRequest(
2063+
article_id: 1,
2064+
data: new CreateEditItemDTO(
2065+
user_id: 1,
2066+
article_type_id: 1,
2067+
intern_code: 'ITEM-001',
2068+
intern_name: 'Updated Item Name',
2069+
intern_description: 'Updated Description',
2070+
sale_price: '25.00',
2071+
purchase_price: '15.00',
2072+
)
2073+
))->dto();
2074+
```
2075+
2076+
```php
2077+
/**
2078+
* Delete Item
2079+
*/
2080+
$response = $connector->send(new DeleteAnItemRequest(
2081+
article_id: 1
2082+
));
2083+
```
2084+
20062085
### VAT Periods
20072086
```php
20082087
/**

phpunit.xml.dist

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -22,6 +22,7 @@
2222
<php>
2323
<env name="APP_KEY" value="base64:F+mHMDBbavrsp/I3WYA5lDSwDJJI/0wQG4eM3csq/lo="/>
2424
<env name="BEXIO_API_TOKEN" value=""/>
25+
<env name="RESET_FIXTURES" value="false"/>
2526
</php>
2627
<source>
2728
<include>
Lines changed: 99 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,99 @@
1+
<?php
2+
3+
namespace CodebarAg\Bexio\Dto\Items;
4+
5+
use Exception;
6+
use Illuminate\Support\Arr;
7+
use Saloon\Http\Response;
8+
use Spatie\LaravelData\Data;
9+
10+
class CreateEditItemDTO extends Data
11+
{
12+
public function __construct(
13+
public ?int $user_id,
14+
public int $article_type_id,
15+
public ?int $contact_id,
16+
public ?string $deliverer_code,
17+
public ?string $deliverer_name,
18+
public ?string $deliverer_description,
19+
public string $intern_code,
20+
public string $intern_name,
21+
public ?string $intern_description = null,
22+
public ?string $purchase_price = null,
23+
public ?string $sale_price = null,
24+
public ?float $purchase_total = null,
25+
public ?float $sale_total = null,
26+
public ?int $currency_id = null,
27+
public ?int $tax_income_id = null,
28+
public ?int $tax_expense_id = null,
29+
public ?int $unit_id = null,
30+
public bool $is_stock = false,
31+
public ?int $stock_id = null,
32+
public ?int $stock_place_id = null,
33+
public int $stock_nr = 0,
34+
public int $stock_min_nr = 0,
35+
public ?int $width = null,
36+
public ?int $height = null,
37+
public ?int $weight = null,
38+
public ?int $volume = null,
39+
public ?string $html_text = null, // Deprecated
40+
public ?string $remarks = null,
41+
public ?float $delivery_price = null,
42+
public ?int $article_group_id = null,
43+
public ?int $account_id = null,
44+
public ?int $expense_account_id = null,
45+
) {}
46+
47+
public static function fromResponse(Response $response): self
48+
{
49+
if ($response->failed()) {
50+
throw new \Exception('Failed to create DTO from Response');
51+
}
52+
53+
$data = $response->json();
54+
55+
return self::fromArray($data);
56+
}
57+
58+
public static function fromArray(array $data): self
59+
{
60+
if (! $data) {
61+
throw new Exception('Unable to create DTO. Data missing from response.');
62+
}
63+
64+
return new self(
65+
user_id: Arr::get($data, 'user_id'),
66+
article_type_id: Arr::get($data, 'article_type_id'),
67+
contact_id: Arr::get($data, 'contact_id'),
68+
deliverer_code: Arr::get($data, 'deliverer_code'),
69+
deliverer_name: Arr::get($data, 'deliverer_name'),
70+
deliverer_description: Arr::get($data, 'deliverer_description'),
71+
intern_code: Arr::get($data, 'intern_code'),
72+
intern_name: Arr::get($data, 'intern_name'),
73+
intern_description: Arr::get($data, 'intern_description'),
74+
purchase_price: Arr::get($data, 'purchase_price'),
75+
sale_price: Arr::get($data, 'sale_price'),
76+
purchase_total: Arr::get($data, 'purchase_total'),
77+
sale_total: Arr::get($data, 'sale_total'),
78+
currency_id: Arr::get($data, 'currency_id'),
79+
tax_income_id: Arr::get($data, 'tax_income_id'),
80+
tax_expense_id: Arr::get($data, 'tax_expense_id'),
81+
unit_id: Arr::get($data, 'unit_id'),
82+
is_stock: Arr::get($data, 'is_stock', false),
83+
stock_id: Arr::get($data, 'stock_id'),
84+
stock_place_id: Arr::get($data, 'stock_place_id'),
85+
stock_nr: Arr::get($data, 'stock_nr', 0),
86+
stock_min_nr: Arr::get($data, 'stock_min_nr', 0),
87+
width: Arr::get($data, 'width'),
88+
height: Arr::get($data, 'height'),
89+
weight: Arr::get($data, 'weight'),
90+
volume: Arr::get($data, 'volume'),
91+
html_text: Arr::get($data, 'html_text'),
92+
remarks: Arr::get($data, 'remarks'),
93+
delivery_price: Arr::get($data, 'delivery_price'),
94+
article_group_id: Arr::get($data, 'article_group_id'),
95+
account_id: Arr::get($data, 'account_id'),
96+
expense_account_id: Arr::get($data, 'expense_account_id'),
97+
);
98+
}
99+
}

src/Dto/Items/ItemDTO.php

Lines changed: 115 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,115 @@
1+
<?php
2+
3+
namespace CodebarAg\Bexio\Dto\Items;
4+
5+
use Exception;
6+
use Illuminate\Support\Arr;
7+
use Saloon\Http\Response;
8+
use Spatie\LaravelData\Data;
9+
10+
class ItemDTO extends Data
11+
{
12+
public function __construct(
13+
public int $id,
14+
public int $user_id,
15+
public int $article_type_id,
16+
public ?int $contact_id,
17+
public ?int $master_id,
18+
public ?string $deliverer_code,
19+
public ?string $deliverer_name,
20+
public ?string $deliverer_description,
21+
public string $intern_code,
22+
public string $intern_name,
23+
public ?string $intern_description,
24+
public ?string $purchase_price,
25+
public ?string $sale_price,
26+
public ?float $purchase_total,
27+
public ?float $sale_total,
28+
public ?int $currency_id,
29+
public ?int $tax_income_id,
30+
public ?int $tax_id,
31+
public ?int $tax_expense_id,
32+
public ?int $unit_id,
33+
public bool $is_stock,
34+
public ?int $stock_id,
35+
public ?int $stock_place_id,
36+
public int $stock_nr,
37+
public int $stock_min_nr,
38+
public int $stock_reserved_nr,
39+
public int $stock_available_nr,
40+
public int $stock_picked_nr,
41+
public int $stock_disposed_nr,
42+
public int $stock_ordered_nr,
43+
public ?int $width,
44+
public ?int $height,
45+
public ?int $weight,
46+
public ?int $volume,
47+
public ?string $html_text, // Deprecated
48+
public ?string $remarks,
49+
public ?float $delivery_price,
50+
public ?int $article_group_id,
51+
public ?int $account_id,
52+
public ?int $expense_account_id,
53+
) {}
54+
55+
public static function fromResponse(Response $response): self
56+
{
57+
if ($response->failed()) {
58+
throw new \Exception('Failed to create DTO from Response');
59+
}
60+
61+
$data = $response->json();
62+
63+
return self::fromArray($data);
64+
}
65+
66+
public static function fromArray(array $data): self
67+
{
68+
if (! $data) {
69+
throw new Exception('Unable to create DTO. Data missing from response.');
70+
}
71+
72+
return new self(
73+
id: Arr::get($data, 'id'),
74+
user_id: Arr::get($data, 'user_id'),
75+
article_type_id: Arr::get($data, 'article_type_id'),
76+
contact_id: Arr::get($data, 'contact_id'),
77+
master_id: Arr::get($data, 'master_id'),
78+
deliverer_code: Arr::get($data, 'deliverer_code'),
79+
deliverer_name: Arr::get($data, 'deliverer_name'),
80+
deliverer_description: Arr::get($data, 'deliverer_description'),
81+
intern_code: Arr::get($data, 'intern_code'),
82+
intern_name: Arr::get($data, 'intern_name'),
83+
intern_description: Arr::get($data, 'intern_description'),
84+
purchase_price: Arr::get($data, 'purchase_price'),
85+
sale_price: Arr::get($data, 'sale_price'),
86+
purchase_total: Arr::get($data, 'purchase_total'),
87+
sale_total: Arr::get($data, 'sale_total'),
88+
currency_id: Arr::get($data, 'currency_id'),
89+
tax_income_id: Arr::get($data, 'tax_income_id'),
90+
tax_id: Arr::get($data, 'tax_id'),
91+
tax_expense_id: Arr::get($data, 'tax_expense_id'),
92+
unit_id: Arr::get($data, 'unit_id'),
93+
is_stock: Arr::get($data, 'is_stock', false),
94+
stock_id: Arr::get($data, 'stock_id'),
95+
stock_place_id: Arr::get($data, 'stock_place_id'),
96+
stock_nr: Arr::get($data, 'stock_nr', 0),
97+
stock_min_nr: Arr::get($data, 'stock_min_nr', 0),
98+
stock_reserved_nr: Arr::get($data, 'stock_reserved_nr', 0),
99+
stock_available_nr: Arr::get($data, 'stock_available_nr', 0),
100+
stock_picked_nr: Arr::get($data, 'stock_picked_nr', 0),
101+
stock_disposed_nr: Arr::get($data, 'stock_disposed_nr', 0),
102+
stock_ordered_nr: Arr::get($data, 'stock_ordered_nr', 0),
103+
width: Arr::get($data, 'width'),
104+
height: Arr::get($data, 'height'),
105+
weight: Arr::get($data, 'weight'),
106+
volume: Arr::get($data, 'volume'),
107+
html_text: Arr::get($data, 'html_text'),
108+
remarks: Arr::get($data, 'remarks'),
109+
delivery_price: Arr::get($data, 'delivery_price'),
110+
article_group_id: Arr::get($data, 'article_group_id'),
111+
account_id: Arr::get($data, 'account_id'),
112+
expense_account_id: Arr::get($data, 'expense_account_id'),
113+
);
114+
}
115+
}

src/Enums/Items/OrderByEnum.php

Lines changed: 40 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,40 @@
1+
<?php
2+
3+
namespace CodebarAg\Bexio\Enums\Items;
4+
5+
use Spatie\Enum\Laravel\Enum;
6+
7+
/**
8+
* @method static self ID()
9+
* @method static self ID_ASC()
10+
* @method static self ID_DESC()
11+
* @method static self INTERN_NAME()
12+
* @method static self INTERN_NAME_ASC()
13+
* @method static self INTERN_NAME_DESC()
14+
*/
15+
final class OrderByEnum extends Enum
16+
{
17+
protected static function values(): array
18+
{
19+
return [
20+
'ID' => 'id',
21+
'ID_ASC' => 'id_asc',
22+
'ID_DESC' => 'id_desc',
23+
'INTERN_NAME' => 'intern_name',
24+
'INTERN_NAME_ASC' => 'intern_name_asc',
25+
'INTERN_NAME_DESC' => 'intern_name_desc',
26+
];
27+
}
28+
29+
protected static function labels(): array
30+
{
31+
return [
32+
'ID' => 'Id',
33+
'ID_ASC' => 'Id Ascending',
34+
'ID_DESC' => 'Id Descending',
35+
'INTERN_NAME' => 'Intern Name',
36+
'INTERN_NAME_ASC' => 'Intern Name Ascending',
37+
'INTERN_NAME_DESC' => 'Intern Name Descending',
38+
];
39+
}
40+
}

0 commit comments

Comments
 (0)