Skip to content

Commit

Permalink
Merge 949dea4 into dafedec
Browse files Browse the repository at this point in the history
  • Loading branch information
nafiesl committed Jan 25, 2020
2 parents dafedec + 949dea4 commit 5cca1f0
Show file tree
Hide file tree
Showing 6 changed files with 31 additions and 11 deletions.
2 changes: 1 addition & 1 deletion app/Http/Controllers/CategoriesController.php
Original file line number Diff line number Diff line change
Expand Up @@ -54,7 +54,7 @@ public function show(Category $category)
$categories = [];
$editableTransaction = null;
$year = request('year', date('Y'));
$partners = $this->getPartnerList();
$partners = $this->getPartnerList()->prepend('-- '.__('transaction.no_partner').' --', 'null');

$defaultStartDate = auth()->user()->account_start_date ?: date('Y-m').'-01';
$startDate = request('start_date', $defaultStartDate);
Expand Down
30 changes: 23 additions & 7 deletions app/Http/Controllers/Controller.php
Original file line number Diff line number Diff line change
Expand Up @@ -2,13 +2,13 @@

namespace App\Http\Controllers;

use App\Category;
use App\Partner;
use App\Category;
use App\Transaction;
use Illuminate\Foundation\Auth\Access\AuthorizesRequests;
use Illuminate\Foundation\Bus\DispatchesJobs;
use Illuminate\Foundation\Validation\ValidatesRequests;
use Illuminate\Routing\Controller as BaseController;
use Illuminate\Foundation\Validation\ValidatesRequests;
use Illuminate\Foundation\Auth\Access\AuthorizesRequests;

class Controller extends BaseController
{
Expand Down Expand Up @@ -44,11 +44,19 @@ protected function getTansactions($yearMonth)
$transactionQuery->where('description', 'like', '%'.request('query').'%');

$transactionQuery->when($categoryId, function ($queryBuilder, $categoryId) {
$queryBuilder->where('category_id', $categoryId);
if ($categoryId == 'null') {
$queryBuilder->whereNull('category_id');
} else {
$queryBuilder->where('category_id', $categoryId);
}
});

$transactionQuery->when($partnerId, function ($queryBuilder, $partnerId) {
$queryBuilder->where('partner_id', $partnerId);
if ($partnerId == 'null') {
$queryBuilder->whereNull('partner_id');
} else {
$queryBuilder->where('partner_id', $partnerId);
}
});

return $transactionQuery->orderBy('date', 'desc')->with('category', 'partner')->get();
Expand Down Expand Up @@ -120,7 +128,11 @@ protected function getCategoryTransactions(Category $category, array $criteria)
$queryBuilder->where('description', 'like', '%'.$query.'%');
});
$transactionQuery->when($partnerId, function ($queryBuilder, $partnerId) {
$queryBuilder->where('partner_id', $partnerId);
if ($partnerId == 'null') {
$queryBuilder->whereNull('partner_id');
} else {
$queryBuilder->where('partner_id', $partnerId);
}
});

return $transactionQuery->orderBy('date', 'desc')->with('partner')->get();
Expand Down Expand Up @@ -149,7 +161,11 @@ protected function getPartnerTransactions(Partner $partner, array $criteria)
$transactionQuery->whereBetween('date', [$startDate, $endDate]);

$transactionQuery->when($categoryId, function ($queryBuilder, $categoryId) {
$queryBuilder->where('category_id', $categoryId);
if ($categoryId == 'null') {
$queryBuilder->whereNull('category_id');
} else {
$queryBuilder->where('category_id', $categoryId);
}
});

return $transactionQuery->orderBy('date', 'desc')->with('category')->get();
Expand Down
2 changes: 1 addition & 1 deletion app/Http/Controllers/PartnerController.php
Original file line number Diff line number Diff line change
Expand Up @@ -58,7 +58,7 @@ public function show(Partner $partner)
$partners = [];
$editableTransaction = null;
$year = request('year', date('Y'));
$categories = $this->getCategoryList();
$categories = $this->getCategoryList()->prepend('-- '.__('transaction.no_category').' --', 'null');

$defaultStartDate = auth()->user()->account_start_date ?: date('Y-m').'-01';
$startDate = request('start_date', $defaultStartDate);
Expand Down
4 changes: 2 additions & 2 deletions app/Http/Controllers/TransactionsController.php
Original file line number Diff line number Diff line change
Expand Up @@ -26,8 +26,8 @@ public function index()

$transactions = $this->getTansactions($yearMonth);

$categories = $this->getCategoryList();
$partners = $this->getPartnerList();
$categories = $this->getCategoryList()->prepend('-- '.__('transaction.no_category').' --', 'null');
$partners = $this->getPartnerList()->prepend('-- '.__('transaction.no_partner').' --', 'null');

if (in_array(request('action'), ['edit', 'delete']) && request('id') != null) {
$editableTransaction = Transaction::find(request('id'));
Expand Down
2 changes: 2 additions & 0 deletions resources/lang/en/transaction.php
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,8 @@
'end_balance' => 'End Balance',
'current_balance' => 'Current Balance',
'balance' => 'Balance',
'no_category' => 'No Category',
'no_partner' => 'No Partner',

// Actions
'add_income' => 'Add Income',
Expand Down
2 changes: 2 additions & 0 deletions resources/lang/id/transaction.php
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,8 @@
'end_balance' => 'Saldo Akhir',
'current_balance' => 'Saldo Saat Ini',
'balance' => 'Saldo',
'no_category' => 'Tanpa Kategori',
'no_partner' => 'Tanpa Partner',

// Actions
'add_income' => 'Input Pemasukan',
Expand Down

0 comments on commit 5cca1f0

Please sign in to comment.