Example #1
0
        public JsonResult SaveLedger(tbl_loan_ledger model)
        {
            try
            {
                db_lendingEntities db = new db_lendingEntities();

                tbl_loan_ledger tbl = new tbl_loan_ledger();

                tbl.date_trans     = model.date_trans;
                tbl.trans_type     = model.trans_type;
                tbl.reference_no   = model.reference_no;
                tbl.loan_no        = model.loan_no;
                tbl.loan_type_name = model.loan_type_name;
                tbl.customer_id    = model.customer_id;
                tbl.customer_name  = model.customer_name;
                tbl.interest_type  = model.interest_type;
                tbl.interest_rate  = model.interest_rate;
                tbl.interest       = model.interest;
                tbl.amount_paid    = model.amount_paid;
                tbl.principal      = model.principal;
                tbl.balance        = model.balance;
                tbl.date_created   = DateTime.Now;
                tbl.created_by     = Session["UserName"].ToString();

                db.tbl_loan_ledger.Add(tbl);

                db.SaveChanges();

                return(Json(tbl.reference_no, JsonRequestBehavior.AllowGet));
            }
            catch (Exception ex)
            {
                return(Json("Failed", JsonRequestBehavior.DenyGet));

                throw ex;
            }
        }
        public ActionResult Save(string id)
        {
            try
            {
                using (db = new db_lendingEntities())
                {
                    string message = "";
                    var    result  = from d in db.tbl_loan_processing where d.loan_no.Equals(id) select d;

                    foreach (var dt in result)
                    {
                        DateTime newDueDate = (DateTime)dt.due_date;
                        var      dueDate    = newDueDate.ToString("MM/dd/yyyy");

                        DateTime newLoanDate = (DateTime)dt.loan_date;
                        var      loanDate    = newLoanDate.ToString("MM/dd/yyyy");

                        decimal loanBalance = decimal.Round((decimal)GetLedgerBalance(dt.loan_no), 2, MidpointRounding.AwayFromZero);

                        decimal restructuredInterest      = 0;
                        decimal restructuredInterestTotal = 0;
                        decimal newLoanBalance            = loanBalance;
                        int     loop = interestLoop(dt.loan_no);
                        for (int i = 0; i < loop; i++)
                        {
                            restructuredInterest      = decimal.Round(newLoanBalance * ((decimal)dt.loan_interest_rate / 100), 2, MidpointRounding.AwayFromZero);
                            newLoanBalance            = newLoanBalance + restructuredInterest;
                            restructuredInterestTotal = restructuredInterestTotal + restructuredInterest;
                        }

                        if (loanBalance > 0)
                        {
                            db_lendingEntities dbSave = new db_lendingEntities();
                            tbl_loan_ledger    tbl    = new tbl_loan_ledger();

                            tbl.date_trans     = _serverDateTime;
                            tbl.trans_type     = "Late Payment Interest";
                            tbl.reference_no   = "";
                            tbl.loan_no        = dt.loan_no;
                            tbl.loan_type_name = dt.loan_name;
                            tbl.customer_id    = dt.customer_id;
                            tbl.customer_name  = dt.customer_name.ToUpper();
                            tbl.interest_type  = GetInterestType(dt.loan_name);
                            tbl.interest_rate  = dt.loan_interest_rate;
                            tbl.interest       = restructuredInterestTotal;
                            tbl.amount_paid    = 0;
                            tbl.principal      = 0;
                            tbl.balance        = 0;
                            tbl.date_created   = DateTime.Now;
                            tbl.created_by     = Session["UserName"].ToString();

                            dbSave.tbl_loan_ledger.Add(tbl);

                            dbSave.SaveChanges();

                            message = "Success!";
                        }
                        else
                        {
                            message = "Failed!";
                        }
                    }
                    return(Json(new { success = true, message = message }, JsonRequestBehavior.AllowGet));
                }
            }
            catch (Exception ex)
            {
                throw new Exception(ex.Message);
            }
        }
Example #3
0
        public JsonResult GenerateInterest(string loanNo)
        {
            using (db = new db_lendingEntities())
            {
                var result =
                    from d in db.tbl_loan_processing
                    where d.loan_no == loanNo &&
                    d.status == "Released" &&
                    d.due_date < _serverDateTime
                    orderby d.loantype_id ascending
                    select d;
                foreach (var dt in result)
                {
                    var balance = (decimal)GetLedgerBalance(dt.loan_no);

                    if (balance > 0)
                    {
                        var     interestRate = (decimal)dt.loan_interest_rate;
                        decimal noOfDays     = 0;
                        var     dateStart    = GetInterestStartDate(dt.loan_no);

                        var skipIinterest = false;

                        if (GetInterestType(dt.loan_name) == "1")
                        {
                            noOfDays = decimal.ToInt32((_serverDateTime - dateStart).Value.Days);
                        }
                        else
                        {
                            skipIinterest = true;
                            //if ((decimal.ToInt32((_serverDateTime - dateStart).Value.Days)) >= 1)
                            //{
                            //    if ((decimal.ToInt32((_serverDateTime - dateStart).Value.Days)) == 1)
                            //    {
                            //        if (NoOfInterest(dt.loan_no) >=
                            //            (decimal.ToInt32((_serverDateTime - dateStart).Value.Days)))
                            //        {
                            //            skipIinterest = true;
                            //        }
                            //        noOfDays = 1;
                            //    }
                            //    else
                            //    {
                            //        noOfDays = (_serverDateTime - dateStart).Value.Days;
                            //        noOfDays = (noOfDays / 30);
                            //        noOfDays = decimal.Ceiling(noOfDays);
                            //        if (NoOfInterest(dt.loan_no) >= noOfDays)
                            //        {
                            //            skipIinterest = true;
                            //        }
                            //    }
                            //}
                        }
                        decimal totalInterest = 0;
                        for (var c = 0; c < noOfDays; c++)
                        {
                            var interest = (balance * (interestRate / 100));
                            balance       = balance + interest;
                            totalInterest = totalInterest + interest;
                        }
                        if (skipIinterest == false)
                        {
                            db_lendingEntities dbSave = new db_lendingEntities();
                            tbl_loan_ledger    tbl    = new tbl_loan_ledger();

                            tbl.date_trans     = _serverDateTime;
                            tbl.trans_type     = "Late Payment Interest";
                            tbl.reference_no   = "";
                            tbl.loan_no        = dt.loan_no;
                            tbl.loan_type_name = dt.loan_name;
                            tbl.customer_id    = dt.customer_id;
                            tbl.customer_name  = dt.customer_name;
                            tbl.interest_type  = GetInterestType(dt.loan_name);
                            tbl.interest_rate  = dt.loan_interest_rate;
                            tbl.interest       = totalInterest;
                            tbl.amount_paid    = 0;
                            tbl.principal      = 0;
                            tbl.balance        = 0;
                            tbl.date_created   = DateTime.Now;
                            tbl.created_by     = Session["UserName"].ToString();

                            dbSave.tbl_loan_ledger.Add(tbl);

                            dbSave.SaveChanges();
                        }
                    }
                }
            }

            return(Json("Success", JsonRequestBehavior.AllowGet));
        }
Example #4
0
        public async Task <JsonResult> Save(collectionSaveModel model)
        {
            try
            {
                tbl_payment payment = new tbl_payment();

                bool   success = false;
                string message = "";

                db = new db_lendingEntities();

                var isDuplicate = await db.tbl_payment.AllAsync(u => u.reference_no == model.PaymentNo);

                if (isDuplicate == false)
                {
                    payment.reference_no = model.PaymentNo;
                    payment.date_trans   = DateTime.Parse(model.PaymentDate);
                    payment.payor_id     = int.Parse(model.CustomerId);
                    payment.payor_name   = model.CustomerName;
                    payment.total_amount = decimal.Round(decimal.Parse(model.Payment), 2,
                                                         MidpointRounding.AwayFromZero);
                    payment.created_by   = Session["UserName"].ToString();
                    payment.date_created = DateTime.Now;

                    db.tbl_payment.Add(payment);
                    await db.SaveChangesAsync();

                    var result = true;
                    success = result;
                    if (result)
                    {
                        decimal totalPayment       = 0;
                        decimal amountDuePrincipal = 0;
                        decimal amountDueInterest  = 0;

                        try
                        {
                            totalPayment = decimal.Round(decimal.Parse(model.Payment), 2,
                                                         MidpointRounding.AwayFromZero);
                            amountDuePrincipal = decimal.Round(decimal.Parse(model.AmountDuePrincipal), 2,
                                                               MidpointRounding.AwayFromZero);
                            amountDueInterest = decimal.Round(decimal.Parse(model.AmountDueInterest), 2,
                                                              MidpointRounding.AwayFromZero);
                        }
                        catch (Exception ex)
                        {
                        }

                        decimal paymentInterest  = 0;
                        decimal paymentPrincipal = 0;

                        if (amountDueInterest > 0)
                        {
                            if (totalPayment >= amountDueInterest)
                            {
                                paymentInterest = decimal.Round(amountDueInterest, 2, MidpointRounding.AwayFromZero);
                                totalPayment    = totalPayment - paymentInterest;
                            }
                            else if (totalPayment < amountDueInterest)
                            {
                                paymentInterest = totalPayment;
                                totalPayment    = 0;
                            }
                        }
                        if (amountDuePrincipal > 0)
                        {
                            paymentPrincipal = totalPayment;
                            totalPayment     = 0;
                        }
                        if (paymentPrincipal > 0)
                        {
                            tbl_payment_details paymentDetailsPrincipal = new tbl_payment_details();
                            paymentDetailsPrincipal.reference_no = model.PaymentNo;
                            paymentDetailsPrincipal.payment_type = "OR Payment";
                            paymentDetailsPrincipal.loan_no      = model.LoanNo;
                            paymentDetailsPrincipal.loan_name    = model.LoanName;
                            paymentDetailsPrincipal.due_date     = DateTime.Parse(model.LoanDueDate);
                            paymentDetailsPrincipal.amount       =
                                decimal.Round(paymentPrincipal, 2, MidpointRounding.AwayFromZero);
                            paymentDetailsPrincipal.created_by   = Session["UserName"].ToString();
                            paymentDetailsPrincipal.date_created = DateTime.Now;
                            db.tbl_payment_details.Add(paymentDetailsPrincipal);
                            await db.SaveChangesAsync();
                        }
                        if (paymentInterest > 0)
                        {
                            tbl_payment_details paymentDetailsInterest = new tbl_payment_details();
                            paymentDetailsInterest.reference_no = model.PaymentNo;
                            paymentDetailsInterest.payment_type = "OR Payment Interest";
                            paymentDetailsInterest.loan_no      = model.LoanNo;
                            paymentDetailsInterest.loan_name    = model.LoanName;
                            paymentDetailsInterest.due_date     = DateTime.Parse(model.LoanDueDate);
                            paymentDetailsInterest.amount       =
                                decimal.Round(paymentInterest, 2, MidpointRounding.AwayFromZero);
                            paymentDetailsInterest.created_by   = Session["UserName"].ToString();
                            paymentDetailsInterest.date_created = DateTime.Now;
                            db.tbl_payment_details.Add(paymentDetailsInterest);
                            await db.SaveChangesAsync();
                        }

                        tbl_loan_ledger loanLedger = new tbl_loan_ledger();
                        loanLedger.date_trans     = DateTime.Parse(model.PaymentDate);
                        loanLedger.trans_type     = "OR Payment";
                        loanLedger.reference_no   = model.PaymentNo;
                        loanLedger.loan_no        = model.LoanNo;
                        loanLedger.loan_type_name = model.LoanName;
                        loanLedger.customer_id    = int.Parse(model.CustomerId);
                        loanLedger.customer_name  = model.CustomerName;
                        loanLedger.interest_type  = GetInterestType(model.LoanName);
                        loanLedger.interest_rate  = GetInterestRate(model.LoanName);
                        loanLedger.interest       = decimal.Round(paymentInterest, 2, MidpointRounding.AwayFromZero);
                        loanLedger.amount_paid    =
                            decimal.Round(decimal.Parse(model.Payment), 2, MidpointRounding.AwayFromZero);
                        loanLedger.principal    = decimal.Round(paymentPrincipal, 2, MidpointRounding.AwayFromZero);
                        loanLedger.balance      = 0;
                        loanLedger.date_created = DateTime.Now;
                        loanLedger.created_by   = Session["UserName"].ToString();
                        db.tbl_loan_ledger.Add(loanLedger);
                        await db.SaveChangesAsync();

                        message = "Successfully saved.";
                    }
                    else
                    {
                        message = "Error saving data. Duplicate entry.";
                    }
                }
                else
                {
                    message = "Error saving data. Duplicate entry.";
                }

                return(Json(new { success = success, message = message }));
            }
            catch (Exception ex)
            {
                throw new Exception(ex.Message);

                return(Json(new { success = false, message = "Failed to save." }));
            }
        }
Example #5
0
        public async Task <JsonResult> Save(tbl_adjustment model)
        {
            try
            {
                tbl_adjustment adjustment = new tbl_adjustment();

                var adjustmentNo = 0;
                using (db = new db_lendingEntities())
                {
                    var count = db.tbl_adjustment.ToList();

                    if (count.Count != 0)
                    {
                        adjustmentNo = db.tbl_adjustment.Max(a => a.Autonum) + 1;
                    }
                    else
                    {
                        adjustmentNo = 1;
                    }
                }

                bool   success = false;
                string message = "";

                using (db_lendingEntities dbSave = new db_lendingEntities())
                {
                    adjustment.TransType = model.TransType;
                    adjustment.DateTrans = model.DateTrans;
                    adjustment.LoanNo    = model.LoanNo;
                    adjustment.Remarks   = model.Remarks;
                    adjustment.Amount    = decimal.Round((decimal)model.Amount, 2, MidpointRounding.AwayFromZero);
                    adjustment.CreatedBy = Session["UserName"].ToString();
                    adjustment.CreatedAt = DateTime.Now;
                    dbSave.tbl_adjustment.Add(adjustment);
                    await dbSave.SaveChangesAsync();

                    var result = true;
                    success = result;
                    if (result)
                    {
                        var customerId   = 0;
                        var customerName = "";
                        var loanName     = "";

                        using (db = new db_lendingEntities())
                        {
                            var loan = from d in db.tbl_loan_processing where d.loan_no == model.LoanNo && d.status == "Released" select d;
                            foreach (var dt in loan)
                            {
                                customerId   = (int)dt.customer_id;
                                customerName = dt.customer_name;
                                loanName     = dt.loan_name;
                            }
                        }

                        tbl_loan_ledger loanLedger = new tbl_loan_ledger();
                        loanLedger.date_trans     = model.DateTrans;
                        loanLedger.trans_type     = model.TransType;
                        loanLedger.reference_no   = adjustmentNo.ToString();
                        loanLedger.loan_no        = model.LoanNo;
                        loanLedger.loan_type_name = loanName.ToString();
                        loanLedger.customer_id    = customerId;
                        loanLedger.customer_name  = customerName;
                        loanLedger.interest_type  = GetInterestType(loanName);
                        loanLedger.interest_rate  = GetInterestRate(loanName);
                        loanLedger.interest       = decimal.Round((decimal)model.Amount, 2, MidpointRounding.AwayFromZero);
                        loanLedger.amount_paid    = decimal.Round(0, 2, MidpointRounding.AwayFromZero);
                        loanLedger.principal      = decimal.Round(0, 2, MidpointRounding.AwayFromZero);
                        loanLedger.balance        = 0;
                        loanLedger.date_created   = DateTime.Now;
                        loanLedger.created_by     = Session["UserName"].ToString();
                        dbSave.tbl_loan_ledger.Add(loanLedger);
                        await dbSave.SaveChangesAsync();

                        message = "Successfully saved.";
                    }
                    else
                    {
                        message = "Error saving data. Duplicate entry.";
                    }
                }

                return(Json(new { success = success, message = message }));
            }
            catch (Exception ex)
            {
                throw new Exception(ex.Message);
            }
        }