Exemplo n.º 1
0
 public HttpResponseMessage GetInvoiceSubject(InvoiceViewModel invoice)
 {
     _dataResult.Code = ResponseStatusCode.Success;
     _dataResult.Msg = BusinessResourceMessage.Success;
     _dataResult.Data = _invoiceService.GetInvoiceSubject(invoice.SpecialId, LoginUser.ID);
     return Request.CreateResponse(HttpStatusCode.OK, _dataResult);
 }
Exemplo n.º 2
0
 public HttpResponseMessage AuditInvoices(InvoiceViewModel invoice)
 {
     _invoiceService.AuditInvoices(invoice, LoginUser.ID);
     _dataResult.Code = ResponseStatusCode.Success;
     _dataResult.Msg = BusinessResourceMessage.Success;
     return Request.CreateResponse(HttpStatusCode.OK, _dataResult);
 }
Exemplo n.º 3
0
        /// <summary>
        /// 申请发票
        /// </summary>
        /// <param name="invoice"></param>
        /// <param name="operateUserId"></param>
        public void ApplyInvoice(InvoiceViewModel invoice, int operateUserId)
        {
            var loginUser = RedisHelp.GetLoginUserCacheNotNull(operateUserId);
            #region 安全验证
            if (loginUser.Type == UserType.Company)
            {
                throw new DataOperationPermissions("无此操作权限,总公司账号不能操作发票");
            }
            else if (loginUser.Type == UserType.Branch)
            {
                throw new DataOperationPermissions("无此操作权限,分社账号不能申请发票");
            }
            else if (loginUser.Type == UserType.SpecialLine)
            {
                if (loginUser.SpecialId.HasValue && loginUser.SpecialId != invoice.SpecialId)
                {
                    throw new DataOperationPermissions("无此操作权限,专线只能申请自己的发票");
                }
            }
            #endregion
            #region 数据验证
            if (invoice.Money <= 0)
                throw new DataValidationException("发票金额不能小于等于0");
            if (string.IsNullOrEmpty(invoice.Content))
                throw new DataValidationException("发票详细不能为空");
            if (!invoice.Content.ValidateLen(500))
                throw new DataValidationException("发票详细填写过多,请分批申请");
            if (invoice.ParValueTime < DateTime.Parse("1753-01-01"))
                throw new DataValidationException("请填写正确的票面日期");
            #endregion
            #region 欠款判断

            var special = _specialRepository.GetModel().Include(p => p.SpecialCapital)
                .Include(p => p.Branch)
                .SingleOrDefault(p => p.ID == invoice.SpecialId);
            if (special == null)
                throw new BusinessException("专线不存在");
            if (special.Status == SpecialStatus.Freeze)
            {
                throw new BusinessException("所属专线已被冻结");
            }
            if (special.Status == SpecialStatus.AccountCancellation)
            {
                throw new BusinessException("所属专线已被销户");
            }
            //专线已开票+当前开票+当前专线所有待审核金额总数-专线已收款>=专线欠款最大额度
            //得到当前专线所有待审核金额总数
            var sumMoney = _invoiceRepository.GetModel(p => p.SpecialId == special.ID && p.Status == InvoiceStatus.WaitInvoice).Sum(s => (decimal?)s.Money) ?? 0;
            if (special.SpecialCapital.InvoiceSend + invoice.Money + sumMoney - special.SpecialCapital.Gathering >= special.Branch.ArrearsTotal)
            {
                throw new BusinessException("你提交发票金额已超出设置的最大欠款额度,暂时不能提交发票申请");
            }
            #endregion

            Invoice model = new Invoice();

            model.Status = InvoiceStatus.WaitInvoice;
            model.SpecialId = invoice.SpecialId;
            model.SpecialName = special.Name;

            model.SellerId = invoice.SellerId;
            model.Title = invoice.SellerSupplier.Name;
            model.ParValueTime = invoice.ParValueTime;
            model.Money = invoice.Money;
            model.Content = invoice.Content;
            model.ApplicantId = loginUser.ID;
            model.ApplicantName = loginUser.Name;
            model.ApplicationTime = DateTime.Now;

            _invoiceRepository.Insert(model);
        }
Exemplo n.º 4
0
        /// <summary>
        /// 审核发票
        /// 
        /// 增加已开发票金额
        /// 
        /// 注:
        /// 只有分社与超级管理员用户 能使用此接口
        /// </summary>
        /// <param name="invoice"></param>
        /// <param name="operateUserId"></param>
        public void AuditInvoices(InvoiceViewModel invoice, int operateUserId)
        {
            var loginUser = RedisHelp.GetLoginUserCacheNotNull(operateUserId);
            #region 安全验证
            switch (loginUser.Type)
            {
                case UserType.Company:
                    throw new DataOperationPermissions("无此操作权限,总公司账号不能操作发票");
                case UserType.SpecialLine:
                    throw new DataOperationPermissions("无此操作权限,专线账号不能审核发票");
            }

            #endregion
            if (!string.IsNullOrEmpty(invoice.AuditRemark) && invoice.AuditRemark.Length > 200)
                throw new DataValidationException("备注不能超过200个汉字");
            if (invoice.Status == InvoiceStatus.OpenInvoice)
            {
                if (invoice.Express == null)
                    throw new BusinessException("快递信息不能为空");
                if (!invoice.Express.Number.ValidateLen(50))
                    throw new DataValidationException("快递单号长度必须在1-50字符之间");
                if (!invoice.Express.Name.ValidateLen(50))
                    throw new DataValidationException("快递名称长度必须在1-50字符之间");
                if (invoice.Express.Money <= 0)
                    throw new DataValidationException("快递费用必须大于0");
            }
            else
            {
                if (invoice.Status == InvoiceStatus.DiscardInvoice && string.IsNullOrEmpty(invoice.AuditRemark))
                    throw new DataValidationException("当发票审核为废弃时,备注不能为空");
            }
            if (invoice.Status == InvoiceStatus.WaitInvoice)
                throw new DataValidationException("参数传入错误,当前接口发票状态参数不能为待开具");

            //得到 待开具状态发票
            var model = _invoiceRepository.GetModelTracking()
                .Include(p => p.Express)
                .Include(p => p.Special.SpecialCapital)
                .Include(p => p.Special.Branch)
                .SingleOrDefault(p => p.Status == InvoiceStatus.WaitInvoice && p.ID == invoice.ID);

            if (model == null)
                throw new BusinessException("此发票不存在");
            if (model.Special.SpecialCapital == null)
                throw new BusinessException("此发票所属专线缺少资金信息");
            if (loginUser.Type == UserType.Branch)
            {
                if (model.Special.BranchId != loginUser.BranchId)
                    throw new DataOperationPermissions("无此操作权限,分社账号只能操作自身下属专线发票申请");
            }
            //当状态为废弃时则没有快递信息
            if (invoice.Status == InvoiceStatus.OpenInvoice)
                model.Express = invoice.Express.MapNew<ExpressViewMdoel, Express>();

            model.Status = invoice.Status;
            model.AuditorId = loginUser.ID;
            model.AuditorName = loginUser.Name;
            model.AuditRemark = invoice.AuditRemark;
            model.AuditTime = DateTime.Now;
            #region 增加已开发票金额

            if (model.Status == InvoiceStatus.OpenInvoice)
            {
                //专线已开票+当前开票-专线已收款>=专线欠款最大额度
                if (model.Special.SpecialCapital.InvoiceSend + model.Money - model.Special.SpecialCapital.Gathering >=
                    model.Special.Branch.ArrearsTotal)
                {
                    throw new BusinessException("已超出设置的最大欠款额度,暂时不能审核通过");
                }

                model.Special.SpecialCapital.InvoiceSend = model.Special.SpecialCapital.InvoiceSend + model.Money;
            }

            #endregion

            _invoiceRepository.Update(model);
        }