Esempio n. 1
0
        /// <summary>
        /// 根据出运明细关联销售订单行的随单BOM生成报关协同行
        /// </summary>
        /// <param name="syneryHead"></param>
        /// <param name="shipPlanLine"></param>
        /// <param name="RowNo"></param>
        /// <param name="item"></param>
        private void CreateSOBomSynergyLine(UFIDA.U9.Cust.GS.FT.SynergyBE.SynergyHead syneryHead, ShipPlanDetailLine shipPlanLine, int RowNo, ItemMaster item)
        {
            OrderBomHead sobomhead = OrderBomHead.Finder.Find("OrderLine=@OrderLine", new OqlParam[1] {
                new OqlParam(shipPlanLine.SrcLineID)
            });

            if (sobomhead != null)
            {
                UFIDA.U9.Cust.GS.FT.SynergyBE.SynergyLine syneryline = UFIDA.U9.Cust.GS.FT.SynergyBE.SynergyLine.Create(syneryHead);
                //syneryline.SynergyProduct = shipPlanLine.SynergyProduct;//报关品名
                syneryline.RowNo             = shipPlanLine.RowNo;                    //行号
                syneryline.SourceSellNo      = shipPlanLine.SrcDocNo;                 //来源销售订单号
                syneryline.SourceSellID      = shipPlanLine.SrcSO.ID;                 //来源销售订单ID
                syneryline.SourceSellRowNo   = int.Parse(shipPlanLine.SrcLineNo);     //来源销售订单行号
                syneryline.SourceSellLineID  = shipPlanLine.SrcLineID;                //来源销售订单行ID
                syneryline.SourceLineID      = shipPlanLine.RowNo;                    //来源行号
                syneryline.SourceOrderLineID = shipPlanLine.ID;                       //来源单据行ID
                syneryline.SourceOrderNo     = shipPlanLine.ShipPlanDetailHead.DocNo; //来源单据号
                syneryline.SourceOrderID     = shipPlanLine.ShipPlanDetailHead.ID;    //来源单据ID
                syneryline.ParentPart        = shipPlanLine.Item;                     //母件
                syneryline.SubKey            = sobomhead.SubKey;                      //子件
                syneryline.SubkeyType        = AttibuerEnum.IsOut;                    //子件类型
                syneryline.Standard          = shipPlanLine.Standard;                 //规格
                syneryline.Qty        = shipPlanLine.Qty;                             //数量
                syneryline.Uom        = shipPlanLine.NumberUom;                       //计量单位
                syneryline.NeddSubkey = shipPlanLine.Qty;                             //子件用量
                // syneryline.CustomsQty = shipPlanLine.CustomsQty;//报关数量

                /*从出运明细单带出,取合同价
                 * 如果无合同价,则取最近一次采购价格,并将采购供应商带至供应商字段*/
                syneryline.Price = shipPlanLine.ExportSales;//单价
                //syneryline.Supplier = shipPlanLine.Supplier;//供应商

                //根据出运明显单计算
                syneryline.Cost = 0;          //成本
                //中类成品报关金额*子件成本/∑成品BOM的子件成本
                syneryline.CustomsAmount = 0; //报关金额
                //syneryline.HSCode = shipPlanLine.Item.;//HS编码
                //syneryline.CustomsProduct = shipPlanLine.CustomsProduct;//报关品名
                //syneryline.BillNo = shipPlanLine.bi;//发票号
                //syneryline.ISCustoms = shipPlanLine.ISCustoms;//是否报关
                //syneryline.Memo = shipPlanLine.Memo;//备注
                //syneryline.Descflexfield = shipPlanLine.Descflexfield;//实体扩展字段集合
                //syneryline.ParentPartCode = shipPlanLine.ParentPartCode;//母件编码
                //syneryline.ParentPartName = shipPlanLine.ParentPartName;//母件名称
                //syneryline.SubKeyCode = shipPlanLine.SubKeyCode;//子件编码
                //syneryline.SubKeyName = shipPlanLine.SubKeyName;//子件名称
            }
        }
Esempio n. 2
0
        public void Notify(params object[] args)
        {
            if (args == null || args.Length == 0 || !(args[0] is UFSoft.UBF.Business.EntityEvent))
            {
                return;
            }
            BusinessEntity.EntityKey key = ((UFSoft.UBF.Business.EntityEvent)args[0]).EntityKey;

            if (key == null)
            {
                return;
            }
            SO so = key.GetEntity() as UFIDA.U9.SM.SO.SO;//销售订单实体

            if (so == null)
            {
                return;
            }
            //if (UFIDA.U9.Base.Context.LoginOrg.Code != "J002") return;//组织必须等于贸易中心
            if (!UFIDA.U9.Cust.GS.FT.PlugInBE.PubHelper.PubHelperExtend.IsTradeCenterOrg())
            {
                return;                                                                            //组织必须等于贸易中心
            }
            #region 变量定义
            List <SOLine>            adjustPriceList = new List <SOLine>();            //需要创建的调价单集合
            List <SOLine>            specilPriceList = new List <SOLine>();            ////需要创建的特价申请单集合
            List <long>              SoLineKey       = new List <long>();              //销售订单行Key集合【需要创建销售订单特价单来源key】
            List <IDCodeNameDTOData> ListIDCodeName  = new List <IDCodeNameDTOData>(); //价表集合
            List <SM.SO.SOLine>      ListSOLine      = new List <SOLine>();
            List <int> Soline_RowNo = new List <int>();                                //没有生成佣金的销售订单行行号
            List <SupplierModeDTOData> SupplierModeList = new List <SupplierModeDTOData>();
            List <long> SoLineAllKey = new List <long>();                              //当前销售订单的销售订单行的KEY
            #endregion

            #region 单头校验 任何操作都需要进行校验的内容
            #endregion

            #region 单行校验
            foreach (SOLine line in so.SOLines)
            {
                SoLineAllKey.Add(line.ID);
                #region 当销售订单行包装方式=外厂包装的时候,随单BOM有且只能有一个是
                if (!string.IsNullOrEmpty(line.DescFlexField.PubDescSeg18) && Convert.ToInt32(line.DescFlexField.PubDescSeg18) == 02)
                {
                    //包装方式为 外厂包装
                    SupplierModeDTOData dto = new SupplierModeDTOData();
                    dto.SoLineListID = Convert.ToInt64(line.ID);
                    dto.PackMode     = string.IsNullOrEmpty(line.DescFlexField.PubDescSeg18) ? 0 : Convert.ToInt32(line.DescFlexField.PubDescSeg18);//包装工厂
                    SupplierModeList.Add(dto);
                }
                #endregion
                #region 保存,修改校验
                //当销售订单已产生订单佣金、随单BOM,则料品不允许进行修改
                if (line.OriginalData.ItemInfo.ItemCode != line.ItemInfo.ItemCode)                                                                                  //料品不一致
                {
                    OrderBomHead Bom    = OrderBomHead.Finder.Find("OrderLine=@OrderLine", new OqlParam(line.ID));                                                  //是否生成BOM
                    bool         IsBoll = string.IsNullOrEmpty(line.DescFlexField.PrivateDescSeg6) ? false : Convert.ToBoolean(line.DescFlexField.PrivateDescSeg6); //是否生成佣金
                    if (IsBoll == true || Bom != null)
                    {
                        throw new Exception("当前销售订单已产生订单佣金/随单BOM,料品不允许进行修改!");
                    }
                }
                #endregion

                #region  是否生成佣金
                bool b = string.IsNullOrEmpty(line.DescFlexField.PrivateDescSeg6 + "") ? false : Convert.ToBoolean(line.DescFlexField.PrivateDescSeg6);
                if (!b)
                {
                    Soline_RowNo.Add(line.DocLineNo);//销售订单行行号
                }
                #endregion

                #region 创建特价申请单校验
                //判断条件 外销价改低[弹性域]与定价比较;勾选特价[弹性域];是否有成本预测;调价原因不为空
                if (!string.IsNullOrEmpty(line.DescFlexField.PrivateDescSeg1) && Convert.ToBoolean(line.DescFlexField.PrivateDescSeg1))                                                                                      //是否特价
                {
                    if (!string.IsNullOrEmpty(line.DescFlexField.PrivateDescSeg5) && Convert.ToDecimal(line.DescFlexField.PrivateDescSeg5) < line.OrderPriceTC && !string.IsNullOrEmpty(line.DescFlexField.PrivateDescSeg2)) //比较外销价 并且调价原因不为空
                    {
                        CostForecast.EntityList Cosst = CostForecast.Finder.FindAll("SOLine=@SOLine", new OqlParam(line.Key.ID));
                        if (Cosst == null && Cosst.Count == 0)//没用做成本预测
                        {
                            SoLineKey.Add(line.ID);
                        }
                    }
                }

                #endregion

                #region 创建销售价格调整单校验
                if (!string.IsNullOrEmpty(line.DescFlexField.PrivateDescSeg5))
                {
                    //外销价>定价&&特价不勾选
                    if (Convert.ToDecimal(line.DescFlexField.PrivateDescSeg5) > Convert.ToDecimal(line["OrderPriceTC"]) && !Convert.ToBoolean(line.DescFlexField.PrivateDescSeg1))
                    {
                        IDCodeNameDTOData PriceDto = new IDCodeNameDTOData();
                        PriceDto.ID   = Convert.ToInt64(line.PriceListID);//价表
                        PriceDto.Code = line.PriceListCode;
                        PriceDto.Name = line.PriceListName;
                        ListIDCodeName.Add(PriceDto);//价表
                        ListSOLine.Add(line);
                    }
                }
                #endregion
            }

            #endregion

            #region    的操作调用不同的方法

            #region 提交操作
            if (so.OriginalData.Status == UFIDA.U9.SM.SO.SODocStatusEnum.Open && so.Status == UFIDA.U9.SM.SO.SODocStatusEnum.Approving)
            {
                if (SoLineKey != null && SoLineKey.Count > 0)
                {
                    PubSoSubmitExtend.CreateSoOrderSale(SoLineKey);//调用创建特价申请单方法
                }
                if (SoLineAllKey != null && SoLineAllKey.Count > 0)
                {
                    PubSoSubmitExtend.CreateAssessType(so.TC.ID, SoLineAllKey); //创建评估类型
                    PubSoSubmitExtend.SetSolineProject(so);                     //反写销售订单行项目号
                }
                PubSoSubmitExtend.CreateFee(so);                                //创建销售订单费用
            }
            #endregion
            #region 审核操作
            if (so.OriginalData.Status == UFIDA.U9.SM.SO.SODocStatusEnum.Approving && so.Status == UFIDA.U9.SM.SO.SODocStatusEnum.Approved)
            {
                if (SupplierModeList != null && SupplierModeList.Count > 0)
                {
                    //当销售订单行包装工厂为外厂包装时,随单BOM的“提供受托加工”有且只能勾选一条:
                    GetSupplierModeProxy proxy = new GetSupplierModeProxy();
                    proxy.SupplierModeDTO = SupplierModeList;
                    string StrMeg = proxy.Do();
                    if (!string.IsNullOrEmpty(StrMeg))
                    {
                        throw new Exception(StrMeg);
                    }
                }
                //判断是否生成佣金,如则不允许审核,
                if (Soline_RowNo != null && Soline_RowNo.Count > 0)
                {
                    throw new Exception("销售订单行" + Soline_RowNo[0] + "没有生成佣金,不可以审批");
                }
                //如果评估类型中有一行大货评估,必须要有一行新品评估类型
                if (SoLineAllKey != null && SoLineAllKey.Count > 0)
                {
                    PubSoApprovedExtend.Is_NewGood(SoLineAllKey);
                }
                if (so.DescFlexField.PrivateDescSeg2 != "04")//业务类型不等于自备库存
                {
                    if (ListIDCodeName.Count > 0 && ListSOLine.Count > 0)
                    {
                        PubSoApprovedExtend.CreateSalePriceAdjustment(ListIDCodeName, ListSOLine);//创建销售价格调整单,提交,审核
                    }
                }

                //销售订单类型为标准订单、预告订单/客户备库、巨星自备、汇总订单时,并且业务类型是普通订单,审核时产生供应计划
                if ((so.DocType.Code == "SO1" || so.DocType.Code == "SO2" || so.DocType.Code == "SO3" || so.DocType.Code == "SO4") && so.DescFlexField.PrivateDescSeg2 == "03")
                {
                    PubSoApprovedExtend.CreateSupplyPlan(so);//创建供应计划
                }
            }
            #endregion
            #region 弃审操作
            if (so.OriginalData.Status == UFIDA.U9.SM.SO.SODocStatusEnum.Approved && so.Status == UFIDA.U9.SM.SO.SODocStatusEnum.Open)
            {
                //PubSoUnAppovedExtend.UnAppoved(so);//销售订单弃审操作逻辑校验
            }
            #endregion
            #endregion
        }
        /// <summary>
        /// 获取采购单价
        /// </summary>
        /// <param name="type">取采购单价类型,因为不同字段取值采购单价校验不同(主要区分币种),用type字段区分,0计算退税率,1计算包装采购成本,3计算工具采购成本</param>
        /// <param name="soLine"></param>
        /// <param name="bomLine"></param>
        /// <param name="ds"></param>
        /// <returns></returns>
        private static decimal CalculatePurchasePrice(int type, SM.SO.SOLine soLine, OrderBomHead bomLine, DataSet ds, ref int currencyType)
        {
            decimal purchasePrice = 0;

            if (ds != null && ds.Tables.Count > 0 && ds.Tables[0].Rows.Count > 0 && ds.Tables[0].Rows[0]["OrderPriceTC"].ToString() != "")
            {
                purchasePrice = Convert.ToDecimal(ds.Tables[0].Rows[0]["OrderPriceTC"].ToString());
                if (type == 0 && Convert.ToInt64(ds.Tables[0].Rows[0]["TC"].ToString()) == 9)//采购币种为美元,不退税
                {
                    return(0);
                }
                else if (type == 1 && Convert.ToInt64(ds.Tables[0].Rows[0]["TC"].ToString()) != 1)//采购币种不为人民币,不计算计算包装采购成本
                {
                    return(0);
                }
                else
                {
                    if (type == 2)                                                       //工具采购成本计算结果根据币种不同需要保存到不同字段,此处记录币种为人民币/美元
                    {
                        if (Convert.ToInt64(ds.Tables[0].Rows[0]["TC"].ToString()) == 1) //人民币
                        {
                            currencyType = 1;
                        }
                        else if (Convert.ToInt64(ds.Tables[0].Rows[0]["TC"].ToString()) == 9)//美元
                        {
                            currencyType = 9;
                        }
                    }
                    else if (Convert.ToInt64(ds.Tables[0].Rows[0]["TC"].ToString()) != soLine.SO.TC.ID)//币种不同,汇率转换为销售订单币种
                    {
                        //purchasePrice =
                        UFIDA.U9.Cust.CBO.RateBE.OperationalRateLine rateLine = UFIDA.U9.Cust.CBO.RateBE.OperationalRateLine.Finder.Find("StartDate<='" + DateTime.Now + "' and EndDate>='" + DateTime.Now + "'" +
                                                                                                                                         "and OperationalRateHead.IsCurrency=" + Convert.ToInt64(ds.Tables[0].Rows[0]["TC"].ToString()) + " and OperationalRateHead.NotCurrency=" + soLine.SO.TC.ID + " and OperationalRateHead.Org=" + UFIDA.U9.Base.Context.LoginOrg.ID);
                        if (rateLine == null)
                        {
                            UFIDA.U9.Base.Currency.Currency isCurenty = UFIDA.U9.Base.Currency.Currency.Finder.FindByID(Convert.ToInt64(ds.Tables[0].Rows[0]["TC"].ToString()));
                            throw new Exception("原币" + isCurenty.Name + "对目标币" + soLine.SO.TC.Name + "的汇率未设置,请在基础设置-业务汇率表中设置");
                        }
                        purchasePrice = purchasePrice * rateLine.Parities;
                    }
                    return(purchasePrice);
                }
            }
            else //没有取到最近采购价,取厂商价目表
            {
                UFIDA.U9.PPR.PurPriceList.PurPriceLine purPriceLine = null;
                if (bomLine == null) //BOM为空,取成品采购价
                {
                    purPriceLine = UFIDA.U9.PPR.PurPriceList.PurPriceLine.Finder.Find("ItemInfo.ItemID.Code='" + soLine.ItemInfo.ItemID.Code + "' and FromDate<='" + DateTime.Now + "' and ToDate>='" + DateTime.Now + "' and  PurPriceList.Org=" + UFIDA.U9.Base.Context.LoginOrg.ID);
                    if (type == 2 && purPriceLine == null) //计算采购成本取不到价格,取销售订单行成品成本
                    {
                        return(0);
                    }
                    else if (purPriceLine == null)
                    {
                        throw new Exception("销售订单" + soLine.SO.DocNo + "行" + soLine.DocLineNo + "对应料号" + soLine.ItemInfo.ItemCode + "品名" + soLine.ItemInfo.ItemName + "没有取到价格,请手工录入价表");
                    }
                }
                else if (bomLine.SubKey != null)//子件
                {
                    purPriceLine = UFIDA.U9.PPR.PurPriceList.PurPriceLine.Finder.Find("ItemInfo.ItemID.Code='" + bomLine.SubKey.Code + "' and FromDate<='" + DateTime.Now + "' and ToDate>='" + DateTime.Now + "' and  PurPriceList.Org=" + UFIDA.U9.Base.Context.LoginOrg.ID);
                    if (type == 2 && purPriceLine == null) //工具子件取不到价格,取销售订单行成品成本
                    {
                        return(0);
                    }
                    else if (purPriceLine == null)
                    {
                        throw new Exception("销售订单" + soLine.SO.DocNo + "行" + soLine.DocLineNo + "对应料号" + soLine.ItemInfo.ItemCode + "品名" + soLine.ItemInfo.ItemName + "子件:" + bomLine.SubKey.Name + "没有取到价格,请手工录入价表");
                    }
                }
                if (type == 0 && purPriceLine.PurPriceList.Currency.ID == 9)//币种为美元,不退税
                {
                    return(0);
                }
                else if (type == 1 && purPriceLine.PurPriceList.Currency.ID != 1)//币种不为人民币,不计算计算包装采购成本
                {
                    return(0);
                }
                else
                {
                    if (type == 2)                                      //工具采购成本计算结果根据币种不同需要保存到不同字段,此处记录币种为人民币/美元
                    {
                        if (purPriceLine.PurPriceList.Currency.ID == 1) //人民币
                        {
                            currencyType = 1;
                        }
                        else if (purPriceLine.PurPriceList.Currency.ID == 9) //美元
                        {
                            currencyType = 9;
                        }
                    }
                }
                purchasePrice = purPriceLine.Price;                                                                   //厂商价目表单价
                if (purPriceLine.PurPriceList.Currency != null && purPriceLine.PurPriceList.Currency != soLine.SO.TC) //币种不同,汇率转换为销售订单币种
                {
                    UFIDA.U9.Cust.CBO.RateBE.OperationalRateLine rateLine = UFIDA.U9.Cust.CBO.RateBE.OperationalRateLine.Finder.Find("StartDate<='" + DateTime.Now + "' and EndDate>='" + DateTime.Now + "'" +
                                                                                                                                     "and OperationalRateHead.IsCurrency=" + purPriceLine.PurPriceList.Currency.ID + " and OperationalRateHead.NotCurrency=" + soLine.SO.TC.ID + " and OperationalRateHead.Org=" + UFIDA.U9.Base.Context.LoginOrg.ID);
                    if (rateLine == null)
                    {
                        throw new Exception("原币" + purPriceLine.PurPriceList.Currency.Name + "对目标币" + soLine.SO.TC.Name + "的汇率未设置,请在基础设置-业务汇率表中设置");
                    }
                    purchasePrice = purchasePrice * rateLine.Parities;
                }
                return(purchasePrice);
            }
            //return purchasePrice;
        }
Esempio n. 4
0
        /// <summary>
        /// 递归
        /// </summary>
        /// <param name="code">料号</param>
        /// <param name="strTier"></param>
        /// <param name="TierCount"></param>
        public void Recursion(string code, SOLine soline, string strTier, Decimal Need_Number)
        {
            string LastTier = string.Empty;
            int    Number   = 0;
            //查找条件为:
            //物料清单.母件料品=销售订单行.料品 and状态=已审核 and 生产单位=销售订单行.料品.生产单位 and 当前日期在生效范围内 数据中心组织 生产目的=0.,Bom类型=自制 项目=null
            BOMMaster Master = BOMMaster.Finder.Find("ItemMaster.Code='" + code + "'  and Status=2 and ProductUOM ='" + soline.ItemInfo.ItemID.ManufactureUOM.ID + "' and EffectiveDate <='" + DateTime.Now + "' and DisableDate >='" + DateTime.Now + "' and AlternateType =0  and Org.Code='J001'");//查询物料清单头   1001411156754220

            if (Master != null)
            {
                foreach (BOMComponent item in Master.BOMComponents) //循环物料清单行
                {
                    if (item.BOMMaster.ID == Master.ID)             //单头id=单行BOMMaster
                    {
                        Number++;
                        //创建BOM单头/业务员
                        OrderBomHead BomHead = OrderBomHead.Create();
                        BomHead.OrderLineRow  = soline.DocLineNo;//销售订单行号
                        BomHead.OrderHeadKey  = soline.SO.Key;
                        BomHead.OrderLineKey  = soline.Key;
                        BomHead.Tier          = strTier + "." + Number;
                        LastTier              = BomHead.Tier;
                        BomHead.ParentPartKey = Master.ItemMasterKey;//母件
                        if (Master.ItemMaster != null)
                        {
                            BomHead.SubkeyTypeKey = BOMComponent.Finder.Find("ItemMaster=@ItemMaster", new OqlParam(item.ItemMaster.ID)).ItemMaster.StockCategoryKey;
                        }//item.ComponentType;//.ComponentTypeKey;//.Name;//子项分类 =》库存分类
                        BomHead.SubKeyKey     = item.ItemMasterKey;//子项
                        BomHead.Dosage        = item.UsageQty;//用量  UsageQty
                        BomHead.DosageUnitKey = item.IssueUOMKey;    //用量单位 IssueUOM
                        BomHead.SellNumber    = soline.OrderByQtyPU; //;//销售数量
                        BomHead.SellUnitKey   = soline.PUKey;        //销售单位
                        if (Need_Number != 0)
                        {
                            BomHead.NeedNumber = BomHead.SellNumber * item.UsageQty;//需求数量=母项的需求数量*子项的用量
                            Need_Number        = BomHead.NeedNumber;
                        }
                        else
                        {
                            BomHead.NeedNumber = BomHead.SellNumber * item.UsageQty;//需求数量=销售数量数量*子项的用量
                            Need_Number        = 0;
                        }
                        // BomHead.SupplierType=;//供应类型  物料清单扩展字段
                        // BomHead.SourceType=;//来源类型
                        BomHead.Remark = item.Remark;                                                                                             //备注
                        OrderBomLine BomLine = OrderBomLine.Create(BomHead);
                        BomLine.SubKeyKey = item.ItemMasterKey;                                                                                   //子项
                        long KeyID = item.ID;
                        Operators.EntityKey BuyerKey = BOMComponent.Finder.Find(string.Format("id={0}", KeyID)).ItemMaster.PurchaseInfo.BuyerKey; //业务员
                        if (BuyerKey != null)
                        {
                            BomLine.SalesManKey = BuyerKey;
                            if (BuyerKey.GetEntity().Dept != null && Department.Finder.FindByID(BuyerKey.GetEntity().Dept.ID) != null)
                            {
                                BomLine.DepartmentKey = Department.Finder.FindByID(BuyerKey.GetEntity().Dept.ID).Key;//所属部门
                            }
                        }
                        BomLine.NeedUomKey     = item.IssueUOMKey;   //需求单位   IssueUOM
                        BomLine.ProcurementQty = BomHead.NeedNumber; //采购数量【可改】   集合不能大于需求数量
                        BomLine.NeedNumber     = BomHead.NeedNumber; //需求数量=销售订单数量
                        BomLine.Memo           = item.Remark;        //备注
                        if (item.ItemMaster != null && item.ItemMaster.Code != null)
                        {
                            Recursion(item.ItemMaster.Code, soline, LastTier, Need_Number);//递归
                        }
                    }
                }
            }
        }
        /// <summary>
        /// 为实体Dto赋值
        /// </summary>
        /// <param name="SO">销售订单集合</param>
        /// <param name="SoLine">销售订单行集合与销售订单集合互斥</param>
        /// <param name="dotList">成本预测实体DTo</param>
        private List <CostForecastBE.CostForecastDTO> SetCostDto(List <SM.SO.SO.EntityKey> SO, List <SM.SO.SOLine.EntityKey> SoLine)
        {
            List <CostForecastBE.CostForecastDTO> dtoList = new List <CostForecastBE.CostForecastDTO>();//订单成本预测实体集合

            #region 参数声明
            CostForecastBE.CostForecastDTO dto    = null; //订单成本预测实体dto
            CostForecastBE.CostForecastDTO dtoOne = null; //成品成本预测实体dto
            //获取所需预置参数
            CalculateDtoFieldExtend.GetPresetParameter();
            #endregion

            //整单成本预测
            if (SO != null && SO.Count > 0)
            {
                //从UI得到的销售订单应该是已经按照销售订单过滤了的
                SM.SO.SO soEntity = null;
                using (ISession session = Session.Open())
                {
                    foreach (SM.SO.SO.EntityKey soKey in SO)                        //遍历销售订单集合
                    {
                        //得到对应销售订单
                        soEntity = soKey.GetEntity();
                        if (soEntity == null)
                        {
                            throw new Exception("请确认查询方式是否设置为整单成本预测");
                            //continue;
                        }
                        dto              = new CostForecastBE.CostForecastDTO();
                        dto.SONo         = soEntity;                                       //赋值销售订单
                        dto.ForecastType = AllEnumBE.CostForecastTypeEnum.AllCostForecast; //预测类型整单成本预测
                        if (soEntity.DescFlexField.PrivateDescSeg6 != "")
                        {
                            dto.OceanFreight = decimal.Parse(soEntity.DescFlexField.PrivateDescSeg6);//国际费用
                        }
                        if (soEntity.DescFlexField.PrivateDescSeg8 != "")
                        {
                            dto.OtherFee = decimal.Parse(soEntity.DescFlexField.PrivateDescSeg8);//其他国外费用
                        }
                        if (soEntity.DescFlexField.PrivateDescSeg5 != "")
                        {
                            dto.DomesticFee = decimal.Parse(soEntity.DescFlexField.PrivateDescSeg5);//国内运费
                        }
                        if (soEntity.DescFlexField.PrivateDescSeg7 != "")
                        {
                            dto.OtherDomesticFee = decimal.Parse(soEntity.DescFlexField.PrivateDescSeg7);//其他国内费用
                        }
                        #region 计算整单体积
                        decimal allVolume = 0;
                        foreach (SM.SO.SOLine soLineEntity in soEntity.SOLines)    //遍历销售订单行集合计算整单体积
                        {
                            //bool isCalculateFreight = 0;//
                            //单行的体积=单行的箱数*料品.体积
                            //单行的箱数=订单数量/料品.装箱数量
                            //判断料品的装箱数量与装箱体积是否为空
                            UFIDA.U9.Cust.GS.FT.ItemSubTableBE.ItemSubTable itemSub = UFIDA.U9.Cust.GS.FT.ItemSubTableBE.ItemSubTable.Finder.Find("ItemMaster=" + soLineEntity.ItemInfo.ItemID.ID + "");
                            //if (itemSub == null)
                            //{
                            //    throw new Exception("请录入" + soLineEntity.SO.DocNo + "行" + soLineEntity.DocLineNo + "对应料品的装箱数量");
                            //}
                            //if(itemSub.BoxNumber ==0)
                            //{
                            //    throw new Exception("请录入" + soLineEntity.SO.DocNo + "行" + soLineEntity.DocLineNo + "对应料品的装箱数量");
                            //}
                            //if (itemSub.GrossWeight == 0)
                            //{
                            //    throw new Exception("请录入" + soLineEntity.SO.DocNo + "行" + soLineEntity.DocLineNo + "对应料品的毛重");
                            //}
                            //if (itemSub.BoxLong == 0)
                            //{
                            //    throw new Exception("请录入" + soLineEntity.SO.DocNo + "行" + soLineEntity.DocLineNo + "对应料品的装箱长度");
                            //}
                            //if (itemSub.BoxWidth == 0)
                            //{
                            //    throw new Exception("请录入" + soLineEntity.SO.DocNo + "行" + soLineEntity.DocLineNo + "对应料品的装箱宽度");
                            //}
                            //if (itemSub.BoxHight == 0)
                            //{
                            //    throw new Exception("请录入" + soLineEntity.SO.DocNo + "行" + soLineEntity.DocLineNo + "对应料品的装箱高度");
                            //}
                            //decimal itemQty = decimal.Parse(soLineEntity.ItemInfo.ItemIDKey.GetEntity().DescFlexField.PrivateDescSeg3);//料品装箱数量
                            //decimal itemRough = decimal.Parse(soLineEntity.ItemInfo.ItemIDKey.GetEntity().DescFlexField.PrivateDescSeg2);//料品毛重
                            if (itemSub != null)
                            {
                                decimal itemVolume = itemSub.BoxLong * itemSub.BoxWidth * itemSub.BoxHight;//料品体积
                                if (itemSub.BoxNumber == 0)
                                {
                                    allVolume += soLineEntity.OrderByQtyTU * itemVolume;//整单体积
                                }
                                else
                                {
                                    allVolume += (soLineEntity.OrderByQtyTU / itemSub.BoxNumber) * itemVolume;//整单体积
                                }
                            }
                        }
                        #endregion

                        #region 遍历得到销售订单行
                        string dtoDemo = "";
                        foreach (SM.SO.SOLine soLineEntity in soEntity.SOLines)    //遍历销售订单行集合
                        {
                            string dtoOneDemo = "";
                            UFIDA.U9.Cust.GS.FT.ItemSubTableBE.ItemSubTable itemSub = UFIDA.U9.Cust.GS.FT.ItemSubTableBE.ItemSubTable.Finder.Find("ItemMaster=" + soLineEntity.ItemInfo.ItemID.ID + "");
                            //计算共用值
                            decimal itemQty    = 0; //料品装箱数量
                            decimal itemRough  = 0; //料品毛重
                            decimal itemVolume = 0; //料品体积
                            if (itemSub != null)
                            {
                                itemQty    = itemSub.BoxNumber;                                     //料品装箱数量
                                itemRough  = itemSub.GrossWeight;                                   //料品毛重
                                itemVolume = itemSub.BoxLong * itemSub.BoxWidth * itemSub.BoxHight; //料品体积
                            }
                            decimal rmbCost    = 0;                                                 //工具人民币采购成本
                            decimal dollorCost = 0;                                                 //工具美元采购成本
                            decimal allFee     = 0;                                                 //成品各项费用

                            dtoOne = new CostForecastBE.CostForecastDTO();
                            dtoOne.ForecastType = AllEnumBE.CostForecastTypeEnum.OneCostForecast;     //预测类型
                            dtoOne.SONo         = soEntity;                                           //销售订单
                            dtoOne.SOLine       = soLineEntity;                                       //销售订单行
                            dtoOne.Brokerage    = CalculateDtoFieldExtend.GetBrokerage(soLineEntity); //佣金
                            dtoOne.Discount     = CalculateDtoFieldExtend.GetDiscount(soLineEntity);  //折扣
                            if (itemQty == 0 || itemRough == 0 || itemVolume == 0)
                            {
                                dtoOne.OceanFreight = 0;
                                dtoOne.DomesticFee  = 0;
                            }
                            else
                            {
                                dtoOne.OceanFreight = CalculateDtoFieldExtend.GetOceanFreight(itemQty, itemRough, itemVolume, soLineEntity);           //海运费
                                dtoOne.DomesticFee  = CalculateDtoFieldExtend.GetDomesticFee(itemQty, itemRough, itemVolume, allVolume, soLineEntity); //国内运费
                            }
                            dtoOne.OtherFee         = CalculateDtoFieldExtend.GetOtherOceanFreight(soLineEntity);                                      //其他国外费
                            dtoOne.OtherDomesticFee = CalculateDtoFieldExtend.GetOtherOceanFreight(soLineEntity);                                      //其他国内费

                            //随单BOM
                            OrderBomBE.OrderBomHead.EntityList orderBom = OrderBomBE.OrderBomHead.Finder.FindAll("OrderLine=@SOLine", new OqlParam(soLineEntity.ID));
                            dtoOne.TaxCredits        = CalculateDtoFieldExtend.GetTaxCredits(soLineEntity, orderBom);                               //退税额
                            dtoOne.ProcurementCost   = CalculateDtoFieldExtend.GetProcurementCost(soLineEntity, orderBom);                          //包装采购成本
                            dtoOne.LabourCharges     = CalculateDtoFieldExtend.GetLabourCharges(soLineEntity);                                      //包装人工费用
                            dtoOne.ProductCost       = CalculateDtoFieldExtend.GetProductCost(soLineEntity, ref rmbCost, ref dollorCost, orderBom); //产品采购成本
                            dtoOne.RMBProductCost    = rmbCost;                                                                                     //工具人民币采购成本
                            dtoOne.DollorProductCost = dollorCost;                                                                                  //工具美元采购成本
                            dtoOne.AdministrativeFee = CalculateDtoFieldExtend.GetAdministrativeFee(soLineEntity);                                  //管理费
                            dtoOne.Interest          = CalculateDtoFieldExtend.GetInterest(soLineEntity);                                           //利息
                            dtoOne.MouldFee          = CalculateDtoFieldExtend.GetMouldFee(soLineEntity);                                           //模具费‘
                            dtoOne.Labelling         = CalculateDtoFieldExtend.GetLabelling(soLineEntity, orderBom);                                //防盗标签费
                            dtoOne.CreditInsurance   = CalculateDtoFieldExtend.GetCreditInsurance(soLineEntity);                                    //信用保险费
                            dtoOne.BankCharge        = CalculateDtoFieldExtend.GetBankCharge(soLineEntity);                                         //银行费用

                            //dtoOne.OrderBomHead = orderBom;//随单Bom
                            dtoOne.ForecastTime = DateTime.Now;
                            dtoOne.ForecastMan  = UFIDA.U9.Base.Context.LoginUser;

                            //成品预测利润:各中类成品外销额-成品各项费用+成品退税额
                            allFee = dtoOne.Brokerage + dtoOne.Discount + dtoOne.OceanFreight + dtoOne.OtherFee + dtoOne.DomesticFee + dtoOne.OtherDomesticFee +
                                     dtoOne.ProcurementCost + dtoOne.LabourCharges + dtoOne.ProductCost + dtoOne.AdministrativeFee + dtoOne.Interest + dtoOne.MouldFee +
                                     dto.Labelling + dtoOne.CreditInsurance + dtoOne.BankCharge;
                            dtoOne.ProductForecastRate = soLineEntity.TotalMoneyTC - allFee + dto.TaxCredits;
                            dtoOne.ProductRate         = dto.ProductForecastRate / soLineEntity.TotalMoneyTC;
                            //备注
                            dtoOne.Demo = dtoOneDemo;
                            dtoList.Add(dtoOne);

                            #region 汇总到整单成本预测
                            dto.Brokerage         += dtoOne.Brokerage;
                            dto.Discount          += dtoOne.Discount;
                            dto.OceanFreight      += dtoOne.OceanFreight;//海运费
                            dto.TaxCredits        += dtoOne.TaxCredits;
                            dto.ProcurementCost   += dtoOne.ProcurementCost;
                            dto.LabourCharges     += dtoOne.LabourCharges;
                            dto.ProductCost       += dtoOne.ProductCost;
                            dto.RMBProductCost    += dtoOne.RMBProductCost;
                            dto.DollorProductCost += dtoOne.DollorProductCost;
                            dto.AdministrativeFee += dtoOne.AdministrativeFee;
                            dto.Interest          += dtoOne.Interest;
                            dto.MouldFee          += dtoOne.MouldFee;
                            dto.Labelling         += dtoOne.Labelling;
                            dto.CreditInsurance   += dtoOne.CreditInsurance;
                            dto.BankCharge        += dtoOne.BankCharge;
                            dto.ListForecastRate  += dto.ProductForecastRate;
                            //备注
                            dto.Demo = "";
                            //dto.SOLine = soLineEntity;
                            //随单BOM


                            #endregion
                            //得到销售订单行soLineEntity
                            #region 计算成本预测字段值
                            //根据销售订单行得到随单Bom表
                            OrderBomHead bomHead = OrderBomHead.Finder.Find("");
                            #endregion
                        }
                        dto.ListRate     = dto.ProductForecastRate / soEntity.TotalMoneyAC; //整单利润率
                        dto.ForecastTime = DateTime.Now;                                    //预测时间
                        dto.ForecastMan  = UFIDA.U9.Base.Context.LoginUser;                 //预测人

                        dtoList.Add(dto);

                        //soEntity.DescFlexField.PrivateDescSeg7 = dto.OceanFreight.ToString();
                        #endregion
                    }
                    session.Commit();
                }
            }
            else if (SoLine != null && SoLine.Count > 0)
            {
                using (Session seesion = Session.Open())
                {
                    //成品成本预测
                    //从UI得到的销售订单行应该是已经按照销售订单行过滤了的
                    foreach (SM.SO.SOLine.EntityKey soLineKey in SoLine)          //遍历销售订单行集合
                    {
                        //得到销售订单行
                        //SM.SO.SOLine soLineEntity = soLineKey.GetEntity();
                        SM.SO.SOLine line = SM.SO.SOLine.Finder.FindByID(soLineKey.ID);
                        if (line == null)
                        {
                            throw new Exception("请确认查询方案设置为成品成本预测");
                        }
                        SM.SO.SOLine soLineEntity = line;

                        #region 计算整单体积
                        decimal allVolume = 0;
                        foreach (SM.SO.SOLine soLine in soLineEntity.SO.SOLines)    //遍历销售订单行集合计算整单体积
                        {
                            //单行的体积=单行的箱数*料品.体积
                            //单行的箱数=订单数量/料品.装箱数量
                            //判断料品的装箱数量与装箱体积是否为空

                            ItemSubTable itemsub = ItemSubTable.Finder.Find("ItemMaster=" + soLine.ItemInfo.ItemID.ID);
                            //if(itemsub == null)
                            //    throw new Exception("请维护" + soLine.SO.DocNo + "行" + soLine.DocLineNo + "对应料品子表装箱长度、装箱宽度、装箱高度、装箱数量、毛重字段");
                            //if(itemsub.BoxNumber == 0)
                            //{
                            //    throw new Exception("请录入" + soLine.SO.DocNo + "行" + soLine.DocLineNo + "对应料品的装箱数量");
                            //}
                            //if (itemsub.GrossWeight ==0 )
                            //{
                            //    throw new Exception("请录入" + soLine.SO.DocNo + "行" + soLine.DocLineNo + "对应料品的毛重");
                            //}
                            //if (itemsub.BoxLong == 0)
                            //{
                            //    throw new Exception("请录入" + soLine.SO.DocNo + "行" + soLine.DocLineNo + "对应料品的装箱长度");
                            //}
                            //if (itemsub.BoxWidth == 0)
                            //{
                            //    throw new Exception("请录入" + soLine.SO.DocNo + "行" + soLine.DocLineNo + "对应料品的装箱宽度");
                            //}
                            //if (itemsub.BoxHight == 0)
                            //{
                            //    throw new Exception("请录入" + soLine.SO.DocNo + "行" + soLine.DocLineNo + "对应料品的装箱高度");
                            //}
                            if (itemsub != null)
                            {
                                decimal itemQty    = itemsub.BoxNumber;                                     //料品装箱数量
                                decimal itemRough  = itemsub.GrossWeight;                                   //料品毛重
                                decimal itemVolume = itemsub.BoxLong * itemsub.BoxWidth * itemsub.BoxHight; //料品体积
                                allVolume += (soLine.OrderByQtyTU / itemQty) * itemVolume;                  //整单体积
                            }
                        }
                        #endregion

                        #region 计算成本预测字段值
                        //根据销售订单行得到随单Bom表
                        //计算共用值
                        ItemSubTable itemsub1    = ItemSubTable.Finder.Find("ItemMaster=" + soLineEntity.ItemInfo.ItemID.ID);
                        int          itemQty1    = 0; //料品装箱数量
                        decimal      itemRough1  = 0; //料品毛重
                        decimal      itemVolume1 = 0; //料品体积
                        if (itemsub1 != null)
                        {
                            itemQty1    = itemsub1.OutBoxNumber;                             //料品装箱数量
                            itemRough1  = itemsub1.GrossWeight;                              //料品毛重
                            itemVolume1 = itemsub1.Length * itemsub1.Width * itemsub1.Hight; //料品体积
                        }
                        decimal rmbCost    = 0;                                              //工具人民币采购成本
                        decimal dollorCost = 0;                                              //工具美元采购成本
                        decimal allFee     = 0;                                              //成品各项费用

                        dtoOne = new CostForecastBE.CostForecastDTO();
                        dtoOne.ForecastType = AllEnumBE.CostForecastTypeEnum.OneCostForecast;     //预测类型
                        dtoOne.SONo         = soLineEntity.SO;                                    //销售订单
                        dtoOne.SOLine       = soLineEntity;                                       //销售订单行
                        dtoOne.Brokerage    = CalculateDtoFieldExtend.GetBrokerage(soLineEntity); //佣金
                        dtoOne.Discount     = CalculateDtoFieldExtend.GetDiscount(soLineEntity);  //折扣
                        if (itemQty1 == 0 || itemRough1 == 0 || itemVolume1 == 0)
                        {
                            dtoOne.OceanFreight = 0;
                            dtoOne.DomesticFee  = 0;
                        }
                        else
                        {
                            dtoOne.OceanFreight = CalculateDtoFieldExtend.GetOceanFreight(itemQty1, itemRough1, itemVolume1, soLineEntity);           //海运费
                            dtoOne.DomesticFee  = CalculateDtoFieldExtend.GetDomesticFee(itemQty1, itemRough1, itemVolume1, allVolume, soLineEntity); //国内运费
                        }
                        dtoOne.OtherFee         = CalculateDtoFieldExtend.GetOtherOceanFreight(soLineEntity);                                         //其他国外费
                        dtoOne.OtherDomesticFee = CalculateDtoFieldExtend.GetOtherOceanFreight(soLineEntity);                                         //其他国内费
                        //随单BOM
                        OrderBomBE.OrderBomHead.EntityList orderBom = OrderBomBE.OrderBomHead.Finder.FindAll("OrderLine=@BomMaster", new OqlParam(soLineEntity.ID));
                        dtoOne.TaxCredits        = CalculateDtoFieldExtend.GetTaxCredits(soLineEntity, orderBom);                               //退税额
                        dtoOne.ProcurementCost   = CalculateDtoFieldExtend.GetProcurementCost(soLineEntity, orderBom);                          //包装采购成本
                        dtoOne.LabourCharges     = CalculateDtoFieldExtend.GetLabourCharges(soLineEntity);                                      //包装人工费用
                        dtoOne.ProductCost       = CalculateDtoFieldExtend.GetProductCost(soLineEntity, ref rmbCost, ref dollorCost, orderBom); //产品采购成本
                        dtoOne.RMBProductCost    = rmbCost;                                                                                     //工具人民币采购成本
                        dtoOne.DollorProductCost = dollorCost;                                                                                  //工具美元采购成本
                        dtoOne.AdministrativeFee = CalculateDtoFieldExtend.GetAdministrativeFee(soLineEntity);                                  //管理费
                        dtoOne.Interest          = CalculateDtoFieldExtend.GetInterest(soLineEntity);                                           //利息
                        dtoOne.MouldFee          = CalculateDtoFieldExtend.GetMouldFee(soLineEntity);                                           //模具费‘
                        dtoOne.Labelling         = CalculateDtoFieldExtend.GetLabelling(soLineEntity, orderBom);                                //防盗标签费
                        dtoOne.CreditInsurance   = CalculateDtoFieldExtend.GetCreditInsurance(soLineEntity);                                    //信用保险费
                        dtoOne.BankCharge        = CalculateDtoFieldExtend.GetBankCharge(soLineEntity);                                         //银行费用

                        //dtoOne.OrderBomHead = orderBom;//随单Bom
                        dtoOne.ForecastTime = DateTime.Now;
                        dtoOne.ForecastMan  = UFIDA.U9.Base.Context.LoginUser;

                        //成品预测利润:各中类成品外销额-成品各项费用+成品退税额
                        allFee = dtoOne.Brokerage + dtoOne.Discount + dtoOne.OceanFreight + dtoOne.OtherFee + dtoOne.DomesticFee + dtoOne.OtherDomesticFee +
                                 dtoOne.ProcurementCost + dtoOne.LabourCharges + dtoOne.ProductCost + dtoOne.AdministrativeFee + dtoOne.Interest + dtoOne.MouldFee +
                                 dtoOne.Labelling + dtoOne.CreditInsurance + dtoOne.BankCharge;
                        dtoOne.ProductForecastRate = soLineEntity.TotalMoneyTC - allFee + dtoOne.TaxCredits;
                        dtoOne.ProductRate         = dtoOne.ProductForecastRate / soLineEntity.TotalMoneyTC;

                        //反写销售订单行预测状态
                        if (soLineEntity.DescFlexField.PrivateDescSeg18 == "")
                        {
                            soLineEntity.DescFlexField.PrivateDescSeg18 = "Y";
                        }
                        //else if (soLineEntity.DescFlexField.PrivateDescSeg18 == "N")
                        //{
                        //    soLineEntity.DescFlexField.PrivateDescSeg18 = "M";
                        //}
                        dtoList.Add(dtoOne);
                        #endregion
                    }
                    seesion.Commit();
                }
            }
            else
            {
                throw new Exception("未选择任何需要预测的订单");
            }
            return(dtoList);
            //CreatEntity(dtoList);
        }
        /// <summary>
        /// 为实体Dto赋值
        /// </summary>
        /// <param name="SO">销售订单集合</param>
        /// <param name="SoLine">销售订单行集合与销售订单集合互斥</param>
        /// <param name="dotList">成本预测实体DTo</param>
        private List <ShipCostForecastBE.ShipCostForecastDTO> SetCostDto(List <GS.FT.ShipPlanDetailBE.ShipPlanDetailHead.EntityKey> ShiPlan, List <GS.FT.ShipPlanDetailBE.ShipPlanDetailLine.EntityKey> ShipLine)
        {
            List <ShipCostForecastBE.ShipCostForecastDTO> dtoList = new List <ShipCostForecastBE.ShipCostForecastDTO>();//订单成本预测实体集合

            #region 参数声明
            ShipCostForecastBE.ShipCostForecastDTO dto    = null; //明细单成本预测实体dto
            ShipCostForecastBE.ShipCostForecastDTO dtoOne = null; //明细单成品成本预测实体dto
            //获取所需预置参数
            CalculateDtoFieldShipExtend.GetPresetParameter();
            #endregion

            //整单成本预测
            if (ShiPlan != null && ShiPlan.Count > 0)
            {
                //从UI得到的销售订单应该是已经按照销售订单过滤了的
                GS.FT.ShipPlanDetailBE.ShipPlanDetailHead shipEntity = null;
                using (ISession session = Session.Open())
                {
                    foreach (GS.FT.ShipPlanDetailBE.ShipPlanDetailHead.EntityKey shipKey in ShiPlan)                        //遍历销售订单集合
                    {
                        //得到对应明细订单
                        shipEntity = shipKey.GetEntity();
                        if (shipEntity == null)
                        {
                            continue;
                        }
                        dto                  = new ShipCostForecastBE.ShipCostForecastDTO();
                        dto.ShipPlan         = shipEntity;                                     //赋值出运明细单
                        dto.ForecastType     = AllEnumBE.CostForecastTypeEnum.AllCostForecast; //预测类型整单成本预测
                        dto.OceanFreight     = shipEntity.OceanFreight;
                        dto.OtherFee         = shipEntity.OherFee;
                        dto.DomesticFee      = shipEntity.InlandFreight;
                        dto.OtherDomesticFee = shipEntity.OtherInland;
                        #region 遍历得到明细订单行
                        foreach (GS.FT.ShipPlanDetailBE.ShipPlanDetailLine shipLineEntity in shipEntity.ShipPlanDetailLine)    //遍历出运明细单行集合
                        {
                            //计算共用值
                            decimal rmbCost    = 0; //工具人民币采购成本
                            decimal dollorCost = 0; //工具美元采购成本
                            decimal allFee     = 0; //成品各项费用

                            dtoOne = new ShipCostForecastBE.ShipCostForecastDTO();
                            dtoOne.ForecastType     = AllEnumBE.CostForecastTypeEnum.OneCostForecast;                   //预测类型
                            dtoOne.ShipPlan         = shipEntity;                                                       //销售订单
                            dtoOne.ShipLine         = shipLineEntity;                                                   //销售订单行
                            dtoOne.Brokerage        = CalculateDtoFieldShipExtend.GetBrokerage(shipLineEntity);         //佣金
                            dtoOne.Discount         = CalculateDtoFieldShipExtend.GetDiscount(shipLineEntity);          //折扣
                            dtoOne.OceanFreight     = CalculateDtoFieldShipExtend.GetOceanFreight(shipLineEntity);      //海运费
                            dtoOne.OtherFee         = CalculateDtoFieldShipExtend.GetOtherOceanFreight(shipLineEntity); //其他国外费
                            dtoOne.DomesticFee      = CalculateDtoFieldShipExtend.GetDomesticFee(shipLineEntity);       //国内运费
                            dtoOne.OtherDomesticFee = CalculateDtoFieldShipExtend.GetOtherOceanFreight(shipLineEntity); //其他国内费
                            //随单BOM
                            OrderBomBE.OrderBomHead.EntityList orderBom = OrderBomBE.OrderBomHead.Finder.FindAll("OrderLine=@SOLine", new OqlParam(shipLineEntity.SrcLineID));
                            dtoOne.TaxCredits        = CalculateDtoFieldShipExtend.GetTaxCredits(shipLineEntity, orderBom);                               //退税额
                            dtoOne.ProcurementCost   = CalculateDtoFieldShipExtend.GetProcurementCost(shipLineEntity, orderBom);                          //包装采购成本
                            dtoOne.LabourCharges     = CalculateDtoFieldShipExtend.GetLabourCharges(shipLineEntity);                                      //包装人工费用
                            dtoOne.ProductCost       = CalculateDtoFieldShipExtend.GetProductCost(shipLineEntity, orderBom, ref rmbCost, ref dollorCost); //产品采购成本
                            dtoOne.RMBProductCost    = rmbCost;                                                                                           //工具人民币采购成本
                            dtoOne.DollorProductCost = dollorCost;                                                                                        //工具美元采购成本
                            dtoOne.AdministrativeFee = CalculateDtoFieldShipExtend.GetAdministrativeFee(shipLineEntity);                                  //管理费
                            dtoOne.Interest          = CalculateDtoFieldShipExtend.GetInterest(shipLineEntity);                                           //利息
                            dtoOne.MouldFee          = CalculateDtoFieldShipExtend.GetMouldFee(shipLineEntity);                                           //模具费‘
                            dtoOne.Labelling         = CalculateDtoFieldShipExtend.GetLabelling(shipLineEntity, orderBom);                                //防盗标签费
                            dtoOne.CreditInsurance   = CalculateDtoFieldShipExtend.GetCreditInsurance(shipLineEntity);                                    //信用保险费
                            dtoOne.BankCharge        = CalculateDtoFieldShipExtend.GetBankCharge(shipLineEntity);                                         //银行费用

                            dtoOne.ForecastTime = DateTime.Now;
                            dtoOne.ForecastMan  = UFIDA.U9.Base.Context.LoginUser;

                            //成品预测利润:各中类成品外销额-成品各项费用+成品退税额
                            allFee = dtoOne.Brokerage + dtoOne.Discount + dtoOne.OceanFreight + dtoOne.OtherFee + dtoOne.DomesticFee + dtoOne.OtherDomesticFee +
                                     dtoOne.ProcurementCost + dtoOne.LabourCharges + dtoOne.ProductCost + dtoOne.AdministrativeFee + dtoOne.Interest + dtoOne.MouldFee +
                                     dto.Labelling + dtoOne.CreditInsurance + dtoOne.BankCharge;
                            dtoOne.ProductForecastRate = shipLineEntity.TotalTax - allFee + dto.TaxCredits;
                            dtoOne.ProductRate         = dto.ProductForecastRate / shipLineEntity.TotalTax;
                            //备注
                            dtoOne.Demo = "";
                            dtoList.Add(dtoOne);

                            #region 汇总到整单成本预测
                            dto.Brokerage         += dtoOne.Brokerage;
                            dto.Discount          += dtoOne.Discount;
                            dto.OceanFreight      += dtoOne.OceanFreight;//海运费
                            dto.TaxCredits        += dtoOne.TaxCredits;
                            dto.ProcurementCost   += dtoOne.ProcurementCost;
                            dto.LabourCharges     += dtoOne.LabourCharges;
                            dto.ProductCost       += dtoOne.ProductCost;
                            dto.RMBProductCost    += dtoOne.RMBProductCost;
                            dto.DollorProductCost += dtoOne.DollorProductCost;
                            dto.AdministrativeFee += dtoOne.AdministrativeFee;
                            dto.Interest          += dtoOne.Interest;
                            dto.MouldFee          += dtoOne.MouldFee;
                            dto.Labelling         += dtoOne.Labelling;
                            dto.CreditInsurance   += dtoOne.CreditInsurance;
                            dto.BankCharge        += dtoOne.BankCharge;
                            dto.ListForecastRate  += dto.ProductForecastRate;
                            //备注
                            dto.Demo = ",";
                            //dto.SOLine = soLineEntity;
                            //随单BOM


                            #endregion
                            //得到销售订单行soLineEntity
                            #region 计算成本预测字段值
                            //根据销售订单行得到随单Bom表
                            OrderBomHead bomHead = OrderBomHead.Finder.Find("");
                            #endregion
                        }
                        //dto.ListRate = dto.ProductForecastRate / soEntity.TotalMoneyAC;//整单利润率
                        dto.ForecastTime = DateTime.Now;                    //预测时间
                        dto.ForecastMan  = UFIDA.U9.Base.Context.LoginUser; //预测人

                        dtoList.Add(dto);

                        shipEntity.DescFlexField.PrivateDescSeg7 = dto.OceanFreight.ToString();
                        #endregion
                    }
                    session.Commit();
                }
            }
            else if (ShipLine != null && ShipLine.Count > 0)
            {
                using (Session seesion = Session.Open())
                {
                    //成品成本预测
                    //从UI得到的销售订单行应该是已经按照销售订单行过滤了的
                    foreach (GS.FT.ShipPlanDetailBE.ShipPlanDetailLine.EntityKey shipLineKey in ShipLine)          //遍历出运明细单行集合
                    {
                        //得到出运明细行
                        //if (shipLineKey.GetEntity() == null)
                        //    throw new Exception("请在列表选择出运明细行信息");
                        ShipPlanDetailBE.ShipPlanDetailLine line = ShipPlanDetailBE.ShipPlanDetailLine.Finder.FindByID(shipLineKey.ID);
                        if (line == null)
                        {
                            throw new Exception("请在列表选择出运明细行信息");
                        }
                        GS.FT.ShipPlanDetailBE.ShipPlanDetailLine shipLineEntity = line;

                        #region 计算成本预测字段值

                        decimal rmbCost    = 0; //工具人民币采购成本
                        decimal dollorCost = 0; //工具美元采购成本
                        decimal allFee     = 0; //成品各项费用

                        dtoOne = new ShipCostForecastBE.ShipCostForecastDTO();
                        dtoOne.ForecastType     = AllEnumBE.CostForecastTypeEnum.OneCostForecast;                   //预测类型
                        dtoOne.ShipPlan         = shipLineEntity.ShipPlanDetailHead;                                //销售订单
                        dtoOne.ShipLine         = shipLineEntity;                                                   //销售订单行
                        dtoOne.Brokerage        = CalculateDtoFieldShipExtend.GetBrokerage(shipLineEntity);         //佣金
                        dtoOne.Discount         = CalculateDtoFieldShipExtend.GetDiscount(shipLineEntity);          //折扣
                        dtoOne.OceanFreight     = CalculateDtoFieldShipExtend.GetOceanFreight(shipLineEntity);      //海运费
                        dtoOne.OtherFee         = CalculateDtoFieldShipExtend.GetOtherOceanFreight(shipLineEntity); //其他国外费
                        dtoOne.DomesticFee      = CalculateDtoFieldShipExtend.GetDomesticFee(shipLineEntity);       //国内运费
                        dtoOne.OtherDomesticFee = CalculateDtoFieldShipExtend.GetOtherOceanFreight(shipLineEntity); //其他国内费

                        //随单BOM
                        OrderBomBE.OrderBomHead.EntityList orderBom = OrderBomBE.OrderBomHead.Finder.FindAll("OrderLine=@SOLine", new OqlParam(shipLineEntity.SrcLineID));
                        dtoOne.TaxCredits        = CalculateDtoFieldShipExtend.GetTaxCredits(shipLineEntity, orderBom);                               //退税额
                        dtoOne.ProcurementCost   = CalculateDtoFieldShipExtend.GetProcurementCost(shipLineEntity, orderBom);                          //包装采购成本
                        dtoOne.LabourCharges     = CalculateDtoFieldShipExtend.GetLabourCharges(shipLineEntity);                                      //包装人工费用
                        dtoOne.ProductCost       = CalculateDtoFieldShipExtend.GetProductCost(shipLineEntity, orderBom, ref rmbCost, ref dollorCost); //产品采购成本
                        dtoOne.RMBProductCost    = rmbCost;                                                                                           //工具人民币采购成本
                        dtoOne.DollorProductCost = dollorCost;                                                                                        //工具美元采购成本
                        dtoOne.AdministrativeFee = CalculateDtoFieldShipExtend.GetAdministrativeFee(shipLineEntity);                                  //管理费
                        dtoOne.Interest          = CalculateDtoFieldShipExtend.GetInterest(shipLineEntity);                                           //利息
                        dtoOne.MouldFee          = CalculateDtoFieldShipExtend.GetMouldFee(shipLineEntity);                                           //模具费‘
                        dtoOne.Labelling         = CalculateDtoFieldShipExtend.GetLabelling(shipLineEntity, orderBom);                                //防盗标签费
                        dtoOne.CreditInsurance   = CalculateDtoFieldShipExtend.GetCreditInsurance(shipLineEntity);                                    //信用保险费
                        dtoOne.BankCharge        = CalculateDtoFieldShipExtend.GetBankCharge(shipLineEntity);                                         //银行费用

                        //dtoOne.OrderBomHead = orderBom;//随单Bom
                        dtoOne.ForecastTime = DateTime.Now;
                        dtoOne.ForecastMan  = UFIDA.U9.Base.Context.LoginUser;

                        //成品预测利润:各中类成品外销额-成品各项费用+成品退税额
                        allFee = dtoOne.Brokerage + dtoOne.Discount + dtoOne.OceanFreight + dtoOne.OtherFee + dtoOne.DomesticFee + dtoOne.OtherDomesticFee +
                                 dtoOne.ProcurementCost + dtoOne.LabourCharges + dtoOne.ProductCost + dtoOne.AdministrativeFee + dtoOne.Interest + dtoOne.MouldFee +
                                 dtoOne.Labelling + dtoOne.CreditInsurance + dtoOne.BankCharge;

                        //dtoOne.ProductForecastRate = shipLineEntity.TotalTax - allFee + dto.TaxCredits;
                        //dtoOne.ProductRate = dto.ProductForecastRate / shipLineEntity.TotalTax;

                        //反写出运明细单预测状态

                        dtoList.Add(dtoOne);
                        #endregion
                    }
                    seesion.Commit();
                }
            }
            else
            {
                throw new Exception("未选择任何需要预测的订单");
            }
            return(dtoList);
            //CreatEntity(dtoList);
        }