diff --git a/app/Filters/Banking/Transactions.php b/app/Filters/Banking/Transactions.php index 27ed093e4..f80f15dcc 100644 --- a/app/Filters/Banking/Transactions.php +++ b/app/Filters/Banking/Transactions.php @@ -13,9 +13,14 @@ class Transactions extends ModelFilter * @var array */ public $relations = []; - - public function search($query) + + public function account($account_id) { - return $this->whereLike('payment.name', $query)->whereLike('revenue.name', $query); + return $this->where('account_id', $account_id); + } + + public function category($category_id) + { + return $this->where('category_id', $category_id); } } \ No newline at end of file diff --git a/app/Http/Controllers/Banking/Transactions.php b/app/Http/Controllers/Banking/Transactions.php index cf332f8be..7ef03890e 100644 --- a/app/Http/Controllers/Banking/Transactions.php +++ b/app/Http/Controllers/Banking/Transactions.php @@ -3,9 +3,11 @@ namespace App\Http\Controllers\Banking; use App\Http\Controllers\Controller; +use App\Models\Banking\Account; use App\Models\Banking\Transaction; use App\Models\Expense\Payment; use App\Models\Income\Revenue; +use App\Models\Setting\Category; class Transactions extends Controller { @@ -17,37 +19,51 @@ class Transactions extends Controller */ public function index() { - //$transactions = Transaction::index(); $request = request(); - - $payments = Payment::collect('paid_at'); - + $transactions = array(); + + $accounts = collect(Account::enabled()->pluck('name', 'id')) + ->prepend(trans('general.all_type', ['type' => trans_choice('general.accounts', 2)]), ''); - foreach ($payments as $payment) { - $transactions[] = (object)[ - 'paid_at' => $payment->paid_at, - 'account_name' => $payment->account->name, - 'type' => trans_choice('general.expenses', 1), - 'category_name' => $payment->category->name, - 'description' => $payment->description, - 'amount' => $payment->amount, - 'currency_code' => $payment->currency_code, - ]; + $types = collect(['expense' => 'Expense', 'income' => 'Income']) + ->prepend(trans('general.all_type', ['type' => trans_choice('general.types', 2)]), ''); + + $categories = collect(Category::enabled()->type('income')->pluck('name', 'id')) + ->prepend(trans('general.all_type', ['type' => trans_choice('general.categories', 2)]), ''); + + $type = $request->get('type'); + + if ($type != 'income') { + $payments = Payment::collect('paid_at'); + + foreach ($payments as $payment) { + $transactions[] = (object)[ + 'paid_at' => $payment->paid_at, + 'account_name' => $payment->account->name, + 'type' => trans_choice('general.expenses', 1), + 'category_name' => $payment->category->name, + 'description' => $payment->description, + 'amount' => $payment->amount, + 'currency_code' => $payment->currency_code, + ]; + } } - $revenues = Revenue::collect('paid_at'); + if ($type != 'expense') { + $revenues = Revenue::collect('paid_at'); - foreach ($revenues as $revenue) { - $transactions[] = (object)[ - 'paid_at' => $revenue->paid_at, - 'account_name' => $revenue->account->name, - 'type' => trans_choice('general.incomes', 1), - 'category_name' => $revenue->category->name, - 'description' => $revenue->description, - 'amount' => $revenue->amount, - 'currency_code' => $revenue->currency_code, - ]; + foreach ($revenues as $revenue) { + $transactions[] = (object)[ + 'paid_at' => $revenue->paid_at, + 'account_name' => $revenue->account->name, + 'type' => trans_choice('general.incomes', 1), + 'category_name' => $revenue->category->name, + 'description' => $revenue->description, + 'amount' => $revenue->amount, + 'currency_code' => $revenue->currency_code, + ]; + } } $special_key = array( @@ -75,6 +91,6 @@ class Transactions extends Controller $transactions = (object) $transactions; - return view('banking.transactions.index', compact('transactions')); + return view('banking.transactions.index', compact('transactions', 'accounts', 'types', 'categories')); } } diff --git a/resources/views/banking/transactions/index.blade.php b/resources/views/banking/transactions/index.blade.php index 6a8935f62..7ef33e24a 100644 --- a/resources/views/banking/transactions/index.blade.php +++ b/resources/views/banking/transactions/index.blade.php @@ -9,7 +9,9 @@ {!! Form::open(['url' => 'banking/transactions', 'role' => 'form', 'method' => 'GET']) !!}