Browse Source

Add transaction receipt print out in html format

pull/8/head
Nafies Luthfi 8 years ago
parent
commit
e7d6fbb4e1
  1. 5
      app/Http/Controllers/TransactionsController.php
  2. 2
      public/css/pdf.css
  3. 28
      resources/lang/id/master.php
  4. 3
      resources/lang/id/transaction.php
  5. 1
      resources/views/layouts/pdf.blade.php
  6. 2
      resources/views/transactions/index.blade.php
  7. 84
      resources/views/transactions/receipt.blade.php
  8. 5
      resources/views/transactions/show.blade.php
  9. 1
      routes/web.php

5
app/Http/Controllers/TransactionsController.php

@ -32,6 +32,11 @@ class TransactionsController extends Controller
return view('transactions.show', compact('transaction'));
}
public function receipt(Transaction $transaction)
{
return view('transactions.receipt', compact('transaction'));
}
public function pdf(Transaction $transaction)
{
// return view('transactions.pdf', compact('transaction'));

2
public/css/pdf.css

@ -59,7 +59,7 @@ div {
.strong { font-weight: bold; }
.border-bottom {
border-bottom: 1px solid #333;
border-bottom: 1px solid #777;
}
.page-break {

28
resources/lang/id/master.php

@ -1,28 +0,0 @@
<?php
return [
// Labels
'master' => 'Master',
'list' => 'Daftar Master',
'search' => 'Cari Master',
'not_found' => 'Master tidak ditemukan',
'empty' => 'Belum ada Master',
'back_to_index' => 'Kembali ke daftar Master',
// Actions
'create' => 'Input Master Baru',
'created' => 'Input Master baru telah berhasil.',
'show' => 'Detail Master',
'edit' => 'Edit Master',
'update' => 'Update Master',
'updated' => 'Update data Master telah berhasil.',
'delete' => 'Hapus Master',
'delete_confirm' => 'Anda yakin akan menghapus Master ini?',
'deleted' => 'Hapus data Master telah berhasil.',
'undeleted' => 'Data Master gagal dihapus.',
'undeleteable' => 'Data Master tidak dapat dihapus.',
// Attributes
'name' => 'Nama Master',
'description' => 'Deskripsi Master',
];

3
resources/lang/id/transaction.php

@ -30,7 +30,8 @@ return [
'item_list_empty' => 'Masukkan setidaknya 1 item produk.',
'save' => 'Simpan Transaksi',
'created' => 'Transaksi berhasil disimpan, No. Invoice: <strong>:invoice_no</strong>',
'invoice_print' => 'Cetak Invoice',
'invoice_print' => 'Cetak Nota',
'invoice_pdf' => 'Cetak PDF',
// Attributes
'invoice_no' => 'No. Invoice',

1
resources/views/layouts/pdf.blade.php

@ -8,6 +8,7 @@
<title>@yield('title') | {{ config('app.name', 'Laravel') }}</title>
{{ Html::style(url('css/pdf.css')) }}
@yield('style')
</head>
<body>
<div class="container">

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

@ -54,7 +54,7 @@
<td class="text-right">{{ formatRp($transaction->total) }}</td>
<td class="text-center">
{{ link_to_route('transactions.show', trans('app.show'), $transaction->invoice_no) }} |
{{ link_to_route('transactions.pdf', trans('app.print'), $transaction->invoice_no) }}
{{ link_to_route('transactions.receipt', trans('app.print'), $transaction->invoice_no) }}
</td>
</tr>
@empty

84
resources/views/transactions/receipt.blade.php

@ -0,0 +1,84 @@
@extends('layouts.pdf')
@section('title', $transaction->invoice_no.' - '.trans('transaction.invoice_print'))
@section('style')
<style>
table.receipt-table {
width: 310px;
border-collapse: collapse;
}
table.receipt-table th {
padding: 5px 0;
}
table.receipt-table td {
padding: 3px 0;
}
</style>
@endsection
@section('content')
<table class="receipt-table">
<tbody>
<tr><td colspan="3"><h2 class="text-center">{{ config('store.name') }}</h2></td></tr>
<tr>
<td colspan="3">
<p class="text-center">{{ config('store.address') }} | Telp: {{ config('store.phone') }}</p>
</td>
</tr>
<tr>
<td style="width:90px">{{ trans('transaction.invoice_no') }}</td>
<td class="strong">: {{ $transaction->invoice_no }}</td>
<td class="text-right">{{ $transaction->created_at->format('d/m/Y') }}</td>
</tr>
<tr>
<td>{{ trans('transaction.cashier') }}</td>
<td>: {{ $transaction->user->name }}</td>
<td class="text-right">{{ $transaction->created_at->format('H:i:s') }}</td>
</tr>
<tr><td>{{ trans('transaction.customer') }}</td><td colspan="2">: {{ $transaction->customer['name'] }}</td></tr>
<tr><td>{{ trans('transaction.customer_phone') }}</td><td colspan="2">: {{ $transaction->customer['phone'] }}</td></tr>
<tr><th colspan="3" class="text-left">{{ trans('transaction.items') }}</th></tr>
<tr>
<th class="border-bottom">{{ trans('product.item_qty') }}</th>
<th class="text-right border-bottom">{{ trans('product.price') }} ({{ trans('product.item_discount') }})</th>
<th class="text-right border-bottom" style="width:90px">{{ trans('product.item_subtotal') }}</th>
</tr>
<?php $discountTotal = 0; ?>
@foreach($transaction->items as $key => $item)
<tr>
<td class="strong" colspan="3">{{ $key + 1 }})&nbsp;{{ $item['name'] }} ({{ $item['unit'] }})</td>
</tr>
<tr>
<td class="text-center border-bottom" style="vertical-align: top;">{{ $item['qty'] }}</td>
<td class="text-right border-bottom">
{{ formatRp($item['price']) }} ({{ formatRp($item['item_discount']) }})
</td>
<td class="text-right border-bottom">{{ formatRp($item['subtotal']) }}</td>
</tr>
<?php $discountTotal += $item['item_discount_subtotal'] ?>
@endforeach
<tr>
<th colspan="2" class="text-right">{{ trans('transaction.subtotal') }} :</th>
<th class="text-right">{{ formatRp($transaction['total'] + $discountTotal) }}</th>
</tr>
<tr>
<th colspan="2" class="text-right">{{ trans('transaction.discount_total') }} :</th>
<th class="text-right">{{ formatRp($discountTotal) }}</th>
</tr>
<tr>
<th colspan="2" class="text-right">{{ trans('transaction.total') }} :</th>
<th class="text-right">{{ formatRp($transaction['total']) }}</th>
</tr>
<tr>
<th colspan="2" class="text-right">{{ trans('transaction.payment') }} :</th>
<th class="text-right">{{ formatRp($transaction->payment) }}</th>
</tr>
<tr>
<th colspan="2" class="text-right">{{ trans('transaction.exchange') }} :</th>
<th class="text-right">{{ formatRp($transaction->getExchange()) }}</th>
</tr>
</tbody>
</table>
@endsection

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

@ -3,7 +3,10 @@
@section('title', $transaction->invoice_no . ' - ' . trans('transaction.detail'))
@section('content')
<div class="pull-right">{{ link_to_route('transactions.pdf', trans('transaction.invoice_print'), [$transaction->invoice_no], ['class' => 'btn btn-info']) }}</div>
<div class="pull-right">
{{ link_to_route('transactions.pdf', trans('transaction.invoice_pdf'), [$transaction->invoice_no], ['class' => 'btn btn-default']) }}
{{ link_to_route('transactions.receipt', trans('transaction.invoice_print'), [$transaction->invoice_no], ['class' => 'btn btn-default']) }}
</div>
<h3 class="page-header">{{ $transaction->invoice_no }} <small>{{ trans('transaction.detail') }}</small></h3>
<div class="row">
<div class="col-sm-4">

1
routes/web.php

@ -67,6 +67,7 @@ Route::group(['middleware' => 'auth'], function () {
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']);
Route::get('transactions/{transaction}/receipt', ['as' => 'transactions.receipt', 'uses' => 'TransactionsController@receipt']);
/*
* Backup Restore Database Routes

Loading…
Cancel
Save