diff --git a/ruoyi-admin/src/main/java/com/ruoyi/purchase/controller/PurchaseOrderChildController.java b/ruoyi-admin/src/main/java/com/ruoyi/purchase/controller/PurchaseOrderChildController.java index a49af649..29acbbdc 100644 --- a/ruoyi-admin/src/main/java/com/ruoyi/purchase/controller/PurchaseOrderChildController.java +++ b/ruoyi-admin/src/main/java/com/ruoyi/purchase/controller/PurchaseOrderChildController.java @@ -114,7 +114,6 @@ public class PurchaseOrderChildController extends BaseController { return toAjax(purchaseOrderChildService.updatePurchaseOrderChild(purchaseOrderChild)); } - /** * 删除采购订单子表 */ diff --git a/ruoyi-admin/src/main/java/com/ruoyi/purchase/controller/PurchaseOrderController.java b/ruoyi-admin/src/main/java/com/ruoyi/purchase/controller/PurchaseOrderController.java index 0f4279eb..461e01df 100644 --- a/ruoyi-admin/src/main/java/com/ruoyi/purchase/controller/PurchaseOrderController.java +++ b/ruoyi-admin/src/main/java/com/ruoyi/purchase/controller/PurchaseOrderController.java @@ -33,9 +33,11 @@ import org.springframework.beans.BeanUtils; import org.springframework.beans.factory.annotation.Autowired; import org.springframework.stereotype.Controller; import org.springframework.ui.ModelMap; +import org.springframework.util.CollectionUtils; import org.springframework.web.bind.annotation.*; import javax.servlet.http.HttpServletResponse; +import javax.validation.Valid; import java.io.IOException; import java.math.BigDecimal; import java.util.*; @@ -114,45 +116,83 @@ public class PurchaseOrderController extends BaseController @Log(title = "采购订单", businessType = BusinessType.INSERT) @PostMapping("/add") @ResponseBody - public AjaxResult addSave(@RequestBody PurchaseOrder purchaseOrder) throws Exception{ - //获取采购订单子表中的供应商,核算供应商数量和采购物料合计以及采购数量合计,采购不含税报价合计,采购含税报价合计 + public AjaxResult addSave(@Valid @RequestBody PurchaseOrder purchaseOrder) { + // 数据校验,确保前端传入数据格式正确 + validatePurchaseOrder(purchaseOrder); + // 生成采购订单编号 purchaseOrder.setPurchaseOrderCode(redisCache.generateBillNo("CG")); - BigDecimal materialNoRmb = BigDecimal.valueOf(0.0); - BigDecimal materialRmb = BigDecimal.valueOf(0.0); - BigDecimal materialNoRmbSum = BigDecimal.valueOf(0.0); - BigDecimal materialRmbSum = BigDecimal.valueOf(0.0); - BigDecimal materialSum = BigDecimal.valueOf(0.0); - List purchaseMaterials = new ArrayList<>(); + // 初始化累加变量 + BigDecimal materialNoRmb = BigDecimal.ZERO; + BigDecimal materialRmb = BigDecimal.ZERO; + BigDecimal materialNoRmbSum = BigDecimal.ZERO; + BigDecimal materialRmbSum = BigDecimal.ZERO; Long materialNum = 0L; int supplierNum = 0; - int purOdersize = purchaseOrder.getPurchaseOrderChildList().size(); - if(purOdersize > 1){ - purchaseMaterials = purchaseOrder.getPurchaseOrderChildList(); - for (PurchaseOrderChild purchaseOrderChild : purchaseMaterials) { - purchaseOrderChild.setPurchaseOrderCode(purchaseOrder.getPurchaseOrderCode()); - for (PurchaseQuoteChild purchaseSupplierQuote : purchaseOrderChild.getPurchaseQuoteChildList()){ - BigDecimal suplierMaterialNoRmb = purchaseSupplierQuote.getMaterialNoRmb(); - BigDecimal suplierMaterialRmb = purchaseSupplierQuote.getMaterialRmb(); - Long suplierMaterialNum = purchaseSupplierQuote.getMaterialNum(); - BigDecimal suplierMaterialNoRmbSum = suplierMaterialNoRmb.multiply(BigDecimal.valueOf(suplierMaterialNum)); - BigDecimal suplierMaterialRmbSum = suplierMaterialRmb.multiply(BigDecimal.valueOf(suplierMaterialNum)); - materialNum = materialNum + suplierMaterialNum; - materialNoRmb = materialNoRmb.add(purchaseSupplierQuote.getMaterialNoRmb()); - materialRmb = materialRmb.add(purchaseSupplierQuote.getMaterialRmb()); - materialRmbSum = materialRmbSum.add(suplierMaterialRmbSum); - materialNoRmbSum = materialNoRmbSum.add(suplierMaterialNoRmbSum); - purchaseSupplierQuote.setPurchaseQuoteCode(purchaseOrder.getPurchaseOrderCode()); - if (purchaseSupplierQuote.getSupplierCode() != null){ - supplierNum ++; - } - } - purchaseOrderChild.setMaterialNormb(materialNoRmb); - purchaseOrderChild.setMaterialRmb(materialRmb); - purchaseOrderChild.setMaterialNum(materialNum); - } - purchaseOrder.setSupplierNum(supplierNum); + // 遍历处理采购订单子表 + for (PurchaseOrderChild child : purchaseOrder.getPurchaseOrderChildList()) { + child.setPurchaseOrderCode(purchaseOrder.getPurchaseOrderCode()); + // 累加物料数量和金额 + for (PurchaseQuoteChild quote : child.getPurchaseQuoteChildList()) { + //获取物料供应商采购价格 + BigDecimal suplierMaterialNoRmb = quote.getMaterialNoRmb(); + // 获取物料供应商采购价格 + BigDecimal suplierMaterialRmb = quote.getMaterialRmb(); + // 获取物料数量 + Long suplierMaterialNum = quote.getMaterialNum(); + // 累加物料数量 + materialNum += suplierMaterialNum; + // 累加不含税物料价格 + materialNoRmb = materialNoRmb.add(suplierMaterialNoRmb); + // 累加含税物料价格 + materialRmb = materialRmb.add(suplierMaterialRmb); + + child.setPurchasePlanCode(quote.getPurchasePlanCode()); + // 计算不含税物料总价 + BigDecimal suplierMaterialNoRmbSumLocal = suplierMaterialNoRmb.multiply(BigDecimal.valueOf(suplierMaterialNum)); + // 计算物料含税总价 + BigDecimal suplierMaterialRmbSumLocal = suplierMaterialRmb.multiply(BigDecimal.valueOf(suplierMaterialNum)); + // 累加物料总价 + materialNoRmbSum = materialNoRmbSum.add(suplierMaterialNoRmbSumLocal); + // 累加物料含税总价 + materialRmbSum = materialRmbSum.add(suplierMaterialRmbSumLocal); + + // 设置采购报价单编号和供应商信息到QuoteChild + quote.setPurchaseQuoteCode(purchaseOrder.getPurchaseOrderCode()); + child.setSupplierCode(quote.getSupplierCode()); + child.setSupplierName(quote.getSupplierName()); + + // 确保供应商数量统计准确 + if (quote.getSupplierCode() != null) { + supplierNum++; + } + } + + // 设置累加的物料信息到子表 + child.setMaterialNoRmb(materialNoRmb); + child.setMaterialRmb(materialRmb); + child.setMaterialNum(materialNum); + + // 执行子表插入操作 + purchaseOrderChildService.insertPurchaseOrderChild(child); + } + + // 设置主表的供应商数量 + purchaseOrder.setSupplierNum(supplierNum); + + // 执行主表插入操作 + return toAjax(purchaseOrderService.insertPurchaseOrder(purchaseOrder)); // 假设toAjax方法处理成功逻辑 + } + + // 数据校验逻辑 + private void validatePurchaseOrder(PurchaseOrder purchaseOrder) { + if (CollectionUtils.isEmpty(purchaseOrder.getPurchaseOrderChildList())) { + try { + throw new Exception("采购订单子项不能为空"); + } catch (Exception e) { + throw new RuntimeException(e); + } } - return toAjax(purchaseOrderService.insertPurchaseOrder(purchaseOrder)); + // 可以添加更多校验逻辑 } /** diff --git a/ruoyi-admin/src/main/java/com/ruoyi/purchase/domain/PurchaseOrderChild.java b/ruoyi-admin/src/main/java/com/ruoyi/purchase/domain/PurchaseOrderChild.java index c7af76bd..d1814ee2 100644 --- a/ruoyi-admin/src/main/java/com/ruoyi/purchase/domain/PurchaseOrderChild.java +++ b/ruoyi-admin/src/main/java/com/ruoyi/purchase/domain/PurchaseOrderChild.java @@ -26,6 +26,8 @@ public class PurchaseOrderChild extends BaseEntity @Excel(name = "关联采购订单号") private String purchaseOrderCode; + private String purchasePlanCode; + /** 供应商代码 */ @Excel(name = "供应商代码") private String supplierCode; @@ -44,7 +46,7 @@ public class PurchaseOrderChild extends BaseEntity /** 物料不含税单价 */ @Excel(name = "物料不含税单价") - private BigDecimal materialNormb; + private BigDecimal materialNoRmb; /** 物料含税单价 */ @Excel(name = "物料含税单价") @@ -64,11 +66,11 @@ public class PurchaseOrderChild extends BaseEntity /** 不含税总价(RMB) */ @Excel(name = "不含税总价(RMB)") - private BigDecimal materialNormbsum; + private BigDecimal materialNoRmbSum; /** 含税总价(RMB) */ @Excel(name = "含税总价(RMB)") - private BigDecimal materialRmbsum; + private BigDecimal materialRmbSum; /** 交货时间 */ @JsonFormat(pattern = "yyyy-MM-dd") @@ -130,7 +132,15 @@ public class PurchaseOrderChild extends BaseEntity this.supplierCode = supplierCode; } - public String getSupplierCode() + public String getPurchasePlanCode() { + return purchasePlanCode; + } + + public void setPurchasePlanCode(String purchasePlanCode) { + this.purchasePlanCode = purchasePlanCode; + } + + public String getSupplierCode() { return supplierCode; } @@ -161,16 +171,16 @@ public class PurchaseOrderChild extends BaseEntity { return materialName; } - public void setMaterialNormb(BigDecimal materialNormb) - { - this.materialNormb = materialNormb; + + public BigDecimal getMaterialNoRmb() { + return materialNoRmb; } - public BigDecimal getMaterialNormb() - { - return materialNormb; + public void setMaterialNoRmb(BigDecimal materialNoRmb) { + this.materialNoRmb = materialNoRmb; } - public void setMaterialRmb(BigDecimal materialRmb) + + public void setMaterialRmb(BigDecimal materialRmb) { this.materialRmb = materialRmb; } @@ -206,25 +216,24 @@ public class PurchaseOrderChild extends BaseEntity { return materialSum; } - public void setMaterialNormbsum(BigDecimal materialNormbsum) - { - this.materialNormbsum = materialNormbsum; + + public BigDecimal getMaterialNoRmbSum() { + return materialNoRmbSum; } - public BigDecimal getMaterialNormbsum() - { - return materialNormbsum; + public void setMaterialNoRmbSum(BigDecimal materialNoRmbSum) { + this.materialNoRmbSum = materialNoRmbSum; } - public void setMaterialRmbsum(BigDecimal materialRmbsum) - { - this.materialRmbsum = materialRmbsum; + + public BigDecimal getMaterialRmbSum() { + return materialRmbSum; } - public BigDecimal getMaterialRmbsum() - { - return materialRmbsum; + public void setMaterialRmbSum(BigDecimal materialRmbSum) { + this.materialRmbSum = materialRmbSum; } - public void setDeliveryTime(Date deliveryTime) + + public void setDeliveryTime(Date deliveryTime) { this.deliveryTime = deliveryTime; } @@ -293,17 +302,18 @@ public class PurchaseOrderChild extends BaseEntity return new ToStringBuilder(this,ToStringStyle.MULTI_LINE_STYLE) .append("purchaseOrderChildId", getPurchaseOrderChildId()) .append("purchaseOrderCode", getPurchaseOrderCode()) + .append("purchasePlanCode", getPurchasePlanCode()) .append("supplierCode", getSupplierCode()) .append("supplierName", getSupplierName()) .append("materialCode", getMaterialCode()) .append("materialName", getMaterialName()) - .append("materialNormb", getMaterialNormb()) + .append("materialNoRmb", getMaterialNoRmb()) .append("materialRmb", getMaterialRmb()) .append("materialNum", getMaterialNum()) .append("materialAmount", getMaterialAmount()) .append("materialSum", getMaterialSum()) - .append("materialNormbsum", getMaterialNormbsum()) - .append("materialRmbsum", getMaterialRmbsum()) + .append("materialNoRmbSum", getMaterialNoRmbSum()) + .append("materialRmbSum", getMaterialRmbSum()) .append("deliveryTime", getDeliveryTime()) .append("eceiptStatus", getEceiptStatus()) .append("paymentStatus", getPaymentStatus()) diff --git a/ruoyi-admin/src/main/resources/mapper/purchase/PurchaseOrderChildMapper.xml b/ruoyi-admin/src/main/resources/mapper/purchase/PurchaseOrderChildMapper.xml index 9cdcf82d..09f82bc3 100644 --- a/ruoyi-admin/src/main/resources/mapper/purchase/PurchaseOrderChildMapper.xml +++ b/ruoyi-admin/src/main/resources/mapper/purchase/PurchaseOrderChildMapper.xml @@ -5,40 +5,45 @@ PUBLIC "-//mybatis.org//DTD Mapper 3.0//EN" - - - - - - - - - - - - - - - - - - - - - - - - + + + + + + + + + + + + + + + + + + + + + + + + + - select purchase_order_child_id, purchase_order_code, supplier_code, supplier_name, material_code, material_name, material_noRmb, material_rmb, material_num, material_amount, material_sum, material_noRmbSum, material_rmbSum, delivery_time, eceipt_status, payment_status, tax_rate, create_by, create_time, update_by, update_time, del_flag, standby_one, standby_two from purchase_order_child + select purchase_order_child_id, purchase_order_code, supplier_code, supplier_name, + material_code, material_name, material_no_rmb, material_rmb, material_num, + material_amount, material_sum, material_no_rmb_sum, material_rmb_sum, delivery_time, + eceipt_status, payment_status, tax_rate, create_by, create_time, update_by, update_time, + del_flag, standby_one, standby_two from purchase_order_child - + and purchase_order_code like concat('%', #{purchaseOrderCode}, '%') and supplier_code like concat('%', #{supplierCode}, '%') and supplier_name like concat('%', #{supplierName}, '%') and billing_date between #{params.beginBillingDate} and #{params.endBillingDate} - and close_case_no = #{closeCaseNo} - and confirm_no = #{confirmNo} - and audit_no = #{auditNo} - and approve_no = #{approveNo} @@ -93,22 +95,10 @@ PUBLIC "-//mybatis.org//DTD Mapper 3.0//EN" purchase_category, purchase_commander, customer_order_number, - remark_content, - close_case_no, - close_case_name, - close_case_time, - confirm_no, - confirm_name, - confirm_time, - audit_no, - audit_name, - audit_time, - approve_no, - approve_name, - approve_time, - first_add_time, standby_one, standby_two, + create_time, + create_by, #{purchaseOrderCode}, @@ -128,21 +118,10 @@ PUBLIC "-//mybatis.org//DTD Mapper 3.0//EN" #{purchaseCommander}, #{customerOrderNumber}, #{remarkContent}, - #{closeCaseNo}, - #{closeCaseName}, - #{closeCaseTime}, - #{confirmNo}, - #{confirmName}, - #{confirmTime}, - #{auditNo}, - #{auditName}, - #{auditTime}, - #{approveNo}, - #{approveName}, - #{approveTime}, - now(), #{standbyOne}, #{standbyTwo}, + #{createTime}, + #{createBy}, @@ -178,7 +157,6 @@ PUBLIC "-//mybatis.org//DTD Mapper 3.0//EN" approve_no = #{approveNo}, approve_name = #{approveName}, approve_time = #{approveTime}, - update_info_time = CONCAT_WS(',',NOW(),update_info_time), standby_one = #{standbyOne}, standby_two = #{standbyTwo}, @@ -201,7 +179,6 @@ PUBLIC "-//mybatis.org//DTD Mapper 3.0//EN" \ No newline at end of file diff --git a/ruoyi-admin/src/main/resources/templates/erp/material/material.html b/ruoyi-admin/src/main/resources/templates/erp/material/material.html index 389b0271..4cb34676 100644 --- a/ruoyi-admin/src/main/resources/templates/erp/material/material.html +++ b/ruoyi-admin/src/main/resources/templates/erp/material/material.html @@ -125,7 +125,7 @@ detailUrl: prefix + "/detail/{id}", pageList: [10, 25, 50], pageSize: 10, - showColumns: false, + showColumns: true, modalName: "物料信息", fixedColumns: true, // 启用冻结列 fixedRightNumber: 1, // 冻结右列个数 diff --git a/ruoyi-admin/src/main/resources/templates/purchase/purchaseOrder/purchaseOrder.html b/ruoyi-admin/src/main/resources/templates/purchase/purchaseOrder/purchaseOrder.html index 6dc625d1..8e3c8484 100644 --- a/ruoyi-admin/src/main/resources/templates/purchase/purchaseOrder/purchaseOrder.html +++ b/ruoyi-admin/src/main/resources/templates/purchase/purchaseOrder/purchaseOrder.html @@ -169,8 +169,13 @@ exportUrl: prefix + "/export", clickToSelect: true, modalName: "采购订单", + detailView: true, fixedColumns: true, // 启用冻结列 fixedRightNumber: 1, // 冻结右列个数 + onExpandRow:function(index, row, $detail){ + $detail.html('
'); + initChildTable(row, index, $detail); + }, columns: [ {checkbox: true}, {title: '采购订单id',field: 'purchaseOrderId', visible: false}, @@ -187,22 +192,20 @@ $.table.selectDictLabel(paymentStatusDatas, value); }}, {title:'采购单号',field: 'purchaseOrderCode'}, - { title: '供应商ID',field: 'supplierCode'}, - {title: '供应商名称',field: 'supplierName'}, {title: '联系人',field: 'customerContact',visible: false}, {title: '联系电话',field: 'contactNumber',visible: false}, {title:'供应商数量',field: 'supplierNum'}, {title:'物料合计',field: 'materialAmount'}, {title:'数量合计',field: 'materialSum'}, {title:'不含税总价(RMB)',field: 'noRmbSum'}, - {title:'含税总价',field: 'rmbSum'}, - {field: 'firstAddTime', title: '录入时间', + {title:'含税总价(RMB)',field: 'rmbSum'}, + {field: 'createTime', title: '录入时间', formatter: function (value, row, index) { if (value == null) { return " ";} else { var vArr = value.split(',');return vArr[0];} } }, - {field: 'updateInfoTime',title: '上次更新时间', + {field: 'updateTime',title: '上次更新时间', formatter: function (value, row, index) { if (value == null) {return ""; } else { var vArr = value.split(',');return vArr[0];} @@ -219,25 +222,35 @@ }; $.table.init(options); }); + initChildTable = function(index, row, $detail) { + $("#"+"purchase_order_"+row.id).bootstrapTable({ + url: ctx + "purchase/purchaseOrderChild/list", + method: 'post', + sidePagination: "server", + contentType: "application/x-www-form-urlencoded", + queryParams : { + purchaseOrderCode: row.purchaseOrderCode + }, + columns: [ + {title: '采购单子表编号',field: 'purchaseOrderChildId',visible: false}, + {title: '关联采购订单号',field: 'purchaseOrderCode',visible: false}, + {title: '供应商ID',field: 'supplierCode',}, + {title: '供应商名称',field: 'supplierName',}, + {title: '物料合计',field: 'materialAmount',}, + {title: '数量合计',field: 'materialSum',}, + {title: '不含税总价(RMB)',field: 'materialNoRmbSum',}, + {title: '含税总价(RMB)',field: 'materialRmbSum',}, + {title:'收货状态',field: 'eceiptStatus',formatter: function (value, row, index) { + $.table.selectDictLabel(eceiptStatusDatas, value);} + }, + {title:'打款状态',field: 'paymentStatus',formatter: function (value, row, index) { + $.table.selectDictLabel(paymentStatusDatas, value);} + }, + {title: '交货时间',field: 'deliveryTime',visible: false}, + ] + }); + }; - /*供应商列表*/ - $.ajax({ - url: ctx + 'system/supplier/list', - type: 'post', - success: function (res) { - console.log(res) - if (res.rows.length > 0) { - var suppliertData = res.rows; - //alert(JSON.stringify(data)); - for (let i in suppliertData) { - // console.log(finishProductData[i].finishProductCode) - $("#formId select[name='supplierCode']").append(""); - } - } else { - $.modal.msgError(res.msg); - } - } - }) //导出 diff --git a/ruoyi-admin/src/main/resources/templates/purchase/purchasePlan/addPurchaseOrder.html b/ruoyi-admin/src/main/resources/templates/purchase/purchasePlan/addPurchaseOrder.html index eb28beeb..635433bc 100644 --- a/ruoyi-admin/src/main/resources/templates/purchase/purchasePlan/addPurchaseOrder.html +++ b/ruoyi-admin/src/main/resources/templates/purchase/purchasePlan/addPurchaseOrder.html @@ -5,7 +5,7 @@
-
+
@@ -25,30 +25,57 @@
- +
- +
- +
- +
+
+

订单合计:

+
+ +
+ +
+
+
+ +
+ +
+
+
+ +
+ +
+
+
+ +
+ +
+
+
@@ -59,10 +86,10 @@ var sysUnitClassDatas = [[${@dict.getType('sys_unit_class')}]]; var processMethodDatas = [[${@dict.getType('processMethod')}]]; var loginName = [[${@permission.getPrincipalProperty('loginName')}]]; - $("#form-plan-add").validate({focusCleanup: true}); + $("#form-plan-purchaseOrder-add").validate({focusCleanup: true}); var purchasePlanChildList = [[${purchasePlanChildList}]]; var purchasePlanList = [[${purchasePlanList}]]; - var formId = $("#form-plan-add").attr("id"); + var formId = "form-plan-purchaseOrder-add"; //根据物料物料数量添加物料分类表,自动生成类似的表单对象 //初始根据采购计划单,涉及到物料做分类表 //根据采购计划单,获取物料信息,自动生成物料的供应商分类表 @@ -134,6 +161,7 @@ // 将整个物料信息容器添加到页面 $('#material').append($tableWrapper); var materialObj = { + purchasePlanCode: material.purchasePlanCode, materialCode: material.materialCode, photoUrl: material.photoUrl, materialName: material.materialName, @@ -148,136 +176,177 @@ materialList.push(materialObj); tables(materialTable, materialData); }); + // 给实际采购数的输入框绑定事件处理器 + $('.supplierMaterialNum').off('keyup').on('keyup', function() { + var tableId = $(this).closest('.table-materialCode').attr('id'); + recalculateTotals(tableId); // 重新计算当前物料的合计 + calculateGlobalTotals(); // 然后重新计算整个订单的合计 + }); + }); + // 新增函数:重新计算某物料的采购数量合计、不含税采购总价和含税采购总价 + function recalculateTotals(tableId) { + var actualPurchaseTotal = 0; + var materialNoRmbTotal = 0; + var materialRmbTotal = 0; - function tableSetup(element, tableId) { - var $totalSection = $( - '
' + - '
' + - '
' + - '' + - '
' + - '' + - '
' + - '
' + - '
' + - '' + - '
' + - '' + - '
' + - '
' + - '
' + - '' + - '
' + - '' + - '
' + - '
' + - '
'+ - '
'); - element.append($totalSection); - } + $('#' + 'supplier-' + tableId).find('.supplier-card').each(function(supplierIndex, supplierCard) { + var purchaseNum = parseFloat($(supplierCard).find('.supplierMaterialNum').val()) || 0; + var noRmbPrice = parseFloat($(supplierCard).find('.supplierMaterialNoRmb').text().trim()); + var rmbPrice = parseFloat($(supplierCard).find('.supplierMaterialRmb').text().trim()); - // 表格初始化函数保持不变 - function tables(tableId, data) { - $('#' + tableId).bootstrapTable({ - showExport: false, - showFooter: false, - showSearch: false, - showRefresh: false, - showColumns: false, - showToggle: false, - data: data, - height: 25, - columns: [ - {checkbox: false}, - {title: '料号', field: 'materialCode'}, - { - title: '图片', field: 'photoUrl', formatter: function (value, row, index) { - return $.table.imageView(value); - } - }, - {title: '物料名称', field: 'materialName'}, - { - title: '物料类型', field: 'materialType', align: 'center', formatter: function (value, row, index) { - return $.table.selectCategoryLabel(materialTypeDatas, value); - } - }, - {title: '物料描述', field: 'describe'}, - {title: '品牌', field: 'brand'}, - { - title: '加工类型', field: 'processMethod', align: 'center', formatter: function (value, row, index) { - return $.table.selectDictLabel(processMethodDatas, value); - } - }, - { - title: '单位', field: 'unit', align: 'center', formatter: function (value, row, index) { - return $.table.selectDictLabel(sysUnitClassDatas, value); - } - }, - {title: '计划采购数', field: 'planPurchaseNum'}, - ], - }); - } + actualPurchaseTotal += purchaseNum; + materialNoRmbTotal += purchaseNum * noRmbPrice; + materialRmbTotal += purchaseNum * rmbPrice; + }); + // 更新合计显示 + $('#materialNoRmbSum_' + tableId).val(materialNoRmbTotal.toFixed(2)); // 格式化为两位小数 + $('#materialRmbSum_' + tableId).val(materialRmbTotal.toFixed(2)); + } + function calculateGlobalTotals() { + var totalMaterialSum = 0; + var totalPurchaseSum = 0; + var totalNoRmbSum = 0; + var totalRmbSum = 0; - // 提交表单的处理函数 - }); + tableIdList.forEach(function(tableId) { + var materialNoRmbTotal = parseFloat($('#materialNoRmbSum_' + tableId).val()) || 0; + var materialRmbTotal = parseFloat($('#materialRmbSum_' + tableId).val()) || 0; + + totalMaterialSum += materialNoRmbTotal; // 假设物料合计就是不含税采购总价 + totalPurchaseSum += materialNoRmbTotal; // 假设采购合计也是不含税采购总价(如果逻辑不同,请相应调整) + totalNoRmbSum += materialNoRmbTotal; + totalRmbSum += materialRmbTotal; + }); + // 设置合计值,确保处理NaN + $('#purchaseMaterialSum').val(isNaN(totalMaterialSum) ? '' : totalMaterialSum.toFixed(2)); + $('#purchaseSum').val(isNaN(totalPurchaseSum) ? '' : totalPurchaseSum.toFixed(2)); + $('#purchaseNoRmbSum').val(isNaN(totalNoRmbSum) ? '' : totalNoRmbSum.toFixed(2)); + $('#purchaseRmbSum').val(isNaN(totalRmbSum) ? '' : totalRmbSum.toFixed(2)); + } + function tableSetup(element, tableId) { + var $totalSection = $( + '
' + + '
' + + '
' + + '' + + '
' + + '' + + '
' + + '
' + + '
' + + '' + + '
' + + '' + + '
' + + '
' + + '
' + + '' + + '
' + + '' + + '
' + + '
' + + '
'+ + '
'); + element.append($totalSection); + } + function tables(tableId, data) { + $('#' + tableId).bootstrapTable({ + showExport: false, + showFooter: false, + showSearch: false, + showRefresh: false, + showColumns: false, + showToggle: false, + data: data, + height: 25, + columns: [ + {checkbox: false}, + {title: '料号', field: 'materialCode'}, + { + title: '图片', field: 'photoUrl', formatter: function (value, row, index) { + return $.table.imageView(value); + } + }, + {title: '物料名称', field: 'materialName'}, + { + title: '物料类型', field: 'materialType', align: 'center', formatter: function (value, row, index) { + return $.table.selectCategoryLabel(materialTypeDatas, value); + } + }, + {title: '物料描述', field: 'describe'}, + {title: '品牌', field: 'brand'}, + { + title: '加工类型', field: 'processMethod', align: 'center', formatter: function (value, row, index) { + return $.table.selectDictLabel(processMethodDatas, value); + } + }, + { + title: '单位', field: 'unit', align: 'center', formatter: function (value, row, index) { + return $.table.selectDictLabel(sysUnitClassDatas, value); + } + }, + {title: '计划采购数', field: 'planPurchaseNum'}, + ], + }); + } function submitHandler() { if ($.validate.form()) { var purchaseOrder = { - purchaseOrderCode: "", // 这里可能需要生成一个临时的或预设的订单号,实际生产环境应由后端生成 supplierNum: 0, materialNum: 0, materialNoRmbSum: 0, materialRmbSum: 0, purchaseOrderChildList: [] }; + // 遍历每个物料容器 $('.table-materialCode').each(function(index, tableElement) { - console.log(tableElement); - var tableId = tableIdList[index]; // 从table ID中提取tableId - var materialTable = "bootstrap-table_" + tableId; - var data = $('#' + materialTable).bootstrapTable('getData'); - var materialData = { - materialCode:'' , // 假设'materialCode'是你要获取的字段名}) , // 确保能正确获取物料编码 - materialNum:10, - materialNoRmbSum: 0, - materialRmbSum: 0, - purchaseQuoteChildList: [] - }; - var materialActualNum = $('#' + 'actualPurchaseNum_' + tableId).val(); - var materialNoRmbTotal = $('#' + 'materialNoRmbSum_' + tableId).val(); - var materialRmbTotal = $('#' + 'materialRmbSum_' + tableId).val(); - materialData.materialNum = parseInt(materialActualNum); - materialData.materialNoRmbSum = parseFloat(materialNoRmbTotal); - materialData.materialRmbSum = parseFloat(materialRmbTotal); - // 遍历该物料下的供应商信息 + var tableId = tableIdList[index]; + let materialObj = materialList[index]; + if (typeof materialObj === 'undefined') return; $('#' + 'material-' + tableId).find('.supplier-card').each(function(supplierIndex, supplierCard) { - var supplierQuote = { - supplierCode: $(supplierCard).find('.supplierCode').text().trim(), - supplierName: $(supplierCard).find('.supplierName').text().trim(), - materialNoRmb: parseFloat($(supplierCard).find('.supplierMaterialNoRmb').text().trim()), - materialRmb: parseFloat($(supplierCard).find('.supplierMaterialRmb').text().trim()), - materialNum: $(supplierCard).find('.supplierMaterialNum').val().trim(), - deliveryTime: $(supplierCard).find('.supplierDeliveryTime').val() - }; - materialData.purchaseQuoteChildList.push(supplierQuote); - purchaseOrder.supplierNum += 1; // 累加供应商数量 + var materialData = { + purchasePlanCode: materialObj.purchasePlanCode, + materialCode: materialObj.materialCode, + materialName: materialObj.materialName, + materialType: materialObj.materialType, + materialBrand:materialObj.brand, + describe: materialObj.describe, + processMethod:materialObj.processMethod, + unit:materialObj.unit, + supplierCode: $(supplierCard).find('.supplierCode').text().trim(), + supplierName: $(supplierCard).find('.supplierName').text().trim(), + materialNoRmb: parseFloat($(supplierCard).find('.supplierMaterialNoRmb').text().trim()), + materialRmb: parseFloat($(supplierCard).find('.supplierMaterialRmb').text().trim()), + materialNum: parseInt($(supplierCard).find('.supplierMaterialNum').val(), 10) || 0, + deliveryTime: $(supplierCard).find('.supplierDeliveryTime').val() + }; + purchaseOrder.purchaseQuoteChildList.push(materialData); }); - purchaseOrder.materialNoRmbSum += parseFloat(materialNoRmbTotal) ; - purchaseOrder.materialRmbSum += parseFloat(materialRmbTotal); // 累加含税总价 - purchaseOrder.purchaseOrderChildList.push(materialData); }); + // 计算整个订单的合计值,这部分应在遍历完所有物料后执行 + let totalMaterialNum = purchaseOrder.materialNum; + let totalNoRmbSum = purchaseOrder.materialNoRmbSum; + let totalRmbSum = purchaseOrder.materialRmbSum; + let totalPurchaseSum = totalNoRmbSum; // 或者根据实际业务逻辑调整 + + // 将合计值附加到purchaseOrder对象 + purchaseOrder.totalMaterialSum = totalMaterialNum; + purchaseOrder.totalPurchaseSum = totalPurchaseSum; + purchaseOrder.totalNoRmbSum = totalNoRmbSum.toFixed(2); + purchaseOrder.totalRmbSum = totalRmbSum.toFixed(2); + // 发送数据到后端API $.ajax({ type: "POST", - url: prefix + "/add", // 这里的prefix应该是之前定义的context路径 - data: JSON.stringify(purchaseOrder), // 将构造好的对象转换为JSON字符串 + url: prefix + "/add", + data: JSON.stringify(purchaseOrder), contentType: "application/json; charset=utf-8", dataType: "json", success: function (response) { if (response.code === 200) { alert("采购订单添加成功!"); - // 可以在这里添加更多成功的处理逻辑,如页面跳转等 } else { alert("采购订单添加失败:" + response.msg); } @@ -287,6 +356,8 @@ alert("提交过程中发生错误,请重试。"); } }); + + // 如果需要在页面加载时初始化合计或重新绑定事件处理器,这部分应放在更合适的位置,不在此函数内 } } diff --git a/ruoyi-admin/src/main/resources/templates/purchase/purchasePlan/purchasePlan.html b/ruoyi-admin/src/main/resources/templates/purchase/purchasePlan/purchasePlan.html index 2c2727a8..192af288 100644 --- a/ruoyi-admin/src/main/resources/templates/purchase/purchasePlan/purchasePlan.html +++ b/ruoyi-admin/src/main/resources/templates/purchase/purchasePlan/purchasePlan.html @@ -146,7 +146,7 @@ }, {field: 'describe',title: '描述',}, {field: 'brand',title: '品牌',}, - {field: 'processMethod',title: '半成品类型', + {field: 'processMethod',title: '加工类型', formatter: function(value, row, index) {return $.table.selectDictLabel(processMethodDatas, value);} }, {field: 'unit',title: '单位', diff --git a/ruoyi-admin/src/main/resources/templates/system/customerQuote/taskYwgzVerify.html b/ruoyi-admin/src/main/resources/templates/system/customerQuote/taskYwzgVerify.html similarity index 98% rename from ruoyi-admin/src/main/resources/templates/system/customerQuote/taskYwgzVerify.html rename to ruoyi-admin/src/main/resources/templates/system/customerQuote/taskYwzgVerify.html index 01829814..a3f3401c 100644 --- a/ruoyi-admin/src/main/resources/templates/system/customerQuote/taskYwgzVerify.html +++ b/ruoyi-admin/src/main/resources/templates/system/customerQuote/taskYwzgVerify.html @@ -6,7 +6,7 @@
- + @@ -179,7 +179,7 @@