--
-- Host: CAMBOXDB    Database: mbilling
-- ------------------------------------------------------


--
-- Table structure for table `pkg_alarm`
--

CREATE TABLE `pkg_alarm` (
  `id` int(11) NOT NULL AUTO_INCREMENT,
  `type` int(11) NOT NULL,
  `amount` int(11) NOT NULL,
  `condition` int(11) NOT NULL,
  `status` int(11) NOT NULL,
  `creationdate` timestamp NOT NULL DEFAULT current_timestamp(),
  `period` int(11) DEFAULT NULL,
  `id_plan` int(11) DEFAULT NULL,
  `email` varchar(100) DEFAULT NULL,
  PRIMARY KEY (`id`)
) ENGINE=InnoDB DEFAULT CHARSET=utf8;

--
-- Table structure for table `pkg_balance`
--

CREATE TABLE `pkg_balance` (
  `id` int(11) NOT NULL AUTO_INCREMENT,
  `last_use` int(2) NOT NULL,
  `id_prefix` int(11) DEFAULT NULL,
  PRIMARY KEY (`id`)
) ENGINE=InnoDB DEFAULT CHARSET=utf8;

--
-- Table structure for table `pkg_boleto`
--

CREATE TABLE `pkg_boleto` (
  `id` int(11) NOT NULL AUTO_INCREMENT,
  `id_user` int(20) NOT NULL,
  `date` timestamp NOT NULL DEFAULT current_timestamp(),
  `description` mediumtext CHARACTER SET utf8 COLLATE utf8_bin NOT NULL,
  `status` varchar(4) CHARACTER SET utf8 COLLATE utf8_bin NOT NULL,
  `payment` varchar(10) CHARACTER SET utf8 COLLATE utf8_bin NOT NULL,
  `vencimento` timestamp NOT NULL DEFAULT '0000-00-00 00:00:00',
  PRIMARY KEY (`id`),
  KEY `fk_pkg_user_pkg_boleto` (`id_user`),
  CONSTRAINT `fk_pkg_user_pkg_boleto` FOREIGN KEY (`id_user`) REFERENCES `pkg_user` (`id`) ON DELETE CASCADE
) ENGINE=InnoDB DEFAULT CHARSET=utf8;

--
-- Table structure for table `pkg_call_chart`
--

CREATE TABLE `pkg_call_chart` (
  `id` int(11) NOT NULL AUTO_INCREMENT,
  `answer` int(11) DEFAULT NULL,
  `date` timestamp NULL DEFAULT current_timestamp(),
  `total` int(11) DEFAULT NULL,
  PRIMARY KEY (`id`),
  UNIQUE KEY `date` (`date`)
) ENGINE=InnoDB AUTO_INCREMENT=18624095 DEFAULT CHARSET=utf8;

--
-- Table structure for table `pkg_call_online`
--

CREATE TABLE `pkg_call_online` (
  `id` int(11) NOT NULL AUTO_INCREMENT,
  `uniqueid` varchar(25) DEFAULT NULL,
  `sip_account` varchar(50) DEFAULT NULL,
  `id_user` int(11) DEFAULT NULL,
  `canal` varchar(50) DEFAULT NULL,
  `tronco` varchar(50) DEFAULT NULL,
  `ndiscado` varchar(25) DEFAULT '0',
  `codec` varchar(5) CHARACTER SET utf8 COLLATE utf8_bin NOT NULL,
  `status` varchar(16) NOT NULL,
  `duration` int(11) NOT NULL DEFAULT 0,
  `reinvite` varchar(5) NOT NULL,
  `from_ip` varchar(50) DEFAULT NULL,
  `server` varchar(50) NOT NULL DEFAULT '',
  PRIMARY KEY (`id`),
  KEY `starttime` (`status`),
  KEY `fk_pkg_user_pkg_call_online` (`id_user`),
  CONSTRAINT `fk_pkg_user_pkg_call_online` FOREIGN KEY (`id_user`) REFERENCES `pkg_user` (`id`) ON DELETE CASCADE
) ENGINE=InnoDB DEFAULT CHARSET=utf8;

--
-- Table structure for table `pkg_callback`
--

CREATE TABLE `pkg_callback` (
  `id` int(20) NOT NULL AUTO_INCREMENT,
  `id_user` int(11) NOT NULL,
  `id_did` int(11) NOT NULL,
  `uniqueid` varchar(40) CHARACTER SET utf8 COLLATE utf8_bin DEFAULT NULL,
  `entry_time` timestamp NOT NULL DEFAULT current_timestamp(),
  `status` varchar(80) CHARACTER SET utf8 COLLATE utf8_bin DEFAULT NULL,
  `server_ip` varchar(40) CHARACTER SET utf8 COLLATE utf8_bin DEFAULT NULL,
  `num_attempt` int(11) NOT NULL DEFAULT 0,
  `last_attempt_time` timestamp NOT NULL DEFAULT '0000-00-00 00:00:00',
  `manager_result` varchar(60) CHARACTER SET utf8 COLLATE utf8_bin DEFAULT NULL,
  `agi_result` varchar(60) CHARACTER SET utf8 COLLATE utf8_bin DEFAULT NULL,
  `callback_time` timestamp NOT NULL DEFAULT '0000-00-00 00:00:00',
  `channel` varchar(60) CHARACTER SET utf8 COLLATE utf8_bin DEFAULT NULL,
  `exten` varchar(60) CHARACTER SET utf8 COLLATE utf8_bin DEFAULT NULL,
  `context` varchar(60) CHARACTER SET utf8 COLLATE utf8_bin DEFAULT NULL,
  `priority` varchar(60) CHARACTER SET utf8 COLLATE utf8_bin DEFAULT NULL,
  `application` varchar(60) CHARACTER SET utf8 COLLATE utf8_bin DEFAULT NULL,
  `data` varchar(60) CHARACTER SET utf8 COLLATE utf8_bin DEFAULT NULL,
  `timeout` varchar(60) CHARACTER SET utf8 COLLATE utf8_bin DEFAULT NULL,
  `callerid` varchar(60) CHARACTER SET utf8 COLLATE utf8_bin DEFAULT NULL,
  `variable` varchar(300) CHARACTER SET utf8 COLLATE utf8_bin DEFAULT NULL,
  `account` varchar(60) CHARACTER SET utf8 COLLATE utf8_bin DEFAULT NULL,
  `async` varchar(60) CHARACTER SET utf8 COLLATE utf8_bin DEFAULT NULL,
  `actionid` varchar(60) CHARACTER SET utf8 COLLATE utf8_bin DEFAULT NULL,
  `id_server` int(11) DEFAULT NULL,
  `id_server_group` int(11) DEFAULT NULL,
  `sessiontime` int(11) NOT NULL DEFAULT 0,
  PRIMARY KEY (`id`),
  UNIQUE KEY `pkg_callback_uniqueid_key` (`uniqueid`),
  KEY `fk_pkg_user_pkg_callback` (`id_user`),
  CONSTRAINT `fk_pkg_user_pkg_callback` FOREIGN KEY (`id_user`) REFERENCES `pkg_user` (`id`) ON DELETE CASCADE
) ENGINE=InnoDB DEFAULT CHARSET=utf8;

--
-- Table structure for table `pkg_callerid`
--

CREATE TABLE `pkg_callerid` (
  `id` int(11) NOT NULL AUTO_INCREMENT,
  `cid` varchar(100) CHARACTER SET utf8 COLLATE utf8_bin NOT NULL,
  `name` varchar(100) NOT NULL DEFAULT '',
  `description` mediumtext CHARACTER SET utf8 COLLATE utf8_bin DEFAULT NULL,
  `id_user` int(11) NOT NULL,
  `activated` char(1) CHARACTER SET utf8 COLLATE utf8_bin NOT NULL DEFAULT 't',
  PRIMARY KEY (`id`),
  UNIQUE KEY `cons_pkg_callerid_cid` (`cid`),
  KEY `fk_pkg_user_pkg_callerid` (`id_user`),
  CONSTRAINT `fk_pkg_user_pkg_callerid` FOREIGN KEY (`id_user`) REFERENCES `pkg_user` (`id`) ON DELETE CASCADE
) ENGINE=InnoDB DEFAULT CHARSET=utf8;
DELIMITER ;;;
DELIMITER ;

--
-- Table structure for table `pkg_campaign`
--

CREATE TABLE `pkg_campaign` (
  `id` int(11) NOT NULL AUTO_INCREMENT,
  `id_user` int(11) NOT NULL,
  `id_plan` int(11) DEFAULT NULL,
  `name` char(50) CHARACTER SET utf8 COLLATE utf8_bin NOT NULL,
  `creationdate` timestamp NOT NULL DEFAULT current_timestamp(),
  `startingdate` timestamp NOT NULL DEFAULT '0000-00-00 00:00:00',
  `expirationdate` timestamp NOT NULL DEFAULT '0000-00-00 00:00:00',
  `description` mediumtext CHARACTER SET utf8 COLLATE utf8_bin DEFAULT NULL,
  `secondusedreal` int(11) DEFAULT 0,
  `nb_callmade` int(11) DEFAULT 0,
  `status` int(11) NOT NULL DEFAULT 1,
  `frequency` int(11) NOT NULL DEFAULT 0,
  `max_frequency` int(11) NOT NULL DEFAULT 0,
  `forward_number` varchar(160) CHARACTER SET utf8 COLLATE utf8_bin DEFAULT NULL,
  `daily_start_time` time NOT NULL DEFAULT '10:00:00',
  `daily_stop_time` time NOT NULL DEFAULT '18:00:00',
  `monday` tinyint(4) NOT NULL DEFAULT 1,
  `tuesday` tinyint(4) NOT NULL DEFAULT 1,
  `wednesday` tinyint(4) NOT NULL DEFAULT 1,
  `thursday` tinyint(4) NOT NULL DEFAULT 1,
  `friday` tinyint(4) NOT NULL DEFAULT 1,
  `saturday` tinyint(4) NOT NULL DEFAULT 0,
  `sunday` tinyint(4) NOT NULL DEFAULT 0,
  `audio` varchar(100) CHARACTER SET utf8 COLLATE utf8_bin DEFAULT NULL,
  `audio_2` varchar(100) DEFAULT NULL,
  `type` int(10) DEFAULT 1,
  `restrict_phone` int(1) NOT NULL DEFAULT 0,
  `enable_max_call` int(1) NOT NULL DEFAULT 0,
  `digit_authorize` smallint(1) NOT NULL DEFAULT 1,
  `tts_audio` varchar(200) DEFAULT NULL,
  `tts_audio2` varchar(200) DEFAULT NULL,
  `asr_audio` varchar(200) DEFAULT NULL,
  `asr_options` varchar(200) DEFAULT NULL,
  `auto_reprocess` int(11) DEFAULT 0,
  `from` varchar(20) DEFAULT NULL,
  `record_call` int(11) NOT NULL DEFAULT 0,
  PRIMARY KEY (`id`),
  KEY `fk_pkg_user_pkg_campaign` (`id_user`),
  KEY `fk_pkg_plan_pkg_campaign` (`id_plan`),
  CONSTRAINT `fk_pkg_plan_pkg_campaign` FOREIGN KEY (`id_plan`) REFERENCES `pkg_plan` (`id`),
  CONSTRAINT `fk_pkg_user_pkg_campaign` FOREIGN KEY (`id_user`) REFERENCES `pkg_user` (`id`) ON DELETE CASCADE
) ENGINE=InnoDB DEFAULT CHARSET=utf8;

--
-- Table structure for table `pkg_campaign_log`
--

CREATE TABLE `pkg_campaign_log` (
  `id` int(11) NOT NULL AUTO_INCREMENT,
  `total` int(11) NOT NULL DEFAULT 0,
  `loops` int(11) NOT NULL DEFAULT 0,
  `date` timestamp NOT NULL DEFAULT current_timestamp(),
  `trunks` varchar(200) DEFAULT NULL,
  `campaigns` varchar(200) NOT NULL,
  PRIMARY KEY (`id`)
) ENGINE=InnoDB DEFAULT CHARSET=utf8;

--
-- Table structure for table `pkg_campaign_phonebook`
--

CREATE TABLE `pkg_campaign_phonebook` (
  `id_campaign` int(11) NOT NULL,
  `id_phonebook` int(11) NOT NULL,
  PRIMARY KEY (`id_campaign`,`id_phonebook`),
  KEY `fk_pkg_campaign_pkg_campaign_phonebook` (`id_campaign`),
  KEY `fk_pkg_phonebook_pkg_campaign_phonebook` (`id_phonebook`),
  CONSTRAINT `fk_pkg_campaign_pkg_campaign_phonebook` FOREIGN KEY (`id_campaign`) REFERENCES `pkg_campaign` (`id`) ON DELETE CASCADE,
  CONSTRAINT `fk_pkg_phonebook_pkg_campaign_phonebook` FOREIGN KEY (`id_phonebook`) REFERENCES `pkg_phonebook` (`id`) ON DELETE CASCADE
) ENGINE=InnoDB DEFAULT CHARSET=utf8;

--
-- Table structure for table `pkg_campaign_poll`
--

CREATE TABLE `pkg_campaign_poll` (
  `id` int(11) NOT NULL AUTO_INCREMENT,
  `id_user` int(11) NOT NULL,
  `id_campaign` int(11) DEFAULT NULL,
  `name` varchar(50) NOT NULL,
  `description` varchar(100) DEFAULT NULL,
  `arq_audio` varchar(100) DEFAULT NULL,
  `ordem_exibicao` int(11) DEFAULT NULL,
  `option0` varchar(150) NOT NULL,
  `option1` varchar(150) NOT NULL,
  `option2` varchar(150) NOT NULL,
  `option3` varchar(150) NOT NULL,
  `option4` varchar(150) NOT NULL,
  `option5` varchar(150) NOT NULL,
  `option6` varchar(150) NOT NULL,
  `option7` varchar(150) NOT NULL,
  `option8` varchar(150) NOT NULL,
  `option9` varchar(150) NOT NULL,
  `digit_authorize` int(1) NOT NULL DEFAULT 1,
  `request_authorize` int(1) NOT NULL DEFAULT 0,
  `repeat` int(1) NOT NULL DEFAULT 1,
  PRIMARY KEY (`id`),
  KEY `fk_pkg_campaign_pkg_campaign_poll` (`id_campaign`),
  CONSTRAINT `fk_pkg_campaign_pkg_campaign_poll` FOREIGN KEY (`id_campaign`) REFERENCES `pkg_campaign` (`id`) ON DELETE CASCADE
) ENGINE=InnoDB DEFAULT CHARSET=utf8;

--
-- Table structure for table `pkg_campaign_poll_info`
--

CREATE TABLE `pkg_campaign_poll_info` (
  `id` int(11) NOT NULL AUTO_INCREMENT,
  `id_campaign_poll` int(11) NOT NULL,
  `resposta` smallint(2) NOT NULL,
  `number` varchar(18) NOT NULL,
  `date` timestamp NOT NULL DEFAULT current_timestamp(),
  `obs` varchar(200) DEFAULT NULL,
  `city` varchar(50) DEFAULT NULL,
  PRIMARY KEY (`id`),
  KEY `fk_pkg_campaign_poll_pkg_campaign_poll_info` (`id_campaign_poll`),
  KEY `number` (`number`),
  CONSTRAINT `fk_pkg_campaign_poll_pkg_campaign_poll_info` FOREIGN KEY (`id_campaign_poll`) REFERENCES `pkg_campaign_poll` (`id`) ON DELETE CASCADE
) ENGINE=InnoDB DEFAULT CHARSET=utf8;

--
-- Table structure for table `pkg_campaign_report`
--

CREATE TABLE `pkg_campaign_report` (
  `id` int(11) NOT NULL AUTO_INCREMENT,
  `id_campaign` int(11) NOT NULL,
  `id_phonenumber` int(11) NOT NULL,
  `id_user` int(11) NOT NULL,
  `id_trunk` int(11) NOT NULL,
  `unix_timestamp` int(11) NOT NULL,
  `status` tinyint(1) NOT NULL DEFAULT 2,
  PRIMARY KEY (`id`),
  KEY `unix_timestamp` (`unix_timestamp`),
  KEY `fk_pkg_campaign_report_pkg_campaign` (`id_campaign`),
  KEY `fk_pkg_campaign_report_pkg_phonenumber` (`id_phonenumber`),
  KEY `fk_pkg_campaign_report_pkg_user` (`id_user`),
  KEY `fk_pkg_campaign_report_pkg_trunk` (`id_trunk`),
  CONSTRAINT `fk_pkg_campaign_report_pkg_campaign` FOREIGN KEY (`id_campaign`) REFERENCES `pkg_campaign` (`id`) ON DELETE CASCADE,
  CONSTRAINT `fk_pkg_campaign_report_pkg_phonenumber` FOREIGN KEY (`id_phonenumber`) REFERENCES `pkg_phonenumber` (`id`) ON DELETE CASCADE,
  CONSTRAINT `fk_pkg_campaign_report_pkg_trunk` FOREIGN KEY (`id_trunk`) REFERENCES `pkg_trunk` (`id`) ON DELETE CASCADE,
  CONSTRAINT `fk_pkg_campaign_report_pkg_user` FOREIGN KEY (`id_user`) REFERENCES `pkg_user` (`id`) ON DELETE CASCADE
) ENGINE=InnoDB DEFAULT CHARSET=utf8;

--
-- Table structure for table `pkg_campaign_restrict_phone`
--

CREATE TABLE `pkg_campaign_restrict_phone` (
  `id` int(11) NOT NULL AUTO_INCREMENT,
  `number` bigint(20) NOT NULL,
  PRIMARY KEY (`id`),
  KEY `number` (`number`)
) ENGINE=InnoDB DEFAULT CHARSET=utf8;

--
-- Table structure for table `pkg_cdr`
--

CREATE TABLE `pkg_cdr` (
  `id` int(11) NOT NULL AUTO_INCREMENT,
  `id_user` int(11) NOT NULL,
  `id_plan` int(11) DEFAULT NULL,
  `id_trunk` int(11) DEFAULT NULL,
  `id_server` int(11) DEFAULT NULL,
  `id_prefix` int(11) DEFAULT NULL,
  `id_campaign` int(11) DEFAULT NULL,
  `callerid` varchar(40) CHARACTER SET utf8 COLLATE utf8_bin NOT NULL DEFAULT '',
  `uniqueid` varchar(30) CHARACTER SET utf8 COLLATE utf8_bin NOT NULL,
  `starttime` timestamp NOT NULL DEFAULT current_timestamp(),
  `sessiontime` int(11) DEFAULT NULL,
  `calledstation` varchar(30) CHARACTER SET utf8 COLLATE utf8_bin NOT NULL,
  `sessionbill` float DEFAULT NULL,
  `sipiax` int(11) DEFAULT 0,
  `src` varchar(40) CHARACTER SET utf8 COLLATE utf8_bin NOT NULL,
  `buycost` decimal(15,6) DEFAULT 0.000000,
  `real_sessiontime` int(11) DEFAULT NULL,
  `terminatecauseid` int(1) DEFAULT 1,
  `agent_bill` decimal(15,6) DEFAULT 0.000000,
  `data_atualizacao` timestamp NOT NULL DEFAULT current_timestamp() ON UPDATE current_timestamp(),
  PRIMARY KEY (`id`),
  KEY `id_user` (`id_user`),
  KEY `id_trunk` (`id_trunk`),
  KEY `id_prefix` (`id_prefix`),
  KEY `calledstation` (`calledstation`),
  KEY `src` (`src`),
  KEY `callerid` (`callerid`),
  KEY `starttime` (`starttime`)
) ENGINE=InnoDB AUTO_INCREMENT=7848 DEFAULT CHARSET=utf8;
DELIMITER ;;;
DELIMITER ;

--
-- Table structure for table `pkg_cdr_archive`
--

CREATE TABLE `pkg_cdr_archive` (
  `id` int(11) NOT NULL AUTO_INCREMENT,
  `id_user` int(11) NOT NULL,
  `id_plan` int(11) DEFAULT NULL,
  `id_trunk` int(11) DEFAULT NULL,
  `id_did` int(11) DEFAULT NULL,
  `id_offer` int(11) DEFAULT 0,
  `id_prefix` int(11) DEFAULT NULL,
  `uniqueid` varchar(30) CHARACTER SET utf8 COLLATE utf8_bin NOT NULL,
  `starttime` timestamp NOT NULL DEFAULT current_timestamp(),
  `stoptime` timestamp NOT NULL DEFAULT '0000-00-00 00:00:00',
  `sessiontime` int(11) DEFAULT NULL,
  `calledstation` varchar(30) CHARACTER SET utf8 COLLATE utf8_bin NOT NULL,
  `sessionbill` float DEFAULT NULL,
  `sipiax` int(11) DEFAULT 0,
  `src` varchar(40) CHARACTER SET utf8 COLLATE utf8_bin NOT NULL,
  `buycost` decimal(15,5) DEFAULT 0.00000,
  `real_sessiontime` int(11) DEFAULT NULL,
  `terminatecauseid` int(1) DEFAULT 1,
  `agent_bill` decimal(15,5) DEFAULT 0.00000,
  PRIMARY KEY (`id`)
) ENGINE=InnoDB DEFAULT CHARSET=utf8;

--
-- Table structure for table `pkg_cdr_summary_day`
--

CREATE TABLE `pkg_cdr_summary_day` (
  `id` int(11) NOT NULL AUTO_INCREMENT,
  `day` varchar(10) NOT NULL,
  `sessiontime` bigint(25) NOT NULL,
  `aloc_all_calls` int(11) NOT NULL,
  `nbcall` int(11) NOT NULL,
  `nbcall_fail` int(11) DEFAULT NULL,
  `buycost` float NOT NULL DEFAULT 0,
  `sessionbill` float NOT NULL DEFAULT 0,
  `lucro` float DEFAULT NULL,
  `asr` float DEFAULT NULL,
  PRIMARY KEY (`id`),
  UNIQUE KEY `day` (`day`)
) ENGINE=InnoDB AUTO_INCREMENT=151996 DEFAULT CHARSET=latin1;

--
-- Table structure for table `pkg_cdr_summary_day_agent`
--

CREATE TABLE `pkg_cdr_summary_day_agent` (
  `id` int(11) NOT NULL AUTO_INCREMENT,
  `day` varchar(10) NOT NULL,
  `id_user` int(11) NOT NULL,
  `sessiontime` bigint(25) NOT NULL,
  `aloc_all_calls` int(11) NOT NULL,
  `nbcall` int(11) NOT NULL,
  `nbcall_fail` int(11) NOT NULL DEFAULT 0,
  `buycost` float NOT NULL DEFAULT 0,
  `sessionbill` float NOT NULL DEFAULT 0,
  `lucro` float DEFAULT 0,
  `agent_bill` float NOT NULL DEFAULT 0,
  `agent_lucro` float NOT NULL DEFAULT 0,
  `asr` float NOT NULL DEFAULT 0,
  PRIMARY KEY (`id`),
  KEY `day` (`day`),
  KEY `id_user` (`id_user`)
) ENGINE=InnoDB DEFAULT CHARSET=latin1;

--
-- Table structure for table `pkg_cdr_summary_day_trunk`
--

CREATE TABLE `pkg_cdr_summary_day_trunk` (
  `id` int(11) NOT NULL AUTO_INCREMENT,
  `day` varchar(10) NOT NULL,
  `id_trunk` int(11) NOT NULL,
  `sessiontime` bigint(25) NOT NULL,
  `aloc_all_calls` int(11) NOT NULL,
  `nbcall` int(11) NOT NULL,
  `nbcall_fail` int(11) NOT NULL DEFAULT 0,
  `buycost` float NOT NULL DEFAULT 0,
  `sessionbill` float NOT NULL DEFAULT 0,
  `lucro` float DEFAULT 0,
  `asr` float NOT NULL DEFAULT 0,
  PRIMARY KEY (`id`),
  KEY `day` (`day`),
  KEY `id_trunk` (`id_trunk`)
) ENGINE=InnoDB AUTO_INCREMENT=164449 DEFAULT CHARSET=latin1;

--
-- Table structure for table `pkg_cdr_summary_day_user`
--

CREATE TABLE `pkg_cdr_summary_day_user` (
  `id` int(11) NOT NULL AUTO_INCREMENT,
  `day` varchar(10) NOT NULL,
  `id_user` int(11) NOT NULL,
  `sessiontime` bigint(25) NOT NULL,
  `aloc_all_calls` int(11) NOT NULL,
  `nbcall` int(11) NOT NULL,
  `nbcall_fail` int(11) NOT NULL DEFAULT 0,
  `buycost` float DEFAULT 0,
  `sessionbill` float DEFAULT 0,
  `lucro` float DEFAULT 0,
  `isAgent` tinyint(1) DEFAULT NULL,
  `agent_bill` float NOT NULL DEFAULT 0,
  `asr` float NOT NULL DEFAULT 0,
  PRIMARY KEY (`id`),
  KEY `day` (`day`),
  KEY `id_user` (`id_user`)
) ENGINE=InnoDB AUTO_INCREMENT=1376929 DEFAULT CHARSET=latin1;

--
-- Table structure for table `pkg_cdr_summary_ids`
--

CREATE TABLE `pkg_cdr_summary_ids` (
  `id` int(11) NOT NULL AUTO_INCREMENT,
  `day` date NOT NULL,
  `cdr_id` int(11) NOT NULL,
  `cdr_falide_id` int(11) NOT NULL,
  PRIMARY KEY (`id`),
  UNIQUE KEY `day` (`day`)
) ENGINE=InnoDB DEFAULT CHARSET=latin1;

--
-- Table structure for table `pkg_cdr_summary_month`
--

CREATE TABLE `pkg_cdr_summary_month` (
  `id` int(11) NOT NULL AUTO_INCREMENT,
  `month` varchar(20) NOT NULL,
  `sessiontime` bigint(25) NOT NULL,
  `aloc_all_calls` int(11) NOT NULL,
  `nbcall` int(11) NOT NULL,
  `nbcall_fail` int(11) NOT NULL DEFAULT 0,
  `buycost` float NOT NULL DEFAULT 0,
  `sessionbill` float NOT NULL DEFAULT 0,
  `lucro` float DEFAULT 0,
  `asr` float NOT NULL DEFAULT 0,
  PRIMARY KEY (`id`),
  UNIQUE KEY `month` (`month`)
) ENGINE=InnoDB AUTO_INCREMENT=408549 DEFAULT CHARSET=latin1;

--
-- Table structure for table `pkg_cdr_summary_month_did`
--

CREATE TABLE `pkg_cdr_summary_month_did` (
  `id` int(11) NOT NULL AUTO_INCREMENT,
  `month` varchar(20) NOT NULL,
  `id_did` int(11) NOT NULL,
  `sessiontime` int(11) NOT NULL,
  `aloc_all_calls` int(11) NOT NULL,
  `nbcall` int(11) NOT NULL,
  `sessionbill` float NOT NULL DEFAULT 0,
  PRIMARY KEY (`id`),
  KEY `month` (`month`),
  KEY `id_did` (`id_did`),
  CONSTRAINT `pkg_cdr_summary_month_did_ibfk_1` FOREIGN KEY (`id_did`) REFERENCES `pkg_did` (`id`)
) ENGINE=InnoDB DEFAULT CHARSET=utf8;

--
-- Table structure for table `pkg_cdr_summary_month_trunk`
--

CREATE TABLE `pkg_cdr_summary_month_trunk` (
  `id` int(11) NOT NULL AUTO_INCREMENT,
  `month` varchar(20) NOT NULL,
  `id_trunk` int(11) NOT NULL,
  `sessiontime` bigint(25) NOT NULL,
  `aloc_all_calls` int(11) NOT NULL,
  `nbcall` int(11) NOT NULL,
  `nbcall_fail` int(11) NOT NULL DEFAULT 0,
  `buycost` float NOT NULL DEFAULT 0,
  `sessionbill` float NOT NULL DEFAULT 0,
  `lucro` float DEFAULT 0,
  `asr` float NOT NULL DEFAULT 0,
  PRIMARY KEY (`id`),
  KEY `month` (`month`),
  KEY `id_trunk` (`id_trunk`)
) ENGINE=InnoDB AUTO_INCREMENT=410516 DEFAULT CHARSET=latin1;

--
-- Table structure for table `pkg_cdr_summary_month_user`
--

CREATE TABLE `pkg_cdr_summary_month_user` (
  `id` int(11) NOT NULL AUTO_INCREMENT,
  `month` varchar(20) NOT NULL,
  `id_user` int(11) NOT NULL,
  `sessiontime` bigint(25) NOT NULL,
  `aloc_all_calls` int(11) NOT NULL,
  `nbcall` int(11) NOT NULL,
  `nbcall_fail` int(11) NOT NULL DEFAULT 0,
  `buycost` float NOT NULL DEFAULT 0,
  `sessionbill` float NOT NULL DEFAULT 0,
  `lucro` float DEFAULT 0,
  `isAgent` tinyint(1) DEFAULT NULL,
  `agent_bill` float NOT NULL DEFAULT 0,
  `asr` float NOT NULL DEFAULT 0,
  PRIMARY KEY (`id`),
  KEY `month` (`month`),
  KEY `id_user` (`id_user`)
) ENGINE=InnoDB AUTO_INCREMENT=14735559 DEFAULT CHARSET=latin1;

--
-- Table structure for table `pkg_cdr_summary_trunk`
--

CREATE TABLE `pkg_cdr_summary_trunk` (
  `id` int(11) NOT NULL AUTO_INCREMENT,
  `id_trunk` int(11) NOT NULL,
  `sessiontime` bigint(25) NOT NULL,
  `aloc_all_calls` int(11) NOT NULL,
  `nbcall` int(11) NOT NULL,
  `nbcall_fail` int(11) DEFAULT NULL,
  `buycost` float NOT NULL DEFAULT 0,
  `sessionbill` float NOT NULL DEFAULT 0,
  `lucro` float DEFAULT NULL,
  `asr` float DEFAULT NULL,
  PRIMARY KEY (`id`),
  KEY `id_trunk` (`id_trunk`)
) ENGINE=InnoDB AUTO_INCREMENT=2 DEFAULT CHARSET=latin1;

--
-- Table structure for table `pkg_cdr_summary_user`
--

CREATE TABLE `pkg_cdr_summary_user` (
  `id` int(11) NOT NULL AUTO_INCREMENT,
  `id_user` int(11) NOT NULL,
  `sessiontime` bigint(25) NOT NULL,
  `aloc_all_calls` int(11) NOT NULL,
  `nbcall` int(11) NOT NULL,
  `nbcall_fail` int(11) DEFAULT NULL,
  `buycost` float NOT NULL DEFAULT 0,
  `sessionbill` float NOT NULL DEFAULT 0,
  `lucro` float DEFAULT NULL,
  `asr` float DEFAULT NULL,
  `isAgent` int(11) DEFAULT NULL,
  `agent_bill` float NOT NULL DEFAULT 0,
  PRIMARY KEY (`id`),
  KEY `id_user` (`id_user`)
) ENGINE=InnoDB AUTO_INCREMENT=173 DEFAULT CHARSET=latin1;

--
-- Table structure for table `pkg_configuration`
--

CREATE TABLE `pkg_configuration` (
  `id` int(11) NOT NULL AUTO_INCREMENT,
  `config_title` varchar(100) CHARACTER SET utf8 COLLATE utf8_bin DEFAULT NULL,
  `config_key` varchar(100) CHARACTER SET utf8 COLLATE utf8_bin DEFAULT NULL,
  `config_value` varchar(200) CHARACTER SET utf8 COLLATE utf8_bin DEFAULT NULL,
  `config_description` varchar(500) CHARACTER SET utf8 COLLATE utf8_bin DEFAULT NULL,
  `config_group_title` varchar(64) CHARACTER SET utf8 COLLATE utf8_bin NOT NULL,
  `status` int(10) NOT NULL,
  PRIMARY KEY (`id`)
) ENGINE=InnoDB AUTO_INCREMENT=307 DEFAULT CHARSET=utf8;

--
-- Table structure for table `pkg_cryptocurrency`
--

CREATE TABLE `pkg_cryptocurrency` (
  `id` int(11) NOT NULL AUTO_INCREMENT,
  `id_user` int(11) NOT NULL,
  `status` tinyint(1) NOT NULL DEFAULT 0,
  `currency` varchar(50) NOT NULL,
  `amountCrypto` decimal(15,8) NOT NULL DEFAULT 0.00000000,
  `amount` decimal(15,8) NOT NULL DEFAULT 0.00000000,
  `date` timestamp NOT NULL DEFAULT current_timestamp(),
  PRIMARY KEY (`id`),
  KEY `fk_pkg_user_pkg_cryptocurrency` (`id_user`),
  CONSTRAINT `fk_pkg_user_pkg_cryptocurrency` FOREIGN KEY (`id_user`) REFERENCES `pkg_user` (`id`) ON DELETE CASCADE
) ENGINE=InnoDB DEFAULT CHARSET=utf8;

--
-- Table structure for table `pkg_did`
--

CREATE TABLE `pkg_did` (
  `id` int(11) NOT NULL AUTO_INCREMENT,
  `id_user` int(11) DEFAULT NULL,
  `activated` int(11) NOT NULL DEFAULT 1,
  `reserved` tinyint(11) DEFAULT 0,
  `did` char(50) CHARACTER SET utf8 COLLATE utf8_bin NOT NULL,
  `callerid` varchar(50) NOT NULL DEFAULT '',
  `creationdate` timestamp NOT NULL DEFAULT current_timestamp(),
  `startingdate` timestamp NOT NULL DEFAULT '0000-00-00 00:00:00',
  `expirationdate` timestamp NOT NULL DEFAULT '0000-00-00 00:00:00',
  `description` mediumtext CHARACTER SET utf8 COLLATE utf8_bin DEFAULT NULL,
  `secondusedreal` int(11) DEFAULT 0,
  `billingtype` int(11) DEFAULT 0,
  `cbr` tinyint(1) NOT NULL DEFAULT 0,
  `fixrate` float NOT NULL DEFAULT 0,
  `connection_charge` decimal(15,5) NOT NULL DEFAULT 0.00000,
  `expression_1` varchar(150) NOT NULL DEFAULT '*',
  `selling_rate_1` decimal(15,5) NOT NULL DEFAULT 0.00000,
  `expression_2` varchar(150) NOT NULL DEFAULT '*',
  `selling_rate_2` decimal(15,5) NOT NULL DEFAULT 0.00000,
  `connection_sell` decimal(15,5) NOT NULL DEFAULT 0.00000,
  `minimal_time_charge` int(11) NOT NULL DEFAULT 0,
  `initblock` int(11) NOT NULL DEFAULT 1,
  `cbr_ua` tinyint(1) NOT NULL DEFAULT 0,
  `cbr_em` tinyint(1) NOT NULL DEFAULT 0,
  `cbr_total_try` int(11) NOT NULL DEFAULT 3,
  `cbr_time_try` int(11) NOT NULL DEFAULT 30,
  `increment` int(11) NOT NULL DEFAULT 1,
  `block_expression_1` smallint(2) NOT NULL DEFAULT 0,
  `block_expression_2` smallint(2) NOT NULL DEFAULT 0,
  `expression_3` varchar(150) NOT NULL DEFAULT '*',
  `selling_rate_3` decimal(15,5) NOT NULL DEFAULT 0.00000,
  `block_expression_3` smallint(2) NOT NULL DEFAULT 0,
  `charge_of` int(1) NOT NULL DEFAULT 1,
  `send_to_callback_1` tinyint(1) NOT NULL DEFAULT 0,
  `send_to_callback_2` tinyint(1) NOT NULL DEFAULT 0,
  `send_to_callback_3` tinyint(1) NOT NULL DEFAULT 0,
  `TimeOfDay_monFri` varchar(150) DEFAULT NULL,
  `TimeOfDay_sat` varchar(150) DEFAULT NULL,
  `TimeOfDay_sun` varchar(150) DEFAULT NULL,
  `workaudio` varchar(150) DEFAULT NULL,
  `noworkaudio` varchar(150) DEFAULT NULL,
  `calllimit` int(11) NOT NULL DEFAULT -1,
  `record_call` int(11) NOT NULL DEFAULT 0,
  PRIMARY KEY (`id`),
  UNIQUE KEY `did` (`did`),
  KEY `fk_pkg_user_pkg_did` (`id_user`),
  CONSTRAINT `fk_pkg_user_pkg_did` FOREIGN KEY (`id_user`) REFERENCES `pkg_user` (`id`)
) ENGINE=InnoDB DEFAULT CHARSET=utf8;

--
-- Table structure for table `pkg_did_destination`
--

CREATE TABLE `pkg_did_destination` (
  `id` int(11) NOT NULL AUTO_INCREMENT,
  `id_user` int(11) NOT NULL,
  `id_ivr` int(11) DEFAULT NULL,
  `id_sip` int(11) DEFAULT NULL,
  `id_queue` int(11) DEFAULT NULL,
  `id_did` int(11) NOT NULL,
  `destination` varchar(120) CHARACTER SET utf8 COLLATE utf8_bin NOT NULL,
  `context` text DEFAULT NULL,
  `priority` int(11) NOT NULL DEFAULT 0,
  `creationdate` timestamp NOT NULL DEFAULT current_timestamp() ON UPDATE current_timestamp(),
  `activated` int(11) NOT NULL DEFAULT 1,
  `secondusedreal` int(11) DEFAULT 0,
  `voip_call` int(11) DEFAULT 0,
  PRIMARY KEY (`id`),
  KEY `fk_pkg_did_pkg_did_destination` (`id_did`),
  KEY `fk_pkg_user_pkg_did_destination` (`id_user`),
  CONSTRAINT `fk_pkg_did_pkg_did_destination` FOREIGN KEY (`id_did`) REFERENCES `pkg_did` (`id`),
  CONSTRAINT `fk_pkg_user_pkg_did_destination` FOREIGN KEY (`id_user`) REFERENCES `pkg_user` (`id`)
) ENGINE=InnoDB DEFAULT CHARSET=utf8;

--
-- Table structure for table `pkg_did_use`
--

CREATE TABLE `pkg_did_use` (
  `id` int(11) NOT NULL AUTO_INCREMENT,
  `id_user` int(11) DEFAULT NULL,
  `id_did` int(11) DEFAULT NULL,
  `reservationdate` timestamp NOT NULL DEFAULT current_timestamp(),
  `releasedate` timestamp NOT NULL DEFAULT '0000-00-00 00:00:00',
  `status` int(11) DEFAULT 0,
  `month_payed` int(11) DEFAULT 0,
  `reminded` tinyint(4) NOT NULL DEFAULT 0,
  PRIMARY KEY (`id`),
  KEY `id_card` (`id_user`),
  KEY `id_did` (`id_did`)
) ENGINE=InnoDB DEFAULT CHARSET=utf8;

--
-- Table structure for table `pkg_estados`
--

CREATE TABLE `pkg_estados` (
  `id` int(11) NOT NULL,
  `nome` varchar(45) NOT NULL,
  `sigla` varchar(2) NOT NULL,
  PRIMARY KEY (`id`,`sigla`),
  UNIQUE KEY `sigla_UNIQUE` (`sigla`)
) ENGINE=InnoDB DEFAULT CHARSET=utf8;

--
-- Table structure for table `pkg_firewall`
--

CREATE TABLE `pkg_firewall` (
  `id` int(11) NOT NULL AUTO_INCREMENT,
  `date` timestamp NOT NULL DEFAULT current_timestamp(),
  `ip` varchar(50) CHARACTER SET utf8 COLLATE utf8_bin NOT NULL,
  `action` int(1) NOT NULL,
  `description` text NOT NULL,
  `jail` varchar(100) DEFAULT NULL,
  PRIMARY KEY (`id`)
) ENGINE=InnoDB DEFAULT CHARSET=utf8;

--
-- Table structure for table `pkg_group_module`
--

CREATE TABLE `pkg_group_module` (
  `id_group` int(11) NOT NULL,
  `id_module` int(11) NOT NULL,
  `action` varchar(45) NOT NULL,
  `show_menu` tinyint(1) NOT NULL DEFAULT 1,
  `createShortCut` tinyint(1) NOT NULL DEFAULT 0,
  `createQuickStart` tinyint(1) NOT NULL DEFAULT 0,
  PRIMARY KEY (`id_group`,`id_module`),
  KEY `fk_pkg_module_group_pkg_module` (`id_module`),
  CONSTRAINT `fk_pkg_group_user_pkg_group_module` FOREIGN KEY (`id_group`) REFERENCES `pkg_group_user` (`id`),
  CONSTRAINT `fk_pkg_module_group_pkg_module` FOREIGN KEY (`id_module`) REFERENCES `pkg_module` (`id`)
) ENGINE=InnoDB DEFAULT CHARSET=utf8;

--
-- Table structure for table `pkg_group_user`
--

CREATE TABLE `pkg_group_user` (
  `id` int(11) NOT NULL AUTO_INCREMENT,
  `name` varchar(100) NOT NULL,
  `id_user_type` int(11) NOT NULL,
  `user_prefix` int(11) DEFAULT NULL,
  `hidden_prices` tinyint(1) NOT NULL DEFAULT 0,
  PRIMARY KEY (`id`),
  KEY `pkg_user_type_pkg_group_user` (`id_user_type`),
  CONSTRAINT `pkg_user_type_pkg_group_user` FOREIGN KEY (`id_user_type`) REFERENCES `pkg_user_type` (`id`)
) ENGINE=InnoDB AUTO_INCREMENT=4 DEFAULT CHARSET=utf8;

--
-- Table structure for table `pkg_group_user_group`
--

CREATE TABLE `pkg_group_user_group` (
  `id` int(11) NOT NULL AUTO_INCREMENT,
  `id_group_user` int(11) NOT NULL,
  `id_group` int(11) NOT NULL,
  PRIMARY KEY (`id`),
  KEY `fk_pkg_pkg_group_user_pkg_group` (`id_group_user`),
  KEY `fk_pkg_group_pkg_pkg_group_user_group` (`id_group`),
  CONSTRAINT `fk_pkg_group_pkg_pkg_group_user_group` FOREIGN KEY (`id_group`) REFERENCES `pkg_group_user` (`id`) ON DELETE CASCADE,
  CONSTRAINT `fk_pkg_pkg_group_user_pkg_group` FOREIGN KEY (`id_group_user`) REFERENCES `pkg_group_user` (`id`) ON DELETE CASCADE
) ENGINE=InnoDB DEFAULT CHARSET=utf8;

--
-- Table structure for table `pkg_holidays`
--

CREATE TABLE `pkg_holidays` (
  `id` int(11) NOT NULL AUTO_INCREMENT,
  `name` varchar(50) NOT NULL,
  `day` date NOT NULL,
  PRIMARY KEY (`id`)
) ENGINE=InnoDB DEFAULT CHARSET=utf8;

--
-- Table structure for table `pkg_ivr`
--

CREATE TABLE `pkg_ivr` (
  `id` int(11) NOT NULL AUTO_INCREMENT,
  `id_user` int(11) NOT NULL,
  `id_did` int(11) DEFAULT NULL,
  `name` varchar(50) NOT NULL,
  `monFriStart` varchar(200) NOT NULL DEFAULT '09:00-12:00|14:00-18:00',
  `satStart` varchar(200) NOT NULL DEFAULT '09:00-12:00',
  `sunStart` varchar(200) NOT NULL DEFAULT '00:00',
  `option_0` varchar(50) DEFAULT NULL,
  `option_1` varchar(50) DEFAULT NULL,
  `option_2` varchar(50) DEFAULT NULL,
  `option_3` varchar(50) DEFAULT NULL,
  `option_4` varchar(50) DEFAULT NULL,
  `option_5` varchar(50) DEFAULT NULL,
  `option_6` varchar(50) DEFAULT NULL,
  `option_7` varchar(50) DEFAULT NULL,
  `option_8` varchar(50) DEFAULT NULL,
  `option_9` varchar(50) DEFAULT NULL,
  `option_10` varchar(50) DEFAULT NULL,
  `direct_extension` tinyint(1) DEFAULT 0,
  `workaudio` varchar(100) DEFAULT NULL,
  `noworkaudio` varchar(100) DEFAULT NULL,
  `option_out_0` varchar(50) DEFAULT NULL,
  `option_out_1` varchar(50) DEFAULT NULL,
  `option_out_2` varchar(50) DEFAULT NULL,
  `option_out_3` varchar(50) DEFAULT NULL,
  `option_out_4` varchar(50) DEFAULT NULL,
  `option_out_5` varchar(50) DEFAULT NULL,
  `option_out_6` varchar(50) DEFAULT NULL,
  `option_out_7` varchar(50) DEFAULT NULL,
  `option_out_8` varchar(50) DEFAULT NULL,
  `option_out_9` varchar(50) DEFAULT NULL,
  `option_out_10` varchar(50) DEFAULT NULL,
  `use_holidays` tinyint(1) NOT NULL DEFAULT 0,
  PRIMARY KEY (`id`),
  KEY `fk_pkg_user_pkg_ivr` (`id_user`),
  KEY `fk_pkg_did_pkg_ivr` (`id_did`),
  CONSTRAINT `fk_pkg_user_pkg_ivr` FOREIGN KEY (`id_user`) REFERENCES `pkg_user` (`id`)
) ENGINE=InnoDB DEFAULT CHARSET=utf8;

--
-- Table structure for table `pkg_log`
--

CREATE TABLE `pkg_log` (
  `id` int(11) NOT NULL AUTO_INCREMENT,
  `id_user` int(11) DEFAULT NULL,
  `id_log_actions` int(11) DEFAULT NULL,
  `description` mediumtext CHARACTER SET utf8 COLLATE utf8_bin DEFAULT NULL,
  `username` varchar(50) DEFAULT NULL,
  `date` timestamp NOT NULL DEFAULT current_timestamp(),
  `ip` varchar(50) DEFAULT NULL,
  PRIMARY KEY (`id`),
  KEY `fk_pkg_log_actions_pkg_log` (`id_log_actions`)
) ENGINE=InnoDB AUTO_INCREMENT=80 DEFAULT CHARSET=utf8;

--
-- Table structure for table `pkg_log_actions`
--

CREATE TABLE `pkg_log_actions` (
  `id` int(11) NOT NULL,
  `name` varchar(20) NOT NULL,
  PRIMARY KEY (`id`)
) ENGINE=InnoDB DEFAULT CHARSET=latin1;

--
-- Table structure for table `pkg_module`
--

CREATE TABLE `pkg_module` (
  `id` int(11) NOT NULL AUTO_INCREMENT,
  `text` varchar(100) NOT NULL,
  `module` varchar(100) DEFAULT NULL,
  `icon_cls` varchar(100) DEFAULT NULL,
  `id_module` int(11) DEFAULT NULL,
  `priority` int(11) DEFAULT NULL,
  PRIMARY KEY (`id`),
  KEY `fk_pkg_module_pkg_module` (`id_module`),
  CONSTRAINT `fk_pkg_module_pkg_module` FOREIGN KEY (`id_module`) REFERENCES `pkg_module` (`id`)
) ENGINE=InnoDB AUTO_INCREMENT=110 DEFAULT CHARSET=utf8;

--
-- Table structure for table `pkg_offer`
--

CREATE TABLE `pkg_offer` (
  `id` int(11) NOT NULL AUTO_INCREMENT,
  `creationdate` timestamp NOT NULL DEFAULT current_timestamp(),
  `label` varchar(70) CHARACTER SET utf8 COLLATE utf8_bin NOT NULL,
  `packagetype` int(11) NOT NULL,
  `billingtype` int(11) NOT NULL,
  `startday` int(11) NOT NULL,
  `freetimetocall` int(11) NOT NULL,
  `price` decimal(10,3) NOT NULL,
  `initblock` int(11) NOT NULL DEFAULT 60,
  `billingblock` int(11) NOT NULL DEFAULT 60,
  `minimal_time_charge` int(2) NOT NULL DEFAULT 0,
  PRIMARY KEY (`id`)
) ENGINE=InnoDB DEFAULT CHARSET=utf8;

--
-- Table structure for table `pkg_offer_cdr`
--

CREATE TABLE `pkg_offer_cdr` (
  `id` int(11) NOT NULL AUTO_INCREMENT,
  `id_user` int(11) NOT NULL,
  `id_offer` int(11) NOT NULL,
  `date_consumption` timestamp NOT NULL DEFAULT current_timestamp(),
  `used_secondes` int(11) NOT NULL,
  PRIMARY KEY (`id`),
  KEY `ind_pkg_offer_cdr_date_consumption` (`date_consumption`),
  KEY `fk_pkg_user_pkg_offer_cdr` (`id_user`),
  KEY `fk_pkg_offer_pkg_offer_cdr` (`id_offer`),
  CONSTRAINT `fk_pkg_offer_pkg_offer_cdr` FOREIGN KEY (`id_offer`) REFERENCES `pkg_offer` (`id`),
  CONSTRAINT `fk_pkg_user_pkg_offer_cdr` FOREIGN KEY (`id_user`) REFERENCES `pkg_user` (`id`)
) ENGINE=InnoDB DEFAULT CHARSET=utf8;

--
-- Table structure for table `pkg_offer_use`
--

CREATE TABLE `pkg_offer_use` (
  `id` int(11) NOT NULL AUTO_INCREMENT,
  `id_user` int(11) DEFAULT NULL,
  `id_offer` int(11) NOT NULL,
  `reservationdate` timestamp NOT NULL DEFAULT current_timestamp(),
  `releasedate` timestamp NOT NULL DEFAULT '0000-00-00 00:00:00',
  `status` int(11) DEFAULT 0,
  `month_payed` int(11) DEFAULT 0,
  `reminded` tinyint(4) NOT NULL DEFAULT 0,
  PRIMARY KEY (`id`),
  KEY `fk_pkg_user_pkg_offer_use` (`id_user`),
  KEY `fk_pkg_offer_pkg_offer_use` (`id_offer`),
  CONSTRAINT `fk_pkg_offer_pkg_offer_use` FOREIGN KEY (`id_offer`) REFERENCES `pkg_offer` (`id`),
  CONSTRAINT `fk_pkg_user_pkg_offer_use` FOREIGN KEY (`id_user`) REFERENCES `pkg_user` (`id`)
) ENGINE=InnoDB DEFAULT CHARSET=utf8;

--
-- Table structure for table `pkg_phonebook`
--

CREATE TABLE `pkg_phonebook` (
  `id` int(11) NOT NULL AUTO_INCREMENT,
  `id_user` int(11) NOT NULL,
  `name` char(30) CHARACTER SET utf8 COLLATE utf8_bin NOT NULL,
  `description` varchar(100) CHARACTER SET utf8 COLLATE utf8_bin DEFAULT NULL,
  `status` int(1) NOT NULL DEFAULT 1,
  PRIMARY KEY (`id`),
  KEY `fk_pkg_user_pkg_phonebook` (`id_user`),
  CONSTRAINT `fk_pkg_user_pkg_phonebook` FOREIGN KEY (`id_user`) REFERENCES `pkg_user` (`id`) ON DELETE CASCADE
) ENGINE=InnoDB DEFAULT CHARSET=utf8;

--
-- Table structure for table `pkg_phonenumber`
--

CREATE TABLE `pkg_phonenumber` (
  `id` int(11) NOT NULL AUTO_INCREMENT,
  `id_phonebook` int(11) NOT NULL,
  `number` varchar(30) CHARACTER SET utf8 COLLATE utf8_bin NOT NULL,
  `name` char(40) CHARACTER SET utf8 COLLATE utf8_bin DEFAULT NULL,
  `email` varchar(200) DEFAULT NULL,
  `doc` varchar(200) DEFAULT NULL,
  `creationdate` timestamp NOT NULL DEFAULT current_timestamp(),
  `status` smallint(6) NOT NULL DEFAULT 1,
  `info` mediumtext CHARACTER SET utf8 COLLATE utf8_bin DEFAULT NULL,
  `try` smallint(1) NOT NULL DEFAULT 0,
  `city` varchar(50) DEFAULT NULL,
  PRIMARY KEY (`id`),
  KEY `fk_pkg_phonebook_pkg_phonenumber` (`id_phonebook`),
  KEY `number` (`number`),
  CONSTRAINT `fk_pkg_phonebook_pkg_phonenumber` FOREIGN KEY (`id_phonebook`) REFERENCES `pkg_phonebook` (`id`) ON DELETE CASCADE
) ENGINE=InnoDB DEFAULT CHARSET=utf8;

--
-- Table structure for table `pkg_plan`
--

CREATE TABLE `pkg_plan` (
  `id` int(11) NOT NULL AUTO_INCREMENT,
  `id_user` int(11) DEFAULT NULL,
  `name` char(50) CHARACTER SET utf8 COLLATE utf8_bin NOT NULL,
  `lcrtype` int(11) NOT NULL DEFAULT 0,
  `creationdate` timestamp NOT NULL DEFAULT current_timestamp(),
  `removeinterprefix` int(11) NOT NULL DEFAULT 1,
  `signup` int(11) NOT NULL DEFAULT 0,
  `portabilidadeMobile` tinyint(1) NOT NULL DEFAULT 0,
  `portabilidadeFixed` tinyint(1) NOT NULL DEFAULT 0,
  `ini_credit` decimal(10,5) NOT NULL DEFAULT 0.00000,
  `techprefix` varchar(7) NOT NULL DEFAULT '',
  `play_audio` smallint(1) NOT NULL DEFAULT 0,
  `tariff_limit` int(11) NOT NULL DEFAULT 3,
  PRIMARY KEY (`id`),
  KEY `fk_pkg_user_pkg_plan` (`id_user`),
  KEY `id_user` (`id_user`),
  CONSTRAINT `fk_pkg_user_pkg_plan` FOREIGN KEY (`id_user`) REFERENCES `pkg_user` (`id`)
) ENGINE=InnoDB AUTO_INCREMENT=2 DEFAULT CHARSET=utf8;

--
-- Table structure for table `pkg_prefix`
--

CREATE TABLE `pkg_prefix` (
  `id` int(11) NOT NULL AUTO_INCREMENT,
  `prefix` varchar(18) NOT NULL,
  `destination` varchar(60) CHARACTER SET utf8 COLLATE utf8_bin NOT NULL,
  PRIMARY KEY (`id`),
  UNIQUE KEY `prefix_2` (`prefix`),
  KEY `prefix` (`prefix`),
  KEY `destination` (`destination`)
) ENGINE=InnoDB AUTO_INCREMENT=716 DEFAULT CHARSET=utf8;

--
-- Table structure for table `pkg_prefix_length`
--

CREATE TABLE `pkg_prefix_length` (
  `id` int(11) NOT NULL AUTO_INCREMENT,
  `code` int(11) NOT NULL,
  `length` int(11) NOT NULL,
  PRIMARY KEY (`id`),
  UNIQUE KEY `code` (`code`)
) ENGINE=InnoDB DEFAULT CHARSET=latin1;

--
-- Table structure for table `pkg_provider`
--

CREATE TABLE `pkg_provider` (
  `id` int(11) NOT NULL AUTO_INCREMENT,
  `provider_name` char(30) CHARACTER SET utf8 COLLATE utf8_bin NOT NULL,
  `creationdate` timestamp NOT NULL DEFAULT current_timestamp(),
  `description` mediumtext CHARACTER SET utf8 COLLATE utf8_bin DEFAULT NULL,
  `credit` decimal(18,5) NOT NULL DEFAULT 0.00000,
  `credit_control` smallint(1) NOT NULL DEFAULT 0,
  PRIMARY KEY (`id`),
  UNIQUE KEY `cons_pkg_provider_provider_name` (`provider_name`)
) ENGINE=InnoDB AUTO_INCREMENT=2 DEFAULT CHARSET=utf8;

--
-- Table structure for table `pkg_queue`
--

CREATE TABLE `pkg_queue` (
  `id` int(11) NOT NULL AUTO_INCREMENT,
  `name` varchar(128) NOT NULL,
  `id_user` int(11) DEFAULT NULL,
  `language` varchar(5) NOT NULL,
  `musiconhold` varchar(128) DEFAULT NULL,
  `announce` varchar(128) DEFAULT NULL,
  `context` varchar(128) DEFAULT NULL,
  `timeout` int(11) DEFAULT NULL,
  `announce-frequency` int(11) DEFAULT NULL,
  `announce-round-seconds` int(11) DEFAULT NULL,
  `announce-holdtime` varchar(128) DEFAULT NULL,
  `announce-position` varchar(5) NOT NULL DEFAULT 'yes',
  `retry` int(11) DEFAULT NULL,
  `wrapuptime` int(11) DEFAULT NULL,
  `maxlen` int(11) DEFAULT NULL,
  `servicelevel` int(11) DEFAULT NULL,
  `strategy` varchar(128) DEFAULT NULL,
  `joinempty` varchar(128) DEFAULT NULL,
  `leavewhenempty` varchar(128) DEFAULT NULL,
  `eventmemberstatus` tinyint(1) DEFAULT NULL,
  `eventwhencalled` tinyint(1) DEFAULT NULL,
  `reportholdtime` tinyint(1) DEFAULT NULL,
  `memberdelay` int(11) DEFAULT NULL,
  `weight` int(11) DEFAULT NULL,
  `timeoutrestart` tinyint(1) DEFAULT NULL,
  `periodic-announce` varchar(200) DEFAULT NULL,
  `periodic-announce-frequency` int(11) DEFAULT NULL,
  `ringinuse` varchar(3) DEFAULT NULL,
  `setinterfacevar` varchar(3) DEFAULT 'yes',
  `setqueuevar` varchar(3) NOT NULL DEFAULT 'yes',
  `setqueueentryvar` varchar(3) NOT NULL DEFAULT 'yes',
  `var_holdtime` int(11) NOT NULL DEFAULT 0,
  `var_talktime` int(11) NOT NULL DEFAULT 0,
  `var_totalCalls` int(11) NOT NULL DEFAULT 0,
  `var_answeredCalls` int(11) NOT NULL DEFAULT 0,
  `ring_or_moh` varchar(4) NOT NULL DEFAULT 'moh',
  `max_wait_time` int(11) DEFAULT NULL,
  `max_wait_time_action` varchar(50) DEFAULT NULL,
  PRIMARY KEY (`id`),
  UNIQUE KEY `name` (`name`),
  KEY `fk_pkg_user_pkg_queue` (`id_user`),
  CONSTRAINT `fk_pkg_user_pkg_queue` FOREIGN KEY (`id_user`) REFERENCES `pkg_user` (`id`)
) ENGINE=InnoDB DEFAULT CHARSET=utf8;

--
-- Table structure for table `pkg_queue_agent_status`
--

CREATE TABLE `pkg_queue_agent_status` (
  `id` int(11) NOT NULL AUTO_INCREMENT,
  `id_user` int(11) DEFAULT NULL,
  `id_queue` int(11) NOT NULL,
  `agentName` varchar(40) DEFAULT NULL,
  `agentStatus` varchar(30) DEFAULT NULL,
  `totalCalls` int(11) NOT NULL DEFAULT 0,
  `last_call` int(11) NOT NULL DEFAULT 0,
  PRIMARY KEY (`id`),
  UNIQUE KEY `unique_index` (`agentName`,`id_queue`),
  KEY `id_user` (`id_user`),
  KEY `id_queue` (`id_queue`)
) ENGINE=InnoDB DEFAULT CHARSET=latin1;

--
-- Table structure for table `pkg_queue_member`
--

CREATE TABLE `pkg_queue_member` (
  `id` int(11) NOT NULL AUTO_INCREMENT,
  `uniqueid` int(11) DEFAULT NULL,
  `id_user` int(11) NOT NULL,
  `membername` varchar(40) DEFAULT NULL,
  `queue_name` varchar(128) DEFAULT NULL,
  `interface` varchar(128) DEFAULT NULL,
  `penalty` int(11) DEFAULT NULL,
  `paused` tinyint(11) DEFAULT NULL,
  PRIMARY KEY (`id`),
  UNIQUE KEY `queue_interface` (`queue_name`,`interface`),
  KEY `fk_pkg_user_pkg_queue_member` (`id_user`),
  CONSTRAINT `fk_pkg_user_pkg_queue_member` FOREIGN KEY (`id_user`) REFERENCES `pkg_user` (`id`)
) ENGINE=InnoDB DEFAULT CHARSET=utf8;

--
-- Table structure for table `pkg_queue_status`
--

CREATE TABLE `pkg_queue_status` (
  `id` int(11) NOT NULL AUTO_INCREMENT,
  `id_queue` int(11) DEFAULT NULL,
  `id_agent` int(11) DEFAULT NULL,
  `callId` varchar(40) NOT NULL,
  `callerId` varchar(60) NOT NULL,
  `status` varchar(30) NOT NULL,
  `time` timestamp NULL DEFAULT NULL,
  `queue_name` varchar(25) NOT NULL,
  `priority` int(11) NOT NULL DEFAULT 0,
  `channel` varchar(50) NOT NULL,
  `holdtime` varchar(11) DEFAULT '',
  `totalCalls` int(11) DEFAULT NULL,
  `answeredCalls` int(11) DEFAULT NULL,
  `callduration` int(11) DEFAULT NULL,
  `oldtime` int(11) NOT NULL DEFAULT 0,
  `agentName` varchar(50) NOT NULL DEFAULT '',
  PRIMARY KEY (`id`),
  KEY `callerId` (`callerId`),
  KEY `status` (`status`),
  KEY `timestamp` (`time`),
  KEY `queue_name` (`queue_name`)
) ENGINE=InnoDB DEFAULT CHARSET=latin1;

--
-- Table structure for table `pkg_rate`
--

CREATE TABLE `pkg_rate` (
  `id` int(11) NOT NULL AUTO_INCREMENT,
  `id_plan` int(11) NOT NULL,
  `id_trunk_group` int(11) NOT NULL,
  `id_prefix` int(11) NOT NULL,
  `rateinitial` decimal(15,6) DEFAULT 0.000000,
  `initblock` int(11) NOT NULL DEFAULT 1,
  `billingblock` int(11) NOT NULL DEFAULT 1,
  `connectcharge` decimal(15,5) NOT NULL DEFAULT 0.00000,
  `disconnectcharge` decimal(15,5) NOT NULL DEFAULT 0.00000,
  `additional_grace` varchar(11) CHARACTER SET utf8 COLLATE utf8_bin NOT NULL DEFAULT '0',
  `minimal_time_charge` int(2) NOT NULL DEFAULT 0,
  `package_offer` smallint(1) NOT NULL DEFAULT 0,
  `status` tinyint(1) NOT NULL DEFAULT 1,
  `dialprefix` bigint(20) DEFAULT NULL,
  `destination` varchar(50) DEFAULT NULL,
  PRIMARY KEY (`id`),
  KEY `fk_pkg_plan_pkg_rate` (`id_plan`),
  KEY `fk_pkg_prefix_pkg_rate` (`id_prefix`),
  KEY `fk_pkg_trunk_pkg_rate` (`id_trunk_group`),
  KEY `dialprefix` (`dialprefix`),
  CONSTRAINT `fk_pkg_plan_pkg_rate` FOREIGN KEY (`id_plan`) REFERENCES `pkg_plan` (`id`),
  CONSTRAINT `fk_pkg_trunk_group_pkg_rate` FOREIGN KEY (`id_trunk_group`) REFERENCES `pkg_trunk_group` (`id`)
) ENGINE=InnoDB AUTO_INCREMENT=1025 DEFAULT CHARSET=utf8;

--
-- Table structure for table `pkg_rate_agent`
--

CREATE TABLE `pkg_rate_agent` (
  `id` int(11) NOT NULL AUTO_INCREMENT,
  `id_plan` int(11) NOT NULL,
  `id_prefix` int(11) NOT NULL,
  `rateinitial` decimal(15,5) NOT NULL DEFAULT 0.00000,
  `initblock` int(11) NOT NULL DEFAULT 0,
  `billingblock` int(11) NOT NULL DEFAULT 0,
  `minimal_time_charge` smallint(2) NOT NULL DEFAULT 0,
  PRIMARY KEY (`id`),
  KEY `fk_pkg_plan_pkg_rate_agent` (`id_plan`),
  KEY `fk_pkg_prefix_pkg_rate_agent` (`id_prefix`),
  CONSTRAINT `fk_pkg_plan_pkg_rate_agent` FOREIGN KEY (`id_plan`) REFERENCES `pkg_plan` (`id`) ON DELETE CASCADE,
  CONSTRAINT `fk_pkg_prefix_pkg_rate_agent` FOREIGN KEY (`id_prefix`) REFERENCES `pkg_prefix` (`id`)
) ENGINE=InnoDB DEFAULT CHARSET=utf8;

--
-- Table structure for table `pkg_rate_callshop`
--

CREATE TABLE `pkg_rate_callshop` (
  `id` int(11) NOT NULL AUTO_INCREMENT,
  `id_user` int(11) DEFAULT NULL,
  `dialprefix` char(30) CHARACTER SET utf8 COLLATE utf8_bin NOT NULL,
  `destination` varchar(100) CHARACTER SET utf8 COLLATE utf8_bin NOT NULL,
  `buyrate` decimal(15,5) NOT NULL DEFAULT 0.00000,
  `minimo` int(10) NOT NULL DEFAULT 1,
  `block` int(10) NOT NULL DEFAULT 1,
  `minimal_time_charge` int(11) DEFAULT 0,
  PRIMARY KEY (`id`),
  KEY `dialprefix` (`dialprefix`),
  KEY `fk_pkg_user_pkg_rate_callshop` (`id_user`),
  CONSTRAINT `fk_pkg_user_pkg_rate_callshop` FOREIGN KEY (`id_user`) REFERENCES `pkg_user` (`id`) ON DELETE CASCADE
) ENGINE=InnoDB DEFAULT CHARSET=utf8;

--
-- Table structure for table `pkg_rate_provider`
--

CREATE TABLE `pkg_rate_provider` (
  `id` int(11) NOT NULL AUTO_INCREMENT,
  `id_provider` int(11) NOT NULL,
  `id_prefix` int(11) NOT NULL,
  `buyrate` decimal(15,6) DEFAULT 0.000000,
  `buyrateinitblock` int(11) NOT NULL DEFAULT 1,
  `buyrateincrement` int(11) NOT NULL DEFAULT 1,
  `minimal_time_buy` int(2) NOT NULL DEFAULT 0,
  `dialprefix` bigint(20) DEFAULT NULL,
  `destination` varchar(50) DEFAULT NULL,
  PRIMARY KEY (`id`),
  KEY `fk_pkg_prefix_pkg_rate` (`id_prefix`),
  KEY `dialprefix` (`dialprefix`),
  KEY `fk_pkg_provider_pkg_rate_provider` (`id_provider`),
  KEY `id_prefix` (`id_prefix`),
  CONSTRAINT `fk_pkg_provider_pkg_rate_provider` FOREIGN KEY (`id_provider`) REFERENCES `pkg_provider` (`id`) ON DELETE CASCADE
) ENGINE=InnoDB DEFAULT CHARSET=utf8;

--
-- Table structure for table `pkg_refill`
--

CREATE TABLE `pkg_refill` (
  `id` int(11) NOT NULL AUTO_INCREMENT,
  `id_user` int(11) NOT NULL,
  `date` timestamp NOT NULL DEFAULT current_timestamp(),
  `credit` decimal(15,5) NOT NULL,
  `description` mediumtext CHARACTER SET utf8 COLLATE utf8_bin DEFAULT NULL,
  `refill_type` tinyint(4) NOT NULL DEFAULT 0,
  `payment` tinyint(1) DEFAULT 0,
  `invoice_number` varchar(50) NOT NULL DEFAULT '',
  PRIMARY KEY (`id`),
  KEY `fk_pkg_user_pkg_logrefill` (`id_user`),
  CONSTRAINT `fk_pkg_user_pkg_logrefill` FOREIGN KEY (`id_user`) REFERENCES `pkg_user` (`id`) ON DELETE CASCADE
) ENGINE=InnoDB DEFAULT CHARSET=utf8;

--
-- Table structure for table `pkg_refill_icepay`
--

CREATE TABLE `pkg_refill_icepay` (
  `id` int(11) NOT NULL AUTO_INCREMENT,
  `id_user` int(11) NOT NULL,
  `date` timestamp NOT NULL DEFAULT current_timestamp(),
  `credit` decimal(15,5) NOT NULL,
  `description` mediumtext CHARACTER SET utf8 COLLATE utf8_bin DEFAULT NULL,
  PRIMARY KEY (`id`)
) ENGINE=InnoDB DEFAULT CHARSET=utf8;

--
-- Table structure for table `pkg_refill_provider`
--

CREATE TABLE `pkg_refill_provider` (
  `id` int(11) NOT NULL AUTO_INCREMENT,
  `id_provider` int(11) NOT NULL,
  `date` timestamp NOT NULL DEFAULT current_timestamp(),
  `credit` decimal(15,5) NOT NULL,
  `description` mediumtext CHARACTER SET utf8 COLLATE utf8_bin DEFAULT NULL,
  `payment` tinyint(1) NOT NULL DEFAULT 0,
  PRIMARY KEY (`id`),
  KEY `fk_pkg_provider_pkg_logrefill_provider` (`id_provider`),
  CONSTRAINT `fk_pkg_provider_pkg_logrefill_provider` FOREIGN KEY (`id_provider`) REFERENCES `pkg_provider` (`id`)
) ENGINE=InnoDB DEFAULT CHARSET=utf8;

--
-- Table structure for table `pkg_restrict_phone`
--

CREATE TABLE `pkg_restrict_phone` (
  `id` int(11) NOT NULL AUTO_INCREMENT,
  `id_user` int(11) NOT NULL,
  `number` bigint(20) NOT NULL,
  `direction` int(11) NOT NULL DEFAULT 1,
  PRIMARY KEY (`id`),
  KEY `fk_pkg_user_pkg_restricted_phonenumber` (`id_user`),
  KEY `number` (`number`),
  CONSTRAINT `fk_pkg_user_pkg_restricted_phonenumber` FOREIGN KEY (`id_user`) REFERENCES `pkg_user` (`id`) ON DELETE CASCADE
) ENGINE=InnoDB DEFAULT CHARSET=utf8;

--
-- Table structure for table `pkg_send_credit`
--

CREATE TABLE `pkg_send_credit` (
  `id` int(11) NOT NULL AUTO_INCREMENT,
  `id_user` int(11) NOT NULL,
  `date` timestamp NULL DEFAULT current_timestamp(),
  `service` varchar(50) NOT NULL,
  `number` varchar(30) NOT NULL,
  `profit` varchar(10) DEFAULT '0',
  `earned` varchar(20) DEFAULT NULL,
  `amount` varchar(10) DEFAULT NULL,
  `total_sale` int(11) DEFAULT NULL,
  `count` int(11) DEFAULT NULL,
  `confirmed` tinyint(1) NOT NULL DEFAULT 0,
  PRIMARY KEY (`id`)
) ENGINE=InnoDB AUTO_INCREMENT=15255 DEFAULT CHARSET=utf8;

--
-- Table structure for table `pkg_services`
--

CREATE TABLE `pkg_services` (
  `id` int(11) NOT NULL AUTO_INCREMENT,
  `name` varchar(100) NOT NULL,
  `type` varchar(50) NOT NULL,
  `status` tinyint(1) NOT NULL DEFAULT 1,
  `price` decimal(15,4) NOT NULL DEFAULT 0.0000,
  `description` text DEFAULT NULL,
  `disk_space` int(11) DEFAULT NULL,
  `sipaccountlimit` int(11) DEFAULT NULL,
  `calllimit` int(11) DEFAULT NULL,
  `return_credit` tinyint(1) NOT NULL DEFAULT 1,
  PRIMARY KEY (`id`)
) ENGINE=InnoDB DEFAULT CHARSET=utf8;

--
-- Table structure for table `pkg_services_module`
--

CREATE TABLE `pkg_services_module` (
  `id_services` int(11) NOT NULL,
  `id_module` int(11) NOT NULL,
  `action` varchar(45) NOT NULL,
  `show_menu` tinyint(1) NOT NULL DEFAULT 1,
  `createShortCut` tinyint(1) NOT NULL DEFAULT 0,
  `createQuickStart` tinyint(1) NOT NULL DEFAULT 0,
  PRIMARY KEY (`id_services`,`id_module`),
  KEY `fk_pkg_services_module_pkg_module` (`id_module`),
  CONSTRAINT `fk_pkg_services_module_pkg_module` FOREIGN KEY (`id_module`) REFERENCES `pkg_module` (`id`),
  CONSTRAINT `fk_pkg_services_pkg_services_module` FOREIGN KEY (`id_services`) REFERENCES `pkg_services` (`id`)
) ENGINE=InnoDB DEFAULT CHARSET=utf8;

--
-- Table structure for table `pkg_services_plan`
--

CREATE TABLE `pkg_services_plan` (
  `id_services` int(11) NOT NULL,
  `id_plan` int(11) NOT NULL,
  PRIMARY KEY (`id_services`,`id_plan`),
  KEY `fk_pkg_services_pkg_services_plan` (`id_services`),
  KEY `fk_pkg_plan_pkg_services_plan` (`id_plan`),
  CONSTRAINT `fk_pkg_plan_pkg_services_plan` FOREIGN KEY (`id_plan`) REFERENCES `pkg_plan` (`id`) ON DELETE CASCADE,
  CONSTRAINT `fk_pkg_services_pkg_services_plan` FOREIGN KEY (`id_services`) REFERENCES `pkg_services` (`id`) ON DELETE CASCADE
) ENGINE=InnoDB DEFAULT CHARSET=utf8;

--
-- Table structure for table `pkg_services_use`
--

CREATE TABLE `pkg_services_use` (
  `id` int(11) NOT NULL AUTO_INCREMENT,
  `id_user` int(11) DEFAULT NULL,
  `id_services` int(11) NOT NULL,
  `reservationdate` timestamp NOT NULL DEFAULT current_timestamp(),
  `releasedate` timestamp NOT NULL DEFAULT '0000-00-00 00:00:00',
  `status` int(11) DEFAULT 0,
  `month_payed` int(11) DEFAULT 0,
  `reminded` tinyint(4) NOT NULL DEFAULT 0,
  `id_method` int(11) DEFAULT NULL,
  PRIMARY KEY (`id`),
  KEY `fk_pkg_user_pkg_services_use` (`id_user`),
  KEY `fk_pkg_services_pkg_services_use` (`id_services`),
  CONSTRAINT `fk_pkg_services_pkg_services_use` FOREIGN KEY (`id_services`) REFERENCES `pkg_services` (`id`),
  CONSTRAINT `fk_pkg_user_pkg_services_use` FOREIGN KEY (`id_user`) REFERENCES `pkg_user` (`id`)
) ENGINE=InnoDB DEFAULT CHARSET=utf8;

--
-- Table structure for table `pkg_sms`
--

CREATE TABLE `pkg_sms` (
  `id` int(11) NOT NULL AUTO_INCREMENT,
  `id_user` int(11) NOT NULL,
  `prefix` int(11) NOT NULL DEFAULT 0,
  `date` timestamp NOT NULL DEFAULT current_timestamp() ON UPDATE current_timestamp(),
  `telephone` varchar(50) NOT NULL DEFAULT '',
  `sms` mediumtext NOT NULL,
  `result` varchar(50) NOT NULL DEFAULT '',
  `rate` decimal(15,5) NOT NULL DEFAULT 0.00000,
  `sms_from` varchar(16) DEFAULT NULL,
  PRIMARY KEY (`id`),
  KEY `fk_pkg_user_pkg_sms` (`id_user`),
  KEY `prefix` (`prefix`),
  KEY `date` (`date`),
  CONSTRAINT `fk_pkg_user_pkg_sms` FOREIGN KEY (`id_user`) REFERENCES `pkg_user` (`id`) ON DELETE CASCADE
) ENGINE=InnoDB DEFAULT CHARSET=utf8;

--
-- Table structure for table `pkg_status_system`
--

CREATE TABLE `pkg_status_system` (
  `id` int(11) NOT NULL AUTO_INCREMENT,
  `date` timestamp NOT NULL DEFAULT current_timestamp(),
  `cpuMediaUso` float NOT NULL DEFAULT 0,
  `cpuPercent` float NOT NULL DEFAULT 0,
  `memTotal` int(11) DEFAULT NULL,
  `memUsed` float NOT NULL DEFAULT 0,
  `networkin` float NOT NULL DEFAULT 0,
  `networkout` float NOT NULL DEFAULT 0,
  `cpuModel` varchar(200) DEFAULT NULL,
  `uptime` varchar(200) DEFAULT NULL,
  `cps` int(11) NOT NULL DEFAULT 0,
  PRIMARY KEY (`id`),
  UNIQUE KEY `date` (`date`)
) ENGINE=InnoDB AUTO_INCREMENT=1443421 DEFAULT CHARSET=utf8;

--
-- Table structure for table `pkg_tables_changes`
--

CREATE TABLE `pkg_tables_changes` (
  `id` int(11) NOT NULL AUTO_INCREMENT,
  `module` varchar(300) NOT NULL,
  `last_time` varchar(18) NOT NULL,
  PRIMARY KEY (`id`)
) ENGINE=InnoDB AUTO_INCREMENT=4 DEFAULT CHARSET=utf8;

--
-- Table structure for table `pkg_templatemail`
--

CREATE TABLE `pkg_templatemail` (
  `id` int(11) NOT NULL AUTO_INCREMENT,
  `id_user` int(11) NOT NULL,
  `mailtype` char(50) CHARACTER SET utf8 COLLATE utf8_bin DEFAULT NULL,
  `fromemail` char(70) CHARACTER SET utf8 COLLATE utf8_bin DEFAULT NULL,
  `fromname` char(70) CHARACTER SET utf8 COLLATE utf8_bin DEFAULT NULL,
  `subject` varchar(130) CHARACTER SET utf8 COLLATE utf8_bin DEFAULT NULL,
  `messagehtml` varchar(3000) CHARACTER SET utf8 COLLATE utf8_bin DEFAULT NULL,
  `language` varchar(5) DEFAULT 'br',
  `status` int(11) NOT NULL DEFAULT 1,
  PRIMARY KEY (`id`)
) ENGINE=InnoDB AUTO_INCREMENT=75 DEFAULT CHARSET=utf8;

--
-- Table structure for table `pkg_trunk_error`
--

CREATE TABLE `pkg_trunk_error` (
  `id` int(11) NOT NULL AUTO_INCREMENT,
  `ip` varchar(100) NOT NULL,
  `code` int(5) NOT NULL,
  `total` int(11) NOT NULL,
  PRIMARY KEY (`id`),
  UNIQUE KEY `unique_index` (`ip`,`code`)
) ENGINE=InnoDB DEFAULT CHARSET=utf8;

--
-- Table structure for table `pkg_trunk_group`
--

CREATE TABLE `pkg_trunk_group` (
  `id` int(11) NOT NULL AUTO_INCREMENT,
  `name` varchar(100) NOT NULL,
  `type` int(11) NOT NULL DEFAULT 1,
  `description` text DEFAULT NULL,
  PRIMARY KEY (`id`),
  UNIQUE KEY `name` (`name`)
) ENGINE=InnoDB AUTO_INCREMENT=2 DEFAULT CHARSET=utf8;

--
-- Table structure for table `pkg_trunk_group_trunk`
--

CREATE TABLE `pkg_trunk_group_trunk` (
  `id` int(11) NOT NULL AUTO_INCREMENT,
  `id_trunk_group` int(11) NOT NULL,
  `id_trunk` int(11) NOT NULL,
  PRIMARY KEY (`id`),
  KEY `id_trunk_group` (`id_trunk_group`),
  KEY `id_trunk` (`id_trunk`),
  CONSTRAINT `fk_pkg_trunk_group_trunk_pkg_trunk` FOREIGN KEY (`id_trunk`) REFERENCES `pkg_trunk` (`id`) ON DELETE CASCADE,
  CONSTRAINT `fk_pkg_trunk_group_trunk_pkg_trunk_group` FOREIGN KEY (`id_trunk_group`) REFERENCES `pkg_trunk_group` (`id`) ON DELETE CASCADE
) ENGINE=InnoDB AUTO_INCREMENT=2 DEFAULT CHARSET=utf8;

--
-- Table structure for table `pkg_user_rate`
--

CREATE TABLE `pkg_user_rate` (
  `id` int(11) NOT NULL AUTO_INCREMENT,
  `id_user` int(11) NOT NULL,
  `id_prefix` int(11) NOT NULL,
  `rateinitial` decimal(15,5) NOT NULL DEFAULT 0.00000,
  `initblock` int(11) NOT NULL DEFAULT 0,
  `billingblock` int(11) NOT NULL DEFAULT 0,
  PRIMARY KEY (`id`),
  KEY `fk_pkg_user_pkg_user_rate` (`id_user`),
  KEY `fk_pkg_prefix_pkg_user_rate` (`id_prefix`),
  CONSTRAINT `fk_pkg_prefix_pkg_user_rate` FOREIGN KEY (`id_prefix`) REFERENCES `pkg_prefix` (`id`),
  CONSTRAINT `fk_pkg_user_pkg_user_rate` FOREIGN KEY (`id_user`) REFERENCES `pkg_user` (`id`) ON DELETE CASCADE
) ENGINE=InnoDB DEFAULT CHARSET=utf8;

--
-- Table structure for table `pkg_user_type`
--

CREATE TABLE `pkg_user_type` (
  `id` int(11) NOT NULL AUTO_INCREMENT,
  `name` varchar(18) NOT NULL,
  PRIMARY KEY (`id`),
  UNIQUE KEY `id` (`id`)
) ENGINE=InnoDB AUTO_INCREMENT=4 DEFAULT CHARSET=utf8;
/*!50001 DROP VIEW IF EXISTS `pkg_voicemail_users`*/;

--
-- Table structure for table `pkg_voucher`
--

CREATE TABLE `pkg_voucher` (
  `id` int(11) NOT NULL AUTO_INCREMENT,
  `id_user` int(11) DEFAULT NULL,
  `id_plan` int(11) DEFAULT NULL,
  `creationdate` timestamp NOT NULL DEFAULT current_timestamp(),
  `usedate` timestamp NOT NULL DEFAULT '0000-00-00 00:00:00',
  `expirationdate` timestamp NOT NULL DEFAULT '0000-00-00 00:00:00',
  `voucher` int(6) NOT NULL,
  `tag` char(50) CHARACTER SET utf8 COLLATE utf8_bin DEFAULT NULL,
  `credit` float NOT NULL DEFAULT 0,
  `used` int(11) DEFAULT 0,
  `prefix_local` varchar(50) DEFAULT NULL,
  `language` char(5) NOT NULL DEFAULT 'en',
  PRIMARY KEY (`id`),
  UNIQUE KEY `cons_pkg_voucher_voucher` (`voucher`),
  KEY `fk_pkg_user_pkg_voucher` (`id_user`),
  CONSTRAINT `fk_pkg_user_pkg_voucher` FOREIGN KEY (`id_user`) REFERENCES `pkg_user` (`id`) ON DELETE CASCADE
) ENGINE=InnoDB DEFAULT CHARSET=utf8;
/*!50001 DROP VIEW IF EXISTS `pkg_voicemail_users`*/;


