Browse Source

Refactor Payment controller and repository

pull/1/head
Nafies Luthfi 8 years ago
parent
commit
4a6bc7a356
  1. 17
      app/Entities/Payments/PaymentsRepository.php
  2. 12
      app/Http/Controllers/PaymentsController.php
  3. 6
      resources/views/payments/edit.blade.php
  4. 68
      tests/Feature/Payments/ManagePaymentsTest.php
  5. 2
      tests/Feature/Users/ManageUsersTest.php

17
app/Entities/Payments/PaymentsRepository.php

@ -6,6 +6,8 @@ use App\Entities\BaseRepository;
/**
* Payments Repository Class
*
* @author Nafies Luthfi <nafiesL@gmail.com>
*/
class PaymentsRepository extends BaseRepository
{
@ -45,19 +47,4 @@ class PaymentsRepository extends BaseRepository
return $this->storeArray($paymentData);
}
public function update($paymentData = [], $paymentId)
{
foreach ($paymentData as $key => $value) {
if ( ! $paymentData[$key]) {
$paymentData[$key] = null;
}
}
$paymentData['amount'] = str_replace('.', '', $paymentData['amount']);
$payment = $this->requireById($paymentId);
$payment->update($paymentData);
return $payment;
}
}

12
app/Http/Controllers/PaymentsController.php

@ -10,6 +10,11 @@ use App\Http\Requests\Payments\DeleteRequest;
use App\Http\Requests\Payments\UpdateRequest;
use Illuminate\Http\Request;
/**
* Payments Controller class
*
* @author Nafies Luthfi <nafiesL@gmail.com>
*/
class PaymentsController extends Controller
{
private $repo;
@ -52,11 +57,12 @@ class PaymentsController extends Controller
return view('payments.edit', compact('payment', 'projects', 'partners'));
}
public function update(UpdateRequest $request, $paymentId)
public function update(UpdateRequest $request, Payment $payment)
{
$payment = $this->repo->update($request->except(['_method', '_token']), $paymentId);
$payment->update($request->except(['_method', '_token']));
flash()->success(trans('payment.updated'));
return redirect()->route('payments.show', $paymentId);
return redirect()->route('payments.show', $payment->id);
}
public function delete(Payment $payment)

6
resources/views/payments/edit.blade.php

@ -56,7 +56,6 @@
@section('ext_js')
{!! Html::script(url('assets/js/plugins/jquery.datetimepicker.js')) !!}
{!! Html::script(url('assets/js/plugins/autoNumeric.min.js')) !!}
@endsection
@section('script')
@ -67,11 +66,6 @@
format:'Y-m-d',
closeOnDateSelect: true
});
$('#amount').autoNumeric("init",{
aSep: '.',
aDec: ',',
mDec: '0'
});
})();
</script>
@endsection

68
tests/Feature/Payments/ManagePaymentsTest.php

@ -8,6 +8,11 @@ use App\Entities\Payments\Payment;
use App\Entities\Projects\Project;
use Tests\TestCase;
/**
* Manage Payments Feature Test
*
* @author Nafies Luthfi <nafiesL@gmail.com>
*/
class ManagePaymentsTest extends TestCase
{
/** @test */
@ -17,24 +22,26 @@ class ManagePaymentsTest extends TestCase
$customer = factory(Customer::class)->create();
$project = factory(Project::class)->create();
$this->visit(route('payments.index'));
$this->seePageIs(route('payments.index'));
$this->click(trans('payment.create'));
$this->visit(route('payments.create'));
$this->seePageIs(route('payments.create'));
// Fill Form
$this->seePageIs(route('payments.create'));
$this->type('2015-05-01', 'date');
$this->select(1, 'in_out');
$this->type(1000000, 'amount');
$this->select($project->id, 'project_id');
$this->select($customer->id, 'partner_id');
$this->type('Pembayaran DP', 'description');
$this->press(trans('payment.create'));
$this->submitForm(trans('payment.create'), [
'date' => '2015-05-01',
'in_out' => 1,
'type_id' => 1,
'amount' => 1000000,
'project_id' => $project->id,
'partner_id' => $customer->id,
'description' => 'Pembayaran DP',
]);
$this->see(trans('payment.created'));
$this->seeInDatabase('payments', [
'project_id' => $project->id,
'amount' => 1000000,
'type_id' => 1,
'in_out' => 1,
'date' => '2015-05-01',
'partner_type' => Customer::class,
@ -49,22 +56,22 @@ class ManagePaymentsTest extends TestCase
$vendor = factory(Vendor::class)->create();
$project = factory(Project::class)->create();
$this->visit(route('payments.index'));
$this->seePageIs(route('payments.index'));
$this->click(trans('payment.create'));
$this->visit(route('payments.create'));
$this->seePageIs(route('payments.create'));
// Fill Form
$this->seePageIs(route('payments.create'));
$this->type('2015-05-01', 'date');
$this->select(0, 'in_out');
$this->select(3, 'type_id');
$this->type(1000000, 'amount');
$this->select($project->id, 'project_id');
$this->select($vendor->id, 'partner_id');
$this->type('Pembayaran DP', 'description');
$this->press(trans('payment.create'));
$this->submitForm(trans('payment.create'), [
'date' => '2015-05-01',
'in_out' => 0,
'type_id' => 3,
'amount' => 1000000,
'project_id' => $project->id,
'partner_id' => $vendor->id,
'description' => 'Pembayaran DP',
]);
$this->see(trans('payment.created'));
$this->seeInDatabase('payments', [
'project_id' => $project->id,
'amount' => 1000000,
@ -84,18 +91,21 @@ class ManagePaymentsTest extends TestCase
$this->visit(route('payments.edit', $payment->id));
$this->seePageIs(route('payments.edit', $payment->id));
$this->type('2016-05-20', 'date');
$this->select(1, 'in_out');
$this->select(3, 'type_id');
$this->type(1234567890, 'amount');
$this->press(trans('payment.update'));
$this->submitForm(trans('payment.update'), [
'date' => '2016-05-20',
'in_out' => 0,
'type_id' => 3,
'amount' => 1000000,
'description' => 'Pembayaran DP',
]);
$this->seePageIs(route('payments.show', $payment->id));
$this->see(trans('payment.updated'));
$this->seeInDatabase('payments', [
'date' => '2016-05-20',
'amount' => 1234567890,
'amount' => 1000000,
]);
}

2
tests/Feature/Users/ManageUsersTest.php

@ -6,6 +6,8 @@ use App\Entities\Users\User;
use Tests\TestCase;
/**
* Manage Users Feature Test
*
* @author Nafies Luthfi <nafiesL@gmail.com>
*/
class ManageUsersTest extends TestCase

Loading…
Cancel
Save