public IActionResult Save(TransactionModel transaction) { if (!ModelState.IsValid) { var userID = _httpContextAccessor.HttpContext.User.FindFirst(ClaimTypes.NameIdentifier).Value; var categories = _categoryService.GetOrderedUserCategories(userID, transaction.IsSpending); var viewModel = new TransactionFormViewModel() { Transaction = transaction, Categories = categories, DefaultCurrencySymbol = _accountService.GetUserDefaultCurrencySymbol(userID) }; return(View("TransactionForm", viewModel)); } if (transaction.ID == Guid.Empty) { _transactionService.AddTransaction(transaction); } else { _transactionService.UpdateTransaction(transaction); } return(RedirectToAction("MainPage", "Transaction")); }
public ActionResult ReturSales() { TransactionFormViewModel viewModel = SetViewModelByStatus(EnumTransactionStatus.ReturSales); ListDetTrans = new List <TTransDet>(); return(View(viewModel)); }
public ActionResult Purchase() { TransactionFormViewModel viewModel = SetViewModelByStatus(EnumTransactionStatus.Purchase); ListDetTrans = new List <TTransDet>(); return(View(viewModel)); }
public ActionResult Edit(int id) { string UserGuid = User.Identity.GetUserId(); var defCurrency = _context.Users.Single(u => u.Id == UserGuid).DefCurrency; var transaction = _context.Transactions.SingleOrDefault(c => c.Id == id); if (transaction == null) { return(HttpNotFound()); } //var categories = _context.Users.Find(UserGuid).Categories.Where(c=>c.IsSpendingCategory==transaction.IsSpending); int DefCatId = transaction.IsSpending ? Category.SpendingCategoryDefault : Category.IncomeCategoryDefault; var categories = _context.Users.Find(UserGuid).Categories.Where(c => c.IsSpendingCategory == transaction.IsSpending).ToList(); var defCategory = categories.First(c => c.Id == DefCatId); categories.Remove(defCategory); categories = categories.OrderBy(c => c.Name).ToList(); categories.Insert(0, defCategory); var viewModel = new TransactionFormViewModel { Transaction = transaction, Categories = categories, //IsSpending = transaction.IsSpending, DefCurrency = defCurrency }; return(View("TransactionForm", viewModel)); }
public ActionResult TransactionForm(bool?id) { string UserGuid = User.Identity.GetUserId(); int DefCatId = id == true ? Category.SpendingCategoryDefault : Category.IncomeCategoryDefault; var categories = _context.Users.Find(UserGuid).Categories.Where(c => c.IsSpendingCategory == id).ToList(); var defCategory = categories.First(c => c.Id == DefCatId); categories.Remove(defCategory); categories.OrderBy(c => c.Name); categories.Insert(0, defCategory); var defCurrency = _context.Users.Single(u => u.Id == UserGuid).DefCurrency; if (id == true) { ViewBag.Head = "Добавить расход"; } else { ViewBag.Head = "Добавить доход"; } var viewModel = new TransactionFormViewModel { Transaction = new Transaction(), Categories = categories, //IsSpending = id, DefCurrency = defCurrency }; return(View(viewModel)); }
public ActionResult Adjusment() { TransactionFormViewModel viewModel = SetViewModelByStatus(EnumTransactionStatus.Adjusment); ListDetTrans = new List <TTransDet>(); return(View(viewModel)); }
public ActionResult Budgeting() { TransactionFormViewModel viewModel = SetViewModelByStatus(EnumTransactionStatus.Budgeting); ListDetTrans = new List <TTransDet>(); return(View(viewModel)); }
private TransactionFormViewModel SetViewModelByStatus(EnumTransactionStatus enumTransactionStatus) { TransactionFormViewModel viewModel = TransactionFormViewModel.CreateTransactionFormViewModel(enumTransactionStatus, _tTransRepository, _mWarehouseRepository, _mSupplierRepository, _mCustomerRepository); ViewData["CurrentItem"] = viewModel.Title; //ViewData[EnumCommonViewData.SaveState.ToString()] = EnumSaveState.NotSaved; return(viewModel); }
private ReportDataSource GetTransTotal(DateTime?dateFrom, DateTime?dateTo, string warehouseId, EnumTransactionStatus transStatus) { Check.Require(transStatus != EnumTransactionStatus.None, "transStatus may not be None"); IList <TTransDet> dets = _tTransDetRepository.GetByDateWarehouse(dateFrom, dateTo, warehouseId, transStatus); string TransName = Helper.CommonHelper.GetStringValue(transStatus); TransactionFormViewModel viewModel = new TransactionFormViewModel(); Helper.CommonHelper.SetViewModelByStatus(viewModel, transStatus); var list = from det in dets select new { det.Id, det.TransDetNo, det.TransDetQty, det.TransDetDesc, det.TransDetTotal, det.TransDetPrice, det.TransDetDisc, ItemId = det.ItemId.Id, det.ItemId.ItemName, ItemUom = det.ItemId.ItemUom.ItemUomName, SupplierName = GetSupplierName(det.TransId.TransBy), det.TransId.TransFactur, det.TransId.TransDate, WarehouseId = det.TransId.WarehouseId.Id, det.TransId.WarehouseId.WarehouseName, WarehouseToName = det.TransId.WarehouseIdTo != null ? det.TransId.WarehouseIdTo.WarehouseName : null, det.TransId.TransStatus, det.TransId.TransDesc, det.TransId.TransSubTotal, det.TransId.TransPaymentMethod, TransId = det.TransId.Id, viewModel.ViewWarehouse, viewModel.ViewWarehouseTo, viewModel.ViewSupplier, viewModel.ViewDate, viewModel.ViewFactur, viewModel.ViewPrice, viewModel.ViewPaymentMethod, viewModel.ViewJobType, viewModel.ViewUnitType, TransName, JobTypeId = det.TransId.JobTypeId != null ? det.TransId.JobTypeId.Id : null, JobTypeName = det.TransId.JobTypeId != null ? det.TransId.JobTypeId.JobTypeName : null, UnitTypeId = det.TransId.UnitTypeId != null ? det.TransId.UnitTypeId.Id : null, UnitTypeName = det.TransId.UnitTypeId != null ? det.TransId.UnitTypeId.UnitTypeName : null } ; ReportDataSource reportDataSource = new ReportDataSource("TransTotalViewModel", list.ToList()); return(reportDataSource); }
public ViewResult New() { var viewModel = new TransactionFormViewModel(); if (User.IsInRole(RoleName.Employer)) { viewModel.Employees = _context.Employees.ToList(); } return(View("TransactionForm", viewModel)); }
public ActionResult Save(Transaction transaction) { if (!ModelState.IsValid) { string UserGuid = User.Identity.GetUserId(); var categories = _context.Users.Find(UserGuid).Categories.Where(c => c.IsSpendingCategory == transaction.IsSpending).OrderBy(c => c.Name); var defCurrency = _context.Users.Single(u => u.Id == UserGuid).DefCurrency; var viewModel = new TransactionFormViewModel() { Transaction = transaction, Categories = categories, DefCurrency = defCurrency }; return(View("TransactionForm", viewModel)); } if (transaction.Id == 0) { _context.Transactions.Add(transaction); } else { var transactionInDb = _context.Transactions.Single(t => t.Id == transaction.Id); transactionInDb.Name = transaction.Name; transactionInDb.Amount = transaction.Amount; transactionInDb.CategoryId = transaction.CategoryId; transactionInDb.Description = transaction.Description; transactionInDb.IsSpending = transaction.IsSpending; transactionInDb.TransDate = transaction.TransDate; transactionInDb.IsPlaned = transaction.IsPlaned; transactionInDb.UserId = transaction.UserId; } try { _context.SaveChanges(); } catch (DbEntityValidationException ex) { foreach (var errors in ex.EntityValidationErrors) { foreach (var validationError in errors.ValidationErrors) { // get the error message string errorMessage = validationError.ErrorMessage; } } } return(RedirectToAction("MyBudget", "Transactions")); }
public ActionResult New() { var services = _context.Services.ToList(); var vehicles = _context.Vehicles.ToList(); var branches = _context.Branches.ToList(); var viewModel = new TransactionFormViewModel { Services = services, Vehicles = vehicles, Branches = branches }; return(View("TransactionForm", viewModel)); }
public IActionResult Edit(string id) { var userID = _httpContextAccessor.HttpContext.User.FindFirst(ClaimTypes.NameIdentifier).Value; var transaction = _transactionService.GetTransaction(id); var categories = _categoryService.GetOrderedUserCategories(userID, transaction.IsSpending); var viewModel = new TransactionFormViewModel { Transaction = transaction, Categories = categories, DefaultCurrencySymbol = _accountService.GetUserDefaultCurrencySymbol(userID) }; return(View("TransactionForm", viewModel)); }
public ActionResult AddTransaction(bool isSpending) { int NoCategoryID; if (isSpending) { ViewBag.Head = "Добавить расход"; NoCategoryID = Category.SpendingCategoryDefault; } else { ViewBag.Head = "Добавить доход"; NoCategoryID = Category.IncomeCategoryDefault; } string UserGuid = User.Identity.GetUserId(); var categories = _context.Users.Find(UserGuid).Categories.Where(c => c.IsSpendingCategory == isSpending).ToList(); var defCategory = categories.First(c => c.Id == NoCategoryID); categories.Remove(defCategory); categories = categories.OrderBy(c => c.Name).ToList(); categories.Insert(0, defCategory); var defCurrency = _context.Users.Single(u => u.Id == UserGuid).DefCurrency; var transaction = new Transaction(); transaction.IsSpending = isSpending; transaction.TransDate = DateTime.Now; transaction.UserId = UserGuid; var viewModel = new TransactionFormViewModel { Transaction = transaction, Categories = categories, DefCurrency = defCurrency }; return(View("TransactionForm", viewModel)); }
public ActionResult SelectedItem(int id) { var item = _context.Items.SingleOrDefault(i => i.Id == id); //TempData["itemId"] = id; if (item == null) { return(HttpNotFound()); } var viewModel = new TransactionFormViewModel { VehicleId = Convert.ToInt32(TempData["vehicleId"]), ItemsList = id.ToString(), Branches = _context.Branches.ToList(), Services = _context.Services.ToList() }; return(View("TransactionForm", viewModel)); }
public ActionResult SelectedVehicle(int id) { var vehicle = _context.Vehicles.SingleOrDefault(i => i.Id == id); TempData["vehicleId"] = id; if (vehicle == null) { return(HttpNotFound()); } var viewModel = new TransactionFormViewModel { //ItemsList = (TempData["itemId"]).ToString(), VehicleId = id, Branches = _context.Branches.ToList(), Services = _context.Services.ToList() }; return(View("TransactionForm", viewModel)); }
public ActionResult Edit(int id) { var transaction = _context.Transactions.Include("Service") .Include("Vehicle") .Include("Branch") .SingleOrDefault(t => t.Id == id); if (transaction == null) { return(HttpNotFound()); } var viewModel = new TransactionFormViewModel(transaction) { Vehicles = _context.Vehicles.ToList(), Services = _context.Services.ToList(), Branches = _context.Branches.ToList() }; return(View("TransactionForm", viewModel)); }
public IActionResult Add(bool isSpending) { var userID = _httpContextAccessor.HttpContext.User.FindFirst(ClaimTypes.NameIdentifier).Value; var categories = _categoryService.GetOrderedUserCategories(userID, isSpending); var currency = _accountService.GetUserDefaultCurrency(userID); var transaction = new TransactionModel() { IsSpending = isSpending, TransactionDate = DateTime.Now, UserID = userID, CurrencyID = currency.ID }; var viewModel = new TransactionFormViewModel { Transaction = transaction, Categories = categories, DefaultCurrencySymbol = _accountService.GetUserDefaultCurrencySymbol(userID) }; return(View("TransactionForm", viewModel)); }
public static void SetViewModelByStatus(TransactionFormViewModel viewModel, EnumTransactionStatus enumTransactionStatus) { switch (enumTransactionStatus) { case EnumTransactionStatus.PurchaseOrder: viewModel.ViewWarehouse = true; viewModel.ViewWarehouseTo = false; viewModel.ViewSupplier = true; viewModel.ViewDate = true; viewModel.ViewFactur = true; viewModel.ViewPrice = true; viewModel.ViewPaymentMethod = false; viewModel.IsGenerateFactur = true; viewModel.IsCalculateStock = false; viewModel.IsAddStock = true; break; case EnumTransactionStatus.Purchase: viewModel.ViewWarehouse = true; viewModel.ViewWarehouseTo = false; viewModel.ViewSupplier = true; viewModel.ViewDate = true; viewModel.ViewFactur = true; viewModel.ViewPrice = true; viewModel.ViewPaymentMethod = true; viewModel.IsGenerateFactur = false; viewModel.IsCalculateStock = false; viewModel.IsAddStock = true; break; case EnumTransactionStatus.ReturPurchase: viewModel.ViewWarehouse = true; viewModel.ViewWarehouseTo = false; viewModel.ViewSupplier = true; viewModel.ViewDate = true; viewModel.ViewFactur = true; viewModel.ViewPrice = true; viewModel.ViewPaymentMethod = true; viewModel.IsGenerateFactur = true; viewModel.IsCalculateStock = false; viewModel.IsAddStock = true; break; case EnumTransactionStatus.Sales: break; case EnumTransactionStatus.ReturSales: break; case EnumTransactionStatus.Using: viewModel.ViewWarehouse = true; viewModel.ViewWarehouseTo = false; viewModel.ViewSupplier = false; viewModel.ViewDate = true; viewModel.ViewFactur = true; viewModel.ViewPrice = false; viewModel.ViewPaymentMethod = false; viewModel.ViewUnitType = true; viewModel.ViewJobType = true; viewModel.IsGenerateFactur = true; viewModel.IsCalculateStock = true; viewModel.IsAddStock = false; break; case EnumTransactionStatus.Mutation: viewModel.ViewWarehouse = true; viewModel.ViewWarehouseTo = true; viewModel.ViewSupplier = false; viewModel.ViewDate = true; viewModel.ViewFactur = true; viewModel.ViewPrice = false; viewModel.ViewPaymentMethod = false; viewModel.IsGenerateFactur = true; viewModel.IsCalculateStock = true; viewModel.IsAddStock = false; break; case EnumTransactionStatus.Adjusment: viewModel.ViewWarehouse = true; viewModel.ViewWarehouseTo = false; viewModel.ViewSupplier = false; viewModel.ViewDate = true; viewModel.ViewFactur = true; viewModel.ViewPrice = false; viewModel.ViewPaymentMethod = false; viewModel.IsGenerateFactur = true; viewModel.IsCalculateStock = true; viewModel.IsAddStock = false; break; case EnumTransactionStatus.Received: viewModel.ViewWarehouse = true; viewModel.ViewWarehouseTo = false; viewModel.ViewSupplier = true; viewModel.ViewDate = true; viewModel.ViewFactur = true; viewModel.ViewPrice = true; viewModel.ViewPaymentMethod = false; viewModel.IsGenerateFactur = true; viewModel.IsCalculateStock = true; viewModel.IsAddStock = true; break; case EnumTransactionStatus.Budgeting: viewModel.ViewWarehouse = true; viewModel.ViewWarehouseTo = false; viewModel.ViewSupplier = false; viewModel.ViewDate = false; viewModel.ViewFactur = true; viewModel.ViewPrice = true; viewModel.ViewPaymentMethod = false; viewModel.ViewUnitType = true; viewModel.ViewJobType = true; viewModel.IsGenerateFactur = true; viewModel.IsCalculateStock = false; viewModel.IsAddStock = true; break; } viewModel.Title = GetStringValue(enumTransactionStatus); }
private ActionResult SaveTransaction(TTrans Trans, FormCollection formCollection) { _tTransRepository.DbContext.BeginTransaction(); if (Trans == null) { Trans = new TTrans(); } Trans.SetAssignedIdTo(formCollection["Trans.Id"]); Trans.WarehouseId = _mWarehouseRepository.Get(formCollection["Trans.WarehouseId"]); if (!string.IsNullOrEmpty(formCollection["Trans.WarehouseIdTo"])) { Trans.WarehouseIdTo = _mWarehouseRepository.Get(formCollection["Trans.WarehouseIdTo"]); } Trans.CreatedDate = DateTime.Now; Trans.CreatedBy = User.Identity.Name; Trans.DataStatus = Enums.EnumDataStatus.New.ToString(); Trans.TransDets.Clear(); //save stock card bool addStock = true; bool calculateStock = false; EnumTransactionStatus status = (EnumTransactionStatus)Enum.Parse(typeof(EnumTransactionStatus), Trans.TransStatus); TransactionFormViewModel.GetIsCalculateStock(status, out addStock, out calculateStock); TTransDet detToInsert; IList <TTransDet> listDet = new List <TTransDet>(); decimal total = 0; foreach (TTransDet det in ListDetTrans) { detToInsert = new TTransDet(Trans); detToInsert.SetAssignedIdTo(Guid.NewGuid().ToString()); detToInsert.ItemId = det.ItemId; detToInsert.ItemUomId = det.ItemUomId; detToInsert.TransDetQty = det.TransDetQty; detToInsert.TransDetPrice = det.TransDetPrice; detToInsert.TransDetDisc = det.TransDetDisc; detToInsert.TransDetTotal = det.TransDetTotal; detToInsert.CreatedBy = User.Identity.Name; detToInsert.CreatedDate = DateTime.Now; detToInsert.DataStatus = Enums.EnumDataStatus.New.ToString(); Trans.TransDets.Add(detToInsert); total += det.TransDetTotal.HasValue ? det.TransDetTotal.Value : 0; listDet.Add(detToInsert); } Trans.TransSubTotal = total; _tTransRepository.Save(Trans); //_tTransRepository.DbContext.CommitTransaction(); //_tStockCardRepository.DbContext.BeginTransaction(); if (calculateStock) { decimal totalHpp = 0; foreach (TTransDet det in listDet) { //save stock if (Trans.TransStatus.Equals(EnumTransactionStatus.Mutation.ToString())) { SaveStockItem(Trans.TransDate, Trans.TransDesc, det.ItemId, det.TransDetQty, false, Trans.WarehouseId); SaveStockItem(Trans.TransDate, Trans.TransDesc, det.ItemId, det.TransDetQty, true, Trans.WarehouseIdTo); //still to do, for mutation, price of stock must recalculate per stock, //sum hpp for each stock for stock out totalHpp += UpdateStock(Trans.TransDate, Trans.TransDesc, Trans.TransStatus, det.ItemId, det.TransDetPrice, det.TransDetQty, det, false, Trans.WarehouseId); UpdateStock(Trans.TransDate, Trans.TransDesc, Trans.TransStatus, det.ItemId, det.TransDetPrice, det.TransDetQty, det, true, Trans.WarehouseIdTo); } else { SaveStockItem(Trans.TransDate, Trans.TransDesc, det.ItemId, det.TransDetQty, addStock, Trans.WarehouseId); //sum hpp for each stock totalHpp += UpdateStock(Trans.TransDate, Trans.TransDesc, Trans.TransStatus, det.ItemId, det.TransDetPrice, det.TransDetQty, det, addStock, Trans.WarehouseId); } } //UPDATE 20150629 : no linked to accounting ////save journal //SaveJournal(Trans, totalHpp); } try { _tTransRepository.DbContext.CommitTransaction(); TempData[EnumCommonViewData.SaveState.ToString()] = EnumSaveState.Success; } catch (Exception) { _tTransRepository.DbContext.RollbackTransaction(); TempData[EnumCommonViewData.SaveState.ToString()] = EnumSaveState.Failed; } //if (!Trans.TransStatus.Equals(EnumTransactionStatus.PurchaseOrder.ToString())) //{ // return RedirectToAction(Trans.TransStatus.ToString()); //} //return RedirectToAction("Index"); return(View("Status")); }
public ActionResult Purchase() { TransactionFormViewModel viewModel = SetViewModelByStatus(EnumTransactionStatus.Purchase); return(View(viewModel)); }
public ActionResult ReturSales() { TransactionFormViewModel viewModel = SetViewModelByStatus(EnumTransactionStatus.ReturSales); return(View(viewModel)); }
public ActionResult Budgeting() { TransactionFormViewModel viewModel = SetViewModelByStatus(EnumTransactionStatus.Budgeting); return(View(viewModel)); }
public ActionResult Adjusment() { TransactionFormViewModel viewModel = SetViewModelByStatus(EnumTransactionStatus.Adjusment); return(View(viewModel)); }
public ActionResult Mutation() { TransactionFormViewModel viewModel = SetViewModelByStatus(EnumTransactionStatus.Mutation); return(View(viewModel)); }