Browse Source

Update: fitur cetak QR Code Checkbox

master
unknown 11 months ago
parent
commit
d4366fb883
  1. 38
      app/Http/Controllers/PetiController.php
  2. 86
      resources/views/dashboard/Master_Data/Manajemen_Peti/Peti/all_print.blade.php
  3. 46
      resources/views/dashboard/Master_Data/Manajemen_Peti/Peti/index.blade.php
  4. 4
      routes/web.php

38
app/Http/Controllers/PetiController.php

@ -210,4 +210,42 @@ class PetiController extends Controller
return redirect()->back()->with('error', 'Terjadi kesalahan saat mencetak PDF.'); return redirect()->back()->with('error', 'Terjadi kesalahan saat mencetak PDF.');
} }
} }
public function AllPdf(Request $request)
{
$peti_ids = $request->input('peti_ids');
$selectedIds = explode(',', $peti_ids);
// Mengambil data dari database berdasarkan ID yang dipilih
$peti = Peti::whereIn('id', $selectedIds)->get();
// $peti = Peti::all();
// Inisialisasi Dompdf
$options = new Options();
$options->set('isHtml5ParserEnabled', true);
$options->set('isRemoteEnabled', true);
$options->set('defaultFont', 'Arial');
$dompdf = new Dompdf($options);
// Load HTML dari view
$html = view('dashboard.Master_Data.Manajemen_Peti.Peti.all_print', compact('peti'))->render();
$dompdf->loadHtml($html);
// Render PDF (portrait A4)
$dompdf->setPaper('A4', 'portrait');
$dompdf->render();
$output = $dompdf->output();
// Download file PDF dengan nama yang sesuai
return response()->stream(
function () use ($output) {
echo $output;
},
200,
[
'Content-Type' => 'application/pdf',
'Content-Disposition' => 'inline; filename="label_Peti.pdf"',
]
);
}
} }

86
resources/views/dashboard/Master_Data/Manajemen_Peti/Peti/all_print.blade.php

@ -0,0 +1,86 @@
<!DOCTYPE html>
<html>
<head>
<title>Data PDF</title>
<style>
body {
font-family: Arial, sans-serif;
page-break-before: always;
}
h1 {
text-align: center;
}
table {
width: 100%;
border-collapse: collapse;
}
table,
th,
td {
border: 1px solid black;
}
th,
td {
padding: 8px;
text-align: center;
}
th {
background-color: #f2f2f2;
}
</style>
</head>
<body>
@foreach ($peti as $item => $data)
<?php
$qrcode = base64_encode(
QrCode::format('svg')
->size(150)
->errorCorrection('H')
->generate($data->fix_lot . ';' . $data->id . ';' . $data->warehouse_id),
);
?>
@if ($loop->index % 3 == 0)
<div style="page-break-before: always;"></div>
@endif
<table style="width:100%; margin-top: 10px;" class="table table-bordered">
<tr>
<td rowspan="2">
<img src="data:image/jpeg;base64,<?= base64_encode(file_get_contents('assets/img/logo istw.jpg')) ?>"
alt="Logo ISTW" width="100" height="100">
</td>
<td>PETI NUMBER</td>
<td>BARCODE</td>
</tr>
<tr>
<td>
{{ $data->fix_lot }}
</td>
<td rowspan="4">
<img src="data:image/svg+xml;base64,{{ $qrcode }}" alt="QR Code" />
</td>
</tr>
<tr>
<td>PT. ISTW</td>
<td>CUSTOMER</td>
</tr>
<tr>
<td>QTY PETI</td>
<td rowspan="2">PT. {{ $data->customer->name }}</td>
</tr>
<tr>
<td>1</td>
</tr>
</table>
@endforeach
</body>
</html>

46
resources/views/dashboard/Master_Data/Manajemen_Peti/Peti/index.blade.php

@ -27,10 +27,16 @@
</div> </div>
<div class="card-body"> <div class="card-body">
<div class="table-responsive"> <div class="table-responsive">
<form action="{{ route('dashboard.all-pdf.cetakpdf') }}" method="GET" id="pdfForm" class="mb-3">
@csrf
<input type="hidden" name="peti_ids" id="peti_ids" value="">
<button type="submit" class="btn btn-primary my-2">Cetak PDF</button>
</form>
<table class="table table-bordered" id="tablebarang" width="100%" cellspacing="0"> <table class="table table-bordered" id="tablebarang" width="100%" cellspacing="0">
<thead> <thead>
<tr> <tr>
<th class="text-center" style="width: 10px">No</th> <th class="text-center" style="width: 10px">No</th>
<th><input type="checkbox" class="checkbox " id="selectAll"></th>
<th>User</th> <th>User</th>
<th>Customer</th> <th>Customer</th>
<th>WH</th> <th>WH</th>
@ -51,6 +57,7 @@
@forelse ($peti as $data_peti) @forelse ($peti as $data_peti)
<tr> <tr>
<td class="text-center">{{ $nopeti++ }}</td> <td class="text-center">{{ $nopeti++ }}</td>
<td><input type="checkbox" class="checkbox" value="{{ $data_peti->id }}"></td>
<td>{{ $data_peti->created_by }}</td> <td>{{ $data_peti->created_by }}</td>
<td>{{ $data_peti->customer->name }}</td> <td>{{ $data_peti->customer->name }}</td>
<td>{{ $data_peti->warehouse->name }}</td> <td>{{ $data_peti->warehouse->name }}</td>
@ -85,10 +92,49 @@
@endforelse @endforelse
</tbody> </tbody>
</table> </table>
</div> </div>
</div> </div>
</div> </div>
@else @else
@include('pages.user.Master_Data.Manajemen_Peti.Peti.index') @include('pages.user.Master_Data.Manajemen_Peti.Peti.index')
@endif @endif
<script src="https://code.jquery.com/jquery-3.6.0.min.js"></script>
<script>
$(document).ready(function() {
// Ketika checkbox "Select All" di-klik
$('#selectAll').click(function() {
$('.checkbox').prop('checked', this.checked);
});
// Ketika salah satu checkbox di-klik
$('.checkbox').click(function() {
if ($('.checkbox:checked').length == $('.checkbox').length) {
$('#selectAll').prop('checked', true);
} else {
$('#selectAll').prop('checked', false);
}
});
// Ketika tombol cetak PDF di-klik
$('#pdfForm').submit(function() {
var selectedIds = [];
$('.checkbox:checked').each(function() {
var id = $(this).val();
if (id !== 'on') {
selectedIds.push(id);
}
});
if (selectedIds.length > 0) {
$('#peti_ids').val(selectedIds.join(','));
} else {
alert('Pilih setidaknya satu ID untuk mencetak PDF.');
return false;
}
});
});
</script>
@endsection @endsection

4
routes/web.php

@ -116,9 +116,11 @@ Route::prefix('dashboard')->name('dashboard.')->middleware(['auth'])->group(func
Route::get('peti/{id}/edit', 'edit')->name('peti.edit'); Route::get('peti/{id}/edit', 'edit')->name('peti.edit');
Route::put('peti/{id}', 'update')->name('peti.update'); Route::put('peti/{id}', 'update')->name('peti.update');
Route::delete('peti/delete/{id}', 'destroy')->name('peti.destroy'); Route::delete('peti/delete/{id}', 'destroy')->name('peti.destroy');
Route::get('peticetak_pdf/{id}', 'cetakpdf')->name('peticetakpdf.cetakpdf'); Route::get('peticetak_pdf/{id}', 'cetakPdf')->name('peticetakpdf.cetakpdf');
Route::get('all-cetak/peti', 'AllPdf')->name('all-pdf.cetakpdf');
}); });
//Halaman Warehouse //Halaman Warehouse
Route::controller(WarehouseController::class)->group(function () { Route::controller(WarehouseController::class)->group(function () {
Route::get('warehouse', 'index')->name('warehouse.index'); Route::get('warehouse', 'index')->name('warehouse.index');

Loading…
Cancel
Save