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

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



Revision: 3002
          http://ledger-smb.svn.sourceforge.net/ledger-smb/?rev=3002&view=rev
Author:   einhverfr
Date:     2010-05-19 17:57:29 +0000 (Wed, 19 May 2010)

Log Message:
-----------
Corrections for partial disposal numbers

Modified Paths:
--------------
    addons/1.3/assets/trunk/scripts/asset.pl
    addons/1.3/assets/trunk/sql/modules/Assets.sql

Modified: addons/1.3/assets/trunk/scripts/asset.pl
===================================================================
--- addons/1.3/assets/trunk/scripts/asset.pl	2010-05-17 16:59:34 UTC (rev 3001)
+++ addons/1.3/assets/trunk/scripts/asset.pl	2010-05-19 17:57:29 UTC (rev 3002)
@@ -835,6 +835,7 @@
     for my $ai ($asset->import_file($request->{import_file})){
         for my $attr_name (qw(location department asset_class)){
             my $attr = $ai->{$attr_name};
+            $ai->{$attr} = $asset->{"${attr}_name"};
         }
         $ai->save;
     }

Modified: addons/1.3/assets/trunk/sql/modules/Assets.sql
===================================================================
--- addons/1.3/assets/trunk/sql/modules/Assets.sql	2010-05-17 16:59:34 UTC (rev 3001)
+++ addons/1.3/assets/trunk/sql/modules/Assets.sql	2010-05-19 17:57:29 UTC (rev 3002)
@@ -578,6 +578,10 @@
                 ELSIF ret_val.report_class = 2 THEN
                     PERFORM asset_report__disposal_gl(
                                  in_id, in_gain_acct, in_loss_acct);
+                ELSIF ret_val.report_class = 4 THEN
+                    PERFORM asset_disposal__approve(in_id, in_gain_acct, in_loss_acct, (select asset_account_id from asset_class 
+                                                                                         where id = ret_val.asset_class)
+                                                   );
                 ELSE RAISE EXCEPTION 'Invalid report class';
                 END IF;
         end if;
@@ -903,12 +907,13 @@
 $$ language sql;
 
 CREATE OR REPLACE FUNCTION asset_disposal__approve
-(in_report_id int, in_gain_acct int, in_loss_acct int, in_asset_acct int)
+(in_id int, in_gain_acct int, in_loss_acct int, in_asset_acct int)
 returns asset_report
 as $$
 DECLARE 
    retval asset_report;
    iter record;
+   t_disposed_percent numeric;
 begin
 -- this code is fairly opaque and needs more documentation that would be 
 -- otherwise optimal. This is mostly due to the fact that we have fairly
@@ -916,28 +921,42 @@
 -- requirements are not immediately intuitive.  Inserts marked functionally along
 -- with typical debit/credit designations.  Note debits are always negative.
 
+
 retval := asset_report__record_approve(in_report_id);
+if retval.report_class = 2 then
+     t_disposed_percent := 100;
+end if;
 
 INSERT INTO gl (reference, description, approved)
-select 'Asset Report ' || in_id, 'Asset Depreciation Report for ' || report_date,
+select 'Asset Report ' || in_id, 'Asset Disposal Report for ' || report_date,
        false
  FROM asset_report where id = in_id;
 
 -- REMOVING ASSETS FROM ACCOUNT (Credit)
 insert into acc_trans (trans_id, chart_id, amount, approved, transdate)
-SELECT currval('id'), a.asset_account_id, a.purchase_value, true, r.report_date
+SELECT currval('id'), a.asset_account_id, 
+       a.purchase_value 
+       * (coalesce(t_disposed_percent, m.percent_disposed)/100), 
+       true, r.report_date
  FROM  asset_item a
  JOIN  asset_report_line l ON (l.asset_id = a.id)
  JOIN  asset_report r ON (r.id = l.report_id)
+ JOIN  asset_rl_to_disposal_method m 
+        ON (l.report_id = m.report_id and l.asset_id = m.asset_id)
  WHERE r.id = in_id;
 
 -- REMOVING ACCUM DEP. (Debit)
 INSERT into acc_trans (trans_id, chart_id, amount, approved, transdate)
-SELECT currval('id', a.dep_account_id, sum(dl.amount) * -1, true, r.report_date)
+SELECT currval('id', a.dep_account_id, 
+       sum(dl.amount) * -1 
+       * (coalesce(t_disposed_percent, m.percent_disposed)/100), 
+       true, r.report_date)
  FROM  asset_item a
  JOIN  asset_report_line l ON (l.asset_id = a.id)
  JOIN  asset_report r ON (r.id = l.report_id)
  JOIN  asset_report_line dl ON (l.asset_id = dl.asset_id)
+ JOIN  asset_rl_to_disposal_method m 
+        ON (l.report_id = m.report_id and l.asset_id = m.asset_id)
  JOIN  asset_report dr ON (dl.report_id = dr.id 
                            and dr.depreciation is true 
                            and dr.approved_at is not null)
@@ -949,20 +968,40 @@
  FROM  asset_item a
  JOIN  asset_report_line l ON (l.asset_id = a.id)
  JOIN  asset_report r ON (r.id = l.report_id)
+ JOIN  asset_rl_to_disposal_method m 
+        ON (l.report_id = m.report_id and l.asset_id = m.asset_id)
  WHERE r.id = in_id;
 
 -- INSERT GAIN/LOSS (Credit for gain, debit for loss)
 INSERT INTO acc_trans(trans_id, chart_id, amount, approed, transdate)
 select currval('id'), 
-       case when sum(dl.amount) > sum(purchase_price) THEN in_loss_acct
+       case when 
+                  sum(dl.amount) 
+                  * 
+                  (coalesce(t_disposed_percent, m.percent_disposed)/100)
+                  > 
+                  sum(purchase_price) 
+                  * (coalesce(t_disposed_percent, m.percent_disposed)/100)
+            THEN in_loss_acct
             else in_gain_account
         END,
-        sum(dl.amount) - sum(a.purchase_price) - sum(l.amount), true, 
+        sum(dl.amount) 
+        * 
+        (coalesce(t_disposed_percent, m.percent_disposed)/100) 
+        - 
+        sum(a.purchase_price) 
+        *
+        (coalesce(t_disposed_percent, m.percent_disposed)/100)
+        - 
+        sum(l.amount), 
+        true, 
         retval.report_date
   FROM  asset_item a
   JOIN  asset_report_line l ON (l.asset_id = a.id)
   JOIN  asset_report r ON (r.id = l.report_id)
   JOIN  asset_report_line dl ON (l.asset_id = dl.asset_id)
+ JOIN  asset_rl_to_disposal_method m 
+        ON (l.report_id = m.report_id and l.asset_id = m.asset_id)
   JOIN  asset_report dr ON (dl.report_id = dr.id 
                             and dr.depreciation is true 
                             and dr.approved_at is not null)


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