Пример #1
0
        public ResultModel CreateStockReceipt(UserModel user, NFMT.WareHouse.Model.StockReceipt stockReceipt, List<NFMT.WareHouse.Model.StockReceiptDetail> details, List<NFMT.WareHouse.Model.StockReceiptDetail> saleDetails, bool isAudit)
        {
            ResultModel result = new ResultModel();

            try
            {
                NFMT.Contract.DAL.ContractSubDAL subDAL = new Contract.DAL.ContractSubDAL();
                NFMT.Contract.DAL.ContractDAL contractDAL = new Contract.DAL.ContractDAL();
                NFMT.WareHouse.DAL.StockDAL stockDAL = new StockDAL();
                NFMT.WareHouse.DAL.StockLogDAL stockLogDAL = new StockLogDAL();
                DAL.StockReceiptDAL receiptDAL = new StockReceiptDAL();
                DAL.StockReceiptDetailDAL detailDAL = new StockReceiptDetailDAL();

                using (System.Transactions.TransactionScope scope = new TransactionScope(TransactionScopeOption.Required))
                {
                    //验证合约
                    result = subDAL.Get(user, stockReceipt.ContractSubId);
                    if (result.ResultStatus != 0)
                        return result;

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

                    result = contractDAL.Get(user, sub.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.ResultStatus = -1;
                        result.Message = "合约不存在";
                        return result;
                    }

                    decimal sumNetAmount = 0;
                    decimal sumReceiptAmount = 0;
                    decimal sumMissAmount = 0;
                    decimal missRate = 0;

                    //明细验证
                    foreach (NFMT.WareHouse.Model.StockReceiptDetail detail in details)
                    {
                        if (detail.ReceiptAmount > 0)
                        {
                            //验证库存
                            result = stockDAL.Get(user, detail.StockId);
                            if (result.ResultStatus != 0)
                                return result;

                            Model.Stock stock = result.ReturnValue as Model.Stock;
                            if (stock == null || stock.StockId <= 0)
                            {
                                result.ResultStatus = -1;
                                result.Message = "库存不存在";
                                return result;
                            }

                            //验证流水
                            result = stockLogDAL.Get(user, detail.StockLogId);
                            if (result.ResultStatus != 0)
                                return result;

                            Model.StockLog stockLog = result.ReturnValue as Model.StockLog;
                            if (stockLog == null || stockLog.StockLogId <= 0)
                            {
                                result.ResultStatus = -1;
                                result.Message = "库存流水不存在";
                                return result;
                            }

                            if (stockLog.StockId != stock.StockId)
                            {
                                result.ResultStatus = -1;
                                result.Message = "库存与库存流水不匹配";
                                return result;
                            }

                            if (stockLog.SubContractId != stockReceipt.ContractSubId)
                            {
                                result.ResultStatus = -1;
                                result.Message = "库存流水与合约不匹配";
                                return result;
                            }

                            detail.ContractId = sub.ContractId;
                            detail.ContractSubId = sub.SubId;
                            detail.DetailStatus = StatusEnum.已生效;
                            detail.PreNetAmount = stock.NetAmount;
                            detail.QtyMiss = detail.ReceiptAmount - stock.NetAmount;
                            detail.QtyRate = (detail.ReceiptAmount / stock.NetAmount - 1) / 100;

                            sumNetAmount += stock.NetAmount;
                            sumReceiptAmount += detail.ReceiptAmount;
                        }
                    }

                    sumMissAmount = sumReceiptAmount - sumNetAmount;
                    missRate = (sumReceiptAmount / sumNetAmount - 1) / 100;

                    //赋值StockReceipt
                    stockReceipt.ContractId = sub.ContractId;
                    stockReceipt.ContractSubId = sub.SubId;
                    stockReceipt.PreNetAmount = sumNetAmount;
                    stockReceipt.QtyMiss = sumMissAmount;
                    stockReceipt.QtyRate = missRate;
                    stockReceipt.ReceiptAmount = sumReceiptAmount;
                    stockReceipt.Receipter = user.EmpId;
                    stockReceipt.ReceiptDate = DateTime.Now;

                    if (contract.TradeDirection == (int)NFMT.Contract.TradeDirectionEnum.Buy)
                        stockReceipt.ReceiptType = (int)WareHouse.ReceiptTypeEnum.StockInReceipt;
                    else
                        stockReceipt.ReceiptType = (int)WareHouse.ReceiptTypeEnum.StockOutReceipt;

                    stockReceipt.UnitId = sub.UnitId;

                    //新增StockReceipt
                    result = stockreceiptDAL.Insert(user, stockReceipt);
                    if (result.ResultStatus != 0)
                        return result;

                    int receiptId = 0;
                    if (result.ReturnValue == null || !int.TryParse(result.ReturnValue.ToString(), out receiptId))
                    {
                        result.ResultStatus = -1;
                        result.Message = "新增库存回执失败";
                        return result;
                    }

                    //新增明细
                    foreach (NFMT.WareHouse.Model.StockReceiptDetail detail in details)
                    {
                        detail.ReceiptId = receiptId;
                        result = detailDAL.Insert(user, detail);
                        if (result.ResultStatus != 0)
                            return result;
                    }

                    stockReceipt.ReceiptId = receiptId;
                    string resultStr = Newtonsoft.Json.JsonConvert.SerializeObject(stockReceipt);

                    //if(isAudit)
                    //{
                    //    stockReceipt.ReceiptId = receiptId;
                    //    NFMT.WorkFlow.AutoSubmit submit = new NFMT.WorkFlow.AutoSubmit();
                    //    result = submit.Submit(user, stockReceipt, new TaskProvider.StockReceiptTaskProvider(), NFMT.WorkFlow.MasterEnum.库存净重回执审核);
                    //    if (result.ResultStatus != 0)
                    //        return result;
                    //}

                    #region 销售合约库存回执

                    if (saleDetails != null && saleDetails.Any())
                    {
                        foreach (int subId in saleDetails.Select(a => a.ContractSubId).Distinct())
                        {
                            //验证合约
                            result = subDAL.Get(user, subId);
                            if (result.ResultStatus != 0)
                                return result;

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

                            sumNetAmount = 0;
                            sumReceiptAmount = 0;
                            sumMissAmount = 0;
                            missRate = 0;

                            //明细验证
                            foreach (NFMT.WareHouse.Model.StockReceiptDetail detail in saleDetails.Where(a => a.ContractSubId == subId))
                            {
                                if (detail.ReceiptAmount > 0)
                                {
                                    //验证库存
                                    result = stockDAL.Get(user, detail.StockId);
                                    if (result.ResultStatus != 0)
                                        return result;

                                    Model.Stock stock = result.ReturnValue as Model.Stock;
                                    if (stock == null || stock.StockId <= 0)
                                    {
                                        result.ResultStatus = -1;
                                        result.Message = "库存不存在";
                                        return result;
                                    }

                                    //验证流水
                                    result = stockLogDAL.Get(user, detail.StockLogId);
                                    if (result.ResultStatus != 0)
                                        return result;

                                    Model.StockLog stockLog = result.ReturnValue as Model.StockLog;
                                    if (stockLog == null || stockLog.StockLogId <= 0)
                                    {
                                        result.ResultStatus = -1;
                                        result.Message = "库存流水不存在";
                                        return result;
                                    }

                                    if (stockLog.StockId != stock.StockId)
                                    {
                                        result.ResultStatus = -1;
                                        result.Message = "库存与库存流水不匹配";
                                        return result;
                                    }

                                    if (stockLog.SubContractId != subId)
                                    {
                                        result.ResultStatus = -1;
                                        result.Message = "库存流水与合约不匹配";
                                        return result;
                                    }

                                    detail.ContractId = saleSub.ContractId;
                                    detail.ContractSubId = saleSub.SubId;
                                    detail.DetailStatus = StatusEnum.已生效;
                                    detail.PreNetAmount = stock.NetAmount;
                                    detail.QtyMiss = detail.ReceiptAmount - stock.NetAmount;
                                    detail.QtyRate = (detail.ReceiptAmount / stock.NetAmount - 1) / 100;

                                    sumNetAmount += stock.NetAmount;
                                    sumReceiptAmount += detail.ReceiptAmount;
                                }
                            }

                            sumMissAmount = sumReceiptAmount - sumNetAmount;
                            missRate = (sumReceiptAmount / sumNetAmount - 1) / 100;

                            //赋值StockReceipt
                            stockReceipt.ContractId = saleSub.ContractId;
                            stockReceipt.ContractSubId = saleSub.SubId;
                            stockReceipt.PreNetAmount = sumNetAmount;
                            stockReceipt.ReceiptAmount = sumReceiptAmount;
                            stockReceipt.UnitId = saleSub.UnitId;
                            stockReceipt.QtyMiss = sumMissAmount;
                            stockReceipt.QtyRate = missRate;
                            stockReceipt.Receipter = user.EmpId;
                            stockReceipt.ReceiptDate = DateTime.Now;

                            if (saleSub.TradeDirection == (int)NFMT.Contract.TradeDirectionEnum.Buy)
                                stockReceipt.ReceiptType = (int)WareHouse.ReceiptTypeEnum.StockInReceipt;
                            else
                                stockReceipt.ReceiptType = (int)WareHouse.ReceiptTypeEnum.StockOutReceipt;

                            //新增StockReceipt
                            result = stockreceiptDAL.Insert(user, stockReceipt);
                            if (result.ResultStatus != 0)
                                return result;

                            receiptId = 0;
                            if (result.ReturnValue == null || !int.TryParse(result.ReturnValue.ToString(), out receiptId))
                            {
                                result.ResultStatus = -1;
                                result.Message = "新增库存回执失败";
                                return result;
                            }

                            //新增明细
                            foreach (NFMT.WareHouse.Model.StockReceiptDetail detail in saleDetails.Where(a => a.ContractSubId == subId))
                            {
                                detail.ReceiptId = receiptId;
                                result = detailDAL.Insert(user, detail);
                                if (result.ResultStatus != 0)
                                    return result;
                            }
                        }

                        //if (isAudit)
                        //{
                        //    stockReceipt.ReceiptId = receiptId;
                        //    NFMT.WorkFlow.AutoSubmit submit = new NFMT.WorkFlow.AutoSubmit();
                        //    result = submit.Submit(user, stockReceipt, new TaskProvider.StockReceiptTaskProvider(), NFMT.WorkFlow.MasterEnum.库存净重回执审核);
                        //    if (result.ResultStatus != 0)
                        //        return result;
                        //}
                    }

                    #endregion

                    stockReceipt.ReceiptId = receiptId;
                    if (result.ResultStatus == 0)
                    {
                        if (saleDetails != null && saleDetails.Any())
                            result.ReturnValue = stockReceipt;
                        else
                            result.ReturnValue = null;

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

            return result;
        }
Пример #2
0
        public ResultModel Create(UserModel user, Model.StockIn stockIn, int subId, bool isSubmitAudit)
        {
            ResultModel result = new ResultModel();

            try
            {
                using (System.Transactions.TransactionScope scope = new TransactionScope())
                {
                    NFMT.User.Model.Corporation corporation = NFMT.User.UserProvider.Corporations.FirstOrDefault(temp => temp.CorpId == stockIn.CorpId);
                    if (corporation == null || corporation.CorpId <= 0)
                    {
                        result.ResultStatus = -1;
                        result.Message = "归属公司不存在";
                        return result;
                    }

                    result = this.ValidateAuth(user, stockIn);
                    if (result.ResultStatus != 0)
                        return result;

                    stockIn.GroupId = corporation.ParentId;
                    stockIn.StockInStatus = StatusEnum.已录入;

                    result = stockinDAL.Insert(user, stockIn);
                    if (result.ResultStatus != 0)
                        return result;

                    int stockInId = 0;
                    if (result.ReturnValue == null || !int.TryParse(result.ReturnValue.ToString(), out stockInId) || stockInId <= 0)
                    {
                        result.ResultStatus = -1;
                        result.Message = "入库登录失败";
                        return result;
                    }

                    if (subId > 0)
                    {
                        //获取子合约
                        NFMT.Contract.DAL.ContractSubDAL subDAL = new Contract.DAL.ContractSubDAL();
                        result = subDAL.Get(user, subId);
                        if (result.ResultStatus != 0)
                            return result;

                        Contract.Model.ContractSub sub = result.ReturnValue as Contract.Model.ContractSub;
                        if (sub == null || sub.SubId <= 0)
                        {
                            result.ResultStatus = -1;
                            result.Message = "子合约序号错误";
                            return result;
                        }

                        if (stockIn.GrossAmount > sub.SignAmount)
                        {
                            result.ResultStatus = -1;
                            result.Message = "入库重量不能大于子合约签订数量";
                            return result;
                        }

                        //获取当前子合约下所有大于已录状态的入库登记
                        result = stockinDAL.Load(user, sub.SubId, StatusEnum.已录入);
                        if (result.ResultStatus != 0)
                            return result;

                        List<StockIn> stockIns = result.ReturnValue as List<Model.StockIn>;
                        if (stockIns == null)
                        {
                            result.ResultStatus = -1;
                            result.Message = "获取子合约下入库登记失败";
                            return result;
                        }

                        decimal sumAmount = stockIns.Sum(temp => temp.GrossAmount);
                        //验证子合约下入库重量是否超额
                        if (stockIn.GrossAmount > sub.SignAmount - sumAmount)
                        {
                            result.ResultStatus = -1;
                            result.Message = "入库数量大于当前子合约下可入库数量";
                            return result;
                        }

                        NFMT.WareHouse.Model.ContractStockIn contractStockIn = new NFMT.WareHouse.Model.ContractStockIn()
                        {
                            ContractId = sub.ContractId,
                            ContractSubId = sub.SubId,
                            StockInId = stockInId,
                            RefStatus = StatusEnum.已生效
                        };

                        DAL.ContractStockInDAL contractStockInDAL = new ContractStockInDAL();
                        result = contractStockInDAL.Insert(user, contractStockIn);
                        if (result.ResultStatus != 0)
                            return result;
                    }

                    if (result.ResultStatus == 0)
                    {
                        stockIn.StockInId = stockInId;
                        result.ReturnValue = stockIn;
                    }

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

            return result;
        }
Пример #3
0
        public ResultModel CreateStock(UserModel user, Model.CashInAllot allot, List<Model.CashInStcok> details, int stockLogId)
        {
            ResultModel result = new ResultModel();

            try
            {
                NFMT.Contract.DAL.ContractCorporationDetailDAL corpDetailDAL = new Contract.DAL.ContractCorporationDetailDAL();
                NFMT.Contract.DAL.ContractSubDAL subDAL = new Contract.DAL.ContractSubDAL();
                DAL.CashInContractDAL cashInContractDAL = new CashInContractDAL();
                DAL.CashInCorpDAL cashInCorpDAL = new CashInCorpDAL();
                DAL.CashInDAL cashInDAL = new CashInDAL();
                NFMT.WareHouse.DAL.StockLogDAL stockLogDAL = new WareHouse.DAL.StockLogDAL();
                NFMT.WareHouse.DAL.StockDAL stockDAL = new WareHouse.DAL.StockDAL();

                using (System.Transactions.TransactionScope scope = new TransactionScope())
                {
                    //获取库存流水
                    result = stockLogDAL.Get(user, stockLogId);
                    if (result.ResultStatus != 0)
                        return result;

                    NFMT.WareHouse.Model.StockLog stockLog = result.ReturnValue as NFMT.WareHouse.Model.StockLog;
                    if (stockLog == null || stockLog.StockLogId <= 0)
                    {
                        result.ResultStatus = -1;
                        result.Message = "库存流水不存在";
                        return result;
                    }

                    //获取库存
                    result = stockDAL.Get(user, stockLog.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;
                    }

                    //获取合约
                    result = subDAL.Get(user, stockLog.SubContractId);
                    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.ResultStatus = -1;
                        result.Message = "合约不存在";
                        return result;
                    }

                    if (sub.SubStatus != StatusEnum.已生效)
                    {
                        result.ResultStatus = -1;
                        result.Message = "合约状态不允许分配收款";
                        return result;
                    }

                    //获取外部公司
                    result = corpDetailDAL.LoadCorpListByContractId(user, sub.ContractId, false);
                    if (result.ResultStatus != 0)
                        return result;
                    List<NFMT.Contract.Model.ContractCorporationDetail> outCorps = result.ReturnValue as List<NFMT.Contract.Model.ContractCorporationDetail>;
                    if (outCorps == null)
                    {
                        result.Message = "合约对方抬头获取失败";
                        result.ResultStatus = -1;
                        return result;
                    }

                    foreach (Model.CashInStcok detail in details)
                    {
                        //收款登记验证
                        result = cashInDAL.Get(user, detail.CashInId);
                        if (result.ResultStatus != 0)
                            return result;

                        Model.CashIn cashIn = result.ReturnValue as Model.CashIn;
                        if (cashIn == null || cashIn.CashInId <= 0)
                        {
                            result.Message = "收款登记不存在";
                            result.ResultStatus = -1;
                            return result;
                        }

                        //收款登记与合约币种验证
                        if (cashIn.CurrencyId != sub.SettleCurrency)
                        {
                            result.Message = "收款登记币种与合约币种不相同";
                            result.ResultStatus = -1;
                            return result;
                        }

                        //获取合约收款分配
                        result = cashInContractDAL.Get(user, detail.ContractRefId);
                        if (result.ResultStatus != 0)
                            return result;

                        Model.CashInContract cashInContract = result.ReturnValue as Model.CashInContract;
                        if (cashInContract == null || cashInContract.RefId <= 0)
                        {
                            result.Message = "收款分配失败";
                            result.ResultStatus = -1;
                            return result;
                        }

                        if (cashInContract.DetailStatus != StatusEnum.已生效)
                        {
                            result.Message = "收款分配失败";
                            result.ResultStatus = -1;
                            return result;
                        }

                        //获取公司收款分配
                        result = cashInCorpDAL.Get(user, cashInContract.CorpRefId);
                        if (result.ResultStatus != 0)
                            return result;

                        Model.CashInCorp cashInCorp = result.ReturnValue as Model.CashInCorp;
                        if (cashInCorp == null || cashInCorp.RefId <= 0 || cashInCorp.DetailStatus != StatusEnum.已生效)
                        {
                            result.Message = "收款分配失败";
                            result.ResultStatus = -1;
                            return result;
                        }

                        //验证公司抬头
                        if (!outCorps.Any(temp => temp.CorpId == cashInCorp.CorpId))
                        {
                            result.Message = "收款分配公司不在合约对方抬头,收款分配失败";
                            result.ResultStatus = -1;
                            return result;
                        }

                        //新增库存收款分配
                        detail.AllotId = cashInContract.AllotId;
                        detail.CashInId = cashInContract.CashInId;
                        detail.ContractRefId = cashInContract.RefId;
                        detail.CorpRefId = cashInContract.CorpRefId;
                        detail.DetailStatus = StatusEnum.已生效;
                        detail.StockId = stock.StockId;
                        detail.StockLogId = stockLog.StockLogId;
                        detail.StockNameId = stock.StockNameId;

                        result = this.cashinstcokDAL.Insert(user, detail);
                        if (result.ResultStatus != 0)
                            return result;
                    }

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

            return result;
        }
Пример #4
0
        public ResultModel Update(UserModel user, NFMT.WareHouse.Model.StockReceipt stockReceipt, List<NFMT.WareHouse.Model.StockReceiptDetail> details)
        {
            ResultModel result = new ResultModel();

            try
            {
                NFMT.Contract.DAL.ContractSubDAL subDAL = new Contract.DAL.ContractSubDAL();
                NFMT.Contract.DAL.ContractDAL contractDAL = new Contract.DAL.ContractDAL();
                NFMT.WareHouse.DAL.StockDAL stockDAL = new StockDAL();
                DAL.StockLogDAL stockLogDAL = new StockLogDAL();
                DAL.StockReceiptDAL receiptDAL = new StockReceiptDAL();
                DAL.StockReceiptDetailDAL detailDAL = new StockReceiptDetailDAL();

                using (System.Transactions.TransactionScope scope = new TransactionScope(TransactionScopeOption.Required))
                {
                    //验证仓库回执
                    result = receiptDAL.Get(user, stockReceipt.ReceiptId);
                    if (result.ResultStatus != 0)
                        return result;

                    Model.StockReceipt resultReceipt = result.ReturnValue as Model.StockReceipt;
                    if (resultReceipt == null || resultReceipt.ReceiptId <= 0)
                    {
                        result.ResultStatus = -1;
                        result.Message = "仓库回执不存在";
                        return result;
                    }

                    //获取仓库回执明细
                    result = detailDAL.Load(user, resultReceipt.ReceiptId);
                    if (result.ResultStatus != 0)
                        return result;

                    List<Model.StockReceiptDetail> resultDetails = result.ReturnValue as List<Model.StockReceiptDetail>;
                    if (resultDetails == null)
                    {
                        result.ResultStatus = -1;
                        result.Message = "仓库回执明细获取失败";
                        return result;
                    }

                    //作废现有仓库回执明细
                    foreach (Model.StockReceiptDetail d in resultDetails)
                    {
                        if (d.DetailStatus == StatusEnum.已生效)
                            d.DetailStatus = StatusEnum.已录入;

                        result = detailDAL.Invalid(user, d);
                        if (result.ResultStatus != 0)
                            return result;
                    }

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

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

                    result = contractDAL.Get(user, sub.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.ResultStatus = -1;
                        result.Message = "合约不存在";
                        return result;
                    }

                    decimal sumNetAmount = 0;
                    decimal sumReceiptAmount = 0;
                    decimal sumMissAmount = 0;
                    decimal missRate = 0;

                    //明细验证
                    foreach (NFMT.WareHouse.Model.StockReceiptDetail detail in details)
                    {
                        //验证库存
                        result = stockDAL.Get(user, detail.StockId);
                        if (result.ResultStatus != 0)
                            return result;

                        Model.Stock stock = result.ReturnValue as Model.Stock;
                        if (stock == null || stock.StockId <= 0)
                        {
                            result.ResultStatus = -1;
                            result.Message = "库存不存在";
                            return result;
                        }

                        //验证流水
                        result = stockLogDAL.Get(user, detail.StockLogId);
                        if (result.ResultStatus != 0)
                            return result;

                        Model.StockLog stockLog = result.ReturnValue as Model.StockLog;
                        if (stockLog == null || stockLog.StockLogId <= 0)
                        {
                            result.ResultStatus = -1;
                            result.Message = "库存流水不存在";
                            return result;
                        }

                        if (stockLog.StockId != stock.StockId)
                        {
                            result.ResultStatus = -1;
                            result.Message = "库存与库存流水不匹配";
                            return result;
                        }

                        if (stockLog.SubContractId != stockReceipt.ContractSubId)
                        {
                            result.ResultStatus = -1;
                            result.Message = "库存流水与合约不匹配";
                            return result;
                        }

                        detail.ReceiptId = resultReceipt.ReceiptId;
                        detail.ContractId = sub.ContractId;
                        detail.ContractSubId = sub.SubId;
                        detail.DetailStatus = StatusEnum.已生效;
                        detail.PreNetAmount = stock.NetAmount;
                        detail.QtyMiss = detail.ReceiptAmount - stock.NetAmount;
                        detail.QtyRate = (detail.ReceiptAmount / stock.NetAmount - 1) / 100;

                        sumNetAmount += stock.NetAmount;
                        sumReceiptAmount += detail.ReceiptAmount;

                        //新增仓库回执明细
                        result = detailDAL.Insert(user, detail);
                        if (result.ResultStatus != 0)
                            return result;
                    }

                    sumMissAmount = sumReceiptAmount - sumNetAmount;
                    missRate = (sumReceiptAmount / sumNetAmount - 1) / 100;

                    //赋值StockReceipt
                    resultReceipt.PreNetAmount = sumReceiptAmount;
                    resultReceipt.QtyMiss = sumMissAmount;
                    resultReceipt.QtyRate = missRate;
                    resultReceipt.ReceiptAmount = sumReceiptAmount;
                    resultReceipt.Receipter = user.EmpId;
                    resultReceipt.Memo = stockReceipt.Memo;
                    resultReceipt.ReceiptDate = stockReceipt.ReceiptDate;
                    if (contract.TradeDirection == (int)NFMT.Contract.TradeDirectionEnum.Buy)
                        resultReceipt.ReceiptType = (int)WareHouse.ReceiptTypeEnum.StockInReceipt;
                    else
                        resultReceipt.ReceiptType = (int)WareHouse.ReceiptTypeEnum.StockOutReceipt;
                    resultReceipt.UnitId = sub.UnitId;

                    //修改StockReceipt
                    result = stockreceiptDAL.Update(user, resultReceipt);
                    if (result.ResultStatus != 0)
                        return result;

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

            return result;
        }
Пример #5
0
        public ResultModel Update(UserModel user, NFMT.Operate.Model.Apply apply, NFMT.DoPrice.Model.PricingApply pricingApply, List<NFMT.DoPrice.Model.PricingApplyDetail> pricingApplyDetails)
        {
            ResultModel result = new ResultModel();
            NFMT.Operate.DAL.ApplyDAL applyDAL = new Operate.DAL.ApplyDAL();
            DAL.PricingApplyDAL pricingApplyDAL = new PricingApplyDAL();
            DAL.PricingApplyDetailDAL pricingApplyDetailDAL = new PricingApplyDetailDAL();
            NFMT.Contract.DAL.ContractSubDAL subDAL = new Contract.DAL.ContractSubDAL();
            NFMT.Contract.DAL.ContractDAL contractDAL = new Contract.DAL.ContractDAL();

            try
            {
                using (TransactionScope scope = new TransactionScope(TransactionScopeOption.Required))
                {
                    result = applyDAL.Get(user, apply.ApplyId);
                    if (result.ResultStatus != 0)
                        return result;
                    NFMT.Operate.Model.Apply getApply = result.ReturnValue as NFMT.Operate.Model.Apply;
                    if (getApply == null || getApply.ApplyId <= 0)
                    {
                        result.ResultStatus = -1;
                        result.Message = "获取申请错误";
                        return result;
                    }

                    NFMT.User.Model.Department dept = NFMT.User.UserProvider.Departments.FirstOrDefault(temp => temp.DeptId == apply.ApplyDept);
                    if (dept == null || dept.DeptId <= 0)
                    {
                        result.ResultStatus = -1;
                        result.Message = "申请部门不存在";
                        return result;
                    }

                    getApply.EmpId = user.EmpId;
                    getApply.ApplyTime = DateTime.Now;
                    getApply.ApplyDept = apply.ApplyDept;
                    getApply.ApplyCorp = apply.ApplyCorp;
                    getApply.ApplyDesc = apply.ApplyDesc;
                    result = applyDAL.Update(user, getApply);
                    if (result.ResultStatus != 0)
                        return result;

                    result = pricingApplyDAL.Get(user, pricingApply.PricingApplyId);
                    if (result.ResultStatus != 0)
                        return result;

                    NFMT.DoPrice.Model.PricingApply getPricingApply = result.ReturnValue as NFMT.DoPrice.Model.PricingApply;
                    if (getPricingApply == null || getPricingApply.PricingApplyId <= 0)
                    {
                        result.ResultStatus = -1;
                        result.Message = "获取点价申请错误";
                        return result;
                    }

                    getPricingApply.StartTime = pricingApply.StartTime;
                    getPricingApply.EndTime = pricingApply.EndTime;
                    getPricingApply.MinPrice = pricingApply.MinPrice;
                    getPricingApply.MaxPrice = pricingApply.MaxPrice;
                    getPricingApply.CurrencyId = pricingApply.CurrencyId;
                    getPricingApply.PricingCorpId = pricingApply.PricingCorpId;
                    getPricingApply.PricingWeight = pricingApply.PricingWeight;
                    getPricingApply.MUId = pricingApply.MUId;
                    getPricingApply.AssertId = pricingApply.AssertId;
                    getPricingApply.PricingPersoinId = pricingApply.PricingPersoinId;

                    //验证子合约
                    result = subDAL.Get(user, pricingApply.SubContractId);
                    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.ResultStatus = -1;
                        result.Message = "子合约不存在";
                        return result;
                    }

                    if (sub.SubStatus != StatusEnum.已生效)
                    {
                        result.ResultStatus = -1;
                        result.Message = "子合约状态非已生效,不能进行点价申请";
                        return result;
                    }

                    //获取合约
                    result = contractDAL.Get(user, sub.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.ResultStatus = -1;
                        result.Message = "关联合约不存在";
                        return result;
                    }

                    if (contract.TradeDirection == (int)NFMT.Contract.TradeDirectionEnum.Buy)
                        getPricingApply.PricingDirection = (int)NFMT.DoPrice.PricingDirection.空头;
                    else
                        getPricingApply.PricingDirection = (int)NFMT.DoPrice.PricingDirection.多头;

                    result = pricingApplyDAL.Update(user, getPricingApply);
                    if (result.ResultStatus != 0)
                        return result;

                    //作废明细
                    result = pricingApplyDetailDAL.InvalidAll(user, getPricingApply.PricingApplyId);
                    if (result.ResultStatus != 0)
                        return result;

                    //写入明细
                    foreach (Model.PricingApplyDetail detail in pricingApplyDetails)
                    {
                        detail.PricingApplyId = getPricingApply.PricingApplyId;
                        detail.DetailStatus = StatusEnum.已生效;

                        result = pricingApplyDetailDAL.Insert(user, detail);
                        if (result.ResultStatus != 0)
                            return result;
                    }

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

            return result;
        }
Пример #6
0
        public ResultModel CreateDirectStock(UserModel user, Model.CashInAllot allot, List<Model.CashInCorp> details, int stockLogId)
        {
            ResultModel result = new ResultModel();

            try
            {
                NFMT.WareHouse.DAL.StockLogDAL stockLogDAL = new WareHouse.DAL.StockLogDAL();
                NFMT.WareHouse.DAL.StockDAL stockDAL = new WareHouse.DAL.StockDAL();
                NFMT.Contract.DAL.ContractSubDAL subDAL = new Contract.DAL.ContractSubDAL();
                DAL.CashInAllotDAL allotDAL = new CashInAllotDAL();
                DAL.CashInDAL cashInDAL = new CashInDAL();
                DAL.CashInCorpDAL cashInCorpDAL = new CashInCorpDAL();
                DAL.CashInContractDAL cashInContractDAL = new CashInContractDAL();

                using (System.Transactions.TransactionScope scope = new TransactionScope())
                {
                    //获取库存流水
                    result = stockLogDAL.Get(user, stockLogId);
                    if (result.ResultStatus != 0)
                        return result;

                    NFMT.WareHouse.Model.StockLog stockLog = result.ReturnValue as NFMT.WareHouse.Model.StockLog;
                    if (stockLog == null || stockLog.StockLogId <= 0)
                    {
                        result.Message = "库存流水不存在";
                        result.ResultStatus = -1;
                        return result;
                    }

                    //获取库存
                    result = stockDAL.Get(user, stockLog.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;
                    }

                    //获取子合约
                    result = subDAL.Get(user, stockLog.SubContractId);
                    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;
                    }

                    allot.AllotBala = details.Sum(temp => temp.AllotBala);
                    allot.Alloter = user.EmpId;
                    allot.AllotStatus = StatusEnum.已录入;
                    allot.AllotTime = DateTime.Now;
                    allot.AllotType = (int)NFMT.Funds.CashInAllotTypeEnum.Stock;
                    allot.CurrencyId = sub.SettleCurrency;

                    result = allotDAL.Insert(user, allot);
                    if (result.ResultStatus != 0)
                        return result;

                    int allotId = 0;
                    if (result.ReturnValue == null || !int.TryParse(result.ReturnValue.ToString(), out allotId) || allotId <= 0)
                    {
                        result.Message = "收款分配新增失败";
                        result.ResultStatus = -1;
                        return result;
                    }

                    //获取外部公司
                    NFMT.Contract.DAL.ContractCorporationDetailDAL corpDAL = new Contract.DAL.ContractCorporationDetailDAL();
                    result = corpDAL.LoadCorpListByContractId(user, sub.ContractId, false);
                    if (result.ResultStatus != 0)
                        return result;
                    List<NFMT.Contract.Model.ContractCorporationDetail> outCorps = result.ReturnValue as List<NFMT.Contract.Model.ContractCorporationDetail>;
                    if (outCorps == null)
                    {
                        result.Message = "合约对方抬头获取失败";
                        result.ResultStatus = -1;
                        return result;
                    }

                    foreach (Model.CashInCorp corpDetail in details)
                    {
                        NFMT.User.Model.Corporation corp = NFMT.User.UserProvider.Corporations.FirstOrDefault(temp => temp.CorpId == corpDetail.CorpId);
                        if (corp == null || corp.CorpId <= 0)
                        {
                            result.Message = "收款分配公司不存在";
                            result.ResultStatus = -1;
                            return result;
                        }

                        if (!outCorps.Any(temp => temp.CorpId == corp.CorpId))
                        {
                            result.Message = "收款分配公司不在合约对方抬头,收款分配失败";
                            result.ResultStatus = -1;
                            return result;
                        }

                        result = cashInDAL.Get(user, corpDetail.CashInId);
                        if (result.ResultStatus != 0)
                            return result;

                        Model.CashIn cashIn = result.ReturnValue as Model.CashIn;
                        if (cashIn == null || cashIn.CashInId <= 0)
                        {
                            result.Message = "收款登记不存在";
                            result.ResultStatus = -1;
                            return result;
                        }

                        if (cashIn.CurrencyId != sub.SettleCurrency)
                        {
                            result.Message = "收款登记币种与合约币种不相同";
                            result.ResultStatus = -1;
                            return result;
                        }

                        corpDetail.AllotId = allotId;
                        corpDetail.BlocId = corp.ParentId;
                        corpDetail.CashInId = cashIn.CashInId;
                        corpDetail.CorpId = corp.CorpId;
                        corpDetail.DetailStatus = StatusEnum.已生效;
                        corpDetail.IsShare = false;

                        result = cashInCorpDAL.Insert(user, corpDetail);
                        if (result.ResultStatus != 0)
                            return result;

                        int corpRefId = 0;
                        if (result.ReturnValue == null || !int.TryParse(result.ReturnValue.ToString(), out corpRefId) || corpRefId <= 0)
                        {
                            result.Message = "收款分配新增失败";
                            result.ResultStatus = -1;
                            return result;
                        }

                        Model.CashInContract cashInContract = new CashInContract();
                        cashInContract.AllotBala = corpDetail.AllotBala;
                        cashInContract.AllotId = corpDetail.AllotId;
                        cashInContract.CashInId = corpDetail.CashInId;
                        cashInContract.ContractId = sub.ContractId;
                        cashInContract.CorpRefId = corpRefId;
                        cashInContract.DetailStatus = StatusEnum.已生效;
                        cashInContract.SubContractId = sub.SubId;

                        result = cashInContractDAL.Insert(user, cashInContract);
                        if (result.ResultStatus != 0)
                            return result;

                        int contractRefId = 0;
                        if (result.ReturnValue == null || !int.TryParse(result.ReturnValue.ToString(), out contractRefId) || contractRefId <= 0)
                        {
                            result.Message = "收款分配新增失败";
                            result.ResultStatus = -1;
                            return result;
                        }

                        Model.CashInStcok cashInStock = new CashInStcok();
                        cashInStock.AllotBala = cashInContract.AllotBala;
                        cashInStock.AllotId = cashInContract.AllotId;
                        cashInStock.CashInId = cashInContract.CashInId;
                        cashInStock.ContractRefId = contractRefId;
                        cashInStock.CorpRefId = cashInContract.CorpRefId;
                        cashInStock.DetailStatus = StatusEnum.已生效;
                        cashInStock.StockId = stockLog.StockId;
                        cashInStock.StockLogId = stockLog.StockLogId;
                        cashInStock.StockNameId = stockLog.StockNameId;

                        result = this.cashinstcokDAL.Insert(user, cashInStock);
                        if (result.ResultStatus != 0)
                            return result;
                    }

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

            return result;
        }
Пример #7
0
        public ResultModel CreateStockOutApply(UserModel user, int subId, List<Model.StockOutApplyDetail> details, int deptId, string memo, int corpId, int buyCorpId)
        {
            ResultModel result = new ResultModel();

            NFMT.Operate.DAL.ApplyDAL applyDAL = new Operate.DAL.ApplyDAL();
            NFMT.Contract.DAL.ContractSubDAL subDAL = new Contract.DAL.ContractSubDAL();
            NFMT.WareHouse.DAL.StockOutApplyDAL outApplyDAL = new DAL.StockOutApplyDAL();
            NFMT.WareHouse.DAL.StockOutApplyDetailDAL detailDAL = new DAL.StockOutApplyDetailDAL();
            NFMT.WareHouse.DAL.StockExclusiveDAL exclusiveDAL = new DAL.StockExclusiveDAL();
            NFMT.WareHouse.DAL.StockDAL stockDAL = new StockDAL();
            NFMT.Contract.DAL.ContractDAL contractDAL = new Contract.DAL.ContractDAL();

            try
            {
                using (TransactionScope scope = new TransactionScope(TransactionScopeOption.Required))
                {
                    //验证分配库存
                    if (details == null || details.Count == 0)
                    {
                        result.ResultStatus = -1;
                        result.Message = "未分配任务库存";
                        return result;
                    }

                    //验证子合约
                    result = subDAL.Get(user, 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.ResultStatus = -1;
                        result.Message = "子合约不存在";
                        return result;
                    }

                    //验证合约
                    result = contractDAL.Get(user, sub.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.ResultStatus = -1;
                        result.Message = "合约不存在";
                        return result;
                    }

                    //获取部门信息
                    NFMT.User.Model.Department dept = User.UserProvider.Departments.Single(temp => temp.DeptId == deptId);
                    if (dept == null || dept.DeptId <= 0)
                    {
                        result.ResultStatus = -1;
                        result.Message = "部门不存在";
                        return result;
                    }

                    //添加主申请表
                    NFMT.Operate.Model.Apply apply = new Operate.Model.Apply();
                    apply.ApplyDept = deptId;
                    apply.ApplyCorp = corpId;
                    apply.ApplyTime = DateTime.Now;
                    apply.ApplyDesc = memo;
                    apply.ApplyType = NFMT.Operate.ApplyType.出库申请;
                    apply.EmpId = user.EmpId;
                    apply.ApplyStatus = Common.StatusEnum.已录入;

                    result = applyDAL.Insert(user, apply);
                    if (result.ResultStatus != 0)
                        return result;

                    int applyId = 0;
                    if (result.ReturnValue == null || !int.TryParse(result.ReturnValue.ToString(), out applyId) || applyId <= 0)
                    {
                        result.ResultStatus = -1;
                        result.Message = "申请主表添加失败";
                        return result;
                    }

                    decimal sumGrossAmount = details.Sum(temp => temp.GrossAmount);
                    decimal sumNetAmount = details.Sum(temp => temp.NetAmount);
                    int sumBundles = details.Sum(temp => temp.Bundles);

                    //添加出库申请主表
                    NFMT.WareHouse.Model.StockOutApply outApply = new StockOutApply();
                    outApply.ApplyId = applyId;
                    outApply.ContractId = sub.ContractId;
                    outApply.SubContractId = sub.SubId;
                    outApply.GrossAmount = sumGrossAmount;
                    outApply.NetAmount = sumNetAmount;
                    outApply.Bundles = sumBundles;
                    outApply.UnitId = sub.UnitId;
                    outApply.BuyCorpId = buyCorpId;

                    result = outApplyDAL.Insert(user, outApply);

                    if (result.ResultStatus != 0)
                        return result;

                    int outApplyId = 0;
                    if (result.ReturnValue == null || !int.TryParse(result.ReturnValue.ToString(), out outApplyId) || outApplyId <= 0)
                    {
                        result.ResultStatus = -1;
                        result.Message = "出库申请添加失败";
                        return result;
                    }

                    foreach (Model.StockOutApplyDetail applyDetail in details)
                    {
                        //验证库存
                        result = stockDAL.Get(user, applyDetail.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.ResultStatus = -1;
                            result.Message = "库存不存在";
                            return result;
                        }

                        //判断库存品种是否与合约品种相同
                        if (stock.AssetId != contract.AssetId)
                        {
                            result.ResultStatus = -1;
                            result.Message = "分配库存的品种与合约品种不一致";
                            return result;
                        }

                        //不允许配货库存
                        int planStockInStatus = (int)NFMT.WareHouse.StockStatusEnum.预入库存;
                        int planCustomsStatus = (int)NFMT.WareHouse.StockStatusEnum.预报关库存;
                        int stockStatus = (int)stock.StockStatus;
                        if (stockStatus > planCustomsStatus || stockStatus < planStockInStatus)
                        {
                            result.ResultStatus = -1;
                            result.Message = "访笔库存不能进行出库申请分配";
                            return result;
                        }

                        applyDetail.ContractId = sub.ContractId;
                        applyDetail.DetailStatus = StatusEnum.已生效;
                        applyDetail.SubContractId = sub.SubId;
                        applyDetail.StockOutApplyId = outApplyId;

                        if (contract.TradeBorder == (int)NFMT.Contract.TradeBorderEnum.ForeignTrade)
                            applyDetail.GrossAmount = stock.GrossAmount;
                        else
                            applyDetail.GrossAmount = applyDetail.NetAmount;

                        result = detailDAL.Insert(user, applyDetail);
                        if (result.ResultStatus != 0)
                            return result;

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

                        //排他表校验
                        result = exclusiveDAL.LoadByStockId(user, stock.StockId);
                        if (result.ResultStatus != 0)
                            return result;

                        List<Model.StockExclusive> excs = result.ReturnValue as List<Model.StockExclusive>;
                        if (excs == null)
                        {
                            result.ResultStatus = -1;
                            result.Message = "获取排他库存信息失败";
                            return result;
                        }

                        decimal excAmount = excs.Sum(temp => temp.ExclusiveAmount);
                        if (excAmount >= stock.CurNetAmount)
                        {
                            result.ResultStatus = -1;
                            result.Message = "该笔库存剩余净重不足,配货失败";
                            return result;
                        }

                        //排他表新增
                        NFMT.WareHouse.Model.StockExclusive exculsive = new StockExclusive();
                        exculsive.ApplyId = applyId;
                        exculsive.DetailApplyId = detailApplyId;
                        exculsive.ExclusiveStatus = StatusEnum.已生效;
                        exculsive.StockApplyId = outApplyId;
                        exculsive.StockId = stock.StockId;
                        exculsive.ExclusiveAmount = applyDetail.NetAmount;

                        result = exclusiveDAL.Insert(user, exculsive);
                        if (result.ResultStatus != 0)
                            return result;
                    }

                    //验证出库申请与子合约签订数量
                    if (sumNetAmount > sub.SignAmount)
                    {
                        result.ResultStatus = -1;
                        result.Message = "出库申请数量不能大于子合约签订数量";
                        return result;
                    }

                    //获取当前子合约下所有出库申请明细
                    result = detailDAL.LoadBySubId(user, sub.SubId, NFMT.Common.StatusEnum.已生效);
                    if (result.ResultStatus != 0)
                        return result;

                    List<Model.StockOutApplyDetail> ds = result.ReturnValue as List<Model.StockOutApplyDetail>;
                    sumNetAmount = ds.Sum(temp => temp.NetAmount);

                    if (sumNetAmount > sub.SignAmount)
                    {
                        result.ResultStatus = -1;
                        result.Message = "出库申请数量不能大于子合约可分配数量";
                        return result;
                    }

                    scope.Complete();
                }
            }
            catch (Exception ex)
            {
                result.ResultStatus = -1;
                result.Message = ex.Message;
            }
            finally
            {
                if (result.ResultStatus != 0)
                    log.ErrorFormat("{0} {1},序号:{2}", user.EmpName, result.Message, result.ReturnValue);
                else if (log.IsInfoEnabled)
                    log.InfoFormat("{0} {1},序号:{2}", user.EmpName, result.Message, result.ReturnValue);
            }

            return result;
        }
Пример #8
0
        public ResultModel Create(UserModel user, NFMT.Operate.Model.Apply apply, NFMT.DoPrice.Model.PricingApply pricingApply, List<NFMT.DoPrice.Model.PricingApplyDetail> pricingApplyDetails)
        {
            ResultModel result = new ResultModel();
            NFMT.Operate.DAL.ApplyDAL applyDAL = new Operate.DAL.ApplyDAL();
            DAL.PricingApplyDAL pricingApplyDAL = new PricingApplyDAL();
            DAL.PricingApplyDetailDAL pricingApplyDetailDAL = new PricingApplyDetailDAL();
            NFMT.Contract.DAL.ContractSubDAL subDAL = new Contract.DAL.ContractSubDAL();
            NFMT.Contract.DAL.ContractDAL contractDAL = new Contract.DAL.ContractDAL();
            try
            {
                using (TransactionScope scope = new TransactionScope(TransactionScopeOption.Required))
                {
                    NFMT.User.Model.Department dept = NFMT.User.UserProvider.Departments.FirstOrDefault(temp => temp.DeptId == apply.ApplyDept);
                    if (dept == null || dept.DeptId <= 0)
                    {
                        result.ResultStatus = -1;
                        result.Message = "申请部门不存在";
                        return result;
                    }

                    //新增主申请
                    apply.EmpId = user.EmpId;
                    apply.ApplyTime = DateTime.Now;
                    apply.ApplyType = NFMT.Operate.ApplyType.PricingApply;
                    apply.ApplyDept = dept.DeptId;
                    result = applyDAL.Insert(user, apply);
                    if (result.ResultStatus != 0)
                        return result;
                    int applyId = (int)result.ReturnValue;
                    pricingApply.ApplyId = applyId;

                    //验证子合约
                    result = subDAL.Get(user, pricingApply.SubContractId);
                    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.ResultStatus = -1;
                        result.Message = "子合约不存在";
                        return result;
                    }

                    if (sub.SubStatus != StatusEnum.已生效)
                    {
                        result.ResultStatus = -1;
                        result.Message = "子合约状态非已生效,不能进行点价申请";
                        return result;
                    }

                    //decimal missRate = Convert.ToDecimal(0.05);
                    //if (pricingApply.PricingWeight > sub.SignAmount)
                    //{
                    //    result.ResultStatus = -1;
                    //    result.Message = "点价重量超过子合约签订数量";
                    //    return result;
                    //}

                    //获取合约
                    result = contractDAL.Get(user, sub.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.ResultStatus = -1;
                        result.Message = "关联合约不存在";
                        return result;
                    }

                    if (contract.TradeDirection == (int)NFMT.Contract.TradeDirectionEnum.Buy)
                        pricingApply.PricingDirection = (int)NFMT.DoPrice.PricingDirection.空头;
                    else
                        pricingApply.PricingDirection = (int)NFMT.DoPrice.PricingDirection.多头;

                    //新增点价申请
                    result = pricingApplyDAL.Insert(user, pricingApply);
                    if (result.ResultStatus != 0)
                        return result;

                    int pricingApplyId = (int)result.ReturnValue;

                    foreach (Model.PricingApplyDetail detail in pricingApplyDetails)
                    {
                        detail.PricingApplyId = pricingApplyId;
                        detail.DetailStatus = StatusEnum.已生效;
                        result = pricingApplyDetailDAL.Insert(user, detail);
                        if (result.ResultStatus != 0)
                            return result;
                    }

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

            return result;
        }
Пример #9
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;
        }
Пример #10
0
        public ResultModel Update(UserModel user, int subId, int refId)
        {
            ResultModel result = new ResultModel();

            try
            {
                DAL.StockInDAL stockInDAL = new StockInDAL();
                NFMT.Contract.DAL.ContractSubDAL subDAL = new Contract.DAL.ContractSubDAL();

                using (System.Transactions.TransactionScope scope = new TransactionScope())
                {
                    //验证子合约
                    result = subDAL.Get(user, 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.ResultStatus = -1;
                        result.Message = "子合约不存在";
                        return result;
                    }

                    //验证入库分配
                    result = this.contractstockin_DAL.Get(user, refId);
                    if (result.ResultStatus != 0)
                        return result;

                    Model.ContractStockIn contractStockIn = result.ReturnValue as Model.ContractStockIn;
                    if (contractStockIn == null || contractStockIn.StockInId <= 0)
                    {
                        result.ResultStatus = -1;
                        result.Message = "入库分配不存在";
                        return result;
                    }

                    //获取入库登记
                    result = stockInDAL.Get(user, contractStockIn.StockInId);
                    if (result.ResultStatus != 0)
                        return result;

                    Model.StockIn stockIn = result.ReturnValue as Model.StockIn;
                    if (stockIn == null || stockIn.StockInId <= 0)
                    {
                        result.ResultStatus = -1;
                        result.Message = "入库登记不存在";
                        return result;
                    }

                    //更新入库分配
                    contractStockIn.ContractSubId = sub.SubId;
                    contractStockIn.ContractId = sub.ContractId;

                    result = this.contractstockin_DAL.Update(user, contractStockIn);
                    if (result.ResultStatus != 0)
                        return result;

                    //验证子合约下分配入库重量
                    result = stockInDAL.Load(user, subId, StatusEnum.已录入);
                    if (result.ResultStatus != 0)
                        return result;

                    List<Model.StockIn> stockIns = result.ReturnValue as List<Model.StockIn>;
                    if (stockIns == null)
                    {
                        result.ResultStatus = -1;
                        result.Message = "子合约下的入库登记获取失败";
                        return result;
                    }

                    decimal sumAmount = stockIns.Sum(temp => temp.GrossAmount);

                    if (sumAmount > sub.SignAmount)
                    {
                        result.ResultStatus = -1;
                        result.Message = "子合约分配入库超额满额";
                        return result;
                    }

                    scope.Complete();

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

            return result;
        }
Пример #11
0
        public ResultModel CreateDirectContract(UserModel user, CashInAllot allot, List<CashInContractDirect> directs, int subId)
        {
            ResultModel result = new ResultModel();

            try
            {
                NFMT.Contract.DAL.ContractSubDAL subDAL = new Contract.DAL.ContractSubDAL();
                DAL.CashInDAL cashInDAL = new CashInDAL();
                DAL.CashInAllotDAL cashInAllotDAL = new CashInAllotDAL();
                DAL.CashInCorpDAL cashInCorpDAL = new CashInCorpDAL();

                using (System.Transactions.TransactionScope scope = new TransactionScope())
                {
                    //获取子合约
                    result = subDAL.Get(user, 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.ResultStatus = -1;
                        result.Message = "子合约不存在,不能进行收款分配";
                        return result;
                    }

                    //判断合约状态

                    //获取合约对方抬头
                    result = subDAL.GetContractOutCorp(user, sub.SubId);
                    if (result.ResultStatus != 0)
                        return result;

                    DataTable outCorpTable = result.ReturnValue as DataTable;

                    if (outCorpTable == null || outCorpTable.Rows.Count == 0)
                    {
                        result.ResultStatus = -1;
                        result.Message = "合约对方抬头不存在,收款分配失败";
                        return result;
                    }

                    List<int> outCorpIds = new List<int>();
                    foreach (DataRow dr in outCorpTable.Rows)
                    {
                        int outCorpId = 0;
                        if (dr["CorpId"] == DBNull.Value || !int.TryParse(dr["CorpId"].ToString(), out outCorpId) || outCorpId <= 0)
                        {
                            result.ResultStatus = -1;
                            result.Message = "合约对方抬头获取失败";
                            return result;
                        }

                        outCorpIds.Add(outCorpId);
                    }

                    List<Model.CashInCorp> cashCorps = new List<CashInCorp>();

                    foreach (CashInContractDirect direct in directs)
                    {
                        //判断收款分配到的对方抬头是否包含在合约抬头中
                        if (!outCorpIds.Contains(direct.AllotCorpId))
                        {
                            result.ResultStatus = -1;
                            result.Message = "收款分配选择的分配公司不在该合约对方抬头中,收款分配失败";
                            return result;
                        }

                        //判断收款登记的币种是否和合约币种相同
                        result = cashInDAL.Get(user, direct.CashInId);
                        if (result.ResultStatus != 0)
                            return result;
                        Model.CashIn cashIn = result.ReturnValue as Model.CashIn;
                        if (cashIn == null || cashIn.CashInId <= 0)
                        {
                            result.ResultStatus = -1;
                            result.Message = "收款登记不存在";
                            return result;
                        }

                        if (cashIn.CashInStatus != StatusEnum.已生效)
                        {
                            result.ResultStatus = -1;
                            result.Message = "收款登记状态错误,不能进行分配";
                            return result;
                        }

                        if (cashIn.CurrencyId != sub.SettleCurrency)
                        {
                            result.ResultStatus = -1;
                            result.Message = "收款登记币种与合约币种不相同,分配错误";
                            return result;
                        }

                        CashInCorp cashCorp = new CashInCorp();

                        NFMT.User.Model.Corporation corp = NFMT.User.UserProvider.Corporations.FirstOrDefault(temp => temp.CorpId == direct.AllotCorpId);
                        if (corp == null || corp.CorpId <= 0)
                        {
                            result.ResultStatus = -1;
                            result.Message = "收款分配选择的分配公司不存在,分配失败";
                            return result;
                        }

                        cashCorp.AllotBala = direct.AllotBala;
                        cashCorp.BlocId = corp.ParentId;
                        cashCorp.CashInId = direct.CashInId;
                        cashCorp.CorpId = corp.CorpId;
                        cashCorp.DetailStatus = StatusEnum.已生效;
                        cashCorp.IsShare = false;
                        cashCorp.AllotId = 0;

                        cashCorps.Add(cashCorp);

                    }

                    decimal sumBala = directs.Sum(temp => temp.AllotBala);

                    allot.AllotBala = sumBala;
                    allot.Alloter = user.EmpId;
                    allot.AllotStatus = StatusEnum.已录入;
                    allot.AllotTime = DateTime.Now;
                    allot.AllotType = (int)NFMT.Funds.CashInAllotTypeEnum.Contract;
                    allot.CurrencyId = sub.SettleCurrency;

                    //新增主分配
                    result = cashInAllotDAL.Insert(user, allot);
                    if (result.ResultStatus != 0)
                        return result;

                    int allotId = 0;
                    if (result.ReturnValue == null || !int.TryParse(result.ReturnValue.ToString(), out allotId) || allotId <= 0)
                    {
                        result.ResultStatus = -1;
                        result.Message = "收款分配新增失败";
                        return result;
                    }

                    //新增公司收款分配
                    foreach (Model.CashInCorp cd in cashCorps)
                    {
                        cd.AllotId = allotId;
                        result = cashInCorpDAL.Insert(user, cd);
                        if (result.ResultStatus != 0)
                            return result;

                        int refId = 0;
                        if (result.ReturnValue == null || !int.TryParse(result.ReturnValue.ToString(), out refId) || refId <= 0)
                        {
                            result.ResultStatus = -1;
                            result.Message = "公司收款分配新增失败";
                            return result;
                        }

                        CashInContract cashContract = new CashInContract();

                        cashContract.AllotBala = cd.AllotBala;
                        cashContract.AllotId = cd.AllotId;
                        cashContract.CashInId = cd.CashInId;
                        cashContract.ContractId = sub.ContractId;
                        cashContract.CorpRefId = refId;
                        cashContract.DetailStatus = StatusEnum.已生效;
                        cashContract.SubContractId = sub.SubId;

                        result = this.cashincontractDAL.Insert(user, cashContract);
                        if (result.ResultStatus != 0)
                            return result;
                    }

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

            return result;
        }
Пример #12
0
        public ResultModel CreateContract(UserModel user, List<CashInContract> details, int subId)
        {
            ResultModel result = new ResultModel();

            try
            {
                DAL.CashInCorpDAL cashInCorpDAL = new CashInCorpDAL();
                NFMT.Contract.DAL.ContractSubDAL subDAL = new Contract.DAL.ContractSubDAL();

                using (System.Transactions.TransactionScope scope = new TransactionScope())
                {
                    //获取子合约
                    result = subDAL.Get(user, 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.ResultStatus = -1;
                        result.Message = "子合约不存在";
                        return result;
                    }

                    //验证子合约状态

                    foreach (CashInContract detail in details)
                    {
                        //获取公司分配
                        result = cashInCorpDAL.Get(user, detail.CorpRefId);
                        if (result.ResultStatus != 0)
                            return result;

                        Model.CashInCorp cashInCorp = result.ReturnValue as Model.CashInCorp;
                        if (cashInCorp == null || cashInCorp.RefId <= 0)
                        {
                            result.ResultStatus = -1;
                            result.Message = "公司款不存在";
                            return result;
                        }

                        if (cashInCorp.DetailStatus != StatusEnum.已生效)
                        {
                            result.ResultStatus = -1;
                            result.Message = "公司款状态错误,分配失败";
                            return result;
                        }

                        detail.AllotId = cashInCorp.AllotId;
                        detail.CashInId = cashInCorp.CashInId;
                        detail.ContractId = sub.ContractId;
                        detail.CorpRefId = cashInCorp.RefId;
                        detail.DetailStatus = StatusEnum.已生效;
                        detail.SubContractId = sub.SubId;

                        result = cashincontractDAL.Insert(user, detail);
                        if (result.ResultStatus != 0)
                            return result;
                    }

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

            return result;
        }
Пример #13
0
        public ResultModel UpdateContract(UserModel user, List<CashInContract> details, int subId)
        {
            ResultModel result = new ResultModel();

            try
            {
                DAL.CashInDAL cashInDAL = new CashInDAL();
                DAL.CashInAllotDAL cashInAllotDAL = new CashInAllotDAL();
                DAL.CashInCorpDAL cashInCorpDAL = new CashInCorpDAL();
                NFMT.Contract.DAL.ContractSubDAL subDAL = new Contract.DAL.ContractSubDAL();
                DAL.CashInStcokDAL cashInStockDAL = new CashInStcokDAL();

                using (System.Transactions.TransactionScope scope = new TransactionScope())
                {
                    //获取子合约
                    result = subDAL.Get(user, 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;
                    }

                    //获取当前合约下的有效明细
                    result = this.cashincontractDAL.Load(user, sub.SubId);
                    if (result.ResultStatus != 0)
                        return result;

                    List<Model.CashInContract> resultDetails = result.ReturnValue as List<Model.CashInContract>;

                    if (resultDetails == null)
                    {
                        result.Message = "获取明细失败";
                        result.ResultStatus = -1;
                        return result;
                    }

                    //作废现有有效明细
                    foreach (Model.CashInContract nd in resultDetails)
                    {
                        //验证当前合约明细是否已分配至库存中
                        result = cashInStockDAL.LoadByContractRefId(user, nd.RefId);
                        if (result.ResultStatus != 0)
                            return result;

                        List<Model.CashInStcok> stocks = result.ReturnValue as List<Model.CashInStcok>;
                        if (stocks != null && stocks.Count > 0)
                        {
                            result.Message = "合约款已全部或部分配款至库存,不能进行修改";
                            result.ResultStatus = -1;
                            return result;
                        }

                        if (nd.DetailStatus == StatusEnum.已生效)
                            nd.DetailStatus = StatusEnum.已录入;

                        result = this.cashincontractDAL.Invalid(user, nd);
                        if (result.ResultStatus != 0)
                            return result;
                    }

                    //新增明细
                    foreach (Model.CashInContract det in details)
                    {
                        //获取公司分配
                        result = cashInCorpDAL.Get(user, det.CorpRefId);
                        if (result.ResultStatus != 0)
                            return result;

                        Model.CashInCorp cashInCrop = result.ReturnValue as Model.CashInCorp;
                        if (cashInCrop == null || cashInCrop.RefId <= 0)
                        {
                            result.Message = "修改失败";
                            result.ResultStatus = -1;
                            return result;
                        }

                        //获取分配
                        result = cashInAllotDAL.Get(user, cashInCrop.AllotId);
                        if (result.ResultStatus != 0)
                            return result;

                        NFMT.Funds.Model.CashInAllot allot = result.ReturnValue as NFMT.Funds.Model.CashInAllot;
                        if (allot == null || allot.AllotId <= 0)
                        {
                            result.Message = "收款分配不存在,不能进行修改";
                            result.ResultStatus = -1;
                            return result;
                        }

                        //获取收款登记
                        result = cashInDAL.Get(user, cashInCrop.CashInId);
                        if (result.ResultStatus != 0)
                            return result;

                        Model.CashIn cashIn = result.ReturnValue as Model.CashIn;
                        if (cashIn == null || cashIn.CashInId <= 0)
                        {
                            result.Message = "修改失败";
                            result.ResultStatus = -1;
                            return result;
                        }

                        if (cashIn.CurrencyId != sub.SettleCurrency)
                        {
                            result.Message = "修改失败";
                            result.ResultStatus = -1;
                            return result;
                        }

                        det.AllotId = cashInCrop.AllotId;
                        det.CorpRefId = cashInCrop.RefId;
                        det.ContractId = sub.ContractId;
                        det.CashInId = cashIn.CashInId;
                        det.CorpRefId = cashInCrop.RefId;
                        det.DetailStatus = StatusEnum.已生效;
                        det.SubContractId = sub.SubId;

                        result = this.cashincontractDAL.Insert(user, det);

                        if (result.ResultStatus != 0)
                            return result;
                    }

                    scope.Complete();
                }

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

            return result;
        }