summaryrefslogtreecommitdiff
path: root/LedgerSMB/DBObject/Company.pm
blob: 9b122b4d74b129e0a5c6073121bb9b890066ce59 (plain)
  1. =head1 NAME
  2. LedgerSMB::DBObject::Company.pm, LedgerSMB Base Class for Customers/Vendors
  3. =head1 SYNOPSIS
  4. This library contains the base utility functions for creating, saving, and
  5. retrieving customers and vendors.
  6. =cut
  7. package LedgerSMB::DBObject::Company;
  8. use base qw(LedgerSMB::DBObject);
  9. use strict;
  10. =head1 METHODS
  11. =over
  12. =item $company->set_entity_class()
  13. This is a stub for a private method that subclasses are expected to overwrite.
  14. It will be set to the account class of the entity (1 for vendor, 2 for customer,
  15. etc).
  16. =back
  17. =cut
  18. sub set_entity_class {
  19. my $self = shift @_;
  20. if (!defined $self->{entity_class}){
  21. $self->error("Entity ID Not Set and No Entity Class Defined!");
  22. }
  23. }
  24. =over
  25. =item save()
  26. This stores the company record including a credit accoun tin the database.
  27. TODO: Separate company from credit account storage.
  28. =back
  29. =cut
  30. sub save {
  31. my $self = shift @_;
  32. $self->set_entity_class();
  33. $self->{threshold} = $self->parse_amount(amount => $self->{threshold});
  34. my ($ref) = $self->exec_method(funcname => 'entity_credit_save');
  35. $self->{entity_id} = $ref->{entity_credit_save};
  36. $self->{threshold} = $self->format_amount(amount => $self->{threshold});
  37. $self->{dbh}->commit;
  38. }
  39. =over
  40. =item save_location
  41. This method saves an address for a company.
  42. =back
  43. =cut
  44. sub save_location {
  45. my $self = shift @_;
  46. $self->{country_id} = $self->{country};
  47. $self->exec_method(funcname => 'company__location_save');
  48. $self->{dbh}->commit;
  49. }
  50. =over
  51. =item get_metadata()
  52. This retrieves various information vor building the user interface. Among other
  53. things, it sets the following properties:
  54. $self->{ar_ap_acc_list} = qw(list of ar or ap accounts)
  55. $self->{cash_acc_list} = qw(list of cash accounts)
  56. =back
  57. =cut
  58. sub get_metadata {
  59. my $self = shift @_;
  60. @{$self->{ar_ap_acc_list}} =
  61. $self->exec_method(funcname => 'chart_get_ar_ap');
  62. for my $ref (@{$self->{ar_ap_acc_list}}){
  63. $ref->{text} = "$ref->{accno}--$ref->{description}";
  64. }
  65. @{$self->{cash_acc_list}} =
  66. $self->exec_method(funcname => 'chart_list_cash');
  67. for my $ref (@{$self->{cash_acc_list}}){
  68. $ref->{text} = "$ref->{accno}--$ref->{description}";
  69. }
  70. @{$self->{location_class_list}} =
  71. $self->exec_method(funcname => 'location_list_class');
  72. @{$self->{business_types}} =
  73. $self->exec_method(funcname => 'business_type__list');
  74. @{$self->{country_list}} =
  75. $self->exec_method(funcname => 'location_list_country');
  76. @{$self->{contact_class_list}} =
  77. $self->exec_method(funcname => 'entity_list_contact_class');
  78. }
  79. sub save_contact {
  80. my ($self) = @_;
  81. $self->exec_method(funcname => 'company__save_contact');
  82. $self->{dbh}->commit;
  83. }
  84. sub save_bank_account {
  85. my $self = shift @_;
  86. $self->exec_method(funcname => 'entity__save_bank_account');
  87. $self->{dbh}->commit;
  88. }
  89. sub save_notes {
  90. my $self = shift @_;
  91. $self->exec_method(funcname => 'entity__save_notes');
  92. $self->{dbh}->commit;
  93. }
  94. sub search {
  95. my ($self) = @_;
  96. @{$self->{search_results}} =
  97. $self->exec_method(funcname => 'company__search');
  98. return @{$self->{search_results}};
  99. }
  100. sub get {
  101. my $self = shift @_;
  102. $self->set_entity_class();
  103. my ($ref) = $self->exec_method(funcname => 'entity__retrieve_credit');
  104. $self->merge($ref);
  105. $self->{threshold} = $self->format_amount(amount => $self->{threshold});
  106. $self->{name} = $self->{legal_name};
  107. @{$self->{locations}} = $self->exec_method(
  108. funcname => 'company__list_locations');
  109. @{$self->{contacts}} = $self->exec_method(
  110. funcname => 'company__list_contacts');
  111. @{$self->{bank_account}} = $self->exec_method(
  112. funcname => 'company__list_bank_account');
  113. @{$self->{notes}} = $self->exec_method(
  114. funcname => 'company__list_notes');
  115. };
  116. 1;