mirror of
https://github.com/firefly-iii/firefly-iii.git
synced 2025-02-25 18:45:27 -06:00
Fixed some reports.
This commit is contained in:
@@ -202,60 +202,6 @@ class ReportQuery implements ReportQueryInterface
|
|||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
/**
|
|
||||||
* Gets a list of expense accounts and the expenses therein, grouped by that expense account.
|
|
||||||
* This result excludes transfers to shared accounts which are expenses, technically.
|
|
||||||
*
|
|
||||||
* So now it will include them!
|
|
||||||
*
|
|
||||||
* @param Carbon $start
|
|
||||||
* @param Carbon $end
|
|
||||||
* @param bool $includeShared
|
|
||||||
*
|
|
||||||
* @return Collection
|
|
||||||
*/
|
|
||||||
public function journalsByExpenseAccount(Carbon $start, Carbon $end, $includeShared = false)
|
|
||||||
{
|
|
||||||
$query = $this->queryJournalsWithTransactions($start, $end);
|
|
||||||
if ($includeShared === false) {
|
|
||||||
// get all withdrawals not from a shared accounts
|
|
||||||
// and all transfers to a shared account
|
|
||||||
$query->where(
|
|
||||||
function (Builder $query) {
|
|
||||||
$query->where(
|
|
||||||
function (Builder $q) {
|
|
||||||
$q->where('transaction_types.type', 'Withdrawal');
|
|
||||||
$q->where('acm_from.data', '!=', '"sharedAsset"');
|
|
||||||
}
|
|
||||||
);
|
|
||||||
$query->orWhere(
|
|
||||||
function (Builder $q) {
|
|
||||||
$q->where('transaction_types.type', 'Transfer');
|
|
||||||
$q->where('acm_to.data', '=', '"sharedAsset"');
|
|
||||||
}
|
|
||||||
);
|
|
||||||
}
|
|
||||||
);
|
|
||||||
} else {
|
|
||||||
// any withdrawal goes:
|
|
||||||
$query->where('transaction_types.type', 'Withdrawal');
|
|
||||||
}
|
|
||||||
$query->before($end)->after($start)
|
|
||||||
->where('transaction_journals.user_id', Auth::user()->id)
|
|
||||||
->groupBy('t_to.account_id')
|
|
||||||
->orderBy('queryAmount', 'DESC');
|
|
||||||
|
|
||||||
$data = $query->get(['t_to.account_id as id', 'ac_to.name as name', 'ac_to.encrypted', DB::Raw('SUM(t_to.amount) as `queryAmount`')]);
|
|
||||||
|
|
||||||
// decrypt
|
|
||||||
$data->each(
|
|
||||||
function (Model $object) {
|
|
||||||
$object->name = intval($object->encrypted) == 1 ? Crypt::decrypt($object->name) : $object->name;
|
|
||||||
}
|
|
||||||
);
|
|
||||||
|
|
||||||
return $data;
|
|
||||||
}
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* @param Account $account
|
* @param Account $account
|
||||||
|
@@ -78,19 +78,4 @@ interface ReportQueryInterface
|
|||||||
public function spentNoBudget(Account $account, Carbon $start, Carbon $end, $shared = false);
|
public function spentNoBudget(Account $account, Carbon $start, Carbon $end, $shared = false);
|
||||||
|
|
||||||
|
|
||||||
/**
|
|
||||||
* Gets a list of expense accounts and the expenses therein, grouped by that expense account.
|
|
||||||
* This result excludes transfers to shared accounts which are expenses, technically.
|
|
||||||
*
|
|
||||||
* So now it will include them!
|
|
||||||
*
|
|
||||||
* @param Carbon $start
|
|
||||||
* @param Carbon $end
|
|
||||||
* @param bool $includeShared
|
|
||||||
*
|
|
||||||
* @return Collection
|
|
||||||
*
|
|
||||||
*/
|
|
||||||
public function journalsByExpenseAccount(Carbon $start, Carbon $end, $includeShared = false);
|
|
||||||
|
|
||||||
}
|
}
|
||||||
|
@@ -96,7 +96,7 @@ class BillController extends Controller
|
|||||||
|
|
||||||
$creditCards = $accounts->getCreditCards();
|
$creditCards = $accounts->getCreditCards();
|
||||||
foreach ($creditCards as $creditCard) {
|
foreach ($creditCards as $creditCard) {
|
||||||
$balance = Steam::balance($creditCard, null, true);
|
$balance = Steam::balance($creditCard, $end, true);
|
||||||
$date = new Carbon($creditCard->getMeta('ccMonthlyPaymentDate'));
|
$date = new Carbon($creditCard->getMeta('ccMonthlyPaymentDate'));
|
||||||
if ($balance < 0) {
|
if ($balance < 0) {
|
||||||
// unpaid! create a fake bill that matches the amount.
|
// unpaid! create a fake bill that matches the amount.
|
||||||
|
@@ -59,7 +59,7 @@ class JsonController extends Controller
|
|||||||
// if the balance is not zero, the monthly payment is still underway.
|
// if the balance is not zero, the monthly payment is still underway.
|
||||||
/** @var Account $creditCard */
|
/** @var Account $creditCard */
|
||||||
foreach ($creditCards as $creditCard) {
|
foreach ($creditCards as $creditCard) {
|
||||||
$balance = Steam::balance($creditCard, null, true);
|
$balance = Steam::balance($creditCard, $end, true);
|
||||||
if ($balance == 0) {
|
if ($balance == 0) {
|
||||||
// find a transfer TO the credit card which should account for
|
// find a transfer TO the credit card which should account for
|
||||||
// anything paid. If not, the CC is not yet used.
|
// anything paid. If not, the CC is not yet used.
|
||||||
@@ -99,7 +99,7 @@ class JsonController extends Controller
|
|||||||
|
|
||||||
$creditCards = $accountRepository->getCreditCards();
|
$creditCards = $accountRepository->getCreditCards();
|
||||||
foreach ($creditCards as $creditCard) {
|
foreach ($creditCards as $creditCard) {
|
||||||
$balance = Steam::balance($creditCard, null, true);
|
$balance = Steam::balance($creditCard, $end, true);
|
||||||
$date = new Carbon($creditCard->getMeta('ccMonthlyPaymentDate'));
|
$date = new Carbon($creditCard->getMeta('ccMonthlyPaymentDate'));
|
||||||
if ($balance < 0) {
|
if ($balance < 0) {
|
||||||
// unpaid! create a fake bill that matches the amount.
|
// unpaid! create a fake bill that matches the amount.
|
||||||
|
@@ -45,7 +45,8 @@ class PiggyBankController extends Controller
|
|||||||
*/
|
*/
|
||||||
public function add(AccountRepositoryInterface $repository, PiggyBank $piggyBank)
|
public function add(AccountRepositoryInterface $repository, PiggyBank $piggyBank)
|
||||||
{
|
{
|
||||||
$leftOnAccount = $repository->leftOnAccount($piggyBank->account);
|
$date = Session::get('end', Carbon::now()->endOfMonth());
|
||||||
|
$leftOnAccount = $repository->leftOnAccount($piggyBank->account, $date);
|
||||||
$savedSoFar = $piggyBank->currentRelevantRep()->currentamount;
|
$savedSoFar = $piggyBank->currentRelevantRep()->currentamount;
|
||||||
$leftToSave = $piggyBank->targetamount - $savedSoFar;
|
$leftToSave = $piggyBank->targetamount - $savedSoFar;
|
||||||
$maxAmount = min($leftOnAccount, $leftToSave);
|
$maxAmount = min($leftOnAccount, $leftToSave);
|
||||||
@@ -157,6 +158,7 @@ class PiggyBankController extends Controller
|
|||||||
{
|
{
|
||||||
/** @var Collection $piggyBanks */
|
/** @var Collection $piggyBanks */
|
||||||
$piggyBanks = $piggyRepository->getPiggyBanks();
|
$piggyBanks = $piggyRepository->getPiggyBanks();
|
||||||
|
$end = Session::get('end', Carbon::now()->endOfMonth());
|
||||||
|
|
||||||
$accounts = [];
|
$accounts = [];
|
||||||
/** @var PiggyBank $piggyBank */
|
/** @var PiggyBank $piggyBank */
|
||||||
@@ -172,8 +174,8 @@ class PiggyBankController extends Controller
|
|||||||
if (!isset($accounts[$account->id])) {
|
if (!isset($accounts[$account->id])) {
|
||||||
$accounts[$account->id] = [
|
$accounts[$account->id] = [
|
||||||
'name' => $account->name,
|
'name' => $account->name,
|
||||||
'balance' => Steam::balance($account, null, true),
|
'balance' => Steam::balance($account, $end, true),
|
||||||
'leftForPiggyBanks' => $repository->leftOnAccount($account),
|
'leftForPiggyBanks' => $repository->leftOnAccount($account, $end),
|
||||||
'sumOfSaved' => $piggyBank->savedSoFar,
|
'sumOfSaved' => $piggyBank->savedSoFar,
|
||||||
'sumOfTargets' => floatval($piggyBank->targetamount),
|
'sumOfTargets' => floatval($piggyBank->targetamount),
|
||||||
'leftToSave' => $piggyBank->leftToSave
|
'leftToSave' => $piggyBank->leftToSave
|
||||||
@@ -215,7 +217,8 @@ class PiggyBankController extends Controller
|
|||||||
public function postAdd(PiggyBankRepositoryInterface $repository, AccountRepositoryInterface $accounts, PiggyBank $piggyBank)
|
public function postAdd(PiggyBankRepositoryInterface $repository, AccountRepositoryInterface $accounts, PiggyBank $piggyBank)
|
||||||
{
|
{
|
||||||
$amount = round(floatval(Input::get('amount')), 2);
|
$amount = round(floatval(Input::get('amount')), 2);
|
||||||
$leftOnAccount = $accounts->leftOnAccount($piggyBank->account);
|
$date = Session::get('end', Carbon::now()->endOfMonth());
|
||||||
|
$leftOnAccount = $accounts->leftOnAccount($piggyBank->account, $date);
|
||||||
$savedSoFar = $piggyBank->currentRelevantRep()->currentamount;
|
$savedSoFar = $piggyBank->currentRelevantRep()->currentamount;
|
||||||
$leftToSave = $piggyBank->targetamount - $savedSoFar;
|
$leftToSave = $piggyBank->targetamount - $savedSoFar;
|
||||||
$maxAmount = round(min($leftOnAccount, $leftToSave), 2);
|
$maxAmount = round(min($leftOnAccount, $leftToSave), 2);
|
||||||
|
@@ -17,6 +17,8 @@ class ConfigServiceProvider extends ServiceProvider
|
|||||||
* to overwrite any "vendor" or package configuration that you may want to
|
* to overwrite any "vendor" or package configuration that you may want to
|
||||||
* modify before the application handles the incoming request / command.
|
* modify before the application handles the incoming request / command.
|
||||||
*
|
*
|
||||||
|
* @SuppressWarnings(PHPMD.ExcessiveMethodLength)
|
||||||
|
*
|
||||||
* @return void
|
* @return void
|
||||||
*/
|
*/
|
||||||
public function register()
|
public function register()
|
||||||
|
@@ -308,12 +308,14 @@ class AccountRepository implements AccountRepositoryInterface
|
|||||||
|
|
||||||
/**
|
/**
|
||||||
* @param Account $account
|
* @param Account $account
|
||||||
|
* @param Carbon $date
|
||||||
*
|
*
|
||||||
* @return float
|
* @return float
|
||||||
*/
|
*/
|
||||||
public function leftOnAccount(Account $account)
|
public function leftOnAccount(Account $account, Carbon $date)
|
||||||
{
|
{
|
||||||
$balance = Steam::balance($account, null, true);
|
|
||||||
|
$balance = Steam::balance($account, $date, true);
|
||||||
/** @var PiggyBank $p */
|
/** @var PiggyBank $p */
|
||||||
foreach ($account->piggybanks()->get() as $p) {
|
foreach ($account->piggybanks()->get() as $p) {
|
||||||
$balance -= $p->currentRelevantRep()->currentamount;
|
$balance -= $p->currentRelevantRep()->currentamount;
|
||||||
|
@@ -115,10 +115,11 @@ interface AccountRepositoryInterface
|
|||||||
|
|
||||||
/**
|
/**
|
||||||
* @param Account $account
|
* @param Account $account
|
||||||
|
* @param Carbon $date
|
||||||
*
|
*
|
||||||
* @return float
|
* @return float
|
||||||
*/
|
*/
|
||||||
public function leftOnAccount(Account $account);
|
public function leftOnAccount(Account $account, Carbon $date);
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* @param Account $account
|
* @param Account $account
|
||||||
|
@@ -261,7 +261,6 @@ class BudgetRepository implements BudgetRepositoryInterface
|
|||||||
* @param bool $shared
|
* @param bool $shared
|
||||||
*
|
*
|
||||||
* @return float
|
* @return float
|
||||||
* @internal param Carbon $date
|
|
||||||
*/
|
*/
|
||||||
public function spentInPeriod(Budget $budget, Carbon $start, Carbon $end, $shared = true)
|
public function spentInPeriod(Budget $budget, Carbon $start, Carbon $end, $shared = true)
|
||||||
{
|
{
|
||||||
|
@@ -28,21 +28,11 @@ class Navigation
|
|||||||
$add = ($skip + 1);
|
$add = ($skip + 1);
|
||||||
|
|
||||||
$functionMap = [
|
$functionMap = [
|
||||||
'1D' => 'addDays',
|
'1D' => 'addDays', 'daily' => 'addDays',
|
||||||
'daily' => 'addDays',
|
'1W' => 'addWeeks', 'weekly' => 'addWeeks', 'week' => 'addWeeks',
|
||||||
'1W' => 'addWeeks',
|
'1M' => 'addMonths', 'month' => 'addMonths', 'monthly' => 'addMonths', '3M' => 'addMonths',
|
||||||
'weekly' => 'addWeeks',
|
'quarter' => 'addMonths', 'quarterly' => 'addMonths', '6M' => 'addMonths', 'half-year' => 'addMonths',
|
||||||
'week' => 'addWeeks',
|
'year' => 'addYears', 'yearly' => 'addYears',
|
||||||
'1M' => 'addMonths',
|
|
||||||
'month' => 'addMonths',
|
|
||||||
'monthly' => 'addMonths',
|
|
||||||
'3M' => 'addMonths',
|
|
||||||
'quarter' => 'addMonths',
|
|
||||||
'quarterly' => 'addMonths',
|
|
||||||
'6M' => 'addMonths',
|
|
||||||
'half-year' => 'addMonths',
|
|
||||||
'year' => 'addYears',
|
|
||||||
'yearly' => 'addYears',
|
|
||||||
];
|
];
|
||||||
$modifierMap = [
|
$modifierMap = [
|
||||||
'quarter' => 3,
|
'quarter' => 3,
|
||||||
|
@@ -23,12 +23,9 @@ class Steam
|
|||||||
*
|
*
|
||||||
* @return float
|
* @return float
|
||||||
*/
|
*/
|
||||||
public function balance(Account $account, Carbon $date = null, $ignoreVirtualBalance = false)
|
public function balance(Account $account, Carbon $date, $ignoreVirtualBalance = false)
|
||||||
{
|
{
|
||||||
$date = is_null($date) ? Carbon::now() : $date;
|
|
||||||
|
|
||||||
// find the first known transaction on this account:
|
// find the first known transaction on this account:
|
||||||
//
|
|
||||||
$firstDateObject = $account
|
$firstDateObject = $account
|
||||||
->transactions()
|
->transactions()
|
||||||
->leftJoin('transaction_journals', 'transaction_journals.id', '=', 'transactions.transaction_journal_id')
|
->leftJoin('transaction_journals', 'transaction_journals.id', '=', 'transactions.transaction_journal_id')
|
||||||
@@ -37,12 +34,6 @@ class Steam
|
|||||||
$firstDate = is_null($firstDateObject) ? clone $date : new Carbon($firstDateObject->date);
|
$firstDate = is_null($firstDateObject) ? clone $date : new Carbon($firstDateObject->date);
|
||||||
$date = $date < $firstDate ? $firstDate : $date;
|
$date = $date < $firstDate ? $firstDate : $date;
|
||||||
|
|
||||||
/**
|
|
||||||
*select * from transactions
|
|
||||||
* left join transaction_journals ON transaction_journals.id = transactions.transaction_journal_id
|
|
||||||
* order by date ASC
|
|
||||||
*/
|
|
||||||
|
|
||||||
$balance = floatval(
|
$balance = floatval(
|
||||||
$account->transactions()->leftJoin(
|
$account->transactions()->leftJoin(
|
||||||
'transaction_journals', 'transaction_journals.id', '=', 'transactions.transaction_journal_id'
|
'transaction_journals', 'transaction_journals.id', '=', 'transactions.transaction_journal_id'
|
||||||
|
@@ -21,6 +21,7 @@ class General extends Twig_Extension
|
|||||||
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
|
* @SuppressWarnings(PHPMD.ExcessiveMethodLength)
|
||||||
* @return array
|
* @return array
|
||||||
*/
|
*/
|
||||||
public function getFilters()
|
public function getFilters()
|
||||||
|
@@ -18,6 +18,7 @@ class Journal extends Twig_Extension
|
|||||||
{
|
{
|
||||||
|
|
||||||
/**
|
/**
|
||||||
|
* @SuppressWarnings(PHPMD.CyclomaticComplexity)
|
||||||
* @return array
|
* @return array
|
||||||
*/
|
*/
|
||||||
public function getFilters()
|
public function getFilters()
|
||||||
@@ -27,20 +28,25 @@ class Journal extends Twig_Extension
|
|||||||
$filters[] = new Twig_SimpleFilter(
|
$filters[] = new Twig_SimpleFilter(
|
||||||
'typeIcon', function (TransactionJournal $journal) {
|
'typeIcon', function (TransactionJournal $journal) {
|
||||||
$type = $journal->transactionType->type;
|
$type = $journal->transactionType->type;
|
||||||
if ($type == 'Withdrawal') {
|
|
||||||
return '<span class="glyphicon glyphicon-arrow-left" title="Withdrawal"></span>';
|
switch ($type) {
|
||||||
}
|
case 'Withdrawal':
|
||||||
if ($type == 'Deposit') {
|
return '<span class="glyphicon glyphicon-arrow-left" title="' . trans('firefly.withdrawal') . '"></span>';
|
||||||
return '<span class="glyphicon glyphicon-arrow-right" title="Deposit"></span>';
|
break;
|
||||||
}
|
case 'Deposit':
|
||||||
if ($type == 'Transfer') {
|
return '<span class="glyphicon glyphicon-arrow-right" title="' . trans('firefly.deposit') . '"></span>';
|
||||||
return '<i class="fa fa-fw fa-exchange" title="Transfer"></i>';
|
break;
|
||||||
}
|
case 'Transfer':
|
||||||
if ($type == 'Opening balance') {
|
return '<i class="fa fa-fw fa-exchange" title="' . trans('firefly.transfer') . '"></i>';
|
||||||
return '<span class="glyphicon glyphicon-ban-circle" title="Opening balance"></span>';
|
break;
|
||||||
|
case 'Opening balance':
|
||||||
|
return '<span class="glyphicon glyphicon-ban-circle" title="' . trans('firefly.openingBalance') . '"></span>';
|
||||||
|
break;
|
||||||
|
default:
|
||||||
|
return '';
|
||||||
|
break;
|
||||||
}
|
}
|
||||||
|
|
||||||
return '';
|
|
||||||
|
|
||||||
}, ['is_safe' => ['html']]
|
}, ['is_safe' => ['html']]
|
||||||
);
|
);
|
||||||
@@ -49,6 +55,8 @@ class Journal extends Twig_Extension
|
|||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
|
* @SuppressWarnings(PHPMD.CyclomaticComplexity)
|
||||||
|
*
|
||||||
* @return array
|
* @return array
|
||||||
*/
|
*/
|
||||||
public function getFunctions()
|
public function getFunctions()
|
||||||
|
Reference in New Issue
Block a user