public int GetTimeLimit(decimal pBalance, SurchargeInfo pAccessNumberSurcharge, SurchargeInfo pPayphoneSurcharge) { if (pBalance <= decimal.Zero) { return(0); } decimal _firstIncrementCost = firstIncrementCost; decimal _addIncrementCost = addIncrementCost; add(pAccessNumberSurcharge, ref _firstIncrementCost, ref _addIncrementCost); add(pPayphoneSurcharge, ref _firstIncrementCost, ref _addIncrementCost); if (_firstIncrementCost == decimal.Zero || _addIncrementCost == decimal.Zero) { return(0); } if (pBalance < _firstIncrementCost) { return(0); } if (pBalance == _firstIncrementCost) { return(firstIncrementLength); } //else: pBalance > First_increment_cost var _numberOfAddIncr = (int)(((pBalance - _firstIncrementCost) / _addIncrementCost)); var _timeLimitInSeconds = firstIncrementLength + _numberOfAddIncr * addIncrementLength; return(_timeLimitInSeconds); }
public RetailService(long pAccessNumber) { AccessNumberListRow _accessNumberRow; using (var _db = new Rbr_Db()) { _accessNumberRow = _db.AccessNumberListCollection.GetByPrimaryKey(pAccessNumber); } if (_accessNumberRow == null) { throw new Exception(string.Format("Service.Ctor: AccessNumber NOT FOUND, AccessNumber={0}", pAccessNumber)); } accessNumber = new AccessNumber(_accessNumberRow); using (var _db = new Rbr_Db()) { serviceRow = _db.ServiceCollection.GetByPrimaryKey(_accessNumberRow.Service_id); } if (serviceRow == null) { throw new Exception(string.Format("Service.Ctor: Service NOT FOUND, ServiceID={0}", _accessNumberRow.Service_id)); } //-- init PayphoneSurchargeInfo = SurchargeInfo.Empty; if (serviceRow.Payphone_surcharge_id > 0) { using (var _db = new Rbr_Db()) { var _payphoneSurchargeRow = _db.PayphoneSurchargeCollection.GetByPrimaryKey(serviceRow.Payphone_surcharge_id); if (_payphoneSurchargeRow != null) { PayphoneSurchargeInfo = new SurchargeInfo(_payphoneSurchargeRow.Surcharge, _payphoneSurchargeRow.SurchargeType); } } } }
public int GetTimeLimit(DateTime pDateTime, decimal pCurrentBalance, SurchargeInfo pAccessNumberSurcharge, SurchargeInfo pPayphoneSurcharge) { var _rate = getRate(pDateTime.Hour); if (_rate.IsBlocked) { TimokLogger.Instance.LogRbr(LogSeverity.Error, "TypeOfDayEntity.GetTimeLimit", string.Format("Rate is BLOCKED, rateInfoId: {0}", rateInfoId)); return(0); } return(_rate.GetTimeLimit(pCurrentBalance, pAccessNumberSurcharge, pPayphoneSurcharge)); }
public decimal GetCost(DateTime pDateTime, int pDuration, SurchargeInfo pAccessNumberSurcharge, SurchargeInfo pPayphoneSurcharge, out short pRoundedSeconds) { pRoundedSeconds = 0; var _rate = getRate(pDateTime.Hour); if (_rate.IsBlocked) { TimokLogger.Instance.LogRbr(LogSeverity.Error, "TypeOfDayEntity.GetCost", string.Format("Rate is BLOCKED, rateInfoId: {0}", rateInfoId)); return(decimal.Zero); } return(_rate.GetCost(pDuration, pAccessNumberSurcharge, pPayphoneSurcharge, out pRoundedSeconds)); }
public decimal GetRetailCost(DateTime pStartTime, int pDuration, SurchargeInfo pAccessNumberSurcharge, SurchargeInfo pPayphoneSurcharge, out short pRoundedSeconds) { pRoundedSeconds = 0; var _cost = decimal.Zero; if (ratingType == RatingType.Disabled) { return(_cost); } var _rateInfo = RateInfo.GetWholesaleRateInfo(WholesaleRouteId, pStartTime); if (_rateInfo != null) { if (ratingType == RatingType.PerCall) { if (pDuration > 0) { _cost += _rateInfo.GetPerCallCost(); } if (pAccessNumberSurcharge != null) { _cost += pAccessNumberSurcharge.Cost; } if (pPayphoneSurcharge != null) { _cost += pPayphoneSurcharge.Cost; } pRoundedSeconds = (short)(pDuration / 60 + pDuration % 60 > 0 ? 60 : 0); } else if (ratingType == RatingType.TimeBased) { _cost = _rateInfo.GetCost(pDuration, pAccessNumberSurcharge, pPayphoneSurcharge, out pRoundedSeconds); } else { throw new RbrException(RbrResult.Rate_TypeUnknown, "CustomerRoute.GetWholesaleCost", string.Format("{0}", ratingType)); } } if (_cost == 0) { TimokLogger.Instance.LogRbr(LogSeverity.Error, "CustomerRoute.GetWholesaleCost_Ex", string.Format("Cost is zero, RouteId={0}, for Duration={1}", routeRow.Route_id, pDuration)); } return(_cost); }
public decimal GetCost(int pDurationInSeconds, SurchargeInfo pAccessNumberSurcharge, SurchargeInfo pPayphoneSurcharge, out short pRoundedSeconds) { pRoundedSeconds = 0; if (firstIncrementLength <= 0 || addIncrementLength <= 0) { return(decimal.Zero); } var _numberOfAddIncr = 0; var _firstIncrementCost = decimal.Zero; var _addIncrementCost = decimal.Zero; add(pAccessNumberSurcharge, ref _firstIncrementCost, ref _addIncrementCost); add(pPayphoneSurcharge, ref _firstIncrementCost, ref _addIncrementCost); if (pDurationInSeconds > 0) { _firstIncrementCost += firstIncrementCost; _addIncrementCost += addIncrementCost; if (pDurationInSeconds <= firstIncrementLength) { _numberOfAddIncr = 0; } else { _numberOfAddIncr = (pDurationInSeconds - firstIncrementLength) / addIncrementLength; _numberOfAddIncr += (pDurationInSeconds - firstIncrementLength) % addIncrementLength == 0 ? 0 : 1; } var _roundedSeconds = firstIncrementLength + _numberOfAddIncr * addIncrementLength; if (_roundedSeconds > short.MaxValue) { TimokLogger.Instance.LogRbr(LogSeverity.Critical, "Rate.GetCost", "_roundedSeconds > short.MaxValue"); pRoundedSeconds = short.MaxValue; } else { pRoundedSeconds = (short)_roundedSeconds; } } var _cost = _firstIncrementCost + _numberOfAddIncr * _addIncrementCost; return(_cost); }
//----------------------------------------- Privates ------------------------------------------------ void add(SurchargeInfo pSurchargeInfo, ref decimal pFirstIncrementCost, ref decimal pAddIncrementCost) { if (pSurchargeInfo == null || pSurchargeInfo.Cost <= decimal.Zero) { return; } if (pSurchargeInfo.SurchargeType == SurchargeType.PerCall) { pFirstIncrementCost += pSurchargeInfo.Cost; return; } var _firstIncrSurchargePercentage = (100 * firstIncrementLength) / 60; var _addIncrSurchargePercentage = (100 * addIncrementLength) / 60; pFirstIncrementCost += pSurchargeInfo.Cost * (_firstIncrSurchargePercentage / 100); pAddIncrementCost += pSurchargeInfo.Cost * (_addIncrSurchargePercentage / 100); }
public int GetNormalizedCost() { var _minutesLenghtList = new[] { 1, 2, 3, 4, 5, 7, 9, 11, 14, 17, 20, 25, 30, 40, 50, 60, 75, 90, 120 }; decimal _totalCost = 0; var _surcharge = new SurchargeInfo(decimal.Zero, SurchargeType.PerCall); for (var _i = 0; _i < _minutesLenghtList.Length; _i++) { short _roundedSeconds; var _cost = GetCost(_minutesLenghtList[_i] * 60, _surcharge, _surcharge, out _roundedSeconds); //decimal _mw = _cost * 10000000; _totalCost = decimal.Add(_totalCost, _cost); } var _res = normalize(_totalCost); return(_res); }
public int GetTimeLimit(decimal pCurrentBalance, SurchargeInfo pAccessNumberSurcharge, SurchargeInfo pPayphoneSurcharge) { int _timeLimit = 0; if (ratingType == RatingType.Disabled) { return(_timeLimit); } var _rateInfo = RateInfo.GetWholesaleRateInfo(WholesaleRouteId, DateTime.Now); if (_rateInfo != null) { if (ratingType == RatingType.PerCall) { //TODO: this should move to Authenticate? it doesn't depend on dialedNumber (Route) if (pCurrentBalance < (pAccessNumberSurcharge.Cost + pPayphoneSurcharge.Cost + _rateInfo.GetPerCallCost())) { _timeLimit = 0; } else { _timeLimit = Configuration.Instance.Main.PerCallTimeLimit; //_rateInfo.GetTimeLimit(); } } else if (ratingType == RatingType.TimeBased) { _timeLimit = _rateInfo.GetTimeLimit(pCurrentBalance, pAccessNumberSurcharge, pPayphoneSurcharge); } else { throw new RbrException(RbrResult.Rate_TypeUnknown, "CustomerRoute.GetTimeLimit", string.Format("{0}", ratingType)); } } if (_timeLimit == 0) { TimokLogger.Instance.LogRbr(LogSeverity.Error, "CustomerRoute.GetTimeLimit_Ex", string.Format("TimeLimit is zero, RouteId={0}, for Amount={1}", routeRow.Route_id, pCurrentBalance)); } return(_timeLimit); }
public decimal GetCost(int pDuration, SurchargeInfo pAccessNumberSurcharge, SurchargeInfo pPayphoneSurcharge, out short pRoundedSeconds) { return(currentRates.GetCost(dateTime, pDuration, pAccessNumberSurcharge, pPayphoneSurcharge, out pRoundedSeconds)); }
public int GetTimeLimit(decimal pCurrentBalance, SurchargeInfo pAccessNumberSurcharge, SurchargeInfo pPayphoneSurcharge) { return(currentRates.GetTimeLimit(dateTime, pCurrentBalance, pAccessNumberSurcharge, pPayphoneSurcharge)); }
public AccessNumber(AccessNumberListRow pAccessNumberRow) { accessNumberRow = pAccessNumberRow; Number = accessNumberRow.Access_number; surchargeInfo = new SurchargeInfo(pAccessNumberRow.Surcharge, pAccessNumberRow.SurchargeType); }