SHOW:
|
|
- or go back to the newest paste.
1 | <?xml version="1.0" encoding="UTF-8"?> | |
2 | <xsl:stylesheet version="2.0" xmlns:xsl="http://www.w3.org/1999/XSL/Transform"> | |
3 | <xsl:output method="xml" encoding="utf-8" indent="yes" /> | |
4 | ||
5 | <xsl:template name="css"> | |
6 | <style> | |
7 | <xsl:attribute name="type"> | |
8 | <xsl:text>text/css</xsl:text> | |
9 | </xsl:attribute> | |
10 | <xsl:text>table{border-collapse: collapse;font-size: 11px;font-family: Arial;border-spacing: 0px;}caption{text-align:left;}td,th{border: 1px solid black;}.date{width:100px;white-space:nowrap;}.number{text-align:right;}#footer{font-size:11px;}#signature{font-size:11px;}</xsl:text> | |
11 | ||
12 | </style> | |
13 | </xsl:template> | |
14 | ||
15 | <xsl:template name="header"> | |
16 | <xsl:param name="title" /> | |
17 | <xsl:param name="name" /> | |
18 | <xsl:param name="surname" /> | |
19 | <xsl:param name="text" /> | |
20 | ||
21 | <p><xsl:value-of select="$title" /><xsl:text> </xsl:text> <xsl:value-of select="$name" /><xsl:text> </xsl:text> <xsl:value-of select="$surname" /><xsl:text>,</xsl:text></p><!-- mettre maj a la premiere lettre --> | |
22 | ||
23 | <p>Veuillez trouver ci-dessous <xsl:value-of select="$text" /></p> | |
24 | ||
25 | </xsl:template> | |
26 | ||
27 | <xsl:template name="footer"> | |
28 | ||
29 | <div id="footer"> | |
30 | <p><xsl:text>Cet email vous est envoyé automatiquement par le système de prestations ICTCG.</xsl:text></p> | |
31 | <p><xsl:text>En cas de question, n'hésitez pas à nous contacter.</xsl:text></p> | |
32 | </div> | |
33 | ||
34 | </xsl:template> | |
35 | ||
36 | <xsl:template name="signature"> | |
37 | <div id="signature"> | |
38 | <p>---</p> | |
39 | <p>ICTCG s.a / GWEB sprl</p> | |
40 | <p>http://www.ictcg.com / http://www.gweb.be</p> | |
41 | <p>+352.27.86.21.00 / +32.4.345.05.42</p> | |
42 | </div> | |
43 | ||
44 | </xsl:template> | |
45 | ||
46 | </xsl:stylesheet> | |
47 | ||
48 | ------ | |
49 | ||
50 | <?xml version="1.0" encoding="UTF-8"?> | |
51 | <xsl:stylesheet version="2.0" xmlns:xsl="http://www.w3.org/1999/XSL/Transform" | |
52 | xmlns:xs="http://www.w3.org/2001/XMLSchema"> | |
53 | <xsl:import href="generate-mail-template.xsl" /> | |
54 | <xsl:output method="xml" encoding="utf-8" indent="yes" /> | |
55 | ||
56 | <!-- take a list of event and calculate the global amount --> | |
57 | <xsl:template name="sum"> | |
58 | <xsl:param name="events" /> | |
59 | <xsl:param name="sum" select="0" /> | |
60 | ||
61 | <xsl:variable name="curr" select="$events[1]" /> | |
62 | ||
63 | <xsl:choose> | |
64 | <!-- If there's at least one event on the list, we calculate its duration and give it the the sum variable --> | |
65 | <!-- and call this template until there's no more event on the list --> | |
66 | <xsl:when test="$curr"> | |
67 | <xsl:variable name="start" select="$curr/start/datetime" /> | |
68 | <xsl:variable name="end" select="$curr/end/datetime" /> | |
69 | <xsl:variable name="starthour" select="hours-from-dateTime($start)" /> | |
70 | <xsl:variable name="endhour" select="hours-from-dateTime($end)" /> | |
71 | ||
72 | <xsl:variable name="eventduration" select="$sum + ($endhour - $starthour)" /> | |
73 | ||
74 | <xsl:call-template name="sum"> | |
75 | <xsl:with-param name="events" select="$events[position() > 1]" /> | |
76 | <xsl:with-param name="sum" select="$eventduration" /> | |
77 | </xsl:call-template> | |
78 | </xsl:when> | |
79 | <!-- If there's no more event we return the calculated sum --> | |
80 | <xsl:otherwise> | |
81 | <xsl:value-of select="$sum" /> | |
82 | </xsl:otherwise> | |
83 | </xsl:choose> | |
84 | </xsl:template> | |
85 | ||
86 | <!-- called template in generate-main --> | |
87 | <xsl:template name="leaves"> | |
88 | <leaves> | |
89 | <!-- to be detected by the servlet, mails must be in an 'emails' node --> | |
90 | <emails> | |
91 | <email> | |
92 | <head> | |
93 | <subject><xsl:text>ICTCG - </xsl:text><xsl:value-of select="/workfile/query/@year" /><xsl:text>-</xsl:text><xsl:value-of select="/workfile/query/@month" /><xsl:text> - Timesheet - Leaves</xsl:text></subject> | |
94 | <from><xsl:value-of select="/workfile/query/parameter[@name='sender-mail']/@value" /></from> | |
95 | <recipient><xsl:value-of select="/workfile/query/customer[@internal='true']/email[@type='production']/@address" /></recipient> | |
96 | <cc><xsl:value-of select="/workfile/query/customer[@internal='true']/email[@type='production']/@cc" /></cc> | |
97 | </head> | |
98 | <body> | |
99 | <xsl:attribute name="type"> | |
100 | <xsl:text>text/xhtml</xsl:text> | |
101 | </xsl:attribute> | |
102 | <html> | |
103 | <head> | |
104 | <xsl:call-template name="css" /> | |
105 | </head> | |
106 | <body> | |
107 | <!-- call the template header to write the header of mail body (see generate-mail-template.xsl) --> | |
108 | <xsl:variable name="text"> | |
109 | <xsl:text>le tableau journalier des absences, ainsi que le tableau récapitulatif pour le mois:</xsl:text> | |
110 | </xsl:variable> | |
111 | <xsl:call-template name="header"> | |
112 | <xsl:with-param name="title" select="/workfile/query/customer[@internal='true']/email[@type='admin']/@title" /> | |
113 | <xsl:with-param name="name" select="/workfile/query/customer[@internal='true']/email[@type='admin']/@name" /> | |
114 | <xsl:with-param name="surname" select="/workfile/query/customer[@internal='true']/email[@type='admin']/@surname" /> | |
115 | <xsl:with-param name="text" select="$text" /> | |
116 | </xsl:call-template> | |
117 | ||
118 | <!-- table for the daily recap --> | |
119 | <table> | |
120 | <caption><i>Récapitulatif journalier</i></caption> | |
121 | <tr> | |
122 | <th>Date</th> | |
123 | <th>Jour</th> | |
124 | <th>Consultant</th> | |
125 | <th>Client</th> | |
126 | <th>Type</th> | |
127 | <th class="number">Dur�E9;e (h)</th> | |
128 | </tr> | |
129 | ||
130 | <!-- to sort correctly by date, first, we write in several tr the recap --> | |
131 | <!-- then we apply a template to sort correctly this result --> | |
132 | <xsl:variable name="vPass1"> | |
133 | <unsortedLines> | |
134 | <!-- for each customer where is considered like internal and where their task has an amount of hours bigger than 0 --> | |
135 | <xsl:for-each select="/workfile/timesheet/customers/customer[@id=/workfile/query/customer[@internal='true']/@id]/task[@hours > 0]"> | |
136 | <xsl:for-each select="consultant"> | |
137 | <xsl:variable name="customer" select="../.." /> | |
138 | <xsl:variable name="task" select=".." /> | |
139 | <xsl:variable name="consultant" select="." /> | |
140 | <!-- we're going to calculate the amount of hours for a task considered all events for this day --> | |
141 | <xsl:for-each select="/workfile/calendar-list/calendar[@id=$consultant/@calendar-id] | |
142 | /items/event[upper-case(summary)=$task/@code]"> | |
143 | <xsl:variable name="position" select="position()" /> | |
144 | <xsl:variable name="startDate" select="substring-before(start/datetime,'T')" /> | |
145 | <xsl:variable name="task-code" select="summary" /> | |
146 | <!-- 'previousevents' is used to know if this event is the first of the day for a task --> | |
147 | <!-- if it's not, we've already calculate the amount of this task for this day and show it on the table --> | |
148 | <xsl:variable name="previousevents" select="preceding-sibling::event[$startDate=substring-before(start/datetime,'T') | |
149 | and upper-case(summary)=$task-code | |
150 | and position() < $position]" /> | |
151 | <xsl:variable name="events" select="/workfile/calendar-list/calendar[@id=$consultant/@calendar-id] | |
152 | /items/event[upper-case(summary)=$task/@code | |
153 | and substring-before(start/datetime,'T')=$startDate]" /> | |
154 | <xsl:variable name="result"> | |
155 | <xsl:call-template name="sum"> | |
156 | <xsl:with-param name="events" select="$events" /> | |
157 | </xsl:call-template> | |
158 | </xsl:variable> | |
159 | <xsl:if test="not($previousevents or $previousevents='')"> | |
160 | <xsl:if test="$result > 0"> | |
161 | <tr> | |
162 | <td class="startdate"><xsl:value-of select="$startDate" /></td> | |
163 | <td><xsl:value-of select="custom-elements/day-of-week[@lang='FR']" /></td> | |
164 | <td><xsl:value-of select="$consultant/@code" /></td> | |
165 | <td><xsl:value-of select="$customer/@id" /></td> | |
166 | <td><xsl:value-of select="upper-case(summary)" /></td> | |
167 | <td style="text-align:right;"><xsl:value-of select="format-number($result, '#.00')" /></td> | |
168 | </tr> | |
169 | </xsl:if> | |
170 | </xsl:if> | |
171 | </xsl:for-each> | |
172 | </xsl:for-each> | |
173 | </xsl:for-each> | |
174 | </unsortedLines> | |
175 | </xsl:variable> | |
176 | <!-- we call the sorting template --> | |
177 | <!-- and transform the result in 'unsortedLines --> | |
178 | <xsl:apply-templates select="$vPass1/*" /> | |
179 | ||
180 | </table> | |
181 | <p></p> | |
182 | <!-- recap for the month --> | |
183 | <table> | |
184 | <xsl:attribute name="border"> | |
185 | <xsl:text>1</xsl:text> | |
186 | </xsl:attribute> | |
187 | <caption><i>Résumé du mois</i></caption> | |
188 | <tr> | |
189 | <th>Client</th> | |
190 | <th>Consultant</th> | |
191 | <th>Type</th> | |
192 | <th class="number">Durée (h)</th> | |
193 | </tr> | |
194 | ||
195 | <!-- for each customer where is considered like internal and where their task has an amount of hours bigger than 0 --> | |
196 | <xsl:for-each select="/workfile/timesheet/customers/customer[@id=/workfile/query/customer[@internal='true']/@id] | |
197 | /task[@hours > 0]"> | |
198 | <xsl:variable name="taskcodetwo" select="./@code" /> | |
199 | <xsl:for-each select="consultant"> | |
200 | <xsl:variable name="cons" select="." /> | |
201 | <xsl:variable name="event-list" select="/workfile/calendar-list/calendar[@id=$cons/@calendar-id]/items | |
202 | /event[upper-case(summary)=$taskcodetwo]" /> | |
203 | <xsl:variable name="total"> | |
204 | <xsl:call-template name="sum"> | |
205 | <xsl:with-param name="events" select="$event-list" /> | |
206 | </xsl:call-template> | |
207 | </xsl:variable> | |
208 | <!-- we only show table line for tasks bigger than 0 --> | |
209 | <xsl:if test="$total > 0"> | |
210 | <tr> | |
211 | <td><xsl:value-of select="../../@id" /></td> | |
212 | <td><xsl:value-of select="@code" /></td> | |
213 | <td><xsl:value-of select="../@code" /></td> | |
214 | <td class="number"><xsl:value-of select="format-number($total, '#.00')" /></td> | |
215 | </tr> | |
216 | </xsl:if> | |
217 | </xsl:for-each> | |
218 | </xsl:for-each> | |
219 | </table> | |
220 | <p></p> | |
221 | <xsl:call-template name="footer" /> | |
222 | <xsl:call-template name="signature" /> | |
223 | ||
224 | </body> | |
225 | </html> | |
226 | </body> | |
227 | </email> | |
228 | </emails> | |
229 | </leaves> | |
230 | ||
231 | </xsl:template> | |
232 | ||
233 | <!-- sorting template --> | |
234 | <xsl:template match="unsortedLines"> | |
235 | <xsl:perform-sort select="*"> | |
236 | <xsl:sort select="day-from-date(xs:date(td[@class='startdate']))" /> | |
237 | </xsl:perform-sort> | |
238 | </xsl:template> | |
239 | ||
240 | </xsl:stylesheet> |