public async Task <IActionResult> Reviewer([FromRoute] Guid id) { if (!ModelState.IsValid) { return(BadRequest(ModelState)); } LoanVoucher v = _context.LoanVouchers.Include(p => p.Records).Include(p => p.Lender).FirstOrDefault(p => p.Records.Any(l => l.ID == id)); if (v == null) { return(this.AlpsActionWarning("无此ID")); } v.ReviewerRecorder(id, User.Identity.Name); await _context.SaveChangesAsync(); var p = v.Records.FirstOrDefault(p => p.ID == id); var dto = new LoanRecordReviewerDto { IsInvalid = p.IsInvalid, LoanVoucherID = p.LoanVoucherID, ID = p.ID, Date = p.OperateTime, Name = v.Lender.Name, Amount = p.Amount, Interest = p.Interest, Type = p.Type, Reviewer = p.Reviewer == null ? string.Empty : p.Reviewer, ReviewTime = p.ReviewTime }; return(this.AlpsActionOk(dto)); }
void LoanMgrSeed(AlpsContext context) { Lender lender = Lender.Create("张三", "350182123", "13905911234"); context.Lenders.Add(lender); lender = Lender.Create("李四", "35018212121213", "13905911231"); context.Lenders.Add(lender); lender = Lender.Create("王五", "3501821234121212", "13905911232"); context.Lenders.Add(lender); // LoanVoucher loanvoucher = LoanVoucher.Create(lender.ID, 1000000, 0.006m, "456123", new DateTimeOffset(DateTime.Now.AddMonths(-4))); // context.LoanVouchers.Add(loanvoucher); // loanvoucher = LoanVoucher.Create(lender.ID, 2000000, 0.006m, "456124"); // context.LoanVouchers.Add(loanvoucher); // loanvoucher.Withdraw(10000); // context.SaveChanges(); LoanVoucher voucher = LoanVoucher.Create(lender.ID, "系统"); voucher.Deposit(DateTimeOffset.Now.AddMonths(-4), 100000, "系统测试", "系统测试"); context.LoanVouchers.Add(voucher); voucher = LoanVoucher.Create(lender.ID, "系统"); voucher.Deposit(DateTimeOffset.Now.AddDays(-4), 200000, "系统测试", "系统测试"); context.LoanVouchers.Add(voucher); context.SaveChanges(); }
public IActionResult GetSettleInteresetPrintInfo([FromRoute] string id) { var dto = new SettleInterestPrintDto { Lender = id, Interest = 0, Date = DateTimeOffset.Now }; var list = _context.LoanVouchers.Where(p => p.Lender.Name == id).SelectMany(p => p.Records).Where(p => p.Type == LoanRecordType.SettleInterest && p.OperateTime.Date == DateTimeOffset.Now.Date && !p.IsInvalid); dto.Amount = list.Sum(p => p.Amount); dto.Interest = list.Sum(p => p.Interest); dto.EndDate = LoanVoucher.GetSettlableDate().AddDays(-1); return(this.AlpsActionOk(dto)); }
private LoanVoucherDetailDto MapToDetailDto(LoanVoucher loanVoucher) { LoanVoucherDetailDto dto = new LoanVoucherDetailDto(); dto.OperateTime = loanVoucher.DepositTime; dto.Lender = loanVoucher.Lender.Name; dto.Amount = loanVoucher.Amount; dto.DepositAmount = loanVoucher.DepositAmount; dto.Isinvalid = loanVoucher.IsInvalid; dto.Records = loanVoucher.Records.Select(p => new LoanRecordDto { IsInvalid = p.IsInvalid, LoanVoucherID = p.LoanVoucherID, ID = p.ID, Date = p.OperateTime, Name = p.LoanVoucher.Lender.Name, Amount = p.Amount, Interest = p.Interest, Type = p.Type }).ToList(); return(dto); }
public async Task <IActionResult> Deposit([FromBody] DepositDto dto) { if (!ModelState.IsValid) { return(BadRequest(ModelState)); } LoanVoucher v = LoanVoucher.Create(dto.LenderID, User.Identity.Name);// dto.Amount, 0.006m, dto.VoucherNumber, dto.Date); v.Deposit(dto.Date, dto.Amount, dto.Memo, User.Identity.Name); _context.LoanVouchers.Add(v); await _context.SaveChangesAsync(); return(this.AlpsActionOk(v.ID)); }
public async Task <IActionResult> ImportWithdraw([FromBody] ICollection <WithdrawImportDto> list) { if (!ModelState.IsValid) { return(BadRequest(ModelState)); } foreach (var dto in list) { LoanVoucher v = _context.LoanVouchers.FirstOrDefault(p => p.Lender.Name == dto.Lender && p.DepositTime == dto.DepositDate && p.Amount == dto.DepositAmount); if (v == null) { return(this.AlpsActionError("找不到" + dto.Lender + "在" + dto.DepositDate.ToString() + "的" + dto.DepositAmount.ToString() + "元的条子")); } v.Withdraw(dto.Date, dto.Amount, "", User.Identity.Name, GetInterestRates()); } var rst = await _context.SaveChangesAsync(); return(this.AlpsActionOk(rst)); }
public IActionResult GetLoanVoucherInfo([FromRoute] Guid id) { var interestRates = _context.LoanSettings.SelectMany(p => p.InterestRates); var loanVoucher = _context.LoanVouchers.Include(p => p.Lender).FirstOrDefault(p => p.ID == id); LoanVoucherInfoDto dto = new LoanVoucherInfoDto { ID = loanVoucher.ID, InterestDays = LoanVoucher.GetInterestDay(loanVoucher.InterestSettlementDate, DateTime.Now), Name = loanVoucher.Lender.Name, Date = loanVoucher.DepositTime, InterestSettlementDate = loanVoucher.InterestSettlementDate, Amount = loanVoucher.Amount, InterestRate = loanVoucher.InterestRate, SettlableInterestDays = LoanVoucher.GetInterestDay(loanVoucher.InterestSettlementDate, LoanVoucher.GetSettlableDate()), SettlableInterest = loanVoucher.CalculateVoucherInterest(interestRates.ToList()) }; return(this.AlpsActionOk(dto)); }
public async Task <IActionResult> Withdraw([FromBody] WithdrawDto dto) { if (!ModelState.IsValid) { return(BadRequest(ModelState)); } LoanVoucher v = _context.LoanVouchers.Include(p => p.Records).FirstOrDefault(p => p.ID == dto.LoanVoucherID); if (v == null) { return(this.AlpsActionWarning("无此ID")); } if (v.Amount < dto.Amount) { return(this.AlpsActionError("取款金额超过存款金额")); } var r = v.Withdraw(dto.OperateTime, dto.Amount, dto.Memo, User.Identity.Name, GetInterestRates(), DoGetLoanSetting().MinDepositDay); await _context.SaveChangesAsync(); return(this.AlpsActionOk(r.ID)); }
public async Task <IActionResult> ImportLoanVoucher([FromBody] ICollection <VoucherImportDto> list) { if (!ModelState.IsValid) { return(BadRequest(ModelState)); } foreach (var dto in list) { Lender lender = _context.Lenders.FirstOrDefault(p => p.Name == dto.Lender); if (lender == null) { return(this.AlpsActionError("找不到存款人:" + dto.Lender)); } //throw new DomainException("找不到存款人:" + dto.Lender); LoanVoucher v = LoanVoucher.Create(lender.ID, User.Identity.Name);// dto.Amount, 0.006m, dto.VoucherNumber, dto.Date); v.Deposit(dto.Date, dto.Amount, dto.Memo, User.Identity.Name); v.ReWriteVoucher(dto.ReWriteTime); _context.LoanVouchers.Add(v); } var rst = await _context.SaveChangesAsync(); return(this.AlpsActionOk(rst)); }
public async Task <IActionResult> SettleInterest([FromRoute] Guid id) { if (!ModelState.IsValid) { return(BadRequest(ModelState)); } LoanVoucher v = _context.LoanVouchers.Include(p => p.Records).FirstOrDefault(p => p.ID == id); if (v == null) { return(this.AlpsActionWarning("无此ID")); } var minDepositDays = DoGetLoanSetting().MinDepositDay; if (v.CanSettleInterest(minDepositDays)) { var interestRates = GetInterestRates(); v.SettleInterest(DateTimeOffset.Now, "", User.Identity.Name, interestRates, minDepositDays); await _context.SaveChangesAsync(); } return(this.AlpsActionOk()); }
public IActionResult TestCalculateInterest([FromBody] TestDaysDto dto) { LoanVoucher voucher = LoanVoucher.Create(Guid.Empty, ""); return(this.AlpsActionOk(voucher.TestCalculateInterest(dto.Rate, dto.StartDate, dto.EndDate, dto.Amount, dto.NotEnoughSubDay))); }