summaryrefslogtreecommitdiff
path: root/scripts/Reconciliation.pl
blob: 189eecb4feffb8a7becac9712286105644339a46 (plain)
  1. =pod
  2. =head1 NAME
  3. =cut
  4. package LedgerSMB::Scripts::Reconciliation;
  5. use LedgerSMB::Template;
  6. use LedgerSMB::DBObject::Reconciliation;
  7. =pod
  8. =over
  9. =item display_report($self, $request, $user)
  10. Renders out the selected report given by the incoming variable report_id.
  11. Returns HTML, or raises an error from being unable to find the selected
  12. report_id.
  13. =back
  14. =cut
  15. sub display_report {
  16. my $recon = LedgerSMB::Employee->new(base => $request, copy => 'all');
  17. my $template = LedgerSMB::Template->new( user=>$user,
  18. template => "reconciliation_report.html", language => $user->{language},
  19. format=>'html'
  20. );
  21. my $report = $recon->get_report();
  22. my $total = $recon->get_total();
  23. $template->render({report=>$report, total=>$total});
  24. }
  25. sub search {
  26. my $search = LedgerSMB::Employee->new(base => $request, copy => 'all');
  27. $employee->{search_results} = $employee->search();
  28. my $template = LedgerSMB::Template->new( user => $user,
  29. template => 'employee_search.html', language => $user->{language},
  30. format => 'html');
  31. $template->render($employee);
  32. }
  33. =pod
  34. =over
  35. =item correct ($self, $request, $user)
  36. Requires report_id, entry_id.
  37. Correct is a strange one. Based on the type of transaction listed in the
  38. report, it will run one of several correction functions in the database.
  39. This is to prevent arbitrary editing of the database by unscrupulous users.
  40. =back
  41. =cut
  42. sub correct {
  43. my $recon = LedgerSMB::DBObject::Reconciliation->new(base => $request, copy => 'all');
  44. my $template = LedgerSMB::Template->new( user => $user,
  45. template => 'reconciliation_correct.html', language => $user->{language},
  46. format => 'html');
  47. $recon->correct_entry();
  48. $template->render($recon->get_report());
  49. }
  50. =pod
  51. =over
  52. =item new_report ($self, $request, $user)
  53. Creates a new report, from a selectable set of bank statements that have been
  54. received (or can be received from, depending on implementation)
  55. Allows for an optional selection key, which will return the new report after
  56. it has been created.
  57. =back
  58. =cut
  59. sub new_report {
  60. # how are we going to allow this to be created? Grr.
  61. # probably select a list of statements that are available to build
  62. # reconciliation reports with.
  63. my $template;
  64. my $recon = LedgerSMB::DBObject::Reconciliation->new(base => $request, copy => 'all');
  65. my $return;
  66. if ($request->{selection}) {
  67. $template = LedgerSMB::Template->new( user => $user,
  68. template => 'reconciliation_report.html', language => $user->{language},
  69. format => 'html');
  70. $template->render($recon->new_report());
  71. }
  72. else {
  73. # Generate the list of available bank statements/bank statements that
  74. # we have access to.
  75. }
  76. return $return;
  77. }
  78. =pod
  79. =over
  80. =item ($self, $request, $user)
  81. Requires report_id
  82. Approves the given report based on id. Generally, the roles should be
  83. configured so as to disallow the same user from approving, as created the report.
  84. Returns a success page on success, returns a new report on failure, showing
  85. the uncorrected entries.
  86. =back
  87. =cut
  88. sub approve {
  89. my $recon = LedgerSMB::DBObject::Reconciliation->new(base => request, copy=> 'all');
  90. my $template;
  91. my $report;
  92. if ($recon->approve()) {
  93. $template = LedgerSMB::Template->new( user => $user,
  94. template => 'reconciliation_approve.html', language => $user->{language},
  95. format => 'html');
  96. }
  97. else {
  98. $template = LedgerSMB::Template->new( user => $user,
  99. template => 'reconciliation_report.html', language => $user->{language},
  100. format => 'html');
  101. $report = $recon->get_report();
  102. ## relies on foreknowledge in the template
  103. ## we basically tell the template, we can't approve, this uncorrected
  104. ## error is preventing us.
  105. $report->{ error } = { approval => 1 };
  106. }
  107. $template->render($report);
  108. }
  109. 1;