summaryrefslogtreecommitdiff
path: root/LedgerSMB/DBObject/Payment.pm
blob: 8d29931122ed0544f4774353dc2313b6a13c76b5 (plain)
  1. =head1:  LedgerSMB::DBObject::Payment: Stub function for payments.
  2. =head1: Copyright (c) 2007. LedgerSMB Core Team
  3. =cut
  4. package LedgerSMB::DBObject::Payment;
  5. use base qw(LedgerSMB::DBObject);
  6. use strict;
  7. use Math::BigFloat lib => 'GMP';
  8. our $VERSION = '0.1.0';
  9. sub get_open_accounts {
  10. my ($self) = @_;
  11. @{$self->{accounts}} =
  12. $self->exec_method(funcname => 'payment_get_open_accounts');
  13. return @{$self->{accounts}};
  14. }
  15. sub get_all_accounts {
  16. my ($self) = @_;
  17. @{$self->{accounts}} =
  18. $self->exec_method(funcname => 'payment_get_all_accounts');
  19. return @{$self->{accounts}};
  20. }
  21. sub get_open_invoices {
  22. my ($self) = @_;
  23. @{$self->{open_invoices}} =
  24. $self->exec_method(funcname => 'payment_get_open_invoices');
  25. return @{$self->{open_invoices}};
  26. }
  27. sub get_all_contact_invoices {
  28. my ($self) = @_;
  29. @{$self->{contacts}} =
  30. $self->exec_method(funcname => 'payment_get_all_contact_invoices');
  31. # When arrays of complex types are supported by all versions of Postgres
  32. # that this application supports, we should look at doing type conversions
  33. # in DBObject so this sort of logic is unncessary. -- CT
  34. for my $contact (@{$self->{contacts}}){
  35. my @invoices = $self->parse_array($contact->{invoices});
  36. my $processed_invoices = [];
  37. for my $invoice (@invoices){
  38. my $new_invoice = {};
  39. for (qw(invoice_id invnumber invoice_date amount discount due)){
  40. $new_invoice->{$_} = shift @$invoice;
  41. if ($_ =~ /^(amount|discount|due)$/){
  42. $new_invoice->{$_} =
  43. Math::BigFloat->new($new_invoice->{$_});
  44. }
  45. }
  46. push(@$processed_invoices, $new_invoice);
  47. }
  48. $contact->{invoice} = $processed_invoices;
  49. }
  50. return @{$self->{contacts}};
  51. }