This commit is contained in:
James Cole 2024-03-06 07:01:21 +01:00
parent 955ab38a85
commit 0597255c08
No known key found for this signature in database
GPG Key ID: B49A324B7EAD6D80
2 changed files with 38 additions and 44 deletions

View File

@ -34,6 +34,7 @@ use FireflyIII\Repositories\Account\AccountRepositoryInterface;
use Illuminate\Http\JsonResponse; use Illuminate\Http\JsonResponse;
use Illuminate\Http\Request; use Illuminate\Http\Request;
use Illuminate\Support\Collection; use Illuminate\Support\Collection;
use Illuminate\Support\Facades\Log;
/** /**
* Class ReconcileController * Class ReconcileController
@ -73,7 +74,6 @@ class ReconcileController extends Controller
$accountCurrency = $this->accountRepos->getAccountCurrency($account) ?? app('amount')->getDefaultCurrency(); $accountCurrency = $this->accountRepos->getAccountCurrency($account) ?? app('amount')->getDefaultCurrency();
$amount = '0'; $amount = '0';
$clearedAmount = '0'; $clearedAmount = '0';
$route = '';
if (null === $start && null === $end) { if (null === $start && null === $end) {
throw new FireflyException('Invalid dates submitted.'); throw new FireflyException('Invalid dates submitted.');
@ -103,14 +103,11 @@ class ReconcileController extends Controller
$clearedJournals = $collector->getExtractedJournals(); $clearedJournals = $collector->getExtractedJournals();
} }
app('log')->debug('Start transaction loop');
/** @var array $journal */ /** @var array $journal */
foreach ($journals as $journal) { foreach ($journals as $journal) {
$amount = $this->processJournal($account, $accountCurrency, $journal, $amount); $amount = $this->processJournal($account, $accountCurrency, $journal, $amount);
} }
app('log')->debug(sprintf('Final amount is %s', $amount)); app('log')->debug(sprintf('Final amount is %s', $amount));
app('log')->debug('End transaction loop');
/** @var array $journal */ /** @var array $journal */
foreach ($clearedJournals as $journal) { foreach ($clearedJournals as $journal) {
@ -118,35 +115,17 @@ class ReconcileController extends Controller
$clearedAmount = $this->processJournal($account, $accountCurrency, $journal, $clearedAmount); $clearedAmount = $this->processJournal($account, $accountCurrency, $journal, $clearedAmount);
} }
} }
\Log::debug(sprintf('Start balance: "%s"', $startBalance)); Log::debug(sprintf('Start balance: "%s"', $startBalance));
\Log::debug(sprintf('End balance: "%s"', $endBalance)); Log::debug(sprintf('End balance: "%s"', $endBalance));
\Log::debug(sprintf('Cleared amount: "%s"', $clearedAmount)); Log::debug(sprintf('Cleared amount: "%s"', $clearedAmount));
\Log::debug(sprintf('Amount: "%s"', $amount)); Log::debug(sprintf('Amount: "%s"', $amount));
$difference = bcadd(bcadd(bcsub($startBalance, $endBalance), $clearedAmount), $amount); $difference = bcadd(bcadd(bcsub($startBalance, $endBalance), $clearedAmount), $amount);
$diffCompare = bccomp($difference, '0'); $diffCompare = bccomp($difference, '0');
$countCleared = count($clearedJournals); $countCleared = count($clearedJournals);
$reconSum = bcadd(bcadd($startBalance, $amount), $clearedAmount); $reconSum = bcadd(bcadd($startBalance, $amount), $clearedAmount);
try { try {
$view = view( $view = view('accounts.reconcile.overview', compact('account', 'start', 'diffCompare', 'difference', 'end', 'clearedAmount', 'startBalance', 'endBalance', 'amount', 'route', 'countCleared', 'reconSum', 'selectedIds'))->render();
'accounts.reconcile.overview',
compact(
'account',
'start',
'diffCompare',
'difference',
'end',
'clearedAmount',
'startBalance',
'endBalance',
'amount',
'route',
'countCleared',
'reconSum',
'selectedIds'
)
)->render();
} catch (\Throwable $e) { } catch (\Throwable $e) {
app('log')->debug(sprintf('View error: %s', $e->getMessage())); app('log')->debug(sprintf('View error: %s', $e->getMessage()));
app('log')->error($e->getTraceAsString()); app('log')->error($e->getTraceAsString());
@ -155,10 +134,7 @@ class ReconcileController extends Controller
throw new FireflyException($view, 0, $e); throw new FireflyException($view, 0, $e);
} }
$return = [ $return = ['post_url' => $route, 'html' => $view];
'post_url' => $route,
'html' => $view,
];
return response()->json($return); return response()->json($return);
} }

View File

@ -73,6 +73,8 @@ class OperatorQuerySearch implements SearchInterface
private CurrencyRepositoryInterface $currencyRepository; private CurrencyRepositoryInterface $currencyRepository;
private array $excludeTags; private array $excludeTags;
private array $includeTags; private array $includeTags;
// added to fix #8632
private array $includeAnyTags;
private array $invalidOperators; private array $invalidOperators;
private int $limit; private int $limit;
private Collection $operators; private Collection $operators;
@ -93,6 +95,7 @@ class OperatorQuerySearch implements SearchInterface
$this->page = 1; $this->page = 1;
$this->words = []; $this->words = [];
$this->excludeTags = []; $this->excludeTags = [];
$this->includeAnyTags = [];
$this->includeTags = []; $this->includeTags = [];
$this->prohibitedWords = []; $this->prohibitedWords = [];
$this->invalidOperators = []; $this->invalidOperators = [];
@ -1112,8 +1115,9 @@ class OperatorQuerySearch implements SearchInterface
$this->collector->findNothing(); $this->collector->findNothing();
} }
if ($tags->count() > 0) { if ($tags->count() > 0) {
// changed from includeTags to includeAnyTags for #8632
$ids = array_values($tags->pluck('id')->toArray()); $ids = array_values($tags->pluck('id')->toArray());
$this->includeTags = array_unique(array_merge($this->includeTags, $ids)); $this->includeAnyTags = array_unique(array_merge($this->includeAnyTags, $ids));
} }
break; break;
@ -1125,8 +1129,9 @@ class OperatorQuerySearch implements SearchInterface
$this->collector->findNothing(); $this->collector->findNothing();
} }
if ($tags->count() > 0) { if ($tags->count() > 0) {
// changed from includeTags to includeAnyTags for #8632
$ids = array_values($tags->pluck('id')->toArray()); $ids = array_values($tags->pluck('id')->toArray());
$this->includeTags = array_unique(array_merge($this->includeTags, $ids)); $this->includeAnyTags = array_unique(array_merge($this->includeAnyTags, $ids));
} }
break; break;
@ -2725,6 +2730,19 @@ class OperatorQuerySearch implements SearchInterface
} }
$this->collector->setAllTags($collection); $this->collector->setAllTags($collection);
} }
// if include ANY tags, include them: (see #8632)
if (count($this->includeAnyTags) > 0) {
app('log')->debug(sprintf('%d include ANY tag(s)', count($this->includeAnyTags)));
$collection = new Collection();
foreach ($this->includeAnyTags as $tagId) {
$tag = $this->tagRepository->find($tagId);
if (null !== $tag) {
app('log')->debug(sprintf('Include ANY tag "%s"', $tag->tag));
$collection->push($tag);
}
}
$this->collector->setTags($collection);
}
} }
public function getWords(): array public function getWords(): array