Skip to content

Commit

Permalink
Merge pull request #11 from marcovr1980/feat-getsaldi
Browse files Browse the repository at this point in the history
  • Loading branch information
petericebear authored Dec 30, 2021
2 parents 1038a66 + bcbfe80 commit 3cf771c
Show file tree
Hide file tree
Showing 4 changed files with 244 additions and 1 deletion.
3 changes: 3 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -43,6 +43,9 @@ $ledgers = $client->getLedgers();

// Get all Invoices
$invoices = $client->getInvoices();

// Get all Balances
$balances = $client->getBalances();
```

## Testing & building
Expand Down
46 changes: 45 additions & 1 deletion src/Client.php
Original file line number Diff line number Diff line change
Expand Up @@ -10,9 +10,11 @@
use IntVent\EBoekhouden\Filters\LedgerFilter;
use IntVent\EBoekhouden\Filters\MutationFilter;
use IntVent\EBoekhouden\Filters\RelationFilter;
use IntVent\EBoekhouden\Filters\SaldiFilter;
use IntVent\EBoekhouden\Filters\SaldoFilter;
use IntVent\EBoekhouden\Models\EboekhoudenAdministration;
use IntVent\EBoekhouden\Models\EboekhoudenArticle;
use IntVent\EBoekhouden\Models\EboekhoudenBalance;
use IntVent\EBoekhouden\Models\EboekhoudenCostPlacement;
use IntVent\EBoekhouden\Models\EboekhoudenInvoice;
use IntVent\EBoekhouden\Models\EboekhoudenInvoiceList;
Expand Down Expand Up @@ -360,6 +362,48 @@ public function getSaldo(SaldoFilter $filter = null): float
return $result->GetSaldoResult->Saldo;
}

/**
* @param SaldiFilter|null $filter
* @return float
* @throws EboekhoudenSoapException
*/
public function getSaldi(SaldiFilter $filter = null): array
{
if (is_null($filter)) {
$filter = new SaldiFilter();
}

$dateFrom = $filter->getDateFrom() ?? new DateTime('1970-01-01 00:00:00');
$dateTo = $filter->getDateTo() ?? new DateTime('2050-12-31 23:59:59');

$result = $this->soapClient->__soapCall('GetSaldi', [
'GetSaldi' => [
'SessionID' => $this->sessionId,
'SecurityCode2' => $this->secCode2,
'cFilter' => [
'KostenPlaatsId' => $filter->getCostPlacementId(),
'DatumVan' => $dateFrom->format('Y-m-d'),
'DatumTot' => $dateTo->format('Y-m-d'),
'Category' => $filter->getCategory(),
],
],
]);

$this->checkError('GetSaldi', $result);

if (! isset($result->GetSaldiResult->Saldi->cSaldo)) {
return [];
}

$balances = $result->GetSaldiResult->Saldi->cSaldo;

if (! is_array($balances)) {
$balances = [$balances];
}

return array_map(fn ($item) => (new EboekhoudenBalance((array)$item))->toArray(), $balances);
}

/**
* Get all invoices from E-Boekhouden.nl.
*
Expand Down Expand Up @@ -740,7 +784,7 @@ public function addMutation(EboekhoudenMutation $mutation): int

return (int)$result->AddMutatieResult->Mutatienummer;
}

/**
* Client destructor.
*
Expand Down
89 changes: 89 additions & 0 deletions src/Filters/SaldiFilter.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,89 @@
<?php

namespace IntVent\EBoekhouden\Filters;

use DateTime;

class SaldiFilter
{
protected int $cost_placement_id = 0;
protected ?DateTime $date_from = null;
protected ?DateTime $date_to = null;
protected string $category = '';

/**
* @return int
*/
public function getCostPlacementId(): int
{
return $this->cost_placement_id;
}

/**
* @param int $cost_placement_id
* @return SaldiFilter
*/
public function setCostPlacementId(int $cost_placement_id): SaldiFilter
{
$this->cost_placement_id = $cost_placement_id;

return $this;
}

/**
* @return DateTime|null
*/
public function getDateFrom(): ?DateTime
{
return $this->date_from;
}

/**
* @param DateTime|null $date_from
* @return SaldiFilter
*/
public function setDateFrom(?DateTime $date_from): SaldiFilter
{
$this->date_from = $date_from;

return $this;
}

/**
* @return DateTime|null
*/
public function getDateTo(): ?DateTime
{
return $this->date_to;
}

/**
* @param DateTime|null $date_to
* @return SaldiFilter
*/
public function setDateTo(?DateTime $date_to): SaldiFilter
{
$this->date_to = $date_to;

return $this;
}

/**
* @return string
*/
public function getCategory(): string
{
return $this->category;
}

/**
* @param string $category
* @return SaldiFilter
*/
public function setCategory(string $category): SaldiFilter
{
$this->category = $category;

return $this;
}
}
107 changes: 107 additions & 0 deletions src/Models/EboekhoudenBalance.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,107 @@
<?php

namespace IntVent\EBoekhouden\Models;

use IntVent\EBoekhouden\Contracts\Arrayable;
use IntVent\EBoekhouden\Traits\ProtectedFieldsToArrayTrait;

class EboekhoudenBalance implements Arrayable
{
use ProtectedFieldsToArrayTrait;

protected int $id = 0;
protected string $code = '';
protected string $category = '';
protected float $balance;

/**
* EboekhoudenBalance constructor.
* @param array|null $item
*/
public function __construct(array $item = null)
{
if (! empty($item)) {
$this
->setId($item['ID'])
->setCode($item['Code'])
->setCategory($item['Categorie'])
->setBalance($item['Saldo']);
}
}

/**
* @return int
*/
public function getId(): int
{
return $this->id;
}

/**
* @param int $id
* @return EboekhoudenBalance
*/
public function setId(int $id): EboekhoudenBalance
{
$this->id = $id;

return $this;
}

/**
* @return string
*/
public function getCode(): string
{
return $this->code;
}

/**
* @param string $code
* @return EboekhoudenBalance
*/
public function setCode(string $code): EboekhoudenBalance
{
$this->code = $code;

return $this;
}

/**
* @return string
*/
public function getCategory(): string
{
return $this->category;
}

/**
* @param string $category
* @return EboekhoudenBalance
*/
public function setCategory(string $category): EboekhoudenBalance
{
$this->category = $category;

return $this;
}

/**
* @return float
*/
public function getBalance(): float
{
return $this->balance;
}

/**
* @param string $balance
* @return EboekhoudenBalance
*/
public function setBalance(float $balance): EboekhoudenBalance
{
$this->balance = $balance;

return $this;
}
}

0 comments on commit 3cf771c

Please sign in to comment.