From f60858823922d7a5e899d28505dbc5572e239561 Mon Sep 17 00:00:00 2001 From: Nafies Luthfi Date: Tue, 17 Apr 2018 19:31:27 +0800 Subject: [PATCH] Add payment entry validation --- app/Http/Requests/Payments/CreateRequest.php | 10 +++++++- resources/lang/en/payment.php | 2 +- tests/Feature/Payments/ManagePaymentsTest.php | 35 +++++++++++++++++++++++++++ 3 files changed, 45 insertions(+), 2 deletions(-) diff --git a/app/Http/Requests/Payments/CreateRequest.php b/app/Http/Requests/Payments/CreateRequest.php index 5545f4e..e428c87 100644 --- a/app/Http/Requests/Payments/CreateRequest.php +++ b/app/Http/Requests/Payments/CreateRequest.php @@ -23,7 +23,7 @@ class CreateRequest extends Request */ public function rules() { - return [ + $rules = [ 'date' => 'required|date|date_format:Y-m-d', 'in_out' => 'required|numeric', 'amount' => 'required', @@ -32,5 +32,13 @@ class CreateRequest extends Request 'partner_id' => 'required|numeric', 'description' => 'required|max:255', ]; + + if ($this->get('in_out') == 0) { + $rules['partner_id'] = 'required|numeric|exists:vendors,id'; + } else { + $rules['partner_id'] = 'required|numeric|exists:customers,id'; + } + + return $rules; } } diff --git a/resources/lang/en/payment.php b/resources/lang/en/payment.php index fc6be37..9316e97 100644 --- a/resources/lang/en/payment.php +++ b/resources/lang/en/payment.php @@ -38,7 +38,7 @@ return [ 'out' => 'Cash out', 'type' => 'Payment Type', 'project' => 'Project', - 'customer' => 'Customer', + 'customer' => 'From/To', 'amount' => 'Amount', 'cash_in' => 'Cash In', 'cash_out' => 'Cash Out', diff --git a/tests/Feature/Payments/ManagePaymentsTest.php b/tests/Feature/Payments/ManagePaymentsTest.php index 87b8c1d..a68aee4 100644 --- a/tests/Feature/Payments/ManagePaymentsTest.php +++ b/tests/Feature/Payments/ManagePaymentsTest.php @@ -83,6 +83,41 @@ class ManagePaymentsTest extends TestCase } /** @test */ + public function payment_entry_validation_check() + { + $user = $this->adminUserSigningIn(); + $project = factory(Project::class)->create(); + + // Submit Form + $this->post(route('payments.store'), [ + 'date' => '2015-05-01', + 'in_out' => 0, + 'type_id' => 3, + 'amount' => 1000000, + 'project_id' => $project->id, + 'partner_id' => $project->customer_id, + 'description' => 'Pembayaran DP', + ]); + + $this->assertSessionHasErrors('partner_id'); + + factory(Vendor::class)->create(); + $vendor = factory(Vendor::class)->create(); + // Submit Form + $this->post(route('payments.store'), [ + 'date' => '2015-05-01', + 'in_out' => 1, + 'type_id' => 3, + 'amount' => 1000000, + 'project_id' => $project->id, + 'partner_id' => $vendor->id, + 'description' => 'Pembayaran DP', + ]); + + $this->assertSessionHasErrors('partner_id'); + } + + /** @test */ public function admin_can_edit_payment_data() { $user = $this->adminUserSigningIn();