Browse Source

Merge remote-tracking branch 'origin/dev' into dev

dev
王晓迪 3 months ago
parent
commit
709c1b3fc1
  1. 45
      ruoyi-admin/src/main/java/com/ruoyi/purchase/controller/PurchaseOrderController.java
  2. 8
      ruoyi-admin/src/main/java/com/ruoyi/purchase/controller/PurchasePlanController.java
  3. 4
      ruoyi-admin/src/main/java/com/ruoyi/purchase/mapper/PurchasePlanMapper.java
  4. 31
      ruoyi-admin/src/main/java/com/ruoyi/purchase/service/impl/PurchaseOrderServiceImpl.java
  5. 2
      ruoyi-admin/src/main/java/com/ruoyi/purchase/service/impl/PurchasePlanServiceImpl.java
  6. 2
      ruoyi-admin/src/main/resources/mapper/purchase/PurchaseOrderMapper.xml
  7. 7
      ruoyi-admin/src/main/resources/mapper/purchase/PurchasePlanMapper.xml
  8. 33
      ruoyi-admin/src/main/resources/templates/erp/material/select.html
  9. 856
      ruoyi-admin/src/main/resources/templates/purchase/purchaseOrder/detail.html
  10. 1104
      ruoyi-admin/src/main/resources/templates/purchase/purchaseOrder/edit.html
  11. 11
      ruoyi-admin/src/main/resources/templates/purchase/purchaseOrder/purchaseOrder.html
  12. 614
      ruoyi-admin/src/main/resources/templates/purchase/purchaseOrder/taskCgjlVerify.html
  13. 320
      ruoyi-admin/src/main/resources/templates/purchase/purchasePlan/addPurchaseOrder.html
  14. 2
      ruoyi-admin/src/main/resources/templates/purchase/purchasePlan/purchasePlan.html

45
ruoyi-admin/src/main/java/com/ruoyi/purchase/controller/PurchaseOrderController.java

@ -178,10 +178,8 @@ public class PurchaseOrderController extends BaseController
purchaseOrder.setAuditStatus("0");
purchaseOrder.setUseStatus("0");
purchaseOrder.setDelFlag("0");
purchaseOrderService.submitApply(purchaseOrder);
// purchaseOrderService.insertPurchaseOrder(purchaseOrder);
// purchaseOrderService.addPurchaseOrderPayable(purchaseOrder);
// 数据校验,确保前端传入数据格式正确
// 执行主表插入操作
@ -205,17 +203,47 @@ public class PurchaseOrderController extends BaseController
supplierCodes.add(purchaseOrderChild.getSupplierCode());
purchasePlanCodes.add(purchaseOrderChild.getPurchasePlanCode());
}
purchaseOrder.setPurchaseOrderChildList(purchaseOrderChildList);
mmap.put("supplierCodes", supplierCodes);
mmap.put("purchasePlanCodes", purchasePlanCodes);
mmap.put("purchaseOrder", purchaseOrder);
return prefix + "/edit";
}
@GetMapping("/detail/{purchaseOrderChildId}")
public String detail(@PathVariable("purchaseOrderChildId") Long purchaseOrderChildId, ModelMap mmap)
@GetMapping("/editPurchaserOrder/{purchaseOrderId}")
@ResponseBody
public AjaxResult editPurchaser(@PathVariable("purchaseOrderId") Long purchaseOrderId, ModelMap mmap)
{
PurchaseOrder purchaseOrder = purchaseOrderService.selectPurchaseOrderById(purchaseOrderId);
//获取子表信息
List<PurchaseOrderChild> purchaseOrderChildList = purchaseOrderChildService.selectPurchaseOrderChildByOrderCode(purchaseOrder.getPurchaseOrderCode());
//Set<String>子表供应商的信息 供应商编号-供应商名称
//Set<String>子表采购计划单信息
Set<String> supplierCodes = new HashSet<>();
Set<String> purchasePlanCodes = new HashSet<>();
for(PurchaseOrderChild purchaseOrderChild : purchaseOrderChildList){
//获取区分的供应商物料信息
if(!purchasePlanCodes.contains(purchaseOrderChild.getPurchasePlanCode())){
purchasePlanCodes.add(purchaseOrderChild.getPurchasePlanCode());
}
//获取区分的采购计划单信息
if(!supplierCodes.contains(purchaseOrderChild.getSupplierCode())){
supplierCodes.add(purchaseOrderChild.getSupplierCode());
}
supplierCodes.add(purchaseOrderChild.getSupplierCode());
}
mmap.put("supplierCodes", supplierCodes);
mmap.put("purchasePlanCodes", purchasePlanCodes);
mmap.put("purchaseOrder", purchaseOrder);
mmap.put("purchasePlanChildList",purchaseOrderChildList);
return AjaxResult.success(mmap);
}
@GetMapping("/detail/{purchaseOrderId}")
public String detail(@PathVariable("purchaseOrderId") Long purchaseOrderChildId, ModelMap mmap)
{
PurchaseOrderChild purchaseOrderChild = purchaseOrderChildService.selectPurchaseOrderChildById(purchaseOrderChildId);
mmap.put("purchaseOrderChild", purchaseOrderChild);
PurchaseOrder purchaseOrder = purchaseOrderService.selectPurchaseOrderById(purchaseOrderChildId);
mmap.put("purchaseOrder", purchaseOrder);
return prefix + "/detail";
}
@ -315,9 +343,8 @@ public class PurchaseOrderController extends BaseController
if("submit".equals(instanceType)){
// 使用状态-是
purchaseOrderVo.setUseStatus("1");
// if(purchaseOrderVo.getPurchaseOrderChildList().addAll(purchaseOrderVo.getPurchaseOrderChildList())){
// purchaseOrderService.addPurchaseOrderPayable(purchaseOrderVo);
// }
purchaseOrderService.addPurchaseOrderPayable(purchaseOrderVo);
}
// 作废
else if("cancel".equals(instanceType)){

8
ruoyi-admin/src/main/java/com/ruoyi/purchase/controller/PurchasePlanController.java

@ -116,10 +116,10 @@ public class PurchasePlanController extends BaseController
@GetMapping("/addPurchaseOrder/{purchasePlanCodes}")
public String addPurchaseOrder(@PathVariable("purchasePlanCodes") String purchasePlanCodes,ModelMap mmap){
//purchasePlanCodes去除重复数据,purchasePlanCodeArray作为数组类型去除
Set<String> uniquePurchasePlanCode = Arrays.stream(purchasePlanCodes.split(",")).collect(Collectors.toSet());
// 直接使用String的split方法分割字符串,然后转为Stream去重,最后再拼接回字符串
String[] purchasePlanCodeArray = purchasePlanCodes.split(",");
String uniquePurchasePlanCodes = String.join(",", Arrays.stream(purchasePlanCodeArray).distinct().toArray(String[]::new));
String uniquePurchasePlanCodes = String.join(",", uniquePurchasePlanCode);
//去除重复的计划单号
//查询相关采购计划数据
List<PurchasePlan> purchasePlanList = purchasePlanService.selectPurchasePlanByPlanCode(uniquePurchasePlanCodes);
//根据采购计划编号查询对应的采购报价数据
@ -134,7 +134,7 @@ public class PurchasePlanController extends BaseController
//用stream流处理相同供应商\物料\
//将供应商信息解析成List<PurchaseSupplier>
mmap.put("purchasePlanList", purchasePlanList);
mmap.put("purchasePlanCodes", purchasePlanCodeArray);
mmap.put("purchasePlanCodes", uniquePurchasePlanCodes);
mmap.put("purchasePlanChildList", purchasePlanChildList);
return prefix + "/addPurchaseOrder";
}

4
ruoyi-admin/src/main/java/com/ruoyi/purchase/mapper/PurchasePlanMapper.java

@ -76,5 +76,7 @@ public interface PurchasePlanMapper
*/
public int restorePurchasePlanById(Long purchasePlanId);
public List<PurchasePlan> selectPurchasePlanByPlanCode(String[] planCode);
public PurchasePlan selectPurchasePlanByPlanCode(String purchasePlanCode);
public List<PurchasePlan> selectPurchasePlanByPlanCodes(String[] planCode);
}

31
ruoyi-admin/src/main/java/com/ruoyi/purchase/service/impl/PurchaseOrderServiceImpl.java

@ -222,9 +222,6 @@ public class PurchaseOrderServiceImpl implements IPurchaseOrderService
@Transactional(rollbackFor = Exception.class)
public int insertPurchaseOrder(PurchaseOrder purchaseOrder)
{
//根据上传的物料信息做采购订单子项
purchaseOrder.setCreateTime(DateUtils.getNowDate());
purchaseOrder.setCreateBy(ShiroUtils.getLoginName());
// 生成采购订单编号
purchaseOrder.setPurchaseOrderCode(redisCache.generateBillNo("CG"));
// 初始化累加变量
@ -234,18 +231,22 @@ public class PurchaseOrderServiceImpl implements IPurchaseOrderService
BigDecimal materialRmbSum = BigDecimal.ZERO;
Long materialNum = 0L;
int supplierNum = 0;
//根据上传的物料信息做采购订单子项
if (!CollectionUtils.isEmpty(purchaseOrder.getPurchaseOrderChildList())) {
supplierNum = purchaseOrder.getPurchaseOrderChildList().size();
}
if (purchaseOrder.getPurchaseOrderChildList() != null) {
for (PurchaseOrderChild child : purchaseOrder.getPurchaseOrderChildList()) {
List<PurchaseOrderChild> purchaseOrderChildList = purchaseOrder.getPurchaseOrderChildList();
//订单子表去除实际物料数量位null或者0的物料信息
purchaseOrderChildList = purchaseOrderChildList.stream().filter(child -> child.getMaterialNoRmb() != null && child.getMaterialNoRmb().compareTo(BigDecimal.ZERO) != 0).collect(Collectors.toList());
for (PurchaseOrderChild child : purchaseOrderChildList) {
if (child.getCorrelationCode().contains(",")) {
String[] correlationCodes = child.getCorrelationCode().split(",");
String[] planCodes = child.getPurchasePlanCode().split(",");
String[] purchaseQuoteCodes = child.getPurchaseQuoteCode().split(",");
for (int i = 0; i < planCodes.length - 1; i++) {
String planCode = planCodes[i];
String correlationCode = correlationCodes[i];
PurchasePlan purchasePlan = purchasePlanService.selectPurchasePlanByPlanCode(planCode);
if (planCode != null) {
PurchaseOrderChild material = new PurchaseOrderChild();
child.setPurchaseOrderCode(purchaseOrder.getPurchaseOrderCode());
@ -254,7 +255,7 @@ public class PurchaseOrderServiceImpl implements IPurchaseOrderService
// 获取物料供应商含税采购价格
BigDecimal suplierMaterialRmb = child.getMaterialRealRmb();
// 获取物料数量
Long suplierMaterialNum = child.getMaterialNum();
Long suplierMaterialNum = child.getMaterialRealNum();
if(suplierMaterialNoRmb == null){suplierMaterialNoRmb = BigDecimal.ZERO;}
if(suplierMaterialRmb == null){suplierMaterialRmb = BigDecimal.ZERO;}
if(suplierMaterialNum == null){suplierMaterialNum = 0L;}
@ -270,6 +271,7 @@ public class PurchaseOrderServiceImpl implements IPurchaseOrderService
materialRmbSum = materialRmbSum.add(suplierMaterialRmbSumLocal);
// 设置采购报价单编号和供应商信息到QuoteChild
material.setPurchaseOrderCode(purchaseOrder.getPurchaseOrderCode());
material.setPurchasePlanCorrelationCode(purchasePlan.getCorrelationCode());
material.setSupplierCode(child.getSupplierCode());
material.setMaterialUnit(child.getMaterialUnit());
material.setWarehouseDept(child.getWarehouseDept());
@ -311,6 +313,7 @@ public class PurchaseOrderServiceImpl implements IPurchaseOrderService
}
else if ((!child.getCorrelationCode().contains(","))
&& child.getPurchasePlanCode() != null) {
PurchasePlan purchasePlan = purchasePlanService.selectPurchasePlanByPlanCode(child.getPurchasePlanCode());
PurchaseOrderChild material = new PurchaseOrderChild();
child.setPurchaseOrderCode(purchaseOrder.getPurchaseOrderCode());
//获取物料供应商不含税采购价格
@ -318,7 +321,7 @@ public class PurchaseOrderServiceImpl implements IPurchaseOrderService
// 获取物料供应商含税采购价格
BigDecimal suplierMaterialRmb = child.getMaterialRealRmb();
// 获取物料数量
Long suplierMaterialNum = child.getMaterialNum();
Long suplierMaterialNum = child.getMaterialRealNum();
if(suplierMaterialNoRmb == null){suplierMaterialNoRmb = BigDecimal.ZERO;}
if(suplierMaterialRmb == null){suplierMaterialRmb = BigDecimal.ZERO;}
if(suplierMaterialNum == null){suplierMaterialNum = 0L;}
@ -334,6 +337,8 @@ public class PurchaseOrderServiceImpl implements IPurchaseOrderService
materialRmbSum = materialRmbSum.add(suplierMaterialRmbSumLocal);
// 设置采购报价单编号和供应商信息到QuoteChild
material.setPurchaseOrderCode(purchaseOrder.getPurchaseOrderCode());
material.setCorrelationCode(purchasePlan.getCorrelationCode());
material.setPurchasePlanCorrelationCode(purchasePlan.getCorrelationCode());
material.setSupplierCode(child.getSupplierCode());
material.setMaterialUnit(child.getMaterialUnit());
material.setWarehouseDept(child.getWarehouseDept());
@ -380,7 +385,7 @@ public class PurchaseOrderServiceImpl implements IPurchaseOrderService
// purchaseOrder.setNoRmbSum(purchaseOrder.getNoRmbSum());
// purchaseOrder.setRmbSum(purchaseOrder.getRmbSum());
// 设置主表的供应商数量
purchaseOrder.setSupplierNum(purchaseOrder.getSupplierNum());
purchaseOrder.setSupplierNum(supplierNum);
purchaseOrder.setNoRmbSum(materialNoRmbSum);
purchaseOrder.setRmbSum(materialRmbSum);
purchaseOrder.setDelFlag("0");
@ -470,7 +475,7 @@ public class PurchaseOrderServiceImpl implements IPurchaseOrderService
List<WarehouseStorageOrder> warehouseStorageOrderList = warehouseStorageOrderMapper.selectWarehouseStorageOrderList(warehouseStorageOrder1);
List<WarehouseStorageOrderDetail> list = warehouseStorageOrder.getWarehouseStorageOrderDetailList();
//子表中通知到货数位过滤掉物料数位空
list = list.stream().filter(e -> (e.getNotifyArriveNum() != null)).collect(Collectors.toList());
list = list.stream().filter(e -> (e.getNotifyArriveNum() != null && e.getNotifyArriveNum() != 0)).collect(Collectors.toList());
int result = 0;
if(!CollectionUtils.isEmpty(list)) {
//根据物料入库部门划分入库单,入库单类型:0 仓库,1 采购,生成入库单号
@ -547,7 +552,7 @@ public class PurchaseOrderServiceImpl implements IPurchaseOrderService
public Integer addPurchaseOrderPayable(PurchaseOrder purchaseOrder){
//根据供应商划分物料信息,合计物料不含税单价 ,含税单价,含税总价,不含税总价,实际采购数量
// 获取采购订单的子项列表
List<PurchaseOrderChild> children = purchaseOrder.getPurchaseOrderChildList();
List<PurchaseOrderChild> children = purchaseOrderChildService.selectPurchaseOrderChildByOrderCode(purchaseOrder.getPurchaseOrderCode());
// 分组供应商的子订单,分组统计各供应商应付单供应商
List<PurchaseOrderChild> supplierGroup = (List<PurchaseOrderChild>) children.stream()
// 分组依据为supplierCode
@ -840,14 +845,10 @@ public class PurchaseOrderServiceImpl implements IPurchaseOrderService
variables.put("authority",1);
}else if(roleKeys.contains("cgjlRole")){
variables.put("authority",2);
}else if(roleKeys.contains("cgzgRole")){
}else if(roleKeys.contains("cgzgRole")|| roleKeys.contains("admin")){
variables.put("authority",3);
}else if(roleKeys.contains("fzjlRole")){
variables.put("authority",4);
}
}
}

2
ruoyi-admin/src/main/java/com/ruoyi/purchase/service/impl/PurchasePlanServiceImpl.java

@ -167,7 +167,7 @@ public class PurchasePlanServiceImpl implements IPurchasePlanService
@Override
public List<PurchasePlan> selectPurchasePlanByPlanCode(String purchasePlanCodes) {
return purchasePlanMapper.selectPurchasePlanByPlanCode(Convert.toStrArray(purchasePlanCodes));
return purchasePlanMapper.selectPurchasePlanByPlanCodes(Convert.toStrArray(purchasePlanCodes));
}

2
ruoyi-admin/src/main/resources/mapper/purchase/PurchaseOrderMapper.xml

@ -180,8 +180,8 @@ PUBLIC "-//mybatis.org//DTD Mapper 3.0//EN"
<if test="customerFax != null">#{customerFax},</if>
<if test="deliveryAddress != null">#{deliveryAddress},</if>
<if test="paymentTerms != null">#{paymentTerms},</if>
<if test="deliveryMethod != null">#{deliveryMethod},</if>
<if test="deliveryConditions != null">#{deliveryConditions},</if>
<if test="deliveryMethod != null">#{deliveryMethod},</if>
<if test="purchaseName != null">#{purchaseName},</if>
<if test="billingDate != null">#{billingDate},</if>
<if test="taxRate != null">#{taxRate},</if>

7
ruoyi-admin/src/main/resources/mapper/purchase/PurchasePlanMapper.xml

@ -47,14 +47,17 @@ PUBLIC "-//mybatis.org//DTD Mapper 3.0//EN"
<include refid="selectPurchasePlanVo"/>
where purchase_plan_id = #{purchasePlanId}
</select>
<select id="selectPurchasePlanByPlanCode" parameterType="Long" resultMap="PurchasePlanResult">
<select id="selectPurchasePlanByPlanCodes" parameterType="String" resultMap="PurchasePlanResult">
<include refid="selectPurchasePlanVo"/>
where purchase_plan_code in
<foreach item="purchasePlanCode" collection="array" open="(" separator="," close=")">
#{purchasePlanCode}
</foreach>
</select>
<select id="selectPurchasePlanByPlanCode" parameterType="String" resultMap="PurchasePlanResult">
<include refid="selectPurchasePlanVo"/>
where purchase_plan_code = #{purchasePlanCode}
</select>
<insert id="insertPurchasePlan" parameterType="PurchasePlan" useGeneratedKeys="true" keyProperty="purchasePlanId">
insert into purchase_plan
<trim prefix="(" suffix=")" suffixOverrides=",">

33
ruoyi-admin/src/main/resources/templates/erp/material/select.html

@ -54,6 +54,7 @@
singleSelect: false, // 单选
url: prefix + "/selectList",
modalName: "物料信息",
rememberSelected: true,
columns: [
{checkbox: true},
{title: '主键ID',field: 'id',visible: false},
@ -76,10 +77,40 @@
return $.table.selectDictLabel(processMethodDatas, value);
}
}
]
],
onPageChange: function (number, size) {
// 当改变页码时,触发此函数
saveSelections();
}
};
$.table.init(options);
$('#bootstrap-select-table').on('load-success.bootstrap.table', function () {
var savedSelections = JSON.parse(localStorage.getItem('selectedRows')) || [];
savedSelections.forEach(function (row) {
var rowIndex = $('#bootstrap-select-table').bootstrapTable('getRowIndex', row.id);
if (rowIndex !== undefined) {
$('#bootstrap-select-table').bootstrapTable('selectRow', rowIndex);
}
});
});
});
function saveSelections() {
var selections = $('#bootstrap-select-table').bootstrapTable('getSelections');
var selectedIds = [];
for (var i = 0; i < selections.length; i++) {
selectedIds.push(selections[i].id); // 假设每行有一个唯一的 id 字段
}
restoreSelections(selectedIds);
}
function restoreSelections(selectedIds) {
$('#bootstrap-select-table').on('load-success.bootstrap.table', function () {
$('#bootstrap-select-table').bootstrapTable('uncheckAll'); // 首先取消所有选择
$.each(selectedIds, function (index, id) {
$('#bootstrap-select-table').bootstrapTable('selectRow', id);
});
});
}
</script>
</body>
</html>

856
ruoyi-admin/src/main/resources/templates/purchase/purchaseOrder/detail.html

@ -1,506 +1,424 @@
<!DOCTYPE html>
<html lang="zh" xmlns:th="http://www.thymeleaf.org" >
<head>
<th:block th:include="include :: header('采购订单详情')" />
<th:block th:include="include :: header('编辑采购订单')" />
<th:block th:include="include :: select2-css" />
<th:block th:include="include :: datetimepicker-css" />
<link th:href="@{/ajax/libs/select2/select2.css}" rel="stylesheet">
<link th:href="@{/ajax/libs/select2/select2-bootstrap.css}" rel="stylesheet">
<th:block th:include="include :: bootstrap-editable-css"/>
<style>
.other-container {
width: 90%;
height: 200px;
margin: auto;
}
.other {
margin-top: 20px;
}
h4 {
display: inline-block;
margin-right: 20px;
}
.modal-body{
height: 550px;
}
iframe{
width: 100%;
height: 500px;
frameborder: 0;
border: 0;
display: inline-block;
}
</style>
<th:block th:include="include :: bootstrap-editable-css" />
</head>
<body class="white-bg">
<div class="wrapper wrapper-content animated fadeInRight ibox-content">
<form class="form-horizontal m" id="form-purchaseOrder-detail" th:object="${purchaseOrder}">
<input name="purchaseOrderId" th:field="*{purchaseOrderId}" type="hidden">
<div class="form-group">
<label class="col-sm-3 control-label">采购单号:</label>
<div class="col-sm-8">
<input name="purchaseOrderCode" th:field="*{purchaseOrderCode}" class="form-control" type="text" readonly>
</div>
<div class="wrapper wrapper-content animated fadeInRight ibox-content">
<form class="form-horizontal m" id="form-purchaseOrder-detail" th:object="${purchaseOrder}">
<div class="col-xs-12">
<label class="col-sm-4 control-label">已选择采购计划:</label>
<div class="col-sm-7">
<input id="purchasePlanCodes" name="purchasePlanCode" class="form-control" type="text">
</div>
<div class="form-group">
<label class="col-sm-3 control-label">采购类别:</label>
<div class="col-sm-8">
<!-- <input name="purchaseCategory" th:field="*{purchaseCategory}" class="form-control" type="text">-->
<select name="purchaseCategory" th:field="*{purchaseCategory}" class="form-control m-b" th:with="type=${@dict.getType('purchase_category')}">
<option th:each="dict : ${type}" th:text="${dict.dictLabel}" th:value="${dict.dictValue}"></option>
</select>
</div>
<div class="container">
<ul class="nav nav-tabs" role="tablist">
<li role="presentation" class="active"><a href="#supplierModel" aria-controls="supplierModel" role="tab" data-toggle="tab">按供应商展示</a></li>
<li role="presentation"><a href="purchasePlanModel" aria-controls="purchasePlanModel" role="tab" data-toggle="tab">按采购计划展示</a></li>
</ul>
<div class="tab-content">
<div role="tabpanel" class="tab-pane" id="supplierModel">
<div class="container" id="supplierMaterial">
</div>
</div>
</div>
<div class="container">
<!--物料相关-->
<div class="row">
<div class="col-sm-12" id="tablesContainer">
<!-- 表格将在这里动态生成 -->
<div role="tabpanel" class="tab-pane active" id="purchasePlanModel">
<div class="container" id="purchasePlanMaterial">
</div>
</div>
</div>
</form>
</div>
</form>
<div class="container">
<div class="row"><h4 class="card-header">公司地址:</h4></div>
<div class="row">
<label for="stockNo" class="col-sm-2 col-form-label">仓库ID:</label>
<div class="col-sm-4">
<select class="form-control" name="stockNo" id="stockNo" ></select>
</div>
<label for="stockName" class="col-sm-2 col-form-label">仓库名称:</label>
<div class="col-sm-4">
<input type="text" class="form-control" name="stockName" id="stockName">
</div>
</div>
<div class="row">
<label for="stockContact" class="col-sm-2 col-form-label">收货人:</label>
<div class="col-sm-4">
<input type="text" name="stockContact" class="form-control" id="stockContact" >
</div>
<label for="stockPhone" class="col-sm-2 col-form-label">收货电话:</label>
<div class="col-sm-4">
<input type="text" name="stockPhone" class="form-control" id="stockPhone" placeholder="请输入收货电话">
</div>
</div>
<div class="form-group">
<label for="stockAddress" class="col-sm-2 col-form-label">详细地址:</label>
<div class="col-sm-4">
<textarea class="form-control" name="stockAddress" id="stockAddress"></textarea>
</div>
</div>
</div>
<div class="other-container">
<div class="other">
<br><hr>
<h4>选择采购信息</h4>
<a class="btn btn-primary" onclick="showQuotationModal()"><i class="fa fa-plus"></i>&nbsp;选择材料</a>
<a class="btn btn-danger" onclick="removeMaterial()" ><i class="fa fa-remove"></i>&nbsp;删除材料</a>
<div class="col-sm-12 select-table table-striped">
<table id="addQuotationTable" style="white-space:nowrap"></table>
<div class="container">
<div class="row"><h4 class="card-header">订单合计:</h4></div>
<div class="form-group">
<label for="purchaseMaterialSum" class="col-sm-2 col-form-label">物料合计:</label>
<div class="col-sm-4">
<input type="text" class="form-control" value="0" id="purchaseMaterialSum">
</div>
</div>
<div class="modal inmodal" id="supplierQuotationModal"
role="dilog" aria-hidden="true">
<!-- 查询供应商报价-->
<div class="modal-dialog" style="width: 1000px;background-color: #FFFFFF">
<div class="modal-content" style="background-color: #FFFFFF">
<div class="modal-body">
<div class="container-div">
<div class="row">
<div class="col-sm-12 search-collapse">
<form id="quotationFormId">
<div class="select-list">
<ul>
<li>
<label>报价编码:</label>
<input type="text" name="quotationCode"/>
</li>
<li>
<label>原辅料代码:</label>
<input type="text" name="rawSubsidiaryCode"/>
</li>
<li>
<label>原辅料名称:</label>
<input type="text" name="rawSubsidiaryName"/>
</li>
<!-- <li>-->
<!-- <label>供应商名称:</label>-->
<!-- <input type="text" name="supplierName"/>-->
<!-- </li>-->
<li>
<a class="btn btn-primary btn-rounded btn-sm" onclick="$.table.search('quotationFormId','quotationTable')"><i
class="fa fa-search"></i>&nbsp;搜索</a>
<a class="btn btn-warning btn-rounded btn-sm" onclick="$.form.reset('quotationFormId','quotationTable')"><i
class="fa fa-refresh"></i>&nbsp;重置</a>
</li>
</ul>
</div>
</form>
</div>
<div class="col-sm-12 select-table table-striped">
<table id="quotationTable" style="white-space:nowrap"></table>
</div>
</div>
</div>
</div>
<div class="modal-footer">
<a class="btn btn-warning btn-rounded" onclick="addQuotationToTable()">确认添加</a>
<a class="btn btn-primary btn-rounded" onclick="closeQuotationModal()">关闭</a>
</div>
</div>
<div class="form-group">
<label for="purchaseSum" class="col-sm-2 col-form-label">采购合计:</label>
<div class="col-sm-4">
<input type="text" class="form-control" value="0" id="purchaseSum">
</div>
</div>
<div class="form-group">
<label for="purchaseNoRmbSum" class="col-sm-2 col-form-label">不含税采购总价:</label>
<div class="col-sm-4">
<input type="text" class="form-control" value="0" id="purchaseNoRmbSum">
</div>
</div>
<div class="form-group">
<label for="purchaseRmbSum" class="col-sm-2 col-form-label">含税采购总价:</label>
<div class="col-sm-4">
<input type="text" class="form-control" value="0" id="purchaseRmbSum">
</div>
</div>
</div>
</div>
<th:block th:include="include :: footer" />
<th:block th:include="include :: datetimepicker-js" />
<th:block th:include="include :: select2-js"/>
<th:block th:include="include :: bootstrap-table-editable-js"/>
<script th:inline="javascript">
var getData = [[${purchaseOrder}]];
var commonCurrencyDatas = [[${@dict.getType('sys_common_currency')}]];
var purchasingUnitDatas = [[${@dict.getType('sys_unit_class')}]];
var materialTypeDatas = [[${@dict.getType('ck_meterialt_type')}]];
var confirmTaxDatas = [[${@dict.getType('sys_whether')}]];
var currentQuoteDatas = [[${@dict.getType('sys_whether')}]];
var confirmNoDatas = [[${@dict.getType('sys_whether')}]];
var auditNoDatas = [[${@dict.getType('sys_whether')}]];
var approveNoDatas = [[${@dict.getType('sys_whether')}]];
var prefix = ctx + "purchase/purchaseOrder";
var prefixSupplierQuotation = ctx + 'system/supplierquotation'
var prefixPurchaseMaterial = ctx + 'purchase/purchaseMaterial'
$("#form-purchaseOrder-detail").validate({
focusCleanup: true
});
function submitHandler() {
// if ($.validate.form()) {
// $.operate.save(prefix + "/edit", $('#form-purchaseOrder-detail').serialize());
// }
let getData=$('#addQuotationTable').bootstrapTable('getData', true)
if(getData.length > 0){
if ($.validate.form()) {
$.modal.confirm("确认以上修改吗?", function (){
//确认添加选中的物料数据
confirmQuotation();
$.operate.save(prefix + "/edit", $('#form-purchaseOrder-detail').serialize());
})
<th:block th:include="include :: footer" />
<th:block th:include="include :: select2-js" />
<th:block th:include="include :: datetimepicker-js" />
<th:block th:include="include :: bootstrap-table-editable-js" />
<script th:inline="javascript">
var prefix = ctx + "purchase/purchaseOrder";
var purchaseOrder = [[${purchaseOrder}]];
var materialTypeDatas = [[${@category.getChildByCode('materialType')}]];
var auditStatusDatas = [[${@dict.getType('auditStatus')}]];
var sysUnitClassDatas = [[${@dict.getType('sys_unit_class')}]];
var processMethodDatas = [[${@dict.getType('processMethod')}]];
var warehouseDeptDatas = [[${@dict.getType('warehouseDept')}]];
var loginName = [[${@permission.getPrincipalProperty('loginName')}]];
$("#form-plan-purchaseOrder-add").validate({focusCleanup: true});
var purchasePlanChildList = [];
var purchasePlanCodes = [];
var formId = "form-plan-purchaseOrder-add";
//根据物料物料数量添加物料分类表,自动生成类似的表单对象
//初始根据采购计划单,涉及到物料做分类表
//根据采购计划单,获取物料信息,自动生成物料的供应商分类表
//获取表单的id;
var materialList = [];
var tableIdList = [];
var $supplierForm;
var tableDatas = [];
//获取采购计划单的物料信息
// 假设qualityOrderCode已经定义或者可以通过某种方式获取到
$(function() {
// 初始化时默认加载仓库ID列表
loadWarehouseCodes();
// 假设purchaseOrderCode已经定义或者可以通过某种方式获取到
var purchaseOrderCode = [[${purchaseOrder.purchaseOrderCode}]]; // 这里需要实际赋值,比如从前端某个地方读取
var purchaseOrderId = [[${purchaseOrder.purchaseOrderId}]];
// 初始化表格,假设purchasePlanChildList已定义并包含了需要处理的数据
$.getJSON(prefix + "/editPurchaserOrder/" + purchaseOrderId, function(data) {
$("#purchasePlanCodes").val(data.data.purchasePlanCodes);
var datas = data.data.purchasePlanChildList;
purchasePlanChildList = datas;
var supplierCodes = data.data.supplierCodes;
var supplierMaterials = {};
datas.forEach(function(item) {
var supplierCode = item.supplierCode;
var materialCode = item.materialCode;
// 如果供应商还没有在对象中,就创建一个新的对象
if (!supplierMaterials[supplierCode]) {supplierMaterials[supplierCode] = {};}
// 如果该物料还没有在供应商的对象中,就添加它
if (!supplierMaterials[supplierCode][materialCode]) {
supplierMaterials[supplierCode][materialCode] = {
...item, materialNum: 0 // 初始化数量为0
};
}
supplierMaterials[supplierCode][materialCode].materialNum += item.materialNum;
});
for (var supplierCode in supplierMaterials) {
if (supplierMaterials.hasOwnProperty(supplierCode)) {
var supplierData = Object.values(supplierMaterials[supplierCode]);
createTableForSupplier(supplierCode, supplierData);
}
} else {
$.modal.alertWarning("未选择产品,请选择!")
}
}
$("input[name='billingDate']").datetimepicker({
format: "yyyy-mm-dd",
minView: "month",
autoclose: true,
todayBtn: true
});
$(function() {
//初始化添加材料表
$('#addQuotationTable').bootstrapTable({
url: prefixPurchaseMaterial + '/list',
pagination: true,
pageNumber: 1,
pageSize: 10,
method: "post",
contentType: "application/x-www-form-urlencoded",
striped: true, // 是否显示行间隔色
cache: false, // 是否使用缓存,默认为true,所以一般情况下需要设置一下这个属性(*)
showToggle: false, // 是否显示详细视图和列表视图的切换按钮
cardView: false, // 是否显示详细视图
detailView: false, // 是否显示父子表
smartDisplay: false, // 加了这个才显示每页显示的行数
showExport: false, // 是否显示导出按钮
clickToSelect: true,
paginationDetailHAlign: ' hiddenDetailInfo',
height: 250,
uniqueId: 'purchaseOrderChildId',
queryParams: function (params) {
//console.log("123");
var curParams = {
// 传递参数查询参数
pageSize: params.limit,
pageNum: params.offset / params.limit + 1,
purchaseOrderCode: getData.purchaseOrderCode,
supplierCode: getData.supplierCode,
supplierName: getData.supplierName
};
// console.log(data[0].enterpriseCode)
return curParams
},
columns: [{
checkbox: true
},
{
title: '采购订单子表id',
field: 'purchaseOrderChildId',
visible: false
},
{
title: '关联采购订单号',
field: 'purchaseOrderCode',
},
{
title: '供应商代码',
field: 'supplierCode',
},
{
title: '供应商名称',
field: 'supplierName',
},
{
title: '物料料号',
field: 'materialCode',
},
{
title: '物料名称',
field: 'materialName',
},
{
title: '物料不含税单价',
field: 'materialNormb',
},
{
title: '物料含税单价',
field: 'materialRmb',
},
{
title: '采购物料数量',
field: 'materialNum',
},
{
title: '物料合计',
field: 'materialAmount',
},
{
title: '数量合计',
field: 'materialSum',
},
{
title: '不含税总价(RMB)',
field: 'materialNormbsum',
},
{
title: '含税总价(RMB)',
field: 'materialRmbsum',
},
{
title: '交货时间',
field: 'deliveryTime',
},
{
title: '收货状态',
field: 'eceiptStatus',
},
{
title: '打款结案状态',
field: 'paymentStatus',
},
{
title: '税率',
field: 'taxRate',
},
]
})
});
//按照物料的维度查看采购订单信息
// 初始化表格
// 假设purchasePlanChildList已定义并包含了需要处理的数据
//物料列表
purchasePlanChildList.forEach(function (material, index) {
var tableId = 'materialCode-' + index;
var materialTable = "bootstrap-table_" + tableId;
tableIdList.push(tableId);
// 创建物料信息的容器
var $tableWrapper = $('<div id="material-' + tableId + '""></div>');
// 将整个物料信息容器添加到页面
$('#purchasePlanMaterial').append($tableWrapper);
// 添加关联销售订单号信息
// 创建表格的容器
var $headerDiv =
$('<div class="row"><div class="col-xs-12"><h3>' +
'<span><strong>物料 ' + (index + 1) + ': </strong><strong>关联订单号: </strong></span><span class="correlationCodes" id="correlateion-' + tableId + ' ">' + material.purchasePlanCorrelationCode
+ '</span>' +
'</h3><div class="col-sm-12"><table class="table-materialCode" id="' + materialTable + '">' + '<table/>' +
'</div></div></div>');
$tableWrapper.append($headerDiv);
//创建物料库存容器
var $stockWrapper = $('<div class="row"><div class="inventory-count " id=" inventory-count-' + tableId + '">'+
'<span><strong>可用库存数:</strong></span>'+'<span id="stock-count-' + tableId + '">10 </span>'+'<span>注:含其他订单待领取的库存,仅供参考,请以实际为准.</span>'+
'</div></div>');
$tableWrapper.append($stockWrapper);
var materialObj = {
purchasePlanCode: material.purchasePlanCode, materialCode: material.materialCode,
photoUrl: material.materialPhotourl, materialName: material.materialName,
materialType: material.materialType, describe: material.materialDescribe,
brand: material.materiaBrand, processMethod: material.materialProcessMethod,
unit: material.materialUnit, warehouseDept:material.warehouseDept,
materialNum: material.materialNum,
};
var materialData = [materialObj];
materialList.push(material);
tables(materialTable, materialData);
var $supplierInfo = $('<div class="supplier-card " style="height: 20px;" id="supplierInfo_' + tableId + '"></div>');
/*供应商列表*/
$.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)
$("#form-purchaseOrder-detail select[name='supplierCode']").append("<option value='" + suppliertData[i].supplierCode + "'>" + suppliertData[i].supplierCode + "</option>");
}
$("#form-purchaseOrder-detail select[name='supplierCode']").val(getData.supplierCode).trigger("change")
$("#form-purchaseOrder-detail select[name='supplierCode']").change(function () {
var code = $(this).val();
for (let i=0;i<suppliertData.length;i++) {
if (suppliertData[i].supplierCode == code) {
$("#form-purchaseOrder-detail input[name='supplierName']").val(suppliertData[i].supplierName);
$("#form-purchaseOrder-detail input[name='customerContact']").val(suppliertData[i].customerContact);
$("#form-purchaseOrder-detail input[name='contactNumber']").val(suppliertData[i].contactNumber);
$("#form-purchaseOrder-detail input[name='customerFax']").val(suppliertData[i].customerFax);
$("#form-purchaseOrder-detail input[name='paymentTerms']").val(suppliertData[i].paymentTerms);
$("#form-purchaseOrder-detail input[name='taxRate']").val(suppliertData[i].taxRate);
}
//如果物料下的供应商为空,则不需要添加供应商信息,并在容器中添加一个提示信息:暂无供应商信息,请先添加供应商信息。
const uniqueSuppliers = [];
if (material.purchaseSupplierList.length <= 0) {
var $noSupplierDiv = $('<div class="no-supplier">暂无供应商信息,请先添加供应商信息。</div>');
$tableWrapper.append($noSupplierDiv);
}
else{
material.purchaseSupplierList.forEach(supplier => {
const key = `${supplier.supplierCode}_${supplier.materialCode}`;
if (!uniqueSuppliers.map(s => `${s.supplierCode}_${s.materialCode}`).includes(key)) {
uniqueSuppliers.push(supplier);
}
})
} else {
$.modal.msgError(res.msg);
});
// 循环处理每个供应商的信息
uniqueSuppliers.forEach(function (supplier, supplierIndex) {
//如果供应商相同,则不需要再次添加供应商信息
// 卡片样式容器,用于包裹每个供应商的信息
// 构建供应商信息头部
var $headerContent =
$('<div class="card-header supplier_card" id = "supplier-' + tableId + '_' + supplierIndex + '">' +
'<div class="row">' +
'<div class="crad-text">'+
'<h4>供应商 ' + (supplierIndex + 1) + ':' + '</h4>' +
'<span class="supplierCode">' + supplier.supplierCode + '</span>' + '-' +
'<span class="supplierName">' + supplier.supplierName + '</span>' +
'-最新不含税采购价: ' +'<span id="supplierMaterialNoRmb-' + tableId + '" class="supplierMaterialNoRmb">' + supplier.materialNoRmb +'</span>'+
' RMB 最新含税采购价: ' +'<span class="supplierMaterialRmb">' + supplier.materialRmb + '</span> RMB ' +
'<span class="supplierPurchasePlanCode" hidden="hidden" >' + material.planCodes + '</span>' +
'<span class="supplierCorrelationCode" hidden="hidden" >' + material.correlationCodes + '</span>' +
'<span class="supplierPurchaseQuoteCode" hidden="hidden" >' + supplier.purchaseQuoteCode + '</span>' +
'</div>' +
'</div>' +
'<div class="row">' +
'<div class="col-xs-6 form-group">' +
'<label class="col-sm-4"> 实际采购数: </label>' +
'<div class ="col-sm-6">' +
'<input type="text" name="materialNum" class="form-control supplierMaterialNum actualPurchaseNum" id="actualPurchaseNum_' + tableId + '">' +
'</div>' +
'</div>' +
'<div class="col-xs-6 form-group">' +
'<label class="col-sm-4">计划交付时间: </label>' +
'<div class ="col-sm-6">' +
'<div class="input-group date"> ' +
'<input type="text" name="deliveryTime" class="form-control supplierDeliveryTime" id="deliveryTime_' + tableId + '">' +
'<span class="input-group-addon"><i class="fa fa-calendar"></i></span>' +
'</div> ' +
'</div>' +
'</div>' +
'</div>' +
'</div>');
if (supplier.supplierCode != undefined && supplier.supplierCode != '' && supplier.supplierCode != null) {
$supplierInfo.append($headerContent);
// 构建供应商信息下的输入表单
$supplierForm = $('<div class="card-body" id="card_body_' + tableId + '"></div>');
// 实际采购数输入框
// 其他表单项可以根据需要类似添加
$supplierInfo.append($supplierForm);
}else{
var $noSupplierDiv = $('<div class="no-supplier">暂无供应商信息,请先添加供应商信息。</div>');
$supplierInfo.append($noSupplierDiv);
}
});
$tableWrapper.append($supplierInfo);
}
}
})
/*用户列表*/
$.ajax({
url: ctx + 'system/user/list',
type: 'post',
success: function (res) {
console.log(res)
if (res.rows.length > 0) {
var usertData = res.rows;
//alert(JSON.stringify(data));
for (let i in usertData) {
// console.log(finishProductData[i].finishProductCode)
$("#form-purchaseOrder-detail select[name='purchaseCommander']").append("<option value='" + usertData[i].userName + "'>" + usertData[i].userName + "</option>");
tableSetup($supplierInfo, tableId);
});
// 给实际采购数的输入框绑定事件处理器
$('.actualPurchaseNum').off('keyup').on('keyup', function(event) {
if (event.keyCode === 13) {
var $supplierInfo = $(this).closest('.supplier-card');
var $supplierCard = $(this).closest('.supplier_card');
var crad = $supplierInfo.attr('id');
var tableId = crad.split('_')[1];
var purchaseNum = parseFloat($(this).val()) || 0;
var noRmbPrice = parseFloat($(this).find('.supplierMaterialNoRmb').text().trim()) || 0;
var rmbPrice = parseFloat($(this).find('.supplierMaterialRmb').text().trim()) || 0;
var materialIndex = tableId.split('-')[1];
// 确保实际采购数不超过计划采购数
var maxPurchaseNum = parseFloat(materialList[materialIndex].materialNum);
// if (purchaseNum > maxPurchaseNum) {
// purchaseNum = maxPurchaseNum;
// $(this).val(maxPurchaseNum);
// }
//物料所有的供应商的采购数加起来超出了materialList[materialIndex].materialNum,就提示超出计划采购数
let actualPurchaseNum = 0;
$supplierCard.find('.actualPurchaseNum').each(function () {
actualPurchaseNum += parseInt($(this).val()) || 0;
});
if (actualPurchaseNum > maxPurchaseNum) {
actualPurchaseNum - maxPurchaseNum;
}
// 更新供应商采购总价
$supplierInfo.find('.supplierPurchaseTotal').val(parseFloat(Number(purchaseNum * noRmbPrice).toFixed(2)));
if (rmbPrice) {
$supplierInfo.find('.supplierPurchaseTotalRmb').val(parseFloat(Number(purchaseNum * rmbPrice).toFixed(2)));
}
$("#form-purchaseOrder-detail select[name='purchaseCommander']").val(getData.purchaseCommander).trigger("change")
} else {
$.modal.msgError(res.msg);
}
}
})
/*添加报价信息*/
//点击按钮显示报价信息模态框
function showQuotationModal() {
if ($.validate.form()) {
$("#supplierQuotationModal").modal("show");
//显示报价信息
showQuotationData();
} else {
$.modal.alertWarning("请填写必填项");
}
}
//关闭报价信息模态框
function closeQuotationModal() {
$("#supplierQuotationModal").modal("hide");
}
//显示报价信息
function showQuotationData() {
var supplierCode = $("#form-purchaseOrder-detail select[name='supplierCode']").val()
$("#quotationTable").bootstrapTable("destroy")
var options = {
id: 'quotationTable',
url: prefixSupplierQuotation + "/list",
modalName: "供应商报价",
pagination: true,
pageNumber: 1,
pageSize: 10,
showRefresh: false,
showToggle: false,
clickToSelect: true,
queryParams: function (params) {
var curParams = {
// 传递参数查询参数
pageSize: params.limit,
pageNum: params.offset / params.limit + 1,
supplierCode: supplierCode
};
let json = $.extend(curParams, $.common.formToJSON("quotationFormId"));
return json;
},
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},
]
};
$.table.init(options);
}
// 如果采购数量大于0,则显示供应商采购总价
if (purchaseNum > 0) {
$supplierInfo.find('.supplierPurchaseTotal').removeClass('hidden');
$supplierInfo.find('.supplierPurchaseTotalRmb').removeClass('hidden');
} else {
// 否则隐藏供应商采购总价
$supplierInfo.find('.supplierPurchaseTotal').addClass('hidden');
$supplierInfo.find('.supplierPurchaseTotalRmb').addClass('hidden');
}
//表中添加选中的物料信息
function addQuotationToTable() {
var data = $("#quotationTable").bootstrapTable("getSelections");
var count = $('#addQuotationTable').bootstrapTable('getData').length;
var purchaseOrderNumber = $("input[name='purchaseOrderNumber']").val();
var supplierCode = $("select[name='supplierCode']").val();
var supplierName = $("input[name='supplierName']").val();
// console.log(data);
// console.log(count);
for (var i = 0; i < data.length; i++) {
let rawSubsidiary = $('#addQuotationTable').bootstrapTable('getRowByUniqueId', data[i].rawSubsidiaryCode);
if (rawSubsidiary != null) {
alert(rawSubsidiary.rawSubsidiaryName + "已存在,不可重复添加!");
continue;
recalculateTotals(tableId); // 重新计算当前物料的合计
}
$("#addQuotationTable").bootstrapTable('insertRow', {
index: count + i,
row: {
purchaseOrderNumber: purchaseOrderNumber,
supplierCode: supplierCode,
supplierName: supplierName,
materialQuantity: '',
amountMoney: '',
deliveryTime: '',
purchaseExplain: '',
accountReconciliationFlag: 0
});
// 定义一个函数来重新计算当前物料的合计
// 初始化总计
purchasePlanChildList.forEach(function (material, index) {recalculateTotals('materialCode-' + index);});
});
});
function createTableForSupplier(supplierCode, supplierData) {
var tableId = 'bootstrap-table-' + supplierCode.replace(/[^a-z0-9]/gi, '_').toLowerCase();
tableDatas.push(tableId);
var $tableWrapper = $('<div class="table-responsive"></div>');
// 确保supplierData至少有一条记录,并从中提取供应商详细信息
var supplierInfo = supplierData.length > 0 ? supplierData[0] : {}; // 默认为空对象,以防数据不存在
// 构建含有额外供应商信息的标题字符串
var headerTitle = '供应商: ' + supplierCode + ' - ' + supplierInfo.supplierName;
var $header = $('<h4>' + headerTitle + '</h4>');
var $table = $('<table id="' + tableId + '" class="table table-striped table-bordered"></table>');
$table.bootstrapTable({
data: supplierData,
columns: [
{ checkbox: false, visible: false },
{ title: '供应商ID', field: 'supplierCode', visible: false },
{ title: '料号', field: 'materialCode' },
{ title: '图片', field: 'materialPhotoUrl', 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: 'materialDescribe' },
{ title: '品牌', field: 'materialBrand' },
{ title: '加工类型', field: 'materialProcessMethod', align: 'center', formatter: function(value, row, index) {
return $.table.selectDictLabel(processMethodDatas, value);
}
},
{ title: '单位', field: 'materialUnit', align: 'center' },
{ title: '入库部门', field: 'warehouseDept', align: 'center', formatter: function(value, row, index) {
return $.table.selectDictLabel(warehouseDeptDatas, value);
}
},
{ title: '计划采购数', field: 'materialNum' },
{ title: '币种', field: '' },
{ title: '不含税采购价', field: 'materialNoRmb' },
{ title: '含税采购价', field: 'materialRmb' },
{ title: '实际采购数', field: 'materialRealNum"' },
{ title: '实际不含税采购金额', field: 'materialRealNoRmb' },
{ title: '实际含税采购金额', field: 'materialRealRmb' },
{ title: '已入库数', field: 'actualHasArrivedNum' },
]
});
$tableWrapper.append($header).append($table);
$('#supplierMaterial').append($tableWrapper);
}
// 加载仓库Id列表函数
$("#form-cgjl-edit").validate({focusCleanup: true});
//open打开时,模态框foot下新增审核通过和审核拒绝按钮
function submitHandler() {
if ($.validate.form()) {
if ($('textarea[name="comment"]').val()) {
$('input[name="p_COM_comment"]').val($('textarea[name="comment"]').val());
}
$("#quotationTable").bootstrapTable("uncheckAll");
closeQuotationModal();
var taskId = [[${taskId}]];
$.operate.save(prefix + "/complete/" + taskId, $('#form-cgjl-edit').serialize());
}
//确认添加选中的物料数据
function confirmQuotation() {
$("#addQuotationTable").bootstrapTable('refresh');
let data = $('#addQuotationTable').bootstrapTable('getData', true);
// console.log(data)
if (data.length > 0) {
for (var i = 0; i < data.length; i++) {
data[i].purchaseOrderNumber = $("input[name='purchaseOrderNumber']").val();
data[i].supplierCode = $("select[name='supplierCode']").val();
data[i].supplierName = $("input[name='supplierName']").val();
}
//获取仓库相关信息Select2,根据仓库ID查询仓库名称
$('#stockNo').on('change', function() {
var selectedWarehouseCode = $(this).val(); // 获取选中的仓库ID
if (selectedWarehouseCode) {
// 发起Ajax请求获取仓库名称
$.ajax({
type: 'GET',
url: ctx +'stock/stockInfo/getStockNameByWarehouseCode/' + selectedWarehouseCode,
dataType: 'json', // 假设返回的数据格式是JSON
success: function(data) {
console.log(data);
// 将获取到的仓库名称填充到输入框
if(data.data == null){
// 如果返回的数据有问题,可以给出提示或处理
$.modal.alertWarning('未能获取到仓库名称!');
}
$('input[name="stockName"]').val(data.data.stockName);
$('input[name="stockAddress"]').val(data.data.stockAddr);
$('input[name="stockContact"]').val(data.data.stockManager);
$('input[name="stockPhone"]').val(data.data.stockManagerPhone);
},
error: function(jqXHR, textStatus, errorThrown) {
console.error('Error:', textStatus, errorThrown);
$.modal.alertWarning('查询仓库名称时发生错误!');
}
$.ajax({
url: prefixPurchaseMaterial + '/addEditSave',
type: "POST",
data: {
data: JSON.stringify(data)
},
dataType: "json",
success: function (resp) {
// console.log(data)
console.log(resp)
},
})
}
});
}
// 批量删除成品
function removeMaterial() {
var addQuotationTableData = $("#addQuotationTable").bootstrapTable("getSelections");
var ids = [];
var rawSubsidiaryCodes=[];
for (let i = 0;i < addQuotationTableData.length;i++) {
ids.push(addQuotationTableData[i].purchaseMaterialId)
rawSubsidiaryCodes.push(addQuotationTableData[i].rawSubsidiaryCode)
}
// console.log(ids)
if (addQuotationTableData.length > 0) {
$.modal.confirm("是否确认要删除选中的产品?", function (){
$.ajax({
url: prefixPurchaseMaterial + "/removeMaterial",
type: "POST",
data: {
ids: JSON.stringify(ids)
},
success: function (res) {
// console.log(ids)
// console.log(res)
$.modal.msgSuccess("删除成功")
// $("#addProductTable").bootstrapTable('refreshOptions', {pageNumber: 1}); // pageNumber:1, 指定页码为第1页
// $("#addProductTable").bootstrapTable('refresh');
$("#addQuotationTable").bootstrapTable ('remove', { field: 'rawSubsidiaryCode', values: rawSubsidiaryCodes })
}
})
})
} else {
alert("请选择需要删除的数据")
else {$('input[name="warehouseName"]').val('');}// 如果没有选择仓库ID,清空仓库名称输入框
});
// 加载仓库Id列表函数
function loadWarehouseCodes() {
var url = ctx + 'stock/stockInfo/getAllWarehouseCode';
$.ajax({
type: 'GET', // 请求类型
url: url, // 后端接口URL
dataType: 'json', // 预期服务器返回的数据类型
success: function(data) {
if (data && Array.isArray(data)) {
var selectElement = $('#stockNo'); // 获取仓库编号下拉框元素
selectElement.empty();// 清空下拉框现有选项
$.each(data, function(index, item) {
selectElement.append('<option value="' + item.stockNO + '">' + item.stockNO + '</option>');
}); // 遍历返回的数据,添加为下拉框的选项
// $('#warehouseCode').val(purchaseOrder.stockNO);
} else {
$.modal.errMsg("数据为空");
}
}
}
</script>
});
}
</script>
</body>
</html>

1104
ruoyi-admin/src/main/resources/templates/purchase/purchaseOrder/edit.html

File diff suppressed because it is too large

11
ruoyi-admin/src/main/resources/templates/purchase/purchaseOrder/purchaseOrder.html

@ -222,13 +222,13 @@
if(row.auditStatus=="1" && row.useStatus=="1" && !row.cancelInstanceId) {
// 作废
actions.push('<a class="btn btn-danger btn-xs" href="javascript:void(0)" onclick="$.operate.cancel(\'' + row.purchaseOrderId + '\')"><i class="fa fa-remove"></i> 作废</a>');
// 编辑
actions.push('<a class="btn btn-success btn-xs" href="javascript:void(0)" onclick="$.operate.edit(\'' + row.purchaseOrderId + '\')"><i class="fa fa-edit"></i> 编辑</a> ');
// 入库通知
actions.push('<a class="btn btn-success btn-xs ' + addPurchaseOrderStorageFlag + '" href="javascript:void(0)" onclick="$.modal.open(\'添加入库通知检验单\',\'' + prefix+"/addPurchaseOrderStorage/"+row.purchaseOrderCode + '\')">入库通知</a> ');
}else{
actions.push('<a class="btn btn-default btn-xs" href="javascript:void(0)" disabled><i class="fa fa-edit"></i> 编辑</a> ');
}else if(row.auditStatus=="2" && row.cancelInstanceId){
// 编辑
actions.push('<a class="btn btn-success btn-xs" href="javascript:void(0)" onclick="$.operate.edit(\'' + row.purchaseOrderId + '\')"><i class="fa fa-edit"></i> 编辑</a> ');
}
//else{actions.push('<a class="btn btn-default btn-xs" href="javascript:void(0)" disabled><i class="fa fa-edit"></i> 编辑</a> ');}
// 有流程实例id
if(row.useStatus=="2" && !row.restoreInstanceId){
// 恢复
@ -249,7 +249,8 @@
// 进度查看
actions.push('<a class="btn btn-info btn-xs" href="javascript:void(0)" onclick="showProcessImgDialog(\'' + row.instanceId + '\')"><i class="fa fa-image"></i> 进度查看</a> ');
}
actions.push('<a class="btn btn-success btn-xs ' +
editFlag + '" href="javascript:void(0)" onclick="$.operate.detail(\'' + row.purchaseOrderId + '\')"><i class="fa fa-edit"></i>详情</a> ');
return actions.join('');
}

614
ruoyi-admin/src/main/resources/templates/purchase/purchaseOrder/taskCgjlVerify.html

@ -6,28 +6,27 @@
</head>
<body class="white-bg">
<div class="wrapper wrapper-content animated fadeInRight ibox-content">
<form class="form-horizontal m" id="form-gcjl-edit" th:object="${formData}">
<form class="form-horizontal m" id="form-cgjl-edit" th:object="${formData}">
<input name="purchaseOrderId" th:field="*{purchaseOrderId}" type="hidden">
<input name="taskId" th:field="*{taskId}" type="hidden">
<input name="taskName" th:field="*{taskName}" type="hidden">
<input name="instanceId" th:field="*{instanceId}" type="hidden">
<input name="instanceType" th:field="*{instanceType}" type="hidden">
<input type="hidden" name="p_COM_comment" />
<div class="form-group">
<div class="form-group" hidden="hidden">
<label class="col-sm-6 control-label">采购单号:</label>
<div class="col-sm-6">
<input name="purchaseOrderCode" th:field="*{purchaseOrderCode}" class="form-control" type="text" readonly>
<input name="purchaseOrderCode" th:field="*{purchaseOrderCode}" class="form-control" type="text" readonly>
</div>
</div>
<div class="form-group">
<div class="form-group" hidden="hidden">
<label class="col-sm-6 control-label">申请人:</label>
<div class="col-sm-6">
<input name="applyUser" th:field="*{applyUser}" class="form-control" type="text" readonly>
</div>
</div>
<div class="form-group">
<div class="form-group" hidden="hidden">
<label class="col-sm-6 control-label">申请时间:</label>
<div class="col-sm-6">
<div class="input-group date">
@ -36,12 +35,36 @@
</div>
</div>
</div>
<div class="form-group">
<div class="form-group" hidden="hidden">
<label class="col-sm-6 control-label">标题:</label>
<div class="col-sm-6">
<input name="title" th:field="*{applyTitle}" class="form-control" type="text" readonly>
</div>
</div>
<div class="col-xs-12">
<label class="col-sm-4 control-label">已选择采购计划:</label>
<div class="col-sm-7">
<input id="purchasePlanCodes" name="purchasePlanCode" class="form-control" type="text">
</div>
</div>
<div class="container">
<ul class="nav nav-tabs" role="tablist">
<li role="presentation" class="active"><a href="#supplierModel" aria-controls="supplierModel" role="tab" data-toggle="tab">按供应商展示</a></li>
<li role="presentation"><a href="#purchasePlanModel" aria-controls="purchasePlanModel" role="tab" data-toggle="tab">按采购计划展示</a></li>
</ul>
<div class="tab-content">
<div role="tabpanel" class="tab-pane " id="supplierModel">
<div class="container" id="supplierMaterial">
</div>
</div>
<div role="tabpanel" class="tab-pane active" id="purchasePlanModel">
<div class="container" id="purchasePlanMaterial">
</div>
</div>
</div>
</div>
<div class="form-group">
<label class="col-sm-3 control-label is-required" for="cgjlVerifyApproved">审批意见:</label>
<div class="col-sm-6">
@ -59,25 +82,596 @@
</div>
</div>
</form>
<div class="container">
<div class="row"><h4 class="card-header">公司地址:</h4></div>
<div class="row">
<label for="stockNo" class="col-sm-2 col-form-label">仓库ID:</label>
<div class="col-sm-4">
<select class="form-control" name="stockNo" id="stockNo" ></select>
</div>
<label for="stockName" class="col-sm-2 col-form-label">仓库名称:</label>
<div class="col-sm-4">
<input type="text" class="form-control" name="stockName" id="stockName">
</div>
</div>
<div class="row">
<label for="stockContact" class="col-sm-2 col-form-label">收货人:</label>
<div class="col-sm-4">
<input type="text" name="stockContact" class="form-control" id="stockContact" >
</div>
<label for="stockPhone" class="col-sm-2 col-form-label">收货电话:</label>
<div class="col-sm-4">
<input type="text" name="stockPhone" class="form-control" id="stockPhone" placeholder="请输入收货电话">
</div>
</div>
<div class="form-group">
<label for="stockAddress" class="col-sm-2 col-form-label">详细地址:</label>
<div class="col-sm-4">
<textarea class="form-control" name="stockAddress" id="stockAddress"></textarea>
</div>
</div>
</div>
<div class="container">
<div class="row"><h4 class="card-header">订单合计:</h4></div>
<div class="form-group">
<label for="purchaseMaterialSum" class="col-sm-2 col-form-label">物料合计:</label>
<div class="col-sm-4">
<input type="text" class="form-control" value="0" id="purchaseMaterialSum">
</div>
</div>
<div class="form-group">
<label for="purchaseSum" class="col-sm-2 col-form-label">采购合计:</label>
<div class="col-sm-4">
<input type="text" class="form-control" value="0" id="purchaseSum">
</div>
</div>
<div class="form-group">
<label for="purchaseNoRmbSum" class="col-sm-2 col-form-label">不含税采购总价:</label>
<div class="col-sm-4">
<input type="text" class="form-control" value="0" id="purchaseNoRmbSum">
</div>
</div>
<div class="form-group">
<label for="purchaseRmbSum" class="col-sm-2 col-form-label">含税采购总价:</label>
<div class="col-sm-4">
<input type="text" class="form-control" value="0" id="purchaseRmbSum">
</div>
</div>
</div>
</div>
<th:block th:include="include :: footer" />
<th:block th:include="include :: select2-js" />
<script th:src="@{/js/activiti.js}"></script>
<script th:inline="javascript">
var prefix = ctx + "purchase/purchaseOrder";
var purchaseOrder = [[${formData}]];
$("#form-gcjl-edit").validate({focusCleanup: true});
var materialTypeDatas = [[${@category.getChildByCode('materialType')}]];
var auditStatusDatas = [[${@dict.getType('auditStatus')}]];
var sysUnitClassDatas = [[${@dict.getType('sys_unit_class')}]];
var processMethodDatas = [[${@dict.getType('processMethod')}]];
var warehouseDeptDatas = [[${@dict.getType('warehouseDept')}]];
var loginName = [[${@permission.getPrincipalProperty('loginName')}]];
$("#form-plan-purchaseOrder-add").validate({focusCleanup: true});
var purchasePlanChildList = [];
var purchasePlanCodes = [];
var formId = "form-plan-purchaseOrder-add";
//根据物料物料数量添加物料分类表,自动生成类似的表单对象
//初始根据采购计划单,涉及到物料做分类表
//根据采购计划单,获取物料信息,自动生成物料的供应商分类表
//获取表单的id;
var materialList = [];
var tableIdList = [];
var $supplierForm;
var tableDatas = [];
//获取采购计划单的物料信息
// 假设qualityOrderCode已经定义或者可以通过某种方式获取到
$(function() {
// 初始化时默认加载仓库ID列表
loadWarehouseCodes();
// 假设purchaseOrderCode已经定义或者可以通过某种方式获取到
var purchaseOrderCode = [[${formData.purchaseOrderCode}]]; // 这里需要实际赋值,比如从前端某个地方读取
var purchaseOrderId = [[${formData.purchaseOrderId}]];
// 初始化表格,假设purchasePlanChildList已定义并包含了需要处理的数据
$.getJSON(prefix + "/editPurchaserOrder/" + purchaseOrderId, function(data) {
$("#purchasePlanCodes").val(data.data.purchasePlanCodes);
var datas = data.data.purchasePlanChildList;
purchasePlanChildList = datas;
var supplierCodes = data.data.supplierCodes;
var supplierMaterials = {};
datas.forEach(function(item) {
var supplierCode = item.supplierCode;
var materialCode = item.materialCode;
// 如果供应商还没有在对象中,就创建一个新的对象
if (!supplierMaterials[supplierCode]) {supplierMaterials[supplierCode] = {};}
// 如果该物料还没有在供应商的对象中,就添加它
if (!supplierMaterials[supplierCode][materialCode]) {
supplierMaterials[supplierCode][materialCode] = {
...item, materialNum: 0 // 初始化数量为0
};
}
supplierMaterials[supplierCode][materialCode].materialNum += item.materialNum;
});
for (var supplierCode in supplierMaterials) {
if (supplierMaterials.hasOwnProperty(supplierCode)) {
var supplierData = Object.values(supplierMaterials[supplierCode]);
createTableForSupplier(supplierCode, supplierData);
}
}
//按照物料的维度查看采购订单信息
// 初始化表格
// 假设purchasePlanChildList已定义并包含了需要处理的数据
//物料列表
purchasePlanChildList.forEach(function (material, index) {
var tableId = 'materialCode-' + index;
var materialTable = "bootstrap-table_" + tableId;
tableIdList.push(tableId);
// 创建物料信息的容器
var $tableWrapper = $('<div id="material-' + tableId + '""></div>');
// 将整个物料信息容器添加到页面
$('#purchasePlanMaterial').append($tableWrapper);
// 添加关联销售订单号信息
// 创建表格的容器
var $headerDiv =
$('<div class="row"><div class="col-xs-12"><h3>' +
'<span><strong>物料 ' + (index + 1) + ': </strong><strong>关联订单号: </strong></span><span class="correlationCodes" id="correlateion-' + tableId + ' ">' + material.purchasePlanCorrelationCode
+ '</span>' +
'</h3><div class="col-sm-12"><table class="table-materialCode" id="' + materialTable + '">' + '<table/>' +
'</div></div></div>');
$tableWrapper.append($headerDiv);
//创建物料库存容器
var $stockWrapper = $('<div class="row"><div class="inventory-count " id=" inventory-count-' + tableId + '">'+
'<span><strong>可用库存数:</strong></span>'+'<span id="stock-count-' + tableId + '">10 </span>'+'<span>注:含其他订单待领取的库存,仅供参考,请以实际为准.</span>'+
'</div></div>');
$tableWrapper.append($stockWrapper);
var materialObj = {
purchasePlanCode: material.purchasePlanCode, materialCode: material.materialCode,
photoUrl: material.materialPhotourl, materialName: material.materialName,
materialType: material.materialType, describe: material.materialDescribe,
brand: material.materiaBrand, processMethod: material.materialProcessMethod,
unit: material.materialUnit, warehouseDept:material.warehouseDept,
materialNum: material.materialNum,
};
var materialData = [materialObj];
materialList.push(material);
tables(materialTable, materialData);
var $supplierInfo = $('<div class="supplier-card " style="height: 20px;" id="supplierInfo_' + tableId + '"></div>');
//如果物料下的供应商为空,则不需要添加供应商信息,并在容器中添加一个提示信息:暂无供应商信息,请先添加供应商信息。
const uniqueSuppliers = [];
if (material.purchaseSupplierList.length <= 0) {
var $noSupplierDiv = $('<div class="no-supplier">暂无供应商信息,请先添加供应商信息。</div>');
$tableWrapper.append($noSupplierDiv);
}
else{
material.purchaseSupplierList.forEach(supplier => {
const key = `${supplier.supplierCode}_${supplier.materialCode}`;
if (!uniqueSuppliers.map(s => `${s.supplierCode}_${s.materialCode}`).includes(key)) {
uniqueSuppliers.push(supplier);
}
});
// 循环处理每个供应商的信息
uniqueSuppliers.forEach(function (supplier, supplierIndex) {
//如果供应商相同,则不需要再次添加供应商信息
// 卡片样式容器,用于包裹每个供应商的信息
// 构建供应商信息头部
var $headerContent =
$('<div class="card-header supplier_card" id = "supplier-' + tableId + '_' + supplierIndex + '">' +
'<div class="row">' +
'<div class="crad-text">'+
'<h4>供应商 ' + (supplierIndex + 1) + ':' + '</h4>' +
'<span class="supplierCode">' + supplier.supplierCode + '</span>' + '-' +
'<span class="supplierName">' + supplier.supplierName + '</span>' +
'-最新不含税采购价: ' +'<span id="supplierMaterialNoRmb-' + tableId + '" class="supplierMaterialNoRmb">' + supplier.materialNoRmb +'</span>'+
' RMB 最新含税采购价: ' +'<span class="supplierMaterialRmb">' + supplier.materialRmb + '</span> RMB ' +
'<span class="supplierPurchasePlanCode" hidden="hidden" >' + material.planCodes + '</span>' +
'<span class="supplierCorrelationCode" hidden="hidden" >' + material.correlationCodes + '</span>' +
'<span class="supplierPurchaseQuoteCode" hidden="hidden" >' + supplier.purchaseQuoteCode + '</span>' +
'</div>' +
'</div>' +
'<div class="row">' +
'<div class="col-xs-6 form-group">' +
'<label class="col-sm-4"> 实际采购数: </label>' +
'<div class ="col-sm-6">' +
'<input type="text" name="materialNum" class="form-control supplierMaterialNum actualPurchaseNum" id="actualPurchaseNum_' + tableId + '">' +
'</div>' +
'</div>' +
'<div class="col-xs-6 form-group">' +
'<label class="col-sm-4">计划交付时间: </label>' +
'<div class ="col-sm-6">' +
'<div class="input-group date"> ' +
'<input type="text" name="deliveryTime" class="form-control supplierDeliveryTime" id="deliveryTime_' + tableId + '">' +
'<span class="input-group-addon"><i class="fa fa-calendar"></i></span>' +
'</div> ' +
'</div>' +
'</div>' +
'</div>' +
'</div>');
if (supplier.supplierCode != undefined && supplier.supplierCode != '' && supplier.supplierCode != null) {
$supplierInfo.append($headerContent);
// 构建供应商信息下的输入表单
$supplierForm = $('<div class="card-body" id="card_body_' + tableId + '"></div>');
// 实际采购数输入框
// 其他表单项可以根据需要类似添加
$supplierInfo.append($supplierForm);
}else{
var $noSupplierDiv = $('<div class="no-supplier">暂无供应商信息,请先添加供应商信息。</div>');
$supplierInfo.append($noSupplierDiv);
}
});
$tableWrapper.append($supplierInfo);
}
tableSetup($supplierInfo, tableId);
});
// 给实际采购数的输入框绑定事件处理器
$('.actualPurchaseNum').off('keyup').on('keyup', function(event) {
if (event.keyCode === 13) {
var $supplierInfo = $(this).closest('.supplier-card');
var $supplierCard = $(this).closest('.supplier_card');
var crad = $supplierInfo.attr('id');
var tableId = crad.split('_')[1];
var purchaseNum = parseFloat($(this).val()) || 0;
var noRmbPrice = parseFloat($(this).find('.supplierMaterialNoRmb').text().trim()) || 0;
var rmbPrice = parseFloat($(this).find('.supplierMaterialRmb').text().trim()) || 0;
var materialIndex = tableId.split('-')[1];
// 确保实际采购数不超过计划采购数
var maxPurchaseNum = parseFloat(materialList[materialIndex].materialNum);
// if (purchaseNum > maxPurchaseNum) {
// purchaseNum = maxPurchaseNum;
// $(this).val(maxPurchaseNum);
// }
//物料所有的供应商的采购数加起来超出了materialList[materialIndex].materialNum,就提示超出计划采购数
let actualPurchaseNum = 0;
$supplierCard.find('.actualPurchaseNum').each(function () {
actualPurchaseNum += parseInt($(this).val()) || 0;
});
if (actualPurchaseNum > maxPurchaseNum) {
actualPurchaseNum - maxPurchaseNum;
}
// 更新供应商采购总价
$supplierInfo.find('.supplierPurchaseTotal').val(parseFloat(Number(purchaseNum * noRmbPrice).toFixed(2)));
if (rmbPrice) {
$supplierInfo.find('.supplierPurchaseTotalRmb').val(parseFloat(Number(purchaseNum * rmbPrice).toFixed(2)));
}
// 如果采购数量大于0,则显示供应商采购总价
if (purchaseNum > 0) {
$supplierInfo.find('.supplierPurchaseTotal').removeClass('hidden');
$supplierInfo.find('.supplierPurchaseTotalRmb').removeClass('hidden');
} else {
// 否则隐藏供应商采购总价
$supplierInfo.find('.supplierPurchaseTotal').addClass('hidden');
$supplierInfo.find('.supplierPurchaseTotalRmb').addClass('hidden');
}
recalculateTotals(tableId); // 重新计算当前物料的合计
}
});
// 定义一个函数来重新计算当前物料的合计
// 初始化总计
purchasePlanChildList.forEach(function (material, index) {recalculateTotals('materialCode-' + index);});
});
});
function createTableForSupplier(supplierCode, supplierData) {
var tableId = 'bootstrap-table-' + supplierCode.replace(/[^a-z0-9]/gi, '_').toLowerCase();
tableDatas.push(tableId);
var $tableWrapper = $('<div class="table-responsive"></div>');
// 确保supplierData至少有一条记录,并从中提取供应商详细信息
var supplierInfo = supplierData.length > 0 ? supplierData[0] : {}; // 默认为空对象,以防数据不存在
// 构建含有额外供应商信息的标题字符串
var headerTitle = '供应商: ' + supplierCode + ' - ' + supplierInfo.supplierName;
var $header = $('<h4>' + headerTitle + '</h4>');
var $table = $('<table id="' + tableId + '" class="table table-striped table-bordered"></table>');
$table.bootstrapTable({
data: supplierData,
columns: [
{ checkbox: false, visible: false },
{ title: '供应商ID', field: 'supplierCode', visible: false },
{ title: '料号', field: 'materialCode' },
{ title: '图片', field: 'materialPhotoUrl', 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: 'materialDescribe' },
{ title: '品牌', field: 'materialBrand' },
{ title: '加工类型', field: 'materialProcessMethod', align: 'center', formatter: function(value, row, index) {
return $.table.selectDictLabel(processMethodDatas, value);
}
},
{ title: '单位', field: 'materialUnit', align: 'center' },
{ title: '入库部门', field: 'warehouseDept', align: 'center', formatter: function(value, row, index) {
return $.table.selectDictLabel(warehouseDeptDatas, value);
}
},
{ title: '计划采购数', field: 'materialNum' },
{ title: '币种', field: '' },
{ title: '不含税采购价', field: 'materialNoRmb' },
{ title: '含税采购价', field: 'materialRmb' },
{ title: '实际采购数', field: 'materialRealNum"' },
{ title: '实际不含税采购金额', field: 'materialRealNoRmb' },
{ title: '实际含税采购金额', field: 'materialRealRmb' },
{ title: '已入库数', field: 'actualHasArrivedNum' },
]
});
$tableWrapper.append($header).append($table);
$('#supplierMaterial').append($tableWrapper);
}
// 加载仓库Id列表函数
$("#form-cgjl-edit").validate({focusCleanup: true});
//open打开时,模态框foot下新增审核通过和审核拒绝按钮
function submitHandler() {
if ($.validate.form()) {
if ($('textarea[name="comment"]').val()) {
$('input[name="p_COM_comment"]').val($('textarea[name="comment"]').val());
}
var taskId = [[${taskId}]];
$.operate.save(prefix + "/complete/" + taskId, $('#form-gcjl-edit').serialize());
$.operate.save(prefix + "/complete/" + taskId, $('#form-cgjl-edit').serialize());
}
}
//获取仓库相关信息Select2,根据仓库ID查询仓库名称
$('#stockNo').on('change', function() {
var selectedWarehouseCode = $(this).val(); // 获取选中的仓库ID
if (selectedWarehouseCode) {
// 发起Ajax请求获取仓库名称
$.ajax({
type: 'GET',
url: ctx +'stock/stockInfo/getStockNameByWarehouseCode/' + selectedWarehouseCode,
dataType: 'json', // 假设返回的数据格式是JSON
success: function(data) {
console.log(data);
// 将获取到的仓库名称填充到输入框
if(data.data == null){
// 如果返回的数据有问题,可以给出提示或处理
$.modal.alertWarning('未能获取到仓库名称!');
}
$('input[name="stockName"]').val(data.data.stockName);
$('input[name="stockAddress"]').val(data.data.stockAddr);
$('input[name="stockContact"]').val(data.data.stockManager);
$('input[name="stockPhone"]').val(data.data.stockManagerPhone);
},
error: function(jqXHR, textStatus, errorThrown) {
console.error('Error:', textStatus, errorThrown);
$.modal.alertWarning('查询仓库名称时发生错误!');
}
});
}
else {$('input[name="warehouseName"]').val('');}// 如果没有选择仓库ID,清空仓库名称输入框
});
// 加载仓库Id列表函数
function loadWarehouseCodes() {
var url = ctx + 'stock/stockInfo/getAllWarehouseCode';
$.ajax({
type: 'GET', // 请求类型
url: url, // 后端接口URL
dataType: 'json', // 预期服务器返回的数据类型
success: function(data) {
if (data && Array.isArray(data)) {
var selectElement = $('#stockNo'); // 获取仓库编号下拉框元素
selectElement.empty();// 清空下拉框现有选项
$.each(data, function(index, item) {
selectElement.append('<option value="' + item.stockNO + '">' + item.stockNO + '</option>');
}); // 遍历返回的数据,添加为下拉框的选项
// $('#warehouseCode').val(formData.stockNO);
} else {
$.modal.errMsg("数据为空");
}
}
});
}
// 新增函数:重新计算某物料的采购数量合计、不含税采购总价和含税采购总价
function recalculateTotals(tableId) {
var $tableWrapper = $('#material-' + tableId);
var totalNoRmb = 0;
var totalRmb = 0;
var totalActualPurchase = 0;
var $suplierInfo = $tableWrapper.find('.supplier-card');
//获取所有物料表中供应商列表数据,实际采购数合计,不含税总价,含税采购总价
$suplierInfo.find('.supplier_card').each(function() {
let purchaseNum = parseFloat($(this).find('.actualPurchaseNum').val()) || 0;
let noRmbPrice = parseFloat($(this).find('.supplierMaterialNoRmb').text().trim()) || 0;
let rmbPrice = parseFloat($(this).find('.supplierMaterialRmb').text().trim()) || 0;
totalNoRmb += purchaseNum * noRmbPrice;
totalRmb += purchaseNum * rmbPrice;
totalActualPurchase = totalActualPurchase + purchaseNum;
});
//物料的实际采购数合计
$('#materialAmountSum_' + tableId).val(totalActualPurchase);
//物料的实际不含税采购总价:
$('#materialNoRmbSum_' + tableId).val(parseFloat(totalNoRmb));
//物料的实际含税总价:
$('#materialRmbSum_' + tableId).val(parseFloat(totalRmb));
// 采购物料合计
materialActualPurchaseSum();
}
function materialActualPurchaseSum(){
var totalNoRmb = 0;
var totalRmb = 0;
var totalActualPurchase = 0;
var materialAmount = 0;
tableIdList.forEach(function (material, index) {
var tableId = tableIdList[index];
var $tableWrapper = $('#material-' + tableId);
//采购合计 = 所有物料的采购数量合计
//采购不含税总价 = 所有物料的不含税总价合计
//采购含税总价 = 所有物料的含税总价合计
//查询物料表下吗整合的物料的实际采购数合计,物料的实际不含税采购总价,物料的实际含税总价
var supplierInfo = $tableWrapper.find('#supplierInfo_' + tableId );
let purchaseNum = parseInt(supplierInfo.find('.actualPurchaseTotalSum').val().trim()) || 0;
let noRmbPrice = parseFloat(supplierInfo.find('.actualPurchaseTotal').val().trim()) || 0;
let rmbPrice = parseFloat(supplierInfo.find('.actualPurchaseTotalTax').val().trim()) || 0;
if (purchaseNum > 0) {
materialAmount += 1;
}
totalActualPurchase += purchaseNum;
totalNoRmb += noRmbPrice;
totalRmb += rmbPrice;
});
//物料合计 = 物料实际采购数合计,不含税总价,含税采购总价不为null的情况可以合计物料,否则跳过
$("#purchaseMaterialSum").val(materialAmount);
//采购数量合计
$('#purchaseSum').val(totalActualPurchase);
//采购不含税总价
$('#purchaseNoRmbSum').val(totalNoRmb);
//采购含税总价
$('#purchaseRmbSum').val(totalRmb);
}
function tableSetup(element, tableId) {
var $totalSection = $(
'<div class="card">' +
'<div class="card-body" class="supplierTotal_' + tableId + '">' +
'<div class="form-row">' +
'<label for="actualPurchaseTotal" class="col-sm-4">实际采购数合计:</label>' +
'<div class="col-sm-8">' +
'<input type="number" name="materialAmountSum" class="form-control actualPurchaseTotalSum" id="materialAmountSum_' + tableId + '">' +
'</div>' +
'</div>' +
'<div class="form-row">' +
'<label for="actualPurchaseTotal" class="col-sm-4">不含税采购总价:</label>' +
'<div class="col-sm-8">' +
'<input type="number" name="materialNoRmbSum" class="form-control actualPurchaseTotal" id="materialNoRmbSum_' + tableId + '" ' +
'</div>' +
'</div>' +
'<div class="form-row">' +
'<label for="actualPurchaseTotalTax" class="col-sm-4">含税采购总价:</label>' +
'<div class="col-sm-8">' +
'<input type="number" name="materialRmbSum" class="form-control actualPurchaseTotalTax" id="materialRmbSum_' + tableId + '">' +
'</div>' +
'</div>' +
'</div>'+
'</div>');
element.append($totalSection);
}
function tables(tableId, data) {
$('#' + tableId).bootstrapTable({
showExport: false,
showFooter: false,
showSearch: false,
showRefresh: false,
showColumns: false,
showToggle: false,
data: data,
height: 70,
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', },
{title: '入库部门', field: 'warehouseDept', align: 'center', formatter: function (value, row, index) {
return $.table.selectDictLabel(warehouseDeptDatas, value);
}},
{title: '计划采购数', field: 'materialNum'},
],
});
}
function submitHandlerPurchaseOrder() {
if ($.validate.form()) {
var materialSum = 0;
var materialRealSum = 0;
var materialNoRmbSum = 0;
var materialRmbSum = 0;
//添加去除供应商编号数组
var supplierNumList = [];
var purchaseOrder = {
supplierNum: 0, materialNum: 0, noRmbSum: 0, rmbSum: 0,
stockNo: $("#stockNo").val(),
stockName: $("#stockName").val(),
stockAddress: $("#stockAddress").val(),
stockContact: $("#stockContact").val(),
stockPhone: $("#stockPhone").val(),
purchaseOrderChildList: [],
};
// 遍历每个物料容器
$('.table-materialCode').each(function (index, tableElement) {
var tableId = tableIdList[index];
let materialObj = materialList[index];
var $tableWrapper = $('#material-' + tableId);
if (typeof materialObj === 'undefined') return;
var $suplierInfo = $tableWrapper.find('.supplier-card');
$suplierInfo.find('.supplier_card').each(function (supplierIndex, supplierCard) {
var supplierCode = $(this).find('.supplierCode').text().trim();
var supplierName = $(this).find('.supplierName').text().trim();
var materialRealNum = parseInt($(this).find('.actualPurchaseNum').val()) || 0;
var materialRealRmb = parseFloat($(this).find('.supplierMaterialRmb').text()) || 0;
var materialRealNoRmb = parseFloat($(this).find('.supplierMaterialNoRmb').text()) || 0;
var deliveryTime = $(this).find('.supplierDeliveryTime').val();
var purchasePlanCode = $(this).find('.supplierPurchasePlanCode').text().trim();
var correlationCode = $(this).find('.supplierCorrelationCode').text().trim();
var purchaseQuoteCode = $(this).find('.supplierPurchaseQuoteCode').text().trim();
var materialRealRmbSum = parseFloat(materialRealRmb * materialRealNum);
var materialRealNoRmbSum = parseFloat(materialRealNoRmb * materialRealNum);
materialRealSum += materialRealNum;
materialNoRmbSum += materialRealNoRmbSum;
materialRmbSum += materialRealRmbSum;
if (supplierNumList.indexOf(supplierCode) === -1) {
supplierNumList.push(supplierCode);
purchaseOrder.supplierNum += 1;
}
var materialData = {
materialCode: materialObj.materialCode,
materialName: materialObj.materialName,
materialType: materialObj.materialType,
materialBrand: materialObj.brand,
materialDescribe: materialObj.describe,
materialProcessMethod: materialObj.processMethod,
materialUnit: materialObj.unit,
materialPhotoUrl: materialObj.photoUrl,
warehouseDept: materialObj.warehouseDept,
materialNum: materialObj.materialNum,
supplierCode: supplierCode,
supplierName: supplierName,
materialNoRmb: materialObj.materialNoRmb,
materialRmb: materialObj.materialRmb,
materialRealNum: materialRealNum,
materialRealRmb: materialRealRmb,
materialRealNoRmb: materialRealNoRmb,
materialRealRmbSum: materialRealRmbSum,
materialRealNoRmbSum: materialRealNoRmbSum,
deliveryTime: deliveryTime,
purchasePlanCode: purchasePlanCode,
correlationCode: correlationCode,
purchaseQuoteCode: purchaseQuoteCode,
};
purchaseOrder.purchaseOrderChildList.push(materialData);
});
});
// 获取采购物料合计,采购物料实际合计,采购物料实际非人民币合计,采购物料实际人民币合计
var purchaseAmount = parseFloat($('#purchaseMaterialSum').val());
var purchaseSum = parseFloat($('#purchaseSum').val());
var purchaseNoRmbSum = parseFloat($('#purchaseNoRmbSum').val());
var purchaseRmbSum = parseFloat($('#purchaseRmbSum').val());
// 将合计值附加到purchaseOrder对象
purchaseOrder.materialAmount = purchaseAmount;
purchaseOrder.materialSum = purchaseSum;
purchaseOrder.materialNoRmbSum = purchaseNoRmbSum;
purchaseOrder.materialRmbSum = purchaseRmbSum;
purchaseOrder.supplierNum = supplierNumList.length;
// 发送数据到后端API
$.operate.saveJson(prefix + "/addPurchaseOrder", JSON.stringify(purchaseOrder));
}
}
</script>
</body>
</html>

320
ruoyi-admin/src/main/resources/templates/purchase/purchasePlan/addPurchaseOrder.html

@ -5,6 +5,13 @@
<th:block th:include="include :: select2-css" />
<th:block th:include="include :: datetimepicker-css" />
<th:block th:include="include :: bootstrap-editable-css" />
<style>
.inventory-count {
background-color: #f9f9f9;
}
.inventory-count p {margin: 0;}
/*.inventory-count span {font-weight: bold;}*/
</style>
</head>
<body class="white-bg">
<div class="wrapper wrapper-content animated fadeInRight ibox-content">
@ -12,7 +19,7 @@
<div class="col-xs-12">
<label class="col-sm-4 control-label">已选择采购计划:</label>
<div class="col-sm-7">
<input id="purchasePlanCodes" name="purchasePlanCode" class="form-control" type="text">
<input id="purchasePlanCodes" name="purchasePlanCode" class="form-control" type="text">
</div>
</div>
<div class="container" id="material">
@ -57,25 +64,25 @@
<div class="form-group">
<label for="purchaseMaterialSum" class="col-sm-2 col-form-label">物料合计:</label>
<div class="col-sm-4">
<input type="text" class="form-control" value="0" id="purchaseMaterialSum">
<input type="number" class="form-control" value="0" id="purchaseMaterialSum">
</div>
</div>
<div class="form-group">
<label for="purchaseSum" class="col-sm-2 col-form-label">采购合计:</label>
<div class="col-sm-4">
<input type="text" class="form-control" value="0" id="purchaseSum">
<input type="number" class="form-control" value="0" id="purchaseSum">
</div>
</div>
<div class="form-group">
<label for="purchaseNoRmbSum" class="col-sm-2 col-form-label">不含税采购总价:</label>
<div class="col-sm-4">
<input type="text" class="form-control" value="0" id="purchaseNoRmbSum">
<input type="number" class="form-control" value="0" id="purchaseNoRmbSum">
</div>
</div>
<div class="form-group">
<label for="purchaseRmbSum" class="col-sm-2 col-form-label">含税采购总价:</label>
<div class="col-sm-4">
<input type="text" class="form-control" value="0" id="purchaseRmbSum">
<input type="number" class="form-control" value="0" id="purchaseRmbSum">
</div>
</div>
</div>
@ -120,11 +127,12 @@
// 将整个物料信息容器添加到页面
$('#material').append($tableWrapper);
// 添加关联销售订单号信息
// 创建表格的容器
var $headerDiv =
$('<div class="row">' +
'<div class="col-xs-12">' +
'<h3>' +
'<span><strong>物料 ' + index + ': </strong> ' + '<strong>关联订单号: </strong></span>' + '<span class="correlationCodes" id="correlateion-' + tableId + ' ">' + material.correlationCodes + '</span>' +
'<span><strong>物料 ' + (index + 1) + ': </strong> ' + '<strong>关联订单号: </strong></span>' + '<span class="correlationCodes" id="correlateion-' + tableId + ' ">' + material.correlationCodes + '</span>' +
'</h3>' +
'<div class="col-sm-12">' +
'<table class="table-materialCode" id="' + materialTable + '">' + '<table/>' +
@ -132,6 +140,13 @@
'</div>' +
'</div>');
$tableWrapper.append($headerDiv);
//创建物料库存容器
var $stockWrapper = $('<div class="row">' +
'<div class="inventory-count " id=" inventory-count-' + tableId + '">'+
'<span><strong>可用库存数:</strong></span>'+'<span id="stock-count-' + tableId + '">10 </span>'+'<span>注:含其他订单待领取的库存,仅供参考,请以实际为准.</span>'+
'</div>' +
'</div>');
$tableWrapper.append($stockWrapper);
var materialObj = {
purchasePlanCode: material.purchasePlanCode,
materialCode: material.materialCode,
@ -148,8 +163,8 @@
var materialData = [materialObj]; // Bootstrap Table需要一个数组作为数据源
materialList.push(material);
tables(materialTable, materialData);
var $supplierInfo = $('<div class="supplier-card" style="height: 20px;" id="supplierInfo-' + tableId + '"></div>');
// 创建表格的容器
var $supplierInfo = $('<div class="supplier-card " style="height: 20px;" id="supplierInfo_' + tableId + '"></div>');
//如果物料下的供应商为空,则不需要添加供应商信息,并在容器中添加一个提示信息:暂无供应商信息,请先添加供应商信息。
const uniqueSuppliers = [];
if (material.purchaseSupplierList.length <= 0) {
@ -161,9 +176,6 @@
const key = `${supplier.supplierCode}_${supplier.materialCode}`;
if (!uniqueSuppliers.map(s => `${s.supplierCode}_${s.materialCode}`).includes(key)) {
uniqueSuppliers.push(supplier);
}else{
var $noSupplierDiv = $('<div class="no-supplier">暂无供应商信息,请先添加供应商信息。</div>');
$supplierInfo.append($noSupplierDiv);
}
});
// 循环处理每个供应商的信息
@ -172,10 +184,10 @@
// 卡片样式容器,用于包裹每个供应商的信息
// 构建供应商信息头部
var $headerContent =
$('<div class="card-header suppplier_card" id = "supplier-' + tableId + '_' + supplierIndex + '">' +
$('<div class="card-header supplier_card" id = "supplier-' + tableId + '_' + supplierIndex + '">' +
'<div class="row">' +
'<div class="crad-text">'+
'<h4>供应商 ' + supplierIndex + ':' + '</h4>' +
'<h4>供应商 ' + (supplierIndex + 1) + ':' + '</h4>' +
'<span class="supplierCode">' + supplier.supplierCode + '</span>' + '-' +
'<span class="supplierName">' + supplier.supplierName + '</span>' +
'-最新不含税采购价: ' +'<span id="supplierMaterialNoRmb-' + tableId + '" class="supplierMaterialNoRmb">' + supplier.materialNoRmb +'</span>'+
@ -186,15 +198,15 @@
'</div>' +
'</div>' +
'<div class="row">' +
'<div class="form-row">' +
'<label class="col-sm-2"> 实际采购数: </label>' +
'<div class ="col-sm-4">' +
'<input type="text" name="materialNum" class="form-control supplierMaterialNum" id="actualPurchaseNum_' + tableId + '">' +
'<div class="col-xs-6 form-group">' +
'<label class="col-sm-4"> 实际采购数: </label>' +
'<div class ="col-sm-6">' +
'<input type="text" name="materialNum" class="form-control supplierMaterialNum actualPurchaseNum" id="actualPurchaseNum_' + tableId + '">' +
'</div>' +
'</div>' +
'<div class="form-row">' +
'<label class="col-sm-2">计划交付时间: </label>' +
'<div class ="col-sm-4">' +
'<div class="col-xs-6 form-group">' +
'<label class="col-sm-4">计划交付时间: </label>' +
'<div class ="col-sm-6">' +
'<div class="input-group date"> ' +
'<input type="text" name="deliveryTime" class="form-control supplierDeliveryTime" id="deliveryTime_' + tableId + '">' +
'<span class="input-group-addon"><i class="fa fa-calendar"></i></span>' +
@ -220,73 +232,113 @@
tableSetup($supplierInfo, tableId);
});
// 给实际采购数的输入框绑定事件处理器
$('.supplierMaterialNum').off('keyup').on('keyup', function(event,element) {
//实际采购数不能超过计划采购数
var tableId = $(element).closest('.table-materialCode').attr('id');
$('.actualPurchaseNum').off('keyup').on('keyup', function(event) {
if (event.keyCode === 13) {
// 获取当前供应商的采购数量
var purchaseNum = parseFloat($(event).val()) || 0;
if (purchaseNum > parseFloat($(event).closest('.supplier-card').find('.supplierMaterialNum').text().trim())) {
$(event).val($(event).closest('.supplier-card').find('.supplierMaterialNum').text().trim());
purchaseNum = parseFloat($(event).val()) || 0;
var $supplierInfo = $(this).closest('.supplier-card');
var $supplierCard = $(this).closest('.supplier_card');
var crad = $supplierInfo.attr('id');
var tableId = crad.split('_')[1];
var purchaseNum = parseFloat($(this).val()) || 0;
var noRmbPrice = parseFloat($(this).find('.supplierMaterialNoRmb').text().trim()) || 0;
var rmbPrice = parseFloat($(this).find('.supplierMaterialRmb').text().trim()) || 0;
var materialIndex = tableId.split('-')[1];
// 确保实际采购数不超过计划采购数
var maxPurchaseNum = parseFloat(materialList[materialIndex].materialNum);
// if (purchaseNum > maxPurchaseNum) {
// purchaseNum = maxPurchaseNum;
// $(this).val(maxPurchaseNum);
// }
//物料所有的供应商的采购数加起来超出了materialList[materialIndex].materialNum,就提示超出计划采购数
let actualPurchaseNum = 0;
$supplierCard.find('.actualPurchaseNum').each(function () {
actualPurchaseNum += parseInt($(this).val()) || 0;
});
if (actualPurchaseNum > maxPurchaseNum) {
actualPurchaseNum - maxPurchaseNum;
}
// 获取当前供应商的采购价格
var noRmbPrice = parseFloat($(event).closest('.supplier-card').find('.supplierMaterialNoRmb').text().trim());
var rmbPrice = parseFloat($(event).closest('.supplier-card').find('.supplierMaterialRmb').text().trim());
// 更新供应商采购总价
$(event).closest('.supplier-card').find('.supplierPurchaseTotal').text(purchaseNum * noRmbPrice);
$supplierInfo.find('.supplierPurchaseTotal').val(parseFloat(Number(purchaseNum * noRmbPrice).toFixed(2)));
if (rmbPrice) {
$(event).closest('.supplier-card').find('.supplierPurchaseTotalRmb').text(purchaseNum * rmbPrice);
$supplierInfo.find('.supplierPurchaseTotalRmb').val(parseFloat(Number(purchaseNum * rmbPrice).toFixed(2)));
}
// 如果采购数量大于0,则显示供应商采购总价
if (purchaseNum > 0) {
// 如果采购数量大于0,则显示供应商采购总价
$(event).closest('.supplier-card').find('.supplierPurchaseTotal').removeClass('hidden');
$(event).closest('.supplier-card').find('.supplierPurchaseTotalRmb').removeClass('hidden');
$supplierInfo.find('.supplierPurchaseTotal').removeClass('hidden');
$supplierInfo.find('.supplierPurchaseTotalRmb').removeClass('hidden');
} else {
// 否则隐藏供应商采购总价
$(event).closest('.supplier-card').find('.supplierPurchaseTotal').addClass('hidden');
$(event).closest('.supplier-card').find('.supplierPurchaseTotalRmb').addClass('hidden');}
$supplierInfo.find('.supplierPurchaseTotal').addClass('hidden');
$supplierInfo.find('.supplierPurchaseTotalRmb').addClass('hidden');
}
recalculateTotals(tableId); // 重新计算当前物料的合计
}
recalculateTotals(tableId); // 重新计算当前物料的合计
});
// 定义一个函数来重新计算当前物料的合计
// 初始化总计
purchasePlanChildList.forEach(function (material, index) {
recalculateTotals('materialCode-' + index);
});
});
// 新增函数:重新计算某物料的采购数量合计、不含税采购总价和含税采购总价
function recalculateTotals(tableId) {
var actualPurchaseTotal = 0;
var materialNoRmbTotal = 0;
var materialRmbTotal = 0;
var totalMaterialSum = 0;
var totalPurchaseSum = 0;
var totalRmbSum = 0;
var totalNoRmbSum = 0;
tableIdList.forEach(function(tableId) {
$('#' + '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());
//物料的供应商合计
totalMaterialSum += purchaseNum;
if (rmbPrice) {
totalPurchaseSum += purchaseNum * rmbPrice;
}
if (noRmbPrice) {
totalNoRmbSum += purchaseNum * noRmbPrice;
}
if (noRmbPrice) {
totalNoRmbSum += purchaseNum * noRmbPrice;
var $tableWrapper = $('#material-' + tableId);
var totalNoRmb = 0;
var totalRmb = 0;
var totalActualPurchase = 0;
var $suplierInfo = $tableWrapper.find('.supplier-card');
//获取所有物料表中供应商列表数据,实际采购数合计,不含税总价,含税采购总价
$suplierInfo.find('.supplier_card').each(function() {
let purchaseNum = parseFloat($(this).find('.actualPurchaseNum').val()) || 0;
let noRmbPrice = parseFloat($(this).find('.supplierMaterialNoRmb').text().trim()) || 0;
let rmbPrice = parseFloat($(this).find('.supplierMaterialRmb').text().trim()) || 0;
totalNoRmb += purchaseNum * noRmbPrice;
totalRmb += purchaseNum * rmbPrice;
totalActualPurchase = totalActualPurchase + purchaseNum;
});
//物料的实际采购数合计
$('#materialAmountSum_' + tableId).val(totalActualPurchase);
//物料的实际不含税采购总价:
$('#materialNoRmbSum_' + tableId).val(parseFloat(totalNoRmb));
//物料的实际含税总价:
$('#materialRmbSum_' + tableId).val(parseFloat(totalRmb));
// 采购物料合计
materialActualPurchaseSum();
}
function materialActualPurchaseSum(){
var totalNoRmb = 0;
var totalRmb = 0;
var totalActualPurchase = 0;
var materialAmount = 0;
tableIdList.forEach(function (material, index) {
var tableId = tableIdList[index];
var $tableWrapper = $('#material-' + tableId);
//采购合计 = 所有物料的采购数量合计
//采购不含税总价 = 所有物料的不含税总价合计
//采购含税总价 = 所有物料的含税总价合计
//查询物料表下吗整合的物料的实际采购数合计,物料的实际不含税采购总价,物料的实际含税总价
var supplierInfo = $tableWrapper.find('#supplierInfo_' + tableId );
let purchaseNum = parseInt(supplierInfo.find('.actualPurchaseTotalSum').val().trim()) || 0;
let noRmbPrice = parseFloat(supplierInfo.find('.actualPurchaseTotal').val().trim()) || 0;
let rmbPrice = parseFloat(supplierInfo.find('.actualPurchaseTotalTax').val().trim()) || 0;
if (purchaseNum > 0) {
materialAmount += 1;
}
$('#purchaseMaterialSum').val(isNaN(totalMaterialSum) ? '' : totalMaterialSum.toFixed(2));
$('#purchaseSum').val(isNaN(totalPurchaseSum) ? '' : totalPurchaseSum.toFixed(2));
$('#purchaseNoRmbSum').val(isNaN(totalNoRmbSum) ? '' : totalNoRmbSum.toFixed(2));
})
})
// 设置合计值,确保处理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));
totalActualPurchase += purchaseNum;
totalNoRmb += noRmbPrice;
totalRmb += rmbPrice;
});
//物料合计 = 物料实际采购数合计,不含税总价,含税采购总价不为null的情况可以合计物料,否则跳过
$("#purchaseMaterialSum").val(materialAmount);
//采购数量合计
$('#purchaseSum').val(totalActualPurchase);
//采购不含税总价
$('#purchaseNoRmbSum').val(totalNoRmb);
//采购含税总价
$('#purchaseRmbSum').val(totalRmb);
}
function tableSetup(element, tableId) {
var $totalSection = $(
'<div class="card">' +
@ -294,19 +346,19 @@
'<div class="form-row">' +
'<label for="actualPurchaseTotal" class="col-sm-4">实际采购数合计:</label>' +
'<div class="col-sm-8">' +
'<input type="number" name="materialAmountSum" class="form-control" id="materialNoRmbSum_' + tableId + '" readonly>' +
'<input type="number" name="materialAmountSum" class="form-control actualPurchaseTotalSum" id="materialAmountSum_' + tableId + '">' +
'</div>' +
'</div>' +
'<div class="form-row">' +
'<label for="actualPurchaseTotal" class="col-sm-4">不含税采购总价:</label>' +
'<div class="col-sm-8">' +
'<input type="number" name="materialNoRmbSum" class="form-control" id="materialNoRmbSum_' + tableId + '" readonly>' +
'<input type="number" name="materialNoRmbSum" class="form-control actualPurchaseTotal" id="materialNoRmbSum_' + tableId + '" ' +
'</div>' +
'</div>' +
'<div class="form-row">' +
'<label for="actualPurchaseTotalTax" class="col-sm-4">含税采购总价:</label>' +
'<div class="col-sm-8">' +
'<input type="number" name="materialRmbSum" class="form-control" id="materialRmbSum_' + tableId + '" readonly>' +
'<input type="number" name="materialRmbSum" class="form-control actualPurchaseTotalTax" id="materialRmbSum_' + tableId + '">' +
'</div>' +
'</div>' +
'</div>'+
@ -322,7 +374,7 @@
showColumns: false,
showToggle: false,
data: data,
height: 10,
height: 70,
columns: [
{checkbox: false},
{title: '料号', field: 'materialCode'},
@ -352,6 +404,7 @@
function submitHandler() {
if ($.validate.form()) {
var materialSum = 0;
var materialRealSum = 0;
var materialNoRmbSum = 0;
var materialRmbSum = 0;
//添加去除供应商编号数组
@ -369,28 +422,28 @@
$('.table-materialCode').each(function(index, tableElement) {
var tableId = tableIdList[index];
let materialObj = materialList[index];
var $tableWrapper = $('#material-' + tableId);
if (typeof materialObj === 'undefined') return;
$('#' + 'material-' + tableId).find('.suppplier_card').each(function(supplierIndex, supplierCard) {
var supplierCode = $(supplierCard).find('.supplierCode').text().trim();
var supplierName = $(supplierCard).find('.supplierName').text().trim();
var materialRealNum = parseInt($(supplierCard).find('.supplierMaterialNum' ).val(), 10) || 0;
var materialRealRmb = parseFloat($(supplierCard).find('.supplierMaterialRmb').text(), 10) || 0;
var materialRealNoRmb = parseFloat($(supplierCard).find('.supplierMaterialNoRmb').text(), 10) || 0;
var deliveryTime = $(supplierCard).find('.supplierDeliveryTime' ).val();
var purchasePlanCode = $(supplierCard).find('.supplierPurchasePlanCode').text().trim();
var correlationCode = $(supplierCard).find('.supplierCorrelationCode' ).text().trim();
var purchaseQuoteCode = $(supplierCard).find('.supplierPurchaseQuoteCode').text().trim();
var materialRealRmbSum = parseFloat(materialRealRmb) * parseFloat(materialRealNum);
var materialRealNoRmbSum = parseFloat(materialRealNoRmb) * parseFloat(materialRealNum);
if (materialRealNum > 0) {
materialSum += materialRealNum;
var $suplierInfo = $tableWrapper.find('.supplier-card');
$suplierInfo.find('.supplier_card').each(function(supplierIndex, supplierCard) {
var supplierCode = $(this).find('.supplierCode').text().trim();
var supplierName = $(this).find('.supplierName').text().trim();
var materialRealNum = parseInt($(this).find('.actualPurchaseNum' ).val()) || 0;
var materialRealRmb = parseFloat($(this).find('.supplierMaterialRmb').text()) || 0;
var materialRealNoRmb = parseFloat($(this).find('.supplierMaterialNoRmb').text()) || 0;
var deliveryTime = $(this).find('.supplierDeliveryTime' ).val();
var purchasePlanCode = $(this).find('.supplierPurchasePlanCode').text().trim();
var correlationCode = $(this).find('.supplierCorrelationCode' ).text().trim();
var purchaseQuoteCode = $(this).find('.supplierPurchaseQuoteCode').text().trim();
var materialRealRmbSum = parseFloat(materialRealRmb * materialRealNum);
var materialRealNoRmbSum = parseFloat(materialRealNoRmb * materialRealNum);
materialRealSum += materialRealNum;
materialNoRmbSum += materialRealNoRmbSum;
materialRmbSum += materialRealRmbSum;
if (supplierNumList.indexOf(supplierCode) === -1) {
supplierNumList.push(supplierCode);
purchaseOrder.supplierNum += 1;
}
}
var materialData = {
materialCode: materialObj.materialCode,
materialName: materialObj.materialName,
@ -419,11 +472,16 @@
purchaseOrder.purchaseOrderChildList.push(materialData);
});
});
// 获取采购物料合计,采购物料实际合计,采购物料实际非人民币合计,采购物料实际人民币合计
var purchaseAmount = parseFloat($('#purchaseMaterialSum').val());
var purchaseSum = parseFloat($('#purchaseSum').val());
var purchaseNoRmbSum = parseFloat($('#purchaseNoRmbSum').val());
var purchaseRmbSum = parseFloat($('#purchaseRmbSum').val());
// 将合计值附加到purchaseOrder对象
purchaseOrder.materialSum = materialSum;
purchaseOrder.materialNoRmbSum = materialNoRmbSum;
purchaseOrder.materialRmbSum = materialRmbSum;
purchaseOrder.materialAmount = purchaseAmount;
purchaseOrder.materialSum = purchaseSum;
purchaseOrder.materialNoRmbSum = purchaseNoRmbSum;
purchaseOrder.materialRmbSum = purchaseRmbSum;
purchaseOrder.supplierNum = supplierNumList.length;
// 发送数据到后端API
@ -431,78 +489,6 @@
}
}
//获取仓库相关信息Select2
//根据仓库ID查询仓库名称
$(function() {
// 初始化时默认加载仓库ID列表
loadWarehouseCodes();
// 监听仓库ID下拉框的变化
});
$('#stockNo').on('change', function() {
var selectedWarehouseCode = $(this).val(); // 获取选中的仓库ID
if (selectedWarehouseCode) {
// 发起Ajax请求获取仓库名称
$.ajax({
type: 'GET',
url: ctx +'stock/stockInfo/getStockNameByWarehouseCode/' + selectedWarehouseCode,
dataType: 'json', // 假设返回的数据格式是JSON
success: function(data) {
console.log(data);
// 将获取到的仓库名称填充到输入框
if(data.data == null){
// 如果返回的数据有问题,可以给出提示或处理
$.modal.alertWarning('未能获取到仓库名称!');
}
$('input[name="stockName"]').val(data.data.stockName);
$('input[name="stockAddress"]').val(data.data.stockAddr);
$('input[name="stockContact"]').val(data.data.stockManager);
$('input[name="stockPhone"]').val(data.data.stockManagerPhone);
},
error: function(jqXHR, textStatus, errorThrown) {
console.error('Error:', textStatus, errorThrown);
$.modal.alertWarning('查询仓库名称时发生错误!');
}
});
} else {
// 如果没有选择仓库ID,清空仓库名称输入框
$('input[name="warehouseName"]').val('');
}
});
// 加载仓库Id列表函数
function loadWarehouseCodes() {
var url = ctx + 'stock/stockInfo/getAllWarehouseCode';
$.ajax({
type: 'GET', // 请求类型
url: url, // 后端接口URL
dataType: 'json', // 预期服务器返回的数据类型
success: function(data) {
if (data && Array.isArray(data)) {
var selectElement = $('#stockNo'); // 获取仓库编号下拉框元素
// 清空下拉框现有选项
selectElement.empty();
// 添加默认选项(如果需要)编辑时不需要添加默认选项
// selectElement.append('<option value="">所有</option>');
// 遍历返回的数据,添加为下拉框的选项
$.each(data, function(index, item) {
// 仓库ID
selectElement.append('<option value="' + item.stockNO + '">' + item.stockNO + '</option>');
});
// $('#warehouseCode').val(stockNO);
} else {
$.modal.errMsg("数据为空");
}
}
});
}
$("input[name='deliveryTime']").datepicker({
language: 'zh-CN',
todayHighlight: true,
format: "yyyy-mm-dd",
autoClose: true,
});
</script>
</body>
</html>

2
ruoyi-admin/src/main/resources/templates/purchase/purchasePlan/purchasePlan.html

@ -153,8 +153,8 @@
]
});
};
var purchasePlanCodes = "";
function addPurchaseOrder(){
var purchasePlanCodes = "";
var selections = $("#bootstrap-table").bootstrapTable("getSelections");
if(selections.length === 0){
$.modal.alertWarning("请选择采购计划单");

Loading…
Cancel
Save