Skip to main content
Skip table of contents

Default Price Calculation

If you have not configured a custom price calculator class, GoMeddo will execute the default price calculation.

Executing the Default Calculation

You can apply the default price calculation in your own code by calling the following global static method:

CODE
B25.Util_PluginManager.applyDefaultPriceCalculation(B25.Util_PluginManager.ReservationPriceData data)

This can be useful when you do have your own custom price calculation, but want to fall back on the default calculation in some cases. For example, in your own calculate method, you can do the following:

JAVA
public void calculate(B25.Util_PluginManager.ReservationPriceData data) {
    if (data.reservation.B25__Account__c == null) {
        B25.Util_PluginManager.applyDefaultPriceCalculation(data);
        return;
    }
    Account linkedAccount = [
        SELECT Type
        FROM Account
        WHERE Id = :data.reservation.B25__Account__c
    ];
    if (linkedAccount.Type == 'Installation Partner') {
        data.reservation.B25__Subtotal__c = 0;
    } else {
        B25.Util_PluginManager.applyDefaultPriceCalculation(data);
    }
}

Default Calculation Logic

In case you’re curious what the default price calculation does exactly, we’ve got you covered. See below for the logic executed by GoMeddo.

JAVA
public void calculate(B25.Util_PluginManager.ReservationPriceData dataObj) {

   // take the base price (for the resource) from the reservation
   Decimal basePrice = dataObj.reservation.B25__Base_Price__c == null ? 0 : dataObj.reservation.B25__Base_Price__c;

   // set a fall back calculation method
   if (dataObj.reservation.B25__Calculation_Method__c == null || !B25.Util_System.getBooleanSetting(B25.Util_System.Setting.USE_CAPACITY)) {
      dataObj.reservation.B25__Calculation_Method__c = 'PER_TIME_UNIT';
   }

   // calculate the subtotal based on the calculation method
   if (dataObj.reservation.B25__Calculation_Method__c == 'PER_PERSON') {

      if (dataObj.reservation.B25__Quantity__c == null || dataObj.reservation.B25__Quantity__c < 1) {
         dataObj.reservation.B25__Quantity__c = 1;
      }
      dataObj.reservation.B25__Subtotal__c = basePrice * dataObj.reservation.B25__Quantity__c;

   } else {

      // check the duration of the reservation (as a rounded up number of pricing time units)
      Long nrOfMilis = 0;
      if (dataObj.reservation.B25__Start__c != null && dataObj.reservation.B25__End__c != null) {
         nrOfMilis = dataObj.reservation.B25__End__c.getTime() - dataObj.reservation.B25__Start__c.getTime();
      } else if (dataObj.reservation.B25__StartLocal__c != null && dataObj.reservation.B25__EndLocal__c != null) {
         nrOfMilis = dataObj.reservation.B25__EndLocal__c.getTime() - dataObj.reservation.B25__StartLocal__c.getTime();
      }
      Decimal nrOfMinutes = (nrOfMilis / 60000);
      Decimal nrOfTimeUnits = nrOfMinutes / B25.Util_System.getIntegerSetting(B25.Util_System.Setting.PRICING_TIME_UNIT);
      Integer roundedNrOfTimeUnits = Math.ceil(nrOfTimeUnits).intValue();

      if (dataObj.reservation.B25__Calculation_Method__c == 'PER_TIME_UNIT') {

         dataObj.reservation.B25__Subtotal__c = basePrice * roundedNrOfTimeUnits;

      } else if (dataObj.reservation.B25__Calculation_Method__c == 'PER_PERSON_PER_TIME_UNIT') {

         if (dataObj.reservation.B25__Quantity__c == null || dataObj.reservation.B25__Quantity__c < 1) dataObj.reservation.B25__Quantity__c = 1;
         dataObj.reservation.B25__Subtotal__c = basePrice * dataObj.reservation.B25__Quantity__c * roundedNrOfTimeUnits;

      }
   }
}

JavaScript errors detected

Please note, these errors can depend on your browser setup.

If this problem persists, please contact our support.