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

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



Revision: 4805
          http://ledger-smb.svn.sourceforge.net/ledger-smb/?rev=4805&view=rev
Author:   einhverfr
Date:     2012-05-30 02:14:17 +0000 (Wed, 30 May 2012)
Log Message:
-----------
Fixed false positives for orphaned accounts for chart of accounts management

Modified Paths:
--------------
    branches/1.3/LedgerSMB/CA.pm
    branches/1.3/LedgerSMB/Template.pm
    branches/1.3/UI/Contact/pricelist.html
    branches/1.3/bin/am.pl

Added Paths:
-----------
    branches/1.3/LedgerSMB/Template/XML.pm

Modified: branches/1.3/LedgerSMB/CA.pm
===================================================================
--- branches/1.3/LedgerSMB/CA.pm	2012-05-29 11:51:15 UTC (rev 4804)
+++ branches/1.3/LedgerSMB/CA.pm	2012-05-30 02:14:17 UTC (rev 4805)
@@ -46,7 +46,12 @@
     my $approved = ($form->{approved})? 'TRUE' : 'FALSE';
 
     my $query = qq|
-		   SELECT accno, SUM(acc_trans.amount) AS amount
+		   SELECT accno, 
+                          SUM(CASE WHEN ($approved OR acc_trans.approved) AND
+                                        (g.approved OR $approved) 
+                                   THEN acc_trans.amount
+                                   ELSE 0 END) AS amount,
+                          count(acc_trans.*) as rowcount
 		     FROM chart
 		     JOIN acc_trans ON (chart.id = acc_trans.chart_id)
 		     JOIN transactions ON (acc_trans.trans_id = transactions.id)
@@ -57,16 +62,15 @@
                          SELECT id, approved, 'gl' as tablename FROM gl
 		    ) g ON (g.id = acc_trans.trans_id 
 				AND transactions.table_name = g.tablename)
-		    WHERE ($approved OR acc_trans.approved)
-			  AND (g.approved OR $approved)
 		 GROUP BY accno|;
 
     my $sth = $dbh->prepare($query);
     $sth->execute || $form->dberror($query);
-
+    my $rcount;
     while ( my $ref = $sth->fetchrow_hashref(NAME_lc) ) {
         $form->db_parse_numeric(sth=>$sth, hashref=>$ref);
         $amount{ $ref->{accno} } = $ref->{amount};
+        $rcount{ $ref->{accno} } = $ref->{rowcount};
     }
 
     $sth->finish;
@@ -97,6 +101,7 @@
 
     while ( my $ca = $sth->fetchrow_hashref(NAME_lc) ) {
         $ca->{amount}           = $amount{ $ca->{accno} };
+        $ca->{rowcount}           = $rcount { $ca->{accno} };
         $ca->{gifi_description} = $gifi{ $ca->{gifi_accno} };
 
         if ( $ca->{amount} < 0 ) {

Copied: branches/1.3/LedgerSMB/Template/XML.pm (from rev 4727, branches/1.3/LedgerSMB/Template/HTML.pm)
===================================================================
--- branches/1.3/LedgerSMB/Template/XML.pm	                        (rev 0)
+++ branches/1.3/LedgerSMB/Template/XML.pm	2012-05-30 02:14:17 UTC (rev 4805)
@@ -0,0 +1,156 @@
+
+=head1 NAME
+
+LedgerSMB::Template::HTML - Template support module for LedgerSMB
+
+=head1 METHODS
+
+=over
+
+=item get_template ($name)
+
+Returns the appropriate template filename for this format.
+
+=item preprocess ($vars)
+
+This method returns a reference to a hash that contains a copy of the passed
+hashref's data with HTML entities converted to escapes. 
+
+=item process ($parent, $cleanvars)
+
+Processes the template for HTML.
+
+=item postprocess ($parent)
+
+Currently does nothing.
+
+=item escape($string)
+
+Escapes a scalar string and returns the sanitized version.
+
+=back
+
+=head1 Copyright (C) 2007, The LedgerSMB core team.
+
+This work contains copyrighted information from a number of sources all used
+with permission.  
+
+It is released under the GNU General Public License Version 2 or, at your 
+option, any later version.  See COPYRIGHT file for details.  For a full list 
+including contact information of contributors, maintainers, and copyright 
+holders, see the CONTRIBUTORS file.
+=cut
+
+package LedgerSMB::Template::HTML;
+
+use warnings;
+use strict;
+
+use Error qw(:try);
+use Template;
+use LedgerSMB::Template::TTI18N;
+
+my $binmode = ':utf8';
+binmode STDOUT, $binmode;
+binmode STDERR, $binmode;
+
+sub get_template {
+    my $name = shift;
+    my $parent = $shift;
+    return "${name}.$parent->{format_args}{filetype}";
+}
+
+sub preprocess {
+    my $rawvars = shift;
+    my $vars;
+    my $type = ref $rawvars;
+
+    return $rawvars if $type =~ /^LedgerSMB::Locale/;
+    return unless defined $rawvars;
+    if ( $type eq 'ARRAY' ) {
+        for (@{$rawvars}) {
+            push @{$vars}, preprocess( $_ );
+        }
+    } elsif (!$type) {
+        return escape($rawvars);
+    } elsif ($type eq 'SCALAR' or $type eq 'Math::BigInt::GMP') {
+        return escape($$rawvars);
+    } elsif ($type eq 'CODE'){
+        return $rawvars;
+    } elsif ($type eq 'IO::File'){
+        return undef;
+    } else { # Hashes and objects
+        for ( keys %{$rawvars} ) {
+            $vars->{preprocess($_)} = preprocess( $rawvars->{$_} );
+        }
+    }
+     
+    return $vars;
+}
+
+sub escape {
+    my $vars = shift @_;
+    if (defined $vars){
+        $vars =~ s/&/&amp;/gm;
+        $vars =~ s/</&lt;/gm;
+        $vars =~ s/>/&gt;/gm;
+        return $vars;
+    }
+    return undef;
+}
+
+sub process {
+	my $parent = shift;
+	my $cleanvars = shift;
+	my $template;
+	my $output;
+	my $source;
+        $parent->{binmode} = $binmode;
+         	
+	if ($parent->{outputfile}) {
+		$output = "$parent->{outputfile}.$parent->{format_args}{filetype}";
+	} else {
+		$output = \$parent->{output};
+	}
+	if (ref $parent->{template} eq 'SCALAR') {
+		$source = $parent->{template};
+	} elsif (ref $parent->{template} eq 'ARRAY') {
+		$source = join "\n", @{$parent->{template}};
+	} else {
+		$source = get_template($parent->{template}, $parent);
+	}
+        my $tempdir;
+        if ($LedgerSMB::Sysconfig::cache_templates){
+            $tempdir = $LedgerSMB::Sysconfig::cache_template_dir;
+        } else {
+            $tempdir = undef;
+        }
+	$template = Template->new({
+		INCLUDE_PATH => [$parent->{include_path_lang}, $parent->{include_path},'templates/demo','UI/lib'],
+                ENCODING => 'utf8',
+		START_TAG => quotemeta('<?lsmb'),
+		END_TAG => quotemeta('?>'),
+		DELIMITER => ';',
+		TRIM => 1,
+                COMPILE_DIR=> $tempdir,
+		DEBUG => ($parent->{debug})? 'dirs': undef,
+		DEBUG_FORMAT => '',
+		}) || throw Error::Simple Template->error(); 
+	if (not $template->process(
+		$source, 
+		{%$cleanvars, %$LedgerSMB::Template::TTI18N::ttfuncs,
+			'escape' => \&preprocess},
+		$output, {binmode => ':utf8'})) {
+		throw Error::Simple $template->error();
+	}
+	$parent->{mimetype} = 'text/html';
+}
+
+sub postprocess {
+    my $parent = shift;
+    $parent->{rendered} = "$parent->{outputfile}.$parent{format_args}{filetype}" 
+            if $parent->{outputfile};
+    return $parent->{rendered};
+}
+
+1;

Modified: branches/1.3/LedgerSMB/Template.pm
===================================================================
--- branches/1.3/LedgerSMB/Template.pm	2012-05-29 11:51:15 UTC (rev 4804)
+++ branches/1.3/LedgerSMB/Template.pm	2012-05-30 02:14:17 UTC (rev 4805)
@@ -213,7 +213,13 @@
 	} elsif (lc $self->{format} eq 'ps' or lc $self->{format} eq 'postscript') {
 		$self->{format} = 'LaTeX';
 		$self->{format_args}{filetype} = 'ps';
-	}	
+	} elsif (lc $self->{format} eq 'xlsx'){
+                $self->{format} = 'XML';
+                $self->{format_args}{filetype} = 'xlsx';
+        } elsif (lc $self->{format} eq 'XML'){
+                $self->{format} = 'XML';
+                $self->{format_args}{filetype} = 'xml';
+        }
 	bless $self, $class;
 
 	if ($self->{format} !~ /^\p{IsAlnum}+$/) {

Modified: branches/1.3/UI/Contact/pricelist.html
===================================================================
--- branches/1.3/UI/Contact/pricelist.html	2012-05-29 11:51:15 UTC (rev 4804)
+++ branches/1.3/UI/Contact/pricelist.html	2012-05-30 02:14:17 UTC (rev 4805)
@@ -87,12 +87,6 @@
              credit_id ?>&entity_id=<?lsmb entity_id 
      ?>">[<?lsmb text('PDF') ?>]</a>
 <?lsmb END;
-IF FORMATS.grep('XLS').size() 
-?> <a href="customer.pl?action=pricelist&format=XLS&credit_id=<?lsmb 
-             credit_id ?>&entity_id=<?lsmb entity_id 
-     ?>">[<?lsmb text('XLS') ?>]</a>
-<?lsmb END;
-
 IF FORMATS.grep('ODS').size() 
 ?> <a href="customer.pl?action=pricelist&format=ODS&credit_id=<?lsmb 
              credit_id ?>&entity_id=<?lsmb entity_id 

Modified: branches/1.3/bin/am.pl
===================================================================
--- branches/1.3/bin/am.pl	2012-05-29 11:51:15 UTC (rev 4804)
+++ branches/1.3/bin/am.pl	2012-05-30 02:14:17 UTC (rev 4805)
@@ -247,10 +247,7 @@
             $column_data{description} = $ca->{description};
             $column_data{debit}       = $ca->{debit};
             $column_data{credit} = $ca->{credit};
-	    if (($ca->{debit} =~ /\d/ )or ($ca->{credit} =~ /\d/)){
-               # Note, this is just a stub in case we want to put a 
-               # message here --CT
-            } else {
+            if ($ca->{rowcount} == 0){
                 $column_data{delete} ={text => '['.$locale->text('Delete').']',
                                       href => 'am.pl?action=delete_account&'.
                                               'id='.$ca->{id} };

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