summaryrefslogtreecommitdiff
path: root/LedgerSMB/Reconciliation.pm
blob: e9963ae9017b32b122c0280195110c6ee7ea46cd (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, $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. Returns the new report ID. || An arrayref of entries.
  22. =item approve($self,$reportid)
  23. Approves the pending report $reportid.
  24. Checks for error codes in the pending report, and approves the report if none
  25. are found.
  26. Limitations: The creating user may not approve the report.
  27. Returns 1 on success.
  28. =item correct_entry($self, $report_id, $source_control_number, $new_balance)
  29. If the given entry $source_control_number in the report $report_id has an error
  30. code, the entry will be updated with $new_balance, and the error code
  31. recomputed.
  32. Returns the error code assigned to this entry.
  33. 0 for success
  34. 1 for found in general ledger, but does not match $new_balance
  35. 2 $source_control_number cannot be found in the general ledger
  36. =back
  37. =head1 Copyright (C) 2007, The LedgerSMB core team.
  38. This file is licensed under the Gnu General Public License version 2, or at your
  39. option any later version. A copy of the license should have been included with
  40. your software.
  41. =cut
  42. package LedgerSMB::DBObject::Reconciliation;
  43. use base qw(LedgerSMB::DBObject);
  44. # don't need new
  45. sub reconcile {
  46. my $self = shift @_;
  47. my $total = shift @_;
  48. my $entries = shift @_; # expects an arrayref.
  49. # Total is in here somewhere, too
  50. my $report_id = $self->new_report(); # gives us a report ID to insert with.
  51. # Now that we have this, we need to create the internal report representation.
  52. # Ideally, we OUGHT to not return anything here, save the report number.
  53. unshift @{$entries}, {scn => 0, balance=> $total, old_balance=> $self->current_balance, code=> $self->compare_total($total) };
  54. for my $entry (@{$entries}) {
  55. # Codes:
  56. # 0 is success
  57. # 1 is found, but mismatch
  58. # 2 is not found
  59. $entry{report_id} = $report_id;
  60. $entry{code} = $self->add_entry( $entry );
  61. }
  62. # Based on chatting with Chris T, we are going to use an arrayref of hashrefs to handle
  63. # the varying return states.
  64. return $entries; # returns the report ID.
  65. }
  66. sub approve {
  67. my $self = shift @_;
  68. # the user should be embedded into the $self object.
  69. my $report_id = shift @_;
  70. my $code = $self->report_approve($report_id,$self->{user}->{id}); # user
  71. if ($code == 0) { # no problem.
  72. return $code;
  73. }
  74. # this is destined to change as we figure out the Error system.
  75. elsif ($code == 99) {
  76. $self->error("User $self->{user}->{name} cannot approve report, must be a different user.");
  77. }
  78. }
  79. sub correct_entry {
  80. my $self = shift @_;
  81. my $report_id = shift @_;
  82. my $scn = shift @_;
  83. my $new_amount = shift @_;
  84. # correct should return the new code value - whether or not it actually "matches"
  85. my $code = $self->correct($report_id, $scn, $new_amount);
  86. return $code[0]->{'correct'};
  87. }
  88. 1;