public static IToolBilling CreateToolBillingFromDataRow(DataRow dr, bool temp) { var item = new ToolBillingItem { ToolBillingID = 0, Period = dr.Field <DateTime>("Period"), ReservationID = dr.Field <int>("ReservationID"), ClientID = dr.Field <int>("ClientID"), AccountID = dr.Field <int>("AccountID"), ChargeTypeID = dr.Field <int>("ChargeTypeID"), BillingTypeID = dr.Field <int>("BillingTypeID"), RoomID = dr.Field <int>("RoomID"), ResourceID = dr.Field <int>("ResourceID"), ActDate = dr.Field <DateTime>("ActDate"), IsStarted = dr.Field <bool>("IsStarted"), IsActive = dr.Field <bool>("IsActive"), IsFiftyPenalty = dr.Field <bool>("IsFiftyPenalty"), ChargeMultiplier = Convert.ToDecimal(dr["ChargeMultiplier"]), Uses = Convert.ToDecimal(dr["Uses"]), SchedDuration = Convert.ToDecimal(dr["SchedDuration"]), ActDuration = Convert.ToDecimal(dr["ActDuration"]), ChargeDuration = Convert.ToDecimal(dr["ChargeDuration"]), TransferredDuration = Convert.ToDecimal(dr["TransferredDuration"]), ForgivenDuration = Convert.ToDecimal(dr["ForgivenDuration"]), MaxReservedDuration = Convert.ToDecimal(dr["MaxReservedDuration"]), OverTime = dr.Field <decimal>("OverTime"), RatePeriod = dr.Field <string>("RatePeriod"), PerUseRate = dr.Field <decimal>("PerUseRate"), ResourceRate = dr.Field <decimal>("ResourceRate"), ReservationRate = dr.Field <decimal>("ReservationRate"), OverTimePenaltyPercentage = Convert.ToDecimal(dr["OverTimePenaltyPercentage"]), UncancelledPenaltyPercentage = Convert.ToDecimal(dr["UncancelledPenaltyPercentage"]), UsageFeeCharged = dr.Field <decimal>("UsageFeeCharged"), UsageFee20110401 = dr.Field <decimal>("UsageFee20110401"), UsageFee = dr.Field <decimal>("UsageFee"), UsageFeeOld = dr.Field <decimal>("UsageFeeOld"), OverTimePenaltyFee = dr.Field <decimal>("OverTimePenaltyFee"), UncancelledPenaltyFee = dr.Field <decimal>("UncancelledPenaltyFee"), BookingFee = dr.Field <decimal>("BookingFee"), TransferredFee = dr.Field <decimal>("TransferredFee"), ForgivenFee = dr.Field <decimal>("ForgivenFee"), SubsidyDiscount = dr.Field <decimal>("SubsidyDiscount"), IsCancelledBeforeAllowedTime = dr.Field <bool>("IsCancelledBeforeAllowedTime"), ReservationFeeOld = dr.Field <decimal>("ReservationFeeOld"), ReservationFee2 = dr.Field <decimal>("ReservationFee2"), UsageFeeFiftyPercent = dr.Field <decimal>("UsageFeeFiftyPercent"), IsTemp = temp }; return(item); }
/// <summary> /// This method computes the total amount charged for tool usage. This is used in all billing reports sent to UofM FinOps /// </summary> public static decimal GetLineCost(ToolLineCostParameters p) { // [2015-11-13 jg] this is identical to the logic originally in: // 1) sselFinOps.AppCode.BLL.FormulaBL.ApplyToolFormula (for External Invoice) // 2) sselIndReports.AppCode.Bll.ToolBillingBL.GetToolBillingDataByClientID20110701 (for User Usage Summary) // 3) LNF.WebApi.Billing.Models.ReportUtility.ApplyToolFormula (for SUB reports, note: this is the replacement for the Billing WCF service) // // I think at this point all the formulas can be replaced by GetTotalCharge() // because each value used by the formula should correctly reflect the rules // in place during the given period (or at least that is the goal). decimal result; //if rates are 0 everything must be 0 (this was at the end, but why not do it at the beginning?) if (p.ResourceRate + p.PerUseRate == 0) { return(0); } int cleanRoomId = 6; int maskMakerId = 56000; if (BillingTypes.IsMonthlyUserBillingType(p.BillingTypeID)) //not used at this point but maybe in the future { // Monthly User, charge mask maker for everyone if (p.RoomID == cleanRoomId) //Clean Room { if (p.ResourceID == maskMakerId) //Mask Maker { if (p.IsStarted) { result = p.UsageFeeCharged + p.OverTimePenaltyFee + (p.ResourceRate == 0 ? 0 : p.ReservationFee2); } else { result = p.UncancelledPenaltyFee + p.ReservationFee2; } } else { result = 0; } } else { //non clean room tools are always charged for usage fee if (p.IsStarted) { result = p.UsageFeeCharged + p.OverTimePenaltyFee + (p.ResourceRate == 0 ? 0 : p.ReservationFee2); } else { result = p.UncancelledPenaltyFee + p.ReservationFee2; } } } else if (p.BillingTypeID == BillingTypes.Other) { //based on sselIndReports.AppCode.BLL.ToolBillingBL.GetToolBillingDataByClientID20110701 the Other billing type is not set to zero any longer result = ToolBillingItem.GetTotalCharge(p.UsageFeeCharged, p.OverTimePenaltyFee, p.BookingFee, p.UncancelledPenaltyFee, p.ReservationFee2); } else { //Per Use types if (p.Period >= new DateTime(2010, 7, 1)) { //2022-04 New tool billing started on 2022-03 if (p.Period >= new DateTime(2022, 3, 1)) { // [2022-04-08 jg] Use the new "audit friendly" method. This way of calculating makes it easy to break out the constituent parts and // do the math to verify the line cost. The User Usage Summary report has been updated to display these parts. result = GetLineCostAuditFriendlyVersion(p); } //2011-05 New tool billing started on 2011-04 else if (p.Period >= new DateTime(2011, 4, 1)) { if (!p.IsCancelledBeforeAllowedTime) { result = p.UsageFeeCharged + p.OverTimePenaltyFee + p.BookingFee; //should be the same as GetTotalCharge() } else { result = p.BookingFee; //Cancelled before two hours - should be the same as GetTotalCharge() } } else { if (p.IsStarted) { result = p.UsageFeeCharged + p.OverTimePenaltyFee + (p.ResourceRate == 0 ? 0 : p.ReservationFee2); //should be the same as GetTotalCharge() } else { result = p.UncancelledPenaltyFee; //should be the same as GetTotalCharge() } } } else { if (p.IsStarted) { result = p.UsageFeeCharged + p.OverTimePenaltyFee + (p.ResourceRate == 0 ? 0 : p.ReservationFee2); //should be the same as GetTotalCharge() } else { result = p.UncancelledPenaltyFee + p.ReservationFee2; //should be the same as GetTotalCharge() } } } return(result); }