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