Add decryption routine.

This commit is contained in:
James Cole 2015-03-31 21:18:22 +02:00
parent cf23858c10
commit 566fadad15
5 changed files with 43 additions and 13 deletions

View File

@ -244,7 +244,9 @@ class ReportQuery implements ReportQueryInterface
DB::Raw('SUM(`t_to`.`amount`) as `amount`'), DB::Raw('SUM(`t_to`.`amount`) as `amount`'),
'transaction_journals.date', 'transaction_journals.date',
't_from.account_id as account_id', 't_from.account_id as account_id',
'ac_from.name as name'] 'ac_from.name as name',
'ac_from.encrypted as account_encrypted'
]
); );
} }
@ -323,7 +325,7 @@ class ReportQuery implements ReportQueryInterface
->groupBy('categories.id') ->groupBy('categories.id')
->orderBy('amount'); ->orderBy('amount');
return $query->get(['categories.id','categories.encrypted', 'categories.name', DB::Raw('SUM(`transactions`.`amount`) AS `amount`')]); return $query->get(['categories.id', 'categories.encrypted', 'categories.name', DB::Raw('SUM(`transactions`.`amount`) AS `amount`')]);
} }
@ -370,7 +372,7 @@ class ReportQuery implements ReportQueryInterface
->groupBy('t_to.account_id') ->groupBy('t_to.account_id')
->orderBy('amount', 'DESC'); ->orderBy('amount', 'DESC');
return $query->get(['t_to.account_id as id', 'ac_to.name as name', DB::Raw('SUM(t_to.amount) as `amount`')]); return $query->get(['t_to.account_id as id', 'ac_to.name as name', 'ac_to.encrypted', DB::Raw('SUM(t_to.amount) as `amount`')]);
} }
/** /**
@ -412,7 +414,9 @@ class ReportQuery implements ReportQueryInterface
$query->groupBy('t_from.account_id')->orderBy('amount'); $query->groupBy('t_from.account_id')->orderBy('amount');
return $query->get(['t_from.account_id as account_id', 'ac_from.name as name', DB::Raw('SUM(t_from.amount) as `amount`')]); return $query->get(
['t_from.account_id as account_id', 'ac_from.name as name', 'ac_from.encrypted as encrypted', DB::Raw('SUM(t_from.amount) as `amount`')]
);
} }
/** /**

View File

@ -247,6 +247,7 @@ class ReportController extends Controller
* Start getExpenseGroupedForMonth DONE * Start getExpenseGroupedForMonth DONE
*/ */
$set = $this->query->journalsByExpenseAccount($start, $end, $showSharedReports); $set = $this->query->journalsByExpenseAccount($start, $end, $showSharedReports);
$expenses = Steam::makeArray($set); $expenses = Steam::makeArray($set);
$expenses = Steam::sortArray($expenses); $expenses = Steam::sortArray($expenses);
$expenses = Steam::limitArray($expenses, 10); $expenses = Steam::limitArray($expenses, 10);
@ -268,6 +269,7 @@ class ReportController extends Controller
$result = $this->query->journalsByCategory($start, $end); $result = $this->query->journalsByCategory($start, $end);
$categories = Steam::makeArray($result); $categories = Steam::makeArray($result);
// loop and decrypt if necessary: // loop and decrypt if necessary:
foreach ($categories as $index => $category) { foreach ($categories as $index => $category) {
$categories[$index]['name'] $categories[$index]['name']
@ -283,6 +285,7 @@ class ReportController extends Controller
$merged = $categories; $merged = $categories;
} }
// sort. // sort.
$sorted = Steam::sortNegativeArray($merged); $sorted = Steam::sortNegativeArray($merged);

View File

@ -100,11 +100,13 @@ class Steam
if (isset($array[$id])) { if (isset($array[$id])) {
$array[$id]['amount'] += floatval($entry->amount); $array[$id]['amount'] += floatval($entry->amount);
$array[$id]['spent'] += floatval($entry->spent); $array[$id]['spent'] += floatval($entry->spent);
$array[$id]['encrypted'] = intval($entry->encrypted);
} else { } else {
$array[$id] = [ $array[$id] = [
'amount' => floatval($entry->amount), 'amount' => floatval($entry->amount),
'spent' => floatval($entry->spent), 'spent' => floatval($entry->spent),
'name' => $entry->name 'encrypted' => intval($entry->encrypted),
'name' => $entry->name
]; ];
} }
} }

View File

@ -44,7 +44,11 @@
{{$entry->date->format('j F Y')}} {{$entry->date->format('j F Y')}}
</td> </td>
<td> <td>
<a href="{{route('accounts.show',$entry->account_id)}}">{{{$entry->name}}}</a> @if(intval($entry->account_encrypted) == 1)
<a href="{{route('accounts.show',$entry->account_id)}}">{{{Crypt::decrypt($entry->name)}}}</a>
@else
<a href="{{route('accounts.show',$entry->account_id)}}">{{{$entry->name}}}</a>
@endif
</td> </td>
</tr> </tr>
@endforeach @endforeach
@ -67,11 +71,16 @@
<table class="table table-bordered"> <table class="table table-bordered">
<?php $sum = 0;?> <?php $sum = 0;?>
@foreach($expenses as $id => $expense) @foreach($expenses as $id => $expense)
<?php $sum += floatval($expense['amount']);?> <?php
$sum += floatval($expense['amount']);
$name = isset($expense['encrypted']) && intval($expense['encrypted']) ==1 ? Crypt::decrypt($expense['name']) :$expense['name'];
//var_dump($expense);
?>
<tr> <tr>
@if($id > 0) @if($id > 0)
<td><a href="{{route('accounts.show',$id)}}">{{{$expense['name']}}}</a></td> <td><a href="{{route('accounts.show',$id)}}">{{{$name}}}</a></td>
@else @else
<td><em>{{{$expense['name']}}}</em></td> <td><em>{{{$expense['name']}}}</em></td>
@endif @endif
<td>{!! Amount::format($expense['amount']) !!}</td> <td>{!! Amount::format($expense['amount']) !!}</td>

View File

@ -43,6 +43,12 @@
Account balance Account balance
</div> </div>
<table class="table table-bordered table-striped"> <table class="table table-bordered table-striped">
<tr>
<th>Name</th>
<th>Balance at start of year</th>
<th>Balance at end of year</th>
<th>Difference</th>
</tr>
<?php <?php
$start = 0; $start = 0;
$end = 0; $end = 0;
@ -120,9 +126,12 @@
<table class="table"> <table class="table">
<?php $sum = 0;?> <?php $sum = 0;?>
@foreach($groupedIncomes as $income) @foreach($groupedIncomes as $income)
<?php $sum += floatval($income->amount)*-1;?> <?php
$sum += floatval($income->amount)*-1;
$name = intval($income->encrypted) == 1 ? Crypt::decrypt($income->name) : $income->name;
?>
<tr> <tr>
<td><a href="{{route('accounts.show',$income->account_id)}}">{{{$income->name}}}</a></td> <td><a href="{{route('accounts.show',$income->account_id)}}">{{{$name}}}</a></td>
<td>{!! Amount::format(floatval($income->amount)*-1) !!}</td> <td>{!! Amount::format(floatval($income->amount)*-1) !!}</td>
</tr> </tr>
@endforeach @endforeach
@ -142,8 +151,11 @@
<table class="table"> <table class="table">
<?php $sum = 0;?> <?php $sum = 0;?>
@foreach($groupedExpenses as $id => $expense) @foreach($groupedExpenses as $id => $expense)
<?php
$name = intval($expense['encrypted']) == 1 ? Crypt::decrypt($expense['name']) : $expense['name'];
?>
<tr> <tr>
<td><a href="{{route('accounts.show',$id)}}">{{{$expense['name']}}}</a></td> <td><a href="{{route('accounts.show',$id)}}">{{{$name}}}</a></td>
<td>{!! Amount::format(floatval($expense['amount'])*-1) !!}</td> <td>{!! Amount::format(floatval($expense['amount'])*-1) !!}</td>
</tr> </tr>
<?php $sum += floatval($expense['amount'])*-1;?> <?php $sum += floatval($expense['amount'])*-1;?>