Merge branch 'feature/expand-transaction-view' into develop

This commit is contained in:
Sander Dorigo 2014-10-11 09:54:33 +02:00
commit d40645be68
2 changed files with 53 additions and 44 deletions

View File

@ -34,9 +34,9 @@ class Json implements JsonInterface
$length = intval(\Input::get('length')); $length = intval(\Input::get('length'));
} }
$parameters = [ $parameters = [
'start' => intval(\Input::get('start')), 'start' => intval(\Input::get('start')),
'length' => $length, 'length' => $length,
'draw' => intval(\Input::get('draw')), 'draw' => intval(\Input::get('draw')),
]; ];
@ -46,11 +46,11 @@ class Json implements JsonInterface
if (!is_null(\Input::get('columns')) && is_array(\Input::get('columns'))) { if (!is_null(\Input::get('columns')) && is_array(\Input::get('columns'))) {
foreach (\Input::get('columns') as $column) { foreach (\Input::get('columns') as $column) {
$parameters['columns'][] = [ $parameters['columns'][] = [
'data' => $column['data'], 'data' => $column['data'],
'name' => $column['name'], 'name' => $column['name'],
'searchable' => $column['searchable'] == 'true' ? true : false, 'searchable' => $column['searchable'] == 'true' ? true : false,
'orderable' => $column['orderable'] == 'true' ? true : false, 'orderable' => $column['orderable'] == 'true' ? true : false,
'search' => [ 'search' => [
'value' => $column['search']['value'], 'value' => $column['search']['value'],
'regex' => $column['search']['regex'] == 'true' ? true : false, 'regex' => $column['search']['regex'] == 'true' ? true : false,
] ]
@ -69,7 +69,7 @@ class Json implements JsonInterface
$columnName = $parameters['columns'][$columnIndex]['name']; $columnName = $parameters['columns'][$columnIndex]['name'];
$parameters['order'][] = [ $parameters['order'][] = [
'name' => $columnName, 'name' => $columnName,
'dir' => strtoupper($order['dir']) 'dir' => strtoupper($order['dir'])
]; ];
if ($columnName == 'to' || $columnName == 'from') { if ($columnName == 'to' || $columnName == 'from') {
$parameters['orderOnAccount'] = true; $parameters['orderOnAccount'] = true;
@ -97,7 +97,7 @@ class Json implements JsonInterface
* Do some sorting, counting and ordering on the query and return a nicely formatted array * Do some sorting, counting and ordering on the query and return a nicely formatted array
* that can be used by the DataTables JQuery plugin. * that can be used by the DataTables JQuery plugin.
* *
* @param array $parameters * @param array $parameters
* @param Builder $query * @param Builder $query
* *
* @return array * @return array
@ -132,10 +132,10 @@ class Json implements JsonInterface
* Build return array: * Build return array:
*/ */
$data = [ $data = [
'draw' => $parameters['draw'], 'draw' => $parameters['draw'],
'recordsTotal' => $count, 'recordsTotal' => $count,
'recordsFiltered' => $filtered, 'recordsFiltered' => $filtered,
'data' => [], 'data' => [],
]; ];
@ -169,19 +169,20 @@ class Json implements JsonInterface
*/ */
/** @var \TransactionJournal $entry */ /** @var \TransactionJournal $entry */
foreach ($set as $entry) { foreach ($set as $entry) {
$from = $entry->transactions[0]->account; $from = $entry->transactions[0]->account;
$to = $entry->transactions[1]->account; $to = $entry->transactions[1]->account;
$budget = $entry->budgets()->first(); $budget = $entry->budgets()->first();
$category = $entry->categories()->first(); $category = $entry->categories()->first();
$arr = [ $recurring = $entry->recurringTransaction()->first();
'date' => $entry->date->format('j F Y'), $arr = [
'date' => $entry->date->format('j F Y'),
'description' => [ 'description' => [
'description' => $entry->description, 'description' => $entry->description,
'url' => route('transactions.show', $entry->id) 'url' => route('transactions.show', $entry->id)
], ],
'amount' => floatval($entry->amount), 'amount' => floatval($entry->amount),
'from' => ['name' => $from->name, 'url' => route('accounts.show', $from->id)], 'from' => ['name' => $from->name, 'url' => route('accounts.show', $from->id)],
'to' => ['name' => $to->name, 'url' => route('accounts.show', $to->id)], 'to' => ['name' => $to->name, 'url' => route('accounts.show', $to->id)],
'components' => [ 'components' => [
'budget_id' => 0, 'budget_id' => 0,
'budget_url' => '', 'budget_url' => '',
@ -190,20 +191,25 @@ class Json implements JsonInterface
'category_url' => '', 'category_url' => '',
'category_name' => '' 'category_name' => ''
], ],
'id' => [ 'id' => [
'edit' => route('transactions.edit', $entry->id), 'edit' => route('transactions.edit', $entry->id),
'delete' => route('transactions.delete', $entry->id) 'delete' => route('transactions.delete', $entry->id)
] ]
]; ];
if($budget) { if ($budget) {
$arr['components']['budget_id'] = $budget->id; $arr['components']['budget_id'] = $budget->id;
$arr['components']['budget_name'] = $budget->name; $arr['components']['budget_name'] = $budget->name;
$arr['components']['budget_url'] = route('budgets.show',$budget->id); $arr['components']['budget_url'] = route('budgets.show', $budget->id);
} }
if($category) { if ($category) {
$arr['components']['category_id'] = $category->id; $arr['components']['category_id'] = $category->id;
$arr['components']['category_name'] = $category->name; $arr['components']['category_name'] = $category->name;
$arr['components']['category_url'] = route('categories.show',$category->id); $arr['components']['category_url'] = route('categories.show', $category->id);
}
if ($recurring) {
$arr['components']['recurring_id'] = $recurring->id;
$arr['components']['recurring_name'] = e($recurring->name);
$arr['components']['recurring_url'] = route('recurring.show', $recurring->id);
} }
$data['data'][] = $arr; $data['data'][] = $arr;
@ -257,14 +263,14 @@ class Json implements JsonInterface
$query->leftJoin( $query->leftJoin(
'transactions AS ' . $prefix . 't1', function ($join) use ($operator) { 'transactions AS ' . $prefix . 't1', function ($join) use ($operator) {
$join->on('t1.transaction_journal_id', '=', 'transaction_journals.id') $join->on('t1.transaction_journal_id', '=', 'transaction_journals.id')
->on('t1.amount', $operator, \DB::Raw(0)); ->on('t1.amount', $operator, \DB::Raw(0));
} }
); );
// left join second table for "to" account: // left join second table for "to" account:
$query->leftJoin( $query->leftJoin(
'transactions AS ' . $prefix . 't2', function ($join) use ($operatorNegated) { 'transactions AS ' . $prefix . 't2', function ($join) use ($operatorNegated) {
$join->on('t2.transaction_journal_id', '=', 'transaction_journals.id') $join->on('t2.transaction_journal_id', '=', 'transaction_journals.id')
->on('t2.amount', $operatorNegated, \DB::Raw(0)); ->on('t2.amount', $operatorNegated, \DB::Raw(0));
} }
); );
@ -293,7 +299,7 @@ class Json implements JsonInterface
* Do some sorting, counting and ordering on the query and return a nicely formatted array * Do some sorting, counting and ordering on the query and return a nicely formatted array
* that can be used by the DataTables JQuery plugin. * that can be used by the DataTables JQuery plugin.
* *
* @param array $parameters * @param array $parameters
* @param Builder $query * @param Builder $query
* *
* @return array * @return array
@ -328,10 +334,10 @@ class Json implements JsonInterface
* Build return array: * Build return array:
*/ */
$data = [ $data = [
'draw' => $parameters['draw'], 'draw' => $parameters['draw'],
'recordsTotal' => $count, 'recordsTotal' => $count,
'recordsFiltered' => $filtered, 'recordsFiltered' => $filtered,
'data' => [], 'data' => [],
]; ];
@ -351,16 +357,16 @@ class Json implements JsonInterface
foreach ($set as $entry) { foreach ($set as $entry) {
$data['data'][] = [ $data['data'][] = [
'name' => ['name' => $entry->name,'url' => route('recurring.show',$entry->id)], 'name' => ['name' => $entry->name, 'url' => route('recurring.show', $entry->id)],
'match' => explode(' ',$entry->match), 'match' => explode(' ', $entry->match),
'amount_max' => floatval($entry->amount_max), 'amount_max' => floatval($entry->amount_max),
'amount_min' => floatval($entry->amount_min), 'amount_min' => floatval($entry->amount_min),
'date' => $entry->date->format('j F Y'), 'date' => $entry->date->format('j F Y'),
'active' => intval($entry->active), 'active' => intval($entry->active),
'automatch' => intval($entry->automatch), 'automatch' => intval($entry->automatch),
'repeat_freq' => $entry->repeat_freq, 'repeat_freq' => $entry->repeat_freq,
'id' => [ 'id' => [
'edit' => route('recurring.edit', $entry->id), 'edit' => route('recurring.edit', $entry->id),
'delete' => route('recurring.delete', $entry->id) 'delete' => route('recurring.delete', $entry->id)
] ]
]; ];

View File

@ -95,6 +95,9 @@ $(document).ready(function () {
if (data.category_id > 0) { if (data.category_id > 0) {
html += '<a href="' + data.category_url + '" title="' + data.category_name + '"><i class="fa fa-bar-chart fa-fw"></i></a> '; html += '<a href="' + data.category_url + '" title="' + data.category_name + '"><i class="fa fa-bar-chart fa-fw"></i></a> ';
} }
if(data.recurring_id > 0) {
html += '<a href="' + data.recurring_url + '" title="' + data.recurring_name + '"><i class="fa fa-rotate-right fa-fw"></i></a> ';
}
return html; return html;
} }
}, },