k&   SalesGraphsByAccountManagerForMonth.xsl C:\Users\Paul.Hunt\Desktop\SalesGraphsByAccountManagerForMonth.xsl    O   C:\Users\PAUL~1.HUN\AppData\Local\Temp\SalesGraphsByAccountManagerForMonth.xsl )$  ﻿<xsl:stylesheet xmlns:x="http://www.w3.org/2001/XMLSchema" xmlns:d="http://schemas.microsoft.com/sharepoint/dsp" version="1.0" exclude-result-prefixes="xsl msxsl ddwrt" xmlns:ddwrt="http://schemas.microsoft.com/WebParts/v2/DataView/runtime" xmlns:asp="http://schemas.microsoft.com/ASPNET/20" xmlns:__designer="http://schemas.microsoft.com/WebParts/v2/DataView/designer" xmlns:xsl="http://www.w3.org/1999/XSL/Transform" xmlns:msxsl="urn:schemas-microsoft-com:xslt" xmlns:WebControls="Microsoft.SharePoint.WebControls" xmlns:ddwrt2="urn:frontpage:internal">
	<xsl:output method="html" indent="no"/>
	<xsl:decimal-format NaN="NaN"/>
	<xsl:param name="dvt_apos">&apos;</xsl:param>
	<xsl:variable name="dvt_1_automode">0</xsl:variable>
	<xsl:template match="/" xmlns:x="http://www.w3.org/2001/XMLSchema" xmlns:d="http://schemas.microsoft.com/sharepoint/dsp" xmlns:asp="http://schemas.microsoft.com/ASPNET/20" xmlns:__designer="http://schemas.microsoft.com/WebParts/v2/DataView/designer" xmlns:WebControls="Microsoft.SharePoint.WebControls">
		<xsl:call-template name="dvt_1"/>
	</xsl:template>

	<xsl:template name="dvt_1">
		<xsl:param name="ParentPath"/>
		<xsl:variable name="dvt_StyleName">Table</xsl:variable>
		<xsl:variable name="Rows" select="/dsQueryResponse/Rows/Row"/>
		<xsl:variable name="dvt_RowCount" select="count($Rows)" />
		<xsl:variable name="IsEmpty" select="$dvt_RowCount = 0" />

		<xsl:call-template name="dvt_1.footer">
			<xsl:with-param name="Rows" select="$Rows" />
		</xsl:call-template>
	</xsl:template>

	<xsl:template name="percentformat">
		<xsl:param name="percent"/>
		<xsl:choose>
			<xsl:when test="format-number($percent, '#,##0%;-#,##0%')= 'NaN'">0%</xsl:when>
			<xsl:otherwise>
				<xsl:value-of select="format-number($percent, '#,##0%;-#,##0%')" />
			</xsl:otherwise>
		</xsl:choose>
	</xsl:template>

	<xsl:template name="dvt_1.footer">
		<xsl:param name="ParentPath" />
		<xsl:param name="Rows" />

<!-- These style are used to colour the bars accordingly.-->
		
		<style>
			.GreenBar
			{
			background-position:left top;
			color:#000000;
			background-image:url("/_layouts/images/greenbar.gif");
			background-color:#ffffff;
			border:1px solid #000000;
			background-repeat:repeat-x;
			}
			.YellowBar
			{
			background-position:left top;
			color:#000000;
			background-image:url("/_layouts/images/yellowbar.gif");
			background-color:#ffffff;
			border:1px solid #000000;
			background-repeat:repeat-x;
			}

			.RedBar
			{
			background-position:left top;
			color:#000000;
			background-image:url("/_layouts/images/redbar.gif");
			background-color:#ffffff;
			border:1px solid #000000;
			background-repeat:repeat-x;
			}
		</style>


		<div class="ms-wptitle">Sales Team</div>
		<table width="100%" cellspacing="0" cellpadding="2" style="border-right: 1 solid #C0C0C0; border-bottom: 1 solid #C0C0C0; border-left-style: solid; border-left-width: 1; border-top-style: solid; border-top-width: 1;">

			<!--Call the section below for each sales manager that exists in the list
				changing the name as required in the three places that it's required. 
				The ItemCount will track the number of sales made in the time interval 
				and ItemSum will add the amounts together, giving us a single value to base our barchart on.
				
				Note: the target value is based on 1/12 of the sales managers annual target. This gives us an
				indication of performance against target for the current month.
				-->

			<xsl:call-template name="showBar">
				<xsl:with-param name="Target" select="25000" />
				<xsl:with-param name="ColumnTitle" select="'Chris'" />
				<xsl:with-param name="ItemCount" select="count(/dsQueryResponse/Rows/Row[normalize-space(@Account_x0020_Manager) = 'Chris'])" />
				<xsl:with-param name="ItemSum" select="sum(/dsQueryResponse/Rows/Row/@Value[../@Account_x0020_Manager = 'Chris'])" />
			</xsl:call-template>

			<xsl:call-template name="showBar">
				<xsl:with-param name="Target" select="25000" />
				<xsl:with-param name="ColumnTitle" select="'Paul'" />
				<xsl:with-param name="ItemCount" select="count(/dsQueryResponse/Rows/Row[normalize-space(@Account_x0020_Manager) = 'Paul'])" />
				<xsl:with-param name="ItemSum" select="sum(/dsQueryResponse/Rows/Row/@Value[../@Account_x0020_Manager = 'Paul'])" />
			</xsl:call-template>

		</table>
		<br/>
		<br/>
		
		<!-- Finally we do the same again, but this time for the two Sales types-->
		
		<div class="ms-wptitle">Consultancy &amp; Managed Services</div>
		<table width="100%" cellspacing="0" cellpadding="2" style="border-right: 1 solid #C0C0C0; border-bottom: 1 solid #C0C0C0; border-left-style: solid; border-left-width: 1; border-top-style: solid; border-top-width: 1;">
			<xsl:call-template name="showBar">
				<xsl:with-param name="Target" select="120000" />
				<xsl:with-param name="ColumnTitle" select="'Consultancy'" />
				<xsl:with-param name="ItemCount" select="count(/dsQueryResponse/Rows/Row[normalize-space(@Sales_x0020_Type) = 'Consultancy'])" />
				<xsl:with-param name="ItemSum" select="sum(/dsQueryResponse/Rows/Row/@Value[../@Sales_x0020_Type = 'Consultancy'])" />
			</xsl:call-template>
			<xsl:call-template name="showBar">
				<xsl:with-param name="Target" select="60000" />
				<xsl:with-param name="ColumnTitle" select="'Managed Services'" />
				<xsl:with-param name="ItemCount" select="count(/dsQueryResponse/Rows/Row[normalize-space(@Sales_x0020_Type) = 'Managed Services'])" />
				<xsl:with-param name="ItemSum" select="sum(/dsQueryResponse/Rows/Row/@Value[../@Sales_x0020_Type = 'Managed Services'])" />
			</xsl:call-template>

		</table>

		<br/>
		<br/>
		<!-- and then for readability, we output a small key.-->
		<table>
			<tr>
				<td width="40%"></td>
				<td width="150px;" class="GreenBar"></td>
				<td class="ms-wptitle">Green bar = 100% target achieved</td>
			</tr>
			<tr>
				<td width="40%"></td>
				<td width="150px;" class="YellowBar"></td>
				<td class="ms-wptitle">Yellow bar = 50-99% target achieved</td>
			</tr>
			<tr>
				<td width="40%"></td>
				<td width="150px;" class="RedBar"></td>
				<td class="ms-wptitle">Red bar = &lt;50% target achieved</td>
			</tr>
		</table>


	</xsl:template>


	<xsl:template name="showBar">
		<xsl:param name="Target" />
		<xsl:param name="ItemCount" />
		<xsl:param name="ColumnTitle" />
		<xsl:param name="ItemSum" />

		<!-- For each time we call the showBar template, we'll output a full row into the table formatted accordingly.
		
			The first part will show the name of the Sales Manager, The number of sales, The total value and the % on target
			for the month. e.g. Chris : 2 : £9,356 (45%)
	
			First we calculate the percentile values that we need, then output the legend field for the row. -->
		
		<xsl:variable name="percentValue" select="$ItemSum div $Target" />
		<xsl:variable name="percentTotal" select="round($percentValue*100)+1" />

		<tr>
			<td class="ms-formbody" width="15%" style="vertical-align:middle" nowrap="nowrap">
				<span style="font-weight:600;">
					<xsl:value-of select="$ColumnTitle" />
				</span> :
				<xsl:value-of select="$ItemCount" /> :
				<xsl:value-of select="format-number($ItemSum,'£#,###,##0')"/>
				<xsl:text xmlns:ddwrt="http://schemas.microsoft.com/WebParts/v2/DataView/runtime" ddwrt:nbsp-preserve="yes" disable-output-escaping="yes">&amp;nbsp; </xsl:text>(

				<xsl:call-template name="percentformat">
					<xsl:with-param name="percent" select="$percentValue"/>
				</xsl:call-template>
				)
			</td>
			
			<!-- We now take the value of the percentage returned above and use it in an XSL:IF statement to output the required
				colour bar for the chart.-->
			
			<td>
				<table width="100%" >
					<tr>
						<xsl:if test="$percentTotal &gt;= 100">
							<td width="{$percentTotal}%" height="15px" class="GreenBar" >
								<xsl:text xmlns:ddwrt="http://schemas.microsoft.com/WebParts/v2/DataView/runtime" ddwrt:nbsp-preserve="yes" disable-output-escaping="yes">&amp;nbsp;</xsl:text>
							</td>
						</xsl:if>

						<xsl:if test="($percentTotal &lt;100) and ($percentTotal &gt;= 50)">
							<td width="{$percentTotal}%" height="15px" class="YellowBar">
								<xsl:text xmlns:ddwrt="http://schemas.microsoft.com/WebParts/v2/DataView/runtime" ddwrt:nbsp-preserve="yes" disable-output-escaping="yes">&amp;nbsp;</xsl:text>
							</td>
						</xsl:if>

						<xsl:if test="$percentTotal &lt;50">
							<td width="{$percentTotal}%" height="15px" class="RedBar">
								<xsl:text xmlns:ddwrt="http://schemas.microsoft.com/WebParts/v2/DataView/runtime" ddwrt:nbsp-preserve="yes" disable-output-escaping="yes">&amp;nbsp;</xsl:text>
							</td>
						</xsl:if>

						<!-- And finally a small spacer to fill up the remaining space in the row.-->
						<td width="100%" >
							<xsl:text xmlns:ddwrt="http://schemas.microsoft.com/WebParts/v2/Data