summaryrefslogtreecommitdiff
path: root/httemplate/edit/cust_credit_bill.cgi
blob: ee29f8e0c9852510d444892b3b143eeac92d9934 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
<%  header("Apply Credit", '') %>

<% include('/elements/error.html') %>

<FORM ACTION="<% $p1 %>process/cust_credit_bill.cgi" METHOD=POST>

Credit #<B><% $crednum %></B>
<INPUT TYPE="hidden" NAME="crednum" VALUE="<% $crednum %>">

<BR>Date: <B><% time2str("%D", $cust_credit->_date) %></B>

<BR>Amount: $<B><% $cust_credit->amount %></B>

<BR>Unapplied amount: $<B><% $credited %></B>

<BR>Reason: <B><% $cust_credit->reason %></B>

<SCRIPT>
function changed(what) {
  cust_bill = what.options[what.selectedIndex].value;

% foreach my $cust_bill ( @cust_bill ) {

  if ( cust_bill == <% $cust_bill->invnum %> ) {
    what.form.amount.value = "<% min($cust_bill->owed, $credited) %>";
  }

% } 

  if ( cust_bill == "Refund" ) {
    what.form.amount.value = "<% $credited %>";
  }
}
</SCRIPT>

<BR>Invoice #<SELECT NAME="invnum" SIZE=1 onChange="changed(this)">
<OPTION VALUE="">

% foreach my $cust_bill ( @cust_bill ) { 
  <OPTION<% $cust_bill->invnum eq $invnum ? ' SELECTED' : '' %> VALUE="<% $cust_bill->invnum %>"><% $cust_bill->invnum %> - <% time2str("%D",$cust_bill->_date) %> - $<% $cust_bill->owed %>
% } 

<OPTION VALUE="Refund">Refund
</SELECT>

<BR>Amount $<INPUT TYPE="text" NAME="amount" VALUE="<% $amount %>" SIZE=8 MAXLENGTH=8>

<BR>
<CENTER><INPUT TYPE="submit" VALUE="Apply"></CENTER>

</FORM>
</BODY>
</HTML>

<%init>
my($crednum, $amount, $invnum);
if ( $cgi->param('error') ) {
  #$cust_credit_bill = new FS::cust_credit_bill ( {
  #  map { $_, scalar($cgi->param($_)) } fields('cust_credit_bill')
  #} );
  $crednum = $cgi->param('crednum');
  $amount = $cgi->param('amount');
  #$refund = $cgi->param('refund');
  $invnum = $cgi->param('invnum');
} else {
  my($query) = $cgi->keywords;
  $query =~ /^(\d+)$/;
  $crednum = $1;
  $amount = '';
  #$refund = 'yes';
  $invnum = '';
}

my $otaker = getotaker;

my $p1 = popurl(1);

my $cust_credit = qsearchs('cust_credit', { 'crednum' => $crednum } );
die "credit $crednum not found!" unless $cust_credit;

my $credited = $cust_credit->credited;

my @cust_bill = sort {    $a->_date  <=> $b->_date
                       or $a->invnum <=> $b->invnum
                     }
                grep { $_->owed != 0 }
                qsearch('cust_bill', { 'custnum' => $cust_credit->custnum } );
</%init>