*:*************************************************************************************************************
*: Procedure: SK2HTML
*:
*: generuje webovou stranku s rychlym prehledem trzeb za poslednich par dni
*: paramatry: sk_path - cesta k SK_???
*:            pocet dni - za kolik dni zpet se report generuje
*:            jmeno_html - jmeno generovaneho souboru. chybi-li pripona .php, bude doplnena
*:            heslo - pod nim bude stranka pristupna
*:            co generovat - krome samotnych trzeb muze generovat report druhu plateb a report slev a cenovych hladin, pokud obsahuje stringy PLAT a SLEV a HLAD
*:                           protoze prazdny parametr znaci generovat vse, chceme-li generovat jen report trzeb, lze pouzit treba parametr "NIC"
*:                           pokud je v parametru string "BEZDPH", je sumarni report generovan bez DPH
*:
*: 2013-04-09: pokud se nalezne soubor texty.txt, pouziji se z nej nazvy plateb
*: 2013-02-09: pridelan report po cenovych hladinach
*: 2013-01-15: vynechava se platba "P_PREDPL" (vraceni predplacene zalohy)
*: 2014-01-03: PLHOT v parametru co_generovat generuje report plateb pouze za hotovost
*:             prvni generovana sekce (pred slevou/po sleve) je nastavovatelna hodnotou "TRZ" v parametru
*: 2014-01-06: i report po platbach ma totalovou cast
*:             totalove reporty zapocitaji uzaverku mezi pulnoci a 06:59 do vcerejska
*: 2014-01-07: liche radky totalovych casti se zobrazuji inverzne (v .css jsou k tomu tridy s priponou "i")
*: 2016-04-22: hodnota "PLH_K" v parametru generuje report plateb poscitany za hotovost+K_KARTA
*: 2018-03-19: totalova kasa zacina mezerama, takze totalove kousky jsou PRED svoji sekci
*:             sekce PLH_K je presunuta pred sekci po platbach, takze jeji totaly ma petka uplne na zacatku
*: 2020-04-14: pocet prodanych porci pizzy v grossetu
*: 2020-04-24: nazvy plateb z texty.txt
*: 2020-05-18: v sekci hot+karty jsou i zahrnuty i dalsi platby
*: 2020-07-17: z fieldu uzaverka vyhozen rok
*: 2022-09-03: platby se vypisuji az od 1000Kc vyse
*:             php header charset
*:
*: v parametru co_generovat se vyhodnocuje:
*:     TRZ    - sestava celkovych trzeb
*:     PLAT   - sestava po platbach
*:     SLEV   - sestava slev
*:     HLAD   - sestava po hladinach
*:     PLHOT  - sestava jen za hotovost
*:     PLH_K  - trzby za platbu "Hotove" plus "K_KARTA"
*:     PIZZA  - pocty prodanych kusu v gastroskupine Pizza (grosseto)
*:     BEZDPH - sumarni report je v cenach bez dph
*:     1000   - castky se vypisuji v tisicich na 1 des.misto
*:
*:*************************************************************************************************************

param sk_path, pocet_dni, jmeno_html, co_generovat, heslo

verze = "2022-09-04"
totalova_kasa = "   TOTALY"
#DEFINE NEJMENSI_TRZBA 777

vysledek = " ver." + m.verze
verze = PROGRAM() +  ' v.' + m.verze

sk_path = sk_path + IIF(RIGHT(m.sk_path,1)="\", "", "\")
if empty(m.pocet_dni)
    pocet_dni = 5
endif

if empt(m.jmeno_html)
    jmeno_html = ".\report.php"
endif
IF EMPTY(JUSTPATH(m.jmeno_html))
    jmeno_html = ".\" + m.jmeno_html
ENDIF 
if justext(m.jmeno_html) # "php"
    jmeno_html = JUSTPATH(m.jmeno_html) + "\" + JUSTSTEM(m.jmeno_html) + ".php"
endif

IF empty(m.co_generovat)
    co_generovat = ""
ELSE
    co_generovat = UPPER(m.co_generovat)
ENDIF
bez_dph = ("BEZDPH" $ co_generovat)
co_generovat = ALLT(STRTR(m.co_generovat, "BEZDPH", ""))
IF empty(m.co_generovat)
    co_generovat = " TRZ PLAT SLEV HLAD PLHOT "
ENDIF

IF empty(m.heslo)
    heslo = allt(detxt("bpdphqlnepbgchdeefag"))
ELSE
    heslo = allt(detxt(m.heslo))
ENDIF 

uz1 = RIGHT(DTOS(DATE() - m.pocet_dni), 6) + " 06:00"

CLOSE DATABASES 

sk_otevreno = ""
TRY     
     use (m.sk_path + "..\FOOD_DAT ") in 0 NOUPDA ORDER id
     use (m.sk_path + "KARTY  ")      in 0 NOUPDA ORDER c_karty
     use (m.sk_path + "SK_FIN ")      in 0 NOUPDA ALIAS velke_fin
     use (m.sk_path + "SK_PLT ")      in 0 NOUPDA ALIAS velke_plt
     use (m.sk_path + "SK_POL ")      in 0 NOUPDA ALIAS velke_pol
     use (m.sk_path + "SK_SEZ ")      in 0 NOUPDA ALIAS velke_sez
     use (m.sk_path + "SK_TXT ")      in 0 NOUPDA ALIAS velke_txt
CATCH 
     sk_otevreno = " nelze otevrit velka SK"
FINALLY
ENDTRY 

IF .not. EMPTY(m.sk_otevreno)
    vysledek = m.vysledek + m.crlf + "[1B#R]  " + " NEPROVEDENO, nelze otevrit " + m.sk_otevreno + "  ... "
    CLOSE DATABASES 
    RETURN 
ENDIF 

SELECT * from velke_sez into table (m.pri_path + "sk_sez") where (uzaverka >= m.uz1) and (":" $ uzaverka)
SELECT * FROM velke_fin INTO TABLE (m.pri_path + "sk_fin") where (uzaverka >= m.uz1) and (":" $ uzaverka)
SELECT * FROM velke_plt INTO TABLE (m.pri_path + "sk_plt") where (uzaverka >= m.uz1) and (":" $ uzaverka)
SELECT * FROM velke_txt INTO TABLE (m.pri_path + "sk_txt") where (uzaverka >= m.uz1) and (":" $ uzaverka)
SELECT *, SPACE(10) as druh ;
         FROM velke_pol INTO TABLE (m.pri_path + "sk_pol") where (uzaverka >= m.uz1) and (":" $ uzaverka) and (not EMPT(k_odpoctu))

SET RELATION TO c_karty INTO karty
REPLACE ALL             druh WITH karty.druh_kalk
REPLACE FOR EMPTY(druh) druh WITH karty.druh
USE IN karty
USE IN ("velke_fin")
USE IN ("velke_plt")
USE IN ("velke_pol")
USE IN ("velke_sez")
USE IN ("velke_txt")

ALTER table (m.pri_path + "sk_fin") alter COLUMN uzaverka Character(14)
ALTER table (m.pri_path + "sk_plt") alter COLUMN uzaverka Character(14)
ALTER table (m.pri_path + "sk_pol") alter COLUMN uzaverka Character(14)
ALTER table (m.pri_path + "sk_sez") alter COLUMN uzaverka Character(14)
ALTER table (m.pri_path + "sk_txt") alter COLUMN uzaverka Character(14)

UPDATE (m.pri_path + "sk_fin") SET uzaverka = "20" + uzaverka
UPDATE (m.pri_path + "sk_plt") SET uzaverka = "20" + uzaverka
UPDATE (m.pri_path + "sk_pol") SET uzaverka = "20" + uzaverka
UPDATE (m.pri_path + "sk_sez") SET uzaverka = "20" + uzaverka
UPDATE (m.pri_path + "sk_txt") SET uzaverka = "20" + uzaverka

SELECT uzaverka, u_cis, SUM(cena_pl) AS cena_plt ;
       GROUP BY 1,2 FROM (m.pri_path + "sk_plt") INTO TABLE (m.pri_path + "plt")

SELECT uzaverka, u_cis, SUM(prachy) AS cena_pol, SUM(prachy/dan) AS dan_zakl, $0 AS cena_plt, 1 AS pocet ;
       GROUP BY 1,2 FROM (m.pri_path + "sk_pol") INTO TABLE (m.pri_path + "pol")

APPE FROM (m.pri_path + "plt")


*   *   *   *   *   *   *   *   TRZBY CELKEM   *   *   *   *   *   *   
SELECT uzaverka, LEFT(u_cis,2) + SPACE(28) as id_kas, ;
       SUM(cena_pol) AS cena_pol, SUM(dan_zakl) AS dan_zakl, SUM(cena_plt) AS cena_plt, SUM(pocet) as pocet, date() as datum_uz ;
       GROUP BY 1,2 FROM (m.pri_path + "pol") INTO TABLE (m.pri_path + "sk_chk")
DO dopln_nazev_kasy
IF m.bez_dph
    REPL FOR cena_pol # 0 cena_plt WITH cena_plt * dan_zakl/cena_pol
ENDIF
COPY all to \sk_chk
*       pridani totalu po dnech
REPL ALL datum_uz with DATE(VAL(LEFT(uzaverka,4)), VAL(SUBSTR(uzaverka, 5,2)), VAL(SUBSTR(uzaverka, 7,2))) - IIF(SUBSTR(uzaverka, 10,2) < "07",1,0)
SELECT left(DTOS(datum_uz),4) + "-" + subst(DTOS(datum_uz),5,4) as uzaverka, m.totalova_kasa as id_kas, ;
       SUM(cena_pol) AS cena_pol, SUM(dan_zakl) AS dan_zakl, SUM(cena_plt) AS cena_plt, SUM(pocet) as pocet ;
       GROUP BY 1,2 FROM (m.pri_path + "sk_chk") INTO TABLE (m.pri_path + "sk_total")
SELECT sk_chk
APPEND FROM (m.pri_path + "sk_total")


*   *   *   *   *   *   *   *   TRZBY PO PLATBACH   *   *   *   *   *   *   
SELECT LEFT(u_cis,2) + SPACE(28) as id_kas, uzaverka, PADR(druh_pl,22) as druh_pl, SUM(cena_pl) as cena_plt, COUNT(*) as pocet, date() as datum_uz ;
GROUP BY 1,2,3 FROM (m.pri_path + "sk_plt") INTO TABLE (m.pri_path + "platby")
DELE FOR druh_pl = "P_PREDPL"

*       pridani totalu po dnech
REPL ALL datum_uz with DATE(VAL(LEFT(uzaverka,4)), VAL(SUBSTR(uzaverka, 5,2)), VAL(SUBSTR(uzaverka, 7,2))) - IIF(SUBSTR(uzaverka, 10,2) < "07",1,0)
SELECT left(DTOS(datum_uz),4) + "-" + subst(DTOS(datum_uz),5,4) as uzaverka, m.totalova_kasa as id_kas, druh_pl, ;
       SUM(cena_plt) AS cena_plt, SUM(pocet) as pocet ;
       GROUP BY 1,2,3 FROM (m.pri_path + "platby") INTO TABLE (m.pri_path + "sk_total")
SELECT platby
APPEND FROM (m.pri_path + "sk_total")

DO dopln_nazev_kasy

SELECT id_kas, uzaverka, "Hot a spol" as druh_pl, SUM(cena_plt) as cena_plt, SUM(pocet) as pocet, datum_uz ;
       WHERE INLIST(druh_pl, "Hotove  ", "K_KARTA", "N_ESHOP", "N_BEZHO6", "N_BEZHO7", "N_BEZHO4") GROUP BY 1,2 ;
       FROM (m.pri_path + "platby") INTO TABLE (m.pri_path + "platby_hot_a_karta")

SELECT id_kas, uzaverka, druh_pl, SUM(cena_plt) as cena_plt, SUM(pocet) as pocet, datum_uz ;
       WHERE INLIST(druh_pl, "Hotove  ", "xxxx") GROUP BY 1,2 ;
       FROM (m.pri_path + "platby") INTO TABLE (m.pri_path + "platby_hot")

SELECT platby
DO dopln_nazev_platby


*   *   *   *   *   *   *   *   SLEVY   *   *   *   *   *   *   
SELECT id_kas, uzaverka, STRTR(LEFT(text_sleva,3), "_", "") + space(8) as text, sleva_abs ;
       FROM (m.pri_path + "sk_fin") INTO TABLE (m.pri_path + "slevy_1") ;
       WHERE "#" $ text_sleva AND sleva_abs > 9
SELECT id_kas + SPACE(28) as id_kas, uzaverka, text, SUM(sleva_abs) as sleva, COUNT(*) as pocet ;
       GROUP BY 1,2,3 FROM (m.pri_path + "slevy_1") INTO TABLE (m.pri_path + "slevy")
repl for "#2" $ text text with "procentní"
repl for "#3" $ text text with "cástkou"
DO dopln_nazev_kasy


*   *   *   *   *   *   *   *   TRZBY PO HLADINACH   *   *   *   *   *   *   
SELECT uzaverka, u_cis, SUM(cena_pol) as prachy_pol, SUM(cena_plt) as prachy_plt, 000.000000000 as slev_koef ;
       GROUP BY uzaverka, u_cis FROM (pri_path + "pol") INTO TABLE (m.pri_path + "koeficienty")
REPLACE ALL slev_koef WITH iif(prachy_pol # 0, ROUND(prachy_plt / prachy_pol, 9), 1)
INDEX on uzaverka + u_cis TAG uz_ucet

SELECT uzaverka, u_cis, cen_hlad, SUM(prachy) as prachy_puv, $0 as prachy ;
       GROUP BY uzaverka, u_cis, cen_hlad FROM (m.pri_path + "sk_pol") INTO TABLE (pri_path + "pol_hlad")
SET RELATION TO uzaverka + u_cis INTO koeficienty
REPLACE ALL prachy WITH ROUND(prachy_puv * koeficienty.slev_koef, 2)

SELECT LEFT(u_cis,2) + SPACE(28) as id_kas, uzaverka, cen_hlad, SUM(prachy) as prachy, COUNT(*) as pocet ;
GROUP BY 1,2,3 FROM (m.pri_path + "pol_hlad") INTO TABLE (m.pri_path + "hladiny")
DO dopln_nazev_kasy


*   *   *   *   *   *   *   *   TRZBY PO SKUPINACH   *   *   *   *   *   *   
SELECT uzaverka, u_cis, druh, SUM(prachy) as prachy, SUM(mnozstvi) as pocet ;
       GROUP BY uzaverka, u_cis, druh FROM (m.pri_path + "sk_pol") INTO TABLE (pri_path + "pol_druh")
DELE FOR ATC("pizza", druh) = 0

SELECT LEFT(u_cis,2) + SPACE(28) as id_kas, uzaverka, druh, SUM(prachy) as prachy, SUM(pocet) as pocet ;
GROUP BY 1,2,3 FROM (m.pri_path + "pol_druh") INTO TABLE (m.pri_path + "skupiny")
DO dopln_nazev_kasy

SELECT platby
INDEX ON id_kas + uzaverka + str(999999999-ABS(cena_plt)) + str(3-sign(cena_plt),2) TAG kup

*   *   *   *   *   *   *   *   *   *   *   *   *   *   *   *   *   *   *   *   *   *   *   *   
fh = fcreate(m.jmeno_html)
if m.fh > 0
     DO create_html_head
     IF "TRZ" $ m.co_generovat 
           DO create_html_trzby
     ENDIF

     IF "PLH_K" $ m.co_generovat
           SELE platby_hot_a_karta
           INDEX ON id_kas + uzaverka + str(999999999-ABS(cena_plt)) + str(3-sign(cena_plt),2) TAG kup
           DO create_html_platby
     ENDIF 

     IF "PLAT" $ m.co_generovat 
           SELECT platby
           DO create_html_platby
     ENDIF 

     IF "PLHOT" $ m.co_generovat
           SELE platby_hot
           INDEX ON id_kas + uzaverka + str(999999999-ABS(cena_plt)) + str(3-sign(cena_plt),2) TAG kup
           DO create_html_platby
     ENDIF 

     IF "SLEV" $ m.co_generovat 
           DO create_html_slevy
     ENDIF 

     IF "HLAD" $ m.co_generovat 
           DO create_html_hladiny
     ENDIF 

     IF "PIZZA" $ m.co_generovat 
           DO create_html_skupiny
     ENDIF 

     DO create_html_tail
     vysledek = m.vysledek + " ... OK "
else
     vysledek = m.vysledek + m.crlf + "[1B#R]  " + " NEPROVEDENO, nelze vytvorit soubor " + upper(m.jmeno_html) + "  ... "
endif
CLOSE DATABASES 


*  *  *  *  *  *  *  *  *  *  *  *  *  *  *  *  *  *  *  *  *  *  *  *  *  *  *  *  *  *  *  *  *  
PROCEDURE create_html_trzby
SELECT sk_chk
inde on id_kas + uzaverka tag kas_uz

STORE "Z*Z" TO o_uzav, pozadi, o_kas
scan for (cena_pol # 0) .and. (cena_plt # 0)
  if id_kas # m.o_kas
    DO zapis_zacatek_tabulky WITH "a"
    fputs(m.fh, '<TD class="center" width="75px"> Před slevou </TD>')
    fputs(m.fh, '<TD class="center" width="70px"> Po slevě </TD>')
    fputs(m.fh, '<TD class="center"> Účtů </TD></TR>')
  endif

  DO zapis_zacatek_radku_tabulky WITH "a"
  fputs(m.fh, '<TD class="right"  >' + formatuj(cena_pol)       + ' &nbsp; </TD>')
  fputs(m.fh, '<TD class="right"  >' + formatuj(cena_plt)       + ' &nbsp; </TD>')
  fputs(m.fh, '<TD class="right"  >' + trans(pocet, "999 999" ) + ' &nbsp; </TD></TR>')
endscan


*  *  *  *  *  *  *  *  *  *  *  *  *  *  *  *  *  *  *  *  *  *  *  *  *  *  *  *  *  *  *  *  *  
PROCEDURE create_html_platby

STORE "Z*Z" TO o_uzav, pozadi, o_kas
*scan for (cena_plt # 0)
SCAN FOR ABS(cena_plt) > NEJMENSI_TRZBA
  if id_kas # m.o_kas
    DO zapis_zacatek_tabulky WITH "b"
    fputs(m.fh, '<TD class="center" width="111px"> Platba </TD>')
    fputs(m.fh, '<TD class="center" width="60px"> Po slevě </TD>')
    fputs(m.fh, '<TD class="center"> Účtů </TD></TR>')
  endif

  DO zapis_zacatek_radku_tabulky WITH "b"

  fputs(m.fh, '<TD class="smallcenter" >' + druh_pl  + '</TD>')
  fputs(m.fh, '<TD class="right" >' + formatuj(cena_plt)       + ' &nbsp; </TD>')
  fputs(m.fh, '<TD class="smallright" >' + trans(pocet, "999 999" ) + ' &nbsp; </TD></TR>')
ENDSCAN 


*  *  *  *  *  *  *  *  *  *  *  *  *  *  *  *  *  *  *  *  *  *  *  *  *  *  *  *  *  *  *  *  *  
PROCEDURE create_html_hladiny
SELECT hladiny
INDEX ON id_kas + uzaverka + cen_hlad TAG kup

STORE "Z*Z" TO o_uzav, pozadi, o_kas
*scan for (prachy # 0)
SCAN FOR ABS(prachy) > NEJMENSI_TRZBA
  if id_kas # m.o_kas
    DO zapis_zacatek_tabulky WITH "d"
    fputs(m.fh, '<TD class="center" width="55px"> Hladina </TD>')
    fputs(m.fh, '<TD class="center" width="75px"> Po slevě </TD>')
    fputs(m.fh, '<TD class="center"> Účtů </TD></TR>')
  endif

  DO zapis_zacatek_radku_tabulky WITH "d"
  fputs(m.fh, '<TD class="center" >' + cen_hlad  + '</TD>')
  fputs(m.fh, '<TD class="right" >' + formatuj(prachy)         + ' &nbsp; </TD>')
  fputs(m.fh, '<TD class="right" >' + trans(pocet, "999 999" ) + ' &nbsp; </TD></TR>')
endscan


*  *  *  *  *  *  *  *  *  *  *  *  *  *  *  *  *  *  *  *  *  *  *  *  *  *  *  *  *  *  *  *  *  
PROCEDURE create_html_skupiny
SELECT skupiny
INDEX ON id_kas + uzaverka + druh TAG kup

STORE "Z*Z" TO o_uzav, pozadi, o_kas
SCAN FOR ABS(prachy) > NEJMENSI_TRZBA
  if id_kas # m.o_kas
    DO zapis_zacatek_tabulky WITH "b"
    fputs(m.fh, '<TD class="center" width="75px"> Skupina </TD>')
    fputs(m.fh, '<TD class="center" width="75px"> Před slevou </TD>')
    fputs(m.fh, '<TD class="center"> Pocet </TD></TR>')
  endif

  DO zapis_zacatek_radku_tabulky WITH "d"
  fputs(m.fh, '<TD class="smallcenter" >' + druh  + '</TD>')
  fputs(m.fh, '<TD class="right" >' + formatuj(prachy) + ' &nbsp; </TD>')
  fputs(m.fh, '<TD class="right" >' + trans(pocet ,   "999 999"  ) + ' &nbsp; </TD></TR>')
endscan


*  *  *  *  *  *  *  *  *  *  *  *  *  *  *  *  *  *  *  *  *  *  *  *  *  *  *  *  *  *  *  *  *  
PROCEDURE create_html_slevy
SELECT slevy
INDEX ON id_kas + uzaverka + str(999999999-ABS(sleva)) + str(3-sign(sleva),2) TAG kup

STORE "Z*Z" TO o_uzav, pozadi, o_kas
scan for (sleva # 0)
  if id_kas # m.o_kas
    DO zapis_zacatek_tabulky WITH "c"
    fputs(m.fh, '<TD class="center" width="70px"> Typ slevy </TD>')
    fputs(m.fh, '<TD class="center" width="70px"> Sleva</TD>')
    fputs(m.fh, '<TD class="center"> Účtů </TD></TR>')
  endif

  DO zapis_zacatek_radku_tabulky WITH "c"
  fputs(m.fh, '<TD class="center" >' + text  + '</TD>')
  fputs(m.fh, '<TD class="right" >' + formatuj(sleva) + ' &nbsp; </TD>')
  fputs(m.fh, '<TD class="right" >' + trans(pocet, "999 999" ) + ' &nbsp; </TD></TR>')
endscan


*  *  *  *  *  *  *  *  *  *  *  *  *  *  *  *  *  *  *  *  *  *  *  *  *  *  *  *  *  *  *  *  *  
PROCEDURE zapis_zacatek_tabulky ( poz1 )
  fputs(m.fh, '</TABLE></CENTER><CENTER><IMG src="./pozadi.jpg"  border="0" height="9" ></CENTER>')
  fputs(m.fh, '<CENTER><TABLE class="a" cellspacing="1" cellpadding="0"> <TR class="' + m.poz1 + 'h">' )
  fputs(m.fh, '<TD class="center" width="122px"> ' + ALLT(id_kas) + ' </TD>')
  STORE ")(*&#$%" TO o_uzav, pozadi
  o_kas = id_kas


*  *  *  *  *  *  *  *  *  *  *  *  *  *  *  *  *  *  *  *  *  *  *  *  *  *  *  *  *  *  *  *  *  
PROCEDURE zapis_zacatek_radku_tabulky (poz1)
if uzaverka # m.o_uzav
   o_uzav = uzaverka
   pozadi = IIF("1" $ m.pozadi, m.poz1 + "2", m.poz1 + "1" + IIF(id_kas = m.totalova_kasa, "i", ""))    && liche totalove radky se zobrazi inverzne

   fputs(m.fh, '<TR class="' + m.pozadi + '"><TD class="center" >' + LEFT(uzaverka, 4) + '-' + SUBST(uzaverka, 5) + '</TD>')
else
   fputs(m.fh, '<TR class="' + m.pozadi + '"><TD class="center" >' +        ""          + '</TD>')
endif


*  *  *  *  *  *  *  *  *  *  *  *  *  *  *  *  *  *  *  *  *  *  *  *  *  *  *  *  *  *  *  *  *  
PROCEDURE create_html_head

*  fputs(m.fh, '<!doctype html>' )
  fputs(m.fh, '<HTML><HEAD>' )
  fputs(m.fh, '<TITLE> Report trzeb ' + dtoc(date()) + '</TITLE>' )
  fputs(m.fh, '<meta http-equiv="content-type" content="text/html; charset=windows-1250" >' )
  fputs(m.fh, '<meta http-equiv="content-language" content="cs" >' )
  fputs(m.fh, '<link href="report.css" rel="stylesheet" type="text/css">' )
  fputs(m.fh, '</HEAD><BODY>' )

  fputs(m.fh, '<?php header("Content-type: text/html; charset=windows-1250");' )
  fputs(m.fh, '$show = $_POST["show"]; $pass = $_POST["pass"]; $password = "' + m.heslo + '"; ' )
  fputs(m.fh, 'if ($show != "1"): ?><br><br><br><br><center><form action="" method="post">' )
  fputs(m.fh, '<input type="hidden" value="1" name="show">' )
  fputs(m.fh, '<label>Heslo: </label><br><input type="password" name="pass" class="input">' )
  fputs(m.fh, '<br><br><input type="submit" value=" Vstoupit " /></form></center>' )
  fputs(m.fh, '<br><br><CENTER><IMG src="./logo.jpg"></CENTER>' )

  fputs(m.fh, '<?php endif; ?>' )
  fputs(m.fh, '<?php if ($show == "1"): ?>' )
  fputs(m.fh, '<?php if ($pass == $password): ?>' )

  fputs(m.fh, '<CENTER><TABLE>' )

*  *  *  *  *  *  *  *  *  *  *  *  *  *  *  *  *  *  *  *  *  *  *  *  *  *  *  *  *  *  *  *  *  
PROCEDURE create_html_tail
  fputs(m.fh, '</TABLE></CENTER>')
  fputs(m.fh, '<h5> generated: ' + SUBST(TTOC(DATETIME(),3), 3, 14) + ' &nbsp; ' + m.verze + '</h5>')
  fputs(m.fh, '<CENTER><IMG src="./logo.jpg" ></CENTER>' )

  fputs(m.fh, '<?php endif; ?>' )
  fputs(m.fh, '<?php if ($pass != $password): ?>' )
  fputs(m.fh, '<p>patné heslo.</p> <script type="text/javascript">history.back();</script>' )
  fputs(m.fh, '<?php endif; ?>' )
  fputs(m.fh, '<?php endif; ?>' )

  fputs(m.fh, '</BODY></HTML>' )
  fclose(m.fh)


*  *  *  *  *  *  *  *  *  *  *  *  *  *  *  *  *  *  *  *  *  *  *  *  *  *  *  *  *  *  *  *  *  
PROCEDURE dopln_nazev_kasy
IF "demo" $ LOWER(m.jmeno_html)
   REPL ALL id_kas WITH "Hospoda " + id_kas
ELSE
   SET RELA TO LEFT(id_kas, 2) INTO food_dat
   REPL FOR .NOT. EMPT(food_dat.id_zkratka) id_kas WITH UPPER(food_dat.id_zkratka)
   SET RELA TO 
   REPL ALL id_kas WITH strtr(id_kas, "POKLADNA", "")
   REPL ALL id_kas WITH strtr(id_kas, "KASA", "")
   REPL ALL id_kas WITH strtr(id_kas, "MASTER", "")
   REPL ALL id_kas WITH strtr(id_kas, " - ", " ")
   REPL for id_kas # m.totalova_kasa id_kas WITH proper(id_kas)
ENDIF 


*  *  *  *  *  *  *  *  *  *  *  *  *  *  *  *  *  *  *  *  *  *  *  *  *  *  *  *  *  *  *  *  *  
PROCEDURE dopln_nazev_platby
o_sel_dnp = SELE()
CREATE TABLE (m.pri_path + "texty") (klic C(10), j C(22))

vysledek = m.vysledek + m.crlf + "[1B#R]  spusteno doplneni nazvu plateb "

fh = fopen(m.sk_path + "..\texty.txt")
if m.fh > 0
  do while ! feof(m.fh)
    str = alltrim(fgets(fh))
    if ! empty(m.str)
      pozice = at("=", m.str)
      if pozice > 0
        klic =           left(m.str, m.pozice-1)
        j    = alltrim(substr(m.str, m.pozice+1))
        if ! empty(m.j)
          INSERT INTO (m.pri_path + "texty") (klic, j) VALUES (m.klic, m.j)
        endif
      endif
    endif
  enddo
  = fclose(m.fh)
  INDEX on klic TAG klic

  SELE (m.o_sel_dnp)
  SET RELA TO lower(LEFT(druh_pl,10)) INTO texty
  REPL FOR .NOT. EMPT(texty.klic) druh_pl WITH LOWER(texty.j)
  USE IN texty
  vysledek = m.vysledek + m.crlf + "[1B#R]  doplneny nazvy plateb "

ENDIF
SELE (m.o_sel_dnp)

*  *  *  *  *  *  *  *  *  *  *  *  *  *  *  *  *  *  *  *  *  *  *  *  *  *  *  *  *  *  *  *  *  
FUNCTION formatuj
PARAMETERS penizky
IF "1000" $ m.co_generovat
    RETURN TRANSFORM(ROUND(penizky/1000, 1), "99 999.9")
ELSE 
    RETURN TRANSFORM(ROUND(penizky, 0), "9 999 999")
ENDIF
