@@ -1,168 +1,169 | |||
|
1 | 1 | <% |
|
2 | 2 | pdf=IfpdfHelper::IFPDF.new |
|
3 | pdf.SetTitle("#{@project.name} - #{l(:label_gantt)}") | |
|
3 | 4 | pdf.AliasNbPages |
|
4 | 5 | pdf.footer_date = format_date(Date.today) |
|
5 | 6 | pdf.AddPage("L") |
|
6 | 7 | pdf.SetFont('Arial','B',12) |
|
7 | 8 | pdf.SetX(15) |
|
8 | 9 | pdf.Cell(70, 20, @project.name) |
|
9 | 10 | pdf.Ln |
|
10 | 11 | pdf.SetFont('Arial','B',9) |
|
11 | 12 | |
|
12 | 13 | subject_width = 70 |
|
13 | 14 | header_heigth = 5 |
|
14 | 15 | |
|
15 | 16 | headers_heigth = header_heigth |
|
16 | 17 | show_weeks = false |
|
17 | 18 | show_days = false |
|
18 | 19 | |
|
19 | 20 | if @months < 7 |
|
20 | 21 | show_weeks = true |
|
21 | 22 | headers_heigth = 2*header_heigth |
|
22 | 23 | if @months < 3 |
|
23 | 24 | show_days = true |
|
24 | 25 | headers_heigth = 3*header_heigth |
|
25 | 26 | end |
|
26 | 27 | end |
|
27 | 28 | |
|
28 | 29 | g_width = 210 |
|
29 | 30 | zoom = (g_width) / (@date_to - @date_from + 1) |
|
30 | 31 | g_height = 120 |
|
31 | 32 | t_height = g_height + headers_heigth |
|
32 | 33 | |
|
33 | 34 | y_start = pdf.GetY |
|
34 | 35 | |
|
35 | 36 | |
|
36 | 37 | # |
|
37 | 38 | # Months headers |
|
38 | 39 | # |
|
39 | 40 | month_f = @date_from |
|
40 | 41 | left = subject_width |
|
41 | 42 | height = header_heigth |
|
42 | 43 | @months.times do |
|
43 | 44 | width = ((month_f >> 1) - month_f) * zoom |
|
44 | 45 | pdf.SetY(y_start) |
|
45 | 46 | pdf.SetX(left) |
|
46 | 47 | pdf.Cell(width, height, "#{month_f.year}-#{month_f.month}", "LTR", 0, "C") |
|
47 | 48 | left = left + width |
|
48 | 49 | month_f = month_f >> 1 |
|
49 | 50 | end |
|
50 | 51 | |
|
51 | 52 | # |
|
52 | 53 | # Weeks headers |
|
53 | 54 | # |
|
54 | 55 | if show_weeks |
|
55 | 56 | left = subject_width |
|
56 | 57 | height = header_heigth |
|
57 | 58 | if @date_from.cwday == 1 |
|
58 | 59 | # @date_from is monday |
|
59 | 60 | week_f = @date_from |
|
60 | 61 | else |
|
61 | 62 | # find next monday after @date_from |
|
62 | 63 | week_f = @date_from + (7 - @date_from.cwday + 1) |
|
63 | 64 | width = (7 - @date_from.cwday + 1) * zoom-1 |
|
64 | 65 | pdf.SetY(y_start + header_heigth) |
|
65 | 66 | pdf.SetX(left) |
|
66 | 67 | pdf.Cell(width + 1, height, "", "LTR") |
|
67 | 68 | left = left + width+1 |
|
68 | 69 | end |
|
69 | 70 | while week_f <= @date_to |
|
70 | 71 | width = (week_f + 6 <= @date_to) ? 7 * zoom : (@date_to - week_f + 1) * zoom |
|
71 | 72 | pdf.SetY(y_start + header_heigth) |
|
72 | 73 | pdf.SetX(left) |
|
73 | 74 | pdf.Cell(width, height, (width >= 5 ? week_f.cweek.to_s : ""), "LTR", 0, "C") |
|
74 | 75 | left = left + width |
|
75 | 76 | week_f = week_f+7 |
|
76 | 77 | end |
|
77 | 78 | end |
|
78 | 79 | |
|
79 | 80 | # |
|
80 | 81 | # Days headers |
|
81 | 82 | # |
|
82 | 83 | if show_days |
|
83 | 84 | left = subject_width |
|
84 | 85 | height = header_heigth |
|
85 | 86 | wday = @date_from.cwday |
|
86 | 87 | pdf.SetFont('Arial','B',7) |
|
87 | 88 | (@date_to - @date_from + 1).to_i.times do |
|
88 | 89 | width = zoom |
|
89 | 90 | pdf.SetY(y_start + 2 * header_heigth) |
|
90 | 91 | pdf.SetX(left) |
|
91 | 92 | pdf.Cell(width, height, day_name(wday)[0,1], "LTR", 0, "C") |
|
92 | 93 | left = left + width |
|
93 | 94 | wday = wday + 1 |
|
94 | 95 | wday = 1 if wday > 7 |
|
95 | 96 | end |
|
96 | 97 | end |
|
97 | 98 | |
|
98 | 99 | pdf.SetY(y_start) |
|
99 | 100 | pdf.SetX(15) |
|
100 | 101 | pdf.Cell(subject_width+g_width-15, headers_heigth, "", 1) |
|
101 | 102 | |
|
102 | 103 | |
|
103 | 104 | # |
|
104 | 105 | # Tasks |
|
105 | 106 | # |
|
106 | 107 | top = headers_heigth + y_start |
|
107 | 108 | pdf.SetFont('Arial','B',7) |
|
108 | 109 | @issues.each do |i| |
|
109 | 110 | pdf.SetY(top) |
|
110 | 111 | pdf.SetX(15) |
|
111 | 112 | pdf.Cell(subject_width-15, 5, "#{i.tracker.name} #{i.id}: #{i.subject}".sub(/^(.{30}[^\s]*\s).*$/, '\1 (...)'), "LR") |
|
112 | 113 | |
|
113 | 114 | pdf.SetY(top) |
|
114 | 115 | pdf.SetX(subject_width) |
|
115 | 116 | pdf.Cell(g_width, 5, "", "LR") |
|
116 | 117 | |
|
117 | 118 | i_start_date = (i.start_date >= @date_from ? i.start_date : @date_from ) |
|
118 | 119 | i_end_date = (i.due_date <= @date_to ? i.due_date : @date_to ) |
|
119 | 120 | |
|
120 | 121 | i_done_date = i.start_date + ((i.due_date - i.start_date+1)*i.done_ratio/100).floor |
|
121 | 122 | i_done_date = (i_done_date <= @date_from ? @date_from : i_done_date ) |
|
122 | 123 | i_done_date = (i_done_date >= @date_to ? @date_to : i_done_date ) |
|
123 | 124 | |
|
124 | 125 | i_late_date = [i_end_date, Date.today].min if i_start_date < Date.today |
|
125 | 126 | |
|
126 | 127 | i_left = ((i_start_date - @date_from)*zoom) |
|
127 | 128 | i_width = ((i_end_date - i_start_date + 1)*zoom) |
|
128 | 129 | d_width = ((i_done_date - i_start_date)*zoom) |
|
129 | 130 | l_width = ((i_late_date - i_start_date+1)*zoom) if i_late_date |
|
130 | 131 | l_width ||= 0 |
|
131 | 132 | |
|
132 | 133 | pdf.SetY(top+1.5) |
|
133 | 134 | pdf.SetX(subject_width + i_left) |
|
134 | 135 | pdf.SetFillColor(200,200,200) |
|
135 | 136 | pdf.Cell(i_width, 2, "", 0, 0, "", 1) |
|
136 | 137 | |
|
137 | 138 | if l_width > 0 |
|
138 | 139 | pdf.SetY(top+1.5) |
|
139 | 140 | pdf.SetX(subject_width + i_left) |
|
140 | 141 | pdf.SetFillColor(255,100,100) |
|
141 | 142 | pdf.Cell(l_width, 2, "", 0, 0, "", 1) |
|
142 | 143 | end |
|
143 | 144 | if d_width > 0 |
|
144 | 145 | pdf.SetY(top+1.5) |
|
145 | 146 | pdf.SetX(subject_width + i_left) |
|
146 | 147 | pdf.SetFillColor(100,100,255) |
|
147 | 148 | pdf.Cell(d_width, 2, "", 0, 0, "", 1) |
|
148 | 149 | end |
|
149 | 150 | |
|
150 | 151 | pdf.SetY(top+1.5) |
|
151 | 152 | pdf.SetX(subject_width + i_left + i_width) |
|
152 | 153 | pdf.Cell(30, 2, "#{i.status.name} #{i.done_ratio}%") |
|
153 | 154 | |
|
154 | 155 | top = top + 5 |
|
155 | 156 | pdf.SetDrawColor(200, 200, 200) |
|
156 | 157 | pdf.Line(15, top, subject_width+g_width, top) |
|
157 | 158 | if pdf.GetY() > 180 |
|
158 | 159 | pdf.AddPage("L") |
|
159 | 160 | top = 20 |
|
160 | 161 | pdf.Line(15, top, subject_width+g_width, top) |
|
161 | 162 | end |
|
162 | 163 | pdf.SetDrawColor(0, 0, 0) |
|
163 | 164 | end |
|
164 | 165 | |
|
165 | 166 | pdf.Line(15, top, subject_width+g_width, top) |
|
166 | 167 | |
|
167 | 168 | %> |
|
168 | 169 | <%= pdf.Output %> No newline at end of file |
General Comments 0
You need to be logged in to leave comments.
Login now