Exemplo n.º 1
0
        /// <summary>
        /// 预装柜时加载出运明细行数据
        /// </summary>
        /// <param name="bpObj"></param>
        /// <returns></returns>
        private List <ShipPlanByBillHeadDTO> GetShipPlanPreArkData(GetShipPlanDoc bpObj)
        {
            List <ShipPlanByBillHeadDTO> listDtoData = new List <ShipPlanByBillHeadDTO>();

            ShipPlanDetailLine.EntityList shipPlanLineList = null;
            if (bpObj.BillNoItemHead > 0)
            {
                shipPlanLineList = ShipPlanDetailLine.Finder.FindAll("ShipPlanDetailHead.BillNoItem=" + bpObj.BillNoItemHead + " and ShipPlanDetailHead.Client=" + bpObj.Customer + " and IsShipping=0");
            }
            else
            {
                shipPlanLineList = ShipPlanDetailLine.Finder.FindAll("ShipPlanDetailHead.ID=" + bpObj.Customer + " and IsShipping=0");
            }
            ShipPlanByBillHeadDTO shipPlan = null;

            foreach (ShipPlanDetailLine line in shipPlanLineList)
            {
                shipPlan                 = new ShipPlanByBillHeadDTO();
                shipPlan.ShipPlan        = line.ShipPlanDetailHead.ID;
                shipPlan.DocNo           = line.ShipPlanDetailHead.DocNo;
                shipPlan.RowNo           = line.RowNo;
                shipPlan.ShipLine        = line.ID;
                shipPlan.ItemMaster      = line.Item.ID;
                shipPlan.ItemMaster_Code = line.Item.Code;
                shipPlan.ItemMaster_Name = line.Item.Name;
                shipPlan.SPECS           = line.Standard;
                shipPlan.Qty             = line.Qty;
                shipPlan.ShipCanQty      = line.Qty - line.InstalledArkQty;
                if (shipPlan.ShipCanQty <= 0)
                {
                    continue;
                }
                shipPlan.OutBoxNumner = line.OuterBoxNumber;
                shipPlan.InBoxNumber  = line.InBoxNumber;
                shipPlan.BoxNumber    = line.SumBoxNumber;
                shipPlan.Bulks        = line.Bulks;
                shipPlan.Length       = line.Length;
                shipPlan.Width        = line.Weith;
                shipPlan.Higth        = line.Higth;
                shipPlan.GrossWeight  = line.GrossWeight;
                shipPlan.NetWeight    = line.NetWeight;
                shipPlan.IsWms        = line.IsWms;

                shipPlan.SrcSO       = line.SrcSO.ID;
                shipPlan.SrcSONo     = line.SrcDocNo;
                shipPlan.SrcSOLine   = line.SrcLineID;
                shipPlan.SrcSOLineNo = Convert.ToInt32(line.SrcLineNo);

                if (line.ShipPlanDetailHead.BillNoItem != null)
                {
                    shipPlan.BillNoItem      = line.ShipPlanDetailHead.BillNoItem.ID;
                    shipPlan.BillNoItem_Name = line.ShipPlanDetailHead.BillNoItem.BillNoItemID;
                }

                listDtoData.Add(shipPlan);
            }
            return(listDtoData);
        }
Exemplo n.º 2
0
        public override object Do(object obj)
        {
            SynergySplit bpObj = (SynergySplit)obj;

            if (bpObj == null)
            {
                return(null);
            }
            string idList;

            switch (bpObj.SrcDocTypeEnum.Value)
            {
            case 0:
                #region 拆分   完全看不懂的代码,也不知道为何要这样写,如果大侠你有信心,可重新启用
//                    string idList = "";
//                    foreach (long id in bpObj.ID)
//                    {
//                        if (!idList.Contains(id.ToString()))
//                            idList += id + ",";
//                    }
//                    idList = idList.Substring(0, idList.Length - 1);
//                    StringBuilder split1 = new StringBuilder();
//                    split1.Append(@"select shiph.BillNoItem as BillNoItem,shiph.Client as Client,shiph.Currency as
//                                    Currency,shiph.IsManage as IsManage,shiph.GetOrderOrg as Org,shiph.SaleMan as
//                                    SaleMans,shiph.ShipPlanDate as ShipPlanDate,shiph.Memo as
//                                    Memo,shipl.SrcLineNo as SrcLineNo,shipl.Qty as
//                                    Qty,shipl.NumberUom as UOM,shipl.SrcLineID as SourceRowID,shipl.RowNo as
//                                    RowNo,shiph.DocNo as DocNo,shipl.[Standard] as
//                                    Standards,shipl.SrcDocNo as SrcDocNo,ParentPart as ParentPart,a.SubKey as
//                                    SubKey,OrderLine,B.SubKey,B.ID as ItemID,A.ParentPart as ParentPart,hs.HSID as HSID,hs.HSCode as HSCode from GS_FT_OrderBomLine B
//                                inner join  GS_FT_OrderBomHead A
//                                ON B.OrderBomHead=A.ID
//                                left join SM_SO so on A.OrderHead = so.ID
//
//                                left join SM_SOLine sol on sol.SO=so.ID
//								left join CBO_ItemMaster imt on sol.ItemInfo_ItemID = imt.ID
//								left join
//								(
//								select cts.ID as HSID,HSCode,item.EntranceInfo from CBO_Customs cts left join CBO_EntranceInfo info on cts.ID=info.CIQCdoe left join CBO_ItemMaster item on item.EntranceInfo=info.ID
//								) hs on hs.EntranceInfo = imt.EntranceInfo
//                                left join GS_FT_ShipPlanDetailLine shipl on shipl.SrcLineID = sol.ID
//                                left join GS_FT_ShipPlanDetailHead shiph on shiph.ID=shipl.ShipPlanDetailHead
//                            WHERE A.OrderLine IN (SELECT SrcLineID FROM GS_FT_ShipPlanDetailLine) and shiph.BillNoItem='" + idList + "'");
//                        //用SQL语句查出数据,并保存到Table里面
//                        DataSet ds1 = new DataSet();
//                        DataAccessor.RunSQL(DataAccessor.GetConn(), split1.ToString(), null, out ds1);

//                        using (ISession session = Session.Open())//Session提交数据库
//                        {

//                            //循环遍历Table取数,并赋值报关协同单
//                            int lineNum = 10;
//                            foreach (DataRow dr3 in ds1.Tables[0].Rows)
//                            {
//                                UFIDA.U9.Cust.GS.FT.SynergyBE.SynergyHead doc = UFIDA.U9.Cust.GS.FT.SynergyBE.SynergyHead.Create();
//                                doc.BillNoItem = BillNoItemHead.Finder.FindByID(dr3["BillNoItem"].ToString());//发票号组
//                                doc.Client = Customer.Finder.FindByID(dr3["Client"].ToString());//客户

//                                doc.ShipPlanDate = Convert.ToDateTime(dr3["ShipPlanDate"].ToString());//储运日期
//                                //doc.State = dr["State"].ToString();

//                                doc.SalesStaff = Operators.Finder.FindByID(dr3["SaleMans"].ToString());//外销员
//                                doc.Currency = Currency.Finder.FindByID(dr3["Currency"].ToString());//币种
//                                doc.IsLiOrder = true;
//                                UFIDA.U9.Cust.GS.FT.SynergyBE.SynergyLine line = UFIDA.U9.Cust.GS.FT.SynergyBE.SynergyLine.Create(doc);


//                                line.RowNo = lineNum;
//                                lineNum = lineNum + 10;
//                                line.SourceSellNo = dr3["SrcDocNo"].ToString();
//                                line.Standard = dr3["Standards"].ToString();
//                                //line.BillNo = BillNo.Finder.FindByID(dr3["BillNoID"].ToString());//发票号
//                                line.ParentPart = ItemMaster.Finder.FindByID(dr3["ParentPart"].ToString());//母件
//                                line.HSCode = Customs.Finder.FindByID(dr3["HSID"].ToString());//HS编码
//                                line.SubKey = ItemMaster.Finder.FindByID(dr3["SubKey"].ToString());//子件
//                                line.SourceSellRowNo = Convert.ToInt32(dr3["SrcLineNo"].ToString());
//                                line.SourceOrderNo = dr3["DocNo"].ToString();//来源单号
//                                line.SourceLineID = Convert.ToInt32(dr3["RowNo"].ToString());//来源行ID
//                                //line.SubKey = dr["Son"].ToString();//子件
//                                //line.ParentPart = dr["Parent"].ToString();//母件
//                                line.Qty = Convert.ToDecimal(dr3["Qty"].ToString());//数量
//                                line.Uom = UOM.Finder.FindByID(dr3["UOM"].ToString());//计量单位

//                            }
//                            session.Commit();
//                        }

                #endregion

                #region  重写后的拆分逻辑
                //发票组信息
                BillNoItemHead billNoHeads = BillNoItemHead.Finder.FindByID(bpObj.ID[0]);
                if (billNoHeads != null)
                {
                    //查询出运明细
                    ShipPlanDetailLine.EntityList shipPlanLines = ShipPlanDetailLine.Finder.FindAll("ShipPlanDetailHead.BillNoItem=@BillNoItem and ShipPlanDetailHead.GetOrderOrg.Code=@OrgCode", new OqlParam[2] {
                        new OqlParam(billNoHeads.ID), new OqlParam("J003")
                    });

                    using (ISession session = Session.Open())
                    {
                        UFIDA.U9.Cust.GS.FT.SynergyBE.SynergyHead syneryHead = UFIDA.U9.Cust.GS.FT.SynergyBE.SynergyHead.Create();
                        //doc.SynergyLine=//报关协同单行
                        syneryHead.BillNoItem   = billNoHeads;                                      //发票号组
                        syneryHead.Client       = shipPlanLines[0].ShipPlanDetailHead.Client;       //客户
                        syneryHead.ShipPlanDate = shipPlanLines[0].ShipPlanDetailHead.ShipPlanDate; //出运日期
                        syneryHead.State        = DocumnetSate.OpenState;                           //状态
                        syneryHead.SalesStaff   = shipPlanLines[0].ShipPlanDetailHead.SaleMan;      //外销员
                        syneryHead.Currency     = shipPlanLines[0].ShipPlanDetailHead.Currency;     //币种
                        //doc.LiOrderDate =//理单日期
                        //doc.Memo =//备注
                        syneryHead.IsLiOrder = false;    //已理单
                        int RowNo = 10;
                        foreach (ShipPlanDetailLine shipPlanLine in shipPlanLines)
                        {
                            CreateSynergyLine(syneryHead, shipPlanLine, RowNo);
                            RowNo = RowNo + 10;
                        }
                        session.Commit();
                    }
                }
                else
                {
                    throw new Exception("未找到发票组信息!");
                }
                #endregion
                break;

            case 1:
                #region 理单
                #region 接单组织为“巨星科技”,查找出运明细单
                if (bpObj.DocOrg == 1001411156754664)
                {
                    string idList1 = "";
                    foreach (long id1 in bpObj.ID)
                    {
                        if (!idList1.Contains(id1.ToString()))
                        {
                            idList1 += id1 + ",";
                        }
                    }
                    idList = idList1.Substring(0, idList1.Length - 1);
                    StringBuilder split = new StringBuilder();
                    split.Append(@"select shiph.BillNoItem as BillNoItem,shiph.Client as Client,shiph.Currency as
                                    Currency,shiph.IsManage as IsManage,shiph.GetOrderOrg as Org,shiph.SaleMan as
                                    SaleMans,shiph.ShipPlanDate as ShipPlanDate,shiph.Memo as
                                    Memo,shipl.SrcLineNo as SrcLineNo,shipl.Qty as
                                    Qty,shipl.NumberUom as UOM,shipl.SrcLineID as SourceRowID,shipl.RowNo as
                                    RowNo,shiph.DocNo as DocNo,shipl.[Standard] as
                                    Standards,shipl.SrcDocNo as SrcDocNo,OrderLine,B.SubKey as SubKey,A.ParentPart as
                                    ParentPart,hs.HSID as HSID,hs.HSCode as
                                    HSCode,A.ID as BOMID,shipl.SrcSO as SrcSoID,shipl.SrcLineID as SrcLineID,sol.ItemInfo_ItemID as ItemInfo_ItemID from GS_FT_OrderBomLine B 
                                inner join GS_FT_OrderBomHead A
                                ON B.OrderBomHead=A.ID 
                                left join SM_SO so on A.OrderHead = so.ID 

                                left join SM_SOLine sol on sol.SO=so.ID 
								left join CBO_ItemMaster imt on sol.ItemInfo_ItemID = imt.ID
								left join 
								(
								select cts.ID as HSID,HSCode,item.EntranceInfo from CBO_Customs cts left join CBO_EntranceInfo info on cts.ID=info.CIQCdoe left join CBO_ItemMaster item on item.EntranceInfo=info.ID
								) hs on hs.EntranceInfo = imt.EntranceInfo
                                left join GS_FT_ShipPlanDetailLine shipl on shipl.SrcLineID = sol.ID 
                                left join GS_FT_ShipPlanDetailHead shiph on shiph.ID=shipl.ShipPlanDetailHead 
                            WHERE A.OrderLine IN (SELECT SrcLineID FROM GS_FT_ShipPlanDetailLine) and shiph.BillNoItem='" + idList + "'");
                    DataSet ds = new DataSet();
                    DataAccessor.RunSQL(DataAccessor.GetConn(), split.ToString(), null, out ds);
                    using (ISession session = Session.Open())
                    {
                        UFIDA.U9.Cust.GS.FT.CustomsDetailBE.CustomsDetailHead doc = UFIDA.U9.Cust.GS.FT.CustomsDetailBE.CustomsDetailHead.Create();
                        int lineNum = 10;
                        foreach (DataRow dr in ds.Tables[0].Rows)
                        {
                            UFIDA.U9.Cust.GS.FT.CustomsDetailBE.CustomsDetailLine line = UFIDA.U9.Cust.GS.FT.CustomsDetailBE.CustomsDetailLine.Create(doc);

                            doc.BillNoItem   = BillNoItemHead.Finder.FindByID(dr["BillNoItem"].ToString());
                            doc.Client       = Customer.Finder.FindByID(dr["Client"].ToString());   //客户
                            doc.ShipPlanDate = Convert.ToDateTime(dr["ShipPlanDate"].ToString());   //出运日期
                            //doc.State = dr["State"].ToString();
                            doc.SalesStaff  = Operators.Finder.FindByID(dr["SaleMans"].ToString()); //外销员
                            doc.Currency    = Currency.Finder.FindByID(dr["Currency"].ToString());  //币种
                            doc.GetOrderOrg = Organization.Finder.FindByID(dr["Org"].ToString());   //接单组织

                            #region 查询随单BOM,推到报关明细单理单页签

                            StringBuilder sb = new StringBuilder();
                            sb.Append(@"select obl.SubKey,* from GS_FT_OrderBomHead obh left join GS_FT_OrderBomLine obl on obl.OrderBomHead=obh.ID where obh.ID='" + dr["BOMID"].ToString() + "'");
                            DataSet dset = new DataSet();
                            DataAccessor.RunSQL(DataAccessor.GetConn(), sb.ToString(), null, out dset);
                            foreach (DataRow drow in dset.Tables[0].Rows)
                            {
                                UFIDA.U9.Cust.GS.FT.CustomsDetailBE.LiOrderLine liLine = UFIDA.U9.Cust.GS.FT.CustomsDetailBE.LiOrderLine.Create(line);
                                //liLine.BillNo = BillNo.Finder.FindByID(dr["BillNoID"].ToString());//发票号
                                liLine.HSCode = Customs.Finder.FindByID(dr["HSID"].ToString());    //HS编码
                                //liLine.OrderNo = drow["SourceSellNo"].ToString();
                                //line.HSCode = Customs.Finder.FindByID(dr["EntranceInfo"].ToString());
                                liLine.Subclass     = ItemMaster.Finder.FindByID(drow["SubKey"].ToString());        //小类
                                liLine.ClassMark    = ItemMaster.Finder.FindByID(dr["ItemInfo_ItemID"].ToString()); //料品编码
                                liLine.SourceLineNo = Convert.ToInt32(dr["RowNo"].ToString());                      //行号

                                //liLine.PurchasePrice = Convert.ToDecimal(dr["Price"].ToString());//采购价
                                //liLine.Amount = Convert.ToDecimal(dr["CustomsAmount"].ToString());//金额
                                //liLine.Subclass = ItemMaster.Finder.FindByID(dr["SubKey"].ToString());//小类
                                liLine.Qty = Convert.ToDecimal(dr["Qty"].ToString());    //数量
                                liLine.Uom = UOM.Finder.FindByID(dr["Uom"].ToString());  //计量单位
                            }
                            //UFIDA.U9.Cust.GS.FT.OrderBomBE.OrderBomHead head = UFIDA.U9.Cust.GS.FT.OrderBomBE.OrderBomHead.Finder.FindByID(Convert.ToInt64(dr["BOMID"].ToString()));

                            //UFIDA.U9.Cust.GS.FT.CustomsDetailBE.LiOrderLine liLine = null;
                            //foreach (OrderBomBE.OrderBomLine bomLine in head.OrderBomLine)
                            //{
                            //    liLine = UFIDA.U9.Cust.GS.FT.CustomsDetailBE.LiOrderLine.Create(line);
                            //    liLine.Subclass = bomLine.SubKey;//小类
                            //    liLine.Qty = bomLine.NeedNumber;//数量
                            //    liLine.Uom = bomLine.NeedUom;//计量单位
                            //}
                            #endregion

                            line.RowNo       = lineNum;
                            lineNum          = lineNum + 10;
                            line.HSCode      = Customs.Finder.FindByID(dr["HSID"].ToString());
                            line.ClassMark   = ItemMaster.Finder.FindByID(dr["ItemInfo_ItemID"].ToString());
                            line.SourceRowNo = Convert.ToInt32(dr["RowNo"].ToString());     //来源行号
                            line.OrderNo     = dr["SrcDocNo"].ToString();                   //订单号
                            line.OrderID     = Convert.ToInt64(dr["SrcSoID"].ToString());   //订单ID
                            line.OrderLineNo = Convert.ToInt32(dr["SrcLineNo"].ToString()); //订单行号
                            line.OrderLineID = Convert.ToInt64(dr["SrcLineID"].ToString()); //订单行ID
                            //line.HSCode = Customs.Finder.FindByID(dr["Item"].ToString());//HS编码
                        }
                        session.Commit();
                    }
                }

                #endregion
                #region 接单组织为“香港巨星”,查找报关协同单
                if (bpObj.DocOrg == 1001411156754442)
                {
                    string idList2 = "";
                    foreach (long id2 in bpObj.ID)
                    {
                        if (!idList2.Contains(id2.ToString()))
                        {
                            idList2 += id2 + ",";
                        }
                    }
                    idList = idList2.Substring(0, idList2.Length - 1);
                    StringBuilder split = new StringBuilder();
                    split.Append(@"select shiph.BillNoItem as BillNoItem,shiph.Client as Client,shiph.Currency as
                                    Currency,shiph.IsManage as IsManage,shiph.GetOrderOrg as Org,shiph.SaleMan as
                                    SaleMans,shiph.ShipPlanDate as ShipPlanDate,shiph.Memo as
                                    Memo,shipl.SrcLineNo as SrcLineNo,shipl.Qty as
                                    Qty,shipl.NumberUom as UOM,shipl.SrcLineID as SourceRowID,shipl.RowNo as
                                    RowNo,shiph.DocNo as DocNo,shipl.[Standard] as
                                    Standards,shipl.SrcDocNo as SrcDocNo,OrderLine,B.SubKey as SubKey,A.ParentPart as
                                    ParentPart,hs.HSID as HSID,hs.HSCode as
                                    HSCode,A.ID as BOMID,shipl.SrcSO as SrcSoID,shipl.SrcLineID as SrcLineID,sol.ItemInfo_ItemID as ItemInfo_ItemID from GS_FT_OrderBomLine B 
                                inner join GS_FT_OrderBomHead A
                                ON B.OrderBomHead=A.ID 
                                left join SM_SO so on A.OrderHead = so.ID 

                                left join SM_SOLine sol on sol.SO=so.ID 
								left join CBO_ItemMaster imt on sol.ItemInfo_ItemID = imt.ID
								left join 
								(
								select cts.ID as HSID,HSCode,item.EntranceInfo from CBO_Customs cts left join CBO_EntranceInfo info on cts.ID=info.CIQCdoe left join CBO_ItemMaster item on item.EntranceInfo=info.ID
								) hs on hs.EntranceInfo = imt.EntranceInfo
                                left join GS_FT_ShipPlanDetailLine shipl on shipl.SrcLineID = sol.ID 
                                left join GS_FT_ShipPlanDetailHead shiph on shiph.ID=shipl.ShipPlanDetailHead 
                            WHERE A.OrderLine IN (SELECT SrcLineID FROM GS_FT_ShipPlanDetailLine) and shiph.BillNoItem='" + idList + "'");
                    DataSet ds = new DataSet();
                    DataAccessor.RunSQL(DataAccessor.GetConn(), split.ToString(), null, out ds);
                    using (ISession session = Session.Open())
                    {
                        UFIDA.U9.Cust.GS.FT.CustomsDetailBE.CustomsDetailHead doc = UFIDA.U9.Cust.GS.FT.CustomsDetailBE.CustomsDetailHead.Create();
                        //UFIDA.U9.Cust.GS.FT.SynergyBE.SynergyHead doc = UFIDA.U9.Cust.GS.FT.SynergyBE.SynergyHead.Create();
                        //UFIDA.U9.Cust.GS.FT.BillNoItemBE.BillNoItemHead doc1 = UFIDA.U9.Cust.GS.FT.BillNoItemBE.BillNoItemHead.Finder.FindByID(doc);
                        //doc.BillNoItem = doc1;
                        int lineNum = 10;
                        foreach (DataRow dr in ds.Tables[0].Rows)
                        {
                            UFIDA.U9.Cust.GS.FT.CustomsDetailBE.CustomsDetailLine line = UFIDA.U9.Cust.GS.FT.CustomsDetailBE.CustomsDetailLine.Create(doc);

                            doc.BillNoItem   = BillNoItemHead.Finder.FindByID(dr["BillNoItem"].ToString());
                            doc.Client       = Customer.Finder.FindByID(dr["Client"].ToString());      //客户
                            doc.ShipPlanDate = Convert.ToDateTime(dr["ShipPlanDate"].ToString());      //出运日期
                            //doc.State = dr["State"].ToString();
                            doc.SalesStaff  = Operators.Finder.FindByID(dr["SaleMans"].ToString());    //外销员
                            doc.Currency    = Currency.Finder.FindByID(dr["Currency"].ToString());     //币种
                            doc.GetOrderOrg = Organization.Finder.FindByID(dr["Org"].ToString());      //接单组织
                            #region 查询报关协同单,推到报关明细单理单页签

                            StringBuilder sb = new StringBuilder();
                            sb.Append(@"select b.HSCode as HSCode,b.BillNo as BillNo,b.Price as
                                                        Price,b.CustomsAmount as CustomsAmount,b.Qty as
                                                        Qty,b.SubKey as SubKey,b.Uom as Uom,b.SourceSellRowNo as
                                                        SourceSellRowNo,b.RowNo as RowNo,b.SourceSellNo as
                                                        SourceSellNo from
                                                        GS_FT_SynergyHead a 
                                                    left join GS_FT_SynergyLine b on b.SynergyHead=a.ID where b.SourceSellRowNo='" + dr["SrcLineNo"].ToString() + "'");
                            DataSet dset = new DataSet();
                            DataAccessor.RunSQL(DataAccessor.GetConn(), sb.ToString(), null, out dset);
                            foreach (DataRow drow in dset.Tables[0].Rows)
                            {
                                UFIDA.U9.Cust.GS.FT.CustomsDetailBE.LiOrderLine liLine = UFIDA.U9.Cust.GS.FT.CustomsDetailBE.LiOrderLine.Create(line);
                                //liLine.BillNo = BillNo.Finder.FindByID(dr["BillNoID"].ToString());//发票号
                                liLine.HSCode  = Customs.Finder.FindByID(dr["HSID"].ToString());           //HS编码
                                liLine.OrderNo = drow["SourceSellNo"].ToString();
                                //line.HSCode = Customs.Finder.FindByID(dr["EntranceInfo"].ToString());
                                liLine.Subclass     = ItemMaster.Finder.FindByID(dr["SubKey"].ToString());          //小类
                                liLine.ClassMark    = ItemMaster.Finder.FindByID(dr["ItemInfo_ItemID"].ToString()); //料品编码
                                liLine.SourceLineNo = Convert.ToInt32(drow["RowNo"].ToString());                    //行号
                                //liLine.PurchasePrice =Convert.ToDecimal(drow["Price"].ToString());//采购价
                                liLine.Amount = Convert.ToDecimal(drow["CustomsAmount"].ToString());                //金额
                                //liLine.Subclass = ItemMaster.Finder.FindByID(drow["SubKey"].ToString());//小类
                                liLine.Qty = Convert.ToDecimal(drow["Qty"].ToString());                             //数量
                                liLine.Uom = UOM.Finder.FindByID(drow["Uom"].ToString());                           //计量单位
                            }
                            //UFIDA.U9.Cust.GS.FT.SynergyBE.SynergyLine.EntityList head = UFIDA.U9.Cust.GS.FT.SynergyBE.SynergyLine.Finder.FindAll("SourceOrderLineID=" + dr["SrcLineID"].ToString());// + "'and SubkeyType='" + '0'
                            //foreach (SynergyBE.SynergyLine synergyLine in head)
                            //{
                            //    UFIDA.U9.Cust.GS.FT.CustomsDetailBE.LiOrderLine liLine = UFIDA.U9.Cust.GS.FT.CustomsDetailBE.LiOrderLine.Create(line);
                            //    liLine.BillNo = synergyLine.BillNo;//发票号
                            //    liLine.HSCode = synergyLine.HSCode;//HS编码
                            //    liLine.PurchasePrice = synergyLine.Price;//采购价
                            //    liLine.Amount = synergyLine.CustomsAmount;//金额
                            //    liLine.Subclass =ItemMaster.Finder.FindByID(synergyLine.SubKey);//小类
                            //    liLine.Qty = synergyLine.Qty;//数量
                            //    liLine.Uom = synergyLine.Uom;//计量单位
                            //}
                            #endregion
                            line.RowNo       = lineNum;
                            lineNum          = lineNum + 10;
                            line.HSCode      = Customs.Finder.FindByID(dr["HSID"].ToString());
                            line.ClassMark   = ItemMaster.Finder.FindByID(dr["ItemInfo_ItemID"].ToString());
                            line.SourceRowNo = Convert.ToInt32(dr["RowNo"].ToString());     //来源行号
                            line.OrderNo     = dr["SrcDocNo"].ToString();                   //订单号
                            line.OrderID     = Convert.ToInt64(dr["SrcSoID"].ToString());   //订单ID
                            line.OrderLineNo = Convert.ToInt32(dr["SrcLineNo"].ToString()); //订单行号
                            line.OrderLineID = Convert.ToInt64(dr["SrcLineID"].ToString()); //订单行ID
                            //line.HSCode = Customs.Finder.FindByID(dr["Item"].ToString());//HS编码
                        }
                        session.Commit();
                    }
                }

                #endregion
                #endregion
                break;

            case 2:
                #region 汇总

                StringBuilder trim = new StringBuilder();
                trim.Append(@"select BillNo,HSCode,Subclass,(select sum(Qty) as Qty from GS_FT_LiOrderLine as a 
											 group by BillNo,HSCode) 
											 as Qty from  
                                            (
                                            select c.ID,BillNo,c.HSCode,Subclass,c.Qty from GS_FT_LiOrderLine c 
                                            left join GS_FT_CustomsDetailLine d on c.CustomsDetailLine=d.ID 
                                            left join GS_FT_CustomsDetailHead e on d.CustomsDetailHead=e.ID
                                            where e.ID='" + bpObj.TrimLineID + "')as b group by BillNo,HSCode,Subclass");
                DataSet ds1 = new DataSet();
                DataAccessor.RunSQL(DataAccessor.GetConn(), trim.ToString(), null, out ds1);
                using (ISession session = Session.Open())
                {
                    UFIDA.U9.Cust.GS.FT.CustomsDetailBE.CustomsDetailHead head = UFIDA.U9.Cust.GS.FT.CustomsDetailBE.CustomsDetailHead.Finder.FindByID(bpObj.TrimLineID);
                    foreach (DataRow dr in ds1.Tables[0].Rows)
                    {
                        CustomsLine lince = CustomsLine.Create(head);
                        //lince.BillNo = BillNo.Finder.FindByID(dr["BillNo"].ToString());//发票号
                        lince.HSCode   = Customs.Finder.FindByID(dr["HSCode"].ToString());      //HS编码
                        lince.Subclass = ItemMaster.Finder.FindByID(dr["Subclass"].ToString()); //小类
                        lince.Qty      = Convert.ToDecimal(dr["Qty"].ToString());               //数量
                        session.Commit();
                    }
                }
                #region

                //UFIDA.U9.Cust.GS.FT.CustomsDetailBE.CustomsDetailHead custhead = UFIDA.U9.Cust.GS.FT.CustomsDetailBE.CustomsDetailHead.Finder.FindByID(bpObj.TrimLineID);
                //UFIDA.U9.Cust.GS.FT.CustomsDetailBE.CustomsDetailLine detailline = UFIDA.U9.Cust.GS.FT.CustomsDetailBE.CustomsDetailLine.Create(custhead);
                //UFIDA.U9.Cust.GS.FT.CustomsDetailBE.LiOrderLine liline = UFIDA.U9.Cust.GS.FT.CustomsDetailBE.LiOrderLine.Create(detailline);
                //if (custhead != null)
                //{
                //    return null;

                //    foreach (CustomsDetailBE.CustomsDetailLine line in custhead.CustomsDetailLine)
                //    {

                //        foreach (CustomsDetailBE.LiOrderLine lidan in detailline.LiOrderLine)
                //        {
                //            UFIDA.U9.Cust.GS.FT.CustomsDetailBE.CustomsLine custline = UFIDA.U9.Cust.GS.FT.CustomsDetailBE.CustomsLine.Create(custhead);
                //            custline.BillNo = lidan.BillNo;
                //            custline.HSCode = lidan.HSCode;
                //            custline.Qty = lidan.Qty;
                //            custline.PurchasePrice = lidan.PurchasePrice;
                //            custline.Amount = lidan.Amount;
                //            custline.Subclass = lidan.Subclass;
                //        }
                //    }
                //}
                #endregion
                #endregion
                break;
            }
            return(null);
        }
Exemplo n.º 3
0
        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);
        }