Skip to content

Commit 6156c77

Browse files
authored
Merge pull request #21 from codebar-ag/feature-new-requests
Feature new requests
2 parents 12979f6 + 8e13ba5 commit 6156c77

32 files changed

+1009
-76
lines changed

Diff for: .phpunit.cache/test-results

+1-1
Large diffs are not rendered by default.

Diff for: README.md

+219-30
Original file line numberDiff line numberDiff line change
@@ -82,6 +82,7 @@ We provide enums for the following values:
8282
| Enum | Values |
8383
|----------------------------------------|-----------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------|
8484
| Accounts: SearchFieldEnum | ACCOUNT_NO(), self FIBU_ACCOUNT_GROUP_ID(), NAME(), ACCOUNT_TYPE() |
85+
| Accounts: AccountTypeEnum | EARNINGS(), EXPENDITURES(), ACTIVE_ACCOUNTS(), PASSIVE_ACCOUNTS(), COMPLETE_ACCOUNTS() |
8586
| AdditionalAddresses: AddSearchTypeEnum | ID(), ID_ASC(), ID_DESC(), NAME(), NAME_ASC(), NAME_DESC() |
8687
| CalendarYears: VatAccountingMethodEnum | EFFECTIVE(), NET_TAX() |
8788
| CalendarYears: VatAccountingTypeEnum | AGREED(), COLLECTED() |
@@ -108,42 +109,58 @@ We provide enums for the following values:
108109

109110
We provide DTOs for the following:
110111

111-
| DTO |
112-
|-----------------------------|
113-
| AccountGroupDTO |
114-
| AccountDTO |
115-
| BankAccountDTO |
116-
| AdditionalAddressDTO |
117-
| BankAccountDTO |
118-
| BusinessYearDTO |
119-
| CalendarYearDTO |
120-
| CompanyProfileDTO |
121-
| ContactAdditionalAddressDTO |
122-
| ContactGroupDTO |
123-
| ContactRelationDTO |
124-
| ContactDTO |
125-
| ContactSectorDTO |
126-
| CurrencyDTO |
127-
| ExchangeCurrencyDTO |
128-
| FileDTO |
129-
| FileUsageDTO |
130-
| EntryDTO |
131-
| ManualEntryDTO |
132-
| FileDTO |
133-
| NoteDTO |
134-
| PaymentDTO |
135-
| JournalDTO |
136-
| SalutationDTO |
137-
| TaxDTO |
138-
| TitleDTO |
139-
| VatPeriodDTO |
112+
| DTO |
113+
|---------------------------------------|
114+
| AccountGroupDTO |
115+
| AccountDTO |
116+
| BankAccountDTO |
117+
| AdditionalAddressDTO |
118+
| BankAccountDTO |
119+
| BusinessActivityDTO |
120+
| BusinessYearDTO |
121+
| CalendarYearDTO |
122+
| CompanyProfileDTO |
123+
| ContactAdditionalAddressDTO |
124+
| ContactGroupDTO |
125+
| ContactRelationDTO |
126+
| ContactDTO |
127+
| CreateEditContactDTO |
128+
| ContactSectorDTO |
129+
| CurrencyDTO |
130+
| CreateCurrencyDTO |
131+
| EditCurrencyDTO |
132+
| ExchangeCurrencyDTO |
133+
| DocumentSettingDTO |
134+
| FileDTO |
135+
| EditFileDTO |
136+
| FileUsageDTO |
137+
| InvoiceDTO |
138+
| InvoicePositionDTO |
139+
| InvoiceTaxDTO |
140+
| PdfDTO |
141+
| LanguageDTO |
142+
| AddFileDTO |
143+
| EntryDTO |
144+
| FileDTO |
145+
| ManualEntryDTO |
146+
| NoteDTO |
147+
| PaymentDTO |
148+
| PaymentTypeDTO |
149+
| ProjectDTO |
150+
| JournalDTO |
151+
| SalutationDTO |
152+
| TaxDTO |
153+
| TitleDTO |
154+
| UnitDTO |
155+
| UserDTO |
156+
| VatPeriodDTO |
140157

141158
In addition to the above, we also provide DTOs to be used for create and edit request for the following:
142159

143160
| DTO |
144161
|---------------------------------------|
145-
| CreateEditAdditionalAddressDTO |
146162
| CreateCalendarYearDTO |
163+
| CreateEditAdditionalAddressDTO |
147164
| CreateEditContactAdditionalAddressDTO |
148165
| CreateEditContactGroupDTO |
149166
| CreateEditContactRelationDTO |
@@ -876,6 +893,178 @@ $payment = $connector->send(new EditIbanPaymentRequest(
876893
))->dto();
877894
```
878895

896+
### Invoices
897+
```php
898+
/**
899+
* Fetch A List Of Invoices
900+
*/
901+
$invoices = $connector->send(new FetchAListOfInvoicesRequest())->dto();
902+
```
903+
904+
```php
905+
/**
906+
* Fetch An Invoice
907+
*/
908+
$invoice = $connector->send(new FetchAnInvoiceRequest(
909+
invoice_id: 1
910+
))->dto();
911+
```
912+
913+
```php
914+
/**
915+
* Create An Invoice
916+
*/
917+
$contacts = $connector->send(new FetchAListOfContactsRequest);
918+
$user = $connector->send(new FetchAuthenticatedUserRequest);
919+
$languages = $connector->send(new FetchAListOfLanguagesRequest);
920+
$banks = $connector->send(new FetchAListOfBankAccountsRequest);
921+
$currencies = $connector->send(new FetchAListOfCurrenciesRequest);
922+
$paymentTypes = $connector->send(new FetchAListOfPaymentTypesRequest);
923+
$units = $connector->send(new FetchAListOfUnitsRequest);
924+
$accounts = $connector->send(new FetchAListOfAccountsRequest);
925+
$taxes = $connector->send(new FetchAListOfTaxesRequest(scope: 'active', types: 'sales_tax'));
926+
927+
$newInvoice = InvoiceDTO::fromArray([
928+
'title' => 'Test',
929+
'contact_id' => $contacts->dto()->first()->id,
930+
'user_id' => $user->dto()->id,
931+
'pr_project_id' => null,
932+
'language_id' => $languages->dto()->first()->id,
933+
'bank_account_id' => $banks->dto()->first()->id,
934+
'currency_id' => $currencies->dto()->first()->id,
935+
'payment_type_id' => $paymentTypes->dto()->first()->id,
936+
'mwst_type' => 1,
937+
'mwst_is_net' => true,
938+
'show_position_taxes' => true,
939+
'is_valid_from' => now()->format('Y-m-d h:m:s'),
940+
'is_valid_to' => now()->addDays(5)->format('Y-m-d h:m:s'),
941+
'api_reference' => Str::uuid(),
942+
'positions' => [
943+
InvoicePositionDTO::fromArray([
944+
'type' => 'KbPositionText',
945+
'show_pos_nr' => true,
946+
'text' => Str::uuid(),
947+
]),
948+
InvoicePositionDTO::fromArray([
949+
'type' => 'KbPositionCustom',
950+
'amount' => 1,
951+
'unit_id' => $units->dto()->first()->id,
952+
'account_id' => $accounts->dto()->filter(fn ($account) => $account->account_type_enum === AccountTypeEnum::ACTIVE_ACCOUNTS())->first()->id,
953+
'tax_id' => $taxes->dto()->first()->id,
954+
'text' => Str::uuid(),
955+
'unit_price' => 100,
956+
'discount_in_percent' => '0',
957+
]),
958+
],
959+
]);
960+
961+
$invoice = $connector->send(new CreateAnInvoiceRequest(invoice: $newInvoice))->dto();
962+
```
963+
964+
```php
965+
/**
966+
* Edit An Invoice
967+
*/
968+
$editInvoice = $connector->send(new FetchAnInvoiceRequest(invoice_id: 1))->dto();
969+
970+
$editInvoice->title = 'Test Invoice';
971+
972+
$invoice = $connector->send(new EditAnInvoiceRequest(invoice_id: 1, invoice: $editInvoice));
973+
```
974+
975+
```php
976+
/**
977+
* Delete An Invoice
978+
*/
979+
$response = $connector->send(new DeleteAnInvoiceRequest(
980+
invoice_id: 1
981+
));
982+
```
983+
984+
```php
985+
/**
986+
* Cancel An Invoice
987+
*/
988+
$response = $connector->send(new CancelAnInvoiceRequest(
989+
invoice_id: 1
990+
));
991+
```
992+
993+
```php
994+
/**
995+
* Create A Default Position For An Invoice
996+
*/
997+
$units = $connector->send(new FetchAListOfUnitsRequest);
998+
$accounts = $connector->send(new FetchAListOfAccountsRequest);
999+
$taxes = $connector->send(new FetchAListOfTaxesRequest(scope: 'active', types: 'sales_tax'));
1000+
1001+
$position = InvoicePositionDTO::fromArray([
1002+
'type' => 'KbPositionCustom',
1003+
'amount' => 1,
1004+
'unit_id' => $units->dto()->first()->id,
1005+
'account_id' => $accounts->dto()->filter(fn ($account) => $account->account_type === 1)->first()->id,
1006+
'tax_id' => $taxes->dto()->first()->id,
1007+
'text' => Str::uuid(),
1008+
'unit_price' => 100,
1009+
'discount_in_percent' => '0',
1010+
]);
1011+
1012+
$response = $connector->send(new CreateADefaultPositionRequest(
1013+
kb_document_type: 'kb_invoice',
1014+
invoice_id: 1,
1015+
position: $position,
1016+
));
1017+
```
1018+
1019+
```php
1020+
/**
1021+
* Create A Sub Position For An Invoice
1022+
*/
1023+
$position = InvoicePositionDTO::fromArray([
1024+
'type' => 'KbSubPosition',
1025+
'text' => Str::uuid(),
1026+
'show_pos_nr' => true,
1027+
]);
1028+
1029+
$response = $connector->send(new CreateASubPositionRequest(
1030+
kb_document_type: 'kb_invoice',
1031+
invoice_id: 1,
1032+
position: $position,
1033+
));
1034+
```
1035+
1036+
```php
1037+
/**
1038+
* Show PDF
1039+
*/
1040+
$pdf = $connector->send(new ShowPdfRequest(
1041+
invoice_id: 1
1042+
))->dto();
1043+
1044+
/**
1045+
* Saving PDF from response
1046+
*/
1047+
Storage::disk('local')->put('your/directory/'. $pdf->name, base64_decode($pdf->content));
1048+
1049+
/**
1050+
* Download PDF from response
1051+
*/
1052+
return response(base64_decode($pdf->content))
1053+
->header('Content-Type', $pdf->mime)
1054+
->header('Content-Disposition', 'attachment; filename="'.$pdf->name.'"')
1055+
->header('Content-Length', $pdf->size);
1056+
```
1057+
1058+
1059+
1060+
### Languages
1061+
```php
1062+
/**
1063+
* Fetch A List Of Languages
1064+
*/
1065+
$languages = $connector->send(new FetchAListOfLanguagesRequest())->dto();
1066+
```
1067+
8791068
### Manual Entries
8801069
```php
8811070
/**

Diff for: src/Dto/Accounts/AccountDTO.php

+3
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,7 @@
22

33
namespace CodebarAg\Bexio\Dto\Accounts;
44

5+
use CodebarAg\Bexio\Enums\Accounts\AccountTypeEnum;
56
use Exception;
67
use Illuminate\Support\Arr;
78
use Saloon\Http\Response;
@@ -14,6 +15,7 @@ public function __construct(
1415
public string $account_no,
1516
public string $name,
1617
public int $account_type,
18+
public AccountTypeEnum $account_type_enum,
1719
public bool $is_active,
1820
public bool $is_locked,
1921
public ?int $tax_id = null,
@@ -42,6 +44,7 @@ public static function fromArray(array $data): self
4244
account_no: Arr::get($data, 'account_no'),
4345
name: Arr::get($data, 'name'),
4446
account_type: Arr::get($data, 'account_type'),
47+
account_type_enum: AccountTypeEnum::from(Arr::get($data, 'account_type')),
4548
is_active: Arr::get($data, 'is_active'),
4649
is_locked: Arr::get($data, 'is_locked'),
4750
tax_id: Arr::get($data, 'tax_id'),

Diff for: src/Dto/Invoices/InvoiceDTO.php

+37-30
Original file line numberDiff line numberDiff line change
@@ -11,43 +11,43 @@
1111
class InvoiceDTO extends Data
1212
{
1313
public function __construct(
14-
public int $id,
15-
public string $document_nr,
14+
public ?int $id,
15+
public ?string $document_nr,
1616
public ?string $title,
1717
public ?int $contact_id,
1818
public ?int $contact_sub_id,
1919
public int $user_id,
20-
public ?int $project_id,
20+
public ?int $pr_project_id,
2121
public ?int $logopaper_id, // Deprecated
22-
public int $language_id,
23-
public int $bank_account_id,
24-
public int $currency_id,
25-
public int $payment_type_id,
26-
public string $header,
27-
public string $footer,
28-
public string $total_gross,
29-
public string $total_net,
30-
public string $total_taxes,
31-
public string $total_received_payments,
32-
public string $total_credit_vouchers,
33-
public string $total_remaining_payments,
34-
public string $total,
35-
public int|float $total_rounding_difference,
36-
public int $mwst_type,
37-
public bool $mwst_is_net,
38-
public bool $show_position_taxes,
39-
public string $is_valid_from,
40-
public string $is_valid_to,
41-
public string $contact_address,
42-
public int $kb_item_status_id,
22+
public ?int $language_id,
23+
public ?int $bank_account_id,
24+
public ?int $currency_id,
25+
public ?int $payment_type_id,
26+
public ?string $header,
27+
public ?string $footer,
28+
public ?string $total_gross,
29+
public ?string $total_net,
30+
public ?string $total_taxes,
31+
public ?string $total_received_payments,
32+
public ?string $total_credit_vouchers,
33+
public ?string $total_remaining_payments,
34+
public ?string $total,
35+
public null|int|float $total_rounding_difference,
36+
public ?int $mwst_type,
37+
public ?bool $mwst_is_net,
38+
public ?bool $show_position_taxes,
39+
public ?string $is_valid_from,
40+
public ?string $is_valid_to,
41+
public ?string $contact_address,
42+
public ?int $kb_item_status_id,
4343
public ?string $reference,
4444
public ?string $api_reference,
4545
public ?string $viewed_by_client_at,
46-
public string $updated_at,
47-
public int $esr_id,
48-
public int $qr_invoice_id,
46+
public ?string $updated_at,
47+
public ?int $esr_id,
48+
public ?int $qr_invoice_id,
4949
public ?string $template_slug,
50-
public Collection $taxs,
50+
public ?Collection $taxs,
5151
public ?string $network_link,
5252
public ?Collection $positions,
5353
) {}
@@ -76,7 +76,7 @@ public static function fromArray(array $data): self
7676
contact_id: Arr::get($data, 'contact_id'),
7777
contact_sub_id: Arr::get($data, 'contact_sub_id'),
7878
user_id: Arr::get($data, 'user_id'),
79-
project_id: Arr::get($data, 'project_id'),
79+
pr_project_id: Arr::get($data, 'pr_project_id'),
8080
logopaper_id: Arr::get($data, 'logopaper_id'),
8181
language_id: Arr::get($data, 'language_id'),
8282
bank_account_id: Arr::get($data, 'bank_account_id'),
@@ -108,7 +108,14 @@ public static function fromArray(array $data): self
108108
template_slug: Arr::get($data, 'template_slug'),
109109
taxs: collect(Arr::get($data, 'taxs', []))->map(fn (array $tax) => InvoiceTaxDTO::fromArray($tax)),
110110
network_link: Arr::get($data, 'network_link'),
111-
positions: collect(Arr::get($data, 'positions', []))->map(fn (array $tax) => InvoicePositionDTO::fromArray($tax)),
111+
positions: collect(Arr::get($data, 'positions', []))
112+
->map(function (InvoicePositionDTO|array $tax) {
113+
if ($tax instanceof InvoicePositionDTO) {
114+
return $tax;
115+
}
116+
117+
return InvoicePositionDTO::fromArray($tax);
118+
}),
112119
);
113120
}
114121
}

0 commit comments

Comments
 (0)