From a31926442821a9c46429441b4d8eb6a2f49149ea Mon Sep 17 00:00:00 2001 From: James Cole Date: Fri, 18 Nov 2016 18:58:48 +0100 Subject: [PATCH] fixed #406 --- app/Repositories/Journal/JournalRepository.php | 18 ++++++++++++++++-- public/js/ff/split/journal/from-store.js | 2 +- 2 files changed, 17 insertions(+), 3 deletions(-) diff --git a/app/Repositories/Journal/JournalRepository.php b/app/Repositories/Journal/JournalRepository.php index 0e8c73942d..1643007904 100644 --- a/app/Repositories/Journal/JournalRepository.php +++ b/app/Repositories/Journal/JournalRepository.php @@ -510,20 +510,28 @@ class JournalRepository implements JournalRepositoryInterface */ private function storeDepositAccounts(array $data): array { + Log::debug('Now in storeDepositAccounts().'); $destinationAccount = Account::where('user_id', $this->user->id)->where('id', $data['destination_account_id'])->first(['accounts.*']); + Log::debug(sprintf('Destination account is #%d ("%s")', $destinationAccount->id, $destinationAccount->name)); + if (strlen($data['source_account_name']) > 0) { $sourceType = AccountType::where('type', 'Revenue account')->first(); $sourceAccount = Account::firstOrCreateEncrypted( ['user_id' => $this->user->id, 'account_type_id' => $sourceType->id, 'name' => $data['source_account_name'], 'active' => 1] ); + Log::debug(sprintf('source account name is "%s", account is %d', $data['source_account_name'], $sourceAccount->id)); + return [ 'source' => $sourceAccount, 'destination' => $destinationAccount, ]; } - $sourceType = AccountType::where('type', 'Cash account')->first(); + + Log::debug('source_account_name is empty, so default to cash account!'); + + $sourceType = AccountType::where('type', AccountType::CASH)->first(); $sourceAccount = Account::firstOrCreateEncrypted( ['user_id' => $this->user->id, 'account_type_id' => $sourceType->id, 'name' => 'Cash account', 'active' => 1] ); @@ -618,8 +626,11 @@ class JournalRepository implements JournalRepositoryInterface */ private function storeWithdrawalAccounts(array $data): array { + Log::debug('Now in storeWithdrawalAccounts().'); $sourceAccount = Account::where('user_id', $this->user->id)->where('id', $data['source_account_id'])->first(['accounts.*']); + Log::debug(sprintf('Source account is #%d ("%s")', $sourceAccount->id, $sourceAccount->name)); + if (strlen($data['destination_account_name']) > 0) { $destinationType = AccountType::where('type', AccountType::EXPENSE)->first(); $destinationAccount = Account::firstOrCreateEncrypted( @@ -631,12 +642,15 @@ class JournalRepository implements JournalRepositoryInterface ] ); + Log::debug(sprintf('destination account name is "%s", account is %d', $data['destination_account_name'], $destinationAccount->id)); + return [ 'source' => $sourceAccount, 'destination' => $destinationAccount, ]; } - $destinationType = AccountType::where('type', 'Cash account')->first(); + Log::debug('destination_account_name is empty, so default to cash account!'); + $destinationType = AccountType::where('type', AccountType::CASH)->first(); $destinationAccount = Account::firstOrCreateEncrypted( ['user_id' => $this->user->id, 'account_type_id' => $destinationType->id, 'name' => 'Cash account', 'active' => 1] ); diff --git a/public/js/ff/split/journal/from-store.js b/public/js/ff/split/journal/from-store.js index a6f8a1ef35..e8b99b09d4 100644 --- a/public/js/ff/split/journal/from-store.js +++ b/public/js/ff/split/journal/from-store.js @@ -148,7 +148,7 @@ function resetSplits() { // ends with ][source_account_name] $.each($('input[name$="][source_account_name]"]'), function (i, v) { var input = $(v); - input.attr('name', 'transaction[' + i + '][source_account_name]'); + input.attr('name', 'transactions[' + i + '][source_account_name]'); console.log('source_account_name is now ' + input.attr('name')); }); // ends with ][amount]