avoid looking up package details redundantly in the pkg loop, RT#5083
[freeside.git] / httemplate / view / cust_main / packages / package.html
1 <TD CLASS="inv" BGCOLOR="<% $bgcolor %>">
2   <TABLE CLASS="inv" BORDER=0 CELLSPACING=0 CELLPADDING=0 WIDTH="100%">
3     <TR>
4       <TD COLSPAN=2>
5         <A NAME="cust_pkg<% $cust_pkg->pkgnum %>"
6            ID  ="cust_pkg<% $cust_pkg->pkgnum %>"
7         ><% $curuser->option('show_pkgnum') ? $cust_pkg->pkgnum.': ' : '' %><B><% $part_pkg->pkg |h %></B></A>
8         - 
9         <% $part_pkg->comment |h %>
10       </TD>
11     </TR>
12
13 % if ( $cust_pkg->quantity > 1 ) {
14     <TR>
15       <TD COLSPAN=2>
16         &nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;Quantity: 
17         <B><% $cust_pkg->quantity %></B>
18       </TD>
19     </TR>
20 %  }
21
22     <TR>
23       <TD COLSPAN=2>
24         <FONT SIZE=-1>
25
26 %         unless ( $cust_pkg->get('cancel') ) { 
27 %
28 %           my $br = 0;
29 %           if ( $curuser->access_right('Change customer package') ) {
30 %             $br=1;
31               (&nbsp;<%pkg_change_link($cust_pkg)%>&nbsp;)
32 %           } 
33 %
34 %           if ( $curuser->access_right('Edit customer package dates') ) {
35 %             $br=1;
36               (&nbsp;<%pkg_dates_link($cust_pkg)%>&nbsp;)
37 %           } 
38 %
39 %           if ( $curuser->access_right('Customize customer package') ) {
40 %             $br=1;
41               (&nbsp;<%pkg_customize_link($cust_pkg,$cust_pkg->custnum)%>&nbsp;)
42 %           } 
43 %
44             <% $br ? '<BR>' : '' %>
45 %         } 
46
47 %         if ( $cust_pkg->num_cust_event
48 %              && (    $curuser->access_right('Billing event reports')
49 %                   || $curuser->access_right('View customer billing events')
50 %                 )
51 %            ) {
52             (&nbsp;<%pkg_event_link($cust_pkg)%>&nbsp;)
53 %         }
54
55         </FONT>
56       </TD>
57     </TR>
58
59 %   my $editi = $curuser->access_right('Edit customer package invoice details');
60 %   my $editc = $curuser->access_right('Edit customer package comments');
61 %   my @cust_pkg_detail = $cust_pkg->cust_pkg_detail;
62 %   my @invoice_detail = grep { $_->detailtype eq 'I' } @cust_pkg_detail;
63 %   my @comments       = grep { $_->detailtype eq 'C' } @cust_pkg_detail;
64 %
65 %   if ( scalar(@invoice_detail) || scalar(@comments) || $editi || $editc ) {
66 %
67 %     my $editlink = $p. 'edit/cust_pkg_detail?pkgnum='. $cust_pkg->pkgnum.
68 %                    ';detailtype=';
69
70       <TR>
71
72 %       if ( @invoice_detail ) {
73           <TD VALIGN="top">
74             <% include('/elements/table-grid.html') %>
75               <TR>
76                 <TH BGCOLOR="#dddddd" STYLE="border-bottom: dashed 1px black; padding-bottom: 1px">
77                   <FONT SIZE="-1">
78                     Invoice details
79 %                   if ( $editi && ! $cust_pkg->get('cancel') ) {
80                       (<% include('/elements/popup_link.html', { 
81                                     'action'      => $editlink. 'I',
82                                     'label'       => 'edit',
83                                     'actionlabel' => 'Edit invoice details',
84                                     'color'       => '#333399',
85                                     'width'       => 763,
86                                  })
87                        %>)
88 %                   }
89                   </FONT>
90                 </TH>
91               </TR>
92 %             foreach my $cust_pkg_detail ( @invoice_detail ) {
93                 <TR>
94                   <TD><FONT SIZE="-1">&nbsp;-&nbsp;<% $cust_pkg_detail->detail |h %></FONT></TD>
95                 </TR>
96 %             }
97             </TABLE>
98           </TD>
99 %       } else {
100           <TD>
101 %           if ( $editi && ! $cust_pkg->get('cancel') ) {
102               <FONT SIZE="-1">
103                 (&nbsp;<% include('/elements/popup_link.html', { 
104                                'action'      => $editlink. 'I',
105                                'label'       => 'Add&nbsp;invoice&nbsp;details',
106                                'actionlabel' => 'Add invoice details',
107                                'color'       => '#333399',
108                                'width'       => 763,
109                             })
110                   %>&nbsp;)
111               </FONT>
112 %           }
113           </TD>
114 %       }
115
116 %       if ( @comments ) { 
117           <TD VALIGN="top">
118             <% include('/elements/table-grid.html') %>
119               <TR>
120                 <TH BGCOLOR="#dddddd" STYLE="border-bottom: dashed 1px black; padding-bottom: 1px">
121                   <FONT SIZE="-1">
122                     Comments
123 %                   if ( $editc ) {
124                       (<% include('/elements/popup_link.html', { 
125                                     'action'      => $editlink. 'C',
126                                     'label'       => 'edit',
127                                     'actionlabel' => 'Edit comments',
128                                     'color'       => '#333399',
129                                     'width'       => 763,
130                                  })
131                        %>)
132 %                   }
133                   </FONT>
134                 </TH>
135               </TR>
136 %             foreach my $cust_pkg_detail ( @comments ) {
137                 <TR>
138                   <TD><FONT SIZE="-1">&nbsp;-&nbsp;<% $cust_pkg_detail->detail |h %></FONT></TD>
139                 </TR>
140 %             }
141             </TABLE>
142           </TD>
143 %       } else {
144           <TD>
145 %           if ( $editc ) {
146               <FONT SIZE="-1">
147                 (&nbsp;<% include('/elements/popup_link.html', { 
148                                'action'      => $editlink. 'C',
149                                'label'       => 'Add&nbsp;comments',
150                                'actionlabel' => 'Add comments',
151                                'color'       => '#333399',
152                                'width'       => 763,
153                             })
154                   %>&nbsp;)
155               </FONT>
156 %           }
157           </TD>
158 %       }
159
160       </TR>
161 %   }
162
163   </TABLE>
164
165 </TD>
166
167 <%init>
168
169 my %opt = @_;
170
171 my $bgcolor  = $opt{'bgcolor'};
172 my $cust_pkg = $opt{'cust_pkg'};
173 my $part_pkg = $opt{'part_pkg'};
174
175 my $curuser = $FS::CurrentUser::CurrentUser;
176
177 #subroutines
178
179 #false laziness w/status.html
180 sub pkg_link {
181   my($action, $label, $cust_pkg) = @_;
182   return '' unless $cust_pkg;
183   qq!<a href="$p$action.cgi?!. $cust_pkg->pkgnum. qq!">$label</a>!;
184 }
185
186 sub pkg_change_link {
187   my $cust_pkg = shift;
188   my $locationnum = $cust_pkg->locationnum;
189   include( '/elements/popup_link-cust_pkg.html',
190     'action'      => $p. "misc/change_pkg.cgi?locationnum=$locationnum",
191     'label'       => 'Change&nbsp;package',
192     'actionlabel' => 'Change',
193     'cust_pkg'    => $cust_pkg,
194   );
195 }
196
197 sub pkg_dates_link { pkg_link('edit/REAL_cust_pkg', 'Edit&nbsp;dates', @_ ); }
198
199 sub pkg_customize_link {
200   my $cust_pkg = shift or return '';
201   my $custnum = $cust_pkg->custnum;
202   qq!<A HREF="${p}edit/part_pkg.cgi?!.
203     "clone=". $cust_pkg->part_pkg->pkgpart. ';'.
204     "pkgnum=". $cust_pkg->pkgnum.
205     qq!">Customize</A>!;
206 }
207
208 sub pkg_event_link {
209   my($cust_pkg) = @_;
210   qq!<a href="${p}search/cust_event.html?pkgnum=!. $cust_pkg->pkgnum. qq!">!.
211   'View package events'.
212   '</a>';
213 }
214
215 </%init>