Esempio n. 1
0
        public override ResultModel Submit(UserModel user, IModel obj)
        {
            ResultModel result = new ResultModel();
            Model.Contract contract = obj as Model.Contract;
            if (contract.CreateFrom == (int)NFMT.Common.CreateFromEnum.采购合约库存创建 || contract.CreateFrom == (int)NFMT.Common.CreateFromEnum.销售合约库存创建)
            {
                result = base.Submit(user, obj);
                if (result.ResultStatus != 0)
                    return result;

                DAL.ContractSubDAL subDAL = new ContractSubDAL();
                result = subDAL.GetSubByContractId(user, contract.ContractId);
                if (result.ResultStatus != 0)
                    return result;

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

                if (sub.SubStatus != StatusEnum.待审核)
                {
                    result = subDAL.Submit(user, sub);
                    if (result.ResultStatus != 0)
                        return result;
                }

                if (result.ResultStatus == 0)
                    result.Message = "合约提交审核成功";
            }
            else
                result = base.Submit(user, obj);

            return result;
        }
Esempio n. 2
0
        public ResultModel ContractOutCompleteCancel(UserModel user, int contractId)
        {
            ResultModel result = new ResultModel();

            try
            {
                DAL.ContractSubDAL subDAL = new ContractSubDAL();
                //获取合约
                result = this.contractDAL.Get(user, contractId);
                if (result.ResultStatus != 0)
                    return result;

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

                if (contract.CreateFrom != (int)NFMT.Common.CreateFromEnum.销售合约库存创建)
                {
                    result.Message = "合约创建来源不正确";
                    result.ResultStatus = -1;
                    return result;
                }

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

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

                //主合约完成撤销
                result = this.contractDAL.CompleteCancel(user, contract);
                if (result.ResultStatus != 0)
                    return result;

                //子合约完成撤销
                result = subDAL.CompleteCancel(user, sub);
                if (result.ResultStatus != 0)
                    return result;
            }
            catch (Exception ex)
            {
                result.ResultStatus = -1;
                result.Message = ex.Message;
            }

            return result;
        }
Esempio n. 3
0
        public ResultModel Complete(UserModel user, int id)
        {
            ResultModel result = new ResultModel();

            try
            {
                using (System.Transactions.TransactionScope scope = new TransactionScope())
                {
                    //获取合约
                    result = this.contractDAL.Get(user, id);
                    if (result.ResultStatus != 0)
                        return result;

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

                    //验证所有子合约是否全部关闭
                    DAL.ContractSubDAL subDAL = new ContractSubDAL();
                    result = subDAL.Load(user, resultObj.ContractId, StatusEnum.已录入);
                    if (result.ResultStatus != 0)
                        return result;

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

                    foreach (Model.ContractSub sub in subs)
                    {
                        if (sub.SubStatus != StatusEnum.已完成 && sub.SubStatus != StatusEnum.已作废 && sub.SubStatus != StatusEnum.部分完成 && sub.SubStatus != StatusEnum.已关闭)
                        {
                            result.ResultStatus = -1;
                            result.Message = "有未完成子合约,合约不能完成";
                            return result;
                        }
                    }

                    //验证子合约的签订重量之和是否等于合约重量
                    decimal sumAmount = subs.Sum(temp => temp.SignAmount);
                    decimal missRate = Convert.ToDecimal(0.05);
                    decimal missValue = resultObj.SignAmount * missRate;
                    decimal maxAmount = resultObj.SignAmount + missValue;
                    decimal minAmount = resultObj.SignAmount - missValue;

                    if (sumAmount > maxAmount || sumAmount < minAmount)
                    {
                        result.Message = "子合约执行总量不在合约签订量范围内,不能完成。";
                        result.ResultStatus = -1;
                        return result;
                    }

                    result = this.contractDAL.Complete(user, resultObj);

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

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

            return result;
        }
Esempio n. 4
0
        public ResultModel ContractOutAudit(UserModel user, NFMT.WorkFlow.Model.DataSource dataSource, bool isPass)
        {
            ResultModel result = new ResultModel();

            try
            {
                DAL.ContractSubDAL subDAL = new ContractSubDAL();

                result = this.contractDAL.Get(NFMT.Common.DefaultValue.SysUser, dataSource.RowId);
                if (result.ResultStatus != 0)
                    return result;

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

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

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

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

                result = subDAL.Audit(user, sub, isPass);
                if (result.ResultStatus != 0)
                    return result;

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

            return result;
        }
Esempio n. 5
0
        public ResultModel ContractInGoBack(UserModel user, int contractId)
        {
            ResultModel result = new ResultModel();

            try
            {
                DAL.ContractSubDAL subDAL = new ContractSubDAL();

                //获取合约
                result = this.contractDAL.Get(user, contractId);
                if (result.ResultStatus != 0)
                    return result;

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

                if (contract.CreateFrom != (int)NFMT.Common.CreateFromEnum.采购合约库存创建)
                {
                    result.Message = "合约创建来源不正确";
                    result.ResultStatus = -1;
                    return result;
                }

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

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

                //撤返合约
                result = this.contractDAL.Goback(user, contract);
                if (result.ResultStatus != 0)
                    return result;

                //撤返子合约
                result = subDAL.Goback(user, sub);
                if (result.ResultStatus != 0)
                    return result;

                //删除工作流审核数据
                WorkFlow.DAL.DataSourceDAL sourceDAL = new WorkFlow.DAL.DataSourceDAL();
                result = sourceDAL.SynchronousStatus(user, contract);
                if (result.ResultStatus != 0)
                    return result;
            }
            catch (Exception ex)
            {
                result.ResultStatus = -1;
                result.Message = ex.Message;
            }

            return result;
        }
Esempio n. 6
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;
        }
Esempio n. 7
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;
        }
Esempio n. 8
0
        public ResultModel PayApplyContractUpdate(UserModel user, PayApply payApply, 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 = payApplyDAL.Get(user, payApply.PayApplyId);
                    if (result.ResultStatus != 0)
                        return result;
                    PayApply resultObj = result.ReturnValue as PayApply;
                    if (resultObj == null || resultObj.PayApplyId <= 0)
                    {
                        result.ResultStatus = -1;
                        result.Message = "付款申请不存在";
                        return result;
                    }

                    //验证申请主表
                    result = applyDAL.Get(user, resultObj.ApplyId);
                    if (result.ResultStatus != 0)
                        return result;
                    Apply apply = result.ReturnValue as Apply;
                    if (apply == null || apply.ApplyId <= 0)
                    {
                        result.ResultStatus = -1;
                        result.Message = "申请主表不存在";
                        return result;
                    }

                    //验证合约付款申请关联表
                    result = contractPayApplyDAL.GetByPayApplyId(user, resultObj.PayApplyId);
                    if (result.ResultStatus != 0)
                        return result;
                    ContractPayApply contractPayApply = result.ReturnValue as ContractPayApply;
                    if (contractPayApply == null || contractPayApply.RefId <= 0)
                    {
                        result.ResultStatus = -1;
                        result.Message = "与合约关联错误";
                        return result;
                    }

                    //验证子合约信息
                    result = subDAL.Get(user, contractPayApply.ContractSubId);
                    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;
                    }

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

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

                    //更新付款申请表
                    resultObj.PayApplySource = (int)FundsStyleEnum.ContractPayApply;
                    resultObj.RecCorpId = payApply.RecCorpId;
                    resultObj.RecBankId = payApply.RecBankId;
                    resultObj.RecBankAccountId = payApply.RecBankAccountId;
                    resultObj.RecBankAccount = payApply.RecBankAccount;
                    resultObj.ApplyBala = payApply.ApplyBala;
                    resultObj.CurrencyId = payApply.CurrencyId;
                    resultObj.PayMode = payApply.PayMode;
                    resultObj.PayDeadline = payApply.PayDeadline;
                    resultObj.PayMatter = payApply.PayMatter;
                    resultObj.SpecialDesc = payApply.SpecialDesc;

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

                    //更新Fun_ContractPayApply_Ref合约付款申请
                    contractPayApply.ApplyBala = payApply.ApplyBala;
                    result = contractPayApplyDAL.Update(user, contractPayApply);
                    if (result.ResultStatus != 0)
                        return result;

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

            return result;
        }
Esempio n. 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;
        }
Esempio n. 10
0
        public ResultModel CreateDirect(UserModel user, Operate.Model.Invoice invoice, BusinessInvoice invoiceBusiness, List<BusinessInvoiceDetail> details)
        {
            ResultModel result = new ResultModel();

            ContractSubDAL subDAL = new ContractSubDAL();
            result = subDAL.Get(user, invoiceBusiness.SubContractId);
            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;
            }

            StockLogDAL stockLogDAL = new StockLogDAL();
            //明细表数据:毛重、金额计算
            foreach (BusinessInvoiceDetail detail in details)
            {
                detail.Bala = Math.Round(detail.NetAmount * detail.UnitPrice, 2, MidpointRounding.AwayFromZero);

                if (sub.TradeBorder == (int)TradeBorderEnum.内贸)
                {
                    //内贸毛重==净重
                    detail.IntegerAmount = detail.NetAmount;
                }
                else
                {
                    //整笔开票情况下,外贸毛重等于库存流水毛重;分笔开票情况下,等于净重。
                    result = stockLogDAL.Get(user, detail.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 (stockLog.NetAmount == detail.NetAmount)
                    {
                        detail.IntegerAmount = stockLog.GrossAmount;
                    }
                    else
                    {
                        detail.IntegerAmount = detail.NetAmount;
                    }
                }
            }

            //主表数据:毛重、净重、均价、总额计算
            decimal sumGrossAmount = details.Sum(temp => temp.IntegerAmount);
            invoiceBusiness.IntegerAmount = sumGrossAmount;

            decimal sumNetAmount = details.Sum(temp => temp.NetAmount);
            if (sumNetAmount != invoiceBusiness.NetAmount)
            {
                result.ResultStatus = -1;
                result.Message = "明细净重之和与总净重不相等";
                return result;
            }

            decimal sumBala = details.Sum(temp => temp.Bala);
            if (Math.Abs(sumBala - invoice.InvoiceBala) >= 1)
            {
                result.ResultStatus = -1;
                result.Message = "明细金额之和与总金额不相等";
                return result;
            }

            decimal avgPrice = Math.Round(sumBala / sumNetAmount, 4, MidpointRounding.AwayFromZero);
            if (avgPrice != invoiceBusiness.UnitPrice)
            {
                result.ResultStatus = -1;
                result.Message = "计算均价错误";
                return result;
            }

            //验证是否已开临票
            //result = this.businessinvoiceDAL.LoadBySubId(user, invoiceBusiness.SubContractId, InvoiceTypeEnum.ProvisionalInvoice);
            //if (result.ResultStatus != 0)
            //    return result;

            //List<Model.BusinessInvoice> proInvoices = result.ReturnValue as List<Model.BusinessInvoice>;
            //if (proInvoices == null)
            //{
            //    result.ResultStatus = -1;
            //    result.Message = "验证是否拥有临票失败";
            //    return result;
            //}
            //if (proInvoices.Count > 0)
            //{
            //    result.ResultStatus = -1;
            //    result.Message = "当前合约已拥有临票,直接终票失败";
            //    return result;
            //}

            result = this.CreateBusinessInvoice(user, invoice, invoiceBusiness, details, InvoiceTypeEnum.DirectFinalInvoice);

            return result;
        }
Esempio n. 11
0
        public ResultModel CreateBusinessInvoice(UserModel user, Operate.Model.Invoice invoice, BusinessInvoice invoiceBusiness, List<BusinessInvoiceDetail> details, InvoiceTypeEnum invoiceType)
        {
            ResultModel result = new ResultModel();

            try
            {
                BusinessInvoiceDAL businessInvoiceDAL = new BusinessInvoiceDAL();
                InvoiceDAL invoiceDAL = new InvoiceDAL();
                BusinessInvoiceDetailDAL detailDAL = new BusinessInvoiceDetailDAL();
                ContractSubDAL subDAL = new ContractSubDAL();
                StockReceiptDetailDAL stockReceiptDetailDAL = new StockReceiptDetailDAL();
                SubDetailDAL subDetailDAL = new SubDetailDAL();

                using (TransactionScope scope = new TransactionScope(TransactionScopeOption.Required))
                {
                    //验证子合约
                    result = subDAL.Get(user, invoiceBusiness.SubContractId);
                    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;
                    }

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

                    //获取子合约明细
                    result = subDetailDAL.GetDetailBySubId(user, sub.SubId);
                    if (result.ResultStatus != 0)
                        return result;

                    SubDetail subDetail = result.ReturnValue as SubDetail;
                    if (subDetail == null || subDetail.SubDetailId <= 0)
                    {
                        result.ResultStatus = -1;
                        result.Message = "子合约明细获取失败";
                        return result;
                    }

                    //获取子合约下所有
                    result = this.businessinvoiceDAL.LoadBySubId(user, invoiceBusiness.SubContractId, invoiceType);
                    if (result.ResultStatus != 0)
                        return result;

                    List<BusinessInvoice> bis = result.ReturnValue as List<BusinessInvoice>;
                    decimal sumNetAmount = bis.Sum(temp => temp.NetAmount);
                    decimal maxNetAmount = sub.SignAmount * (1 + subDetail.MoreOrLess);
                    //if (maxNetAmount < sumNetAmount + invoiceBusiness.NetAmount)
                    //{
                    //    result.ResultStatus = -1;
                    //    result.Message = "开票重量超额";
                    //    return result;
                    //}

                    //新增发票主表
                    int invoiceId = 0;
                    invoice.InvoiceType = (int)invoiceType;
                    invoice.InvoiceStatus = StatusEnum.已录入;
                    Corporation outCorp = UserProvider.Corporations.FirstOrDefault(temp => temp.CorpId == invoice.OutCorpId);
                    if (outCorp == null || outCorp.CorpId <= 0)
                    {
                        result.ResultStatus = -1;
                        result.Message = "开票公司信息错误";
                        return result;
                    }
                    invoice.OutCorpName = outCorp.CorpName;

                    Corporation inCorp = UserProvider.Corporations.FirstOrDefault(temp => temp.CorpId == invoice.InCorpId);
                    if (inCorp == null || inCorp.CorpId <= 0)
                    {
                        result.ResultStatus = -1;
                        result.Message = "收票公司信息错误";
                        return result;
                    }
                    invoice.InCorpName = inCorp.CorpName;

                    result = invoiceDAL.Insert(user, invoice);
                    if (result.ResultStatus != 0)
                        return result;

                    if (result.ReturnValue == null || !int.TryParse(result.ReturnValue.ToString(), out invoiceId))
                    {
                        result.ResultStatus = -1;
                        result.Message = "发票添加失败";
                        return result;
                    }

                    //新增业务发票表
                    int businessInvoiceId = 0;
                    invoiceBusiness.InvoiceId = invoiceId;
                    result = businessInvoiceDAL.Insert(user, invoiceBusiness);
                    if (result.ResultStatus != 0)
                        return result;

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

                    //新增业务发票明细
                    StockLogDAL stockLogDAL = new StockLogDAL();
                    StockDAL stockDAL = new StockDAL();
                    foreach (BusinessInvoiceDetail detail in details)
                    {
                        if (detail.NetAmount != 0 && detail.StockId > 0)
                        {
                            //验证库存
                            result = stockDAL.Get(user, detail.StockId);
                            if (result.ResultStatus != 0)
                                return result;
                            Stock stock = result.ReturnValue as 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;

                            StockLog stockLog = result.ReturnValue as 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 != invoiceBusiness.SubContractId)
                            {
                                result.ResultStatus = -1;
                                result.Message = "合约与库存流水不匹配";
                                return result;
                            }

                            detail.DetailStatus = StatusEnum.已生效;
                            detail.InvoiceId = invoiceId;
                            detail.BusinessInvoiceId = businessInvoiceId;
                            detail.StockId = stockLog.StockId;
                            detail.StockLogId = stockLog.StockLogId;

                            if (invoice.InvoiceType == (int)InvoiceTypeEnum.SuppleFinalInvoice)
                            {
                                //获取当前流水回执信息
                                result = stockReceiptDetailDAL.LoadByStockLogId(user, stockLog.StockLogId);
                                List<StockReceiptDetail> stockReceiptDetails = result.ReturnValue as List<StockReceiptDetail>;
                                if (stockReceiptDetails == null)
                                {
                                    result.ResultStatus = -1;
                                    result.Message = "当前流水未回执,不能补零";
                                    return result;
                                }

                                decimal sumQtyMiss = stockReceiptDetails.Sum(temp => temp.QtyMiss);
                                detail.IntegerAmount = sumQtyMiss;
                                detail.NetAmount = sumQtyMiss;
                            }
                            //else
                            //{
                            //    detail.IntegerAmount = stockLog.GrossAmount;
                            //    detail.NetAmount = stockLog.NetAmount;
                            //}
                            result = detailDAL.Insert(user, detail);
                            if (result.ResultStatus != 0)
                                return result;
                        }
                    }

                    invoice.InvoiceId = invoiceId;
                    if (result.ResultStatus == 0) result.ReturnValue = invoice;

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

            return result;
        }
Esempio n. 12
0
        public ResultModel UpdateDirect(UserModel user, Operate.Model.Invoice invoice, BusinessInvoice invoiceBusiness, List<BusinessInvoiceDetail> details)
        {
            ResultModel result = new ResultModel();
            ContractSubDAL subDAL = new ContractSubDAL();
            result = subDAL.Get(user, invoiceBusiness.SubContractId);
            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;
            }

            StockLogDAL stockLogDAL = new StockLogDAL();
            //明细表数据:毛重、金额计算
            foreach (BusinessInvoiceDetail detail in details)
            {
                detail.Bala = Math.Round(detail.NetAmount * detail.UnitPrice, 2, MidpointRounding.AwayFromZero);

                if (sub.TradeBorder == (int)TradeBorderEnum.内贸)
                {
                    //内贸毛重==净重
                    detail.IntegerAmount = detail.NetAmount;
                }
                else
                {
                    //整笔开票情况下,外贸毛重等于库存流水毛重;分笔开票情况下,等于净重。
                    result = stockLogDAL.Get(user, detail.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 (stockLog.NetAmount == detail.NetAmount)
                    {
                        detail.IntegerAmount = stockLog.GrossAmount;
                    }
                    else
                    {
                        detail.IntegerAmount = detail.NetAmount;
                    }
                }
            }

            //主表数据:毛重、净重、均价、总额计算
            decimal sumGrossAmount = details.Sum(temp => temp.IntegerAmount);
            invoiceBusiness.IntegerAmount = sumGrossAmount;

            decimal sumNetAmount = details.Sum(temp => temp.NetAmount);
            if (sumNetAmount != invoiceBusiness.NetAmount)
            {
                result.ResultStatus = -1;
                result.Message = "明细净重之和与总净重不相等";
                return result;
            }

            decimal sumBala = details.Sum(temp => temp.Bala);
            if (Math.Abs(sumBala - invoice.InvoiceBala) >=1)
            {
                result.ResultStatus = -1;
                result.Message = "明细金额之和与总金额不相等";
                return result;
            }

            decimal avgPrice = Math.Round(sumBala / sumNetAmount, 4, MidpointRounding.AwayFromZero);
            if (avgPrice != invoiceBusiness.UnitPrice)
            {
                result.ResultStatus = -1;
                result.Message = "计算均价错误";
                return result;
            }

            return this.UpdateBusinessInvoice(user, invoice, invoiceBusiness, details);
            //ResultModel result = new ResultModel();

            //try
            //{
            //    DAL.BusinessInvoiceDAL businessInvoiceDAL = new BusinessInvoiceDAL();
            //    NFMT.Operate.DAL.InvoiceDAL invoiceDAL = new Operate.DAL.InvoiceDAL();
            //    DAL.BusinessInvoiceDetailDAL detailDAL = new BusinessInvoiceDetailDAL();

            //    using (System.Transactions.TransactionScope scope = new TransactionScope(TransactionScopeOption.Required))
            //    {
            //        //验证发票
            //        if (invoiceBusiness.BusinessInvoiceId <= 0)
            //        {
            //            result.Message = "直发票不存在";
            //            return result;
            //        }

            //        result = businessinvoiceDAL.Get(user, invoiceBusiness.BusinessInvoiceId);
            //        if (result.ResultStatus != 0)
            //            return result;

            //        NFMT.Invoice.Model.BusinessInvoice resultBusinessInvoice = result.ReturnValue as NFMT.Invoice.Model.BusinessInvoice;
            //        if (resultBusinessInvoice == null || resultBusinessInvoice.BusinessInvoiceId <= 0)
            //        {
            //            result.ResultStatus = -1;
            //            result.Message = "发票不存在";
            //            return result;
            //        }

            //        //更新发票
            //        resultBusinessInvoice.IntegerAmount = invoiceBusiness.IntegerAmount;
            //        resultBusinessInvoice.NetAmount = invoiceBusiness.NetAmount;
            //        resultBusinessInvoice.VATRatio = invoiceBusiness.VATRatio;
            //        resultBusinessInvoice.VATBala = invoiceBusiness.VATBala;
            //        resultBusinessInvoice.UnitPrice = invoiceBusiness.UnitPrice;

            //        resultBusinessInvoice.Status = StatusEnum.已录入;

            //        result = businessinvoiceDAL.Update(user, resultBusinessInvoice);
            //        if (result.ResultStatus != 0)
            //            return result;

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

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

            //        //更新发票
            //        resultInvoice.InvoiceDate = invoice.InvoiceDate;
            //        resultInvoice.InvoiceName = invoice.InvoiceName;
            //        resultInvoice.InvoiceBala = invoice.InvoiceBala;
            //        resultInvoice.OutCorpId = invoice.OutCorpId;
            //        resultInvoice.InCorpId = invoice.InCorpId;
            //        resultInvoice.Memo = invoice.Memo;

            //        result = invoiceDAL.Update(user, resultInvoice);
            //        if (result.ResultStatus != 0)
            //            return result;

            //        //获取发票明细
            //        result = detailDAL.Load(user, resultBusinessInvoice.BusinessInvoiceId);
            //        if (result.ResultStatus != 0)
            //            return result;

            //        List<Model.BusinessInvoiceDetail> resultDetails = result.ReturnValue as List<Model.BusinessInvoiceDetail>;
            //        if (resultDetails == null)
            //        {
            //            result.ResultStatus = -1;
            //            result.Message = "获取发票明细失败";
            //            return result;
            //        }

            //        //作废发票明细
            //        foreach (Model.BusinessInvoiceDetail detail in resultDetails)
            //        {
            //            if (detail.DetailStatus == StatusEnum.已生效)
            //                detail.DetailStatus = StatusEnum.已录入;

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

            //        //新增发票明细
            //        foreach (Model.BusinessInvoiceDetail detail in details)
            //        {
            //            if (detail.NetAmount > 0 && detail.Bala > 0 && detail.StockId > 0)
            //            {
            //                detail.DetailStatus = StatusEnum.已生效;
            //                detail.InvoiceId = invoice.InvoiceId;
            //                detail.BusinessInvoiceId = invoiceBusiness.BusinessInvoiceId;
            //                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;
        }