예제 #1
0
        public ActionResult AddInstallments(int id, InstallmentViewModel model)
        {
            if (ModelState.IsValid)
            {
                model.LoanId = id;

                string        cmd    = "SELECT * FROM Loan";
                SqlDataReader reader = Database_Connection.get_instance().Getdata(cmd);
                while (reader.Read())
                {
                    if (reader.GetInt32(0) == id)
                    {
                        model.Amount = reader.GetInt32(3) / model.Plan;
                    }
                }

                string cmd2 = string.Format("INSERT INTO Installement(LoanId,InstallementPlan,Amount) VALUES('{0}','{1}','{2}')", model.LoanId, model.Plan, model.Amount);
                int    rows = Database_Connection.get_instance().Executequery(cmd2);


                // con.Close();

                return(RedirectToAction("ViewInstallment", "Admin", new { id = id }));
            }

            // If we got this far, something failed, redisplay form
            return(View(model));
        }
예제 #2
0
        public async Task <IActionResult> GetInstallments([FromBody] InstallmentViewModel model)
        {
            //add cash option
            model.AddCashRate(model.TotalAmount);

            //get card prefix by prefix
            CreditCard creditCard = await _bankService.GetCreditCardByPrefix(model.Prefix, true);

            if (creditCard == null)
            {
                //get default bank
                Bank defaultBank = await _bankService.GetDefaultBank();

                if (defaultBank == null || !defaultBank.Active)
                {
                    return(Ok(new { errorMessage = "Ödeme için aktif banka bulunamadı." }));
                }

                model.BankId   = defaultBank.Id;
                model.BankLogo = defaultBank.LogoPath;
                model.BankName = defaultBank.Name;

                return(Ok(model));
            }

            //get bank by identifier
            Bank bank = await _bankService.GetById(creditCard.BankId);

            //get default bank
            if (bank == null || !bank.Active)
            {
                bank = await _bankService.GetDefaultBank();
            }

            if (bank == null || !bank.Active)
            {
                return(Ok(new { errorMessage = "Ödeme için aktif banka bulunamadı." }));
            }

            //prepare installment model
            foreach (CreditCardInstallment installment in creditCard.Installments)
            {
                decimal installmentAmount      = model.TotalAmount;
                decimal installmentTotalAmount = installmentAmount;

                if (installment.InstallmentRate > 0)
                {
                    installmentTotalAmount = Math.Round(model.TotalAmount + ((model.TotalAmount * installment.InstallmentRate) / 100), 2, MidpointRounding.AwayFromZero);
                }

                installmentAmount = Math.Round(installmentTotalAmount / installment.Installment, 2, MidpointRounding.AwayFromZero);

                model.InstallmentRates.Add(new InstallmentViewModel.InstallmentRate
                {
                    Text             = $"{installment.Installment} Taksit",
                    Installment      = installment.Installment,
                    Rate             = installment.InstallmentRate,
                    Amount           = installmentAmount.ToString("N2"),
                    AmountValue      = installmentAmount,
                    TotalAmount      = installmentTotalAmount.ToString("N2"),
                    TotalAmountValue = installmentTotalAmount
                });
            }

            //set manufacturer card flag
            model.BankId   = bank.Id;
            model.BankLogo = bank.LogoPath;
            model.BankName = bank.Name;

            return(Ok(model));
        }
        public ActionResult Edit(InstallmentViewModel viewModel)
        {
            if (ModelState.IsValid)
            {
                var installmentExist = _repository.Project <Installment, bool>(
                    installments => (from installment in installments
                                     where installment.InstallmentId == viewModel.InstallmentId
                                     select installment).Any());
                if (!installmentExist)
                {
                    _logger.Warn(string.Format("Payment not exists."));
                    Danger(string.Format("Payment not exists."));
                }

                var result = _installmentService.Update(new Installment
                {
                    InstallmentId     = viewModel.InstallmentId,
                    ReceiptBookNumber = viewModel.ReceiptBookNumber,
                    ReceiptNumber     = viewModel.ReceiptNumber,
                    Payment           = viewModel.Payment,
                    ReceivedFee       = viewModel.FinalFee - viewModel.RemainingFee
                });

                if (result.Success)
                {
                    string userName = User.Identity.GetUserName() + "(" + "Master Admin" + ")";;
                    string body     = string.Empty;
                    using (StreamReader reader = new StreamReader(Server.MapPath("~/MailDesign/InstallmentMailDesign.html")))
                    {
                        body = reader.ReadToEnd();
                    }
                    body = body.Replace("{BatchWithSubjectName}", viewModel.StudBatch);
                    body = body.Replace("{BranchName}", viewModel.BranchName);
                    body = body.Replace("{StudentName}", viewModel.StudentName);
                    body = body.Replace("{ClassName}", viewModel.ClassName);
                    body = body.Replace("{TotalFees}", viewModel.FinalFee.ToString());
                    body = body.Replace("{PaidFees}", viewModel.Payment.ToString());
                    body = body.Replace("{RemainingFees}", viewModel.RemainingFee.ToString());
                    body = body.Replace("{UserName}", userName);
                    var emailMessage = new MailModel
                    {
                        Body    = body,
                        Subject = "Updated Payment",
                        To      = viewModel.Email,
                    };
                    _emailService.Send(emailMessage);

                    List <string> listOfPlayerId = new List <string>();

                    if (viewModel.SMS == true)
                    {
                        string        classname;
                        string        query = "SELECT name FROM Configuration";
                        SqlConnection con   = new SqlConnection(constr);

                        SqlCommand cmd = new SqlCommand(query, con);
                        cmd.Connection = con;
                        con.Open();
                        SqlDataReader dr = cmd.ExecuteReader();

                        dr.Read();
                        classname = dr["name"].ToString();

                        var smsModel = new SmsModel
                        {
                            Message = "Hi " + classname + "\r\n Student Name: " + viewModel.StudentName + "\r\nPayment: " + viewModel.Payment + "\r\nRemaining Fees: " + viewModel.RemainingFee + "\r\nFees Paid Successfully.",
                            SendTo  = viewModel.ParentContact + "," + viewModel.StudentContact
                        };

                        var smsResult = _smsService.SendMessage(smsModel);
                    }
                    if (viewModel.AppNotification == true)
                    {
                        listOfPlayerId.Add(viewModel.ParentAppPlayerId);
                        listOfPlayerId = listOfPlayerId.Where(s => !string.IsNullOrWhiteSpace(s)).ToList();
                        var sendAppNotification = new SendNotification
                        {
                            Message    = "Fee-Student Name: " + viewModel.StudentName + " Payment: " + viewModel.Payment + " Remaining Fees: " + viewModel.RemainingFee + " Fees Paid Successfully.",
                            PlayerIds  = listOfPlayerId,
                            AppIds     = ConfigurationManager.AppSettings[Common.Constants.ParentAppId],
                            RestApiKey = ConfigurationManager.AppSettings[Common.Constants.ParentRestAppId]
                        };

                        if (listOfPlayerId.Count > 0)
                        {
                            var sendNotificationResult = _sendNotificationService.SendNotificationByPlayersId(sendAppNotification);
                        }
                    }

                    Success(result.Results.FirstOrDefault().Message);
                    ModelState.Clear();
                    return(RedirectToAction("Index"));
                }
                else
                {
                    _logger.Warn(result.Results.FirstOrDefault().Message);
                    Warning(result.Results.FirstOrDefault().Message, true);
                }
            }
            return(View(viewModel));
        }
        public ActionResult Create(InstallmentViewModel viewModel)
        {
            ViewBag.ClassId          = viewModel.ClassId;
            ViewBag.BranchId         = viewModel.BranchId;
            ViewBag.UserId           = viewModel.UserId;
            ViewBag.installmentCount = viewModel.InstallmentNo;

            var students = _studentService.GetStudentById(viewModel.UserId);
            //var commaseperatedList = students.SelectedSubjects ?? string.Empty;
            //var subjectIds = commaseperatedList.Split(',').Where(x => !string.IsNullOrEmpty(x)).Select(int.Parse);

            //var subjects = _repository.LoadList<Subject>(x => subjectIds.Contains(x.SubjectId)).ToList();
            //string subject = "";
            //foreach (var s in subjects)
            //{
            //    subject += string.Format("{0}", s.Name);
            //}

            //var selectedSubjects =students.BatchName +" - "+ string.Join(",", subject.TrimEnd(',')) ;
            var studentFinalFee  = _studentService.GetStudentFeeByUserId(viewModel.UserId);
            var paidFee          = _installmentService.GetCountInstallment(viewModel.UserId);
            var remainFee        = studentFinalFee - paidFee;
            var roles            = viewModel.CurrentUserRole;
            var branchId         = viewModel.BranchId;
            var branchName       = viewModel.BranchName;
            var remainingPayment = remainFee - viewModel.Payment;
            var ReceivedFee      = paidFee + viewModel.Payment;

            viewModel.RemainingFee = remainingPayment;
            viewModel.TotalFee     = (studentFinalFee).ToString();

            List <string> listOfPlayerId = new List <string>();

            if (ModelState.IsValid)
            {
                if (remainFee < viewModel.Payment && remainFee != 0)
                {
                    ViewBag.StudentName  = viewModel.StudentName;
                    ViewBag.TotalFee     = viewModel.TotalFee;
                    ViewBag.RemainingFee = viewModel.RemainingFee;
                    _logger.Warn("Payment amount is exceded!");
                    Warning("Payment amount is exceded!", true);
                }
                else if (remainFee == 0)
                {
                    ViewBag.StudentName  = viewModel.StudentName;
                    ViewBag.TotalFee     = viewModel.TotalFee;
                    ViewBag.RemainingFee = viewModel.RemainingFee;
                    _logger.Warn("Your Remaining Fee is Nill!");
                    Warning("Your Remaining Fee is Nill!", true);
                }
                else
                {
                    var result = _installmentService.Save(new Installment
                    {
                        ClassId           = viewModel.ClassId,
                        UserId            = viewModel.UserId,
                        Payment           = viewModel.Payment,
                        RemainingFee      = remainingPayment,
                        ReceiptBookNumber = viewModel.ReceiptBookNumber,
                        ReceiptNumber     = viewModel.ReceiptNumber,
                        ReceivedFee       = ReceivedFee,
                    });
                    if (result.Success)
                    {
                        ViewBag.ClassId  = 0;
                        ViewBag.BranchId = 0;
                        string createdBranchName = "", userName = "";
                        bool   isBranchAdmin = false;
                        if (viewModel.CurrentUserRole == "BranchAdmin")
                        {
                            isBranchAdmin     = true;
                            createdBranchName = viewModel.BranchName;
                            userName          = User.Identity.GetUserName();
                        }
                        else
                        {
                            createdBranchName = viewModel.BranchName;
                            userName          = User.Identity.GetUserName() + "(" + "Master Admin" + ")";
                        }
                        string body = string.Empty;
                        using (StreamReader reader = new StreamReader(Server.MapPath("~/MailDesign/InstallmentMailDesign.html")))
                        {
                            body = reader.ReadToEnd();
                        }
                        body = body.Replace("{BatchWithSubjectName}", viewModel.StudBatch);
                        body = body.Replace("{BranchName}", createdBranchName);
                        body = body.Replace("{StudentName}", viewModel.StudentName);
                        body = body.Replace("{ClassName}", students.ClassName);
                        body = body.Replace("{TotalFees}", studentFinalFee.ToString());
                        body = body.Replace("{PaidFees}", viewModel.Payment.ToString());
                        body = body.Replace("{RemainingFees}", remainingPayment.ToString());
                        body = body.Replace("{UserName}", userName);

                        var emailMessage = new MailModel
                        {
                            Body          = body,
                            Subject       = "Fees Payment",
                            To            = viewModel.Email,
                            IsBranchAdmin = isBranchAdmin
                        };
                        _emailService.Send(emailMessage);

                        if (viewModel.SMS == true)
                        {
                            string        classname;
                            string        query = "SELECT name FROM Configuration";
                            SqlConnection con   = new SqlConnection(constr);

                            SqlCommand cmd = new SqlCommand(query, con);
                            cmd.Connection = con;
                            con.Open();
                            SqlDataReader dr = cmd.ExecuteReader();

                            dr.Read();
                            classname = dr["name"].ToString();

                            var smsModel = new SmsModel
                            {
                                Message = "Hi " + classname + "\r\n Student Name: " + viewModel.StudentName + "\r\nPayment: " + viewModel.Payment + "\r\nRemaining Fees: " + viewModel.RemainingFee + "\r\nFees paid successfully.",
                                SendTo  = viewModel.ParentContact + "," + viewModel.StudentContact
                            };
                            var smsResult = _smsService.SendMessage(smsModel);
                        }
                        if (viewModel.AppNotification == true)
                        {
                            listOfPlayerId.Add(viewModel.ParentAppPlayerId);
                            listOfPlayerId = listOfPlayerId.Where(s => !string.IsNullOrWhiteSpace(s)).ToList();
                            var sendAppNotification = new SendNotification
                            {
                                Message    = "Fee-Student Name: " + viewModel.StudentName + " Payment: " + viewModel.Payment + " Remaining Fees: " + viewModel.RemainingFee + " Fees paid successfully.",
                                PlayerIds  = listOfPlayerId,
                                AppIds     = ConfigurationManager.AppSettings[Common.Constants.ParentAppId],
                                RestApiKey = ConfigurationManager.AppSettings[Common.Constants.ParentRestAppId]
                            };

                            if (listOfPlayerId.Count > 0)
                            {
                                var sendNotificationResult = _sendNotificationService.SendNotificationByPlayersId(sendAppNotification);
                            }
                        }

                        Success(result.Results.FirstOrDefault().Message);
                        ModelState.Clear();
                        viewModel                = new InstallmentViewModel();
                        ViewBag.StudentName      = "";
                        ViewBag.TotalFee         = "0";
                        ViewBag.RemainingFee     = "0";
                        ViewBag.installmentCount = "";
                    }
                    else
                    {
                        _logger.Warn(result.Results.FirstOrDefault().Message);
                        Warning(result.Results.FirstOrDefault().Message, true);
                        ViewBag.StudentName  = viewModel.StudentName;
                        ViewBag.TotalFee     = viewModel.TotalFee;
                        ViewBag.RemainingFee = viewModel.RemainingFee;
                    }
                }
            }
            else
            {
                ViewBag.StudentName  = viewModel.StudentName;
                ViewBag.TotalFee     = viewModel.TotalFee;
                ViewBag.RemainingFee = viewModel.RemainingFee;
            }

            if (roles == "Admin")
            {
                var branchList = _branchService.GetAllBranches().ToList();
                viewModel.Branches = new SelectList(branchList, "BranchId", "Name");
            }
            else if (roles == "BranchAdmin")
            {
            }
            viewModel.CurrentUserRole = roles;
            var classes = _classService.GetClasses().ToList();

            viewModel.Classes = new SelectList(classes, "ClassId", "Name");

            return(View(viewModel));
        }