|
@@ -0,0 +1,525 @@
|
|
|
+<?php
|
|
|
+require_once 'conn.php';
|
|
|
+checkLogin();
|
|
|
+
|
|
|
+$id = $_GET['id'] ?? '';
|
|
|
+$page = $_GET['Page'] ?? '';
|
|
|
+$keys = urlencode($_GET['Keys'] ?? '');
|
|
|
+
|
|
|
+$hrefstr = "keys=$keys&Page=$page";
|
|
|
+
|
|
|
+
|
|
|
+if (!empty($id) && is_numeric($id)) {
|
|
|
+
|
|
|
+ $employee_id = $_SESSION['employee_id'];
|
|
|
+ $sql = "SELECT o.*, c.cs_company, cc.contact_name
|
|
|
+ FROM orders o
|
|
|
+ LEFT JOIN customer c ON o.customer_id = c.id
|
|
|
+ LEFT JOIN customer_contact cc ON o.contact_id = cc.id
|
|
|
+ WHERE o.id = $id AND o.employee_id = $employee_id";
|
|
|
+
|
|
|
+ $result = mysqli_query($conn, $sql);
|
|
|
+
|
|
|
+ if ($row = mysqli_fetch_assoc($result)) {
|
|
|
+ $order = $row;
|
|
|
+ } else {
|
|
|
+ echo "<script>alert('订单不存在或您没有权限查看');history.back();</script>";
|
|
|
+ exit;
|
|
|
+ }
|
|
|
+
|
|
|
+
|
|
|
+ $sql = "SELECT oi.*, p.ProductName
|
|
|
+ FROM order_items oi
|
|
|
+ LEFT JOIN products p ON oi.product_id = p.id
|
|
|
+ WHERE oi.order_id = $id";
|
|
|
+
|
|
|
+ $itemsResult = mysqli_query($conn, $sql);
|
|
|
+
|
|
|
+ $orderItems = [];
|
|
|
+ while ($itemRow = mysqli_fetch_assoc($itemsResult)) {
|
|
|
+ $orderItems[] = $itemRow;
|
|
|
+ }
|
|
|
+} else {
|
|
|
+ echo "<script>alert('订单不存在!');history.back();</script>";
|
|
|
+ exit;
|
|
|
+}
|
|
|
+?>
|
|
|
+<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
|
|
|
+<html xmlns="http://www.w3.org/1999/xhtml">
|
|
|
+<head>
|
|
|
+ <meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
|
|
|
+ <title>编辑订单</title>
|
|
|
+ <link rel="stylesheet" href="css/common.css" type="text/css" />
|
|
|
+ <link rel="stylesheet" href="css/alert.css" type="text/css" />
|
|
|
+ <script src="js/jquery-1.7.2.min.js"></script>
|
|
|
+ <script src="js/js.js"></script>
|
|
|
+ <style>
|
|
|
+ body {
|
|
|
+ margin: 0;
|
|
|
+ padding: 20px;
|
|
|
+ background:
|
|
|
+ }
|
|
|
+
|
|
|
+ margin-left: 0;
|
|
|
+ }
|
|
|
+ .product-row {
|
|
|
+ border: 1px solid
|
|
|
+ padding: 10px;
|
|
|
+ margin-bottom: 10px;
|
|
|
+ background-color:
|
|
|
+ position: relative;
|
|
|
+ }
|
|
|
+ .delete-product {
|
|
|
+ position: absolute;
|
|
|
+ right: 10px;
|
|
|
+ top: 10px;
|
|
|
+ color: red;
|
|
|
+ cursor: pointer;
|
|
|
+ }
|
|
|
+ .add-product-btn {
|
|
|
+ background-color:
|
|
|
+ color: white;
|
|
|
+ padding: 8px 12px;
|
|
|
+ border: none;
|
|
|
+ cursor: pointer;
|
|
|
+ margin-bottom: 15px;
|
|
|
+ }
|
|
|
+ .total-section {
|
|
|
+ margin-top: 20px;
|
|
|
+ padding: 10px;
|
|
|
+ background-color:
|
|
|
+ font-weight: bold;
|
|
|
+ }
|
|
|
+
|
|
|
+ margin-bottom: 20px;
|
|
|
+ }
|
|
|
+ </style>
|
|
|
+</head>
|
|
|
+<body>
|
|
|
+<div id="man_zone">
|
|
|
+ <form name="form1" id="form1" method="post" action="order_save.php?<?= $hrefstr ?>" onsubmit="return validateOrderForm()">
|
|
|
+ <table width="100%" border="0" cellpadding="3" cellspacing="1" class="table1">
|
|
|
+ <tbody>
|
|
|
+ <tr>
|
|
|
+ <th width="8%">订单编号</th>
|
|
|
+ <td>
|
|
|
+ <input type="text" id="order_code" name="order_code" value="<?= htmlspecialcharsFix($order['order_code']) ?>" class="txt1" />
|
|
|
+ <input type="hidden" name="id" value="<?= $id ?>" />
|
|
|
+ </td>
|
|
|
+ </tr>
|
|
|
+ <tr>
|
|
|
+ <th width="8%">客户选择</th>
|
|
|
+ <td>
|
|
|
+ <select id="customer_id" name="customer_id" onchange="loadCustomerContacts(this.value)">
|
|
|
+ <option value="0">请选择客户</option>
|
|
|
+ <?php
|
|
|
+ $customerSql = "SELECT id, cs_company FROM customer WHERE cs_belong = " . $_SESSION['employee_id'] . " ORDER BY cs_company";
|
|
|
+ $customerResult = mysqli_query($conn, $customerSql);
|
|
|
+ while ($customerRow = mysqli_fetch_assoc($customerResult)) {
|
|
|
+ $selected = ($order['customer_id'] == $customerRow['id']) ? ' selected' : '';
|
|
|
+ echo "<option value=\"{$customerRow['id']}\"$selected>" . htmlspecialcharsFix($customerRow['cs_company']) . "</option>";
|
|
|
+ }
|
|
|
+ ?>
|
|
|
+ </select>
|
|
|
+ </td>
|
|
|
+ </tr>
|
|
|
+ <tr>
|
|
|
+ <th width="8%">联系人</th>
|
|
|
+ <td>
|
|
|
+ <select id="contact_id" name="contact_id">
|
|
|
+ <option value="">请选择联系人</option>
|
|
|
+ <?php
|
|
|
+ if ($order['customer_id']) {
|
|
|
+ $contactSql = "SELECT id, contact_name FROM customer_contact WHERE customer_id = " . $order['customer_id'];
|
|
|
+ $contactResult = mysqli_query($conn, $contactSql);
|
|
|
+ while ($contactRow = mysqli_fetch_assoc($contactResult)) {
|
|
|
+ $selected = ($order['contact_id'] == $contactRow['id']) ? ' selected' : '';
|
|
|
+ echo "<option value=\"{$contactRow['id']}\"$selected>" . htmlspecialcharsFix($contactRow['contact_name']) . "</option>";
|
|
|
+ }
|
|
|
+ }
|
|
|
+ ?>
|
|
|
+ </select>
|
|
|
+ </td>
|
|
|
+ </tr>
|
|
|
+ <tr>
|
|
|
+ <th width="8%">订单日期</th>
|
|
|
+ <td>
|
|
|
+ <input type="date" id="order_date" name="order_date" value="<?= substr($order['order_date'], 0, 10) ?>" class="txt1" />
|
|
|
+ </td>
|
|
|
+ </tr>
|
|
|
+ <tr>
|
|
|
+ <th width="8%">预计交付日期</th>
|
|
|
+ <td>
|
|
|
+ <input type="date" id="delivery_date" name="delivery_date" value="<?= $order['delivery_date'] ? substr($order['delivery_date'], 0, 10) : '' ?>" class="txt1" />
|
|
|
+ </td>
|
|
|
+ </tr>
|
|
|
+ <tr>
|
|
|
+ <th width="8%">实际交付日期</th>
|
|
|
+ <td>
|
|
|
+ <input type="date" id="actual_delivery_date" name="actual_delivery_date" value="<?= $order['actual_delivery_date'] ? substr($order['actual_delivery_date'], 0, 10) : '' ?>" class="txt1" />
|
|
|
+ </td>
|
|
|
+ </tr>
|
|
|
+ <tr>
|
|
|
+ <th width="8%">订单状态</th>
|
|
|
+ <td>
|
|
|
+ <select id="order_status" name="order_status">
|
|
|
+ <option value="0" <?= $order['order_status'] == 0 ? 'selected' : '' ?>>已取消</option>
|
|
|
+ <option value="1" <?= $order['order_status'] == 1 ? 'selected' : '' ?>>待确认</option>
|
|
|
+ <option value="2" <?= $order['order_status'] == 2 ? 'selected' : '' ?>>已确认</option>
|
|
|
+ <option value="3" <?= $order['order_status'] == 3 ? 'selected' : '' ?>>生产中</option>
|
|
|
+ <option value="4" <?= $order['order_status'] == 4 ? 'selected' : '' ?>>已发货</option>
|
|
|
+ <option value="5" <?= $order['order_status'] == 5 ? 'selected' : '' ?>>已完成</option>
|
|
|
+ </select>
|
|
|
+ </td>
|
|
|
+ </tr>
|
|
|
+ <tr>
|
|
|
+ <th width="8%">付款状态</th>
|
|
|
+ <td>
|
|
|
+ <select id="payment_status" name="payment_status">
|
|
|
+ <option value="0" <?= $order['payment_status'] == 0 ? 'selected' : '' ?>>未付款</option>
|
|
|
+ <option value="1" <?= $order['payment_status'] == 1 ? 'selected' : '' ?>>部分付款</option>
|
|
|
+ <option value="2" <?= $order['payment_status'] == 2 ? 'selected' : '' ?>>已付清</option>
|
|
|
+ </select>
|
|
|
+ </td>
|
|
|
+ </tr>
|
|
|
+ <tr>
|
|
|
+ <th width="8%">币种</th>
|
|
|
+ <td>
|
|
|
+ <select id="currency" name="currency">
|
|
|
+ <option value="CNY" <?= $order['currency'] == 'CNY' ? 'selected' : '' ?>>人民币 (CNY)</option>
|
|
|
+ <option value="USD" <?= $order['currency'] == 'USD' ? 'selected' : '' ?>>美元 (USD)</option>
|
|
|
+ <option value="EUR" <?= $order['currency'] == 'EUR' ? 'selected' : '' ?>>欧元 (EUR)</option>
|
|
|
+ </select>
|
|
|
+ </td>
|
|
|
+ </tr>
|
|
|
+ <tr>
|
|
|
+ <th width="8%" valign="top">产品列表</th>
|
|
|
+ <td>
|
|
|
+ <button type="button" id="add-product-btn" class="add-product-btn">添加产品</button>
|
|
|
+ <div id="product-container">
|
|
|
+ <?php foreach ($orderItems as $index => $item): ?>
|
|
|
+ <div class="product-row" data-index="<?= $index ?>">
|
|
|
+ <span class="delete-product">×</span>
|
|
|
+ <div>
|
|
|
+ <label>产品:</label>
|
|
|
+ <select name="items[<?= $index ?>][product_id]" class="product-select" onchange="updateProductInfo(this)">
|
|
|
+ <option value="">请选择产品</option>
|
|
|
+ <?php
|
|
|
+ $productSql = "SELECT id, ProductName FROM products ORDER BY ProductName";
|
|
|
+ $productResult = mysqli_query($conn, $productSql);
|
|
|
+ while ($productRow = mysqli_fetch_assoc($productResult)) {
|
|
|
+ $selected = ($item['product_id'] == $productRow['id']) ? ' selected' : '';
|
|
|
+ echo "<option value=\"{$productRow['id']}\"$selected>" . htmlspecialcharsFix($productRow['ProductName']) . "</option>";
|
|
|
+ }
|
|
|
+ ?>
|
|
|
+ </select>
|
|
|
+ </div>
|
|
|
+ <div style="margin-top: 5px;">
|
|
|
+ <label>数量:</label>
|
|
|
+ <input type="number" name="items[<?= $index ?>][quantity]" value="<?= $item['quantity'] ?>" min="1" class="quantity-input" onchange="calculateItemTotal(this)">
|
|
|
+
|
|
|
+ <label style="margin-left: 10px;">单位:</label>
|
|
|
+ <input type="text" name="items[<?= $index ?>][unit]" value="<?= htmlspecialcharsFix($item['unit']) ?>" class="unit-input">
|
|
|
+
|
|
|
+ <label style="margin-left: 10px;">单价:</label>
|
|
|
+ <input type="number" step="0.01" name="items[<?= $index ?>][unit_price]" value="<?= $item['unit_price'] ?>" class="price-input" onchange="calculateItemTotal(this)">
|
|
|
+ </div>
|
|
|
+ <div style="margin-top: 5px;">
|
|
|
+ <label>折扣金额:</label>
|
|
|
+ <input type="number" step="0.01" name="items[<?= $index ?>][discount_amount]" value="<?= $item['discount_amount'] ?>" class="discount-amount-input" onchange="calculateItemTotal(this)">
|
|
|
+
|
|
|
+ <label style="margin-left: 10px;">折扣率:</label>
|
|
|
+ <input type="number" step="0.01" name="items[<?= $index ?>][discount_percent]" value="<?= $item['discount_percent'] ?>" class="discount-percent-input" max="100" min="0">%
|
|
|
+
|
|
|
+ <label style="margin-left: 10px;">总价:</label>
|
|
|
+ <input type="number" step="0.01" name="items[<?= $index ?>][total_price]" value="<?= $item['total_price'] ?>" class="total-price-input" readonly>
|
|
|
+ </div>
|
|
|
+ <div style="margin-top: 5px;">
|
|
|
+ <label>备注:</label>
|
|
|
+ <input type="text" name="items[<?= $index ?>][notes]" value="<?= htmlspecialcharsFix($item['notes']) ?>" style="width: 80%;">
|
|
|
+ </div>
|
|
|
+ </div>
|
|
|
+ <?php endforeach; ?>
|
|
|
+ </div>
|
|
|
+ <div class="total-section">
|
|
|
+ <div>
|
|
|
+ <label>订单小计:</label>
|
|
|
+ <span id="subtotal"><?= number_format($order['subtotal'], 2) ?></span>
|
|
|
+ <input type="hidden" name="subtotal" id="subtotal-input" value="<?= $order['subtotal'] ?>">
|
|
|
+ </div>
|
|
|
+ <div style="margin-top: 5px;">
|
|
|
+ <label>运费:</label>
|
|
|
+ <input type="number" step="0.01" name="shipping_fee" id="shipping-fee" value="<?= $order['shipping_fee'] ?>" onchange="calculateOrderTotal()">
|
|
|
+ </div>
|
|
|
+ <div style="margin-top: 5px;">
|
|
|
+ <label>订单折扣:</label>
|
|
|
+ <input type="number" step="0.01" name="discount_amount" id="order-discount" value="<?= $order['discount_amount'] ?>" onchange="calculateOrderTotal()">
|
|
|
+ </div>
|
|
|
+ <div style="margin-top: 5px;">
|
|
|
+ <label>订单总额:</label>
|
|
|
+ <span id="total-amount"><?= number_format($order['total_amount'], 2) ?></span>
|
|
|
+ <input type="hidden" name="total_amount" id="total-amount-input" value="<?= $order['total_amount'] ?>">
|
|
|
+ </div>
|
|
|
+ </div>
|
|
|
+ </td>
|
|
|
+ </tr>
|
|
|
+ <tr>
|
|
|
+ <th width="8%">订单备注</th>
|
|
|
+ <td>
|
|
|
+ <textarea name="notes" rows="3" style="width: 90%;"><?= htmlspecialcharsFix($order['notes']) ?></textarea>
|
|
|
+ </td>
|
|
|
+ </tr>
|
|
|
+ <tr>
|
|
|
+ <th width="8%">内部备注</th>
|
|
|
+ <td>
|
|
|
+ <textarea name="internal_notes" rows="3" style="width: 90%;"><?= htmlspecialcharsFix($order['internal_notes']) ?></textarea>
|
|
|
+ </td>
|
|
|
+ </tr>
|
|
|
+ <tr>
|
|
|
+ <th></th>
|
|
|
+ <td>
|
|
|
+ <input type="submit" name="save" value="保存订单" class="btn1">
|
|
|
+ <input type="button" value="返回" class="btn1" onClick="location.href='order.php?<?= $hrefstr ?>'" />
|
|
|
+ </td>
|
|
|
+ </tr>
|
|
|
+ </tbody>
|
|
|
+ </table>
|
|
|
+ </form>
|
|
|
+
|
|
|
+ <script>
|
|
|
+ var productIndex = <?= count($orderItems) ?>;
|
|
|
+
|
|
|
+ $(document).ready(function() {
|
|
|
+
|
|
|
+ calculateOrderTotal();
|
|
|
+
|
|
|
+
|
|
|
+ $('#add-product-btn').click(function() {
|
|
|
+ addProductRow();
|
|
|
+ });
|
|
|
+
|
|
|
+
|
|
|
+ $(document).on('click', '.delete-product', function() {
|
|
|
+ if ($('.product-row').length > 1) {
|
|
|
+ $(this).closest('.product-row').remove();
|
|
|
+ reindexProductRows();
|
|
|
+ calculateOrderTotal();
|
|
|
+ } else {
|
|
|
+ alert('订单至少需要一个产品');
|
|
|
+ }
|
|
|
+ });
|
|
|
+
|
|
|
+
|
|
|
+ $(document).on('change', '.discount-percent-input', function() {
|
|
|
+ var row = $(this).closest('.product-row');
|
|
|
+ var percent = parseFloat($(this).val()) || 0;
|
|
|
+ var quantity = parseInt(row.find('.quantity-input').val()) || 0;
|
|
|
+ var price = parseFloat(row.find('.price-input').val()) || 0;
|
|
|
+ var subtotal = quantity * price;
|
|
|
+
|
|
|
+ var discountAmount = (subtotal * percent / 100).toFixed(2);
|
|
|
+ row.find('.discount-amount-input').val(discountAmount);
|
|
|
+
|
|
|
+ calculateItemTotal(this);
|
|
|
+ });
|
|
|
+
|
|
|
+ $(document).on('change', '.discount-amount-input', function() {
|
|
|
+ var row = $(this).closest('.product-row');
|
|
|
+ var amount = parseFloat($(this).val()) || 0;
|
|
|
+ var quantity = parseInt(row.find('.quantity-input').val()) || 0;
|
|
|
+ var price = parseFloat(row.find('.price-input').val()) || 0;
|
|
|
+ var subtotal = quantity * price;
|
|
|
+
|
|
|
+ if (subtotal > 0) {
|
|
|
+ var percent = ((amount / subtotal) * 100).toFixed(2);
|
|
|
+ row.find('.discount-percent-input').val(percent);
|
|
|
+ }
|
|
|
+
|
|
|
+ calculateItemTotal(this);
|
|
|
+ });
|
|
|
+ });
|
|
|
+
|
|
|
+ function addProductRow() {
|
|
|
+ var html = `
|
|
|
+ <div class="product-row" data-index="${productIndex}">
|
|
|
+ <span class="delete-product">×</span>
|
|
|
+ <div>
|
|
|
+ <label>产品:</label>
|
|
|
+ <select name="items[${productIndex}][product_id]" class="product-select" onchange="updateProductInfo(this)">
|
|
|
+ <option value="">请选择产品</option>
|
|
|
+ ${getProductOptions()}
|
|
|
+ </select>
|
|
|
+ </div>
|
|
|
+ <div style="margin-top: 5px;">
|
|
|
+ <label>数量:</label>
|
|
|
+ <input type="number" name="items[${productIndex}][quantity]" value="1" min="1" class="quantity-input" onchange="calculateItemTotal(this)">
|
|
|
+
|
|
|
+ <label style="margin-left: 10px;">单位:</label>
|
|
|
+ <input type="text" name="items[${productIndex}][unit]" value="" class="unit-input">
|
|
|
+
|
|
|
+ <label style="margin-left: 10px;">单价:</label>
|
|
|
+ <input type="number" step="0.01" name="items[${productIndex}][unit_price]" value="0.00" class="price-input" onchange="calculateItemTotal(this)">
|
|
|
+ </div>
|
|
|
+ <div style="margin-top: 5px;">
|
|
|
+ <label>折扣金额:</label>
|
|
|
+ <input type="number" step="0.01" name="items[${productIndex}][discount_amount]" value="0.00" class="discount-amount-input" onchange="calculateItemTotal(this)">
|
|
|
+
|
|
|
+ <label style="margin-left: 10px;">折扣率:</label>
|
|
|
+ <input type="number" step="0.01" name="items[${productIndex}][discount_percent]" value="0" class="discount-percent-input" max="100" min="0">%
|
|
|
+
|
|
|
+ <label style="margin-left: 10px;">总价:</label>
|
|
|
+ <input type="number" step="0.01" name="items[${productIndex}][total_price]" value="0.00" class="total-price-input" readonly>
|
|
|
+ </div>
|
|
|
+ <div style="margin-top: 5px;">
|
|
|
+ <label>备注:</label>
|
|
|
+ <input type="text" name="items[${productIndex}][notes]" value="" style="width: 80%;">
|
|
|
+ </div>
|
|
|
+ </div>
|
|
|
+ `;
|
|
|
+
|
|
|
+ $('#product-container').append(html);
|
|
|
+ productIndex++;
|
|
|
+ }
|
|
|
+
|
|
|
+ function getProductOptions() {
|
|
|
+ var options = '';
|
|
|
+ <?php
|
|
|
+ $productSql = "SELECT id, ProductName FROM products ORDER BY ProductName";
|
|
|
+ $productResult = mysqli_query($conn, $productSql);
|
|
|
+ while ($productRow = mysqli_fetch_assoc($productResult)) {
|
|
|
+ echo "options += '<option value=\"{$productRow['id']}\">" . addslashes(htmlspecialcharsFix($productRow['ProductName'])) . "</option>';\n";
|
|
|
+ }
|
|
|
+ ?>
|
|
|
+ return options;
|
|
|
+ }
|
|
|
+
|
|
|
+ function reindexProductRows() {
|
|
|
+ $('.product-row').each(function(index) {
|
|
|
+ $(this).attr('data-index', index);
|
|
|
+ $(this).find('select, input').each(function() {
|
|
|
+ var name = $(this).attr('name');
|
|
|
+ if (name) {
|
|
|
+ name = name.replace(/items\[\d+\]/, 'items[' + index + ']');
|
|
|
+ $(this).attr('name', name);
|
|
|
+ }
|
|
|
+ });
|
|
|
+ });
|
|
|
+ productIndex = $('.product-row').length;
|
|
|
+ }
|
|
|
+
|
|
|
+ function updateProductInfo(selectElement) {
|
|
|
+ var productId = $(selectElement).val();
|
|
|
+ var row = $(selectElement).closest('.product-row');
|
|
|
+
|
|
|
+ if (productId) {
|
|
|
+
|
|
|
+ $.ajax({
|
|
|
+ url: 'get_product_info.php',
|
|
|
+ type: 'GET',
|
|
|
+ data: {id: productId},
|
|
|
+ dataType: 'json',
|
|
|
+ success: function(data) {
|
|
|
+ if (data) {
|
|
|
+ row.find('.unit-input').val(data.unit);
|
|
|
+ row.find('.price-input').val(data.price);
|
|
|
+ calculateItemTotal(selectElement);
|
|
|
+ }
|
|
|
+ }
|
|
|
+ });
|
|
|
+ } else {
|
|
|
+ row.find('.unit-input').val('');
|
|
|
+ row.find('.price-input').val('0.00');
|
|
|
+ calculateItemTotal(selectElement);
|
|
|
+ }
|
|
|
+ }
|
|
|
+
|
|
|
+ function calculateItemTotal(element) {
|
|
|
+ var row = $(element).closest('.product-row');
|
|
|
+ var quantity = parseInt(row.find('.quantity-input').val()) || 0;
|
|
|
+ var price = parseFloat(row.find('.price-input').val()) || 0;
|
|
|
+ var discountAmount = parseFloat(row.find('.discount-amount-input').val()) || 0;
|
|
|
+
|
|
|
+ var subtotal = quantity * price;
|
|
|
+ var total = subtotal - discountAmount;
|
|
|
+ if (total < 0) total = 0;
|
|
|
+
|
|
|
+ row.find('.total-price-input').val(total.toFixed(2));
|
|
|
+
|
|
|
+ calculateOrderTotal();
|
|
|
+ }
|
|
|
+
|
|
|
+ function calculateOrderTotal() {
|
|
|
+ var subtotal = 0;
|
|
|
+ $('.total-price-input').each(function() {
|
|
|
+ subtotal += parseFloat($(this).val()) || 0;
|
|
|
+ });
|
|
|
+
|
|
|
+ var shippingFee = parseFloat($('#shipping-fee').val()) || 0;
|
|
|
+ var orderDiscount = parseFloat($('#order-discount').val()) || 0;
|
|
|
+ var total = subtotal + shippingFee - orderDiscount;
|
|
|
+
|
|
|
+ if (total < 0) total = 0;
|
|
|
+
|
|
|
+ $('#subtotal').text(subtotal.toFixed(2));
|
|
|
+ $('#subtotal-input').val(subtotal.toFixed(2));
|
|
|
+ $('#total-amount').text(total.toFixed(2));
|
|
|
+ $('#total-amount-input').val(total.toFixed(2));
|
|
|
+ }
|
|
|
+
|
|
|
+ function loadCustomerContacts(customerId) {
|
|
|
+ if (customerId) {
|
|
|
+ $.ajax({
|
|
|
+ url: 'get_customer_contacts.php',
|
|
|
+ type: 'GET',
|
|
|
+ data: {customer_id: customerId},
|
|
|
+ dataType: 'json',
|
|
|
+ success: function(data) {
|
|
|
+ var options = '<option value="">请选择联系人</option>';
|
|
|
+ if (data && data.length > 0) {
|
|
|
+ for (var i = 0; i < data.length; i++) {
|
|
|
+ options += '<option value="' + data[i].id + '">' + data[i].contact_name + '</option>';
|
|
|
+ }
|
|
|
+ }
|
|
|
+ $('#contact_id').html(options);
|
|
|
+ }
|
|
|
+ });
|
|
|
+ } else {
|
|
|
+ $('#contact_id').html('<option value="">请选择联系人</option>');
|
|
|
+ }
|
|
|
+ }
|
|
|
+
|
|
|
+ function validateOrderForm() {
|
|
|
+ var orderCode = $('#order_code').val();
|
|
|
+ var customerId = $('#customer_id').val();
|
|
|
+ var hasProducts = false;
|
|
|
+
|
|
|
+ $('.product-select').each(function() {
|
|
|
+ if ($(this).val()) {
|
|
|
+ hasProducts = true;
|
|
|
+ return false;
|
|
|
+ }
|
|
|
+ });
|
|
|
+
|
|
|
+ if (!orderCode) {
|
|
|
+ alert('订单编号不能为空');
|
|
|
+ $('#order_code').focus();
|
|
|
+ return false;
|
|
|
+ }
|
|
|
+
|
|
|
+ if (!customerId || customerId == '0') {
|
|
|
+ alert('请选择客户');
|
|
|
+ $('#customer_id').focus();
|
|
|
+ return false;
|
|
|
+ }
|
|
|
+
|
|
|
+ if (!hasProducts) {
|
|
|
+ alert('请至少选择一个产品');
|
|
|
+ return false;
|
|
|
+ }
|
|
|
+
|
|
|
+ return true;
|
|
|
+ }
|
|
|
+ </script>
|
|
|
+</div>
|
|
|
+</body>
|
|
|
+</html>
|