Browse Source

Fixed invalid partner_type on payment update action

Before, payment update action does not update partner_type
column even if the in_out are changed. This commit fixed
will also update partner_type on in_out changes.
pull/12/head
Nafies Luthfi 8 years ago
parent
commit
2e44b9cc69
  1. 10
      app/Http/Controllers/PaymentsController.php
  2. 52
      tests/Feature/Payments/ManagePaymentsTest.php

10
app/Http/Controllers/PaymentsController.php

@ -63,7 +63,15 @@ class PaymentsController extends Controller
public function update(UpdateRequest $request, Payment $payment)
{
$payment->update($request->except(['_method', '_token']));
$paymentData = $request->validated();
if ($paymentData['in_out'] == 0) {
$paymentData['partner_type'] = 'App\Entities\Partners\Vendor';
} else {
$paymentData['partner_type'] = 'App\Entities\Partners\Customer';
}
$payment->update($paymentData);
flash(trans('payment.updated'), 'success');

52
tests/Feature/Payments/ManagePaymentsTest.php

@ -122,16 +122,58 @@ class ManagePaymentsTest extends TestCase
{
$user = $this->adminUserSigningIn();
$payment = factory(Payment::class)->create();
$vendor = factory(Vendor::class)->create();
$payment = factory(Payment::class)->create([
'in_out' => 0, // Outcome
'partner_type' => Vendor::class,
'partner_id' => $vendor->id,
]);
$this->visit(route('payments.edit', $payment->id));
$this->seePageIs(route('payments.edit', $payment->id));
$this->submitForm(trans('payment.update'), [
'date' => '2016-05-20',
'in_out' => 0,
'in_out' => 0, // Outcome
'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',
'in_out' => 0, // Outcome
'partner_type' => Vendor::class,
'partner_id' => $payment->partner_id,
'amount' => 1000000,
]);
}
/** @test */
public function admin_can_change_payment_type_from_expanse_to_income()
{
$user = $this->adminUserSigningIn();
$vendor = factory(Vendor::class)->create();
$payment = factory(Payment::class)->create([
'in_out' => 0, // Outcome
'partner_type' => Vendor::class,
'partner_id' => $vendor->id,
]);
$customer = factory(Customer::class)->create();
$this->visit(route('payments.edit', $payment->id));
$this->seePageIs(route('payments.edit', $payment->id));
$this->submitForm(trans('payment.update'), [
'date' => '2016-05-20',
'in_out' => 1, // Income
'type_id' => 3,
'amount' => 1000000,
'partner_id' => $customer->id,
'description' => 'Pembayaran DP',
]);
@ -139,8 +181,10 @@ class ManagePaymentsTest extends TestCase
$this->see(trans('payment.updated'));
$this->seeInDatabase('payments', [
'date' => '2016-05-20',
'amount' => 1000000,
'date' => '2016-05-20',
'in_out' => 1, // Income
'partner_type' => Customer::class,
'amount' => 1000000,
]);
}

Loading…
Cancel
Save