/// <summary> /// after Update /// </summary> protected override void OnUpdated() { SM.SO.SOLine soLine = null; using (ISession session = Session.Open()) { decimal shippedQty = 0; soLine = SM.SO.SOLine.Finder.FindByID(this.SrcLineID); if (soLine != null) { //校验修改的数量是否等于或者小于来源销售订单行.数量-来源销售订单行.已出运数量, // 如果大于,则修改无效,不提示,将数量还原至修改前, if (soLine.DescFlexField.PrivateDescSeg8 != "") { shippedQty = Convert.ToDecimal(soLine.DescFlexField.PrivateDescSeg8); } //if (this.Qty > soLine.OrderByQtyTU - shippedQty) // this.Qty = this.OriginalData.Qty;//数量未改变 //else //{ // //数量改变 // //反写来源销售订单行.已出运数量(弹性域字段) // soLine.DescFlexField.PrivateDescSeg8 = (shippedQty + this.Qty - this.OriginalData.Qty).ToString(); //} //反写来源销售订单行.已出运数量(弹性域字段) soLine.DescFlexField.PrivateDescSeg8 = (shippedQty + this.Qty - this.OriginalData.Qty).ToString(); } session.Commit(); } base.OnUpdated(); // TO DO: write your business code here... }
/// <summary> /// 计算信用保险保费, /// </summary> /// <param name="soLine"></param> /// <returns></returns> public static decimal GetCreditInsurance(SM.SO.SOLine soLine) { decimal creditInsurance = 0; //客户档案中维护,信用保险费率。 ---客户的扩展字段 //公式:∑(订单行金额*费率)。 //先有订单行金额,在汇总到单头。 //信用保险费率会存在多个,当存在多个时,取最高值 if (soLine.SO.OrderBy.Customer.DescFlexField.PrivateDescSeg1 != "") { creditInsurance = soLine.TotalMoneyTC * decimal.Parse(soLine.SO.OrderBy.Customer.DescFlexField.PrivateDescSeg1); } //EntityDataQuery customerQ = CBO.SCM.Customer.Customer.Finder.CreateDataQuery(); //customerQ.FindValue("Select "); //CBO.SCM.Customer.Customer customer = CBO.SCM.Customer.Customer.Finder.FindByID(soLine.SO.OrderBy.CustomerKey); //if (customer != null) //{ // decimal credit1 = 0, credit2 = 0;//客户的信用费率 // if (customer.DescFlexField.PrivateDescSeg1 == "" && customer.DescFlexField.PrivateDescSeg2 == "") // return 0; // credit1 = decimal.Parse(customer.DescFlexField.PrivateDescSeg1); // credit2 = decimal.Parse(customer.DescFlexField.PrivateDescSeg2); // if (credit1 >= credit2) // { // return credit1 * soLine.TotalMoneyTC; // } // else // { // return credit2 * soLine.TotalMoneyTC; // } //} return(creditInsurance); }
/// <summary> /// before Update /// </summary> protected override void OnUpdating() { //出运数量不能大于可出运数量 SM.SO.SOLine soLine = null; soLine = SM.SO.SOLine.Finder.FindByID(this.SrcLineID); decimal shippedQty = 0; //已出运数量 if (soLine != null) { //校验修改的数量是否等于或者小于来源销售订单行.数量-来源销售订单行.已出运数量, // 如果大于,则修改无效,不提示,将数量还原至修改前, if (soLine.DescFlexField.PrivateDescSeg8 != "") { shippedQty = Convert.ToDecimal(soLine.DescFlexField.PrivateDescSeg8); } if (this.Qty - this.OriginalData.Qty > soLine.OrderByQtyTU - shippedQty) { throw new Exception("出运明细单" + this.ShipPlanDetailHead.DocNo + "行" + this.RowNo + "本次出运数量不能大于可出运数量" + (soLine.OrderByQtyTU - shippedQty + this.OriginalData.Qty)); } } //判断总体积/5000(系统预制参数)和毛重的大小,取两者的最大值赋值给体积重量字段; if (this.SumBulk / 5000 > this.SumGross) { this.VolumeWeight = this.SumBulk; } else { this.VolumeWeight = this.SumGross; } base.OnUpdating(); // TO DO: write your business code here... }
/// <summary> /// 计算行佣金,(销售订单行扩展字段?) /// </summary> /// <param name="soLine">销售订单行</param> /// <returns>行佣金</returns> public static decimal GetBrokerage(SM.SO.SOLine soLine) { //销售订单行扩展字段:佣金生成状态为true计算佣金, if (soLine.DescFlexField.PrivateDescSeg6 == "" || soLine.DescFlexField.PrivateDescSeg6.ToLower() == "false") { return(0); } if (soLine.SO.OrderBy == null || soLine.SO.OrderBy.CustomerKey == null) { return(0); } // OrderLineBrokerage.EntityList orderLineList = OrderLineBrokerage.Finder.FindAll("ShipPlanLine=@ShipPlanLine,Client=@Custmer ,Product=@Product", new OqlParam(shipLine.ID), new OqlParam(shipLine.ShipPlanDetailHead.ClientKey), new OqlParam(shipLine.ItemKey)); OrderLineBrokerage.EntityList brokerageList = OrderLineBrokerage.Finder.FindAll("OrderLineID=@OrderLineID and Client=@Custmer and Product=@Product", new OqlParam(soLine.ID), new OqlParam(soLine.SO.OrderBy.CustomerKey), new OqlParam(soLine.ItemInfo.ItemIDKey)); if (brokerageList == null || brokerageList.Count < 1) { return(0); } decimal brokerage = 0; foreach (OrderLineBrokerage line in brokerageList) { brokerage += line.Prices; } return(brokerage); }
/// <summary> /// after Delete /// </summary> protected override void OnDeleted() { using (ISession session = Session.Open()) { if (this.OriginalData.SOLine != null) { CostForecastBE.CostForecast.EntityList lineList = CostForecastBE.CostForecast.Finder.FindAll("SOLine=" + this.OriginalData.SOLine.ID + ""); SM.SO.SOLine line = SM.SO.SOLine.Finder.FindByID(this.OriginalData.SOLine.ID); if (line != null) { if (lineList == null || lineList.Count == 0) { line.DescFlexField.PrivateDescSeg18 = AllEnumBE.ForecastStateEnum.N.Name.ToString(); } else { line.DescFlexField.PrivateDescSeg18 = AllEnumBE.ForecastStateEnum.Y.Name.ToString(); } } } session.Commit(); } base.OnDeleted(); // TO DO: write your business code here... }
/// <summary> /// 计算折扣 /// </summary> /// <param name="soLine"></param> /// <returns></returns> public static decimal GetDiscount(SM.SO.SOLine soLine) { decimal discont = 0; discont = soLine.DiscountTC;//销售订单行的折扣额 return(discont); }
/// <summary> /// 计算包装采购成本, /// </summary> /// <param name="shipLine"></param> /// <returns></returns> public static decimal GetProcurementCost(GS.FT.ShipPlanDetailBE.ShipPlanDetailLine shipLine, OrderBomBE.OrderBomHead.EntityList orderBom) { decimal procurementCost = 0; //全部成品采购,无包装BOM:取中类上包装采购价格。 //明细单行中类对应的中类包装价*订单行中类数量 //全部成品委外。 //公式:明细单行中类对应的子件采购合价*子件数量 //1)先算子件数量(含放的余量) //2)子件单位成本*子件数量 //先算明细单行成本金额,再汇总到明细单头。 decimal purchasePrice = 0; SM.SO.SOLine soLine = SM.SO.SOLine.Finder.FindByID(shipLine.SrcLineID); if (orderBom == null) //随单BOM为空,即计算成品采购; { //purchasePrice = GetPurchasePrice(0, shipLine, null); purchasePrice = 0; } else //子件退税额 { foreach (OrderBomBE.OrderBomHead bomLine in orderBom) { if (bomLine.SubKey.StockCategory.Code != "03")//不为包材小类,不计算包装成本 { continue; } purchasePrice = GetPurchasePrice(1, shipLine, bomLine); //先算子件数量 //2)再算子件成本=子件合同单价*子件数量 decimal sumQty = bomLine.NeedNumber / soLine.OrderByQtyTU * shipLine.Qty;//子件数量: } } return(procurementCost); }
/// <summary> /// 计算退税额, /// </summary> /// <param name="soLine">销售订单行</param> /// <param name="orderBom">随单BOM</param> /// <returns></returns> public static decimal GetTaxCredits(SM.SO.SOLine soLine, OrderBomBE.OrderBomHead.EntityList orderBom) { decimal taxCredits = 0;//计算的单行退税额 //退税率:料品私有字段9 // 成本的减项,根据中类退税率自动算出 //公式:订单行中类工具子件单位成本*子件用量*订单行中类数量*中类退税率 //取价退税时,子件最近一次的采购价为美金时,采购费用不退税。 //订单行中类非进口的工具子件单位成本的计算方式: //料品的商品类型:工具子件、包材子件、工具成品(就是指中类) //销售订单行的包装工厂如果为外厂包装(委外业务)、内厂包装(自制),展开BOM,卷积子件成本,没BOM报错 //销售订单行的外厂成品直接取成品采购价格 decimal taxRefundRate = 0;//退税率 if (soLine.ItemInfo.ItemIDKey.GetEntity().DescFlexField.PrivateDescSeg9 != "") { taxRefundRate = Convert.ToDecimal(soLine.ItemInfo.ItemIDKey.GetEntity().DescFlexField.PrivateDescSeg9); } else { throw new Exception("请维护销售订单" + soLine.SO.DocNo + "行" + soLine.DocLineNo + "对应料品退税率"); } decimal purchasePrice = 0; //采购价 int currencyType = 0; //采购币种标记 //if (soLine.ItemInfo.ItemIDKey.GetEntity().StockCategory == null) //{ // throw new Exception("销售订单" + soLine.SO.DocNo + "行" + soLine.DocLineNo + "对应的料品没有设置料品分类"); //} //if (soLine.DescFlexField.PubDescSeg18 == "03") ////如果是成品采购,根据包装工厂为外厂成品区分 //if (soLine.ItemInfo.ItemIDKey.GetEntity().StockCategory != null && soLine.ItemInfo.ItemIDKey.GetEntity().StockCategory.Code == "01") //中类直接取最近采购价格 if (orderBom == null) //随单BOM为空,即计算成品采购; { DataSet ds = new DataSet(); string sql = "select top 1 B.OrderPriceTC,A.TC from PM_POLine b left join PM_PurchaseOrder a on b.PurchaseOrder=a.id where b.ItemInfo_ItemID=" + soLine.ItemInfo.ItemID.ID + " and Org=" + UFIDA.U9.Base.Context.LoginOrg.ID + " order by a.BusinessDate desc"; UFSoft.UBF.Util.DataAccess.DataAccessor.RunSQL(UFSoft.UBF.Util.DataAccess.DataAccessor.GetConn(), sql, null, out ds); purchasePrice = CalculatePurchasePrice(0, soLine, null, ds, ref currencyType); return(purchasePrice * soLine.OrderByQtyTU * taxRefundRate); } else //计算子件退税额 { //获取子项 DataSet ds = new DataSet(); string sql = ""; foreach (OrderBomHead line in orderBom) { if (line.SubKey != null && line.SubKey.Code == "FDBQ") //防盗标签子件不退税 { continue; } sql = "select top 1 B.OrderPriceTC,A.TC from PM_POLine b left join PM_PurchaseOrder a on b.PurchaseOrder=a.id where b.ItemInfo_ItemID=" + line.SubKey.ID + " and Org=" + UFIDA.U9.Base.Context.LoginOrg.ID + " order by a.BusinessDate desc"; UFSoft.UBF.Util.DataAccess.DataAccessor.RunSQL(UFSoft.UBF.Util.DataAccess.DataAccessor.GetConn(), sql, null, out ds); purchasePrice = CalculatePurchasePrice(0, soLine, line, ds, ref currencyType); //taxCredits += purchasePrice * line.OrderBomHead.Dosage * soLine.OrderByQtyTU * taxRefundRate; //子件成本=子件的采购单价*需求数量,需求数量=子件的用量比例*中类的销售数量(即为随单BOM行的需要数量) taxCredits += purchasePrice * line.NeedNumber * taxRefundRate; } } return(taxCredits); }
private static decimal GetPurchasePrice(SM.SO.SOLine soLine) { decimal purchasePrice = 0; //取采购合同价格,根据销售订单行-供应计划行-采购订单行,从采购订单取价格 return(purchasePrice); }
/// <summary> /// 计算银行费用 /// </summary> /// <param name="soLine"></param> /// <returns></returns> public static decimal GetBankCharge(SM.SO.SOLine soLine) { decimal bankCharge = 0; //销售订单头私有字段15 if (soLine.SO.DescFlexField.PrivateDescSeg15 != "" && soLine.SO.DescFlexField.PrivateDescSeg15 != "0") { bankCharge = decimal.Parse(soLine.SO.DescFlexField.PrivateDescSeg15) / soLine.SO.TotalMoneyAC * soLine.TotalMoneyTC; } return(bankCharge); }
/// <summary> /// 计算其他国内费 /// </summary> /// <param name="soLine">销售订单行</param> /// <returns></returns> public static decimal GetOtherDomesticFee(SM.SO.SOLine soLine) { decimal otherDomesticFee = 0; //单行的其他国内费用=其他国内费用/整单金额*单行的金额(金额为外销价) if (soLine.SO.DescFlexField.PrivateDescSeg7 == "") //单头其他国内费用 { return(0); } otherDomesticFee = decimal.Parse(soLine.SO.DescFlexField.PrivateDescSeg7) / soLine.SO.TotalMoneyAC * decimal.Parse(soLine.DescFlexField.PrivateDescSeg5); return(otherDomesticFee); }
/// <summary> /// 计算防盗标签费 /// </summary> /// <param name="soLine"></param> /// <returns></returns> public static decimal GetLabelling(SM.SO.SOLine soLine, OrderBomBE.OrderBomHead.EntityList orderBom) { decimal labelling = 0; //BOM中防盗标签子件,则根据【防盗标签】最近一次采购价,币种,不退税。 //BOM中没有防盗标签子件,则手工输入。 //中类需要一个字段来标识需要防盗标签,子件通过物料分类来区分防盗标签 //销售行防盗标签费扩展字段 //if (soLine.DescFlexField.PrivateDescSeg7 == "") //{ // //throw new Exception("请维护销售单" + soLine.SO.DocNo + "行" + soLine.DocLineNo + "对应的防盗标签费"); //} decimal purchasePrice = 0;//采购价 DataSet ds = new DataSet(); string sql = ""; if (orderBom != null) { foreach (OrderBomHead line in orderBom) { ds = new DataSet(); sql = ""; if (line.SubKey != null && line.SubKey.Code == "FDBQ") { //取最近采购价 sql = "select top 1 B.OrderPriceTC,A.TC from PM_POLine b left join PM_PurchaseOrder a on b.PurchaseOrder=a.id where b.ItemInfo_ItemID=" + line.SubKey.ID + " and Org=" + UFIDA.U9.Base.Context.LoginOrg.ID + " order by a.BusinessDate desc"; UFSoft.UBF.Util.DataAccess.DataAccessor.RunSQL(UFSoft.UBF.Util.DataAccess.DataAccessor.GetConn(), sql, null, out ds); 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 (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; } } labelling += purchasePrice * line.NeedNumber; } } } if (labelling == 0)//未取到防盗标签费,取销售订单行 { labelling = decimal.Parse(soLine.DescFlexField.PrivateDescSeg7); } return(labelling); }
/// <summary> /// after Insert /// </summary> protected override void OnInserted() { SM.SO.SOLine soLine = null; using (ISession session = Session.Open()) { decimal shippedQty = 0; soLine = SM.SO.SOLine.Finder.FindByID(this.SrcLineID); if (soLine != null) { //校验修改的数量是否等于或者小于来源销售订单行.数量-来源销售订单行.已出运数量, // 如果大于,则修改无效,不提示,将数量还原至修改前, if (soLine.DescFlexField.PrivateDescSeg8 != "") { shippedQty = Convert.ToDecimal(soLine.DescFlexField.PrivateDescSeg8); } soLine.DescFlexField.PrivateDescSeg8 = (shippedQty + this.Qty).ToString(); #region 生成订单佣金 if (soLine.DescFlexField.PrivateDescSeg6.ToLower() == "true") { OrderLineBrokerage.EntityList brokerage = OrderLineBrokerage.Finder.FindAll("OrderLineID='" + soLine.ID + "'"); if (brokerage != null && brokerage.Count > 0) { OrderLineBrokerage shipLineBroke = null; foreach (OrderLineBrokerage orderBrokerage in brokerage) { shipLineBroke = OrderLineBrokerage.Create(); shipLineBroke.SourceType = AllEnumBE.SourceTypeEnum.ShipPlanDoc; shipLineBroke.ShipPlanLine = this; shipLineBroke.ShipPlanRowNo = this.RowNo; shipLineBroke.Client = orderBrokerage.Client; shipLineBroke.Product = orderBrokerage.Product; shipLineBroke.BrokerageRatio = orderBrokerage.BrokerageRatio; shipLineBroke.Payee = orderBrokerage.Payee; shipLineBroke.Prices = orderBrokerage.Prices; //支付金额根据明细单数量计算 shipLineBroke.PayAmount = orderBrokerage.PayAmount / soLine.OrderByQtyTU * this.Qty; shipLineBroke.PayCurrency = orderBrokerage.PayCurrency; //shipLineBroke.OutPayment = orderBrokerage.OutPayment; shipLineBroke.OrderCurrency = orderBrokerage.OrderCurrency; shipLineBroke.Rate = orderBrokerage.Rate; shipLineBroke.SrcBrokerageLine = orderBrokerage.SrcBrokerageLine; } } } #endregion } session.Commit(); } base.OnInserted(); // TO DO: write your business code here... }
/// <summary> /// 计算管理费 /// </summary> /// <param name="soLine"></param> /// <returns></returns> public static decimal GetAdministrativeFee(SM.SO.SOLine soLine) { decimal administrativeFee = 0; //每年固定比例,按比例承担 // 公式:每个中类总金额*管理费固定比例 //先算订单行各个中类成本金额,再汇总到订单头 //需求:希望U9中设置[费用项目-管理费]比例 if (m_managementFee == 0) { throw new Exception("请维护参数设置中的管理费固定比例"); } administrativeFee = soLine.TotalMoneyTC * m_managementFee; return(administrativeFee); }
/// <summary> /// after Insert /// </summary> protected override void OnInserted() { using (ISession sesion = Session.Open()) { if (this.SOLine != null) { SM.SO.SOLine line = SM.SO.SOLine.Finder.FindByID(this.SOLine.ID); if (line != null) { line.DescFlexField.PrivateDescSeg18 = AllEnumBE.ForecastStateEnum.Y.Name.ToString(); } } sesion.Commit(); } base.OnInserted(); // TO DO: write your business code here... }
/// <summary> /// 计算模具费 /// </summary> /// <param name="soLine"></param> /// <returns></returns> public static decimal GetMouldFee(SM.SO.SOLine soLine) { decimal mouldFee = 0; //料品的模具费扩展字段???还是销售订单?? //应该是销售订单的模具费 //标准销售订单审核时,计算订单行模具费=料品.模具费/料品.预期销量*销售订单行.数量, //如果订单行数量大于料品.预期销量-料品.已销量,则订单模具费等于料品.模具费-料品.已分摊模具费, //如果料品.模具费-料品.已分摊模具费等于0,则订单模具费等于0, if (soLine.ItemInfo.ItemIDKey.GetEntity().DescFlexField.PrivateDescSeg4 == "") //是否可空,不是很确定??? { //throw new Exception("请维护销售单" + soLine.SO.DocNo + "行" + soLine.DocLineNo + "对应的料品模具费"); return(0); } mouldFee = decimal.Parse(soLine.ItemInfo.ItemIDKey.GetEntity().DescFlexField.PrivateDescSeg4) * soLine.OrderByQtyTU; return(mouldFee); }
private void CollectHeadData() { if (this.CustomsSingle == -1) { this.CustomsSingle = 0; } //汇总所有行所对应的明细单佣金中的支付金额,赋值至“出运明细单.佣金”字段中 //汇总所有行的价税合计至“出运明细单.价税合计”字段中 //汇总所有行中的总箱数、毛重、净重、体积至“出运明细单.总件数”、“出运明细单.总毛重”、“出运明细单.总净重”、“出运明细单.总体积 //循环行,判断总体积/5000(系统预制参数)和毛重的大小,取两者的最大值赋值给体积重量字段; decimal brokerage = 0; //佣金 decimal totalTax = 0; //价税合计 decimal discount = 0; //折扣 decimal sumGross = 0, sumSuttle = 0, sumBulk = 0; //毛重、净重、体积 int sumNumber = 0; //总箱数 decimal shippedQty = 0; //销售订单的已出运数量 OrderLineBrokerage.EntityList orderLine = null; SM.SO.SOLine soLine = null; foreach (ShipPlanDetailLine shipLine in this.ShipPlanDetailLine) { //修改出运明细单行.价税合计=出运明细单行.单价*修改后出运明细单行.数量, shipLine.TotalTax = shipLine.Ultimately * shipLine.Qty; discount += (shipLine.ExportSales - shipLine.Ultimately) * shipLine.Qty; orderLine = OrderLineBrokerage.Finder.FindAll("ShipPlanLine=" + shipLine.ID + "");//佣金汇总 foreach (OrderLineBrokerage line in orderLine) { brokerage += line.PayAmount; } totalTax += shipLine.TotalTax; sumNumber += shipLine.SumBoxNumber; sumGross += shipLine.SumGross; sumSuttle = shipLine.NetWeight; sumBulk += shipLine.Bulks; //this. } this.Brokerage = brokerage; this.TotalTax = totalTax; this.SumNumber = sumNumber; this.SumGross = sumGross; this.SumSuttle = sumSuttle; this.SumBulk = sumBulk; this.Discount = discount; }
/// <summary> /// 计算其他国外费 /// </summary> /// <param name="soLine"></param> /// <returns></returns> public static decimal GetOtherOceanFreight(SM.SO.SOLine soLine) { decimal oceanOtherFreight = 0; //分摊的行其他国外费 decimal othrerFreightRates = 0; //销售订单头扩展字段的其他国外费 //单行的其他国外费用=其他国外费用/整单金额*单行的金额 if (soLine.SO.DescFlexField.PrivateDescSeg8 == null || soLine.SO.DescFlexField.PrivateDescSeg8 == "") { //throw new Exception("销售订单"+soLine.SO.DocNo+"国际其他费用不能为空"); return(0); } othrerFreightRates = decimal.Parse(soLine.SO.DescFlexField.PrivateDescSeg8); if (othrerFreightRates == 0) { //throw new Exception("国际其他费用不能为0"); return(0); } oceanOtherFreight = othrerFreightRates / soLine.SO.TotalMoneyAC * soLine.TotalMoneyTC; return(oceanOtherFreight); }
/// <summary> /// 计算包装人工费用 /// </summary> /// <param name="soLine"></param> /// <returns></returns> public static decimal GetLabourCharges(SM.SO.SOLine soLine) { decimal labourCharges = 0; //销售订单行上,如果是【内厂包装】、【内/外厂包装】,从中类档案上【工具包装人工费】取, //如果取得不到,则手工输入,并反写到中类,如果是【外厂包装】,无包装人工费。 //公式:订单行中类对应的包装人工费*订单行数量 if (soLine.DescFlexField.PubDescSeg18 == "01" || soLine.DescFlexField.PubDescSeg18 == "02") //行扩展字段包装工厂 { if (soLine.ItemInfo.ItemIDKey.GetEntity().DescFlexField.PrivateDescSeg7 == "") { labourCharges = 0; //throw new Exception("销售订单" + soLine.SO.DocNo + "行" + soLine.DocLineNo + "对应料品" + soLine.ItemInfo.ItemName + "没有录入包装人工费"); } else { labourCharges = decimal.Parse(soLine.ItemInfo.ItemIDKey.GetEntity().DescFlexField.PrivateDescSeg7) * soLine.OrderByQtyTU; } } return(labourCharges); }
/// <summary> /// after Delete /// </summary> protected override void OnDeleted() { SM.SO.SOLine soLine = null; using (ISession session = Session.Open()) { decimal shippedQty = 0; soLine = SM.SO.SOLine.Finder.FindByID(this.SrcLineID); if (soLine != null) { //校验修改的数量是否等于或者小于来源销售订单行.数量-来源销售订单行.已出运数量, // 如果大于,则修改无效,不提示,将数量还原至修改前, if (soLine.DescFlexField.PrivateDescSeg8 != "") { shippedQty = Convert.ToDecimal(soLine.DescFlexField.PrivateDescSeg8); } if (shippedQty - this.Qty <= 0) { soLine.DescFlexField.PrivateDescSeg8 = "0"; } else { soLine.DescFlexField.PrivateDescSeg8 = (shippedQty - this.Qty).ToString(); } #region 除订单佣金 OrderLineBrokerage.EntityList brokerage = OrderLineBrokerage.Finder.FindAll("ShipPlanLine='" + this.OriginalData.ID + "'"); if (brokerage != null && brokerage.Count > 0) { foreach (OrderLineBrokerage orderBrokerage in brokerage) { orderBrokerage.Remove(); } } #endregion } session.Commit(); } base.OnDeleted(); // TO DO: write your business code here... }
/// <summary> /// 计算产品采购成本 /// </summary> /// <param name="shipLine">销售行</param> /// <param name="rmbCost">人民币采购成本</param> /// <param name="dollorCost">美元采购成本</param> /// <returns></returns> public static decimal GetProductCost(GS.FT.ShipPlanDetailBE.ShipPlanDetailLine shipLine, OrderBomBE.OrderBomHead.EntityList orderBom, ref decimal rmbCost, ref decimal dollorCost) { decimal productCost = 0; // 取【批号装配关系表】中的中类批号对应的成品或子件批号价格。 //全部纯成品采购:取中类采购合同价格。包装工厂判断 //明细单行中类对应的中类成品采购合同价*明细单行中类数量 //全部成品委外: //公式:明细单行中类对应的子件采购合价*子件数量 //1)先算子件数量(含放的余量) //2)子件单位成本*子件数量 // 先算明细单行成本金额,再汇总到明细单头。 decimal purchasePrice = 0; SM.SO.SOLine soLine = SM.SO.SOLine.Finder.FindByID(shipLine.SrcLineID); if (orderBom == null || orderBom.Count == 0) //随单BOM为空,即计算成品采购; { purchasePrice = GetPurchasePrice(0, shipLine, null); productCost = purchasePrice * shipLine.Qty; } else //子件退税额 { foreach (OrderBomBE.OrderBomHead bomLine in orderBom) { if (bomLine.SubKey.StockCategory.Code != "02")//不为工具小类,不计算成本 { continue; } purchasePrice = GetPurchasePrice(1, shipLine, bomLine); //先算子件数量 //2)再算子件成本=子件合同单价*子件数量 decimal sumQty = bomLine.NeedNumber / soLine.OrderByQtyTU * shipLine.Qty;//子件数量: } } return(productCost); }
/// <summary> /// 计算年利息 /// </summary> /// <param name="soLine"></param> /// <returns></returns> public static decimal GetInterest(SM.SO.SOLine soLine) { decimal interest = 0; // 固定利率,主要是年息 //公式:订单行每个中类利息=年息7.47/365*(收汇天数+15)*单价*订单行数量 //先算订单行各个中类利息成本金额,再汇总到订单头 //需求:U9中年息需要统一维护。 //客户扩展字段:收汇天数 if (soLine.SO.OrderBy.Customer.DescFlexField.PubDescSeg1 == "") { //throw new Exception("销售订单"+soLine.SO.DocNo+"对应客户没有录入收汇天数"); return(0); } decimal tradeDay = decimal.Parse(soLine.SO.OrderBy.Customer.DescFlexField.PubDescSeg1); if (tradeDay == 0) { //throw new Exception("销售订单"+soLine.SO.DocNo+"对应客户没有录入收汇天数"); return(0); } interest = m_annualInterest / 365 * (tradeDay + 15) * soLine.FinallyPriceTC * soLine.OrderByQtyTU; return(interest); }
/// <summary> /// 计算工具采购成本 /// </summary> /// <param name="soLine">销售行</param> /// <param name="rmbCost">人民币采购成本</param> /// <param name="dollorCost">美元采购成本</param> /// <returns></returns> public static decimal GetProductCost(SM.SO.SOLine soLine, ref decimal rmbCost, ref decimal dollorCost, OrderBomBE.OrderBomHead.EntityList orderBom) { decimal productCost = 0; //如果成品采购: //取成品采购最近一次采购价,如果读取不到,则手工输入; //如果是子件采购: //根据小类最近一次采购价、币别取价。 //公式:订单行中类对应的子件采购单价*子件数量 //1)先算子件数量 //2)子件单位成本*子件数量 //先算订单行成本金额,再汇总到订单头 //委外/生产,工具子件/包装子件采购成本取价: //1)无BOM时,手工填写工具子件\包材子件采购成本。 //2)有BOM时,老物料优先取最新实际成本(最新价表),如果取不到,手工填写工具子件\包材子件采购成本。 decimal purchaseCost = 0; decimal purchasePrice = 0; //采购价 int currencyType = 0; //采购币种标记 //if (soLine.ItemInfo.ItemIDKey.GetEntity().StockCategory.Code == "01") //中类直接取最近采购价格 //if (soLine.DescFlexField.PubDescSeg18 == "03") ////如果是成品采购, if (orderBom == null || orderBom.Count == 0) //随单BOM为空,取中类采购价 { DataSet ds = new DataSet(); string sql = "select top 1 B.OrderPriceTC,A.TC from PM_POLine b left join PM_PurchaseOrder a on b.PurchaseOrder=a.id where b.ItemInfo_ItemID=" + soLine.ItemInfo.ItemID.ID + " and Org=" + UFIDA.U9.Base.Context.LoginOrg.ID + " order by a.BusinessDate desc"; UFSoft.UBF.Util.DataAccess.DataAccessor.RunSQL(UFSoft.UBF.Util.DataAccess.DataAccessor.GetConn(), sql, null, out ds); purchasePrice = CalculatePurchasePrice(2, soLine, null, ds, ref currencyType); //取成品采购最近一次采购价,如果读取不到,则取销售订单行成品成本字段值 if (purchasePrice == 0 && soLine.DescFlexField.PrivateDescSeg23 != "") { purchasePrice = decimal.Parse(soLine.DescFlexField.PrivateDescSeg23); if (soLine.SO.TC.ID == 1) { currencyType = 1; } else if (soLine.SO.TC.ID == 9) { currencyType = 9; } } if (currencyType == 1) { rmbCost = purchasePrice; } else if (currencyType == 9) { dollorCost = purchasePrice; } purchaseCost = rmbCost + dollorCost; //return purchaseCost; } else { //获取子项 DataSet ds = new DataSet(); string sql = ""; foreach (OrderBomHead line in orderBom) { if (line.SubKey != null && line.SubKey.StockCategory != null && line.SubKey.StockCategory.Code == "02")//工具子件 { ds = new DataSet(); sql = "select top 1 B.OrderPriceTC,A.TC from PM_POLine b left join PM_PurchaseOrder a on b.PurchaseOrder=a.id where b.ItemInfo_ItemID=" + line.SubKey.ID + " and Org=" + UFIDA.U9.Base.Context.LoginOrg.ID + " order by a.BusinessDate desc"; UFSoft.UBF.Util.DataAccess.DataAccessor.RunSQL(UFSoft.UBF.Util.DataAccess.DataAccessor.GetConn(), sql, null, out ds); purchasePrice = CalculatePurchasePrice(2, soLine, line, ds, ref currencyType); if (currencyType == 1) { rmbCost += purchasePrice; } else if (currencyType == 9) { dollorCost += purchasePrice; } } } } //币种转换 if (dollorCost != 0 && soLine.SO.TC.ID == 1) { 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=9 and OperationalRateHead.NotCurrency=1 and OperationalRateHead.Org=" + UFIDA.U9.Base.Context.LoginOrg.ID); if (rateLine == null) { throw new Exception("美元对人民币的汇率未设置,请在基础设置-业务汇率表中设置"); } productCost = dollorCost * rateLine.Parities + rmbCost; } else if (rmbCost != 0 && soLine.SO.TC.ID == 9) { 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=1 and OperationalRateHead.NotCurrency=9 and OperationalRateHead.Org=" + UFIDA.U9.Base.Context.LoginOrg.ID); if (rateLine == null) { throw new Exception("人民币对美元的汇率未设置,请在基础设置-业务汇率表中设置"); } productCost = dollorCost + rmbCost * rateLine.Parities; } return(productCost); }
/// <summary> /// 计算退税额, /// </summary> /// <param name="shipLine"></param> /// <param name="orderBom"></param> /// <returns></returns> public static decimal GetTaxCredits(GS.FT.ShipPlanDetailBE.ShipPlanDetailLine shipLine, OrderBomBE.OrderBomHead.EntityList orderBom) { decimal taxCredits = 0; //1、全部成品委外公式:明细单行中类工具子件采购合同成本(不含税)*中类退税率。 // 1)先算子件数量 // 2)再算子件成本=子件合同单价*子件数量。 //如果是全部成品采购时,退税公式: //明细单行中类采购合同成本(不含税)*中类退税率 //是否退税的判断: //1)进口件采购不退税。 //2)在KJ组织标记,子件和供应商绑定时(货源表)设置是否为进口件,则子件合同存在该组合的采购时,不退税。(如果 //GJ存在,也可以使用该原则) //3)所有HK组织的采购不退税。 decimal purchasePrice = 0; if (shipLine.SrcLineID <= 0) { throw new Exception("出运明细单" + shipLine.ShipPlanDetailHead.DocNo + "行" + shipLine.RowNo + "来源为空"); } SM.SO.SOLine soLine = SM.SO.SOLine.Finder.FindByID(shipLine.SrcLineID); if (soLine == null) { throw new Exception("出运明细单" + shipLine.ShipPlanDetailHead.DocNo + "行" + shipLine.RowNo + "来源为空"); } decimal taxRefundRate = 0;//退税率 if (soLine.ItemInfo.ItemIDKey.GetEntity().DescFlexField.PrivateDescSeg9 != "") { taxRefundRate = Convert.ToDecimal(soLine.ItemInfo.ItemIDKey.GetEntity().DescFlexField.PrivateDescSeg9); } else { throw new Exception("请维护销售订单" + soLine.SO.DocNo + "行" + soLine.DocLineNo + "对应料品退税率"); } //if (soLine.DescFlexField.PubDescSeg18 == "03") ////如果是成品采购,根据包装工厂为外厂成品区分 if (orderBom == null) //随单BOM为空,即计算成品采购; { ////先根据销售订单号和行号查询采购订单行 //PM.PO.POLine.EntityList poLineList = PM.PO.POLine.Finder.FindAll("DescFlexSegments.PrivateDescSeg1='" + shipLine.SrcDocNo + "' and DescFlexSegments.PrivateDescSeg2='" + shipLine.SrcLineNo + "' and ItemInfo.ItemCode='"+shipLine.Item.Code+""); //// var max = poLineList.Max<PM.PO.POLine, DateTime>(p => p.PurchaseOrder.BusinessDate); ////取出最近销售订单行对应的最近采购行,可能只会有一个 //var lasterPM = poLineList.OrderByDescending<PM.PO.POLine, DateTime>(p => p.PurchaseOrder.BusinessDate).FirstOrDefault<PM.PO.POLine>(); //if (lasterPM != null) //{ // if (lasterPM.PurchaseOrder.DescFlexField.PrivateDescSeg2 != "J003") //HK组织不退税 // { // return 0; // } // //中类采购合同成本(不含税)*中类退税率 // if (taxRefundRate == 0) // throw new Exception("出运明细单" + shipLine.ShipPlanDetailHead.DocNo + "行" + shipLine.RowNo + "对应的料品退税率不能为0"); // taxCredits = lasterPM.NetMnyTC / lasterPM.PurQtyPU * taxRefundRate; //} purchasePrice = GetPurchasePrice(0, shipLine, null); taxCredits = purchasePrice * shipLine.Qty * taxRefundRate; } else //子件退税额 { foreach (OrderBomBE.OrderBomHead bomLine in orderBom) { ////取出最近销售订单行对应的最近采购行,可能只会有一个 //var lineByPoList = poLineList.Where<PM.PO.POLine>(p => p.ItemInfo.ItemCode == line.SubKey.Code); ////取最近一次采购价 //var lasterPM = lineByPoList.OrderByDescending<PM.PO.POLine, DateTime>(p => p.PurchaseOrder.BusinessDate).FirstOrDefault<PM.PO.POLine>(); //if (lasterPM != null) //{ // if (lasterPM.PurchaseOrder.DescFlexField.PrivateDescSeg2 != "J003") // { // //HK组织不退税 // } // else // { // //在KJ组织标记,子件和供应商绑定时(货源表)设置是否为进口件,则子件合同存在该组合的采购时,不退税。 // //(如果GJ存在,也可以使用该原则) // //暂时无法判断进口件, // //明细单行中类工具子件采购合同成本(不含税)*中类退税率。 // //先算子件数量 // //2)再算子件成本=子件合同单价*子件数量 // decimal price = line.NeedNumber / soLine.OrderByQtyTU * shipLine.Qty ;//子件数量: // taxCredits += lasterPM.NetMnyTC / lasterPM.PurQtyPU * price * taxRefundRate; // } //} purchasePrice = GetPurchasePrice(0, shipLine, bomLine); //先算子件数量 //2)再算子件成本=子件合同单价*子件数量 decimal sumQty = bomLine.NeedNumber / soLine.OrderByQtyTU * shipLine.Qty;//子件数量: taxCredits += purchasePrice * sumQty * taxRefundRate; } } return(taxCredits); }
private int CloseShipPlan(long shipPlanID, int closeType) { UFIDA.U9.Cust.GS.FT.ShipPlanDetailBE.ShipPlanDetailHead shipPlan = UFIDA.U9.Cust.GS.FT.ShipPlanDetailBE.ShipPlanDetailHead.Finder.FindByID(shipPlanID); if (shipPlan == null) { throw new Exception("没有对应的出运明细单,无法操作"); } using (ISession session = Session.Open()) { switch (closeType) { case 1: //付款关闭 shipPlan.BillClose = true; shipPlan.BillCloseDate = DateTime.Now; break; case 2: //财务关闭 shipPlan.FeeClose = true; shipPlan.FeeCloseDate = DateTime.Now; break; case 3: shipPlan.BizClose = true; shipPlan.BizCloseDate = DateTime.Now; break; case 4: //提交理单 if (shipPlan.Status != AllEnumBE.DocumnetSate.ApprovedSate) { throw new Exception("只有审核状态才可以提交理单"); } shipPlan.IsManage = true; break; case 5: //出运确认 if (shipPlan.Status != AllEnumBE.DocumnetSate.ApprovedSate) { throw new Exception("只有审核状态才可以出运确认"); } //如果来源销售订单行有标识需要第三方验货(验货过程发生在WMS中),则需要判断订单行上是否有实际验货日期, //如果没有,则不允许进行出运确认,否则将出运状态变更为“已出运”,并且单据不允许再弃审, //同时只有在已出运的情况下才允许进行后续的成本决算以及财务核算,同时需要校验料品是否已上传图片, //如果没有,则不允许出运确认 //出运确认时需要进行以下校验: //1、 如果中类的图片有没有上传齐全,如果没有上传齐全,则不允许出运确认; //备注:BOM需要开发BE插件,上传一个子件图片后,则需要反写母件中的图片上传齐全标识,同时要注意反写母件的母件的齐全标识 //2、如果订单行中类需要第三方验货,但是没有验货日期,则不允许出运确认; //3、如果预制参数中的“质检评估控制出运”为True,则判断当前销售订单所对应的评估单的评估结果是否全部为合格,查找条件: //select max(评估日期) from 评估单明细表 where 来源销售订单号=销售订单.单号 and 评估结果=不合格 group by 料品,如果查出结果大于等于1,则不允许出运确认 //4、校验出运明细单与标准出货单是否存在差异,如果存在差异,一期提示,人为的调整出运明细单差异与出货保持一致 SM.SO.SOLine soLine = null; string soIDstr = ""; foreach (ShipPlanDetailBE.ShipPlanDetailLine line in shipPlan.ShipPlanDetailLine) { soLine = SM.SO.SOLine.Finder.FindByID(line.SrcLineID); if (soLine != null) { if (!soIDstr.Contains(soLine.SO.ID.ToString())) { soIDstr += soLine.SO.ID.ToString() + ","; } //1、种类图片齐全校验 //2、验货校验,如果来源销售订单行有标识需要第三方验货, if (soLine.DescFlexField.PrivateDescSeg12 != "" && soLine.DescFlexField.PrivateDescSeg12 != "01") { if (soLine.DescFlexField.PrivateDescSeg11 == "") { throw new Exception("出运明细行" + line.RowNo + "对应的销售订单行" + soLine.DocLineNo + "为第三方验货,但是没有实际验货日期,请录入"); } } //3、外出检验合格状态控制 if (soLine.DescFlexField.PubDescSeg22 != "" && soLine.DescFlexField.PubDescSeg22.ToLower() == "true") { if (soLine.DescFlexField.PrivateDescSeg13 != "01") { throw new Exception("出运明细行" + line.RowNo + "对应的销售订单行" + soLine.DocLineNo + "需要外出检验且检验状态不是合格状态,无法出运"); } } } } #region //4、评估合格校验 DataSet ds = new DataSet(); string sql = "SELECT A.Code,B.Value FROM Base_Profile A,Base_ProfileValue B WHERE A.ID = B.Profile AND A.Code='FT_Ship' AND B.Organization=" + UFIDA.U9.Base.Context.LoginOrg.ID; UFSoft.UBF.Util.DataAccess.DataAccessor.RunSQL(UFSoft.UBF.Util.DataAccess.DataAccessor.GetConn(), sql, null, out ds); if (ds.Tables.Count > 0 && ds.Tables[0].Rows.Count > 0) { if (ds.Tables[0].Rows[0][0].ToString().ToLower() == "true" && soIDstr.Trim().Length > 1) { //判断当前销售订单所对应的评估单的评估结果是否全部为合格 , soIDstr = soIDstr.Substring(0, soIDstr.Length - 1); ds = new DataSet(); sql = "select max(TestDate),SoID from GS_FT_AssessType where SoID in (" + soIDstr + ") and TestResult=" + AllEnumBE.TestResultEnum.NoQualified.Value + " group by Item"; UFSoft.UBF.Util.DataAccess.DataAccessor.RunSQL(UFSoft.UBF.Util.DataAccess.DataAccessor.GetConn(), sql, null, out ds); if (ds.Tables.Count > 0 && ds.Tables[0].Rows.Count > 0) { throw new Exception("来源销售订单所对应的评估单的评估结果有不合格项,无法确认出运"); } } } #endregion #region //5、出货差异校验 #endregion shipPlan.ShipPlanState = AllEnumBE.ShipPlanStateEnum.ShipPlan; //出运明细状态为已出运 break; case 6: //预装柜时校验是否第三方验货 //校验如果来源销售订单行需要进行第三方验货,则校验第三方验货是否已完成,如果未完成,则抛出异常,否则弹出预装柜界面; ds = new DataSet(); string soLineList = ""; foreach (ShipPlanDetailBE.ShipPlanDetailLine line in shipPlan.ShipPlanDetailLine) { if (!soLineList.Contains(line.SrcLineID.ToString())) { soLineList += line.SrcLineID.ToString(); } } soLineList = soLineList.Trim().Substring(0, soLineList.Length - 1); if (soLineList.Trim() != "") { sql = "select ID,DescFlexField_PrivateDescSeg11,DescFlexField_PrivateDescSeg12 from SM_SOLine where DescFlexField_PrivateDescSeg11 != '' and DescFlexField_PrivateDescSeg11 !='01' and DescFlexField_PrivateDescSeg12='' "; UFSoft.UBF.Util.DataAccess.DataAccessor.RunSQL(UFSoft.UBF.Util.DataAccess.DataAccessor.GetConn(), sql, null, out ds); if (ds.Tables.Count > 0 && ds.Tables[0].Rows.Count > 0) { SM.SO.SOLine line = SM.SO.SOLine.Finder.FindByID(Convert.ToInt64(ds.Tables[0].Rows[0]["ID"].ToString())); if (line != null) { throw new Exception("来源销售订单" + line.SO.DocNo + "行" + line.DocLineNo + "验货方式为第三方验货,但是没有验货,无法预装柜"); } } } break; case 7: //取消理单 if (shipPlan.Status != AllEnumBE.DocumnetSate.ApprovedSate) { throw new Exception("只有审核状态才可以取消理单"); } shipPlan.IsManage = false; break; case 8: //仓库下发 //if (shipPlan.Status != AllEnumBE.DocumnetSate.ApprovedSate) //{ // throw new Exception("只有审核状态才可以下发仓库"); //} //验出运明细单是否已做预装柜,如果未装柜,不允许下发仓库 foreach (ShipPlanDetailBE.ShipPlanDetailLine line in shipPlan.ShipPlanDetailLine) { if (!line.IsShipping) { throw new Exception("出运明细行" + line.RowNo + "没有预装柜处理,无法下发仓库"); } if (line.Qty != line.InstalledArkQty) //未全部装柜完成,无法下发仓库 { throw new Exception("出运明细行" + line.RowNo + "没有装柜完成,无法下发仓库"); } } shipPlan.ShipPlanState = ShipPlanStateEnum.IssuedStorage; //状态改为下发仓库 break; case 9: //取消仓库下发 if (shipPlan.ShipPlanState != ShipPlanStateEnum.IssuedStorage) { throw new Exception("没有下发仓库,无需取消仓库下发"); } #region 调用WMS接口校验是否已做后续业务 //调用WMS接口,校验WMS系统是否已做后续业务,如果已做,则不允许取消仓库下发 #endregion shipPlan.ShipPlanState = ShipPlanStateEnum.NotShipPlan; //状态改为未出运 break; case 10: if (shipPlan.ShipPlanState == ShipPlanStateEnum.IssuedStorage) { throw new Exception("已下发仓库,请先取消仓库下发"); } else if (shipPlan.ShipPlanState == ShipPlanStateEnum.NotShipPlan) { throw new Exception("未出运,无需取消出运"); } shipPlan.ShipPlanState = ShipPlanStateEnum.NotShipPlan; //状态改为未出运 break; default: break; } session.Commit(); } return(1); }
/// <summary> /// 分摊表头海运费到行 /// </summary> /// <param name="itemQty"></param> /// <param name="itemRough"></param> /// <param name="itemVolume"></param> /// <param name="oceanFreightHead"></param> /// <param name="soLine"></param> /// <returns></returns> public static decimal GetOceanFreight(decimal itemQty, decimal itemRough, decimal itemVolume, SM.SO.SOLine soLine) { decimal oceanFreight = 0; //分整柜与散货两种计算方式 //先算集装箱数 decimal roughCount = 0; //毛重计算的集装箱个数 decimal volumeCount = 0; //体积计算的集装箱个数 decimal freightRates = 0; //销售订单扩展字段的运价 //if (soLine.SO.DescFlexField.PrivateDescSeg9 == "") // throw new Exception("请输入销售订单"+soLine.SO.DocNo+"运价"); if (soLine.SO.DescFlexField.PrivateDescSeg9.Trim() == "") { freightRates = 0; } else { freightRates = decimal.Parse(soLine.SO.DescFlexField.PrivateDescSeg9);//运价 } //if(freightRates == 0) // throw new Exception("销售订单"+soLine.SO.DocNo+"运价不能为0"); if (soLine.DescFlexField.PubDescSeg11 == "") { //throw new Exception("销售订单" + soLine.SO.DocNo + "行"+soLine.DocLineNo+"装柜方式不能为空"); return(0); } if (soLine.DescFlexField.PubDescSeg11 == "ZG") //整柜 { //算法说明: //单行的箱数=订单数量/料品.装箱数量 --料品扩展字段 //单行的毛重:单行的箱数*料品.毛重 --料品扩展字段 //单行的体积:单行的箱数*料品.体积 --料品扩展字段 //按照毛重的集装箱个数算法:单行的箱数*料品.毛重/柜子的额定重量(预制参数) //按照体积的集装箱个数算法:单行的箱数*料品.体积/柜子的额定体积(预制参数) //单行集装箱数=取两个算法的最大值 roughCount = Math.Ceiling(((soLine.OrderByQtyTU / itemQty)) * itemRough) / m_cabinetRough; volumeCount = ((soLine.OrderByQtyTU / itemQty) * itemVolume) / m_cabinetVolume; if (roughCount >= volumeCount) { return(roughCount * freightRates); } else { return(volumeCount * freightRates); } } else if (soLine.DescFlexField.PubDescSeg11 == "SH") //散柜 { //单品的散柜类型的海运费=单行的体积*运价 return((soLine.OrderByQtyTU / itemQty) * itemVolume * freightRates); } return(oceanFreight); }
/// <summary> /// 计算国内运费 /// </summary> /// <param name="itemQty">装箱数量</param> /// <param name="itemRough">料品毛重</param> /// <param name="itemVolume">料品体积</param> /// <param name="allVolume">销售订单整单体积</param> /// <param name="soLine">销售订单行</param> /// <returns></returns> public static decimal GetDomesticFee(decimal itemQty, decimal itemRough, decimal itemVolume, decimal allVolume, SM.SO.SOLine soLine) { decimal domesticFee = 0;//分摊的单行国内费用 //单行的国内运费=国内运费/整单体积*单行的体积 //单行的体积:单行的箱数*料品.体积 //单行的箱数=订单数量/料品.装箱数量 if (soLine.SO.DescFlexField.PrivateDescSeg5 == "" || soLine.SO.DescFlexField.PrivateDescSeg5 == "0")//单头国内费用 { //throw new Exception("销售订单" + soLine.SO.DocNo + "国内费用不能为空"); return(0); } if (allVolume == 0 || itemQty == 0) { return(0); } domesticFee = decimal.Parse(soLine.SO.DescFlexField.PrivateDescSeg5) / allVolume * ((soLine.OrderByQtyTU / itemQty) * itemVolume); return(domesticFee); }
/// <summary> /// 计算包装采购成本 /// </summary> /// <param name="soLine"></param> /// <returns></returns> public static decimal GetProcurementCost(SM.SO.SOLine soLine, OrderBomBE.OrderBomHead.EntityList orderBom) { decimal procurementCost = 0;//包装采购成本 //委外/生产,包装子件采购成本取价: //1)无BOM时,手工填写【包材汇总成本】。--2014725销售订单维护 //2)有BOM时,老物料优先取最新实际成本(最新价表),多个价格,按照熟高,如果取不到,方式2种: //—在【包材汇总成本】处输入金额,则成本预测按照汇总成本预测。 //—按照成本预测子件取价逻辑。 //解释:包材分类:泡壳、纸材,按照包材的分类维护余量比例及上限量档案,即某一类包材的余量比例是多少 //只有人民币采购 decimal sumCost = 0;//包材汇总成本 if (soLine.DescFlexField.PrivateDescSeg22 != "") { sumCost = decimal.Parse(soLine.DescFlexField.PrivateDescSeg22); } decimal purchasePrice = 0; //采购价 int currencyType = 0; //采购币种标记 if (orderBom == null || orderBom.Count == 0) //随单BOM为空,从销售订单行扩展字段【包材汇总成本】中取 { return(sumCost); } else { //获取子项 DataSet ds = new DataSet(); string sql = ""; foreach (OrderBomHead line in orderBom) { if (line.SubKey != null && line.SubKey.StockCategory != null) { if (line.SubKey.StockCategory.Code != "03")//不为包材小类,不计算包装成本 { continue; } sql = "select top 1 B.OrderPriceTC,A.TC from PM_POLine b left join PM_PurchaseOrder a on b.PurchaseOrder=a.id where b.ItemInfo_ItemID=" + line.SubKey.ID + " and Org=" + UFIDA.U9.Base.Context.LoginOrg.ID + " order by a.BusinessDate desc"; UFSoft.UBF.Util.DataAccess.DataAccessor.RunSQL(UFSoft.UBF.Util.DataAccess.DataAccessor.GetConn(), sql, null, out ds); purchasePrice = CalculatePurchasePrice(1, soLine, line, ds, ref currencyType); procurementCost += purchasePrice * line.NeedNumber; } } } #region 废弃代码 //if (soLine.DescFlexField.PubDescSeg18 == "03") ////如果是成品采购, ////if (soLine.ItemInfo.ItemIDKey.GetEntity().StockCategory.Code == "01") //成品直接取最近采购价格 //{ // DataSet ds = new DataSet(); // string sql = "select top 1 B.OrderPriceTC,A.TC from PM_POLine b left join PM_PurchaseOrder a on b.PurchaseOrder=a.id where b.ItemInfo_ItemID=" + soLine.ItemInfo.ItemID.ID + " and Org=" + UFIDA.U9.Base.Context.LoginOrg.ID + " order by a.BusinessDate desc"; // UFSoft.UBF.Util.DataAccess.DataAccessor.RunSQL(UFSoft.UBF.Util.DataAccess.DataAccessor.GetConn(), sql, null, out ds); // if (ds.Tables[0].Rows.Count > 0) // { // procurementCost = Convert.ToDecimal(ds.Tables[0].Rows[0]["OrderPriceTC"].ToString()); // return procurementCost;//应该为采购价*料品扩展字段包装单位成本*销售订单数量 // } // else // { // //throw new Exception("请设置销售订单" + soLine.SO.DocNo + "行" + soLine.DocLineNo + "包材汇总成本"); // } //} //else if(orderBom != null) //{ // decimal price = 0; // if(soLine.DescFlexField.PrivateDescSeg7 != "") // { // //throw new Exception("请设置销售订单" + soLine.SO.DocNo + "行" + soLine.DocLineNo + "包装成本费用"); // price = decimal.Parse(soLine.DescFlexField.PrivateDescSeg7); // foreach (OrderBomLine line in orderBom.OrderBomLine) // { // procurementCost += soLine.OrderByQtyTU * price * line.ProcurementQty; // } // } //} #endregion return(procurementCost); }
/// <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> /// 为实体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); }