summaryrefslogtreecommitdiff
path: root/LedgerSMB/DBObject/Company.pm
blob: 13b9ff65289c9105b7cb3548063c0a07c3a94eb3 (plain)
  1. package LedgerSMB::DBObject::Company;
  2. use base qw(LedgerSMB::DBObject);
  3. use strict;
  4. sub set_entity_class {
  5. my $self = shift @_;
  6. if (!defined $self->{entity_class}){
  7. $self->error("Entity ID Not Set and No Entity Class Defined!");
  8. }
  9. }
  10. sub save {
  11. my $self = shift @_;
  12. $self->set_entity_class();
  13. my ($ref) = $self->exec_method(funcname => 'entity_credit_save');
  14. $self->{entity_id} = $ref->{entity_credit_save};
  15. $self->{dbh}->commit;
  16. }
  17. sub save_location {
  18. my $self = shift @_;
  19. $self->{country_id} = $self->{country};
  20. $self->exec_method(funcname => 'company__location_save');
  21. $self->{dbh}->commit;
  22. }
  23. sub get_metadata {
  24. my $self = shift @_;
  25. @{$self->{ar_ap_acc_list}} =
  26. $self->exec_method(funcname => 'chart_get_ar_ap');
  27. for my $ref (@{$self->{ar_ap_acc_list}}){
  28. $ref->{text} = "$ref->{accno}--$ref->{description}";
  29. }
  30. @{$self->{cash_acc_list}} =
  31. $self->exec_method(funcname => 'chart_list_cash');
  32. for my $ref (@{$self->{cash_acc_list}}){
  33. $ref->{text} = "$ref->{accno}--$ref->{description}";
  34. }
  35. @{$self->{location_class_list}} =
  36. $self->exec_method(funcname => 'location_list_class');
  37. @{$self->{business_types}} =
  38. $self->exec_method(funcname => 'business_type__list');
  39. @{$self->{country_list}} =
  40. $self->exec_method(funcname => 'location_list_country');
  41. @{$self->{contact_class_list}} =
  42. $self->exec_method(funcname => 'entity_list_contact_class');
  43. }
  44. sub save_contact {
  45. my ($self) = @_;
  46. $self->exec_method(funcname => 'company__save_contact');
  47. $self->{dbh}->commit;
  48. }
  49. sub save_bank_account {
  50. my $self = shift @_;
  51. $self->exec_method(funcname => 'entity__save_bank_account');
  52. $self->{dbh}->commit;
  53. }
  54. sub save_notes {
  55. my $self = shift @_;
  56. $self->exec_method(funcname => 'entity__save_notes');
  57. $self->{dbh}->commit;
  58. }
  59. sub search {
  60. my ($self) = @_;
  61. @{$self->{search_results}} =
  62. $self->exec_method(funcname => 'company__search');
  63. return @{$self->{search_results}};
  64. }
  65. sub get {
  66. my $self = shift @_;
  67. $self->set_entity_class();
  68. my ($ref) = $self->exec_method(funcname => 'entity__retrieve_credit');
  69. $self->merge($ref);
  70. $self->{name} = $self->{legal_name};
  71. @{$self->{locations}} = $self->exec_method(
  72. funcname => 'company__list_locations');
  73. @{$self->{contacts}} = $self->exec_method(
  74. funcname => 'company__list_contacts');
  75. @{$self->{bank_account}} = $self->exec_method(
  76. funcname => 'company__list_bank_account');
  77. @{$self->{notes}} = $self->exec_method(
  78. funcname => 'company__list_notes');
  79. };
  80. 1;