
had = CREATEOBJECT("had")
had.SHOW()

SELECT disti clientname, client, client_id, date, den_tydne, 0000.0 as cena, ;
           0000 as  no_pre, 0000 as  no_main, 0000 as  no_side, 0000 as  no_dinner, ;
           0000 as can_pre, 0000 as can_main, 0000 as can_side, 0000 as can_dinner, ;
           0000 as ord_pre, 0000 as ord_main, 0000 as ord_side, 0000 as ord_dinner, 0000 as ord_lunch, ;
           0000 as eat_pre, 0000 as eat_main, 0000 as eat_side, 0000 as eat_dinner, 0000 as eat_lunch  ;
           FROM orders INTO CURSOR orders_sum READWRITE 

SELECT orders
SCAN
    SCATTER MEMVAR 
    SELECT orders_sum
    DO CASE 
    CASE m.course = "lunch_pre"
        REPLACE FOR date = m.date .and. client = m.client no_pre    with m.number, can_pre    with m.canteen, ord_pre    with m.ordered, eat_pre    with m.eaten, ord_lunch WITH MAX(ord_pre, ord_main, ord_side), eat_lunch WITH MAX(eat_pre, eat_main, eat_side)
    CASE m.course = "lunch_main"
        REPLACE FOR date = m.date .and. client = m.client no_main   with m.number, can_main   with m.canteen, ord_main   with m.ordered, eat_main   with m.eaten, ord_lunch WITH MAX(ord_pre, ord_main, ord_side), eat_lunch WITH MAX(eat_pre, eat_main, eat_side)
    CASE m.course = "lunch_side"
        REPLACE FOR date = m.date .and. client = m.client no_side   with m.number, can_side   with m.canteen, ord_side   with m.ordered, eat_side   with m.eaten, ord_lunch WITH MAX(ord_pre, ord_main, ord_side), eat_lunch WITH MAX(eat_pre, eat_main, eat_side)
    OTHERWISE
        REPLACE FOR date = m.date .and. client = m.client no_dinner with m.number, can_dinner with m.canteen, ord_dinner with m.ordered, eat_dinner with m.eaten
    ENDCASE 
ENDSCAN 

RELEASE had
SELECT orders_sum
INDEX on clientname + date TAG cli_da
DO pr_report WITH "stravovani_odber_parlament"

SELECT clientname, client, client_id, " " as date, " " as den_tydne, 0000.0 as cena, ;
       00 as  no_pre, 00 as  no_main, 00 as  no_side, 00 as  no_dinner, ;
       00 as can_pre, 00 as can_main, 00 as can_side, 00 as can_dinner, ;
       SUM(ord_pre) as ord_pre, SUM(ord_main) as ord_main, SUM(ord_side) as ord_side, SUM(ord_dinner) as ord_dinner, SUM(ord_lunch) as ord_lunch, ;
       SUM(eat_pre) as eat_pre, SUM(eat_main) as eat_main, SUM(eat_side) as eat_side, SUM(eat_dinner) as eat_dinner ;
       GROUP BY clientname FROM orders_sum INTO CURSOR orders_sumsum READWRITE 

DO pr_report WITH "stravovani_odber"
