summaryrefslogtreecommitdiff
path: root/LedgerSMB/DBObject/Company.pm
blob: 2d538582529195df3f5ba81252642fe553c73336 (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. my ($ref) = $self->exec_method(funcname => 'company_save');
  34. $self->{id} = $ref->{company_save};
  35. $self->{dbh}->commit;
  36. }
  37. =over
  38. =item save_credit
  39. This method saves the credit account for the company.
  40. =back
  41. =cut
  42. sub save_credit {
  43. my $self = shift @_;
  44. $self->set_entity_class();
  45. $self->{threshold} = $self->parse_amount(amount => $self->{threshold});
  46. $self->exec_method(funcname => 'entity_credit_save');
  47. $self->{threshold} = $self->format_amount(amount => $self->{threshold});
  48. $self->{dbh}->commit;
  49. }
  50. =over
  51. =item save_location
  52. This method saves an address for a company.
  53. =back
  54. =cut
  55. sub save_location {
  56. my $self = shift @_;
  57. $self->{country_id} = $self->{country_code};
  58. $self->exec_method(funcname => 'company__location_save');
  59. $self->{dbh}->commit;
  60. }
  61. =over
  62. =item get_credit_id
  63. This method returns the current credit id from the screen.
  64. =back
  65. =cut
  66. sub get_credit_id {
  67. my $self = shift @_;
  68. my ($ref) = $self->exec_method(
  69. funcname => 'entity_credit_get_id'
  70. );
  71. $self->{credit_id} = $ref->{'entity_credit_get_id'};
  72. }
  73. =over
  74. =item get_metadata()
  75. This retrieves various information vor building the user interface. Among other
  76. things, it sets the following properties:
  77. $self->{ar_ap_acc_list} = qw(list of ar or ap accounts)
  78. $self->{cash_acc_list} = qw(list of cash accounts)
  79. =back
  80. =cut
  81. sub get_metadata {
  82. my $self = shift @_;
  83. @{$self->{ar_ap_acc_list}} =
  84. $self->exec_method(funcname => 'chart_get_ar_ap');
  85. for my $ref (@{$self->{ar_ap_acc_list}}){
  86. $ref->{text} = "$ref->{accno}--$ref->{description}";
  87. }
  88. @{$self->{cash_acc_list}} =
  89. $self->exec_method(funcname => 'chart_list_cash');
  90. for my $ref (@{$self->{cash_acc_list}}){
  91. $ref->{text} = "$ref->{accno}--$ref->{description}";
  92. }
  93. @{$self->{location_class_list}} =
  94. $self->exec_method(funcname => 'location_list_class');
  95. @{$self->{business_types}} =
  96. $self->exec_method(funcname => 'business_type__list');
  97. @{$self->{country_list}} =
  98. $self->exec_method(funcname => 'location_list_country');
  99. @{$self->{contact_class_list}} =
  100. $self->exec_method(funcname => 'entity_list_contact_class');
  101. @{$self->{credit_list}} =
  102. $self->exec_method(funcname => 'entity__list_credit');
  103. }
  104. sub save_contact {
  105. my ($self) = @_;
  106. $self->exec_method(funcname => 'company__save_contact');
  107. $self->{dbh}->commit;
  108. }
  109. sub save_bank_account {
  110. my $self = shift @_;
  111. $self->exec_method(funcname => 'entity__save_bank_account');
  112. $self->{dbh}->commit;
  113. }
  114. sub save_notes {
  115. my $self = shift @_;
  116. $self->exec_method(funcname => 'entity__save_notes');
  117. $self->{dbh}->commit;
  118. }
  119. sub search {
  120. my ($self) = @_;
  121. @{$self->{search_results}} =
  122. $self->exec_method(funcname => 'company__search');
  123. return @{$self->{search_results}};
  124. }
  125. sub get {
  126. my $self = shift @_;
  127. $self->set_entity_class();
  128. my ($ref) = $self->exec_method(funcname => 'entity__retrieve_credit');
  129. $self->merge($ref);
  130. $self->{threshold} = $self->format_amount(amount => $self->{threshold});
  131. $self->{name} = $self->{legal_name};
  132. @{$self->{locations}} = $self->exec_method(
  133. funcname => 'company__list_locations');
  134. @{$self->{contacts}} = $self->exec_method(
  135. funcname => 'company__list_contacts');
  136. @{$self->{bank_account}} = $self->exec_method(
  137. funcname => 'company__list_bank_account');
  138. @{$self->{notes}} = $self->exec_method(
  139. funcname => 'company__list_notes');
  140. };
  141. 1;