mirror of
https://github.com/firefly-iii/firefly-iii.git
synced 2024-11-27 03:10:32 -06:00
Remapped all library classes.
This commit is contained in:
parent
3cfa3f3b27
commit
21a0a5d573
@ -1,11 +1,11 @@
|
||||
<?php
|
||||
|
||||
namespace FireflyIII\Database;
|
||||
namespace FireflyIII\Database\Account;
|
||||
|
||||
use Carbon\Carbon;
|
||||
use FireflyIII\Database\Ifaces\AccountInterface;
|
||||
use FireflyIII\Database\Ifaces\CommonDatabaseCalls;
|
||||
use FireflyIII\Database\Ifaces\CUD;
|
||||
use FireflyIII\Database\CommonDatabaseCalls;
|
||||
use FireflyIII\Database\CUD;
|
||||
use FireflyIII\Database\SwitchUser;
|
||||
use FireflyIII\Exception\NotImplementedException;
|
||||
use Illuminate\Support\Collection;
|
||||
use Illuminate\Support\MessageBag;
|
||||
@ -70,8 +70,8 @@ class Account implements CUD, CommonDatabaseCalls, AccountInterface
|
||||
*/
|
||||
public function findInitialBalanceAccount(\Account $account)
|
||||
{
|
||||
/** @var \FireflyIII\Database\AccountType $acctType */
|
||||
$acctType = \App::make('FireflyIII\Database\AccountType');
|
||||
/** @var \FireflyIII\Database\AccountType\AccountType $acctType */
|
||||
$acctType = \App::make('FireflyIII\Database\AccountType\AccountType');
|
||||
|
||||
$accountType = $acctType->findByWhat('initial');
|
||||
|
||||
@ -182,8 +182,8 @@ class Account implements CUD, CommonDatabaseCalls, AccountInterface
|
||||
*/
|
||||
$balance = floatval($data['openingbalance']);
|
||||
$date = new Carbon($data['openingbalancedate']);
|
||||
/** @var \FireflyIII\Database\TransactionJournal $tj */
|
||||
$tj = \App::make('FireflyIII\Database\TransactionJournal');
|
||||
/** @var \FireflyIII\Database\TransactionJournal\TransactionJournal $tj */
|
||||
$tj = \App::make('FireflyIII\Database\TransactionJournal\TransactionJournal');
|
||||
if ($balance < 0) {
|
||||
// first transaction draws money from the new account to the opposing
|
||||
$from = $account;
|
||||
@ -282,8 +282,8 @@ class Account implements CUD, CommonDatabaseCalls, AccountInterface
|
||||
/*
|
||||
* Find account type.
|
||||
*/
|
||||
/** @var \FireflyIII\Database\AccountType $acctType */
|
||||
$acctType = \App::make('FireflyIII\Database\AccountType');
|
||||
/** @var \FireflyIII\Database\AccountType\AccountType $acctType */
|
||||
$acctType = \App::make('FireflyIII\Database\AccountType\AccountType');
|
||||
|
||||
$accountType = $acctType->findByWhat($data['what']);
|
||||
|
@ -1,6 +1,6 @@
|
||||
<?php
|
||||
|
||||
namespace FireflyIII\Database\Ifaces;
|
||||
namespace FireflyIII\Database\Account;
|
||||
|
||||
use Illuminate\Support\Collection;
|
||||
|
@ -1,11 +1,10 @@
|
||||
<?php
|
||||
|
||||
namespace FireflyIII\Database;
|
||||
namespace FireflyIII\Database\AccountType;
|
||||
|
||||
use FireflyIII\Exception\FireflyException;
|
||||
use FireflyIII\Database\Ifaces\AccountTypeInterface;
|
||||
use FireflyIII\Database\Ifaces\CommonDatabaseCalls;
|
||||
use FireflyIII\Database\Ifaces\CUD;
|
||||
use FireflyIII\Database\CommonDatabaseCalls;
|
||||
use FireflyIII\Database\CUD;
|
||||
use FireflyIII\Exception\NotImplementedException;
|
||||
use Illuminate\Support\Collection;
|
||||
|
@ -1,10 +1,10 @@
|
||||
<?php
|
||||
namespace FireflyIII\Database;
|
||||
namespace FireflyIII\Database\Budget;
|
||||
|
||||
use Carbon\Carbon;
|
||||
use FireflyIII\Database\Ifaces\BudgetInterface;
|
||||
use FireflyIII\Database\Ifaces\CommonDatabaseCalls;
|
||||
use FireflyIII\Database\Ifaces\CUD;
|
||||
use FireflyIII\Database\CommonDatabaseCalls;
|
||||
use FireflyIII\Database\CUD;
|
||||
use FireflyIII\Database\SwitchUser;
|
||||
use FireflyIII\Exception\NotImplementedException;
|
||||
use Illuminate\Support\Collection;
|
||||
use Illuminate\Support\MessageBag;
|
@ -1,6 +1,6 @@
|
||||
<?php
|
||||
|
||||
namespace FireflyIII\Database\Ifaces;
|
||||
namespace FireflyIII\Database\Budget;
|
||||
|
||||
use Carbon\Carbon;
|
||||
use Illuminate\Support\Collection;
|
@ -1,6 +1,6 @@
|
||||
<?php
|
||||
|
||||
namespace FireflyIII\Database\Ifaces;
|
||||
namespace FireflyIII\Database;
|
||||
|
||||
|
||||
|
@ -1,10 +1,10 @@
|
||||
<?php
|
||||
namespace FireflyIII\Database;
|
||||
namespace FireflyIII\Database\Category;
|
||||
|
||||
use Carbon\Carbon;
|
||||
use FireflyIII\Database\Ifaces\CategoryInterface;
|
||||
use FireflyIII\Database\Ifaces\CommonDatabaseCalls;
|
||||
use FireflyIII\Database\Ifaces\CUD;
|
||||
use FireflyIII\Database\CommonDatabaseCalls;
|
||||
use FireflyIII\Database\CUD;
|
||||
use FireflyIII\Database\SwitchUser;
|
||||
use FireflyIII\Exception\NotImplementedException;
|
||||
use Illuminate\Support\Collection;
|
||||
use Illuminate\Support\MessageBag;
|
@ -1,6 +1,6 @@
|
||||
<?php
|
||||
|
||||
namespace FireflyIII\Database\Ifaces;
|
||||
namespace FireflyIII\Database;
|
||||
|
||||
use Illuminate\Support\Collection;
|
||||
|
@ -1,32 +0,0 @@
|
||||
<?php
|
||||
|
||||
namespace FireflyIII\Database\Ifaces;
|
||||
|
||||
|
||||
use Carbon\Carbon;
|
||||
|
||||
/**
|
||||
* Interface ReportInterface
|
||||
*
|
||||
* @package FireflyIII\Database\Ifaces
|
||||
*/
|
||||
interface ReportInterface
|
||||
{
|
||||
|
||||
/**
|
||||
* @param \Account $account
|
||||
* @param Carbon $month
|
||||
*
|
||||
* @return float
|
||||
*/
|
||||
public function getExpenseByMonth(\Account $account, Carbon $month);
|
||||
|
||||
/**
|
||||
* @param \Account $account
|
||||
* @param Carbon $month
|
||||
*
|
||||
* @return float
|
||||
*/
|
||||
public function getIncomeByMonth(\Account $account, Carbon $month);
|
||||
|
||||
}
|
@ -1,11 +1,11 @@
|
||||
<?php
|
||||
namespace FireflyIII\Database;
|
||||
namespace FireflyIII\Database\PiggyBank;
|
||||
|
||||
use Carbon\Carbon;
|
||||
use FireflyIII\Database\CommonDatabaseCalls;
|
||||
use FireflyIII\Database\CUD;
|
||||
use FireflyIII\Database\SwitchUser;
|
||||
use FireflyIII\Exception\FireflyException;
|
||||
use FireflyIII\Database\Ifaces\CommonDatabaseCalls;
|
||||
use FireflyIII\Database\Ifaces\CUD;
|
||||
use FireflyIII\Database\Ifaces\PiggybankInterface;
|
||||
use FireflyIII\Exception\NotImplementedException;
|
||||
use Illuminate\Support\Collection;
|
||||
use Illuminate\Support\MessageBag;
|
||||
@ -16,7 +16,7 @@ use Illuminate\Support\MessageBag;
|
||||
*
|
||||
* @package FireflyIII\Database
|
||||
*/
|
||||
class Piggybank implements CUD, CommonDatabaseCalls, PiggybankInterface
|
||||
class PiggyBank implements CUD, CommonDatabaseCalls, PiggybankInterface
|
||||
{
|
||||
use SwitchUser;
|
||||
|
@ -1,6 +1,6 @@
|
||||
<?php
|
||||
|
||||
namespace FireflyIII\Database\Ifaces;
|
||||
namespace FireflyIII\Database\PiggyBank;
|
||||
|
||||
/**
|
||||
* Interface PiggybankInterface
|
@ -1,13 +1,13 @@
|
||||
<?php
|
||||
|
||||
namespace FireflyIII\Database;
|
||||
namespace FireflyIII\Database\PiggyBank;
|
||||
|
||||
|
||||
use Carbon\Carbon;
|
||||
use FireflyIII\Collection\PiggybankPart;
|
||||
use FireflyIII\Database\Ifaces\CommonDatabaseCalls;
|
||||
use FireflyIII\Database\Ifaces\CUD;
|
||||
use FireflyIII\Database\Ifaces\PiggybankInterface;
|
||||
use FireflyIII\Database\CommonDatabaseCalls;
|
||||
use FireflyIII\Database\CUD;
|
||||
use FireflyIII\Database\SwitchUser;
|
||||
use FireflyIII\Exception\NotImplementedException;
|
||||
use Illuminate\Support\Collection;
|
||||
use Illuminate\Support\MessageBag;
|
@ -1,24 +1,22 @@
|
||||
<?php
|
||||
|
||||
namespace FireflyIII\Database;
|
||||
namespace FireflyIII\Database\RecurringTransaction;
|
||||
|
||||
|
||||
use Carbon\Carbon;
|
||||
use FireflyIII\Database\Ifaces\CommonDatabaseCalls;
|
||||
use FireflyIII\Database\Ifaces\CUD;
|
||||
use FireflyIII\Database\Ifaces\RecurringInterface;
|
||||
use FireflyIII\Database\CommonDatabaseCalls;
|
||||
use FireflyIII\Database\CUD;
|
||||
use FireflyIII\Database\SwitchUser;
|
||||
use FireflyIII\Exception\NotImplementedException;
|
||||
use Illuminate\Support\Collection;
|
||||
use Illuminate\Support\MessageBag;
|
||||
|
||||
use stdObject;
|
||||
|
||||
/**
|
||||
* Class Recurring
|
||||
*
|
||||
* @package FireflyIII\Database
|
||||
*/
|
||||
class Recurring implements CUD, CommonDatabaseCalls, RecurringInterface
|
||||
class RecurringTransaction implements CUD, CommonDatabaseCalls, RecurringTransactionInterface
|
||||
{
|
||||
use SwitchUser;
|
||||
|
||||
@ -83,7 +81,7 @@ class Recurring implements CUD, CommonDatabaseCalls, RecurringInterface
|
||||
|
||||
/**
|
||||
* @param \Eloquent $model
|
||||
* @param array $data
|
||||
* @param array $data
|
||||
*
|
||||
* @return bool
|
||||
*/
|
@ -1,6 +1,6 @@
|
||||
<?php
|
||||
|
||||
namespace FireflyIII\Database\Ifaces;
|
||||
namespace FireflyIII\Database\RecurringTransaction;
|
||||
|
||||
use Carbon\Carbon;
|
||||
|
||||
@ -9,7 +9,7 @@ use Carbon\Carbon;
|
||||
*
|
||||
* @package FireflyIII\Database
|
||||
*/
|
||||
interface RecurringInterface
|
||||
interface RecurringTransactionInterface
|
||||
{
|
||||
/**
|
||||
* @param \RecurringTransaction $recurring
|
@ -1,180 +0,0 @@
|
||||
<?php
|
||||
/**
|
||||
* Created by PhpStorm.
|
||||
* User: sander
|
||||
* Date: 06/12/14
|
||||
* Time: 08:40
|
||||
*/
|
||||
|
||||
namespace FireflyIII\Database;
|
||||
|
||||
|
||||
use Carbon\Carbon;
|
||||
use FireflyIII\Database\Ifaces\ReportInterface;
|
||||
|
||||
/**
|
||||
* Class Report
|
||||
*
|
||||
* @package FireflyIII\Database
|
||||
*/
|
||||
class Report implements ReportInterface
|
||||
{
|
||||
use SwitchUser;
|
||||
|
||||
|
||||
/**
|
||||
* @param \Account $account
|
||||
* @param Carbon $month
|
||||
*
|
||||
* @return float
|
||||
*/
|
||||
public function getExpenseByMonth(\Account $account, Carbon $month)
|
||||
{
|
||||
if (isset($account->sharedExpense) && $account->sharedExpense === true) {
|
||||
$shared = true;
|
||||
} else {
|
||||
if (isset($account->sharedExpense) && $account->sharedExpense === false) {
|
||||
$shared = false;
|
||||
} else {
|
||||
$shared = ($account->getMeta('accountRole') == 'sharedExpense');
|
||||
}
|
||||
}
|
||||
|
||||
$start = clone $month;
|
||||
$end = clone $month;
|
||||
$start->startOfMonth();
|
||||
$end->endOfMonth();
|
||||
$sum = 0;
|
||||
|
||||
// get all journals.
|
||||
$journals = \TransactionJournal::with(['transactionType','transactions'])->whereIn(
|
||||
'id', function ($query) use ($account, $start, $end) {
|
||||
$query->select('transaction_journal_id')
|
||||
->from('transactions')
|
||||
->where('account_id', $account->id);
|
||||
}
|
||||
)->before($end)->after($start)->get();
|
||||
|
||||
|
||||
if ($shared) {
|
||||
$expenses = $journals->filter(
|
||||
function (\TransactionJournal $journal) use ($account) {
|
||||
// any withdrawal is an expense:
|
||||
if ($journal->transactionType->type == 'Withdrawal') {
|
||||
return $journal;
|
||||
}
|
||||
// any transfer away from this account is an expense.
|
||||
if ($journal->transactionType->type == 'Transfer') {
|
||||
/** @var \Transaction $t */
|
||||
foreach ($journal->transactions as $t) {
|
||||
if ($t->account_id == $account->id && floatval($t->amount) < 0) {
|
||||
return $journal;
|
||||
}
|
||||
}
|
||||
}
|
||||
return null;
|
||||
}
|
||||
);
|
||||
} else {
|
||||
$expenses = $journals->filter(
|
||||
function (\TransactionJournal $journal) use ($account) {
|
||||
// only withdrawals are expenses:
|
||||
if ($journal->transactionType->type == 'Withdrawal') {
|
||||
return $journal;
|
||||
}
|
||||
// transfers TO a shared account are also expenses.
|
||||
if ($journal->transactionType->type == 'Transfer') {
|
||||
/** @var \Transaction $t */
|
||||
foreach ($journal->transactions() as $t) {
|
||||
if ($t->account->getMeta('accountRole') == 'sharedExpense') {
|
||||
echo '#'.$journal->id.' is a shared expense!<br>';
|
||||
return $journal;
|
||||
}
|
||||
}
|
||||
}
|
||||
return null;
|
||||
}
|
||||
);
|
||||
}
|
||||
/** @var \TransactionJournal $expense */
|
||||
foreach ($expenses as $expense) {
|
||||
$sum += $expense->getAmount();
|
||||
}
|
||||
|
||||
|
||||
return $sum;
|
||||
}
|
||||
|
||||
/**
|
||||
* @param \Account $account
|
||||
* @param Carbon $month
|
||||
*
|
||||
* @return float
|
||||
*/
|
||||
public function getIncomeByMonth(\Account $account, Carbon $month)
|
||||
{
|
||||
if (isset($account->sharedExpense) && $account->sharedExpense === true) {
|
||||
$shared = true;
|
||||
} else {
|
||||
if (isset($account->sharedExpense) && $account->sharedExpense === false) {
|
||||
$shared = false;
|
||||
} else {
|
||||
$shared = ($account->getMeta('accountRole') == 'sharedExpense');
|
||||
}
|
||||
}
|
||||
|
||||
$start = clone $month;
|
||||
$end = clone $month;
|
||||
$start->startOfMonth();
|
||||
$end->endOfMonth();
|
||||
$sum = 0;
|
||||
|
||||
// get all journals.
|
||||
$journals = \TransactionJournal::with(['transactionType','transactions'])->whereIn(
|
||||
'id', function ($query) use ($account, $start, $end) {
|
||||
$query->select('transaction_journal_id')
|
||||
->from('transactions')
|
||||
->where('account_id', $account->id);
|
||||
}
|
||||
)->before($end)->after($start)->get();
|
||||
|
||||
|
||||
if ($shared) {
|
||||
$incomes = $journals->filter(
|
||||
function (\TransactionJournal $journal) use ($account) {
|
||||
// any deposit is an income:
|
||||
if ($journal->transactionType->type == 'Deposit') {
|
||||
return $journal;
|
||||
}
|
||||
// any transfer TO this account is an income.
|
||||
if ($journal->transactionType->type == 'Transfer') {
|
||||
/** @var \Transaction $t */
|
||||
foreach ($journal->transactions as $t) {
|
||||
if ($t->account_id == $account->id && floatval($t->amount) > 0) {
|
||||
return $journal;
|
||||
}
|
||||
}
|
||||
}
|
||||
return null;
|
||||
}
|
||||
);
|
||||
} else {
|
||||
$incomes = $journals->filter(
|
||||
function (\TransactionJournal $journal) use ($account) {
|
||||
// only deposits are incomes:
|
||||
if ($journal->transactionType->type == 'Deposit') {
|
||||
return $journal;
|
||||
}
|
||||
return null;
|
||||
}
|
||||
);
|
||||
}
|
||||
/** @var \TransactionJournal $expense */
|
||||
foreach ($incomes as $income) {
|
||||
$sum += $income->getAmount();
|
||||
}
|
||||
|
||||
|
||||
return $sum;
|
||||
}
|
||||
}
|
@ -1,11 +1,11 @@
|
||||
<?php
|
||||
|
||||
namespace FireflyIII\Database;
|
||||
namespace FireflyIII\Database\Transaction;
|
||||
|
||||
use FireflyIII\Database\CommonDatabaseCalls;
|
||||
use FireflyIII\Database\CUD;
|
||||
use FireflyIII\Database\SwitchUser;
|
||||
use FireflyIII\Exception\FireflyException;
|
||||
use FireflyIII\Database\Ifaces\CommonDatabaseCalls;
|
||||
use FireflyIII\Database\Ifaces\CUD;
|
||||
use FireflyIII\Database\Ifaces\TransactionInterface;
|
||||
use FireflyIII\Exception\NotImplementedException;
|
||||
use Illuminate\Support\Collection;
|
||||
use Illuminate\Support\MessageBag;
|
@ -1,10 +1,8 @@
|
||||
<?php
|
||||
|
||||
namespace FireflyIII\Database;
|
||||
namespace FireflyIII\Database\TransactionCurrency;
|
||||
|
||||
|
||||
use FireflyIII\Database\Ifaces\TransactionCurrencyInterface;
|
||||
|
||||
/**
|
||||
* Class TransactionType
|
||||
*
|
@ -1,6 +1,6 @@
|
||||
<?php
|
||||
|
||||
namespace FireflyIII\Database\Ifaces;
|
||||
namespace FireflyIII\Database\TransactionCurrency;
|
||||
|
||||
|
||||
/**
|
@ -1,12 +1,12 @@
|
||||
<?php
|
||||
|
||||
namespace FireflyIII\Database;
|
||||
namespace FireflyIII\Database\TransactionJournal;
|
||||
|
||||
|
||||
use Carbon\Carbon;
|
||||
use FireflyIII\Database\Ifaces\CommonDatabaseCalls;
|
||||
use FireflyIII\Database\Ifaces\CUD;
|
||||
use FireflyIII\Database\Ifaces\TransactionJournalInterface;
|
||||
use FireflyIII\Database\CommonDatabaseCalls;
|
||||
use FireflyIII\Database\CUD;
|
||||
use FireflyIII\Database\SwitchUser;
|
||||
use FireflyIII\Exception\FireflyException;
|
||||
use FireflyIII\Exception\NotImplementedException;
|
||||
use Illuminate\Support\Collection;
|
@ -1,6 +1,6 @@
|
||||
<?php
|
||||
|
||||
namespace FireflyIII\Database\Ifaces;
|
||||
namespace FireflyIII\Database\TransactionJournal;
|
||||
|
||||
use Carbon\Carbon;
|
||||
use Illuminate\Support\Collection;
|
@ -1,11 +1,10 @@
|
||||
<?php
|
||||
|
||||
namespace FireflyIII\Database;
|
||||
namespace FireflyIII\Database\TransactionType;
|
||||
|
||||
|
||||
use FireflyIII\Database\Ifaces\CommonDatabaseCalls;
|
||||
use FireflyIII\Database\Ifaces\CUD;
|
||||
use FireflyIII\Database\Ifaces\TransactionTypeInterface;
|
||||
use FireflyIII\Database\CommonDatabaseCalls;
|
||||
use FireflyIII\Database\CUD;
|
||||
use FireflyIII\Exception\FireflyException;
|
||||
use FireflyIII\Exception\NotImplementedException;
|
||||
use Illuminate\Support\Collection;
|
@ -1,6 +1,6 @@
|
||||
<?php
|
||||
|
||||
namespace FireflyIII\Database;
|
||||
namespace FireflyIII\Database\User;
|
||||
|
||||
|
||||
/**
|
@ -3,9 +3,11 @@
|
||||
namespace FireflyIII\Report;
|
||||
|
||||
use Carbon\Carbon;
|
||||
use FireflyIII\Database\Account as AccountRepository;
|
||||
use FireflyIII\Database\Account\Account as AccountRepository;
|
||||
use Illuminate\Support\Collection;
|
||||
|
||||
// todo add methods to itnerface
|
||||
|
||||
/**
|
||||
* Class Report
|
||||
*
|
||||
@ -39,25 +41,25 @@ class Report implements ReportInterface
|
||||
return \TransactionJournal::
|
||||
leftJoin(
|
||||
'transactions as t_from', function ($join) {
|
||||
$join->on('t_from.transaction_journal_id', '=', 'transaction_journals.id')->where('t_from.amount', '<', 0);
|
||||
}
|
||||
$join->on('t_from.transaction_journal_id', '=', 'transaction_journals.id')->where('t_from.amount', '<', 0);
|
||||
}
|
||||
)
|
||||
->leftJoin('accounts as ac_from', 't_from.account_id', '=', 'ac_from.id')
|
||||
->leftJoin(
|
||||
'account_meta as acm_from', function ($join) {
|
||||
$join->on('ac_from.id', '=', 'acm_from.account_id')->where('acm_from.name', '=', 'accountRole');
|
||||
}
|
||||
$join->on('ac_from.id', '=', 'acm_from.account_id')->where('acm_from.name', '=', 'accountRole');
|
||||
}
|
||||
)
|
||||
->leftJoin(
|
||||
'transactions as t_to', function ($join) {
|
||||
$join->on('t_to.transaction_journal_id', '=', 'transaction_journals.id')->where('t_to.amount', '>', 0);
|
||||
}
|
||||
$join->on('t_to.transaction_journal_id', '=', 'transaction_journals.id')->where('t_to.amount', '>', 0);
|
||||
}
|
||||
)
|
||||
->leftJoin('accounts as ac_to', 't_to.account_id', '=', 'ac_to.id')
|
||||
->leftJoin(
|
||||
'account_meta as acm_to', function ($join) {
|
||||
$join->on('ac_to.id', '=', 'acm_to.account_id')->where('acm_to.name', '=', 'accountRole');
|
||||
}
|
||||
$join->on('ac_to.id', '=', 'acm_to.account_id')->where('acm_to.name', '=', 'accountRole');
|
||||
}
|
||||
)
|
||||
->leftJoin('transaction_types', 'transaction_types.id', '=', 'transaction_journals.transaction_type_id')
|
||||
->where('transaction_types.type', 'Withdrawal')
|
||||
@ -120,25 +122,25 @@ class Report implements ReportInterface
|
||||
return \TransactionJournal::
|
||||
leftJoin(
|
||||
'transactions as t_from', function ($join) {
|
||||
$join->on('t_from.transaction_journal_id', '=', 'transaction_journals.id')->where('t_from.amount', '<', 0);
|
||||
}
|
||||
$join->on('t_from.transaction_journal_id', '=', 'transaction_journals.id')->where('t_from.amount', '<', 0);
|
||||
}
|
||||
)
|
||||
->leftJoin('accounts as ac_from', 't_from.account_id', '=', 'ac_from.id')
|
||||
->leftJoin(
|
||||
'account_meta as acm_from', function ($join) {
|
||||
$join->on('ac_from.id', '=', 'acm_from.account_id')->where('acm_from.name', '=', 'accountRole');
|
||||
}
|
||||
$join->on('ac_from.id', '=', 'acm_from.account_id')->where('acm_from.name', '=', 'accountRole');
|
||||
}
|
||||
)
|
||||
->leftJoin(
|
||||
'transactions as t_to', function ($join) {
|
||||
$join->on('t_to.transaction_journal_id', '=', 'transaction_journals.id')->where('t_to.amount', '>', 0);
|
||||
}
|
||||
$join->on('t_to.transaction_journal_id', '=', 'transaction_journals.id')->where('t_to.amount', '>', 0);
|
||||
}
|
||||
)
|
||||
->leftJoin('accounts as ac_to', 't_to.account_id', '=', 'ac_to.id')
|
||||
->leftJoin(
|
||||
'account_meta as acm_to', function ($join) {
|
||||
$join->on('ac_to.id', '=', 'acm_to.account_id')->where('acm_to.name', '=', 'accountRole');
|
||||
}
|
||||
$join->on('ac_to.id', '=', 'acm_to.account_id')->where('acm_to.name', '=', 'accountRole');
|
||||
}
|
||||
)
|
||||
->leftJoin('transaction_types', 'transaction_types.id', '=', 'transaction_journals.transaction_type_id')
|
||||
->where('transaction_types.type', 'Deposit')
|
||||
@ -196,4 +198,168 @@ class Report implements ReportInterface
|
||||
return $report;
|
||||
}
|
||||
|
||||
use SwitchUser;
|
||||
|
||||
|
||||
/**
|
||||
* @param \Account $account
|
||||
* @param Carbon $month
|
||||
*
|
||||
* @return float
|
||||
*/
|
||||
public function getExpenseByMonth(\Account $account, Carbon $month)
|
||||
{
|
||||
if (isset($account->sharedExpense) && $account->sharedExpense === true) {
|
||||
$shared = true;
|
||||
} else {
|
||||
if (isset($account->sharedExpense) && $account->sharedExpense === false) {
|
||||
$shared = false;
|
||||
} else {
|
||||
$shared = ($account->getMeta('accountRole') == 'sharedExpense');
|
||||
}
|
||||
}
|
||||
|
||||
$start = clone $month;
|
||||
$end = clone $month;
|
||||
$start->startOfMonth();
|
||||
$end->endOfMonth();
|
||||
$sum = 0;
|
||||
|
||||
// get all journals.
|
||||
$journals = \TransactionJournal::with(['transactionType', 'transactions'])->whereIn(
|
||||
'id', function ($query) use ($account, $start, $end) {
|
||||
$query->select('transaction_journal_id')
|
||||
->from('transactions')
|
||||
->where('account_id', $account->id);
|
||||
}
|
||||
)->before($end)->after($start)->get();
|
||||
|
||||
|
||||
if ($shared) {
|
||||
$expenses = $journals->filter(
|
||||
function (\TransactionJournal $journal) use ($account) {
|
||||
// any withdrawal is an expense:
|
||||
if ($journal->transactionType->type == 'Withdrawal') {
|
||||
return $journal;
|
||||
}
|
||||
// any transfer away from this account is an expense.
|
||||
if ($journal->transactionType->type == 'Transfer') {
|
||||
/** @var \Transaction $t */
|
||||
foreach ($journal->transactions as $t) {
|
||||
if ($t->account_id == $account->id && floatval($t->amount) < 0) {
|
||||
return $journal;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
return null;
|
||||
}
|
||||
);
|
||||
} else {
|
||||
$expenses = $journals->filter(
|
||||
function (\TransactionJournal $journal) use ($account) {
|
||||
// only withdrawals are expenses:
|
||||
if ($journal->transactionType->type == 'Withdrawal') {
|
||||
return $journal;
|
||||
}
|
||||
// transfers TO a shared account are also expenses.
|
||||
if ($journal->transactionType->type == 'Transfer') {
|
||||
/** @var \Transaction $t */
|
||||
foreach ($journal->transactions() as $t) {
|
||||
if ($t->account->getMeta('accountRole') == 'sharedExpense') {
|
||||
echo '#' . $journal->id . ' is a shared expense!<br>';
|
||||
|
||||
return $journal;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
return null;
|
||||
}
|
||||
);
|
||||
}
|
||||
/** @var \TransactionJournal $expense */
|
||||
foreach ($expenses as $expense) {
|
||||
$sum += $expense->getAmount();
|
||||
}
|
||||
|
||||
|
||||
return $sum;
|
||||
}
|
||||
|
||||
/**
|
||||
* @param \Account $account
|
||||
* @param Carbon $month
|
||||
*
|
||||
* @return float
|
||||
*/
|
||||
public function getIncomeByMonth(\Account $account, Carbon $month)
|
||||
{
|
||||
if (isset($account->sharedExpense) && $account->sharedExpense === true) {
|
||||
$shared = true;
|
||||
} else {
|
||||
if (isset($account->sharedExpense) && $account->sharedExpense === false) {
|
||||
$shared = false;
|
||||
} else {
|
||||
$shared = ($account->getMeta('accountRole') == 'sharedExpense');
|
||||
}
|
||||
}
|
||||
|
||||
$start = clone $month;
|
||||
$end = clone $month;
|
||||
$start->startOfMonth();
|
||||
$end->endOfMonth();
|
||||
$sum = 0;
|
||||
|
||||
// get all journals.
|
||||
$journals = \TransactionJournal::with(['transactionType', 'transactions'])->whereIn(
|
||||
'id', function ($query) use ($account, $start, $end) {
|
||||
$query->select('transaction_journal_id')
|
||||
->from('transactions')
|
||||
->where('account_id', $account->id);
|
||||
}
|
||||
)->before($end)->after($start)->get();
|
||||
|
||||
|
||||
if ($shared) {
|
||||
$incomes = $journals->filter(
|
||||
function (\TransactionJournal $journal) use ($account) {
|
||||
// any deposit is an income:
|
||||
if ($journal->transactionType->type == 'Deposit') {
|
||||
return $journal;
|
||||
}
|
||||
// any transfer TO this account is an income.
|
||||
if ($journal->transactionType->type == 'Transfer') {
|
||||
/** @var \Transaction $t */
|
||||
foreach ($journal->transactions as $t) {
|
||||
if ($t->account_id == $account->id && floatval($t->amount) > 0) {
|
||||
return $journal;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
return null;
|
||||
}
|
||||
);
|
||||
} else {
|
||||
$incomes = $journals->filter(
|
||||
function (\TransactionJournal $journal) use ($account) {
|
||||
// only deposits are incomes:
|
||||
if ($journal->transactionType->type == 'Deposit') {
|
||||
return $journal;
|
||||
}
|
||||
|
||||
return null;
|
||||
}
|
||||
);
|
||||
}
|
||||
/** @var \TransactionJournal $expense */
|
||||
foreach ($incomes as $income) {
|
||||
$sum += $income->getAmount();
|
||||
}
|
||||
|
||||
|
||||
return $sum;
|
||||
}
|
||||
|
||||
}
|
Loading…
Reference in New Issue
Block a user