/// <summary> /// after Update /// </summary> protected override void OnUpdated() { BillNoItemBE.BillNoItemHead oldBillNoItem = this.OriginalData.BillNoItem; BillNoItemBE.BillNoItemHead newBillNoItem = this.BillNoItem; //为出运明细单分配发票号组时,反写发票号组状态 //为出运明细单取消发票号组分配时,需要判断此发票号组是不是仍分配到其他出运明细单,没有的话值发票号组状态为“未分配" using (ISession session = Session.Open()) { if (oldBillNoItem == null && newBillNoItem != null) { //出运明细单分配发票号 if (newBillNoItem.BillNoItemStates == AllEnumBE.BillNoItemEnum.UnAllot) { newBillNoItem.BillNoItemStates = AllEnumBE.BillNoItemEnum.IsAllot; } } else if (oldBillNoItem != null && newBillNoItem == null) { //出运明细单取消分配发票号 if (oldBillNoItem.BillNoItemStates == AllEnumBE.BillNoItemEnum.IsAllot) { ShipPlanDetailBE.ShipPlanDetailHead shipPlan = ShipPlanDetailBE.ShipPlanDetailHead.Finder.Find("BillNoItem='" + oldBillNoItem.ID + "'"); if (shipPlan == null) { oldBillNoItem.BillNoItemStates = AllEnumBE.BillNoItemEnum.UnAllot; } } } session.Commit(); } base.OnUpdated(); // TO DO: write your business code here... }
private List <ShipPlanIDDTO> CreatShipPlanList(CreatShipPlan bpObj) { List <ShipPlanIDDTO> listShip = new List <ShipPlanIDDTO>(); using (ISession session = Session.Open()) { ShipPlanDetailBE.ShipPlanDetailHead shipPlan = ShipPlanDetailBE.ShipPlanDetailHead.Create(); ShipDetailTypeBE.ShipDetailType formType = ShipDetailTypeBE.ShipDetailType.Finder.Find("IsCreatedByPush=1"); if (formType == null) { throw new Exception("未设置出运明细单生单的单据类型,请设置出运明细单单据类型为“上游单据推出”"); } shipPlan.DocumnetType = formType; shipPlan.SourceDocumnetType = AllEnumBE.SourceTypeEnum.SoOrder; shipPlan.Status = AllEnumBE.DocumnetSate.OpenState; //单据状态 shipPlan.ShipPlanState = AllEnumBE.ShipPlanStateEnum.NotShipPlan; //出运状态 shipPlan.BusinessDate = DateTime.Now; //设置默认行号 GetProfileValueProxy lineNo = new GetProfileValueProxy(); lineNo.ProfileCode = "SysLineNo"; PVDTOData pVTDOData = lineNo.Do(); string row = pVTDOData.ProfileValue; //财务费率 decimal fiFeeRate = 0; GetProfileValueProxy bpObj1 = new GetProfileValueProxy(); bpObj1.ProfileCode = "FTFIFee"; bpObj1.ProfileOrg = Base.Context.LoginOrg.ID; PVDTOData pVDTOData = bpObj1.Do(); if (pVDTOData != null && pVDTOData.ProfileValue != null) { fiFeeRate = decimal.Parse(pVDTOData.ProfileValue); } string docNo = "", shipplingType = "", soLine = ""; long customer = 0, currenty = 0; int count = 1; foreach (SOLineIDDTO lineDto in bpObj.SOLineIDDTO) { UFIDA.U9.SM.SO.SOLine line = SM.SO.SOLine.Finder.FindByID(lineDto.SOLine); if (line == null) { continue; } //不同的客户、币种、装箱方式不允许拉式生成同一个出运明细单 if (count > 1) { if (customer != 0 && customer != line.SO.OrderBy.Customer.ID) { throw new Exception("销售订单" + line.SO.DocNo + "的客户与单号" + docNo + "的客户不一致,不能生成同一个出运明细单"); } if (currenty != 0 && currenty != line.SO.TC.ID) { throw new Exception("销售订单" + line.SO.DocNo + "的币种与单号" + docNo + "的币种不一致,不能生成同一个出运明细单"); } if (shipplingType != "" && shipplingType != line.DescFlexField.PubDescSeg11) { throw new Exception("销售订单" + line.SO.DocNo + "行号" + line.DocLineNo + "的装箱方式与单号" + docNo + "行号" + soLine + "装箱方式不一致,不能生成同一个出运明细单"); } } docNo = line.SO.DocNo; customer = line.SO.OrderBy.Customer.ID; currenty = line.SO.TC.ID; shipplingType = line.DescFlexField.PubDescSeg11; soLine = line.DocLineNo.ToString(); //赋值表头信息 shipPlan.SaleMan = line.SO.Seller; //业务员 shipPlan.Client = line.SO.OrderBy.Customer; //客户 if (line.SO.OrderBy.Customer != null) { // shipPlan.Consignee = line.SO.OrderBy.Customer.a //提箱港区 地区档案 从销售订单带出,从客户带出 if (line.SO.OrderBy.Customer.Territory != null) { shipPlan.CargoPort = line.SO.OrderBy.Customer.Territory;// } } if (line.SO.ShipToSite != null && line.SO.ShipToSite.CustomerSite != null)//收货位置 { //shipPlan. } shipPlan.Department = line.SO.SaleDepartment; //部门 shipPlan.Currency = line.SO.TC; //币种 shipPlan.DealMode = line.SO.BargainMode; //成交方式 //贸易国别 国家\地区档案 从销售订单带出 //shipPlan.Country = line.SO. shipPlan.Transportation = line.SO.TransMode; // if (line.SO.DescFlexField.PrivateDescSeg14 != "") { Base.Organization.Organization org = Base.Organization.Organization.FindByCode(line.SO.DescFlexField.PrivateDescSeg14); if (org != null) { shipPlan.GetOrderOrg = org; } else { throw new Exception("销售订单" + line.SO.DocNo + "接单组织为空,不能生成出运明细单"); } } else { throw new Exception("销售订单" + line.SO.DocNo + "接单组织为空,不能生成出运明细单"); } //出口口岸 港口档案 从销售订单带出 shipPlan.ExportPort = line.SO.ShippingPort; //进港区 地区档案 从销售订单带出 //shipPlan.IntoPort //目的口岸 港口档案 从销售订单带出 shipPlan.DestinationPort = line.SO.AimPort; //运输方式 shipPlan.Transportation = line.SO.TransMode; //贸易方式 shipPlan.TradeMode = line.SO.TradeMode; //收汇天数,从销售订单公共扩展字段1带出 if (line.SO.OrderBy.CustomerKey.GetEntity().DescFlexField.PubDescSeg1 == "") { shipPlan.NumberDay = 0; } else { shipPlan.NumberDay = Convert.ToInt32(line.SO.OrderBy.CustomerKey.GetEntity().DescFlexField.PubDescSeg1); } //赋值表体信息 ShipPlanDetailBE.ShipPlanDetailLine shipLine = ShipPlanDetailBE.ShipPlanDetailLine.Create(shipPlan); //包装工厂 值集值 从销售订单行带出 //Base.FlexField.ValueSet.DefineValue flexField = Base.FlexField.ValueSet.DefineValue.Finder.Find("Code='Z022'"); if (line.DescFlexField.PrivateDescSeg18 != "") { Base.FlexField.ValueSet.DefineValue flexField = Base.FlexField.ValueSet.DefineValue.Finder.Find("ValueSetDef.Code='Z002' and Code='" + line.DescFlexField.PrivateDescSeg18 + "'"); // flexField.ValueSetDef.CodeAttribute shipLine.PackingHouse = flexField; } if (line.DescFlexField.PrivateDescSeg12 != "") //验货方式直接 { Base.FlexField.ValueSet.DefineValue flexField = Base.FlexField.ValueSet.DefineValue.Finder.Find("ValueSetDef.Code='Z009' and Code='" + line.DescFlexField.PrivateDescSeg12 + "'"); shipLine.ExamineCargoMode = flexField; //shipLine.ExamineCargoMode = AllEnumBE.ExamineCargoModeEnum.GetFromValue(line.DescFlexField.PrivateDescSeg12); } //else // shipLine.ExamineCargoMode = AllEnumBE.ExamineCargoModeEnum.Empty; shipLine.RowNo = Convert.ToInt32(row); shipLine.SrcSO = line.SO; shipLine.SrcDocNo = line.SO.DocNo; shipLine.SrcLineID = line.ID; shipLine.SrcLineNo = line.DocLineNo.ToString(); //shipLine.SrcSOKey = line. if (line.ItemInfo == null || line.ItemInfo.ItemID == null) { throw new Exception("销售订单" + line.SO.DocNo + "行" + line.DocLineNo + "找不见对应料品信息,不能生成出运明细单"); } shipLine.Item = line.ItemInfo.ItemID; shipLine.Standard = line.ItemInfo.ItemID.SPECS; shipLine.NumberUom = line.TU; shipLine.Ultimately = line.FinallyPriceTC;//最终价 //外销价 十进制 销售订单带出 if (line.DescFlexField.PrivateDescSeg5 != "") { shipLine.ExportSales = decimal.Parse(line.DescFlexField.PrivateDescSeg5);//外销价 } shipLine.Qty = lineDto.ShipQty; shipPlan.FinancialCost += shipPlan.FinancialCost + (shipLine.ExportSales * shipLine.Qty * fiFeeRate / 100); //反写销售订单已出运数量 //if (line.DescFlexField.PrivateDescSeg8 != "") //{ // line.DescFlexField.PrivateDescSeg8 = (decimal.Parse(line.DescFlexField.PrivateDescSeg8) + lineDto.ShipQty).ToString();//反写销售订单行的已出运数量 //} //else // line.DescFlexField.PrivateDescSeg8 = lineDto.ShipQty.ToString(); //验货方式销售订单行私有字段12 //带出料品的总箱数、内箱数、外箱数、毛重、净重、体积、长、宽、高,体积、总体积 //料品的字表字段 ItemSubTable itemsub = ItemSubTable.Finder.Find("ItemMaster=" + line.ItemInfo.ItemID.ID); if (itemsub != null) { //string sumBoxNumber = line.ItemInfo.ItemIDKey.GetEntity().DescFlexField.PrivateDescSeg3;//料品的扩展字段;箱数 //string inBoxNumber = line.ItemInfo.ItemIDKey.GetEntity().DescFlexField.PrivateDescSeg27;//料品的扩展字段;内箱数 //string outerBoxNumber = line.ItemInfo.ItemIDKey.GetEntity().DescFlexField.PrivateDescSeg28;//料品的扩展字段;外箱数 //string grossWeight = line.ItemInfo.ItemIDKey.GetEntity().DescFlexField.PrivateDescSeg2;//料品的扩展字段:毛重 ////string netWeight = line.ItemInfo.ItemIDKey.GetEntity().DescFlexField.PrivateDescSeg3;//料品的扩展字段:净重 //string length = line.ItemInfo.ItemIDKey.GetEntity().DescFlexField.PrivateDescSeg8;//料品的扩展字段:长 //string weith = line.ItemInfo.ItemIDKey.GetEntity().DescFlexField.PrivateDescSeg9;//料品的扩展字段:宽 //string hight = line.ItemInfo.ItemIDKey.GetEntity().DescFlexField.PrivateDescSeg10;//料品的扩展字段:高 //string sumBoxNumber = itemsub.BoxNumber; ;//料品的扩展字段;箱数 //string inBoxNumber = line.ItemInfo.ItemIDKey.GetEntity().DescFlexField.PrivateDescSeg27;//料品的扩展字段;内箱数 //string outerBoxNumber = line.ItemInfo.ItemIDKey.GetEntity().DescFlexField.PrivateDescSeg28;//料品的扩展字段;外箱数 //string grossWeight = line.ItemInfo.ItemIDKey.GetEntity().DescFlexField.PrivateDescSeg2;//料品的扩展字段:毛重 ////string netWeight = line.ItemInfo.ItemIDKey.GetEntity().DescFlexField.PrivateDescSeg3;//料品的扩展字段:净重 //string length = line.ItemInfo.ItemIDKey.GetEntity().DescFlexField.PrivateDescSeg8;//料品的扩展字段:长 //string weith = line.ItemInfo.ItemIDKey.GetEntity().DescFlexField.PrivateDescSeg9;//料品的扩展字段:宽 //string hight = line.ItemInfo.ItemIDKey.GetEntity().DescFlexField.PrivateDescSeg10;//料品的扩展字段:高 shipLine.SumBoxNumber = itemsub.BoxNumber; shipLine.InBoxNumber = itemsub.InnerBoxNumber; shipLine.OuterBoxNumber = itemsub.OutBoxNumber; shipLine.GrossWeight = itemsub.GrossWeight; //毛重 shipLine.NetWeight = itemsub.NetWeight; //净重 shipLine.SumGross = shipLine.GrossWeight * shipLine.Qty; //总毛重 shipLine.Length = itemsub.BoxLong; shipLine.Weith = itemsub.BoxWidth; shipLine.Higth = itemsub.BoxHight; shipLine.Bulks = shipLine.Length * shipLine.Weith * shipLine.Higth; //体积 shipLine.SumBulk = shipLine.Bulks * shipLine.Qty; //总体积 } #region 产生佣金表,放到BE里生成 //if (line.DescFlexField.PrivateDescSeg6.ToLower() == "true") //{ // OrderLineBrokerage.EntityList brokerage = OrderLineBrokerage.Finder.FindAll("OrderLineID='" + line.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 = shipLine; // shipLineBroke.ShipPlanRowNo = int.Parse(row); // shipLineBroke.Client = orderBrokerage.Client; // shipLineBroke.Product = orderBrokerage.Product; // shipLineBroke.BrokerageRatio = orderBrokerage.BrokerageRatio; // shipLineBroke.Payee = orderBrokerage.Payee; // shipLineBroke.PayAmount = orderBrokerage.PayAmount; // shipLineBroke.PayCurrency = orderBrokerage.PayCurrency; // shipLineBroke.OutPayment = orderBrokerage.OutPayment; // shipLineBroke.OrderCurrency = orderBrokerage.OrderCurrency; // shipLineBroke.Rate = orderBrokerage.Rate; // } // } //} #endregion row = (int.Parse(row) + int.Parse(pVTDOData.ProfileValue)).ToString(); count++; } session.Commit(); ShipPlanIDDTO shipID = new ShipPlanIDDTO(); shipID.DocNo = shipPlan.DocNo; shipID.ShipPlan = shipPlan.ID; listShip.Add(shipID); } return(listShip); }
private bool UpdateStatus(FTDocStatusUpdate bpObj) { bool result = false; switch (bpObj.DocType) { case 0: //出运明细单状态改变 #region 更改出运明细单单据状态 ShipPlanDetailBE.ShipPlanDetailHead shipPlan = ShipPlanDetailBE.ShipPlanDetailHead.Finder.FindByID(bpObj.DocID); if (shipPlan != null && shipPlan.SysVersion == bpObj.VIVersion) { using (ISession session = Session.Open()) { if (shipPlan != null) { //提交 if (bpObj.DocStatus == 0) { shipPlan.Status = AllEnumBE.DocumnetSate.ApprovingState; shipPlan.CommitDate = DateTime.Now; shipPlan.CommitAssessor = UFIDA.U9.Base.Context.LoginUser; } //审核操作( else if (bpObj.DocStatus == 1) { if (shipPlan.BillNoItem == null) { //throw new Exception("出运明细单没有发票发票号"); } shipPlan.Status = AllEnumBE.DocumnetSate.ApprovedSate; shipPlan.AuditDate = DateTime.Now; shipPlan.Assessor = UFIDA.U9.Base.Context.LoginUser; } //弃申操作 else if (bpObj.DocStatus == 2) { if (shipPlan.ShipPlanState == ShipPlanStateEnum.IssuedStorage) { throw new Exception("出运明细单已下发仓库无法弃审"); } #region 调用WMS系统检验是否已经开始拣货 #endregion // foreach (ShipPlanDetailBE.ShipPlanDetailLine line in shipPlan.ShipPlanDetailLine) //{ // if (line.IsWms) // { // throw new Exception("出运明细单已拣货"); // } //} if (shipPlan.IsAgvFee) { throw new Exception("出运明细单费用已分摊,无法弃审,请先弃审出运发票费用单再操作"); } shipPlan.Status = AllEnumBE.DocumnetSate.OpenState; shipPlan.IsAllocation = false; //出运明细单.已分配发票号赋值为false shipPlan.UndoAuditDate = DateTime.Now; shipPlan.UndoAssessor = UFIDA.U9.Base.Context.LoginUser; } } //session.Modify(shipPlan); session.Commit(); } } else { throw new Exception("当前数据已被修改或删除,请刷新后操作!!!"); } result = true; break; #endregion case 1: //出运发票费用单单据状态改变 #region 更改出运发票费用单单据状态 ShipPlanDetailFeeBE.ShipPlanDetailFeeHead shipFee = ShipPlanDetailFeeBE.ShipPlanDetailFeeHead.Finder.FindByID(bpObj.DocID); if (shipFee != null && shipFee.SysVersion == bpObj.VIVersion) { using (ISession session = Session.Open()) { if (shipFee != null) { //提交 if (bpObj.DocStatus == 0) { shipFee.Status = AllEnumBE.DocumnetSate.ApprovingState; } //审核操作( else if (bpObj.DocStatus == 1) { //费用单放到list集合中 List <ShipPlanDetailFeeLine> listCustomerFee = new List <ShipPlanDetailFeeLine>(); List <ShipPlanDetailFeeLine> listSupplierFee = new List <ShipPlanDetailFeeLine>(); shipFee.Status = AllEnumBE.DocumnetSate.ApprovedSate; //审核时金额分摊 //出运发票费用单审核时,如果发票费用单分摊方式为“按金额分摊”, //则根据出运发票号查找所有出运明细单金行集合,并汇总出运明细单行价税合计,申明变量“累计分摊金额”,循环出运发票费用单行: decimal totalMny = 0; //价税合计 //decimal totalvolumeWeight = 0;//汇总体积重量 decimal totalAppMny = 0; //累计分摊金额 decimal agvAppMny = 0; //单行分摊金额 int index = 1; //计算出运明细单循环行标志 bool isDeduction = false; //是否扣款登记 //CurrencyData currency = BPHelperExtend.GetEntityDataByID<CurrencyData>(long.Parse(pVDTOData.ProfileValue)); if (shipFee.AllocationWay == AllEnumBE.AllocationWayEnum.Amount) //按金额分摊 { ShipPlanDetailLine.EntityList shipLineList = ShipPlanDetailLine.Finder.FindAll("ShipPlanDetailHead.BillNoItem=" + shipFee.ShipPlanOrderNo.ID + ""); foreach (ShipPlanDetailLine ship in shipLineList) { totalMny += ship.TotalTax; } ShipPlanDetailLineFee detailFee = null; foreach (ShipPlanDetailFeeLine lineFee in shipFee.ShipPlanDetailFeeLine) { //生成扣款登记表时用到。 if (lineFee.PayClient != null && lineFee.AmountPayable > 0) { listCustomerFee.Add(lineFee); } if (lineFee.PaySupplier != null && lineFee.AmountPayable > 0) { listSupplierFee.Add(lineFee); } #region 获取币种精度 UFIDA.U9.Base.Currency.Proxy.GetCurrencyRoundProxy proxy = new Base.Currency.Proxy.GetCurrencyRoundProxy(); proxy.Currency = lineFee.Currency.ID; Base.PropertyTypes.RoundData round = proxy.Do(); #endregion if (lineFee.Payment == AllEnumBE.PaymentEnum.WePay) //付款方式等于我方支付 { //价格含税时税额计算方式:含税金额 - 含税金额/(1+税率) foreach (ShipPlanDetailLine line in shipLineList) { //得到精度 if (index == shipLineList.Count) //循环至最后一行 { agvAppMny = System.Math.Round(lineFee.AmountPayable - totalAppMny, round.Precision); } //出运明细单行分摊金额=出运明细单行.价税合计*出运发票费用单行.付款金额/sum(出运明细单行.价税合计); else { agvAppMny = System.Math.Round((line.TotalTax * lineFee.AmountPayable / totalMny), round.Precision); } totalAppMny += agvAppMny; index++; //创建出运明细费用单 detailFee = ShipPlanDetailLineFee.Create(line); detailFee.RowNo = lineFee.RowNo; detailFee.ShipItemFee = lineFee.ShipItemFee; detailFee.ShipFeeProject = lineFee.ShipFeeProject; detailFee.Supplier = lineFee.Supplier; detailFee.Currency = lineFee.Currency; detailFee.Uom = lineFee.Uom; detailFee.Memo = lineFee.Memo; detailFee.Combination = lineFee.Combination; //税组合 detailFee.TaxRate = lineFee.TaxRate; //税率 if (lineFee.TaxRate == null || lineFee.TaxRate <= 0) { detailFee.Prices = lineFee.Prices; //单价 detailFee.Qty = lineFee.Qty; //数量 detailFee.AmountPayable = agvAppMny; //付款金额为分摊金额 detailFee.NotTaxMoney = agvAppMny; //未税金额 detailFee.TaxMoney = 0; //税额 detailFee.NotTaxPrice = lineFee.Prices; //未税单价 //detailFee.PaymentAmount = lineFee.PaymentAmount; } else { //分摊的金额全部是含税金额 //价格含税时税额计算方式:含税金额 - 含税金额/(1+税率) detailFee.Prices = lineFee.Prices; //单价 detailFee.Qty = lineFee.Qty; //数量 detailFee.AmountPayable = agvAppMny; //付款金额为分摊金额 detailFee.NotTaxMoney = System.Math.Round(agvAppMny / (1 + lineFee.TaxRate), round.Precision); //未税金额 detailFee.TaxMoney = detailFee.AmountPayable - detailFee.NotTaxMoney; //税额 detailFee.NotTaxPrice = lineFee.NotTaxPrice; //未税单价 } } } else if (lineFee.Payment == AllEnumBE.PaymentEnum.OtherPay) { isDeduction = true; } } } else //按体积分摊 { ShipPlanDetailLine.EntityList shipLineList = ShipPlanDetailLine.Finder.FindAll("ShipPlanDetailHead.BillNoItem=" + shipFee.ShipPlanOrderNo.ID + ""); foreach (ShipPlanDetailLine ship in shipLineList) { totalMny += ship.VolumeWeight; } ShipPlanDetailLineFee detailFee = null; foreach (ShipPlanDetailFeeLine lineFee in shipFee.ShipPlanDetailFeeLine) { //生成扣款登记表时用到。 if (lineFee.PayClient != null && lineFee.AmountPayable > 0) { listCustomerFee.Add(lineFee); } if (lineFee.PaySupplier != null && lineFee.AmountPayable > 0) { listSupplierFee.Add(lineFee); } UFIDA.U9.Base.Currency.Proxy.GetCurrencyRoundProxy proxy = new Base.Currency.Proxy.GetCurrencyRoundProxy(); proxy.Currency = lineFee.Currency.ID; Base.PropertyTypes.RoundData round = proxy.Do(); if (lineFee.Payment == AllEnumBE.PaymentEnum.WePay) //付款方式等于我方支付 { //价格含税时税额计算方式:含税金额 - 含税金额/(1+税率) foreach (ShipPlanDetailLine line in shipLineList) { //得到精度 if (index == shipLineList.Count) //循环至最后一行 { agvAppMny = System.Math.Round((totalMny - totalAppMny), round.Precision); } //出运明细单行分摊金额=出运明细单行.总体积重量*出运发票费用单行.付款金额/sum(出运明细单行.总体积重量); else { agvAppMny = System.Math.Round((line.VolumeWeight * lineFee.AmountPayable / totalMny), round.Precision); } totalAppMny += agvAppMny; index++; //创建出运明细费用单 detailFee = ShipPlanDetailLineFee.Create(line); detailFee.RowNo = lineFee.RowNo; detailFee.ShipItemFee = lineFee.ShipItemFee; detailFee.ShipFeeProject = lineFee.ShipFeeProject; detailFee.Supplier = lineFee.Supplier; detailFee.Prices = lineFee.Prices; detailFee.Qty = lineFee.Qty; detailFee.AmountPayable = agvAppMny; detailFee.Combination = lineFee.Combination; detailFee.NotTaxMoney = lineFee.NotTaxPrice; detailFee.TaxMoney = lineFee.TaxMoney; detailFee.NotTaxPrice = lineFee.NotTaxPrice; detailFee.PaymentAmount = lineFee.PaymentAmount; detailFee.Currency = lineFee.Currency; detailFee.Uom = lineFee.Uom; detailFee.Memo = lineFee.Memo; } } else if (lineFee.Payment == AllEnumBE.PaymentEnum.OtherPay) { isDeduction = true; } } } //果出运发票费用单行付款方式存在“代收代付”时,分别根据代付客户、代付供应商进行分组汇总付款金额: //如果出运发票费用单行付款方式存在“代收代付”时,分别根据代付客户、代付供应商进行分组汇总付款金额: //1、 如果代付客户不为空,并且付款金额大于0,则产生一张代付对象为客户的扣款登记表,扣款金额为汇总的付款金额,并自动审核扣款登记; //2、 如果代付供应商不为空,并且付款金额大于0,则产生一张代付对象为供应商的扣款登记表,扣款金额为汇总的汇总金额,并自动审核扣款登记 //3、 客户类的扣款登记在登记上进行与明细单进行核销; if (isDeduction) { //linq分组 IEnumerable <IGrouping <string, ShipPlanDetailFeeLine> > dtoCustomer = listCustomerFee.Cast <ShipPlanDetailFeeLine>().GroupBy <ShipPlanDetailFeeLine, string>(cur => cur.PayClient.Code); IEnumerable <IGrouping <string, ShipPlanDetailFeeLine> > dotSupplier = listSupplierFee.Cast <ShipPlanDetailFeeLine>().GroupBy <ShipPlanDetailFeeLine, string>(cur => cur.PaySupplier.Code); #region 生成扣款登记表 UFIDA.U9.Cust.GS.FI.DeductionRegisterBP.Proxy.CreateDeductionRegisterBPProxy proxy = new FI.DeductionRegisterBP.Proxy.CreateDeductionRegisterBPProxy(); List <DeductionRegisterDTOData> listDeduction = new List <DeductionRegisterDTOData>(); DeductionRegisterDTOData deductionDto = null; foreach (IEnumerable <ShipPlanDetailFeeLine> client in dtoCustomer) { decimal totalCustomMey = 0; foreach (ShipPlanDetailFeeLine ship in client) { totalCustomMey += ship.AmountPayable; } //生成客户的扣款登记表 //decimal totalCustomMey = (from s in listCustomerFee where s.PayClient.Code == client.PayClient.Code select s.AmountPayable).Sum(); deductionDto = new DeductionRegisterDTOData(); DeductionRegisterDocType docType = DeductionRegisterDocType.Finder.Find("IsCreatedByPush=1"); if (docType == null) { throw new Exception("没有设定扣款登记表生单单据类型!"); } deductionDto.DocumentType = docType.ID; deductionDto.BusinessDate = DateTime.Now; deductionDto.SrcDocType = 2; deductionDto.SrcOrg = UFIDA.U9.Base.Context.LoginOrg.ID; deductionDto.SrcDocNo = shipFee.DocNo; deductionDto.SrcDocID = shipFee.ID; deductionDto.Currency = client.First <ShipPlanDetailFeeLine>().Currency.ID; deductionDto.DRObject = 1;//扣款对象1为客户 deductionDto.Customer = client.First <ShipPlanDetailFeeLine>().PayClient.ID; deductionDto.Supplier = 0; deductionDto.DROrg = UFIDA.U9.Base.Context.LoginOrg.ID; deductionDto.DRMoney = totalCustomMey; deductionDto.RegisterOrg = UFIDA.U9.Base.Context.LoginOrg.ID; deductionDto.RegisterBy = UFIDA.U9.Base.Context.LoginUser; listDeduction.Add(deductionDto); } foreach (IEnumerable <ShipPlanDetailFeeLine> supplier in dotSupplier) { decimal totalSupplierMey = 0; foreach (ShipPlanDetailFeeLine ship in supplier) { totalSupplierMey += ship.AmountPayable; } //生成供应商的扣款登记表 //decimal totalSupplierMey = (from s in listCustomerFee where s.PaySupplier.Code == supplier.PaySupplier.Code select s.AmountPayable).Sum(); deductionDto = new DeductionRegisterDTOData(); DeductionRegisterDocType docType = DeductionRegisterDocType.Finder.Find("IsCreatedByPush"); if (docType == null) { throw new Exception("没有设定扣款登记表生单单据类型!"); } deductionDto.DocumentType = docType.ID; deductionDto.BusinessDate = DateTime.Now; deductionDto.SrcDocType = 2; deductionDto.SrcOrg = UFIDA.U9.Base.Context.LoginOrg.ID; deductionDto.SrcDocNo = shipFee.DocNo; deductionDto.SrcDocID = shipFee.ID; deductionDto.Currency = supplier.First <ShipPlanDetailFeeLine>().Currency.ID; deductionDto.DRObject = 0;//扣款对象0为供应商 deductionDto.Customer = 0; deductionDto.Supplier = supplier.First <ShipPlanDetailFeeLine>().PaySupplier.ID; deductionDto.DROrg = UFIDA.U9.Base.Context.LoginOrg.ID; deductionDto.DRMoney = totalSupplierMey; deductionDto.RegisterOrg = UFIDA.U9.Base.Context.LoginOrg.ID; deductionDto.RegisterBy = UFIDA.U9.Base.Context.LoginUser; listDeduction.Add(deductionDto); } List <FI.PubBP.CommonDTOData> listData = null; using (Session sessoin1 = Session.Open()) { proxy.DeductionRegisterDTOs = listDeduction; listData = proxy.Do(); sessoin1.Commit(); } #endregion #region 审核扣款登记表 FI.DeductionRegisterBP.Proxy.ApprovedDeductionRegisterBPProxy proxyApprove = new FI.DeductionRegisterBP.Proxy.ApprovedDeductionRegisterBPProxy(); foreach (CommonDTOData approveDto in listData) { proxyApprove.DocStatus = 1; proxyApprove.EntityKey = approveDto.ID; ErrorMessageDTOData error = proxyApprove.Do(); if (!error.IsSuccess) { throw new Exception("扣款登记表自动审核失败,错误信息" + error.ErrorMessage); } } #endregion } } //弃申操作 else if (bpObj.DocStatus == 2) { // 校验:如果发票号对应的出运明细单已做成本决算, //或者对应的扣款登记已被核销(扣款登记.已扣款金额大于0),则出运发票费用单不允许弃审 ShipPlanDetailHead.EntityList shipHeadList = ShipPlanDetailHead.Finder.FindAll("BillNoItem=" + shipFee.ShipPlanOrderNo.ID + ""); foreach (ShipPlanDetailHead head in shipHeadList) { if (head.ForecastStateEnum == AllEnumBE.ForecastStateEnum.Y) { throw new Exception("出运发票费用单引用的发票号组对应的出运明细单" + head.DocNo + "已做成本决算"); } } //扣款登记已被核销(扣款登记.已扣款金额大于0),则出运发票费用单不允许弃审 DeductionRegister.EntityList deductionList = DeductionRegister.Finder.FindAll("SrcDocID=" + shipFee.ID + ""); FI.DeductionRegisterBP.Proxy.ApprovedDeductionRegisterBPProxy proxyApprove = new FI.DeductionRegisterBP.Proxy.ApprovedDeductionRegisterBPProxy(); foreach (DeductionRegister deduction in deductionList) { if (deduction.DRMoney > 0) { throw new Exception("生成的下游表单扣款登记单" + deduction.DocNo + "已扣款金额大于0,不允许弃审"); } //弃审扣款登记表 proxyApprove.DocStatus = 2; proxyApprove.EntityKey = deduction.ID; ErrorMessageDTOData error = proxyApprove.Do(); if (!error.IsSuccess) { throw new Exception("扣款登记表自动弃审失败,错误信息" + error.ErrorMessage); } //弃审成功后,删除扣款登记表 deduction.Remove(); } ShipPlanDetailLine.EntityList shipLineList = ShipPlanDetailLine.Finder.FindAll("ShipPlanDetailHead.BillNoItem=" + shipFee.ShipPlanOrderNo.ID + ""); foreach (ShipPlanDetailLine line in shipLineList) { for (int i = 0; i < line.ShipPlanDetailLineFee.Count; i++) { line.ShipPlanDetailLineFee[i].Remove(); i = i - 1; } //foreach (ShipPlanDetailLineFee fee in line.ShipPlanDetailLineFee) //{ // ShipPlanDetailLineFee deleFee = ShipPlanDetailLineFee.Finder.FindByID(fee.ID); // deleFee.Remove(); //} } shipFee.Status = AllEnumBE.DocumnetSate.OpenState; //弃审 } } session.Commit(); } } else { throw new Exception("当前数据已被修改或删除,请刷新后操作!!!"); } result = true; break; #endregion } return(result); }