continue sales person work: customer and package selection, commissions, reporting...
authorIvan Kohler <ivan@freeside.biz>
Sun, 18 Aug 2013 05:36:35 +0000 (22:36 -0700)
committerIvan Kohler <ivan@freeside.biz>
Sun, 18 Aug 2013 05:36:35 +0000 (22:36 -0700)
13 files changed:
FS/FS/AccessRight.pm
FS/FS/Agent_Mixin.pm [new file with mode: 0644]
FS/FS/Mason.pm
FS/FS/Schema.pm
FS/FS/access_right.pm
FS/FS/cust_main.pm
FS/FS/cust_pkg.pm
FS/FS/sales.pm
FS/MANIFEST
httemplate/browse/sales.html [new file with mode: 0644]
httemplate/edit/process/sales.html [new file with mode: 0644]
httemplate/edit/sales.html [new file with mode: 0755]
httemplate/elements/menu.html

index 3f6073e..019ea21 100644 (file)
@@ -344,6 +344,8 @@ tie my %rights, 'Tie::IxHash',
     'Edit advertising sources',
     { rightname=>'Edit global advertising sources', global=>1 },
 
+    'Edit sales people',
+
     'Edit package definitions',
     { rightname=>'Edit global package definitions', global=>1 },
   
diff --git a/FS/FS/Agent_Mixin.pm b/FS/FS/Agent_Mixin.pm
new file mode 100644 (file)
index 0000000..0f84ba9
--- /dev/null
@@ -0,0 +1,42 @@
+package FS::Agent_Mixin;
+
+use strict;
+use FS::Record qw( qsearchs );
+use FS::agent;
+
+=head1 NAME
+
+FS::Agent_Mixin - Mixin class for objects that have an agent.
+
+=over 4
+
+=item agent
+
+Returns the agent (see L<FS::agent>) for this object.
+
+=cut
+
+sub agent {
+  my $self = shift;
+  qsearchs( 'agent', { 'agentnum' => $self->agentnum } );
+}
+
+=item agent_name
+
+Returns the agent name (see L<FS::agent>) for this object.
+
+=cut
+
+sub agent_name {
+  my $self = shift;
+  $self->agent->agent;
+}
+
+=back
+
+=head1 BUGS
+
+=cut
+
+1;
+
index 1d4a939..7993048 100644 (file)
@@ -315,7 +315,6 @@ if ( -e $addl_handler_use_file ) {
   use FS::tower;
   use FS::tower_sector;
   use FS::sales;
-  use FS::access_groupsales;
   use FS::contact_class;
   use FS::part_svc_class;
   use FS::upload_target;
index 2ce1794..56cd065 100644 (file)
@@ -1036,6 +1036,7 @@ sub tables_hashref {
       'columns' => [
         'custnum',  'serial',  '',     '', '', '', 
         'agentnum', 'int',  '',     '', '', '', 
+        'salesnum', 'int',  'NULL', '', '', '', 
         'agent_custid', 'varchar', 'NULL', $char_d, '', '',
         'classnum', 'int', 'NULL', '', '', '',
         'custbatch', 'varchar', 'NULL', $char_d, '', '',
@@ -1802,6 +1803,7 @@ sub tables_hashref {
         'locationnum',         'int', 'NULL', '', '', '',
         'otaker',          'varchar', 'NULL', 32, '', '', 
         'usernum',             'int', 'NULL', '', '', '',
+        'salesnum',            'int', 'NULL', '', '', '', 
         'order_date',     @date_type,             '', '', 
         'start_date',     @date_type,             '', '', 
         'setup',          @date_type,             '', '', 
@@ -3772,17 +3774,6 @@ sub tables_hashref {
       'index'  => [ [ 'groupnum' ] ],
     },
 
-    'access_groupsales' => {
-      'columns' => [
-        'groupsalesnum', 'serial', '', '', '', '',
-        'groupnum',         'int', '', '', '', '',
-        'salesnum',         'int', '', '', '', '',
-      ],
-      'primary_key' => 'groupsalesnum',
-      'unique' => [ [ 'groupnum', 'salesnum' ] ],
-      'index'  => [ [ 'groupnum' ] ],
-    },
-
     'access_right' => {
       'columns' => [
         'rightnum',   'serial', '',      '', '', '',
index f8e30d0..85334ed 100644 (file)
@@ -235,6 +235,7 @@ sub _upgrade_data { # class method
     'Change customer package' => 'Detach customer package',
     'Services: Accounts' => 'Services: Cable Subscribers',
     'Bulk change customer packages' => 'Bulk move customer services',
+    'Configuration' => 'Edit sales people',
 ;
 
   foreach my $old_acl ( keys %onetime ) {
index 30d6fa0..8e7c3e7 100644 (file)
@@ -76,6 +76,7 @@ use FS::cust_attachment;
 use FS::contact;
 use FS::Locales;
 use FS::upgrade_journal;
+use FS::sales;
 
 # 1 is mostly method/subroutine entry and options
 # 2 traces progress of some operations
@@ -1696,6 +1697,7 @@ sub check {
     || $self->ut_foreign_key('bill_locationnum', 'cust_location','locationnum')
     || $self->ut_foreign_key('ship_locationnum', 'cust_location','locationnum')
     || $self->ut_foreign_keyn('classnum', 'cust_class', 'classnum')
+    || $self->ut_foreign_keyn('salesnum', 'sales', 'salesnum')
     || $self->ut_textn('custbatch')
     || $self->ut_name('last')
     || $self->ut_name('first')
index 89c683e..3948c2f 100644 (file)
@@ -34,7 +34,7 @@ use FS::reason;
 use FS::cust_pkg_discount;
 use FS::discount;
 use FS::UI::Web;
-use Data::Dumper;
+use FS::sales;
 
 # need to 'use' these instead of 'require' in sub { cancel, suspend, unsuspend,
 # setup }
@@ -631,6 +631,7 @@ sub check {
     || $self->ut_numbern('pkgpart')
     || $self->ut_foreign_keyn('contactnum',  'contact',       'contactnum' )
     || $self->ut_foreign_keyn('locationnum', 'cust_location', 'locationnum')
+    || $self->ut_foreign_keyn('salesnum', 'sales', 'salesnum')
     || $self->ut_numbern('start_date')
     || $self->ut_numbern('setup')
     || $self->ut_numbern('bill')
@@ -2240,6 +2241,7 @@ sub set_quantity {
 
 use Storable 'thaw';
 use MIME::Base64;
+use Data::Dumper;
 sub process_bulk_cust_pkg {
   my $job = shift;
   my $param = thaw(decode_base64(shift));
index 3cb61fd..5dba4d8 100644 (file)
@@ -1,18 +1,8 @@
 package FS::sales;
+use base qw( FS::Agent_Mixin FS::Record );
 
 use strict;
-use vars qw( @ISA );
-use base qw( FS::Record );
-use Business::CreditCard 0.28;
-use FS::Record qw( dbh qsearch qsearchs );
-use FS::cust_main;
-use FS::cust_pkg;
-use FS::agent_type;
-use FS::reg_code;
-use FS::TicketSystem;
-#use FS::Conf;
-
-@ISA = qw( FS::m2m_Common FS::Record );
+use FS::agent;
 
 =head1 NAME
 
@@ -35,7 +25,7 @@ FS::sales - Object methods for sales records
 
 =head1 DESCRIPTION
 
-An FS::sales object represents an example.  FS::sales inherits from
+An FS::sales object represents a sales person.  FS::sales inherits from
 FS::Record.  The following fields are currently supported:
 
 =over 4
@@ -61,7 +51,8 @@ disabled
 
 =item new HASHREF
 
-Creates a new example.  To add the example to the database, see L<"insert">.
+Creates a new sales person.  To add the sales person to the database, see
+L<"insert">.
 
 Note that this stores the hash reference, not a distinct copy of the hash it
 points to.  You can ask the object for a copy with the I<hash> method.
@@ -100,7 +91,7 @@ returns the error, otherwise returns false.
 
 =item check
 
-Checks all fields to make sure this is a valid example.  If there is
+Checks all fields to make sure this is a valid sales person.  If there is
 an error, returns the error, otherwise returns false.  Called by the insert
 and replace methods.
 
@@ -114,15 +105,12 @@ sub check {
 
   my $error = 
     $self->ut_numbern('salesnum')
-    || $self->ut_numbern('agentnum')
+    || $self->ut_text('salesperson')
+    || $self->ut_foreign_key('agentnum', 'agent', 'agentnum')
+    || $self->ut_enum('disabled', [ '', 'Y' ])
   ;
   return $error if $error;
 
-  if ( $self->dbdef_table->column('disabled') ) {
-    $error = $self->ut_enum('disabled', [ '', 'Y' ] );
-    return $error if $error;
-  }
-
   $self->SUPER::check;
 }
 
@@ -130,8 +118,6 @@ sub check {
 
 =head1 BUGS
 
-The author forgot to customize this manpage.
-
 =head1 SEE ALSO
 
 L<FS::Record>, schema.html from the base documentation.
index 803c521..a6e87f6 100644 (file)
@@ -637,8 +637,6 @@ FS/upgrade_journal.pm
 t/upgrade_journal.t
 FS/sales.pm
 t/sales.t
-FS/access_groupsales.pm
-t/access_groupsales.t
 FS/part_svc_class.pm
 t/part_svc_class.t
 FS/upload_target.pm
diff --git a/httemplate/browse/sales.html b/httemplate/browse/sales.html
new file mode 100644 (file)
index 0000000..1cdc490
--- /dev/null
@@ -0,0 +1,32 @@
+<& elements/browse.html,
+     'title'              => 'Sales People',
+     'name_singular'      => 'sales person',
+     'menubar'            => ['Add a new sales person' => $p.'edit/sales.html'],
+     'query'              => { 'table' => 'sales' },
+     'count_query'        => 'SELECT COUNT(*) FROM sales',
+     'header'             => \@header,
+     'fields'             => \@fields,
+     'links'              => \@links,
+     'disableable'        => 1,
+     'disabled_statuspos' => 1,
+     'agent_virt'         => 1,
+&>
+<%init>
+
+my $curuser = $FS::CurrentUser::CurrentUser;
+
+die "access denied" unless $curuser->access_right('Edit sales people');
+
+my @header = ( 'Sales person' );
+my @fields = ( 'salesperson' );
+my @links  = ( [$p.'edit/sales.html?', 'salesnum'] );
+
+if ( $curuser->access_right('Configuration') ) {
+  push @header, 'Agent';
+  push @fields, 'agent_name';
+  push @links,  [ $p.'edit/agent.cgi?', 'agentnum' ];
+}
+
+#Sales people bring in business.<BR><BR>
+
+</%init>
diff --git a/httemplate/edit/process/sales.html b/httemplate/edit/process/sales.html
new file mode 100644 (file)
index 0000000..b60276d
--- /dev/null
@@ -0,0 +1,12 @@
+<& elements/process.html,
+     'table'       => 'sales',
+     'viewall_dir' => 'browse',
+     'agent_virt'  => 1,
+&>
+<%init>
+
+die "access denied"
+  unless $FS::CurrentUser::CurrentUser->access_right('Edit sales people');
+
+</%init>
+
diff --git a/httemplate/edit/sales.html b/httemplate/edit/sales.html
new file mode 100755 (executable)
index 0000000..65cddfc
--- /dev/null
@@ -0,0 +1,21 @@
+<& elements/edit.html,
+     'name_singular' => 'sales person',
+     'table'         => 'sales',
+     'fields'        => [ 'salesperson',
+                          { field=>'agentnum', type=>'select-agent', disable_empty=>1, },
+                          { field=>'disabled', type=>'checkbox', value=>'Y', },
+                        ],
+     'labels'        => { 'salesnum'    => 'Sales Person',
+                          'salesperson' => 'Name',
+                          'agentnum'    => 'Agent',
+                          'disabled'    => 'Disabled',
+                        },
+     'viewall_dir'   => 'browse',
+     'agent_virt'    => 1,
+&>
+<%init>
+
+die "access denied"
+  unless $FS::CurrentUser::CurrentUser->access_right('Edit sales people');
+
+</%init>
index a7411b7..15d2f53 100644 (file)
@@ -573,7 +573,7 @@ tie my %config_agent, 'Tie::IxHash',
 ;
 
 tie my %config_sales, 'Tie::IxHash',
-  'Sales'      => [ $fsurl.'browse/sales.cgi', 'Sales bring in new business.' ],
+  'Sales People' => [ $fsurl.'browse/sales.html', 'Sales people bring in new business.' ],
 ;
 
 tie my %config_billing_rates, 'Tie::IxHash',
@@ -689,13 +689,19 @@ if ( $curuser->access_right('Configuration' ) ) {
     'Settings'      => [ $fsurl.'config/config-view.cgi', '' ],
     'separator'     => '', #its a separator!
     'Companies'     => [ \%config_agent, '' ],
-    'Employees'     => [ \%config_employees, '' ],
-    'Sales People'  => [ \%config_sales, '' ],
-    'separator2'    => '', #its a separator!
-    'Customers'     => [ \%config_cust, '' ],
-    #or this? 'Customers and Contacts' => [ \%config_cust, '' ],
   );
 }
+
+$config_menu{'Sales People'}  = [ \%config_sales, '' ]
+  if $curuser->access_right('Edit sales people');
+
+if ( $curuser->access_right('Configuration' ) ) {
+  $config_menu{'Employees'}  = [ \%config_employees, '' ];
+  $config_menu{'separator2'} = ''; #its a separator!
+  $config_menu{'Customers'}  = [ \%config_cust, '' ];
+    #or this? 'Customers and Contacts'
+}
+
 $config_menu{'Packages'} = [ \%config_pkg, '' ]
   if    $curuser->access_right('Configuration' )
      || $curuser->access_right('Edit package definitions')