chase canada E-xactBatch
[freeside.git] / httemplate / misc / download-batch.cgi
1 %
2 %
3 %my $conf=new FS::Conf;
4 %
5 %#http_header('Content-Type' => 'text/comma-separated-values' ); #IE chokes
6 %http_header('Content-Type' => 'text/plain' );
7 %
8 %my $batchnum;
9 %if ( $cgi->param('batchnum') =~ /^(\d+)$/ ) {
10 %  $batchnum = $1;
11 %} else {
12 %  die "No batch number (bad URL) \n";
13 %}
14 %
15 %my $format;
16 %if ( $cgi->param('format') =~ /^([\w\- ]+)$/ ) {
17 %  $format = $1;
18 %} else {
19 %  $format = $conf->config('batch-default_format');
20 %}
21 %
22 %my $oldAutoCommit = $FS::UID::AutoCommit;
23 %local $FS::UID::AutoCommit = 0;
24 %my $dbh = dbh;
25 %
26 %my $pay_batch = qsearchs('pay_batch', {'batchnum'=>$batchnum, 'status'=>'O'} );
27 %die "No pending batch. \n" unless $pay_batch;
28 %
29 %my %batchhash = $pay_batch->hash;
30 %$batchhash{'status'} = 'I';
31 %$batchhash{'download'} = time unless $batchhash{'download'};
32 %my $new = new FS::pay_batch \%batchhash;
33 %my $error = $new->replace($pay_batch);
34 %die "error updating batch status: $error\n" if $error;
35 %
36 %my $batchtotal=0;
37 %my $batchcount=0;
38 %
39 %my (@date)=localtime($new->download);
40 %my $jdate = sprintf("%03d", $date[5] % 100).sprintf("%03d", $date[7] + 1);
41 %my $cdate = sprintf("%02d", $date[3]).sprintf("%02d", $date[4] + 1).
42 %            sprintf("%02d", $date[5] % 100);
43 %my $sdate = sprintf("%02d", $date[5] % 100).'/'.sprintf("%02d", $date[4] + 1).
44 %            '/'.sprintf("%02d", $date[3]);
45 %
46 %if ($format eq "BoM") {
47 %
48 %  my($origid,$datacenter,$typecode,$shortname,$longname,$mybank,$myacct) =
49 %    $conf->config("batchconfig-$format");
50 %  
51 <% sprintf( "A%10s%04u%06u%05u%54s\n",$origid,$pay_batch->batchnum,$jdate,$datacenter,"").
52         sprintf( "XD%03u%06u%-15s%-30s%09u%-12s   \n",$typecode,$jdate,$shortname,$longname,$mybank,$myacct )
53   %>
54 %
55 %
56 %}elsif ($format eq "PAP"){
57 %
58 %  my($origid,$datacenter,$typecode,$shortname,$longname,$mybank,$myacct) =
59 %    $conf->config("batchconfig-$format");
60 %  
61 <% sprintf( "H%10sD%3s%06u%-15s%09u%-12s%04u%19s\n",$origid,$typecode,$cdate,$shortname,$mybank,$myacct,$pay_batch->batchnum,"")
62
63   %>
64 %
65 %
66 %}elsif ($format eq "csv-td_canada_trust-merchant_pc_batch"){
67 %#  1;
68 %}elsif ($format eq "csv-chase_canada-E-xactBatch"){
69 %
70 %  my($origid) = $conf->config("batchconfig-$format");
71 <% sprintf( '$$E-xactBatchFileV1.0$$%s:%03u$$%s',$sdate,$pay_batch->batchnum, $origid)
72   %>
73 %
74 %}else{
75 %  die "Unknown format for batch in batchconfig. \n";
76 %}
77 %
78 %
79 %for my $cust_pay_batch ( sort { $a->paybatchnum <=> $b->paybatchnum }
80 %                           qsearch('cust_pay_batch',
81 %                             {'batchnum'=>$pay_batch->batchnum} )
82 %) {
83 %
84 %  $cust_pay_batch->exp =~ /^\d{2}(\d{2})[\/\-](\d+)[\/\-]\d+$/;
85 %  my( $mon, $y ) = ( $2, $1 );
86 %  $mon = "0$mon" if $mon < 10;
87 %  my $exp = "$mon$y";
88 %  $batchcount++;
89 %  $batchtotal += $cust_pay_batch->amount;
90 %  
91 %  if ($format eq "BoM") {
92 %
93 %    my( $account, $aba ) = split( '@', $cust_pay_batch->payinfo );
94 %    
95 <% sprintf( "D%010.0f%09u%-12s%-29s%-19s\n",$cust_pay_batch->amount*100,$aba,$account,$cust_pay_batch->payname,$cust_pay_batch->paybatchnum) %>
96 %
97 %
98 %  } elsif ($format eq "PAP"){
99 %
100 %    my( $account, $aba ) = split( '@', $cust_pay_batch->payinfo );
101 %    
102 <% sprintf( "D%-23s%06u%-19s%09u%-12s%010.0f\n",$cust_pay_batch->payname,$cdate,$cust_pay_batch->paybatchnum,$aba,$account,$cust_pay_batch->amount*100) %>
103 %
104 %
105 %  } elsif ($format eq "csv-td_canada_trust-merchant_pc_batch") {
106 %
107 %    
108 ,,,,<% $cust_pay_batch->payinfo %>,<% $exp %>,<% $cust_pay_batch->amount %>,<% $cust_pay_batch->paybatchnum %>
109 %
110 %
111 %  } elsif ($format eq "csv-chase_canada-E-xactBatch"){
112 %
113 %    
114 <% $cust_pay_batch->paybatchnum %>,<% $cust_pay_batch->custnum %>,<% $cust_pay_batch->invnum %>,"<% $cust_pay_batch->payname %>",01,<% $cust_pay_batch->payinfo %>,<% $cust_pay_batch->amount %>,<% $exp %>,,
115 %
116 %
117 %  } else {
118 %    die "I'm already dead, but you did not know that.\n";
119 %  }
120 %
121 %}
122 %
123 %if ($format eq "BoM") {
124 %
125 %  
126 <% sprintf( "YD%08u%014.0f%56s\n",$batchcount,$batchtotal*100,"" ).
127         sprintf( "Z%014u%05u%014u%05u%41s\n",$batchtotal*100,$batchcount,"0","0","" ) %>
128 %
129 %
130 %} elsif ($format eq "PAP"){
131 %
132 %  
133 <% sprintf( "T%08u%014.0f%57s\n",$batchcount,$batchtotal*100,"" ) %>
134 %
135 %
136 %} elsif ($format eq "csv-td_canada_trust-merchant_pc_batch"){
137 %  #1;
138 %} elsif ($format eq "csv-chase_canada-E-xactBatch"){
139 %  #1;
140 %} else {
141 %  die "I'm already dead (again), but you did not know that.\n";
142 %}
143 %
144 %$dbh->commit or die $dbh->errstr if $oldAutoCommit;
145 %
146 %
147
148