403Webshell
Server IP : 172.67.187.206  /  Your IP : 162.159.115.41
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 :  /Inetpub/www/supply_system/supplies/

Upload File :
current_dir [ Writeable ] document_root [ Writeable ]

 

Command :


[ Back ]     

Current File : /Inetpub/www/supply_system/supplies/batch_edit.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 = "แก้ไขข้อมูล Batch";
$batch_id = isset($_GET['id']) ? intval($_GET['id']) : 0;
$supply_id_from_url = isset($_GET['supply_id']) ? intval($_GET['supply_id']) : 0; // Get supply_id for context/redirect
$batch_data = null;
$supply_info = null; // To display supply name
$error_message = '';

if ($batch_id <= 0) {
    $_SESSION['message'] = 'ไม่ได้ระบุ Batch ที่ต้องการแก้ไข';
    $_SESSION['message_type'] = 'warning';
    redirect('index.php'); // Redirect to supply list
}

// --- Fetch Batch Data ---
$sql_batch = "SELECT sb.*, s.supply_name, s.supply_code, s.unit
              FROM supply_batches sb
              JOIN supplies s ON sb.supply_id = s.id
              WHERE sb.id = $batch_id";
$result_batch = mysqli_query($conn, $sql_batch);

if ($result_batch && mysqli_num_rows($result_batch) > 0) {
    $batch_data = mysqli_fetch_assoc($result_batch);
    $supply_info = [ // Store supply info separately
        'id' => $batch_data['supply_id'],
        'name' => $batch_data['supply_name'],
        'code' => $batch_data['supply_code'],
        'unit' => $batch_data['unit']
    ];
    // Security check: ensure supply_id from URL matches batch's supply_id if provided
    if ($supply_id_from_url > 0 && $supply_id_from_url != $supply_info['id']) {
         $error_message = "Batch ID ไม่ตรงกับ Supply ID ที่ระบุ";
         $batch_data = null; // Prevent displaying the form
    }
    mysqli_free_result($result_batch);
} else {
    $error_message = "ไม่พบข้อมูล Batch ID: $batch_id";
}

// Set dynamic page title
if ($batch_data) {
    $page_title = "แก้ไข Batch: " . htmlspecialchars($batch_data['batch_no']) . " (" . htmlspecialchars($supply_info['name']) . ")";
}

// --- Include Header and Sidebar ---
include_once __DIR__ . '/../includes/header.php';
include_once __DIR__ . '/../includes/sidebar_supply.php';
mysqli_close($conn);
?>

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

     <?php if (isset($_SESSION['message'])): // Display message from previous action (e.g., update failed) ?>
        <div class="alert alert-<?php echo $_SESSION['message_type']; ?> alert-dismissible fade show" role="alert">
            <?php echo $_SESSION['message']; ?>
            <button type="button" class="btn-close" data-bs-dismiss="alert" aria-label="Close"></button>
        </div>
        <?php unset($_SESSION['message'], $_SESSION['message_type']); ?>
    <?php endif; ?>

    <?php if ($error_message): ?>
        <div class="alert alert-danger" role="alert">
            <?php echo $error_message; ?>
        </div>
        <a href="supply_view.php?id=<?php echo $supply_id_from_url; ?>" class="btn btn-secondary"><i class="bi bi-arrow-left"></i> กลับไปดูรายละเอียดพัสดุ</a>
    <?php elseif ($batch_data && $supply_info): ?>
        <div class="alert alert-warning" role="alert">
            <i class="bi bi-exclamation-triangle-fill"></i> <strong>ข้อควรระวัง:</strong> การแก้ไขราคาต่อหน่วย จะส่งผลต่อการคำนวณมูลค่าเฉลี่ยของพัสดุนี้ใหม่ทั้งหมด
        </div>
        <div class="card mb-4">
            <div class="card-header">
                <i class="bi bi-pencil-fill me-1"></i>
                แก้ไขข้อมูล Batch: <?php echo htmlspecialchars($batch_data['batch_no']); ?>
                 - <?php echo htmlspecialchars($supply_info['name']); ?>
            </div>
            <div class="card-body">
                <form action="action_batch_update.php" method="POST">
                    <input type="hidden" name="batch_id" value="<?php echo $batch_data['id']; ?>">
                    <input type="hidden" name="supply_id" value="<?php echo $supply_info['id']; ?>"> <div class="row g-3">
                         <div class="col-md-3">
                            <label class="form-label">จำนวนรับเข้า</label>
                            <input type="number" class="form-control" value="<?php echo $batch_data['quantity_received']; ?>" readonly disabled>
                            <small class="text-muted">ไม่สามารถแก้ไขได้</small>
                        </div>
                         <div class="col-md-3">
                            <label class="form-label">จำนวนคงเหลือ</label>
                            <input type="number" class="form-control" value="<?php echo $batch_data['quantity_remaining']; ?>" readonly disabled>
                             <small class="text-muted">ไม่สามารถแก้ไขได้</small>
                        </div>

                        <div class="col-md-3">
                            <label for="unit_price" class="form-label required-field">ราคาต่อหน่วย (บาท)</label>
                            <input type="number" class="form-control" id="unit_price" name="unit_price" value="<?php echo htmlspecialchars($batch_data['unit_price']); ?>" min="0" step="0.01" required>
                        </div>
                         <div class="col-md-3">
                            <label for="expiry_date" class="form-label">วันที่หมดอายุ (ถ้ามี)</label>
                            <input type="date" class="form-control" id="expiry_date" name="expiry_date" value="<?php echo htmlspecialchars($batch_data['expiry_date']); ?>">
                        </div>

                        <div class="col-md-6">
                            <label for="supplier" class="form-label">ผู้จำหน่าย</label>
                            <input type="text" class="form-control" id="supplier" name="supplier" value="<?php echo htmlspecialchars($batch_data['supplier']); ?>" maxlength="200">
                        </div>
                         <div class="col-md-6">
                            <label for="invoice_no" class="form-label">เลขที่ใบส่งของ/ใบกำกับ</label>
                            <input type="text" class="form-control" id="invoice_no" name="invoice_no" value="<?php echo htmlspecialchars($batch_data['invoice_no']); ?>" maxlength="50">
                        </div>

                         <div class="col-12 mt-4">
                             <button type="submit" class="btn btn-primary"><i class="bi bi-save me-1"></i> บันทึกการเปลี่ยนแปลง</button>
                             <a href="supply_view.php?id=<?php echo $supply_info['id']; ?>" class="btn btn-secondary">ยกเลิก</a>
                         </div>
                    </div>
                </form>
            </div>
        </div>
    <?php endif; ?>
</div>

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

Youez - 2016 - github.com/yon3zu
LinuXploit