continue sales person work: customer and package selection, commissions, reporting...
authorIvan Kohler <ivan@freeside.biz>
Mon, 19 Aug 2013 03:12:45 +0000 (20:12 -0700)
committerIvan Kohler <ivan@freeside.biz>
Mon, 19 Aug 2013 03:12:45 +0000 (20:12 -0700)
FS/FS/Schema.pm
FS/FS/cust_pkg.pm
FS/FS/sales.pm
httemplate/browse/sales.html
httemplate/edit/process/cust_main.cgi
httemplate/edit/sales.html
httemplate/view/cust_main/packages/package.html
httemplate/view/cust_main/packages/section.html

index 6fca62e..818b437 100644 (file)
@@ -541,6 +541,7 @@ sub tables_hashref {
         'salesnum',          'serial',    '',       '', '', '', 
         'salesperson',      'varchar',    '',  $char_d, '', '', 
         'agentnum',             'int', 'NULL',      '', '', '', 
+        'sales_custnum',        'int', 'NULL',      '', '', '',
         'disabled',            'char', 'NULL',       1, '', '', 
       ],
       'primary_key' => 'salesnum',
index dedc637..3e638a6 100644 (file)
@@ -632,6 +632,7 @@ sub check {
     || $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('quantity')
     || $self->ut_numbern('start_date')
     || $self->ut_numbern('setup')
     || $self->ut_numbern('bill')
@@ -2227,7 +2228,7 @@ sub abort_change {
 
 =item set_quantity QUANTITY
 
-Change the package's quantity field.  This is the one package property
+Change the package's quantity field.  This is one of the few package properties
 that can safely be changed without canceling and reordering the package
 (because it doesn't affect tax eligibility).  Returns an error or an 
 empty string.
@@ -2237,9 +2238,23 @@ empty string.
 sub set_quantity {
   my $self = shift;
   $self = $self->replace_old; # just to make sure
-  my $qty = shift;
-  ($qty =~ /^\d+$/ and $qty > 0) or return "bad package quantity $qty";
-  $self->set('quantity' => $qty);
+  $self->quantity(shift);
+  $self->replace;
+}
+
+=item set_salesnum SALESNUM
+
+Change the package's salesnum (sales person) field.  This is one of the few
+package properties that can safely be changed without canceling and reordering
+the package (because it doesn't affect tax eligibility).  Returns an error or
+an empty string.
+
+=cut
+
+sub set_salesnum {
+  my $self = shift;
+  $self = $self->replace_old; # just to make sure
+  $self->salesnum(shift);
   $self->replace;
 }
 
index 5dba4d8..00f45c0 100644 (file)
@@ -2,7 +2,9 @@ package FS::sales;
 use base qw( FS::Agent_Mixin FS::Record );
 
 use strict;
+use FS::Record qw( qsearchs ); #qsearch qsearchs );
 use FS::agent;
+use FS::cust_main;
 
 =head1 NAME
 
@@ -107,6 +109,7 @@ sub check {
     $self->ut_numbern('salesnum')
     || $self->ut_text('salesperson')
     || $self->ut_foreign_key('agentnum', 'agent', 'agentnum')
+    || $self->ut_foreign_keyn('sales_custnum', 'cust_main', 'custnum')
     || $self->ut_enum('disabled', [ '', 'Y' ])
   ;
   return $error if $error;
@@ -114,6 +117,18 @@ sub check {
   $self->SUPER::check;
 }
 
+=item sales_cust_main
+
+Returns the FS::cust_main object (see L<FS::cust_main>), if any, for this
+sales person.
+
+=cut
+
+sub sales_cust_main {
+  my $self = shift;
+  qsearchs( 'cust_main', { 'custnum' => $self->sales_custnum } );
+}
+
 =back
 
 =head1 BUGS
index 6fac058..d2b6cfe 100644 (file)
@@ -16,6 +16,8 @@
 my $curuser = $FS::CurrentUser::CurrentUser;
 die "access denied" unless $curuser->access_right('Edit sales people');
 
+my $conf = new FS::Conf;
+
 #Sales people bring in business.<BR><BR>
 
 my @header = ( 'Sales person' );
@@ -28,6 +30,18 @@ if ( $curuser->access_right('Configuration') ) {
   push @links,  [ $p.'edit/agent.cgi?', 'agentnum' ];
 }
 
+push @header, 'Master Customer';
+push @fields, sub {
+  my $sales = shift;
+  return '' unless $sales->sales_custnum;
+  include('/elements/small_custview.html',
+            $sales->sales_custnum,
+            scalar($conf->config('countrydefault')),
+            1, #show balance
+         );
+};
+push @links, '';
+
 push @header, 'Commissions';
 push @fields, sub {
 
index 621de24..ff8be1a 100755 (executable)
@@ -213,6 +213,7 @@ if ( $new->custnum eq '' or $duplicate_of ) {
       #later         'custnum' => $custnum,
       'pkgpart'     => $pkgpart,
       'locationnum' => scalar($cgi->param('locationnum')),
+      'salesnum'    => scalar($cgi->param('salesnum')),
     } );
 
 
index 763f861..90f651d 100755 (executable)
@@ -3,12 +3,14 @@
      'table'         => 'sales',
      'fields'        => [ 'salesperson',
                           { field=>'agentnum', type=>'select-agent', disable_empty=>1, },
+                          { field=>'sales_custnum', type=>'search-cust_main', },
                           { field=>'disabled', type=>'checkbox', value=>'Y', },
                         ],
-     'labels'        => { 'salesnum'    => 'Sales Person',
-                          'salesperson' => 'Name',
-                          'agentnum'    => 'Agent',
-                          'disabled'    => 'Disabled',
+     'labels'        => { 'salesnum'      => 'Sales Person',
+                          'salesperson'   => 'Name',
+                          'agentnum'      => 'Agent',
+                          'sales_custnum' => 'Master customer',
+                          'disabled'      => 'Disabled',
                         },
      'viewall_dir'   => 'browse',
      'agent_virt'    => 1,
index 7df0869..f0ece98 100644 (file)
@@ -1,5 +1,7 @@
 <TD CLASS="inv package" BGCOLOR="<% $bgcolor %>" VALIGN="top" <%$style%>>
   <TABLE CLASS="inv package"> 
+
+
     <TR>
       <TD COLSPAN=2>
         <% $opt{before_pkg_callback}
       </TD>
     </TR>
 
-% if ( $cust_pkg->quantity > 1 ) {
-    <TR>
-      <TD COLSPAN=2>
-        &nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;<% mt('Quantity:') |h %> 
-        <B><% $cust_pkg->quantity %></B>
-      </TD>
-    </TR>
-% }
 
     <TR>
       <TD COLSPAN=2>
       </TD>
     </TR>
 
+
+    <TR>
+      <TD COLSPAN=2>
+
+%       my $change_quan_label = 'Change quantity';
+%       if ( $cust_pkg->quantity > 1 ) {
+%         $change_quan_label = 'change';
+          &nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;<% mt('Quantity:') |h %> 
+          <B><% $cust_pkg->quantity %></B>
+%       }
+
+%       if ( $curuser->access_right('Change customer package')
+%              && ! $cust_pkg->get('cancel')
+%              && ! $supplemental
+%              && $part_pkg->freq ne '0'
+%              && ! $opt{no_links}
+%              && $opt{'invoice-unitprice'}
+%          )
+%       {
+          <FONT SIZE="-1">
+            (&nbsp;<% pkg_change_quantity_link($cust_pkg, $change_quan_label) %>&nbsp;)
+          </FONT>
+%       }
+
+      </TD>
+    </TR>
+
+
+    <TR>
+      <TD COLSPAN=2>
+
+%       my $change_sales_label = 'Change sales person';
+%       if ( $cust_pkg->salesnum ) {
+%         $change_sales_label = 'change';
+          &nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;<% mt('Sales Person:') |h %> 
+          <B><% $cust_pkg->salesperson %></B>
+%       }
+
+%       if ( $curuser->access_right('Change customer package')
+%              && ! $cust_pkg->get('cancel')
+%              && ! $supplemental
+%              #&& $part_pkg->freq ne '0'
+%              && ! $opt{no_links}
+%          )
+%       {
+        <FONT SIZE="-1">
+          (&nbsp;<% pkg_change_salesnum_link($cust_pkg, $change_sales_label) %>&nbsp;)
+        </FONT>
+%     }
+
+      </TD>
+    </TR>
+
+
 %   my $editi = $curuser->access_right('Edit customer package invoice details');
 %   my $editc = $curuser->access_right('Edit customer package comments');
 %   my @cust_pkg_detail = $cust_pkg->cust_pkg_detail;
 %       }
 
       </TR>
-%     if ( $curuser->access_right('Change customer package')
-%            && ! $cust_pkg->get('cancel')
-%            && ! $supplemental
-%            && $part_pkg->freq ne '0'
-%            && ! $opt{no_links}
-%        )
-%     {
-      <TR>
-% # yeah, I guess we'll let you do this on a future change package
-%       if ( FS::Conf->new->exists('invoice-unitprice') ) {
-        <TD><FONT SIZE="-1">
-          (&nbsp;<% pkg_change_quantity_link($cust_pkg) %>&nbsp;)
-        </FONT></TD>
-%       }
-      </TR>
-%     }
+
+
 %   }
   </TABLE>
+
 % if ( @cust_pkg_usage ) {
   <TABLE CLASS="usage inv">
     <TR><TH COLSPAN=4><% mt('Included usage') %></TH></TR>
@@ -301,11 +336,24 @@ sub pkg_change_location_link {
 }
 
 sub pkg_change_quantity_link {
+  my( $cust_pkg, $label ) = @_;
   include( '/elements/popup_link-cust_pkg.html',
     'action'      => $p. 'edit/cust_pkg_quantity.html?',
-    'label'       => emt('Change quantity'),
+    'label'       => emt($label),
     'actionlabel' => emt('Change'),
-    'cust_pkg'    => shift,
+    'cust_pkg'    => $cust_pkg,
+    'width'       => 390,
+    'height'      => 220,
+  );
+}
+
+sub pkg_change_salesnum_link {
+  my( $cust_pkg, $label ) = @_;
+  include( '/elements/popup_link-cust_pkg.html',
+    'action'      => $p. 'edit/cust_pkg_salesnum.html?',
+    'label'       => emt($label),
+    'actionlabel' => emt('Change'),
+    'cust_pkg'    => $cust_pkg,
     'width'       => 390,
     'height'      => 220,
   );
index 0383fe8..152ccaa 100755 (executable)
@@ -77,6 +77,9 @@ my $pkg_attached = ( scalar(keys %change_custnum) == 1
 my $countrydefault = scalar($conf->config('countrydefault')) || 'US';  
 
 my %conf_opt = (
+  #for package.html
+  'invoice-unitprice'         => $conf->exists('invoice-unitprice'),
+
   #for services.html and status.html
   'cust_pkg-display_times'    => ($conf->exists('cust_pkg-display_times')
                                  || $curuser->option('cust_pkg-display_times')),