SELECT d.*, fd.id_zkratka ;
       WHERE operace = "ZV" AND EMPTY(pz2) AND d.c_stredisk = m.gic_stredisk ;
       FROM (m.fn_doklady) d left join (m.fn_food_dat) fd on fd.c_stredisk == d.c_partner ;
       INTO TABLE (m.gcpri_path + "zad_dokl")

SELECT disti datum_dokl WHERE datum_dokl > DATE() - 5 ORDER BY 1 FROM (m.gcpri_path + "zad_dokl") INTO TABLE (m.gcpri_path + "zad_datumy")
DO CASE 
CASE RECC() = 0
    WAIT jaz("form_ziadne_ziadanky") wind time 3 AT 22,22
CASE RECC() = 1
    datum = zad_datumy.datum_dokl
    DO jeden_den
OTHERWISE 
    DEFINE popup zad_datumy from 1, 5 prompt field datum_dokl font "Courier New" title "Vyber datum" 
    ON Selection popu zad_datumy deacti popu
    ACTIVATE SCREEN 
    ACTIVATE POPUP zad_datumy
    IF .not. empt(prompt())
         datum = zad_datumy.datum_dokl
         DO jeden_den
    ENDIF 
    RELEASE POPUP zad_datumy
ENDCASE 
DO clos_data

*    *    *    *    *    *    *    *    *    *    *    *    *    *    *    
PROCEDURE jeden_den
had = CREATEOBJECT("had")
had.SHOW()
SELECT zad_dokl
DELETE FOR datum_dokl # m.datum

SELECT o.c_dokl, o.c_karty, o.mnozstvi, o.serial_no, d.datum_dokl, d.pz1, d.provedl, d.kdy, d.c_partner, d.id_zkratka ;
       FROM (m.fn_obraty) o left join (m.gcpri_path + "zad_dokl") d on d.c_dokl == o.c_dokl where o.c_dokl IN (SELECT c_dokl FROM (m.gcpri_path + "zad_dokl")) ;
       INTO TABLE (m.gcpri_path + "z1")

SELECT  z1.*, k.nazev, k.druh, k.druh_skl FROM (m.gcpri_path + "z1") LEFT JOIN (m.fn_karty) k ON k.c_karty == z1.c_karty ;
        INTO TABLE (m.gcpri_path + "z2")
REPLACE FOR .not. EMPTY(druh_skl) druh WITH druh_skl
INDEX ON id_zkratka + druh + nazev TAG id_dr_naz
RELEASE had
DO pr_report WITH "zadansum"
