mirror of
https://github.com/firefly-iii/firefly-iii.git
synced 2025-10-22 03:53:37 +00:00
More work done for the transaction controller.
This commit is contained in:
@@ -216,6 +216,107 @@ class GoogleTableController extends BaseController
|
|||||||
return Response::json($chart->getData());
|
return Response::json($chart->getData());
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @param $what
|
||||||
|
*
|
||||||
|
* @return \Illuminate\Http\JsonResponse
|
||||||
|
*/
|
||||||
|
public function transactionsList($what)
|
||||||
|
{
|
||||||
|
/** @var \Grumpydictator\Gchart\GChart $chart */
|
||||||
|
$chart = App::make('gchart');
|
||||||
|
$chart->addColumn('ID', 'number');
|
||||||
|
$chart->addColumn('ID_Edit', 'string');
|
||||||
|
$chart->addColumn('ID_Delete', 'string');
|
||||||
|
$chart->addColumn('Date', 'date');
|
||||||
|
$chart->addColumn('Description_URL', 'string');
|
||||||
|
$chart->addColumn('Description', 'string');
|
||||||
|
$chart->addColumn('Amount', 'number');
|
||||||
|
$chart->addColumn('From_URL', 'string');
|
||||||
|
$chart->addColumn('From', 'string');
|
||||||
|
$chart->addColumn('To_URL', 'string');
|
||||||
|
$chart->addColumn('To', 'string');
|
||||||
|
$chart->addColumn('Budget_URL', 'string');
|
||||||
|
$chart->addColumn('Budget', 'string');
|
||||||
|
$chart->addColumn('Category_URL', 'string');
|
||||||
|
$chart->addColumn('Category', 'string');
|
||||||
|
|
||||||
|
/** @var \FireflyIII\Database\TransactionJournal $repository */
|
||||||
|
$repository = App::make('FireflyIII\Database\TransactionJournal');
|
||||||
|
|
||||||
|
switch ($what) {
|
||||||
|
case 'expenses':
|
||||||
|
case 'withdrawal':
|
||||||
|
$list = $repository->getWithdrawals();
|
||||||
|
break;
|
||||||
|
case 'revenue':
|
||||||
|
case 'deposit':
|
||||||
|
$list = $repository->getDeposits();
|
||||||
|
break;
|
||||||
|
case 'transfer':
|
||||||
|
case 'transfers':
|
||||||
|
$list = $repository->getTransfers();
|
||||||
|
break;
|
||||||
|
}
|
||||||
|
|
||||||
|
/** @var Transaction $transaction */
|
||||||
|
foreach ($list as $transaction) {
|
||||||
|
$date = $transaction->transactionJournal->date;
|
||||||
|
$descriptionURL = route('transactions.show', $transaction->transaction_journal_id);
|
||||||
|
$description = $transaction->transactionJournal->description;
|
||||||
|
$amount = floatval($transaction->amount);
|
||||||
|
|
||||||
|
if ($transaction->transactionJournal->transactions[0]->account->id == $account->id) {
|
||||||
|
$opposingAccountURI = route('accounts.show', $transaction->transactionJournal->transactions[1]->account->id);
|
||||||
|
$opposingAccountName = $transaction->transactionJournal->transactions[1]->account->name;
|
||||||
|
} else {
|
||||||
|
$opposingAccountURI = route('accounts.show', $transaction->transactionJournal->transactions[0]->account->id);
|
||||||
|
$opposingAccountName = $transaction->transactionJournal->transactions[0]->account->name;
|
||||||
|
}
|
||||||
|
if (isset($transaction->transactionJournal->budgets[0])) {
|
||||||
|
$budgetURL = route('budgets.show', $transaction->transactionJournal->budgets[0]->id);
|
||||||
|
$budget = $transaction->transactionJournal->budgets[0]->name;
|
||||||
|
} else {
|
||||||
|
$budgetURL = '';
|
||||||
|
$budget = '';
|
||||||
|
}
|
||||||
|
|
||||||
|
if (isset($transaction->transactionJournal->categories[0])) {
|
||||||
|
$categoryURL = route('categories.show', $transaction->transactionJournal->categories[0]->id);
|
||||||
|
$category = $transaction->transactionJournal->categories[0]->name;
|
||||||
|
} else {
|
||||||
|
$categoryURL = '';
|
||||||
|
$category = '';
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
if ($amount < 0) {
|
||||||
|
$from = $account->name;
|
||||||
|
$fromURL = route('accounts.show', $account->id);
|
||||||
|
|
||||||
|
$to = $opposingAccountName;
|
||||||
|
$toURL = $opposingAccountURI;
|
||||||
|
} else {
|
||||||
|
$to = $account->name;
|
||||||
|
$toURL = route('accounts.show', $account->id);
|
||||||
|
|
||||||
|
$from = $opposingAccountName;
|
||||||
|
$fromURL = $opposingAccountURI;
|
||||||
|
}
|
||||||
|
|
||||||
|
$id = $transaction->transactionJournal->id;
|
||||||
|
$edit = route('transactions.edit', $transaction->transactionJournal->id);
|
||||||
|
$delete = route('transactions.delete', $transaction->transactionJournal->id);
|
||||||
|
$chart->addRow(
|
||||||
|
$id, $edit, $delete, $date, $descriptionURL, $description, $amount, $fromURL, $from, $toURL, $to, $budgetURL, $budget, $categoryURL, $category
|
||||||
|
);
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
$chart->generate();
|
||||||
|
return Response::json($chart->getData());
|
||||||
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* @param Account $account
|
* @param Account $account
|
||||||
*/
|
*/
|
||||||
@@ -239,6 +340,7 @@ class GoogleTableController extends BaseController
|
|||||||
$chart->addColumn('Category_URL', 'string');
|
$chart->addColumn('Category_URL', 'string');
|
||||||
$chart->addColumn('Category', 'string');
|
$chart->addColumn('Category', 'string');
|
||||||
|
|
||||||
|
|
||||||
/*
|
/*
|
||||||
* Find transactions:
|
* Find transactions:
|
||||||
*/
|
*/
|
||||||
|
@@ -12,6 +12,7 @@ use Illuminate\Support\MessageBag;
|
|||||||
class TransactionController extends BaseController
|
class TransactionController extends BaseController
|
||||||
{
|
{
|
||||||
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Construct a new transaction controller with two of the most often used helpers.
|
* Construct a new transaction controller with two of the most often used helpers.
|
||||||
*
|
*
|
||||||
@@ -22,6 +23,36 @@ class TransactionController extends BaseController
|
|||||||
View::share('mainTitleIcon', 'fa-repeat');
|
View::share('mainTitleIcon', 'fa-repeat');
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @param $what
|
||||||
|
*
|
||||||
|
* @return $this
|
||||||
|
*/
|
||||||
|
public function index($what)
|
||||||
|
{
|
||||||
|
|
||||||
|
switch ($what) {
|
||||||
|
case 'expenses':
|
||||||
|
case 'withdrawal':
|
||||||
|
$subTitleIcon = 'fa-long-arrow-left';
|
||||||
|
$subTitle = 'Expenses';
|
||||||
|
break;
|
||||||
|
case 'revenue':
|
||||||
|
case 'deposit':
|
||||||
|
$subTitleIcon = 'fa-long-arrow-right';
|
||||||
|
$subTitle = 'Revenue, income and deposits';
|
||||||
|
break;
|
||||||
|
case 'transfer':
|
||||||
|
case 'transfers':
|
||||||
|
$subTitleIcon = 'fa-arrows-h';
|
||||||
|
$subTitle = 'Transfers';
|
||||||
|
break;
|
||||||
|
}
|
||||||
|
|
||||||
|
return View::make('transactions.index', compact('subTitle', 'subTitleIcon'))->with('what', $what);
|
||||||
|
|
||||||
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Shows the view helping the user to create a new transaction journal.
|
* Shows the view helping the user to create a new transaction journal.
|
||||||
*
|
*
|
||||||
@@ -222,33 +253,14 @@ class TransactionController extends BaseController
|
|||||||
);
|
);
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
|
||||||
* @return $this
|
|
||||||
*/
|
|
||||||
public function expenses()
|
|
||||||
{
|
|
||||||
return View::make('transactions.list')->with('subTitle', 'Expenses')->with(
|
|
||||||
'subTitleIcon', 'fa-long-arrow-left'
|
|
||||||
)->with('what', 'expenses');
|
|
||||||
}
|
|
||||||
|
|
||||||
/**
|
|
||||||
* @return $this
|
|
||||||
*/
|
|
||||||
public function revenue()
|
|
||||||
{
|
|
||||||
return View::make('transactions.list')->with('subTitle', 'Revenue')->with(
|
|
||||||
'subTitleIcon', 'fa-long-arrow-right'
|
|
||||||
)->with('what', 'revenue');
|
|
||||||
}
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* @param TransactionJournal $journal
|
* @param TransactionJournal $journal
|
||||||
*
|
*
|
||||||
* @return $this
|
* @return $this
|
||||||
*/
|
*/
|
||||||
public function show(TransactionJournal $journal)
|
public function show(
|
||||||
{
|
TransactionJournal $journal
|
||||||
|
) {
|
||||||
return View::make('transactions.show')->with('journal', $journal)->with(
|
return View::make('transactions.show')->with('journal', $journal)->with(
|
||||||
'subTitle', $journal->transactionType->type . ' "' . $journal->description . '"'
|
'subTitle', $journal->transactionType->type . ' "' . $journal->description . '"'
|
||||||
);
|
);
|
||||||
@@ -260,8 +272,7 @@ class TransactionController extends BaseController
|
|||||||
* @return $this|\Illuminate\Http\RedirectResponse
|
* @return $this|\Illuminate\Http\RedirectResponse
|
||||||
* @throws FireflyException
|
* @throws FireflyException
|
||||||
*/
|
*/
|
||||||
public function store($what)
|
public function store($what) {
|
||||||
{
|
|
||||||
throw new NotImplementedException;
|
throw new NotImplementedException;
|
||||||
/*
|
/*
|
||||||
* Collect data to process:
|
* Collect data to process:
|
||||||
@@ -314,19 +325,13 @@ class TransactionController extends BaseController
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
public function index($what)
|
|
||||||
{
|
|
||||||
return View::make('transactions.index')->with('subTitle', 'Bla bla')->with('subTitleIcon', 'fa-arrows-h')->with('what', $what);
|
|
||||||
|
|
||||||
}
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* @param TransactionJournal $journal
|
* @param TransactionJournal $journal
|
||||||
*
|
*
|
||||||
* @throws FireflyException
|
* @throws FireflyException
|
||||||
*/
|
*/
|
||||||
public function update(TransactionJournal $journal)
|
public function update(TransactionJournal $journal) {
|
||||||
{
|
|
||||||
throw new NotImplementedException;
|
throw new NotImplementedException;
|
||||||
switch (Input::get('post_submit_action')) {
|
switch (Input::get('post_submit_action')) {
|
||||||
case 'update':
|
case 'update':
|
||||||
|
@@ -327,6 +327,38 @@ class TransactionJournal implements TransactionJournalInterface, CUD, CommonData
|
|||||||
return $this->getUser()->transactionjournals()->get();
|
return $this->getUser()->transactionjournals()->get();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Some objects.
|
||||||
|
*
|
||||||
|
* @return Collection
|
||||||
|
*/
|
||||||
|
public function getTransfers()
|
||||||
|
{
|
||||||
|
return $this->getUser()->transactionjournals()->withRelevantData()->transactionTypes(['Transfer'])->get(['transaction_journals.*']);
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Some objects.
|
||||||
|
*
|
||||||
|
* @return Collection
|
||||||
|
*/
|
||||||
|
public function getDeposits()
|
||||||
|
{
|
||||||
|
return $this->getUser()->transactionjournals()->withRelevantData()->transactionTypes(['Deposit'])->get(['transaction_journals.*']);
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Some objects.
|
||||||
|
*
|
||||||
|
* @return Collection
|
||||||
|
*/
|
||||||
|
public function getWithdrawals()
|
||||||
|
{
|
||||||
|
return $this->getUser()->transactionjournals()->withRelevantData()->transactionTypes(['Withdrawal'])->get(['transaction_journals.*']);
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Finds an account type using one of the "$what"'s: expense, asset, revenue, opening, etc.
|
* Finds an account type using one of the "$what"'s: expense, asset, revenue, opening, etc.
|
||||||
*
|
*
|
||||||
|
@@ -164,6 +164,7 @@ Route::group(
|
|||||||
Route::get('/table/accounts/{what}', ['uses' => 'GoogleTableController@accountList']);
|
Route::get('/table/accounts/{what}', ['uses' => 'GoogleTableController@accountList']);
|
||||||
Route::get('/table/categories', ['uses' => 'GoogleTableController@categoryList']);
|
Route::get('/table/categories', ['uses' => 'GoogleTableController@categoryList']);
|
||||||
Route::get('/table/recurring', ['uses' => 'GoogleTableController@recurringList']);
|
Route::get('/table/recurring', ['uses' => 'GoogleTableController@recurringList']);
|
||||||
|
Route::get('/table/transactions/{what}', ['uses' => 'GoogleTableController@transactionsList'])->where(['what' => 'expenses|revenue|withdrawal|deposit|transfer|transfers']);
|
||||||
|
|
||||||
// google table for components (categories + budgets)
|
// google table for components (categories + budgets)
|
||||||
Route::get('/table/component/{component}/{limitrepetition}/transactions', ['uses' => 'GoogleTableController@transactionsByComponent']);
|
Route::get('/table/component/{component}/{limitrepetition}/transactions', ['uses' => 'GoogleTableController@transactionsByComponent']);
|
||||||
|
@@ -7,7 +7,7 @@
|
|||||||
<i class="fa {{$subTitleIcon}}"></i> {{{$subTitle}}}
|
<i class="fa {{$subTitleIcon}}"></i> {{{$subTitle}}}
|
||||||
</div>
|
</div>
|
||||||
<div class="panel-body">
|
<div class="panel-body">
|
||||||
<div id="transactionList"></div>
|
<div id="transaction-table"></div>
|
||||||
<!--<table id="transactionTable" class="table table-striped table-bordered" >
|
<!--<table id="transactionTable" class="table table-striped table-bordered" >
|
||||||
<thead>
|
<thead>
|
||||||
<tr>
|
<tr>
|
||||||
@@ -30,7 +30,13 @@
|
|||||||
@stop
|
@stop
|
||||||
@section('scripts')
|
@section('scripts')
|
||||||
<script type="text/javascript">
|
<script type="text/javascript">
|
||||||
var display = '{{{$what}}}';
|
var what = '{{{$what}}}';
|
||||||
</script>
|
</script>
|
||||||
|
<!-- load the libraries and scripts necessary for Google Charts: -->
|
||||||
|
<script type="text/javascript" src="https://www.google.com/jsapi"></script>
|
||||||
|
{{HTML::script('assets/javascript/firefly/gcharts.options.js')}}
|
||||||
|
{{HTML::script('assets/javascript/firefly/gcharts.js')}}
|
||||||
|
|
||||||
|
|
||||||
{{HTML::script('assets/javascript/firefly/transactions.js')}}
|
{{HTML::script('assets/javascript/firefly/transactions.js')}}
|
||||||
@stop
|
@stop
|
@@ -15,5 +15,7 @@ if ($('input[name="category"]').length > 0) {
|
|||||||
}
|
}
|
||||||
|
|
||||||
$(document).ready(function () {
|
$(document).ready(function () {
|
||||||
|
if(typeof googleTable != 'undefined') {
|
||||||
|
googleTable('table/transactions/' + what,'transaction-table');
|
||||||
|
}
|
||||||
});
|
});
|
Reference in New Issue
Block a user