Home  >  Article  >  Backend Development  >  Application of asset management module developed using PHP in enterprise resource planning (ERP) system

Application of asset management module developed using PHP in enterprise resource planning (ERP) system

PHPz
PHPzOriginal
2023-07-02 11:10:551443browse

Application of asset management module developed using PHP in enterprise resource planning (ERP) system

In modern enterprises, asset management is a very important task. Effectively managing a business's assets can improve productivity and financial health. To achieve this goal, many companies have added asset management modules to their enterprise resource planning (ERP) systems. This article will introduce how to use PHP to develop a simple asset management module and demonstrate how to integrate it into an ERP system.

First, we need to create a database to store asset information. The following is the design of a simple asset table:

CREATE TABLE assets (
    id INT(11) AUTO_INCREMENT PRIMARY KEY,
    name VARCHAR(255) NOT NULL,
    type VARCHAR(100) NOT NULL,
    purchase_date DATE NOT NULL,
    cost DECIMAL(10, 2),
    status ENUM('Available', 'In Use', 'Damaged', 'Disposed') NOT NULL
);

Next, we can start using PHP to write the asset management module. First, we need a page to display the asset list and provide search and filter functionality.

<?php
// 连接数据库
$conn = new mysqli('localhost', 'username', 'password', 'database_name');
if($conn->connect_error) {
    die('Failed to connect to the database: ' . $conn->connect_error);
}

// 获取资产列表
$sql = "SELECT * FROM assets";
$result = $conn->query($sql);
if($result->num_rows > 0) {
    while($row = $result->fetch_assoc()) {
        echo "<tr>";
        echo "<td>" . $row['name'] . "</td>";
        echo "<td>" . $row['type'] . "</td>";
        echo "<td>" . $row['purchase_date'] . "</td>";
        echo "<td>" . $row['cost'] . "</td>";
        echo "<td>" . $row['status'] . "</td>";
        echo "</tr>";
    }
} else {
    echo "No assets found.";
}
$conn->close();
?>

The above code obtains the asset list from the database and displays the relevant details of each asset in a table. Next, we can add search and filter functionality to the asset list.

<form method="GET">
    <input type="text" name="search" placeholder="Search by name">
    <select name="status">
        <option value="">All Status</option>
        <option value="Available">Available</option>
        <option value="In Use">In Use</option>
        <option value="Damaged">Damaged</option>
        <option value="Disposed">Disposed</option>
    </select>
    <button type="submit">Search</button>
</form>

<?php
// 获取搜索条件
$search = isset($_GET['search']) ? $_GET['search'] : '';
$status = isset($_GET['status']) ? $_GET['status'] : '';

// 构建SQL查询语句
$sql = "SELECT * FROM assets WHERE 1=1";
if(!empty($search)) {
    $sql .= " AND name LIKE '%$search%'";
}
if(!empty($status)) {
    $sql .= " AND status = '$status'";
}

// 执行查询
$result = $conn->query($sql);
if($result->num_rows > 0) {
    while($row = $result->fetch_assoc()) {
        // 显示资产信息
    }
} else {
    echo "No assets found.";
}
$conn->close();
?>

The above code shows the user a search form that can search based on asset name and status. Based on the user's input, we construct the corresponding SQL query statement and obtain qualified assets from the database.

In addition, we can also add the ability to add, edit and delete assets.

// 添加资产
if(isset($_POST['add'])) {
    $name = $_POST['name'];
    $type = $_POST['type'];
    $purchase_date = $_POST['purchase_date'];
    $cost = $_POST['cost'];
    $status = $_POST['status'];

    $sql = "INSERT INTO assets (name, type, purchase_date, cost, status) VALUES ('$name', '$type', '$purchase_date', '$cost', '$status')";
    if($conn->query($sql) === TRUE) {
        echo "Asset added successfully.";
    } else {
        echo "Error adding asset: " . $conn->error;
    }
}

// 编辑资产
if(isset($_POST['edit'])) {
    $id = $_POST['id'];
    $name = $_POST['name'];
    $type = $_POST['type'];
    $purchase_date = $_POST['purchase_date'];
    $cost = $_POST['cost'];
    $status = $_POST['status'];

    $sql = "UPDATE assets SET name='$name', type='$type', purchase_date='$purchase_date', cost='$cost', status='$status' WHERE id=$id";
    if($conn->query($sql) === TRUE) {
        echo "Asset updated successfully.";
    } else {
        echo "Error updating asset: " . $conn->error;
    }
}

// 删除资产
if(isset($_GET['delete'])) {
    $id = $_GET['delete'];

    $sql = "DELETE FROM assets WHERE id=$id";
    if($conn->query($sql) === TRUE) {
        echo "Asset deleted successfully.";
    } else {
        echo "Error deleting asset: " . $conn->error;
    }
}

Through the above code, we can implement the functions of adding, editing and deleting assets. Users can fill in corresponding forms to perform these actions, and corresponding messages are displayed based on the results.

This article describes how to use PHP to develop a simple asset management module and integrate it into an enterprise resource planning (ERP) system. By using the code examples above, you can customize and extend the module to meet the specific needs of your business. The introduction of the asset management module can help enterprises better manage and track their assets, improve efficiency and control costs.

The above is the detailed content of Application of asset management module developed using PHP in enterprise resource planning (ERP) system. For more information, please follow other related articles on the PHP Chinese website!

Statement:
The content of this article is voluntarily contributed by netizens, and the copyright belongs to the original author. This site does not assume corresponding legal responsibility. If you find any content suspected of plagiarism or infringement, please contact admin@php.cn