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

SF.net SVN: ledger-smb:[4622] branches/1.3



Revision: 4622
          http://ledger-smb.svn.sourceforge.net/ledger-smb/?rev=4622&view=rev
Author:   einhverfr
Date:     2012-03-28 13:19:10 +0000 (Wed, 28 Mar 2012)
Log Message:
-----------
CSV pricelists

Modified Paths:
--------------
    branches/1.3/Changelog
    branches/1.3/LedgerSMB/Template/CSV.pm
    branches/1.3/LedgerSMB/Template/TXT.pm
    branches/1.3/LedgerSMB/Template.pm
    branches/1.3/UI/Contact/pricelist.html

Added Paths:
-----------
    branches/1.3/UI/lib/dynatable.csv

Modified: branches/1.3/Changelog
===================================================================
--- branches/1.3/Changelog	2012-03-28 12:09:13 UTC (rev 4621)
+++ branches/1.3/Changelog	2012-03-28 13:19:10 UTC (rev 4622)
@@ -7,7 +7,7 @@
 * Corrected build issues w/Makefile due to inclusion of LedgerSMB.pm (Chris T)
 * ledgersmb.conf.default : Update default PATH (H Sorli, item 3430019)
 * Fixed imballanced payments when early payment discount processed (Chris T)
-* Pricelists exportable as PDF (Chris T)
+* Pricelists exportable as PDF and CSV (Chris T)
 
 Chris B is Chris Bennet
 Chris T is Chris Travers

Modified: branches/1.3/LedgerSMB/Template/CSV.pm
===================================================================
--- branches/1.3/LedgerSMB/Template/CSV.pm	2012-03-28 12:09:13 UTC (rev 4621)
+++ branches/1.3/LedgerSMB/Template/CSV.pm	2012-03-28 13:19:10 UTC (rev 4622)
@@ -124,8 +124,11 @@
 }
 
 sub postprocess {
-	my $parent = shift;
+	my ($parent, ) = @_;
 	$parent->{rendered} = "$parent->{outputfile}.csv" if $parent->{outputfile};
+        if (!$parent->{rendered}){
+            return "$parent->{template}.csv";
+        }
 	return $parent->{rendered};
 }
 

Modified: branches/1.3/LedgerSMB/Template/TXT.pm
===================================================================
--- branches/1.3/LedgerSMB/Template/TXT.pm	2012-03-28 12:09:13 UTC (rev 4621)
+++ branches/1.3/LedgerSMB/Template/TXT.pm	2012-03-28 13:19:10 UTC (rev 4622)
@@ -111,7 +111,10 @@
 }
 
 sub postprocess {
-    my $parent = shift;
+    my ($self, $parent) = shift;
+    if (!$parent->{rendered}){
+        return $parent->{template} . '.' get_extension($parent); 
+    }
     $parent->{rendered} = "$parent->{outputfile}.". get_extension($parent) if $parent->{outputfile};
     return $parent->{rendered};
 }

Modified: branches/1.3/LedgerSMB/Template.pm
===================================================================
--- branches/1.3/LedgerSMB/Template.pm	2012-03-28 12:09:13 UTC (rev 4621)
+++ branches/1.3/LedgerSMB/Template.pm	2012-03-28 13:19:10 UTC (rev 4622)
@@ -298,7 +298,11 @@
 sub escape {
     my ($self, $vars) = @_;
     my $format = "LedgerSMB::Template::$self->{format}";
-    return $format->can('escape')->($vars) || $vars;
+    if ($format->can('escape')){
+         return $format->can('escape')->($vars);
+    } else {
+         return $vars;
+    }
 } 
 
 sub output {
@@ -344,8 +348,7 @@
 
 	my $format = "LedgerSMB::Template::$self->{format}";
 	my $disposition = "";
-	my $name = $format->can('postprocess')->($self);
-
+	my $name = $format->can('postprocess')->($self) || $self->{rendered};
 	if ($name) {
 		$name =~ s#^.*/##;
 		$disposition .= qq|\nContent-Disposition: attachment; filename="$name"|;

Modified: branches/1.3/UI/Contact/pricelist.html
===================================================================
--- branches/1.3/UI/Contact/pricelist.html	2012-03-28 12:09:13 UTC (rev 4621)
+++ branches/1.3/UI/Contact/pricelist.html	2012-03-28 13:19:10 UTC (rev 4622)
@@ -83,6 +83,9 @@
 } ?> <a href="customer.pl?action=pricelist&format=PDF&credit_id=<?lsmb 
              credit_id ?>&entity_id=<?lsmb entity_id 
      ?>">[<?lsmb text('PDF') ?>]</a>
+ <a href="customer.pl?action=pricelist&format=CSV&credit_id=<?lsmb 
+             credit_id ?>&entity_id=<?lsmb entity_id 
+     ?>">[<?lsmb text('CSV') ?>]</a>
 <?lsmb IF pricematrix_pricegroup;
      PROCESS dynatable
          tbody = { rows = pricematrix_pricegroup };

Added: branches/1.3/UI/lib/dynatable.csv
===================================================================
--- branches/1.3/UI/lib/dynatable.csv	                        (rev 0)
+++ branches/1.3/UI/lib/dynatable.csv	2012-03-28 13:19:10 UTC (rev 4622)
@@ -0,0 +1,39 @@
+<?lsmb- BLOCK escape;
+
+IF VALUE.match('\D'); # any non-digit means run escaping
+   '"' _ VALUE.replace('"', '""') _ '"';
+ELSE;
+   VALUE;
+END;
+
+END -?>
+<?lsmb- BLOCK dynatable;
+SKIP_TYPES = ['hidden', 'radio', 'checkbox'];
+
+FOREACH COL IN columns;
+    IF 0 == SKIP_TYPES.grep(COL.type).size();
+        IF ADD_COMMA;
+           ',';
+        END;
+        INCLUDE escape VALUE = COL.name;
+        ADD_COMMA = 1;
+    END;
+END;
+?>
+<?lsmb FOREACH ROW IN tbody.rows;
+
+ADD_COMMA=0;
+
+    FOREACH COL IN columns;
+        COL_ID = COL.col_id;
+        IF 0 == SKIP_TYPES.grep(COL.type).size();
+            IF ADD_COMMA;
+               ',';
+            END;
+            ADD_COMMA = 1;
+            ROW.$COL_ID;
+        END;
+    END; 
+
+END ?>
+<?lsmb END ?>

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