[freeside-commits] freeside/FS/FS Schema.pm, 1.22, 1.23 cust_main.pm, 1.221, 1.222 part_referral.pm, 1.5, 1.6

Ivan,,, ivan at wavetail.420.am
Thu Aug 10 06:50:46 PDT 2006


Update of /home/cvs/cvsroot/freeside/FS/FS
In directory wavetail:/tmp/cvs-serv1633/FS/FS

Modified Files:
	Schema.pm cust_main.pm part_referral.pm 
Log Message:
add cust_main.agent_custid (at least to schema and customer view, no manual editing yet)

Index: Schema.pm
===================================================================
RCS file: /home/cvs/cvsroot/freeside/FS/FS/Schema.pm,v
retrieving revision 1.22
retrieving revision 1.23
diff -u -d -r1.22 -r1.23
--- Schema.pm	10 Aug 2006 11:55:50 -0000	1.22
+++ Schema.pm	10 Aug 2006 13:50:44 -0000	1.23
@@ -394,6 +394,7 @@
       'columns' => [
         'custnum',  'serial',  '',     '', '', '', 
         'agentnum', 'int',  '',     '', '', '', 
+        'agent_custid', 'varchar', 'NULL', $char_d, '', '',
 #        'titlenum', 'int',  'NULL',   '', '', '', 
         'last',     'varchar', '',     $char_d, '', '', 
 #        'middle',   'varchar', 'NULL', $char_d, '', '', 
@@ -443,7 +444,7 @@
         'spool_cdr','char', 'NULL', 1, '', '', 
       ],
       'primary_key' => 'custnum',
-      'unique' => [],
+      'unique' => [ [ 'agentnum', 'agent_custid' ] ],
       #'index' => [ ['last'], ['company'] ],
       'index' => [ ['last'], [ 'company' ], [ 'referral_custnum' ],
                    [ 'daytime' ], [ 'night' ], [ 'fax' ], [ 'refnum' ],

Index: part_referral.pm
===================================================================
RCS file: /home/cvs/cvsroot/freeside/FS/FS/part_referral.pm,v
retrieving revision 1.5
retrieving revision 1.6
diff -u -d -r1.5 -r1.6
--- part_referral.pm	10 Aug 2006 11:55:50 -0000	1.5
+++ part_referral.pm	10 Aug 2006 13:50:44 -0000	1.6
@@ -2,7 +2,7 @@
 
 use strict;
 use vars qw( @ISA );
-use FS::Record qw(qsearchs);
+use FS::Record qw( qsearch qsearchs dbh );
 use FS::agent;
 
 @ISA = qw( FS::Record );
@@ -120,6 +120,65 @@
 
 =back
 
+=head1 CLASS METHODS
+
+=over 4
+
+=item acl_agentnum_sql
+
+Returns an SQL fragment for searching for part_referral records allowed by the
+current users's agent ACLs (and "Edit global advertising sources" right).
+
+=cut
+
+sub acl_agentnum_sql {
+  #my $class = shift;
+
+  my $curuser = $FS::CurrentUser::CurrentUser;
+  my $sql = $curuser->agentnums_sql;
+  $sql = " ( $sql OR agentnum IS NULL ) "
+    if $curuser->access_right('Edit global advertising sources');
+
+  $sql;
+
+}
+
+=item all_part_referral
+
+Returns all part_referral records allowed by the current users's agent ACLs
+(and "Edit global advertising sources" right).
+
+=cut
+
+sub all_part_referral {
+  my $self = shift;
+
+  qsearch({
+    'table'     => 'part_referral',
+    'extra_sql' => ' WHERE '. $self->acl_agentnum_sql. ' ORDER BY refnum ',
+  });
+
+}
+
+=item num_part_referral
+
+Returns the number of part_referral records allowed by the current users's
+agent ACLs (and "Edit global advertising sources" right).
+
+=cut
+
+sub num_part_referral {
+  my $self = shift;
+
+  my $sth = dbh->prepare(
+    'SELECT COUNT(*) FROM part_referral WHERE '. $self->acl_agentnum_sql
+  ) or die dbh->errstr;
+  $sth->execute() or die $sth->errstr;
+  $sth->fetchrow_arrayref->[0];
+}
+
+=back
+
 =head1 BUGS
 
 The delete method is unimplemented.

Index: cust_main.pm
===================================================================
RCS file: /home/cvs/cvsroot/freeside/FS/FS/cust_main.pm,v
retrieving revision 1.221
retrieving revision 1.222
diff -u -d -r1.221 -r1.222
--- cust_main.pm	9 Aug 2006 06:43:01 -0000	1.221
+++ cust_main.pm	10 Aug 2006 13:50:44 -0000	1.222
@@ -1060,6 +1060,7 @@
   my $error =
     $self->ut_numbern('custnum')
     || $self->ut_number('agentnum')
+    || $self->ut_textn('agent_custid')
     || $self->ut_number('refnum')
     || $self->ut_name('last')
     || $self->ut_name('first')



More information about the freeside-commits mailing list