diff --git a/app/Http/Controllers/PaymentsController.php b/app/Http/Controllers/PaymentsController.php
index 21b5738..38eeb4d 100755
--- a/app/Http/Controllers/PaymentsController.php
+++ b/app/Http/Controllers/PaymentsController.php
@@ -112,7 +112,11 @@ class PaymentsController extends Controller
$paymentData = $request->validated();
if ($paymentData['in_out'] == 0) {
- $paymentData['partner_type'] = 'App\Entities\Partners\Vendor';
+ if (isset($paymentData['partner_type']) && $paymentData['partner_type'] == 'users') {
+ $paymentData['partner_type'] = 'App\Entities\Users\User';
+ } else {
+ $paymentData['partner_type'] = 'App\Entities\Partners\Vendor';
+ }
} else {
$paymentData['partner_type'] = 'App\Entities\Partners\Customer';
}
diff --git a/app/Http/Requests/Payments/UpdateRequest.php b/app/Http/Requests/Payments/UpdateRequest.php
index 53dc6b1..ee856da 100644
--- a/app/Http/Requests/Payments/UpdateRequest.php
+++ b/app/Http/Requests/Payments/UpdateRequest.php
@@ -24,13 +24,14 @@ class UpdateRequest extends Request
public function rules()
{
return [
- 'date' => 'required|date|date_format:Y-m-d',
- 'in_out' => 'required|numeric',
- 'amount' => 'required',
- 'project_id' => 'required|numeric',
- 'type_id' => 'required|numeric',
- 'partner_id' => 'required|numeric',
- 'description' => 'required|max:255',
+ 'date' => 'required|date|date_format:Y-m-d',
+ 'in_out' => 'required|numeric',
+ 'amount' => 'required',
+ 'project_id' => 'required|numeric',
+ 'type_id' => 'required|numeric',
+ 'partner_type' => 'nullable|string',
+ 'partner_id' => 'required|numeric',
+ 'description' => 'required|max:255',
];
}
}
diff --git a/resources/views/payments/edit.blade.php b/resources/views/payments/edit.blade.php
index e531eb3..53155b0 100755
--- a/resources/views/payments/edit.blade.php
+++ b/resources/views/payments/edit.blade.php
@@ -14,10 +14,10 @@
- {!! FormField::radios('in_out', [__('payment.out'), __('payment.in')], ['label'=> __('payment.in_out'), 'value' => 1]) !!}
+ {!! FormField::radios('in_out', [__('payment.out'), __('payment.in')], ['label'=> __('payment.in_out')]) !!}
- {!! FormField::radios('type_id', PaymentType::toArray(), ['label' => __('payment.type'), 'value' => 1, 'list_style' => 'unstyled']) !!}
+ {!! FormField::radios('type_id', PaymentType::toArray(), ['label' => __('payment.type'), 'list_style' => 'unstyled']) !!}
@@ -33,7 +33,12 @@
{!! FormField::select('project_id', $projects, ['label'=> __('payment.project')]) !!}
- {!! FormField::select('partner_id', $partners, ['label'=> __('payment.customer')]) !!}
+ @if ($payment->partner_type == 'App\Entities\Users\User')
+ {!! FormField::select('partner_id', App\Entities\Users\User::pluck('name', 'id'), ['label'=> __('payment.partner')]) !!}
+ {{ Form::hidden('partner_type', 'users') }}
+ @else
+ {!! FormField::select('partner_id', $partners, ['label'=> __('payment.customer')]) !!}
+ @endif
{!! FormField::textarea('description', ['label'=> __('payment.description')]) !!}
diff --git a/tests/Feature/Payments/ManageProjectFeesTest.php b/tests/Feature/Payments/ManageProjectFeesTest.php
index 917c519..fb2c226 100644
--- a/tests/Feature/Payments/ManageProjectFeesTest.php
+++ b/tests/Feature/Payments/ManageProjectFeesTest.php
@@ -4,6 +4,7 @@ namespace Tests\Feature\Payments;
use Tests\TestCase;
use App\Entities\Users\User;
+use App\Entities\Payments\Payment;
use App\Entities\Projects\Project;
class ManageProjectFeesTest extends TestCase
@@ -43,4 +44,43 @@ class ManageProjectFeesTest extends TestCase
'partner_id' => $worker->id,
]);
}
+
+ /** @test */
+ public function admin_can_edit_project_fee_payment()
+ {
+ $this->adminUserSigningIn();
+ $worker = factory(User::class)->create();
+ $project = factory(Project::class)->create();
+ $payment = factory(Payment::class)->create([
+ 'project_id' => $project->id,
+ 'partner_type' => User::class,
+ 'partner_id' => $worker->id,
+ ]);
+
+ $this->visit(route('payments.edit', $payment));
+
+ // Fill Form
+ $this->submitForm(__('payment.update'), [
+ 'date' => '2015-05-01',
+ 'in_out' => 0,
+ 'type_id' => 1,
+ 'amount' => 1000000,
+ 'partner_type' => 'users',
+ 'partner_id' => $worker->id,
+ 'description' => 'Honor pengerjaan fitur a project '.$project->name,
+ ]);
+
+ $this->see(__('payment.updated'));
+ $this->seePageIs(route('payments.show', $payment));
+
+ $this->seeInDatabase('payments', [
+ 'project_id' => $project->id,
+ 'amount' => 1000000,
+ 'type_id' => 1,
+ 'in_out' => 0,
+ 'date' => '2015-05-01',
+ 'partner_type' => User::class,
+ 'partner_id' => $worker->id,
+ ]);
+ }
}