mirror of
https://github.com/firefly-iii/firefly-iii.git
synced 2025-09-19 19:01:58 +00:00
More code cleanup [skip ci]
This commit is contained in:
@@ -117,6 +117,7 @@ class AccountController extends BaseController
|
|||||||
$openingBalance = $this->_repository->openingBalanceTransaction($account);
|
$openingBalance = $this->_repository->openingBalanceTransaction($account);
|
||||||
$subTitleIcon = $this->_subIconsByIdentifier[$account->accountType->type];
|
$subTitleIcon = $this->_subIconsByIdentifier[$account->accountType->type];
|
||||||
$subTitle = 'Edit ' . strtolower(e($account->accountType->type)) . ' "' . e($account->name) . '"';
|
$subTitle = 'Edit ' . strtolower(e($account->accountType->type)) . ' "' . e($account->name) . '"';
|
||||||
|
$what = $this->_shortNamesByFullName[$account->accountType->type];
|
||||||
|
|
||||||
// pre fill some useful values.
|
// pre fill some useful values.
|
||||||
$preFilled = [
|
$preFilled = [
|
||||||
@@ -126,7 +127,7 @@ class AccountController extends BaseController
|
|||||||
];
|
];
|
||||||
Session::flash('preFilled', $preFilled);
|
Session::flash('preFilled', $preFilled);
|
||||||
|
|
||||||
return View::make('accounts.edit', compact('account', 'subTitle', 'openingBalance', 'subTitleIcon'));
|
return View::make('accounts.edit', compact('account', 'what', 'subTitle', 'openingBalance', 'subTitleIcon'));
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
@@ -168,17 +169,10 @@ class AccountController extends BaseController
|
|||||||
*/
|
*/
|
||||||
public function store()
|
public function store()
|
||||||
{
|
{
|
||||||
/** @var \FireflyIII\Database\AccountType\AccountType $accountTypes */
|
|
||||||
$accountTypes = App::make('FireflyIII\Database\AccountType\AccountType');
|
|
||||||
|
|
||||||
|
|
||||||
$data = Input::except('_token');
|
$data = Input::except('_token');
|
||||||
$type = $accountTypes->findByWhat($data['what']);
|
|
||||||
$data['user_id'] = \Auth::user()->id;
|
|
||||||
$data['account_type_id'] = $type->id;
|
|
||||||
// always validate:
|
|
||||||
$messages = $this->_repository->validate($data);
|
$messages = $this->_repository->validate($data);
|
||||||
|
|
||||||
|
|
||||||
// flash messages:
|
// flash messages:
|
||||||
Session::flash('successes', $messages['successes']);
|
Session::flash('successes', $messages['successes']);
|
||||||
Session::flash('errors', $messages['errors']);
|
Session::flash('errors', $messages['errors']);
|
||||||
@@ -210,15 +204,9 @@ class AccountController extends BaseController
|
|||||||
public function update(Account $account)
|
public function update(Account $account)
|
||||||
{
|
{
|
||||||
$data = Input::except('_token');
|
$data = Input::except('_token');
|
||||||
$data['account_type_id'] = $account->account_type_id;
|
|
||||||
$data['user_id'] = \Auth::user()->id;
|
|
||||||
|
|
||||||
|
|
||||||
// always validate:
|
|
||||||
$messages = $this->_repository->validate($data);
|
$messages = $this->_repository->validate($data);
|
||||||
|
|
||||||
// flash messages:
|
// flash messages:
|
||||||
Session::flash('warnings', $messages['warnings']);
|
|
||||||
Session::flash('successes', $messages['successes']);
|
Session::flash('successes', $messages['successes']);
|
||||||
Session::flash('errors', $messages['errors']);
|
Session::flash('errors', $messages['errors']);
|
||||||
if ($messages['errors']->count() > 0) {
|
if ($messages['errors']->count() > 0) {
|
||||||
|
@@ -127,6 +127,7 @@ class Account implements CUDInterface, CommonDatabaseCallsInterface, AccountInte
|
|||||||
'transaction_type_id' => $transactionType->id,
|
'transaction_type_id' => $transactionType->id,
|
||||||
'transaction_currency_id' => $currency->id,
|
'transaction_currency_id' => $currency->id,
|
||||||
'amount' => $balance,
|
'amount' => $balance,
|
||||||
|
'what' => 'opening',
|
||||||
'from' => $fromAccount,
|
'from' => $fromAccount,
|
||||||
'completed' => 0,
|
'completed' => 0,
|
||||||
'to' => $toAccount,
|
'to' => $toAccount,
|
||||||
@@ -312,24 +313,8 @@ class Account implements CUDInterface, CommonDatabaseCallsInterface, AccountInte
|
|||||||
$model->save();
|
$model->save();
|
||||||
|
|
||||||
if (isset($data['openingBalance']) && isset($data['openingBalanceDate']) && strlen($data['openingBalanceDate']) > 0) {
|
if (isset($data['openingBalance']) && isset($data['openingBalanceDate']) && strlen($data['openingBalanceDate']) > 0) {
|
||||||
/** @noinspection PhpParamsInspection */
|
$this->updateInitialBalance($model, $data);
|
||||||
$openingBalance = $this->openingBalanceTransaction($model);
|
|
||||||
if (is_null($openingBalance)) {
|
|
||||||
$this->storeInitialBalance($model, $data);
|
|
||||||
} else {
|
|
||||||
$openingBalance->date = new Carbon($data['openingBalanceDate']);
|
|
||||||
$openingBalance->save();
|
|
||||||
$amount = floatval($data['openingBalance']);
|
|
||||||
/** @var \Transaction $transaction */
|
|
||||||
foreach ($openingBalance->transactions as $transaction) {
|
|
||||||
if ($transaction->account_id == $model->id) {
|
|
||||||
$transaction->amount = $amount;
|
|
||||||
} else {
|
|
||||||
$transaction->amount = $amount * -1;
|
|
||||||
}
|
|
||||||
$transaction->save();
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
\Event::fire('account.update', [$model]);
|
\Event::fire('account.update', [$model]);
|
||||||
|
|
||||||
@@ -348,7 +333,7 @@ class Account implements CUDInterface, CommonDatabaseCallsInterface, AccountInte
|
|||||||
{
|
{
|
||||||
$successes = new MessageBag;
|
$successes = new MessageBag;
|
||||||
$account = new \Account($model);
|
$account = new \Account($model);
|
||||||
$account->isValid();
|
$account->isValid('form_input', false);
|
||||||
$errors = $account->getErrors();
|
$errors = $account->getErrors();
|
||||||
|
|
||||||
if (isset($model['account_role']) && !in_array($model['account_role'], array_keys(\Config::get('firefly.accountRoles')))) {
|
if (isset($model['account_role']) && !in_array($model['account_role'], array_keys(\Config::get('firefly.accountRoles')))) {
|
||||||
@@ -379,6 +364,32 @@ class Account implements CUDInterface, CommonDatabaseCallsInterface, AccountInte
|
|||||||
return ['errors' => $errors, 'successes' => $successes];
|
return ['errors' => $errors, 'successes' => $successes];
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @param Eloquent $model
|
||||||
|
* @param array $data
|
||||||
|
*/
|
||||||
|
public function updateInitialBalance(Eloquent $model, array $data)
|
||||||
|
{
|
||||||
|
/** @noinspection PhpParamsInspection */
|
||||||
|
$openingBalance = $this->openingBalanceTransaction($model);
|
||||||
|
if (is_null($openingBalance)) {
|
||||||
|
$this->storeInitialBalance($model, $data);
|
||||||
|
} else {
|
||||||
|
$openingBalance->date = new Carbon($data['openingBalanceDate']);
|
||||||
|
$openingBalance->save();
|
||||||
|
$amount = floatval($data['openingBalance']);
|
||||||
|
/** @var \Transaction $transaction */
|
||||||
|
foreach ($openingBalance->transactions as $transaction) {
|
||||||
|
if ($transaction->account_id == $model->id) {
|
||||||
|
$transaction->amount = $amount;
|
||||||
|
} else {
|
||||||
|
$transaction->amount = $amount * -1;
|
||||||
|
}
|
||||||
|
$transaction->save();
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Returns an object with id $id.
|
* Returns an object with id $id.
|
||||||
*
|
*
|
||||||
|
@@ -19,12 +19,18 @@ class Account extends Eloquent
|
|||||||
*
|
*
|
||||||
* @var array
|
* @var array
|
||||||
*/
|
*/
|
||||||
protected $rules
|
protected $rulesets
|
||||||
= [
|
= [
|
||||||
|
'saving' => [
|
||||||
'name' => 'required|between:1,100',
|
'name' => 'required|between:1,100',
|
||||||
'user_id' => 'required|exists:users,id',
|
'user_id' => 'required|exists:users,id',
|
||||||
'account_type_id' => 'required|exists:account_types,id',
|
'account_type_id' => 'required|exists:account_types,id',
|
||||||
'active' => 'required|boolean'
|
'active' => 'required|boolean'
|
||||||
|
],
|
||||||
|
'form_input' => [
|
||||||
|
'name' => 'required|between:1,100',
|
||||||
|
'active' => 'required|boolean',
|
||||||
|
]
|
||||||
];
|
];
|
||||||
|
|
||||||
/**
|
/**
|
||||||
|
@@ -29,6 +29,7 @@
|
|||||||
{{Form::ffBalance('openingBalance',null, ['currency' => $openingBalance ? $openingBalance->transactionCurrency : null])}}
|
{{Form::ffBalance('openingBalance',null, ['currency' => $openingBalance ? $openingBalance->transactionCurrency : null])}}
|
||||||
{{Form::ffDate('openingBalanceDate')}}
|
{{Form::ffDate('openingBalanceDate')}}
|
||||||
{{Form::ffSelect('account_role',Config::get('firefly.accountRoles'))}}
|
{{Form::ffSelect('account_role',Config::get('firefly.accountRoles'))}}
|
||||||
|
{{Form::hidden('what',$what)}}
|
||||||
@endif
|
@endif
|
||||||
</div>
|
</div>
|
||||||
</div>
|
</div>
|
||||||
|
Reference in New Issue
Block a user