diff --git a/force-app/main/default/classes/AccountHealthCalculator.cls b/force-app/main/default/classes/AccountHealthCalculator.cls
new file mode 100644
index 0000000..00aa7ce
--- /dev/null
+++ b/force-app/main/default/classes/AccountHealthCalculator.cls
@@ -0,0 +1,27 @@
+public class AccountHealthCalculator {
+ public static Decimal score(Account acc, Integer failedOrders) {
+ Decimal s = 100;
+ if (acc.Credit_Limit__c != null && acc.Credit_Limit__c > 0) {
+ Decimal util = acc.Open_Order_Value__c / acc.Credit_Limit__c;
+ if (util > 0.9) {
+ s = s - 40;
+ } else if (util > 0.75) {
+ s = s - 25;
+ } else if (util > 0.5) {
+ s = s - 10;
+ }
+ }
+ if (acc.Credit_Hold__c) {
+ s = s - 30;
+ }
+ s = s - (failedOrders * 5);
+ s = acc.Customer_Tier__c == 'Platinum' ? s + 10 : acc.Customer_Tier__c == 'Gold' ? s + 5 : s;
+ if (s < 0) {
+ s = 0;
+ }
+ if (s > 100) {
+ s = 100;
+ }
+ return s;
+ }
+}
diff --git a/force-app/main/default/classes/AccountHealthCalculator.cls-meta.xml b/force-app/main/default/classes/AccountHealthCalculator.cls-meta.xml
new file mode 100644
index 0000000..82775b9
--- /dev/null
+++ b/force-app/main/default/classes/AccountHealthCalculator.cls-meta.xml
@@ -0,0 +1,5 @@
+
+
+ 65.0
+ Active
+
diff --git a/force-app/main/default/classes/AccountHealthController.cls b/force-app/main/default/classes/AccountHealthController.cls
new file mode 100644
index 0000000..e510071
--- /dev/null
+++ b/force-app/main/default/classes/AccountHealthController.cls
@@ -0,0 +1,42 @@
+public class AccountHealthController {
+ @AuraEnabled
+ public static List searchAccounts(String searchTerm, String sortField) {
+ String query =
+ 'SELECT Id, Name, Health_Score__c, Customer_Tier__c, Credit_Limit__c, Open_Order_Value__c ' +
+ 'FROM Account WHERE Name LIKE \'%' +
+ searchTerm +
+ '%\' ORDER BY ' +
+ sortField;
+ return Database.query(query);
+ }
+
+ @AuraEnabled(cacheable=true)
+ public static List