采购订单明细计算逻辑标品逻辑去除
This commit is contained in:
		
							parent
							
								
									dd302c682d
								
							
						
					
					
						commit
						1b725ff2fb
					
				| 
						 | 
					@ -0,0 +1,122 @@
 | 
				
			||||||
 | 
					package shkd.repc.repe.formplugin;
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					import kd.bos.dataentity.entity.DynamicObject;
 | 
				
			||||||
 | 
					import kd.bos.dataentity.entity.DynamicObjectCollection;
 | 
				
			||||||
 | 
					import kd.bos.dataentity.resource.ResManager;
 | 
				
			||||||
 | 
					import kd.bos.entity.datamodel.events.PropertyChangedArgs;
 | 
				
			||||||
 | 
					import kd.bos.orm.query.QFilter;
 | 
				
			||||||
 | 
					import kd.bos.servicehelper.BusinessDataServiceHelper;
 | 
				
			||||||
 | 
					import kd.repc.repe.formplugin.order.OrderFormEdit;
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					import java.math.BigDecimal;
 | 
				
			||||||
 | 
					import java.util.ArrayList;
 | 
				
			||||||
 | 
					import java.util.List;
 | 
				
			||||||
 | 
					import java.util.Map;
 | 
				
			||||||
 | 
					import java.util.stream.Collectors;
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					public class OrderFormEditExt extends OrderFormEdit {
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					    @Override
 | 
				
			||||||
 | 
					    protected void calculatePrice(int rowIndex, String fieldKey, PropertyChangedArgs e) {
 | 
				
			||||||
 | 
					        DynamicObject orderForm = this.getModel().getDataEntity(true);
 | 
				
			||||||
 | 
					        DynamicObjectCollection orderformEntryColl = orderForm.getDynamicObjectCollection("orderformentry");
 | 
				
			||||||
 | 
					        DynamicObject orderFormEntry = (DynamicObject)orderformEntryColl.get(rowIndex);
 | 
				
			||||||
 | 
					        DynamicObject material = orderFormEntry.getDynamicObject("material");
 | 
				
			||||||
 | 
					        if (material != null) {
 | 
				
			||||||
 | 
					            BigDecimal orderCount = orderFormEntry.getBigDecimal("ordercount");
 | 
				
			||||||
 | 
					            BigDecimal unitPrice;
 | 
				
			||||||
 | 
					            BigDecimal transportPrice;
 | 
				
			||||||
 | 
					            BigDecimal installPrice;
 | 
				
			||||||
 | 
					            if (fieldKey.equals("ordercount") && this.getNpFlag(orderForm)) {
 | 
				
			||||||
 | 
					                unitPrice = this.getContractOrderCount(orderForm, material.getPkValue());
 | 
				
			||||||
 | 
					                transportPrice = ((DynamicObject)orderForm.getDynamicObjectCollection("orderformentry").get(rowIndex)).getBigDecimal("contractnum");
 | 
				
			||||||
 | 
					                installPrice = transportPrice.subtract(unitPrice);
 | 
				
			||||||
 | 
					                if (orderCount.compareTo(installPrice) > 0) {
 | 
				
			||||||
 | 
					                    this.getView().showTipNotification(ResManager.loadKDString("本次订货数量只可填≤合同剩余数量的值", "OrderFormEdit_25", "repc-repe-formplugin", new Object[0]));
 | 
				
			||||||
 | 
					                    orderFormEntry.set("ordercount", 0);
 | 
				
			||||||
 | 
					                }
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					                orderFormEntry.set("contractremainnum", installPrice.subtract(orderCount));
 | 
				
			||||||
 | 
					                this.getView().setEnable(Boolean.FALSE, rowIndex, new String[]{"brand", "model", "contractnum", "unitprice", "transportprice", "installprice", "taxprice", "taxrate", "description"});
 | 
				
			||||||
 | 
					            }
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					            unitPrice = orderFormEntry.getBigDecimal("unitprice").setScale(4, 1);
 | 
				
			||||||
 | 
					            transportPrice = orderFormEntry.getBigDecimal("transportprice").setScale(4, 1);
 | 
				
			||||||
 | 
					            installPrice = orderFormEntry.getBigDecimal("installprice").setScale(4, 1);
 | 
				
			||||||
 | 
					            DynamicObject taxRate = orderFormEntry.getDynamicObject("taxrate");
 | 
				
			||||||
 | 
					            BigDecimal totalPrice;
 | 
				
			||||||
 | 
					            BigDecimal noTaxTotalPrice;
 | 
				
			||||||
 | 
					            if (fieldKey.equals("taxprice")) {
 | 
				
			||||||
 | 
					                totalPrice = orderFormEntry.getBigDecimal("taxprice");
 | 
				
			||||||
 | 
					                if (null != taxRate) {
 | 
				
			||||||
 | 
					                    noTaxTotalPrice = taxRate.getBigDecimal("taxrate");
 | 
				
			||||||
 | 
					                    totalPrice = totalPrice.divide(BigDecimal.ONE.add(noTaxTotalPrice.divide(new BigDecimal("100"))), 4, 4).setScale(4, 4);
 | 
				
			||||||
 | 
					                }
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					                unitPrice = totalPrice.subtract(transportPrice).subtract(installPrice);
 | 
				
			||||||
 | 
					                //orderFormEntry.set("unitprice", unitPrice);
 | 
				
			||||||
 | 
					            }
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					            totalPrice = transportPrice.add(unitPrice).add(installPrice);
 | 
				
			||||||
 | 
					            noTaxTotalPrice = orderCount.multiply(totalPrice).setScale(4, 4);
 | 
				
			||||||
 | 
					            BigDecimal taxPrice = totalPrice;
 | 
				
			||||||
 | 
					            BigDecimal taxTotalPrice = noTaxTotalPrice;
 | 
				
			||||||
 | 
					            BigDecimal taxAmount = BigDecimal.ZERO;
 | 
				
			||||||
 | 
					            if (taxRate != null) {
 | 
				
			||||||
 | 
					                BigDecimal rate = taxRate.getBigDecimal("taxrate");
 | 
				
			||||||
 | 
					                taxPrice = totalPrice.multiply(BigDecimal.ONE.add(rate.divide(new BigDecimal("100")))).setScale(4, 4);
 | 
				
			||||||
 | 
					                taxTotalPrice = noTaxTotalPrice.multiply(BigDecimal.ONE.add(rate.divide(new BigDecimal("100")))).setScale(4, 4);
 | 
				
			||||||
 | 
					                taxAmount = noTaxTotalPrice.multiply(rate.divide(new BigDecimal(100))).setScale(4, 4);
 | 
				
			||||||
 | 
					            }
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					            //orderFormEntry.set("totalprice", totalPrice);
 | 
				
			||||||
 | 
					            //orderFormEntry.set("notaxtotalprice", noTaxTotalPrice);
 | 
				
			||||||
 | 
					            //orderFormEntry.set("taxprice", taxPrice);
 | 
				
			||||||
 | 
					            orderFormEntry.set("taxamount", taxAmount);
 | 
				
			||||||
 | 
					            //orderFormEntry.set("taxtotalprice", taxTotalPrice);
 | 
				
			||||||
 | 
					            this.getView().updateView("orderformentry");
 | 
				
			||||||
 | 
					            this.setTotalAmoTaxAndNotTax(orderformEntryColl);
 | 
				
			||||||
 | 
					        }
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					    }
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					    private BigDecimal getContractOrderCount(DynamicObject orderForm, Object pkValue) {
 | 
				
			||||||
 | 
					        DynamicObject insideNprContract = orderForm.getDynamicObject("insidenprcontract");
 | 
				
			||||||
 | 
					        String entityName = orderForm.getDynamicObjectType().getName();
 | 
				
			||||||
 | 
					        List<QFilter> qFilters = new ArrayList();
 | 
				
			||||||
 | 
					        qFilters.add(new QFilter("insidenprcontract", "=", insideNprContract.getPkValue()));
 | 
				
			||||||
 | 
					        qFilters.add(new QFilter("isfrom", "=", true));
 | 
				
			||||||
 | 
					        qFilters.add(new QFilter("id", "!=", orderForm.getPkValue()));
 | 
				
			||||||
 | 
					        if ("repe_orderform_change".equals(entityName)) {
 | 
				
			||||||
 | 
					            DynamicObject relatedorderform = orderForm.getDynamicObject("relatedorderform");
 | 
				
			||||||
 | 
					            if (relatedorderform != null) {
 | 
				
			||||||
 | 
					                qFilters.add(new QFilter("id", "!=", relatedorderform.getPkValue()));
 | 
				
			||||||
 | 
					            }
 | 
				
			||||||
 | 
					        }
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					        DynamicObject[] orderForms = BusinessDataServiceHelper.load("repe_orderform", "material,ordercount", (QFilter[])qFilters.toArray(new QFilter[0]));
 | 
				
			||||||
 | 
					        BigDecimal totalCount = new BigDecimal(0);
 | 
				
			||||||
 | 
					        if (orderForms != null && orderForms.length > 0) {
 | 
				
			||||||
 | 
					            DynamicObject[] var8 = orderForms;
 | 
				
			||||||
 | 
					            int var9 = orderForms.length;
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					            for(int var10 = 0; var10 < var9; ++var10) {
 | 
				
			||||||
 | 
					                DynamicObject order = var8[var10];
 | 
				
			||||||
 | 
					                DynamicObjectCollection entrys = order.getDynamicObjectCollection("orderformentry");
 | 
				
			||||||
 | 
					                Map<Object, DynamicObject> map = (Map)entrys.stream().collect(Collectors.toMap((item) -> {
 | 
				
			||||||
 | 
					                    return item.getDynamicObject("material").getPkValue();
 | 
				
			||||||
 | 
					                }, (item) -> {
 | 
				
			||||||
 | 
					                    return item;
 | 
				
			||||||
 | 
					                }, (v1, v2) -> {
 | 
				
			||||||
 | 
					                    return v1;
 | 
				
			||||||
 | 
					                }));
 | 
				
			||||||
 | 
					                if (map.containsKey(pkValue)) {
 | 
				
			||||||
 | 
					                    BigDecimal ordercount = ((DynamicObject)map.get(pkValue)).getBigDecimal("ordercount");
 | 
				
			||||||
 | 
					                    totalCount = totalCount.add(ordercount);
 | 
				
			||||||
 | 
					                }
 | 
				
			||||||
 | 
					            }
 | 
				
			||||||
 | 
					        }
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					        return totalCount;
 | 
				
			||||||
 | 
					    }
 | 
				
			||||||
 | 
					}
 | 
				
			||||||
		Loading…
	
		Reference in New Issue