119 lines
4.3 KiB
ABAP
119 lines
4.3 KiB
ABAP
REPORT {{p}}court_old.
|
|
|
|
TYPES: BEGIN OF ty_line,
|
|
court TYPE {{p}}court-court_id,
|
|
bookings TYPE i,
|
|
total_min TYPE i,
|
|
charge TYPE {{p}}court-hourly_rate,
|
|
END OF ty_line.
|
|
TYPES tt_line TYPE STANDARD TABLE OF ty_line WITH EMPTY KEY.
|
|
TYPES tt_court TYPE RANGE OF {{p}}court-court_id.
|
|
|
|
DATA gv_court TYPE {{p}}court-court_id.
|
|
|
|
PARAMETERS p_date TYPE d OBLIGATORY.
|
|
SELECT-OPTIONS s_court FOR gv_court.
|
|
|
|
CLASS lcl_report DEFINITION FINAL.
|
|
PUBLIC SECTION.
|
|
METHODS read_usage
|
|
IMPORTING iv_date TYPE d
|
|
it_court TYPE tt_court
|
|
RETURNING VALUE(rt_lines) TYPE tt_line.
|
|
METHODS show
|
|
CHANGING ct_lines TYPE tt_line.
|
|
ENDCLASS.
|
|
|
|
CLASS lcl_report IMPLEMENTATION.
|
|
METHOD read_usage.
|
|
SELECT c~court_id AS court,
|
|
COUNT( * ) AS bookings,
|
|
SUM( b~duration_min ) AS total_min,
|
|
SUM( b~duration_min * c~hourly_rate / 60 ) AS charge
|
|
FROM {{p}}booking AS b
|
|
INNER JOIN {{p}}court AS c ON c~court_id = b~court_id
|
|
WHERE b~booking_date = @iv_date
|
|
AND b~booking_state <> 'X'
|
|
AND b~court_id IN @it_court
|
|
GROUP BY c~court_id
|
|
ORDER BY c~court_id
|
|
INTO CORRESPONDING FIELDS OF TABLE @rt_lines.
|
|
|
|
DELETE rt_lines WHERE bookings < 2.
|
|
ENDMETHOD.
|
|
|
|
METHOD show.
|
|
TRY.
|
|
cl_salv_table=>factory( IMPORTING r_salv_table = DATA(lo_alv)
|
|
CHANGING t_table = ct_lines ).
|
|
lo_alv->display( ).
|
|
CATCH cx_salv_msg INTO DATA(lx_error).
|
|
MESSAGE lx_error TYPE 'I' DISPLAY LIKE 'E'.
|
|
ENDTRY.
|
|
ENDMETHOD.
|
|
ENDCLASS.
|
|
|
|
START-OF-SELECTION.
|
|
DATA(go_report) = NEW lcl_report( ).
|
|
DATA(gt_lines) = go_report->read_usage( iv_date = p_date it_court = s_court[] ).
|
|
go_report->show( CHANGING ct_lines = gt_lines ).
|
|
|
|
CLASS ltc_report DEFINITION FINAL FOR TESTING DURATION SHORT RISK LEVEL HARMLESS.
|
|
PRIVATE SECTION.
|
|
CLASS-DATA go_env TYPE REF TO if_osql_test_environment.
|
|
CLASS-METHODS class_setup.
|
|
CLASS-METHODS class_teardown.
|
|
METHODS totals_per_court FOR TESTING.
|
|
METHODS quiet_courts_dropped FOR TESTING.
|
|
ENDCLASS.
|
|
|
|
CLASS ltc_report IMPLEMENTATION.
|
|
METHOD class_setup.
|
|
go_env = cl_osql_test_environment=>create(
|
|
i_dependency_list = VALUE #( ( '{{P}}COURT' ) ( '{{P}}BOOKING' ) ) ).
|
|
|
|
DATA lt_court TYPE STANDARD TABLE OF {{p}}court WITH EMPTY KEY.
|
|
lt_court = VALUE #(
|
|
( court_id = 'A01' court_name = 'A Court' court_kind = 'I' hourly_rate = '12.00' )
|
|
( court_id = 'B01' court_name = 'B Court' court_kind = 'O' hourly_rate = '20.00' ) ).
|
|
go_env->insert_test_data( lt_court ).
|
|
|
|
DATA lt_booking TYPE STANDARD TABLE OF {{p}}booking WITH EMPTY KEY.
|
|
lt_booking = VALUE #(
|
|
( booking_id = 1 court_id = 'A01' booking_date = '20260401' duration_min = 60 booking_state = 'B' )
|
|
( booking_id = 2 court_id = 'A01' booking_date = '20260401' duration_min = 30 booking_state = 'B' )
|
|
( booking_id = 3 court_id = 'B01' booking_date = '20260401' duration_min = 60 booking_state = 'B' )
|
|
( booking_id = 4 court_id = 'B01' booking_date = '20260401' duration_min = 60 booking_state = 'X' ) ).
|
|
go_env->insert_test_data( lt_booking ).
|
|
ENDMETHOD.
|
|
|
|
METHOD class_teardown.
|
|
go_env->destroy( ).
|
|
ENDMETHOD.
|
|
|
|
METHOD totals_per_court.
|
|
DATA lv_court TYPE {{p}}court-court_id.
|
|
DATA lv_expected TYPE {{p}}court-hourly_rate.
|
|
lv_court = 'A01'.
|
|
lv_expected = '18.00'.
|
|
|
|
DATA(lt_lines) = NEW lcl_report( )->read_usage( iv_date = '20260401' it_court = VALUE #( ) ).
|
|
|
|
cl_abap_unit_assert=>assert_equals( exp = 1 act = lines( lt_lines ) ).
|
|
cl_abap_unit_assert=>assert_equals( exp = lv_court act = lt_lines[ 1 ]-court ).
|
|
cl_abap_unit_assert=>assert_equals( exp = 2 act = lt_lines[ 1 ]-bookings ).
|
|
cl_abap_unit_assert=>assert_equals( exp = 90 act = lt_lines[ 1 ]-total_min ).
|
|
cl_abap_unit_assert=>assert_equals( exp = lv_expected act = lt_lines[ 1 ]-charge ).
|
|
ENDMETHOD.
|
|
|
|
METHOD quiet_courts_dropped.
|
|
DATA lv_court TYPE {{p}}court-court_id.
|
|
lv_court = 'A01'.
|
|
|
|
DATA(lt_lines) = NEW lcl_report( )->read_usage( iv_date = '20260401' it_court = VALUE #( ) ).
|
|
|
|
cl_abap_unit_assert=>assert_equals( exp = 1 act = lines( lt_lines ) ).
|
|
cl_abap_unit_assert=>assert_equals( exp = lv_court act = lt_lines[ 1 ]-court ).
|
|
ENDMETHOD.
|
|
ENDCLASS.
|