Esempio n. 1
0
/**
 * Create a new employee
 *
 * @param  array  arguments
 *
 * @return int  employee id
 */
function erp_hr_employee_create($args = array())
{
    global $wpdb;
    $defaults = array('user_email' => '', 'company_id' => erp_get_current_company_id(), 'work' => array('designation' => 0, 'department' => 0, 'location' => '', 'hiring_source' => '', 'hiring_date' => '', 'date_of_birth' => '', 'reporting_to' => 0, 'pay_rate' => '', 'pay_type' => '', 'type' => '', 'status' => ''), 'personal' => array('photo_id' => 0, 'user_id' => 0, 'first_name' => '', 'middle_name' => '', 'last_name' => '', 'other_email' => '', 'phone' => '', 'work_phone' => '', 'mobile' => '', 'address' => '', 'gender' => '', 'marital_status' => '', 'nationality' => '', 'driving_license' => '', 'hobbies' => '', 'user_url' => '', 'description' => ''));
    $posted = array_map('strip_tags_deep', $args);
    $posted = array_map('trim_deep', $posted);
    $data = wp_parse_args($posted, $defaults);
    // some basic validation
    if (empty($data['personal']['first_name'])) {
        return new WP_Error('empty-first-name', __('Please provide the first name.', 'wp-erp'));
    }
    if (empty($data['personal']['last_name'])) {
        return new WP_Error('empty-last-name', __('Please provide the last name.', 'wp-erp'));
    }
    if (!is_email($data['user_email'])) {
        return new WP_Error('invalid-email', __('Please provide a valid email address.', 'wp-erp'));
    }
    // attempt to create the user
    $password = wp_generate_password(12);
    $userdata = array('user_login' => $data['user_email'], 'user_pass' => $password, 'user_email' => $data['user_email'], 'first_name' => $data['personal']['first_name'], 'last_name' => $data['personal']['last_name'], 'display_name' => $data['personal']['first_name'] . ' ' . $data['personal']['last_name'], 'role' => 'employee');
    // if user id exists, do an update
    $user_id = isset($posted['user_id']) ? intval($posted['user_id']) : 0;
    $update = false;
    if ($user_id) {
        $update = true;
        $userdata['ID'] = $user_id;
    }
    $userdata = apply_filters('erp_hr_employee_args', $userdata);
    $user_id = wp_insert_user($userdata);
    if (is_wp_error($user_id)) {
        return $user_id;
    }
    // if reached here, seems like we have success creating the user
    $employee = new \WeDevs\ERP\HRM\Employee($user_id);
    // inserting the user for the first time
    if (!$update) {
        $work = $data['work'];
        if (!empty($work['type'])) {
            $employee->update_employment_status($work['type']);
        }
        // update compensation
        if (!empty($work['pay_rate'])) {
            $pay_type = !empty($work['pay_type']) ? $work['pay_type'] : 'monthly';
            $employee->update_compensation($work['pay_rate'], $pay_type);
        }
        // update job info
        $employee->update_job_info($work['department'], $work['designation'], $work['reporting_to'], $work['location']);
    }
    // update the erp table
    $wpdb->update($wpdb->prefix . 'erp_hr_employees', array('company_id' => (int) $data['company_id'], 'hiring_source' => $data['work']['hiring_source'], 'hiring_date' => $data['work']['hiring_date'], 'date_of_birth' => $data['work']['date_of_birth']), array('user_id' => $user_id));
    foreach ($data['personal'] as $key => $value) {
        update_user_meta($user_id, $key, $value);
    }
    if ($update) {
        do_action('erp_hr_employee_update', $user_id, $data);
    } else {
        do_action('erp_hr_employee_new', $user_id, $data);
    }
    return $user_id;
}
Esempio n. 2
0
/**
 * Assign for schedule leave policy
 *
 * @since 0.1
 *
 * @return void
 */
function erp_hr_apply_policy_schedule()
{
    $active_employes = \WeDevs\ERP\HRM\Models\Employee::select('user_id')->where('status', 'active')->get()->toArray();
    $policies = \WeDevs\ERP\HRM\Models\Leave_Policies::get()->toArray();
    $selected_policy = [];
    $today = date('Y-m-d', strtotime(current_time('mysql')));
    foreach ($active_employes as $key => $employee) {
        $employee_obj = new \WeDevs\ERP\HRM\Employee(intval($employee['user_id']));
        $employee_data = $employee_obj->to_array();
        $department = isset($employee_data['work']['department']) ? $employee_data['work']['department'] : '';
        $designation = isset($employee_data['work']['designation']) ? $employee_data['work']['designation'] : '';
        $gender = isset($employee_data['personal']['gender']) ? $employee_data['personal']['gender'] : '';
        $location = isset($employee_data['work']['location']) ? $employee_data['work']['location'] : '';
        $marital = isset($employee_data['personal']['marital_status']) ? $employee_data['personal']['marital_status'] : '';
        $hire_date = isset($employee_data['work']['hiring_date']) ? $employee_data['work']['hiring_date'] : '';
        $current_time = current_time('mysql');
        $daydiff = count(erp_extract_dates($hire_date, $current_time)) - 1;
        foreach ($policies as $key => $policy) {
            if ($policy['activate'] == 1) {
                erp_hr_apply_new_employee_policy($employee_data, $policy);
                continue;
            }
            $effective_date = date('Y-m-d', strtotime($policy['effective_date']));
            if (strtotime($effective_date) < 0 && $today < $effective_date) {
                continue;
            }
            if ($daydiff <= $policy['execute_day']) {
                continue;
            }
            if ($policy['department'] != '-1' && $policy['department'] != $department) {
                continue;
            }
            if ($policy['designation'] != '-1' && $policy['designation'] != $designation) {
                continue;
            }
            if ($policy['gender'] != '-1' && $policy['gender'] != $gender) {
                continue;
            }
            if ($policy['location'] != '-1' && $policy['location'] != $location) {
                continue;
            }
            if ($policy['marital'] != '-1' && $policy['marital'] != $marital) {
                continue;
            }
            erp_hr_apply_leave_policy(intval($employee['user_id']), $policy);
        }
    }
}
Esempio n. 3
0
 /**
  * Add log when entitlement created
  *
  * @since 0.1
  *
  * @param  integer $entitlement_id
  * @param  array $fields
  *
  * @return void
  */
 public function create_entitlement($entitlement_id, $fields)
 {
     if (!$entitlement_id) {
         return;
     }
     $employee = new \WeDevs\ERP\HRM\Employee(intval($fields['user_id']));
     $message = sprintf('%s <strong>%s</strong>', __('A new entitlement has been created for'), $employee->get_full_name());
     erp_log()->add(['sub_component' => 'leave', 'message' => $message, 'created_by' => get_current_user_id(), 'changetype' => 'add']);
 }
Esempio n. 4
0
        ?>
                        </td>
                        <td>
                            <?php 
        echo !empty($row->category) ? $row->category : '--';
        ?>
                        </td>
                        <td>
                            <?php 
        echo !empty($row->comment) ? $row->comment : '--';
        ?>
                        </td>
                        <td>
                            <?php 
        if (!empty($row->data)) {
            $emp = new \WeDevs\ERP\HRM\Employee(intval($row->data));
            if ($emp->id) {
                echo $emp->get_link();
            }
        }
        ?>
                        </td>
                        <td class="action">
                            <?php 
        if (current_user_can('erp_manage_jobinfo', $employee->id)) {
            ?>
                                <a href="#" class="remove" data-id="<?php 
            echo $row->id;
            ?>
"><span class="dashicons dashicons-trash"></span></a>
                            <?php 
/**
 * Erp dashboard who is out widget
 *
 * @since 0.1
 *
 * @return void
 */
function erp_hr_dashboard_widget_whoisout()
{
    $leave_requests = erp_hr_get_current_month_leave_list();
    $leave_requests_nextmonth = erp_hr_get_next_month_leave_list();
    ?>
    <h4><?php 
    _e('This Month', 'wp-erp');
    ?>
</h4>
    <?php 
    if ($leave_requests) {
        ?>
        <ul class="erp-list list-two-side list-sep">
            <?php 
        foreach ($leave_requests as $key => $leave) {
            ?>
                <?php 
            $employee = new \WeDevs\ERP\HRM\Employee(intval($leave->user_id));
            ?>
                <li>
                    <a href="<?php 
            echo $employee->get_details_url();
            ?>
"><?php 
            echo $employee->get_full_name();
            ?>
</a>
                    <span><i class="fa fa-calendar"></i> <?php 
            echo erp_format_date($leave->start_date, 'M d,y') . ' - ' . erp_format_date($leave->end_date, 'M d,y');
            ?>
</span>
                </li>
            <?php 
        }
        ?>
        </ul>
    <?php 
    } else {
        ?>
        <?php 
        _e('No one is in vacation', 'wp-erp');
        ?>
    <?php 
    }
    ?>
    <hr>
    <h4><?php 
    _e('Next Month', 'wp-erp');
    ?>
</h4>
    <?php 
    if ($leave_requests_nextmonth) {
        ?>
        <ul class="erp-list list-two-side list-sep">
            <?php 
        foreach ($leave_requests_nextmonth as $key => $leave) {
            ?>
                <?php 
            $employee = new \WeDevs\ERP\HRM\Employee(intval($leave->user_id));
            ?>
                <li>
                    <a href="<?php 
            echo $employee->get_details_url();
            ?>
"><?php 
            echo $employee->get_full_name();
            ?>
</a>
                    <span><i class="fa fa-calendar"></i> <?php 
            echo erp_format_date($leave->start_date, 'M d,y') . ' - ' . erp_format_date($leave->end_date, 'M d,y');
            ?>
</span>
                </li>
            <?php 
        }
        ?>
        </ul>
    <?php 
    } else {
        ?>
        <?php 
        _e('No one is vacation on next month', 'wp-erp');
        ?>
    <?php 
    }
    ?>

    <?php 
}
Esempio n. 6
0
</td>
                        <td><?php 
        echo erp_format_date($row->completion_date);
        ?>
</td>
                        <td><?php 
        echo esc_textarea($row->goal_description);
        ?>
</td>
                        <td><?php 
        echo esc_textarea($row->employee_assessment);
        ?>
</td>
                        <td>
                            <?php 
        $reporting_user = new \WeDevs\ERP\HRM\Employee(intval($row->supervisor));
        echo $reporting_user->get_full_name();
        ?>
                        </td>
                        <td><?php 
        echo esc_textarea($row->supervisor_assessment);
        ?>
</td>
                        
                        <td class="action">
                            <?php 
        if (current_user_can('erp_delete_review')) {
            ?>
                                <a href="#" class="performance-remove" data-id="<?php 
            echo $row->id;
            ?>
Esempio n. 7
0
/**
 * Maps HR capabilities to employee or HR manager
 *
 * @param array $caps Capabilities for meta capability
 * @param string $cap Capability name
 * @param int $user_id User id
 * @param mixed $args Arguments
 *
 * @return array Actual capabilities for meta capability
 */
function erp_hr_map_meta_caps($caps = array(), $cap = '', $user_id = 0, $args = array())
{
    // What capability is being checked?
    switch ($cap) {
        case 'erp_view_employee':
        case 'erp_edit_employee':
            $employee_id = isset($args[0]) ? $args[0] : false;
            if ($user_id == $employee_id) {
                $caps = [$cap];
            } else {
                $hr_manager_role = erp_hr_get_manager_role();
                // HR manager can read any employee
                if (user_can($user_id, $hr_manager_role)) {
                    $caps = array($hr_manager_role);
                } else {
                    $caps = ['do_not_allow'];
                }
            }
            break;
        case 'erp_create_review':
            $employee_id = isset($args[0]) ? $args[0] : false;
            $employee = new \WeDevs\ERP\HRM\Employee($employee_id);
            if ($employee->get_reporting_to() && $employee->get_reporting_to()->ID == $user_id) {
                $caps = ['employee'];
            } else {
                $caps = [$cap];
            }
            break;
    }
    return apply_filters('erp_hr_map_meta_caps', $caps, $cap, $user_id, $args);
}