Skip to content

Commit

Permalink
Merge pull request #20 from nafiesl/user_start_date
Browse files Browse the repository at this point in the history
Add Category and Partner Transaction Listing Default Start Date
  • Loading branch information
nafiesl committed Jun 4, 2019
2 parents e41619b + 6c107b8 commit e5b3052
Show file tree
Hide file tree
Showing 14 changed files with 66 additions and 29 deletions.
5 changes: 3 additions & 2 deletions app/Http/Controllers/Auth/ProfileController.php
Original file line number Diff line number Diff line change
Expand Up @@ -40,8 +40,9 @@ public function edit()
public function update(Request $request)
{
$userData = $request->validate([
'name' => 'required|max:60',
'email' => 'required|max:255|unique:users,email,'.auth()->id(),
'name' => 'required|max:60',
'email' => 'required|max:255|unique:users,email,'.auth()->id(),
'account_start_date' => 'nullable|date',
]);

auth()->user()->update($userData);
Expand Down
5 changes: 4 additions & 1 deletion app/Http/Controllers/CategoriesController.php
Original file line number Diff line number Diff line change
Expand Up @@ -55,8 +55,11 @@ public function show(Category $category)
$editableTransaction = null;
$year = request('year', date('Y'));
$partners = $this->getPartnerList();
$startDate = request('start_date', date('Y-m').'-01');

$defaultStartDate = auth()->user()->account_start_date ?: date('Y-m').'-01';
$startDate = request('start_date', $defaultStartDate);
$endDate = request('end_date', date('Y-m-d'));

$transactions = $this->getCategoryTransactions($category, [
'partner_id' => request('partner_id'),
'start_date' => $startDate,
Expand Down
5 changes: 4 additions & 1 deletion app/Http/Controllers/PartnerController.php
Original file line number Diff line number Diff line change
Expand Up @@ -59,8 +59,11 @@ public function show(Partner $partner)
$editableTransaction = null;
$year = request('year', date('Y'));
$categories = $this->getCategoryList();
$startDate = request('start_date', date('Y-m').'-01');

$defaultStartDate = auth()->user()->account_start_date ?: date('Y-m').'-01';
$startDate = request('start_date', $defaultStartDate);
$endDate = request('end_date', date('Y-m-d'));

$transactions = $this->getPartnerTransactions($partner, [
'category_id' => request('category_id'),
'start_date' => $startDate,
Expand Down
9 changes: 6 additions & 3 deletions app/Http/Controllers/TransactionsController.php
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,8 @@ public function index()
$yearMonth = $this->getYearMonth();
$year = request('year', date('Y'));
$month = request('month', date('m'));
$defaultStartDate = auth()->user()->account_start_date;
$startDate = $defaultStartDate ?: $year.'-'.$month.'-01';

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

Expand All @@ -36,7 +38,8 @@ public function index()
return view('transactions.index', compact(
'transactions', 'editableTransaction',
'yearMonth', 'month', 'year', 'categories',
'incomeTotal', 'spendingTotal', 'partners'
'incomeTotal', 'spendingTotal', 'partners',
'startDate'
));
}

Expand Down Expand Up @@ -82,7 +85,7 @@ public function update(UpdateRequest $transactionUpateForm, Transaction $transac
$transaction->partner_id,
'start_date' => $transactionUpateForm->get('start_date'),
'end_date' => $transactionUpateForm->get('end_date'),
'category_id' => $transactionUpateForm->get('queried_category_id'),
'category_id' => $transactionUpateForm->get('category_id'),
'query' => $transactionUpateForm->get('query'),
]);
}
Expand All @@ -91,7 +94,7 @@ public function update(UpdateRequest $transactionUpateForm, Transaction $transac
$transaction->category_id,
'start_date' => $transactionUpateForm->get('start_date'),
'end_date' => $transactionUpateForm->get('end_date'),
'partner_id' => $transactionUpateForm->get('queried_partner_id'),
'partner_id' => $transactionUpateForm->get('partner_id'),
'query' => $transactionUpateForm->get('query'),
]);
}
Expand Down
2 changes: 1 addition & 1 deletion app/User.php
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@ class User extends Authenticatable
* @var array
*/
protected $fillable = [
'name', 'email', 'password', 'api_token',
'name', 'email', 'password', 'api_token', 'account_start_date',
];

/**
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,7 @@ public function up()
$table->string('password');
$table->char('api_token', 24);
$table->boolean('is_active')->default(1);
$table->date('account_start_date')->nullable();
$table->rememberToken();
$table->timestamps();
});
Expand Down
11 changes: 6 additions & 5 deletions resources/lang/en/user.php
Original file line number Diff line number Diff line change
Expand Up @@ -26,11 +26,12 @@
'undeleted' => 'User not deleted.',

// Attributes
'name' => 'User Name',
'email' => 'Email Address',
'phone' => 'Phone',
'is_active' => 'User Status',
'registered_at' => 'Registered at',
'name' => 'User Name',
'email' => 'Email Address',
'phone' => 'Phone',
'is_active' => 'User Status',
'registered_at' => 'Registered at',
'account_start_date' => 'Account Start Date',

// Relations
'groups' => 'Member List',
Expand Down
11 changes: 6 additions & 5 deletions resources/lang/id/user.php
Original file line number Diff line number Diff line change
Expand Up @@ -26,11 +26,12 @@
'undeleted' => 'Data User gagal dihapus.',

// Attributes
'name' => 'Nama User',
'email' => 'Alamat Email',
'phone' => 'Telp/Hp.',
'is_active' => 'Status User',
'registered_at' => 'Terdaftar sejak',
'name' => 'Nama User',
'email' => 'Alamat Email',
'phone' => 'Telp/Hp.',
'is_active' => 'Status User',
'registered_at' => 'Terdaftar sejak',
'account_start_date' => 'Akun Mulai Digunakan',

// Relations
'groups' => 'List Member',
Expand Down
19 changes: 19 additions & 0 deletions resources/views/auth/profile/edit.blade.php
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,7 @@
<div class="panel-body">
{!! FormField::text('name', ['required' => true]) !!}
{!! FormField::email('email', ['required' => true]) !!}
{!! FormField::text('account_start_date') !!}
</div>
<div class="panel-footer">
{{ Form::submit(__('user.profile_update'), ['class' => 'btn btn-success']) }}
Expand All @@ -21,3 +22,21 @@
</div>
</div>
@endsection

@section('styles')
{{ Html::style(url('css/plugins/jquery.datetimepicker.css')) }}
@endsection

@push('scripts')
{{ Html::script(url('js/plugins/jquery.datetimepicker.js')) }}
<script>
(function () {
$('#account_start_date').datetimepicker({
timepicker:false,
format:'Y-m-d',
closeOnDateSelect: true,
scrollInput: false
});
})();
</script>
@endpush
1 change: 1 addition & 0 deletions resources/views/auth/profile/show.blade.php
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,7 @@
<tbody>
<tr><td>{{ __('user.name') }}</td><td>{{ $user->name }}</td></tr>
<tr><td>{{ __('user.email') }}</td><td>{{ $user->email }}</td></tr>
<tr><td>{{ __('user.account_start_date') }}</td><td>{{ $user->account_start_date }}</td></tr>
</tbody>
</table>
<div class="panel-footer">
Expand Down
4 changes: 2 additions & 2 deletions resources/views/transactions/index.blade.php
Original file line number Diff line number Diff line change
Expand Up @@ -50,15 +50,15 @@
@php
$partnerRoute = route('partners.show', [
$transaction->partner_id,
'start_date' => $year.'-'.$month.'-01',
'start_date' => $startDate,
'end_date' => $year.'-'.$month.'-'.date('t'),
]);
@endphp
<a href="{{ $partnerRoute }}">{!! optional($transaction->partner)->name_label !!}</a>
@php
$categoryRoute = route('categories.show', [
$transaction->category_id,
'start_date' => $year.'-'.$month.'-01',
'start_date' => $startDate,
'end_date' => $year.'-'.$month.'-'.date('t'),
]);
@endphp
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -20,15 +20,15 @@
@php
$partnerRoute = route('partners.show', [
$transaction->partner_id,
'start_date' => $year.'-'.$month.'-01',
'start_date' => $startDate,
'end_date' => $year.'-'.$month.'-'.date('t'),
]);
@endphp
<a href="{{ $partnerRoute }}">{!! optional($transaction->partner)->name_label !!}</a>
@php
$categoryRoute = route('categories.show', [
$transaction->category_id,
'start_date' => $year.'-'.$month.'-01',
'start_date' => $startDate,
'end_date' => $year.'-'.$month.'-'.date('t'),
]);
@endphp
Expand Down
12 changes: 7 additions & 5 deletions tests/Feature/Auth/UserProfileTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -27,18 +27,20 @@ public function user_can_update_their_profile_data()
$this->click(__('user.profile_edit'));
$this->seeRouteIs('profile.edit');
$this->submitForm(__('user.profile_update'), [
'name' => 'User Baru',
'email' => 'user3@mail.com',
'name' => 'User Baru',
'email' => 'user3@mail.com',
'account_start_date' => '2016-06-01',
]);

$this->seeRouteIs('profile.show');
$this->seeText(__('user.profile_updated'));
$this->seeText('User Baru');

$this->seeInDatabase('users', [
'id' => $user->id,
'name' => 'User Baru',
'email' => 'user3@mail.com',
'id' => $user->id,
'name' => 'User Baru',
'email' => 'user3@mail.com',
'account_start_date' => '2016-06-01',
]);
}
}
6 changes: 4 additions & 2 deletions tests/Feature/Transactions/TransactionEditTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -167,8 +167,9 @@ public function user_can_edit_a_transaction_from_partner_transactions_page()

$this->seeRouteIs('partners.show', [
$partner->id,
'end_date' => $year.'-'.$month.'-28',
'start_date' => $date,
'category_id' => $category->id,
'end_date' => $year.'-'.$month.'-28',
'start_date' => $date,
]);
$this->see(__('transaction.updated'));

Expand Down Expand Up @@ -268,6 +269,7 @@ public function user_can_edit_a_transaction_from_category_transactions_page()
$this->seeRouteIs('categories.show', [
$category->id,
'end_date' => $year.'-'.$month.'-28',
'partner_id' => $partner->id,
'start_date' => $date,
]);
$this->see(__('transaction.updated'));
Expand Down

0 comments on commit e5b3052

Please sign in to comment.