Skip to content

Commit

Permalink
Update classes and methods, rename classes, and add new features
Browse files Browse the repository at this point in the history
Added the setCompanyVatCode method to multiple classes along with edits to existing functions for better return typing and renaming of classes for clarity. The ability to send an email upon invoice creation has also been added to ProformaInvoice. The README documentation was updated accordingly to reflect these changes.
  • Loading branch information
ag84ark committed Jan 29, 2024
1 parent 5020d15 commit b2ae26f
Show file tree
Hide file tree
Showing 9 changed files with 130 additions and 26 deletions.
7 changes: 6 additions & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -19,8 +19,13 @@ You can publish the config file with:
php artisan vendor:publish --provider="Ag84ark\SmartBill\SmartBillServiceProvider" --tag="laravel-smartbill-config"
```

## Documentation

In the making

## Usage

### Invoice
### Using resources

```php
Expand Down Expand Up @@ -140,7 +145,7 @@ try {
### Testing

``` bash
In the making
Partially tested
```

### Changelog
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2,17 +2,17 @@

namespace Ag84ark\SmartBill\ApiResponse;

class CreateInvoiceResponse extends BaseApiResponse
class CreateInvoiceApiResponse extends BaseApiResponse
{
private string $number = '';

private string $series = '';

private string $url = '';

public static function fromArray(array $data): CreateInvoiceResponse
public static function fromArray(array $data): CreateInvoiceApiResponse
{
$invoiceResponse = new CreateInvoiceResponse();
$invoiceResponse = new CreateInvoiceApiResponse();
$invoiceResponse->errorText = $data['errorText'];
$invoiceResponse->message = $data['message'];
$invoiceResponse->number = $data['number'];
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2,17 +2,17 @@

namespace Ag84ark\SmartBill\ApiResponse;

class CreateProformaInvoiceResponse extends BaseApiResponse
class CreateProformaInvoiceApiResponse extends BaseApiResponse
{
private string $number = '';

private string $series = '';

private string $url = '';

public static function fromArray(array $data): CreateProformaInvoiceResponse
public static function fromArray(array $data): CreateProformaInvoiceApiResponse
{
$proformaInvoiceResponse = new CreateProformaInvoiceResponse();
$proformaInvoiceResponse = new CreateProformaInvoiceApiResponse();
$proformaInvoiceResponse->errorText = $data['errorText'];
$proformaInvoiceResponse->message = $data['message'];
$proformaInvoiceResponse->number = $data['number'];
Expand Down
39 changes: 39 additions & 0 deletions src/ApiResponse/InvoicePaymentStatusApiResponse.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,39 @@
<?php

namespace Ag84ark\SmartBill\ApiResponse;

class InvoicePaymentStatusApiResponse extends BaseApiResponse
{
private string $number = '';
private string $series = '';
private float $invoiceTotalAmount = 0;
private float $paidAmount = 0;
private float $unpaidAmount = 0;

public static function fromArray(array $data): InvoicePaymentStatusApiResponse
{
$invoicePaymentStatusResponse = new InvoicePaymentStatusApiResponse();
$invoicePaymentStatusResponse->errorText = $data['errorText'];
$invoicePaymentStatusResponse->message = $data['message'];
$invoicePaymentStatusResponse->number = $data['number'];
$invoicePaymentStatusResponse->series = $data['series'];
$invoicePaymentStatusResponse->invoiceTotalAmount = $data['invoiceTotalAmount'];
$invoicePaymentStatusResponse->paidAmount = $data['paidAmount'];
$invoicePaymentStatusResponse->unpaidAmount = $data['unpaidAmount'];

$invoicePaymentStatusResponse->responseData = $data;

return $invoicePaymentStatusResponse;
}

public function toArray(): array
{
return array_merge(parent::toArray(), [
'number' => $this->number,
'series' => $this->series,
'invoiceTotalAmount' => $this->invoiceTotalAmount,
'paidAmount' => $this->paidAmount,
'unpaidAmount' => $this->unpaidAmount,
]);
}
}
25 changes: 15 additions & 10 deletions src/Endpoints/InvoiceEndpoint.php
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,8 @@
namespace Ag84ark\SmartBill\Endpoints;

use Ag84ark\SmartBill\ApiResponse\BaseApiResponse;
use Ag84ark\SmartBill\ApiResponse\CreateInvoiceResponse;
use Ag84ark\SmartBill\ApiResponse\CreateInvoiceApiResponse;
use Ag84ark\SmartBill\ApiResponse\InvoicePaymentStatusApiResponse;
use Ag84ark\SmartBill\Resources\Invoice;
use Ag84ark\SmartBill\Resources\ReverseInvoices;
use Ag84ark\SmartBill\SmartBillCloudRestClient;
Expand All @@ -28,7 +29,7 @@ public function getPDFInvoice($number)
return $this->rest_read($url, 'Accept: application/octet-stream');
}

public function createInvoice(Invoice $invoice): CreateInvoiceResponse
public function createInvoice(Invoice $invoice): CreateInvoiceApiResponse
{
return $this->createInvoiceFromArray($invoice->toArray());
}
Expand Down Expand Up @@ -62,19 +63,19 @@ public function restoreInvoice($number): BaseApiResponse
return BaseApiResponse::fromArray($response);
}

public function getStatusInvoicePayments($number): BaseApiResponse
public function getInvoicePaymentStatus($number): InvoicePaymentStatusApiResponse
{
$url = sprintf(self::STATUS_INVOICE_URL.self::PARAMS_STATUS, $this->companyVatCode, $this->getEncodedSeriesName(), $number);
$response = $this->rest_read($url);

return BaseApiResponse::fromArray($response);
return InvoicePaymentStatusApiResponse::fromArray($response);
}

public function createInvoiceFromArray(array $data): CreateInvoiceResponse
public function createInvoiceFromArray(array $data): CreateInvoiceApiResponse
{
$response = $this->rest_create(self::INVOICE_URL, $data);

return CreateInvoiceResponse::fromArray($response);
return CreateInvoiceApiResponse::fromArray($response);
}

public function createReverseInvoiceFromArray(array $data): BaseApiResponse
Expand All @@ -84,14 +85,18 @@ public function createReverseInvoiceFromArray(array $data): BaseApiResponse
return BaseApiResponse::fromArray($response);
}

public function setSeriesName(string $seriesName): void
public function setCompanyVatCode(string $companyVatCode): InvoiceEndpoint
{
$this->seriesName = $seriesName;
$this->companyVatCode = $companyVatCode;

return $this;
}

public function setCompanyVatCode(string $companyVatCode): void
public function setSeriesName(string $seriesName): InvoiceEndpoint
{
$this->companyVatCode = $companyVatCode;
$this->seriesName = $seriesName;

return $this;
}

private function getEncodedSeriesName(): string
Expand Down
20 changes: 12 additions & 8 deletions src/Endpoints/ProformaEndpoint.php
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@
namespace Ag84ark\SmartBill\Endpoints;

use Ag84ark\SmartBill\ApiResponse\BaseApiResponse;
use Ag84ark\SmartBill\ApiResponse\CreateProformaInvoiceResponse;
use Ag84ark\SmartBill\ApiResponse\CreateProformaInvoiceApiResponse;
use Ag84ark\SmartBill\Resources\ProformaInvoice;
use Ag84ark\SmartBill\SmartBillCloudRestClient;

Expand All @@ -27,7 +27,7 @@ public function getPDFProforma($number)
return $this->rest_read($url, 'Accept: application/octet-stream');
}

public function createProforma(ProformaInvoice $invoice): CreateProformaInvoiceResponse
public function createProforma(ProformaInvoice $invoice): CreateProformaInvoiceApiResponse
{
return $this->createProformaFromArray($invoice->toArray());
}
Expand Down Expand Up @@ -64,19 +64,23 @@ public function getStatusProforma($number): BaseApiResponse
return BaseApiResponse::fromArray($response);
}

public function createProformaFromArray(array $data): CreateProformaInvoiceResponse
public function createProformaFromArray(array $data): CreateProformaInvoiceApiResponse
{
return CreateProformaInvoiceResponse::fromArray($this->rest_create(self::PROFORMA_URL, $data));
return CreateProformaInvoiceApiResponse::fromArray($this->rest_create(self::PROFORMA_URL, $data));
}

public function setSeriesName(string $seriesName): void
public function setCompanyVatCode(string $companyVatCode): ProformaEndpoint
{
$this->seriesName = $seriesName;
$this->companyVatCode = $companyVatCode;

return $this;
}

public function setCompanyVatCode(string $companyVatCode): void
public function setSeriesName(string $seriesName): ProformaEndpoint
{
$this->companyVatCode = $companyVatCode;
$this->seriesName = $seriesName;

return $this;
}

private function getEncodedSeriesName(): string
Expand Down
12 changes: 12 additions & 0 deletions src/Endpoints/SeriesEndpoint.php
Original file line number Diff line number Diff line change
Expand Up @@ -23,4 +23,16 @@ public function getSeries(string $documentType = ''): BaseApiResponse

return BaseApiResponse::fromArray($response);
}

public function getCompanyVatCode(): string
{
return $this->companyVatCode;
}

public function setCompanyVatCode(string $companyVatCode): SeriesEndpoint
{
$this->companyVatCode = $companyVatCode;

return $this;
}
}
9 changes: 8 additions & 1 deletion src/Endpoints/TaxesEndpoint.php
Original file line number Diff line number Diff line change
Expand Up @@ -15,11 +15,18 @@ public function __construct(SmartBillCloudRestClient $restClient)
parent::__construct($restClient);
}

public function getTaxes()
public function getTaxes(): BaseApiResponse
{
$url = sprintf(self::TAXES_URL, $this->companyVatCode);
$response = $this->rest_read($url);

return BaseApiResponse::fromArray($response);
}

public function setCompanyVatCode(string $companyVatCode): TaxesEndpoint
{
$this->companyVatCode = $companyVatCode;

return $this;
}
}
32 changes: 32 additions & 0 deletions src/Resources/ProformaInvoice.php
Original file line number Diff line number Diff line change
Expand Up @@ -47,6 +47,12 @@ class ProformaInvoice
/** se completeaza doar pentru afisarea linkului de plata pe pdf */
private ?string $paymentUrl = null;

/** Trimiterea facturii clientului la emitere utilizand $email data de mai jos */
private bool $sendEmail = false;

/** adresele de email la care se trimite factura */
private ?InvoiceSendEmailDetails $email = null;

/**
* @var InvoiceProduct[]|Collection
*/
Expand Down Expand Up @@ -101,6 +107,8 @@ public function toArray(): array
'delegateIdentityCard' => $this->delegateIdentityCard,
'delegateAuto' => $this->delegateAuto,
'paymentUrl' => $this->paymentUrl,
'sendEmail' => $this->sendEmail,
'email' => $this->email ? $this->email->toArray() : null,
'products' => $this->products->map(function (InvoiceProduct $product) {
return $product->toArray();
})->toArray(),
Expand Down Expand Up @@ -358,4 +366,28 @@ public function setProducts(Collection $products): ProformaInvoice

return $this;
}

public function isSendEmail(): bool
{
return $this->sendEmail;
}

public function setSendEmail(bool $sendEmail): ProformaInvoice
{
$this->sendEmail = $sendEmail;

return $this;
}

public function getEmail(): ?InvoiceSendEmailDetails
{
return $this->email;
}

public function setEmail(?InvoiceSendEmailDetails $email): ProformaInvoice
{
$this->email = $email;

return $this;
}
}

0 comments on commit b2ae26f

Please sign in to comment.