pdf result

This commit is contained in:
nurafrinaalimi16
2024-04-29 16:56:53 +08:00
parent 2a7f91199e
commit eac65986a6
8 changed files with 577 additions and 7 deletions
+130
View File
@@ -0,0 +1,130 @@
<?php
namespace App\Http\Controllers;
use Illuminate\Http\Request;
use Illuminate\Support\Facades\App;
use App\Result;
use App\Position;
use Illuminate\Support\Facades\DB;
class ResultController extends Controller
{
/**
* Display a listing of the resource.
*
* @return \Illuminate\Http\Response
*/
public function index2(Request $request)
{
//dd()
// calculatePercentage(votes, positionId) {
// const totalVotes = this.results
// .filter(result => result.position_id === positionId)
// .reduce((total, result) => total + result.votes, 0);
// return ((votes / totalVotes) * 100).toFixed(2);
// },
$positions = Position::all();
$results = Result::with('nominee')->get();
dd($results->toArray());
$pdf = App::make('dompdf.wrapper');
$pdf->loadView('report.result', compact('results', 'positions'));
return $pdf->stream();
}
public function index($id)
{
$results = $this->getResult($id);
$total_votes = Result::where('election_id', $id)->count();
$positions = \App\Position::where('election_id', $id)->get();
$nominees = \App\Nominee::where('election_id', $id)->get();
$no_votes = \App\Nominee::whereNotIn('id', $results->pluck('nominee_id') )->get();
$pdf = App::make('dompdf.wrapper');
$pdf->loadView('report.result', compact('results', 'positions','nominees', 'no_votes', 'total_votes'));
return $pdf->stream();
}
private function getResult($id)
{
return \App\Result::select(DB::raw('position_id,nominee_id,count(*) as votes'))
->groupBy('position_id', 'nominee_id')
->where('election_id', $id)
->orderBy('votes', 'DESC')
->get();
}
/**
* Show the form for creating a new resource.
*
* @return \Illuminate\Http\Response
*/
public function create()
{
//
}
/**
* Store a newly created resource in storage.
*
* @param \Illuminate\Http\Request $request
* @return \Illuminate\Http\Response
*/
public function store(Request $request)
{
//
}
/**
* Display the specified resource.
*
* @param int $id
* @return \Illuminate\Http\Response
*/
public function show($id)
{
//
}
/**
* Show the form for editing the specified resource.
*
* @param int $id
* @return \Illuminate\Http\Response
*/
public function edit($id)
{
//
}
/**
* Update the specified resource in storage.
*
* @param \Illuminate\Http\Request $request
* @param int $id
* @return \Illuminate\Http\Response
*/
public function update(Request $request, $id)
{
//
}
/**
* Remove the specified resource from storage.
*
* @param int $id
* @return \Illuminate\Http\Response
*/
public function destroy($id)
{
//
}
}
+16
View File
@@ -3,9 +3,25 @@
namespace App;
use Illuminate\Database\Eloquent\Model;
use Illuminate\Database\Eloquent\Relations\BelongsTo;
class Result extends Model
{
protected $table = 'result';
protected $fillable = ['voter_id', 'nominee_id', 'position_id', 'election_id'];
// protected $appends = ['votes'];
function nominee() : BelongsTo {
return $this->belongsTo(Nominee::class);
}
public function votes($nominee_id)
{
return $this->where('nominee_id','=',$nominee_id)->count();
}
}
+1
View File
@@ -6,6 +6,7 @@
"type": "project",
"require": {
"php": ">=5.6.4",
"barryvdh/laravel-dompdf": "v0.8.4",
"cloudinary/cloudinary_php": "^2.3",
"doctrine/dbal": "^2.5",
"guzzlehttp/guzzle": "^6.5",
Generated
+287 -1
View File
@@ -4,8 +4,68 @@
"Read more about it at https://getcomposer.org/doc/01-basic-usage.md#installing-dependencies",
"This file is @generated automatically"
],
"content-hash": "0a5b2fadbc0e0e1ff0d4762c70a70818",
"content-hash": "1e25a85ac1ac7795e1f547dd83318564",
"packages": [
{
"name": "barryvdh/laravel-dompdf",
"version": "v0.8.4",
"source": {
"type": "git",
"url": "https://github.com/barryvdh/laravel-dompdf.git",
"reference": "3fd817065e1c820b1ddace8b2bf65ca45088df4f"
},
"dist": {
"type": "zip",
"url": "https://api.github.com/repos/barryvdh/laravel-dompdf/zipball/3fd817065e1c820b1ddace8b2bf65ca45088df4f",
"reference": "3fd817065e1c820b1ddace8b2bf65ca45088df4f",
"shasum": ""
},
"require": {
"dompdf/dompdf": "^0.8",
"illuminate/support": "5.5.x|5.6.x|5.7.x|5.8.x",
"php": ">=7"
},
"type": "library",
"extra": {
"branch-alias": {
"dev-master": "0.8-dev"
},
"laravel": {
"providers": [
"Barryvdh\\DomPDF\\ServiceProvider"
],
"aliases": {
"PDF": "Barryvdh\\DomPDF\\Facade"
}
}
},
"autoload": {
"psr-4": {
"Barryvdh\\DomPDF\\": "src"
}
},
"notification-url": "https://packagist.org/downloads/",
"license": [
"MIT"
],
"authors": [
{
"name": "Barry vd. Heuvel",
"email": "barryvdh@gmail.com"
}
],
"description": "A DOMPDF Wrapper for Laravel",
"keywords": [
"dompdf",
"laravel",
"pdf"
],
"support": {
"issues": "https://github.com/barryvdh/laravel-dompdf/issues",
"source": "https://github.com/barryvdh/laravel-dompdf/tree/master"
},
"time": "2019-02-26T18:07:43+00:00"
},
{
"name": "cloudinary/cloudinary_php",
"version": "2.3.0",
@@ -692,6 +752,78 @@
],
"time": "2020-05-25T17:44:05+00:00"
},
{
"name": "dompdf/dompdf",
"version": "v0.8.6",
"source": {
"type": "git",
"url": "https://github.com/dompdf/dompdf.git",
"reference": "db91d81866c69a42dad1d2926f61515a1e3f42c5"
},
"dist": {
"type": "zip",
"url": "https://api.github.com/repos/dompdf/dompdf/zipball/db91d81866c69a42dad1d2926f61515a1e3f42c5",
"reference": "db91d81866c69a42dad1d2926f61515a1e3f42c5",
"shasum": ""
},
"require": {
"ext-dom": "*",
"ext-mbstring": "*",
"phenx/php-font-lib": "^0.5.2",
"phenx/php-svg-lib": "^0.3.3",
"php": "^7.1"
},
"require-dev": {
"mockery/mockery": "^1.3",
"phpunit/phpunit": "^7.5",
"squizlabs/php_codesniffer": "^3.5"
},
"suggest": {
"ext-gd": "Needed to process images",
"ext-gmagick": "Improves image processing performance",
"ext-imagick": "Improves image processing performance",
"ext-zlib": "Needed for pdf stream compression"
},
"type": "library",
"extra": {
"branch-alias": {
"dev-develop": "0.7-dev"
}
},
"autoload": {
"psr-4": {
"Dompdf\\": "src/"
},
"classmap": [
"lib/"
]
},
"notification-url": "https://packagist.org/downloads/",
"license": [
"LGPL-2.1"
],
"authors": [
{
"name": "Fabien Ménager",
"email": "fabien.menager@gmail.com"
},
{
"name": "Brian Sweeney",
"email": "eclecticgeek@gmail.com"
},
{
"name": "Gabriel Bull",
"email": "me@gabrielbull.com"
}
],
"description": "DOMPDF is a CSS 2.1 compliant HTML to PDF converter",
"homepage": "https://github.com/dompdf/dompdf",
"support": {
"issues": "https://github.com/dompdf/dompdf/issues",
"source": "https://github.com/dompdf/dompdf/tree/master"
},
"time": "2020-08-30T22:54:22+00:00"
},
{
"name": "dragonmantank/cron-expression",
"version": "v2.3.1",
@@ -2261,6 +2393,95 @@
},
"time": "2022-02-16T17:07:03+00:00"
},
{
"name": "phenx/php-font-lib",
"version": "0.5.6",
"source": {
"type": "git",
"url": "https://github.com/dompdf/php-font-lib.git",
"reference": "a1681e9793040740a405ac5b189275059e2a9863"
},
"dist": {
"type": "zip",
"url": "https://api.github.com/repos/dompdf/php-font-lib/zipball/a1681e9793040740a405ac5b189275059e2a9863",
"reference": "a1681e9793040740a405ac5b189275059e2a9863",
"shasum": ""
},
"require": {
"ext-mbstring": "*"
},
"require-dev": {
"symfony/phpunit-bridge": "^3 || ^4 || ^5 || ^6"
},
"type": "library",
"autoload": {
"psr-4": {
"FontLib\\": "src/FontLib"
}
},
"notification-url": "https://packagist.org/downloads/",
"license": [
"LGPL-2.1-or-later"
],
"authors": [
{
"name": "Fabien Ménager",
"email": "fabien.menager@gmail.com"
}
],
"description": "A library to read, parse, export and make subsets of different types of font files.",
"homepage": "https://github.com/PhenX/php-font-lib",
"support": {
"issues": "https://github.com/dompdf/php-font-lib/issues",
"source": "https://github.com/dompdf/php-font-lib/tree/0.5.6"
},
"time": "2024-01-29T14:45:26+00:00"
},
{
"name": "phenx/php-svg-lib",
"version": "0.3.4",
"source": {
"type": "git",
"url": "https://github.com/PhenX/php-svg-lib.git",
"reference": "f627771eb854aa7f45f80add0f23c6c4d67ea0f2"
},
"dist": {
"type": "zip",
"url": "https://api.github.com/repos/PhenX/php-svg-lib/zipball/f627771eb854aa7f45f80add0f23c6c4d67ea0f2",
"reference": "f627771eb854aa7f45f80add0f23c6c4d67ea0f2",
"shasum": ""
},
"require": {
"php": "^7.4 || ^8.0",
"sabberworm/php-css-parser": "^8.3"
},
"require-dev": {
"phpunit/phpunit": "^9.5"
},
"type": "library",
"autoload": {
"psr-4": {
"Svg\\": "src/Svg"
}
},
"notification-url": "https://packagist.org/downloads/",
"license": [
"LGPL-3.0"
],
"authors": [
{
"name": "Fabien Ménager",
"email": "fabien.menager@gmail.com"
}
],
"description": "A library to read, parse and export to PDF SVG files.",
"homepage": "https://github.com/PhenX/php-svg-lib",
"support": {
"issues": "https://github.com/PhenX/php-svg-lib/issues",
"source": "https://github.com/PhenX/php-svg-lib/tree/0.3.4"
},
"time": "2021-10-18T02:13:32+00:00"
},
{
"name": "phpoption/phpoption",
"version": "1.8.1",
@@ -2870,6 +3091,71 @@
],
"time": "2021-09-25T23:07:42+00:00"
},
{
"name": "sabberworm/php-css-parser",
"version": "v8.5.1",
"source": {
"type": "git",
"url": "https://github.com/MyIntervals/PHP-CSS-Parser.git",
"reference": "4a3d572b0f8b28bb6fd016ae8bbfc445facef152"
},
"dist": {
"type": "zip",
"url": "https://api.github.com/repos/MyIntervals/PHP-CSS-Parser/zipball/4a3d572b0f8b28bb6fd016ae8bbfc445facef152",
"reference": "4a3d572b0f8b28bb6fd016ae8bbfc445facef152",
"shasum": ""
},
"require": {
"ext-iconv": "*",
"php": ">=5.6.20"
},
"require-dev": {
"phpunit/phpunit": "^5.7.27"
},
"suggest": {
"ext-mbstring": "for parsing UTF-8 CSS"
},
"type": "library",
"extra": {
"branch-alias": {
"dev-main": "9.0.x-dev"
}
},
"autoload": {
"psr-4": {
"Sabberworm\\CSS\\": "src/"
}
},
"notification-url": "https://packagist.org/downloads/",
"license": [
"MIT"
],
"authors": [
{
"name": "Raphael Schweikert"
},
{
"name": "Oliver Klee",
"email": "github@oliverklee.de"
},
{
"name": "Jake Hotson",
"email": "jake.github@qzdesign.co.uk"
}
],
"description": "Parser for CSS Files written in PHP",
"homepage": "https://www.sabberworm.com/blog/2010/6/10/php-css-parser",
"keywords": [
"css",
"parser",
"stylesheet"
],
"support": {
"issues": "https://github.com/MyIntervals/PHP-CSS-Parser/issues",
"source": "https://github.com/MyIntervals/PHP-CSS-Parser/tree/v8.5.1"
},
"time": "2024-02-15T16:41:13+00:00"
},
{
"name": "shrikeh/teapot",
"version": "v2.3.1",
+4 -1
View File
@@ -6,7 +6,7 @@ return [
| My Configuration
|-------------------------------------------------------------------------
|
|
|
*/
'nominee_image' => 'images/nominee/default.jpg',
@@ -195,6 +195,8 @@ return [
// App\Providers\BroadcastServiceProvider::class,
App\Providers\EventServiceProvider::class,
App\Providers\RouteServiceProvider::class,
Barryvdh\DomPDF\ServiceProvider::class,
],
@@ -244,6 +246,7 @@ return [
'URL' => Illuminate\Support\Facades\URL::class,
'Validator' => Illuminate\Support\Facades\Validator::class,
'View' => Illuminate\Support\Facades\View::class,
'PDF' => Barryvdh\DomPDF\Facade::class,
],
@@ -3,7 +3,7 @@
<div class="panel-body">
<h4>Undian Terkini</h4>
<div class="form-group">
<button class="btn btn-success" v-if="data.election.status == 1 && data.user.role==1"
<button class="btn btn-success" v-if="data.election.status == 1 && data.user.role == 1"
@click="util.showModal('#start-election-modal')">Mula Undian</button>
<router-link :to="{ name: 'Current Result' }" class="btn btn-info" v-if="data.election.status == 2">
@@ -37,6 +37,9 @@
<td>
<router-link :to="{ name: 'Election Result', params: { election_id: election.id } }"
class="btn btn-info">Keputusan Undian</router-link>
<a class="btn btn-warning" :href="getPDFurl(election.id)">Muat Turun PDF</a>
</td>
</tr>
<tr v-if="data.elections.length < 1">
@@ -60,7 +63,8 @@
<div class="modal-body">
<div class="form-group">
<label for="name">Nama Undian</label>
<input type="text" name="name" autocomplete="on" class="form-control" placeholder="(Optional)" />
<input type="text" name="name" autocomplete="on" class="form-control"
placeholder="(Optional)" />
</div>
<div class="form-group">
@@ -91,12 +95,14 @@
<div class="modal-body">
<div class="form-group">
<label for="name">Nama Undian</label>
<input type="text" name="name" :value="data.election.name" autocomplete="on" class="form-control" placeholder="(Optional)" />
<input type="text" name="name" :value="data.election.name" autocomplete="on"
class="form-control" placeholder="(Optional)" />
</div>
<div class="form-group">
<label for="password">Kata Laluan</label>
<input type="password" name="password" autocomplete="on" class="form-control" required />
<input type="password" name="password" autocomplete="on" class="form-control"
required />
</div>
</div>
<div class="modal-footer">
@@ -112,6 +118,12 @@
</div>
</template>
<style>
.center-header {
text-align: center;
}
</style>
<script>
export default {
data: () => ({
@@ -181,6 +193,12 @@ export default {
$.notifyClose();
vm.util.showResult(error, 'error');
})
},
getPDFurl(Id) {
// Construct and return the URL based on the item ID
return `/result/${Id}`;
}
}
}
+92
View File
@@ -0,0 +1,92 @@
<div class="container">
<div class="row">
<div class="col-md-12">
@foreach ($positions as $position)
<h5>{{ $position->name }}</h5>
<div class="table-responsive">
<table class="table table-striped table-condensed">
<thead>
<tr>
<th width="20%">No. Anggota</th>
<th width="30%">Nama</th>
<th width="15%">Unit</th>
<th width="10%">Undian</th>
<th width="15%">Peratus (%)</th>
</tr>
</thead>
<tbody>
@foreach ($results as $result)
@if ($result->position_id == $position->id)
<tr>
<td>{{ $result->nominee->no_anggota }}</td>
<td>{{ $result->nominee->name }}</td>
<td>{{ $result->nominee->unit }}</td>
{{-- <td>{{ $result->votes}}</td> --}}
<td>{{ $result->votes($result->nominee->id) }}</td>
<td>{{ ($result->votes($result->nominee->id) / $total_votes) * 100 }} %</td>
</tr>
@endif
@endforeach
@foreach ($no_votes as $no_vote)
@if ($no_vote->position_id == $position->id)
<tr>
<td>{{ $no_vote->no_anggota }}</td>
<td>{{ $no_vote->name }}</td>
<td>{{ $no_vote->unit }}</td>
<td>0</td>
<td>0</td>
</tr>
@endif
@endforeach
<tr>
<td colspan="3"><b>Jumlah Undian</b></td>
<td><b>{{ $total_votes }}</b></td>
</tr>
</tbody>
</table>
</div>
<hr />
@endforeach
</div>
</div>
</div>
<!-- Verified By column -->
<div class="container mt-4">
<div class="row">
<div class="col-md-12">
<div class="table-responsive">
<table>
<tbody>
<tr>
<td colspan="4"><b>Disahkan Oleh :</b></td>
</tr>
<tr>
<td><b>...................................</b></td>
</tr>
</tbody>
</table>
</div>
</div>
</div>
</div>
<style>
/* Style for table body */
.table tbody td {
border-bottom: 1px solid #ddd;
padding: 8px;
}
/* Add space between specific columns */
.table tbody td:nth-child(3),
/* Unit column */
.table tbody td:nth-child(4),
/* Undian column */
.table tbody td:nth-child(5) {
/* Peratus (%) column */
padding-right: 20px;
/* Adjust this value as needed */
}
</style>
+25 -1
View File
@@ -1,6 +1,14 @@
<?php
use App\Http\Controllers\KehadiranController;
use App\Http\Controllers\ResultController;
use App\Result;
use Illuminate\Support\Facades\Route;
use Barryvdh\DomPDF\PDF;
use Illuminate\Support\Facades\App;
/*
|--------------------------------------------------------------------------
| Web Routes
@@ -12,4 +20,20 @@ use Illuminate\Support\Facades\Route;
|
*/
Route::view('/{any}', 'index')->where('any', '.*');
Route::get('/result/{id}', [ResultController::class, 'index']);
Route::get('/pdftest', function(){
$result=Result::all();
$pdf = App::make('dompdf.wrapper');
$pdf->loadView('report.result-2',compact('result'));
return $pdf->stream();
// $pdf = PDF::loadView('report.result-2');
// return $pdf->download('result.pdf');
});
Route::get('/kehadiranpdf/{id}', [KehadiranController::class, 'index']);
Route::view('/{any}', 'index')->where('any', '.*');