63 lines
2.0 KiB
ABAP
63 lines
2.0 KiB
ABAP
CLASS {{p}}tool_hire DEFINITION PUBLIC FINAL CREATE PUBLIC.
|
|
PUBLIC SECTION.
|
|
INTERFACES {{p}}if_tool_hire.
|
|
|
|
PRIVATE SECTION.
|
|
TYPES:
|
|
BEGIN OF ty_rate,
|
|
tool TYPE {{p}}if_tool_hire=>ty_tool,
|
|
daily TYPE {{p}}if_tool_hire=>ty_amount,
|
|
weekly TYPE {{p}}if_tool_hire=>ty_amount,
|
|
monthly TYPE {{p}}if_tool_hire=>ty_amount,
|
|
END OF ty_rate,
|
|
tt_rate TYPE HASHED TABLE OF ty_rate WITH UNIQUE KEY tool.
|
|
|
|
CONSTANTS:
|
|
c_week_days TYPE i VALUE 7,
|
|
c_month_days TYPE i VALUE 28,
|
|
c_max_days TYPE i VALUE 90.
|
|
|
|
METHODS rates
|
|
RETURNING VALUE(rt_rate) TYPE tt_rate.
|
|
METHODS fee_for
|
|
IMPORTING is_rate TYPE ty_rate
|
|
iv_days TYPE {{p}}if_tool_hire=>ty_days
|
|
RETURNING VALUE(rv_fee) TYPE {{p}}if_tool_hire=>ty_amount.
|
|
ENDCLASS.
|
|
|
|
|
|
CLASS {{p}}tool_hire IMPLEMENTATION.
|
|
METHOD {{p}}if_tool_hire~calculate.
|
|
DATA(lt_rate) = rates( ).
|
|
ASSIGN lt_rate[ tool = iv_tool ] TO FIELD-SYMBOL(<ls_rate>).
|
|
IF sy-subrc <> 0.
|
|
rs_result = VALUE #( fee = 0
|
|
reason = {{p}}if_tool_hire=>c_reason-unknown_tool ).
|
|
RETURN.
|
|
ENDIF.
|
|
IF iv_days < 1 OR iv_days > c_max_days.
|
|
rs_result = VALUE #( fee = 0
|
|
reason = {{p}}if_tool_hire=>c_reason-too_short ).
|
|
RETURN.
|
|
ENDIF.
|
|
rs_result = VALUE #( fee = fee_for( is_rate = <ls_rate> iv_days = iv_days )
|
|
reason = {{p}}if_tool_hire=>c_reason-ok ).
|
|
ENDMETHOD.
|
|
|
|
METHOD rates.
|
|
rt_rate = VALUE #( ( tool = 'D' daily = 12 weekly = 60 monthly = 180 )
|
|
( tool = 'S' daily = 9 weekly = 45 monthly = 135 )
|
|
( tool = 'C' daily = 15 weekly = 75 monthly = 225 ) ).
|
|
ENDMETHOD.
|
|
|
|
METHOD fee_for.
|
|
IF iv_days >= c_month_days.
|
|
rv_fee = is_rate-monthly.
|
|
ELSEIF iv_days >= c_week_days.
|
|
rv_fee = is_rate-weekly.
|
|
ELSE.
|
|
rv_fee = is_rate-daily * iv_days.
|
|
ENDIF.
|
|
ENDMETHOD.
|
|
ENDCLASS.
|