
SELECT DISTI firma                      FROM clients INTO CURSOR firmy READWRITE 

DEFINE POPUP firmy FROM 1,55 PROMPT FIELD firma TITLE "Vyber firmu, [Esc]=vsechny"
ON SELECTION POPUP firmy deacti POPUP 
ACTIVATE SCREEN 

ACTIVATE POPUP firmy
vybranafirma = PROMPT()

IF EMPTY(m.vybranafirma)
   sele * from clients into cursor clients2balances
ELSE
   sele * from clients into cursor clients2balances where firma = m.vybranafirma
ENDIF

DO get_balances     IN stravovani_ppgm

SELECT DISTI ALLTRIM(surname) + " " + ALLTRIM((firstname)) + " (" + ALLTRIM(client_id) + ")" as druh, .F. AS lbl, id ;
       FROM balances INTO CURSOR cloveci READWRITE 

DO FORM seldruhy WITH "cloveci", "Vyber strávníky " + m.vybranafirma

SELECT * WHERE id IN (SELECT id FROM cloveci WHERE lbl) FROM balances INTO CURSOR balances2 READWRITE 
INDEX on firma + surname + firstname + client_id TAG cli_tra
DO pr_report WITH "stravovani_balances"



retu

*!*    proc qwoieuqwoieuqoiuxc - puvodni stravovani_zustatky_kont

*!*    SELECT DISTI "{ " + typ + " }" as firma FROM balances INTO CURSOR typy_stravniku
*!*    SELECT DISTI firma                      FROM balances INTO CURSOR firmy READWRITE 
*!*    APPEND FROM DBF("typy_stravniku")

*!*    DEFINE POPUP firmy FROM 1,55 PROMPT FIELD firma TITLE "Vyber firmu, [Esc]=vsechny"
*!*    ON SELECTION POPUP firmy deacti POPUP 
*!*    ACTIVATE SCREEN 

*!*    ACTIVATE POPUP firmy
*!*    vybranafirma = PROMPT()

*!*    DO CASE 
*!*    CASE EMPTY(vybranafirma)
*!*        SELECT DISTI ALLTRIM(surname) + " " + ALLTRIM((firstname)) + " (" + ALLTRIM(client_id) + ")" as druh, .F. AS lbl, id FROM balances INTO CURSOR cloveci READWRITE 

*!*    CASE AT("{", vybranafirma) > 0 .and. AT("}", vybranafirma) > 4
*!*        vybranafirma = SUBSTR(vybranafirma, 3, 1)
*!*        SELECT DISTI ALLTRIM(surname) + " " + ALLTRIM((firstname)) + " (" + ALLTRIM(client_id) + ")" as druh, .F. AS lbl, id FROM balances INTO CURSOR cloveci READWRITE WHERE typ   = m.vybranafirma 

*!*    OTHERWISE 
*!*        SELECT DISTI ALLTRIM(surname) + " " + ALLTRIM((firstname)) + " (" + ALLTRIM(client_id) + ")" as druh, .F. AS lbl, id FROM balances INTO CURSOR cloveci READWRITE WHERE firma = m.vybranafirma 

*!*    ENDCASE 

*!*    DO FORM seldruhy WITH "cloveci", "Vyber strávníky " + m.vybranafirma

*!*    SELECT * WHERE id IN (SELECT id FROM cloveci WHERE lbl) FROM balances INTO CURSOR balances2 READWRITE 
*!*    INDEX on firma + surname + firstname + client_id TAG cli_tra
*!*    DO pr_report WITH "stravovani_balances"

