61143413cd90f8f6a3ca136b9ff23ebc59d2265e
[freeside.git] / httemplate / view / cust_main / packages / package.html
1 <TD CLASS="inv package" BGCOLOR="<% $bgcolor %>" VALIGN="top">
2   <% join('', @marker ) %>
3   <TABLE CLASS="inv package"> 
4     <TR>
5       <TD COLSPAN=2>
6         <% $opt{before_pkg_callback}
7              ? &{ $opt{before_pkg_callback} }( $cust_pkg )
8              : ''
9         %>
10
11 % ###
12 % # Package
13 % ###
14         <A NAME="cust_pkg<% $cust_pkg->pkgnum %>"
15            ID  ="cust_pkg<% $cust_pkg->pkgnum %>"
16         ><% $opt{show_pkgnum} ? $cust_pkg->pkgnum.': ' : '' %><B><% $part_pkg->pkg |h %></B></A>
17 %
18 %       my $custom_comment;
19 %       if ( 0 && FS::part_pkg::flat->can('price_info') eq $part_pkg->can('price_info') ) {
20 %         #perf hack / disabled in 4.x (feature pricing / cust_pkg_usageprice incompatible, well, harder)
21 %
22 %         $part_pkg->{"_$_"} = $part_pkg->option($_) || 0
23 %           foreach grep !defined($part_pkg->{"_$_"} ), qw(setup_fee recur_fee);
24 %           
25 %         my $str = '';
26 %         $str = $opt{money_char} . $part_pkg->{_setup_fee}.
27 %                ($part_pkg->{_recur_fee} ? ' setup' : ' one-time')
28 %           if $part_pkg->{_setup_fee};
29 %         $str .= ', ' if $part_pkg->{_setup_fee} && $part_pkg->{_recur_fee};
30 %         $str .= $opt{money_char}. $part_pkg->{_recur_fee}.
31 %                 '/'. $part_pkg->freq_pretty
32 %           if $part_pkg->{_recur_fee};
33 %         $str;
34 %
35 %         $custom_comment = 
36 %           ( $part_pkg->custom ? '(CUSTOM) ' : '' ).
37 %           $part_pkg->comment.
38 %           ( ($part_pkg->custom || $part_pkg->comment) ? ' - ' : '' ).
39 %           ($str || 'No charge');
40 %
41 %       } else {
42 %         $custom_comment = $part_pkg->custom_comment('cust_pkg'=>$cust_pkg);
43 %       }
44         <% $custom_comment ? ' - ' : '' %>
45         <% $custom_comment |h %>
46       </TD>
47     </TR>
48
49 % ###
50 % # Quantity
51 % ###
52 % if ( $cust_pkg->quantity > 1 ) {
53     <TR>
54       <TD COLSPAN=2>
55           &nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;<% mt('Quantity:') |h %> 
56           <B><% $cust_pkg->quantity %></B>
57
58 %       if ( $curuser->access_right('Change customer package')
59 %              && ! $cust_pkg->get('cancel')
60 %              && ! $change_from
61 %              && ! $supplemental
62 %              && $part_pkg->freq ne '0'
63 %              && ! $opt{no_links}
64 %              && $opt{'invoice-unitprice'}
65 %          )
66 %       {
67           <FONT SIZE="-1">
68             (&nbsp;<% pkg_change_quantity_link($cust_pkg, 'change') %>&nbsp;)
69           </FONT>
70 %       }
71       </TD>
72     </TR>
73 % }
74
75 % ###
76 % # Sales person
77 % ###
78 % if ( $cust_pkg->salesnum ) {
79     <TR>
80       <TD COLSPAN=2>
81           &nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;<% mt('Sales Person:') |h %> 
82           <B><% $cust_pkg->salesperson |h %></B>
83 %       if ( $curuser->access_right('Change customer package')
84 %              && ! $cust_pkg->get('cancel')
85 %              && ! $change_from
86 %              && ! $supplemental
87 %              #&& $part_pkg->freq ne '0'
88 %              && ! $opt{no_links}
89 %          )
90 %       {
91         <FONT SIZE="-1">
92           (&nbsp;<% pkg_change_salesnum_link($cust_pkg, 'change') %>&nbsp;)
93         </FONT>
94 %     }
95       </TD>
96     </TR>
97 % }
98
99
100 % ###
101 % # Invoice details & comments
102 % ###
103 %   my $editi = $curuser->access_right('Edit customer package invoice details');
104 %   my $editc = $curuser->access_right('Edit customer package comments');
105 %   my @cust_pkg_detail = $cust_pkg->cust_pkg_detail;
106 %   my @invoice_detail = grep { $_->detailtype eq 'I' } @cust_pkg_detail;
107 %   my @comments       = grep { $_->detailtype eq 'C' } @cust_pkg_detail;
108 %
109 %   if ( scalar(@invoice_detail) || scalar(@comments) || $editi || $editc ) {
110 %
111 %     my $editlink = $p. 'edit/cust_pkg_detail.html?pkgnum='. $cust_pkg->pkgnum.
112 %                    ';detailtype=';
113
114       <TR>
115
116 %       if ( @invoice_detail ) {
117           <TD VALIGN="top">
118             <& /elements/table-grid.html &>
119               <TR>
120                 <TH BGCOLOR="#dddddd" STYLE="border-bottom: dashed 1px black; padding-bottom: 1px">
121                   <FONT SIZE="-1">
122                     <% mt('Invoice details') |h %> 
123 %                   if ( $editi && ! $cust_pkg->get('cancel') && ! $opt{no_links} ) {
124                       (<& /elements/popup_link.html, { 
125                                     'action'      => $editlink. 'I',
126                                     'label'       => emt('edit'),
127                                     'actionlabel' => emt('Edit invoice details'),
128                                     'color'       => '#333399',
129                                     'width'       => 763,
130                                  }
131                        &>)
132 %                   }
133                   </FONT>
134                 </TH>
135               </TR>
136 %             foreach my $cust_pkg_detail ( @invoice_detail ) {
137                 <TR>
138                   <TD><FONT SIZE="-1">&nbsp;-&nbsp;<% $cust_pkg_detail->detail |h %></FONT></TD>
139                 </TR>
140 %             }
141             </TABLE>
142           </TD>
143 %       } else {
144           <TD>
145           </TD>
146 %       }
147
148 %       if ( @comments ) { 
149           <TD VALIGN="top">
150             <& /elements/table-grid.html &>
151               <TR>
152                 <TH BGCOLOR="#dddddd" STYLE="border-bottom: dashed 1px black; padding-bottom: 1px">
153                   <FONT SIZE="-1">
154                     <% mt('Comments') |h %> 
155 %                   if ( $editc && ! $opt{no_links} ) {
156                       (<& /elements/popup_link.html, { 
157                                     'action'      => $editlink. 'C',
158                                     'label'       => emt('edit'),
159                                     'actionlabel' => emt('Edit comments'),
160                                     'color'       => '#333399',
161                                     'width'       => 763,
162                                  }
163                        &>)
164 %                   }
165                   </FONT>
166                 </TH>
167               </TR>
168 %             foreach my $cust_pkg_detail ( @comments ) {
169                 <TR>
170                   <TD><FONT SIZE="-1">&nbsp;-&nbsp;<% $cust_pkg_detail->detail |h %></FONT></TD>
171                 </TR>
172 %             }
173             </TABLE>
174           </TD>
175 %       } else {
176           <TD>
177           </TD>
178 %       }
179
180       </TR>
181
182
183 %   }
184   </TABLE>
185
186 % if ( @cust_pkg_usage ) {
187   <TABLE CLASS="usage inv">
188     <TR><TH COLSPAN=4><% emt('Included usage') %></TH></TR>
189 %   foreach my $usage (@cust_pkg_usage) {
190 %     my $part = $usage->part_pkg_usage;
191 %     my $ratio = 255 * ($usage->minutes / $part->minutes);
192 %     $ratio = 255 if $ratio > 255; # because rollover
193 %     my $color = sprintf('STYLE="font-weight: bold; color: #%02x%02x00"', 255 - $ratio, $ratio);
194 %     my $trstyle = '';
195 %     $trstyle = ' CLASS="shared"' if $part->shared;
196     <TR<%$trstyle%>>
197       <TD ALIGN="right"><% $part->description %>: </TD>
198       <TD <%$color%> ALIGN="right"><% sprintf('%.1f', $usage->minutes) %></TD>
199       <TD <%$color%>> / </TD>
200       <TD <%$color%>><% $part->minutes %></TD>
201 %     if ( $part->shared ) {
202       <TD><I>(shared)</I></TD>
203 %     }
204     </TR>
205 %   }
206   </TABLE>
207 % }
208
209
210 % ###
211 % # Package actions dropdown
212 % ###
213 % unless ( $opt{no_links} ) {
214
215   <TABLE CLASS="inv package"> 
216     <TR>
217       <TD COLSPAN=2>
218
219 %       my $plink = "pkgnum=$pkgnum";
220 %       my $reg_recur_cond =  sub { $part_pkg->freq ne '0'
221 %                                       && ! $change_from
222 %                                       && ! $supplemental
223 %                                       && ! $cust_pkg->get('cancel')
224 %                                 };
225 %       my $change_cond = sub { $part_pkg->freq ne '0'
226 %                                 && ! $change_from
227 %                                 && ! $supplemental
228 %                                 && ! $cust_pkg->get('cancel')
229 %                                 && $cust_pkg->change_to_pkgnum,
230 %                             };
231
232         <& /elements/dropdown-menu.html,
233              id      => 'cust_pkg'. $cust_pkg->pkgnum. '_menu',
234              bgcolor => $opt{row} % 2 ? '#ffffff' : '#eeeeee',
235              menu    => [
236                [ 
237
238                  #TODO: order/group these better
239
240                  { label => 'Package actions',
241                    content =>
242                     '<FONT STYLE="text-decoration:underline;font-weight:bold">'.
243                     'Package actions</FONT>'.
244                     ' <IMG SRC="'.$p.'images/arrow.down.black.png">',
245                  },
246
247                  { label       => 'Modify one-time charge',
248                    acl         => 'Modify one-time charge',
249                    condition   => sub { $part_pkg->freq eq '0' },
250                    url         => "edit/quick-charge.html?change_$plink",
251                  },
252
253                  { label       => 'Change package',
254                    acl         => 'Change customer package',
255                    condition   => $reg_recur_cond,
256                    popup       => "misc/change_pkg.cgi?$plink".
257                                     ';locationnum='. $cust_pkg->locationnum,
258                    actionlabel => emt('Change package'),
259                    #width       => 768,
260                    width       => 960,
261                    height      => 538,
262                  },
263
264                  { label       => 'Discount package',
265                    condition   => sub {     ! $change_from
266                                          && ! $supplemental
267                                          && ! $cust_pkg->get('cancel')
268                                          && $can_discount_pkg
269                                       },
270                    popup       => "edit/cust_pkg_discount.html?$plink",
271                    actionlabel => emt('Discount package'),
272                    width       => 616,
273                  },
274
275                  { label       => 'Customize package',
276                    acl         => 'Customize customer package',
277                    condition   => $reg_recur_cond,
278                    url         => "edit/part_pkg.cgi?$plink".
279                                     ';clone='. $part_pkg->pkgpart,
280                  },
281
282                  { label       => '-',
283                    content     => '-',
284                  },
285
286                  { label       => 'View package events',
287                    acl         => [ 'Billing event reports',
288                                     'View customer billing events', ],
289                    condition   => sub { $cust_pkg->exists_cust_event },
290                    url         => "search/cust_event.html?$plink",
291                  },
292
293                  { label       => '-',
294                    condition   => sub { $cust_pkg->exists_cust_event },
295                    content     => '-',
296                  },
297
298                  { label       => 'Change quantity',
299                    acl         => 'Change customer package',
300                    condition   => sub { $part_pkg->freq ne '0'
301                                         && ! $change_from
302                                         && ! $supplemental
303                                         && ! $cust_pkg->get('cancel')
304                                         && $opt{'invoice-unitprice'}
305                                   },
306                    popup       => "edit/cust_pkg_quantity.html?$plink",
307
308                    actionlabel => emt('Change quantity'),
309                    width       => 390,
310                    height      => 220,
311                  },
312
313                  { label       => 'Change sales person',
314                    acl         => 'Change customer package',
315                    condition   => sub { ! $change_from
316                                         && ! $supplemental
317                                         && ! $cust_pkg->get('cancel')
318                                   },
319                    popup       => "edit/cust_pkg_salesnum.html?$plink",
320                    actionlabel => emt('Change sales persion'),
321                    width       => 390,
322                    height      => 220,
323                  },
324
325                  { label       => '-',
326                    content     => '-',
327                  },
328
329                  { label       => (@invoice_detail ? 'Edit' : 'Add').
330                                     ' invoice details',
331                    acl         => 'Edit customer package invoice details',
332                    condition   => sub { ! $cust_pkg->get('cancel') },
333                    popup       => "edit/cust_pkg_detail.html?$plink".
334                                     ';detailtype=I',
335                    actionlabel => emt( (@invoice_detail ? 'Edit' : 'Add').
336                                        ' invoice details'
337                                      ),
338                    width       => 768,
339                  },
340
341                  { label        => (@comments ? 'Edit' : 'Add'). ' comments',
342                    acl         => 'Edit customer package comments',
343                    popup       => "edit/cust_pkg_detail.html?$plink".
344                                     ';detailtype=C',
345                    actionlabel => emt( (@comments ? 'Edit' : 'Add').
346                                        ' comments'
347                                      ),
348                    width       => 768,
349                  },
350
351                  { label       => '-',
352                    #condition   => sub { $part_pkg->freq ne '0' },
353                    content     => '-',
354                  },
355
356                  { label       => 'Set start date',
357                    acl         => 'Change package start date',
358                    condition   => sub { $part_pkg->freq ne '0'
359                                           && ! $change_from
360                                           && ! $supplemental
361                                           && ! $cust_pkg->get('cancel')
362                                           && ! $cust_pkg->get('setup')
363                                       },
364                   popup       => "misc/change_pkg_date.html?$plink".
365                                    ';field=start_date',
366                   actionlabel => emt('Set start of billing for'),
367                   width       => 510,
368                   height      => 310,
369                  },
370
371                  { label       => 'Set contract end',
372                    acl         => 'Change package contract end date',
373                    condition   => sub { $part_pkg->freq ne '0'
374                                           && ! $change_from
375                                           && ! $supplemental
376                                           && ! $cust_pkg->get('cancel')
377                                           && ! $cust_pkg->change_to_pkgnum
378                                       },
379                    popup       => "misc/change_pkg_date.html?$plink".
380                                    ';field=contract_end',
381                    actionlabel => emt('Set contract end for'),
382                    width       => 510,
383                    height      => 310,
384                  },
385
386                  { label       => '-',
387                    condition   => sub { $part_pkg->freq ne '0' },
388                    content     => '-',
389                  },
390
391                  { label       => 'Change now',
392                    acl         => 'Change customer package',
393                    condition   => $change_cond,
394                    url         => "misc/change_pkg_now.cgi?$pkgnum",
395                  },
396
397                  { label       => 'Reschedule',
398                    acl         => 'Change customer package',
399                    condition   => sub { $part_pkg->freq ne '0'
400                                           && ! $change_from
401                                           && ! $supplemental
402                                           && ! $cust_pkg->get('cancel')
403                                           && $cust_pkg->change_to_pkgnum,
404                                       },
405                    popup       => "misc/change_pkg.html?$plink",
406                    actionlabel => emt('Edit scheduled change for'),
407                    url         => "misc/change_pkg_now.cgi?$pkgnum",
408                    width       => 960,
409                    height      => 490,
410     
411                  },
412
413                  { label       => 'Abort change',
414                    acl         => 'Change customer package',
415                    condition   => $change_cond,
416                    url         => "misc/do_not_change_pkg.cgi?$pkgnum",
417                  },
418
419                  { label       => '-',
420                    acl         => 'Change customer package',
421                    condition   => $change_cond,
422                    content     => '-',
423                  },
424
425                  { label       => 'Suspend now',
426                    acl         => 'Suspend customer package',
427                    condition   => sub { $part_pkg->freq ne '0'
428                                           && ! $change_from
429                                           && ! $supplemental
430                                           && ! $cust_pkg->get('cancel')
431                                           && ! $cust_pkg->get('susp')
432                                       },
433                    popup       => "misc/cancel_pkg.html?method=suspend;$plink",
434                    actionlabel => emt('Suspend now'),
435                    color       => '#FF9900',
436                    width       => 768,
437                    height      => 420,
438                  },
439
440                  { label       => 'Suspend later',
441                    acl         => 'Suspend customer package later',
442                    condition   => sub { $part_pkg->freq ne '0'
443                                           && ! $change_from
444                                           && ! $supplemental
445                                           && ! $cust_pkg->get('cancel')
446                                           && ! $cust_pkg->get('susp')
447                                       },
448                    popup       => "misc/cancel_pkg.html?method=adjourn;$plink",
449                    actionlabel => emt('Suspend later'),
450                    color       => '#CC6600',
451                    width       => 768,
452                    height      => 445,
453                  },
454
455                  { label       => $cust_pkg->dundate
456                                     ? 'Edit suspension delay'
457                                     : 'Delay suspend',
458
459                    acl         => 'Delay suspension events',
460                    condition   => sub { $part_pkg->freq ne '0'
461                                           && ! $change_from
462                                           && ! $supplemental
463                                           && ! $cust_pkg->get('cancel')
464                                           && ! $cust_pkg->get('susp')
465                                       },
466                    popup       => "misc/delay_susp_pkg.html?$plink",
467                    actionlabel => emt('Delay suspend for'),
468                    width       => 768,
469                  },
470
471                  { label       => 'Start billing',
472                    acl         => 'Unsuspend customer package',
473                    condition   => sub {    ! $change_from
474                                         && ! $supplemental
475                                         && ! $cust_pkg->get('cancel')
476                                         && $cust_pkg->get('susp')
477                                         && $cust_pkg->order_date == $cust_pkg->get('susp')
478                                       },
479                    popup        => "misc/unhold_pkg.html?$plink",
480                    actionlabel  => emt('Start billing'),
481                    color       => '#00CC00',
482                    width       => 510,
483                    height      => 310,
484                  },
485
486                  { label       => 'Unsuspend now',
487                    acl         => 'Unsuspend customer package',
488                    condition   => sub { $part_pkg->freq ne '0'
489                                           && ! $change_from
490                                           && ! $supplemental
491                                           && ! $cust_pkg->get('cancel')
492                                           && $cust_pkg->get('susp')
493                                           && $cust_pkg->order_date != $cust_pkg->get('susp')
494                                       },
495                    'url'       => "misc/unsusp_pkg.cgi?$pkgnum",
496                  },
497
498                  { label       => 'Unsuspend later',
499                    acl         => 'Unsuspend customer package',
500                    condition   => sub { $part_pkg->freq ne '0'
501                                           && ! $change_from
502                                           && ! $supplemental
503                                           && ! $cust_pkg->get('cancel')
504                                           && $cust_pkg->get('susp')
505                                           && $cust_pkg->order_date != $cust_pkg->get('susp')
506                                       },
507                    popup       => "misc/cancel_pkg.html?method=resume;$plink",
508                    actionlabel => emt('Unsuspend later'),
509                    color       => '#00CC00',
510                    width       => 768,
511                  },
512
513                  { label       => '-',
514                    condition   => sub { $part_pkg->freq ne '0'
515                                           && ! $change_from
516                                           && ! $supplemental
517                                           && ! $cust_pkg->get('cancel')
518                                           && ! $cust_pkg->get('susp')
519                                       },
520                    content     => '-',
521                  },
522
523                  { label       => 'Cancel now',
524                    acl         => 'Cancel customer package immediately',
525                    condition   => sub {
526                      ( $part_pkg->freq ne '0' || ! $cust_pkg->get('setup') )
527                        && ! $change_from
528                        && ! $supplemental
529                        && ! $cust_pkg->change_to_pkgnum
530                        && ! $cust_pkg->get('cancel')
531                    },
532                    popup       => "misc/cancel_pkg.html?method=cancel;$plink",
533                    actionlabel => emt('Cancel now'),
534                    color       => '#FF0000',
535                    width       => 768,
536                  },
537
538                  { label       => 'Cancel later',
539                    acl         => 'Cancel customer package later',
540                    condition   => sub { $part_pkg->freq ne '0'
541                                           && ! $change_from
542                                           && ! $supplemental
543                                           && ! $cust_pkg->change_to_pkgnum
544                                           && ! $cust_pkg->get('cancel')
545                                       },
546                    popup       => "misc/cancel_pkg.html?method=expire;$plink",
547                    actionlabel => emt('Cancel later'),
548                    color       => '#CC0000',
549                    width       => 768,
550                  },
551
552                  { label       => 'Un-cancel',
553                    acl         => 'Un-cancel customer package',
554                    condition   => sub { $part_pkg->freq ne '0'
555                                           && ! $supplemental
556                                           && ! $cust_pkg->change_custnum
557                                           && $cust_pkg->get('cancel')
558                                       },
559                    popup       => "misc/cancel_pkg.html?method=uncancel;$plink",
560                    actionlabel => emt('Un-cancel'),
561                    width       => 960,
562                    height      => 740,
563
564                  },
565
566                  { label       => '-',
567                    condition   => sub {
568                      ( $part_pkg->freq ne '0' || ! $cust_pkg->get('setup') )
569                        && ! $change_from
570                        && ! $cust_pkg->get('cancel')
571                    },
572                    content     => '-',
573                  },
574
575                  { label       => 'Add contact',
576                    #acl         => 'Add package contact',#or something like that
577                    condition   => sub { ! $cust_pkg->get('cancel') },
578                    popup       => "misc/change_pkg_contact.html?$plink",
579                    actionlabel => emt('Add contact'),
580                    width       => 616,
581                    height      => 200,
582                  },
583
584                  { label       => 'Change location',
585                    acl         => 'Change customer package',
586                    condition   => sub { ! $change_from },
587                    popup       => "misc/change_pkg.cgi?locationnum=-1;$plink;".
588                       "address1=;address2=;city=;county=;state=$statedefault;".
589                       "zip=;country=$countrydefault",
590                    actionlabel => emt('Change location'),
591                    width       => 960,
592                    height      => 530,
593                  },
594
595                  { label       => 'Edit location',
596                    acl         => 'Change customer package',
597                    condition   => sub { ! $change_from && $cust_pkg->locationnum != $cust_pkg->cust_main->ship_locationnum  },
598                    popup       => 'misc/cust_location.cgi?locationnum='.
599                                     $cust_pkg->locationnum,
600                    actionlabel => emt('Edit location'),
601                    width       => 700,
602                    height      => 355,
603                  },
604
605                ],
606              ],
607         &>
608
609       </TD>
610     </TR>
611   </TABLE>
612
613 % }
614
615   <% join('', map '</DIV>', @marker ) %>
616
617 </TD>
618
619 <%init>
620
621 my %opt = @_;
622
623 my $bgcolor  = $opt{'bgcolor'};
624 my $cust_pkg = $opt{'cust_pkg'};
625 my $part_pkg = $opt{'part_pkg'};
626
627 my $curuser = $FS::CurrentUser::CurrentUser;
628
629 my $countrydefault = $opt{'countrydefault'} || 'US';
630 my $statedefault   = $opt{'statedefault'}
631                      || ($countrydefault eq 'US' ? 'CA' : '');
632
633 # put a marker on the left edge of this column
634 # if this package is somehow special
635 my $supplemental = $opt{'supplemental'} || 0;
636 my $change_from = $opt{'change_from'} || 0;
637 my @marker;
638 if ( $supplemental ) {
639   push @marker, '<DIV CLASS="package-marker-supplemental">';
640 }
641 if ( $change_from ) {
642   push @marker, '<DIV CLASS="package-marker-change_from">';
643 }
644
645 $cust_pkg->pkgnum =~ /^(\d+)$/;
646 my $pkgnum = $1;
647 my @cust_pkg_usage = qsearch({
648   'select'    => 'cust_pkg_usage.*',
649   'table'     => 'cust_pkg_usage',
650   'addl_from' => ' JOIN part_pkg_usage USING (pkgusagepart)',
651   'extra_sql' => " WHERE pkgnum = $1",
652   'order_by'  => ' ORDER BY priority ASC, description ASC',
653 });
654
655 #subroutines
656
657 #false laziness w/status.html
658 sub pkg_link {
659   my($action, $label, $cust_pkg) = @_;
660   return '' unless $cust_pkg;
661   qq!<a href="$p$action.cgi?!. $cust_pkg->pkgnum. qq!">$label</a>!;
662 }
663
664 sub pkg_change_location_link {
665   my $cust_pkg = shift;
666   my $pkgpart = $cust_pkg->pkgpart;
667   include( '/elements/popup_link-cust_pkg.html',
668     'action'      => $p. "misc/change_pkg.cgi?locationnum=-1;pkgpart=$pkgpart;".
669                      "address1=;address2=;city=;county=;state=$statedefault;".
670                      "zip=;country=$countrydefault",
671     'label'       => emt('Change location'),
672     'actionlabel' => emt('Change'),
673     'cust_pkg'    => $cust_pkg,
674     'width'       => 960,
675     'height'      => 530,
676   );
677 }
678
679 sub pkg_change_quantity_link {
680   my( $cust_pkg, $label ) = @_;
681   include( '/elements/popup_link-cust_pkg.html',
682     'action'      => $p. 'edit/cust_pkg_quantity.html?',
683     'label'       => emt($label),
684     'actionlabel' => emt('Change'),
685     'cust_pkg'    => $cust_pkg,
686     'width'       => 390,
687     'height'      => 220,
688   );
689 }
690
691 sub pkg_change_salesnum_link {
692   my( $cust_pkg, $label ) = @_;
693   include( '/elements/popup_link-cust_pkg.html',
694     'action'      => $p. 'edit/cust_pkg_salesnum.html?',
695     'label'       => emt($label),
696     'actionlabel' => emt('Change'),
697     'cust_pkg'    => $cust_pkg,
698     'width'       => 390,
699     'height'      => 220,
700   );
701 }
702
703 # figure out if this user will be able to edit either the setup or recurring
704 # discounts for this package
705 my $can_discount_pkg = 0;
706
707 if ( $part_pkg->can_discount ) {
708   #looking these up individually uses the ACL cache and is a big win for lots
709   # of packages
710   my $discount = $curuser->access_right('Discount customer package');
711   my $waive    = $curuser->access_right('Waive setup fee');
712
713   $can_discount_pkg = 
714     (   ($discount || $waive) 
715           && $cust_pkg->base_setup > 0
716           && !$cust_pkg->setup
717      or
718         ( $discount
719           && $cust_pkg->base_recur > 0
720           && $cust_pkg->freq ne '0'
721         )
722     );
723
724 }
725
726 </%init>