[freeside-commits] branch FREESIDE_3_BRANCH updated. 344686a7c0c2c015df2189ea7531117174e30fb4

Ivan ivan at 420.am
Thu Oct 24 23:30:05 PDT 2013


The branch, FREESIDE_3_BRANCH has been updated
       via  344686a7c0c2c015df2189ea7531117174e30fb4 (commit)
      from  4b90fe87e2510d424917c69605654d9c61c360c2 (commit)

Those revisions listed above that are new to this repository have
not appeared on any other notification email; so we list those
revisions in full, below.

- Log -----------------------------------------------------------------
commit 344686a7c0c2c015df2189ea7531117174e30fb4
Author: Ivan Kohler <ivan at freeside.biz>
Date:   Thu Oct 24 23:30:02 2013 -0700

    limit sales reports for employee, RT#25524

diff --git a/FS/FS/Schema.pm b/FS/FS/Schema.pm
index 10e8524..52b630e 100644
--- a/FS/FS/Schema.pm
+++ b/FS/FS/Schema.pm
@@ -3688,13 +3688,14 @@ sub tables_hashref {
 
     'access_user' => {
       'columns' => [
-        'usernum',   'serial',  '',      '', '', '',
-        'username',  'varchar', '', $char_d, '', '',
-        '_password', 'varchar', '', $char_d, '', '',
-        'last',      'varchar', '', $char_d, '', '', 
-        'first',     'varchar', '', $char_d, '', '', 
-        'user_custnum',  'int', 'NULL',  '', '', '',
-        'disabled',     'char', 'NULL',   1, '', '', 
+        'usernum',            'serial',      '',      '', '', '',
+        'username',           'varchar',     '', $char_d, '', '',
+        '_password',          'varchar',     '', $char_d, '', '',
+        'last',               'varchar',     '', $char_d, '', '', 
+        'first',              'varchar',     '', $char_d, '', '', 
+        'user_custnum',           'int', 'NULL',      '', '', '',
+        'report_salesnum',        'int', 'NULL',      '', '', '',
+        'disabled',              'char', 'NULL',       1, '', '', 
       ],
       'primary_key' => 'usernum',
       'unique' => [ [ 'username' ] ],
diff --git a/FS/FS/access_user.pm b/FS/FS/access_user.pm
index 509cc09..bbebecb 100644
--- a/FS/FS/access_user.pm
+++ b/FS/FS/access_user.pm
@@ -10,6 +10,7 @@ use FS::access_user_pref;
 use FS::access_usergroup;
 use FS::agent;
 use FS::cust_main;
+use FS::sales;
 
 $DEBUG = 0;
 $me = '[FS::access_user]';
@@ -254,6 +255,7 @@ sub check {
     || $self->ut_text('last')
     || $self->ut_text('first')
     || $self->ut_foreign_keyn('user_custnum', 'cust_main', 'custnum')
+    || $self->ut_foreign_keyn('report_salesnum', 'sales', 'salesnum')
     || $self->ut_enum('disabled', [ '', 'Y' ] )
   ;
   return $error if $error;
@@ -286,6 +288,18 @@ sub user_cust_main {
   qsearchs( 'cust_main', { 'custnum' => $self->user_custnum } );
 }
 
+=item report_sales
+
+Returns the FS::sales object (see L<FS::sales>), if any, for this
+user.
+
+=cut
+
+sub report_sales {
+  my $self = shift;
+  qsearchs( 'sales', { 'salesnum' => $self->report_salesnum } );
+}
+
 =item access_usergroup
 
 Returns links to the the groups this user is a part of, as FS::access_usergroup
diff --git a/httemplate/edit/access_user.html b/httemplate/edit/access_user.html
index 86ce253..3dc30d2 100644
--- a/httemplate/edit/access_user.html
+++ b/httemplate/edit/access_user.html
@@ -8,17 +8,19 @@
                                'last',
                                'first',
                                { field=>'user_custnum', type=>'search-cust_main', },
+                               { field=>'report_salesnum', type=>'select-sales', empty_label=>'all', },
                                { field=>'disabled', type=>'checkbox', value=>'Y' },
                              ],
                  'labels' => { 
-                               'usernum'      => 'User number',
-                               'username'     => 'Username',
-                               '_password'    => 'Password',
-                               '_password2'   => 'Re-enter Password',
-                               'last'         => 'Last name',
-                               'first'        => 'First name',
-                               'user_custnum' => 'Customer (optional)',
-                               'disabled'     => 'Disable employee',
+                               'usernum'         => 'User number',
+                               'username'        => 'Username',
+                               '_password'       => 'Password',
+                               '_password2'      => 'Re-enter Password',
+                               'last'            => 'Last name',
+                               'first'           => 'First name',
+                               'user_custnum'    => 'Customer (optional)',
+                               'report_salesnum' => 'Limit commission report to sales person',
+                               'disabled'        => 'Disable employee',
                              },
                  'edit_callback' => \&edit_callback,
                  'field_callback'=> \&field_callback,
@@ -62,8 +64,8 @@ my $check_user_custnum_search = <<END;
 END
 
 sub edit_callback {
-  my ($c, $o, $f, $opt) = @_;
-  $o->set('_password', '');
+  my ($cgi, $access_user, $fields_listref, $opt_hashref) = @_;
+  $access_user->_password('');
 }
 
 sub field_callback {
diff --git a/httemplate/search/report_sales_commission.html b/httemplate/search/report_sales_commission.html
index 792c335..19af428 100644
--- a/httemplate/search/report_sales_commission.html
+++ b/httemplate/search/report_sales_commission.html
@@ -4,25 +4,34 @@
 
 <TABLE BGCOLOR="#cccccc" CELLSPACING=0>
 
-<& /elements/tr-select-agent.html,
-     'onchange'      => 'agent_changed(this)',
-&>
+% if ( $curuser->report_salesnum ) {
 
-<SCRIPT TYPE="text/javascript">
+    <INPUT TYPE="hidden" NAME="agentnum" VALUE="<% $curuser->report_sales->agentnum %>">
+    <INPUT TYPE="hidden" NAME="salesnum" VALUE="<% $curuser->report_salesnum %>">
 
-  function agent_changed(what) {
-    salesnum_agentnum_changed(what);
-  }
+% } else {
 
-  <&| /elements/onload.js &>
-  agent_changed(document.getElementById('agentnum'))
-  </&>
+    <& /elements/tr-select-agent.html,
+         'onchange'      => 'agent_changed(this)',
+    &>
 
-</SCRIPT>
+    <SCRIPT TYPE="text/javascript">
 
-<& /elements/tr-select-sales.html,
-    'empty_label' => 'all',
-&>
+      function agent_changed(what) {
+        salesnum_agentnum_changed(what);
+      }
+
+      <&| /elements/onload.js &>
+      agent_changed(document.getElementById('agentnum'))
+      </&>
+
+    </SCRIPT>
+
+    <& /elements/tr-select-sales.html,
+        'empty_label' => 'all',
+    &>
+
+% }
 
 <& /elements/tr-checkbox.html,
     'label' => 'Customer sales person if there is no package sales person',
@@ -46,7 +55,8 @@
 <% include('/elements/footer.html') %>
 <%init>
 
-die "access denied"
-  unless $FS::CurrentUser::CurrentUser->access_right('Financial reports');
+my $curuser = $FS::CurrentUser::CurrentUser;
+
+die "access denied" unless $curuser->access_right('Financial reports');
 
 </%init>

-----------------------------------------------------------------------

Summary of changes:
 FS/FS/Schema.pm                                |   15 ++++----
 FS/FS/access_user.pm                           |   14 ++++++++
 httemplate/edit/access_user.html               |   22 +++++++------
 httemplate/search/report_sales_commission.html |   42 +++++++++++++++---------
 4 files changed, 60 insertions(+), 33 deletions(-)




More information about the freeside-commits mailing list