mirror of
https://github.com/firefly-iii/firefly-iii.git
synced 2025-10-02 02:18:20 +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());
|
||||
}
|
||||
|
||||
/**
|
||||
* @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
|
||||
*/
|
||||
@@ -239,6 +340,7 @@ class GoogleTableController extends BaseController
|
||||
$chart->addColumn('Category_URL', 'string');
|
||||
$chart->addColumn('Category', 'string');
|
||||
|
||||
|
||||
/*
|
||||
* Find transactions:
|
||||
*/
|
||||
|
Reference in New Issue
Block a user