eee81dd5b6c67dfca39344e17c8f20f4da203a62
[freeside.git] / httemplate / search / elements / cust_pay_batch_top.html
1 <& /elements/xmlhttp.html,
2   'url'   => $p.'misc/xmlhttp-pay_batch-note.html',
3   'subs'  => [ 'get_note' ]
4 &>
5 <script type="text/javascript">
6 function format_changed() {
7   var form = document.forms['download'];
8   get_note( <% $batchnum %>, form.elements['format'].value,
9     //callback
10     function(text) {
11       document.getElementById('download_note').textContent = text;
12     }
13   );
14 }
15 <&| /elements/onload.js &>format_changed()</&>
16 </script>
17 % # Download batch
18 % if ( $status eq 'O'
19 %   or ( $status eq 'I' and $curuser->access_right('Reprocess batches') )
20 %   or ( $status eq 'R' and $curuser->access_right('Redownload resolved batches') )
21 %   ) {
22 <FORM ACTION="<%$p%>misc/download-batch.cgi" NAME="download" METHOD="GET">
23     <INPUT TYPE="hidden" NAME="batchnum" VALUE="<%$batchnum%>">
24 %   if ( $fixed ) {
25     <INPUT TYPE="hidden" NAME="format" VALUE="<%$fixed%>">
26 %   }
27 %   else {
28     Download batch in format <SELECT NAME="format" onchange="format_changed()">
29 %     foreach ( keys %download_formats ) {
30       <OPTION VALUE="<%$_%>"><% $download_formats{$_} %></OPTION>
31 %     }
32     </SELECT> 
33     <& .select_gateway &>
34 %   }
35     <BR>
36     <DIV STYLE="color:#ff0000" ID="download_note"></DIV>
37     <INPUT TYPE="submit" VALUE="Download">
38 % } # end of download
39 </FORM>
40 <BR>
41
42 % # Upload batch
43 % if ( $pay_batch->status eq 'I'
44 %   or ( $pay_batch->status eq 'R'
45 %     and $curuser->access_right('Reprocess batches')
46 %     and $conf->exists('batch-manual_approval')
47 %   ) 
48 % ) {
49 <& /elements/form-file_upload.html,
50               'name'      => 'FileUpload',
51               'action'    => "${p}misc/upload-batch.cgi",
52               'num_files' => 1,
53               'fields'    => [ 'batchnum', 'format', 'gatewaynum' ],
54               'url'       => $cgi->self_url,
55               'message'   => 'Batch results uploaded.',
56 &>
57   Upload results<BR>
58   <& /elements/file-upload.html,
59               'field'     => 'file',
60               'label'     => 'Filename',
61               'no_table'  => 1,
62   &>
63   <INPUT TYPE="hidden" NAME="batchnum" VALUE="<% $batchnum %>">
64   <BR>
65 %   if ( $fixed ) {
66 %     if ( $fixed eq 'td_eft1464' ) { # special case
67   Upload in format <SELECT NAME="format">
68     <OPTION VALUE="td_eftack264">TD EFT Acknowledgement</OPTION>
69     <OPTION VALUE="td_eftret80">TD EFT Returned Items</OPTION>
70   </SELECT>
71 %     }
72 %     else {
73   <INPUT TYPE="hidden" NAME="format" VALUE="<% $fixed %>">
74 %     }
75 %   }
76 %   else {
77   Upload in format <SELECT NAME="format">
78 %     foreach ( keys(%upload_formats) ) {
79     <OPTION VALUE="<%$_%>"><% $upload_formats{$_} %></OPTION>
80 %     }
81   </SELECT>
82   <& .select_gateway &>
83 %   } # if $fixed
84   <INPUT TYPE="submit" VALUE="Upload">
85 </FORM><BR>
86 % } # end upload
87
88 % # manual approval
89 % if ( $fixed eq 'td_eft1464'
90 %   and $status eq 'I'
91 %   and $payby eq 'CHEK'
92 %   and $conf->exists('batch-manual_approval')
93 %   ) {
94 <INPUT TYPE="button" VALUE="Manually approve" onclick="
95 if ( confirm('Approve all remaining payments in this batch?') ) 
96   window.location.href='<%$p%>misc/process/pay_batch-approve.cgi?batchnum=<%$batchnum%>';
97 ">
98 <BR>
99 % } # end manual approval
100
101 % # summary info
102 Batch is <% $statustext{$status} %><BR>
103 <%$count%> payments batched<BR>
104 <%$money_char%><%$total%> total in batch<BR>
105
106 <%def .select_gateway>
107 % if ( $show_gateways ) {
108  or for gateway
109 <& /elements/select-table.html,
110   empty_label => ' ',
111   field     => 'gatewaynum',
112   table     => 'payment_gateway',
113   name_col  => 'label',
114   value_col => 'gatewaynum',
115   order_by  => 'ORDER BY gatewaynum',
116   hashref   => { 
117     'gateway_namespace' => 'Business::BatchPayment',
118     'disabled'          => '',
119   }
120 &>
121 % }
122 </%def>
123 <%shared>
124 my $show_gateways = FS::payment_gateway->count("gateway_namespace = 'Business::BatchPayment' AND disabled IS NULL");
125 </%shared>
126 <%init>
127 my %opt = @_;
128 my $pay_batch = $opt{'pay_batch'} or return;
129 my $conf = new FS::Conf;
130 my $money_char = $conf->config('money_char') || '$';
131 my $payby = $pay_batch->payby;
132 my $status = $pay_batch->status;
133 my $curuser = $FS::CurrentUser::CurrentUser;
134 my $batchnum = $pay_batch->batchnum;
135
136 my $fixed = $conf->config("batch-fixed_format-$payby");
137
138 tie my %download_formats, 'Tie::IxHash', FS::pay_batch::batch_download_formats;
139
140 tie my %upload_formats, 'Tie::IxHash', (
141   %download_formats,
142 # minor tweaks
143   'td_eftack' => 'TD EFT Acknowledgement',
144   'td_eftret' => 'TD EFT Returned Items',
145 );
146 delete $upload_formats{'td_eft1464'};
147 $upload_formats{'PAP'} = '264 byte results for TD Canada Trust PAP Batch';
148
149 if ($pay_batch->type eq "CREDIT") {
150   foreach my $key (keys %download_formats) {
151     delete $download_formats{$key} unless FS::pay_batch->can_handle_electronic_refunds($key);
152   }
153 }
154
155 my %statustext = ( 'O' => 'open', 'I' => 'in transit', 'R' => 'resolved' );
156
157 my $count_query = "SELECT COUNT(*) FROM cust_pay_batch WHERE batchnum=$batchnum";
158 my $count = FS::Record->scalar_sql($count_query);
159 my $sum_query = "SELECT SUM(amount) FROM cust_pay_batch WHERE batchnum=$batchnum";
160 my $total = sprintf("%.2f", FS::Record->scalar_sql($sum_query));
161
162 </%init>