Server IP : 43.241.58.20 / Your IP : 216.73.216.25 Web Server : Apache/2 System : Linux ns1-1556229.dragonhispeed.com 3.16.0 #1 SMP Fri Mar 29 22:50:14 MSK 2024 x86_64 User : ratsitne ( 1130) PHP Version : 5.6.40 Disable Function : exec,system,passthru,shell_exec,proc_close,proc_open,dl,popen,show_source,posix_kill,posix_mkfifo,posix_getpwuid,posix_setpgid,posix_setsid,posix_setuid,posix_setgid,posix_seteuid,posix_setegid,posix_uname MySQL : ON | cURL : ON | WGET : OFF | Perl : OFF | Python : OFF | Sudo : OFF | Pkexec : OFF Directory : /home/ratsitne/.trash/files/admin/ |
Upload File : |
<?php include '../config.php'; include 'auth.php'; // Check if ID is provided if (!isset($_GET['id']) || empty($_GET['id'])) { $_SESSION['error_message'] = 'ไม่พบหมายเลขเอกสาร'; header('Location: ' . $admin_url . '/invoice-list.php'); exit; } $invoice_id = mysqli_real_escape_string($conn, $_GET['id']); // Get invoice data $query = "SELECT * FROM invoices WHERE id = '$invoice_id'"; $result = mysqli_query($conn, $query); if (mysqli_num_rows($result) == 0) { $_SESSION['error_message'] = 'ไม่พบข้อมูลเอกสารที่ต้องการ'; header('Location: ' . $admin_url . '/invoice-list.php'); exit; } $invoice = mysqli_fetch_assoc($result); // Get invoice items - using invoice_details table instead of invoice_items $items_query = "SELECT * FROM invoice_details WHERE invoice_id = '$invoice_id' ORDER BY id ASC"; $items_result = mysqli_query($conn, $items_query); if (!$items_result) { $_SESSION['error_message'] = 'เกิดข้อผิดพลาดในการดึงข้อมูลรายการสินค้า: ' . mysqli_error($conn); header('Location: ' . $admin_url . '/invoice-list.php'); exit; } $items = []; while ($row = mysqli_fetch_assoc($items_result)) { $items[] = $row; } // Check if settings table exists, if not, use default values $company = []; $company_query = "SELECT * FROM settings WHERE setting_key IN ('company_name', 'company_address', 'company_tax_id', 'company_phone', 'company_fax', 'company_email', 'company_logo')"; $company_result = mysqli_query($conn, $company_query); if ($company_result) { while ($row = mysqli_fetch_assoc($company_result)) { $company[$row['setting_key']] = $row['setting_value']; } } // Format date function formatThaiDate($date) { if (empty($date)) return '-'; $date_obj = new DateTime($date); return $date_obj->format('d/m/Y'); } // Format number function formatNumber($number) { return number_format($number, 2); } // Convert number to Thai Baht text function baht_text($number) { $number = number_format($number, 2, '.', ''); $number_arr = explode('.', $number); $baht = convert_to_thai_number($number_arr[0]); $satang = convert_to_thai_number($number_arr[1]); $baht_text = $baht . 'บาท'; if ($satang != 'ศูนย์') { $baht_text .= $satang . 'สตางค์'; } return $baht_text; } // Convert number to Thai text function convert_to_thai_number($number) { $number = intval($number); if ($number == 0) return 'ศูนย์'; $digits = ['', 'หนึ่ง', 'สอง', 'สาม', 'สี่', 'ห้า', 'หก', 'เจ็ด', 'แปด', 'เก้า']; $positions = ['', 'สิบ', 'ร้อย', 'พัน', 'หมื่น', 'แสน', 'ล้าน']; $number_text = ''; $digit_count = strlen($number); for ($i = 0; $i < $digit_count; $i++) { $digit = intval(substr($number, $i, 1)); $position = ($digit_count - $i - 1) % 7; if ($digit != 0) { if ($position == 1 && $digit == 1) { $number_text .= 'สิบ'; } elseif ($position == 1 && $digit == 2) { $number_text .= 'ยี่สิบ'; } elseif ($position == 0 && $digit == 1 && strlen($number_text) > 0) { $number_text .= 'เอ็ด'; } else { $number_text .= $digits[$digit] . $positions[$position]; } } elseif ($position == 6 && $i > 0 && intval(substr($number, $i - 1, 7)) > 0) { $number_text .= 'ล้าน'; } } return $number_text; } ?> <!DOCTYPE html> <html lang="th"> <head> <meta charset="UTF-8"> <meta name="viewport" content="width=device-width, initial-scale=1.0"> <title>ใบเสร็จรับเงิน/ใบกำกับภาษี: <?php echo $invoice['document_no']; ?></title> <style> @page { size: A4; margin: 10mm; } body { font-family: 'Garuda', 'THSarabunNew', sans-serif; font-size: 14px; line-height: 1.3; margin: 0; padding: 0; } .header-table { width: 100%; border-collapse: collapse; margin-bottom: 10px; } .logo-container { width: 100px; } .logo-container img { width: 80px; height: auto; } .company-details { vertical-align: top; } .document-info { width: 180px; text-align: right; vertical-align: top; } .document-title { font-weight: bold; font-size: 16px; margin-bottom: 5px; } .customer-box { border: 1px solid #000; padding: 10px; margin-bottom: 10px; } .customer-table { width: 100%; border-collapse: collapse; } .fw-bold { font-weight: bold; } .text-end { text-align: right; } .items-table { width: 100%; border-collapse: collapse; border: 1px solid #000; } .items-table th, .items-table td { padding: 5px; } .items-header { background-color: #f2f2f2; } .border-end { border-right: 1px solid #000; } .border-bottom { border-bottom: 1px solid #000; } .signature-table { width: 100%; margin-top: 20px; text-align: center; } .signature-table td { width: 50%; padding: 10px; } .signature-line { display: block; width: 80%; margin: 30px auto 10px; border-bottom: 1px solid #000; } @media print { body { width: 210mm; height: 297mm; } } </style> </head> <body> <div class="container"> <table class="header-table"> <tr> <td class="logo-container"> <img src="assets/img/logo.png" alt="Logo"> </td> <td class="company-details"> <div style="font-weight: bold; font-size: 16px;"><?php echo $company['company_name']; ?></div> <div style="font-size: 12px;"><?php echo nl2br($company['company_address']); ?></div> <div style="font-size: 12px;">โทร: <?php echo $company['company_phone']; ?> แฟกซ์: <?php echo $company['company_fax']; ?></div> <div style="font-size: 12px;">เลขประจำตัวผู้เสียภาษี: <?php echo $company['company_tax_id']; ?></div> </td> <td class="document-info"> <div class="document-title">ใบเสร็จรับเงิน/ใบกำกับภาษี</div> </td> </tr> </table> <div class="customer-box"> <table style="width: 100%;border-collapse: collapse;"> <tr> <td style="width: 480px;" valign="top"> <table class="customer-table"> <tr> <td class="fw-bold" style="width: 50px;">ชื่อ</td> <td><?php echo $invoice['customer_name']; ?> (<?php echo $invoice['customer_branch']; ?>)</td> </tr> <tr> <td class="fw-bold">ที่อยู่</td> <td><?php echo $invoice['customer_address']; ?></td> </tr> <tr> <td colspan="2"><strong>เลขประจำตัวผู้เสียภาษี</strong> <?php echo $invoice['customer_taxid'] ?? ''; ?></td> </tr> </table> </td> <td valign="top"> <table class="customer-table text-end"> <tr> <td class="fw-bold" style="width: 110px;">เลขที่เอกสาร</td> <td><?php echo $invoice['document_no']; ?></td> </tr> <tr> <td class="fw-bold">วันที่เอกสาร</td> <td><?php echo formatThaiDate($invoice['document_date']); ?></td> </tr> <tr> <td class="fw-bold">วันที่ครบกำหนด</td> <td><?php echo formatThaiDate($invoice['due_date']); ?></td> </tr> </table> </td> </tr> </table> </div> <table class="items-table"> <thead> <tr class="items-header"> <th class="text-center border-end border-bottom" style="width: 40px;">ลำดับ</th> <th class="border-end border-bottom">รายการ</th> <th class="text-center border-end border-bottom" style="width: 80px;">จำนวน</th> <th class="text-center border-end border-bottom" style="width: 100px;">ราคาต่อหน่วย</th> <th class="text-center border-bottom" style="width: 120px;">จำนวนเงิน</th> </tr> </thead> <tbody> <?php $rowHeight = 30; $remainingRows = 20 - count($items); foreach ($items as $index => $item): ?> <tr> <td class="text-center border-end border-bottom"><?php echo $index + 1; ?></td> <td class="border-end border-bottom"> <?php echo $item['product_name']; ?> <?php if (!empty($item['product_description'])): ?> <br><?php echo $item['product_description']; ?> <?php endif; ?> </td> <td class="text-end border-end border-bottom"><?php echo formatNumber($item['quantity']); ?></td> <td class="text-end border-end border-bottom"><?php echo formatNumber($item['price']); ?></td> <td class="text-end border-bottom"><?php echo formatNumber($item['total']); ?></td> </tr> <?php endforeach; ?> <?php if ($remainingRows > 0): ?> <tr> <td class="border-end border-bottom" style="height: <?php echo $remainingRows * $rowHeight; ?>px;"> </td> <td class="border-end border-bottom"> </td> <td class="border-end border-bottom"> </td> <td class="border-end border-bottom"> </td> <td class="border-bottom"> </td> </tr> <?php endif; ?> </tbody> <tfoot> <tr> <td class="border-end border-bottom" valign="top" colspan="2" rowspan="3"><strong>หมายเหตุ:</strong> <?php echo nl2br($invoice['notes']); ?></td> <td class="text-end border-end" colspan="2" style="width: 180px;">มูลค่ารวม</td> <td class="text-end" style="width: 120px;"><?php echo formatNumber($invoice['subtotal']); ?></td> </tr> <tr> <td class="text-end border-end" colspan="2">ส่วนลด</td> <td class="text-end"><?php echo formatNumber($invoice['discount']); ?></td> </tr> <tr> <td class="text-end border-end border-bottom" colspan="2">ภาษี <?php echo number_format($invoice['vat_rate'], 0); ?>% (<?php echo $invoice['vat_type']; ?>)</td> <td class="text-end border-bottom"><?php echo formatNumber($invoice['vat']); ?></td> </tr> <tr> <th class="text-center border-end" colspan="2" style="width: 418px;">(<?php echo baht_text($invoice['grand_total']); ?>)</th> <th class="text-end border-end" colspan="2">ยอดสุทธิ</th> <th class="text-end"><?php echo formatNumber($invoice['grand_total']); ?></th> </tr> </tfoot> </table> <table class="signature-table"> <tr> <td> <span class="signature-line"></span> ( .................................................... ) <div> </div> วันที่ ........./................../................... <div> </div> <div>ผู้รับสินค้า Received by</div> </td> <td> <span class="signature-line"></span> ( .................................................... ) <div> </div> วันที่ ........./................../................... <div> </div> <div>ผู้รับเงิน Bill collector</div> </td> </tr> </table> </div> <script> // Auto trigger print dialog when page loads window.onload = function() { setTimeout(function() { window.print(); }, 500); // Delay for 500ms to ensure page is fully loaded }; </script> </body> </html>