优化销售发票接口精度处理

This commit is contained in:
mzr 2025-05-04 14:27:05 +08:00
parent 666bac34d0
commit 938f0fbc1c
1 changed files with 39 additions and 53 deletions

View File

@ -328,62 +328,48 @@ public class IAPISaleInvMaitainImpl {
BigDecimal nexchangerate = getUFDouble_NullAsZero(value2.get("nexchangerate")).toBigDecimal(); BigDecimal nexchangerate = getUFDouble_NullAsZero(value2.get("nexchangerate")).toBigDecimal();
otherJson.put("nexchangerate", nexchangerate); otherJson.put("nexchangerate", nexchangerate);
// 输入参数从你的 item 获取各个字段 // 处理精度数量(2)单价(4位)和金额(2位)
/*BigDecimal nastnum = new BigDecimal(item.getString("nnum")); // 数量
nastnum = nastnum.setScale(4, RoundingMode.HALF_UP);
BigDecimal nqtorigtaxprice = new BigDecimal(item.getString("nqtorigtaxprice")); // 含税单价
nqtorigtaxprice = nqtorigtaxprice.setScale(4, RoundingMode.HALF_UP);
BigDecimal ntaxrate = new BigDecimal(item.getString("ntaxrate")).divide(new BigDecimal("100")); // 税率
ntaxrate = ntaxrate.setScale(4, RoundingMode.HALF_UP);
// 含税净价
BigDecimal norigtaxnetprice = nqtorigtaxprice;
// 1. 计算价税合计含税金额
BigDecimal norigtaxmny = nastnum.multiply(norigtaxnetprice).setScale(2, RoundingMode.HALF_UP);
// 2. 计算折扣额
BigDecimal discountAmount = nastnum.multiply(nqtorigtaxprice).subtract(norigtaxmny).setScale(4,
RoundingMode.HALF_UP);
// 3. 计算税额两种方法应税外加税和应税内含税
BigDecimal ntax = norigtaxmny.multiply(ntaxrate).divide(BigDecimal.ONE.add(ntaxrate), 2,
RoundingMode.HALF_UP); // 应税外加税
BigDecimal taxInclusiveInner = norigtaxmny.multiply(ntaxrate).setScale(4, RoundingMode.HALF_UP); // 应税内含税
// 4. 计算无税金额
BigDecimal norigmny = norigtaxmny.subtract(ntax).setScale(2, RoundingMode.HALF_UP);
// 4. 计算无税单价nqtorigprice = 无税金额 / 数量
BigDecimal nqtorigprice = norigmny.divide(nastnum, 4, RoundingMode.HALF_UP);
// 计税金额 = 无税金额
BigDecimal ncaltaxmny = norigmny;
// 主含税单价即含税单价
BigDecimal norigtaxprice = nqtorigtaxprice.setScale(4, RoundingMode.HALF_UP);
// 主无税净价即不含税单价
BigDecimal norignetprice = nqtorigprice;
// 本币(人民币)需要处理汇率金额保留两位小数单价保留4位小数
// 本币无税金额
BigDecimal nmny = norigmny.multiply(nexchangerate).setScale(2, RoundingMode.HALF_UP);
// 主本币无税净价
BigDecimal nnetprice = norignetprice.multiply(nexchangerate).setScale(4, RoundingMode.HALF_UP);
// 本币价税合计 价税合计*汇率
BigDecimal ntaxmny = norigtaxmny.multiply(nexchangerate).setScale(2, RoundingMode.HALF_UP);
// 税额
ntax = ntaxmny.subtract(nmny).setScale(2, RoundingMode.HALF_UP);*/
UFDouble nnum = new UFDouble(item.getString("nnum"));// Ö÷ÊýÁ¿ UFDouble nnum = new UFDouble(item.getString("nnum"));// Ö÷ÊýÁ¿
nnum = nnum.setScale(2, UFDouble.ROUND_HALF_UP);
UFDouble nqtorigprice = new UFDouble(item.getString("nqtorigprice"));// 无税单价
nqtorigprice = nqtorigprice.setScale(4, UFDouble.ROUND_HALF_UP);
UFDouble norigprice = new UFDouble(item.getString("norigprice"));// 主无税单价
norigprice = norigprice.setScale(4, UFDouble.ROUND_HALF_UP);
UFDouble norigmny = new UFDouble(item.getString("norigmny"));// 本币无税金额
norigmny = norigmny.setScale(2, UFDouble.ROUND_HALF_UP);
UFDouble nmny = new UFDouble(item.getString("nmny"));// 本币无税金额
nmny = nmny.setScale(2, UFDouble.ROUND_HALF_UP);
UFDouble norigtaxmny = new UFDouble(item.getString("norigtaxmny"));// 价税合计
norigtaxmny = norigtaxmny.setScale(2, UFDouble.ROUND_HALF_UP);
UFDouble norigtaxprice = new UFDouble(item.getString("norigtaxprice"));// 主含税单价
norigtaxprice = norigtaxprice.setScale(4, UFDouble.ROUND_HALF_UP);
UFDouble norignetprice = new UFDouble(item.getString("norignetprice"));// 主无税净价
norignetprice = norignetprice.setScale(4, UFDouble.ROUND_HALF_UP);
UFDouble nqtorigtaxprice = new UFDouble(item.getString("nqtorigtaxprice"));// 含税单价
nqtorigtaxprice = nqtorigtaxprice.setScale(4, UFDouble.ROUND_HALF_UP);
UFDouble ntax = new UFDouble(item.getString("ntax"));// 税额
ntax = ntax.setScale(2, UFDouble.ROUND_HALF_UP);
UFDouble norigtaxnetprice = new UFDouble(item.getString("norigtaxnetprice"));// 主含税净价
norigtaxnetprice = norigtaxnetprice.setScale(4, UFDouble.ROUND_HALF_UP);
UFDouble nnetprice = new UFDouble(item.getString("nnetprice"));// 主本币无税净价
nnetprice = nnetprice.setScale(4, UFDouble.ROUND_HALF_UP);
UFDouble ntaxmny = new UFDouble(item.getString("ntaxmny"));// 本币价税合计
ntaxmny = ntaxmny.setScale(2, UFDouble.ROUND_HALF_UP);
itemDetails.put("nastnum", nnum);// ÊýÁ¿ itemDetails.put("nastnum", nnum);// ÊýÁ¿
// itemDetails.put("nqtorigprice", nqtorigprice);// 无税单价 itemDetails.put("nqtorigprice", nqtorigprice);// 无税单价
// itemDetails.put("norigprice", nqtorigprice);// 主无税单价 itemDetails.put("norigprice", norigprice);// 主无税单价
// itemDetails.put("norigmny", norigmny);// 无税金额 itemDetails.put("norigmny", norigmny);// 无税金额
// itemDetails.put("nmny", nmny);// 本币无税金额 itemDetails.put("nmny", nmny);// 本币无税金额
// itemDetails.put("norigtaxmny", norigtaxmny);// 价税合计 itemDetails.put("norigtaxmny", norigtaxmny);// 价税合计
// itemDetails.put("norigtaxprice", norigtaxprice);// 主含税单价 itemDetails.put("norigtaxprice", norigtaxprice);// 主含税单价
// itemDetails.put("norignetprice", norignetprice);// 主无税净价 itemDetails.put("norignetprice", norignetprice);// 主无税净价
// itemDetails.put("nqtorigtaxprice", nqtorigtaxprice);// 含税单价 itemDetails.put("nqtorigtaxprice", nqtorigtaxprice);// 含税单价
// itemDetails.put("ntax", ntax);// 税额 itemDetails.put("ntax", ntax);// 税额
itemDetails.put("ncaltaxmny", new UFDouble(item.getString("nmny")));// 计税金额 itemDetails.put("ncaltaxmny", nmny);// 计税金额
// itemDetails.put("norigtaxnetprice", norigtaxnetprice);// 主含税净价 itemDetails.put("norigtaxnetprice", norigtaxnetprice);// 主含税净价
// itemDetails.put("nnetprice", nnetprice);// 主本币无税净价 itemDetails.put("nnetprice", nnetprice);// 主本币无税净价
// itemDetails.put("ntaxmny", ntaxmny);// 本币价税合计 itemDetails.put("ntaxmny", ntaxmny);// 本币价税合计
csaleinvoicebid.add(itemDetails); csaleinvoicebid.add(itemDetails);
} }