| 1 |
<?php |
| 2 |
|
| 3 |
namespace WeDevs\ERP\HRM; |
| 4 |
|
| 5 |
use WeDevs\ERP\Framework\Traits\Hooker; |
| 6 |
|
| 7 |
/** |
| 8 |
* The HRM Class |
| 9 |
* |
| 10 |
* This is loaded in `init` action hook |
| 11 |
*/ |
| 12 |
class Human_Resource { |
| 13 |
|
| 14 |
use Hooker; |
| 15 |
|
| 16 |
private $plugin; |
| 17 |
|
| 18 |
/** |
| 19 |
* Kick-in the class |
| 20 |
* |
| 21 |
* @param \WeDevs_ERP $plugin |
| 22 |
*/ |
| 23 |
public function __construct( \WeDevs_ERP $plugin ) { |
| 24 |
|
| 25 |
// prevent duplicate loading |
| 26 |
if ( did_action( 'erp_hrm_loaded' ) ) { |
| 27 |
return; |
| 28 |
} |
| 29 |
|
| 30 |
$this->plugin = $plugin; |
| 31 |
|
| 32 |
// Define constants |
| 33 |
$this->define_constants(); |
| 34 |
|
| 35 |
// Include required files |
| 36 |
$this->includes(); |
| 37 |
|
| 38 |
// Initialize the classes |
| 39 |
$this->init_classes(); |
| 40 |
|
| 41 |
// Initialize the action hooks |
| 42 |
$this->init_actions(); |
| 43 |
|
| 44 |
// Initialize the filter hooks |
| 45 |
$this->init_filters(); |
| 46 |
|
| 47 |
do_action( 'erp_hrm_loaded' ); |
| 48 |
} |
| 49 |
|
| 50 |
/** |
| 51 |
* Define the plugin constants |
| 52 |
* |
| 53 |
* @return void |
| 54 |
*/ |
| 55 |
private function define_constants() { |
| 56 |
define( 'WPERP_HRM_FILE', __FILE__ ); |
| 57 |
define( 'WPERP_HRM_PATH', dirname( __FILE__ ) ); |
| 58 |
define( 'WPERP_HRM_VIEWS', dirname( __FILE__ ) . '/views' ); |
| 59 |
define( 'WPERP_HRM_JS_TMPL', WPERP_HRM_VIEWS . '/js-templates' ); |
| 60 |
define( 'WPERP_HRM_ASSETS', plugins_url( '/assets', __FILE__ ) ); |
| 61 |
} |
| 62 |
|
| 63 |
/** |
| 64 |
* Include the required files |
| 65 |
* |
| 66 |
* @since 1.0.0 |
| 67 |
* @since 1.2.0 Include CLI class |
| 68 |
* |
| 69 |
* @return void |
| 70 |
*/ |
| 71 |
private function includes() { |
| 72 |
require_once WPERP_HRM_PATH . '/includes/functions-url.php'; |
| 73 |
require_once WPERP_HRM_PATH . '/includes/functions.php'; |
| 74 |
require_once WPERP_HRM_PATH . '/includes/functions-department.php'; |
| 75 |
require_once WPERP_HRM_PATH . '/includes/functions-designation.php'; |
| 76 |
require_once WPERP_HRM_PATH . '/includes/functions-employee.php'; |
| 77 |
require_once WPERP_HRM_PATH . '/includes/functions-leave.php'; |
| 78 |
require_once WPERP_HRM_PATH . '/includes/functions-capabilities.php'; |
| 79 |
require_once WPERP_HRM_PATH . '/includes/functions-dashboard-widgets.php'; |
| 80 |
require_once WPERP_HRM_PATH . '/includes/functions-reporting.php'; |
| 81 |
require_once WPERP_HRM_PATH . '/includes/functions-announcement.php'; |
| 82 |
require_once WPERP_HRM_PATH . '/includes/actions-filters.php'; |
| 83 |
|
| 84 |
// cli command |
| 85 |
if ( defined( 'WP_CLI' ) && WP_CLI ) { |
| 86 |
include WPERP_HRM_PATH . '/includes/cli/commands.php'; |
| 87 |
} |
| 88 |
} |
| 89 |
|
| 90 |
/** |
| 91 |
* Initialize WordPress action hooks |
| 92 |
* |
| 93 |
* @return void |
| 94 |
*/ |
| 95 |
private function init_actions() { |
| 96 |
$this->action( 'admin_enqueue_scripts', 'admin_scripts' ); |
| 97 |
$this->action( 'admin_footer', 'admin_js_templates' ); |
| 98 |
$this->filter( 'erp_rest_api_controllers', 'load_hrm_rest_controllers' ); |
| 99 |
} |
| 100 |
|
| 101 |
/** |
| 102 |
* Initialize WordPress filter hooks |
| 103 |
* |
| 104 |
* @return void |
| 105 |
*/ |
| 106 |
private function init_filters() { |
| 107 |
add_filter( 'erp_settings_pages', array( $this, 'add_settings_page' ) ); |
| 108 |
} |
| 109 |
|
| 110 |
/** |
| 111 |
* Init classes |
| 112 |
* |
| 113 |
* @return void |
| 114 |
*/ |
| 115 |
private function init_classes() { |
| 116 |
new Ajax_Handler(); |
| 117 |
new Form_Handler(); |
| 118 |
new Announcement(); |
| 119 |
new Admin\Admin_Menu(); |
| 120 |
new Admin\User_Profile(); |
| 121 |
new Hr_Log(); |
| 122 |
new Emailer(); |
| 123 |
} |
| 124 |
|
| 125 |
/** |
| 126 |
* Register HR settings page |
| 127 |
* |
| 128 |
* @param array |
| 129 |
*/ |
| 130 |
public function add_settings_page( $settings = [] ) { |
| 131 |
|
| 132 |
$settings[] = include __DIR__ . '/includes/class-settings.php'; |
| 133 |
|
| 134 |
return $settings; |
| 135 |
} |
| 136 |
|
| 137 |
/** |
| 138 |
* Load admin scripts and styles |
| 139 |
* |
| 140 |
* @param string |
| 141 |
* |
| 142 |
* @return void |
| 143 |
*/ |
| 144 |
public function admin_scripts( $hook ) { |
| 145 |
$hook = str_replace( sanitize_title( __( 'HR Management', 'erp' ) ), 'hr-management', $hook ); |
| 146 |
|
| 147 |
$suffix = ( defined( 'SCRIPT_DEBUG' ) && SCRIPT_DEBUG ) ? '' : '.min'; |
| 148 |
|
| 149 |
wp_enqueue_media(); |
| 150 |
wp_enqueue_script( 'erp-tiptip' ); |
| 151 |
|
| 152 |
if ( 'hr-management_page_erp-hr-employee' == $hook ) { |
| 153 |
wp_enqueue_style( 'erp-sweetalert' ); |
| 154 |
wp_enqueue_script( 'erp-sweetalert' ); |
| 155 |
} |
| 156 |
|
| 157 |
wp_enqueue_script( 'wp-erp-hr', WPERP_HRM_ASSETS . "/js/hrm$suffix.js", array( 'erp-script' ), date( 'Ymd' ), true ); |
| 158 |
wp_enqueue_script( 'wp-erp-hr-leave', WPERP_HRM_ASSETS . "/js/leave$suffix.js", array( |
| 159 |
'erp-script', |
| 160 |
'wp-color-picker' |
| 161 |
), date( 'Ymd' ), true ); |
| 162 |
|
| 163 |
$localize_script = apply_filters( 'erp_hr_localize_script', array( |
| 164 |
'nonce' => wp_create_nonce( 'wp-erp-hr-nonce' ), |
| 165 |
'popup' => array( |
| 166 |
'dept_title' => __( 'New Department', 'erp' ), |
| 167 |
'dept_submit' => __( 'Create Department', 'erp' ), |
| 168 |
'location_title' => __( 'New Location', 'erp' ), |
| 169 |
'location_submit' => __( 'Create Location', 'erp' ), |
| 170 |
'dept_update' => __( 'Update Department', 'erp' ), |
| 171 |
'desig_title' => __( 'New Designation', 'erp' ), |
| 172 |
'desig_submit' => __( 'Create Designation', 'erp' ), |
| 173 |
'desig_update' => __( 'Update Designation', 'erp' ), |
| 174 |
'employee_title' => __( 'New Employee', 'erp' ), |
| 175 |
'employee_create' => __( 'Create Employee', 'erp' ), |
| 176 |
'employee_update' => __( 'Update Employee', 'erp' ), |
| 177 |
'employment_status' => __( 'Employment Status', 'erp' ), |
| 178 |
'update_status' => __( 'Update', 'erp' ), |
| 179 |
'policy' => __( 'Leave Policy', 'erp' ), |
| 180 |
'policy_create' => __( 'Create Policy', 'erp' ), |
| 181 |
'holiday' => __( 'Holiday', 'erp' ), |
| 182 |
'holiday_create' => __( 'Create Holiday', 'erp' ), |
| 183 |
'holiday_update' => __( 'Update Holiday', 'erp' ), |
| 184 |
'new_leave_req' => __( 'Leave Request', 'erp' ), |
| 185 |
'take_leave' => __( 'Send Leave Request', 'erp' ), |
| 186 |
'terminate' => __( 'Terminate', 'erp' ), |
| 187 |
'leave_reject' => __( 'Reject Reason', 'erp' ), |
| 188 |
'already_terminate' => __( 'Sorry, this employee is already terminated', 'erp' ), |
| 189 |
'already_active' => __( 'Sorry, this employee is already active', 'erp' ) |
| 190 |
), |
| 191 |
'asset_url' => WPERP_ASSETS, |
| 192 |
'emp_upload_photo' => __( 'Upload Photo', 'erp' ), |
| 193 |
'emp_set_photo' => __( 'Set Photo', 'erp' ), |
| 194 |
'confirm' => __( 'Are you sure?', 'erp' ), |
| 195 |
'delConfirmDept' => __( 'Are you sure to delete this department?', 'erp' ), |
| 196 |
'delConfirmPolicy' => __( 'If you delete this policy, the leave entitlements and requests related to it will also be deleted. Are you sure to delete this policy?', 'erp' ), |
| 197 |
'delConfirmHoliday' => __( 'Are you sure to delete this Holiday?', 'erp' ), |
| 198 |
'delConfirmEmployee' => __( 'Are you sure to delete this employee?', 'erp' ), |
| 199 |
'restoreConfirmEmployee' => __( 'Are you sure to restore this employee?', 'erp' ), |
| 200 |
'delConfirmEmployeeNote' => __( 'Are you sure to delete this employee note?', 'erp' ), |
| 201 |
'delConfirmEntitlement' => __( 'Are you sure to delete this Entitlement? If yes, then all leave request under this entitlement also permanently deleted', 'erp' ), |
| 202 |
'make_employee_text' => __( 'This user already exists, Do you want to make this user as a employee?', 'erp' ), |
| 203 |
'employee_exit' => __( 'This employee already exists', 'erp' ), |
| 204 |
'employee_created' => __( 'Employee successfully created', 'erp' ), |
| 205 |
'create_employee_text' => __( 'Click to create employee', 'erp' ), |
| 206 |
'empty_entitlement_text' => sprintf( '<span>%s <a href="%s" title="%s">%s</a></span>', __( 'Please create entitlement first', 'erp' ), add_query_arg( [ |
| 207 |
'page' => 'erp-leave-assign', |
| 208 |
'tab' => 'assignment' |
| 209 |
], admin_url( 'admin.php' ) ), __( 'Create Entitlement', 'erp' ), __( 'Create Entitlement', 'erp' ) ), |
| 210 |
) ); |
| 211 |
|
| 212 |
// if its an employee page |
| 213 |
if ( 'hr-management_page_erp-hr-employee' == $hook ) { |
| 214 |
wp_enqueue_script( 'post' ); |
| 215 |
|
| 216 |
$employee = new Employee(); |
| 217 |
$localize_script['employee_empty'] = $employee->to_array(); |
| 218 |
} |
| 219 |
|
| 220 |
wp_localize_script( 'wp-erp-hr', 'wpErpHr', $localize_script ); |
| 221 |
|
| 222 |
wp_enqueue_style( 'wp-color-picker' ); |
| 223 |
wp_enqueue_style( 'erp-select2' ); |
| 224 |
wp_enqueue_style( 'erp-tiptip' ); |
| 225 |
wp_enqueue_style( 'erp-style' ); |
| 226 |
|
| 227 |
if ( 'hr-management_page_erp-hr-reporting' == $hook ) { |
| 228 |
wp_enqueue_script( 'erp-flotchart' ); |
| 229 |
wp_enqueue_script( 'erp-flotchart-time' ); |
| 230 |
wp_enqueue_script( 'erp-flotchart-pie' ); |
| 231 |
wp_enqueue_script( 'erp-flotchart-orerbars' ); |
| 232 |
wp_enqueue_script( 'erp-flotchart-axislables' ); |
| 233 |
wp_enqueue_script( 'erp-flotchart-valuelabel' ); |
| 234 |
wp_enqueue_style( 'erp-flotchart-valuelabel-css' ); |
| 235 |
} |
| 236 |
} |
| 237 |
|
| 238 |
/** |
| 239 |
* Print JS templates in footer |
| 240 |
* |
| 241 |
* @return void |
| 242 |
*/ |
| 243 |
public function admin_js_templates() { |
| 244 |
global $current_screen; |
| 245 |
|
| 246 |
// main HR menu |
| 247 |
$hook = str_replace( sanitize_title( __( 'HR Management', 'erp' ) ), 'hr-management', $current_screen->base ); |
| 248 |
|
| 249 |
switch ( $hook ) { |
| 250 |
case 'toplevel_page_erp-hr': |
| 251 |
erp_get_js_template( WPERP_HRM_JS_TMPL . '/new-leave-request.php', 'erp-new-leave-req' ); |
| 252 |
erp_get_js_template( WPERP_HRM_JS_TMPL . '/leave-days.php', 'erp-leave-days' ); |
| 253 |
break; |
| 254 |
|
| 255 |
case 'hr-management_page_erp-hr-depts': |
| 256 |
erp_get_js_template( WPERP_HRM_JS_TMPL . '/new-dept.php', 'erp-new-dept' ); |
| 257 |
erp_get_js_template( WPERP_HRM_JS_TMPL . '/row-dept.php', 'erp-dept-row' ); |
| 258 |
break; |
| 259 |
|
| 260 |
case 'hr-management_page_erp-hr-designation': |
| 261 |
erp_get_js_template( WPERP_HRM_JS_TMPL . '/new-designation.php', 'erp-new-desig' ); |
| 262 |
erp_get_js_template( WPERP_HRM_JS_TMPL . '/row-desig.php', 'erp-desig-row' ); |
| 263 |
break; |
| 264 |
|
| 265 |
case 'hr-management_page_erp-hr-employee': |
| 266 |
case 'hr-management_page_erp-hr-my-profile': |
| 267 |
erp_get_js_template( WPERP_HRM_JS_TMPL . '/new-employee.php', 'erp-new-employee' ); |
| 268 |
erp_get_js_template( WPERP_HRM_JS_TMPL . '/row-employee.php', 'erp-employee-row' ); |
| 269 |
erp_get_js_template( WPERP_HRM_JS_TMPL . '/employment-status.php', 'erp-employment-status' ); |
| 270 |
erp_get_js_template( WPERP_HRM_JS_TMPL . '/compensation.php', 'erp-employment-compensation' ); |
| 271 |
erp_get_js_template( WPERP_HRM_JS_TMPL . '/job-info.php', 'erp-employment-jobinfo' ); |
| 272 |
erp_get_js_template( WPERP_HRM_JS_TMPL . '/work-experience.php', 'erp-employment-work-experience' ); |
| 273 |
erp_get_js_template( WPERP_HRM_JS_TMPL . '/education-form.php', 'erp-employment-education' ); |
| 274 |
erp_get_js_template( WPERP_HRM_JS_TMPL . '/performance-reviews.php', 'erp-employment-performance-reviews' ); |
| 275 |
erp_get_js_template( WPERP_HRM_JS_TMPL . '/performance-comments.php', 'erp-employment-performance-comments' ); |
| 276 |
erp_get_js_template( WPERP_HRM_JS_TMPL . '/performance-goals.php', 'erp-employment-performance-goals' ); |
| 277 |
erp_get_js_template( WPERP_HRM_JS_TMPL . '/dependents.php', 'erp-employment-dependent' ); |
| 278 |
erp_get_js_template( WPERP_HRM_JS_TMPL . '/new-dept.php', 'erp-new-dept' ); |
| 279 |
erp_get_js_template( WPERP_HRM_JS_TMPL . '/new-designation.php', 'erp-new-desig' ); |
| 280 |
erp_get_js_template( WPERP_HRM_JS_TMPL . '/employee-terminate.php', 'erp-employment-terminate' ); |
| 281 |
break; |
| 282 |
} |
| 283 |
|
| 284 |
// leave menu |
| 285 |
$hook = str_replace( sanitize_title( __( 'Leave', 'erp' ) ), 'leave', $current_screen->base ); |
| 286 |
|
| 287 |
switch ( $hook ) { |
| 288 |
case 'leave_page_erp-leave-policies': |
| 289 |
erp_get_js_template( WPERP_HRM_JS_TMPL . '/leave-policy.php', 'erp-leave-policy' ); |
| 290 |
break; |
| 291 |
|
| 292 |
case 'leave_page_erp-holiday-assign': |
| 293 |
erp_get_js_template( WPERP_HRM_JS_TMPL . '/holiday.php', 'erp-hr-holiday-js-tmp' ); |
| 294 |
break; |
| 295 |
|
| 296 |
case 'toplevel_page_erp-leave': |
| 297 |
erp_get_js_template( WPERP_HRM_JS_TMPL . '/leave-reject.php', 'erp-hr-leave-reject-js-tmp' ); |
| 298 |
break; |
| 299 |
|
| 300 |
default: |
| 301 |
# code... |
| 302 |
break; |
| 303 |
} |
| 304 |
|
| 305 |
} |
| 306 |
|
| 307 |
|
| 308 |
/** |
| 309 |
* Load HRM rest controllers |
| 310 |
* |
| 311 |
* @since 1.3.0 |
| 312 |
* |
| 313 |
* @param $controller |
| 314 |
* |
| 315 |
* @return array |
| 316 |
*/ |
| 317 |
public function load_hrm_rest_controllers( $controller ) { |
| 318 |
$hrm_controller = [ |
| 319 |
'\WeDevs\ERP\HRM\API\Employees_Controller', |
| 320 |
'\WeDevs\ERP\HRM\API\Departments_Controller', |
| 321 |
'\WeDevs\ERP\HRM\API\Designations_Controller', |
| 322 |
'\WeDevs\ERP\HRM\API\Birthdays_Controller', |
| 323 |
'\WeDevs\ERP\HRM\API\HRM_Reports_Controller', |
| 324 |
'\WeDevs\ERP\HRM\API\Leave_Entitlements_Controller', |
| 325 |
'\WeDevs\ERP\HRM\API\Leave_Holidays_Controller', |
| 326 |
'\WeDevs\ERP\HRM\API\Leave_Policies_Controller', |
| 327 |
'\WeDevs\ERP\HRM\API\Leave_Requests_Controller', |
| 328 |
'\WeDevs\ERP\HRM\API\Announcements_Controller', |
| 329 |
'\WeDevs\ERP\HRM\API\Company_Controller', |
| 330 |
]; |
| 331 |
$hrm_controller = apply_filters( 'erp_hrm_rest_api_controllers', $hrm_controller ); |
| 332 |
|
| 333 |
return array_merge( $controller, $hrm_controller ); |
| 334 |
} |
| 335 |
} |
| 336 |
|
| 337 |
|