Browse Source

First fix for partner payment

pull/24/head
Nafies Luthfi 7 years ago
parent
commit
a9172a1ad4
  1. 6
      app/Http/Controllers/PaymentsController.php
  2. 15
      app/Http/Requests/Payments/UpdateRequest.php
  3. 11
      resources/views/payments/edit.blade.php
  4. 40
      tests/Feature/Payments/ManageProjectFeesTest.php

6
app/Http/Controllers/PaymentsController.php

@ -112,7 +112,11 @@ class PaymentsController extends Controller
$paymentData = $request->validated(); $paymentData = $request->validated();
if ($paymentData['in_out'] == 0) { 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 { } else {
$paymentData['partner_type'] = 'App\Entities\Partners\Customer'; $paymentData['partner_type'] = 'App\Entities\Partners\Customer';
} }

15
app/Http/Requests/Payments/UpdateRequest.php

@ -24,13 +24,14 @@ class UpdateRequest extends Request
public function rules() public function rules()
{ {
return [ 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',
]; ];
} }
} }

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

@ -14,10 +14,10 @@
<div class="panel-body"> <div class="panel-body">
<div class="row"> <div class="row">
<div class="col-md-6"> <div class="col-md-6">
{!! 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')]) !!}
</div> </div>
<div class="col-md-6"> <div class="col-md-6">
{!! 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']) !!}
</div> </div>
</div> </div>
<div class="row"> <div class="row">
@ -33,7 +33,12 @@
{!! FormField::select('project_id', $projects, ['label'=> __('payment.project')]) !!} {!! FormField::select('project_id', $projects, ['label'=> __('payment.project')]) !!}
</div> </div>
<div class="col-sm-6"> <div class="col-sm-6">
{!! 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
</div> </div>
</div> </div>
{!! FormField::textarea('description', ['label'=> __('payment.description')]) !!} {!! FormField::textarea('description', ['label'=> __('payment.description')]) !!}

40
tests/Feature/Payments/ManageProjectFeesTest.php

@ -4,6 +4,7 @@ namespace Tests\Feature\Payments;
use Tests\TestCase; use Tests\TestCase;
use App\Entities\Users\User; use App\Entities\Users\User;
use App\Entities\Payments\Payment;
use App\Entities\Projects\Project; use App\Entities\Projects\Project;
class ManageProjectFeesTest extends TestCase class ManageProjectFeesTest extends TestCase
@ -43,4 +44,43 @@ class ManageProjectFeesTest extends TestCase
'partner_id' => $worker->id, '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,
]);
}
} }
Loading…
Cancel
Save