move services between packages, RT#22619
[freeside.git] / httemplate / view / cust_main / packages / package.html
1 <TD CLASS="inv package" BGCOLOR="<% $bgcolor %>" VALIGN="top"
2   STYLE="border-left-width: <% $supplemental * 30 %>px">
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         <A NAME="cust_pkg<% $cust_pkg->pkgnum %>"
11            ID  ="cust_pkg<% $cust_pkg->pkgnum %>"
12         ><% $curuser->option('show_pkgnum') ? $cust_pkg->pkgnum.': ' : '' %><B><% $part_pkg->pkg |h %></B></A>
13         - 
14         <% $part_pkg->custom_comment |h %>
15       </TD>
16     </TR>
17
18 % if ( $cust_pkg->quantity > 1 ) {
19     <TR>
20       <TD COLSPAN=2>
21         &nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;<% mt('Quantity:') |h %> 
22         <B><% $cust_pkg->quantity %></B>
23       </TD>
24     </TR>
25 % }
26
27     <TR>
28       <TD COLSPAN=2>
29         <FONT SIZE=-1>
30
31 %         unless ( $cust_pkg->get('cancel') || $opt{no_links} ) {
32 %
33 %           if ( $supplemental or $part_pkg->freq eq '0' ) {
34 %             # Supplemental packages can't be changed independently.
35 %             # One-time charges don't need to be changed.
36 %             # For both of those, we only show "Edit dates", "Add comments",
37 %             # and "Add invoice details".
38 %             if ( $curuser->access_right('Edit customer package dates') ) {
39                 (&nbsp;<%pkg_dates_link($cust_pkg)%>&nbsp;)
40 %             }
41 %           } else {
42 %             # the usual case: links to change package definition,
43 %             # discount, and customization
44 %             my $br = 0;
45 %             if ( $curuser->access_right('Change customer package') ) {
46 %               $br=1;
47                 (&nbsp;<%pkg_change_link($cust_pkg)%>&nbsp;)
48 %             } 
49 %
50 %             if ( $curuser->access_right('Edit customer package dates') ) {
51 %               $br=1;
52                 (&nbsp;<%pkg_dates_link($cust_pkg)%>&nbsp;)
53 %             } 
54 %
55 %             if ( $curuser->access_right('Discount customer package')
56 %                  && $part_pkg->can_discount
57 %                  && ! scalar($cust_pkg->cust_pkg_discount_active)
58 %                  && ! scalar($cust_pkg->part_pkg->part_pkg_discount)
59 %                )
60 %             {
61 %               $br=1;
62                 (&nbsp;<%pkg_discount_link($cust_pkg)%>&nbsp;)
63 %             }
64 %
65 %             if ( $curuser->access_right('Customize customer package') ) {
66 %               $br=1;
67                 (&nbsp;<%pkg_customize_link($cust_pkg,$part_pkg)%>&nbsp;)
68 %             } 
69 %
70               <% $br ? '<BR>' : '' %>
71 %           } 
72
73 %           if ( $cust_pkg->num_cust_event
74 %                && (    $curuser->access_right('Billing event reports')
75 %                     || $curuser->access_right('View customer billing events')
76 %                   )
77 %              ) {
78               (&nbsp;<%pkg_event_link($cust_pkg)%>&nbsp;)
79 %           }
80 %         } #!$supplemental
81
82         </FONT>
83       </TD>
84     </TR>
85
86 %   my $editi = $curuser->access_right('Edit customer package invoice details');
87 %   my $editc = $curuser->access_right('Edit customer package comments');
88 %   my @cust_pkg_detail = $cust_pkg->cust_pkg_detail;
89 %   my @invoice_detail = grep { $_->detailtype eq 'I' } @cust_pkg_detail;
90 %   my @comments       = grep { $_->detailtype eq 'C' } @cust_pkg_detail;
91 %
92 %   if ( scalar(@invoice_detail) || scalar(@comments) || $editi || $editc ) {
93 %
94 %     my $editlink = $p. 'edit/cust_pkg_detail.html?pkgnum='. $cust_pkg->pkgnum.
95 %                    ';detailtype=';
96
97       <TR>
98
99 %       if ( @invoice_detail ) {
100           <TD VALIGN="top">
101             <& /elements/table-grid.html &>
102               <TR>
103                 <TH BGCOLOR="#dddddd" STYLE="border-bottom: dashed 1px black; padding-bottom: 1px">
104                   <FONT SIZE="-1">
105                     <% mt('Invoice details') |h %> 
106 %                   if ( $editi && ! $cust_pkg->get('cancel') && ! $opt{no_links} ) {
107                       (<& /elements/popup_link.html, { 
108                                     'action'      => $editlink. 'I',
109                                     'label'       => emt('edit'),
110                                     'actionlabel' => emt('Edit invoice details'),
111                                     'color'       => '#333399',
112                                     'width'       => 763,
113                                  }
114                        &>)
115 %                   }
116                   </FONT>
117                 </TH>
118               </TR>
119 %             foreach my $cust_pkg_detail ( @invoice_detail ) {
120                 <TR>
121                   <TD><FONT SIZE="-1">&nbsp;-&nbsp;<% $cust_pkg_detail->detail |h %></FONT></TD>
122                 </TR>
123 %             }
124             </TABLE>
125           </TD>
126 %       } else {
127           <TD>
128 %           if ( $editi && ! $cust_pkg->get('cancel') && ! $opt{no_links} ) {
129               <FONT SIZE="-1">
130                 (&nbsp;<% include('/elements/popup_link.html', { 
131                                'action'      => $editlink. 'I',
132                                'label'       => emt('Add invoice details'),
133                                'actionlabel' => emt('Add invoice details'),
134                                'color'       => '#333399',
135                                'width'       => 763,
136                             })
137                   %>&nbsp;)
138               </FONT>
139 %           }
140           </TD>
141 %       }
142
143 %       if ( @comments ) { 
144           <TD VALIGN="top">
145             <& /elements/table-grid.html &>
146               <TR>
147                 <TH BGCOLOR="#dddddd" STYLE="border-bottom: dashed 1px black; padding-bottom: 1px">
148                   <FONT SIZE="-1">
149                     <% mt('Comments') |h %> 
150 %                   if ( $editc && ! $opt{no_links} ) {
151                       (<& /elements/popup_link.html, { 
152                                     'action'      => $editlink. 'C',
153                                     'label'       => emt('edit'),
154                                     'actionlabel' => emt('Edit comments'),
155                                     'color'       => '#333399',
156                                     'width'       => 763,
157                                  }
158                        &>)
159 %                   }
160                   </FONT>
161                 </TH>
162               </TR>
163 %             foreach my $cust_pkg_detail ( @comments ) {
164                 <TR>
165                   <TD><FONT SIZE="-1">&nbsp;-&nbsp;<% $cust_pkg_detail->detail |h %></FONT></TD>
166                 </TR>
167 %             }
168             </TABLE>
169           </TD>
170 %       } else {
171           <TD>
172 %           if ( $editc && ! $opt{no_links} ) {
173               <FONT SIZE="-1">
174                 (&nbsp;<& /elements/popup_link.html, { 
175                                'action'      => $editlink. 'C',
176                                'label'       => emt('Add comments'),
177                                'actionlabel' => emt('Add comments'),
178                                'color'       => '#333399',
179                                'width'       => 763,
180                             }
181                   &>&nbsp;)
182               </FONT>
183 %           }
184           </TD>
185 %       }
186
187       </TR>
188 %     if ( $curuser->access_right('Change customer package')
189 %            && ! $cust_pkg->get('cancel')
190 %            && ! $supplemental
191 %            && $part_pkg->freq ne '0'
192 %            && ! $opt{no_links}
193 %        )
194 %     {
195       <TR>
196 %       if ( FS::Conf->new->exists('invoice-unitprice') ) {
197         <TD><FONT SIZE="-1">
198           (&nbsp;<% pkg_change_quantity_link($cust_pkg) %>&nbsp;)
199         </FONT></TD>
200 %       }
201       </TR>
202 %     }
203 %   }
204   </TABLE>
205 % if ( @cust_pkg_usage ) {
206   <TABLE CLASS="usage inv">
207     <TR><TH COLSPAN=4><% mt('Included usage') %></TH></TR>
208 %   foreach my $usage (@cust_pkg_usage) {
209 %     my $part = $usage->part_pkg_usage;
210 %     my $ratio = 255 * ($usage->minutes / $part->minutes);
211 %     $ratio = 255 if $ratio > 255; # because rollover
212 %     my $color = sprintf('STYLE="font-weight: bold; color: #%02x%02x00"', 255 - $ratio, $ratio);
213 %     my $trstyle = '';
214 %     $trstyle = ' CLASS="shared"' if $part->shared;
215     <TR<%$trstyle%>>
216       <TD ALIGN="right"><% $part->description %>: </TD>
217       <TD <%$color%> ALIGN="right"><% $usage->minutes %></TD>
218       <TD <%$color%>> / </TD>
219       <TD <%$color%>><% $part->minutes %></TD>
220 %     if ( $part->shared ) {
221       <TD><I>(shared)</I></TD>
222 %     }
223     </TR>
224 %   }
225   </TABLE>
226 % }
227
228 </TD>
229
230 <%init>
231
232 my %opt = @_;
233
234 my $bgcolor  = $opt{'bgcolor'};
235 my $cust_pkg = $opt{'cust_pkg'};
236 my $part_pkg = $opt{'part_pkg'};
237
238 my $curuser = $FS::CurrentUser::CurrentUser;
239
240 my $countrydefault = $opt{'countrydefault'} || 'US';
241 my $statedefault   = $opt{'statedefault'}
242                      || ($countrydefault eq 'US' ? 'CA' : '');
243
244 my $supplemental = $opt{'supplemental'} || 0;
245
246 $cust_pkg->pkgnum =~ /^(\d+)$/;
247 my $pkgnum = $1;
248 my @cust_pkg_usage = qsearch({
249   'select'    => 'cust_pkg_usage.*',
250   'table'     => 'cust_pkg_usage',
251   'addl_from' => ' JOIN part_pkg_usage USING (pkgusagepart)',
252   'extra_sql' => " WHERE pkgnum = $1",
253   'order_by'  => ' ORDER BY priority ASC, description ASC',
254 });
255
256 #subroutines
257
258 #false laziness w/status.html
259 sub pkg_link {
260   my($action, $label, $cust_pkg) = @_;
261   return '' unless $cust_pkg;
262   qq!<a href="$p$action.cgi?!. $cust_pkg->pkgnum. qq!">$label</a>!;
263 }
264
265 sub pkg_change_link {
266   my $cust_pkg = shift;
267   my $locationnum = $cust_pkg->locationnum;
268   include( '/elements/popup_link-cust_pkg.html',
269     'action'      => $p. "misc/change_pkg.cgi?locationnum=$locationnum",
270     'label'       => emt('Change package'),
271     'actionlabel' => emt('Change'),
272     'cust_pkg'    => $cust_pkg,
273   );
274 }
275
276 sub pkg_change_location_link {
277   my $cust_pkg = shift;
278   my $pkgpart = $cust_pkg->pkgpart;
279   include( '/elements/popup_link-cust_pkg.html',
280     'action'      => $p. "misc/change_pkg.cgi?locationnum=-1;pkgpart=$pkgpart;".
281                      "address1=;address2=;city=;county=;state=$statedefault;".
282                      "zip=;country=$countrydefault",
283     'label'       => emt('Change location'),
284     'actionlabel' => emt('Change'),
285     'cust_pkg'    => $cust_pkg,
286   );
287 }
288
289 sub pkg_change_quantity_link {
290   include( '/elements/popup_link-cust_pkg.html',
291     'action'      => $p. 'edit/cust_pkg_quantity.html?',
292     'label'       => emt('Change quantity'),
293     'actionlabel' => emt('Change'),
294     'cust_pkg'    => shift,
295     'width'       => 390,
296     'height'      => 220,
297   );
298 }
299
300 sub pkg_dates_link { pkg_link('edit/REAL_cust_pkg', emt('Edit dates'), @_ ); }
301
302 sub pkg_discount_link {
303   my $cust_pkg = shift or return '';
304   include( '/elements/popup_link-cust_pkg.html',
305     'action'      => $p.'edit/cust_pkg_discount.html',
306     'label'       => emt('Discount'),
307     'actionlabel' => emt('Discount'),
308     'cust_pkg'    => $cust_pkg,
309     'width'       => 616,
310   );
311 }
312
313 sub pkg_customize_link {
314   my $cust_pkg = shift or return '';
315   my $part_pkg = shift;
316   my $custnum = $cust_pkg->custnum;
317   qq!<A HREF="${p}edit/part_pkg.cgi?!.
318     "clone=". $part_pkg->pkgpart. ';'.
319     "pkgnum=". $cust_pkg->pkgnum.
320     qq!">!.emt('Customize').'</A>';
321 }
322
323 sub pkg_event_link {
324   my($cust_pkg) = @_;
325   qq!<a href="${p}search/cust_event.html?pkgnum=!. $cust_pkg->pkgnum. qq!">!.
326   emt('View package events').
327   '</a>';
328 }
329
330 </%init>