Esempio n. 1
0
        public bool AuditStkOutBill(STK_OutParam param)
        {
            bool auditFlag = true;

            try
            {
                STK_OutResult outResult = this.GetInfo(param);
                if (outResult != null)
                {
                    bool isAllowAudit = true;
                    if (outResult.ApproveStatus == "待提交")
                    {
                        isAllowAudit = false;
                        throw new WarnException("出库单当前状态为:【待提交】,请先提交!");
                    }
                    else if (outResult.ApproveStatus == "审核完成")
                    {
                        isAllowAudit = false;
                        throw new WarnException("出库单当前状态为:【审核完成】,禁止重复审核!");
                    }
                    if (isAllowAudit)
                    {
                        outResult.Status        = "Complete";
                        outResult.ApproveStatus = "审核完成";
                        WCFAddUpdateResult ret = this.AddOrUpdate(outResult);

                        if (ret.KeyGuid.ToGuid() == Guid.Empty)
                        {
                            auditFlag = false;
                        }
                        else
                        {
                            #region 定义相关变量(可重复使用)
                            STK_OutLineBLL outLineBLL = new STK_OutLineBLL();
                            outLineBLL.SessionInfo = this.SessionInfo;
                            STK_InBLL inBLL = new STK_InBLL();
                            inBLL.SessionInfo = this.SessionInfo;
                            STK_InLineBLL inLineBLL = new STK_InLineBLL();
                            inLineBLL.SessionInfo = this.SessionInfo;

                            ORD_PurchaseOrderLineBLL purOrderLineBLL = new ORD_PurchaseOrderLineBLL();
                            purOrderLineBLL.SessionInfo = this.SessionInfo;
                            ORD_PurchaseOrderBLL purOrderBLL = new ORD_PurchaseOrderBLL();
                            purOrderBLL.SessionInfo = this.SessionInfo;
                            ORD_SalesOrderBLL saleOrderBLL = new ORD_SalesOrderBLL();
                            saleOrderBLL.SessionInfo = this.SessionInfo;
                            ORD_SalesOrderLineBLL saleOrderLineBLL = new ORD_SalesOrderLineBLL();
                            saleOrderLineBLL.SessionInfo = this.SessionInfo;
                            ORD_PurchaseReturnBLL purReturnBLL = new ORD_PurchaseReturnBLL();
                            purReturnBLL.SessionInfo = this.SessionInfo;
                            ORD_PurchaseReturnLineBLL purReturnLineBLL = new ORD_PurchaseReturnLineBLL();
                            purReturnLineBLL.SessionInfo = this.SessionInfo;
                            STK_StockSheetBLL stockSheetBLL = new STK_StockSheetBLL();
                            stockSheetBLL.SessionInfo = this.SessionInfo;
                            STK_StockBLL stockBLL = new STK_StockBLL();
                            stockBLL.SessionInfo = this.SessionInfo;
                            STK_InOutLinkBLL inOutLinkBLL = new STK_InOutLinkBLL();
                            inOutLinkBLL.SessionInfo = this.SessionInfo;
                            List <ORD_SalesOrderResult>         saleList          = null;
                            List <ORD_SalesOrderLineResult>     saleLineList      = null;
                            List <ORD_PurchaseOrderLineResult>  purLineList       = null;
                            List <ORD_PurchaseReturnResult>     purReturnList     = null;
                            List <ORD_PurchaseReturnLineResult> purReturnLineList = null;
                            List <STK_InResult>         stkInList         = null;
                            List <STK_InLineResult>     stkInLineList     = null;
                            List <STK_InLineResult>     effStkInLineList  = null;
                            List <STK_OutResult>        stkOutList        = null;
                            List <STK_OutLineResult>    stkOutLineList    = null;
                            List <STK_OutLineResult>    effStkOutLineList = null;
                            List <STK_StockResult>      stockList         = null;
                            List <STK_StockSheetResult> stkStockSheetList = null;

                            Guid?[] ItemCodes        = null;
                            Guid?[] StkInGuids       = null;
                            Guid?[] StkInLineGuids   = null;
                            Guid?[] EffStkInGuids    = null;
                            Guid?[] StkOutGuids      = null;
                            Guid?[] _stkOutLineGuids = null;
                            Guid?[] EffStkOutGuids   = null;
                            Guid?[] POGuids          = null;
                            Guid?[] POLineGuids      = null;
                            Guid?[] SOGuids          = null;
                            Guid?[] SOLineGuids      = null;
                            Guid?[] PRGuids          = null;
                            Guid?[] PRLineGuids      = null;
                            #endregion
                            //获取出库单下的出库明细集合
                            List <STK_OutLineResult> outLineList = outLineBLL.GetList(new STK_OutLineParam()
                            {
                                StkOutGuid = ret.KeyGuid
                            });
                            //获取出库单下的关联明细集合
                            List <STK_InOutLinkResult> inOutLinkList = inOutLinkBLL.GetList(new STK_InOutLinkParam()
                            {
                                StkOutGuid = ret.KeyGuid
                            });
                            if (outLineList != null && outLineList.Count > 0)
                            {
                                #region 减少库存,形成出库流水
                                ItemCodes = outLineList.Select(a => a.ItemCode).Distinct().ToArray();
                                stockList = stockBLL.GetList(new STK_StockParam()
                                {
                                    ItemCodes = ItemCodes
                                });

                                stkStockSheetList = new List <STK_StockSheetResult>();
                                STK_StockSheetResult stkStockSheetResult = null;
                                foreach (STK_OutLineResult outLineResult in outLineList)
                                {
                                    STK_StockResult stockResult = stockList.FirstOrDefault(a => a.ItemCode == outLineResult.ItemCode.ToGuid());
                                    if (stockResult != null)
                                    {
                                        stockResult.InvQty                    -= outLineResult.Qty;
                                        stockResult.BookedQty                 -= outLineResult.Qty;
                                        stkStockSheetResult                    = new STK_StockSheetResult();
                                        stkStockSheetResult.SSType             = 2;
                                        stkStockSheetResult.SourceBillGuid     = outResult.StkOutGuid;
                                        stkStockSheetResult.SourceBillNo       = outResult.BillNo;
                                        stkStockSheetResult.SourceBillLineGuid = outLineResult.StkOutLineGuid;
                                        stkStockSheetResult.ItemCode           = outLineResult.ItemCode;
                                        stkStockSheetResult.Model              = outLineResult.Model;
                                        stkStockSheetResult.Brand              = outLineResult.Brand;
                                        stkStockSheetResult.Batch              = outLineResult.Batch;
                                        stkStockSheetResult.Package            = outLineResult.Package;
                                        stkStockSheetResult.Quality            = outLineResult.Quality;
                                        stkStockSheetResult.MPQ                = outLineResult.MPQ;
                                        stkStockSheetResult.MarkCode           = outLineResult.MarkCode;
                                        stkStockSheetResult.Currency           = outLineResult.Currency;
                                        stkStockSheetResult.FlowQty            = outLineResult.Qty;
                                        stkStockSheetResult.FlowPrice          = outLineResult.UnitPrice;
                                        stkStockSheetResult.FlowAmount         = outLineResult.Amount;
                                        stkStockSheetList.Add(stkStockSheetResult);
                                    }
                                }
                                stockBLL.UpdateOrInsertList(stockList);
                                stockSheetBLL.UpdateOrInsertList(stkStockSheetList);


                                #endregion

                                #region 回写关联的入库单的出库数量和出库状态,入库单关联单据的出库数量和出库状态,出库单关联单据的出库数量和出库状态

                                #region 回写关联入库单的出库数量出库状态

                                //获取出库明细的guid
                                StkInLineGuids = inOutLinkList.Select(a => a.StkInLineGuid).Distinct().ToArray();

                                if (StkInLineGuids != null && StkInLineGuids.Length > 0)
                                {
                                    //获取出库明细所关联的入库明细
                                    stkInLineList = inLineBLL.GetList(new STK_InLineParam()
                                    {
                                        StkInLineGuids = StkInLineGuids
                                    });
                                    if (stkInLineList != null && stkInLineList.Count > 0)
                                    {
                                        //获取出库明细所关联的入库明细对应的出库明细
                                        List <STK_InOutLinkResult> linkList = inOutLinkBLL.GetList(new STK_InOutLinkParam()
                                        {
                                            StkInLineGuids = StkInLineGuids
                                        });
                                        if (linkList != null && linkList.Count > 0)
                                        {
                                            _stkOutLineGuids = linkList.Select(a => a.StkOutLineGuid).Distinct().ToArray();
                                            stkOutLineList   = outLineBLL.GetList(new STK_OutLineParam()
                                            {
                                                StkOutLineGuids = _stkOutLineGuids
                                            });
                                            if (stkOutLineList != null && stkOutLineList.Count > 0)
                                            {
                                                //获取出库明细对应的出库主单guid
                                                StkOutGuids = stkOutLineList.Select(a => a.StkOutGuid).Distinct().ToArray();
                                                if (StkOutGuids != null && StkOutGuids.Length > 0)
                                                {
                                                    //获取出库明细对应的出库主单
                                                    stkOutList = this.GetList(new STK_OutParam()
                                                    {
                                                        StkOutGuids = StkOutGuids, Status = "Complete"
                                                    });
                                                    if (stkOutList != null && stkOutList.Count > 0)
                                                    {
                                                        //获取有效的出库主单guid
                                                        EffStkOutGuids = stkOutList.Select(a => a.StkOutGuid).Distinct().ToArray();
                                                        //获取有效的出库明细集合
                                                        effStkOutLineList = stkOutLineList.Where(a => EffStkOutGuids.Contains(a.StkOutGuid)).ToList();
                                                        foreach (STK_InLineResult stkInLineResult in stkInLineList)
                                                        {
                                                            //汇总出库明细的出库数量
                                                            int?qty = effStkOutLineList.Where(a => a.StkInLineGuid == stkInLineResult.StkInLineGuid).Sum(a => a.Qty.ToInt32());
                                                            //回写入库明细的出库数量
                                                            stkInLineResult.StkOutQty = qty;
                                                        }
                                                    }
                                                }
                                                //更新入库明细的集合
                                                inLineBLL.UpdateOrInsertList(stkInLineList);
                                                //获取入库主单guid
                                                StkInGuids = stkInLineList.Select(a => a.StkInGuid).Distinct().ToArray();
                                                foreach (Guid stkinguid in StkInGuids)
                                                {
                                                    //更新入库单的状态
                                                    inBLL.UpdateStatus(new STK_InParam()
                                                    {
                                                        StkInGuid = stkinguid
                                                    });
                                                    //获取入库单
                                                    STK_InResult stkInResult = inBLL.GetInfo(new STK_InParam()
                                                    {
                                                        StkInGuid = stkinguid
                                                    });
                                                    if (stkInResult.BillType == "PO_IN")
                                                    {
                                                        #region 回写采购单的出库的数量出库状态
                                                        //找到入库明细所关联的采购明细guid和采购明细集合
                                                        POLineGuids = stkInLineList.Where(a => a.StkInGuid == stkinguid).Select(a => a.SourceBillLineGuid).Distinct().ToArray();
                                                        if (POLineGuids != null && POLineGuids.Length > 0)
                                                        {
                                                            purLineList = purOrderLineBLL.GetList(new ORD_PurchaseOrderLineParam()
                                                            {
                                                                POLineGuids = POLineGuids
                                                            });
                                                            if (purLineList != null && purLineList.Count > 0)
                                                            {
                                                                //找到采购单明细关联的入库明细
                                                                List <STK_InLineResult> linkInLineList = inLineBLL.GetList(new STK_InLineParam()
                                                                {
                                                                    SourceBillLineGuids = POLineGuids
                                                                });
                                                                if (linkInLineList != null && linkInLineList.Count > 0)
                                                                {
                                                                    //找到采购明细关联的入库明细的入库主单guid
                                                                    Guid?[] LinkInGuids = linkInLineList.Select(a => a.StkInGuid).Distinct().ToArray();
                                                                    if (LinkInGuids != null && LinkInGuids.Length > 0)
                                                                    {
                                                                        //找到采购单明细关联的入库明细所在的入库主单
                                                                        stkInList = inBLL.GetList(new STK_InParam()
                                                                        {
                                                                            StkInGuids = LinkInGuids, Status = "Complete"
                                                                        });
                                                                        if (stkInList != null && stkInList.Count > 0)
                                                                        {
                                                                            //有效的入库主单guid
                                                                            EffStkInGuids = stkInList.Select(a => a.StkInGuid).Distinct().ToArray();
                                                                            //有效的入库明细集合
                                                                            effStkInLineList = linkInLineList.Where(a => EffStkInGuids.Contains(a.StkInGuid)).ToList();
                                                                            foreach (ORD_PurchaseOrderLineResult purLineResult in purLineList)
                                                                            {
                                                                                //汇总有效的入库明细的出库数量
                                                                                int?qty = effStkInLineList.Where(a => a.SourceBillLineGuid == purLineResult.POLineGuid).Sum(a => a.StkOutQty).ToInt32();
                                                                                //更新采购明细的出库数量
                                                                                purLineResult.StkOutQty = qty;
                                                                            }
                                                                        }
                                                                    }
                                                                }
                                                                //更新采购明细集合
                                                                purOrderLineBLL.UpdateOrInsertList(purLineList);
                                                                POGuids = purLineList.Select(a => a.POGuid).Distinct().ToArray();
                                                                foreach (Guid poguid in POGuids)
                                                                {
                                                                    purOrderBLL.UpdateStatus(new ORD_PurchaseOrderParam()
                                                                    {
                                                                        POGuid = poguid
                                                                    });
                                                                }
                                                            }
                                                        }

                                                        #endregion
                                                    }
                                                    else if (stkInResult.BillType == "SOR_IN")
                                                    {
                                                    }
                                                    else if (stkInResult.BillType == "ZX_IN")
                                                    {
                                                    }
                                                }
                                            }
                                        }
                                    }
                                }
                                #endregion


                                #region 回写出库单关联的业务单据的出库数量和出库状态
                                if (outResult.BillType == "SO_OUT")
                                {
                                    #region 回写销售单的出库数量和出库状态
                                    //获取出库明细对应的销售明细guid
                                    SOLineGuids = outLineList.Select(a => a.SourceBillLineGuid).Distinct().ToArray();
                                    if (SOLineGuids != null && SOLineGuids.Length > 0)
                                    {
                                        //获取出库明细对应的销售明细
                                        saleLineList = saleOrderLineBLL.GetList(new ORD_SalesOrderLineParam()
                                        {
                                            SOLineGuids = SOLineGuids
                                        });
                                        if (saleLineList != null && saleLineList.Count > 0)
                                        {
                                            //获取出库明细对应的销售明细关联关联的出库明细
                                            stkOutLineList = outLineBLL.GetList(new STK_OutLineParam()
                                            {
                                                SourceBillLineGuids = SOLineGuids
                                            });
                                            if (stkOutLineList != null && stkOutLineList.Count > 0)
                                            {
                                                //获取出库明细对应的出库主单guid
                                                StkOutGuids = stkOutLineList.Select(a => a.StkOutGuid).Distinct().ToArray();
                                                if (StkOutGuids != null && StkOutGuids.Length > 0)
                                                {
                                                    //获取出库明细对应的出库主单
                                                    stkOutList = this.GetList(new STK_OutParam()
                                                    {
                                                        StkOutGuids = StkOutGuids, Status = "Complete"
                                                    });
                                                    if (stkOutList != null && stkOutList.Count > 0)
                                                    {
                                                        //获取有效的出库主单guid
                                                        EffStkOutGuids = stkOutList.Select(a => a.StkOutGuid).Distinct().ToArray();
                                                        //获取有效的出库明细集合
                                                        effStkOutLineList = stkOutLineList.Where(a => EffStkOutGuids.Contains(a.StkOutGuid)).ToList();
                                                        foreach (ORD_SalesOrderLineResult orderLineResult in saleLineList)
                                                        {
                                                            //汇总有效的出库明细的出库数量
                                                            int?qty = effStkOutLineList.Where(a => a.SourceBillLineGuid == orderLineResult.SOLineGuid).Sum(a => a.Qty).ToInt32();
                                                            orderLineResult.StkOutQty = qty;
                                                        }
                                                    }
                                                }
                                            }
                                            saleOrderLineBLL.UpdateOrInsertList(saleLineList);
                                            SOGuids = saleLineList.Select(a => a.SOGuid).Distinct().ToArray();
                                            foreach (Guid soguid in SOGuids)
                                            {
                                                saleOrderBLL.UpdateStatus(new ORD_SalesOrderParam()
                                                {
                                                    SOGuid = soguid
                                                });
                                            }
                                        }
                                    }
                                    #endregion
                                }
                                else if (outResult.BillType == "POR_OUT")
                                {
                                    #region 回写采购退货单的出库数量和出库状态
                                    //获取出库明细对应的退货明细guid
                                    PRLineGuids = outLineList.Select(a => a.SourceBillLineGuid).Distinct().ToArray();
                                    if (PRLineGuids != null && PRLineGuids.Length > 0)
                                    {
                                        //获取出库明细对应的退货明细
                                        purReturnLineList = purReturnLineBLL.GetList(new ORD_PurchaseReturnLineParam()
                                        {
                                            PRLineGuids = PRLineGuids
                                        });
                                        if (purReturnLineList != null && purReturnLineList.Count > 0)
                                        {
                                            //获取出库明细对应的退货明细关联关联的出库明细
                                            stkOutLineList = outLineBLL.GetList(new STK_OutLineParam()
                                            {
                                                SourceBillLineGuids = PRLineGuids
                                            });
                                            if (stkOutLineList != null && stkOutLineList.Count > 0)
                                            {
                                                //获取出库明细对应的出库主单guid
                                                StkOutGuids = stkOutLineList.Select(a => a.StkOutGuid).Distinct().ToArray();
                                                if (StkOutGuids != null && StkOutGuids.Length > 0)
                                                {
                                                    //获取出库明细对应的出库主单
                                                    stkOutList = this.GetList(new STK_OutParam()
                                                    {
                                                        StkOutGuids = StkOutGuids, Status = "Complete"
                                                    });
                                                    if (stkOutList != null && stkOutList.Count > 0)
                                                    {
                                                        //获取有效的出库主单guid
                                                        EffStkOutGuids = stkOutList.Select(a => a.StkOutGuid).Distinct().ToArray();
                                                        //获取有效的出库明细集合
                                                        effStkOutLineList = stkOutLineList.Where(a => EffStkOutGuids.Contains(a.StkOutGuid)).ToList();
                                                        foreach (ORD_PurchaseReturnLineResult purReturnLineResult in purReturnLineList)
                                                        {
                                                            //汇总有效的出库明细的出库数量
                                                            int?qty = effStkOutLineList.Where(a => a.SourceBillLineGuid == purReturnLineResult.PRLineGuid).Sum(a => a.Qty).ToInt32();
                                                            purReturnLineResult.StkOutQty = qty;
                                                        }
                                                    }
                                                }
                                            }
                                            purReturnLineBLL.UpdateOrInsertList(purReturnLineList);
                                            PRGuids = purReturnLineList.Select(a => a.PRGuid).Distinct().ToArray();
                                            foreach (Guid prguid in PRGuids)
                                            {
                                                purReturnBLL.UpdateStatus(new ORD_PurchaseReturnParam()
                                                {
                                                    PRGuid = prguid
                                                });
                                            }
                                        }
                                    }
                                    #endregion
                                }
                                else if (outResult.BillType == "ZX_OUT")
                                {
                                }
                                #endregion
                                #endregion
                            }
                        }
                    }
                }
                else
                {
                    throw new WarnException("要审核的出库单在系统中不存在!");
                }
            }
            catch (WarnException exp)
            {
                throw exp;
            }
            catch (Exception exp)
            {
                LogInfoBLL.WriteLog(this.SessionInfo, exp);
                throw exp;
            }
            return(auditFlag);
        }
Esempio n. 2
0
        public bool AuditStkInBill(STK_InParam param)
        {
            bool auditFlag = true;

            try
            {
                STK_InResult inResult = this.GetInfo(param);;

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

                    if (inResult.ApproveStatus == "待提交")
                    {
                        isAllowAudit = false;
                        throw new WarnException("入库单当前状态为:【待提交】,请先提交!");
                    }
                    else if (inResult.ApproveStatus == "审核完成")
                    {
                        isAllowAudit = false;
                        throw new WarnException("入库单当前状态为:【审核完成】,禁止重复审核!");
                    }
                    if (isAllowAudit)
                    {
                        inResult.Status        = "Complete";
                        inResult.ApproveStatus = "审核完成";
                        WCFAddUpdateResult ret = this.AddOrUpdate(inResult);
                        if (ret.KeyGuid.ToGuid() == Guid.Empty)
                        {
                            auditFlag = false;
                        }
                        else
                        {
                            #region 定义相关变量(可重复使用)
                            STK_InLineBLL stkInLineBLL = new STK_InLineBLL();
                            stkInLineBLL.SessionInfo = this.SessionInfo;
                            STK_StockBLL stkStockBLL = new STK_StockBLL();
                            stkStockBLL.SessionInfo = this.SessionInfo;
                            STK_StockSheetBLL stkStockSheetBLL = new STK_StockSheetBLL();
                            stkStockSheetBLL.SessionInfo = this.SessionInfo;
                            STK_StockReserveBLL reserveBLL = new STK_StockReserveBLL();
                            reserveBLL.SessionInfo = this.SessionInfo;

                            ORD_SalesOrderBLL saleOrderBLL = new ORD_SalesOrderBLL();
                            saleOrderBLL.SessionInfo = this.SessionInfo;
                            ORD_SalesOrderLineBLL saleOrderLineBLL = new ORD_SalesOrderLineBLL();
                            saleOrderLineBLL.SessionInfo = this.SessionInfo;

                            ORD_PurchaseOrderBLL purOrderBLL = new ORD_PurchaseOrderBLL();
                            purOrderBLL.SessionInfo = this.SessionInfo;
                            ORD_PurchaseOrderLineBLL purOrderLineBLL = new ORD_PurchaseOrderLineBLL();
                            purOrderLineBLL.SessionInfo = this.SessionInfo;

                            ORD_SalesReturnBLL returnBLL = new ORD_SalesReturnBLL();
                            returnBLL.SessionInfo = this.SessionInfo;
                            ORD_SalesReturnLineBLL returnLineBLL = new ORD_SalesReturnLineBLL();
                            returnLineBLL.SessionInfo = this.SessionInfo;

                            Guid?[] _ItemCodes = null;
                            List <STK_InLineResult> stkInLineList = stkInLineBLL.GetList(new STK_InLineParam()
                            {
                                StkInGuid = inResult.StkInGuid
                            });
                            #endregion
                            #region 形成库存,回写库存ID到入库明细,形成库存流水,预留库存 ,回写采购单,销售单的入库数量和入库状态
                            List <STK_StockResult>      stkStockList      = new List <STK_StockResult>();
                            List <STK_StockSheetResult> stkStockSheetList = new List <STK_StockSheetResult>();
                            if (stkInLineList != null && stkInLineList.Count > 0)
                            {
                                if (inResult.BillType == "SOR_IN")
                                {
                                    _ItemCodes   = stkInLineList.Where(a => a.ItemCode != null).Select(a => a.ItemCode).Distinct().ToArray();
                                    stkStockList = stkStockBLL.GetList(new STK_StockParam()
                                    {
                                        ItemCodes = _ItemCodes
                                    });
                                }
                                #region 形成库存,回写库存ID,形成流水
                                STK_StockResult      stkStockResult      = null;
                                STK_StockSheetResult stkStockSheetResult = null;
                                foreach (STK_InLineResult stkInLineResult in stkInLineList)
                                {
                                    //形成ItemCode,如果是采购入库则new一个实体,如果是销售退货入库则使用传递过来的退货明细的itemCode
                                    Guid?itemCode = null;

                                    #region 形成库存

                                    if (inResult.BillType == "PO_IN")//采购入库
                                    {
                                        itemCode                     = Guid.NewGuid();
                                        stkStockResult               = new STK_StockResult();
                                        stkStockResult.BuyerID       = stkInLineResult.BuyerID;
                                        stkStockResult.BuyerName     = stkInLineResult.BuyerName;
                                        stkStockResult.POGuid        = stkInLineResult.SourceBillGuid;
                                        stkStockResult.POBillNo      = stkInLineResult.SourceBillNo;
                                        stkStockResult.POLineGuid    = stkInLineResult.SourceBillLineGuid;
                                        stkStockResult.StkInGuid     = inResult.StkInGuid;
                                        stkStockResult.StkInBillNo   = inResult.BillNo;
                                        stkStockResult.StkInLineGuid = stkInLineResult.StkInLineGuid;
                                        stkStockResult.ItemCode      = itemCode;
                                        stkStockResult.Model         = stkInLineResult.Model;
                                        stkStockResult.Brand         = stkInLineResult.Brand;
                                        stkStockResult.Batch         = stkInLineResult.Batch;
                                        stkStockResult.Package       = stkInLineResult.Package;
                                        stkStockResult.Quality       = stkInLineResult.Quality;
                                        stkStockResult.MPQ           = stkInLineResult.MPQ;
                                        stkStockResult.MarkCode      = stkInLineResult.MarkCode;
                                        stkStockResult.Remark        = stkInLineResult.Remark;
                                        stkStockResult.Warehouse     = stkInLineResult.Warehouse;
                                        stkStockResult.Location      = stkInLineResult.Location;
                                        stkStockResult.InvType       = stkInLineResult.InvType;
                                        stkStockResult.InvQty        = stkInLineResult.Qty;
                                        stkStockResult.BookedQty     = 0;
                                        stkStockResult.UsableQty     = stkInLineResult.Qty;
                                        stkStockResult.Unit          = stkInLineResult.Unit;
                                        stkStockResult.Currency      = stkInLineResult.Currency;
                                        stkStockResult.BuyPrice      = stkInLineResult.CostPrice;
                                        stkStockResult.BuyPriceRMB   = stkInLineResult.CostPrice * stkInLineResult.ExchangeRate;
                                        stkStockList.Add(stkStockResult);

                                        stkInLineResult.ItemCode = itemCode; //回写入库明细的库存ID
                                    }
                                    else if (inResult.BillType == "SOR_IN")  //销售退货入库
                                    {
                                        itemCode                  = stkInLineResult.ItemCode;
                                        stkStockResult            = stkStockList.FirstOrDefault(a => a.ItemCode == stkInLineResult.ItemCode);
                                        stkStockResult.InvQty    += stkInLineResult.Qty;
                                        stkStockResult.UsableQty += stkInLineResult.Qty;
                                    }
                                    else if (inResult.BillType == "ZX_IN")
                                    {
                                    }
                                    #endregion

                                    #region 形成流水
                                    stkStockSheetResult                    = new STK_StockSheetResult();
                                    stkStockSheetResult.OperEmpID          = stkInLineResult.BuyerID;
                                    stkStockSheetResult.OperEmpName        = stkInLineResult.BuyerName;
                                    stkStockSheetResult.SSType             = 1;
                                    stkStockSheetResult.SourceBillGuid     = inResult.StkInGuid;
                                    stkStockSheetResult.SourceBillNo       = inResult.BillNo;
                                    stkStockSheetResult.SourceBillLineGuid = stkInLineResult.StkInLineGuid;
                                    stkStockSheetResult.ItemCode           = itemCode;
                                    stkStockSheetResult.Model              = stkInLineResult.Model;
                                    stkStockSheetResult.Brand              = stkInLineResult.Brand;
                                    stkStockSheetResult.Batch              = stkInLineResult.Batch;
                                    stkStockSheetResult.Package            = stkInLineResult.Package;
                                    stkStockSheetResult.Quality            = stkInLineResult.Quality;
                                    stkStockSheetResult.MPQ                = stkInLineResult.MPQ;
                                    stkStockSheetResult.MarkCode           = stkInLineResult.MarkCode;
                                    stkStockSheetResult.Currency           = stkInLineResult.Currency;
                                    stkStockSheetResult.FlowQty            = stkInLineResult.Qty;
                                    stkStockSheetResult.FlowPrice          = stkInLineResult.CostPrice;
                                    stkStockSheetResult.FlowAmount         = stkInLineResult.Amount;
                                    stkStockSheetList.Add(stkStockSheetResult);
                                    #endregion
                                }
                                stkStockBLL.UpdateOrInsertList(stkStockList);
                                stkStockSheetBLL.UpdateOrInsertList(stkStockSheetList);
                                stkInLineBLL.UpdateOrInsertList(stkInLineList);
                                #endregion
                                #region 预留库存
                                if (inResult.BillType == "PO_IN")//采购入库
                                {
                                    //有关联销售的采购入库会有销售明细Guid
                                    List <STK_InLineResult> tempInLineList = stkInLineList.Where(a => a.SOLineGuid != null).ToList();
                                    if (tempInLineList != null && tempInLineList.Count > 0)
                                    {
                                        Guid?[] POLineGuids = tempInLineList.Select(a => a.SourceBillLineGuid).Distinct().ToArray();
                                        List <ORD_PurchaseOrderLineResult> purOrderLineList = purOrderLineBLL.GetList(new ORD_PurchaseOrderLineParam()
                                        {
                                            POLineGuids = POLineGuids
                                        });
                                        foreach (STK_InLineResult stkInLineResult in   tempInLineList)
                                        {
                                            //入库明细所对应的采购明细
                                            ORD_PurchaseOrderLineResult purOrderLineResult = purOrderLineList.FirstOrDefault(a => a.POLineGuid == stkInLineResult.SourceBillLineGuid);
                                            if (purOrderLineResult != null)
                                            {
                                                //创建预留明细
                                                STK_StockReserveResult reserveResult = new STK_StockReserveResult();
                                                reserveResult.SourceBillGuid     = purOrderLineResult.SOGuid;     //销售单guid
                                                reserveResult.SourceBillNo       = purOrderLineResult.SOBillNo;   //销售单编号
                                                reserveResult.SourceBillLineGuid = purOrderLineResult.SOLineGuid; //销售明细guid
                                                reserveResult.SourceBillType     = "销售出库";
                                                reserveResult.ReserveType        = 1;                             //采购预留
                                                reserveResult.OperType           = false;                         //系统预留
                                                reserveResult.StkInLineGuid      = stkInLineResult.StkInLineGuid; // 入库明细guid
                                                reserveResult.ItemCode           = stkInLineResult.ItemCode;
                                                reserveResult.OperFlag           = true;                          //增加
                                                reserveBLL.OperateReserve(reserveResult);
                                            }
                                        }
                                    }
                                }
                                #endregion
                                #region 回写关联单据的入库数量和入库状态
                                //入库单关联的入库明细
                                if (stkInLineList != null && stkInLineList.Count > 0)
                                {
                                    #region 定义相关变量(可重复使用)
                                    Guid?[] SOGuids     = null;
                                    Guid?[] SOLineGuids = null;

                                    Guid?   POGuid      = null;
                                    Guid?[] POLineGuids = null;

                                    Guid?   SRGuid      = null;
                                    Guid?[] SRLineGuids = null;

                                    Guid?[] StkInGuids = null;
                                    Guid?[] effInGuids = null;

                                    List <ORD_SalesReturnLineResult>   returnLineList = null;
                                    List <ORD_PurchaseOrderLineResult> purLineList    = null;

                                    List <STK_InResult>     inList         = null;
                                    List <STK_InLineResult> linkInLineList = null;
                                    List <STK_InLineResult> effInLineList  = null;
                                    #endregion
                                    if (inResult.BillType == "PO_IN")
                                    {
                                        #region 更新采购明细的入库数量和采购主单的入库状态
                                        //关联的采购主单
                                        POGuid = inResult.SourceBillGuid;
                                        //关联的采购明细ID集合
                                        POLineGuids = stkInLineList.Where(a => a.SourceBillLineGuid != null).Select(a => a.SourceBillLineGuid).Distinct().ToArray();
                                        if (POLineGuids != null && POLineGuids.Length > 0)
                                        {
                                            //采购明细
                                            purLineList = purOrderLineBLL.GetList(new ORD_PurchaseOrderLineParam()
                                            {
                                                POLineGuids = POLineGuids
                                            });

                                            //采购明细所关联的入库明细
                                            linkInLineList = stkInLineBLL.GetList(new STK_InLineParam()
                                            {
                                                SourceBillLineGuids = POLineGuids
                                            });
                                            StkInGuids = linkInLineList.Select(a => a.StkInGuid).Distinct().ToArray();
                                            if (StkInGuids != null && StkInGuids.Length > 0)
                                            {
                                                //采购明细所关联的入库明细对应的入库主单
                                                inList = this.GetList(new STK_InParam()
                                                {
                                                    StkInGuids = StkInGuids, Status = "Complete"
                                                });
                                                if (inList != null && inList.Count > 0)
                                                {
                                                    effInGuids    = inList.Select(a => a.StkInGuid).Distinct().ToArray();
                                                    effInLineList = linkInLineList.Where(a => effInGuids.Contains(a.StkInGuid)).ToList();
                                                    foreach (ORD_PurchaseOrderLineResult purLineResult in purLineList)
                                                    {
                                                        int?qty = effInLineList.Where(a => a.SourceBillLineGuid == purLineResult.POLineGuid).Sum(a => a.Qty.ToInt32());
                                                        purLineResult.StkInQty = qty;
                                                    }
                                                }
                                            }
                                            purOrderLineBLL.UpdateOrInsertList(purLineList);
                                            purOrderBLL.UpdateStatus(new ORD_PurchaseOrderParam()
                                            {
                                                POGuid = POGuid
                                            });
                                        }
                                        #endregion
                                        #region 更新销售明细的入库数量和销售主单的入库状态

                                        List <STK_InLineResult> tempInLineList = stkInLineList.Where(a => a.SOLineGuid != null).ToList();
                                        if (tempInLineList != null)
                                        {
                                            //获取关联的销售明细ID集合
                                            SOLineGuids = tempInLineList.Select(a => a.SOLineGuid).Distinct().ToArray();
                                            List <ORD_SalesOrderLineResult> saleOrderLineList = saleOrderLineBLL.GetList(new ORD_SalesOrderLineParam()
                                            {
                                                SOLineGuids = SOLineGuids
                                            });
                                            //获取关联的销售明细所关联的入库明细
                                            linkInLineList = stkInLineBLL.GetList(new STK_InLineParam()
                                            {
                                                SOLineGuids = SOLineGuids
                                            });
                                            StkInGuids = linkInLineList.Select(a => a.StkInGuid).Distinct().ToArray();
                                            if (StkInGuids != null && StkInGuids.Length > 0)
                                            {
                                                //销售明细所关联的入库明细对应的入库主单
                                                inList = this.GetList(new STK_InParam()
                                                {
                                                    StkInGuids = StkInGuids, Status = "Complete"
                                                });
                                                if (inList != null && inList.Count > 0)
                                                {
                                                    effInGuids    = inList.Select(a => a.StkInGuid).Distinct().ToArray();
                                                    effInLineList = linkInLineList.Where(a => effInGuids.Contains(a.StkInGuid)).ToList();
                                                    foreach (ORD_SalesOrderLineResult saleLineResult in saleOrderLineList)
                                                    {
                                                        int?qty = effInLineList.Where(a => a.SOLineGuid == saleLineResult.SOLineGuid).Sum(a => a.Qty.ToInt32());
                                                        saleLineResult.StkInQty = qty;
                                                    }
                                                }
                                            }
                                            saleOrderLineBLL.UpdateOrInsertList(saleOrderLineList);
                                            SOGuids = saleOrderLineList.Select(a => a.SOGuid).Distinct().ToArray();
                                            foreach (Guid soguid in SOGuids)
                                            {
                                                saleOrderBLL.UpdateStatus(new ORD_SalesOrderParam()
                                                {
                                                    SOGuid = soguid
                                                });
                                            }
                                        }
                                        #endregion
                                    }
                                    else if (inResult.BillType == "SOR_IN")
                                    {
                                        #region 更新销售退货明细的入库数量和退货主单的入库状态
                                        //关联的销售退货主单
                                        SRGuid = inResult.SourceBillGuid;
                                        //关联的销售退货明细ID集合
                                        SRLineGuids = stkInLineList.Where(a => a.SourceBillLineGuid != null).Select(a => a.SourceBillLineGuid).Distinct().ToArray();
                                        if (SRLineGuids != null && SRLineGuids.Length > 0)
                                        {
                                            //退货明细
                                            returnLineList = returnLineBLL.GetList(new ORD_SalesReturnLineParam()
                                            {
                                                SRLineGuids = SRLineGuids
                                            });

                                            //退货明细所关联的入库明细
                                            linkInLineList = stkInLineBLL.GetList(new STK_InLineParam()
                                            {
                                                SourceBillLineGuids = SRLineGuids
                                            });
                                            StkInGuids = linkInLineList.Select(a => a.StkInGuid).Distinct().ToArray();
                                            if (StkInGuids != null && StkInGuids.Length > 0)
                                            {
                                                //退货明细所关联的入库明细对应的入库主单
                                                inList = this.GetList(new STK_InParam()
                                                {
                                                    StkInGuids = StkInGuids, Status = "Complete"
                                                });
                                                if (inList != null && inList.Count > 0)
                                                {
                                                    effInGuids    = inList.Select(a => a.StkInGuid).Distinct().ToArray();
                                                    effInLineList = linkInLineList.Where(a => effInGuids.Contains(a.StkInGuid)).ToList();
                                                    foreach (ORD_SalesReturnLineResult returnLineResult in returnLineList)
                                                    {
                                                        int?qty = effInLineList.Where(a => a.SourceBillLineGuid == returnLineResult.SRLineGuid).Sum(a => a.Qty.ToInt32());
                                                        returnLineResult.StkInQty = qty;
                                                    }
                                                }
                                            }
                                            returnLineBLL.UpdateOrInsertList(returnLineList);
                                        }

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