summaryrefslogtreecommitdiff
path: root/LedgerSMB/Reconciliation.pm
blob: f12251e5c3485dc24ff86b09626b7d8cf36e5182 (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. =back
  43. =head1 Copyright (C) 2007, The LedgerSMB core team.
  44. This file is licensed under the Gnu General Public License version 2, or at your
  45. option any later version. A copy of the license should have been included with
  46. your software.
  47. =cut
  48. package LedgerSMB::DBObject::Reconciliation;
  49. use base qw(LedgerSMB);
  50. use LedgerSMB::DBObject;
  51. # don't need new
  52. #sub reconcile {
  53. sub new_report {
  54. my $self = shift @_;
  55. my $total = shift @_;
  56. my $month = shift @_;
  57. my $entries = shift @_; # expects an arrayref.
  58. # Total is in here somewhere, too
  59. my $report_id = $self->new_report_id()[0]; # gives us a report ID to insert with.
  60. # Now that we have this, we need to create the internal report representation.
  61. # Ideally, we OUGHT to not return anything here, save the report number.
  62. unshift @{$entries}, {
  63. scn => -1,
  64. balance=> $total,
  65. old_balance=> $self->current_balance,
  66. date=>$month
  67. };
  68. for my $entry (@{$entries}) {
  69. # Codes:
  70. # 0 is success
  71. # 1 is found, but mismatch
  72. # 2 is not found
  73. $entry{report_id} = $report_id;
  74. $entry{code} = $self->add_entry( $entry );
  75. }
  76. $self->pending_transactions($report_id, $date);
  77. return $entries; # returns the report ID.
  78. }
  79. sub approve {
  80. my $self = shift @_;
  81. # the user should be embedded into the $self object.
  82. my $report_id = shift @_;
  83. my $code = $self->report_approve($report_id); # user
  84. if ($code == 0) { # no problem.
  85. return $code;
  86. }
  87. # this is destined to change as we figure out the Error system.
  88. elsif ($code == 99) {
  89. $self->error("User $self->{user}->{name} cannot approve report, must be a different user.");
  90. }
  91. }
  92. sub correct_entry {
  93. my $self = shift @_;
  94. my $report_id = $self->{report_id}; # shift @_;
  95. my $scn = $self->{id}; #shift @_;
  96. my $new_amount = $self->{new_amount}; #shift @_;
  97. # correct should return the new code value - whether or not it actually "matches"
  98. my $code = $self->correct($report_id, $scn, $new_amount);
  99. return $code[0]->{'correct'};
  100. }
  101. sub get_report {
  102. my $self = shift @_;
  103. return $self->report($self->{report_id});
  104. }
  105. 1;