mirror of
https://github.com/firefly-iii/firefly-iii.git
synced 2026-01-06 22:21:42 +00:00
New tests for object transformers.
This commit is contained in:
@@ -132,6 +132,8 @@ class AccountTransformer extends TransformerAbstract
|
||||
}
|
||||
|
||||
/**
|
||||
* Transform the account.
|
||||
*
|
||||
* @param Account $account
|
||||
*
|
||||
* @return array
|
||||
|
||||
@@ -32,6 +32,7 @@ use Illuminate\Support\Collection;
|
||||
use League\Fractal\Resource\Collection as FractalCollection;
|
||||
use League\Fractal\Resource\Item;
|
||||
use League\Fractal\TransformerAbstract;
|
||||
use Log;
|
||||
use Symfony\Component\HttpFoundation\ParameterBag;
|
||||
|
||||
/**
|
||||
@@ -212,13 +213,18 @@ class BillTransformer extends TransformerAbstract
|
||||
}
|
||||
|
||||
/**
|
||||
* Get the data the bill was paid and predict the next expected match.
|
||||
*
|
||||
* @param Bill $bill
|
||||
*
|
||||
* @return array
|
||||
*/
|
||||
protected function paidData(Bill $bill): array
|
||||
{
|
||||
Log::debug(sprintf('Now in paidData for bill #%d', $bill->id));
|
||||
if (is_null($this->parameters->get('start')) || is_null($this->parameters->get('end'))) {
|
||||
Log::debug('parameters are NULL, return empty array');
|
||||
|
||||
return [
|
||||
'paid_dates' => [],
|
||||
'next_expected_match' => null,
|
||||
@@ -228,7 +234,8 @@ class BillTransformer extends TransformerAbstract
|
||||
/** @var BillRepositoryInterface $repository */
|
||||
$repository = app(BillRepositoryInterface::class);
|
||||
$repository->setUser($bill->user);
|
||||
$set = $repository->getPaidDatesInRange($bill, $this->parameters->get('start'), $this->parameters->get('end'));
|
||||
$set = $repository->getPaidDatesInRange($bill, $this->parameters->get('start'), $this->parameters->get('end'));
|
||||
Log::debug(sprintf('Count %d entries in getPaidDatesInRange()', $set->count()));
|
||||
$simple = $set->map(
|
||||
function (Carbon $date) {
|
||||
return $date->format('Y-m-d');
|
||||
|
||||
@@ -24,7 +24,11 @@ declare(strict_types=1);
|
||||
namespace FireflyIII\Transformers;
|
||||
|
||||
|
||||
use FireflyIII\Helpers\Collector\JournalCollector;
|
||||
use FireflyIII\Models\Budget;
|
||||
use Illuminate\Support\Collection;
|
||||
use League\Fractal\Resource\Collection as FractalCollection;
|
||||
use League\Fractal\Resource\Item;
|
||||
use League\Fractal\TransformerAbstract;
|
||||
use Symfony\Component\HttpFoundation\ParameterBag;
|
||||
|
||||
@@ -50,7 +54,9 @@ class BudgetTransformer extends TransformerAbstract
|
||||
protected $parameters;
|
||||
|
||||
/**
|
||||
* BillTransformer constructor.
|
||||
* BudgetTransformer constructor.
|
||||
*
|
||||
* @codeCoverageIgnore
|
||||
*
|
||||
* @param ParameterBag $parameters
|
||||
*/
|
||||
@@ -60,6 +66,48 @@ class BudgetTransformer extends TransformerAbstract
|
||||
}
|
||||
|
||||
/**
|
||||
* Include any transactions.
|
||||
*
|
||||
* @param Budget $budget
|
||||
*
|
||||
* @codeCoverageIgnore
|
||||
* @return FractalCollection
|
||||
*/
|
||||
public function includeTransactions(Budget $budget): FractalCollection
|
||||
{
|
||||
$pageSize = intval(app('preferences')->getForUser($budget->user, 'listPageSize', 50)->data);
|
||||
|
||||
// journals always use collector and limited using URL parameters.
|
||||
$collector = new JournalCollector;
|
||||
$collector->setUser($budget->user);
|
||||
$collector->withOpposingAccount()->withCategoryInformation()->withBudgetInformation();
|
||||
$collector->setAllAssetAccounts();
|
||||
$collector->setBudgets(new Collection([$budget]));
|
||||
if (!is_null($this->parameters->get('start')) && !is_null($this->parameters->get('end'))) {
|
||||
$collector->setRange($this->parameters->get('start'), $this->parameters->get('end'));
|
||||
}
|
||||
$collector->setLimit($pageSize)->setPage($this->parameters->get('page'));
|
||||
$journals = $collector->getJournals();
|
||||
|
||||
return $this->collection($journals, new TransactionTransformer($this->parameters), 'transactions');
|
||||
}
|
||||
|
||||
/**
|
||||
* Include the user.
|
||||
*
|
||||
* @param Budget $budget
|
||||
*
|
||||
* @codeCoverageIgnore
|
||||
* @return Item
|
||||
*/
|
||||
public function includeUser(Budget $budget): Item
|
||||
{
|
||||
return $this->item($budget->user, new UserTransformer($this->parameters), 'users');
|
||||
}
|
||||
|
||||
/**
|
||||
* Transform a budget.
|
||||
*
|
||||
* @param Budget $budget
|
||||
*
|
||||
* @return array
|
||||
@@ -70,6 +118,7 @@ class BudgetTransformer extends TransformerAbstract
|
||||
'id' => (int)$budget->id,
|
||||
'updated_at' => $budget->updated_at->toAtomString(),
|
||||
'created_at' => $budget->created_at->toAtomString(),
|
||||
'active' => intval($budget->active) === 1,
|
||||
'name' => $budget->name,
|
||||
'links' => [
|
||||
[
|
||||
|
||||
@@ -24,7 +24,11 @@ declare(strict_types=1);
|
||||
namespace FireflyIII\Transformers;
|
||||
|
||||
|
||||
use FireflyIII\Helpers\Collector\JournalCollector;
|
||||
use FireflyIII\Models\Category;
|
||||
use Illuminate\Support\Collection;
|
||||
use League\Fractal\Resource\Collection as FractalCollection;
|
||||
use League\Fractal\Resource\Item;
|
||||
use League\Fractal\TransformerAbstract;
|
||||
use Symfony\Component\HttpFoundation\ParameterBag;
|
||||
|
||||
@@ -38,7 +42,7 @@ class CategoryTransformer extends TransformerAbstract
|
||||
*
|
||||
* @var array
|
||||
*/
|
||||
protected $availableIncludes = ['user','transactions'];
|
||||
protected $availableIncludes = ['user', 'transactions'];
|
||||
/**
|
||||
* List of resources to automatically include
|
||||
*
|
||||
@@ -50,7 +54,9 @@ class CategoryTransformer extends TransformerAbstract
|
||||
protected $parameters;
|
||||
|
||||
/**
|
||||
* BillTransformer constructor.
|
||||
* CategoryTransformer constructor.
|
||||
*
|
||||
* @codeCoverageIgnore
|
||||
*
|
||||
* @param ParameterBag $parameters
|
||||
*/
|
||||
@@ -60,6 +66,48 @@ class CategoryTransformer extends TransformerAbstract
|
||||
}
|
||||
|
||||
/**
|
||||
* Include any transactions.
|
||||
*
|
||||
* @param Category $category
|
||||
*
|
||||
* @codeCoverageIgnore
|
||||
* @return FractalCollection
|
||||
*/
|
||||
public function includeTransactions(Category $category): FractalCollection
|
||||
{
|
||||
$pageSize = intval(app('preferences')->getForUser($category->user, 'listPageSize', 50)->data);
|
||||
|
||||
// journals always use collector and limited using URL parameters.
|
||||
$collector = new JournalCollector;
|
||||
$collector->setUser($category->user);
|
||||
$collector->withOpposingAccount()->withCategoryInformation()->withCategoryInformation();
|
||||
$collector->setAllAssetAccounts();
|
||||
$collector->setCategories(new Collection([$category]));
|
||||
if (!is_null($this->parameters->get('start')) && !is_null($this->parameters->get('end'))) {
|
||||
$collector->setRange($this->parameters->get('start'), $this->parameters->get('end'));
|
||||
}
|
||||
$collector->setLimit($pageSize)->setPage($this->parameters->get('page'));
|
||||
$journals = $collector->getJournals();
|
||||
|
||||
return $this->collection($journals, new TransactionTransformer($this->parameters), 'transactions');
|
||||
}
|
||||
|
||||
/**
|
||||
* Include the user.
|
||||
*
|
||||
* @param Category $category
|
||||
*
|
||||
* @codeCoverageIgnore
|
||||
* @return Item
|
||||
*/
|
||||
public function includeUser(Category $category): Item
|
||||
{
|
||||
return $this->item($category->user, new UserTransformer($this->parameters), 'users');
|
||||
}
|
||||
|
||||
/**
|
||||
* Convert category.
|
||||
*
|
||||
* @param Category $category
|
||||
*
|
||||
* @return array
|
||||
|
||||
@@ -24,7 +24,10 @@ declare(strict_types=1);
|
||||
namespace FireflyIII\Transformers;
|
||||
|
||||
|
||||
use FireflyIII\Helpers\Collector\JournalCollector;
|
||||
use FireflyIII\Models\TransactionJournalMeta;
|
||||
use Illuminate\Support\Collection;
|
||||
use League\Fractal\Resource\Collection as FractalCollection;
|
||||
use League\Fractal\TransformerAbstract;
|
||||
use Symfony\Component\HttpFoundation\ParameterBag;
|
||||
|
||||
@@ -38,7 +41,7 @@ class JournalMetaTransformer extends TransformerAbstract
|
||||
*
|
||||
* @var array
|
||||
*/
|
||||
protected $availableIncludes = ['journal'];
|
||||
protected $availableIncludes = ['transactions'];
|
||||
/**
|
||||
* List of resources to automatically include
|
||||
*
|
||||
@@ -50,7 +53,9 @@ class JournalMetaTransformer extends TransformerAbstract
|
||||
protected $parameters;
|
||||
|
||||
/**
|
||||
* BillTransformer constructor.
|
||||
* JournalMetaTransformer constructor.
|
||||
*
|
||||
* @codeCoverageIgnore
|
||||
*
|
||||
* @param ParameterBag $parameters
|
||||
*/
|
||||
@@ -60,6 +65,36 @@ class JournalMetaTransformer extends TransformerAbstract
|
||||
}
|
||||
|
||||
/**
|
||||
* Include any transactions.
|
||||
*
|
||||
* @param TransactionJournalMeta $meta
|
||||
*
|
||||
* @codeCoverageIgnore
|
||||
* @return FractalCollection
|
||||
*/
|
||||
public function includeTransactions(TransactionJournalMeta $meta): FractalCollection
|
||||
{
|
||||
$journal = $meta->transactionJournal;
|
||||
$pageSize = intval(app('preferences')->getForUser($journal->user, 'listPageSize', 50)->data);
|
||||
|
||||
// journals always use collector and limited using URL parameters.
|
||||
$collector = new JournalCollector;
|
||||
$collector->setUser($journal->user);
|
||||
$collector->withOpposingAccount()->withCategoryInformation()->withCategoryInformation();
|
||||
$collector->setAllAssetAccounts();
|
||||
$collector->setJournals(new Collection([$journal]));
|
||||
if (!is_null($this->parameters->get('start')) && !is_null($this->parameters->get('end'))) {
|
||||
$collector->setRange($this->parameters->get('start'), $this->parameters->get('end'));
|
||||
}
|
||||
$collector->setLimit($pageSize)->setPage($this->parameters->get('page'));
|
||||
$journals = $collector->getJournals();
|
||||
|
||||
return $this->collection($journals, new TransactionTransformer($this->parameters), 'transactions');
|
||||
}
|
||||
|
||||
/**
|
||||
* Convert meta object.
|
||||
*
|
||||
* @param TransactionJournalMeta $meta
|
||||
*
|
||||
* @return array
|
||||
|
||||
@@ -24,8 +24,11 @@ declare(strict_types=1);
|
||||
namespace FireflyIII\Transformers;
|
||||
|
||||
|
||||
use FireflyIII\Helpers\Collector\JournalCollector;
|
||||
use FireflyIII\Models\PiggyBankEvent;
|
||||
use FireflyIII\Models\TransactionCurrency;
|
||||
use FireflyIII\Repositories\Currency\CurrencyRepositoryInterface;
|
||||
use Illuminate\Support\Collection;
|
||||
use League\Fractal\Resource\Item;
|
||||
use League\Fractal\TransformerAbstract;
|
||||
use Symfony\Component\HttpFoundation\ParameterBag;
|
||||
|
||||
@@ -39,7 +42,7 @@ class PiggyBankEventTransformer extends TransformerAbstract
|
||||
*
|
||||
* @var array
|
||||
*/
|
||||
protected $availableIncludes = ['piggy_bank', 'transactions'];
|
||||
protected $availableIncludes = ['piggy_bank', 'transaction'];
|
||||
/**
|
||||
* List of resources to automatically include
|
||||
*
|
||||
@@ -51,7 +54,9 @@ class PiggyBankEventTransformer extends TransformerAbstract
|
||||
protected $parameters;
|
||||
|
||||
/**
|
||||
* BillTransformer constructor.
|
||||
* PiggyBankEventTransformer constructor.
|
||||
*
|
||||
* @codeCoverageIgnore
|
||||
*
|
||||
* @param ParameterBag $parameters
|
||||
*/
|
||||
@@ -61,6 +66,51 @@ class PiggyBankEventTransformer extends TransformerAbstract
|
||||
}
|
||||
|
||||
/**
|
||||
* Include piggy bank into end result.
|
||||
*
|
||||
* @codeCoverageIgnore
|
||||
*
|
||||
* @param PiggyBankEvent $event
|
||||
*
|
||||
* @return Item
|
||||
*/
|
||||
public function includePiggyBank(PiggyBankEvent $event): Item
|
||||
{
|
||||
return $this->item($event->piggyBank, new PiggyBankTransformer($this->parameters), 'piggy_banks');
|
||||
}
|
||||
|
||||
/**
|
||||
* Include transaction into end result.
|
||||
*
|
||||
* @codeCoverageIgnore
|
||||
*
|
||||
* @param PiggyBankEvent $event
|
||||
*
|
||||
* @return Item
|
||||
*/
|
||||
public function includeTransaction(PiggyBankEvent $event): Item
|
||||
{
|
||||
$journal = $event->transactionJournal;
|
||||
$pageSize = intval(app('preferences')->getForUser($journal->user, 'listPageSize', 50)->data);
|
||||
|
||||
// journals always use collector and limited using URL parameters.
|
||||
$collector = new JournalCollector;
|
||||
$collector->setUser($journal->user);
|
||||
$collector->withOpposingAccount()->withCategoryInformation()->withCategoryInformation();
|
||||
$collector->setAllAssetAccounts();
|
||||
$collector->setJournals(new Collection([$journal]));
|
||||
if (!is_null($this->parameters->get('start')) && !is_null($this->parameters->get('end'))) {
|
||||
$collector->setRange($this->parameters->get('start'), $this->parameters->get('end'));
|
||||
}
|
||||
$collector->setLimit($pageSize)->setPage($this->parameters->get('page'));
|
||||
$journals = $collector->getJournals();
|
||||
|
||||
return $this->item($journals->first(), new TransactionTransformer($this->parameters), 'transactions');
|
||||
}
|
||||
|
||||
/**
|
||||
* Convert piggy bank event.
|
||||
*
|
||||
* @param PiggyBankEvent $event
|
||||
*
|
||||
* @return array
|
||||
@@ -71,7 +121,10 @@ class PiggyBankEventTransformer extends TransformerAbstract
|
||||
$currencyId = intval($account->getMeta('currency_id'));
|
||||
$decimalPlaces = 2;
|
||||
if ($currencyId > 0) {
|
||||
$currency = TransactionCurrency::find($currencyId);
|
||||
/** @var CurrencyRepositoryInterface $repository */
|
||||
$repository = app(CurrencyRepositoryInterface::class);
|
||||
$repository->setUser($account->user);
|
||||
$currency = $repository->findNull($currencyId);
|
||||
$decimalPlaces = $currency->decimal_places;
|
||||
}
|
||||
|
||||
|
||||
@@ -26,6 +26,10 @@ namespace FireflyIII\Transformers;
|
||||
|
||||
use FireflyIII\Models\Note;
|
||||
use FireflyIII\Models\PiggyBank;
|
||||
use FireflyIII\Repositories\Currency\CurrencyRepositoryInterface;
|
||||
use FireflyIII\Repositories\PiggyBank\PiggyBankRepositoryInterface;
|
||||
use League\Fractal\Resource\Collection as FractalCollection;
|
||||
use League\Fractal\Resource\Item;
|
||||
use League\Fractal\TransformerAbstract;
|
||||
use Symfony\Component\HttpFoundation\ParameterBag;
|
||||
|
||||
@@ -51,7 +55,9 @@ class PiggyBankTransformer extends TransformerAbstract
|
||||
protected $parameters;
|
||||
|
||||
/**
|
||||
* BillTransformer constructor.
|
||||
* PiggyBankTransformer constructor.
|
||||
*
|
||||
* @codeCoverageIgnore
|
||||
*
|
||||
* @param ParameterBag $parameters
|
||||
*/
|
||||
@@ -61,20 +67,88 @@ class PiggyBankTransformer extends TransformerAbstract
|
||||
}
|
||||
|
||||
/**
|
||||
* Include account.
|
||||
*
|
||||
* @codeCoverageIgnore
|
||||
*
|
||||
* @param PiggyBank $piggyBank
|
||||
*
|
||||
* @return Item
|
||||
*/
|
||||
public function includeAccount(PiggyBank $piggyBank): Item
|
||||
{
|
||||
return $this->item($piggyBank->account, new AccountTransformer($this->parameters), 'accounts');
|
||||
}
|
||||
|
||||
/**
|
||||
* Include events.
|
||||
*
|
||||
* @codeCoverageIgnore
|
||||
*
|
||||
* @param PiggyBank $piggyBank
|
||||
*
|
||||
* @return FractalCollection
|
||||
*/
|
||||
public function includePiggyBankEvents(PiggyBank $piggyBank): FractalCollection
|
||||
{
|
||||
return $this->collection($piggyBank->piggyBankEvents, new PiggyBankEventTransformer($this->parameters), 'piggy_bank_events');
|
||||
}
|
||||
|
||||
/**
|
||||
* Include the user.
|
||||
*
|
||||
* @param PiggyBank $piggyBank
|
||||
*
|
||||
* @codeCoverageIgnore
|
||||
* @return Item
|
||||
*/
|
||||
public function includeUser(PiggyBank $piggyBank): Item
|
||||
{
|
||||
return $this->item($piggyBank->account->user, new UserTransformer($this->parameters), 'users');
|
||||
}
|
||||
|
||||
/**
|
||||
* Transform the piggy bank.
|
||||
*
|
||||
* @param PiggyBank $piggyBank
|
||||
*
|
||||
* @return array
|
||||
*/
|
||||
public function transform(PiggyBank $piggyBank): array
|
||||
{
|
||||
$account = $piggyBank->account;
|
||||
$currencyId = intval($account->getMeta('currency_id'));
|
||||
$decimalPlaces = 2;
|
||||
if ($currencyId > 0) {
|
||||
/** @var CurrencyRepositoryInterface $repository */
|
||||
$repository = app(CurrencyRepositoryInterface::class);
|
||||
$repository->setUser($account->user);
|
||||
$currency = $repository->findNull($currencyId);
|
||||
$decimalPlaces = $currency->decimal_places;
|
||||
}
|
||||
|
||||
$data = [
|
||||
'id' => (int)$piggyBank->id,
|
||||
'updated_at' => $piggyBank->updated_at->toAtomString(),
|
||||
'created_at' => $piggyBank->created_at->toAtomString(),
|
||||
'name' => $piggyBank->name,
|
||||
'notes' => null,
|
||||
'links' => [
|
||||
// get currently saved amount:
|
||||
/** @var PiggyBankRepositoryInterface $piggyRepos */
|
||||
$piggyRepos = app(PiggyBankRepositoryInterface::class);
|
||||
$piggyRepos->setUser($account->user);
|
||||
$currentAmount = round($piggyRepos->getCurrentAmount($piggyBank), $decimalPlaces);
|
||||
|
||||
$startDate = is_null($piggyBank->startdate) ? null : $piggyBank->startdate->format('Y-m-d');
|
||||
$targetDate = is_null($piggyBank->targetdate) ? null : $piggyBank->targetdate->format('Y-m-d');
|
||||
$targetAmount = round($piggyBank->targetamount, $decimalPlaces);
|
||||
$data = [
|
||||
'id' => (int)$piggyBank->id,
|
||||
'updated_at' => $piggyBank->updated_at->toAtomString(),
|
||||
'created_at' => $piggyBank->created_at->toAtomString(),
|
||||
'name' => $piggyBank->name,
|
||||
'target_amount' => $targetAmount,
|
||||
'current_amount' => $currentAmount,
|
||||
'startdate' => $startDate,
|
||||
'targetdate' => $targetDate,
|
||||
'order' => (int)$piggyBank->order,
|
||||
'active' => intval($piggyBank->active) === 1,
|
||||
'notes' => null,
|
||||
'links' => [
|
||||
[
|
||||
'rel' => 'self',
|
||||
'uri' => '/piggy_banks/' . $piggyBank->id,
|
||||
|
||||
@@ -24,7 +24,10 @@ declare(strict_types=1);
|
||||
namespace FireflyIII\Transformers;
|
||||
|
||||
|
||||
use FireflyIII\Helpers\Collector\JournalCollector;
|
||||
use FireflyIII\Models\Tag;
|
||||
use League\Fractal\Resource\Collection as FractalCollection;
|
||||
use League\Fractal\Resource\Item;
|
||||
use League\Fractal\TransformerAbstract;
|
||||
use Symfony\Component\HttpFoundation\ParameterBag;
|
||||
|
||||
@@ -38,7 +41,7 @@ class TagTransformer extends TransformerAbstract
|
||||
*
|
||||
* @var array
|
||||
*/
|
||||
protected $availableIncludes = ['user'];
|
||||
protected $availableIncludes = ['user', 'transactions'];
|
||||
/**
|
||||
* List of resources to automatically include
|
||||
*
|
||||
@@ -50,7 +53,9 @@ class TagTransformer extends TransformerAbstract
|
||||
protected $parameters;
|
||||
|
||||
/**
|
||||
* BillTransformer constructor.
|
||||
* TagTransformer constructor.
|
||||
*
|
||||
* @codeCoverageIgnore
|
||||
*
|
||||
* @param ParameterBag $parameters
|
||||
*/
|
||||
@@ -60,18 +65,67 @@ class TagTransformer extends TransformerAbstract
|
||||
}
|
||||
|
||||
/**
|
||||
* Include any transactions.
|
||||
*
|
||||
* @param Tag $tag
|
||||
*
|
||||
* @codeCoverageIgnore
|
||||
* @return FractalCollection
|
||||
*/
|
||||
public function includeTransactions(Tag $tag): FractalCollection
|
||||
{
|
||||
$pageSize = intval(app('preferences')->getForUser($tag->user, 'listPageSize', 50)->data);
|
||||
|
||||
// journals always use collector and limited using URL parameters.
|
||||
$collector = new JournalCollector;
|
||||
$collector->setUser($tag->user);
|
||||
$collector->withOpposingAccount()->withCategoryInformation()->withCategoryInformation();
|
||||
$collector->setAllAssetAccounts();
|
||||
$collector->setTag($tag);
|
||||
if (!is_null($this->parameters->get('start')) && !is_null($this->parameters->get('end'))) {
|
||||
$collector->setRange($this->parameters->get('start'), $this->parameters->get('end'));
|
||||
}
|
||||
$collector->setLimit($pageSize)->setPage($this->parameters->get('page'));
|
||||
$journals = $collector->getJournals();
|
||||
|
||||
return $this->collection($journals, new TransactionTransformer($this->parameters), 'transactions');
|
||||
}
|
||||
|
||||
/**
|
||||
* Include the user.
|
||||
*
|
||||
* @param Tag $tag
|
||||
*
|
||||
* @codeCoverageIgnore
|
||||
* @return Item
|
||||
*/
|
||||
public function includeUser(Tag $tag): Item
|
||||
{
|
||||
return $this->item($tag->user, new UserTransformer($this->parameters), 'users');
|
||||
}
|
||||
|
||||
/**
|
||||
* Transform a tag.
|
||||
*
|
||||
* @param Tag $tag
|
||||
*
|
||||
* @return array
|
||||
*/
|
||||
public function transform(Tag $tag): array
|
||||
{
|
||||
$date = is_null($tag->date) ? null : $tag->date->format('Y-m-d');
|
||||
$data = [
|
||||
'id' => (int)$tag->id,
|
||||
'updated_at' => $tag->updated_at->toAtomString(),
|
||||
'created_at' => $tag->created_at->toAtomString(),
|
||||
'tag' => $tag->tag,
|
||||
'links' => [
|
||||
'id' => (int)$tag->id,
|
||||
'updated_at' => $tag->updated_at->toAtomString(),
|
||||
'created_at' => $tag->created_at->toAtomString(),
|
||||
'tag' => $tag->tag,
|
||||
'tag_mode' => $tag->tagMode,
|
||||
'date' => $date,
|
||||
'description' => $tag->description === '' ? null : $tag->description,
|
||||
'latitude' => (float)$tag->latitude,
|
||||
'longitude' => (float)$tag->longitude,
|
||||
'zoom_level' => (int)$tag->zoomLevel,
|
||||
'links' => [
|
||||
[
|
||||
'rel' => 'self',
|
||||
'uri' => '/tags/' . $tag->id,
|
||||
|
||||
@@ -54,7 +54,9 @@ class TransactionTransformer extends TransformerAbstract
|
||||
protected $parameters;
|
||||
|
||||
/**
|
||||
* BillTransformer constructor.
|
||||
* TransactionTransformer constructor.
|
||||
*
|
||||
* @codeCoverageIgnore
|
||||
*
|
||||
* @param ParameterBag $parameters
|
||||
*/
|
||||
@@ -64,6 +66,10 @@ class TransactionTransformer extends TransformerAbstract
|
||||
}
|
||||
|
||||
/**
|
||||
* Include attachments.
|
||||
*
|
||||
* @codeCoverageIgnore
|
||||
*
|
||||
* @param Transaction $transaction
|
||||
*
|
||||
* @return FractalCollection
|
||||
@@ -74,6 +80,10 @@ class TransactionTransformer extends TransformerAbstract
|
||||
}
|
||||
|
||||
/**
|
||||
* Include meta data
|
||||
*
|
||||
* @codeCoverageIgnore
|
||||
*
|
||||
* @param Transaction $transaction
|
||||
*
|
||||
* @return FractalCollection
|
||||
@@ -86,6 +96,10 @@ class TransactionTransformer extends TransformerAbstract
|
||||
}
|
||||
|
||||
/**
|
||||
* Include piggy bank events
|
||||
*
|
||||
* @codeCoverageIgnore
|
||||
*
|
||||
* @param Transaction $transaction
|
||||
*
|
||||
* @return FractalCollection
|
||||
@@ -98,6 +112,10 @@ class TransactionTransformer extends TransformerAbstract
|
||||
}
|
||||
|
||||
/**
|
||||
* Include tags
|
||||
*
|
||||
* @codeCoverageIgnore
|
||||
*
|
||||
* @param Transaction $transaction
|
||||
*
|
||||
* @return FractalCollection
|
||||
@@ -110,6 +128,10 @@ class TransactionTransformer extends TransformerAbstract
|
||||
}
|
||||
|
||||
/**
|
||||
* Include the user.
|
||||
*
|
||||
* @codeCoverageIgnore
|
||||
*
|
||||
* @param Transaction $transaction
|
||||
*
|
||||
* @return \League\Fractal\Resource\Item
|
||||
@@ -121,6 +143,8 @@ class TransactionTransformer extends TransformerAbstract
|
||||
|
||||
|
||||
/**
|
||||
* Transform the journal.
|
||||
*
|
||||
* @param Transaction $transaction
|
||||
*
|
||||
* @return array
|
||||
@@ -128,6 +152,21 @@ class TransactionTransformer extends TransformerAbstract
|
||||
*/
|
||||
public function transform(Transaction $transaction): array
|
||||
{
|
||||
$categoryId = null;
|
||||
$categoryName = null;
|
||||
$budgetId = null;
|
||||
$budgetName = null;
|
||||
$categoryId = is_null($transaction->transaction_category_id) ? $transaction->transaction_journal_category_id
|
||||
: $transaction->transaction_category_id;
|
||||
$categoryName = is_null($transaction->transaction_category_name) ? $transaction->transaction_journal_category_name
|
||||
: $transaction->transaction_category_name;
|
||||
|
||||
if ($transaction->transaction_type_type === TransactionType::WITHDRAWAL) {
|
||||
$budgetId = is_null($transaction->transaction_budget_id) ? $transaction->transaction_journal_budget_id
|
||||
: $transaction->transaction_budget_id;
|
||||
$budgetName = is_null($transaction->transaction_budget_name) ? $transaction->transaction_journal_budget_name
|
||||
: $transaction->transaction_budget_name;
|
||||
}
|
||||
$data = [
|
||||
'id' => (int)$transaction->id,
|
||||
'updated_at' => $transaction->updated_at->toAtomString(),
|
||||
@@ -138,7 +177,7 @@ class TransactionTransformer extends TransformerAbstract
|
||||
'identifier' => $transaction->identifier,
|
||||
'journal_id' => (int)$transaction->journal_id,
|
||||
'reconciled' => (bool)$transaction->reconciled,
|
||||
'amount' => round($transaction->transaction_amount, $transaction->transaction_currency_dp),
|
||||
'amount' => round($transaction->transaction_amount, intval($transaction->transaction_currency_dp)),
|
||||
'currency_id' => $transaction->transaction_currency_id,
|
||||
'currency_code' => $transaction->transaction_currency_code,
|
||||
'currency_dp' => $transaction->transaction_currency_dp,
|
||||
@@ -148,14 +187,10 @@ class TransactionTransformer extends TransformerAbstract
|
||||
'foreign_currency_dp' => $transaction->foreign_currency_dp,
|
||||
'bill_id' => $transaction->bill_id,
|
||||
'bill_name' => $transaction->bill_name,
|
||||
'category_id' => is_null($transaction->transaction_category_id) ? $transaction->transaction_journal_category_id
|
||||
: $transaction->transaction_category_id,
|
||||
'category_name' => is_null($transaction->transaction_category_name) ? $transaction->transaction_journal_category_name
|
||||
: $transaction->transaction_category_name,
|
||||
'budget_id' => is_null($transaction->transaction_budget_id) ? $transaction->transaction_journal_budget_id
|
||||
: $transaction->transaction_budget_id,
|
||||
'budget_name' => is_null($transaction->transaction_budget_name) ? $transaction->transaction_journal_budget_name
|
||||
: $transaction->transaction_budget_name,
|
||||
'category_id' => $categoryId,
|
||||
'category_name' => $categoryName,
|
||||
'budget_id' => $budgetId,
|
||||
'budget_name' => $budgetName,
|
||||
'links' => [
|
||||
[
|
||||
'rel' => 'self',
|
||||
@@ -166,12 +201,12 @@ class TransactionTransformer extends TransformerAbstract
|
||||
|
||||
// expand foreign amount:
|
||||
if (!is_null($transaction->transaction_foreign_amount)) {
|
||||
$data['foreign_amount'] = round($transaction->transaction_foreign_amount, $transaction->foreign_currency_dp);
|
||||
$data['foreign_amount'] = round($transaction->transaction_foreign_amount, intval($transaction->foreign_currency_dp));
|
||||
}
|
||||
|
||||
// switch on type for consistency
|
||||
switch (true) {
|
||||
case TransactionType::WITHDRAWAL === $transaction->transaction_type_type:
|
||||
switch ($transaction->transaction_type_type) {
|
||||
case TransactionType::WITHDRAWAL:
|
||||
$data['source_id'] = $transaction->account_id;
|
||||
$data['source_name'] = $transaction->account_name;
|
||||
$data['source_iban'] = $transaction->account_iban;
|
||||
@@ -181,7 +216,10 @@ class TransactionTransformer extends TransformerAbstract
|
||||
$data['destination_iban'] = $transaction->opposing_account_iban;
|
||||
$data['destination_type'] = $transaction->opposing_account_type;
|
||||
break;
|
||||
case TransactionType::DEPOSIT === $transaction->transaction_type_type:
|
||||
case TransactionType::DEPOSIT:
|
||||
case TransactionType::TRANSFER:
|
||||
case TransactionType::OPENING_BALANCE:
|
||||
case TransactionType::RECONCILIATION:
|
||||
$data['source_id'] = $transaction->opposing_account_id;
|
||||
$data['source_name'] = $transaction->opposing_account_name;
|
||||
$data['source_iban'] = $transaction->opposing_account_iban;
|
||||
@@ -191,30 +229,12 @@ class TransactionTransformer extends TransformerAbstract
|
||||
$data['destination_iban'] = $transaction->account_iban;
|
||||
$data['destination_type'] = $transaction->account_type;
|
||||
break;
|
||||
case TransactionType::TRANSFER === $transaction->transaction_type_type && bccomp($transaction->transaction_amount, '0') > 0:
|
||||
$data['source_id'] = $transaction->opposing_account_id;
|
||||
$data['source_name'] = $transaction->opposing_account_name;
|
||||
$data['source_iban'] = $transaction->opposing_account_iban;
|
||||
$data['source_type'] = $transaction->opposing_account_type;
|
||||
$data['destination_id'] = $transaction->account_id;
|
||||
$data['destination_name'] = $transaction->account_name;
|
||||
$data['destination_iban'] = $transaction->account_iban;
|
||||
$data['destination_type'] = $transaction->account_type;
|
||||
break;
|
||||
case TransactionType::TRANSFER === $transaction->transaction_type_type && bccomp($transaction->transaction_amount, '0') < 0:
|
||||
$data['source_id'] = $transaction->account_id;
|
||||
$data['source_name'] = $transaction->account_name;
|
||||
$data['source_iban'] = $transaction->account_iban;
|
||||
$data['source_type'] = $transaction->account_type;
|
||||
$data['destination_id'] = $transaction->opposing_account_id;
|
||||
$data['destination_name'] = $transaction->opposing_account_name;
|
||||
$data['destination_iban'] = $transaction->opposing_account_iban;
|
||||
$data['destination_type'] = $transaction->opposing_account_type;
|
||||
$data['amount'] = $data['amount'] * -1;
|
||||
$data['foreign_amount'] = is_null($data['foreign_amount']) ? null : $data['foreign_amount'] * -1;
|
||||
break;
|
||||
default:
|
||||
throw new FireflyException(sprintf('Cannot handle % s!', $transaction->transaction_type_type));
|
||||
// @codeCoverageIgnoreStart
|
||||
throw new FireflyException(
|
||||
sprintf('Transaction transformer cannot handle transactions of type "%s"!', $transaction->transaction_type_type)
|
||||
);
|
||||
// @codeCoverageIgnoreEnd
|
||||
|
||||
}
|
||||
|
||||
|
||||
@@ -38,7 +38,9 @@ class UserTransformer extends TransformerAbstract
|
||||
protected $parameters;
|
||||
|
||||
/**
|
||||
* BillTransformer constructor.
|
||||
* UserTransformer constructor.
|
||||
*
|
||||
* @codeCoverageIgnore
|
||||
*
|
||||
* @param ParameterBag $parameters
|
||||
*/
|
||||
@@ -48,6 +50,8 @@ class UserTransformer extends TransformerAbstract
|
||||
}
|
||||
|
||||
/**
|
||||
* Transform user.
|
||||
*
|
||||
* @param User $user
|
||||
*
|
||||
* @return array
|
||||
|
||||
Reference in New Issue
Block a user