Browse Source

Fixed invalid item subtotal in draft item list

pull/3/head
Nafies Luthfi 9 years ago
parent
commit
4062610f15
  1. 1
      app/Cart/Item.php
  2. 4
      app/Cart/TransactionDraft.php
  3. 12
      resources/views/cart/partials/draft-confirm.blade.php
  4. 1
      tests/Feature/TransactionEntryTest.php
  5. 29
      tests/Unit/Integration/TransactionDraftTest.php

1
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;
}
}

4
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()

12
resources/views/cart/partials/draft-confirm.blade.php

@ -8,9 +8,9 @@
<tr>
<th>#</th>
<th>Nama Item</th>
<th>Harga Satuan</th>
<th>Diskon per Item</th>
<th>Qty</th>
<th class="text-right">Harga Satuan</th>
<th class="text-right">Diskon per Item</th>
<th class="text-center">Qty</th>
<th class="text-right">Subtotal</th>
</tr>
</thead>
@ -19,9 +19,9 @@
<tr>
<td>{{ $key + 1 }}</td>
<td>{{ $item->name }}</td>
<td>{{ formatRp($item->price) }}</td>
<td>{{ formatRp($item->item_discount) }}</td>
<td>{{ $item->qty }}</td>
<td class="text-right">{{ formatRp($item->price) }}</td>
<td class="text-right">{{ formatRp($item->item_discount) }}</td>
<td class="text-center">{{ $item->qty }}</td>
<td class="text-right">{{ formatRp($item->subtotal) }}</td>
</tr>
@empty

1
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']);
}
}

29
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);
}
}
Loading…
Cancel
Save