LPARAMETERS c_dokl
PRIVATE o_sel
o_sel = SELECT()
SELECT * WHERE c_dokl = m.c_dokl FROM doklady INTO CURSOR dd1
dat_zacatek_mesice = DATE(YEAR(dd1.datum_dokl), MONTH(dd1.datum_dokl), 1)
hlidany_partner = dd1.c_partner
SELECT -SUM(mnozstvi*cena) as prachy FROM obraty INTO CURSOR oo1 ;
       WHERE c_dokl in (SELECT c_dokl FROM doklady WHERE c_partner = m.hlidany_partner AND operace = "VV" ;
                                                     AND c_dokl <= m.c_dokl AND datum_dokl >= m.dat_zacatek_mesice)
IF RECCOUNT() = 1
   STRTOFILE( STR(m.c_dokl, 12) + "Od zacatku mesice vydano za " + ALLTRIM(TRANS(oo1.prachy, "999 999 999Kc")) + CHR(13)+CHR(10), ".\budget.txt", 1)
   SELECT (m.o_sel)
   RETURN "Od zacatku mesice vydano za " + ALLTRIM(TRANS(oo1.prachy, "999 999 999Kc"))
ELSE
   STRTOFILE( STR(m.c_dokl, 12) + CHR(13)+CHR(10), ".\budget.txt", 1)
   SELECT (m.o_sel)
   RETURN ""
ENDIF 
