入库单添加运费费用项目逻辑
This commit is contained in:
		
							parent
							
								
									b1b094ec7c
								
							
						
					
					
						commit
						5f5f533ca7
					
				| 
						 | 
				
			
			@ -253,6 +253,7 @@ public class MaterialInbPurchaseApplyPlugin extends AbstractBillPlugIn implement
 | 
			
		|||
            this.getView().updateView("transoftaxamount");
 | 
			
		||||
            this.getView().updateView("totaloftaxamount");
 | 
			
		||||
            this.getModel().endInit();
 | 
			
		||||
            setNewExpenseSummary();
 | 
			
		||||
        } else if ("ftransamount".equals(key)) {
 | 
			
		||||
            // 入库单明细-运费
 | 
			
		||||
            EntryGrid entryGrid = (EntryGrid) this.getControl("entryentity");
 | 
			
		||||
| 
						 | 
				
			
			@ -277,6 +278,7 @@ public class MaterialInbPurchaseApplyPlugin extends AbstractBillPlugIn implement
 | 
			
		|||
            this.getView().updateView("transoftaxamount");
 | 
			
		||||
            this.getView().updateView("totaloftaxamount");
 | 
			
		||||
            this.getModel().endInit();
 | 
			
		||||
            setNewExpenseSummary();
 | 
			
		||||
        } else if ("oftaxamount".equals(key) || "taxprice".equals(key)) {
 | 
			
		||||
            //入库单明细-含税金额、入库单明细-入库含税单价
 | 
			
		||||
            boolean inputtaxprice = (boolean) this.getModel().getValue("inputtaxprice");//录入含税价
 | 
			
		||||
| 
						 | 
				
			
			@ -545,7 +547,14 @@ public class MaterialInbPurchaseApplyPlugin extends AbstractBillPlugIn implement
 | 
			
		|||
    private void setNewExpenseSummary() {
 | 
			
		||||
        DynamicObjectCollection entryEntityCollection = this.getModel().getDataEntity(true).getDynamicObjectCollection("entryentity");//入库单分录
 | 
			
		||||
        DynamicObjectCollection expenseSummaryCollection = this.getModel().getDataEntity(true).getDynamicObjectCollection("zcgj_expensesummary");//费用汇总分录
 | 
			
		||||
        expenseSummaryCollection.clear();
 | 
			
		||||
 | 
			
		||||
        // 查找现有的运费行,如果没有则创建新的
 | 
			
		||||
        DynamicObject freightLine = findOrCreateFreightLine(expenseSummaryCollection);
 | 
			
		||||
 | 
			
		||||
        // 清空费用汇总分录(保留运费行)
 | 
			
		||||
        clearNonFreightLines(expenseSummaryCollection);
 | 
			
		||||
 | 
			
		||||
        // 根据入库单分录创建费用行
 | 
			
		||||
        DynamicObjectType expenseSummaryType = expenseSummaryCollection.getDynamicObjectType();
 | 
			
		||||
        for (DynamicObject entryEntity : entryEntityCollection) {
 | 
			
		||||
            DynamicObject newExpenseSummaryEntity = new DynamicObject(expenseSummaryType);
 | 
			
		||||
| 
						 | 
				
			
			@ -572,10 +581,78 @@ public class MaterialInbPurchaseApplyPlugin extends AbstractBillPlugIn implement
 | 
			
		|||
 | 
			
		||||
            expenseSummaryCollection.add(newExpenseSummaryEntity);
 | 
			
		||||
        }
 | 
			
		||||
 | 
			
		||||
        // 更新运费行数据并确保其存在于集合中
 | 
			
		||||
        updateFreightLineData(freightLine);
 | 
			
		||||
        if (!expenseSummaryCollection.contains(freightLine)) {
 | 
			
		||||
            expenseSummaryCollection.add(freightLine);
 | 
			
		||||
        }
 | 
			
		||||
 | 
			
		||||
        mergeExpenseSummaryEntriesByExpenseItemAndRate(expenseSummaryCollection);
 | 
			
		||||
        this.getView().updateView("zcgj_expensesummary");//刷新分录
 | 
			
		||||
    }
 | 
			
		||||
 | 
			
		||||
 | 
			
		||||
    /**
 | 
			
		||||
     * 查找或创建运费行
 | 
			
		||||
     *
 | 
			
		||||
     * @param expenseSummaryCollection 费用汇总分录集合
 | 
			
		||||
     * @return 运费行对象
 | 
			
		||||
     */
 | 
			
		||||
    private DynamicObject findOrCreateFreightLine(DynamicObjectCollection expenseSummaryCollection) {
 | 
			
		||||
        // 查找现有的运费行
 | 
			
		||||
        for (DynamicObject line : expenseSummaryCollection) {
 | 
			
		||||
            if (Boolean.TRUE.equals(line.getBoolean("zcgj_isfreightline"))) {
 | 
			
		||||
                return line;
 | 
			
		||||
            }
 | 
			
		||||
        }
 | 
			
		||||
 | 
			
		||||
        // 如果没有找到,创建新的运费行
 | 
			
		||||
        DynamicObjectType expenseSummaryType = expenseSummaryCollection.getDynamicObjectType();
 | 
			
		||||
        DynamicObject freightLine = new DynamicObject(expenseSummaryType);
 | 
			
		||||
        freightLine.set("zcgj_isfreightline", true); // 标识为运费行
 | 
			
		||||
        return freightLine;
 | 
			
		||||
    }
 | 
			
		||||
 | 
			
		||||
    /**
 | 
			
		||||
     * 清除除运费行外的所有行
 | 
			
		||||
     *
 | 
			
		||||
     * @param expenseSummaryCollection 费用汇总分录集合
 | 
			
		||||
     */
 | 
			
		||||
    private void clearNonFreightLines(DynamicObjectCollection expenseSummaryCollection) {
 | 
			
		||||
        Iterator<DynamicObject> iterator = expenseSummaryCollection.iterator();
 | 
			
		||||
        while (iterator.hasNext()) {
 | 
			
		||||
            DynamicObject line = iterator.next();
 | 
			
		||||
            if (!Boolean.TRUE.equals(line.getBoolean("zcgj_isfreightline"))) {
 | 
			
		||||
                iterator.remove();
 | 
			
		||||
            }
 | 
			
		||||
        }
 | 
			
		||||
    }
 | 
			
		||||
 | 
			
		||||
    /**
 | 
			
		||||
     * 更新运费行数据
 | 
			
		||||
     *
 | 
			
		||||
     * @param freightLine 运费行对象
 | 
			
		||||
     */
 | 
			
		||||
    private void updateFreightLineData(DynamicObject freightLine) {
 | 
			
		||||
        freightLine.set("zcgj_pa_amount", getModel().getValue("transoftaxamount"));//价税合计-含税总运费
 | 
			
		||||
        freightLine.set("zcgj_amountnotax", getModel().getValue("transamount"));//不含税金额-总运费
 | 
			
		||||
        DynamicObject entryTaxRate = (DynamicObject) getModel().getValue("taxrate");
 | 
			
		||||
        if (entryTaxRate != null) {
 | 
			
		||||
            freightLine.set("zcgj_rateval", entryTaxRate.get("taxrate"));//税率(%)-运费税率
 | 
			
		||||
        }
 | 
			
		||||
        freightLine.set("zcgj_taxamt", getModel().getValue("transtaxamount"));//税额-运费总税额
 | 
			
		||||
 | 
			
		||||
        DynamicObject ecbd_resource = BusinessDataServiceHelper.loadSingle("ecbd_resource",
 | 
			
		||||
                "id,zcgj_expenseitem", new QFilter[]{new QFilter("number", QCP.equals, "ZCKS07")});//清单分类-固定运费
 | 
			
		||||
 | 
			
		||||
        if (ecbd_resource != null) {
 | 
			
		||||
            DynamicObject expenseItem = ecbd_resource.getDynamicObject("zcgj_expenseitem");//运费对应费用项目
 | 
			
		||||
            freightLine.set("zcgj_shippingcostitem", expenseItem);//运费费用项目
 | 
			
		||||
            freightLine.set("zcgj_expenseitem", expenseItem);//费用项目-对应费用项目
 | 
			
		||||
        }
 | 
			
		||||
    }
 | 
			
		||||
 | 
			
		||||
    /**
 | 
			
		||||
     * 按费用项目和税率组合合并费用汇总条目
 | 
			
		||||
     *
 | 
			
		||||
| 
						 | 
				
			
			
 | 
			
		|||
		Loading…
	
		Reference in New Issue