issue 21656: The reamortization of an asset cannot be calculated
authorJavier Etxarri <javier.echarri@openbravo.com>
Wed, 19 Sep 2012 17:38:29 +0200
changeset 17983 7d048ad0b76f
parent 17982 9626592579b5
child 17984 7e0c66407ed1
issue 21656: The reamortization of an asset cannot be calculated
src-db/database/model/functions/A_ASSET_POST.xml
--- a/src-db/database/model/functions/A_ASSET_POST.xml	Tue Sep 18 17:41:08 2012 +0200
+++ b/src-db/database/model/functions/A_ASSET_POST.xml	Wed Sep 19 17:38:29 2012 +0200
@@ -190,7 +190,8 @@
             v_LAST_DAY_DATE:=TO_DATE('31-12-' || TO_CHAR(v_AMORTIZATIONSTARTDATE, 'YYYY'), 'DD-MM-YYYY') ;
             if v_Count>1 then
               v_BEGINING_DATE:=TO_DATE('31-12-' || to_char(TO_number(to_char(v_BEGINING_DATE, 'yyyy')) +v_Count-1), 'DD-MM-YYYY') ;
-              v_USELIFEYEARS:=v_USELIFEYEARS+1;
+	      v_USELIFEYEARS:=v_USELIFEYEARS+ (1- (to_number(TO_DATE('31-12-' || TO_CHAR(v_AMORTIZATIONSTARTDATE, 'YYYY'), 'DD-MM-YYYY') - v_AMORTIZATIONSTARTDATE) /
+              to_number(TO_DATE('31-12-' || TO_CHAR(v_AMORTIZATIONSTARTDATE, 'YYYY'), 'DD-MM-YYYY') - TO_DATE('01-01-' || TO_CHAR(v_AMORTIZATIONSTARTDATE, 'YYYY'), 'DD-MM-YYYY'))));
             end if;
             if v_AMORTIZATIONCALCTYPE='PE' then
               v_PercentageGeneral:=v_AMORTIZATIONPERCENTAGE;
@@ -198,7 +199,6 @@
             else
               --  v_PercentageGeneral := 100 / v_USELIFEYEARS;
               v_PercentageGeneral:=((v_AMORTIZATIONVALUEAMT-v_DEPRECIATEDPREVIOUSAMT-v_depreciatedPlan) *100/v_AMORTIZATIONVALUEAMT) /(v_USELIFEYEARS-v_DepreciatedLines) ;
-              UPDATE A_ASSET SET percentagegeneral = v_PercentageGeneral WHERE A_ASSET_ID=v_Record_ID;
               SELECT to_number(TO_DATE(ADD_MONTHS(v_AMORTIZATIONSTARTDATE, 12*v_USELIFEYEARS)) - v_AMORTIZATIONSTARTDATE)
               INTO v_TOTAL_DAYS
               FROM DUAL;
@@ -309,8 +309,9 @@
             v_FIRST_DAY_DATE:=TO_DATE('01-'|| TO_CHAR(v_AMORTIZATIONSTARTDATE, 'MM') || '-' || TO_CHAR(v_AMORTIZATIONSTARTDATE, 'YYYY'), 'DD-MM-YYYY') ;
             v_LAST_DAY_DATE:=TO_DATE('31-12-'|| TO_CHAR(v_AMORTIZATIONSTARTDATE, 'YYYY'), 'DD-MM-YYYY') ;
             if v_Count>1 then
-              v_BEGINING_DATE:=TO_DATE(ADD_MONTHS(LAST_DAY(TO_DATE('01-' || TO_CHAR(v_BEGINING_DATE, 'MM') || '-' || TO_CHAR(v_BEGINING_DATE, 'yyyy'), 'DD-MM-YYYY')), v_DepreciatedLines)) ;
-              v_USELIFEMonths:=v_USELIFEMonths+1;
+              v_BEGINING_DATE:=TO_DATE(ADD_MONTHS(LAST_DAY(TO_DATE('01-' || TO_CHAR(v_BEGINING_DATE, 'MM') || '-' || TO_CHAR(v_BEGINING_DATE, 'yyyy'), 'DD-MM-YYYY')), v_DepreciatedLines)) ; 
+              v_USELIFEMonths:=v_USELIFEMonths + (1- (to_number(last_day(v_AMORTIZATIONSTARTDATE) - v_AMORTIZATIONSTARTDATE) /
+              to_number(last_day(v_AMORTIZATIONSTARTDATE) - TO_DATE('01-' || TO_CHAR(v_AMORTIZATIONSTARTDATE, 'MM-YYYY'), 'DD-MM-YYYY'))));
             end if;
             
             if v_AMORTIZATIONCALCTYPE='PE' then
@@ -336,7 +337,7 @@
             loop
               IF(v_COUNT=1 AND to_number(v_BEGINING_DATE-v_FIRST_DAY_DATE)<>0) THEN
                 v_Percentage:=(to_number(to_number(last_day(v_BEGINING_DATE) -v_BEGINING_DATE)) + 1) / (trunc((last_day(v_BEGINING_DATE) -(TO_DATE('01-'||to_char(TO_DATE(v_BEGINING_DATE), 'MM-YYYY'), 'DD-MM-YYYY')))) +1) * v_PercentageGeneral;
-                v_USELIFEMONTHS:=v_USELIFEMONTHS+1;
+		v_USELIFEMONTHS:=v_USELIFEMONTHS+1;
               ELSE
                 v_Percentage:=v_PercentageGeneral;
               END IF;
@@ -423,7 +424,7 @@
     END IF;
     IF  ((v_AMORTIZATIONCALCTYPE='TI' AND v_ASSETSCHEDULE='YE' AND v_Inserted + v_DepreciatedLines <> v_ORIGUSELIFEYEARS)
       OR (v_AMORTIZATIONCALCTYPE='TI' AND v_ASSETSCHEDULE='MO' AND v_Inserted + v_DepreciatedLines <> v_ORIGUSELIFEMONTHS)) THEN
-      RAISE_APPLICATION_ERROR(-20000, '@TooLowValueToAmortize@');
+        RAISE_APPLICATION_ERROR(-20000, '@TooLowValueToAmortize@');
     END IF;
     IF(FINISH_PROCESS) THEN
       UPDATE A_ASSET SET PROCESSED='Y', PROCESSING='N'  WHERE A_ASSET_ID=v_Record_ID;