Beispiel #1
0
        public static UserUsageAuditResult GetUserUsageAuditResult(UserUsageAuditItem item)
        {
            // This is how UsageFeeCharged is calculated:
            //      if IsCancelledBeforeAllowedTime:
            //          result = 0
            //      not IsCancelledBeforeAllowedTime:
            //          result = (PerUseRate + RatePeriodCharge) * ChargeMultiplier
            //
            // PerUseRate is Cost.AddVal
            // RatePeriodCharge is based on baseDuration (see below), Cost.AcctPer, and Cost.MulVal

            // unrounded decimal value
            decimal hourlyDuration;

            var perUseCharge = Round(item.PerUseRate * item.Uses * item.ChargeMultiplier);

            hourlyDuration = item.SchedDuration / 60M;
            var schedDurationHours         = Round(hourlyDuration);
            var schedDurationHoursForgiven = Round(hourlyDuration * item.ChargeMultiplier);

            hourlyDuration = item.ChargeDuration / 60M;
            var chargeDurationHours         = Round(hourlyDuration);
            var chargeDurationHoursForgiven = Round(hourlyDuration * item.ChargeMultiplier);

            // same calculation used in LNF.Impl.Billing.ToolBillingUtility.CalculateUsageFeeCharged
            var baseDuration = item.ChargeDuration - item.OverTime - item.TransferredDuration;

            hourlyDuration = baseDuration / 60M;
            var baseDurationHours         = Round(hourlyDuration);
            var baseDurationHoursForgiven = Round(hourlyDuration * item.ChargeMultiplier);

            hourlyDuration = item.OverTime / 60M;
            var overTimeHours         = Round(hourlyDuration);
            var overTimeHoursForgiven = Round(hourlyDuration * item.ChargeMultiplier);

            var overTimePenalty = item.OverTime * item.OverTimePenaltyPercentage;

            hourlyDuration = overTimePenalty / 60M;
            var overTimePenaltyHours         = Round(hourlyDuration);
            var overTimePenaltyHoursForgiven = Round(hourlyDuration * item.ChargeMultiplier);

            // this is the same method used to populate LineCost elsewhere
            var forgivenPercentage = 1 - item.ChargeMultiplier;
            var hourlyRate         = GetHourlyRate(item.RatePeriod, item.ResourceRate);

            // To be able to calculate the line cost using only the values in each row (this is the goal here) we must set BaseDuration
            // to zero when IsCancelledBeforeAllowedTime is true. This is because for these reservations there is only a booking fee.
            if (item.IsCancelledBeforeAllowedTime)
            {
                baseDuration              = 0;
                baseDurationHours         = 0;
                baseDurationHoursForgiven = 0;
            }

            // This is a new concept for this report: the sum of base duration plus overtime multiplied by the overtime penalty.
            // The purpose of this is to have one duration that can be multiplied by the hourly rate to get the line cost.
            var billingDuration = baseDuration + overTimePenalty; // zero when cancelled before cutoff

            hourlyDuration = billingDuration / 60M;
            var billingDurationHours         = Round(hourlyDuration);
            var billingDurationHoursForgiven = Round(hourlyDuration * item.ChargeMultiplier);

            // includes overtime penalty duration and charge duration
            var billingCharge = Round(hourlyRate * billingDurationHoursForgiven);

            // for a typical reservation:
            //      if IsCancelledBeforeAllowedTime:
            //          result = bookingFee
            //      not IsCancelledBeforeAllowedTime:
            //          result = usageFeeCharged + overTimePenaltyFee + bookingFee (bookingFee will be zero)
            //var lineCost = Provider.Billing.Tool.GetLineCost(new ToolLineCostParameters
            //{
            //    Period = period,
            //    ResourceID = resourceId,
            //    RoomID = roomId,
            //    BillingTypeID = billingTypeId,
            //    IsStarted = isStarted,
            //    ResourceRate = item.ResourceRate,
            //    PerUseRate = item.PerUseRate,
            //    UsageFeeCharged = item.UsageFeeCharged,
            //    OverTimePenaltyFee = item.OverTimePenaltyFee,
            //    UncancelledPenaltyFee = item.UncancelledPenaltyFee,
            //    BookingFee = item.BookingFee,
            //    ReservationFee2 = item.ReservationFee2,
            //    IsCancelledBeforeAllowedTime = isCancelledBeforeAllowedTime
            //});

            var result = new UserUsageAuditResult
            {
                ResourceID                   = item.ResourceID,
                ResourceDisplayName          = $"{item.ResourceName} [{item.ResourceID}]",
                BookingFee                   = item.BookingFee, //aready forgiven via ToolBilling import process
                PerUseCharge                 = perUseCharge,
                HourlyRate                   = hourlyRate,
                ForgivenPercentage           = forgivenPercentage,
                SchedDurationHours           = schedDurationHours,
                SchedDurationHoursForgiven   = schedDurationHoursForgiven,
                ChargeDurationHours          = chargeDurationHours,
                ChargeDurationHoursForgiven  = chargeDurationHoursForgiven,
                BaseDuration                 = baseDuration,
                BaseDurationHours            = baseDurationHours,
                BaseDurationHoursForgiven    = baseDurationHoursForgiven,
                OverTimeHours                = overTimeHours,
                OverTimeHoursForgiven        = overTimeHoursForgiven,
                OverTimePenalty              = overTimePenalty,
                OverTimePenaltyHours         = overTimePenaltyHours,
                OverTimePenaltyHoursForgiven = overTimePenaltyHoursForgiven,
                BillingDuration              = billingDuration,
                BillingDurationHours         = billingDurationHours,
                BillingDurationHoursForgiven = billingDurationHoursForgiven,
                BillingCharge                = billingCharge
            };

            return(result);
        }
Beispiel #2
0
        private void SetDataRow(DataRow dr)
        {
            // Some of these are stored in the database as float but the IToolBilling object defines
            // them as decimal. Putting all decimal values in a variable for convenience.
            var item = new UserUsageAuditItem
            {
                ResourceID    = dr.Field <int>("ResourceID"),
                ResourceName  = dr.Field <string>("ResourceName"),
                RoomID        = dr.Field <int>("RoomID"),
                BillingTypeID = dr.Field <int>("BillingTypeID"),
                IsStarted     = dr.Field <bool>("IsStarted"),
                IsCancelledBeforeAllowedTime = dr.Field <bool>("IsCancelledBeforeAllowedTime"),
                RatePeriod                   = dr.Field <string>("RatePeriod"),
                Uses                         = Convert.ToDecimal(dr.Field <double>("Uses")),
                PerUseRate                   = dr.Field <decimal>("PerUseRate"),            // stored as decimal in database
                ResourceRate                 = dr.Field <decimal>("ResourceRate"),          // stored as decimal in database
                ReservationRate              = dr.Field <decimal>("ReservationRate"),       // stored as decimal in database
                OverTimePenaltyPercentage    = Convert.ToDecimal(dr.Field <double>("OverTimePenaltyPercentage")),
                OverTimePenaltyFee           = dr.Field <decimal>("OverTimePenaltyFee"),    // stored as decimal in the database
                UncancelledPenaltyPercentage = Convert.ToDecimal(dr.Field <double>("UncancelledPenaltyPercentage")),
                UncancelledPenaltyFee        = dr.Field <decimal>("UncancelledPenaltyFee"), // stored as decimal in the database
                BookingFee                   = dr.Field <decimal>("BookingFee"),            // stored as decimal in the database
                ReservationFee2              = dr.Field <decimal>("ReservationFee2"),       // stored as decimal in the database
                SchedDuration                = Convert.ToDecimal(dr.Field <double>("SchedDuration")),
                ChargeDuration               = Convert.ToDecimal(dr.Field <double>("ChargeDuration")),
                OverTime                     = dr.Field <decimal>("OverTime"), // stored as decimal in database
                TransferredDuration          = Convert.ToDecimal(dr.Field <double>("TransferredDuration")),
                ChargeMultiplier             = Convert.ToDecimal(dr.Field <double>("ChargeMultiplier")),
                UsageFeeCharged              = dr.Field <decimal>("UsageFeeCharged"), // stored as decimal in database
            };

            var auditResult = GetUserUsageAuditResult(item);

            dr["ResourceDisplayName"]          = auditResult.ResourceDisplayName;
            dr["PerUseCharge"]                 = auditResult.PerUseCharge;
            dr["HourlyRate"]                   = auditResult.HourlyRate;
            dr["ForgivenPercentage"]           = auditResult.ForgivenPercentage;
            dr["SchedDurationHours"]           = auditResult.SchedDurationHours;
            dr["SchedDurationHoursForgiven"]   = auditResult.SchedDurationHoursForgiven;
            dr["ChargeDurationHours"]          = auditResult.ChargeDurationHours;
            dr["ChargeDurationHoursForgiven"]  = auditResult.ChargeDurationHoursForgiven;
            dr["BaseDuration"]                 = auditResult.BaseDuration;
            dr["BaseDurationHours"]            = auditResult.BaseDurationHours;
            dr["BaseDurationHoursForgiven"]    = auditResult.BaseDurationHoursForgiven;
            dr["OverTimeHours"]                = auditResult.OverTimeHours;
            dr["OverTimeHoursForgiven"]        = auditResult.OverTimeHoursForgiven;
            dr["OverTimePenalty"]              = auditResult.OverTimePenalty;
            dr["OverTimePenaltyHours"]         = auditResult.OverTimePenaltyHours;
            dr["OverTimePenaltyHoursForgiven"] = auditResult.OverTimePenaltyHoursForgiven;
            dr["BillingDuration"]              = auditResult.BillingDuration;
            dr["BillingDurationHours"]         = auditResult.BillingDurationHours;
            dr["BillingDurationHoursForgiven"] = auditResult.BillingDurationHoursForgiven;
            dr["BillingCharge"]                = auditResult.BillingCharge;
            dr["LineCost"] = auditResult.LineCost;

            // for a typical reservation:
            //      if IsCancelledBeforeAllowedTime:
            //          result = bookingFee
            //      not IsCancelledBeforeAllowedTime:
            //          result = usageFeeCharged + overTimePenaltyFee + bookingFee (bookingFee will be zero)
            //var lineCost = Provider.Billing.Tool.GetLineCost(new ToolLineCostParameters
            //{
            //    Period = period,
            //    ResourceID = resourceId,
            //    RoomID = roomId,
            //    BillingTypeID = billingTypeId,
            //    IsStarted = isStarted,
            //    ResourceRate = item.ResourceRate,
            //    PerUseRate = item.PerUseRate,
            //    UsageFeeCharged = item.UsageFeeCharged,
            //    OverTimePenaltyFee = item.OverTimePenaltyFee,
            //    UncancelledPenaltyFee = item.UncancelledPenaltyFee,
            //    BookingFee = item.BookingFee,
            //    ReservationFee2 = item.ReservationFee2,
            //    IsCancelledBeforeAllowedTime = isCancelledBeforeAllowedTime
            //});
        }