Ejemplo n.º 1
0
        public List <ORD_PurchaseOrderLineResult> GetSimpleList(ORD_PurchaseOrderLineParam param, List <Field> fields)
        {
            List <ORD_PurchaseOrderLineResult> ret = new List <ORD_PurchaseOrderLineResult>();

            try
            {
                WhereClip whereClip = GetWhereClip(param);
                ret = this.SelectList <ORD_PurchaseOrderLineResult>(fields, whereClip, ORD_PurchaseOrderLine._.CreatedTime.Asc);
                if (ret != null && ret.Count > 0)
                {
                    Guid?[] POGuids = ret.Select(a => a.POGuid).Distinct().ToArray();
                    ORD_PurchaseOrderBLL orderBLL = new ORD_PurchaseOrderBLL();
                    orderBLL.SessionInfo = this.SessionInfo;
                    List <ORD_PurchaseOrderResult> orderResultList = orderBLL.GetList(new ORD_PurchaseOrderParam()
                    {
                        POGuids = POGuids
                    });
                    foreach (ORD_PurchaseOrderLineResult lineResult in ret)
                    {
                        ORD_PurchaseOrderResult orderResult = orderResultList.FirstOrDefault(a => a.POGuid == lineResult.POGuid);
                        if (orderResult != null)
                        {
                            lineResult.POBillNo = orderResult.BillNo;
                            lineResult.Currency = orderResult.Currency;
                            lineResult.TaxRate  = orderResult.TaxRate;
                        }
                    }
                }
            }
            catch (WarnException exp)
            {
                throw exp;
            }
            catch (System.Exception exp)
            {
                LogInfoBLL.WriteLog(this.SessionInfo, exp);
                throw exp;
            }
            return(ret);
        }
Ejemplo n.º 2
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);
        }
Ejemplo n.º 3
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);
        }