87 lines
2.4 KiB
ABAP
87 lines
2.4 KiB
ABAP
CLASS {{p}}snow_fee DEFINITION PUBLIC FINAL CREATE PUBLIC.
|
|
PUBLIC SECTION.
|
|
TYPES ty_area TYPE i.
|
|
TYPES ty_priority TYPE c LENGTH 1.
|
|
TYPES ty_distance TYPE i.
|
|
TYPES ty_fee TYPE p LENGTH 9 DECIMALS 2.
|
|
|
|
METHODS calculate
|
|
IMPORTING iv_area TYPE ty_area
|
|
iv_priority TYPE ty_priority
|
|
iv_distance TYPE ty_distance
|
|
RETURNING VALUE(rv_fee) TYPE ty_fee.
|
|
|
|
PRIVATE SECTION.
|
|
CONSTANTS:
|
|
c_rate_small TYPE ty_fee VALUE '0.20',
|
|
c_rate_medium TYPE ty_fee VALUE '0.16',
|
|
c_rate_large TYPE ty_fee VALUE '0.12',
|
|
c_rate_per_km TYPE ty_fee VALUE '0.40',
|
|
c_minimum_fee TYPE ty_fee VALUE '45.00',
|
|
c_free_km TYPE ty_distance VALUE 10,
|
|
c_priority_expr TYPE ty_priority VALUE 'E',
|
|
c_priority_emerg TYPE ty_priority VALUE 'X'.
|
|
|
|
METHODS base_fee
|
|
IMPORTING iv_area TYPE ty_area
|
|
iv_priority TYPE ty_priority
|
|
RETURNING VALUE(rv_fee) TYPE ty_fee.
|
|
METHODS rate_per_sqm
|
|
IMPORTING iv_area TYPE ty_area
|
|
RETURNING VALUE(rv_rate) TYPE ty_fee.
|
|
METHODS surcharge_factor
|
|
IMPORTING iv_priority TYPE ty_priority
|
|
RETURNING VALUE(rv_factor) TYPE i.
|
|
METHODS travel_cost
|
|
IMPORTING iv_distance TYPE ty_distance
|
|
RETURNING VALUE(rv_cost) TYPE ty_fee.
|
|
ENDCLASS.
|
|
|
|
|
|
CLASS {{p}}snow_fee IMPLEMENTATION.
|
|
METHOD calculate.
|
|
IF iv_area <= 0.
|
|
rv_fee = 0.
|
|
RETURN.
|
|
ENDIF.
|
|
rv_fee = base_fee( iv_area = iv_area iv_priority = iv_priority )
|
|
+ travel_cost( iv_distance = iv_distance ).
|
|
ENDMETHOD.
|
|
|
|
METHOD base_fee.
|
|
DATA(lv_amount) = iv_area * rate_per_sqm( iv_area ).
|
|
IF lv_amount < c_minimum_fee.
|
|
lv_amount = c_minimum_fee.
|
|
ENDIF.
|
|
rv_fee = lv_amount * surcharge_factor( iv_priority ) / 100.
|
|
ENDMETHOD.
|
|
|
|
METHOD rate_per_sqm.
|
|
IF iv_area <= 500.
|
|
rv_rate = c_rate_small.
|
|
ELSEIF iv_area <= 2000.
|
|
rv_rate = c_rate_medium.
|
|
ELSE.
|
|
rv_rate = c_rate_large.
|
|
ENDIF.
|
|
ENDMETHOD.
|
|
|
|
METHOD surcharge_factor.
|
|
CASE iv_priority.
|
|
WHEN c_priority_expr.
|
|
rv_factor = 125.
|
|
WHEN c_priority_emerg.
|
|
rv_factor = 150.
|
|
WHEN OTHERS.
|
|
rv_factor = 100.
|
|
ENDCASE.
|
|
ENDMETHOD.
|
|
|
|
METHOD travel_cost.
|
|
DATA(lv_chargeable_km) = iv_distance - c_free_km.
|
|
IF lv_chargeable_km > 0.
|
|
rv_cost = lv_chargeable_km * c_rate_per_km.
|
|
ENDIF.
|
|
ENDMETHOD.
|
|
ENDCLASS.
|