Merge branch 'patch-18' of https://github.com/gjones2/Freeside
[freeside.git] / httemplate / search / elements / cust_pay_batch_top.html
1 % # Download batch
2 % if ( $status eq 'O'
3 %   or ( $status eq 'I' and $curuser->access_right('Reprocess batches') )
4 %   or ( $status eq 'R' and $curuser->access_right('Redownload resolved batches') )
5 %   ) {
6 <TABLE>
7 <TR><FORM ACTION="<%$p%>misc/download-batch.cgi" METHOD="POST">
8 <INPUT TYPE="hidden" NAME="batchnum" VALUE="<%$batchnum%>">
9 %   if ( $fixed ) {
10 <INPUT TYPE="hidden" NAME="format" VALUE="<%$fixed%>">
11 %   }
12 %   else {
13 Download batch in format <SELECT NAME="format">
14 %     foreach ( keys %download_formats ) {
15 <OPTION VALUE="<%$_%>"><% $download_formats{$_} %></OPTION>
16 %     }
17 </SELECT> 
18 <& .select_gateway &>
19 %   }
20 <INPUT TYPE="submit" VALUE="Download"></FORM><BR><BR></TR>
21 % } # end of download
22
23 % # Upload batch
24 % if ( $pay_batch->status eq 'I'
25 %   or ( $pay_batch->status eq 'R'
26 %     and $curuser->access_right('Reprocess batches')
27 %     and $conf->exists('batch-manual_approval')
28 %   ) 
29 % ) {
30 <TR>
31 <% include('/elements/form-file_upload.html',
32               'name'      => 'FileUpload',
33               'action'    => "${p}misc/upload-batch.cgi",
34               'num_files' => 1,
35               'fields'    => [ 'batchnum', 'format', 'gatewaynum' ],
36               'url'       => $cgi->self_url,
37               'message'   => 'Batch results uploaded.',
38 ) %>
39 Upload results<BR></TR>
40 <TR>
41 <% include('/elements/file-upload.html',
42               'field'     => 'file',
43               'label'     => 'Filename',
44               'no_table'  => 1,
45 ) %>
46 <INPUT TYPE="hidden" NAME="batchnum" VALUE="<% $batchnum %>">
47 <BR></TR>
48 %   if ( $fixed ) {
49 %     if ( $fixed eq 'td_eft1464' ) { # special case
50 <TR>Upload in format <SELECT NAME="format">
51 <OPTION VALUE="td_eftack264">TD EFT Acknowledgement</OPTION>
52 <OPTION VALUE="td_eftret80">TD EFT Returned Items</OPTION>
53 </SELECT> </TR>
54 %     }
55 %     else {
56 <INPUT TYPE="hidden" NAME="format" VALUE="<% $fixed %>">
57 %     }
58 %   }
59 %   else {
60 <TR>Upload in format <SELECT NAME="format">
61 %     foreach ( keys(%upload_formats) ) {
62 <OPTION VALUE="<%$_%>"><% $upload_formats{$_} %></OPTION>
63 %     }
64 </SELECT>
65 <& .select_gateway &>
66 %   } # if $fixed
67 <TR><INPUT TYPE="submit" VALUE="Upload"></TR>
68 </FORM><BR>
69 % } # end upload
70
71 % # manual approval
72 % if ( $fixed eq 'td_eft1464'
73 %   and $status eq 'I'
74 %   and $payby eq 'CHEK'
75 %   and $conf->exists('batch-manual_approval')
76 %   ) {
77 <TR><INPUT TYPE="button" VALUE="Manually approve" onclick="
78 if ( confirm('Approve all remaining payments in this batch?') ) 
79   window.location.href='<%$p%>misc/process/pay_batch-approve.cgi?batchnum=<%$batchnum%>';
80 "></TR>
81 % } # end manual approval
82 </TABLE>
83
84 % # summary info
85 Batch is <% $statustext{$status} %><BR>
86 <%$count%> payments batched<BR>
87 <%$money_char%><%$total%> total in batch<BR>
88
89 <%def .select_gateway>
90 % if ( $show_gateways ) {
91  or for gateway
92 <& /elements/select-table.html,
93   empty_label => ' ',
94   field     => 'gatewaynum',
95   table     => 'payment_gateway',
96   name_col  => 'label',
97   value_col => 'gatewaynum',
98   order_by  => 'ORDER BY gatewaynum',
99   hashref   => { 
100     'gateway_namespace' => 'Business::BatchPayment',
101     'disabled'          => '',
102   }
103 &>
104 % }
105 </%def>
106 <%shared>
107 my $show_gateways = FS::payment_gateway->count("gateway_namespace = 'Business::BatchPayment' AND disabled IS NULL");
108 </%shared>
109 <%init>
110 my %opt = @_;
111 my $pay_batch = $opt{'pay_batch'} or return;
112 my $conf = new FS::Conf;
113 my $money_char = $conf->config('money_char') || '$';
114 my $payby = $pay_batch->payby;
115 my $status = $pay_batch->status;
116 my $curuser = $FS::CurrentUser::CurrentUser;
117 my $batchnum = $pay_batch->batchnum;
118
119 my $fixed = $conf->config("batch-fixed_format-$payby");
120
121 tie my %download_formats, 'Tie::IxHash', (
122 '' => 'Default batch mode',
123 'NACHA' => '94 byte NACHA',
124 'csv-td_canada_trust-merchant_pc_batch' => 
125               'CSV file for TD Canada Trust Merchant PC Batch',
126 'csv-chase_canada-E-xactBatch' =>
127               'CSV file for Chase Canada E-xactBatch',
128 'PAP' => '80 byte file for TD Canada Trust PAP Batch',
129 'BoM' => 'Bank of Montreal ECA batch',
130 'ach-spiritone' => 'Spiritone ACH batch',
131 'paymentech' => 'XML file for Chase Paymentech',
132 'RBC' => 'Royal Bank of Canada PDS batch',
133 'td_eft1464' => '1464 byte file for TD Commercial Banking EFT',
134 'eft_canada' => 'EFT Canada CSV batch',
135 # insert new batch formats here
136 );
137
138 tie my %upload_formats, 'Tie::IxHash', (
139   %download_formats,
140 # minor tweaks
141   'td_eftack' => 'TD EFT Acknowledgement',
142   'td_eftret' => 'TD EFT Returned Items',
143 );
144 delete $upload_formats{'td_eft1464'};
145 $upload_formats{'PAP'} = '264 byte results for TD Canada Trust PAP Batch',
146
147 my %statustext = ( 'O' => 'open', 'I' => 'in transit', 'R' => 'resolved' );
148
149 my $count_query = "SELECT COUNT(*) FROM cust_pay_batch WHERE batchnum=$batchnum";
150 my $count = FS::Record->scalar_sql($count_query);
151 my $sum_query = "SELECT SUM(amount) FROM cust_pay_batch WHERE batchnum=$batchnum";
152 my $total = sprintf("%.2f", FS::Record->scalar_sql($sum_query));
153 </%init>