diff options
-rwxr-xr-x | LedgerSMB.pm | 23 | ||||
-rw-r--r-- | LedgerSMB/AA.pm | 4 | ||||
-rw-r--r-- | LedgerSMB/Batch.pm | 6 | ||||
-rw-r--r-- | LedgerSMB/DBObject/Payment.pm | 4 | ||||
-rwxr-xr-x | LedgerSMB/Template/LaTeX.pm | 5 | ||||
-rw-r--r-- | scripts/payment.pl | 29 | ||||
-rw-r--r-- | sql/Pg-database.sql | 1 | ||||
-rw-r--r-- | sql/modules/Voucher.sql | 9 | ||||
-rw-r--r-- | templates/demo/check_multiple.tex | 1 |
9 files changed, 53 insertions, 29 deletions
diff --git a/LedgerSMB.pm b/LedgerSMB.pm index 67055b4f..9239cd50 100755 --- a/LedgerSMB.pm +++ b/LedgerSMB.pm @@ -370,11 +370,16 @@ sub format_amount { # 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) { @@ -397,7 +402,7 @@ sub format_amount { if ($amount) { - if ( $myconfig->{numberformat} ) { + if ( $format ) { my ( $whole, $dec ) = split /\./, "$amount"; $amount = join '', reverse split //, $whole; @@ -407,35 +412,35 @@ sub format_amount { $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 @@ sub format_amount { if ( $dash eq "0" && $places ) { - if ( $myconfig->{numberformat} =~ /0,00$/ ) { + if ( $format =~ /0,00$/ ) { $amount = "0" . "," . "0" x $places; } else { diff --git a/LedgerSMB/AA.pm b/LedgerSMB/AA.pm index d5d8a1fe..8245fa33 100644 --- a/LedgerSMB/AA.pm +++ b/LedgerSMB/AA.pm @@ -373,9 +373,9 @@ sub post_transaction { $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) diff --git a/LedgerSMB/Batch.pm b/LedgerSMB/Batch.pm index 34d0185c..a4c4ecaf 100644 --- a/LedgerSMB/Batch.pm +++ b/LedgerSMB/Batch.pm @@ -71,4 +71,10 @@ sub list_vouchers { return @{$self->{vouchers}}; } +sub get { + my ($self) = @_; + my ($ref) = $self->exec_method(funcname => 'voucher_get_batch'); + $self->merge($ref); +} + 1; diff --git a/LedgerSMB/DBObject/Payment.pm b/LedgerSMB/DBObject/Payment.pm index 50e7829f..11e5ebfd 100644 --- a/LedgerSMB/DBObject/Payment.pm +++ b/LedgerSMB/DBObject/Payment.pm @@ -89,6 +89,10 @@ sub get_metadata { 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 { diff --git a/LedgerSMB/Template/LaTeX.pm b/LedgerSMB/Template/LaTeX.pm index 00f283fa..593a0a74 100755 --- a/LedgerSMB/Template/LaTeX.pm +++ b/LedgerSMB/Template/LaTeX.pm @@ -70,7 +70,9 @@ sub preprocess { 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 @@ sub preprocess { $vars =~ s/"(.*)"/``$1''/gs; } } else { + print STDERR "Type: $type\n"; for ( keys %{$rawvars} ) { $vars->{$_} = preprocess($rawvars->{$_}); } diff --git a/scripts/payment.pl b/scripts/payment.pl index e9aa8482..905c89c8 100644 --- a/scripts/payment.pl +++ b/scripts/payment.pl @@ -256,6 +256,7 @@ sub post_payments_bulk { 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,18 +264,18 @@ sub print { 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} = []; @@ -323,9 +324,9 @@ sub print { 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( diff --git a/sql/Pg-database.sql b/sql/Pg-database.sql index b0b42f8f..e1d8251e 100644 --- a/sql/Pg-database.sql +++ b/sql/Pg-database.sql @@ -391,6 +391,7 @@ CREATE TABLE batch ( 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), diff --git a/sql/modules/Voucher.sql b/sql/modules/Voucher.sql index f4a30595..6ae6a5e2 100644 --- a/sql/modules/Voucher.sql +++ b/sql/modules/Voucher.sql @@ -310,13 +310,16 @@ END; $$ 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'); diff --git a/templates/demo/check_multiple.tex b/templates/demo/check_multiple.tex index 5dced55b..b3380d47 100644 --- a/templates/demo/check_multiple.tex +++ b/templates/demo/check_multiple.tex @@ -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 ?> |