Пример #1
0
 /**
  * Function get the import/export fields for hrjobcontract
  *
  * @return array self::$_hrjobFields  associative array of hrjobcontract fields
  * @static
  */
 function &getFields()
 {
     if (!self::$_hrjobFields) {
         self::$_hrjobFields = CRM_Hrjobcontract_BAO_HRJobDetails::export();
         self::$_hrjobFields['hrjobcontract_role_manager_contact'] = array('name' => 'manager_contact', 'title' => 'Job Manager', 'type' => CRM_Utils_Type::T_STRING, 'where' => 'civicrm_hrjobcontract_role_manager.display_name');
         self::$_hrjobFields = array_merge(self::$_hrjobFields, CRM_Hrjobcontract_BAO_HRJobHealth::export());
         self::$_hrjobFields = array_merge(self::$_hrjobFields, CRM_Hrjobcontract_BAO_HRJobHour::export());
         // special case to check for existence of health record entry
         /*self::$_hrjobFields['hrjobcontract_health_is_healthcare'] =
           array(
             'name'  => 'is_healthcare',
             'title' => 'Is health care',
             'type'  => CRM_Utils_Type::T_BOOLEAN,
             'where' => 'civicrm_hrjobcontract_health.id'
           );*/
         self::$_hrjobFields = array_merge(self::$_hrjobFields, CRM_Hrjobcontract_BAO_HRJobLeave::export());
         self::$_hrjobFields = array_merge(self::$_hrjobFields, CRM_Hrjobcontract_BAO_HRJobPay::export());
         self::$_hrjobFields = array_merge(self::$_hrjobFields, CRM_Hrjobcontract_BAO_HRJobPension::export());
         self::$_hrjobFields = array_merge(self::$_hrjobFields, CRM_Hrjobcontract_BAO_HRJobRole::export());
     }
     return self::$_hrjobFields;
 }
<?php

echo "Script started.\n";
$timeStart = time();
$jobContracts = CRM_Core_DAO::executeQuery('SELECT * FROM civicrm_hrjobcontract WHERE deleted = 0 ORDER BY id ASC');
$i = 0;
while ($jobContracts->fetch()) {
    echo "Recalculating Absence Entitlement by Job Contract #{$jobContracts->id}...";
    CRM_Hrjobcontract_BAO_HRJobLeave::recalculateAbsenceEntitlement($jobContracts->id);
    echo "OK.\n";
    $i++;
}
$timeEnd = time();
echo "{$i} Job Contracts processed in " . ($timeEnd - $timeStart) . " seconds.\n";
echo "Finished.\n";
Пример #3
0
 static function getLeavesForPeriod($contactId, $startDate = null, $endDate = null)
 {
     $data = CRM_Hrjobcontract_BAO_HRJobLeave::createAbsenceArray();
     $jobContracts = civicrm_api3('HRJobContract', 'get', array('sequential' => 1, 'contact_id' => $contactId, 'deleted' => 0));
     foreach ($jobContracts['values'] as $jobContract) {
         $jobContractDetails = civicrm_api3('HRJobDetails', 'get', array('sequential' => 1, 'jobcontract_id' => $jobContract['id']));
         if (empty($jobContractDetails['values'])) {
             continue;
         }
         $details = CRM_Utils_Array::first($jobContractDetails['values']);
         $details['period_start_date'] = $details['period_start_date'] ? date('Y-m-d H:i:s', strtotime($details['period_start_date'])) : null;
         $details['period_end_date'] = $details['period_end_date'] ? date('Y-m-d H:i:s', strtotime($details['period_end_date'])) : null;
         if (CRM_Hrjobcontract_BAO_HRJobLeave::isJobDetailsInPeriod($details, $startDate, $endDate)) {
             $leaves = civicrm_api3('HRJobLeave', 'get', array('sequential' => 1, 'jobcontract_id' => $jobContract['id']));
             foreach ($leaves['values'] as $leave) {
                 $data[$leave['leave_type']] += $leave['leave_amount'];
             }
         }
     }
     return $data;
 }
Пример #4
0
/**
 * HRJobLeave.get API
 *
 * @param array $params
 * @return array API result descriptor
 * @throws API_Exception
 */
function civicrm_api3_h_r_job_leave_replace($params)
{
    $validRevisionId = null;
    if (!empty($params['values'])) {
        foreach ($params['values'] as $leave) {
            if (!empty($leave['id']) && !empty($leave['jobcontract_revision_id'])) {
                $validRevisionId = $leave['jobcontract_revision_id'];
                break;
            }
        }
    }
    $result = _civicrm_hrjobcontract_api3_replace(_civicrm_get_entity_name(_civicrm_api3_get_BAO(__FUNCTION__)), $params, $validRevisionId);
    if (!empty($params['values'])) {
        $firstLeaveEntry = CRM_Utils_Array::first($params['values']);
        $jobContractId = isset($firstLeaveEntry['jobcontract_id']) ? $firstLeaveEntry['jobcontract_id'] : null;
        if (!$jobContractId && isset($firstLeaveEntry['jobcontract_revision_id'])) {
            $revision = civicrm_api3('HRJobContractRevision', 'get', array('sequential' => 1, 'id' => $firstLeaveEntry['jobcontract_revision_id']));
            $revisionData = CRM_Utils_Array::first($revision['values']);
            $jobContractId = $revisionData['jobcontract_id'];
        }
        if ($jobContractId) {
            CRM_Hrjobcontract_BAO_HRJobLeave::recalculateAbsenceEntitlement($jobContractId);
        }
    }
    return $result;
}