<?xml version="1.0" encoding="utf-8"?>
<xsl:stylesheet version="1.0" xmlns:xsl="http://www.w3.org/1999/XSL/Transform" xmlns:soap="http://schemas.xmlsoap.org/soap/envelope/">
	<xsl:output method="xml" encoding="UTF-8"/>

	<xsl:decimal-format name="european" decimal-separator="." grouping-separator=","/>

	<xsl:param name="mode"/>

	<xsl:template match="bestelopdracht">
		<xsl:comment>Facilitor custom XSL template for cXML bestelopdracht</xsl:comment>
		<PurchaseOrder>
			<MessageHeader>
				<CreationDateTime>
					<xsl:value-of select="datum/jaar"/>-<xsl:value-of select="datum/maand"/>-<xsl:value-of select="datum/dag"/>T<xsl:value-of select="datum/tijd"/>:00Z</CreationDateTime>
			</MessageHeader>
			<PurchaseOrder>
				<PurchaseOrderHeader>
					<DocumentID>
						<ID>
							<xsl:value-of select="id"/>
						</ID>
					</DocumentID>
					<EmployeeResponsibleParty>
						<NamePerson>
							<GivenName>
								<xsl:value-of select="bestelling/aanvrager/naam_friendly"/>
							</GivenName>
						</NamePerson>
						<Location>
							<Address>
								<StreetName>
									<xsl:value-of select="afleveradres/bezoek_adres"/>
								</StreetName>
								<PostalCode>
									<xsl:value-of select="afleveradres/bezoek_postcode"/>
								</PostalCode>
								<CityName>
									<xsl:value-of select="afleveradres/bezoek_plaats"/>
								</CityName>
								<CountryCode>NL</CountryCode>
							</Address>
						</Location>
						<Contact>
							<TelephoneCommunication>
								<FormatedNumber>
									<xsl:value-of select="besteller/telefoonnr"/>
								</FormatedNumber>
							</TelephoneCommunication>
							<EMailAddressCommunication>
								<EMailAddressID>
									<xsl:value-of select="besteller/email"/>
								</EMailAddressID>
							</EMailAddressCommunication>
						</Contact>
					</EmployeeResponsibleParty>
					<NetAmount currencyCode="EUR">
						<xsl:value-of select="format-number(sum(bestelopdrachtitem/totaal), '0.00', 'european')"/>
					</NetAmount>
					<Costcenter>
						<CostcenterId>
							<xsl:value-of select="bestelling/kostenplaats/nr"/>
						</CostcenterId>
						<Description>
							<xsl:value-of select="bestelling/kostenplaats/omschrijving"/>
						</Description>
					</Costcenter>
				</PurchaseOrderHeader>
				<xsl:for-each select="bestelopdrachtitem">
					<xsl:sort select="posnr"/>
					<PurchaseOrderLine>
						<LineNumber>
							<xsl:value-of select="posnr"/>
						</LineNumber>
						<Product>
							<Item>
								<SupplierItemID>
									<ID>
										<xsl:value-of select="substring-before(bestelitem/srtdeel/artikel_nummer,&quot;/&quot;)"/>
									</ID>
								</SupplierItemID>
								<Description>
									<xsl:value-of select="bestelitem/srtdeel/omschrijving"/>
								</Description>
							</Item>
						</Product>
						<OrderQuantity unitCode="PCE">
							<xsl:value-of select="aantal"/>
						</OrderQuantity>
						<NetPricePerUnit>
							<UnitSalePriceAmount currencyCode="EUR">
								<xsl:value-of select="prijs"/>
							</UnitSalePriceAmount>
							<Quantity unitCode="PCE">
								<xsl:value-of select="aantal"/>
							</Quantity>
						</NetPricePerUnit>
						<Prices>
							<NetAmount currencyCode="EUR">
								<xsl:value-of select="totaal"/>
							</NetAmount>
						</Prices>
						<Delivery>
							<DeliveryLocation>
								<Name>
									<xsl:value-of select="../afleveradres/naam"/>
								</Name>
								<Address>
									<StreetName>
										<xsl:value-of select="../afleveradres/bezoek_adres"/>
									</StreetName>
									<PostalCode>
										<xsl:value-of select="../afleveradres/bezoek_postcode"/>
									</PostalCode>
									<CityName>
										<xsl:value-of select="../afleveradres/bezoek_plaats"/>
									</CityName>
									<CountryCode>NL</CountryCode>
								</Address>
							</DeliveryLocation>
							<DeliveryTimePeriod>
								<StartDateTime>
									<xsl:value-of select="bestelitem/srtdeel/notitie"/>
								</StartDateTime>
								<EndDateTime>
									<xsl:value-of select="bestelitem/srtdeel/notitie"/>
								</EndDateTime>
							</DeliveryTimePeriod>
						</Delivery>
						<OrderLineCharacteristic>
							<CharacteristicName>CategoryID</CharacteristicName>
							<CharacteristicValue>
								<xsl:value-of select="substring-after(bestelitem/srtdeel/artikel_nummer,&quot;/&quot;)"/>
							</CharacteristicValue>
						</OrderLineCharacteristic>
					</PurchaseOrderLine>
				</xsl:for-each>
			</PurchaseOrder>
		</PurchaseOrder>
	</xsl:template>




	<!-- Inpakken 'bon' in SOAP envelope
	     PutOrders voegt de tag SOAPEnvelope toe roept vervolgens deze stylesheet aan -->
	<xsl:template match="SOAPEnvelope">
		<soap:Envelope xmlns:SOAP-ENV="http://schemas.xmlsoap.org/soap/envelope/" xmlns:ns1="https://corp.dev.sotasty.nl/webservice/server" xmlns:xsd="http://www.w3.org/2001/XMLSchema" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
                   xmlns:SOAP-ENC="http://schemas.xmlsoap.org/soap/encoding/" SOAP-ENV:encodingStyle="http://schemas.xmlsoap.org/soap/encoding/">
			<soap:Body>
				<ns1:PurchaseOrderRequest>
					<xXml><xsl:copy-of select="./node()"/></xXml>
					<cUsername>facilitor@absoluta.nl</cUsername>
					<cPassword>facilitator01</cPassword>
					<bBase64>false</bBase64>
				</ns1:PurchaseOrderRequest>
			</soap:Body>
		</soap:Envelope>
	</xsl:template>


	<!-- Uitpakken SOAP envelope -->
	<xsl:template match="soap:Envelope">
		<soapResult>
			<xsl:copy-of select="soap:Body/node()"/>
		</soapResult>
	</xsl:template>

	<!-- Decoderen XML response -->
	<xsl:template match="soapResult">
		<Result>
			<xsl:choose>
				<xsl:when test="facilitor/melding/returncode = 0"></xsl:when>
				<xsl:otherwise>Foutmelding:<xsl:value-of select="facilitor/melding/returncode"/> - <xsl:value-of select="facilitor/melding/returntekst"/></xsl:otherwise>
			</xsl:choose>
		</Result>
	</xsl:template>

	<xsl:template match="facilitor">
		<xsl:apply-templates select="bestelopdracht"/>
	</xsl:template>

	<xsl:template match="/">
		<!-- door SendFile.cls gebruikt voor maken 'bon' (XML die via SOAP verstuurd wordt) -->
		<xsl:apply-templates select="facilitor"/>
		<!-- door SendSOAP.cls gebruikt voor inpakken van 'bon' in SOAP envelope 
 	     SOAPEnvelope is een harde tag die in PutOrders gedefinieerd wordt. -->
		<xsl:apply-templates select="SOAPEnvelope"/>
		<!-- door SendSOAP.cls gebruikt voor uitpakken van response uit SOAP envelope -->
		<xsl:apply-templates select="soap:Envelope"/>
		<!-- door SendSOAP.cls gebruikt voor uitpakken van de inhoud uit het bericht -->
		<xsl:apply-templates select="soapResult"/>
	</xsl:template>
</xsl:stylesheet>
<!-- Stylesheet edited using Stylus Studio - (c) 2004-2007. Progress Software Corporation. All rights reserved. --><!-- Stylesheet edited using Stylus Studio - (c) 2004-2007. Progress Software Corporation. All rights reserved. --><!-- Stylesheet edited using Stylus Studio - (c) 2004-2007. Progress Software Corporation. All rights reserved. -->