From 032b372c54bc8029737b9787e4cdee5b79e1b4e8 Mon Sep 17 00:00:00 2001 From: Nafies Luthfi Date: Tue, 30 Apr 2024 23:31:01 +0800 Subject: [PATCH] feat: Change transaction entry from from modal into single page --- .../Controllers/TransactionsController.php | 12 +++ resources/views/transactions/create.blade.php | 89 +++++++++++++++++++ resources/views/transactions/forms.blade.php | 65 -------------- resources/views/transactions/index.blade.php | 4 +- .../Transactions/TransactionEntryTest.php | 4 +- 5 files changed, 105 insertions(+), 69 deletions(-) create mode 100644 resources/views/transactions/create.blade.php diff --git a/app/Http/Controllers/TransactionsController.php b/app/Http/Controllers/TransactionsController.php index da3a49b..eeec03f 100644 --- a/app/Http/Controllers/TransactionsController.php +++ b/app/Http/Controllers/TransactionsController.php @@ -2,10 +2,12 @@ namespace App\Http\Controllers; +use App\Category; use App\Http\Requests\Transactions\CreateRequest; use App\Http\Requests\Transactions\UpdateRequest; use App\Transaction; use Carbon\Carbon; +use Illuminate\Http\Request; class TransactionsController extends Controller { @@ -46,6 +48,16 @@ public function index() )); } + public function create(Request $request) + { + $partners = $this->getPartnerList()->prepend('-- '.__('transaction.no_partner').' --', 'null'); + $categories = Category::orderBy('name') + ->where('status_id', Category::STATUS_ACTIVE) + ->pluck('name', 'id'); + + return view('transactions.create', compact('categories', 'partners')); + } + /** * Store a newly created transaction in storage. * diff --git a/resources/views/transactions/create.blade.php b/resources/views/transactions/create.blade.php new file mode 100644 index 0000000..91ad427 --- /dev/null +++ b/resources/views/transactions/create.blade.php @@ -0,0 +1,89 @@ +@extends('layouts.app') + +@section('title', __('transaction.list')) + +@section('content') +
+
+ @can('create', new App\Transaction) + @if (request('action') == 'add-income') +
+
+
{{ __('transaction.add_income') }}
+ +
+ {!! Form::open(['route' => 'transactions.store', 'autocomplete' => 'off']) !!} + {{ Form::hidden('in_out', 1) }} +
+
+
{!! FormField::text('date', ['required' => true, 'label' => __('app.date'), 'value' => old('date', date('Y-m-d')), 'class' => 'date-select']) !!}
+
{!! FormField::select('category_id', $categories, ['label' => __('category.category'), 'placeholder' => __('category.uncategorized')]) !!}
+
+ {!! FormField::textarea('description', ['required' => true, 'label' => __('transaction.description')]) !!} +
+
{!! FormField::price('amount', ['required' => true, 'label' => __('transaction.amount'), 'type' => 'number', 'currency' => config('money.currency_code'), 'step' => '0.01']) !!}
+
{!! FormField::select('partner_id', $partners, ['label' => __('partner.partner'), 'placeholder' => __('partner.no_partner')]) !!}
+
+
+ + {{ Form::close() }} +
+ @endif + @if (request('action') == 'add-spending') +
+
+
{{ __('transaction.add_spending') }}
+ +
+ {!! Form::open(['route' => 'transactions.store', 'autocomplete' => 'off']) !!} + {{ Form::hidden('in_out', 0) }} +
+
+
{!! FormField::text('date', ['required' => true, 'label' => __('app.date'), 'value' => old('date', date('Y-m-d')), 'class' => 'date-select']) !!}
+
{!! FormField::select('category_id', $categories, ['label' => __('category.category'), 'placeholder' => __('category.uncategorized')]) !!}
+
+ {!! FormField::textarea('description', ['required' => true, 'label' => __('transaction.description')]) !!} +
+
{!! FormField::price('amount', ['required' => true, 'label' => __('transaction.amount'), 'type' => 'number', 'currency' => config('money.currency_code'), 'step' => '0.01']) !!}
+
{!! FormField::select('partner_id', $partners, ['label' => __('partner.partner'), 'placeholder' => __('partner.no_partner')]) !!}
+
+
+ + {{ Form::close() }} +
+ @endif + @endcan +
+
+@endsection + +@section('styles') + {{ Html::style(url('css/plugins/jquery.datetimepicker.css')) }} +@endsection + +@push('scripts') + {{ Html::script(url('js/plugins/jquery.datetimepicker.js')) }} + +@endpush diff --git a/resources/views/transactions/forms.blade.php b/resources/views/transactions/forms.blade.php index db31516..4000203 100644 --- a/resources/views/transactions/forms.blade.php +++ b/resources/views/transactions/forms.blade.php @@ -1,68 +1,3 @@ -@can('create', new App\Transaction) -@if (request('action') == 'add-income') - -@endif -@if (request('action') == 'add-spending') - -@endif -@endcan - @if (request('action') == 'edit' && $editableTransaction) @can('update', $editableTransaction) diff --git a/tests/Feature/Transactions/TransactionEntryTest.php b/tests/Feature/Transactions/TransactionEntryTest.php index b071aa5..95df2a5 100644 --- a/tests/Feature/Transactions/TransactionEntryTest.php +++ b/tests/Feature/Transactions/TransactionEntryTest.php @@ -23,7 +23,7 @@ public function user_can_create_an_income_transaction() $this->visit(route('transactions.index', ['month' => $month, 'year' => $year])); $this->click(__('transaction.add_income')); - $this->seeRouteIs('transactions.index', ['action' => 'add-income', 'month' => $month, 'year' => $year]); + $this->seeRouteIs('transactions.create', ['action' => 'add-income', 'month' => $month, 'year' => $year]); $this->submitForm(__('transaction.add_income'), [ 'amount' => 99.99, @@ -56,7 +56,7 @@ public function user_can_create_a_spending_transaction() $this->visit(route('transactions.index', ['month' => $month, 'year' => $year])); $this->click(__('transaction.add_spending')); - $this->seeRouteIs('transactions.index', ['action' => 'add-spending', 'month' => $month, 'year' => $year]); + $this->seeRouteIs('transactions.create', ['action' => 'add-spending', 'month' => $month, 'year' => $year]); $this->submitForm(__('transaction.add_spending'), [ 'amount' => 99.99,