Advertisement
Guest User

Untitled

a guest
Dec 11th, 2019
112
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C# 2.02 KB | None | 0 0
  1.   public static void AmortissementLineaire(BienAmortissable b1)
  2.         {
  3.             Console.WriteLine("Amortissement linéaire en prorata temporis\n\n");
  4.  
  5.             // Check duree vie
  6.             int duree = b1.DureeVie1;
  7.             double taux = 1 / (double)duree;
  8.  
  9.             int proataDebut = 360 - ( b1.DateMiseService1.Day - 30 + b1.DateMiseService1.Month * 30 ) ;
  10.             int proataFin = 360 - proataDebut;
  11.  
  12.             duree = proataDebut == 360 ? duree : duree+=1 ;
  13.  
  14.             // Var
  15.             double uncDebut = b1.CoutAchat1;
  16.             double uncFin = b1.CoutAchat1;
  17.             double annuite = 0;
  18.             double cumul = 0;
  19.             double valeurAmortissable = b1.CoutAchat1 - b1.ValeurCession1;
  20.  
  21.             // Each year
  22.             for ( int i = 0; i < duree; i++ )
  23.             {
  24.                 // Unique annuite calc for first year, last year
  25.                 if ( i == 0)
  26.                 {
  27.                     // First year
  28.                     annuite = valeurAmortissable * taux  * proataDebut / 360;
  29.                 }
  30.                 else
  31.                 {
  32.                     /* Ternary operator
  33.                      *  Check is not last year
  34.                      *   true -> Calc annuite for lambda year
  35.                      *   false -> Calc annuite for last year
  36.                      */
  37.                     annuite = i != duree - 1 ? annuite = valeurAmortissable * taux : valeurAmortissable * taux * proataFin / 360;
  38.  
  39.                     // Increment year
  40.                     b1.DateMiseService1 = b1.DateMiseService1.AddYears(1);
  41.                 }
  42.                 cumul += annuite;
  43.                 uncFin -= annuite;
  44.  
  45.                 Console.WriteLine("EXERCICE : {0}", b1.DateMiseService1.Year);
  46.                 Console.WriteLine("\tUNC début : {0}", uncDebut);
  47.                 Console.WriteLine("\tAnnuité : {0}", annuite);
  48.                 Console.WriteLine("\tCumul : {0}", cumul);
  49.                 Console.WriteLine("\tUNC fin : {0}\n", uncFin);
  50.             }
  51.         }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement