Example #1
0
        /// <summary>
        /// 获取一条信息记录
        /// </summary>
        /// <param name="param"></param>
        /// <returns></returns>
        public ORD_PurchaseOrderResult GetInfo(ORD_PurchaseOrderParam param)
        {
            this.CheckSession();
            ORD_PurchaseOrderResult rst = new ORD_PurchaseOrderResult();

            #region 判断
            if (param.POGuid == null)
            {
                throw new WarnException("请指定采购单GUID!");
            }
            #endregion
            #region 获取实体

            rst = this.Select <ORD_PurchaseOrderResult>(GetWhereClip(param));
            if (rst != null)
            {
                string[] statusArr = new string[] { rst.StkInStatus, rst.StkOutStatus, rst.ReturnStatus, rst.PaymentStatus };
                rst.AllStatus = string.Join(",", statusArr);
                ORD_PurchaseOrderLineBLL lineBLL = new ORD_PurchaseOrderLineBLL();
                lineBLL.SessionInfo = this.SessionInfo;
                rst.OrderLineList   = lineBLL.GetList(new ORD_PurchaseOrderLineParam()
                {
                    POGuid = rst.POGuid
                });
                Guid?[] NoticeGuids             = rst.OrderLineList.Where(a => a.NoticeGuid != null).Select(a => a.NoticeGuid).Distinct().ToArray();
                ORD_PurchaseNoticeBLL noticeBLl = new ORD_PurchaseNoticeBLL();
                noticeBLl.SessionInfo = this.SessionInfo;
                ORD_PurchaseNoticeParam noticeParam = new ORD_PurchaseNoticeParam();
                noticeParam.NoticeGuids = NoticeGuids;
                List <ORD_PurchaseNoticeResult> noticeList = noticeBLl.GetList(noticeParam);

                foreach (ORD_PurchaseOrderLineResult lineResult in rst.OrderLineList)
                {
                    ORD_PurchaseNoticeResult noticeResult = noticeList.FirstOrDefault(a => a.NoticeGuid == lineResult.NoticeGuid);
                    if (noticeResult != null)
                    {
                        lineResult.SOLineCode         = noticeResult.SOLineCode;
                        lineResult.SOModel            = noticeResult.Model;
                        lineResult.SOBrand            = noticeResult.Brand;
                        lineResult.SOBatch            = noticeResult.Batch;
                        lineResult.SOPackage          = noticeResult.Package;
                        lineResult.SOQty              = noticeResult.SaleQty;
                        lineResult.SONeedDeliveryDate = noticeResult.NeedDeliveryDate;
                    }
                }
                rst.HR_DepartmentResult = this.Select <HR_DepartmentResult>(new List <Field>()
                {
                    HR_Department._.DeptID, HR_Department._.DeptName
                }, HR_Department._.DeptID == rst.PurDeptID);
            }



            #endregion
            return(rst);
        }
Example #2
0
        public bool AuditPurchaseOrderBill(ORD_PurchaseOrderParam param)
        {
            bool auditFlag = true;

            try
            {
                ORD_PurchaseOrderResult orderResult = this.GetInfo(param);

                if (orderResult != null)
                {
                    bool isAllowAudit = true;

                    if (orderResult.ApproveStatus == "待提交")
                    {
                        isAllowAudit = false;
                        throw new WarnException("采购单当前状态为:【待提交】,请先提交!");
                    }
                    else if (orderResult.ApproveStatus == "审核完成")
                    {
                        isAllowAudit = false;
                        throw new WarnException("采购单当前状态为:【审核完成】,禁止重复审核!");
                    }
                    if (isAllowAudit)
                    {
                        orderResult.Status        = "Complete";
                        orderResult.ApproveStatus = "审核完成";
                        WCFAddUpdateResult ret = this.AddOrUpdate(orderResult);
                        if (ret.KeyGuid.ToGuid() == Guid.Empty)
                        {
                            auditFlag = false;
                        }
                        else
                        {
                            #region  更新关联单据的相关数据(回写)和状态
                            //采购单关联的采购明细
                            List <ORD_PurchaseOrderLineResult> purLineList = orderResult.OrderLineList;
                            if (purLineList != null && purLineList.Count > 0)
                            {
                                #region 定义相关变量(可重复使用)
                                ORD_SalesOrderBLL saleOrderBLL = new ORD_SalesOrderBLL();
                                saleOrderBLL.SessionInfo = this.SessionInfo;
                                ORD_SalesOrderLineBLL saleLineBLL = new ORD_SalesOrderLineBLL();
                                saleLineBLL.SessionInfo = this.SessionInfo;
                                ORD_PurchaseNoticeBLL noticeBLL = new ORD_PurchaseNoticeBLL();
                                noticeBLL.SessionInfo = this.SessionInfo;
                                ORD_PurchaseOrderLineBLL purLineBLL = new ORD_PurchaseOrderLineBLL();
                                purLineBLL.SessionInfo = this.SessionInfo;
                                Guid?[] SOGuids     = null;
                                Guid?[] SOLineGuids = null;
                                Guid?[] NoticeGuids = null;
                                Guid?[] POGuids     = null;
                                Guid?[] effPOGuids  = null;
                                List <ORD_SalesOrderLineResult>    saleLineList     = null;
                                List <ORD_PurchaseNoticeResult>    noticeResultList = null;
                                List <ORD_PurchaseOrderResult>     purOrderList     = null;
                                List <ORD_PurchaseOrderLineResult> linkPurLineList  = null;
                                List <ORD_PurchaseOrderLineResult> effPurLineList   = null;

                                #endregion

                                #region 更新采购通知的采购数量
                                //获取关联的所有的采购通知guid
                                NoticeGuids = purLineList.Where(a => a.NoticeGuid != Guid.Empty && a.IsCancel != true).Select(a => a.NoticeGuid).Distinct().ToArray();
                                //获取关联的所有的采购通知信息
                                noticeResultList = noticeBLL.GetList(new ORD_PurchaseNoticeParam()
                                {
                                    NoticeGuids = NoticeGuids
                                });
                                if (noticeResultList != null && noticeResultList.Count > 0)
                                {
                                    //采购单明细关联的采购通知所有关联的采购明细
                                    linkPurLineList = purLineBLL.GetList(new ORD_PurchaseOrderLineParam()
                                    {
                                        NoticeGuids = NoticeGuids, IsCancel = false
                                    });
                                    //获取采购单明细关联的POGuid
                                    POGuids = linkPurLineList.Select(a => a.POGuid).Distinct().ToArray();
                                    //获取所有关联的采购主单
                                    purOrderList = this.GetList(new ORD_PurchaseOrderParam()
                                    {
                                        POGuids = POGuids, Status = "Complete"
                                    });
                                    if (purOrderList != null && purOrderList.Count > 0)
                                    {
                                        effPOGuids     = purOrderList.Select(a => a.POGuid).Distinct().ToArray();
                                        effPurLineList = linkPurLineList.Where(a => effPOGuids.Contains(a.POGuid)).ToList();
                                        foreach (ORD_PurchaseNoticeResult noticeResult in noticeResultList)
                                        {
                                            int?qty = effPurLineList.Where(a => a.NoticeGuid == noticeResult.NoticeGuid).Sum(a => a.Qty.ToInt32());
                                            noticeResult.PurchaseQty = qty;
                                        }
                                    }
                                    noticeBLL.UpdateOrInsertList(noticeResultList);
                                }
                                #endregion

                                #region 更新销售明细的采购数量
                                // 有关联销售同时未取消的采购明细
                                SOLineGuids = purLineList.Where(a => a.SOLineGuid != null && a.IsCancel != true).Select(a => a.SOLineGuid).Distinct().ToArray();
                                if (SOLineGuids != null && SOLineGuids.Length > 0)
                                {
                                    //采购明细关联的所有的销售明细(未取消)
                                    saleLineList = saleLineBLL.GetList(new ORD_SalesOrderLineParam()
                                    {
                                        SOLineGuids = SOLineGuids, IsCancel = false
                                    });
                                    if (saleLineList != null && saleLineList.Count > 0)
                                    {
                                        //销售明细所关联的采购明细(未取消)
                                        linkPurLineList = purLineBLL.GetList(new ORD_PurchaseOrderLineParam()
                                        {
                                            SOLineGuids = SOLineGuids, IsCancel = false
                                        });
                                        POGuids = linkPurLineList.Select(a => a.POGuid).Distinct().ToArray();
                                        if (POGuids != null && POGuids.Length > 0)
                                        {
                                            //销售明细所关联的采购明细对应的采购主单
                                            purOrderList = this.GetList(new ORD_PurchaseOrderParam()
                                            {
                                                POGuids = POGuids, Status = "Complete"
                                            });
                                            if (purOrderList != null && purOrderList.Count > 0)
                                            {
                                                effPOGuids     = purOrderList.Select(a => a.POGuid).Distinct().ToArray();
                                                effPurLineList = linkPurLineList.Where(a => effPOGuids.Contains(a.POGuid)).ToList();
                                                foreach (ORD_SalesOrderLineResult saleLineResult in saleLineList)
                                                {
                                                    int?qty = effPurLineList.Where(a => a.SOLineGuid == saleLineResult.SOLineGuid).Sum(a => a.Qty.ToInt32());
                                                    saleLineResult.PurchaseQty = qty;
                                                }
                                            }
                                        }
                                        saleLineBLL.UpdateOrInsertList(saleLineList);
                                        SOGuids = saleLineList.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(auditFlag);
        }
Example #3
0
        public bool SubmitPurchaseReturnBill(ORD_PurchaseReturnParam param)
        {
            this.CheckSession();
            bool submitFlag = true;

            try
            {
                ORD_PurchaseReturnResult 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_PurchaseOrderBLL purOrderBLL = new ORD_PurchaseOrderBLL();
                            purOrderBLL.SessionInfo = this.SessionInfo;
                            ORD_PurchaseOrderLineBLL purOrderLineBLL = new ORD_PurchaseOrderLineBLL();
                            purOrderLineBLL.SessionInfo = this.SessionInfo;
                            STK_InBLL inBLL = new STK_InBLL();
                            inBLL.SessionInfo = this.SessionInfo;
                            STK_InLineBLL inLineBLL = new STK_InLineBLL();
                            inLineBLL.SessionInfo = this.SessionInfo;
                            ORD_PurchaseReturnLineBLL returnLineBLL = new ORD_PurchaseReturnLineBLL();
                            returnLineBLL.SessionInfo = this.SessionInfo;
                            STK_StockReserveBLL reserveBLL = new STK_StockReserveBLL();
                            reserveBLL.SessionInfo = this.SessionInfo;
                            Guid?[] POLineGuids    = null;
                            Guid?[] StkInLineGuids = null;
                            Guid?[] PRGuids        = null;
                            Guid?[] effPRGuids     = null;
                            Guid?[] POGuids        = null;
                            List <STK_InLineResult>             linkInLineList            = new List <STK_InLineResult>();
                            List <ORD_PurchaseOrderLineResult>  linkPurchaseOrderLineList = new List <ORD_PurchaseOrderLineResult>();
                            List <ORD_PurchaseReturnResult>     linkReturnList            = new List <ORD_PurchaseReturnResult>();
                            List <ORD_PurchaseReturnLineResult> linkReturnLineList        = new List <ORD_PurchaseReturnLineResult>();
                            List <ORD_PurchaseReturnLineResult> effReturnLineList         = new List <ORD_PurchaseReturnLineResult>();
                            #endregion
                            List <ORD_PurchaseReturnLineResult> purReturnLineList = returnLineBLL.GetList(new ORD_PurchaseReturnLineParam()
                            {
                                PRGuid = returnResult.PRGuid
                            });

                            #region 预留库存
                            foreach (ORD_PurchaseReturnLineResult returnLineResult in purReturnLineList)
                            {
                                //创建预留明细
                                STK_StockReserveResult reserveResult = new STK_StockReserveResult();
                                reserveResult.SourceBillGuid     = returnResult.PRGuid;            //采购退货单guid
                                reserveResult.SourceBillNo       = returnResult.BillNo;            //退货单编号
                                reserveResult.SourceBillLineGuid = returnLineResult.PRLineGuid;    //退货明细guid
                                reserveResult.SourceBillType     = "采购退货出库";
                                reserveResult.ReserveType        = 4;                              //退货预留
                                reserveResult.OperType           = false;                          //系统预留
                                reserveResult.StkInLineGuid      = returnLineResult.StkInLineGuid; // 入库明细guid
                                reserveResult.ItemCode           = returnLineResult.ItemCode;
                                reserveResult.OperFlag           = true;                           //增加
                                reserveBLL.OperateReserve(reserveResult);
                            }
                            #endregion

                            #region 更新入库明细的退货数量
                            //获取退货明细关联的入库明细ID集合
                            StkInLineGuids = purReturnLineList.Select(a => a.StkInLineGuid).Distinct().ToArray();
                            if (StkInLineGuids != null && StkInLineGuids.Length > 0)
                            {
                                //退货明细关联的入库明细
                                linkInLineList = inLineBLL.GetList(new STK_InLineParam()
                                {
                                    StkInLineGuids = StkInLineGuids
                                });
                                //关联的入库明细所关联的退货明细
                                linkReturnLineList = returnLineBLL.GetList(new ORD_PurchaseReturnLineParam()
                                {
                                    StkInLineGuids = StkInLineGuids
                                });
                                PRGuids = linkReturnLineList.Select(a => a.PRGuid).Distinct().ToArray();
                                if (PRGuids != null && PRGuids.Length > 0)
                                {
                                    //关联的入库明细所关联的退货明细对应的退货主单
                                    linkReturnList = this.GetList(new ORD_PurchaseReturnParam()
                                    {
                                        PRGuids = PRGuids, StatusArr = new string[] { "Complete", "Approve" }
                                    });
                                    if (linkReturnList != null && linkReturnList.Count > 0)
                                    {
                                        effPRGuids        = linkReturnList.Select(a => (Guid?)a.PRGuid).Distinct().ToArray();
                                        effReturnLineList = linkReturnLineList.Where(a => effPRGuids.Contains(a.PRGuid)).ToList();
                                        foreach (STK_InLineResult inLineResult in linkInLineList)
                                        {
                                            int?qty = effReturnLineList.Where(a => a.StkInLineGuid == inLineResult.StkInLineGuid).Sum(a => a.Qty.ToInt32());
                                            inLineResult.ReturnOccQty = qty;
                                        }
                                    }
                                }
                                //更新退货明细关联的入库明细的退货占有数量
                                inLineBLL.UpdateOrInsertList(linkInLineList);
                            }
                            #endregion

                            #region 更新采购明细的采购占有数量和采购主单的退货占有状态
                            //获取关联采购明细ID集合
                            POLineGuids = purReturnLineList.Select(a => a.POLineGuid).Distinct().ToArray();
                            linkPurchaseOrderLineList = purOrderLineBLL.GetList(new ORD_PurchaseOrderLineParam()
                            {
                                POLineGuids = POLineGuids, IsCancel = false
                            });
                            //获取关联的采购明细所关联的退货明细
                            linkReturnLineList = returnLineBLL.GetList(new ORD_PurchaseReturnLineParam()
                            {
                                POLineGuids = POLineGuids
                            });
                            PRGuids = linkReturnLineList.Select(a => a.PRGuid).Distinct().ToArray();
                            if (PRGuids != null && PRGuids.Length > 0)
                            {
                                //采购明细所关联的退货明细对应的退货主单
                                linkReturnList = this.GetList(new ORD_PurchaseReturnParam()
                                {
                                    PRGuids = PRGuids, StatusArr = new string[] { "Complete", "Approve" }
                                });
                                if (linkReturnList != null && linkReturnList.Count > 0)
                                {
                                    effPRGuids        = linkReturnList.Select(a => (Guid?)a.PRGuid).Distinct().ToArray();
                                    effReturnLineList = linkReturnLineList.Where(a => effPRGuids.Contains(a.PRGuid)).ToList();
                                    foreach (ORD_PurchaseOrderLineResult purLineResult in linkPurchaseOrderLineList)
                                    {
                                        int?qty = effReturnLineList.Where(a => a.POLineGuid == purLineResult.POLineGuid).Sum(a => a.Qty.ToInt32());
                                        purLineResult.ReturnOccQty = qty;
                                    }
                                }
                            }
                            purOrderLineBLL.UpdateOrInsertList(linkPurchaseOrderLineList);
                            POGuids = linkPurchaseOrderLineList.Select(a => a.SOGuid).Distinct().ToArray();
                            foreach (Guid poguid in POGuids)
                            {
                                purOrderBLL.UpdateStatus(new ORD_PurchaseOrderParam()
                                {
                                    POGuid = poguid
                                });
                            }

                            #endregion
                        }
                    }


                    #endregion
                }
                else
                {
                    throw new WarnException("要提交的采购退货单在系统中不存在!");
                }
            }
            catch (WarnException exp)
            {
                throw exp;
            }
            catch (Exception exp)
            {
                LogInfoBLL.WriteLog(this.SessionInfo, exp);
                throw exp;
            }
            return(submitFlag);
        }
Example #4
0
        public bool AuditPurchaseReturnBill(ORD_PurchaseReturnParam param)
        {
            bool auditFlag = true;

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

                if (returnResult != null)
                {
                    bool isAllowAudit = true;

                    if (returnResult.ApproveStatus == "待提交")
                    {
                        isAllowAudit = false;
                        throw new WarnException("采购退货单当前状态为:【待提交】,请先提交!");
                    }
                    else if (returnResult.ApproveStatus == "审核完成")
                    {
                        isAllowAudit = false;
                        throw new WarnException("采购退货单当前状态为:【审核完成】,禁止重复审核!");
                    }
                    if (isAllowAudit)
                    {
                        returnResult.Status        = "Complete";
                        returnResult.ApproveStatus = "审核完成";
                        WCFAddUpdateResult ret = this.AddOrUpdate(returnResult);
                        if (ret.KeyGuid.ToGuid() == Guid.Empty)
                        {
                            auditFlag = false;
                        }
                        else
                        {
                            #region 定义相关变量
                            ORD_PurchaseOrderBLL purOrderBLL = new ORD_PurchaseOrderBLL();
                            purOrderBLL.SessionInfo = this.SessionInfo;
                            ORD_PurchaseOrderLineBLL purOrderLineBLL = new ORD_PurchaseOrderLineBLL();
                            purOrderLineBLL.SessionInfo = this.SessionInfo;
                            STK_InBLL inBLL = new STK_InBLL();
                            inBLL.SessionInfo = this.SessionInfo;
                            STK_InLineBLL inLineBLL = new STK_InLineBLL();
                            inLineBLL.SessionInfo = this.SessionInfo;
                            ORD_PurchaseReturnLineBLL returnLineBLL = new ORD_PurchaseReturnLineBLL();
                            returnLineBLL.SessionInfo = this.SessionInfo;
                            Guid?[] POLineGuids    = null;
                            Guid?[] StkInLineGuids = null;
                            Guid?[] PRGuids        = null;
                            Guid?[] effPRGuids     = null;
                            Guid?[] POGuids        = null;
                            List <STK_InLineResult>             linkInLineList            = new List <STK_InLineResult>();
                            List <ORD_PurchaseOrderLineResult>  linkPurchaseOrderLineList = new List <ORD_PurchaseOrderLineResult>();
                            List <ORD_PurchaseReturnResult>     linkReturnList            = new List <ORD_PurchaseReturnResult>();
                            List <ORD_PurchaseReturnLineResult> linkReturnLineList        = new List <ORD_PurchaseReturnLineResult>();
                            List <ORD_PurchaseReturnLineResult> effReturnLineList         = new List <ORD_PurchaseReturnLineResult>();
                            #endregion
                            List <ORD_PurchaseReturnLineResult> purReturnLineList = returnLineBLL.GetList(new ORD_PurchaseReturnLineParam()
                            {
                                PRGuid = returnResult.PRGuid
                            });



                            #region 更新采购明细的退货数量和采购主单的退货状态
                            //获取关联的采购明细ID集合
                            POLineGuids = purReturnLineList.Select(a => a.POLineGuid).Distinct().ToArray();
                            linkPurchaseOrderLineList = purOrderLineBLL.GetList(new ORD_PurchaseOrderLineParam()
                            {
                                POLineGuids = POLineGuids
                            });
                            //获取关联的采购明细所关联的退货明细
                            linkReturnLineList = returnLineBLL.GetList(new ORD_PurchaseReturnLineParam()
                            {
                                POLineGuids = POLineGuids
                            });
                            PRGuids = linkReturnLineList.Select(a => a.PRGuid).Distinct().ToArray();
                            if (PRGuids != null && PRGuids.Length > 0)
                            {
                                //采购明细所关联的退货明细对应的退货主单
                                linkReturnList = this.GetList(new ORD_PurchaseReturnParam()
                                {
                                    PRGuids = PRGuids, Status = "Complete"
                                });
                                if (linkReturnList != null && linkReturnList.Count > 0)
                                {
                                    effPRGuids        = linkReturnList.Select(a => (Guid?)a.PRGuid).Distinct().ToArray();
                                    effReturnLineList = linkReturnLineList.Where(a => effPRGuids.Contains(a.PRGuid)).ToList();
                                    foreach (ORD_PurchaseOrderLineResult purLineResult in linkPurchaseOrderLineList)
                                    {
                                        int?qty = effReturnLineList.Where(a => a.POLineGuid == purLineResult.SOLineGuid).Sum(a => a.Qty.ToInt32());
                                        purLineResult.ReturnQty = qty;
                                    }
                                }
                            }
                            purOrderLineBLL.UpdateOrInsertList(linkPurchaseOrderLineList);
                            POGuids = linkPurchaseOrderLineList.Select(a => a.SOGuid).Distinct().ToArray();
                            foreach (Guid poguid in POGuids)
                            {
                                purOrderBLL.UpdateStatus(new ORD_PurchaseOrderParam()
                                {
                                    POGuid = poguid
                                });
                            }

                            #endregion
                        }
                    }
                }
                else
                {
                    throw new WarnException("要审核的采购退货单在系统中不存在!");
                }
            }
            catch (WarnException exp)
            {
                throw exp;
            }
            catch (Exception exp)
            {
                LogInfoBLL.WriteLog(this.SessionInfo, exp);
                throw exp;
            }
            return(auditFlag);
        }