コード例 #1
0
ファイル: class-ajax.php プロジェクト: ediamin/wp-erp
 /**
  * Employee Termination
  *
  * @since 0.1
  *
  * @return json
  */
 public function employee_terminate()
 {
     $this->verify_nonce('employee_update_terminate');
     $employee_id = isset($_POST['employee_id']) ? intval($_POST['employee_id']) : 0;
     $terminate_date = empty($_POST['terminate_date']) ? current_time('mysql') : $_POST['terminate_date'];
     $termination_type = isset($_POST['termination_type']) ? $_POST['termination_type'] : '';
     $termination_reason = isset($_POST['termination_reason']) ? $_POST['termination_reason'] : '';
     $eligible_for_rehire = isset($_POST['eligible_for_rehire']) ? $_POST['eligible_for_rehire'] : '';
     $requires = ['terminate_date' => __('Termination Date', 'wp-erp'), 'termination_type' => __('Termination Type', 'wp-erp'), 'termination_reason' => __('Termination Reason', 'wp-erp'), 'eligible_for_rehire' => __('Eligible for Hire', 'wp-erp')];
     $fields = ['terminate_date' => $terminate_date, 'termination_type' => $termination_type, 'termination_reason' => $termination_reason, 'eligible_for_rehire' => $eligible_for_rehire];
     foreach ($requires as $var_name => $label) {
         if (!${$var_name}) {
             $this->send_error(sprintf(__('%s is required', 'wp-erp'), $label));
         }
     }
     $employee = new \WeDevs\ERP\HRM\Models\Employee();
     $employee->where('user_id', $employee_id)->update(['status' => 'terminated', 'termination_date' => $terminate_date]);
     update_user_meta($employee_id, '_erp_hr_termination', $fields);
     $this->send_success();
 }
コード例 #2
0
ファイル: functions-employee.php プロジェクト: ediamin/wp-erp
/**
 * Count trash employee
 *
 * @since 0.1
 *
 * @return int [no of trash employee]
 */
function erp_hr_count_trashed_employees()
{
    $employee = new \WeDevs\ERP\HRM\Models\Employee();
    return $employee->onlyTrashed()->count();
}
コード例 #3
0
/**
 * Create a new employee when a user role is changed to employee
 *
 * @param  int  $user_id
 * @param  string  $role
 *
 * @return void
 */
function erp_hr_existing_role_to_employee($user_id, $role)
{
    if ('employee' != $role) {
        return;
    }
    // check if a employee of that ID exists, otherwise create one
    $employee = new \WeDevs\ERP\HRM\Models\Employee();
    $exists = $employee->where('user_id', '=', $user_id)->get()->first();
    if (null === $exists) {
        $employee->create(['user_id' => $user_id, 'designation' => 0, 'department' => 0, 'status' => 'active']);
    }
}