cust_location editing features, RT#10766
[freeside.git] / httemplate / view / cust_main / packages / package.html
1 <TD CLASS="inv" BGCOLOR="<% $bgcolor %>" VALIGN="top">
2   <TABLE CLASS="inv" BORDER=0 CELLSPACING=0 CELLPADDING=0 WIDTH="100%">
3     <TR>
4       <TD COLSPAN=2>
5         <A NAME="cust_pkg<% $cust_pkg->pkgnum %>"
6            ID  ="cust_pkg<% $cust_pkg->pkgnum %>"
7         ><% $curuser->option('show_pkgnum') ? $cust_pkg->pkgnum.': ' : '' %><B><% $part_pkg->pkg |h %></B></A>
8         - 
9         <% $part_pkg->custom_comment |h %>
10       </TD>
11     </TR>
12
13 % if ( $cust_pkg->quantity > 1 ) {
14     <TR>
15       <TD COLSPAN=2>
16         &nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;Quantity: 
17         <B><% $cust_pkg->quantity %></B>
18       </TD>
19     </TR>
20 %  }
21
22     <TR>
23       <TD COLSPAN=2>
24         <FONT SIZE=-1>
25
26 %         unless ( $cust_pkg->get('cancel') ) { 
27 %
28 %           my $br = 0;
29 %           if ( $curuser->access_right('Change customer package') ) {
30 %             $br=1;
31               (&nbsp;<%pkg_change_link($cust_pkg)%>&nbsp;)
32 %           } 
33 %
34 %           if ( $curuser->access_right('Edit customer package dates') ) {
35 %             $br=1;
36               (&nbsp;<%pkg_dates_link($cust_pkg)%>&nbsp;)
37 %           } 
38 %
39 %           if ( $curuser->access_right('Discount customer package')
40 %                && $part_pkg->can_discount
41 %                && ! scalar($cust_pkg->cust_pkg_discount_active)
42 %                && ! scalar($cust_pkg->part_pkg->part_pkg_discount)
43 %              )
44 %           {
45 %             $br=1;
46               (&nbsp;<%pkg_discount_link($cust_pkg)%>&nbsp;)
47 %           }
48 %
49 %           if ( $curuser->access_right('Customize customer package') ) {
50 %             $br=1;
51               (&nbsp;<%pkg_customize_link($cust_pkg,$part_pkg)%>&nbsp;)
52 %           } 
53 %
54             <% $br ? '<BR>' : '' %>
55 %         } 
56
57 %         if ( $cust_pkg->num_cust_event
58 %              && (    $curuser->access_right('Billing event reports')
59 %                   || $curuser->access_right('View customer billing events')
60 %                 )
61 %            ) {
62             (&nbsp;<%pkg_event_link($cust_pkg)%>&nbsp;)
63 %         }
64
65         </FONT>
66       </TD>
67     </TR>
68
69 %   my $editi = $curuser->access_right('Edit customer package invoice details');
70 %   my $editc = $curuser->access_right('Edit customer package comments');
71 %   my @cust_pkg_detail = $cust_pkg->cust_pkg_detail;
72 %   my @invoice_detail = grep { $_->detailtype eq 'I' } @cust_pkg_detail;
73 %   my @comments       = grep { $_->detailtype eq 'C' } @cust_pkg_detail;
74 %
75 %   if ( scalar(@invoice_detail) || scalar(@comments) || $editi || $editc ) {
76 %
77 %     my $editlink = $p. 'edit/cust_pkg_detail?pkgnum='. $cust_pkg->pkgnum.
78 %                    ';detailtype=';
79
80       <TR>
81
82 %       if ( @invoice_detail ) {
83           <TD VALIGN="top">
84             <% include('/elements/table-grid.html') %>
85               <TR>
86                 <TH BGCOLOR="#dddddd" STYLE="border-bottom: dashed 1px black; padding-bottom: 1px">
87                   <FONT SIZE="-1">
88                     Invoice details
89 %                   if ( $editi && ! $cust_pkg->get('cancel') ) {
90                       (<% include('/elements/popup_link.html', { 
91                                     'action'      => $editlink. 'I',
92                                     'label'       => 'edit',
93                                     'actionlabel' => 'Edit invoice details',
94                                     'color'       => '#333399',
95                                     'width'       => 763,
96                                  })
97                        %>)
98 %                   }
99                   </FONT>
100                 </TH>
101               </TR>
102 %             foreach my $cust_pkg_detail ( @invoice_detail ) {
103                 <TR>
104                   <TD><FONT SIZE="-1">&nbsp;-&nbsp;<% $cust_pkg_detail->detail |h %></FONT></TD>
105                 </TR>
106 %             }
107             </TABLE>
108           </TD>
109 %       } else {
110           <TD>
111 %           if ( $editi && ! $cust_pkg->get('cancel') ) {
112               <FONT SIZE="-1">
113                 (&nbsp;<% include('/elements/popup_link.html', { 
114                                'action'      => $editlink. 'I',
115                                'label'       => 'Add&nbsp;invoice&nbsp;details',
116                                'actionlabel' => 'Add invoice details',
117                                'color'       => '#333399',
118                                'width'       => 763,
119                             })
120                   %>&nbsp;)
121               </FONT>
122 %           }
123           </TD>
124 %       }
125
126 %       if ( @comments ) { 
127           <TD VALIGN="top">
128             <% include('/elements/table-grid.html') %>
129               <TR>
130                 <TH BGCOLOR="#dddddd" STYLE="border-bottom: dashed 1px black; padding-bottom: 1px">
131                   <FONT SIZE="-1">
132                     Comments
133 %                   if ( $editc ) {
134                       (<% include('/elements/popup_link.html', { 
135                                     'action'      => $editlink. 'C',
136                                     'label'       => 'edit',
137                                     'actionlabel' => 'Edit comments',
138                                     'color'       => '#333399',
139                                     'width'       => 763,
140                                  })
141                        %>)
142 %                   }
143                   </FONT>
144                 </TH>
145               </TR>
146 %             foreach my $cust_pkg_detail ( @comments ) {
147                 <TR>
148                   <TD><FONT SIZE="-1">&nbsp;-&nbsp;<% $cust_pkg_detail->detail |h %></FONT></TD>
149                 </TR>
150 %             }
151             </TABLE>
152           </TD>
153 %       } else {
154           <TD>
155 %           if ( $editc ) {
156               <FONT SIZE="-1">
157                 (&nbsp;<% include('/elements/popup_link.html', { 
158                                'action'      => $editlink. 'C',
159                                'label'       => 'Add&nbsp;comments',
160                                'actionlabel' => 'Add comments',
161                                'color'       => '#333399',
162                                'width'       => 763,
163                             })
164                   %>&nbsp;)
165               </FONT>
166 %           }
167           </TD>
168 %       }
169
170       </TR>
171 %     if ( $curuser->access_right('Change customer package') and 
172 %           !$cust_pkg->get('cancel') and
173 %           !$opt{'show_location'}) {
174       <TR>
175         <TD><FONT SIZE="-1">
176           (&nbsp;<% pkg_change_location_link($cust_pkg) %>&nbsp;)
177         </FONT></TD>
178       </TR>
179 %     }
180 %   }
181   </TABLE>
182
183 </TD>
184
185 <%init>
186
187 my %opt = @_;
188
189 my $bgcolor  = $opt{'bgcolor'};
190 my $cust_pkg = $opt{'cust_pkg'};
191 my $part_pkg = $opt{'part_pkg'};
192
193 my $curuser = $FS::CurrentUser::CurrentUser;
194
195 my $countrydefault = $opt{'countrydefault'} || 'US';
196 my $statedefault   = $opt{'statedefault'}
197                      || ($countrydefault eq 'US' ? 'CA' : '');
198
199 #subroutines
200
201 #false laziness w/status.html
202 sub pkg_link {
203   my($action, $label, $cust_pkg) = @_;
204   return '' unless $cust_pkg;
205   qq!<a href="$p$action.cgi?!. $cust_pkg->pkgnum. qq!">$label</a>!;
206 }
207
208 sub pkg_change_link {
209   my $cust_pkg = shift;
210   my $locationnum = $cust_pkg->locationnum;
211   include( '/elements/popup_link-cust_pkg.html',
212     'action'      => $p. "misc/change_pkg.cgi?locationnum=$locationnum",
213     'label'       => 'Change&nbsp;package',
214     'actionlabel' => 'Change',
215     'cust_pkg'    => $cust_pkg,
216   );
217 }
218
219 sub pkg_change_location_link {
220   my $cust_pkg = shift;
221   my $pkgpart = $cust_pkg->pkgpart;
222   include( '/elements/popup_link-cust_pkg.html',
223     'action'      => $p. "misc/change_pkg.cgi?locationnum=-1;pkgpart=$pkgpart;".
224                      "address1=;address2=;city=;county=;state=$statedefault;".
225                      "zip=;country=$countrydefault",
226     'label'       => 'Change&nbsp;location',
227     'actionlabel' => 'Change',
228     'cust_pkg'    => $cust_pkg,
229   );
230 }
231
232 sub pkg_dates_link { pkg_link('edit/REAL_cust_pkg', 'Edit&nbsp;dates', @_ ); }
233
234 sub pkg_discount_link {
235   my $cust_pkg = shift or return '';
236   #my $part_pkg = shift;
237   #my $custnum = $cust_pkg->custnum;
238   include( '/elements/popup_link-cust_pkg.html',
239     'action'      => $p.'edit/cust_pkg_discount.html',
240     'label'       => 'Discount',
241     'actionlabel' => 'Discount',
242     'cust_pkg'    => $cust_pkg,
243     'width'       => 616,
244   );
245 }
246
247 sub pkg_customize_link {
248   my $cust_pkg = shift or return '';
249   my $part_pkg = shift;
250   my $custnum = $cust_pkg->custnum;
251   qq!<A HREF="${p}edit/part_pkg.cgi?!.
252     "clone=". $part_pkg->pkgpart. ';'.
253     "pkgnum=". $cust_pkg->pkgnum.
254     qq!">Customize</A>!;
255 }
256
257 sub pkg_event_link {
258   my($cust_pkg) = @_;
259   qq!<a href="${p}search/cust_event.html?pkgnum=!. $cust_pkg->pkgnum. qq!">!.
260   'View package events'.
261   '</a>';
262 }
263
264 </%init>