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

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



Revision: 2727
          http://ledger-smb.svn.sourceforge.net/ledger-smb/?rev=2727&view=rev
Author:   einhverfr
Date:     2009-07-15 00:27:26 +0000 (Wed, 15 Jul 2009)

Log Message:
-----------
Yearend moved to new structure

Modified Paths:
--------------
    trunk/LedgerSMB/DBObject/EOY.pm
    trunk/UI/accounts/yearend.html
    trunk/scripts/account.pl
    trunk/sql/Pg-database.sql
    trunk/sql/modules/EndOfYear.sql

Modified: trunk/LedgerSMB/DBObject/EOY.pm
===================================================================
--- trunk/LedgerSMB/DBObject/EOY.pm	2009-07-14 23:52:46 UTC (rev 2726)
+++ trunk/LedgerSMB/DBObject/EOY.pm	2009-07-15 00:27:26 UTC (rev 2727)
@@ -69,7 +69,7 @@
 
 sub close_books {
     my ($self) = @_;
-   $self->exec_method(funcname => 'eoy_reopen_books');
+   $self->exec_method(funcname => 'eoy_close_books');
    $self->{dbh}->commit;
 }
 
@@ -83,7 +83,7 @@
 
 sub list_earnings_accounts{
     my ($self) = @_;
-    my @results = $self->exec_method(funcname => 'earnings_accounts');
+    my @results = $self->exec_method(funcname => 'eoy_earnings_accounts');
     $self->{earnings_accounts} = ..hidden..;
     return @results;
 }

Modified: trunk/UI/accounts/yearend.html
===================================================================
--- trunk/UI/accounts/yearend.html	2009-07-14 23:52:46 UTC (rev 2726)
+++ trunk/UI/accounts/yearend.html	2009-07-15 00:27:26 UTC (rev 2727)
@@ -35,7 +35,14 @@
         </tr>
         <tr>
           <th align="right"><?lsmb text('Retained Earnings') ?></th>
-          <td><?lsmb PROCESS select element_data=accounts -?></td>
+          <?lsmb FOREACH opt = earnings_accounts; 
+                     opt.text = opt.accno _ '--' _ opt.description;
+		END -?>
+          <td><?lsmb PROCESS select element_data={
+                     name = "retention_acc_id"
+                     options = earnings_accounts
+                     value_attr = "id"
+                } -?></td>
         </tr>
       </table>
     </td>
@@ -48,7 +55,13 @@
 		name = hidden,
 		value = hiddens.item(hidden)
 		}; END ?>
-<?lsmb FOREACH button IN buttons; PROCESS button element_data=button; END ?>
+<?lsmb PROCESS button element_data = {
+	name = "action"
+	type = "submit"
+	class = "submit"
+	value = "post_yearend"
+	text = text('Post Yearend') #'
+} ?>
 </form>
 </body>
 </html>

Modified: trunk/scripts/account.pl
===================================================================
--- trunk/scripts/account.pl	2009-07-14 23:52:46 UTC (rev 2726)
+++ trunk/scripts/account.pl	2009-07-15 00:27:26 UTC (rev 2727)
@@ -102,13 +102,13 @@
     my ($request) = @_;
     my $eoy =  LedgerSMB::DBObject::EOY->new(base => $request);
     $eoy->list_earnings_accounts;
-    $eoy->user = $request->{_user};    
+    $eoy->{user} = $request->{_user};    
     my $template = LedgerSMB::Template->new_UI(
-        user => $form->{_user}, 
-        locale => $locale,
+        user => $request->{_user}, 
+        locale => $request->{_locale},
         template => 'accounts/yearend'
     );
-    $temlate->render($eoy);
+    $template->render($eoy);
 }
 
 sub post_yearend {
@@ -117,11 +117,11 @@
     my $eoy =  LedgerSMB::DBObject::EOY->new(base => $request);
     $eoy->close_books;
     my $template = LedgerSMB::Template->new_UI(
-        user => $form->{_user}, 
-        locale => $locale,
+        user => $request->{_user},
+        locale => $request->{_locale},
         template => 'accounts/yearend_complete'
     );
-    $temlate->render($eoy);
+    $template->render($eoy);
     
 }
 

Modified: trunk/sql/Pg-database.sql
===================================================================
--- trunk/sql/Pg-database.sql	2009-07-14 23:52:46 UTC (rev 2726)
+++ trunk/sql/Pg-database.sql	2009-07-15 00:27:26 UTC (rev 2727)
@@ -35,7 +35,7 @@
   account_id int not null references account(id), 
   amount numeric not null,
   id serial not null unique,
-  primary key (end_date, chart_id)
+  primary key (end_date, account_id)
 );
 
 CREATE TABLE account_link (

Modified: trunk/sql/modules/EndOfYear.sql
===================================================================
--- trunk/sql/modules/EndOfYear.sql	2009-07-14 23:52:46 UTC (rev 2726)
+++ trunk/sql/modules/EndOfYear.sql	2009-07-15 00:27:26 UTC (rev 2727)
@@ -4,16 +4,17 @@
 DECLARE ret_val int;
 	approval_check int;
 BEGIN
-	IF end_date > now()::date THEN
+	IF in_end_date > now()::date THEN
 		RAISE EXCEPTION 'Invalid date:  Must be earlier than present';
 	END IF;
 
 	SELECT count(*) into approval_check
 	FROM acc_trans ac
 	JOIN (
-		select id, approved FROM ar UNION
-		SELECT id, approved FROM gl UNION
-		SELECT id, approved FROM ap) gl ON (gl.id = ac.trans_id)
+		select id, approved, transdate FROM ar UNION
+		SELECT id, approved, transdate FROM gl UNION
+		SELECT id, approved, transdate FROM ap
+	) gl ON (gl.id = ac.trans_id)
 	WHERE (ac.approved IS NOT TRUE AND ac.transdate <= in_end_date) 
 		OR (gl.approved IS NOT TRUE AND gl.transdate <= in_end_date);
 
@@ -28,9 +29,10 @@
 		select account_id, end_date, amount from account_checkpoint
 		WHERE end_date = (select max(end_date) from account_checkpoint
 				where end_date < in_end_date)
-		) cp on (a.chrt_id = cp.account_id)
+		) cp on (a.chart_id = cp.account_id)
 	WHERE a.transdate <= in_end_date 
-		AND a.transdate > coalesce(cp.end_date, a.transdate);
+		AND a.transdate > coalesce(cp.end_date, a.transdate)
+	group by a.chart_id, cp.amount;
 
 	SELECT count(*) INTO ret_val FROM account_checkpoint 
 	where end_date = in_end_date;
@@ -49,7 +51,7 @@
 	INSERT INTO gl (transdate, reference, description, approved)
 	VALUES (in_end_date, in_reference, in_description, true);
 
-	INSERT INTO yearend (id, transdate) values (currval('id'), in_end_date);
+	INSERT INTO yearend (trans_id, transdate) values (currval('id'), in_end_date);
 	INSERT INTO acc_trans (transdate, chart_id, trans_id, amount)
 	SELECT in_end_date, a.chart_id, currval('id'),
 		(sum(a.amount) + coalesce(cp.amount, 0)) * -1
@@ -58,11 +60,12 @@
 		select account_id, end_date, amount from account_checkpoint
 		WHERE end_date = (select max(end_date) from account_checkpoint
 				where end_date < in_end_date)
-		) cp on (a.chrt_id = cp.account_id)
+		) cp on (a.chart_id = cp.account_id)
 	JOIN account acc ON (acc.id = a.chart_id)
 	WHERE a.transdate <= in_end_date 
 		AND a.transdate > coalesce(cp.end_date, a.transdate)
-		AND acc.category IN ('I', 'E');
+		AND acc.category IN ('I', 'E')
+	GROUP BY a.chart_id, cp.amount;
 
 	INSERT INTO acc_trans (transdate, trans_id, chart_id, amount)
 	SELECT in_end_date, currval('id'), in_retention_acc_id, 
@@ -78,12 +81,13 @@
 $$ language plpgsql;
 
 CREATE OR REPLACE FUNCTION eoy_close_books
-(in_end_date date, in_reference text, in_description text)
+(in_end_date date, in_reference text, in_description text, 
+in_retention_acc_id int)
 RETURNS bool AS
 $$
 BEGIN
-	IF eoy_zero_accounts(in_end_date, in_reference, in_description) > 0 THEN
-		select eoy_create_checkpoints(in_end_date);
+	IF eoy_zero_accounts(in_end_date, in_reference, in_description, in_retention_acc_id) > 0 THEN
+		PERFORM eoy_create_checkpoint(in_end_date);
 		RETURN TRUE;
 	ELSE
 		RETURN FALSE;
@@ -95,7 +99,7 @@
 RETURNS bool AS
 $$
 BEGIN
-	SELECT count(*) FROM account_checkpoint WHERE end_date = in_end_date;
+	PERFORM count(*) FROM account_checkpoint WHERE end_date = in_end_date;
 
 	IF NOT FOUND THEN
 		RETURN FALSE;
@@ -103,20 +107,20 @@
 
 	DELETE FROM account_checkpoint WHERE end_date = in_end_date;
 
-	SELECT count(*) FROM yearend 
+	PERFORM count(*) FROM yearend 
 	WHERE transdate = in_end_date and reversed is not true;
 
 	IF FOUND THEN
 		INSERT INTO gl (reference, description, approved)
-		SELECT 'Reversing ' || reverence, 'Reversing ' || description,
+		SELECT 'Reversing ' || reference, 'Reversing ' || description,
 			true
-		FROM gl WHERE id = (select id from yearend 
+		FROM gl WHERE id = (select trans_id from yearend 
 			where transdate = in_end_date and reversed is not true);
 
 		INSERT INTO acc_trans (chart_id, amount, transdate, trans_id,
 			approved)
 		SELECT chart_id, amount * -1, currval('id'), true
-		FROM acc_trans where trans_id = (select id from yearend
+		FROM acc_trans where trans_id = (select trans_id from yearend
 			where transdate = in_end_date and reversed is not true);
 
 		UPDATE yearend SET reversed = true where transdate = in_end_date


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