PROCEDURE makexmlfacturaelectronica

LPARAMETERS plrectificativa,  ;
            mlnumefisier,  ;
            plcalefacturi
LOCAL mtipfactura, i, mlinii,  ;
      mliniireducere,  ;
      mliniistornare, mid,  ;
      maccize, mtotalcharges,  ;
      mtotalallowances, mmoneda,  ;
      minvoicetype, mcodfiscal,  ;
      mcomanda, mtara, mtiptert,  ;
      mtiptvacurent, mtvai,  ;
      mincasat, mindicetva,  ;
      mexpliesirilot
STORE 1 TO i
STORE 0 TO maccize,  ;
      mliniireducere,  ;
      mtotalcharges,  ;
      mtotalallowances, mtvai,  ;
      mincasat
STORE "" TO mexpliesirilot
IF EMPTY(pcodfiscal)
     MESSAGEBOX( ;
               "Completati codul fiscal al societatii, in ecranul 'Configurare societati'.",  ;
               48,  ;
               "Date incomplete..." ;
               )
     RETURN
ENDIF
IF  .NOT. USED("SOC_SUPL")
     myot("SOC_SUPL","SOC_SUPL", ;
         1)
ENDIF
UPDATE C_IES_FORM SET indice =  ;
       IIF(INLIST(cont, '667',  ;
       '709', '609'), -1, 0)
UPDATE C_IES_FORM SET protva = 0  ;
       WHERE INLIST(tip, "U",  ;
       "H")
DELETE FROM C_IES_FORM WHERE  ;
       EMPTY(id_u)
mid = c_id_tip.id_iesire
IF pisfb
     SQLEXEC(gnconnhandle,  ;
            "SELECT CONTRACTE.nr, CONTRACTE.data,CONTRACTE_TIP.recurenta FROM CONTRACTE INNER JOIN CONTR_DET ON CONTRACTE.id = CONTR_DET.id JOIN CONTRACTE_TIP ON CONTRACTE.cod_contr=CONTRACTE_TIP.cod WHERE id_fact=?mId",  ;
            "C_CONTRACT_FACTURA")
ELSE
     SELECT contracte.nr,  ;
            contracte.data,  ;
            contracte_tip.recurenta  ;
            FROM CONTRACTE INNER  ;
            JOIN CONTR_DET ON  ;
            contracte.id =  ;
            contr_det.id INNER  ;
            JOIN CONTRACTE_TIP ON  ;
            contracte.cod_contr =  ;
            contracte_tip.cod  ;
            WHERE id_fact = mid  ;
            INTO CURSOR  ;
            C_CONTRACT_FACTURA
ENDIF
SELECT protva, ROUND(SUM(valoare) *  ;
       protva / 100, 2) AS tva,  ;
       SUM(valoare) AS valoare,  ;
       '  ' AS tip, REPLICATE(' ',  ;
       30) AS explicatie,  ;
       REPLICATE(' ', 30) AS  ;
       motiv FROM C_IES_FORM  ;
       GROUP BY protva INTO  ;
       CURSOR C_TVA_FACTURA  ;
       READWRITE
SELECT c_tva_factura
SUM tva TO mtotaltva
INDEX ON protva TAG procent
IF pisfb
     SQLEXEC(gnconnhandle,  ;
            "SELECT DISTINCT ies_det.id_u,com_m.nr,com_m.data FROM iesiri INNER JOIN ies_det ON iesiri.id_iesire=ies_det.id_iesire" +  ;
            "		 	JOIN FACT_COMENZI ON ies_det.id_u=fact_comenzi.id_factura JOIN COMENZI ON FACT_COMENZI.id_comanda = comenzi.id_com JOIN com_m ON comenzi.id=com_m.id WHERE IESIRI.id_iesire=?mId",  ;
            "C_COMENZI_FACTURA")
ELSE
     SELECT DISTINCT ies_det.id_u,  ;
            com_m.nr, com_m.data  ;
            FROM iesiri INNER  ;
            JOIN ies_det ON  ;
            iesiri.id_iesire =  ;
            ies_det.id_iesire  ;
            INNER JOIN  ;
            FACT_COMENZI ON  ;
            ies_det.id_u =  ;
            fact_comenzi.id_factura  ;
            INNER JOIN COMENZI ON  ;
            fact_comenzi.id_comanda =  ;
            comenzi.id_com INNER  ;
            JOIN com_m ON  ;
            comenzi.id = com_m.id  ;
            WHERE  ;
            iesiri.id_iesire =  ;
            mid INTO CURSOR  ;
            C_COMENZI_FACTURA
ENDIF
SELECT DISTINCT nr, data FROM  ;
       C_COMENZI_FACTURA INTO  ;
       CURSOR  ;
       C_COMENZI_INDIVIDUALE
IF RECCOUNT("C_COMENZI_INDIVIDUALE") =  ;
   1
     mcomanda = ALLTRIM(c_comenzi_individuale.nr) +  ;
                "/" +  ;
                ALLTRIM(DTOC(c_comenzi_individuale.data))
ELSE
     mcomanda = ""
ENDIF
IF pisfb
     SQLEXEC(gnconnhandle,  ;
            "SELECT SUM(suma) AS suma FROM NOTE_FACTURI WHERE id_factura=?mId",  ;
            "C_FB")
     IF RECCOUNT("C_FB") > 0  ;
        .AND.  .NOT.  ;
        ISNULL(c_fb.suma)
          mincasat = c_fb.suma
     ENDIF
ELSE
     SELECT SUM(suma) FROM  ;
            NOTE_FACTURI WHERE  ;
            id_factura = mid INTO  ;
            ARRAY  ;
            atestincasareefactura
     IF _TALLY > 0 .AND.  .NOT.  ;
        ISNULL(atestincasareefactura)
          mincasat = atestincasareefactura(1)
     ENDIF
ENDIF
SELECT c_ies_form
mmoneda = ALLTRIM(c_ies_form.moneda)
mcodfiscal = c_ies_form.cod_fiscal
mtipfactura = c_ies_form.tip
mtara = c_ies_form.tara
mtiptert = c_ies_form.tip_tert
mtiptvacurent = gettva(c_ies_form.data)
mtvai = c_ies_form.tvai
minf_suplm = c_ies_form.inf_suplm
IF  .NOT. INLIST(mtipfactura, ' ',  ;
    'S', 'M', 'U', 'H')
     MESSAGEBOX( ;
               "Pentru acest document nu se genereaza factura electronica momentan.",  ;
               64, "Atentie...")
     RETURN
ENDIF
COUNT TO mlinii
COUNT FOR indice = -1 TO  ;
      mliniireducere
COUNT FOR indice >= 0 .AND.  ;
      valoare < 0 TO  ;
      mliniistornare
COUNT FOR cont = '419' TO  ;
      mnrliniiavans
SUM ABS(valoare) TO mdiscounturi  ;
    FOR indice = -1
mtotalallowances = mtotalallowances +  ;
                   mdiscounturi
LOCATE
SELECT c_tva_factura
SCAN
     DO CASE
          CASE mtipfactura = 'T'  ;
               .OR. mtiptert =  ;
               'I'
               REPLACE tip WITH  ;
                       'AE',  ;
                       explicatie  ;
                       WITH  ;
                       'Taxare inversa',  ;
                       motiv WITH  ;
                       'VATEX-EU-AE'
          CASE mtipfactura = 'S'
               REPLACE tip WITH  ;
                       'E',  ;
                       explicatie  ;
                       WITH  ;
                       'Scutit cu drept de deducere'
          CASE EMPTY(mtipfactura)  ;
               .AND.  ;
               c_tva_factura.protva =  ;
               0
               IF mtiptvacurent <  ;
                  3
                    REPLACE tip  ;
                            WITH  ;
                            'Z'
               ELSE
                    REPLACE tip  ;
                            WITH  ;
                            'Z'
               ENDIF
          CASE mtipfactura = 'H'
               REPLACE tip WITH  ;
                       'E',  ;
                       explicatie  ;
                       WITH  ;
                       'Bunuri second-hand',  ;
                       motiv WITH  ;
                       'VATEX-EU-F'
          CASE mtipfactura = 'U'
               REPLACE tip WITH  ;
                       'E',  ;
                       explicatie  ;
                       WITH  ;
                       'Regim special agentii de turism',  ;
                       motiv WITH  ;
                       'VATEX-EU-D'
          OTHERWISE
               REPLACE tip WITH  ;
                       'S'
     ENDCASE
ENDSCAN
IF c_ies_form.accize > 0
     maccize = c_ies_form.accize
     mtotalcharges = mtotalcharges +  ;
                     maccize
     SELECT COUNT(*) FROM  ;
            C_TVA_FACTURA WHERE  ;
            tip = 'Z' INTO ARRAY  ;
            agetcotaz
     IF _TALLY > 0 .AND.  .NOT.  ;
        ISNULL(agetcotaz(1))  ;
        .AND. agetcotaz(1) > 0
          UPDATE C_TVA_FACTURA  ;
                 SET valoare =  ;
                 valoare +  ;
                 maccize WHERE  ;
                 tip = 'Z'
     ELSE
          INSERT INTO  ;
                 C_TVA_FACTURA  ;
                 (protva, tva,  ;
                 valoare, tip,  ;
                 explicatie,  ;
                 motiv) VALUES (0,  ;
                 0, maccize, 'Z',  ;
                 'Acciza', '')
     ENDIF
ENDIF
SELECT c_ies_form
LOCATE
oxml = CREATEOBJECT("msxml2.DOMDocument")
oxml.appendchild(oxml.createnode("PROCESSINGINSTRUCTION", ;
                "xml",""))
oinvoice = oxml.appendchild(oxml.createelement("Invoice"))
oinvoice.setattribute("xmlns:cbc", ;
                     "urn:oasis:names:specification:ubl:schema:xsd:CommonBasicComponents-2" ;
                     )
oinvoice.setattribute("xmlns:udt", ;
                     "urn:oasis:names:specification:ubl:schema:xsd:UnqualifiedDataTypes-2" ;
                     )
oinvoice.setattribute("xmlns:cac", ;
                     "urn:oasis:names:specification:ubl:schema:xsd:CommonAggregateComponents-2" ;
                     )
oinvoice.setattribute("xmlns:ccts", ;
                     "urn:un:unece:uncefact:documentation:2")
oinvoice.setattribute("xmlns", ;
                     "urn:oasis:names:specification:ubl:schema:xsd:Invoice-2" ;
                     )
oinvoice.setattribute("xmlns:qdt", ;
                     "urn:oasis:names:specification:ubl:schema:xsd:QualifiedDataTypes-2" ;
                     )
oinvoice.setattribute("xsi:schemaLocation", ;
                     "urn:oasis:names:specification:ubl:schema:xsd:Invoice-2 ../../UBL-2.1(1)/xsd/maindoc/UBL-Invoice-2.1.xsd" ;
                     )
oinvoice.setattribute("xmlns:xsi", ;
                     "http://www.w3.org/2001/XMLSchema-instance" ;
                     )
oinvoice.appendchild(oxml.createelement("cbc:UBLVersionID"))
oinvoice.lastchild.text = "2.1"
oinvoice.appendchild(oxml.createelement("cbc:CustomizationID"))
oinvoice.lastchild.text = "urn:cen.eu:en16931:2017#compliant#urn:efactura.mfinante.ro:CIUS-RO:1.0.0"
oinvoice.appendchild(oxml.createelement("cbc:ID"))
oinvoice.lastchild.text = ALLTRIM(c_ies_form.nr)
oinvoice.appendchild(oxml.createelement("cbc:IssueDate"))
oinvoice.lastchild.text = ALLTRIM(STR(YEAR(c_ies_form.data))) +  ;
                          "-" +  ;
                          PADL(ALLTRIM(STR(MONTH(c_ies_form.data))),  ;
                          2, "0") +  ;
                          "-" +  ;
                          PADL(ALLTRIM(STR(DAY(c_ies_form.data))),  ;
                          2,  ;
                          "0")
IF  .NOT.  ;
    EMPTY(c_ies_form.scadent)  ;
    .AND.  .NOT.  ;
    ISNULL(c_ies_form.scadent)  ;
    .AND. c_ies_form.scadent <>  ;
    {}
     oinvoice.appendchild(oxml.createelement("cbc:DueDate"))
     oinvoice.lastchild.text = ALLTRIM(STR(YEAR(c_ies_form.scadent))) +  ;
                               "-" +  ;
                               PADL(ALLTRIM(STR(MONTH(c_ies_form.scadent))),  ;
                               2,  ;
                               "0") +  ;
                               "-" +  ;
                               PADL(ALLTRIM(STR(DAY(c_ies_form.scadent))),  ;
                               2,  ;
                               "0")
ENDIF
minvoicetype = ""
DO CASE
     CASE plrectificativa = 1
          minvoicetype = "384"
     CASE ALLTRIM(getnrfromstring(mcodfiscal)) ==  ;
          ALLTRIM(pcodfiscal)
          minvoicetype = "389"
     CASE mliniistornare = mlinii
          minvoicetype = "381"
     OTHERWISE
          minvoicetype = "380"
ENDCASE
oinvoice.appendchild(oxml.createelement("cbc:InvoiceTypeCode"))
oinvoice.lastchild.text = minvoicetype
IF mtvai = 1
     oinvoice.appendchild(oxml.createelement("cbc:Note"))
     oinvoice.lastchild.text = "TVA la incasare"
ENDIF
IF  .NOT. EMPTY(mtipfactura = 'T'  ;
    .OR. mtiptert = 'I')
     oinvoice.appendchild(oxml.createelement("cbc:Note"))
     oinvoice.lastchild.text = "Taxare inversa"
ENDIF
IF  .NOT.  ;
    EMPTY(c_ies_form.inf_suplm)
     oinvoice.appendchild(oxml.createelement("cbc:Note"))
     oinvoice.lastchild.text = ALLTRIM(minf_suplm)
ENDIF
oinvoice.appendchild(oxml.createelement("cbc:DocumentCurrencyCode"))
IF pisexport
     oinvoice.lastchild.text = ALLTRIM(moneda)
ELSE
     oinvoice.lastchild.text = "RON"
ENDIF
oinvoice.appendchild(oxml.createelement("cbc:TaxCurrencyCode"))
oinvoice.lastchild.text = "RON"
IF  .NOT. EMPTY(mcomanda)
     oorderreference = oinvoice.appendchild(oxml.createelement("cac:OrderReference"))
     oorderreference.appendchild(oxml.createelement("cbc:ID"))
     oorderreference.lastchild.text =  ;
      mcomanda
ENDIF
IF RECCOUNT("C_CONTRACT_FACTURA") >  ;
   0
     ocontractreference = oinvoice.appendchild(oxml.createelement("cac:ContractDocumentReference"))
     ocontractreference.appendchild(oxml.createelement("cbc:ID"))
     ocontractreference.lastchild.text =  ;
      ALLTRIM(c_contract_factura.nr) +  ;
      "/" +  ;
      ALLTRIM(DTOC(c_contract_factura.data))
ENDIF
osupplier = oinvoice.appendchild(oxml.createelement("cac:AccountingSupplierParty"))
oparty = osupplier.appendchild(oxml.createelement("cac:Party"))
IF EMPTY(pcs.email)
     MESSAGEBOX( ;
               "Completati adresa de email a societatii in ecranul 'Configurare societati'." +  ;
               CHR(13) +  ;
               "Aceasta este necesara pentru primirea raspunsului facturii electronice.",  ;
               48,  ;
               "Date incomplete..." ;
               )
     RETURN
ENDIF
oendpointid = oparty.appendchild(oxml.createelement("cbc:EndpointID"))
oendpointid.setattribute("schemeID", ;
                        "EM")
oendpointid.text = ALLTRIM(pcs.email)
IF  .NOT.  ;
    EMPTY(c_ies_form.cod_fiscal)
     opartyidentification = oparty.appendchild(oxml.createelement("cac:PartyIdentification"))
     oidparty = opartyidentification.appendchild(oxml.createelement("cbc:ID"))
     oidparty.text = pcodfiscal
ENDIF
oadresa = oparty.appendchild(oxml.createelement("cac:PostalAddress"))
IF EMPTY(pcs.strada)
     MESSAGEBOX( ;
               "Completati strada in ecranul 'Configurare societati'.",  ;
               48,  ;
               "Date incomplete..." ;
               )
     RETURN
ENDIF
oadresa.appendchild(oxml.createelement("cbc:StreetName"))
oadresa.lastchild.text = ALLTRIM(pcs.strada)
IF EMPTY(pcs.localitate)
     MESSAGEBOX( ;
               "Completati localitatea in ecranul 'Configurare societati'.",  ;
               48,  ;
               "Date incomplete..." ;
               )
     RETURN
ENDIF
IF EMPTY(pcs.judet)
     MESSAGEBOX( ;
               "Alegeti judetul in ecranul 'Configurare societati'.",  ;
               48,  ;
               "Date incomplete..." ;
               )
     RETURN
ELSE
     IF pcs.judet = "BUCURESTI"  ;
        .AND. EMPTY(pcs.sect)
          MESSAGEBOX( ;
                    "Completati sectorul in ecranul 'Configurare societati'.",  ;
                    48,  ;
                    "Date incomplete..." ;
                    )
          RETURN
     ENDIF
ENDIF
oadresa.appendchild(oxml.createelement("cbc:CityName"))
IF pcs.judet = "B "
     oadresa.lastchild.text = "SECTOR " +  ;
                              ALLTRIM(pcs.sect)
ELSE
     oadresa.lastchild.text = ALLTRIM(UPPER(pcs.localitate))
ENDIF
SELECT cod FROM FREETAB\JUDETE  ;
       WHERE denjud = pcs.judet  ;
       INTO ARRAY agetjudadresa
mcodjudet = ""
IF _TALLY > 0 .AND.  .NOT.  ;
   ISNULL(agetjudadresa(1))
     mcodjudet = agetjudadresa(1)
ENDIF
oadresa.appendchild(oxml.createelement("cbc:CountrySubentity"))
oadresa.lastchild.text = "RO-" +  ;
                         ALLTRIM(mcodjudet)
otara = oadresa.appendchild(oxml.createelement("cac:Country"))
otara.appendchild(oxml.createelement("cbc:IdentificationCode"))
otara.lastchild.text = "RO"
otaxe = oparty.appendchild(oxml.createelement("cac:PartyTaxScheme"))
otaxe.appendchild(oxml.createelement("cbc:CompanyID"))
otaxe.lastchild.text = "RO" +  ;
                       pcodfiscal
oschemataxe = otaxe.appendchild(oxml.createelement("cac:TaxScheme"))
oschemataxe.appendchild(oxml.createelement("cbc:ID"))
oschemataxe.lastchild.text = "VAT"
oformalegala = oparty.appendchild(oxml.createelement("cac:PartyLegalEntity"))
oformalegala.appendchild(oxml.createelement("cbc:RegistrationName"))
oformalegala.lastchild.text = ALLTRIM(pdensoc)
IF  .NOT. EMPTY(pregcom)
     oidentificatorformalegala = oformalegala.appendchild(oxml.createelement("cbc:CompanyID"))
     oidentificatorformalegala.text =  ;
      ALLTRIM(pregcom)
ENDIF
mdensoc = UPPER(pdensoc) + " "
mprefix = ""
msufix = ""
DO CASE
     CASE mdensoc = "S.C. " .OR.  ;
          mdensoc = "SC "
          mprefix = "Societate comerciala"
     CASE mdensoc = "P.F. " .OR.  ;
          mdensoc = "PF "
          mprefix = "Persoana fizica"
     CASE mdensoc = "P.F.A. "  ;
          .OR. mdensoc = "PFA "
          mprefix = "Persoana fizica autorizata"
     CASE mdensoc = "A.F. " .OR.  ;
          mdensoc = "AF "
          mprefix = "Asociatie familiala"
ENDCASE
DO CASE
     CASE " S.R.L." $ mdensoc  ;
          .OR. " SRL " $ mdensoc
          msufix = "Societate cu raspundere limitata"
     CASE " S.A." $ mdensoc .OR.  ;
          " SA " $ mdensoc
          msufix = "Societate pe actiuni"
ENDCASE
IF  .NOT. EMPTY(mprefix)
     oformalegala.appendchild(oxml.createelement("cbc:CompanyLegalForm"))
     oformalegala.lastchild.text =  ;
      ALLTRIM(mprefix)
ENDIF
IF  .NOT. EMPTY(pcs.numea) .OR.   ;
    .NOT. EMPTY(pcs.prea) .OR.   ;
    .NOT. EMPTY(pcs.email) .OR.   ;
    .NOT. EMPTY(pcs.telefon)
     ocontact = oparty.appendchild(oxml.createelement("cac:Contact"))
     IF  .NOT. EMPTY(pcs.numea)  ;
         .OR.  .NOT.  ;
         EMPTY(pcs.prea)
          ocontact.appendchild(oxml.createelement("cbc:Name"))
          ocontact.lastchild.text =  ;
           ALLTRIM(pcs.numea) +  ;
           " " +  ;
           ALLTRIM(pcs.prea)
     ENDIF
     IF  .NOT. EMPTY(pcs.telefon)
          ocontact.appendchild(oxml.createelement("cbc:Telephone"))
          ocontact.lastchild.text =  ;
           ALLTRIM(pcs.telefon)
     ENDIF
     IF  .NOT. EMPTY(pcs.email)
          ocontact.appendchild(oxml.createelement("cbc:ElectronicMail"))
          ocontact.lastchild.text =  ;
           ALLTRIM(pcs.email)
     ENDIF
ENDIF
SELECT c_ies_form
LOCATE
ocustomer = oinvoice.appendchild(oxml.createelement("cac:AccountingCustomerParty"))
opartys = ocustomer.appendchild(oxml.createelement("cac:Party"))
IF  .NOT. EMPTY(c_ies_form.email)
     oendpointid = opartys.appendchild(oxml.createelement("cbc:EndpointID"))
     oendpointid.setattribute("schemeID", ;
                             "EM")
     oendpointid.text = ALLTRIM(c_ies_form.email)
ENDIF
IF  .NOT.  ;
    EMPTY(c_ies_form.cod_fiscal)  ;
    .AND.  ;
    verifcf(ALLTRIM(c_ies_form.cod_fiscal))
     opartyidentifications = opartys.appendchild(oxml.createelement("cac:PartyIdentification"))
     oidpartys = opartyidentifications.appendchild(oxml.createelement("cbc:ID"))
     oidpartys.text = ALLTRIM(c_ies_form.cod_fiscal)
ENDIF
oadresas = opartys.appendchild(oxml.createelement("cac:PostalAddress"))
IF EMPTY(c_ies_form.adresa)
     MESSAGEBOX( ;
               "Completati adresa clientului.",  ;
               48,  ;
               "Date incomplete..." ;
               )
     RETURN
ENDIF
oadresas.appendchild(oxml.createelement("cbc:StreetName"))
oadresas.lastchild.text = ALLTRIM(c_ies_form.adresa)
IF EMPTY(c_ies_form.localitate)
     MESSAGEBOX( ;
               "Completati localitatea in adresa clientului.",  ;
               48,  ;
               "Date incomplete..." ;
               )
     RETURN
ENDIF
oadresas.appendchild(oxml.createelement("cbc:CityName"))
IF EMPTY(c_ies_form.judet)
     MESSAGEBOX( ;
               "Alegeti judetul clientului.",  ;
               48,  ;
               "Date incomplete..." ;
               )
     RETURN
ENDIF
IF c_ies_form.judet = "B "
     msector = ""
     IF  .NOT. "SECTOR" $  ;
         UPPER(c_ies_form.localitate)
          MESSAGEBOX( ;
                    "Alegeti un sector valid pentru Bucuresti in adresa clientului.",  ;
                    48,  ;
                    "Atentie...")
          RETURN
     ENDIF
     oadresas.lastchild.text = "SECTOR " +  ;
                               RIGHT(ALLTRIM(c_ies_form.localitate),  ;
                               1)
ELSE
     oadresas.lastchild.text = ALLTRIM(c_ies_form.localitate)
ENDIF
oadresas.appendchild(oxml.createelement("cbc:CountrySubentity"))
oadresas.lastchild.text = ALLTRIM(c_ies_form.judet)
otaras = oadresas.appendchild(oxml.createelement("cac:Country"))
otaras.appendchild(oxml.createelement("cbc:IdentificationCode"))
otaras.lastchild.text = IIF(  ;
                        .NOT.  ;
                        EMPTY(c_ies_form.tara),  ;
                        c_ies_form.tara,  ;
                        "RO")
IF (EMPTY(c_ies_form.tara) .OR.  ;
   c_ies_form.tara = 'RO') .AND.   ;
   .NOT.  ;
   EMPTY(c_ies_form.cod_fiscal)  ;
   .AND.  ;
   verifcf(c_ies_form.cod_fiscal)
     otaxes = opartys.appendchild(oxml.createelement("cac:PartyTaxScheme"))
     otaxes.appendchild(oxml.createelement("cbc:CompanyID"))
     otaxes.lastchild.text = "RO" +  ;
                             getnrfromstring(c_ies_form.cod_fiscal)
     oschemataxes = otaxes.appendchild(oxml.createelement("cac:TaxScheme"))
     oschemataxes.appendchild(oxml.createelement("cbc:ID"))
     oschemataxes.lastchild.text =  ;
      "VAT"
ENDIF
oformalegalas = opartys.appendchild(oxml.createelement("cac:PartyLegalEntity"))
oformalegalas.appendchild(oxml.createelement("cbc:RegistrationName"))
oformalegalas.lastchild.text = ALLTRIM(c_ies_form.den_cli)
IF  .NOT.  ;
    EMPTY(c_ies_form.reg_com)
     oidentificatorformalegalas =  ;
      oformalegalas.appendchild(oxml.createelement("cbc:CompanyID"))
     oidentificatorformalegalas.text =  ;
      ALLTRIM(c_ies_form.reg_com)
ENDIF
mdensoc = ALLTRIM(c_ies_form.den_cli) +  ;
          " "
mprefix = ""
msufix = ""
DO CASE
     CASE mdensoc = "S.C. " .OR.  ;
          mdensoc = "SC "
          mprefix = "Societate comerciala"
     CASE mdensoc = "P.F. " .OR.  ;
          mdensoc = "PF "
          mprefix = "Persoana fizica"
     CASE mdensoc = "P.F.A. "  ;
          .OR. mdensoc = "PFA "
          mprefix = "Persoana fizica autorizata"
     CASE mdensoc = "A.F. " .OR.  ;
          mdensoc = "AF "
          mprefix = "Asociatie familiala"
ENDCASE
DO CASE
     CASE " S.R.L." $ mdensoc  ;
          .OR. " SRL " $ mdensoc
          msufix = "Societate cu raspundere limitata"
     CASE " S.A." $ mdensoc .OR.  ;
          " SA " $ mdensoc
          msufix = "Societate pe actiuni"
ENDCASE
IF  .NOT. EMPTY(mprefix)
     oformalegalas.appendchild(oxml.createelement("cbc:CompanyLegalForm"))
     oformalegalas.lastchild.text =  ;
      mprefix
ENDIF
IF  .NOT. EMPTY(c_ies_form.tel)  ;
    .OR.  .NOT.  ;
    EMPTY(c_ies_form.email) .OR.   ;
    .NOT.  ;
    EMPTY(c_ies_form.delegat)
     ocontacts = opartys.appendchild(oxml.createelement("cac:Contact"))
     IF  .NOT.  ;
         EMPTY(c_ies_form.delegat)
          ocontacts.appendchild(oxml.createelement("cbc:Name"))
          ocontacts.lastchild.text =  ;
           ALLTRIM(c_ies_form.delegat)
     ENDIF
     IF  .NOT.  ;
         EMPTY(c_ies_form.tel)
          ocontacts.appendchild(oxml.createelement("cbc:Telephone"))
          ocontacts.lastchild.text =  ;
           ALLTRIM(c_ies_form.tel)
     ENDIF
     IF  .NOT.  ;
         EMPTY(c_ies_form.email)
          ocontacts.appendchild(oxml.createelement("cbc:ElectronicMail"))
          ocontacts.lastchild.text =  ;
           ALLTRIM(c_ies_form.email)
     ENDIF
ENDIF
IF USED("C_GET_ADRLIV") .AND.  ;
   RECCOUNT("C_GET_ADRLIV") > 0
     SELECT c_get_adrliv
     odelivery = oinvoice.appendchild(oxml.createelement("cac:Delivery"))
     odeliverylocation = odelivery.appendchild(oxml.createelement("cac:DeliveryLocation"))
     oadresalivrare = odeliverylocation.appendchild(oxml.createelement("cac:Address"))
     oadresalivrare.appendchild(oxml.createelement("cbc:StreetName"))
     oadresalivrare.lastchild.text =  ;
      ALLTRIM(c_get_adrliv.adresa)
     oadresalivrare.appendchild(oxml.createelement("cbc:CityName"))
     IF EMPTY(c_get_adrliv.localitate)
          MESSAGEBOX( ;
                    "Alegeti localitatea din adresa de livrare.",  ;
                    48,  ;
                    "Atentie...")
          RETURN
     ENDIF
     IF EMPTY(c_get_adrliv.judet)
          MESSAGEBOX( ;
                    "Alegeti judetul din adresa de livrare.",  ;
                    48,  ;
                    "Atentie...")
          RETURN
     ENDIF
     IF c_get_adrliv.judet = "B "
          msector = ""
          IF  .NOT. "SECTOR" $  ;
              UPPER(c_get_adrliv.localitate)
               MESSAGEBOX( ;
                         "Alegeti un sector valid pentru Bucuresti, in adresa de livrare.",  ;
                         48,  ;
                         "Atentie...")
               RETURN
          ENDIF
          oadresalivrare.lastchild.text =  ;
           "SECTOR " +  ;
           RIGHT(ALLTRIM(c_get_adrliv.localitate),  ;
           1)
     ELSE
          oadresalivrare.lastchild.text =  ;
           ALLTRIM(c_get_adrliv.localitate)
     ENDIF
     oadresalivrare.appendchild(oxml.createelement("cbc:CountrySubentity"))
     oadresalivrare.lastchild.text =  ;
      "RO-" +  ;
      ALLTRIM(c_get_adrliv.judet)
     otaralivrare = oadresalivrare.appendchild(oxml.createelement("cac:Country"))
     otaralivrare.appendchild(oxml.createelement("cbc:IdentificationCode"))
     otaralivrare.lastchild.text =  ;
      "RO"
ENDIF
SELECT c_ies_form
IF mliniireducere > 0
     SELECT c_ies_form
     SCAN FOR indice = -1
          oallowancecharge = oinvoice.appendchild(oxml.createelement("cac:AllowanceCharge"))
          oallowancecharge.appendchild(oxml.createelement("cbc:ChargeIndicator"))
          oallowancecharge.lastchild.text =  ;
           "false"
          oallowancecharge.appendchild(oxml.createelement("cbc:AllowanceChargeReasonCode"))
          oallowancecharge.lastchild.text =  ;
           "95"
          oallowancecharge.appendchild(oxml.createelement("cbc:AllowanceChargeReason"))
          oallowancecharge.lastchild.text =  ;
           IIF(c_ies_form.cont =  ;
           "667", "Scont",  ;
           IIF(c_ies_form.cont =  ;
           "709",  ;
           "Reducere comerciala",  ;
           "Discount"))
          odocallowancecharge = oallowancecharge.appendchild(oxml.createelement("cbc:Amount"))
          odocallowancecharge.setattribute("currencyID", ;
           mmoneda)
          odocallowancecharge.text =  ;
           ALLTRIM(STR(ABS(c_ies_form.valoare),  ;
           15, 2))
          otaxcategoryallowance =  ;
           oallowancecharge.appendchild(oxml.createelement("cac:TaxCategory"))
          otaxcategoryallowance.appendchild(oxml.createelement("cbc:ID"))
          SELECT tip FROM  ;
                 C_TVA_FACTURA  ;
                 WHERE protva =  ;
                 c_ies_form.protva  ;
                 INTO ARRAY  ;
                 agettipcota
          otaxcategoryallowance.lastchild.text =  ;
           ALLTRIM(agettipcota(1))
          otaxcategoryallowance.appendchild(oxml.createelement("cbc:Percent"))
          otaxcategoryallowance.lastchild.text =  ;
           ALLTRIM(STR(c_ies_form.protva,  ;
           2, 0))
          otaxschemeallowance = otaxcategoryallowance.appendchild(oxml.createelement("cac:TaxScheme"))
          otaxschemeallowance.appendchild(oxml.createelement("cbc:ID"))
          otaxschemeallowance.lastchild.text =  ;
           "VAT"
     ENDSCAN
ENDIF
IF maccize > 0
     oallowancecharge = oinvoice.appendchild(oxml.createelement("cac:AllowanceCharge"))
     oallowancecharge.appendchild(oxml.createelement("cbc:ChargeIndicator"))
     oallowancecharge.lastchild.text =  ;
      "true"
     oallowancecharge.appendchild(oxml.createelement("cbc:AllowanceChargeReason"))
     oallowancecharge.lastchild.text =  ;
      "Acciza"
     odocallowancecharge = oallowancecharge.appendchild(oxml.createelement("cbc:Amount"))
     odocallowancecharge.setattribute("currencyID", ;
      mmoneda)
     odocallowancecharge.text = ALLTRIM(STR(maccize,  ;
                                15,  ;
                                2))
     otaxcategorycharge = oallowancecharge.appendchild(oxml.createelement("cac:TaxCategory"))
     otaxcategorycharge.appendchild(oxml.createelement("cbc:ID"))
     otaxcategorycharge.lastchild.text =  ;
      "Z"
     otaxcategorycharge.appendchild(oxml.createelement("cbc:Percent"))
     otaxcategorycharge.lastchild.text =  ;
      "0"
     otaxschemeallowance = otaxcategorycharge.appendchild(oxml.createelement("cac:TaxScheme"))
     otaxschemeallowance.appendchild(oxml.createelement("cbc:ID"))
     otaxschemeallowance.lastchild.text =  ;
      "VAT"
ENDIF
IF RECCOUNT("C_TVA_FACTURA") > 0
     otaxtotal = oinvoice.appendchild(oxml.createelement("cac:TaxTotal"))
     mtvatotal = 000000000.00
     IF  .NOT. INLIST(mtipfactura,  ;
         "U", "H")
          SELECT ROUND(SUM(valoare *  ;
                 protva / 100),  ;
                 2) AS tva FROM  ;
                 C_TVA_FACTURA  ;
                 GROUP BY protva  ;
                 INTO CURSOR  ;
                 C_COTE_T
          SELECT c_cote_t
          SUM (tva) TO mtvatotal
     ELSE
          SUM (tva) TO mtvatotal
     ENDIF
     ototal = otaxtotal.appendchild(oxml.createelement("cbc:TaxAmount"))
     ototal.setattribute("currencyID", ;
                        mmoneda)
     ototal.text = ALLTRIM(STR(mtvatotal,  ;
                   15, 2))
     SELECT c_tva_factura
     SET ORDER TO procent
     LOCATE
     SCAN
          otaxablesubtotal = otaxtotal.appendchild(oxml.createelement("cac:TaxSubtotal"))
          osubtotal = otaxablesubtotal.appendchild(oxml.createelement("cbc:TaxableAmount"))
          osubtotal.setattribute("currencyID", ;
                                mmoneda)
          osubtotal.text = ALLTRIM(STR(c_tva_factura.valoare,  ;
                           15,  ;
                           2))
          osubtotaltaxa = otaxablesubtotal.appendchild(oxml.createelement("cbc:TaxAmount"))
          osubtotaltaxa.setattribute("currencyID", ;
           mmoneda)
          osubtotaltaxa.text = ALLTRIM(STR(c_tva_factura.tva,  ;
                               15,  ;
                               2))
          otaxcategorytotals = otaxablesubtotal.appendchild(oxml.createelement("cac:TaxCategory"))
          otaxcategorytotals.appendchild(oxml.createelement("cbc:ID"))
          otaxcategorytotals.lastchild.text =  ;
           ALLTRIM(c_tva_factura.tip)
          otaxcategorytotals.appendchild(oxml.createelement("cbc:Percent"))
          otaxcategorytotals.lastchild.text =  ;
           ALLTRIM(STR(c_tva_factura.protva,  ;
           2, 0))
          IF  .NOT.  ;
              EMPTY(c_tva_factura.motiv)
               otaxcategorytotals.appendchild(oxml.createelement("cbc:TaxExemptionReasonCode"))
               otaxcategorytotals.lastchild.text =  ;
                ALLTRIM(c_tva_factura.motiv)
          ENDIF
          IF  .NOT.  ;
              EMPTY(c_tva_factura.explicatie)
               otaxcategorytotals.appendchild(oxml.createelement("cbc:TaxExemptionReason"))
               otaxcategorytotals.lastchild.text =  ;
                ALLTRIM(c_tva_factura.explicatie)
          ENDIF
          otaxschemetotals = otaxcategorytotals.appendchild(oxml.createelement("cac:TaxScheme"))
          otaxschemetotals.appendchild(oxml.createelement("cbc:ID"))
          otaxschemetotals.lastchild.text =  ;
           "VAT"
     ENDSCAN
     SELECT c_ies_form
     LOCATE
     IF mmoneda <> "RON"
          otaxtotal = oinvoice.appendchild(oxml.createelement("cac:TaxTotal"))
          ototal = otaxtotal.appendchild(oxml.createelement("cbc:TaxAmount"))
          ototal.setattribute("currencyID", ;
                             "RON")
          ototal.text = ALLTRIM(STR(ROUND(mtvatotal *  ;
                        c_ies_form.curs,  ;
                        2), 15,  ;
                        2))
     ENDIF
ENDIF
SELECT c_ies_form
LOCATE
SUM valoare TO mtotalnet FOR  ;
    indice >= 0
LOCATE
mtotalnetliniifactura = mtotalnet
mtotalnet = mtotalnet +  ;
            mtotalcharges -  ;
            mtotalallowances
mtotalbrut = mtotalnet +  ;
             mtotaltva
omonetarytotal = oinvoice.appendchild(oxml.createelement("cac:LegalMonetaryTotal"))
ototalnet = omonetarytotal.appendchild(oxml.createelement("cbc:LineExtensionAmount"))
ototalnet.setattribute("currencyID", ;
                      mmoneda)
ototalnet.text = ALLTRIM(STR(mtotalnetliniifactura,  ;
                 15, 2))
ototalnetfaratva = omonetarytotal.appendchild(oxml.createelement("cbc:TaxExclusiveAmount"))
ototalnetfaratva.setattribute("currencyID", ;
                             mmoneda)
ototalnetfaratva.text = ALLTRIM(STR(mtotalnet,  ;
                        15, 2))
ototalbrut = omonetarytotal.appendchild(oxml.createelement("cbc:TaxInclusiveAmount"))
ototalbrut.setattribute("currencyID", ;
                       mmoneda)
ototalbrut.text = ALLTRIM(STR(mtotalbrut,  ;
                  15, 2))
IF mtotalallowances > 0
     ototaldeduceri = omonetarytotal.appendchild(oxml.createelement("cbc:AllowanceTotalAmount"))
     ototaldeduceri.setattribute("currencyID", ;
                                mmoneda)
     ototaldeduceri.text = ALLTRIM(STR(mtotalallowances,  ;
                           15,  ;
                           2))
ENDIF
IF mtotalcharges > 0
     ototaltaxe = omonetarytotal.appendchild(oxml.createelement("cbc:ChargeTotalAmount"))
     ototaltaxe.setattribute("currencyID", ;
                            mmoneda)
     ototaltaxe.text = ALLTRIM(STR(mtotalcharges,  ;
                       15, 2))
ENDIF
IF mincasat > 0
     ototalincasat = omonetarytotal.appendchild(oxml.createelement("cbc:PrepaidAmount"))
     ototalincasat.setattribute("currencyID", ;
                               mmoneda)
     ototalincasat.text = ALLTRIM(STR(mincasat,  ;
                          15,  ;
                          2))
ENDIF
ototalplata = omonetarytotal.appendchild(oxml.createelement("cbc:PayableAmount"))
ototalplata.setattribute("currencyID", ;
                        mmoneda)
ototalplata.text = ALLTRIM(STR(mtotalbrut -  ;
                   mincasat, 15,  ;
                   2))
SELECT c_ies_form
SCAN FOR indice = 0
     oinvoiceline = oinvoice.appendchild(oxml.createelement("cac:InvoiceLine"))
     oinvoiceline.appendchild(oxml.createelement("cbc:ID"))
     oinvoiceline.lastchild.text =  ;
      ALLTRIM(STR(i, 4, 0))
     IF  .NOT.  ;
         EMPTY(ALLTRIM(c_ies_form.text_supl))
          oinvoiceline.appendchild(oxml.createelement("cbc:Note"))
          oinvoiceline.lastchild.text =  ;
           ALLTRIM(c_ies_form.text_supl)
     ENDIF
     SELECT cod FROM FREETAB\um  ;
            WHERE cod_ro =  ;
            c_ies_form.um INTO  ;
            ARRAY agetumfact
     mum = "H87"
     IF _TALLY > 0 .AND.  .NOT.  ;
        ISNULL(agetumfact(1))
          mum = ALLTRIM(agetumfact(1))
     ENDIF
     oum = oinvoiceline.appendchild(oxml.createelement("cbc:InvoicedQuantity"))
     oum.setattribute("unitCode", ;
                     mum)
     oum.text = ALLTRIM(STR(c_ies_form.cantitate,  ;
                15, 3))
     oamount = oinvoiceline.appendchild(oxml.createelement("cbc:LineExtensionAmount"))
     oamount.setattribute("currencyID", ;
                         mmoneda)
     oamount.text = ALLTRIM(STR(c_ies_form.valoare,  ;
                    15, 2))
     SELECT * FROM  ;
              C_COMENZI_FACTURA  ;
              WHERE id_u =  ;
              c_ies_form.id_u  ;
              INTO ARRAY  ;
              agetcomenzilinie
     IF _TALLY > 0 .AND.  .NOT.  ;
        ISNULL(agetcomenzilinie(1, ;
        2)) .AND.  .NOT.  ;
        ISNULL(agetcomenzilinie(1, ;
        3))
          oorderlinereference = oinvoiceline.appendchild(oxml.createelement("cac:OrderLineReference"))
          oorderlinereference.appendchild(oxml.createelement("cbc:LineID"))
          oorderlinereference.lastchild.text =  ;
           ALLTRIM(agetcomenzilinie(1, ;
           2)) + "/" +  ;
           ALLTRIM(DTOC(agetcomenzilinie(1, ;
           3)))
     ENDIF
     oitem = oinvoiceline.appendchild(oxml.createelement("cac:Item"))
     IF  .NOT.  ;
         EMPTY(c_ies_form.is_a)
          oitem.appendchild(oxml.createelement("cbc:Description"))
          oitem.lastchild.text = ALLTRIM(c_ies_form.is_a)
     ENDIF
     IF  .NOT.  ;
         EMPTY(c_ies_form.denumire)
          oitem.appendchild(oxml.createelement("cbc:Name"))
          oitem.lastchild.text = ALLTRIM(c_ies_form.denumire)
     ENDIF
     IF  .NOT.  ;
         EMPTY(c_ies_form.cod_art_cl)
          obuyeritem = oitem.appendchild(oxml.createelement("cac:BuyersItemIdentification"))
          obuyeritem.appendchild(oxml.createelement("cbc:ID"))
          obuyeritem.lastchild.text =  ;
           c_ies_form.cod_art_cl
     ENDIF
     IF  .NOT.  ;
         EMPTY(c_ies_form.cod)
          oselleritem = oitem.appendchild(oxml.createelement("cac:SellersItemIdentification"))
          oselleritem.appendchild(oxml.createelement("cbc:ID"))
          oselleritem.lastchild.text =  ;
           ALLTRIM(c_ies_form.cod)
     ENDIF
     IF isi
          SELECT c_get_cbare
          LOCATE FOR cod =  ;
                 c_ies_form.cod  ;
                 .AND.  ;
                 c_get_cbare.cod_bare <>  ;
                 0
          IF FOUND()
               ostandarditem = oitem.appendchild(oxml.createelement("cac:StandardItemIdentification"))
               oidstandard = ostandarditem.appendchild(oxml.createelement("cbc:ID"))
               oidstandard.setattribute("schemeID", ;
                "0160")
               oidstandard.text =  ;
                ALLTRIM(STR(c_get_cbare.cod_bare,  ;
                13, 0))
          ENDIF
          IF pcs.is_loturi
               SELECT c_get_cbare
               LOCATE FOR cod =  ;
                      c_ies_form.cod  ;
                      .AND.  ;
                      is_lot = 1
               IF FOUND()
                    IF c_ies_form.cantitate >=  ;
                       0
                         IF  .NOT.  ;
                             USED("TMPDESC1")
                              getdescarcari(c_ies_form.cod, ;
                               c_ies_form.gestiune, ;
                               c_id_tip.id_iesire, ;
                               0, ;
                               1, ;
                               .F.)
                         ENDIF
                         SELECT tmpdesc1
                         mexpliesirilot =  ;
                          ""
                         SCAN FOR   ;
                              .NOT.  ;
                              EMPTY(lot)
                              IF pisfb
                                   SQLEXEC(gnconnhandle, "SELECT garantie,fabricatie,explicatie FROM LOTURI WHERE cod=?TMPDESC1.lot", "C_FB")
                                   SELECT * FROM C_FB INTO ARRAY agetgarantie
                              ELSE
                                   SELECT garantie, fabricatie, explicatie FROM LOTURI WHERE cod = tmpdesc1.lot INTO ARRAY agetgarantie
                              ENDIF
                              IF _TALLY >  ;
                                 0
                                   mexpliesirilot = mexpliesirilot + IIF(EMPTY(mexpliesirilot), "Lot ", "." + " Lot ") + ALLTRIM(tmpdesc1.lot) + IIF( .NOT. EMPTY(agetgarantie(1,1)) .AND.  .NOT. ISNULL(agetgarantie(1,1)), " exp. " + DTOC(agetgarantie(1,1)), "") + IIF( .NOT. EMPTY(agetgarantie(1,2)) .AND.  .NOT. ISNULL(agetgarantie(1,2)), " fabr. " + DTOC(agetgarantie(1,2)), "")
                              ELSE
                                   mexpliesirilot = IIF(EMPTY(mexpliesirilot), "Lot " + ALLTRIM(tmpdesc1.lot), mexpliesirilot + ", " + ALLTRIM(tmpdesc1.lot))
                              ENDIF
                         ENDSCAN
                    ENDIF
               ENDIF
               IF  .NOT.  ;
                   EMPTY(mexpliesirilot)
                    oclassificationlot =  ;
                     oitem.appendchild(oxml.createelement("cac:CommodityClassification"))
                    olot = oclassificationlot.appendchild(oxml.createelement("cbc:ItemClassificationCode"))
                    olot.setattribute("listID", ;
                     "BB")
                    olot.text = IIF(LEN(ALLTRIM(mexpliesirilot)) >  ;
                                50,  ;
                                LEFT(ALLTRIM(mexpliesirilot),  ;
                                50),  ;
                                ALLTRIM(mexpliesirilot))
               ENDIF
          ENDIF
          SELECT c_get_cbare
          LOCATE FOR cod =  ;
                 c_ies_form.cod  ;
                 .AND.  ;
                 c_get_cbare.cod_bare <>  ;
                 0
          IF FOUND()
               oclassificationcodbare =  ;
                oitem.appendchild(oxml.createelement("cac:CommodityClassification"))
               ocodbare = oclassificationcodbare.appendchild(oxml.createelement("cbc:ItemClassificationCode"))
               ocodbare.setattribute("listID", ;
                "EN")
               ocodbare.text = ALLTRIM(STR(c_get_cbare.cod_bare,  ;
                               13,  ;
                               0))
          ENDIF
          SELECT c_get_cbare
          LOCATE FOR cod =  ;
                 c_ies_form.cod  ;
                 .AND.  .NOT.  ;
                 EMPTY(c_get_cbare.cod_fe)  ;
                 .AND.  .NOT.  ;
                 ISNULL(c_get_cbare.cod_fe)
          IF FOUND()
               oclassificationnc =  ;
                oitem.appendchild(oxml.createelement("cac:CommodityClassification"))
               oclassificationstandardidnc =  ;
                oclassificationnc.appendchild(oxml.createelement("cbc:ItemClassificationCode"))
               oclassificationstandardidnc.setattribute("listID", ;
                "TSP")
               oclassificationstandardidnc.text =  ;
                ALLTRIM(c_get_cbare.cod_fe)
          ENDIF
     ENDIF
     oitemtaxcategory = oitem.appendchild(oxml.createelement("cac:ClassifiedTaxCategory"))
     SELECT tip FROM  ;
            C_TVA_FACTURA WHERE  ;
            protva =  ;
            c_ies_form.protva  ;
            INTO ARRAY  ;
            agettipcota
     oitemtaxcategory.appendchild(oxml.createelement("cbc:ID"))
     oitemtaxcategory.lastchild.text =  ;
      ALLTRIM(agettipcota(1))
     oitemtaxcategory.appendchild(oxml.createelement("cbc:Percent"))
     oitemtaxcategory.lastchild.text =  ;
      ALLTRIM(STR(c_ies_form.protva,  ;
      2, 0))
     oitemtaxscheme = oitemtaxcategory.appendchild(oxml.createelement("cac:TaxScheme"))
     oitemtaxscheme.appendchild(oxml.createelement("cbc:ID"))
     oitemtaxscheme.lastchild.text =  ;
      "VAT"
     oitemprice = oinvoiceline.appendchild(oxml.createelement("cac:Price"))
     oitemamount = oitemprice.appendchild(oxml.createelement("cbc:PriceAmount"))
     oitemamount.setattribute("currencyID", ;
                             mmoneda)
     oitemamount.text = ALLTRIM(STR(c_ies_form.pret_vanz,  ;
                        15, 4))
     i = i + 1
ENDSCAN
mdencomplet = plcalefacturi +  ;
              mlnumefisier +  ;
              ".xml"
mdenfisierraspuns = plcalefacturi +  ;
                    mlnumefisier +  ;
                    '.txt'
oxml.save(mdencomplet)
IF FILE(mdenfisierraspuns)
     DELETE FILE  ;
            (mdenfisierraspuns)
ENDIF
cfilename = 'FREETAB\dist\Efactura\DUKIntegrator.jar'
cparams = ' -c FREETAB\dist\Efactura\config -v FACT1 ' +  ;
          mdencomplet + ' ' +  ;
          mdenfisierraspuns
shellexecute(0,"open",cfilename, ;
            cparams,"",1)
WAIT WINDOW TIMEOUT 2 ""
shellexecute(0,"open", ;
            plcalefacturi,"","", ;
            1)
IF FILE(mdenfisierraspuns)
     IF FILETOSTR(mdenfisierraspuns) =  ;
        "ok"
          MESSAGEBOX( ;
                    "Factura este valida. O puteti încarca prin SPV, la sectiunea 'Factura electronica', cu optiunea de sintaxa XML - UBL sau cu programul 'Declaratii ANAF'.",  ;
                    64,  ;
                    "Validare declaratie" ;
                    )
          DELETE FILE  ;
                 (mdenfisierraspuns)
     ELSE
          MODIFY FILE  ;
                 (mdenfisierraspuns)
     ENDIF
ENDIF
ENDPROC



