Esempio n. 1
0
        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);
        }
Esempio n. 2
0
        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);
        }