<?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";
Exemple #2
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;
}