예제 #1
0
        public ResultModel Update(UserModel user, Model.DocumentOrder order, List<NFMT.Document.Model.OrderStockInvoice> stockInvoices, NFMT.Document.Model.DocumentOrderDetail detail)
        {
            ResultModel result = new ResultModel();

            try
            {
                DAL.DocumentOrderDetailDAL orderDetailDAL = new DocumentOrderDetailDAL();
                DAL.DocumentOrderStockDAL orderStockDAL = new DocumentOrderStockDAL();
                DAL.DocumentOrderInvoiceDAL orderInvoiceDAL = new DocumentOrderInvoiceDAL();
                NFMT.WareHouse.DAL.StockDAL stockDAL = new WareHouse.DAL.StockDAL();
                NFMT.WareHouse.DAL.StockNameDAL stockNameDAL = new WareHouse.DAL.StockNameDAL();
                NFMT.Contract.DAL.ContractSubDAL subDAL = new Contract.DAL.ContractSubDAL();
                NFMT.Contract.DAL.ContractDAL contractDAL = new Contract.DAL.ContractDAL();
                NFMT.Contract.DAL.ContractCorporationDetailDAL corpDetailDAL = new Contract.DAL.ContractCorporationDetailDAL();

                using (System.Transactions.TransactionScope scope = new TransactionScope())
                {
                    if (order == null)
                    {
                        result.Message = "制单指令不包含任何数据";
                        result.ResultStatus = -1;
                        return result;
                    }

                    //验证制单指令
                    result = this.documentorderDAL.Get(user, order.OrderId);
                    if (result.ResultStatus != 0)
                        return result;

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

                    resultOrder.ContractNo = order.ContractNo;
                    resultOrder.LCNo = order.LCNo;
                    resultOrder.LCDay = order.LCDay;
                    resultOrder.OrderType = order.OrderType;
                    resultOrder.OrderDate = order.OrderDate;
                    resultOrder.ApplyCorp = order.ApplyCorp;
                    resultOrder.ApplyDept = order.ApplyDept;
                    resultOrder.BuyerCorp = order.BuyerCorp;
                    resultOrder.BuyerCorpName = order.BuyerCorpName;
                    resultOrder.BuyerAddress = order.BuyerAddress;
                    resultOrder.RecBankId = order.RecBankId;
                    resultOrder.DiscountBase = order.DiscountBase;
                    resultOrder.AssetId = order.AssetId;
                    resultOrder.BrandId = order.BrandId;
                    resultOrder.AreaName = order.AreaName;
                    resultOrder.BankCode = order.BankCode;
                    resultOrder.GrossAmount = order.GrossAmount;
                    resultOrder.NetAmount = order.NetAmount;
                    resultOrder.UnitId = order.UnitId;
                    resultOrder.Bundles = order.Bundles;
                    resultOrder.Currency = order.Currency;
                    resultOrder.UnitPrice = order.UnitPrice;
                    resultOrder.InvBala = order.InvBala;
                    resultOrder.Meno = order.Meno;

                    //更新主表
                    result = this.documentorderDAL.Update(user, resultOrder);
                    if (result.ResultStatus != 0)
                        return result;

                    //获取明细表
                    result = orderDetailDAL.GetByOrderId(user, order.OrderId);
                    if (result.ResultStatus != 0)
                        return result;

                    Model.DocumentOrderDetail resultDetail = result.ReturnValue as Model.DocumentOrderDetail;
                    if (resultDetail == null || resultDetail.DetailId <= 0)
                    {
                        result.Message = "制单指令明细获取失败";
                        result.ResultStatus = -1;
                        return result;
                    }

                    resultDetail.InvoiceCopies = detail.InvoiceCopies;
                    resultDetail.InvoiceSpecific = detail.InvoiceSpecific;
                    resultDetail.QualityCopies = detail.QualityCopies;
                    resultDetail.QualitySpecific = detail.QualitySpecific;
                    resultDetail.WeightCopies = detail.WeightCopies;
                    resultDetail.WeightSpecific = detail.WeightSpecific;
                    resultDetail.TexCopies = detail.TexCopies;
                    resultDetail.TexSpecific = detail.TexSpecific;
                    resultDetail.DeliverCopies = detail.DeliverCopies;
                    resultDetail.DeliverSpecific = detail.DeliverSpecific;
                    resultDetail.TotalInvCopies = detail.TotalInvCopies;
                    resultDetail.TotalInvSpecific = detail.TotalInvSpecific;

                    result = orderDetailDAL.Update(user, resultDetail);
                    if (result.ResultStatus != 0)
                        return result;

                    //作废库存明细与发票明细
                    result = orderInvoiceDAL.Load(user, order.OrderId);
                    if (result.ResultStatus != 0)
                        return result;

                    List<Model.DocumentOrderInvoice> orderInvoices = result.ReturnValue as List<Model.DocumentOrderInvoice>;
                    if (orderInvoices == null)
                    {
                        result.Message = "制单指令发票明细获取失败";
                        result.ResultStatus = -1;
                        return result;
                    }
                    foreach (Model.DocumentOrderInvoice orderInvoice in orderInvoices)
                    {
                        result = orderInvoiceDAL.Invalid(user, orderInvoice);
                        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)
                    {
                        result.Message = "制单指令库存明细获取失败";
                        result.ResultStatus = -1;
                        return result;
                    }

                    foreach (Model.DocumentOrderStock orderStock in orderStocks)
                    {
                        result = orderStockDAL.Invalid(user, orderStock);
                        if (result.ResultStatus != 0)
                            return result;
                    }

                    OrderTypeEnum orderType = (OrderTypeEnum)order.OrderType;

                    //新增库存明细与发票明细
                    foreach (Model.OrderStockInvoice stockInvoice in stockInvoices)
                    {
                        Model.DocumentOrderStock orderStock = new DocumentOrderStock();
                        orderStock.DetailStatus = StatusEnum.已生效;
                        orderStock.OrderId = order.OrderId;
                        orderStock.ApplyAmount = stockInvoice.ApplyWeight;

                        //库存分配制单指令校验库存信息
                        if (orderType == OrderTypeEnum.临票制单指令 || orderType == OrderTypeEnum.替临制单指令)
                        {
                            //验证库存
                            result = stockDAL.Get(user, stockInvoice.StockId);
                            if (result.ResultStatus != 0)
                                return result;
                            NFMT.WareHouse.Model.Stock stock = result.ReturnValue as NFMT.WareHouse.Model.Stock;
                            if (stock == null || stock.StockId <= 0)
                            {
                                result.Message = "制单指令分配库存不存在";
                                result.ResultStatus = -1;
                                return result;
                            }

                            if (stock.AssetId != order.AssetId)
                            {
                                result.Message = "库存品种不匹配";
                                result.ResultStatus = -1;
                                return result;
                            }

                            if (stock.CurNetAmount < stockInvoice.ApplyWeight)
                            {
                                result.Message = "申请重量不能大于库存剩余净重";
                                result.ResultStatus = -1;
                                return result;
                            }

                            //获取业务单号
                            result = stockNameDAL.Get(user, stock.StockNameId);
                            if (result.ResultStatus != 0)
                                return result;

                            NFMT.WareHouse.Model.StockName stockName = result.ReturnValue as NFMT.WareHouse.Model.StockName;
                            if (stockName == null || stockName.StockNameId <= 0)
                            {
                                result.Message = "业务单号不存在";
                                result.ResultStatus = -1;
                                return result;
                            }

                            orderStock.StockId = stock.StockId;
                            orderStock.StockNameId = stock.StockNameId;
                            orderStock.RefNo = stockName.RefNo;
                        }
                        else
                        {
                            //无库存配货权录入业务单号
                            orderStock.RefNo = stockInvoice.RefNo;
                        }

                        //添加库存明细
                        int orderStockId = 0;

                        result = orderStockDAL.Insert(user, orderStock);
                        if (result.ResultStatus != 0)
                            return result;

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

                        //添加发票明细
                        Model.DocumentOrderInvoice orderInvoice = new DocumentOrderInvoice();
                        orderInvoice.DetailStatus = StatusEnum.已生效;
                        orderInvoice.InvoiceBala = stockInvoice.InvoiceBala;
                        orderInvoice.InvoiceNo = stockInvoice.InvoiceNo;
                        orderInvoice.OrderId = order.OrderId;
                        orderInvoice.StockDetailId = orderStockId;

                        result = orderInvoiceDAL.Insert(user, orderInvoice);
                        if (result.ResultStatus != 0)
                            return result;
                    }

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

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

            return result;
        }
예제 #2
0
        public ResultModel UpdateReplaceOrder(UserModel user, Model.DocumentOrder order, List<NFMT.Document.Model.OrderReplaceStock> stockInvoices, NFMT.Document.Model.DocumentOrderDetail detail)
        {
            ResultModel result = new ResultModel();

            try
            {
                DAL.DocumentOrderDetailDAL orderDetailDAL = new DocumentOrderDetailDAL();
                DAL.DocumentOrderStockDAL orderStockDAL = new DocumentOrderStockDAL();
                DAL.DocumentOrderInvoiceDAL orderInvoiceDAL = new DocumentOrderInvoiceDAL();
                NFMT.WareHouse.DAL.StockDAL stockDAL = new WareHouse.DAL.StockDAL();
                NFMT.WareHouse.DAL.StockNameDAL stockNameDAL = new WareHouse.DAL.StockNameDAL();
                NFMT.Contract.DAL.ContractSubDAL subDAL = new Contract.DAL.ContractSubDAL();
                NFMT.Contract.DAL.ContractDAL contractDAL = new Contract.DAL.ContractDAL();
                NFMT.Contract.DAL.ContractCorporationDetailDAL corpDetailDAL = new Contract.DAL.ContractCorporationDetailDAL();

                using (System.Transactions.TransactionScope scope = new TransactionScope())
                {
                    if (order == null)
                    {
                        result.Message = "制单指令不包含任何数据";
                        result.ResultStatus = -1;
                        return result;
                    }

                    //验证制单指令
                    result = this.documentorderDAL.Get(user, order.OrderId);
                    if (result.ResultStatus != 0)
                        return result;

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

                    resultOrder.OrderDate = order.OrderDate;
                    resultOrder.BankCode = order.BankCode;
                    resultOrder.GrossAmount = order.GrossAmount;
                    resultOrder.NetAmount = order.NetAmount;
                    resultOrder.Bundles = order.Bundles;
                    resultOrder.UnitPrice = order.UnitPrice;
                    resultOrder.InvBala = order.InvBala;
                    resultOrder.InvGap = order.InvGap;
                    resultOrder.Meno = order.Meno;

                    //更新主表
                    result = this.documentorderDAL.Update(user, resultOrder);
                    if (result.ResultStatus != 0)
                        return result;

                    //获取明细表
                    result = orderDetailDAL.GetByOrderId(user, resultOrder.OrderId);
                    if (result.ResultStatus != 0)
                        return result;

                    Model.DocumentOrderDetail resultDetail = result.ReturnValue as Model.DocumentOrderDetail;
                    if (resultDetail == null || resultDetail.DetailId <= 0)
                    {
                        result.Message = "制单指令明细获取失败";
                        result.ResultStatus = -1;
                        return result;
                    }

                    resultDetail.InvoiceCopies = detail.InvoiceCopies;
                    resultDetail.InvoiceSpecific = detail.InvoiceSpecific;
                    resultDetail.QualityCopies = detail.QualityCopies;
                    resultDetail.QualitySpecific = detail.QualitySpecific;
                    resultDetail.WeightCopies = detail.WeightCopies;
                    resultDetail.WeightSpecific = detail.WeightSpecific;
                    resultDetail.TexCopies = detail.TexCopies;
                    resultDetail.TexSpecific = detail.TexSpecific;
                    resultDetail.DeliverCopies = detail.DeliverCopies;
                    resultDetail.DeliverSpecific = detail.DeliverSpecific;
                    resultDetail.TotalInvCopies = detail.TotalInvCopies;
                    resultDetail.TotalInvSpecific = detail.TotalInvSpecific;

                    result = orderDetailDAL.Update(user, resultDetail);
                    if (result.ResultStatus != 0)
                        return result;

                    //作废库存明细与发票明细
                    result = orderInvoiceDAL.Load(user, resultOrder.OrderId);
                    if (result.ResultStatus != 0)
                        return result;

                    List<Model.DocumentOrderInvoice> orderInvoices = result.ReturnValue as List<Model.DocumentOrderInvoice>;
                    if (orderInvoices == null)
                    {
                        result.Message = "制单指令发票明细获取失败";
                        result.ResultStatus = -1;
                        return result;
                    }
                    foreach (Model.DocumentOrderInvoice orderInvoice in orderInvoices)
                    {
                        result = orderInvoiceDAL.Invalid(user, orderInvoice);
                        if (result.ResultStatus != 0)
                            return result;
                    }

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

                    foreach (Model.DocumentOrderStock orderStock in orderStocks)
                    {
                        result = orderStockDAL.Invalid(user, orderStock);
                        if (result.ResultStatus != 0)
                            return result;
                    }

                    OrderTypeEnum orderType = (OrderTypeEnum)resultOrder.OrderType;

                    //新增库存明细与发票明细
                    foreach (Model.OrderReplaceStock stockInvoice in stockInvoices)
                    {
                        //验证临票库存明细
                        result = orderStockDAL.Get(user, stockInvoice.DetailId);
                        if (result.ResultStatus != 0)
                            return result;

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

                        if (commercialOrderStock.DetailStatus != StatusEnum.已生效)
                        {
                            result.Message = "制单指令替临库存状态不正确";
                            result.ResultStatus = -1;
                            return result;
                        }

                        if (commercialOrderStock.OrderId != resultOrder.CommercialId)
                        {
                            result.Message = "制单指令替临库存不存在";
                            result.ResultStatus = -1;
                            return result;
                        }

                        Model.DocumentOrderStock orderStock = new DocumentOrderStock();
                        orderStock.DetailStatus = StatusEnum.已生效;
                        orderStock.OrderId = resultOrder.OrderId;
                        orderStock.ApplyAmount = stockInvoice.ApplyWeight;
                        orderStock.StockId = commercialOrderStock.StockId;
                        orderStock.StockNameId = commercialOrderStock.StockNameId;
                        orderStock.RefNo = commercialOrderStock.RefNo;
                        orderStock.ComDetailId = commercialOrderStock.DetailId;

                        //添加库存明细
                        int orderStockId = 0;

                        result = orderStockDAL.Insert(user, orderStock);
                        if (result.ResultStatus != 0)
                            return result;

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

                        //添加发票明细
                        Model.DocumentOrderInvoice orderInvoice = new DocumentOrderInvoice();
                        orderInvoice.DetailStatus = StatusEnum.已生效;
                        orderInvoice.InvoiceBala = stockInvoice.InvoiceBala;
                        orderInvoice.InvoiceNo = stockInvoice.InvoiceNo;
                        orderInvoice.OrderId = resultOrder.OrderId;
                        orderInvoice.StockDetailId = orderStockId;

                        result = orderInvoiceDAL.Insert(user, orderInvoice);
                        if (result.ResultStatus != 0)
                            return result;
                    }

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

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

            return result;
        }
예제 #3
0
        public ResultModel Invalid(UserModel user, int orderId)
        {
            ResultModel result = new ResultModel();

            try
            {
                //作废制单指令
                //作废制单指令明细
                //作废制单指令库存明细
                //作废制单指令发票明细
                //作废制单指令附件
                DAL.DocumentOrderDetailDAL detailDAL = new DocumentOrderDetailDAL();
                DAL.DocumentOrderStockDAL stockDAL = new DocumentOrderStockDAL();
                DAL.DocumentOrderInvoiceDAL invoiceDAL = new DocumentOrderInvoiceDAL();

                using (System.Transactions.TransactionScope scope = new TransactionScope())
                {
                    //验证制单指令
                    result = this.documentorderDAL.Get(user, 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;
                    }

                    //作废制单指令
                    result = this.documentorderDAL.Invalid(user, order);
                    if (result.ResultStatus != 0)
                        return result;

                    //获取明细
                    result = detailDAL.GetByOrderId(user, order.OrderId);
                    if (result.ResultStatus != 0)
                        return result;

                    Model.DocumentOrderDetail detail = result.ReturnValue as Model.DocumentOrderDetail;
                    if (detail == null || detail.DetailId <= 0)
                    {
                        result.ResultStatus = -1;
                        result.Message = "制单指令明细获取失败";
                        return result;
                    }

                    //作废明细
                    result = detailDAL.Invalid(user, detail);
                    if (result.ResultStatus != 0)
                        return result;

                    //获取库存明细
                    result = stockDAL.Load(user, order.OrderId);
                    if (result.ResultStatus != 0)
                        return result;

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

                    //作废库存明细
                    foreach (Model.DocumentOrderStock orderStock in orderStocks)
                    {
                        result = stockDAL.Invalid(user, orderStock);
                        if (result.ResultStatus != 0)
                            return result;
                    }

                    //获取发票明细
                    result = invoiceDAL.Load(user, order.OrderId);
                    if (result.ResultStatus != 0)
                        return result;

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

                    //作废发票明细
                    foreach (Model.DocumentOrderInvoice orderInvoice in orderInvoices)
                    {
                        result = invoiceDAL.Invalid(user, orderInvoice);
                        if (result.ResultStatus != 0)
                            return result;
                    }

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

            return result;
        }