public async Task <IActionResult> Accounts(string username = null, string name = null, string email = null) { ViewBag.Usename = username; ViewBag.Name = name; ViewBag.Email = email; var users = _userRepository.GetAccounts(username, name, email).ToList(); var model = new List <AccountsVM>(); if (users.Any()) { foreach (var x in users) { var m = new AccountsVM { FullName = x.FirstName + " " + x.LastName, Username = x.UserName, Email = x.Email, RegistrationDate = x.RegistrationDate, ID = x.Id, Permision = await _userManager.GetRolesAsync(x), LastLoginDate = x.LastLoginDate }; model.Add(m); } } else { ErrorMessage = "Ne postoje korisnici prema zadanom filteru."; } return(View(model)); }
public ActionResult Index2(string Message) { AccountsVM accountsVM = new AccountsVM(); accountsVM.VendorList = db.VendorInfoes.ToList().Select(m => new SelectListItem() { Text = m.VendorName, Value = m.Id.ToString() }).ToList(); if (!string.IsNullOrEmpty(Message)) { ViewBag.Message = Message; } accountsVM.SPs = new List <AccountsVMSP>(); //DateTime tempDateTime = DateTime.Now; //List<AccountDetail> OldStockDetails = new List<AccountDetail>(); //if (db.AccountDetails.Count() > 0) //{ // tempDateTime = Convert.ToDateTime(db.AccountDetails.OrderByDescending(o => o.Id).FirstOrDefault().AccountDateTime); // //To not consider without old stock entry for realstock // if(tempDateTime.Date == DateTime.Today) // { // tempDateTime = tempDateTime.Date.AddDays(-1); // } // YesterdayStartTime = new DateTime(tempDateTime.Year, tempDateTime.Month, tempDateTime.Day, 0, 0, 0); // YesterdayEndTime = new DateTime(tempDateTime.Year, tempDateTime.Month, tempDateTime.Day, 23, 59, 59); //} //else //{ // YesterdayStartTime = new DateTime(tempDateTime.Year, tempDateTime.Month, tempDateTime.Day - 1, 0, 0, 0); // YesterdayEndTime = new DateTime(tempDateTime.Year, tempDateTime.Month, tempDateTime.Day - 1, 23, 59, 59); //} //OldStockDetails = db.AccountDetails.Where(u => u.AccountDateTime < YesterdayEndTime && u.AccountDateTime > YesterdayStartTime && u.ConsiderOldStock == true).ToList(); //if (OldStockDetails!= null && OldStockDetails.Count() > 0) //{ // foreach (var item in OldStockDetails) // { // accountsVM.OldStock += Convert.ToDecimal(item.RealStock); // } //} accountsVM.OldStock = Convert.ToDecimal(db.AccountDetailsLastRealStocks.FirstOrDefault()?.RealStock); return(View(accountsVM)); }
public ActionResult Edit(int Id) { if (Id == 0) { return(RedirectToAction("ListAccounts")); } else { AccountsVM accountsVM = new AccountsVM(); var accountDetail = db.AccountDetails.FirstOrDefault(d => d.Id == Id); if (accountDetail != null) { accountsVM.AccountDateTime = Convert.ToDateTime(accountDetail.AccountDateTime); accountsVM.AccountId = accountDetail.Id; accountsVM.AvailableStock = Convert.ToDecimal(accountDetail.AvailableStock); accountsVM.AvailableStockNote = accountDetail.AvailableStockNote; accountsVM.ConsiderOldStock = Convert.ToBoolean(accountDetail.ConsiderOldStock); accountsVM.OldStock = Convert.ToDecimal(accountDetail.OldStock); accountsVM.RealStock = Convert.ToDecimal(accountDetail.RealStock); accountsVM.RealStockNote = accountDetail.RealStockNote; accountsVM.StockDifference = Convert.ToDecimal(accountDetail.StockDifference); accountsVM.StockDifferenceNote = accountDetail.StockDifferenceNote; accountsVM.TodayMilk = Convert.ToDecimal(accountDetail.TodayMilk); accountsVM.TodayMilkNote = accountDetail.TodayMilkNote; accountsVM.TotalPurchase = Convert.ToDecimal(accountDetail.TotalPurchase); accountsVM.TotalPurchaseNote = accountDetail.TotalPurchaseNote; accountsVM.TotalSell = Convert.ToDecimal(accountDetail.TotalSell); accountsVM.TotalSellNote = accountDetail.TotalSellNote; accountsVM.VendorId = Convert.ToInt32(accountDetail.VendorId); accountsVM.VendorList = db.VendorInfoes.ToList().Select(m => new SelectListItem() { Text = m.VendorName, Value = m.Id.ToString() }).ToList(); accountsVM.SPs = db.AccountSPs.Where(d => d.AccountId == accountsVM.AccountId).ToList().Select(d => new AccountsVMSP() { SPNote = d.SPNote, SPValue = Convert.ToDecimal(d.SPValue) }).ToList(); } else { return(RedirectToAction("ListAccounts")); } return(View("Index", accountsVM)); } }
// GET: AccountController public async Task <ActionResult> Index() { var debitAccounts = await _accountRepo.GetAccountByType(AccountType.Debit); var creditAccounts = await _accountRepo.GetAccountByType(AccountType.Credit); var incomeAndExpenseAccounts = await _accountRepo.GetAccountByTwoTypes(AccountType.Expense, AccountType.Income); var mappedDebitAccounts = _mapper.Map <List <AccountVM> >(debitAccounts); var mappedCreditAccounts = _mapper.Map <List <AccountVM> >(creditAccounts); var mappedIncomeExpenseAccounts = _mapper.Map <List <AccountVM> >(incomeAndExpenseAccounts); var model = new AccountsVM { CreditAccounts = mappedCreditAccounts, DebitAccounts = mappedDebitAccounts, ExpenseAndIncomeAccounts = mappedIncomeExpenseAccounts }; return(View(model)); }
public ActionResult Index(AccountsVM accountsVM, FormCollection collection) { try { accountsVM.VendorList = db.VendorInfoes.ToList().Select(m => new SelectListItem() { Text = m.VendorName, Value = m.Id.ToString() }).ToList(); if (ModelState.IsValid) { using (DbContextTransaction transaction = db.Database.BeginTransaction()) { try { AccountDetail ac = new AccountDetail(); ac.AccountDateTime = accountsVM.AccountDateTime; ac.AvailableStock = accountsVM.AvailableStock; ac.AvailableStockNote = accountsVM.AvailableStockNote; ac.OldStock = accountsVM.OldStock; ac.RealStock = accountsVM.RealStock; ac.RealStockNote = accountsVM.RealStockNote; ac.StockDifference = accountsVM.StockDifference; ac.StockDifferenceNote = accountsVM.StockDifferenceNote; ac.TodayMilk = accountsVM.TodayMilk; ac.TodayMilkNote = accountsVM.TodayMilkNote; ac.TotalPurchase = accountsVM.TotalPurchase; ac.TotalPurchaseNote = accountsVM.TotalPurchaseNote; ac.TotalSell = accountsVM.TotalSell; ac.TotalSellNote = accountsVM.TotalSellNote; ac.VendorId = accountsVM.VendorId; ac.ConsiderOldStock = accountsVM.ConsiderOldStock; db.AccountDetails.Add(ac); if (db.SaveChanges() > 0) { List <AccountSP> accountVMSPs = AddUpdateAccountSPs(collection, ac.Id); if (accountVMSPs.Count() > 0) { db.AccountSPs.AddRange(accountVMSPs); if (db.SaveChanges() > 0) { if (accountsVM.ConsiderOldStock) { AddUpdateRealStock(ac, false); } transaction.Commit(); } } return(RedirectToAction("ListAccounts")); } } catch (Exception ex) { transaction.Rollback(); } } return(View(accountsVM)); } else { if (accountsVM.SPs == null) { accountsVM.SPs = new List <AccountsVMSP>(); } return(View(accountsVM)); } } catch (System.Exception ex) { } return(View(accountsVM)); }