
USE (gcdat_path + "karty") ORDER C_KARTY IN 0 AGAIN 
USE (gcdat_path + "sklad") ORDER C_KARTY IN 0 AGAIN 

SELECT sklad.c_stredisk, sklad.c_karty, karty.nazev, ROUND(sklad.cena_prum, 1) as cena_skl, ROUND(karty.cena_prum, 1) as cena_prum, 33.33 AS pomer, SPACE(9) AS vysledek ;
       FROM sklad LEFT JOIN karty ON karty.c_karty == sklad.c_karty ;
       INTO TABLE porovnani_cen
DELETE FOR cena_skl = 0 .and. cena_prum = 0
REPLACE FOR cena_prum = 0 pomer WITH 3.33
REPLACE FOR cena_prum # 0 pomer WITH cena_skl / cena_prum
REPLACE FOR pomer>0 .and. pomer<1 pomer WITH -1 / pomer
REPLACE ALL pomer WITH ROUND(pomer, 1)

REPLACE FOR pomer      =   0 vysledek WITH "00"
REPLACE FOR ABS(pomer) > 1.2 vysledek WITH ALLTRIM(vysledek) + IIF(pomer > 0, ">>", "<<")
REPLACE FOR ABS(pomer) > 1.6 vysledek WITH ALLTRIM(vysledek) + IIF(pomer > 0, ">", "<")
REPLACE FOR ABS(pomer) > 2.0 vysledek WITH ALLTRIM(vysledek) + IIF(pomer > 0, ">", "<")
REPLACE FOR ABS(pomer) > 3.0 vysledek WITH ALLTRIM(vysledek) + IIF(pomer > 0, ">", "<")
REPLACE FOR ABS(pomer) > 4.0 vysledek WITH ALLTRIM(vysledek) + IIF(pomer > 0, ">", "<")
REPLACE FOR ABS(pomer) > 6.0 vysledek WITH ALLTRIM(vysledek) + IIF(pomer > 0, ">", "<")

SELECT DISTINCT c_karty WHERE NOT EMPTY(vysledek) FROM porovnani_cen INTO TABLE podezrele_karty
INDEX on c_karty TAG c_karty
SELECT porovnani_cen
SET RELATION TO c_karty INTO podezrele_karty
REPLACE FOR .not. EMPTY(podezrele_karty.c_karty) .and. EMPTY(vysledek) vysledek WITH "       ."
DELETE FOR EMPTY(vysledek)

ALTER table porovnani_cen alter cena_skl N(9,1)
ALTER table porovnani_cen alter cena_prum N(9,1)
INDEX ON nazev + STR(cena_skl) TO qwe

*BROWSE
DO pr_report WITH "nesrovnalosti_v_prumernych_cenach"
SET FILTER TO ">" $ vysledek .or. "<" $ vysledek
*BROWSE
DO pr_report WITH "nesrovnalosti_v_prumernych_cenach"
