Mini Shell
<!doctype html>
<html lang="en">
<?php include 'head.php'; ?>
<link href="https://cdn.jsdelivr.net/npm/[email protected]/dist/css/select2.min.css" rel="stylesheet" />
<style>
/* --- ปรับแต่ง Select2 ให้เข้ากับ Material Design --- */
.select2-container--default .select2-selection--single {
background-color: transparent !important;
border: none !important;
border-bottom: 1px solid #D2D2D2 !important;
border-radius: 0 !important;
height: 36px !important;
padding: 0 !important;
box-shadow: none !important;
}
.select2-container--default .select2-selection--single .select2-selection__rendered {
padding-left: 0 !important;
line-height: 36px !important;
color: #555555 !important;
font-size: 14px;
}
.select2-container--default .select2-selection--single .select2-selection__arrow {
height: 36px !important;
}
.form-group.is-focused .select2-container--default .select2-selection--single {
border-bottom: 2px solid #9c27b0 !important;
}
.form-group.label-floating label.control-label {
z-index: 10;
pointer-events: none;
}
.select2-container {
margin-top: 5px;
}
</style>
<body>
<div class="wrapper">
<?php include 'leftside.php'; ?>
<div class="main-panel">
<?php include 'header.php'; ?>
<?php
include 'db/database.php';
// ฟังก์ชันสำหรับแปลงวันที่เป็นภาษาไทย
function DateThai($strDate) {
$strYear = date("Y",strtotime($strDate))+543;
$strMonth= date("n",strtotime($strDate));
$strDay= date("j",strtotime($strDate));
$strMonthCut = Array("","มกราคม","กุมภาพันธ์","มีนาคม","เมษายน","พฤษภาคม","มิถุนายน","กรกฎาคม","สิงหาคม","กันยายน","ตุลาคม","พฤศจิกายน","ธันวาคม");
$strMonthThai=$strMonthCut[$strMonth];
return "$strDay $strMonthThai $strYear";
}
$is_searched = false;
$report_data = [];
$header_sahakorn_name = "ไม่ทราบชื่อสหกรณ์";
$header_province = "-";
if ($_SERVER['REQUEST_METHOD'] == 'POST' && isset($_POST['btn_report'])) {
$search_sahakornID = $_POST['sahakornID'];
$search_year = $_POST['year'];
$is_searched = true; // เมื่อกดปุ่มให้แสดงตารางเสมอ
// 1. ค้นหาชื่อสหกรณ์และจังหวัดแยกต่างหาก (เพื่อแก้ปัญหา Undefined index)
$sql_sk_info = "SELECT name, province FROM sahakorn WHERE sahakornID = '$search_sahakornID'";
$res_sk_info = mysqli_query($link, $sql_sk_info);
if ($res_sk_info && mysqli_num_rows($res_sk_info) > 0) {
$row_sk_info = mysqli_fetch_assoc($res_sk_info);
$header_sahakorn_name = $row_sk_info['name'];
$header_province = $row_sk_info['province'];
}
// 2. ค้นหาข้อมูลสำหรับแสดงในตารางรายงาน
$sql_report = "SELECT c.*, f.name_formula
FROM calculate_remaining c
LEFT JOIN formula f ON c.formulaID = f.formulaID
WHERE c.sahakornID = '$search_sahakornID' AND c.year = '$search_year'
ORDER BY f.name_formula ASC";
$res_report = mysqli_query($link, $sql_report);
if ($res_report && mysqli_num_rows($res_report) > 0) {
while ($row = mysqli_fetch_assoc($res_report)) {
$report_data[] = $row;
}
}
}
?>
<div class="content">
<div class="container-fluid">
<div class="card">
<div class="card-header" data-background-color="purple">
<h4 class="title" style="font-family: 'Kanit', sans-serif; color: #ffffff;">
<i class="material-icons" style="vertical-align: middle; margin-right: 5px;">assessment</i>
ออกรายงานปุ๋ยผสมคงเหลือ
</h4>
</div>
<div class="card-content">
<form action="" method="POST">
<div class="row" style="display: flex; align-items: flex-end;">
<div class="col-md-5">
<div class="form-group label-floating">
<label class="control-label">กรุณาเลือกสหกรณ์</label>
<select class="form-control select2-search" name="sahakornID" required>
<option value=""></option>
<?php
$sql_sk = "SELECT * FROM sahakorn";
$res_sk = mysqli_query($link, $sql_sk);
while ($row_sk = mysqli_fetch_assoc($res_sk)) {
$selected = (isset($search_sahakornID) && $search_sahakornID == $row_sk['sahakornID']) ? "selected" : "";
echo "<option value='{$row_sk['sahakornID']}' $selected>{$row_sk['name']}</option>";
}
?>
</select>
</div>
</div>
<div class="col-md-4">
<div class="form-group label-floating">
<label class="control-label">กรุณาเลือกปีบัญชี (ปีพ.ศ.)</label>
<select class="form-control select2-search" name="year" required>
<option value=""></option>
<?php
$current_year_be = date('Y') + 543;
for ($i = 0; $i <= 4; $i++) {
$year_option = $current_year_be - $i;
$selected_year = (isset($search_year) && $search_year == $year_option) ? "selected" : "";
echo "<option value='$year_option' $selected_year>$year_option</option>";
}
?>
</select>
</div>
</div>
<div class="col-md-3 text-right">
<button type="submit" name="btn_report" class="btn btn-primary" style="margin-bottom: 15px;">
<i class="material-icons">search</i> ดูรายงาน
</button>
</div>
</div>
<div class="clearfix"></div>
</form>
</div>
</div>
<?php if($is_searched): ?>
<div class="card">
<div class="card-content">
<div style="position: relative;">
<div style="position: absolute; right: 0; top: 0;">
<form action="print_pdf3.php" method="POST" target="_blank">
<input type="hidden" name="sahakornID" value="<?php echo $search_sahakornID; ?>">
<input type="hidden" name="year" value="<?php echo $search_year; ?>">
<button type="submit" name="btn_print_pdf" class="btn btn-danger btn-round">
<i class="material-icons">print</i> พิมพ์รายงาน (PDF)
</button>
</form>
</div>
<div class="text-center" style="margin-top: 15px; margin-bottom: 30px; padding-bottom: 20px; border-bottom: 2px dashed #eee;">
<h3 style="font-weight: bold; margin-bottom: 15px; color: #333;">รายงานปุ๋ยผสมคงเหลือ</h3>
<h4 style="margin: 8px 0; color: #555;">ชื่อสหกรณ์ : <span style="color: #000000; font-weight: bold;"><?php echo $header_sahakorn_name; ?></span></h4>
<h4 style="margin: 8px 0; color: #555;">ปีบัญชี : <span style="font-weight: bold; color: #000000;"><?php echo $search_year; ?></span> | จังหวัด : <span style="font-weight: bold; color: #000000;"><?php echo $header_province; ?></span></h4>
<h5 style="margin: 8px 0; color: #777;">วันที่ออกรายงาน : <?php echo DateThai(date("Y-m-d")); ?></h5>
</div>
</div>
<?php if(count($report_data) > 0): ?>
<div class="table-responsive">
<table class="table table-bordered table-hover" style="text-align: center; border-color: #ddd;">
<thead style="background-color: #f3f5f7; color: #333;">
<tr>
<th rowspan="2" style="text-align: center; font-weight: bold; vertical-align: middle;">ลำดับ</th>
<th rowspan="2" style="text-align: center; font-weight: bold; vertical-align: middle;">สูตรปุ๋ยที่ผสม</th>
<th rowspan="2" style="text-align: center; font-weight: bold; vertical-align: middle;">ยกมาต้นปี</th>
<th rowspan="2" style="text-align: center; font-weight: bold; vertical-align: middle;">รับจากการผลิต</th>
<th rowspan="2" style="text-align: center; font-weight: bold; vertical-align: middle;">รวม</th>
<th rowspan="2" style="text-align: center; font-weight: bold; vertical-align: middle;">ขายปุ๋ยผสม</th>
<th rowspan="2" style="text-align: center; font-weight: bold; vertical-align: middle;">เบิกใช้</th>
<th colspan="2" style="text-align: center; font-weight: bold;">คงเหลือสิ้นปี</th>
<th colspan="2" style="text-align: center; font-weight: bold;">นับได้</th>
<th colspan="2" style="text-align: center; font-weight: bold;">ขาด/เกิน</th>
</tr>
<tr>
<th style="text-align: center; font-weight: bold; font-size: 12px;">กิโลกรัม</th>
<th style="text-align: center; font-weight: bold; font-size: 12px;">กระสอบ</th>
<th style="text-align: center; font-weight: bold; font-size: 12px;">กิโลกรัม</th>
<th style="text-align: center; font-weight: bold; font-size: 12px;">กระสอบ</th>
<th style="text-align: center; font-weight: bold; font-size: 12px;">กิโลกรัม</th>
<th style="text-align: center; font-weight: bold; font-size: 12px;">กระสอบ</th>
</tr>
</thead>
<tbody>
<?php
$no = 1;
$sum_remaining = 0; $sum_production = 0; $sum_total = 0;
$sum_sell = 0; $sum_use = 0; $sum_balance = 0;
$sum_sack = 0; $sum_countable = 0; $sum_tooshort = 0;
foreach($report_data as $row){
$row_total = $row['remaining_pui'] + $row['from_production'];
$sum_remaining += $row['remaining_pui'];
$sum_production += $row['from_production'];
$sum_total += $row_total;
$sum_sell += $row['sell_pui'];
$sum_use += $row['use'];
$sum_balance += $row['pui_year_balance'];
$sum_sack += $row['sack_R'];
$sum_countable += $row['countable_R'];
$sum_tooshort += $row['tooshort_R'];
?>
<tr>
<td><?php echo $no++; ?></td>
<td style="text-align: left; color: #007bb6; font-weight: 500;"><?php echo $row['name_formula']; ?></td>
<td><?php echo number_format($row['remaining_pui'], 2); ?></td>
<td style="color: #4caf50;"><?php echo number_format($row['from_production'], 2); ?></td>
<td style="font-weight: bold;"><?php echo number_format($row_total, 2); ?></td>
<td style="color: #f44336;"><?php echo number_format($row['sell_pui'], 2); ?></td>
<td style="color: #ff9800;"><?php echo number_format($row['use'], 2); ?></td>
<td style="font-weight: bold; color: #9c27b0;"><?php echo number_format($row['pui_year_balance'], 2); ?></td>
<td><?php $balance_sack = $row['pui_year_balance'] / 50; echo number_format($balance_sack, 2); ?></td>
<td><?php echo number_format($row['countable_R'], 2); ?></td>
<td><?php $countable_sack = $row['countable_R'] / 50; echo number_format($countable_sack, 2); ?></td>
<td style="<?php echo ($row['tooshort_R'] < 0) ? 'color: red;' : 'color: green;'; ?> font-weight: bold;">
<?php echo number_format($row['tooshort_R'], 2); ?>
</td>
<td style="<?php echo ($row['tooshort_R'] < 0) ? 'color: red;' : 'color: green;'; ?> font-weight: bold;">
<?php $tooshort_sack = $row['tooshort_R'] / 50; echo number_format($tooshort_sack, 2); ?>
</td>
</tr>
<?php } ?>
</tbody>
<tfoot style="background-color: #e8ede1; font-weight: bold; color: #2c3e50;">
<tr>
<td colspan="2" style="text-align: right; padding-right: 20px;">ผลรวมทั้งหมด</td>
<td><?php echo number_format($sum_remaining, 2); ?></td>
<td><?php echo number_format($sum_production, 2); ?></td>
<td style="color: #000;"><?php echo number_format($sum_total, 2); ?></td>
<td><?php echo number_format($sum_sell, 2); ?></td>
<td><?php echo number_format($sum_use, 2); ?></td>
<td style="color: #9c27b0;"><?php echo number_format($sum_balance, 2); ?></td>
<td><?php $sum_balance_sack = $sum_balance / 50; echo number_format($sum_balance_sack, 2); ?></td>
<td><?php echo number_format($sum_countable, 2); ?></td>
<td><?php $sum_countable_sack = $sum_countable / 50; echo number_format($sum_countable_sack, 2); ?></td>
<td style="<?php echo ($sum_tooshort < 0) ? 'color: red;' : 'color: green;'; ?>">
<?php echo number_format($sum_tooshort, 2); ?>
</td>
<td style="<?php echo ($sum_tooshort < 0) ? 'color: red;' : 'color: green;'; ?>">
<?php $sum_tooshort_sack = $sum_tooshort / 50; echo number_format($sum_tooshort_sack, 2); ?>
</td>
</tr>
</tfoot>
</table>
</div>
<?php else: ?>
<div class="alert alert-info text-center" style="font-size: 16px; padding: 20px;">
<i class="material-icons" style="font-size: 36px; display: block; margin-bottom: 10px;">info_outline</i>
ไม่พบข้อมูลการบันทึกของ <strong><?php echo $header_sahakorn_name; ?></strong> ในปีบัญชี <strong><?php echo $search_year; ?></strong>
</div>
<?php endif; ?>
</div>
</div>
<?php endif; ?>
</div>
</div>
<?php include 'footer1.php'; ?>
</div>
</div>
<?php include 'footer2.php'; ?>
<script src="https://cdn.jsdelivr.net/npm/[email protected]/dist/js/select2.min.js"></script>
<script>
$(document).ready(function() {
// เริ่มใช้งาน Select2
$('.select2-search').select2({
width: '100%',
placeholder: "",
allowClear: true
});
// ฟังก์ชันตรวจสอบการลอยของตัวหนังสือ (Label-floating)
function updateLabelFloating(selectElement) {
var val = $(selectElement).val();
var parentFormGroup = $(selectElement).closest('.form-group');
if (val && val !== "") {
parentFormGroup.removeClass('is-empty');
} else {
parentFormGroup.addClass('is-empty');
}
}
// รันเช็คค่าตอนเปิดหน้าเว็บครั้งแรก
$('.select2-search').each(function() {
updateLabelFloating(this);
});
// จับ Event เพื่อใส่แอนิเมชันให้เหมือนช่องปกติ
$('.select2-search')
.on('select2:open', function() {
$(this).closest('.form-group').addClass('is-focused').removeClass('is-empty');
})
.on('select2:close', function() {
$(this).closest('.form-group').removeClass('is-focused');
updateLabelFloating(this);
})
.on('change', function() {
updateLabelFloating(this);
});
});
</script>
</body>
</html>
Zerion Mini Shell 1.0