diff --git a/app/Entities/Payments/PaymentsRepository.php b/app/Entities/Payments/PaymentsRepository.php index 8391379..c80653a 100755 --- a/app/Entities/Payments/PaymentsRepository.php +++ b/app/Entities/Payments/PaymentsRepository.php @@ -6,6 +6,8 @@ use App\Entities\BaseRepository; /** * Payments Repository Class + * + * @author Nafies Luthfi */ 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; - } } diff --git a/app/Http/Controllers/PaymentsController.php b/app/Http/Controllers/PaymentsController.php index eaf8051..09fe1d5 100755 --- a/app/Http/Controllers/PaymentsController.php +++ b/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 + */ 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) diff --git a/resources/views/payments/edit.blade.php b/resources/views/payments/edit.blade.php index 2a3fe4e..6797b17 100755 --- a/resources/views/payments/edit.blade.php +++ b/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' - }); })(); @endsection diff --git a/tests/Feature/Payments/ManagePaymentsTest.php b/tests/Feature/Payments/ManagePaymentsTest.php index d65eaf4..3d484bc 100644 --- a/tests/Feature/Payments/ManagePaymentsTest.php +++ b/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 + */ 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, ]); } diff --git a/tests/Feature/Users/ManageUsersTest.php b/tests/Feature/Users/ManageUsersTest.php index f7ed2d5..74ea3ca 100644 --- a/tests/Feature/Users/ManageUsersTest.php +++ b/tests/Feature/Users/ManageUsersTest.php @@ -6,6 +6,8 @@ use App\Entities\Users\User; use Tests\TestCase; /** + * Manage Users Feature Test + * * @author Nafies Luthfi */ class ManageUsersTest extends TestCase