5 use FS::Record qw( qsearchs );
9 my( $custnum ) = shift; #@_;
10 my $svcnum = @_ ? shift : '';
12 my $curuser = $FS::CurrentUser::CurrentUser;
14 my $cust_main = qsearchs({
15 'table' => 'cust_main',
16 'hashref' => { 'custnum' => $custnum },
17 'extra_sql' => ' AND '. $curuser->agentnums_sql,
19 or return { 'status' => 'E',
20 'error' => "custnum $custnum not found" };
22 my( $svc_pbx, $good_till, $outbound_service ) = ( '', '', '' );
27 # reseller scenario to maestro (customer w/ multiple packages)
34 'addl_from' => ' LEFT JOIN cust_svc USING ( svcnum ) '.
35 ' LEFT JOIN cust_pkg USING ( pkgnum ) ',
36 'hashref' => { 'svcnum' => $svcnum },
37 'extra_sql' => " AND custnum = $custnum",
39 or return { 'status' => 'E',
40 'error' => "svcnum $svcnum not found" };
42 #status in the reseller scenario
44 my $cust_pkg = $svc_pbx->cust_svc->cust_pkg;
46 $result{'status'} = substr($cust_pkg->ucfirst_status,0,1);
48 # find "outbound service" y/n
50 #XXX outbound service per-reseller ?
51 #my @cust_pkg = $cust_main->cust_pkg;
53 #my $conf = new FS::Conf;
54 #my %outbound_pkgs = map { $_=>1 } $conf->config('mc-outbound_packages');
55 #my $outbound_service =
56 # scalar( grep { $outbound_pkgs{ $_->pkgpart }
57 # && !$_->get('cancel')
63 # find "good till" date/time stamp (this package)
65 $good_till = time2str('%c', $cust_pkg->bill || time );
70 # regular customer to maestro (single package)
73 my @cust_pkg = $cust_main->cust_pkg;
75 #things specific to the non-reseller scenario
77 $result{'status'} = substr($cust_main->ucfirst_status,0,1);
80 [ map $_->pkgpart, grep !$_->get('cancel'), @cust_pkg ];
84 my @cust_svc = map $_->cust_svc, @cust_pkg;
87 grep { my($n,$l,$t) = $_->label; $t eq 'svc_pbx' }
90 if ( ! @cust_svc_pbx ) {
91 return { 'status' => 'E',
92 'error' => "customer $custnum has no conference service" };
93 } elsif ( scalar(@cust_svc_pbx) > 1 ) {
94 return { 'status' => 'E',
96 "customer $custnum has more than one conference".
97 " service (reseller?); specify a svcnum as a second argument",
101 my $cust_svc_pbx = $cust_svc_pbx[0];
103 $svc_pbx = $cust_svc_pbx->svc_x;
105 # find "outbound service" y/n
107 my $conf = new FS::Conf;
108 my %outbound_pkgs = map { $_=>1 } $conf->config('mc-outbound_packages');
110 scalar( grep { $outbound_pkgs{ $_->pkgpart }
111 && !$_->get('cancel')
117 # find "good till" date/time stamp
119 my @active_cust_pkg =
120 sort { $a->bill <=> $b->bill }
121 grep { !$_->get('cancel') && $_->part_pkg->freq ne '0' }
123 $good_till = time2str('%c', $active_cust_pkg[0]->bill || time );
128 'name' => $cust_main->name,
129 'email' => $cust_main->invoicing_list_emailonly_scalar,
130 'max_lines' => $svc_pbx ? $svc_pbx->max_extensions : '',
131 'max_simultaneous' => $svc_pbx ? $svc_pbx->max_simultaneous : '',
132 'outbound_service' => $outbound_service,
133 'good_till' => $good_till,