mirror of
https://github.com/firefly-iii/firefly-iii.git
synced 2025-10-12 15:35:15 +00:00
Merge remote-tracking branch 'upstream/develop' into feat/expression-engine
This commit is contained in:
@@ -69,6 +69,11 @@ abstract class Controller extends BaseController
|
||||
$authGuard = config('firefly.authentication_guard');
|
||||
$logoutUrl = config('firefly.custom_logout_url');
|
||||
|
||||
// overrule v2 layout back to v1.
|
||||
if ('true' === request()->get('force_default_layout') && 'v2' === config('firefly.layout')) {
|
||||
app('view')->getFinder()->setPaths([realpath(base_path('resources/views'))]); // @phpstan-ignore-line
|
||||
}
|
||||
|
||||
app('view')->share('authGuard', $authGuard);
|
||||
app('view')->share('logoutUrl', $logoutUrl);
|
||||
|
||||
|
@@ -24,6 +24,7 @@ declare(strict_types=1);
|
||||
namespace FireflyIII\Http\Controllers;
|
||||
|
||||
use Carbon\Carbon;
|
||||
use Exception;
|
||||
use FireflyIII\Exceptions\FireflyException;
|
||||
use FireflyIII\Http\Middleware\IsDemoUser;
|
||||
use FireflyIII\Models\AccountType;
|
||||
|
@@ -34,6 +34,7 @@ use FireflyIII\Repositories\Account\AccountRepositoryInterface;
|
||||
use Illuminate\Http\JsonResponse;
|
||||
use Illuminate\Http\Request;
|
||||
use Illuminate\Support\Collection;
|
||||
use Illuminate\Support\Facades\Log;
|
||||
|
||||
/**
|
||||
* Class ReconcileController
|
||||
@@ -73,7 +74,6 @@ class ReconcileController extends Controller
|
||||
$accountCurrency = $this->accountRepos->getAccountCurrency($account) ?? app('amount')->getDefaultCurrency();
|
||||
$amount = '0';
|
||||
$clearedAmount = '0';
|
||||
$route = '';
|
||||
|
||||
if (null === $start && null === $end) {
|
||||
throw new FireflyException('Invalid dates submitted.');
|
||||
@@ -103,14 +103,11 @@ class ReconcileController extends Controller
|
||||
$clearedJournals = $collector->getExtractedJournals();
|
||||
}
|
||||
|
||||
app('log')->debug('Start transaction loop');
|
||||
|
||||
/** @var array $journal */
|
||||
foreach ($journals as $journal) {
|
||||
$amount = $this->processJournal($account, $accountCurrency, $journal, $amount);
|
||||
}
|
||||
app('log')->debug(sprintf('Final amount is %s', $amount));
|
||||
app('log')->debug('End transaction loop');
|
||||
|
||||
/** @var array $journal */
|
||||
foreach ($clearedJournals as $journal) {
|
||||
@@ -118,31 +115,17 @@ class ReconcileController extends Controller
|
||||
$clearedAmount = $this->processJournal($account, $accountCurrency, $journal, $clearedAmount);
|
||||
}
|
||||
}
|
||||
Log::debug(sprintf('Start balance: "%s"', $startBalance));
|
||||
Log::debug(sprintf('End balance: "%s"', $endBalance));
|
||||
Log::debug(sprintf('Cleared amount: "%s"', $clearedAmount));
|
||||
Log::debug(sprintf('Amount: "%s"', $amount));
|
||||
$difference = bcadd(bcadd(bcsub($startBalance, $endBalance), $clearedAmount), $amount);
|
||||
$diffCompare = bccomp($difference, '0');
|
||||
$countCleared = count($clearedJournals);
|
||||
|
||||
$reconSum = bcadd(bcadd($startBalance, $amount), $clearedAmount);
|
||||
|
||||
try {
|
||||
$view = view(
|
||||
'accounts.reconcile.overview',
|
||||
compact(
|
||||
'account',
|
||||
'start',
|
||||
'diffCompare',
|
||||
'difference',
|
||||
'end',
|
||||
'clearedAmount',
|
||||
'startBalance',
|
||||
'endBalance',
|
||||
'amount',
|
||||
'route',
|
||||
'countCleared',
|
||||
'reconSum',
|
||||
'selectedIds'
|
||||
)
|
||||
)->render();
|
||||
$view = view('accounts.reconcile.overview', compact('account', 'start', 'diffCompare', 'difference', 'end', 'clearedAmount', 'startBalance', 'endBalance', 'amount', 'route', 'countCleared', 'reconSum', 'selectedIds'))->render();
|
||||
} catch (\Throwable $e) {
|
||||
app('log')->debug(sprintf('View error: %s', $e->getMessage()));
|
||||
app('log')->error($e->getTraceAsString());
|
||||
@@ -151,14 +134,42 @@ class ReconcileController extends Controller
|
||||
throw new FireflyException($view, 0, $e);
|
||||
}
|
||||
|
||||
$return = [
|
||||
'post_url' => $route,
|
||||
'html' => $view,
|
||||
];
|
||||
$return = ['post_url' => $route, 'html' => $view];
|
||||
|
||||
return response()->json($return);
|
||||
}
|
||||
|
||||
private function processJournal(Account $account, TransactionCurrency $currency, array $journal, string $amount): string
|
||||
{
|
||||
$toAdd = '0';
|
||||
app('log')->debug(sprintf('User submitted %s #%d: "%s"', $journal['transaction_type_type'], $journal['transaction_journal_id'], $journal['description']));
|
||||
|
||||
// not much magic below we need to cover using tests.
|
||||
|
||||
if ($account->id === $journal['source_account_id']) {
|
||||
if ($currency->id === $journal['currency_id']) {
|
||||
$toAdd = $journal['amount'];
|
||||
}
|
||||
if (null !== $journal['foreign_currency_id'] && $journal['foreign_currency_id'] === $currency->id) {
|
||||
$toAdd = $journal['foreign_amount'];
|
||||
}
|
||||
}
|
||||
if ($account->id === $journal['destination_account_id']) {
|
||||
if ($currency->id === $journal['currency_id']) {
|
||||
$toAdd = bcmul($journal['amount'], '-1');
|
||||
}
|
||||
if (null !== $journal['foreign_currency_id'] && $journal['foreign_currency_id'] === $currency->id) {
|
||||
$toAdd = bcmul($journal['foreign_amount'], '-1');
|
||||
}
|
||||
}
|
||||
|
||||
app('log')->debug(sprintf('Going to add %s to %s', $toAdd, $amount));
|
||||
$amount = bcadd($amount, $toAdd);
|
||||
app('log')->debug(sprintf('Result is %s', $amount));
|
||||
|
||||
return $amount;
|
||||
}
|
||||
|
||||
/**
|
||||
* Returns a list of transactions in a modal.
|
||||
*
|
||||
@@ -176,6 +187,7 @@ class ReconcileController extends Controller
|
||||
}
|
||||
$startDate = clone $start;
|
||||
$startDate->subDay();
|
||||
$end->endOfDay();
|
||||
|
||||
$currency = $this->accountRepos->getAccountCurrency($account) ?? app('amount')->getDefaultCurrency();
|
||||
$startBalance = app('steam')->bcround(app('steam')->balance($account, $startDate), $currency->decimal_places);
|
||||
@@ -214,37 +226,6 @@ class ReconcileController extends Controller
|
||||
return response()->json(['html' => $html, 'startBalance' => $startBalance, 'endBalance' => $endBalance]);
|
||||
}
|
||||
|
||||
private function processJournal(Account $account, TransactionCurrency $currency, array $journal, string $amount): string
|
||||
{
|
||||
$toAdd = '0';
|
||||
app('log')->debug(sprintf('User submitted %s #%d: "%s"', $journal['transaction_type_type'], $journal['transaction_journal_id'], $journal['description']));
|
||||
|
||||
// not much magic below we need to cover using tests.
|
||||
|
||||
if ($account->id === $journal['source_account_id']) {
|
||||
if ($currency->id === $journal['currency_id']) {
|
||||
$toAdd = $journal['amount'];
|
||||
}
|
||||
if (null !== $journal['foreign_currency_id'] && $journal['foreign_currency_id'] === $currency->id) {
|
||||
$toAdd = $journal['foreign_amount'];
|
||||
}
|
||||
}
|
||||
if ($account->id === $journal['destination_account_id']) {
|
||||
if ($currency->id === $journal['currency_id']) {
|
||||
$toAdd = bcmul($journal['amount'], '-1');
|
||||
}
|
||||
if (null !== $journal['foreign_currency_id'] && $journal['foreign_currency_id'] === $currency->id) {
|
||||
$toAdd = bcmul($journal['foreign_amount'], '-1');
|
||||
}
|
||||
}
|
||||
|
||||
app('log')->debug(sprintf('Going to add %s to %s', $toAdd, $amount));
|
||||
$amount = bcadd($amount, $toAdd);
|
||||
app('log')->debug(sprintf('Result is %s', $amount));
|
||||
|
||||
return $amount;
|
||||
}
|
||||
|
||||
/**
|
||||
* "fix" amounts to make it easier on the reconciliation overview:
|
||||
*/
|
||||
|
@@ -75,52 +75,45 @@ class IndexController extends Controller
|
||||
$objectType = 'transfer';
|
||||
}
|
||||
|
||||
// add a split for the (future) v2 release.
|
||||
$periods = [];
|
||||
$groups = [];
|
||||
$subTitle = 'TODO page subtitle in v2';
|
||||
$subTitleIcon = config('firefly.transactionIconsByType.'.$objectType);
|
||||
$types = config('firefly.transactionTypesByType.'.$objectType);
|
||||
$page = (int)$request->get('page');
|
||||
$pageSize = (int)app('preferences')->get('listPageSize', 50)->data;
|
||||
|
||||
$subTitleIcon = config('firefly.transactionIconsByType.'.$objectType);
|
||||
$types = config('firefly.transactionTypesByType.'.$objectType);
|
||||
$page = (int)$request->get('page');
|
||||
$pageSize = (int)app('preferences')->get('listPageSize', 50)->data;
|
||||
|
||||
if ('v2' !== (string)config('firefly.layout')) {
|
||||
if (null === $start) {
|
||||
$start = session('start');
|
||||
$end = session('end');
|
||||
}
|
||||
if (null === $end) {
|
||||
// get last transaction ever?
|
||||
$last = $this->repository->getLast();
|
||||
$end = null !== $last ? $last->date : session('end');
|
||||
}
|
||||
|
||||
[$start, $end] = $end < $start ? [$end, $start] : [$start, $end];
|
||||
$startStr = $start->isoFormat($this->monthAndDayFormat);
|
||||
$endStr = $end->isoFormat($this->monthAndDayFormat);
|
||||
$subTitle = (string)trans(sprintf('firefly.title_%s_between', $objectType), ['start' => $startStr, 'end' => $endStr]);
|
||||
$path = route('transactions.index', [$objectType, $start->format('Y-m-d'), $end->format('Y-m-d')]);
|
||||
$firstJournal = $this->repository->firstNull();
|
||||
$startPeriod = null === $firstJournal ? new Carbon() : $firstJournal->date;
|
||||
$endPeriod = clone $end;
|
||||
$periods = $this->getTransactionPeriodOverview($objectType, $startPeriod, $endPeriod);
|
||||
|
||||
/** @var GroupCollectorInterface $collector */
|
||||
$collector = app(GroupCollectorInterface::class);
|
||||
|
||||
$collector->setRange($start, $end)
|
||||
->setTypes($types)
|
||||
->setLimit($pageSize)
|
||||
->setPage($page)
|
||||
->withBudgetInformation()
|
||||
->withCategoryInformation()
|
||||
->withAccountInformation()
|
||||
->withAttachmentInformation()
|
||||
;
|
||||
$groups = $collector->getPaginatedGroups();
|
||||
$groups->setPath($path);
|
||||
if (null === $start) {
|
||||
$start = session('start');
|
||||
$end = session('end');
|
||||
}
|
||||
if (null === $end) {
|
||||
// get last transaction ever?
|
||||
$last = $this->repository->getLast();
|
||||
$end = null !== $last ? $last->date : session('end');
|
||||
}
|
||||
|
||||
[$start, $end] = $end < $start ? [$end, $start] : [$start, $end];
|
||||
$startStr = $start->isoFormat($this->monthAndDayFormat);
|
||||
$endStr = $end->isoFormat($this->monthAndDayFormat);
|
||||
$subTitle = (string)trans(sprintf('firefly.title_%s_between', $objectType), ['start' => $startStr, 'end' => $endStr]);
|
||||
$path = route('transactions.index', [$objectType, $start->format('Y-m-d'), $end->format('Y-m-d')]);
|
||||
$firstJournal = $this->repository->firstNull();
|
||||
$startPeriod = null === $firstJournal ? new Carbon() : $firstJournal->date;
|
||||
$endPeriod = clone $end;
|
||||
$periods = $this->getTransactionPeriodOverview($objectType, $startPeriod, $endPeriod);
|
||||
|
||||
/** @var GroupCollectorInterface $collector */
|
||||
$collector = app(GroupCollectorInterface::class);
|
||||
|
||||
$collector->setRange($start, $end)
|
||||
->setTypes($types)
|
||||
->setLimit($pageSize)
|
||||
->setPage($page)
|
||||
->withBudgetInformation()
|
||||
->withCategoryInformation()
|
||||
->withAccountInformation()
|
||||
->withAttachmentInformation()
|
||||
;
|
||||
$groups = $collector->getPaginatedGroups();
|
||||
$groups->setPath($path);
|
||||
|
||||
return view('transactions.index', compact('subTitle', 'objectType', 'subTitleIcon', 'groups', 'periods', 'start', 'end'));
|
||||
}
|
||||
|
Reference in New Issue
Block a user