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

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



Revision: 2219
          http://ledger-smb.svn.sourceforge.net/ledger-smb/?rev=2219&view=rev
Author:   einhverfr
Date:     2008-07-22 23:27:50 +0000 (Tue, 22 Jul 2008)

Log Message:
-----------
Added format option to LedgerSMB::format_amount
Added batch information options for check template
Added batch default_date field
Corrected issues with payment batches not preserving post dates when adding vouchers to existing batch.

Modified Paths:
--------------
    trunk/LedgerSMB/AA.pm
    trunk/LedgerSMB/Batch.pm
    trunk/LedgerSMB/DBObject/Payment.pm
    trunk/LedgerSMB/Template/LaTeX.pm
    trunk/LedgerSMB.pm
    trunk/scripts/payment.pl
    trunk/sql/Pg-database.sql
    trunk/sql/modules/Voucher.sql
    trunk/templates/demo/check_multiple.tex

Modified: trunk/LedgerSMB/AA.pm
===================================================================
--- trunk/LedgerSMB/AA.pm	2008-07-21 22:57:42 UTC (rev 2218)
+++ trunk/LedgerSMB/AA.pm	2008-07-22 23:27:50 UTC (rev 2219)
@@ -373,9 +373,9 @@
             $form->dberror($query);
         if (!$form->{approved} && $form->{batch_id}){
            if ($form->{arap} eq 'ar'){
-               $batch_class = 'receivable';
+               $batch_class = 'ar';
            } else {
-               $batch_class = 'payable';
+               $batch_class = 'ap';
            }
            $query = qq| 
 		INSERT INTO voucher (batch_id, trans_id, batch_class)

Modified: trunk/LedgerSMB/Batch.pm
===================================================================
--- trunk/LedgerSMB/Batch.pm	2008-07-21 22:57:42 UTC (rev 2218)
+++ trunk/LedgerSMB/Batch.pm	2008-07-22 23:27:50 UTC (rev 2219)
@@ -71,4 +71,10 @@
     return @{$self->{vouchers}};
 }
 
+sub get {
+    my ($self) = @_;
+    my ($ref) = $self->exec_method(funcname => 'voucher_get_batch');
+    $self->merge($ref);
+}
+
 1;

Modified: trunk/LedgerSMB/DBObject/Payment.pm
===================================================================
--- trunk/LedgerSMB/DBObject/Payment.pm	2008-07-21 22:57:42 UTC (rev 2218)
+++ trunk/LedgerSMB/DBObject/Payment.pm	2008-07-22 23:27:50 UTC (rev 2219)
@@ -89,6 +89,10 @@
     for my $ref(@{$self->{cash_accounts}}){
         $ref->{text} = "$ref->{accno}--$ref->{description}";
     }
+    if ($self->{batch_id} && !defined $self->{batch_date}){
+        my ($ref) = $self->exec_method(funcname => 'voucher_get_batch');
+        $self->{batch_date} = $ref->{default_date};
+    }
 }
 
 sub search {

Modified: trunk/LedgerSMB/Template/LaTeX.pm
===================================================================
--- trunk/LedgerSMB/Template/LaTeX.pm	2008-07-21 22:57:42 UTC (rev 2218)
+++ trunk/LedgerSMB/Template/LaTeX.pm	2008-07-22 23:27:50 UTC (rev 2219)
@@ -70,7 +70,9 @@
 		for (@{$rawvars}) {
 			push @{$vars}, preprocess($_);
 		}
-	} elsif (!$type or $type eq 'SCALAR' or $type eq 'Math::BigInt::GMP') {
+	} elsif (!$type or $type eq 'SCALAR' or $type eq 'Math::BigInt::GMP'
+		or $type eq 'CODE'
+	) {
 		if ($type eq 'SCALAR' or $type eq 'Math::BigInt::GMP') {
 			$vars = $$rawvars;
 		} else {
@@ -82,6 +84,7 @@
 			$vars =~ s/"(.*)"/``$1''/gs;
 		}
 	} else {
+		print STDERR "Type: $type\n";
 		for ( keys %{$rawvars} ) {
 			$vars->{$_} = preprocess($rawvars->{$_});
 		}

Modified: trunk/LedgerSMB.pm
===================================================================
--- trunk/LedgerSMB.pm	2008-07-21 22:57:42 UTC (rev 2218)
+++ trunk/LedgerSMB.pm	2008-07-22 23:27:50 UTC (rev 2219)
@@ -370,12 +370,17 @@
 
     # Based on SQL-Ledger's Form::format_amount
     my $self     = shift @_;
-    my %args     = @_;
+    my %args  = (ref($_[0]) eq 'HASH')? %{$_[0]}: @_;
     my $myconfig = $args{user} || $self->{_user};
     my $amount   = $args{amount};
     my $places   = $args{precision};
     my $dash     = $args{neg_format};
+    my $format   = $args{format};
 
+    if (!defined $format){
+       $format = $myconfig->{numberformat}
+    }
+
     my $negative;
     if ($amount) {
         $amount = $self->parse_amount( 'user' => $myconfig, 'amount' => $amount );
@@ -397,7 +402,7 @@
 
     if ($amount) {
 
-        if ( $myconfig->{numberformat} ) {
+        if ( $format ) {
 
             my ( $whole, $dec ) = split /\./, "$amount";
             $amount = join '', reverse split //, $whole;
@@ -407,35 +412,35 @@
                 $dec = substr( $dec, 0, $places );
             }
 
-            if ( $myconfig->{numberformat} eq '1,000.00' ) {
+            if ( $format eq '1,000.00' ) {
                 $amount =~ s/\d{3,}?/$&,/g;
                 $amount =~ s/,$//;
                 $amount = join '', reverse split //, $amount;
                 $amount .= "\.$dec" if ( $dec ne "" );
             } 
-	    elsif ( $myconfig->{numberformat} eq '1 000.00' ) {
+	    elsif ( $format eq '1 000.00' ) {
                 $amount =~ s/\d{3,}?/$& /g;
                 $amount =~ s/\s$//;
                 $amount = join '', reverse split //, $amount;
                 $amount .= "\.$dec" if ( $dec ne "" );
             } 
-	    elsif ( $myconfig->{numberformat} eq "1'000.00" ) {
+	    elsif ( $format eq "1'000.00" ) {
                 $amount =~ s/\d{3,}?/$&'/g;
                 $amount =~ s/'$//;
                 $amount = join '', reverse split //, $amount;
                 $amount .= "\.$dec" if ( $dec ne "" );
             } 
-	    elsif ( $myconfig->{numberformat} eq '1.000,00' ) {
+	    elsif ( $format eq '1.000,00' ) {
                 $amount =~ s/\d{3,}?/$&./g;
                 $amount =~ s/\.$//;
                 $amount = join '', reverse split //, $amount;
                 $amount .= ",$dec" if ( $dec ne "" );
             } 
-	    elsif ( $myconfig->{numberformat} eq '1000,00' ) {
+	    elsif ( $format eq '1000,00' ) {
                 $amount = "$whole";
                 $amount .= ",$dec" if ( $dec ne "" );
             } 
-	    elsif ( $myconfig->{numberformat} eq '1000.00' ) {
+	    elsif ( $format eq '1000.00' ) {
                 $amount = "$whole";
                 $amount .= ".$dec" if ( $dec ne "" );
             }
@@ -456,7 +461,7 @@
 
         if ( $dash eq "0" && $places ) {
 
-            if ( $myconfig->{numberformat} =~ /0,00$/ ) {
+            if ( $format =~ /0,00$/ ) {
                 $amount = "0" . "," . "0" x $places;
             }
             else {

Modified: trunk/scripts/payment.pl
===================================================================
--- trunk/scripts/payment.pl	2008-07-21 22:57:42 UTC (rev 2218)
+++ trunk/scripts/payment.pl	2008-07-22 23:27:50 UTC (rev 2219)
@@ -256,6 +256,7 @@
 
 sub print {
     use LedgerSMB::DBObject::Company;
+    use LedgerSMB::Batch;
     my ($request) = @_;
     my $payment =  LedgerSMB::DBObject::Payment->new({'base' => $request});
     $payment->{company} = $payment->{_user}->{company};
@@ -263,19 +264,19 @@
 
     my $template;
 
-    # To be committed tonight separately -- CT
-    #
-    #if ($payment->{batch_id}){
-    #    my $batch = LedgerSMB::Batch->new(
-    #                     {base => $payment,
-    #                     copy  => 'base' }
-    #    );
-    #    $batch->{id} = $payment->{batch_id};
-    #    $batch->get;
-    #    $payment->{batch_description} = $batch->{description};
-    #    $payment->{batch_control_code} = $batch->{control_code};
-    #}
+    if ($payment->{batch_id}){
+        my $batch = LedgerSMB::Batch->new(
+                         {base => $payment,
+                         copy  => 'base' }
+        );
+        $batch->{id} = $payment->{batch_id};
+        $batch->get;
+        $payment->{batch_description} = $batch->{description};
+        $payment->{batch_control_code} = $batch->{control_code};
+    }
 
+    $payment->{format_amount} = sub {return $payment->format_amount(@_); };
+
     if ($payment->{multiple}){
         $payment->{checks} = [];
         print "Multiple checks printing";
@@ -323,9 +324,9 @@
             my $amt = $check->{amount}->copy;
             $amt->bfloor();
             $check->{text_amount} = $payment->text_amount($amt);
-            $check->{amount} = $check->format_amount(amount => $check->{amount});
+            $check->{amount} = $check->format_amount(amount => $check->{amount},
+                                                     format => '1000.00');
             $check->{decimal} = $check->format_amount(amount => ($check->{amount} - $amt) * 100);
-            print STDERR "amount = $check->{amount}, texamount = $check->{textamount}\n";
             push @{$payment->{checks}}, $check;
         }
         $template = LedgerSMB::Template->new(

Modified: trunk/sql/Pg-database.sql
===================================================================
--- trunk/sql/Pg-database.sql	2008-07-21 22:57:42 UTC (rev 2218)
+++ trunk/sql/Pg-database.sql	2008-07-22 23:27:50 UTC (rev 2219)
@@ -391,6 +391,7 @@
   batch_class_id integer references batch_class(id) not null,
   control_code text,
   description text,
+  default_date date not null,
   approved_on date default null,
   approved_by int references entity_employee(entity_id),
   created_by int references entity_employee(entity_id),

Modified: trunk/sql/modules/Voucher.sql
===================================================================
--- trunk/sql/modules/Voucher.sql	2008-07-21 22:57:42 UTC (rev 2218)
+++ trunk/sql/modules/Voucher.sql	2008-07-22 23:27:50 UTC (rev 2219)
@@ -310,13 +310,16 @@
 $$ LANGUAGE PLPGSQL;
 
 CREATE OR REPLACE FUNCTION batch_create(
-in_batch_number text, in_description text, in_batch_class text) RETURNS int AS
+in_batch_number text, in_description text, in_batch_class text, 
+in_batch_date date) 
+RETURNS int AS
 $$
 BEGIN
 	INSERT INTO 
-		batch (batch_class_id, description, control_code, created_by)
+		batch (batch_class_id, default_date, description, control_code,
+			created_by)
 	VALUES ((SELECT id FROM batch_class WHERE class = in_batch_class),
-		in_description, in_batch_number, 
+		in_batch_date, in_description, in_batch_number, 
 			(select entity_id FROM users WHERE username = session_user));
 
 	return currval('batch_id_seq');

Modified: trunk/templates/demo/check_multiple.tex
===================================================================
--- trunk/templates/demo/check_multiple.tex	2008-07-21 22:57:42 UTC (rev 2218)
+++ trunk/templates/demo/check_multiple.tex	2008-07-22 23:27:50 UTC (rev 2219)
@@ -4,6 +4,7 @@
 \usepackage{tabularx}
 \usepackage[letterpaper,top=2cm,bottom=1.5cm,left=1.1cm,right=1.5cm]{geometry}
 \usepackage{graphicx}
+\usepackage{textpos}
 
 <?lsmb PROCESS check_base.tex ?>
 


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