Functii API

Adaugarea Facturilor, Proformelor, Avizelor

Metoda de adaugare a documentelor se apeleaza la adresa: https://appv1.facturis-online.ro/facturis/api/add_invoice.php

Iata mai jos modul de apelare al acestei metode

Se face un POST pe pagina cu urmatorii parametrii:

xml_string – textul xml ce contine datele de logare si factura cu produse

In cazul in care datele sunt furnizate corect, se introduce documentul in sistem si se intoarce PDF-ul pentru listare ori salvare

In cazul in care apare o eroare aceasta va fi listata ca in exemplele urmatoare:

Eroare: 4 – Autentificare client esuata

Eroare: 12 – Data emiterii nu este valida

Eroare: 16 – Trebuie completat Cod Fiscal/CNP

Eroare: 27 – Valoarea TVA trebuie sa fie numerica! – nodul: n

Va prezentam mai jos modul de apelare al acestei metode in PHP:

$xml_string='<?xml version="1.0" encoding="ISO-8859-1"?>
<addInvoice>
    <login>
         <pass>!parola_primita_de_la_facturis_online!</pass>
    </login>   
    <invoice>
        <office></office>
        <administration></administration> 
        <type>A</type>
        <series>XXXX</series>
        <number>3</number>
        <issueDate>2013-06-11 08:00:00</issueDate>
        <dueDate>2013-06-11</dueDate>
        <currency>RON</currency>
        <client>client</client>
        <clientType>Juridica</clientType>
        <registerNumber>J/1981/2134</registerNumber>
        <taxCode>ro 123455</taxCode>
        <address>Adresa</address>
        <county>Judet</county>
        <bankAccount>roncb343432xxxx</bankAccount>
        <bank>banca</bank>
        <representative>delegat</representative>
        <representativeId>xx324234</representativeId>
        <deliveryPerson>persoana de livrare</deliveryPerson>
        <observations>...</observations>
        <VATrate>24%</VATrate>
        <paymentType>Ordin de Plata</paymentType>
		<Status>Emisa</Status>
        <products>
            <product>
                <productId>12345</productId>
                <productName>produs1</productName>
                <unit>buc</unit>
                <amount>2</amount>
                <unitPrice>6</unitPrice>
                <value>12</value>
                <VAT>2.88</VAT>
                <discount>0</discount>
                <productCodEan></productCodEan>
                <productCodSku></productCodSku>
                <productAltCod></productAltCod>
                <sincStocField></sincStocField>
            </product>
            <product>
                <productId>123456</productId>
                <productName>produs2</productName>
                <unit>buc</unit>
                <amount>1</amount>
                <unitPrice>120</unitPrice>
                <value>120</value>
                <VAT>28.80</VAT>
                <discount>0</discount> 
                <productCodEan></productCodEan>
                <productCodSku></productCodSku>
                <productAltCod></productAltCod>
                <sincStocField></sincStocField>				
            </product>
            <product>
                <productId>1234567</productId>
                <productName>produs3</productName>
                <unit>buc</unit>
                <amount>3</amount>
                <unitPrice>50</unitPrice>
                <value>150</value>
                <VAT>36</VAT>
                <discount>6</discount>
                <productCodEan></productCodEan>
                <productCodSku></productCodSku>
                <productAltCod></productAltCod>
                <sincStocField></sincStocField>				
            </product>
        </products>
    </invoice>
</addInvoice>';
 
 $curl_options = array(
    CURLOPT_URL => "https://appv1.facturis-online.ro/facturis/api/add_invoice.php",
    CURLOPT_POST => true,
    CURLOPT_POSTFIELDS => "xml_string=$xml_string",
    CURLOPT_RETURNTRANSFER => true,
    CURLOPT_HEADER => false,
    CURLOPT_TIMEOUT => 30,
    CURLOPT_CONNECTTIMEOUT => 5
  );
 
  $curl = curl_init();
  curl_setopt_array( $curl, $curl_options );
  $result = curl_exec( $curl );

 //daca raspunsul este o eroare
  if (strrpos($result, "Eroare") !== false){
    echo $result;
    die;
  }
 
    header('Cache-Control: public');
    header('Content-type: application/pdf');
    //daca se doreste salvata
    //header('Content-Disposition: attachment; filename="invoice.pdf"');
    //daca se doreste vizualizata
    header('Content-Disposition: inline; filename="invoice.pdf"');
    header('Content-Length: '.strlen($result));
    echo $result;
    die; 

si descrierea tag-urilor XML:

<?xml version="1.0" encoding="ISO-8859-1"?>
<addInvoice>
    <login>
         <pass>!parola_primita_de_la_facturis_online!</pass>
		 <!-- cod unic firma generat din facturis-online.ro - obligatoriu -->
    </login>   
    <invoice>
        <office></office>
		<!-- denumire punct de lucru din facturis-online.ro - optional -->
        <administration></administration>
		<!-- denumire gestiune din facturis-online.ro - optional -->   
        <type>A</type>
		<!-- tipul documentului (F - factura, P - proforma, A - aviz) - obligatoriu -->
        <series>XXXX</series>
		<!-- seria documentului - optional -->
        <number>3</number>
		<!-- numarul documentului - optional -->
        <issueDate>2013-06-11 08:00:00</issueDate>
		<!-- data emiterii in format (AAAA-LL-ZZ HH:MM:SS) - obligatoriu -->
        <dueDate>2013-06-11</dueDate>
		<!-- data scadenta in format (AAAA-LL-ZZ) - obligatoriu -->
        <currency>RON</currency>
		<!-- moneda - obligatoriu -->
        <client>client</client>
		<!-- numele complet al clientului - obligatoriu -->
        <clientType>Juridica</clientType>
		<!-- tipul clientului (persoana <Juridica, Fizica>) - obligatoriu -->
        <registerNumber>J/1981/2134</registerNumber>
		<!-- Nr. Reg. Comertului (pt. persoane juridice) / CI  (pt. persoane fizice) - obligatoriu -->
        <taxCode>ro 123455</taxCode>
		<!-- Cod Fiscal (pt. persoane juridice) /CNP (pt. persoane fizice) - obligatoriu -->
        <address>Adresa</address>
		<!-- adresa clientului - obligatoriu -->
        <county>Judet</county>
		<!-- judetul clientului - obligatoriu -->
        <bankAccount>roncb343432xxxx</bankAccount>
		<!-- contul bancar al clientului - optional -->
        <bank>banca</bank>
		<!-- banca clientului - optional -->
        <representative>delegat</representative>
		<!-- delegat - optional -->
        <representativeId>xx324234</representativeId>
		<!-- act delegat - optional -->
        <deliveryPerson>persoana de livrare</deliveryPerson>
		<!-- persoana livrare - optional -->
        <observations>...</observations>
		<!-- observatii - optional -->
        <VATrate>24%</VATrate>
		<!-- cota tva (text ex: 24%, 9%, Scutit de TVA ) - optional -->
        <paymentType>Ordin de Plata</paymentType>
		<!-- modalitate de plata (Bon Fiscal,Card,Card Partial,Chitanta (cash),Chitanta Partial,Chitanta (ramburs),Fila CEC,Ordin Bancar,Ordin de Plata,Ramburs,Ramburs in cont,Ramburs cash) - optional -->
        <Status>Emisa</Status>
		<!-- starea documentului: pt. Factura (Emisa, Platita, Partial Platita, Anulata), pt. Proforma (Emisa, Transformata), pt. Aviz (Emisa, Anulata) -->
		<products>
            <product>
                <productId>12345</productId>
				<!-- id produs FO - optional -->
                <productName>produs1</productName>
				<!-- nume produs - obligatoriu -->
                <unit>buc</unit>
				<!-- unitate de masura - obligatoriu -->
                <amount>2</amount>
				<!-- cantitate - obligatoriu -->
                <unitPrice>6</unitPrice>
				<!-- pret unitar fara TVA - obligatoriu -->
                <value>12</value>
				<!-- valoare totala fara TVA - obligatoriu -->
                <VAT>2.88</VAT>
				<!-- valoare TVA - obligatoriu -->
                <discount>0</discount>
				<!-- discount - suma ce va fi scazuta din valoarea totala cu TVA - obligatoriu -->
                <productCodEan></productCodEan>
				<!-- codul EAN - optional -->
                <productCodSku></productCodSku>
				<!-- codul SKU - optional -->
                <productAltCod></productAltCod>
				<!-- alt cod suplimentar - optional -->
                <sincStocField></sincStocField>					
				<!-- campul dupa care se face identificarea produsului in facturis online valori posibile (productId, productCodEan, productCodSku, productAltCod) - implicit identificarea se face dupa numele produsului - optional -->
            </product>
        </products>
    </invoice>
</addInvoice>	


0
Ultimele articole RO-eFactura: