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