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

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



Revision: 4854
          http://ledger-smb.svn.sourceforge.net/ledger-smb/?rev=4854&view=rev
Author:   einhverfr
Date:     2012-06-07 02:03:22 +0000 (Thu, 07 Jun 2012)
Log Message:
-----------
Account deletion now works in 1.4

Modified Paths:
--------------
    trunk/LedgerSMB/DBObject/Report/COA.pm
    trunk/LedgerSMB/Scripts/journal.pm
    trunk/sql/modules/Account.sql

Modified: trunk/LedgerSMB/DBObject/Report/COA.pm
===================================================================
--- trunk/LedgerSMB/DBObject/Report/COA.pm	2012-06-06 10:57:05 UTC (rev 4853)
+++ trunk/LedgerSMB/DBObject/Report/COA.pm	2012-06-07 02:03:22 UTC (rev 4854)
@@ -121,7 +121,7 @@
      pwidth => '3', },
 
     {col_id => 'delete',
-       name => $locale->text('Cleared'),
+       name => $locale->text('Delete'),
        type => 'href',
   href_base => '',
      pwidth => '3', },
@@ -187,10 +187,11 @@
            $ct = 'A';
         }
         $r->{edit} = '['.$locale->text('Edit').']';
-        $r->{delete} = '['.$locale->text('Delete').']' if $r->{rowcount};
+        $r->{delete} = '['.$locale->text('Delete').']' 
+                  if !$r->{rowcount} and !$r->{is_heading};
         $r->{edit_href_suffix} = 'account.pl?action=edit&id='.$r->{id} . 
            "&charttype=$ct";
-        $r->{delete_href_suffix} = 'account.pl?action=delete&id='.$r->{id} .
+        $r->{delete_href_suffix} = 'journal.pl?action=delete_account&id='.$r->{id} .
            "&charttype=$ct";
         $r->{accno_href_suffix} = 
                 'reports.pl?action=start_report&module_name=gl&report_name=gl' .

Modified: trunk/LedgerSMB/Scripts/journal.pm
===================================================================
--- trunk/LedgerSMB/Scripts/journal.pm	2012-06-06 10:57:05 UTC (rev 4853)
+++ trunk/LedgerSMB/Scripts/journal.pm	2012-06-07 02:03:22 UTC (rev 4854)
@@ -80,6 +80,23 @@
     $report->render($request);
 }
 
+=item delete_account
+
+This deletes an account and returns to the chart of accounts screen.
+
+This is here rather than in LedgerSMB::Scripts::Account because the redirect
+occurs to here.
+
+=cut
+
+sub delete_account {
+    my ($request) = @_;
+    use LedgerSMB::DBObject::Account;
+    my $account =  LedgerSMB::DBObject::Account->new({base => $request});
+    $account->delete;
+    chart_of_accounts($request);
+}
+
 =item search
 
 Runs a search and displays results.

Modified: trunk/sql/modules/Account.sql
===================================================================
--- trunk/sql/modules/Account.sql	2012-06-06 10:57:05 UTC (rev 4853)
+++ trunk/sql/modules/Account.sql	2012-06-07 02:03:22 UTC (rev 4854)
@@ -165,6 +165,7 @@
 RETURNS BOOL AS
 $$
 BEGIN
+DELETE FROM account_link WHERE account_id = in_id;
 DELETE FROM account WHERE id = in_id;
 RETURN FOUND;
 END;
@@ -328,12 +329,13 @@
 $$
 
 WITH ac (chart_id, amount) AS (
-     SELECT chart_id, amount
+     SELECT chart_id, CASE WHEN acc_trans.approved and gl.approved THEN amount
+                           ELSE 0 
+                       END
        FROM acc_trans
        JOIN (select id, approved from ar union all
              select id, approved from ap union all
              select id, approved from gl) gl ON gl.id = acc_trans.trans_id
-      WHERE acc_trans.approved and gl.approved
 ),
 l(account_id, link) AS (
      SELECT account_id, array_to_string(array_agg(description), ':')

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