Beispiel #1
0
        public async Task <IActionResult> GenerateBulkInvoices(InvoiceBulkViewModel model)
        {
            try {
                if (ModelState.IsValid)
                {
                    var customers = await _businessManager.GetCustomers(model.Customers.ToArray());

                    var subtotalRange = await _companyBusinessManager.GetSummaryRange(model.SummaryRangeId ?? 0);

                    if (subtotalRange != null)
                    {
                        model.Header = $"{subtotalRange.From}-{subtotalRange.To}";
                        List <InvoiceViewModel> invoices = new List <InvoiceViewModel>();
                        Random random = new Random();

                        foreach (var customer in customers)
                        {
                            var date    = random.NextDate(model.DateFrom, model.DateTo);
                            var invoice = new InvoiceViewModel()
                            {
                                CompanyId  = model.CompanyId,
                                CustomerId = customer.Id,
                                Customer   = _mapper.Map <CustomerViewModel>(customer),
                                Date       = date,
                                DueDate    = date.AddDays(30),
                                No         = $"{date.ToString("mmyy")}_{random.Next(100000, 999999)}",
                                Subtotal   = random.NextDecimal(subtotalRange.From, subtotalRange.To)
                            };
                            invoices.Add(invoice);
                        }
                        model.Invoices = invoices;

                        string html = await _viewRenderService.RenderToStringAsync("_BulkInvoicePartial", model);

                        return(Ok(html));
                    }
                    else
                    {
                        return(BadRequest());
                    }
                }
            } catch (Exception er) {
                Console.WriteLine(er.Message);
            }
            return(Ok(model));
        }
Beispiel #2
0
        public async Task <IActionResult> CreateBulkInvoices(InvoiceBulkViewModel model)
        {
            if (!ModelState.IsValid)
            {
                return(BadRequest(model));
            }

            if (model.Invoices != null && model.Invoices?.Count != 0)
            {
                var invoiceList = _mapper.Map <List <InvoiceDto> >(model.Invoices);

                var result = await _businessManager.CreateInvoice(invoiceList);

                if (result == null || result.Count == 0)
                {
                    return(BadRequest(model));
                }
                return(Ok(result));
            }

            return(Ok(""));
        }