sys_ok([ 'message' => 'Use /tools/rpt_t_002/pdf?T_OrderHeaderID= or /tools/rpt_t_002/data?T_OrderHeaderID=' ]); } public function data() { try { $orderHeaderId = $this->get_order_header_id(); if ($orderHeaderId <= 0) { $this->sys_error('T_OrderHeaderID mandatory'); return; } $username = $this->input->get('username', true); if (!$username) { $username = 'ADMIN'; } $an = $this->input->get('AN', true); if ($an === null || $an === '') { $an = $this->input->get('an', true); } if ($an === null) { $an = ''; } $sql = 'CALL sp_rpt_t_002(?, ?, ?)'; $qry = $this->db->query($sql, [$orderHeaderId, $an, $username]); $lastQry = $this->db->last_query(); if (!$qry) { $this->sys_error_db([ 'message' => $this->db->error()['message'], 'sql' => $lastQry ]); return; } $result = $qry->result_array(); $this->clean_mysqli_connection($this->db->conn_id); $this->sys_ok($result); } catch (Exception $exc) { $this->sys_error($exc->getMessage()); } } public function pdf() { try { $orderHeaderId = $this->get_order_header_id(); if ($orderHeaderId <= 0) { $this->sys_error('T_OrderHeaderID mandatory'); return; } $username = $this->input->get('username', true); if (!$username) { $username = 'ADMIN'; } $an = $this->input->get('AN', true); if ($an === null || $an === '') { $an = $this->input->get('an', true); } if ($an === null) { $an = ''; } $sql = 'CALL sp_rpt_t_002(?, ?, ?)'; $qry = $this->db->query($sql, [$orderHeaderId, $an, $username]); $lastQry = $this->db->last_query(); if (!$qry) { $this->sys_error_db([ 'message' => $this->db->error()['message'], 'sql' => $lastQry ]); return; } $rows = $qry->result_array(); $this->clean_mysqli_connection($this->db->conn_id); if (count($rows) === 0) { $this->sys_error('Data report tidak ditemukan'); return; } require_once APPPATH . 'third_party/fpdf/fpdf.php'; $first = $rows[0]; $title = $this->pick_value($first, ['judul', 'title', 'report_name', 'nama_report'], 'KWITANSI'); $patientName = $this->pick_value($first, ['M_PatientName', 'patient_name', 'nama_pasien'], '-'); $pidReg = $this->pick_value($first, ['PIiD', 'M_PatientNoReg'], '-'); $orderDate = $this->pick_value($first, ['T_OrderHeaderDate', 'tanggal', 'order_date'], '-'); $umur = $this->pick_value($first, ['Umur', 'T_OrderHeaderM_PatientAge'], '-'); $sex = $this->pick_value($first, ['M_SexName'], '-'); $phone = $this->pick_value($first, ['M_PatientHP', 'M_PatientPhone'], '-'); $pengirim = $this->pick_value($first, ['M_DoctorName', 'DokterPJ'], '-'); $mou = $this->pick_value($first, ['M_MouName'], '-'); $alamat = $this->pick_value($first, ['M_PatientAddressDescription', 'alamatkirim'], '-'); $company = $this->pick_value($first, ['S_SystemsCompanyName', 'M_CompanyName'], ''); $dokter = $this->pick_value($first, ['M_DoctorName', 'DokterPJ'], '-'); $printBy = $this->pick_value($first, ['M_UserUsername'], '-'); $printAt = date('M j, Y g:i A'); $formRev = $this->pick_value($first, ['M_No_FormRev'], ''); $city = $this->pick_value($first, ['S_SystemsCompanyCity'], 'Surabaya'); $testName = $this->pick_value($first, ['T_TestNamea', 'T_TestName', 'test'], ''); $status = strtoupper((string) $this->pick_value($first, ['Status'], '')); $subtot = (float) $this->pick_value($first, ['subtot', 'T_OrderHeaderSubTotal'], 0); $discAll = (float) $this->pick_value($first, ['disc'], 0); $grandTotal = (float) $this->pick_value($first, ['T_OrderHeaderTotal'], 0); $terbilang = (string) $this->pick_value($first, ['terbilang'], '-'); $fontBody = 8; $pdf = new FPDF('P', 'mm', 'A5'); $pdf->SetMargins(8, 8, 8); $pdf->SetAutoPageBreak(false); $pdf->AddPage(); $pageW = $pdf->GetPageWidth(); $pageH = $pdf->GetPageHeight(); $left = 8; $right = 8; $contentW = $pageW - $left - $right; if ($formRev !== '') { $pdf->SetFont('Arial', '', 7); $pdf->SetXY($pageW - $right - 34, 26); $pdf->Cell(34, 4, $this->safe_text((string) $formRev), 0, 1, 'R'); } $pdf->SetY(24); $pdf->SetFont('Arial', 'B', 14); $pdf->Cell(0, 12, strtoupper((string) $title), 0, 1, 'C'); $pdf->SetY(42); $labelW = 30; $colonW = 4; $valueGap = 2; $valueW = $contentW - $labelW - $colonW - $valueGap; $lineH = 6; $pdf->SetFont('Arial', '', $fontBody); $pdf->Cell($labelW, $lineH, 'Telah diterima dari', 0, 0); $pdf->Cell($colonW, $lineH, ':', 0, 0, 'C'); $terimaDari = trim((string) $an) !== '' ? $an : $patientName; $pdf->Cell($valueW, $lineH, $this->safe_text((string) $terimaDari), 0, 1); $pdf->Cell($labelW, $lineH, 'Uang Sejumlah', 0, 0); $pdf->Cell($colonW, $lineH, ':', 0, 0, 'C'); $pdf->Cell($valueW, $lineH, 'Rp. ' . $this->format_rupiah($grandTotal), 0, 1); $pdf->Cell($labelW, $lineH, 'Terbilang', 0, 0); $pdf->Cell($colonW, $lineH, ':', 0, 0, 'C'); $pdf->Cell($valueW, $lineH, $this->safe_text((string) $terbilang), 0, 1); $pdf->Ln(4); $pdf->Cell(0, 6, 'Untuk pembayaran pemeriksaan laboratorium :', 0, 1); $pdf->Ln(1); $details = [ ['Nama Pasien', $patientName], ['PID/No. Registrasi', $pidReg], ['Tanggal', $orderDate], ['Umur / Jns. Kelamin', $umur . ' / ' . $this->pick_value($first, ['M_SexCode'], 'P')], ['No. Telp', $phone], ['Pengirim', $pengirim], ['Kelompok Pelanggan', str_ireplace('PROGRAM CICILAN (', '', rtrim((string) $mou, ')'))], ['Alamat', $alamat], ]; foreach ($details as $item) { $y0 = $pdf->GetY(); $pdf->SetX($left); $pdf->Cell($labelW, 5, $item[0], 0, 0); $pdf->Cell($colonW, 5, ':', 0, 0, 'C'); $pdf->SetXY($left + $labelW + $colonW + $valueGap, $y0); $pdf->MultiCell($valueW, 5, $this->safe_text((string) $item[1]), 0, 'L'); } $pdf->Ln(3); $pdf->SetFont('Arial', 'B', $fontBody); $pdf->Cell(0, 6, 'Rincian Pemeriksaan :', 0, 1); if ($testName !== '') { $pdf->SetFont('Arial', '', $fontBody); $pdf->Cell(0, 5, ' ' . $this->safe_text($this->strip_html_break((string) $testName)), 0, 1); } $pdf->SetFont('Arial', 'I', $fontBody); $rightX = $left + 74; $rightW = $pageW - $right - $rightX; $rpW = 10; $y = $pdf->GetY(); $pdf->Cell(62, 6, 'Biaya Pemeriksaan', 0, 0); $pdf->Line($rightX, $y + 5, $pageW - $right, $y + 5); $pdf->SetXY($rightX + 2, $y); $pdf->Cell($rpW, 6, 'Rp.', 0, 0, 'L'); $pdf->Cell($rightW - $rpW - 2, 6, $this->format_rupiah($subtot), 0, 1, 'R'); $y = $pdf->GetY(); $pdf->SetX($left); $pdf->Cell(62, 6, 'Discount', 0, 0); $pdf->SetXY($rightX + 2, $y); $pdf->Cell($rpW, 6, 'Rp.', 0, 0, 'L'); $pdf->Cell($rightW - $rpW - 2, 6, $this->format_rupiah($discAll), 0, 1, 'R'); $y = $pdf->GetY(); $pdf->SetX($left); $pdf->Cell(62, 6, 'Total Biaya Pemeriksaan', 0, 0); $pdf->Line($rightX, $y + 5, $pageW - $right, $y + 5); $pdf->SetXY($rightX + 2, $y); $pdf->Cell($rpW, 6, 'Rp.', 0, 0, 'L'); $pdf->Cell($rightW - $rpW - 2, 6, $this->format_rupiah($grandTotal), 0, 1, 'R'); $pdf->Ln(3); $pdf->SetFont('Arial', '', $fontBody); $note = 'Dokumen pelunasan dianggap sah apabila nominal tersebut diatas telah masuk pada rekening yang telah di tetapkan'; $pdf->SetX($left); $pdf->MultiCell($contentW, 5, $this->safe_text($note), 1, 'C'); $ySign = max($pdf->GetY() + 4, $pageH - 42); $pdf->SetY($ySign); if ($status === 'LUNAS') { $pdf->Rect($left, $ySign, 50, 8); $pdf->SetFont('Arial', '', $fontBody); $pdf->SetXY($left, $ySign + 0.5); $pdf->Cell(50, 7, 'LUNAS', 0, 1, 'C'); } $pdf->SetFont('Arial', '', $fontBody); $pdf->SetXY($pageW - $right - 48, $ySign + 1); $pdf->Cell(48, 5, $this->safe_text($city) . ' , ' . date('d-m-Y H:i:s'), 0, 1, 'L'); $pdf->SetXY($pageW - $right - 44, $ySign + 12); $pdf->Cell(40, 5, $this->safe_text((string) $printBy), 0, 1, 'C'); $pdf->Line($pageW - $right - 44, $ySign + 17, $pageW - $right - 4, $ySign + 17); $pdf->SetY($pageH - 7); $pdf->SetFont('Times', '', 6); $pdf->SetX($left); $pdf->Cell(22, 4, 'Print Oleh :', 0, 0, 'L'); $pdf->Cell(50, 4, $this->safe_text((string) $printBy), 0, 0, 'L'); $pdf->Cell(12, 4, '1', 0, 0, 'C'); $pdf->Cell(6, 4, '/', 0, 0, 'C'); $pdf->Cell(12, 4, '1', 0, 0, 'C'); $pdf->Cell($pageW - $right - $pdf->GetX(), 4, $this->safe_text((string) $printAt), 0, 1, 'R'); header('Content-Type: application/pdf'); header('Content-Disposition: inline; filename="rpt_t_002_' . $orderHeaderId . '.pdf"'); echo $pdf->Output('S'); } catch (Exception $exc) { $this->sys_error($exc->getMessage()); } } private function get_order_header_id() { $orderHeaderId = $this->input->get('T_OrderHeaderID', true); if ($orderHeaderId === null || $orderHeaderId === '') { $orderHeaderId = $this->input->get('PID', true); } return intval($orderHeaderId); } private function pick_value($row, $keys, $default = '') { foreach ($keys as $key) { if (array_key_exists($key, $row) && $row[$key] !== null && $row[$key] !== '') { return $row[$key]; } } return $default; } private function safe_text($text) { return iconv('UTF-8', 'windows-1252//TRANSLIT', $text); } private function format_rupiah($num) { return number_format((float) $num, 0, ',', '.'); } private function strip_html_break($text) { return trim(str_replace(['
', '
', '
', '
'], ', ', $text)); } }