public ActionResult AddSalesInvoiceLine(Models.ViewModels.Sales.AddSalesInvoice model) { model.Customers = Models.ModelViewHelper.Customers(); model.Items = Models.ModelViewHelper.Items(); model.Measurements = Models.ModelViewHelper.Measurements(); if (model.Quantity > 0) { var item = _inventoryService.GetItemById(model.ItemId); if (!item.Price.HasValue) { ModelState.AddModelError("Amount", "Selling price is not set."); return(View(model)); } Models.ViewModels.Sales.AddSalesInvoiceLine itemModel = new Models.ViewModels.Sales.AddSalesInvoiceLine() { ItemId = model.ItemId, MeasurementId = model.MeasurementId, Quantity = model.Quantity, Discount = model.Discount, Amount = item.Price.Value * model.Quantity, Price = item.Price.Value, }; if (model.AddSalesInvoiceLines.FirstOrDefault(i => i.ItemId == model.ItemId) == null) { model.AddSalesInvoiceLines.Add(itemModel); } } return(View(model)); }
public ActionResult SaveSalesInvoice(Models.ViewModels.Sales.AddSalesInvoice model) { if (model.AddSalesInvoiceLines.Sum(i => i.Amount) == 0 || model.AddSalesInvoiceLines.Count < 1) { model.Customers = Models.ModelViewHelper.Customers(); model.Items = Models.ModelViewHelper.Items(); model.Measurements = Models.ModelViewHelper.Measurements(); ModelState.AddModelError("Amount", "No invoice line"); return(View(model)); } var invoiceHeader = new SalesInvoiceHeader(); var invoiceLines = new List <SalesInvoiceLine>(); foreach (var item in model.AddSalesInvoiceLines) { var Item = _inventoryService.GetItemById(item.ItemId); var invoiceDetail = new SalesInvoiceLine(); invoiceDetail.TaxId = Item.ItemTaxGroupId; invoiceDetail.ItemId = item.ItemId; invoiceDetail.MeasurementId = item.MeasurementId; invoiceDetail.Quantity = item.Quantity; invoiceDetail.Discount = item.Discount; invoiceDetail.Amount = Convert.ToDecimal(item.Quantity * Item.Price); invoiceLines.Add(invoiceDetail); } invoiceHeader.SalesInvoiceLines = invoiceLines; invoiceHeader.CustomerId = model.CustomerId; invoiceHeader.Date = model.Date; invoiceHeader.ShippingHandlingCharge = 4;// model.ShippingHandlingCharge; _salesService.AddSalesInvoice(invoiceHeader, model.SalesOrderId); return(RedirectToAction("SalesInvoices")); }
public ActionResult DeleteInvoiceLineItem(Models.ViewModels.Sales.AddSalesInvoice model) { model.Customers = Models.ModelViewHelper.Customers(); model.Items = Models.ModelViewHelper.Items(); model.Measurements = Models.ModelViewHelper.Measurements(); var request = HttpContext.Request; var deletedItem = request.Form["DeletedLineItem"]; model.AddSalesInvoiceLines.Remove(model.AddSalesInvoiceLines.Where(i => i.ItemId == int.Parse(deletedItem.ToString())).FirstOrDefault()); return(View(model)); }