diff --git a/app/Http/Controllers/PaymentsController.php b/app/Http/Controllers/PaymentsController.php index d8b58ab..c9f7425 100755 --- a/app/Http/Controllers/PaymentsController.php +++ b/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'); diff --git a/tests/Feature/Payments/ManagePaymentsTest.php b/tests/Feature/Payments/ManagePaymentsTest.php index 6e4c004..7ac0f3d 100644 --- a/tests/Feature/Payments/ManagePaymentsTest.php +++ b/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, ]); }