diff --git a/app/Cart/Item.php b/app/Cart/Item.php index eba193b..b49dbfc 100644 --- a/app/Cart/Item.php +++ b/app/Cart/Item.php @@ -46,6 +46,5 @@ class Item { $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 40768e2..22e9ae6 100644 --- a/app/Cart/TransactionDraft.php +++ b/app/Cart/TransactionDraft.php @@ -54,12 +54,12 @@ abstract class TransactionDraft public function getSubtotal() { - return $this->items()->sum('subtotal') + $this->getDiscountTotal(); + return $this->items()->sum('subtotal'); } public function getTotal() { - return $this->items()->sum('subtotal'); + return $this->items()->sum('subtotal') - $this->getDiscountTotal(); } public function getTotalQty() diff --git a/resources/views/cart/partials/draft-confirm.blade.php b/resources/views/cart/partials/draft-confirm.blade.php index a2a4cc7..5c69e20 100644 --- a/resources/views/cart/partials/draft-confirm.blade.php +++ b/resources/views/cart/partials/draft-confirm.blade.php @@ -8,9 +8,9 @@ # Nama Item - Harga Satuan - Diskon per Item - Qty + Harga Satuan + Diskon per Item + Qty Subtotal @@ -19,9 +19,9 @@ {{ $key + 1 }} {{ $item->name }} - {{ formatRp($item->price) }} - {{ formatRp($item->item_discount) }} - {{ $item->qty }} + {{ formatRp($item->price) }} + {{ formatRp($item->item_discount) }} + {{ $item->qty }} {{ formatRp($item->subtotal) }} @empty diff --git a/tests/Feature/TransactionEntryTest.php b/tests/Feature/TransactionEntryTest.php index 3242283..d9f27a2 100644 --- a/tests/Feature/TransactionEntryTest.php +++ b/tests/Feature/TransactionEntryTest.php @@ -196,6 +196,7 @@ class TransactionEntryTest extends BrowserKitTestCase $this->see(trans('transaction.confirm')); $this->see(formatRp(10000)); + $this->see(formatRp(3000)); $this->seeElement('input', ['id' => 'save-transaction-draft']); } } diff --git a/tests/Unit/Integration/TransactionDraftTest.php b/tests/Unit/Integration/TransactionDraftTest.php index 0f7aefe..a1d81b5 100644 --- a/tests/Unit/Integration/TransactionDraftTest.php +++ b/tests/Unit/Integration/TransactionDraftTest.php @@ -141,12 +141,20 @@ class TransactionDraftTest extends TestCase } /** @test */ - public function transaction_draft_has_detail() + public function transaction_draft_has_payment_and_exchange() { - // TODO: check corrent draft attributes $cart = new CartCollection(); $draft = $cart->add(new CashDraft()); + + $product1 = factory(Product::class)->make(['cash_price' => 1000]); + $product2 = factory(Product::class)->make(['cash_price' => 2000]); + $item1 = new Item($product1, 1); + $item2 = new Item($product2, 3); + // Add items to draft + $cart->addItemToDraft($draft->draftKey, $item1); + $cart->addItemToDraft($draft->draftKey, $item2); + $draftAttributes = [ 'customer' => [ 'name' => 'Nafies', @@ -157,14 +165,13 @@ class TransactionDraftTest extends TestCase ]; $cart->updateDraftAttributes($draft->draftKey, $draftAttributes); - $this->assertArrayHasKey('invoice_no', $draft->toArray()); - $this->assertArrayHasKey('date', $draft->toArray()); - $this->assertArrayHasKey('items', $draft->toArray()); - $this->assertArrayHasKey('total', $draft->toArray()); - $this->assertArrayHasKey('payment', $draft->toArray()); - $this->assertArrayHasKey('customer', $draft->toArray()); - $this->assertArrayHasKey('status_id', $draft->toArray()); - $this->assertArrayHasKey('creator_id', $draft->toArray()); - $this->assertArrayHasKey('remark', $draft->toArray()); + $this->assertEquals(10000, $draft->payment); + $this->assertEquals(7000, $draft->getTotal()); + $this->assertEquals(3000, $draft->getExchange()); + $this->assertEquals([ + 'name' => 'Nafies', + 'phone' => '081234567890', + ], $draft->customer); + $this->assertEquals('Catatan', $draft->notes); } }