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 <% $cgi->redirect(popurl(2). $opt{error_redirect}. '?'. $cgi->query_string ) %>
26 <% header("$src_thing application$to sucessful") %>
27 <SCRIPT TYPE="text/javascript">
28 window.top.location.reload();
39 my $src_thing = ucfirst($opt{'src_thing'});
40 my $src_table = $opt{'src_table'};
41 my $src_pkey = dbdef->table($src_table)->primary_key;
43 my $to = $opt{'link_table'} =~ /refund/ ? ' to Refund' : '';
45 $cgi->param($src_pkey) =~ /^(\d+)$/ or die "Illegal $src_pkey!";
46 my $src_pkeyvalue = $1;
48 my $src = qsearchs($src_table, { $src_pkey => $src_pkeyvalue } )
49 or die "No such $src_pkey: $src_pkeyvalue";
51 my $cust_main = qsearchs('cust_main', { 'custnum' => $src->custnum } )
52 or die "Bogus $src_thing: not attached to customer";
54 my $custnum = $cust_main->custnum;
56 my @subnames = grep { /.+/ } map { /^subnum(\d+)$/ ? $1 : '' } $cgi->param;
57 my @subitems = map { [ $cgi->param("subnum$_"), $cgi->param("subamount$_"), $cgi->param("taxXlocationnum$_") ] }
59 { local $^W = 0; @subitems = grep { $_->[1] + 0 } @subitems; }
62 $options{subitems} = \@subitems if scalar(@subitems);
64 my $oldAutoCommit = $FS::UID::AutoCommit;
65 local $FS::UID::AutoCommit = 0;
69 # $new = new FS::cust_refund ( {
70 # 'reason' => 'Refunding payment', #enter reason in UI
71 # 'refund' => $cgi->param('amount'),
73 # #'_date' => $cgi->param('_date'),
74 # 'payinfo' => 'Cash', #enter payinfo in UI
75 # 'paynum' => $paynum,
79 if ($src->amount != $cgi->param('src_amount')) {
80 $src->amount($cgi->param('src_amount'));
81 $error = $src->replace;
84 my $class = 'FS::'. $opt{link_table};
88 $_ => scalar($cgi->param($_));
89 } fields($opt{link_table})
96 $error ||= $new->insert( %options );
99 $dbh->rollback if $oldAutoCommit;
101 $dbh->commit or die $dbh->errstr if $oldAutoCommit;