From e5b21c64effd93d2be6ec1a4f2a8adab9ca0ff40 Mon Sep 17 00:00:00 2001 From: Nafies Luthfi Date: Wed, 19 Apr 2017 20:47:10 +0800 Subject: [PATCH] Fixed CreditDraft item has credit product price --- app/Cart/CartCollection.php | 7 ++++++ composer.json | 2 +- composer.lock | 16 ++++++------- resources/lang/id/cart.php | 1 + resources/lang/id/transaction.php | 10 ++++++++ resources/views/cart/index.blade.php | 39 +++++++++++++++++-------------- resources/views/layouts/app.blade.php | 9 +------ routes/web.php | 2 +- tests/Feature/Cart/CartControllerTest.php | 28 ++++++++++++++++++++-- tests/Feature/TransactionEntryTest.php | 2 +- 10 files changed, 77 insertions(+), 39 deletions(-) create mode 100644 resources/lang/id/transaction.php diff --git a/app/Cart/CartCollection.php b/app/Cart/CartCollection.php index 4714561..2723606 100644 --- a/app/Cart/CartCollection.php +++ b/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); diff --git a/composer.json b/composer.json index 725eb97..7202b25 100644 --- a/composer.json +++ b/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", diff --git a/composer.lock b/composer.lock index 5469957..9e7c1f5 100644 --- a/composer.lock +++ b/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": { diff --git a/resources/lang/id/cart.php b/resources/lang/id/cart.php index 19bd903..e1162ea 100644 --- a/resources/lang/id/cart.php +++ b/resources/lang/id/cart.php @@ -1,5 +1,6 @@ 'Cari Produk' ]; \ No newline at end of file diff --git a/resources/lang/id/transaction.php b/resources/lang/id/transaction.php new file mode 100644 index 0000000..dce4d33 --- /dev/null +++ b/resources/lang/id/transaction.php @@ -0,0 +1,10 @@ + 'Buat Transaksi', + 'create_cash' => 'Buat Transaksi Tunai', + 'create_credit' => 'Buat Transaksi Kredit', + 'cash' => 'Tunai', + 'credit' => 'Kredit', +]; \ No newline at end of file diff --git a/resources/views/cart/index.blade.php b/resources/views/cart/index.blade.php index 28ca51f..6c13867 100644 --- a/resources/views/cart/index.blade.php +++ b/resources/views/cart/index.blade.php @@ -9,7 +9,7 @@ draftKey == $key) ? 'class=active' : '' ?>
  • - {{ $content->type }} - {{ $key }} + {{ trans('transaction.' . $content->type) }} - {{ $key }}
    {{ csrf_field() }} {{ method_field('delete') }} @@ -67,7 +67,6 @@ @endif
    -

    Items

    @@ -75,36 +74,42 @@ - + + @forelse($draft->items() as $key => $item) - {!! Form::open(['route' => ['cart.update-draft-item', $draft->draftKey], 'method' => 'patch']) !!} - - - - {!! Form::close() !!} + + @empty @endforelse +
    Nama Item Harga Satuan QtyDiskonDiskon per Item Subtotal Action
    {{ $key + 1 }} {{ $item->name }} {{ formatRp($item->price) }}{!! FormField::text('qty', ['value' => $item->qty, 'id' => 'qty-' . $key, 'style' => 'width:50px', 'label' => false]) !!}{{ Form::text('item_discount', $item->item_discount, ['id' => 'item_discount-' . $key]) }} + {{ 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() }} + + {{ 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() }} + {{ formatRp($item->subtotal) }} - - {{ csrf_field() }} {{ method_field('delete') }} - - - + {!! 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]) !!}
    @endif diff --git a/resources/views/layouts/app.blade.php b/resources/views/layouts/app.blade.php index 1874855..5731cca 100644 --- a/resources/views/layouts/app.blade.php +++ b/resources/views/layouts/app.blade.php @@ -41,13 +41,6 @@