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

SF.net SVN: ledger-smb:[2948] addons/1.3/assets/trunk



Revision: 2948
          http://ledger-smb.svn.sourceforge.net/ledger-smb/?rev=2948&view=rev
Author:   einhverfr
Date:     2010-03-03 20:27:43 +0000 (Wed, 03 Mar 2010)

Log Message:
-----------
Disposal workflow now working and verified on my system

Modified Paths:
--------------
    addons/1.3/assets/trunk/LedgerSMB/DBObject/Asset_Report.pm
    addons/1.3/assets/trunk/UI/asset/begin_approval.html
    addons/1.3/assets/trunk/scripts/asset.pl
    addons/1.3/assets/trunk/sql/modules/Assets.sql

Modified: addons/1.3/assets/trunk/LedgerSMB/DBObject/Asset_Report.pm
===================================================================
--- addons/1.3/assets/trunk/LedgerSMB/DBObject/Asset_Report.pm	2010-03-03 19:35:04 UTC (rev 2947)
+++ addons/1.3/assets/trunk/LedgerSMB/DBObject/Asset_Report.pm	2010-03-03 20:27:43 UTC (rev 2948)
@@ -43,7 +43,15 @@
     my ($ref) = $self->exec_method(funcname => 'asset_report__get');
     $self->merge($ref);
     $self->{report_lines} = [];
-    @{$self->{report_lines}} = $self->exec_method(funcname => 'asset_report__get_lines');
+    if ($self->{report_class} == 1){
+        @{$self->{report_lines}} = $self->exec_method(
+                                  funcname => 'asset_report__get_lines'
+        );
+    } else {
+        @{$self->{report_lines}} = $self->exec_method(
+                                  funcname => 'get_disposal_report'
+        );
+    }
     return;
 }
 
@@ -84,7 +92,7 @@
     @{$self->{loss_accounts}} = $self->exec_method(
                    funcname => 'asset_report__get_loss_accts'
     );
-    for my $atype (qw(exp_accounts gain_accounts loss_accts)){
+    for my $atype (qw(exp_accounts gain_accounts loss_accounts)){
         for my $acct (@{$self->{$atype}}){
             $acct->{text} = $acct->{accno}. '--'. $acct->{description};
         }

Modified: addons/1.3/assets/trunk/UI/asset/begin_approval.html
===================================================================
--- addons/1.3/assets/trunk/UI/asset/begin_approval.html	2010-03-03 19:35:04 UTC (rev 2947)
+++ addons/1.3/assets/trunk/UI/asset/begin_approval.html	2010-03-03 20:27:43 UTC (rev 2948)
@@ -35,20 +35,22 @@
 <?lsmb IF depreciation ?>
 <!-- moved expense acct drop down to asset screen -->
 <?lsmb ELSE ?>
-<div class="inputgroup" id="gaingroup"
+<div class="inputgroup" id="gaingroup">
 <?lsmb PROCESS select element_data = {
      name = "gain_acct"
      class = "account"
-     options = gain_accts
+     value_attr = "id"
+     options = gain_accounts
      default_values = [gain_acct]
      label = text('Gain Account') #'
 } ?>
 </div>
-<div class="inputgroup" id="lossgroup"
+<div class="inputgroup" id="lossgroup">
 <?lsmb PROCESS select element_data = {
      name = "loss_acct"
      class = "account"
-     options = loss_accts
+     options = loss_accounts
+     value_attr = "id"
      default_values = [loss_acct]
      label = text('Loss Account') #'
 } ?>

Modified: addons/1.3/assets/trunk/scripts/asset.pl
===================================================================
--- addons/1.3/assets/trunk/scripts/asset.pl	2010-03-03 19:35:04 UTC (rev 2947)
+++ addons/1.3/assets/trunk/scripts/asset.pl	2010-03-03 20:27:43 UTC (rev 2948)
@@ -326,6 +326,8 @@
 
 sub search_reports {
     my ($request) = @_;
+    my $report = LedgerSMB::DBObject::Report->new(base => $request);
+    $report->get_metadata;
     my $template = LedgerSMB::Template->new(
         user =>$request->{_user}, 
         locale => $request->{_locale},
@@ -333,7 +335,7 @@
         template => 'report_criteria',
         format => 'HTML'
     );
-    $template->render($request);
+    $template->render($report);
 }
 
 sub report_get {
@@ -460,6 +462,9 @@
                      "expense_acct=$ar->{expense_acct}";
     if ($ar->{depreciation}){
              $base_href .= '&depreciation=1';
+    } else {
+             $base_href .= "&gain_acct=$ar->{gain_acct}&loss_acct=".
+                            "$ar->{loss_acct}";
     }
     for my $r (@results){
         next if (($r->{report_class} != 1 and $ar->{depreciation})
@@ -587,23 +592,27 @@
     my $report = LedgerSMB::DBObject::Asset_Report->new(base => $request);
     $report->get;
     my @cols = qw(tag description start_dep disposed_on dm purchase_value
-                 accum_depreciation adj_basis gain_loss);
+                 accum_depreciation adj_basis disposal_amt gain_loss);
     $report->{title} = $locale->text("Report [_1] on date [_2]", 
                      $report->{id}, $report->{report_date});
     my $header = {
                             tag => $locale->text('Tag'),
+                    description => $locale->text('Description'),
                       start_dep => $locale->text('Dep. Starts'),
-                     disposed_on => $locale->text('Disposal Date'),
-                 purchase_value =>$locale->text('Aquired Value'),
-                             dm =>$locale->text('D M'),
-             accum_depreciation =>$locale->text('Accum. Depreciation'),
-                      adj_basis =>$locale->text('Adjusted Basis'),
-                      gain_loss =>$locale->text('Gain (Loss)'),
+                    disposed_on => $locale->text('Disposal Date'),
+                 purchase_value => $locale->text('Aquired Value'),
+                             dm => $locale->text('D M'),
+             accum_depreciation => $locale->text('Accum. Depreciation'),
+                   disposal_amt => $locale->text('Proceeds'),
+                      adj_basis => $locale->text('Adjusted Basis'),
+                      gain_loss => $locale->text('Gain (Loss)'),
     };
     my $rows = [];
     for my $r (@{$report->{report_lines}}){
         $r->{usable_life} = $report->format_amount({amount => $r->{usable_life}});
-        for my $amt (qw(purchase_value adj_basis)){
+        for my $amt (qw(purchase_value adj_basis accum_depreciation 
+                        disposal_amt)
+        ){
              $r->{$amt} = $report->format_amount({amount => $r->{$amt},
                                               money  => 1,});
         }

Modified: addons/1.3/assets/trunk/sql/modules/Assets.sql
===================================================================
--- addons/1.3/assets/trunk/sql/modules/Assets.sql	2010-03-03 19:35:04 UTC (rev 2947)
+++ addons/1.3/assets/trunk/sql/modules/Assets.sql	2010-03-03 20:27:43 UTC (rev 2948)
@@ -539,9 +539,9 @@
          where id = in_id;
 	SELECT * INTO ret_val FROM asset_report WHERE id = in_id;
         if ret_val.dont_approve is not true then 
-                if retval.report_class = 1 THEN
+                if ret_val.report_class = 1 THEN
                     PERFORM asset_report__generate_gl(in_id, in_expense_acct);
-                ELSIF retval.report_class = 1 THEN
+                ELSIF ret_val.report_class = 2 THEN
                     PERFORM asset_report__disposal_gl(
                                  in_id, in_gain_acct, in_loss_acct);
                 ELSE RAISE EXCEPTION 'Invalid report class';
@@ -551,7 +551,7 @@
 	RETURN ret_val;
 end;
 $$ language plpgsql;
-revoke execute on function asset_report__approve(int, int) from public;
+revoke execute on function asset_report__approve(int, int, int, int) from public;
 
 CREATE OR REPLACE FUNCTION asset_report__disposal_gl
 (in_id int, in_gain_acct int, in_loss_acct int)
@@ -569,16 +569,17 @@
 
   INSERT
     INTO acc_trans (chart_id, trans_id, amount, approved, transdate)
-  SELECT a.dep_account_id, currval('id')::int, sum(r.accum_depreciation),
+  SELECT a.dep_account_id, currval('id')::int, sum(r.accum_depreciation) * -1,
          TRUE, r.disposed_on
     FROM get_disposal_report($1) r
     JOIN asset_item a ON (r.id = a.id)
 GROUP BY a.dep_account_id, r.disposed_on;
 
+  -- GAIN is negative since it is a debit
   INSERT
     INTO acc_trans (chart_id, trans_id, amount, approved, transdate)
-  SELECT case when sum(r.gain_loss) > 0 THEN $2 else $3 end,
-         currval('id')::int, sum(r.gain_loss) * -1,
+  SELECT case when sum(r.gain_loss) > 0 THEN $3 else $2 end,
+         currval('id')::int, sum(r.gain_loss),
          TRUE, r.disposed_on
     FROM get_disposal_report($1) r
     JOIN asset_item ai ON (r.id = ai.id)


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