mirror of
https://github.com/firefly-iii/firefly-iii.git
synced 2025-02-25 18:45:27 -06:00
Bug fix in new accounts.
This commit is contained in:
parent
83190572c7
commit
21d5420b2a
@ -37,8 +37,8 @@ return [
|
|||||||
'Illuminate\Validation\ValidationServiceProvider',
|
'Illuminate\Validation\ValidationServiceProvider',
|
||||||
'Illuminate\View\ViewServiceProvider',
|
'Illuminate\View\ViewServiceProvider',
|
||||||
'Illuminate\Workbench\WorkbenchServiceProvider',
|
'Illuminate\Workbench\WorkbenchServiceProvider',
|
||||||
// 'Barryvdh\LaravelIdeHelper\IdeHelperServiceProvider',
|
// 'Barryvdh\LaravelIdeHelper\IdeHelperServiceProvider',
|
||||||
// 'Barryvdh\Debugbar\ServiceProvider',
|
// 'Barryvdh\Debugbar\ServiceProvider',
|
||||||
'FireflyIII\FF3ServiceProvider',
|
'FireflyIII\FF3ServiceProvider',
|
||||||
'DaveJamesMiller\Breadcrumbs\ServiceProvider',
|
'DaveJamesMiller\Breadcrumbs\ServiceProvider',
|
||||||
'Grumpydictator\Gchart\GchartServiceProvider',
|
'Grumpydictator\Gchart\GchartServiceProvider',
|
||||||
|
@ -7,11 +7,12 @@ use FireflyIII\Database\CommonDatabaseCallsInterface;
|
|||||||
use FireflyIII\Database\CUDInterface;
|
use FireflyIII\Database\CUDInterface;
|
||||||
use FireflyIII\Database\SwitchUser;
|
use FireflyIII\Database\SwitchUser;
|
||||||
use FireflyIII\Exception\NotImplementedException;
|
use FireflyIII\Exception\NotImplementedException;
|
||||||
|
use Illuminate\Database\Eloquent\Builder as EloquentBuilder;
|
||||||
use Illuminate\Database\Eloquent\Model as Eloquent;
|
use Illuminate\Database\Eloquent\Model as Eloquent;
|
||||||
|
use Illuminate\Database\Query\Builder as QueryBuilder;
|
||||||
use Illuminate\Support\Collection;
|
use Illuminate\Support\Collection;
|
||||||
use Illuminate\Support\MessageBag;
|
use Illuminate\Support\MessageBag;
|
||||||
use Illuminate\Database\Query\Builder as QueryBuilder;
|
|
||||||
use Illuminate\Database\Eloquent\Builder as EloquentBuilder;
|
|
||||||
/**
|
/**
|
||||||
* Class Account
|
* Class Account
|
||||||
*
|
*
|
||||||
@ -199,7 +200,25 @@ class Account implements CUDInterface, CommonDatabaseCallsInterface, AccountInte
|
|||||||
|
|
||||||
// data for transaction journal:
|
// data for transaction journal:
|
||||||
$balance = $balance < 0 ? $balance * -1 : $balance;
|
$balance = $balance < 0 ? $balance * -1 : $balance;
|
||||||
$opening = ['what' => 'opening', 'currency' => 'EUR', 'amount' => $balance, 'from' => $from, 'to' => $to, 'date' => $date,
|
|
||||||
|
// find the account type:
|
||||||
|
/** @var \FireflyIII\Database\TransactionType\TransactionType $typeRepository */
|
||||||
|
$typeRepository = \App::make('FireflyIII\Database\TransactionType\TransactionType');
|
||||||
|
$type = $typeRepository->findByWhat('opening');
|
||||||
|
|
||||||
|
// find the currency.
|
||||||
|
$currency = \Amount::getDefaultCurrency();
|
||||||
|
|
||||||
|
$opening = [
|
||||||
|
'transaction_type_id' => $type->id,
|
||||||
|
'transaction_currency_id' => $currency->id,
|
||||||
|
'amount' => $balance,
|
||||||
|
'from' => $from,
|
||||||
|
'completed' => 0,
|
||||||
|
'currency' => 'EUR',
|
||||||
|
'what' => 'opening',
|
||||||
|
'to' => $to,
|
||||||
|
'date' => $date,
|
||||||
'description' => 'Opening balance for new account ' . $account->name,];
|
'description' => 'Opening balance for new account ' . $account->name,];
|
||||||
|
|
||||||
|
|
||||||
@ -209,6 +228,7 @@ class Account implements CUDInterface, CommonDatabaseCallsInterface, AccountInte
|
|||||||
|
|
||||||
return true;
|
return true;
|
||||||
} else {
|
} else {
|
||||||
|
\Log::error('Initial balance created is not valid (Database/Account)');
|
||||||
\Log::error($validation['errors']->all());
|
\Log::error($validation['errors']->all());
|
||||||
\App::abort(500);
|
\App::abort(500);
|
||||||
}
|
}
|
||||||
@ -314,6 +334,7 @@ class Account implements CUDInterface, CommonDatabaseCallsInterface, AccountInte
|
|||||||
$data = array_except($data, ['_token', 'what']);
|
$data = array_except($data, ['_token', 'what']);
|
||||||
$account = new \Account($data);
|
$account = new \Account($data);
|
||||||
if (!$account->isValid()) {
|
if (!$account->isValid()) {
|
||||||
|
\Log::error('Account created is not valid (Database/Account)');
|
||||||
\Log::error($account->getErrors()->all());
|
\Log::error($account->getErrors()->all());
|
||||||
\App::abort(500);
|
\App::abort(500);
|
||||||
}
|
}
|
||||||
|
@ -74,8 +74,15 @@ class TransactionJournal implements TransactionJournalInterface, CUDInterface, C
|
|||||||
|
|
||||||
list($fromAccount, $toAccount) = $this->storeAccounts($data);
|
list($fromAccount, $toAccount) = $this->storeAccounts($data);
|
||||||
|
|
||||||
$this->storeTransaction(['account' => $fromAccount, 'transaction_journal' => $journal, 'amount' => floatval($data['amount'] * -1)]);
|
|
||||||
$this->storeTransaction(['account' => $toAccount, 'transaction_journal' => $journal, 'amount' => floatval($data['amount'])]);
|
$this->storeTransaction(
|
||||||
|
['account_id' => $fromAccount->id, 'account' => $fromAccount, 'transaction_journal' => $journal, 'transaction_journal_id' => $journal->id,
|
||||||
|
'amount' => floatval($data['amount'] * -1)]
|
||||||
|
);
|
||||||
|
$this->storeTransaction(
|
||||||
|
['account_id' => $toAccount->id, 'account' => $toAccount, 'transaction_journal' => $journal, 'transaction_journal_id' => $journal->id,
|
||||||
|
'amount' => floatval($data['amount'])]
|
||||||
|
);
|
||||||
$this->storeBudget($data, $journal);
|
$this->storeBudget($data, $journal);
|
||||||
$this->storeCategory($data, $journal);
|
$this->storeCategory($data, $journal);
|
||||||
|
|
||||||
@ -278,6 +285,8 @@ class TransactionJournal implements TransactionJournalInterface, CUDInterface, C
|
|||||||
$toAccount = $accountRepository->firstExpenseAccountOrCreate($data['expense_account']);
|
$toAccount = $accountRepository->firstExpenseAccountOrCreate($data['expense_account']);
|
||||||
break;
|
break;
|
||||||
case 'opening':
|
case 'opening':
|
||||||
|
$fromAccount = $data['from'];
|
||||||
|
$toAccount = $data['to'];
|
||||||
break;
|
break;
|
||||||
case 'deposit':
|
case 'deposit':
|
||||||
$fromAccount = $accountRepository->firstRevenueAccountOrCreate($data['revenue_account']);
|
$fromAccount = $accountRepository->firstRevenueAccountOrCreate($data['revenue_account']);
|
||||||
|
@ -145,4 +145,21 @@ class Amount
|
|||||||
return $currency->code;
|
return $currency->code;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @return string
|
||||||
|
*/
|
||||||
|
public function getDefaultCurrency()
|
||||||
|
{
|
||||||
|
/** @var \FireflyIII\Database\TransactionCurrency\TransactionCurrency $currencies */
|
||||||
|
$currencies = \App::make('FireflyIII\Database\TransactionCurrency\TransactionCurrency');
|
||||||
|
|
||||||
|
/** @var \FireflyIII\Shared\Preferences\Preferences $preferences */
|
||||||
|
$preferences = \App::make('FireflyIII\Shared\Preferences\Preferences');
|
||||||
|
|
||||||
|
$currencyPreference = $preferences->get('currencyPreference', 'EUR');
|
||||||
|
$currency = $currencies->findByCode($currencyPreference->data);
|
||||||
|
|
||||||
|
return $currency;
|
||||||
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
|
2301
composer.lock
generated
2301
composer.lock
generated
File diff suppressed because it is too large
Load Diff
Loading…
Reference in New Issue
Block a user