diff --git a/app/Cart/CashDraft.php b/app/Cart/CashDraft.php
index 2d774f5..807cfad 100644
--- a/app/Cart/CashDraft.php
+++ b/app/Cart/CashDraft.php
@@ -8,4 +8,6 @@ namespace App\Cart;
class CashDraft extends TransactionDraft
{
public $draftKey;
+ public $type = 'cash';
+ public $type_id = 1;
}
\ No newline at end of file
diff --git a/app/Cart/CreditDraft.php b/app/Cart/CreditDraft.php
index 7777af6..8c516b1 100644
--- a/app/Cart/CreditDraft.php
+++ b/app/Cart/CreditDraft.php
@@ -8,4 +8,6 @@ namespace App\Cart;
class CreditDraft extends TransactionDraft
{
public $draftKey;
+ public $type = 'credit';
+ public $type_id = 2;
}
\ No newline at end of file
diff --git a/app/Http/Controllers/CartController.php b/app/Http/Controllers/CartController.php
index f109e5e..0534f52 100644
--- a/app/Http/Controllers/CartController.php
+++ b/app/Http/Controllers/CartController.php
@@ -17,14 +17,33 @@ class CartController extends Controller
{
$this->cart = new CartCollection;
}
- public function add(Request $request, $type)
+
+ public function index(Request $request)
+ {
+ $draft = $this->cart->content()->last();
+
+ return view('cart.index', compact('draft'));
+ }
+
+ public function show(Request $request, $draftKey)
{
- if ($type == 1)
+ $queriedProducts = Product::where(function($query) use ($request) {
+ return $query->where('name', 'like', '%' . $request->get('query') . '%');
+ })->get();
+
+ $draft = $this->cart->get($draftKey);
+
+ return view('cart.index', compact('draft','queriedProducts'));
+ }
+
+ public function add(Request $request)
+ {
+ if ($request->has('create-cash-draft'))
$this->cart->add(new CashDraft);
else
$this->cart->add(new CreditDraft);
- return redirect()->route('cart.index', $item->draftKey);
+ return redirect()->route('cart.show', $this->cart->content()->last()->draftKey);
}
public function addDraftItem(Request $request, $draftKey, Product $product)
diff --git a/resources/views/cart/index.blade.php b/resources/views/cart/index.blade.php
new file mode 100644
index 0000000..922f0cb
--- /dev/null
+++ b/resources/views/cart/index.blade.php
@@ -0,0 +1,41 @@
+@extends('layouts.app')
+
+@section('content')
+
+
+
+@if (! CartCollection::isEmpty())
+
+
+@endif
+@if ($draft)
+ {{ $draft ? $draft->type : '' }}
+
+ @if (isset($queriedProducts))
+
+ @foreach($queriedProducts as $product)
+ - {{ $product->name }}
+ - {{ $draft->type == 'cash' ? $product->cash_price : $product->credit_price }}
+ @endforeach
+
+ @endif
+@endif
+@endsection
\ No newline at end of file
diff --git a/resources/views/layouts/app.blade.php b/resources/views/layouts/app.blade.php
index 5ec5531..1874855 100644
--- a/resources/views/layouts/app.blade.php
+++ b/resources/views/layouts/app.blade.php
@@ -42,14 +42,23 @@
+ @if (Auth::check())
+ @endif
- @yield('content')
+
+ @yield('content')
+
diff --git a/routes/web.php b/routes/web.php
index ab58f6c..17e03b9 100644
--- a/routes/web.php
+++ b/routes/web.php
@@ -18,10 +18,14 @@ Route::get('/', function () {
Auth::routes();
Route::get('/home', 'HomeController@index')->name('home');
-Route::post('cart/add-draft/{product}', 'CartController@add')->name('cart.add');
-Route::post('cart/add-draft-item/{draftKey}/{product}', 'CartController@addDraftItem')->name('cart.add-draft-item');
-Route::patch('cart/update-draft-item/{draftKey}', 'CartController@updateDraftItem')->name('cart.update-draft-item');
-Route::delete('cart/remove-draft-item/{draftKey}', 'CartController@removeDraftItem')->name('cart.remove-draft-item');
-Route::delete('cart/empty/{draftKey}', 'CartController@empty')->name('cart.empty');
-Route::delete('cart/remove', 'CartController@remove')->name('cart.remove');
-Route::delete('cart/destroy', 'CartController@destroy')->name('cart.destroy');
+Route::group(['middleware' => 'auth'], function() {
+ Route::get('drafts', 'CartController@index')->name('cart.index');
+ Route::get('drafts/{draftKey}', 'CartController@show')->name('cart.show');
+ Route::post('cart/add-draft', 'CartController@add')->name('cart.add');
+ Route::post('cart/add-draft-item/{draftKey}/{product}', 'CartController@addDraftItem')->name('cart.add-draft-item');
+ Route::patch('cart/update-draft-item/{draftKey}', 'CartController@updateDraftItem')->name('cart.update-draft-item');
+ Route::delete('cart/remove-draft-item/{draftKey}', 'CartController@removeDraftItem')->name('cart.remove-draft-item');
+ Route::delete('cart/empty/{draftKey}', 'CartController@empty')->name('cart.empty');
+ Route::delete('cart/remove', 'CartController@remove')->name('cart.remove');
+ Route::delete('cart/destroy', 'CartController@destroy')->name('cart.destroy');
+});
\ No newline at end of file
diff --git a/tests/BrowserKitTestCase.php b/tests/BrowserKitTestCase.php
index 6e39516..92a33d9 100644
--- a/tests/BrowserKitTestCase.php
+++ b/tests/BrowserKitTestCase.php
@@ -2,9 +2,19 @@
namespace Tests;
+use App\User;
+
abstract class BrowserKitTestCase extends \Laravel\BrowserKitTesting\TestCase
{
use CreatesApplication;
protected $baseUrl = 'http://localhost';
+
+ protected function loginAsUser()
+ {
+ $user = factory(User::class)->create();
+ $this->actingAs($user);
+
+ return $user;
+ }
}
diff --git a/tests/Feature/Cart/CartControllerTest.php b/tests/Feature/Cart/CartControllerTest.php
index 22f6e31..d515f38 100644
--- a/tests/Feature/Cart/CartControllerTest.php
+++ b/tests/Feature/Cart/CartControllerTest.php
@@ -21,8 +21,8 @@ class CartControllerTest extends TestCase
$cart = new CartCollection;
- $response = $this->post(route('cart.add', 1));
- $response = $this->post(route('cart.add', 2));
+ $response = $this->post(route('cart.add'), ['create-cash-draft'=> trans('transaction.create')]);
+ $response = $this->post(route('cart.add'), ['create-credit-draft'=> trans('transaction.create_credit')]);
$response->assertSessionHas('transactions.drafts');
$cashDraft = $cart->content()->first();
diff --git a/tests/Feature/TransactionEntryTest.php b/tests/Feature/TransactionEntryTest.php
new file mode 100644
index 0000000..d25f469
--- /dev/null
+++ b/tests/Feature/TransactionEntryTest.php
@@ -0,0 +1,72 @@
+loginAsUser();
+
+ // Add new draft to collection
+ $cart = new CartCollection;
+ $draft = $cart->add(new CashDraft);
+
+ $this->visit(route('cart.index'));
+
+ $this->assertViewHas('draft', $draft);
+ $this->see($draft->type);
+ }
+
+ /** @test */
+ public function user_can_create_transaction_draft_by_transaction_create_button()
+ {
+ $this->loginAsUser();
+ $this->visit(route('home'));
+
+ $this->press(trans('transaction.create'));
+ $cart = new CartCollection;
+ $draft = $cart->content()->last();
+ $this->seePageIs(route('cart.show', $draft->draftKey));
+
+ $this->press(trans('transaction.create_credit'));
+ $cart = new CartCollection;
+ $draft = $cart->content()->last();
+ $this->seePageIs(route('cart.show', $draft->draftKey));
+ }
+
+ /** @test */
+ public function user_can_search_product_on_transaction_draft_page()
+ {
+ $product = factory(Product::class)->create(['name' => 'Testing Produk 1']);
+ $this->loginAsUser();
+
+ $cart = new CartCollection;
+ $draft = new CreditDraft;
+ $cart->add($draft);
+
+ // Visit cart index page
+ $this->visit(route('cart.index'));
+
+ // Visit search for products
+ $this->submitForm(trans('product.search'), [
+ 'query' => 'testing',
+ ]);
+
+ $this->seePageIs(route('cart.show', [$draft->draftKey, 'query' => 'testing']));
+ // See product list appears
+ $this->see($product->name);
+ $this->see($product->credit_price);
+ $this->dontSee($product->cash_price);
+ }
+}