summaryrefslogtreecommitdiff
path: root/scripts/customer.pl
blob: c684c7e612bef27bde54ca098901e4caa096f12c (plain)
  1. =pod
  2. =head1 NAME
  3. LedgerSMB::Scripts::customer - LedgerSMB class defining the Controller
  4. functions, template instantiation and rendering for customer editing and display.
  5. =head1 SYOPSIS
  6. This module is the UI controller for the customer DB access; it provides the
  7. View interface, as well as defines the Save customer.
  8. Save customer will update or create as needed.
  9. =head1 METHODS
  10. =cut
  11. package LedgerSMB::Scripts::customer;
  12. use LedgerSMB::Template;
  13. use LedgerSMB::DBObject::Customer;
  14. =pod
  15. =over
  16. =item get($self, $request, $user)
  17. Requires form var: id
  18. Extracts a single customer from the database, using its company ID as the primary
  19. point of uniqueness. Shows (appropriate to user privileges) and allows editing
  20. of the customer informations.
  21. =back
  22. =cut
  23. sub get {
  24. my ($request) = @_;
  25. my $customer = LedgerSMB::DBObject::Customer->new(base => $request, copy => 'all');
  26. my $result = $customer->get($customer->{id});
  27. my $template = LedgerSMB::Template->new( user => $user,
  28. template => 'customer.html', language => $user->{language},
  29. format => 'html');
  30. $template->render($results);
  31. }
  32. =pod
  33. =over
  34. =item add
  35. This method creates a blank screen for entering a customer's information.
  36. =back
  37. =cut
  38. sub add {
  39. my ($request) = @_;
  40. my $customer = LedgerSMB::DBObject::Customer->new(base => $request, copy => 'all');
  41. my $template = LedgerSMB::Template->new( user => $user,
  42. template => 'customer.html', language => $user->{language},
  43. format => 'html');
  44. $template->render($results);
  45. }
  46. =pod
  47. =over
  48. =item search($self, $request, $user)
  49. Requires form var: search_pattern
  50. Directly calls the database function search, and returns a set of all customers
  51. found that match the search parameters. Search parameters search over address
  52. as well as customer/Company name.
  53. =back
  54. =cut
  55. sub search {
  56. my ($request) = @_;
  57. my $customer = LedgerSMB::DBObject::Customer->new(base => $request, copy => 'all');
  58. my $results = $customer->search($customer->{search_pattern});
  59. my $template = LedgerSMB::Template->new( user => $user,
  60. template => 'customer_search.html', language => $user->{language},
  61. format => 'html');
  62. $template->render($results);
  63. }
  64. =pod
  65. =over
  66. =item save($self, $request, $user)
  67. Saves a customer to the database. The function will update or insert a new
  68. customer as needed, and will generate a new Company ID for the customer if needed.
  69. =back
  70. =cut
  71. sub save {
  72. my ($request) = @_;
  73. my $customer = LedgerSMB::DBObject::Customer->new(base => $request, copy => 'all');
  74. my $result = $customer->save_to_db();
  75. my $template = LedgerSMB::Template->new( user => $user,
  76. template => 'customer.html', language => $user->{language},
  77. format => 'html');
  78. $template->render($result);
  79. }
  80. 1;