예제 #1
0
        public ResultModel ContractInCompleteStockOperate(UserModel user, int contractId)
        {
            ResultModel result = new ResultModel();
            StockInDAL stockInDAL = new StockInDAL();
            StockLogDAL stockLogDAL = new StockLogDAL();
            StockDAL stockDAL = new StockDAL();
            ContractStockInDAL contractStockInDAL = new ContractStockInDAL();
            StockInStockDAL stockInStockDAL = new StockInStockDAL();

            result = contractStockInDAL.Load(user, contractId);
            if (result.ResultStatus != 0)
                return result;

            List<NFMT.WareHouse.Model.ContractStockIn> contractStockIns = result.ReturnValue as List<NFMT.WareHouse.Model.ContractStockIn>;
            if (contractStockIns == null)
            {
                result.Message = "合约入库分配获取失败";
                result.ResultStatus = -1;
                return result;
            }

            foreach (NFMT.WareHouse.Model.ContractStockIn contractStcokIn in contractStockIns)
            {
                //获取入库登记
                result = stockInDAL.Get(user, contractStcokIn.StockInId);
                if (result.ResultStatus != 0)
                    return result;

                NFMT.WareHouse.Model.StockIn stockIn = result.ReturnValue as NFMT.WareHouse.Model.StockIn;
                if (stockIn == null || stockIn.StockInId <= 0)
                {
                    result.ResultStatus = -1;
                    result.Message = "数据不存在,无法完成";
                    return result;
                }

                //入库登记完成
                if (stockIn.StockInStatus == StatusEnum.已生效)
                {
                    result = stockInDAL.Complete(user, stockIn);
                    if (result.ResultStatus != 0)
                        return result;
                }

                //获取合约关联
                result = contractStockInDAL.GetByStockInId(user, stockIn.StockInId);
                if (result.ResultStatus != 0)
                    return result;

                NFMT.WareHouse.Model.ContractStockIn contractStockIn = result.ReturnValue as NFMT.WareHouse.Model.ContractStockIn;
                if (contractStockIn == null || contractStockIn.RefId <= 0)
                {
                    result.ResultStatus = -1;
                    result.Message = "入库登记未关联合约,不允许确认完成";
                    return result;
                }

                //完成合约关联
                if (contractStockIn.RefStatus == StatusEnum.已生效)
                {
                    result = contractStockInDAL.Complete(user, contractStockIn);
                    if (result.ResultStatus != 0)
                        return result;
                }

                //获取入库登记库存关联
                result = stockInStockDAL.GetByStockIn(NFMT.Common.DefaultValue.SysUser, stockIn.StockInId);
                if (result.ResultStatus != 0)
                    return result;

                NFMT.WareHouse.Model.StockInStock stockInStock = result.ReturnValue as NFMT.WareHouse.Model.StockInStock;
                if (stockInStock == null || stockInStock.RefId <= 0)
                {
                    result.ResultStatus = -1;
                    result.Message = "获取入库登记与库存关联失败";
                    return result;
                }

                //完成入库登记库存关联
                if (stockInStock.RefStatus == StatusEnum.已生效)
                {
                    result = stockInStockDAL.Complete(user, stockInStock);
                    if (result.ResultStatus != 0)
                        return result;
                }

                //获取库存流水
                result = stockLogDAL.Get(user, stockInStock.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;
                }

                //判断库存流水是否关联合约
                if (stockLog.ContractId <= 0)
                {
                    stockLog.ContractId = contractStockIn.ContractId;
                    stockLog.SubContractId = contractStockIn.ContractSubId;

                    result = stockLogDAL.Update(user, stockLog);
                    if (result.ResultStatus != 0)
                        return result;
                }

                if (stockLog.LogStatus == StatusEnum.已生效)
                {
                    result = stockLogDAL.Complete(user, stockLog);
                    if (result.ResultStatus != 0)
                        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.ResultStatus = -1;
                    result.Message = "库存获取失败";
                    return result;
                }

                //更新库存表
                if (stock.StockStatus == NFMT.WareHouse.StockStatusEnum.预入库存)
                {
                    result = stockDAL.UpdateStockStatus(stock, NFMT.WareHouse.StockStatusEnum.在库正常);
                    if (result.ResultStatus != 0)
                        return result;
                }
            }

            return result;
        }
예제 #2
0
        public ResultModel Close(UserModel user, int customId)
        {
            ResultModel result = new ResultModel();

            try
            {
                using (System.Transactions.TransactionScope scope = new TransactionScope())
                {
                    //获取报关
                    result = this.customsclearanceDAL.Get(user, customId);
                    if (result.ResultStatus != 0)
                        return result;

                    Model.CustomsClearance customsClearance = result.ReturnValue as Model.CustomsClearance;
                    if (customsClearance == null || customsClearance.CustomsId <= 0)
                    {
                        result.ResultStatus = -1;
                        result.Message = "报关不存在";
                        return result;
                    }

                    //报关关闭
                    result = this.customsclearanceDAL.Close(user, customsClearance);
                    if (result.ResultStatus != 0)
                        return result;

                    //获取所有已完成的明细
                    DAL.CustomsDetailDAL customsDetailDAL = new CustomsDetailDAL();
                    result = customsDetailDAL.Load(user, customId, StatusEnum.已生效);
                    if (result.ResultStatus != 0)
                        return result;

                    List<Model.CustomsDetail> details = result.ReturnValue as List<Model.CustomsDetail>;
                    if (details == null || !details.Any())
                    {
                        result.ResultStatus = -1;
                        result.Message = "获取失败";
                        return result;
                    }

                    DAL.StockLogDAL stockLogDAL = new StockLogDAL();
                    DAL.StockDAL stockDAL = new StockDAL();

                    foreach (Model.CustomsDetail detail in details)
                    {
                        //明细关闭
                        result = customsDetailDAL.Close(user, detail);
                        if (result.ResultStatus != 0)
                            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;
                        }

                        //完成报关流水
                        result = stockLogDAL.Close(user, stockLog);
                        if (result.ResultStatus != 0)
                            return result;

                        //获取库存
                        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 = stockDAL.UpdateStockStatusDirect(stock, StockStatusEnum.在库正常);
                        if (result.ResultStatus != 0)
                            return result;
                    }

                    scope.Complete();
                }

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

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

            try
            {
                using (System.Transactions.TransactionScope scope = new TransactionScope())
                {
                    result = this.customsclearanceDAL.Get(user, customId);
                    if (result.ResultStatus != 0)
                        return result;

                    Model.CustomsClearance customsClearance = result.ReturnValue as CustomsClearance;
                    if (customsClearance == null)
                    {
                        result.Message = "该数据不存在,不能完成";
                        result.ResultStatus = -1;
                        return result;
                    }

                    result = customsclearanceDAL.CompleteCancel(user, customsClearance);
                    if (result.ResultStatus != 0)
                        return result;

                    //获取所有已生效的明细
                    DAL.CustomsDetailDAL customsDetailDAL = new CustomsDetailDAL();
                    result = customsDetailDAL.Load(user, customId, StatusEnum.已完成);
                    if (result.ResultStatus != 0)
                        return result;

                    List<Model.CustomsDetail> details = result.ReturnValue as List<Model.CustomsDetail>;
                    if (details == null || !details.Any())
                    {
                        result.ResultStatus = -1;
                        result.Message = "获取失败";
                        return result;
                    }

                    DAL.StockLogDAL stockLogDAL = new StockLogDAL();
                    DAL.StockDAL stockDAL = new StockDAL();

                    foreach (Model.CustomsDetail detail in details)
                    {
                        //明细完成
                        result = customsDetailDAL.CompleteCancel(user, detail);
                        if (result.ResultStatus != 0)
                            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;
                        }

                        //完成报关流水
                        result = stockLogDAL.CompleteCancel(user, stockLog);
                        if (result.ResultStatus != 0)
                            return result;

                        //获取库存
                        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;
                        }

                        stock.StockStatus = StockStatusEnum.预报关库存;
                        stock.CustomsType = NFMT.Data.DetailProvider.Details(Data.StyleEnum.CustomType)["OutsideCustom"].StyleDetailId;//关外
                        result = stockDAL.Update(user, stock);
                        if (result.ResultStatus != 0)
                            return result;
                    }

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

            return result;
        }
예제 #4
0
        public ResultModel Update(UserModel user, int repoApplyId, List<int> stockIds, string memo, int deptId)
        {
            ResultModel result = new ResultModel();

            //获取质押申请
            try
            {
                DAL.StockDAL stockDAL = new StockDAL();
                DAL.RepoApplyDetailDAL detailDAL = new RepoApplyDetailDAL();
                NFMT.Operate.DAL.ApplyDAL applyDAL = new Operate.DAL.ApplyDAL();

                using (System.Transactions.TransactionScope scope = new TransactionScope(TransactionScopeOption.Required))
                {
                    //验证质押申请
                    result = repoapplyDAL.Get(user, repoApplyId);
                    if (result.ResultStatus != 0)
                        return result;

                    Model.RepoApply repoApply = result.ReturnValue as Model.RepoApply;
                    if (repoApply == null || repoApply.RepoApplyId <= 0)
                    {
                        result.ResultStatus = -1;
                        result.Message = "质押申请获取失败";
                        return result;
                    }

                    //获取主申请
                    result = applyDAL.Get(user, repoApply.ApplyId);
                    if (result.ResultStatus != 0)
                        return result;

                    NFMT.Operate.Model.Apply apply = result.ReturnValue as NFMT.Operate.Model.Apply;
                    if (apply == null || apply.ApplyId <= 0)
                    {
                        result.ResultStatus = -1;
                        result.Message = "主申请获取失败";
                        return result;
                    }

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

                    apply.ApplyDesc = memo;
                    apply.ApplyDept = dept.DeptId;
                    //apply.ApplyDeptName = dept.DeptName;
                    result = applyDAL.Update(user, apply);
                    if (result.ResultStatus != 0)
                        return result;

                    //获了质押申请明细
                    result = detailDAL.Load(user, repoApply.RepoApplyId);
                    if (result.ResultStatus != 0)
                        return result;
                    List<Model.RepoApplyDetail> details = result.ReturnValue as List<Model.RepoApplyDetail>;
                    if (details == null)
                    {
                        result.ResultStatus = -1;
                        result.Message = "明细获取失败";
                        return result;
                    }

                    //作废明细
                    foreach (Model.RepoApplyDetail detail in details)
                    {
                        if (detail.DetailStatus == StatusEnum.已生效)
                            detail.DetailStatus = StatusEnum.已录入;
                        result = detailDAL.Invalid(user, detail);
                        if (result.ResultStatus != 0)
                            return result;
                    }

                    //获取库存
                    foreach (int stockId in stockIds)
                    {
                        result = stockDAL.Get(user, 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;
                        }

                        if (stock.StockStatus != StockStatusEnum.质押库存)
                        {
                            result.ResultStatus = -1;
                            result.Message = "库存非质押状态,不能进行回购操作";
                            return result;
                        }

                        //添加明细
                        Model.RepoApplyDetail detail = new RepoApplyDetail();
                        detail.DetailStatus = StatusEnum.已生效;
                        detail.RepoApplyId = repoApply.RepoApplyId;
                        detail.StockId = stock.StockId;
                        result = detailDAL.Insert(user, detail);
                        if (result.ResultStatus != 0)
                            return result;
                    }

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

            return result;
        }
예제 #5
0
파일: StockInBLL.cs 프로젝트: weiliji/NFMT
        public ResultModel Complete(UserModel user, int stockInId)
        {
            //总体业务描述
            //1:验证入库登记
            //2:完成入库登记
            //3:完成入库登记与合约关联
            //4:完成库存流水与入库登记合约关联
            //5:更新库存流水状态为已完成
            //6:更新库存状态为在库正常

            ResultModel result = new ResultModel();

            try
            {
                DAL.StockInStockDAL stockInStockDAL = new StockInStockDAL();
                DAL.ContractStockInDAL contractStockInDAL = new ContractStockInDAL();
                NFMT.WareHouse.DAL.StockDAL stockDAL = new StockDAL();
                DAL.StockLogDAL stockLogDAL = new StockLogDAL();

                using (TransactionScope scope = new TransactionScope(TransactionScopeOption.Required))
                {
                    result = stockinDAL.Get(user, 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;
                    }

                    //入库登记完成
                    result = stockinDAL.Complete(user, stockIn);
                    if (result.ResultStatus != 0)
                        return result;

                    //获取合约关联
                    result = contractStockInDAL.GetByStockInId(user, stockIn.StockInId);
                    if (result.ResultStatus != 0)
                        return result;

                    Model.ContractStockIn contractStockIn = result.ReturnValue as Model.ContractStockIn;
                    if (contractStockIn == null || contractStockIn.RefId <= 0)
                    {
                        result.ResultStatus = -1;
                        result.Message = "入库登记未关联合约,不允许确认完成";
                        return result;
                    }

                    //完成合约关联
                    result = contractStockInDAL.Complete(user, contractStockIn);
                    if (result.ResultStatus != 0)
                        return result;

                    //获取入库登记库存关联
                    result = stockInStockDAL.GetByStockIn(NFMT.Common.DefaultValue.SysUser, stockIn.StockInId);

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

                    Model.StockInStock stockInStock = result.ReturnValue as Model.StockInStock;
                    if (stockInStock == null || stockInStock.RefId <= 0)
                    {
                        result.ResultStatus = -1;
                        result.Message = "获取入库登记与库存关联失败";
                        return result;
                    }

                    //完成入库登记库存关联
                    result = stockInStockDAL.Complete(user, stockInStock);
                    if (result.ResultStatus != 0)
                        return result;

                    //获取库存流水
                    result = stockLogDAL.Get(user, stockInStock.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.ContractId <= 0)
                    {
                        stockLog.ContractId = contractStockIn.ContractId;
                        stockLog.SubContractId = contractStockIn.ContractSubId;

                        result = stockLogDAL.Update(user, stockLog);
                        if (result.ResultStatus != 0)
                            return result;
                    }

                    result = stockLogDAL.Complete(user, stockLog);
                    if (result.ResultStatus != 0)
                        return result;

                    //获取库存
                    result = stockDAL.Get(user, stockLog.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 = stockDAL.UpdateStockStatus(stock, StockStatusEnum.在库正常);
                    if (result.ResultStatus != 0)
                        return result;

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

            return result;
        }
예제 #6
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;
        }
예제 #7
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;
        }
예제 #8
0
        public ResultModel ContractOutCreateStockOperate(UserModel user, NFMT.Contract.Model.Contract contract, int subId, int outCorpId, List<NFMT.WareHouse.Model.StockOutApplyDetail> details)
        {
            ResultModel result = new ResultModel();

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

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

                //添加主申请表
                NFMT.Operate.Model.Apply apply = new NFMT.Operate.Model.Apply();
                apply.ApplyDept = user.DeptId;
                apply.ApplyCorp = user.CorpId;
                apply.ApplyTime = DateTime.Now;
                apply.ApplyDesc = string.Empty;
                apply.ApplyType = NFMT.Operate.ApplyType.出库申请;
                apply.EmpId = user.EmpId;
                apply.ApplyStatus = NFMT.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 sumNetAmount = details.Sum(temp => temp.NetAmount);
                int sumBundles = details.Sum(temp => temp.Bundles);

                //添加出库申请主表
                NFMT.WareHouse.Model.StockOutApply outApply = new NFMT.WareHouse.Model.StockOutApply();
                outApply.ApplyId = applyId;
                outApply.ContractId = contract.ContractId;
                outApply.SubContractId = subId;
                outApply.NetAmount = sumNetAmount;
                outApply.Bundles = sumBundles;
                outApply.UnitId = contract.UnitId;
                outApply.BuyCorpId = outCorpId;

                foreach (NFMT.WareHouse.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;
                    }

                    //验证关境
                    if (contract.TradeBorder == (int)NFMT.Contract.TradeBorderEnum.外贸 && stock.CustomsType != (int)NFMT.WareHouse.CustomTypeEnum.关外)
                    {
                        result.ResultStatus = -1;
                        result.Message = "库存关境与合约不一致";
                        return result;
                    }
                    else if (contract.TradeBorder == (int)NFMT.Contract.TradeBorderEnum.内贸 && stock.CustomsType != (int)NFMT.WareHouse.CustomTypeEnum.关内)
                    {
                        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 = contract.ContractId;
                    applyDetail.DetailStatus = StatusEnum.已生效;
                    applyDetail.SubContractId = subId;

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

                decimal sumGrossAmount = details.Sum(temp => temp.GrossAmount);
                outApply.GrossAmount = sumGrossAmount;
                outApply.CreateFrom = (int)NFMT.Common.CreateFromEnum.销售合约库存创建;
                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 (NFMT.WareHouse.Model.StockOutApplyDetail applyDetail in details)
                {
                    NFMT.WareHouse.Model.StockOutApplyDetail appDetail = new NFMT.WareHouse.Model.StockOutApplyDetail();
                    appDetail.StockOutApplyId = outApplyId;
                    appDetail.Bundles = applyDetail.Bundles;
                    appDetail.ContractId = applyDetail.ContractId;
                    appDetail.DetailStatus = StatusEnum.已生效;
                    appDetail.GrossAmount = applyDetail.GrossAmount;
                    appDetail.NetAmount = applyDetail.NetAmount;
                    appDetail.StockId = applyDetail.StockId;
                    appDetail.SubContractId = applyDetail.SubContractId;

                    result = detailDAL.Insert(user, appDetail);
                    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 = 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;
                    }

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

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

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

                    //排他表新增
                    NFMT.WareHouse.Model.StockExclusive exculsive = new NFMT.WareHouse.Model.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;
                }
            }
            catch (Exception ex)
            {
                result.ResultStatus = -1;
                result.Message = ex.Message;
            }

            return result;
        }
예제 #9
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;
        }
예제 #10
0
파일: PledgeBLL.cs 프로젝트: weiliji/NFMT
        /// <summary>
        /// 数据撤返
        /// </summary>
        /// <param name="user">当前操作用户</param>
        /// <param name="pledge">Pledge对象</param>
        /// <returns></returns>
        public ResultModel GoBack(UserModel user, int pledgeId)
        {
            ResultModel result = new ResultModel();

            try
            {
                using (TransactionScope scope = new TransactionScope(TransactionScopeOption.Required))
                {
                    result = this.Get(user, pledgeId);
                    if (result.ResultStatus != 0)
                        return result;
                    Model.Pledge pledge = result.ReturnValue as Pledge;

                    if (pledge == null)
                    {
                        result.ResultStatus = -1;
                        result.Message = "该数据不存在,不能撤返";
                        return result;
                    }

                    if (pledge.Status != StatusEnum.待审核 && pledge.Status != StatusEnum.已生效)
                    {
                        result.ResultStatus = -1;
                        result.Message = "非待审核或已生效状态的数据不允许撤返";
                        return result;
                    }

                    //获取质押申请实体
                    DAL.PledgeApplyDAL pledgeApplyDAL = new PledgeApplyDAL();
                    result = pledgeApplyDAL.Get(user, pledge.PledgeApplyId);
                    if (result.ResultStatus != 0)
                        return result;

                    Model.PledgeApply pledgeApply = result.ReturnValue as Model.PledgeApply;

                    //获取申请实体
                    NFMT.Operate.DAL.ApplyDAL applyDAl = new Operate.DAL.ApplyDAL();
                    result = applyDAl.Get(user, pledgeApply.ApplyId);
                    if (result.ResultStatus != 0)
                        return result;

                    NFMT.Operate.Model.Apply apply = result.ReturnValue as NFMT.Operate.Model.Apply;
                    if (apply.Status == Common.StatusEnum.已关闭 || apply.Status == Common.StatusEnum.已完成)
                    {
                        result.ResultStatus = -1;
                        result.Message = "质押对应的申请已完成或已关闭,不能进行撤返操作";
                        return result;
                    }

                    result = pledgeDAL.Goback(user, pledge);
                    if (result.ResultStatus != 0)
                        return result;

                    if (pledge.Status == StatusEnum.待审核)
                    {
                        //同步工作流状态
                        NFMT.WorkFlow.BLL.DataSourceBLL dataSourceBLL = new WorkFlow.BLL.DataSourceBLL();
                        result = dataSourceBLL.SynchronousStatus(user, pledge);
                        if (result.ResultStatus != 0)
                            return result;
                    }

                    NFMT.WareHouse.DAL.PledgeDetialDAL pledgeDetialDAL = new DAL.PledgeDetialDAL();
                    result = pledgeDetialDAL.GetStockId(user, pledgeId);
                    if (result.ResultStatus != 0)
                        return result;

                    if (!string.IsNullOrEmpty(result.ReturnValue.ToString()))
                    {
                        NFMT.WareHouse.DAL.StockDAL stockDAL = new StockDAL();
                        NFMT.WareHouse.DAL.StockNameDAL stockNameDAL = new StockNameDAL();
                        NFMT.WareHouse.DAL.StockLogDAL stockLogDAL = new StockLogDAL();

                        NFMT.WareHouse.Model.StockName stockName = new StockName();
                        NFMT.WareHouse.Model.Stock stock = new Stock();
                        NFMT.WareHouse.Model.StockLog stockLog = new StockLog();

                        foreach (string s in result.ReturnValue.ToString().Split(','))
                        {
                            result = stockDAL.Get(user, Convert.ToInt32(s));
                            if (result.ResultStatus != 0)
                                return result;
                            stock = result.ReturnValue as Model.Stock;

                            result = stockNameDAL.Get(user, stock.StockNameId);
                            if (result.ResultStatus != 0)
                                return result;
                            stockName = result.ReturnValue as Model.StockName;

                            ////创建stockLog对象
                            //stockLog = new StockLog()
                            //{
                            //    StockId = stock.StockId,
                            //    StockNameId = stock.StockNameId,
                            //    RefNo = stockName.RefNo,
                            //    //LogDirection =
                            //    LogType = LogEnum.质押冲销,
                            //    //ContractId = ,
                            //    //SubContractId = ,
                            //    LogDate = DateTime.Now,
                            //    OpPerson = user.EmpId,
                            //    Bundles = stock.Bundles,
                            //    GrossAmount = stock.GrossAmount,
                            //    NetAmount = stock.NetAmount,
                            //    MUId = stock.UintId,
                            //    BrandId = stock.BrandId,
                            //    DeliverPlaceId = stock.DeliverPlaceId,
                            //    PaperNo = stock.PaperNo,
                            //    PaperHolder = stock.PaperHolder,
                            //    CardNo = stock.CardNo,
                            //    Memo = stock.Memo,
                            //    LogStatus = StatusEnum.已生效,
                            //    LogSourceBase = "NFMT",
                            //    LogSource = "dbo.St_Pledge",
                            //    SourceId = pledgeId
                            //};

                            //result = stockLogDAL.Insert(user, stockLog);
                            //if (result.ResultStatus != 0)
                            //    return result;

                            result = stockDAL.UpdateStockStatusToPrevious(user, stock);
                            if (result.ResultStatus != 0)
                                return result;
                        }

                        scope.Complete();
                    }
                }
            }
            catch (Exception ex)
            {
                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;
        }
예제 #11
0
파일: PledgeBLL.cs 프로젝트: weiliji/NFMT
        public ResultModel Close(UserModel user, int pledgeId)
        {
            ResultModel result = new ResultModel();

            try
            {
                using (System.Transactions.TransactionScope scope = new TransactionScope())
                {
                    //获取质押
                    result = this.pledgeDAL.Get(user, pledgeId);
                    if (result.ResultStatus != 0)
                        return result;

                    Model.Pledge pledge = result.ReturnValue as Model.Pledge;
                    if (pledge == null || pledge.PledgeId <= 0)
                    {
                        result.ResultStatus = -1;
                        result.Message = "质押不存在";
                        return result;
                    }

                    //质押关闭
                    result = this.pledgeDAL.Close(user, pledge);
                    if (result.ResultStatus != 0)
                        return result;

                    //获取所有已完成的明细
                    DAL.PledgeDetialDAL pledgeDetialDAL = new PledgeDetialDAL();
                    result = pledgeDetialDAL.Load(user, pledgeId, StatusEnum.已生效);
                    if (result.ResultStatus != 0)
                        return result;

                    List<Model.PledgeDetial> details = result.ReturnValue as List<Model.PledgeDetial>;
                    if (details == null || !details.Any())
                    {
                        result.ResultStatus = -1;
                        result.Message = "获取失败";
                        return result;
                    }

                    DAL.StockLogDAL stockLogDAL = new StockLogDAL();
                    DAL.StockDAL stockDAL = new StockDAL();

                    foreach (Model.PledgeDetial detail in details)
                    {
                        //明细关闭
                        result = pledgeDetialDAL.Close(user, detail);
                        if (result.ResultStatus != 0)
                            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;
                        }

                        //完成质押流水
                        result = stockLogDAL.Close(user, stockLog);
                        if (result.ResultStatus != 0)
                            return result;

                        //获取库存
                        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;
                        }

                        if (stock.PreStatus == StockStatusEnum.质押库存)
                            stock.PreStatus = StockStatusEnum.在库正常;

                        result = stockDAL.UpdateStockStatusToPrevious(user, stock);
                        if (result.ResultStatus != 0)
                            return result;
                    }

                    scope.Complete();
                }

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

            return result;
        }
예제 #12
0
파일: PledgeBLL.cs 프로젝트: weiliji/NFMT
        public ResultModel Complete(UserModel user, int pledgeId)
        {
            ResultModel result = new ResultModel();

            try
            {
                using (TransactionScope scope = new TransactionScope(TransactionScopeOption.Required))
                {
                    //验证质押
                    result = pledgeDAL.Get(user, pledgeId);
                    if (result.ResultStatus != 0)
                        return result;

                    Pledge pledge = result.ReturnValue as Pledge;
                    if (pledge == null || pledge.PledgeId <= 0)
                    {
                        result.ResultStatus = -1;
                        result.Message = "该数据不存在,不能进行执行完成操作";
                        return result;
                    }

                    //执行完成
                    result = pledgeDAL.Complete(user, pledge);
                    if (result.ResultStatus != 0)
                        return result;

                    //加载明细
                    PledgeDetialDAL pledgeDetialDAL = new PledgeDetialDAL();
                    result = pledgeDetialDAL.Load(user, pledge.PledgeId);
                    if (result.ResultStatus != 0)
                        return result;

                    List<Model.PledgeDetial> details = result.ReturnValue as List<Model.PledgeDetial>;
                    if (details == null || !details.Any())
                    {
                        result.ResultStatus = -1;
                        result.Message = "获取质押明细失败";
                        return result;
                    }

                    //加载对应质押申请
                    PledgeApplyDAL pledgeApplyDAL = new PledgeApplyDAL();
                    result = pledgeApplyDAL.Get(user, pledge.PledgeApplyId);
                    if (result.ResultStatus != 0)
                        return result;

                    PledgeApply pledgeApply = result.ReturnValue as PledgeApply;
                    if (pledgeApply == null || pledgeApply.PledgeApplyId <= 0)
                    {
                        result.ResultStatus = -1;
                        result.Message = "对应质押申请加载失败";
                        return result;
                    }

                    //明细执行完成
                    //更新库存状态至质押库存
                    StockDAL stockDAL = new StockDAL();
                    StockLogDAL stockLogDAL = new StockLogDAL();
                    StockNameDAL stockNameDAL = new StockNameDAL();

                    foreach (Model.PledgeDetial detail in details)
                    {
                        //明细完成
                        result = pledgeDetialDAL.Complete(user, detail);
                        if (result.ResultStatus != 0)
                            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;
                        }

                        //完成质押流水
                        result = stockLogDAL.Complete(user, stockLog);
                        if (result.ResultStatus != 0)
                            return result;

                        //获取库存
                        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 = stockDAL.UpdateStockStatusDirect(stock, StockStatusEnum.质押库存);
                        if (result.ResultStatus != 0)
                            return result;
                    }

                    scope.Complete();
                }
            }
            catch (Exception ex)
            {
                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;
        }
예제 #13
0
        //移库完成撤销	   流水操作:更新 流水状态:已生效		     库存操作:更新 库存状态:预移库存
        public ResultModel CompleteCancel(UserModel user, int stockMoveId)
        {
            ResultModel result = new ResultModel();

            try
            {
                using (System.Transactions.TransactionScope scope = new TransactionScope())
                {
                    result = this.stockmoveDAL.Get(user, stockMoveId);
                    if (result.ResultStatus != 0)
                        return result;

                    Model.StockMove stockmove = result.ReturnValue as StockMove;
                    if (stockmove == null)
                    {
                        result.Message = "该数据不存在,不能完成";
                        result.ResultStatus = -1;
                        return result;
                    }

                    result = stockmoveDAL.CompleteCancel(user, stockmove);
                    if (result.ResultStatus != 0)
                        return result;

                    //获取所有已生效的明细
                    DAL.StockMoveDetailDAL stockMoveDetailDAL = new StockMoveDetailDAL();
                    result = stockMoveDetailDAL.Load(user, stockMoveId, StatusEnum.已完成);
                    if (result.ResultStatus != 0)
                        return result;

                    List<Model.StockMoveDetail> details = result.ReturnValue as List<Model.StockMoveDetail>;
                    if (details == null || !details.Any())
                    {
                        result.ResultStatus = -1;
                        result.Message = "获取失败";
                        return result;
                    }

                    DAL.StockLogDAL stockLogDAL = new StockLogDAL();
                    DAL.StockDAL stockDAL = new StockDAL();

                    foreach (Model.StockMoveDetail detail in details)
                    {
                        //明细完成
                        result = stockMoveDetailDAL.CompleteCancel(user, detail);
                        if (result.ResultStatus != 0)
                            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;
                        }

                        //完成移库流水
                        result = stockLogDAL.CompleteCancel(user, stockLog);
                        if (result.ResultStatus != 0)
                            return result;

                        //获取库存
                        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 = stockDAL.UpdateStockStatus(stock, StockStatusEnum.预移库存);
                        if (result.ResultStatus != 0)
                            return result;
                    }

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

            return result;
        }
예제 #14
0
        public ResultModel Complete(UserModel user, int stockMoveId)
        {
            ResultModel result = new ResultModel();

            try
            {
                using (TransactionScope scope = new TransactionScope(TransactionScopeOption.Required))
                {
                    result = this.stockmoveDAL.Get(user, stockMoveId);
                    if (result.ResultStatus != 0)
                        return result;

                    Model.StockMove stockmove = result.ReturnValue as StockMove;
                    if (stockmove == null)
                    {
                        result.Message = "该数据不存在,不能完成";
                        return result;
                    }

                    result = stockmoveDAL.Complete(user, stockmove);
                    if (result.ResultStatus != 0)
                        return result;

                    //获取所有已生效的明细
                    DAL.StockMoveDetailDAL stockMoveDetailDAL = new StockMoveDetailDAL();
                    result = stockMoveDetailDAL.Load(user, stockMoveId, StatusEnum.已生效);
                    if (result.ResultStatus != 0)
                        return result;

                    List<Model.StockMoveDetail> details = result.ReturnValue as List<Model.StockMoveDetail>;
                    if (details == null || !details.Any())
                    {
                        result.ResultStatus = -1;
                        result.Message = "获取失败";
                        return result;
                    }

                    DAL.StockLogDAL stockLogDAL = new StockLogDAL();
                    DAL.StockDAL stockDAL = new StockDAL();

                    foreach (Model.StockMoveDetail detail in details)
                    {
                        //明细完成
                        result = stockMoveDetailDAL.Complete(user, detail);
                        if (result.ResultStatus != 0)
                            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;
                        }

                        //完成移库流水
                        result = stockLogDAL.Complete(user, stockLog);
                        if (result.ResultStatus != 0)
                            return result;

                        //获取库存
                        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 = stockDAL.UpdateStockStatusToPrevious(user, stock, StockStatusEnum.在库正常);
                        if (result.ResultStatus != 0)
                            return result;
                    }

                    scope.Complete();
                }
            }
            catch (Exception ex)
            {
                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;
        }
예제 #15
0
파일: RepoBLL.cs 프로젝트: weiliji/NFMT
        public ResultModel RepoUpdateHandle(UserModel user, int repoId, string sids, string memo)
        {
            ResultModel result = new ResultModel();
            DAL.RepoDetailDAL repoDetailDAL = new RepoDetailDAL();
            NFMT.WareHouse.DAL.StockDAL stockDAL = new StockDAL();
            NFMT.WareHouse.Model.Stock stock = new Stock();
            NFMT.WareHouse.DAL.RepoApplyDetailDAL repoApplyDetailDAL = new RepoApplyDetailDAL();

            try
            {
                using (TransactionScope scope = new TransactionScope(TransactionScopeOption.Required))
                {
                    result = repoDAL.Get(user, repoId);
                    if (result.ResultStatus != 0)
                        return result;

                    Model.Repo repo = result.ReturnValue as Model.Repo;
                    if (repo == null)
                    {
                        result.ResultStatus = -1;
                        return result;
                    }

                    repo.Memo = memo;

                    //更新回购
                    result = repoDAL.Update(user, repo);
                    if (result.ResultStatus != 0)
                        return result;

                    //作废所有该回购下的明细
                    result = repoDetailDAL.InvalidAll(user, repoId);
                    if (result.ResultStatus != 0)
                        return result;

                    string[] splits = sids.Split(',');
                    if (splits != null && splits.Length > 0)
                    {
                        foreach (string str in splits)
                        {
                            //获取库存信息
                            result = stockDAL.Get(user, Convert.ToInt32(str));
                            if (result.ResultStatus != 0)
                                return result;

                            stock = result.ReturnValue as NFMT.WareHouse.Model.Stock;
                            if (stock == null)
                            {
                                result.ResultStatus = -1;
                                return result;
                            }

                            result = repoApplyDetailDAL.GetDetailId(user, repo.RepoApplyId, Convert.ToInt32(str));
                            if (result.ResultStatus != 0)
                                return result;

                            int detailId = (int)result.ReturnValue;

                            //写入质押明细表
                            result = repoDetailDAL.Insert(user, new RepoDetail()
                            {
                                RepoId = repoId,
                                RepoApplyDetailId = detailId,
                                StockId = Convert.ToInt32(str),
                                RepoWeight = stock.GrossAmount,
                                Unit = stock.UintId
                            });
                            if (result.ResultStatus != 0)
                                return result;
                        }
                        scope.Complete();
                    }
                }
            }
            catch (Exception ex)
            {
                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;
        }
예제 #16
0
파일: StockOutBLL.cs 프로젝트: weiliji/NFMT
        public ResultModel Close(UserModel user, int stockOutId)
        {
            ResultModel result = new ResultModel();

            try
            {
                StockOutDetailDAL stockOutDetailDAL = new StockOutDetailDAL();
                StockOutApplyDAL applyDAL = new StockOutApplyDAL();
                StockLogDAL stockLogDAL = new StockLogDAL();
                StockDAL stockDAL = new StockDAL();

                using (TransactionScope scope = new TransactionScope(TransactionScopeOption.Required))
                {
                    //验证出库
                    result = stockoutDAL.Get(user, stockOutId);
                    if (result.ResultStatus != 0)
                        return result;

                    StockOut resultObj = result.ReturnValue as StockOut;
                    if (resultObj == null || resultObj.StockOutId <= 0)
                    {
                        result.ResultStatus = -1;
                        result.Message = "该数据不存在,不能进行执行完成操作";
                        return result;
                    }

                    //关闭出库
                    result = stockoutDAL.Close(user, resultObj);
                    if (result.ResultStatus != 0)
                        return result;

                    //加载对应出库申请
                    result = applyDAL.Get(user, resultObj.StockOutApplyId);
                    if (result.ResultStatus != 0)
                        return result;

                    StockOutApply apply = result.ReturnValue as StockOutApply;
                    if (apply == null || apply.StockOutApplyId <= 0)
                    {
                        result.ResultStatus = -1;
                        result.Message = "对应出库申请加载失败";
                        return result;
                    }

                    //加载明细
                    result = stockOutDetailDAL.Load(user, resultObj.StockOutId);
                    if (result.ResultStatus != 0)
                        return result;

                    List<StockOutDetail> details = result.ReturnValue as List<StockOutDetail>;
                    if(details ==null)
                    {
                        result.ResultStatus = -1;
                        result.Message = "获取明细失败";
                        return result;
                    }

                    foreach (StockOutDetail detail in details)
                    {
                        //关闭明细
                        result = stockOutDetailDAL.Close(user,detail);
                        if(result.ResultStatus !=0)
                            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;
                        }

                        //关闭出库流水
                        result = stockLogDAL.Close(user, stockLog);
                        if (result.ResultStatus != 0)
                            return result;

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

                        if (stock.StockStatus == StockStatusEnum.预售库存)
                        {
                            result = stockDAL.UpdateStockStatusToPrevious(user, stock);
                            if (result.ResultStatus != 0)
                                return result;
                        }

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

            return result;
        }
예제 #17
0
        public ResultModel StockReceiptUpdate(UserModel user, int detailId, int stockId, int stockLogId, decimal receiptAmount)
        {
            ResultModel result = new ResultModel();

            try
            {
                DAL.StockDAL stockDAL = new StockDAL();
                DAL.StockLogDAL stockLogDAL = new StockLogDAL();
                DAL.StockReceiptDetailDAL stockReceiptDetailDAL = new StockReceiptDetailDAL();

                using (TransactionScope scope = new TransactionScope(TransactionScopeOption.Required))
                {
                    result = stockReceiptDetailDAL.Get(user, detailId);
                    if (result.ResultStatus != 0)
                        return result;

                    Model.StockReceiptDetail stockReceiptDetail = result.ReturnValue as Model.StockReceiptDetail;
                    if (stockReceiptDetail == null || stockReceiptDetail.DetailId <= 0)
                    {
                        result.ResultStatus = -1;
                        result.Message = "获取库存回执错误";
                        return result;
                    }
                    stockReceiptDetail.ReceiptAmount = receiptAmount;
                    stockReceiptDetail.QtyMiss = receiptAmount - stockReceiptDetail.PreNetAmount;
                    stockReceiptDetail.QtyRate = (receiptAmount / stockReceiptDetail.PreNetAmount - 1) / 100;

                    //修改库存回执明细
                    result = stockReceiptDetailDAL.Update(user, stockReceiptDetail);
                    if (result.ResultStatus != 0)
                        return result;

                    //获取库存回执
                    result = stockreceiptDAL.Get(user, stockReceiptDetail.ReceiptId);
                    if (result.ResultStatus != 0)
                        return result;

                    Model.StockReceipt stockReceipt = result.ReturnValue as Model.StockReceipt;
                    if (stockReceipt == null || stockReceipt.ReceiptId <= 0)
                    {
                        result.ResultStatus = -1;
                        result.Message = "获取库存回执出错";
                        return result;
                    }

                    result = stockLogDAL.Get(user, 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;
                    }

                    stockLog.GapAmount = receiptAmount - stockReceiptDetail.PreNetAmount;

                    //更新库存流水
                    result = stockLogDAL.Update(user, stockLog);
                    if (result.ResultStatus != 0)
                        return result;

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

                    if (stockReceipt.ReceiptType == (int)NFMT.WareHouse.ReceiptTypeEnum.入库回执)
                    {
                        stock.ReceiptInGap = receiptAmount - stockReceiptDetail.PreNetAmount;
                    }
                    else if (stockReceipt.ReceiptType == (int)NFMT.WareHouse.ReceiptTypeEnum.出库回执)
                    {
                        stock.ReceiptOutGap = receiptAmount - stockReceiptDetail.PreNetAmount;
                    }
                    stock.CurNetAmount = receiptAmount;

                    //更新库存
                    result = stockDAL.Update(user, stock);
                    if (result.ResultStatus != 0)
                        return result;

                    //若此库存已开业务票,则修改业务票中的净重
                    result = stockreceiptDAL.UpdateBussinessInvDetail(user, stockLogId, receiptAmount);
                    if (result.ResultStatus != 0)
                        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;
        }
예제 #18
0
파일: StockOutBLL.cs 프로젝트: weiliji/NFMT
        public ResultModel Complete(UserModel user, int stockOutId)
        {
            ResultModel result = new ResultModel();

            try
            {
                StockDAL stockDAL = new StockDAL();
                StockLogDAL stockLogDAL = new StockLogDAL();
                StockNameDAL stockNameDAL = new StockNameDAL();
                StockOutDetailDAL stockOutDetailDAL = new StockOutDetailDAL();
                StockOutApplyDAL applyDAL = new StockOutApplyDAL();

                using (TransactionScope scope = new TransactionScope(TransactionScopeOption.Required))
                {
                    //验证出库
                    result = stockoutDAL.Get(user, stockOutId);
                    if (result.ResultStatus != 0)
                        return result;
                    StockOut resultObj = result.ReturnValue as StockOut;
                    if (resultObj == null || resultObj.StockOutId <= 0)
                    {
                        result.ResultStatus = -1;
                        result.Message = "该数据不存在,不能进行执行完成操作";
                        return result;
                    }

                    //执行完成
                    result = stockoutDAL.Complete(user, resultObj);
                    if (result.ResultStatus != 0)
                        return result;

                    //加载明细
                    result = stockOutDetailDAL.Load(user, resultObj.StockOutId);
                    if (result.ResultStatus != 0)
                        return result;

                    List<Model.StockOutDetail> details = result.ReturnValue as List<Model.StockOutDetail>;
                    if (details == null)
                    {
                        result.ResultStatus = -1;
                        result.Message = "获取出库明细失败";
                        return result;
                    }

                    //加载对应出库申请
                    result = applyDAL.Get(user, resultObj.StockOutApplyId);
                    if (result.ResultStatus != 0)
                        return result;

                    StockOutApply apply = result.ReturnValue as StockOutApply;
                    if (apply == null || apply.StockOutApplyId <= 0)
                    {
                        result.ResultStatus = -1;
                        result.Message = "对应出库申请加载失败";
                        return result;
                    }

                    //明细执行完成
                    foreach(Model.StockOutDetail detail in details)
                    {
                        //出库明细完成
                        result = stockOutDetailDAL.Complete(user,detail);
                        if (result.ResultStatus != 0)
                            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;
                        }

                        //完成出库流水
                        result = stockLogDAL.Complete(user, stockLog);
                        if (result.ResultStatus != 0)
                            return result;

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

                        //库存重量捆数减少
                        stock.CurGrossAmount -= detail.GrossAmount;
                        stock.CurNetAmount -= detail.NetAmount;
                        stock.Bundles -= detail.Bundles;

                        //库存状态修改
                        if (stock.StockStatus == StockStatusEnum.预售库存)
                            stock.StockStatus = StockStatusEnum.已售库存;

                        result = stockDAL.Update(user, stock);
                        if (result.ResultStatus != 0)
                            return result;

                    }

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

            return result;
        }
예제 #19
0
        public ResultModel CompleteCancel(UserModel user, int receiptId)
        {
            ResultModel result = new ResultModel();

            try
            {
                DAL.StockDAL stockDAL = new StockDAL();
                using (TransactionScope scope = new TransactionScope(TransactionScopeOption.Required))
                {
                    result = this.stockreceiptDAL.Get(user, receiptId);
                    if (result.ResultStatus != 0)
                        return result;

                    StockReceipt stockReceipt = result.ReturnValue as StockReceipt;

                    if (stockReceipt == null || stockReceipt.ReceiptId <= 0)
                    {
                        result.ResultStatus = -1;
                        result.Message = "该数据不存在,不能作废";
                        return result;
                    }

                    result = this.stockreceiptDAL.CompleteCancel(user, stockReceipt);
                    if (result.ResultStatus != 0)
                        return result;

                    StockReceiptDetailDAL detailDAL = new StockReceiptDetailDAL();
                    result = detailDAL.Load(user, stockReceipt.ReceiptId, StatusEnum.已完成);
                    if (result.ResultStatus != 0)
                        return result;

                    List<Model.StockReceiptDetail> details = result.ReturnValue as List<Model.StockReceiptDetail>;
                    if (details == null)
                    {
                        result.ResultStatus = -1;
                        result.Message = "获取回执明细失败";
                        return result;
                    }
                    foreach (Model.StockReceiptDetail detail in details)
                    {
                        result = detailDAL.CompleteCancel(user, detail);
                        if (result.ResultStatus != 0)
                            return result;

                        //获取库存
                        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;
                        }

                        //更新库存净重
                        if (stockReceipt.ReceiptType == (int)ReceiptTypeEnum.入库回执)
                        {
                            stock.ReceiptInGap -= detail.QtyMiss;
                            stock.NetAmount -= detail.QtyMiss;
                        }
                        else
                            stock.ReceiptOutGap -= detail.QtyMiss;
                        stock.CurNetAmount -= detail.QtyMiss;

                        result = stockDAL.Update(user, stock);
                        if (result.ResultStatus != 0)
                            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;
        }
예제 #20
0
파일: StockOutBLL.cs 프로젝트: weiliji/NFMT
        public ResultModel CompleteCancel(UserModel user, int stockOutId)
        {
            ResultModel result = new ResultModel();

            try
            {
                DAL.StockLogDAL stockLogDAL = new StockLogDAL();
                DAL.StockDAL stockDAL = new StockDAL();
                DAL.StockNameDAL stockNameDAL = new StockNameDAL();
                DAL.StockOutDAL stockOutDAL = new StockOutDAL();
                DAL.StockOutDetailDAL stockOutDetailDAL = new StockOutDetailDAL();
                DAL.StockOutApplyDAL outApplyDAL = new StockOutApplyDAL();
                Operate.DAL.ApplyDAL applyDAL = new Operate.DAL.ApplyDAL();

                using (TransactionScope scope = new TransactionScope(TransactionScopeOption.Required))
                {
                    //验证出库
                    result = stockoutDAL.Get(user, stockOutId);
                    if (result.ResultStatus != 0)
                        return result;
                    StockOut stockOut = result.ReturnValue as StockOut;
                    if (stockOut == null || stockOut.StockOutId <= 0)
                    {
                        result.ResultStatus = -1;
                        result.Message = "该数据不存在,不能进行执行完成操作";
                        return result;
                    }

                    //撤销出库
                    result = this.stockoutDAL.CompleteCancel(user, stockOut);
                    if (result.ResultStatus != 0)
                        return result;

                    //验证出库申请
                    result = outApplyDAL.Get(user, stockOut.StockOutApplyId);
                    if (result.ResultStatus != 0)
                        return result;

                    Model.StockOutApply outApply = result.ReturnValue as Model.StockOutApply;
                    if (outApply == null || outApply.StockOutApplyId <= 0)
                    {
                        result.ResultStatus = -1;
                        result.Message = "出库申请不存在";
                        return result;
                    }

                    //验证主申请
                    result = applyDAL.Get(user, outApply.ApplyId);
                    if (result.ResultStatus != 0)
                        return result;

                    Operate.Model.Apply apply = result.ReturnValue as Operate.Model.Apply;
                    if (apply == null || apply.ApplyId <= 0)
                    {
                        result.ResultStatus = -1;
                        result.Message = "主申请不存在";
                        return result;
                    }

                    //判断主申请状态是否为已生效,
                    if (apply.ApplyStatus != StatusEnum.已生效)
                    {
                        result.ResultStatus = -1;
                        result.Message = "申请状态只有在已生效下才能进行执行完成撤销";
                        return result;
                    }

                    //获取已完成出库明细
                    result = stockOutDetailDAL.Load(user, stockOut.StockOutId, Common.StatusEnum.已完成);
                    if (result.ResultStatus != 0)
                        return result;
                    List<Model.StockOutDetail> details = result.ReturnValue as List<Model.StockOutDetail>;
                    if (details == null)
                    {
                        result.ResultStatus = -1;
                        result.Message = "获取出库明细错误";
                        return result;
                    }

                    //将所有已完成出库明细更新至已生效
                    foreach (Model.StockOutDetail detail in details)
                    {
                        result = stockOutDetailDAL.CompleteCancel(user, detail);
                        if (result.ResultStatus != 0)
                            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;
                        }

                        //更新出库流水状态为已生效
                        result = stockLogDAL.CompleteCancel(user, stockLog);
                        if (result.ResultStatus != 0)
                            return result;

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

                        //库存重量添加
                        stock.CurGrossAmount += detail.GrossAmount;
                        stock.CurNetAmount += detail.NetAmount;
                        stock.Bundles += detail.Bundles;

                        //明细关联库存状态更新至前一状态
                        if (stock.StockStatus == StockStatusEnum.已售库存)
                            stock.StockStatus = StockStatusEnum.预售库存;

                        result = stockDAL.Update(user, stock);
                        if (result.ResultStatus != 0)
                            return result;

                    }

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

            return result;
        }
예제 #21
0
        public ResultModel Audit(UserModel user, NFMT.WorkFlow.Model.DataSource dataSource, bool isPass)
        {
            ResultModel result = new ResultModel();

            try
            {
                DAL.StockDAL stockDAL = new StockDAL();
                NFMT.WareHouse.DAL.StockLogDAL stockLogDAL = new StockLogDAL();
                NFMT.WareHouse.DAL.StockReceiptDetailDAL stockReceiptDetailDAL = new StockReceiptDetailDAL();

                using (TransactionScope scope = new TransactionScope(TransactionScopeOption.Required))
                {
                    result = this.stockreceiptDAL.Get(NFMT.Common.DefaultValue.SysUser, dataSource.RowId);
                    if (result.ResultStatus != 0)
                        return result;

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

                    //审核,修改数据状态
                    result = this.stockreceiptDAL.Audit(user, stockReceipt, isPass);
                    if (result.ResultStatus != 0)
                        return result;

                    //审核通过
                    if (isPass)
                    {
                        //获取回执明细
                        result = stockReceiptDetailDAL.Load(user, stockReceipt.ReceiptId);
                        if (result.ResultStatus != 0)
                            return result;

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

                        foreach (Model.StockReceiptDetail detail in stockReceiptDetails)
                        {
                            //获取库存流水
                            result = stockLogDAL.Get(NFMT.Common.DefaultValue.SysUser, 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;
                            }

                            //更新库存流水回执重量
                            stockLog.GapAmount += detail.QtyMiss;
                            result = stockLogDAL.Update(user, stockLog);
                            if (result.ResultStatus != 0)
                                return result;

                            //获取库存
                            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;
                            }

                            //更新库存净重
                            if (stockReceipt.ReceiptType == (int)ReceiptTypeEnum.入库回执)
                            {
                                stock.ReceiptInGap += detail.QtyMiss;
                                //stock.NetAmount += detail.QtyMiss;
                            }
                            else
                                stock.ReceiptOutGap += detail.QtyMiss;
                            stock.CurNetAmount = detail.ReceiptAmount;

                            result = stockDAL.Update(user, stock);
                            if (result.ResultStatus != 0)
                                return result;
                        }
                    }

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

            return result;
        }
예제 #22
0
파일: StockOutBLL.cs 프로젝트: weiliji/NFMT
        public ResultModel CreateStockOut(NFMT.Common.UserModel user, int stockOutApplyId, List<int> detailIds, string memo)
        {
            ResultModel result = new ResultModel();

            try
            {
                //dal init
                DAL.StockDAL stockDAL = new StockDAL();
                DAL.StockOutApplyDAL stockOutApplyDAL = new StockOutApplyDAL();
                DAL.StockOutApplyDetailDAL stockOutApplyDetailDAL = new StockOutApplyDetailDAL();
                DAL.StockOutDAL stockOutDAL = new StockOutDAL();
                DAL.StockOutDetailDAL stockOutDetailDAL = new StockOutDetailDAL();

                using (System.Transactions.TransactionScope scope = new TransactionScope(TransactionScopeOption.Required))
                {
                    //获取出库申请
                    result = stockOutApplyDAL.Get(user, stockOutApplyId);
                    if (result.ResultStatus != 0)
                        return result;

                    Model.StockOutApply stockOutApply = result.ReturnValue as Model.StockOutApply;
                    if (stockOutApply == null || stockOutApply.StockOutApplyId <= 0)
                    {
                        result.ResultStatus = -1;
                        result.Message = "出库申请不存在";
                        return result;
                    }

                    //获取出库申请明细
                    result = stockOutApplyDetailDAL.Load(user, stockOutApplyId);
                    if (result.ResultStatus != 0)
                        return result;
                    List<Model.StockOutApplyDetail> stockOutApplyDetails = result.ReturnValue as List<Model.StockOutApplyDetail>;
                    if (stockOutApplyDetails == null)
                    {
                        result.ResultStatus = -1;
                        result.Message = "出库申请明细获取失败";
                        return result;
                    }

                    //判断detailIds 是否都在出库申请明细中
                    List<int> applyDetails = new List<int>();
                    foreach (Model.StockOutApplyDetail detail in stockOutApplyDetails)
                    {
                        applyDetails.Add(detail.DetailId);
                    }

                    foreach (int id in detailIds)
                    {
                        if (!applyDetails.Contains(id))
                        {
                            result.ResultStatus = -1;
                            result.Message = "出库申请不包含选中库存";
                            return result;
                        }
                    }

                    decimal sumGrossAmount = 0;
                    decimal sumNetAmount = 0;
                    int sumBundles = 0;

                    //验证库存及申请明细
                    foreach (int id in detailIds)
                    {
                        Model.StockOutApplyDetail applyDetail = stockOutApplyDetails.FirstOrDefault(temp => temp.DetailId == id);

                        if (applyDetail == null || applyDetail.DetailId <= 0)
                        {
                            result.ResultStatus = -1;
                            result.Message = "出库申请不包含选中库存";
                            return result;
                        }
                        if (applyDetail.DetailStatus != StatusEnum.已生效)
                        {
                            result.ResultStatus = -1;
                            result.Message = "选中库存存在已作废状态库存";
                            return result;
                        }

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

                        //库存状态校验
                        if (stock.StockStatus != StockStatusEnum.在库正常 && stock.StockStatus != StockStatusEnum.新拆库存 && stock.StockStatus != StockStatusEnum.质押库存)
                        {
                            result.ResultStatus = -1;
                            result.Message = "库存不允许出库,出库失败";
                            return result;
                        }

                        sumGrossAmount += applyDetail.GrossAmount;
                        sumNetAmount += applyDetail.NetAmount;
                        sumBundles += applyDetail.Bundles;
                    }

                    //新增出库表
                    Model.StockOut stockOut = new StockOut();
                    stockOut.Executor = user.EmpId;
                    stockOut.Memo = memo;
                    stockOut.StockOutApplyId = stockOutApply.StockOutApplyId;
                    stockOut.StockOutStatus = StatusEnum.已录入;
                    stockOut.StockOutTime = DateTime.Now;
                    stockOut.Unit = stockOutApply.UnitId;
                    stockOut.GrosstAmount = sumGrossAmount;
                    stockOut.NetAmount = sumNetAmount;
                    stockOut.Bundles = sumBundles;

                    result = stockoutDAL.Insert(user, stockOut);
                    if (result.ResultStatus != 0)
                        return result;

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

                    stockOut.StockOutId = stockOutId;

                    //新增出库明细表
                    foreach (int id in detailIds)
                    {
                        Model.StockOutApplyDetail applyDetail = stockOutApplyDetails.FirstOrDefault(temp => temp.DetailId == id);

                        Model.StockOutDetail stockOutDetail = new StockOutDetail();
                        stockOutDetail.DetailStatus = StatusEnum.已生效;
                        stockOutDetail.GrossAmount = applyDetail.GrossAmount;
                        stockOutDetail.NetAmount = applyDetail.NetAmount;
                        stockOutDetail.Bundles = applyDetail.Bundles;
                        stockOutDetail.StockId = applyDetail.StockId;
                        stockOutDetail.StockOutApplyDetailId = applyDetail.DetailId;
                        stockOutDetail.StockOutId = stockOutId;

                        result = stockOutDetailDAL.Insert(user, stockOutDetail);
                        if (result.ResultStatus != 0)
                            return result;
                    }

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

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

            return result;
        }
예제 #23
0
파일: StockInBLL.cs 프로젝트: weiliji/NFMT
        public ResultModel Close(UserModel user, int stockInId)
        {
            ResultModel result = new ResultModel();

            try
            {
                DAL.StockDAL stockDAL = new StockDAL();
                DAL.StockLogDAL stockLogDAL = new StockLogDAL();
                DAL.StockInStockDAL stockInStockDAL = new StockInStockDAL();
                DAL.StockExclusiveDAL stockExclusiveDAL = new StockExclusiveDAL();
                DAL.ContractStockInDAL contractStockInDAL = new ContractStockInDAL();

                using (System.Transactions.TransactionScope scope = new TransactionScope())
                {
                    //获取入库登记
                    result = this.stockinDAL.Get(user, 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;
                    }

                    //入库登记关闭
                    result = this.stockinDAL.Close(user, stockIn);
                    if (result.ResultStatus != 0)
                        return result;

                    //获取合约关联
                    result = contractStockInDAL.GetByStockInId(user, stockIn.StockInId);
                    if (result.ResultStatus != 0)
                        return result;

                    Model.ContractStockIn contractStockIn = result.ReturnValue as Model.ContractStockIn;
                    if (contractStockIn != null && contractStockIn.RefId > 0)
                    {
                        //关闭合约关联
                        result = contractStockInDAL.Close(user, contractStockIn);
                        if (result.ResultStatus != 0)
                            return result;
                    }

                    //获取入库登记与库存流水关联
                    result = stockInStockDAL.GetByStockIn(user, stockIn.StockInId);
                    if (result.ResultStatus != 0)
                        return result;

                    Model.StockInStock stockInStock = result.ReturnValue as Model.StockInStock;
                    if (stockInStock == null || stockInStock.RefId <= 0)
                    {
                        result.ResultStatus = -1;
                        result.Message = "关联获取失败";
                        return result;
                    }

                    //关闭关联
                    result = stockInStockDAL.Close(user, stockInStock);
                    if (result.ResultStatus != 0)
                        return result;

                    //获取库存流水
                    result = stockLogDAL.Get(user, stockInStock.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;
                    }

                    //关闭库存流水
                    result = stockLogDAL.Close(user, stockLog);
                    if (result.ResultStatus != 0)
                        return result;

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

                    //库存校验是否在库正常
                    if (stock.StockStatus != StockStatusEnum.预入库存)
                    {
                        result.ResultStatus = -1;
                        result.Message = "库存已由业务关联,不允许关闭";
                        return result;
                    }

                    //库存流水校验是否配货
                    result = stockExclusiveDAL.CheckStockIsInExclusive(user, stock.StockId);
                    if (result.ResultStatus != 0)
                        return result;

                    //更新库存状态为作废库存
                    result = stockDAL.UpdateStockStatus(stock, StockStatusEnum.作废库存);
                    if (result.ResultStatus != 0)
                        return result;

                    scope.Complete();
                }

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

            return result;
        }
예제 #24
0
파일: StockOutBLL.cs 프로젝트: weiliji/NFMT
        public ResultModel Audit(UserModel user, NFMT.WorkFlow.Model.DataSource dataSource, bool isPass)
        {
            ResultModel result = new ResultModel();

            try
            {
                DAL.StockDAL stockDAL = new StockDAL();
                DAL.StockLogDAL stockLogDAL = new StockLogDAL();
                DAL.StockOutDetailDAL detailDAL = new StockOutDetailDAL();
                DAL.StockNameDAL stockNameDAL = new StockNameDAL();
                DAL.StockOutApplyDAL stockOutApplyDAL = new StockOutApplyDAL();

                using (TransactionScope scope = new TransactionScope(TransactionScopeOption.Required))
                {
                    result = this.stockoutDAL.Get(NFMT.Common.DefaultValue.SysUser, dataSource.RowId);
                    if (result.ResultStatus != 0)
                        return result;

                    Model.StockOut stockOut = result.ReturnValue as Model.StockOut;
                    if (stockOut == null || stockOut.StockOutId <= 0)
                    {
                        result.ResultStatus = -1;
                        result.Message = "出库不存在";
                        return result;
                    }

                    //审核,修改数据状态
                    result = this.stockoutDAL.Audit(user, stockOut, isPass);
                    if (result.ResultStatus != 0)
                        return result;

                    //审核通过
                    if (isPass)
                    {
                        //流水操作:写入 流水类型:出库 流水状态:已生效    库存操作:更新 库存状态:预售库存

                        //获取出库申请
                        result = stockOutApplyDAL.Get(user,stockOut.StockOutApplyId);
                        if(result.ResultStatus!=0)
                            return result;

                        Model.StockOutApply stockOutApply = result.ReturnValue as Model.StockOutApply;
                        if(stockOutApply == null || stockOutApply.StockOutApplyId<=0)
                        {
                            result.ResultStatus = -1;
                            result.Message = "出库申请获取失败";
                            return result;
                        }

                        //获取出库明细
                        result = detailDAL.Load(user, stockOut.StockOutId);
                        if (result.ResultStatus != 0)
                            return result;

                        List<Model.StockOutDetail> outDetails = result.ReturnValue as List<Model.StockOutDetail>;
                        if (outDetails == null)
                        {
                            result.ResultStatus = -1;
                            result.Message = "出库明细获取失败";
                            return result;
                        }

                        foreach (Model.StockOutDetail outDetail in outDetails)
                        {
                            //获取库存
                            result = stockDAL.Get(user, outDetail.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 = stockNameDAL.Get(user,stock.StockNameId);
                            if(result.ResultStatus!=0)
                                return result;

                            Model.StockName stockName = result.ReturnValue as Model.StockName;
                            if(stockName == null || stockName.StockNameId <=0)
                            {
                                result.ResultStatus = -1;
                                result.Message = "业务单号获取失败";
                                return result;
                            }

                            //出库净重==当前净重时 库存状态更新至 预售库存
                            if (outDetail.NetAmount == stock.CurNetAmount)
                            {
                                result = stockDAL.UpdateStockStatus(stock, StockStatusEnum.预售库存);
                                if (result.ResultStatus != 0)
                                    return result;
                            }

                            //写出库流水,流水状态为已生效
                            Model.StockLog stockLog = new StockLog()
                            {
                                AssetId = stock.AssetId,
                                BrandId = stock.BrandId,
                                CardNo = stock.CardNo,
                                DeliverPlaceId = stock.DeliverPlaceId,
                                GrossAmount = outDetail.GrossAmount,
                                LogDate = DateTime.Now,
                                LogDirection = (int)LogDirectionEnum.Out,
                                LogSource = "dbo.St_StockOutDetail",
                                LogSourceBase = "NFMT",
                                LogStatus = StatusEnum.已生效,
                                LogType = (int)LogTypeEnum.出库,
                                NetAmount = outDetail.NetAmount,
                                MUId = stock.UintId,
                                OpPerson = user.EmpId,
                                PaperHolder = stock.PaperHolder,
                                PaperNo = stock.PaperNo,
                                RefNo = stockName.RefNo,
                                SourceId = outDetail.DetailId,
                                StockId = stock.StockId,
                                StockNameId = stock.StockNameId,
                                SubContractId = stockOutApply.SubContractId,
                                ContractId = stockOutApply.ContractId,
                                Memo = stockOut.Memo,
                                Bundles = outDetail.Bundles
                            };

                            result = stockLogDAL.Insert(user, stockLog);
                            if (result.ResultStatus != 0)
                                return result;

                            int stockLogId = 0;
                            if (result.ReturnValue == null || !int.TryParse(result.ReturnValue.ToString(), out stockLogId) || stockLogId <= 0)
                            {
                                result.ResultStatus = -1;
                                result.Message = "出库流水写入失败";
                                return result;
                            }

                            //更新出库明细的出库流水
                            outDetail.StockLogId = stockLogId;
                            result = detailDAL.Update(user, outDetail);
                            if (result.ResultStatus != 0)
                                return result;
                        }
                    }

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

            return result;
        }
예제 #25
0
파일: StockInBLL.cs 프로젝트: weiliji/NFMT
        public ResultModel CompleteCancel(UserModel user, int stockInId)
        {
            ResultModel result = new ResultModel();

            try
            {
                DAL.StockDAL stockDAL = new StockDAL();
                DAL.StockLogDAL stockLogDAL = new StockLogDAL();
                DAL.StockInStockDAL stockInStockDAL = new StockInStockDAL();
                DAL.ContractStockInDAL contractStockInDAL = new ContractStockInDAL();

                using (System.Transactions.TransactionScope scope = new TransactionScope())
                {
                    //获取入库登记
                    result = this.stockinDAL.Get(user, 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;
                    }

                    //入库登记撤销完成
                    result = this.stockinDAL.CompleteCancel(user, stockIn);
                    if (result.ResultStatus != 0)
                        return result;

                    //获取合约关联
                    result = contractStockInDAL.GetByStockInId(user, stockIn.StockInId);
                    if (result.ResultStatus != 0)
                        return result;

                    Model.ContractStockIn contractStockIn = result.ReturnValue as Model.ContractStockIn;
                    if (contractStockIn == null || contractStockIn.RefId <= 0)
                    {
                        result.ResultStatus = -1;
                        result.Message = "入库登记未关联合约,不允许确认完成";
                        return result;
                    }

                    //完成撤销合约关联
                    result = contractStockInDAL.CompleteCancel(user, contractStockIn);
                    if (result.ResultStatus != 0)
                        return result;

                    //获取入库登记与库存流水关联
                    result = stockInStockDAL.GetByStockIn(user, stockIn.StockInId);
                    if (result.ResultStatus != 0)
                        return result;

                    Model.StockInStock stockInStock = result.ReturnValue as Model.StockInStock;
                    if (stockInStock == null || stockInStock.RefId <= 0)
                    {
                        result.ResultStatus = -1;
                        result.Message = "关联获取失败";
                        return result;
                    }

                    //撤销关联
                    result = stockInStockDAL.CompleteCancel(user, stockInStock);
                    if (result.ResultStatus != 0)
                        return result;

                    //获取库存流水
                    result = stockLogDAL.Get(user, stockInStock.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;
                    }

                    //撤销库存流水
                    result = stockLogDAL.CompleteCancel(user, stockLog);
                    if (result.ResultStatus != 0)
                        return result;

                    //获取库存
                    result = stockDAL.Get(user, stockLog.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 = stockDAL.UpdateStockStatus(stock, StockStatusEnum.预入库存);
                    if (result.ResultStatus != 0)
                        return result;

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

            return result;
        }
예제 #26
0
파일: RepoBLL.cs 프로젝트: weiliji/NFMT
        public ResultModel Close(UserModel user, int repoId)
        {
            ResultModel result = new ResultModel();

            try
            {
                using (System.Transactions.TransactionScope scope = new TransactionScope())
                {
                    //获取回购
                    result = this.repoDAL.Get(user, repoId);
                    if (result.ResultStatus != 0)
                        return result;

                    Model.Repo repo = result.ReturnValue as Model.Repo;
                    if (repo == null || repo.RepoId <= 0)
                    {
                        result.ResultStatus = -1;
                        result.Message = "回购不存在";
                        return result;
                    }

                    //回购关闭
                    result = this.repoDAL.Close(user, repo);
                    if (result.ResultStatus != 0)
                        return result;

                    //获取所有已完成的明细
                    DAL.RepoDetailDAL repoDetailDAL = new RepoDetailDAL();
                    result = repoDetailDAL.Load(user, repoId, StatusEnum.已生效);
                    if (result.ResultStatus != 0)
                        return result;

                    List<Model.RepoDetail> details = result.ReturnValue as List<Model.RepoDetail>;
                    if (details == null || !details.Any())
                    {
                        result.ResultStatus = -1;
                        result.Message = "获取失败";
                        return result;
                    }

                    DAL.StockLogDAL stockLogDAL = new StockLogDAL();
                    DAL.StockDAL stockDAL = new StockDAL();

                    foreach (Model.RepoDetail detail in details)
                    {
                        //明细关闭
                        result = repoDetailDAL.Close(user, detail);
                        if (result.ResultStatus != 0)
                            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;
                        }

                        //完成回购流水
                        result = stockLogDAL.Close(user, stockLog);
                        if (result.ResultStatus != 0)
                            return result;

                        //获取库存
                        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 = stockDAL.UpdateStockStatusToPrevious(user, stock, StockStatusEnum.质押库存);
                        if (result.ResultStatus != 0)
                            return result;
                    }

                    scope.Complete();
                }

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

            return result;
        }
예제 #27
0
        public ResultModel Complete(UserModel user, int customId)
        {
            ResultModel result = new ResultModel();

            try
            {
                using (TransactionScope scope = new TransactionScope(TransactionScopeOption.Required))
                {
                    result = this.customsclearanceDAL.Get(user, customId);
                    if (result.ResultStatus != 0)
                        return result;

                    Model.CustomsClearance customsClearance = result.ReturnValue as CustomsClearance;
                    if (customsClearance == null)
                    {
                        result.Message = "该数据不存在,不能完成";
                        return result;
                    }

                    result = customsclearanceDAL.Complete(user, customsClearance);
                    if (result.ResultStatus != 0)
                        return result;

                    //获取所有已生效的明细
                    DAL.CustomsDetailDAL customsDetailDAL = new CustomsDetailDAL();
                    result = customsDetailDAL.Load(user, customId, StatusEnum.已生效);
                    if (result.ResultStatus != 0)
                        return result;

                    List<Model.CustomsDetail> details = result.ReturnValue as List<Model.CustomsDetail>;
                    if (details == null || !details.Any())
                    {
                        result.ResultStatus = -1;
                        result.Message = "获取失败";
                        return result;
                    }

                    DAL.StockLogDAL stockLogDAL = new StockLogDAL();
                    DAL.StockDAL stockDAL = new StockDAL();

                    foreach (Model.CustomsDetail detail in details)
                    {
                        //明细完成
                        result = customsDetailDAL.Complete(user, detail);
                        if (result.ResultStatus != 0)
                            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;
                        }

                        //完成报关流水
                        result = stockLogDAL.Complete(user, stockLog);
                        if (result.ResultStatus != 0)
                            return result;

                        //获取库存
                        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;
                        }

                        stock.StockStatus = (int)stock.PreStatus == 0 ? StockStatusEnum.在库正常 : stock.PreStatus;
                        stock.CustomsType = NFMT.Data.DetailProvider.Details(Data.StyleEnum.CustomType)["InsideCustom"].StyleDetailId;//关内
                        result = stockDAL.Update(user, stock);
                        if (result.ResultStatus != 0)
                            return result;
                    }

                    scope.Complete();
                }
            }
            catch (Exception ex)
            {
                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;
        }
예제 #28
0
파일: RepoBLL.cs 프로젝트: weiliji/NFMT
        public ResultModel CompleteCancel(UserModel user, int repoId)
        {
            ResultModel result = new ResultModel();

            try
            {
                using (TransactionScope scope = new TransactionScope(TransactionScopeOption.Required))
                {
                    result = this.repoDAL.Get(user, repoId);
                    if (result.ResultStatus != 0)
                        return result;

                    Model.Repo repo = result.ReturnValue as Repo;
                    if (repo == null)
                    {
                        result.Message = "该数据不存在,不能完成";
                        result.ResultStatus = -1;
                        return result;
                    }

                    result = repoDAL.CompleteCancel(user, repo);
                    if (result.ResultStatus != 0)
                        return result;

                    //获取所有已生效的明细
                    DAL.RepoDetailDAL repoDetailDAL = new RepoDetailDAL();
                    result = repoDetailDAL.Load(user, repoId, StatusEnum.已完成);
                    if (result.ResultStatus != 0)
                        return result;

                    List<Model.RepoDetail> details = result.ReturnValue as List<Model.RepoDetail>;
                    if (details == null || !details.Any())
                    {
                        result.ResultStatus = -1;
                        result.Message = "获取失败";
                        return result;
                    }

                    DAL.StockLogDAL stockLogDAL = new StockLogDAL();
                    DAL.StockDAL stockDAL = new StockDAL();

                    foreach (Model.RepoDetail detail in details)
                    {
                        //明细完成
                        result = repoDetailDAL.CompleteCancel(user, detail);
                        if (result.ResultStatus != 0)
                            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;
                        }

                        //完成回购流水
                        result = stockLogDAL.CompleteCancel(user, stockLog);
                        if (result.ResultStatus != 0)
                            return result;

                        //获取库存
                        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 = stockDAL.UpdateStockStatusDirect(stock, StockStatusEnum.预回购库存);
                        if (result.ResultStatus != 0)
                            return result;
                    }

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

            return result;
        }
예제 #29
0
        //报关审核生效	   流水操作:写入 流水类型:报关 流水状态:已生效    库存操作:更新 库存状态:预报关库存
        public ResultModel Audit(UserModel user, NFMT.WorkFlow.Model.DataSource dataSource, bool isPass)
        {
            ResultModel result = new ResultModel();

            try
            {
                using (TransactionScope scope = new TransactionScope(TransactionScopeOption.Required))
                {
                    result = this.customsclearanceDAL.Get(user, dataSource.RowId);
                    if (result.ResultStatus != 0)
                        return result;

                    Model.CustomsClearance customsClearance = result.ReturnValue as Model.CustomsClearance;
                    if (customsClearance == null || customsClearance.CustomsId <= 0)
                    {
                        result.ResultStatus = -1;
                        result.Message = "报关不存在";
                        return result;
                    }

                    //审核,修改数据状态
                    result = this.customsclearanceDAL.Audit(user, customsClearance, isPass);
                    if (result.ResultStatus != 0)
                        return result;

                    //审核通过
                    if (isPass)
                    {
                        //加载已生效明细
                        DAL.CustomsDetailDAL customsDetailDAL = new CustomsDetailDAL();
                        result = customsDetailDAL.Load(user, customsClearance.CustomsId, StatusEnum.已生效);
                        if (result.ResultStatus != 0)
                            return result;

                        List<Model.CustomsDetail> details = result.ReturnValue as List<Model.CustomsDetail>;
                        if (details == null || !details.Any())
                        {
                            result.ResultStatus = -1;
                            result.Message = "获取失败";
                            return result;
                        }

                        DAL.StockDAL stockDAL = new StockDAL();
                        DAL.StockNameDAL stockNameDAL = new StockNameDAL();
                        DAL.StockLogDAL stockLogDAL = new StockLogDAL();
                        Model.Stock stock = null;
                        Model.StockName stockName = null;
                        Model.StockLog stockLog = null;

                        foreach (Model.CustomsDetail detail in details)
                        {
                            //获取库存
                            result = stockDAL.Get(user, detail.StockId);
                            if (result.ResultStatus != 0)
                                return result;

                            stock = result.ReturnValue as Model.Stock;
                            if (stock == null)
                            {
                                result.ResultStatus = -1;
                                result.Message = "获取库存失败";
                                return result;
                            }

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

                            stockName = result.ReturnValue as Model.StockName;
                            if (stockName == null)
                            {
                                result.ResultStatus = -1;
                                result.Message = "获取业务单号失败";
                                return result;
                            }

                            //创建库存流水
                            stockLog = new StockLog()
                            {
                                StockId = stock.StockId,
                                StockNameId = stock.StockNameId,
                                RefNo = stockName.RefNo,
                                LogDirection = (int)LogDirectionEnum.Out,
                                LogType = (int)LogTypeEnum.报关,
                                //ContractId =
                                //SubContractId =
                                LogDate = DateTime.Now,
                                OpPerson = user.EmpId,
                                Bundles = stock.Bundles,
                                GrossAmount = stock.GrossAmount,
                                NetAmount = stock.NetAmount,
                                MUId = stock.UintId,
                                BrandId = stock.BrandId,
                                DeliverPlaceId = stock.DeliverPlaceId,
                                PaperNo = stock.PaperNo,
                                PaperHolder = stock.PaperHolder,
                                CardNo = stock.CardNo,
                                Memo = stock.Memo,
                                LogStatus = StatusEnum.已生效,
                                LogSourceBase = "NFMT",
                                LogSource = "dbo.St_CustomsClearance",
                                SourceId = customsClearance.CustomsId
                            };

                            result = stockLogDAL.Insert(user, stockLog);
                            if (result.ResultStatus != 0)
                                return result;

                            int stockLogId = 0;
                            if (result.ReturnValue == null || !int.TryParse(result.ReturnValue.ToString(), out stockLogId) || stockLogId <= 0)
                            {
                                result.ResultStatus = -1;
                                result.Message = "流水添加失败";
                                return result;
                            }

                            //将库存流水Id反向更新到明细表中
                            detail.StockLogId = stockLogId;
                            result = customsDetailDAL.Update(user, detail);
                            if (result.ResultStatus != 0)
                                return result;

                            //更新库存状态
                            result = stockDAL.UpdateStockStatus(stock, StockStatusEnum.预报关库存);
                            if (result.ResultStatus != 0)
                                return result;
                        }
                    }

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

            return result;
        }
예제 #30
0
        public ResultModel ContractInCompleteCancelStockOperate(UserModel user, int contractId)
        {
            ResultModel result = new ResultModel();
            StockDAL stockDAL = new StockDAL();
            StockLogDAL stockLogDAL = new StockLogDAL();
            StockInStockDAL stockInStockDAL = new StockInStockDAL();
            ContractStockInDAL contractStockInDAL = new ContractStockInDAL();
            StockInDAL stockInDAL = new StockInDAL();

            result = contractStockInDAL.Load(user, contractId);
            if (result.ResultStatus != 0)
                return result;

            List<NFMT.WareHouse.Model.ContractStockIn> contractStockIns = result.ReturnValue as List<NFMT.WareHouse.Model.ContractStockIn>;
            if (contractStockIns == null)
            {
                result.Message = "合约入库分配获取失败";
                result.ResultStatus = -1;
                return result;
            }

            foreach (NFMT.WareHouse.Model.ContractStockIn contractStcokIn in contractStockIns)
            {
                //获取入库登记
                result = stockInDAL.Get(user, contractStcokIn.StockInId);
                if (result.ResultStatus != 0)
                    return result;

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

                //入库登记撤销完成
                result = stockInDAL.CompleteCancel(user, stockIn);
                if (result.ResultStatus != 0)
                    return result;

                //获取合约关联
                result = contractStockInDAL.GetByStockInId(user, stockIn.StockInId);
                if (result.ResultStatus != 0)
                    return result;

                NFMT.WareHouse.Model.ContractStockIn contractStockIn = result.ReturnValue as NFMT.WareHouse.Model.ContractStockIn;
                if (contractStockIn == null || contractStockIn.RefId <= 0)
                {
                    result.ResultStatus = -1;
                    result.Message = "入库登记未关联合约,不允许确认完成";
                    return result;
                }

                //完成撤销合约关联
                result = contractStockInDAL.CompleteCancel(user, contractStockIn);
                if (result.ResultStatus != 0)
                    return result;

                //获取入库登记与库存流水关联
                result = stockInStockDAL.GetByStockIn(user, stockIn.StockInId);
                if (result.ResultStatus != 0)
                    return result;

                NFMT.WareHouse.Model.StockInStock stockInStock = result.ReturnValue as NFMT.WareHouse.Model.StockInStock;
                if (stockInStock == null || stockInStock.RefId <= 0)
                {
                    result.ResultStatus = -1;
                    result.Message = "关联获取失败";
                    return result;
                }

                //撤销关联
                result = stockInStockDAL.CompleteCancel(user, stockInStock);
                if (result.ResultStatus != 0)
                    return result;

                //获取库存流水
                result = stockLogDAL.Get(user, stockInStock.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 = stockLogDAL.CompleteCancel(user, stockLog);
                if (result.ResultStatus != 0)
                    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.ResultStatus = -1;
                    result.Message = "库存获取失败";
                    return result;
                }

                //更新库存状态为预入库存
                result = stockDAL.UpdateStockStatus(stock, StockStatusEnum.预入库存);
                if (result.ResultStatus != 0)
                    return result;
            }

            return result;
        }