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

SF.net SVN: ledger-smb:[5754] branches/1.3



Revision: 5754
          http://sourceforge.net/p/ledger-smb/code/5754
Author:   einhverfr
Date:     2013-05-10 13:13:04 +0000 (Fri, 10 May 2013)
Log Message:
-----------
Reopen books merged from 1.4 codebase and tested

Modified Paths:
--------------
    branches/1.3/Changelog
    branches/1.3/LedgerSMB/DBObject/EOY.pm
    branches/1.3/UI/accounts/yearend.html
    branches/1.3/scripts/account.pl
    branches/1.3/sql/modules/EndOfYear.sql

Modified: branches/1.3/Changelog
===================================================================
--- branches/1.3/Changelog	2013-05-10 12:36:59 UTC (rev 5753)
+++ branches/1.3/Changelog	2013-05-10 13:13:04 UTC (rev 5754)
@@ -9,6 +9,7 @@
 * Fixed transaction list empty if searched by creditor name (Nick P, 806)
 * Fixed cash transfer enforces ticked 'FX' boxes (Nick P, 802)
 * Fixed extra newline-related errors in tex template engine (Chris T)
+* Reopen books now works again (Chris T, 792)
 
 Nick P is Nick Prater
 

Modified: branches/1.3/LedgerSMB/DBObject/EOY.pm
===================================================================
--- branches/1.3/LedgerSMB/DBObject/EOY.pm	2013-05-10 12:36:59 UTC (rev 5753)
+++ branches/1.3/LedgerSMB/DBObject/EOY.pm	2013-05-10 13:13:04 UTC (rev 5754)
@@ -50,17 +50,30 @@
 
 =item $eoy->reopen_books()
 
-This reverses any end of year transaction on $eoy->{end_date}, and deletes 
-checkpoints for that day.
+This reverses any end of year transaction on $eoy->{reopen_date}, and deletes 
+checkpoints later than that and creates a checkpoint for the prior day.
 
 =cut
 
 sub reopen_books {
     my ($self) = @_;
-   $self->exec_method(funcname => 'eoy_reopen_books');
+   $self->exec_method(funcname => 'eoy__reopen_books_at');
    $self->{dbh}->commit;
 }
 
+=item $eoy->latest_closing()
+
+Needs no properties set (other than internal private ones).  Retrieves the 
+latest closing date and returns it.
+
+=cut
+
+sub latest_closing {
+    my ($self) = @_;
+    my ($ref) = $self->exec_method(funcname => 'eoy__latest_checkpoint');
+    return $ref->{end_date};
+}
+
 =item $eoy->close_books()
 
 Requires all properies in BASIC PROPERTIES to be set.  This creates a gl 

Modified: branches/1.3/UI/accounts/yearend.html
===================================================================
--- branches/1.3/UI/accounts/yearend.html	2013-05-10 12:36:59 UTC (rev 5753)
+++ branches/1.3/UI/accounts/yearend.html	2013-05-10 13:13:04 UTC (rev 5754)
@@ -3,11 +3,11 @@
 <body>
 <form method="post" action="<?lsmb script ?>">
 <table width="100%">
-  <tr><th class="listtop"><?lsmb title ?></th></tr>
+  <tr><th class="listtop"><?lsmb text('Post Yearend') ?></th></tr>
   <tr><td> </td></tr>
   <tr>
     <td>
-      <table>
+      <table width="100%">
         <tr>
           <th align="right"><?lsmb text('Yearend') ?></th>
           <td><?lsmb PROCESS input element_data={
@@ -44,24 +44,50 @@
                      value_attr = "id"
                 } -?></td>
         </tr>
-      </table>
-    </td>
-  </tr>
-</table>
+<tr><td colspan="2">
 <hr size="3" noshade="noshade" />
 <?lsmb FOREACH hidden IN hiddens.keys;
 	PROCESS input element_data={
 		type = 'hidden',
 		name = hidden,
 		value = hiddens.item(hidden)
-		}; END ?>
+		}; END ?></td>
+</tr>
+<tr>
+<td align="right">
 <?lsmb PROCESS button element_data = {
 	name = "action"
 	type = "submit"
 	class = "submit"
 	value = "post_yearend"
 	text = text('Post Yearend') #'
-} ?>
+} ?></td></tr>
+<tr><th colspan="2" class="listtop"><?lsmb text('Re-open Books') ?></th></tr>
+<tr><th align="right"><?lsmb text('Books closed on') ?></th>
+    <td><?lsmb closed_date ?></td>
+<tr>
+          <th align="right"><?lsmb text('Re-Open As Of') ?></th>
+          <td><?lsmb PROCESS input element_data={
+            class = 'date',
+            name = 'reopen_date',
+            size = 11,
+            title = user.dateformat,
+            } -?></td></tr>
+<tr>
+<tr><td colspan="2">
+<hr size="3" noshade="noshade" /></td></tr>
+<td align="right">
+<?lsmb PROCESS button element_data = {
+	name = "action"
+	type = "submit"
+	class = "submit"
+	value = "reopen_books"
+	text = text('Reopen Books') #'
+} ?></td></tr>
+      </table>
+    </td>
+  </tr>
+</table>
 </form>
 </body>
 </html>

Modified: branches/1.3/scripts/account.pl
===================================================================
--- branches/1.3/scripts/account.pl	2013-05-10 12:36:59 UTC (rev 5753)
+++ branches/1.3/scripts/account.pl	2013-05-10 13:13:04 UTC (rev 5754)
@@ -1,5 +1,6 @@
 use Template;
 use LedgerSMB::DBObject::Account;
+use LedgerSMB::DBObject::EOY;
 package LedgerSMB::Scripts::account;
 use LedgerSMB::Log;
 use Data::Dumper;
@@ -176,10 +177,10 @@
 =cut
 
 sub yearend_info {
-    use LedgerSMB::DBObject::EOY;
     my ($request) = @_;
     my $eoy =  LedgerSMB::DBObject::EOY->new(base => $request);
     $eoy->list_earnings_accounts;
+    $eoy->{closed_date} = $eoy->latest_closing;
     $eoy->{user} = $request->{_user};    
     my $template = LedgerSMB::Template->new_UI(
         user => $request->{_user}, 
@@ -202,7 +203,6 @@
 =cut
 
 sub post_yearend {
-    use LedgerSMB::DBObject::EOY;
     my ($request) = @_;
     my $eoy =  LedgerSMB::DBObject::EOY->new(base => $request);
     $eoy->close_books;
@@ -215,6 +215,20 @@
     
 }
 
+=item reopen_books
+
+This reopens books as of $request->{reopen_date}
+
+=cut
+
+sub reopen_books {
+    my ($request) = @_;
+    my $eoy =  LedgerSMB::DBObject::EOY->new(base => $request);
+    $eoy->reopen_books;
+    delete $request->{reopen_date};
+    yearend_info($request);
+}
+
 =back
 
 =head1 COPYRIGHT

Modified: branches/1.3/sql/modules/EndOfYear.sql
===================================================================
--- branches/1.3/sql/modules/EndOfYear.sql	2013-05-10 12:36:59 UTC (rev 5753)
+++ branches/1.3/sql/modules/EndOfYear.sql	2013-05-10 13:13:04 UTC (rev 5754)
@@ -1,3 +1,30 @@
+CREATE OR REPLACE FUNCTION eoy__latest_checkpoint() RETURNS account_checkpoint
+LANGUAGE SQL AS
+$$
+   SELECT * FROM account_checkpoint ORDER BY end_date DESC LIMIT 1;
+$$;
+
+COMMENT ON FUNCTION eoy__latest_checkpoint() IS $$
+This returns a single checkpoint from the latest set.  Which account and info 
+is returned is non-determinative and so only the end date shoudl be relied on.
+$$;
+
+CREATE OR REPLACE FUNCTION eoy__reopen_books_at(in_reopen_date date) 
+RETURNS BOOL
+LANGUAGE SQL AS
+$$
+
+    SELECT eoy_reopen_books(end_date) 
+      FROM (SELECT end_date 
+              FROM account_checkpoint
+             WHERE end_date >= $1
+             GROUP BY end_date) eoy_dates
+  ORDER BY end_date;
+
+SELECT eoy_create_checkpoint($1 - 1) > 0;
+
+$$;
+
 CREATE OR REPLACE FUNCTION eoy_create_checkpoint(in_end_date date)
 RETURNS int AS
 $$

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