/// <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, OrderBomLine 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='" + soLine.ItemInfo.ItemID.ID + "' and FromDate<='" + DateTime.Now + "' and ToDate>='" + DateTime.Now + "'"); if (type == 2 && purPriceLine == null) //工具子件取不到价格,取销售订单行成品成本 { return(0); } else if (purPriceLine == null) { throw new Exception("销售订单" + soLine.SO.DocNo + "行" + soLine.DocLineNo + "对应料品" + soLine.ItemInfo.ItemName + "没有取到价格,请手工录入价表"); } } else if (bomLine.SubKey != null)//子件 { purPriceLine = UFIDA.U9.PPR.PurPriceList.PurPriceLine.Finder.Find("ItemInfo='" + bomLine.SubKey.ID + "' and FromDate<='" + DateTime.Now + "' and ToDate>='" + DateTime.Now + "'"); if (type == 2 && purPriceLine == null) //工具子件取不到价格,取销售订单行成品成本 { return(0); } else if (purPriceLine == null) { throw new Exception("销售订单" + soLine.SO.DocNo + "行" + soLine.DocLineNo + "对应料品" + 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; }
/// <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);//递归 } } } } }