export pdf 50%

pull/2/head
ajikamaludin 2 years ago
parent 04c97952c1
commit c6c9ab2dc3

@ -7,7 +7,10 @@ use App\Models\Company;
use App\Models\Document;
use App\Models\Type;
use App\Models\User;
use Barryvdh\DomPDF\Facade\Pdf;
use Illuminate\Http\Request;
use OpenSpout\Writer\Common\Creator\Style\StyleBuilder;
use Rap2hpoutre\FastExcel\FastExcel;
class DocumentController extends Controller
{
@ -205,4 +208,61 @@ class DocumentController extends Controller
{
$doc->delete();
}
public function import()
{
//
}
public function export(Request $request)
{
$query = Document::with(['variety', 'category', 'company.region.group'])->orderBy('created_at', 'desc');
$collections = collect([]);
foreach ($query->get() as $document) {
$collections->add([
'group' => $document->company->region->group->name,
'region' => $document->company->region->name,
'nama perusahaan' => $document->company->name,
'jenis' => $document->variety->name,
'kategori' => $document->category->name,
'no' => $document->no_doc,
'nama' => $document->name,
'penerbit' => $document->publisher,
'tipe' => $document->type == Document::TYPE_TETAP ? 'Tetap' : 'Tidak Tetap',
'tanggal terbit' => $document->publish_date->format('d-m-Y'),
'tanggal jatuh tempo' => $document->due_date->format('d-m-Y'),
'keterangan' => $document->description,
'file' => asset('documents/'.$document->document),
'status' => $document->status == Document::STATUS_YES ? 'Ya' : 'Tidak',
'catatan' => $document->due_status,
]);
}
if($request->type == 'pdf') {
return $this->exportAsPdf($collections);
}
if($request->type == 'excel') {
return $this->exportAsExcel($collections);
}
}
private function exportAsPdf($collections)
{
$pdf = Pdf::loadView('exports.documents', ['collections' => $collections->toArray()]);
$date = now()->format('d-m-Y');
return $pdf->download("documents-$date.pdf");
}
private function exportAsExcel($collections)
{
$date = now()->format('d-m-Y');
$header_style = (new StyleBuilder())->setFontBold()->build();
return (new FastExcel($collections))
->headerStyle($header_style)
->download("document-$date.xlsx");
}
}

@ -6,6 +6,7 @@
"license": "MIT",
"require": {
"php": "^8.0.2",
"barryvdh/laravel-dompdf": "^2.0",
"guzzlehttp/guzzle": "^7.2",
"inertiajs/inertia-laravel": "^0.6.9",
"laravel/framework": "^9.48",

353
composer.lock generated

@ -4,8 +4,85 @@
"Read more about it at https://getcomposer.org/doc/01-basic-usage.md#installing-dependencies",
"This file is @generated automatically"
],
"content-hash": "6ea3a91a17dd8ccd5fa4886bcef58ef8",
"content-hash": "776f6b59288b5ff0657e18a74e116064",
"packages": [
{
"name": "barryvdh/laravel-dompdf",
"version": "v2.0.0",
"source": {
"type": "git",
"url": "https://github.com/barryvdh/laravel-dompdf.git",
"reference": "1d47648c6cef37f715ecb8bcc5f5a656ad372e27"
},
"dist": {
"type": "zip",
"url": "https://api.github.com/repos/barryvdh/laravel-dompdf/zipball/1d47648c6cef37f715ecb8bcc5f5a656ad372e27",
"reference": "1d47648c6cef37f715ecb8bcc5f5a656ad372e27",
"shasum": ""
},
"require": {
"dompdf/dompdf": "^2",
"illuminate/support": "^6|^7|^8|^9",
"php": "^7.2 || ^8.0"
},
"require-dev": {
"nunomaduro/larastan": "^1|^2",
"orchestra/testbench": "^4|^5|^6|^7",
"phpro/grumphp": "^1",
"squizlabs/php_codesniffer": "^3.5"
},
"type": "library",
"extra": {
"branch-alias": {
"dev-master": "2.0-dev"
},
"laravel": {
"providers": [
"Barryvdh\\DomPDF\\ServiceProvider"
],
"aliases": {
"Pdf": "Barryvdh\\DomPDF\\Facade\\Pdf",
"PDF": "Barryvdh\\DomPDF\\Facade\\Pdf"
}
}
},
"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/v2.0.0"
},
"funding": [
{
"url": "https://fruitcake.nl",
"type": "custom"
},
{
"url": "https://github.com/barryvdh",
"type": "github"
}
],
"time": "2022-07-06T11:12:10+00:00"
},
{
"name": "brick/math",
"version": "0.10.2",
@ -305,6 +382,68 @@
],
"time": "2022-12-15T16:57:16+00:00"
},
{
"name": "dompdf/dompdf",
"version": "v2.0.1",
"source": {
"type": "git",
"url": "https://github.com/dompdf/dompdf.git",
"reference": "c5310df0e22c758c85ea5288175fc6cd777bc085"
},
"dist": {
"type": "zip",
"url": "https://api.github.com/repos/dompdf/dompdf/zipball/c5310df0e22c758c85ea5288175fc6cd777bc085",
"reference": "c5310df0e22c758c85ea5288175fc6cd777bc085",
"shasum": ""
},
"require": {
"ext-dom": "*",
"ext-mbstring": "*",
"masterminds/html5": "^2.0",
"phenx/php-font-lib": ">=0.5.4 <1.0.0",
"phenx/php-svg-lib": ">=0.3.3 <1.0.0",
"php": "^7.1 || ^8.0"
},
"require-dev": {
"ext-json": "*",
"ext-zip": "*",
"mockery/mockery": "^1.3",
"phpunit/phpunit": "^7.5 || ^8 || ^9",
"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",
"autoload": {
"psr-4": {
"Dompdf\\": "src/"
},
"classmap": [
"lib/"
]
},
"notification-url": "https://packagist.org/downloads/",
"license": [
"LGPL-2.1"
],
"authors": [
{
"name": "The Dompdf Community",
"homepage": "https://github.com/dompdf/dompdf/blob/master/AUTHORS.md"
}
],
"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/v2.0.1"
},
"time": "2022-09-22T13:43:41+00:00"
},
{
"name": "dragonmantank/cron-expression",
"version": "v3.3.2",
@ -1686,6 +1825,75 @@
],
"time": "2022-04-17T13:12:02+00:00"
},
{
"name": "masterminds/html5",
"version": "2.7.6",
"source": {
"type": "git",
"url": "https://github.com/Masterminds/html5-php.git",
"reference": "897eb517a343a2281f11bc5556d6548db7d93947"
},
"dist": {
"type": "zip",
"url": "https://api.github.com/repos/Masterminds/html5-php/zipball/897eb517a343a2281f11bc5556d6548db7d93947",
"reference": "897eb517a343a2281f11bc5556d6548db7d93947",
"shasum": ""
},
"require": {
"ext-ctype": "*",
"ext-dom": "*",
"ext-libxml": "*",
"php": ">=5.3.0"
},
"require-dev": {
"phpunit/phpunit": "^4.8.35 || ^5.7.21 || ^6 || ^7"
},
"type": "library",
"extra": {
"branch-alias": {
"dev-master": "2.7-dev"
}
},
"autoload": {
"psr-4": {
"Masterminds\\": "src"
}
},
"notification-url": "https://packagist.org/downloads/",
"license": [
"MIT"
],
"authors": [
{
"name": "Matt Butcher",
"email": "technosophos@gmail.com"
},
{
"name": "Matt Farina",
"email": "matt@mattfarina.com"
},
{
"name": "Asmir Mustafic",
"email": "goetas@gmail.com"
}
],
"description": "An HTML5 parser and serializer.",
"homepage": "http://masterminds.github.io/html5-php",
"keywords": [
"HTML5",
"dom",
"html",
"parser",
"querypath",
"serializer",
"xml"
],
"support": {
"issues": "https://github.com/Masterminds/html5-php/issues",
"source": "https://github.com/Masterminds/html5-php/tree/2.7.6"
},
"time": "2022-08-18T16:18:26+00:00"
},
{
"name": "monolog/monolog",
"version": "2.8.0",
@ -2269,6 +2477,96 @@
],
"time": "2022-03-31T06:15:15+00:00"
},
{
"name": "phenx/php-font-lib",
"version": "0.5.4",
"source": {
"type": "git",
"url": "https://github.com/dompdf/php-font-lib.git",
"reference": "dd448ad1ce34c63d09baccd05415e361300c35b4"
},
"dist": {
"type": "zip",
"url": "https://api.github.com/repos/dompdf/php-font-lib/zipball/dd448ad1ce34c63d09baccd05415e361300c35b4",
"reference": "dd448ad1ce34c63d09baccd05415e361300c35b4",
"shasum": ""
},
"require": {
"ext-mbstring": "*"
},
"require-dev": {
"symfony/phpunit-bridge": "^3 || ^4 || ^5"
},
"type": "library",
"autoload": {
"psr-4": {
"FontLib\\": "src/FontLib"
}
},
"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, 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.4"
},
"time": "2021-12-17T19:44:54+00:00"
},
{
"name": "phenx/php-svg-lib",
"version": "0.5.0",
"source": {
"type": "git",
"url": "https://github.com/dompdf/php-svg-lib.git",
"reference": "76876c6cf3080bcb6f249d7d59705108166a6685"
},
"dist": {
"type": "zip",
"url": "https://api.github.com/repos/dompdf/php-svg-lib/zipball/76876c6cf3080bcb6f249d7d59705108166a6685",
"reference": "76876c6cf3080bcb6f249d7d59705108166a6685",
"shasum": ""
},
"require": {
"ext-mbstring": "*",
"php": "^7.1 || ^8.0",
"sabberworm/php-css-parser": "^8.4"
},
"require-dev": {
"phpunit/phpunit": "^7.5 || ^8.5 || ^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/dompdf/php-svg-lib/issues",
"source": "https://github.com/dompdf/php-svg-lib/tree/0.5.0"
},
"time": "2022-09-06T12:16:56+00:00"
},
{
"name": "phpoption/phpoption",
"version": "1.9.0",
@ -3079,6 +3377,59 @@
],
"time": "2022-07-21T14:21:25+00:00"
},
{
"name": "sabberworm/php-css-parser",
"version": "8.4.0",
"source": {
"type": "git",
"url": "https://github.com/sabberworm/PHP-CSS-Parser.git",
"reference": "e41d2140031d533348b2192a83f02d8dd8a71d30"
},
"dist": {
"type": "zip",
"url": "https://api.github.com/repos/sabberworm/PHP-CSS-Parser/zipball/e41d2140031d533348b2192a83f02d8dd8a71d30",
"reference": "e41d2140031d533348b2192a83f02d8dd8a71d30",
"shasum": ""
},
"require": {
"ext-iconv": "*",
"php": ">=5.6.20"
},
"require-dev": {
"codacy/coverage": "^1.4",
"phpunit/phpunit": "^4.8.36"
},
"suggest": {
"ext-mbstring": "for parsing UTF-8 CSS"
},
"type": "library",
"autoload": {
"psr-4": {
"Sabberworm\\CSS\\": "src/"
}
},
"notification-url": "https://packagist.org/downloads/",
"license": [
"MIT"
],
"authors": [
{
"name": "Raphael Schweikert"
}
],
"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/sabberworm/PHP-CSS-Parser/issues",
"source": "https://github.com/sabberworm/PHP-CSS-Parser/tree/8.4.0"
},
"time": "2021-12-11T13:40:54+00:00"
},
{
"name": "shiftonelabs/laravel-cascade-deletes",
"version": "1.0.1",

@ -7,9 +7,11 @@ export default function NavDropdown({ name, items }) {
return (
<div className="dropdown">
<label tabIndex={0} className={`btn btn-ghost rounded-btn gap-2 ${active ? 'btn-active' : ''}`}>
{name}
<ArrowDownIcon/>
<label tabIndex={0} className={`btn btn-ghost rounded-btn ${active ? 'btn-active' : ''}`}>
<div className="flex flex-row gap-2 items-center">
<div>{name}</div>
<ArrowDownIcon/>
</div>
</label>
<ul tabIndex={0} className="menu dropdown-content p-2 shadow bg-base-100 rounded-box w-52 mt-4">
{items.map((item, index) => (

@ -59,7 +59,7 @@ export default function Authenticated({ auth, children, flash, notify }) {
<div className="px-2">
<a className="text-xl font-bold">Monitor Doc</a>
</div>
<div className="sm:flex px-6 hidden">
<div className="lg:flex px-6 hidden">
<div className="flex items-stretch gap-2">
{routes.filter(r => r.show).map((item, index) => (
<div key={index}>
@ -77,11 +77,13 @@ export default function Authenticated({ auth, children, flash, notify }) {
))}
</div>
</div>
<div className="sm:flex justify-end flex-1 px-2 hidden">
<div className="lg:flex justify-end flex-1 px-2 hidden">
<div className="dropdown dropdown-end">
<label tabIndex={0} className="btn btn-ghost gap-2 m-1 normal-case">
{auth.user.name}
<ArrowDownIcon/>
<label tabIndex={0} className="btn btn-ghost normal-case">
<div className='flex flex-row gap-2 items-center'>
<div>{auth.user.name}</div>
<ArrowDownIcon/>
</div>
</label>
<ul tabIndex={0} className="dropdown-content menu p-2 shadow bg-base-100 rounded-box w-52">
<li>
@ -92,7 +94,7 @@ export default function Authenticated({ auth, children, flash, notify }) {
</ul>
</div>
</div>
<div className="flex-1 justify-end items-center sm:hidden">
<div className="flex-1 justify-end items-center lg:hidden">
<button
onClick={() => setShowingNavigationDropdown((previousState) => !previousState)}
className="inline-flex items-center justify-center p-2 rounded-md text-gray-400 hover:text-gray-500 hover:bg-gray-100 focus:outline-none focus:bg-gray-100 focus:text-gray-500 transition duration-150 ease-in-out"
@ -117,7 +119,7 @@ export default function Authenticated({ auth, children, flash, notify }) {
</div>
</div>
<div className={(showingNavigationDropdown ? 'block' : 'hidden') + ' sm:hidden'}>
<div className={(showingNavigationDropdown ? 'block' : 'hidden') + ' lg:hidden'}>
<div className="pt-2 pb-3 space-y-1">
{routes.filter(r => r.show).map((item, index) => (
<div key={index}>

@ -76,7 +76,7 @@ export default function FormModal(props) {
}
>
<div className="modal-box overflow-y-auto max-h-screen">
<h1 className="font-bold text-2xl pb-8">Jenis</h1>
<h1 className="font-bold text-2xl pb-8">Perusahaan</h1>
<div className="form-control">
<label className="label">
<span className="label-text font-semibold">Nama</span>

@ -118,8 +118,8 @@ export default function Document(props) {
<div className="dropdown dropdown-end">
<label tabIndex={0} className="btn btn-outline">Export</label>
<ul tabIndex={0} className="dropdown-content menu p-2 shadow bg-base-100 rounded-box w-52">
<li><a>XLSX</a></li>
<li><a>PDF</a></li>
<li><a href={route('docs.export', {type: 'excel'})} target='_blank'>XLSX</a></li>
<li><a href={route('docs.export', {type: 'pdf'})} target='_blank'>PDF</a></li>
</ul>
</div>
)}

@ -0,0 +1,42 @@
<table>
<thead>
<tr>
<th>group</th>
<th>region</th>
<th>nama perusahaan</th>
<th>jenis</th>
<th>kategori</th>
<th>no</th>
<th>nama</th>
<th>penerbit</th>
<th>tipe</th>
<th>tanggal terbit</th>
<th>tanggal jatuh tempo</th>
<th>keterangan</th>
<th>file</th>
<th>status</th>
<th>catatan</th>
</tr>
</thead>
<tbody>
<tr>
@foreach($collections as $collec)
<td>{{ $collec["group"] }}</td>
<td>{{ $collec["region"] }}</td>
<td>{{ $collec["nama perusahaan"] }}</td>
<td>{{ $collec["jenis"] }}</td>
<td>{{ $collec["kategori"] }}</td>
<td>{{ $collec["no"] }}</td>
<td>{{ $collec["nama"] }}</td>
<td>{{ $collec["penerbit"] }}</td>
<td>{{ $collec["tipe"] }}</td>
<td>{{ $collec["tanggal terbit"] }}</td>
<td>{{ $collec["tanggal jatuh tempo"] }}</td>
<td>{{ $collec["keterangan"] }}</td>
<td>{{ $collec["file"] }}</td>
<td>{{ $collec["status"] }}</td>
<td>{{ $collec["catatan"] }}</td>
@endforeach
</tr>
</tbody>
</table>

@ -30,6 +30,7 @@ Route::get('/', function () {
return redirect()->route('login');
});
Route::get('/docs/export', [DocumentController::class, 'export'])->name('docs.export');
Route::middleware(['auth'])->group(function () {
Route::get('/dashboard', [GeneralController::class, 'index'])->name('dashboard');

Loading…
Cancel
Save