feat: print data

This commit is contained in:
myuqinurrohman 2025-04-22 14:13:14 +07:00
parent dc78f8ba32
commit f05407b0ef
7 changed files with 235 additions and 3 deletions

View File

@ -7,6 +7,7 @@
use App\Http\Requests\ContentRecapRequest;
use App\Models\ContentRecap;
use App\Models\ContentRecapClassification;
use Barryvdh\DomPDF\Facade\Pdf;
use Carbon\Carbon;
use Illuminate\Http\Request;
use Illuminate\Support\Facades\Auth;
@ -139,4 +140,14 @@ public function export(Request $request)
return Excel::download(new ContentRecapExport($classification, $channel, $social_media, $posted_year, $posted_month, $posted_date), 'content-recaps-'.$formattedNow.'.xlsx');
}
public function printData($id){
$contentRecap = ContentRecap::with(['enhancer', 'classification'])->findOrFail(decrypt_id($id));
$pdf = Pdf::loadView('dashboard.content-recaps.print', compact('contentRecap'));
return $pdf->stream(slugify('rekap konten '. $contentRecap->content_theme).'.pdf');
}
}

View File

@ -2156,6 +2156,8 @@ public function contentRecap(Request $request){
->addColumn('action', function ($data) {
$showUrl = route('dashboard.content.recaps.show', ['id' => encrypt_id($data->id)]);
$printUrl = route('dashboard.content.recaps.print', ['id' => encrypt_id($data->id)]);
$editUrl = route('dashboard.content.recaps.edit', ['id' => encrypt_id($data->id)]);
$deleteUrl = route('dashboard.content.recaps.destroy', ['id' => encrypt_id($data->id)]);
@ -2166,6 +2168,10 @@ public function contentRecap(Request $request){
<ul class="link-list-opt">
<li><a href="'.$showUrl.'"><em class="icon ni ni-eye"></em><span>Detail</span></a></li>';
if (is_role([1])) {
$dropdown .= '<li><a href="'.$printUrl.'" target="_blank"><em class="icon ni ni-printer"></em><span>Cetak</span></a></li>';
}
if (is_role([1])) {
$dropdown .= '<li><a href="'.$editUrl.'"><em class="icon ni ni-edit"></em><span>Ubah</span></a></li>';
}

View File

@ -60,7 +60,7 @@
}
.header h2 {
font-size: 24px;
color: #007bff;
color: #3A59D1;
}
.header h3 {
font-size: 20px;

View File

@ -0,0 +1,214 @@
<!DOCTYPE html>
<html lang="id">
<head>
<meta charset="UTF-8">
<title>Data Rekap Konten</title>
<style>
/* Styling tetap sama seperti sebelumnya */
body {
font-family: 'Segoe UI', Tahoma, Geneva, Verdana, sans-serif;
font-size: 14px;
}
body::before {
content: "";
position: fixed;
top: 0;
left: 0;
width: 100%;
height: 100%;
background-image: url('assets/defaults/simedkom-logo-circle.png');
background-size: 300px auto;
background-repeat: no-repeat;
background-position: center center;
opacity: 0.05;
z-index: -1;
}
header .icon {
text-align: center;
}
header .icon img {
width: 20% !important;
max-width: 200px;
height: auto;
}
.container {
width: 80%;
margin: 20px auto;
padding: 20px;
box-shadow: 0 4px 6px rgba(0, 0, 0, 0.1);
}
.header {
text-align: center;
margin-bottom: 20px;
padding-bottom: 20px;
border-bottom: 2px solid #e0e0e0;
}
.header h2 {
font-size: 24px;
color: #3A59D1;
}
.header h3 {
font-size: 20px;
color: #555;
}
.row {
display: flex;
justify-content: space-between;
margin-bottom: 15px;
padding: 5px 0;
border-bottom: 1px solid #f1f1f1;
}
.row:last-child {
border-bottom: none;
}
.label {
font-weight: bold;
width: 35%;
color: #444;
}
.value {
width: 60%;
color: #555;
}
.section {
margin-bottom: 25px;
}
.document {
margin-top: 10px;
padding: 5px 0;
}
.document img {
max-width: 300px;
margin-bottom: 10px;
display: block;
}
.document .content {
background-color: rgba(241, 237, 237, 0.363);
padding: 1rem;
border-radius: 0.5rem;
display: flex;
justify-content: center;
align-items: center; /* ini yang bikin vertikal align tengah */
text-align: center;
flex-direction: column;
}
.document a {
color: #007bff;
text-decoration: underline;
}
.footer {
text-align: right;
font-size: 12px;
color: #aaa;
margin-top: 30px;
}
</style>
</head>
<body>
<header>
<div class="icon">
<img src="{{ public_path('assets/defaults/simedkom-logo-full.png') }}" alt="">
</div>
</header>
<div class="container">
<div class="header">
<h2>Rekap Konten</h2>
{{-- <h3>{{ $contentRecap->content_theme }}</h3> --}}
</div>
<div class="section">
<div class="row">
<div class="label">Tema Konten</div>
<div class="value">{{ $contentRecap->content_theme }}</div>
</div>
<div class="row">
<div class="label">Tanggal Posting</div>
<div class="value">{{ idn_date($contentRecap->posted_date, 'l, d F Y') }}</div>
</div>
<div class="row">
<div class="label">Kanal</div>
<div class="value">{{ ucfirst($contentRecap->channel) }}</div>
</div>
<div class="row">
<div class="label">Link</div>
<div class="value">
@if (filled(($contentRecap->link)))
<a href="{{$contentRecap->link}}" target="_blank">{{$contentRecap->link}}</a>
@else
<i>Tidak ada link</i>
@endif
</div>
</div>
<div class="row">
<div class="label">Sosial Media</div>
<div class="value">{{ $contentRecap->social_media }}</div>
</div>
<div class="row">
<div class="label">Klasifikasi</div>
<div class="value">{{ $contentRecap->classification->name }}</div>
</div>
<div class="row">
<div class="label">Deskripsi</div>
<div class="value">
@if (filled(($contentRecap->description)))
{!!$contentRecap->description!!}
@else
<i>Tidak ada deskripsi</i>
@endif
</div>
</div>
<div class="row">
<div class="label">Tanggal Input</div>
<div class="value">{{ idn_date($contentRecap->created_at, 'l, d F Y') }}</div>
</div>
<div class="row">
<div class="label">Diinput Oleh</div>
<div class="value">{{ $contentRecap->enhancer->name }}</div>
</div>
</div>
{{-- Dokumen --}}
<div class="section">
@php
$documents = [
'Gambar' => $contentRecap->image,
];
@endphp
@foreach($documents as $label => $doc)
<div class="document">
<strong>{{ $label }}</strong><br>
<div class="content">
@if($doc)
@php
$ext = pathinfo($doc, PATHINFO_EXTENSION);
@endphp
@if(in_array(strtolower($ext), ['jpg', 'jpeg', 'png', 'gif', 'webp']))
<img src="{{ public_path('storage/uploads/content-recaps/' . $doc) }}" alt="{{ "Tidak ada " . $label }}">
@elseif(strtolower($ext) === 'pdf')
<a href="{{ asset('storage/uploads/content-recaps/' . $doc) }}" target="_blank">Lihat Dokumen PDF</a>
@else
File tidak dikenali.
@endif
@else
Tidak Ada Dokumen
@endif
</div>
</div>
@endforeach
</div>
<div class="footer">
Dicetak pada {{ now()->format('d-m-Y H:i') . ' - ' . $app->app_title }}
</div>
</div>
</body>
</html>

View File

@ -49,7 +49,7 @@
}
.header h2 {
font-size: 24px;
color: #007bff;
color: #3A59D1;
}
.header h3 {
font-size: 20px;

View File

@ -49,7 +49,7 @@
}
.header h2 {
font-size: 24px;
color: #007bff;
color: #3A59D1;
}
.header h3 {
font-size: 20px;

View File

@ -499,6 +499,7 @@
Route::post('/export', 'export')->name('export');
Route::post('/filter', 'filter')->name('filter');
Route::get('/print/{id}', 'printData')->name('print');
});
Route::get('/data', [DatatableController::class, 'contentRecap'])->name('data');