//[Authorize(Roles = DBCRole.Admin)] //public JsonResult Transaction(int offset, int limit, string sort, string order, int? UserId) //{ // if (UserId.IsNullOrEmpty()) return Json(new { }, JsonRequestBehavior.AllowGet); // var walletId = _financialService.GetUserWallet(UserId.Value).WalletId; // var tz = User.Identity.GetUserTimeZone(); // var rawQueryableList = _financialService.GetWalletTransaction(walletId).Select(x => new // { // WalletTransactionId = x.WalletTransactionId, // TransactionDate = x.TransactionDate, // ReferenceNo = x.ReferenceNo, // TransactionType = x.TransactionType, // Debit = x.Debit, // Credit = x.Credit // }); // rawQueryableList = rawQueryableList.PaginateList(x => x.TransactionDate, "TransactionDate", "desc", offset, limit); // var rowsResult = new List<WalletListViewModels>(); // decimal totalDebit = decimal.Zero; // decimal totalCredit = decimal.Zero; // foreach (var item in rawQueryableList) // { // totalDebit += item.Debit ?? decimal.Zero; // totalCredit += item.Credit ?? decimal.Zero; // var walletTransaction = new WalletListViewModels() // { // WalletTransactionId = item.WalletTransactionId, // TransactionDate = item.TransactionDate.ToUserLocalDate(tz), // ReferenceNo = item.ReferenceNo + " - " + item.TransactionType, // Debit = (item.Debit.HasValue) ? item.Debit.Value.toCurrencyFormat() : null, // Credit = (item.Credit.HasValue) ? item.Credit.Value.toCurrencyFormat() : null, // Balance = (totalCredit - totalDebit).toCurrencyFormat() // }; // rowsResult.Add(walletTransaction); // } // //If last page // var isLastPage = ((offset + rowsResult.Count + 1) > rawQueryableList.Count()); // if (isLastPage) // { // //Footer // rowsResult.Add(new WalletListViewModels() // { // Debit = totalDebit.toCurrencyFormat(), // Credit = totalCredit.toCurrencyFormat(), // Balance = rowsResult.Last().Balance // }); // } // var model = new // { // total = rawQueryableList.Count(), // rows = rowsResult // }; // return Json(model, JsonRequestBehavior.AllowGet); //} public ActionResult Withdrawal() { //Read user primary bank var userBankAccount = _userService.GetUserBankAccounts(User.Identity.GetUserId <int>()).FirstOrDefault(); var userWallet = _financialService.GetUserWallet(userBankAccount.UserId); WithdrawalViewModels model = new WithdrawalViewModels(); if (userBankAccount != null) { model = new WithdrawalViewModels { BankAccountHolder = userBankAccount.BankAccountHolder, BankAccountNo = userBankAccount.BankAccountNo, BankBranch = userBankAccount.BankBranch, Bank = userBankAccount.Bank.Name, CreditBalance = (_financialService.GetUserWalletAvailableBalance(userWallet.WalletId) ?? decimal.Zero).toCurrencyFormat(), NotifyEmail = userBankAccount.User.Email, }; } model.BankDDL = new SelectList(_bankService.GetAllBank().Select(x => new SelectListItem() { Text = x.Name, Value = x.Name }), "Value", "Text", model.Bank); return(View(model)); }
public ActionResult Withdrawal(WithdrawalViewModels model, string saveState) { try { var user = _userService.GetUserBy(User.Identity.GetUserId <int>()); var userWallet = _financialService.GetUserWallet(user.UserId); //Insufficient Balance handling if (userWallet.Balance < model.WithdrawAmount) { Warning("You have insufficient E-Wallet Credit to withdraw."); var defaultModel = (WithdrawalViewModels)((ViewResultBase)Withdrawal()).ViewData.Model; model.BankDDL = defaultModel.BankDDL; model.CreditBalance = defaultModel.CreditBalance; return(RedirectToAction("Withdrawal")); } if (ModelState.IsValid) { var docCode = _docService.GetNextDocumentNumber(DBConstant.DBCDocSequence.EDocSequenceId.Withdrawal); //Insert withdrawal record Withdrawal wd = new Service.Entities.Withdrawal { WalletId = userWallet.WalletId, ReferenceNo = docCode, NotifyEmail = model.NotifyEmail, Bank = model.Bank, StatusId = (int)EStatus.Approved, BankAccountName = model.BankAccountHolder, BankAccountNo = model.BankAccountNo, BankBranch = model.BankBranch, CreatedTimestamp = DateTime.UtcNow, WithdrawAmount = model.WithdrawAmount, }; _financialService.InsertWithdrawal(wd); //Preauth _financialService.PreauthorizeWalletCredit(EOperator.DEDUCT, ETransactionType.Withdrawal, model.WithdrawAmount, docCode, userWallet.WalletId); //Commit _financialService.SaveChange(User.Identity.GetUserId <int>()); Success("Your request to withdraw total amount of $" + model.WithdrawAmount.toCurrencyFormat() + " has been submitted."); } } catch (Exception ex) { Log.Error(ex.Message, ex); Danger("Failed to submit withdrawal request. Please try again later. If error still persist please contact our customer support."); } return(RedirectToAction("Index")); }