...
Code Block | ||
---|---|---|
| ||
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; } } } |
...