mirror of
https://github.com/firefly-iii/firefly-iii.git
synced 2025-09-18 18:44:16 +00:00
Fix some bugs related to cash accounts.
This commit is contained in:
@@ -134,7 +134,9 @@ class JournalCollector implements JournalCollectorInterface
|
|||||||
{
|
{
|
||||||
$this->run = true;
|
$this->run = true;
|
||||||
$set = $this->query->get(array_values($this->fields));
|
$set = $this->query->get(array_values($this->fields));
|
||||||
$set = $this->filterTransfers($set);
|
Log::debug(sprintf('Count of set is %d', $set->count()));
|
||||||
|
$set = $this->filterTransfers($set);
|
||||||
|
Log::debug(sprintf('Count of set after filterTransfers() is %d', $set->count()));
|
||||||
|
|
||||||
// loop for decryption.
|
// loop for decryption.
|
||||||
$set->each(
|
$set->each(
|
||||||
@@ -374,6 +376,7 @@ class JournalCollector implements JournalCollectorInterface
|
|||||||
public function setTypes(array $types): JournalCollectorInterface
|
public function setTypes(array $types): JournalCollectorInterface
|
||||||
{
|
{
|
||||||
if (count($types) > 0) {
|
if (count($types) > 0) {
|
||||||
|
Log::debug('Set query collector types', $types);
|
||||||
$this->query->whereIn('transaction_types.type', $types);
|
$this->query->whereIn('transaction_types.type', $types);
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -390,7 +393,9 @@ class JournalCollector implements JournalCollectorInterface
|
|||||||
$accountIds = $this->accountIds;
|
$accountIds = $this->accountIds;
|
||||||
$this->query->where(
|
$this->query->where(
|
||||||
function (EloquentBuilder $q1) use ($accountIds) {
|
function (EloquentBuilder $q1) use ($accountIds) {
|
||||||
// set 1
|
// set 1:
|
||||||
|
// where source is in the set of $accounts
|
||||||
|
// but destination is not.
|
||||||
$q1->where(
|
$q1->where(
|
||||||
function (EloquentBuilder $q2) use ($accountIds) {
|
function (EloquentBuilder $q2) use ($accountIds) {
|
||||||
// transactions.account_id in set
|
// transactions.account_id in set
|
||||||
@@ -400,7 +405,9 @@ class JournalCollector implements JournalCollectorInterface
|
|||||||
|
|
||||||
}
|
}
|
||||||
);
|
);
|
||||||
// or set 2
|
// set 1:
|
||||||
|
// where source is not in the set of $accounts
|
||||||
|
// but destination is.
|
||||||
$q1->orWhere(
|
$q1->orWhere(
|
||||||
function (EloquentBuilder $q3) use ($accountIds) {
|
function (EloquentBuilder $q3) use ($accountIds) {
|
||||||
// transactions.account_id not in set
|
// transactions.account_id not in set
|
||||||
|
@@ -189,9 +189,9 @@ class SingleController extends Controller
|
|||||||
'budget_id' => TransactionJournal::budgetId($journal),
|
'budget_id' => TransactionJournal::budgetId($journal),
|
||||||
'tags' => join(',', $journal->tags->pluck('tag')->toArray()),
|
'tags' => join(',', $journal->tags->pluck('tag')->toArray()),
|
||||||
'source_account_id' => $sourceAccounts->first()->id,
|
'source_account_id' => $sourceAccounts->first()->id,
|
||||||
'source_account_name' => $sourceAccounts->first()->name,
|
'source_account_name' => $sourceAccounts->first()->edit_name,
|
||||||
'destination_account_id' => $destinationAccounts->first()->id,
|
'destination_account_id' => $destinationAccounts->first()->id,
|
||||||
'destination_account_name' => $destinationAccounts->first()->name,
|
'destination_account_name' => $destinationAccounts->first()->edit_name,
|
||||||
'amount' => TransactionJournal::amountPositive($journal),
|
'amount' => TransactionJournal::amountPositive($journal),
|
||||||
|
|
||||||
// new custom fields:
|
// new custom fields:
|
||||||
|
@@ -19,6 +19,7 @@ use FireflyIII\Models\TransactionJournal;
|
|||||||
use FireflyIII\Repositories\Journal\JournalRepositoryInterface;
|
use FireflyIII\Repositories\Journal\JournalRepositoryInterface;
|
||||||
use FireflyIII\Repositories\Journal\JournalTaskerInterface;
|
use FireflyIII\Repositories\Journal\JournalTaskerInterface;
|
||||||
use Illuminate\Http\Request;
|
use Illuminate\Http\Request;
|
||||||
|
use Log;
|
||||||
use Preferences;
|
use Preferences;
|
||||||
use Response;
|
use Response;
|
||||||
use View;
|
use View;
|
||||||
@@ -63,8 +64,13 @@ class TransactionController extends Controller
|
|||||||
$subTitle = trans('firefly.title_' . $what);
|
$subTitle = trans('firefly.title_' . $what);
|
||||||
$page = intval($request->get('page')) === 0 ? 1 : intval($request->get('page'));
|
$page = intval($request->get('page')) === 0 ? 1 : intval($request->get('page'));
|
||||||
$collector = new JournalCollector(auth()->user());
|
$collector = new JournalCollector(auth()->user());
|
||||||
$collector->setTypes($types)->setLimit($pageSize)->setPage($page)->setAllAssetAccounts()
|
$collector->setTypes($types)->setLimit($pageSize)->setPage($page)->setAllAssetAccounts();
|
||||||
->withOpposingAccount();
|
|
||||||
|
// do not filter transfers if $what = transfer.
|
||||||
|
if (!in_array($what, ['transfer', 'transfers'])) {
|
||||||
|
Log::debug('Also get opposing account info.');
|
||||||
|
$collector->withOpposingAccount();
|
||||||
|
}
|
||||||
|
|
||||||
$journals = $collector->getPaginatedJournals();
|
$journals = $collector->getPaginatedJournals();
|
||||||
$journals->setPath('transactions/' . $what);
|
$journals->setPath('transactions/' . $what);
|
||||||
|
@@ -119,6 +119,20 @@ class Account extends Model
|
|||||||
return $this->belongsTo('FireflyIII\Models\AccountType');
|
return $this->belongsTo('FireflyIII\Models\AccountType');
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @return string
|
||||||
|
*/
|
||||||
|
public function getEditNameAttribute(): string
|
||||||
|
{
|
||||||
|
$name = $this->name;
|
||||||
|
|
||||||
|
if ($this->accountType->type === AccountType::CASH) {
|
||||||
|
return '';
|
||||||
|
}
|
||||||
|
|
||||||
|
return $name;
|
||||||
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* FIxxME can return null
|
* FIxxME can return null
|
||||||
*
|
*
|
||||||
@@ -229,20 +243,6 @@ class Account extends Model
|
|||||||
return $journal->date;
|
return $journal->date;
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
|
||||||
* @return string
|
|
||||||
*/
|
|
||||||
public function nameForEdit(): string
|
|
||||||
{
|
|
||||||
$name = $this->name;
|
|
||||||
|
|
||||||
if ($this->accountType->type === AccountType::CASH) {
|
|
||||||
return '';
|
|
||||||
}
|
|
||||||
|
|
||||||
return $name;
|
|
||||||
}
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* @return HasMany
|
* @return HasMany
|
||||||
*/
|
*/
|
||||||
|
@@ -15,6 +15,7 @@ namespace FireflyIII\Repositories\Journal;
|
|||||||
|
|
||||||
use Crypt;
|
use Crypt;
|
||||||
use DB;
|
use DB;
|
||||||
|
use FireflyIII\Models\AccountType;
|
||||||
use FireflyIII\Models\PiggyBankEvent;
|
use FireflyIII\Models\PiggyBankEvent;
|
||||||
use FireflyIII\Models\Transaction;
|
use FireflyIII\Models\Transaction;
|
||||||
use FireflyIII\Models\TransactionJournal;
|
use FireflyIII\Models\TransactionJournal;
|
||||||
@@ -114,7 +115,9 @@ class JournalTasker implements JournalTaskerInterface
|
|||||||
)
|
)
|
||||||
->with(['budgets', 'categories'])
|
->with(['budgets', 'categories'])
|
||||||
->leftJoin('accounts as source_accounts', 'transactions.account_id', '=', 'source_accounts.id')
|
->leftJoin('accounts as source_accounts', 'transactions.account_id', '=', 'source_accounts.id')
|
||||||
|
->leftJoin('account_types as source_account_types', 'source_accounts.account_type_id', '=', 'source_account_types.id')
|
||||||
->leftJoin('accounts as destination_accounts', 'destination.account_id', '=', 'destination_accounts.id')
|
->leftJoin('accounts as destination_accounts', 'destination.account_id', '=', 'destination_accounts.id')
|
||||||
|
->leftJoin('account_types as destination_account_types', 'destination_accounts.account_type_id', '=', 'destination_account_types.id')
|
||||||
->where('transactions.amount', '<', 0)
|
->where('transactions.amount', '<', 0)
|
||||||
->whereNull('transactions.deleted_at')
|
->whereNull('transactions.deleted_at')
|
||||||
->get(
|
->get(
|
||||||
@@ -123,12 +126,14 @@ class JournalTasker implements JournalTaskerInterface
|
|||||||
'transactions.account_id',
|
'transactions.account_id',
|
||||||
'source_accounts.name as account_name',
|
'source_accounts.name as account_name',
|
||||||
'source_accounts.encrypted as account_encrypted',
|
'source_accounts.encrypted as account_encrypted',
|
||||||
|
'source_account_types.type as account_type',
|
||||||
'transactions.amount',
|
'transactions.amount',
|
||||||
'transactions.description',
|
'transactions.description',
|
||||||
'destination.id as destination_id',
|
'destination.id as destination_id',
|
||||||
'destination.account_id as destination_account_id',
|
'destination.account_id as destination_account_id',
|
||||||
'destination_accounts.name as destination_account_name',
|
'destination_accounts.name as destination_account_name',
|
||||||
'destination_accounts.encrypted as destination_account_encrypted',
|
'destination_accounts.encrypted as destination_account_encrypted',
|
||||||
|
'destination_account_types.type as destination_account_type',
|
||||||
]
|
]
|
||||||
);
|
);
|
||||||
|
|
||||||
@@ -141,17 +146,18 @@ class JournalTasker implements JournalTaskerInterface
|
|||||||
$budget = $entry->budgets->first();
|
$budget = $entry->budgets->first();
|
||||||
$category = $entry->categories->first();
|
$category = $entry->categories->first();
|
||||||
$transaction = [
|
$transaction = [
|
||||||
'source_id' => $entry->id,
|
'source_id' => $entry->id,
|
||||||
'source_amount' => $entry->amount,
|
'source_amount' => $entry->amount,
|
||||||
|
|
||||||
'description' => $entry->description,
|
'description' => $entry->description,
|
||||||
'source_account_id' => $entry->account_id,
|
'source_account_id' => $entry->account_id,
|
||||||
'source_account_name' => intval($entry->account_encrypted) === 1 ? Crypt::decrypt($entry->account_name) : $entry->account_name,
|
'source_account_name' => intval($entry->account_encrypted) === 1 ? Crypt::decrypt($entry->account_name) : $entry->account_name,
|
||||||
|
'source_account_type' => $entry->account_type,
|
||||||
'source_account_before' => $sourceBalance,
|
'source_account_before' => $sourceBalance,
|
||||||
'source_account_after' => bcadd($sourceBalance, $entry->amount),
|
'source_account_after' => bcadd($sourceBalance, $entry->amount),
|
||||||
'destination_id' => $entry->destination_id,
|
'destination_id' => $entry->destination_id,
|
||||||
'destination_amount' => bcmul($entry->amount, '-1'),
|
'destination_amount' => bcmul($entry->amount, '-1'),
|
||||||
'destination_account_id' => $entry->destination_account_id,
|
'destination_account_id' => $entry->destination_account_id,
|
||||||
|
'destination_account_type' => $entry->destination_account_type,
|
||||||
'destination_account_name' =>
|
'destination_account_name' =>
|
||||||
intval($entry->destination_account_encrypted) === 1 ? Crypt::decrypt($entry->destination_account_name) : $entry->destination_account_name,
|
intval($entry->destination_account_encrypted) === 1 ? Crypt::decrypt($entry->destination_account_name) : $entry->destination_account_name,
|
||||||
'destination_account_before' => $destinationBalance,
|
'destination_account_before' => $destinationBalance,
|
||||||
@@ -159,6 +165,13 @@ class JournalTasker implements JournalTaskerInterface
|
|||||||
'budget_id' => is_null($budget) ? 0 : $budget->id,
|
'budget_id' => is_null($budget) ? 0 : $budget->id,
|
||||||
'category' => is_null($category) ? '' : $category->name,
|
'category' => is_null($category) ? '' : $category->name,
|
||||||
];
|
];
|
||||||
|
if ($entry->destination_account_type === AccountType::CASH) {
|
||||||
|
$transaction['destination_account_name'] = '';
|
||||||
|
}
|
||||||
|
|
||||||
|
if ($entry->account_type === AccountType::CASH) {
|
||||||
|
$transaction['source_account_name'] = '';
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
$transactions[] = $transaction;
|
$transactions[] = $transaction;
|
||||||
|
@@ -277,14 +277,24 @@
|
|||||||
{% endif %}
|
{% endif %}
|
||||||
</td>
|
</td>
|
||||||
<td>
|
<td>
|
||||||
<a href="{{ route('accounts.show', transaction.source_account_id) }}">{{ transaction.source_account_name }}</a>
|
{% if transaction.source_account_type == 'Cash account' %}
|
||||||
|
<span class="text-success">(cash)</span>
|
||||||
|
{% else %}
|
||||||
|
<a href="{{ route('accounts.show', transaction.source_account_id) }}">{{ transaction.source_account_name }}</a>
|
||||||
|
{% endif %}
|
||||||
|
|
||||||
</td>
|
</td>
|
||||||
<td>
|
<td>
|
||||||
{{ formatAmountWithCode(transaction.source_account_before,journal.transactionCurrency.code) }}
|
{{ formatAmountWithCode(transaction.source_account_before,journal.transactionCurrency.code) }}
|
||||||
⟶ {{ formatAmountWithCode(transaction.source_account_after,journal.transactionCurrency.code) }}
|
⟶ {{ formatAmountWithCode(transaction.source_account_after,journal.transactionCurrency.code) }}
|
||||||
</td>
|
</td>
|
||||||
<td>
|
<td>
|
||||||
<a href="{{ route('accounts.show', transaction.destination_account_id) }}">{{ transaction.destination_account_name }}</a>
|
{% if transaction.destination_account_type == 'Cash account' %}
|
||||||
|
<span class="text-success">(cash)</span>
|
||||||
|
{% else %}
|
||||||
|
<a href="{{ route('accounts.show', transaction.destination_account_id) }}">{{ transaction.destination_account_name }}</a>
|
||||||
|
{% endif %}
|
||||||
|
|
||||||
</td>
|
</td>
|
||||||
<td>
|
<td>
|
||||||
{{ formatAmountWithCode(transaction.destination_account_before,journal.transactionCurrency.code) }}
|
{{ formatAmountWithCode(transaction.destination_account_before,journal.transactionCurrency.code) }}
|
||||||
@@ -313,27 +323,6 @@
|
|||||||
{{ transactionIdCategories(transaction.source_id) }}
|
{{ transactionIdCategories(transaction.source_id) }}
|
||||||
</td>
|
</td>
|
||||||
</tr>
|
</tr>
|
||||||
{#
|
|
||||||
<tr>
|
|
||||||
<td>
|
|
||||||
{% if (index+1) != transactions|length or what == 'transfer' %}
|
|
||||||
{{ t.description }}
|
|
||||||
{% endif %}
|
|
||||||
</td>
|
|
||||||
<td><a href="{{ route('accounts.show',t.account.id) }}">{{ t.account.name }}</a> ({{ t.account.accounttype.type|_ }})</td>
|
|
||||||
<td>{{ t.sum|formatAmount }}</td>
|
|
||||||
<td>{{ t.before|formatAmount }} → {{ (t.sum+t.before)|formatAmount }}</td>
|
|
||||||
<td>
|
|
||||||
{% if (index+1) != transactions|length or what == 'transfer' %}
|
|
||||||
{{ transactionBudgets(t)|raw }}
|
|
||||||
{% endif %}
|
|
||||||
</td>
|
|
||||||
<td>
|
|
||||||
{% if (index+1) != transactions|length or what == 'transfer' %}
|
|
||||||
{{ transactionCategories(t)|raw }}
|
|
||||||
{% endif %}
|
|
||||||
</td>
|
|
||||||
#}
|
|
||||||
{% endfor %}
|
{% endfor %}
|
||||||
</tbody>
|
</tbody>
|
||||||
</table>
|
</table>
|
||||||
|
Reference in New Issue
Block a user