summaryrefslogtreecommitdiff
path: root/httemplate/view/cust_main/packages/package.html
blob: 78d3a885d6554396aaeb2a2237f06d7b2abee7cd (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
<TD CLASS="inv package" BGCOLOR="<% $bgcolor %>" VALIGN="top"
  STYLE="border-left-width: <% $supplemental * 30 %>px">
  <TABLE CLASS="inv package"> 
    <TR>
      <TD COLSPAN=2>
        <% $opt{before_pkg_callback}
             ? &{ $opt{before_pkg_callback} }( $cust_pkg )
             : ''
        %>
        <A NAME="cust_pkg<% $cust_pkg->pkgnum %>"
           ID  ="cust_pkg<% $cust_pkg->pkgnum %>"
        ><% $curuser->option('show_pkgnum') ? $cust_pkg->pkgnum.': ' : '' %><B><% $part_pkg->pkg |h %></B></A>
        - 
        <% $part_pkg->custom_comment |h %>
      </TD>
    </TR>

% if ( $cust_pkg->quantity > 1 ) {
    <TR>
      <TD COLSPAN=2>
        &nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;<% mt('Quantity:') |h %> 
        <B><% $cust_pkg->quantity %></B>
      </TD>
    </TR>
% }

    <TR>
      <TD COLSPAN=2>
        <FONT SIZE=-1>

%         unless ( $cust_pkg->get('cancel') || $opt{no_links} ) {
%
%           if ( $supplemental or $part_pkg->freq eq '0' ) {
%             # Supplemental packages can't be changed independently.
%             # One-time charges don't need to be changed.
%             # For both of those, we only show "Add comments",
%             # and "Add invoice details".
%           } else {
%             # the usual case: links to change package definition,
%             # discount, and customization
%             my $br = 0;
%             if ( $curuser->access_right('Change customer package') ) {
%               $br=1;
                (&nbsp;<%pkg_change_link($cust_pkg)%>&nbsp;)
%             } 
%
%             if ( $curuser->access_right('Discount customer package')
%                  && $part_pkg->can_discount
%                  && ! scalar($cust_pkg->cust_pkg_discount_active)
%                  && ! scalar($cust_pkg->part_pkg->part_pkg_discount)
%                )
%             {
%               $br=1;
                (&nbsp;<%pkg_discount_link($cust_pkg)%>&nbsp;)
%             }
%
%             if ( $curuser->access_right('Customize customer package') ) {
%               $br=1;
                (&nbsp;<%pkg_customize_link($cust_pkg,$part_pkg)%>&nbsp;)
%             } 
%
              <% $br ? '<BR>' : '' %>
%           } 

%           if ( $cust_pkg->num_cust_event
%                && (    $curuser->access_right('Billing event reports')
%                     || $curuser->access_right('View customer billing events')
%                   )
%              ) {
              (&nbsp;<%pkg_event_link($cust_pkg)%>&nbsp;)
%           }
%         } #!$supplemental

        </FONT>
      </TD>
    </TR>

%   my $editi = $curuser->access_right('Edit customer package invoice details');
%   my $editc = $curuser->access_right('Edit customer package comments');
%   my @cust_pkg_detail = $cust_pkg->cust_pkg_detail;
%   my @invoice_detail = grep { $_->detailtype eq 'I' } @cust_pkg_detail;
%   my @comments       = grep { $_->detailtype eq 'C' } @cust_pkg_detail;
%
%   if ( scalar(@invoice_detail) || scalar(@comments) || $editi || $editc ) {
%
%     my $editlink = $p. 'edit/cust_pkg_detail.html?pkgnum='. $cust_pkg->pkgnum.
%                    ';detailtype=';

      <TR>

%       if ( @invoice_detail ) {
          <TD VALIGN="top">
            <& /elements/table-grid.html &>
              <TR>
                <TH BGCOLOR="#dddddd" STYLE="border-bottom: dashed 1px black; padding-bottom: 1px">
                  <FONT SIZE="-1">
                    <% mt('Invoice details') |h %> 
%                   if ( $editi && ! $cust_pkg->get('cancel') && ! $opt{no_links} ) {
                      (<& /elements/popup_link.html, { 
                                    'action'      => $editlink. 'I',
                                    'label'       => emt('edit'),
                                    'actionlabel' => emt('Edit invoice details'),
                                    'color'       => '#333399',
                                    'width'       => 763,
                                 }
                       &>)
%                   }
                  </FONT>
                </TH>
              </TR>
%             foreach my $cust_pkg_detail ( @invoice_detail ) {
                <TR>
                  <TD><FONT SIZE="-1">&nbsp;-&nbsp;<% $cust_pkg_detail->detail |h %></FONT></TD>
                </TR>
%             }
            </TABLE>
          </TD>
%       } else {
          <TD>
%           if ( $editi && ! $cust_pkg->get('cancel') && ! $opt{no_links} ) {
              <FONT SIZE="-1">
                (&nbsp;<% include('/elements/popup_link.html', { 
                               'action'      => $editlink. 'I',
                               'label'       => emt('Add invoice details'),
                               'actionlabel' => emt('Add invoice details'),
                               'color'       => '#333399',
                               'width'       => 763,
                            })
                  %>&nbsp;)
              </FONT>
%           }
          </TD>
%       }

%       if ( @comments ) { 
          <TD VALIGN="top">
            <& /elements/table-grid.html &>
              <TR>
                <TH BGCOLOR="#dddddd" STYLE="border-bottom: dashed 1px black; padding-bottom: 1px">
                  <FONT SIZE="-1">
                    <% mt('Comments') |h %> 
%                   if ( $editc && ! $opt{no_links} ) {
                      (<& /elements/popup_link.html, { 
                                    'action'      => $editlink. 'C',
                                    'label'       => emt('edit'),
                                    'actionlabel' => emt('Edit comments'),
                                    'color'       => '#333399',
                                    'width'       => 763,
                                 }
                       &>)
%                   }
                  </FONT>
                </TH>
              </TR>
%             foreach my $cust_pkg_detail ( @comments ) {
                <TR>
                  <TD><FONT SIZE="-1">&nbsp;-&nbsp;<% $cust_pkg_detail->detail |h %></FONT></TD>
                </TR>
%             }
            </TABLE>
          </TD>
%       } else {
          <TD>
%           if ( $editc && ! $opt{no_links} ) {
              <FONT SIZE="-1">
                (&nbsp;<& /elements/popup_link.html, { 
                               'action'      => $editlink. 'C',
                               'label'       => emt('Add comments'),
                               'actionlabel' => emt('Add comments'),
                               'color'       => '#333399',
                               'width'       => 763,
                            }
                  &>&nbsp;)
              </FONT>
%           }
          </TD>
%       }

      </TR>
%     if ( $curuser->access_right('Change customer package')
%            && ! $cust_pkg->get('cancel')
%            && ! $supplemental
%            && $part_pkg->freq ne '0'
%            && ! $opt{no_links}
%        )
%     {
      <TR>
%       if ( FS::Conf->new->exists('invoice-unitprice') ) {
        <TD><FONT SIZE="-1">
          (&nbsp;<% pkg_change_quantity_link($cust_pkg) %>&nbsp;)
        </FONT></TD>
%       }
      </TR>
%     }
%   }
  </TABLE>
% if ( @cust_pkg_usage ) {
  <TABLE CLASS="usage inv">
    <TR><TH COLSPAN=4><% mt('Included usage') %></TH></TR>
%   foreach my $usage (@cust_pkg_usage) {
%     my $part = $usage->part_pkg_usage;
%     my $ratio = 255 * ($usage->minutes / $part->minutes);
%     $ratio = 255 if $ratio > 255; # because rollover
%     my $color = sprintf('STYLE="font-weight: bold; color: #%02x%02x00"', 255 - $ratio, $ratio);
%     my $trstyle = '';
%     $trstyle = ' CLASS="shared"' if $part->shared;
    <TR<%$trstyle%>>
      <TD ALIGN="right"><% $part->description %>: </TD>
      <TD <%$color%> ALIGN="right"><% $usage->minutes %></TD>
      <TD <%$color%>> / </TD>
      <TD <%$color%>><% $part->minutes %></TD>
%     if ( $part->shared ) {
      <TD><I>(shared)</I></TD>
%     }
    </TR>
%   }
  </TABLE>
% }

</TD>

<%init>

my %opt = @_;

my $bgcolor  = $opt{'bgcolor'};
my $cust_pkg = $opt{'cust_pkg'};
my $part_pkg = $opt{'part_pkg'};

my $curuser = $FS::CurrentUser::CurrentUser;

my $countrydefault = $opt{'countrydefault'} || 'US';
my $statedefault   = $opt{'statedefault'}
                     || ($countrydefault eq 'US' ? 'CA' : '');

my $supplemental = $opt{'supplemental'} || 0;

$cust_pkg->pkgnum =~ /^(\d+)$/;
my $pkgnum = $1;
my @cust_pkg_usage = qsearch({
  'select'    => 'cust_pkg_usage.*',
  'table'     => 'cust_pkg_usage',
  'addl_from' => ' JOIN part_pkg_usage USING (pkgusagepart)',
  'extra_sql' => " WHERE pkgnum = $1",
  'order_by'  => ' ORDER BY priority ASC, description ASC',
});

#subroutines

#false laziness w/status.html
sub pkg_link {
  my($action, $label, $cust_pkg) = @_;
  return '' unless $cust_pkg;
  qq!<a href="$p$action.cgi?!. $cust_pkg->pkgnum. qq!">$label</a>!;
}

sub pkg_change_link {
  my $cust_pkg = shift;
  my $locationnum = $cust_pkg->locationnum;
  include( '/elements/popup_link-cust_pkg.html',
    'action'      => $p. "misc/change_pkg.cgi?locationnum=$locationnum",
    'label'       => emt('Change package'),
    'actionlabel' => emt('Change'),
    'cust_pkg'    => $cust_pkg,
  );
}

sub pkg_change_location_link {
  my $cust_pkg = shift;
  my $pkgpart = $cust_pkg->pkgpart;
  include( '/elements/popup_link-cust_pkg.html',
    'action'      => $p. "misc/change_pkg.cgi?locationnum=-1;pkgpart=$pkgpart;".
                     "address1=;address2=;city=;county=;state=$statedefault;".
                     "zip=;country=$countrydefault",
    'label'       => emt('Change location'),
    'actionlabel' => emt('Change'),
    'cust_pkg'    => $cust_pkg,
  );
}

sub pkg_change_quantity_link {
  include( '/elements/popup_link-cust_pkg.html',
    'action'      => $p. 'edit/cust_pkg_quantity.html?',
    'label'       => emt('Change quantity'),
    'actionlabel' => emt('Change'),
    'cust_pkg'    => shift,
    'width'       => 390,
    'height'      => 220,
  );
}

sub pkg_discount_link {
  my $cust_pkg = shift or return '';
  include( '/elements/popup_link-cust_pkg.html',
    'action'      => $p.'edit/cust_pkg_discount.html',
    'label'       => emt('Discount'),
    'actionlabel' => emt('Discount'),
    'cust_pkg'    => $cust_pkg,
    'width'       => 616,
  );
}

sub pkg_customize_link {
  my $cust_pkg = shift or return '';
  my $part_pkg = shift;
  my $custnum = $cust_pkg->custnum;
  qq!<A HREF="${p}edit/part_pkg.cgi?!.
    "clone=". $part_pkg->pkgpart. ';'.
    "pkgnum=". $cust_pkg->pkgnum.
    qq!">!.emt('Customize').'</A>';
}

sub pkg_event_link {
  my($cust_pkg) = @_;
  qq!<a href="${p}search/cust_event.html?pkgnum=!. $cust_pkg->pkgnum. qq!">!.
  emt('View package events').
  '</a>';
}

</%init>