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