format documents with letterhead

This commit is contained in:
Edmond Teh
2020-09-14 13:11:51 +08:00
parent d69e3384ff
commit 5821fd2f57
7 changed files with 284 additions and 90 deletions
+98 -7
View File
@@ -416,16 +416,30 @@ class InvoiceController extends Controller
public function CIEFToCustomerInvoice($id)
{
$defaultConfig = (new \Mpdf\Config\ConfigVariables())->getDefaults();
$fontDirs = $defaultConfig['fontDir'];
$defaultFontConfig = (new \Mpdf\Config\FontVariables())->getDefaults();
$fontData = $defaultFontConfig['fontdata'];
$mpdf = new \Mpdf\Mpdf([
'fontDir' => array_merge($fontDirs, [
__DIR__ . '/custom/font/directory',
]),
]);
$mpdf->shrink_tables_to_fit=1;
$mpdf->keep_table_proportions = true;
$mpdf->SetTitle('Purchase Order');
$booking = Booking::where('id', $id)->first();
$invoice = Invoice::where('booking_id', $booking['id'])->first();
$lines = InvoiceDetails::where('invoice_id', $invoice->id)->get();
$data = [
'title' => 'INVOICE',
'title' => 'Invoice',
'detail' => [
'date' => Carbon::createFromFormat('Y-m-d H:i:s', $booking->created_at)->format('d-m-Y'),
'ei' => 'EI-202009-000001',
'edo' => '',
'ei' => '',
'edo' => 'EDO-202009-000001',
'ref' => $booking->id
],
'billto' => [
@@ -436,14 +450,37 @@ class InvoiceController extends Controller
'phone' => $invoice->contact_no,
'marking_no' => ''
],
'total_page' => (count($lines) / 10),
'lines' => $lines,
'amount' => $invoice->amount
];
$pdf = PDF::loadView('pdf/invoice', $data);
// Send
return $pdf->download('invoice.pdf');
$html = view('pdf/invoice', $data);
$footer = array(
"C" => array(
"content" => "This is generated by computer , no signature required."
),
"R" => array(
"content" => "Page {PAGENO} of {nb}"
),
"line" => 1
);
$mpdf->Bookmark('Start of the document');
$mpdf->SetHTMLFooter('
<table width="100%">
<tr>
<td style="text-align: right; ">This is generated by computer. No signature required.</td>
<td style="text-align: right; ">Page {PAGENO} of {nbpg}</td>
</tr>
</table>
');
$mpdf->setHeader("EDO-202009-000001");
$mpdf->WriteHTML($html);
$mpdf->Output();
}
public function CIEFToCustomerDO($id)
@@ -480,6 +517,60 @@ class InvoiceController extends Controller
return $pdf->download('do.pdf');
}
public function showpo() {
$defaultConfig = (new \Mpdf\Config\ConfigVariables())->getDefaults();
$fontDirs = $defaultConfig['fontDir'];
$defaultFontConfig = (new \Mpdf\Config\FontVariables())->getDefaults();
$fontData = $defaultFontConfig['fontdata'];
$mpdf = new \Mpdf\Mpdf([
'fontDir' => array_merge($fontDirs, [
__DIR__ . '/custom/font/directory',
]),
]);
$mpdf->SetTitle('Purchase Order');
$id = '2020';
$booking = Booking::where('id', $id)->first();
$invoice = Invoice::where('booking_id', $booking['id'])->first();
$lines = InvoiceDetails::where('invoice_id', $invoice->id)->get();
$data = [
'title' => 'Delivery Order',
'detail' => [
'date' => Carbon::createFromFormat('Y-m-d H:i:s', $booking->created_at)->format('d-m-Y'),
'ei' => '',
'edo' => 'EDO-202009-000001',
'ref' => $booking->id
],
'billto' => [
'buyer_company' => $invoice->buyer_company,
'reg_no' => $invoice->reg_no,
'address' => $invoice->address,
'gst' => '',
'phone' => $invoice->contact_no,
'marking_no' => ''
],
'total_page' => (count($lines) / 10),
'lines' => $lines,
'amount' => $invoice->amount
];
$html = view('pdf/invoice', $data);
$mpdf->Bookmark('Start of the document');
$mpdf->WriteHTML($html);
$mpdf->Output();
}
private function isUser($booking_id, $user_id) {
$booking = Booking::where([
@@ -0,0 +1,32 @@
<?php
use Illuminate\Support\Facades\Schema;
use Illuminate\Database\Schema\Blueprint;
use Illuminate\Database\Migrations\Migration;
class ChangeDescriptionTo256Varchar extends Migration
{
/**
* Run the migrations.
*
* @return void
*/
public function up()
{
Schema::table('invoice_details', function (Blueprint $table) {
$table->string('description', 256)->change();
});
}
/**
* Reverse the migrations.
*
* @return void
*/
public function down()
{
Schema::table('invoice_details', function (Blueprint $table) {
//
});
}
}
@@ -0,0 +1,33 @@
<?php
use Illuminate\Support\Facades\Schema;
use Illuminate\Database\Schema\Blueprint;
use Illuminate\Database\Migrations\Migration;
class AddEiEdoEpoToInvoice extends Migration
{
/**
* Run the migrations.
*
* @return void
*/
public function up()
{
Schema::table('invoices', function (Blueprint $table) {
$table->string('edo')->unique();
$table->string('ei')->unique();
});
}
/**
* Reverse the migrations.
*
* @return void
*/
public function down()
{
Schema::table('invoices', function (Blueprint $table) {
//
});
}
}
@@ -155,7 +155,7 @@
name="description" cols="20" rows="2"
@blur="$v.form.addLine.description.$touch()"/>
<div class="invalid-feedback">
Description Required
Maximum length for description is 256 characters
</div>
</div>
</td>
@@ -375,6 +375,9 @@
</div>
</template>
<style>
input {
min-width: 6em;
}
.container {
margin-left: 10% !important;
margin-right: 10% !important;
@@ -448,7 +451,7 @@
<script>
import Vue from 'vue'
import Vuelidate from 'vuelidate'
import { required, numeric, decimal, requiredIf } from 'vuelidate/lib/validators'
import { required, numeric, decimal, requiredIf, maxLength } from 'vuelidate/lib/validators'
import axios from 'axios'
Vue.use(Vuelidate)
@@ -553,7 +556,7 @@ export default {
required
},
description: {
required
maxLength: maxLength(256)
},
quantity: {
required,
+110 -75
View File
@@ -4,41 +4,24 @@
<title>Document</title>
<style>
body {
font-family: Droidsans;
font-family: sun-extA;
}
.clear-fix::after {
content: "";
clear: both;
display: table;
}
.letter-head {
float: left;
display: inline-block;
position: relative;
}
img.logo {
display: inline;
position: absolute;
top: 10px;
right: 0;
}
img {
height: 7em;
width: 18%;
}
.cief-address {
position: absolute;
left: 18%;
top: -30px;
}
.details {
position: absolute;
left: 76%;
top: -20px;
}
.title {
font-size: 2em;
font-weight: bolder;
font-weight: 1200;
}
.details {
display: inline-block;
position: relative;
}
.sub-title {
font-size: 1.3em;
@@ -53,7 +36,7 @@
}
table {
width: 100%;
vertical-align: top;
}
th {
border-bottom: 1px solid black;
@@ -66,10 +49,17 @@
td {
padding: 0.4em;
text-align: center;
}td.description, th.description {
text-align: justify;
max-width: 40em;
}
td.description, th.description {
text-align: left;
td.stock-code, th.stock-code {
text-align: center;
}
th {
vertical-align: middle;
}
td, th {
margin-top: 0.6em;
margin-right: 0.6em;
@@ -79,75 +69,117 @@
}
.total {
border-top: 1px solid black;
border-bottom: 1px double black;
border-bottom: 3px double black;
font-weight: bolder;
}
.address {
} */
td.header-logo {
text-align: left;
width: fit-content;
}
td.header-cief-address {
text-align: left;
}
td.header-details {
text-align: left;
vertical-align: top;
}
td.bill-to {
text-align: left;
}
td.address {
text-align: left;
}
td.computer-generated {
padding-top: 2em;
text-align: center;
font-size: 1.2em;
font-weight: bold;
}
</style>
</head>
<body>
<div class="header clear-fix">
<img src="https://firebasestorage.googleapis.com/v0/b/edmondtm-1d8ed.appspot.com/o/logo.png?alt=media&token=e8458dc5-b9cd-4db4-b2c9-b953c0b9d09e" alt="logo" id="logo">
<p class="cief-address">
<span class="company-name">CIEF WORLDWIDE SDN BHD</span>
<table>
<tr>
<td class="header-logo">
<img src="https://firebasestorage.googleapis.com/v0/b/edmondtm-1d8ed.appspot.com/o/logo.png?alt=media&token=e8458dc5-b9cd-4db4-b2c9-b953c0b9d09e" alt="logo" id="logo" class="">
</td>
<td class="header-cief-address">
<span class="company-name">
<strong>
CIEF WORLDWIDE SDN BHD
</strong>
</span>
<span class="company-reg">(1134596-M)</span><br>
Malaysian Global Innovation &amp; Creativity Center <br>
Level 1 CWS, Block 3730, Persiaran APEC, <br>
63000 Cyberjaya, Malaysian. <br>
Tel: 018-2909252
</p>
<div class="details">
<div class="title">{{$title}}</div>
@if($detail['ei'])
<div class="number">EI#: {{$detail['ei']}}</div>
@endif
@if($detail['edo'])
<div class="number">EDO#: {{$detail['edo']}}</div>
@endif
<div class="ref">Ref#: {{$detail['ref']}}</div>
<div class="date">Date: {{$detail['date']}}</div>
<div class="page">Page: 1 of 1</div>
</div>
</div>
<div class="bill-to sub-title">
Bill To
</div>
<div class="address">
<div class="label">
{{$billto['buyer_company']}}
</div>
<div class="address">
{{$billto['address']}}
</div>
<div>
Phone: {{$billto['phone']}}
</div>
</div>
</td>
<td class="header-details">
<div class="title">
<strong>
{{$title}}
</strong>
</div>
@if($detail['ei'])
<div class="number">EI#: {{$detail['ei']}}</div>
@endif
@if($detail['edo'])
<div class="number">EDO#: {{$detail['edo']}}</div>
@endif
<div class="ref">Ref#: {{$detail['ref']}}</div>
<div class="date">Date: {{$detail['date']}}</div>
<div>&nbsp;</div>
</div>
</td>
<tr>
<td colspan="3" class="bill-to">
<span class="sub-title">
Bill To
</span>
</td>
</tr>
<tr>
<td colspan="3" class="address">
<div class="label">
{{$billto['buyer_company']}}
</div>
<div class="address">
{{$billto['address']}}
</div>
<div>
Phone: {{$billto['phone']}}
</div>
</td>
</tr>
</table>
<br>
<br>
<table>
<table style="overflow: wrap" autosize="1">
<thead>
<tr>
<th>No</th>
<th class="description">Stock Code</th>
<th width="5%">No</th>
<th class="stock-code" width="10%">Stock Code</th>
<th class="description">Description</th>
<th>Quantity</th>
<th>Unit Price (RM)</th>
<th>Total Amount (RM)</th>
<th width="10%">Quantity</th>
<th width="12%">Unit Price (RM)</th>
<th width="10%">Total Amount<br>(RM)</th>
</tr>
</thead>
<tbody>
@foreach ($lines as $line)
<tr>
<td>{{$line->order}}</td>
<td class="description">{{$line->stock_code}}</td>
<td class="description">{{$line->description}}</td>
<td>{{$line->quantity}}</td>
<td>{{number_format($line->unit_price_rm, 2)}}</td>
<td>{{number_format($line->total, 2)}}</td>
<td width="5%">{{$line->order}}</td>
<td class="stock-code" width="10%">{{$line->stock_code}}</td>
<td class="description" >{{$line->description}}</td>
<td width="10%">{{$line->quantity}}</td>
<td width="12%">{{number_format($line->unit_price_rm, 2)}}</td>
<td width="20%">{{number_format($line->total, 2)}}</td>
</tr>
@endforeach
</tbody>
@@ -165,5 +197,8 @@
</tfoot>
</table>
</body>
</html>
+2 -4
View File
@@ -5,8 +5,8 @@
<title>document</title>
<style>
body {
font-family: sans-serif;
font-size: 16px;
font-family: noto sans-serif;
font-size: normal;
}
.details {
float: right;
@@ -16,11 +16,9 @@
}
.buyer, .header {
max-width: 45%;
float: left;
}
.seller, .doc-details {
max-width: 45%;
float: right;
}
.doc-details {
padding: 1em;
+3 -1
View File
@@ -67,8 +67,10 @@ Route::group(['middleware' => 'auth:api'], function () {
Route::get('malaysia-bank/{malaysiaBank}', 'SettingMalaysiaBankController@show');
});
Route::group(['middleware' => 'guest:api'], function () {
Route::get('showpo', 'InvoiceController@showpo');
Route::group(['middleware' => 'guest:api'], function () {
Route::get('showinvoice', 'InvoiceController@showinvoice');
Route::post('login', 'Auth\LoginController@login')->name('login');
Route::post('register', 'Auth\RegisterController@create');