[freeside-commits] branch FREESIDE_4_BRANCH updated. 1d84ced5422aff16e5f2fdebdd1d1fe4bb806016
Jonathan Prykop
jonathan at 420.am
Fri Jul 31 19:25:26 PDT 2015
The branch, FREESIDE_4_BRANCH has been updated
via 1d84ced5422aff16e5f2fdebdd1d1fe4bb806016 (commit)
from 6a24b8134d19a68339b927c9887f796ba7a04e0e (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 1d84ced5422aff16e5f2fdebdd1d1fe4bb806016
Author: Jonathan Prykop <jonathan at freeside.biz>
Date: Wed Jul 29 20:54:53 2015 -0500
RT#35100: how to void a payment in the cust_pay_batch before file has been uploaded to the bank
diff --git a/FS/FS/cust_pay_batch.pm b/FS/FS/cust_pay_batch.pm
index 8f31e4d..a5fa89b 100644
--- a/FS/FS/cust_pay_batch.pm
+++ b/FS/FS/cust_pay_batch.pm
@@ -433,6 +433,75 @@ sub request_item {
);
}
+=item process_unbatch_and_delete
+
+L</unbatch_and_delete> run as a queued job, accepts I<$job> and I<$param>.
+
+=cut
+
+sub process_unbatch_and_delete {
+ my ($job, $param) = @_;
+ my $self = qsearchs('cust_pay_batch',{ 'paybatchnum' => scalar($param->{'paybatchnum'}) })
+ or die 'Could not find paybatchnum ' . $param->{'paybatchnum'};
+ my $error = $self->unbatch_and_delete;
+ die $error if $error;
+ return '';
+}
+
+=item unbatch_and_delete
+
+May only be called on a record with an empty status and an associated
+L<pay_batch> with a status of 'O' (not yet in transit.) Deletes all associated
+records from L<cust_bill_pay_batch> and then deletes this record.
+If there is an error, returns the error, otherwise returns false.
+
+=cut
+
+sub unbatch_and_delete {
+ my $self = shift;
+
+ return 'Cannot unbatch a cust_pay_batch with status ' . $self->status
+ if $self->status;
+
+ my $pay_batch = qsearchs('pay_batch',{ 'batchnum' => $self->batchnum })
+ or return 'Cannot find associated pay_batch record';
+
+ return 'Cannot unbatch from a pay_batch with status ' . $pay_batch->status
+ if $pay_batch->status ne 'O';
+
+ local $SIG{HUP} = 'IGNORE';
+ local $SIG{INT} = 'IGNORE';
+ local $SIG{QUIT} = 'IGNORE';
+ local $SIG{TERM} = 'IGNORE';
+ local $SIG{TSTP} = 'IGNORE';
+ local $SIG{PIPE} = 'IGNORE';
+
+ my $oldAutoCommit = $FS::UID::AutoCommit;
+ local $FS::UID::AutoCommit = 0;
+ my $dbh = dbh;
+
+ # have not generated actual payments yet, so should be safe to delete
+ foreach my $cust_bill_pay_batch (
+ qsearch('cust_bill_pay_batch',{ 'paybatchnum' => $self->paybatchnum })
+ ) {
+ my $error = $cust_bill_pay_batch->delete;
+ if ( $error ) {
+ $dbh->rollback if $oldAutoCommit;
+ return $error;
+ }
+ }
+
+ my $error = $self->delete;
+ if ( $error ) {
+ $dbh->rollback if $oldAutoCommit;
+ return $error;
+ }
+
+ $dbh->commit or die $dbh->errstr if $oldAutoCommit;
+ '';
+
+}
+
=back
=head1 BUGS
diff --git a/httemplate/misc/process/delete-cust_pay_batch.cgi b/httemplate/misc/process/delete-cust_pay_batch.cgi
new file mode 100644
index 0000000..4937b58
--- /dev/null
+++ b/httemplate/misc/process/delete-cust_pay_batch.cgi
@@ -0,0 +1,37 @@
+<% $server->process %>
+<%init>
+
+my $curuser = $FS::CurrentUser::CurrentUser;
+
+die "access denied"
+ unless $curuser->access_right('Process batches')
+ || $curuser->access_right('Process global batches');
+
+# look up paybatch using agentnums_sql & status constraints
+# to validate access for this particular cust_pay_batch,
+# similar to how it's done in cust_pay_batch.cgi
+
+my %arg = $cgi->param('arg');
+my $paybatchnum = $arg{'paybatchnum'};
+$paybatchnum =~ /^\d+$/ or die "Illegal paybatchnum";
+my @search = ();
+push @search, 'cust_pay_batch.paybatchnum = ' . $paybatchnum;
+push @search, '(cust_pay_batch.status = \'\' OR cust_pay_batch.status IS NULL)';
+push @search, 'pay_batch.status = \'O\'';
+push @search, $curuser->agentnums_sql({ table => 'cust_main' });
+push @search, $curuser->agentnums_sql({ table => 'pay_batch',
+ null_right => 'Process global batches',
+ });
+my $search = ' WHERE ' . join(' AND ', @search);
+die "permission denied" unless qsearchs({
+ 'table' => 'cust_pay_batch',
+ 'hashref' => {},
+ 'addl_from' => 'LEFT JOIN pay_batch USING ( batchnum ) '.
+ 'LEFT JOIN cust_main USING ( custnum ) '.
+ 'LEFT JOIN cust_pay USING ( batchnum, custnum ) ',
+ 'extra_sql' => $search
+});
+
+my $server = new FS::UI::Web::JSRPC 'FS::cust_pay_batch::process_unbatch_and_delete', $cgi;
+
+</%init>
diff --git a/httemplate/search/cust_pay_batch.cgi b/httemplate/search/cust_pay_batch.cgi
index c0f84ec..cc958b9 100755
--- a/httemplate/search/cust_pay_batch.cgi
+++ b/httemplate/search/cust_pay_batch.cgi
@@ -14,6 +14,7 @@
'Exp',
'Amount',
'Status',
+ '', # delete link
'', # error_message
],
'fields' => [ 'paybatchnum',
@@ -31,9 +32,10 @@
sprintf('%.02f', $_[0]->amount)
},
sub { $_[0]->display_status },
+ $sub_unbatch,
'error_message',
],
- 'align' => 'rrrlllcrlll',
+ 'align' => 'rrrlllcrllll',
'links' => [ '',
["${p}view/cust_bill.cgi?", 'invnum'],
(["${p}view/cust_main.cgi?", 'custnum']) x 2,
@@ -129,6 +131,36 @@ my $sub_receipt = sub {
);
};
+my $sub_unbatch = '';
+if ( ($pay_batch && ($pay_batch->status eq 'O'))
+ && ( $curuser->access_right('Process batches')
+ || $curuser->access_right('Process global batches') )
+) {
+ $sub_unbatch = sub {
+ my $self = shift;
+ return '' if $self->status; # sanity check, shouldn't happen
+ my $batchnum = $self->batchnum;
+ my $paybatchnum = $self->paybatchnum;
+ my $out = <<EOF;
+<FORM name="delete_cust_pay_batch_$paybatchnum">
+<INPUT TYPE="hidden" name="paybatchnum" value="$paybatchnum">
+</FORM>
+EOF
+ $out .= include('/elements/progress-init.html',
+ "delete_cust_pay_batch_$paybatchnum",
+ [ 'paybatchnum' ],
+ $p.'misc/process/delete-cust_pay_batch.cgi',
+ $p.'search/cust_pay_batch.cgi?' . $cgi->query_string,
+ "paybatchnum$paybatchnum",
+ );
+ my $onclick = 'if ( confirm(\'';
+ $onclick .= emt('Are you sure you want to delete batch payment ') . $self->paybatchnum;
+ $onclick .= emt(' from payment batch ') . $self->batchnum;
+ $onclick .= '\') ) { paybatchnum' . $paybatchnum . 'process() }';
+ return $out . '<A HREF="javascript:void(0)" ONCLICK="' . $onclick . '">delete</A>';
+ };
+}
+
my $html_init = '';
if ( $pay_batch ) {
$html_init = include('elements/cust_pay_batch_top.html',
-----------------------------------------------------------------------
Summary of changes:
FS/FS/cust_pay_batch.pm | 69 +++++++++++++++++++++
httemplate/misc/process/delete-cust_pay_batch.cgi | 37 +++++++++++
httemplate/search/cust_pay_batch.cgi | 34 +++++++++-
3 files changed, 139 insertions(+), 1 deletion(-)
create mode 100644 httemplate/misc/process/delete-cust_pay_batch.cgi
More information about the freeside-commits
mailing list