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