From 484f4f00ff319bf97c5ca911313738aa05a63a2c Mon Sep 17 00:00:00 2001 From: einhverfr Date: Mon, 7 Jul 2008 17:37:20 +0000 Subject: Correcting all check printing issues on my secondary testing instance git-svn-id: https://ledger-smb.svn.sourceforge.net/svnroot/ledger-smb/trunk@2190 4979c152-3d1c-0410-bac9-87ea11338e46 --- LedgerSMB.pm | 2 + LedgerSMB/DBObject.pm | 4 +- LedgerSMB/DBObject/Company.pm | 7 ++++ LedgerSMB/DBObject/Payment.pm | 9 +++++ LedgerSMB/Template.pm | 13 +++++- LedgerSMB/Template/LaTeX.pm | 3 +- UI/payments/payments_detail.html | 15 +++++++ scripts/payment.pl | 78 +++++++++++++++++++++++++++++++++++- sql/modules/Company.sql | 33 +++++++++++++++ templates/Default-check_base.tex | 64 +++++++++++++++++++++++++++++ templates/Default-check_multiple.tex | 31 ++++++++++++++ templates/demo/check.tex | 71 +++----------------------------- templates/demo/check_base.tex | 65 ++++++++++++++++++++++++++++++ templates/demo/check_multiple.tex | 34 ++++++++++++++++ 14 files changed, 356 insertions(+), 73 deletions(-) create mode 100644 templates/Default-check_base.tex create mode 100644 templates/Default-check_multiple.tex create mode 100644 templates/demo/check_base.tex create mode 100644 templates/demo/check_multiple.tex diff --git a/LedgerSMB.pm b/LedgerSMB.pm index 3fe186b9..4ba0b0cf 100755 --- a/LedgerSMB.pm +++ b/LedgerSMB.pm @@ -375,6 +375,7 @@ sub format_amount { 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 @@ sub merge { if (defined $args{keys}){ @keys = @{ $args{keys} }; } + print STDERR 'Merging ' . scalar @keys . " keys\n"; my $index = $args{index}; if ( !scalar @keys ) { @keys = keys %{$src}; diff --git a/LedgerSMB/DBObject.pm b/LedgerSMB/DBObject.pm index 07b2b0a6..d2ce0fbb 100644 --- a/LedgerSMB/DBObject.pm +++ b/LedgerSMB/DBObject.pm @@ -73,10 +73,10 @@ sub new { 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 => \@mergelist); } else { $self->merge($base); diff --git a/LedgerSMB/DBObject/Company.pm b/LedgerSMB/DBObject/Company.pm index 1e4ca4d5..23a56cec 100644 --- a/LedgerSMB/DBObject/Company.pm +++ b/LedgerSMB/DBObject/Company.pm @@ -183,6 +183,13 @@ sub search { 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 @_; diff --git a/LedgerSMB/DBObject/Payment.pm b/LedgerSMB/DBObject/Payment.pm index 6cc23f2e..50e7829f 100644 --- a/LedgerSMB/DBObject/Payment.pm +++ b/LedgerSMB/DBObject/Payment.pm @@ -61,6 +61,15 @@ sub __validate__ { ($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(); diff --git a/LedgerSMB/Template.pm b/LedgerSMB/Template.pm index e87251fd..2d1fd130 100755 --- a/LedgerSMB/Template.pm +++ b/LedgerSMB/Template.pm @@ -181,6 +181,7 @@ sub new { .";$self->{'include_path'}" } } + print STDERR "include path: $self->{'include_path'} \n"; return $self; } @@ -293,12 +294,20 @@ sub output { } 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 .= $line; + } + } + my $format = "LedgerSMB::Template::$self->{format}"; my $disposition = ""; my $name = $format->can('postprocess')->($self); diff --git a/LedgerSMB/Template/LaTeX.pm b/LedgerSMB/Template/LaTeX.pm index 71ddfce8..00f283fa 100755 --- a/LedgerSMB/Template/LaTeX.pm +++ b/LedgerSMB/Template/LaTeX.pm @@ -70,7 +70,7 @@ sub preprocess { 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 @@ sub process { DEBUG => ($parent->{debug})? 'dirs': undef, DEBUG_FORMAT => '', }) || throw Error::Simple Template::Latex->error(); - if (not $template->process( $source, {%$cleanvars, %$LedgerSMB::Template::TTI18N::ttfuncs, diff --git a/UI/payments/payments_detail.html b/UI/payments/payments_detail.html index 1b142aa2..f1b4c04a 100644 --- a/UI/payments/payments_detail.html +++ b/UI/payments/payments_detail.html @@ -231,7 +231,17 @@   +   +     @@ -279,6 +289,11 @@ name = "contact_count" value = count } ?> + 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 @@ sub payments { $template->render($payment); } +sub print { +} + sub get_search_criteria { my ($request) = @_; my $payment = LedgerSMB::DBObject::Payment->new({'base' => $request}); @@ -253,11 +256,82 @@ sub post_payments_bulk { $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}); } diff --git a/sql/modules/Company.sql b/sql/modules/Company.sql index d653d9f7..45fd89dd 100644 --- a/sql/modules/Company.sql +++ b/sql/modules/Company.sql @@ -229,6 +229,39 @@ BEGIN 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, diff --git a/templates/Default-check_base.tex b/templates/Default-check_base.tex new file mode 100644 index 00000000..8aba93a0 --- /dev/null +++ b/templates/Default-check_base.tex @@ -0,0 +1,64 @@ + +\parbox[t]{12cm}{ + + + } +\hfill +\parbox[t]{6cm}{\hfill } + +\vspace*{0.6cm} + + \dotfill /100 \makebox[0.5cm]{\hfill} + +\vspace{0.5cm} + +\hfill \makebox[2cm]{\hfill} + +% different date format for datepaid +% + +\vspace{0.5cm} + + + + + + + + + +\hspace{-0.1cm}, + + + + + +\vspace{1.8cm} + + + +\vspace{0.8cm} + + + +\vspace{0.5cm} + + \hfill \hfill + +\vspace{0.5cm} +\begin{tabularx}{\textwidth}{lXrr@{}} +\textbf{Invoice \#} & \textbf{Invoice Date} + & \textbf{Amount Due} & \textbf{Applied} \\ + + & \dotfill + & & \\ + +\end{tabularx} + +\vspace{1cm} + + + +\vfill + + diff --git a/templates/Default-check_multiple.tex b/templates/Default-check_multiple.tex new file mode 100644 index 00000000..48fad192 --- /dev/null +++ b/templates/Default-check_multiple.tex @@ -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} + + + +\begin{document} + +\pagestyle{myheadings} +\thispagestyle{empty} + +\fontfamily{cmss}\fontsize{9pt}{9pt}\selectfont + + +\endpage + +\end{document} diff --git a/templates/demo/check.tex b/templates/demo/check.tex index 34da77c1..33bcb515 100644 --- a/templates/demo/check.tex +++ b/templates/demo/check.tex @@ -1,10 +1,12 @@ - + \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} + + \begin{document} \pagestyle{myheadings} @@ -12,68 +14,7 @@ \fontfamily{cmss}\fontsize{9pt}{9pt}\selectfont -\parbox[t]{12cm}{ - - - } -\hfill -\parbox[t]{6cm}{\hfill } - -\vspace*{0.6cm} - - \dotfill /100 \makebox[0.5cm]{\hfill} - -\vspace{0.5cm} - -\hfill \makebox[2cm]{\hfill} - -% different date format for datepaid -% - -\vspace{0.5cm} - - - - - - - - - -\hspace{-0.1cm}, - - - - - -\vspace{1.8cm} - - - -\vspace{0.8cm} - - - -\vspace{0.5cm} - - \hfill \hfill - -\vspace{0.5cm} -\begin{tabularx}{\textwidth}{lXrr@{}} -\textbf{Invoice \#} & \textbf{Invoice Date} - & \textbf{Amount Due} & \textbf{Applied} \\ - - - & \dotfill - & & \\ - -\end{tabularx} - -\vspace{1cm} - - - -\vfill + \end{document} - + diff --git a/templates/demo/check_base.tex b/templates/demo/check_base.tex new file mode 100644 index 00000000..9493c7ee --- /dev/null +++ b/templates/demo/check_base.tex @@ -0,0 +1,65 @@ + +\parbox[t]{12cm}{ + + + } +\hfill +\parbox[t]{6cm}{\hfill } + +\vspace*{0.6cm} + + \dotfill /100 \makebox[0.5cm]{\hfill} + +\vspace{0.5cm} + +\hfill \makebox[2cm]{\hfill} + +% different date format for datepaid +% + +\vspace{0.5cm} + + + + + + + + + +\hspace{-0.1cm}, + + + + + + +\vspace{1.8cm} + + + +\vspace{0.8cm} + + + +\vspace{0.5cm} + + \hfill \hfill + +\vspace{0.5cm} +\begin{tabularx}{\textwidth}{lXrr@{}} +\textbf{Invoice \#} & \textbf{Invoice Date} + & \textbf{Amount Due} & \textbf{Applied} \\ + + & \dotfill + & & \\ + +\end{tabularx} + +\vspace{1cm} + + + +\vfill + + diff --git a/templates/demo/check_multiple.tex b/templates/demo/check_multiple.tex new file mode 100644 index 00000000..5dced55b --- /dev/null +++ b/templates/demo/check_multiple.tex @@ -0,0 +1,34 @@ + +\documentclass{scrartcl} +\usepackage[latin1]{inputenc} +\usepackage{tabularx} +\usepackage[letterpaper,top=2cm,bottom=1.5cm,left=1.1cm,right=1.5cm]{geometry} +\usepackage{graphicx} + + + +\begin{document} + +\pagestyle{myheadings} +\thispagestyle{empty} + +\fontfamily{cmss}\fontsize{9pt}{9pt}\selectfont + + +\clearpage + +\end{document} + -- cgit v1.2.3