This commit is contained in:
James Cole
2017-08-15 17:34:34 +02:00
parent 34894fb76b
commit 7b3ef0e3ab
5 changed files with 125 additions and 61 deletions

View File

@@ -117,8 +117,11 @@ trait SupportJournalsTrait
if (strlen($data['source_account_name']) > 0) {
$sourceType = AccountType::where('type', 'Revenue account')->first();
$sourceAccount = Account::firstOrCreateEncrypted(
['user_id' => $user->id, 'account_type_id' => $sourceType->id, 'name' => $data['source_account_name'], 'active' => 1]
['user_id' => $user->id, 'account_type_id' => $sourceType->id, 'name' => $data['source_account_name']]
);
// always make account active
$sourceAccount->active = true;
$sourceAccount->save();
Log::debug(sprintf('source account name is "%s", account is %d', $data['source_account_name'], $sourceAccount->id));
@@ -132,8 +135,11 @@ trait SupportJournalsTrait
$sourceType = AccountType::where('type', AccountType::CASH)->first();
$sourceAccount = Account::firstOrCreateEncrypted(
['user_id' => $user->id, 'account_type_id' => $sourceType->id, 'name' => 'Cash account', 'active' => 1]
['user_id' => $user->id, 'account_type_id' => $sourceType->id, 'name' => 'Cash account']
);
// always make account active
$sourceAccount->active = true;
$sourceAccount->save();
return [
'source' => $sourceAccount,
@@ -161,10 +167,13 @@ trait SupportJournalsTrait
'user_id' => $user->id,
'account_type_id' => $destinationType->id,
'name' => $data['destination_account_name'],
'active' => 1,
]
);
// always make account active
$destinationAccount->active = true;
$destinationAccount->save();
Log::debug(sprintf('destination account name is "%s", account is %d', $data['destination_account_name'], $destinationAccount->id));
return [
@@ -175,8 +184,11 @@ trait SupportJournalsTrait
Log::debug('destination_account_name is empty, so default to cash account!');
$destinationType = AccountType::where('type', AccountType::CASH)->first();
$destinationAccount = Account::firstOrCreateEncrypted(
['user_id' => $user->id, 'account_type_id' => $destinationType->id, 'name' => 'Cash account', 'active' => 1]
['user_id' => $user->id, 'account_type_id' => $destinationType->id, 'name' => 'Cash account']
);
// always make account active
$destinationAccount->active = true;
$destinationAccount->save();
return [
'source' => $sourceAccount,