291 lines
16 KiB
PHP
291 lines
16 KiB
PHP
<?php
|
|
$thaiMonths = [
|
|
'01' => 'มกราคม', '02' => 'กุมภาพันธ์', '03' => 'มีนาคม', '04' => 'เมษายน',
|
|
'05' => 'พฤษภาคม', '06' => 'มิถุนายน', '07' => 'กรกฎาคม', '08' => 'สิงหาคม',
|
|
'09' => 'กันยายน', '10' => 'ตุลาคม', '11' => 'พฤศจิกายน', '12' => 'ธันวาคม'
|
|
];
|
|
$thaiYear = $year + 543;
|
|
$monthName = $thaiMonths[$month] ?? '';
|
|
|
|
// Grouping by Fund Source
|
|
$cgdIncomes = [];
|
|
$hospIncomes = [];
|
|
foreach($incomes as $inc) {
|
|
if ($inc['amount'] > 0) {
|
|
if (($inc['fund_source'] ?? '') === 'CGD') $cgdIncomes[] = $inc;
|
|
else $hospIncomes[] = $inc;
|
|
}
|
|
}
|
|
|
|
$cgdDeductions = [];
|
|
$hospDeductions = [];
|
|
foreach($deductions as $ded) {
|
|
if ($ded['amount'] > 0) {
|
|
if (($ded['fund_source'] ?? '') === 'CGD') $cgdDeductions[] = $ded;
|
|
else $hospDeductions[] = $ded;
|
|
}
|
|
}
|
|
|
|
$cgdTotalIncome = array_sum(array_column($cgdIncomes, 'amount'));
|
|
$cgdTotalDeduction = array_sum(array_column($cgdDeductions, 'amount'));
|
|
$hospTotalIncome = array_sum(array_column($hospIncomes, 'amount'));
|
|
$hospTotalDeduction = array_sum(array_column($hospDeductions, 'amount'));
|
|
|
|
$netSalary = ($cgdTotalIncome + $hospTotalIncome) - ($cgdTotalDeduction + $hospTotalDeduction);
|
|
?>
|
|
<!DOCTYPE html>
|
|
<html lang="th">
|
|
<head>
|
|
<meta charset="UTF-8">
|
|
<meta name="viewport" content="width=device-width, initial-scale=1.0">
|
|
<title>สลิปเงินเดือน - <?= htmlspecialchars($hrData['HR_FNAME'] ?? '') ?></title>
|
|
<!-- Google Fonts: Sarabun (Standard Thai Font) -->
|
|
<link href="https://fonts.googleapis.com/css2?family=Sarabun:wght@300;400;500;600;700&display=swap" rel="stylesheet">
|
|
<!-- Tailwind CSS CDN -->
|
|
<script src="https://cdn.tailwindcss.com"></script>
|
|
<script>
|
|
tailwind.config = {
|
|
theme: {
|
|
extend: {
|
|
fontFamily: {
|
|
sans: ['Sarabun', 'sans-serif'],
|
|
}
|
|
}
|
|
}
|
|
}
|
|
</script>
|
|
<style>
|
|
@media print {
|
|
body { background: white; margin: 0; padding: 0; }
|
|
.no-print { display: none !important; }
|
|
@page { size: A4; margin: 0; } /* Set A4 without margins */
|
|
* { -webkit-print-color-adjust: exact !important; print-color-adjust: exact !important; }
|
|
.slip-container {
|
|
padding: 1cm !important;
|
|
box-shadow: none !important;
|
|
max-width: 100% !important;
|
|
margin: 0 !important;
|
|
width: 210mm !important;
|
|
height: 297mm !important;
|
|
box-sizing: border-box !important;
|
|
overflow: hidden !important;
|
|
page-break-after: avoid !important;
|
|
page-break-inside: avoid !important;
|
|
border: none !important;
|
|
}
|
|
}
|
|
body { font-size: <?= htmlspecialchars($slipFontSize ?? '11pt') ?>; color: #1e293b; background-color: #f8fafc; font-family: 'Sarabun', sans-serif; }
|
|
.slip-container {
|
|
width: 210mm;
|
|
min-height: 297mm;
|
|
box-sizing: border-box;
|
|
margin: 2cm auto;
|
|
background: white;
|
|
padding: 1cm;
|
|
box-shadow: 0 10px 15px -3px rgb(0 0 0 / 0.1), 0 4px 6px -4px rgb(0 0 0 / 0.1);
|
|
border-radius: 0.5rem;
|
|
border: 1px solid #e2e8f0;
|
|
}
|
|
|
|
table { width: 100%; border-collapse: collapse; margin-bottom: 0.75rem; }
|
|
th, td { border: 1px solid #cbd5e1; padding: 0.2rem 0.5rem; }
|
|
|
|
.bg-gray-header { background-color: #f1f5f9 !important; }
|
|
.bg-gray-light { background-color: #f8fafc !important; }
|
|
.bg-gray-dark { background-color: #e2e8f0 !important; }
|
|
.bg-white { background-color: #ffffff !important; }
|
|
|
|
.border-none { border: none !important; }
|
|
.border-l { border-left: 1px solid #cbd5e1 !important; }
|
|
.border-r { border-right: 1px solid #cbd5e1 !important; }
|
|
.border-t { border-top: 1px solid #cbd5e1 !important; }
|
|
.border-b { border-bottom: 1px solid #cbd5e1 !important; }
|
|
|
|
.w-col-name { width: 35%; }
|
|
.w-col-amt { width: 15%; }
|
|
|
|
.table-rounded { border-radius: 0.5rem; overflow: hidden; border: 1px solid #cbd5e1; }
|
|
.table-rounded table { margin-bottom: 0; }
|
|
.table-rounded th, .table-rounded td { border-color: #e2e8f0; }
|
|
.table-rounded tr:last-child td { border-bottom: none; }
|
|
</style>
|
|
</head>
|
|
<body>
|
|
|
|
<div class="fixed top-4 right-4 no-print flex space-x-2">
|
|
<button onclick="window.close()" class="px-4 py-2 bg-slate-200 hover:bg-slate-300 rounded-lg text-sm font-medium">ปิด</button>
|
|
<button onclick="window.print()" class="px-4 py-2 bg-sky-600 hover:bg-sky-700 text-white rounded-lg text-sm font-medium shadow flex items-center">
|
|
<svg xmlns="http://www.w3.org/2000/svg" fill="none" viewBox="0 0 24 24" stroke-width="2" stroke="currentColor" class="w-4 h-4 mr-2"><path stroke-linecap="round" stroke-linejoin="round" d="M6.72 13.829c-.24.03-.48.062-.72.096m.72-.096a42.415 42.415 0 0 1 10.56 0m-10.56 0L6.34 18m10.94-4.171c.24.03.48.062.72.096m-.72-.096L17.66 18m0 0 .229 2.523a1.125 1.125 0 0 1-1.12 1.227H7.231c-.662 0-1.18-.568-1.12-1.227L6.34 18m11.318 0h1.091A2.25 2.25 0 0 0 21 15.75V9.456c0-1.081-.768-2.015-1.837-2.175a48.055 48.055 0 0 0-1.913-.247M6.34 18H5.25A2.25 2.25 0 0 1 3 15.75V9.456c0-1.081.768-2.015 1.837-2.175a48.041 48.041 0 0 1 1.913-.247m10.5 0a48.536 48.536 0 0 0-10.5 0m10.5 0V3.375c0-.621-.504-1.125-1.125-1.125h-8.25c-.621 0-1.125.504-1.125 1.125v3.659M18 10.5h.008v.008H18V10.5Zm-3 0h.008v.008H15V10.5Z" /></svg>
|
|
พิมพ์
|
|
</button>
|
|
</div>
|
|
|
|
<div class="slip-container">
|
|
|
|
<!-- Header Info Table -->
|
|
<table>
|
|
<tr>
|
|
<td colspan="4" class="bg-gray-header p-6 text-center relative border-b-0 rounded-t-lg">
|
|
<img src="<?= BASE_URL ?>/public/img/logo.png" alt="Logo" class="h-20 absolute top-4 left-1/2 transform -translate-x-1/2" onerror="this.style.display='none'">
|
|
<h1 class="text-3xl font-bold mt-20 text-slate-800">โรงพยาบาลเกาะสมุย</h1>
|
|
</td>
|
|
</tr>
|
|
<tr>
|
|
<td class="bg-gray-light font-bold w-[20%]">ชื่อ - สกุล</td>
|
|
<td class="w-[30%]"><?= htmlspecialchars($hrData['HR_FNAME'] ?? $salary['first_name']) ?> <?= htmlspecialchars($hrData['HR_LNAME'] ?? $salary['last_name']) ?></td>
|
|
<td class="bg-gray-light font-bold w-[20%]">ตำแหน่ง</td>
|
|
<td class="w-[30%]"><?= htmlspecialchars($hrData['HR_POSITION_NAME'] ?? '-') ?></td>
|
|
</tr>
|
|
<tr>
|
|
<td class="bg-gray-light font-bold">กรม</td>
|
|
<td>สำนักงานปลัดกระทรวงสาธารณสุข</td>
|
|
<td class="bg-gray-light font-bold">ระดับ</td>
|
|
<td><?= htmlspecialchars($hrData['HR_LEVEL_NAME'] ?? 'ชำนาญการ') ?></td>
|
|
</tr>
|
|
<tr>
|
|
<td class="bg-gray-light font-bold">สำนัก/กอง/ศูนย์</td>
|
|
<td>โรงพยาบาลทั่วไปเกาะสมุย</td>
|
|
<td class="bg-gray-light font-bold">เลขที่ตำแหน่ง</td>
|
|
<td><?= htmlspecialchars($hrData['HR_POSITION_NUM'] ?? '-') ?></td>
|
|
</tr>
|
|
<tr>
|
|
<td class="bg-gray-light font-bold">รอบจ่าย</td>
|
|
<td>เดือน <?= $monthName ?> ปี <?= $thaiYear ?></td>
|
|
<td class="bg-gray-light font-bold">แผนก</td>
|
|
<td><?= htmlspecialchars($hrData['HR_DEPARTMENT_SUB_SUB_NAME'] ?? '-') ?></td>
|
|
</tr>
|
|
<tr>
|
|
<td class="bg-gray-light font-bold">โอนเงินเข้า</td>
|
|
<td class="w-[30%]"><?= htmlspecialchars($bankProfile['bank_name'] ?? 'ธนาคารกรุงไทย จำกัด(มหาชน)') ?></td>
|
|
<td class="bg-gray-light font-bold w-[20%]">เลขที่บัญชี</td>
|
|
<td class="w-[30%]"><?= htmlspecialchars($bankProfile['bank_account'] ?? '-') ?></td>
|
|
</tr>
|
|
</table>
|
|
|
|
<?php if (!empty($cgdIncomes) || !empty($cgdDeductions)): ?>
|
|
<!-- Section 1: กรมบัญชีกลาง -->
|
|
<table class="mb-4">
|
|
<tr>
|
|
<td colspan="4" class="bg-gray-dark font-bold text-lg p-3 text-slate-800 border-x-0 border-t-0">รายการจากกรมบัญชีกลาง</td>
|
|
</tr>
|
|
<tr class="bg-gray-light text-center font-bold">
|
|
<td class="w-col-name">รายรับ</td>
|
|
<td class="w-col-amt">จำนวน (บาท)</td>
|
|
<td class="w-col-name">รายจ่าย</td>
|
|
<td class="w-col-amt">จำนวน (บาท)</td>
|
|
</tr>
|
|
|
|
<?php
|
|
$maxCgdRows = max(count($cgdIncomes), count($cgdDeductions), 1);
|
|
for($i=0; $i<$maxCgdRows; $i++):
|
|
$inc = $cgdIncomes[$i] ?? null;
|
|
$ded = $cgdDeductions[$i] ?? null;
|
|
?>
|
|
<tr>
|
|
<td class="border-t-0 border-b-0 border-l border-r"><?= $inc ? htmlspecialchars($inc['name']) : ' ' ?></td>
|
|
<td class="border-t-0 border-b-0 border-l border-r text-right"><?= $inc ? number_format($inc['amount'], 2) : '' ?></td>
|
|
<td class="border-t-0 border-b-0 border-l border-r"><?= $ded ? htmlspecialchars($ded['name']) : '' ?></td>
|
|
<td class="border-t-0 border-b-0 border-l border-r text-right"><?= $ded ? number_format($ded['amount'], 2) : '' ?></td>
|
|
</tr>
|
|
<?php endfor; ?>
|
|
|
|
<tr>
|
|
<td class="border-t border-b border-l border-r font-bold text-center bg-gray-light text-slate-700">รวมรับ</td>
|
|
<td class="border-t border-b border-l border-r text-right font-medium"><?= number_format($cgdTotalIncome, 2) ?></td>
|
|
<td class="border-t border-b border-l border-r font-bold text-center bg-gray-light text-slate-700">รวมจ่าย</td>
|
|
<td class="border-t border-b border-l border-r text-right font-medium"><?= number_format($cgdTotalDeduction, 2) ?></td>
|
|
</tr>
|
|
<tr>
|
|
<td colspan="2" class="border-t border-b border-l border-r bg-white" style="border-right: none;"></td>
|
|
<td class="border-t border-b border-l border-r font-bold text-center bg-gray-dark text-slate-800">รับสุทธิจากกรมบัญชีกลาง</td>
|
|
<td class="border-t border-b border-l border-r text-right bg-white font-bold text-sky-700"><?= number_format($cgdTotalIncome - $cgdTotalDeduction, 2) ?></td>
|
|
</tr>
|
|
</table>
|
|
<?php endif; ?>
|
|
|
|
<?php if (!empty($hospIncomes) || !empty($hospDeductions)): ?>
|
|
<!-- Section 2: โรงพยาบาล -->
|
|
<table class="mb-4">
|
|
<tr>
|
|
<td colspan="4" class="bg-gray-dark font-bold text-lg p-3 text-slate-800 border-x-0 border-t-0">รายการจากโรงพยาบาล</td>
|
|
</tr>
|
|
<tr class="bg-gray-light text-center font-bold">
|
|
<td class="w-col-name">รายรับ</td>
|
|
<td class="w-col-amt">จำนวน (บาท)</td>
|
|
<td class="w-col-name">รายจ่าย</td>
|
|
<td class="w-col-amt">จำนวน (บาท)</td>
|
|
</tr>
|
|
|
|
<?php
|
|
$maxHospRows = max(count($hospIncomes), count($hospDeductions), 1);
|
|
for($i=0; $i<$maxHospRows; $i++):
|
|
$inc = $hospIncomes[$i] ?? null;
|
|
$ded = $hospDeductions[$i] ?? null;
|
|
?>
|
|
<tr>
|
|
<td class="border-t-0 border-b-0 border-l border-r"><?= $inc ? htmlspecialchars($inc['name']) : ' ' ?></td>
|
|
<td class="border-t-0 border-b-0 border-l border-r text-right"><?= $inc ? number_format($inc['amount'], 2) : '' ?></td>
|
|
<td class="border-t-0 border-b-0 border-l border-r"><?= $ded ? htmlspecialchars($ded['name']) : '' ?></td>
|
|
<td class="border-t-0 border-b-0 border-l border-r text-right"><?= $ded ? number_format($ded['amount'], 2) : '' ?></td>
|
|
</tr>
|
|
<?php endfor; ?>
|
|
|
|
<tr>
|
|
<td class="border-t border-b border-l border-r font-bold text-center bg-gray-light text-slate-700">รวมรับ</td>
|
|
<td class="border-t border-b border-l border-r text-right font-medium"><?= number_format($hospTotalIncome, 2) ?></td>
|
|
<td class="border-t border-b border-l border-r font-bold text-center bg-gray-light text-slate-700">รวมจ่าย</td>
|
|
<td class="border-t border-b border-l border-r text-right font-medium"><?= number_format($hospTotalDeduction, 2) ?></td>
|
|
</tr>
|
|
<tr>
|
|
<td colspan="2" class="border-t border-b border-l border-r bg-white" style="border-right: none;"></td>
|
|
<td class="border-t border-b border-l border-r font-bold text-center bg-gray-dark text-slate-800">รับสุทธิจากโรงพยาบาล</td>
|
|
<td class="border-t border-b border-l border-r text-right bg-white font-bold text-sky-700"><?= number_format($hospTotalIncome - $hospTotalDeduction, 2) ?></td>
|
|
</tr>
|
|
</table>
|
|
<?php endif; ?>
|
|
|
|
<!-- Grand Totals -->
|
|
<table class="mb-4">
|
|
<tr>
|
|
<td class="bg-gray-dark font-bold text-center text-xl p-4 w-[85%] text-slate-800 rounded-l-lg border-r-0">รวมรับสุทธิทั้งสิ้น</td>
|
|
<td class="text-right font-bold text-xl p-4 w-[15%] bg-white text-emerald-600 rounded-r-lg border-l-0"><?= number_format($netSalary, 2) ?></td>
|
|
</tr>
|
|
</table>
|
|
|
|
<!-- Signature -->
|
|
<div class="mt-16 flex justify-end pr-8">
|
|
<table class="text-center w-72 border-none">
|
|
<tr class="border-none">
|
|
<td class="text-right w-16 pr-2 border-none pb-1 align-bottom text-slate-700">ลงชื่อ</td>
|
|
<td class="border-b border-dotted border-slate-300 border-t-0 border-l-0 border-r-0 h-16 align-bottom pb-1 relative">
|
|
<?php
|
|
$sigPath = APP_ROOT . '/public/img/signature.png';
|
|
if (file_exists($sigPath)):
|
|
$modTime = filemtime($sigPath);
|
|
// signatureScale from Controller (default 100)
|
|
$scale = $signatureScale ?? 100;
|
|
$maxHeight = 3 * ($scale / 100) . 'rem'; // 3rem is roughly 48px (h-12)
|
|
|
|
// Signature position shift (default 0)
|
|
$posX = $signaturePosX ?? '0';
|
|
$posY = $signaturePosY ?? '0';
|
|
?>
|
|
<img src="<?= BASE_URL ?>/public/img/signature.png?t=<?= $modTime ?>" alt="Signature" class="mx-auto object-contain mix-blend-multiply absolute bottom-1 left-0 right-0" style="max-height: <?= $maxHeight ?>; transform: translate(<?= $posX ?>px, <?= $posY ?>px);" onerror="this.style.display='none'">
|
|
<?php endif; ?>
|
|
</td>
|
|
</tr>
|
|
<tr class="border-none">
|
|
<td class="border-none"></td>
|
|
<td class="pt-4 border-none"><?= htmlspecialchars($signatureName ?? '( นางณัฐฐิณี เรืองทอง )') ?></td>
|
|
</tr>
|
|
<tr class="border-none">
|
|
<td class="border-none"></td>
|
|
<td class="border-none"><?= htmlspecialchars($signaturePosition ?? 'นักวิชาการเงินและบัญชี') ?></td>
|
|
</tr>
|
|
</table>
|
|
</div>
|
|
|
|
</div>
|
|
</body>
|
|
</html>
|