summaryrefslogtreecommitdiff
path: root/httemplate/view/cust_main/packages/services.html
blob: a23a4c2fefd9d1ad3a0d7c8ae6691a2129df323a (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
% ###
% # Services
% ###

  <TD CLASS="inv" BGCOLOR="<% $bgcolor %>">
    <TABLE CLASS="inv" BORDER=0 CELLSPACING=0 CELLPADDING=2 WIDTH="100%">
    <SCRIPT TYPE="text/javascript">
function clearhint_search_cust_svc(obj, str) {
  if (obj.value == str) obj.value = '';
}
    </SCRIPT>

%  my $showdidlink = browse_received_did_inventory($cust_pkg->custnum);
%  foreach my $part_svc (
%    $cust_pkg->part_svc(
%      'summarize_size'    => $opt{'cust_pkg-large_pkg_size'},
%      'hide_discontinued' => $opt{'cust_pkg-hide_discontinued-part_svc'},
%    )
%  ) {
%
%    my $num_cust_svc = $cust_pkg->num_cust_svc( $part_svc->svcpart );
%
%    if ( $opt{'cust_pkg-large_pkg_size'} > 0 and
%         $opt{'cust_pkg-large_pkg_size'} <= $num_cust_svc ) { # summarize
%
      <TR>
        <TD ALIGN="right" VALIGN="top">
%       my $href="${p}search/cust_pkg_svc.html?svcpart=".$part_svc->svcpart.
%          ";pkgnum=".$cust_pkg->pkgnum;
        <A HREF="<% $href %>"><% $part_svc->svc |h %></A>
        </TD>
        <TD ALIGN="left" VALIGN="top">
        <A HREF="<% $href %>"><B>(<% mt("view all [_1]", $num_cust_svc) |h %>)</B></A>
        </TD>
      </TR>
%     my $hint = $hints{$part_svc->svcdb};
%     if ( $hint ) {
      <TR>
        <TD></TD>
        <TD ALIGN="left" VALIGN="top">
        <FORM name="svcpart<%$part_svc->svcpart%>_search" STYLE="display:inline"
        ACTION="<%$p%>search/cust_pkg_svc.html" METHOD="GET">
        <INPUT TYPE="hidden" NAME="svcpart" VALUE="<%$part_svc->svcpart%>">
        <INPUT TYPE="hidden" NAME="pkgnum" VALUE="<%$cust_pkg->pkgnum%>">
        <INPUT TYPE="text" NAME="search_svc"
        onfocus="clearhint_search_cust_svc(this, '<%$hint%>')" VALUE="<%$hint%>">
        <INPUT TYPE="submit" VALUE="Search"></FORM>
        </TD>
      </TR>
%     } #$hint
%
%    } else { # don't summarize
%
%      foreach my $cust_svc ( @{ $part_svc->cust_pkg_svc } ) {
%        if ( $cust_pkg->getfield('cancel') > 0 ) {
      <& /elements/tr-cust_svc_cancel.html,
                  %opt,
                  'part_svc' => $part_svc,
                  'cust_svc' => $cust_svc,
                  'cust_pkg' => $cust_pkg,
       &>
%        }
%        else {
      <& /elements/tr-cust_svc.html,
                  %opt,
                  'part_svc' => $part_svc,
                  'cust_svc' => $cust_svc,
                  'cust_pkg' => $cust_pkg,
       &>
%       } #if cancel > 0
%     } #foreach $cust_svc
%   } #if summarizing
%   if (    ! $cust_pkg->get('cancel')
%        && $curuser->access_right('Provision customer service') 
%        && $part_svc->num_avail
%      ) {

      <TR>
        <TD COLSPAN=3 ALIGN="center" STYLE="padding-bottom:4px;padding-top:0px">

          <B>
%         if ( $opt{no_links} ) {
            <% $part_svc->svc |h %>: <% $part_svc->num_avail %>
            <% mt('Available') |h %>
%         } else {
            <% svc_provision_link($cust_pkg, $part_svc, \%opt, $curuser) %>
%         }
          </B>

%        if ( $curuser->access_right('Bulk provision customer service') 
%               && $part_svc->svcdb eq 'svc_phone'
%               && ! $opt{no_links}
%           )
%        {
%          if ( $part_svc->num_avail > 5 ) {
%             local $opt{'bulk'} = 1;
%             local $opt{'svc_phone_bulk_provision_simple'} =  $svc_phone_bulk_provision_simple;
%             local $opt{'num_avail'} = $part_svc->num_avail;
              <BR><% svc_provision_link($cust_pkg, $part_svc, \%opt, $curuser) %>
%           }
%           if ($showdidlink) {
              <BR><A HREF="<%$p%>browse/did_order.html?custnum=<%$cust_pkg->custnum%>"><% mt('Browse Received DID Inventory') |h %></A> 
%           }
%       }
        </TD>
      </TR>

%   }

% } #foreach part_svc

% if ($cust_pkg->get('cancel')) {
%   foreach my $svc (
%     $cust_pkg->uncancel_svc_summary('summarize_size' => $opt{'cust_pkg-large_pkg_size'}, 'no_test_reprovision' => 1)
%   ) {
      <TR>
        <TD ALIGN="right" VALIGN="top"><% $svc->{'svc'} |h %></TD>
        <TD STYLE="padding-bottom:0px; font-style: italic">
        <% $svc->{'num_cust_svc'} 
           ? $svc->{'num_cust_svc'} . ' ' . emt('services in history') 
           : (defined($svc->{'label'}) ? $svc->{'label'} : emt('(cannot load svc label)')) |h %>
        </TD>
      </TR>
%   }
% }


    </TABLE>
  </TD>

<%init>

my %opt = @_;

my $bgcolor  = $opt{'bgcolor'};
my $cust_pkg = $opt{'cust_pkg'};
my $part_pkg = $opt{'part_pkg'};
my $svc_phone_bulk_provision_simple = $opt{'svc_phone-bulk_provision_simple'};

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

sub svc_provision_link {
  my ($cust_pkg, $part_svc, $opt, $curuser) = @_;

  ( my $svc_nbsp = $part_svc->svc ) =~ s/\s+/ /g;
  my $num_avail = $part_svc->num_avail;

  my $query = "pkgnum=". $cust_pkg->pkgnum. ';'.
              "svcpart=". $part_svc->svcpart;
  $query .= ';bulk=1' if $opt->{bulk};

  my $url;
  if ( $part_svc->svcdb eq 'svc_external' #could be generalized
       && $opt->{'svc_external-skip_manual'}
  ) {
    $url = "${p}edit/process/". $part_svc->svcdb. ".cgi?$query";
  } elsif ( $part_svc->svcdb eq 'svc_phone' && $opt->{bulk}
              && $opt->{svc_phone_bulk_provision_simple}
          )
  {
    $query .= ';num_avail='. $opt->{num_avail};
    $url = "${p}edit/bulk-svc_phone.html?$query";
  } else {
    $url = svc_url(
                    'm'        => $m,
                    'action'   => 'edit',
                    'part_svc' => $part_svc, 
                    'query'    => $query,
                  );
  }

  my $action = $opt->{bulk} ? 'Bulk provision' : 'Provision';

  my $link = qq!<A CLASS="provision" HREF="$url">!.
             emt("$action [_1] ([_2])",$svc_nbsp,$num_avail).'</A>';

  if ( $opt->{'legacy_link'}
       && $curuser->access_right('View/link unlinked services')
       && ! $opt{bulk}
     )
  {
    $link .= '<BR>'.
             qq!<A CLASS="provision" HREF="${p}misc/link.cgi?$query">!.
            emt("Link to legacy [_1] ([_2])",$svc_nbsp,$num_avail).'</A>';
  }

  $link;
}

sub browse_received_did_inventory {
  local($FS::Record::qsearch_qualify_columns) = 1;
  qsearch({
    'table' => 'did_order',
    'hashref' => { 'custnum' => $_[0] },
    'extra_sql' => ' LIMIT 1'
  }) ||
  qsearch({
    'table' => 'did_order_item',
    'hashref' => { 'custnum' => $_[0] },
    'addl_from' => ' INNER JOIN did_order ON did_order_item.ordernum = did_order.ordernum',
    'extra_sql' => ' LIMIT 1'
  });
}

my %hints = (
svc_acct      => emt('(user or email)'),
svc_domain    => emt('(domain)'),
svc_broadband => emt('(ip or mac)'),
svc_forward   => emt('(email)'),
svc_phone     => emt('(phone)'),
svc_pbx       => emt('(phone)'),
);

</%init>