示例#1
0
文件: ApplyDAL.cs 项目: weiliji/NFMT
        public override IModel CreateModel(SqlDataReader dr)
        {
            Apply apply = new Apply();

            int indexApplyId = dr.GetOrdinal("ApplyId");
            apply.ApplyId = Convert.ToInt32(dr[indexApplyId]);

            int indexApplyNo = dr.GetOrdinal("ApplyNo");
            if (dr["ApplyNo"] != DBNull.Value)
            {
                apply.ApplyNo = Convert.ToString(dr[indexApplyNo]);
            }

            int indexApplyType = dr.GetOrdinal("ApplyType");
            if (dr["ApplyType"] != DBNull.Value)
            {
                apply.ApplyType = (ApplyType)Convert.ToInt32(dr[indexApplyType]);
            }

            int indexEmpId = dr.GetOrdinal("EmpId");
            if (dr["EmpId"] != DBNull.Value)
            {
                apply.EmpId = Convert.ToInt32(dr[indexEmpId]);
            }

            int indexApplyTime = dr.GetOrdinal("ApplyTime");
            if (dr["ApplyTime"] != DBNull.Value)
            {
                apply.ApplyTime = Convert.ToDateTime(dr[indexApplyTime]);
            }

            int indexApplyStatus = dr.GetOrdinal("ApplyStatus");
            if (dr["ApplyStatus"] != DBNull.Value)
            {
                apply.ApplyStatus = (Common.StatusEnum)Convert.ToInt32(dr[indexApplyStatus]);
            }

            int indexApplyDept = dr.GetOrdinal("ApplyDept");
            if (dr["ApplyDept"] != DBNull.Value)
            {
                apply.ApplyDept = Convert.ToInt32(dr[indexApplyDept]);
            }

            int indexApplyCorp = dr.GetOrdinal("ApplyCorp");
            if (dr["ApplyCorp"] != DBNull.Value)
            {
                apply.ApplyCorp = Convert.ToInt32(dr[indexApplyCorp]);
            }

            int indexApplyDesc = dr.GetOrdinal("ApplyDesc");
            if (dr["ApplyDesc"] != DBNull.Value)
            {
                apply.ApplyDesc = Convert.ToString(dr[indexApplyDesc]);
            }

            int indexCreatorId = dr.GetOrdinal("CreatorId");
            if (dr["CreatorId"] != DBNull.Value)
            {
                apply.CreatorId = Convert.ToInt32(dr[indexCreatorId]);
            }

            int indexCreateTime = dr.GetOrdinal("CreateTime");
            if (dr["CreateTime"] != DBNull.Value)
            {
                apply.CreateTime = Convert.ToDateTime(dr[indexCreateTime]);
            }

            int indexLastModifyId = dr.GetOrdinal("LastModifyId");
            if (dr["LastModifyId"] != DBNull.Value)
            {
                apply.LastModifyId = Convert.ToInt32(dr[indexLastModifyId]);
            }

            int indexLastModifyTime = dr.GetOrdinal("LastModifyTime");
            if (dr["LastModifyTime"] != DBNull.Value)
            {
                apply.LastModifyTime = Convert.ToDateTime(dr[indexLastModifyTime]);
            }

            return apply;
        }
示例#2
0
        public ResultModel PayApplyUpdate(UserModel user, Apply apply, PayApply payApply, List<StockPayApply> stockDetails)
        {
            ResultModel result = new ResultModel();

            try
            {
                ApplyDAL applyDAL = new ApplyDAL();
                ContractPayApplyDAL contractPayApplyDAL = new ContractPayApplyDAL();
                StockPayApplyDAL stockPayApplyDAL = new StockPayApplyDAL();
                StockDAL stockDAL = new StockDAL();
                StockLogDAL stockLogDAL = new StockLogDAL();
                ContractSubDAL subDAL = new ContractSubDAL();

                using (TransactionScope scope = new TransactionScope())
                {
                    //获取主申请
                    result = applyDAL.Get(user, apply.ApplyId);
                    if (result.ResultStatus != 0)
                        return result;

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

                    resultApply.EmpId = user.EmpId;
                    resultApply.ApplyDept = apply.ApplyDept;
                    resultApply.ApplyCorp = apply.ApplyCorp;
                    resultApply.ApplyDesc = apply.ApplyDesc;
                    resultApply.ApplyTime = apply.ApplyTime;

                    result = applyDAL.Update(user, resultApply);
                    if (result.ResultStatus != 0)
                        return result;

                    //获取付款申请
                    result = this.payapplyDAL.Get(user, payApply.PayApplyId);
                    if (result.ResultStatus != 0)
                        return result;

                    PayApply resultPayApply = result.ReturnValue as PayApply;
                    if (resultPayApply == null || resultPayApply.PayApplyId <= 0)
                    {
                        result.Message = "付款申请获取失败";
                        result.ResultStatus = -1;
                        return result;
                    }
                    if (resultPayApply.ApplyId != resultApply.ApplyId)
                    {
                        result.Message = "付款申请与主申请不一致,更新失败";
                        result.ResultStatus = -1;
                        return result;
                    }

                    resultPayApply.RecCorpId = payApply.RecCorpId;
                    resultPayApply.RecBankId = payApply.RecBankId;
                    resultPayApply.RecBankAccountId = payApply.RecBankAccountId;
                    resultPayApply.RecBankAccount = payApply.RecBankAccount;
                    resultPayApply.ApplyBala = payApply.ApplyBala;
                    resultPayApply.CurrencyId = payApply.CurrencyId;
                    resultPayApply.PayMode = payApply.PayMode;
                    resultPayApply.PayDeadline = payApply.PayDeadline;
                    resultPayApply.PayMatter = payApply.PayMatter;
                    resultPayApply.SpecialDesc = payApply.SpecialDesc;

                    if (stockDetails.Count > 0)
                        resultPayApply.PayApplySource = (int)FundsStyleEnum.StockPayApply;
                    else
                        resultPayApply.PayApplySource = (int)FundsStyleEnum.ContractPayApply;

                    result = this.payapplyDAL.Update(user, resultPayApply);
                    if (result.ResultStatus != 0)
                        return result;

                    //获取合约关联付款申请
                    result = contractPayApplyDAL.GetByPayApplyId(user, resultPayApply.PayApplyId);
                    if (result.ResultStatus != 0)
                        return result;

                    ContractPayApply contractPayApply = result.ReturnValue as ContractPayApply;
                    if (contractPayApply == null || contractPayApply.RefId <= 0)
                    {
                        result.Message = "合约关联付款申请获取失败";
                        result.ResultStatus = -1;
                        return result;
                    }

                    contractPayApply.ApplyBala = resultPayApply.ApplyBala;
                    result = contractPayApplyDAL.Update(user, contractPayApply);
                    if (result.ResultStatus != 0)
                        return result;

                    //获取现有库存明细
                    result = stockPayApplyDAL.Load(user, resultPayApply.PayApplyId);
                    if (result.ResultStatus != 0)
                        return result;

                    List<StockPayApply> resultDetails = result.ReturnValue as List<StockPayApply>;
                    if (resultDetails == null)
                    {
                        result.Message = "库存付款申请获取失败";
                        result.ResultStatus = -1;
                        return result;
                    }

                    //作废现有库存明细
                    foreach (StockPayApply stockPayApply in resultDetails)
                    {
                        stockPayApply.RefStatus = StatusEnum.已录入;
                        result = stockPayApplyDAL.Invalid(user, stockPayApply);
                        if (result.ResultStatus != 0)
                            return result;
                    }

                    //新增库存付款申请
                    if (stockDetails != null && stockDetails.Count > 0)
                    {
                        foreach (StockPayApply detail in stockDetails)
                        {
                            detail.ContractId = contractPayApply.ContractId;
                            detail.ContractRefId = contractPayApply.RefId;
                            detail.PayApplyId = contractPayApply.PayApplyId;
                            detail.RefStatus = StatusEnum.已生效;
                            detail.SubId = contractPayApply.ContractSubId;
                            result = stockPayApplyDAL.Insert(user, detail);
                            if (result.ResultStatus != 0)
                                return result;
                        }
                    }

                    if (result.ResultStatus == 0)
                        result.ReturnValue = payApply.PayApplyId;

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

            return result;
        }
示例#3
0
文件: ApplyDAL.cs 项目: weiliji/NFMT
        public override IModel CreateModel(DataRow dr)
        {
            Apply apply = new Apply();

            apply.ApplyId = Convert.ToInt32(dr["ApplyId"]);

            if (dr["ApplyNo"] != DBNull.Value)
            {
                apply.ApplyNo = Convert.ToString(dr["ApplyNo"]);
            }

            if (dr["ApplyType"] != DBNull.Value)
            {
                apply.ApplyType = (ApplyType)Convert.ToInt32(dr["ApplyType"]);
            }

            if (dr["EmpId"] != DBNull.Value)
            {
                apply.EmpId = Convert.ToInt32(dr["EmpId"]);
            }

            if (dr["ApplyTime"] != DBNull.Value)
            {
                apply.ApplyTime = Convert.ToDateTime(dr["ApplyTime"]);
            }

            if (dr["ApplyStatus"] != DBNull.Value)
            {
                apply.ApplyStatus = (Common.StatusEnum)Convert.ToInt32(dr["ApplyStatus"]);
            }

            if (dr["ApplyDept"] != DBNull.Value)
            {
                apply.ApplyDept = Convert.ToInt32(dr["ApplyDept"]);
            }

            if (dr["ApplyCorp"] != DBNull.Value)
            {
                apply.ApplyCorp = Convert.ToInt32(dr["ApplyCorp"]);
            }

            if (dr["ApplyDesc"] != DBNull.Value)
            {
                apply.ApplyDesc = Convert.ToString(dr["ApplyDesc"]);
            }

            if (dr["CreatorId"] != DBNull.Value)
            {
                apply.CreatorId = Convert.ToInt32(dr["CreatorId"]);
            }

            if (dr["CreateTime"] != DBNull.Value)
            {
                apply.CreateTime = Convert.ToDateTime(dr["CreateTime"]);
            }

            if (dr["LastModifyId"] != DBNull.Value)
            {
                apply.LastModifyId = Convert.ToInt32(dr["LastModifyId"]);
            }

            if (dr["LastModifyTime"] != DBNull.Value)
            {
                apply.LastModifyTime = Convert.ToDateTime(dr["LastModifyTime"]);
            }

            return apply;
        }
示例#4
0
        public ResultModel PayApplyMultiCreate(UserModel user, Apply apply, PayApply payApply, List<StockPayApply> stockDetails, bool isAudit)
        {
            ResultModel result = new ResultModel();

            try
            {
                ApplyDAL applyDAL = new ApplyDAL();
                ContractPayApplyDAL contractPayApplyDAL = new ContractPayApplyDAL();
                StockPayApplyDAL stockPayApplyDAL = new StockPayApplyDAL();

                using (TransactionScope scope = new TransactionScope())
                {
                    //新增主申请
                    apply.ApplyStatus = StatusEnum.已录入;
                    apply.ApplyType = ApplyType.PayApply;
                    apply.EmpId = user.EmpId;
                    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.Message = "主申请新增失败";
                        result.ResultStatus = -1;
                        return result;
                    }
                    apply.ApplyId = applyId;

                    //新增付款申请
                    payApply.ApplyId = apply.ApplyId;
                    payApply.PayApplySource = (int)FundsStyleEnum.ContractPayApply;
                    if (stockDetails != null && stockDetails.Any())
                        payApply.PayApplySource = (int)FundsStyleEnum.StockPayApply;

                    result = this.payapplyDAL.Insert(user, payApply);
                    if (result.ResultStatus != 0)
                        return result;

                    int payApplyId = 0;
                    if (result.ReturnValue == null || !int.TryParse(result.ReturnValue.ToString(), out payApplyId) || payApplyId <= 0)
                    {
                        result.Message = "付款申请新增失败";
                        result.ResultStatus = -1;
                        return result;
                    }
                    payApply.PayApplyId = payApplyId;

                    if (stockDetails != null)
                        foreach (int subId in stockDetails.Select(a => a.SubId).Distinct())
                        {
                            List<Model.StockPayApply> stockPayApplyDetails = stockDetails.Where(a => a.SubId == subId).ToList();

                            //新增合约付款申请
                            ContractPayApply contractPayApply = new ContractPayApply
                            {
                                ApplyBala = stockPayApplyDetails.Sum(a=>a.ApplyBala),
                                ContractId = stockPayApplyDetails.First().ContractId,
                                ContractSubId = subId,
                                PayApplyId = payApply.PayApplyId,
                                Status = StatusEnum.已录入
                            };
                            result = contractPayApplyDAL.Insert(user, contractPayApply);
                            if (result.ResultStatus != 0)
                                return result;

                            int contractPayApplyId = 0;
                            if (result.ReturnValue == null || !int.TryParse(result.ReturnValue.ToString(), out contractPayApplyId) || contractPayApplyId <= 0)
                            {
                                result.Message = "合约关联新增失败";
                                result.ResultStatus = -1;
                                return result;
                            }
                            contractPayApply.RefId = contractPayApplyId;

                            foreach (StockPayApply detail in stockPayApplyDetails)
                            {
                                detail.ContractId = contractPayApply.ContractId;
                                detail.ContractRefId = contractPayApply.RefId;
                                detail.PayApplyId = contractPayApply.PayApplyId;
                                detail.RefStatus = StatusEnum.已生效;
                                detail.SubId = contractPayApply.ContractSubId;
                                result = stockPayApplyDAL.Insert(user, detail);
                                if (result.ResultStatus != 0)
                                    return result;
                            }
                        }

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

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

            return result;
        }
示例#5
0
        public ResultModel PayApplyStockCreate(UserModel user, PayApply payApply, List<StockPayApply> stockPayApplies, string memo, int deptId, int corpId)
        {
            ResultModel result = new ResultModel();

            try
            {
                StockPayApplyDAL stockPayApplyDAL = new StockPayApplyDAL();
                ApplyDAL applyDAL = new ApplyDAL();
                PayApplyDAL payApplyDAL = new PayApplyDAL();
                ContractPayApplyDAL contractPayApplyDAL = new ContractPayApplyDAL();

                StockLogDAL stockLogDAL = new StockLogDAL();

                using (TransactionScope scope = new TransactionScope(TransactionScopeOption.Required))
                {
                    //验证可申请金额
                    //NFMT.Data.Model.FuturesPrice futuresPrice = NFMT.Data.BasicDataProvider.FuturesPrices[0];

                    //验证库存流水是否在同一子合约中
                    int subId = 0;
                    int contractId = 0;
                    foreach (StockPayApply stockPayApply in stockPayApplies)
                    {
                        result = stockLogDAL.Get(user, stockPayApply.StockLogId);
                        if (result.ResultStatus != 0)
                            return result;

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

                        if (subId == 0)
                        {
                            subId = stockLog.SubContractId;
                            contractId = stockLog.ContractId;
                        }

                        if (stockLog.SubContractId != subId)
                        {
                            result.ResultStatus = -1;
                            result.Message = "不能同时申请不同子合约中的库存付款";
                            return result;
                        }
                    }

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

                    int applyId = 0;
                    Apply apply = new Apply();

                    apply.ApplyDept = dept.DeptId;
                    apply.ApplyCorp = corpId;
                    apply.ApplyDesc = memo;
                    apply.ApplyTime = DateTime.Now;
                    apply.ApplyType = ApplyType.付款申请;
                    apply.EmpId = user.EmpId;

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

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

                    decimal sumApplyBala = stockPayApplies.Sum(temp => temp.ApplyBala);
                    //新增付款申请表
                    payApply.ApplyId = applyId;
                    payApply.PayApplySource = (int)FundsStyleEnum.StockPayApply;
                    payApply.ApplyBala = sumApplyBala;
                    result = payapplyDAL.Insert(user, payApply);
                    if (result.ResultStatus != 0)
                        return result;
                    int payApplyId = 0;
                    if (result.ReturnValue == null || !int.TryParse(result.ReturnValue.ToString(), out payApplyId))
                    {
                        result.ResultStatus = -1;
                        result.Message = "付款申请新增失败";
                        return result;
                    }

                    //新增合约付款申请关联表
                    ContractPayApply payApplyContract = new ContractPayApply();
                    payApplyContract.ApplyBala = sumApplyBala;
                    payApplyContract.ContractId = contractId;
                    payApplyContract.ContractSubId = subId;
                    payApplyContract.PayApplyId = payApplyId;

                    result = contractPayApplyDAL.Insert(user, payApplyContract);
                    if (result.ResultStatus != 0)
                        return result;

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

                    //新增dbo.Fun_StockPayApply_Ref库存付款申请
                    foreach (StockPayApply stockPayApply in stockPayApplies)
                    {
                        stockPayApply.ContractId = contractId;
                        stockPayApply.ContractRefId = contractRefId;
                        stockPayApply.SubId = subId;
                        stockPayApply.PayApplyId = payApplyId;
                        stockPayApply.RefStatus = StatusEnum.已生效;
                        result = stockPayApplyDAL.Insert(user, stockPayApply);
                        if (result.ResultStatus != 0)
                            return result;
                    }

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

            return result;
        }
示例#6
0
        public ResultModel PayApplyInvoiceUpdate(UserModel user, Apply apply, PayApply payApply, List<InvoicePayApply> details)
        {
            ResultModel result = new ResultModel();

            try
            {
                InvoicePayApplyDAL invoicePayApplyDAL = new InvoicePayApplyDAL();
                ApplyDAL applyDAL = new ApplyDAL();
                PayApplyDAL payApplyDAL = new PayApplyDAL();
                InvoiceDAL invoiceDAL = new InvoiceDAL();
                SIDAL sIDAL = new SIDAL();

                using (TransactionScope scope = new TransactionScope(TransactionScopeOption.Required))
                {
                    if (details == null || details.Count == 0)
                    {
                        result.ResultStatus = -1;
                        result.Message = "未选中任务发票";
                        return result;
                    }

                    //验证总额
                    decimal sumApplyBala = details.Sum(temp => temp.ApplyBala);
                    if (sumApplyBala != payApply.ApplyBala)
                    {
                        result.ResultStatus = -1;
                        result.Message = "申请总额与分项总额不相等";
                        return result;
                    }

                    //获取付款申请
                    result = this.payapplyDAL.Get(user, payApply.PayApplyId);
                    if (result.ResultStatus != 0)
                        return result;

                    PayApply resultPayApply = result.ReturnValue as PayApply;
                    if (resultPayApply == null || resultPayApply.PayApplyId <= 0)
                    {
                        result.ResultStatus = -1;
                        result.Message = "付款申请不存在";
                        return result;
                    }

                    //获取发票申请列表
                    result = invoicePayApplyDAL.Load(user, resultPayApply.PayApplyId);
                    if (result.ResultStatus != 0)
                        return result;

                    List<InvoicePayApply> resultDetails = result.ReturnValue as List<InvoicePayApply>;
                    if (resultDetails == null)
                    {
                        result.ResultStatus = -1;
                        result.Message = "付款申请发票明细列表获取失败";
                        return result;
                    }

                    //作废原有发票申请明细
                    foreach (InvoicePayApply detail in resultDetails)
                    {
                        detail.DetailStatus = StatusEnum.已录入;
                        result = invoicePayApplyDAL.Invalid(user, detail);
                        if (result.ResultStatus != 0)
                            return result;
                    }

                    //验证发票
                    int payDept = 0;
                    int outCorpId = 0;
                    foreach (InvoicePayApply detail in details)
                    {
                        //获取价外票
                        result = sIDAL.Get(user, detail.SIId);
                        if (result.ResultStatus != 0)
                            return result;

                        SI sI = result.ReturnValue as SI;
                        if (sI == null || sI.SIId <= 0)
                        {
                            result.ResultStatus = -1;
                            result.Message = "价外票不存在";
                            return result;
                        }

                        //获取发票
                        result = invoiceDAL.Get(user, detail.InvoiceId);
                        if (result.ResultStatus != 0)
                            return result;

                        Operate.Model.Invoice invoice = result.ReturnValue as Operate.Model.Invoice;
                        if (invoice == null || invoice.InvoiceId <= 0)
                        {
                            result.ResultStatus = -1;
                            result.Message = "发票不存在";
                            return result;
                        }

                        //验证币种
                        if (payApply.CurrencyId != invoice.CurrencyId)
                        {
                            result.ResultStatus = -1;
                            result.Message = "发票币种不一致";
                            return result;
                        }

                        //验证开票抬头
                        if (outCorpId == 0) { outCorpId = invoice.OutCorpId; }
                        if (outCorpId != invoice.OutCorpId)
                        {
                            result.ResultStatus = -1;
                            result.Message = "发票开票公司不一致";
                            return result;
                        }

                        //验证成本部门
                        if (payDept == 0) { payDept = sI.PayDept; }
                        if (payDept != sI.PayDept)
                        {
                            result.ResultStatus = -1;
                            result.Message = "发票成本部门不一致";
                            return result;
                        }

                        //验证可申请余额
                        result = invoicePayApplyDAL.LoadByInvoice(user, detail.InvoiceId);
                        if (result.ResultStatus != 0)
                            return result;
                        resultDetails = result.ReturnValue as List<InvoicePayApply>;
                        if (resultDetails == null)
                        {
                            result.ResultStatus = -1;
                            result.Message = "获取发票已申请列表失败";
                            return result;
                        }

                        decimal applyBala = resultDetails.Sum(temp => temp.ApplyBala);
                        if (applyBala >= invoice.InvoiceBala)
                        {
                            result.ResultStatus = -1;
                            result.Message = string.Format("发票{0}款项已全部申请", invoice.InvoiceNo);
                            return result;
                        }

                        if (invoice.InvoiceBala - applyBala < detail.ApplyBala)
                        {
                            result.ResultStatus = -1;
                            result.Message = string.Format("发票{0}申请金额超过可申请余额,申请失败", invoice.InvoiceNo);
                            return result;
                        }
                    }

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

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

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

                    resultApply.ApplyDept = dept.DeptId;
                    resultApply.ApplyCorp = apply.ApplyCorp;
                    resultApply.ApplyDesc = apply.ApplyDesc;
                    resultApply.ApplyTime = apply.ApplyTime;
                    resultApply.EmpId = user.EmpId;
                    result = applyDAL.Update(user, resultApply);
                    if (result.ResultStatus != 0)
                        return result;

                    //更新付款申请表
                    resultPayApply.RecCorpId = payApply.RecCorpId;
                    resultPayApply.RecBankId = payApply.RecBankId;
                    resultPayApply.RecBankAccountId = payApply.RecBankAccountId;
                    resultPayApply.RecBankAccount = payApply.RecBankAccount;
                    resultPayApply.CurrencyId = payApply.CurrencyId;
                    resultPayApply.ApplyBala = sumApplyBala;
                    resultPayApply.PayMode = payApply.PayMode;
                    resultPayApply.PayDeadline = payApply.PayDeadline;
                    resultPayApply.PayMatter = payApply.PayMatter;
                    resultPayApply.SpecialDesc = payApply.SpecialDesc;

                    result = payapplyDAL.Update(user, resultPayApply);
                    if (result.ResultStatus != 0)
                        return result;

                    //新增发票付款申请关联表
                    foreach (InvoicePayApply detail in details)
                    {
                        detail.DetailStatus = StatusEnum.已生效;
                        detail.PayApplyId = resultPayApply.PayApplyId;

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

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

            return result;
        }
示例#7
0
        public ResultModel PayApplyInvoiceCreate(UserModel user, Apply apply, PayApply payApply, List<InvoicePayApply> details)
        {
            ResultModel result = new ResultModel();

            try
            {
                InvoicePayApplyDAL invoicePayApplyDAL = new InvoicePayApplyDAL();
                ApplyDAL applyDAL = new ApplyDAL();
                PayApplyDAL payApplyDAL = new PayApplyDAL();
                InvoiceDAL invoiceDAL = new InvoiceDAL();
                SIDAL sIDAL = new SIDAL();

                using (TransactionScope scope = new TransactionScope(TransactionScopeOption.Required))
                {
                    if (details == null || details.Count == 0)
                    {
                        result.ResultStatus = -1;
                        result.Message = "未选中任务发票";
                        return result;
                    }

                    //验证总额
                    decimal sumApplyBala = details.Sum(temp => temp.ApplyBala);
                    if (sumApplyBala != payApply.ApplyBala)
                    {
                        result.ResultStatus = -1;
                        result.Message = "申请总额与分项总额不相等";
                        return result;
                    }

                    //验证发票
                    int payDept = 0;
                    int outCorpId = 0;
                    foreach (InvoicePayApply detail in details)
                    {
                        //获取价外票
                        result = sIDAL.Get(user, detail.SIId);
                        if (result.ResultStatus != 0)
                            return result;

                        SI sI = result.ReturnValue as SI;
                        if (sI == null || sI.SIId <= 0)
                        {
                            result.ResultStatus = -1;
                            result.Message = "价外票不存在";
                            return result;
                        }

                        //获取发票
                        result = invoiceDAL.Get(user, detail.InvoiceId);
                        if (result.ResultStatus != 0)
                            return result;

                        Operate.Model.Invoice invoice = result.ReturnValue as Operate.Model.Invoice;
                        if (invoice == null || invoice.InvoiceId <= 0)
                        {
                            result.ResultStatus = -1;
                            result.Message = "发票不存在";
                            return result;
                        }

                        //验证币种
                        if (payApply.CurrencyId != invoice.CurrencyId)
                        {
                            result.ResultStatus = -1;
                            result.Message = "发票币种不一致";
                            return result;
                        }

                        //验证开票抬头
                        if (outCorpId == 0) { outCorpId = invoice.OutCorpId; }
                        if (outCorpId != invoice.OutCorpId)
                        {
                            result.ResultStatus = -1;
                            result.Message = "发票开票公司不一致";
                            return result;
                        }

                        //验证成本部门
                        if (payDept == 0) { payDept = sI.PayDept; }
                        if (payDept != sI.PayDept)
                        {
                            result.ResultStatus = -1;
                            result.Message = "发票成本部门不一致";
                            return result;
                        }

                        //验证可申请余额
                        result = invoicePayApplyDAL.LoadByInvoice(user, detail.InvoiceId);
                        if (result.ResultStatus != 0)
                            return result;
                        List<InvoicePayApply> resultDetails = result.ReturnValue as List<InvoicePayApply>;
                        if (resultDetails == null)
                        {
                            result.ResultStatus = -1;
                            result.Message = "获取发票已申请列表失败";
                            return result;
                        }

                        decimal applyBala = resultDetails.Sum(temp => temp.ApplyBala);
                        if (applyBala >= invoice.InvoiceBala)
                        {
                            result.ResultStatus = -1;
                            result.Message = string.Format("发票{0}款项已全部申请", invoice.InvoiceNo);
                            return result;
                        }

                        if (invoice.InvoiceBala - applyBala < detail.ApplyBala)
                        {
                            result.ResultStatus = -1;
                            result.Message = string.Format("发票{0}申请金额超过可申请余额,申请失败", invoice.InvoiceNo);
                            return result;
                        }
                    }

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

                    int applyId = 0;
                    apply.ApplyDept = dept.DeptId;
                    apply.ApplyType = ApplyType.付款申请;
                    apply.EmpId = user.EmpId;
                    apply.ApplyStatus = StatusEnum.已录入;
                    result = applyDAL.Insert(user, apply);
                    if (result.ResultStatus != 0)
                        return result;

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

                    //新增付款申请表
                    payApply.ApplyId = applyId;
                    payApply.PayApplySource = (int)FundsStyleEnum.InvoicePayApply;
                    payApply.ApplyBala = sumApplyBala;
                    result = payapplyDAL.Insert(user, payApply);
                    if (result.ResultStatus != 0)
                        return result;
                    int payApplyId = 0;
                    if (result.ReturnValue == null || !int.TryParse(result.ReturnValue.ToString(), out payApplyId))
                    {
                        result.ResultStatus = -1;
                        result.Message = "付款申请新增失败";
                        return result;
                    }

                    //新增发票付款申请关联表
                    foreach (InvoicePayApply detail in details)
                    {
                        detail.DetailStatus = StatusEnum.已生效;
                        detail.PayApplyId = payApplyId;

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

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

            return result;
        }
示例#8
0
        public ResultModel PayApplyCreate(UserModel user, Apply apply, PayApply payApply, List<StockPayApply> stockDetails, int subId, bool isAudit)
        {
            ResultModel result = new ResultModel();

            try
            {
                ApplyDAL applyDAL = new ApplyDAL();
                ContractPayApplyDAL contractPayApplyDAL = new ContractPayApplyDAL();
                StockPayApplyDAL stockPayApplyDAL = new StockPayApplyDAL();
                StockDAL stockDAL = new StockDAL();
                StockLogDAL stockLogDAL = new StockLogDAL();
                ContractSubDAL subDAL = new ContractSubDAL();

                using (TransactionScope scope = new TransactionScope())
                {
                    //新增主申请
                    apply.ApplyStatus = StatusEnum.已录入;
                    apply.ApplyType = ApplyType.PayApply;
                    apply.EmpId = user.EmpId;
                    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.Message = "主申请新增失败";
                        result.ResultStatus = -1;
                        return result;
                    }
                    apply.ApplyId = applyId;

                    //新增付款申请
                    payApply.ApplyId = apply.ApplyId;
                    payApply.PayApplySource = (int)FundsStyleEnum.ContractPayApply;
                    if (stockDetails != null && stockDetails.Count > 0)
                        payApply.PayApplySource = (int)FundsStyleEnum.StockPayApply;

                    result = this.payapplyDAL.Insert(user, payApply);
                    if (result.ResultStatus != 0)
                        return result;

                    int payApplyId = 0;
                    if (result.ReturnValue == null || !int.TryParse(result.ReturnValue.ToString(), out payApplyId) || payApplyId <= 0)
                    {
                        result.Message = "付款申请新增失败";
                        result.ResultStatus = -1;
                        return result;
                    }
                    payApply.PayApplyId = payApplyId;

                    //获取子合约
                    result = subDAL.Get(user, subId);
                    if (result.ResultStatus != 0)
                        return result;

                    ContractSub sub = result.ReturnValue as ContractSub;
                    if (sub == null || sub.SubId <= 0)
                    {
                        result.Message = "子合约获取失败";
                        result.ResultStatus = -1;
                        return result;
                    }

                    if (sub.SubStatus != StatusEnum.已生效)
                    {
                        result.Message = "子合约状态不正确,不能进行付款申请";
                        result.ResultStatus = -1;
                        return result;
                    }
                    //新增合约付款申请
                    ContractPayApply contractPayApply = new ContractPayApply();
                    contractPayApply.ApplyBala = payApply.ApplyBala;
                    contractPayApply.ContractId = sub.ContractId;
                    contractPayApply.ContractSubId = sub.SubId;
                    contractPayApply.PayApplyId = payApply.PayApplyId;
                    contractPayApply.Status = StatusEnum.已录入;
                    result = contractPayApplyDAL.Insert(user, contractPayApply);
                    if (result.ResultStatus != 0)
                        return result;

                    int contractPayApplyId = 0;
                    if (result.ReturnValue == null || !int.TryParse(result.ReturnValue.ToString(), out contractPayApplyId) || contractPayApplyId <= 0)
                    {
                        result.Message = "合约关联新增失败";
                        result.ResultStatus = -1;
                        return result;
                    }
                    contractPayApply.RefId = contractPayApplyId;

                    //新增库存付款申请
                    if (stockDetails != null && stockDetails.Count > 0)
                    {
                        foreach (StockPayApply detail in stockDetails)
                        {
                            detail.ContractId = contractPayApply.ContractId;
                            detail.ContractRefId = contractPayApply.RefId;
                            detail.PayApplyId = contractPayApply.PayApplyId;
                            detail.RefStatus = StatusEnum.已生效;
                            detail.SubId = contractPayApply.ContractSubId;
                            result = stockPayApplyDAL.Insert(user, detail);
                            if (result.ResultStatus != 0)
                                return result;
                        }
                    }

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

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

            return result;
        }
示例#9
0
        public ResultModel PayApplyContractCreate(UserModel user, PayApply payApply, int subId, string memo, int deptId, int corpId)
        {
            ResultModel result = new ResultModel();

            try
            {
                ContractSubDAL subDAL = new ContractSubDAL();
                ApplyDAL applyDAL = new ApplyDAL();
                PayApplyDAL payApplyDAL = new PayApplyDAL();
                ContractPayApplyDAL contractPayApplyDAL = new ContractPayApplyDAL();

                using (TransactionScope scope = new TransactionScope(TransactionScopeOption.Required))
                {
                    //验证子合约信息
                    result = subDAL.Get(user, subId);
                    if (result.ResultStatus != 0)
                        return result;
                    ContractSub sub = result.ReturnValue as ContractSub;
                    if (sub == null || sub.SubId <= 0)
                    {
                        result.ResultStatus = -1;
                        result.Message = "子合约不存在";
                        return result;
                    }

                    //验证可申请金额
                    //NFMT.Data.Model.FuturesPrice futuresPrice = NFMT.Data.BasicDataProvider.FuturesPrices[0];

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

                    int applyId = 0;
                    Apply apply = new Apply();

                    apply.ApplyDept = dept.DeptId;
                    apply.ApplyCorp = corpId;
                    apply.ApplyDesc = memo;
                    apply.ApplyTime = DateTime.Now;
                    apply.ApplyType = ApplyType.付款申请;
                    apply.EmpId = user.EmpId;

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

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

                    //新增付款申请表
                    payApply.ApplyId = applyId;
                    payApply.PayApplySource = (int)FundsStyleEnum.ContractPayApply;
                    result = payapplyDAL.Insert(user, payApply);
                    if (result.ResultStatus != 0)
                        return result;
                    int payApplyId = 0;
                    if (result.ReturnValue == null || !int.TryParse(result.ReturnValue.ToString(), out payApplyId))
                    {
                        result.ResultStatus = -1;
                        result.Message = "付款申请新增失败";
                        return result;
                    }

                    //新增Fun_ContractPayApply_Ref合约付款申请
                    ContractPayApply contractPayApply = new ContractPayApply();
                    contractPayApply.ContractId = sub.ContractId;
                    contractPayApply.ContractSubId = sub.SubId;
                    contractPayApply.PayApplyId = payApplyId;
                    contractPayApply.ApplyBala = payApply.ApplyBala;

                    result = contractPayApplyDAL.Insert(user, contractPayApply);
                    if (result.ResultStatus != 0)
                        return result;

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

            return result;
        }
示例#10
0
        protected void Page_Load(object sender, EventArgs e)
        {
            VerificationUtility ver = new VerificationUtility();
            ver.JudgeOperate(this.Page, 52, new List<OperateEnum>() { OperateEnum.修改 });

            if (!IsPostBack)
            {
                UserModel user = UserUtility.CurrentUser;
                this.curUser = user;

                this.PayMatterStyle = (int)StyleEnum.付款事项;
                this.PayModeStyle = (int)StyleEnum.PayMode;

                string redirectUrl = "PayApplyList.aspx";

                this.navigation1.Routes.Add("付款申请列表", redirectUrl);
                this.navigation1.Routes.Add("付款申请明细", string.Empty);

                int applyId = 0, payApplyId = 0;
                if (!string.IsNullOrEmpty(Request.QueryString["aid"]))
                    int.TryParse(Request.QueryString["aid"], out applyId);
                if (applyId <= 0 && (string.IsNullOrEmpty(Request.QueryString["id"]) || !int.TryParse(Request.QueryString["id"], out payApplyId)))
                    this.WarmAlert("付款申请序号错误", redirectUrl);

                ResultModel result = new ResultModel();

                //获取付款申请
                PayApplyBLL payApplyBLL = new PayApplyBLL();
                if (applyId > 0)
                    result = payApplyBLL.GetByApplyId(user, applyId);
                else
                    result = payApplyBLL.Get(user, payApplyId);

                if (result.ResultStatus != 0)
                    this.WarmAlert("获取付款申请失败", redirectUrl);

                PayApply payApply = result.ReturnValue as PayApply;
                if (payApply == null || payApply.PayApplyId <= 0)
                    this.WarmAlert("获取付款申请失败", redirectUrl);

                this.curPayApply = payApply;

                //获取主申请
                ApplyBLL applyBLL = new ApplyBLL();
                result = applyBLL.Get(user, payApply.ApplyId);
                if (result.ResultStatus != 0)
                    this.WarmAlert("获取主申请失败", redirectUrl);

                Apply apply = result.ReturnValue as Apply;
                if (apply == null || apply.ApplyId <= 0)
                    this.WarmAlert("获取主申请失败", redirectUrl);

                this.curApply = apply;

                //获取合约付款申请
                ContractPayApplyBLL contractPayApplyBLL = new ContractPayApplyBLL();
                result = contractPayApplyBLL.GetByPayApplyId(user, payApply.PayApplyId);
                if (result.ResultStatus != 0)
                    this.WarmAlert("获取合约失败", redirectUrl);

                ContractPayApply contractPayApply = result.ReturnValue as ContractPayApply;
                if (contractPayApply == null || contractPayApply.RefId <= 0)
                    this.WarmAlert("获取合约失败", redirectUrl);

                //获取子合约
                ContractSubBLL subBll = new ContractSubBLL();
                result = subBll.Get(user, contractPayApply.ContractSubId);
                if (result.ResultStatus != 0)
                    this.WarmAlert("获取子合约失败", redirectUrl);
                ContractSub sub = result.ReturnValue as ContractSub;
                if (sub == null || sub.ContractId == 0)
                    this.WarmAlert("获取子合约失败", redirectUrl);

                this.curSub = sub;

                //合约
                ContractBLL bll = new ContractBLL();
                result = bll.Get(user, sub.ContractId);
                if (result.ResultStatus != 0)
                    this.WarmAlert("获取合约失败", redirectUrl);

                NFMT.Contract.Model.Contract contract = result.ReturnValue as NFMT.Contract.Model.Contract;
                if (contract == null || contract.ContractId == 0)
                    this.WarmAlert("获取合约失败", redirectUrl);

                this.contractExpander1.CurContract = contract;
                this.contractExpander1.CurContractSub = sub;
                this.contractExpander1.RedirectUrl = redirectUrl;

                SelectModel select = payApplyBLL.GetPayApplyStocksSelect(1, 100, "spa.RefId desc", payApply.PayApplyId);
                result = payApplyBLL.Load(user, select, DefaultValue.ClearAuth);
                if (result.ResultStatus != 0)
                    this.WarmAlert("获取付款库存列表失败", redirectUrl);

                DataTable dt = result.ReturnValue as DataTable;
                if (dt == null)
                    this.WarmAlert("获取付款库存列表失败", redirectUrl);

                this.StockDetailsJson = JsonConvert.SerializeObject(dt, new DataTableConverter());

                //付款明细
                PaymentBLL paymentBLL = new PaymentBLL();
                select = paymentBLL.GetSelectModel(1, 100, "pay.PaymentId desc", DefaultValue.DefaultTime, DefaultValue.DefaultTime, 0, 0, (int)StatusEnum.已生效, payApply.PayApplyId);
                result = paymentBLL.Load(user, select, DefaultValue.ClearAuth);
                if (result.ResultStatus != 0)
                    this.WarmAlert("获取付款明细失败", redirectUrl);

                dt = result.ReturnValue as DataTable;
                if (dt == null)
                    this.WarmAlert("获取付款明细失败", redirectUrl);
                this.PaymentJson = JsonConvert.SerializeObject(dt, new DataTableConverter());

                //审核实体
                JavaScriptSerializer serializer = new JavaScriptSerializer();
                string json = serializer.Serialize(apply);
                this.hidModel.Value = json;

                FundsStyleEnum fundsStyle = (FundsStyleEnum)payApply.PayApplySource;
                result = payApplyBLL.GetAuditInfo(user, payApply.ApplyId, fundsStyle);
                if (result.ResultStatus != 0)
                    this.WarmAlert("获取付款申请审核信息失败", redirectUrl);

                //this.txbAuditInfo.InnerHtml = result.ReturnValue.ToString();

                if (apply.ApplyStatus != StatusEnum.已录入 && apply.ApplyStatus != StatusEnum.待审核 && apply.ApplyStatus != StatusEnum.审核拒绝
                    && apply.ApplyStatus != StatusEnum.已撤返)
                {
                    //this.jqxAuditInfoExpander.Visible = false;
                }
                else if (apply.ApplyStatus == StatusEnum.已生效 || apply.ApplyStatus == StatusEnum.已完成)
                {

                }
            }
        }