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