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