summaryrefslogtreecommitdiff
path: root/scripts/Reconciliation.pl
blob: 8826f037f137faa9e0d67a872b530d6f207155f4 (plain)
  1. =pod
  2. =head1 NAME
  3. LedgerSMB::Scripts::Reconciliation - LedgerSMB class defining the Controller
  4. functions, template instantiation and rendering.
  5. =head1 SYOPSIS
  6. This module acts as the UI controller class for Reconciliation. It controls
  7. interfacing with the Core Logic and database layers.
  8. =head1 METHODS
  9. =cut
  10. # NOTE: This is a first draft modification to use the current parameter type.
  11. # It will certainly need some fine tuning on my part. Chris
  12. package LedgerSMB::Scripts::Reconciliation;
  13. use LedgerSMB::Template;
  14. use LedgerSMB::DBObject::Reconciliation;
  15. =pod
  16. =over
  17. =item display_report($self, $request, $user)
  18. Renders out the selected report given by the incoming variable report_id.
  19. Returns HTML, or raises an error from being unable to find the selected
  20. report_id.
  21. =back
  22. =cut
  23. sub display_report {
  24. my ($class, $request) = @_;
  25. my $recon = LedgerSMB::Employee->new(base => $request, copy => 'all');
  26. my $template = LedgerSMB::Template->new( user=>$user,
  27. template => "reconciliation_report.html", language => $user->{language},
  28. format=>'html'
  29. );
  30. my $report = $recon->get_report();
  31. my $total = $recon->get_total();
  32. $template->render({report=>$report, total=>$total});
  33. }
  34. sub search {
  35. my ($class, $request) = @_;
  36. my $search = LedgerSMB::Employee->new(base => $request, copy => 'all');
  37. $employee->{search_results} = $employee->search();
  38. my $template = LedgerSMB::Template->new( user => $user,
  39. template => 'employee_search.html', language => $user->{language},
  40. format => 'html');
  41. $template->render($employee);
  42. }
  43. =pod
  44. =over
  45. =item correct ($self, $request, $user)
  46. Requires report_id, entry_id.
  47. Correct is a strange one. Based on the type of transaction listed in the
  48. report, it will run one of several correction functions in the database.
  49. This is to prevent arbitrary editing of the database by unscrupulous users.
  50. =back
  51. =cut
  52. sub correct {
  53. my ($class, $request) = @_;
  54. my $recon = LedgerSMB::DBObject::Reconciliation->new(base => $request, copy => 'all');
  55. $recon->correct_entry();
  56. if ($recon->{corrected_id}) {
  57. my $template = LedgerSMB::Template->new( user => $user,
  58. template => 'reconciliation_report.html', language => $user->{language},
  59. format => 'html');
  60. $template->render( {
  61. corrected=> $recon->{corrected_id},
  62. report=> $recon->get_report(),
  63. total=> $recon->get_total()
  64. } );
  65. }
  66. else {
  67. # indicate we were unable to correct this entry, with the error code
  68. # spat back to us by the DB.
  69. my $template = LedgerSMB::Template->new( user => $user,
  70. template => 'reconciliation_report.html', language => $user->{language},
  71. format => 'html');
  72. $template->render( {
  73. recon => $recon,
  74. report=> $recon->get_report(),
  75. total=> $recon->get_total()
  76. } );
  77. }
  78. }
  79. =pod
  80. =over
  81. =item new_report ($self, $request, $user)
  82. Creates a new report, from a selectable set of bank statements that have been
  83. received (or can be received from, depending on implementation)
  84. Allows for an optional selection key, which will return the new report after
  85. it has been created.
  86. =back
  87. =cut
  88. sub new_report {
  89. my ($class, $request) = @_;
  90. # how are we going to allow this to be created? Grr.
  91. # probably select a list of statements that are available to build
  92. # reconciliation reports with.
  93. my $template;
  94. my $recon = LedgerSMB::DBObject::Reconciliation->new(base => $request, copy => 'all');
  95. my $return;
  96. if ($request->{selection}) {
  97. $template = LedgerSMB::Template->new( user => $user,
  98. template => 'reconciliation_report.html', language => $user->{language},
  99. format => 'html');
  100. $template->render($recon->new_report());
  101. }
  102. else {
  103. # Generate the list of available bank statements/bank statements that
  104. # we have access to.
  105. }
  106. return $return;
  107. }
  108. =pod
  109. =over
  110. =item approve ($self, $request, $user)
  111. Requires report_id
  112. Approves the given report based on id. Generally, the roles should be
  113. configured so as to disallow the same user from approving, as created the report.
  114. Returns a success page on success, returns a new report on failure, showing
  115. the uncorrected entries.
  116. =back
  117. =cut
  118. sub approve {
  119. my ($class, $request) = @_;
  120. # Approve will also display the report in a blurred/opaqued out version,
  121. # with the controls removed/disabled, so that we know that it has in fact
  122. # been cleared. This will also provide for return-home links, auditing,
  123. # etc.
  124. my $recon = LedgerSMB::DBObject::Reconciliation->new(base => request, copy=> 'all');
  125. my $template;
  126. my $report;
  127. if ($recon->approve()) {
  128. $template = LedgerSMB::Template->new( user => $user,
  129. template => 'reconciliation_approve.html', language => $user->{language},
  130. format => 'html');
  131. }
  132. else {
  133. $template = LedgerSMB::Template->new( user => $user,
  134. template => 'reconciliation_report.html', language => $user->{language},
  135. format => 'html');
  136. $report = $recon->get_report();
  137. ## relies on foreknowledge in the template
  138. ## we basically tell the template, we can't approve, this uncorrected
  139. ## error is preventing us.
  140. $report->{ error } = { approval => 1 };
  141. }
  142. $template->render($report);
  143. }
  144. =pod
  145. =over
  146. =item corrections ($self, $request, $user)
  147. Requires report_id and entry_id.
  148. Loads the selected entry id and all corrections associated with it. If there
  149. aren't any corrections, it will display "no corrections found".
  150. =back
  151. =cut
  152. sub corrections {
  153. my ($class, $request) = @_;
  154. # Load the corrections for a given report & entry id.
  155. # possibly should use a "micro" popup window?
  156. my $recon = LedgerSMB::DBObject::Reconciliation->new(base => request, copy=> 'all');
  157. my $template;
  158. $template = LedgerSMB::Template->new( user => $user,
  159. template => 'reconciliation_corrected.html', language => $user->{language},
  160. format => 'html');
  161. return $template->render(
  162. {
  163. corrections=>$recon->get_corrections(),
  164. entry=>$recon->entry($self->{report_id}, $self->{entry_id})
  165. }
  166. );
  167. }
  168. 1;
  169. =pod
  170. =head1 Copyright (C) 2007, The LedgerSMB core team.
  171. This file is licensed under the Gnu General Public License version 2, or at your
  172. option any later version. A copy of the license should have been included with
  173. your software.
  174. =cut