Browse Source

发票毛重净重列

java8
han\hanst 4 months ago
parent
commit
ab651c819c
  1. 2
      src/main/java/com/xujie/sys/common/utils/ExcelTemplate.java
  2. 1
      src/main/java/com/xujie/sys/modules/ecss/entity/EcssDeclarationHeaderData.java
  3. 42
      src/main/java/com/xujie/sys/modules/ecss/service/impl/CoDelServiceImpl.java
  4. 87
      src/main/resources/mapper/ecss/CoDelMapper.xml
  5. BIN
      src/main/resources/templates/declaration-all-showWeight-template-pdf.xlsx
  6. BIN
      src/main/resources/templates/declaration-all-showWeight-template.xlsx
  7. BIN
      src/main/resources/templates/declaration-invoice-showWeight-template.xlsx

2
src/main/java/com/xujie/sys/common/utils/ExcelTemplate.java

@ -308,7 +308,7 @@ public class ExcelTemplate {
style2.setWrapText(true);
c2.setCellStyle(style2);
if (priceRight) { //仅供发票excel使用第678是价格列居右
for (int i = 6; i < 9; i++) {
for (int i = 6; i < 11; i++) {
XSSFRow row = sheet.getRow(dtlRow);
if (row == null) {
continue;

1
src/main/java/com/xujie/sys/modules/ecss/entity/EcssDeclarationHeaderData.java

@ -63,4 +63,5 @@ public class EcssDeclarationHeaderData extends EcssDeclarationHeader{
private String declarationWeight;
private String destination;
private Boolean highPalletFlag;
private Boolean showWeight;
}

42
src/main/java/com/xujie/sys/modules/ecss/service/impl/CoDelServiceImpl.java

@ -1596,7 +1596,6 @@ public class CoDelServiceImpl implements CoDelService {
}
// 装箱数据
List<EcssCoDelPalletHeaderData> palletHeaderDataList = coDelMapper.searchEcssCoDelPalletHeaderData(notifyHeaderData);
List<Map> palletDetailList = coDelMapper.exportCoDelPalletDetail(notifyHeaderData);
Integer totalPlt = palletHeaderDataList.stream()
.map(EcssCoDelPalletHeaderData::getPalletQty)
.filter(Objects::nonNull) // 防止空指针
@ -1816,6 +1815,10 @@ public class CoDelServiceImpl implements CoDelService {
// RFID和RF不需要po,合同带印章declaration-invoice-seal-template.xlsx发票号不带章declaration-invoice-template.xlsx
String xlsx = notifyHeader.getBuNo().equals("04-MHM") || notifyHeader.getBuNo().equals("02-Hardtag")?
"templates/declaration-invoice2-template.xlsx":"templates/declaration-invoice-template.xlsx";
if (data.getShowWeight()!=null && data.getShowWeight()) {
xlsx = "templates/declaration-invoice-showWeight-template.xlsx";
}
ExcelTemplate template = ExcelTemplate.load(new ClassPathResource(xlsx).getInputStream());
extractedInvoice(data, template, notifyHeader);
try (XSSFWorkbook workbook = template.render(0)) {
@ -1973,6 +1976,10 @@ public class CoDelServiceImpl implements CoDelService {
// 硬标天线需要po(declaration-all2-template.xlsx)且多一个合同sheet
xlsx = "templates/declaration-all2-template.xlsx";
}
if (data.getShowWeight()!=null && data.getShowWeight()) {
xlsx = "templates/declaration-all-showWeight-template.xlsx";
}
XSSFWorkbook workbook = null;
try {
ExcelTemplate template = ExcelTemplate.load(new ClassPathResource(xlsx).getInputStream());
@ -2036,14 +2043,11 @@ public class CoDelServiceImpl implements CoDelService {
EcssCoDelNotifyHeaderData notifyHeader = coDelMapper.getEcssCoDelNotifyHeader(data.getSite(), data.getDelNo());
// RFID和RF和硬标天线使用的模版不一样
// RFID和RF如果勾选了合同导出需要带公章declaration-all-seal-template.xlsx
String xlsx;
if (notifyHeader.getBuNo().equals("03-RFID") || notifyHeader.getBuNo().equals("01-Label")) {
xlsx = "templates/declaration-all-template-pdf.xlsx";
} else {
// 硬标天线需要po(declaration-all2-template.xlsx)且多一个合同sheet
xlsx = "templates/declaration-all2-template.xlsx";
}
String xlsx = "templates/declaration-all-template-pdf.xlsx";
if (data.getShowWeight()!=null && data.getShowWeight()) {
xlsx = "templates/declaration-all-showWeight-template-pdf.xlsx";
}
XSSFWorkbook excelWorkbook = null;
try {
ExcelTemplate template = ExcelTemplate.load(new ClassPathResource(xlsx).getInputStream());
@ -2387,6 +2391,13 @@ public class CoDelServiceImpl implements CoDelService {
eorder.put("totalPrice", (((BigDecimal) eorder.get("qty")).multiply((BigDecimal) eorder.get("unitPrice"))).
setScale(2, RoundingMode.HALF_UP));
allPrice = allPrice.add(((BigDecimal) eorder.get("qty")).multiply((BigDecimal) eorder.get("unitPrice")));
if (data.getShowWeight()!=null && data.getShowWeight()) {
// 根据发货通知单明细查找装箱明细获取重量和净重保留2位小数
eorder.put("grossWeight", pm != null && pm.get("gross_weight") != null ?
new BigDecimal(pm.get("gross_weight").toString()).setScale(2, RoundingMode.HALF_UP) : "");
eorder.put("netWeight", pm != null && pm.get("net_weight") != null ?
new BigDecimal(pm.get("net_weight").toString()).setScale(2, RoundingMode.HALF_UP) : "");
}
}
// RFID需要的
if (notifyHeader.getBuNo().equals("01-Label") || notifyHeader.getBuNo().equals("03-RFID")) {
@ -2669,18 +2680,6 @@ public class CoDelServiceImpl implements CoDelService {
template.addVar("hs_code", stringInput(hsCodes));
Map<Object, Object> poNoMap = new HashMap<>();
BigDecimal ttlAmount = BigDecimal.ZERO;
BigDecimal grossWeight = BigDecimal.valueOf(0.0);
BigDecimal netWeight = BigDecimal.valueOf(0.0);
for (Map map : nodifyDetailList) {
String partNo = (String) map.get("part_no");
poNoMap.put(map.get("customerPO"), map.get("customerPO"));
ttlAmount = ttlAmount.add((BigDecimal) map.get("ttl_amount"));
Map pm = palletMap.get(partNo);
if (pm != null && !pm.isEmpty()) {
grossWeight = grossWeight.add((BigDecimal) pm.get("gross_weight"));
netWeight = netWeight.add((BigDecimal) pm.get("net_weight"));
}
}
StringBuilder ponos = new StringBuilder();
poNoMap.forEach((key, value) -> ponos.append(key).append("\n"));
template.addVar("poNo", ponos);
@ -2716,9 +2715,6 @@ public class CoDelServiceImpl implements CoDelService {
template.addVar("price", ttlAmount.setScale(2, RoundingMode.HALF_UP));
template.addVar("total_qty", totalQty);
//BigDecimal grossWeight = ecHeader.getGrossWeight() != null ? ecHeader.getGrossWeight() : BigDecimal.ZERO;
//template.addVar("grossWeight", (grossWeight.add(palletWeight)).setScale(2, RoundingMode.HALF_UP));
//template.addVar("netWeight", ecHeader.getNetWeight() != null ? ecHeader.getNetWeight().setScale(2, RoundingMode.HALF_UP) : "");
// 托盘重量=根据每个pallet的重量*数量累加
BigDecimal palletWeight = BigDecimal.ZERO;
for (EcssCoDelPalletHeaderData palletHeader : palletHeaderDataList) {

87
src/main/resources/mapper/ecss/CoDelMapper.xml

@ -843,27 +843,78 @@ left join ecss_CoDelNotifyHeader noHeader on a.site=noHeader.site and a.delNo=no
</select>
<select id="exportCoDelPalletDetail" resultType="java.util.Map">
select b.part_no,CONVERT(DECIMAL(20, 0),sum(b.qty)) as total_qty,
CONVERT(DECIMAL(20, 0),sum(DISTINCT a.box_qty)) as box_qty,
CONVERT(DECIMAL(20, 0),sum(b.rolls)) as rolls,
CONVERT(DECIMAL(20, 2),sum(a.net_weight)) as net_weight,
CONVERT(DECIMAL(20, 2),sum(a.gross_weight)) as gross_weight,
CONVERT(DECIMAL(20, 0),sum(b.rolls*b.qty)) as qty_per_carton
from ecss_CoDelBoxList a left join ecss_CoDelPalletDetail b
on a.site=b.site and a.bu_no=b.bu_no and a.delNo=b.delNo and a.item_no=b.seq_no
where a.site=#{site} and a.bu_no=#{buNo} and a.delNo=#{delNo} and b.site is not null GROUP BY b.part_no
-- 修复净重毛重重复计算问题:按数量比例分配箱子重量
WITH BoxDetail AS (
SELECT
b.part_no,
b.qty,
b.rolls,
a.box_qty,
a.net_weight,
a.gross_weight,
b.site,
b.bu_no,
b.delNo,
b.seq_no,
-- 计算该零件数量占该箱子总数量的比例
CASE
WHEN SUM(b.qty) OVER (PARTITION BY b.site, b.bu_no, b.delNo, b.seq_no) > 0
THEN b.qty * 1.0 / SUM(b.qty) OVER (PARTITION BY b.site, b.bu_no, b.delNo, b.seq_no)
ELSE 0
END as qtyRatio
FROM ecss_CoDelBoxList a
LEFT JOIN ecss_CoDelPalletDetail b ON a.site=b.site AND a.bu_no=b.bu_no AND a.delNo=b.delNo AND a.item_no=b.seq_no
WHERE a.site=#{site} AND a.bu_no=#{buNo} AND a.delNo=#{delNo} AND b.site IS NOT NULL
)
SELECT
part_no,
CONVERT(DECIMAL(20, 0), SUM(qty)) as total_qty,
CONVERT(DECIMAL(20, 0), SUM(DISTINCT box_qty)) as box_qty,
CONVERT(DECIMAL(20, 0), SUM(rolls)) as rolls,
-- 按数量比例分配净重和毛重
CONVERT(DECIMAL(20, 2), SUM(ISNULL(net_weight, 0) * qtyRatio)) as net_weight,
CONVERT(DECIMAL(20, 2), SUM(ISNULL(gross_weight, 0) * qtyRatio)) as gross_weight,
CONVERT(DECIMAL(20, 0), SUM(rolls * qty)) as qty_per_carton
FROM BoxDetail
GROUP BY part_no
</select>
<select id="getCoDelPalletDetailGroupByPn" resultType="java.util.Map">
select b.pn,CONVERT(DECIMAL(20, 0),sum(b.qty)) as total_qty,
CONVERT(DECIMAL(20, 0),sum(DISTINCT a.box_qty)) as box_qty,
CONVERT(DECIMAL(20, 0),sum(b.rolls)) as rolls,
CONVERT(DECIMAL(20, 2),sum(a.net_weight)) as net_weight,
CONVERT(DECIMAL(20, 2),sum(a.gross_weight)) as gross_weight,
CONVERT(DECIMAL(20, 0),sum(b.rolls*b.qty)) as qty_per_carton
from ecss_CoDelBoxList a left join ecss_CoDelPalletDetail b
on a.site=b.site and a.bu_no=b.bu_no and a.delNo=b.delNo and a.item_no=b.seq_no
where a.site=#{site} and a.bu_no=#{buNo} and a.delNo=#{delNo} GROUP BY b.pn
-- 修复净重毛重重复计算问题:按数量比例分配箱子重量
WITH BoxDetail AS (
SELECT
b.pn,
b.qty,
b.rolls,
a.box_qty,
a.net_weight,
a.gross_weight,
b.site,
b.bu_no,
b.delNo,
b.seq_no,
-- 计算该零件数量占该箱子总数量的比例
CASE
WHEN SUM(b.qty) OVER (PARTITION BY b.site, b.bu_no, b.delNo, b.seq_no) > 0
THEN b.qty * 1.0 / SUM(b.qty) OVER (PARTITION BY b.site, b.bu_no, b.delNo, b.seq_no)
ELSE 0
END as qtyRatio
FROM ecss_CoDelBoxList a
LEFT JOIN ecss_CoDelPalletDetail b ON a.site=b.site AND a.bu_no=b.bu_no AND a.delNo=b.delNo AND a.item_no=b.seq_no
WHERE a.site=#{site} AND a.bu_no=#{buNo} AND a.delNo=#{delNo}
)
SELECT
pn,
CONVERT(DECIMAL(20, 0), SUM(qty)) as total_qty,
CONVERT(DECIMAL(20, 0), SUM(DISTINCT box_qty)) as box_qty,
CONVERT(DECIMAL(20, 0), SUM(rolls)) as rolls,
-- 按数量比例分配净重和毛重
CONVERT(DECIMAL(20, 2), SUM(ISNULL(net_weight, 0) * qtyRatio)) as net_weight,
CONVERT(DECIMAL(20, 2), SUM(ISNULL(gross_weight, 0) * qtyRatio)) as gross_weight,
CONVERT(DECIMAL(20, 0), SUM(rolls * qty)) as qty_per_carton
FROM BoxDetail
WHERE pn IS NOT NULL
GROUP BY pn
</select>
<select id="exportCoDelBoxList" resultType="java.util.Map">

BIN
src/main/resources/templates/declaration-all-showWeight-template-pdf.xlsx

BIN
src/main/resources/templates/declaration-all-showWeight-template.xlsx

BIN
src/main/resources/templates/declaration-invoice-showWeight-template.xlsx

Loading…
Cancel
Save