Merge branch 'master' of git.freeside.biz:/home/git/freeside
[freeside.git] / httemplate / edit / process / cust_pay-no_auto_apply.cgi
1 <%doc>
2 Quick process for toggling no_auto_apply field in cust_pay.
3
4 Requires paynum and no_auto_apply ('Y' or '') in cgi.
5
6 Requires 'Apply payment' acl.
7 </%doc>
8
9 % if ($error) {
10
11 <P STYLE="color: #FF0000"><% emt($error) %></P>
12
13 % } else {
14
15 <P STYLE="font-weight: bold;"><% emt($message) %></P>
16 <P><% emt('Please wait while the page reloads.') %></P>
17 <SCRIPT TYPE="text/javascript">
18 window.top.location.reload();
19 </SCRIPT>
20
21 % }
22
23 <%init>
24 die "access denied"
25   unless $FS::CurrentUser::CurrentUser->access_right('Apply payment');
26
27 my $paynum = $cgi->param('paynum');
28 my $noauto = $cgi->param('no_auto_apply');
29
30 my $error = '';
31 my $message = '';
32 my $cust_pay = qsearchs('cust_pay',{ paynum => $paynum });
33 if ($cust_pay) {
34   if (($noauto eq 'Y') || (defined($noauto) && (length($noauto) == 0))) {
35     $cust_pay->no_auto_apply($noauto);
36     $error = $cust_pay->replace;
37     $message = $noauto ?
38                q(Payment will not be automatically applied to open invoices, must be applied manually) :
39                q(Payment will be automatically applied to open invoices the next time this customer's payments are processed);
40   } else {
41     $error = 'no_auto_apply not specified';
42   }
43 } else {
44   $error .= 'Payment could not be found in database';
45 }
46
47
48 </%init>