Skip to content

Commit

Permalink
Fix #2956
Browse files Browse the repository at this point in the history
  • Loading branch information
JC5 committed Jan 5, 2020
1 parent e2bb5c7 commit d116609
Show file tree
Hide file tree
Showing 2 changed files with 29 additions and 1 deletion.
22 changes: 21 additions & 1 deletion app/Http/Controllers/Account/ReconcileController.php
Original file line number Diff line number Diff line change
Expand Up @@ -90,6 +90,7 @@ public function reconcile(Account $account, Carbon $start = null, Carbon $end =
return $this->redirectAccountToAccount($account); // @codeCoverageIgnore
}


if (AccountType::ASSET !== $account->accountType->type) {
// @codeCoverageIgnoreStart
session()->flash('error', (string)trans('firefly.must_be_asset_account'));
Expand Down Expand Up @@ -117,6 +118,9 @@ public function reconcile(Account $account, Carbon $start = null, Carbon $end =
$end = app('navigation')->endOfPeriod($start, $range);
}
// @codeCoverageIgnoreEnd
if ($end->lt($start)) {
[$start, $end] = [$end, $start];
}

$startDate = clone $start;
$startDate->subDay();
Expand Down Expand Up @@ -163,6 +167,11 @@ public function submit(ReconciliationStoreRequest $request, Account $account, Ca
}
Log::debug('Reconciled all transactions.');

// switch dates if necessary
if ($end->lt($start)) {
[$start, $end] = [$end, $start];
}

// create reconciliation transaction (if necessary):
$result = '';
if ('create' === $data['reconcile']) {
Expand All @@ -182,9 +191,16 @@ public function submit(ReconciliationStoreRequest $request, Account $account, Ca

/**
* Creates a reconciliation group.
*
* @param Account $account
* @param Carbon $start
* @param Carbon $end
* @param string $difference
*
* @return string
* @throws \FireflyIII\Exceptions\DuplicateTransactionException
*/
private function createReconciliation(Account $account, Carbon $start, Carbon $end, string $difference): string
private function createReconciliation(Account $account, Carbon $start, Carbon $end, string $difference)
{
if (!$this->isEditableAccount($account)) {
return $this->redirectAccountToAccount($account); // @codeCoverageIgnore
Expand All @@ -199,6 +215,10 @@ private function createReconciliation(Account $account, Carbon $start, Carbon $e
$destination = $reconciliation;
}

if ($end->lt($start)) {
[$start, $end] = [$end, $start];
}

// title:
$description = trans('firefly.reconciliation_transaction_title',
['from' => $start->formatLocalized($this->monthAndDayFormat), 'to' => $end->formatLocalized($this->monthAndDayFormat)]);
Expand Down
8 changes: 8 additions & 0 deletions app/Http/Controllers/Json/ReconcileController.php
Original file line number Diff line number Diff line change
Expand Up @@ -93,6 +93,11 @@ public function overview(Request $request, Account $account, Carbon $start, Carb
$accountCurrency = $this->accountRepos->getAccountCurrency($account) ?? app('amount')->getDefaultCurrency();
$amount = '0';
$clearedAmount = '0';

if ($end->lt($start)) {
[$start, $end] = [$end, $start];
}

$route = route('accounts.reconcile.submit', [$account->id, $start->format('Ymd'), $end->format('Ymd')]);
$selectedIds = $request->get('journals') ?? [];
$clearedJournals = [];
Expand Down Expand Up @@ -171,6 +176,9 @@ public function overview(Request $request, Account $account, Carbon $start, Carb
*/
public function transactions(Account $account, Carbon $start, Carbon $end)
{
if ($end->lt($start)) {
[$end, $start] = [$start, $end];
}
$startDate = clone $start;
$startDate->subDay();

Expand Down

0 comments on commit d116609

Please sign in to comment.