
SELECT c_dokl, c_karty, poradi, SUM(mnozstvi) as mnozstvi, SUM(mnozstvi*cena) as prachy ;
       GROUP BY 1,2,3 WHERE INLIST(operace, "PB", "VP", "PP") ;
       FROM (m.gcdat_path + "obraty") INTO TABLE (m.gcpri_path + "jalove_polotovary")

DELETE FOR mnozstvi # 0
PACK
INDEX on STR(c_dokl) + STR(c_karty) + STR(poradi) TAG dkp
 
SELECT obraty
SET RELATION TO STR(c_dokl) + STR(c_karty) + STR(poradi) INTO jalove_polotovary
SET FILTER TO .not. EMPTY(jalove_polotovary.c_dokl)
REPLACE ALL serial_no WITH "JALOVE" + STR(mnozstvi,10,4), mnozstvi WITH 0
*** DELETE ALL



SELECT c_dokl, poradi, COUNT(*) as pocet ;
       GROUP BY 1,2 WHERE INLIST(operace, "PP", "VP") ;
       FROM (m.gcdat_path + "obraty") INTO TABLE (m.gcpri_path + "jedinacci")
DELETE FOR pocet > 1
PACK
INDEX on STR(c_dokl) + STR(poradi) TAG dp

SELECT obraty
SET RELATION TO STR(c_dokl) + STR(poradi) INTO jedinacci
SET FILTER TO .not. EMPTY(jedinacci.c_dokl)
REPLACE ALL serial_no WITH "JEDINACEK" + STR(mnozstvi,10,4), mnozstvi WITH 0

