* 2020-04-30 - osetrena i hladina mimo rozsah "1" - "9"
* 2020-06-10 - food_dat beew i ze sql

DO clos_data
adresar = m.gchom_path

chyba_pri_otevirani = .f.
TRY
    IF m.issql
        DO open_database
        otevira_se = "fooddat"
        rv("fooddat","food_dat")
    ELSE
        otevira_se = m.fn_food_dat
        USE (adresar + "food_dat"   ) IN 0 NOUPDATE 
    ENDIF

    otevira_se = m.fn_sk_pol
    USE (adresar + "data\sk_pol") IN 0 NOUPDATE 
    USE (m.fn_sk_sez)   ALIAS sk_sez IN 0
CATCH
    chyba_pri_otevirani = .T.
ENDTRY
IF chyba_pri_otevirani
    DO zurnal_log WITH "OPERA", "zobraz_pouzite_hladiny", "nejde_otevrit" + m.otevira_se
    RETURN
ENDIF

SELECT disti id_kas, cen_hlad, dan WHERE uzaverka > "191111" FROM sk_pol INTO CURSOR hladiny READWRITE 
REPLACE FOR cen_hlad < "1" cen_hlad WITH "X"
REPLACE FOR cen_hlad > "9" cen_hlad WITH "X"

oblast = obl_num6(DATE())

SELECT disti id_kas, food_dat.id_zkratka as kasa, ;
       food_dat.&oblast.1 as cen_hlad_1, SPACE(55) as dane_1, ;
       food_dat.&oblast.2 as cen_hlad_2, SPACE(55) as dane_2, ;
       food_dat.&oblast.3 as cen_hlad_3, SPACE(55) as dane_3, ;
       food_dat.&oblast.4 as cen_hlad_4, SPACE(55) as dane_4, ;
       food_dat.&oblast.5 as cen_hlad_5, SPACE(55) as dane_5, ;
       food_dat.&oblast.6 as cen_hlad_6, SPACE(55) as dane_6, ;
       food_dat.&oblast.7 as cen_hlad_7, SPACE(55) as dane_7, ;
       food_dat.&oblast.8 as cen_hlad_8, SPACE(55) as dane_8, ;
       food_dat.&oblast.9 as cen_hlad_9, SPACE(55) as dane_9, ;
                                         SPACE(55) as dane_x  ;
       FROM hladiny LEFT JOIN food_dat ON food_dat.id == hladiny.id_kas INTO CURSOR kas_hlad READWRITE 

SELECT hladiny 
SCAN
    SCATTER MEMVAR 
    SELECT kas_hlad
    LOCATE FOR id_kas = m.id_kas 
    REPLACE dane_&cen_hlad WITH ALLTRIM(ALLTRIM(dane_&cen_hlad) + "  " + STR(dan*100-100, 2) + "%")
ENDSCAN 

SELECT kas_hlad
REPLACE FOR EMPTY(dane_1) dane_1 with "    -- nepouzito --"
REPLACE FOR EMPTY(dane_2) dane_2 with "    -- nepouzito --"
REPLACE FOR EMPTY(dane_3) dane_3 with "    -- nepouzito --"
REPLACE FOR EMPTY(dane_4) dane_4 with "    -- nepouzito --"
REPLACE FOR EMPTY(dane_5) dane_5 with "    -- nepouzito --"
REPLACE FOR EMPTY(dane_6) dane_6 with "    -- nepouzito --"
REPLACE FOR EMPTY(dane_7) dane_7 with "    -- nepouzito --"
REPLACE FOR EMPTY(dane_8) dane_8 with "    -- nepouzito --"
REPLACE FOR EMPTY(dane_9) dane_9 with "    -- nepouzito --"

DO pr_report WITH "pouzite_hladiny"

DO clos_data
