From 343c6184f7ac98ae28f4bd457a0b2c17d12530ce Mon Sep 17 00:00:00 2001 From: einhverfr Date: Fri, 21 Nov 2008 18:23:51 +0000 Subject: Committing David Mora's single payment interface enhancements git-svn-id: https://ledger-smb.svn.sourceforge.net/svnroot/ledger-smb/trunk@2410 4979c152-3d1c-0410-bac9-87ea11338e46 --- LedgerSMB/CP.pm | 1 + LedgerSMB/DBObject/Payment.pm | 42 +++++++++++++++++++++++++++++++++++++++++- LedgerSMB/Num2text.pm | 2 +- 3 files changed, 43 insertions(+), 2 deletions(-) (limited to 'LedgerSMB') diff --git a/LedgerSMB/CP.pm b/LedgerSMB/CP.pm index b901354b..2f3d5307 100644 --- a/LedgerSMB/CP.pm +++ b/LedgerSMB/CP.pm @@ -37,6 +37,7 @@ package CP; use LedgerSMB::Sysconfig; + sub new { my ( $type, $countrycode ) = @_; diff --git a/LedgerSMB/DBObject/Payment.pm b/LedgerSMB/DBObject/Payment.pm index b148165e..65526609 100644 --- a/LedgerSMB/DBObject/Payment.pm +++ b/LedgerSMB/DBObject/Payment.pm @@ -19,6 +19,7 @@ included COPYRIGHT and LICENSE files for more information. =cut package LedgerSMB::DBObject::Payment; +use LedgerSMB::Num2text; use base qw(LedgerSMB::DBObject); use strict; use Math::BigFloat lib => 'GMP'; @@ -547,7 +548,46 @@ This method uses payment_post to store a payment (not a bulk payment) on the dat sub post_payment { my ($self) = @_; - $self->exec_method(funcname => 'payment_post'); + # We have to check if it was a fx_payment + $self->{currency} = $self->{curr}; + + + if ("$self->{currency}" ne $self->get_default_currency()) { + # First we have to check for an exchangerate on this date + my $db_exchangerate = $self->get_exchange_rate($self->{curr},$self->{datepaid}); + if (!$db_exchangerate) { + # We have to set the exchangerate + + + $self->call_procedure(procname => 'payments_set_exchangerate', args => ["$self->{account_class}", "$self->{exchangerate}" ,"$self->{curr}", "$self->{datepaid}"]); + + + + } + elsif ($db_exchangerate != $self->{exchangerate} ) + { + # Something went wrong + $self->error("Exchange rate inconsistency with database, please try again") + } + } + my @TMParray = $self->exec_method(funcname => 'payment_post'); $self->{dbh}->commit(); + $self->{payment_id} = $TMParray[0]->{payment_post}; + return $self->{payment_id}; +} + +=item gather_printable_info + +This method retrieves all the payment related info needed to build a +document and print it. IT IS NECESSARY TO ALREADY HAVE payment_id on $self + +=cut + + +sub gather_printable_info { +my ($self) = @_; +@{$self->{header_info}} = $self->exec_method(funcname => 'payment_gather_header_info'); +@{$self->{line_info}} = $self->exec_method(funcname => 'payment_gather_line_info'); } + 1; diff --git a/LedgerSMB/Num2text.pm b/LedgerSMB/Num2text.pm index 57accc3b..aceb4840 100644 --- a/LedgerSMB/Num2text.pm +++ b/LedgerSMB/Num2text.pm @@ -121,7 +121,7 @@ sub num2text { sub num2text_en { my ( $self, $amount ) = @_; - + return $self->{numbername}{0} unless $amount; my @textnumber = (); -- cgit v1.2.3