public ActionResult Index() { ChallanViewModel billViewModel = new ChallanViewModel(); //Read all customers billViewModel = GetData(); return(View(billViewModel)); }
public ActionResult AddMore(ChallanViewModel challanViewModel) { ModelState.Clear(); challanViewModel.Customers = new SelectList( _context.Customers .Select(x => new { x.Id, x.Name }) .OrderBy(x => x.Name) .ToList(), "Id", "Name", challanViewModel.Customer); challanViewModel.Challans.Add(new Challan()); return(View("Create", challanViewModel)); }
public ActionResult Remove(ChallanViewModel challanViewModel, int id) { ModelState.Clear(); challanViewModel.Customers = new SelectList( _context.Customers .Select(x => new { x.Id, x.Name }) .OrderBy(x => x.Name) .ToList(), "Id", "Name", challanViewModel.Customer); //challanViewModel.Challans.Remove(challanViewModel.Challans.Where(x => x.Id == id).FirstOrDefault()); challanViewModel.Challans.RemoveAt(id); return(View("Create", challanViewModel)); }
// GET: Challans public ActionResult Index(int id = 0) { ChallanViewModel cvm = new ChallanViewModel { Customer = id, Customers = new SelectList( _context.Customers .Select(x => new { x.Id, x.Name }) //.OrderBy(x => x.Name) .ToList(), "Id", "Name", id), Challans = _context.Challans .Where(x => x.CustomerId == id) .OrderByDescending(x => x.ChallanDate).ToList() }; return(View(cvm)); }
public ActionResult Create() { SelectList CustList = new SelectList( _context.Customers .Select(x => new { x.Id, x.Name }) .OrderBy(x => x.Name) .ToList(), "Id", "Name", 0); List <Challan> Challans = new List <Challan>(); Challans.Add(new Challan()); ChallanViewModel cvm = new ChallanViewModel { Customer = 0, Customers = CustList, Challans = Challans }; return(View(cvm)); }
public ActionResult Create(ChallanViewModel challanViewModel) { if (ModelState.IsValid) { foreach (Challan ch in challanViewModel.Challans) { ch.CustomerId = challanViewModel.Customer; } _context.Challans.AddRange(challanViewModel.Challans); _context.SaveChanges(); ChallanViewModel cvm = new ChallanViewModel { Customer = challanViewModel.Customer, Customers = new SelectList( _context.Customers .Select(x => new { x.Id, x.Name }) //.OrderBy(x => x.Name) .ToList(), "Id", "Name", challanViewModel.Customer), Challans = _context.Challans .Where(x => x.CustomerId == challanViewModel.Customer) .OrderBy(x => x.ChallanDate).ToList() }; return(View("Index", cvm)); } else { challanViewModel.Customers = new SelectList( _context.Customers .Select(x => new { x.Id, x.Name }) .OrderBy(x => x.Name) .ToList(), "Id", "Name", challanViewModel.Customer); return(View(challanViewModel)); } }
private ChallanViewModel GetData() { ChallanViewModel billViewModel = new ChallanViewModel(); var customers = customerDAL.ReadAllCustomer(); billViewModel.Customer.Customers = new List <CustomerViewModel>(); billViewModel.Customer.Customers = customers.ConvertAll(x => new CustomerViewModel { CustomerId = x.CustomerId, CustomerName = x.CustomerName, CustomerAddress = x.CustomerAddress, TaxName = x.tax.TaxName, TaxValue = x.tax.Value }); //Read all categories var lstCategory = categoryDAL.ReadAllCategory(); billViewModel.lstChallanDetails = new List <ChallanDetails>(); billViewModel.lstChallanDetails = lstCategory.ConvertAll(x => new ChallanDetails { CategoryId = x.CategoryId, CategoryName = x.CategoryName, Rate = x.Rate, Discount = x.Discount }); var taxes = taxDAL.ReadAllTax(); billViewModel.ecess = taxes.Where(x => x.TaxId == (int)TaxType.ECESS).FirstOrDefault().Value; billViewModel.shecess = taxes.Where(x => x.TaxId == (int)TaxType.SHECESS).FirstOrDefault().Value; billViewModel.freight = taxes.Where(x => x.TaxId == (int)TaxType.Freight).FirstOrDefault().Value; billViewModel.tcs = taxes.Where(x => x.TaxId == (int)TaxType.TCS).FirstOrDefault().Value; return(billViewModel); }
public ActionResult Index(ChallanViewModel model) { List <ChallanDetails> challanDetails = new List <ChallanDetails>(); Challan challan = new Challan(); decimal grandTotal = 0; if (ModelState.IsValid) { foreach (var item in model.lstChallanDetails) { ChallanDetails challanDetail = new ChallanDetails(); decimal amt = Convert.ToDecimal(item.Rate * item.Quantity); amt -= Convert.ToDecimal(amt * item.Discount) / 100; grandTotal += amt; challanDetail.CategoryId = item.CategoryId; challanDetail.Rate = item.Rate; challanDetail.Discount = item.Discount; challanDetail.Quantity = item.Quantity; challanDetails.Add(challanDetail); } model.AmountWithoutTax = grandTotal; if (model.vat != 0) { decimal ecess = (grandTotal * model.ecess) / 100; decimal shecess = (grandTotal * model.shecess) / 100; decimal tcs = (grandTotal * model.tcs) / 100; decimal freight = (grandTotal * model.freight) / 100; decimal vat = (grandTotal * model.vat) / 100; model.TaxAmount = ecess + shecess + tcs + freight + vat; } else { decimal ecess = (grandTotal * model.ecess) / 100; decimal shecess = (grandTotal * model.shecess) / 100; decimal tcs = (grandTotal * model.tcs) / 100; decimal freight = (grandTotal * model.freight) / 100; decimal cst = (grandTotal * model.cst) / 100; model.TaxAmount = ecess + shecess + tcs + freight + cst; } model.TotalAmount = model.AmountWithoutTax + model.TaxAmount; challan.AmountWithoutTax = model.AmountWithoutTax; challan.TaxAmount = model.TaxAmount; challan.TotalAmount = model.TotalAmount; challan.ecess = model.ecess; challan.shecess = model.shecess; challan.cst = model.cst; challan.vat = model.vat; challan.freight = model.freight; challan.tcs = model.tcs; challan.CustomerId = model.CustomerId; challan.Remarks = model.Remarks; challan.CompanyId = model.CompanyId; challanDAL.Create(challan, challanDetails); TempData["SuccessMsg"] = "Challan Created Successfully"; return(RedirectToAction("Index")); } model = GetData(); return(View(model)); }