403Webshell
Server IP : 104.21.80.248  /  Your IP : 172.71.28.156
Web Server : Apache/2.4.25 (Win32) OpenSSL/1.0.2j PHP/5.6.30
System : Windows NT WIN-ECQAAA40806 6.2 build 9200 (Windows Server 2012 Standard Edition) i586
User : SYSTEM ( 0)
PHP Version : 5.6.30
Disable Function : NONE
MySQL : ON  |  cURL : ON  |  WGET : OFF  |  Perl : OFF  |  Python : OFF  |  Sudo : OFF  |  Pkexec : OFF
Directory :  E:/Inetpub/www/supply_system/requisitions/

Upload File :
current_dir [ Writeable ] document_root [ Writeable ]

 

Command :


[ Back ]     

Current File : E:/Inetpub/www/supply_system/requisitions/history_all.php
<?php
include_once __DIR__ . '/../config.php';
include_once __DIR__ . '/../functions.php';
include_once __DIR__ . '/../includes/auth_check.php';
// requireRole(['admin', 'supply_manager']);

$page_title = "ประวัติการเบิกพัสดุทั้งหมด";

// --- Handle Filters ---
$filter_start_date = isset($_GET['start_date']) ? sanitize_input($conn, $_GET['start_date']) : '';
$filter_end_date = isset($_GET['end_date']) ? sanitize_input($conn, $_GET['end_date']) : '';

// --- Build WHERE clause ---
$where_clauses = []; // Start with an empty array
if (!empty($filter_start_date)) {
    // ใช้ DATE() เพื่อเปรียบเทียบเฉพาะส่วนวันที่ (ไม่รวมเวลา)
    $where_clauses[] = "DATE(r.request_date) >= '" . $filter_start_date . "'";
}
if (!empty($filter_end_date)) {
    $where_clauses[] = "DATE(r.request_date) <= '" . $filter_end_date . "'";
}

$where_sql = "";
if (count($where_clauses) > 0) {
    $where_sql = "WHERE " . implode(' AND ', $where_clauses);
}


// --- Fetch All Requisitions ---
$requisitions = [];
$sql = "SELECT r.id, r.requisition_no, r.request_date, r.status, d.dept_name, u.full_name as requester_name, r.total_value, r.approved_date
        FROM requisitions r
        JOIN departments d ON r.department_id = d.id
        JOIN users u ON r.requested_by = u.id
        $where_sql  -- Applied filter
        ORDER BY r.request_date DESC, r.id DESC";
$result = mysqli_query($conn, $sql);
if ($result) {
    while ($row = mysqli_fetch_assoc($result)) {
        $requisitions[] = $row;
    }
    mysqli_free_result($result);
} else {
    echo "Error fetching requisitions: " . mysqli_error($conn);
}
mysqli_close($conn);

// --- Include Header and Sidebar ---
include_once __DIR__ . '/../includes/header.php';
include_once __DIR__ . '/../includes/sidebar_supply.php';
?>

<div class="container-fluid">
    <h1 class="mt-4"><?php echo $page_title; ?></h1>

    <div class="card mb-4">
        <div class="card-header"><i class="bi bi-filter me-1"></i>ตัวกรองรายงาน</div>
        <div class="card-body">
            <form method="GET" action="" class="row g-3 align-items-end">
                <div class="col-md-4">
                    <label for="start_date" class="form-label">วันที่ขอ (จาก):</label>
                    <input type="date" id="start_date" name="start_date" class="form-control" value="<?php echo htmlspecialchars($filter_start_date); ?>">
                </div>
                <div class="col-md-4">
                     <label for="end_date" class="form-label">วันที่ขอ (ถึง):</label>
                    <input type="date" id="end_date" name="end_date" class="form-control" value="<?php echo htmlspecialchars($filter_end_date); ?>">
                </div>
                <div class="col-md-2">
                    <button type="submit" class="btn btn-primary w-100">
                        <i class="bi bi-search me-1"></i> กรองข้อมูล
                    </button>
                </div>
                <div class="col-md-2">
                    <a href="history_all.php" class="btn btn-outline-secondary w-100" title="ล้างตัวกรอง">
                        <i class="bi bi-arrow-clockwise"></i> ล้าง
                    </a>
                </div>
            </form>
        </div>
    </div>


    <div class="card mb-4">
        <div class="card-header">
            <i class="bi bi-clock-history me-1"></i>
            ประวัติการเบิกทั้งหมด (<?php echo count($requisitions); ?> รายการ)
        </div>
        <div class="card-body">
            <div class="table-responsive">
                <table class="table table-bordered table-striped table-hover table-sm"> <thead class="table-dark">
                        <tr>
                            <th>#</th>
                            <th>เลขที่คำขอ</th>
                            <th>วันที่ขอ</th>
                            <th>กลุ่มงาน</th>
                            <th>ผู้ขอเบิก</th>
                            <th>สถานะ</th>
                            <th class="text-end">มูลค่ารวม (ถ้าอนุมัติ)</th>
                            <th>วันที่อนุมัติ</th>
                            <th>ดำเนินการ</th>
                        </tr>
                    </thead>
                    <tbody>
                        <?php if (!empty($requisitions)): ?>
                            <?php $counter = 1; $grand_total = 0; ?>
                            <?php foreach ($requisitions as $req): ?>
                                <tr>
                                    <td><?php echo $counter++; ?></td>
                                    <td><?php echo htmlspecialchars($req['requisition_no']); ?></td>
                                    <td><?php echo formatThaiDate($req['request_date'], false); ?></td>
                                    <td><?php echo htmlspecialchars($req['dept_name']); ?></td>
                                    <td><?php echo htmlspecialchars($req['requester_name']); ?></td>
                                    <td>
                                         <?php
                                            $status_badge = 'secondary';
                                            $status_text = $req['status'];
                                            switch ($req['status']) {
                                                case 'pending': $status_badge = 'warning text-dark'; $status_text = 'รอ ผอ. กลุ่ม'; break;
                                                case 'head_approved': $status_badge = 'info text-dark'; $status_text = 'รอพัสดุอนุมัติ'; break;
                                                case 'approved': $status_badge = 'success'; $status_text = 'อนุมัติแล้ว'; break;
                                                case 'rejected': $status_badge = 'danger'; $status_text = 'ไม่อนุมัติ (พัสดุ)'; break;
                                                case 'head_rejected': $status_badge = 'danger'; $status_text = 'ไม่อนุมัติ (ผอ.)'; break;
                                            }
                                        ?>
                                        <span class="badge bg-<?php echo $status_badge; ?>"><?php echo $status_text; ?></span>
                                    </td>
                                    <td class="text-end">
                                        <?php
                                            $value = ($req['status'] == 'approved') ? $req['total_value'] : 0;
                                            echo ($value > 0) ? number_format($value, 2) : '-';
                                            $grand_total += $value; // Add to grand total only if approved
                                        ?>
                                    </td>
                                     <td><?php echo $req['approved_date'] ? formatThaiDate($req['approved_date'], false) : '-'; ?></td>
                                    <td>
                                        <a href="view.php?id=<?php echo $req['id']; ?>" class="btn btn-sm btn-info" title="ดูรายละเอียด">
                                            <i class="bi bi-search"></i>
                                        </a>
                                    </td>
                                </tr>
                            <?php endforeach; ?>
                        <?php else: ?>
                            <tr>
                                <td colspan="9" class="text-center">ไม่พบข้อมูลตามเงื่อนไขที่เลือก</td>
                            </tr>
                        <?php endif; ?>
                    </tbody>
                     <?php if (!empty($requisitions)): ?>
                     <tfoot class="table-light fw-bold">
                         <tr>
                             <td colspan="6" class="text-end">ยอดรวม (เฉพาะที่อนุมัติแล้ว):</td>
                             <td class="text-end fs-5"><?php echo number_format($grand_total, 2); ?></td>
                             <td colspan="2"></td>
                         </tr>
                     </tfoot>
                     <?php endif; ?>
                </table>
            </div>
        </div>
    </div>
</div>

<?php
// --- Include Footer ---
include_once __DIR__ . '/../includes/footer.php';
?>

Youez - 2016 - github.com/yon3zu
LinuXploit