-
Notifications
You must be signed in to change notification settings - Fork 146
Sediakan pengelolaan QR Code pengganti TTE #1580
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Open
lukman48
wants to merge
7
commits into
OpenSID:rilis-dev
Choose a base branch
from
lukman48:fitur/qr-code-tte
base: rilis-dev
Could not load branches
Branch not found: {{ refName }}
Loading
Could not load tags
Nothing to show
Loading
Are you sure you want to change the base?
Some commits from the old base branch may be removed from the timeline,
and old review comments may become outdated.
Open
Changes from all commits
Commits
Show all changes
7 commits
Select commit
Hold shift + click to select a range
e1b7df6
feat: sediakan pengelolaan QR Code pengganti TTE
lukman48 aee863e
Merge remote-tracking branch 'origin/rilis-dev' into fitur/qr-code-tte
pandigresik c520601
fix conflict
pandigresik 9031a57
fix: perbaiki code review PR #1580 - QR Code TTE
lukman48 26dc7ff
fix: perbaiki semua isu code review PR #1580 - QR Code TTE
lukman48 7e61dcb
Merge remote-tracking branch 'origin/rilis-dev' into fitur/qr-code-tte
pandigresik e8b1141
tambahkan seeder untuk permohonan surat
pandigresik File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -38,26 +38,34 @@ | |
| use App\Models\DataDesa; | ||
| use App\Models\LogTte; | ||
| use App\Models\Surat; | ||
| use Endroid\QrCode\Builder\Builder; | ||
| use Endroid\QrCode\Encoding\Encoding; | ||
| use Endroid\QrCode\ErrorCorrectionLevel; | ||
| use Endroid\QrCode\RoundBlockSizeMode; | ||
| use Endroid\QrCode\Writer\PngWriter; | ||
| use GuzzleHttp\Exception\ClientException; | ||
| use GuzzleHttp\Psr7; | ||
| use Illuminate\Http\JsonResponse; | ||
| use Illuminate\Http\Request; | ||
| use Illuminate\Support\Facades\DB; | ||
| use Illuminate\Support\Facades\Log; | ||
| use Illuminate\Support\Facades\Storage; | ||
| use Illuminate\View\View; | ||
| use setasign\Fpdi\Fpdi; | ||
| use Symfony\Component\HttpFoundation\BinaryFileResponse; | ||
| use Yajra\DataTables\DataTables; | ||
|
|
||
| class PermohonanController extends Controller | ||
| { | ||
| public function index() | ||
| public function index(): View | ||
| { | ||
| // dd(!$this->isDatabaseGabungan(), DataDesa::pluck('desa_id')); | ||
| $page_title = 'Permohonan Surat'; | ||
| $page_description = 'Daftar Permohonan Surat'; | ||
|
|
||
| return view('surat.permohonan.index', compact('page_title', 'page_description')); | ||
| } | ||
|
|
||
| public function getData() | ||
| public function getData(): JsonResponse | ||
| { | ||
| $desa = request('kode_desa'); | ||
|
|
||
|
|
@@ -127,9 +135,8 @@ public function getData() | |
| ->rawColumns(['aksi', 'nama', 'log_verifikasi'])->make(); | ||
| } | ||
|
|
||
| public function show($id) | ||
| public function show(Surat $surat): View | ||
| { | ||
| $surat = Surat::findOrFail($id); | ||
| $page_title = 'Detail Surat'; | ||
| $page_description = "Detail Data Surat: {$surat->nama}"; | ||
|
|
||
|
|
@@ -153,27 +160,24 @@ public function show($id) | |
| return view('surat.permohonan.show', compact('page_title', 'page_description', 'surat')); | ||
| } | ||
|
|
||
| public function download($id) | ||
| public function download(Surat $surat): BinaryFileResponse | ||
| { | ||
| try { | ||
| $surat = Surat::findOrFail($id); | ||
|
|
||
| return Storage::download('public/surat/' . $surat->file); | ||
| } catch (\Exception $e) { | ||
| Log::error('Permohonan Surat download failed', [ | ||
| 'error' => $e->getMessage(), | ||
| 'user_id' => auth()->id(), | ||
| 'surat_id' => $id, | ||
| 'surat_id' => $surat->id, | ||
| ]); | ||
|
|
||
| return back()->with('error', 'Dokumen tidak ditemukan'); | ||
| } | ||
| } | ||
|
|
||
| public function setujui($id) | ||
| public function setujui(Surat $surat): JsonResponse | ||
| { | ||
| try { | ||
| $surat = Surat::findOrFail($id); | ||
| $log_sekarang = $surat->log_verifikasi; | ||
|
|
||
| if ($log_sekarang == LogVerifikasiSurat::Operator) { | ||
|
|
@@ -193,35 +197,38 @@ public function setujui($id) | |
| Log::error('Permohonan Surat approval failed', [ | ||
| 'error' => $e->getMessage(), | ||
| 'user_id' => auth()->id(), | ||
| 'surat_id' => $id, | ||
| 'surat_id' => $surat->id, | ||
| ]); | ||
| } | ||
|
|
||
| return response()->json(); | ||
| } | ||
|
|
||
| public function tolak(Request $request, $id) | ||
| public function tolak(Request $request, Surat $surat): JsonResponse | ||
| { | ||
| try { | ||
| Surat::findOrFail($id)->update([ | ||
| $request->validate(['keterangan' => 'required|string|max:500']); | ||
|
|
||
| $surat->update([ | ||
| 'log_verifikasi' => LogVerifikasiSurat::Ditolak, | ||
| 'status' => StatusSurat::Ditolak, | ||
| 'keterangan' => $request['keterangan'], | ||
| 'keterangan' => $request->input('keterangan'), | ||
| ]); | ||
| } catch (\Exception $e) { | ||
| Log::error('Permohonan Surat rejection failed', [ | ||
| 'error' => $e->getMessage(), | ||
| 'user_id' => auth()->id(), | ||
| 'surat_id' => $id, | ||
| 'surat_id' => $surat->id, | ||
| ]); | ||
| } | ||
|
|
||
| return response()->json(); | ||
| } | ||
|
|
||
| public function passphrase(Request $request, $id) | ||
| public function passphrase(Request $request, Surat $surat): JsonResponse | ||
|
Contributor
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. gunakan formRequest untuk validasi |
||
| { | ||
| $surat = Surat::findOrFail($id); | ||
| $request->validate(['passphrase' => 'required|string']); | ||
|
|
||
|
|
||
| DB::beginTransaction(); | ||
|
|
||
|
|
@@ -244,7 +251,7 @@ public function passphrase(Request $request, $id) | |
| 'multipart' => [ | ||
| ['name' => 'file', 'contents' => Psr7\Utils::tryFopen($file_path, 'r')], | ||
| ['name' => 'nik', 'contents' => $surat->pengurus->nik], | ||
| ['name' => 'passphrase', 'contents' => $request['passphrase']], | ||
| ['name' => 'passphrase', 'contents' => $request->input('passphrase')], | ||
| ['name' => 'tampilan', 'contents' => 'visible'], | ||
| ['name' => 'linkQR', 'contents' => route('surat.arsip.qrcode', $surat->id)], | ||
| ['name' => 'width', 'contents' => $width], | ||
|
|
@@ -271,43 +278,148 @@ public function passphrase(Request $request, $id) | |
| 'status' => true, | ||
| 'pesan_error' => 'success', | ||
| 'jenis' => 'success', | ||
| ]); | ||
| ], $surat->id); | ||
| } catch (ClientException $e) { | ||
| Log::error('Permohonan Surat TTE signing failed', [ | ||
| 'error' => $e->getMessage(), | ||
| 'user_id' => auth()->id(), | ||
| 'surat_id' => $id, | ||
| 'surat_id' => $surat->id, | ||
| ]); | ||
|
|
||
| DB::rollback(); | ||
|
|
||
| return $this->response([ | ||
| 'status' => false, | ||
| 'pesan_error' => $e->getMessage(), | ||
| 'pesan_error' => 'Terjadi kesalahan saat menandatangani surat.', | ||
| 'jenis' => 'ClientException', | ||
| ], $surat->id); | ||
| } | ||
| } | ||
|
|
||
| public function tandatanganQr(Surat $surat): JsonResponse | ||
|
Contributor
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. tambahkan testing untuk method baru, lengkapi pada tests/Feature/PermohonanControllerTest.php |
||
| { | ||
| if ($surat->log_verifikasi != LogVerifikasiSurat::ProsesTTE) { | ||
| return response()->json(['status' => false, 'pesan_error' => 'Surat tidak dalam tahap penandatanganan.'], 400); | ||
| } | ||
|
|
||
| $user = auth()->user()->pengurus_id; | ||
| if ($user != $this->akun_camat->id) { | ||
| return response()->json(['status' => false, 'pesan_error' => 'Hanya camat yang dapat menandatangani surat.'], 403); | ||
| } | ||
|
|
||
| DB::beginTransaction(); | ||
|
|
||
| try { | ||
| $file_path = public_path('storage/surat/' . basename($surat->file)); | ||
| $file_info = pathinfo($file_path); | ||
| $signed_path = public_path('storage/surat/' . $file_info['filename'] . '_signed.pdf'); | ||
|
|
||
| $verificationUrl = route('surat.arsip.qrcode', $surat->id); | ||
|
|
||
| $qrCode = Builder::create() | ||
| ->writer(new PngWriter()) | ||
| ->data($verificationUrl) | ||
| ->encoding(new Encoding('UTF-8')) | ||
| ->errorCorrectionLevel(ErrorCorrectionLevel::High) | ||
| ->size(200) | ||
| ->margin(10) | ||
| ->roundBlockSizeMode(RoundBlockSizeMode::Margin) | ||
| ->build(); | ||
|
|
||
| $qrTempPath = public_path('storage/surat/qr_temp_' . uniqid() . '_' . $surat->id . '.png'); | ||
| $qrCode->saveToFile($qrTempPath); | ||
|
|
||
| $pdf = new Fpdi(); | ||
| $pageCount = $pdf->setSourceFile($file_path); | ||
|
|
||
| for ($i = 1; $i <= $pageCount; $i++) { | ||
| $templateId = $pdf->importPage($i); | ||
| $size = $pdf->getTemplateSize($templateId); | ||
| $pdf->AddPage($size['orientation'], [$size['width'], $size['height']]); | ||
| $pdf->useTemplate($templateId); | ||
|
|
||
| if ($i === $pageCount) { | ||
| $qrSize = 40; | ||
| $margin = 10; | ||
| $pdf->Image($qrTempPath, $size['width'] - $qrSize - $margin, $size['height'] - $qrSize - $margin, $qrSize, $qrSize); | ||
| } | ||
| } | ||
|
|
||
| $pdf->Output('F', $signed_path); | ||
|
|
||
| if (file_exists($qrTempPath)) { | ||
| unlink($qrTempPath); | ||
| } | ||
|
|
||
| $fileHash = hash_file('sha256', $signed_path); | ||
|
|
||
| $surat->update([ | ||
| 'status' => StatusSurat::Arsip, | ||
| 'log_verifikasi' => LogVerifikasiSurat::SudahTTE, | ||
| 'file_hash' => $fileHash, | ||
| ]); | ||
|
|
||
| DB::commit(); | ||
|
|
||
| if (!rename($signed_path, $file_path)) { | ||
| throw new \RuntimeException('Gagal memindahkan file signed ke lokasi asal.'); | ||
| } | ||
|
|
||
| LogTte::create([ | ||
| 'pesan_error' => 'success', | ||
| 'jenis' => 'QRCode', | ||
| 'surat_id' => $surat->id, | ||
| ]); | ||
|
|
||
| return response()->json([ | ||
| 'status' => true, | ||
| 'pesan_error' => 'success', | ||
| 'jenis' => 'success', | ||
| ]); | ||
| } catch (\Exception $e) { | ||
| DB::rollback(); | ||
|
|
||
| if (isset($signed_path) && file_exists($signed_path)) { | ||
| unlink($signed_path); | ||
| } | ||
| if (isset($qrTempPath) && file_exists($qrTempPath)) { | ||
| unlink($qrTempPath); | ||
| } | ||
|
|
||
| Log::error('QR Code signing failed', [ | ||
| 'error' => $e->getMessage(), | ||
| 'user_id' => auth()->id(), | ||
| 'surat_id' => $surat->id, | ||
| ]); | ||
|
|
||
| return response()->json([ | ||
| 'status' => false, | ||
| 'pesan_error' => 'Terjadi kesalahan saat menandatangani surat.', | ||
| 'jenis' => 'Exception', | ||
| ]); | ||
| } | ||
| } | ||
|
|
||
| protected function response($notif = []) | ||
| protected function response(array $notif = [], $suratId = null): JsonResponse | ||
| { | ||
| LogTte::create([ | ||
| 'pesan_error' => $notif['pesan_error'], | ||
| 'jenis' => $notif['jenis'], | ||
| ]); | ||
| LogTte::create(array_filter([ | ||
| 'pesan_error' => $notif['pesan_error'] ?? '', | ||
| 'jenis' => $notif['jenis'] ?? '', | ||
| 'surat_id' => $suratId, | ||
| ])); | ||
|
|
||
| return response()->json($notif); | ||
| } | ||
|
|
||
| public function ditolak() | ||
| public function ditolak(): View | ||
| { | ||
| $page_title = 'Permohonan Surat Ditolak'; | ||
| $page_description = 'Daftar Permohonan Surat Ditolak'; | ||
|
|
||
| return view('surat.permohonan.ditolak', compact('page_title', 'page_description')); | ||
| } | ||
|
|
||
| public function getDataDitolak() | ||
| public function getDataDitolak(): JsonResponse | ||
| { | ||
| $desa = request('kode_desa'); | ||
| $surat = Surat::ditolak() | ||
|
|
||
Oops, something went wrong.
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
masih belum menggunakan formRequest untuk validasi