*  2016-06-11


SELECT disti uct_den ORDER BY 1 from (m.fn_sk_n_sez) INTO CURSOR datumy
prumer = RECCOUNT()/2 + .6
GO (m.prumer)
ddd = DATE(YEAR(datumy.uct_den), MONTH(datumy.uct_den), 22) + 22
ddd = DATE(YEAR(m.ddd), MONTH(m.ddd), 1) -1   && posledni den mesice

SELECT id_kas, uzaverka, u_cis, druh_pl, cena_pl WHERE druh_pl # "Hotove    " .and. cena_pl # 0 ;
       FROM tm_sk_plt INTO TABLE (m.gcpri_path + "platby_nehotove")
***       FROM (m.gcpri_path + "tm_sk_plt") INTO TABLE (m.gcpri_path + "platby_nehotove")
INDEX on id_kas + uzaverka + u_cis TAG kuu

SELECT id_kas, uzaverka, u_cis, PADR(id_kas, 30) as zkr_kas, trzba1, trzba2, trzba3, trzba4, dan1, dan2, dan3, dan4 ;
       FROM tm_sk_fin INTO TABLE (m.gcpri_path + "trzby_a_dane")
**       FROM (m.gcpri_path + "tm_sk_fin") INTO TABLE (m.gcpri_path + "trzby_a_dane")

SET ORDER TO    uz_kas            IN tm_sk_sez_kas
SET RELATION TO uzaverka + id_kas INTO tm_sk_sez_kas
REPLACE ALL     zkr_kas           WITH tm_sk_sez_kas.zkr_kas
SET RELATION TO

SET RELATION TO id_kas + uzaverka + u_cis INTO platby_nehotove

REPLACE FOR .not. EMPTY(platby_nehotove.druh_pl) id_kas WITH "XX", zkr_kas WITH "XX - NEHOTOVOSTNI PLATBY"
DELETE FOR id_kas = "XX"

LOCATE FOR trzba4 # 0
IF FOUND()
   = MESSAGEBOX("v datech jsou vic nez 2 sazby DPH!!", 1+48,"")
ENDIF 

select id_kas as pokladna, zkr_kas as nazev, sum(trzba1+trzba2+trzba3+trzba4) as castka, ;
       sum(trzba1) as zaklad0, sum(trzba2-dan2) as zaklad2, sum(trzba3-dan3) as zaklad1, ;
                               sum(dan2)        as  sazba2, sum(dan3)        as  sazba1  ;
       group by 1 from (m.gcpri_path + "trzby_a_dane") into table (m.gcpri_path + "trzby_jkr_1")

DO mk_dir WITH m.gchom_path + "ucto_jkr"

* pro kontrolu
COPY all to (m.gchom_path + "ucto_jkr\trzby_jkr_1")

LOCATE FOR pokladna = "AR"
kasa_arena = IIF( FOUND(), trzby_jkr_1.nazev, "AR-ARENA")
REPLACE FOR INLIST(pokladna, "L1", "O3", "O6", "O7", "OC", "OD", "F1") pokladna WITH "AR", nazev WITH m.kasa_arena

DELETE FOR pokladna = "FC"    && odpisy, nevstupuji do trzeb

select pokladna, nazev, sum(castka) as castka, ;
       sum(zaklad0) as zaklad0, sum(zaklad2) as zaklad2, sum(zaklad1) as zaklad1, ;
                                sum(sazba2)  as sazba2 , sum(sazba1)  as sazba1 , ;
       "Trzba " + LEFT(DTOS(m.ddd),6) + " " + nazev as za_co, "DPH"as danovy, "100" as kod, 0 as kolikpk, 0 as nedanove, "    " as stred, ;
       m.ddd as datum, STR(YEAR(m.ddd),4) as obd_rr, TRANSFORM(MONTH(m.ddd), "@L 99") as obd_mm, DATETIME() as caszapsani, "T" + SUBSTR(DTOS(m.ddd),2) as listek, ;
       m.s_dph2*100-100 as dan2, m.s_dph3*100-100 as dan1;
       group by 1 from (m.gcpri_path + "trzby_jkr_1") into table (m.gcpri_path + "trzby_jkr")

REPLACE FOR pokladna = "CA" stred WITH "200"
REPLACE FOR pokladna = "CB" stred WITH "210"
REPLACE FOR pokladna = "CM" stred WITH "310"
REPLACE FOR pokladna = "IP" stred WITH "450"
REPLACE FOR pokladna = "PR" stred WITH "630"
REPLACE FOR pokladna = "PC" stred WITH "632"
REPLACE FOR pokladna = "BW" stred WITH "711"
REPLACE FOR pokladna = "SL" stred WITH "715"
REPLACE FOR pokladna = "NC" stred WITH "801"
REPLACE FOR pokladna = "IC" stred WITH "810"
REPLACE FOR pokladna = "CD" stred WITH "900"
REPLACE FOR pokladna = "RR" stred WITH "903"
REPLACE FOR pokladna = "KK" stred WITH "920"
REPLACE FOR pokladna = "AR" stred WITH "700"
REPLACE FOR pokladna = "GH" stred WITH "222"    && gelato budejovicka

select disti pokladna as cislo, nazev, stred as stredisko ;
       from (m.gcpri_path + "trzby_jkr") INTO TABLE (m.gcpri_path + "trzby_jkr_kasy")

COPY FILE (m.gchom_path + "ucto_vzor\*.*") TO (m.gchom_path + "ucto_jkr\*.*")
SELECT 0
USE (m.gchom_path + "ucto_jkr\po_prij") EXCLUSIVE
ZAP 
APPEND FROM (m.gcpri_path + "trzby_jkr")
REPLACE ALL dodavatel WITH .null., fyz WITH 2, uclikv WITH .null., doklad WITH .null., exp WITH .null., pozn WITH .null., ;
kniha WITH .null., cesta WITH .null., kurs WITH .null., p_abo WITH .null., ru_nde WITH .null., reziduum WITH .null., dodak WITH .null., ;
po_karta WITH .null., zaloha WITH .null., kodover WITH .null., zakazka WITH .null., code WITH .null., euro_kur WITH .null., ;
euro_jed WITH .null., klic_odb WITH .null., uc_penez WITH .null., po_bdkod WITH .null., druhzak WITH .null., obd_ru WITH .null., p_apsstr WITH .null., ;
klic_ad WITH .null., jmeno WITH .null., kolikpopkc WITH .null., wf_spust WITH .null., cashback WITH .null., obdmaj_mm WITH .null., ;
obdmaj_rr WITH .null., zaklad_maj WITH .null., dan_maj WITH .null., rezid_zem WITH .null., _prijemka WITH .null., _smlouva WITH .null., ;
pajo WITH "Ne", odkud WITH "Z", klic_sta WITH 1, storno WITH 0, po_runde WITH 1, aritm WITH "aritmeticky", castzaok WITH "1,-", dph_prep WITH "N", soupplk WITH .F., platce WITH 1, typ WITH "PŘÍJEM"
USE (m.gchom_path + "ucto_jkr\po_poklsez") EXCLUSIVE
ZAP 
SET NULLDISPLAY TO
APPEND FROM (m.gcpri_path + "trzby_jkr_kasy")
REPLACE ALL pocatek WITH .null., zustatek WITH .null., poksklad WITH .null., pokcena WITH .null., kniha WITH .null., ;
            uc_md WITH "211", soko WITH "NE", mnoz_men WITH 1, druhvydsk WITH .null., stred1 WITH .null., ;
            klic_stred WITH .null., pk_ref WITH .null., kontrzaok WITH "0.01", fiskal_sk WITH 1, fiskal_sku WITH 1
brow
USE 
cmd = "RUN " + gcini_path + "LHA32 a " + m.gchom_path + "ucto_jkr\b3p0" + SUBSTR(DTOS(m.ddd),5,4) + " " + m.gchom_path + "ucto_jkr\ *.dbf"
&cmd
ERASE                                              (m.gchom_path + "ucto_jkr\B3P0" + SUBSTR(DTOS(m.ddd),5,4) + ".TXT")
RENAME (m.gchom_path + "ucto_jkr\B3P00000.TXT") TO (m.gchom_path + "ucto_jkr\B3P0" + SUBSTR(DTOS(m.ddd),5,4) + ".TXT")
