Introducción


A continuación puedes encontrar un ejemplo de una aplicación con la que se pueden crear facturas de venta en PHP en Yuki a través del método ProcessSalesInvoices(sessionID, administrationId, xmlDoc). 


Ejemplo


<%

Dim objXmlHttp

Dim objXmlHttp2

Dim strSessionId

Dim strXml

Dim strAccessKey

Dim strAdministrationId

Dim strWebserviceUrl

Dim strSalesXml


strAccessKey = "REPLACE WITH WEBSERVICEACCESSKEY"

strAdministrationId = "REPLACE WITH ADMINISTRATIONID"

strWebserviceUrl = "https://api.yukiworks.be/ws/Sales.asmx"


Construye el mensaje SOAP XML para el WebServiceMethod "http://www.theyukicompany.com/Authenticate".

strXml = "<?xml version=""1.0"" encoding=""utf-8""?>" & _

"<soap12:Envelope xmlns:xsi=""http://www.w3.org/2001/XMLSchema-instance"" xmlns:xsd=""http://www.w3.org/2001/XMLSchema"" xmlns:soap12=""http://www.w3.org/2003/05/soap-envelope"">" y _

"<soap12:Body>" & _

"<Authenticate xmlns=""http://www.theyukicompany.com/"">" y _

                        "<accessKey>" & strAccessKey & "</accessKey>" & _


                        "</Autentificar>" & _

"</soap12:Body>" & _

"</soap12:Envelope>"


Crear un objeto ServerXMLHTTP.

Set objXmlHttp = Server.CreateObject("Msxml2.ServerXMLHTTP")

objXmlHttp.open "POST", strWebserviceUrl, False

objXmlHttp.setRequestHeader "Content-Type", "application/soap+xml; charset=utf-8"

objXmlHttp.setRequestHeader "SOAPAction", "http://www.theyukicompany.com/Authenticate"

objXmlHttp.setRequestHeader "Content-Length", Len(strXml)


Envía un mensaje SOAP.

objXmlHttp.send strXml


Imprime el estado de la solicitud.

Respuesta. Escribe "WebServiceMethod ""Autentificar"" estado de la solicitud: <b>" & objXmlHttp.status & " " & objXmlHttp.statusText & "</b><br /><br />"


Imprime la respuesta SOAP XML.

Escribe "<div style=""border: solid 1px black;"">" & Server.HTMLEncode(objXmlHttp.responseText) & "</div><br /><br />"


"Sesión de análisis: Clave de la respuesta SOAP XML con ActiveXObject". Si el ActiveXObject "MSXML2.DomDocument.X.X" no se puede encontrar, intenta encontrar

otra versión en MSDN.

Set objXML = Server.CreateObject("MSXML2.DomDocument.3.0")

objXML.loadXML(objXmlHttp.responseText)

strSessionId = objXML.selectNodes("/").item(0).text


Establecer objXML = Nothing

Set objXmlHttp = Nothing


strSalesXml = "<Facturas de ventas xmlns=""urn:xmlns:http://www.theyukicompany.com:salesinvoices""" y _


                " xmlns:xsi=""http://www.w3.org/2001/XMLSchema-instance"">" y _

                "  <Factura de venta>" & _


                "    <Referencia>XX-1234</Referencia>" & _


                "    <Sujeto>Testfactuur - 1</Sujeto>" & _

" <PaymentMethod>ElectronicTransfer</PaymentMethod>" & _

" <Process>true</Process>" & _

" <EmailToCustomer>false</EmailToCustomer>" & _

" <Layout />" & _

" <Date>2012-06-22</Date>" & _

" <DueDate>2012-07-22</DueDate>" & _

" <PriceList />" & _

" <Currency />" & _

" <Remarks />" & _

" <Contact>" & _

" <ContactCode>1122</ContactCode>" & _

" <FullName>Apple Sales International</FullName>" & _

" <FirstName />" & _

" <MiddleName />" & _

" <LastName />" & _

" <Gender>Male</Gender>" & _

" <CountryCode>NL</CountryCode>" & _

" <City>Rotterdam</City>" & _

" <Zipcode>1234 AA</Zipcode>" & _

" <AddressLine_1>Bergweg 25</AddressLine_1>" & _

" <AddressLine_2 />" & _

" <EmailAddress>info@test.nl</EmailAddress>" & _

" <Website />" & _

" <CoCNumber />" & _

" <VATNumber />" & _

" <ContactType>Person</ContactType>" & _

" </Contact>" & _

" <InvoiceLines>" & _

" <InvoiceLine>" & _

" <Description>Regel 1</Description>" & _

" <ProductQuantity>2</ProductQuantity>" & _

" <Product>" & _

" <Description>Product 1</Description>" & _

" <Reference>TP-1122</Reference>" & _

" <Category xsi:nil=""true"" />" & _

" <SalesPrice>14.88</SalesPrice>" & _

" <VATPercentage>6.00</VATPercentage>" & _

" <VATIncluded>true</VATIncluded>" & _

" <VATType>2</VATType>" & _

" <GLAccountCode></GLAccountCode>" & _

" <Remarks />" & _

" </Product>" & _

" </InvoiceLine>" & _

" </InvoiceLines>" & _

" </SalesInvoice>" & _

"</SalesInvoices>"




Construye el mensaje SOAP XML para el WebServiceMethod "http://www.theyukicompany.com/ProcessSalesInvoices".

strXml = "<?xml version=""1.0"" encoding=""utf-8""?>" & _

"<soap12:Envelope xmlns:xsi=""http://www.w3.org/2001/XMLSchema-instance"" xmlns:xsd=""http://www.w3.org/2001/XMLSchema"" xmlns:soap12=""http://www.w3.org/2003/05/soap-envelope"">" & _


                        "<soap12:Body>" & _

"<ProcessSalesInvoices xmlns=""http://www.theyukicompany.com/"">" & _

"<sessionId>" & strSessionId & "</sessionId>" & _

"<administrationId>" & strAdministrationId & "</administrationId>" & _

"<xmlDoc>" & strSalesXml & "</xmlDoc>" & _

"</ProcessSalesInvoices>" & _

"</soap12:Body>" & _

"</soap12:Envelope>"



Crear un objeto ServerXMLHTTP.

Set objXmlHttp2 = Server.CreateObject("Msxml2.ServerXMLHTTP")

objXmlHttp2.open "POST", strWebserviceUrl, False

objXmlHttp2.setRequestHeader "SOAPAction", "http://www.theyukicompany.com/ProcessSalesInvoices"

objXmlHttp2.setRequestHeader "Content-Type", "application/soap+xml; charset=utf-8"

objXmlHttp2.setRequestHeader "Content-Length", Len(strXml)


Envía un mensaje SOAP.

objXmlHttp2.send strXml


Imprime el estado de la solicitud.

Respuesta. Escribe "WebServiceMethod ""ProcessSalesInvoices"" estado de la solicitud: <b>" & objXmlHttp2.status & " " & objXmlHttp2.statusTexto & "</b><br /><br />"


Imprime la respuesta SOAP XML.

Escribe "<div style=""border: solid 1px black;"">" & Server.HTMLEncode(objXmlHttp2.responseText) & "</div>"


Set objXmlHttp2 = Nothing

%>