*    *    *    *    *    *    *    *    *    *    *    *    *    *    *    *    *    *    *    *    *    *    
*    v d_televize prekopiruje u receptur cenu_prum do cena20
*    predpoklada spustenou cast1 a vypocet porizovacich cen
*
*  u receptur cenu_prum do cena20
*  v obratech prepise cenu_part z karty.cena20 pro VE
*  
*
*   2022-02-06 
*   2022-03-03 - v karty.dbf uklizen field bar_kod1, ktery byl pouzit k oznaceni receptur
*
*    *    *    *    *    *    *    *    *    *    *    *      #> ver. 2022-03-03 <#       *    *    *    *    *    *    *    *    *    *    *    *    *

IF ATC("d_televize", m.gchom_path) = 0
    WAIT "na tehle datech se to nepousti, holenku" WINDOW TIMEOUT 3
    RETURN 
ENDIF
CLOSE DATABASES 
CLOSE DATABASES 
ACTIVATE SCREEN 

USE         (m.gccen_path + "karty") ALIAS karty ORDER c_karty
COPY all to (m.gccen_path + JUSTSTEM(DBF()) + STRTRAN(TTOC(DATETIME(), 3), ":", "-"))
REPLACE FOR ATC("RECEPT", bar_kod1) > 0 cena20 WITH ROUND(cena_prum, 2), bar_kod1 WITH LOWER(bar_kod1)


SELE 0
USE         (m.gccen_path + "obraty") ALIAS obraty
COPY all to (m.gccen_path + JUSTSTEM(DBF()) + STRTRAN(TTOC(DATETIME(), 3), ":", "-"))

SET RELATION TO c_karty INTO karty
REPLACE FOR INLIST(operace, "VE", "xx", "xx") .and. .not. EMPTY(karty.cena20) cena_part WITH karty.cena20


SET POINT TO "."
generuj_csv("preceneno20a.csv")
SET POINT TO ","
generuj_csv("preceneno20b.csv")


USE IN obraty
SELECT karty
REPLACE ALL bar_kod1 WITH ""



*    *    *    *    *    *    *    *    *    *    *    *    *    *    *    *    *    *    *    *    *    *    
FUNCTION generuj_csv (jmeno_souboru)
SELECT karty
INDEX on druh_kalk + nazev TO qwe
STRTOFILE('nazev; druh_kalk; cena20; cena21; cena_prum; bar_kod1' + CHR(13)+CHR(10), m.jmeno_souboru)
SCAN FOR nazev1 # "xxx SMAZANO xxx "
    STRTOFILE('"' + nazev + '"; "' + druh_kalk + '"; ' + STR(cena20, 10,2) + "; " +  STR(cena21, 10,2) + "; " + STR(cena_prum, 10,2) + '; "' +  ALLTRIM(bar_kod1) + '"' + CHR(13)+CHR(10), m.jmeno_souboru, 1)
ENDSCAN 
