public ActionResult GenerateBulkInvoice(Models.ViewModels.Administration.CreateBulkInvoice model) { var day = 15; var month = DateTime.Now.Month == 12 ? 1 : DateTime.Now.Month + 1; var year = DateTime.Now.Month == 12 ? DateTime.Now.Year + 1 : DateTime.Now.Year; DateTime invoiceDate = new DateTime(year, month, day); var query = from c in _salesService.GetCustomers() select c; var customers = query.ToList(); var itemAssociationDues = (from i in _inventoryService.GetAllItems().ToList() where (i != null && i.SellDescription.ToLower().Contains("dues")) select i).FirstOrDefault(); var invoices = new List <SalesInvoiceHeader>(); foreach (var customer in customers) { var current = (from si in _salesService.GetSalesInvoices() where si.CustomerId == customer.Id && si.Date.Year == invoiceDate.Year && si.Date.Month == invoiceDate.Month && si.Date.Day == invoiceDate.Day select si).FirstOrDefault(); if (current != null) { return(RedirectToAction("BulkInvoice")); } var invoiceLine = new SalesInvoiceLine(); invoiceLine.ItemId = itemAssociationDues.Id; invoiceLine.Quantity = 1; invoiceLine.Amount = Convert.ToDecimal(itemAssociationDues.Price * invoiceLine.Quantity); invoiceLine.MeasurementId = itemAssociationDues.SmallestMeasurementId.Value; invoiceLine.CreatedBy = User.Identity.Name; invoiceLine.CreatedOn = DateTime.Now; invoiceLine.ModifiedBy = User.Identity.Name; invoiceLine.ModifiedOn = DateTime.Now; var invoice = new SalesInvoiceHeader(); invoice.Date = invoiceDate; invoice.CustomerId = customer.Id; invoice.CreatedBy = User.Identity.Name; invoice.CreatedOn = DateTime.Now; invoice.ModifiedBy = User.Identity.Name; invoice.ModifiedOn = DateTime.Now; invoice.SalesInvoiceLines.Add(invoiceLine); invoices.Add(invoice); } foreach (var invoice in invoices) { _salesService.AddSalesInvoice(invoice, null); } return(RedirectToAction("SalesInvoices", "Sales")); }
public ActionResult BulkInvoice() { var model = new Models.ViewModels.Administration.CreateBulkInvoice(); var itemAssociationDues = (from i in _inventoryService.GetAllItems().ToList() where (i != null && i.SellDescription.ToLower().Contains("dues")) select i).FirstOrDefault(); var day = 15; var month = DateTime.Now.Month == 12 ? 1 : DateTime.Now.Month + 1; var year = DateTime.Now.Month == 12 ? DateTime.Now.Year + 1 : DateTime.Now.Year; DateTime invoiceDate = new DateTime(year, month, day); model.InvoiceDate = invoiceDate; model.DueDate = new DateTime(year, month, day + 5); model.TotalAmountPerInvoice = (decimal)itemAssociationDues.Price; return View(model); }
public ActionResult BulkInvoice() { var model = new Models.ViewModels.Administration.CreateBulkInvoice(); var itemAssociationDues = (from i in _inventoryService.GetAllItems().ToList() where (i != null && i.SellDescription.ToLower().Contains("dues")) select i).FirstOrDefault(); var day = 15; var month = DateTime.Now.Month == 12 ? 1 : DateTime.Now.Month + 1; var year = DateTime.Now.Month == 12 ? DateTime.Now.Year + 1 : DateTime.Now.Year; DateTime invoiceDate = new DateTime(year, month, day); model.InvoiceDate = invoiceDate; model.DueDate = new DateTime(year, month, day + 5); model.TotalAmountPerInvoice = (decimal)itemAssociationDues.Price; return(View(model)); }