From: ivan Date: Thu, 15 Dec 2005 04:04:51 +0000 (+0000) Subject: payment "un-void"ing X-Git-Tag: BEFORE_FINAL_MASONIZE~254 X-Git-Url: http://git.freeside.biz/gitweb/?p=freeside.git;a=commitdiff_plain;h=0f37b9c32e41fd94a0d5ea2f895a737cf674f310 payment "un-void"ing --- diff --git a/FS/FS/Conf.pm b/FS/FS/Conf.pm index 4090a9001..526ac3cf3 100644 --- a/FS/FS/Conf.pm +++ b/FS/FS/Conf.pm @@ -1569,6 +1569,13 @@ httemplate/docs/config.html }, { + 'key' => 'unvoid', + 'section' => 'billing', + 'description' => 'Enable unvoiding of voided payments', + 'type' => 'checkbox', + }, + + { 'key' => 'address2-search', 'section' => 'UI', 'description' => 'Enable a "Unit" search box which searches the second address field', diff --git a/FS/FS/Record.pm b/FS/FS/Record.pm index 7f64d849e..887c8dcd4 100644 --- a/FS/FS/Record.pm +++ b/FS/FS/Record.pm @@ -745,9 +745,12 @@ sub insert { $sth->execute or return $sth->errstr; - my $insertid = ''; - if ( $db_seq ) { # get inserted id from the database, if applicable + # get inserted id from the database, if applicable & needed + if ( $db_seq && ! $self->getfield($primary_key) ) { warn "[debug]$me retreiving sequence from database\n" if $DEBUG; + + my $insertid = ''; + if ( driver_name eq 'Pg' ) { #my $oid = $sth->{'pg_oid_status'}; @@ -793,11 +796,15 @@ sub insert { } } else { + dbh->rollback if $FS::UID::AutoCommit; return "don't know how to retreive inserted ids from ". driver_name. ", try using counterfiles (maybe run dbdef-create?)"; + } + $self->setfield($primary_key, $insertid); + } my @virtual_fields = diff --git a/FS/FS/cust_pay_void.pm b/FS/FS/cust_pay_void.pm index 71fe88b6f..946d69fe1 100644 --- a/FS/FS/cust_pay_void.pm +++ b/FS/FS/cust_pay_void.pm @@ -3,7 +3,8 @@ use strict; use vars qw( @ISA ); use Business::CreditCard; use FS::UID qw(getotaker); -use FS::Record qw(qsearchs); # dbh qsearch ); +use FS::Record qw(qsearchs dbh fields); # qsearch ); +use FS::cust_pay; #use FS::cust_bill; #use FS::cust_bill_pay; #use FS::cust_pay_refund; @@ -78,16 +79,53 @@ sub table { 'cust_pay_void'; } Adds this voided payment to the database. -=item delete +=item unvoid -Currently unimplemented. +"Un-void"s this payment: Deletes the voided payment from the database and adds +back a normal payment. =cut -sub delete { - return "Can't delete voided payments!"; +sub unvoid { + my $self = shift; + + 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; + + my $cust_pay = new FS::cust_pay ( { + map { $_ => $self->get($_) } fields('cust_pay') + } ); + my $error = $cust_pay->insert; + if ( $error ) { + $dbh->rollback if $oldAutoCommit; + return $error; + } + + $error = $self->delete; + if ( $error ) { + $dbh->rollback if $oldAutoCommit; + return $error; + } + + $dbh->commit or die $dbh->errstr if $oldAutoCommit; + + ''; + } +=item delete + +Deletes this voided payment. You probably don't want to use this directly; see +the B method to add the original payment back. + =item replace OLD_RECORD Currently unimplemented. diff --git a/httemplate/misc/unvoid-cust_pay_void.cgi b/httemplate/misc/unvoid-cust_pay_void.cgi new file mode 100755 index 000000000..539cd4a23 --- /dev/null +++ b/httemplate/misc/unvoid-cust_pay_void.cgi @@ -0,0 +1,16 @@ +<% + +#untaint paynum +my($query) = $cgi->keywords; +$query =~ /^(\d+)$/ || die "Illegal paynum"; +my $paynum = $1; + +my $cust_pay_void = qsearchs('cust_pay_void', { 'paynum' => $paynum } ); +my $custnum = $cust_pay_void->custnum; + +my $error = $cust_pay_void->unvoid; +eidiot($error) if $error; + +print $cgi->redirect($p. "view/cust_main.cgi?". $custnum); + +%>