mirror of
https://github.com/firefly-iii/firefly-iii.git
synced 2025-09-25 06:51:08 +00:00
Fix for #1825
This commit is contained in:
@@ -123,7 +123,6 @@ class ReconcileController extends Controller
|
|||||||
* @return \Illuminate\Contracts\View\Factory|\Illuminate\Http\RedirectResponse|\Illuminate\Routing\Redirector|\Illuminate\View\View
|
* @return \Illuminate\Contracts\View\Factory|\Illuminate\Http\RedirectResponse|\Illuminate\Routing\Redirector|\Illuminate\View\View
|
||||||
* @SuppressWarnings(PHPMD.CyclomaticComplexity)
|
* @SuppressWarnings(PHPMD.CyclomaticComplexity)
|
||||||
* @SuppressWarnings(PHPMD.ExcessiveMethodLength)
|
* @SuppressWarnings(PHPMD.ExcessiveMethodLength)
|
||||||
* @throws FireflyException
|
|
||||||
*/
|
*/
|
||||||
public function reconcile(Account $account, Carbon $start = null, Carbon $end = null)
|
public function reconcile(Account $account, Carbon $start = null, Carbon $end = null)
|
||||||
{
|
{
|
||||||
|
@@ -113,13 +113,41 @@ class ReconcileController extends Controller
|
|||||||
|
|
||||||
/** @var Transaction $transaction */
|
/** @var Transaction $transaction */
|
||||||
foreach ($transactions as $transaction) {
|
foreach ($transactions as $transaction) {
|
||||||
$amount = bcadd($amount, $transaction->amount);
|
// find the account and opposing account for this transaction
|
||||||
|
$srcAccount = $this->accountRepos->findNull((int)$transaction->account_id);
|
||||||
|
$dstAccount = $this->accountRepos->findNull((int)$transaction->opposing_account_id);
|
||||||
|
$srcCurrency = (int)$this->accountRepos->getMetaValue($srcAccount, 'currency_id');
|
||||||
|
$dstCurrency = (int)$this->accountRepos->getMetaValue($dstAccount, 'currency_id');
|
||||||
|
|
||||||
|
// is $account source or destination?
|
||||||
|
if ($account->id === $srcAccount->id) {
|
||||||
|
// source, and it matches the currency id or is 0
|
||||||
|
if ($srcCurrency === $transaction->transaction_currency_id || 0 === $srcCurrency) {
|
||||||
|
$amount = bcadd($amount, $transaction->transaction_amount);
|
||||||
|
}
|
||||||
|
// destination, and it matches the foreign currency ID.
|
||||||
|
if ($srcCurrency === $transaction->foreign_currency_id) {
|
||||||
|
$amount = bcadd($amount, $transaction->transaction_foreign_amount);
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
if ($account->id === $dstAccount->id) {
|
||||||
|
// destination, and it matches the currency id or is 0
|
||||||
|
if ($dstCurrency === $transaction->transaction_currency_id || 0 === $dstCurrency) {
|
||||||
|
$amount = bcadd($amount, $transaction->transaction_amount);
|
||||||
|
}
|
||||||
|
// destination, and it matches the foreign currency ID.
|
||||||
|
if ($dstCurrency === $transaction->foreign_currency_id) {
|
||||||
|
$amount = bcadd($amount, $transaction->transaction_foreign_amount);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
// make sure amount is positive.
|
||||||
|
$amount = app('steam')->positive($amount);
|
||||||
/** @var Transaction $transaction */
|
/** @var Transaction $transaction */
|
||||||
foreach ($cleared as $transaction) {
|
foreach ($cleared as $transaction) {
|
||||||
if ($transaction->transactionJournal->date <= $end) {
|
if ($transaction->date <= $end) {
|
||||||
$clearedAmount = bcadd($clearedAmount, $transaction->amount); // @codeCoverageIgnore
|
$clearedAmount = bcadd($clearedAmount, $transaction->transaction_amount); // @codeCoverageIgnore
|
||||||
++$countCleared;
|
++$countCleared;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@@ -201,6 +229,7 @@ class ReconcileController extends Controller
|
|||||||
Log::debug(sprintf('Could not render: %s', $e->getMessage()));
|
Log::debug(sprintf('Could not render: %s', $e->getMessage()));
|
||||||
$html = 'Could not render accounts.reconcile.transactions';
|
$html = 'Could not render accounts.reconcile.transactions';
|
||||||
}
|
}
|
||||||
|
|
||||||
// @codeCoverageIgnoreEnd
|
// @codeCoverageIgnoreEnd
|
||||||
|
|
||||||
return response()->json(['html' => $html, 'startBalance' => $startBalance, 'endBalance' => $endBalance]);
|
return response()->json(['html' => $html, 'startBalance' => $startBalance, 'endBalance' => $endBalance]);
|
||||||
|
@@ -27,6 +27,8 @@ use Exception;
|
|||||||
use FireflyIII\Exceptions\FireflyException;
|
use FireflyIII\Exceptions\FireflyException;
|
||||||
use FireflyIII\Factory\TransactionJournalFactory;
|
use FireflyIII\Factory\TransactionJournalFactory;
|
||||||
use FireflyIII\Factory\TransactionJournalMetaFactory;
|
use FireflyIII\Factory\TransactionJournalMetaFactory;
|
||||||
|
use FireflyIII\Helpers\Collector\TransactionCollectorInterface;
|
||||||
|
use FireflyIII\Helpers\Filter\TransferFilter;
|
||||||
use FireflyIII\Models\Account;
|
use FireflyIII\Models\Account;
|
||||||
use FireflyIII\Models\AccountType;
|
use FireflyIII\Models\AccountType;
|
||||||
use FireflyIII\Models\PiggyBankEvent;
|
use FireflyIII\Models\PiggyBankEvent;
|
||||||
@@ -581,14 +583,21 @@ class JournalRepository implements JournalRepositoryInterface
|
|||||||
*/
|
*/
|
||||||
public function getTransactionsById(array $transactionIds): Collection
|
public function getTransactionsById(array $transactionIds): Collection
|
||||||
{
|
{
|
||||||
$set = Transaction::leftJoin('transaction_journals', 'transaction_journals.id', '=', 'transactions.transaction_journal_id')
|
$journalIds = Transaction::whereIn('id', $transactionIds)->get(['transaction_journal_id'])->pluck('transaction_journal_id')->toArray();
|
||||||
->whereIn('transactions.id', $transactionIds)
|
$journals = new Collection;
|
||||||
->where('transaction_journals.user_id', $this->user->id)
|
foreach($journalIds as $journalId) {
|
||||||
->whereNull('transaction_journals.deleted_at')
|
$result = $this->findNull((int)$journalId);
|
||||||
->whereNull('transactions.deleted_at')
|
if(null !== $result) {
|
||||||
->get(['transactions.*']);
|
$journals->push($result);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
/** @var TransactionCollectorInterface $collector */
|
||||||
|
$collector = app(TransactionCollectorInterface::class);
|
||||||
|
$collector->setUser($this->user);
|
||||||
|
$collector->addFilter(TransferFilter::class);
|
||||||
|
|
||||||
return $set;
|
$collector->setJournals($journals)->withOpposingAccount();
|
||||||
|
return $collector->getTransactions();
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
|
Reference in New Issue
Block a user