public async Task <IActionResult> CreatePaymentsView([FromQuery] long[] id) { if (id.Length > 0) { var invoices = await _businessManager.GetInvoices(id); Random rd = new Random(); var payments = invoices.Select(x => new PaymentViewModel() { No = string.Format("PMNT_{0}", rd.NextLong(11111, 99999).ToString()), Amount = x.Subtotal - x.Payments.TotalAmount(), CustomerId = x.CustomerId, Date = DateTime.Now, InvoiceId = x.Id, InvoiceNo = x.No, InvoiceAmount = x.Subtotal * (1 + x.TaxRate / 100), }).ToList(); var model = new BulkPaymentViewModel() { DateFrom = DateTime.Now.FirstDayOfMonth(), DateTo = DateTime.Now.LastDayOfMonth(), CompanyId = 0, Payments = payments, Invoices = id.ToList() }; string html = _viewRenderService.RenderToStringAsync("_PaymentsPartial", model).Result; return(Ok(html)); } return(BadRequest("No items selected")); }
public async Task <IActionResult> GenerateBulkInvoice(BulkPaymentViewModel model) { try { if (ModelState.IsValid) { Random rd = new Random(); byte[] bytes = new byte[4]; var invoices = await _businessManager.GetInvoices(model.Invoices.ToArray()); var invoiceList = _mapper.Map <List <InvoiceListViewModel> >(invoices); //if(subtotalRange != null) { // model.Header = $"{subtotalRange.From}-{subtotalRange.To}"; List <PaymentViewModel> payments = new List <PaymentViewModel>(); Random random = new Random(); foreach (var invoice in invoices) { rd.NextBytes(bytes); var date = random.NextDate(model.PaymentDateFrom, model.PaymentDateTo); var invoiceAmount = invoice.Subtotal * (1 + invoice.TaxRate / 100); var payment = new PaymentViewModel() { No = BitConverter.ToString(bytes).Replace("-", ""), CustomerId = invoice.Customer?.Id ?? 0, InvoiceId = invoice.Id, InvoiceNo = invoice.No, InvoiceAmount = invoiceAmount, Date = date, Amount = invoiceAmount - invoice.Payments.TotalAmount() }; payments.Add(payment); } model.Payments = payments; string html = _viewRenderService.RenderToStringAsync("_BulkPaymentPartial", model).Result; return(Ok(html)); //} else { // return BadRequest(); //} } } catch (Exception er) { Console.WriteLine(er.Message); } return(Ok(model)); }
public async Task <IActionResult> CreatePayments([FromBody] BulkPaymentViewModel model) { if (!ModelState.IsValid) { return(BadRequest(model)); } var invoiceList = _mapper.Map <List <PaymentDto> >(model.Payments); var result = await _businessManager.CreatePayment(invoiceList); if (result == null || result.Count == 0) { return(BadRequest(model)); } return(Ok(result)); }
// GET: Payment/Bulk public async Task <ActionResult> Bulk() { var companies = await _companyBusinessManager.GetCompanies(); ViewBag.Companies = companies.Select(x => new SelectListItem() { Text = x.Name, Value = x.Id.ToString() }).ToList(); var selectedCompany = companies.FirstOrDefault(); var model = new BulkPaymentViewModel() { CompanyId = selectedCompany?.Id ?? 0 }; var invoices = await _businessManager.GetUnpaidInvoicesByCompanyId(selectedCompany?.Id ?? 0, model.DateFrom, model.DateTo); ViewBag.Invoices = _mapper.Map <List <InvoiceListViewModel> >(invoices); return(View(model)); }