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