mirror of
https://github.com/firefly-iii/firefly-iii.git
synced 2025-10-12 15:35:15 +00:00
Fixed some more reports and charts. [skip ci]
This commit is contained in:
@@ -129,7 +129,7 @@ class ReportHelper implements ReportHelperInterface
|
||||
$balanceEntry->setAccount($account);
|
||||
|
||||
// get spent:
|
||||
$spent = $this->query->spentInBudget($account, $budget, $start, $end); // I think shared is irrelevant.
|
||||
$spent = $this->query->spentInBudgetCorrected($account, $budget, $start, $end); // I think shared is irrelevant.
|
||||
|
||||
$balanceEntry->setSpent($spent);
|
||||
$line->addBalanceEntry($balanceEntry);
|
||||
|
@@ -300,6 +300,32 @@ class ReportQuery implements ReportQueryInterface
|
||||
);
|
||||
}
|
||||
|
||||
/**
|
||||
* Covers tags
|
||||
*
|
||||
* @param Account $account
|
||||
* @param Budget $budget
|
||||
* @param Carbon $start
|
||||
* @param Carbon $end
|
||||
*
|
||||
* @return float
|
||||
*/
|
||||
public function spentInBudgetCorrected(Account $account, Budget $budget, Carbon $start, Carbon $end)
|
||||
{
|
||||
|
||||
return floatval(
|
||||
Auth::user()->transactionjournals()
|
||||
->leftJoin('transactions', 'transactions.transaction_journal_id', '=', 'transaction_journals.id')
|
||||
->leftJoin('budget_transaction_journal', 'budget_transaction_journal.transaction_journal_id', '=', 'transaction_journals.id')
|
||||
->transactionTypes(['Withdrawal'])
|
||||
->where('transactions.account_id', $account->id)
|
||||
->before($end)
|
||||
->after($start)
|
||||
->where('budget_transaction_journal.budget_id', $budget->id)
|
||||
->get(['transaction_journals.*'])->sum('amount')
|
||||
) * -1;
|
||||
}
|
||||
|
||||
/**
|
||||
* @param Account $account
|
||||
* @param Carbon $start
|
||||
|
@@ -89,6 +89,18 @@ interface ReportQueryInterface
|
||||
*/
|
||||
public function spentInBudget(Account $account, Budget $budget, Carbon $start, Carbon $end);
|
||||
|
||||
/**
|
||||
* Covers tags as well.
|
||||
*
|
||||
* @param Account $account
|
||||
* @param Budget $budget
|
||||
* @param Carbon $start
|
||||
* @param Carbon $end
|
||||
*
|
||||
* @return float
|
||||
*/
|
||||
public function spentInBudgetCorrected(Account $account, Budget $budget, Carbon $start, Carbon $end);
|
||||
|
||||
/**
|
||||
* @param Account $account
|
||||
* @param Carbon $start
|
||||
|
@@ -78,13 +78,10 @@ class CategoryController extends Controller
|
||||
|
||||
$start = Session::get('start', Carbon::now()->startOfMonth());
|
||||
$end = Session::get('end', Carbon::now()->endOfMonth());
|
||||
$set = $repository->getCategoriesAndExpenses($start, $end);
|
||||
$set = $repository->getCategoriesAndExpensesCorrected($start, $end);
|
||||
|
||||
foreach ($set as $entry) {
|
||||
$isEncrypted = intval($entry->encrypted) == 1 ? true : false;
|
||||
$name = strlen($entry->name) == 0 ? trans('firefly.noCategory') : $entry->name;
|
||||
$name = $isEncrypted ? Crypt::decrypt($name) : $name;
|
||||
$chart->addRow($name, floatval($entry->sum));
|
||||
$chart->addRow($entry['name'], floatval($entry['sum']));
|
||||
}
|
||||
|
||||
$chart->generate();
|
||||
|
@@ -73,9 +73,9 @@ class Range
|
||||
Session::put('first', Carbon::now()->startOfYear());
|
||||
}
|
||||
}
|
||||
$current = Carbon::now()->format('F Y');
|
||||
$next = Carbon::now()->endOfMonth()->addDay()->format('F Y');
|
||||
$prev = Carbon::now()->startOfMonth()->subDay()->format('F Y');
|
||||
$current = Carbon::now()->formatLocalized('%B %Y');
|
||||
$next = Carbon::now()->endOfMonth()->addDay()->formatLocalized('%B %Y');
|
||||
$prev = Carbon::now()->startOfMonth()->subDay()->formatLocalized('%B %Y');
|
||||
View::share('currentMonthName', $current);
|
||||
View::share('previousMonthName', $prev);
|
||||
View::share('nextMonthName', $next);
|
||||
|
@@ -4,6 +4,7 @@ namespace FireflyIII\Repositories\Category;
|
||||
|
||||
use Auth;
|
||||
use Carbon\Carbon;
|
||||
use Crypt;
|
||||
use DB;
|
||||
use FireflyIII\Models\Category;
|
||||
use FireflyIII\Models\TransactionJournal;
|
||||
@@ -87,6 +88,47 @@ class CategoryRepository implements CategoryRepositoryInterface
|
||||
->get(['categories.id', 'categories.encrypted', 'categories.name', DB::Raw('SUM(`transactions`.`amount`) AS `sum`')]);
|
||||
}
|
||||
|
||||
/**
|
||||
*
|
||||
* @param Carbon $start
|
||||
* @param Carbon $end
|
||||
*
|
||||
* @return Collection
|
||||
*/
|
||||
public function getCategoriesAndExpensesCorrected($start, $end)
|
||||
{
|
||||
$set = Auth::user()->transactionjournals()
|
||||
->leftJoin(
|
||||
'category_transaction_journal', 'category_transaction_journal.transaction_journal_id', '=', 'transaction_journals.id'
|
||||
)
|
||||
->leftJoin('categories', 'categories.id', '=', 'category_transaction_journal.category_id')
|
||||
->before($end)
|
||||
->where('categories.user_id', Auth::user()->id)
|
||||
->after($start)
|
||||
->transactionTypes(['Withdrawal'])
|
||||
->groupBy('categories.id')
|
||||
->get(['categories.id as category_id', 'categories.encrypted', 'categories.name', 'transaction_journals.*']);
|
||||
|
||||
$result = [];
|
||||
foreach ($set as $entry) {
|
||||
$categoryId = intval($entry->category_id);
|
||||
if (isset($result[$categoryId])) {
|
||||
$result[$categoryId]['sum'] += $entry->amount;
|
||||
} else {
|
||||
$isEncrypted = intval($entry->encrypted) == 1 ? true : false;
|
||||
$name = strlen($entry->name) == 0 ? trans('firefly.noCategory') : $entry->name;
|
||||
$name = $isEncrypted ? Crypt::decrypt($name) : $name;
|
||||
$result[$categoryId] = [
|
||||
'name' => $name,
|
||||
'sum' => $entry->amount,
|
||||
];
|
||||
|
||||
}
|
||||
}
|
||||
|
||||
return $result;
|
||||
}
|
||||
|
||||
/**
|
||||
* @param Category $category
|
||||
*
|
||||
@@ -220,10 +262,10 @@ class CategoryRepository implements CategoryRepositoryInterface
|
||||
// shared is true.
|
||||
// always ignore transfers between accounts!
|
||||
$sum = floatval(
|
||||
$category->transactionjournals()
|
||||
->transactionTypes(['Withdrawal'])
|
||||
->before($end)->after($start)->get(['transaction_journals.*'])->sum('amount')
|
||||
);
|
||||
$category->transactionjournals()
|
||||
->transactionTypes(['Withdrawal'])
|
||||
->before($end)->after($start)->get(['transaction_journals.*'])->sum('amount')
|
||||
);
|
||||
|
||||
} else {
|
||||
// do something else, SEE budgets.
|
||||
@@ -260,6 +302,7 @@ class CategoryRepository implements CategoryRepositoryInterface
|
||||
|
||||
/**
|
||||
* Corrected for tags
|
||||
*
|
||||
* @param Category $category
|
||||
* @param Carbon $date
|
||||
*
|
||||
|
@@ -40,6 +40,16 @@ interface CategoryRepositoryInterface
|
||||
*/
|
||||
public function getCategoriesAndExpenses($start, $end);
|
||||
|
||||
/**
|
||||
* Corrected for tags.
|
||||
*
|
||||
* @param Carbon $start
|
||||
* @param Carbon $end
|
||||
*
|
||||
* @return Collection
|
||||
*/
|
||||
public function getCategoriesAndExpensesCorrected($start, $end);
|
||||
|
||||
/**
|
||||
* @param Category $category
|
||||
*
|
||||
|
Reference in New Issue
Block a user