Example #1
0
 private function createBookings(Status $logger, array $clockingDataItems, array $bookingTypesByIdentifier, PropelPDO $con)
 {
     $bookings = array();
     foreach ($clockingDataItems as $itemIndex => $clockingDataItem) {
         $clocking = $clockingDataItem->clocking;
         $row = $clockingDataItem->row;
         $clockingType = $clocking->getClockingType($con);
         if ($clockingType === null) {
             throw new Exception('Could not find clocking type #' . $clocking->getTypeId() . ' for clocking #' . $clocking->getId() . '.');
         }
         $typeIdentifier = $clockingType->getIdentifier();
         $bookingType = $this->getBookingType($typeIdentifier, $bookingTypesByIdentifier);
         if ($bookingType === null) {
             $logger->info('No booking type found for clocking type "' . $typeIdentifier . '" in clocking ' . $clocking->getId() . ' "' . $clocking->getComment() . '".');
             continue;
         }
         $flexitime = (int) round($row['flexitime'] * 60);
         $overtime = (int) round($row['overtime'] * 60);
         $start = (int) $clocking->getStart('U');
         $startDay = strtotime('today', $start);
         $end = (int) $clocking->getEnd('U');
         // Create bookings corresponding directly to clockings
         switch ($typeIdentifier) {
             case 'vacation':
             case 'sick_leave':
             case 'education':
                 $start = $startDay;
                 $end = strtotime('tomorrow', $end);
                 $duration = BookingTypePeer::timeToDuration($start, $end, 0, $bookingType->getUnit(), BookingTypePeer::ROUND_NEAREST);
                 $dateText = $clocking->getStart('Y-m-d');
                 if ($start !== $end) {
                     $dateText .= ' - ' . $clocking->getEnd('Y-m-d');
                 }
                 break;
             case 'regular':
             case 'reduce_overtime':
                 if ($typeIdentifier === 'reduce_overtime' and $overtime !== 0) {
                     $duration = BookingTypePeer::timeToDuration(0, $overtime, 0, $bookingType->getUnit(), BookingTypePeer::ROUND_NEAREST);
                 } else {
                     // Do not subtract flexitime from regular work time
                     // if it is negative. Negative values only reflect work
                     // days where someone works less time than expected.
                     $duration = BookingTypePeer::timeToDuration($start, $end - ($flexitime > 0 ? $flexitime : 0) - $overtime, $clocking->getBreaktime(), $bookingType->getUnit(), BookingTypePeer::ROUND_NEAREST);
                 }
                 $dateText = $clocking->getStart('Y-m-d H:i');
                 if ($start !== $end) {
                     $dateText .= ' - ' . $clocking->getEnd(($startDay === strtotime('today', $end) ? '' : 'Y-m-d ') . 'H:i');
                 }
                 break;
             default:
                 $logger->info('Skipping clocking #' . $clocking->getId() . ' with unknown type "' . $typeIdentifier . '".');
                 continue;
         }
         $comment = trim($dateText . ' ' . $clocking->getComment());
         $bookings[] = $this->createBooking($bookingType, $comment, $duration);
         // Add flexitime / over-time bookings
         if ($flexitime !== 0) {
             $bookings[] = $this->createBooking($bookingTypesByIdentifier['flexitime'], $comment, BookingTypePeer::timeToDuration(0, $flexitime, 0, $bookingType->getUnit(), BookingTypePeer::ROUND_NEAREST));
         }
         // "reduce_overtime" is booked as type "overtime" already,
         // so do not book it again
         if ($overtime !== 0 and $bookingType->getIdentifier() !== 'overtime') {
             $bookings[] = $this->createBooking($bookingTypesByIdentifier['overtime'], $comment, BookingTypePeer::timeToDuration(0, $overtime, 0, $bookingType->getUnit(), BookingTypePeer::ROUND_NEAREST));
         }
     }
     return $bookings;
 }
Example #2
0
 protected function _BOOKINGTIME($elem)
 {
     $unit = $elem['UNIT'];
     $start = $elem['START'];
     $end = $elem['END'];
     $break = $elem['BREAK'];
     $round = $elem['ROUND'];
     if ((string) $round === '') {
         $round = BookingTypePeer::ROUND_CEIL;
     }
     return BookingTypePeer::timeToDuration($start, $end, $break, $unit, $round);
 }