Example #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;
        }
Example #2
0
        public ResultModel Create(UserModel user, Model.Document doc, List<Model.DocumentStock> docStocks, bool isSubmitAudit)
        {
            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.OrderId <= 0)
                    {
                        result.ResultStatus = -1;
                        result.Message = "制单信息错误";
                        return result;
                    }

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

                    //获取指令
                    result = orderDAL.Get(user, doc.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;
                    }

                    //新增制单
                    //doc.AcceptanceDate = DefaultValue.DefaultTime;
                    //doc.PresentDate = DefaultValue.DefaultTime;
                    doc.DocEmpId = user.EmpId;
                    doc.DocumentStatus = DocumentStatusEnum.已录入;
                    result = this.documentDAL.Insert(user, doc);
                    if (result.ResultStatus != 0)
                        return result;

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

                    doc.DocumentId = documentId;

                    //获取当前指令所有库存明细
                    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;
                    }

                    //明细新增
                    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.DocumentId = documentId;
                        addDocStock.OrderId = order.OrderId;
                        addDocStock.OrderStockDetailId = orderStock.DetailId;
                        addDocStock.RefNo = orderStock.RefNo;
                        addDocStock.StockId = orderStock.StockId;
                        addDocStock.StockNameId = orderStock.StockNameId;

                        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 = doc.DocumentId;
                        docInvoice.InvoiceNo = orderInvoice.InvoiceNo;
                        docInvoice.InvoiceBala =orderInvoice.InvoiceBala;
                        docInvoice.OrderId = order.OrderId;
                        docInvoice.OrderInvoiceDetailId = orderInvoice.DetailId;
                        docInvoice.StockDetailId = addDocStock.DetailId;

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

                    if (isSubmitAudit)
                    {
                        NFMT.WorkFlow.AutoSubmit submit = new WorkFlow.AutoSubmit();
                        NFMT.WorkFlow.ITaskProvider taskProvider = new TaskProvider.DocumentTaskProvider();
                        result = submit.Submit(user, doc, taskProvider, WorkFlow.MasterEnum.制单审核);
                        if (result.ResultStatus != 0)
                            return result;
                    }

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

                    scope.Complete();
                }

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

            return result;
        }
Example #3
0
        public ResultModel CreateReplaceOrder(UserModel user, Model.DocumentOrder order, List<NFMT.Document.Model.OrderReplaceStock> stockInvoices, NFMT.Document.Model.DocumentOrderDetail detail, bool isSubmitAudit)
        {
            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.CommercialId);
                    if (result.ResultStatus != 0)
                        return result;

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

                    if (commercialOrder.OrderStatus != StatusEnum.已生效)
                    {
                        result.Message = "临票制单指令状态不正确,不能替临";
                        result.ResultStatus = -1;
                        return result;
                    }

                    //验证合约
                    result = contractDAL.Get(user, order.ContractId);
                    if (result.ResultStatus != 0)
                        return result;

                    NFMT.Contract.Model.Contract contract = result.ReturnValue as NFMT.Contract.Model.Contract;
                    if (contract == null || contract.ContractId <= 0)
                    {
                        result.Message = "合约不存在";
                        result.ResultStatus = -1;
                        return result;
                    }

                    //验证子合约
                    result = subDAL.Get(user, order.SubId);
                    if (result.ResultStatus != 0)
                        return result;

                    NFMT.Contract.Model.ContractSub sub = result.ReturnValue as NFMT.Contract.Model.ContractSub;
                    if (sub == null || sub.SubId <= 0)
                    {
                        result.Message = "子合约不存在";
                        result.ResultStatus = -1;
                        return result;
                    }

                    if (sub.SubStatus != StatusEnum.已生效)
                    {
                        result.Message = "子合约非已生效状态,不能进行制单指令新增";
                        result.ResultStatus = -1;
                        return result;
                    }

                    if (sub.ContractId != order.ContractId)
                    {
                        result.Message = "子合约归属主合约与制单指令主合约不一致";
                        result.ResultStatus = -1;
                        return result;
                    }

                    result = corpDetailDAL.LoadCorpListByContractId(user, sub.ContractId, true);
                    if (result.ResultStatus != 0)
                        return result;

                    List<NFMT.Contract.Model.ContractCorporationDetail> corps = result.ReturnValue as List<NFMT.Contract.Model.ContractCorporationDetail>;
                    if (corps == null || corps.Count == 0)
                    {
                        result.Message = "合约我方抬头获取失败";
                        result.ResultStatus = -1;
                        return result;
                    }

                    int orderId = 0;

                    //制单指令主表数据初始化
                    //付款方式默认为LC
                    order.PaymentStyle = 19;
                    //卖方默认为合约我方抬头默认公司
                    order.SellerCorp = corps[0].CorpId;
                    ////临票制单或直接终票制单,临终发票差额为0
                    //order.InvGap = 0;
                    //LC未加入时LC序号为0
                    order.LCId = 0;
                    order.ApplyEmpId = user.EmpId;

                    //新增主表
                    order.OrderStatus = StatusEnum.已录入;
                    result = this.documentorderDAL.Insert(user, order);
                    if (result.ResultStatus != 0)
                        return result;

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

                    //新增明细表
                    detail.OrderId = orderId;
                    detail.DetailStatus = StatusEnum.已生效;
                    result = orderDetailDAL.Insert(user, detail);
                    if (result.ResultStatus != 0)
                        return result;

                    //临票指令类型,区分是否分配库存
                    OrderTypeEnum orderType = (OrderTypeEnum)commercialOrder.OrderType;

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

                        //验证临票库存明细是否存在
                        result = orderStockDAL.Get(user,stockInvoice.DetailId);
                        if (result.ResultStatus != 0)
                            return result;

                        Model.DocumentOrderStock commercialOrderStock = result.ReturnValue as Model.DocumentOrderStock;
                        if (commercialOrderStock == null || commercialOrderStock.DetailId <= 0)
                        {
                            result.Message = "替换的库存明细不存在";
                            result.ResultStatus = -1;
                            return result;
                        }

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

                        int orderStockId = 0;

                        orderStock.StockId = commercialOrderStock.StockId;
                        orderStock.StockNameId = commercialOrderStock.StockNameId;
                        orderStock.RefNo = commercialOrderStock.RefNo;

                        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 = orderId;
                        orderInvoice.StockDetailId = orderStockId;

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

                    if (isSubmitAudit)
                    {
                        NFMT.WorkFlow.AutoSubmit submit = new WorkFlow.AutoSubmit();
                        NFMT.WorkFlow.ITaskProvider taskProvider = new TaskProvider.OrderTaskProvider();
                        result = submit.Submit(user, order, taskProvider, WorkFlow.MasterEnum.制单指令审核);
                        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;
        }
Example #4
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;
        }
Example #5
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;
        }
Example #6
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;
        }