Skip to content

Commit

Permalink
Merge pull request #21 from codebar-ag/feature-new-requests
Browse files Browse the repository at this point in the history
Feature new requests
  • Loading branch information
StanBarrows authored Oct 28, 2024
2 parents 12979f6 + 8e13ba5 commit 6156c77
Show file tree
Hide file tree
Showing 32 changed files with 1,009 additions and 76 deletions.
2 changes: 1 addition & 1 deletion .phpunit.cache/test-results

Large diffs are not rendered by default.

249 changes: 219 additions & 30 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -82,6 +82,7 @@ We provide enums for the following values:
| Enum | Values |
|----------------------------------------|-----------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------|
| Accounts: SearchFieldEnum | ACCOUNT_NO(), self FIBU_ACCOUNT_GROUP_ID(), NAME(), ACCOUNT_TYPE() |
| Accounts: AccountTypeEnum | EARNINGS(), EXPENDITURES(), ACTIVE_ACCOUNTS(), PASSIVE_ACCOUNTS(), COMPLETE_ACCOUNTS() |
| AdditionalAddresses: AddSearchTypeEnum | ID(), ID_ASC(), ID_DESC(), NAME(), NAME_ASC(), NAME_DESC() |
| CalendarYears: VatAccountingMethodEnum | EFFECTIVE(), NET_TAX() |
| CalendarYears: VatAccountingTypeEnum | AGREED(), COLLECTED() |
Expand All @@ -108,42 +109,58 @@ We provide enums for the following values:

We provide DTOs for the following:

| DTO |
|-----------------------------|
| AccountGroupDTO |
| AccountDTO |
| BankAccountDTO |
| AdditionalAddressDTO |
| BankAccountDTO |
| BusinessYearDTO |
| CalendarYearDTO |
| CompanyProfileDTO |
| ContactAdditionalAddressDTO |
| ContactGroupDTO |
| ContactRelationDTO |
| ContactDTO |
| ContactSectorDTO |
| CurrencyDTO |
| ExchangeCurrencyDTO |
| FileDTO |
| FileUsageDTO |
| EntryDTO |
| ManualEntryDTO |
| FileDTO |
| NoteDTO |
| PaymentDTO |
| JournalDTO |
| SalutationDTO |
| TaxDTO |
| TitleDTO |
| VatPeriodDTO |
| DTO |
|---------------------------------------|
| AccountGroupDTO |
| AccountDTO |
| BankAccountDTO |
| AdditionalAddressDTO |
| BankAccountDTO |
| BusinessActivityDTO |
| BusinessYearDTO |
| CalendarYearDTO |
| CompanyProfileDTO |
| ContactAdditionalAddressDTO |
| ContactGroupDTO |
| ContactRelationDTO |
| ContactDTO |
| CreateEditContactDTO |
| ContactSectorDTO |
| CurrencyDTO |
| CreateCurrencyDTO |
| EditCurrencyDTO |
| ExchangeCurrencyDTO |
| DocumentSettingDTO |
| FileDTO |
| EditFileDTO |
| FileUsageDTO |
| InvoiceDTO |
| InvoicePositionDTO |
| InvoiceTaxDTO |
| PdfDTO |
| LanguageDTO |
| AddFileDTO |
| EntryDTO |
| FileDTO |
| ManualEntryDTO |
| NoteDTO |
| PaymentDTO |
| PaymentTypeDTO |
| ProjectDTO |
| JournalDTO |
| SalutationDTO |
| TaxDTO |
| TitleDTO |
| UnitDTO |
| UserDTO |
| VatPeriodDTO |

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

| DTO |
|---------------------------------------|
| CreateEditAdditionalAddressDTO |
| CreateCalendarYearDTO |
| CreateEditAdditionalAddressDTO |
| CreateEditContactAdditionalAddressDTO |
| CreateEditContactGroupDTO |
| CreateEditContactRelationDTO |
Expand Down Expand Up @@ -876,6 +893,178 @@ $payment = $connector->send(new EditIbanPaymentRequest(
))->dto();
```

### Invoices
```php
/**
* Fetch A List Of Invoices
*/
$invoices = $connector->send(new FetchAListOfInvoicesRequest())->dto();
```

```php
/**
* Fetch An Invoice
*/
$invoice = $connector->send(new FetchAnInvoiceRequest(
invoice_id: 1
))->dto();
```

```php
/**
* Create An Invoice
*/
$contacts = $connector->send(new FetchAListOfContactsRequest);
$user = $connector->send(new FetchAuthenticatedUserRequest);
$languages = $connector->send(new FetchAListOfLanguagesRequest);
$banks = $connector->send(new FetchAListOfBankAccountsRequest);
$currencies = $connector->send(new FetchAListOfCurrenciesRequest);
$paymentTypes = $connector->send(new FetchAListOfPaymentTypesRequest);
$units = $connector->send(new FetchAListOfUnitsRequest);
$accounts = $connector->send(new FetchAListOfAccountsRequest);
$taxes = $connector->send(new FetchAListOfTaxesRequest(scope: 'active', types: 'sales_tax'));

$newInvoice = InvoiceDTO::fromArray([
'title' => 'Test',
'contact_id' => $contacts->dto()->first()->id,
'user_id' => $user->dto()->id,
'pr_project_id' => null,
'language_id' => $languages->dto()->first()->id,
'bank_account_id' => $banks->dto()->first()->id,
'currency_id' => $currencies->dto()->first()->id,
'payment_type_id' => $paymentTypes->dto()->first()->id,
'mwst_type' => 1,
'mwst_is_net' => true,
'show_position_taxes' => true,
'is_valid_from' => now()->format('Y-m-d h:m:s'),
'is_valid_to' => now()->addDays(5)->format('Y-m-d h:m:s'),
'api_reference' => Str::uuid(),
'positions' => [
InvoicePositionDTO::fromArray([
'type' => 'KbPositionText',
'show_pos_nr' => true,
'text' => Str::uuid(),
]),
InvoicePositionDTO::fromArray([
'type' => 'KbPositionCustom',
'amount' => 1,
'unit_id' => $units->dto()->first()->id,
'account_id' => $accounts->dto()->filter(fn ($account) => $account->account_type_enum === AccountTypeEnum::ACTIVE_ACCOUNTS())->first()->id,
'tax_id' => $taxes->dto()->first()->id,
'text' => Str::uuid(),
'unit_price' => 100,
'discount_in_percent' => '0',
]),
],
]);

$invoice = $connector->send(new CreateAnInvoiceRequest(invoice: $newInvoice))->dto();
```

```php
/**
* Edit An Invoice
*/
$editInvoice = $connector->send(new FetchAnInvoiceRequest(invoice_id: 1))->dto();

$editInvoice->title = 'Test Invoice';

$invoice = $connector->send(new EditAnInvoiceRequest(invoice_id: 1, invoice: $editInvoice));
```

```php
/**
* Delete An Invoice
*/
$response = $connector->send(new DeleteAnInvoiceRequest(
invoice_id: 1
));
```

```php
/**
* Cancel An Invoice
*/
$response = $connector->send(new CancelAnInvoiceRequest(
invoice_id: 1
));
```

```php
/**
* Create A Default Position For An Invoice
*/
$units = $connector->send(new FetchAListOfUnitsRequest);
$accounts = $connector->send(new FetchAListOfAccountsRequest);
$taxes = $connector->send(new FetchAListOfTaxesRequest(scope: 'active', types: 'sales_tax'));

$position = InvoicePositionDTO::fromArray([
'type' => 'KbPositionCustom',
'amount' => 1,
'unit_id' => $units->dto()->first()->id,
'account_id' => $accounts->dto()->filter(fn ($account) => $account->account_type === 1)->first()->id,
'tax_id' => $taxes->dto()->first()->id,
'text' => Str::uuid(),
'unit_price' => 100,
'discount_in_percent' => '0',
]);

$response = $connector->send(new CreateADefaultPositionRequest(
kb_document_type: 'kb_invoice',
invoice_id: 1,
position: $position,
));
```

```php
/**
* Create A Sub Position For An Invoice
*/
$position = InvoicePositionDTO::fromArray([
'type' => 'KbSubPosition',
'text' => Str::uuid(),
'show_pos_nr' => true,
]);

$response = $connector->send(new CreateASubPositionRequest(
kb_document_type: 'kb_invoice',
invoice_id: 1,
position: $position,
));
```

```php
/**
* Show PDF
*/
$pdf = $connector->send(new ShowPdfRequest(
invoice_id: 1
))->dto();

/**
* Saving PDF from response
*/
Storage::disk('local')->put('your/directory/'. $pdf->name, base64_decode($pdf->content));

/**
* Download PDF from response
*/
return response(base64_decode($pdf->content))
->header('Content-Type', $pdf->mime)
->header('Content-Disposition', 'attachment; filename="'.$pdf->name.'"')
->header('Content-Length', $pdf->size);
```



### Languages
```php
/**
* Fetch A List Of Languages
*/
$languages = $connector->send(new FetchAListOfLanguagesRequest())->dto();
```

### Manual Entries
```php
/**
Expand Down
3 changes: 3 additions & 0 deletions src/Dto/Accounts/AccountDTO.php
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@

namespace CodebarAg\Bexio\Dto\Accounts;

use CodebarAg\Bexio\Enums\Accounts\AccountTypeEnum;
use Exception;
use Illuminate\Support\Arr;
use Saloon\Http\Response;
Expand All @@ -14,6 +15,7 @@ public function __construct(
public string $account_no,
public string $name,
public int $account_type,
public AccountTypeEnum $account_type_enum,
public bool $is_active,
public bool $is_locked,
public ?int $tax_id = null,
Expand Down Expand Up @@ -42,6 +44,7 @@ public static function fromArray(array $data): self
account_no: Arr::get($data, 'account_no'),
name: Arr::get($data, 'name'),
account_type: Arr::get($data, 'account_type'),
account_type_enum: AccountTypeEnum::from(Arr::get($data, 'account_type')),
is_active: Arr::get($data, 'is_active'),
is_locked: Arr::get($data, 'is_locked'),
tax_id: Arr::get($data, 'tax_id'),
Expand Down
67 changes: 37 additions & 30 deletions src/Dto/Invoices/InvoiceDTO.php
Original file line number Diff line number Diff line change
Expand Up @@ -11,43 +11,43 @@
class InvoiceDTO extends Data
{
public function __construct(
public int $id,
public string $document_nr,
public ?int $id,
public ?string $document_nr,
public ?string $title,
public ?int $contact_id,
public ?int $contact_sub_id,
public int $user_id,
public ?int $project_id,
public ?int $pr_project_id,
public ?int $logopaper_id, // Deprecated
public int $language_id,
public int $bank_account_id,
public int $currency_id,
public int $payment_type_id,
public string $header,
public string $footer,
public string $total_gross,
public string $total_net,
public string $total_taxes,
public string $total_received_payments,
public string $total_credit_vouchers,
public string $total_remaining_payments,
public string $total,
public int|float $total_rounding_difference,
public int $mwst_type,
public bool $mwst_is_net,
public bool $show_position_taxes,
public string $is_valid_from,
public string $is_valid_to,
public string $contact_address,
public int $kb_item_status_id,
public ?int $language_id,
public ?int $bank_account_id,
public ?int $currency_id,
public ?int $payment_type_id,
public ?string $header,
public ?string $footer,
public ?string $total_gross,
public ?string $total_net,
public ?string $total_taxes,
public ?string $total_received_payments,
public ?string $total_credit_vouchers,
public ?string $total_remaining_payments,
public ?string $total,
public null|int|float $total_rounding_difference,
public ?int $mwst_type,
public ?bool $mwst_is_net,
public ?bool $show_position_taxes,
public ?string $is_valid_from,
public ?string $is_valid_to,
public ?string $contact_address,
public ?int $kb_item_status_id,
public ?string $reference,
public ?string $api_reference,
public ?string $viewed_by_client_at,
public string $updated_at,
public int $esr_id,
public int $qr_invoice_id,
public ?string $updated_at,
public ?int $esr_id,
public ?int $qr_invoice_id,
public ?string $template_slug,
public Collection $taxs,
public ?Collection $taxs,
public ?string $network_link,
public ?Collection $positions,
) {}
Expand Down Expand Up @@ -76,7 +76,7 @@ public static function fromArray(array $data): self
contact_id: Arr::get($data, 'contact_id'),
contact_sub_id: Arr::get($data, 'contact_sub_id'),
user_id: Arr::get($data, 'user_id'),
project_id: Arr::get($data, 'project_id'),
pr_project_id: Arr::get($data, 'pr_project_id'),
logopaper_id: Arr::get($data, 'logopaper_id'),
language_id: Arr::get($data, 'language_id'),
bank_account_id: Arr::get($data, 'bank_account_id'),
Expand Down Expand Up @@ -108,7 +108,14 @@ public static function fromArray(array $data): self
template_slug: Arr::get($data, 'template_slug'),
taxs: collect(Arr::get($data, 'taxs', []))->map(fn (array $tax) => InvoiceTaxDTO::fromArray($tax)),
network_link: Arr::get($data, 'network_link'),
positions: collect(Arr::get($data, 'positions', []))->map(fn (array $tax) => InvoicePositionDTO::fromArray($tax)),
positions: collect(Arr::get($data, 'positions', []))
->map(function (InvoicePositionDTO|array $tax) {
if ($tax instanceof InvoicePositionDTO) {
return $tax;
}

return InvoicePositionDTO::fromArray($tax);
}),
);
}
}
Loading

0 comments on commit 6156c77

Please sign in to comment.