mirror of
https://github.com/OpenXE-org/OpenXE.git
synced 2024-12-26 06:30:29 +01:00
96 lines
2.2 KiB
PHP
96 lines
2.2 KiB
PHP
<?php
|
|
|
|
declare(strict_types=1);
|
|
|
|
namespace Xentral\Modules\FiskalyApi\Data\CashPointClosing;
|
|
|
|
use ArrayIterator;
|
|
use Countable;
|
|
use IteratorAggregate;
|
|
|
|
class CashAmountByCurrencyCollection implements IteratorAggregate, Countable
|
|
{
|
|
/** @var CashAmountByCurrency[] $cashAmountsByCurrecy */
|
|
private $cashAmountsByCurrecy = [];
|
|
|
|
/**
|
|
* CashAmountByCurrencyCollection constructor.
|
|
*
|
|
* @param array $cashAmountsByCurrecy
|
|
*/
|
|
public function __construct(array $cashAmountsByCurrecy = [])
|
|
{
|
|
foreach ($cashAmountsByCurrecy as $cashAmountByCurrecy) {
|
|
$this->addAmountPerCurrecy($cashAmountByCurrecy);
|
|
}
|
|
}
|
|
|
|
/**
|
|
* @param $apiResult
|
|
*
|
|
* @return static
|
|
*/
|
|
public static function fromApiResult($apiResult): self
|
|
{
|
|
$instance = new self();
|
|
foreach ($apiResult as $item) {
|
|
$instance->addAmountPerCurrecy(CashAmountByCurrency::fromApiResult($item));
|
|
}
|
|
|
|
return $instance;
|
|
}
|
|
|
|
/**
|
|
* @param array $dbState
|
|
*
|
|
* @return static
|
|
*/
|
|
public static function fromDbState(array $dbState): self
|
|
{
|
|
$instance = new self();
|
|
foreach ($dbState as $item) {
|
|
$instance->addAmountPerCurrecy(CashAmountByCurrency::fromDbState($item));
|
|
}
|
|
|
|
return $instance;
|
|
}
|
|
|
|
/**
|
|
* @return array
|
|
*/
|
|
public function toArray(): array
|
|
{
|
|
$dbState = [];
|
|
/** @var CashAmountByCurrency $amountPerCurrency */
|
|
foreach ($this as $amountPerCurrency) {
|
|
$dbState[] = $amountPerCurrency->toArray();
|
|
}
|
|
|
|
return $dbState;
|
|
}
|
|
|
|
/**
|
|
* @param CashAmountByCurrency $amountPerCurrency
|
|
*/
|
|
public function addAmountPerCurrecy(CashAmountByCurrency $amountPerCurrency): void
|
|
{
|
|
$this->cashAmountsByCurrecy[] = CashAmountByCurrency::fromDbState($amountPerCurrency->toArray());
|
|
}
|
|
|
|
/**
|
|
* @return int
|
|
*/
|
|
public function count(): int
|
|
{
|
|
return count($this->cashAmountsByCurrecy);
|
|
}
|
|
|
|
/**
|
|
* @return ArrayIterator
|
|
*/
|
|
public function getIterator(): ArrayIterator
|
|
{
|
|
return new ArrayIterator($this->cashAmountsByCurrecy);
|
|
}
|
|
}
|