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