freeside/FS/FS/ClientAPI MyAccount.pm,1.28,1.29 Signup.pm,1.15,1.16 Agent.pm,1.1,1.2
ivan
ivan at pouncequick.420.am
Tue Aug 24 04:17:01 PDT 2004
Update of /home/cvs/cvsroot/freeside/FS/FS/ClientAPI
In directory pouncequick:/tmp/cvs-serv11531/FS/FS/ClientAPI
Modified Files:
MyAccount.pm Signup.pm Agent.pm
Log Message:
big update for reseller interface
Index: Signup.pm
===================================================================
RCS file: /home/cvs/cvsroot/freeside/FS/FS/ClientAPI/Signup.pm,v
retrieving revision 1.15
retrieving revision 1.16
diff -u -d -r1.15 -r1.16
--- Signup.pm 15 Jul 2004 22:40:00 -0000 1.15
+++ Signup.pm 24 Aug 2004 11:16:57 -0000 1.16
@@ -76,7 +76,7 @@
'cvv_enabled' => defined dbdef->table('cust_main')->column('paycvv'),
'msgcat' => { map { $_=>gettext($_) } qw(
- passwords_dont_match invalid_card unknown_card_type not_a
+ passwords_dont_match invalid_card unknown_card_type not_a empty_password
) },
'statedefault' => $conf->config('statedefault') || 'CA',
Index: MyAccount.pm
===================================================================
RCS file: /home/cvs/cvsroot/freeside/FS/FS/ClientAPI/MyAccount.pm,v
retrieving revision 1.28
retrieving revision 1.29
diff -u -d -r1.28 -r1.29
--- MyAccount.pm 15 Jul 2004 22:40:00 -0000 1.28
+++ MyAccount.pm 24 Aug 2004 11:16:56 -0000 1.29
@@ -109,23 +109,8 @@
sub customer_info {
my $p = shift;
- my($session, $custnum, $context);
- if ( $p->{'session_id'} ) {
- $context = 'customer';
- $session = $cache->get($p->{'session_id'})
- or return { 'error' => "Can't resume session" }; #better error message
- $custnum = $session->{'custnum'};
- } elsif ( $p->{'agent_session_id'} ) {
- $context = 'agent';
- my $agent_cache = new Cache::SharedMemoryCache( {
- 'namespace' => 'FS::ClientAPI::Agent',
- } );
- $session = $agent_cache->get($p->{'agent_session_id'})
- or return { 'error' => "Can't resume session" }; #better error message
- $custnum = $p->{'custnum'};
- } else {
- return { 'error' => "Can't resume session" }; #better error message
- }
+ my($context, $session, $custnum) = _custoragent_session_custnum($p);
+ return { 'error' => $session } if $context eq 'error';
my %return;
if ( $custnum ) { #customer record
@@ -451,31 +436,42 @@
sub list_pkgs {
my $p = shift;
- my $session = $cache->get($p->{'session_id'})
- or return { 'error' => "Can't resume session" }; #better error message
- my $custnum = $session->{'custnum'};
+ my($context, $session, $custnum) = _custoragent_session_custnum($p);
+ return { 'error' => $session } if $context eq 'error';
- my $cust_main = qsearchs('cust_main', { 'custnum' => $custnum } )
+ my $search = { 'custnum' => $custnum };
+ $search->{'agentnum'} = $session->{'agentnum'} if $context eq 'agent';
+ my $cust_main = qsearchs('cust_main', $search )
or return { 'error' => "unknown custnum $custnum" };
#return { 'cust_pkg' => [ map { $_->hashref } $cust_main->ncancelled_pkgs ] };
+ my $conf = new FS::Conf;
+
{ 'svcnum' => $session->{'svcnum'},
+ 'custnum' => $custnum,
'cust_pkg' => [ map {
{ $_->hash,
$_->part_pkg->hash,
part_svc =>
[ map $_->hashref, $_->available_part_svc ],
cust_svc =>
- [ map { { $_->hash,
- label => [ $_->label ],
- }
+ [ map { my $ref = { $_->hash,
+ label => [ $_->label ],
+ };
+ $ref->{_password} = $_->svc_x->_password
+ if $context eq 'agent'
+ && $conf->exists('agent-showpasswords')
+ && $_->part_svc->svcdb eq 'svc_acct';
+ $ref;
} $_->cust_svc
],
};
} $cust_main->ncancelled_pkgs
],
+ 'small_custview' =>
+ small_custview( $cust_main, $conf->config('defaultcountry') ),
};
}
@@ -483,28 +479,11 @@
sub order_pkg {
my $p = shift;
- my($session, $custnum, $context);
-
- if ( $p->{'session_id'} ) {
- $context = 'customer';
- $session = $cache->get($p->{'session_id'})
- or return { 'error' => "Can't resume session" }; #better error message
- $custnum = $session->{'custnum'};
- } elsif ( $p->{'agent_session_id'} ) {
- $context = 'agent';
- my $agent_cache = new Cache::SharedMemoryCache( {
- 'namespace' => 'FS::ClientAPI::Agent',
- } );
- $session = $agent_cache->get($p->{'agent_session_id'})
- or return { 'error' => "Can't resume session" }; #better error message
- $custnum = $p->{'custnum'};
- } else {
- return { 'error' => "Can't resume session" }; #better error message
- }
+ my($context, $session, $custnum) = _custoragent_session_custnum($p);
+ return { 'error' => $session } if $context eq 'error';
my $search = { 'custnum' => $custnum };
$search->{'agentnum'} = $session->{'agentnum'} if $context eq 'agent';
-
my $cust_main = qsearchs('cust_main', $search )
or return { 'error' => "unknown custnum $custnum" };
@@ -632,12 +611,12 @@
sub provision_acct {
my $p = shift;
- my $session = $cache->get($p->{'session_id'})
- or return { 'error' => "Can't resume session" }; #better error message
-
- my $custnum = $session->{'custnum'};
+ my($context, $session, $custnum) = _custoragent_session_custnum($p);
+ return { 'error' => $session } if $context eq 'error';
- my $cust_main = qsearchs('cust_main', { 'custnum' => $custnum } )
+ my $search = { 'custnum' => $custnum };
+ $search->{'agentnum'} = $session->{'agentnum'} if $context eq 'agent';
+ my $cust_main = qsearchs('cust_main', $search )
or return { 'error' => "unknown custnum $custnum" };
my $pkgnum = $p->{'pkgnum'};
@@ -671,12 +650,12 @@
sub part_svc_info {
my $p = shift;
- my $session = $cache->get($p->{'session_id'})
- or return { 'error' => "Can't resume session" }; #better error message
-
- my $custnum = $session->{'custnum'};
+ my($context, $session, $custnum) = _custoragent_session_custnum($p);
+ return { 'error' => $session } if $context eq 'error';
- my $cust_main = qsearchs('cust_main', { 'custnum' => $custnum } )
+ my $search = { 'custnum' => $custnum };
+ $search->{'agentnum'} = $session->{'agentnum'} if $context eq 'agent';
+ my $cust_main = qsearchs('cust_main', $search )
or return { 'error' => "unknown custnum $custnum" };
my $pkgnum = $p->{'pkgnum'};
@@ -693,11 +672,14 @@
or return { 'error' => "unknown svcpart $svcpart for pkgnum $pkgnum" };
my $part_svc = $pkg_svc->part_svc;
+ my $conf = new FS::Conf;
+
return {
'svc' => $part_svc->svc,
'svcdb' => $part_svc->svcdb,
'pkgnum' => $pkgnum,
'svcpart' => $svcpart,
+ 'custnum' => $custnum,
'security_phrase' => 0, #XXX !
'svc_acct_pop' => [], #XXX !
@@ -705,6 +687,10 @@
'init_popstate' => '',
'popac' => '',
'acstate' => '',
+
+ 'small_custview' =>
+ small_custview( $cust_main, $conf->config('defaultcountry') ),
+
};
}
@@ -712,12 +698,12 @@
sub unprovision_svc {
my $p = shift;
- my $session = $cache->get($p->{'session_id'})
- or return { 'error' => "Can't resume session" }; #better error message
-
- my $custnum = $session->{'custnum'};
+ my($context, $session, $custnum) = _custoragent_session_custnum($p);
+ return { 'error' => $session } if $context eq 'error';
- my $cust_main = qsearchs('cust_main', { 'custnum' => $custnum } )
+ my $search = { 'custnum' => $custnum };
+ $search->{'agentnum'} = $session->{'agentnum'} if $context eq 'agent';
+ my $cust_main = qsearchs('cust_main', $search )
or return { 'error' => "unknown custnum $custnum" };
my $svcnum = $p->{'svcnum'};
@@ -728,11 +714,47 @@
return { 'error' => "Service $svcnum does not belong to customer $custnum" }
unless $cust_svc->cust_pkg->custnum == $custnum;
+ my $conf = new FS::Conf;
+
return { 'svc' => $cust_svc->part_svc->svc,
- 'error' => $cust_svc->cancel
+ 'error' => $cust_svc->cancel,
+ 'small_custview' =>
+ small_custview( $cust_main, $conf->config('defaultcountry') ),
};
}
+
+#--
+
+sub _custoragent_session_custnum {
+ my $p = shift;
+
+ my($context, $session, $custnum);
+ if ( $p->{'session_id'} ) {
+
+ $context = 'customer';
+ $session = $cache->get($p->{'session_id'})
+ or return { 'error' => "Can't resume session" }; #better error message
+ $custnum = $session->{'custnum'};
+
+ } elsif ( $p->{'agent_session_id'} ) {
+
+ $context = 'agent';
+ my $agent_cache = new Cache::SharedMemoryCache( {
+ 'namespace' => 'FS::ClientAPI::Agent',
+ } );
+ $session = $agent_cache->get($p->{'agent_session_id'})
+ or return { 'error' => "Can't resume session" }; #better error message
+ $custnum = $p->{'custnum'};
+
+ } else {
+ return { 'error' => "Can't resume session" }; #better error message
+ }
+
+ ($context, $session, $custnum);
+
+}
+
1;
Index: Agent.pm
===================================================================
RCS file: /home/cvs/cvsroot/freeside/FS/FS/ClientAPI/Agent.pm,v
retrieving revision 1.1
retrieving revision 1.2
diff -u -d -r1.1 -r1.2
--- Agent.pm 10 Jun 2004 12:31:31 -0000 1.1
+++ Agent.pm 24 Aug 2004 11:16:57 -0000 1.2
@@ -6,12 +6,14 @@
use vars qw($cache);
use Digest::MD5 qw(md5_hex);
use Cache::SharedMemoryCache; #store in db?
-use FS::Record qw(qsearchs); # qsearch);
+use FS::Record qw(qsearchs qsearch dbdef dbh);
use FS::agent;
+use FS::cust_main;
use FS::ClientAPI;
FS::ClientAPI->register_handlers(
'Agent/agent_login' => \&agent_login,
+ 'Agent/agent_logout' => \&agent_logout,
'Agent/agent_info' => \&agent_info,
'Agent/agent_list_customers' => \&agent_list_customers,
);
@@ -52,6 +54,16 @@
};
}
+sub agent_logout {
+ my $p = shift;
+ if ( $p->{'session_id'} ) {
+ $cache->remove($p->{'session_id'});
+ return { 'error' => '' };
+ } else {
+ return { 'error' => "Can't resume session" }; #better error message
+ }
+}
+
sub agent_info {
my $p = shift;
@@ -92,11 +104,75 @@
my @cust_main = ();
- warn $p->{'susp'};
+ #warn $p->{'search'};
+ if ( $p->{'search'} =~ /^\s*(\d+)\s*$/ ) { # customer # search
+ push @cust_main, qsearch('cust_main', { 'agentnum' => $agentnum,
+ 'custnum' => $1 } );
+ } elsif ( $p->{'search'} =~ /^\s*(\S.*\S)\s*$/ ) { #value search
+ my $value = lc($1);
+ my $q_value = dbh->quote($value);
+
+ #exact
+ my $sql = " AND ( LOWER(last) = $q_value OR LOWER(company) = $q_value";
+ $sql .= " OR LOWER(ship_last) = $q_value OR LOWER(ship_company) = $q_value"
+ if defined dbdef->table('cust_main')->column('ship_last');
+ $sql .= ' )';
+
+ push @cust_main, qsearch( 'cust_main',
+ { 'agentnum' => $agentnum },
+ '',
+ $sql
+ );
+
+ unless ( @cust_main ) {
+ warn "no exact match, trying substring/fuzzy\n";
+
+ #still some false laziness w/ search/cust_main.cgi
+
+ #substring
+ push @cust_main, qsearch( 'cust_main',
+ { 'agentnum' => $agentnum,
+ 'last' => { 'op' => 'ILIKE',
+ 'value' => "%$q_value%" } } );
+
+ push @cust_main, qsearch( 'cust_main',
+ { 'agentnum' => $agentnum,
+ 'ship_last' => { 'op' => 'ILIKE',
+ 'value' => "%$q_value%" } } )
+ if defined dbdef->table('cust_main')->column('ship_last');
+
+ push @cust_main, qsearch( 'cust_main',
+ { 'agentnum' => $agentnum,
+ 'company' => { 'op' => 'ILIKE',
+ 'value' => "%$q_value%" } } );
+
+ push @cust_main, qsearch( 'cust_main',
+ { 'agentnum' => $agentnum,
+ 'ship_company' => { 'op' => 'ILIKE',
+ 'value' => "%$q_value%" } } )
+ if defined dbdef->table('cust_main')->column('ship_last');
+
+ #fuzzy
+ push @cust_main, FS::cust_main->fuzzy_search(
+ { 'last' => $value },
+ { 'agentnum' => $agentnum }
+ );
+ push @cust_main, FS::cust_main->fuzzy_search(
+ { 'company' => $value },
+ { 'agentnum' => $agentnum }
+ );
+
+ }
+ }
+ #aggregate searches
push @cust_main,
map $agent->$_(), map $_.'_cust_main',
grep $p->{$_}, qw( prospect active susp cancel );
+
+ #eliminate dups?
+ my %saw = ();
+ @cust_main = grep { !$saw{$_->custnum}++ } @cust_main;
{ customers => [ map {
my $cust_main = $_;
More information about the freeside-commits
mailing list