This commit is contained in:
James Cole 2016-03-30 17:47:13 +02:00
parent e953f58c74
commit 21181d8d8e
2 changed files with 7 additions and 6 deletions

View File

@ -42,6 +42,7 @@ class AccountController extends Controller
$subTitleIcon = Config::get('firefly.subIconsByIdentifier.' . $what); $subTitleIcon = Config::get('firefly.subIconsByIdentifier.' . $what);
$subTitle = trans('firefly.make_new_' . $what . '_account'); $subTitle = trans('firefly.make_new_' . $what . '_account');
Session::flash('preFilled', []);
// put previous url in session if not redirect from store (not "create another"). // put previous url in session if not redirect from store (not "create another").
if (session('accounts.create.fromStore') !== true) { if (session('accounts.create.fromStore') !== true) {

View File

@ -34,6 +34,9 @@ class AccountRepository implements AccountRepositoryInterface
/** @var User */ /** @var User */
private $user; private $user;
/** @var array */
private $validFields = ['accountRole', 'ccMonthlyPaymentDate', 'ccType', 'accountNumber'];
/** /**
* AttachmentRepository constructor. * AttachmentRepository constructor.
* *
@ -448,7 +451,7 @@ class AccountRepository implements AccountRepositoryInterface
$this->updateMetadata($account, $data); $this->updateMetadata($account, $data);
$openingBalance = $this->openingBalanceTransaction($account); $openingBalance = $this->openingBalanceTransaction($account);
if ($data['openingBalance'] != 0) { if ($data['openingBalance'] != 0) {
if ($openingBalance) { if (!is_null($openingBalance->id)) {
$this->updateInitialBalance($account, $openingBalance, $data); $this->updateInitialBalance($account, $openingBalance, $data);
} else { } else {
$type = $data['openingBalance'] < 0 ? 'expense' : 'revenue'; $type = $data['openingBalance'] < 0 ? 'expense' : 'revenue';
@ -570,8 +573,7 @@ class AccountRepository implements AccountRepositoryInterface
*/ */
protected function storeMetadata(Account $account, array $data) protected function storeMetadata(Account $account, array $data)
{ {
$validFields = ['accountRole', 'ccMonthlyPaymentDate', 'ccType']; foreach ($this->validFields as $field) {
foreach ($validFields as $field) {
if (isset($data[$field])) { if (isset($data[$field])) {
$metaData = new AccountMeta( $metaData = new AccountMeta(
[ [
@ -621,9 +623,7 @@ class AccountRepository implements AccountRepositoryInterface
*/ */
protected function updateMetadata(Account $account, array $data) protected function updateMetadata(Account $account, array $data)
{ {
$validFields = ['accountRole', 'ccMonthlyPaymentDate', 'ccType']; foreach ($this->validFields as $field) {
foreach ($validFields as $field) {
$entry = $account->accountMeta()->where('name', $field)->first(); $entry = $account->accountMeta()->where('name', $field)->first();
if (isset($data[$field])) { if (isset($data[$field])) {