This commit is contained in:
		
							parent
							
								
									350e7bdd65
								
							
						
					
					
						commit
						1aef4df699
					
				| 
						 | 
				
			
			@ -65,6 +65,7 @@ public class MaterialInbPurchaseApplyPlugin extends AbstractBillPlugIn implement
 | 
			
		|||
        zcgj_applidepart.addBeforeF7SelectListener(this);
 | 
			
		||||
        this.addItemClickListeners("advcontoolbarap");//入库单明细工具栏
 | 
			
		||||
        this.addItemClickListeners("zcgj_entrytoolbar111");//采购申请分录工具栏
 | 
			
		||||
        this.addItemClickListeners("zcgj_subentrytoolbar");//合同进项发票信息分录工具栏
 | 
			
		||||
        EntryGrid entryGrid = this.getView().getControl("zcgj_purchaseapplyentry");//采购申请分录-采购申请
 | 
			
		||||
        if (entryGrid != null) {
 | 
			
		||||
            entryGrid.addHyperClickListener(this);
 | 
			
		||||
| 
						 | 
				
			
			@ -98,8 +99,8 @@ public class MaterialInbPurchaseApplyPlugin extends AbstractBillPlugIn implement
 | 
			
		|||
    public void itemClick(ItemClickEvent evt) {
 | 
			
		||||
        super.itemClick(evt);
 | 
			
		||||
        String itemKey = evt.getItemKey();
 | 
			
		||||
        if (itemKey.equals("delentry")) {
 | 
			
		||||
            //入库单明细-删行
 | 
			
		||||
        if (itemKey.equals("delentry") || itemKey.equals("zcgj_subremoveline")) {
 | 
			
		||||
            //入库单明细-删行,合同进项信息发票分录-删行
 | 
			
		||||
            setNewExpenseSummary();
 | 
			
		||||
        }
 | 
			
		||||
    }
 | 
			
		||||
| 
						 | 
				
			
			@ -334,6 +335,7 @@ public class MaterialInbPurchaseApplyPlugin extends AbstractBillPlugIn implement
 | 
			
		|||
            } else {
 | 
			
		||||
                this.getModel().setValue("zcgj_freight_invoice", false);//运费发票
 | 
			
		||||
            }
 | 
			
		||||
            setNewExpenseSummary();
 | 
			
		||||
        } else if ("zcgj_yssupplier".equals(key)) {
 | 
			
		||||
            //运输单位
 | 
			
		||||
            ChangeData[] changeSet = e.getChangeSet();
 | 
			
		||||
| 
						 | 
				
			
			@ -369,6 +371,7 @@ public class MaterialInbPurchaseApplyPlugin extends AbstractBillPlugIn implement
 | 
			
		|||
                    }
 | 
			
		||||
                }
 | 
			
		||||
            }
 | 
			
		||||
            setNewExpenseSummary();
 | 
			
		||||
        }
 | 
			
		||||
    }
 | 
			
		||||
 | 
			
		||||
| 
						 | 
				
			
			@ -589,10 +592,119 @@ public class MaterialInbPurchaseApplyPlugin extends AbstractBillPlugIn implement
 | 
			
		|||
            expenseSummaryCollection.add(freightLine);
 | 
			
		||||
        }
 | 
			
		||||
 | 
			
		||||
        // 处理发票号码汇总逻辑
 | 
			
		||||
        processInvoiceNumbers(expenseSummaryCollection);
 | 
			
		||||
 | 
			
		||||
        mergeExpenseSummaryEntriesByExpenseItemAndRate(expenseSummaryCollection);
 | 
			
		||||
        this.getView().updateView("zcgj_expensesummary");//刷新分录
 | 
			
		||||
    }
 | 
			
		||||
 | 
			
		||||
    /**
 | 
			
		||||
     * 处理发票号码汇总逻辑
 | 
			
		||||
     *
 | 
			
		||||
     * @param expenseSummaryCollection 费用汇总分录集合
 | 
			
		||||
     */
 | 
			
		||||
    private void processInvoiceNumbers(DynamicObjectCollection expenseSummaryCollection) {
 | 
			
		||||
        DynamicObjectCollection zcgj_entryentityCollection = this.getModel().getDataEntity(true).getDynamicObjectCollection("zcgj_entryentity");//合同进项发票信息分录
 | 
			
		||||
 | 
			
		||||
        // 存储运费和非运费发票号码
 | 
			
		||||
        List<String> freightInvoiceNumbers = new ArrayList<>();
 | 
			
		||||
        List<String> nonFreightInvoiceNumbers = new ArrayList<>();
 | 
			
		||||
 | 
			
		||||
        // 存储发票类型信息,用于判断是否为专票
 | 
			
		||||
        Map<String, DynamicObject> invoiceTypeMap = new HashMap<>(); // 发票号码 -> 发票对象
 | 
			
		||||
 | 
			
		||||
        // 遍历合同进项发票信息分录,分类处理运费和非运费发票
 | 
			
		||||
        for (DynamicObject entryEntity : zcgj_entryentityCollection) {
 | 
			
		||||
            DynamicObject invoice = entryEntity.getDynamicObject("zcgj_invoice"); // 发票号码
 | 
			
		||||
            if (invoice == null) continue;
 | 
			
		||||
 | 
			
		||||
            String invoiceNumber = invoice.getString("invoiceno"); // 获取发票编号
 | 
			
		||||
            if (invoiceNumber == null || invoiceNumber.isEmpty()) continue;
 | 
			
		||||
 | 
			
		||||
            Boolean isFreightInvoice = entryEntity.getBoolean("zcgj_freight_invoice"); // 是否是运费发票
 | 
			
		||||
 | 
			
		||||
            if (Boolean.TRUE.equals(isFreightInvoice)) {
 | 
			
		||||
                // 运费发票
 | 
			
		||||
                freightInvoiceNumbers.add(invoiceNumber);
 | 
			
		||||
            } else {
 | 
			
		||||
                // 非运费发票
 | 
			
		||||
                nonFreightInvoiceNumbers.add(invoiceNumber);
 | 
			
		||||
            }
 | 
			
		||||
 | 
			
		||||
            // 保存发票类型信息
 | 
			
		||||
            invoiceTypeMap.put(invoiceNumber, invoice);
 | 
			
		||||
        }
 | 
			
		||||
 | 
			
		||||
        // 更新运费行的发票号码和专票/抵扣字段
 | 
			
		||||
        for (DynamicObject line : expenseSummaryCollection) {
 | 
			
		||||
            if (Boolean.TRUE.equals(line.getBoolean("zcgj_isfreightline"))) {
 | 
			
		||||
                // 运费行 - 设置运费发票号码
 | 
			
		||||
                if (!freightInvoiceNumbers.isEmpty()) {
 | 
			
		||||
                    String invoiceNumbersStr = String.join(",", freightInvoiceNumbers);
 | 
			
		||||
                    line.set("zcgj_invoicenoentry", invoiceNumbersStr);
 | 
			
		||||
 | 
			
		||||
                    // 设置专票和抵扣字段
 | 
			
		||||
                    boolean isSpecialInvoice = checkIfSpecialInvoice(freightInvoiceNumbers, invoiceTypeMap);
 | 
			
		||||
                    line.set("zcgj_isspecialinvoice", isSpecialInvoice);
 | 
			
		||||
                    line.set("zcgj_offset", isSpecialInvoice);
 | 
			
		||||
                } else {
 | 
			
		||||
                    line.set("zcgj_invoicenoentry", null);
 | 
			
		||||
                    line.set("zcgj_isspecialinvoice", false);
 | 
			
		||||
                    line.set("zcgj_offset", false);
 | 
			
		||||
                }
 | 
			
		||||
                break;
 | 
			
		||||
            }
 | 
			
		||||
        }
 | 
			
		||||
 | 
			
		||||
        // 更新所有非运费行的发票号码和专票/抵扣字段
 | 
			
		||||
        for (DynamicObject line : expenseSummaryCollection) {
 | 
			
		||||
            if (Boolean.TRUE.equals(line.getBoolean("zcgj_isfreightline"))) {
 | 
			
		||||
                continue; // 跳过运费行
 | 
			
		||||
            }
 | 
			
		||||
 | 
			
		||||
            // 非运费行 - 设置非运费发票号码
 | 
			
		||||
            if (!nonFreightInvoiceNumbers.isEmpty()) {
 | 
			
		||||
                String invoiceNumbersStr = String.join(",", nonFreightInvoiceNumbers);
 | 
			
		||||
                line.set("zcgj_invoicenoentry", invoiceNumbersStr);
 | 
			
		||||
 | 
			
		||||
                // 设置专票和抵扣字段
 | 
			
		||||
                boolean isSpecialInvoice = checkIfSpecialInvoice(nonFreightInvoiceNumbers, invoiceTypeMap);
 | 
			
		||||
                line.set("zcgj_isspecialinvoice", isSpecialInvoice);
 | 
			
		||||
                line.set("zcgj_offset", isSpecialInvoice);
 | 
			
		||||
            } else {
 | 
			
		||||
                line.set("zcgj_invoicenoentry", null);
 | 
			
		||||
                line.set("zcgj_isspecialinvoice", false);
 | 
			
		||||
                line.set("zcgj_offset", false);
 | 
			
		||||
            }
 | 
			
		||||
        }
 | 
			
		||||
    }
 | 
			
		||||
 | 
			
		||||
    /**
 | 
			
		||||
     * 检查发票列表中是否包含专票类型的发票
 | 
			
		||||
     *
 | 
			
		||||
     * @param invoiceNumbers 发票号码列表
 | 
			
		||||
     * @param invoiceTypeMap 发票号码到发票对象的映射
 | 
			
		||||
     * @return 是否包含专票
 | 
			
		||||
     */
 | 
			
		||||
    private boolean checkIfSpecialInvoice(List<String> invoiceNumbers, Map<String, DynamicObject> invoiceTypeMap) {
 | 
			
		||||
        for (String invoiceNumber : invoiceNumbers) {
 | 
			
		||||
            DynamicObject invoice = invoiceTypeMap.get(invoiceNumber);
 | 
			
		||||
            if (invoice != null) {
 | 
			
		||||
                DynamicObject invoiceType = invoice.getDynamicObject("invoicetypeid"); // 发票类型字段
 | 
			
		||||
                if (invoiceType != null) {
 | 
			
		||||
                    String invoiceTypeName = invoiceType.getString("name"); // 发票类型名称
 | 
			
		||||
                    // 当发票类型为"数电发票(普通发票)"或"电子发票专票"时,认为是专票
 | 
			
		||||
                    if ("数电发票(普通发票)".equals(invoiceTypeName) || "电子发票专票".equals(invoiceTypeName)) {
 | 
			
		||||
                        return true;
 | 
			
		||||
                    }
 | 
			
		||||
                }
 | 
			
		||||
            }
 | 
			
		||||
        }
 | 
			
		||||
        return false;
 | 
			
		||||
    }
 | 
			
		||||
 | 
			
		||||
 | 
			
		||||
 | 
			
		||||
    /**
 | 
			
		||||
     * 查找或创建运费行
 | 
			
		||||
| 
						 | 
				
			
			
 | 
			
		|||
		Loading…
	
		Reference in New Issue