mirror of
https://github.com/firefly-iii/firefly-iii.git
synced 2025-02-25 18:45:27 -06:00
Improve test coverage.
This commit is contained in:
@@ -27,11 +27,8 @@ namespace FireflyIII\Api\V1\Controllers;
|
||||
use FireflyIII\Api\V1\Requests\BudgetLimitRequest;
|
||||
use FireflyIII\Exceptions\FireflyException;
|
||||
use FireflyIII\Helpers\Collector\TransactionCollectorInterface;
|
||||
use FireflyIII\Helpers\Filter\InternalTransferFilter;
|
||||
use FireflyIII\Models\BudgetLimit;
|
||||
use FireflyIII\Models\TransactionType;
|
||||
use FireflyIII\Repositories\Budget\BudgetRepositoryInterface;
|
||||
use FireflyIII\Repositories\Journal\JournalRepositoryInterface;
|
||||
use FireflyIII\Support\Http\Api\TransactionFilter;
|
||||
use FireflyIII\Transformers\BudgetLimitTransformer;
|
||||
use FireflyIII\Transformers\TransactionTransformer;
|
||||
@@ -203,7 +200,7 @@ class BudgetLimitController extends Controller
|
||||
$paginator = $collector->getPaginatedTransactions();
|
||||
$paginator->setPath(route('api.v1.budget_limits.transactions', [$budgetLimit->id]) . $this->buildParams());
|
||||
$transactions = $paginator->getCollection();
|
||||
$resource = new FractalCollection($transactions, new TransactionTransformer($this->parameters), 'transactions');
|
||||
$resource = new FractalCollection($transactions, new TransactionTransformer($this->parameters), 'transactions');
|
||||
$resource->setPaginator(new IlluminatePaginatorAdapter($paginator));
|
||||
|
||||
return response()->json($manager->createData($resource)->toArray())->header('Content-Type', 'application/vnd.api+json');
|
||||
@@ -219,12 +216,8 @@ class BudgetLimitController extends Controller
|
||||
*/
|
||||
public function update(BudgetLimitRequest $request, BudgetLimit $budgetLimit): JsonResponse
|
||||
{
|
||||
$data = $request->getAll();
|
||||
$budget = $this->repository->findNull($data['budget_id']);
|
||||
if (null === $budget) {
|
||||
$budget = $budgetLimit->budget;
|
||||
}
|
||||
$data['budget'] = $budget;
|
||||
$data = $request->getAll();
|
||||
$data['budget'] = $budgetLimit->budget;
|
||||
$budgetLimit = $this->repository->updateBudgetLimit($budgetLimit, $data);
|
||||
$manager = new Manager;
|
||||
$baseUrl = $request->getSchemeAndHttpHost() . '/api/v1';
|
||||
|
||||
@@ -28,7 +28,6 @@ use FireflyIII\Helpers\Collector\TransactionCollectorInterface;
|
||||
use FireflyIII\Helpers\Filter\InternalTransferFilter;
|
||||
use FireflyIII\Models\Tag;
|
||||
use FireflyIII\Models\TransactionType;
|
||||
use FireflyIII\Repositories\Journal\JournalRepositoryInterface;
|
||||
use FireflyIII\Repositories\Tag\TagRepositoryInterface;
|
||||
use FireflyIII\Support\Http\Api\TransactionFilter;
|
||||
use FireflyIII\Transformers\TagTransformer;
|
||||
@@ -39,10 +38,10 @@ use Illuminate\Http\Request;
|
||||
use Illuminate\Pagination\LengthAwarePaginator;
|
||||
use League\Fractal\Manager;
|
||||
use League\Fractal\Pagination\IlluminatePaginatorAdapter;
|
||||
use League\Fractal\Resource\Collection as FractalCollection;
|
||||
use League\Fractal\Resource\Item;
|
||||
use League\Fractal\Serializer\JsonApiSerializer;
|
||||
|
||||
use League\Fractal\Resource\Collection as FractalCollection;
|
||||
/**
|
||||
* Class TagController
|
||||
*/
|
||||
@@ -124,11 +123,11 @@ class TagController extends Controller
|
||||
* List single resource.
|
||||
*
|
||||
* @param Request $request
|
||||
* @param Tag $tag
|
||||
* @param Tag $tag
|
||||
*
|
||||
* @return JsonResponse
|
||||
*/
|
||||
public function show(Request $request, Tag $tag): JsonResponse
|
||||
public function show(Request $request, Tag $tag): JsonResponse
|
||||
{
|
||||
$manager = new Manager();
|
||||
$baseUrl = $request->getSchemeAndHttpHost() . '/api/v1';
|
||||
@@ -140,6 +139,24 @@ class TagController extends Controller
|
||||
|
||||
}
|
||||
|
||||
/**
|
||||
* Store new object.
|
||||
*
|
||||
* @param TagRequest $request
|
||||
*
|
||||
* @return JsonResponse
|
||||
*/
|
||||
public function store(TagRequest $request): JsonResponse
|
||||
{
|
||||
$rule = $this->repository->store($request->getAll());
|
||||
$manager = new Manager();
|
||||
$baseUrl = $request->getSchemeAndHttpHost() . '/api/v1';
|
||||
$manager->setSerializer(new JsonApiSerializer($baseUrl));
|
||||
|
||||
$resource = new Item($rule, new TagTransformer($this->parameters), 'tags');
|
||||
|
||||
return response()->json($manager->createData($resource)->toArray())->header('Content-Type', 'application/vnd.api+json');
|
||||
}
|
||||
|
||||
/**
|
||||
* Show all transactions.
|
||||
@@ -188,31 +205,11 @@ class TagController extends Controller
|
||||
return response()->json($manager->createData($resource)->toArray())->header('Content-Type', 'application/vnd.api+json');
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* Store new object.
|
||||
*
|
||||
* @param TagRequest $request
|
||||
*
|
||||
* @return JsonResponse
|
||||
*/
|
||||
public function store(TagRequest $request): JsonResponse
|
||||
{
|
||||
$rule = $this->repository->store($request->getAll());
|
||||
$manager = new Manager();
|
||||
$baseUrl = $request->getSchemeAndHttpHost() . '/api/v1';
|
||||
$manager->setSerializer(new JsonApiSerializer($baseUrl));
|
||||
|
||||
$resource = new Item($rule, new TagTransformer($this->parameters), 'tags');
|
||||
|
||||
return response()->json($manager->createData($resource)->toArray())->header('Content-Type', 'application/vnd.api+json');
|
||||
}
|
||||
|
||||
/**
|
||||
* Update a rule.
|
||||
*
|
||||
* @param TagRequest $request
|
||||
* @param Tag $tag
|
||||
* @param Tag $tag
|
||||
*
|
||||
* @return JsonResponse
|
||||
*/
|
||||
|
||||
@@ -91,32 +91,13 @@ class TransactionController extends Controller
|
||||
$baseUrl = $request->getSchemeAndHttpHost() . '/api/v1';
|
||||
$manager->setSerializer(new JsonApiSerializer($baseUrl));
|
||||
|
||||
$attachments = $transaction->transactionJournal->attachments()->get();
|
||||
$attachments = $this->repository->getAttachmentsByTr($transaction);
|
||||
$resource = new FractalCollection($attachments, new AttachmentTransformer($this->parameters), 'attachments');
|
||||
|
||||
return response()->json($manager->createData($resource)->toArray())->header('Content-Type', 'application/vnd.api+json');
|
||||
|
||||
}
|
||||
|
||||
/**
|
||||
* @param Request $request
|
||||
* @param Transaction $transaction
|
||||
*
|
||||
* @return JsonResponse
|
||||
*/
|
||||
public function piggyBankEvents(Request $request, Transaction $transaction): JsonResponse
|
||||
{
|
||||
$manager = new Manager();
|
||||
$baseUrl = $request->getSchemeAndHttpHost() . '/api/v1';
|
||||
$manager->setSerializer(new JsonApiSerializer($baseUrl));
|
||||
|
||||
$events= $transaction->transactionJournal->piggyBankEvents()->get();
|
||||
$resource = new FractalCollection($events, new PiggyBankEventTransformer($this->parameters), 'piggy_bank_events');
|
||||
|
||||
return response()->json($manager->createData($resource)->toArray())->header('Content-Type', 'application/vnd.api+json');
|
||||
|
||||
}
|
||||
|
||||
/**
|
||||
* Remove the specified resource from storage.
|
||||
*
|
||||
@@ -177,6 +158,25 @@ class TransactionController extends Controller
|
||||
return response()->json($manager->createData($resource)->toArray())->header('Content-Type', 'application/vnd.api+json');
|
||||
}
|
||||
|
||||
/**
|
||||
* @param Request $request
|
||||
* @param Transaction $transaction
|
||||
*
|
||||
* @return JsonResponse
|
||||
*/
|
||||
public function piggyBankEvents(Request $request, Transaction $transaction): JsonResponse
|
||||
{
|
||||
$manager = new Manager();
|
||||
$baseUrl = $request->getSchemeAndHttpHost() . '/api/v1';
|
||||
$manager->setSerializer(new JsonApiSerializer($baseUrl));
|
||||
|
||||
$events = $this->repository->getPiggyBankEventsByTr($transaction);
|
||||
$resource = new FractalCollection($events, new PiggyBankEventTransformer($this->parameters), 'piggy_bank_events');
|
||||
|
||||
return response()->json($manager->createData($resource)->toArray())->header('Content-Type', 'application/vnd.api+json');
|
||||
|
||||
}
|
||||
|
||||
/**
|
||||
* Show a single transaction.
|
||||
*
|
||||
|
||||
@@ -59,7 +59,7 @@ class ConfigurationRequest extends Request
|
||||
return ['value' => $this->integer('value')];
|
||||
}
|
||||
|
||||
return ['value' => $this->string('value')];
|
||||
return ['value' => $this->string('value')]; // @codeCoverageIgnore
|
||||
}
|
||||
|
||||
/**
|
||||
@@ -78,6 +78,6 @@ class ConfigurationRequest extends Request
|
||||
return ['value' => 'required|numeric|between:-1,1'];
|
||||
}
|
||||
|
||||
return ['value' => 'required'];
|
||||
return ['value' => 'required']; // @codeCoverageIgnore
|
||||
}
|
||||
}
|
||||
|
||||
@@ -25,7 +25,6 @@ declare(strict_types=1);
|
||||
namespace FireflyIII\Api\V1\Requests;
|
||||
|
||||
use FireflyIII\Models\Tag;
|
||||
use Illuminate\Validation\Validator;
|
||||
|
||||
/**
|
||||
* Class TagRequest
|
||||
@@ -57,7 +56,7 @@ class TagRequest extends Request
|
||||
'description' => $this->string('description'),
|
||||
'latitude' => '' === $this->string('latitude') ? null : $this->string('latitude'),
|
||||
'longitude' => '' === $this->string('longitude') ? null : $this->string('longitude'),
|
||||
'zoom_level' => $this->integer('zoom_level'),
|
||||
'zoom_level' => $this->integer('zoom_level'),
|
||||
];
|
||||
|
||||
return $data;
|
||||
@@ -76,7 +75,7 @@ class TagRequest extends Request
|
||||
'date' => 'date|nullable',
|
||||
'latitude' => 'numeric|min:-90|max:90|nullable|required_with:longitude',
|
||||
'longitude' => 'numeric|min:-90|max:90|nullable|required_with:latitude',
|
||||
'zoomLevel' => 'numeric|min:0|max:80|nullable',
|
||||
'zoom_level' => 'numeric|min:0|max:80|nullable',
|
||||
];
|
||||
switch ($this->method()) {
|
||||
default:
|
||||
@@ -91,25 +90,4 @@ class TagRequest extends Request
|
||||
|
||||
return $rules;
|
||||
}
|
||||
|
||||
/**
|
||||
* Configure the validator instance.
|
||||
*
|
||||
* @param Validator $validator
|
||||
*
|
||||
* @return void
|
||||
*/
|
||||
public function withValidator(Validator $validator): void
|
||||
{
|
||||
$validator->after(
|
||||
function (Validator $validator) {
|
||||
$data = $validator->getData();
|
||||
$min = (float)($data['amount_min'] ?? 0);
|
||||
$max = (float)($data['amount_max'] ?? 0);
|
||||
if ($min > $max) {
|
||||
$validator->errors()->add('amount_min', (string)trans('validation.amount_min_over_max'));
|
||||
}
|
||||
}
|
||||
);
|
||||
}
|
||||
}
|
||||
|
||||
@@ -19,6 +19,7 @@ use Illuminate\Support\Collection;
|
||||
/**
|
||||
*
|
||||
* Class ApplyRules
|
||||
* @codeCoverageIgnore
|
||||
*/
|
||||
class ApplyRules extends Command
|
||||
{
|
||||
|
||||
@@ -72,7 +72,7 @@ class TransactionFactory
|
||||
throw new FireflyException('Amount is an empty string, which Firefly III cannot handle. Apologies.');
|
||||
}
|
||||
if (null === $currencyId) {
|
||||
throw new FireflyException('Cannot store transaction without currency information.');
|
||||
throw new FireflyException('Cannot store transaction without currency information.'); // @codeCoverageIgnore
|
||||
}
|
||||
$data['foreign_amount'] = '' === (string)$data['foreign_amount'] ? null : $data['foreign_amount'];
|
||||
Log::debug(sprintf('Create transaction for account #%d ("%s") with amount %s', $data['account']->id, $data['account']->name, $data['amount']));
|
||||
|
||||
@@ -48,7 +48,7 @@ class AutomationHandler
|
||||
$sendReport = envNonEmpty('SEND_REPORT_JOURNALS', true);
|
||||
|
||||
if (false === $sendReport) {
|
||||
return true;
|
||||
return true; // @codeCoverageIgnore
|
||||
}
|
||||
|
||||
Log::debug('In reportJournals.');
|
||||
|
||||
@@ -31,6 +31,8 @@ use Illuminate\Support\Collection;
|
||||
*
|
||||
* Used when the final collection contains double transactions, which can happen when viewing the tag report.
|
||||
* Class DoubleTransactionFilter
|
||||
*
|
||||
* @codeCoverageIgnore
|
||||
*/
|
||||
class DoubleTransactionFilter implements FilterInterface
|
||||
{
|
||||
|
||||
@@ -86,9 +86,11 @@ class ProfileController extends Controller
|
||||
{
|
||||
$loginProvider = config('firefly.login_provider');
|
||||
if ('eloquent' !== $loginProvider) {
|
||||
// @codeCoverageIgnoreStart
|
||||
$request->session()->flash('error', trans('firefly.login_provider_local_only', ['login_provider' => $loginProvider]));
|
||||
|
||||
return redirect(route('profile.index'));
|
||||
// @codeCoverageIgnoreEnd
|
||||
}
|
||||
|
||||
$title = auth()->user()->email;
|
||||
@@ -108,9 +110,11 @@ class ProfileController extends Controller
|
||||
{
|
||||
$loginProvider = config('firefly.login_provider');
|
||||
if ('eloquent' !== $loginProvider) {
|
||||
// @codeCoverageIgnoreStart
|
||||
$request->session()->flash('error', trans('firefly.login_provider_local_only', ['login_provider' => $loginProvider]));
|
||||
|
||||
return redirect(route('profile.index'));
|
||||
// @codeCoverageIgnoreEnd
|
||||
}
|
||||
|
||||
$title = auth()->user()->email;
|
||||
@@ -150,7 +154,9 @@ class ProfileController extends Controller
|
||||
{
|
||||
$loginProvider = config('firefly.login_provider');
|
||||
if ('eloquent' !== $loginProvider) {
|
||||
// @codeCoverageIgnoreStart
|
||||
throw new FireflyException('Cannot confirm email change when authentication provider is not local.');
|
||||
// @codeCoverageIgnoreEnd
|
||||
}
|
||||
// find preference with this token value.
|
||||
/** @var Collection $set */
|
||||
@@ -187,7 +193,9 @@ class ProfileController extends Controller
|
||||
{
|
||||
$loginProvider = config('firefly.login_provider');
|
||||
if ('eloquent' !== $loginProvider) {
|
||||
// @codeCoverageIgnoreStart
|
||||
$request->session()->flash('warning', trans('firefly.delete_local_info_only', ['login_provider' => $loginProvider]));
|
||||
// @codeCoverageIgnoreEnd
|
||||
}
|
||||
$title = auth()->user()->email;
|
||||
$subTitle = (string)trans('firefly.delete_account');
|
||||
@@ -281,9 +289,11 @@ class ProfileController extends Controller
|
||||
{
|
||||
$loginProvider = config('firefly.login_provider');
|
||||
if ('eloquent' !== $loginProvider) {
|
||||
// @codeCoverageIgnoreStart
|
||||
$request->session()->flash('error', trans('firefly.login_provider_local_only', ['login_provider' => $loginProvider]));
|
||||
|
||||
return redirect(route('profile.index'));
|
||||
// @codeCoverageIgnoreEnd
|
||||
}
|
||||
|
||||
/** @var User $user */
|
||||
@@ -333,9 +343,11 @@ class ProfileController extends Controller
|
||||
{
|
||||
$loginProvider = config('firefly.login_provider');
|
||||
if ('eloquent' !== $loginProvider) {
|
||||
// @codeCoverageIgnoreStart
|
||||
$request->session()->flash('error', trans('firefly.login_provider_local_only', ['login_provider' => $loginProvider]));
|
||||
|
||||
return redirect(route('profile.index'));
|
||||
// @codeCoverageIgnoreEnd
|
||||
}
|
||||
|
||||
// the request has already validated both new passwords must be equal.
|
||||
@@ -437,7 +449,9 @@ class ProfileController extends Controller
|
||||
{
|
||||
$loginProvider = config('firefly.login_provider');
|
||||
if ('eloquent' !== $loginProvider) {
|
||||
// @codeCoverageIgnoreStart
|
||||
throw new FireflyException('Cannot confirm email change when authentication provider is not local.');
|
||||
// @codeCoverageIgnoreEnd
|
||||
}
|
||||
|
||||
// find preference with this token value.
|
||||
|
||||
@@ -40,6 +40,9 @@ use Symfony\Component\HttpKernel\Exception\NotFoundHttpException;
|
||||
* @property float $spent // used in category reports
|
||||
* @property Carbon|null lastActivity
|
||||
* @property bool encrypted
|
||||
* @property User $user
|
||||
* @property Carbon $created_at
|
||||
* @property Carbon $updated_at
|
||||
*/
|
||||
class Category extends Model
|
||||
{
|
||||
|
||||
@@ -44,7 +44,6 @@ use Symfony\Component\HttpKernel\Exception\NotFoundHttpException;
|
||||
* @property Carbon $created_at
|
||||
* @property Carbon $updated_at
|
||||
* @property string $title
|
||||
* @property string $text
|
||||
* @property int $order
|
||||
* @property RuleGroup $ruleGroup
|
||||
* @property int $rule_group_id
|
||||
|
||||
@@ -709,6 +709,54 @@ class BudgetRepository implements BudgetRepositoryInterface
|
||||
return (string)$set->sum('transaction_amount');
|
||||
}
|
||||
|
||||
/**
|
||||
* @param Collection $budgets
|
||||
* @param Collection $accounts
|
||||
* @param Carbon $start
|
||||
* @param Carbon $end
|
||||
*
|
||||
* @return array
|
||||
*/
|
||||
public function spentInPeriodMc(Collection $budgets, Collection $accounts, Carbon $start, Carbon $end): array
|
||||
{
|
||||
/** @var TransactionCollectorInterface $collector */
|
||||
$collector = app(TransactionCollectorInterface::class);
|
||||
$collector->setUser($this->user);
|
||||
$collector->setRange($start, $end)->setBudgets($budgets)->withBudgetInformation();
|
||||
|
||||
if ($accounts->count() > 0) {
|
||||
$collector->setAccounts($accounts);
|
||||
}
|
||||
if (0 === $accounts->count()) {
|
||||
$collector->setAllAssetAccounts();
|
||||
}
|
||||
|
||||
$set = $collector->getTransactions();
|
||||
$return = [];
|
||||
$total = [];
|
||||
$currencies = [];
|
||||
/** @var Transaction $transaction */
|
||||
foreach ($set as $transaction) {
|
||||
$code = $transaction->transaction_currency_code;
|
||||
if (!isset($currencies[$code])) {
|
||||
$currencies[$code] = $transaction->transactionCurrency;
|
||||
}
|
||||
$total[$code] = isset($total[$code]) ? bcadd($total[$code], $transaction->transaction_amount) : $transaction->transaction_amount;
|
||||
}
|
||||
foreach ($total as $code => $spent) {
|
||||
/** @var TransactionCurrency $currency */
|
||||
$currency = $currencies[$code];
|
||||
$return[] = [
|
||||
'currency_code' => $code,
|
||||
'currency_symbol' => $currency->symbol,
|
||||
'currency_dp' => $currency->decimal_places,
|
||||
'amount' => round($spent, $currency->decimal_places),
|
||||
];
|
||||
}
|
||||
|
||||
return $return;
|
||||
}
|
||||
|
||||
/**
|
||||
* @param Collection $accounts
|
||||
* @param Carbon $start
|
||||
|
||||
@@ -35,7 +35,6 @@ use Illuminate\Support\Collection;
|
||||
*/
|
||||
interface BudgetRepositoryInterface
|
||||
{
|
||||
|
||||
/**
|
||||
* A method that returns the amount of money budgeted per day for this budget,
|
||||
* on average.
|
||||
@@ -166,13 +165,13 @@ interface BudgetRepositoryInterface
|
||||
*/
|
||||
public function getBudgetPeriodReport(Collection $budgets, Collection $accounts, Carbon $start, Carbon $end): array;
|
||||
|
||||
/** @noinspection MoreThanThreeArgumentsInspection */
|
||||
|
||||
/**
|
||||
* @return Collection
|
||||
*/
|
||||
public function getBudgets(): Collection;
|
||||
|
||||
/** @noinspection MoreThanThreeArgumentsInspection */
|
||||
|
||||
/**
|
||||
* Get all budgets with these ID's.
|
||||
*
|
||||
@@ -206,20 +205,19 @@ interface BudgetRepositoryInterface
|
||||
*/
|
||||
public function setAvailableBudget(TransactionCurrency $currency, Carbon $start, Carbon $end, string $amount): AvailableBudget;
|
||||
|
||||
/** @noinspection MoreThanThreeArgumentsInspection */
|
||||
|
||||
/**
|
||||
* @param Budget $budget
|
||||
* @param int $order
|
||||
*/
|
||||
public function setBudgetOrder(Budget $budget, int $order): void;
|
||||
|
||||
/** @noinspection MoreThanThreeArgumentsInspection */
|
||||
|
||||
/**
|
||||
* @param User $user
|
||||
*/
|
||||
public function setUser(User $user);
|
||||
|
||||
/** @noinspection MoreThanThreeArgumentsInspection */
|
||||
/**
|
||||
* @param Collection $budgets
|
||||
* @param Collection $accounts
|
||||
@@ -230,6 +228,20 @@ interface BudgetRepositoryInterface
|
||||
*/
|
||||
public function spentInPeriod(Collection $budgets, Collection $accounts, Carbon $start, Carbon $end): string;
|
||||
|
||||
/** @noinspection MoreThanThreeArgumentsInspection */
|
||||
|
||||
/**
|
||||
* Return multi-currency spent information.
|
||||
*
|
||||
* @param Collection $budgets
|
||||
* @param Collection $accounts
|
||||
* @param Carbon $start
|
||||
* @param Carbon $end
|
||||
*
|
||||
* @return array
|
||||
*/
|
||||
public function spentInPeriodMc(Collection $budgets, Collection $accounts, Carbon $start, Carbon $end): array;
|
||||
|
||||
/**
|
||||
* @param Collection $accounts
|
||||
* @param Carbon $start
|
||||
|
||||
@@ -274,6 +274,16 @@ class JournalRepository implements JournalRepositoryInterface
|
||||
return $journal->attachments;
|
||||
}
|
||||
|
||||
/**
|
||||
* @param Transaction $transaction
|
||||
*
|
||||
* @return Collection
|
||||
*/
|
||||
public function getAttachmentsByTr(Transaction $transaction): Collection
|
||||
{
|
||||
return $transaction->transactionJournal->attachments()->get();
|
||||
}
|
||||
|
||||
/**
|
||||
* Returns the first positive transaction for the journal. Useful when editing journals.
|
||||
*
|
||||
@@ -574,6 +584,16 @@ class JournalRepository implements JournalRepositoryInterface
|
||||
return $events;
|
||||
}
|
||||
|
||||
/**
|
||||
* @param Transaction $transaction
|
||||
*
|
||||
* @return Collection
|
||||
*/
|
||||
public function getPiggyBankEventsbyTr(Transaction $transaction): Collection
|
||||
{
|
||||
return $transaction->transactionJournal->piggyBankEvents()->get();
|
||||
}
|
||||
|
||||
/**
|
||||
* Return all tags as strings in an array.
|
||||
*
|
||||
|
||||
@@ -122,6 +122,13 @@ interface JournalRepositoryInterface
|
||||
*/
|
||||
public function getAttachments(TransactionJournal $journal): Collection;
|
||||
|
||||
/**
|
||||
* @param Transaction $transaction
|
||||
*
|
||||
* @return Collection
|
||||
*/
|
||||
public function getAttachmentsByTr(Transaction $transaction): Collection;
|
||||
|
||||
/**
|
||||
* Returns the first positive transaction for the journal. Useful when editing journals.
|
||||
*
|
||||
@@ -233,6 +240,13 @@ interface JournalRepositoryInterface
|
||||
*/
|
||||
public function getPiggyBankEvents(TransactionJournal $journal): Collection;
|
||||
|
||||
/**
|
||||
* @param Transaction $transaction
|
||||
*
|
||||
* @return Collection
|
||||
*/
|
||||
public function getPiggyBankEventsbyTr(Transaction $transaction): Collection;
|
||||
|
||||
/**
|
||||
* Return all tags as strings in an array.
|
||||
*
|
||||
|
||||
@@ -118,8 +118,8 @@ class AccountTransformer extends TransformerAbstract
|
||||
|
||||
$data = [
|
||||
'id' => (int)$account->id,
|
||||
'updated_at' => $account->updated_at->toAtomString(),
|
||||
'created_at' => $account->created_at->toAtomString(),
|
||||
'updated_at' => $account->updated_at->toAtomString(),
|
||||
'active' => 1 === (int)$account->active,
|
||||
'name' => $account->name,
|
||||
'type' => $type,
|
||||
|
||||
@@ -66,8 +66,8 @@ class AttachmentTransformer extends TransformerAbstract
|
||||
|
||||
return [
|
||||
'id' => (int)$attachment->id,
|
||||
'updated_at' => $attachment->updated_at->toAtomString(),
|
||||
'created_at' => $attachment->created_at->toAtomString(),
|
||||
'updated_at' => $attachment->updated_at->toAtomString(),
|
||||
'attachable_id' => $attachment->attachable_id,
|
||||
'attachable_type' => str_replace('FireflyIII\\Models\\','',$attachment->attachable_type),
|
||||
'md5' => $attachment->md5,
|
||||
|
||||
@@ -25,7 +25,6 @@ namespace FireflyIII\Transformers;
|
||||
|
||||
|
||||
use FireflyIII\Models\AvailableBudget;
|
||||
use League\Fractal\Resource\Item;
|
||||
use League\Fractal\TransformerAbstract;
|
||||
use Symfony\Component\HttpFoundation\ParameterBag;
|
||||
|
||||
@@ -58,14 +57,19 @@ class AvailableBudgetTransformer extends TransformerAbstract
|
||||
*/
|
||||
public function transform(AvailableBudget $availableBudget): array
|
||||
{
|
||||
$data = [
|
||||
'id' => (int)$availableBudget->id,
|
||||
'updated_at' => $availableBudget->updated_at->toAtomString(),
|
||||
'created_at' => $availableBudget->created_at->toAtomString(),
|
||||
'start_date' => $availableBudget->start_date->format('Y-m-d'),
|
||||
'end_date' => $availableBudget->end_date->format('Y-m-d'),
|
||||
'amount' => round($availableBudget->amount, $availableBudget->transactionCurrency->decimal_places),
|
||||
'links' => [
|
||||
$currency = $availableBudget->transactionCurrency;
|
||||
$data = [
|
||||
'id' => (int)$availableBudget->id,
|
||||
'created_at' => $availableBudget->created_at->toAtomString(),
|
||||
'updated_at' => $availableBudget->updated_at->toAtomString(),
|
||||
'currency_id' => $currency->id,
|
||||
'currency_code' => $currency->code,
|
||||
'currency_symbol' => $currency->symbol,
|
||||
'currency_dp' => $currency->decimal_places,
|
||||
'start' => $availableBudget->start_date->format('Y-m-d'),
|
||||
'end' => $availableBudget->end_date->format('Y-m-d'),
|
||||
'amount' => round($availableBudget->amount, $currency->decimal_places),
|
||||
'links' => [
|
||||
[
|
||||
'rel' => 'self',
|
||||
'uri' => '/available_budgets/' . $availableBudget->id,
|
||||
|
||||
@@ -72,24 +72,24 @@ class BillTransformer extends TransformerAbstract
|
||||
$this->repository->setUser($bill->user);
|
||||
$data = [
|
||||
'id' => (int)$bill->id,
|
||||
'updated_at' => $bill->updated_at->toAtomString(),
|
||||
'created_at' => $bill->created_at->toAtomString(),
|
||||
'name' => $bill->name,
|
||||
'updated_at' => $bill->updated_at->toAtomString(),
|
||||
'currency_id' => $bill->transaction_currency_id,
|
||||
'currency_code' => $bill->transactionCurrency->code,
|
||||
'currency_symbol' => $bill->transactionCurrency->symbol,
|
||||
'currency_dp' => $bill->transactionCurrency->decimal_places,
|
||||
'name' => $bill->name,
|
||||
'amount_min' => round((float)$bill->amount_min, 2),
|
||||
'amount_max' => round((float)$bill->amount_max, 2),
|
||||
'date' => $bill->date->format('Y-m-d'),
|
||||
'repeat_freq' => $bill->repeat_freq,
|
||||
'skip' => (int)$bill->skip,
|
||||
'automatch' => $bill->automatch,
|
||||
'active' => $bill->active,
|
||||
'attachments_count' => $bill->attachments()->count(),
|
||||
'pay_dates' => $payDates,
|
||||
'notes' => $this->repository->getNoteText($bill),
|
||||
'paid_dates' => $paidData['paid_dates'],
|
||||
'next_expected_match' => $paidData['next_expected_match'],
|
||||
'pay_dates' => $payDates,
|
||||
'paid_dates' => $paidData['paid_dates'],
|
||||
|
||||
'links' => [
|
||||
[
|
||||
'rel' => 'self',
|
||||
|
||||
@@ -71,8 +71,8 @@ class BudgetLimitTransformer extends TransformerAbstract
|
||||
}
|
||||
$data = [
|
||||
'id' => (int)$budgetLimit->id,
|
||||
'updated_at' => $budgetLimit->updated_at->toAtomString(),
|
||||
'created_at' => $budgetLimit->created_at->toAtomString(),
|
||||
'updated_at' => $budgetLimit->updated_at->toAtomString(),
|
||||
'start_date' => $budgetLimit->start_date->format('Y-m-d'),
|
||||
'end_date' => $budgetLimit->end_date->format('Y-m-d'),
|
||||
'budget_id' => $budgetLimit->budget_id,
|
||||
|
||||
@@ -24,11 +24,9 @@ declare(strict_types=1);
|
||||
namespace FireflyIII\Transformers;
|
||||
|
||||
|
||||
use FireflyIII\Helpers\Collector\TransactionCollectorInterface;
|
||||
use FireflyIII\Models\Budget;
|
||||
use FireflyIII\Repositories\Budget\BudgetRepositoryInterface;
|
||||
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;
|
||||
|
||||
@@ -61,12 +59,24 @@ class BudgetTransformer extends TransformerAbstract
|
||||
*/
|
||||
public function transform(Budget $budget): array
|
||||
{
|
||||
$start = $this->parameters->get('start');
|
||||
$end = $this->parameters->get('end');
|
||||
$spent = [];
|
||||
if (null !== $start && null !== $end) {
|
||||
/** @var BudgetRepositoryInterface $repository */
|
||||
$repository = app(BudgetRepositoryInterface::class);
|
||||
$repository->setUser($budget->user);
|
||||
$spent = $repository->spentInPeriodMc(new Collection([$budget]), new Collection, $start, $end);
|
||||
}
|
||||
|
||||
|
||||
$data = [
|
||||
'id' => (int)$budget->id,
|
||||
'updated_at' => $budget->updated_at->toAtomString(),
|
||||
'created_at' => $budget->created_at->toAtomString(),
|
||||
'updated_at' => $budget->updated_at->toAtomString(),
|
||||
'active' => 1 === (int)$budget->active,
|
||||
'name' => $budget->name,
|
||||
'spent' => $spent,
|
||||
'links' => [
|
||||
[
|
||||
'rel' => 'self',
|
||||
|
||||
@@ -24,11 +24,12 @@ declare(strict_types=1);
|
||||
namespace FireflyIII\Transformers;
|
||||
|
||||
|
||||
use FireflyIII\Helpers\Collector\TransactionCollectorInterface;
|
||||
use Carbon\Carbon;
|
||||
use FireflyIII\Models\Category;
|
||||
use FireflyIII\Models\Transaction;
|
||||
use FireflyIII\Models\TransactionCurrency;
|
||||
use FireflyIII\Repositories\Category\CategoryRepositoryInterface;
|
||||
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;
|
||||
|
||||
@@ -61,11 +62,21 @@ class CategoryTransformer extends TransformerAbstract
|
||||
*/
|
||||
public function transform(Category $category): array
|
||||
{
|
||||
$spent = [];
|
||||
$earned = [];
|
||||
$start = $this->parameters->get('start');
|
||||
$end = $this->parameters->get('end');
|
||||
if (null !== $start && null !== $end) {
|
||||
$spent = $this->getSpentInformation($category, $start, $end);
|
||||
$earned = $this->getEarnedInformation($category, $start, $end);
|
||||
}
|
||||
$data = [
|
||||
'id' => (int)$category->id,
|
||||
'updated_at' => $category->updated_at->toAtomString(),
|
||||
'created_at' => $category->created_at->toAtomString(),
|
||||
'updated_at' => $category->updated_at->toAtomString(),
|
||||
'name' => $category->name,
|
||||
'spent' => $spent,
|
||||
'earned' => $earned,
|
||||
'links' => [
|
||||
[
|
||||
'rel' => 'self',
|
||||
@@ -77,4 +88,80 @@ class CategoryTransformer extends TransformerAbstract
|
||||
return $data;
|
||||
}
|
||||
|
||||
/**
|
||||
* @param Category $category
|
||||
* @param Carbon $start
|
||||
* @param Carbon $end
|
||||
*
|
||||
* @return array
|
||||
*/
|
||||
private function getEarnedInformation(Category $category, Carbon $start, Carbon $end): array
|
||||
{
|
||||
/** @var CategoryRepositoryInterface $repository */
|
||||
$repository = app(CategoryRepositoryInterface::class);
|
||||
$repository->setUser($category->user);
|
||||
$collection = $repository->earnedInPeriodCollection(new Collection([$category]), new Collection, $start, $end);
|
||||
$return = [];
|
||||
$total = [];
|
||||
$currencies = [];
|
||||
/** @var Transaction $transaction */
|
||||
foreach ($collection as $transaction) {
|
||||
$code = $transaction->transaction_currency_code;
|
||||
if (!isset($currencies[$code])) {
|
||||
$currencies[$code] = $transaction->transactionCurrency;
|
||||
}
|
||||
$total[$code] = isset($total[$code]) ? bcadd($total[$code], $transaction->transaction_amount) : $transaction->transaction_amount;
|
||||
}
|
||||
foreach ($total as $code => $earned) {
|
||||
/** @var TransactionCurrency $currency */
|
||||
$currency = $currencies[$code];
|
||||
$return[] = [
|
||||
'currency_code' => $code,
|
||||
'currency_symbol' => $currency->symbol,
|
||||
'currency_dp' => $currency->decimal_places,
|
||||
'amount' => round($earned, $currency->decimal_places),
|
||||
];
|
||||
}
|
||||
|
||||
return $return;
|
||||
}
|
||||
|
||||
/**
|
||||
* @param Category $category
|
||||
* @param Carbon $start
|
||||
* @param Carbon $end
|
||||
*
|
||||
* @return array
|
||||
*/
|
||||
private function getSpentInformation(Category $category, Carbon $start, Carbon $end): array
|
||||
{
|
||||
/** @var CategoryRepositoryInterface $repository */
|
||||
$repository = app(CategoryRepositoryInterface::class);
|
||||
$repository->setUser($category->user);
|
||||
$collection = $repository->spentInPeriodCollection(new Collection([$category]), new Collection, $start, $end);
|
||||
$return = [];
|
||||
$total = [];
|
||||
$currencies = [];
|
||||
/** @var Transaction $transaction */
|
||||
foreach ($collection as $transaction) {
|
||||
$code = $transaction->transaction_currency_code;
|
||||
if (!isset($currencies[$code])) {
|
||||
$currencies[$code] = $transaction->transactionCurrency;
|
||||
}
|
||||
$total[$code] = isset($total[$code]) ? bcadd($total[$code], $transaction->transaction_amount) : $transaction->transaction_amount;
|
||||
}
|
||||
foreach ($total as $code => $spent) {
|
||||
/** @var TransactionCurrency $currency */
|
||||
$currency = $currencies[$code];
|
||||
$return[] = [
|
||||
'currency_code' => $code,
|
||||
'currency_symbol' => $currency->symbol,
|
||||
'currency_dp' => $currency->decimal_places,
|
||||
'amount' => round($spent, $currency->decimal_places),
|
||||
];
|
||||
}
|
||||
|
||||
return $return;
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
@@ -59,8 +59,8 @@ class CurrencyExchangeRateTransformer extends TransformerAbstract
|
||||
$result = 0.0 === $result ? null : $result;
|
||||
$data = [
|
||||
'id' => (int)$rate->id,
|
||||
'updated_at' => $rate->updated_at->toAtomString(),
|
||||
'created_at' => $rate->created_at->toAtomString(),
|
||||
'updated_at' => $rate->updated_at->toAtomString(),
|
||||
'from_currency_id' => $rate->fromCurrency->id,
|
||||
'from_currency_name' => $rate->fromCurrency->name,
|
||||
'from_currency_code' => $rate->fromCurrency->code,
|
||||
|
||||
@@ -63,14 +63,14 @@ class CurrencyTransformer extends TransformerAbstract
|
||||
}
|
||||
$data = [
|
||||
'id' => (int)$currency->id,
|
||||
'updated_at' => $currency->updated_at->toAtomString(),
|
||||
'created_at' => $currency->created_at->toAtomString(),
|
||||
'updated_at' => $currency->updated_at->toAtomString(),
|
||||
'default' => $isDefault,
|
||||
'enabled' => $currency->enabled,
|
||||
'name' => $currency->name,
|
||||
'code' => $currency->code,
|
||||
'symbol' => $currency->symbol,
|
||||
'decimal_places' => (int)$currency->decimal_places,
|
||||
'default' => $isDefault,
|
||||
'enabled' => $currency->enabled,
|
||||
'links' => [
|
||||
[
|
||||
'rel' => 'self',
|
||||
|
||||
@@ -67,8 +67,10 @@ class ImportJobTransformer extends TransformerAbstract
|
||||
}
|
||||
$data = [
|
||||
'id' => (int)$importJob->id,
|
||||
'updated_at' => $importJob->updated_at->toAtomString(),
|
||||
'created_at' => $importJob->created_at->toAtomString(),
|
||||
'updated_at' => $importJob->updated_at->toAtomString(),
|
||||
'tag_id' => $tagId,
|
||||
'tag_tag' => $tagTag,
|
||||
'key' => $importJob->key,
|
||||
'file_type' => $importJob->file_type,
|
||||
'provider' => $importJob->provider,
|
||||
@@ -78,8 +80,7 @@ class ImportJobTransformer extends TransformerAbstract
|
||||
'extended_status' => $importJob->extended_status,
|
||||
'transactions' => $importJob->transactions,
|
||||
'errors' => $importJob->errors,
|
||||
'tag_id' => $tagId,
|
||||
'tag_tag' => $tagTag,
|
||||
|
||||
'links' => [
|
||||
[
|
||||
'rel' => 'self',
|
||||
|
||||
@@ -66,8 +66,8 @@ class JournalLinkTransformer extends TransformerAbstract
|
||||
|
||||
$data = [
|
||||
'id' => (int)$link->id,
|
||||
'updated_at' => $link->updated_at->toAtomString(),
|
||||
'created_at' => $link->created_at->toAtomString(),
|
||||
'updated_at' => $link->updated_at->toAtomString(),
|
||||
'inward_id' => $link->source_id,
|
||||
'outward_id' => $link->destination_id,
|
||||
'notes' => $notes,
|
||||
|
||||
@@ -62,8 +62,8 @@ class JournalMetaTransformer extends TransformerAbstract
|
||||
{
|
||||
$data = [
|
||||
'id' => (int)$meta->id,
|
||||
'updated_at' => $meta->updated_at->toAtomString(),
|
||||
'created_at' => $meta->created_at->toAtomString(),
|
||||
'updated_at' => $meta->updated_at->toAtomString(),
|
||||
'name' => $meta->name,
|
||||
'data' => $meta->data,
|
||||
'hash' => $meta->hash,
|
||||
|
||||
@@ -74,8 +74,8 @@ class LinkTypeTransformer extends TransformerAbstract
|
||||
{
|
||||
$data = [
|
||||
'id' => (int)$linkType->id,
|
||||
'updated_at' => $linkType->updated_at->toAtomString(),
|
||||
'created_at' => $linkType->created_at->toAtomString(),
|
||||
'updated_at' => $linkType->updated_at->toAtomString(),
|
||||
'name' => $linkType->name,
|
||||
'inward' => $linkType->inward,
|
||||
'outward' => $linkType->outward,
|
||||
|
||||
@@ -74,8 +74,8 @@ class NoteTransformer extends TransformerAbstract
|
||||
$converter = new CommonMarkConverter;
|
||||
$data = [
|
||||
'id' => (int)$note->id,
|
||||
'updated_at' => $note->updated_at->toAtomString(),
|
||||
'created_at' => $note->created_at->toAtomString(),
|
||||
'updated_at' => $note->updated_at->toAtomString(),
|
||||
'title' => $note->title,
|
||||
'text' => $note->text,
|
||||
'markdown' => $converter->convertToHtml($note->text),
|
||||
|
||||
@@ -85,8 +85,8 @@ class PiggyBankEventTransformer extends TransformerAbstract
|
||||
|
||||
$data = [
|
||||
'id' => (int)$event->id,
|
||||
'updated_at' => $event->updated_at->toAtomString(),
|
||||
'created_at' => $event->created_at->toAtomString(),
|
||||
'updated_at' => $event->updated_at->toAtomString(),
|
||||
'amount' => round($event->amount, $decimalPlaces),
|
||||
'currency_id' => $currency->id,
|
||||
'currency_code' => $currency->code,
|
||||
|
||||
@@ -102,8 +102,8 @@ class PiggyBankTransformer extends TransformerAbstract
|
||||
$percentage = (int)(0 !== bccomp('0', $currentAmountStr) ? $currentAmount / $targetAmount * 100 : 0);
|
||||
$data = [
|
||||
'id' => (int)$piggyBank->id,
|
||||
'updated_at' => $piggyBank->updated_at->toAtomString(),
|
||||
'created_at' => $piggyBank->created_at->toAtomString(),
|
||||
'updated_at' => $piggyBank->updated_at->toAtomString(),
|
||||
'name' => $piggyBank->name,
|
||||
'currency_id' => $currency->id,
|
||||
'currency_code' => $currency->code,
|
||||
|
||||
@@ -57,8 +57,8 @@ class PreferenceTransformer extends TransformerAbstract
|
||||
{
|
||||
return [
|
||||
'id' => (int)$preference->id,
|
||||
'updated_at' => $preference->updated_at->toAtomString(),
|
||||
'created_at' => $preference->created_at->toAtomString(),
|
||||
'updated_at' => $preference->updated_at->toAtomString(),
|
||||
'name' => $preference->name,
|
||||
'data' => $preference->data,
|
||||
];
|
||||
|
||||
@@ -36,7 +36,6 @@ use FireflyIII\Repositories\Bill\BillRepositoryInterface;
|
||||
use FireflyIII\Repositories\Budget\BudgetRepositoryInterface;
|
||||
use FireflyIII\Repositories\PiggyBank\PiggyBankRepositoryInterface;
|
||||
use FireflyIII\Repositories\Recurring\RecurringRepositoryInterface;
|
||||
use League\Fractal\Resource\Item;
|
||||
use League\Fractal\TransformerAbstract;
|
||||
use Symfony\Component\HttpFoundation\ParameterBag;
|
||||
|
||||
@@ -78,8 +77,8 @@ class RecurrenceTransformer extends TransformerAbstract
|
||||
// basic data.
|
||||
$return = [
|
||||
'id' => (int)$recurrence->id,
|
||||
'updated_at' => $recurrence->updated_at->toAtomString(),
|
||||
'created_at' => $recurrence->created_at->toAtomString(),
|
||||
'updated_at' => $recurrence->updated_at->toAtomString(),
|
||||
'transaction_type_id' => $recurrence->transaction_type_id,
|
||||
'transaction_type' => $recurrence->transactionType->type,
|
||||
'title' => $recurrence->title,
|
||||
@@ -172,15 +171,15 @@ class RecurrenceTransformer extends TransformerAbstract
|
||||
/** @var RecurrenceRepetition $repetition */
|
||||
foreach ($recurrence->recurrenceRepetitions as $repetition) {
|
||||
$repetitionArray = [
|
||||
'id' => $repetition->id,
|
||||
'updated_at' => $repetition->updated_at->toAtomString(),
|
||||
'created_at' => $repetition->created_at->toAtomString(),
|
||||
'repetition_type' => $repetition->repetition_type,
|
||||
'repetition_moment' => $repetition->repetition_moment,
|
||||
'repetition_skip' => (int)$repetition->repetition_skip,
|
||||
'weekend' => (int)$repetition->weekend,
|
||||
'description' => $this->repository->repetitionDescription($repetition),
|
||||
'occurrences' => [],
|
||||
'id' => $repetition->id,
|
||||
'created_at' => $repetition->created_at->toAtomString(),
|
||||
'updated_at' => $repetition->updated_at->toAtomString(),
|
||||
'type' => $repetition->repetition_type,
|
||||
'moment' => $repetition->repetition_moment,
|
||||
'skip' => (int)$repetition->repetition_skip,
|
||||
'weekend' => (int)$repetition->weekend,
|
||||
'description' => $this->repository->repetitionDescription($repetition),
|
||||
'occurrences' => [],
|
||||
];
|
||||
|
||||
// get the (future) occurrences for this specific type of repetition:
|
||||
@@ -255,22 +254,38 @@ class RecurrenceTransformer extends TransformerAbstract
|
||||
/** @var RecurrenceTransaction $transaction */
|
||||
foreach ($recurrence->recurrenceTransactions as $transaction) {
|
||||
|
||||
$sourceAccount = $transaction->sourceAccount;
|
||||
$destinationAccount = $transaction->destinationAccount;
|
||||
$transactionArray = [
|
||||
'currency_id' => $transaction->transaction_currency_id,
|
||||
'currency_code' => $transaction->transactionCurrency->code,
|
||||
'currency_symbol' => $transaction->transactionCurrency->symbol,
|
||||
'currency_dp' => $transaction->transactionCurrency->decimal_places,
|
||||
'foreign_currency_id' => $transaction->foreign_currency_id,
|
||||
'source_id' => $transaction->source_id,
|
||||
'source_name' => null === $sourceAccount ? '' : $sourceAccount->name,
|
||||
'destination_id' => $transaction->destination_id,
|
||||
'destination_name' => null === $destinationAccount ? '' : $destinationAccount->name,
|
||||
'amount' => $transaction->amount,
|
||||
'foreign_amount' => $transaction->foreign_amount,
|
||||
'description' => $transaction->description,
|
||||
'meta' => $this->getTransactionMeta($transaction),
|
||||
$sourceAccount = $transaction->sourceAccount;
|
||||
$destinationAccount = $transaction->destinationAccount;
|
||||
$foreignCurrencyCode = null;
|
||||
$foreignCurrencySymbol = null;
|
||||
$foreignCurrencyDp = null;
|
||||
if (null !== $transaction->foreign_currency_id) {
|
||||
$foreignCurrencyCode = $transaction->foreignCurrency->code;
|
||||
$foreignCurrencySymbol = $transaction->foreignCurrency->symbol;
|
||||
$foreignCurrencyDp = $transaction->foreignCurrency->decimal_places;
|
||||
}
|
||||
$amount = round($transaction->amount, $transaction->transactionCurrency->decimal_places);
|
||||
$foreignAmount = null;
|
||||
if (null !== $transaction->foreign_currency_id && null !== $transaction->foreign_amount) {
|
||||
$foreignAmount = round($transaction->foreign_amount, $foreignCurrencyDp);
|
||||
}
|
||||
$transactionArray = [
|
||||
'currency_id' => $transaction->transaction_currency_id,
|
||||
'currency_code' => $transaction->transactionCurrency->code,
|
||||
'currency_symbol' => $transaction->transactionCurrency->symbol,
|
||||
'currency_dp' => $transaction->transactionCurrency->decimal_places,
|
||||
'foreign_currency_id' => $transaction->foreign_currency_id,
|
||||
'foreign_currency_code' => $foreignCurrencyCode,
|
||||
'foreign_currency_symbol' => $foreignCurrencySymbol,
|
||||
'foreign_currency_dp' => $foreignCurrencyDp,
|
||||
'source_id' => $transaction->source_id,
|
||||
'source_name' => null === $sourceAccount ? '' : $sourceAccount->name,
|
||||
'destination_id' => $transaction->destination_id,
|
||||
'destination_name' => null === $destinationAccount ? '' : $destinationAccount->name,
|
||||
'amount' => $amount,
|
||||
'foreign_amount' => $foreignAmount,
|
||||
'description' => $transaction->description,
|
||||
'meta' => $this->getTransactionMeta($transaction),
|
||||
];
|
||||
if (null !== $transaction->foreign_currency_id) {
|
||||
$transactionArray['foreign_currency_code'] = $transaction->foreignCurrency->code;
|
||||
|
||||
@@ -60,10 +60,10 @@ class RuleActionTransformer extends TransformerAbstract
|
||||
{
|
||||
$data = [
|
||||
'id' => (int)$ruleAction->id,
|
||||
'updated_at' => $ruleAction->updated_at->toAtomString(),
|
||||
'created_at' => $ruleAction->created_at->toAtomString(),
|
||||
'action_type' => $ruleAction->action_type,
|
||||
'action_value' => $ruleAction->action_value,
|
||||
'updated_at' => $ruleAction->updated_at->toAtomString(),
|
||||
'type' => $ruleAction->action_type,
|
||||
'value' => $ruleAction->action_value,
|
||||
'order' => $ruleAction->order,
|
||||
'active' => $ruleAction->active,
|
||||
'stop_processing' => $ruleAction->stop_processing,
|
||||
|
||||
@@ -58,8 +58,8 @@ class RuleGroupTransformer extends TransformerAbstract
|
||||
{
|
||||
$data = [
|
||||
'id' => (int)$ruleGroup->id,
|
||||
'updated_at' => $ruleGroup->updated_at->toAtomString(),
|
||||
'created_at' => $ruleGroup->created_at->toAtomString(),
|
||||
'updated_at' => $ruleGroup->updated_at->toAtomString(),
|
||||
'title' => $ruleGroup->title,
|
||||
'description' => $ruleGroup->description,
|
||||
'order' => $ruleGroup->order,
|
||||
|
||||
@@ -61,14 +61,15 @@ class RuleTransformer extends TransformerAbstract
|
||||
{
|
||||
$data = [
|
||||
'id' => (int)$rule->id,
|
||||
'updated_at' => $rule->updated_at->toAtomString(),
|
||||
'created_at' => $rule->created_at->toAtomString(),
|
||||
'updated_at' => $rule->updated_at->toAtomString(),
|
||||
'rule_group_id' => (int)$rule->rule_group_id,
|
||||
'title' => $rule->title,
|
||||
'description' => $rule->text,
|
||||
'description' => $rule->description,
|
||||
'order' => (int)$rule->order,
|
||||
'active' => $rule->active,
|
||||
'stop_processing' => $rule->stop_processing,
|
||||
'strict' => $rule->strict,
|
||||
'stop_processing' => $rule->stop_processing,
|
||||
'triggers' => $this->triggers($rule),
|
||||
'actions' => $this->actions($rule),
|
||||
'links' => [
|
||||
@@ -95,8 +96,8 @@ class RuleTransformer extends TransformerAbstract
|
||||
foreach ($actions as $ruleAction) {
|
||||
$result[] = [
|
||||
'id' => (int)$ruleAction->id,
|
||||
'updated_at' => $ruleAction->updated_at->toAtomString(),
|
||||
'created_at' => $ruleAction->created_at->toAtomString(),
|
||||
'updated_at' => $ruleAction->updated_at->toAtomString(),
|
||||
'type' => $ruleAction->action_type,
|
||||
'value' => $ruleAction->action_value,
|
||||
'order' => $ruleAction->order,
|
||||
@@ -121,8 +122,8 @@ class RuleTransformer extends TransformerAbstract
|
||||
foreach ($triggers as $ruleTrigger) {
|
||||
$result[] = [
|
||||
'id' => (int)$ruleTrigger->id,
|
||||
'updated_at' => $ruleTrigger->updated_at->toAtomString(),
|
||||
'created_at' => $ruleTrigger->created_at->toAtomString(),
|
||||
'updated_at' => $ruleTrigger->updated_at->toAtomString(),
|
||||
'type' => $ruleTrigger->trigger_type,
|
||||
'value' => $ruleTrigger->trigger_value,
|
||||
'order' => $ruleTrigger->order,
|
||||
|
||||
@@ -59,10 +59,10 @@ class RuleTriggerTransformer extends TransformerAbstract
|
||||
{
|
||||
$data = [
|
||||
'id' => (int)$ruleTrigger->id,
|
||||
'updated_at' => $ruleTrigger->updated_at->toAtomString(),
|
||||
'created_at' => $ruleTrigger->created_at->toAtomString(),
|
||||
'trigger_type' => $ruleTrigger->trigger_type,
|
||||
'trigger_value' => $ruleTrigger->trigger_value,
|
||||
'updated_at' => $ruleTrigger->updated_at->toAtomString(),
|
||||
'type' => $ruleTrigger->trigger_type,
|
||||
'value' => $ruleTrigger->trigger_value,
|
||||
'order' => $ruleTrigger->order,
|
||||
'active' => $ruleTrigger->active,
|
||||
'stop_processing' => $ruleTrigger->stop_processing,
|
||||
|
||||
@@ -66,8 +66,8 @@ class TagTransformer extends TransformerAbstract
|
||||
$date = 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(),
|
||||
'updated_at' => $tag->updated_at->toAtomString(),
|
||||
'tag' => $tag->tag,
|
||||
'date' => $date,
|
||||
'description' => '' === $tag->description ? null : $tag->description,
|
||||
|
||||
@@ -85,8 +85,8 @@ class TransactionTransformer extends TransformerAbstract
|
||||
|
||||
$data = [
|
||||
'id' => (int)$transaction->id,
|
||||
'updated_at' => $transaction->updated_at->toAtomString(),
|
||||
'created_at' => $transaction->created_at->toAtomString(),
|
||||
'updated_at' => $transaction->updated_at->toAtomString(),
|
||||
'description' => $transaction->description,
|
||||
'transaction_description' => $transaction->transaction_description,
|
||||
'date' => $transaction->date->format('Y-m-d'),
|
||||
|
||||
@@ -66,8 +66,8 @@ class UserTransformer extends TransformerAbstract
|
||||
|
||||
return [
|
||||
'id' => (int)$user->id,
|
||||
'updated_at' => $user->updated_at->toAtomString(),
|
||||
'created_at' => $user->created_at->toAtomString(),
|
||||
'updated_at' => $user->updated_at->toAtomString(),
|
||||
'email' => $user->email,
|
||||
'blocked' => 1 === (int)$user->blocked,
|
||||
'blocked_code' => '' === $user->blocked_code ? null : $user->blocked_code,
|
||||
|
||||
Reference in New Issue
Block a user