internal static List <LoanDeduction> GetListByLoanProductId(int loanProductId) { var sqlBuilder = new StringBuilder(); sqlBuilder.AppendLine("SELECT ld.ID, ld.LoanProductId, ld.AccountCode, ch.TITLE, ld.Amount"); sqlBuilder.AppendLine("FROM " + TABLE_NAME + " ld"); sqlBuilder.AppendLine("LEFT JOIN chart ch"); sqlBuilder.AppendLine("ON ld.AccountCode = ch.`CODE`"); sqlBuilder.AppendLine("WHERE ld.LoanProductId = ?LoanProductId"); sqlBuilder.AppendLine("ORDER BY ld.AccountCode"); DataTable dataTable = DatabaseController.ExecuteSelectQuery(sqlBuilder, new SqlParameter("?LoanProductId", loanProductId)); var loanDeductions = new List <LoanDeduction>(); foreach (DataRow dataRow in dataTable.Rows) { var loanDeduction = new LoanDeduction(); loanDeduction.SetPropertiesFromDataRow(dataRow); loanDeductions.Add(loanDeduction); } return(loanDeductions); }
public LoanComputation(decimal loanAmount, int loanProductId) : this() { LoanAmount = loanAmount; var loanProduct = new LoanProduct(); loanProduct.Find(loanProductId); var loanApplied = Account.FindByCode(loanProduct.ProductCode); LoanDescription = string.Format("{0} - {1}", loanApplied.AccountCode, loanApplied.AccountTitle); LoanDetails.AccountCode = loanApplied.AccountCode; #region --- Populate Charges --- var loanCharges = LoanCharge.GetListByLoanProductId(loanProduct.ID); int i = 0; foreach (var loanCharge in loanCharges) { i++; if (i == 1) { ChargeCode1 = loanCharge.AccountCode; ChargeTitle1 = loanCharge.AccountTitle; ChargeAmount1 = Math.Round(loanCharge.Rate * LoanAmount, 2); continue; } if (i == 2) { ChargeCode2 = loanCharge.AccountCode; ChargeTitle2 = loanCharge.AccountTitle; ChargeAmount2 = Math.Round(loanCharge.Rate * LoanAmount, 2); continue; } if (i == 3) { ChargeCode3 = loanCharge.AccountCode; ChargeTitle3 = loanCharge.AccountTitle; ChargeAmount3 = Math.Round(loanCharge.Rate * LoanAmount, 2); continue; } if (i == 4) { ChargeCode4 = loanCharge.AccountCode; ChargeTitle4 = loanCharge.AccountTitle; ChargeAmount4 = Math.Round(loanCharge.Rate * LoanAmount, 2); continue; } if (i == 5) { ChargeCode5 = loanCharge.AccountCode; ChargeTitle5 = loanCharge.AccountTitle; ChargeAmount5 = Math.Round(loanCharge.Rate * LoanAmount, 2); continue; } if (i == 6) { ChargeCode6 = loanCharge.AccountCode; ChargeTitle6 = loanCharge.AccountTitle; ChargeAmount6 = Math.Round(loanCharge.Rate * LoanAmount, 2); break; } } #endregion #region --- Populate Deductions --- var loanDeductions = LoanDeduction.GetListByLoanProductId(loanProduct.ID); i = 0; foreach (var loanDeduct in loanDeductions) { i++; if (i == 1) { DeductCode1 = loanDeduct.AccountCode; DeductTitle1 = loanDeduct.AccountTitle; DeductAmount1 = loanDeduct.Amount; continue; } if (i == 2) { DeductCode2 = loanDeduct.AccountCode; DeductTitle2 = loanDeduct.AccountTitle; DeductAmount2 = loanDeduct.Amount; continue; } if (i == 3) { DeductCode3 = loanDeduct.AccountCode; DeductTitle3 = loanDeduct.AccountTitle; DeductAmount3 = loanDeduct.Amount; continue; } if (i == 4) { DeductCode4 = loanDeduct.AccountCode; DeductTitle4 = loanDeduct.AccountTitle; DeductAmount4 = loanDeduct.Amount; continue; } if (i == 5) { DeductCode5 = loanDeduct.AccountCode; DeductTitle5 = loanDeduct.AccountTitle; DeductAmount5 = loanDeduct.Amount; continue; } if (i == 6) { DeductCode6 = loanDeduct.AccountCode; DeductTitle6 = loanDeduct.AccountTitle; DeductAmount6 = loanDeduct.Amount; break; } } #endregion #region --- INITIALIZE DEFAULT NET PROCEEDS --- var netProceedsAccount = Account.FindByCode(GlobalSettings.CodeOfCashOnHand); NetProceedsCode = netProceedsAccount.AccountCode; //NetProceedsTitle = netProceedsAccount.AccountTitle; #endregion --- INITIALIZE DEFAULT NET PROCEEDS --- }