* * *   v d_televize prekopiruje karty.cena20 do zalistovanych cen od c_partner = 14  * * * 
*
*   2020-01-27 karty s nulovou cena20 se v zalistovani smazou
*   2020-02-22 vynechaji se karty se spartem "MTZ"
*   2020-03-12 "MTZ" se nejen vynecha, ale smazou se karty, ktere tam z minula zbyly
*   2020-05-12 dvacata cena se prekopiruje taky do cena06 vcetne pripocteni DPH pro prodej vnitrnim sluzbam na kase
*

#DEFINE TELEVIZNI_DODAVATEL 14
#DEFINE VYNECHANY_SPART     "MTZ"

ACTIVATE SCREEN 
IF .not. m.issql
    USE (m.gccen_path + "dod_list")
    IF EMPTY(TAG())
        USE (m.gccen_path + "dod_list") EXCLUSIVE 
        PACK
        INDEX on c_karty TAG c_karty 
        USE (m.gccen_path + "dod_list")
    ENDIF 
    COPY all to (m.gccen_path + "dod_list" + STRTRAN(TTOC(DATETIME(), 3), ":", "-"))

    USE (m.fn_skupiny) ALIAS skupiny NOUPDATE ORDER c_druh IN 0
    SELE 0
    USE (m.fn_karty)   ALIAS karty
    SET RELATION TO c_druhs INTO skupiny 


    *    *    *   sestka je pouzita na kase pro vnitrni sluzby=repre
    REPLACE ALL            cena06 WITH ROUND(cena20 * skupiny.dan06, 1)
    REPLACE FOR cena06 = 0 cena06 WITH ROUND(cena20 * 1.15         , 1)
    *    *    *   sestka je pouzita na kase pro vnitrni sluzby=repre


    SCAN FOR c_druhs # 0 .and. skupiny.spart = VYNECHANY_SPART
       SCATTER FIELDS c_karty MEMVAR 
       WAIT skupiny.spart + karty.nazev + "    MAZEEEEEEM" WINDOW NOWAIT AT 22,22
       SELECT dod_list
       DELETE FOR c_karty = m.c_karty .and. c_partner = TELEVIZNI_DODAVATEL
    ENDSCAN 

    SCAN FOR c_druhs # 0 .and. skupiny.spart # VYNECHANY_SPART
       SCATTER FIELDS c_karty, cena20 MEMVAR 
       WAIT skupiny.spart + karty.nazev WINDOW NOWAIT AT 22,22
       
       SELECT dod_list
       IF m.cena20 # 0
           LOCATE FOR c_karty = m.c_karty .and. c_partner = TELEVIZNI_DODAVATEL
           IF FOUND()
               REPLACE cena WITH m.cena20
           ELSE
               INSERT INTO (m.gccen_path + "dod_list") (c_partner, c_karty,   cena  ) ;
                                    VALUES (TELEVIZNI_DODAVATEL, m.c_karty, m.cena20)
           ENDIF 

       ELSE
           DELETE FOR c_karty = m.c_karty .and. c_partner = TELEVIZNI_DODAVATEL
       ENDIF 

    ENDSCAN 
   WAIT CLEAR
ENDIF
