summaryrefslogtreecommitdiff
path: root/LedgerSMB/DBObject/Company.pm
blob: 0ce2f6ee900d692d1518661793528c96af46055f (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 get {
  43. my $self = shift @_;
  44. $self->set_entity_class()
  45. my ($ref) = $self->exec_method(funcname => 'entity__retrieve_credit');
  46. $self->merge($ref);
  47. $self->{name} = $self->{legal_name};
  48. @{$self->{locations}} = $self->exec_method(
  49. funcname => 'company__list_locations');
  50. @{$self->{contacts}} = $self->exec_method(
  51. funcname => 'company__list_contacts');
  52. @{$self->{bank_account}} = $self->exec_method(
  53. funcname => 'company__list_bank_account');
  54. @{$self->{notes}} = $self->exec_method(
  55. funcname => 'company__list_notes');
  56. };
  57. 1;