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