function readOnly(count){ }
Starting November 20, the site will be set to read-only. On December 4, 2023,
forum discussions will move to the Trailblazer Community.
+ Start a Discussion
Kris WebsterKris Webster 

Map Comparison Help !

I am attempting to construct a class that will create Timecards for users automatically in my system. 

I know this is a basic question but I am just stuck... 

Here is the code 
 
global class Monthly_TC_Creator implements Database.Batchable<sObject>
{   

    //query the list of holidays from the holiday object 
    private pse__Proj__c proj = new pse__Proj__c();    

    public Monthly_TC_Creator() {
   		
    }

    global Database.queryLocator start(Database.BatchableContext ctx)
    { 
        //Query all the assignments that are active and Billable in the system
        Date d = system.today();
        String str = 'SELECT Id, pse__Start_Date__c, pse__End_Date__c, pse__Resource__c, Start_of_The_Week__c, End_of_Month_Calculator__c, Today__c, pse__Project__c, pse__Is_Billable__c FROM pse__Assignment__c WHERE pse__End_date__c >: d';
        return Database.getQueryLocator(str);
    }
	
    global void execute(Database.BatchableContext ctx, List<pse__Assignment__c> TCs_to_create)
    {

        List<Date> HolidayList = new List<Date>();
        List<pse__HolidayObj__c> tempHolidayList = [SELECT pse__Date__c from pse__HolidayObj__c];
        for (pse__HolidayObj__c holiday : tempHolidayList) {
            HolidayList.add(holiday.pse__Date__c);
            system.debug('holiday ' + HolidayList);
        }
        
        //Map to store all the PTO requests in. We will only store PTO requests for the current month
        Map<String,map<String, Object>> ptoMap  = new Map<String,map<String, Object>>();
        Map<String,Object> PTOValues = new Map<String,Object>();
        
        List<Time_Off_Request__c> tempPTOList = [SELECT Employee__c, Total_Days_Off__c , First_Day_Off__c, Last_Day_Off__c FROM Time_Off_Request__c];
            for(Time_Off_Request__c PTO : tempPTOList) {
                PTOValues.put('PTO ID', PTO.id);
                PTOValues.put('PTO First Day Off', PTO.First_Day_Off__c);
                PTOValues.put('PTO Last Day Off', PTO.Last_Day_Off__c);
                PTOValues.put('employee', PTO.Employee__c);
                PTOValues.put('NumberOfDays', PTO.Total_Days_Off__c);
                ptoMap.put(pto.employee__c,PTOValues);

                system.debug('ptoValues ' + PTOValues);
            }
        
        List<pse__Timecard_Header__c> timeCardList = new List<pse__Timecard_Header__c> (); 
        list<Date> firstDayOff = new List<Date>();
         
        for (pse__Assignment__c ass : TCs_to_create) {

            map<string, datetime> endDateList = new map<string, datetime>();

            /////////////////////////////////////////////
            // Get the correct hours for the correct Days 
            DateTime startDate = ass.Start_of_The_Week__c ;
            system.debug('Original Start Date ' + startDate);

            if(ass.pse__End_Date__c > ass.End_of_Month_Calculator__c){
                DateTime endDate = ass.End_of_Month_Calculator__c;
                endDateList.put('endDate', endDate);
                system.debug('endDate1 ' + endDate);
            }
            else if (ass.pse__End_Date__c < ass.End_of_Month_Calculator__c){
                DateTime endDate = ass.pse__End_Date__c;
                 endDateList.put('endDate', endDate);
                system.debug('endDate2 ' + endDate); 
            }
    
            Date startDateTC = ass.Start_of_The_Week__c;
            
            map<String, Integer> hours = new Map<String, Integer>();
            Map<String, DateTime> secondTC = new Map<String, DateTime>();
            list<string> Days = new List<String>();
            list<date> PtoStartDate = new list<date>();
                       
            pse__Timecard_Header__c tch = new pse__Timecard_Header__c();
            	tch.CurrencyIsoCode = 'USD';
            	tch.pse__Project__c = ass.pse__Project__c;
            	tch.pse__Assignment__c = ass.id;
            	tch.pse__Resource__c = ass.pse__Resource__c;
            	tch.pse__Start_Date__c = startDateTC;	
            	tch.pse__End_Date__c = startDateTC.addDays(6);
            	tch.pse__Billable__c = true;
            	tch.pse__Time_Credited__c = true;
            	tch.pse__Time_Excluded__c = false;
            	tch.pse__Bill_Rate__c = null;
            	tch.pse__Cost_Rate_Amount__c = null;
            	tch.pse__Cost_Rate_Currency_Code__c = null;
            	tch.pse__Status__c = 'Saved';
            	tch.pse__Submitted__c = False;
            	tch.pse__Approved__c = False;
            	tch.pse__Include_In_Financials__c = False;
            
                //now we search the current resource for PTO and take those days out of the TC creation

at the very bottom how can I pull out the PTOmap pto.employee__c so that I can use it to compare it to the tch.pse__Resource__c value? 

My logic is that if there are any PTO requests in the PTO map where the pto.employee__c = tch.pse__Resource__c then I want to populate a list with the associated PTO start dates associated with the specific tch.pse__Resource__c? 

Any help would be GREATLY appreciated