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

SF.net SVN: ledger-smb: [1603] trunk/LedgerSMB/DBObject/Payment.pm



Revision: 1603
          http://ledger-smb.svn.sourceforge.net/ledger-smb/?rev=1603&view=rev
Author:   einhverfr
Date:     2007-09-14 17:06:50 -0700 (Fri, 14 Sep 2007)

Log Message:
-----------
Adding not-yet-documented Payment.pm

Added Paths:
-----------
    trunk/LedgerSMB/DBObject/Payment.pm

Added: trunk/LedgerSMB/DBObject/Payment.pm
===================================================================
--- trunk/LedgerSMB/DBObject/Payment.pm	                        (rev 0)
+++ trunk/LedgerSMB/DBObject/Payment.pm	2007-09-15 00:06:50 UTC (rev 1603)
@@ -0,0 +1,59 @@
+
+=head1:  LedgerSMB::DBObject::Payment:  Stub function for payments.
+=head1:  Copyright (c) 2007.  LedgerSMB Core Team 
+
+=cut
+
+package LedgerSMB::DBObject::Payment;
+use base qw(LedgerSMB::DBObject);
+use strict;
+use Math::BigFloat lib => 'GMP';
+our $VERSION = '0.1.0';
+
+sub get_open_accounts {
+    my ($self) = @_;
+    @{$self->{accounts}} = 
+        $self->exec_method(funcname => 'payment_get_open_accounts');
+    return @{$self->{accounts}};
+}
+
+sub get_all_accounts {
+    my ($self) = @_;
+    @{$self->{accounts}} = 
+        $self->exec_method(funcname => 'payment_get_all_accounts');
+    return @{$self->{accounts}};
+}
+
+sub get_open_invoices {
+    my ($self) = @_;
+    @{$self->{open_invoices}} = 
+        $self->exec_method(funcname => 'payment_get_open_invoices');
+    return @{$self->{open_invoices}};
+}
+
+sub get_all_contact_invoices {
+    my ($self) = @_;
+    @{$self->{contacts}} = 
+        $self->exec_method(funcname => 'payment_get_all_contact_invoices');
+
+    # When arrays of complex types are supported by all versions of Postgres
+    # that this application supports, we should look at doing type conversions
+    # in DBObject so this sort of logic is unncessary. -- CT
+    for my $contact (@{$self->{contacts}}){
+        my @invoices = $self->parse_array($contact->{invoices});
+        my $processed_invoices = [];
+        for my $invoice (@invoices){
+            my $new_invoice = {};
+            for (qw(invoice_id invnumber invoice_date amount discount due)){
+                 $new_invoice->{$_} = shift @$invoice;
+                 if ($_ =~ /^(amount|discount|due)$/){
+                     $new_invoice->{$_} = 
+                          Math::BigFloat->new($new_invoice->{$_});
+                 }
+            }
+            push(@$processed_invoices, $new_invoice);
+        }
+        $contact->{invoice} = $processed_invoices;
+    }
+    return @{$self->{contacts}};
+}


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