diff --git a/app/Http/Controllers/CartController.php b/app/Http/Controllers/CartController.php
index ceba4e9..d592ada 100644
--- a/app/Http/Controllers/CartController.php
+++ b/app/Http/Controllers/CartController.php
@@ -121,8 +121,12 @@ class CartController extends Controller
$this->validate($request, [
'customer.name' => 'required|string|max:30',
'customer.phone' => 'nullable|string|max:20',
- 'payment' => 'required|numeric',
+ 'total' => 'required|numeric',
+ 'payment' => 'required|numeric|min:' . $request->get('total') . '|max:' . ($request->get('total') + 100000),
'notes' => 'nullable|string|max:100',
+ ], [
+ 'payment.min' => 'Pembayaran minimal ' . formatRp($request->get('total')) . '.',
+ 'payment.max' => 'Pembayaran terlalu besar.'
]);
$draft = $this->cart->updateDraftAttributes($draftKey, $request->only('customer', 'notes', 'payment'));
diff --git a/resources/views/cart/partials/form-draft-detail.blade.php b/resources/views/cart/partials/form-draft-detail.blade.php
index 3707dbc..b6b6608 100644
--- a/resources/views/cart/partials/form-draft-detail.blade.php
+++ b/resources/views/cart/partials/form-draft-detail.blade.php
@@ -5,6 +5,7 @@
{!! FormField::text('customer[phone]', ['label' => trans('transaction.customer_phone'), 'value' => $draft->customer['phone']]) !!}
{!! FormField::price('payment', ['label' => trans('transaction.payment'), 'value' => $draft->payment, 'required' => true]) !!}
+{{ Form::hidden('total', $draft->getTotal()) }}
{!! FormField::textarea('notes', ['label' => trans('transaction.notes'), 'value' => $draft->notes]) !!}
{{ Form::submit(trans('transaction.proccess'), ['class' => 'btn btn-info']) }}
{{ Form::close() }}
\ No newline at end of file
diff --git a/tests/Feature/TransactionEntryTest.php b/tests/Feature/TransactionEntryTest.php
index 4c55dd0..64bd009 100644
--- a/tests/Feature/TransactionEntryTest.php
+++ b/tests/Feature/TransactionEntryTest.php
@@ -214,6 +214,42 @@ class TransactionEntryTest extends BrowserKitTestCase
}
/** @test */
+ public function it_validates_proper_payment_amount()
+ {
+ $cart = new CartCollection();
+
+ $draft = $cart->add(new CashDraft());
+
+ $product1 = factory(Product::class)->create(['cash_price' => 100000]);
+ $product2 = factory(Product::class)->create(['cash_price' => 50000]);
+ $item1 = new Item($product1, 1);
+ $item2 = new Item($product2, 3);
+
+ // Add items to draft
+ $cart->addItemToDraft($draft->draftKey, $item1);
+ $cart->addItemToDraft($draft->draftKey, $item2);
+
+ $this->loginAsUser();
+ $this->visit(route('cart.show', $draft->draftKey));
+
+ $this->type('Nafies', 'customer[name]');
+ $this->type('-', 'customer[phone]');
+ $this->type('catatan', 'notes');
+
+ $this->type(100000, 'payment');
+ $this->press(trans('transaction.proccess'));
+ $this->dontSee(trans('transaction.confirm'));
+
+ $this->type(350001, 'payment');
+ $this->press(trans('transaction.proccess'));
+ $this->dontSee(trans('transaction.confirm'));
+
+ $this->type(350000, 'payment');
+ $this->press(trans('transaction.proccess'));
+ $this->see(trans('transaction.confirm'));
+ }
+
+ /** @test */
public function user_can_save_transaction_if_draft_is_completed()
{
$cart = new CartCollection();