Пример #1
0
        /// <summary>
        /// 获取一条信息记录
        /// </summary>
        /// <param name="param"></param>
        /// <returns></returns>
        public ORD_SalesReturnResult GetInfo(ORD_SalesReturnParam param)
        {
            this.CheckSession();
            ORD_SalesReturnResult rst = new ORD_SalesReturnResult();

            #region 判断
            if (param.SRGuid == null)
            {
                throw new WarnException("请指定销售退货单GUID!");
            }
            #endregion
            #region 获取实体

            rst = this.Select <ORD_SalesReturnResult>(GetWhereClip(param));
            if (rst != null)
            {
                string[] statusArr = new string[] { rst.StkInStatus };
                rst.AllStatus = string.Join(",", statusArr);

                ORD_SalesReturnLineBLL lineBLL = new ORD_SalesReturnLineBLL();
                lineBLL.SessionInfo = this.SessionInfo;
                rst.ReturnLineList  = lineBLL.GetList(new ORD_SalesReturnLineParam()
                {
                    SRGuid = rst.SRGuid
                });
                //this.SelectList<ORD_SalesOrderLineResult>(ORD_SalesOrderLine._.SOGuid == rst.SOGuid);

                HR_DepartmentBLL deptBLL = new HR_DepartmentBLL();
                deptBLL.SessionInfo = this.SessionInfo;
                HR_DepartmentResult deptResult = deptBLL.GetInfo(new HR_DepartmentParam()
                {
                    DeptID = rst.OperDeptID
                });
                rst.OperDeptName = deptResult.DeptName;
            }
            #endregion
            return(rst);
        }
Пример #2
0
        public bool SubmitSalesReturnBill(ORD_SalesReturnParam param)
        {
            this.CheckSession();
            bool submitFlag = true;

            try
            {
                ORD_SalesReturnResult returnResult = this.GetInfo(param);

                if (returnResult != null)
                {
                    #region 判断是否可以提交

                    bool isAllowSubmit = true;

                    if (returnResult.ApproveStatus == "待审核")
                    {
                        isAllowSubmit = false;
                        throw new WarnException("销售退货单当前状态为:【已提交,待审核】,禁止重复提交!");
                    }
                    else if (returnResult.ApproveStatus == "审核完成")
                    {
                        isAllowSubmit = false;
                        throw new WarnException("销售退货单当前状态为:【审核完成】,撤单后才可以再次提交!");
                    }
                    if (isAllowSubmit)
                    {
                        returnResult.Status        = "Approve";
                        returnResult.ApproveStatus = "待审核";
                        WCFAddUpdateResult ret = this.AddOrUpdate(returnResult);
                        if (ret.KeyGuid.ToGuid() == Guid.Empty)
                        {
                            submitFlag = false;
                        }
                        else
                        {
                            #region 定义相关变量
                            ORD_SalesOrderBLL saleOrderBLL = new ORD_SalesOrderBLL();
                            saleOrderBLL.SessionInfo = this.SessionInfo;
                            ORD_SalesOrderLineBLL saleOrderLineBLL = new ORD_SalesOrderLineBLL();
                            saleOrderLineBLL.SessionInfo = this.SessionInfo;
                            STK_OutBLL outBLL = new STK_OutBLL();
                            outBLL.SessionInfo = this.SessionInfo;
                            STK_OutLineBLL outLineBLL = new STK_OutLineBLL();
                            outLineBLL.SessionInfo = this.SessionInfo;
                            ORD_SalesReturnLineBLL returnLineBLL = new ORD_SalesReturnLineBLL();
                            returnLineBLL.SessionInfo = this.SessionInfo;
                            Guid?[] SOLineGuids     = null;
                            Guid?[] StkOutLineGuids = null;
                            Guid?[] SRGuids         = null;
                            Guid?[] effSRGuids      = null;
                            Guid?[] SOGuids         = null;
                            List <STK_OutLineResult>         linkOutLineList       = new List <STK_OutLineResult>();
                            List <ORD_SalesOrderLineResult>  linkSaleOrderLineList = new List <ORD_SalesOrderLineResult>();
                            List <ORD_SalesReturnResult>     linkReturnList        = new List <ORD_SalesReturnResult>();
                            List <ORD_SalesReturnLineResult> linkReturnLineList    = new List <ORD_SalesReturnLineResult>();
                            List <ORD_SalesReturnLineResult> effReturnLineList     = new List <ORD_SalesReturnLineResult>();
                            #endregion
                            List <ORD_SalesReturnLineResult> salesReturnLineList = returnLineBLL.GetList(new ORD_SalesReturnLineParam()
                            {
                                SRGuid = returnResult.SRGuid
                            });

                            #region 更新出库明细的数量
                            //获取退货明细关联的出库明细ID集合
                            StkOutLineGuids = salesReturnLineList.Select(a => a.StkOutLineGuid).Distinct().ToArray();
                            if (StkOutLineGuids != null && StkOutLineGuids.Length > 0)
                            {
                                //退货明细关联的出库明细
                                linkOutLineList = outLineBLL.GetList(new STK_OutLineParam()
                                {
                                    StkOutLineGuids = StkOutLineGuids
                                });
                                //关联的出库明细所关联的退货明细
                                linkReturnLineList = returnLineBLL.GetList(new ORD_SalesReturnLineParam()
                                {
                                    StkOutLineGuids = StkOutLineGuids
                                });
                                SRGuids = linkReturnLineList.Select(a => a.SRGuid).Distinct().ToArray();
                                if (SRGuids != null && SRGuids.Length > 0)
                                {
                                    //关联的出库明细所关联的退货明细对应的退货主单
                                    linkReturnList = this.GetList(new ORD_SalesReturnParam()
                                    {
                                        SRGuids = SRGuids, StatusArr = new string[] { "Complete", "Approve" }
                                    });
                                    if (linkReturnList != null && linkReturnList.Count > 0)
                                    {
                                        effSRGuids        = linkReturnList.Select(a => (Guid?)a.SRGuid).Distinct().ToArray();
                                        effReturnLineList = linkReturnLineList.Where(a => effSRGuids.Contains(a.SRGuid)).ToList();
                                        foreach (STK_OutLineResult outLineResult in linkOutLineList)
                                        {
                                            int?qty = effReturnLineList.Where(a => a.StkOutLineGuid == outLineResult.StkOutLineGuid).Sum(a => a.Qty.ToInt32());
                                            outLineResult.ReturnOccQty = qty;
                                        }
                                    }
                                }
                                //更新退货明细关联的出库明细的退货数量
                                outLineBLL.UpdateOrInsertList(linkOutLineList);
                            }
                            #endregion

                            #region 更新销售明细的退货占有数量和销售主单的退货占有状态
                            //获取关联的销售明细ID集合
                            SOLineGuids           = salesReturnLineList.Select(a => a.SOLineGuid).Distinct().ToArray();
                            linkSaleOrderLineList = saleOrderLineBLL.GetList(new ORD_SalesOrderLineParam()
                            {
                                SOLineGuids = SOLineGuids, IsCancel = false
                            });
                            //获取关联的销售明细所关联的退货明细
                            linkReturnLineList = returnLineBLL.GetList(new ORD_SalesReturnLineParam()
                            {
                                SOLineGuids = SOLineGuids
                            });
                            SRGuids = linkReturnLineList.Select(a => a.SRGuid).Distinct().ToArray();
                            if (SRGuids != null && SRGuids.Length > 0)
                            {
                                //销售明细所关联的退货明细对应的退货主单
                                linkReturnList = this.GetList(new ORD_SalesReturnParam()
                                {
                                    SRGuids = SRGuids, StatusArr = new string[] { "Complete", "Approve" }
                                });
                                if (linkReturnList != null && linkReturnList.Count > 0)
                                {
                                    effSRGuids        = linkReturnList.Select(a => (Guid?)a.SRGuid).Distinct().ToArray();
                                    effReturnLineList = linkReturnLineList.Where(a => effSRGuids.Contains(a.SRGuid)).ToList();
                                    foreach (ORD_SalesOrderLineResult saleLineResult in linkSaleOrderLineList)
                                    {
                                        int?qty = effReturnLineList.Where(a => a.SOLineGuid == saleLineResult.SOLineGuid).Sum(a => a.Qty.ToInt32());
                                        saleLineResult.ReturnOccQty = qty;
                                    }
                                }
                            }
                            saleOrderLineBLL.UpdateOrInsertList(linkSaleOrderLineList);
                            SOGuids = linkSaleOrderLineList.Select(a => a.SOGuid).Distinct().ToArray();
                            foreach (Guid soguid in SOGuids)
                            {
                                saleOrderBLL.UpdateStatus(new ORD_SalesOrderParam()
                                {
                                    SOGuid = soguid
                                });
                            }

                            #endregion
                        }
                    }


                    #endregion
                }
                else
                {
                    throw new WarnException("要提交的销售退货单在系统中不存在!");
                }
            }
            catch (WarnException exp)
            {
                throw exp;
            }
            catch (Exception exp)
            {
                LogInfoBLL.WriteLog(this.SessionInfo, exp);
                throw exp;
            }
            return(submitFlag);
        }