summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-rwxr-xr-xLedgerSMB.pm2
-rw-r--r--LedgerSMB/DBObject.pm4
-rw-r--r--LedgerSMB/DBObject/Company.pm7
-rw-r--r--LedgerSMB/DBObject/Payment.pm9
-rwxr-xr-xLedgerSMB/Template.pm13
-rwxr-xr-xLedgerSMB/Template/LaTeX.pm3
-rw-r--r--UI/payments/payments_detail.html15
-rw-r--r--scripts/payment.pl78
-rw-r--r--sql/modules/Company.sql33
-rw-r--r--templates/Default-check_base.tex64
-rw-r--r--templates/Default-check_multiple.tex31
-rw-r--r--templates/demo/check.tex71
-rw-r--r--templates/demo/check_base.tex65
-rw-r--r--templates/demo/check_multiple.tex34
14 files changed, 356 insertions, 73 deletions
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>){
+ $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 @@
<?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'
diff --git a/scripts/payment.pl b/scripts/payment.pl
index a5561cc1..d0896dc9 100644
--- a/scripts/payment.pl
+++ b/scripts/payment.pl
@@ -50,6 +50,7 @@ package LedgerSMB::Scripts::payment;
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 @@ sub payments {
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 @@ 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 @@
+<?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}
+\begin{tabularx}{\textwidth}{lXrr@{}}
+\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 ?>
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}
+
+<?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}
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 @@
-<?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 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}
-\begin{tabularx}{\textwidth}{lXrr@{}}
-\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
+<?lsmb PROCESS check_single ?>
\end{document}
-<?lsmb END ?>
+<?lsmb END # FILTER latex ?>
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 @@
+<?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}
+\begin{tabularx}{\textwidth}{lXrr@{}}
+\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 ?>
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 @@
+<?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 ?>