[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

SF.net SVN: ledger-smb:[5744] trunk



Revision: 5744
          http://sourceforge.net/p/ledger-smb/code/5744
Author:   einhverfr
Date:     2013-05-03 14:59:37 +0000 (Fri, 03 May 2013)
Log Message:
-----------
EDI electronic invoices now print properly.

Modified Paths:
--------------
    trunk/LedgerSMB/Template/TXT.pm
    trunk/LedgerSMB/Template.pm
    trunk/bin/io.pl

Modified: trunk/LedgerSMB/Template/TXT.pm
===================================================================
--- trunk/LedgerSMB/Template/TXT.pm	2013-05-03 14:49:31 UTC (rev 5743)
+++ trunk/LedgerSMB/Template/TXT.pm	2013-05-03 14:59:37 UTC (rev 5744)
@@ -47,7 +47,13 @@
 use Error qw(:try);
 use Template;
 use LedgerSMB::Template::TTI18N;
+use DateTime;
 
+# The following are for EDI only
+my $dt = DateTime->now;
+my $date = sprintf('%04d%02d%02d', $dt->year, $dt->month, $dt->day);
+my $time = sprintf('%02d%02d', $dt->hour, $dt->min);
+
 my $binmode = ':utf8';
 binmode STDOUT, $binmode;
 binmode STDERR, $binmode;
@@ -103,14 +109,15 @@
 sub process {
 	my $parent = shift;
 	my $cleanvars = shift;
+        $cleanvars->{EDI_CURRENT_DATE} = $date;
+        $cleanvars->{EDI_CURRENT_TIME} = $time;
 	my $template;
 	my $source;
 	my $output;
         $parent->{binmode} = $binmode;
 	if ($parent->{outputfile}) {
 		$output = "$parent->{outputfile}.". get_extension($parent);
-	} else {
-		$output = \$parent->{output};
+                $parent->{outputfile} = $output;
 	}
 	if (ref $parent->{template} eq 'SCALAR') {
 		$source = $parent->{template};
@@ -132,9 +139,14 @@
 		$source, 
 		{%$cleanvars, %$LedgerSMB::Template::TTI18N::ttfuncs,
 			'escape' => \&preprocess},
-		$output, binmode => ':utf8')) {
-		throw Error::Simple $template->error();
+		\$parent->{output}, binmode => ':utf8')) {
+		die $template->error();
 	}
+        if ($output){
+            open(OUT, '>', $output);
+            print OUT $parent->{output};
+            close OUT;
+        }
 	$parent->{mimetype} = 'text/plain';
 }
 

Modified: trunk/LedgerSMB/Template.pm
===================================================================
--- trunk/LedgerSMB/Template.pm	2013-05-03 14:49:31 UTC (rev 5743)
+++ trunk/LedgerSMB/Template.pm	2013-05-03 14:59:37 UTC (rev 5744)
@@ -220,6 +220,9 @@
         } elsif (lc $self->{format} eq 'XML'){
                 $self->{format} = 'XML';
                 $self->{format_args}{filetype} = 'xml';
+        } elsif ($self->{format} =~ /edi$/i){
+                $self->{format_args}{extension} = lc $self->{format};
+                $self->{format} = 'TXT';
         }
 	bless $self, $class;
 
@@ -341,6 +344,9 @@
                return $str;
         };
 
+        use Data::Dumper;
+        $Data::Dumper::Sortkeys = 1;
+
 	$format->can('process')->($self, $cleanvars);
 	#return $format->can('postprocess')->($self);
 	my $post = $format->can('postprocess')->($self);

Modified: trunk/bin/io.pl
===================================================================
--- trunk/bin/io.pl	2013-05-03 14:49:31 UTC (rev 5743)
+++ trunk/bin/io.pl	2013-05-03 14:59:37 UTC (rev 5744)
@@ -1460,6 +1460,12 @@
             value => 'pdf',
             };
     }
+    if ($form->{type} eq 'invoice'){
+       push @{$options{format}{options}}, {
+            text => $locale->text('894.EDI'),
+            value => '894.edi',
+            };
+    }
 
     if (   %{LedgerSMB::Sysconfig::printer}
         && ${LedgerSMB::Sysconfig::latex}

This was sent by the SourceForge.net collaborative development platform, the world's largest Open Source development site.