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