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

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



Revision: 2190
          http://ledger-smb.svn.sourceforge.net/ledger-smb/?rev=2190&view=rev
Author:   einhverfr
Date:     2008-07-07 10:37:20 -0700 (Mon, 07 Jul 2008)

Log Message:
-----------
Correcting all check printing issues on my secondary testing instance

Modified Paths:
--------------
    trunk/LedgerSMB/DBObject/Company.pm
    trunk/LedgerSMB/DBObject/Payment.pm
    trunk/LedgerSMB/DBObject.pm
    trunk/LedgerSMB/Template/LaTeX.pm
    trunk/LedgerSMB/Template.pm
    trunk/LedgerSMB.pm
    trunk/UI/payments/payments_detail.html
    trunk/scripts/payment.pl
    trunk/sql/modules/Company.sql
    trunk/templates/demo/check.tex

Added Paths:
-----------
    trunk/templates/Default-check_base.tex
    trunk/templates/Default-check_multiple.tex
    trunk/templates/demo/check_base.tex
    trunk/templates/demo/check_multiple.tex

Modified: trunk/LedgerSMB/DBObject/Company.pm
===================================================================
--- trunk/LedgerSMB/DBObject/Company.pm	2008-07-07 02:49:32 UTC (rev 2189)
+++ trunk/LedgerSMB/DBObject/Company.pm	2008-07-07 17:37:20 UTC (rev 2190)
@@ -183,6 +183,13 @@
     return @{$self->{search_results}};
 }
 
+sub get_billing_info {
+    my $self = shift @_;
+    $self->set_entity_class();
+    my ($ref) = $self->exec_method(funcname => 'company_get_billing_info');
+    $self->merge($ref);
+}
+
 sub get {
     my $self = shift @_;
 

Modified: trunk/LedgerSMB/DBObject/Payment.pm
===================================================================
--- trunk/LedgerSMB/DBObject/Payment.pm	2008-07-07 02:49:32 UTC (rev 2189)
+++ trunk/LedgerSMB/DBObject/Payment.pm	2008-07-07 17:37:20 UTC (rev 2190)
@@ -61,6 +61,15 @@
   ($self->{current_date}) = $self->{dbh}->selectrow_array('select current_date');
 }
 
+sub text_amount {
+    use LedgerSMB::Num2text;
+    print STDERR "num2text\n";
+    my ($self, $value) = @_;
+    $self->{locale} = $self->{_locale};
+    $self->init();
+    return $self->num2text($value);
+}
+
 sub get_metadata {
     my ($self) = @_;
     $self->list_open_projects();

Modified: trunk/LedgerSMB/DBObject.pm
===================================================================
--- trunk/LedgerSMB/DBObject.pm	2008-07-07 02:49:32 UTC (rev 2189)
+++ trunk/LedgerSMB/DBObject.pm	2008-07-07 17:37:20 UTC (rev 2190)
@@ -73,10 +73,10 @@
 
     my $attr;
     if (lc($mode) eq 'base'){
-        $self->merge($base, 'dbh', '_roles');
+        $self->merge($base, keys => ['dbh', '_roles', '_user', '_locale']);
     }
     elsif (lc($mode) eq 'list'){
-        $self->merge($base, @mergelist);
+        $self->merge($base, keys => ..hidden..);
     }
     else {
         $self->merge($base);

Modified: trunk/LedgerSMB/Template/LaTeX.pm
===================================================================
--- trunk/LedgerSMB/Template/LaTeX.pm	2008-07-07 02:49:32 UTC (rev 2189)
+++ trunk/LedgerSMB/Template/LaTeX.pm	2008-07-07 17:37:20 UTC (rev 2190)
@@ -70,7 +70,7 @@
 		for (@{$rawvars}) {
 			push @{$vars}, preprocess($_);
 		}
-	} elsif (!$type or $type eq 'SCALAR') {
+	} elsif (!$type or $type eq 'SCALAR' or $type eq 'Math::BigInt::GMP') {
 		if ($type eq 'SCALAR' or $type eq 'Math::BigInt::GMP') {
 			$vars = $$rawvars;
 		} else {
@@ -120,7 +120,6 @@
 		DEBUG => ($parent->{debug})? 'dirs': undef,
 		DEBUG_FORMAT => '',
 		}) || throw Error::Simple Template::Latex->error(); 
-
 	if (not $template->process(
 		$source, 
 		{%$cleanvars, %$LedgerSMB::Template::TTI18N::ttfuncs,

Modified: trunk/LedgerSMB/Template.pm
===================================================================
--- trunk/LedgerSMB/Template.pm	2008-07-07 02:49:32 UTC (rev 2189)
+++ trunk/LedgerSMB/Template.pm	2008-07-07 17:37:20 UTC (rev 2190)
@@ -181,6 +181,7 @@
 					.";$self->{'include_path'}"
 		}
 	}
+        print STDERR "include path: $self->{'include_path'} \n";
 
 	return $self;
 }
@@ -293,12 +294,20 @@
 }
 
 sub _http_output {
-	my $self = shift;
-	my $data = shift;
+	my ($self, $data) = @_;
 	$data ||= $self->{output};
 	if ($self->{format} !~ /^\p{IsAlnum}+$/) {
 		throw Error::Simple "Invalid format";
 	}
+
+	if (!defined $data and defined $self->{rendered}){
+		$data = "";
+		open (DATA, '<', $self->{rendered});
+		while (my $line = <DATA>){
+			$data .= $line;
+		}
+	}
+
 	my $format = "LedgerSMB::Template::$self->{format}";
 	my $disposition = "";
 	my $name = $format->can('postprocess')->($self);

Modified: trunk/LedgerSMB.pm
===================================================================
--- trunk/LedgerSMB.pm	2008-07-07 02:49:32 UTC (rev 2189)
+++ trunk/LedgerSMB.pm	2008-07-07 17:37:20 UTC (rev 2190)
@@ -375,6 +375,7 @@
     my $amount   = $args{amount};
     my $places   = $args{precision};
     my $dash     = $args{neg_format};
+    print STDERR "Formatting $amount in format $myconfig->{numberformat}\n";
 
     my $negative;
     if ($amount) {
@@ -767,6 +768,7 @@
     if (defined $args{keys}){
          @keys  = @{ $args{keys} };
     }
+    print STDERR 'Merging ' . scalar @keys . " keys\n";
     my $index = $args{index};
     if ( !scalar @keys ) {
         @keys = keys %{$src};

Modified: trunk/UI/payments/payments_detail.html
===================================================================
--- trunk/UI/payments/payments_detail.html	2008-07-07 02:49:32 UTC (rev 2189)
+++ trunk/UI/payments/payments_detail.html	2008-07-07 17:37:20 UTC (rev 2190)
@@ -231,7 +231,17 @@
 		<?lsmb icount = icount + 1 ?>
 		<tr>
 			<td class="invoice_date_list">&nbsp;<?lsmb i.2 ?></td>
+			<?lsmb PROCESS input element_data = {
+				name = "invdate_$i.0"
+				type = "hidden"
+				value = i.2
+			} ?>
 			<td class="invoice_list">&nbsp;<?lsmb i.1 ?></td>
+			<?lsmb PROCESS input element_data = {
+				name = "invnumber_$i.0"
+				type = "hidden"
+				value = i.1
+			} ?>
 		        <td class="total_due_list">&nbsp;
 				<?lsmb INCLUDE format_money number=i.3 ?></td>
 			<td class="paid_list">&nbsp;
@@ -279,6 +289,11 @@
 	name = "contact_count"
 	value = count
     } ?>
+    <?lsmb PROCESS input element_data = {
+		name = "multiple"
+		type = "hidden"
+		value = '1'
+    } ?>
     <?lsmb INCLUDE button element_data = {
 	text = text((batch_id) ? 'Save' : 'Post'),
 	value = 'post_payments_bulk'

Modified: trunk/scripts/payment.pl
===================================================================
--- trunk/scripts/payment.pl	2008-07-07 02:49:32 UTC (rev 2189)
+++ trunk/scripts/payment.pl	2008-07-07 17:37:20 UTC (rev 2190)
@@ -50,6 +50,7 @@
 use LedgerSMB::Template;
 use LedgerSMB::DBObject::Payment;
 use LedgerSMB::DBObject::Date;
+use Error::Simple;
 use strict; 
 
 # CT:  A few notes for future refactoring of this code:
@@ -72,7 +73,6 @@
     my ($request) = @_;
     my $payment =  LedgerSMB::DBObject::Payment->new({'base' => $request});
     $payment->get_metadata();
-	$payment->debug({file => '/tmp/delme'});
     my $template = LedgerSMB::Template->new(
         user     => $request->{_user},
         locale   => $request->{_locale},
@@ -83,6 +83,9 @@
     $template->render($payment);
 }
 
+sub print {
+}
+
 sub get_search_criteria {
     my ($request) = @_;
     my $payment =  LedgerSMB::DBObject::Payment->new({'base' => $request});
@@ -253,11 +256,82 @@
     $template->render($payment);
 }
 
+sub print {
+    use LedgerSMB::DBObject::Company;
+    my ($request) = @_;
+    my $payment =  LedgerSMB::DBObject::Payment->new({'base' => $request});
+    $payment->{company} = $payment->{_user}->{company};
+    $payment->{address} = $payment->{_user}->{address};
+
+    my $template;
+
+    if ($payment->{multiple}){
+        $payment->{checks} = [];
+        print "Multiple checks printing";
+        for my $line (1 .. $payment->{contact_count}){
+            my $id = $payment->{"contact_$line"};
+            next if !defined $payment->{"id_$id"};
+            my $check = LedgerSMB::DBObject::Company->new(
+                                {base => $request, copy => 'base' }
+            );
+            $check->{entity_class} = $payment->{account_class};
+            $check->{id} = $id;
+            $check->get_billing_info;
+            $check->{amount} = $check->parse_amount(amount => '0');
+            $check->{invoices} = [];
+            $check->{source} = $payment->{"source_$id"};
+            for my $inv (1 .. $payment->{"invoice_count_$id"}){
+		print STDERR "Invoice $inv of " .$payment->{"invoice_count_$id"} . "\n";
+                my $invhash = {};
+                my $inv_id = $payment->{"invoice_${id}_$inv"};
+                for (qw(invnumber invdate)){
+                    $invhash->{$_} = $payment->{"${_}_$inv_id"};
+                }
+                if ($payment->{"paid_$id"} eq 'some'){
+                    $invhash->{paid} = $payment->parse_amount(amount => $payment->{"payment_$inv_id"});
+                } elsif ($payment->{"paid_$id"} eq 'all'){
+                    $invhash->{paid} = $payment->parse_amount(amount => $payment->{"net_$inv_id"});
+                } else {
+                    $payment->error("Invalid Payment Amount Option"); 
+                }
+                $check->{amount} += $invhash->{paid};
+                $invhash->{paid} = $check->format_amount(amount => $invhash->{paid});
+                push @{$check->{invoices}}, $invhash;
+            }
+            my $amt = $check->{amount}->copy;
+            $amt->bfloor();
+            $check->{text_amount} = $payment->text_amount($amt);
+            $check->{amount} = $check->format_amount(amount => $check->{amount});
+            $check->{decimal} = $check->format_amount(amount => ($check->{amount} - $amt) * 100);
+            print STDERR "amount = $check->{amount}, texamount = $check->{textamount}\n";
+            push @{$payment->{checks}}, $check;
+        }
+        $payment->debug({file => '/tmp/payment'});
+        $template = LedgerSMB::Template->new(
+            user => $payment->{_user}, template => 'check_multiple', 
+            format => uc $payment->{'format'},
+	    no_auto_output => 1,
+            output_args => $payment,
+        );
+        try {
+            $template->render($payment);
+            $template->output(%$payment);
+        }
+        catch Error::Simple with {
+            my $E = shift;
+            $payment->error( $E->stacktrace );
+        };
+
+    } else {
+
+    }
+
+}
+
 sub display_payments {
     my ($request) = @_;
     my $payment =  LedgerSMB::DBObject::Payment->new({'base' => $request});
     $payment->get_payment_detail_data();
-	$payment->debug({file => '/tmp/delme'});
     for (@{$payment->{contact_invoices}}){
         $_->{total_due} = $payment->format_amount(amount =>  $_->{total_due});
     }

Modified: trunk/sql/modules/Company.sql
===================================================================
--- trunk/sql/modules/Company.sql	2008-07-07 02:49:32 UTC (rev 2189)
+++ trunk/sql/modules/Company.sql	2008-07-07 17:37:20 UTC (rev 2190)
@@ -229,6 +229,39 @@
 END;
 $$ language plpgsql;
 
+CREATE TYPE company_billing_info AS (
+legal_name text,
+tax_id text,
+street1 text,
+street2 text,
+street3 text,
+city text,
+state text,
+mail_code text,
+country text
+);
+
+CREATE OR REPLACE FUNCTION company_get_billing_info (in_id int) 
+returns company_billing_info as
+$$
+DECLARE out_var company_billing_info;
+	t_id INT;
+BEGIN
+	select c.legal_name, c.tax_id, a.line_one, a.line_two, a.line_three, 
+		a.city, a.state, a.mail_code, cc.name
+	into out_var
+	FROM company c
+	JOIN company_to_location cl ON (c.id = cl.company_id)
+	JOIN location a ON (a.id = cl.location_id)
+	JOIN country cc ON (cc.id = a.country_id)
+	WHERE c.entity_id = (select entity_id 
+			from entity_credit_account where id = in_id)
+		AND a.id = (SELECT min(location_id) from company_to_location
+			where company_id = c.id and location_class = 1);
+	RETURN out_var;
+END;
+$$ language plpgsql;
+
 CREATE OR REPLACE FUNCTION company_save (
     in_id int, in_entity_class int,
     in_name text, in_tax_id TEXT,

Added: trunk/templates/Default-check_base.tex
===================================================================
--- trunk/templates/Default-check_base.tex	                        (rev 0)
+++ trunk/templates/Default-check_base.tex	2008-07-07 17:37:20 UTC (rev 2190)
@@ -0,0 +1,64 @@
+<?lsmb BLOCK check_single ?>
+\parbox[t]{12cm}{
+  <?lsmb company ?>
+
+  <?lsmb address ?>}
+\hfill
+\parbox[t]{6cm}{\hfill <?lsmb source ?>}
+
+\vspace*{0.6cm}
+
+<?lsmb text_amount ?> \dotfill <?lsmb decimal ?>/100 \makebox[0.5cm]{\hfill}
+
+\vspace{0.5cm}
+
+\hfill <?lsmb datepaid ?> \makebox[2cm]{\hfill} <?lsmb amount ?>
+
+% different date format for datepaid
+% <?lsmb DD ?><?lsmb MM ?><?lsmb YYYY ?>
+
+\vspace{0.5cm}
+
+<?lsmb name ?>
+
+<?lsmb address1 ?>
+
+<?lsmb address2 ?>
+
+<?lsmb city ?>
+<?lsmb if state ?>
+\hspace{-0.1cm}, <?lsmb state ?>
+<?lsmb end state ?>
+<?lsmb zipcode ?>
+
+<?lsmb country ?>
+
+\vspace{1.8cm}
+
+<?lsmb memo ?>
+
+\vspace{0.8cm}
+
+<?lsmb company ?>
+
+\vspace{0.5cm}
+
+<?lsmb name ?> \hfill <?lsmb datepaid ?> \hfill <?lsmb source ?>
+
+\vspace{0.5cm}
..hidden..
+\textbf{Invoice \#} & \textbf{Invoice Date}
+  & \textbf{Amount Due} & \textbf{Applied} \\
+<?lsmb FOR inv = invoices ?>
+<?lsmb inv.invnumber ?> & <?lsmb inv.invdate ?> \dotfill
+  & <?lsmb inv.due ?> & <?lsmb inv.paid ?> \\
+<?lsmb end # FOREACH inv ?>
+\end{tabularx}
+
+\vspace{1cm}
+
+<?lsmb memo ?>
+
+\vfill
+<?lsmb message ?>
+<?lsmb END # BLOCK ?>

Added: trunk/templates/Default-check_multiple.tex
===================================================================
--- trunk/templates/Default-check_multiple.tex	                        (rev 0)
+++ trunk/templates/Default-check_multiple.tex	2008-07-07 17:37:20 UTC (rev 2190)
@@ -0,0 +1,31 @@
+\documentclass{scrartcl}
+\usepackage[latin1]{inputenc}
+\usepackage{tabularx}
+\usepackage[letterpaper,top=2cm,bottom=1.5cm,left=1.1cm,right=1.5cm]{geometry}
+\usepackage{graphicx}
+
+<?lsmb INCLUDE check_base.tex ?>
+
+\begin{document}
+
+\pagestyle{myheadings}
+\thispagestyle{empty}
+
+\fontfamily{cmss}\fontsize{9pt}{9pt}\selectfont
+<?lsmb FOR check = checks_data ?>
+<?lsmb INCLUDE check_single 
+	source = check.source
+	text_amount = check.text_amount
+	amount = check.amount
+	name = check.name
+	address1 = check.address1
+	address2 = check.address2
+	city = check.city
+	state = check.state
+	zipcode = check.zipcode
+	memo = check.memo
+	invoices = check.invoices
+?>
+\endpage
+<?lsmb END # FOR check ?>
+\end{document}

Modified: trunk/templates/demo/check.tex
===================================================================
--- trunk/templates/demo/check.tex	2008-07-07 02:49:32 UTC (rev 2189)
+++ trunk/templates/demo/check.tex	2008-07-07 17:37:20 UTC (rev 2190)
@@ -1,10 +1,12 @@
-<?lsmb FILTER latex -?>
+<?lsmb FILTER latex ?>
 \documentclass{scrartcl}
-\usepackage[utf8]{inputenc}
+\usepackage[latin1]{inputenc}
 \usepackage{tabularx}
 \usepackage[letterpaper,top=2cm,bottom=1.5cm,left=1.1cm,right=1.5cm]{geometry}
 \usepackage{graphicx}
 
+<?lsmb REQUIRE check_base.tex ?>
+
 \begin{document}
 
 \pagestyle{myheadings}
@@ -12,68 +14,7 @@
 
 \fontfamily{cmss}\fontsize{9pt}{9pt}\selectfont
 
-\parbox[t]{12cm}{
-  <?lsmb company ?>
+<?lsmb PROCESS check_single ?>
 
-  <?lsmb address ?>}
-\hfill
-\parbox[t]{6cm}{\hfill <?lsmb source ?>}
-
-\vspace*{0.6cm}
-
-<?lsmb text_amount ?> \dotfill <?lsmb decimal ?>/100 \makebox[0.5cm]{\hfill}
-
-\vspace{0.5cm}
-
-\hfill <?lsmb datepaid ?> \makebox[2cm]{\hfill} <?lsmb amount ?>
-
-% different date format for datepaid
-% <?lsmb DD ?><?lsmb MM ?><?lsmb YYYY ?>
-
-\vspace{0.5cm}
-
-<?lsmb name ?>
-
-<?lsmb address1 ?>
-
-<?lsmb address2 ?>
-
-<?lsmb city ?>
-<?lsmb IF state ?>
-\hspace{-0.1cm}, <?lsmb state ?>
-<?lsmb END ?>
-<?lsmb zipcode ?>
-
-<?lsmb country ?>
-
-\vspace{1.8cm}
-
-<?lsmb memo ?>
-
-\vspace{0.8cm}
-
-<?lsmb company ?>
-
-\vspace{0.5cm}
-
-<?lsmb name ?> \hfill <?lsmb datepaid ?> \hfill <?lsmb source ?>
-
-\vspace{0.5cm}
..hidden..
-\textbf{Invoice \#} & \textbf{Invoice Date}
-  & \textbf{Amount Due} & \textbf{Applied} \\
-<?lsmb FOREACH invnumber ?>
-<?lsmb lc = loop.count - 1 ?>
-<?lsmb invnumber.${lc} ?> & <?lsmb invdate.${lc} ?> \dotfill
-  & <?lsmb due.${lc} ?> & <?lsmb paid.${lc} ?> \\
-<?lsmb END ?>
-\end{tabularx}
-
-\vspace{1cm}
-
-<?lsmb memo ?>
-
-\vfill
-
 \end{document}
-<?lsmb END ?>
+<?lsmb END # FILTER latex ?>

Added: trunk/templates/demo/check_base.tex
===================================================================
--- trunk/templates/demo/check_base.tex	                        (rev 0)
+++ trunk/templates/demo/check_base.tex	2008-07-07 17:37:20 UTC (rev 2190)
@@ -0,0 +1,65 @@
+<?lsmb BLOCK check_single ?>
+\parbox[t]{12cm}{
+  <?lsmb company ?>
+
+  <?lsmb address ?>}
+\hfill
+\parbox[t]{6cm}{\hfill <?lsmb source ?>}
+
+\vspace*{0.6cm}
+
+<?lsmb text_amount ?> \dotfill <?lsmb decimal ?>/100 \makebox[0.5cm]{\hfill}
+
+\vspace{0.5cm}
+
+\hfill <?lsmb datepaid ?> \makebox[2cm]{\hfill} <?lsmb amount ?>
+
+% different date format for datepaid
+% <?lsmb DD ?><?lsmb MM ?><?lsmb YYYY ?>
+
+\vspace{0.5cm}
+
+<?lsmb legal_name ?>
+
+<?lsmb street1 ?>
+
+<?lsmb street2 ?>
+
+<?lsmb city ?>
+<?lsmb IF state ?>
+\hspace{-0.1cm}, <?lsmb state ?>
+<?lsmb END # state ?>
+
+<?lsmb mail_code ?>
+
+<?lsmb country ?>
+
+\vspace{1.8cm}
+
+<?lsmb memo ?>
+
+\vspace{0.8cm}
+
+<?lsmb company ?>
+
+\vspace{0.5cm}
+
+<?lsmb name ?> \hfill <?lsmb datepaid ?> \hfill <?lsmb source ?>
+
+\vspace{0.5cm}
..hidden..
+\textbf{Invoice \#} & \textbf{Invoice Date}
+  & \textbf{Amount Due} & \textbf{Applied} \\
+<?lsmb FOR inv = invoices ?>
+<?lsmb inv.invnumber ?> & <?lsmb inv.invdate ?> \dotfill
+  & <?lsmb inv.due ?> & <?lsmb inv.paid ?> \\
+<?lsmb END # FOREACH inv ?>
+\end{tabularx}
+
+\vspace{1cm}
+
+<?lsmb memo ?>
+
+\vfill
+<?lsmb message ?>
+<?lsmb END # BLOCK ?>

Added: trunk/templates/demo/check_multiple.tex
===================================================================
--- trunk/templates/demo/check_multiple.tex	                        (rev 0)
+++ trunk/templates/demo/check_multiple.tex	2008-07-07 17:37:20 UTC (rev 2190)
@@ -0,0 +1,34 @@
+<?lsmb FILTER latex ?>
+\documentclass{scrartcl}
+\usepackage[latin1]{inputenc}
+\usepackage{tabularx}
+\usepackage[letterpaper,top=2cm,bottom=1.5cm,left=1.1cm,right=1.5cm]{geometry}
+\usepackage{graphicx}
+
+<?lsmb PROCESS check_base.tex ?>
+
+\begin{document}
+
+\pagestyle{myheadings}
+\thispagestyle{empty}
+
+\fontfamily{cmss}\fontsize{9pt}{9pt}\selectfont
+<?lsmb FOR check = checks ?>
+<?lsmb INCLUDE check_single 
+	source = check.source
+	text_amount = check.text_amount
+	decimal = check.decimal
+	amount = check.amount
+	legal_name = check.legal_name
+	street1 = check.street1 
+	street2 = check.street2 
+	city = check.city
+	state = check.state
+	mail_code = check.mail_code
+	memo = check.memo
+	invoices = check.invoices
+?>
+\clearpage
+<?lsmb END # FOR check ?>
+\end{document}
+<?lsmb END # FILTER latex ?>


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