From 170174b76910a2916db1a9208597a428ebb9b40d Mon Sep 17 00:00:00 2001 From: einhverfr Date: Fri, 22 Jun 2007 05:01:13 +0000 Subject: Added version of Aurynn's reconciliation logic git-svn-id: https://ledger-smb.svn.sourceforge.net/svnroot/ledger-smb/trunk@1302 4979c152-3d1c-0410-bac9-87ea11338e46 --- LedgerSMB/Reconciliation.pm | 24 +++++++++ Reconciliation.pl | 3 ++ UI/approved.html | 28 +++++++++++ UI/correct.html | Bin 0 -> 72 bytes UI/corrections.html | 39 +++++++++++++++ UI/get_password.html | 45 +++++++++++++++++ UI/report.html | 52 ++++++++++++++++++++ UI/voucher.html | 35 ++++++++++++++ scripts/Reconciliation.pl | 110 +++++++++++++++++++++++++++++++++++++++--- sql/modules/Reconciliaton.sql | 51 ++++++++++++++++++-- 10 files changed, 374 insertions(+), 13 deletions(-) create mode 100644 Reconciliation.pl create mode 100644 UI/approved.html create mode 100644 UI/correct.html create mode 100644 UI/corrections.html create mode 100644 UI/get_password.html create mode 100644 UI/report.html create mode 100644 UI/voucher.html diff --git a/LedgerSMB/Reconciliation.pm b/LedgerSMB/Reconciliation.pm index f12251e5..6dca96d2 100644 --- a/LedgerSMB/Reconciliation.pm +++ b/LedgerSMB/Reconciliation.pm @@ -65,6 +65,16 @@ arrayref of entries in the table for the given report_id. Returns undef in the event of no records found. +=item get_corrections($self, $report_id, $entry_id) + +Returns the corrections made for the selected report and entry. +Returns undef in the event of no corrections found. + +=item entry ($self,$report_id,$entry_id) + +Returns a single entry from the pending reports table, either cleared or +uncleared. + =back =head1 Copyright (C) 2007, The LedgerSMB core team. @@ -155,4 +165,18 @@ sub get_report { return $self->report($self->{report_id}); } +sub get_corrections { + + my $self = shift @_; + + return $self->corrections($self->{report_id},$self->{entry_id}); +} + +sub entry { + + my $self = shift @_; + + return $self->single_entry($self->{report_id},$self->{entry_id}); +} + 1; \ No newline at end of file diff --git a/Reconciliation.pl b/Reconciliation.pl new file mode 100644 index 00000000..76f60115 --- /dev/null +++ b/Reconciliation.pl @@ -0,0 +1,3 @@ +#!/usr/bin/perl + +require "lsmb-request.pl"; diff --git a/UI/approved.html b/UI/approved.html new file mode 100644 index 00000000..16afc6cc --- /dev/null +++ b/UI/approved.html @@ -0,0 +1,28 @@ +
+
+ Bank statement for on has been approved! +
+
+ + + + + + + + + + + + + + + + + + + + + + +
Clear dateTransaction TypeOur BalanceTheir BalanceError CorrectionsError Code
\ No newline at end of file diff --git a/UI/correct.html b/UI/correct.html new file mode 100644 index 00000000..e9cb708a Binary files /dev/null and b/UI/correct.html differ diff --git a/UI/corrections.html b/UI/corrections.html new file mode 100644 index 00000000..bdf7424a --- /dev/null +++ b/UI/corrections.html @@ -0,0 +1,39 @@ + + + + + + + + + + + + + +
Clear dateTransaction TypeOur BalanceTheir Balance
+ + +Corrections: + + + + + + + +
+
+ at +
+ +
+
+
+ + +
+ No corrections found. +
+ + \ No newline at end of file diff --git a/UI/get_password.html b/UI/get_password.html new file mode 100644 index 00000000..4f3bfc9a --- /dev/null +++ b/UI/get_password.html @@ -0,0 +1,45 @@ + + + + <?lsmb titlebar ?> + + + + + + + + + + + + +

+ +

+ +
+ +
+ + + + +
+ + + +
+ + + diff --git a/UI/report.html b/UI/report.html new file mode 100644 index 00000000..cd6c8972 --- /dev/null +++ b/UI/report.html @@ -0,0 +1,52 @@ +
Reconciliation Report for [% total.account %] for the month of [%total.month%]
+ +
+ [%IF total.errorcode != 0 %] +
+ [%ELSE%] +
+ [%END%] + Our Balance: total.our_balance | Bank Balance: total.their_balance +
+
+ +
Report generated by [% total.user %]
+ +[% if recon.error %] +
+ [% recon.error %] +
+[%end%] + + + + + + + + + + + + + [% FOREACH row = records %] + [%IF row.errorcode != 0 %] + + [% ELSIF row.id = corrected %] + + [%ELSE%] + + [%END%] + + + + + + [% IF row.errorcode > 0 %] + + [%ELSE%] + + [%END%] + + [% END %] +
Clear dateTransaction TypeOur BalanceTheir BalanceError CorrectionsError Code
[% row.clear_time %][% row.transaction_type %] [% row.our_balance %][% row.their_balance%][% row.corrections %][% row.errorcode %] View Corrections 0
\ No newline at end of file diff --git a/UI/voucher.html b/UI/voucher.html new file mode 100644 index 00000000..4cf6bf29 --- /dev/null +++ b/UI/voucher.html @@ -0,0 +1,35 @@ + + + + <?lsmb titlebar ?> + + + + + + + + + + + +
+
+ Date From: + +
+
+ Date To: + +
+
+ And Date: + + + +
+ + + diff --git a/scripts/Reconciliation.pl b/scripts/Reconciliation.pl index 189eecb4..8826f037 100644 --- a/scripts/Reconciliation.pl +++ b/scripts/Reconciliation.pl @@ -2,8 +2,21 @@ =head1 NAME +LedgerSMB::Scripts::Reconciliation - LedgerSMB class defining the Controller +functions, template instantiation and rendering. + +=head1 SYOPSIS + +This module acts as the UI controller class for Reconciliation. It controls +interfacing with the Core Logic and database layers. + +=head1 METHODS + =cut +# NOTE: This is a first draft modification to use the current parameter type. +# It will certainly need some fine tuning on my part. Chris + package LedgerSMB::Scripts::Reconciliation; use LedgerSMB::Template; @@ -24,7 +37,7 @@ report_id. =cut sub display_report { - + my ($class, $request) = @_; my $recon = LedgerSMB::Employee->new(base => $request, copy => 'all'); my $template = LedgerSMB::Template->new( user=>$user, template => "reconciliation_report.html", language => $user->{language}, @@ -36,6 +49,7 @@ sub display_report { } sub search { + my ($class, $request) = @_; my $search = LedgerSMB::Employee->new(base => $request, copy => 'all'); $employee->{search_results} = $employee->search(); my $template = LedgerSMB::Template->new( user => $user, @@ -61,14 +75,38 @@ This is to prevent arbitrary editing of the database by unscrupulous users. =cut sub correct { + my ($class, $request) = @_; my $recon = LedgerSMB::DBObject::Reconciliation->new(base => $request, copy => 'all'); - - my $template = LedgerSMB::Template->new( user => $user, - template => 'reconciliation_correct.html', language => $user->{language}, - format => 'html'); + $recon->correct_entry(); - $template->render($recon->get_report()); + + if ($recon->{corrected_id}) { + + my $template = LedgerSMB::Template->new( user => $user, + template => 'reconciliation_report.html', language => $user->{language}, + format => 'html'); + + $template->render( { + corrected=> $recon->{corrected_id}, + report=> $recon->get_report(), + total=> $recon->get_total() + } ); + } + else { + + # indicate we were unable to correct this entry, with the error code + # spat back to us by the DB. + my $template = LedgerSMB::Template->new( user => $user, + template => 'reconciliation_report.html', language => $user->{language}, + format => 'html'); + + $template->render( { + recon => $recon, + report=> $recon->get_report(), + total=> $recon->get_total() + } ); + } } =pod @@ -88,6 +126,7 @@ it has been created. =cut sub new_report { + my ($class, $request) = @_; # how are we going to allow this to be created? Grr. # probably select a list of statements that are available to build # reconciliation reports with. @@ -116,7 +155,7 @@ sub new_report { =over -=item ($self, $request, $user) +=item approve ($self, $request, $user) Requires report_id @@ -131,6 +170,12 @@ the uncorrected entries. =cut sub approve { + my ($class, $request) = @_; + + # Approve will also display the report in a blurred/opaqued out version, + # with the controls removed/disabled, so that we know that it has in fact + # been cleared. This will also provide for return-home links, auditing, + # etc. my $recon = LedgerSMB::DBObject::Reconciliation->new(base => request, copy=> 'all'); @@ -148,11 +193,60 @@ sub approve { template => 'reconciliation_report.html', language => $user->{language}, format => 'html'); $report = $recon->get_report(); + ## relies on foreknowledge in the template ## we basically tell the template, we can't approve, this uncorrected ## error is preventing us. + $report->{ error } = { approval => 1 }; } $template->render($report); } -1; \ No newline at end of file + +=pod + +=over + +=item corrections ($self, $request, $user) + +Requires report_id and entry_id. + +Loads the selected entry id and all corrections associated with it. If there +aren't any corrections, it will display "no corrections found". +=back + +=cut + +sub corrections { + my ($class, $request) = @_; + + # Load the corrections for a given report & entry id. + # possibly should use a "micro" popup window? + + my $recon = LedgerSMB::DBObject::Reconciliation->new(base => request, copy=> 'all'); + + my $template; + + $template = LedgerSMB::Template->new( user => $user, + template => 'reconciliation_corrected.html', language => $user->{language}, + format => 'html'); + + return $template->render( + { + corrections=>$recon->get_corrections(), + entry=>$recon->entry($self->{report_id}, $self->{entry_id}) + } + ); +} + +1; + +=pod + +=head1 Copyright (C) 2007, The LedgerSMB core team. + +This file is licensed under the Gnu General Public License version 2, or at your +option any later version. A copy of the license should have been included with +your software. + +=cut diff --git a/sql/modules/Reconciliaton.sql b/sql/modules/Reconciliaton.sql index 2700a2fb..1dfc7d7e 100644 --- a/sql/modules/Reconciliaton.sql +++ b/sql/modules/Reconciliaton.sql @@ -13,6 +13,15 @@ CREATE TABLE pending_reports ( overlook boolean not null default 'f' ); +CREATE TABLE report_corrections ( + id serial primary key not null, + correction_id int not null default 1, + entry references pending_reports(id) not null, + user text not null, + reason text not null, + insert_time timestamptz not null default now() +); + -- to correct OUR wrong amount. CREATE OR REPLACE FUNCTION reconciliation_correct_ledger (in_report_id INT, in_id int, in_new_amount NUMERIC, reason TEXT) returns INT AS $$ @@ -371,14 +380,46 @@ CREATE OR REPLACE FUNCTION reconciliation_get_total (in_report_id INT) returns s AND scn = -1; IF NOT FOUND THEN -- I think this is a fairly major error condition - - RAISE EXCEPTION "No Bank Total found." - + RAISE EXCEPTION "No Bank Total found."; ELSE - return row; - END IF; END; $$ language 'plpgsql'; + +CREATE OR REPLACE FUNCTION reconciliation_corrections (in_report_id INT, in_id INT) returns setof report_corrections AS $$ + + DECLARE + corr report_corrections; + BEGIN + + SELECT INTO corr FROM report_corrections WHERE report_id = in_report_id AND id = in_id LIMIT 1; + IF NOT FOUND THEN + RAISE EXCEPTION "No corrections for selected entry."; + ELSE + FOR corr IN select * from report_corrections WHERE report_id = in_report_id AND id = in_id LOOP + RETURN NEXT corr; + END LOOP; + END IF; + END; + +$$ language 'plplsql'; + +CREATE OR REPLACE FUNCTION reconciliation_single_entry (in_report_id INT, in_id INT) returns setof pending_reports AS + + DECLARE + row pending_reports; + BEGIN + + SELECT INTO row FROM pending_reports WHERE report_id = in_report_id and id = in_id LIMIT 1; + -- if there's more than one, that's a Bad Thing + + IF NOT FOUND THEN + RAISE EXCEPTION "Could not find selected report entry"; + ELSE + RETURN row; + END IF; + END; + +$$ language 'plpgsql'; \ No newline at end of file -- cgit v1.2.3