mirror of
https://github.com/firefly-iii/firefly-iii.git
synced 2025-10-12 15:35:15 +00:00
Fixed a bug where the transaction list was a giant mess.
This commit is contained in:
@@ -1,5 +1,4 @@
|
||||
<?php
|
||||
use Carbon\Carbon;
|
||||
use FireflyIII\Exception\FireflyException;
|
||||
|
||||
/**
|
||||
@@ -232,6 +231,7 @@ class GoogleTableController extends BaseController
|
||||
$chart->addColumn('Description_URL', 'string');
|
||||
$chart->addColumn('Description', 'string');
|
||||
$chart->addColumn('Amount', 'number');
|
||||
|
||||
$chart->addColumn('From_URL', 'string');
|
||||
$chart->addColumn('From', 'string');
|
||||
$chart->addColumn('To_URL', 'string');
|
||||
@@ -259,56 +259,53 @@ class GoogleTableController extends BaseController
|
||||
break;
|
||||
}
|
||||
|
||||
/** @var Transaction $transaction */
|
||||
foreach ($list as $transaction) {
|
||||
$date = $transaction->transactionJournal->date;
|
||||
$descriptionURL = route('transactions.show', $transaction->transaction_journal_id);
|
||||
$description = $transaction->transactionJournal->description;
|
||||
$amount = floatval($transaction->amount);
|
||||
/** @var TransactionJournal $journal */
|
||||
foreach ($list as $journal) {
|
||||
$date = $journal->date;
|
||||
$descriptionURL = route('transactions.show', $journal->id);
|
||||
$description = $journal->description;
|
||||
$amount = floatval(-0.01); // TODO
|
||||
$id = $journal->id;
|
||||
|
||||
|
||||
if ($journal->transactions[0]->amount < 0) {
|
||||
|
||||
$fromURL = route('accounts.show', $journal->transactions[0]->account->id);
|
||||
$fromName = $journal->transactions[0]->account->name;
|
||||
$amount = floatval($journal->transactions[0]->amount);
|
||||
|
||||
$toURL = route('accounts.show', $journal->transactions[1]->account->id);
|
||||
$toName = $journal->transactions[1]->account->name;
|
||||
|
||||
if ($transaction->transactionJournal->transactions[0]->account->id == $account->id) {
|
||||
$opposingAccountURI = route('accounts.show', $transaction->transactionJournal->transactions[1]->account->id);
|
||||
$opposingAccountName = $transaction->transactionJournal->transactions[1]->account->name;
|
||||
} else {
|
||||
$opposingAccountURI = route('accounts.show', $transaction->transactionJournal->transactions[0]->account->id);
|
||||
$opposingAccountName = $transaction->transactionJournal->transactions[0]->account->name;
|
||||
$fromURL = route('accounts.show', $journal->transactions[1]->account->id);
|
||||
$fromName = $journal->transactions[1]->account->name;
|
||||
$amount = floatval($journal->transactions[1]->amount);
|
||||
|
||||
$toURL = route('accounts.show', $journal->transactions[0]->account->id);
|
||||
$toName = $journal->transactions[0]->account->name;
|
||||
}
|
||||
if (isset($transaction->transactionJournal->budgets[0])) {
|
||||
$budgetURL = route('budgets.show', $transaction->transactionJournal->budgets[0]->id);
|
||||
$budget = $transaction->transactionJournal->budgets[0]->name;
|
||||
if (isset($journal->budgets[0])) {
|
||||
$budgetURL = route('budgets.show', $journal->budgets[0]->id);
|
||||
$budget = $journal->budgets[0]->name;
|
||||
} else {
|
||||
$budgetURL = '';
|
||||
$budget = '';
|
||||
}
|
||||
|
||||
if (isset($transaction->transactionJournal->categories[0])) {
|
||||
$categoryURL = route('categories.show', $transaction->transactionJournal->categories[0]->id);
|
||||
$category = $transaction->transactionJournal->categories[0]->name;
|
||||
if (isset($journal->categories[0])) {
|
||||
$categoryURL = route('categories.show', $journal->categories[0]->id);
|
||||
$category = $journal->categories[0]->name;
|
||||
} else {
|
||||
$categoryURL = '';
|
||||
$category = '';
|
||||
}
|
||||
|
||||
|
||||
if ($amount < 0) {
|
||||
$from = $account->name;
|
||||
$fromURL = route('accounts.show', $account->id);
|
||||
|
||||
$to = $opposingAccountName;
|
||||
$toURL = $opposingAccountURI;
|
||||
} else {
|
||||
$to = $account->name;
|
||||
$toURL = route('accounts.show', $account->id);
|
||||
|
||||
$from = $opposingAccountName;
|
||||
$fromURL = $opposingAccountURI;
|
||||
}
|
||||
|
||||
$id = $transaction->transactionJournal->id;
|
||||
$edit = route('transactions.edit', $transaction->transactionJournal->id);
|
||||
$delete = route('transactions.delete', $transaction->transactionJournal->id);
|
||||
$edit = route('transactions.edit', $journal->id);
|
||||
$delete = route('transactions.delete', $journal->id);
|
||||
$chart->addRow(
|
||||
$id, $edit, $delete, $date, $descriptionURL, $description, $amount, $fromURL, $from, $toURL, $to, $budgetURL, $budget, $categoryURL, $category
|
||||
$id, $edit, $delete, $date, $descriptionURL, $description, $amount,
|
||||
$fromURL, $fromName, $toURL, $toName,
|
||||
$budgetURL, $budget, $categoryURL, $category
|
||||
);
|
||||
}
|
||||
|
||||
|
@@ -301,7 +301,7 @@ class TransactionController extends BaseController
|
||||
if ($data['post_submit_action'] == 'create_another') {
|
||||
return Redirect::route('transactions.create', $what);
|
||||
} else {
|
||||
return Redirect::route('transactions.index');
|
||||
return Redirect::route('transactions.index',$what);
|
||||
}
|
||||
break;
|
||||
case 'validate_only':
|
||||
|
@@ -6,9 +6,9 @@ use Carbon\Carbon;
|
||||
use FireflyIII\Database\Ifaces\AccountInterface;
|
||||
use FireflyIII\Database\Ifaces\CommonDatabaseCalls;
|
||||
use FireflyIII\Database\Ifaces\CUD;
|
||||
use Illuminate\Support\Collection;
|
||||
use Illuminate\Support\MessageBag;
|
||||
use LaravelBook\Ardent\Ardent;
|
||||
use Illuminate\Support\Collection;
|
||||
|
||||
/**
|
||||
* Class Account
|
||||
@@ -58,6 +58,23 @@ class Account implements CUD, CommonDatabaseCalls, AccountInterface
|
||||
return true;
|
||||
}
|
||||
|
||||
/**
|
||||
* @param \Account $account
|
||||
*
|
||||
* @return \TransactionJournal|null
|
||||
*/
|
||||
public function openingBalanceTransaction(\Account $account)
|
||||
{
|
||||
return \TransactionJournal::withRelevantData()
|
||||
->accountIs($account)
|
||||
->leftJoin(
|
||||
'transaction_types', 'transaction_types.id', '=',
|
||||
'transaction_journals.transaction_type_id'
|
||||
)
|
||||
->where('transaction_types.type', 'Opening balance')
|
||||
->first(['transaction_journals.*']);
|
||||
}
|
||||
|
||||
/**
|
||||
* Get all asset accounts. Optional JSON based parameters.
|
||||
*
|
||||
@@ -71,21 +88,6 @@ class Account implements CUD, CommonDatabaseCalls, AccountInterface
|
||||
|
||||
}
|
||||
|
||||
/**
|
||||
* @param \Account $account
|
||||
*
|
||||
* @return \Account|null
|
||||
*/
|
||||
public function findInitialBalanceAccount(\Account $account)
|
||||
{
|
||||
/** @var \FireflyIII\Database\AccountType $acctType */
|
||||
$acctType = \App::make('FireflyIII\Database\AccountType');
|
||||
|
||||
$accountType = $acctType->findByWhat('initial');
|
||||
|
||||
return $this->getUser()->accounts()->where('account_type_id', $accountType->id)->where('name', 'LIKE', $account->name . '%')->first();
|
||||
}
|
||||
|
||||
/**
|
||||
* @param array $types
|
||||
* @param array $parameters
|
||||
@@ -146,19 +148,26 @@ class Account implements CUD, CommonDatabaseCalls, AccountInterface
|
||||
}
|
||||
|
||||
/**
|
||||
* @return int
|
||||
* @param \Account $account
|
||||
*
|
||||
* @return \Account|null
|
||||
*/
|
||||
public function countAssetAccounts()
|
||||
public function findInitialBalanceAccount(\Account $account)
|
||||
{
|
||||
return $this->countAccountsByType(['Default account', 'Asset account']);
|
||||
/** @var \FireflyIII\Database\AccountType $acctType */
|
||||
$acctType = \App::make('FireflyIII\Database\AccountType');
|
||||
|
||||
$accountType = $acctType->findByWhat('initial');
|
||||
|
||||
return $this->getUser()->accounts()->where('account_type_id', $accountType->id)->where('name', 'LIKE', $account->name . '%')->first();
|
||||
}
|
||||
|
||||
/**
|
||||
* @return int
|
||||
*/
|
||||
public function countExpenseAccounts()
|
||||
public function countAssetAccounts()
|
||||
{
|
||||
return $this->countAccountsByType(['Expense account', 'Beneficiary account']);
|
||||
return $this->countAccountsByType(['Default account', 'Asset account']);
|
||||
}
|
||||
|
||||
/**
|
||||
@@ -171,6 +180,14 @@ class Account implements CUD, CommonDatabaseCalls, AccountInterface
|
||||
return $this->getUser()->accounts()->accountTypeIn($types)->count();
|
||||
}
|
||||
|
||||
/**
|
||||
* @return int
|
||||
*/
|
||||
public function countExpenseAccounts()
|
||||
{
|
||||
return $this->countAccountsByType(['Expense account', 'Beneficiary account']);
|
||||
}
|
||||
|
||||
/**
|
||||
* @param array $parameters
|
||||
*
|
||||
@@ -200,7 +217,24 @@ class Account implements CUD, CommonDatabaseCalls, AccountInterface
|
||||
*/
|
||||
public function find($id)
|
||||
{
|
||||
// TODO: Implement find() method.
|
||||
return $this->getUser()->accounts()->find($id);
|
||||
}
|
||||
|
||||
public function firstExpenseAccountOrCreate($name)
|
||||
{
|
||||
/** @var \FireflyIII\Database\AccountType $accountTypeRepos */
|
||||
$accountTypeRepos = \App::make('FireflyIII\Database\AccountType');
|
||||
|
||||
$accountType = $accountTypeRepos->findByWhat('expense');
|
||||
|
||||
$data = [
|
||||
'user_id' => $this->getUser()->id,
|
||||
'account_type_id' => $accountType->id,
|
||||
'name' => $name,
|
||||
'active' => 1
|
||||
];
|
||||
return \Account::firstOrCreate($data);
|
||||
|
||||
}
|
||||
|
||||
/**
|
||||
@@ -247,23 +281,6 @@ class Account implements CUD, CommonDatabaseCalls, AccountInterface
|
||||
|
||||
}
|
||||
|
||||
/**
|
||||
* @param \Account $account
|
||||
*
|
||||
* @return \TransactionJournal|null
|
||||
*/
|
||||
public function openingBalanceTransaction(\Account $account)
|
||||
{
|
||||
return \TransactionJournal::withRelevantData()
|
||||
->accountIs($account)
|
||||
->leftJoin(
|
||||
'transaction_types', 'transaction_types.id', '=',
|
||||
'transaction_journals.transaction_type_id'
|
||||
)
|
||||
->where('transaction_types.type', 'Opening balance')
|
||||
->first(['transaction_journals.*']);
|
||||
}
|
||||
|
||||
/**
|
||||
* Validates a model. Returns an array containing MessageBags
|
||||
* errors/warnings/successes.
|
||||
|
@@ -240,7 +240,7 @@ class TransactionJournal implements TransactionJournalInterface, CUD, CommonData
|
||||
$errors->add('account_to_id', 'Invalid account selected.');
|
||||
|
||||
} else {
|
||||
if (intval($model['account_from_id']) == intval($model['account_from_id'])) {
|
||||
if (intval($model['account_from_id']) == intval($model['account_to_id'])) {
|
||||
$errors->add('account_to_id', 'Cannot be the same as "from" account.');
|
||||
$errors->add('account_from_id', 'Cannot be the same as "to" account.');
|
||||
} else {
|
||||
@@ -319,6 +319,9 @@ class TransactionJournal implements TransactionJournalInterface, CUD, CommonData
|
||||
/** @var \FireflyIII\Database\TransactionType $typeRepository */
|
||||
$typeRepository = \App::make('FireflyIII\Database\TransactionType');
|
||||
|
||||
/** @var \FireflyIII\Database\Account $accountRepository */
|
||||
$accountRepository = \App::make('FireflyIII\Database\Account');
|
||||
|
||||
/** @var \FireflyIII\Database\TransactionCurrency $currencyRepository */
|
||||
$currencyRepository = \App::make('FireflyIII\Database\TransactionCurrency');
|
||||
|
||||
@@ -335,17 +338,33 @@ class TransactionJournal implements TransactionJournalInterface, CUD, CommonData
|
||||
$journal->description = $data['description'];
|
||||
$journal->date = $data['date'];
|
||||
$journal->completed = 0;
|
||||
//$journal->user_id = $this->getUser()->id;
|
||||
|
||||
/*
|
||||
* This must be enough to store the journal:
|
||||
*/
|
||||
if (!$journal->validate()) {
|
||||
\Log::error($journal->errors()->all());
|
||||
throw new FireflyException('store() transactionjournal failed, but it should not!');
|
||||
throw new FireflyException('store() transaction journal failed, but it should not!');
|
||||
}
|
||||
$journal->save();
|
||||
|
||||
/*
|
||||
* Still need to find the accounts related to the transactions.
|
||||
* This depends on the type of transaction.
|
||||
*/
|
||||
switch ($data['what']) {
|
||||
case 'withdrawal':
|
||||
$data['from'] = $accountRepository->find($data['account_id']);
|
||||
$data['to'] = $accountRepository->firstExpenseAccountOrCreate($data['expense_account']);
|
||||
break;
|
||||
case 'opening':
|
||||
break;
|
||||
|
||||
default:
|
||||
throw new FireflyException('Cannot save transaction journal with accounts based on $what "' . $data['what'] . '".');
|
||||
break;
|
||||
}
|
||||
|
||||
/*
|
||||
* Then store both transactions.
|
||||
*/
|
||||
|
@@ -3,11 +3,12 @@
|
||||
namespace FireflyIII\Database;
|
||||
|
||||
|
||||
use Illuminate\Support\Collection;
|
||||
use LaravelBook\Ardent\Ardent;
|
||||
use FireflyIII\Database\Ifaces\CommonDatabaseCalls;
|
||||
use FireflyIII\Database\Ifaces\CUD;
|
||||
use FireflyIII\Database\Ifaces\TransactionTypeInterface;
|
||||
use FireflyIII\Exception\FireflyException;
|
||||
use Illuminate\Support\Collection;
|
||||
use LaravelBook\Ardent\Ardent;
|
||||
|
||||
/**
|
||||
* Class TransactionType
|
||||
@@ -98,10 +99,17 @@ class TransactionType implements TransactionTypeInterface, CUD, CommonDatabaseCa
|
||||
case 'opening':
|
||||
return \TransactionType::whereType('Opening balance')->first();
|
||||
break;
|
||||
case 'transfer':
|
||||
return \TransactionType::whereType('Transfer')->first();
|
||||
break;
|
||||
case 'withdrawal':
|
||||
return \TransactionType::whereType('Withdrawal')->first();
|
||||
break;
|
||||
default:
|
||||
throw new FireflyException('Cannot find transaction type described as "' . e($what) . '".');
|
||||
break;
|
||||
|
||||
|
||||
}
|
||||
return null;
|
||||
}
|
||||
|
Reference in New Issue
Block a user