mirror of
https://github.com/firefly-iii/firefly-iii.git
synced 2025-10-18 10:16:49 +00:00
Migrated all code to group collector.
This commit is contained in:
@@ -25,12 +25,10 @@ namespace FireflyIII\Support\Http\Controllers;
|
||||
|
||||
use Carbon\Carbon;
|
||||
use FireflyIII\Helpers\Collector\GroupCollectorInterface;
|
||||
use FireflyIII\Helpers\Collector\TransactionCollectorInterface;
|
||||
use FireflyIII\Models\Account;
|
||||
use FireflyIII\Models\AccountType;
|
||||
use FireflyIII\Models\Budget;
|
||||
use FireflyIII\Models\BudgetLimit;
|
||||
use FireflyIII\Models\Transaction;
|
||||
use FireflyIII\Models\TransactionType;
|
||||
use FireflyIII\Repositories\Account\AccountRepositoryInterface;
|
||||
use FireflyIII\Repositories\Budget\BudgetRepositoryInterface;
|
||||
@@ -86,22 +84,19 @@ trait AugumentData
|
||||
*/
|
||||
protected function earnedByCategory(Collection $assets, Collection $opposing, Carbon $start, Carbon $end): array // get data + augment with info
|
||||
{
|
||||
/** @var TransactionCollectorInterface $collector */
|
||||
$collector = app(TransactionCollectorInterface::class);
|
||||
$collector->setRange($start, $end)->setTypes([TransactionType::DEPOSIT])->setAccounts($assets);
|
||||
$collector->setOpposingAccounts($opposing)->withCategoryInformation();
|
||||
$set = $collector->getTransactions();
|
||||
$sum = [];
|
||||
/** @var GroupCollectorInterface $collector */
|
||||
$collector = app(GroupCollectorInterface::class);
|
||||
|
||||
$total = $assets->merge($opposing);
|
||||
$collector->setRange($start, $end)->setTypes([TransactionType::DEPOSIT])->setAccounts($total);
|
||||
$collector->withCategoryInformation();
|
||||
$journals = $collector->getExtractedJournals();
|
||||
$sum = [];
|
||||
// loop to support multi currency
|
||||
foreach ($set as $transaction) {
|
||||
$currencyId = $transaction->transaction_currency_id;
|
||||
$categoryName = $transaction->transaction_category_name;
|
||||
$categoryId = (int)$transaction->transaction_category_id;
|
||||
// if null, grab from journal:
|
||||
if (0 === $categoryId) {
|
||||
$categoryName = $transaction->transaction_journal_category_name;
|
||||
$categoryId = (int)$transaction->transaction_journal_category_id;
|
||||
}
|
||||
foreach ($journals as $journal) {
|
||||
$currencyId = $journal['currency_id'];
|
||||
$categoryName = $journal['category_name'];
|
||||
$categoryId = (int)$journal['category_id'];
|
||||
|
||||
// if not set, set to zero:
|
||||
if (!isset($sum[$categoryId][$currencyId])) {
|
||||
@@ -116,8 +111,8 @@ trait AugumentData
|
||||
'name' => $categoryName,
|
||||
],
|
||||
'currency' => [
|
||||
'symbol' => $transaction->transaction_currency_symbol,
|
||||
'dp' => $transaction->transaction_currency_dp,
|
||||
'symbol' => $journal['currency_symbol'],
|
||||
'dp' => $journal['currency_decimal_places'],
|
||||
],
|
||||
],
|
||||
],
|
||||
@@ -126,9 +121,9 @@ trait AugumentData
|
||||
|
||||
// add amount
|
||||
$sum[$categoryId]['per_currency'][$currencyId]['sum'] = bcadd(
|
||||
$sum[$categoryId]['per_currency'][$currencyId]['sum'], $transaction->transaction_amount
|
||||
$sum[$categoryId]['per_currency'][$currencyId]['sum'], $journal['amount']
|
||||
);
|
||||
$sum[$categoryId]['grand_total'] = bcadd($sum[$categoryId]['grand_total'], $transaction->transaction_amount);
|
||||
$sum[$categoryId]['grand_total'] = bcadd($sum[$categoryId]['grand_total'], $journal['amount']);
|
||||
}
|
||||
|
||||
return $sum;
|
||||
@@ -146,33 +141,34 @@ trait AugumentData
|
||||
*/
|
||||
protected function earnedInPeriod(Collection $assets, Collection $opposing, Carbon $start, Carbon $end): array // get data + augment with info
|
||||
{
|
||||
/** @var TransactionCollectorInterface $collector */
|
||||
$collector = app(TransactionCollectorInterface::class);
|
||||
$collector->setRange($start, $end)->setTypes([TransactionType::DEPOSIT])->setAccounts($assets);
|
||||
$collector->setOpposingAccounts($opposing);
|
||||
$set = $collector->getTransactions();
|
||||
$sum = [
|
||||
/** @var GroupCollectorInterface $collector */
|
||||
$collector = app(GroupCollectorInterface::class);
|
||||
|
||||
$total = $assets->merge($opposing);
|
||||
$collector->setRange($start, $end)->setTypes([TransactionType::DEPOSIT])->setAccounts($total);
|
||||
$journals = $collector->getExtractedJournals();
|
||||
$sum = [
|
||||
'grand_sum' => '0',
|
||||
'per_currency' => [],
|
||||
];
|
||||
// loop to support multi currency
|
||||
foreach ($set as $transaction) {
|
||||
$currencyId = $transaction->transaction_currency_id;
|
||||
foreach ($journals as $journal) {
|
||||
$currencyId = (int)$journal['currency_id'];
|
||||
|
||||
// if not set, set to zero:
|
||||
if (!isset($sum['per_currency'][$currencyId])) {
|
||||
$sum['per_currency'][$currencyId] = [
|
||||
'sum' => '0',
|
||||
'currency' => [
|
||||
'symbol' => $transaction->transaction_currency_symbol,
|
||||
'dp' => $transaction->transaction_currency_dp,
|
||||
'symbol' => $journal['currency_symbol'],
|
||||
'decimal_places' => $journal['currency_decimal_places'],
|
||||
],
|
||||
];
|
||||
}
|
||||
|
||||
// add amount
|
||||
$sum['per_currency'][$currencyId]['sum'] = bcadd($sum['per_currency'][$currencyId]['sum'], $transaction->transaction_amount);
|
||||
$sum['grand_sum'] = bcadd($sum['grand_sum'], $transaction->transaction_amount);
|
||||
$sum['per_currency'][$currencyId]['sum'] = bcadd($sum['per_currency'][$currencyId]['sum'], $journal['amount']);
|
||||
$sum['grand_sum'] = bcadd($sum['grand_sum'], $journal['amount']);
|
||||
}
|
||||
|
||||
return $sum;
|
||||
@@ -525,19 +521,27 @@ trait AugumentData
|
||||
/**
|
||||
* Group set of transactions by name of opposing account.
|
||||
*
|
||||
* @param Collection $set
|
||||
* @param array $array
|
||||
*
|
||||
* @return array
|
||||
*/
|
||||
protected function groupByName(Collection $set): array // filter + group data
|
||||
protected function groupByName(array $array): array // filter + group data
|
||||
{
|
||||
|
||||
// group by opposing account name.
|
||||
$grouped = [];
|
||||
/** @var Transaction $transaction */
|
||||
foreach ($set as $transaction) {
|
||||
$name = $transaction->opposing_account_name;
|
||||
/** @var array $journal */
|
||||
foreach ($array as $journal) {
|
||||
$name = '(no name)';
|
||||
if (TransactionType::WITHDRAWAL === $journal['transaction_type_type']) {
|
||||
$name = $journal['destination_account_name'];
|
||||
}
|
||||
if (TransactionType::WITHDRAWAL !== $journal['transaction_type_type']) {
|
||||
$name = $journal['source_account_name'];
|
||||
}
|
||||
|
||||
$grouped[$name] = $grouped[$name] ?? '0';
|
||||
$grouped[$name] = bcadd($transaction->transaction_amount, $grouped[$name]);
|
||||
$grouped[$name] = bcadd($journal['amount'], $grouped[$name]);
|
||||
}
|
||||
|
||||
return $grouped;
|
||||
@@ -587,22 +591,18 @@ trait AugumentData
|
||||
*/
|
||||
protected function spentByBudget(Collection $assets, Collection $opposing, Carbon $start, Carbon $end): array // get data + augment with info
|
||||
{
|
||||
/** @var TransactionCollectorInterface $collector */
|
||||
$collector = app(TransactionCollectorInterface::class);
|
||||
$collector->setRange($start, $end)->setTypes([TransactionType::WITHDRAWAL])->setAccounts($assets);
|
||||
$collector->setOpposingAccounts($opposing)->withBudgetInformation();
|
||||
$set = $collector->getTransactions();
|
||||
$sum = [];
|
||||
/** @var GroupCollectorInterface $collector */
|
||||
$collector = app(GroupCollectorInterface::class);
|
||||
$total = $assets->merge($opposing);
|
||||
$collector->setRange($start, $end)->setTypes([TransactionType::WITHDRAWAL])->setAccounts($total);
|
||||
$collector->withBudgetInformation();
|
||||
$journals = $collector->getExtractedJournals();
|
||||
$sum = [];
|
||||
// loop to support multi currency
|
||||
foreach ($set as $transaction) {
|
||||
$currencyId = $transaction->transaction_currency_id;
|
||||
$budgetName = $transaction->transaction_budget_name;
|
||||
$budgetId = (int)$transaction->transaction_budget_id;
|
||||
// if null, grab from journal:
|
||||
if (0 === $budgetId) {
|
||||
$budgetName = $transaction->transaction_journal_budget_name;
|
||||
$budgetId = (int)$transaction->transaction_journal_budget_id;
|
||||
}
|
||||
foreach ($journals as $journal) {
|
||||
$currencyId = $journal['currency_id'];
|
||||
$budgetName = $journal['budget_name'];
|
||||
$budgetId = (int)$journal['budget_id'];
|
||||
|
||||
// if not set, set to zero:
|
||||
if (!isset($sum[$budgetId][$currencyId])) {
|
||||
@@ -617,8 +617,8 @@ trait AugumentData
|
||||
'name' => $budgetName,
|
||||
],
|
||||
'currency' => [
|
||||
'symbol' => $transaction->transaction_currency_symbol,
|
||||
'dp' => $transaction->transaction_currency_dp,
|
||||
'symbol' => $journal['currency_symbol'],
|
||||
'dp' => $journal['currency_decimal_places'],
|
||||
],
|
||||
],
|
||||
],
|
||||
@@ -627,9 +627,9 @@ trait AugumentData
|
||||
|
||||
// add amount
|
||||
$sum[$budgetId]['per_currency'][$currencyId]['sum'] = bcadd(
|
||||
$sum[$budgetId]['per_currency'][$currencyId]['sum'], $transaction->transaction_amount
|
||||
$sum[$budgetId]['per_currency'][$currencyId]['sum'], $journal['amount']
|
||||
);
|
||||
$sum[$budgetId]['grand_total'] = bcadd($sum[$budgetId]['grand_total'], $transaction->transaction_amount);
|
||||
$sum[$budgetId]['grand_total'] = bcadd($sum[$budgetId]['grand_total'], $journal['amount']);
|
||||
}
|
||||
|
||||
return $sum;
|
||||
@@ -652,22 +652,18 @@ trait AugumentData
|
||||
*/
|
||||
protected function spentByCategory(Collection $assets, Collection $opposing, Carbon $start, Carbon $end): array // get data + augment with info
|
||||
{
|
||||
/** @var TransactionCollectorInterface $collector */
|
||||
$collector = app(TransactionCollectorInterface::class);
|
||||
$collector->setRange($start, $end)->setTypes([TransactionType::WITHDRAWAL])->setAccounts($assets);
|
||||
$collector->setOpposingAccounts($opposing)->withCategoryInformation();
|
||||
$set = $collector->getTransactions();
|
||||
$sum = [];
|
||||
/** @var GroupCollectorInterface $collector */
|
||||
$collector = app(GroupCollectorInterface::class);
|
||||
$total = $assets->merge($opposing);
|
||||
$collector->setRange($start, $end)->setTypes([TransactionType::WITHDRAWAL])->setAccounts($total);
|
||||
$collector->withCategoryInformation();
|
||||
$journals = $collector->getExtractedJournals();
|
||||
$sum = [];
|
||||
// loop to support multi currency
|
||||
foreach ($set as $transaction) {
|
||||
$currencyId = $transaction->transaction_currency_id;
|
||||
$categoryName = $transaction->transaction_category_name;
|
||||
$categoryId = (int)$transaction->transaction_category_id;
|
||||
// if null, grab from journal:
|
||||
if (0 === $categoryId) {
|
||||
$categoryName = $transaction->transaction_journal_category_name;
|
||||
$categoryId = (int)$transaction->transaction_journal_category_id;
|
||||
}
|
||||
foreach ($journals as $journal) {
|
||||
$currencyId = (int)$journal['currency_id'];
|
||||
$categoryName = $journal['category_name'];
|
||||
$categoryId = (int)$journal['category_id'];
|
||||
|
||||
// if not set, set to zero:
|
||||
if (!isset($sum[$categoryId][$currencyId])) {
|
||||
@@ -682,8 +678,8 @@ trait AugumentData
|
||||
'name' => $categoryName,
|
||||
],
|
||||
'currency' => [
|
||||
'symbol' => $transaction->transaction_currency_symbol,
|
||||
'dp' => $transaction->transaction_currency_dp,
|
||||
'symbol' => $journal['currency_symbol'],
|
||||
'dp' => $journal['currency_decimal_places'],
|
||||
],
|
||||
],
|
||||
],
|
||||
@@ -692,9 +688,9 @@ trait AugumentData
|
||||
|
||||
// add amount
|
||||
$sum[$categoryId]['per_currency'][$currencyId]['sum'] = bcadd(
|
||||
$sum[$categoryId]['per_currency'][$currencyId]['sum'], $transaction->transaction_amount
|
||||
$sum[$categoryId]['per_currency'][$currencyId]['sum'], $journal['amount']
|
||||
);
|
||||
$sum[$categoryId]['grand_total'] = bcadd($sum[$categoryId]['grand_total'], $transaction->transaction_amount);
|
||||
$sum[$categoryId]['grand_total'] = bcadd($sum[$categoryId]['grand_total'], $journal['amount']);
|
||||
}
|
||||
|
||||
return $sum;
|
||||
@@ -714,33 +710,35 @@ trait AugumentData
|
||||
*/
|
||||
protected function spentInPeriod(Collection $assets, Collection $opposing, Carbon $start, Carbon $end): array // get data + augment with info
|
||||
{
|
||||
/** @var TransactionCollectorInterface $collector */
|
||||
$collector = app(TransactionCollectorInterface::class);
|
||||
$collector->setRange($start, $end)->setTypes([TransactionType::WITHDRAWAL])->setAccounts($assets);
|
||||
$collector->setOpposingAccounts($opposing);
|
||||
$set = $collector->getTransactions();
|
||||
$sum = [
|
||||
/** @var GroupCollectorInterface $collector */
|
||||
$collector = app(GroupCollectorInterface::class);
|
||||
|
||||
$total = $assets->merge($opposing);
|
||||
$collector->setRange($start, $end)->setTypes([TransactionType::WITHDRAWAL])->setAccounts($total);
|
||||
$journals = $collector->getExtractedJournals();
|
||||
$sum = [
|
||||
'grand_sum' => '0',
|
||||
'per_currency' => [],
|
||||
];
|
||||
// loop to support multi currency
|
||||
foreach ($set as $transaction) {
|
||||
$currencyId = (int)$transaction->transaction_currency_id;
|
||||
foreach ($journals as $journal) {
|
||||
$currencyId = (int)$journal['currency_id'];
|
||||
|
||||
// if not set, set to zero:
|
||||
if (!isset($sum['per_currency'][$currencyId])) {
|
||||
$sum['per_currency'][$currencyId] = [
|
||||
'sum' => '0',
|
||||
'currency' => [
|
||||
'symbol' => $transaction->transaction_currency_symbol,
|
||||
'dp' => $transaction->transaction_currency_dp,
|
||||
'name' => $journal['currency_name'],
|
||||
'symbol' => $journal['currency_symbol'],
|
||||
'decimal_places' => $journal['currency_decimal_places'],
|
||||
],
|
||||
];
|
||||
}
|
||||
|
||||
// add amount
|
||||
$sum['per_currency'][$currencyId]['sum'] = bcadd($sum['per_currency'][$currencyId]['sum'], $transaction->transaction_amount);
|
||||
$sum['grand_sum'] = bcadd($sum['grand_sum'], $transaction->transaction_amount);
|
||||
$sum['per_currency'][$currencyId]['sum'] = bcadd($sum['per_currency'][$currencyId]['sum'], $journal['amount']);
|
||||
$sum['grand_sum'] = bcadd($sum['grand_sum'], $journal['amount']);
|
||||
}
|
||||
|
||||
return $sum;
|
||||
@@ -767,6 +765,7 @@ trait AugumentData
|
||||
$collector = app(GroupCollectorInterface::class);
|
||||
$types = [TransactionType::WITHDRAWAL];
|
||||
$collector->setTypes($types)->setRange($start, $end)->withoutBudget();
|
||||
|
||||
return $collector->getSum();
|
||||
}
|
||||
}
|
||||
|
@@ -24,11 +24,8 @@ declare(strict_types=1);
|
||||
namespace FireflyIII\Support\Http\Controllers;
|
||||
|
||||
use Carbon\Carbon;
|
||||
use FireflyIII\Exceptions\FireflyException;
|
||||
use FireflyIII\Helpers\Collector\GroupCollectorInterface;
|
||||
use FireflyIII\Helpers\Collector\GroupSumCollectorInterface;
|
||||
use FireflyIII\Helpers\Collector\TransactionCollectorInterface;
|
||||
use FireflyIII\Helpers\Filter\InternalTransferFilter;
|
||||
use FireflyIII\Models\Account;
|
||||
use FireflyIII\Models\Category;
|
||||
use FireflyIII\Models\Tag;
|
||||
|
@@ -24,29 +24,18 @@ declare(strict_types=1);
|
||||
namespace FireflyIII\Support\Http\Controllers;
|
||||
|
||||
use Carbon\Carbon;
|
||||
use FireflyIII\Exceptions\FireflyException;
|
||||
use FireflyIII\Exceptions\ValidationException;
|
||||
use FireflyIII\Helpers\Collector\TransactionCollectorInterface;
|
||||
use FireflyIII\Helpers\Help\HelpInterface;
|
||||
use FireflyIII\Http\Requests\SplitJournalFormRequest;
|
||||
use FireflyIII\Http\Requests\TestRuleFormRequest;
|
||||
use FireflyIII\Models\Transaction;
|
||||
use FireflyIII\Models\TransactionJournal;
|
||||
use FireflyIII\Models\TransactionType;
|
||||
use FireflyIII\Repositories\Journal\JournalRepositoryInterface;
|
||||
use FireflyIII\Support\Binder\AccountList;
|
||||
use FireflyIII\Transformers\TransactionTransformer;
|
||||
use FireflyIII\User;
|
||||
use Hash;
|
||||
use Illuminate\Contracts\Validation\Validator as ValidatorContract;
|
||||
use Illuminate\Http\Request;
|
||||
use Illuminate\Routing\Route;
|
||||
use Illuminate\Support\Collection;
|
||||
use Illuminate\Support\Facades\Validator;
|
||||
use InvalidArgumentException;
|
||||
use Log;
|
||||
use Route as RouteFacade;
|
||||
use Symfony\Component\HttpFoundation\ParameterBag;
|
||||
|
||||
/**
|
||||
* Trait RequestInformation
|
||||
@@ -54,138 +43,7 @@ use Symfony\Component\HttpFoundation\ParameterBag;
|
||||
*/
|
||||
trait RequestInformation
|
||||
{
|
||||
/**
|
||||
* Create data-array from a journal.
|
||||
*
|
||||
* @param SplitJournalFormRequest|Request $request
|
||||
* @param TransactionJournal $journal
|
||||
*
|
||||
* @return array
|
||||
* @throws FireflyException
|
||||
*/
|
||||
protected function arrayFromJournal(Request $request, TransactionJournal $journal): array // convert user input.
|
||||
{
|
||||
/** @var JournalRepositoryInterface $repository */
|
||||
$repository = app(JournalRepositoryInterface::class);
|
||||
$sourceAccounts = $repository->getJournalSourceAccounts($journal);
|
||||
$destinationAccounts = $repository->getJournalDestinationAccounts($journal);
|
||||
$array = [
|
||||
'journal_description' => $request->old('journal_description', $journal->description),
|
||||
'journal_amount' => '0',
|
||||
'journal_foreign_amount' => '0',
|
||||
'sourceAccounts' => $sourceAccounts,
|
||||
'journal_source_id' => $request->old('journal_source_id', $sourceAccounts->first()->id),
|
||||
'journal_source_name' => $request->old('journal_source_name', $sourceAccounts->first()->name),
|
||||
'journal_destination_id' => $request->old('journal_destination_id', $destinationAccounts->first()->id),
|
||||
'destinationAccounts' => $destinationAccounts,
|
||||
'what' => strtolower($this->repository->getTransactionType($journal)),
|
||||
'date' => $request->old('date', $this->repository->getJournalDate($journal, null)),
|
||||
'tags' => implode(',', $journal->tags->pluck('tag')->toArray()),
|
||||
|
||||
// all custom fields:
|
||||
'interest_date' => $request->old('interest_date', $repository->getMetaField($journal, 'interest_date')),
|
||||
'book_date' => $request->old('book_date', $repository->getMetaField($journal, 'book_date')),
|
||||
'process_date' => $request->old('process_date', $repository->getMetaField($journal, 'process_date')),
|
||||
'due_date' => $request->old('due_date', $repository->getMetaField($journal, 'due_date')),
|
||||
'payment_date' => $request->old('payment_date', $repository->getMetaField($journal, 'payment_date')),
|
||||
'invoice_date' => $request->old('invoice_date', $repository->getMetaField($journal, 'invoice_date')),
|
||||
'internal_reference' => $request->old('internal_reference', $repository->getMetaField($journal, 'internal_reference')),
|
||||
'notes' => $request->old('notes', $repository->getNoteText($journal)),
|
||||
|
||||
// transactions.
|
||||
'transactions' => $this->getTransactionDataFromJournal($journal),
|
||||
];
|
||||
// update transactions array with old request data.
|
||||
$array['transactions'] = $this->updateWithPrevious($array['transactions'], $request->old());
|
||||
|
||||
// update journal amount and foreign amount:
|
||||
$array['journal_amount'] = array_sum(array_column($array['transactions'], 'amount'));
|
||||
$array['journal_foreign_amount'] = array_sum(array_column($array['transactions'], 'foreign_amount'));
|
||||
|
||||
return $array;
|
||||
}
|
||||
|
||||
/**
|
||||
* Get transaction overview from journal.
|
||||
*
|
||||
* @param TransactionJournal $journal
|
||||
*
|
||||
* @return array
|
||||
* @throws FireflyException
|
||||
*
|
||||
* @SuppressWarnings(PHPMD.CyclomaticComplexity)
|
||||
*/
|
||||
protected function getTransactionDataFromJournal(TransactionJournal $journal): array // convert object
|
||||
{
|
||||
// use collector to collect transactions.
|
||||
$collector = app(TransactionCollectorInterface::class);
|
||||
$collector->setUser(auth()->user());
|
||||
$collector->withOpposingAccount()->withCategoryInformation()->withBudgetInformation();
|
||||
// filter on specific journals.
|
||||
$collector->setJournals(new Collection([$journal]));
|
||||
$set = $collector->getTransactions();
|
||||
$transactions = [];
|
||||
|
||||
/** @var TransactionTransformer $transformer */
|
||||
$transformer = app(TransactionTransformer::class);
|
||||
$transformer->setParameters(new ParameterBag());
|
||||
/** @var Transaction $transaction */
|
||||
foreach ($set as $transaction) {
|
||||
$res = [];
|
||||
if ((float)$transaction->transaction_amount > 0 && $journal->transactionType->type === TransactionType::DEPOSIT) {
|
||||
$res = $transformer->transform($transaction);
|
||||
}
|
||||
if ((float)$transaction->transaction_amount < 0 && $journal->transactionType->type !== TransactionType::DEPOSIT) {
|
||||
$res = $transformer->transform($transaction);
|
||||
}
|
||||
|
||||
if (count($res) > 0) {
|
||||
$res['amount'] = app('steam')->positive((string)$res['amount']);
|
||||
$res['foreign_amount'] = app('steam')->positive((string)$res['foreign_amount']);
|
||||
$transactions[] = $res;
|
||||
}
|
||||
}
|
||||
|
||||
return $transactions;
|
||||
}
|
||||
|
||||
/**
|
||||
* Get info from old input.
|
||||
*
|
||||
* @param $array
|
||||
* @param $old
|
||||
*
|
||||
* @return array
|
||||
*
|
||||
* @SuppressWarnings(PHPMD.ExcessiveMethodLength)
|
||||
* @SuppressWarnings(PHPMD.CyclomaticComplexity)
|
||||
*/
|
||||
protected function updateWithPrevious($array, $old): array // update object with new info
|
||||
{
|
||||
if (0 === count($old) || !isset($old['transactions'])) {
|
||||
return $array;
|
||||
}
|
||||
$old = $old['transactions'];
|
||||
|
||||
foreach ($old as $index => $row) {
|
||||
if (isset($array[$index])) {
|
||||
/** @noinspection SlowArrayOperationsInLoopInspection */
|
||||
$array[$index] = array_merge($array[$index], $row);
|
||||
continue;
|
||||
}
|
||||
// take some info from first transaction, that should at least exist.
|
||||
$array[$index] = $row;
|
||||
$array[$index]['currency_id'] = $array[0]['currency_id'];
|
||||
$array[$index]['currency_code'] = $array[0]['currency_code'] ?? '';
|
||||
$array[$index]['currency_symbol'] = $array[0]['currency_symbol'] ?? '';
|
||||
$array[$index]['foreign_amount'] = round($array[0]['foreign_destination_amount'] ?? '0', 12);
|
||||
$array[$index]['foreign_currency_id'] = $array[0]['foreign_currency_id'];
|
||||
$array[$index]['foreign_currency_code'] = $array[0]['foreign_currency_code'];
|
||||
$array[$index]['foreign_currency_symbol'] = $array[0]['foreign_currency_symbol'];
|
||||
}
|
||||
|
||||
return $array;
|
||||
}
|
||||
|
||||
/**
|
||||
* Get the domain of FF system.
|
||||
|
@@ -46,14 +46,18 @@ trait TransactionCalculation
|
||||
*/
|
||||
protected function getExpensesForOpposing(Collection $accounts, Collection $opposing, Carbon $start, Carbon $end): array
|
||||
{
|
||||
$total = $accounts->merge($opposing);
|
||||
|
||||
/** @var GroupCollectorInterface $collector */
|
||||
$collector = app(GroupCollectorInterface::class);
|
||||
$collector->setAccounts($accounts)
|
||||
$collector->setAccounts($total)
|
||||
->setRange($start, $end)
|
||||
->setTypes([TransactionType::WITHDRAWAL])
|
||||
->setAccounts($opposing);
|
||||
->withAccountInformation()
|
||||
->setTypes([TransactionType::WITHDRAWAL]);
|
||||
|
||||
return $collector->getExtractedJournals();
|
||||
$result = $collector->getExtractedJournals();
|
||||
|
||||
return $result;
|
||||
}
|
||||
|
||||
/**
|
||||
@@ -156,10 +160,10 @@ trait TransactionCalculation
|
||||
*/
|
||||
protected function getIncomeForOpposing(Collection $accounts, Collection $opposing, Carbon $start, Carbon $end): array
|
||||
{
|
||||
$total =$accounts->merge($opposing);
|
||||
/** @var GroupCollectorInterface $collector */
|
||||
$collector = app(GroupCollectorInterface::class);
|
||||
$collector->setAccounts($accounts)->setRange($start, $end)->setTypes([TransactionType::DEPOSIT])
|
||||
->setAccounts($opposing);
|
||||
$collector->setAccounts($total)->setRange($start, $end)->withAccountInformation()->setTypes([TransactionType::DEPOSIT]);
|
||||
|
||||
return $collector->getExtractedJournals();
|
||||
}
|
||||
|
Reference in New Issue
Block a user