How to use PHP and Vue to develop the financial management function of warehouse management
As a warehouse management system, financial management is a crucial part. Through reasonable financial management, the stability of the warehouse's capital flow and profits can be ensured. This article will introduce how to use PHP and Vue to develop financial management functions for warehouse management, and provide corresponding code examples.
Before starting development, you first need to design a database model to store financial information. For example, we can design the following table structure:
Next, we will use PHP to develop the back-end interface so that the front-end can be implemented by calling these interfaces Financial management functions.
2.1 Get the warehouse list
<?php // 连接数据库并查询仓库表 $conn = new mysqli("localhost", "username", "password", "database"); if ($conn->connect_error) { die("数据库连接失败: " . $conn->connect_error); } $sql = "SELECT * FROM warehouse"; $result = $conn->query($sql); // 返回查询结果 $warehouses = []; if ($result->num_rows > 0) { while ($row = $result->fetch_assoc()) { $warehouses[] = $row; } } echo json_encode($warehouses); $conn->close(); ?>
2.2 Get the supplier list
<?php // 连接数据库并查询供应商表 $conn = new mysqli("localhost", "username", "password", "database"); if ($conn->connect_error) { die("数据库连接失败: " . $conn->connect_error); } $sql = "SELECT * FROM supplier"; $result = $conn->query($sql); // 返回查询结果 $suppliers = []; if ($result->num_rows > 0) { while ($row = $result->fetch_assoc()) { $suppliers[] = $row; } } echo json_encode($suppliers); $conn->close(); ?>
2.3 Add purchase record
<?php // 连接数据库并插入进货记录 $conn = new mysqli("localhost", "username", "password", "database"); if ($conn->connect_error) { die("数据库连接失败: " . $conn->connect_error); } $supplier = $_POST['supplier']; $item = $_POST['item']; $quantity = $_POST['quantity']; $unit_price = $_POST['unit_price']; $sql = "INSERT INTO purchase (supplier, item, quantity, unit_price) VALUES ('$supplier', '$item', '$quantity', '$unit_price')"; $result = $conn->query($sql); // 返回结果 if ($result === TRUE) { echo "进货记录添加成功"; } else { echo "进货记录添加失败: " . $conn->error; } $conn->close(); ?>
2.4 Add sales record
<?php // 连接数据库并插入销售记录 $conn = new mysqli("localhost", "username", "password", "database"); if ($conn->connect_error) { die("数据库连接失败: " . $conn->connect_error); } $customer = $_POST['customer']; $item = $_POST['item']; $quantity = $_POST['quantity']; $unit_price = $_POST['unit_price']; $sql = "INSERT INTO sales (customer, item, quantity, unit_price) VALUES ('$customer', '$item', '$quantity', '$unit_price')"; $result = $conn->query($sql); // 返回结果 if ($result === TRUE) { echo "销售记录添加成功"; } else { echo "销售记录添加失败: " . $conn->error; } $conn->close(); ?>
2.5 Add payment record
<?php // 连接数据库并插入收款记录 $conn = new mysqli("localhost", "username", "password", "database"); if ($conn->connect_error) { die("数据库连接失败: " . $conn->connect_error); } $sales = $_POST['sales']; $customer = $_POST['customer']; $amount = $_POST['amount']; $sql = "INSERT INTO payment (sales, customer, amount) VALUES ('$sales', '$customer', '$amount')"; $result = $conn->query($sql); // 返回结果 if ($result === TRUE) { echo "收款记录添加成功"; } else { echo "收款记录添加失败: " . $conn->error; } $conn->close(); ?>
2.6 Add expenditure record
<?php // 连接数据库并插入支出记录 $conn = new mysqli("localhost", "username", "password", "database"); if ($conn->connect_error) { die("数据库连接失败: " . $conn->connect_error); } $payee = $_POST['payee']; $amount = $_POST['amount']; $date = $_POST['date']; $sql = "INSERT INTO expense (payee, amount, date) VALUES ('$payee', '$amount', '$date')"; $result = $conn->query($sql); // 返回结果 if ($result === TRUE) { echo "支出记录添加成功"; } else { echo "支出记录添加失败: " . $conn->error; } $conn->close(); ?>
Through Vue, we can easily create An interactive interface that manages financial information by calling the back-end interface.
3.1 Get the warehouse list
<template> <div> <h2>仓库列表</h2> <ul> <li v-for="warehouse in warehouses" :key="warehouse.id"> {{ warehouse.name }} - {{ warehouse.address }} </li> </ul> </div> </template> <script> export default { data() { return { warehouses: [] } }, mounted() { this.getWarehouses(); }, methods: { getWarehouses() { axios.get('/api/getWarehouses') .then(response => { this.warehouses = response.data; }) .catch(error => { console.error(error); }); } } } </script>
3.2 Add purchase record
<template> <div> <h2>添加进货记录</h2> <form @submit.prevent="addPurchase"> <label for="supplier">供应商:</label> <input type="text" v-model="supplier"> <label for="item">货物名称:</label> <input type="text" v-model="item"> <label for="quantity">进货数量:</label> <input type="number" v-model="quantity" min="1"> <label for="unit_price">进货单价:</label> <input type="number" v-model="unit_price"> <button type="submit">添加进货记录</button> </form> </div> </template> <script> export default { data() { return { supplier: '', item: '', quantity: '', unit_price: '' } }, methods: { addPurchase() { axios.post('/api/addPurchase', { supplier: this.supplier, item: this.item, quantity: this.quantity, unit_price: this.unit_price }) .then(response => { console.log(response.data); }) .catch(error => { console.error(error); }); } } } </script>
3.3 The code for adding sales record, adding receipt record and adding expenditure record is similar to the code in Section 3.2 , with only minor modifications.
Through these sample codes, we can see that it is not complicated to use PHP and Vue to develop financial management functions for warehouse management. You can modify and extend it to meet your specific business requirements. At the same time, this example also provides you with a good development framework to help you better understand and apply PHP and Vue development technologies.
The above is the detailed content of How to use PHP and Vue to develop financial management functions for warehouse management. For more information, please follow other related articles on the PHP Chinese website!