Ejemplo n.º 1
0
        public ResultModel Update(UserModel user, Model.Document doc, List<Model.DocumentStock> docStocks)
        {
            ResultModel result = new ResultModel();

            try
            {
                DAL.DocumentOrderDAL orderDAL = new DocumentOrderDAL();
                DAL.DocumentOrderStockDAL orderStockDAL = new DocumentOrderStockDAL();
                DAL.DocumentOrderInvoiceDAL orderInvoiceDAL = new DocumentOrderInvoiceDAL();
                DAL.DocumentStockDAL docStockDAL = new DocumentStockDAL();
                DAL.DocumentInvoiceDAL docInvoiceDAL = new DocumentInvoiceDAL();
                Invoice.DAL.BusinessInvoiceDAL invoiceDAL = new Invoice.DAL.BusinessInvoiceDAL();

                using (System.Transactions.TransactionScope scope = new TransactionScope())
                {
                    if (doc == null || doc.DocumentId <= 0)
                    {
                        result.ResultStatus = -1;
                        result.Message = "制单信息错误";
                        return result;
                    }

                    if (docStocks == null || docStocks.Count == 0)
                    {
                        result.ResultStatus = -1;
                        result.Message = "未选择任何制单库存";
                        return result;
                    }

                    //获取制单
                    result = this.documentDAL.Get(user, doc.DocumentId);
                    if (result.ResultStatus != 0)
                        return result;

                    Model.Document resultDoc = result.ReturnValue as Model.Document;
                    if (resultDoc == null || resultDoc.DocumentId <= 0)
                    {
                        result.ResultStatus = -1;
                        result.Message = "制单不存在";
                        return result;
                    }

                    //获取指令
                    result = orderDAL.Get(user, resultDoc.OrderId);
                    if (result.ResultStatus != 0)
                        return result;

                    Model.DocumentOrder order = result.ReturnValue as Model.DocumentOrder;
                    if (order == null || order.OrderId <= 0)
                    {
                        result.ResultStatus = -1;
                        result.Message = "制单指令不存在";
                        return result;
                    }

                    //判断指令状态
                    if (order.OrderStatus != StatusEnum.已生效)
                    {
                        result.ResultStatus = -1;
                        result.Message = "制单指令非已生效状态,不能进行制单";
                        return result;
                    }

                    //新增制单
                    resultDoc.DocEmpId = user.EmpId;
                    resultDoc.DocumentDate = doc.DocumentDate;
                    resultDoc.Meno = doc.Meno;
                    result = this.documentDAL.Update(user, resultDoc);
                    if (result.ResultStatus != 0)
                        return result;

                    //获取当前指令所有库存明细
                    result = orderStockDAL.Load(user, order.OrderId);
                    if (result.ResultStatus != 0)
                        return result;

                    List<Model.DocumentOrderStock> orderStocks = result.ReturnValue as List<Model.DocumentOrderStock>;
                    if (orderStocks == null || orderStocks.Count == 0)
                    {
                        result.ResultStatus = -1;
                        result.Message = "制单指令库存明细获取失败";
                        return result;
                    }

                    //获取当前制单所有库存明细与发票明细并作废
                    result = docStockDAL.Load(user, resultDoc.DocumentId);
                    if (result.ResultStatus != 0)
                        return result;

                    List<Model.DocumentStock> resultDocStocks = result.ReturnValue as List<Model.DocumentStock>;
                    if (resultDocStocks == null)
                    {
                        result.ResultStatus = -1;
                        result.Message = "制单库存明细获取失败";
                        return result;
                    }

                    foreach (Model.DocumentStock docStock in resultDocStocks)
                    {
                        result = docStockDAL.Invalid(user, docStock);
                        if (result.ResultStatus != 0)
                            return result;
                    }

                    result = docInvoiceDAL.Load(user,resultDoc.DocumentId);
                    if(result.ResultStatus!=0)
                        return result;

                    List<Model.DocumentInvoice> resultDocInvoices = result.ReturnValue as List<Model.DocumentInvoice>;
                    if (resultDocInvoices == null)
                    {
                        result.ResultStatus = -1;
                        result.Message = "制单发票明细获取失败";
                        return result;
                    }

                    foreach (Model.DocumentInvoice docInvoice in resultDocInvoices)
                    {
                        result = docInvoiceDAL.Invalid(user, docInvoice);
                        if (result.ResultStatus != 0)
                            return result;
                    }

                    //明细新增
                    foreach (Model.DocumentStock docStock in docStocks)
                    {
                        //验证选择明细是否在指令中
                        Model.DocumentOrderStock orderStock = orderStocks.FirstOrDefault(temp => temp.DetailId == docStock.DetailId);
                        if (orderStock == null || orderStock.DetailId <= 0)
                        {
                            result.ResultStatus = -1;
                            result.Message = "制单指令库存不存在";
                            return result;
                        }

                        //新增制单库存明细
                        Model.DocumentStock addDocStock = new DocumentStock();
                        addDocStock.DetailStatus = StatusEnum.已生效;
                        addDocStock.OrderId = resultDoc.OrderId;
                        addDocStock.OrderStockDetailId = orderStock.DetailId;
                        addDocStock.RefNo = orderStock.RefNo;
                        addDocStock.StockId = orderStock.StockId;
                        addDocStock.StockNameId = orderStock.StockNameId;
                        addDocStock.DocumentId = resultDoc.DocumentId;

                        result = docStockDAL.Insert(user, addDocStock);
                        if (result.ResultStatus != 0)
                            return result;

                        int docStockDetailId = 0;
                        if (result.ReturnValue == null || !int.TryParse(result.ReturnValue.ToString(), out docStockDetailId) || docStockDetailId <= 0)
                        {
                            result.ResultStatus = -1;
                            result.Message = "制单库存明细新增失败";
                            return result;
                        }

                        addDocStock.DetailId = docStockDetailId;

                        //获取指令发票明细
                        result = orderInvoiceDAL.GetByStockDetailId(user, orderStock.DetailId);
                        if (result.ResultStatus != 0)
                            return result;

                        Model.DocumentOrderInvoice orderInvoice = result.ReturnValue as Model.DocumentOrderInvoice;
                        if (orderInvoice == null || orderInvoice.DetailId <= 0)
                        {
                            result.ResultStatus = -1;
                            result.Message = "制单指令发票明细不存在";
                            return result;
                        }

                        Model.DocumentInvoice docInvoice = new DocumentInvoice();
                        docInvoice.DetailStatus = StatusEnum.已生效;
                        docInvoice.DocumentId = resultDoc.DocumentId;
                        docInvoice.InvoiceNo = orderInvoice.InvoiceNo;
                        docInvoice.InvoiceBala = orderInvoice.InvoiceBala;
                        docInvoice.OrderId = resultDoc.OrderId;
                        docInvoice.OrderInvoiceDetailId = orderInvoice.DetailId;
                        docInvoice.StockDetailId = addDocStock.DetailId;

                        result = docInvoiceDAL.Insert(user, docInvoice);
                        if (result.ResultStatus != 0)
                            return result;

                    }

                    if (result.ResultStatus == 0)
                        result.ReturnValue = resultDoc;

                    scope.Complete();
                }
            }
            catch (Exception ex)
            {
                result.ResultStatus = -1;
                result.Message = ex.Message;
            }

            return result;
        }
Ejemplo n.º 2
0
        public ResultModel Acceptan(UserModel user, int documentId, DateTime acceptanceDate)
        {
            ResultModel result = new ResultModel();

            try
            {
                DAL.DocumentStockDAL docStockDAL = new DocumentStockDAL();
                DAL.DocumentInvoiceDAL docInvoiceDAL = new DocumentInvoiceDAL();

                //承兑
                using (System.Transactions.TransactionScope scope = new TransactionScope())
                {
                    //校验制单
                    result = this.documentDAL.Get(user, documentId);
                    if (result.ResultStatus != 0)
                        return result;

                    Model.Document doc = result.ReturnValue as Model.Document;
                    if (doc == null || doc.DocumentId <= 0)
                    {
                        result.ResultStatus = -1;
                        result.Message = "制单不存在";
                        return result;
                    }

                    //更新制单
                    doc.AcceptanceDate = acceptanceDate;
                    doc.Acceptancer = user.EmpId;

                    result = this.documentDAL.Update(user, doc);
                    if (result.ResultStatus != 0)
                        return result;

                    result = this.documentDAL.Acceptan(user, doc);
                    if (result.ResultStatus != 0)
                        return result;

                    //获取库存与发票明细,并设置状态完成
                    result = docStockDAL.Load(user, doc.DocumentId);
                    if (result.ResultStatus != 0)
                        return result;

                    List<Model.DocumentStock> docStocks = result.ReturnValue as List<Model.DocumentStock>;
                    if (docStocks != null)
                    {
                        foreach (Model.DocumentStock docStock in docStocks)
                        {
                            result = docStockDAL.Complete(user, docStock);
                            if (result.ResultStatus != 0)
                                return result;
                        }
                    }

                    result = docInvoiceDAL.Load(user, doc.DocumentId);
                    if (result.ResultStatus != 0)
                        return result;

                    List<Model.DocumentInvoice> docInvoices = result.ReturnValue as List<Model.DocumentInvoice>;
                    if (docInvoices != null)
                    {
                        foreach (Model.DocumentInvoice docInvoice in docInvoices)
                        {
                            result = docInvoiceDAL.Complete(user, docInvoice);
                            if (result.ResultStatus != 0)
                                return result;
                        }
                    }

                    scope.Complete();
                }
            }
            catch (Exception ex)
            {
                result.ResultStatus = -1;
                result.Message = ex.Message;
            }

            return result;
        }
Ejemplo n.º 3
0
        public ResultModel Invalid(UserModel user, int documentId)
        {
            ResultModel result = new ResultModel();

            try
            {
                //作废制单主表
                //作废制单库存明细
                //作废制单发票明细
                //作废出库执行
                //作废发票

                DAL.DocumentInvoiceDAL docInvoiceDAL = new DocumentInvoiceDAL();
                DAL.DocumentStockDAL docStockDAL = new DocumentStockDAL();

                using (System.Transactions.TransactionScope scope = new TransactionScope())
                {
                    //校验制单
                    result = this.documentDAL.Get(user, documentId);
                    if (result.ResultStatus != 0)
                        return result;

                    Model.Document doc = result.ReturnValue as Model.Document;
                    if (doc == null || doc.DocumentId <= 0)
                    {
                        result.ResultStatus = -1;
                        result.Message = "制单不存在";
                        return result;
                    }

                    //作废制单主表
                    result = this.documentDAL.Invalid(user, doc);
                    if (result.ResultStatus != 0)
                        return result;

                    //获取所有库存明细
                    result = docStockDAL.Load(user, doc.DocumentId);
                    if (result.ResultStatus != 0)
                        return result;

                    List<Model.DocumentStock> docStocks = result.ReturnValue as List<Model.DocumentStock>;
                    if (docStocks == null)
                    {
                        result.ResultStatus = -1;
                        result.Message = "制单的库存明细获取失败";
                        return result;
                    }

                    foreach (Model.DocumentStock docStock in docStocks)
                    {
                        result = docStockDAL.Invalid(user, docStock);
                        if (result.ResultStatus != 0)
                            return result;
                    }

                    //获取所有发票明细并作废
                    result = docInvoiceDAL.Load(user, doc.DocumentId);
                    if (result.ResultStatus != 0)
                        return result;

                    List<Model.DocumentInvoice> docInvoices = result.ReturnValue as List<Model.DocumentInvoice>;
                    if (docInvoices == null)
                    {
                        result.ResultStatus = -1;
                        result.Message = "制单的发票明细获取失败";
                        return result;
                    }

                    foreach (Model.DocumentInvoice docInvoice in docInvoices)
                    {
                        result = docInvoiceDAL.Invalid(user, docInvoice);
                        if (result.ResultStatus != 0)
                            return result;
                    }

                    scope.Complete();
                }
            }
            catch (Exception ex)
            {
                result.ResultStatus = -1;
                result.Message = ex.Message;
            }

            return result;
        }