summaryrefslogtreecommitdiff
path: root/LedgerSMB/DBObject/Company.pm
blob: 0e56567b7c35c920bcdd05e107887d8156e55b2d (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. $self->{threshold} = $self->parse_amount(amount => $self->{threshold});
  14. my ($ref) = $self->exec_method(funcname => 'entity_credit_save');
  15. $self->{entity_id} = $ref->{entity_credit_save};
  16. $self->{threshold} = $self->format_amount(amount => $self->{threshold});
  17. $self->{dbh}->commit;
  18. }
  19. sub save_location {
  20. my $self = shift @_;
  21. $self->{country_id} = $self->{country};
  22. $self->exec_method(funcname => 'company__location_save');
  23. $self->{dbh}->commit;
  24. }
  25. sub get_metadata {
  26. my $self = shift @_;
  27. @{$self->{ar_ap_acc_list}} =
  28. $self->exec_method(funcname => 'chart_get_ar_ap');
  29. for my $ref (@{$self->{ar_ap_acc_list}}){
  30. $ref->{text} = "$ref->{accno}--$ref->{description}";
  31. }
  32. @{$self->{cash_acc_list}} =
  33. $self->exec_method(funcname => 'chart_list_cash');
  34. for my $ref (@{$self->{cash_acc_list}}){
  35. $ref->{text} = "$ref->{accno}--$ref->{description}";
  36. }
  37. @{$self->{location_class_list}} =
  38. $self->exec_method(funcname => 'location_list_class');
  39. @{$self->{business_types}} =
  40. $self->exec_method(funcname => 'business_type__list');
  41. @{$self->{country_list}} =
  42. $self->exec_method(funcname => 'location_list_country');
  43. @{$self->{contact_class_list}} =
  44. $self->exec_method(funcname => 'entity_list_contact_class');
  45. }
  46. sub save_contact {
  47. my ($self) = @_;
  48. $self->exec_method(funcname => 'company__save_contact');
  49. $self->{dbh}->commit;
  50. }
  51. sub save_bank_account {
  52. my $self = shift @_;
  53. $self->exec_method(funcname => 'entity__save_bank_account');
  54. $self->{dbh}->commit;
  55. }
  56. sub save_notes {
  57. my $self = shift @_;
  58. $self->exec_method(funcname => 'entity__save_notes');
  59. $self->{dbh}->commit;
  60. }
  61. sub search {
  62. my ($self) = @_;
  63. @{$self->{search_results}} =
  64. $self->exec_method(funcname => 'company__search');
  65. return @{$self->{search_results}};
  66. }
  67. sub get {
  68. my $self = shift @_;
  69. $self->set_entity_class();
  70. my ($ref) = $self->exec_method(funcname => 'entity__retrieve_credit');
  71. $self->merge($ref);
  72. $self->{threshold} = $self->format_amount(amount => $self->{threshold});
  73. $self->{name} = $self->{legal_name};
  74. @{$self->{locations}} = $self->exec_method(
  75. funcname => 'company__list_locations');
  76. @{$self->{contacts}} = $self->exec_method(
  77. funcname => 'company__list_contacts');
  78. @{$self->{bank_account}} = $self->exec_method(
  79. funcname => 'company__list_bank_account');
  80. @{$self->{notes}} = $self->exec_method(
  81. funcname => 'company__list_notes');
  82. };
  83. 1;