mirror of
https://github.com/firefly-iii/firefly-iii.git
synced 2024-11-27 11:20:39 -06:00
Completed views for transactions.
This commit is contained in:
parent
f15fc80233
commit
5f4669341e
@ -29,7 +29,18 @@ $(document).ready(function () {
|
||||
name: 'description',
|
||||
data: 'description',
|
||||
render: function (data, type, full, meta) {
|
||||
return '<span class="glyphicon glyphicon-arrow-left"></span> '+
|
||||
var icon = '';
|
||||
if(display == 'expenses') {
|
||||
icon = 'glyphicon-arrow-left';
|
||||
}
|
||||
if(display == 'revenue') {
|
||||
icon = 'glyphicon-arrow-right';
|
||||
}
|
||||
if(display == 'transfers') {
|
||||
icon = 'glyphicon-resize-full';
|
||||
}
|
||||
|
||||
return '<span class="glyphicon '+icon+'"></span> '+
|
||||
'<a href="' + data.url + '" title="' + data.description + '">' + data.description + '</a>';
|
||||
}
|
||||
},
|
||||
@ -37,7 +48,15 @@ $(document).ready(function () {
|
||||
name: 'amount',
|
||||
data: 'amount',
|
||||
render: function (data, type, full, meta) {
|
||||
return '<span class="text-danger">\u20AC ' + data.toFixed(2) + '</span>';
|
||||
if(display == 'expenses') {
|
||||
return '<span class="text-danger">\u20AC ' + data.toFixed(2) + '</span>';
|
||||
}
|
||||
if(display == 'revenue') {
|
||||
return '<span class="text-success">\u20AC ' + data.toFixed(2) + '</span>';
|
||||
}
|
||||
if(display == 'transfers') {
|
||||
return '<span class="text-info">\u20AC ' + data.toFixed(2) + '</span>';
|
||||
}
|
||||
}
|
||||
},
|
||||
{
|
||||
|
@ -6,6 +6,7 @@ use Firefly\Storage\Category\CategoryRepositoryInterface as Cat;
|
||||
use Firefly\Storage\Component\ComponentRepositoryInterface as CRI;
|
||||
use Firefly\Storage\TransactionJournal\TransactionJournalRepositoryInterface as TJRI;
|
||||
use Illuminate\Support\Collection;
|
||||
use LaravelBook\Ardent\Builder;
|
||||
|
||||
/**
|
||||
* Class JsonController
|
||||
@ -38,12 +39,72 @@ class JsonController extends BaseController
|
||||
}
|
||||
|
||||
/**
|
||||
* Returns a list of transactions, expenses only, using the given parameters.
|
||||
*
|
||||
*/
|
||||
public function expenses()
|
||||
public function revenue()
|
||||
{
|
||||
$parameters = $this->_datatableParameters();
|
||||
$parameters['transactionTypes'] = ['Deposit'];
|
||||
$parameters['amount'] = 'positive';
|
||||
|
||||
$query = $this->_datatableQuery($parameters);
|
||||
$resultSet = $this->_datatableResultset($parameters, $query);
|
||||
|
||||
|
||||
/*
|
||||
* Build return data:
|
||||
*/
|
||||
|
||||
if (Input::get('debug') == 'true') {
|
||||
echo '<pre>';
|
||||
print_r($parameters);
|
||||
echo '<hr>';
|
||||
print_r($resultSet);
|
||||
return '';
|
||||
|
||||
} else {
|
||||
return Response::json($resultSet);
|
||||
}
|
||||
|
||||
|
||||
}
|
||||
|
||||
/**
|
||||
*
|
||||
*/
|
||||
public function transfers()
|
||||
{
|
||||
$parameters = $this->_datatableParameters();
|
||||
$parameters['transactionTypes'] = ['Transfer'];
|
||||
$parameters['amount'] = 'positive';
|
||||
|
||||
$query = $this->_datatableQuery($parameters);
|
||||
$resultSet = $this->_datatableResultset($parameters, $query);
|
||||
|
||||
|
||||
/*
|
||||
* Build return data:
|
||||
*/
|
||||
|
||||
if (Input::get('debug') == 'true') {
|
||||
echo '<pre>';
|
||||
print_r($parameters);
|
||||
echo '<hr>';
|
||||
print_r($resultSet);
|
||||
return '';
|
||||
|
||||
} else {
|
||||
return Response::json($resultSet);
|
||||
}
|
||||
|
||||
|
||||
}
|
||||
|
||||
/**
|
||||
* @return array
|
||||
*/
|
||||
protected function _datatableParameters()
|
||||
{
|
||||
/*
|
||||
* Process all parameters!
|
||||
*/
|
||||
@ -76,7 +137,7 @@ class JsonController extends BaseController
|
||||
/*
|
||||
* Sorting.
|
||||
*/
|
||||
$orderOnAccount = false;
|
||||
$parameters['orderOnAccount'] = false;
|
||||
if (!is_null(Input::get('order')) && is_array(Input::get('order'))) {
|
||||
foreach (Input::get('order') as $order) {
|
||||
$columnIndex = intval($order['column']);
|
||||
@ -86,7 +147,7 @@ class JsonController extends BaseController
|
||||
'dir' => strtoupper($order['dir'])
|
||||
];
|
||||
if ($columnName == 'to' || $columnName == 'from') {
|
||||
$orderOnAccount = true;
|
||||
$parameters['orderOnAccount'] = true;
|
||||
}
|
||||
}
|
||||
}
|
||||
@ -100,11 +161,33 @@ class JsonController extends BaseController
|
||||
'regex' => $search['regex'] == 'true' ? true : false
|
||||
];
|
||||
}
|
||||
return $parameters;
|
||||
}
|
||||
|
||||
/**
|
||||
* @param array $parameters
|
||||
*
|
||||
* @return Builder
|
||||
*/
|
||||
protected function _datatableQuery(array $parameters)
|
||||
{
|
||||
/*
|
||||
* We need the following vars to fine tune the query:
|
||||
*/
|
||||
if ($parameters['amount'] == 'negative') {
|
||||
$operator = '<';
|
||||
$operatorNegated = '>';
|
||||
$function = 'lessThan';
|
||||
} else {
|
||||
$operator = '>';
|
||||
$operatorNegated = '<';
|
||||
$function = 'moreThan';
|
||||
}
|
||||
|
||||
/*
|
||||
* Build query:
|
||||
*/
|
||||
$query = \TransactionJournal::transactionTypes(['Withdrawal'])->withRelevantData();
|
||||
$query = \TransactionJournal::transactionTypes($parameters['transactionTypes'])->withRelevantData();
|
||||
|
||||
/*
|
||||
* This is complex. Join `transactions` twice, once for the "to" account and once for the
|
||||
@ -114,21 +197,21 @@ class JsonController extends BaseController
|
||||
*
|
||||
* Also need the table prefix for this to work.
|
||||
*/
|
||||
if ($orderOnAccount === true) {
|
||||
if ($parameters['orderOnAccount'] === true) {
|
||||
$connection = \Config::get('database.default');
|
||||
$prefix = \Config::get('database.connections.' . $connection . '.prefix');
|
||||
// left join first table for "from" account:
|
||||
$query->leftJoin(
|
||||
'transactions AS ' . $prefix . 't1', function ($join) {
|
||||
'transactions AS ' . $prefix . 't1', function ($join) use ($operator) {
|
||||
$join->on('t1.transaction_journal_id', '=', 'transaction_journals.id')
|
||||
->on('t1.amount', '<', \DB::Raw(0));
|
||||
->on('t1.amount', $operator, \DB::Raw(0));
|
||||
}
|
||||
);
|
||||
// left join second table for "to" account:
|
||||
$query->leftJoin(
|
||||
'transactions AS ' . $prefix . 't2', function ($join) {
|
||||
'transactions AS ' . $prefix . 't2', function ($join) use ($operatorNegated) {
|
||||
$join->on('t2.transaction_journal_id', '=', 'transaction_journals.id')
|
||||
->on('t2.amount', '>', \DB::Raw(0));
|
||||
->on('t2.amount', $operatorNegated, \DB::Raw(0));
|
||||
}
|
||||
);
|
||||
|
||||
@ -137,21 +220,12 @@ class JsonController extends BaseController
|
||||
$query->leftJoin('accounts as ' . $prefix . 'a2', 'a2.id', '=', 't2.account_id');
|
||||
} else {
|
||||
// less complex
|
||||
$query->lessThan(0);
|
||||
$query->$function(0);
|
||||
}
|
||||
|
||||
|
||||
//'t1.transaction_journal_id','=','transaction_journals.id');
|
||||
|
||||
|
||||
$count = $query->count();
|
||||
$query->take($parameters['length']);
|
||||
$query->skip($parameters['start']);
|
||||
|
||||
/*
|
||||
* Add sort parameters to query:
|
||||
*/
|
||||
\Debugbar::startMeasure('order');
|
||||
if (isset($parameters['order']) && count($parameters['order']) > 0) {
|
||||
foreach ($parameters['order'] as $order) {
|
||||
$query->orderBy($order['name'], $order['dir']);
|
||||
@ -159,6 +233,66 @@ class JsonController extends BaseController
|
||||
} else {
|
||||
$query->defaultSorting();
|
||||
}
|
||||
return $query;
|
||||
}
|
||||
|
||||
/**
|
||||
* Returns a list of transactions, expenses only, using the given parameters.
|
||||
*/
|
||||
public function expenses()
|
||||
{
|
||||
|
||||
/*
|
||||
* Gets most parameters from the Input::all() array:
|
||||
*/
|
||||
$parameters = $this->_datatableParameters();
|
||||
|
||||
/*
|
||||
* Add some more parameters to fine tune the query:
|
||||
*/
|
||||
$parameters['transactionTypes'] = ['Withdrawal'];
|
||||
$parameters['amount'] = 'negative';
|
||||
|
||||
/*
|
||||
* Get the query:
|
||||
*/
|
||||
$query = $this->_datatableQuery($parameters);
|
||||
|
||||
/*
|
||||
* Build result set:
|
||||
*/
|
||||
$resultSet = $this->_datatableResultset($parameters, $query);
|
||||
|
||||
|
||||
/*
|
||||
* Build return data:
|
||||
*/
|
||||
|
||||
if (Input::get('debug') == 'true') {
|
||||
echo '<pre>';
|
||||
print_r($parameters);
|
||||
echo '<hr>';
|
||||
print_r($resultSet);
|
||||
return '';
|
||||
|
||||
} else {
|
||||
return Response::json($resultSet);
|
||||
}
|
||||
}
|
||||
|
||||
protected function _datatableResultset(array $parameters, Builder $query)
|
||||
{
|
||||
/*
|
||||
* Count query:
|
||||
*/
|
||||
$count = $query->count();
|
||||
|
||||
/*
|
||||
* Update the selection:
|
||||
*/
|
||||
|
||||
$query->take($parameters['length']);
|
||||
$query->skip($parameters['start']);
|
||||
|
||||
/*
|
||||
* Build return array:
|
||||
@ -174,7 +308,7 @@ class JsonController extends BaseController
|
||||
/*
|
||||
* Get paginated result set:
|
||||
*/
|
||||
if ($orderOnAccount === true) {
|
||||
if ($parameters['orderOnAccount'] === true) {
|
||||
/** @var Collection $set */
|
||||
$set = $query->get(
|
||||
[
|
||||
@ -218,22 +352,7 @@ class JsonController extends BaseController
|
||||
];
|
||||
|
||||
}
|
||||
|
||||
/*
|
||||
* Build return data:
|
||||
*/
|
||||
$return = $data;
|
||||
|
||||
if (Input::get('debug') == 'true') {
|
||||
echo '<pre>';
|
||||
print_r($parameters);
|
||||
echo '<hr>';
|
||||
print_r($return);
|
||||
return '';
|
||||
|
||||
} else {
|
||||
return Response::json($return);
|
||||
}
|
||||
return $data;
|
||||
}
|
||||
|
||||
/**
|
||||
|
@ -231,55 +231,26 @@ class TransactionController extends BaseController
|
||||
*/
|
||||
public function expenses()
|
||||
{
|
||||
#$transactionType = $this->_repository->getTransactionType('Withdrawal');
|
||||
#$journals = $this->_repository->paginate($transactionType, 25, $this->_start, $this->_end);
|
||||
|
||||
return View::make('transactions.list')->with('subTitle', 'Expenses')->with(
|
||||
'subTitleIcon', 'fa-long-arrow-left'
|
||||
);
|
||||
)->with('what','expenses');
|
||||
}
|
||||
|
||||
/**
|
||||
* @return $this
|
||||
*/
|
||||
public function revenue()
|
||||
{
|
||||
$transactionType = $this->_repository->getTransactionType('Deposit');
|
||||
$start = is_null(Input::get('startdate')) ? null : new Carbon(Input::get('startdate'));
|
||||
$end = is_null(Input::get('enddate')) ? null : new Carbon(Input::get('enddate'));
|
||||
if ($start <= $end && !is_null($start) && !is_null($end)) {
|
||||
$journals = $this->_repository->paginate($transactionType, 25, $start, $end);
|
||||
$filtered = true;
|
||||
$filters = ['start' => $start, 'end' => $end];
|
||||
} else {
|
||||
$journals = $this->_repository->paginate($transactionType, 25);
|
||||
$filtered = false;
|
||||
$filters = null;
|
||||
}
|
||||
|
||||
View::share('subTitleIcon', 'fa-long-arrow-right');
|
||||
return View::make('transactions.index')->with('journals', $journals)->with('filtered', $filtered)->with(
|
||||
'filters', $filters
|
||||
)->with('subTitle', 'Revenue');
|
||||
|
||||
return View::make('transactions.list')->with('subTitle', 'Revenue')->with(
|
||||
'subTitleIcon', 'fa-long-arrow-right'
|
||||
)->with('what','revenue');
|
||||
}
|
||||
|
||||
public function transfers()
|
||||
{
|
||||
$transactionType = $this->_repository->getTransactionType('Transfer');
|
||||
$start = is_null(Input::get('startdate')) ? null : new Carbon(Input::get('startdate'));
|
||||
$end = is_null(Input::get('enddate')) ? null : new Carbon(Input::get('enddate'));
|
||||
if ($start <= $end && !is_null($start) && !is_null($end)) {
|
||||
$journals = $this->_repository->paginate($transactionType, 25, $start, $end);
|
||||
$filtered = true;
|
||||
$filters = ['start' => $start, 'end' => $end];
|
||||
} else {
|
||||
$journals = $this->_repository->paginate($transactionType, 25);
|
||||
$filtered = false;
|
||||
$filters = null;
|
||||
}
|
||||
|
||||
View::share('subTitleIcon', 'fa-arrows-h');
|
||||
return View::make('transactions.index')->with('journals', $journals)->with('filtered', $filtered)->with(
|
||||
'filters', $filters
|
||||
)->with('subTitle', 'Transfers');
|
||||
return View::make('transactions.list')->with('subTitle', 'Transfers')->with(
|
||||
'subTitleIcon', 'fa-arrows-h'
|
||||
)->with('what','transfers');
|
||||
|
||||
}
|
||||
|
||||
|
@ -178,10 +178,12 @@ Route::group(['before' => 'auth'], function () {
|
||||
Route::get('/flush', ['uses' => 'HomeController@flush', 'as' => 'flush']);
|
||||
|
||||
// JSON controller:
|
||||
Route::get('/json/expense-accounts', ['uses' => 'JsonController@expenseAccounts', 'as' => 'json.expense']);
|
||||
Route::get('/json/revenue-accounts', ['uses' => 'JsonController@revenueAccounts', 'as' => 'json.revenue']);
|
||||
Route::get('/json/expense-accounts', ['uses' => 'JsonController@expenseAccounts', 'as' => 'json.expense-accounts']);
|
||||
Route::get('/json/revenue-accounts', ['uses' => 'JsonController@revenueAccounts', 'as' => 'json.revenue-accounts']);
|
||||
Route::get('/json/categories', ['uses' => 'JsonController@categories', 'as' => 'json.categories']);
|
||||
Route::get('/json/expenses', ['uses' => 'JsonController@expenses', 'as' => 'json.expenses']);
|
||||
Route::get('/json/revenue', ['uses' => 'JsonController@revenue', 'as' => 'json.revenue']);
|
||||
Route::get('/json/transfers', ['uses' => 'JsonController@transfers', 'as' => 'json.transfers']);
|
||||
|
||||
// limit controller:
|
||||
Route::get('/budgets/limits/create/{budget?}',['uses' => 'LimitController@create','as' => 'budgets.limits.create']);
|
||||
|
@ -28,7 +28,8 @@
|
||||
@stop
|
||||
@section('scripts')
|
||||
<script type="text/javascript">
|
||||
var URL = '{{route('json.expenses')}}';
|
||||
var URL = '{{route('json.'.$what)}}';
|
||||
var display = '{{{$what}}}';
|
||||
</script>
|
||||
<?php echo javascript_include_tag('transactions'); ?>
|
||||
@stop
|
||||
|
Loading…
Reference in New Issue
Block a user