Repository: Alino2023/Method_Dev_Travail1
Pull request #13: la fonction pour calculer le taux d'endetement est pret 
Author: login: JeffloveJeanfrancois
Created: 2025-04-01T21:43:59Z | Merged: 2025-04-01T22:16:15Z



Diff:
diff --git a/ApiTP1MethodeDeDev/ApiTP1MethodeDeDev/ApiTP1MethodeDeDev.csproj b/ApiTP1MethodeDeDev/ApiTP1MethodeDeDev/ApiTP1MethodeDeDev.csproj
index cc3aa9b..20726d7 100644
--- a/ApiTP1MethodeDeDev/ApiTP1MethodeDeDev/ApiTP1MethodeDeDev.csproj
+++ b/ApiTP1MethodeDeDev/ApiTP1MethodeDeDev/ApiTP1MethodeDeDev.csproj
@@ -13,8 +13,11 @@
       <PrivateAssets>all</PrivateAssets>
       <IncludeAssets>runtime; build; native; contentfiles; analyzers; buildtransitive</IncludeAssets>
     </PackageReference>
+    <PackageReference Include="Microsoft.VisualStudio.Sdk.TestFramework" Version="17.11.53" />
     <PackageReference Include="Microsoft.VisualStudio.Web.CodeGeneration.Design" Version="9.0.0" />
+    <PackageReference Include="Moq.EntityFrameworkCore" Version="9.0.0.1" />
     <PackageReference Include="Swashbuckle.AspNetCore.SwaggerUI" Version="7.2.0" />
+    <PackageReference Include="xunit" Version="2.9.3" />
   </ItemGroup>
 
   <ItemGroup>
diff --git a/ApiTP1MethodeDeDev/Domain/Bank/OtherBankLoan.cs b/ApiTP1MethodeDeDev/Domain/Bank/OtherBankLoan.cs
index cb0782e..773b3f5 100644
--- a/ApiTP1MethodeDeDev/Domain/Bank/OtherBankLoan.cs
+++ b/ApiTP1MethodeDeDev/Domain/Bank/OtherBankLoan.cs
@@ -22,9 +22,9 @@ public class OtherBankLoan
         [Required]
         [Description("Loan Remaining Balance")]
         public decimal RemainingBalance {  get; set; }
-
         [Required]
         [Description("Reason for the loan ")]
         public string Reason { get; set; }
+        public decimal MonthlyPayment { get; set; }
     }
 }
diff --git a/ApiTP1MethodeDeDev/Domain/Borrowers/Borrower.cs b/ApiTP1MethodeDeDev/Domain/Borrowers/Borrower.cs
index b76822b..1db26b6 100644
--- a/ApiTP1MethodeDeDev/Domain/Borrowers/Borrower.cs
+++ b/ApiTP1MethodeDeDev/Domain/Borrowers/Borrower.cs
@@ -57,10 +57,12 @@ public class Borrower
         [Description("Number Of borrower's Late Payements")]
         public List<LatePaymentBorrower> NumberOfLatePayments {  get; set; }
 
+        [Required]
+        public decimal MonthlyIncome { get; set; }
 
         [Required]
         [Description("Debt Ratio")]
-        public Decimal DebtRatio {  get; set; }
+        public Decimal DebtRatio { get; set; }
 
 
         [Required]
@@ -73,22 +75,13 @@ public class Borrower
 
 
         public List<Loan> Loans { get; set; } = new List<Loan>();
-        public object ActiveLoanPayments { get; private set; }
+        public List<decimal> ActiveLoanPayments { get; set; } = new List<decimal>();
+
 
         public Borrower()
         {
         }
 
-        //public Borrower(string sin, string firstName, string lastName, string phone, string email, string address, decimal monthlyIncome)
-        //{
-        //    Sin = sin;
-        //    FirstName = firstName;
-        //    LastName = lastName;
-        //    Phone = phone;
-        //    Email = email;
-        //    Address = address; 
-        //}
-
         public Borrower(string sin, string firstName, string lastName, string phone, string email, string address)
         {
             Sin = sin;
@@ -97,6 +90,25 @@ public Borrower(string sin, string firstName, string lastName, string phone, str
             Phone = phone;
             Email = email;
             Address = address;
+         
+        }
+        public void CalculateDebtRatio()
+        {
+            Job jobActuel = EmploymentHistory.OrderByDescending(job => job.StartingDate).FirstOrDefault();
+
+            if (jobActuel == null)
+            {
+                throw new InvalidOperationException("No employment found in the history to calculate the debt ratio.");
+            }
+
+            if (jobActuel.MentualSalary <= 0)
+            {
+                throw new InvalidOperationException("The current job's salary must be greater than zero to calculate the debt ratio.");
+            }
+
+            decimal totalLoanPayments = OtherBankLoans.Sum(loan => loan.Mensuality) + Loans.Sum(loan => loan.MonthlyPayment);
+
+            DebtRatio = (totalLoanPayments / jobActuel.MentualSalary) * 100;
         }
         public string ClassifyRisk()
         {
@@ -135,12 +147,5 @@ private bool IsLowRisk(int jobsInLastTwoYears, Job currentJob, bool currentJobIs
             return false;
         }
 
-        //public decimal CalculateDebtRatio(object activeLoanPayments)
-        //{
-        ////    decimal totalLoanPayments = activeLoanPayments.Sum();
-        ////    return (MonthlyIncome > 0) ? (totalLoanPayments / MonthlyIncome) * 100 : 0;
-        //}
-
-       
     }
 }
diff --git a/ApiTP1MethodeDeDev/Domain/Loans/Loan.cs b/ApiTP1MethodeDeDev/Domain/Loans/Loan.cs
index 454d80a..dee438e 100644
--- a/ApiTP1MethodeDeDev/Domain/Loans/Loan.cs
+++ b/ApiTP1MethodeDeDev/Domain/Loans/Loan.cs
@@ -48,6 +48,11 @@ public class Loan
         [Required]
         public Borrower TheBorrower { get; set; }
 
+        [Required]
+        [Description("The monthly payment amount for the loan")]
+        public decimal MonthlyPayment { get; set; }
+
+
         public List<decimal> Loans { get; set; } = new List<decimal>();
 
        
@@ -86,6 +91,7 @@ private void ValidateLoanDates(DateTime startDate, DateTime endDate, int duratio
         }
         public Loan()
         {
+
         }
     }
 }
diff --git a/ApiTP1MethodeDeDev/Domain/Loans/LoanServicesTests.cs b/ApiTP1MethodeDeDev/Domain/Loans/LoanServicesTests.cs
new file mode 100644
index 0000000..0c248f8
--- /dev/null
+++ b/ApiTP1MethodeDeDev/Domain/Loans/LoanServicesTests.cs
@@ -0,0 +1,13 @@
+﻿using System;
+using System.Collections.Generic;
+using System.Linq;
+using System.Text;
+using System.Threading.Tasks;
+
+namespace Domain.Loans
+{
+    internal class LoanServicesTests
+    {
+
+    }
+}


Reviews:
user: login: Zakaria-morjani
state: COMMENTED
author_association: COLLABORATOR
submitted_at: 2025-04-01T21:50:21Z
user: login: FiliwaK
state: COMMENTED
author_association: COLLABORATOR
submitted_at: 2025-04-01T21:57:27Z
user: login: FiliwaK
state: COMMENTED
author_association: COLLABORATOR
submitted_at: 2025-04-01T22:14:56Z

Review comments:
diff_hunk: @@ -97,6 +90,31 @@ public Borrower(string sin, string firstName, string lastName, string phone, str
             Phone = phone;
             Email = email;
             Address = address;
+            MonthlyIncome = MonthlyIncome;
+        }
+        public void CalculateDebtRatio()
+        {
+            if (MonthlyIncome <= 0)
+            {
+                DebtRatio = 0;
path: ApiTP1MethodeDeDev/Domain/Borrowers/Borrower.cs
user: login: Zakaria-morjani
body: je pense qu il ne faut pas mettre debtRatio a 0 mais plus lancer une exception ou une erreur pour dir que la personne n'a pas de salaire 
created_at: 2025-04-01T21:50:21Z
author_association: COLLABORATOR
diff_hunk: @@ -93,14 +89,32 @@ public Borrower(string sin, string firstName, string lastName, string phone, str
             Phone = phone;
             Email = email;
             Address = address;
+            MonthlyIncome = MonthlyIncome;
+        }
+        public void CalculateDebtRatio()
+        {
+            if (MonthlyIncome <= 0)
+            {
+                DebtRatio = 0;
path: ApiTP1MethodeDeDev/Domain/Borrowers/Borrower.cs
user: login: FiliwaK
body: j'pense pas qu'il est necessaire de mettre debtratio ici , parce que c'est ce que zak va utiliser pour les risques 
created_at: 2025-04-01T21:57:27Z
author_association: COLLABORATOR
diff_hunk: @@ -93,14 +89,32 @@ public Borrower(string sin, string firstName, string lastName, string phone, str
             Phone = phone;
             Email = email;
             Address = address;
+            MonthlyIncome = MonthlyIncome;
+        }
+        public void CalculateDebtRatio()
+        {
+            if (MonthlyIncome <= 0)
+            {
+                DebtRatio = 0;
path: ApiTP1MethodeDeDev/Domain/Borrowers/Borrower.cs
user: login: FiliwaK
body: hey c'est plutot le monthlyincome qui doit pas etre utilise tu dois prendre le salaire de son dernier job plutot
created_at: 2025-04-01T22:14:56Z
author_association: COLLABORATOR

PR comments:
user: login: Alino2023
created_at: 2025-04-01T21:56:11Z
body: Jeff, si le client n'a pas d'autres crédits (OtherBankLoans) en cours auprès d'autres banques, cela entraînera une exception je pense. Stp assures toi qu'ils ne soient pas null.
author_association: OWNER
user: login: FiliwaK
created_at: 2025-04-01T22:16:05Z
body: ok, mais on doit aussi essayer pour voir si le calcul marche soit par le controller ou d'une autre facon 
author_association: COLLABORATOR