SetDrawColor(0, 0, 0); // สีดำ $pdf->SetLineWidth(0.3); $pdf->Rect($x, $y, 4, 4); // วาดกรอบ 4x4 mm // วาดเครื่องหมายถูกถ้าเลือก if ($isChecked) { $pdf->SetLineWidth(0.5); // วาดเครื่องหมายถูก (checkmark) ด้วยเส้น $pdf->Line($x + 0.8, $y + 2, $x + 1.8, $y + 2.8); // เส้นแรก $pdf->Line($x + 1.8, $y + 2.8, $x + 3.2, $y + 1.2); // เส้นสอง } } // ฟังก์ชันแปลงวันที่เป็นภาษาไทย function thai_date($date) { if (empty($date) || $date == '0000-00-00') return ''; $thai_month_arr = array( "01" => "มกราคม", "02" => "กุมภาพันธ์", "03" => "มีนาคม", "04" => "เมษายน", "05" => "พฤษภาคม", "06" => "มิถุนายน", "07" => "กรกฎาคม", "08" => "สิงหาคม", "09" => "กันยายน", "10" => "ตุลาคม", "11" => "พฤศจิกายน", "12" => "ธันวาคม" ); $year = date("Y", strtotime($date)) + 543; $month = $thai_month_arr[date("m", strtotime($date))]; $day = date("d", strtotime($date)); return "$day $month $year"; } // ฟังก์ชันแปลงวันที่เป็นภาษาไทยแบบย่อ function thai_date_short($date) { if (empty($date) || $date == '0000-00-00') return ''; $thai_month_short_arr = array( "01" => "ม.ค.", "02" => "ก.พ.", "03" => "มี.ค.", "04" => "เม.ย.", "05" => "พ.ค.", "06" => "มิ.ย.", "07" => "ก.ค.", "08" => "ส.ค.", "09" => "ก.ย.", "10" => "ต.ค.", "11" => "พ.ย.", "12" => "ธ.ค." ); $year = date("Y", strtotime($date)) + 543; $month = $thai_month_short_arr[date("m", strtotime($date))]; $day = date("d", strtotime($date)); return "$day $month $year"; } // ฟังก์ชันสำหรับดึงข้อมูลจากตารางประเภทต่างๆ function getTypeData($table, $pdo) { try { $sql = "SELECT id, title FROM `{$table}` WHERE status = 1 ORDER BY id"; $stmt = $pdo->prepare($sql); $stmt->execute(); $result = $stmt->fetchAll(PDO::FETCH_ASSOC); // ถ้าไม่พบข้อมูลใน status = 1 ให้ลองดูทั้งหมด if (empty($result)) { $sql = "SELECT id, title FROM `{$table}` ORDER BY id"; $stmt = $pdo->prepare($sql); $stmt->execute(); $result = $stmt->fetchAll(PDO::FETCH_ASSOC); } return $result; } catch (PDOException $e) { return array(); } } // ฟังก์ชันสำหรับหาชื่อจาก ID function getNameById($id, $data) { foreach ($data as $item) { if ($item['id'] == $id) { return $item['title']; } } return 'ไม่ระบุ'; } // ดึงข้อมูลประเภทต่างๆ จากฐานข้อมูล $prefixs = getTypeData('prefix', $pdo); $genders = getTypeData('typeSex', $pdo); $occupations = getTypeData('typeOccupation', $pdo); $statuses = getTypeData('typeStatus', $pdo); $educations = getTypeData('typeEducational', $pdo); $relationships = getTypeData('typeRelationship', $pdo); $helpTypes = getTypeData('typeGiveHelp', $pdo); $serviceTypes = getTypeData('typeService', $pdo); $socialAspects = getTypeData('typesocialSspects', $pdo); $eduOccupations = getTypeData('typeEduOccupation', $pdo); // ดึงข้อมูลจากตาราง success_types try { $sql = "SELECT id, title FROM typeServiceSuccess ORDER BY id"; $stmt = $pdo->prepare($sql); $stmt->execute(); $successTypes = $stmt->fetchAll(PDO::FETCH_ASSOC); } catch (PDOException $e) { $successTypes = array(); } // ดึงข้อมูลจากตาราง appointments try { $sql = "SELECT id, title FROM typeAppointment ORDER BY id"; $stmt = $pdo->prepare($sql); $stmt->execute(); $appointments = $stmt->fetchAll(PDO::FETCH_ASSOC); } catch (PDOException $e) { $appointments = array(); } // ดึงข้อมูล sub-menu สำหรับ typeGiveHelp $helpSubTypes = array(); try { $stmt = $pdo->prepare("SELECT id, title, typeGiveHelpId FROM typegivehelpsub WHERE status = 1 ORDER BY typeGiveHelpId, id"); $stmt->execute(); $helpSubData = $stmt->fetchAll(PDO::FETCH_ASSOC); // จัดกลุ่ม sub-types ตาม parent ID foreach ($helpSubData as $sub) { $helpSubTypes[$sub['typeGiveHelpId']][] = $sub; } } catch (PDOException $e) { $helpSubTypes = array(); } // ดึงข้อมูลหลักจากตาราง individual_counseling try { $stmt = $pdo->prepare("SELECT * FROM individual_counseling WHERE id = ? AND username = ? AND schoolID = ?"); $stmt->execute(array($report_id, $username, $schoolID)); $editData = $stmt->fetch(PDO::FETCH_ASSOC); if (!$editData) { die('ไม่พบข้อมูลรายงาน ID: ' . $report_id); } } catch (PDOException $e) { die('เกิดข้อผิดพลาดในการดึงข้อมูล: ' . $e->getMessage()); } // ดึงข้อมูลประวัติการให้บริการ $serviceHistory = array(); try { $stmt = $pdo->prepare("SELECT * FROM individual_counseling_service WHERE individual_counseling_id = ? ORDER BY service_request_date DESC, created_at DESC"); $stmt->execute(array($report_id)); $serviceHistory = $stmt->fetchAll(PDO::FETCH_ASSOC); // ถ้าไม่มีข้อมูลในตาราง individual_counseling_service ให้ใช้ข้อมูลจาก individual_counseling if (empty($serviceHistory) && !empty($editData['service_request_date'])) { $serviceHistory = array(array( 'service_request_number' => 1, 'service_request_date' => $editData['service_request_date'], 'service_request_details' => isset($editData['service_request_details']) ? $editData['service_request_details'] : '', 'service_success_id' => isset($editData['service_success_id']) ? $editData['service_success_id'] : null, 'service_failure_reason' => isset($editData['service_failure_reason']) ? $editData['service_failure_reason'] : '', 'follow_up_id' => isset($editData['follow_up_id']) ? $editData['follow_up_id'] : null, 'follow_up_date' => isset($editData['follow_up_date']) ? $editData['follow_up_date'] : '', 'created_at' => isset($editData['created_at']) ? $editData['created_at'] : '', 'education_issues' => isset($editData['education_issues']) ? $editData['education_issues'] : '', 'career_issues' => isset($editData['career_issues']) ? $editData['career_issues'] : '', 'personal_issues' => isset($editData['personal_issues']) ? $editData['personal_issues'] : '', 'education_other' => isset($editData['education_other']) ? $editData['education_other'] : '', 'career_other' => isset($editData['career_other']) ? $editData['career_other'] : '', 'personal_other' => isset($editData['personal_other']) ? $editData['personal_other'] : '', 'recommendations' => isset($editData['recommendations']) ? $editData['recommendations'] : '', 'referral_services' => isset($editData['referral_services']) ? $editData['referral_services'] : '', 'referral_other' => isset($editData['referral_other']) ? $editData['referral_other'] : '' )); } } catch (PDOException $e) { $serviceHistory = array(); } // สร้างเอกสาร PDF $pdf = new FPDF('P', 'mm', 'A4'); $pdf->SetMargins(20, 20, 20); // เพิ่มฟอนต์ไทย $pdf->AddFont('THSarabunNew', 'b', 'THSarabunNew Bold.php'); $pdf->AddFont('THSarabunNew', '', 'THSarabunNew.php'); $pdf->AddFont('THSarabunNew', 'i', 'THSarabunNew Italic.php'); $pdf->AddFont('THSarabunNew', 'bi', 'THSarabunNew BoldItalic.php'); $pdf->AddPage(); // หัวเรื่อง $pdf->SetFont('THSarabunNew', 'b', 18); $pdf->Cell(0, 10, thai_text('แบบบันทึกข้อมูลการให้บริการคำปรึกษา สกร.'), 0, 1, 'C'); $pdf->SetFont('THSarabunNew', 'B', 16); $pdf->Cell(0, 8, thai_text('บริการให้คำปรึกษารายบุคคล'), 0, 1, 'C'); $pdf->Ln(5); // ตอนที่ 1 ข้อมูลทั่วไป $pdf->SetFont('THSarabunNew', 'B', 16); $pdf->Cell(0, 8, thai_text('ตอนที่ 1 ข้อมูลทั่วไป'), 0, 1, 'L'); $pdf->Ln(2); $pdf->SetFont('THSarabunNew', '', 14); // 1.1 คำนำหน้าชื่อ $prefix = getNameById(isset($editData['prefix_id']) ? $editData['prefix_id'] : '', $prefixs); $pdf->Cell(0, 8, thai_text('1.1 คำนำหน้าชื่อ : ' . $prefix), 0, 1, 'L'); // 1.2 ชื่อ $first_name = isset($editData['first_name']) ? $editData['first_name'] : ''; $pdf->Cell(0, 8, thai_text('1.2 ชื่อ : ' . $first_name), 0, 1, 'L'); // 1.3 นามสกุล $last_name = isset($editData['last_name']) ? $editData['last_name'] : ''; $pdf->Cell(0, 8, thai_text('1.3 นามสกุล : ' . $last_name), 0, 1, 'L'); // 1.4 วัน/เดือน/ปี เกิด $birth_date = thai_date(isset($editData['birth_date']) ? $editData['birth_date'] : ''); $pdf->Cell(0, 8, thai_text('1.4 วัน/เดือน/ปี เกิด : ' . $birth_date), 0, 1, 'L'); // 1.5 เพศ $pdf->Cell(0, 8, thai_text('1.5 เพศ '), 0, 1, 'L'); $gender_id = isset($editData['gender_id']) ? $editData['gender_id'] : ''; foreach ($genders as $gender) { $isSelected = ($gender['id'] == $gender_id); $x = $pdf->GetX() + 8; $y = $pdf->GetY() + 1; drawCheckbox($pdf, $x, $y, $isSelected); $pdf->SetXY($x + 6, $y - 1); $pdf->Cell(0, 6, thai_text($gender['title']), 0, 1, 'L'); } // 1.6 เชื้อชาติ $ethnicity = isset($editData['ethnicity']) ? $editData['ethnicity'] : ''; $pdf->Cell(0, 8, thai_text('1.6 เชื้อชาติ : ' . $ethnicity), 0, 1, 'L'); // 1.7 สัญชาติ $nationality = isset($editData['nationality']) ? $editData['nationality'] : ''; $pdf->Cell(0, 8, thai_text('1.7 สัญชาติ : ' . $nationality), 0, 1, 'L'); // 1.8 ศาสนา $religion = isset($editData['religion']) ? $editData['religion'] : ''; $pdf->Cell(0, 8, thai_text('1.8 ศาสนา : ' . $religion), 0, 1, 'L'); // 1.9 หมู่โลหิต $blood_type = isset($editData['blood_type']) ? $editData['blood_type'] : ''; $pdf->Cell(0, 8, thai_text('1.9 หมู่โลหิต: ' . $blood_type), 0, 1, 'L'); // ตรวจสอบพื้นที่สำหรับ 1.10 ประกอบอาชีพ (เหลือพื้นที่อย่างน้อย 50mm) if ($pdf->GetY() > 220) { $pdf->AddPage(); } // 1.10 ประกอบอาชีพ $pdf->Cell(0, 8, thai_text('1.10 ประกอบอาชีพ'), 0, 1, 'L'); $occupation_id = isset($editData['occupation_id']) ? $editData['occupation_id'] : ''; foreach ($occupations as $occupation) { $isSelected = ($occupation['id'] == $occupation_id); $x = $pdf->GetX() + 8; $y = $pdf->GetY() + 1; drawCheckbox($pdf, $x, $y, $isSelected); $pdf->SetXY($x + 6, $y - 1); $pdf->Cell(0, 6, thai_text($occupation['title']), 0, 1, 'L'); } // แสดง "อื่น ๆ" ถ้ามีข้อมูล if (!empty($editData['occupation_other'])) { $x = $pdf->GetX() + 8; $y = $pdf->GetY() + 1; drawCheckbox($pdf, $x, $y, true); $pdf->SetXY($x + 6, $y - 1); $pdf->Cell(0, 6, thai_text('อื่น ๆ: ' . $editData['occupation_other']), 0, 1, 'L'); } // ตรวจสอบพื้นที่สำหรับ 1.11 สถานภาพ (เหลือพื้นที่อย่างน้อย 50mm) if ($pdf->GetY() > 220) { $pdf->AddPage(); } // 1.11 สถานภาพ $pdf->Cell(0, 8, thai_text('1.11 สถานภาพ'), 0, 1, 'L'); $marital_status_id = isset($editData['marital_status_id']) ? $editData['marital_status_id'] : ''; foreach ($statuses as $status) { $isSelected = ($status['id'] == $marital_status_id); $x = $pdf->GetX() + 8; $y = $pdf->GetY() + 1; drawCheckbox($pdf, $x, $y, $isSelected); $pdf->SetXY($x + 6, $y - 1); $pdf->Cell(0, 6, thai_text($status['title']), 0, 1, 'L'); } // ตรวจสอบพื้นที่สำหรับ 1.12 ที่อยู่ปัจจุบันที่สามารถติดต่อได้ (เหลือพื้นที่อย่างน้อย 50mm) if ($pdf->GetY() > 220) { $pdf->AddPage(); } // 1.12 ที่อยู่ปัจจุบันที่สามารถติดต่อได้ $pdf->Cell(0, 8, thai_text('1.12 ที่อยู่ปัจจุบันที่สามารถติดต่อได้'), 0, 1, 'L'); // 1.12.1 จังหวัด $province = isset($editData['province']) ? $editData['province'] : ''; $pdf->Cell(8, 6, '', 0, 0, 'L'); // เยื้อง 1 แท็บ $pdf->Cell(0, 6, thai_text('1.12.1 จังหวัด : ' . $province), 0, 1, 'L'); // 1.12.2 อำเภอ $district = isset($editData['district']) ? $editData['district'] : ''; $pdf->Cell(8, 6, '', 0, 0, 'L'); // เยื้อง 1 แท็บ $pdf->Cell(0, 6, thai_text('1.12.2 อำเภอ : ' . $district), 0, 1, 'L'); // 1.12.3 ตำบล $subdistrict = isset($editData['subdistrict']) ? $editData['subdistrict'] : ''; $pdf->Cell(8, 6, '', 0, 0, 'L'); // เยื้อง 1 แท็บ $pdf->Cell(0, 6, thai_text('1.12.3 ตำบล : ' . $subdistrict), 0, 1, 'L'); // ตรวจสอบว่าต้องขึ้นหน้าใหม่หรือไม่ if ($pdf->GetY() > 250) { $pdf->AddPage(); } // 1.12.4 ถนน $street = isset($editData['street']) ? $editData['street'] : ''; $pdf->Cell(8, 6, '', 0, 0, 'L'); // เยื้อง 1 แท็บ $pdf->Cell(0, 6, thai_text('1.12.4 ถนน : ' . $street), 0, 1, 'L'); // 1.12.5 อาคาร/หมู่บ้าน $building = isset($editData['building']) ? $editData['building'] : ''; $pdf->Cell(8, 6, '', 0, 0, 'L'); // เยื้อง 1 แท็บ $pdf->Cell(0, 6, thai_text('1.12.5 อาคาร/หมู่บ้าน: ' . $building), 0, 1, 'L'); // 1.12.6 หมู่ที่ $village_number = isset($editData['village_number']) ? $editData['village_number'] : ''; $pdf->Cell(8, 6, '', 0, 0, 'L'); // เยื้อง 1 แท็บ $pdf->Cell(0, 6, thai_text('1.12.6 หมู่ที่: ' . $village_number), 0, 1, 'L'); // 1.12.7 บ้านเลขที่ $house_number = isset($editData['house_number']) ? $editData['house_number'] : ''; $pdf->Cell(8, 6, '', 0, 0, 'L'); // เยื้อง 1 แท็บ $pdf->Cell(0, 6, thai_text('1.12.7 บ้านเลขที่: ' . $house_number), 0, 1, 'L'); // 1.13 หมายเลขโทรศัพท์มือถือ $phone = isset($editData['phone']) ? $editData['phone'] : ''; $pdf->Cell(0, 8, thai_text('1.13 หมายเลขโทรศัพท์มือถือ: ' . $phone), 0, 1, 'L'); // 1.14 ID LINE $line_id = isset($editData['line_id']) ? $editData['line_id'] : ''; $pdf->Cell(0, 8, thai_text('1.14 ID LINE: ' . $line_id), 0, 1, 'L'); // 1.15 E-Mail $email = isset($editData['email']) ? $editData['email'] : ''; $pdf->Cell(0, 8, thai_text('1.15 E-Mail: ' . $email), 0, 1, 'L'); // ตรวจสอบพื้นที่สำหรับ 1.16 ประเภทผู้รับบริการ (เหลือพื้นที่อย่างน้อย 50mm) if ($pdf->GetY() > 220) { $pdf->AddPage(); } // 1.16 ประเภทผู้รับบริการ $pdf->Cell(0, 8, thai_text('1.16 ประเภทผู้รับบริการ'), 0, 1, 'L'); $service_type_id = isset($editData['service_type_id']) ? $editData['service_type_id'] : ''; foreach ($serviceTypes as $serviceType) { $isSelected = ($serviceType['id'] == $service_type_id); $x = $pdf->GetX() + 8; $y = $pdf->GetY() + 1; drawCheckbox($pdf, $x, $y, $isSelected); $pdf->SetXY($x + 6, $y - 1); $pdf->Cell(0, 6, thai_text($serviceType['title']), 0, 1, 'L'); } // 1.17 ผู้ติดต่อกรณีฉุกเฉิน $pdf->Cell(0, 8, thai_text('1.17 ผู้ติดต่อกรณีฉุกเฉิน'), 0, 1, 'L'); // 1.17.1 ชื่อ $emergency_first_name = isset($editData['emergency_first_name']) ? $editData['emergency_first_name'] : ''; $pdf->Cell(8, 8, '', 0, 0, 'L'); // เยื้อง 1 แท็บ $pdf->Cell(0, 8, thai_text('1.17.1 ชื่อ: ' . $emergency_first_name), 0, 1, 'L'); // 1.17.2 สกุล $emergency_last_name = isset($editData['emergency_last_name']) ? $editData['emergency_last_name'] : ''; $pdf->Cell(8, 8, '', 0, 0, 'L'); // เยื้อง 1 แท็บ $pdf->Cell(0, 8, thai_text('1.17.2 สกุล: ' . $emergency_last_name), 0, 1, 'L'); // ตรวจสอบพื้นที่สำหรับ 1.17.3 ความสัมพันธ์ (เหลือพื้นที่อย่างน้อย 50mm) if ($pdf->GetY() > 220) { $pdf->AddPage(); } // 1.17.3 ความสัมพันธ์ $pdf->Cell(8, 8, '', 0, 0, 'L'); // เยื้อง 1 แท็บ $pdf->Cell(0, 8, thai_text('1.17.3 ความสัมพันธ์'), 0, 1, 'L'); $emergency_relation_id = isset($editData['emergency_relation_id']) ? $editData['emergency_relation_id'] : ''; foreach ($relationships as $relationship) { $isSelected = ($relationship['id'] == $emergency_relation_id); $x = $pdf->GetX() + 16; $y = $pdf->GetY() + 1; drawCheckbox($pdf, $x, $y, $isSelected); $pdf->SetXY($x + 6, $y - 1); $pdf->Cell(0, 6, thai_text($relationship['title']), 0, 1, 'L'); } // แสดง "อื่น ๆ" ถ้ามีข้อมูล if (!empty($editData['emergency_relation_other'])) { $x = $pdf->GetX() + 16; $y = $pdf->GetY() + 1; drawCheckbox($pdf, $x, $y, true); $pdf->SetXY($x + 6, $y - 1); $pdf->Cell(0, 6, thai_text('อื่น ๆ: ' . $editData['emergency_relation_other']), 0, 1, 'L'); } // 1.17.4 หมายเลขโทรศัพท์มือถือ $emergency_phone = isset($editData['emergency_phone']) ? $editData['emergency_phone'] : ''; $pdf->Cell(8, 8, '', 0, 0, 'L'); // เยื้อง 1 แท็บ $pdf->Cell(0, 8, thai_text('1.17.4 หมายเลขโทรศัพท์มือถือ: ' . $emergency_phone), 0, 1, 'L'); // คำอธิบายข้อมูล (กรอบข้อความ) $pdf->Ln(5); $pdf->SetDrawColor(0, 0, 0); $pdf->SetLineWidth(0.5); $y_start = $pdf->GetY(); // วาดกรอบ (เพิ่มความสูงเพื่อรองรับลงชื่อ 2 บรรทัด) $pdf->Rect(20, $y_start, 170, 57); $pdf->SetXY(22, $y_start + 2); $pdf->SetFont('THSarabunNew', 'B', 12); $pdf->Cell(0, 6, thai_text('คำอธิบายข้อมูล:'), 0, 1, 'L'); $pdf->SetXY(22, $pdf->GetY()); $pdf->SetFont('THSarabunNew', '', 12); $explanation_text = 'ข้อมูลที่ท่านให้มาในการทำฟอร์มนี้ ถือเป็นข้อมูลส่วนบุคคลที่มีความลับและจะถูกนำไปใช้เพื่อวัตถุประสงค์ในการให้บริการให้คำปรึกษาเท่านั้น เราจะเก็บรักษาข้อมูลของท่านเป็นความลับอย่างเคร่งครัด และจะไม่เปิดเผยข้อมูลของท่านต่อบุคคลภายนอกโดยไม่ได้รับความยินยอมจากท่าน ยกเว้นในกรณีที่กฎหมายกำหนด'; // แบ่งข้อความเป็นหลายบรรทัด $lines = explode(' ', $explanation_text); $current_line = ''; $line_height = 4; $max_width = 166; foreach ($lines as $word) { $test_line = $current_line . ($current_line ? ' ' : '') . $word; if ($pdf->GetStringWidth(thai_text($test_line)) > $max_width) { if ($current_line) { $pdf->Cell(0, $line_height, thai_text($current_line), 0, 1, 'L'); $pdf->SetX(22); $current_line = $word; } else { $pdf->Cell(0, $line_height, thai_text($word), 0, 1, 'L'); $pdf->SetX(22); } } else { $current_line = $test_line; } } if ($current_line) { $pdf->Cell(0, $line_height, thai_text($current_line), 0, 1, 'L'); } $pdf->Ln(3); $pdf->SetXY(22, $pdf->GetY()); $pdf->SetFont('THSarabunNew', 'B', 12); $pdf->Cell(0, 6, thai_text('คำยินยอม:'), 0, 1, 'L'); $pdf->SetXY(22, $pdf->GetY()); $pdf->SetFont('THSarabunNew', '', 12); $explanation_text2 = 'ข้าพเจ้ายืนยันว่าได้รับและเข้าใจข้อมูลข้างต้นแล้ว และข้าพเจ้าให้ความยินยอมในการให้ข้อมูลของข้าพเจ้าแก่ กรมส่งเสริมการเรียนรู้ เพื่อวัตถุประสงค์ที่ได้ระบุไว้ข้างต้น'; $lines = explode(' ', $explanation_text2); $current_line = ''; foreach ($lines as $word) { $test_line = $current_line . ($current_line ? ' ' : '') . $word; if ($pdf->GetStringWidth(thai_text($test_line)) > $max_width) { if ($current_line) { $pdf->Cell(0, $line_height, thai_text($current_line), 0, 1, 'L'); $pdf->SetX(22); $current_line = $word; } else { $pdf->Cell(0, $line_height, thai_text($word), 0, 1, 'L'); $pdf->SetX(22); } } else { $current_line = $test_line; } } if ($current_line) { $pdf->Cell(0, $line_height, thai_text($current_line), 0, 1, 'L'); } $pdf->Ln(5); $pdf->SetXY(22, $pdf->GetY()); $pdf->Cell(0, 6, thai_text('ลงชื่อ.................................................................................. ผู้รับบริการ'), 0, 1, 'C'); $pdf->SetXY(22, $pdf->GetY()); $pdf->Cell(0, 6, thai_text('วันที่.....................................................'), 0, 1, 'C'); // ตอนที่ 2-4 ประวัติการให้บริการ - ขึ้นหน้าใหม่ $pdf->AddPage(); // ตอนที่ 2 ประวัติการขอรับบริการ (ตาราง) $pdf->SetFont('THSarabunNew', 'B', 16); $pdf->Cell(0, 8, thai_text('ตอนที่ 2 ประวัติการขอรับบริการ'), 0, 1, 'L'); $pdf->Ln(2); // สร้างตาราง $pdf->SetFont('THSarabunNew', 'B', 12); $pdf->SetDrawColor(0, 0, 0); $pdf->SetLineWidth(0.3); // หัวตาราง $pdf->Cell(10, 8, thai_text('ครั้งที่'), 1, 0, 'C'); $pdf->Cell(25, 8, thai_text('วันเดือนปี'), 1, 0, 'C'); $pdf->Cell(85, 8, thai_text('รายละเอียด'), 1, 0, 'C'); $pdf->Cell(25, 8, thai_text('ผลการให้บริการ'), 1, 0, 'C'); $pdf->Cell(25, 8, thai_text('หมายเหตุ'), 1, 1, 'C'); // เนื้อหาตาราง $pdf->SetFont('THSarabunNew', '', 12); if (!empty($serviceHistory)) { foreach ($serviceHistory as $index => $service) { $service_number = isset($service['service_request_number']) ? $service['service_request_number'] : ($index + 1); $service_date = isset($service['service_request_date']) ? $service['service_request_date'] : ''; // แสดงเฉพาะ service_request_details $service_details = isset($service['service_request_details']) ? trim($service['service_request_details']) : ''; // ถ้าไม่มีรายละเอียดเลย if (empty($service_details)) { $service_details = 'ไม่ระบุ'; } // จำกัดความยาวให้พอดีกับช่องตาราง (ความกว้าง 85mm) if (mb_strlen($service_details, 'UTF-8') > 65) { $service_details = mb_substr($service_details, 0, 62, 'UTF-8') . '...'; } $success_id = isset($service['service_success_id']) ? $service['service_success_id'] : ''; $success_text = ''; if ($success_id == 1) { $success_text = 'สำเร็จ'; } elseif ($success_id == 2) { $success_text = 'ไม่สำเร็จ'; } else { $success_text = 'ไม่ระบุ'; } // หมายเหตุ - แสดงข้อมูลการนัดหมายติดตาม $remark = ''; if (!empty($service['follow_up_date'])) { $follow_up_name = ''; if (!empty($service['follow_up_id'])) { $follow_up_name = getNameById($service['follow_up_id'], $appointments); if ($follow_up_name !== 'ไม่ระบุ') { $remark = 'นัด: ' . thai_date_short($service['follow_up_date']); } } else { $remark = 'นัด: ' . thai_date_short($service['follow_up_date']); } } $pdf->Cell(10, 8, thai_text($service_number), 1, 0, 'C'); $pdf->Cell(25, 8, thai_text(thai_date($service_date)), 1, 0, 'C'); $pdf->Cell(85, 8, thai_text($service_details), 1, 0, 'L'); $pdf->Cell(25, 8, thai_text($success_text), 1, 0, 'C'); $pdf->Cell(25, 8, thai_text($remark), 1, 1, 'C'); } } else { // แถวว่าง for ($i = 0; $i < 3; $i++) { $pdf->Cell(10, 8, '', 1, 0, 'C'); $pdf->Cell(25, 8, '', 1, 0, 'C'); $pdf->Cell(85, 8, '', 1, 0, 'C'); $pdf->Cell(25, 8, '', 1, 0, 'C'); $pdf->Cell(25, 8, '', 1, 1, 'C'); } } $pdf->Ln(10); // ตอนที่ 3 ข้อมูลการขอรับบริการ และ ตอนที่ 4 ผลการให้บริการ - ขึ้นหน้าใหม่ if (!empty($serviceHistory)) { // แสดงข้อมูลของแต่ละครั้ง foreach ($serviceHistory as $index => $service) { $pdf->AddPage(); // หัวข้อประวัติการให้บริการ (จัดกึ่งกลาง) $pdf->SetFont('THSarabunNew', 'B', 18); $pdf->Cell(0, 10, thai_text('ประวัติการให้บริการ ครั้งที่ ' . (isset($service['service_request_number']) ? $service['service_request_number'] : ($index + 1))), 0, 1, 'C'); $pdf->Ln(5); $pdf->SetFont('THSarabunNew', 'B', 16); $pdf->Cell(0, 8, thai_text('ตอนที่ 3 ข้อมูลการขอรับบริการ'), 0, 1, 'L'); $pdf->Ln(2); $pdf->SetFont('THSarabunNew', '', 14); // 3.1 ครั้งที่ขอรับบริการ $service_number = isset($service['service_request_number']) ? $service['service_request_number'] : ($index + 1); $pdf->Cell(0, 8, thai_text('3.1 ครั้งที่ขอรับบริการ: ' . $service_number), 0, 1, 'L'); // 3.2 วันที่ขอรับบริการ $service_date = thai_date(isset($service['service_request_date']) ? $service['service_request_date'] : ''); $pdf->Cell(0, 8, thai_text('3.2 วันที่ขอรับบริการ*: ' . $service_date), 0, 1, 'L'); // 3.3 รายละเอียดที่ขอรับบริการ $pdf->Cell(0, 8, thai_text('3.3 รายละเอียดที่ขอรับบริการ พอสังเขป :'), 0, 1, 'L'); $service_details = isset($service['service_request_details']) ? $service['service_request_details'] : ''; if (!empty($service_details)) { $lines = explode("\n", $service_details); foreach ($lines as $line) { $line = trim($line); if (!empty($line)) { // แบ่งข้อความเป็นหลายบรรทัดถ้าเกินขอบกระดาษ $words = explode(' ', $line); $current_line = ''; $max_width = 160; // ความกว้างสูงสุดของข้อความ (มม.) foreach ($words as $word) { $test_line = $current_line . ($current_line ? ' ' : '') . $word; if ($pdf->GetStringWidth(thai_text($test_line)) > $max_width) { if ($current_line) { $pdf->Cell(8, 6, '', 0, 0, 'L'); $pdf->Cell(0, 6, thai_text($current_line), 0, 1, 'L'); $current_line = $word; } else { $pdf->Cell(8, 6, '', 0, 0, 'L'); $pdf->Cell(0, 6, thai_text($word), 0, 1, 'L'); } } else { $current_line = $test_line; } } if ($current_line) { $pdf->Cell(8, 6, '', 0, 0, 'L'); $pdf->Cell(0, 6, thai_text($current_line), 0, 1, 'L'); } } } } $pdf->Ln(2); // 3.4 วิเคราะห์ประเด็นการขอรับบริการ $pdf->Cell(0, 8, thai_text('3.4 วิเคราะห์ประเด็นการขอรับบริการ*'), 0, 1, 'L'); // ตรวจสอบพื้นที่สำหรับด้านการศึกษา (เหลือพื้นที่อย่างน้อย 50mm) if ($pdf->GetY() > 220) { $pdf->AddPage(); } // ด้านการศึกษา $pdf->Cell(8, 6, '', 0, 0, 'L'); $pdf->Cell(0, 6, thai_text('ด้านการศึกษา'), 0, 1, 'L'); $selectedEducation = !empty($service['education_issues']) ? json_decode($service['education_issues'], true) : array(); foreach ($educations as $education) { $isSelected = in_array($education['id'], $selectedEducation); $x = $pdf->GetX() + 16; $y = $pdf->GetY() + 1; drawCheckbox($pdf, $x, $y, $isSelected); $pdf->SetXY($x + 6, $y - 1); // แบ่งข้อความเป็นหลายบรรทัดถ้าเกินขอบกระดาษ $title = $education['title']; $words = explode(' ', $title); $current_line = ''; $max_width = 140; // ความกว้างสูงสุด (เหลือพื้นที่สำหรับ checkbox) foreach ($words as $word) { $test_line = $current_line . ($current_line ? ' ' : '') . $word; if ($pdf->GetStringWidth(thai_text($test_line)) > $max_width) { if ($current_line) { $pdf->Cell(0, 6, thai_text($current_line), 0, 1, 'L'); $pdf->SetX($x + 6); $current_line = $word; } else { $pdf->Cell(0, 6, thai_text($word), 0, 1, 'L'); $pdf->SetX($x + 6); } } else { $current_line = $test_line; } } if ($current_line) { $pdf->Cell(0, 6, thai_text($current_line), 0, 1, 'L'); } } if (!empty($service['education_other'])) { $x = $pdf->GetX() + 16; $y = $pdf->GetY() + 1; drawCheckbox($pdf, $x, $y, true); $pdf->SetXY($x + 6, $y - 1); // แบ่งข้อความเป็นหลายบรรทัดถ้าเกินขอบกระดาษ $title = 'อื่น ๆ: ' . $service['education_other']; $words = explode(' ', $title); $current_line = ''; $max_width = 140; foreach ($words as $word) { $test_line = $current_line . ($current_line ? ' ' : '') . $word; if ($pdf->GetStringWidth(thai_text($test_line)) > $max_width) { if ($current_line) { $pdf->Cell(0, 6, thai_text($current_line), 0, 1, 'L'); $pdf->SetX($x + 6); $current_line = $word; } else { $pdf->Cell(0, 6, thai_text($word), 0, 1, 'L'); $pdf->SetX($x + 6); } } else { $current_line = $test_line; } } if ($current_line) { $pdf->Cell(0, 6, thai_text($current_line), 0, 1, 'L'); } } // ตรวจสอบพื้นที่สำหรับด้านอาชีพ (เหลือพื้นที่อย่างน้อย 50mm) if ($pdf->GetY() > 220) { $pdf->AddPage(); } // ด้านอาชีพ $pdf->Cell(8, 6, '', 0, 0, 'L'); $pdf->Cell(0, 6, thai_text('ด้านอาชีพ'), 0, 1, 'L'); $selectedCareer = !empty($service['career_issues']) ? json_decode($service['career_issues'], true) : array(); foreach ($eduOccupations as $occupation) { $isSelected = in_array($occupation['id'], $selectedCareer); $x = $pdf->GetX() + 16; $y = $pdf->GetY() + 1; drawCheckbox($pdf, $x, $y, $isSelected); $pdf->SetXY($x + 6, $y - 1); // แบ่งข้อความเป็นหลายบรรทัดถ้าเกินขอบกระดาษ $title = $occupation['title']; $words = explode(' ', $title); $current_line = ''; $max_width = 140; foreach ($words as $word) { $test_line = $current_line . ($current_line ? ' ' : '') . $word; if ($pdf->GetStringWidth(thai_text($test_line)) > $max_width) { if ($current_line) { $pdf->Cell(0, 6, thai_text($current_line), 0, 1, 'L'); $pdf->SetX($x + 6); $current_line = $word; } else { $pdf->Cell(0, 6, thai_text($word), 0, 1, 'L'); $pdf->SetX($x + 6); } } else { $current_line = $test_line; } } if ($current_line) { $pdf->Cell(0, 6, thai_text($current_line), 0, 1, 'L'); } } if (!empty($service['career_other'])) { $x = $pdf->GetX() + 16; $y = $pdf->GetY() + 1; drawCheckbox($pdf, $x, $y, true); $pdf->SetXY($x + 6, $y - 1); // แบ่งข้อความเป็นหลายบรรทัดถ้าเกินขอบกระดาษ $title = 'อื่น ๆ: ' . $service['career_other']; $words = explode(' ', $title); $current_line = ''; $max_width = 140; foreach ($words as $word) { $test_line = $current_line . ($current_line ? ' ' : '') . $word; if ($pdf->GetStringWidth(thai_text($test_line)) > $max_width) { if ($current_line) { $pdf->Cell(0, 6, thai_text($current_line), 0, 1, 'L'); $pdf->SetX($x + 6); $current_line = $word; } else { $pdf->Cell(0, 6, thai_text($word), 0, 1, 'L'); $pdf->SetX($x + 6); } } else { $current_line = $test_line; } } if ($current_line) { $pdf->Cell(0, 6, thai_text($current_line), 0, 1, 'L'); } } // ตรวจสอบพื้นที่สำหรับด้านส่วนตัว/สังคม (เหลือพื้นที่อย่างน้อย 50mm) if ($pdf->GetY() > 220) { $pdf->AddPage(); } // ด้านส่วนตัว/สังคม $pdf->Cell(8, 6, '', 0, 0, 'L'); $pdf->Cell(0, 6, thai_text('ด้านส่วนตัว/สังคม'), 0, 1, 'L'); $selectedPersonal = !empty($service['personal_issues']) ? json_decode($service['personal_issues'], true) : array(); foreach ($socialAspects as $aspect) { $isSelected = in_array($aspect['id'], $selectedPersonal); $x = $pdf->GetX() + 16; $y = $pdf->GetY() + 1; drawCheckbox($pdf, $x, $y, $isSelected); $pdf->SetXY($x + 6, $y - 1); // แบ่งข้อความเป็นหลายบรรทัดถ้าเกินขอบกระดาษ $title = $aspect['title']; $words = explode(' ', $title); $current_line = ''; $max_width = 140; foreach ($words as $word) { $test_line = $current_line . ($current_line ? ' ' : '') . $word; if ($pdf->GetStringWidth(thai_text($test_line)) > $max_width) { if ($current_line) { $pdf->Cell(0, 6, thai_text($current_line), 0, 1, 'L'); $pdf->SetX($x + 6); $current_line = $word; } else { $pdf->Cell(0, 6, thai_text($word), 0, 1, 'L'); $pdf->SetX($x + 6); } } else { $current_line = $test_line; } } if ($current_line) { $pdf->Cell(0, 6, thai_text($current_line), 0, 1, 'L'); } } if (!empty($service['personal_other'])) { $x = $pdf->GetX() + 16; $y = $pdf->GetY() + 1; drawCheckbox($pdf, $x, $y, true); $pdf->SetXY($x + 6, $y - 1); // แบ่งข้อความเป็นหลายบรรทัดถ้าเกินขอบกระดาษ $title = 'อื่น ๆ: ' . $service['personal_other']; $words = explode(' ', $title); $current_line = ''; $max_width = 140; foreach ($words as $word) { $test_line = $current_line . ($current_line ? ' ' : '') . $word; if ($pdf->GetStringWidth(thai_text($test_line)) > $max_width) { if ($current_line) { $pdf->Cell(0, 6, thai_text($current_line), 0, 1, 'L'); $pdf->SetX($x + 6); $current_line = $word; } else { $pdf->Cell(0, 6, thai_text($word), 0, 1, 'L'); $pdf->SetX($x + 6); } } else { $current_line = $test_line; } } if ($current_line) { $pdf->Cell(0, 6, thai_text($current_line), 0, 1, 'L'); } } // 3.5 สิ่งที่ดำเนินการหรือข้อแนะนำ $pdf->Ln(3); $pdf->Cell(0, 8, thai_text('3.5 สิ่งที่ดำเนินการหรือข้อแนะนำที่ให้แก่ผู้รับบริการ พอสังเขป'), 0, 1, 'L'); $recommendations = isset($service['recommendations']) ? $service['recommendations'] : ''; if (!empty($recommendations)) { $lines = explode("\n", $recommendations); foreach ($lines as $line) { $line = trim($line); if (!empty($line)) { $words = explode(' ', $line); $current_line = ''; $max_width = 160; foreach ($words as $word) { $test_line = $current_line . ($current_line ? ' ' : '') . $word; if ($pdf->GetStringWidth(thai_text($test_line)) > $max_width) { if ($current_line) { $pdf->Cell(8, 6, '', 0, 0, 'L'); $pdf->Cell(0, 6, thai_text($current_line), 0, 1, 'L'); $current_line = $word; } else { $pdf->Cell(8, 6, '', 0, 0, 'L'); $pdf->Cell(0, 6, thai_text($word), 0, 1, 'L'); } } else { $current_line = $test_line; } } if ($current_line) { $pdf->Cell(8, 6, '', 0, 0, 'L'); $pdf->Cell(0, 6, thai_text($current_line), 0, 1, 'L'); } } } } // ตอนที่ 4 ผลการให้บริการ $pdf->Ln(5); $pdf->SetFont('THSarabunNew', 'B', 16); $pdf->Cell(0, 8, thai_text('ตอนที่ 4 ผลการให้บริการ'), 0, 1, 'L'); $pdf->Ln(2); $pdf->SetFont('THSarabunNew', '', 14); // ตรวจสอบพื้นที่สำหรับ 4.1 ความสำเร็จในการให้บริการ (เหลือพื้นที่อย่างน้อย 50mm) if ($pdf->GetY() > 220) { $pdf->AddPage(); } // 4.1 ความสำเร็จในการให้บริการ $pdf->Cell(0, 8, thai_text('4.1 ความสำเร็จในการให้บริการ'), 0, 1, 'L'); $success_id = isset($service['service_success_id']) ? $service['service_success_id'] : ''; foreach ($successTypes as $successType) { $isSelected = ($successType['id'] == $success_id); $x = $pdf->GetX() + 8; $y = $pdf->GetY() + 1; drawCheckbox($pdf, $x, $y, $isSelected); $pdf->SetXY($x + 6, $y - 1); $pdf->Cell(0, 6, thai_text($successType['title']), 0, 1, 'L'); } if (!empty($service['service_failure_reason'])) { $pdf->Cell(8, 6, '', 0, 0, 'L'); $pdf->Cell(0, 6, thai_text('เหตุผลที่ไม่สำเร็จ: ' . $service['service_failure_reason']), 0, 1, 'L'); } // ตรวจสอบพื้นที่สำหรับ 4.2 นัดหมายติดตาม (เหลือพื้นที่อย่างน้อย 50mm) if ($pdf->GetY() > 220) { $pdf->AddPage(); } // 4.2 นัดหมายติดตาม $pdf->Ln(2); $pdf->Cell(0, 8, thai_text('4.2 นัดหมายติดตาม'), 0, 1, 'L'); $follow_up_id = isset($service['follow_up_id']) ? $service['follow_up_id'] : ''; foreach ($appointments as $appointment) { $isSelected = ($appointment['id'] == $follow_up_id); $x = $pdf->GetX() + 8; $y = $pdf->GetY() + 1; drawCheckbox($pdf, $x, $y, $isSelected); $pdf->SetXY($x + 6, $y - 1); $pdf->Cell(0, 6, thai_text($appointment['title']), 0, 1, 'L'); } if (!empty($service['follow_up_date'])) { $pdf->Cell(8, 6, '', 0, 0, 'L'); $pdf->Cell(0, 6, thai_text('วันที่นัดติดตาม: ' . thai_date($service['follow_up_date'])), 0, 1, 'L'); } // ตรวจสอบพื้นที่สำหรับ 4.3 ให้ความช่วยเหลือ/ส่งต่อ/ประสาน (เหลือพื้นที่อย่างน้อย 50mm) if ($pdf->GetY() > 220) { $pdf->AddPage(); } // 4.3 ให้ความช่วยเหลือ/ส่งต่อ/ประสาน $pdf->Ln(2); $pdf->Cell(0, 8, thai_text('4.3 ให้ความช่วยเหลือ/ส่งต่อ/ประสาน หน่วยงานหรือเครือข่ายภายนอก'), 0, 1, 'L'); $selectedReferral = !empty($service['referral_services']) ? json_decode($service['referral_services'], true) : array(); foreach ($helpTypes as $helpType) { $isSelected = in_array($helpType['id'], $selectedReferral); $x = $pdf->GetX() + 8; $y = $pdf->GetY() + 1; drawCheckbox($pdf, $x, $y, $isSelected); $pdf->SetXY($x + 6, $y - 1); // แบ่งข้อความหลักเป็นหลายบรรทัดถ้าเกินขอบกระดาษ $title = $helpType['title']; $words = explode(' ', $title); $current_line = ''; $max_width = 140; foreach ($words as $word) { $test_line = $current_line . ($current_line ? ' ' : '') . $word; if ($pdf->GetStringWidth(thai_text($test_line)) > $max_width) { if ($current_line) { $pdf->Cell(0, 6, thai_text($current_line), 0, 1, 'L'); $pdf->SetX($x + 6); $current_line = $word; } else { $pdf->Cell(0, 6, thai_text($word), 0, 1, 'L'); $pdf->SetX($x + 6); } } else { $current_line = $test_line; } } if ($current_line) { $pdf->Cell(0, 6, thai_text($current_line), 0, 1, 'L'); } // แสดง sub-items ถ้ามี และถูกเลือกหลัก if ($isSelected && !empty($helpSubTypes[$helpType['id']])) { foreach ($helpSubTypes[$helpType['id']] as $subType) { $isSubSelected = in_array('sub_' . $subType['id'], $selectedReferral); if ($isSubSelected) { $sub_x = $pdf->GetX() + 16; $sub_y = $pdf->GetY() + 1; drawCheckbox($pdf, $sub_x, $sub_y, true); $pdf->SetXY($sub_x + 6, $sub_y - 1); // แบ่งข้อความ sub-item เป็นหลายบรรทัดถ้าเกินขอบกระดาษ $sub_title = $subType['title']; $sub_words = explode(' ', $sub_title); $sub_current_line = ''; $sub_max_width = 130; // น้อยกว่าเพราะมีการเยื้องมากขึ้น foreach ($sub_words as $sub_word) { $sub_test_line = $sub_current_line . ($sub_current_line ? ' ' : '') . $sub_word; if ($pdf->GetStringWidth(thai_text($sub_test_line)) > $sub_max_width) { if ($sub_current_line) { $pdf->Cell(0, 6, thai_text($sub_current_line), 0, 1, 'L'); $pdf->SetX($sub_x + 6); $sub_current_line = $sub_word; } else { $pdf->Cell(0, 6, thai_text($sub_word), 0, 1, 'L'); $pdf->SetX($sub_x + 6); } } else { $sub_current_line = $sub_test_line; } } if ($sub_current_line) { $pdf->Cell(0, 6, thai_text($sub_current_line), 0, 1, 'L'); } } } } } if (!empty($service['referral_other'])) { $x = $pdf->GetX() + 8; $y = $pdf->GetY() + 1; drawCheckbox($pdf, $x, $y, true); $pdf->SetXY($x + 6, $y - 1); // แบ่งข้อความอื่นๆ เป็นหลายบรรทัดถ้าเกินขอบกระดาษ $other_title = 'อื่น ๆ: ' . $service['referral_other']; $other_words = explode(' ', $other_title); $other_current_line = ''; $other_max_width = 140; foreach ($other_words as $other_word) { $other_test_line = $other_current_line . ($other_current_line ? ' ' : '') . $other_word; if ($pdf->GetStringWidth(thai_text($other_test_line)) > $other_max_width) { if ($other_current_line) { $pdf->Cell(0, 6, thai_text($other_current_line), 0, 1, 'L'); $pdf->SetX($x + 6); $other_current_line = $other_word; } else { $pdf->Cell(0, 6, thai_text($other_word), 0, 1, 'L'); $pdf->SetX($x + 6); } } else { $other_current_line = $other_test_line; } } if ($other_current_line) { $pdf->Cell(0, 6, thai_text($other_current_line), 0, 1, 'L'); } } // ตรวจสอบพื้นที่สำหรับ 4.4 ผู้ปฏิบัติหน้าที่ให้คำปรึกษา (เหลือพื้นที่อย่างน้อย 50mm) if ($pdf->GetY() > 220) { $pdf->AddPage(); } // 4.4 ผู้ปฏิบัติหน้าที่ให้คำปรึกษา $pdf->Ln(3); $pdf->Cell(0, 8, thai_text('4.4 ผู้ปฏิบัติหน้าที่ให้คำปรึกษาในครั้งนี้'), 0, 1, 'L'); $counselor_name = (isset($service['counselor_first_name']) ? $service['counselor_first_name'] : '') . ' ' . (isset($service['counselor_last_name']) ? $service['counselor_last_name'] : ''); $pdf->Cell(8, 6, '', 0, 0, 'L'); $pdf->Cell(0, 6, thai_text('4.4.1 ชื่อ-สกุล: ' . trim($counselor_name)), 0, 1, 'L'); $counselor_position = isset($service['counselor_position']) ? $service['counselor_position'] : ''; $pdf->Cell(8, 6, '', 0, 0, 'L'); $pdf->Cell(0, 6, thai_text('4.4.3 ตำแหน่ง: ' . $counselor_position), 0, 1, 'L'); $counselor_org = isset($service['counselor_organization']) ? $service['counselor_organization'] : ''; $pdf->Cell(8, 6, '', 0, 0, 'L'); $pdf->Cell(0, 6, thai_text('4.4.4 หน่วยงาน: ' . $counselor_org), 0, 1, 'L'); $counselor_phone = isset($service['counselor_phone']) ? $service['counselor_phone'] : ''; $pdf->Cell(8, 6, '', 0, 0, 'L'); $pdf->Cell(0, 6, thai_text('4.4.5 เบอร์โทรศัพท์: ' . $counselor_phone), 0, 1, 'L'); } } else { $pdf->AddPage(); $pdf->SetFont('THSarabunNew', '', 14); $pdf->Cell(0, 8, thai_text('ยังไม่มีประวัติการให้บริการ'), 0, 1, 'L'); } // เส้นใต้หน้า $pdf->Ln(10); $pdf->SetDrawColor(0, 0, 0); $pdf->SetLineWidth(1); $pdf->Line(20, $pdf->GetY(), 190, $pdf->GetY()); // สร้างชื่อไฟล์ $current_datetime = date('dmY_His'); $filename = 'รายงานการให้คำปรึกษารายบุคคล_' . $current_datetime . '.pdf'; // ส่งออกไฟล์ PDF $pdf->Output($filename, 'I'); ?>