Files
MES/app/views/Inventory/purchaseAdd.php
T
2026-08-08 18:28:49 +08:00

125 lines
6.5 KiB
PHP

<?php
include APP_PATH . 'app/views/layouts/admin_header.php';
?>
<div class="row">
<div class="col-md-10 col-md-offset-1">
<div class="box box-primary">
<div class="box-header with-border">
<h3 class="box-title"><i class="fa fa-plus"></i> 新建采购订单</h3>
</div>
<form method="post">
<input type="hidden" name="csrf_token" value="<?php echo htmlspecialchars($csrfToken); ?>">
<div class="box-body">
<div class="row">
<div class="col-md-4">
<div class="form-group">
<label>采购单号 <span class="text-red">*</span></label>
<input type="text" name="order_no" class="form-control" value="CG<?php echo date('YmdHis'); ?>" required>
</div>
</div>
<div class="col-md-4">
<div class="form-group">
<label>供应商</label>
<select name="supplier_id" class="form-control">
<option value="">-- 请选择 --</option>
<?php foreach ($suppliers as $s): ?>
<option value="<?php echo $s['id']; ?>"><?php echo htmlspecialchars($s['name']); ?></option>
<?php endforeach; ?>
</select>
</div>
</div>
<div class="col-md-2">
<div class="form-group">
<label>采购日期</label>
<input type="date" name="order_date" class="form-control" value="<?php echo date('Y-m-d'); ?>">
</div>
</div>
<div class="col-md-2">
<div class="form-group">
<label>状态</label>
<select name="status" class="form-control">
<option value="pending">待确认</option>
<option value="confirmed">已确认</option>
<option value="received">已收货</option>
</select>
</div>
</div>
</div>
<h4>采购明细</h4>
<table class="table table-bordered" id="itemsTable">
<thead>
<tr>
<th>产品名称</th>
<th style="width:120px">规格型号</th>
<th style="width:80px">数量</th>
<th style="width:80px">单位</th>
<th style="width:100px">单价</th>
<th style="width:100px">金额</th>
<th style="width:60px">操作</th>
</tr>
</thead>
<tbody id="itemsBody">
<tr>
<td><input type="text" name="product_name[]" class="form-control"></td>
<td><input type="text" name="product_model[]" class="form-control"></td>
<td><input type="number" name="quantity[]" class="form-control qty" value="1" min="1" onchange="calcRow(this)"></td>
<td><input type="text" name="unit[]" class="form-control" value="个"></td>
<td><input type="number" name="unit_price[]" class="form-control price" value="0" step="0.01" onchange="calcRow(this)"></td>
<td><input type="text" class="form-control amount" readonly value="0.00"></td>
<td><button type="button" class="btn btn-xs btn-danger" onclick="removeRow(this)"><i class="fa fa-times"></i></button></td>
</tr>
</tbody>
<tfoot>
<tr>
<td colspan="7">
<button type="button" class="btn btn-sm btn-success" onclick="addRow()"><i class="fa fa-plus"></i> 添加行</button>
</td>
</tr>
</tfoot>
</table>
<div class="form-group">
<label>备注</label>
<textarea name="remark" class="form-control" rows="2"></textarea>
</div>
</div>
<div class="box-footer">
<button type="submit" class="btn btn-primary"><i class="fa fa-save"></i> 保存</button>
<a href="<?php echo BASE_URL; ?>/Inventory/purchase" class="btn btn-default">返回</a>
</div>
</form>
</div>
</div>
</div>
<script>
function addRow() {
var tbody = document.getElementById('itemsBody');
var row = document.createElement('tr');
row.innerHTML = '<td><input type="text" name="product_name[]" class="form-control"></td>' +
'<td><input type="text" name="product_model[]" class="form-control"></td>' +
'<td><input type="number" name="quantity[]" class="form-control qty" value="1" min="1" onchange="calcRow(this)"></td>' +
'<td><input type="text" name="unit[]" class="form-control" value="个"></td>' +
'<td><input type="number" name="unit_price[]" class="form-control price" value="0" step="0.01" onchange="calcRow(this)"></td>' +
'<td><input type="text" class="form-control amount" readonly value="0.00"></td>' +
'<td><button type="button" class="btn btn-xs btn-danger" onclick="removeRow(this)"><i class="fa fa-times"></i></button></td>';
tbody.appendChild(row);
}
function removeRow(btn) {
var tbody = document.getElementById('itemsBody');
if (tbody.rows.length > 1) {
btn.closest('tr').remove();
}
}
function calcRow(el) {
var row = el.closest('tr');
var qty = parseFloat(row.querySelector('.qty').value) || 0;
var price = parseFloat(row.querySelector('.price').value) || 0;
row.querySelector('.amount').value = (qty * price).toFixed(2);
}
</script>
<?php include APP_PATH . 'app/views/layouts/admin_footer.php'; ?>