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

SF.net SVN: ledger-smb:[5665] trunk/sql



Revision: 5665
          http://ledger-smb.svn.sourceforge.net/ledger-smb/?rev=5665&view=rev
Author:   einhverfr
Date:     2013-02-15 08:44:12 +0000 (Fri, 15 Feb 2013)
Log Message:
-----------
More recurring transaction logic

Modified Paths:
--------------
    trunk/sql/Pg-database.sql
    trunk/sql/modules/Transaction_Templates.sql

Modified: trunk/sql/Pg-database.sql
===================================================================
--- trunk/sql/Pg-database.sql	2013-02-15 07:03:05 UTC (rev 5664)
+++ trunk/sql/Pg-database.sql	2013-02-15 08:44:12 UTC (rev 5665)
@@ -2225,8 +2225,7 @@
   startdate date,
   nextdate date,
   enddate date,
-  repeat int2,
-  unit varchar(6),
+  recurring_interval interval, 
   howmany int,
   payment bool default 'f'
 );

Modified: trunk/sql/modules/Transaction_Templates.sql
===================================================================
--- trunk/sql/modules/Transaction_Templates.sql	2013-02-15 07:03:05 UTC (rev 5664)
+++ trunk/sql/modules/Transaction_Templates.sql	2013-02-15 08:44:12 UTC (rev 5665)
@@ -123,7 +123,10 @@
 			(in_meta_number is null 
 				or eca.meta_number = in_meta_number) and
 			(in_entity_class is null
-				or eca.entity_class = in_entity_class)
+				or eca.entity_class = in_entity_class) AND
+                        (in_recurring IS NOT TRUE OR
+                                coalesce(r.startdate, r.nextdate) <= now()::date
+                        )
 	LOOP
 		RETURN NEXT retval;
 	END LOOP;
@@ -153,7 +156,7 @@
 $$
 delete from recurringprint where id = $5;
 delete from recurring where id = $5;
-insert into recurring (id, reference, startdate, interval, howmany)
+insert into recurring (id, reference, startdate, recurring_interval, howmany)
 values ($5, $1, $2, $3, $4);
 $$;
 
@@ -165,4 +168,15 @@
 values ($1, $2, 'PDF', $3);
 $$;
 
+CREATE OR REPLACE FUNCTION journal__increment_recurring
+(in_id int, in_transdate date)
+RETURNS recurring LANGUAGE SQL AS
+$$
+UPDATE recurring
+   SET howmany = howmany - 1,
+       nextdate = $2::timestamp + recurring_interval
+ WHERE id = $1 AND howmany > 0
+RETURNING *;
+$$;
+
 COMMIT;

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