public int GetStartingTotalCash() { List <TotalCash> totalCashes = new List <TotalCash>(); List <TotalCash> orderedTotalCashes = TotalCashes.OrderBy(t => t.Date).ToList(); for (int i = 0; i < orderedTotalCashes.Count; i++) { if ((orderedTotalCashes[i].Date <= EndDate && orderedTotalCashes[i].Date >= StartDate) || (orderedTotalCashes[i].Date < StartDate && i + 1 == orderedTotalCashes.Count) || (orderedTotalCashes[i].Date < StartDate && i + 1 < orderedTotalCashes.Count && orderedTotalCashes[i + 1].Date > StartDate)) { totalCashes.Add(orderedTotalCashes[i]); } } if (totalCashes.Count == 0) { return(0); } TotalCash firstTotalCash = totalCashes.First(); if (firstTotalCash.Date >= StartDate) { return(firstTotalCash.Amount); } // get transactions until startdate List <Transaction> transactions = AllTransactions.Where(t => t.CreateDate <StartDate && t.CreateDate> firstTotalCash.Date).ToList(); return(firstTotalCash.Amount - transactions.Select(t => t.Amount).Sum()); }
public int GetCurrentTotalCash() { if (TotalCashes.Count == 0) { return(0); } TotalCash lastTotalCash = TotalCashes.Last(); List <Transaction> transactions = AllTransactions.Where(t => t.CreateDate > lastTotalCash.Date).ToList(); return(lastTotalCash.Amount - transactions.Select(t => t.Amount).Sum()); }
public ActionResult Create(TotalCash totalcash) { if (ModelState.IsValid) { db.TotalCashes.Add(totalcash); db.SaveChanges(); HttpContext.Session["lastCreateDate"] = totalcash.Date; return RedirectToAction("Index"); } object o = HttpContext.Session["lastCreateDate"]; DateTime date = (o == null ? DateTime.Now : (DateTime)o); ViewBag.LastCreateDate = date.ToString("yyyy-MM-dd"); return View(totalcash); }
public ActionResult Edit(TotalCash totalcash) { if (ModelState.IsValid) { db.Entry(totalcash).State = EntityState.Modified; db.SaveChanges(); return RedirectToAction("Index"); } return View(totalcash); }