Exemple #1
0
        public bool SubmitStkOutBill(STK_OutParam param)
        {
            this.CheckSession();
            bool submitFlag = true;

            try
            {
                STK_OutResult outResult = this.GetInfo(param);

                if (outResult != null)
                {
                    #region 判断是否可以提交
                    bool isAllowSubmit = true;
                    if (outResult.ApproveStatus == "待审核")
                    {
                        isAllowSubmit = false;
                        throw new WarnException("入库单当前状态为:【已提交,待审核】,禁止重复提交!");
                    }
                    else if (outResult.ApproveStatus == "审核完成")
                    {
                        isAllowSubmit = false;
                        throw new WarnException("入库单当前状态为:【审核完成】,撤单后才可以再次提交!");
                    }

                    #region 提交时判断预留信息使用数量是否大于预留数量,如果大于预留数量是不允许提交的
                    List <STK_OutLineResult> outLineList = outResult.StkOutLineList;
                    Guid?[]             SRGuids          = outLineList.Select(a => a.SRGuid).Distinct().ToArray();
                    STK_StockReserveBLL reserveBLL       = new STK_StockReserveBLL();
                    reserveBLL.SessionInfo = this.SessionInfo;

                    List <STK_StockReserveResult> reserveList = reserveBLL.GetList(new STK_StockReserveParam()
                    {
                        SRGuids = SRGuids
                    });
                    foreach (STK_StockReserveResult reserveResult in reserveList)
                    {
                        reserveResult.UsedQty    = reserveResult.UsedQty.ToInt32();
                        reserveResult.ReserveQty = reserveResult.ReserveQty.ToInt32();
                        int?usedQty = 0;
                        STK_OutLineResult outLineResult = outLineList.FirstOrDefault(a => a.SRGuid == reserveResult.SRGuid);
                        if (outLineResult != null)
                        {
                            usedQty = outLineResult.Qty;
                        }
                        if ((reserveResult.UsedQty + usedQty) > reserveResult.ReserveQty)
                        {
                            isAllowSubmit = false;
                            break;
                        }
                        reserveResult.UsedQty += usedQty;
                    }

                    if (isAllowSubmit)
                    {
                        #region 回写库存预留的出库数量
                        WCFAddUpdateResult ret = reserveBLL.UpdateOrInsertList(reserveList);
                        if (ret.Key <= 0)
                        {
                            submitFlag = false;
                            throw new WarnException("回写出库单明细关联的库存预留明细的出库数量失败,禁止提交出库单!");
                        }
                        #endregion

                        #region 更新出库单的状态
                        outResult.Status        = "Approve";
                        outResult.ApproveStatus = "待审核";
                        this.AddOrUpdate(outResult);
                        #endregion
                    }
                    else
                    {
                        submitFlag = false;
                        throw new WarnException("出库单明细所关联库存预留明细的出库数量+此次出库数量>库存预留数量,禁止提交出库单!");
                    }
                    #endregion
                    #endregion
                }
                else
                {
                    throw  new WarnException("要提交的出库单在系统中不存在!");
                }
            }
            catch (WarnException exp)
            {
                throw exp;
            }
            catch (Exception exp)
            {
                LogInfoBLL.WriteLog(this.SessionInfo, exp);
                throw exp;
            }
            return(submitFlag);
        }
Exemple #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);
        }