*!*****************************************************************************
*!      Procedure: ODP_VYROBA
*!*****************************************************************************
PARAMETERS hladajdavku, m.hladajdatumod, plan
PRIVATE m.cdokldo, m.hladajcstredisk, m.menobuffera, m.lic_dokl, m.hladajcdokl, m.natlac, m.ret
m.ret=.t.
m.menobuffera=LOWER(SUBSTR(SYS(2015),4))
m.hladajcstredisk=m.gic_stredisk
m.natlac=""
CREATE CURSOR selzost (sestava C(30), lbl L, riadok I)
INSERT INTO selzost (sestava, lbl, riadok) VALUES ("Výroba podle pořadí",             .F.,1)
INSERT INTO selzost (sestava, lbl, riadok) VALUES ("Výroba podle zadání",             .F.,2)
INSERT INTO selzost (sestava, lbl, riadok) VALUES ("Spotřeba surovin po druzích",     .F.,3)
INSERT INTO selzost (sestava, lbl, riadok) VALUES ("Spotřeba surovin abecedně",       .F.,4)
INSERT INTO selzost (sestava, lbl, riadok) VALUES ("D4 podle pořadí",                 .F.,5)
INSERT INTO selzost (sestava, lbl, riadok) VALUES ("D4 podle zadání",                 .F.,6)
INSERT INTO selzost (sestava, lbl, riadok) VALUES ("D4 pizza",                        .F.,7)
INSERT INTO selzost (sestava, lbl, riadok) VALUES ("Sestava pro kuchaře",             .F.,10)
INSERT INTO selzost (sestava, lbl, riadok) VALUES ("Sestava pro kuchaře podle pořadí",.F.,11)
INSERT INTO selzost (sestava, lbl, riadok) VALUES ("Sestava pro skladníka",           .F.,12)
*DO FORM selpartn WITH "selzost","sestava"
SELECT selzost
SCAN FOR !EMPTY(lbl)
    m.natlac = m.natlac + TRANSFORM(riadok, "@L 99") + ","
ENDSCAN
USE IN selzost

m.natlac = " 05,06"


IF !EMPTY(m.natlac)
    IF "01,"$m.natlac .OR. "02,"$m.natlac .OR. "03,"$m.natlac .OR. "04,"$m.natlac .OR. "05,"$m.natlac .OR. "06,"$m.natlac .OR. "07,"$m.natlac
        IF m.issql
        ELSE
            *:*****************************************************************
            IF "05,"$m.natlac .OR. "06,"$m.natlac .OR. "07,"$m.natlac
                SELECT polozky.c_karty, polozky.c_poloz, polozky.hruba / polozky.pocet AS hruba,polozky.cista / polozky.pocet AS cista, polozky.poznamka, karty.nazev ;
                    FROM polozky LEFT JOIN karty ON karty.c_karty==polozky.c_karty ;
                    INTO CURSOR poc1

                SELECT poc1.nazev + SPACE(10) AS nazev, poc1.c_karty, poc1.c_poloz, poc1.hruba, poc1.cista, karty.nazev + poc1.poznamka AS poloz;
                    FROM poc1 LEFT JOIN karty ON karty.c_karty==poc1.c_poloz ;
                    INTO CURSOR mkapoc
                INDEX ON nazev TAG nazev

                SELECT nazev, c_karty, SUM(mnozstvi) + $0 AS mnozstvi, c_karty AS c_dokl, poradi ;
                    GROUP BY c_karty FROM buf_dav INTO CURSOR davka
                INDEX ON c_karty TAG c_karty

                SELECT $0 AS mnozstvi, mnozstvi AS hruba,mnozstvi AS cista, poradi, ;
                    nazev + SPACE(10) AS poloz, c_karty, SPACE(30) AS nazev, " " AS FLAG, 00 AS hloubka ;
                    FROM davka INTO CURSOR debil4 READWRITE WHERE mnozstvi>0
                FOR hloubka = 1 TO 8
                    UPDATE debil4 SET flag="S" from mkapoc WHERE EMPTY(debil4.flag)
                    UPDATE debil4 SET flag="" from mkapoc WHERE debil4.flag="S" AND LEFT(debil4.poloz,30)=LEFT(mkapoc.nazev,30)
                    SELECT debil4.poloz AS nazev, mkapoc.poloz, debil4.hruba AS mnozstvi, debil4.c_karty, ;
                        SUM(debil4.hruba * mkapoc.hruba) AS hruba,SUM(debil4.cista * mkapoc.cista) AS cista, m.hloubka AS hloubka ,debil4.poradi AS poradi;
                        FROM debil4, mkapoc GROUP BY debil4.poloz, mkapoc.poloz;
                        WHERE EMPTY(FLAG) AND LEFT(debil4.poloz,30)==LEFT(mkapoc.nazev,30) INTO CURSOR debil44
                    rcc = RECCOUNT()
                    SELECT debil4
                    REPLACE FOR EMPTY(FLAG) FLAG WITH "K"
                    INSERT INTO debil4 (nazev, poloz, mnozstvi, hruba, cista, hloubka, poradi, c_karty) ;
                                 SELECT nazev, poloz, mnozstvi, hruba, cista, hloubka, poradi, c_karty FROM debil44
                    USE IN debil44
                    IF EMPTY(m.rcc)
                        EXIT
                    ENDIF
                ENDFOR
                
                SET ORDER TO c_karty IN karty

                SELECT nazev+"|"+poloz AS qwe,poradi, nazev, poloz, c_karty, SUM(mnozstvi) AS mnozstvi, SUM(hruba) AS hruba, SUM(cista) AS cista, FLAG, hloubka ;
                    GROUP BY 1 FROM debil4 INTO CURSOR debil444 READWRITE
                REPLACE poradi WITH 9999 FOR hloubka>1
                REPLACE FOR FLAG # "K" FLAG WITH ""

                DELETE FOR EMPTY(nazev)

                SET RELATION TO c_karty INTO karty
                IF "05,"$m.natlac AND m.ret
                    INDEX ON STR(hloubka,1,0)+STR(poradi,10,0) TAG por_pol
*                    DO pr_report WITH "jak_varit_s_postupem"
                    DO prreport  WITH "jak_varit_globus"
                ENDIF

                IF "06,"$m.natlac AND m.ret
                    INDEX ON hloubka TAG naz_pol
*                    DO pr_report WITH "jak_varit_s_postupem"
                    DO prreport  WITH "jak_varit_globus"
                ENDIF

                DO pozavirej WITH "debil4, debil444, mkapoc, poc1, davka"
            ENDIF
        ENDIF 
    ENDIF
ENDIF

