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