Browse Source

Added Transaction Confirm page

pull/3/head
Nafies Luthfi 9 years ago
parent
commit
0c45b9a44f
  1. 10
      app/Cart/Item.php
  2. 11
      app/Cart/TransactionDraft.php
  3. 6
      app/Http/Controllers/CartController.php
  4. 37
      resources/lang/id/app.php
  5. 28
      resources/lang/id/transaction.php
  6. 13
      resources/views/cart/index.blade.php
  7. 73
      resources/views/cart/partials/draft-confirm.blade.php
  8. 9
      resources/views/cart/partials/draft-item-list.blade.php
  9. 10
      resources/views/cart/partials/form-draft-detail.blade.php
  10. 1
      routes/web.php
  11. 32
      tests/Feature/TransactionEntryTest.php
  12. 28
      tests/Unit/Integration/TransactionDraftTest.php

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;
}

11
app/Cart/TransactionDraft.php

@ -11,12 +11,16 @@ abstract class TransactionDraft
{
public $items = [];
public $customer = ['name' => null, 'phone' => null];
public $notes;
public $payment;
public function toArray()
{
return [
'invoice_no' => 2,
'date' => 1,
'items' => [],
'items' => $this->items(),
'total' => 0,
'payment' => 0,
'customer' => 0,
@ -87,4 +91,9 @@ abstract class TransactionDraft
return $productItem;
}
public function getExchange()
{
return $this->payment - $this->getTotal();
}
}

6
app/Http/Controllers/CartController.php

@ -94,4 +94,10 @@ class CartController extends Controller
return redirect()->route('cart.index');
}
public function proccess(Request $request, $draftKey)
{
$this->cart->updateDraftAttributes($draftKey, $request->only('customer','notes','payment'));
return redirect()->route('cart.show', [$draftKey, 'action' => 'confirm']);
}
}

37
resources/lang/id/app.php

@ -0,0 +1,37 @@
<?php
return [
// Labels
'table_no' => '#',
'name' => 'Nama',
'submit' => 'Submit',
'update' => 'Update',
'delete' => 'Hapus',
'add' => 'Tambah',
'back' => 'Kembali',
'cancel' => 'Batal',
'reset' => 'Reset',
'show' => 'Lihat Detail',
'label' => 'Label',
'edit' => 'Edit',
'print' => 'Print',
'search' => 'Cari',
'filter' => 'Filter',
'close' => 'Tutup',
'action' => 'Action',
'notes' => 'Catatan',
'delete_confirm_button' => 'Ya, silakan hapus!',
'delete_confirm' => 'Anda yakin akan menghapus?',
'description' => 'Deskripsi',
'code' => 'Kode',
'active' => 'Status',
'status' => 'Status',
'date' => 'Tanggal',
'time' => 'Waktu',
'created_at' => 'Dibuat Pada',
'created_by' => 'Oleh',
'total' => 'Total',
'count' => 'Jumlah',
'welcome' => 'Selamat datang',
'export-pdf' => 'Export PDF',
];

28
resources/lang/id/transaction.php

@ -2,9 +2,27 @@
return [
// Labels
'create' => 'Buat Transaksi',
'create_cash' => 'Buat Transaksi Tunai',
'create_credit' => 'Buat Transaksi Kredit',
'cash' => 'Tunai',
'credit' => 'Kredit',
'create' => 'Buat Transaksi',
'create_cash' => 'Buat Transaksi Tunai',
'create_credit' => 'Buat Transaksi Kredit',
'cash' => 'Tunai',
'credit' => 'Kredit',
'detail' => 'Detail Transaksi',
'confirm' => 'Konfirmasi Transaksi',
'items' => 'Barang Belanja',
'subtotal' => 'Subtotal',
'discount_total' => 'Total Diskon',
'total' => 'Total',
'exchange' => 'Kembalian',
// Actions
'proccess' => 'Proses Transaksi',
'save' => 'Simpan Transaksi',
// Attributes
'customer' => 'Customer',
'customer_name' => 'Nama Customer',
'customer_phone' => 'Hp/Telp.',
'payment' => 'Jumlah Dibayar',
'notes' => 'Catatan Transaksi',
];

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

@ -5,9 +5,16 @@
@section('content')
<?php use Facades\App\Cart\CartCollection; ?>
@includeWhen (! CartCollection::isEmpty(), 'cart.partials.transaction-draft-tabs')
@includeWhen(! CartCollection::isEmpty(), 'cart.partials.transaction-draft-tabs')
@if ($draft)
@include ('cart.partials.product-search-box')
@include('cart.partials.draft-item-list')
@if (Request::get('action') == 'confirm')
@include('cart.partials.draft-confirm')
@else
@include('cart.partials.product-search-box')
<div class="row">
<div class="col-md-9">@include('cart.partials.draft-item-list')</div>
<div class="col-md-3">@include('cart.partials.form-draft-detail')</div>
</div>
@endif
@endif
@endsection

73
resources/views/cart/partials/draft-confirm.blade.php

@ -0,0 +1,73 @@
<div class="row">
<div class="col-md-8">
<div class="panel panel-default">
<div class="panel-heading"><h3 class="panel-title">{{ trans('transaction.confirm') }}</h3></div>
<div class="panel-body">
<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">Subtotal</th>
</tr>
</thead>
<tbody>
@forelse($draft->items() as $key => $item)
<tr>
<td>{{ $key + 1 }}</td>
<td>{{ $item->name }}</td>
<td>{{ formatRp($item->price) }}</td>
<td>{{ formatRp($item->item_discount) }}</td>
<td>{{ $item->qty }}</td>
<td class="text-right">{{ formatRp($item->subtotal) }}</td>
</tr>
@empty
@endforelse
</tbody>
<tfoot>
<tr>
<th colspan="5" class="text-right">{{ trans('transaction.subtotal') }} :</th>
<th class="text-right">{{ formatRp($draft->getSubtotal()) }}</th>
</tr>
<tr>
<th colspan="5" class="text-right">{{ trans('transaction.discount_total') }} :</th>
<th class="text-right">{{ formatRp($draft->getDiscountTotal()) }}</th>
</tr>
<tr>
<th colspan="5" class="text-right">{{ trans('transaction.total') }} :</th>
<th class="text-right">{{ formatRp($draft->getTotal()) }}</th>
</tr>
</tfoot>
</table>
</div>
</div>
</div>
<div class="col-md-4">
<div class="panel panel-default">
<div class="panel-heading"><h3 class="panel-title">{{ trans('transaction.detail') }}</h3></div>
<div class="panel-body">
<table class="table table-condensed">
<tbody>
<tr><td>{{ trans('transaction.customer_name') }}</td><td>{{ $draft->customer['name'] }}</td></tr>
<tr><td>{{ trans('transaction.customer_phone') }}</td><td>{{ $draft->customer['phone'] }}</td></tr>
<tr><td>{{ trans('transaction.payment') }}</td><th class="text-right">{{ formatRp($draft->payment) }}</th></tr>
<tr><td>{{ trans('transaction.total') }}</td><th class="text-right">{{ formatRp($draft->getTotal()) }}</th></tr>
<tr><td>{{ trans('transaction.exchange') }}</td><th class="text-right">{{ formatRp($draft->getExchange()) }}</th></tr>
<tr><td>{{ trans('transaction.notes') }}</td><td>{{ $draft->notes }}</td></tr>
</tbody>
</table>
</div>
<div class="panel-footer">
{{ Form::open() }}
{{ Form::submit(trans('transaction.save'), ['id' => 'save-transaction-draft', 'class' => 'btn btn-success']) }}
{{ link_to_route('cart.show', trans('app.back'), $draft->draftKey, ['class' => 'btn btn-default']) }}
{{ Form::close() }}
</div>
</div>
</div>
</div>

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

@ -1,3 +1,4 @@
<legend>{{ trans('transaction.items') }} <small class="text-muted">({{ $draft->items()->count() }} Item)</small></legend>
<div class="panel panel-default">
<div class="panel-body">
<table class="table">
@ -21,7 +22,7 @@
{{ 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:100px;text-align: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']) }}
@ -42,17 +43,17 @@
</tbody>
<tfoot>
<tr>
<th colspan="5" class="text-right">Subtotal :</th>
<th colspan="5" class="text-right">{{ trans('transaction.subtotal') }} :</th>
<th class="text-right">{{ formatRp($draft->getSubtotal()) }}</th>
<th></th>
</tr>
<tr>
<th colspan="5" class="text-right">Diskon Total :</th>
<th colspan="5" class="text-right">{{ trans('transaction.discount_total') }} :</th>
<th class="text-right">{{ formatRp($draft->getDiscountTotal()) }}</th>
<th></th>
</tr>
<tr>
<th colspan="5" class="text-right">Total :</th>
<th colspan="5" class="text-right">{{ trans('transaction.total') }} :</th>
<th class="text-right">{{ formatRp($draft->getTotal()) }}</th>
<th></th>
</tr>

10
resources/views/cart/partials/form-draft-detail.blade.php

@ -0,0 +1,10 @@
<legend>{{ trans('transaction.detail') }}</legend>
{{ Form::open(['route' => ['cart.draft-proccess', $draft->draftKey], 'method' => 'patch']) }}
{!! FormField::text('customer[name]', ['label' => trans('transaction.customer_name'), 'value' => $draft->customer['name']]) !!}
<div class="row">
<div class="col-md-6">{!! FormField::text('customer[phone]', ['label' => trans('transaction.customer_phone'), 'value' => $draft->customer['phone']]) !!}</div>
<div class="col-md-6">{!! FormField::price('payment', ['label' => trans('transaction.payment'), 'value' => $draft->payment]) !!}</div>
</div>
{!! FormField::textarea('notes', ['label' => trans('transaction.notes'), 'value' => $draft->notes]) !!}
{{ Form::submit(trans('transaction.proccess'), ['class' => 'btn btn-info']) }}
{{ Form::close() }}

1
routes/web.php

@ -24,6 +24,7 @@ Route::group(['middleware' => 'auth'], function () {
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::patch('cart/{draftKey}/proccess', 'CartController@proccess')->name('cart.draft-proccess');
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');

32
tests/Feature/TransactionEntryTest.php

@ -166,4 +166,36 @@ class TransactionEntryTest extends BrowserKitTestCase
$this->see(formatRp($draft->getSubtotal()));
$this->see(formatRp($draft->getTotal()));
}
/** @test */
public function user_can_update_draft_transaction_detail_and_get_confirm_page()
{
$cart = new CartCollection();
$draft = $cart->add(new CashDraft());
$product1 = factory(Product::class)->create(['cash_price' => 1000]);
$product2 = factory(Product::class)->create(['cash_price' => 2000]);
$item1 = new Item($product1, 1);
$item2 = new Item($product2, 3);
// Add items to draft
$cart->addItemToDraft($draft->draftKey, $item1);
$cart->addItemToDraft($draft->draftKey, $item2);
$this->loginAsUser();
$this->visit(route('cart.show', $draft->draftKey));
$this->type('Nafies', 'customer[name]');
$this->type('-', 'customer[phone]');
$this->type('catatan', 'notes');
$this->type(10000, 'payment');
$this->press(trans('transaction.proccess'));
$this->seePageIs(route('cart.show', [$draft->draftKey, 'action' => 'confirm']));
$this->see(trans('transaction.confirm'));
$this->see(formatRp(10000));
$this->seeElement('input', ['id' => 'save-transaction-draft']);
}
}

28
tests/Unit/Integration/TransactionDraftTest.php

@ -139,4 +139,32 @@ class TransactionDraftTest extends TestCase
$this->assertEquals(7000, $draft->getSubtotal());
$this->assertEquals(6700, $draft->getTotal());
}
/** @test */
public function transaction_draft_has_detail()
{
// TODO: check corrent draft attributes
$cart = new CartCollection();
$draft = $cart->add(new CashDraft());
$draftAttributes = [
'customer' => [
'name' => 'Nafies',
'phone' => '081234567890',
],
'payment' => 10000,
'notes' => 'Catatan',
];
$cart->updateDraftAttributes($draft->draftKey, $draftAttributes);
$this->assertArrayHasKey('invoice_no', $draft->toArray());
$this->assertArrayHasKey('date', $draft->toArray());
$this->assertArrayHasKey('items', $draft->toArray());
$this->assertArrayHasKey('total', $draft->toArray());
$this->assertArrayHasKey('payment', $draft->toArray());
$this->assertArrayHasKey('customer', $draft->toArray());
$this->assertArrayHasKey('status_id', $draft->toArray());
$this->assertArrayHasKey('creator_id', $draft->toArray());
$this->assertArrayHasKey('remark', $draft->toArray());
}
}
Loading…
Cancel
Save