Browse Source

Added product unit name to cart

pull/4/head
Nafies Luthfi 9 years ago
parent
commit
ec1e2d9a71
  1. 2
      app/Cart/Item.php
  2. 2
      app/Http/Controllers/CartController.php
  3. 4
      app/Http/Controllers/ProductsController.php
  4. 1
      resources/lang/id/product.php
  5. 26
      resources/views/cart/partials/draft-item-list.blade.php
  6. 12
      resources/views/cart/partials/product-search-result-box.blade.php
  7. 2
      resources/views/products/index.blade.php

2
app/Cart/Item.php

@ -12,6 +12,7 @@ class Item
public $id;
public $product;
public $name;
public $unit;
public $price;
public $qty;
public $item_discount = 0;
@ -22,6 +23,7 @@ class Item
{
$this->id = $product->id;
$this->name = $product->name;
$this->unit = $product->unit_id ? $product->unit->name : null;
$this->product = $product;
$this->qty = $qty;
$this->price = $product->getPrice();

2
app/Http/Controllers/CartController.php

@ -40,7 +40,7 @@ class CartController extends Controller
if ($query) {
$queriedProducts = Product::where(function ($q) use ($query) {
$q->where('name', 'like', '%'.$query.'%');
})->get();
})->with('unit')->get();
}
return view('cart.index', compact('draft', 'queriedProducts'));

4
app/Http/Controllers/ProductsController.php

@ -16,7 +16,9 @@ class ProductsController extends Controller
$query->where('name', 'like', '%' . $q . '%');
}
})
->orderBy('name')->paginate(25);
->orderBy('name')
->with('unit')
->paginate(25);
if (in_array($request->get('action'), ['edit','delete']) && $request->has('id'))
$editableProduct = Product::find($request->get('id'));

1
resources/lang/id/product.php

@ -8,6 +8,7 @@ return [
'not_found' => 'Produk tidak ditemukan',
'empty' => 'Belum ada Produk',
'price' => 'Harga',
'unit' => 'Satuan',
'back_to_index' => 'Kembali ke daftar Produk',
// Actions

26
resources/views/cart/partials/draft-item-list.blade.php

@ -5,15 +5,15 @@
</small>
</legend>
<div class="panel panel-default">
<div class="panel-body">
<div class="panel-body table-responsive">
<table class="table">
<thead>
<tr>
<th>#</th>
<th>Nama Item</th>
<th>Harga Satuan</th>
<th>Diskon per Item</th>
<th>Qty</th>
<th class="text-right">Diskon per Item</th>
<th class="text-center">Qty</th>
<th class="text-right">Subtotal</th>
<th class="text-center">Action</th>
</tr>
@ -22,15 +22,25 @@
@forelse($draft->items() as $key => $item)
<tr>
<td>{{ $key + 1 }}</td>
<td>{{ $item->name }}</td>
<td>
{{ $item->name }} <br>
<small class="text-primary">({{ $item->unit }})</small>
</td>
<td>{{ formatRp($item->price) }}</td>
{{ Form::open(['route' => ['cart.update-draft-item', $draft->draftKey], 'method' => 'patch']) }}
{{ Form::hidden('item_key', $key) }}
<td>
{{ Form::text('item_discount', $item->item_discount, ['id' => 'item_discount-' . $key, 'style' => 'width:80px;text-align:right']) }}
<td class="text-right">
{{ Form::text('item_discount', $item->item_discount, [
'id' => 'item_discount-' . $key,
'style' => 'width:80px;text-align:right']
) }}
</td>
<td>
{{ Form::number('qty', $item->qty, ['id' => 'qty-' . $key, 'style' => 'width:50px;text-align:center']) }}
<td class="text-center">
{{ Form::number('qty', $item->qty, [
'id' => 'qty-' . $key,
'style' => 'width:50px;text-align:center',
'min' => 1
]) }}
</td>
<td class="text-right">{{ formatRp($item->subtotal) }}</td>
{{ Form::submit('update-item-' . $key, ['style'=>'display:none']) }}

12
resources/views/cart/partials/product-search-result-box.blade.php

@ -1,21 +1,23 @@
<div class="panel-body">
<div class="panel-body table-responsive">
<table class="table table-condensed">
<thead>
<tr>
<th>Produk</th>
<th>Harga Satuan ({{ $draft->type }})</th>
<th>Action</th>
<th>{{ trans('product.name') }}</th>
<th>{{ trans('product.unit') }}</th>
<th>{{ trans('product.price') }} ({{ $draft->type }})</th>
<th>{{ trans('app.action') }}</th>
</tr>
</thead>
<tbody>
@forelse($queriedProducts as $product)
<tr>
<td>{{ $product->name }}</td>
<td>{{ $product->unit->name }}</td>
<td>{{ formatRp($draft->type == 'cash' ? $product->cash_price : $product->credit_price) }}</td>
<td>
<form action="{{ route('cart.add-draft-item', [$draft->draftKey, $product->id]) }}" method="post" style="display:inline">
{{ csrf_field() }}
<input type="number" id="qty-{{ $product->id }}" style="width:50px" name="qty" value="1">
<input type="number" id="qty-{{ $product->id }}" style="width:50px" name="qty" value="1" min="1">
<input type="submit" id="add-product-{{ $product->id }}" value="Tambah">
</form>
</td>

2
resources/views/products/index.blade.php

@ -20,6 +20,7 @@
<tr>
<th class="text-center">{{ trans('app.table_no') }}</th>
<th>{{ trans('product.name') }}</th>
<th>{{ trans('product.unit') }}</th>
<th class="text-right">{{ trans('product.cash_price') }}</th>
<th class="text-right">{{ trans('product.credit_price') }}</th>
<th class="text-center">{{ trans('app.action') }}</th>
@ -31,6 +32,7 @@
<tr>
<td class="text-center">{{ $products->firstItem() + $key }}</td>
<td>{{ $product->name }}</td>
<td>{{ $product->unit->name }}</td>
<td class="text-right">{{ formatRp($product->cash_price) }}</td>
<td class="text-right">{{ formatRp($product->credit_price) }}</td>
<td class="text-center">

Loading…
Cancel
Save