[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

SF.net SVN: ledger-smb:[2530] trunk



Revision: 2530
          http://ledger-smb.svn.sourceforge.net/ledger-smb/?rev=2530&view=rev
Author:   einhverfr
Date:     2009-03-25 19:49:27 +0000 (Wed, 25 Mar 2009)

Log Message:
-----------
Correcting pg-database to remove reconciliation references

Modified Paths:
--------------
    trunk/LedgerSMB/DBObject/Reconciliation.pm
    trunk/scripts/recon.pl
    trunk/sql/Pg-database.sql
    trunk/sql/modules/Reconciliation.sql

Modified: trunk/LedgerSMB/DBObject/Reconciliation.pm
===================================================================
--- trunk/LedgerSMB/DBObject/Reconciliation.pm	2009-03-25 00:29:26 UTC (rev 2529)
+++ trunk/LedgerSMB/DBObject/Reconciliation.pm	2009-03-25 19:49:27 UTC (rev 2530)
@@ -179,6 +179,50 @@
     return ($report_id, $entries); # returns the report ID.
 }
 
+=pod
+
+=over
+
+=item delete ($self, $report_id)
+
+Requires report_id
+
+Deletes a report based on the report id.
+Stored procedure returns true if deleted, false if not deleted/could not be 
+found, and raises EXCEPTION on report already approved.
+
+=back
+
+=cut
+
+sub delete_report {
+    
+    my $self = shift @_;
+    
+    my $report_id = shift @_;
+    
+    my $bool = $self->exec_method(funcname=>'reconciliation__delete_report',
+                                  args=>[$report_id]);
+                                  
+    if ($bool) {
+        $self->{dbh}->commit();
+    }
+    else{
+        $err = $self->{dbh}->errstr();
+        $self->{dbh}->rollback();
+        if ($err) {
+            # It's an exception.
+            $self->error("Report delete failed due to previous report submission or approval.");
+        }
+        else {
+            
+            # It's due to a non-existant report
+            $self->error("Cannot delete non-existant report.");
+        }
+    }
+    return $bool;
+}
+
 sub add_entries {
     my $self = shift;
     my $entries = $self->{import_entries};

Modified: trunk/scripts/recon.pl
===================================================================
--- trunk/scripts/recon.pl	2009-03-25 00:29:26 UTC (rev 2529)
+++ trunk/scripts/recon.pl	2009-03-25 19:49:27 UTC (rev 2530)
@@ -209,9 +209,7 @@
 sub search {
     my ($request,$type) = @_;
     
-
-        
-        my $recon = LedgerSMB::DBObject::Reconciliation->new(base=>$request, copy=>'all');
+    my $recon = LedgerSMB::DBObject::Reconciliation->new(base=>$request, copy=>'all');
 	if (!$recon->{hide_status}){
             $recon->{show_approved} = 1;        
             $recon->{show_submitted} = 1;        
@@ -318,6 +316,7 @@
     
 }
 
+
 =pod
 
 =over
@@ -499,6 +498,55 @@
 
 =over
 
+=item delete_report ($request)
+
+Requires report_id
+
+Deletes the given report_id, and marks whom it was deleted by.
+Will fail if the report does not exist, or if the report has already been
+approved.
+
+TO BE DETERMINED:
+Whether or not a delete is permissable by the same user that created the 
+report.
+=back
+
+=cut
+
+sub delete_report {
+    
+    
+    my ($request) = @_;
+    
+    my $recon = LedgerSMB::DBObject::Reconciliation->new(base=>$request, copy=>'all');
+    
+    # report_id should be set in the request object. It should be an int, and 
+    # it should correspond to one of the reports.
+    
+    if ($request->type() eq "POST") {
+        
+        $resp = $recon->delete_report($request->{report_id});
+        
+        if ($resp) {
+            
+            # This is good; we have a true-like response.
+            # Drop the report_id and send the request to search()
+            delete($request->{report_id});
+            return search($request);
+        }
+        return undef;
+    }
+    else {
+        # this is wrong - We should never get a GET request here. This should 
+        # throw an error? Or redirect back to the display page?
+        return undef;
+    }
+}
+
+=pod
+
+=over
+
 =item approve ($self, $request, $user)
 
 Requires report_id

Modified: trunk/sql/Pg-database.sql
===================================================================
--- trunk/sql/Pg-database.sql	2009-03-25 00:29:26 UTC (rev 2529)
+++ trunk/sql/Pg-database.sql	2009-03-25 19:49:27 UTC (rev 2530)
@@ -2131,10 +2131,10 @@
 43	module	rp.pl	103
 43	action	report	104
 43	report	payments	105
-45	module	rc.pl	106
-45	action	reconciliation	107
-44	module	rc.pl	108
-44	action	reconciliation	109
+45	module	recon.pl	106
+45	action	new_report	107
+44	module	recon.pl	108
+44	action	search	109
 44	report	1	110
 46	menu	1	111
 47	menu	1	112

Modified: trunk/sql/modules/Reconciliation.sql
===================================================================
--- trunk/sql/modules/Reconciliation.sql	2009-03-25 00:29:26 UTC (rev 2529)
+++ trunk/sql/modules/Reconciliation.sql	2009-03-25 19:49:27 UTC (rev 2530)
@@ -7,7 +7,10 @@
     end_date date not null default now(),
     updated timestamp not null default now(),
     entered_by int not null default person__get_my_entity_id() references entity(id),
-    entered_username text not null default SESSION_USER
+    entered_username text not null default SESSION_USER,
+    deleted boolean not null default 'f'::boolean,
+    deleted_by int not null default person__get_my_entity_id() references entity(id),
+    CHECK (deleted is not true or approved is not true)
 );
 
 create table cr_approval (
@@ -64,6 +67,46 @@
 END;
 $$ LANGUAGE PLPGSQL;
 
+CREATE OR REPLACE FUNCTION reconciliation__delete_report(in_report_id int)
+RETURN bool AS 
+$$
+    DECLARE
+    BEGIN
+        PERFORM id FROM cr_report WHERE id = in_report_id;
+        
+        IF NOT FOUND THEN
+            RAISE NOTICE 'reconciliation__delete_report(): Cannot find specified report.';
+            return FOUND;
+        END IF;
+        
+        -- We found the entry. Update it.
+        
+        PERFORM id FROM cr_report WHERE id = in_report_id AND approved = TRUE;
+        
+        IF FOUND THEN
+            RAISE EXCEPTION 'reconcilation__delete_report(): report % is approved; cannot delete.', in_report_id;
+        END IF;
+        
+        PERFORM id 
+           FROM cr_report 
+          WHERE id = in_report_id 
+            AND submitted = TRUE
+            AND entered_by = people__get_my_entity_id();
+        
+        IF FOUND THEN
+            -- Creators cannot delete their own reports if they've been submitted.
+            RAISE EXCEPTION 'reconciliation__delete_report(): creators cannot delete their own report after submission. %', in_report_id;
+        END IF;
+        
+        UPDATE cr_report
+           SET deleted = TRUE,
+               deleted_by = people__get_my_entity_id()
+         WHERE id = in_report_id;
+         
+        return TRUE;
+    END;
+$$ language plpgsql;
+
 CREATE OR REPLACE FUNCTION reconciliation__get_cleared_balance(in_chart_id int)
 RETURNS numeric AS
 $$
@@ -386,7 +429,8 @@
 				OR in_balance_to >= their_total) AND
 			(in_chart_id IS NULL OR in_chart_id = chart_id) AND
 			(in_submitted IS NULL or in_submitted = submitted) AND
-			(in_approved IS NULL OR in_approved = approved)
+			(in_approved IS NULL OR in_approved = approved) AND
+			(r.deleted IS FALSE)
 		ORDER BY c.accno, end_date, their_total
 	LOOP
 		RETURN NEXT report;


This was sent by the SourceForge.net collaborative development platform, the world's largest Open Source development site.