More fields for query.

This commit is contained in:
James Cole 2016-12-28 06:09:48 +01:00
parent ebdd64f46f
commit 94e51952f4
No known key found for this signature in database
GPG Key ID: C16961E655E74B5E
3 changed files with 70 additions and 6 deletions

View File

@ -649,9 +649,17 @@ class JournalCollector implements JournalCollectorInterface
// join some extra tables:
$this->joinedBudget = true;
$this->query->leftJoin('budget_transaction_journal', 'budget_transaction_journal.transaction_journal_id', '=', 'transaction_journals.id');
$this->query->leftJoin('budgets as transaction_journal_budgets', 'transaction_journal_budgets.id', '=', 'budget_transaction_journal.budget_id');
$this->query->leftJoin('budget_transaction', 'budget_transaction.transaction_id', '=', 'transactions.id');
$this->query->leftJoin('budgets as transaction_budgets', 'transaction_budgets.id', '=', 'budget_transaction.budget_id');
$this->fields[] = 'budget_transaction_journal.budget_id as transaction_journal_budget_id';
$this->fields[] = 'transaction_journal_budgets.encrypted as transaction_journal_budget_encrypted';
$this->fields[] = 'transaction_journal_budgets.name as transaction_journal_budget_name';
$this->fields[] = 'budget_transaction.budget_id as transaction_budget_id';
$this->fields[] = 'transaction_budgets.encrypted as transaction_budget_encrypted';
$this->fields[] = 'transaction_budgets.name as transaction_budget_name';
}
}
@ -664,12 +672,24 @@ class JournalCollector implements JournalCollectorInterface
// join some extra tables:
$this->joinedCategory = true;
$this->query->leftJoin('category_transaction_journal', 'category_transaction_journal.transaction_journal_id', '=', 'transaction_journals.id');
$this->query->leftJoin('categories as transaction_journal_categories', 'transaction_journal_categories.id', '=', 'category_transaction_journal.category_id');
$this->query->leftJoin('category_transaction', 'category_transaction.transaction_id', '=', 'transactions.id');
$this->query->leftJoin('categories as transaction_categories', 'transaction_categories.id', '=', 'category_transaction.category_id');
$this->fields[] = 'category_transaction_journal.category_id as transaction_journal_category_id';
$this->fields[] = 'transaction_journal_categories.encrypted as transaction_journal_category_encrypted';
$this->fields[] = 'transaction_journal_categories.name as transaction_journal_category_name';
$this->fields[] = 'category_transaction.category_id as transaction_category_id';
$this->fields[] = 'transaction_categories.encrypted as transaction_category_encrypted';
$this->fields[] = 'transaction_categories.name as transaction_category_name';
}
}
/**
*
*/
private function joinOpposingTables()
{
if (!$this->joinedOpposing) {

View File

@ -71,10 +71,10 @@ class TransactionController extends Controller
$start = session('start', Navigation::startOfPeriod(new Carbon, $range));
$end = session('end', Navigation::endOfPeriod(new Carbon, $range));
/** @var JournalCollectorInterface $collector */
$collector = app(JournalCollectorInterface::class, [auth()->user()]);
$collector->setTypes($types)->setLimit($pageSize)->setPage($page)->setAllAssetAccounts();
$collector->setRange($start, $end);
$collector->setRange($start, $end)->withBudgetInformation()->withCategoryInformation();
// do not filter transfers if $what = transfer.
if (!in_array($what, ['transfer', 'transfers'])) {
@ -123,7 +123,7 @@ class TransactionController extends Controller
$page = intval($request->get('page')) === 0 ? 1 : intval($request->get('page'));
$collector = app(JournalCollectorInterface::class, [auth()->user()]);
$collector->setTypes($types)->setLimit($pageSize)->setPage($page)->setAllAssetAccounts();
$collector->setTypes($types)->setLimit($pageSize)->setPage($page)->setAllAssetAccounts()->withBudgetInformation()->withCategoryInformation();
// do not filter transfers if $what = transfer.
if (!in_array($what, ['transfer', 'transfers'])) {
@ -160,9 +160,10 @@ class TransactionController extends Controller
Log::debug(sprintf('Transaction index by date will show between %s and %s', $start->format('Y-m-d'), $end->format('Y-m-d')));
/** @var JournalCollectorInterface $collector */
$collector = app(JournalCollectorInterface::class, [auth()->user()]);
$collector->setTypes($types)->setLimit($pageSize)->setPage($page)->setAllAssetAccounts();
$collector->setRange($start, $end);
$collector->setRange($start, $end)->withBudgetInformation()->withCategoryInformation();
// do not filter transfers if $what = transfer.
if (!in_array($what, ['transfer', 'transfers'])) {

View File

@ -327,6 +327,21 @@ class Transaction extends Twig_Extension
);
}
/**
* @param int $isEncrypted
* @param string $value
*
* @return string
*/
private function encrypted(int $isEncrypted, string $value): string
{
if ($isEncrypted === 1) {
return Crypt::decrypt($value);
}
return $value;
}
/**
* @param TransactionModel $transaction
*
@ -334,6 +349,20 @@ class Transaction extends Twig_Extension
*/
private function getTransactionBudgets(TransactionModel $transaction): string
{
// journal has a budget:
if (isset($transaction->transaction_journal_budget_id)) {
$name = $this->encrypted(intval($transaction->transaction_journal_budget_encrypted), $transaction->transaction_journal_budget_name);
return sprintf('<a href="%s" title="%s">%s</a> (a)', route('budgets.show', [$transaction->transaction_journal_budget_id]), $name, $name);
}
// transaction has a budget
if (isset($transaction->transaction_budget_id)) {
$name = $this->encrypted(intval($transaction->transaction_budget_encrypted), $transaction->transaction_budget_name);
return sprintf('<a href="%s" title="%s">%s</a> (b)', route('budgets.show', [$transaction->transaction_budget_id]), $name, $name);
}
// see if the transaction has a budget:
$budgets = $transaction->budgets()->get();
if ($budgets->count() === 0) {
@ -342,7 +371,7 @@ class Transaction extends Twig_Extension
if ($budgets->count() > 0) {
$str = [];
foreach ($budgets as $budget) {
$str[] = sprintf('<a href="%s" title="%s">%s</a>', route('budgets.show', [$budget->id]), $budget->name, $budget->name);
$str[] = sprintf('<a href="%s" title="%s">%s</a> (c)', route('budgets.show', [$budget->id]), $budget->name, $budget->name);
}
return join(', ', $str);
@ -359,6 +388,20 @@ class Transaction extends Twig_Extension
*/
private function getTransactionCategories(TransactionModel $transaction): string
{
// journal has a category:
if (isset($transaction->transaction_journal_category_id)) {
$name = $this->encrypted(intval($transaction->transaction_journal_category_encrypted), $transaction->transaction_journal_category_name);
return sprintf('<a href="%s" title="%s">%s</a> (a)', route('categories.show', [$transaction->transaction_journal_category_id]), $name, $name);
}
// transaction has a category:
if (isset($transaction->transaction_category_id)) {
$name = $this->encrypted(intval($transaction->transaction_category_encrypted), $transaction->transaction_category_name);
return sprintf('<a href="%s" title="%s">%s</a> (b)', route('categories.show', [$transaction->transaction_category_id]), $name, $name);
}
// see if the transaction has a category:
$categories = $transaction->categories()->get();
if ($categories->count() === 0) {
@ -367,7 +410,7 @@ class Transaction extends Twig_Extension
if ($categories->count() > 0) {
$str = [];
foreach ($categories as $category) {
$str[] = sprintf('<a href="%s" title="%s">%s</a>', route('categories.show', [$category->id]), $category->name, $category->name);
$str[] = sprintf('<a href="%s" title="%s">%s</a> (c)', route('categories.show', [$category->id]), $category->name, $category->name);
}
return join(', ', $str);