Skip to content

Commit

Permalink
Formatting
Browse files Browse the repository at this point in the history
  • Loading branch information
stephangroen committed Aug 12, 2015
1 parent 09243e2 commit e88c530
Show file tree
Hide file tree
Showing 11 changed files with 65 additions and 43 deletions.
17 changes: 9 additions & 8 deletions src/Picqer/Financials/Exact/Account.php
Original file line number Diff line number Diff line change
@@ -1,18 +1,19 @@
<?php namespace Picqer\Financials\Exact;

class Account extends Model {
class Account extends Model
{

use Query\Findable;
use Persistance\Storable;

protected $fillable = [
'ID',
'Accountant',
'AccountManager',
'AccountManagerFullName',
'AccountManagerHID',
'ActivitySector',
'ActivitySubSector',
'ID',
'Accountant',
'AccountManager',
'AccountManagerFullName',
'AccountManagerHID',
'ActivitySector',
'ActivitySubSector',
'AddressLine1',
'AddressLine2',
'AddressLine3',
Expand Down
3 changes: 2 additions & 1 deletion src/Picqer/Financials/Exact/ApiException.php
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
<?php namespace Picqer\Financials\Exact;

class ApiException extends \Exception {
class ApiException extends \Exception
{

}
3 changes: 2 additions & 1 deletion src/Picqer/Financials/Exact/Division.php
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
<?php namespace Picqer\Financials\Exact;

class Division extends Model {
class Division extends Model
{

use Query\Findable;

Expand Down
3 changes: 2 additions & 1 deletion src/Picqer/Financials/Exact/GLAccount.php
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
<?php namespace Picqer\Financials\Exact;

class GLAccount extends Model {
class GLAccount extends Model
{

use Query\Findable;
use Persistance\Storable;
Expand Down
3 changes: 2 additions & 1 deletion src/Picqer/Financials/Exact/Journal.php
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
<?php namespace Picqer\Financials\Exact;

class Journal extends Model {
class Journal extends Model
{

use Query\Findable;
use Persistance\Storable;
Expand Down
4 changes: 3 additions & 1 deletion src/Picqer/Financials/Exact/Me.php
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
<?php namespace Picqer\Financials\Exact;

class Me extends Model {
class Me extends Model
{

protected $fillable = [
'CurrentDivision',
Expand All @@ -22,6 +23,7 @@ class Me extends Model {
'Mobile'
];


public function find()
{
$result = $this->connection()->get('current/Me');
Expand Down
42 changes: 26 additions & 16 deletions src/Picqer/Financials/Exact/Model.php
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
<?php namespace Picqer\Financials\Exact;

abstract class Model {
abstract class Model
{

/**
* @var Connection
Expand All @@ -10,12 +11,12 @@ abstract class Model {
/**
* @var array The model's attributes
*/
protected $attributes = [];
protected $attributes = [ ];

/**
* @var array The model's fillable attributes
*/
protected $fillable = [];
protected $fillable = [ ];

/**
* @var string The URL endpoint of this model
Expand All @@ -27,12 +28,14 @@ abstract class Model {
*/
protected $primaryKey = 'ID';

public function __construct(Connection $connection, array $attributes = [])

public function __construct(Connection $connection, array $attributes = [ ])
{
$this->connection = $connection;
$this->fill($attributes);
}


/**
* Get the connection instance
*
Expand All @@ -43,6 +46,7 @@ public function connection()
return $this->connection;
}


/**
* Get the model's attributes
*
Expand All @@ -53,71 +57,77 @@ public function attributes()
return $this->attributes;
}


/**
* Fill the entity from an array
*
* @param array $attributes
*/
protected function fill(array $attributes)
{
foreach ($this->fillableFromArray($attributes) as $key => $value)
{
if ($this->isFillable($key))
{
foreach ($this->fillableFromArray($attributes) as $key => $value) {
if ($this->isFillable($key)) {
$this->setAttribute($key, $value);
}
}
}


/**
* Get the fillable attributes of an array
*
* @param array $attributes
*
* @return array
*/
protected function fillableFromArray(array $attributes)
{
if (count($this->fillable) > 0)
{
if (count($this->fillable) > 0) {
return array_intersect_key($attributes, array_flip($this->fillable));
}

return $attributes;
}


protected function isFillable($key)
{
return in_array($key, $this->fillable);
}


protected function setAttribute($key, $value)
{
$this->attributes[$key] = $value;
}


public function __get($key)
{
if (isset($this->attributes[$key]))
{
if (isset( $this->attributes[$key] )) {
return $this->attributes[$key];
}
}


public function __set($key, $value)
{
if ($this->isFillable($key))
{
if ($this->isFillable($key)) {
return $this->setAttribute($key, $value);
}
}


public function exists()
{
if (! in_array($this->primaryKey, $this->attributes)) return false;
if ( ! in_array($this->primaryKey, $this->attributes)) {
return false;
}

return ! empty($this->attributes[$this->primaryKey]);
return ! empty( $this->attributes[$this->primaryKey] );
}


public function json()
{
return json_encode($this->attributes);
Expand Down
3 changes: 2 additions & 1 deletion src/Picqer/Financials/Exact/PaymentCondition.php
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
<?php namespace Picqer\Financials\Exact;

class PaymentCondition extends Model {
class PaymentCondition extends Model
{

use Query\Findable;
use Persistance\Storable;
Expand Down
22 changes: 12 additions & 10 deletions src/Picqer/Financials/Exact/SalesEntry.php
Original file line number Diff line number Diff line change
@@ -1,12 +1,14 @@
<?php namespace Picqer\Financials\Exact;

class SalesEntry extends Model {
class SalesEntry extends Model
{

use Query\Findable;
use Persistance\Storable;

protected $primaryKey = 'EntryID';
protected $saleEntryLines = array();

protected $saleEntryLines = [ ];

protected $fillable = [
'Division',
Expand All @@ -26,20 +28,20 @@ class SalesEntry extends Model {
'Status',
'PaymentCondition'
];



public function addItem(array $array)
{
if (!isset($this->attributes['SalesEntryLines']) || $this->attributes['SalesEntryLines'] == null)
{
$this->attributes['SalesEntryLines'] = array();
if ( ! isset( $this->attributes['SalesEntryLines'] ) || $this->attributes['SalesEntryLines'] == null) {
$this->attributes['SalesEntryLines'] = [ ];
}
if (!isset($array['LineNumber']))
{
$array['LineNumber'] = count($this->attributes['SalesEntryLines'])+1;
if ( ! isset( $array['LineNumber'] )) {
$array['LineNumber'] = count($this->attributes['SalesEntryLines']) + 1;
}
$this->attributes['SalesEntryLines'][] = $array;
}


protected $url = 'salesentry/SalesEntries';

}
5 changes: 3 additions & 2 deletions src/Picqer/Financials/Exact/SalesEntryLine.php
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
<?php namespace Picqer\Financials\Exact;

class SalesEntryLine extends Model {
class SalesEntryLine extends Model
{

use Query\Findable;
use Persistance\Storable;
Expand All @@ -19,7 +20,7 @@ class SalesEntryLine extends Model {
'VATCode',
'VATPercentage',
'Notes',

];

protected $url = 'salesinvoice/SalesInvoiceLines';
Expand Down
3 changes: 2 additions & 1 deletion src/Picqer/Financials/Exact/VatCode.php
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
<?php namespace Picqer\Financials\Exact;

class VatCode extends Model {
class VatCode extends Model
{

use Query\Findable;

Expand Down

0 comments on commit e88c530

Please sign in to comment.