Mini Shell

Direktori : /var/www/vhosts/ccp.ac.th/backup_full/httpdocs/fertilizer/
Upload File :
Current File : /var/www/vhosts/ccp.ac.th/backup_full/httpdocs/fertilizer/report2.php

<?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";
}
?>
<!doctype html>
<html lang="en">
    <?php include 'head.php'; ?>
    
    <link href="https://cdnjs.cloudflare.com/ajax/libs/select2/4.0.13/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;
        }
        .select2-container--default .select2-selection--single .select2-selection__rendered {
            padding-left: 0 !important;
            line-height: 36px !important;
            color: #555 !important;
        }
        .select2-container--default .select2-selection--single .select2-selection__arrow {
            height: 36px !important;
        }
        /* เปลี่ยนสีเส้นใต้เมื่อถูกคลิก(โฟกัส) เป็นสีฟ้าเข้ากับ Card */
        .form-group.is-focused .select2-container--default .select2-selection--single {
            border-bottom: 2px solid #00bcd4 !important; 
        }
        /* ซ่อนกรอบสีฟ้าเวลาคลิกบน Chrome */
        .select2-container--default .select2-selection--single:focus {
            outline: none !important;
        }
    </style>

    <body>
        <div class="wrapper">
            <?php include 'leftside.php'; ?>

            <div class="main-panel">
                <?php include 'header.php'; ?>
                <?php 
                    include 'db/database.php'; 
                ?>  

                <div class="content">
                    <div class="container-fluid">            

                        <div class="card">
                            <div class="card-header" data-background-color="blue">
                                <h4 class="title" style="color: white;">ออกรายงานคำนวณแม่ปุ๋ยคงเหลือ</h4>
                            </div>
                            <div class="card-content">
                                <form method="POST" action="">
                                    <div class="row">
                                        <div class="col-md-5">
                                            <div class="form-group label-floating">
                                                <label class="control-label">กรุณาเลือกสหกรณ์</label>
                                                <select name="sahakornID" class="form-control select2" required>
                                                    <option value=""></option>
                                                    <?php
                                                    $sql_sahakorn = "SELECT sahakornID, name FROM sahakorn ORDER BY sahakornID ASC";
                                                    $result_sahakorn = mysqli_query($link, $sql_sahakorn);
                                                    while($row_sahakorn = mysqli_fetch_assoc($result_sahakorn)) {
                                                        $selected = (isset($_POST['sahakornID']) && $_POST['sahakornID'] == $row_sahakorn['sahakornID']) ? 'selected' : '';
                                                        echo "<option value='".$row_sahakorn['sahakornID']."' {$selected}>".$row_sahakorn['name']."</option>";
                                                    }
                                                    ?>
                                                </select>
                                            </div>
                                        </div>
                                        <div class="col-md-4">
                                            <div class="form-group label-floating">
                                                <label class="control-label">กรุณาเลือกปีบัญชี(ปีพ.ศ.)</label>
                                                <select name="year" class="form-control select2" required>
                                                    <option value=""></option>
                                                    <?php
                                                    $current_year_be = (int)date('Y') + 543; 
                                                    for ($y = $current_year_be; $y >= $current_year_be - 4; $y--) {
                                                        $selected_year = (isset($_POST['year']) && $_POST['year'] == $y) ? 'selected' : '';
                                                        echo "<option value='".$y."' {$selected_year}>".$y."</option>";
                                                    }
                                                    ?>
                                                </select>
                                            </div>
                                        </div>
                                        <div class="col-md-3">
                                            <button type="submit" name="btn_report" class="btn btn-info pull-right" style="margin-top: 20px;">
                                                <i class="material-icons">search</i> ค้นหาข้อมูล
                                            </button>
                                        </div>
                                    </div>
                                    <div class="clearfix"></div>
                                </form>
                            </div>
                        </div>

                        <?php
                        if(isset($_POST['btn_report'])){
                            $sahakornID = mysqli_real_escape_string($link, $_POST['sahakornID']);
                            $year = mysqli_real_escape_string($link, $_POST['year']);

                            // ดึงชื่อสหกรณ์และจังหวัด
                            $sk_name = "";
                            $sk_province = "";
                            $sql_sk = "SELECT name, province FROM sahakorn WHERE sahakornID = '$sahakornID'";
                            $rs_sk = mysqli_query($link, $sql_sk);
                            if($row_sk = mysqli_fetch_assoc($rs_sk)){
                                $sk_name = $row_sk['name'];
                                $sk_province = $row_sk['province'];
                            }

                            // ดึงข้อมูลสำหรับตารางรายงาน
                            $sql_data = "SELECT * FROM calculate_fertilizer WHERE sahakornID = '$sahakornID' AND year = '$year'";
                            $rs_data = mysqli_query($link, $sql_data);
                            $num_rows = mysqli_num_rows($rs_data);
                        ?>
                        
                        <div class="card" style="margin-top: 30px;">
                            <div class="card-content">
                                
                                <?php if($num_rows > 0) { ?>
                                <form method="POST" action="print_report_pdf.php" target="_blank" style="text-align: right; margin-bottom: -40px; position: relative; z-index: 10;">
                                    <input type="hidden" name="sahakornID" value="<?php echo $sahakornID; ?>">
                                    <input type="hidden" name="year" value="<?php echo $year; ?>">
                                    <button type="submit" class="btn btn-danger">
                                        <i class="material-icons">picture_as_pdf</i> พิมพ์รายงาน PDF
                                    </button>
                                </form>
                                <?php } ?>

                                <div style="text-align: center; margin-bottom: 30px;">
                                    <h3 style="font-weight: bold; margin-bottom: 5px;">รายงานคำนวณแม่ปุ๋ยคงเหลือ</h3>
                                    <h4 style="margin-top: 0; margin-bottom: 5px;">ชื่อสหกรณ์ : <?php echo htmlspecialchars($sk_name); ?></h4>
                                    <p style="font-size: 16px; margin-bottom: 5px;">ปีบัญชี : <?php echo htmlspecialchars($year); ?> &nbsp;&nbsp;&nbsp; จังหวัด : <?php echo htmlspecialchars($sk_province); ?></p>
                                    <p style="font-size: 14px; color: #555;">วันที่ออกรายงาน : <?php echo DateThai(date("Y-m-d")); ?></p>
                                </div>

                                <?php if($num_rows > 0) { ?>
                                <div class="table-responsive">
                                    <table class="table table-bordered table-hover" style="text-align: center; white-space: nowrap;">
                                        <thead style="background-color: #f5f5f5;">
                                            <tr class="text-primary">
                                                <th style="text-align: center; font-weight: bold;">ลำดับ</th>
                                                <th style="text-align: center; font-weight: bold;">แม่ปุ๋ย/สารเติม</th>
                                                <th style="text-align: center; font-weight: bold;">วัตถุดิบคงเหลือ<br>ต้นปี</th>
                                                <th style="text-align: center; font-weight: bold;">ซื้อวัตถุดิบ<br>ระหว่างปี</th>
                                                <th style="text-align: center; font-weight: bold;">รวม</th>
                                                <th style="text-align: center; font-weight: bold;">ขาย<br>วัตถุดิบ</th>
                                                <th style="text-align: center; font-weight: bold;">เบิกวัตถุดิบไป<br>ผลิต</th>
                                                <th style="text-align: center; font-weight: bold;">วัตถุดิบคงเหลือ<br>สิ้นปี</th>
                                                <th style="text-align: center; font-weight: bold;">ปริมาณนับ<br>ได้(กก.)</th>
                                                <th style="text-align: center; font-weight: bold;">ขาด/เกิน</th>
                                                <th style="text-align: center; font-weight: bold;">คิดเป็นกระสอบ</th>
                                            </tr>
                                        </thead>
                                        <tbody>
                                            <?php
                                            $i = 1;
                                            $sum_remaining = 0; $sum_buy = 0; $sum_total_col = 0; 
                                            $sum_sell = 0; $sum_pick_up = 0; $sum_year_balance = 0; 
                                            $sum_countable = 0; $sum_tooshort = 0; $sum_sack = 0;

                                            while($row = mysqli_fetch_assoc($rs_data)){
                                                $total = $row['remaining'] + $row['buy'];
                                                $sum_remaining += $row['remaining'];
                                                $sum_buy += $row['buy'];
                                                $sum_total_col += $total;
                                                $sum_sell += $row['sell'];
                                                $sum_pick_up += $row['pick_up'];
                                                $sum_year_balance += $row['year_balance'];
                                                $sum_countable += $row['countable_F'];
                                                $sum_tooshort += $row['tooshort_F'];
                                                $sum_sack += $row['sack_C'];
                                            ?>
                                            <tr>
                                                <td><?php echo $i; ?></td>
                                                <td style="text-align: left;"><?php echo htmlspecialchars($row['name_pui_C']); ?></td>
                                                <td style="text-align: right;"><?php echo number_format($row['remaining'], 2); ?></td>
                                                <td style="text-align: right;"><?php echo number_format($row['buy'], 2); ?></td>
                                                <td style="text-align: right; color: #4caf50; font-weight: bold;"><?php echo number_format($total, 2); ?></td>
                                                <td style="text-align: right;"><?php echo number_format($row['sell'], 2); ?></td>
                                                <td style="text-align: right;"><?php echo number_format($row['pick_up'], 2); ?></td>
                                                <td style="text-align: right; color: #ff9800; font-weight: bold;"><?php echo number_format($row['year_balance'], 2); ?></td>
                                                <td style="text-align: right;"><?php echo number_format($row['countable_F'], 2); ?></td>
                                                <td style="text-align: right; <?php echo ($row['tooshort_F'] < 0) ? 'color: red;' : 'color: blue;'; ?>">
                                                    <?php echo number_format($row['tooshort_F'], 2); ?>
                                                </td>
                                                <td style="text-align: right;"><?php echo number_format($row['sack_C'], 2); ?></td>
                                            </tr>
                                            <?php 
                                                $i++;
                                            } 
                                            ?>
                                            <tr style="background-color: #fff9c4; font-weight: bold; color: #d32f2f;">
                                                <td colspan="2" style="text-align: center;">รวมทั้งสิ้น</td>
                                                <td style="text-align: right;"><?php echo number_format($sum_remaining, 2); ?></td>
                                                <td style="text-align: right;"><?php echo number_format($sum_buy, 2); ?></td>
                                                <td style="text-align: right;"><?php echo number_format($sum_total_col, 2); ?></td>
                                                <td style="text-align: right;"><?php echo number_format($sum_sell, 2); ?></td>
                                                <td style="text-align: right;"><?php echo number_format($sum_pick_up, 2); ?></td>
                                                <td style="text-align: right;"><?php echo number_format($sum_year_balance, 2); ?></td>
                                                <td style="text-align: right;"><?php echo number_format($sum_countable, 2); ?></td>
                                                <td style="text-align: right;"><?php echo number_format($sum_tooshort, 2); ?></td>
                                                <td style="text-align: right;"><?php echo number_format($sum_sack, 2); ?></td>
                                            </tr>
                                        </tbody>
                                    </table>
                                </div>
                                <?php 
                                } else { 
                                    echo "<div class='alert alert-warning text-center' style='margin-top: 20px; font-size: 16px;'>ไม่มีข้อมูลการคำนวณวัตถุดิบของสหกรณ์นี้ ในปีบัญชี " . htmlspecialchars($year) . "</div>";
                                } 
                                ?>
                            </div>
                        </div>
                        <?php 
                        } 
                        ?>
                    </div>
                </div>

                <?php include 'footer1.php'; ?> 

            </div>
        </div>
        <?php include 'footer2.php'; ?>
        
        <script src="https://cdnjs.cloudflare.com/ajax/libs/select2/4.0.13/js/select2.min.js"></script>

        <script>
        $(document).ready(function (){

            // เรียกใช้งาน Select2 สำหรับช่องที่มีคลาส .select2
            $('.select2').select2({
                width: '100%',
                placeholder: "" // เว้นว่างไว้เพื่อให้ Label ขยับลงมาตอนยังไม่เลือก
            });

            // ----------------------------------------------------------------------
            // Script ควบคุม Label Floating สำหรับ Select2 (Material Design)
            // ----------------------------------------------------------------------
            // 1. ตรวจเช็คในตอนแรกที่โหลดหน้า หากมีข้อมูลค้างอยู่แล้วให้ Label ลอยขึ้นไป
            $('.select2').each(function() {
                if ($(this).val()) {
                    $(this).closest('.form-group').removeClass('is-empty');
                }
            });

            // 2. เมื่อคลิกเปิด/ปิด Select2 จะจัดการ class is-empty, is-focused เพื่อลอย Label
            $('.select2').on('select2:open', function() {
                $(this).closest('.form-group').removeClass('is-empty').addClass('is-focused');
            }).on('select2:close', function() {
                $(this).closest('.form-group').removeClass('is-focused');
                if (!$(this).val()) {
                    $(this).closest('.form-group').addClass('is-empty');
                }
            }).on('change', function() {
                if ($(this).val()) {
                    $(this).closest('.form-group').removeClass('is-empty');
                } else {
                    $(this).closest('.form-group').addClass('is-empty');
                }
            });
            // ----------------------------------------------------------------------

        }); 
        </script>
    </body>
</html>

Zerion Mini Shell 1.0