PluginProbe
ERP: Complete HR, Accounting & CRM Suite Built for WooCommerce / 1.2.6
ERP: Complete HR, Accounting & CRM Suite Built for WooCommerce v1.2.6
1.17.9 1.17.8 1.17.7 1.17.6 1.17.5 1.17.4 1.2.2 1.2.3 1.2.4 1.2.5 1.2.6 1.2.7 1.2.8 1.3.0 1.3.1 1.3.11 1.3.12 1.3.13 1.3.14 1.3.2 1.3.3 1.3.4 1.3.5 1.3.6 1.3.7 All 143 releases
erp / includes / class-install.php

class-install.php in ERP: Complete HR, Accounting & CRM Suite Built for WooCommerce 1.2.6, at includes/class-install.php

1,069 lines 44.4 KB
No matching file
Up and down to move Enter to open Esc to close
Raw Download Zip
1 <?php
2 /**
3 * Installation related functions and actions.
4 *
5 * @author Tareq Hasan
6 * @package ERP
7 */
8
9 // don't call the file directly
10 if ( !defined( 'ABSPATH' ) ) exit;
11
12 /**
13 * Installer Class
14 *
15 * @package ERP
16 */
17 class WeDevs_ERP_Installer {
18
19 use \WeDevs\ERP\Framework\Traits\Hooker;
20
21 /**
22 * Binding all events
23 *
24 * @since 1.0
25 *
26 * @return void
27 */
28 function __construct() {
29 $this->set_default_modules();
30
31 register_activation_hook( WPERP_FILE, array( $this, 'activate' ) );
32 register_deactivation_hook( WPERP_FILE, array( $this, 'deactivate' ) );
33
34 $this->action( 'admin_menu', 'welcome_screen_menu' );
35 $this->action( 'admin_head', 'welcome_screen_menu_remove' );
36 }
37
38 /**
39 * Placeholder for activation function
40 * Nothing being called here yet.
41 *
42 * @since 1.0
43 *
44 * @return void
45 */
46 public function activate() {
47 $current_erp_version = get_option( 'wp_erp_version', null );
48 $current_db_version = get_option( 'wp_erp_db_version', null );
49
50 $this->create_tables();
51 $this->populate_data();
52
53 if ( is_null( $current_erp_version ) ) {
54 $this->set_role();
55 }
56
57 $this->create_roles(); // @TODO: Needs to change later :)
58 $this->create_cron_jobs();
59 $this->setup_default_emails();
60
61 // does it needs any update?
62 $updater = new \WeDevs\ERP\Updates();
63 $updater->perform_updates();
64
65 if ( is_null( $current_erp_version ) && is_null( $current_db_version ) && apply_filters( 'erp_enable_setup_wizard', true ) ) {
66 set_transient( '_erp_activation_redirect', 1, 30 );
67 }
68
69 // update to latest version
70 $latest_version = erp_get_version();
71 update_option( 'wp_erp_version', $latest_version );
72 update_option( 'wp_erp_db_version', $latest_version );
73 }
74
75 /**
76 * Include required files to prevent fatal errors
77 *
78 * @return void
79 */
80 function includes() {
81 include_once WPERP_MODULES . '/hrm/includes/functions-capabilities.php';
82 include_once WPERP_MODULES . '/crm/includes/functions-capabilities.php';
83 include_once WPERP_MODULES . '/accounting/includes/function-capabilities.php';
84 }
85
86 /**
87 * Set default mail subject, heading and body
88 *
89 * @since 1.0
90 *
91 * @return void
92 */
93 function setup_default_emails() {
94
95 //Employee welcome
96 $welcome = [
97 'subject' => 'Welcome {full_name} to {company_name}',
98 'heading' => 'Welcome Onboard {first_name}!',
99 'body' => 'Dear {full_name},
100
101 Welcome aboard as a <strong>{job_title}</strong> in our <strong>{dept_title}</strong> team at <strong>{company_name}</strong>! I am pleased to have you working with us. You were selected for employment due to the attributes that you displayed that appear to match the qualities I look for in an employee.
102
103 I’m looking forward to seeing you grow and develop into an outstanding employee that exhibits a high level of care, concern, and compassion for others. I hope that you will find your work to be rewarding, challenging, and meaningful.
104
105 Your <strong>{type}</strong> employment will start from <strong>{joined_date}</strong> and you will be reporting to <strong>{reporting_to}</strong>.
106
107 Please take your time and review our yearly goals so that you can know what is expected and make a positive contribution. Again, I look forward to seeing you grow as a professional while enhancing the lives of the clients entrusted in your care.
108
109 Sincerely,
110 Manager Name
111 CEO, Company Name
112
113 {login_info}'
114 ];
115
116 update_option( 'erp_email_settings_employee-welcome', $welcome );
117
118 //New Leave Request
119 $new_leave_request = [
120 'subject' => 'New leave request received from {employee_name}',
121 'heading' => 'New Leave Request',
122 'body' => 'Hello,
123
124 A new leave request has been received from {employee_url}.
125
126 <strong>Leave type:</strong> {leave_type}
127 <strong>Date:</strong> {date_from} to {date_to}
128 <strong>Days:</strong> {no_days}
129 <strong>Reason:</strong> {reason}
130
131 Please approve/reject this leave application by going following:
132
133 {requests_url}
134
135 Thanks.'
136 ];
137
138 update_option( 'erp_email_settings_new-leave-request', $new_leave_request );
139
140 //Approved Leave Request
141 $approved_request = [
142 'subject' => 'Your leave request has been approved',
143 'heading' => 'Leave Request Approved',
144 'body' => 'Hello {employee_name},
145
146 Your <strong>{leave_type}</strong> type leave request for <strong>{no_days} days</strong> from {date_from} to {date_to} has been approved.
147
148 Regards
149 Manager Name
150 Company'
151 ];
152
153 update_option( 'erp_email_settings_approved-leave-request', $approved_request );
154
155 //Rejected Leave Request
156 $reject_request = [
157 'subject' => 'Your leave request has been rejected',
158 'heading' => 'Leave Request Rejected',
159 'body' => 'Hello {employee_name},
160
161 Your <strong>{leave_type}</strong> type leave request for <strong>{no_days} days</strong> from {date_from} to {date_to} has been rejected.
162
163 The reason of rejection is: {reject_reason}
164
165 Regards
166 Manager Name
167 Company'
168 ];
169
170 update_option( 'erp_email_settings_rejected-leave-request', $reject_request );
171
172 // New Task Assigned
173 $new_task_assigned = [
174 'subject' => 'New task has been assigned to you',
175 'heading' => 'New Task Assigned',
176 'body' => 'Hello {employee_name},
177
178 A new task <strong>{task_title}</strong> has been assigned to you by {created_by}.
179 Due Date: {due_date}
180
181 Regards
182 Manager Name
183 Company'
184 ];
185
186 update_option( 'erp_email_settings_new-task-assigned', $new_task_assigned );
187 }
188
189 /**
190 * Create cron jobs
191 *
192 * @return void
193 */
194 public function create_cron_jobs() {
195 wp_schedule_event( time(), 'per_minute', 'erp_per_minute_scheduled_events' );
196 wp_schedule_event( time(), 'daily', 'erp_daily_scheduled_events' );
197 wp_schedule_event( time(), 'weekly', 'erp_weekly_scheduled_events' );
198 }
199
200 /**
201 * Placeholder for deactivation function
202 *
203 * Nothing being called here yet.
204 */
205 public function deactivate() {
206 wp_clear_scheduled_hook( 'erp_per_minute_scheduled_events' );
207 wp_clear_scheduled_hook( 'erp_daily_scheduled_events' );
208 wp_clear_scheduled_hook( 'erp_weekly_scheduled_events' );
209
210 remove_role('erp_crm_manager');
211 remove_role('erp_crm_agent');
212 }
213
214 /**
215 * Welcome screen menu page cb
216 *
217 * @since 1.0
218 *
219 * @return void
220 */
221 public function welcome_screen_menu() {
222 add_dashboard_page( __( 'Welcome to WP ERP', 'erp' ), 'WP ERP', 'manage_options', 'erp-welcome', array( $this, 'welcome_screen_content' ) );
223 }
224
225 /**
226 * Welcome screen menu remove
227 *
228 * @since 1.0
229 *
230 * @return void
231 */
232 public function welcome_screen_menu_remove() {
233 remove_submenu_page( 'index.php', 'erp-welcome' );
234 }
235
236 /**
237 * Render welcome screen content
238 *
239 * @since 1.0
240 *
241 * @return void
242 */
243 public function welcome_screen_content() {
244 include WPERP_VIEWS . '/welcome-screen.php';
245 }
246
247 /**
248 * Create necessary table for ERP & HRM
249 *
250 * @since 1.0
251 *
252 * @return void
253 */
254 public function create_tables() {
255 global $wpdb;
256
257 $collate = '';
258
259 if ( $wpdb->has_cap( 'collation' ) ) {
260 if ( ! empty($wpdb->charset ) ) {
261 $collate .= "DEFAULT CHARACTER SET $wpdb->charset";
262 }
263
264 if ( ! empty($wpdb->collate ) ) {
265 $collate .= " COLLATE $wpdb->collate";
266 }
267 }
268
269 $table_schema = [
270
271 "CREATE TABLE IF NOT EXISTS `{$wpdb->prefix}erp_company_locations` (
272 `id` int(11) unsigned NOT NULL AUTO_INCREMENT,
273 `company_id` int(11) unsigned DEFAULT NULL,
274 `name` varchar(255) DEFAULT NULL,
275 `address_1` varchar(255) DEFAULT NULL,
276 `address_2` varchar(255) DEFAULT NULL,
277 `city` varchar(100) DEFAULT NULL,
278 `state` varchar(100) DEFAULT NULL,
279 `zip` int(6) DEFAULT NULL,
280 `country` varchar(5) DEFAULT NULL,
281 `fax` varchar(20) DEFAULT NULL,
282 `phone` varchar(20) DEFAULT NULL,
283 `created_at` datetime NOT NULL,
284 `updated_at` datetime NOT NULL,
285 PRIMARY KEY (`id`),
286 KEY `company_id` (`company_id`)
287 ) $collate;",
288
289 "CREATE TABLE IF NOT EXISTS `{$wpdb->prefix}erp_hr_depts` (
290 `id` int(11) unsigned NOT NULL AUTO_INCREMENT,
291 `title` varchar(200) NOT NULL DEFAULT '',
292 `description` text,
293 `lead` int(11) unsigned DEFAULT '0',
294 `parent` int(11) unsigned DEFAULT '0',
295 `status` tinyint(1) unsigned DEFAULT '1',
296 `created_at` datetime NOT NULL,
297 `updated_at` datetime NOT NULL,
298 PRIMARY KEY (`id`)
299 ) $collate;",
300
301 "CREATE TABLE IF NOT EXISTS `{$wpdb->prefix}erp_hr_designations` (
302 `id` int(11) unsigned NOT NULL AUTO_INCREMENT,
303 `title` varchar(200) NOT NULL DEFAULT '',
304 `description` text,
305 `status` tinyint(1) DEFAULT '1',
306 `created_at` datetime NOT NULL,
307 `updated_at` datetime NOT NULL,
308 PRIMARY KEY (`id`)
309 ) $collate;",
310
311 "CREATE TABLE IF NOT EXISTS `{$wpdb->prefix}erp_hr_employees` (
312 `id` bigint(20) unsigned NOT NULL AUTO_INCREMENT,
313 `user_id` bigint(20) unsigned NOT NULL DEFAULT '0',
314 `employee_id` varchar(20) DEFAULT NULL,
315 `designation` int(11) unsigned NOT NULL DEFAULT '0',
316 `department` int(11) unsigned NOT NULL DEFAULT '0',
317 `location` int(10) unsigned NOT NULL DEFAULT '0',
318 `hiring_source` varchar(20) NOT NULL,
319 `hiring_date` date NOT NULL,
320 `termination_date` date NOT NULL,
321 `date_of_birth` date NOT NULL,
322 `reporting_to` bigint(20) unsigned NOT NULL DEFAULT '0',
323 `pay_rate` int(11) unsigned NOT NULL DEFAULT '0',
324 `pay_type` varchar(20) NOT NULL DEFAULT '',
325 `type` varchar(20) NOT NULL,
326 `status` varchar(10) NOT NULL DEFAULT '',
327 `deleted_at` datetime DEFAULT NULL,
328 PRIMARY KEY (`id`),
329 KEY `user_id` (`user_id`),
330 KEY `employee_id` (`employee_id`),
331 KEY `designation` (`designation`),
332 KEY `department` (`department`),
333 KEY `status` (`status`)
334 ) $collate;",
335
336 "CREATE TABLE IF NOT EXISTS `{$wpdb->prefix}erp_hr_employee_history` (
337 `id` int(11) unsigned NOT NULL AUTO_INCREMENT,
338 `user_id` bigint(20) unsigned NOT NULL DEFAULT '0',
339 `module` varchar(20) DEFAULT NULL,
340 `category` varchar(20) DEFAULT NULL,
341 `type` varchar(20) DEFAULT NULL,
342 `comment` text,
343 `data` longtext,
344 `date` datetime NOT NULL,
345 PRIMARY KEY (`id`),
346 KEY `user_id` (`user_id`),
347 KEY `module` (`module`)
348 ) $collate;",
349
350 "CREATE TABLE IF NOT EXISTS `{$wpdb->prefix}erp_hr_employee_notes` (
351 `id` bigint(20) unsigned NOT NULL AUTO_INCREMENT,
352 `user_id` bigint(20) unsigned NOT NULL DEFAULT '0',
353 `comment` text NOT NULL,
354 `comment_by` bigint(20) unsigned NOT NULL,
355 `created_at` datetime NOT NULL,
356 `updated_at` datetime NOT NULL,
357 PRIMARY KEY (`id`)
358 ) $collate;",
359
360 "CREATE TABLE IF NOT EXISTS `{$wpdb->prefix}erp_hr_leave_policies` (
361 `id` int(11) unsigned NOT NULL AUTO_INCREMENT,
362 `name` varchar(20) DEFAULT NULL,
363 `value` mediumint(5) DEFAULT NULL,
364 `color` varchar(7) DEFAULT NULL,
365 `department` int(11) NOT NULL,
366 `designation` int(11) NOT NULL,
367 `gender` varchar(50) NOT NULL,
368 `marital` varchar(50) NOT NULL,
369 `description` LONGTEXT NOT NULL,
370 `location` INT(3) NOT NULL,
371 `effective_date` TIMESTAMP NOT NULL,
372 `activate` INT(2) NOT NULL,
373 `execute_day` INT(11) NOT NULL,
374 `created_at` datetime NOT NULL,
375 `updated_at` datetime NOT NULL,
376 PRIMARY KEY (`id`)
377 ) $collate;",
378
379 "CREATE TABLE IF NOT EXISTS `{$wpdb->prefix}erp_hr_holiday` (
380 `id` bigint(20) unsigned NOT NULL AUTO_INCREMENT,
381 `title` varchar(200) NOT NULL,
382 `start` timestamp NOT NULL DEFAULT CURRENT_TIMESTAMP,
383 `end` timestamp NOT NULL DEFAULT '0000-00-00 00:00:00',
384 `description` text NOT NULL,
385 `range_status` varchar(5) COLLATE utf8mb4_unicode_ci NOT NULL,
386 `created_at` datetime NOT NULL,
387 `updated_at` datetime NOT NULL,
388 PRIMARY KEY (`id`)
389 ) $collate;",
390
391 "CREATE TABLE IF NOT EXISTS `{$wpdb->prefix}erp_hr_leave_entitlements` (
392 `id` int(11) unsigned NOT NULL AUTO_INCREMENT,
393 `user_id` bigint(20) unsigned NOT NULL,
394 `policy_id` int(11) unsigned DEFAULT NULL,
395 `days` mediumint(4) DEFAULT NULL,
396 `from_date` datetime NOT NULL,
397 `to_date` datetime NOT NULL,
398 `comments` text,
399 `status` tinyint(2) unsigned NOT NULL,
400 `created_by` bigint(20) unsigned DEFAULT NULL,
401 `created_on` datetime NOT NULL,
402 PRIMARY KEY (`id`),
403 KEY `user_id` (`user_id`),
404 KEY `policy_id` (`policy_id`)
405 ) $collate;",
406
407 "CREATE TABLE IF NOT EXISTS `{$wpdb->prefix}erp_hr_leaves` (
408 `id` bigint(20) unsigned NOT NULL AUTO_INCREMENT,
409 `request_id` bigint(20) unsigned NOT NULL,
410 `date` date NOT NULL,
411 `length_hours` decimal(6,2) unsigned NOT NULL,
412 `length_days` decimal(6,2) NOT NULL,
413 `start_time` time NOT NULL,
414 `end_time` time NOT NULL,
415 `duration_type` tinyint(4) unsigned NOT NULL,
416 PRIMARY KEY (`id`),
417 KEY `request_id` (`request_id`),
418 KEY `date` (`date`)
419 ) $collate;",
420
421 "CREATE TABLE IF NOT EXISTS `{$wpdb->prefix}erp_hr_leave_requests` (
422 `id` bigint(20) unsigned NOT NULL AUTO_INCREMENT,
423 `user_id` bigint(20) unsigned NOT NULL,
424 `policy_id` int(11) unsigned NOT NULL,
425 `days` tinyint(3) unsigned DEFAULT NULL,
426 `start_date` datetime NOT NULL,
427 `end_date` datetime NOT NULL,
428 `comments` text,
429 `reason` text NOT NULL,
430 `status` tinyint(2) unsigned DEFAULT NULL,
431 `created_by` bigint(20) unsigned DEFAULT NULL,
432 `updated_by` bigint(20) unsigned DEFAULT NULL,
433 `created_on` datetime NOT NULL,
434 `updated_on` datetime DEFAULT NULL,
435 `last_date` datetime DEFAULT NULL,
436 PRIMARY KEY (`id`),
437 KEY `user_id` (`user_id`),
438 KEY `policy_id` (`policy_id`),
439 KEY `status` (`status`),
440 KEY `created_by` (`created_by`),
441 KEY `updated_by` (`updated_by`)
442 ) $collate;",
443
444 "CREATE TABLE IF NOT EXISTS `{$wpdb->prefix}erp_hr_work_exp` (
445 `id` int(11) unsigned NOT NULL AUTO_INCREMENT,
446 `employee_id` int(11) DEFAULT NULL,
447 `company_name` varchar(100) DEFAULT NULL,
448 `job_title` varchar(100) DEFAULT NULL,
449 `from` date DEFAULT NULL,
450 `to` date DEFAULT NULL,
451 `description` text,
452 `created_at` datetime DEFAULT NULL,
453 `updated_at` datetime DEFAULT NULL,
454 PRIMARY KEY (`id`),
455 KEY `employee_id` (`employee_id`)
456 ) $collate;",
457
458 "CREATE TABLE IF NOT EXISTS `{$wpdb->prefix}erp_hr_education` (
459 `id` int(11) unsigned NOT NULL AUTO_INCREMENT,
460 `employee_id` int(11) unsigned DEFAULT NULL,
461 `school` varchar(100) DEFAULT NULL,
462 `degree` varchar(100) DEFAULT NULL,
463 `field` varchar(100) DEFAULT NULL,
464 `finished` int(4) unsigned DEFAULT NULL,
465 `notes` text,
466 `interest` text,
467 `created_at` datetime DEFAULT NULL,
468 `updated_at` datetime DEFAULT NULL,
469 PRIMARY KEY (`id`),
470 KEY `employee_id` (`employee_id`)
471 ) $collate;",
472
473 "CREATE TABLE IF NOT EXISTS `{$wpdb->prefix}erp_hr_dependents` (
474 `id` int(11) unsigned NOT NULL AUTO_INCREMENT,
475 `employee_id` int(11) DEFAULT NULL,
476 `name` varchar(100) DEFAULT NULL,
477 `relation` varchar(100) DEFAULT NULL,
478 `dob` date DEFAULT NULL,
479 `created_at` datetime DEFAULT NULL,
480 `updated_at` datetime DEFAULT NULL,
481 PRIMARY KEY (`id`),
482 KEY `employee_id` (`employee_id`)
483 ) $collate;",
484
485 "CREATE TABLE IF NOT EXISTS `{$wpdb->prefix}erp_hr_employee_performance` (
486 `id` int(11) unsigned NOT NULL AUTO_INCREMENT,
487 `employee_id` int(11) unsigned DEFAULT NULL,
488 `reporting_to` int(11) unsigned DEFAULT NULL,
489 `job_knowledge` varchar(100) DEFAULT NULL,
490 `work_quality` varchar(100) DEFAULT NULL,
491 `attendance` varchar(100) DEFAULT NULL,
492 `communication` varchar(100) DEFAULT NULL,
493 `dependablity` varchar(100) DEFAULT NULL,
494 `reviewer` int(11) unsigned DEFAULT NULL,
495 `comments` text,
496 `completion_date` datetime DEFAULT NULL,
497 `goal_description` text,
498 `employee_assessment` text,
499 `supervisor` int(11) unsigned DEFAULT NULL,
500 `supervisor_assessment` text,
501 `type` text,
502 `performance_date` datetime DEFAULT NULL,
503 PRIMARY KEY (`id`),
504 KEY `employee_id` (`employee_id`)
505 ) $collate;",
506
507 "CREATE TABLE IF NOT EXISTS `{$wpdb->prefix}erp_hr_announcement` (
508 `id` bigint(20) unsigned NOT NULL AUTO_INCREMENT,
509 `user_id` bigint(20) unsigned NOT NULL,
510 `post_id` bigint(11) NOT NULL,
511 `status` varchar(30) NOT NULL,
512 `email_status` varchar(30) NOT NULL,
513 PRIMARY KEY (id),
514 KEY `user_id` (`user_id`),
515 KEY `post_id` (`post_id`),
516 KEY `status` (`status`)
517 ) $collate;",
518
519 "CREATE TABLE IF NOT EXISTS `{$wpdb->prefix}erp_peoples` (
520 `id` bigint(20) unsigned NOT NULL AUTO_INCREMENT,
521 `user_id` bigint(20) unsigned DEFAULT '0',
522 `first_name` varchar(60) DEFAULT NULL,
523 `last_name` varchar(60) DEFAULT NULL,
524 `company` varchar(60) DEFAULT NULL,
525 `email` varchar(100) DEFAULT NULL,
526 `phone` varchar(20) DEFAULT NULL,
527 `mobile` varchar(20) DEFAULT NULL,
528 `other` varchar(50) DEFAULT NULL,
529 `website` varchar(100) DEFAULT NULL,
530 `fax` varchar(20) DEFAULT NULL,
531 `notes` text,
532 `street_1` varchar(255) DEFAULT NULL,
533 `street_2` varchar(255) DEFAULT NULL,
534 `city` varchar(80) DEFAULT NULL,
535 `state` varchar(50) DEFAULT NULL,
536 `postal_code` varchar(10) DEFAULT NULL,
537 `country` varchar(20) DEFAULT NULL,
538 `currency` varchar(5) DEFAULT NULL,
539 `created_by` BIGINT(20) DEFAULT NULL,
540 `created` datetime DEFAULT NULL,
541 PRIMARY KEY (`id`),
542 KEY `user_id` (`user_id`),
543 KEY `first_name` (`first_name`),
544 KEY `last_name` (`last_name`),
545 KEY `email` (`email`)
546 ) $collate;",
547
548 "CREATE TABLE IF NOT EXISTS `{$wpdb->prefix}erp_peoplemeta` (
549 `meta_id` bigint(20) unsigned NOT NULL AUTO_INCREMENT,
550 `erp_people_id` bigint(20) DEFAULT NULL,
551 `meta_key` varchar(255) DEFAULT NULL,
552 `meta_value` longtext,
553 PRIMARY KEY (`meta_id`),
554 KEY `erp_people_id` (`erp_people_id`),
555 KEY `meta_key` (`meta_key`(191))
556 ) $collate;",
557
558
559 "CREATE TABLE IF NOT EXISTS `{$wpdb->prefix}erp_people_types` (
560 `id` int(11) unsigned NOT NULL AUTO_INCREMENT,
561 `name` varchar(20) DEFAULT NULL,
562 PRIMARY KEY (`id`),
563 UNIQUE KEY `name` (`name`)
564 ) $collate;",
565
566 "CREATE TABLE IF NOT EXISTS `{$wpdb->prefix}erp_people_type_relations` (
567 `id` bigint(20) unsigned NOT NULL AUTO_INCREMENT,
568 `people_id` bigint(20) unsigned DEFAULT NULL,
569 `people_types_id` int(11) unsigned DEFAULT NULL,
570 `deleted_at` datetime DEFAULT NULL,
571 PRIMARY KEY (`id`),
572 KEY `people_id` (`people_id`),
573 KEY `people_types_id` (`people_types_id`)
574 ) $collate;",
575
576 "CREATE TABLE IF NOT EXISTS `{$wpdb->prefix}erp_audit_log` (
577 `id` bigint(20) unsigned NOT NULL AUTO_INCREMENT,
578 `component` varchar(50) NOT NULL DEFAULT '',
579 `sub_component` varchar(50) NOT NULL DEFAULT '',
580 `data_id` bigint(20) DEFAULT NULL,
581 `old_value` longtext,
582 `new_value` longtext,
583 `message` longtext,
584 `changetype` varchar(10) DEFAULT NULL,
585 `created_by` bigint(20) unsigned DEFAULT NULL,
586 `created_at` datetime DEFAULT NULL,
587 `updated_at` datetime DEFAULT NULL,
588 PRIMARY KEY (`id`),
589 KEY `component` (`component`),
590 KEY `sub_component` (`sub_component`),
591 KEY `changetype` (`changetype`),
592 KEY `created_by` (`created_by`)
593 ) $collate;",
594
595 "CREATE TABLE IF NOT EXISTS `{$wpdb->prefix}erp_crm_customer_companies` (
596 `id` bigint(20) unsigned NOT NULL AUTO_INCREMENT,
597 `customer_id` bigint(20) DEFAULT NULL,
598 `company_id` bigint(50) DEFAULT NULL,
599 PRIMARY KEY (`id`),
600 KEY `customer_id` (`customer_id`),
601 KEY `company_id` (`company_id`)
602 ) $collate;",
603
604 "CREATE TABLE IF NOT EXISTS `{$wpdb->prefix}erp_crm_customer_activities` (
605 `id` int(11) unsigned NOT NULL AUTO_INCREMENT,
606 `user_id` int(11) DEFAULT NULL,
607 `type` varchar(255) DEFAULT NULL,
608 `message` longtext,
609 `email_subject` text,
610 `log_type` varchar(255) DEFAULT NULL,
611 `start_date` datetime DEFAULT NULL,
612 `end_date` datetime DEFAULT NULL,
613 `created_by` int(11) DEFAULT NULL,
614 `extra` longtext,
615 `sent_notification` tinyint(4) DEFAULT '0',
616 `created_at` datetime DEFAULT NULL,
617 `updated_at` datetime DEFAULT NULL,
618 PRIMARY KEY (`id`),
619 KEY `user_id` (`user_id`),
620 KEY `type` (`type`),
621 KEY `log_type` (`log_type`),
622 KEY `created_by` (`created_by`)
623 ) $collate;",
624
625 "CREATE TABLE IF NOT EXISTS `{$wpdb->prefix}erp_crm_activities_task` (
626 `id` int(11) unsigned NOT NULL AUTO_INCREMENT,
627 `activity_id` int(11) DEFAULT NULL,
628 `user_id` int(11) DEFAULT NULL,
629 PRIMARY KEY (`id`),
630 KEY `activity_id` (`activity_id`),
631 KEY `user_id` (`user_id`)
632 ) $collate;",
633
634 "CREATE TABLE IF NOT EXISTS `{$wpdb->prefix}erp_crm_contact_group` (
635 `id` int(11) unsigned NOT NULL AUTO_INCREMENT,
636 `name` varchar(255) DEFAULT NULL,
637 `description` text,
638 `private` TINYINT(1) DEFAULT NULL,
639 `created_at` datetime DEFAULT NULL,
640 `updated_at` datetime DEFAULT NULL,
641 PRIMARY KEY (`id`)
642 ) $collate;",
643
644 "CREATE TABLE IF NOT EXISTS `{$wpdb->prefix}erp_crm_contact_subscriber` (
645 `id` int(11) unsigned NOT NULL AUTO_INCREMENT,
646 `user_id` int(11) DEFAULT NULL,
647 `group_id` int(11) DEFAULT NULL,
648 `status` varchar(25) DEFAULT NULL,
649 `subscribe_at` datetime DEFAULT NULL,
650 `unsubscribe_at` datetime DEFAULT NULL,
651 `hash` VARCHAR(40) NULL DEFAULT NULL,
652 PRIMARY KEY (`id`),
653 UNIQUE KEY `user_group` (`user_id`,`group_id`),
654 KEY `status` (`status`),
655 KEY `hash` (`hash`)
656 ) $collate;",
657
658 "CREATE TABLE IF NOT EXISTS `{$wpdb->prefix}erp_crm_save_search` (
659 `id` int(11) unsigned NOT NULL AUTO_INCREMENT,
660 `user_id` int(11) DEFAULT NULL,
661 `type` VARCHAR(255) DEFAULT NULL,
662 `global` tinyint(4) DEFAULT '0',
663 `search_name` text,
664 `search_val` text,
665 `created_at` datetime DEFAULT NULL,
666 `updated_at` datetime DEFAULT NULL,
667 PRIMARY KEY (`id`)
668 ) $collate;",
669
670 "CREATE TABLE IF NOT EXISTS `{$wpdb->prefix}erp_crm_save_email_replies` (
671 `id` int(11) unsigned NOT NULL AUTO_INCREMENT,
672 `name` text,
673 `subject` text,
674 `template` longtext,
675 PRIMARY KEY (`id`)
676 ) $collate;",
677
678 "CREATE TABLE IF NOT EXISTS `{$wpdb->prefix}erp_ac_chart_classes` (
679 `id` int(11) unsigned NOT NULL AUTO_INCREMENT,
680 `name` varchar(100) DEFAULT NULL,
681 PRIMARY KEY (`id`)
682 ) $collate;",
683
684 "CREATE TABLE IF NOT EXISTS `{$wpdb->prefix}erp_ac_chart_types` (
685 `id` int(11) unsigned NOT NULL AUTO_INCREMENT,
686 `name` varchar(60) NOT NULL DEFAULT '',
687 `class_id` tinyint(3) NOT NULL,
688 PRIMARY KEY (`id`),
689 KEY `class_id` (`class_id`)
690 ) $collate;",
691
692 "CREATE TABLE IF NOT EXISTS `{$wpdb->prefix}erp_ac_journals` (
693 `id` bigint(20) unsigned NOT NULL AUTO_INCREMENT,
694 `ledger_id` int(11) unsigned NOT NULL,
695 `transaction_id` bigint(20) unsigned NOT NULL,
696 `type` varchar(20) DEFAULT NULL,
697 `debit` DECIMAL(13,4) unsigned DEFAULT NULL,
698 `credit` DECIMAL(13,4) unsigned DEFAULT NULL,
699 PRIMARY KEY (`id`),
700 KEY `ledger_id` (`ledger_id`),
701 KEY `transaction_id` (`transaction_id`)
702 ) $collate;",
703
704 "CREATE TABLE IF NOT EXISTS `{$wpdb->prefix}erp_ac_ledger` (
705 `id` int(11) unsigned NOT NULL AUTO_INCREMENT,
706 `code` varchar(10) DEFAULT NULL,
707 `name` varchar(100) DEFAULT NULL,
708 `description` text,
709 `parent` int(11) unsigned NOT NULL DEFAULT '0',
710 `type_id` int(3) unsigned NOT NULL DEFAULT '0',
711 `currency` varchar(10) DEFAULT '',
712 `tax` bigint(20) DEFAULT NULL,
713 `cash_account` tinyint(2) unsigned NOT NULL DEFAULT '0',
714 `reconcile` tinyint(2) unsigned NOT NULL DEFAULT '0',
715 `system` tinyint(2) unsigned NOT NULL DEFAULT '0',
716 `active` tinyint(2) unsigned NOT NULL DEFAULT '1',
717 `created_by` bigint(20) DEFAULT 0,
718 PRIMARY KEY (`id`),
719 KEY `code` (`code`),
720 KEY `type_id` (`type_id`),
721 KEY `parent` (`parent`)
722 ) $collate;",
723
724 "CREATE TABLE IF NOT EXISTS `{$wpdb->prefix}erp_ac_banks` (
725 `id` int(11) unsigned NOT NULL AUTO_INCREMENT,
726 `ledger_id` int(10) unsigned DEFAULT NULL,
727 `account_number` varchar(20) DEFAULT NULL,
728 `bank_name` varchar(30) DEFAULT NULL,
729 PRIMARY KEY (`id`),
730 KEY `ledger_id` (`ledger_id`)
731 ) $collate;",
732
733 "CREATE TABLE IF NOT EXISTS `{$wpdb->prefix}erp_ac_transactions` (
734 `id` bigint(20) unsigned NOT NULL AUTO_INCREMENT,
735 `type` varchar(10) DEFAULT NULL,
736 `form_type` varchar(20) DEFAULT NULL,
737 `status` varchar(20) DEFAULT NULL,
738 `user_id` bigint(20) unsigned DEFAULT NULL,
739 `billing_address` tinytext,
740 `ref` varchar(50) DEFAULT NULL,
741 `summary` text,
742 `issue_date` date DEFAULT NULL,
743 `due_date` date DEFAULT NULL,
744 `currency` varchar(10) DEFAULT NULL,
745 `conversion_rate` decimal(2,2) unsigned DEFAULT NULL,
746 `sub_total` DECIMAL(13,4) DEFAULT '0.00',
747 `total` DECIMAL(13,4) DEFAULT '0.00',
748 `due` DECIMAL(13,4) unsigned DEFAULT '0.00',
749 `trans_total` DECIMAL(13,4) DEFAULT '0.00',
750 `invoice_number` INT(10) UNSIGNED NULL DEFAULT '0',
751 `invoice_format` VARCHAR(20) NOT NULL,
752 `files` varchar(255) DEFAULT NULL,
753 `parent` bigint(20) unsigned NOT NULL DEFAULT '0',
754 `created_by` int(11) unsigned DEFAULT NULL,
755 `created_at` datetime DEFAULT NULL,
756 PRIMARY KEY (`id`),
757 KEY `user_id` (`user_id`),
758 KEY `type` (`type`),
759 KEY `status` (`status`),
760 KEY `issue_date` (`issue_date`)
761 ) $collate;",
762
763 "CREATE TABLE IF NOT EXISTS `{$wpdb->prefix}erp_ac_transaction_items` (
764 `id` bigint(20) unsigned NOT NULL AUTO_INCREMENT,
765 `transaction_id` bigint(20) unsigned DEFAULT NULL,
766 `journal_id` bigint(20) unsigned DEFAULT NULL,
767 `product_id` int(10) unsigned DEFAULT NULL,
768 `description` text,
769 `qty` DECIMAL(10,2) unsigned NOT NULL DEFAULT '1',
770 `unit_price` DECIMAL(13,4) unsigned NOT NULL DEFAULT '0.00',
771 `discount` tinyint(3) unsigned NOT NULL DEFAULT '0',
772 `tax` tinyint(3) unsigned NOT NULL DEFAULT '0',
773 `tax_rate` DECIMAL(13,4) NOT NULL,
774 `tax_journal` BIGINT(20) NOT NULL,
775 `line_total` DECIMAL(13,4) unsigned NOT NULL DEFAULT '0.00',
776 `order` tinyint(3) unsigned NOT NULL DEFAULT '0',
777 PRIMARY KEY (`id`),
778 KEY `transaction_id` (`transaction_id`),
779 KEY `journal_id` (`journal_id`),
780 KEY `product_id` (`product_id`)
781 ) $collate;",
782
783 "CREATE TABLE IF NOT EXISTS `{$wpdb->prefix}erp_ac_payments` (
784 `id` bigint(20) NOT NULL AUTO_INCREMENT,
785 `transaction_id` int(11) NOT NULL,
786 `parent` int(11) NOT NULL,
787 `child` int(11) NOT NULL,
788 PRIMARY KEY (`id`)
789 ) $collate;",
790
791 "CREATE TABLE IF NOT EXISTS `{$wpdb->prefix}erp_ac_tax` (
792 `id` bigint(20) unsigned NOT NULL AUTO_INCREMENT,
793 `name` varchar(255) DEFAULT NULL,
794 `tax_number` varchar(255) DEFAULT NULL,
795 `is_compound` varchar(5) DEFAULT NULL,
796 `created_by` bigint(20) unsigned NOT NULL,
797 PRIMARY KEY (`id`)
798 ) $collate;",
799
800 "CREATE TABLE IF NOT EXISTS `{$wpdb->prefix}erp_ac_tax_items` (
801 `id` bigint(20) unsigned NOT NULL AUTO_INCREMENT,
802 `tax_id` bigint(20) NOT NULL,
803 `component_name` varchar(255) DEFAULT NULL,
804 `agency_name` varchar(255) DEFAULT NULL,
805 `tax_rate` float NOT NULL,
806 PRIMARY KEY (`id`)
807 ) $collate;",
808
809 ];
810
811 require_once( ABSPATH . 'wp-admin/includes/upgrade.php' );
812 foreach ( $table_schema as $table ) {
813 dbDelta( $table );
814 }
815
816 }
817
818 /**
819 * Populate tables with initial data
820 *
821 * @return void
822 */
823 public function populate_data() {
824 global $wpdb;
825
826 // check if people_types exists
827 if ( ! $wpdb->get_var( "SELECT id FROM `{$wpdb->prefix}erp_people_types` LIMIT 0, 1" ) ) {
828 $sql = "INSERT INTO `{$wpdb->prefix}erp_people_types` (`id`, `name`)
829 VALUES (1,'contact'), (2,'company'), (3,'customer'), (4,'vendor');";
830
831 $wpdb->query( $sql );
832 }
833
834 //Accounting
835
836 // check if classes exists
837 if ( ! $wpdb->get_var( "SELECT id FROM `{$wpdb->prefix}erp_ac_chart_classes` LIMIT 0, 1" ) ) {
838 $sql = "INSERT INTO `{$wpdb->prefix}erp_ac_chart_classes` (`id`, `name`)
839 VALUES (1,'Assets'), (2,'Liabilities'), (3,'Expenses'), (4,'Income'), (5,'Equity');";
840
841 $wpdb->query( $sql );
842 }
843
844 // check if chart types exists
845 if ( ! $wpdb->get_var( "SELECT id FROM `{$wpdb->prefix}erp_ac_chart_types` LIMIT 0, 1" ) ) {
846 $sql = "INSERT INTO `{$wpdb->prefix}erp_ac_chart_types` (`id`, `name`, `class_id`)
847 VALUES (1,'Current Asset',1), (2,'Fixed Asset',1), (3,'Inventory',1),
848 (4,'Non-current Asset',1), (5,'Prepayment',1), (6,'Bank & Cash',1), (7,'Current Liability',2),
849 (8,'Liability',2), (9,'Non-current Liability',2), (10,'Depreciation',3),
850 (11,'Direct Costs',3), (12,'Expense',3), (13,'Revenue',4), (14,'Sales',4),
851 (15,'Other Income',4), (16,'Equity',5);";
852
853 $wpdb->query( $sql );
854 }
855
856 // check if ledger exists
857 if ( ! $wpdb->get_var( "SELECT id FROM `{$wpdb->prefix}erp_ac_ledger` LIMIT 0, 1" ) ) {
858
859 $sql = "INSERT INTO `{$wpdb->prefix}erp_ac_ledger` (`id`, `code`, `name`, `description`, `parent`, `type_id`, `currency`, `tax`, `cash_account`, `reconcile`, `system`, `active`)
860 VALUES
861 (1,'120','Accounts Receivable',NULL,0,1,'',NULL,0,0,1,1),
862 (2,'140','Inventory',NULL,0,3,'',NULL,0,0,1,1),
863 (3,'150','Office Equipment',NULL,0,2,'',NULL,0,0,1,1),
864 (4,'151','Less Accumulated Depreciation on Office Equipment',NULL,0,2,'',NULL,0,0,1,1),
865 (5,'160','Computer Equipment',NULL,0,2,'',NULL,0,0,1,1),
866 (6,'161','Less Accumulated Depreciation on Computer Equipment',NULL,0,2,'',NULL,0,0,1,1),
867 (7,'090','Petty Cash',NULL,0,6,'',NULL,1,1,0,1),
868 (8,'200','Accounts Payable',NULL,0,7,'',NULL,0,0,1,1),
869 (9,'205','Accruals',NULL,0,7,'',NULL,0,0,0,1),
870 (10,'210','Unpaid Expense Claims',NULL,0,7,'',NULL,0,0,1,1),
871 (11,'215','Wages Payable',NULL,0,7,'',NULL,0,0,1,1),
872 (12,'216','Wages Payable - Payroll',NULL,0,7,'',NULL,0,0,0,1),
873 (13,'220','Sales Tax',NULL,0,7,'',NULL,0,0,1,1),
874 (14,'230','Employee Tax Payable',NULL,0,7,'',NULL,0,0,0,1),
875 (15,'235','Employee Benefits Payable',NULL,0,7,'',NULL,0,0,0,1),
876 (16,'236','Employee Deductions payable',NULL,0,7,'',NULL,0,0,0,1),
877 (17,'240','Income Tax Payable',NULL,0,7,'',NULL,0,0,0,1),
878 (18,'250','Suspense',NULL,0,7,'',NULL,0,0,0,1),
879 (19,'255','Historical Adjustments',NULL,0,7,'',NULL,0,0,1,1),
880 (20,'260','Rounding',NULL,0,7,'',NULL,0,0,1,1),
881 (21,'835','Revenue Received in Advance',NULL,0,7,'',NULL,0,0,0,1),
882 (22,'855','Clearing Account',NULL,0,7,'',NULL,0,0,0,1),
883 (23,'290','Loan',NULL,0,9,'',NULL,0,0,0,1),
884 (24,'500','Costs of Goods Sold',NULL,0,11,'',NULL,0,0,1,1),
885 (25,'600','Advertising',NULL,0,12,'',NULL,0,0,0,1),
886 (26,'605','Bank Service Charges',NULL,0,12,'',NULL,0,0,0,1),
887 (27,'610','Janitorial Expenses',NULL,0,12,'',NULL,0,0,0,1),
888 (28,'615','Consulting & Accounting',NULL,0,12,'',NULL,0,0,0,1),
889 (29,'620','Entertainment',NULL,0,12,'',NULL,0,0,0,1),
890 (30,'624','Postage & Delivary',NULL,0,12,'',NULL,0,0,0,1),
891 (31,'628','General Expenses',NULL,0,12,'',NULL,0,0,0,1),
892 (32,'632','Insurance',NULL,0,12,'',NULL,0,0,0,1),
893 (33,'636','Legal Expenses',NULL,0,12,'',NULL,0,0,0,1),
894 (34,'640','Utilities',NULL,0,12,'',NULL,0,0,1,1),
895 (35,'644','Automobile Expenses',NULL,0,12,'',NULL,0,0,0,1),
896 (36,'648','Office Expenses',NULL,0,12,'',NULL,0,0,1,1),
897 (37,'652','Printing & Stationary',NULL,0,12,'',NULL,0,0,0,1),
898 (38,'656','Rent',NULL,0,12,'',NULL,0,0,1,1),
899 (39,'660','Repairs & Maintenance',NULL,0,12,'',NULL,0,0,0,1),
900 (40,'664','Wages & Salaries',NULL,0,12,'',NULL,0,0,0,1),
901 (41,'668','Payroll Tax Expense',NULL,0,12,'',NULL,0,0,0,1),
902 (42,'672','Dues & Subscriptions',NULL,0,12,'',NULL,0,0,0,1),
903 (43,'676','Telephone & Internet',NULL,0,12,'',NULL,0,0,0,1),
904 (44,'680','Travel',NULL,0,12,'',NULL,0,0,0,1),
905 (45,'684','Bad Debts',NULL,0,12,'',NULL,0,0,0,1),
906 (46,'700','Depreciation',NULL,0,10,'',NULL,0,0,1,1),
907 (47,'710','Income Tax Expense',NULL,0,12,'',NULL,0,0,0,1),
908 (48,'715','Employee Benefits Expense',NULL,0,12,'',NULL,0,0,0,1),
909 (49,'800','Interest Expense',NULL,0,12,'',NULL,0,0,0,1),
910 (50,'810','Bank Revaluations',NULL,0,12,'',NULL,0,0,1,1),
911 (51,'815','Unrealized Currency Gains',NULL,0,12,'',NULL,0,0,1,1),
912 (52,'820','Realized Currency Gains',NULL,0,12,'',NULL,0,0,1,1),
913 (53,'825','Sales Discount',NULL,0,12,'',NULL,0,0,1,1),
914 (54,'400','Sales',NULL,0,13,'',NULL,0,0,0,1),
915 (55,'460','Interest Income',NULL,0,13,'',NULL,0,0,0,1),
916 (56,'470','Other Revenue',NULL,0,13,'',NULL,0,0,0,1),
917 (57,'475','Purchase Discount',NULL,0,13,'',NULL,0,0,1,1),
918 (58,'300','Owners Contribution',NULL,0,16,'',NULL,0,0,0,1),
919 (59,'310','Owners Draw',NULL,0,16,'',NULL,0,0,0,1),
920 (60,'320','Retained Earnings',NULL,0,16,'',NULL,0,0,1,1),
921 (61,'330','Common Stock',NULL,0,16,'',NULL,0,0,0,1),
922 (62,'092','Savings Account',NULL,0,6,'',NULL,1,1,0,1);";
923
924 $wpdb->query( $sql );
925 }
926
927 // check if banks exists
928 if ( ! $wpdb->get_var( "SELECT id FROM `{$wpdb->prefix}erp_ac_banks` LIMIT 0, 1" ) ) {
929 $sql = "INSERT INTO `{$wpdb->prefix}erp_ac_banks` (`id`, `ledger_id`, `account_number`, `bank_name`)
930 VALUES (1,7,'',''), (2,62,'012345689','ABC Bank');";
931
932 $wpdb->query( $sql );
933 }
934
935 // Subscription pages
936 $subscription_settings = get_option( 'erp_settings_erp-crm_subscription', [] );
937
938 if ( empty( $subscription_settings ) ) {
939 // insert default erp subscription form settings
940 $args = [
941 'post_title' => __( 'ERP Subscription', 'erp' ),
942 'post_content' => '',
943 'post_status' => 'publish',
944 'post_type' => 'page',
945 'comment_status' => 'closed',
946 'ping_status' => 'closed',
947 ];
948
949 $page_id = wp_insert_post( $args );
950
951 $settings = [
952 'is_enabled' => 'yes',
953 'email_subject' => sprintf( __( 'Confirm your subscription to %s', 'erp' ), get_bloginfo( 'name' ) ),
954 'email_content' => sprintf(
955 __( "Hello!\n\nThanks so much for signing up for our newsletter.\nWe need you to activate your subscription to the list(s): [contact_groups_to_confirm] by clicking the link below: \n\n[activation_link]Click here to confirm your subscription.[/activation_link]\n\nThank you,\n\n%s", 'erp' ),
956 get_bloginfo( 'name' )
957 ),
958 'page_id' => $page_id,
959 'confirm_page_title' => __( 'You are now subscribed!', 'erp' ),
960 'confirm_page_content' => __( "We've added you to our email list. You'll hear from us shortly.", 'erp' ),
961 'unsubs_page_title' => __( 'You are now unsubscribed', 'erp' ),
962 'unsubs_page_content' => __( 'You are successfully unsubscribed from list(s):', 'erp' ),
963 ];
964
965 update_option( 'erp_settings_erp-crm_subscription', $settings );
966 }
967 }
968
969 /**
970 * Set default module for initial erp setup
971 *
972 * @since 1.0
973 *
974 * @return void
975 */
976 public function set_default_modules() {
977
978 if ( get_option( 'wp_erp_version' ) ) {
979 return ;
980 }
981
982 $default = [
983 'hrm' => [
984 'title' => __( 'HR Management', 'erp' ),
985 'slug' => 'erp-hrm',
986 'description' => __( 'Human Resource Mnanagement', 'erp' ),
987 'callback' => '\WeDevs\ERP\HRM\Human_Resource',
988 'modules' => apply_filters( 'erp_hr_modules', [ ] )
989 ],
990
991 'crm' => [
992 'title' => __( 'CR Management', 'erp' ),
993 'slug' => 'erp-crm',
994 'description' => __( 'Client Resource Management', 'erp' ),
995 'callback' => '\WeDevs\ERP\CRM\Customer_Relationship',
996 'modules' => apply_filters( 'erp_crm_modules', [ ] )
997 ],
998
999 'accounting' => [
1000 'title' => __( 'Accountig Management', 'erp' ),
1001 'slug' => 'erp-accounting',
1002 'description' => __( 'Accountig Management', 'erp' ),
1003 'callback' => '\WeDevs\ERP\Accounting\Accountig',
1004 'modules' => apply_filters( 'erp_accounting_modules', [ ] )
1005 ]
1006 ];
1007
1008 update_option( 'erp_modules', $default );
1009 }
1010
1011 /**
1012 * Create user roles and capabilities
1013 *
1014 * @since 1.0
1015 *
1016 * @return void
1017 */
1018 public function create_roles() {
1019 $this->includes();
1020
1021 $roles_hr = erp_hr_get_roles();
1022
1023 if ( $roles_hr ) {
1024 foreach ($roles_hr as $key => $role) {
1025 add_role( $key, $role['name'], $role['capabilities'] );
1026 }
1027 }
1028
1029 $roles_crm = erp_crm_get_roles();
1030
1031 if ( $roles_crm ) {
1032 foreach ($roles_crm as $key => $role) {
1033 add_role( $key, $role['name'], $role['capabilities'] );
1034 }
1035 }
1036
1037 $roles_ac = erp_ac_get_roles();
1038
1039 if ( $roles_ac ) {
1040 foreach ($roles_ac as $key => $role) {
1041 add_role( $key, $role['name'], $role['capabilities'] );
1042 }
1043 }
1044 }
1045
1046 /**
1047 * Set erp_hr_manager role for admin user
1048 *
1049 * @since 1.0
1050 *
1051 * @return void
1052 */
1053 public function set_role() {
1054 $this->includes();
1055
1056 $admins = get_users( array( 'role' => 'administrator' ) );
1057
1058 if ( $admins ) {
1059 foreach ($admins as $user) {
1060 $user->add_role( erp_hr_get_manager_role() );
1061 $user->add_role( erp_crm_get_manager_role() );
1062 $user->add_role( erp_ac_get_manager_role() );
1063 }
1064 }
1065 }
1066 }
1067
1068 new WeDevs_ERP_Installer();
1069