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