Exemplo n.º 1
0
 /**
  * Get all data for displaying the timesheet.
  * @return array
  */
 function getTimeSheetData($user_id, $base_date, $data = FALSE)
 {
     if ($user_id == '') {
         //This isn't really permission issue, but in cases where the user can't see any employees timesheets, we want to display an error to them at least.
         //return $this->returnHandler( FALSE );
         return $this->getPermissionObject()->PermissionDenied();
     }
     if ($base_date == '') {
         return $this->returnHandler(FALSE);
     }
     $profile_start = microtime(TRUE);
     if (!$this->getPermissionObject()->Check('punch', 'enabled') or !($this->getPermissionObject()->Check('punch', 'view') or $this->getPermissionObject()->Check('punch', 'view_child') or $this->getPermissionObject()->Check('punch', 'view_own'))) {
         return $this->getPermissionObject()->PermissionDenied();
     }
     //Get Permission Hierarchy Children first, as this can be used for viewing, or editing.
     //Check for ===FALSE on permission_children_ids, as that means their are no children assigned to them and they don't have view all permissions.
     $data['filter_data']['permission_children_ids'] = $this->getPermissionObject()->getPermissionChildren('punch', 'view');
     if ($data['filter_data']['permission_children_ids'] === FALSE or is_array($data['filter_data']['permission_children_ids']) and !in_array($user_id, $data['filter_data']['permission_children_ids'])) {
         return $this->getPermissionObject()->PermissionDenied();
     }
     //
     //Get timesheet start/end dates.
     //
     $timesheet_dates = $this->getTimesheetDates($base_date);
     //Include all dates within the timesheet range.
     $timesheet_dates['pay_period_date_map'] = array();
     //Add array containing date => pay_period_id pairs.
     //
     //Get PayPeriod information
     //
     $pplf = TTnew('PayPeriodListFactory');
     $pplf->StartTransaction();
     //Make sure we all pay periods that fall within the start/end date, so we can properly display the timesheet range at the top.
     $primary_pay_period_id = 0;
     $pay_period_ids = array();
     $pplf->getByUserIdAndOverlapStartDateAndEndDate($user_id, $timesheet_dates['start_date'], $timesheet_dates['end_date']);
     if ($pplf->getRecordCount() > 0) {
         foreach ($pplf as $pp_obj) {
             $pay_period_ids[] = $pp_obj->getId();
             if ($pp_obj->getStartDate() <= $timesheet_dates['base_date'] and $pp_obj->getEndDate() >= $timesheet_dates['base_date']) {
                 $primary_pay_period_id = $pp_obj->getId();
             }
             $timesheet_dates['pay_period_date_map'] += (array) $pp_obj->getPayPeriodDates($timesheet_dates['start_date'], $timesheet_dates['end_date'], TRUE);
         }
         unset($pp_obj);
     }
     //Debug::Text('Pay Periods: '. $pplf->getRecordCount() .' Primary Pay Period: '. $primary_pay_period_id, __FILE__, __LINE__, __METHOD__, 10);
     //Debug::Arr($timesheet_dates, 'TimeSheet Dates: ', __FILE__, __LINE__, __METHOD__, 10);
     //
     //Get punches
     //
     $punch_data = array();
     $filter_data = $this->initializeFilterAndPager(array('filter_data' => array('start_date' => $timesheet_dates['start_date'], 'end_date' => $timesheet_dates['end_date'], 'user_id' => $user_id)), TRUE);
     //Carry over timesheet filter options.
     if (isset($data['filter_data']['branch_id'])) {
         $filter_data['filter_data']['branch_id'] = $data['filter_data']['branch_id'];
     }
     if (isset($data['filter_data']['department_id'])) {
         $filter_data['filter_data']['department_id'] = $data['filter_data']['department_id'];
     }
     if (isset($data['filter_data']['job_id'])) {
         $filter_data['filter_data']['job_id'] = $data['filter_data']['job_id'];
     }
     if (isset($data['filter_data']['job_item_id'])) {
         $filter_data['filter_data']['job_item_id'] = $data['filter_data']['job_item_id'];
     }
     $plf = TTnew('PunchListFactory');
     $plf->getAPISearchByCompanyIdAndArrayCriteria($this->getCurrentCompanyObject()->getId(), $filter_data['filter_data'], $filter_data['filter_items_per_page'], $filter_data['filter_page'], NULL, $filter_data['filter_sort']);
     Debug::Text('Punch Record Count: ' . $plf->getRecordCount(), __FILE__, __LINE__, __METHOD__, 10);
     if ($plf->getRecordCount() > 0) {
         foreach ($plf as $p_obj) {
             //$punch_data[] = $p_obj->getObjectAsArray( NULL, $data['filter_data']['permission_children_ids'] );
             //Don't need to pass permission_children_ids, as Flex uses is_owner/is_child from the timesheet user record instead, not the punch record.
             $punch_data[] = $p_obj->getObjectAsArray();
         }
     }
     $meal_and_break_total_data = PunchFactory::calcMealAndBreakTotalTime($punch_data, TRUE);
     if ($meal_and_break_total_data === FALSE) {
         $meal_and_break_total_data = array();
     }
     //
     //Get total time for day/pay period
     //
     $user_date_total_data = array();
     $udt_filter_data = $this->initializeFilterAndPager(array('filter_data' => array('start_date' => $timesheet_dates['start_date'], 'end_date' => $timesheet_dates['end_date'], 'user_id' => $user_id)), TRUE);
     //Carry over timesheet filter options.
     if (isset($data['filter_data']['branch_id'])) {
         $udt_filter_data['filter_data']['branch_id'] = $data['filter_data']['branch_id'];
     }
     if (isset($data['filter_data']['department_id'])) {
         $udt_filter_data['filter_data']['department_id'] = $data['filter_data']['department_id'];
     }
     if (isset($data['filter_data']['job_id'])) {
         $udt_filter_data['filter_data']['job_id'] = $data['filter_data']['job_id'];
     }
     if (isset($data['filter_data']['job_item_id'])) {
         $udt_filter_data['filter_data']['job_item_id'] = $data['filter_data']['job_item_id'];
     }
     $udtlf = TTnew('UserDateTotalListFactory');
     $udtlf->getAPISearchByCompanyIdAndArrayCriteria($this->getCurrentCompanyObject()->getId(), $udt_filter_data['filter_data'], $udt_filter_data['filter_items_per_page'], $udt_filter_data['filter_page'], NULL, $udt_filter_data['filter_sort']);
     Debug::Text('User Date Total Record Count: ' . $udtlf->getRecordCount(), __FILE__, __LINE__, __METHOD__, 10);
     if ($udtlf->getRecordCount() > 0) {
         foreach ($udtlf as $udt_obj) {
             //Don't need to pass permission_children_ids, as Flex uses is_owner/is_child from the timesheet user record instead, not the punch record.
             //$user_date_total = $udt_obj->getObjectAsArray( NULL, $data['filter_data']['permission_children_ids'] );
             $user_date_total = $udt_obj->getObjectAsArray();
             $user_date_total_data[] = $user_date_total;
             //Get all pay periods that have total time assigned to them.
             $timesheet_dates['pay_period_date_map'][$user_date_total['date_stamp']] = $pay_period_ids[] = $user_date_total['pay_period_id'];
             //Adjust primary pay period if the pay period schedules were changed mid-way through perhaps.
             if ($timesheet_dates['base_display_date'] == $user_date_total['date_stamp'] and $timesheet_dates['pay_period_date_map'][$user_date_total['date_stamp']] != $primary_pay_period_id) {
                 $primary_pay_period_id = $user_date_total['pay_period_id'];
                 Debug::Text('Changing primary pay period to: ' . $primary_pay_period_id, __FILE__, __LINE__, __METHOD__, 10);
             }
         }
         unset($user_date_total);
     }
     Debug::Arr($timesheet_dates['pay_period_date_map'], 'Date/Pay Period IDs. Primary Pay Period ID: ' . $primary_pay_period_id, __FILE__, __LINE__, __METHOD__, 10);
     $accumulated_user_date_total_data = UserDateTotalFactory::calcAccumulatedTime($user_date_total_data, TRUE);
     if ($accumulated_user_date_total_data === FALSE) {
         $accumulated_user_date_total_data = array();
     }
     //Get data for all pay periods
     $pay_period_data = array();
     $pplf->getByIDList($pay_period_ids);
     if ($pplf->getRecordCount() > 0) {
         foreach ($pplf as $pp_obj) {
             $pay_period_data[$pp_obj->getId()] = $pp_obj->getObjectAsArray();
             $pay_period_data[$pp_obj->getId()]['timesheet_verify_type_id'] = $pp_obj->getTimeSheetVerifyType();
         }
     }
     unset($pp_obj);
     $pp_user_date_total_data = array();
     $pay_period_accumulated_user_date_total_data = array();
     if (isset($primary_pay_period_id) and $primary_pay_period_id > 0) {
         $pp_udt_filter_data = $this->initializeFilterAndPager(array('filter_data' => array('pay_period_id' => $primary_pay_period_id, 'user_id' => $user_id)), TRUE);
         //Carry over timesheet filter options.
         if (isset($data['filter_data']['branch_id'])) {
             $pp_udt_filter_data['filter_data']['branch_id'] = $data['filter_data']['branch_id'];
         }
         if (isset($data['filter_data']['department_id'])) {
             $pp_udt_filter_data['filter_data']['department_id'] = $data['filter_data']['department_id'];
         }
         if (isset($data['filter_data']['job_id'])) {
             $pp_udt_filter_data['filter_data']['job_id'] = $data['filter_data']['job_id'];
         }
         if (isset($data['filter_data']['job_item_id'])) {
             $pp_udt_filter_data['filter_data']['job_item_id'] = $data['filter_data']['job_item_id'];
         }
         $udtlf = TTnew('UserDateTotalListFactory');
         $udtlf->getAPISearchByCompanyIdAndArrayCriteria($this->getCurrentCompanyObject()->getId(), $pp_udt_filter_data['filter_data'], $pp_udt_filter_data['filter_items_per_page'], $pp_udt_filter_data['filter_page'], NULL, $pp_udt_filter_data['filter_sort']);
         Debug::Text('PP User Date Total Record Count: ' . $udtlf->getRecordCount(), __FILE__, __LINE__, __METHOD__, 10);
         if ($udtlf->getRecordCount() > 0) {
             foreach ($udtlf as $udt_obj) {
                 $pp_user_date_total_data[] = $udt_obj->getObjectAsArray();
             }
             $pay_period_accumulated_user_date_total_data = UserDateTotalFactory::calcAccumulatedTime($pp_user_date_total_data, TRUE);
             if (isset($pay_period_accumulated_user_date_total_data['total'])) {
                 $pay_period_accumulated_user_date_total_data = $pay_period_accumulated_user_date_total_data['total'];
             } else {
                 $pay_period_accumulated_user_date_total_data = array();
             }
         }
     }
     //
     //Get Exception data, use the same filter data as punches.
     //
     $exception_data = array();
     $elf = TTnew('ExceptionListFactory');
     $elf->getAPISearchByCompanyIdAndArrayCriteria($this->getCurrentCompanyObject()->getId(), $filter_data['filter_data'], $filter_data['filter_items_per_page'], $filter_data['filter_page'], NULL, $filter_data['filter_sort']);
     Debug::Text('Exception Record Count: ' . $elf->getRecordCount(), __FILE__, __LINE__, __METHOD__, 10);
     if ($elf->getRecordCount() > 0) {
         foreach ($elf as $e_obj) {
             $exception_data[] = $e_obj->getObjectAsArray();
         }
     }
     //
     //Get request data, so authorized/pending can be shown in a request row for each day.
     //If there are two requests for both authorized and pending, the pending is displayed.
     //
     $request_data = array();
     $rlf = TTnew('RequestListFactory');
     $rlf->getAPISearchByCompanyIdAndArrayCriteria($this->getCurrentCompanyObject()->getId(), $filter_data['filter_data'], $filter_data['filter_items_per_page'], $filter_data['filter_page'], NULL, $filter_data['filter_sort']);
     Debug::Text('Request Record Count: ' . $rlf->getRecordCount(), __FILE__, __LINE__, __METHOD__, 10);
     if ($rlf->getRecordCount() > 0) {
         foreach ($rlf as $r_obj) {
             $request_data[] = $r_obj->getObjectAsArray();
         }
     }
     //
     //Get timesheet verification information.
     //
     $timesheet_verify_data = array();
     if (isset($primary_pay_period_id) and $primary_pay_period_id > 0) {
         $pptsvlf = TTnew('PayPeriodTimeSheetVerifyListFactory');
         $pptsvlf->getByPayPeriodIdAndUserId($primary_pay_period_id, $user_id);
         if ($pptsvlf->getRecordCount() > 0) {
             $pptsv_obj = $pptsvlf->getCurrent();
             $pptsv_obj->setCurrentUser($this->getCurrentUserObject()->getId());
         } else {
             $pptsv_obj = $pptsvlf;
             $pptsv_obj->setCurrentUser($this->getCurrentUserObject()->getId());
             $pptsv_obj->setUser($user_id);
             $pptsv_obj->setPayPeriod($primary_pay_period_id);
             //$pptsv_obj->setStatus( 45 ); //Pending Verification
         }
         $verification_window_dates = $pptsv_obj->getVerificationWindowDates();
         if (is_array($verification_window_dates)) {
             $verification_window_dates['start'] = TTDate::getAPIDate('DATE', $verification_window_dates['start']);
             $verification_window_dates['end'] = TTDate::getAPIDate('DATE', $verification_window_dates['end']);
         }
         $timesheet_verify_data = array('id' => $pptsv_obj->getId(), 'user_verified' => $pptsv_obj->getUserVerified(), 'user_verified_date' => $pptsv_obj->getUserVerifiedDate(), 'status_id' => $pptsv_obj->getStatus(), 'status' => Option::getByKey($pptsv_obj->getStatus(), $pptsv_obj->getOptions('status')), 'pay_period_id' => $pptsv_obj->getPayPeriod(), 'user_id' => $pptsv_obj->getUser(), 'authorized' => $pptsv_obj->getAuthorized(), 'authorized_users' => $pptsv_obj->getAuthorizedUsers(), 'is_hierarchy_superior' => $pptsv_obj->isHierarchySuperior(), 'display_verify_button' => $pptsv_obj->displayVerifyButton(), 'verification_box_color' => $pptsv_obj->getVerificationBoxColor(), 'verification_status_display' => $pptsv_obj->getVerificationStatusDisplay(), 'previous_pay_period_verification_display' => $pptsv_obj->displayPreviousPayPeriodVerificationNotice(), 'verification_confirmation_message' => $pptsv_obj->getVerificationConfirmationMessage(), 'verification_window_dates' => $verification_window_dates, 'created_date' => $pptsv_obj->getCreatedDate(), 'created_by' => $pptsv_obj->getCreatedBy(), 'updated_date' => $pptsv_obj->getUpdatedDate(), 'updated_by' => $pptsv_obj->getUpdatedBy(), 'deleted_date' => $pptsv_obj->getDeletedDate(), 'deleted_by' => $pptsv_obj->getDeletedBy());
         unset($pptsvlf, $pptsv_obj, $verification_window_dates);
         if (isset($pay_period_data[$primary_pay_period_id])) {
             $timesheet_verify_data['pay_period_verify_type_id'] = $pay_period_data[$primary_pay_period_id]['timesheet_verify_type_id'];
         }
     }
     //
     //Get holiday data.
     //
     $holiday_data = array();
     $hlf = TTnew('HolidayListFactory');
     $hlf->getAPISearchByCompanyIdAndArrayCriteria($this->getCurrentCompanyObject()->getId(), array('start_date' => $timesheet_dates['start_date'], 'end_date' => $timesheet_dates['end_date'], 'user_id' => $user_id), $filter_data['filter_items_per_page'], $filter_data['filter_page'], NULL, $filter_data['filter_sort']);
     Debug::Text('Holiday Record Count: ' . $hlf->getRecordCount(), __FILE__, __LINE__, __METHOD__, 10);
     if ($hlf->getRecordCount() > 0) {
         foreach ($hlf as $h_obj) {
             $holiday_data[] = $h_obj->getObjectAsArray();
         }
     }
     unset($hlf, $h_obj);
     $pplf->CommitTransaction();
     $retarr = array('timesheet_dates' => $timesheet_dates, 'pay_period_data' => $pay_period_data, 'punch_data' => $punch_data, 'holiday_data' => $holiday_data, 'user_date_total_data' => $user_date_total_data, 'accumulated_user_date_total_data' => $accumulated_user_date_total_data, 'pay_period_accumulated_user_date_total_data' => $pay_period_accumulated_user_date_total_data, 'meal_and_break_total_data' => $meal_and_break_total_data, 'exception_data' => $exception_data, 'request_data' => $request_data, 'timesheet_verify_data' => $timesheet_verify_data);
     //Debug::Arr($retarr, 'TimeSheet Data: ', __FILE__, __LINE__, __METHOD__,10);
     Debug::Text('TimeSheet Data: User ID:' . $user_id . ' Base Date: ' . $base_date . ' in: ' . (microtime(TRUE) - $profile_start) . 's', __FILE__, __LINE__, __METHOD__, 10);
     return $this->returnHandler($retarr);
 }
Exemplo n.º 2
0
 function getTotalAccumulatedUserDateTotal($data, $disable_paging = FALSE)
 {
     $retarr = UserDateTotalFactory::calcAccumulatedTime($this->getUserDateTotal($data, TRUE));
     if (isset($retarr['total'])) {
         return $retarr['total'];
     }
     return FALSE;
 }