//--------------------------- private ----------------------------- static CustomerRoute getCustomerRoute(short pServiceId, int pRoutingPlanId, int pBaseRouteId) { CustomerRoute _customerRoute = null; using (var _db = new Rbr_Db()) { var _routeRow = _db.RouteCollection.GetByPrimaryKey(pBaseRouteId); if (_routeRow != null) { var _wholesaleRouteRow = _db.WholesaleRouteCollection.GetByServiceIdBaseRouteId(pServiceId, pBaseRouteId); if (_wholesaleRouteRow != null) { _customerRoute = new CustomerRoute(_wholesaleRouteRow, pRoutingPlanId, _routeRow); } else { TimokLogger.Instance.LogRbr(LogSeverity.Error, "CustomerRoute.getCustomerRoute", string.Format("ServiceRouteRow NOT FOUND: {0}, {1}", pServiceId, pBaseRouteId)); } } else { TimokLogger.Instance.LogRbr(LogSeverity.Error, "CustomerRoute.getCustomerRoute", string.Format("CustomerRouteRow NOT FOUND: {0}, {1}", pServiceId, pBaseRouteId)); } } return(_customerRoute); }
//----------------------------------------- Public Instance Methods ------------------------------------ public int Authorize(CustomerRoute pCustomerRoute) { if (Status != Status.Active) { throw new RbrException(RbrResult.Customer_NotActive, "CustomerAcct.Authorize", string.Format("CustomerAcctId={0}", Id)); } if (NumberOfCallsCounter.ContainsKey(Id)) { if (NumberOfCallsCounter[Id] >= MaxNumberOfCalls) { throw new RbrException(RbrResult.Customer_LimitReached, "CustomerAcct.Authorize", string.Format("CustomerAcctId={0}", Id)); } } if (!IsPrepaid) { return(MaxCallLength); } //-- Check prepaid conditions if (IsBalanceLimitReached) { throw new RbrException(RbrResult.Customer_BalanceInvalid, "CustomerAcct.Authorize", string.Format("Customer Balance INVALID, CustomerAcctId={0}", Id)); } if (IsBalanceWarningLimitReached) { TimokLogger.Instance.LogRbr(LogSeverity.Error, "CustomerAcct.Authorize", string.Format("Customer Warning REACHED, CustomerAcctId={0}", Id)); } if (pCustomerRoute.Status != Status.Active) { throw new RbrException(RbrResult.Customer_RouteBlocked, "CustomerAcct.Authorize", string.Format("CustomerAcctId={0}, CustomerRouteId={1}", Id, pCustomerRoute.WholesaleRouteId)); } int _timeLimit = pCustomerRoute.GetTimeLimit(Balance); if (_timeLimit <= 0) { throw new RbrException(RbrResult.Customer_LimitReached, "CustomerAcct.Authorize", string.Format("Customer Limit REACHED, CustomerAcct={0}", Id)); } if (_timeLimit > MaxCallLength) { _timeLimit = MaxCallLength; TimokLogger.Instance.LogRbr(LogSeverity.Status, "CustomerAcct.Authorize", string.Format("Max Call Time Limit REACHED, CustomerAcct={0}, Calculated TimeLimit={1}", Id, _timeLimit)); } return(_timeLimit); }
//--------------------- End-Static ------------------------------------------------------- public void Authorize(ISession pSession, IRetailAccount pRetailAcct, CustomerRoute pCustomerRoute, out int pTimeLimit, out int pPromptTimeLimit) { pTimeLimit = 0; //--Check for Domestic Bonus minutes: if (pRetailAcct.WithBonusMinutes && pCustomerRoute.WithBonusMinutes && pRetailAcct.CurrentBonusBalance > 0) { pTimeLimit = pRetailAcct.CurrentBonusBalance * 60; } //-- Check money based balance and add to the TimeLimit if balance > 0: if (pRetailAcct.CurrentBalance > decimal.Zero) { var _accessNumberSurcharge = AccessNumberSurchargeInfo; var _payphoneSurcharge = SurchargeInfo.Empty; if (pSession.InfoDigits > 0) { _payphoneSurcharge = PayphoneSurchargeInfo; } pTimeLimit += pCustomerRoute.GetTimeLimit(pRetailAcct.CurrentBalance, _accessNumberSurcharge, _payphoneSurcharge); } if (pTimeLimit < 0) { pTimeLimit = 0; TimokLogger.Instance.LogRbr(LogSeverity.Critical, "BillingService.Authorize:", string.Format("TimeLimit less then Zero! Serial={0}, CustomerId={1} TimeLimit={2}", pRetailAcct.SerialNumber, pRetailAcct.CustomerAcctId, pTimeLimit)); } //-- propmpt multiplier if (pCustomerRoute.Multiplier > 0) { pPromptTimeLimit = (pTimeLimit * pCustomerRoute.Multiplier) / 100; } else { pPromptTimeLimit = pTimeLimit; } }
public int RateCall(CustomerRoute pCustomerRoute, ref Cdr pCdr) { int _result = 0; pCdr.CustomerDuration = (short)((pCdr.Duration / 6) * 6); pCdr.CustomerDuration += (short)(pCdr.Duration % 6 > 0 ? 6 : 0); if (IsRatingEnabled && pCustomerRoute != null) { if (IsWholesale) { try { short _roundedSeconds; pCdr.CustomerPrice = pCustomerRoute.GetWholesaleCost(pCdr.StartTime, pCdr.Duration, out _roundedSeconds); if (_roundedSeconds > short.MaxValue) { TimokLogger.Instance.LogRbr(LogSeverity.Critical, "CustomerAcct.RateCall", "Rounded Seconds greater then short.MaxValue"); } pCdr.CustomerDuration = _roundedSeconds; pCdr.CustomerRoundedMinutes = (short)(_roundedSeconds / 60); } catch (Exception _ex) { _result = 1; TimokLogger.Instance.LogRbr(LogSeverity.Error, "CustomerAcct.RateCall", string.Format("Finding Wholesale price, Exception:\r\n{0}", _ex)); } } else if (IsRetail) { //-- Add retail part, to supress errors, retail rated separately } else { _result = 1; TimokLogger.Instance.LogRbr(LogSeverity.Critical, "CustomerAcct.RateCall", string.Format("Unknown CustomerType, {0}", serviceType)); } } return(_result); }
public int Rate(CustomerRoute pCustomerRoute, ref Cdr pCdr) { short _roundedSeconds = 0; try { pCdr.RetailDuration = 0; if (pCdr.Duration > 0) { pCdr.RetailDuration = (short)((pCdr.Duration / 6) * 6); pCdr.RetailDuration += (short)(pCdr.Duration % 6 > 0 ? 6 : 0); } if (pCustomerRoute != null && pCustomerRoute.WithBonusMinutes && WithBonusMinutes && CurrentBonusBalance > 0) { pCdr.RetailRoundedMinutes = (short)(pCdr.Duration / 60 + (pCdr.Duration % 60 > 0 ? 1 : 0)); if (CurrentBonusBalance < pCdr.RetailRoundedMinutes) { TimokLogger.Instance.LogRbr(LogSeverity.Debug, "RetailAccount.Rate", string.Format("All bonus minutes used: {0} | {1}", CurrentBonusBalance, pCdr.RetailRoundedMinutes)); var _overflowDuration = (pCdr.RetailRoundedMinutes - CurrentBonusBalance) * 60; //in seconds pCdr.RetailPrice = pCustomerRoute.GetWholesaleCost(pCdr.StartTime, _overflowDuration, out _roundedSeconds); } else { //TODO: should substract bonus minutes used from duration and then chargae balance for the remianing time used!!! //NOTE: this is NOT correct _roundedSeconds = (short)(pCdr.RetailRoundedMinutes * 60); pCdr.UsedBonusMinutes = pCdr.RetailRoundedMinutes; } } else { var _service = RetailService.Get(pCdr.DNIS.ToString()); if (_service == null) { TimokLogger.Instance.LogRbr(LogSeverity.Error, "RetailAccount.Rate", string.Format("Service NOT found, AccessNumber: {0}", pCdr.DNIS)); return(1); } var _payphoneSurcharge = SurchargeInfo.Empty; if (pCdr.InfoDigits > 0) { if (_service.PayphoneSurchargeInfo != null) { _payphoneSurcharge = _service.PayphoneSurchargeInfo; } else { TimokLogger.Instance.LogRbr(LogSeverity.Error, "RetailAccount.Rate", "PayphoneSurcharge required, but NOT defined"); } } if (pCustomerRoute != null) { pCdr.RetailPrice = pCustomerRoute.GetRetailCost(pCdr.StartTime, pCdr.Duration, _service.AccessNumberSurchargeInfo, _payphoneSurcharge, out _roundedSeconds); } else { //- Apply surcharges only! if (_service.AccessNumberSurchargeInfo != null) { pCdr.RetailPrice += _service.AccessNumberSurchargeInfo.Cost; } if (_payphoneSurcharge != null) { pCdr.RetailPrice += _payphoneSurcharge.Cost; } } } if (pCdr.RetailPrice < decimal.Zero) { TimokLogger.Instance.LogRbr(LogSeverity.Critical, "RetailAccount.Rate", string.Format("Price < decimal.Zero: {0} | 0.0", pCdr.RetailPrice)); return(1); } if (_roundedSeconds > short.MaxValue) { TimokLogger.Instance.LogRbr(LogSeverity.Critical, "RetailAccount.Rate", "Rounded Seconds greater then short.MaxValue !"); return(1); } pCdr.RetailDuration = _roundedSeconds; pCdr.RetailRoundedMinutes = (short)(_roundedSeconds / 60); pCdr.UsedBonusMinutes = CurrentBonusBalance; } catch (Exception _ex) { TimokLogger.Instance.LogRbr(LogSeverity.Critical, "RetailAccount.Rate", string.Format("Exception:\r\n{0}", _ex)); return(1); } return(0); }