<?xml version="1.0" encoding="utf-16" ?>
<xsl:stylesheet version="1.0" xmlns:xsl="http://www.w3.org/1999/XSL/Transform" xmlns:fo="http://www.w3.org/1999/XSL/Format">

	<xsl:output encoding="Unicode" method="xml" version="1.0" />
	
	<xsl:strip-space elements='*'/>

	<xsl:attribute-set name='Heading'>
		<xsl:attribute name='font'>bold 14pt Calibri</xsl:attribute>
		<xsl:attribute name='margin-bottom'>2pt</xsl:attribute>
		<xsl:attribute name='margin-top'>10pt</xsl:attribute>
		<xsl:attribute name='color'>
			<xsl:value-of select='company/primaryColor'/>
		</xsl:attribute>
		<xsl:attribute name='width'>100%</xsl:attribute>
	</xsl:attribute-set>

	<xsl:attribute-set name='MainHeading'>
		<xsl:attribute name='font'>bold 16pt Calibri</xsl:attribute>
		<xsl:attribute name='margin-bottom'>2pt</xsl:attribute>
		<xsl:attribute name='margin-top'>10pt</xsl:attribute>
		<xsl:attribute name='color'>
			<xsl:value-of select='company/primaryColor'/>
		</xsl:attribute>
		<xsl:attribute name='width'>100%</xsl:attribute>
	</xsl:attribute-set>
	
	<xsl:attribute-set name='SubHeading'>
		<xsl:attribute name='font'>bold 13pt Calibri</xsl:attribute>
		<xsl:attribute name='margin-bottom'>2pt</xsl:attribute>
		<xsl:attribute name='color'>
			<xsl:value-of select='company/primaryColor'/>
		</xsl:attribute>
		<xsl:attribute name='width'>100%</xsl:attribute>
	</xsl:attribute-set>

	<xsl:attribute-set name='Title'>
		<xsl:attribute name='font'>bold 11pt Calibri</xsl:attribute>
		<xsl:attribute name='margin-bottom'>4pt</xsl:attribute>
	</xsl:attribute-set>

	<xsl:attribute-set name='Text'>
		<xsl:attribute name='font'>11pt Calibri</xsl:attribute>
		<xsl:attribute name='linefeed-treatment'>preserve</xsl:attribute>
		<xsl:attribute name='margin-bottom'>2pt</xsl:attribute>
	</xsl:attribute-set>
	
	<xsl:attribute-set name='Footer'>
		<xsl:attribute name='color'>#888888</xsl:attribute>
		<xsl:attribute name='font'>8pt Calibri</xsl:attribute>		
	</xsl:attribute-set>
	

	<xsl:template match="document">

		<fo:root>

			<fo:layout-master-set>

				<fo:simple-page-master master-name="page" margin-left="2.5cm" margin-right="2.5cm" margin-top="2.5cm">
					<fo:region-body margin-bottom="3cm" region-name="body" />
					<fo:region-after extent="2cm" region-name="footer"/>
				</fo:simple-page-master>

			</fo:layout-master-set>

			<fo:page-sequence master-reference="page">
				<fo:flow flow-name="body">

					<!-- Banner image -->
					<xsl:if test="company/logoUrl">
						<fo:block text-align="left">
							<fo:external-graphic content-width="50%"  text-align="right" src="url({company/logoUrl})"/>
							<!--<fo:external-graphic text-align="right" src="url({company/logoUrl})" height="1.5cm" content-width="100%" content-height="100%"/>-->
						</fo:block>
					</xsl:if>

					<fo:block text-align="right" xsl:use-attribute-sets="MainHeading">
						<xsl:value-of select="contact/name"/>
					</fo:block>
					<fo:block text-align="right" xsl:use-attribute-sets="SubHeading">						
						<xsl:choose>
							<xsl:when test="not(projectName = '') and not(jobName = '')">
								<xsl:value-of select="projectName"/>: <xsl:value-of select="jobName"/>
							</xsl:when>
							<xsl:when test="not(projectName = '')">
								<xsl:value-of select="projectName"/>
							</xsl:when>
							<xsl:when test="not(jobName = '')">
								<xsl:value-of select="jobName"/>
							</xsl:when>
						</xsl:choose>
					</fo:block>

					<fo:block xsl:use-attribute-sets="Text">

					</fo:block>

					<fo:block xsl:use-attribute-sets="Text">
						<xsl:value-of select="documentDate"/>&#xA0;

					</fo:block>

					<fo:block xsl:use-attribute-sets="Text" keep-together="always">
						We are very pleased to provide the following proposal for <xsl:value-of select="company/legalName"/>’s services set out below.
					</fo:block>

					<!-- Information -->
					<xsl:for-each select="documentEntries/documentEntry[entryTypeCode='ENTRYTYPE/INFORMATION' and entryStatusCode='ENTRYSTATUS/ACTIVE']">
						<fo:block xsl:use-attribute-sets="Heading" keep-with-next="always">
							<xsl:value-of select="title"/>
						</fo:block>
						<fo:block xsl:use-attribute-sets="Text" keep-together="always">
							<xsl:value-of select="description"/>
						</fo:block>
					</xsl:for-each>

					<!-- Prices -->
					<fo:block xsl:use-attribute-sets="Heading" keep-with-next="always">Pricing</fo:block>
					<xsl:for-each select="documentEntries/documentEntry[entryTypeCode='ENTRYTYPE/PRICE' and entryStatusCode='ENTRYSTATUS/ACTIVE']">
						<fo:block xsl:use-attribute-sets="Title" keep-with-next="always" keep-with-previous="always">
							<xsl:value-of select="title"/>: $<xsl:value-of select="totalValue"/>
							<xsl:if test="not(quantity = '1')">	(<xsl:value-of select="quantity"/> x $<xsl:value-of select="unitPrice"/>)</xsl:if>
						</fo:block>
						<fo:block xsl:use-attribute-sets="Text" keep-with-next="always" keep-with-previous="always" keep-together="always">
							<xsl:value-of select="description"/>
						</fo:block>
						<fo:block height="0.5cm" keep-with-previous="always"> </fo:block>
					</xsl:for-each>

					<!-- Terms -->
					<fo:block xsl:use-attribute-sets="Heading" keep-with-next="always">Terms of Service</fo:block>
					<fo:block xsl:use-attribute-sets="Text" keep-together="always">
						<xsl:value-of select="documentEntries/documentEntry[entryTypeCode='ENTRYTYPE/TERMS']/description" />

Yours sincerely,

<xsl:value-of select="salesperson/name"/> for
<xsl:value-of select="company/name"/>				
					</fo:block>

					<!-- Terms -->
					<fo:block xsl:use-attribute-sets="Heading" keep-with-next="always">Execution</fo:block>
					<fo:block xsl:use-attribute-sets="Text" keep-together="always" keep-with-next="always">By signing below you agree to the <xsl:value-of select="company/legalName"/> Terms of Service, for all Services that we (<xsl:value-of select="company/legalName"/>) provide to you anytime whether now or in the future.

Signed for and on behalf of <xsl:value-of select="contact/name"/> by:
					</fo:block>
					
					<fo:table space-before="1.5cm">
						<fo:table-body>
							<fo:table-row keep-with-next="always" height="1.5cm">
								<fo:table-cell>
									<fo:block>Name</fo:block>
								</fo:table-cell>
								<fo:table-cell width="10cm">
									<fo:block border-bottom="1pt dashed black" width="10cm">&#xA0;</fo:block>
								</fo:table-cell>
							</fo:table-row>
							<fo:table-row keep-with-next="always" height="1.5cm">
								<fo:table-cell>
									<fo:block>Title</fo:block>
								</fo:table-cell>
								<fo:table-cell width="10cm">
									<fo:block border-bottom="1pt dashed black" width="10cm">&#xA0;</fo:block>
								</fo:table-cell>
							</fo:table-row>
							<fo:table-row keep-with-next="always" height="1.5cm">
								<fo:table-cell>
									<fo:block>Signature</fo:block>
								</fo:table-cell>
								<fo:table-cell width="10cm">
									<fo:block border-bottom="1pt dashed black" width="10cm">&#xA0;</fo:block>
								</fo:table-cell>
							</fo:table-row>
							<fo:table-row keep-with-next="always" height="1.5cm">
								<fo:table-cell>
									<fo:block>Date</fo:block>
								</fo:table-cell>
								<fo:table-cell width="10cm">
									<fo:block border-bottom="1pt dashed black" width="10cm">&#xA0;</fo:block>
								</fo:table-cell>
							</fo:table-row>
						</fo:table-body>
					</fo:table>

						<fo:block id="lastPage"/>					
				</fo:flow>

				<fo:static-content flow-name="footer">
					<fo:table>
						<fo:table-body>
							<fo:table-row>
								<fo:table-cell text-align="left" xsl:use-attribute-sets="Footer">
									<fo:block>
										Phone: <xsl:value-of select="salesperson/phoneNumber"/> | Email: <xsl:value-of select="salesperson/emailAddress"/>
									</fo:block>

								</fo:table-cell>
								<fo:table-cell text-align="center"  xsl:use-attribute-sets="Footer">
									<fo:block>

									</fo:block>
								</fo:table-cell>
								<fo:table-cell text-align="right" xsl:use-attribute-sets="Footer">
									<fo:block>
										<xsl:value-of select="company/legalName"/>
									</fo:block>
								</fo:table-cell>
							</fo:table-row>
							<fo:table-row>
								<fo:table-cell text-align="left" xsl:use-attribute-sets="Footer">
									<fo:block>
										All pricing is exclusive of GST - © <xsl:value-of select="company/legalName"/>&#xA0;<xsl:value-of select="company/copyrightYear"/>
									</fo:block>
								</fo:table-cell>
								<fo:table-cell text-align="center"  xsl:use-attribute-sets="Footer">
									<fo:block>
										
									</fo:block>
								</fo:table-cell>
								<fo:table-cell text-align="right" xsl:use-attribute-sets="Footer">
								<fo:block>
									Powered by <fo:inline external-destination="url(http://www.catalystque.com)">Catalyst QUE</fo:inline> | Page <fo:page-number/> of <fo:page-number-citation ref-id="lastPage"/>								
								</fo:block>
								</fo:table-cell>
							</fo:table-row>
						</fo:table-body>
					</fo:table>
				</fo:static-content>
			</fo:page-sequence>

		</fo:root>

	</xsl:template>	

</xsl:stylesheet>
