summaryrefslogtreecommitdiff
path: root/scripts/customer.pl
blob: 8b4769950bb8c1872ff4eacc9be10b5e63650e8e (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 ($class, $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 search($self, $request, $user)
  35. Requires form var: search_pattern
  36. Directly calls the database function search, and returns a set of all customers
  37. found that match the search parameters. Search parameters search over address
  38. as well as customer/Company name.
  39. =back
  40. =cut
  41. sub search {
  42. my ($class, $request) = @_;
  43. my $customer = LedgerSMB::DBObject::Customer->new(base => $request, copy => 'all');
  44. my $results = $customer->search($customer->{search_pattern});
  45. my $template = LedgerSMB::Template->new( user => $user,
  46. template => 'customer_search.html', language => $user->{language},
  47. format => 'html');
  48. $template->render($results);
  49. }
  50. =pod
  51. =over
  52. =item save($self, $request, $user)
  53. Saves a customer to the database. The function will update or insert a new
  54. customer as needed, and will generate a new Company ID for the customer if needed.
  55. =back
  56. =cut
  57. sub save {
  58. my ($class, $request) = @_;
  59. my $customer = LedgerSMB::DBObject::Customer->new(base => $request, copy => 'all');
  60. my $result = $customer->save_to_db();
  61. my $template = LedgerSMB::Template->new( user => $user,
  62. template => 'customer.html', language => $user->{language},
  63. format => 'html');
  64. $template->render($result);
  65. }
  66. 1;