mirror of
https://github.com/firefly-iii/firefly-iii.git
synced 2025-02-16 18:25:00 -06:00
Merge branch 'release/3.2.4'
Conflicts: app/config/app.php
This commit is contained in:
commit
144e329eca
@ -7,11 +7,12 @@ use FireflyIII\Database\CommonDatabaseCallsInterface;
|
||||
use FireflyIII\Database\CUDInterface;
|
||||
use FireflyIII\Database\SwitchUser;
|
||||
use FireflyIII\Exception\NotImplementedException;
|
||||
use Illuminate\Database\Eloquent\Builder as EloquentBuilder;
|
||||
use Illuminate\Database\Eloquent\Model as Eloquent;
|
||||
use Illuminate\Database\Query\Builder as QueryBuilder;
|
||||
use Illuminate\Support\Collection;
|
||||
use Illuminate\Support\MessageBag;
|
||||
use Illuminate\Database\Query\Builder as QueryBuilder;
|
||||
use Illuminate\Database\Eloquent\Builder as EloquentBuilder;
|
||||
|
||||
/**
|
||||
* Class Account
|
||||
*
|
||||
@ -199,8 +200,26 @@ class Account implements CUDInterface, CommonDatabaseCallsInterface, AccountInte
|
||||
|
||||
// data for transaction journal:
|
||||
$balance = $balance < 0 ? $balance * -1 : $balance;
|
||||
$opening = ['what' => 'opening', 'currency' => 'EUR', 'amount' => $balance, 'from' => $from, 'to' => $to, 'date' => $date,
|
||||
'description' => 'Opening balance for new account ' . $account->name,];
|
||||
|
||||
// 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,];
|
||||
|
||||
|
||||
$validation = $tj->validate($opening);
|
||||
@ -209,6 +228,7 @@ class Account implements CUDInterface, CommonDatabaseCallsInterface, AccountInte
|
||||
|
||||
return true;
|
||||
} else {
|
||||
\Log::error('Initial balance created is not valid (Database/Account)');
|
||||
\Log::error($validation['errors']->all());
|
||||
\App::abort(500);
|
||||
}
|
||||
@ -314,6 +334,7 @@ class Account implements CUDInterface, CommonDatabaseCallsInterface, AccountInte
|
||||
$data = array_except($data, ['_token', 'what']);
|
||||
$account = new \Account($data);
|
||||
if (!$account->isValid()) {
|
||||
\Log::error('Account created is not valid (Database/Account)');
|
||||
\Log::error($account->getErrors()->all());
|
||||
\App::abort(500);
|
||||
}
|
||||
|
@ -74,8 +74,15 @@ class TransactionJournal implements TransactionJournalInterface, CUDInterface, C
|
||||
|
||||
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->storeCategory($data, $journal);
|
||||
|
||||
@ -278,6 +285,8 @@ class TransactionJournal implements TransactionJournalInterface, CUDInterface, C
|
||||
$toAccount = $accountRepository->firstExpenseAccountOrCreate($data['expense_account']);
|
||||
break;
|
||||
case 'opening':
|
||||
$fromAccount = $data['from'];
|
||||
$toAccount = $data['to'];
|
||||
break;
|
||||
case 'deposit':
|
||||
$fromAccount = $accountRepository->firstRevenueAccountOrCreate($data['revenue_account']);
|
||||
|
@ -145,4 +145,21 @@ class Amount
|
||||
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