/// <summary> /// </summary> /// <param name="iInstrType"></param> /// <param name="iInstrOPType"></param> /// <param name="hInputValues"></param> /// <param name="sErrMsg"></param> /// <param name="alErrorMsg"></param> /// <returns>Calculated result</returns> public static Double DoCalculate(int iInstrType, int iInstrOPType, Hashtable hInputValues, ref string sErrMsg, ref ArrayList alErrorMsg) { Double dResult = 0; try { // Validate input fields dResult = ValidateFields(hInputValues, iInstrType, iInstrOPType, ref sErrMsg, ref alErrorMsg); if (dResult > 0) { if (iInstrType == Constants.cStr_IT_SavingsAccount || iInstrType == Constants.cStr_IT_CurrentAccount || iInstrType == Constants.cStr_IT_CashAtHand) { if (iInstrType == Constants.cStr_IT_CashAtHand) { dResult = Convert.ToDouble(hInputValues["DAMT"]); } else { dResult = Convert.ToDouble(hInputValues["AAB"]); } return(dResult); } // Set calculated field values. setCalculatedFields(iInstrType, iInstrOPType, hInputValues); string sFormula = null; int nCount = dsFormula.Tables[0].Rows.Count; DataTable dtFormula = dsFormula.Tables[0]; var resultFormula = from formula in dtFormula.AsEnumerable() where formula.Field <Int32>("OFM_InstrumentTypeId") == iInstrType && formula.Field <Int32>("OFM_OutputId") == iInstrOPType select formula; foreach (var formula in resultFormula) { // If interest calculation basis is simple use formula 9 or formula 2 for the instruments, if ((iInstrType == Constants.cStr_IT_FixedDeposits || iInstrType == Constants.cStr_IT_CompanyFD || iInstrType == Constants.cStr_IT_GOIReliefBonds || iInstrType == Constants.cStr_IT_GOITaxSavingBonds || iInstrType == Constants.cStr_IT_TaxSavingBonds) && (iInstrOPType == Constants.cStr_IO_CurrentValue || iInstrOPType == Constants.cStr_IO_MaturityValue || iInstrOPType == Constants.cStr_IO_InterestAccumulatedEarnedTillDate || iInstrOPType == Constants.cStr_IO_InterestAccumulatedEarnedTillMaturity) && hInputValues["ICB"].Equals("Simple")) { if (formula["OFM_FormulaId"].ToString().Equals(Constants.cStr_Formula_SimpleInterestBasis) && formula.ItemArray[3].ToString().Equals(Constants.cStr_Formula_SimpleInterestBasis)) { sFormula = formula["FM_Formula"].ToString(); break; } else if (formula["OFM_FormulaId"].ToString().Equals(Constants.cStr_Formula_InterestAccumulatedEarnedTillDate) && formula.ItemArray[3].ToString().Equals(Constants.cStr_Formula_InterestAccumulatedEarnedTillDate)) { sFormula = formula["FM_Formula"].ToString(); break; } } else if (iInstrType == Constants.cStr_IT_SeniorCitizensSavingsScheme || iInstrType == Constants.cStr_IT_PostOfficeSavingsBankAcc || iInstrType == Constants.cStr_IT_PostOfficeMIS) { sFormula = formula["FM_Formula"].ToString(); break; } else { if (formula["OFM_FormulaId"].ToString().Equals(Constants.cStr_Formula_SimpleInterestBasis) && formula.ItemArray[3].ToString().Equals(Constants.cStr_Formula_SimpleInterestBasis)) { continue; } else if (formula["OFM_FormulaId"].ToString().Equals(Constants.cStr_Formula_InterestAccumulatedEarnedTillDate) && formula.ItemArray[3].ToString().Equals(Constants.cStr_Formula_InterestAccumulatedEarnedTillDate)) { continue; } else if (formula["OFM_FormulaId"].ToString().Equals(Constants.cStr_Formula_CompoundInterestAccumulatedEarnedTillDate) && formula.ItemArray[3].ToString().Equals(Constants.cStr_Formula_CompoundInterestAccumulatedEarnedTillDate)) { sFormula = formula["FM_Formula"].ToString(); break; } else if (formula["OFM_FormulaId"].ToString().Equals(Constants.cStr_Formula_CurrentValueOrMaturityValue) && formula.ItemArray[3].ToString().Equals(Constants.cStr_Formula_CurrentValueOrMaturityValue)) { sFormula = formula["FM_Formula"].ToString(); break; } else { sFormula = formula["FM_Formula"].ToString(); break; } } } // Months will be rounded of to the nearest year if the covered under Gratuity Act otherwise no rounded off if (iInstrType == Constants.cStr_IT_Gratuity) { int nNoOfMonthComp = Convert.ToInt32(hInputValues["NOMC"]); int nNoOfYearsComp = Convert.ToInt32(hInputValues["CYOS"]); if (iInstrOPType == Constants.cStr_IO_GratuityAmountWhenCoveredUnderGratuityAct) { if (nNoOfMonthComp > 5) { nNoOfYearsComp += 1; } hInputValues["CYOS"] = nNoOfYearsComp; } else { hInputValues["CYOS"] = nNoOfYearsComp; } } IDictionaryEnumerator en = hInputValues.GetEnumerator(); while (en.MoveNext()) { string str = en.Key.ToString(); if (sFormula.Contains(str)) { sFormula = sFormula.Replace(str, en.Value.ToString()); } } FunctionParser fn = new FunctionParser(); fn.Parse(sFormula); fn.Infix2Postfix(); fn.EvaluatePostfix(); dResult = Math.Round(fn.Result, 2); } return(dResult); } catch (BaseApplicationException Ex) { throw Ex; } catch (Exception Ex) { BaseApplicationException exBase = new BaseApplicationException(Ex.Message, Ex); NameValueCollection FunctionInfo = new NameValueCollection(); object[] objects = new object[4]; objects[0] = iInstrType; objects[1] = iInstrOPType; objects[2] = hInputValues; objects[3] = sErrMsg; objects[4] = alErrorMsg; FunctionInfo.Add("Method", "CalculatorBo.cs:DoCalculate()"); FunctionInfo = exBase.AddObject(FunctionInfo, objects); exBase.AdditionalInformation = FunctionInfo; ExceptionManager.Publish(exBase); throw exBase; } }