employee commission reporting, RT#6991
authorivan <ivan>
Tue, 30 Mar 2010 12:07:48 +0000 (12:07 +0000)
committerivan <ivan>
Tue, 30 Mar 2010 12:07:48 +0000 (12:07 +0000)
FS/FS/cust_credit.pm
FS/FS/cust_event.pm
FS/FS/cust_main.pm
FS/FS/part_event/Action/pkg_agent_credit.pm
FS/FS/part_event/Action/pkg_employee_credit.pm
FS/FS/part_event/Action/pkg_referral_credit.pm
httemplate/search/report_employee_commission.html [new file with mode: 0644]

index a7de397..b87b0db 100644 (file)
@@ -14,6 +14,7 @@ use FS::cust_credit_bill;
 use FS::part_pkg;
 use FS::reason_type;
 use FS::reason;
+use FS::cust_event;
 
 $me = '[ FS::cust_credit ]';
 $DEBUG = 0;
@@ -300,6 +301,7 @@ sub check {
     || $self->ut_textn('addlinfo')
     || $self->ut_enum('closed', [ '', 'Y' ])
     || $self->ut_foreign_keyn('pkgnum', 'cust_pkg', 'pkgnum')
+    || $self->ut_foreign_keyn('eventnum', 'cust_event', 'eventnum')
   ;
   return $error if $error;
 
index d2fcfc1..52b5911 100644 (file)
@@ -1,18 +1,16 @@
 package FS::cust_event;
 
 use strict;
+use base qw( FS::cust_main_Mixin FS::Record );
 use vars qw( @ISA $DEBUG $me );
 use Carp qw( croak confess );
 use FS::Record qw( qsearch qsearchs dbdef );
-use FS::cust_main_Mixin;
 use FS::part_event;
 #for cust_X
 use FS::cust_main;
 use FS::cust_pkg;
 use FS::cust_bill;
 
-@ISA = qw(FS::cust_main_Mixin FS::Record);
-
 $DEBUG = 0;
 $me = '[FS::cust_event]';
 
@@ -230,7 +228,7 @@ sub do_event {
   my $error;
   {
     local $SIG{__DIE__}; # don't want Mason __DIE__ handler active
-    $error = eval { $part_event->do_action($object); };
+    $error = eval { $part_event->do_action($object, $self); };
   }
 
   my $status = '';
index 24eb73a..1d220fe 100644 (file)
@@ -7447,7 +7447,7 @@ sub referral_cust_main_ncancelled {
 
 Like referral_cust_main, except returns a flat list of all unsuspended (and
 uncancelled) packages for each customer.  The number of items in this list may
-be useful for comission calculations (perhaps after a C<grep { my $pkgpart = $_->pkgpart; grep { $_ == $pkgpart } @commission_worthy_pkgparts> } $cust_main-> ).
+be useful for commission calculations (perhaps after a C<grep { my $pkgpart = $_->pkgpart; grep { $_ == $pkgpart } @commission_worthy_pkgparts> } $cust_main-> ).
 
 =cut
 
@@ -7509,8 +7509,10 @@ sub credit {
     $cust_credit->set('reason', $reason)
   }
 
-  $cust_credit->addlinfo( delete $options{'addlinfo'} )
-    if exists($options{'addlinfo'});
+  for (qw( addlinfo eventnum )) {
+    $cust_credit->$_( delete $options{$_} )
+      if exists($options{$_});
+  }
 
   $cust_credit->insert(%options);
 
index 2502738..4bcee98 100644 (file)
@@ -7,7 +7,7 @@ sub description { 'Credit the agent a specific amount'; }
 
 #a little false laziness w/pkg_referral_credit
 sub do_action {
-  my( $self, $cust_pkg ) = @_;
+  my( $self, $cust_pkg, $cust_event ) = @_;
 
   my $cust_main = $self->cust_main($cust_pkg);
 
@@ -26,8 +26,9 @@ sub do_action {
   my $error = $agent_cust_main->credit(
     $amount, 
     \$reasonnum,
-    'addlinfo' =>
-      'for customer #'. $cust_main->display_custnum. ': '.$cust_main->name,
+    'eventnum' => $cust_event->eventnum,
+    'addlinfo' => 'for customer #'. $cust_main->display_custnum.
+                               ': '.$cust_main->name,
   );
   die "Error crediting customer ". $agent_cust_main->custnum.
       " for agent commission: $error"
index 28fd025..64dd8b2 100644 (file)
@@ -7,7 +7,7 @@ sub description { 'Credit the ordering employee a specific amount'; }
 
 #a little false laziness w/pkg_referral_credit
 sub do_action {
-  my( $self, $cust_pkg ) = @_;
+  my( $self, $cust_pkg, $cust_event ) = @_;
 
   my $cust_main = $self->cust_main($cust_pkg);
 
@@ -26,8 +26,9 @@ sub do_action {
   my $error = $employee_cust_main->credit(
     $amount, 
     \$reasonnum,
-    'addlinfo' =>
-      'for customer #'. $cust_main->display_custnum. ': '.$cust_main->name,
+    'eventnum' => $cust_event->eventnum,
+    'addlinfo' => 'for customer #'. $cust_main->display_custnum.
+                               ': '.$cust_main->name,
   );
   die "Error crediting customer ". $employee_cust_main->custnum.
       " for employee commission: $error"
index da872e7..e7c92d6 100644 (file)
@@ -23,7 +23,7 @@ sub option_fields {
 }
 
 sub do_action {
-  my( $self, $cust_pkg ) = @_;
+  my( $self, $cust_pkg, $cust_event ) = @_;
 
   my $cust_main = $self->cust_main($cust_pkg);
 
@@ -43,8 +43,9 @@ sub do_action {
   my $error = $referring_cust_main->credit(
     $amount, 
     \$reasonnum,
-    'addlinfo' =>
-      'for customer #'. $cust_main->display_custnum. ': '.$cust_main->name,
+    'eventnum' => $cust_event->eventnum,
+    'addlinfo' => 'for customer #'. $cust_main->display_custnum.
+                               ': '.$cust_main->name,
   );
   die "Error crediting customer ". $cust_main->referral_custnum.
       " for referral: $error"
diff --git a/httemplate/search/report_employee_commission.html b/httemplate/search/report_employee_commission.html
new file mode 100644 (file)
index 0000000..a79630a
--- /dev/null
@@ -0,0 +1,34 @@
+<% include('/elements/header.html', 'Employee commission report' ) %>
+
+<FORM ACTION="part_pkg.html">
+
+<TABLE BGCOLOR="#cccccc" CELLSPACING=0>
+
+%# 
+%# <% include( '/elements/tr-select-agent.html',
+%#                'curr_value'    => scalar( $cgi->param('agentnum') ),
+%#                'disable_empty' => 0,
+%#            )
+%# %>
+%# 
+
+%#2.1
+<% include( '/elements/tr-select-user.html' ) %>
+
+%#1.9
+%# <%include( '/elements/tr-select-otaker.html' ) %>
+
+<% include( '/elements/tr-input-beginning_ending.html', ) %>
+
+</TABLE>
+
+<BR>
+<INPUT TYPE="submit" VALUE="Get Report">
+
+<% include('/elements/footer.html') %>
+<%init>
+
+die "access denied"
+  unless $FS::CurrentUser::CurrentUser->access_right('Financial reports');
+
+</%init>