summaryrefslogtreecommitdiff
path: root/LedgerSMB/Reconciliation.pm
blob: 6dca96d2bae56e5b339137dd9b05051ae2631f7e (plain)
  1. =pod
  2. =head1 NAME
  3. LedgerSMB::DBObject::Reconciliation - LedgerSMB class defining the core
  4. database interaction logic for Reconciliation.
  5. =head1 SYOPSIS
  6. This module creates object instances based on LedgerSMB's in-database ORM.
  7. =head1 METHODS
  8. =over
  9. =item new ($class, base => $LedgerSMB::hash)
  10. This is the base constructor for all child classes. It must be used with base
  11. argument because this is necessary for database connectivity and the like.
  12. Of course the base object can be any object that inherits LedgerSMB, so you can
  13. use any subclass of that. The per-session dbh is passed between the objects
  14. this way as is any information that is needed.
  15. =item reconcile($self, $total, $month, $entries)
  16. Accepts the total balance, as well as a list of all entries from the bank
  17. statement as an array reference, and generates the pending report from
  18. this list.
  19. The first entry is always the total balance of the general ledger as
  20. compared to the balance held by the bank.
  21. Month is taken to be the date that the statement as represented by Entries
  22. is applicable to.
  23. Returns the new report ID. || An arrayref of entries.
  24. =item approve($self,$reportid)
  25. Approves the pending report $reportid.
  26. Checks for error codes in the pending report, and approves the report if none
  27. are found.
  28. Limitations: The creating user may not approve the report.
  29. Returns 1 on success.
  30. =item correct_entry($self, $report_id, $source_control_number, $new_balance)
  31. If the given entry $source_control_number in the report $report_id has an error
  32. code, the entry will be updated with $new_balance, and the error code
  33. recomputed.
  34. Returns the error code assigned to this entry.
  35. 0 for success
  36. 1 for found in general ledger, but does not match $new_balance
  37. 2 $source_control_number cannot be found in the general ledger
  38. =item get_report($self, $report_id)
  39. Collects all the rows from the database in the given report. Returns an
  40. arrayref of entries in the table for the given report_id.
  41. Returns undef in the event of no records found.
  42. =item get_corrections($self, $report_id, $entry_id)
  43. Returns the corrections made for the selected report and entry.
  44. Returns undef in the event of no corrections found.
  45. =item entry ($self,$report_id,$entry_id)
  46. Returns a single entry from the pending reports table, either cleared or
  47. uncleared.
  48. =back
  49. =head1 Copyright (C) 2007, The LedgerSMB core team.
  50. This file is licensed under the Gnu General Public License version 2, or at your
  51. option any later version. A copy of the license should have been included with
  52. your software.
  53. =cut
  54. package LedgerSMB::DBObject::Reconciliation;
  55. use base qw(LedgerSMB);
  56. use LedgerSMB::DBObject;
  57. # don't need new
  58. #sub reconcile {
  59. sub new_report {
  60. my $self = shift @_;
  61. my $total = shift @_;
  62. my $month = shift @_;
  63. my $entries = shift @_; # expects an arrayref.
  64. # Total is in here somewhere, too
  65. my $report_id = $self->new_report_id()[0]; # gives us a report ID to insert with.
  66. # Now that we have this, we need to create the internal report representation.
  67. # Ideally, we OUGHT to not return anything here, save the report number.
  68. unshift @{$entries}, {
  69. scn => -1,
  70. balance=> $total,
  71. old_balance=> $self->current_balance,
  72. date=>$month
  73. };
  74. for my $entry (@{$entries}) {
  75. # Codes:
  76. # 0 is success
  77. # 1 is found, but mismatch
  78. # 2 is not found
  79. $entry{report_id} = $report_id;
  80. $entry{code} = $self->add_entry( $entry );
  81. }
  82. $self->pending_transactions($report_id, $date);
  83. return $entries; # returns the report ID.
  84. }
  85. sub approve {
  86. my $self = shift @_;
  87. # the user should be embedded into the $self object.
  88. my $report_id = shift @_;
  89. my $code = $self->report_approve($report_id); # user
  90. if ($code == 0) { # no problem.
  91. return $code;
  92. }
  93. # this is destined to change as we figure out the Error system.
  94. elsif ($code == 99) {
  95. $self->error("User $self->{user}->{name} cannot approve report, must be a different user.");
  96. }
  97. }
  98. sub correct_entry {
  99. my $self = shift @_;
  100. my $report_id = $self->{report_id}; # shift @_;
  101. my $scn = $self->{id}; #shift @_;
  102. my $new_amount = $self->{new_amount}; #shift @_;
  103. # correct should return the new code value - whether or not it actually "matches"
  104. my $code = $self->correct($report_id, $scn, $new_amount);
  105. return $code[0]->{'correct'};
  106. }
  107. sub get_report {
  108. my $self = shift @_;
  109. return $self->report($self->{report_id});
  110. }
  111. sub get_corrections {
  112. my $self = shift @_;
  113. return $self->corrections($self->{report_id},$self->{entry_id});
  114. }
  115. sub entry {
  116. my $self = shift @_;
  117. return $self->single_entry($self->{report_id},$self->{entry_id});
  118. }
  119. 1;