Merge branch 'master' of git.freeside.biz:/home/git/freeside
[freeside.git] / httemplate / view / cust_main / packages / package.html
1 <TD CLASS="inv package" BGCOLOR="<% $bgcolor %>" VALIGN="top"
2   STYLE="border-left-width: <% $supplemental * 30 %>px">
3   <TABLE CLASS="inv package"> 
4     <TR>
5       <TD COLSPAN=2>
6         <% $opt{before_pkg_callback}
7              ? &{ $opt{before_pkg_callback} }( $cust_pkg )
8              : ''
9         %>
10         <A NAME="cust_pkg<% $cust_pkg->pkgnum %>"
11            ID  ="cust_pkg<% $cust_pkg->pkgnum %>"
12         ><% $curuser->option('show_pkgnum') ? $cust_pkg->pkgnum.': ' : '' %><B><% $part_pkg->pkg |h %></B></A>
13         - 
14         <% $part_pkg->custom_comment |h %>
15       </TD>
16     </TR>
17
18 % if ( $cust_pkg->quantity > 1 ) {
19     <TR>
20       <TD COLSPAN=2>
21         &nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;<% mt('Quantity:') |h %> 
22         <B><% $cust_pkg->quantity %></B>
23       </TD>
24     </TR>
25 % }
26
27     <TR>
28       <TD COLSPAN=2>
29         <FONT SIZE=-1>
30
31 %         unless ( $cust_pkg->get('cancel') || $opt{no_links} ) {
32 %
33 %           if ( $supplemental or $part_pkg->freq eq '0' ) {
34 %             # Supplemental packages can't be changed independently.
35 %             # One-time charges don't need to be changed.
36 %             # For both of those, we only show "Add comments",
37 %             # and "Add invoice details".
38 %           } else {
39 %             # the usual case: links to change package definition,
40 %             # discount, and customization
41 %             my $br = 0;
42 %             if ( $curuser->access_right('Change customer package') ) {
43 %               $br=1;
44                 (&nbsp;<%pkg_change_link($cust_pkg)%>&nbsp;)
45 %             } 
46 %
47 %             if ( $curuser->access_right('Discount customer package')
48 %                  && $part_pkg->can_discount
49 %                  && ! scalar($cust_pkg->cust_pkg_discount_active)
50 %                  && ! scalar($cust_pkg->part_pkg->part_pkg_discount)
51 %                )
52 %             {
53 %               $br=1;
54                 (&nbsp;<%pkg_discount_link($cust_pkg)%>&nbsp;)
55 %             }
56 %
57 %             if ( $curuser->access_right('Customize customer package') ) {
58 %               $br=1;
59                 (&nbsp;<%pkg_customize_link($cust_pkg,$part_pkg)%>&nbsp;)
60 %             } 
61 %
62               <% $br ? '<BR>' : '' %>
63 %           } 
64
65 %           if ( $cust_pkg->num_cust_event
66 %                && (    $curuser->access_right('Billing event reports')
67 %                     || $curuser->access_right('View customer billing events')
68 %                   )
69 %              ) {
70               (&nbsp;<%pkg_event_link($cust_pkg)%>&nbsp;)
71 %           }
72 %         } #!$supplemental
73
74         </FONT>
75       </TD>
76     </TR>
77
78 %   my $editi = $curuser->access_right('Edit customer package invoice details');
79 %   my $editc = $curuser->access_right('Edit customer package comments');
80 %   my @cust_pkg_detail = $cust_pkg->cust_pkg_detail;
81 %   my @invoice_detail = grep { $_->detailtype eq 'I' } @cust_pkg_detail;
82 %   my @comments       = grep { $_->detailtype eq 'C' } @cust_pkg_detail;
83 %
84 %   if ( scalar(@invoice_detail) || scalar(@comments) || $editi || $editc ) {
85 %
86 %     my $editlink = $p. 'edit/cust_pkg_detail.html?pkgnum='. $cust_pkg->pkgnum.
87 %                    ';detailtype=';
88
89       <TR>
90
91 %       if ( @invoice_detail ) {
92           <TD VALIGN="top">
93             <& /elements/table-grid.html &>
94               <TR>
95                 <TH BGCOLOR="#dddddd" STYLE="border-bottom: dashed 1px black; padding-bottom: 1px">
96                   <FONT SIZE="-1">
97                     <% mt('Invoice details') |h %> 
98 %                   if ( $editi && ! $cust_pkg->get('cancel') && ! $opt{no_links} ) {
99                       (<& /elements/popup_link.html, { 
100                                     'action'      => $editlink. 'I',
101                                     'label'       => emt('edit'),
102                                     'actionlabel' => emt('Edit invoice details'),
103                                     'color'       => '#333399',
104                                     'width'       => 763,
105                                  }
106                        &>)
107 %                   }
108                   </FONT>
109                 </TH>
110               </TR>
111 %             foreach my $cust_pkg_detail ( @invoice_detail ) {
112                 <TR>
113                   <TD><FONT SIZE="-1">&nbsp;-&nbsp;<% $cust_pkg_detail->detail |h %></FONT></TD>
114                 </TR>
115 %             }
116             </TABLE>
117           </TD>
118 %       } else {
119           <TD>
120 %           if ( $editi && ! $cust_pkg->get('cancel') && ! $opt{no_links} ) {
121               <FONT SIZE="-1">
122                 (&nbsp;<% include('/elements/popup_link.html', { 
123                                'action'      => $editlink. 'I',
124                                'label'       => emt('Add invoice details'),
125                                'actionlabel' => emt('Add invoice details'),
126                                'color'       => '#333399',
127                                'width'       => 763,
128                             })
129                   %>&nbsp;)
130               </FONT>
131 %           }
132           </TD>
133 %       }
134
135 %       if ( @comments ) { 
136           <TD VALIGN="top">
137             <& /elements/table-grid.html &>
138               <TR>
139                 <TH BGCOLOR="#dddddd" STYLE="border-bottom: dashed 1px black; padding-bottom: 1px">
140                   <FONT SIZE="-1">
141                     <% mt('Comments') |h %> 
142 %                   if ( $editc && ! $opt{no_links} ) {
143                       (<& /elements/popup_link.html, { 
144                                     'action'      => $editlink. 'C',
145                                     'label'       => emt('edit'),
146                                     'actionlabel' => emt('Edit comments'),
147                                     'color'       => '#333399',
148                                     'width'       => 763,
149                                  }
150                        &>)
151 %                   }
152                   </FONT>
153                 </TH>
154               </TR>
155 %             foreach my $cust_pkg_detail ( @comments ) {
156                 <TR>
157                   <TD><FONT SIZE="-1">&nbsp;-&nbsp;<% $cust_pkg_detail->detail |h %></FONT></TD>
158                 </TR>
159 %             }
160             </TABLE>
161           </TD>
162 %       } else {
163           <TD>
164 %           if ( $editc && ! $opt{no_links} ) {
165               <FONT SIZE="-1">
166                 (&nbsp;<& /elements/popup_link.html, { 
167                                'action'      => $editlink. 'C',
168                                'label'       => emt('Add comments'),
169                                'actionlabel' => emt('Add comments'),
170                                'color'       => '#333399',
171                                'width'       => 763,
172                             }
173                   &>&nbsp;)
174               </FONT>
175 %           }
176           </TD>
177 %       }
178
179       </TR>
180 %     if ( $curuser->access_right('Change customer package')
181 %            && ! $cust_pkg->get('cancel')
182 %            && ! $supplemental
183 %            && $part_pkg->freq ne '0'
184 %            && ! $opt{no_links}
185 %        )
186 %     {
187       <TR>
188 %       if ( FS::Conf->new->exists('invoice-unitprice') ) {
189         <TD><FONT SIZE="-1">
190           (&nbsp;<% pkg_change_quantity_link($cust_pkg) %>&nbsp;)
191         </FONT></TD>
192 %       }
193       </TR>
194 %     }
195 %   }
196   </TABLE>
197 % if ( @cust_pkg_usage ) {
198   <TABLE CLASS="usage inv">
199     <TR><TH COLSPAN=4><% mt('Included usage') %></TH></TR>
200 %   foreach my $usage (@cust_pkg_usage) {
201 %     my $part = $usage->part_pkg_usage;
202 %     my $ratio = 255 * ($usage->minutes / $part->minutes);
203 %     $ratio = 255 if $ratio > 255; # because rollover
204 %     my $color = sprintf('STYLE="font-weight: bold; color: #%02x%02x00"', 255 - $ratio, $ratio);
205 %     my $trstyle = '';
206 %     $trstyle = ' CLASS="shared"' if $part->shared;
207     <TR<%$trstyle%>>
208       <TD ALIGN="right"><% $part->description %>: </TD>
209       <TD <%$color%> ALIGN="right"><% $usage->minutes %></TD>
210       <TD <%$color%>> / </TD>
211       <TD <%$color%>><% $part->minutes %></TD>
212 %     if ( $part->shared ) {
213       <TD><I>(shared)</I></TD>
214 %     }
215     </TR>
216 %   }
217   </TABLE>
218 % }
219
220 </TD>
221
222 <%init>
223
224 my %opt = @_;
225
226 my $bgcolor  = $opt{'bgcolor'};
227 my $cust_pkg = $opt{'cust_pkg'};
228 my $part_pkg = $opt{'part_pkg'};
229
230 my $curuser = $FS::CurrentUser::CurrentUser;
231
232 my $countrydefault = $opt{'countrydefault'} || 'US';
233 my $statedefault   = $opt{'statedefault'}
234                      || ($countrydefault eq 'US' ? 'CA' : '');
235
236 my $supplemental = $opt{'supplemental'} || 0;
237
238 $cust_pkg->pkgnum =~ /^(\d+)$/;
239 my $pkgnum = $1;
240 my @cust_pkg_usage = qsearch({
241   'select'    => 'cust_pkg_usage.*',
242   'table'     => 'cust_pkg_usage',
243   'addl_from' => ' JOIN part_pkg_usage USING (pkgusagepart)',
244   'extra_sql' => " WHERE pkgnum = $1",
245   'order_by'  => ' ORDER BY priority ASC, description ASC',
246 });
247
248 #subroutines
249
250 #false laziness w/status.html
251 sub pkg_link {
252   my($action, $label, $cust_pkg) = @_;
253   return '' unless $cust_pkg;
254   qq!<a href="$p$action.cgi?!. $cust_pkg->pkgnum. qq!">$label</a>!;
255 }
256
257 sub pkg_change_link {
258   my $cust_pkg = shift;
259   my $locationnum = $cust_pkg->locationnum;
260   include( '/elements/popup_link-cust_pkg.html',
261     'action'      => $p. "misc/change_pkg.cgi?locationnum=$locationnum",
262     'label'       => emt('Change package'),
263     'actionlabel' => emt('Change'),
264     'cust_pkg'    => $cust_pkg,
265     'width'       => 763,
266     'height'      => 380,
267   );
268 }
269
270 sub pkg_change_location_link {
271   my $cust_pkg = shift;
272   my $pkgpart = $cust_pkg->pkgpart;
273   include( '/elements/popup_link-cust_pkg.html',
274     'action'      => $p. "misc/change_pkg.cgi?locationnum=-1;pkgpart=$pkgpart;".
275                      "address1=;address2=;city=;county=;state=$statedefault;".
276                      "zip=;country=$countrydefault",
277     'label'       => emt('Change location'),
278     'actionlabel' => emt('Change'),
279     'cust_pkg'    => $cust_pkg,
280     'width'       => 763,
281     'height'      => 380,
282   );
283 }
284
285 sub pkg_change_quantity_link {
286   include( '/elements/popup_link-cust_pkg.html',
287     'action'      => $p. 'edit/cust_pkg_quantity.html?',
288     'label'       => emt('Change quantity'),
289     'actionlabel' => emt('Change'),
290     'cust_pkg'    => shift,
291     'width'       => 390,
292     'height'      => 220,
293   );
294 }
295
296 sub pkg_discount_link {
297   my $cust_pkg = shift or return '';
298   include( '/elements/popup_link-cust_pkg.html',
299     'action'      => $p.'edit/cust_pkg_discount.html',
300     'label'       => emt('Discount'),
301     'actionlabel' => emt('Discount'),
302     'cust_pkg'    => $cust_pkg,
303     'width'       => 616,
304   );
305 }
306
307 sub pkg_customize_link {
308   my $cust_pkg = shift or return '';
309   my $part_pkg = shift;
310   my $custnum = $cust_pkg->custnum;
311   qq!<A HREF="${p}edit/part_pkg.cgi?!.
312     "clone=". $part_pkg->pkgpart. ';'.
313     "pkgnum=". $cust_pkg->pkgnum.
314     qq!">!.emt('Customize').'</A>';
315 }
316
317 sub pkg_event_link {
318   my($cust_pkg) = @_;
319   qq!<a href="${p}search/cust_event.html?pkgnum=!. $cust_pkg->pkgnum. qq!">!.
320   emt('View package events').
321   '</a>';
322 }
323
324 </%init>