| 1 |
<?php |
| 2 |
namespace WeDevs\ERP\Accounting; |
| 3 |
/** |
| 4 |
* Installer class |
| 5 |
*/ |
| 6 |
class Install { |
| 7 |
|
| 8 |
public function install() { |
| 9 |
$this->create_tables(); |
| 10 |
$this->populate_data(); |
| 11 |
$this->create_roles(); |
| 12 |
$this->set_role(); |
| 13 |
} |
| 14 |
|
| 15 |
/** |
| 16 |
* Create user roles and capabilities |
| 17 |
* |
| 18 |
* @since 0.1 |
| 19 |
* |
| 20 |
* @return void |
| 21 |
*/ |
| 22 |
public function create_roles() { |
| 23 |
$roles = erp_ac_get_roles(); |
| 24 |
|
| 25 |
if ( $roles ) { |
| 26 |
foreach ($roles as $key => $role) { |
| 27 |
add_role( $key, $role['name'], $role['capabilities'] ); |
| 28 |
} |
| 29 |
} |
| 30 |
} |
| 31 |
|
| 32 |
function set_role() { |
| 33 |
$admins = get_users( array( 'role' => 'administrator' ) ); |
| 34 |
|
| 35 |
if ( $admins ) { |
| 36 |
foreach ($admins as $user) { |
| 37 |
$user->add_role( erp_ac_get_manager_role() ); |
| 38 |
} |
| 39 |
} |
| 40 |
} |
| 41 |
|
| 42 |
/** |
| 43 |
* Create necessary tables |
| 44 |
* |
| 45 |
* @since 0.1 |
| 46 |
* |
| 47 |
* @return void |
| 48 |
*/ |
| 49 |
public function create_tables() { |
| 50 |
global $wpdb; |
| 51 |
|
| 52 |
$collate = ''; |
| 53 |
|
| 54 |
if ( $wpdb->has_cap( 'collation' ) ) { |
| 55 |
if ( ! empty($wpdb->charset ) ) { |
| 56 |
$collate .= "DEFAULT CHARACTER SET $wpdb->charset"; |
| 57 |
} |
| 58 |
|
| 59 |
if ( ! empty($wpdb->collate ) ) { |
| 60 |
$collate .= " COLLATE $wpdb->collate"; |
| 61 |
} |
| 62 |
} |
| 63 |
|
| 64 |
$table_schema = [ |
| 65 |
"CREATE TABLE IF NOT EXISTS `{$wpdb->prefix}erp_ac_chart_classes` ( |
| 66 |
`id` int(11) unsigned NOT NULL AUTO_INCREMENT, |
| 67 |
`name` varchar(100) DEFAULT NULL, |
| 68 |
PRIMARY KEY (`id`) |
| 69 |
) $collate;", |
| 70 |
|
| 71 |
"CREATE TABLE IF NOT EXISTS `{$wpdb->prefix}erp_ac_chart_types` ( |
| 72 |
`id` int(11) unsigned NOT NULL AUTO_INCREMENT, |
| 73 |
`name` varchar(60) NOT NULL DEFAULT '', |
| 74 |
`class_id` tinyint(3) NOT NULL, |
| 75 |
PRIMARY KEY (`id`), |
| 76 |
KEY `class_id` (`class_id`) |
| 77 |
) $collate;", |
| 78 |
|
| 79 |
"CREATE TABLE IF NOT EXISTS `{$wpdb->prefix}erp_ac_journals` ( |
| 80 |
`id` bigint(20) unsigned NOT NULL AUTO_INCREMENT, |
| 81 |
`ledger_id` int(11) unsigned NOT NULL, |
| 82 |
`transaction_id` bigint(20) unsigned NOT NULL, |
| 83 |
`type` varchar(20) DEFAULT NULL, |
| 84 |
`debit` DECIMAL(13,4) unsigned DEFAULT NULL, |
| 85 |
`credit` DECIMAL(13,4) unsigned DEFAULT NULL, |
| 86 |
PRIMARY KEY (`id`), |
| 87 |
KEY `ledger_id` (`ledger_id`), |
| 88 |
KEY `transaction_id` (`transaction_id`) |
| 89 |
) $collate;", |
| 90 |
|
| 91 |
"CREATE TABLE IF NOT EXISTS `{$wpdb->prefix}erp_ac_ledger` ( |
| 92 |
`id` int(11) unsigned NOT NULL AUTO_INCREMENT, |
| 93 |
`code` varchar(10) DEFAULT NULL, |
| 94 |
`name` varchar(100) DEFAULT NULL, |
| 95 |
`description` text, |
| 96 |
`parent` int(11) unsigned NOT NULL DEFAULT '0', |
| 97 |
`type_id` int(3) unsigned NOT NULL DEFAULT '0', |
| 98 |
`currency` varchar(10) DEFAULT '', |
| 99 |
`tax` bigint(20) DEFAULT NULL, |
| 100 |
`cash_account` tinyint(2) unsigned NOT NULL DEFAULT '0', |
| 101 |
`reconcile` tinyint(2) unsigned NOT NULL DEFAULT '0', |
| 102 |
`system` tinyint(2) unsigned NOT NULL DEFAULT '0', |
| 103 |
`active` tinyint(2) unsigned NOT NULL DEFAULT '1', |
| 104 |
PRIMARY KEY (`id`), |
| 105 |
KEY `code` (`code`), |
| 106 |
KEY `type_id` (`type_id`), |
| 107 |
KEY `parent` (`parent`) |
| 108 |
) $collate;", |
| 109 |
|
| 110 |
"CREATE TABLE IF NOT EXISTS `{$wpdb->prefix}erp_ac_banks` ( |
| 111 |
`id` int(11) unsigned NOT NULL AUTO_INCREMENT, |
| 112 |
`ledger_id` int(10) unsigned DEFAULT NULL, |
| 113 |
`account_number` varchar(20) DEFAULT NULL, |
| 114 |
`bank_name` varchar(30) DEFAULT NULL, |
| 115 |
PRIMARY KEY (`id`), |
| 116 |
KEY `ledger_id` (`ledger_id`) |
| 117 |
) $collate;", |
| 118 |
|
| 119 |
"CREATE TABLE IF NOT EXISTS `{$wpdb->prefix}erp_ac_transactions` ( |
| 120 |
`id` bigint(20) unsigned NOT NULL AUTO_INCREMENT, |
| 121 |
`type` varchar(10) DEFAULT NULL, |
| 122 |
`form_type` varchar(20) DEFAULT NULL, |
| 123 |
`status` varchar(20) DEFAULT NULL, |
| 124 |
`user_id` bigint(20) unsigned DEFAULT NULL, |
| 125 |
`billing_address` tinytext, |
| 126 |
`ref` varchar(50) DEFAULT NULL, |
| 127 |
`summary` text, |
| 128 |
`issue_date` date DEFAULT NULL, |
| 129 |
`due_date` date DEFAULT NULL, |
| 130 |
`currency` varchar(10) DEFAULT NULL, |
| 131 |
`conversion_rate` decimal(2,2) unsigned DEFAULT NULL, |
| 132 |
`total` DECIMAL(13,4) DEFAULT '0.00', |
| 133 |
`due` DECIMAL(13,4) unsigned DEFAULT '0.00', |
| 134 |
`trans_total` DECIMAL(13,4) DEFAULT '0.00', |
| 135 |
`files` varchar(255) DEFAULT NULL, |
| 136 |
`parent` bigint(20) unsigned NOT NULL DEFAULT '0', |
| 137 |
`created_by` int(11) unsigned DEFAULT NULL, |
| 138 |
`created_at` datetime DEFAULT NULL, |
| 139 |
PRIMARY KEY (`id`), |
| 140 |
KEY `user_id` (`user_id`), |
| 141 |
KEY `type` (`type`), |
| 142 |
KEY `status` (`status`), |
| 143 |
KEY `issue_date` (`issue_date`) |
| 144 |
) $collate;", |
| 145 |
|
| 146 |
"CREATE TABLE IF NOT EXISTS `{$wpdb->prefix}erp_ac_transaction_items` ( |
| 147 |
`id` bigint(20) unsigned NOT NULL AUTO_INCREMENT, |
| 148 |
`transaction_id` bigint(20) unsigned DEFAULT NULL, |
| 149 |
`journal_id` bigint(20) unsigned DEFAULT NULL, |
| 150 |
`product_id` int(10) unsigned DEFAULT NULL, |
| 151 |
`description` text, |
| 152 |
`qty` tinyint(5) unsigned NOT NULL DEFAULT '1', |
| 153 |
`unit_price` DECIMAL(13,4) unsigned NOT NULL DEFAULT '0.00', |
| 154 |
`discount` tinyint(3) unsigned NOT NULL DEFAULT '0', |
| 155 |
`tax` tinyint(3) unsigned NOT NULL DEFAULT '0', |
| 156 |
`line_total` DECIMAL(13,4) unsigned NOT NULL DEFAULT '0.00', |
| 157 |
`order` tinyint(3) unsigned NOT NULL DEFAULT '0', |
| 158 |
PRIMARY KEY (`id`), |
| 159 |
KEY `transaction_id` (`transaction_id`), |
| 160 |
KEY `journal_id` (`journal_id`), |
| 161 |
KEY `product_id` (`product_id`) |
| 162 |
) $collate;", |
| 163 |
|
| 164 |
"CREATE TABLE IF NOT EXISTS `{$wpdb->prefix}erp_ac_payments` ( |
| 165 |
`id` bigint(20) NOT NULL AUTO_INCREMENT, |
| 166 |
`transaction_id` int(11) NOT NULL, |
| 167 |
`parent` int(11) NOT NULL, |
| 168 |
`child` int(11) NOT NULL, |
| 169 |
PRIMARY KEY (`id`) |
| 170 |
) $collate;", |
| 171 |
|
| 172 |
"CREATE TABLE IF NOT EXISTS `{$wpdb->prefix}erp_ac_tax` ( |
| 173 |
`id` bigint(20) unsigned NOT NULL AUTO_INCREMENT, |
| 174 |
`name` varchar(255) DEFAULT NULL, |
| 175 |
`tax_number` varchar(255) DEFAULT NULL, |
| 176 |
`is_compound` varchar(5) DEFAULT NULL, |
| 177 |
`created_by` bigint(20) NOT NULL, |
| 178 |
PRIMARY KEY (`id`) |
| 179 |
) $collate;", |
| 180 |
|
| 181 |
"CREATE TABLE IF NOT EXISTS `{$wpdb->prefix}erp_ac_tax_items` ( |
| 182 |
`id` bigint(20) unsigned NOT NULL AUTO_INCREMENT, |
| 183 |
`tax_id` bigint(20) NOT NULL, |
| 184 |
`component_name` varchar(255) DEFAULT NULL, |
| 185 |
`agency_name` varchar(255) DEFAULT NULL, |
| 186 |
`tax_rate` float NOT NULL, |
| 187 |
PRIMARY KEY (`id`) |
| 188 |
) $collate;", |
| 189 |
|
| 190 |
"CREATE TABLE IF NOT EXISTS `{$wpdb->prefix}erp_company_locations` ( |
| 191 |
`id` int(11) unsigned NOT NULL AUTO_INCREMENT, |
| 192 |
`company_id` int(11) unsigned DEFAULT NULL, |
| 193 |
`name` varchar(255) DEFAULT NULL, |
| 194 |
`address_1` varchar(255) DEFAULT NULL, |
| 195 |
`address_2` varchar(255) DEFAULT NULL, |
| 196 |
`city` varchar(100) DEFAULT NULL, |
| 197 |
`state` varchar(100) DEFAULT NULL, |
| 198 |
`zip` varchar(10) DEFAULT NULL, |
| 199 |
`country` varchar(5) DEFAULT NULL, |
| 200 |
`fax` varchar(20) DEFAULT NULL, |
| 201 |
`phone` varchar(20) DEFAULT NULL, |
| 202 |
`created_at` datetime NOT NULL, |
| 203 |
`updated_at` datetime NOT NULL, |
| 204 |
PRIMARY KEY (`id`), |
| 205 |
KEY `company_id` (`company_id`) |
| 206 |
) $collate;", |
| 207 |
|
| 208 |
"CREATE TABLE IF NOT EXISTS `{$wpdb->prefix}erp_hr_depts` ( |
| 209 |
`id` int(11) unsigned NOT NULL AUTO_INCREMENT, |
| 210 |
`title` varchar(200) NOT NULL DEFAULT '', |
| 211 |
`description` text, |
| 212 |
`lead` int(11) unsigned DEFAULT '0', |
| 213 |
`parent` int(11) unsigned DEFAULT '0', |
| 214 |
`status` tinyint(1) unsigned DEFAULT '1', |
| 215 |
`created_at` datetime NOT NULL, |
| 216 |
`updated_at` datetime NOT NULL, |
| 217 |
PRIMARY KEY (`id`) |
| 218 |
) $collate;", |
| 219 |
|
| 220 |
"CREATE TABLE IF NOT EXISTS `{$wpdb->prefix}erp_hr_designations` ( |
| 221 |
`id` int(11) unsigned NOT NULL AUTO_INCREMENT, |
| 222 |
`title` varchar(200) NOT NULL DEFAULT '', |
| 223 |
`description` text, |
| 224 |
`status` tinyint(1) DEFAULT '1', |
| 225 |
`created_at` datetime NOT NULL, |
| 226 |
`updated_at` datetime NOT NULL, |
| 227 |
PRIMARY KEY (`id`) |
| 228 |
) $collate;", |
| 229 |
|
| 230 |
"CREATE TABLE IF NOT EXISTS `{$wpdb->prefix}erp_hr_employees` ( |
| 231 |
`id` bigint(20) unsigned NOT NULL AUTO_INCREMENT, |
| 232 |
`user_id` bigint(20) unsigned NOT NULL DEFAULT '0', |
| 233 |
`employee_id` varchar(20) DEFAULT NULL, |
| 234 |
`designation` int(11) unsigned NOT NULL DEFAULT '0', |
| 235 |
`department` int(11) unsigned NOT NULL DEFAULT '0', |
| 236 |
`location` int(10) unsigned NOT NULL DEFAULT '0', |
| 237 |
`hiring_source` varchar(20) NOT NULL, |
| 238 |
`hiring_date` date NOT NULL, |
| 239 |
`termination_date` date NOT NULL, |
| 240 |
`date_of_birth` date NOT NULL, |
| 241 |
`reporting_to` bigint(20) unsigned NOT NULL DEFAULT '0', |
| 242 |
`pay_rate` int(11) unsigned NOT NULL DEFAULT '0', |
| 243 |
`pay_type` varchar(20) NOT NULL DEFAULT '', |
| 244 |
`type` varchar(20) NOT NULL, |
| 245 |
`status` varchar(10) NOT NULL DEFAULT '', |
| 246 |
`deleted_at` datetime DEFAULT NULL, |
| 247 |
PRIMARY KEY (`id`), |
| 248 |
KEY `user_id` (`user_id`) |
| 249 |
) $collate;", |
| 250 |
|
| 251 |
"CREATE TABLE IF NOT EXISTS `{$wpdb->prefix}erp_hr_employee_history` ( |
| 252 |
`id` int(11) unsigned NOT NULL AUTO_INCREMENT, |
| 253 |
`user_id` bigint(20) unsigned NOT NULL DEFAULT '0', |
| 254 |
`module` varchar(20) DEFAULT NULL, |
| 255 |
`category` varchar(20) DEFAULT NULL, |
| 256 |
`type` varchar(20) DEFAULT NULL, |
| 257 |
`comment` text, |
| 258 |
`data` longtext, |
| 259 |
`date` datetime NOT NULL, |
| 260 |
PRIMARY KEY (`id`), |
| 261 |
KEY `user_id` (`user_id`), |
| 262 |
KEY `module` (`module`) |
| 263 |
) $collate;", |
| 264 |
|
| 265 |
"CREATE TABLE IF NOT EXISTS `{$wpdb->prefix}erp_hr_employee_notes` ( |
| 266 |
`id` bigint(20) unsigned NOT NULL AUTO_INCREMENT, |
| 267 |
`user_id` bigint(20) unsigned NOT NULL DEFAULT '0', |
| 268 |
`comment` text NOT NULL, |
| 269 |
`comment_by` bigint(20) unsigned NOT NULL, |
| 270 |
`created_at` datetime NOT NULL, |
| 271 |
`updated_at` datetime NOT NULL, |
| 272 |
PRIMARY KEY (`id`) |
| 273 |
) $collate;", |
| 274 |
|
| 275 |
"CREATE TABLE IF NOT EXISTS `{$wpdb->prefix}erp_hr_leave_policies` ( |
| 276 |
`id` int(11) unsigned NOT NULL AUTO_INCREMENT, |
| 277 |
`name` varchar(20) DEFAULT NULL, |
| 278 |
`value` mediumint(5) DEFAULT NULL, |
| 279 |
`color` varchar(7) DEFAULT NULL, |
| 280 |
`department` int(11) NOT NULL, |
| 281 |
`designation` int(11) NOT NULL, |
| 282 |
`gender` varchar(50) NOT NULL, |
| 283 |
`marital` varchar(50) NOT NULL, |
| 284 |
`description` LONGTEXT NOT NULL, |
| 285 |
`location` INT(3) NOT NULL, |
| 286 |
`effective_date` TIMESTAMP NOT NULL, |
| 287 |
`activate` INT(2) NOT NULL, |
| 288 |
`execute_day` INT(11) NOT NULL, |
| 289 |
`created_at` datetime NOT NULL, |
| 290 |
`updated_at` datetime NOT NULL, |
| 291 |
PRIMARY KEY (`id`) |
| 292 |
) $collate;", |
| 293 |
|
| 294 |
"CREATE TABLE IF NOT EXISTS `{$wpdb->prefix}erp_hr_holiday` ( |
| 295 |
`id` bigint(20) unsigned NOT NULL AUTO_INCREMENT, |
| 296 |
`title` varchar(200) NOT NULL, |
| 297 |
`start` timestamp NOT NULL DEFAULT CURRENT_TIMESTAMP, |
| 298 |
`end` timestamp NOT NULL DEFAULT '0000-00-00 00:00:00', |
| 299 |
`description` text NOT NULL, |
| 300 |
`range_status` varchar(5) COLLATE utf8mb4_unicode_ci NOT NULL, |
| 301 |
`created_at` datetime NOT NULL, |
| 302 |
`updated_at` datetime NOT NULL, |
| 303 |
PRIMARY KEY (`id`) |
| 304 |
) $collate;", |
| 305 |
|
| 306 |
"CREATE TABLE IF NOT EXISTS `{$wpdb->prefix}erp_hr_leave_entitlements` ( |
| 307 |
`id` int(11) unsigned NOT NULL AUTO_INCREMENT, |
| 308 |
`user_id` bigint(20) unsigned NOT NULL, |
| 309 |
`policy_id` int(11) unsigned DEFAULT NULL, |
| 310 |
`days` mediumint(4) DEFAULT NULL, |
| 311 |
`from_date` datetime NOT NULL, |
| 312 |
`to_date` datetime NOT NULL, |
| 313 |
`comments` text, |
| 314 |
`status` tinyint(2) unsigned NOT NULL, |
| 315 |
`created_by` bigint(20) unsigned DEFAULT NULL, |
| 316 |
`created_on` datetime NOT NULL, |
| 317 |
PRIMARY KEY (`id`), |
| 318 |
KEY `user_id` (`user_id`) |
| 319 |
) $collate;", |
| 320 |
|
| 321 |
"CREATE TABLE IF NOT EXISTS `{$wpdb->prefix}erp_hr_leaves` ( |
| 322 |
`id` bigint(20) unsigned NOT NULL AUTO_INCREMENT, |
| 323 |
`request_id` bigint(20) unsigned NOT NULL, |
| 324 |
`date` date NOT NULL, |
| 325 |
`length_hours` decimal(6,2) unsigned NOT NULL, |
| 326 |
`length_days` decimal(6,2) NOT NULL, |
| 327 |
`start_time` time NOT NULL, |
| 328 |
`end_time` time NOT NULL, |
| 329 |
`duration_type` tinyint(4) unsigned NOT NULL, |
| 330 |
PRIMARY KEY (`id`), |
| 331 |
KEY `request_id` (`request_id`) |
| 332 |
) $collate;", |
| 333 |
|
| 334 |
"CREATE TABLE IF NOT EXISTS `{$wpdb->prefix}erp_hr_leave_requests` ( |
| 335 |
`id` bigint(20) unsigned NOT NULL AUTO_INCREMENT, |
| 336 |
`user_id` bigint(20) unsigned NOT NULL, |
| 337 |
`policy_id` int(11) unsigned NOT NULL, |
| 338 |
`days` tinyint(3) unsigned DEFAULT NULL, |
| 339 |
`start_date` datetime NOT NULL, |
| 340 |
`end_date` datetime NOT NULL, |
| 341 |
`comments` text, |
| 342 |
`reason` text NOT NULL, |
| 343 |
`status` tinyint(2) unsigned DEFAULT NULL, |
| 344 |
`created_by` bigint(20) unsigned DEFAULT NULL, |
| 345 |
`updated_by` bigint(20) unsigned DEFAULT NULL, |
| 346 |
`created_on` datetime NOT NULL, |
| 347 |
`updated_on` datetime DEFAULT NULL, |
| 348 |
`last_date` datetime DEFAULT NULL, |
| 349 |
PRIMARY KEY (`id`), |
| 350 |
KEY `user_id` (`user_id`), |
| 351 |
KEY `policy_id` (`policy_id`) |
| 352 |
) $collate;", |
| 353 |
|
| 354 |
"CREATE TABLE IF NOT EXISTS `{$wpdb->prefix}erp_hr_work_exp` ( |
| 355 |
`id` int(11) unsigned NOT NULL AUTO_INCREMENT, |
| 356 |
`employee_id` int(11) DEFAULT NULL, |
| 357 |
`company_name` varchar(100) DEFAULT NULL, |
| 358 |
`job_title` varchar(100) DEFAULT NULL, |
| 359 |
`from` date DEFAULT NULL, |
| 360 |
`to` date DEFAULT NULL, |
| 361 |
`description` text, |
| 362 |
`created_at` datetime DEFAULT NULL, |
| 363 |
`updated_at` datetime DEFAULT NULL, |
| 364 |
PRIMARY KEY (`id`), |
| 365 |
KEY `employee_id` (`employee_id`) |
| 366 |
) $collate;", |
| 367 |
|
| 368 |
"CREATE TABLE IF NOT EXISTS `{$wpdb->prefix}erp_hr_education` ( |
| 369 |
`id` int(11) unsigned NOT NULL AUTO_INCREMENT, |
| 370 |
`employee_id` int(11) unsigned DEFAULT NULL, |
| 371 |
`school` varchar(100) DEFAULT NULL, |
| 372 |
`degree` varchar(100) DEFAULT NULL, |
| 373 |
`field` varchar(100) DEFAULT NULL, |
| 374 |
`finished` int(4) unsigned DEFAULT NULL, |
| 375 |
`notes` text, |
| 376 |
`interest` text, |
| 377 |
`created_at` datetime DEFAULT NULL, |
| 378 |
`updated_at` datetime DEFAULT NULL, |
| 379 |
PRIMARY KEY (`id`), |
| 380 |
KEY `employee_id` (`employee_id`) |
| 381 |
) $collate;", |
| 382 |
|
| 383 |
"CREATE TABLE IF NOT EXISTS `{$wpdb->prefix}erp_hr_dependents` ( |
| 384 |
`id` int(11) unsigned NOT NULL AUTO_INCREMENT, |
| 385 |
`employee_id` int(11) DEFAULT NULL, |
| 386 |
`name` varchar(100) DEFAULT NULL, |
| 387 |
`relation` varchar(100) DEFAULT NULL, |
| 388 |
`dob` date DEFAULT NULL, |
| 389 |
`created_at` datetime DEFAULT NULL, |
| 390 |
`updated_at` datetime DEFAULT NULL, |
| 391 |
PRIMARY KEY (`id`), |
| 392 |
KEY `employee_id` (`employee_id`) |
| 393 |
) $collate;", |
| 394 |
|
| 395 |
"CREATE TABLE IF NOT EXISTS `{$wpdb->prefix}erp_hr_employee_performance` ( |
| 396 |
`id` int(11) unsigned NOT NULL AUTO_INCREMENT, |
| 397 |
`employee_id` int(11) unsigned DEFAULT NULL, |
| 398 |
`reporting_to` int(11) unsigned DEFAULT NULL, |
| 399 |
`job_knowledge` varchar(100) DEFAULT NULL, |
| 400 |
`work_quality` varchar(100) DEFAULT NULL, |
| 401 |
`attendance` varchar(100) DEFAULT NULL, |
| 402 |
`communication` varchar(100) DEFAULT NULL, |
| 403 |
`dependablity` varchar(100) DEFAULT NULL, |
| 404 |
`reviewer` int(11) unsigned DEFAULT NULL, |
| 405 |
`comments` text, |
| 406 |
`completion_date` datetime DEFAULT NULL, |
| 407 |
`goal_description` text, |
| 408 |
`employee_assessment` text, |
| 409 |
`supervisor` int(11) unsigned DEFAULT NULL, |
| 410 |
`supervisor_assessment` text, |
| 411 |
`type` text, |
| 412 |
`performance_date` datetime DEFAULT NULL, |
| 413 |
PRIMARY KEY (`id`), |
| 414 |
KEY `employee_id` (`employee_id`) |
| 415 |
) $collate;", |
| 416 |
|
| 417 |
"CREATE TABLE IF NOT EXISTS `{$wpdb->prefix}erp_hr_announcement` ( |
| 418 |
`id` bigint(20) unsigned NOT NULL AUTO_INCREMENT, |
| 419 |
`user_id` bigint(20) unsigned NOT NULL, |
| 420 |
`post_id` bigint(11) NOT NULL, |
| 421 |
`status` varchar(30) NOT NULL, |
| 422 |
PRIMARY KEY (id) |
| 423 |
) $collate;", |
| 424 |
|
| 425 |
"CREATE TABLE IF NOT EXISTS `{$wpdb->prefix}erp_peoples` ( |
| 426 |
`id` bigint(20) unsigned NOT NULL AUTO_INCREMENT, |
| 427 |
`user_id` bigint(20) unsigned DEFAULT '0', |
| 428 |
`first_name` varchar(60) DEFAULT NULL, |
| 429 |
`last_name` varchar(60) DEFAULT NULL, |
| 430 |
`company` varchar(60) DEFAULT NULL, |
| 431 |
`email` varchar(100) DEFAULT NULL, |
| 432 |
`phone` varchar(20) DEFAULT NULL, |
| 433 |
`mobile` varchar(20) DEFAULT NULL, |
| 434 |
`other` varchar(50) DEFAULT NULL, |
| 435 |
`website` varchar(100) DEFAULT NULL, |
| 436 |
`fax` varchar(20) DEFAULT NULL, |
| 437 |
`notes` text, |
| 438 |
`street_1` varchar(255) DEFAULT NULL, |
| 439 |
`street_2` varchar(255) DEFAULT NULL, |
| 440 |
`city` varchar(80) DEFAULT NULL, |
| 441 |
`state` varchar(50) DEFAULT NULL, |
| 442 |
`postal_code` varchar(10) DEFAULT NULL, |
| 443 |
`country` varchar(20) DEFAULT NULL, |
| 444 |
`currency` varchar(5) DEFAULT NULL, |
| 445 |
`created` datetime DEFAULT NULL, |
| 446 |
PRIMARY KEY (`id`), |
| 447 |
KEY `user_id` (`user_id`) |
| 448 |
) $collate;", |
| 449 |
|
| 450 |
"CREATE TABLE IF NOT EXISTS `{$wpdb->prefix}erp_peoplemeta` ( |
| 451 |
`meta_id` bigint(20) unsigned NOT NULL AUTO_INCREMENT, |
| 452 |
`erp_people_id` bigint(20) DEFAULT NULL, |
| 453 |
`meta_key` varchar(255) DEFAULT NULL, |
| 454 |
`meta_value` longtext, |
| 455 |
PRIMARY KEY (`meta_id`), |
| 456 |
KEY `erp_people_id` (`erp_people_id`), |
| 457 |
KEY `meta_key` (`meta_key`(191)) |
| 458 |
) $collate;", |
| 459 |
|
| 460 |
|
| 461 |
"CREATE TABLE IF NOT EXISTS `{$wpdb->prefix}erp_people_types` ( |
| 462 |
`id` int(11) unsigned NOT NULL AUTO_INCREMENT, |
| 463 |
`name` varchar(20) DEFAULT NULL, |
| 464 |
PRIMARY KEY (`id`), |
| 465 |
UNIQUE KEY `name` (`name`) |
| 466 |
) $collate;", |
| 467 |
|
| 468 |
"CREATE TABLE IF NOT EXISTS `{$wpdb->prefix}erp_people_type_relations` ( |
| 469 |
`id` bigint(20) unsigned NOT NULL AUTO_INCREMENT, |
| 470 |
`people_id` bigint(20) unsigned DEFAULT NULL, |
| 471 |
`people_types_id` int(11) unsigned DEFAULT NULL, |
| 472 |
`deleted_at` datetime DEFAULT NULL, |
| 473 |
PRIMARY KEY (`id`), |
| 474 |
KEY `people_id` (`people_id`), |
| 475 |
KEY `people_types_id` (`people_types_id`) |
| 476 |
) $collate;", |
| 477 |
|
| 478 |
"CREATE TABLE IF NOT EXISTS `{$wpdb->prefix}erp_audit_log` ( |
| 479 |
`id` bigint(20) unsigned NOT NULL AUTO_INCREMENT, |
| 480 |
`component` varchar(50) NOT NULL DEFAULT '', |
| 481 |
`sub_component` varchar(50) NOT NULL DEFAULT '', |
| 482 |
`old_value` longtext, |
| 483 |
`new_value` longtext, |
| 484 |
`message` longtext, |
| 485 |
`changetype` varchar(10) DEFAULT NULL, |
| 486 |
`created_by` bigint(20) unsigned DEFAULT NULL, |
| 487 |
`created_at` datetime DEFAULT NULL, |
| 488 |
`updated_at` datetime DEFAULT NULL, |
| 489 |
PRIMARY KEY (`id`) |
| 490 |
) $collate;", |
| 491 |
|
| 492 |
"CREATE TABLE IF NOT EXISTS `{$wpdb->prefix}erp_crm_customer_companies` ( |
| 493 |
`id` bigint(20) unsigned NOT NULL AUTO_INCREMENT, |
| 494 |
`customer_id` bigint(20) DEFAULT NULL, |
| 495 |
`company_id` bigint(50) DEFAULT NULL, |
| 496 |
PRIMARY KEY (`id`) |
| 497 |
) $collate;", |
| 498 |
|
| 499 |
"CREATE TABLE IF NOT EXISTS `{$wpdb->prefix}erp_crm_customer_activities` ( |
| 500 |
`id` int(11) unsigned NOT NULL AUTO_INCREMENT, |
| 501 |
`user_id` int(11) DEFAULT NULL, |
| 502 |
`type` varchar(255) DEFAULT NULL, |
| 503 |
`message` longtext, |
| 504 |
`email_subject` text, |
| 505 |
`log_type` varchar(255) DEFAULT NULL, |
| 506 |
`start_date` datetime DEFAULT NULL, |
| 507 |
`end_date` datetime DEFAULT NULL, |
| 508 |
`created_by` int(11) DEFAULT NULL, |
| 509 |
`extra` longtext, |
| 510 |
`created_at` datetime DEFAULT NULL, |
| 511 |
`updated_at` datetime DEFAULT NULL, |
| 512 |
PRIMARY KEY (`id`) |
| 513 |
) $collate;", |
| 514 |
|
| 515 |
"CREATE TABLE IF NOT EXISTS `{$wpdb->prefix}erp_crm_activities_task` ( |
| 516 |
`id` int(11) unsigned NOT NULL AUTO_INCREMENT, |
| 517 |
`activity_id` int(11) DEFAULT NULL, |
| 518 |
`user_id` int(11) DEFAULT NULL, |
| 519 |
PRIMARY KEY (`id`) |
| 520 |
) $collate;", |
| 521 |
|
| 522 |
"CREATE TABLE IF NOT EXISTS `{$wpdb->prefix}erp_crm_contact_group` ( |
| 523 |
`id` int(11) unsigned NOT NULL AUTO_INCREMENT, |
| 524 |
`name` varchar(255) DEFAULT NULL, |
| 525 |
`description` text, |
| 526 |
`created_at` datetime DEFAULT NULL, |
| 527 |
`updated_at` datetime DEFAULT NULL, |
| 528 |
PRIMARY KEY (`id`) |
| 529 |
) $collate;", |
| 530 |
|
| 531 |
"CREATE TABLE IF NOT EXISTS `{$wpdb->prefix}erp_crm_contact_subscriber` ( |
| 532 |
`id` int(11) unsigned NOT NULL AUTO_INCREMENT, |
| 533 |
`user_id` int(11) DEFAULT NULL, |
| 534 |
`group_id` int(11) DEFAULT NULL, |
| 535 |
`status` varchar(25) DEFAULT NULL, |
| 536 |
`subscribe_at` datetime DEFAULT NULL, |
| 537 |
`unsubscribe_at` datetime DEFAULT NULL, |
| 538 |
PRIMARY KEY (`id`), |
| 539 |
UNIQUE KEY `user_group` (`user_id`,`group_id`) |
| 540 |
) $collate;", |
| 541 |
|
| 542 |
"CREATE TABLE IF NOT EXISTS `{$wpdb->prefix}erp_crm_campaigns` ( |
| 543 |
`id` int(11) unsigned NOT NULL AUTO_INCREMENT, |
| 544 |
`title` text, |
| 545 |
`description` longtext, |
| 546 |
`created_at` datetime DEFAULT NULL, |
| 547 |
`updated_at` datetime DEFAULT NULL, |
| 548 |
PRIMARY KEY (`id`) |
| 549 |
) $collate;", |
| 550 |
|
| 551 |
"CREATE TABLE IF NOT EXISTS `{$wpdb->prefix}erp_crm_campaign_group` ( |
| 552 |
`id` int(11) unsigned NOT NULL AUTO_INCREMENT, |
| 553 |
`campaign_id` int(11) DEFAULT NULL, |
| 554 |
`group_id` int(11) DEFAULT NULL, |
| 555 |
PRIMARY KEY (`id`) |
| 556 |
) $collate;", |
| 557 |
|
| 558 |
"CREATE TABLE IF NOT EXISTS `{$wpdb->prefix}erp_crm_save_search` ( |
| 559 |
`id` int(11) unsigned NOT NULL AUTO_INCREMENT, |
| 560 |
`user_id` int(11) DEFAULT NULL, |
| 561 |
`global` tinyint(4) DEFAULT '0', |
| 562 |
`search_name` text, |
| 563 |
`search_val` text, |
| 564 |
PRIMARY KEY (`id`) |
| 565 |
) $collate;", |
| 566 |
|
| 567 |
"CREATE TABLE IF NOT EXISTS `{$wpdb->prefix}erp_crm_save_email_replies` ( |
| 568 |
`id` int(11) unsigned NOT NULL AUTO_INCREMENT, |
| 569 |
`name` text, |
| 570 |
`subject` text, |
| 571 |
`template` longtext, |
| 572 |
PRIMARY KEY (`id`) |
| 573 |
) $collate;" |
| 574 |
|
| 575 |
]; |
| 576 |
|
| 577 |
require_once( ABSPATH . 'wp-admin/includes/upgrade.php' ); |
| 578 |
|
| 579 |
foreach ( $table_schema as $table ) { |
| 580 |
dbDelta( $table ); |
| 581 |
} |
| 582 |
} |
| 583 |
|
| 584 |
public function populate_data() { |
| 585 |
global $wpdb; |
| 586 |
|
| 587 |
// check if classes exists |
| 588 |
if ( ! $wpdb->get_var( "SELECT id FROM `{$wpdb->prefix}erp_ac_chart_classes` LIMIT 0, 1" ) ) { |
| 589 |
$sql = "INSERT INTO `{$wpdb->prefix}erp_ac_chart_classes` (`id`, `name`) |
| 590 |
VALUES (1,'Assets'), (2,'Liabilities'), (3,'Expenses'), (4,'Income'), (5,'Equity');"; |
| 591 |
|
| 592 |
$wpdb->query( $sql ); |
| 593 |
} |
| 594 |
|
| 595 |
// check if chart types exists |
| 596 |
if ( ! $wpdb->get_var( "SELECT id FROM `{$wpdb->prefix}erp_ac_chart_types` LIMIT 0, 1" ) ) { |
| 597 |
$sql = "INSERT INTO `{$wpdb->prefix}erp_ac_chart_types` (`id`, `name`, `class_id`) |
| 598 |
VALUES (1,'Current Asset',1), (2,'Fixed Asset',1), (3,'Inventory',1), |
| 599 |
(4,'Non-current Asset',1), (5,'Prepayment',1), (6,'Bank & Cash',1), (7,'Current Liability',2), |
| 600 |
(8,'Liability',2), (9,'Non-current Liability',2), (10,'Depreciation',3), |
| 601 |
(11,'Direct Costs',3), (12,'Expense',3), (13,'Revenue',4), (14,'Sales',4), |
| 602 |
(15,'Other Income',4), (16,'Equity',5);"; |
| 603 |
|
| 604 |
$wpdb->query( $sql ); |
| 605 |
} |
| 606 |
|
| 607 |
// check if ledger exists |
| 608 |
if ( ! $wpdb->get_var( "SELECT id FROM `{$wpdb->prefix}erp_ac_ledger` LIMIT 0, 1" ) ) { |
| 609 |
|
| 610 |
$sql = "INSERT INTO `{$wpdb->prefix}erp_ac_ledger` (`id`, `code`, `name`, `description`, `parent`, `type_id`, `currency`, `tax`, `cash_account`, `reconcile`, `system`, `active`) |
| 611 |
VALUES |
| 612 |
(1,'120','Accounts Receivable',NULL,0,1,'',NULL,0,0,1,1), |
| 613 |
(2,'140','Inventory',NULL,0,3,'',NULL,0,0,1,1), |
| 614 |
(3,'150','Office Equipment',NULL,0,2,'',NULL,0,0,1,1), |
| 615 |
(4,'151','Less Accumulated Depreciation on Office Equipment',NULL,0,2,'',NULL,0,0,1,1), |
| 616 |
(5,'160','Computer Equipment',NULL,0,2,'',NULL,0,0,1,1), |
| 617 |
(6,'161','Less Accumulated Depreciation on Computer Equipment',NULL,0,2,'',NULL,0,0,1,1), |
| 618 |
(7,'090','Petty Cash',NULL,0,6,'',NULL,1,1,0,1), |
| 619 |
(8,'200','Accounts Payable',NULL,0,7,'',NULL,0,0,1,1), |
| 620 |
(9,'205','Accruals',NULL,0,7,'',NULL,0,0,0,1), |
| 621 |
(10,'210','Unpaid Expense Claims',NULL,0,7,'',NULL,0,0,1,1), |
| 622 |
(11,'215','Wages Payable',NULL,0,7,'',NULL,0,0,1,1), |
| 623 |
(12,'216','Wages Payable - Payroll',NULL,0,7,'',NULL,0,0,0,1), |
| 624 |
(13,'220','Sales Tax',NULL,0,7,'',NULL,0,0,1,1), |
| 625 |
(14,'230','Employee Tax Payable',NULL,0,7,'',NULL,0,0,0,1), |
| 626 |
(15,'235','Employee Benefits Payable',NULL,0,7,'',NULL,0,0,0,1), |
| 627 |
(16,'236','Employee Deductions payable',NULL,0,7,'',NULL,0,0,0,1), |
| 628 |
(17,'240','Income Tax Payable',NULL,0,7,'',NULL,0,0,0,1), |
| 629 |
(18,'250','Suspense',NULL,0,7,'',NULL,0,0,0,1), |
| 630 |
(19,'255','Historical Adjustments',NULL,0,7,'',NULL,0,0,1,1), |
| 631 |
(20,'260','Rounding',NULL,0,7,'',NULL,0,0,1,1), |
| 632 |
(21,'835','Revenue Received in Advance',NULL,0,7,'',NULL,0,0,0,1), |
| 633 |
(22,'855','Clearing Account',NULL,0,7,'',NULL,0,0,0,1), |
| 634 |
(23,'290','Loan',NULL,0,9,'',NULL,0,0,0,1), |
| 635 |
(24,'500','Costs of Goods Sold',NULL,0,11,'',NULL,0,0,1,1), |
| 636 |
(25,'600','Advertising',NULL,0,12,'',NULL,0,0,0,1), |
| 637 |
(26,'605','Bank Service Charges',NULL,0,12,'',NULL,0,0,0,1), |
| 638 |
(27,'610','Janitorial Expenses',NULL,0,12,'',NULL,0,0,0,1), |
| 639 |
(28,'615','Consulting & Accounting',NULL,0,12,'',NULL,0,0,0,1), |
| 640 |
(29,'620','Entertainment',NULL,0,12,'',NULL,0,0,0,1), |
| 641 |
(30,'624','Postage & Delivary',NULL,0,12,'',NULL,0,0,0,1), |
| 642 |
(31,'628','General Expenses',NULL,0,12,'',NULL,0,0,0,1), |
| 643 |
(32,'632','Insurance',NULL,0,12,'',NULL,0,0,0,1), |
| 644 |
(33,'636','Legal Expenses',NULL,0,12,'',NULL,0,0,0,1), |
| 645 |
(34,'640','Utilities',NULL,0,12,'',NULL,0,0,1,1), |
| 646 |
(35,'644','Automobile Expenses',NULL,0,12,'',NULL,0,0,0,1), |
| 647 |
(36,'648','Office Expenses',NULL,0,12,'',NULL,0,0,1,1), |
| 648 |
(37,'652','Printing & Stationary',NULL,0,12,'',NULL,0,0,0,1), |
| 649 |
(38,'656','Rent',NULL,0,12,'',NULL,0,0,1,1), |
| 650 |
(39,'660','Repairs & Maintenance',NULL,0,12,'',NULL,0,0,0,1), |
| 651 |
(40,'664','Wages & Salaries',NULL,0,12,'',NULL,0,0,0,1), |
| 652 |
(41,'668','Payroll Tax Expense',NULL,0,12,'',NULL,0,0,0,1), |
| 653 |
(42,'672','Dues & Subscriptions',NULL,0,12,'',NULL,0,0,0,1), |
| 654 |
(43,'676','Telephone & Internet',NULL,0,12,'',NULL,0,0,0,1), |
| 655 |
(44,'680','Travel',NULL,0,12,'',NULL,0,0,0,1), |
| 656 |
(45,'684','Bad Debts',NULL,0,12,'',NULL,0,0,0,1), |
| 657 |
(46,'700','Depreciation',NULL,0,10,'',NULL,0,0,1,1), |
| 658 |
(47,'710','Income Tax Expense',NULL,0,12,'',NULL,0,0,0,1), |
| 659 |
(48,'715','Employee Benefits Expense',NULL,0,12,'',NULL,0,0,0,1), |
| 660 |
(49,'800','Interest Expense',NULL,0,12,'',NULL,0,0,0,1), |
| 661 |
(50,'810','Bank Revaluations',NULL,0,12,'',NULL,0,0,1,1), |
| 662 |
(51,'815','Unrealized Currency Gains',NULL,0,12,'',NULL,0,0,1,1), |
| 663 |
(52,'820','Realized Currency Gains',NULL,0,12,'',NULL,0,0,1,1), |
| 664 |
(53,'825','Sales Discount',NULL,0,12,'',NULL,0,0,1,1), |
| 665 |
(54,'400','Sales',NULL,0,13,'',NULL,0,0,0,1), |
| 666 |
(55,'460','Interest Income',NULL,0,13,'',NULL,0,0,0,1), |
| 667 |
(56,'470','Other Revenue',NULL,0,13,'',NULL,0,0,0,1), |
| 668 |
(57,'475','Purchase Discount',NULL,0,13,'',NULL,0,0,1,1), |
| 669 |
(58,'300','Owners Contribution',NULL,0,16,'',NULL,0,0,0,1), |
| 670 |
(59,'310','Owners Draw',NULL,0,16,'',NULL,0,0,0,1), |
| 671 |
(60,'320','Retained Earnings',NULL,0,16,'',NULL,0,0,1,1), |
| 672 |
(61,'330','Common Stock',NULL,0,16,'',NULL,0,0,0,1), |
| 673 |
(62,'092','Savings Account',NULL,0,6,'',NULL,1,1,0,1);"; |
| 674 |
|
| 675 |
$wpdb->query( $sql ); |
| 676 |
} |
| 677 |
|
| 678 |
// check if banks exists |
| 679 |
if ( ! $wpdb->get_var( "SELECT id FROM `{$wpdb->prefix}erp_ac_banks` LIMIT 0, 1" ) ) { |
| 680 |
$sql = "INSERT INTO `{$wpdb->prefix}erp_ac_banks` (`id`, `ledger_id`, `account_number`, `bank_name`) |
| 681 |
VALUES (1,7,'',''), (2,62,'012345689','ABC Bank');"; |
| 682 |
|
| 683 |
$wpdb->query( $sql ); |
| 684 |
} |
| 685 |
} |
| 686 |
} |