Merge branch 'fix_category_table' of https://github.com/jgoodman/Freeside into jgoodm...
[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
4
5     <TR>
6       <TD COLSPAN=2>
7         <% $opt{before_pkg_callback}
8              ? &{ $opt{before_pkg_callback} }( $cust_pkg )
9              : ''
10         %>
11         <A NAME="cust_pkg<% $cust_pkg->pkgnum %>"
12            ID  ="cust_pkg<% $cust_pkg->pkgnum %>"
13         ><% $opt{show_pkgnum} ? $cust_pkg->pkgnum.': ' : '' %><B><% $part_pkg->pkg |h %></B></A>
14 %
15 %       my $custom_comment;
16 %       if ( 0 && FS::part_pkg::flat->can('price_info') eq $part_pkg->can('price_info') ) {
17 %         #perf hack / disabled in 4.x (feature pricing / cust_pkg_usageprice incompatible, well, harder)
18 %
19 %         $part_pkg->{"_$_"} = $part_pkg->option($_) || 0
20 %           foreach grep !defined($part_pkg->{"_$_"} ), qw(setup_fee recur_fee);
21 %           
22 %         my $str = '';
23 %         $str = $opt{money_char} . $part_pkg->{_setup_fee}.
24 %                ($part_pkg->{_recur_fee} ? ' setup' : ' one-time')
25 %           if $part_pkg->{_setup_fee};
26 %         $str .= ', ' if $part_pkg->{_setup_fee} && $part_pkg->{_recur_fee};
27 %         $str .= $opt{money_char}. $part_pkg->{_recur_fee}.
28 %                 '/'. $part_pkg->freq_pretty
29 %           if $part_pkg->{_recur_fee};
30 %         $str;
31 %
32 %         $custom_comment = 
33 %           ( $part_pkg->custom ? '(CUSTOM) ' : '' ).
34 %           $part_pkg->comment.
35 %           ( ($part_pkg->custom || $part_pkg->comment) ? ' - ' : '' ).
36 %           ($str || 'No charge');
37 %
38 %       } else {
39 %         $custom_comment = $part_pkg->custom_comment('cust_pkg'=>$cust_pkg);
40 %       }
41         <% $custom_comment ? ' - ' : '' %>
42         <% $custom_comment |h %>
43       </TD>
44     </TR>
45
46
47     <TR>
48       <TD COLSPAN=2>
49         <FONT SIZE=-1>
50
51 %         if ( $part_pkg->freq eq '0' and !$opt{no_links} ) {
52 %           # One-time charge.  Nothing you can do with this, unless:
53 %           if ( $curuser->access_right('Modify one-time charge') ) {
54                 (&nbsp;<%onetime_change_link($cust_pkg)%>&nbsp;)
55 %           }
56 %           # also, you can discount it
57 %           if ( $curuser->access_right('Discount customer package')
58 %                && ! scalar($cust_pkg->cust_pkg_discount_active)
59 %                && ! scalar($cust_pkg->part_pkg->part_pkg_discount)
60 %              ) {
61               (&nbsp;<%pkg_discount_link($cust_pkg)%>&nbsp;)
62 %           }
63           <BR>
64 %
65 %         } elsif ( !$cust_pkg->get('cancel') and !$opt{no_links} ) {
66 %
67 %           if ( $change_from ) {
68 %             # This is the target package for a future change.
69 %             # Nothing you can do with it besides modify/cancel the 
70 %             # future change, and that's on the current package.
71 %           } elsif ( $supplemental ) {
72 %             # Supplemental packages can't be changed independently.
73 %             # Show only "Add comments" and "Add invoice details".
74 %           } else {
75 %             # the usual case: links to change package definition,
76 %             # discount, and customization
77 %             my $br = 0;
78 %             if ( $curuser->access_right('Change customer package') ) {
79 %               $br=1;
80                 (&nbsp;<%pkg_change_link($cust_pkg)%>&nbsp;)
81 %             } 
82 %
83 %             if ( $curuser->access_right('Discount customer package')
84 %                  && $part_pkg->can_discount
85 %                  && ! scalar( @{ $cust_pkg->{_cust_pkg_discount_active} } )
86 %                  && (    ! $opt{'term_discounts'}
87 %                       || ! scalar($cust_pkg->part_pkg->part_pkg_discount)
88 %                     )
89 %                )
90 %             {
91 %               $br=1;
92                 (&nbsp;<%pkg_discount_link($cust_pkg)%>&nbsp;)
93 %             }
94 %
95 %             if ( $curuser->access_right('Customize customer package') ) {
96 %               $br=1;
97                 (&nbsp;<%pkg_customize_link($cust_pkg,$part_pkg)%>&nbsp;)
98 %             } 
99 %
100               <% $br ? '<BR>' : '' %>
101 %           } 
102
103 %           if (    (    $curuser->access_right('Billing event reports')
104 %                     || $curuser->access_right('View customer billing events')
105 %                   )
106 %                && $cust_pkg->exists_cust_event
107 %              ) {
108               (&nbsp;<%pkg_event_link($cust_pkg)%>&nbsp;)
109 %           }
110 %         } #!$supplemental
111
112         </FONT>
113       </TD>
114     </TR>
115
116
117     <TR>
118       <TD COLSPAN=2>
119
120 %       my $change_quan_label = 'Change quantity';
121 %       if ( $cust_pkg->quantity > 1 ) {
122 %         $change_quan_label = 'change';
123           &nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;<% mt('Quantity:') |h %> 
124           <B><% $cust_pkg->quantity %></B>
125 %       }
126
127 %       if ( $curuser->access_right('Change customer package')
128 %              && ! $cust_pkg->get('cancel')
129 %              && ! $supplemental
130 %              && $part_pkg->freq ne '0'
131 %              && ! $opt{no_links}
132 %              && $opt{'invoice-unitprice'}
133 %          )
134 %       {
135           <FONT SIZE="-1">
136             (&nbsp;<% pkg_change_quantity_link($cust_pkg, $change_quan_label) %>&nbsp;)
137           </FONT>
138 %       }
139
140       </TD>
141     </TR>
142
143
144     <TR>
145       <TD COLSPAN=2>
146
147 %       my $change_sales_label = 'Change sales person';
148 %       if ( $cust_pkg->salesnum ) {
149 %         $change_sales_label = 'change';
150           &nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;<% mt('Sales Person:') |h %> 
151           <B><% $cust_pkg->salesperson |h %></B>
152 %       }
153
154 %       if ( $curuser->access_right('Change customer package')
155 %              && ! $cust_pkg->get('cancel')
156 %              && ! $supplemental
157 %              #&& $part_pkg->freq ne '0'
158 %              && ! $opt{no_links}
159 %          )
160 %       {
161         <FONT SIZE="-1">
162           (&nbsp;<% pkg_change_salesnum_link($cust_pkg, $change_sales_label) %>&nbsp;)
163         </FONT>
164 %     }
165
166       </TD>
167     </TR>
168
169
170 %   my $editi = $curuser->access_right('Edit customer package invoice details');
171 %   my $editc = $curuser->access_right('Edit customer package comments');
172 %   my @cust_pkg_detail = $cust_pkg->cust_pkg_detail;
173 %   my @invoice_detail = grep { $_->detailtype eq 'I' } @cust_pkg_detail;
174 %   my @comments       = grep { $_->detailtype eq 'C' } @cust_pkg_detail;
175 %
176 %   if ( scalar(@invoice_detail) || scalar(@comments) || $editi || $editc ) {
177 %
178 %     my $editlink = $p. 'edit/cust_pkg_detail.html?pkgnum='. $cust_pkg->pkgnum.
179 %                    ';detailtype=';
180
181       <TR>
182
183 %       if ( @invoice_detail ) {
184           <TD VALIGN="top">
185             <& /elements/table-grid.html &>
186               <TR>
187                 <TH BGCOLOR="#dddddd" STYLE="border-bottom: dashed 1px black; padding-bottom: 1px">
188                   <FONT SIZE="-1">
189                     <% mt('Invoice details') |h %> 
190 %                   if ( $editi && ! $cust_pkg->get('cancel') && ! $opt{no_links} ) {
191                       (<& /elements/popup_link.html, { 
192                                     'action'      => $editlink. 'I',
193                                     'label'       => emt('edit'),
194                                     'actionlabel' => emt('Edit invoice details'),
195                                     'color'       => '#333399',
196                                     'width'       => 763,
197                                  }
198                        &>)
199 %                   }
200                   </FONT>
201                 </TH>
202               </TR>
203 %             foreach my $cust_pkg_detail ( @invoice_detail ) {
204                 <TR>
205                   <TD><FONT SIZE="-1">&nbsp;-&nbsp;<% $cust_pkg_detail->detail |h %></FONT></TD>
206                 </TR>
207 %             }
208             </TABLE>
209           </TD>
210 %       } else {
211           <TD>
212 %           if ( $editi && ! $cust_pkg->get('cancel') && ! $opt{no_links} ) {
213               <FONT SIZE="-1">
214                 (&nbsp;<% include('/elements/popup_link.html', { 
215                                'action'      => $editlink. 'I',
216                                'label'       => emt('Add invoice details'),
217                                'actionlabel' => emt('Add invoice details'),
218                                'color'       => '#333399',
219                                'width'       => 763,
220                             })
221                   %>&nbsp;)
222               </FONT>
223 %           }
224           </TD>
225 %       }
226
227 %       if ( @comments ) { 
228           <TD VALIGN="top">
229             <& /elements/table-grid.html &>
230               <TR>
231                 <TH BGCOLOR="#dddddd" STYLE="border-bottom: dashed 1px black; padding-bottom: 1px">
232                   <FONT SIZE="-1">
233                     <% mt('Comments') |h %> 
234 %                   if ( $editc && ! $opt{no_links} ) {
235                       (<& /elements/popup_link.html, { 
236                                     'action'      => $editlink. 'C',
237                                     'label'       => emt('edit'),
238                                     'actionlabel' => emt('Edit comments'),
239                                     'color'       => '#333399',
240                                     'width'       => 763,
241                                  }
242                        &>)
243 %                   }
244                   </FONT>
245                 </TH>
246               </TR>
247 %             foreach my $cust_pkg_detail ( @comments ) {
248                 <TR>
249                   <TD><FONT SIZE="-1">&nbsp;-&nbsp;<% $cust_pkg_detail->detail |h %></FONT></TD>
250                 </TR>
251 %             }
252             </TABLE>
253           </TD>
254 %       } else {
255           <TD>
256 %           if ( $editc && ! $opt{no_links} ) {
257               <FONT SIZE="-1">
258                 (&nbsp;<& /elements/popup_link.html, { 
259                                'action'      => $editlink. 'C',
260                                'label'       => emt('Add comments'),
261                                'actionlabel' => emt('Add comments'),
262                                'color'       => '#333399',
263                                'width'       => 763,
264                             }
265                   &>&nbsp;)
266               </FONT>
267 %           }
268           </TD>
269 %       }
270
271       </TR>
272
273
274 %   }
275   </TABLE>
276
277 % if ( @cust_pkg_usage ) {
278   <TABLE CLASS="usage inv">
279     <TR><TH COLSPAN=4><% mt('Included usage') %></TH></TR>
280 %   foreach my $usage (@cust_pkg_usage) {
281 %     my $part = $usage->part_pkg_usage;
282 %     my $ratio = 255 * ($usage->minutes / $part->minutes);
283 %     $ratio = 255 if $ratio > 255; # because rollover
284 %     my $color = sprintf('STYLE="font-weight: bold; color: #%02x%02x00"', 255 - $ratio, $ratio);
285 %     my $trstyle = '';
286 %     $trstyle = ' CLASS="shared"' if $part->shared;
287     <TR<%$trstyle%>>
288       <TD ALIGN="right"><% $part->description %>: </TD>
289       <TD <%$color%> ALIGN="right"><% sprintf('%.1f', $usage->minutes) %></TD>
290       <TD <%$color%>> / </TD>
291       <TD <%$color%>><% $part->minutes %></TD>
292 %     if ( $part->shared ) {
293       <TD><I>(shared)</I></TD>
294 %     }
295     </TR>
296 %   }
297   </TABLE>
298 % }
299
300 </TD>
301
302 <%init>
303
304 my %opt = @_;
305
306 my $bgcolor  = $opt{'bgcolor'};
307 my $cust_pkg = $opt{'cust_pkg'};
308 my $part_pkg = $opt{'part_pkg'};
309
310 my $curuser = $FS::CurrentUser::CurrentUser;
311
312 my $countrydefault = $opt{'countrydefault'} || 'US';
313 my $statedefault   = $opt{'statedefault'}
314                      || ($countrydefault eq 'US' ? 'CA' : '');
315
316 # put a marker on the left edge of this column
317 # if this package is somehow special
318 my $supplemental = $opt{'supplemental'} || 0;
319 my $change_from = $opt{'change_from'} || 0;
320 my $style = '';
321 if ( $supplemental or $change_from ) {
322   $style = 'border-left-width: '.($supplemental + $change_from)*30 . 'px; '.
323            'border-color: ';
324   if ( $supplemental ) {
325     $style .= '#bbbbff';
326   } elsif ( $change_from ) {
327     $style .= '#bbffbb';
328   }
329   $style = qq!STYLE="$style"!;
330 }
331
332 $cust_pkg->pkgnum =~ /^(\d+)$/;
333 my $pkgnum = $1;
334 my @cust_pkg_usage = qsearch({
335   'select'    => 'cust_pkg_usage.*',
336   'table'     => 'cust_pkg_usage',
337   'addl_from' => ' JOIN part_pkg_usage USING (pkgusagepart)',
338   'extra_sql' => " WHERE pkgnum = $1",
339   'order_by'  => ' ORDER BY priority ASC, description ASC',
340 });
341
342 #subroutines
343
344 #false laziness w/status.html
345 sub pkg_link {
346   my($action, $label, $cust_pkg) = @_;
347   return '' unless $cust_pkg;
348   qq!<a href="$p$action.cgi?!. $cust_pkg->pkgnum. qq!">$label</a>!;
349 }
350
351 sub pkg_change_link {
352   my $cust_pkg = shift;
353   my $locationnum = $cust_pkg->locationnum;
354   include( '/elements/popup_link-cust_pkg.html',
355     'action'      => $p. "misc/change_pkg.cgi?locationnum=$locationnum",
356     'label'       => emt('Change package'),
357     'actionlabel' => emt('Change'),
358     'cust_pkg'    => $cust_pkg,
359     'width'       => 960,
360     'height'      => 490,
361   );
362 }
363
364 sub onetime_change_link {
365   my $cust_pkg = shift;
366   my $pkgnum = $cust_pkg->pkgnum;
367   include( '/elements/popup_link-cust_pkg.html',
368     'action'      => $p. "edit/quick-charge.html?change_pkgnum=$pkgnum",
369     'label'       => emt('Modify one-time charge'),
370     'actionlabel' => emt('Modify'),
371     'cust_pkg'    => $cust_pkg,
372     'width'       => 690,
373     'height'      => 380,
374   );
375 }
376
377 sub pkg_change_location_link {
378   my $cust_pkg = shift;
379   my $pkgpart = $cust_pkg->pkgpart;
380   include( '/elements/popup_link-cust_pkg.html',
381     'action'      => $p. "misc/change_pkg.cgi?locationnum=-1;pkgpart=$pkgpart;".
382                      "address1=;address2=;city=;county=;state=$statedefault;".
383                      "zip=;country=$countrydefault",
384     'label'       => emt('Change location'),
385     'actionlabel' => emt('Change'),
386     'cust_pkg'    => $cust_pkg,
387     'width'       => 960,
388     'height'      => 490,
389   );
390 }
391
392 sub pkg_change_quantity_link {
393   my( $cust_pkg, $label ) = @_;
394   include( '/elements/popup_link-cust_pkg.html',
395     'action'      => $p. 'edit/cust_pkg_quantity.html?',
396     'label'       => emt($label),
397     'actionlabel' => emt('Change'),
398     'cust_pkg'    => $cust_pkg,
399     'width'       => 390,
400     'height'      => 220,
401   );
402 }
403
404 sub pkg_change_salesnum_link {
405   my( $cust_pkg, $label ) = @_;
406   include( '/elements/popup_link-cust_pkg.html',
407     'action'      => $p. 'edit/cust_pkg_salesnum.html?',
408     'label'       => emt($label),
409     'actionlabel' => emt('Change'),
410     'cust_pkg'    => $cust_pkg,
411     'width'       => 390,
412     'height'      => 220,
413   );
414 }
415
416 sub pkg_discount_link {
417   my $cust_pkg = shift or return '';
418   include( '/elements/popup_link-cust_pkg.html',
419     'action'      => $p.'edit/cust_pkg_discount.html',
420     'label'       => emt('Discount'),
421     'actionlabel' => emt('Discount'),
422     'cust_pkg'    => $cust_pkg,
423     'width'       => 616,
424   );
425 }
426
427 sub pkg_customize_link {
428   my $cust_pkg = shift or return '';
429   my $part_pkg = shift;
430   my $custnum = $cust_pkg->custnum;
431   qq!<A HREF="${p}edit/part_pkg.cgi?!.
432     "clone=". $part_pkg->pkgpart. ';'.
433     "pkgnum=". $cust_pkg->pkgnum.
434     qq!">!.emt('Customize').'</A>';
435 }
436
437 sub pkg_event_link {
438   my($cust_pkg) = @_;
439   qq!<a href="${p}search/cust_event.html?pkgnum=!. $cust_pkg->pkgnum. qq!">!.
440   emt('View package events').
441   '</a>';
442 }
443
444 </%init>