[freeside-commits] freeside/httemplate/misc download-batch.cgi, 1.6, 1.7

Ivan,,, ivan at wavetail.420.am
Thu Jun 15 17:27:45 PDT 2006


Update of /home/cvs/cvsroot/freeside/httemplate/misc
In directory wavetail:/tmp/cvs-serv32733

Modified Files:
	download-batch.cgi 
Log Message:
s/printf/sprintf/ and make the config a little less strange

Index: download-batch.cgi
===================================================================
RCS file: /home/cvs/cvsroot/freeside/httemplate/misc/download-batch.cgi,v
retrieving revision 1.6
retrieving revision 1.7
diff -u -d -r1.6 -r1.7
--- download-batch.cgi	20 May 2006 20:06:30 -0000	1.6
+++ download-batch.cgi	16 Jun 2006 00:27:43 -0000	1.7
@@ -5,11 +5,12 @@
 #http_header('Content-Type' => 'text/comma-separated-values' ); #IE chokes
 http_header('Content-Type' => 'text/plain' );
 
-#need default
-my $formatconfig = "batchconfig".$cgi->param('format');
-
-die "No batch configuration exists.\n$formatconfig\n" unless $conf->exists($formatconfig);
-my $format = $conf->config($formatconfig);
+my $format;
+if ( $cgi->param('format') =~ /^([\w ]+)$/ ) {
+  $format = $1;
+} else {
+  $format = $conf->config('batch_default_format');
+}
 
 my $oldAutoCommit = $FS::UID::AutoCommit;
 local $FS::UID::AutoCommit = 0;
@@ -31,11 +32,14 @@
 my $jdate = sprintf("%03d", $date[5] % 100).sprintf("%03d", $date[7]);
 
 if ($format eq "BoM") {
-  my($reformat,$origid,$datacenter,$typecode,$shortname,$longname,$mybank,$myacct) = $conf->config('batchconfig');
-  printf "A%10s%04u%06u%05u%54s\n",$origid,$pay_batch->batchnum,$jdate,$datacenter,"";
-  printf "XD%03u%06u%-15s%-30s%09u%-12s   \n",$typecode,$jdate,$shortname,$longname,$mybank,$myacct;
+
+  my($reformat,$origid,$datacenter,$typecode,$shortname,$longname,$mybank,$myacct) = $conf->config("batchconfig-$format");
+  %><%= sprintf( "A%10s%04u%06u%05u%54s\n",$origid,$pay_batch->batchnum,$jdate,$datacenter,"").
+        sprintf( "XD%03u%06u%-15s%-30s%09u%-12s   \n",$typecode,$jdate,$shortname,$longname,$mybank,$myacct )
+  %><%
+
 }elsif ($format eq "CSV file for TD Canada Trust Merchant PC Batch"){
-  1;
+#  1;
 }else{
   die "Unknown format for batch in batchconfig. \n";
 }
@@ -46,30 +50,36 @@
 			      {'batchnum'=>$pay_batch->batchnum} )
 ) {
 
-$cust_pay_batch->exp =~ /^\d{2}(\d{2})[\/\-](\d+)[\/\-]\d+$/;
-my( $mon, $y ) = ( $2, $1 );
-$mon = "0$mon" if $mon < 10;
-my $exp = "$mon$y";
-$batchcount++;
-$batchtotal += $cust_pay_batch->amount;
+  $cust_pay_batch->exp =~ /^\d{2}(\d{2})[\/\-](\d+)[\/\-]\d+$/;
+  my( $mon, $y ) = ( $2, $1 );
+  $mon = "0$mon" if $mon < 10;
+  my $exp = "$mon$y";
+  $batchcount++;
+  $batchtotal += $cust_pay_batch->amount;
+  
+  if ($format eq "BoM") {
 
-if ($format eq "BoM") {
-  my( $account, $aba ) = split( '@', $cust_pay_batch->payinfo );
-  printf "D%010u%09u%-12s%-29s%-19s\n",$cust_pay_batch->amount*100,$aba,$account,$cust_pay_batch->payname,$cust_pay_batch->invnum;
-}elsif ($format eq "CSV file for TD Canada Trust Merchant PC Batch"){
-%>,,,,<%= $cust_pay_batch->payinfo %>,<%= $exp %>,<%= $cust_pay_batch->amount %>,<%= $cust_pay_batch->paybatchnum %>
-<% }else{
-   die "I'm already dead, but you did not know that.\n";
-}
+    my( $account, $aba ) = split( '@', $cust_pay_batch->payinfo );
+    %><%= sprintf( "D%010u%09u%-12s%-29s%-19s\n",$cust_pay_batch->amount*100,$aba,$account,$cust_pay_batch->payname,$cust_pay_batch->invnum %><%
+
+  } elsif ($format eq "CSV file for TD Canada Trust Merchant PC Batch") {
+
+    %>,,,,<%= $cust_pay_batch->payinfo %>,<%= $exp %>,<%= $cust_pay_batch->amount %>,<%= $cust_pay_batch->paybatchnum %><%
+
+  } else {
+    die "I'm already dead, but you did not know that.\n";
+  }
 
 }
 
 if ($format eq "BoM") {
-  printf "YD%08u%014u%56s\n",$batchcount,$batchtotal*100,"";
-  printf "Z%014u%05u%014u%05u%41s\n",$batchtotal*100,$batchcount,"0","0","";
-}elsif ($format eq "CSV file for TD Canada Trust Merchant PC Batch"){
-  1;
-} else{
+
+  %><%= sprintf( "YD%08u%014u%56s\n",$batchcount,$batchtotal*100,"" ).
+        sprintf( "Z%014u%05u%014u%05u%41s\n",$batchtotal*100,$batchcount,"0","0","" ) %><%
+
+} elsif ($format eq "CSV file for TD Canada Trust Merchant PC Batch"){
+  #1;
+} else {
   die "I'm already dead (again), but you did not know that.\n";
 }
 



More information about the freeside-commits mailing list