296 lines
11 KiB
PHP
296 lines
11 KiB
PHP
<?php
|
|
class Rpt_t_002_eng extends MY_Controller
|
|
{
|
|
public function __construct()
|
|
{
|
|
parent::__construct();
|
|
}
|
|
|
|
public function index()
|
|
{
|
|
$this->sys_ok([
|
|
'message' => 'Use /tools/rpt_t_002_eng/pdf?T_OrderHeaderID=<id> or /tools/rpt_t_002_eng/data?T_OrderHeaderID=<id>'
|
|
]);
|
|
}
|
|
|
|
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(['</br>', '<br>', '<br/>', '<br />'], ', ', $text));
|
|
}
|
|
}
|