Fixed some more reports and charts. [skip ci]

This commit is contained in:
James Cole 2015-05-20 07:07:46 +02:00
parent 7a0ad5a587
commit 95ef691077
9 changed files with 109 additions and 38 deletions

View File

@ -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);

View File

@ -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

View File

@ -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

View File

@ -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();

View File

@ -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);

View File

@ -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
*

View File

@ -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
*

View File

@ -108,6 +108,7 @@ return [
'splitByAccount' => 'Split by account',
'balancedByTransfersAndTags' => 'Balanced by transfers and tags',
'coveredWithTags' => 'Covered with tags',
'leftUnbalanced' => 'Left unbalanced',
'expectedBalance' => 'Expected balance',
'outsideOfBudgets' => 'Outside of budgets',

View File

@ -1,37 +1,19 @@
<div class="list-group">
{% for journal in transactions %}
{% if journal.amount != 0 %}
<a class="list-group-item" title="{{journal.date.format('jS M Y')}}" href="{{route('transactions.show',journal.id)}}">
<a class="list-group-item" title="{{journal.date.format('jS M Y')}}" href="{{route('transactions.show',journal.id)}}">
{% if not journal.type %}
{% if journal.transactiontype.type == 'Withdrawal' %}
<i class="fa fa-long-arrow-left fa-fw" title="{{ trans('list.withdrawal') }}"></i>
{% endif %}
{% if journal.transactiontype.type == 'Deposit' %}
<i class="fa fa-long-arrow-right fa-fw" title="{{ trans('list.deposit') }}"></i>
{% endif %}
{% if journal.transactiontype.type == 'Transfer' %}
<i class="fa fa-fw fa-exchange" title="{{ trans('list.transfer') }}"></i>
{% endif %}
{% else %}
{% if journal.type == 'Withdrawal' %}
<i class="fa fa-long-arrow-left fa-fw" title="{{ trans('list.withdrawal') }}"></i>
{% endif %}
{% if journal.type == 'Deposit' %}
<i class="fa fa-long-arrow-right fa-fw" title="{{ trans('list.deposit') }}"></i>
{% endif %}
{% if journal.type == 'Transfer' %}
<i class="fa fa-fw fa-exchange" title="{{ trans('list.transfer') }}"></i>
{% endif %}
{% endif %}
{{ journal|typeIcon }}
{{ journal.description }}
<span class="pull-right small">
<span class="pull-right small">
{{ journal|formatJournal }}
</span>
</span>
</a>
</a>
{% endif %}
{% endfor %}
</div>