Skip to content

Commit

Permalink
Merge pull request #70 from jonasdekeukelaere/accounts
Browse files Browse the repository at this point in the history
Accounts
  • Loading branch information
carakas authored Oct 24, 2017
2 parents 6abe96a + 208d4d5 commit 3d0e17c
Show file tree
Hide file tree
Showing 2 changed files with 53 additions and 6 deletions.
31 changes: 25 additions & 6 deletions Invoices/InvoiceLine.php
Original file line number Diff line number Diff line change
@@ -1,9 +1,5 @@
<?php

/**
* @todo Bookkeeping accounts
*/

namespace SumoCoders\Teamleader\Invoices;

use SumoCoders\Teamleader\Exception;
Expand Down Expand Up @@ -51,6 +47,11 @@ class InvoiceLine
*/
private $productId;

/**
* @var int
*/
private $accountId;

/**
* @var string
*/
Expand Down Expand Up @@ -208,6 +209,22 @@ public function getProductId()
return $this->productId;
}

/**
* @param int $accountId
*/
public function setAccountId($accountId)
{
$this->accountId = $accountId;
}

/**
* @return int
*/
public function getAccountId()
{
return $this->accountId;
}

/**
* Initialize an Invoiceline with raw data we got from the API
*
Expand All @@ -229,7 +246,7 @@ public static function initializeWithRawData($data)
break;

case 'account':
// Todo
$invoiceLine->setAccountId($value);
break;

default:
Expand Down Expand Up @@ -272,7 +289,9 @@ public function toArrayForApi($index = 1)
if ($this->getProductId()) {
$return['product_id_' . $index] = $this->getProductId();
}
// $return['account_' . $index] = $this->getAccount()->getId();
if ($this->getAccountId()) {
$return['account_' . $index] = $this->getAccountId();
}

return $return;
}
Expand Down
28 changes: 28 additions & 0 deletions Products/Product.php
Original file line number Diff line number Diff line change
Expand Up @@ -39,6 +39,11 @@ class Product
*/
private $stockAmount;

/**
* @var int
*/
private $invoiceAccountId;

/**
* @return int
*/
Expand Down Expand Up @@ -135,6 +140,22 @@ public function getStockAmount()
return $this->stockAmount;
}

/**
* @param int $invoiceAccountId
*/
public function setInvoiceAccountId($invoiceAccountId)
{
$this->invoiceAccountId = $invoiceAccountId;
}

/**
* @return int
*/
public function getInvoiceAccountId()
{
return $this->invoiceAccountId;
}

/**
* Initialize an Product with raw data we got from the API
*
Expand All @@ -146,6 +167,10 @@ public static function initializeWithRawData($data)

foreach ($data as $key => $value) {
switch ($key) {
case 'inv_account_id':
$product->setInvoiceAccountId($value);
break;

default:
// Ignore empty values
if ($value == '') {
Expand Down Expand Up @@ -189,6 +214,9 @@ public function toArrayForApi()
if ($this->getVat()) {
$return['vat'] = $this->getVat();
}
if ($this->getInvoiceAccountId()) {
$return['inv_account_id'] = $this->getInvoiceAccountId();
}

return $return;
}
Expand Down

0 comments on commit 3d0e17c

Please sign in to comment.