Browse Source

Merge pull request #2 from nafiesl/analysis-qypyZN

Apply fixes from StyleCI
pull/3/head
Nafies Luthfi 9 years ago
committed by GitHub
parent
commit
fe975ce27a
  1. 2
      app/Cart/CartCollection.php
  2. 10
      app/Cart/Item.php
  3. 1
      app/Cart/TransactionDraft.php
  4. 9
      app/Helpers/helpers.php
  5. 2
      app/Http/Controllers/CartController.php
  6. 2
      app/Providers/AppServiceProvider.php
  7. 2
      resources/lang/id/cart.php
  8. 8
      resources/lang/id/transaction.php
  9. 14
      tests/Feature/TransactionEntryTest.php

2
app/Cart/CartCollection.php

@ -122,7 +122,7 @@ class CartCollection
{
$item = $draft->search($product);
return ! is_null($item);
return !is_null($item);
}
public function updateDraftItem($draftKey, $itemKey, $newItemData)

10
app/Cart/Item.php

@ -20,11 +20,11 @@ class Item
public function __construct(Product $product, $qty)
{
$this->id = $product->id;
$this->name = $product->name;
$this->product = $product;
$this->qty = $qty;
$this->price = $product->getPrice();
$this->id = $product->id;
$this->name = $product->name;
$this->product = $product;
$this->qty = $qty;
$this->price = $product->getPrice();
$this->subtotal = $product->getPrice() * $qty;
}

1
app/Cart/TransactionDraft.php

@ -79,6 +79,7 @@ abstract class TransactionDraft
public function search(Product $product)
{
$productItem = $this->items()->where('id', $product->id)->first();
return $productItem;
}
}

9
app/Helpers/helpers.php

@ -2,11 +2,14 @@
function formatNo($number)
{
return number_format($number, 0,',','.');
return number_format($number, 0, ',', '.');
}
function formatRp($number)
{
if ($number == 0) { return '-'; }
return 'Rp. ' . formatNo($number);
if ($number == 0) {
return '-';
}
return 'Rp. '.formatNo($number);
}

2
app/Http/Controllers/CartController.php

@ -23,7 +23,7 @@ class CartController extends Controller
$queriedProducts = [];
$draft = $this->cart->content()->first();
return view('cart.index', compact('draft','queriedProducts'));
return view('cart.index', compact('draft', 'queriedProducts'));
}
public function show(Request $request, $draftKey)

2
app/Providers/AppServiceProvider.php

@ -13,7 +13,7 @@ class AppServiceProvider extends ServiceProvider
*/
public function boot()
{
require_once app_path() . '/Helpers/helpers.php';
require_once app_path().'/Helpers/helpers.php';
}
/**

2
resources/lang/id/cart.php

@ -2,5 +2,5 @@
return [
// Labels
'product_search' => 'Cari Produk'
'product_search' => 'Cari Produk',
];

8
resources/lang/id/transaction.php

@ -2,9 +2,9 @@
return [
// Labels
'create' => 'Buat Transaksi',
'create_cash' => 'Buat Transaksi Tunai',
'create' => 'Buat Transaksi',
'create_cash' => 'Buat Transaksi Tunai',
'create_credit' => 'Buat Transaksi Kredit',
'cash' => 'Tunai',
'credit' => 'Kredit',
'cash' => 'Tunai',
'credit' => 'Kredit',
];

14
tests/Feature/TransactionEntryTest.php

@ -68,15 +68,15 @@ class TransactionEntryTest extends BrowserKitTestCase
$this->see($product->name);
$this->see($product->credit_price);
$this->seeElement('form', ['action' => route('cart.add-draft-item', [$draft->draftKey, $product->id])]);
$this->seeElement('input', ['id' => 'qty-' . $product->id, 'name' => 'qty']);
$this->seeElement('input', ['id' => 'add-product-' . $product->id]);
$this->seeElement('input', ['id' => 'qty-'.$product->id, 'name' => 'qty']);
$this->seeElement('input', ['id' => 'add-product-'.$product->id]);
$this->dontSee($product->cash_price);
}
/** @test */
public function user_can_add_item_to_draft()
{
$product = factory(Product::class)->create(['name' => 'Testing Produk 1','cash_price' => 400,'credit_price' => 500]);
$product = factory(Product::class)->create(['name' => 'Testing Produk 1', 'cash_price' => 400, 'credit_price' => 500]);
$this->loginAsUser();
$cart = new CartCollection();
@ -87,14 +87,14 @@ class TransactionEntryTest extends BrowserKitTestCase
$this->visit(route('cart.show', [$draft->draftKey, 'query' => 'testing']));
$this->type(2, 'qty');
$this->press('add-product-' . $product->id);
$this->press('add-product-'.$product->id);
$this->seePageIs(route('cart.show', [$draft->draftKey, 'query' => 'testing']));
$this->assertTrue($cart->draftHasItem($draft, $product));
$this->assertEquals(800, $draft->getTotal());
$this->see(formatRp(800));
$this->seeElement('input', ['id' => 'qty-' . 0]);
$this->seeElement('input', ['id' => 'item_discount-' . 0]);
$this->seeElement('button', ['id' => 'remove-item-' . 0]);
$this->seeElement('input', ['id' => 'qty-'. 0]);
$this->seeElement('input', ['id' => 'item_discount-'. 0]);
$this->seeElement('button', ['id' => 'remove-item-'. 0]);
}
}
Loading…
Cancel
Save