summaryrefslogtreecommitdiff
path: root/scripts/employee.pl
blob: b265dba59c7650136cc78cf2df8e84842e902801 (plain)
  1. #!/usr/bin/perl
  2. =pod
  3. =head1 NAME
  4. LedgerSMB::Scripts::employee - LedgerSMB class defining the Controller
  5. functions, template instantiation and rendering for employee editing and display.
  6. =head1 SYOPSIS
  7. This module is the UI controller for the employee DB access; it provides the
  8. View interface, as well as defines the Save employee.
  9. Save employee will update or create as needed.
  10. =head1 METHODS
  11. =cut
  12. package LedgerSMB::Scripts::employee;
  13. use LedgerSMB::Template;
  14. use LedgerSMB::DBObject::Employee;
  15. require 'lsmb-request.pl';
  16. =pod
  17. =over
  18. =item get($self, $request, $user)
  19. Requires form var: id
  20. Extracts a single employee 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 employee informations.
  23. =back
  24. =cut
  25. sub get {
  26. my ($request) = @_;
  27. my $employee = LedgerSMB::DBObject::Employee->new(base => $request, copy => 'all');
  28. $employee->set( entity_class=> '3' );
  29. my $result = $employee->get();
  30. my $template = LedgerSMB::Template->new( user => $user,
  31. template => 'contact', language => $user->{language},
  32. path => 'UI/Contact',
  33. format => 'HTML');
  34. $template->render($results);
  35. }
  36. sub add_location {
  37. my ($request) = @_;
  38. my $employee= LedgerSMB::DBObject::Employee->new({base => $request, copy => 'all'});
  39. $employee->set( entity_class=> '3' );
  40. $employee->save_location();
  41. $employee->get();
  42. $employee->get_metadata();
  43. _render_main_screen($employee);
  44. }
  45. =pod
  46. =over
  47. =item add
  48. This method creates a blank screen for entering a employee's information.
  49. =back
  50. =cut
  51. sub add {
  52. my ($request) = @_;
  53. my $employee= LedgerSMB::DBObject::Employee->new(base => $request, copy => 'all');
  54. $employee->set( entity_class=> '3' );
  55. _render_main_screen($employee);
  56. }
  57. =pod
  58. =over
  59. =item search($self, $request, $user)
  60. Requires form var: search_pattern
  61. Directly calls the database function search, and returns a set of all employees
  62. found that match the search parameters. Search parameters search over address
  63. as well as employee/Company name.
  64. =back
  65. =cut
  66. sub search {
  67. my ($request) = @_;
  68. if ($request->type() eq 'POST') {
  69. # assume it's asking us to do the search, now
  70. my $employee = LedgerSMB::DBObject::Employee->new(base => $request, copy => 'all');
  71. $employee->set(entity_class=>3);
  72. my $results = $employee->search($employee->{search_pattern});
  73. my $template = LedgerSMB::Template->new( user => $user,
  74. template => 'Contact/employee', language => $user->{language},
  75. format => 'HTML');
  76. $template->render($results);
  77. }
  78. else {
  79. # grab the happy search page out.
  80. my $template = LedgerSMB::Template->new(
  81. user => $user,
  82. path => 'UI/Contact' ,
  83. template => 'employee_search',
  84. locale => $request->{_locale},
  85. format => 'HTML');
  86. $template->render();
  87. }
  88. }
  89. =pod
  90. =over
  91. =item save($self, $request, $user)
  92. Saves a employee to the database. The function will update or insert a new
  93. employee as needed, and will generate a new Company ID for the employee if needed.
  94. =back
  95. =cut
  96. sub save {
  97. my ($request) = @_;
  98. my $employee = LedgerSMB::DBObject::Employee->new({base => $request});
  99. $employee->save();
  100. _render_main_screen($employee);
  101. }
  102. sub edit{
  103. my $request = shift @_;
  104. my $employee = LedgerSMB::DBObject::Employee->new({base => $request});
  105. $employee->get();
  106. _render_main_screen($employee);
  107. }
  108. sub _render_main_screen{
  109. my $employee = shift @_;
  110. $employee->get_metadata();
  111. $employee->{creditlimit} = "$employee->{creditlimit}";
  112. $employee->{discount} = "$employee->{discount}";
  113. $employee->{script} = "employee.pl";
  114. my $template = LedgerSMB::Template->new(
  115. user => $employee->{_user},
  116. template => 'contact',
  117. locale => $employee->{_locale},
  118. path => 'UI/Contact',
  119. format => 'HTML'
  120. );
  121. $template->render($employee);
  122. }
  123. sub save_contact {
  124. my ($request) = @_;
  125. my $employee = LedgerSMB::DBObject::Employee->new({base => $request});
  126. $employee->save_contact();
  127. $employee->get;
  128. _render_main_screen($employee );
  129. }
  130. sub save_bank_account {
  131. my ($request) = @_;
  132. my $employee = LedgerSMB::DBObject::Employee->new({base => $request});
  133. $employee->save_bank_account();
  134. $employee->get;
  135. _render_main_screen($employee);
  136. }
  137. sub save_notes {
  138. my ($request) = @_;
  139. my $employee = LedgerSMB::DBObject::Employee->new({base => $request});
  140. $employee->save_notes();
  141. $employee->get();
  142. _render_main_screen($employee);
  143. }
  144. 1;