diff --git a/app/Cart/Item.php b/app/Cart/Item.php
index fdfb5d7..7dcc5ba 100644
--- a/app/Cart/Item.php
+++ b/app/Cart/Item.php
@@ -36,11 +36,16 @@ class Item
}
if (isset($newItemData['item_discount'])) {
- $this->item_discount = $newItemData['item_discount'];
- $this->item_discount_subtotal = $this->item_discount * $this->qty;
- $this->subtotal = $this->subtotal - $this->item_discount_subtotal;
+ $this->setItemDiscount($newItemData['item_discount']);
}
return $this;
}
+
+ public function setItemDiscount(int $discount)
+ {
+ $this->item_discount = $discount;
+ $this->item_discount_subtotal = $discount * $this->qty;
+ $this->subtotal = $this->subtotal - $this->item_discount_subtotal;
+ }
}
diff --git a/app/Cart/TransactionDraft.php b/app/Cart/TransactionDraft.php
index 0f8d055..faf0318 100644
--- a/app/Cart/TransactionDraft.php
+++ b/app/Cart/TransactionDraft.php
@@ -48,6 +48,11 @@ abstract class TransactionDraft
$this->items = [];
}
+ public function getSubtotal()
+ {
+ return $this->items()->sum('subtotal') + $this->getDiscountTotal();
+ }
+
public function getTotal()
{
return $this->items()->sum('subtotal');
diff --git a/resources/views/cart/index.blade.php b/resources/views/cart/index.blade.php
index 6c13867..fe23d6e 100644
--- a/resources/views/cart/index.blade.php
+++ b/resources/views/cart/index.blade.php
@@ -45,7 +45,7 @@
@forelse($queriedProducts as $product)
| {{ $product->name }} |
- {{ $draft->type == 'cash' ? $product->cash_price : $product->credit_price }} |
+ {{ formatRp($draft->type == 'cash' ? $product->cash_price : $product->credit_price) }} |
|
@@ -88,28 +88,48 @@
{{ Form::open(['route' => ['cart.update-draft-item', $draft->draftKey], 'method' => 'patch']) }}
{{ Form::hidden('item_key', $key) }}
- {{ Form::hidden('item_discount', $item->item_discount) }}
- {{ Form::number('qty', $item->qty, ['id' => 'qty-' . $key, 'style' => 'width:50px;text-align:center']) }}
+ {{ Form::hidden('qty', $item->qty) }}
+ {{ Form::text('item_discount', $item->item_discount, ['id' => 'item_discount-' . $key, 'style' => 'width:100px;text-align:right']) }}
+ {{ Form::submit('update-item-' . $key, ['style'=>'display:none']) }}
{{ Form::close() }}
|
{{ Form::open(['route' => ['cart.update-draft-item', $draft->draftKey], 'method' => 'patch']) }}
{{ Form::hidden('item_key', $key) }}
- {{ Form::hidden('qty', $item->qty) }}
- {{ Form::text('item_discount', $item->item_discount, ['id' => 'item_discount-' . $key, 'style' => 'width:100px;text-align:right']) }}
+ {{ Form::hidden('item_discount', $item->item_discount) }}
+ {{ Form::number('qty', $item->qty, ['id' => 'qty-' . $key, 'style' => 'width:50px;text-align:center']) }}
+ {{ Form::submit('update-item-' . $key, ['style'=>'display:none']) }}
{{ Form::close() }}
|
- {{ formatRp($item->subtotal) }} |
-
+ | {{ formatRp($item->subtotal) }} |
+
{!! FormField::delete([
'route' => ['cart.remove-draft-item', $draft->draftKey],
'onsubmit' => 'Yakin ingin menghapus Item ini?',
+ 'class' => '',
], 'x', ['id' => 'remove-item-' . $key, 'class' => 'btn btn-danger btn-xs'], ['item_index' => $key]) !!}
|
@empty
@endforelse
+