summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorJonathan Prykop <jonathan@freeside.biz>2015-08-20 01:42:15 -0500
committerJonathan Prykop <jonathan@freeside.biz>2015-08-24 17:49:06 -0500
commit98ed783317fe098b221dda211ef6264cf6334c43 (patch)
treecc2a3c1337f365033714a85379e0ade88469f504
parent0d678bcd0d18621ede25d0465b71e919e1c5212e (diff)
RT#14829: automatic payments triggered by bill now show up as Payment by fs_queue
-rw-r--r--FS/FS/Schema.pm1
-rw-r--r--FS/FS/queue.pm21
-rw-r--r--FS/bin/freeside-queued5
-rw-r--r--httemplate/search/queue.html6
4 files changed, 33 insertions, 0 deletions
diff --git a/FS/FS/Schema.pm b/FS/FS/Schema.pm
index e06fce65c..1166f240d 100644
--- a/FS/FS/Schema.pm
+++ b/FS/FS/Schema.pm
@@ -2962,6 +2962,7 @@ sub tables_hashref {
'custnum', 'int', 'NULL', '', '', '',
'secure', 'char', 'NULL', 1, '', '',
'priority', 'int', 'NULL', '', '', '',
+ 'usernum', 'int', 'NULL', '', '', '',
],
'primary_key' => 'jobnum',
'unique' => [],
diff --git a/FS/FS/queue.pm b/FS/FS/queue.pm
index 3f8763da8..9bbaf3431 100644
--- a/FS/FS/queue.pm
+++ b/FS/FS/queue.pm
@@ -98,6 +98,10 @@ Optional link to customer (see L<FS::cust_main>).
Secure flag, 'Y' indicates that when using encryption, the job needs to be
run on a machine with the private key.
+=item usernum
+
+For access_user that created the job
+
=cut
=back
@@ -152,6 +156,8 @@ sub insert {
$self->custnum( $args{'custnum'} ) if $args{'custnum'};
+ $self->usernum($FS::CurrentUser::CurrentUser->usernum) unless $self->usernum;
+
my $error = $self->SUPER::insert;
if ( $error ) {
$dbh->rollback if $oldAutoCommit;
@@ -263,6 +269,7 @@ sub check {
|| $self->ut_enum('status',['', qw( new locked failed done )])
|| $self->ut_anything('statustext')
|| $self->ut_numbern('svcnum')
+ || $self->ut_foreign_keyn('usernum', 'access_user', 'usernum')
;
return $error if $error;
@@ -399,6 +406,20 @@ sub update_statustext {
#'';
}
+=item access_user
+
+Returns FS::access_user object (if any) associated with this user.
+
+Returns nothing if not found.
+
+=cut
+
+sub access_user {
+ my $self = shift;
+ my $usernum = $self->usernum || return ();
+ return qsearchs('access_user',{ 'usernum' => $usernum }) || ();
+}
+
=back
=head1 SUBROUTINES
diff --git a/FS/bin/freeside-queued b/FS/bin/freeside-queued
index f5284e708..82dc81407 100644
--- a/FS/bin/freeside-queued
+++ b/FS/bin/freeside-queued
@@ -218,8 +218,13 @@ while (1) {
# don't put @args in the log, may expose passwords
$log->info('starting job ('.$ljob->job.')');
warn 'running "&'. $ljob->job. '('. join(', ', @args). ")\n" if $DEBUG;
+ # switch user only if a job user is available
+ my $oldCurrentUser = $FS::CurrentUser::CurrentUser;
+ my $jobuser = $ljob->access_user;
+ local $FS::CurrentUser::CurrentUser = $jobuser if $jobuser;
local $FS::UID::AutoCommit = 0; # so that we can clean up failures
eval $eval; #throw away return value? suppose so
+ $FS::CurrentUser::CurrentUser = $oldCurrentUser if $jobuser;
if ( $@ ) {
dbh->rollback;
my %hash = $ljob->hash;
diff --git a/httemplate/search/queue.html b/httemplate/search/queue.html
index 141c535da..22032b13c 100644
--- a/httemplate/search/queue.html
+++ b/httemplate/search/queue.html
@@ -13,6 +13,7 @@
'Date',
'Status',
'Account', # unless $hashref->{'svcnum'}
+ 'Employee',
'', # checkbox column
],
'fields' => [
@@ -78,6 +79,11 @@
},
sub {
my $queue = shift;
+ my $access_user = $queue->access_user;
+ return $access_user ? $access_user->username : '';
+ },
+ sub {
+ my $queue = shift;
my $jobnum = $queue->jobnum;
my $status = $queue->status;
my $changable = $dangerous