|
|
@@ -25,7 +25,10 @@ import java.sql.SQLException;
|
|
|
import java.text.SimpleDateFormat;
|
|
|
import java.util.*;
|
|
|
import java.util.stream.Collectors;
|
|
|
-
|
|
|
+import java.math.BigDecimal;
|
|
|
+import java.math.RoundingMode;
|
|
|
+import java.util.HashMap;
|
|
|
+import java.util.Map;
|
|
|
@Controller
|
|
|
public class ivtOrderController {
|
|
|
/**
|
|
|
@@ -634,6 +637,16 @@ public class ivtOrderController {
|
|
|
conn.setAutoCommit(false);
|
|
|
System.out.println("接收到的costIds参数: " + costIds);
|
|
|
|
|
|
+// ========== 新增:初始化TAX_CATEGORY_ID与税率的映射关系 ==========
|
|
|
+ Map<String, BigDecimal> taxRateMap = new HashMap<>();
|
|
|
+ taxRateMap.put("597", new BigDecimal("0.00")); // 增值税-0
|
|
|
+ taxRateMap.put("598", new BigDecimal("0.01")); // 增值税-1
|
|
|
+ taxRateMap.put("599", new BigDecimal("0.03")); // 增值税-3
|
|
|
+ taxRateMap.put("10095", new BigDecimal("0.05")); // 增值税-5
|
|
|
+ taxRateMap.put("10096", new BigDecimal("0.06")); // 增值税-6
|
|
|
+ taxRateMap.put("10097", new BigDecimal("0.09")); // 增值税-9
|
|
|
+ taxRateMap.put("14138", new BigDecimal("0.13")); // 增值税-13
|
|
|
+
|
|
|
String[] costIdArr = costIds.split(",");
|
|
|
String sql = "SELECT * FROM BO_EU_DNCTT_CONTRACT_COST WHERE ID IN(";
|
|
|
for (int i = 0; i < costIdArr.length; i++) {
|
|
|
@@ -708,7 +721,34 @@ public class ivtOrderController {
|
|
|
for (RowMap cost : costList) {
|
|
|
BO purchaseOrderProduct = new BO();
|
|
|
purchaseOrderProduct.setBindId(processInstance.getId());
|
|
|
+ String unitCostStr = cost.getString("UNIT_COST");
|
|
|
+ String taxCategoryId = cost.getString("TAX_CATEGORY_ID");
|
|
|
+ int purchaseQuantity = cost.getInt("PURCHASE_QUANTITY");
|
|
|
+
|
|
|
+// 2. 参数校验
|
|
|
+ if (StringUtils.isBlank(unitCostStr) || StringUtils.isBlank(taxCategoryId) || purchaseQuantity <= 0) {
|
|
|
+ System.err.println("无效计算参数:UNIT_COST=" + unitCostStr + ",TAX_CATEGORY_ID=" + taxCategoryId + ",PURCHASE_QUANTITY=" + purchaseQuantity);
|
|
|
+ throw new RuntimeException("计算不含税金额失败:参数无效");
|
|
|
+ }
|
|
|
+
|
|
|
+// 3. 从映射表获取税率
|
|
|
+ BigDecimal taxRate = taxRateMap.get(taxCategoryId);
|
|
|
+ if (taxRate == null) {
|
|
|
+ System.err.println("未知TAX_CATEGORY_ID:" + taxCategoryId);
|
|
|
+ throw new RuntimeException("计算不含税金额失败:未知税率ID");
|
|
|
+ }
|
|
|
|
|
|
+// 4. 计算不含税单价(含税单价 ÷ (1 + 税率),保留2位小数)
|
|
|
+ BigDecimal unitCost = new BigDecimal(unitCostStr);
|
|
|
+ BigDecimal unitCostNotax = unitCost.divide(
|
|
|
+ BigDecimal.ONE.add(taxRate),
|
|
|
+ 2,
|
|
|
+ RoundingMode.HALF_UP
|
|
|
+ );
|
|
|
+
|
|
|
+// 5. 计算不含税总价(不含税单价 × 采购数量,保留2位小数)
|
|
|
+ BigDecimal costTotalNotax = unitCostNotax.multiply(new BigDecimal(purchaseQuantity))
|
|
|
+ .setScale(2, RoundingMode.HALF_UP);
|
|
|
purchaseOrderProduct.set("PURCHASE_ACCOUNT_ID", cost.getString("ACCOUNT_ID"));
|
|
|
purchaseOrderProduct.set("NAME", cost.getString("NAME"));
|
|
|
purchaseOrderProduct.set("PRODUCT_ID", cost.getString("PRODUCT_ID"));
|
|
|
@@ -731,6 +771,8 @@ public class ivtOrderController {
|
|
|
purchaseOrderProduct.set("CONTRACT_COST_ID", cost.getString("ID"));
|
|
|
purchaseOrderProduct.set("CONTRACT_SERVICE_ID", cost.getString("SERVICE_ID"));
|
|
|
purchaseOrderProduct.set("ORDER_ID", purchaseOrder.getId());
|
|
|
+ purchaseOrderProduct.set("UNIT_COST_NOTAX", unitCostNotax);
|
|
|
+ purchaseOrderProduct.set("COST_TOTAL_NOTAX", costTotalNotax);
|
|
|
|
|
|
SDK.getBOAPI().createDataBO("BO_EU_DNIVT_ORDER_PRODUCT", purchaseOrderProduct, uc, conn);
|
|
|
System.out.println("采购项创建成功,关联采购单ID: " + purchaseOrder.getId());
|