6 include('elements/ApplicationCommon.html',
7 'error_redirect' => 'cust_bill_pay.cgi',
8 'src_table' => 'cust_pay',
9 'src_thing' => 'payment',
10 'link_table' => 'cust_bill_pay',
14 include('elements/ApplicationCommon.html',
15 'error_redirect' => 'cust_credit_bill.cgi',
16 'src_table' => 'cust_credit',
17 'src_thing' => 'credit',
18 'link_table' => 'cust_credit_bill',
23 % $cgi->param('error', $error);
24 % my $query = $m->scomp('/elements/create_uri_query');
25 <% $cgi->redirect(popurl(2). $opt{error_redirect}. "?$query") %>
27 <& /elements/header-popup.html, "$src_thing application$to successful" &>
28 <SCRIPT TYPE="text/javascript">
40 my $src_thing = ucfirst($opt{'src_thing'});
41 my $src_table = $opt{'src_table'};
42 my $src_pkey = dbdef->table($src_table)->primary_key;
44 my $to = $opt{'link_table'} =~ /refund/ ? ' to Refund' : '';
46 $cgi->param($src_pkey) =~ /^(\d+)$/ or die "Illegal $src_pkey!";
47 my $src_pkeyvalue = $1;
49 my $src = qsearchs($src_table, { $src_pkey => $src_pkeyvalue } )
50 or die "No such $src_pkey: $src_pkeyvalue";
52 my $cust_main = qsearchs('cust_main', { 'custnum' => $src->custnum } )
53 or die "Bogus $src_thing: not attached to customer";
55 my $custnum = $cust_main->custnum;
57 my @subnames = grep { /.+/ } map { /^subnum(\d+)$/ ? $1 : '' } $cgi->param;
58 my @subitems = map { [ $cgi->param("subnum$_"), $cgi->param("subamount$_"), $cgi->param("taxXlocationnum$_") ] }
60 { local $^W = 0; @subitems = grep { $_->[1] + 0 } @subitems; }
63 $options{subitems} = \@subitems if scalar(@subitems);
65 my $oldAutoCommit = $FS::UID::AutoCommit;
66 local $FS::UID::AutoCommit = 0;
70 # $new = new FS::cust_refund ( {
71 # 'reason' => 'Refunding payment', #enter reason in UI
72 # 'refund' => scalar($cgi->param('amount')),
74 # #'_date' => scalar($cgi->param('_date')),
75 # 'payinfo' => 'Cash', #enter payinfo in UI
76 # 'paynum' => $paynum,
80 if ($src->amount != $cgi->param('src_amount')) {
81 $src->amount($cgi->param('src_amount'));
82 $error = $src->replace;
85 my $class = 'FS::'. $opt{link_table};
89 $_ => scalar($cgi->param($_));
90 } fields($opt{link_table})
97 $error ||= $new->insert( %options );
100 $dbh->rollback if $oldAutoCommit;
102 $dbh->commit or die $dbh->errstr if $oldAutoCommit;