CLASS {{p}}storage_pricer DEFINITION PUBLIC FINAL CREATE PUBLIC. PUBLIC SECTION. TYPES ty_amount TYPE p LENGTH 8 DECIMALS 2. TYPES ty_sqm TYPE i. TYPES ty_months TYPE i. TYPES: BEGIN OF ty_booking, size_sqm TYPE ty_sqm, months TYPE ty_months, climate TYPE abap_bool, insurance TYPE abap_bool, END OF ty_booking. METHODS calculate_price IMPORTING is_booking TYPE ty_booking RETURNING VALUE(rv_price) TYPE ty_amount. PRIVATE SECTION. CONSTANTS: c_rate_small TYPE ty_amount VALUE '14.00', c_rate_medium TYPE ty_amount VALUE '11.50', c_rate_large TYPE ty_amount VALUE '9.00', c_climate_addon TYPE ty_amount VALUE '4.50', c_insurance_rate TYPE ty_amount VALUE '0.90', c_admin_fee TYPE ty_amount VALUE '19.00', c_percent TYPE i VALUE 100, c_size_small_max TYPE ty_sqm VALUE 5, c_size_medium_max TYPE ty_sqm VALUE 15, c_months_short TYPE ty_months VALUE 6, c_months_medium TYPE ty_months VALUE 12, c_months_long TYPE ty_months VALUE 24, c_disc_short TYPE i VALUE 5, c_disc_medium TYPE i VALUE 10, c_disc_long TYPE i VALUE 15. METHODS is_valid IMPORTING is_booking TYPE ty_booking RETURNING VALUE(rv_valid) TYPE abap_bool. METHODS monthly_rate IMPORTING is_booking TYPE ty_booking RETURNING VALUE(rv_rate) TYPE ty_amount. METHODS discount_percent IMPORTING is_booking TYPE ty_booking RETURNING VALUE(rv_percent) TYPE i. METHODS insurance_fee IMPORTING is_booking TYPE ty_booking RETURNING VALUE(rv_fee) TYPE ty_amount. ENDCLASS. CLASS {{p}}storage_pricer IMPLEMENTATION. METHOD calculate_price. IF is_valid( is_booking ) = abap_false. RETURN. ENDIF. DATA lv_rent TYPE ty_amount. DATA lv_discount TYPE ty_amount. DATA lv_total TYPE ty_amount. lv_rent = is_booking-size_sqm * is_booking-months * monthly_rate( is_booking ). lv_discount = lv_rent * discount_percent( is_booking ) / c_percent. lv_total = lv_rent - lv_discount + insurance_fee( is_booking ) + c_admin_fee. rv_price = lv_total. ENDMETHOD. METHOD is_valid. rv_valid = xsdbool( is_booking-size_sqm > 0 AND is_booking-months > 0 ). ENDMETHOD. METHOD monthly_rate. IF is_booking-size_sqm <= c_size_small_max. rv_rate = c_rate_small. ELSEIF is_booking-size_sqm <= c_size_medium_max. rv_rate = c_rate_medium. ELSE. rv_rate = c_rate_large. ENDIF. IF is_booking-climate = abap_true. rv_rate = rv_rate + c_climate_addon. ENDIF. ENDMETHOD. METHOD discount_percent. IF is_booking-months >= c_months_long. rv_percent = c_disc_long. ELSEIF is_booking-months >= c_months_medium. rv_percent = c_disc_medium. ELSEIF is_booking-months >= c_months_short. rv_percent = c_disc_short. ENDIF. ENDMETHOD. METHOD insurance_fee. IF is_booking-insurance = abap_true. rv_fee = is_booking-size_sqm * is_booking-months * c_insurance_rate. ENDIF. ENDMETHOD. ENDCLASS.