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