my %opt = @_;
+my $error = '';
+
my $src_thing = ucfirst($opt{'src_thing'});
my $src_table = $opt{'src_table'};
my $src_pkey = dbdef->table($src_table)->primary_key;
my %options = ();
$options{subitems} = \@subitems if scalar(@subitems);
+
+my $oldAutoCommit = $FS::UID::AutoCommit;
+local $FS::UID::AutoCommit = 0;
+my $dbh = dbh;
my $new;
# $new = new FS::cust_refund ( {
# } );
#} else {
+ if ($src->amount != $cgi->param('src_amount')) {
+ $src->amount($cgi->param('src_amount'));
+ $error = $src->replace;
+ }
+
my $class = 'FS::'. $opt{link_table};
$new = $class->new( {
$options{manual} = 1;
-my $error = $new->insert( %options );
+$error ||= $new->insert( %options );
+if ($error) {
+ $dbh->rollback if $oldAutoCommit;
+} else {
+ $dbh->commit or die $dbh->errstr if $oldAutoCommit;
+}
</%init>