Browse Source

Added transactions index and show page

Added redirection to transaction show page after transaction has created
Prepared for transaction print (A4 PDF)
pull/4/head
Nafies Luthfi 9 years ago
parent
commit
46e0467f71
  1. 2
      app/Helpers/helpers.php
  2. 2
      app/Http/Controllers/CartController.php
  3. 20
      app/Http/Controllers/TransactionsController.php
  4. 19
      app/Transaction.php
  5. 2
      database/migrations/2017_04_27_121204_create_transactions_table.php
  6. 4
      resources/lang/id/product.php
  7. 4
      resources/lang/id/transaction.php
  8. 9
      resources/views/layouts/partials/top-nav.blade.php
  9. 41
      resources/views/transactions/index.blade.php
  10. 78
      resources/views/transactions/show.blade.php
  11. 7
      routes/web.php
  12. 2
      tests/Feature/TransactionEntryTest.php
  13. 54
      tests/Unit/Integration/TransactionTest.php

2
app/Helpers/helpers.php

@ -8,7 +8,7 @@ function formatNo($number)
function formatRp($number)
{
if ($number == 0) {
return '-';
return 0;
}
return 'Rp. '.formatNo($number);

2
app/Http/Controllers/CartController.php

@ -139,6 +139,6 @@ class CartController extends Controller
$draft->destroy();
flash(trans('transaction.created', ['invoice_no' => $transaction->invoice_no]), 'success')->important();
return redirect()->route('cart.index');
return redirect()->route('transactions.show', $transaction->invoice_no);
}
}

20
app/Http/Controllers/TransactionsController.php

@ -0,0 +1,20 @@
<?php
namespace App\Http\Controllers;
use App\Transaction;
use Illuminate\Http\Request;
class TransactionsController extends Controller
{
public function index(Request $request)
{
$transactions = Transaction::orderBy('invoice_no','desc')->paginate(24);
return view('transactions.index', compact('transactions'));
}
public function show(Transaction $transaction)
{
return view('transactions.show', compact('transaction'));
}
}

19
app/Transaction.php

@ -10,4 +10,23 @@ class Transaction extends Model
'items' => 'array',
'customer' => 'array',
];
public function getRouteKeyName()
{
return 'invoice_no';
}
public function getItemsCountAttribute($value)
{
$pcsCount = 0;
foreach ($this->items as $item) {
$pcsCount += $item['qty'];
}
return count($this->items) . ' Item, ' . $pcsCount . ' Pcs';
}
public function getExchange()
{
return $this->payment - $this->total;
}
}

2
database/migrations/2017_04_27_121204_create_transactions_table.php

@ -15,7 +15,7 @@ class CreateTransactionsTable extends Migration
{
Schema::create('transactions', function (Blueprint $table) {
$table->increments('id');
$table->char('invoice_no', 8);
$table->char('invoice_no', 8)->unique();
$table->text('items');
$table->string('customer');
$table->unsignedInteger('payment');

4
resources/lang/id/product.php

@ -10,6 +10,10 @@ return [
'price' => 'Harga',
'unit' => 'Satuan',
'back_to_index' => 'Kembali ke daftar Produk',
'item_price' => 'Harga Satuan',
'item_discount' => 'Diskon Item',
'item_qty' => 'Qty',
'item_subtotal' => 'Subtotal',
// Actions
'create' => 'Input Produk Baru',

4
resources/lang/id/transaction.php

@ -2,6 +2,8 @@
return [
// Labels
'transaction' => 'Transaksi',
'list' => 'List Transaksi',
'create' => 'Buat Transaksi',
'create_cash' => 'Buat Transaksi Tunai',
'create_credit' => 'Buat Transaksi Kredit',
@ -18,6 +20,7 @@ return [
'draft_removed' => 'Draft transaksi telah dihapus.',
'draft_destroyed' => 'Seluruh Draft transaksi telah dihapus.',
'draft_not_found' => 'Draft transaksi tidak ditemukan.',
'items_count' => 'Jumlah Item',
// Actions
'proccess' => 'Proses Transaksi',
@ -27,6 +30,7 @@ return [
'created' => 'Transaksi berhasil disimpan, No. Invoice: <strong>:invoice_no</strong>',
// Attributes
'invoice_no' => 'No. Invoice',
'customer' => 'Customer',
'customer_name' => 'Nama Customer',
'customer_phone' => 'Hp/Telp.',

9
resources/views/layouts/partials/top-nav.blade.php

@ -19,7 +19,12 @@
<div class="collapse navbar-collapse" id="app-navbar-collapse">
@if (Auth::check())
<ul class="nav navbar-nav">
<li>{{ link_to_route('cart.index', trans('nav_menu.draft_list')) }}</li>
<li {{ (Request::segment(1) == 'drafts') ? 'class=active' : '' }}>
{{ link_to_route('cart.index', trans('nav_menu.draft_list'), [], ['class' => 'strong text-primary']) }}
</li>
<li {{ (Request::segment(1) == 'transactions') ? 'class=active' : '' }}>
{{ link_to_route('transactions.index', trans('transaction.list')) }}
</li>
</ul>
<!-- Right Side Of Navbar -->
<ul class="nav navbar-nav navbar-right">
@ -33,7 +38,7 @@
</li>
<li class="dropdown">
<a href="#" class="dropdown-toggle" data-toggle="dropdown" role="button" aria-expanded="false">
Produk <span class="caret"></span>
{{ trans('product.product') }} <span class="caret"></span>
</a>
<ul class="dropdown-menu" role="menu">
<li>{{ link_to_route('products.index', trans('product.list')) }}</li>

41
resources/views/transactions/index.blade.php

@ -0,0 +1,41 @@
@extends('layouts.app')
@section('title', trans('transaction.list'))
@section('content')
<div class="panel panel-default">
<div class="panel-heading"><h3 class="panel-title">{{ trans('transaction.list') }}</h3></div>
<div class="panel-body">
<table class="table table-condensed">
<thead>
<tr>
<th>{{ trans('app.table_no') }}</th>
<th>{{ trans('transaction.invoice_no') }}</th>
<th>{{ trans('app.date') }}</th>
<th>{{ trans('transaction.customer') }}</th>
<th>{{ trans('transaction.items_count') }}</th>
<th class="text-right">{{ trans('transaction.total') }}</th>
<th>{{ trans('app.action') }}</th>
</tr>
</thead>
<tbody>
@forelse($transactions as $key => $transaction)
<tr>
<td>{{ 1 + $key }}</td>
<td>{{ $transaction->invoice_no }}</td>
<td>{{ $transaction->created_at->format('Y-m-d') }}</td>
<td>{{ $transaction->customer['name'] }}</td>
<td>{{ $transaction->items_count }}</td>
<td class="text-right">{{ formatRp($transaction->total) }}</td>
<td>
{{ link_to_route('transactions.show', trans('app.show'), $transaction->invoice_no) }} |
{{ link_to_route('transactions.pdf', trans('app.print'), $transaction->invoice_no) }}
</td>
</tr>
@empty
@endforelse
</tbody>
</table>
</div>
</div>
@endsection

78
resources/views/transactions/show.blade.php

@ -0,0 +1,78 @@
@extends('layouts.app')
@section('title', trans('transaction.detail'))
@section('content')
<h3 class="page-header">{{ $transaction->invoice_no }} <small>{{ trans('transaction.detail') }}</small></h3>
<div class="row">
<div class="col-sm-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.invoice_no') }}</td><td class="text-primary strong">{{ $transaction->invoice_no }}</td></tr>
<tr><td>{{ trans('app.date') }}</td><td>{{ $transaction->created_at->format('Y-m-d') }}</td></tr>
<tr><td>{{ trans('transaction.customer_name') }}</td><td>{{ $transaction->customer['name'] }}</td></tr>
<tr><td>{{ trans('transaction.customer_phone') }}</td><td>{{ $transaction->customer['phone'] }}</td></tr>
<tr><td>{{ trans('transaction.items_count') }}</td><td>{{ $transaction->items_count }}</td></tr>
<tr><td>{{ trans('transaction.total') }}</td><td class="text-right strong">{{ formatRp($transaction->total) }}</td></tr>
<tr><td>{{ trans('transaction.payment') }}</td><td class="text-right">{{ formatRp($transaction->payment) }}</td></tr>
<tr><td>{{ trans('transaction.exchange') }}</td><td class="text-right">{{ formatRp($transaction->getExchange()) }}</td></tr>
</tbody>
</table>
</div>
</div>
</div>
<div class="col-sm-8">
<div class="panel panel-default">
<div class="panel-heading"><h3 class="panel-title">{{ trans('transaction.items') }}</h3></div>
<div class="panel-body">
<table class="table table-condensed">
<thead>
<tr>
<th>{{ trans('app.table_no') }}</th>
<th>{{ trans('product.name') }}</th>
<th class="text-right">{{ trans('product.item_price') }}</th>
<th class="text-right">{{ trans('product.item_discount') }}</th>
<th class="text-center">{{ trans('product.item_qty') }}</th>
<th class="text-right">{{ trans('product.item_subtotal') }}</th>
</tr>
</thead>
<tbody>
<?php $discountTotal = 0; ?>
@foreach($transaction->items as $key => $item)
<tr>
<td>{{ $key + 1 }}</td>
<td>
{{ $item['name'] }} <br>
<small class="text-primary">({{ $item['unit'] }})</small>
</td>
<td class="text-right">{{ formatRp($item['price']) }}</td>
<td class="text-right">{{ formatRp($item['item_discount']) }}</td>
<td class="text-center">{{ $item['qty'] }}</td>
<td class="text-right">{{ formatRp($item['subtotal']) }}</td>
</tr>
<?php $discountTotal = $transaction['item_discount_subtotal'] ?>
@endforeach
</tbody>
<tfoot>
<tr>
<th colspan="5" class="text-right">{{ trans('transaction.subtotal') }} :</th>
<th class="text-right">{{ formatRp($transaction['total'] + $discountTotal) }}</th>
</tr>
<tr>
<th colspan="5" class="text-right">{{ trans('transaction.discount_total') }} :</th>
<th class="text-right">{{ formatRp($discountTotal) }}</th>
</tr>
<tr>
<th colspan="5" class="text-right">{{ trans('transaction.total') }} :</th>
<th class="text-right">{{ formatRp($transaction['total']) }}</th>
</tr>
</tfoot>
</table>
</div>
</div>
</div>
</div>
@endsection

7
routes/web.php

@ -49,6 +49,13 @@ Route::group(['middleware' => 'auth'], function () {
Route::resource('units', 'UnitsController', ['except' => ['create','show','edit']]);
/**
* Transactions Routes
*/
Route::get('transactions', ['as' => 'transactions.index', 'uses' => 'TransactionsController@index']);
Route::get('transactions/{transaction}', ['as' => 'transactions.show', 'uses' => 'TransactionsController@show']);
Route::get('transactions/{transaction}/pdf', ['as' => 'transactions.pdf', 'uses' => 'TransactionsController@pdf']);
/**
* Backup Restore Database Routes
*/
Route::post('backups/upload', ['as'=>'backups.upload', 'uses'=>'BackupsController@upload']);

2
tests/Feature/TransactionEntryTest.php

@ -234,7 +234,7 @@ class TransactionEntryTest extends BrowserKitTestCase
$this->press(trans('transaction.save'));
$this->seePageIs(route('cart.index'));
$this->seePageIs(route('transactions.show', date('ym').'0001'));
$this->see(trans('transaction.created', ['invoice_no' => date('ym').'0001']));
$this->seeInDatabase('transactions', [

54
tests/Unit/Integration/TransactionTest.php

@ -0,0 +1,54 @@
<?php
namespace Tests\Unit\Integration;
use App\Transaction;
use Illuminate\Foundation\Testing\DatabaseMigrations;
use Tests\TestCase;
class TransactionTest extends TestCase
{
use DatabaseMigrations;
/** @test */
public function it_has_items_count_attribute()
{
$transaction = new Transaction;
$items = [
[
'id' => '1',
'name' => 'Test Item',
'unit' => 'Test unit',
'price' => 1000,
'qty' => 2,
'item_discount' => 0,
'item_discount_subtotal' => 0,
'subtotal' => 2000,
],
[
'id' => '2',
'name' => 'Test Item 2',
'unit' => 'Test unit',
'price' => 1000,
'qty' => 3,
'item_discount' => 0,
'item_discount_subtotal' => 0,
'subtotal' => 2000,
],
];
$transaction->items = $items;
$this->assertEquals('2 Item, 5 Pcs', $transaction->items_count);
}
/** @test */
public function it_has_get_exchange_method()
{
$transaction = new Transaction;
$transaction->payment = 100000;
$transaction->total = 90000;
$this->assertEquals(10000, $transaction->getExchange());
}
}
Loading…
Cancel
Save