Browse Source

采购计划生成采购订单:获取物料料号采购报价,并放入采购计划的物料的供应商列表中转换为前端动态页面

dev
zhangsiqi 5 months ago
parent
commit
8bc05cca1e
  1. 19
      ruoyi-admin/src/main/java/com/ruoyi/purchase/controller/PurchasePlanController.java
  2. 22
      ruoyi-admin/src/main/java/com/ruoyi/purchase/domain/PurchasePlanChild.java
  3. 2
      ruoyi-admin/src/main/java/com/ruoyi/purchase/service/impl/PurchasePlanServiceImpl.java
  4. 79
      ruoyi-admin/src/main/resources/mapper/purchase/PurchasePlanChildMapper.xml
  5. 238
      ruoyi-admin/src/main/resources/templates/purchase/purchaseOrder/addPurchaseStorage.html
  6. 259
      ruoyi-admin/src/main/resources/templates/purchase/purchasePlan/addPurchaseOrder.html

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

@ -1,8 +1,7 @@
package com.ruoyi.purchase.controller;
import java.util.Arrays;
import java.util.List;
import java.util.Set;
import java.util.*;
import java.util.stream.Collectors;
import com.ruoyi.common.core.text.Convert;
import com.ruoyi.purchase.domain.PurchasePlan;
@ -27,6 +26,8 @@ import com.ruoyi.common.core.domain.AjaxResult;
import com.ruoyi.common.utils.poi.ExcelUtil;
import com.ruoyi.common.core.page.TableDataInfo;
import static com.alibaba.druid.sql.ast.TDDLHint.Type.Function;
/**
* 采购计划单Controller
*
@ -113,7 +114,7 @@ public class PurchasePlanController extends BaseController
return prefix + "/edit";
}
@GetMapping("/addPurchaseOrder/{purchasePlanCodes}")
public String purChaseOrder(@PathVariable("purchasePlanCodes") String purchasePlanCodes,ModelMap mmap){
public String addPurchaseOrder(@PathVariable("purchasePlanCodes") String purchasePlanCodes,ModelMap mmap){
//purchasePlanCodes去除重复数据,purchasePlanCodeArray作为数组类型去除
// 直接使用String的split方法分割字符串,然后转为Stream去重,最后再拼接回字符串
@ -123,11 +124,15 @@ public class PurchasePlanController extends BaseController
List<PurchasePlan> purchasePlanList = purchasePlanService.selectPurchasePlanByPlanCode(uniquePurchasePlanCodes);
//根据采购计划编号查询对应的采购报价数据
List<PurchasePlanChild> purchasePlanChildList = purchasePlanChildService.getPurchasePlanChildByPlanCodes(uniquePurchasePlanCodes);
//再根据采购计划编号分组查询对应的采购报价数据分组
for(PurchasePlanChild purchasePlanChild : purchasePlanChildList){
purchasePlanChild.setPurchaseSupplierList(purchasePlanChild.parseSupplierMaterialCombinations(purchasePlanChild.getSupplierCodes()));
String materialCode = purchasePlanChild.getMaterialCode();
List<PurchaseQuoteChild> purchaseQuoteChildList = purchaseQuoteChildService.selectQuoteChildByMaterialCode(materialCode);
purchasePlanChild.setPurchaseSupplierList(purchaseQuoteChildList);
}
//查询物料报价中供应商
//再根据采购计划编号分组查询对应的采购报价数据分组
//用stream流处理相同供应商\物料\
//将供应商信息解析成List<PurchaseSupplier>
mmap.put("purchasePlanList", purchasePlanList);
mmap.put("purchasePlanCodes", uniquePurchasePlanCodes);
mmap.put("purchasePlanChildList", purchasePlanChildList);

22
ruoyi-admin/src/main/java/com/ruoyi/purchase/domain/PurchasePlanChild.java

@ -91,6 +91,7 @@ public class PurchasePlanChild extends BaseEntity
/** 关联采购报价单编号 */
private String correlationCodes;
private String planCodes;
private List<PurchaseQuoteChild> purchaseSupplierList;
public String getSupplierCodes() {
@ -264,6 +265,14 @@ public class PurchasePlanChild extends BaseEntity
this.purchaseSupplierList = purchaseSupplierList;
}
public String getPlanCodes() {
return planCodes;
}
public void setPlanCodes(String planCodes) {
this.planCodes = planCodes;
}
public String getUseStatus()
{
return useStatus;
@ -282,7 +291,9 @@ public class PurchasePlanChild extends BaseEntity
this.delFlag = delFlag;
}
public String getDelFlag()
public String getDelFlag()
{
return delFlag;
}
@ -291,15 +302,12 @@ public class PurchasePlanChild extends BaseEntity
if (combinations == null || combinations.isEmpty()) {
return Collections.emptyList();
}
//materialCode|purchaseQuoteCode|supplierCode|supplierName|materialName|materialNoRmb|materialRmb
/* 1. 料号 | 2. 供应商报价编号 | 3. 供应商编号 | 4.供应商名称 | 5. 物料名称 | 6. 物料含税单价(RMB) | 7. 物料不含税单价(RMB) */
//materialCode|purchaseQuoteCode|supplierCode|supplierName|materialName|materialNoRmb|materialRmb|purchasePlanCode|correlationCode
/* 1. 料号 | 2. 供应商报价编号 | 3. 供应商编号 | 4.供应商名称 | 5. 物料名称 | 6. 物料含税单价(RMB) | 7. 物料不含税单价(RMB) | 8关联采购计划单号 | 9关联相关订单号 */
List<PurchaseQuoteChild> purchaseSupplierList = new ArrayList<>();
String[] split = combinations.split(",");
for (int i = 0; i < split.length; i++) {
String[] split1 = split[i].split("\\|");
if (split1.length != 7) {
continue;
}
PurchaseQuoteChild purchaseQuoteChild = new PurchaseQuoteChild();
purchaseQuoteChild.setMaterialCode(split1[0]);
purchaseQuoteChild.setPurchaseQuoteCode(split1[1]);
@ -308,6 +316,8 @@ public class PurchasePlanChild extends BaseEntity
purchaseQuoteChild.setMaterialName(split1[4]);
purchaseQuoteChild.setMaterialNoRmb(BigDecimal.valueOf(Float.parseFloat(split1[5])));
purchaseQuoteChild.setMaterialRmb(BigDecimal.valueOf(Float.parseFloat(split1[6])));
purchaseQuoteChild.setPurchasePlanCode(split1[7]);
purchaseQuoteChild.setCorrelationCode(split1[8]);
purchaseSupplierList.add(purchaseQuoteChild);
}
return purchaseSupplierList;

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

@ -20,6 +20,7 @@ import org.springframework.stereotype.Service;
import com.ruoyi.purchase.mapper.PurchasePlanMapper;
import com.ruoyi.purchase.service.IPurchasePlanService;
import com.ruoyi.common.core.text.Convert;
import org.springframework.transaction.annotation.Transactional;
/**
* 采购计划单Service业务层处理
@ -88,6 +89,7 @@ public class PurchasePlanServiceImpl implements IPurchasePlanService
* @return 结果
*/
@Override
@Transactional(rollbackFor = Exception.class)
public int updatePurchasePlan(PurchasePlan purchasePlan)
{
String loginName = ShiroUtils.getLoginName();

79
ruoyi-admin/src/main/resources/mapper/purchase/PurchasePlanChildMapper.xml

@ -20,7 +20,8 @@ PUBLIC "-//mybatis.org//DTD Mapper 3.0//EN"
<result property="materialNoRmb" column="material_noRmb" />
<result property="supplierCode" column="supplier_code" />
<result property="supplierCodes" column="supplier_codes" />
<result property="correlationCodes" column="correlation_codes" />
<result property="planCodes" column="purchase_plan_codes" />
<result property="correlationCodes" column="correlation_codes" />
<result property="supplierName" column="supplier_name" />
<result property="createBy" column="create_by" />
<result property="createTime" column="create_time" />
@ -31,6 +32,7 @@ PUBLIC "-//mybatis.org//DTD Mapper 3.0//EN"
<result property="auditStatus" column="audit_status" />
<result property="delFlag" column="del_flag" />
</resultMap>
<sql id="selectPurchasePlanChildVo">
select purchase_plan_child_id, purchase_plan_code, material_id,
material_code, material_name, material_type, process_method, brand,
@ -165,25 +167,60 @@ PUBLIC "-//mybatis.org//DTD Mapper 3.0//EN"
update purchase_plan_child set del_flag = '0' where purchase_plan_child_id = #{purchasePlanChildId}
</update>
<select id="getPurchasePlanChildByPlanCodes" parameterType="String" resultMap="PurchasePlanChildResult">
SELECT
GROUP_CONCAT(DISTINCT planOrder.correlation_code ORDER BY planOrder.correlation_code) AS correlation_codes,
GROUP_CONCAT(DISTINCT CONCAT(quote.material_code,'|',quote.purchase_quote_code , '|' ,quote.supplier_code,'|',
quote.supplier_name,'|',quote.material_name,'|',quote.material_noRmb,'|',quote.material_rmb)
ORDER BY quote.supplier_code) AS supplier_codes,
plan.material_code,
plan.material_name,
plan.material_type,
plan.process_method,
plan.brand,
plan.photoUrl,
plan.material_num
FROM
purchase_plan_child AS plan
LEFT JOIN purchase_plan AS planOrder ON plan.purchase_plan_code = planOrder.purchase_plan_code AND planOrder.del_flag = '0'
LEFT JOIN purchase_quote_child AS quote ON plan.material_code = quote.material_code AND quote.del_flag = '0'
WHERE
plan.purchase_plan_code IN ('CGJH20240415001', 'CGJH20240415002') AND plan.del_flag = '0'
GROUP BY
plan.material_code;
<!-- SELECT-->
<!-- GROUP_CONCAT(DISTINCT plan.purchase_plan_code ORDER BY plan.purchase_plan_code) AS purchase_plan_codes,-->
<!-- GROUP_CONCAT(DISTINCT planOrder.correlation_code ORDER BY planOrder.correlation_code) AS correlation_codes,-->
<!-- GROUP_CONCAT(DISTINCT CONCAT(quote.material_code,'|',quote.purchase_quote_code , '|' ,quote.supplier_code,'|',-->
<!-- quote.supplier_name,'|',quote.material_name,'|',quote.material_noRmb,'|',quote.material_rmb, '|',-->
<!-- plan.purchase_plan_code,'|',planOrder.correlation_code)-->
<!-- ORDER BY quote.supplier_code) AS supplier_codes,-->
<!-- plan.material_code,-->
<!-- plan.material_name,-->
<!-- plan.material_type,-->
<!-- plan.process_method,-->
<!-- plan.brand,-->
<!-- plan.photoUrl,-->
<!-- plan.material_num-->
<!-- FROM-->
<!-- purchase_plan_child AS plan-->
<!-- LEFT JOIN purchase_plan AS planOrder-->
<!-- ON plan.purchase_plan_code = planOrder.purchase_plan_code-->
<!-- AND planOrder.del_flag = '0' and planOrder.use_status = '1' and planOrder.audit_status = '1'-->
<!-- LEFT JOIN (-->
<!-- SELECT material_code, MAX(create_time) AS max_create_time-->
<!-- FROM purchase_quote_child-->
<!-- WHERE del_flag = '0'-->
<!-- GROUP BY material_code-->
<!-- ) AS quoteLatestTime-->
<!-- ON quoteLatestTime.material_code = plan.material_code-->
<!-- LEFT JOIN purchase_quote_child AS quote-->
<!-- ON quoteLatestTime.material_code = quote.material_code-->
<!-- AND quote.create_time = quoteLatestTime.max_create_time-->
<!-- AND quote.del_flag = '0'-->
<!-- WHERE-->
<!-- plan.purchase_plan_code IN-->
<!-- <foreach item="purchasePlanCode" collection="array" open="(" separator="," close=")">-->
<!-- #{purchasePlanCode}-->
<!-- </foreach>-->
<!-- AND plan.del_flag = '0'-->
<!-- GROUP BY-->
<!-- plan.material_code;-->
select
planChild.material_code,
planChild.material_name,
planChild.material_type,
planChild.process_method,
planChild.brand,
planChild.photoUrl,
sum(planChild.material_num) as material_num,
GROUP_CONCAT(DISTINCT plan.correlation_code ORDER BY plan.correlation_code) AS correlation_codes,
from purchase_plan_child as planChild
left join purchase_plan as plan
on plan.purchase_plan_code = planChild.purchase_plan_code
where plan.purchase_plan_code IN
<foreach item="purchasePlanCode" collection="array" open="(" separator="," close=")">
#{purchasePlanCode}
</foreach>
group by material_code
</select>
</mapper>

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

@ -3,13 +3,7 @@
<head>
<th:block th:include="include :: header('采购入库单详情')" />
<th:block th:include="include :: datetimepicker-css" />
<style>
.supplier-value span {
margin-right: 10px;
}
</style>
<style>.supplier-value span { margin-right: 10px;}</style>
</head>
<body class="white-bg">
<div class="wrapper wrapper-content animated fadeInRight ibox-content">
@ -52,174 +46,57 @@
<th:block th:include="include :: datetimepicker-js" />
<th:block th:include="include :: bootstrap-table-editable-js" />
<script th:inline="javascript">
var warehouseStorageCode = [[${warehouseStorageOrder.warehouseStorageCode}]]
var warehouseCode = [[${warehouseStorageOrder.warehouseCode}]]
var prefix = ctx + "purchase/purchaseStorage";
$("#form-purchaseStorage-detail").validate({
focusCleanup: true
});
var purchaseOrder = [[${purchaseOrder}]];
var purchaseOrderChildList = [[${purchaseOrderChildList}]];
$("#form-purchaseStorage-detail").validate({focusCleanup: true});
//生成的不同table的id集合
var tableDatas = [];
function submitHandler() {
const storageOrderData = $("#form-purchaseStorage-detail").serializeArray().reduce((obj, item) => {
obj[item.name] = item.value;
return obj;
}, {});
// 初始化一个数组用于存放所有表格的数据
let allMaterialDataList = [];
for(let i in tableDatas){
$('#' + tableDatas[i]).each(function() {
const tableData = $(this).bootstrapTable('getData');
console.log(JSON.stringify(tableData));
// 将表数据转换成与qualityReportData格式一致的数组
var materialDataList = tableData.map(function (item) {
// 根据实际字段名调整
return {
"supplierCode": item.supplierCode,
"materialNo": item.materialNo,
"materialName": item.materialName,
"materialType": item.materialType,
"materialPhotourl": item.materialPhotourl,
"materialDescribe": item.materialDescribe,
"materialBrand": item.materialBrand,
"materialUnit": item.materialUnit,
"materialProcessMethod": item.materialProcessMethod,
"notifyHasArrivedNum": item.notifyHasArrivedNum,
"actualHasArrivedNum": item.actualHasArrivedNum,
"temporaryHasQualifiedNum": item.temporaryHasQualifiedNum,
"hasStorageNum": item.hasStorageNum,
"notifyArriveNum": item.notifyArriveNum,
"actualArriveNum": item.actualArriveNum,
"temporaryQualifiedNum": item.temporaryQualifiedNum,
"temporaryRemark": item.temporaryRemark,
"temporaryReportUrl": item.temporaryReportUrl,
"storageNum": item.storageNum,
"storageLocation": item.storageLocation,
// ...其他字段
};
});
allMaterialDataList = allMaterialDataList.concat(materialDataList);
});
}
const combinedData = Object.assign({}, storageOrderData, {
warehouseStorageOrderDetailList: allMaterialDataList
});
// 合并表单数据和表格数据
// const combinedData = Object.assign({}, ...complaintNoticeData.array(item => ({ [item.name]: item.value })), ...materialData);
console.log(combinedData)
// 使用 JSON.stringify() 序列化数据
const jsonData = JSON.stringify(combinedData);
// 发送 AJAX 请求到后端接口
$.operate.saveJson(prefix + "/detail", jsonData);
}
$("input[name='arrivedTime']").datetimepicker({
format: "yyyy-mm-dd",
minView: "month",
autoclose: true
});
$("input[name='deliveryInspectionTime']").datetimepicker({
format: "yyyy-mm-dd",
minView: "month",
autoclose: true
});
$(function() {
// 假设qualityOrderCode已经定义或者可以通过某种方式获取到
var warehouseStorageCode = [[${warehouseStorageOrder.warehouseStorageCode}]]; // 这里需要实际赋值,比如从前端某个地方读取
$.getJSON(prefix + "/storagePurchaseDetailList?warehouseStorageCode=" + warehouseStorageCode, function(data) {
for (var supplierCode in data) {
if (data.hasOwnProperty(supplierCode)) {
var supplierData = data[supplierCode];
createTableForSupplier(supplierCode, supplierData);
}
for (var purchaseOrderChild in purchaseOrderChildList) {
if (data.hasOwnProperty(purchaseOrderChild)) {
var supplierData = data[purchaseOrderChild];
createTableForSupplier(purchaseOrderChild, supplierData);
}
});
}
});
function createTableForSupplier(supplierCode, supplierData) {
var tableId = 'bootstrap-table-' + supplierCode.replace(/[^a-z0-9]/gi, '_').toLowerCase();
tableDatas.push(tableId);
var $tableWrapper = $('<div class="table-responsive mt-3"></div>');
// 确保supplierData至少有一条记录,并从中提取供应商详细信息
var supplierInfo = supplierData.length > 0 ? supplierData[0] : {}; // 默认为空对象,以防数据不存在
// 构建含有额外供应商信息的标题字符串
var headerTitle ='供应商'+'</br>'+supplierCode + ' - ' + (supplierInfo.supplierName || 'N/A');
var $header = $('<h4>' + headerTitle + '</h4>');
var $table = $('<table id="' + tableId + '" class="table table-striped table-bordered"></table>');
$table.bootstrapTable({
data: supplierData,
columns: [{
checkbox: true
},
{
title: '供应商ID',
field: 'supplierCode',
visible: false
},
{
title: '料号',
field: 'materialNo'
}, {
title: '物料名称',
field: 'materialName'
},
{
title: '物料类型',
field: 'materialType',
},
{
title: '物料图片地址',
field: 'materialPhotourl',
},
{
title: '物料描述',
field: 'materialDescribe',
},
{
title: '物料品牌',
field: 'materialBrand',
},
{
title: '物料单位',
field: 'materialUnit',
},
{
title: '物料加工方式',
field: 'materialProcessMethod',
},
{
title: '通知已到货数',
field: 'notifyHasArrivedNum',
},
{
title: '已入库数',
field: 'hasStorageNum',
},
{
title: '通知到货数',
field: 'notifyArriveNum',
},
columns: [
{checkbox: true},
{title: '供应商ID',field: 'supplierCode',visible: false},
{title: '料号',field: 'materialNo'},
{title: '物料名称',field: 'materialName'},
{title: '物料类型',field: 'materialType',},
{title: '物料图片地址',field: 'materialPhotourl',},
{title: '物料描述',field: 'materialDescribe',},
{title: '物料品牌',field: 'materialBrand',},
{title: '物料单位',field: 'materialUnit',},
{title: '物料加工方式',field: 'materialProcessMethod',},
{title: '通知已到货数',field: 'notifyHasArrivedNum',},
{title: '已入库数',field: 'hasStorageNum',},
{title: '通知到货数',field: 'notifyArriveNum',},
]
});
$tableWrapper.append($header).append($table);
$('#tablesContainer').append($tableWrapper);
}
//根据仓库ID查询仓库名称
$(document).ready(function() {
// 初始化时默认加载仓库ID列表
@ -241,7 +118,7 @@
// 如果返回的数据有问题,可以给出提示或处理
$.modal.alertWarning('未能获取到仓库名称!');
}
$('input[name="warehouseName"]').val(data.data.stockname);
$('input[name="warehouseName"]').val(data.data.StockName);
},
error: function(jqXHR, textStatus, errorThrown) {
console.error('Error:', textStatus, errorThrown);
@ -255,7 +132,6 @@
});
});
// 加载仓库Id列表函数
function loadWarehouseCodes() {
var url = ctx + 'stock/stockInfo/getAllWarehouseCode';
@ -268,14 +144,11 @@
var selectElement = $('#warehouseCode'); // 获取仓库编号下拉框元素
// 清空下拉框现有选项
selectElement.empty();
// 添加默认选项(如果需要)编辑时不需要添加默认选项
// selectElement.append('<option value="">所有</option>');
// 遍历返回的数据,添加为下拉框的选项
$.each(data, function(index, item) {
// 仓库ID
selectElement.append('<option value="' + item.stockNO + '">' + item.stockNO + '</option>');
selectElement.append('<option value="' + item.StockNO + '">' + item.StockNO + '</option>');
});
// $('#warehouseCode').val(stockNO);
} else {
@ -284,7 +157,68 @@
}
});
}
function submitHandler() {
const storageOrderData = $("#form-purchaseStorage-detail").serializeArray().reduce((obj, item) => {
obj[item.name] = item.value;
return obj;
}, {});
// 初始化一个数组用于存放所有表格的数据
let allMaterialDataList = [];
for(let i in tableDatas){
$('#' + tableDatas[i]).each(function() {
const tableData = $(this).bootstrapTable('getData');
console.log(JSON.stringify(tableData));
// 将表数据转换成与qualityReportData格式一致的数组
var materialDataList = tableData.map(function (item) {
// 根据实际字段名调整
return {
"supplierCode": item.supplierCode,
"materialNo": item.materialNo,
"materialName": item.materialName,
"materialType": item.materialType,
"materialPhotourl": item.materialPhotourl,
"materialDescribe": item.materialDescribe,
"materialBrand": item.materialBrand,
"materialUnit": item.materialUnit,
"materialProcessMethod": item.materialProcessMethod,
"notifyHasArrivedNum": item.notifyHasArrivedNum,
"actualHasArrivedNum": item.actualHasArrivedNum,
"temporaryHasQualifiedNum": item.temporaryHasQualifiedNum,
"hasStorageNum": item.hasStorageNum,
"notifyArriveNum": item.notifyArriveNum,
"actualArriveNum": item.actualArriveNum,
"temporaryQualifiedNum": item.temporaryQualifiedNum,
"temporaryRemark": item.temporaryRemark,
"temporaryReportUrl": item.temporaryReportUrl,
"storageNum": item.storageNum,
"storageLocation": item.storageLocation,
// ...其他字段
};
});
allMaterialDataList = allMaterialDataList.concat(materialDataList);
});
}
const combinedData = Object.assign({}, storageOrderData, {warehouseStorageOrderDetailList: allMaterialDataList});
// 合并表单数据和表格数据
// const combinedData = Object.assign({}, ...complaintNoticeData.array(item => ({ [item.name]: item.value })), ...materialData);
console.log(combinedData)
// 使用 JSON.stringify() 序列化数据
const jsonData = JSON.stringify(combinedData);
// 发送 AJAX 请求到后端接口
$.operate.saveJson(prefix + "/detail", jsonData);
}
$("input[name='arrivedTime']").datetimepicker({
format: "yyyy-mm-dd",
minView: "month",
autoclose: true
});
$("input[name='deliveryInspectionTime']").datetimepicker({
format: "yyyy-mm-dd",
minView: "month",
autoclose: true
});
</script>
</body>
</html>

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

@ -9,7 +9,7 @@
<div class="col-xs-12">
<label class="col-sm-4 control-label">已选择采购计划:</label>
<div class="col-sm-7">
<input id="purchasePlanCodes" th:value="${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">
@ -19,33 +19,33 @@
<div class="container">
<div class="row"><h4 class="card-header">公司地址:</h4></div>
<div class="form-group">
<label for="inputWarehouseID" class="col-sm-2 col-form-label">仓库ID:</label>
<label for="stockNo" class="col-sm-2 col-form-label">仓库ID:</label>
<div class="col-sm-4">
<input type="text" class="form-control" id="inputWarehouseID" placeholder="请输入仓库ID">
<select class="form-control" name="stockNo" id="stockNo" ></select>
</div>
</div>
<div class="form-group">
<label for="inputWarehouseName" class="col-sm-2 col-form-label">仓库名称:</label>
<label for="stockName" class="col-sm-2 col-form-label">仓库名称:</label>
<div class="col-sm-4">
<input type="text" class="form-control" id="inputWarehouseName" placeholder="请输入仓库名称">
<input type="text" class="form-control" name="stockName" id="stockName">
</div>
</div>
<div class="form-group">
<label for="inputReceiver" class="col-sm-2 col-form-label">收货人:</label>
<label for="stockContact" class="col-sm-2 col-form-label">收货人:</label>
<div class="col-sm-4">
<input type="text" class="form-control" id="inputReceiver" placeholder="请输入收货人">
<input type="text" name="stockContact" class="form-control" id="stockContact" >
</div>
</div>
<div class="form-group">
<label for="inputPhone" class="col-sm-2 col-form-label">收货电话:</label>
<label for="stockPhone" class="col-sm-2 col-form-label">收货电话:</label>
<div class="col-sm-4">
<input type="text" class="form-control" id="inputPhone" placeholder="请输入收货电话">
<input type="text" name="stockPhone" class="form-control" id="stockPhone" placeholder="请输入收货电话">
</div>
</div>
<div class="form-group">
<label for="inputAddressDetails" class="col-sm-2 col-form-label">详细地址:</label>
<label for="stockAddress" class="col-sm-2 col-form-label">详细地址:</label>
<div class="col-sm-4">
<textarea class="form-control" id="inputAddressDetails"></textarea>
<textarea class="form-control" name="stockAddress" id="stockAddress"></textarea>
</div>
</div>
</div>
@ -89,6 +89,7 @@
$("#form-plan-purchaseOrder-add").validate({focusCleanup: true});
var purchasePlanChildList = [[${purchasePlanChildList}]];
var purchasePlanList = [[${purchasePlanList}]];
var purchasePlanCodes = [[${purchasePlanCodes}]];
var formId = "form-plan-purchaseOrder-add";
//根据物料物料数量添加物料分类表,自动生成类似的表单对象
//初始根据采购计划单,涉及到物料做分类表
@ -101,6 +102,7 @@
//获取
// 假设qualityOrderCode已经定义或者可以通过某种方式获取到
$(function() {
$("#purchasePlanCodes").val(purchasePlanCodes);
// 初始化表格
// 假设purchasePlanChildList已定义并包含了需要处理的数据
purchasePlanChildList.forEach(function (material, index) {
@ -109,57 +111,21 @@
tableIdList.push(tableId);
// 创建物料信息的容器
var $tableWrapper = $('<div id="material-' + tableId + '""></div>');
// 将整个物料信息容器添加到页面
$('#material').append($tableWrapper);
// 添加关联销售订单号信息
var $headerDiv =
$('<div class="row">' +
'<div class="col-xs-12">' +
'<div class="row">' +
'<h3>' +
'<span><strong>物料 ' + index + ': </strong> ' + '<strong>关联订单号: </strong></span>' + '<span class="correlationCodes" id="correlateion-' + tableId + ' ">' + material.correlationCodes + '</span>' +
'</div>' +
'</h3>' +
'<div class="col-sm-12">' +
'<table class="table-materialCode" id="' + materialTable + '">' + '<br />' +
'<table class="table-materialCode" id="' + materialTable + '">' + '<table/>' +
'</div>' +
'</div>' +
'</div>');
$tableWrapper.append($headerDiv);
// 创建表格的容器
// 循环处理每个供应商的信息
material.purchaseSupplierList.forEach(function (supplier, supplierIndex) {
var $supplierInfo = $('<div class="card mt-12 supplier-card" ></div>'); // 卡片样式容器,用于包裹每个供应商的信息
// 构建供应商信息头部
var $headerContent =
$('<div class="card-header" id = "supplier-' + tableId + '>' +
'<h3 class="card-title">' + '供应商 ' + supplierIndex + ': ' + '</h3>' +
'<p class="card-text ">' + '<span class="supplierCode"">' + supplier.supplierCode + '</span>' + '-' + '<span class="supplierName">' + supplier.supplierName + '</span>' + '-最新不含税采购价: ' + '<span class="supplierMaterialNoRmb">' + supplier.materialNoRmb + '</span>' + ' RMB ' + ' 最新含税采购价: ' + '<span class="supplierMaterialRmb">' + supplier.materialRmb + '</span> RMB </p>' +
'<div class="card-body">' +
'<div class="form-group">' +
'<label class="col-sm-3"> 实际采购数: </label>' +
'<div class ="col-sm-8">' +
'<input type="text" name="materialNum" class="form-control supplierMaterialNum" id="actualPurchaseNum_' + tableId + '">' +
'</div>' +
'</div>' +
'<div class="form-group">' +
'<label class="col-sm-3">计划交付时间:</label>' +
'<div class ="col-sm-8">' +
'<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>');
$supplierInfo.append($headerContent);
// 构建供应商信息下的输入表单
$supplierForm = $('<div class="card-body" id="card_body_' + tableId + '"></div>');
// 实际采购数输入框
// 其他表单项可以根据需要类似添加
$supplierInfo.append($supplierForm);
$tableWrapper.append($supplierInfo);
});
tableSetup($supplierForm, tableId);
// 将整个物料信息容器添加到页面
$('#material').append($tableWrapper);
var materialObj = {
purchasePlanCode: material.purchasePlanCode,
materialCode: material.materialCode,
@ -173,14 +139,97 @@
materialNum: material.materialNum,
};
var materialData = [materialObj]; // Bootstrap Table需要一个数组作为数据源
materialList.push(materialObj);
materialList.push(material);
tables(materialTable, materialData);
// 创建表格的容器
//如果物料下的供应商为空,则不需要添加供应商信息,并在容器中添加一个提示信息:暂无供应商信息,请先添加供应商信息。
const uniqueSuppliers = [];
if (material.purchaseSupplierList.size == 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) {
//如果供应商相同,则不需要再次添加供应商信息
$supplierInfo = $('<div class="card supplier-card" id="supplierInfo-' + tableId +'-'+ supplierIndex + '"></div>');
// 卡片样式容器,用于包裹每个供应商的信息
// 构建供应商信息头部
var $headerContent =
$('<div class="card-header" id = "supplier-' + tableId + '">' +
'<div class="row">' +
'<div class="crad-text">'+
'<h4>供应商 ' + supplierIndex + ':' + '</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.purchasePlanCodes + '</span>' +
'<span class="supplierCorrelationCode" hidden="hidden" >' + material.correlationCodes + '</span>' +
'<span class="supplierPurchaseQuoteCode" hidden="hidden" >' + supplier.purchaseQuoteCode + '</span>' +
'</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>' +
'</div>' +
'<div class="form-row">' +
'<label class="col-sm-2">计划交付时间: </label>' +
'<div class ="col-sm-4">' +
'<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>');
$tableWrapper.append($supplierInfo);
$supplierInfo.append($headerContent);
// 构建供应商信息下的输入表单
$supplierForm = $('<div class="card-body" id="card_body_' + tableId + '"></div>');
// 实际采购数输入框
// 其他表单项可以根据需要类似添加
$supplierInfo.append($supplierForm);
});
tableSetup($supplierInfo, tableId);
}
});
// 给实际采购数的输入框绑定事件处理器
$('.supplierMaterialNum').off('keyup').on('keyup', function() {
var tableId = $(this).closest('.table-materialCode').attr('id');
$('.supplierMaterialNum').off('keyup').on('keyup', function(event,element) {
console.log(event);
console.log(element);
var tableId = $(element).closest('.table-materialCode').attr('id');
if (event.keyCode === 13) {
// 获取当前供应商的采购数量
var purchaseNum = parseFloat($(event).val()) || 0;
// 获取当前供应商的采购价格
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);
if (rmbPrice) {
$(event).closest('.supplier-card').find('.supplierPurchaseTotalRmb').text(purchaseNum * rmbPrice);
}
if (purchaseNum > 0) {
// 如果采购数量大于0,则显示供应商采购总价
$(event).closest('.supplier-card').find('.supplierPurchaseTotal').removeClass('hidden');
$(event).closest('.supplier-card').find('.supplierPurchaseTotalRmb').removeClass('hidden');
} else {
// 否则隐藏供应商采购总价
$(event).closest('.supplier-card').find('.supplierPurchaseTotal').addClass('hidden');
$(event).closest('.supplier-card').find('.supplierPurchaseTotalRmb').addClass('hidden');}
}
recalculateTotals(tableId); // 重新计算当前物料的合计
calculateGlobalTotals(); // 然后重新计算整个订单的合计
});
});
// 新增函数:重新计算某物料的采购数量合计、不含税采购总价和含税采购总价
@ -225,27 +274,27 @@
}
function tableSetup(element, tableId) {
var $totalSection = $(
'<div class="card mt-8">' +
'<div class="card-body" class="supplierTotal_' + tableId + '">' +
'<div class="form-row">' +
'<label for="actualPurchaseTotal" class="col-sm-3">实际采购数合计:</label>' +
'<div class="col-sm-8">' +
'<input type="number" name="materialAmountSum" class="form-control" id="materialNoRmbSum_' + tableId + '" readonly>' +
'</div>' +
'</div>' +
'<div class="form-row">' +
'<label for="actualPurchaseTotal" class="col-sm-3">不含税采购总价:</label>' +
'<div class="col-sm-8">' +
'<input type="number" name="materialNoRmbSum" class="form-control" id="materialNoRmbSum_' + tableId + '" readonly>' +
'</div>' +
'</div>' +
'<div class="form-row">' +
'<label for="actualPurchaseTotalTax" class="col-sm-3">含税采购总价:</label>' +
'<div class="col-sm-8">' +
'<input type="number" name="materialRmbSum" class="form-control" id="materialRmbSum_' + tableId + '" readonly>' +
'</div>' +
'</div>' +
'</div>'+
'<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" id="materialNoRmbSum_' + tableId + '" readonly>' +
'</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>' +
'</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>' +
'</div>' +
'</div>' +
'</div>'+
'</div>');
element.append($totalSection);
}
@ -292,13 +341,14 @@
function submitHandler() {
if ($.validate.form()) {
var purchaseOrder = {
supplierNum: 0,
materialNum: 0,
materialNoRmbSum: 0,
materialRmbSum: 0,
purchaseOrderChildList: []
supplierNum: 0,materialNum: 0,materialNoRmbSum: 0,materialRmbSum: 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];
@ -306,7 +356,6 @@
if (typeof materialObj === 'undefined') return;
$('#' + 'material-' + tableId).find('.supplier-card').each(function(supplierIndex, supplierCard) {
var materialData = {
purchasePlanCode: materialObj.purchasePlanCode,
materialCode: materialObj.materialCode,
materialName: materialObj.materialName,
materialType: materialObj.materialType,
@ -319,9 +368,12 @@
materialNoRmb: parseFloat($(supplierCard).find('.supplierMaterialNoRmb').text().trim()),
materialRmb: parseFloat($(supplierCard).find('.supplierMaterialRmb').text().trim()),
materialNum: parseInt($(supplierCard).find('.supplierMaterialNum').val(), 10) || 0,
deliveryTime: $(supplierCard).find('.supplierDeliveryTime').val()
deliveryTime: $(supplierCard).find('.supplierDeliveryTime').val(),
purchasePlanCode:$(supplierCard).find('.supplierPurchasePlanCode').text().trim(),
correlationCode:$(supplierCard).find('.supplierCorrelationCode').text().trim(),
purchaseQuoteCode: $(supplierCard).find('.supplierPurchaseQuoteCode').text().trim(),
};
purchaseOrder.purchaseQuoteChildList.push(materialData);
purchaseOrder.purchaseOrderChildList.push(materialData);
});
});
@ -340,7 +392,7 @@
// 发送数据到后端API
$.ajax({
type: "POST",
url: prefix + "/add",
url: prefix + "/addPurchaseOrder",
data: JSON.stringify(purchaseOrder),
contentType: "application/json; charset=utf-8",
dataType: "json",
@ -360,6 +412,39 @@
// 如果需要在页面加载时初始化合计或重新绑定事件处理器,这部分应放在更合适的位置,不在此函数内
}
}
//获取仓库相关信息
function getWarehouseInfo() {
$("#inputWarehouseID").select2({
theme: "bootstrap",
allowClear: true,
placeholder: "请选择供应商",
ajax: {
url: ctx + "stock/stockInfo/list",
type: "post",
dataType: "json",
delay: 250,
processResults: function (res, params) {
var resultList = res.rows;
var options = [];
for (let i in resultList) {
var option = resultList[i];
option.id = resultList[i]["StockNo"];
option.text = resultList[i]["StockNo"];
option.title = resultList[i]["StockName"];
options.push(option);
}
return {results: options,}
},
escapeMarkup: function (markup) {return markup;},
}
})
$("#inputWarehouseID").on("select2:select", function (e) {
var data = e.params.data;
$("#inputWarehouseName").val(data.StockName);
$("#inputReceiver").val(data.stockmanager);
$("#inputAddressDetails").val(data.stockAddr);
});
}
</script>
</body>
</html>
Loading…
Cancel
Save