Guest User

Untitled

a guest
May 16th, 2018
136
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. -(void) slotShifts
  2.  
  3. {
  4.     for (int loop = 0; loop < 5; loop++){
  5.         BOOL result = TRUE;
  6.         printf("------------------------+++++++++++LOOP:%i\n", loop);
  7.         while (result) {
  8.             result = FALSE;
  9.     for (int y = 0; y < [empStorage count]; y++) // this cycles
  10.                                                 //through the employees
  11.     {
  12.         for (int x = 0; x < DAYCOUNT; x++) // change the 3 to 7 once
  13.                                         //all days are allocated
  14.         {
  15.             BOOL plCheck = [self placementCheck:[[dayStorage objectAtIndex:x]
  16.                             objectAtIndex:0] withEmp:[[[empStorage objectAtIndex:y]
  17.                             objectAtIndex:6]intValue]];
  18.             if (plCheck) { //checks if employee and shift are both
  19.                          //the same placement, i.e. FOH or BOH
  20.                
  21.                
  22.                
  23.             //for each shift
  24.             for (int j = 1; j < [[dayStorage objectAtIndex:x]count];j++)
  25.             {
  26.                
  27.                 if ([[[dayStorage objectAtIndex:x] // checks if shift is available
  28.                       objectAtIndex:j]count] == 2) {
  29.                
  30.            
  31.         if ([[[[empStorage objectAtIndex:y] // this checks if the employee is
  32.                objectAtIndex:4]             // available this day to work
  33.               objectAtIndex:x]intValue]
  34.             == 1) {
  35.            
  36.        
  37.             BOOL curWorking = [self currentlyWorking:[[empStorage objectAtIndex:y]
  38.                                         objectAtIndex:0]onDay:x andShift:j];
  39.             //before and after test to see if employee is currently working
  40.             if (!curWorking) {
  41.            
  42.            
  43.         // this takes the shift's end time and subtracts the
  44.         // start time to get the hours of a shift. Then it
  45.         // adds the already accumulated hours the employee has
  46.         int z =
  47.         ([[[[dayStorage objectAtIndex:x]objectAtIndex:j]
  48.             objectAtIndex:1]intValue] - [[[[dayStorage objectAtIndex:x]
  49.                                 objectAtIndex:j]objectAtIndex:0]intValue]) +
  50.             [[[empStorage objectAtIndex:y]objectAtIndex:5]intValue];
  51.        
  52.            
  53.         // following if checks if max hours have been met  
  54.         if ( z <
  55.             [[[empStorage objectAtIndex:y]objectAtIndex:1]intValue]) {
  56.  
  57.            
  58.         //PAY ATTENTION
  59.         //PAY ATTENTION
  60.         //LOOK AT THIS
  61.         //HERE IS THE PART THAT YOU NEED TO LOOK AT
  62.         // this adds the employee at the scheduled time
  63.         // IMPORTANT: everything after this point should be setting
  64.         // new values rather than checks because the shift has
  65.         // ALREADY BEEN SLOTTED
  66.         [self addEmp:[empStorage objectAtIndex:y]
  67.                toDay:[dayStorage objectAtIndex:x]
  68.                 toShift:j];
  69.             printf(".\n");
  70.            
  71.            
  72.             // this replaces the accumulated hours with the new total, z.
  73.             [[empStorage objectAtIndex:y]replaceObjectAtIndex:5
  74.                             withObject:[NSNumber numberWithInt:z]];
  75.             result = TRUE;
  76.             //[self printTest];
  77.            
  78.                 }//endif hrs max met
  79.             } //endif currently working
  80.             } //endif day available
  81.                 } //endif shift available
  82.             } //end for each shift in day loop
  83.             }//end if placement is correct
  84.         }//end for each day in the week
  85.     }//end for each employee
  86.         }//end while loop  
  87.     }//end for loop of whole thing for redundancy
  88. }//end method
Add Comment
Please, Sign In to add comment