diff --git a/Server/HetsApi/Controllers/RentalRequestController.cs b/Server/HetsApi/Controllers/RentalRequestController.cs
index 3af54e1d..a9ffbf70 100644
--- a/Server/HetsApi/Controllers/RentalRequestController.cs
+++ b/Server/HetsApi/Controllers/RentalRequestController.cs
@@ -1199,7 +1199,10 @@ public virtual IActionResult GetSeniorityList(int id, bool counterCopy = false)
}
// TH-112626
listRecord.SeniorityList = listRecord.SeniorityList
- .OrderByDescending(x => Convert.ToDecimal(x.Seniority))
+ // TH-115131
+ //.OrderByDescending(x => Convert.ToDecimal(x.Seniority))
+ .OrderBy(x => x.Block)
+ .ThenByDescending(x => Convert.ToDecimal(x.Seniority))
.ToList();
string documentName = $"SeniorityList-{DateTime.Now:yyyy-MM-dd}{(counterCopy ? "-(CounterCopy)" : "")}.docx";
byte[] document = SeniorityList.GetSeniorityList(seniorityList, documentName, counterCopy, (errMessage, ex) => {
diff --git a/Server/HetsApi/HetsApi.csproj b/Server/HetsApi/HetsApi.csproj
index 42fe674e..d15ffc45 100644
--- a/Server/HetsApi/HetsApi.csproj
+++ b/Server/HetsApi/HetsApi.csproj
@@ -12,7 +12,7 @@
1.0.0.0
sprint1
- 1.10.10.0
+ 1.10.11.0
diff --git a/Server/HetsApi/appsettings.json b/Server/HetsApi/appsettings.json
index 0586e7d9..fa69725c 100644
--- a/Server/HetsApi/appsettings.json
+++ b/Server/HetsApi/appsettings.json
@@ -13,7 +13,7 @@
"LogoffUrl-Training": "https://logontest.gov.bc.ca/clp-cgi/logoff.cgi?returl=https://trn-hets.th.gov.bc.ca&retnow=1",
"LogoffUrl-UAT": "https://logontest.gov.bc.ca/clp-cgi/logoff.cgi?returl=https://uat-hets.th.gov.bc.ca&retnow=1",
"LogoffUrl-Production": "https://logon.gov.bc.ca/clp-cgi/logoff.cgi?returl=https://hets.th.gov.bc.ca&retnow=1",
- "Version-Application": "Release 1.10.10.0",
+ "Version-Application": "Release 1.10.11.0",
"Version-Database": "Release 1.10.10.0",
"Maximum-Blank-Agreements": "3",
"ExceptionDescriptions": {
diff --git a/Server/HetsData/Repositories/RentalRequestRepository.cs b/Server/HetsData/Repositories/RentalRequestRepository.cs
index 886852cc..1ddde8ee 100644
--- a/Server/HetsData/Repositories/RentalRequestRepository.cs
+++ b/Server/HetsData/Repositories/RentalRequestRepository.cs
@@ -7,6 +7,8 @@
using System;
using System.Linq;
using HetsCommon;
+using System.Collections.Generic;
+using Hangfire.Server;
namespace HetsData.Repositories
{
@@ -213,6 +215,117 @@ public RentalRequestDto GetRecordWithRotationList(int id, SeniorityScoringRules
{
sortedList[i].RotationListSortOrder = i + 1;
}
+
+ // TH-115131
+ // Recalculate the rotationListSortOrder based on LastCall
+ try
+ {
+ var sortedSeniorityList = request.HetRentalRequestSeniorityLists
+ .OrderBy(x => x.BlockNumber)
+ .ThenByDescending(x => Convert.ToDecimal(x.Seniority))
+ .ToList();
+ var lastCalledInGroup = sortedSeniorityList.Where(x => x.LastCalled).ToList();
+ var dicBlockCount = new Dictionary();
+ var dicBlockFirstItem = new Dictionary();
+
+ var dicBlockItemsBefore = new Dictionary();
+ var dicBlockItemsAfter = new Dictionary();
+ var dicBlockBeforeItems = new Dictionary>();
+ var dicBlockAfterItems = new Dictionary>();
+ var dicBlockAllItems = new Dictionary>();
+
+ for (int i = 0; i < lastCalledInGroup.Count; i++)
+ {
+ var itemsCount = sortedList.Where(x => x.BlockNumber == lastCalledInGroup[i].BlockNumber).ToList().Count;
+ dicBlockCount.Add(lastCalledInGroup[i].BlockNumber, itemsCount);
+
+ }
+ for (int i = 1; i < sortedSeniorityList.Count; i++)
+ {
+ if (sortedSeniorityList[i - 1].BlockNumber == sortedSeniorityList[i].BlockNumber && sortedSeniorityList[i - 1].LastCalled == true && sortedSeniorityList[i].LastCalled == false)
+ {
+ dicBlockFirstItem.Add(sortedSeniorityList[i].BlockNumber, sortedSeniorityList[i].EquipmentCode);
+ }
+ }
+
+ var groupedByBlock = sortedSeniorityList.GroupBy(item => item.BlockNumber);
+ Dictionary orders = new Dictionary();
+ foreach (var block in groupedByBlock)
+ {
+ int countBefore = 0;
+ int countAfter = 0;
+ bool foundTrue = false;
+ var itemsBefore = new List();
+ var itemsAfter = new List();
+
+ foreach (var item in block)
+ {
+ if (item.LastCalled == true)
+ {
+ foundTrue = true;
+ continue;
+ }
+ else
+ {
+ if (foundTrue)
+ {
+ countBefore++;
+ itemsBefore.Add(item);
+ }
+ else
+ {
+ countAfter++;
+ itemsAfter.Add(item);
+ }
+ }
+ }
+ dicBlockItemsBefore.Add(block.Key, countBefore);
+ dicBlockItemsAfter.Add(block.Key, countAfter);
+ dicBlockBeforeItems.Add(block.Key, itemsBefore);
+ dicBlockAfterItems.Add(block.Key, itemsAfter);
+ }
+
+ int tempOrder = 0;
+
+ foreach (var kvp in dicBlockBeforeItems)
+ {
+ int? key = kvp.Key;
+ var items = kvp.Value;
+
+ foreach (var item in items)
+ {
+ tempOrder++;
+ orders.Add(item.EquipmentCode, tempOrder);
+
+ }
+
+ foreach (var item in dicBlockAfterItems[key])
+ {
+ tempOrder++;
+ orders.Add(item.EquipmentCode, tempOrder);
+ }
+
+ // last called item should be at the end of the group
+ var lastCalled = sortedSeniorityList.Where(x => x.BlockNumber == key && x.LastCalled).FirstOrDefault();
+ if (lastCalled != null)
+ {
+ tempOrder++;
+ orders.Add(lastCalled.EquipmentCode, tempOrder);
+ }
+ }
+
+ for (int i = 0; i < sortedList.Count; i++)
+ {
+ var currentOrder = orders.Where(x => x.Key == sortedList[i].Equipment.EquipmentCode).FirstOrDefault().Value;
+ sortedList[i].RotationListSortOrder = currentOrder;
+ }
+
+ }
+ catch (Exception ex)
+ {
+ Console.WriteLine("Rotation list order calculation error: " + ex.Message);
+ }
+
request.HetRentalRequestRotationLists = sortedList;
return _mapper.Map(request);
}