/** * @param Account $account * @param Account $opposing * @param array $data * * @return TransactionJournal */ protected function storeInitialBalance(Account $account, Account $opposing, array $data) { $transactionType = TransactionType::whereType('Opening balance')->first(); $journal = TransactionJournal::create(['user_id' => $data['user'], 'transaction_type_id' => $transactionType->id, 'bill_id' => null, 'transaction_currency_id' => $data['openingBalanceCurrency'], 'description' => 'Initial balance for "' . $account->name . '"', 'completed' => true, 'date' => $data['openingBalanceDate'], 'encrypted' => true]); if ($data['openingBalance'] < 0) { $firstAccount = $opposing; $secondAccount = $account; $firstAmount = $data['openingBalance'] * -1; $secondAmount = $data['openingBalance']; } else { $firstAccount = $account; $secondAccount = $opposing; $firstAmount = $data['openingBalance']; $secondAmount = $data['openingBalance'] * -1; } $one = new Transaction(['account_id' => $firstAccount->id, 'transaction_journal_id' => $journal->id, 'amount' => $firstAmount]); $one->save(); // first transaction: from $two = new Transaction(['account_id' => $secondAccount->id, 'transaction_journal_id' => $journal->id, 'amount' => $secondAmount]); $two->save(); // second transaction: to return $journal; }
/** * @param Account $account * @param array $data * * @return TransactionJournal */ protected function storeInitialBalance(Account $account, array $data) : TransactionJournal { $amount = $data['openingBalance']; $user = $data['user']; $name = $data['name']; $opposing = $this->storeOpposingAccount($amount, $user, $name); $transactionType = TransactionType::whereType(TransactionType::OPENING_BALANCE)->first(); $journal = TransactionJournal::create(['user_id' => $data['user'], 'transaction_type_id' => $transactionType->id, 'transaction_currency_id' => $data['openingBalanceCurrency'], 'description' => 'Initial balance for "' . $account->name . '"', 'completed' => true, 'date' => $data['openingBalanceDate'], 'encrypted' => true]); $firstAccount = $account; $secondAccount = $opposing; $firstAmount = $amount; $secondAmount = $amount * -1; if ($data['openingBalance'] < 0) { $firstAccount = $opposing; $secondAccount = $account; $firstAmount = $amount * -1; $secondAmount = $amount; } $one = new Transaction(['account_id' => $firstAccount->id, 'transaction_journal_id' => $journal->id, 'amount' => $firstAmount]); $one->save(); // first transaction: from $two = new Transaction(['account_id' => $secondAccount->id, 'transaction_journal_id' => $journal->id, 'amount' => $secondAmount]); $two->save(); // second transaction: to return $journal; }