raks13

Untitled

Feb 19th, 2014
114
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 12.00 KB | None | 0 0
  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:variable name="event" select="/workfile/calendar-list/calendar[@id=/workfile/query/consultant/@calendar-id]/items/event" />
  7. <xsl:variable name="startdatetime" select="substring-before($event/start/datetime, 'T')" />
  8. <xsl:for-each
  9. select="/workfile/calendar-list/calendar[@id=/workfile/query/consultant/@calendar-id]">
  10. <xsl:variable name="calendar-id" select="@id" />
  11. <xsl:variable name="datesMois">
  12. <xsl:call-template name="dayOfMonth">
  13. <xsl:with-param name="pDay" select="01" />
  14. <xsl:with-param name="pMonth" select="/workfile/query/@month" />
  15. <xsl:with-param name="pYear" select="/workfile/query/@year" />
  16. </xsl:call-template>
  17. </xsl:variable>
  18. <xsl:for-each select="tokenize($datesMois,',')">
  19. <xsl:variable name="dateJour" select="." />
  20. <xsl:if test="not ($dateJour=$query/bank-holiday/@date)">
  21. <xsl:choose>
  22. <xsl:when test="$dateJour = $startdatetime">
  23. <xsl:for-each select="$event[substring-before(start/datetime, 'T')=$dateJour]">
  24. <xsl:variable name="currentevent" select="." />
  25. <xsl:variable name="position" select="position()" />
  26. <xsl:variable name="currentcustomer" select="upper-case(summary)" />
  27.  
  28. <xsl:choose>
  29. <xsl:when test="(upper-case($currentcustomer)=$query/customer/task/@code) and not(upper-case($currentcustomer)=$query/customer/@id)
  30. or($query/consultant[$calendar-id=@calendar-id]/@code=
  31. $query/customer[task/@code=$currentcustomer and @internal='false']
  32. /task[@code=$currentcustomer]/pricing/@consultant-code)
  33. and not(upper-case($currentcustomer)=$query/customer[@internal='true']/task/@code)">
  34. <!-- If the summary equal one of the customer code, we check after the
  35. description -->
  36.  
  37. <!-- If description is empty => error -->
  38. <xsl:variable name="description" select="description" />
  39. <xsl:if test="(not($description) or $description='')
  40. and not ($currentcustomer=/workfile/query/customer[@internal='true']/task/@code)">
  41. <!-- the description is not needed if the summary equal one of the internal codes -->
  42. <xsl:text>ERROR_EMPTY_DESC;</xsl:text>
  43. <xsl:value-of select="substring-before(start/datetime, 'T')" />
  44. <xsl:text>;</xsl:text>
  45. <xsl:value-of select="$currentcustomer" />
  46. <xsl:text>;</xsl:text>
  47. <xsl:value-of
  48. select="/workfile/query/consultant[@calendar-id=$calendar-id]/@code" />
  49. <xsl:text>;</xsl:text>
  50. <xsl:value-of select="html-link" />
  51. <xsl:text>;</xsl:text>
  52. <xsl:value-of select="id" />
  53. <xsl:text>;</xsl:text>
  54. <xsl:value-of select="$calendar-id" />
  55. <xsl:text>;</xsl:text>
  56. </xsl:if>
  57.  
  58.  
  59. <!-- If description is not empty, we check if the amount of work hour
  60. is correct -->
  61. <xsl:variable name="current-event" select="." />
  62. <xsl:variable name="recurrence" select="recurrences/recurrence" />
  63. <xsl:variable name="startdate" select="substring-before(start/datetime, 'T')" />
  64. <xsl:variable name="enddate" select="substring-before(end/datetime, 'T')" />
  65. <xsl:variable name="prevdate"
  66. select="substring-before(/workfile/calendar-list/calendar[$calendar-id=@id]
  67. /items/event[number($position)-1]/start/datetime,'T')" />
  68. <xsl:variable name="startminute"
  69. select="minutes-from-dateTime(xs:dateTime(start/datetime))" />
  70. <xsl:variable name="endminute"
  71. select="minutes-from-dateTime(xs:dateTime(end/datetime))" />
  72. <xsl:if
  73. test="$startminute mod 15
  74. or ($endminute mod 15)">
  75.  
  76. <xsl:text>ERROR_EVENT_DURATION;</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.  
  91. </xsl:if>
  92. <!-- If the event start on a day and end the same day = OK -->
  93. <xsl:if test="not($startdate=$enddate)">
  94. <xsl:text>ERROR_EVENT_DATE_OVERFLOW;</xsl:text>
  95. <xsl:value-of select="substring-before(start/datetime,'T')" />
  96. <xsl:text>;</xsl:text>
  97. <xsl:value-of select="$currentcustomer" />
  98. <xsl:text>;</xsl:text>
  99. <xsl:value-of
  100. select="/workfile/query/consultant[@calendar-id=$calendar-id]/@code" />
  101. <xsl:text>;</xsl:text>
  102. <xsl:value-of select="html-link" />
  103. <xsl:text>;</xsl:text>
  104. <xsl:value-of select="id" />
  105. <xsl:text>;</xsl:text>
  106. <xsl:value-of select="$calendar-id" />
  107. <xsl:text>;</xsl:text>
  108. </xsl:if>
  109. <!-- If the event is not recurring = OK -->
  110. <xsl:if test="not(empty($recurrence))">
  111. <xsl:text>ERROR_EVENT_RECURRENCE;</xsl:text>
  112. <xsl:value-of select="substring-before(start/datetime,'T')" />
  113. <xsl:text>;</xsl:text>
  114. <xsl:value-of select="$currentcustomer" />
  115. <xsl:text>;</xsl:text>
  116. <xsl:value-of
  117. select="/workfile/query/consultant[@calendar-id=$calendar-id]/@code" />
  118. <xsl:text>;</xsl:text>
  119. <xsl:value-of select="html-link" />
  120. <xsl:text>;</xsl:text>
  121. <xsl:value-of select="id" />
  122. <xsl:text>;</xsl:text>
  123. <xsl:value-of select="$calendar-id" />
  124. <xsl:text>;</xsl:text>
  125. </xsl:if>
  126. <!-- If the event start on a day and end on another day => error -->
  127. <xsl:variable name="total">
  128. <xsl:if test="not($prevdate=$startdate)">
  129. <xsl:call-template name="sum">
  130. <xsl:with-param name="events"
  131. select="/workfile/calendar-list/calendar[@id=$calendar-id]
  132. /items/event[substring-before(start/datetime,'T')=$startdate
  133. and substring-before(start/datetime,'T')=substring-before(end/datetime,'T')
  134. and upper-case(summary)=/workfile/query/customer/task/@code]" />
  135. </xsl:call-template>
  136. </xsl:if>
  137. </xsl:variable>
  138.  
  139. <!-- we don't check if work hour is correct for the second, third, etc.
  140. event of the day -->
  141. <xsl:if test="not($prevdate=$startdate)">
  142. <!-- If amount of work hour is not correct => error -->
  143. <xsl:if
  144. test="not($current-event/custom-elements/day-of-week/@index-day-of-week='5')
  145. and not($current-event/custom-elements/day-of-week/@index-day-of-week='6')
  146. and not($startdate=/workfile/query/bank-holiday/@date)
  147. and (number($total) &gt; number(/workfile/query/parameter[@name='work-hour-max']/@value)
  148. or number($total) &lt; number(/workfile/query/parameter[@name='work-hour-min']/@value))">
  149. <xsl:text>ERROR_WORK_HOUR;</xsl:text>
  150. <xsl:value-of select="substring-before(start/datetime,'T')" />
  151. <xsl:text>;</xsl:text>
  152. <xsl:value-of select="$currentcustomer" />
  153. <xsl:text>;</xsl:text>
  154. <xsl:value-of
  155. select="/workfile/query/consultant[@calendar-id=$calendar-id]/@code" />
  156. <xsl:text>;</xsl:text>
  157. <xsl:value-of select="html-link" />
  158. <xsl:text>;</xsl:text>
  159. <xsl:value-of select="id" />
  160. <xsl:text>;</xsl:text>
  161. <xsl:value-of select="$calendar-id" />
  162. <xsl:text>;</xsl:text>
  163. </xsl:if>
  164. </xsl:if>
  165. </xsl:when>
  166. <xsl:when test="$currentcustomer and $currentcustomer!=''">
  167. <xsl:text>ERROR_UNKNOWN_CODE;</xsl:text>
  168. <xsl:value-of select="substring-before(start/datetime,'T')" />
  169. <xsl:text>;</xsl:text>
  170. <xsl:value-of select="$currentcustomer" />
  171. <xsl:text>;</xsl:text>
  172. <xsl:value-of
  173. select="/workfile/query/consultant[@calendar-id=$calendar-id]/@code" />
  174. <xsl:text>;</xsl:text>
  175. <xsl:value-of select="html-link" />
  176. <xsl:text>;</xsl:text>
  177. <xsl:value-of select="id" />
  178. <xsl:text>;</xsl:text>
  179. <xsl:value-of select="$calendar-id" />
  180. <xsl:text>;</xsl:text>
  181. </xsl:when>
  182. </xsl:choose>
  183.  
  184. </xsl:for-each>
  185.  
  186. </xsl:when>
  187. <xsl:otherwise>
  188. <xsl:text>ERROR_EVENT_NOT_FOUND;</xsl:text>
  189. <xsl:value-of select="$dateJour" />
  190. <xsl:text>;</xsl:text>
  191. <xsl:text>no-customer;</xsl:text>
  192. <xsl:value-of
  193. select="/workfile/query/consultant[@calendar-id=$calendar-id]/@code" />
  194. <xsl:text>;</xsl:text>
  195. <xsl:text>no-link;</xsl:text>
  196. <xsl:value-of select="id" />
  197. <xsl:text>;</xsl:text>
  198. <xsl:value-of select="$calendar-id" />
  199. <xsl:text>;</xsl:text>
  200. </xsl:otherwise>
  201. </xsl:choose>
  202.  
  203. </xsl:if>
  204.  
  205. </xsl:for-each>
  206. </xsl:for-each>
  207.  
  208.  
  209. <!-- VERIFICATION FOR EMPTY WORK DAY -->
  210. <!-- <xsl:variable name="startdate" -->
  211. <!-- select="substring-before(/workfile/calendar-list/ -->
  212. <!-- calendar[$calendar-id=@id]/items/ -->
  213. <!-- event[1]/start/datetime, 'T')" /> -->
  214.  
  215. <!-- <xsl:if test="$startdate and not($startdate='')"> -->
  216. <!-- <xsl:if test="not(day-from-date(xs:date($startdate)) = 01)"> -->
  217. <!-- <xsl:call-template name="check-before-date"> -->
  218. <!-- <xsl:with-param name="date" select="$startdate" /> -->
  219. <!-- <xsl:with-param name="index-day-of-week" -->
  220. <!-- select="string(/workfile/calendar-list/ -->
  221. <!-- calendar[$calendar-id=@id]/items/ -->
  222. <!-- event[1]/custom-elements/day-of-week[@lang='FR']/@index-day-of-week)" /> -->
  223. <!-- <xsl:with-param name="calendar-id" select="$calendar-id" /> -->
  224. <!-- </xsl:call-template> -->
  225. <!-- </xsl:if> -->
  226.  
  227. <!-- <xsl:variable name="days-in-month"> -->
  228. <!-- <xsl:call-template name="last-day-of-month"> -->
  229. <!-- <xsl:with-param name="year" select="/workfile/query/@year" /> -->
  230. <!-- <xsl:with-param name="month" select="/workfile/query/@month" /> -->
  231. <!-- </xsl:call-template> -->
  232. <!-- </xsl:variable> -->
  233. <!-- <xsl:call-template name="check-after-date"> -->
  234. <!-- <xsl:with-param name="date" select="$startdate" /> -->
  235. <!-- <xsl:with-param name="days-of-month" select="$days-in-month" /> -->
  236. <!-- <xsl:with-param name="index-day-of-week" -->
  237. <!-- select="string(/workfile/calendar-list/ -->
  238. <!-- calendar[$calendar-id=@id]/items/ -->
  239. <!-- event[1]/custom-elements/day-of-week[@lang='FR']/@index-day-of-week)" /> -->
  240. <!-- <xsl:with-param name="calendar-id" select="$calendar-id" /> -->
  241. <!-- </xsl:call-template> -->
  242.  
  243. <!-- </xsl:if> -->
  244.  
  245. <!-- END -->
  246.  
  247.  
  248. </xsl:variable>
  249.  
  250. <xsl:if test="$error">
  251. <xsl:value-of select="$error" />
  252. </xsl:if>
  253.  
  254. </xsl:template>
Advertisement
Add Comment
Please, Sign In to add comment