Skip to content

Commit

Permalink
Merge pull request #2 from davidoskay/main
Browse files Browse the repository at this point in the history
ADD gtu_code support AND update documentation for GTU_CODE and buyer not company
  • Loading branch information
MattMoszczynski committed Apr 10, 2022
2 parents e6e7a02 + 533db8e commit 1a552ab
Show file tree
Hide file tree
Showing 2 changed files with 49 additions and 1 deletion.
42 changes: 42 additions & 0 deletions DOCUMENTATION.md
Original file line number Diff line number Diff line change
Expand Up @@ -56,6 +56,18 @@ $product = new FakturowniaPosition("Product ABC", 1, 10.00);
$invoice->addPosition($product);
```

If we want to specify that buyer is not company - instead of `$invoice->buyer['name']` use `$invoice->buyer['first_name']` and `$invoice->buyer['last_name']`:
```php
$invoice = new FakturowniaInvoice();

$invoice->isBuyerCompany = false;
$invoice->buyer['first_name'] = "First name";
$invoice->buyer['last_name'] = "Last name";

$product = new FakturowniaPosition("Product ABC", 1, 10.00);
$invoice->addPosition($product);
```

<br/>

### <a id="1-2"></a>Using the constructor
Expand Down Expand Up @@ -125,6 +137,17 @@ $price = 10.00;

$product = new FakturowniaPosition($name, $quantity, $price);
```
or with all optional parameters:
```php
$name = "Product ABC";
$quantity = 1;
$price = 10.00;
$isNetto = false;
$tax = 23;
$gtu_code = 'GTU_02';

$product = new FakturowniaPosition($name, $quantity, $price, $isNetto, $tax, $gtu_code)
````

<br/>

Expand Down Expand Up @@ -186,6 +209,25 @@ $product->tax = 18;

<br/>


### <a id="2-4"></a>Setting GTU Code

In order to set up or change gtu code you can do that by using one of `FakturowniaPosition` constructor optional parameters with default parameters:

```php
// By default netto and tax set at 23%
$product = new FakturowniaPosition("Product B", 1, 10.00, false, 23, 'GTU_02');
```

You can also do that by using the `$gtu_code` variable:

```php
$product = new FakturowniaPosition("Product A", 1, 12.00, true);
$product->gtu_code = "GTU_02";
```

<br/>

### <a id="2-5"></a>Adding position to an invoice

To add position object to the invoice object you can use command `addPosition()` on your invoice object:
Expand Down
8 changes: 7 additions & 1 deletion src/FakturowniaPosition.php
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@ class FakturowniaPosition extends FakturowniaDataObject
private ?int $id = null;
public string $name = "";
public string $code = "";
public string $gtu_code = "";
public string $description = "";

public int $quantity = 0;
Expand All @@ -18,13 +19,14 @@ class FakturowniaPosition extends FakturowniaDataObject
public float $price = 0.0;
public bool $isNetto = false;

function __construct($name, $quantity, $price, $isNetto = false, $tax = 23)
function __construct($name, $quantity, $price, $isNetto = false, $tax = 23, $gtu_code = '')
{
$this->name = $name;
$this->quantity = $quantity;
$this->price = $price;
$this->isNetto = $isNetto;
$this->tax = $tax;
$this->gtu_code = $gtu_code;
}

public function getID()
Expand All @@ -50,6 +52,9 @@ public static function createFromJson($json)
if (isset($json['code']) && !empty($json['code'])) {
$position->code = $json['code'];
}
if (isset($json['gtu_code']) && !empty($json['gtu_code'])) {
$position->gtu_code = $json['gtu_code'];
}

$position->description = $json['description'];
$position->quantityUnit = $json['quantity_unit'];
Expand All @@ -64,6 +69,7 @@ public function toArray($includeEmptyFields = true)
$data = array(
'name' => $this->name,
'code' => $this->code,
'gtu_code' => $this->gtu_code,
'quantity' => $this->quantity,
'quantity_unit' => $this->quantityUnit,
'tax' => $this->tax
Expand Down

0 comments on commit 1a552ab

Please sign in to comment.