mirror of
https://github.com/firefly-iii/firefly-iii.git
synced 2024-12-25 16:31:15 -06:00
Fix some bugs related to cash accounts.
This commit is contained in:
parent
781621960d
commit
ee6b72afa5
@ -134,7 +134,9 @@ class JournalCollector implements JournalCollectorInterface
|
||||
{
|
||||
$this->run = true;
|
||||
$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.
|
||||
$set->each(
|
||||
@ -374,6 +376,7 @@ class JournalCollector implements JournalCollectorInterface
|
||||
public function setTypes(array $types): JournalCollectorInterface
|
||||
{
|
||||
if (count($types) > 0) {
|
||||
Log::debug('Set query collector types', $types);
|
||||
$this->query->whereIn('transaction_types.type', $types);
|
||||
}
|
||||
|
||||
@ -390,7 +393,9 @@ class JournalCollector implements JournalCollectorInterface
|
||||
$accountIds = $this->accountIds;
|
||||
$this->query->where(
|
||||
function (EloquentBuilder $q1) use ($accountIds) {
|
||||
// set 1
|
||||
// set 1:
|
||||
// where source is in the set of $accounts
|
||||
// but destination is not.
|
||||
$q1->where(
|
||||
function (EloquentBuilder $q2) use ($accountIds) {
|
||||
// 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(
|
||||
function (EloquentBuilder $q3) use ($accountIds) {
|
||||
// transactions.account_id not in set
|
||||
|
@ -189,9 +189,9 @@ class SingleController extends Controller
|
||||
'budget_id' => TransactionJournal::budgetId($journal),
|
||||
'tags' => join(',', $journal->tags->pluck('tag')->toArray()),
|
||||
'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_name' => $destinationAccounts->first()->name,
|
||||
'destination_account_name' => $destinationAccounts->first()->edit_name,
|
||||
'amount' => TransactionJournal::amountPositive($journal),
|
||||
|
||||
// new custom fields:
|
||||
|
@ -19,6 +19,7 @@ use FireflyIII\Models\TransactionJournal;
|
||||
use FireflyIII\Repositories\Journal\JournalRepositoryInterface;
|
||||
use FireflyIII\Repositories\Journal\JournalTaskerInterface;
|
||||
use Illuminate\Http\Request;
|
||||
use Log;
|
||||
use Preferences;
|
||||
use Response;
|
||||
use View;
|
||||
@ -63,8 +64,13 @@ class TransactionController extends Controller
|
||||
$subTitle = trans('firefly.title_' . $what);
|
||||
$page = intval($request->get('page')) === 0 ? 1 : intval($request->get('page'));
|
||||
$collector = new JournalCollector(auth()->user());
|
||||
$collector->setTypes($types)->setLimit($pageSize)->setPage($page)->setAllAssetAccounts()
|
||||
->withOpposingAccount();
|
||||
$collector->setTypes($types)->setLimit($pageSize)->setPage($page)->setAllAssetAccounts();
|
||||
|
||||
// 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->setPath('transactions/' . $what);
|
||||
|
@ -119,6 +119,20 @@ class Account extends Model
|
||||
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
|
||||
*
|
||||
@ -229,20 +243,6 @@ class Account extends Model
|
||||
return $journal->date;
|
||||
}
|
||||
|
||||
/**
|
||||
* @return string
|
||||
*/
|
||||
public function nameForEdit(): string
|
||||
{
|
||||
$name = $this->name;
|
||||
|
||||
if ($this->accountType->type === AccountType::CASH) {
|
||||
return '';
|
||||
}
|
||||
|
||||
return $name;
|
||||
}
|
||||
|
||||
/**
|
||||
* @return HasMany
|
||||
*/
|
||||
|
@ -15,6 +15,7 @@ namespace FireflyIII\Repositories\Journal;
|
||||
|
||||
use Crypt;
|
||||
use DB;
|
||||
use FireflyIII\Models\AccountType;
|
||||
use FireflyIII\Models\PiggyBankEvent;
|
||||
use FireflyIII\Models\Transaction;
|
||||
use FireflyIII\Models\TransactionJournal;
|
||||
@ -114,7 +115,9 @@ class JournalTasker implements JournalTaskerInterface
|
||||
)
|
||||
->with(['budgets', 'categories'])
|
||||
->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('account_types as destination_account_types', 'destination_accounts.account_type_id', '=', 'destination_account_types.id')
|
||||
->where('transactions.amount', '<', 0)
|
||||
->whereNull('transactions.deleted_at')
|
||||
->get(
|
||||
@ -123,12 +126,14 @@ class JournalTasker implements JournalTaskerInterface
|
||||
'transactions.account_id',
|
||||
'source_accounts.name as account_name',
|
||||
'source_accounts.encrypted as account_encrypted',
|
||||
'source_account_types.type as account_type',
|
||||
'transactions.amount',
|
||||
'transactions.description',
|
||||
'destination.id as destination_id',
|
||||
'destination.account_id as destination_account_id',
|
||||
'destination_accounts.name as destination_account_name',
|
||||
'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();
|
||||
$category = $entry->categories->first();
|
||||
$transaction = [
|
||||
'source_id' => $entry->id,
|
||||
'source_amount' => $entry->amount,
|
||||
|
||||
'source_id' => $entry->id,
|
||||
'source_amount' => $entry->amount,
|
||||
'description' => $entry->description,
|
||||
'source_account_id' => $entry->account_id,
|
||||
'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_after' => bcadd($sourceBalance, $entry->amount),
|
||||
'destination_id' => $entry->destination_id,
|
||||
'destination_amount' => bcmul($entry->amount, '-1'),
|
||||
'destination_account_id' => $entry->destination_account_id,
|
||||
'destination_account_type' => $entry->destination_account_type,
|
||||
'destination_account_name' =>
|
||||
intval($entry->destination_account_encrypted) === 1 ? Crypt::decrypt($entry->destination_account_name) : $entry->destination_account_name,
|
||||
'destination_account_before' => $destinationBalance,
|
||||
@ -159,6 +165,13 @@ class JournalTasker implements JournalTaskerInterface
|
||||
'budget_id' => is_null($budget) ? 0 : $budget->id,
|
||||
'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;
|
||||
|
@ -277,14 +277,24 @@
|
||||
{% endif %}
|
||||
</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>
|
||||
{{ formatAmountWithCode(transaction.source_account_before,journal.transactionCurrency.code) }}
|
||||
⟶ {{ formatAmountWithCode(transaction.source_account_after,journal.transactionCurrency.code) }}
|
||||
</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>
|
||||
{{ formatAmountWithCode(transaction.destination_account_before,journal.transactionCurrency.code) }}
|
||||
@ -313,27 +323,6 @@
|
||||
{{ transactionIdCategories(transaction.source_id) }}
|
||||
</td>
|
||||
</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 %}
|
||||
</tbody>
|
||||
</table>
|
||||
|
Loading…
Reference in New Issue
Block a user