Advertisement
raks13

Untitled

Feb 20th, 2014
223
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. <xsl:template name="validated">
  2.     <!-- error variable collect all errors finding in calendars -->
  3.     <xsl:variable name="error">
  4.     <!-- loop consultant by consultant -->
  5.     <xsl:variable name="query" select="/workfile/query" />
  6.     <xsl:for-each select="/workfile/calendar-list/calendar[@id=/workfile/query/consultant/@calendar-id]">
  7.         <xsl:variable name="calendar-id" select="@id" />
  8.         <xsl:variable name="event" select="./items/event" />
  9.         <xsl:variable name="datesMois">
  10.             <xsl:call-template name="dayOfMonth">
  11.                 <xsl:with-param name="pDay" select="01" />
  12.                 <xsl:with-param name="pMonth" select="/workfile/query/@month" />
  13.                 <xsl:with-param name="pYear" select="/workfile/query/@year" />         
  14.             </xsl:call-template>
  15.         </xsl:variable>
  16.         <xsl:for-each select="tokenize($datesMois,',')">
  17.             <xsl:variable name="dateJour" select="." />
  18.             <xsl:if test="not ($dateJour=$query/bank-holiday/@date)">
  19.                 <xsl:choose>
  20.                     <xsl:when test="$event[substring-before(start/datetime, 'T')=$dateJour]">
  21.                         <xsl:for-each select="$event[substring-before(start/datetime, 'T')=$dateJour]">
  22.                             <xsl:variable name="currentevent" select="." />
  23.                             <xsl:variable name="position" select="position()" />
  24.                             <xsl:variable name="currentcustomer" select="upper-case(summary)" />
  25.                                    
  26.                             <xsl:choose>
  27.                                 <xsl:when test="(upper-case($currentcustomer)=/workfile/query/customer/task/@code) and not(upper-case($currentcustomer)=/workfile/query/customer/@id) or(/workfile/query/consultant[$calendar-id=@calendar-id]/@code=/workfile/query/customer[task/@code=$currentcustomer and @internal='false']/task[@code=$currentcustomer]/pricing/@consultant-code)
  28. and not(upper-case($currentcustomer)=/workfile/query/customer[@internal='true']/task/@code)">
  29.  
  30. <!-- If the summary equal one of the customer code, we check after the description --> 
  31. <!-- If description is empty => error -->
  32.                                     <xsl:variable name="description" select="description" />
  33.                                     <xsl:if test="(not($description) or $description='') and not ($currentcustomer=/workfile/query/customer[@internal='true']/task/@code)">
  34. <!-- the description is not needed if the summary equal one of the internal codes -->
  35.                                         <xsl:text>ERROR_EMPTY_DESC;</xsl:text>
  36.                                         <xsl:value-of select="substring-before(start/datetime, 'T')" />
  37.                                         <xsl:text>;</xsl:text>
  38.                                         <xsl:value-of select="$currentcustomer" />
  39.                                         <xsl:text>;</xsl:text>
  40.                                         <xsl:value-of select="/workfile/query/consultant[@calendar-id=$calendar-id]/@code" />
  41.                                         <xsl:text>;</xsl:text>
  42.                                         <xsl:value-of select="html-link" />
  43.                                         <xsl:text>;</xsl:text>
  44.                                         <xsl:value-of select="id" />
  45.                                         <xsl:text>;</xsl:text>
  46.                                         <xsl:value-of select="$calendar-id" />
  47.                                         <xsl:text>;</xsl:text>
  48.                                     </xsl:if>
  49.                                        
  50. <!-- If description is not empty, we check if the amount of work hour is correct -->
  51.                                     <xsl:variable name="current-event" select="." />
  52.                                     <xsl:variable name="recurrence" select="recurrences/recurrence" />
  53.                                     <xsl:variable name="startdate" select="substring-before(start/datetime, 'T')" />
  54.                                     <xsl:variable name="enddate" select="substring-before(end/datetime, 'T')" />
  55.                                     <xsl:variable name="prevdate" select="substring-before(/workfile/calendar-list/calendar[$calendar-id=@id]/items/event[number($position)-1]/start/datetime,'T')" />
  56.                                     <xsl:variable name="startminute" select="minutes-from-dateTime(xs:dateTime(start/datetime))" />
  57.                                     <xsl:variable name="endminute" select="minutes-from-dateTime(xs:dateTime(end/datetime))" />
  58.                                     <xsl:if test="$startminute mod 15 or ($endminute mod 15)">
  59.                                         <xsl:text>ERROR_EVENT_DURATION;</xsl:text>
  60.                                         <xsl:value-of select="substring-before(start/datetime,'T')" />
  61.                                         <xsl:text>;</xsl:text>
  62.                                         <xsl:value-of select="$currentcustomer" />
  63.                                         <xsl:text>;</xsl:text>
  64.                                         <xsl:value-of
  65. select="/workfile/query/consultant[@calendar-id=$calendar-id]/@code" />
  66.                                         <xsl:text>;</xsl:text>
  67.                                         <xsl:value-of select="html-link" />
  68.                                         <xsl:text>;</xsl:text>
  69.                                         <xsl:value-of select="id" />
  70.                                         <xsl:text>;</xsl:text>
  71.                                         <xsl:value-of select="$calendar-id" />
  72.                                         <xsl:text>;</xsl:text>
  73.                                     </xsl:if>
  74. <!-- If the event start on a day and end the same day = OK -->
  75.                                     <xsl:if test="not($startdate=$enddate)">
  76.                                         <xsl:text>ERROR_EVENT_DATE_OVERFLOW;</xsl:text>
  77.                                         <xsl:value-of select="substring-before(start/datetime,'T')" />
  78.                                         <xsl:text>;</xsl:text>
  79.                                         <xsl:value-of select="$currentcustomer" />
  80.                                         <xsl:text>;</xsl:text>
  81.                                         <xsl:value-of
  82. select="/workfile/query/consultant[@calendar-id=$calendar-id]/@code" />
  83.                                         <xsl:text>;</xsl:text>
  84.                                         <xsl:value-of select="html-link" />
  85.                                         <xsl:text>;</xsl:text>
  86.                                         <xsl:value-of select="id" />
  87.                                         <xsl:text>;</xsl:text>
  88.                                         <xsl:value-of select="$calendar-id" />
  89.                                         <xsl:text>;</xsl:text>
  90.                                     </xsl:if>
  91. <!-- If the event is not recurring = OK -->
  92.                                     <xsl:if test="not(empty($recurrence))">
  93.                                         <xsl:text>ERROR_EVENT_RECURRENCE;</xsl:text>
  94.                                         <xsl:value-of select="substring-before(start/datetime,'T')" />
  95.                                         <xsl:text>;</xsl:text>
  96.                                         <xsl:value-of select="$currentcustomer" />
  97.                                         <xsl:text>;</xsl:text>
  98.                                         <xsl:value-of
  99. select="/workfile/query/consultant[@calendar-id=$calendar-id]/@code" />
  100.                                         <xsl:text>;</xsl:text>
  101.                                         <xsl:value-of select="html-link" />
  102.                                         <xsl:text>;</xsl:text>
  103.                                         <xsl:value-of select="id" />
  104.                                         <xsl:text>;</xsl:text>
  105.                                         <xsl:value-of select="$calendar-id" />
  106.                                         <xsl:text>;</xsl:text>
  107.                                     </xsl:if>
  108. <!-- If the event start on a day and end on another day => error -->
  109.                                     <xsl:variable name="total">
  110.                                         <xsl:if test="not($prevdate=$startdate)">
  111.                                             <xsl:call-template name="sum">
  112.                                                 <xsl:with-param name="events" select="/workfile/calendar-list/calendar[@id=$calendar-id]/items/event[substring-before(start/datetime,'T')=$startdate and substring-before(start/datetime,'T')=substring-before(end/datetime,'T') and upper-case(summary)=/workfile/query/customer/task/@code]" />
  113.                                             </xsl:call-template>
  114.                                         </xsl:if>
  115.                                     </xsl:variable>
  116.                        
  117. <!-- we don't check if work hour is correct for the second, third, etc. event of the day -->
  118.                                     <xsl:if test="not($prevdate=$startdate)">
  119. <!-- If amount of work hour is not correct => error -->
  120.                                         <xsl:if test="not($current-event/custom-elements/day-of-week/@index-day-of-week='5') and not($current-event/custom-elements/day-of-week/@index-day-of-week='6') and not($startdate=/workfile/query/bank-holiday/@date) and (number($total) &gt; number(/workfile/query/parameter[@name='work-hour-max']/@value) or number($total) &lt; number(/workfile/query/parameter[@name='work-hour-min']/@value))">
  121.                                             <xsl:text>ERROR_WORK_HOUR;</xsl:text>
  122.                                             <xsl:value-of select="substring-before(start/datetime,'T')" />
  123.                                             <xsl:text>;</xsl:text>
  124.                                             <xsl:value-of select="$currentcustomer" />
  125.                                             <xsl:text>;</xsl:text>
  126.                                             <xsl:value-of select="/workfile/query/consultant[@calendar-id=$calendar-id]/@code" />
  127.                                             <xsl:text>;</xsl:text>
  128.                                             <xsl:value-of select="html-link" />
  129.                                             <xsl:text>;</xsl:text>
  130.                                             <xsl:value-of select="id" />
  131.                                             <xsl:text>;</xsl:text>
  132.                                             <xsl:value-of select="$calendar-id" />
  133.                                             <xsl:text>;</xsl:text>
  134.                                         </xsl:if>
  135.                                     </xsl:if>
  136.                                 </xsl:when>
  137.                                 <xsl:when test="$currentcustomer and $currentcustomer!=''">                                    
  138.                                     <xsl:text>ERROR_UNKNOWN_CODE;</xsl:text>
  139.                                     <xsl:value-of select="substring-before(start/datetime,'T')" />
  140.                                     <xsl:text>;</xsl:text>
  141.                                     <xsl:value-of select="$currentcustomer" />
  142.                                     <xsl:text>;</xsl:text>
  143.                                     <xsl:value-of select="/workfile/query/consultant[@calendar-id=$calendar-id]/@code" />
  144.                                     <xsl:text>;</xsl:text>
  145.                                     <xsl:value-of select="html-link" />
  146.                                     <xsl:text>;</xsl:text>
  147.                                     <xsl:value-of select="id" />
  148.                                     <xsl:text>;</xsl:text>
  149.                                     <xsl:value-of select="$calendar-id" />
  150.                                     <xsl:text>;</xsl:text>
  151.                                 </xsl:when>
  152.                             </xsl:choose>
  153.                                                    
  154.                         </xsl:for-each>
  155.                     </xsl:when>
  156.                     <xsl:otherwise>
  157.                         <xsl:text>ERROR_EVENT_NOT_FOUND;</xsl:text>
  158.                         <xsl:value-of select="$dateJour" />
  159.                         <xsl:text>;</xsl:text>
  160.                         <xsl:text>no-customer;</xsl:text>
  161.                         <xsl:value-of select="/workfile/query/consultant[@calendar-id=$calendar-id]/@code" />
  162.                         <xsl:text>;</xsl:text>
  163.                         <xsl:text>no-link;</xsl:text>
  164.                         <xsl:value-of select="id" />
  165.                         <xsl:text>;</xsl:text>
  166.                         <xsl:value-of select="$calendar-id" />
  167.                         <xsl:text>;</xsl:text>
  168.                     </xsl:otherwise>
  169.                 </xsl:choose>              
  170.             </xsl:if>
  171.         </xsl:for-each>
  172.     </xsl:for-each>
  173. </xsl:variable>
  174.  
  175. <xsl:if test="$error">
  176.     <xsl:value-of select="$error" />
  177. </xsl:if>
  178.  
  179. </xsl:template>
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement