public async Task <ActionResult <Cashbook> > PostCashbook(Cashbook cashbook) { _context.Cashbook.Add(cashbook); await _context.SaveChangesAsync(); return(CreatedAtAction("GetCashbook", new { id = cashbook.receipt_no }, cashbook)); }
public async Task <IActionResult> PutCashbook(int id, Cashbook cashbook) { if (id != cashbook.receipt_no) { return(BadRequest()); } _context.Entry(cashbook).State = EntityState.Modified; try { await _context.SaveChangesAsync(); } catch (DbUpdateConcurrencyException) { if (!CashbookExists(id)) { return(NotFound()); } else { throw; } } return(NoContent()); }
private void cashbookToolStripMenuItem_Click(object sender, EventArgs e) { Cashbook frm = new Cashbook(); // Pathology.FebrilAntigen frm = new GHospital_Care.Pathology.FebrilAntigen(); frm.MdiParent = this; frm.Show(); }
public async Task <JsonResult> SaveReservation(Reservation e) { var status = false; using (var savedata = db.Database.BeginTransaction()) { try { if (e.Fromdate != null) { if (e.Client != 0 && e.FirstName == "" || e.FirstName == null) { var itemTitle = db.Items.Where(x => x.Id == e.ItemId).Select(z => z.Name).FirstOrDefault(); var customerCode = db.Customer.Where(a => a.Id == e.Client).Select(s => s.Code).FirstOrDefault(); var customerName = db.Customer.Where(a => a.Id == e.Client).Select(s => s.FirstName).FirstOrDefault() + " " + db.Customer.Where(a => a.Id == e.Client).Select(s => s.LastName).FirstOrDefault(); e.ScheduleTitle = customerName + " - " + itemTitle; e.Client = e.Client; } if (e.FirstName != null) { Customer cus = new Customer(); cus.FirstName = e.FirstName; cus.LastName = e.LastName; cus.Mobile = e.Mobile; var itemTitle = db.Items.Where(x => x.Id == e.ItemId).Select(z => z.Name).FirstOrDefault(); var rowcount = db.Customer.Count(); if (rowcount > 0) { var cuscode = db.Customer.Max(x => x.Code); cus.Code = cuscode + 1; } else { cus.Code = 1000; } cus.CreatedOn = DateTime.Now.ToUniversalTime().AddHours(2); cus.Phone = e.Phone; db.Customer.Add(cus); db.SaveChanges(); e.Client = cus.Id; e.ScheduleTitle = e.FirstName + " " + e.LastName + " - " + itemTitle; } var username = User.Identity.GetUserName(); CultureInfo provider = new CultureInfo("en-LB"); e.StartedAt = Convert.ToDateTime(e.Fromdate); e.EndAt = Convert.ToDateTime(e.ToDate); if (e.Advancereservation == true) { var getDate = e.StartedAt; var getDay = e.StartedAt.Day; var theTime = e.StartedAt.TimeOfDay; var theDay = e.StartedAt.DayOfWeek; var lastDayOfMonth = new DateTime(getDate.Year, getDate.Month, DateTime.DaysInMonth(getDate.Year, getDate.Month)); var lastDay = lastDayOfMonth.Day; var days = Convert.ToInt16(lastDay - getDay); var numberOfweek = Convert.ToInt16(days / 7) + 1; List <Reservation> r = new List <Reservation>(); for (int i = 0; i < numberOfweek; i++) { var rv = new Reservation(); if (i == 0) { rv = new Reservation() { StartedAt = e.StartedAt, EndAt = e.EndAt, PaidPrice = e.PaidPrice, //ExtraitemPrice = e.ExtraitemPrice, BillingStatus = e.BillingStatus, //IsBallRent = e.IsBallRent }; } else { rv = new Reservation() { StartedAt = e.StartedAt.AddDays(i * 7), EndAt = e.EndAt.AddDays(i * 7), PaidPrice = 0, //ExtraitemPrice = 0, }; } r.Add(rv); } foreach (var re in r) { re.StartedAt = re.StartedAt; re.EndAt = re.EndAt; re.CreateDate = DateTime.Now.ToUniversalTime().AddHours(2); re.CreateUser = username; re.ScheduleTitle = e.ScheduleTitle; re.Client = e.Client; re.Status = true; if (re.BillingStatus.ToString() == "Confirmed") { re.Color = "green"; } if (re.BillingStatus.ToString() == "Pending" || re.BillingStatus.ToString() == null) { re.Color = "orange"; } if (e.Price != 0) { re.ScheduleNote = "Price: " + re.Price.ToString() + " Total : " + re.TotalPrice.ToString(); } re.BillingStatus = re.BillingStatus; re.Price = e.Price; re.PaidPrice = re.PaidPrice; re.ExtraitemPrice = e.ExtraitemPrice; re.IsBallRent = e.IsBallRent; re.ItemId = e.ItemId; re.Note = e.Note; db.Reservation.Add(re); db.SaveChanges(); Transaction t = new Transaction(); t.Id = Guid.NewGuid(); t.CreatedOn = DateTime.Now.ToUniversalTime().AddHours(2); t.UserId = username; var count = db.Transaction.Count(); if (count > 0) { var cuscode = db.Transaction.Max(x => x.VoucherNo); t.VoucherNo = cuscode + 1; } else { t.VoucherNo = 1000; } t.VoucherType = "Reservation"; t.TrasactionalAmount = re.Price + Convert.ToDecimal(e.ExtraitemPrice) + Convert.ToDecimal(re.PaidPrice); t.Narration = re.ScheduleTitle + " - " + re.StartedAt.ToString() + " to " + re.EndAt.ToString(); t.DebitAmount = Convert.ToDecimal(re.PaidPrice); t.CreditAmount = re.Price + Convert.ToDecimal(e.ExtraitemPrice); t.TransactionDate = re.StartedAt; t.CreatedOn = DateTime.Now.ToUniversalTime().AddHours(2); t.Client = re.Client; t.ReservationId = re.Id; db.Transaction.Add(t); db.SaveChanges(); if (re.PaidPrice == null) { re.PaidPrice = 0; } if (re.PaidPrice != 0) { Cashbook tc = new Cashbook(); tc.Id = Guid.NewGuid(); tc.CreatedOn = DateTime.Now.ToUniversalTime().AddHours(2); tc.UserId = username; var co = db.Cashbook.Count(); if (co > 0) { var cuscode = db.Cashbook.Max(x => x.VoucherNo); tc.VoucherNo = cuscode + 1; } else { tc.VoucherNo = 1000; } tc.Client = t.Client; tc.DebitAmount = t.DebitAmount; tc.CreditAmount = 0; tc.Narration = t.Narration; tc.ReservationId = re.Id; tc.VoucherType = "Cash Reservation"; tc.TrasactionalAmount = re.Price + Convert.ToDecimal(e.ExtraitemPrice) + Convert.ToDecimal(re.PaidPrice);; if (tc.DebitAmount == null) { tc.DebitAmount = 0; } if (tc.CreditAmount == null) { tc.CreditAmount = 0; } tc.TransactionDate = re.StartedAt; db.Cashbook.Add(tc); db.SaveChanges(); } var cBalance = db.Customer.Where(x => x.Id == e.Client).Select(s => s.Balance).FirstOrDefault(); Customer c = new Customer(); c = db.Customer.FirstOrDefault(f => f.Id == e.Client); c.Balance = Convert.ToDecimal(cBalance) + Convert.ToDecimal(re.PaidPrice) - (re.Price + Convert.ToDecimal(e.ExtraitemPrice)); db.Entry(c).State = EntityState.Modified; } } else { if (e.BillingStatus.ToString() == "Confirmed") { e.Color = "green"; } if (e.BillingStatus.ToString() == "Pending" || e.BillingStatus.ToString() == null) { e.Color = "orange"; } e.Status = true; e.CreateDate = DateTime.Now.ToUniversalTime().AddHours(2); e.CreateUser = username; if (e.Price != 0) { e.ScheduleNote = "Price: " + e.Price.ToString() + " Total : " + e.TotalPrice.ToString(); } db.Reservation.Add(e); Transaction t = new Transaction(); t.Id = Guid.NewGuid(); t.CreatedOn = DateTime.Now.ToUniversalTime().AddHours(2); t.UserId = username; var count = db.Transaction.Count(); if (count > 0) { var cuscode = db.Transaction.Max(x => x.VoucherNo); t.VoucherNo = cuscode + 1; } else { t.VoucherNo = 1000; } t.VoucherType = "Reservation"; t.TrasactionalAmount = e.Price + Convert.ToDecimal(e.ExtraitemPrice) + Convert.ToDecimal(e.PaidPrice); t.Narration = e.ScheduleTitle + " - " + e.StartedAt.ToString() + " to " + e.EndAt.ToString(); t.DebitAmount = Convert.ToDecimal(e.PaidPrice); t.CreditAmount = e.Price + Convert.ToDecimal(e.ExtraitemPrice); t.CreatedOn = DateTime.Now.ToUniversalTime().AddHours(2); t.TransactionDate = e.StartedAt; t.Client = e.Client; t.ReservationId = e.Id; db.Transaction.Add(t); if (e.PaidPrice == null) { e.PaidPrice = 0; } if (e.PaidPrice != 0) { Cashbook tc = new Cashbook(); tc.Id = Guid.NewGuid(); tc.CreatedOn = DateTime.Now.ToUniversalTime().AddHours(2); tc.UserId = username; var co = db.Cashbook.Count(); if (co > 0) { var cuscode = db.Cashbook.Max(x => x.VoucherNo); tc.VoucherNo = cuscode + 1; } else { tc.VoucherNo = 1000; } tc.Client = t.Client; tc.DebitAmount = t.DebitAmount; tc.CreditAmount = 0; tc.Narration = t.Narration; tc.ReservationId = e.Id; tc.VoucherType = "Cash Reservation"; tc.TrasactionalAmount = e.Price + Convert.ToDecimal(e.ExtraitemPrice) + Convert.ToDecimal(e.PaidPrice);; if (tc.DebitAmount == null) { tc.DebitAmount = 0; } if (tc.CreditAmount == null) { tc.CreditAmount = 0; } tc.TransactionDate = e.StartedAt; db.Cashbook.Add(tc); db.SaveChanges(); } var cBalance = db.Customer.Where(x => x.Id == e.Client).Select(s => s.Balance).FirstOrDefault(); Customer c = new Customer(); c = db.Customer.FirstOrDefault(f => f.Id == e.Client); c.Balance = Convert.ToDecimal(cBalance) + Convert.ToDecimal(e.PaidPrice) - (e.Price + Convert.ToDecimal(e.ExtraitemPrice)); db.Entry(c).State = EntityState.Modified; } await db.SaveChangesAsync(); savedata.Commit(); status = true; } } catch (Exception) { savedata.Rollback(); status = false; } } return(new JsonResult { Data = new { status } }); }
public async Task <JsonResult> UpdateEvent(Reservation e) { var status = false; using (var savedata = db.Database.BeginTransaction()) { try { if (e.Id != 0) { var username = User.Identity.GetUserName(); CultureInfo provider = new CultureInfo("en-LB"); var getId = db.Transaction.Where(x => x.ReservationId == e.Id).OrderByDescending(o => o.CreatedOn).Take(1).Select(l => l.Id).FirstOrDefault(); var getDebit = db.Transaction.Where(x => x.Id == getId).Select(a => a.DebitAmount).FirstOrDefault(); var getCredit = db.Transaction.Where(x => x.Id == getId).Select(a => a.CreditAmount).FirstOrDefault(); var getPrice = db.Reservation.Where(x => x.Id == e.Id).Select(a => a.Price).FirstOrDefault(); var getEPrice = db.Reservation.Where(x => x.Id == e.Id).Select(a => a.ExtraitemPrice).FirstOrDefault(); var getPaid = db.Reservation.Where(x => x.Id == e.Id).Select(a => a.PaidPrice).FirstOrDefault(); if (getPaid == null) { decimal?v = getPaid = 0; } var getClientId = db.Reservation.Where(x => x.Id == e.Id).Select(a => a.Client).FirstOrDefault(); var cBalance = db.Customer.Where(x => x.Id == getClientId).Select(k => k.Balance).FirstOrDefault(); if (cBalance == null) { decimal?v = cBalance = 0; } Customer c = new Customer(); c = db.Customer.FirstOrDefault(f => f.Id == getClientId); Transaction t = new Transaction(); t = db.Transaction.FirstOrDefault(f => f.Id == getId); t.UserId = username; t.VoucherType = "Update Reservation"; t.TransactionDate = Convert.ToDateTime(e.Fromdate); t.Narration = e.ScheduleTitle + " - " + Convert.ToDateTime(e.Fromdate).ToString() + " to " + Convert.ToDateTime(e.ToDate).ToString(); if (getPrice != 0) { if (e.Price > getPrice) { t.CreditAmount = getCredit + (e.Price - getPrice); getCredit = t.CreditAmount; c.Balance = cBalance - (e.Price - getPrice); db.Entry(c).State = EntityState.Modified; } else if (e.Price < getPrice) { t.CreditAmount = getCredit - (getPrice - e.Price); getCredit = t.CreditAmount; c.Balance = cBalance + (getPrice - e.Price); db.Entry(c).State = EntityState.Modified; } else { t.CreditAmount = getCredit; getCredit = t.CreditAmount; } db.Entry(t).State = EntityState.Modified; } if (e.ExtraitemPrice != null) { if (e.ExtraitemPrice > getEPrice) { t.CreditAmount = getCredit + (e.ExtraitemPrice - getEPrice); getCredit = t.CreditAmount; cBalance = db.Customer.Where(x => x.Id == getClientId).Select(k => k.Balance).FirstOrDefault(); c.Balance = cBalance - (e.ExtraitemPrice - getEPrice); db.Entry(c).State = EntityState.Modified; } else if (e.ExtraitemPrice < getEPrice) { t.CreditAmount = getCredit - (getEPrice - e.ExtraitemPrice); getCredit = t.CreditAmount; cBalance = db.Customer.Where(x => x.Id == getClientId).Select(k => k.Balance).FirstOrDefault(); c.Balance = cBalance + (getEPrice - e.ExtraitemPrice); db.Entry(c).State = EntityState.Modified; } else { t.CreditAmount = getCredit; getCredit = t.CreditAmount; } } if (e.PaidPrice != null) { if (e.PaidPrice == null) { e.PaidPrice = 0; } if (e.PaidPrice > getPaid) { t.DebitAmount = getDebit + (e.PaidPrice - getPaid); c.Balance = cBalance + (e.PaidPrice - getPaid); db.Entry(c).State = EntityState.Modified; Cashbook tc = new Cashbook(); tc.Id = Guid.NewGuid(); tc.CreatedOn = DateTime.Now.ToUniversalTime().AddHours(2); tc.UserId = username; var co = db.Cashbook.Count(); if (co > 0) { var cuscode = db.Cashbook.Max(x => x.VoucherNo); tc.VoucherNo = cuscode + 1; } else { tc.VoucherNo = 1000; } tc.Client = getClientId; tc.DebitAmount = (e.PaidPrice - getPaid); tc.CreditAmount = 0; tc.Narration = t.Narration; tc.ReservationId = e.Id; tc.VoucherType = "Cash Reservation"; tc.TrasactionalAmount = e.Price + Convert.ToDecimal(e.ExtraitemPrice) + Convert.ToDecimal(e.PaidPrice);; if (tc.DebitAmount == null) { tc.DebitAmount = 0; } if (tc.CreditAmount == null) { tc.CreditAmount = 0; } tc.TransactionDate = Convert.ToDateTime(e.Fromdate); db.Cashbook.Add(tc); } else if (e.PaidPrice < getPaid) { t.DebitAmount = getDebit - (getPaid - e.PaidPrice); c.Balance = cBalance - (getPaid - e.PaidPrice); db.Entry(c).State = EntityState.Modified; Cashbook tc = new Cashbook(); tc.Id = Guid.NewGuid(); tc.CreatedOn = DateTime.Now.ToUniversalTime().AddHours(2); tc.UserId = username; var co = db.Cashbook.Count(); if (co > 0) { var cuscode = db.Cashbook.Max(x => x.VoucherNo); tc.VoucherNo = cuscode + 1; } else { tc.VoucherNo = 1000; } tc.Client = getClientId; tc.DebitAmount = 0; tc.CreditAmount = (getPaid - e.PaidPrice); tc.Narration = t.Narration; tc.ReservationId = e.Id; tc.VoucherType = "Cash Reservation"; tc.TrasactionalAmount = e.Price + Convert.ToDecimal(e.ExtraitemPrice) + Convert.ToDecimal(e.PaidPrice); if (tc.DebitAmount == null) { tc.DebitAmount = 0; } if (tc.CreditAmount == null) { tc.CreditAmount = 0; } tc.TransactionDate = Convert.ToDateTime(e.Fromdate); db.Cashbook.Add(tc); } else { t.CreditAmount = getCredit; } } db.Entry(t).State = EntityState.Modified; Reservation s = new Reservation(); s = db.Reservation.FirstOrDefault(f => f.Id == e.Id); if (e.Price != 0) { s.Price = e.Price; } if (e.ExtraitemPrice != null) { s.ExtraitemPrice = e.ExtraitemPrice; } if (e.PaidPrice != null) { s.PaidPrice = e.PaidPrice; } if (e.BillingStatus.ToString() == "Confirmed") { s.Color = "green"; } if (e.BillingStatus.ToString() == "Pending") { s.Color = "orange"; } s.UpdateUser = username; s.StartedAt = Convert.ToDateTime(e.Fromdate); s.EndAt = Convert.ToDateTime(e.ToDate); s.Note = e.Note; s.BillingStatus = e.BillingStatus; s.IsBallRent = e.IsBallRent; s.ItemId = e.ItemId; db.Entry(s).State = EntityState.Modified; await db.SaveChangesAsync(); savedata.Commit(); status = true; } } catch (Exception) { savedata.Rollback(); status = false; } } return(new JsonResult { Data = new { status } }); }
public async Task <ActionResult> GetBills(Transaction t) { if (ModelState.IsValid) { using (var savedata = db.Database.BeginTransaction()) { try { var username = User.Identity.GetUserName(); t.Id = Guid.NewGuid(); t.CreatedOn = DateTime.Now.ToUniversalTime().AddHours(2); t.UserId = username; var count = db.Transaction.Count(); if (count > 0) { var cuscode = db.Transaction.Max(x => x.VoucherNo); t.VoucherNo = cuscode + 1; } else { t.VoucherNo = 1000; } t.VoucherType = "Receive"; t.TrasactionalAmount = Convert.ToDecimal(t.DebitAmount) + Convert.ToDecimal(t.CreditAmount); if (t.DebitAmount == null) { t.DebitAmount = 0; } if (t.CreditAmount == null) { t.CreditAmount = 0; } t.TransactionDate = DateTime.Now.ToUniversalTime().AddHours(2); db.Transaction.Add(t); var cBalance = db.Customer.Where(x => x.Id == t.Client).Select(s => s.Balance).FirstOrDefault(); Customer c = new Customer(); c = db.Customer.FirstOrDefault(f => f.Id == t.Client); c.Balance = Convert.ToDecimal(cBalance) + Convert.ToDecimal(t.DebitAmount) - (t.CreditAmount); db.Entry(c).State = EntityState.Modified; db.SaveChanges(); Cashbook tc = new Cashbook(); tc.Id = Guid.NewGuid(); tc.CreatedOn = DateTime.Now.ToUniversalTime().AddHours(2); tc.UserId = username; var co = db.Cashbook.Count(); if (co > 0) { var cuscode = db.Cashbook.Max(x => x.VoucherNo); tc.VoucherNo = cuscode + 1; } else { tc.VoucherNo = 1000; } tc.Client = t.Client; tc.DebitAmount = t.DebitAmount; tc.CreditAmount = t.CreditAmount; tc.Narration = t.Narration; tc.VoucherType = "Cash"; tc.TrasactionalAmount = Convert.ToDecimal(tc.DebitAmount) + Convert.ToDecimal(tc.CreditAmount); if (tc.DebitAmount == null) { tc.DebitAmount = 0; } if (tc.CreditAmount == null) { tc.CreditAmount = 0; } tc.TransactionDate = DateTime.Now.ToUniversalTime().AddHours(2); db.Cashbook.Add(tc); db.SaveChanges(); await db.SaveChangesAsync(); savedata.Commit(); return(RedirectToAction("GetBills")); } catch (Exception) { savedata.Rollback(); return(RedirectToAction("GetBills")); } } } ViewBag.Client = new SelectList(db.Customer, "Id", "FullName"); return(View(t)); }