*    *    *    *    *    *    *    *    *    *    *    *    *    *    *    *    *    *    *    *    *    *    *    *    *    *    *    *    
*PROCEDURE spracuj_xmlbidfood
PARAMETERS xmlko, edipor, orimeno, edimeno, kodedistred
PRIVATE hladajidedi
LOCAL pocetfaktur, odberatel, dodavatel, polozky, polozka, pocetpoloziek, sumadokladu, riadok

#DEFINE CRLF CHR(13)+CHR(10)

*!*       <HEAD>
*!*          <VENDOR_REGNO>46355821</VENDOR_REGNO>
*!*          <CUSTOMER_BRANCH>A010</CUSTOMER_BRANCH>
*!*          <STMH_NUMDOC>1221030415</STMH_NUMDOC>
*!*          <STMH_BUSCASE />
*!*          <STMH_MOVEDATE>2022-05-17</STMH_MOVEDATE>
*!*          <VOL_NAK>2517.41</VOL_NAK>
*!*          <STATUT>0</STATUT>
*!*        </HEAD>
*!*        <ITEMS>
*!*          <ITEM>
*!*            <ORDER_NR>39112452</ORDER_NR>
*!*            <CTLG_DESC>Pašt.Májka 120g</CTLG_DESC>
*!*            <VAT_TARIFF>15.00</VAT_TARIFF>
*!*            <ST_NUM>4</ST_NUM>
*!*            <VOL_NAK>71.60</VOL_NAK>
*!*          </ITEM>


hladajidedi=i_max("id_edi") 
otevri_edi_hlavpol()
insert_edihlav()

odberatel = vratsekciu("CUSTOMER_BRANCH", m.xmlko,1,"X")
c_faktury = vratsekciu("STMH_NUMDOC"    , m.xmlko,1,"C")
dat_vyst  = vratsekciu("STMH_MOVEDATE"  , m.xmlko,1,"D")
ico       = vratsekciu("VENDOR_REGNO"   , m.xmlko,1,"C")
partner   = m.ico
suma      = vratsekciu("VOL_NAK"        , m.xmlko,1,"N")
edi_stred = m.odberatel

IF EMPTY(m.odberatel) .or. EMPTY(m.c_faktury) .or. EMPTY(m.dat_vyst) .or. EMPTY(m.ico)
    chybatxt=m.chybatxt+CRLF+"Chybaju udaje o odberatelovi v doklade "+vratsekciu("Document_Number",m.xmlko,1)
ELSE 

    SELECT edihlav
    GATHER MEMVAR FIELDS c_faktury, dat_vyst, ico, partner, suma, edi_stred

    polozky       = vratsekciu("ITEMS", m.xmlko,1)
    pocetpoloziek = hladajsekciu("ITEM", m.polozky)
    sumadokladu   = 0

    FOR riadok = 1 TO m.pocetpoloziek
        polozka=vratsekciu("ITEM", m.polozky, m.riadok)
        INSERT INTO edipol (id_edi, c_data, riadok, ean, kod_zak, mnozstvo, cena_celk, dan, nazov) VALUES ;
                        (m.hladajidedi, m.cdata, m.riadok, "",;
                        vratsekciu("ORDER_NR"  ,m.polozka,1,"C"),;
                        vratsekciu("ST_NUM"    ,m.polozka,1,"N"),;
                        vratsekciu("VOL_NAK"   ,m.polozka,1,"N"),;
                        vratsekciu("VAT_TARIFF",m.polozka,1,"N"),;
                        vratsekciu("CTLG_DESC" ,m.polozka,1,"C",m.kodovastranka))
        SELECT edipol
        REPLACE FOR mnozstvo # 0 cena WITH cena_celk / mnozstvo
        sumadokladu = m.sumadokladu + cena_celk
    ENDFOR

    druhy_doklad_z_minusu()
    uloz_a_zavri_hlav_a_pol()
ENDIF 
DO pozavirej WITH "edihlav, edipol"

era_and_ok_or_err()

