summaryrefslogtreecommitdiff
path: root/httemplate/misc/batch-cust_pay.html
blob: c5ed6d85280e7bb69e76b86cabaa505ab418d881 (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
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
<% include('/elements/header.html', 'Quick payment entry') %>

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

<SCRIPT TYPE="text/javascript">
function warnUnload() {
  if(document.getElementById("OneTrueTable").rows.length > 3 &&
     !document.OneTrueForm.submit.disabled) {
    return "The current batch will be lost.";
  }
  else {
    return null;
  }
}
window.onbeforeunload = warnUnload;

function select_discount_term(row, prefix) {
  var custnum_obj = document.getElementById('custnum'+prefix+row);
  var select_obj = document.getElementById('discount_term'+prefix+row);

  var value = '';
  if (select_obj.type == 'hidden') {
    value = select_obj.value;
  }

  var term_select = document.createElement('SELECT');
  term_select.setAttribute('name', 'discount_term'+row);
  term_select.setAttribute('id',   'discount_term'+row);
  term_select.setAttribute('rownum', row);
  term_select.style.display = '';
  select_obj.parentNode.replaceChild(term_select, select_obj);
  opt(term_select, '', '1 month');
  
  function select_discount_term_update(discount_terms) {

    var termArray = eval('(' + discount_terms + ')');
    for ( var t = 0; t < termArray.length; t++ ) {
      opt(term_select, termArray[t][0], termArray[t][1]);
      if (termArray[t][0] == value) {
        term_select.selectedIndex = t+1;
      }
    }

  }

  discount_terms(custnum_obj.value, select_discount_term_update);

}
</SCRIPT>

<% include('/elements/xmlhttp.html',
              'url'  => $p. 'misc/xmlhttp-cust_main-discount_terms.cgi',
              'subs' => [qw( discount_terms )],
           )
%>

<FORM ACTION="process/batch-cust_pay.cgi" NAME="OneTrueForm" METHOD="POST" onsubmit="document.OneTrueForm.submit.disabled=true;window.onbeforeunload = null;">

<!-- <B>Batch</B> <INPUT TYPE="text" NAME="paybatch"><BR><BR> -->

<% include( "/elements/customer-table.html",
              name_singular => 'payment',
              header  => \@header,
              fields  => \@fields,
              types   => \@types,
              align   => \@align,
              sizes   => \@sizes,
              colors  => \@colors,
              param   => \%param,
              footer  => \@footer,
              footer_align => \@footer_align,
              custnum_update_callback => $custnum_update_callback,
          )
%>

<!-- <BR>
<INPUT TYPE="button" VALUE="TEST addrow" onclick="addRow()"> -->

<BR>
<INPUT TYPE="submit" NAME="submit" VALUE="Post payment batch">

</FORM>

%if ( $cgi->param('error') ) {
<SCRIPT TYPE="text/javascript">
%  for ( my $row = 0; defined($cgi->param("custnum$row")); $row++ ) {
     select_discount_term(<% $row %>, '');
%  }
</SCRIPT>
%}

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

<%init>

die "access denied"
  unless $FS::CurrentUser::CurrentUser->access_right('Post payment batch');

my @header  = ( '', 'Amount', 'Check #' );
my @fields  = ( sub {'$'}, 'paid', 'payinfo' );
my @types   = ( 'immutable', '', '' );
my @align   = ( 'c', 'r', 'r' );
my @sizes   = ( 0, 8, 10 );
my @colors  = ( '', '', '' );
my %param   = ();
my @footer  = ( '$', '_TOTAL', '' );
my @footer_align = ( 'c', 'r', 'r' );
my $custnum_update_callback = '';

if ( FS::Record->scalar_sql('SELECT COUNT(*) FROM part_pkg_discount') ) {
  push @header, '';
  push @fields, 'discount_term';
  push @types, 'immutable';
  push @align, 'r';
  push @sizes, '0';
  push @colors, '';
  push @footer, '';
  push @footer_align, '';
  $custnum_update_callback = 'select_discount_term';
}

push @header, '';
push @fields, 'error';
push @types, 'immutable';
push @align, 'l';
push @sizes, '0';
push @colors, '#ff0000';
push @footer, '';
push @footer_align, '';

$m->comp('/elements/handle_uri_query');

</%init>