Browse Source

Fixed CreditDraft item has credit product price

pull/2/head
Nafies Luthfi 9 years ago
parent
commit
e5b21c64ef
  1. 7
      app/Cart/CartCollection.php
  2. 2
      composer.json
  3. 16
      composer.lock
  4. 1
      resources/lang/id/cart.php
  5. 10
      resources/lang/id/transaction.php
  6. 39
      resources/views/cart/index.blade.php
  7. 9
      resources/views/layouts/app.blade.php
  8. 2
      routes/web.php
  9. 28
      tests/Feature/Cart/CartControllerTest.php
  10. 2
      tests/Feature/TransactionEntryTest.php

7
app/Cart/CartCollection.php

@ -104,6 +104,13 @@ class CartCollection
public function addItemToDraft($draftKey, Item $item)
{
$content = $this->getContent();
$draft = $content[$draftKey];
if ($draft->type == 'credit') {
$item->price = $item->product->getPrice('credit');
$item->subtotal = $item->product->getPrice('credit') * $item->qty;
}
$content[$draftKey]->addItem($item);
$this->session->put($this->instance, $content);

2
composer.json

@ -8,7 +8,7 @@
"php": ">=5.6.4",
"laravel/browser-kit-testing": "^1.0",
"laravel/framework": "5.4.*",
"luthfi/formfield": "dev-master"
"luthfi/formfield": "^0.1.3"
},
"require-dev": {
"fzaninotto/faker": "~1.4",

16
composer.lock

@ -4,7 +4,7 @@
"Read more about it at https://getcomposer.org/doc/01-basic-usage.md#composer-lock-the-lock-file",
"This file is @generated automatically"
],
"content-hash": "368165fbcebe846c9c2075a5c891d081",
"content-hash": "360ad09108ebcf2e18cdc61e59e298d9",
"packages": [
{
"name": "doctrine/inflector",
@ -430,16 +430,16 @@
},
{
"name": "luthfi/formfield",
"version": "dev-master",
"version": "0.1.3",
"source": {
"type": "git",
"url": "https://github.com/nafiesl/FormField.git",
"reference": "1042513145c227eaf2325e7be83c8c193e1b3955"
"reference": "2f6222d1f72562d102811bc5a0e584b4b78f86b6"
},
"dist": {
"type": "zip",
"url": "https://api.github.com/repos/nafiesl/FormField/zipball/1042513145c227eaf2325e7be83c8c193e1b3955",
"reference": "1042513145c227eaf2325e7be83c8c193e1b3955",
"url": "https://api.github.com/repos/nafiesl/FormField/zipball/2f6222d1f72562d102811bc5a0e584b4b78f86b6",
"reference": "2f6222d1f72562d102811bc5a0e584b4b78f86b6",
"shasum": ""
},
"require": {
@ -466,7 +466,7 @@
}
],
"description": "Form Field helper class for Laravel 5.3 with Twitter Bootstrap",
"time": "2017-04-18 15:38:34"
"time": "2017-04-19T04:09:24+00:00"
},
{
"name": "monolog/monolog",
@ -3233,9 +3233,7 @@
],
"aliases": [],
"minimum-stability": "stable",
"stability-flags": {
"luthfi/formfield": 20
},
"stability-flags": [],
"prefer-stable": false,
"prefer-lowest": false,
"platform": {

1
resources/lang/id/cart.php

@ -1,5 +1,6 @@
<?php
return [
// Labels
'product_search' => 'Cari Produk'
];

10
resources/lang/id/transaction.php

@ -0,0 +1,10 @@
<?php
return [
// Labels
'create' => 'Buat Transaksi',
'create_cash' => 'Buat Transaksi Tunai',
'create_credit' => 'Buat Transaksi Kredit',
'cash' => 'Tunai',
'credit' => 'Kredit',
];

39
resources/views/cart/index.blade.php

@ -9,7 +9,7 @@
<?php $active = ($draft->draftKey == $key) ? 'class=active' : '' ?>
<li {{ $active }} role="presentation">
<a href="{{ route('cart.show', $key) }}">
{{ $content->type }} - {{ $key }}
{{ trans('transaction.' . $content->type) }} - {{ $key }}
<form action="{{ route('cart.remove') }}" method="post" style="display:inline" onsubmit="return confirm('Yakin ingin menghapus Draft Transaksi ini?')">
{{ csrf_field() }}
{{ method_field('delete') }}
@ -67,7 +67,6 @@
@endif
</div>
<div class="panel panel-default">
<div class="panel-heading"><h3 class="panel-title">Items</h3></div>
<table class="table">
<thead>
<tr>
@ -75,36 +74,42 @@
<th>Nama Item</th>
<th>Harga Satuan</th>
<th>Qty</th>
<th>Diskon</th>
<th>Diskon per Item</th>
<th>Subtotal</th>
<th>Action</th>
</tr>
</thead>
<tbody>
@forelse($draft->items() as $key => $item)
<tr>
<td>{{ $key + 1 }}</td>
<td>{{ $item->name }}</td>
<td>{{ formatRp($item->price) }}</td>
{!! Form::open(['route' => ['cart.update-draft-item', $draft->draftKey], 'method' => 'patch']) !!}
<input type="hidden" name="item_key" value="{{ $key }}">
<td>{!! FormField::text('qty', ['value' => $item->qty, 'id' => 'qty-' . $key, 'style' => 'width:50px', 'label' => false]) !!}</td>
<td>{{ Form::text('item_discount', $item->item_discount, ['id' => 'item_discount-' . $key]) }}</td>
{!! Form::close() !!}
<td>
{{ 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::close() }}
</td>
<td>
{{ 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::close() }}
</td>
<td>{{ formatRp($item->subtotal) }}</td>
<td>
<form
action="{{ route('cart.remove-draft-item', $draft->draftKey) }}"
method="post"
onsubmit="return confirm('Yakin ingin menghapus Item ini?')"
>
{{ csrf_field() }} {{ method_field('delete') }}
<input type="hidden" name="item_index" value="{{ $key }}">
<input type="submit" id="remove-item-{{ $key }}" value="x">
</form>
{!! FormField::delete([
'route' => ['cart.remove-draft-item', $draft->draftKey],
'onsubmit' => 'Yakin ingin menghapus Item ini?',
], 'x', ['id' => 'remove-item-' . $key, 'class' => 'btn btn-danger btn-xs'], ['item_index' => $key]) !!}
</td>
</tr>
@empty
@endforelse
</tbody>
</table>
</div>
@endif

9
resources/views/layouts/app.blade.php

@ -41,13 +41,6 @@
</div>
<div class="collapse navbar-collapse" id="app-navbar-collapse">
<!-- Left Side Of Navbar -->
@if (Auth::check())
<ul class="nav navbar-nav">
&nbsp;
</ul>
@endif
<!-- Right Side Of Navbar -->
<ul class="nav navbar-nav navbar-right">
<!-- Authentication Links -->
@ -55,7 +48,7 @@
<li>
<form class="" action="{{ route('cart.add') }}" method="POST">
{{ csrf_field() }}
<input type="submit" class="btn btn-default navbar-btn" name="create-cash-draft" id="cash-draft-create-button" value="{{ trans('transaction.create') }}">
<input type="submit" class="btn btn-default navbar-btn" name="create-cash-draft" id="cash-draft-create-button" value="{{ trans('transaction.create_cash') }}">
<input type="submit" class="btn btn-default navbar-btn" name="create-credit-draft" id="credit-draft-create-button" value="{{ trans('transaction.create_credit') }}">
</form>
</li>

2
routes/web.php

@ -17,7 +17,7 @@ Route::get('/', function () {
Auth::routes();
Route::get('/home', 'HomeController@index')->name('home');
Route::get('/home', 'CartController@index')->name('home');
Route::group(['middleware' => 'auth'], function () {
Route::get('drafts', 'CartController@index')->name('cart.index');
Route::get('drafts/{draftKey}', 'CartController@show')->name('cart.show');

28
tests/Feature/Cart/CartControllerTest.php

@ -21,7 +21,7 @@ class CartControllerTest extends TestCase
$cart = new CartCollection();
$response = $this->post(route('cart.add'), ['create-cash-draft'=> trans('transaction.create')]);
$response = $this->post(route('cart.add'), ['create-cash-draft'=> trans('transaction.create_cash')]);
$response = $this->post(route('cart.add'), ['create-credit-draft'=> trans('transaction.create_credit')]);
$response->assertSessionHas('transactions.drafts');
@ -33,7 +33,7 @@ class CartControllerTest extends TestCase
}
/** @test */
public function user_can_add_item_product_into_cart_draft()
public function user_can_add_item_product_into_cash_draft()
{
$this->loginAsUser();
@ -56,6 +56,30 @@ class CartControllerTest extends TestCase
}
/** @test */
public function user_can_add_item_product_into_credit_draft()
{
$this->loginAsUser();
$cart = new CartCollection();
$draft = new CreditDraft();
$cart->add($draft);
// Add Product to database
$product = factory(Product::class)->create(['cash_price' => 1100], ['credit_price' => 1000]);
$itemQty = 2;
// Add Product as CreditDraft item
$response = $this->post(route('cart.add-draft-item', [$draft->draftKey, $product->id]), [
'qty' => $itemQty,
]);
// $response->assertStatus(200);
$cashDraft = $cart->content()->first();
$this->assertTrue($cashDraft instanceof CreditDraft);
$this->assertEquals(2000, $cashDraft->getTotal());
}
/** @test */
public function user_can_remove_item_product_from_a_transaction_draft()
{
$this->loginAsUser();

2
tests/Feature/TransactionEntryTest.php

@ -95,6 +95,6 @@ class TransactionEntryTest extends BrowserKitTestCase
$this->see(formatRp(800));
$this->seeElement('input', ['id' => 'qty-' . 0]);
$this->seeElement('input', ['id' => 'item_discount-' . 0]);
$this->seeElement('input', ['id' => 'remove-item-' . 0]);
$this->seeElement('button', ['id' => 'remove-item-' . 0]);
}
}
Loading…
Cancel
Save