summaryrefslogtreecommitdiff
path: root/LedgerSMB/DBObject/Company.pm
blob: ed94b0158f4b0d856b30f4e724452c1b1249f2f8 (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->{location_class_list}} =
  26. $self->exec_method(funcname => 'location_list_class');
  27. @{$self->{country_list}} =
  28. $self->exec_method(funcname => 'location_list_country');
  29. @{$self->{contact_class_list}} =
  30. $self->exec_method(funcname => 'entity_list_contact_class');
  31. }
  32. sub save_contact {
  33. my ($self) = @_;
  34. $self->exec_method(funcname => 'company__save_contact');
  35. $self->{dbh}->commit;
  36. }
  37. sub save_bank_account {
  38. my $self = shift @_;
  39. $self->exec_method(funcname => 'entity__save_bank_account');
  40. $self->{dbh}->commit;
  41. }
  42. sub save_notes {
  43. my $self = shift @_;
  44. $self->exec_method(funcname => 'entity__save_notes');
  45. $self->{dbh}->commit;
  46. }
  47. sub get {
  48. my $self = shift @_;
  49. $self->set_entity_class();
  50. my ($ref) = $self->exec_method(funcname => 'entity__retrieve_credit');
  51. $self->merge($ref);
  52. $self->{name} = $self->{legal_name};
  53. @{$self->{locations}} = $self->exec_method(
  54. funcname => 'company__list_locations');
  55. @{$self->{contacts}} = $self->exec_method(
  56. funcname => 'company__list_contacts');
  57. @{$self->{bank_account}} = $self->exec_method(
  58. funcname => 'company__list_bank_account');
  59. @{$self->{notes}} = $self->exec_method(
  60. funcname => 'company__list_notes');
  61. };
  62. 1;