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
|
||||
|
@@ -78,19 +78,4 @@ interface ReportQueryInterface
|
||||
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();
|
||||
foreach ($creditCards as $creditCard) {
|
||||
$balance = Steam::balance($creditCard, null, true);
|
||||
$balance = Steam::balance($creditCard, $end, true);
|
||||
$date = new Carbon($creditCard->getMeta('ccMonthlyPaymentDate'));
|
||||
if ($balance < 0) {
|
||||
// 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.
|
||||
/** @var Account $creditCard */
|
||||
foreach ($creditCards as $creditCard) {
|
||||
$balance = Steam::balance($creditCard, null, true);
|
||||
$balance = Steam::balance($creditCard, $end, true);
|
||||
if ($balance == 0) {
|
||||
// find a transfer TO the credit card which should account for
|
||||
// anything paid. If not, the CC is not yet used.
|
||||
@@ -99,7 +99,7 @@ class JsonController extends Controller
|
||||
|
||||
$creditCards = $accountRepository->getCreditCards();
|
||||
foreach ($creditCards as $creditCard) {
|
||||
$balance = Steam::balance($creditCard, null, true);
|
||||
$balance = Steam::balance($creditCard, $end, true);
|
||||
$date = new Carbon($creditCard->getMeta('ccMonthlyPaymentDate'));
|
||||
if ($balance < 0) {
|
||||
// unpaid! create a fake bill that matches the amount.
|
||||
|
@@ -45,7 +45,8 @@ class PiggyBankController extends Controller
|
||||
*/
|
||||
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;
|
||||
$leftToSave = $piggyBank->targetamount - $savedSoFar;
|
||||
$maxAmount = min($leftOnAccount, $leftToSave);
|
||||
@@ -157,6 +158,7 @@ class PiggyBankController extends Controller
|
||||
{
|
||||
/** @var Collection $piggyBanks */
|
||||
$piggyBanks = $piggyRepository->getPiggyBanks();
|
||||
$end = Session::get('end', Carbon::now()->endOfMonth());
|
||||
|
||||
$accounts = [];
|
||||
/** @var PiggyBank $piggyBank */
|
||||
@@ -172,8 +174,8 @@ class PiggyBankController extends Controller
|
||||
if (!isset($accounts[$account->id])) {
|
||||
$accounts[$account->id] = [
|
||||
'name' => $account->name,
|
||||
'balance' => Steam::balance($account, null, true),
|
||||
'leftForPiggyBanks' => $repository->leftOnAccount($account),
|
||||
'balance' => Steam::balance($account, $end, true),
|
||||
'leftForPiggyBanks' => $repository->leftOnAccount($account, $end),
|
||||
'sumOfSaved' => $piggyBank->savedSoFar,
|
||||
'sumOfTargets' => floatval($piggyBank->targetamount),
|
||||
'leftToSave' => $piggyBank->leftToSave
|
||||
@@ -215,7 +217,8 @@ class PiggyBankController extends Controller
|
||||
public function postAdd(PiggyBankRepositoryInterface $repository, AccountRepositoryInterface $accounts, PiggyBank $piggyBank)
|
||||
{
|
||||
$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;
|
||||
$leftToSave = $piggyBank->targetamount - $savedSoFar;
|
||||
$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
|
||||
* modify before the application handles the incoming request / command.
|
||||
*
|
||||
* @SuppressWarnings(PHPMD.ExcessiveMethodLength)
|
||||
*
|
||||
* @return void
|
||||
*/
|
||||
public function register()
|
||||
|
@@ -308,12 +308,14 @@ class AccountRepository implements AccountRepositoryInterface
|
||||
|
||||
/**
|
||||
* @param Account $account
|
||||
* @param Carbon $date
|
||||
*
|
||||
* @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 */
|
||||
foreach ($account->piggybanks()->get() as $p) {
|
||||
$balance -= $p->currentRelevantRep()->currentamount;
|
||||
|
@@ -115,10 +115,11 @@ interface AccountRepositoryInterface
|
||||
|
||||
/**
|
||||
* @param Account $account
|
||||
* @param Carbon $date
|
||||
*
|
||||
* @return float
|
||||
*/
|
||||
public function leftOnAccount(Account $account);
|
||||
public function leftOnAccount(Account $account, Carbon $date);
|
||||
|
||||
/**
|
||||
* @param Account $account
|
||||
|
@@ -261,7 +261,6 @@ class BudgetRepository implements BudgetRepositoryInterface
|
||||
* @param bool $shared
|
||||
*
|
||||
* @return float
|
||||
* @internal param Carbon $date
|
||||
*/
|
||||
public function spentInPeriod(Budget $budget, Carbon $start, Carbon $end, $shared = true)
|
||||
{
|
||||
|
@@ -28,21 +28,11 @@ class Navigation
|
||||
$add = ($skip + 1);
|
||||
|
||||
$functionMap = [
|
||||
'1D' => 'addDays',
|
||||
'daily' => 'addDays',
|
||||
'1W' => 'addWeeks',
|
||||
'weekly' => 'addWeeks',
|
||||
'week' => 'addWeeks',
|
||||
'1M' => 'addMonths',
|
||||
'month' => 'addMonths',
|
||||
'monthly' => 'addMonths',
|
||||
'3M' => 'addMonths',
|
||||
'quarter' => 'addMonths',
|
||||
'quarterly' => 'addMonths',
|
||||
'6M' => 'addMonths',
|
||||
'half-year' => 'addMonths',
|
||||
'year' => 'addYears',
|
||||
'yearly' => 'addYears',
|
||||
'1D' => 'addDays', 'daily' => 'addDays',
|
||||
'1W' => 'addWeeks', 'weekly' => 'addWeeks', 'week' => 'addWeeks',
|
||||
'1M' => 'addMonths', 'month' => 'addMonths', 'monthly' => 'addMonths', '3M' => 'addMonths',
|
||||
'quarter' => 'addMonths', 'quarterly' => 'addMonths', '6M' => 'addMonths', 'half-year' => 'addMonths',
|
||||
'year' => 'addYears', 'yearly' => 'addYears',
|
||||
];
|
||||
$modifierMap = [
|
||||
'quarter' => 3,
|
||||
|
@@ -23,12 +23,9 @@ class Steam
|
||||
*
|
||||
* @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:
|
||||
//
|
||||
$firstDateObject = $account
|
||||
->transactions()
|
||||
->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);
|
||||
$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(
|
||||
$account->transactions()->leftJoin(
|
||||
'transaction_journals', 'transaction_journals.id', '=', 'transactions.transaction_journal_id'
|
||||
|
@@ -21,6 +21,7 @@ class General extends Twig_Extension
|
||||
|
||||
|
||||
/**
|
||||
* @SuppressWarnings(PHPMD.ExcessiveMethodLength)
|
||||
* @return array
|
||||
*/
|
||||
public function getFilters()
|
||||
|
@@ -18,6 +18,7 @@ class Journal extends Twig_Extension
|
||||
{
|
||||
|
||||
/**
|
||||
* @SuppressWarnings(PHPMD.CyclomaticComplexity)
|
||||
* @return array
|
||||
*/
|
||||
public function getFilters()
|
||||
@@ -27,20 +28,25 @@ class Journal extends Twig_Extension
|
||||
$filters[] = new Twig_SimpleFilter(
|
||||
'typeIcon', function (TransactionJournal $journal) {
|
||||
$type = $journal->transactionType->type;
|
||||
if ($type == 'Withdrawal') {
|
||||
return '<span class="glyphicon glyphicon-arrow-left" title="Withdrawal"></span>';
|
||||
}
|
||||
if ($type == 'Deposit') {
|
||||
return '<span class="glyphicon glyphicon-arrow-right" title="Deposit"></span>';
|
||||
}
|
||||
if ($type == 'Transfer') {
|
||||
return '<i class="fa fa-fw fa-exchange" title="Transfer"></i>';
|
||||
}
|
||||
if ($type == 'Opening balance') {
|
||||
return '<span class="glyphicon glyphicon-ban-circle" title="Opening balance"></span>';
|
||||
|
||||
switch ($type) {
|
||||
case 'Withdrawal':
|
||||
return '<span class="glyphicon glyphicon-arrow-left" title="' . trans('firefly.withdrawal') . '"></span>';
|
||||
break;
|
||||
case 'Deposit':
|
||||
return '<span class="glyphicon glyphicon-arrow-right" title="' . trans('firefly.deposit') . '"></span>';
|
||||
break;
|
||||
case 'Transfer':
|
||||
return '<i class="fa fa-fw fa-exchange" title="' . trans('firefly.transfer') . '"></i>';
|
||||
break;
|
||||
case 'Opening balance':
|
||||
return '<span class="glyphicon glyphicon-ban-circle" title="' . trans('firefly.openingBalance') . '"></span>';
|
||||
break;
|
||||
default:
|
||||
return '';
|
||||
break;
|
||||
}
|
||||
|
||||
return '';
|
||||
|
||||
}, ['is_safe' => ['html']]
|
||||
);
|
||||
@@ -49,6 +55,8 @@ class Journal extends Twig_Extension
|
||||
}
|
||||
|
||||
/**
|
||||
* @SuppressWarnings(PHPMD.CyclomaticComplexity)
|
||||
*
|
||||
* @return array
|
||||
*/
|
||||
public function getFunctions()
|
||||
|
Reference in New Issue
Block a user