Skip to content

Commit

Permalink
Styled pdf print
Browse files Browse the repository at this point in the history
  • Loading branch information
orkit committed Nov 24, 2023
1 parent ada89c4 commit a6d7a66
Show file tree
Hide file tree
Showing 5 changed files with 94 additions and 58 deletions.
26 changes: 23 additions & 3 deletions app/Http/Controllers/FOController.php
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,9 @@
namespace App\Http\Controllers;

use App\Models\Dashboard;
use App\Models\TravelRequest;
use App\Models\User;
use Barryvdh\DomPDF\Facade\Pdf;
use Illuminate\Http\Request;

class FOController extends Controller
Expand All @@ -14,10 +17,27 @@ public function __construct()

public function list()
{
$dashboard = Dashboard::all();
return (new \Statamic\View\View)
->template('requests.fo.list')
->layout('mylayout')
->with(['dashboards' => $dashboard]);
->layout('mylayout');
}

public function pdfview($id)
{
$tr = TravelRequest::find($id);
$user = User::find(Dashboard::where('request_id', $tr->id)->first()->user_id);
$manager = User::find(Dashboard::where('request_id', $tr->id)->first()->manager_id);
$head = User::find(Dashboard::where('request_id', $tr->id)->first()->head_id);
return view('requests.travel.pdf', ['tr' => $tr, 'user' => $user, 'manager' => $manager, 'head' => $head]);
}

public function download($id)
{
$tr = TravelRequest::find($id);
$user = User::find(Dashboard::where('request_id', $tr->id)->first()->user_id);
$manager = User::find(Dashboard::where('request_id', $tr->id)->first()->manager_id);
$head = User::find(Dashboard::where('request_id', $tr->id)->first()->head_id);
$pdf = Pdf::loadView('requests.travel.pdf', ['tr' => $tr, 'user' => $user, 'manager' => $manager, 'head' => $head]);
return $pdf->download('travelrequest_'.$tr->id.'.pdf');
}
}
11 changes: 0 additions & 11 deletions app/Http/Controllers/TravelRequestController.php
Original file line number Diff line number Diff line change
Expand Up @@ -7,10 +7,8 @@
use App\Models\TravelRequest;
use App\Models\User;
use App\Workflows\TravelRequestWorkflow;
use Barryvdh\DomPDF\Facade\Pdf;
use Carbon\Carbon;
use Illuminate\Http\Request;
use Illuminate\Support\Facades\Auth;
use Illuminate\Support\Facades\DB;
use Workflow\WorkflowStub;

Expand Down Expand Up @@ -39,15 +37,6 @@ public function show($id)
->with(['tr' => $tr, 'formtype' => $formtype]);
}

public function download($id)
{
$tr = TravelRequest::find($id);
$user = User::find(Dashboard::where('request_id', $tr->id)->first()->user_id);
$manager = User::find(Dashboard::where('request_id', $tr->id)->first()->manager_id);
$head = User::find(Dashboard::where('request_id', $tr->id)->first()->head_id);
$pdf = Pdf::loadView('requests.travel.pdf', ['tr' => $tr, 'user' => $user, 'manager' => $manager, 'head' => $head]);
return $pdf->download('travelrequest_'.$tr->id.'.pdf');
}

public function create()
{
Expand Down
27 changes: 22 additions & 5 deletions public/tr/pdf.css
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,7 @@ body{
margin:0;
padding:1cm 2cm;
color:var(--font-color);
font-size:12pt;
font-size:10pt;
}

a{
Expand All @@ -33,7 +33,13 @@ hr{
margin:1cm 0;
height:0;
border:0;
border-top:1mm solid var(--highlight-color);
border-top:1mm solid;
}

.container {
display: flex;
flex-direction: column;
align-items: flex-end;
}

header{
Expand All @@ -43,12 +49,12 @@ header{

header .logoAndName{
display:flex;
align-items:center;
align-items:start;
justify-content:space-between;
width:1.5cm;
height:1.5cm;
/*margin-right:.5cm;*/
margin-bottom:.5cm;
margin-left: -.28cm;
padding-bottom: 8px;
}

header h1,
Expand All @@ -63,6 +69,12 @@ header h3{
text-transform:uppercase;
}

status table{
width:50%;
margin-left:50%;
border-collapse:collapse;
}

main table{
width:100%;
border-collapse:collapse;
Expand Down Expand Up @@ -92,6 +104,11 @@ main table tbody td:last-of-type{
text-align:right;
}

status table thead th:last-of-type,
status table tbody td:last-of-type{
text-align:right;
}

req table thead th:last-of-type,
req table tbody td:last-of-type{
text-align:right;
Expand Down
85 changes: 47 additions & 38 deletions resources/views/requests/travel/pdf.blade.php
Original file line number Diff line number Diff line change
Expand Up @@ -14,46 +14,60 @@
<img src="{{ asset('./images/su_cp.png') }}" alt="Stockholms University" width="100" />
</div>
</div>
<p style="margin-top:.8cm">{{__("Department of Computer and Systems Sciences")}}</p>
<p style="margin-top:.8cm; font-size:12pt;">{{__("Department of Computer and Systems Sciences")}}</p>
</header>
<div class="container">
<status>
<table>
<thead style="border: 1px solid;">
<tr>
<th colspan="2" style="border: 1px solid; padding-right: 10px;">
<h3 style="margin: 10px;">{{__("TRAVELREQUEST")}}</h3>
</th>

</tr>
<tr>
<th style="border: 1px solid; padding: 5px;">{{__("Name")}}</th>
<th style="padding: 5px;">{{__("Created Date")}}</th>
</tr>
</thead>
<tbody style="border: 1px solid;">
<tr>
<td style="border: 1px solid; padding: 5px;">
{{$user->name}}
</td>
<td style="padding: 5px;">
{{\Carbon\Carbon::createFromTimestamp($tr->created)->toDateString()}}
</td>
</tr>
</tbody>
</table>
</status>
</div>
<br><br>
<req>
<table>
<thead>
<tr>
<th>{{__("Name")}}</th>
<th>{{__("Request Created")}}</th>
<th>{{__("ProjectID")}}</th>
<th>{{__("Project leader")}}</th>
<th>{{__("Unit head")}}</th>
<th>{{__("Approved date")}}</th>
</tr>
</thead>
<tbody>
<tr>
<td>
{{$user->name}}
{{$tr->project}}
</td>
<td>
{{\Carbon\Carbon::createFromTimestamp($tr->created)->toDateString()}}
{{$manager->name}}
</td>
</tr>
</table>
<br>
<table>
<thead>
<tr>
<th>{{__("Purpose")}}</th>
<th>{{__("Paper accepted")}}</th>
</tr>
</thead>
<tbody>
<tr>
<td>
{{$tr->purpose}}
{{$head->name}}
</td>
<td>
@if($tr->paper == 0 or $tr->paper == null)
{{__("No")}}
@else
{{__("Yes")}}
@endif
{{\Carbon\Carbon::parse($tr->updated_at)->format('Y-m-d')}}
</td>
</tr>
</table>
Expand Down Expand Up @@ -87,35 +101,31 @@
</td>
</tr>
</table>
<br>
<br><br>
<table>
<thead>
<tr>
<th>{{__("ProjectID")}}</th>
<th>{{__("Project leader")}}</th>
<th>{{__("Unit head")}}</th>
<th>{{__("Approved date")}}</th>
<th>{{__("Purpose")}}</th>
<th>{{__("Paper accepted")}}</th>
</tr>
</thead>
<tbody>
<tr>
<td>
{{$tr->project}}
</td>
<td>
{{$manager->name}}
</td>
<td>
{{$head->name}}
{{$tr->purpose}}
</td>
<td>
{{\Carbon\Carbon::parse($tr->updated_at)->format('Y-m-d')}}
@if($tr->paper == 0 or $tr->paper == null)
{{__("No")}}
@else
{{__("Yes")}}
@endif
</td>
</tr>
</table>
<br>
<b>{{__("Comments from")}}:</b>
<br>
<br><br>
<table>
<thead>
<tr>
Expand Down Expand Up @@ -150,7 +160,6 @@
</tr>
</table>
</req>

<br><br>
<main>
<table>
Expand Down
3 changes: 2 additions & 1 deletion routes/web.php
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,6 @@
//Travelrequest
Route::get('/travel', [\App\Http\Controllers\TravelRequestController::class, 'create'])->name('travel-request-create');
Route::get('/travel/show/{id}', [\App\Http\Controllers\TravelRequestController::class, 'show'])->name('travel-request-show');
Route::get('/travel/pdf/{id}', [\App\Http\Controllers\TravelRequestController::class, 'download'])->name('travel-request-pdf');
Route::post('/travel', [\App\Http\Controllers\TravelRequestController::class, 'submit'])->name('travel-submit');

//ReviewHandler
Expand All @@ -34,6 +33,8 @@

//FO Handler
Route::get('/list', [\App\Http\Controllers\FOController::class, 'list'])->name('request-list');
Route::get('/viewpdf/{id}', [\App\Http\Controllers\FOController::class, 'pdfview'])->name('travel-request-pdfview');
Route::get('/travel/pdf/{id}', [\App\Http\Controllers\FOController::class, 'download'])->name('travel-request-pdf');

//Test
Route::get('/test', [TestController::class, 'test'])->name('workflow-dashboard');
Expand Down

0 comments on commit a6d7a66

Please sign in to comment.