mirror of
https://github.com/firefly-iii/firefly-iii.git
synced 2025-01-03 12:47:17 -06:00
Cleanup.
This commit is contained in:
parent
3896a66122
commit
3270d3bf96
@ -85,55 +85,4 @@ class ReportHelper implements ReportHelperInterface
|
||||
return $months;
|
||||
}
|
||||
|
||||
/**
|
||||
* @param Carbon $date
|
||||
* @param bool $includeShared
|
||||
*
|
||||
* @return array
|
||||
*/
|
||||
public function yearBalanceReport(Carbon $date, $includeShared = false)
|
||||
{
|
||||
$start = clone $date;
|
||||
$end = clone $date;
|
||||
$sharedAccounts = [];
|
||||
if ($includeShared === false) {
|
||||
$sharedCollection = Auth::user()->accounts()
|
||||
->leftJoin('account_meta', 'account_meta.account_id', '=', 'accounts.id')
|
||||
->where('account_meta.name', '=', 'accountRole')
|
||||
->where('account_meta.data', '=', json_encode('sharedAsset'))
|
||||
->get(['accounts.id']);
|
||||
|
||||
foreach ($sharedCollection as $account) {
|
||||
$sharedAccounts[] = $account->id;
|
||||
}
|
||||
}
|
||||
|
||||
$accounts = Auth::user()->accounts()->accountTypeIn(['Default account', 'Asset account'])->orderBy('accounts.name', 'ASC')->get(['accounts.*'])
|
||||
->filter(
|
||||
function (Account $account) use ($sharedAccounts) {
|
||||
if (!in_array($account->id, $sharedAccounts)) {
|
||||
return $account;
|
||||
}
|
||||
|
||||
return null;
|
||||
}
|
||||
);
|
||||
$report = [];
|
||||
$start->startOfYear()->subDay();
|
||||
$end->endOfYear();
|
||||
|
||||
foreach ($accounts as $account) {
|
||||
$startBalance = Steam::balance($account, $start);
|
||||
$endBalance = Steam::balance($account, $end);
|
||||
$report[] = [
|
||||
'start' => $startBalance,
|
||||
'end' => $endBalance,
|
||||
'hide' => ($startBalance == 0 && $endBalance == 0),
|
||||
'account' => $account,
|
||||
'shared' => $account->accountRole == 'sharedAsset'
|
||||
];
|
||||
}
|
||||
|
||||
return $report;
|
||||
}
|
||||
}
|
||||
|
@ -30,11 +30,4 @@ interface ReportHelperInterface
|
||||
*/
|
||||
public function listOfMonths(Carbon $date);
|
||||
|
||||
/**
|
||||
* @param Carbon $date
|
||||
* @param bool $includeShared
|
||||
*
|
||||
* @return array
|
||||
*/
|
||||
public function yearBalanceReport(Carbon $date, $includeShared = false);
|
||||
}
|
||||
|
@ -437,58 +437,6 @@ class ReportQuery implements ReportQueryInterface
|
||||
return $data;
|
||||
}
|
||||
|
||||
/**
|
||||
* This method returns all deposits into asset accounts, grouped by the revenue account,
|
||||
*
|
||||
* @param Carbon $start
|
||||
* @param Carbon $end
|
||||
* @param bool $includeShared
|
||||
*
|
||||
* @return Collection
|
||||
*/
|
||||
public function journalsByRevenueAccount(Carbon $start, Carbon $end, $includeShared = false)
|
||||
{
|
||||
$query = $this->queryJournalsWithTransactions($start, $end);
|
||||
if ($includeShared === false) {
|
||||
|
||||
// show queries where transfer type is deposit, and its not to a shared account
|
||||
// or where its a transfer and its from a shared account (both count as incomes)
|
||||
$query->where(
|
||||
function (Builder $query) {
|
||||
$query->where(
|
||||
function (Builder $q) {
|
||||
$q->where('transaction_types.type', 'Deposit');
|
||||
$q->where('acm_to.data', '!=', '"sharedAsset"');
|
||||
}
|
||||
);
|
||||
$query->orWhere(
|
||||
function (Builder $q) {
|
||||
$q->where('transaction_types.type', 'Transfer');
|
||||
$q->where('acm_from.data', '=', '"sharedAsset"');
|
||||
}
|
||||
);
|
||||
}
|
||||
);
|
||||
} else {
|
||||
// any deposit goes:
|
||||
$query->where('transaction_types.type', 'Deposit');
|
||||
}
|
||||
|
||||
$query->groupBy('t_from.account_id')->orderBy('queryAmount');
|
||||
|
||||
$data = $query->get(
|
||||
['t_from.account_id as account_id', 'ac_from.name as name', 'ac_from.encrypted as encrypted', DB::Raw('SUM(t_from.amount) as `queryAmount`')]
|
||||
);
|
||||
// decrypt
|
||||
$data->each(
|
||||
function (Model $object) {
|
||||
$object->name = intval($object->encrypted) == 1 ? Crypt::decrypt($object->name) : $object->name;
|
||||
}
|
||||
);
|
||||
|
||||
return $data;
|
||||
}
|
||||
|
||||
/**
|
||||
* With an equally misleading name, this query returns are transfers to shared accounts. These are considered
|
||||
* expenses.
|
||||
|
@ -138,17 +138,6 @@ interface ReportQueryInterface
|
||||
*/
|
||||
public function journalsByExpenseAccount(Carbon $start, Carbon $end, $includeShared = false);
|
||||
|
||||
/**
|
||||
* This method returns all deposits into asset accounts, grouped by the revenue account,
|
||||
*
|
||||
* @param Carbon $start
|
||||
* @param Carbon $end
|
||||
* @param bool $includeShared
|
||||
*
|
||||
* @return Collection
|
||||
*/
|
||||
public function journalsByRevenueAccount(Carbon $start, Carbon $end, $includeShared = false);
|
||||
|
||||
/**
|
||||
* With an equally misleading name, this query returns are transfers to shared accounts. These are considered
|
||||
* expenses.
|
||||
|
@ -118,108 +118,4 @@ class ReportHelperTest extends TestCase
|
||||
|
||||
}
|
||||
|
||||
|
||||
public function testYearBalanceReport()
|
||||
{
|
||||
$date = new Carbon('2015-01-01');
|
||||
$user = FactoryMuffin::create('FireflyIII\User');
|
||||
$setShared = [];
|
||||
$setNormal = [];
|
||||
|
||||
FactoryMuffin::create('FireflyIII\Models\AccountType');
|
||||
FactoryMuffin::create('FireflyIII\Models\AccountType');
|
||||
$assetType = FactoryMuffin::create('FireflyIII\Models\AccountType');
|
||||
|
||||
// need some shared accounts:
|
||||
for ($i = 0; $i < 3; $i++) {
|
||||
$shared = FactoryMuffin::create('FireflyIII\Models\Account');
|
||||
$shared->user_id = $user->id;
|
||||
$shared->account_type_id = $assetType->id;
|
||||
$shared->save();
|
||||
// meta for shared:
|
||||
AccountMeta::create(
|
||||
[
|
||||
'account_id' => $shared->id,
|
||||
'name' => 'accountRole',
|
||||
'data' => 'sharedAsset',
|
||||
]
|
||||
);
|
||||
$setShared[] = $shared;
|
||||
}
|
||||
|
||||
// need some normal accounts:
|
||||
for ($i = 0; $i < 3; $i++) {
|
||||
$account = FactoryMuffin::create('FireflyIII\Models\Account');
|
||||
$account->user_id = $user->id;
|
||||
$account->account_type_id = $assetType->id;
|
||||
$account->save();
|
||||
$setNormal[] = $account;
|
||||
}
|
||||
|
||||
// mock stuff:
|
||||
Steam::shouldReceive('balance')->withAnyArgs()->andReturn(0);
|
||||
|
||||
$this->be($user);
|
||||
|
||||
$result = $this->object->yearBalanceReport($date, false);
|
||||
foreach ($result as $entry) {
|
||||
// everything is hidden:
|
||||
$this->assertTrue($entry['hide']);
|
||||
// nothing is shared:
|
||||
$this->assertFalse($entry['shared']);
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
public function testYearBalanceReportWithShared()
|
||||
{
|
||||
$date = new Carbon('2015-01-01');
|
||||
$user = FactoryMuffin::create('FireflyIII\User');
|
||||
$setShared = [];
|
||||
$setNormal = [];
|
||||
|
||||
FactoryMuffin::create('FireflyIII\Models\AccountType');
|
||||
FactoryMuffin::create('FireflyIII\Models\AccountType');
|
||||
$assetType = FactoryMuffin::create('FireflyIII\Models\AccountType');
|
||||
|
||||
// need some shared accounts:
|
||||
for ($i = 0; $i < 3; $i++) {
|
||||
$shared = FactoryMuffin::create('FireflyIII\Models\Account');
|
||||
$shared->user_id = $user->id;
|
||||
$shared->account_type_id = $assetType->id;
|
||||
$shared->save();
|
||||
// meta for shared:
|
||||
AccountMeta::create(
|
||||
[
|
||||
'account_id' => $shared->id,
|
||||
'name' => 'accountRole',
|
||||
'data' => 'sharedAsset',
|
||||
]
|
||||
);
|
||||
$setShared[] = $shared;
|
||||
}
|
||||
|
||||
// need some normal accounts:
|
||||
for ($i = 0; $i < 3; $i++) {
|
||||
$account = FactoryMuffin::create('FireflyIII\Models\Account');
|
||||
$account->user_id = $user->id;
|
||||
$account->account_type_id = $assetType->id;
|
||||
$account->save();
|
||||
$setNormal[] = $account;
|
||||
}
|
||||
|
||||
// mock stuff:
|
||||
Steam::shouldReceive('balance')->withAnyArgs()->andReturn(0);
|
||||
|
||||
$this->be($user);
|
||||
|
||||
$result = $this->object->yearBalanceReport($date, true);
|
||||
foreach ($result as $entry) {
|
||||
// everything is hidden:
|
||||
$this->assertTrue($entry['hide']);
|
||||
// nothing is shared:
|
||||
$this->assertFalse($entry['shared']);
|
||||
}
|
||||
|
||||
}
|
||||
}
|
Loading…
Reference in New Issue
Block a user