mirror of
https://github.com/firefly-iii/firefly-iii.git
synced 2025-02-25 18:45:27 -06:00
Fixed the income report.
This commit is contained in:
parent
5cd1e7c100
commit
eedf6a07f0
@ -24,7 +24,7 @@ class EntryAccount
|
|||||||
public $iban;
|
public $iban;
|
||||||
/** @var string */
|
/** @var string */
|
||||||
public $name;
|
public $name;
|
||||||
/** @var int */
|
/** @var string */
|
||||||
public $number;
|
public $number;
|
||||||
/** @var string */
|
/** @var string */
|
||||||
public $type;
|
public $type;
|
||||||
|
@ -18,7 +18,7 @@ use FireflyIII\Models\Bill;
|
|||||||
*/
|
*/
|
||||||
class EntryBill
|
class EntryBill
|
||||||
{
|
{
|
||||||
/** @var string */
|
/** @var int */
|
||||||
public $billId = '';
|
public $billId = '';
|
||||||
/** @var string */
|
/** @var string */
|
||||||
public $name = '';
|
public $name = '';
|
||||||
|
@ -18,7 +18,7 @@ use FireflyIII\Models\Budget;
|
|||||||
*/
|
*/
|
||||||
class EntryBudget
|
class EntryBudget
|
||||||
{
|
{
|
||||||
/** @var string */
|
/** @var int */
|
||||||
public $budgetId = '';
|
public $budgetId = '';
|
||||||
/** @var string */
|
/** @var string */
|
||||||
public $name = '';
|
public $name = '';
|
||||||
|
@ -18,7 +18,7 @@ use FireflyIII\Models\Category;
|
|||||||
*/
|
*/
|
||||||
class EntryCategory
|
class EntryCategory
|
||||||
{
|
{
|
||||||
/** @var string */
|
/** @var int */
|
||||||
public $categoryId = '';
|
public $categoryId = '';
|
||||||
/** @var string */
|
/** @var string */
|
||||||
public $name = '';
|
public $name = '';
|
||||||
|
@ -166,8 +166,7 @@ class ReportHelper implements ReportHelperInterface
|
|||||||
$object = new Income;
|
$object = new Income;
|
||||||
/** @var AccountRepositoryInterface $repos */
|
/** @var AccountRepositoryInterface $repos */
|
||||||
$repos = app(AccountRepositoryInterface::class);
|
$repos = app(AccountRepositoryInterface::class);
|
||||||
$types = [TransactionType::DEPOSIT, TransactionType::TRANSFER];
|
$journals = $repos->incomesInPeriod($accounts, $start, $end);
|
||||||
$journals = $repos->journalsInPeriod($accounts, $types, $start, $end);
|
|
||||||
|
|
||||||
foreach ($journals as $entry) {
|
foreach ($journals as $entry) {
|
||||||
$amount = TransactionJournal::amount($entry);
|
$amount = TransactionJournal::amount($entry);
|
||||||
|
@ -18,6 +18,7 @@ use Symfony\Component\HttpKernel\Exception\NotFoundHttpException;
|
|||||||
* @property float $amount
|
* @property float $amount
|
||||||
* @property-read BudgetLimit $budgetLimit
|
* @property-read BudgetLimit $budgetLimit
|
||||||
* @property int $budget_id
|
* @property int $budget_id
|
||||||
|
* @property string $spent
|
||||||
* @method static \Illuminate\Database\Query\Builder|\FireflyIII\Models\LimitRepetition whereId($value)
|
* @method static \Illuminate\Database\Query\Builder|\FireflyIII\Models\LimitRepetition whereId($value)
|
||||||
* @method static \Illuminate\Database\Query\Builder|\FireflyIII\Models\LimitRepetition whereCreatedAt($value)
|
* @method static \Illuminate\Database\Query\Builder|\FireflyIII\Models\LimitRepetition whereCreatedAt($value)
|
||||||
* @method static \Illuminate\Database\Query\Builder|\FireflyIII\Models\LimitRepetition whereUpdatedAt($value)
|
* @method static \Illuminate\Database\Query\Builder|\FireflyIII\Models\LimitRepetition whereUpdatedAt($value)
|
||||||
|
@ -300,6 +300,44 @@ class AccountRepository implements AccountRepositoryInterface
|
|||||||
return $accounts;
|
return $accounts;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* This method will call AccountRepositoryInterface::journalsInPeriod and get all deposits made by the given $accounts,
|
||||||
|
* as well as the transfers that move away from those $accounts. This is a slightly sharper selection
|
||||||
|
* than made by journalsInPeriod itself.
|
||||||
|
*
|
||||||
|
* @param Collection $accounts
|
||||||
|
* @param Carbon $start
|
||||||
|
* @param Carbon $end
|
||||||
|
*
|
||||||
|
* @see AccountRepositoryInterface::journalsInPeriod
|
||||||
|
*
|
||||||
|
* @return Collection
|
||||||
|
*/
|
||||||
|
public function incomesInPeriod(Collection $accounts, Carbon $start, Carbon $end): Collection
|
||||||
|
{
|
||||||
|
$types = [TransactionType::DEPOSIT, TransactionType::TRANSFER];
|
||||||
|
$journals = $this->journalsInPeriod($accounts, $types, $start, $end);
|
||||||
|
$accountIds = $accounts->pluck('id')->toArray();
|
||||||
|
|
||||||
|
// filter because some of these journals are
|
||||||
|
$journals = $journals->filter(
|
||||||
|
function (TransactionJournal $journal) use ($accountIds) {
|
||||||
|
if ($journal->transaction_type_type == TransactionType::DEPOSIT) {
|
||||||
|
return $journal;
|
||||||
|
}
|
||||||
|
/*
|
||||||
|
* The destination of a transfer must be one of the $accounts in order to
|
||||||
|
* be included. Otherwise, it would not be income.
|
||||||
|
*/
|
||||||
|
if (in_array($journal->destination_account_id, $accountIds)) {
|
||||||
|
return $journal;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
);
|
||||||
|
|
||||||
|
return $journals;
|
||||||
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* @param Collection $accounts
|
* @param Collection $accounts
|
||||||
* @param array $types
|
* @param array $types
|
||||||
@ -337,7 +375,10 @@ class AccountRepository implements AccountRepositoryInterface
|
|||||||
|
|
||||||
}
|
}
|
||||||
// that should do it:
|
// that should do it:
|
||||||
$complete = $query->get(TransactionJournal::queryFields());
|
$fields = TransactionJournal::queryFields();
|
||||||
|
$fields[] = 'source.account_id as source_account_id';
|
||||||
|
$fields[] = 'destination.account_id as destination_account_id';
|
||||||
|
$complete = $query->get($fields);
|
||||||
|
|
||||||
return $complete;
|
return $complete;
|
||||||
}
|
}
|
||||||
|
@ -8,7 +8,6 @@ use FireflyIII\Models\Account;
|
|||||||
use FireflyIII\Models\AccountMeta;
|
use FireflyIII\Models\AccountMeta;
|
||||||
use FireflyIII\Models\Transaction;
|
use FireflyIII\Models\Transaction;
|
||||||
use FireflyIII\Models\TransactionJournal;
|
use FireflyIII\Models\TransactionJournal;
|
||||||
use Illuminate\Pagination\LengthAwarePaginator;
|
|
||||||
use Illuminate\Support\Collection;
|
use Illuminate\Support\Collection;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
@ -108,6 +107,21 @@ interface AccountRepositoryInterface
|
|||||||
*/
|
*/
|
||||||
public function getSavingsAccounts(Carbon $start, Carbon $end): Collection;
|
public function getSavingsAccounts(Carbon $start, Carbon $end): Collection;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* This method will call AccountRepositoryInterface::journalsInPeriod and get all deposits made by the given $accounts,
|
||||||
|
* as well as the transfers that move away from those $accounts. This is a slightly sharper selection
|
||||||
|
* than made by journalsInPeriod itself.
|
||||||
|
*
|
||||||
|
* @param Collection $accounts
|
||||||
|
* @param Carbon $start
|
||||||
|
* @param Carbon $end
|
||||||
|
*
|
||||||
|
* @see AccountRepositoryInterface::journalsInPeriod
|
||||||
|
*
|
||||||
|
* @return Collection
|
||||||
|
*/
|
||||||
|
public function incomesInPeriod(Collection $accounts, Carbon $start, Carbon $end): Collection;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* @param Collection $accounts
|
* @param Collection $accounts
|
||||||
* @param array $types
|
* @param array $types
|
||||||
|
Loading…
Reference in New Issue
Block a user