*    vygeneruje report objednavek tady a s sebou.
*    predpoklada se, ze chody, nekoncici cislem, jsou tady, ocislovane (lunch_main2-5 atd) jsou s sebou. vyjimkou je firma REPRE, ktera je vzdy tady
*    aby se vedelo, co dat do krabicek s sebou, jsou prilohy preilepeny k objednavce hlavniho jidla
*

SELECT meal, ordered, eaten, course, number, UPPER(name_long) + SPACE(99) as name, c_karty, date + " " + den_tydne as date, client, firma, ;
       SPACE(30) AS name_side, 00 as num_side, 00 as poradi, 0000 as ord_tady, 0000 as ord_ssebou ;
       FROM orders INTO TABLE (m.gcpri_path + "velim_tady_ssebou")

REPLACE ALL poradi WITH VAL(RIGHT( ALLTRIM(course), 1))

FOR iii = 1 TO RECCOUNT()
    GO (m.iii)
    IF ATC("side", course) > 0
        SCATTER MEMVAR 
        LOCATE FOR date = m.date .and. client = m.client .and. poradi = m.poradi .and. ATC("main", course) > 0
        IF FOUND()
            REPLACE name_side WITH m.name, num_side WITH number, name WITH LEFT(name, 32) + LOWER(m.name)
            GO (m.iii)
            DELETE
        ENDIF 
    ENDIF 
ENDFOR 

REPLACE FOR firma = "REPRE " course WITH STRTRAN(course, "2", ""), poradi WITH 0
REPLACE FOR firma = "REPRE " course WITH STRTRAN(course, "3", ""), poradi WITH 0
REPLACE FOR firma = "REPRE " course WITH STRTRAN(course, "4", ""), poradi WITH 0
REPLACE FOR firma = "REPRE " course WITH STRTRAN(course, "5", ""), poradi WITH 0

REPLACE FOR ATC("_pre"  , course) > 0 course WITH "1  Polevka"
REPLACE FOR ATC("_main" , course) > 0 course WITH "2  Hlavni jidlo"
REPLACE FOR ATC("dinner", course) > 0 course WITH "3  Po limitu"


REPLACE FOR poradi = 0 ord_tady   WITH ordered    && tady 
REPLACE FOR poradi # 0 ord_ssebou WITH ordered    && s sebou

SELECT date, course, name, c_karty, SUM(ord_tady) as ord_tady, SUM(ord_ssebou) as ord_ssebou ;
       GROUP BY 1,2,3,4 FROM velim_tady_ssebou INTO TABLE (m.gcpri_path + "velim_tady_ssebou_sum") 

DO pr_report WITH "stravovani_velim"

DO pozavirej WITH "velim_tady_ssebou_sum, velim_tady_ssebou"
