diff --git a/application/controllers/mockup/fo/cashiernewpayment-v27/Payment.http b/application/controllers/mockup/fo/cashiernewpayment-v27/Payment.http index 45c9673b..69365948 100644 --- a/application/controllers/mockup/fo/cashiernewpayment-v27/Payment.http +++ b/application/controllers/mockup/fo/cashiernewpayment-v27/Payment.http @@ -3,10 +3,20 @@ @url = devone.aplikasi.web.id ### -POST https://{{url}}/one-api-lab/mockup/fo/cashiernewpayment-v27/payment/getLocations -Content-Type: application/json - -{ - "order_id": "229", - "token": "{{token}}" -} \ No newline at end of file +POST https://{{url}}/one-api-lab/mockup/fo/cashiernewpayment-v27/payment/getLocations +Content-Type: application/json + +{ + "order_id": "229", + "token": "{{token}}" +} + +### +POST https://{{url}}/one-api-lab/mockup/fo/cashiernewpayment-v27/payment/lookup_print_transaction +Content-Type: application/json + +{ + "start_id": 15, + "end_id": 25, + "token": "{{token}}" +} diff --git a/application/controllers/mockup/fo/cashiernewpayment-v27/Payment.php b/application/controllers/mockup/fo/cashiernewpayment-v27/Payment.php index a12ab035..7b02056e 100644 --- a/application/controllers/mockup/fo/cashiernewpayment-v27/Payment.php +++ b/application/controllers/mockup/fo/cashiernewpayment-v27/Payment.php @@ -695,8 +695,8 @@ class Payment extends MY_Controller } } - function insert_voucher_payment($orderheaderID, $paymentID, $companyID, $mouID, $userID) - { + function insert_voucher_payment($orderheaderID, $paymentID, $companyID, $mouID, $userID) + { $sql = "INSERT INTO f_payment_voucher( F_Payment_VoucherT_OrderHeaderID, @@ -708,9 +708,44 @@ class Payment extends MY_Controller ) VALUES (?, ?, ?, ?, NOW(), ?) "; $query = $this->db_onedev->query($sql, array($orderheaderID, $paymentID, $companyID, $mouID, $userID)); - if (!$query) { - $this->sys_error_db("error inserta f payment voucher"); - exit; - } - } -} + if (!$query) { + $this->sys_error_db("error inserta f payment voucher"); + exit; + } + } + + function lookup_print_transaction() + { + if (! $this->isLogin) { + $this->sys_error("Invalid Token"); + exit; + } + + $prm = $this->sys_input; + $startId = isset($prm['start_id']) && intval($prm['start_id']) > 0 ? intval($prm['start_id']) : 15; + $endId = isset($prm['end_id']) && intval($prm['end_id']) > 0 ? intval($prm['end_id']) : 25; + + if ($startId > $endId) { + $tmp = $startId; + $startId = $endId; + $endId = $tmp; + } + + $sql = "SELECT * + FROM print_transaction + WHERE Print_TransactionID >= ? AND Print_TransactionID <= ? + ORDER BY Print_TransactionID ASC"; + $query = $this->db_onedev->query($sql, array($startId, $endId)); + if ($query) { + $rows = $query->result_array(); + $result = array( + "total" => count($rows), + "records" => $rows + ); + $this->sys_ok($result); + } else { + $this->sys_error_db("lookup_print_transaction", $this->db_onedev); + exit; + } + } +} diff --git a/application/controllers/tools/Rpt_t_002.php b/application/controllers/tools/Rpt_t_002.php index c6797334..f394c0d6 100644 --- a/application/controllers/tools/Rpt_t_002.php +++ b/application/controllers/tools/Rpt_t_002.php @@ -27,7 +27,10 @@ class Rpt_t_002 extends MY_Controller $username = 'ADMIN'; } - $an = $this->input->get('an', true); + $an = $this->input->get('AN', true); + if ($an === null || $an === '') { + $an = $this->input->get('an', true); + } if ($an === null) { $an = ''; } @@ -65,7 +68,10 @@ class Rpt_t_002 extends MY_Controller $username = 'ADMIN'; } - $an = $this->input->get('an', true); + $an = $this->input->get('AN', true); + if ($an === null || $an === '') { + $an = $this->input->get('an', true); + } if ($an === null) { $an = ''; } @@ -143,7 +149,8 @@ class Rpt_t_002 extends MY_Controller $pdf->SetFont('Arial', '', $fontBody); $pdf->Cell($labelW, $lineH, 'Telah diterima dari', 0, 0); $pdf->Cell($colonW, $lineH, ':', 0, 0, 'C'); - $pdf->Cell($valueW, $lineH, $this->safe_text((string) $patientName), 0, 1); + $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'); @@ -219,8 +226,8 @@ class Rpt_t_002 extends MY_Controller $ySign = max($pdf->GetY() + 4, $pageH - 42); $pdf->SetY($ySign); - $pdf->Rect($left, $ySign, 50, 8); 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'); diff --git a/application/controllers/tools/Rpt_t_002_eng.php b/application/controllers/tools/Rpt_t_002_eng.php new file mode 100644 index 00000000..bfc1fefc --- /dev/null +++ b/application/controllers/tools/Rpt_t_002_eng.php @@ -0,0 +1,295 @@ +sys_ok([ + 'message' => 'Use /tools/rpt_t_002_eng/pdf?T_OrderHeaderID= or /tools/rpt_t_002_eng/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_eng(?, ?, ?)'; + $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_eng(?, ?, ?)'; + $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('Report data not found'); + return; + } + + require_once APPPATH . 'third_party/fpdf/fpdf.php'; + + $first = $rows[0]; + $title = $this->pick_value($first, ['judul', 'title', 'report_name', 'nama_report'], 'RECEIPT'); + $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'], '-'); + $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'], '-'); + $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, 'Receive From', 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, 'Amount Receive', 0, 0); + $pdf->Cell($colonW, $lineH, ':', 0, 0, 'C'); + $pdf->Cell($valueW, $lineH, 'Rp. ' . $this->format_rupiah($grandTotal), 0, 1); + + $pdf->Cell($labelW, $lineH, 'Inword', 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, 'In payment examination laboratory :', 0, 1); + $pdf->Ln(1); + + $details = [ + ['Patient Name', $patientName], + ['PID/Reg. No', $pidReg], + ['Date', $orderDate], + ['Age / Sex Code', $umur . ' / ' . $this->pick_value($first, ['M_SexCode'], 'F')], + ['Phone', $phone], + ['Sender', $pengirim], + ['Company Type', str_ireplace('PROGRAM CICILAN (', '', rtrim((string) $mou, ')'))], + ['Address', $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, 'Examination :', 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, 'Price', 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, 'Grand Total', 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 = 'The settlement document is considered valid if the nominal above has been accept into designated bank account'; + $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 === 'PAID') { + $pdf->Rect($left, $ySign, 50, 8); + $pdf->SetFont('Arial', '', $fontBody); + $pdf->SetXY($left, $ySign + 0.5); + $pdf->Cell(50, 7, 'PAID', 0, 1, 'C'); + } + $pdf->SetFont('Arial', '', $fontBody); + $pdf->SetXY($pageW - $right - 48, $ySign + 1); + $pdf->Cell(48, 5, $this->safe_text($city) . ' , ' . date('M j 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 by :', 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_eng_' . $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)); + } +}