Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
38 changes: 38 additions & 0 deletions src/classes/DContractTriggerController.cls
Original file line number Diff line number Diff line change
@@ -0,0 +1,38 @@
public class DContractTriggerController {

public static void handleBeforeUpdate(List<DContract__c> updated, Map<Id, DContract__c> beforeUpdate) {
for (DContract__c upsertedContract : updated) {
DContract__c oldValue = beforeUpdate.get(upsertedContract.Id);
if ((oldValue == null || oldValue.FTE_Tracker__c != upsertedContract.FTE_Tracker__c)) {
upsertedContract.addError('FTE Tracker is currently calculating Empolyee Work Cards, try update FTE Tracker field later.');
}
}
}

public static void handleAfterUpdate(List<DContract__c> updated, Map<Id, DContract__c> beforeUpdate) {
Set<Id> contracts = new Set<Id>();
List<DContract__c> contractsToUpdate = new List<DContract__c>();
Boolean fteJob = FTETrackerHelper.loadWorkCardJobStatus().isRunning;

for (DContract__c upsertedContract : updated) {
DContract__c oldValue = beforeUpdate.get(upsertedContract.Id);
if ((oldValue == null || oldValue.FTE_Tracker__c != upsertedContract.FTE_Tracker__c) && (upsertedContract.Skip_FTE_Tracker_Trigger__c == false)) {
contracts.add(upsertedContract.Id);
} else if (upsertedContract.Skip_FTE_Tracker_Trigger__c == true) { // we want skip this batch job FTE Contract is uploaded by CSV File, we want have full controll and run moving hours batch job after Generating work cards
contractsToUpdate.add(new DContract__c(Id = upsertedContract.Id, Skip_FTE_Tracker_Trigger__c = false));
}
}

if (contractsToUpdate.size() > 0) {
update contractsToUpdate;
}

FTETrackerHelper.markTemplates(contracts);

if (contracts.size() > 0) {
if (!Test.isRunningTest()) {
Database.executeBatch(new FTETimeAllocator(false), 1);
}
}
}
}
5 changes: 5 additions & 0 deletions src/classes/DContractTriggerController.cls-meta.xml
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
<?xml version="1.0" encoding="UTF-8"?>
<ApexClass xmlns="http://soap.sforce.com/2006/04/metadata">
<apiVersion>38.0</apiVersion>
<status>Active</status>
</ApexClass>
1 change: 0 additions & 1 deletion src/classes/FTEController.cls
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,6 @@ public virtual class FTEController {
public JobWrapper workCardJobStatus {get; set;}

public FTEController() {

}

public virtual PageReference goToEmployeeListView() {
Expand Down
58 changes: 35 additions & 23 deletions src/classes/FTECsvUploadController.cls
Original file line number Diff line number Diff line change
Expand Up @@ -10,38 +10,40 @@ public class FTECsvUploadController extends FTEController {
public Pagination fteStatusPagination { get; set; }
public Map<Id, FTEUploadData> records { get; set; }

private Id contractId;
private Set<Id> employees;
private Decimal uploadedYear;
private Map<String, SFDC_Employee__c> employeeMap;

public FTECsvUploadController() {
this.fteStatusPagination = new Pagination();
loadWorkCardJobStatus();
}

public List<FTE_Data_Record_Status__c> getFTEStatusRecords() {
List<FTE_Data_Record_Status__c> result = [SELECT Status__c, Status_Message__c, Line_Number__c, Line_Number_Text__c FROM FTE_Data_Record_Status__c
ORDER BY Line_Number__c LIMIT : this.fteStatusPagination.pageSize OFFSET : this.fteStatusPagination.getOffsetValue()];
this.fteStatusPagination.handleResulSize([SELECT count() FROM FTE_Data_Record_Status__c]);
return result;
}
public Boolean processFTEDataRecords() {
Map<Id, FTE_Data_Record__c> mappedTemplates = new Map<Id, FTE_Data_Record__c>();
for (FTE_Data_Record__c rec : [SELECT Id, Employee__c, Year__c,
Month_1__c, Month_2__c, Month_3__c, Month_4__c, Month_5__c, Month_6__c,
Month_7__c, Month_8__c, Month_9__c, Month_10__c, Month_11__c, Month_12__c,
Month_Updated_1__c, Month_Updated_2__c, Month_Updated_3__c, Month_Updated_4__c, Month_Updated_5__c, Month_Updated_6__c,
Month_Updated_7__c, Month_Updated_8__c, Month_Updated_9__c, Month_Updated_10__c, Month_Updated_11__c, Month_Updated_12__c
FROM FTE_Data_Record__c
WHERE Contract__c =: this.contractId AND Employee__c IN: this.employees AND Year__c =: this.uploadedYear]) {
mappedTemplates.put(rec.Employee__c, rec);
}

public void removeFTEDataStatusRecords() {
List<FTE_Data_Record_Status__c> toRemove = [SELECT Id FROM FTE_Data_Record_Status__c];
if (toRemove.size() > 0) {
delete toRemove;
ApexPages.getMessages().clear();
List<FTE_Data_Record__c> finalDataList = new List<FTE_Data_Record__c>();
for (FTEUploadData rec : this.records.values()) {
finalDataList.add(rec.mergeData(mappedTemplates.get(rec.getEmployeeId())));
}
}

public Boolean processFTEDataRecords() {
loadWorkCardJobStatus();
if (this.workCardJobStatus.isRunning == false) {
removeFTEDataStatusRecords(); // Remove status of last batch upload
upsert finalDataList;

if (!Test.isRunningTest()) {
Database.executeBatch(new FTEHoursUploadBatch(this.records.values()), 1);
} else {
Database.executeBatch(new FTEHoursUploadBatch(this.records.values())); // no more then one batch execute can be invoked from test
}
Database.executeBatch(new FTETimeAllocator(true), 1);
} // In test we want test only parsing and how records was upserted, Time allocator has seprate tests

loadWorkCardJobStatus();
ApexPages.getMessages().clear();
Expand Down Expand Up @@ -105,6 +107,7 @@ public class FTECsvUploadController extends FTEController {
Integer csvYear = Integer.valueOf(numbers.get(1));
if (year == -1) {
year = csvYear;
this.uploadedYear = csvYear;
}

if (!validateColumnHeaderData(year, csvYear, csvMonth, lineNum, strHelper, monthMapping)) {
Expand All @@ -126,10 +129,15 @@ public class FTECsvUploadController extends FTEController {
fteContract = getContract(contractName);
if (fteContract == null) {
return null;
} else if (fteContract.FTE_Tracker__c != 'Yes') {
ApexPages.addMessage(new ApexPages.message(ApexPages.severity.ERROR, 'Contract : "' + contractName + '" is not a FTE Tracker contract, please add it to Tracker before uploading CSV Template'));
return null;
}
this.contractId = fteContract.Id;

csvPattern = Pattern.compile('(\\d*\\.\\d+)|(\\d+\\.\\d*)');
this.records = new Map<Id, FTEUploadData>();
this.employees = new Set<Id>();
loadEmployeeMap();

Boolean wasData = false;
Expand All @@ -144,6 +152,7 @@ public class FTECsvUploadController extends FTEController {

FTEUploadData emplDataRec = null;
Id emplId = this.employeeMap.get(employeeName).Id;
this.employees.add(emplId);
if (this.records.containsKey(emplId)) {
emplDataRec = this.records.get(emplId);
} else {
Expand All @@ -157,12 +166,14 @@ public class FTECsvUploadController extends FTEController {
}

Integer index = monthMapping.get(i - 1 - columnsToSkip);
if (strHelper.isNumeric() || csvPattern.matcher(strHelper).matches()) {
if (strHelper.isNumeric() || csvPattern.matcher(strHelper).matches()) { // number 0 - ...
emplDataRec.addMonthTime(index, Decimal.valueOf(strHelper));
wasData = true;
} else if (!String.isBlank(strHelper)) {
} else if (!String.isBlank(strHelper)) { // wrong number
ApexPages.addMessage(new ApexPages.message(ApexPages.severity.ERROR, 'Line ' + lineNum + ' : ' + 'bad number format - ' + strHelper));
return null;
} else { // blank value we must set -1 to it will mean that threshold is removed
emplDataRec.addMonthTime(index, -1);
}
}
this.records.put(emplId, emplDataRec);
Expand All @@ -175,9 +186,10 @@ public class FTECsvUploadController extends FTEController {

Boolean success = processFTEDataRecords();
if (success) {
ApexPages.addMessage(new ApexPages.message(ApexPages.severity.INFO, 'CSV file ' + fileName + ' was parsed. Upload job was scheduled, please wait for results.'));
ApexPages.addMessage(new ApexPages.message(ApexPages.severity.INFO, 'CSV file ' + fileName + ' was parsed. '
+ this.records.values().size() + ' records was added for ' + this.records.keySet().size() + ' employees.'));
} else {
ApexPages.addMessage(new ApexPages.message(ApexPages.severity.ERROR, 'Cannot upload csv file. FTE Tracker is calculating time.'));
ApexPages.addMessage(new ApexPages.message(ApexPages.severity.ERROR, 'Cannot upload csv file. FTE Tracker is currently calculating time.'));
}

return null;
Expand All @@ -189,7 +201,7 @@ public class FTECsvUploadController extends FTEController {
}

private DContract__c getContract(String contractName) {
List<DContract__c> contracts = [SELECT Id, Name FROM DContract__c WHERE Name =: contractName];
List<DContract__c> contracts = [SELECT Id, Name, FTE_Tracker__c FROM DContract__c WHERE Name =: contractName];
if (contracts.size() > 0) {
return contracts.get(0);
}
Expand Down
Loading