This commit is contained in:
James Cole 2016-11-18 18:58:48 +01:00
parent 6506e70a91
commit a319264428
2 changed files with 17 additions and 3 deletions

View File

@ -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]
);

View File

@ -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]