-- MySQL dump 10.16  Distrib 10.1.48-MariaDB, for Linux (x86_64)
--
-- Host: localhost    Database: dsadeveloper_youattend
-- ------------------------------------------------------
-- Server version	10.1.48-MariaDB

/*!40101 SET @OLD_CHARACTER_SET_CLIENT=@@CHARACTER_SET_CLIENT */;
/*!40101 SET @OLD_CHARACTER_SET_RESULTS=@@CHARACTER_SET_RESULTS */;
/*!40101 SET @OLD_COLLATION_CONNECTION=@@COLLATION_CONNECTION */;
/*!40101 SET NAMES utf8mb4 */;
/*!40103 SET @OLD_TIME_ZONE=@@TIME_ZONE */;
/*!40103 SET TIME_ZONE='+00:00' */;
/*!40014 SET @OLD_UNIQUE_CHECKS=@@UNIQUE_CHECKS, UNIQUE_CHECKS=0 */;
/*!40014 SET @OLD_FOREIGN_KEY_CHECKS=@@FOREIGN_KEY_CHECKS, FOREIGN_KEY_CHECKS=0 */;
/*!40101 SET @OLD_SQL_MODE=@@SQL_MODE, SQL_MODE='NO_AUTO_VALUE_ON_ZERO' */;
/*!40111 SET @OLD_SQL_NOTES=@@SQL_NOTES, SQL_NOTES=0 */;

--
-- Table structure for table `account_access_rights`
--

DROP TABLE IF EXISTS `account_access_rights`;
/*!40101 SET @saved_cs_client     = @@character_set_client */;
/*!40101 SET character_set_client = utf8 */;
CREATE TABLE `account_access_rights` (
  `ACC_ACCESS_ID` bigint(20) NOT NULL AUTO_INCREMENT,
  `ACC_ACCESS_SERVER_ID` bigint(20) NOT NULL,
  `ACC_ACCESS_ACC_LEVEL_ID` bigint(20) NOT NULL,
  `ACC_ACCESS_SYS_MODULE_ID` bigint(20) NOT NULL,
  `ACC_ACCESS_SYS_AUTHORITY_ID` bigint(20) NOT NULL,
  `ACC_ACCESS_AUTHORITY_POINT` bigint(20) NOT NULL,
  PRIMARY KEY (`ACC_ACCESS_ID`)
) ENGINE=InnoDB AUTO_INCREMENT=502 DEFAULT CHARSET=latin1;
/*!40101 SET character_set_client = @saved_cs_client */;

--
-- Dumping data for table `account_access_rights`
--

LOCK TABLES `account_access_rights` WRITE;
/*!40000 ALTER TABLE `account_access_rights` DISABLE KEYS */;
INSERT INTO `account_access_rights` (`ACC_ACCESS_ID`, `ACC_ACCESS_SERVER_ID`, `ACC_ACCESS_ACC_LEVEL_ID`, `ACC_ACCESS_SYS_MODULE_ID`, `ACC_ACCESS_SYS_AUTHORITY_ID`, `ACC_ACCESS_AUTHORITY_POINT`) VALUES (1,0,2,10040,5,999999),(2,0,2,10060,5,999999),(3,0,2,10080,5,999999),(4,0,2,10140,5,999999),(5,0,2,11010,5,999999),(6,0,2,11020,5,999999),(7,0,2,11030,5,999999),(8,0,2,11040,5,999999),(9,0,2,20010,5,999999),(10,0,2,20020,5,999999),(11,0,2,20030,5,999999),(25,0,2,21190,5,999999),(38,0,2,30010,5,999999),(39,0,2,30020,5,999999),(40,0,2,30030,5,999999),(41,0,2,30040,5,999999),(42,0,2,30050,5,999999),(43,0,2,30060,5,999999),(44,0,2,30070,5,999999),(45,0,2,30080,5,999999),(46,0,2,30090,5,999999),(82,0,2,20040,5,999999),(83,0,2,20050,5,999999),(84,0,2,20060,5,999999),(85,0,2,20070,5,999999),(86,0,2,40010,5,999999),(87,0,2,40020,5,999999),(88,0,2,40030,5,999999),(89,0,2,40040,5,999999),(90,0,2,40050,5,999999),(91,0,2,40060,5,999999),(92,0,2,40070,5,999999),(113,0,2,20080,5,999999),(114,0,2,20090,5,999999),(115,0,2,20100,5,999999),(116,0,2,20110,5,999999),(144,0,2,10100,5,999999),(145,0,2,40080,5,999999),(146,0,2,20120,5,999999),(147,0,2,20130,5,999999),(148,0,2,40090,5,999999),(149,0,2,60010,5,999999),(150,0,2,60020,5,999999),(151,0,2,60030,5,999999),(152,0,2,60040,5,999999),(153,0,2,60050,5,999999),(154,0,2,60060,5,999999),(283,0,2,21010,5,999999),(284,0,2,21100,5,999999),(285,0,2,31010,5,999999),(286,0,2,31020,5,999999),(287,0,2,31030,5,999999),(294,0,1,10040,0,0),(295,0,1,10060,0,0),(296,0,1,10080,0,0),(297,0,1,10100,0,0),(298,0,1,10140,0,0),(299,0,1,21010,0,0),(300,0,1,21100,0,0),(301,0,1,31010,0,0),(302,0,1,31020,0,0),(303,0,1,31030,0,0),(304,0,3,10040,0,0),(305,0,3,10060,0,0),(306,0,3,10080,0,0),(307,0,3,10100,0,0),(308,0,3,10140,0,0),(309,0,3,21010,0,0),(310,0,3,21100,0,0),(311,0,3,31010,4,0),(312,0,3,31020,4,0),(313,0,3,31030,4,0),(314,0,3,31040,4,0),(315,0,2,10070,5,999999),(316,0,2,31040,5,999999),(317,0,2,31050,5,999999),(344,0,3,31050,4,0),(345,0,2,31025,5,999999),(346,0,3,10070,0,0),(347,0,3,31025,4,0),(348,0,2,31060,5,999999),(456,0,0,60010,4,0),(457,0,2,60010,5,999999),(458,0,2,31070,5,999999),(459,0,2,10120,5,999999),(460,0,2,10160,5,999999),(461,0,2,10180,5,999999),(462,0,2,15010,5,999999),(463,0,2,15030,5,999999),(464,0,2,15050,5,999999),(465,0,2,15070,5,999999),(466,0,2,21030,5,999999),(467,0,2,21050,5,999999),(468,0,4,10040,0,0),(469,0,4,10060,0,0),(470,0,4,10070,0,0),(471,0,4,10080,0,0),(472,0,4,10100,0,0),(473,0,4,10120,0,0),(474,0,4,10140,0,0),(475,0,4,10160,0,0),(476,0,4,10180,0,0),(477,0,4,15010,0,0),(478,0,4,15030,0,0),(479,0,4,15050,0,0),(480,0,4,15070,0,0),(481,0,4,20010,0,0),(482,0,4,20030,0,0),(483,0,4,20050,0,0),(484,0,4,20070,0,0),(485,0,4,20090,0,0),(486,0,4,20110,0,0),(487,0,4,21010,0,0),(488,0,4,21030,0,0),(489,0,4,21050,0,0),(490,0,4,31010,0,0),(491,0,4,31020,0,0),(492,0,4,31025,0,0),(493,0,4,31030,0,0),(494,0,4,31040,0,0),(495,0,4,31050,0,0),(496,0,4,31060,0,0),(497,0,4,31070,0,0),(498,0,4,40010,0,0),(499,0,4,40050,0,0),(500,0,4,40070,0,0),(501,0,4,40090,0,0);
/*!40000 ALTER TABLE `account_access_rights` ENABLE KEYS */;
UNLOCK TABLES;

--
-- Table structure for table `account_audit_trail`
--

DROP TABLE IF EXISTS `account_audit_trail`;
/*!40101 SET @saved_cs_client     = @@character_set_client */;
/*!40101 SET character_set_client = utf8 */;
CREATE TABLE `account_audit_trail` (
  `ACC_TRAIL_ID` bigint(20) NOT NULL AUTO_INCREMENT,
  `ACC_TRAIL_REQUEST_IP_ADDRESS` varchar(500) CHARACTER SET utf8 COLLATE utf8_unicode_ci NOT NULL,
  `ACC_TRAIL_SYS_METHOD_ID` bigint(20) NOT NULL,
  `ACC_TRAIL_ACC_DEVICE_ID` bigint(20) NOT NULL,
  `ACC_TRAIL_ACC_ACCOUNT_ID` bigint(20) NOT NULL,
  `ACC_TRAIL_PROXY_USER` bigint(20) NOT NULL,
  `ACC_TRAIL_ACC_SERVER_ID` bigint(20) NOT NULL,
  `ACC_TRAIL_SYS_MODULE_ID` bigint(20) NOT NULL,
  `ACC_TRAIL_TARGET_ID` bigint(20) NOT NULL,
  `ACC_TRAIL_TARGET_SERVER_ID` bigint(20) NOT NULL,
  `ACC_TRAIL_DESCRIPTION` varchar(500) CHARACTER SET utf8 COLLATE utf8_unicode_ci NOT NULL,
  `ACC_TRAIL_PARAMETERS` varchar(10000) CHARACTER SET utf8 COLLATE utf8_unicode_ci NOT NULL,
  `ACC_TRAIL_TIMESTAMP` datetime(6) DEFAULT NULL,
  `ACC_TRAIL_UNIQUE_SESSION_ID` varchar(1000) CHARACTER SET utf8 COLLATE utf8_unicode_ci NOT NULL,
  PRIMARY KEY (`ACC_TRAIL_ID`)
) ENGINE=InnoDB AUTO_INCREMENT=283 DEFAULT CHARSET=latin1;
/*!40101 SET character_set_client = @saved_cs_client */;

--
-- Dumping data for table `account_audit_trail`
--

LOCK TABLES `account_audit_trail` WRITE;
/*!40000 ALTER TABLE `account_audit_trail` DISABLE KEYS */;
INSERT INTO `account_audit_trail` (`ACC_TRAIL_ID`, `ACC_TRAIL_REQUEST_IP_ADDRESS`, `ACC_TRAIL_SYS_METHOD_ID`, `ACC_TRAIL_ACC_DEVICE_ID`, `ACC_TRAIL_ACC_ACCOUNT_ID`, `ACC_TRAIL_PROXY_USER`, `ACC_TRAIL_ACC_SERVER_ID`, `ACC_TRAIL_SYS_MODULE_ID`, `ACC_TRAIL_TARGET_ID`, `ACC_TRAIL_TARGET_SERVER_ID`, `ACC_TRAIL_DESCRIPTION`, `ACC_TRAIL_PARAMETERS`, `ACC_TRAIL_TIMESTAMP`, `ACC_TRAIL_UNIQUE_SESSION_ID`) VALUES (1,'49.146.42.127',1,0,3,0,0,10080,459,0,'add/edit Access rights record','LEVEL: 0 (\"\")  >  2 (\" Super Admin \") | MODULE: 0 (\"\")  >  10120 (\" Devices \") | AUTHORITY:  0 (\"\")  > 0 (\" No Access \")','2021-01-11 15:40:31.270676','Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/87.0.4280.141 Safari/537.36'),(2,'49.146.42.127',1,0,3,0,0,10080,460,0,'add/edit Access rights record','LEVEL: 0 (\"\")  >  2 (\" Super Admin \") | MODULE: 0 (\"\")  >  10120 (\" Devices \") | AUTHORITY:  0 (\"\")  > 0 (\" No Access \") | LEVEL: 0 (\"\")  >  2 (\" Super Admin \") | MODULE: 0 (\"\")  >  10160 (\" Brute Force Login Attempt \") | AUTHORITY:  0 (\"\")  > 0 (\" No Access \")','2021-01-11 15:40:31.277302','Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/87.0.4280.141 Safari/537.36'),(3,'49.146.42.127',1,0,3,0,0,10080,461,0,'add/edit Access rights record','LEVEL: 0 (\"\")  >  2 (\" Super Admin \") | MODULE: 0 (\"\")  >  10120 (\" Devices \") | AUTHORITY:  0 (\"\")  > 0 (\" No Access \") | LEVEL: 0 (\"\")  >  2 (\" Super Admin \") | MODULE: 0 (\"\")  >  10160 (\" Brute Force Login Attempt \") | AUTHORITY:  0 (\"\")  > 0 (\" No Access \") | LEVEL: 0 (\"\")  >  2 (\" Super Admin \") | MODULE: 0 (\"\")  >  10180 (\" Bruteforce IP \") | AUTHORITY:  0 (\"\")  > 0 (\" No Access \")','2021-01-11 15:40:31.282255','Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/87.0.4280.141 Safari/537.36'),(4,'49.146.42.127',1,0,3,0,0,10080,462,0,'add/edit Access rights record','LEVEL: 0 (\"\")  >  2 (\" Super Admin \") | MODULE: 0 (\"\")  >  10120 (\" Devices \") | AUTHORITY:  0 (\"\")  > 0 (\" No Access \") | LEVEL: 0 (\"\")  >  2 (\" Super Admin \") | MODULE: 0 (\"\")  >  10160 (\" Brute Force Login Attempt \") | AUTHORITY:  0 (\"\")  > 0 (\" No Access \") | LEVEL: 0 (\"\")  >  2 (\" Super Admin \") | MODULE: 0 (\"\")  >  10180 (\" Bruteforce IP \") | AUTHORITY:  0 (\"\")  > 0 (\" No Access \") | LEVEL: 0 (\"\")  >  2 (\" Super Admin \") | MODULE: 0 (\"\")  >  15010 (\" Addon: Group License \") | AUTHORITY:  0 (\"\")  > 0 (\" No Access \")','2021-01-11 15:40:31.286701','Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/87.0.4280.141 Safari/537.36'),(5,'49.146.42.127',1,0,3,0,0,10080,463,0,'add/edit Access rights record','LEVEL: 0 (\"\")  >  2 (\" Super Admin \") | MODULE: 0 (\"\")  >  10120 (\" Devices \") | AUTHORITY:  0 (\"\")  > 0 (\" No Access \") | LEVEL: 0 (\"\")  >  2 (\" Super Admin \") | MODULE: 0 (\"\")  >  10160 (\" Brute Force Login Attempt \") | AUTHORITY:  0 (\"\")  > 0 (\" No Access \") | LEVEL: 0 (\"\")  >  2 (\" Super Admin \") | MODULE: 0 (\"\")  >  10180 (\" Bruteforce IP \") | AUTHORITY:  0 (\"\")  > 0 (\" No Access \") | LEVEL: 0 (\"\")  >  2 (\" Super Admin \") | MODULE: 0 (\"\")  >  15010 (\" Addon: Group License \") | AUTHORITY:  0 (\"\")  > 0 (\" No Access \") | LEVEL: 0 (\"\")  >  2 (\" Super Admin \") | MODULE: 0 (\"\")  >  15030 (\" Addon: User License \") | AUTHORITY:  0 (\"\")  > 0 (\" No Access \")','2021-01-11 15:40:31.291263','Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/87.0.4280.141 Safari/537.36'),(6,'49.146.42.127',1,0,3,0,0,10080,464,0,'add/edit Access rights record','LEVEL: 0 (\"\")  >  2 (\" Super Admin \") | MODULE: 0 (\"\")  >  10120 (\" Devices \") | AUTHORITY:  0 (\"\")  > 0 (\" No Access \") | LEVEL: 0 (\"\")  >  2 (\" Super Admin \") | MODULE: 0 (\"\")  >  10160 (\" Brute Force Login Attempt \") | AUTHORITY:  0 (\"\")  > 0 (\" No Access \") | LEVEL: 0 (\"\")  >  2 (\" Super Admin \") | MODULE: 0 (\"\")  >  10180 (\" Bruteforce IP \") | AUTHORITY:  0 (\"\")  > 0 (\" No Access \") | LEVEL: 0 (\"\")  >  2 (\" Super Admin \") | MODULE: 0 (\"\")  >  15010 (\" Addon: Group License \") | AUTHORITY:  0 (\"\")  > 0 (\" No Access \") | LEVEL: 0 (\"\")  >  2 (\" Super Admin \") | MODULE: 0 (\"\")  >  15030 (\" Addon: User License \") | AUTHORITY:  0 (\"\")  > 0 (\" No Access \") | LEVEL: 0 (\"\")  >  2 (\" Super Admin \") | MODULE: 0 (\"\")  >  15050 (\" Addon: Queuing \") | AUTHORITY:  0 (\"\")  > 0 (\" No Access \")','2021-01-11 15:40:31.295146','Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/87.0.4280.141 Safari/537.36'),(7,'49.146.42.127',1,0,3,0,0,10080,465,0,'add/edit Access rights record','LEVEL: 0 (\"\")  >  2 (\" Super Admin \") | MODULE: 0 (\"\")  >  10120 (\" Devices \") | AUTHORITY:  0 (\"\")  > 0 (\" No Access \") | LEVEL: 0 (\"\")  >  2 (\" Super Admin \") | MODULE: 0 (\"\")  >  10160 (\" Brute Force Login Attempt \") | AUTHORITY:  0 (\"\")  > 0 (\" No Access \") | LEVEL: 0 (\"\")  >  2 (\" Super Admin \") | MODULE: 0 (\"\")  >  10180 (\" Bruteforce IP \") | AUTHORITY:  0 (\"\")  > 0 (\" No Access \") | LEVEL: 0 (\"\")  >  2 (\" Super Admin \") | MODULE: 0 (\"\")  >  15010 (\" Addon: Group License \") | AUTHORITY:  0 (\"\")  > 0 (\" No Access \") | LEVEL: 0 (\"\")  >  2 (\" Super Admin \") | MODULE: 0 (\"\")  >  15030 (\" Addon: User License \") | AUTHORITY:  0 (\"\")  > 0 (\" No Access \") | LEVEL: 0 (\"\")  >  2 (\" Super Admin \") | MODULE: 0 (\"\")  >  15050 (\" Addon: Queuing \") | AUTHORITY:  0 (\"\")  > 0 (\" No Access \") | LEVEL: 0 (\"\")  >  2 (\" Super Admin \") | MODULE: 0 (\"\")  >  15070 (\" Addon: Resource \") | AUTHORITY:  0 (\"\")  > 0 (\" No Access \")','2021-01-11 15:40:31.299737','Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/87.0.4280.141 Safari/537.36'),(8,'49.146.42.127',1,0,3,0,0,10080,466,0,'add/edit Access rights record','LEVEL: 0 (\"\")  >  2 (\" Super Admin \") | MODULE: 0 (\"\")  >  10120 (\" Devices \") | AUTHORITY:  0 (\"\")  > 0 (\" No Access \") | LEVEL: 0 (\"\")  >  2 (\" Super Admin \") | MODULE: 0 (\"\")  >  10160 (\" Brute Force Login Attempt \") | AUTHORITY:  0 (\"\")  > 0 (\" No Access \") | LEVEL: 0 (\"\")  >  2 (\" Super Admin \") | MODULE: 0 (\"\")  >  10180 (\" Bruteforce IP \") | AUTHORITY:  0 (\"\")  > 0 (\" No Access \") | LEVEL: 0 (\"\")  >  2 (\" Super Admin \") | MODULE: 0 (\"\")  >  15010 (\" Addon: Group License \") | AUTHORITY:  0 (\"\")  > 0 (\" No Access \") | LEVEL: 0 (\"\")  >  2 (\" Super Admin \") | MODULE: 0 (\"\")  >  15030 (\" Addon: User License \") | AUTHORITY:  0 (\"\")  > 0 (\" No Access \") | LEVEL: 0 (\"\")  >  2 (\" Super Admin \") | MODULE: 0 (\"\")  >  15050 (\" Addon: Queuing \") | AUTHORITY:  0 (\"\")  > 0 (\" No Access \") | LEVEL: 0 (\"\")  >  2 (\" Super Admin \") | MODULE: 0 (\"\")  >  15070 (\" Addon: Resource \") | AUTHORITY:  0 (\"\")  > 0 (\" No Access \") | LEVEL: 0 (\"\")  >  2 (\" Super Admin \") | MODULE: 0 (\"\")  >  21030 (\" Section \") | AUTHORITY:  0 (\"\")  > 0 (\" No Access \")','2021-01-11 15:40:31.307781','Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/87.0.4280.141 Safari/537.36'),(9,'49.146.42.127',1,0,3,0,0,10080,467,0,'add/edit Access rights record','LEVEL: 0 (\"\")  >  2 (\" Super Admin \") | MODULE: 0 (\"\")  >  10120 (\" Devices \") | AUTHORITY:  0 (\"\")  > 0 (\" No Access \") | LEVEL: 0 (\"\")  >  2 (\" Super Admin \") | MODULE: 0 (\"\")  >  10160 (\" Brute Force Login Attempt \") | AUTHORITY:  0 (\"\")  > 0 (\" No Access \") | LEVEL: 0 (\"\")  >  2 (\" Super Admin \") | MODULE: 0 (\"\")  >  10180 (\" Bruteforce IP \") | AUTHORITY:  0 (\"\")  > 0 (\" No Access \") | LEVEL: 0 (\"\")  >  2 (\" Super Admin \") | MODULE: 0 (\"\")  >  15010 (\" Addon: Group License \") | AUTHORITY:  0 (\"\")  > 0 (\" No Access \") | LEVEL: 0 (\"\")  >  2 (\" Super Admin \") | MODULE: 0 (\"\")  >  15030 (\" Addon: User License \") | AUTHORITY:  0 (\"\")  > 0 (\" No Access \") | LEVEL: 0 (\"\")  >  2 (\" Super Admin \") | MODULE: 0 (\"\")  >  15050 (\" Addon: Queuing \") | AUTHORITY:  0 (\"\")  > 0 (\" No Access \") | LEVEL: 0 (\"\")  >  2 (\" Super Admin \") | MODULE: 0 (\"\")  >  15070 (\" Addon: Resource \") | AUTHORITY:  0 (\"\")  > 0 (\" No Access \") | LEVEL: 0 (\"\")  >  2 (\" Super Admin \") | MODULE: 0 (\"\")  >  21030 (\" Section \") | AUTHORITY:  0 (\"\")  > 0 (\" No Access \") | LEVEL: 0 (\"\")  >  2 (\" Super Admin \") | MODULE: 0 (\"\")  >  21050 (\" Entrance \") | AUTHORITY:  0 (\"\")  > 0 (\" No Access \")','2021-01-11 15:40:31.311881','Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/87.0.4280.141 Safari/537.36'),(10,'49.146.42.127',1,0,3,0,0,10080,1,0,'add/edit Access rights record','LEVEL: 0 (\"\")  >  2 (\" Super Admin \") | MODULE: 0 (\"\")  >  10120 (\" Devices \") | AUTHORITY:  0 (\"\")  > 0 (\" No Access \") | LEVEL: 0 (\"\")  >  2 (\" Super Admin \") | MODULE: 0 (\"\")  >  10160 (\" Brute Force Login Attempt \") | AUTHORITY:  0 (\"\")  > 0 (\" No Access \") | LEVEL: 0 (\"\")  >  2 (\" Super Admin \") | MODULE: 0 (\"\")  >  10180 (\" Bruteforce IP \") | AUTHORITY:  0 (\"\")  > 0 (\" No Access \") | LEVEL: 0 (\"\")  >  2 (\" Super Admin \") | MODULE: 0 (\"\")  >  15010 (\" Addon: Group License \") | AUTHORITY:  0 (\"\")  > 0 (\" No Access \") | LEVEL: 0 (\"\")  >  2 (\" Super Admin \") | MODULE: 0 (\"\")  >  15030 (\" Addon: User License \") | AUTHORITY:  0 (\"\")  > 0 (\" No Access \") | LEVEL: 0 (\"\")  >  2 (\" Super Admin \") | MODULE: 0 (\"\")  >  15050 (\" Addon: Queuing \") | AUTHORITY:  0 (\"\")  > 0 (\" No Access \") | LEVEL: 0 (\"\")  >  2 (\" Super Admin \") | MODULE: 0 (\"\")  >  15070 (\" Addon: Resource \") | AUTHORITY:  0 (\"\")  > 0 (\" No Access \") | LEVEL: 0 (\"\")  >  2 (\" Super Admin \") | MODULE: 0 (\"\")  >  21030 (\" Section \") | AUTHORITY:  0 (\"\")  > 0 (\" No Access \") | LEVEL: 0 (\"\")  >  2 (\" Super Admin \") | MODULE: 0 (\"\")  >  21050 (\" Entrance \") | AUTHORITY:  0 (\"\")  > 0 (\" No Access \") | AUTHORITY:  0 (\"\")  > 4 (\" View/Edit/Delete \")','2021-01-11 15:40:31.319240','Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/87.0.4280.141 Safari/537.36'),(11,'49.146.42.127',1,0,3,0,0,10080,2,0,'add/edit Access rights record','LEVEL: 0 (\"\")  >  2 (\" Super Admin \") | MODULE: 0 (\"\")  >  10120 (\" Devices \") | AUTHORITY:  0 (\"\")  > 0 (\" No Access \") | LEVEL: 0 (\"\")  >  2 (\" Super Admin \") | MODULE: 0 (\"\")  >  10160 (\" Brute Force Login Attempt \") | AUTHORITY:  0 (\"\")  > 0 (\" No Access \") | LEVEL: 0 (\"\")  >  2 (\" Super Admin \") | MODULE: 0 (\"\")  >  10180 (\" Bruteforce IP \") | AUTHORITY:  0 (\"\")  > 0 (\" No Access \") | LEVEL: 0 (\"\")  >  2 (\" Super Admin \") | MODULE: 0 (\"\")  >  15010 (\" Addon: Group License \") | AUTHORITY:  0 (\"\")  > 0 (\" No Access \") | LEVEL: 0 (\"\")  >  2 (\" Super Admin \") | MODULE: 0 (\"\")  >  15030 (\" Addon: User License \") | AUTHORITY:  0 (\"\")  > 0 (\" No Access \") | LEVEL: 0 (\"\")  >  2 (\" Super Admin \") | MODULE: 0 (\"\")  >  15050 (\" Addon: Queuing \") | AUTHORITY:  0 (\"\")  > 0 (\" No Access \") | LEVEL: 0 (\"\")  >  2 (\" Super Admin \") | MODULE: 0 (\"\")  >  15070 (\" Addon: Resource \") | AUTHORITY:  0 (\"\")  > 0 (\" No Access \") | LEVEL: 0 (\"\")  >  2 (\" Super Admin \") | MODULE: 0 (\"\")  >  21030 (\" Section \") | AUTHORITY:  0 (\"\")  > 0 (\" No Access \") | LEVEL: 0 (\"\")  >  2 (\" Super Admin \") | MODULE: 0 (\"\")  >  21050 (\" Entrance \") | AUTHORITY:  0 (\"\")  > 0 (\" No Access \") | AUTHORITY:  0 (\"\")  > 4 (\" View/Edit/Delete \") | AUTHORITY:  0 (\"\")  > 4 (\" View/Edit/Delete \")','2021-01-11 15:40:31.322945','Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/87.0.4280.141 Safari/537.36'),(12,'49.146.42.127',1,0,3,0,0,10080,3,0,'add/edit Access rights record','LEVEL: 0 (\"\")  >  2 (\" Super Admin \") | MODULE: 0 (\"\")  >  10120 (\" Devices \") | AUTHORITY:  0 (\"\")  > 0 (\" No Access \") | LEVEL: 0 (\"\")  >  2 (\" Super Admin \") | MODULE: 0 (\"\")  >  10160 (\" Brute Force Login Attempt \") | AUTHORITY:  0 (\"\")  > 0 (\" No Access \") | LEVEL: 0 (\"\")  >  2 (\" Super Admin \") | MODULE: 0 (\"\")  >  10180 (\" Bruteforce IP \") | AUTHORITY:  0 (\"\")  > 0 (\" No Access \") | LEVEL: 0 (\"\")  >  2 (\" Super Admin \") | MODULE: 0 (\"\")  >  15010 (\" Addon: Group License \") | AUTHORITY:  0 (\"\")  > 0 (\" No Access \") | LEVEL: 0 (\"\")  >  2 (\" Super Admin \") | MODULE: 0 (\"\")  >  15030 (\" Addon: User License \") | AUTHORITY:  0 (\"\")  > 0 (\" No Access \") | LEVEL: 0 (\"\")  >  2 (\" Super Admin \") | MODULE: 0 (\"\")  >  15050 (\" Addon: Queuing \") | AUTHORITY:  0 (\"\")  > 0 (\" No Access \") | LEVEL: 0 (\"\")  >  2 (\" Super Admin \") | MODULE: 0 (\"\")  >  15070 (\" Addon: Resource \") | AUTHORITY:  0 (\"\")  > 0 (\" No Access \") | LEVEL: 0 (\"\")  >  2 (\" Super Admin \") | MODULE: 0 (\"\")  >  21030 (\" Section \") | AUTHORITY:  0 (\"\")  > 0 (\" No Access \") | LEVEL: 0 (\"\")  >  2 (\" Super Admin \") | MODULE: 0 (\"\")  >  21050 (\" Entrance \") | AUTHORITY:  0 (\"\")  > 0 (\" No Access \") | AUTHORITY:  0 (\"\")  > 4 (\" View/Edit/Delete \") | AUTHORITY:  0 (\"\")  > 4 (\" View/Edit/Delete \") | AUTHORITY:  0 (\"\")  > 4 (\" View/Edit/Delete \")','2021-01-11 15:40:31.327189','Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/87.0.4280.141 Safari/537.36'),(13,'49.146.42.127',1,0,3,0,0,10080,4,0,'add/edit Access rights record','LEVEL: 0 (\"\")  >  2 (\" Super Admin \") | MODULE: 0 (\"\")  >  10120 (\" Devices \") | AUTHORITY:  0 (\"\")  > 0 (\" No Access \") | LEVEL: 0 (\"\")  >  2 (\" Super Admin \") | MODULE: 0 (\"\")  >  10160 (\" Brute Force Login Attempt \") | AUTHORITY:  0 (\"\")  > 0 (\" No Access \") | LEVEL: 0 (\"\")  >  2 (\" Super Admin \") | MODULE: 0 (\"\")  >  10180 (\" Bruteforce IP \") | AUTHORITY:  0 (\"\")  > 0 (\" No Access \") | LEVEL: 0 (\"\")  >  2 (\" Super Admin \") | MODULE: 0 (\"\")  >  15010 (\" Addon: Group License \") | AUTHORITY:  0 (\"\")  > 0 (\" No Access \") | LEVEL: 0 (\"\")  >  2 (\" Super Admin \") | MODULE: 0 (\"\")  >  15030 (\" Addon: User License \") | AUTHORITY:  0 (\"\")  > 0 (\" No Access \") | LEVEL: 0 (\"\")  >  2 (\" Super Admin \") | MODULE: 0 (\"\")  >  15050 (\" Addon: Queuing \") | AUTHORITY:  0 (\"\")  > 0 (\" No Access \") | LEVEL: 0 (\"\")  >  2 (\" Super Admin \") | MODULE: 0 (\"\")  >  15070 (\" Addon: Resource \") | AUTHORITY:  0 (\"\")  > 0 (\" No Access \") | LEVEL: 0 (\"\")  >  2 (\" Super Admin \") | MODULE: 0 (\"\")  >  21030 (\" Section \") | AUTHORITY:  0 (\"\")  > 0 (\" No Access \") | LEVEL: 0 (\"\")  >  2 (\" Super Admin \") | MODULE: 0 (\"\")  >  21050 (\" Entrance \") | AUTHORITY:  0 (\"\")  > 0 (\" No Access \") | AUTHORITY:  0 (\"\")  > 4 (\" View/Edit/Delete \") | AUTHORITY:  0 (\"\")  > 4 (\" View/Edit/Delete \") | AUTHORITY:  0 (\"\")  > 4 (\" View/Edit/Delete \") | AUTHORITY:  0 (\"\")  > 4 (\" View/Edit/Delete \")','2021-01-11 15:40:31.331701','Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/87.0.4280.141 Safari/537.36'),(14,'49.146.42.127',1,0,3,0,0,10080,5,0,'add/edit Access rights record','LEVEL: 0 (\"\")  >  2 (\" Super Admin \") | MODULE: 0 (\"\")  >  10120 (\" Devices \") | AUTHORITY:  0 (\"\")  > 0 (\" No Access \") | LEVEL: 0 (\"\")  >  2 (\" Super Admin \") | MODULE: 0 (\"\")  >  10160 (\" Brute Force Login Attempt \") | AUTHORITY:  0 (\"\")  > 0 (\" No Access \") | LEVEL: 0 (\"\")  >  2 (\" Super Admin \") | MODULE: 0 (\"\")  >  10180 (\" Bruteforce IP \") | AUTHORITY:  0 (\"\")  > 0 (\" No Access \") | LEVEL: 0 (\"\")  >  2 (\" Super Admin \") | MODULE: 0 (\"\")  >  15010 (\" Addon: Group License \") | AUTHORITY:  0 (\"\")  > 0 (\" No Access \") | LEVEL: 0 (\"\")  >  2 (\" Super Admin \") | MODULE: 0 (\"\")  >  15030 (\" Addon: User License \") | AUTHORITY:  0 (\"\")  > 0 (\" No Access \") | LEVEL: 0 (\"\")  >  2 (\" Super Admin \") | MODULE: 0 (\"\")  >  15050 (\" Addon: Queuing \") | AUTHORITY:  0 (\"\")  > 0 (\" No Access \") | LEVEL: 0 (\"\")  >  2 (\" Super Admin \") | MODULE: 0 (\"\")  >  15070 (\" Addon: Resource \") | AUTHORITY:  0 (\"\")  > 0 (\" No Access \") | LEVEL: 0 (\"\")  >  2 (\" Super Admin \") | MODULE: 0 (\"\")  >  21030 (\" Section \") | AUTHORITY:  0 (\"\")  > 0 (\" No Access \") | LEVEL: 0 (\"\")  >  2 (\" Super Admin \") | MODULE: 0 (\"\")  >  21050 (\" Entrance \") | AUTHORITY:  0 (\"\")  > 0 (\" No Access \") | AUTHORITY:  0 (\"\")  > 4 (\" View/Edit/Delete \") | AUTHORITY:  0 (\"\")  > 4 (\" View/Edit/Delete \") | AUTHORITY:  0 (\"\")  > 4 (\" View/Edit/Delete \") | AUTHORITY:  0 (\"\")  > 4 (\" View/Edit/Delete \") | AUTHORITY:  0 (\"\")  > 4 (\" View/Edit/Delete \")','2021-01-11 15:40:31.336062','Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/87.0.4280.141 Safari/537.36'),(15,'49.146.42.127',1,0,3,0,0,10080,6,0,'add/edit Access rights record','LEVEL: 0 (\"\")  >  2 (\" Super Admin \") | MODULE: 0 (\"\")  >  10120 (\" Devices \") | AUTHORITY:  0 (\"\")  > 0 (\" No Access \") | LEVEL: 0 (\"\")  >  2 (\" Super Admin \") | MODULE: 0 (\"\")  >  10160 (\" Brute Force Login Attempt \") | AUTHORITY:  0 (\"\")  > 0 (\" No Access \") | LEVEL: 0 (\"\")  >  2 (\" Super Admin \") | MODULE: 0 (\"\")  >  10180 (\" Bruteforce IP \") | AUTHORITY:  0 (\"\")  > 0 (\" No Access \") | LEVEL: 0 (\"\")  >  2 (\" Super Admin \") | MODULE: 0 (\"\")  >  15010 (\" Addon: Group License \") | AUTHORITY:  0 (\"\")  > 0 (\" No Access \") | LEVEL: 0 (\"\")  >  2 (\" Super Admin \") | MODULE: 0 (\"\")  >  15030 (\" Addon: User License \") | AUTHORITY:  0 (\"\")  > 0 (\" No Access \") | LEVEL: 0 (\"\")  >  2 (\" Super Admin \") | MODULE: 0 (\"\")  >  15050 (\" Addon: Queuing \") | AUTHORITY:  0 (\"\")  > 0 (\" No Access \") | LEVEL: 0 (\"\")  >  2 (\" Super Admin \") | MODULE: 0 (\"\")  >  15070 (\" Addon: Resource \") | AUTHORITY:  0 (\"\")  > 0 (\" No Access \") | LEVEL: 0 (\"\")  >  2 (\" Super Admin \") | MODULE: 0 (\"\")  >  21030 (\" Section \") | AUTHORITY:  0 (\"\")  > 0 (\" No Access \") | LEVEL: 0 (\"\")  >  2 (\" Super Admin \") | MODULE: 0 (\"\")  >  21050 (\" Entrance \") | AUTHORITY:  0 (\"\")  > 0 (\" No Access \") | AUTHORITY:  0 (\"\")  > 4 (\" View/Edit/Delete \") | AUTHORITY:  0 (\"\")  > 4 (\" View/Edit/Delete \") | AUTHORITY:  0 (\"\")  > 4 (\" View/Edit/Delete \") | AUTHORITY:  0 (\"\")  > 4 (\" View/Edit/Delete \") | AUTHORITY:  0 (\"\")  > 4 (\" View/Edit/Delete \") | AUTHORITY:  0 (\"\")  > 4 (\" View/Edit/Delete \")','2021-01-11 15:40:31.341098','Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/87.0.4280.141 Safari/537.36'),(16,'49.146.42.127',1,0,3,0,0,10080,7,0,'add/edit Access rights record','LEVEL: 0 (\"\")  >  2 (\" Super Admin \") | MODULE: 0 (\"\")  >  10120 (\" Devices \") | AUTHORITY:  0 (\"\")  > 0 (\" No Access \") | LEVEL: 0 (\"\")  >  2 (\" Super Admin \") | MODULE: 0 (\"\")  >  10160 (\" Brute Force Login Attempt \") | AUTHORITY:  0 (\"\")  > 0 (\" No Access \") | LEVEL: 0 (\"\")  >  2 (\" Super Admin \") | MODULE: 0 (\"\")  >  10180 (\" Bruteforce IP \") | AUTHORITY:  0 (\"\")  > 0 (\" No Access \") | LEVEL: 0 (\"\")  >  2 (\" Super Admin \") | MODULE: 0 (\"\")  >  15010 (\" Addon: Group License \") | AUTHORITY:  0 (\"\")  > 0 (\" No Access \") | LEVEL: 0 (\"\")  >  2 (\" Super Admin \") | MODULE: 0 (\"\")  >  15030 (\" Addon: User License \") | AUTHORITY:  0 (\"\")  > 0 (\" No Access \") | LEVEL: 0 (\"\")  >  2 (\" Super Admin \") | MODULE: 0 (\"\")  >  15050 (\" Addon: Queuing \") | AUTHORITY:  0 (\"\")  > 0 (\" No Access \") | LEVEL: 0 (\"\")  >  2 (\" Super Admin \") | MODULE: 0 (\"\")  >  15070 (\" Addon: Resource \") | AUTHORITY:  0 (\"\")  > 0 (\" No Access \") | LEVEL: 0 (\"\")  >  2 (\" Super Admin \") | MODULE: 0 (\"\")  >  21030 (\" Section \") | AUTHORITY:  0 (\"\")  > 0 (\" No Access \") | LEVEL: 0 (\"\")  >  2 (\" Super Admin \") | MODULE: 0 (\"\")  >  21050 (\" Entrance \") | AUTHORITY:  0 (\"\")  > 0 (\" No Access \") | AUTHORITY:  0 (\"\")  > 4 (\" View/Edit/Delete \") | AUTHORITY:  0 (\"\")  > 4 (\" View/Edit/Delete \") | AUTHORITY:  0 (\"\")  > 4 (\" View/Edit/Delete \") | AUTHORITY:  0 (\"\")  > 4 (\" View/Edit/Delete \") | AUTHORITY:  0 (\"\")  > 4 (\" View/Edit/Delete \") | AUTHORITY:  0 (\"\")  > 4 (\" View/Edit/Delete \") | AUTHORITY:  0 (\"\")  > 4 (\" View/Edit/Delete \")','2021-01-11 15:40:31.345475','Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/87.0.4280.141 Safari/537.36'),(17,'49.146.42.127',1,0,3,0,0,10080,8,0,'add/edit Access rights record','LEVEL: 0 (\"\")  >  2 (\" Super Admin \") | MODULE: 0 (\"\")  >  10120 (\" Devices \") | AUTHORITY:  0 (\"\")  > 0 (\" No Access \") | LEVEL: 0 (\"\")  >  2 (\" Super Admin \") | MODULE: 0 (\"\")  >  10160 (\" Brute Force Login Attempt \") | AUTHORITY:  0 (\"\")  > 0 (\" No Access \") | LEVEL: 0 (\"\")  >  2 (\" Super Admin \") | MODULE: 0 (\"\")  >  10180 (\" Bruteforce IP \") | AUTHORITY:  0 (\"\")  > 0 (\" No Access \") | LEVEL: 0 (\"\")  >  2 (\" Super Admin \") | MODULE: 0 (\"\")  >  15010 (\" Addon: Group License \") | AUTHORITY:  0 (\"\")  > 0 (\" No Access \") | LEVEL: 0 (\"\")  >  2 (\" Super Admin \") | MODULE: 0 (\"\")  >  15030 (\" Addon: User License \") | AUTHORITY:  0 (\"\")  > 0 (\" No Access \") | LEVEL: 0 (\"\")  >  2 (\" Super Admin \") | MODULE: 0 (\"\")  >  15050 (\" Addon: Queuing \") | AUTHORITY:  0 (\"\")  > 0 (\" No Access \") | LEVEL: 0 (\"\")  >  2 (\" Super Admin \") | MODULE: 0 (\"\")  >  15070 (\" Addon: Resource \") | AUTHORITY:  0 (\"\")  > 0 (\" No Access \") | LEVEL: 0 (\"\")  >  2 (\" Super Admin \") | MODULE: 0 (\"\")  >  21030 (\" Section \") | AUTHORITY:  0 (\"\")  > 0 (\" No Access \") | LEVEL: 0 (\"\")  >  2 (\" Super Admin \") | MODULE: 0 (\"\")  >  21050 (\" Entrance \") | AUTHORITY:  0 (\"\")  > 0 (\" No Access \") | AUTHORITY:  0 (\"\")  > 4 (\" View/Edit/Delete \") | AUTHORITY:  0 (\"\")  > 4 (\" View/Edit/Delete \") | AUTHORITY:  0 (\"\")  > 4 (\" View/Edit/Delete \") | AUTHORITY:  0 (\"\")  > 4 (\" View/Edit/Delete \") | AUTHORITY:  0 (\"\")  > 4 (\" View/Edit/Delete \") | AUTHORITY:  0 (\"\")  > 4 (\" View/Edit/Delete \") | AUTHORITY:  0 (\"\")  > 4 (\" View/Edit/Delete \") | AUTHORITY:  0 (\"\")  > 4 (\" View/Edit/Delete \")','2021-01-11 15:40:31.350203','Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/87.0.4280.141 Safari/537.36'),(18,'49.146.42.127',1,0,3,0,0,10080,9,0,'add/edit Access rights record','LEVEL: 0 (\"\")  >  2 (\" Super Admin \") | MODULE: 0 (\"\")  >  10120 (\" Devices \") | AUTHORITY:  0 (\"\")  > 0 (\" No Access \") | LEVEL: 0 (\"\")  >  2 (\" Super Admin \") | MODULE: 0 (\"\")  >  10160 (\" Brute Force Login Attempt \") | AUTHORITY:  0 (\"\")  > 0 (\" No Access \") | LEVEL: 0 (\"\")  >  2 (\" Super Admin \") | MODULE: 0 (\"\")  >  10180 (\" Bruteforce IP \") | AUTHORITY:  0 (\"\")  > 0 (\" No Access \") | LEVEL: 0 (\"\")  >  2 (\" Super Admin \") | MODULE: 0 (\"\")  >  15010 (\" Addon: Group License \") | AUTHORITY:  0 (\"\")  > 0 (\" No Access \") | LEVEL: 0 (\"\")  >  2 (\" Super Admin \") | MODULE: 0 (\"\")  >  15030 (\" Addon: User License \") | AUTHORITY:  0 (\"\")  > 0 (\" No Access \") | LEVEL: 0 (\"\")  >  2 (\" Super Admin \") | MODULE: 0 (\"\")  >  15050 (\" Addon: Queuing \") | AUTHORITY:  0 (\"\")  > 0 (\" No Access \") | LEVEL: 0 (\"\")  >  2 (\" Super Admin \") | MODULE: 0 (\"\")  >  15070 (\" Addon: Resource \") | AUTHORITY:  0 (\"\")  > 0 (\" No Access \") | LEVEL: 0 (\"\")  >  2 (\" Super Admin \") | MODULE: 0 (\"\")  >  21030 (\" Section \") | AUTHORITY:  0 (\"\")  > 0 (\" No Access \") | LEVEL: 0 (\"\")  >  2 (\" Super Admin \") | MODULE: 0 (\"\")  >  21050 (\" Entrance \") | AUTHORITY:  0 (\"\")  > 0 (\" No Access \") | AUTHORITY:  0 (\"\")  > 4 (\" View/Edit/Delete \") | AUTHORITY:  0 (\"\")  > 4 (\" View/Edit/Delete \") | AUTHORITY:  0 (\"\")  > 4 (\" View/Edit/Delete \") | AUTHORITY:  0 (\"\")  > 4 (\" View/Edit/Delete \") | AUTHORITY:  0 (\"\")  > 4 (\" View/Edit/Delete \") | AUTHORITY:  0 (\"\")  > 4 (\" View/Edit/Delete \") | AUTHORITY:  0 (\"\")  > 4 (\" View/Edit/Delete \") | AUTHORITY:  0 (\"\")  > 4 (\" View/Edit/Delete \") | AUTHORITY:  0 (\"\")  > 4 (\" View/Edit/Delete \")','2021-01-11 15:40:31.354354','Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/87.0.4280.141 Safari/537.36'),(19,'49.146.42.127',1,0,3,0,0,10080,10,0,'add/edit Access rights record','LEVEL: 0 (\"\")  >  2 (\" Super Admin \") | MODULE: 0 (\"\")  >  10120 (\" Devices \") | AUTHORITY:  0 (\"\")  > 0 (\" No Access \") | LEVEL: 0 (\"\")  >  2 (\" Super Admin \") | MODULE: 0 (\"\")  >  10160 (\" Brute Force Login Attempt \") | AUTHORITY:  0 (\"\")  > 0 (\" No Access \") | LEVEL: 0 (\"\")  >  2 (\" Super Admin \") | MODULE: 0 (\"\")  >  10180 (\" Bruteforce IP \") | AUTHORITY:  0 (\"\")  > 0 (\" No Access \") | LEVEL: 0 (\"\")  >  2 (\" Super Admin \") | MODULE: 0 (\"\")  >  15010 (\" Addon: Group License \") | AUTHORITY:  0 (\"\")  > 0 (\" No Access \") | LEVEL: 0 (\"\")  >  2 (\" Super Admin \") | MODULE: 0 (\"\")  >  15030 (\" Addon: User License \") | AUTHORITY:  0 (\"\")  > 0 (\" No Access \") | LEVEL: 0 (\"\")  >  2 (\" Super Admin \") | MODULE: 0 (\"\")  >  15050 (\" Addon: Queuing \") | AUTHORITY:  0 (\"\")  > 0 (\" No Access \") | LEVEL: 0 (\"\")  >  2 (\" Super Admin \") | MODULE: 0 (\"\")  >  15070 (\" Addon: Resource \") | AUTHORITY:  0 (\"\")  > 0 (\" No Access \") | LEVEL: 0 (\"\")  >  2 (\" Super Admin \") | MODULE: 0 (\"\")  >  21030 (\" Section \") | AUTHORITY:  0 (\"\")  > 0 (\" No Access \") | LEVEL: 0 (\"\")  >  2 (\" Super Admin \") | MODULE: 0 (\"\")  >  21050 (\" Entrance \") | AUTHORITY:  0 (\"\")  > 0 (\" No Access \") | AUTHORITY:  0 (\"\")  > 4 (\" View/Edit/Delete \") | AUTHORITY:  0 (\"\")  > 4 (\" View/Edit/Delete \") | AUTHORITY:  0 (\"\")  > 4 (\" View/Edit/Delete \") | AUTHORITY:  0 (\"\")  > 4 (\" View/Edit/Delete \") | AUTHORITY:  0 (\"\")  > 4 (\" View/Edit/Delete \") | AUTHORITY:  0 (\"\")  > 4 (\" View/Edit/Delete \") | AUTHORITY:  0 (\"\")  > 4 (\" View/Edit/Delete \") | AUTHORITY:  0 (\"\")  > 4 (\" View/Edit/Delete \") | AUTHORITY:  0 (\"\")  > 4 (\" View/Edit/Delete \") | AUTHORITY:  0 (\"\")  > 4 (\" View/Edit/Delete \")','2021-01-11 15:40:31.358471','Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/87.0.4280.141 Safari/537.36'),(20,'49.146.42.127',1,0,3,0,0,10080,11,0,'add/edit Access rights record','LEVEL: 0 (\"\")  >  2 (\" Super Admin \") | MODULE: 0 (\"\")  >  10120 (\" Devices \") | AUTHORITY:  0 (\"\")  > 0 (\" No Access \") | LEVEL: 0 (\"\")  >  2 (\" Super Admin \") | MODULE: 0 (\"\")  >  10160 (\" Brute Force Login Attempt \") | AUTHORITY:  0 (\"\")  > 0 (\" No Access \") | LEVEL: 0 (\"\")  >  2 (\" Super Admin \") | MODULE: 0 (\"\")  >  10180 (\" Bruteforce IP \") | AUTHORITY:  0 (\"\")  > 0 (\" No Access \") | LEVEL: 0 (\"\")  >  2 (\" Super Admin \") | MODULE: 0 (\"\")  >  15010 (\" Addon: Group License \") | AUTHORITY:  0 (\"\")  > 0 (\" No Access \") | LEVEL: 0 (\"\")  >  2 (\" Super Admin \") | MODULE: 0 (\"\")  >  15030 (\" Addon: User License \") | AUTHORITY:  0 (\"\")  > 0 (\" No Access \") | LEVEL: 0 (\"\")  >  2 (\" Super Admin \") | MODULE: 0 (\"\")  >  15050 (\" Addon: Queuing \") | AUTHORITY:  0 (\"\")  > 0 (\" No Access \") | LEVEL: 0 (\"\")  >  2 (\" Super Admin \") | MODULE: 0 (\"\")  >  15070 (\" Addon: Resource \") | AUTHORITY:  0 (\"\")  > 0 (\" No Access \") | LEVEL: 0 (\"\")  >  2 (\" Super Admin \") | MODULE: 0 (\"\")  >  21030 (\" Section \") | AUTHORITY:  0 (\"\")  > 0 (\" No Access \") | LEVEL: 0 (\"\")  >  2 (\" Super Admin \") | MODULE: 0 (\"\")  >  21050 (\" Entrance \") | AUTHORITY:  0 (\"\")  > 0 (\" No Access \") | AUTHORITY:  0 (\"\")  > 4 (\" View/Edit/Delete \") | AUTHORITY:  0 (\"\")  > 4 (\" View/Edit/Delete \") | AUTHORITY:  0 (\"\")  > 4 (\" View/Edit/Delete \") | AUTHORITY:  0 (\"\")  > 4 (\" View/Edit/Delete \") | AUTHORITY:  0 (\"\")  > 4 (\" View/Edit/Delete \") | AUTHORITY:  0 (\"\")  > 4 (\" View/Edit/Delete \") | AUTHORITY:  0 (\"\")  > 4 (\" View/Edit/Delete \") | AUTHORITY:  0 (\"\")  > 4 (\" View/Edit/Delete \") | AUTHORITY:  0 (\"\")  > 4 (\" View/Edit/Delete \") | AUTHORITY:  0 (\"\")  > 4 (\" View/Edit/Delete \") | AUTHORITY:  0 (\"\")  > 4 (\" View/Edit/Delete \")','2021-01-11 15:40:31.362238','Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/87.0.4280.141 Safari/537.36'),(21,'49.146.42.127',1,0,3,0,0,10080,25,0,'add/edit Access rights record','LEVEL: 0 (\"\")  >  2 (\" Super Admin \") | MODULE: 0 (\"\")  >  10120 (\" Devices \") | AUTHORITY:  0 (\"\")  > 0 (\" No Access \") | LEVEL: 0 (\"\")  >  2 (\" Super Admin \") | MODULE: 0 (\"\")  >  10160 (\" Brute Force Login Attempt \") | AUTHORITY:  0 (\"\")  > 0 (\" No Access \") | LEVEL: 0 (\"\")  >  2 (\" Super Admin \") | MODULE: 0 (\"\")  >  10180 (\" Bruteforce IP \") | AUTHORITY:  0 (\"\")  > 0 (\" No Access \") | LEVEL: 0 (\"\")  >  2 (\" Super Admin \") | MODULE: 0 (\"\")  >  15010 (\" Addon: Group License \") | AUTHORITY:  0 (\"\")  > 0 (\" No Access \") | LEVEL: 0 (\"\")  >  2 (\" Super Admin \") | MODULE: 0 (\"\")  >  15030 (\" Addon: User License \") | AUTHORITY:  0 (\"\")  > 0 (\" No Access \") | LEVEL: 0 (\"\")  >  2 (\" Super Admin \") | MODULE: 0 (\"\")  >  15050 (\" Addon: Queuing \") | AUTHORITY:  0 (\"\")  > 0 (\" No Access \") | LEVEL: 0 (\"\")  >  2 (\" Super Admin \") | MODULE: 0 (\"\")  >  15070 (\" Addon: Resource \") | AUTHORITY:  0 (\"\")  > 0 (\" No Access \") | LEVEL: 0 (\"\")  >  2 (\" Super Admin \") | MODULE: 0 (\"\")  >  21030 (\" Section \") | AUTHORITY:  0 (\"\")  > 0 (\" No Access \") | LEVEL: 0 (\"\")  >  2 (\" Super Admin \") | MODULE: 0 (\"\")  >  21050 (\" Entrance \") | AUTHORITY:  0 (\"\")  > 0 (\" No Access \") | AUTHORITY:  0 (\"\")  > 4 (\" View/Edit/Delete \") | AUTHORITY:  0 (\"\")  > 4 (\" View/Edit/Delete \") | AUTHORITY:  0 (\"\")  > 4 (\" View/Edit/Delete \") | AUTHORITY:  0 (\"\")  > 4 (\" View/Edit/Delete \") | AUTHORITY:  0 (\"\")  > 4 (\" View/Edit/Delete \") | AUTHORITY:  0 (\"\")  > 4 (\" View/Edit/Delete \") | AUTHORITY:  0 (\"\")  > 4 (\" View/Edit/Delete \") | AUTHORITY:  0 (\"\")  > 4 (\" View/Edit/Delete \") | AUTHORITY:  0 (\"\")  > 4 (\" View/Edit/Delete \") | AUTHORITY:  0 (\"\")  > 4 (\" View/Edit/Delete \") | AUTHORITY:  0 (\"\")  > 4 (\" View/Edit/Delete \") | AUTHORITY:  0 (\"\")  > 4 (\" View/Edit/Delete \")','2021-01-11 15:40:31.366177','Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/87.0.4280.141 Safari/537.36'),(22,'49.146.42.127',1,0,3,0,0,10080,38,0,'add/edit Access rights record','LEVEL: 0 (\"\")  >  2 (\" Super Admin \") | MODULE: 0 (\"\")  >  10120 (\" Devices \") | AUTHORITY:  0 (\"\")  > 0 (\" No Access \") | LEVEL: 0 (\"\")  >  2 (\" Super Admin \") | MODULE: 0 (\"\")  >  10160 (\" Brute Force Login Attempt \") | AUTHORITY:  0 (\"\")  > 0 (\" No Access \") | LEVEL: 0 (\"\")  >  2 (\" Super Admin \") | MODULE: 0 (\"\")  >  10180 (\" Bruteforce IP \") | AUTHORITY:  0 (\"\")  > 0 (\" No Access \") | LEVEL: 0 (\"\")  >  2 (\" Super Admin \") | MODULE: 0 (\"\")  >  15010 (\" Addon: Group License \") | AUTHORITY:  0 (\"\")  > 0 (\" No Access \") | LEVEL: 0 (\"\")  >  2 (\" Super Admin \") | MODULE: 0 (\"\")  >  15030 (\" Addon: User License \") | AUTHORITY:  0 (\"\")  > 0 (\" No Access \") | LEVEL: 0 (\"\")  >  2 (\" Super Admin \") | MODULE: 0 (\"\")  >  15050 (\" Addon: Queuing \") | AUTHORITY:  0 (\"\")  > 0 (\" No Access \") | LEVEL: 0 (\"\")  >  2 (\" Super Admin \") | MODULE: 0 (\"\")  >  15070 (\" Addon: Resource \") | AUTHORITY:  0 (\"\")  > 0 (\" No Access \") | LEVEL: 0 (\"\")  >  2 (\" Super Admin \") | MODULE: 0 (\"\")  >  21030 (\" Section \") | AUTHORITY:  0 (\"\")  > 0 (\" No Access \") | LEVEL: 0 (\"\")  >  2 (\" Super Admin \") | MODULE: 0 (\"\")  >  21050 (\" Entrance \") | AUTHORITY:  0 (\"\")  > 0 (\" No Access \") | AUTHORITY:  0 (\"\")  > 4 (\" View/Edit/Delete \") | AUTHORITY:  0 (\"\")  > 4 (\" View/Edit/Delete \") | AUTHORITY:  0 (\"\")  > 4 (\" View/Edit/Delete \") | AUTHORITY:  0 (\"\")  > 4 (\" View/Edit/Delete \") | AUTHORITY:  0 (\"\")  > 4 (\" View/Edit/Delete \") | AUTHORITY:  0 (\"\")  > 4 (\" View/Edit/Delete \") | AUTHORITY:  0 (\"\")  > 4 (\" View/Edit/Delete \") | AUTHORITY:  0 (\"\")  > 4 (\" View/Edit/Delete \") | AUTHORITY:  0 (\"\")  > 4 (\" View/Edit/Delete \") | AUTHORITY:  0 (\"\")  > 4 (\" View/Edit/Delete \") | AUTHORITY:  0 (\"\")  > 4 (\" View/Edit/Delete \") | AUTHORITY:  0 (\"\")  > 4 (\" View/Edit/Delete \") | AUTHORITY:  0 (\"\")  > 4 (\" View/Edit/Delete \")','2021-01-11 15:40:31.370208','Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/87.0.4280.141 Safari/537.36'),(23,'49.146.42.127',1,0,3,0,0,10080,39,0,'add/edit Access rights record','LEVEL: 0 (\"\")  >  2 (\" Super Admin \") | MODULE: 0 (\"\")  >  10120 (\" Devices \") | AUTHORITY:  0 (\"\")  > 0 (\" No Access \") | LEVEL: 0 (\"\")  >  2 (\" Super Admin \") | MODULE: 0 (\"\")  >  10160 (\" Brute Force Login Attempt \") | AUTHORITY:  0 (\"\")  > 0 (\" No Access \") | LEVEL: 0 (\"\")  >  2 (\" Super Admin \") | MODULE: 0 (\"\")  >  10180 (\" Bruteforce IP \") | AUTHORITY:  0 (\"\")  > 0 (\" No Access \") | LEVEL: 0 (\"\")  >  2 (\" Super Admin \") | MODULE: 0 (\"\")  >  15010 (\" Addon: Group License \") | AUTHORITY:  0 (\"\")  > 0 (\" No Access \") | LEVEL: 0 (\"\")  >  2 (\" Super Admin \") | MODULE: 0 (\"\")  >  15030 (\" Addon: User License \") | AUTHORITY:  0 (\"\")  > 0 (\" No Access \") | LEVEL: 0 (\"\")  >  2 (\" Super Admin \") | MODULE: 0 (\"\")  >  15050 (\" Addon: Queuing \") | AUTHORITY:  0 (\"\")  > 0 (\" No Access \") | LEVEL: 0 (\"\")  >  2 (\" Super Admin \") | MODULE: 0 (\"\")  >  15070 (\" Addon: Resource \") | AUTHORITY:  0 (\"\")  > 0 (\" No Access \") | LEVEL: 0 (\"\")  >  2 (\" Super Admin \") | MODULE: 0 (\"\")  >  21030 (\" Section \") | AUTHORITY:  0 (\"\")  > 0 (\" No Access \") | LEVEL: 0 (\"\")  >  2 (\" Super Admin \") | MODULE: 0 (\"\")  >  21050 (\" Entrance \") | AUTHORITY:  0 (\"\")  > 0 (\" No Access \") | AUTHORITY:  0 (\"\")  > 4 (\" View/Edit/Delete \") | AUTHORITY:  0 (\"\")  > 4 (\" View/Edit/Delete \") | AUTHORITY:  0 (\"\")  > 4 (\" View/Edit/Delete \") | AUTHORITY:  0 (\"\")  > 4 (\" View/Edit/Delete \") | AUTHORITY:  0 (\"\")  > 4 (\" View/Edit/Delete \") | AUTHORITY:  0 (\"\")  > 4 (\" View/Edit/Delete \") | AUTHORITY:  0 (\"\")  > 4 (\" View/Edit/Delete \") | AUTHORITY:  0 (\"\")  > 4 (\" View/Edit/Delete \") | AUTHORITY:  0 (\"\")  > 4 (\" View/Edit/Delete \") | AUTHORITY:  0 (\"\")  > 4 (\" View/Edit/Delete \") | AUTHORITY:  0 (\"\")  > 4 (\" View/Edit/Delete \") | AUTHORITY:  0 (\"\")  > 4 (\" View/Edit/Delete \") | AUTHORITY:  0 (\"\")  > 4 (\" View/Edit/Delete \") | AUTHORITY:  0 (\"\")  > 4 (\" View/Edit/Delete \")','2021-01-11 15:40:31.374441','Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/87.0.4280.141 Safari/537.36'),(24,'49.146.42.127',1,0,3,0,0,10080,40,0,'add/edit Access rights record','LEVEL: 0 (\"\")  >  2 (\" Super Admin \") | MODULE: 0 (\"\")  >  10120 (\" Devices \") | AUTHORITY:  0 (\"\")  > 0 (\" No Access \") | LEVEL: 0 (\"\")  >  2 (\" Super Admin \") | MODULE: 0 (\"\")  >  10160 (\" Brute Force Login Attempt \") | AUTHORITY:  0 (\"\")  > 0 (\" No Access \") | LEVEL: 0 (\"\")  >  2 (\" Super Admin \") | MODULE: 0 (\"\")  >  10180 (\" Bruteforce IP \") | AUTHORITY:  0 (\"\")  > 0 (\" No Access \") | LEVEL: 0 (\"\")  >  2 (\" Super Admin \") | MODULE: 0 (\"\")  >  15010 (\" Addon: Group License \") | AUTHORITY:  0 (\"\")  > 0 (\" No Access \") | LEVEL: 0 (\"\")  >  2 (\" Super Admin \") | MODULE: 0 (\"\")  >  15030 (\" Addon: User License \") | AUTHORITY:  0 (\"\")  > 0 (\" No Access \") | LEVEL: 0 (\"\")  >  2 (\" Super Admin \") | MODULE: 0 (\"\")  >  15050 (\" Addon: Queuing \") | AUTHORITY:  0 (\"\")  > 0 (\" No Access \") | LEVEL: 0 (\"\")  >  2 (\" Super Admin \") | MODULE: 0 (\"\")  >  15070 (\" Addon: Resource \") | AUTHORITY:  0 (\"\")  > 0 (\" No Access \") | LEVEL: 0 (\"\")  >  2 (\" Super Admin \") | MODULE: 0 (\"\")  >  21030 (\" Section \") | AUTHORITY:  0 (\"\")  > 0 (\" No Access \") | LEVEL: 0 (\"\")  >  2 (\" Super Admin \") | MODULE: 0 (\"\")  >  21050 (\" Entrance \") | AUTHORITY:  0 (\"\")  > 0 (\" No Access \") | AUTHORITY:  0 (\"\")  > 4 (\" View/Edit/Delete \") | AUTHORITY:  0 (\"\")  > 4 (\" View/Edit/Delete \") | AUTHORITY:  0 (\"\")  > 4 (\" View/Edit/Delete \") | AUTHORITY:  0 (\"\")  > 4 (\" View/Edit/Delete \") | AUTHORITY:  0 (\"\")  > 4 (\" View/Edit/Delete \") | AUTHORITY:  0 (\"\")  > 4 (\" View/Edit/Delete \") | AUTHORITY:  0 (\"\")  > 4 (\" View/Edit/Delete \") | AUTHORITY:  0 (\"\")  > 4 (\" View/Edit/Delete \") | AUTHORITY:  0 (\"\")  > 4 (\" View/Edit/Delete \") | AUTHORITY:  0 (\"\")  > 4 (\" View/Edit/Delete \") | AUTHORITY:  0 (\"\")  > 4 (\" View/Edit/Delete \") | AUTHORITY:  0 (\"\")  > 4 (\" View/Edit/Delete \") | AUTHORITY:  0 (\"\")  > 4 (\" View/Edit/Delete \") | AUTHORITY:  0 (\"\")  > 4 (\" View/Edit/Delete \") | AUTHORITY:  0 (\"\")  > 4 (\" View/Edit/Delete \")','2021-01-11 15:40:31.380465','Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/87.0.4280.141 Safari/537.36'),(25,'49.146.42.127',1,0,3,0,0,10080,41,0,'add/edit Access rights record','LEVEL: 0 (\"\")  >  2 (\" Super Admin \") | MODULE: 0 (\"\")  >  10120 (\" Devices \") | AUTHORITY:  0 (\"\")  > 0 (\" No Access \") | LEVEL: 0 (\"\")  >  2 (\" Super Admin \") | MODULE: 0 (\"\")  >  10160 (\" Brute Force Login Attempt \") | AUTHORITY:  0 (\"\")  > 0 (\" No Access \") | LEVEL: 0 (\"\")  >  2 (\" Super Admin \") | MODULE: 0 (\"\")  >  10180 (\" Bruteforce IP \") | AUTHORITY:  0 (\"\")  > 0 (\" No Access \") | LEVEL: 0 (\"\")  >  2 (\" Super Admin \") | MODULE: 0 (\"\")  >  15010 (\" Addon: Group License \") | AUTHORITY:  0 (\"\")  > 0 (\" No Access \") | LEVEL: 0 (\"\")  >  2 (\" Super Admin \") | MODULE: 0 (\"\")  >  15030 (\" Addon: User License \") | AUTHORITY:  0 (\"\")  > 0 (\" No Access \") | LEVEL: 0 (\"\")  >  2 (\" Super Admin \") | MODULE: 0 (\"\")  >  15050 (\" Addon: Queuing \") | AUTHORITY:  0 (\"\")  > 0 (\" No Access \") | LEVEL: 0 (\"\")  >  2 (\" Super Admin \") | MODULE: 0 (\"\")  >  15070 (\" Addon: Resource \") | AUTHORITY:  0 (\"\")  > 0 (\" No Access \") | LEVEL: 0 (\"\")  >  2 (\" Super Admin \") | MODULE: 0 (\"\")  >  21030 (\" Section \") | AUTHORITY:  0 (\"\")  > 0 (\" No Access \") | LEVEL: 0 (\"\")  >  2 (\" Super Admin \") | MODULE: 0 (\"\")  >  21050 (\" Entrance \") | AUTHORITY:  0 (\"\")  > 0 (\" No Access \") | AUTHORITY:  0 (\"\")  > 4 (\" View/Edit/Delete \") | AUTHORITY:  0 (\"\")  > 4 (\" View/Edit/Delete \") | AUTHORITY:  0 (\"\")  > 4 (\" View/Edit/Delete \") | AUTHORITY:  0 (\"\")  > 4 (\" View/Edit/Delete \") | AUTHORITY:  0 (\"\")  > 4 (\" View/Edit/Delete \") | AUTHORITY:  0 (\"\")  > 4 (\" View/Edit/Delete \") | AUTHORITY:  0 (\"\")  > 4 (\" View/Edit/Delete \") | AUTHORITY:  0 (\"\")  > 4 (\" View/Edit/Delete \") | AUTHORITY:  0 (\"\")  > 4 (\" View/Edit/Delete \") | AUTHORITY:  0 (\"\")  > 4 (\" View/Edit/Delete \") | AUTHORITY:  0 (\"\")  > 4 (\" View/Edit/Delete \") | AUTHORITY:  0 (\"\")  > 4 (\" View/Edit/Delete \") | AUTHORITY:  0 (\"\")  > 4 (\" View/Edit/Delete \") | AUTHORITY:  0 (\"\")  > 4 (\" View/Edit/Delete \") | AUTHORITY:  0 (\"\")  > 4 (\" View/Edit/Delete \") | AUTHORITY:  0 (\"\")  > 4 (\" View/Edit/Delete \")','2021-01-11 15:40:31.384984','Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/87.0.4280.141 Safari/537.36'),(26,'49.146.42.127',1,0,3,0,0,10080,42,0,'add/edit Access rights record','LEVEL: 0 (\"\")  >  2 (\" Super Admin \") | MODULE: 0 (\"\")  >  10120 (\" Devices \") | AUTHORITY:  0 (\"\")  > 0 (\" No Access \") | LEVEL: 0 (\"\")  >  2 (\" Super Admin \") | MODULE: 0 (\"\")  >  10160 (\" Brute Force Login Attempt \") | AUTHORITY:  0 (\"\")  > 0 (\" No Access \") | LEVEL: 0 (\"\")  >  2 (\" Super Admin \") | MODULE: 0 (\"\")  >  10180 (\" Bruteforce IP \") | AUTHORITY:  0 (\"\")  > 0 (\" No Access \") | LEVEL: 0 (\"\")  >  2 (\" Super Admin \") | MODULE: 0 (\"\")  >  15010 (\" Addon: Group License \") | AUTHORITY:  0 (\"\")  > 0 (\" No Access \") | LEVEL: 0 (\"\")  >  2 (\" Super Admin \") | MODULE: 0 (\"\")  >  15030 (\" Addon: User License \") | AUTHORITY:  0 (\"\")  > 0 (\" No Access \") | LEVEL: 0 (\"\")  >  2 (\" Super Admin \") | MODULE: 0 (\"\")  >  15050 (\" Addon: Queuing \") | AUTHORITY:  0 (\"\")  > 0 (\" No Access \") | LEVEL: 0 (\"\")  >  2 (\" Super Admin \") | MODULE: 0 (\"\")  >  15070 (\" Addon: Resource \") | AUTHORITY:  0 (\"\")  > 0 (\" No Access \") | LEVEL: 0 (\"\")  >  2 (\" Super Admin \") | MODULE: 0 (\"\")  >  21030 (\" Section \") | AUTHORITY:  0 (\"\")  > 0 (\" No Access \") | LEVEL: 0 (\"\")  >  2 (\" Super Admin \") | MODULE: 0 (\"\")  >  21050 (\" Entrance \") | AUTHORITY:  0 (\"\")  > 0 (\" No Access \") | AUTHORITY:  0 (\"\")  > 4 (\" View/Edit/Delete \") | AUTHORITY:  0 (\"\")  > 4 (\" View/Edit/Delete \") | AUTHORITY:  0 (\"\")  > 4 (\" View/Edit/Delete \") | AUTHORITY:  0 (\"\")  > 4 (\" View/Edit/Delete \") | AUTHORITY:  0 (\"\")  > 4 (\" View/Edit/Delete \") | AUTHORITY:  0 (\"\")  > 4 (\" View/Edit/Delete \") | AUTHORITY:  0 (\"\")  > 4 (\" View/Edit/Delete \") | AUTHORITY:  0 (\"\")  > 4 (\" View/Edit/Delete \") | AUTHORITY:  0 (\"\")  > 4 (\" View/Edit/Delete \") | AUTHORITY:  0 (\"\")  > 4 (\" View/Edit/Delete \") | AUTHORITY:  0 (\"\")  > 4 (\" View/Edit/Delete \") | AUTHORITY:  0 (\"\")  > 4 (\" View/Edit/Delete \") | AUTHORITY:  0 (\"\")  > 4 (\" View/Edit/Delete \") | AUTHORITY:  0 (\"\")  > 4 (\" View/Edit/Delete \") | AUTHORITY:  0 (\"\")  > 4 (\" View/Edit/Delete \") | AUTHORITY:  0 (\"\")  > 4 (\" View/Edit/Delete \") | AUTHORITY:  0 (\"\")  > 4 (\" View/Edit/Delete \")','2021-01-11 15:40:31.389517','Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/87.0.4280.141 Safari/537.36'),(27,'49.146.42.127',1,0,3,0,0,10080,43,0,'add/edit Access rights record','LEVEL: 0 (\"\")  >  2 (\" Super Admin \") | MODULE: 0 (\"\")  >  10120 (\" Devices \") | AUTHORITY:  0 (\"\")  > 0 (\" No Access \") | LEVEL: 0 (\"\")  >  2 (\" Super Admin \") | MODULE: 0 (\"\")  >  10160 (\" Brute Force Login Attempt \") | AUTHORITY:  0 (\"\")  > 0 (\" No Access \") | LEVEL: 0 (\"\")  >  2 (\" Super Admin \") | MODULE: 0 (\"\")  >  10180 (\" Bruteforce IP \") | AUTHORITY:  0 (\"\")  > 0 (\" No Access \") | LEVEL: 0 (\"\")  >  2 (\" Super Admin \") | MODULE: 0 (\"\")  >  15010 (\" Addon: Group License \") | AUTHORITY:  0 (\"\")  > 0 (\" No Access \") | LEVEL: 0 (\"\")  >  2 (\" Super Admin \") | MODULE: 0 (\"\")  >  15030 (\" Addon: User License \") | AUTHORITY:  0 (\"\")  > 0 (\" No Access \") | LEVEL: 0 (\"\")  >  2 (\" Super Admin \") | MODULE: 0 (\"\")  >  15050 (\" Addon: Queuing \") | AUTHORITY:  0 (\"\")  > 0 (\" No Access \") | LEVEL: 0 (\"\")  >  2 (\" Super Admin \") | MODULE: 0 (\"\")  >  15070 (\" Addon: Resource \") | AUTHORITY:  0 (\"\")  > 0 (\" No Access \") | LEVEL: 0 (\"\")  >  2 (\" Super Admin \") | MODULE: 0 (\"\")  >  21030 (\" Section \") | AUTHORITY:  0 (\"\")  > 0 (\" No Access \") | LEVEL: 0 (\"\")  >  2 (\" Super Admin \") | MODULE: 0 (\"\")  >  21050 (\" Entrance \") | AUTHORITY:  0 (\"\")  > 0 (\" No Access \") | AUTHORITY:  0 (\"\")  > 4 (\" View/Edit/Delete \") | AUTHORITY:  0 (\"\")  > 4 (\" View/Edit/Delete \") | AUTHORITY:  0 (\"\")  > 4 (\" View/Edit/Delete \") | AUTHORITY:  0 (\"\")  > 4 (\" View/Edit/Delete \") | AUTHORITY:  0 (\"\")  > 4 (\" View/Edit/Delete \") | AUTHORITY:  0 (\"\")  > 4 (\" View/Edit/Delete \") | AUTHORITY:  0 (\"\")  > 4 (\" View/Edit/Delete \") | AUTHORITY:  0 (\"\")  > 4 (\" View/Edit/Delete \") | AUTHORITY:  0 (\"\")  > 4 (\" View/Edit/Delete \") | AUTHORITY:  0 (\"\")  > 4 (\" View/Edit/Delete \") | AUTHORITY:  0 (\"\")  > 4 (\" View/Edit/Delete \") | AUTHORITY:  0 (\"\")  > 4 (\" View/Edit/Delete \") | AUTHORITY:  0 (\"\")  > 4 (\" View/Edit/Delete \") | AUTHORITY:  0 (\"\")  > 4 (\" View/Edit/Delete \") | AUTHORITY:  0 (\"\")  > 4 (\" View/Edit/Delete \") | AUTHORITY:  0 (\"\")  > 4 (\" View/Edit/Delete \") | AUTHORITY:  0 (\"\")  > 4 (\" View/Edit/Delete \") | AUTHORITY:  0 (\"\")  > 4 (\" View/Edit/Delete \")','2021-01-11 15:40:31.393482','Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/87.0.4280.141 Safari/537.36'),(28,'49.146.42.127',1,0,3,0,0,10080,44,0,'add/edit Access rights record','LEVEL: 0 (\"\")  >  2 (\" Super Admin \") | MODULE: 0 (\"\")  >  10120 (\" Devices \") | AUTHORITY:  0 (\"\")  > 0 (\" No Access \") | LEVEL: 0 (\"\")  >  2 (\" Super Admin \") | MODULE: 0 (\"\")  >  10160 (\" Brute Force Login Attempt \") | AUTHORITY:  0 (\"\")  > 0 (\" No Access \") | LEVEL: 0 (\"\")  >  2 (\" Super Admin \") | MODULE: 0 (\"\")  >  10180 (\" Bruteforce IP \") | AUTHORITY:  0 (\"\")  > 0 (\" No Access \") | LEVEL: 0 (\"\")  >  2 (\" Super Admin \") | MODULE: 0 (\"\")  >  15010 (\" Addon: Group License \") | AUTHORITY:  0 (\"\")  > 0 (\" No Access \") | LEVEL: 0 (\"\")  >  2 (\" Super Admin \") | MODULE: 0 (\"\")  >  15030 (\" Addon: User License \") | AUTHORITY:  0 (\"\")  > 0 (\" No Access \") | LEVEL: 0 (\"\")  >  2 (\" Super Admin \") | MODULE: 0 (\"\")  >  15050 (\" Addon: Queuing \") | AUTHORITY:  0 (\"\")  > 0 (\" No Access \") | LEVEL: 0 (\"\")  >  2 (\" Super Admin \") | MODULE: 0 (\"\")  >  15070 (\" Addon: Resource \") | AUTHORITY:  0 (\"\")  > 0 (\" No Access \") | LEVEL: 0 (\"\")  >  2 (\" Super Admin \") | MODULE: 0 (\"\")  >  21030 (\" Section \") | AUTHORITY:  0 (\"\")  > 0 (\" No Access \") | LEVEL: 0 (\"\")  >  2 (\" Super Admin \") | MODULE: 0 (\"\")  >  21050 (\" Entrance \") | AUTHORITY:  0 (\"\")  > 0 (\" No Access \") | AUTHORITY:  0 (\"\")  > 4 (\" View/Edit/Delete \") | AUTHORITY:  0 (\"\")  > 4 (\" View/Edit/Delete \") | AUTHORITY:  0 (\"\")  > 4 (\" View/Edit/Delete \") | AUTHORITY:  0 (\"\")  > 4 (\" View/Edit/Delete \") | AUTHORITY:  0 (\"\")  > 4 (\" View/Edit/Delete \") | AUTHORITY:  0 (\"\")  > 4 (\" View/Edit/Delete \") | AUTHORITY:  0 (\"\")  > 4 (\" View/Edit/Delete \") | AUTHORITY:  0 (\"\")  > 4 (\" View/Edit/Delete \") | AUTHORITY:  0 (\"\")  > 4 (\" View/Edit/Delete \") | AUTHORITY:  0 (\"\")  > 4 (\" View/Edit/Delete \") | AUTHORITY:  0 (\"\")  > 4 (\" View/Edit/Delete \") | AUTHORITY:  0 (\"\")  > 4 (\" View/Edit/Delete \") | AUTHORITY:  0 (\"\")  > 4 (\" View/Edit/Delete \") | AUTHORITY:  0 (\"\")  > 4 (\" View/Edit/Delete \") | AUTHORITY:  0 (\"\")  > 4 (\" View/Edit/Delete \") | AUTHORITY:  0 (\"\")  > 4 (\" View/Edit/Delete \") | AUTHORITY:  0 (\"\")  > 4 (\" View/Edit/Delete \") | AUTHORITY:  0 (\"\")  > 4 (\" View/Edit/Delete \") | AUTHORITY:  0 (\"\")  > 4 (\" View/Edit/Delete \")','2021-01-11 15:40:31.397602','Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/87.0.4280.141 Safari/537.36'),(29,'49.146.42.127',1,0,3,0,0,10080,45,0,'add/edit Access rights record','LEVEL: 0 (\"\")  >  2 (\" Super Admin \") | MODULE: 0 (\"\")  >  10120 (\" Devices \") | AUTHORITY:  0 (\"\")  > 0 (\" No Access \") | LEVEL: 0 (\"\")  >  2 (\" Super Admin \") | MODULE: 0 (\"\")  >  10160 (\" Brute Force Login Attempt \") | AUTHORITY:  0 (\"\")  > 0 (\" No Access \") | LEVEL: 0 (\"\")  >  2 (\" Super Admin \") | MODULE: 0 (\"\")  >  10180 (\" Bruteforce IP \") | AUTHORITY:  0 (\"\")  > 0 (\" No Access \") | LEVEL: 0 (\"\")  >  2 (\" Super Admin \") | MODULE: 0 (\"\")  >  15010 (\" Addon: Group License \") | AUTHORITY:  0 (\"\")  > 0 (\" No Access \") | LEVEL: 0 (\"\")  >  2 (\" Super Admin \") | MODULE: 0 (\"\")  >  15030 (\" Addon: User License \") | AUTHORITY:  0 (\"\")  > 0 (\" No Access \") | LEVEL: 0 (\"\")  >  2 (\" Super Admin \") | MODULE: 0 (\"\")  >  15050 (\" Addon: Queuing \") | AUTHORITY:  0 (\"\")  > 0 (\" No Access \") | LEVEL: 0 (\"\")  >  2 (\" Super Admin \") | MODULE: 0 (\"\")  >  15070 (\" Addon: Resource \") | AUTHORITY:  0 (\"\")  > 0 (\" No Access \") | LEVEL: 0 (\"\")  >  2 (\" Super Admin \") | MODULE: 0 (\"\")  >  21030 (\" Section \") | AUTHORITY:  0 (\"\")  > 0 (\" No Access \") | LEVEL: 0 (\"\")  >  2 (\" Super Admin \") | MODULE: 0 (\"\")  >  21050 (\" Entrance \") | AUTHORITY:  0 (\"\")  > 0 (\" No Access \") | AUTHORITY:  0 (\"\")  > 4 (\" View/Edit/Delete \") | AUTHORITY:  0 (\"\")  > 4 (\" View/Edit/Delete \") | AUTHORITY:  0 (\"\")  > 4 (\" View/Edit/Delete \") | AUTHORITY:  0 (\"\")  > 4 (\" View/Edit/Delete \") | AUTHORITY:  0 (\"\")  > 4 (\" View/Edit/Delete \") | AUTHORITY:  0 (\"\")  > 4 (\" View/Edit/Delete \") | AUTHORITY:  0 (\"\")  > 4 (\" View/Edit/Delete \") | AUTHORITY:  0 (\"\")  > 4 (\" View/Edit/Delete \") | AUTHORITY:  0 (\"\")  > 4 (\" View/Edit/Delete \") | AUTHORITY:  0 (\"\")  > 4 (\" View/Edit/Delete \") | AUTHORITY:  0 (\"\")  > 4 (\" View/Edit/Delete \") | AUTHORITY:  0 (\"\")  > 4 (\" View/Edit/Delete \") | AUTHORITY:  0 (\"\")  > 4 (\" View/Edit/Delete \") | AUTHORITY:  0 (\"\")  > 4 (\" View/Edit/Delete \") | AUTHORITY:  0 (\"\")  > 4 (\" View/Edit/Delete \") | AUTHORITY:  0 (\"\")  > 4 (\" View/Edit/Delete \") | AUTHORITY:  0 (\"\")  > 4 (\" View/Edit/Delete \") | AUTHORITY:  0 (\"\")  > 4 (\" View/Edit/Delete \") | AUTHORITY:  0 (\"\")  > 4 (\" View/Edit/Delete \") | AUTHORITY:  0 (\"\")  > 4 (\" View/Edit/Delete \")','2021-01-11 15:40:31.402033','Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/87.0.4280.141 Safari/537.36'),(30,'49.146.42.127',1,0,3,0,0,10080,46,0,'add/edit Access rights record','LEVEL: 0 (\"\")  >  2 (\" Super Admin \") | MODULE: 0 (\"\")  >  10120 (\" Devices \") | AUTHORITY:  0 (\"\")  > 0 (\" No Access \") | LEVEL: 0 (\"\")  >  2 (\" Super Admin \") | MODULE: 0 (\"\")  >  10160 (\" Brute Force Login Attempt \") | AUTHORITY:  0 (\"\")  > 0 (\" No Access \") | LEVEL: 0 (\"\")  >  2 (\" Super Admin \") | MODULE: 0 (\"\")  >  10180 (\" Bruteforce IP \") | AUTHORITY:  0 (\"\")  > 0 (\" No Access \") | LEVEL: 0 (\"\")  >  2 (\" Super Admin \") | MODULE: 0 (\"\")  >  15010 (\" Addon: Group License \") | AUTHORITY:  0 (\"\")  > 0 (\" No Access \") | LEVEL: 0 (\"\")  >  2 (\" Super Admin \") | MODULE: 0 (\"\")  >  15030 (\" Addon: User License \") | AUTHORITY:  0 (\"\")  > 0 (\" No Access \") | LEVEL: 0 (\"\")  >  2 (\" Super Admin \") | MODULE: 0 (\"\")  >  15050 (\" Addon: Queuing \") | AUTHORITY:  0 (\"\")  > 0 (\" No Access \") | LEVEL: 0 (\"\")  >  2 (\" Super Admin \") | MODULE: 0 (\"\")  >  15070 (\" Addon: Resource \") | AUTHORITY:  0 (\"\")  > 0 (\" No Access \") | LEVEL: 0 (\"\")  >  2 (\" Super Admin \") | MODULE: 0 (\"\")  >  21030 (\" Section \") | AUTHORITY:  0 (\"\")  > 0 (\" No Access \") | LEVEL: 0 (\"\")  >  2 (\" Super Admin \") | MODULE: 0 (\"\")  >  21050 (\" Entrance \") | AUTHORITY:  0 (\"\")  > 0 (\" No Access \") | AUTHORITY:  0 (\"\")  > 4 (\" View/Edit/Delete \") | AUTHORITY:  0 (\"\")  > 4 (\" View/Edit/Delete \") | AUTHORITY:  0 (\"\")  > 4 (\" View/Edit/Delete \") | AUTHORITY:  0 (\"\")  > 4 (\" View/Edit/Delete \") | AUTHORITY:  0 (\"\")  > 4 (\" View/Edit/Delete \") | AUTHORITY:  0 (\"\")  > 4 (\" View/Edit/Delete \") | AUTHORITY:  0 (\"\")  > 4 (\" View/Edit/Delete \") | AUTHORITY:  0 (\"\")  > 4 (\" View/Edit/Delete \") | AUTHORITY:  0 (\"\")  > 4 (\" View/Edit/Delete \") | AUTHORITY:  0 (\"\")  > 4 (\" View/Edit/Delete \") | AUTHORITY:  0 (\"\")  > 4 (\" View/Edit/Delete \") | AUTHORITY:  0 (\"\")  > 4 (\" View/Edit/Delete \") | AUTHORITY:  0 (\"\")  > 4 (\" View/Edit/Delete \") | AUTHORITY:  0 (\"\")  > 4 (\" View/Edit/Delete \") | AUTHORITY:  0 (\"\")  > 4 (\" View/Edit/Delete \") | AUTHORITY:  0 (\"\")  > 4 (\" View/Edit/Delete \") | AUTHORITY:  0 (\"\")  > 4 (\" View/Edit/Delete \") | AUTHORITY:  0 (\"\")  > 4 (\" View/Edit/Delete \") | AUTHORITY:  0 (\"\")  > 4 (\" View/Edit/Delete \") | AUTHORITY:  0 (\"\")  > 4 (\" View/Edit/Delete \") | AUTHORITY:  0 (\"\")  > 4 (\" View/Edit/Delete \")','2021-01-11 15:40:31.419261','Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/87.0.4280.141 Safari/537.36'),(31,'49.146.42.127',1,0,3,0,0,10080,82,0,'add/edit Access rights record','LEVEL: 0 (\"\")  >  2 (\" Super Admin \") | MODULE: 0 (\"\")  >  10120 (\" Devices \") | AUTHORITY:  0 (\"\")  > 0 (\" No Access \") | LEVEL: 0 (\"\")  >  2 (\" Super Admin \") | MODULE: 0 (\"\")  >  10160 (\" Brute Force Login Attempt \") | AUTHORITY:  0 (\"\")  > 0 (\" No Access \") | LEVEL: 0 (\"\")  >  2 (\" Super Admin \") | MODULE: 0 (\"\")  >  10180 (\" Bruteforce IP \") | AUTHORITY:  0 (\"\")  > 0 (\" No Access \") | LEVEL: 0 (\"\")  >  2 (\" Super Admin \") | MODULE: 0 (\"\")  >  15010 (\" Addon: Group License \") | AUTHORITY:  0 (\"\")  > 0 (\" No Access \") | LEVEL: 0 (\"\")  >  2 (\" Super Admin \") | MODULE: 0 (\"\")  >  15030 (\" Addon: User License \") | AUTHORITY:  0 (\"\")  > 0 (\" No Access \") | LEVEL: 0 (\"\")  >  2 (\" Super Admin \") | MODULE: 0 (\"\")  >  15050 (\" Addon: Queuing \") | AUTHORITY:  0 (\"\")  > 0 (\" No Access \") | LEVEL: 0 (\"\")  >  2 (\" Super Admin \") | MODULE: 0 (\"\")  >  15070 (\" Addon: Resource \") | AUTHORITY:  0 (\"\")  > 0 (\" No Access \") | LEVEL: 0 (\"\")  >  2 (\" Super Admin \") | MODULE: 0 (\"\")  >  21030 (\" Section \") | AUTHORITY:  0 (\"\")  > 0 (\" No Access \") | LEVEL: 0 (\"\")  >  2 (\" Super Admin \") | MODULE: 0 (\"\")  >  21050 (\" Entrance \") | AUTHORITY:  0 (\"\")  > 0 (\" No Access \") | AUTHORITY:  0 (\"\")  > 4 (\" View/Edit/Delete \") | AUTHORITY:  0 (\"\")  > 4 (\" View/Edit/Delete \") | AUTHORITY:  0 (\"\")  > 4 (\" View/Edit/Delete \") | AUTHORITY:  0 (\"\")  > 4 (\" View/Edit/Delete \") | AUTHORITY:  0 (\"\")  > 4 (\" View/Edit/Delete \") | AUTHORITY:  0 (\"\")  > 4 (\" View/Edit/Delete \") | AUTHORITY:  0 (\"\")  > 4 (\" View/Edit/Delete \") | AUTHORITY:  0 (\"\")  > 4 (\" View/Edit/Delete \") | AUTHORITY:  0 (\"\")  > 4 (\" View/Edit/Delete \") | AUTHORITY:  0 (\"\")  > 4 (\" View/Edit/Delete \") | AUTHORITY:  0 (\"\")  > 4 (\" View/Edit/Delete \") | AUTHORITY:  0 (\"\")  > 4 (\" View/Edit/Delete \") | AUTHORITY:  0 (\"\")  > 4 (\" View/Edit/Delete \") | AUTHORITY:  0 (\"\")  > 4 (\" View/Edit/Delete \") | AUTHORITY:  0 (\"\")  > 4 (\" View/Edit/Delete \") | AUTHORITY:  0 (\"\")  > 4 (\" View/Edit/Delete \") | AUTHORITY:  0 (\"\")  > 4 (\" View/Edit/Delete \") | AUTHORITY:  0 (\"\")  > 4 (\" View/Edit/Delete \") | AUTHORITY:  0 (\"\")  > 4 (\" View/Edit/Delete \") | AUTHORITY:  0 (\"\")  > 4 (\" View/Edit/Delete \") | AUTHORITY:  0 (\"\")  > 4 (\" View/Edit/Delete \") | AUTHORITY:  0 (\"\")  > 4 (\" View/Edit/Delete \")','2021-01-11 15:40:31.425835','Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/87.0.4280.141 Safari/537.36'),(32,'49.146.42.127',1,0,3,0,0,10080,83,0,'add/edit Access rights record','LEVEL: 0 (\"\")  >  2 (\" Super Admin \") | MODULE: 0 (\"\")  >  10120 (\" Devices \") | AUTHORITY:  0 (\"\")  > 0 (\" No Access \") | LEVEL: 0 (\"\")  >  2 (\" Super Admin \") | MODULE: 0 (\"\")  >  10160 (\" Brute Force Login Attempt \") | AUTHORITY:  0 (\"\")  > 0 (\" No Access \") | LEVEL: 0 (\"\")  >  2 (\" Super Admin \") | MODULE: 0 (\"\")  >  10180 (\" Bruteforce IP \") | AUTHORITY:  0 (\"\")  > 0 (\" No Access \") | LEVEL: 0 (\"\")  >  2 (\" Super Admin \") | MODULE: 0 (\"\")  >  15010 (\" Addon: Group License \") | AUTHORITY:  0 (\"\")  > 0 (\" No Access \") | LEVEL: 0 (\"\")  >  2 (\" Super Admin \") | MODULE: 0 (\"\")  >  15030 (\" Addon: User License \") | AUTHORITY:  0 (\"\")  > 0 (\" No Access \") | LEVEL: 0 (\"\")  >  2 (\" Super Admin \") | MODULE: 0 (\"\")  >  15050 (\" Addon: Queuing \") | AUTHORITY:  0 (\"\")  > 0 (\" No Access \") | LEVEL: 0 (\"\")  >  2 (\" Super Admin \") | MODULE: 0 (\"\")  >  15070 (\" Addon: Resource \") | AUTHORITY:  0 (\"\")  > 0 (\" No Access \") | LEVEL: 0 (\"\")  >  2 (\" Super Admin \") | MODULE: 0 (\"\")  >  21030 (\" Section \") | AUTHORITY:  0 (\"\")  > 0 (\" No Access \") | LEVEL: 0 (\"\")  >  2 (\" Super Admin \") | MODULE: 0 (\"\")  >  21050 (\" Entrance \") | AUTHORITY:  0 (\"\")  > 0 (\" No Access \") | AUTHORITY:  0 (\"\")  > 4 (\" View/Edit/Delete \") | AUTHORITY:  0 (\"\")  > 4 (\" View/Edit/Delete \") | AUTHORITY:  0 (\"\")  > 4 (\" View/Edit/Delete \") | AUTHORITY:  0 (\"\")  > 4 (\" View/Edit/Delete \") | AUTHORITY:  0 (\"\")  > 4 (\" View/Edit/Delete \") | AUTHORITY:  0 (\"\")  > 4 (\" View/Edit/Delete \") | AUTHORITY:  0 (\"\")  > 4 (\" View/Edit/Delete \") | AUTHORITY:  0 (\"\")  > 4 (\" View/Edit/Delete \") | AUTHORITY:  0 (\"\")  > 4 (\" View/Edit/Delete \") | AUTHORITY:  0 (\"\")  > 4 (\" View/Edit/Delete \") | AUTHORITY:  0 (\"\")  > 4 (\" View/Edit/Delete \") | AUTHORITY:  0 (\"\")  > 4 (\" View/Edit/Delete \") | AUTHORITY:  0 (\"\")  > 4 (\" View/Edit/Delete \") | AUTHORITY:  0 (\"\")  > 4 (\" View/Edit/Delete \") | AUTHORITY:  0 (\"\")  > 4 (\" View/Edit/Delete \") | AUTHORITY:  0 (\"\")  > 4 (\" View/Edit/Delete \") | AUTHORITY:  0 (\"\")  > 4 (\" View/Edit/Delete \") | AUTHORITY:  0 (\"\")  > 4 (\" View/Edit/Delete \") | AUTHORITY:  0 (\"\")  > 4 (\" View/Edit/Delete \") | AUTHORITY:  0 (\"\")  > 4 (\" View/Edit/Delete \") | AUTHORITY:  0 (\"\")  > 4 (\" View/Edit/Delete \") | AUTHORITY:  0 (\"\")  > 4 (\" View/Edit/Delete \") | AUTHORITY:  0 (\"\")  > 4 (\" View/Edit/Delete \")','2021-01-11 15:40:31.432089','Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/87.0.4280.141 Safari/537.36'),(33,'49.146.42.127',1,0,3,0,0,10080,84,0,'add/edit Access rights record','LEVEL: 0 (\"\")  >  2 (\" Super Admin \") | MODULE: 0 (\"\")  >  10120 (\" Devices \") | AUTHORITY:  0 (\"\")  > 0 (\" No Access \") | LEVEL: 0 (\"\")  >  2 (\" Super Admin \") | MODULE: 0 (\"\")  >  10160 (\" Brute Force Login Attempt \") | AUTHORITY:  0 (\"\")  > 0 (\" No Access \") | LEVEL: 0 (\"\")  >  2 (\" Super Admin \") | MODULE: 0 (\"\")  >  10180 (\" Bruteforce IP \") | AUTHORITY:  0 (\"\")  > 0 (\" No Access \") | LEVEL: 0 (\"\")  >  2 (\" Super Admin \") | MODULE: 0 (\"\")  >  15010 (\" Addon: Group License \") | AUTHORITY:  0 (\"\")  > 0 (\" No Access \") | LEVEL: 0 (\"\")  >  2 (\" Super Admin \") | MODULE: 0 (\"\")  >  15030 (\" Addon: User License \") | AUTHORITY:  0 (\"\")  > 0 (\" No Access \") | LEVEL: 0 (\"\")  >  2 (\" Super Admin \") | MODULE: 0 (\"\")  >  15050 (\" Addon: Queuing \") | AUTHORITY:  0 (\"\")  > 0 (\" No Access \") | LEVEL: 0 (\"\")  >  2 (\" Super Admin \") | MODULE: 0 (\"\")  >  15070 (\" Addon: Resource \") | AUTHORITY:  0 (\"\")  > 0 (\" No Access \") | LEVEL: 0 (\"\")  >  2 (\" Super Admin \") | MODULE: 0 (\"\")  >  21030 (\" Section \") | AUTHORITY:  0 (\"\")  > 0 (\" No Access \") | LEVEL: 0 (\"\")  >  2 (\" Super Admin \") | MODULE: 0 (\"\")  >  21050 (\" Entrance \") | AUTHORITY:  0 (\"\")  > 0 (\" No Access \") | AUTHORITY:  0 (\"\")  > 4 (\" View/Edit/Delete \") | AUTHORITY:  0 (\"\")  > 4 (\" View/Edit/Delete \") | AUTHORITY:  0 (\"\")  > 4 (\" View/Edit/Delete \") | AUTHORITY:  0 (\"\")  > 4 (\" View/Edit/Delete \") | AUTHORITY:  0 (\"\")  > 4 (\" View/Edit/Delete \") | AUTHORITY:  0 (\"\")  > 4 (\" View/Edit/Delete \") | AUTHORITY:  0 (\"\")  > 4 (\" View/Edit/Delete \") | AUTHORITY:  0 (\"\")  > 4 (\" View/Edit/Delete \") | AUTHORITY:  0 (\"\")  > 4 (\" View/Edit/Delete \") | AUTHORITY:  0 (\"\")  > 4 (\" View/Edit/Delete \") | AUTHORITY:  0 (\"\")  > 4 (\" View/Edit/Delete \") | AUTHORITY:  0 (\"\")  > 4 (\" View/Edit/Delete \") | AUTHORITY:  0 (\"\")  > 4 (\" View/Edit/Delete \") | AUTHORITY:  0 (\"\")  > 4 (\" View/Edit/Delete \") | AUTHORITY:  0 (\"\")  > 4 (\" View/Edit/Delete \") | AUTHORITY:  0 (\"\")  > 4 (\" View/Edit/Delete \") | AUTHORITY:  0 (\"\")  > 4 (\" View/Edit/Delete \") | AUTHORITY:  0 (\"\")  > 4 (\" View/Edit/Delete \") | AUTHORITY:  0 (\"\")  > 4 (\" View/Edit/Delete \") | AUTHORITY:  0 (\"\")  > 4 (\" View/Edit/Delete \") | AUTHORITY:  0 (\"\")  > 4 (\" View/Edit/Delete \") | AUTHORITY:  0 (\"\")  > 4 (\" View/Edit/Delete \") | AUTHORITY:  0 (\"\")  > 4 (\" View/Edit/Delete \") | AUTHORITY:  0 (\"\")  > 4 (\" View/Edit/Delete \")','2021-01-11 15:40:31.438104','Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/87.0.4280.141 Safari/537.36'),(34,'49.146.42.127',1,0,3,0,0,10080,85,0,'add/edit Access rights record','LEVEL: 0 (\"\")  >  2 (\" Super Admin \") | MODULE: 0 (\"\")  >  10120 (\" Devices \") | AUTHORITY:  0 (\"\")  > 0 (\" No Access \") | LEVEL: 0 (\"\")  >  2 (\" Super Admin \") | MODULE: 0 (\"\")  >  10160 (\" Brute Force Login Attempt \") | AUTHORITY:  0 (\"\")  > 0 (\" No Access \") | LEVEL: 0 (\"\")  >  2 (\" Super Admin \") | MODULE: 0 (\"\")  >  10180 (\" Bruteforce IP \") | AUTHORITY:  0 (\"\")  > 0 (\" No Access \") | LEVEL: 0 (\"\")  >  2 (\" Super Admin \") | MODULE: 0 (\"\")  >  15010 (\" Addon: Group License \") | AUTHORITY:  0 (\"\")  > 0 (\" No Access \") | LEVEL: 0 (\"\")  >  2 (\" Super Admin \") | MODULE: 0 (\"\")  >  15030 (\" Addon: User License \") | AUTHORITY:  0 (\"\")  > 0 (\" No Access \") | LEVEL: 0 (\"\")  >  2 (\" Super Admin \") | MODULE: 0 (\"\")  >  15050 (\" Addon: Queuing \") | AUTHORITY:  0 (\"\")  > 0 (\" No Access \") | LEVEL: 0 (\"\")  >  2 (\" Super Admin \") | MODULE: 0 (\"\")  >  15070 (\" Addon: Resource \") | AUTHORITY:  0 (\"\")  > 0 (\" No Access \") | LEVEL: 0 (\"\")  >  2 (\" Super Admin \") | MODULE: 0 (\"\")  >  21030 (\" Section \") | AUTHORITY:  0 (\"\")  > 0 (\" No Access \") | LEVEL: 0 (\"\")  >  2 (\" Super Admin \") | MODULE: 0 (\"\")  >  21050 (\" Entrance \") | AUTHORITY:  0 (\"\")  > 0 (\" No Access \") | AUTHORITY:  0 (\"\")  > 4 (\" View/Edit/Delete \") | AUTHORITY:  0 (\"\")  > 4 (\" View/Edit/Delete \") | AUTHORITY:  0 (\"\")  > 4 (\" View/Edit/Delete \") | AUTHORITY:  0 (\"\")  > 4 (\" View/Edit/Delete \") | AUTHORITY:  0 (\"\")  > 4 (\" View/Edit/Delete \") | AUTHORITY:  0 (\"\")  > 4 (\" View/Edit/Delete \") | AUTHORITY:  0 (\"\")  > 4 (\" View/Edit/Delete \") | AUTHORITY:  0 (\"\")  > 4 (\" View/Edit/Delete \") | AUTHORITY:  0 (\"\")  > 4 (\" View/Edit/Delete \") | AUTHORITY:  0 (\"\")  > 4 (\" View/Edit/Delete \") | AUTHORITY:  0 (\"\")  > 4 (\" View/Edit/Delete \") | AUTHORITY:  0 (\"\")  > 4 (\" View/Edit/Delete \") | AUTHORITY:  0 (\"\")  > 4 (\" View/Edit/Delete \") | AUTHORITY:  0 (\"\")  > 4 (\" View/Edit/Delete \") | AUTHORITY:  0 (\"\")  > 4 (\" View/Edit/Delete \") | AUTHORITY:  0 (\"\")  > 4 (\" View/Edit/Delete \") | AUTHORITY:  0 (\"\")  > 4 (\" View/Edit/Delete \") | AUTHORITY:  0 (\"\")  > 4 (\" View/Edit/Delete \") | AUTHORITY:  0 (\"\")  > 4 (\" View/Edit/Delete \") | AUTHORITY:  0 (\"\")  > 4 (\" View/Edit/Delete \") | AUTHORITY:  0 (\"\")  > 4 (\" View/Edit/Delete \") | AUTHORITY:  0 (\"\")  > 4 (\" View/Edit/Delete \") | AUTHORITY:  0 (\"\")  > 4 (\" View/Edit/Delete \") | AUTHORITY:  0 (\"\")  > 4 (\" View/Edit/Delete \") | AUTHORITY:  0 (\"\")  > 4 (\" View/Edit/Delete \")','2021-01-11 15:40:31.443825','Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/87.0.4280.141 Safari/537.36'),(35,'49.146.42.127',1,0,3,0,0,10080,86,0,'add/edit Access rights record','LEVEL: 0 (\"\")  >  2 (\" Super Admin \") | MODULE: 0 (\"\")  >  10120 (\" Devices \") | AUTHORITY:  0 (\"\")  > 0 (\" No Access \") | LEVEL: 0 (\"\")  >  2 (\" Super Admin \") | MODULE: 0 (\"\")  >  10160 (\" Brute Force Login Attempt \") | AUTHORITY:  0 (\"\")  > 0 (\" No Access \") | LEVEL: 0 (\"\")  >  2 (\" Super Admin \") | MODULE: 0 (\"\")  >  10180 (\" Bruteforce IP \") | AUTHORITY:  0 (\"\")  > 0 (\" No Access \") | LEVEL: 0 (\"\")  >  2 (\" Super Admin \") | MODULE: 0 (\"\")  >  15010 (\" Addon: Group License \") | AUTHORITY:  0 (\"\")  > 0 (\" No Access \") | LEVEL: 0 (\"\")  >  2 (\" Super Admin \") | MODULE: 0 (\"\")  >  15030 (\" Addon: User License \") | AUTHORITY:  0 (\"\")  > 0 (\" No Access \") | LEVEL: 0 (\"\")  >  2 (\" Super Admin \") | MODULE: 0 (\"\")  >  15050 (\" Addon: Queuing \") | AUTHORITY:  0 (\"\")  > 0 (\" No Access \") | LEVEL: 0 (\"\")  >  2 (\" Super Admin \") | MODULE: 0 (\"\")  >  15070 (\" Addon: Resource \") | AUTHORITY:  0 (\"\")  > 0 (\" No Access \") | LEVEL: 0 (\"\")  >  2 (\" Super Admin \") | MODULE: 0 (\"\")  >  21030 (\" Section \") | AUTHORITY:  0 (\"\")  > 0 (\" No Access \") | LEVEL: 0 (\"\")  >  2 (\" Super Admin \") | MODULE: 0 (\"\")  >  21050 (\" Entrance \") | AUTHORITY:  0 (\"\")  > 0 (\" No Access \") | AUTHORITY:  0 (\"\")  > 4 (\" View/Edit/Delete \") | AUTHORITY:  0 (\"\")  > 4 (\" View/Edit/Delete \") | AUTHORITY:  0 (\"\")  > 4 (\" View/Edit/Delete \") | AUTHORITY:  0 (\"\")  > 4 (\" View/Edit/Delete \") | AUTHORITY:  0 (\"\")  > 4 (\" View/Edit/Delete \") | AUTHORITY:  0 (\"\")  > 4 (\" View/Edit/Delete \") | AUTHORITY:  0 (\"\")  > 4 (\" View/Edit/Delete \") | AUTHORITY:  0 (\"\")  > 4 (\" View/Edit/Delete \") | AUTHORITY:  0 (\"\")  > 4 (\" View/Edit/Delete \") | AUTHORITY:  0 (\"\")  > 4 (\" View/Edit/Delete \") | AUTHORITY:  0 (\"\")  > 4 (\" View/Edit/Delete \") | AUTHORITY:  0 (\"\")  > 4 (\" View/Edit/Delete \") | AUTHORITY:  0 (\"\")  > 4 (\" View/Edit/Delete \") | AUTHORITY:  0 (\"\")  > 4 (\" View/Edit/Delete \") | AUTHORITY:  0 (\"\")  > 4 (\" View/Edit/Delete \") | AUTHORITY:  0 (\"\")  > 4 (\" View/Edit/Delete \") | AUTHORITY:  0 (\"\")  > 4 (\" View/Edit/Delete \") | AUTHORITY:  0 (\"\")  > 4 (\" View/Edit/Delete \") | AUTHORITY:  0 (\"\")  > 4 (\" View/Edit/Delete \") | AUTHORITY:  0 (\"\")  > 4 (\" View/Edit/Delete \") | AUTHORITY:  0 (\"\")  > 4 (\" View/Edit/Delete \") | AUTHORITY:  0 (\"\")  > 4 (\" View/Edit/Delete \") | AUTHORITY:  0 (\"\")  > 4 (\" View/Edit/Delete \") | AUTHORITY:  0 (\"\")  > 4 (\" View/Edit/Delete \") | AUTHORITY:  0 (\"\")  > 4 (\" View/Edit/Delete \") | AUTHORITY:  0 (\"\")  > 4 (\" View/Edit/Delete \")','2021-01-11 15:40:31.450351','Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/87.0.4280.141 Safari/537.36'),(36,'49.146.42.127',1,0,3,0,0,10080,87,0,'add/edit Access rights record','LEVEL: 0 (\"\")  >  2 (\" Super Admin \") | MODULE: 0 (\"\")  >  10120 (\" Devices \") | AUTHORITY:  0 (\"\")  > 0 (\" No Access \") | LEVEL: 0 (\"\")  >  2 (\" Super Admin \") | MODULE: 0 (\"\")  >  10160 (\" Brute Force Login Attempt \") | AUTHORITY:  0 (\"\")  > 0 (\" No Access \") | LEVEL: 0 (\"\")  >  2 (\" Super Admin \") | MODULE: 0 (\"\")  >  10180 (\" Bruteforce IP \") | AUTHORITY:  0 (\"\")  > 0 (\" No Access \") | LEVEL: 0 (\"\")  >  2 (\" Super Admin \") | MODULE: 0 (\"\")  >  15010 (\" Addon: Group License \") | AUTHORITY:  0 (\"\")  > 0 (\" No Access \") | LEVEL: 0 (\"\")  >  2 (\" Super Admin \") | MODULE: 0 (\"\")  >  15030 (\" Addon: User License \") | AUTHORITY:  0 (\"\")  > 0 (\" No Access \") | LEVEL: 0 (\"\")  >  2 (\" Super Admin \") | MODULE: 0 (\"\")  >  15050 (\" Addon: Queuing \") | AUTHORITY:  0 (\"\")  > 0 (\" No Access \") | LEVEL: 0 (\"\")  >  2 (\" Super Admin \") | MODULE: 0 (\"\")  >  15070 (\" Addon: Resource \") | AUTHORITY:  0 (\"\")  > 0 (\" No Access \") | LEVEL: 0 (\"\")  >  2 (\" Super Admin \") | MODULE: 0 (\"\")  >  21030 (\" Section \") | AUTHORITY:  0 (\"\")  > 0 (\" No Access \") | LEVEL: 0 (\"\")  >  2 (\" Super Admin \") | MODULE: 0 (\"\")  >  21050 (\" Entrance \") | AUTHORITY:  0 (\"\")  > 0 (\" No Access \") | AUTHORITY:  0 (\"\")  > 4 (\" View/Edit/Delete \") | AUTHORITY:  0 (\"\")  > 4 (\" View/Edit/Delete \") | AUTHORITY:  0 (\"\")  > 4 (\" View/Edit/Delete \") | AUTHORITY:  0 (\"\")  > 4 (\" View/Edit/Delete \") | AUTHORITY:  0 (\"\")  > 4 (\" View/Edit/Delete \") | AUTHORITY:  0 (\"\")  > 4 (\" View/Edit/Delete \") | AUTHORITY:  0 (\"\")  > 4 (\" View/Edit/Delete \") | AUTHORITY:  0 (\"\")  > 4 (\" View/Edit/Delete \") | AUTHORITY:  0 (\"\")  > 4 (\" View/Edit/Delete \") | AUTHORITY:  0 (\"\")  > 4 (\" View/Edit/Delete \") | AUTHORITY:  0 (\"\")  > 4 (\" View/Edit/Delete \") | AUTHORITY:  0 (\"\")  > 4 (\" View/Edit/Delete \") | AUTHORITY:  0 (\"\")  > 4 (\" View/Edit/Delete \") | AUTHORITY:  0 (\"\")  > 4 (\" View/Edit/Delete \") | AUTHORITY:  0 (\"\")  > 4 (\" View/Edit/Delete \") | AUTHORITY:  0 (\"\")  > 4 (\" View/Edit/Delete \") | AUTHORITY:  0 (\"\")  > 4 (\" View/Edit/Delete \") | AUTHORITY:  0 (\"\")  > 4 (\" View/Edit/Delete \") | AUTHORITY:  0 (\"\")  > 4 (\" View/Edit/Delete \") | AUTHORITY:  0 (\"\")  > 4 (\" View/Edit/Delete \") | AUTHORITY:  0 (\"\")  > 4 (\" View/Edit/Delete \") | AUTHORITY:  0 (\"\")  > 4 (\" View/Edit/Delete \") | AUTHORITY:  0 (\"\")  > 4 (\" View/Edit/Delete \") | AUTHORITY:  0 (\"\")  > 4 (\" View/Edit/Delete \") | AUTHORITY:  0 (\"\")  > 4 (\" View/Edit/Delete \") | AUTHORITY:  0 (\"\")  > 4 (\" View/Edit/Delete \") | AUTHORITY:  0 (\"\")  > 4 (\" View/Edit/Delete \")','2021-01-11 15:40:31.457543','Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/87.0.4280.141 Safari/537.36'),(37,'49.146.42.127',1,0,3,0,0,10080,88,0,'add/edit Access rights record','LEVEL: 0 (\"\")  >  2 (\" Super Admin \") | MODULE: 0 (\"\")  >  10120 (\" Devices \") | AUTHORITY:  0 (\"\")  > 0 (\" No Access \") | LEVEL: 0 (\"\")  >  2 (\" Super Admin \") | MODULE: 0 (\"\")  >  10160 (\" Brute Force Login Attempt \") | AUTHORITY:  0 (\"\")  > 0 (\" No Access \") | LEVEL: 0 (\"\")  >  2 (\" Super Admin \") | MODULE: 0 (\"\")  >  10180 (\" Bruteforce IP \") | AUTHORITY:  0 (\"\")  > 0 (\" No Access \") | LEVEL: 0 (\"\")  >  2 (\" Super Admin \") | MODULE: 0 (\"\")  >  15010 (\" Addon: Group License \") | AUTHORITY:  0 (\"\")  > 0 (\" No Access \") | LEVEL: 0 (\"\")  >  2 (\" Super Admin \") | MODULE: 0 (\"\")  >  15030 (\" Addon: User License \") | AUTHORITY:  0 (\"\")  > 0 (\" No Access \") | LEVEL: 0 (\"\")  >  2 (\" Super Admin \") | MODULE: 0 (\"\")  >  15050 (\" Addon: Queuing \") | AUTHORITY:  0 (\"\")  > 0 (\" No Access \") | LEVEL: 0 (\"\")  >  2 (\" Super Admin \") | MODULE: 0 (\"\")  >  15070 (\" Addon: Resource \") | AUTHORITY:  0 (\"\")  > 0 (\" No Access \") | LEVEL: 0 (\"\")  >  2 (\" Super Admin \") | MODULE: 0 (\"\")  >  21030 (\" Section \") | AUTHORITY:  0 (\"\")  > 0 (\" No Access \") | LEVEL: 0 (\"\")  >  2 (\" Super Admin \") | MODULE: 0 (\"\")  >  21050 (\" Entrance \") | AUTHORITY:  0 (\"\")  > 0 (\" No Access \") | AUTHORITY:  0 (\"\")  > 4 (\" View/Edit/Delete \") | AUTHORITY:  0 (\"\")  > 4 (\" View/Edit/Delete \") | AUTHORITY:  0 (\"\")  > 4 (\" View/Edit/Delete \") | AUTHORITY:  0 (\"\")  > 4 (\" View/Edit/Delete \") | AUTHORITY:  0 (\"\")  > 4 (\" View/Edit/Delete \") | AUTHORITY:  0 (\"\")  > 4 (\" View/Edit/Delete \") | AUTHORITY:  0 (\"\")  > 4 (\" View/Edit/Delete \") | AUTHORITY:  0 (\"\")  > 4 (\" View/Edit/Delete \") | AUTHORITY:  0 (\"\")  > 4 (\" View/Edit/Delete \") | AUTHORITY:  0 (\"\")  > 4 (\" View/Edit/Delete \") | AUTHORITY:  0 (\"\")  > 4 (\" View/Edit/Delete \") | AUTHORITY:  0 (\"\")  > 4 (\" View/Edit/Delete \") | AUTHORITY:  0 (\"\")  > 4 (\" View/Edit/Delete \") | AUTHORITY:  0 (\"\")  > 4 (\" View/Edit/Delete \") | AUTHORITY:  0 (\"\")  > 4 (\" View/Edit/Delete \") | AUTHORITY:  0 (\"\")  > 4 (\" View/Edit/Delete \") | AUTHORITY:  0 (\"\")  > 4 (\" View/Edit/Delete \") | AUTHORITY:  0 (\"\")  > 4 (\" View/Edit/Delete \") | AUTHORITY:  0 (\"\")  > 4 (\" View/Edit/Delete \") | AUTHORITY:  0 (\"\")  > 4 (\" View/Edit/Delete \") | AUTHORITY:  0 (\"\")  > 4 (\" View/Edit/Delete \") | AUTHORITY:  0 (\"\")  > 4 (\" View/Edit/Delete \") | AUTHORITY:  0 (\"\")  > 4 (\" View/Edit/Delete \") | AUTHORITY:  0 (\"\")  > 4 (\" View/Edit/Delete \") | AUTHORITY:  0 (\"\")  > 4 (\" View/Edit/Delete \") | AUTHORITY:  0 (\"\")  > 4 (\" View/Edit/Delete \") | AUTHORITY:  0 (\"\")  > 4 (\" View/Edit/Delete \") | AUTHORITY:  0 (\"\")  > 4 (\" View/Edit/Delete \")','2021-01-11 15:40:31.463327','Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/87.0.4280.141 Safari/537.36'),(38,'49.146.42.127',1,0,3,0,0,10080,89,0,'add/edit Access rights record','LEVEL: 0 (\"\")  >  2 (\" Super Admin \") | MODULE: 0 (\"\")  >  10120 (\" Devices \") | AUTHORITY:  0 (\"\")  > 0 (\" No Access \") | LEVEL: 0 (\"\")  >  2 (\" Super Admin \") | MODULE: 0 (\"\")  >  10160 (\" Brute Force Login Attempt \") | AUTHORITY:  0 (\"\")  > 0 (\" No Access \") | LEVEL: 0 (\"\")  >  2 (\" Super Admin \") | MODULE: 0 (\"\")  >  10180 (\" Bruteforce IP \") | AUTHORITY:  0 (\"\")  > 0 (\" No Access \") | LEVEL: 0 (\"\")  >  2 (\" Super Admin \") | MODULE: 0 (\"\")  >  15010 (\" Addon: Group License \") | AUTHORITY:  0 (\"\")  > 0 (\" No Access \") | LEVEL: 0 (\"\")  >  2 (\" Super Admin \") | MODULE: 0 (\"\")  >  15030 (\" Addon: User License \") | AUTHORITY:  0 (\"\")  > 0 (\" No Access \") | LEVEL: 0 (\"\")  >  2 (\" Super Admin \") | MODULE: 0 (\"\")  >  15050 (\" Addon: Queuing \") | AUTHORITY:  0 (\"\")  > 0 (\" No Access \") | LEVEL: 0 (\"\")  >  2 (\" Super Admin \") | MODULE: 0 (\"\")  >  15070 (\" Addon: Resource \") | AUTHORITY:  0 (\"\")  > 0 (\" No Access \") | LEVEL: 0 (\"\")  >  2 (\" Super Admin \") | MODULE: 0 (\"\")  >  21030 (\" Section \") | AUTHORITY:  0 (\"\")  > 0 (\" No Access \") | LEVEL: 0 (\"\")  >  2 (\" Super Admin \") | MODULE: 0 (\"\")  >  21050 (\" Entrance \") | AUTHORITY:  0 (\"\")  > 0 (\" No Access \") | AUTHORITY:  0 (\"\")  > 4 (\" View/Edit/Delete \") | AUTHORITY:  0 (\"\")  > 4 (\" View/Edit/Delete \") | AUTHORITY:  0 (\"\")  > 4 (\" View/Edit/Delete \") | AUTHORITY:  0 (\"\")  > 4 (\" View/Edit/Delete \") | AUTHORITY:  0 (\"\")  > 4 (\" View/Edit/Delete \") | AUTHORITY:  0 (\"\")  > 4 (\" View/Edit/Delete \") | AUTHORITY:  0 (\"\")  > 4 (\" View/Edit/Delete \") | AUTHORITY:  0 (\"\")  > 4 (\" View/Edit/Delete \") | AUTHORITY:  0 (\"\")  > 4 (\" View/Edit/Delete \") | AUTHORITY:  0 (\"\")  > 4 (\" View/Edit/Delete \") | AUTHORITY:  0 (\"\")  > 4 (\" View/Edit/Delete \") | AUTHORITY:  0 (\"\")  > 4 (\" View/Edit/Delete \") | AUTHORITY:  0 (\"\")  > 4 (\" View/Edit/Delete \") | AUTHORITY:  0 (\"\")  > 4 (\" View/Edit/Delete \") | AUTHORITY:  0 (\"\")  > 4 (\" View/Edit/Delete \") | AUTHORITY:  0 (\"\")  > 4 (\" View/Edit/Delete \") | AUTHORITY:  0 (\"\")  > 4 (\" View/Edit/Delete \") | AUTHORITY:  0 (\"\")  > 4 (\" View/Edit/Delete \") | AUTHORITY:  0 (\"\")  > 4 (\" View/Edit/Delete \") | AUTHORITY:  0 (\"\")  > 4 (\" View/Edit/Delete \") | AUTHORITY:  0 (\"\")  > 4 (\" View/Edit/Delete \") | AUTHORITY:  0 (\"\")  > 4 (\" View/Edit/Delete \") | AUTHORITY:  0 (\"\")  > 4 (\" View/Edit/Delete \") | AUTHORITY:  0 (\"\")  > 4 (\" View/Edit/Delete \") | AUTHORITY:  0 (\"\")  > 4 (\" View/Edit/Delete \") | AUTHORITY:  0 (\"\")  > 4 (\" View/Edit/Delete \") | AUTHORITY:  0 (\"\")  > 4 (\" View/Edit/Delete \") | AUTHORITY:  0 (\"\")  > 4 (\" View/Edit/Delete \") | AUTHORITY:  0 (\"\")  > 4 (\" View/Edit/Delete \")','2021-01-11 15:40:31.469202','Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/87.0.4280.141 Safari/537.36'),(39,'49.146.42.127',1,0,3,0,0,10080,90,0,'add/edit Access rights record','LEVEL: 0 (\"\")  >  2 (\" Super Admin \") | MODULE: 0 (\"\")  >  10120 (\" Devices \") | AUTHORITY:  0 (\"\")  > 0 (\" No Access \") | LEVEL: 0 (\"\")  >  2 (\" Super Admin \") | MODULE: 0 (\"\")  >  10160 (\" Brute Force Login Attempt \") | AUTHORITY:  0 (\"\")  > 0 (\" No Access \") | LEVEL: 0 (\"\")  >  2 (\" Super Admin \") | MODULE: 0 (\"\")  >  10180 (\" Bruteforce IP \") | AUTHORITY:  0 (\"\")  > 0 (\" No Access \") | LEVEL: 0 (\"\")  >  2 (\" Super Admin \") | MODULE: 0 (\"\")  >  15010 (\" Addon: Group License \") | AUTHORITY:  0 (\"\")  > 0 (\" No Access \") | LEVEL: 0 (\"\")  >  2 (\" Super Admin \") | MODULE: 0 (\"\")  >  15030 (\" Addon: User License \") | AUTHORITY:  0 (\"\")  > 0 (\" No Access \") | LEVEL: 0 (\"\")  >  2 (\" Super Admin \") | MODULE: 0 (\"\")  >  15050 (\" Addon: Queuing \") | AUTHORITY:  0 (\"\")  > 0 (\" No Access \") | LEVEL: 0 (\"\")  >  2 (\" Super Admin \") | MODULE: 0 (\"\")  >  15070 (\" Addon: Resource \") | AUTHORITY:  0 (\"\")  > 0 (\" No Access \") | LEVEL: 0 (\"\")  >  2 (\" Super Admin \") | MODULE: 0 (\"\")  >  21030 (\" Section \") | AUTHORITY:  0 (\"\")  > 0 (\" No Access \") | LEVEL: 0 (\"\")  >  2 (\" Super Admin \") | MODULE: 0 (\"\")  >  21050 (\" Entrance \") | AUTHORITY:  0 (\"\")  > 0 (\" No Access \") | AUTHORITY:  0 (\"\")  > 4 (\" View/Edit/Delete \") | AUTHORITY:  0 (\"\")  > 4 (\" View/Edit/Delete \") | AUTHORITY:  0 (\"\")  > 4 (\" View/Edit/Delete \") | AUTHORITY:  0 (\"\")  > 4 (\" View/Edit/Delete \") | AUTHORITY:  0 (\"\")  > 4 (\" View/Edit/Delete \") | AUTHORITY:  0 (\"\")  > 4 (\" View/Edit/Delete \") | AUTHORITY:  0 (\"\")  > 4 (\" View/Edit/Delete \") | AUTHORITY:  0 (\"\")  > 4 (\" View/Edit/Delete \") | AUTHORITY:  0 (\"\")  > 4 (\" View/Edit/Delete \") | AUTHORITY:  0 (\"\")  > 4 (\" View/Edit/Delete \") | AUTHORITY:  0 (\"\")  > 4 (\" View/Edit/Delete \") | AUTHORITY:  0 (\"\")  > 4 (\" View/Edit/Delete \") | AUTHORITY:  0 (\"\")  > 4 (\" View/Edit/Delete \") | AUTHORITY:  0 (\"\")  > 4 (\" View/Edit/Delete \") | AUTHORITY:  0 (\"\")  > 4 (\" View/Edit/Delete \") | AUTHORITY:  0 (\"\")  > 4 (\" View/Edit/Delete \") | AUTHORITY:  0 (\"\")  > 4 (\" View/Edit/Delete \") | AUTHORITY:  0 (\"\")  > 4 (\" View/Edit/Delete \") | AUTHORITY:  0 (\"\")  > 4 (\" View/Edit/Delete \") | AUTHORITY:  0 (\"\")  > 4 (\" View/Edit/Delete \") | AUTHORITY:  0 (\"\")  > 4 (\" View/Edit/Delete \") | AUTHORITY:  0 (\"\")  > 4 (\" View/Edit/Delete \") | AUTHORITY:  0 (\"\")  > 4 (\" View/Edit/Delete \") | AUTHORITY:  0 (\"\")  > 4 (\" View/Edit/Delete \") | AUTHORITY:  0 (\"\")  > 4 (\" View/Edit/Delete \") | AUTHORITY:  0 (\"\")  > 4 (\" View/Edit/Delete \") | AUTHORITY:  0 (\"\")  > 4 (\" View/Edit/Delete \") | AUTHORITY:  0 (\"\")  > 4 (\" View/Edit/Delete \") | AUTHORITY:  0 (\"\")  > 4 (\" View/Edit/Delete \") | AUTHORITY:  0 (\"\")  > 4 (\" View/Edit/Delete \")','2021-01-11 15:40:31.473877','Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/87.0.4280.141 Safari/537.36'),(40,'49.146.42.127',1,0,3,0,0,10080,91,0,'add/edit Access rights record','LEVEL: 0 (\"\")  >  2 (\" Super Admin \") | MODULE: 0 (\"\")  >  10120 (\" Devices \") | AUTHORITY:  0 (\"\")  > 0 (\" No Access \") | LEVEL: 0 (\"\")  >  2 (\" Super Admin \") | MODULE: 0 (\"\")  >  10160 (\" Brute Force Login Attempt \") | AUTHORITY:  0 (\"\")  > 0 (\" No Access \") | LEVEL: 0 (\"\")  >  2 (\" Super Admin \") | MODULE: 0 (\"\")  >  10180 (\" Bruteforce IP \") | AUTHORITY:  0 (\"\")  > 0 (\" No Access \") | LEVEL: 0 (\"\")  >  2 (\" Super Admin \") | MODULE: 0 (\"\")  >  15010 (\" Addon: Group License \") | AUTHORITY:  0 (\"\")  > 0 (\" No Access \") | LEVEL: 0 (\"\")  >  2 (\" Super Admin \") | MODULE: 0 (\"\")  >  15030 (\" Addon: User License \") | AUTHORITY:  0 (\"\")  > 0 (\" No Access \") | LEVEL: 0 (\"\")  >  2 (\" Super Admin \") | MODULE: 0 (\"\")  >  15050 (\" Addon: Queuing \") | AUTHORITY:  0 (\"\")  > 0 (\" No Access \") | LEVEL: 0 (\"\")  >  2 (\" Super Admin \") | MODULE: 0 (\"\")  >  15070 (\" Addon: Resource \") | AUTHORITY:  0 (\"\")  > 0 (\" No Access \") | LEVEL: 0 (\"\")  >  2 (\" Super Admin \") | MODULE: 0 (\"\")  >  21030 (\" Section \") | AUTHORITY:  0 (\"\")  > 0 (\" No Access \") | LEVEL: 0 (\"\")  >  2 (\" Super Admin \") | MODULE: 0 (\"\")  >  21050 (\" Entrance \") | AUTHORITY:  0 (\"\")  > 0 (\" No Access \") | AUTHORITY:  0 (\"\")  > 4 (\" View/Edit/Delete \") | AUTHORITY:  0 (\"\")  > 4 (\" View/Edit/Delete \") | AUTHORITY:  0 (\"\")  > 4 (\" View/Edit/Delete \") | AUTHORITY:  0 (\"\")  > 4 (\" View/Edit/Delete \") | AUTHORITY:  0 (\"\")  > 4 (\" View/Edit/Delete \") | AUTHORITY:  0 (\"\")  > 4 (\" View/Edit/Delete \") | AUTHORITY:  0 (\"\")  > 4 (\" View/Edit/Delete \") | AUTHORITY:  0 (\"\")  > 4 (\" View/Edit/Delete \") | AUTHORITY:  0 (\"\")  > 4 (\" View/Edit/Delete \") | AUTHORITY:  0 (\"\")  > 4 (\" View/Edit/Delete \") | AUTHORITY:  0 (\"\")  > 4 (\" View/Edit/Delete \") | AUTHORITY:  0 (\"\")  > 4 (\" View/Edit/Delete \") | AUTHORITY:  0 (\"\")  > 4 (\" View/Edit/Delete \") | AUTHORITY:  0 (\"\")  > 4 (\" View/Edit/Delete \") | AUTHORITY:  0 (\"\")  > 4 (\" View/Edit/Delete \") | AUTHORITY:  0 (\"\")  > 4 (\" View/Edit/Delete \") | AUTHORITY:  0 (\"\")  > 4 (\" View/Edit/Delete \") | AUTHORITY:  0 (\"\")  > 4 (\" View/Edit/Delete \") | AUTHORITY:  0 (\"\")  > 4 (\" View/Edit/Delete \") | AUTHORITY:  0 (\"\")  > 4 (\" View/Edit/Delete \") | AUTHORITY:  0 (\"\")  > 4 (\" View/Edit/Delete \") | AUTHORITY:  0 (\"\")  > 4 (\" View/Edit/Delete \") | AUTHORITY:  0 (\"\")  > 4 (\" View/Edit/Delete \") | AUTHORITY:  0 (\"\")  > 4 (\" View/Edit/Delete \") | AUTHORITY:  0 (\"\")  > 4 (\" View/Edit/Delete \") | AUTHORITY:  0 (\"\")  > 4 (\" View/Edit/Delete \") | AUTHORITY:  0 (\"\")  > 4 (\" View/Edit/Delete \") | AUTHORITY:  0 (\"\")  > 4 (\" View/Edit/Delete \") | AUTHORITY:  0 (\"\")  > 4 (\" View/Edit/Delete \") | AUTHORITY:  0 (\"\")  > 4 (\" View/Edit/Delete \") | AUTHORITY:  0 (\"\")  > 4 (\" View/Edit/Delete \")','2021-01-11 15:40:31.478278','Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/87.0.4280.141 Safari/537.36'),(41,'49.146.42.127',1,0,3,0,0,10080,92,0,'add/edit Access rights record','LEVEL: 0 (\"\")  >  2 (\" Super Admin \") | MODULE: 0 (\"\")  >  10120 (\" Devices \") | AUTHORITY:  0 (\"\")  > 0 (\" No Access \") | LEVEL: 0 (\"\")  >  2 (\" Super Admin \") | MODULE: 0 (\"\")  >  10160 (\" Brute Force Login Attempt \") | AUTHORITY:  0 (\"\")  > 0 (\" No Access \") | LEVEL: 0 (\"\")  >  2 (\" Super Admin \") | MODULE: 0 (\"\")  >  10180 (\" Bruteforce IP \") | AUTHORITY:  0 (\"\")  > 0 (\" No Access \") | LEVEL: 0 (\"\")  >  2 (\" Super Admin \") | MODULE: 0 (\"\")  >  15010 (\" Addon: Group License \") | AUTHORITY:  0 (\"\")  > 0 (\" No Access \") | LEVEL: 0 (\"\")  >  2 (\" Super Admin \") | MODULE: 0 (\"\")  >  15030 (\" Addon: User License \") | AUTHORITY:  0 (\"\")  > 0 (\" No Access \") | LEVEL: 0 (\"\")  >  2 (\" Super Admin \") | MODULE: 0 (\"\")  >  15050 (\" Addon: Queuing \") | AUTHORITY:  0 (\"\")  > 0 (\" No Access \") | LEVEL: 0 (\"\")  >  2 (\" Super Admin \") | MODULE: 0 (\"\")  >  15070 (\" Addon: Resource \") | AUTHORITY:  0 (\"\")  > 0 (\" No Access \") | LEVEL: 0 (\"\")  >  2 (\" Super Admin \") | MODULE: 0 (\"\")  >  21030 (\" Section \") | AUTHORITY:  0 (\"\")  > 0 (\" No Access \") | LEVEL: 0 (\"\")  >  2 (\" Super Admin \") | MODULE: 0 (\"\")  >  21050 (\" Entrance \") | AUTHORITY:  0 (\"\")  > 0 (\" No Access \") | AUTHORITY:  0 (\"\")  > 4 (\" View/Edit/Delete \") | AUTHORITY:  0 (\"\")  > 4 (\" View/Edit/Delete \") | AUTHORITY:  0 (\"\")  > 4 (\" View/Edit/Delete \") | AUTHORITY:  0 (\"\")  > 4 (\" View/Edit/Delete \") | AUTHORITY:  0 (\"\")  > 4 (\" View/Edit/Delete \") | AUTHORITY:  0 (\"\")  > 4 (\" View/Edit/Delete \") | AUTHORITY:  0 (\"\")  > 4 (\" View/Edit/Delete \") | AUTHORITY:  0 (\"\")  > 4 (\" View/Edit/Delete \") | AUTHORITY:  0 (\"\")  > 4 (\" View/Edit/Delete \") | AUTHORITY:  0 (\"\")  > 4 (\" View/Edit/Delete \") | AUTHORITY:  0 (\"\")  > 4 (\" View/Edit/Delete \") | AUTHORITY:  0 (\"\")  > 4 (\" View/Edit/Delete \") | AUTHORITY:  0 (\"\")  > 4 (\" View/Edit/Delete \") | AUTHORITY:  0 (\"\")  > 4 (\" View/Edit/Delete \") | AUTHORITY:  0 (\"\")  > 4 (\" View/Edit/Delete \") | AUTHORITY:  0 (\"\")  > 4 (\" View/Edit/Delete \") | AUTHORITY:  0 (\"\")  > 4 (\" View/Edit/Delete \") | AUTHORITY:  0 (\"\")  > 4 (\" View/Edit/Delete \") | AUTHORITY:  0 (\"\")  > 4 (\" View/Edit/Delete \") | AUTHORITY:  0 (\"\")  > 4 (\" View/Edit/Delete \") | AUTHORITY:  0 (\"\")  > 4 (\" View/Edit/Delete \") | AUTHORITY:  0 (\"\")  > 4 (\" View/Edit/Delete \") | AUTHORITY:  0 (\"\")  > 4 (\" View/Edit/Delete \") | AUTHORITY:  0 (\"\")  > 4 (\" View/Edit/Delete \") | AUTHORITY:  0 (\"\")  > 4 (\" View/Edit/Delete \") | AUTHORITY:  0 (\"\")  > 4 (\" View/Edit/Delete \") | AUTHORITY:  0 (\"\")  > 4 (\" View/Edit/Delete \") | AUTHORITY:  0 (\"\")  > 4 (\" View/Edit/Delete \") | AUTHORITY:  0 (\"\")  > 4 (\" View/Edit/Delete \") | AUTHORITY:  0 (\"\")  > 4 (\" View/Edit/Delete \") | AUTHORITY:  0 (\"\")  > 4 (\" View/Edit/Delete \") | AUTHORITY:  0 (\"\")  > 4 (\" View/Edit/Delete \")','2021-01-11 15:40:31.511805','Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/87.0.4280.141 Safari/537.36'),(42,'49.146.42.127',1,0,3,0,0,10080,113,0,'add/edit Access rights record','LEVEL: 0 (\"\")  >  2 (\" Super Admin \") | MODULE: 0 (\"\")  >  10120 (\" Devices \") | AUTHORITY:  0 (\"\")  > 0 (\" No Access \") | LEVEL: 0 (\"\")  >  2 (\" Super Admin \") | MODULE: 0 (\"\")  >  10160 (\" Brute Force Login Attempt \") | AUTHORITY:  0 (\"\")  > 0 (\" No Access \") | LEVEL: 0 (\"\")  >  2 (\" Super Admin \") | MODULE: 0 (\"\")  >  10180 (\" Bruteforce IP \") | AUTHORITY:  0 (\"\")  > 0 (\" No Access \") | LEVEL: 0 (\"\")  >  2 (\" Super Admin \") | MODULE: 0 (\"\")  >  15010 (\" Addon: Group License \") | AUTHORITY:  0 (\"\")  > 0 (\" No Access \") | LEVEL: 0 (\"\")  >  2 (\" Super Admin \") | MODULE: 0 (\"\")  >  15030 (\" Addon: User License \") | AUTHORITY:  0 (\"\")  > 0 (\" No Access \") | LEVEL: 0 (\"\")  >  2 (\" Super Admin \") | MODULE: 0 (\"\")  >  15050 (\" Addon: Queuing \") | AUTHORITY:  0 (\"\")  > 0 (\" No Access \") | LEVEL: 0 (\"\")  >  2 (\" Super Admin \") | MODULE: 0 (\"\")  >  15070 (\" Addon: Resource \") | AUTHORITY:  0 (\"\")  > 0 (\" No Access \") | LEVEL: 0 (\"\")  >  2 (\" Super Admin \") | MODULE: 0 (\"\")  >  21030 (\" Section \") | AUTHORITY:  0 (\"\")  > 0 (\" No Access \") | LEVEL: 0 (\"\")  >  2 (\" Super Admin \") | MODULE: 0 (\"\")  >  21050 (\" Entrance \") | AUTHORITY:  0 (\"\")  > 0 (\" No Access \") | AUTHORITY:  0 (\"\")  > 4 (\" View/Edit/Delete \") | AUTHORITY:  0 (\"\")  > 4 (\" View/Edit/Delete \") | AUTHORITY:  0 (\"\")  > 4 (\" View/Edit/Delete \") | AUTHORITY:  0 (\"\")  > 4 (\" View/Edit/Delete \") | AUTHORITY:  0 (\"\")  > 4 (\" View/Edit/Delete \") | AUTHORITY:  0 (\"\")  > 4 (\" View/Edit/Delete \") | AUTHORITY:  0 (\"\")  > 4 (\" View/Edit/Delete \") | AUTHORITY:  0 (\"\")  > 4 (\" View/Edit/Delete \") | AUTHORITY:  0 (\"\")  > 4 (\" View/Edit/Delete \") | AUTHORITY:  0 (\"\")  > 4 (\" View/Edit/Delete \") | AUTHORITY:  0 (\"\")  > 4 (\" View/Edit/Delete \") | AUTHORITY:  0 (\"\")  > 4 (\" View/Edit/Delete \") | AUTHORITY:  0 (\"\")  > 4 (\" View/Edit/Delete \") | AUTHORITY:  0 (\"\")  > 4 (\" View/Edit/Delete \") | AUTHORITY:  0 (\"\")  > 4 (\" View/Edit/Delete \") | AUTHORITY:  0 (\"\")  > 4 (\" View/Edit/Delete \") | AUTHORITY:  0 (\"\")  > 4 (\" View/Edit/Delete \") | AUTHORITY:  0 (\"\")  > 4 (\" View/Edit/Delete \") | AUTHORITY:  0 (\"\")  > 4 (\" View/Edit/Delete \") | AUTHORITY:  0 (\"\")  > 4 (\" View/Edit/Delete \") | AUTHORITY:  0 (\"\")  > 4 (\" View/Edit/Delete \") | AUTHORITY:  0 (\"\")  > 4 (\" View/Edit/Delete \") | AUTHORITY:  0 (\"\")  > 4 (\" View/Edit/Delete \") | AUTHORITY:  0 (\"\")  > 4 (\" View/Edit/Delete \") | AUTHORITY:  0 (\"\")  > 4 (\" View/Edit/Delete \") | AUTHORITY:  0 (\"\")  > 4 (\" View/Edit/Delete \") | AUTHORITY:  0 (\"\")  > 4 (\" View/Edit/Delete \") | AUTHORITY:  0 (\"\")  > 4 (\" View/Edit/Delete \") | AUTHORITY:  0 (\"\")  > 4 (\" View/Edit/Delete \") | AUTHORITY:  0 (\"\")  > 4 (\" View/Edit/Delete \") | AUTHORITY:  0 (\"\")  > 4 (\" View/Edit/Delete \") | AUTHORITY:  0 (\"\")  > 4 (\" View/Edit/Delete \") | AUTHORITY:  0 (\"\")  > 4 (\" View/Edit/Delete \")','2021-01-11 15:40:31.516432','Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/87.0.4280.141 Safari/537.36'),(43,'49.146.42.127',1,0,3,0,0,10080,114,0,'add/edit Access rights record','LEVEL: 0 (\"\")  >  2 (\" Super Admin \") | MODULE: 0 (\"\")  >  10120 (\" Devices \") | AUTHORITY:  0 (\"\")  > 0 (\" No Access \") | LEVEL: 0 (\"\")  >  2 (\" Super Admin \") | MODULE: 0 (\"\")  >  10160 (\" Brute Force Login Attempt \") | AUTHORITY:  0 (\"\")  > 0 (\" No Access \") | LEVEL: 0 (\"\")  >  2 (\" Super Admin \") | MODULE: 0 (\"\")  >  10180 (\" Bruteforce IP \") | AUTHORITY:  0 (\"\")  > 0 (\" No Access \") | LEVEL: 0 (\"\")  >  2 (\" Super Admin \") | MODULE: 0 (\"\")  >  15010 (\" Addon: Group License \") | AUTHORITY:  0 (\"\")  > 0 (\" No Access \") | LEVEL: 0 (\"\")  >  2 (\" Super Admin \") | MODULE: 0 (\"\")  >  15030 (\" Addon: User License \") | AUTHORITY:  0 (\"\")  > 0 (\" No Access \") | LEVEL: 0 (\"\")  >  2 (\" Super Admin \") | MODULE: 0 (\"\")  >  15050 (\" Addon: Queuing \") | AUTHORITY:  0 (\"\")  > 0 (\" No Access \") | LEVEL: 0 (\"\")  >  2 (\" Super Admin \") | MODULE: 0 (\"\")  >  15070 (\" Addon: Resource \") | AUTHORITY:  0 (\"\")  > 0 (\" No Access \") | LEVEL: 0 (\"\")  >  2 (\" Super Admin \") | MODULE: 0 (\"\")  >  21030 (\" Section \") | AUTHORITY:  0 (\"\")  > 0 (\" No Access \") | LEVEL: 0 (\"\")  >  2 (\" Super Admin \") | MODULE: 0 (\"\")  >  21050 (\" Entrance \") | AUTHORITY:  0 (\"\")  > 0 (\" No Access \") | AUTHORITY:  0 (\"\")  > 4 (\" View/Edit/Delete \") | AUTHORITY:  0 (\"\")  > 4 (\" View/Edit/Delete \") | AUTHORITY:  0 (\"\")  > 4 (\" View/Edit/Delete \") | AUTHORITY:  0 (\"\")  > 4 (\" View/Edit/Delete \") | AUTHORITY:  0 (\"\")  > 4 (\" View/Edit/Delete \") | AUTHORITY:  0 (\"\")  > 4 (\" View/Edit/Delete \") | AUTHORITY:  0 (\"\")  > 4 (\" View/Edit/Delete \") | AUTHORITY:  0 (\"\")  > 4 (\" View/Edit/Delete \") | AUTHORITY:  0 (\"\")  > 4 (\" View/Edit/Delete \") | AUTHORITY:  0 (\"\")  > 4 (\" View/Edit/Delete \") | AUTHORITY:  0 (\"\")  > 4 (\" View/Edit/Delete \") | AUTHORITY:  0 (\"\")  > 4 (\" View/Edit/Delete \") | AUTHORITY:  0 (\"\")  > 4 (\" View/Edit/Delete \") | AUTHORITY:  0 (\"\")  > 4 (\" View/Edit/Delete \") | AUTHORITY:  0 (\"\")  > 4 (\" View/Edit/Delete \") | AUTHORITY:  0 (\"\")  > 4 (\" View/Edit/Delete \") | AUTHORITY:  0 (\"\")  > 4 (\" View/Edit/Delete \") | AUTHORITY:  0 (\"\")  > 4 (\" View/Edit/Delete \") | AUTHORITY:  0 (\"\")  > 4 (\" View/Edit/Delete \") | AUTHORITY:  0 (\"\")  > 4 (\" View/Edit/Delete \") | AUTHORITY:  0 (\"\")  > 4 (\" View/Edit/Delete \") | AUTHORITY:  0 (\"\")  > 4 (\" View/Edit/Delete \") | AUTHORITY:  0 (\"\")  > 4 (\" View/Edit/Delete \") | AUTHORITY:  0 (\"\")  > 4 (\" View/Edit/Delete \") | AUTHORITY:  0 (\"\")  > 4 (\" View/Edit/Delete \") | AUTHORITY:  0 (\"\")  > 4 (\" View/Edit/Delete \") | AUTHORITY:  0 (\"\")  > 4 (\" View/Edit/Delete \") | AUTHORITY:  0 (\"\")  > 4 (\" View/Edit/Delete \") | AUTHORITY:  0 (\"\")  > 4 (\" View/Edit/Delete \") | AUTHORITY:  0 (\"\")  > 4 (\" View/Edit/Delete \") | AUTHORITY:  0 (\"\")  > 4 (\" View/Edit/Delete \") | AUTHORITY:  0 (\"\")  > 4 (\" View/Edit/Delete \") | AUTHORITY:  0 (\"\")  > 4 (\" View/Edit/Delete \") | AUTHORITY:  0 (\"\")  > 4 (\" View/Edit/Delete \")','2021-01-11 15:40:31.520569','Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/87.0.4280.141 Safari/537.36'),(44,'49.146.42.127',1,0,3,0,0,10080,115,0,'add/edit Access rights record','LEVEL: 0 (\"\")  >  2 (\" Super Admin \") | MODULE: 0 (\"\")  >  10120 (\" Devices \") | AUTHORITY:  0 (\"\")  > 0 (\" No Access \") | LEVEL: 0 (\"\")  >  2 (\" Super Admin \") | MODULE: 0 (\"\")  >  10160 (\" Brute Force Login Attempt \") | AUTHORITY:  0 (\"\")  > 0 (\" No Access \") | LEVEL: 0 (\"\")  >  2 (\" Super Admin \") | MODULE: 0 (\"\")  >  10180 (\" Bruteforce IP \") | AUTHORITY:  0 (\"\")  > 0 (\" No Access \") | LEVEL: 0 (\"\")  >  2 (\" Super Admin \") | MODULE: 0 (\"\")  >  15010 (\" Addon: Group License \") | AUTHORITY:  0 (\"\")  > 0 (\" No Access \") | LEVEL: 0 (\"\")  >  2 (\" Super Admin \") | MODULE: 0 (\"\")  >  15030 (\" Addon: User License \") | AUTHORITY:  0 (\"\")  > 0 (\" No Access \") | LEVEL: 0 (\"\")  >  2 (\" Super Admin \") | MODULE: 0 (\"\")  >  15050 (\" Addon: Queuing \") | AUTHORITY:  0 (\"\")  > 0 (\" No Access \") | LEVEL: 0 (\"\")  >  2 (\" Super Admin \") | MODULE: 0 (\"\")  >  15070 (\" Addon: Resource \") | AUTHORITY:  0 (\"\")  > 0 (\" No Access \") | LEVEL: 0 (\"\")  >  2 (\" Super Admin \") | MODULE: 0 (\"\")  >  21030 (\" Section \") | AUTHORITY:  0 (\"\")  > 0 (\" No Access \") | LEVEL: 0 (\"\")  >  2 (\" Super Admin \") | MODULE: 0 (\"\")  >  21050 (\" Entrance \") | AUTHORITY:  0 (\"\")  > 0 (\" No Access \") | AUTHORITY:  0 (\"\")  > 4 (\" View/Edit/Delete \") | AUTHORITY:  0 (\"\")  > 4 (\" View/Edit/Delete \") | AUTHORITY:  0 (\"\")  > 4 (\" View/Edit/Delete \") | AUTHORITY:  0 (\"\")  > 4 (\" View/Edit/Delete \") | AUTHORITY:  0 (\"\")  > 4 (\" View/Edit/Delete \") | AUTHORITY:  0 (\"\")  > 4 (\" View/Edit/Delete \") | AUTHORITY:  0 (\"\")  > 4 (\" View/Edit/Delete \") | AUTHORITY:  0 (\"\")  > 4 (\" View/Edit/Delete \") | AUTHORITY:  0 (\"\")  > 4 (\" View/Edit/Delete \") | AUTHORITY:  0 (\"\")  > 4 (\" View/Edit/Delete \") | AUTHORITY:  0 (\"\")  > 4 (\" View/Edit/Delete \") | AUTHORITY:  0 (\"\")  > 4 (\" View/Edit/Delete \") | AUTHORITY:  0 (\"\")  > 4 (\" View/Edit/Delete \") | AUTHORITY:  0 (\"\")  > 4 (\" View/Edit/Delete \") | AUTHORITY:  0 (\"\")  > 4 (\" View/Edit/Delete \") | AUTHORITY:  0 (\"\")  > 4 (\" View/Edit/Delete \") | AUTHORITY:  0 (\"\")  > 4 (\" View/Edit/Delete \") | AUTHORITY:  0 (\"\")  > 4 (\" View/Edit/Delete \") | AUTHORITY:  0 (\"\")  > 4 (\" View/Edit/Delete \") | AUTHORITY:  0 (\"\")  > 4 (\" View/Edit/Delete \") | AUTHORITY:  0 (\"\")  > 4 (\" View/Edit/Delete \") | AUTHORITY:  0 (\"\")  > 4 (\" View/Edit/Delete \") | AUTHORITY:  0 (\"\")  > 4 (\" View/Edit/Delete \") | AUTHORITY:  0 (\"\")  > 4 (\" View/Edit/Delete \") | AUTHORITY:  0 (\"\")  > 4 (\" View/Edit/Delete \") | AUTHORITY:  0 (\"\")  > 4 (\" View/Edit/Delete \") | AUTHORITY:  0 (\"\")  > 4 (\" View/Edit/Delete \") | AUTHORITY:  0 (\"\")  > 4 (\" View/Edit/Delete \") | AUTHORITY:  0 (\"\")  > 4 (\" View/Edit/Delete \") | AUTHORITY:  0 (\"\")  > 4 (\" View/Edit/Delete \") | AUTHORITY:  0 (\"\")  > 4 (\" View/Edit/Delete \") | AUTHORITY:  0 (\"\")  > 4 (\" View/Edit/Delete \") | AUTHORITY:  0 (\"\")  > 4 (\" View/Edit/Delete \") | AUTHORITY:  0 (\"\")  > 4 (\" View/Edit/Delete \") | AUTHORITY:  0 (\"\")  > 4 (\" View/Edit/Delete \")','2021-01-11 15:40:31.527512','Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/87.0.4280.141 Safari/537.36'),(45,'49.146.42.127',1,0,3,0,0,10080,116,0,'add/edit Access rights record','LEVEL: 0 (\"\")  >  2 (\" Super Admin \") | MODULE: 0 (\"\")  >  10120 (\" Devices \") | AUTHORITY:  0 (\"\")  > 0 (\" No Access \") | LEVEL: 0 (\"\")  >  2 (\" Super Admin \") | MODULE: 0 (\"\")  >  10160 (\" Brute Force Login Attempt \") | AUTHORITY:  0 (\"\")  > 0 (\" No Access \") | LEVEL: 0 (\"\")  >  2 (\" Super Admin \") | MODULE: 0 (\"\")  >  10180 (\" Bruteforce IP \") | AUTHORITY:  0 (\"\")  > 0 (\" No Access \") | LEVEL: 0 (\"\")  >  2 (\" Super Admin \") | MODULE: 0 (\"\")  >  15010 (\" Addon: Group License \") | AUTHORITY:  0 (\"\")  > 0 (\" No Access \") | LEVEL: 0 (\"\")  >  2 (\" Super Admin \") | MODULE: 0 (\"\")  >  15030 (\" Addon: User License \") | AUTHORITY:  0 (\"\")  > 0 (\" No Access \") | LEVEL: 0 (\"\")  >  2 (\" Super Admin \") | MODULE: 0 (\"\")  >  15050 (\" Addon: Queuing \") | AUTHORITY:  0 (\"\")  > 0 (\" No Access \") | LEVEL: 0 (\"\")  >  2 (\" Super Admin \") | MODULE: 0 (\"\")  >  15070 (\" Addon: Resource \") | AUTHORITY:  0 (\"\")  > 0 (\" No Access \") | LEVEL: 0 (\"\")  >  2 (\" Super Admin \") | MODULE: 0 (\"\")  >  21030 (\" Section \") | AUTHORITY:  0 (\"\")  > 0 (\" No Access \") | LEVEL: 0 (\"\")  >  2 (\" Super Admin \") | MODULE: 0 (\"\")  >  21050 (\" Entrance \") | AUTHORITY:  0 (\"\")  > 0 (\" No Access \") | AUTHORITY:  0 (\"\")  > 4 (\" View/Edit/Delete \") | AUTHORITY:  0 (\"\")  > 4 (\" View/Edit/Delete \") | AUTHORITY:  0 (\"\")  > 4 (\" View/Edit/Delete \") | AUTHORITY:  0 (\"\")  > 4 (\" View/Edit/Delete \") | AUTHORITY:  0 (\"\")  > 4 (\" View/Edit/Delete \") | AUTHORITY:  0 (\"\")  > 4 (\" View/Edit/Delete \") | AUTHORITY:  0 (\"\")  > 4 (\" View/Edit/Delete \") | AUTHORITY:  0 (\"\")  > 4 (\" View/Edit/Delete \") | AUTHORITY:  0 (\"\")  > 4 (\" View/Edit/Delete \") | AUTHORITY:  0 (\"\")  > 4 (\" View/Edit/Delete \") | AUTHORITY:  0 (\"\")  > 4 (\" View/Edit/Delete \") | AUTHORITY:  0 (\"\")  > 4 (\" View/Edit/Delete \") | AUTHORITY:  0 (\"\")  > 4 (\" View/Edit/Delete \") | AUTHORITY:  0 (\"\")  > 4 (\" View/Edit/Delete \") | AUTHORITY:  0 (\"\")  > 4 (\" View/Edit/Delete \") | AUTHORITY:  0 (\"\")  > 4 (\" View/Edit/Delete \") | AUTHORITY:  0 (\"\")  > 4 (\" View/Edit/Delete \") | AUTHORITY:  0 (\"\")  > 4 (\" View/Edit/Delete \") | AUTHORITY:  0 (\"\")  > 4 (\" View/Edit/Delete \") | AUTHORITY:  0 (\"\")  > 4 (\" View/Edit/Delete \") | AUTHORITY:  0 (\"\")  > 4 (\" View/Edit/Delete \") | AUTHORITY:  0 (\"\")  > 4 (\" View/Edit/Delete \") | AUTHORITY:  0 (\"\")  > 4 (\" View/Edit/Delete \") | AUTHORITY:  0 (\"\")  > 4 (\" View/Edit/Delete \") | AUTHORITY:  0 (\"\")  > 4 (\" View/Edit/Delete \") | AUTHORITY:  0 (\"\")  > 4 (\" View/Edit/Delete \") | AUTHORITY:  0 (\"\")  > 4 (\" View/Edit/Delete \") | AUTHORITY:  0 (\"\")  > 4 (\" View/Edit/Delete \") | AUTHORITY:  0 (\"\")  > 4 (\" View/Edit/Delete \") | AUTHORITY:  0 (\"\")  > 4 (\" View/Edit/Delete \") | AUTHORITY:  0 (\"\")  > 4 (\" View/Edit/Delete \") | AUTHORITY:  0 (\"\")  > 4 (\" View/Edit/Delete \") | AUTHORITY:  0 (\"\")  > 4 (\" View/Edit/Delete \") | AUTHORITY:  0 (\"\")  > 4 (\" View/Edit/Delete \") | AUTHORITY:  0 (\"\")  > 4 (\" View/Edit/Delete \") | AUTHORITY:  0 (\"\")  > 4 (\" View/Edit/Delete \")','2021-01-11 15:40:31.534558','Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/87.0.4280.141 Safari/537.36'),(46,'49.146.42.127',1,0,3,0,0,10080,144,0,'add/edit Access rights record','LEVEL: 0 (\"\")  >  2 (\" Super Admin \") | MODULE: 0 (\"\")  >  10120 (\" Devices \") | AUTHORITY:  0 (\"\")  > 0 (\" No Access \") | LEVEL: 0 (\"\")  >  2 (\" Super Admin \") | MODULE: 0 (\"\")  >  10160 (\" Brute Force Login Attempt \") | AUTHORITY:  0 (\"\")  > 0 (\" No Access \") | LEVEL: 0 (\"\")  >  2 (\" Super Admin \") | MODULE: 0 (\"\")  >  10180 (\" Bruteforce IP \") | AUTHORITY:  0 (\"\")  > 0 (\" No Access \") | LEVEL: 0 (\"\")  >  2 (\" Super Admin \") | MODULE: 0 (\"\")  >  15010 (\" Addon: Group License \") | AUTHORITY:  0 (\"\")  > 0 (\" No Access \") | LEVEL: 0 (\"\")  >  2 (\" Super Admin \") | MODULE: 0 (\"\")  >  15030 (\" Addon: User License \") | AUTHORITY:  0 (\"\")  > 0 (\" No Access \") | LEVEL: 0 (\"\")  >  2 (\" Super Admin \") | MODULE: 0 (\"\")  >  15050 (\" Addon: Queuing \") | AUTHORITY:  0 (\"\")  > 0 (\" No Access \") | LEVEL: 0 (\"\")  >  2 (\" Super Admin \") | MODULE: 0 (\"\")  >  15070 (\" Addon: Resource \") | AUTHORITY:  0 (\"\")  > 0 (\" No Access \") | LEVEL: 0 (\"\")  >  2 (\" Super Admin \") | MODULE: 0 (\"\")  >  21030 (\" Section \") | AUTHORITY:  0 (\"\")  > 0 (\" No Access \") | LEVEL: 0 (\"\")  >  2 (\" Super Admin \") | MODULE: 0 (\"\")  >  21050 (\" Entrance \") | AUTHORITY:  0 (\"\")  > 0 (\" No Access \") | AUTHORITY:  0 (\"\")  > 4 (\" View/Edit/Delete \") | AUTHORITY:  0 (\"\")  > 4 (\" View/Edit/Delete \") | AUTHORITY:  0 (\"\")  > 4 (\" View/Edit/Delete \") | AUTHORITY:  0 (\"\")  > 4 (\" View/Edit/Delete \") | AUTHORITY:  0 (\"\")  > 4 (\" View/Edit/Delete \") | AUTHORITY:  0 (\"\")  > 4 (\" View/Edit/Delete \") | AUTHORITY:  0 (\"\")  > 4 (\" View/Edit/Delete \") | AUTHORITY:  0 (\"\")  > 4 (\" View/Edit/Delete \") | AUTHORITY:  0 (\"\")  > 4 (\" View/Edit/Delete \") | AUTHORITY:  0 (\"\")  > 4 (\" View/Edit/Delete \") | AUTHORITY:  0 (\"\")  > 4 (\" View/Edit/Delete \") | AUTHORITY:  0 (\"\")  > 4 (\" View/Edit/Delete \") | AUTHORITY:  0 (\"\")  > 4 (\" View/Edit/Delete \") | AUTHORITY:  0 (\"\")  > 4 (\" View/Edit/Delete \") | AUTHORITY:  0 (\"\")  > 4 (\" View/Edit/Delete \") | AUTHORITY:  0 (\"\")  > 4 (\" View/Edit/Delete \") | AUTHORITY:  0 (\"\")  > 4 (\" View/Edit/Delete \") | AUTHORITY:  0 (\"\")  > 4 (\" View/Edit/Delete \") | AUTHORITY:  0 (\"\")  > 4 (\" View/Edit/Delete \") | AUTHORITY:  0 (\"\")  > 4 (\" View/Edit/Delete \") | AUTHORITY:  0 (\"\")  > 4 (\" View/Edit/Delete \") | AUTHORITY:  0 (\"\")  > 4 (\" View/Edit/Delete \") | AUTHORITY:  0 (\"\")  > 4 (\" View/Edit/Delete \") | AUTHORITY:  0 (\"\")  > 4 (\" View/Edit/Delete \") | AUTHORITY:  0 (\"\")  > 4 (\" View/Edit/Delete \") | AUTHORITY:  0 (\"\")  > 4 (\" View/Edit/Delete \") | AUTHORITY:  0 (\"\")  > 4 (\" View/Edit/Delete \") | AUTHORITY:  0 (\"\")  > 4 (\" View/Edit/Delete \") | AUTHORITY:  0 (\"\")  > 4 (\" View/Edit/Delete \") | AUTHORITY:  0 (\"\")  > 4 (\" View/Edit/Delete \") | AUTHORITY:  0 (\"\")  > 4 (\" View/Edit/Delete \") | AUTHORITY:  0 (\"\")  > 4 (\" View/Edit/Delete \") | AUTHORITY:  0 (\"\")  > 4 (\" View/Edit/Delete \") | AUTHORITY:  0 (\"\")  > 4 (\" View/Edit/Delete \") | AUTHORITY:  0 (\"\")  > 4 (\" View/Edit/Delete \") | AUTHORITY:  0 (\"\")  > 4 (\" View/Edit/Delete \") | AUTHORITY:  0 (\"\")  > 4 (\" View/Edit/Delete \")','2021-01-11 15:40:31.542474','Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/87.0.4280.141 Safari/537.36'),(47,'49.146.42.127',1,0,3,0,0,10080,145,0,'add/edit Access rights record','LEVEL: 0 (\"\")  >  2 (\" Super Admin \") | MODULE: 0 (\"\")  >  10120 (\" Devices \") | AUTHORITY:  0 (\"\")  > 0 (\" No Access \") | LEVEL: 0 (\"\")  >  2 (\" Super Admin \") | MODULE: 0 (\"\")  >  10160 (\" Brute Force Login Attempt \") | AUTHORITY:  0 (\"\")  > 0 (\" No Access \") | LEVEL: 0 (\"\")  >  2 (\" Super Admin \") | MODULE: 0 (\"\")  >  10180 (\" Bruteforce IP \") | AUTHORITY:  0 (\"\")  > 0 (\" No Access \") | LEVEL: 0 (\"\")  >  2 (\" Super Admin \") | MODULE: 0 (\"\")  >  15010 (\" Addon: Group License \") | AUTHORITY:  0 (\"\")  > 0 (\" No Access \") | LEVEL: 0 (\"\")  >  2 (\" Super Admin \") | MODULE: 0 (\"\")  >  15030 (\" Addon: User License \") | AUTHORITY:  0 (\"\")  > 0 (\" No Access \") | LEVEL: 0 (\"\")  >  2 (\" Super Admin \") | MODULE: 0 (\"\")  >  15050 (\" Addon: Queuing \") | AUTHORITY:  0 (\"\")  > 0 (\" No Access \") | LEVEL: 0 (\"\")  >  2 (\" Super Admin \") | MODULE: 0 (\"\")  >  15070 (\" Addon: Resource \") | AUTHORITY:  0 (\"\")  > 0 (\" No Access \") | LEVEL: 0 (\"\")  >  2 (\" Super Admin \") | MODULE: 0 (\"\")  >  21030 (\" Section \") | AUTHORITY:  0 (\"\")  > 0 (\" No Access \") | LEVEL: 0 (\"\")  >  2 (\" Super Admin \") | MODULE: 0 (\"\")  >  21050 (\" Entrance \") | AUTHORITY:  0 (\"\")  > 0 (\" No Access \") | AUTHORITY:  0 (\"\")  > 4 (\" View/Edit/Delete \") | AUTHORITY:  0 (\"\")  > 4 (\" View/Edit/Delete \") | AUTHORITY:  0 (\"\")  > 4 (\" View/Edit/Delete \") | AUTHORITY:  0 (\"\")  > 4 (\" View/Edit/Delete \") | AUTHORITY:  0 (\"\")  > 4 (\" View/Edit/Delete \") | AUTHORITY:  0 (\"\")  > 4 (\" View/Edit/Delete \") | AUTHORITY:  0 (\"\")  > 4 (\" View/Edit/Delete \") | AUTHORITY:  0 (\"\")  > 4 (\" View/Edit/Delete \") | AUTHORITY:  0 (\"\")  > 4 (\" View/Edit/Delete \") | AUTHORITY:  0 (\"\")  > 4 (\" View/Edit/Delete \") | AUTHORITY:  0 (\"\")  > 4 (\" View/Edit/Delete \") | AUTHORITY:  0 (\"\")  > 4 (\" View/Edit/Delete \") | AUTHORITY:  0 (\"\")  > 4 (\" View/Edit/Delete \") | AUTHORITY:  0 (\"\")  > 4 (\" View/Edit/Delete \") | AUTHORITY:  0 (\"\")  > 4 (\" View/Edit/Delete \") | AUTHORITY:  0 (\"\")  > 4 (\" View/Edit/Delete \") | AUTHORITY:  0 (\"\")  > 4 (\" View/Edit/Delete \") | AUTHORITY:  0 (\"\")  > 4 (\" View/Edit/Delete \") | AUTHORITY:  0 (\"\")  > 4 (\" View/Edit/Delete \") | AUTHORITY:  0 (\"\")  > 4 (\" View/Edit/Delete \") | AUTHORITY:  0 (\"\")  > 4 (\" View/Edit/Delete \") | AUTHORITY:  0 (\"\")  > 4 (\" View/Edit/Delete \") | AUTHORITY:  0 (\"\")  > 4 (\" View/Edit/Delete \") | AUTHORITY:  0 (\"\")  > 4 (\" View/Edit/Delete \") | AUTHORITY:  0 (\"\")  > 4 (\" View/Edit/Delete \") | AUTHORITY:  0 (\"\")  > 4 (\" View/Edit/Delete \") | AUTHORITY:  0 (\"\")  > 4 (\" View/Edit/Delete \") | AUTHORITY:  0 (\"\")  > 4 (\" View/Edit/Delete \") | AUTHORITY:  0 (\"\")  > 4 (\" View/Edit/Delete \") | AUTHORITY:  0 (\"\")  > 4 (\" View/Edit/Delete \") | AUTHORITY:  0 (\"\")  > 4 (\" View/Edit/Delete \") | AUTHORITY:  0 (\"\")  > 4 (\" View/Edit/Delete \") | AUTHORITY:  0 (\"\")  > 4 (\" View/Edit/Delete \") | AUTHORITY:  0 (\"\")  > 4 (\" View/Edit/Delete \") | AUTHORITY:  0 (\"\")  > 4 (\" View/Edit/Delete \") | AUTHORITY:  0 (\"\")  > 4 (\" View/Edit/Delete \") | AUTHORITY:  0 (\"\")  > 4 (\" View/Edit/Delete \") | AUTHORITY:  0 (\"\")  > 4 (\" View/Edit/Delete \")','2021-01-11 15:40:31.547829','Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/87.0.4280.141 Safari/537.36'),(48,'49.146.42.127',1,0,3,0,0,10080,146,0,'add/edit Access rights record','LEVEL: 0 (\"\")  >  2 (\" Super Admin \") | MODULE: 0 (\"\")  >  10120 (\" Devices \") | AUTHORITY:  0 (\"\")  > 0 (\" No Access \") | LEVEL: 0 (\"\")  >  2 (\" Super Admin \") | MODULE: 0 (\"\")  >  10160 (\" Brute Force Login Attempt \") | AUTHORITY:  0 (\"\")  > 0 (\" No Access \") | LEVEL: 0 (\"\")  >  2 (\" Super Admin \") | MODULE: 0 (\"\")  >  10180 (\" Bruteforce IP \") | AUTHORITY:  0 (\"\")  > 0 (\" No Access \") | LEVEL: 0 (\"\")  >  2 (\" Super Admin \") | MODULE: 0 (\"\")  >  15010 (\" Addon: Group License \") | AUTHORITY:  0 (\"\")  > 0 (\" No Access \") | LEVEL: 0 (\"\")  >  2 (\" Super Admin \") | MODULE: 0 (\"\")  >  15030 (\" Addon: User License \") | AUTHORITY:  0 (\"\")  > 0 (\" No Access \") | LEVEL: 0 (\"\")  >  2 (\" Super Admin \") | MODULE: 0 (\"\")  >  15050 (\" Addon: Queuing \") | AUTHORITY:  0 (\"\")  > 0 (\" No Access \") | LEVEL: 0 (\"\")  >  2 (\" Super Admin \") | MODULE: 0 (\"\")  >  15070 (\" Addon: Resource \") | AUTHORITY:  0 (\"\")  > 0 (\" No Access \") | LEVEL: 0 (\"\")  >  2 (\" Super Admin \") | MODULE: 0 (\"\")  >  21030 (\" Section \") | AUTHORITY:  0 (\"\")  > 0 (\" No Access \") | LEVEL: 0 (\"\")  >  2 (\" Super Admin \") | MODULE: 0 (\"\")  >  21050 (\" Entrance \") | AUTHORITY:  0 (\"\")  > 0 (\" No Access \") | AUTHORITY:  0 (\"\")  > 4 (\" View/Edit/Delete \") | AUTHORITY:  0 (\"\")  > 4 (\" View/Edit/Delete \") | AUTHORITY:  0 (\"\")  > 4 (\" View/Edit/Delete \") | AUTHORITY:  0 (\"\")  > 4 (\" View/Edit/Delete \") | AUTHORITY:  0 (\"\")  > 4 (\" View/Edit/Delete \") | AUTHORITY:  0 (\"\")  > 4 (\" View/Edit/Delete \") | AUTHORITY:  0 (\"\")  > 4 (\" View/Edit/Delete \") | AUTHORITY:  0 (\"\")  > 4 (\" View/Edit/Delete \") | AUTHORITY:  0 (\"\")  > 4 (\" View/Edit/Delete \") | AUTHORITY:  0 (\"\")  > 4 (\" View/Edit/Delete \") | AUTHORITY:  0 (\"\")  > 4 (\" View/Edit/Delete \") | AUTHORITY:  0 (\"\")  > 4 (\" View/Edit/Delete \") | AUTHORITY:  0 (\"\")  > 4 (\" View/Edit/Delete \") | AUTHORITY:  0 (\"\")  > 4 (\" View/Edit/Delete \") | AUTHORITY:  0 (\"\")  > 4 (\" View/Edit/Delete \") | AUTHORITY:  0 (\"\")  > 4 (\" View/Edit/Delete \") | AUTHORITY:  0 (\"\")  > 4 (\" View/Edit/Delete \") | AUTHORITY:  0 (\"\")  > 4 (\" View/Edit/Delete \") | AUTHORITY:  0 (\"\")  > 4 (\" View/Edit/Delete \") | AUTHORITY:  0 (\"\")  > 4 (\" View/Edit/Delete \") | AUTHORITY:  0 (\"\")  > 4 (\" View/Edit/Delete \") | AUTHORITY:  0 (\"\")  > 4 (\" View/Edit/Delete \") | AUTHORITY:  0 (\"\")  > 4 (\" View/Edit/Delete \") | AUTHORITY:  0 (\"\")  > 4 (\" View/Edit/Delete \") | AUTHORITY:  0 (\"\")  > 4 (\" View/Edit/Delete \") | AUTHORITY:  0 (\"\")  > 4 (\" View/Edit/Delete \") | AUTHORITY:  0 (\"\")  > 4 (\" View/Edit/Delete \") | AUTHORITY:  0 (\"\")  > 4 (\" View/Edit/Delete \") | AUTHORITY:  0 (\"\")  > 4 (\" View/Edit/Delete \") | AUTHORITY:  0 (\"\")  > 4 (\" View/Edit/Delete \") | AUTHORITY:  0 (\"\")  > 4 (\" View/Edit/Delete \") | AUTHORITY:  0 (\"\")  > 4 (\" View/Edit/Delete \") | AUTHORITY:  0 (\"\")  > 4 (\" View/Edit/Delete \") | AUTHORITY:  0 (\"\")  > 4 (\" View/Edit/Delete \") | AUTHORITY:  0 (\"\")  > 4 (\" View/Edit/Delete \") | AUTHORITY:  0 (\"\")  > 4 (\" View/Edit/Delete \") | AUTHORITY:  0 (\"\")  > 4 (\" View/Edit/Delete \") | AUTHORITY:  0 (\"\")  > 4 (\" View/Edit/Delete \") | AUTHORITY:  0 (\"\")  > 4 (\" View/Edit/Delete \")','2021-01-11 15:40:31.552697','Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/87.0.4280.141 Safari/537.36'),(49,'49.146.42.127',1,0,3,0,0,10080,147,0,'add/edit Access rights record','LEVEL: 0 (\"\")  >  2 (\" Super Admin \") | MODULE: 0 (\"\")  >  10120 (\" Devices \") | AUTHORITY:  0 (\"\")  > 0 (\" No Access \") | LEVEL: 0 (\"\")  >  2 (\" Super Admin \") | MODULE: 0 (\"\")  >  10160 (\" Brute Force Login Attempt \") | AUTHORITY:  0 (\"\")  > 0 (\" No Access \") | LEVEL: 0 (\"\")  >  2 (\" Super Admin \") | MODULE: 0 (\"\")  >  10180 (\" Bruteforce IP \") | AUTHORITY:  0 (\"\")  > 0 (\" No Access \") | LEVEL: 0 (\"\")  >  2 (\" Super Admin \") | MODULE: 0 (\"\")  >  15010 (\" Addon: Group License \") | AUTHORITY:  0 (\"\")  > 0 (\" No Access \") | LEVEL: 0 (\"\")  >  2 (\" Super Admin \") | MODULE: 0 (\"\")  >  15030 (\" Addon: User License \") | AUTHORITY:  0 (\"\")  > 0 (\" No Access \") | LEVEL: 0 (\"\")  >  2 (\" Super Admin \") | MODULE: 0 (\"\")  >  15050 (\" Addon: Queuing \") | AUTHORITY:  0 (\"\")  > 0 (\" No Access \") | LEVEL: 0 (\"\")  >  2 (\" Super Admin \") | MODULE: 0 (\"\")  >  15070 (\" Addon: Resource \") | AUTHORITY:  0 (\"\")  > 0 (\" No Access \") | LEVEL: 0 (\"\")  >  2 (\" Super Admin \") | MODULE: 0 (\"\")  >  21030 (\" Section \") | AUTHORITY:  0 (\"\")  > 0 (\" No Access \") | LEVEL: 0 (\"\")  >  2 (\" Super Admin \") | MODULE: 0 (\"\")  >  21050 (\" Entrance \") | AUTHORITY:  0 (\"\")  > 0 (\" No Access \") | AUTHORITY:  0 (\"\")  > 4 (\" View/Edit/Delete \") | AUTHORITY:  0 (\"\")  > 4 (\" View/Edit/Delete \") | AUTHORITY:  0 (\"\")  > 4 (\" View/Edit/Delete \") | AUTHORITY:  0 (\"\")  > 4 (\" View/Edit/Delete \") | AUTHORITY:  0 (\"\")  > 4 (\" View/Edit/Delete \") | AUTHORITY:  0 (\"\")  > 4 (\" View/Edit/Delete \") | AUTHORITY:  0 (\"\")  > 4 (\" View/Edit/Delete \") | AUTHORITY:  0 (\"\")  > 4 (\" View/Edit/Delete \") | AUTHORITY:  0 (\"\")  > 4 (\" View/Edit/Delete \") | AUTHORITY:  0 (\"\")  > 4 (\" View/Edit/Delete \") | AUTHORITY:  0 (\"\")  > 4 (\" View/Edit/Delete \") | AUTHORITY:  0 (\"\")  > 4 (\" View/Edit/Delete \") | AUTHORITY:  0 (\"\")  > 4 (\" View/Edit/Delete \") | AUTHORITY:  0 (\"\")  > 4 (\" View/Edit/Delete \") | AUTHORITY:  0 (\"\")  > 4 (\" View/Edit/Delete \") | AUTHORITY:  0 (\"\")  > 4 (\" View/Edit/Delete \") | AUTHORITY:  0 (\"\")  > 4 (\" View/Edit/Delete \") | AUTHORITY:  0 (\"\")  > 4 (\" View/Edit/Delete \") | AUTHORITY:  0 (\"\")  > 4 (\" View/Edit/Delete \") | AUTHORITY:  0 (\"\")  > 4 (\" View/Edit/Delete \") | AUTHORITY:  0 (\"\")  > 4 (\" View/Edit/Delete \") | AUTHORITY:  0 (\"\")  > 4 (\" View/Edit/Delete \") | AUTHORITY:  0 (\"\")  > 4 (\" View/Edit/Delete \") | AUTHORITY:  0 (\"\")  > 4 (\" View/Edit/Delete \") | AUTHORITY:  0 (\"\")  > 4 (\" View/Edit/Delete \") | AUTHORITY:  0 (\"\")  > 4 (\" View/Edit/Delete \") | AUTHORITY:  0 (\"\")  > 4 (\" View/Edit/Delete \") | AUTHORITY:  0 (\"\")  > 4 (\" View/Edit/Delete \") | AUTHORITY:  0 (\"\")  > 4 (\" View/Edit/Delete \") | AUTHORITY:  0 (\"\")  > 4 (\" View/Edit/Delete \") | AUTHORITY:  0 (\"\")  > 4 (\" View/Edit/Delete \") | AUTHORITY:  0 (\"\")  > 4 (\" View/Edit/Delete \") | AUTHORITY:  0 (\"\")  > 4 (\" View/Edit/Delete \") | AUTHORITY:  0 (\"\")  > 4 (\" View/Edit/Delete \") | AUTHORITY:  0 (\"\")  > 4 (\" View/Edit/Delete \") | AUTHORITY:  0 (\"\")  > 4 (\" View/Edit/Delete \") | AUTHORITY:  0 (\"\")  > 4 (\" View/Edit/Delete \") | AUTHORITY:  0 (\"\")  > 4 (\" View/Edit/Delete \") | AUTHORITY:  0 (\"\")  > 4 (\" View/Edit/Delete \") | AUTHORITY:  0 (\"\")  > 4 (\" View/Edit/Delete \")','2021-01-11 15:40:31.579800','Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/87.0.4280.141 Safari/537.36'),(50,'49.146.42.127',1,0,3,0,0,10080,148,0,'add/edit Access rights record','LEVEL: 0 (\"\")  >  2 (\" Super Admin \") | MODULE: 0 (\"\")  >  10120 (\" Devices \") | AUTHORITY:  0 (\"\")  > 0 (\" No Access \") | LEVEL: 0 (\"\")  >  2 (\" Super Admin \") | MODULE: 0 (\"\")  >  10160 (\" Brute Force Login Attempt \") | AUTHORITY:  0 (\"\")  > 0 (\" No Access \") | LEVEL: 0 (\"\")  >  2 (\" Super Admin \") | MODULE: 0 (\"\")  >  10180 (\" Bruteforce IP \") | AUTHORITY:  0 (\"\")  > 0 (\" No Access \") | LEVEL: 0 (\"\")  >  2 (\" Super Admin \") | MODULE: 0 (\"\")  >  15010 (\" Addon: Group License \") | AUTHORITY:  0 (\"\")  > 0 (\" No Access \") | LEVEL: 0 (\"\")  >  2 (\" Super Admin \") | MODULE: 0 (\"\")  >  15030 (\" Addon: User License \") | AUTHORITY:  0 (\"\")  > 0 (\" No Access \") | LEVEL: 0 (\"\")  >  2 (\" Super Admin \") | MODULE: 0 (\"\")  >  15050 (\" Addon: Queuing \") | AUTHORITY:  0 (\"\")  > 0 (\" No Access \") | LEVEL: 0 (\"\")  >  2 (\" Super Admin \") | MODULE: 0 (\"\")  >  15070 (\" Addon: Resource \") | AUTHORITY:  0 (\"\")  > 0 (\" No Access \") | LEVEL: 0 (\"\")  >  2 (\" Super Admin \") | MODULE: 0 (\"\")  >  21030 (\" Section \") | AUTHORITY:  0 (\"\")  > 0 (\" No Access \") | LEVEL: 0 (\"\")  >  2 (\" Super Admin \") | MODULE: 0 (\"\")  >  21050 (\" Entrance \") | AUTHORITY:  0 (\"\")  > 0 (\" No Access \") | AUTHORITY:  0 (\"\")  > 4 (\" View/Edit/Delete \") | AUTHORITY:  0 (\"\")  > 4 (\" View/Edit/Delete \") | AUTHORITY:  0 (\"\")  > 4 (\" View/Edit/Delete \") | AUTHORITY:  0 (\"\")  > 4 (\" View/Edit/Delete \") | AUTHORITY:  0 (\"\")  > 4 (\" View/Edit/Delete \") | AUTHORITY:  0 (\"\")  > 4 (\" View/Edit/Delete \") | AUTHORITY:  0 (\"\")  > 4 (\" View/Edit/Delete \") | AUTHORITY:  0 (\"\")  > 4 (\" View/Edit/Delete \") | AUTHORITY:  0 (\"\")  > 4 (\" View/Edit/Delete \") | AUTHORITY:  0 (\"\")  > 4 (\" View/Edit/Delete \") | AUTHORITY:  0 (\"\")  > 4 (\" View/Edit/Delete \") | AUTHORITY:  0 (\"\")  > 4 (\" View/Edit/Delete \") | AUTHORITY:  0 (\"\")  > 4 (\" View/Edit/Delete \") | AUTHORITY:  0 (\"\")  > 4 (\" View/Edit/Delete \") | AUTHORITY:  0 (\"\")  > 4 (\" View/Edit/Delete \") | AUTHORITY:  0 (\"\")  > 4 (\" View/Edit/Delete \") | AUTHORITY:  0 (\"\")  > 4 (\" View/Edit/Delete \") | AUTHORITY:  0 (\"\")  > 4 (\" View/Edit/Delete \") | AUTHORITY:  0 (\"\")  > 4 (\" View/Edit/Delete \") | AUTHORITY:  0 (\"\")  > 4 (\" View/Edit/Delete \") | AUTHORITY:  0 (\"\")  > 4 (\" View/Edit/Delete \") | AUTHORITY:  0 (\"\")  > 4 (\" View/Edit/Delete \") | AUTHORITY:  0 (\"\")  > 4 (\" View/Edit/Delete \") | AUTHORITY:  0 (\"\")  > 4 (\" View/Edit/Delete \") | AUTHORITY:  0 (\"\")  > 4 (\" View/Edit/Delete \") | AUTHORITY:  0 (\"\")  > 4 (\" View/Edit/Delete \") | AUTHORITY:  0 (\"\")  > 4 (\" View/Edit/Delete \") | AUTHORITY:  0 (\"\")  > 4 (\" View/Edit/Delete \") | AUTHORITY:  0 (\"\")  > 4 (\" View/Edit/Delete \") | AUTHORITY:  0 (\"\")  > 4 (\" View/Edit/Delete \") | AUTHORITY:  0 (\"\")  > 4 (\" View/Edit/Delete \") | AUTHORITY:  0 (\"\")  > 4 (\" View/Edit/Delete \") | AUTHORITY:  0 (\"\")  > 4 (\" View/Edit/Delete \") | AUTHORITY:  0 (\"\")  > 4 (\" View/Edit/Delete \") | AUTHORITY:  0 (\"\")  > 4 (\" View/Edit/Delete \") | AUTHORITY:  0 (\"\")  > 4 (\" View/Edit/Delete \") | AUTHORITY:  0 (\"\")  > 4 (\" View/Edit/Delete \") | AUTHORITY:  0 (\"\")  > 4 (\" View/Edit/Delete \") | AUTHORITY:  0 (\"\")  > 4 (\" View/Edit/Delete \") | AUTHORITY:  0 (\"\")  > 4 (\" View/Edit/Delete \") | AUTHORITY:  0 (\"\")  > 4 (\" View/Edit/Delete \")','2021-01-11 15:40:31.585435','Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/87.0.4280.141 Safari/537.36'),(51,'49.146.42.127',1,0,3,0,0,10080,149,0,'add/edit Access rights record','LEVEL: 0 (\"\")  >  2 (\" Super Admin \") | MODULE: 0 (\"\")  >  10120 (\" Devices \") | AUTHORITY:  0 (\"\")  > 0 (\" No Access \") | LEVEL: 0 (\"\")  >  2 (\" Super Admin \") | MODULE: 0 (\"\")  >  10160 (\" Brute Force Login Attempt \") | AUTHORITY:  0 (\"\")  > 0 (\" No Access \") | LEVEL: 0 (\"\")  >  2 (\" Super Admin \") | MODULE: 0 (\"\")  >  10180 (\" Bruteforce IP \") | AUTHORITY:  0 (\"\")  > 0 (\" No Access \") | LEVEL: 0 (\"\")  >  2 (\" Super Admin \") | MODULE: 0 (\"\")  >  15010 (\" Addon: Group License \") | AUTHORITY:  0 (\"\")  > 0 (\" No Access \") | LEVEL: 0 (\"\")  >  2 (\" Super Admin \") | MODULE: 0 (\"\")  >  15030 (\" Addon: User License \") | AUTHORITY:  0 (\"\")  > 0 (\" No Access \") | LEVEL: 0 (\"\")  >  2 (\" Super Admin \") | MODULE: 0 (\"\")  >  15050 (\" Addon: Queuing \") | AUTHORITY:  0 (\"\")  > 0 (\" No Access \") | LEVEL: 0 (\"\")  >  2 (\" Super Admin \") | MODULE: 0 (\"\")  >  15070 (\" Addon: Resource \") | AUTHORITY:  0 (\"\")  > 0 (\" No Access \") | LEVEL: 0 (\"\")  >  2 (\" Super Admin \") | MODULE: 0 (\"\")  >  21030 (\" Section \") | AUTHORITY:  0 (\"\")  > 0 (\" No Access \") | LEVEL: 0 (\"\")  >  2 (\" Super Admin \") | MODULE: 0 (\"\")  >  21050 (\" Entrance \") | AUTHORITY:  0 (\"\")  > 0 (\" No Access \") | AUTHORITY:  0 (\"\")  > 4 (\" View/Edit/Delete \") | AUTHORITY:  0 (\"\")  > 4 (\" View/Edit/Delete \") | AUTHORITY:  0 (\"\")  > 4 (\" View/Edit/Delete \") | AUTHORITY:  0 (\"\")  > 4 (\" View/Edit/Delete \") | AUTHORITY:  0 (\"\")  > 4 (\" View/Edit/Delete \") | AUTHORITY:  0 (\"\")  > 4 (\" View/Edit/Delete \") | AUTHORITY:  0 (\"\")  > 4 (\" View/Edit/Delete \") | AUTHORITY:  0 (\"\")  > 4 (\" View/Edit/Delete \") | AUTHORITY:  0 (\"\")  > 4 (\" View/Edit/Delete \") | AUTHORITY:  0 (\"\")  > 4 (\" View/Edit/Delete \") | AUTHORITY:  0 (\"\")  > 4 (\" View/Edit/Delete \") | AUTHORITY:  0 (\"\")  > 4 (\" View/Edit/Delete \") | AUTHORITY:  0 (\"\")  > 4 (\" View/Edit/Delete \") | AUTHORITY:  0 (\"\")  > 4 (\" View/Edit/Delete \") | AUTHORITY:  0 (\"\")  > 4 (\" View/Edit/Delete \") | AUTHORITY:  0 (\"\")  > 4 (\" View/Edit/Delete \") | AUTHORITY:  0 (\"\")  > 4 (\" View/Edit/Delete \") | AUTHORITY:  0 (\"\")  > 4 (\" View/Edit/Delete \") | AUTHORITY:  0 (\"\")  > 4 (\" View/Edit/Delete \") | AUTHORITY:  0 (\"\")  > 4 (\" View/Edit/Delete \") | AUTHORITY:  0 (\"\")  > 4 (\" View/Edit/Delete \") | AUTHORITY:  0 (\"\")  > 4 (\" View/Edit/Delete \") | AUTHORITY:  0 (\"\")  > 4 (\" View/Edit/Delete \") | AUTHORITY:  0 (\"\")  > 4 (\" View/Edit/Delete \") | AUTHORITY:  0 (\"\")  > 4 (\" View/Edit/Delete \") | AUTHORITY:  0 (\"\")  > 4 (\" View/Edit/Delete \") | AUTHORITY:  0 (\"\")  > 4 (\" View/Edit/Delete \") | AUTHORITY:  0 (\"\")  > 4 (\" View/Edit/Delete \") | AUTHORITY:  0 (\"\")  > 4 (\" View/Edit/Delete \") | AUTHORITY:  0 (\"\")  > 4 (\" View/Edit/Delete \") | AUTHORITY:  0 (\"\")  > 4 (\" View/Edit/Delete \") | AUTHORITY:  0 (\"\")  > 4 (\" View/Edit/Delete \") | AUTHORITY:  0 (\"\")  > 4 (\" View/Edit/Delete \") | AUTHORITY:  0 (\"\")  > 4 (\" View/Edit/Delete \") | AUTHORITY:  0 (\"\")  > 4 (\" View/Edit/Delete \") | AUTHORITY:  0 (\"\")  > 4 (\" View/Edit/Delete \") | AUTHORITY:  0 (\"\")  > 4 (\" View/Edit/Delete \") | AUTHORITY:  0 (\"\")  > 4 (\" View/Edit/Delete \") | AUTHORITY:  0 (\"\")  > 4 (\" View/Edit/Delete \") | AUTHORITY:  0 (\"\")  > 4 (\" View/Edit/Delete \") | AUTHORITY:  0 (\"\")  > 4 (\" View/Edit/Delete \") | AUTHORITY:  0 (\"\")  > 4 (\" View/Edit/Delete \")','2021-01-11 15:40:31.591054','Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/87.0.4280.141 Safari/537.36'),(52,'49.146.42.127',1,0,3,0,0,10080,150,0,'add/edit Access rights record','LEVEL: 0 (\"\")  >  2 (\" Super Admin \") | MODULE: 0 (\"\")  >  10120 (\" Devices \") | AUTHORITY:  0 (\"\")  > 0 (\" No Access \") | LEVEL: 0 (\"\")  >  2 (\" Super Admin \") | MODULE: 0 (\"\")  >  10160 (\" Brute Force Login Attempt \") | AUTHORITY:  0 (\"\")  > 0 (\" No Access \") | LEVEL: 0 (\"\")  >  2 (\" Super Admin \") | MODULE: 0 (\"\")  >  10180 (\" Bruteforce IP \") | AUTHORITY:  0 (\"\")  > 0 (\" No Access \") | LEVEL: 0 (\"\")  >  2 (\" Super Admin \") | MODULE: 0 (\"\")  >  15010 (\" Addon: Group License \") | AUTHORITY:  0 (\"\")  > 0 (\" No Access \") | LEVEL: 0 (\"\")  >  2 (\" Super Admin \") | MODULE: 0 (\"\")  >  15030 (\" Addon: User License \") | AUTHORITY:  0 (\"\")  > 0 (\" No Access \") | LEVEL: 0 (\"\")  >  2 (\" Super Admin \") | MODULE: 0 (\"\")  >  15050 (\" Addon: Queuing \") | AUTHORITY:  0 (\"\")  > 0 (\" No Access \") | LEVEL: 0 (\"\")  >  2 (\" Super Admin \") | MODULE: 0 (\"\")  >  15070 (\" Addon: Resource \") | AUTHORITY:  0 (\"\")  > 0 (\" No Access \") | LEVEL: 0 (\"\")  >  2 (\" Super Admin \") | MODULE: 0 (\"\")  >  21030 (\" Section \") | AUTHORITY:  0 (\"\")  > 0 (\" No Access \") | LEVEL: 0 (\"\")  >  2 (\" Super Admin \") | MODULE: 0 (\"\")  >  21050 (\" Entrance \") | AUTHORITY:  0 (\"\")  > 0 (\" No Access \") | AUTHORITY:  0 (\"\")  > 4 (\" View/Edit/Delete \") | AUTHORITY:  0 (\"\")  > 4 (\" View/Edit/Delete \") | AUTHORITY:  0 (\"\")  > 4 (\" View/Edit/Delete \") | AUTHORITY:  0 (\"\")  > 4 (\" View/Edit/Delete \") | AUTHORITY:  0 (\"\")  > 4 (\" View/Edit/Delete \") | AUTHORITY:  0 (\"\")  > 4 (\" View/Edit/Delete \") | AUTHORITY:  0 (\"\")  > 4 (\" View/Edit/Delete \") | AUTHORITY:  0 (\"\")  > 4 (\" View/Edit/Delete \") | AUTHORITY:  0 (\"\")  > 4 (\" View/Edit/Delete \") | AUTHORITY:  0 (\"\")  > 4 (\" View/Edit/Delete \") | AUTHORITY:  0 (\"\")  > 4 (\" View/Edit/Delete \") | AUTHORITY:  0 (\"\")  > 4 (\" View/Edit/Delete \") | AUTHORITY:  0 (\"\")  > 4 (\" View/Edit/Delete \") | AUTHORITY:  0 (\"\")  > 4 (\" View/Edit/Delete \") | AUTHORITY:  0 (\"\")  > 4 (\" View/Edit/Delete \") | AUTHORITY:  0 (\"\")  > 4 (\" View/Edit/Delete \") | AUTHORITY:  0 (\"\")  > 4 (\" View/Edit/Delete \") | AUTHORITY:  0 (\"\")  > 4 (\" View/Edit/Delete \") | AUTHORITY:  0 (\"\")  > 4 (\" View/Edit/Delete \") | AUTHORITY:  0 (\"\")  > 4 (\" View/Edit/Delete \") | AUTHORITY:  0 (\"\")  > 4 (\" View/Edit/Delete \") | AUTHORITY:  0 (\"\")  > 4 (\" View/Edit/Delete \") | AUTHORITY:  0 (\"\")  > 4 (\" View/Edit/Delete \") | AUTHORITY:  0 (\"\")  > 4 (\" View/Edit/Delete \") | AUTHORITY:  0 (\"\")  > 4 (\" View/Edit/Delete \") | AUTHORITY:  0 (\"\")  > 4 (\" View/Edit/Delete \") | AUTHORITY:  0 (\"\")  > 4 (\" View/Edit/Delete \") | AUTHORITY:  0 (\"\")  > 4 (\" View/Edit/Delete \") | AUTHORITY:  0 (\"\")  > 4 (\" View/Edit/Delete \") | AUTHORITY:  0 (\"\")  > 4 (\" View/Edit/Delete \") | AUTHORITY:  0 (\"\")  > 4 (\" View/Edit/Delete \") | AUTHORITY:  0 (\"\")  > 4 (\" View/Edit/Delete \") | AUTHORITY:  0 (\"\")  > 4 (\" View/Edit/Delete \") | AUTHORITY:  0 (\"\")  > 4 (\" View/Edit/Delete \") | AUTHORITY:  0 (\"\")  > 4 (\" View/Edit/Delete \") | AUTHORITY:  0 (\"\")  > 4 (\" View/Edit/Delete \") | AUTHORITY:  0 (\"\")  > 4 (\" View/Edit/Delete \") | AUTHORITY:  0 (\"\")  > 4 (\" View/Edit/Delete \") | AUTHORITY:  0 (\"\")  > 4 (\" View/Edit/Delete \") | AUTHORITY:  0 (\"\")  > 4 (\" View/Edit/Delete \") | AUTHORITY:  0 (\"\")  > 4 (\" View/Edit/Delete \") | AUTHORITY:  0 (\"\")  > 4 (\" View/Edit/Delete \") | AUTHORITY:  0 (\"\")  > 4 (\" View/Edit/Delete \")','2021-01-11 15:40:31.596598','Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/87.0.4280.141 Safari/537.36'),(53,'49.146.42.127',1,0,3,0,0,10080,151,0,'add/edit Access rights record','LEVEL: 0 (\"\")  >  2 (\" Super Admin \") | MODULE: 0 (\"\")  >  10120 (\" Devices \") | AUTHORITY:  0 (\"\")  > 0 (\" No Access \") | LEVEL: 0 (\"\")  >  2 (\" Super Admin \") | MODULE: 0 (\"\")  >  10160 (\" Brute Force Login Attempt \") | AUTHORITY:  0 (\"\")  > 0 (\" No Access \") | LEVEL: 0 (\"\")  >  2 (\" Super Admin \") | MODULE: 0 (\"\")  >  10180 (\" Bruteforce IP \") | AUTHORITY:  0 (\"\")  > 0 (\" No Access \") | LEVEL: 0 (\"\")  >  2 (\" Super Admin \") | MODULE: 0 (\"\")  >  15010 (\" Addon: Group License \") | AUTHORITY:  0 (\"\")  > 0 (\" No Access \") | LEVEL: 0 (\"\")  >  2 (\" Super Admin \") | MODULE: 0 (\"\")  >  15030 (\" Addon: User License \") | AUTHORITY:  0 (\"\")  > 0 (\" No Access \") | LEVEL: 0 (\"\")  >  2 (\" Super Admin \") | MODULE: 0 (\"\")  >  15050 (\" Addon: Queuing \") | AUTHORITY:  0 (\"\")  > 0 (\" No Access \") | LEVEL: 0 (\"\")  >  2 (\" Super Admin \") | MODULE: 0 (\"\")  >  15070 (\" Addon: Resource \") | AUTHORITY:  0 (\"\")  > 0 (\" No Access \") | LEVEL: 0 (\"\")  >  2 (\" Super Admin \") | MODULE: 0 (\"\")  >  21030 (\" Section \") | AUTHORITY:  0 (\"\")  > 0 (\" No Access \") | LEVEL: 0 (\"\")  >  2 (\" Super Admin \") | MODULE: 0 (\"\")  >  21050 (\" Entrance \") | AUTHORITY:  0 (\"\")  > 0 (\" No Access \") | AUTHORITY:  0 (\"\")  > 4 (\" View/Edit/Delete \") | AUTHORITY:  0 (\"\")  > 4 (\" View/Edit/Delete \") | AUTHORITY:  0 (\"\")  > 4 (\" View/Edit/Delete \") | AUTHORITY:  0 (\"\")  > 4 (\" View/Edit/Delete \") | AUTHORITY:  0 (\"\")  > 4 (\" View/Edit/Delete \") | AUTHORITY:  0 (\"\")  > 4 (\" View/Edit/Delete \") | AUTHORITY:  0 (\"\")  > 4 (\" View/Edit/Delete \") | AUTHORITY:  0 (\"\")  > 4 (\" View/Edit/Delete \") | AUTHORITY:  0 (\"\")  > 4 (\" View/Edit/Delete \") | AUTHORITY:  0 (\"\")  > 4 (\" View/Edit/Delete \") | AUTHORITY:  0 (\"\")  > 4 (\" View/Edit/Delete \") | AUTHORITY:  0 (\"\")  > 4 (\" View/Edit/Delete \") | AUTHORITY:  0 (\"\")  > 4 (\" View/Edit/Delete \") | AUTHORITY:  0 (\"\")  > 4 (\" View/Edit/Delete \") | AUTHORITY:  0 (\"\")  > 4 (\" View/Edit/Delete \") | AUTHORITY:  0 (\"\")  > 4 (\" View/Edit/Delete \") | AUTHORITY:  0 (\"\")  > 4 (\" View/Edit/Delete \") | AUTHORITY:  0 (\"\")  > 4 (\" View/Edit/Delete \") | AUTHORITY:  0 (\"\")  > 4 (\" View/Edit/Delete \") | AUTHORITY:  0 (\"\")  > 4 (\" View/Edit/Delete \") | AUTHORITY:  0 (\"\")  > 4 (\" View/Edit/Delete \") | AUTHORITY:  0 (\"\")  > 4 (\" View/Edit/Delete \") | AUTHORITY:  0 (\"\")  > 4 (\" View/Edit/Delete \") | AUTHORITY:  0 (\"\")  > 4 (\" View/Edit/Delete \") | AUTHORITY:  0 (\"\")  > 4 (\" View/Edit/Delete \") | AUTHORITY:  0 (\"\")  > 4 (\" View/Edit/Delete \") | AUTHORITY:  0 (\"\")  > 4 (\" View/Edit/Delete \") | AUTHORITY:  0 (\"\")  > 4 (\" View/Edit/Delete \") | AUTHORITY:  0 (\"\")  > 4 (\" View/Edit/Delete \") | AUTHORITY:  0 (\"\")  > 4 (\" View/Edit/Delete \") | AUTHORITY:  0 (\"\")  > 4 (\" View/Edit/Delete \") | AUTHORITY:  0 (\"\")  > 4 (\" View/Edit/Delete \") | AUTHORITY:  0 (\"\")  > 4 (\" View/Edit/Delete \") | AUTHORITY:  0 (\"\")  > 4 (\" View/Edit/Delete \") | AUTHORITY:  0 (\"\")  > 4 (\" View/Edit/Delete \") | AUTHORITY:  0 (\"\")  > 4 (\" View/Edit/Delete \") | AUTHORITY:  0 (\"\")  > 4 (\" View/Edit/Delete \") | AUTHORITY:  0 (\"\")  > 4 (\" View/Edit/Delete \") | AUTHORITY:  0 (\"\")  > 4 (\" View/Edit/Delete \") | AUTHORITY:  0 (\"\")  > 4 (\" View/Edit/Delete \") | AUTHORITY:  0 (\"\")  > 4 (\" View/Edit/Delete \") | AUTHORITY:  0 (\"\")  > 4 (\" View/Edit/Delete \") | AUTHORITY:  0 (\"\")  > 4 (\" View/Edit/Delete \") | AUTHORITY:  0 (\"\")  > 4 (\" View/Edit/Delete \")','2021-01-11 15:40:31.602465','Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/87.0.4280.141 Safari/537.36'),(54,'49.146.42.127',1,0,3,0,0,10080,152,0,'add/edit Access rights record','LEVEL: 0 (\"\")  >  2 (\" Super Admin \") | MODULE: 0 (\"\")  >  10120 (\" Devices \") | AUTHORITY:  0 (\"\")  > 0 (\" No Access \") | LEVEL: 0 (\"\")  >  2 (\" Super Admin \") | MODULE: 0 (\"\")  >  10160 (\" Brute Force Login Attempt \") | AUTHORITY:  0 (\"\")  > 0 (\" No Access \") | LEVEL: 0 (\"\")  >  2 (\" Super Admin \") | MODULE: 0 (\"\")  >  10180 (\" Bruteforce IP \") | AUTHORITY:  0 (\"\")  > 0 (\" No Access \") | LEVEL: 0 (\"\")  >  2 (\" Super Admin \") | MODULE: 0 (\"\")  >  15010 (\" Addon: Group License \") | AUTHORITY:  0 (\"\")  > 0 (\" No Access \") | LEVEL: 0 (\"\")  >  2 (\" Super Admin \") | MODULE: 0 (\"\")  >  15030 (\" Addon: User License \") | AUTHORITY:  0 (\"\")  > 0 (\" No Access \") | LEVEL: 0 (\"\")  >  2 (\" Super Admin \") | MODULE: 0 (\"\")  >  15050 (\" Addon: Queuing \") | AUTHORITY:  0 (\"\")  > 0 (\" No Access \") | LEVEL: 0 (\"\")  >  2 (\" Super Admin \") | MODULE: 0 (\"\")  >  15070 (\" Addon: Resource \") | AUTHORITY:  0 (\"\")  > 0 (\" No Access \") | LEVEL: 0 (\"\")  >  2 (\" Super Admin \") | MODULE: 0 (\"\")  >  21030 (\" Section \") | AUTHORITY:  0 (\"\")  > 0 (\" No Access \") | LEVEL: 0 (\"\")  >  2 (\" Super Admin \") | MODULE: 0 (\"\")  >  21050 (\" Entrance \") | AUTHORITY:  0 (\"\")  > 0 (\" No Access \") | AUTHORITY:  0 (\"\")  > 4 (\" View/Edit/Delete \") | AUTHORITY:  0 (\"\")  > 4 (\" View/Edit/Delete \") | AUTHORITY:  0 (\"\")  > 4 (\" View/Edit/Delete \") | AUTHORITY:  0 (\"\")  > 4 (\" View/Edit/Delete \") | AUTHORITY:  0 (\"\")  > 4 (\" View/Edit/Delete \") | AUTHORITY:  0 (\"\")  > 4 (\" View/Edit/Delete \") | AUTHORITY:  0 (\"\")  > 4 (\" View/Edit/Delete \") | AUTHORITY:  0 (\"\")  > 4 (\" View/Edit/Delete \") | AUTHORITY:  0 (\"\")  > 4 (\" View/Edit/Delete \") | AUTHORITY:  0 (\"\")  > 4 (\" View/Edit/Delete \") | AUTHORITY:  0 (\"\")  > 4 (\" View/Edit/Delete \") | AUTHORITY:  0 (\"\")  > 4 (\" View/Edit/Delete \") | AUTHORITY:  0 (\"\")  > 4 (\" View/Edit/Delete \") | AUTHORITY:  0 (\"\")  > 4 (\" View/Edit/Delete \") | AUTHORITY:  0 (\"\")  > 4 (\" View/Edit/Delete \") | AUTHORITY:  0 (\"\")  > 4 (\" View/Edit/Delete \") | AUTHORITY:  0 (\"\")  > 4 (\" View/Edit/Delete \") | AUTHORITY:  0 (\"\")  > 4 (\" View/Edit/Delete \") | AUTHORITY:  0 (\"\")  > 4 (\" View/Edit/Delete \") | AUTHORITY:  0 (\"\")  > 4 (\" View/Edit/Delete \") | AUTHORITY:  0 (\"\")  > 4 (\" View/Edit/Delete \") | AUTHORITY:  0 (\"\")  > 4 (\" View/Edit/Delete \") | AUTHORITY:  0 (\"\")  > 4 (\" View/Edit/Delete \") | AUTHORITY:  0 (\"\")  > 4 (\" View/Edit/Delete \") | AUTHORITY:  0 (\"\")  > 4 (\" View/Edit/Delete \") | AUTHORITY:  0 (\"\")  > 4 (\" View/Edit/Delete \") | AUTHORITY:  0 (\"\")  > 4 (\" View/Edit/Delete \") | AUTHORITY:  0 (\"\")  > 4 (\" View/Edit/Delete \") | AUTHORITY:  0 (\"\")  > 4 (\" View/Edit/Delete \") | AUTHORITY:  0 (\"\")  > 4 (\" View/Edit/Delete \") | AUTHORITY:  0 (\"\")  > 4 (\" View/Edit/Delete \") | AUTHORITY:  0 (\"\")  > 4 (\" View/Edit/Delete \") | AUTHORITY:  0 (\"\")  > 4 (\" View/Edit/Delete \") | AUTHORITY:  0 (\"\")  > 4 (\" View/Edit/Delete \") | AUTHORITY:  0 (\"\")  > 4 (\" View/Edit/Delete \") | AUTHORITY:  0 (\"\")  > 4 (\" View/Edit/Delete \") | AUTHORITY:  0 (\"\")  > 4 (\" View/Edit/Delete \") | AUTHORITY:  0 (\"\")  > 4 (\" View/Edit/Delete \") | AUTHORITY:  0 (\"\")  > 4 (\" View/Edit/Delete \") | AUTHORITY:  0 (\"\")  > 4 (\" View/Edit/Delete \") | AUTHORITY:  0 (\"\")  > 4 (\" View/Edit/Delete \") | AUTHORITY:  0 (\"\")  > 4 (\" View/Edit/Delete \") | AUTHORITY:  0 (\"\")  > 4 (\" View/Edit/Delete \") | AUTHORITY:  0 (\"\")  > 4 (\" View/Edit/Delete \") | AUTHORITY:  0 (\"\")  > 4 (\" View/Edit/Delete \")','2021-01-11 15:40:31.608790','Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/87.0.4280.141 Safari/537.36'),(55,'49.146.42.127',1,0,3,0,0,10080,153,0,'add/edit Access rights record','LEVEL: 0 (\"\")  >  2 (\" Super Admin \") | MODULE: 0 (\"\")  >  10120 (\" Devices \") | AUTHORITY:  0 (\"\")  > 0 (\" No Access \") | LEVEL: 0 (\"\")  >  2 (\" Super Admin \") | MODULE: 0 (\"\")  >  10160 (\" Brute Force Login Attempt \") | AUTHORITY:  0 (\"\")  > 0 (\" No Access \") | LEVEL: 0 (\"\")  >  2 (\" Super Admin \") | MODULE: 0 (\"\")  >  10180 (\" Bruteforce IP \") | AUTHORITY:  0 (\"\")  > 0 (\" No Access \") | LEVEL: 0 (\"\")  >  2 (\" Super Admin \") | MODULE: 0 (\"\")  >  15010 (\" Addon: Group License \") | AUTHORITY:  0 (\"\")  > 0 (\" No Access \") | LEVEL: 0 (\"\")  >  2 (\" Super Admin \") | MODULE: 0 (\"\")  >  15030 (\" Addon: User License \") | AUTHORITY:  0 (\"\")  > 0 (\" No Access \") | LEVEL: 0 (\"\")  >  2 (\" Super Admin \") | MODULE: 0 (\"\")  >  15050 (\" Addon: Queuing \") | AUTHORITY:  0 (\"\")  > 0 (\" No Access \") | LEVEL: 0 (\"\")  >  2 (\" Super Admin \") | MODULE: 0 (\"\")  >  15070 (\" Addon: Resource \") | AUTHORITY:  0 (\"\")  > 0 (\" No Access \") | LEVEL: 0 (\"\")  >  2 (\" Super Admin \") | MODULE: 0 (\"\")  >  21030 (\" Section \") | AUTHORITY:  0 (\"\")  > 0 (\" No Access \") | LEVEL: 0 (\"\")  >  2 (\" Super Admin \") | MODULE: 0 (\"\")  >  21050 (\" Entrance \") | AUTHORITY:  0 (\"\")  > 0 (\" No Access \") | AUTHORITY:  0 (\"\")  > 4 (\" View/Edit/Delete \") | AUTHORITY:  0 (\"\")  > 4 (\" View/Edit/Delete \") | AUTHORITY:  0 (\"\")  > 4 (\" View/Edit/Delete \") | AUTHORITY:  0 (\"\")  > 4 (\" View/Edit/Delete \") | AUTHORITY:  0 (\"\")  > 4 (\" View/Edit/Delete \") | AUTHORITY:  0 (\"\")  > 4 (\" View/Edit/Delete \") | AUTHORITY:  0 (\"\")  > 4 (\" View/Edit/Delete \") | AUTHORITY:  0 (\"\")  > 4 (\" View/Edit/Delete \") | AUTHORITY:  0 (\"\")  > 4 (\" View/Edit/Delete \") | AUTHORITY:  0 (\"\")  > 4 (\" View/Edit/Delete \") | AUTHORITY:  0 (\"\")  > 4 (\" View/Edit/Delete \") | AUTHORITY:  0 (\"\")  > 4 (\" View/Edit/Delete \") | AUTHORITY:  0 (\"\")  > 4 (\" View/Edit/Delete \") | AUTHORITY:  0 (\"\")  > 4 (\" View/Edit/Delete \") | AUTHORITY:  0 (\"\")  > 4 (\" View/Edit/Delete \") | AUTHORITY:  0 (\"\")  > 4 (\" View/Edit/Delete \") | AUTHORITY:  0 (\"\")  > 4 (\" View/Edit/Delete \") | AUTHORITY:  0 (\"\")  > 4 (\" View/Edit/Delete \") | AUTHORITY:  0 (\"\")  > 4 (\" View/Edit/Delete \") | AUTHORITY:  0 (\"\")  > 4 (\" View/Edit/Delete \") | AUTHORITY:  0 (\"\")  > 4 (\" View/Edit/Delete \") | AUTHORITY:  0 (\"\")  > 4 (\" View/Edit/Delete \") | AUTHORITY:  0 (\"\")  > 4 (\" View/Edit/Delete \") | AUTHORITY:  0 (\"\")  > 4 (\" View/Edit/Delete \") | AUTHORITY:  0 (\"\")  > 4 (\" View/Edit/Delete \") | AUTHORITY:  0 (\"\")  > 4 (\" View/Edit/Delete \") | AUTHORITY:  0 (\"\")  > 4 (\" View/Edit/Delete \") | AUTHORITY:  0 (\"\")  > 4 (\" View/Edit/Delete \") | AUTHORITY:  0 (\"\")  > 4 (\" View/Edit/Delete \") | AUTHORITY:  0 (\"\")  > 4 (\" View/Edit/Delete \") | AUTHORITY:  0 (\"\")  > 4 (\" View/Edit/Delete \") | AUTHORITY:  0 (\"\")  > 4 (\" View/Edit/Delete \") | AUTHORITY:  0 (\"\")  > 4 (\" View/Edit/Delete \") | AUTHORITY:  0 (\"\")  > 4 (\" View/Edit/Delete \") | AUTHORITY:  0 (\"\")  > 4 (\" View/Edit/Delete \") | AUTHORITY:  0 (\"\")  > 4 (\" View/Edit/Delete \") | AUTHORITY:  0 (\"\")  > 4 (\" View/Edit/Delete \") | AUTHORITY:  0 (\"\")  > 4 (\" View/Edit/Delete \") | AUTHORITY:  0 (\"\")  > 4 (\" View/Edit/Delete \") | AUTHORITY:  0 (\"\")  > 4 (\" View/Edit/Delete \") | AUTHORITY:  0 (\"\")  > 4 (\" View/Edit/Delete \") | AUTHORITY:  0 (\"\")  > 4 (\" View/Edit/Delete \") | AUTHORITY:  0 (\"\")  > 4 (\" View/Edit/Delete \") | AUTHORITY:  0 (\"\")  > 4 (\" View/Edit/Delete \") | AUTHORITY:  0 (\"\")  > 4 (\" View/Edit/Delete \") | AUTHORITY:  0 (\"\")  > 4 (\" View/Edit/Delete \")','2021-01-11 15:40:32.208023','Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/87.0.4280.141 Safari/537.36'),(56,'49.146.42.127',1,0,3,0,0,10080,154,0,'add/edit Access rights record','LEVEL: 0 (\"\")  >  2 (\" Super Admin \") | MODULE: 0 (\"\")  >  10120 (\" Devices \") | AUTHORITY:  0 (\"\")  > 0 (\" No Access \") | LEVEL: 0 (\"\")  >  2 (\" Super Admin \") | MODULE: 0 (\"\")  >  10160 (\" Brute Force Login Attempt \") | AUTHORITY:  0 (\"\")  > 0 (\" No Access \") | LEVEL: 0 (\"\")  >  2 (\" Super Admin \") | MODULE: 0 (\"\")  >  10180 (\" Bruteforce IP \") | AUTHORITY:  0 (\"\")  > 0 (\" No Access \") | LEVEL: 0 (\"\")  >  2 (\" Super Admin \") | MODULE: 0 (\"\")  >  15010 (\" Addon: Group License \") | AUTHORITY:  0 (\"\")  > 0 (\" No Access \") | LEVEL: 0 (\"\")  >  2 (\" Super Admin \") | MODULE: 0 (\"\")  >  15030 (\" Addon: User License \") | AUTHORITY:  0 (\"\")  > 0 (\" No Access \") | LEVEL: 0 (\"\")  >  2 (\" Super Admin \") | MODULE: 0 (\"\")  >  15050 (\" Addon: Queuing \") | AUTHORITY:  0 (\"\")  > 0 (\" No Access \") | LEVEL: 0 (\"\")  >  2 (\" Super Admin \") | MODULE: 0 (\"\")  >  15070 (\" Addon: Resource \") | AUTHORITY:  0 (\"\")  > 0 (\" No Access \") | LEVEL: 0 (\"\")  >  2 (\" Super Admin \") | MODULE: 0 (\"\")  >  21030 (\" Section \") | AUTHORITY:  0 (\"\")  > 0 (\" No Access \") | LEVEL: 0 (\"\")  >  2 (\" Super Admin \") | MODULE: 0 (\"\")  >  21050 (\" Entrance \") | AUTHORITY:  0 (\"\")  > 0 (\" No Access \") | AUTHORITY:  0 (\"\")  > 4 (\" View/Edit/Delete \") | AUTHORITY:  0 (\"\")  > 4 (\" View/Edit/Delete \") | AUTHORITY:  0 (\"\")  > 4 (\" View/Edit/Delete \") | AUTHORITY:  0 (\"\")  > 4 (\" View/Edit/Delete \") | AUTHORITY:  0 (\"\")  > 4 (\" View/Edit/Delete \") | AUTHORITY:  0 (\"\")  > 4 (\" View/Edit/Delete \") | AUTHORITY:  0 (\"\")  > 4 (\" View/Edit/Delete \") | AUTHORITY:  0 (\"\")  > 4 (\" View/Edit/Delete \") | AUTHORITY:  0 (\"\")  > 4 (\" View/Edit/Delete \") | AUTHORITY:  0 (\"\")  > 4 (\" View/Edit/Delete \") | AUTHORITY:  0 (\"\")  > 4 (\" View/Edit/Delete \") | AUTHORITY:  0 (\"\")  > 4 (\" View/Edit/Delete \") | AUTHORITY:  0 (\"\")  > 4 (\" View/Edit/Delete \") | AUTHORITY:  0 (\"\")  > 4 (\" View/Edit/Delete \") | AUTHORITY:  0 (\"\")  > 4 (\" View/Edit/Delete \") | AUTHORITY:  0 (\"\")  > 4 (\" View/Edit/Delete \") | AUTHORITY:  0 (\"\")  > 4 (\" View/Edit/Delete \") | AUTHORITY:  0 (\"\")  > 4 (\" View/Edit/Delete \") | AUTHORITY:  0 (\"\")  > 4 (\" View/Edit/Delete \") | AUTHORITY:  0 (\"\")  > 4 (\" View/Edit/Delete \") | AUTHORITY:  0 (\"\")  > 4 (\" View/Edit/Delete \") | AUTHORITY:  0 (\"\")  > 4 (\" View/Edit/Delete \") | AUTHORITY:  0 (\"\")  > 4 (\" View/Edit/Delete \") | AUTHORITY:  0 (\"\")  > 4 (\" View/Edit/Delete \") | AUTHORITY:  0 (\"\")  > 4 (\" View/Edit/Delete \") | AUTHORITY:  0 (\"\")  > 4 (\" View/Edit/Delete \") | AUTHORITY:  0 (\"\")  > 4 (\" View/Edit/Delete \") | AUTHORITY:  0 (\"\")  > 4 (\" View/Edit/Delete \") | AUTHORITY:  0 (\"\")  > 4 (\" View/Edit/Delete \") | AUTHORITY:  0 (\"\")  > 4 (\" View/Edit/Delete \") | AUTHORITY:  0 (\"\")  > 4 (\" View/Edit/Delete \") | AUTHORITY:  0 (\"\")  > 4 (\" View/Edit/Delete \") | AUTHORITY:  0 (\"\")  > 4 (\" View/Edit/Delete \") | AUTHORITY:  0 (\"\")  > 4 (\" View/Edit/Delete \") | AUTHORITY:  0 (\"\")  > 4 (\" View/Edit/Delete \") | AUTHORITY:  0 (\"\")  > 4 (\" View/Edit/Delete \") | AUTHORITY:  0 (\"\")  > 4 (\" View/Edit/Delete \") | AUTHORITY:  0 (\"\")  > 4 (\" View/Edit/Delete \") | AUTHORITY:  0 (\"\")  > 4 (\" View/Edit/Delete \") | AUTHORITY:  0 (\"\")  > 4 (\" View/Edit/Delete \") | AUTHORITY:  0 (\"\")  > 4 (\" View/Edit/Delete \") | AUTHORITY:  0 (\"\")  > 4 (\" View/Edit/Delete \") | AUTHORITY:  0 (\"\")  > 4 (\" View/Edit/Delete \") | AUTHORITY:  0 (\"\")  > 4 (\" View/Edit/Delete \") | AUTHORITY:  0 (\"\")  > 4 (\" View/Edit/Delete \") | AUTHORITY:  0 (\"\")  > 4 (\" View/Edit/Delete \") | AUTHORITY:  0 (\"\")  > 4 (\" View/Edit/Delete \")','2021-01-11 15:40:32.212379','Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/87.0.4280.141 Safari/537.36'),(57,'49.146.42.127',1,0,3,0,0,10080,283,0,'add/edit Access rights record','LEVEL: 0 (\"\")  >  2 (\" Super Admin \") | MODULE: 0 (\"\")  >  10120 (\" Devices \") | AUTHORITY:  0 (\"\")  > 0 (\" No Access \") | LEVEL: 0 (\"\")  >  2 (\" Super Admin \") | MODULE: 0 (\"\")  >  10160 (\" Brute Force Login Attempt \") | AUTHORITY:  0 (\"\")  > 0 (\" No Access \") | LEVEL: 0 (\"\")  >  2 (\" Super Admin \") | MODULE: 0 (\"\")  >  10180 (\" Bruteforce IP \") | AUTHORITY:  0 (\"\")  > 0 (\" No Access \") | LEVEL: 0 (\"\")  >  2 (\" Super Admin \") | MODULE: 0 (\"\")  >  15010 (\" Addon: Group License \") | AUTHORITY:  0 (\"\")  > 0 (\" No Access \") | LEVEL: 0 (\"\")  >  2 (\" Super Admin \") | MODULE: 0 (\"\")  >  15030 (\" Addon: User License \") | AUTHORITY:  0 (\"\")  > 0 (\" No Access \") | LEVEL: 0 (\"\")  >  2 (\" Super Admin \") | MODULE: 0 (\"\")  >  15050 (\" Addon: Queuing \") | AUTHORITY:  0 (\"\")  > 0 (\" No Access \") | LEVEL: 0 (\"\")  >  2 (\" Super Admin \") | MODULE: 0 (\"\")  >  15070 (\" Addon: Resource \") | AUTHORITY:  0 (\"\")  > 0 (\" No Access \") | LEVEL: 0 (\"\")  >  2 (\" Super Admin \") | MODULE: 0 (\"\")  >  21030 (\" Section \") | AUTHORITY:  0 (\"\")  > 0 (\" No Access \") | LEVEL: 0 (\"\")  >  2 (\" Super Admin \") | MODULE: 0 (\"\")  >  21050 (\" Entrance \") | AUTHORITY:  0 (\"\")  > 0 (\" No Access \") | AUTHORITY:  0 (\"\")  > 4 (\" View/Edit/Delete \") | AUTHORITY:  0 (\"\")  > 4 (\" View/Edit/Delete \") | AUTHORITY:  0 (\"\")  > 4 (\" View/Edit/Delete \") | AUTHORITY:  0 (\"\")  > 4 (\" View/Edit/Delete \") | AUTHORITY:  0 (\"\")  > 4 (\" View/Edit/Delete \") | AUTHORITY:  0 (\"\")  > 4 (\" View/Edit/Delete \") | AUTHORITY:  0 (\"\")  > 4 (\" View/Edit/Delete \") | AUTHORITY:  0 (\"\")  > 4 (\" View/Edit/Delete \") | AUTHORITY:  0 (\"\")  > 4 (\" View/Edit/Delete \") | AUTHORITY:  0 (\"\")  > 4 (\" View/Edit/Delete \") | AUTHORITY:  0 (\"\")  > 4 (\" View/Edit/Delete \") | AUTHORITY:  0 (\"\")  > 4 (\" View/Edit/Delete \") | AUTHORITY:  0 (\"\")  > 4 (\" View/Edit/Delete \") | AUTHORITY:  0 (\"\")  > 4 (\" View/Edit/Delete \") | AUTHORITY:  0 (\"\")  > 4 (\" View/Edit/Delete \") | AUTHORITY:  0 (\"\")  > 4 (\" View/Edit/Delete \") | AUTHORITY:  0 (\"\")  > 4 (\" View/Edit/Delete \") | AUTHORITY:  0 (\"\")  > 4 (\" View/Edit/Delete \") | AUTHORITY:  0 (\"\")  > 4 (\" View/Edit/Delete \") | AUTHORITY:  0 (\"\")  > 4 (\" View/Edit/Delete \") | AUTHORITY:  0 (\"\")  > 4 (\" View/Edit/Delete \") | AUTHORITY:  0 (\"\")  > 4 (\" View/Edit/Delete \") | AUTHORITY:  0 (\"\")  > 4 (\" View/Edit/Delete \") | AUTHORITY:  0 (\"\")  > 4 (\" View/Edit/Delete \") | AUTHORITY:  0 (\"\")  > 4 (\" View/Edit/Delete \") | AUTHORITY:  0 (\"\")  > 4 (\" View/Edit/Delete \") | AUTHORITY:  0 (\"\")  > 4 (\" View/Edit/Delete \") | AUTHORITY:  0 (\"\")  > 4 (\" View/Edit/Delete \") | AUTHORITY:  0 (\"\")  > 4 (\" View/Edit/Delete \") | AUTHORITY:  0 (\"\")  > 4 (\" View/Edit/Delete \") | AUTHORITY:  0 (\"\")  > 4 (\" View/Edit/Delete \") | AUTHORITY:  0 (\"\")  > 4 (\" View/Edit/Delete \") | AUTHORITY:  0 (\"\")  > 4 (\" View/Edit/Delete \") | AUTHORITY:  0 (\"\")  > 4 (\" View/Edit/Delete \") | AUTHORITY:  0 (\"\")  > 4 (\" View/Edit/Delete \") | AUTHORITY:  0 (\"\")  > 4 (\" View/Edit/Delete \") | AUTHORITY:  0 (\"\")  > 4 (\" View/Edit/Delete \") | AUTHORITY:  0 (\"\")  > 4 (\" View/Edit/Delete \") | AUTHORITY:  0 (\"\")  > 4 (\" View/Edit/Delete \") | AUTHORITY:  0 (\"\")  > 4 (\" View/Edit/Delete \") | AUTHORITY:  0 (\"\")  > 4 (\" View/Edit/Delete \") | AUTHORITY:  0 (\"\")  > 4 (\" View/Edit/Delete \") | AUTHORITY:  0 (\"\")  > 4 (\" View/Edit/Delete \") | AUTHORITY:  0 (\"\")  > 4 (\" View/Edit/Delete \") | AUTHORITY:  0 (\"\")  > 4 (\" View/Edit/Delete \") | AUTHORITY:  0 (\"\")  > 4 (\" View/Edit/Delete \") | AUTHORITY:  0 (\"\")  > 4 (\" View/Edit/Delete \") | AUTHORITY:  0 (\"\")  > 4 (\" View/Edit/Delete \")','2021-01-11 15:40:32.218432','Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/87.0.4280.141 Safari/537.36'),(58,'49.146.42.127',1,0,3,0,0,10080,284,0,'add/edit Access rights record','LEVEL: 0 (\"\")  >  2 (\" Super Admin \") | MODULE: 0 (\"\")  >  10120 (\" Devices \") | AUTHORITY:  0 (\"\")  > 0 (\" No Access \") | LEVEL: 0 (\"\")  >  2 (\" Super Admin \") | MODULE: 0 (\"\")  >  10160 (\" Brute Force Login Attempt \") | AUTHORITY:  0 (\"\")  > 0 (\" No Access \") | LEVEL: 0 (\"\")  >  2 (\" Super Admin \") | MODULE: 0 (\"\")  >  10180 (\" Bruteforce IP \") | AUTHORITY:  0 (\"\")  > 0 (\" No Access \") | LEVEL: 0 (\"\")  >  2 (\" Super Admin \") | MODULE: 0 (\"\")  >  15010 (\" Addon: Group License \") | AUTHORITY:  0 (\"\")  > 0 (\" No Access \") | LEVEL: 0 (\"\")  >  2 (\" Super Admin \") | MODULE: 0 (\"\")  >  15030 (\" Addon: User License \") | AUTHORITY:  0 (\"\")  > 0 (\" No Access \") | LEVEL: 0 (\"\")  >  2 (\" Super Admin \") | MODULE: 0 (\"\")  >  15050 (\" Addon: Queuing \") | AUTHORITY:  0 (\"\")  > 0 (\" No Access \") | LEVEL: 0 (\"\")  >  2 (\" Super Admin \") | MODULE: 0 (\"\")  >  15070 (\" Addon: Resource \") | AUTHORITY:  0 (\"\")  > 0 (\" No Access \") | LEVEL: 0 (\"\")  >  2 (\" Super Admin \") | MODULE: 0 (\"\")  >  21030 (\" Section \") | AUTHORITY:  0 (\"\")  > 0 (\" No Access \") | LEVEL: 0 (\"\")  >  2 (\" Super Admin \") | MODULE: 0 (\"\")  >  21050 (\" Entrance \") | AUTHORITY:  0 (\"\")  > 0 (\" No Access \") | AUTHORITY:  0 (\"\")  > 4 (\" View/Edit/Delete \") | AUTHORITY:  0 (\"\")  > 4 (\" View/Edit/Delete \") | AUTHORITY:  0 (\"\")  > 4 (\" View/Edit/Delete \") | AUTHORITY:  0 (\"\")  > 4 (\" View/Edit/Delete \") | AUTHORITY:  0 (\"\")  > 4 (\" View/Edit/Delete \") | AUTHORITY:  0 (\"\")  > 4 (\" View/Edit/Delete \") | AUTHORITY:  0 (\"\")  > 4 (\" View/Edit/Delete \") | AUTHORITY:  0 (\"\")  > 4 (\" View/Edit/Delete \") | AUTHORITY:  0 (\"\")  > 4 (\" View/Edit/Delete \") | AUTHORITY:  0 (\"\")  > 4 (\" View/Edit/Delete \") | AUTHORITY:  0 (\"\")  > 4 (\" View/Edit/Delete \") | AUTHORITY:  0 (\"\")  > 4 (\" View/Edit/Delete \") | AUTHORITY:  0 (\"\")  > 4 (\" View/Edit/Delete \") | AUTHORITY:  0 (\"\")  > 4 (\" View/Edit/Delete \") | AUTHORITY:  0 (\"\")  > 4 (\" View/Edit/Delete \") | AUTHORITY:  0 (\"\")  > 4 (\" View/Edit/Delete \") | AUTHORITY:  0 (\"\")  > 4 (\" View/Edit/Delete \") | AUTHORITY:  0 (\"\")  > 4 (\" View/Edit/Delete \") | AUTHORITY:  0 (\"\")  > 4 (\" View/Edit/Delete \") | AUTHORITY:  0 (\"\")  > 4 (\" View/Edit/Delete \") | AUTHORITY:  0 (\"\")  > 4 (\" View/Edit/Delete \") | AUTHORITY:  0 (\"\")  > 4 (\" View/Edit/Delete \") | AUTHORITY:  0 (\"\")  > 4 (\" View/Edit/Delete \") | AUTHORITY:  0 (\"\")  > 4 (\" View/Edit/Delete \") | AUTHORITY:  0 (\"\")  > 4 (\" View/Edit/Delete \") | AUTHORITY:  0 (\"\")  > 4 (\" View/Edit/Delete \") | AUTHORITY:  0 (\"\")  > 4 (\" View/Edit/Delete \") | AUTHORITY:  0 (\"\")  > 4 (\" View/Edit/Delete \") | AUTHORITY:  0 (\"\")  > 4 (\" View/Edit/Delete \") | AUTHORITY:  0 (\"\")  > 4 (\" View/Edit/Delete \") | AUTHORITY:  0 (\"\")  > 4 (\" View/Edit/Delete \") | AUTHORITY:  0 (\"\")  > 4 (\" View/Edit/Delete \") | AUTHORITY:  0 (\"\")  > 4 (\" View/Edit/Delete \") | AUTHORITY:  0 (\"\")  > 4 (\" View/Edit/Delete \") | AUTHORITY:  0 (\"\")  > 4 (\" View/Edit/Delete \") | AUTHORITY:  0 (\"\")  > 4 (\" View/Edit/Delete \") | AUTHORITY:  0 (\"\")  > 4 (\" View/Edit/Delete \") | AUTHORITY:  0 (\"\")  > 4 (\" View/Edit/Delete \") | AUTHORITY:  0 (\"\")  > 4 (\" View/Edit/Delete \") | AUTHORITY:  0 (\"\")  > 4 (\" View/Edit/Delete \") | AUTHORITY:  0 (\"\")  > 4 (\" View/Edit/Delete \") | AUTHORITY:  0 (\"\")  > 4 (\" View/Edit/Delete \") | AUTHORITY:  0 (\"\")  > 4 (\" View/Edit/Delete \") | AUTHORITY:  0 (\"\")  > 4 (\" View/Edit/Delete \") | AUTHORITY:  0 (\"\")  > 4 (\" View/Edit/Delete \") | AUTHORITY:  0 (\"\")  > 4 (\" View/Edit/Delete \") | AUTHORITY:  0 (\"\")  > 4 (\" View/Edit/Delete \") | AUTHORITY:  0 (\"\")  > 4 (\" View/Edit/Delete \") | AUTHORITY:  0 (\"\")  > 4 (\" View/Edit/Delete \")','2021-01-11 15:40:32.223010','Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/87.0.4280.141 Safari/537.36'),(59,'49.146.42.127',1,0,3,0,0,10080,285,0,'add/edit Access rights record','LEVEL: 0 (\"\")  >  2 (\" Super Admin \") | MODULE: 0 (\"\")  >  10120 (\" Devices \") | AUTHORITY:  0 (\"\")  > 0 (\" No Access \") | LEVEL: 0 (\"\")  >  2 (\" Super Admin \") | MODULE: 0 (\"\")  >  10160 (\" Brute Force Login Attempt \") | AUTHORITY:  0 (\"\")  > 0 (\" No Access \") | LEVEL: 0 (\"\")  >  2 (\" Super Admin \") | MODULE: 0 (\"\")  >  10180 (\" Bruteforce IP \") | AUTHORITY:  0 (\"\")  > 0 (\" No Access \") | LEVEL: 0 (\"\")  >  2 (\" Super Admin \") | MODULE: 0 (\"\")  >  15010 (\" Addon: Group License \") | AUTHORITY:  0 (\"\")  > 0 (\" No Access \") | LEVEL: 0 (\"\")  >  2 (\" Super Admin \") | MODULE: 0 (\"\")  >  15030 (\" Addon: User License \") | AUTHORITY:  0 (\"\")  > 0 (\" No Access \") | LEVEL: 0 (\"\")  >  2 (\" Super Admin \") | MODULE: 0 (\"\")  >  15050 (\" Addon: Queuing \") | AUTHORITY:  0 (\"\")  > 0 (\" No Access \") | LEVEL: 0 (\"\")  >  2 (\" Super Admin \") | MODULE: 0 (\"\")  >  15070 (\" Addon: Resource \") | AUTHORITY:  0 (\"\")  > 0 (\" No Access \") | LEVEL: 0 (\"\")  >  2 (\" Super Admin \") | MODULE: 0 (\"\")  >  21030 (\" Section \") | AUTHORITY:  0 (\"\")  > 0 (\" No Access \") | LEVEL: 0 (\"\")  >  2 (\" Super Admin \") | MODULE: 0 (\"\")  >  21050 (\" Entrance \") | AUTHORITY:  0 (\"\")  > 0 (\" No Access \") | AUTHORITY:  0 (\"\")  > 4 (\" View/Edit/Delete \") | AUTHORITY:  0 (\"\")  > 4 (\" View/Edit/Delete \") | AUTHORITY:  0 (\"\")  > 4 (\" View/Edit/Delete \") | AUTHORITY:  0 (\"\")  > 4 (\" View/Edit/Delete \") | AUTHORITY:  0 (\"\")  > 4 (\" View/Edit/Delete \") | AUTHORITY:  0 (\"\")  > 4 (\" View/Edit/Delete \") | AUTHORITY:  0 (\"\")  > 4 (\" View/Edit/Delete \") | AUTHORITY:  0 (\"\")  > 4 (\" View/Edit/Delete \") | AUTHORITY:  0 (\"\")  > 4 (\" View/Edit/Delete \") | AUTHORITY:  0 (\"\")  > 4 (\" View/Edit/Delete \") | AUTHORITY:  0 (\"\")  > 4 (\" View/Edit/Delete \") | AUTHORITY:  0 (\"\")  > 4 (\" View/Edit/Delete \") | AUTHORITY:  0 (\"\")  > 4 (\" View/Edit/Delete \") | AUTHORITY:  0 (\"\")  > 4 (\" View/Edit/Delete \") | AUTHORITY:  0 (\"\")  > 4 (\" View/Edit/Delete \") | AUTHORITY:  0 (\"\")  > 4 (\" View/Edit/Delete \") | AUTHORITY:  0 (\"\")  > 4 (\" View/Edit/Delete \") | AUTHORITY:  0 (\"\")  > 4 (\" View/Edit/Delete \") | AUTHORITY:  0 (\"\")  > 4 (\" View/Edit/Delete \") | AUTHORITY:  0 (\"\")  > 4 (\" View/Edit/Delete \") | AUTHORITY:  0 (\"\")  > 4 (\" View/Edit/Delete \") | AUTHORITY:  0 (\"\")  > 4 (\" View/Edit/Delete \") | AUTHORITY:  0 (\"\")  > 4 (\" View/Edit/Delete \") | AUTHORITY:  0 (\"\")  > 4 (\" View/Edit/Delete \") | AUTHORITY:  0 (\"\")  > 4 (\" View/Edit/Delete \") | AUTHORITY:  0 (\"\")  > 4 (\" View/Edit/Delete \") | AUTHORITY:  0 (\"\")  > 4 (\" View/Edit/Delete \") | AUTHORITY:  0 (\"\")  > 4 (\" View/Edit/Delete \") | AUTHORITY:  0 (\"\")  > 4 (\" View/Edit/Delete \") | AUTHORITY:  0 (\"\")  > 4 (\" View/Edit/Delete \") | AUTHORITY:  0 (\"\")  > 4 (\" View/Edit/Delete \") | AUTHORITY:  0 (\"\")  > 4 (\" View/Edit/Delete \") | AUTHORITY:  0 (\"\")  > 4 (\" View/Edit/Delete \") | AUTHORITY:  0 (\"\")  > 4 (\" View/Edit/Delete \") | AUTHORITY:  0 (\"\")  > 4 (\" View/Edit/Delete \") | AUTHORITY:  0 (\"\")  > 4 (\" View/Edit/Delete \") | AUTHORITY:  0 (\"\")  > 4 (\" View/Edit/Delete \") | AUTHORITY:  0 (\"\")  > 4 (\" View/Edit/Delete \") | AUTHORITY:  0 (\"\")  > 4 (\" View/Edit/Delete \") | AUTHORITY:  0 (\"\")  > 4 (\" View/Edit/Delete \") | AUTHORITY:  0 (\"\")  > 4 (\" View/Edit/Delete \") | AUTHORITY:  0 (\"\")  > 4 (\" View/Edit/Delete \") | AUTHORITY:  0 (\"\")  > 4 (\" View/Edit/Delete \") | AUTHORITY:  0 (\"\")  > 4 (\" View/Edit/Delete \") | AUTHORITY:  0 (\"\")  > 4 (\" View/Edit/Delete \") | AUTHORITY:  0 (\"\")  > 4 (\" View/Edit/Delete \") | AUTHORITY:  0 (\"\")  > 4 (\" View/Edit/Delete \") | AUTHORITY:  0 (\"\")  > 4 (\" View/Edit/Delete \") | AUTHORITY:  0 (\"\")  > 4 (\" View/Edit/Delete \") | AUTHORITY:  0 (\"\")  > 4 (\" View/Edit/Delete \")','2021-01-11 15:40:32.231279','Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/87.0.4280.141 Safari/537.36'),(60,'49.146.42.127',1,0,3,0,0,10080,286,0,'add/edit Access rights record','LEVEL: 0 (\"\")  >  2 (\" Super Admin \") | MODULE: 0 (\"\")  >  10120 (\" Devices \") | AUTHORITY:  0 (\"\")  > 0 (\" No Access \") | LEVEL: 0 (\"\")  >  2 (\" Super Admin \") | MODULE: 0 (\"\")  >  10160 (\" Brute Force Login Attempt \") | AUTHORITY:  0 (\"\")  > 0 (\" No Access \") | LEVEL: 0 (\"\")  >  2 (\" Super Admin \") | MODULE: 0 (\"\")  >  10180 (\" Bruteforce IP \") | AUTHORITY:  0 (\"\")  > 0 (\" No Access \") | LEVEL: 0 (\"\")  >  2 (\" Super Admin \") | MODULE: 0 (\"\")  >  15010 (\" Addon: Group License \") | AUTHORITY:  0 (\"\")  > 0 (\" No Access \") | LEVEL: 0 (\"\")  >  2 (\" Super Admin \") | MODULE: 0 (\"\")  >  15030 (\" Addon: User License \") | AUTHORITY:  0 (\"\")  > 0 (\" No Access \") | LEVEL: 0 (\"\")  >  2 (\" Super Admin \") | MODULE: 0 (\"\")  >  15050 (\" Addon: Queuing \") | AUTHORITY:  0 (\"\")  > 0 (\" No Access \") | LEVEL: 0 (\"\")  >  2 (\" Super Admin \") | MODULE: 0 (\"\")  >  15070 (\" Addon: Resource \") | AUTHORITY:  0 (\"\")  > 0 (\" No Access \") | LEVEL: 0 (\"\")  >  2 (\" Super Admin \") | MODULE: 0 (\"\")  >  21030 (\" Section \") | AUTHORITY:  0 (\"\")  > 0 (\" No Access \") | LEVEL: 0 (\"\")  >  2 (\" Super Admin \") | MODULE: 0 (\"\")  >  21050 (\" Entrance \") | AUTHORITY:  0 (\"\")  > 0 (\" No Access \") | AUTHORITY:  0 (\"\")  > 4 (\" View/Edit/Delete \") | AUTHORITY:  0 (\"\")  > 4 (\" View/Edit/Delete \") | AUTHORITY:  0 (\"\")  > 4 (\" View/Edit/Delete \") | AUTHORITY:  0 (\"\")  > 4 (\" View/Edit/Delete \") | AUTHORITY:  0 (\"\")  > 4 (\" View/Edit/Delete \") | AUTHORITY:  0 (\"\")  > 4 (\" View/Edit/Delete \") | AUTHORITY:  0 (\"\")  > 4 (\" View/Edit/Delete \") | AUTHORITY:  0 (\"\")  > 4 (\" View/Edit/Delete \") | AUTHORITY:  0 (\"\")  > 4 (\" View/Edit/Delete \") | AUTHORITY:  0 (\"\")  > 4 (\" View/Edit/Delete \") | AUTHORITY:  0 (\"\")  > 4 (\" View/Edit/Delete \") | AUTHORITY:  0 (\"\")  > 4 (\" View/Edit/Delete \") | AUTHORITY:  0 (\"\")  > 4 (\" View/Edit/Delete \") | AUTHORITY:  0 (\"\")  > 4 (\" View/Edit/Delete \") | AUTHORITY:  0 (\"\")  > 4 (\" View/Edit/Delete \") | AUTHORITY:  0 (\"\")  > 4 (\" View/Edit/Delete \") | AUTHORITY:  0 (\"\")  > 4 (\" View/Edit/Delete \") | AUTHORITY:  0 (\"\")  > 4 (\" View/Edit/Delete \") | AUTHORITY:  0 (\"\")  > 4 (\" View/Edit/Delete \") | AUTHORITY:  0 (\"\")  > 4 (\" View/Edit/Delete \") | AUTHORITY:  0 (\"\")  > 4 (\" View/Edit/Delete \") | AUTHORITY:  0 (\"\")  > 4 (\" View/Edit/Delete \") | AUTHORITY:  0 (\"\")  > 4 (\" View/Edit/Delete \") | AUTHORITY:  0 (\"\")  > 4 (\" View/Edit/Delete \") | AUTHORITY:  0 (\"\")  > 4 (\" View/Edit/Delete \") | AUTHORITY:  0 (\"\")  > 4 (\" View/Edit/Delete \") | AUTHORITY:  0 (\"\")  > 4 (\" View/Edit/Delete \") | AUTHORITY:  0 (\"\")  > 4 (\" View/Edit/Delete \") | AUTHORITY:  0 (\"\")  > 4 (\" View/Edit/Delete \") | AUTHORITY:  0 (\"\")  > 4 (\" View/Edit/Delete \") | AUTHORITY:  0 (\"\")  > 4 (\" View/Edit/Delete \") | AUTHORITY:  0 (\"\")  > 4 (\" View/Edit/Delete \") | AUTHORITY:  0 (\"\")  > 4 (\" View/Edit/Delete \") | AUTHORITY:  0 (\"\")  > 4 (\" View/Edit/Delete \") | AUTHORITY:  0 (\"\")  > 4 (\" View/Edit/Delete \") | AUTHORITY:  0 (\"\")  > 4 (\" View/Edit/Delete \") | AUTHORITY:  0 (\"\")  > 4 (\" View/Edit/Delete \") | AUTHORITY:  0 (\"\")  > 4 (\" View/Edit/Delete \") | AUTHORITY:  0 (\"\")  > 4 (\" View/Edit/Delete \") | AUTHORITY:  0 (\"\")  > 4 (\" View/Edit/Delete \") | AUTHORITY:  0 (\"\")  > 4 (\" View/Edit/Delete \") | AUTHORITY:  0 (\"\")  > 4 (\" View/Edit/Delete \") | AUTHORITY:  0 (\"\")  > 4 (\" View/Edit/Delete \") | AUTHORITY:  0 (\"\")  > 4 (\" View/Edit/Delete \") | AUTHORITY:  0 (\"\")  > 4 (\" View/Edit/Delete \") | AUTHORITY:  0 (\"\")  > 4 (\" View/Edit/Delete \") | AUTHORITY:  0 (\"\")  > 4 (\" View/Edit/Delete \") | AUTHORITY:  0 (\"\")  > 4 (\" View/Edit/Delete \") | AUTHORITY:  0 (\"\")  > 4 (\" View/Edit/Delete \") | AUTHORITY:  0 (\"\")  > 4 (\" View/Edit/Delete \") | AUTHORITY:  0 (\"\")  > 4 (\" View/Edit/Delete \")','2021-01-11 15:40:32.237525','Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/87.0.4280.141 Safari/537.36'),(61,'49.146.42.127',1,0,3,0,0,10080,287,0,'add/edit Access rights record','LEVEL: 0 (\"\")  >  2 (\" Super Admin \") | MODULE: 0 (\"\")  >  10120 (\" Devices \") | AUTHORITY:  0 (\"\")  > 0 (\" No Access \") | LEVEL: 0 (\"\")  >  2 (\" Super Admin \") | MODULE: 0 (\"\")  >  10160 (\" Brute Force Login Attempt \") | AUTHORITY:  0 (\"\")  > 0 (\" No Access \") | LEVEL: 0 (\"\")  >  2 (\" Super Admin \") | MODULE: 0 (\"\")  >  10180 (\" Bruteforce IP \") | AUTHORITY:  0 (\"\")  > 0 (\" No Access \") | LEVEL: 0 (\"\")  >  2 (\" Super Admin \") | MODULE: 0 (\"\")  >  15010 (\" Addon: Group License \") | AUTHORITY:  0 (\"\")  > 0 (\" No Access \") | LEVEL: 0 (\"\")  >  2 (\" Super Admin \") | MODULE: 0 (\"\")  >  15030 (\" Addon: User License \") | AUTHORITY:  0 (\"\")  > 0 (\" No Access \") | LEVEL: 0 (\"\")  >  2 (\" Super Admin \") | MODULE: 0 (\"\")  >  15050 (\" Addon: Queuing \") | AUTHORITY:  0 (\"\")  > 0 (\" No Access \") | LEVEL: 0 (\"\")  >  2 (\" Super Admin \") | MODULE: 0 (\"\")  >  15070 (\" Addon: Resource \") | AUTHORITY:  0 (\"\")  > 0 (\" No Access \") | LEVEL: 0 (\"\")  >  2 (\" Super Admin \") | MODULE: 0 (\"\")  >  21030 (\" Section \") | AUTHORITY:  0 (\"\")  > 0 (\" No Access \") | LEVEL: 0 (\"\")  >  2 (\" Super Admin \") | MODULE: 0 (\"\")  >  21050 (\" Entrance \") | AUTHORITY:  0 (\"\")  > 0 (\" No Access \") | AUTHORITY:  0 (\"\")  > 4 (\" View/Edit/Delete \") | AUTHORITY:  0 (\"\")  > 4 (\" View/Edit/Delete \") | AUTHORITY:  0 (\"\")  > 4 (\" View/Edit/Delete \") | AUTHORITY:  0 (\"\")  > 4 (\" View/Edit/Delete \") | AUTHORITY:  0 (\"\")  > 4 (\" View/Edit/Delete \") | AUTHORITY:  0 (\"\")  > 4 (\" View/Edit/Delete \") | AUTHORITY:  0 (\"\")  > 4 (\" View/Edit/Delete \") | AUTHORITY:  0 (\"\")  > 4 (\" View/Edit/Delete \") | AUTHORITY:  0 (\"\")  > 4 (\" View/Edit/Delete \") | AUTHORITY:  0 (\"\")  > 4 (\" View/Edit/Delete \") | AUTHORITY:  0 (\"\")  > 4 (\" View/Edit/Delete \") | AUTHORITY:  0 (\"\")  > 4 (\" View/Edit/Delete \") | AUTHORITY:  0 (\"\")  > 4 (\" View/Edit/Delete \") | AUTHORITY:  0 (\"\")  > 4 (\" View/Edit/Delete \") | AUTHORITY:  0 (\"\")  > 4 (\" View/Edit/Delete \") | AUTHORITY:  0 (\"\")  > 4 (\" View/Edit/Delete \") | AUTHORITY:  0 (\"\")  > 4 (\" View/Edit/Delete \") | AUTHORITY:  0 (\"\")  > 4 (\" View/Edit/Delete \") | AUTHORITY:  0 (\"\")  > 4 (\" View/Edit/Delete \") | AUTHORITY:  0 (\"\")  > 4 (\" View/Edit/Delete \") | AUTHORITY:  0 (\"\")  > 4 (\" View/Edit/Delete \") | AUTHORITY:  0 (\"\")  > 4 (\" View/Edit/Delete \") | AUTHORITY:  0 (\"\")  > 4 (\" View/Edit/Delete \") | AUTHORITY:  0 (\"\")  > 4 (\" View/Edit/Delete \") | AUTHORITY:  0 (\"\")  > 4 (\" View/Edit/Delete \") | AUTHORITY:  0 (\"\")  > 4 (\" View/Edit/Delete \") | AUTHORITY:  0 (\"\")  > 4 (\" View/Edit/Delete \") | AUTHORITY:  0 (\"\")  > 4 (\" View/Edit/Delete \") | AUTHORITY:  0 (\"\")  > 4 (\" View/Edit/Delete \") | AUTHORITY:  0 (\"\")  > 4 (\" View/Edit/Delete \") | AUTHORITY:  0 (\"\")  > 4 (\" View/Edit/Delete \") | AUTHORITY:  0 (\"\")  > 4 (\" View/Edit/Delete \") | AUTHORITY:  0 (\"\")  > 4 (\" View/Edit/Delete \") | AUTHORITY:  0 (\"\")  > 4 (\" View/Edit/Delete \") | AUTHORITY:  0 (\"\")  > 4 (\" View/Edit/Delete \") | AUTHORITY:  0 (\"\")  > 4 (\" View/Edit/Delete \") | AUTHORITY:  0 (\"\")  > 4 (\" View/Edit/Delete \") | AUTHORITY:  0 (\"\")  > 4 (\" View/Edit/Delete \") | AUTHORITY:  0 (\"\")  > 4 (\" View/Edit/Delete \") | AUTHORITY:  0 (\"\")  > 4 (\" View/Edit/Delete \") | AUTHORITY:  0 (\"\")  > 4 (\" View/Edit/Delete \") | AUTHORITY:  0 (\"\")  > 4 (\" View/Edit/Delete \") | AUTHORITY:  0 (\"\")  > 4 (\" View/Edit/Delete \") | AUTHORITY:  0 (\"\")  > 4 (\" View/Edit/Delete \") | AUTHORITY:  0 (\"\")  > 4 (\" View/Edit/Delete \") | AUTHORITY:  0 (\"\")  > 4 (\" View/Edit/Delete \") | AUTHORITY:  0 (\"\")  > 4 (\" View/Edit/Delete \") | AUTHORITY:  0 (\"\")  > 4 (\" View/Edit/Delete \") | AUTHORITY:  0 (\"\")  > 4 (\" View/Edit/Delete \") | AUTHORITY:  0 (\"\")  > 4 (\" View/Edit/Delete \") | AUTHORITY:  0 (\"\")  > 4 (\" View/Edit/Delete \") | AUTHORITY:  0 (\"\")  > 4 (\" View/Edit/Delete \")','2021-01-11 15:40:32.243307','Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/87.0.4280.141 Safari/537.36'),(62,'49.146.42.127',1,0,3,0,0,10080,315,0,'add/edit Access rights record','LEVEL: 0 (\"\")  >  2 (\" Super Admin \") | MODULE: 0 (\"\")  >  10120 (\" Devices \") | AUTHORITY:  0 (\"\")  > 0 (\" No Access \") | LEVEL: 0 (\"\")  >  2 (\" Super Admin \") | MODULE: 0 (\"\")  >  10160 (\" Brute Force Login Attempt \") | AUTHORITY:  0 (\"\")  > 0 (\" No Access \") | LEVEL: 0 (\"\")  >  2 (\" Super Admin \") | MODULE: 0 (\"\")  >  10180 (\" Bruteforce IP \") | AUTHORITY:  0 (\"\")  > 0 (\" No Access \") | LEVEL: 0 (\"\")  >  2 (\" Super Admin \") | MODULE: 0 (\"\")  >  15010 (\" Addon: Group License \") | AUTHORITY:  0 (\"\")  > 0 (\" No Access \") | LEVEL: 0 (\"\")  >  2 (\" Super Admin \") | MODULE: 0 (\"\")  >  15030 (\" Addon: User License \") | AUTHORITY:  0 (\"\")  > 0 (\" No Access \") | LEVEL: 0 (\"\")  >  2 (\" Super Admin \") | MODULE: 0 (\"\")  >  15050 (\" Addon: Queuing \") | AUTHORITY:  0 (\"\")  > 0 (\" No Access \") | LEVEL: 0 (\"\")  >  2 (\" Super Admin \") | MODULE: 0 (\"\")  >  15070 (\" Addon: Resource \") | AUTHORITY:  0 (\"\")  > 0 (\" No Access \") | LEVEL: 0 (\"\")  >  2 (\" Super Admin \") | MODULE: 0 (\"\")  >  21030 (\" Section \") | AUTHORITY:  0 (\"\")  > 0 (\" No Access \") | LEVEL: 0 (\"\")  >  2 (\" Super Admin \") | MODULE: 0 (\"\")  >  21050 (\" Entrance \") | AUTHORITY:  0 (\"\")  > 0 (\" No Access \") | AUTHORITY:  0 (\"\")  > 4 (\" View/Edit/Delete \") | AUTHORITY:  0 (\"\")  > 4 (\" View/Edit/Delete \") | AUTHORITY:  0 (\"\")  > 4 (\" View/Edit/Delete \") | AUTHORITY:  0 (\"\")  > 4 (\" View/Edit/Delete \") | AUTHORITY:  0 (\"\")  > 4 (\" View/Edit/Delete \") | AUTHORITY:  0 (\"\")  > 4 (\" View/Edit/Delete \") | AUTHORITY:  0 (\"\")  > 4 (\" View/Edit/Delete \") | AUTHORITY:  0 (\"\")  > 4 (\" View/Edit/Delete \") | AUTHORITY:  0 (\"\")  > 4 (\" View/Edit/Delete \") | AUTHORITY:  0 (\"\")  > 4 (\" View/Edit/Delete \") | AUTHORITY:  0 (\"\")  > 4 (\" View/Edit/Delete \") | AUTHORITY:  0 (\"\")  > 4 (\" View/Edit/Delete \") | AUTHORITY:  0 (\"\")  > 4 (\" View/Edit/Delete \") | AUTHORITY:  0 (\"\")  > 4 (\" View/Edit/Delete \") | AUTHORITY:  0 (\"\")  > 4 (\" View/Edit/Delete \") | AUTHORITY:  0 (\"\")  > 4 (\" View/Edit/Delete \") | AUTHORITY:  0 (\"\")  > 4 (\" View/Edit/Delete \") | AUTHORITY:  0 (\"\")  > 4 (\" View/Edit/Delete \") | AUTHORITY:  0 (\"\")  > 4 (\" View/Edit/Delete \") | AUTHORITY:  0 (\"\")  > 4 (\" View/Edit/Delete \") | AUTHORITY:  0 (\"\")  > 4 (\" View/Edit/Delete \") | AUTHORITY:  0 (\"\")  > 4 (\" View/Edit/Delete \") | AUTHORITY:  0 (\"\")  > 4 (\" View/Edit/Delete \") | AUTHORITY:  0 (\"\")  > 4 (\" View/Edit/Delete \") | AUTHORITY:  0 (\"\")  > 4 (\" View/Edit/Delete \") | AUTHORITY:  0 (\"\")  > 4 (\" View/Edit/Delete \") | AUTHORITY:  0 (\"\")  > 4 (\" View/Edit/Delete \") | AUTHORITY:  0 (\"\")  > 4 (\" View/Edit/Delete \") | AUTHORITY:  0 (\"\")  > 4 (\" View/Edit/Delete \") | AUTHORITY:  0 (\"\")  > 4 (\" View/Edit/Delete \") | AUTHORITY:  0 (\"\")  > 4 (\" View/Edit/Delete \") | AUTHORITY:  0 (\"\")  > 4 (\" View/Edit/Delete \") | AUTHORITY:  0 (\"\")  > 4 (\" View/Edit/Delete \") | AUTHORITY:  0 (\"\")  > 4 (\" View/Edit/Delete \") | AUTHORITY:  0 (\"\")  > 4 (\" View/Edit/Delete \") | AUTHORITY:  0 (\"\")  > 4 (\" View/Edit/Delete \") | AUTHORITY:  0 (\"\")  > 4 (\" View/Edit/Delete \") | AUTHORITY:  0 (\"\")  > 4 (\" View/Edit/Delete \") | AUTHORITY:  0 (\"\")  > 4 (\" View/Edit/Delete \") | AUTHORITY:  0 (\"\")  > 4 (\" View/Edit/Delete \") | AUTHORITY:  0 (\"\")  > 4 (\" View/Edit/Delete \") | AUTHORITY:  0 (\"\")  > 4 (\" View/Edit/Delete \") | AUTHORITY:  0 (\"\")  > 4 (\" View/Edit/Delete \") | AUTHORITY:  0 (\"\")  > 4 (\" View/Edit/Delete \") | AUTHORITY:  0 (\"\")  > 4 (\" View/Edit/Delete \") | AUTHORITY:  0 (\"\")  > 4 (\" View/Edit/Delete \") | AUTHORITY:  0 (\"\")  > 4 (\" View/Edit/Delete \") | AUTHORITY:  0 (\"\")  > 4 (\" View/Edit/Delete \") | AUTHORITY:  0 (\"\")  > 4 (\" View/Edit/Delete \") | AUTHORITY:  0 (\"\")  > 4 (\" View/Edit/Delete \") | AUTHORITY:  0 (\"\")  > 4 (\" View/Edit/Delete \") | AUTHORITY:  0 (\"\")  > 4 (\" View/Edit/Delete \") | AUTHORITY:  0 (\"\")  > 4 (\" View/Edit/Delete \")','2021-01-11 15:40:32.248628','Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/87.0.4280.141 Safari/537.36'),(63,'49.146.42.127',1,0,3,0,0,10080,316,0,'add/edit Access rights record','LEVEL: 0 (\"\")  >  2 (\" Super Admin \") | MODULE: 0 (\"\")  >  10120 (\" Devices \") | AUTHORITY:  0 (\"\")  > 0 (\" No Access \") | LEVEL: 0 (\"\")  >  2 (\" Super Admin \") | MODULE: 0 (\"\")  >  10160 (\" Brute Force Login Attempt \") | AUTHORITY:  0 (\"\")  > 0 (\" No Access \") | LEVEL: 0 (\"\")  >  2 (\" Super Admin \") | MODULE: 0 (\"\")  >  10180 (\" Bruteforce IP \") | AUTHORITY:  0 (\"\")  > 0 (\" No Access \") | LEVEL: 0 (\"\")  >  2 (\" Super Admin \") | MODULE: 0 (\"\")  >  15010 (\" Addon: Group License \") | AUTHORITY:  0 (\"\")  > 0 (\" No Access \") | LEVEL: 0 (\"\")  >  2 (\" Super Admin \") | MODULE: 0 (\"\")  >  15030 (\" Addon: User License \") | AUTHORITY:  0 (\"\")  > 0 (\" No Access \") | LEVEL: 0 (\"\")  >  2 (\" Super Admin \") | MODULE: 0 (\"\")  >  15050 (\" Addon: Queuing \") | AUTHORITY:  0 (\"\")  > 0 (\" No Access \") | LEVEL: 0 (\"\")  >  2 (\" Super Admin \") | MODULE: 0 (\"\")  >  15070 (\" Addon: Resource \") | AUTHORITY:  0 (\"\")  > 0 (\" No Access \") | LEVEL: 0 (\"\")  >  2 (\" Super Admin \") | MODULE: 0 (\"\")  >  21030 (\" Section \") | AUTHORITY:  0 (\"\")  > 0 (\" No Access \") | LEVEL: 0 (\"\")  >  2 (\" Super Admin \") | MODULE: 0 (\"\")  >  21050 (\" Entrance \") | AUTHORITY:  0 (\"\")  > 0 (\" No Access \") | AUTHORITY:  0 (\"\")  > 4 (\" View/Edit/Delete \") | AUTHORITY:  0 (\"\")  > 4 (\" View/Edit/Delete \") | AUTHORITY:  0 (\"\")  > 4 (\" View/Edit/Delete \") | AUTHORITY:  0 (\"\")  > 4 (\" View/Edit/Delete \") | AUTHORITY:  0 (\"\")  > 4 (\" View/Edit/Delete \") | AUTHORITY:  0 (\"\")  > 4 (\" View/Edit/Delete \") | AUTHORITY:  0 (\"\")  > 4 (\" View/Edit/Delete \") | AUTHORITY:  0 (\"\")  > 4 (\" View/Edit/Delete \") | AUTHORITY:  0 (\"\")  > 4 (\" View/Edit/Delete \") | AUTHORITY:  0 (\"\")  > 4 (\" View/Edit/Delete \") | AUTHORITY:  0 (\"\")  > 4 (\" View/Edit/Delete \") | AUTHORITY:  0 (\"\")  > 4 (\" View/Edit/Delete \") | AUTHORITY:  0 (\"\")  > 4 (\" View/Edit/Delete \") | AUTHORITY:  0 (\"\")  > 4 (\" View/Edit/Delete \") | AUTHORITY:  0 (\"\")  > 4 (\" View/Edit/Delete \") | AUTHORITY:  0 (\"\")  > 4 (\" View/Edit/Delete \") | AUTHORITY:  0 (\"\")  > 4 (\" View/Edit/Delete \") | AUTHORITY:  0 (\"\")  > 4 (\" View/Edit/Delete \") | AUTHORITY:  0 (\"\")  > 4 (\" View/Edit/Delete \") | AUTHORITY:  0 (\"\")  > 4 (\" View/Edit/Delete \") | AUTHORITY:  0 (\"\")  > 4 (\" View/Edit/Delete \") | AUTHORITY:  0 (\"\")  > 4 (\" View/Edit/Delete \") | AUTHORITY:  0 (\"\")  > 4 (\" View/Edit/Delete \") | AUTHORITY:  0 (\"\")  > 4 (\" View/Edit/Delete \") | AUTHORITY:  0 (\"\")  > 4 (\" View/Edit/Delete \") | AUTHORITY:  0 (\"\")  > 4 (\" View/Edit/Delete \") | AUTHORITY:  0 (\"\")  > 4 (\" View/Edit/Delete \") | AUTHORITY:  0 (\"\")  > 4 (\" View/Edit/Delete \") | AUTHORITY:  0 (\"\")  > 4 (\" View/Edit/Delete \") | AUTHORITY:  0 (\"\")  > 4 (\" View/Edit/Delete \") | AUTHORITY:  0 (\"\")  > 4 (\" View/Edit/Delete \") | AUTHORITY:  0 (\"\")  > 4 (\" View/Edit/Delete \") | AUTHORITY:  0 (\"\")  > 4 (\" View/Edit/Delete \") | AUTHORITY:  0 (\"\")  > 4 (\" View/Edit/Delete \") | AUTHORITY:  0 (\"\")  > 4 (\" View/Edit/Delete \") | AUTHORITY:  0 (\"\")  > 4 (\" View/Edit/Delete \") | AUTHORITY:  0 (\"\")  > 4 (\" View/Edit/Delete \") | AUTHORITY:  0 (\"\")  > 4 (\" View/Edit/Delete \") | AUTHORITY:  0 (\"\")  > 4 (\" View/Edit/Delete \") | AUTHORITY:  0 (\"\")  > 4 (\" View/Edit/Delete \") | AUTHORITY:  0 (\"\")  > 4 (\" View/Edit/Delete \") | AUTHORITY:  0 (\"\")  > 4 (\" View/Edit/Delete \") | AUTHORITY:  0 (\"\")  > 4 (\" View/Edit/Delete \") | AUTHORITY:  0 (\"\")  > 4 (\" View/Edit/Delete \") | AUTHORITY:  0 (\"\")  > 4 (\" View/Edit/Delete \") | AUTHORITY:  0 (\"\")  > 4 (\" View/Edit/Delete \") | AUTHORITY:  0 (\"\")  > 4 (\" View/Edit/Delete \") | AUTHORITY:  0 (\"\")  > 4 (\" View/Edit/Delete \") | AUTHORITY:  0 (\"\")  > 4 (\" View/Edit/Delete \") | AUTHORITY:  0 (\"\")  > 4 (\" View/Edit/Delete \") | AUTHORITY:  0 (\"\")  > 4 (\" View/Edit/Delete \") | AUTHORITY:  0 (\"\")  > 4 (\" View/Edit/Delete \") | AUTHORITY:  0 (\"\")  > 4 (\" View/Edit/Delete \") | AUTHORITY:  0 (\"\")  > 4 (\" View/Edit/Delete \")','2021-01-11 15:40:32.253114','Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/87.0.4280.141 Safari/537.36'),(64,'49.146.42.127',1,0,3,0,0,10080,317,0,'add/edit Access rights record','LEVEL: 0 (\"\")  >  2 (\" Super Admin \") | MODULE: 0 (\"\")  >  10120 (\" Devices \") | AUTHORITY:  0 (\"\")  > 0 (\" No Access \") | LEVEL: 0 (\"\")  >  2 (\" Super Admin \") | MODULE: 0 (\"\")  >  10160 (\" Brute Force Login Attempt \") | AUTHORITY:  0 (\"\")  > 0 (\" No Access \") | LEVEL: 0 (\"\")  >  2 (\" Super Admin \") | MODULE: 0 (\"\")  >  10180 (\" Bruteforce IP \") | AUTHORITY:  0 (\"\")  > 0 (\" No Access \") | LEVEL: 0 (\"\")  >  2 (\" Super Admin \") | MODULE: 0 (\"\")  >  15010 (\" Addon: Group License \") | AUTHORITY:  0 (\"\")  > 0 (\" No Access \") | LEVEL: 0 (\"\")  >  2 (\" Super Admin \") | MODULE: 0 (\"\")  >  15030 (\" Addon: User License \") | AUTHORITY:  0 (\"\")  > 0 (\" No Access \") | LEVEL: 0 (\"\")  >  2 (\" Super Admin \") | MODULE: 0 (\"\")  >  15050 (\" Addon: Queuing \") | AUTHORITY:  0 (\"\")  > 0 (\" No Access \") | LEVEL: 0 (\"\")  >  2 (\" Super Admin \") | MODULE: 0 (\"\")  >  15070 (\" Addon: Resource \") | AUTHORITY:  0 (\"\")  > 0 (\" No Access \") | LEVEL: 0 (\"\")  >  2 (\" Super Admin \") | MODULE: 0 (\"\")  >  21030 (\" Section \") | AUTHORITY:  0 (\"\")  > 0 (\" No Access \") | LEVEL: 0 (\"\")  >  2 (\" Super Admin \") | MODULE: 0 (\"\")  >  21050 (\" Entrance \") | AUTHORITY:  0 (\"\")  > 0 (\" No Access \") | AUTHORITY:  0 (\"\")  > 4 (\" View/Edit/Delete \") | AUTHORITY:  0 (\"\")  > 4 (\" View/Edit/Delete \") | AUTHORITY:  0 (\"\")  > 4 (\" View/Edit/Delete \") | AUTHORITY:  0 (\"\")  > 4 (\" View/Edit/Delete \") | AUTHORITY:  0 (\"\")  > 4 (\" View/Edit/Delete \") | AUTHORITY:  0 (\"\")  > 4 (\" View/Edit/Delete \") | AUTHORITY:  0 (\"\")  > 4 (\" View/Edit/Delete \") | AUTHORITY:  0 (\"\")  > 4 (\" View/Edit/Delete \") | AUTHORITY:  0 (\"\")  > 4 (\" View/Edit/Delete \") | AUTHORITY:  0 (\"\")  > 4 (\" View/Edit/Delete \") | AUTHORITY:  0 (\"\")  > 4 (\" View/Edit/Delete \") | AUTHORITY:  0 (\"\")  > 4 (\" View/Edit/Delete \") | AUTHORITY:  0 (\"\")  > 4 (\" View/Edit/Delete \") | AUTHORITY:  0 (\"\")  > 4 (\" View/Edit/Delete \") | AUTHORITY:  0 (\"\")  > 4 (\" View/Edit/Delete \") | AUTHORITY:  0 (\"\")  > 4 (\" View/Edit/Delete \") | AUTHORITY:  0 (\"\")  > 4 (\" View/Edit/Delete \") | AUTHORITY:  0 (\"\")  > 4 (\" View/Edit/Delete \") | AUTHORITY:  0 (\"\")  > 4 (\" View/Edit/Delete \") | AUTHORITY:  0 (\"\")  > 4 (\" View/Edit/Delete \") | AUTHORITY:  0 (\"\")  > 4 (\" View/Edit/Delete \") | AUTHORITY:  0 (\"\")  > 4 (\" View/Edit/Delete \") | AUTHORITY:  0 (\"\")  > 4 (\" View/Edit/Delete \") | AUTHORITY:  0 (\"\")  > 4 (\" View/Edit/Delete \") | AUTHORITY:  0 (\"\")  > 4 (\" View/Edit/Delete \") | AUTHORITY:  0 (\"\")  > 4 (\" View/Edit/Delete \") | AUTHORITY:  0 (\"\")  > 4 (\" View/Edit/Delete \") | AUTHORITY:  0 (\"\")  > 4 (\" View/Edit/Delete \") | AUTHORITY:  0 (\"\")  > 4 (\" View/Edit/Delete \") | AUTHORITY:  0 (\"\")  > 4 (\" View/Edit/Delete \") | AUTHORITY:  0 (\"\")  > 4 (\" View/Edit/Delete \") | AUTHORITY:  0 (\"\")  > 4 (\" View/Edit/Delete \") | AUTHORITY:  0 (\"\")  > 4 (\" View/Edit/Delete \") | AUTHORITY:  0 (\"\")  > 4 (\" View/Edit/Delete \") | AUTHORITY:  0 (\"\")  > 4 (\" View/Edit/Delete \") | AUTHORITY:  0 (\"\")  > 4 (\" View/Edit/Delete \") | AUTHORITY:  0 (\"\")  > 4 (\" View/Edit/Delete \") | AUTHORITY:  0 (\"\")  > 4 (\" View/Edit/Delete \") | AUTHORITY:  0 (\"\")  > 4 (\" View/Edit/Delete \") | AUTHORITY:  0 (\"\")  > 4 (\" View/Edit/Delete \") | AUTHORITY:  0 (\"\")  > 4 (\" View/Edit/Delete \") | AUTHORITY:  0 (\"\")  > 4 (\" View/Edit/Delete \") | AUTHORITY:  0 (\"\")  > 4 (\" View/Edit/Delete \") | AUTHORITY:  0 (\"\")  > 4 (\" View/Edit/Delete \") | AUTHORITY:  0 (\"\")  > 4 (\" View/Edit/Delete \") | AUTHORITY:  0 (\"\")  > 4 (\" View/Edit/Delete \") | AUTHORITY:  0 (\"\")  > 4 (\" View/Edit/Delete \") | AUTHORITY:  0 (\"\")  > 4 (\" View/Edit/Delete \") | AUTHORITY:  0 (\"\")  > 4 (\" View/Edit/Delete \") | AUTHORITY:  0 (\"\")  > 4 (\" View/Edit/Delete \") | AUTHORITY:  0 (\"\")  > 4 (\" View/Edit/Delete \") | AUTHORITY:  0 (\"\")  > 4 (\" View/Edit/Delete \") | AUTHORITY:  0 (\"\")  > 4 (\" View/Edit/Delete \") | AUTHORITY:  0 (\"\")  > 4 (\" View/Edit/Delete \") | AUTHORITY:  0 (\"\")  > 4 (\" View/Edit/Delete \")','2021-01-11 15:40:32.259285','Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/87.0.4280.141 Safari/537.36'),(65,'49.146.42.127',1,0,3,0,0,10080,345,0,'add/edit Access rights record','LEVEL: 0 (\"\")  >  2 (\" Super Admin \") | MODULE: 0 (\"\")  >  10120 (\" Devices \") | AUTHORITY:  0 (\"\")  > 0 (\" No Access \") | LEVEL: 0 (\"\")  >  2 (\" Super Admin \") | MODULE: 0 (\"\")  >  10160 (\" Brute Force Login Attempt \") | AUTHORITY:  0 (\"\")  > 0 (\" No Access \") | LEVEL: 0 (\"\")  >  2 (\" Super Admin \") | MODULE: 0 (\"\")  >  10180 (\" Bruteforce IP \") | AUTHORITY:  0 (\"\")  > 0 (\" No Access \") | LEVEL: 0 (\"\")  >  2 (\" Super Admin \") | MODULE: 0 (\"\")  >  15010 (\" Addon: Group License \") | AUTHORITY:  0 (\"\")  > 0 (\" No Access \") | LEVEL: 0 (\"\")  >  2 (\" Super Admin \") | MODULE: 0 (\"\")  >  15030 (\" Addon: User License \") | AUTHORITY:  0 (\"\")  > 0 (\" No Access \") | LEVEL: 0 (\"\")  >  2 (\" Super Admin \") | MODULE: 0 (\"\")  >  15050 (\" Addon: Queuing \") | AUTHORITY:  0 (\"\")  > 0 (\" No Access \") | LEVEL: 0 (\"\")  >  2 (\" Super Admin \") | MODULE: 0 (\"\")  >  15070 (\" Addon: Resource \") | AUTHORITY:  0 (\"\")  > 0 (\" No Access \") | LEVEL: 0 (\"\")  >  2 (\" Super Admin \") | MODULE: 0 (\"\")  >  21030 (\" Section \") | AUTHORITY:  0 (\"\")  > 0 (\" No Access \") | LEVEL: 0 (\"\")  >  2 (\" Super Admin \") | MODULE: 0 (\"\")  >  21050 (\" Entrance \") | AUTHORITY:  0 (\"\")  > 0 (\" No Access \") | AUTHORITY:  0 (\"\")  > 4 (\" View/Edit/Delete \") | AUTHORITY:  0 (\"\")  > 4 (\" View/Edit/Delete \") | AUTHORITY:  0 (\"\")  > 4 (\" View/Edit/Delete \") | AUTHORITY:  0 (\"\")  > 4 (\" View/Edit/Delete \") | AUTHORITY:  0 (\"\")  > 4 (\" View/Edit/Delete \") | AUTHORITY:  0 (\"\")  > 4 (\" View/Edit/Delete \") | AUTHORITY:  0 (\"\")  > 4 (\" View/Edit/Delete \") | AUTHORITY:  0 (\"\")  > 4 (\" View/Edit/Delete \") | AUTHORITY:  0 (\"\")  > 4 (\" View/Edit/Delete \") | AUTHORITY:  0 (\"\")  > 4 (\" View/Edit/Delete \") | AUTHORITY:  0 (\"\")  > 4 (\" View/Edit/Delete \") | AUTHORITY:  0 (\"\")  > 4 (\" View/Edit/Delete \") | AUTHORITY:  0 (\"\")  > 4 (\" View/Edit/Delete \") | AUTHORITY:  0 (\"\")  > 4 (\" View/Edit/Delete \") | AUTHORITY:  0 (\"\")  > 4 (\" View/Edit/Delete \") | AUTHORITY:  0 (\"\")  > 4 (\" View/Edit/Delete \") | AUTHORITY:  0 (\"\")  > 4 (\" View/Edit/Delete \") | AUTHORITY:  0 (\"\")  > 4 (\" View/Edit/Delete \") | AUTHORITY:  0 (\"\")  > 4 (\" View/Edit/Delete \") | AUTHORITY:  0 (\"\")  > 4 (\" View/Edit/Delete \") | AUTHORITY:  0 (\"\")  > 4 (\" View/Edit/Delete \") | AUTHORITY:  0 (\"\")  > 4 (\" View/Edit/Delete \") | AUTHORITY:  0 (\"\")  > 4 (\" View/Edit/Delete \") | AUTHORITY:  0 (\"\")  > 4 (\" View/Edit/Delete \") | AUTHORITY:  0 (\"\")  > 4 (\" View/Edit/Delete \") | AUTHORITY:  0 (\"\")  > 4 (\" View/Edit/Delete \") | AUTHORITY:  0 (\"\")  > 4 (\" View/Edit/Delete \") | AUTHORITY:  0 (\"\")  > 4 (\" View/Edit/Delete \") | AUTHORITY:  0 (\"\")  > 4 (\" View/Edit/Delete \") | AUTHORITY:  0 (\"\")  > 4 (\" View/Edit/Delete \") | AUTHORITY:  0 (\"\")  > 4 (\" View/Edit/Delete \") | AUTHORITY:  0 (\"\")  > 4 (\" View/Edit/Delete \") | AUTHORITY:  0 (\"\")  > 4 (\" View/Edit/Delete \") | AUTHORITY:  0 (\"\")  > 4 (\" View/Edit/Delete \") | AUTHORITY:  0 (\"\")  > 4 (\" View/Edit/Delete \") | AUTHORITY:  0 (\"\")  > 4 (\" View/Edit/Delete \") | AUTHORITY:  0 (\"\")  > 4 (\" View/Edit/Delete \") | AUTHORITY:  0 (\"\")  > 4 (\" View/Edit/Delete \") | AUTHORITY:  0 (\"\")  > 4 (\" View/Edit/Delete \") | AUTHORITY:  0 (\"\")  > 4 (\" View/Edit/Delete \") | AUTHORITY:  0 (\"\")  > 4 (\" View/Edit/Delete \") | AUTHORITY:  0 (\"\")  > 4 (\" View/Edit/Delete \") | AUTHORITY:  0 (\"\")  > 4 (\" View/Edit/Delete \") | AUTHORITY:  0 (\"\")  > 4 (\" View/Edit/Delete \") | AUTHORITY:  0 (\"\")  > 4 (\" View/Edit/Delete \") | AUTHORITY:  0 (\"\")  > 4 (\" View/Edit/Delete \") | AUTHORITY:  0 (\"\")  > 4 (\" View/Edit/Delete \") | AUTHORITY:  0 (\"\")  > 4 (\" View/Edit/Delete \") | AUTHORITY:  0 (\"\")  > 4 (\" View/Edit/Delete \") | AUTHORITY:  0 (\"\")  > 4 (\" View/Edit/Delete \") | AUTHORITY:  0 (\"\")  > 4 (\" View/Edit/Delete \") | AUTHORITY:  0 (\"\")  > 4 (\" View/Edit/Delete \") | AUTHORITY:  0 (\"\")  > 4 (\" View/Edit/Delete \") | AUTHORITY:  0 (\"\")  > 4 (\" View/Edit/Delete \") | AUTHORITY:  0 (\"\")  > 4 (\" View/Edit/Delete \") | AUTHORITY:  0 (\"\")  > 4 (\" View/Edit/Delete \")','2021-01-11 15:40:32.263533','Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/87.0.4280.141 Safari/537.36'),(66,'49.146.42.127',1,0,3,0,0,10080,348,0,'add/edit Access rights record','LEVEL: 0 (\"\")  >  2 (\" Super Admin \") | MODULE: 0 (\"\")  >  10120 (\" Devices \") | AUTHORITY:  0 (\"\")  > 0 (\" No Access \") | LEVEL: 0 (\"\")  >  2 (\" Super Admin \") | MODULE: 0 (\"\")  >  10160 (\" Brute Force Login Attempt \") | AUTHORITY:  0 (\"\")  > 0 (\" No Access \") | LEVEL: 0 (\"\")  >  2 (\" Super Admin \") | MODULE: 0 (\"\")  >  10180 (\" Bruteforce IP \") | AUTHORITY:  0 (\"\")  > 0 (\" No Access \") | LEVEL: 0 (\"\")  >  2 (\" Super Admin \") | MODULE: 0 (\"\")  >  15010 (\" Addon: Group License \") | AUTHORITY:  0 (\"\")  > 0 (\" No Access \") | LEVEL: 0 (\"\")  >  2 (\" Super Admin \") | MODULE: 0 (\"\")  >  15030 (\" Addon: User License \") | AUTHORITY:  0 (\"\")  > 0 (\" No Access \") | LEVEL: 0 (\"\")  >  2 (\" Super Admin \") | MODULE: 0 (\"\")  >  15050 (\" Addon: Queuing \") | AUTHORITY:  0 (\"\")  > 0 (\" No Access \") | LEVEL: 0 (\"\")  >  2 (\" Super Admin \") | MODULE: 0 (\"\")  >  15070 (\" Addon: Resource \") | AUTHORITY:  0 (\"\")  > 0 (\" No Access \") | LEVEL: 0 (\"\")  >  2 (\" Super Admin \") | MODULE: 0 (\"\")  >  21030 (\" Section \") | AUTHORITY:  0 (\"\")  > 0 (\" No Access \") | LEVEL: 0 (\"\")  >  2 (\" Super Admin \") | MODULE: 0 (\"\")  >  21050 (\" Entrance \") | AUTHORITY:  0 (\"\")  > 0 (\" No Access \") | AUTHORITY:  0 (\"\")  > 4 (\" View/Edit/Delete \") | AUTHORITY:  0 (\"\")  > 4 (\" View/Edit/Delete \") | AUTHORITY:  0 (\"\")  > 4 (\" View/Edit/Delete \") | AUTHORITY:  0 (\"\")  > 4 (\" View/Edit/Delete \") | AUTHORITY:  0 (\"\")  > 4 (\" View/Edit/Delete \") | AUTHORITY:  0 (\"\")  > 4 (\" View/Edit/Delete \") | AUTHORITY:  0 (\"\")  > 4 (\" View/Edit/Delete \") | AUTHORITY:  0 (\"\")  > 4 (\" View/Edit/Delete \") | AUTHORITY:  0 (\"\")  > 4 (\" View/Edit/Delete \") | AUTHORITY:  0 (\"\")  > 4 (\" View/Edit/Delete \") | AUTHORITY:  0 (\"\")  > 4 (\" View/Edit/Delete \") | AUTHORITY:  0 (\"\")  > 4 (\" View/Edit/Delete \") | AUTHORITY:  0 (\"\")  > 4 (\" View/Edit/Delete \") | AUTHORITY:  0 (\"\")  > 4 (\" View/Edit/Delete \") | AUTHORITY:  0 (\"\")  > 4 (\" View/Edit/Delete \") | AUTHORITY:  0 (\"\")  > 4 (\" View/Edit/Delete \") | AUTHORITY:  0 (\"\")  > 4 (\" View/Edit/Delete \") | AUTHORITY:  0 (\"\")  > 4 (\" View/Edit/Delete \") | AUTHORITY:  0 (\"\")  > 4 (\" View/Edit/Delete \") | AUTHORITY:  0 (\"\")  > 4 (\" View/Edit/Delete \") | AUTHORITY:  0 (\"\")  > 4 (\" View/Edit/Delete \") | AUTHORITY:  0 (\"\")  > 4 (\" View/Edit/Delete \") | AUTHORITY:  0 (\"\")  > 4 (\" View/Edit/Delete \") | AUTHORITY:  0 (\"\")  > 4 (\" View/Edit/Delete \") | AUTHORITY:  0 (\"\")  > 4 (\" View/Edit/Delete \") | AUTHORITY:  0 (\"\")  > 4 (\" View/Edit/Delete \") | AUTHORITY:  0 (\"\")  > 4 (\" View/Edit/Delete \") | AUTHORITY:  0 (\"\")  > 4 (\" View/Edit/Delete \") | AUTHORITY:  0 (\"\")  > 4 (\" View/Edit/Delete \") | AUTHORITY:  0 (\"\")  > 4 (\" View/Edit/Delete \") | AUTHORITY:  0 (\"\")  > 4 (\" View/Edit/Delete \") | AUTHORITY:  0 (\"\")  > 4 (\" View/Edit/Delete \") | AUTHORITY:  0 (\"\")  > 4 (\" View/Edit/Delete \") | AUTHORITY:  0 (\"\")  > 4 (\" View/Edit/Delete \") | AUTHORITY:  0 (\"\")  > 4 (\" View/Edit/Delete \") | AUTHORITY:  0 (\"\")  > 4 (\" View/Edit/Delete \") | AUTHORITY:  0 (\"\")  > 4 (\" View/Edit/Delete \") | AUTHORITY:  0 (\"\")  > 4 (\" View/Edit/Delete \") | AUTHORITY:  0 (\"\")  > 4 (\" View/Edit/Delete \") | AUTHORITY:  0 (\"\")  > 4 (\" View/Edit/Delete \") | AUTHORITY:  0 (\"\")  > 4 (\" View/Edit/Delete \") | AUTHORITY:  0 (\"\")  > 4 (\" View/Edit/Delete \") | AUTHORITY:  0 (\"\")  > 4 (\" View/Edit/Delete \") | AUTHORITY:  0 (\"\")  > 4 (\" View/Edit/Delete \") | AUTHORITY:  0 (\"\")  > 4 (\" View/Edit/Delete \") | AUTHORITY:  0 (\"\")  > 4 (\" View/Edit/Delete \") | AUTHORITY:  0 (\"\")  > 4 (\" View/Edit/Delete \") | AUTHORITY:  0 (\"\")  > 4 (\" View/Edit/Delete \") | AUTHORITY:  0 (\"\")  > 4 (\" View/Edit/Delete \") | AUTHORITY:  0 (\"\")  > 4 (\" View/Edit/Delete \") | AUTHORITY:  0 (\"\")  > 4 (\" View/Edit/Delete \") | AUTHORITY:  0 (\"\")  > 4 (\" View/Edit/Delete \") | AUTHORITY:  0 (\"\")  > 4 (\" View/Edit/Delete \") | AUTHORITY:  0 (\"\")  > 4 (\" View/Edit/Delete \") | AUTHORITY:  0 (\"\")  > 4 (\" View/Edit/Delete \") | AUTHORITY:  0 (\"\")  > 4 (\" View/Edit/Delete \") | AUTHORITY:  0 (\"\")  > 4 (\" View/Edit/Delete \")','2021-01-11 15:40:32.267535','Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/87.0.4280.141 Safari/537.36'),(67,'49.146.42.127',1,0,3,0,0,10080,457,0,'add/edit Access rights record','LEVEL: 0 (\"\")  >  2 (\" Super Admin \") | MODULE: 0 (\"\")  >  10120 (\" Devices \") | AUTHORITY:  0 (\"\")  > 0 (\" No Access \") | LEVEL: 0 (\"\")  >  2 (\" Super Admin \") | MODULE: 0 (\"\")  >  10160 (\" Brute Force Login Attempt \") | AUTHORITY:  0 (\"\")  > 0 (\" No Access \") | LEVEL: 0 (\"\")  >  2 (\" Super Admin \") | MODULE: 0 (\"\")  >  10180 (\" Bruteforce IP \") | AUTHORITY:  0 (\"\")  > 0 (\" No Access \") | LEVEL: 0 (\"\")  >  2 (\" Super Admin \") | MODULE: 0 (\"\")  >  15010 (\" Addon: Group License \") | AUTHORITY:  0 (\"\")  > 0 (\" No Access \") | LEVEL: 0 (\"\")  >  2 (\" Super Admin \") | MODULE: 0 (\"\")  >  15030 (\" Addon: User License \") | AUTHORITY:  0 (\"\")  > 0 (\" No Access \") | LEVEL: 0 (\"\")  >  2 (\" Super Admin \") | MODULE: 0 (\"\")  >  15050 (\" Addon: Queuing \") | AUTHORITY:  0 (\"\")  > 0 (\" No Access \") | LEVEL: 0 (\"\")  >  2 (\" Super Admin \") | MODULE: 0 (\"\")  >  15070 (\" Addon: Resource \") | AUTHORITY:  0 (\"\")  > 0 (\" No Access \") | LEVEL: 0 (\"\")  >  2 (\" Super Admin \") | MODULE: 0 (\"\")  >  21030 (\" Section \") | AUTHORITY:  0 (\"\")  > 0 (\" No Access \") | LEVEL: 0 (\"\")  >  2 (\" Super Admin \") | MODULE: 0 (\"\")  >  21050 (\" Entrance \") | AUTHORITY:  0 (\"\")  > 0 (\" No Access \") | AUTHORITY:  0 (\"\")  > 4 (\" View/Edit/Delete \") | AUTHORITY:  0 (\"\")  > 4 (\" View/Edit/Delete \") | AUTHORITY:  0 (\"\")  > 4 (\" View/Edit/Delete \") | AUTHORITY:  0 (\"\")  > 4 (\" View/Edit/Delete \") | AUTHORITY:  0 (\"\")  > 4 (\" View/Edit/Delete \") | AUTHORITY:  0 (\"\")  > 4 (\" View/Edit/Delete \") | AUTHORITY:  0 (\"\")  > 4 (\" View/Edit/Delete \") | AUTHORITY:  0 (\"\")  > 4 (\" View/Edit/Delete \") | AUTHORITY:  0 (\"\")  > 4 (\" View/Edit/Delete \") | AUTHORITY:  0 (\"\")  > 4 (\" View/Edit/Delete \") | AUTHORITY:  0 (\"\")  > 4 (\" View/Edit/Delete \") | AUTHORITY:  0 (\"\")  > 4 (\" View/Edit/Delete \") | AUTHORITY:  0 (\"\")  > 4 (\" View/Edit/Delete \") | AUTHORITY:  0 (\"\")  > 4 (\" View/Edit/Delete \") | AUTHORITY:  0 (\"\")  > 4 (\" View/Edit/Delete \") | AUTHORITY:  0 (\"\")  > 4 (\" View/Edit/Delete \") | AUTHORITY:  0 (\"\")  > 4 (\" View/Edit/Delete \") | AUTHORITY:  0 (\"\")  > 4 (\" View/Edit/Delete \") | AUTHORITY:  0 (\"\")  > 4 (\" View/Edit/Delete \") | AUTHORITY:  0 (\"\")  > 4 (\" View/Edit/Delete \") | AUTHORITY:  0 (\"\")  > 4 (\" View/Edit/Delete \") | AUTHORITY:  0 (\"\")  > 4 (\" View/Edit/Delete \") | AUTHORITY:  0 (\"\")  > 4 (\" View/Edit/Delete \") | AUTHORITY:  0 (\"\")  > 4 (\" View/Edit/Delete \") | AUTHORITY:  0 (\"\")  > 4 (\" View/Edit/Delete \") | AUTHORITY:  0 (\"\")  > 4 (\" View/Edit/Delete \") | AUTHORITY:  0 (\"\")  > 4 (\" View/Edit/Delete \") | AUTHORITY:  0 (\"\")  > 4 (\" View/Edit/Delete \") | AUTHORITY:  0 (\"\")  > 4 (\" View/Edit/Delete \") | AUTHORITY:  0 (\"\")  > 4 (\" View/Edit/Delete \") | AUTHORITY:  0 (\"\")  > 4 (\" View/Edit/Delete \") | AUTHORITY:  0 (\"\")  > 4 (\" View/Edit/Delete \") | AUTHORITY:  0 (\"\")  > 4 (\" View/Edit/Delete \") | AUTHORITY:  0 (\"\")  > 4 (\" View/Edit/Delete \") | AUTHORITY:  0 (\"\")  > 4 (\" View/Edit/Delete \") | AUTHORITY:  0 (\"\")  > 4 (\" View/Edit/Delete \") | AUTHORITY:  0 (\"\")  > 4 (\" View/Edit/Delete \") | AUTHORITY:  0 (\"\")  > 4 (\" View/Edit/Delete \") | AUTHORITY:  0 (\"\")  > 4 (\" View/Edit/Delete \") | AUTHORITY:  0 (\"\")  > 4 (\" View/Edit/Delete \") | AUTHORITY:  0 (\"\")  > 4 (\" View/Edit/Delete \") | AUTHORITY:  0 (\"\")  > 4 (\" View/Edit/Delete \") | AUTHORITY:  0 (\"\")  > 4 (\" View/Edit/Delete \") | AUTHORITY:  0 (\"\")  > 4 (\" View/Edit/Delete \") | AUTHORITY:  0 (\"\")  > 4 (\" View/Edit/Delete \") | AUTHORITY:  0 (\"\")  > 4 (\" View/Edit/Delete \") | AUTHORITY:  0 (\"\")  > 4 (\" View/Edit/Delete \") | AUTHORITY:  0 (\"\")  > 4 (\" View/Edit/Delete \") | AUTHORITY:  0 (\"\")  > 4 (\" View/Edit/Delete \") | AUTHORITY:  0 (\"\")  > 4 (\" View/Edit/Delete \") | AUTHORITY:  0 (\"\")  > 4 (\" View/Edit/Delete \") | AUTHORITY:  0 (\"\")  > 4 (\" View/Edit/Delete \") | AUTHORITY:  0 (\"\")  > 4 (\" View/Edit/Delete \") | AUTHORITY:  0 (\"\")  > 4 (\" View/Edit/Delete \") | AUTHORITY:  0 (\"\")  > 4 (\" View/Edit/Delete \") | AUTHORITY:  0 (\"\")  > 4 (\" View/Edit/Delete \") | AUTHORITY:  0 (\"\")  > 4 (\" View/Edit/Delete \") | AUTHORITY:  0 (\"\")  > 4 (\" View/Edi','2021-01-11 15:40:32.273040','Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/87.0.4280.141 Safari/537.36'),(68,'49.146.42.127',1,0,3,0,0,10080,458,0,'add/edit Access rights record','LEVEL: 0 (\"\")  >  2 (\" Super Admin \") | MODULE: 0 (\"\")  >  10120 (\" Devices \") | AUTHORITY:  0 (\"\")  > 0 (\" No Access \") | LEVEL: 0 (\"\")  >  2 (\" Super Admin \") | MODULE: 0 (\"\")  >  10160 (\" Brute Force Login Attempt \") | AUTHORITY:  0 (\"\")  > 0 (\" No Access \") | LEVEL: 0 (\"\")  >  2 (\" Super Admin \") | MODULE: 0 (\"\")  >  10180 (\" Bruteforce IP \") | AUTHORITY:  0 (\"\")  > 0 (\" No Access \") | LEVEL: 0 (\"\")  >  2 (\" Super Admin \") | MODULE: 0 (\"\")  >  15010 (\" Addon: Group License \") | AUTHORITY:  0 (\"\")  > 0 (\" No Access \") | LEVEL: 0 (\"\")  >  2 (\" Super Admin \") | MODULE: 0 (\"\")  >  15030 (\" Addon: User License \") | AUTHORITY:  0 (\"\")  > 0 (\" No Access \") | LEVEL: 0 (\"\")  >  2 (\" Super Admin \") | MODULE: 0 (\"\")  >  15050 (\" Addon: Queuing \") | AUTHORITY:  0 (\"\")  > 0 (\" No Access \") | LEVEL: 0 (\"\")  >  2 (\" Super Admin \") | MODULE: 0 (\"\")  >  15070 (\" Addon: Resource \") | AUTHORITY:  0 (\"\")  > 0 (\" No Access \") | LEVEL: 0 (\"\")  >  2 (\" Super Admin \") | MODULE: 0 (\"\")  >  21030 (\" Section \") | AUTHORITY:  0 (\"\")  > 0 (\" No Access \") | LEVEL: 0 (\"\")  >  2 (\" Super Admin \") | MODULE: 0 (\"\")  >  21050 (\" Entrance \") | AUTHORITY:  0 (\"\")  > 0 (\" No Access \") | AUTHORITY:  0 (\"\")  > 4 (\" View/Edit/Delete \") | AUTHORITY:  0 (\"\")  > 4 (\" View/Edit/Delete \") | AUTHORITY:  0 (\"\")  > 4 (\" View/Edit/Delete \") | AUTHORITY:  0 (\"\")  > 4 (\" View/Edit/Delete \") | AUTHORITY:  0 (\"\")  > 4 (\" View/Edit/Delete \") | AUTHORITY:  0 (\"\")  > 4 (\" View/Edit/Delete \") | AUTHORITY:  0 (\"\")  > 4 (\" View/Edit/Delete \") | AUTHORITY:  0 (\"\")  > 4 (\" View/Edit/Delete \") | AUTHORITY:  0 (\"\")  > 4 (\" View/Edit/Delete \") | AUTHORITY:  0 (\"\")  > 4 (\" View/Edit/Delete \") | AUTHORITY:  0 (\"\")  > 4 (\" View/Edit/Delete \") | AUTHORITY:  0 (\"\")  > 4 (\" View/Edit/Delete \") | AUTHORITY:  0 (\"\")  > 4 (\" View/Edit/Delete \") | AUTHORITY:  0 (\"\")  > 4 (\" View/Edit/Delete \") | AUTHORITY:  0 (\"\")  > 4 (\" View/Edit/Delete \") | AUTHORITY:  0 (\"\")  > 4 (\" View/Edit/Delete \") | AUTHORITY:  0 (\"\")  > 4 (\" View/Edit/Delete \") | AUTHORITY:  0 (\"\")  > 4 (\" View/Edit/Delete \") | AUTHORITY:  0 (\"\")  > 4 (\" View/Edit/Delete \") | AUTHORITY:  0 (\"\")  > 4 (\" View/Edit/Delete \") | AUTHORITY:  0 (\"\")  > 4 (\" View/Edit/Delete \") | AUTHORITY:  0 (\"\")  > 4 (\" View/Edit/Delete \") | AUTHORITY:  0 (\"\")  > 4 (\" View/Edit/Delete \") | AUTHORITY:  0 (\"\")  > 4 (\" View/Edit/Delete \") | AUTHORITY:  0 (\"\")  > 4 (\" View/Edit/Delete \") | AUTHORITY:  0 (\"\")  > 4 (\" View/Edit/Delete \") | AUTHORITY:  0 (\"\")  > 4 (\" View/Edit/Delete \") | AUTHORITY:  0 (\"\")  > 4 (\" View/Edit/Delete \") | AUTHORITY:  0 (\"\")  > 4 (\" View/Edit/Delete \") | AUTHORITY:  0 (\"\")  > 4 (\" View/Edit/Delete \") | AUTHORITY:  0 (\"\")  > 4 (\" View/Edit/Delete \") | AUTHORITY:  0 (\"\")  > 4 (\" View/Edit/Delete \") | AUTHORITY:  0 (\"\")  > 4 (\" View/Edit/Delete \") | AUTHORITY:  0 (\"\")  > 4 (\" View/Edit/Delete \") | AUTHORITY:  0 (\"\")  > 4 (\" View/Edit/Delete \") | AUTHORITY:  0 (\"\")  > 4 (\" View/Edit/Delete \") | AUTHORITY:  0 (\"\")  > 4 (\" View/Edit/Delete \") | AUTHORITY:  0 (\"\")  > 4 (\" View/Edit/Delete \") | AUTHORITY:  0 (\"\")  > 4 (\" View/Edit/Delete \") | AUTHORITY:  0 (\"\")  > 4 (\" View/Edit/Delete \") | AUTHORITY:  0 (\"\")  > 4 (\" View/Edit/Delete \") | AUTHORITY:  0 (\"\")  > 4 (\" View/Edit/Delete \") | AUTHORITY:  0 (\"\")  > 4 (\" View/Edit/Delete \") | AUTHORITY:  0 (\"\")  > 4 (\" View/Edit/Delete \") | AUTHORITY:  0 (\"\")  > 4 (\" View/Edit/Delete \") | AUTHORITY:  0 (\"\")  > 4 (\" View/Edit/Delete \") | AUTHORITY:  0 (\"\")  > 4 (\" View/Edit/Delete \") | AUTHORITY:  0 (\"\")  > 4 (\" View/Edit/Delete \") | AUTHORITY:  0 (\"\")  > 4 (\" View/Edit/Delete \") | AUTHORITY:  0 (\"\")  > 4 (\" View/Edit/Delete \") | AUTHORITY:  0 (\"\")  > 4 (\" View/Edit/Delete \") | AUTHORITY:  0 (\"\")  > 4 (\" View/Edit/Delete \") | AUTHORITY:  0 (\"\")  > 4 (\" View/Edit/Delete \") | AUTHORITY:  0 (\"\")  > 4 (\" View/Edit/Delete \") | AUTHORITY:  0 (\"\")  > 4 (\" View/Edit/Delete \") | AUTHORITY:  0 (\"\")  > 4 (\" View/Edit/Delete \") | AUTHORITY:  0 (\"\")  > 4 (\" View/Edit/Delete \") | AUTHORITY:  0 (\"\")  > 4 (\" View/Edi','2021-01-11 15:40:32.276771','Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/87.0.4280.141 Safari/537.36'),(69,'49.146.42.127',1,0,3,0,0,10080,459,0,'add/edit Access rights record','LEVEL: 0 (\"\")  >  2 (\" Super Admin \") | MODULE: 0 (\"\")  >  10120 (\" Devices \") | AUTHORITY:  0 (\"\")  > 0 (\" No Access \") | LEVEL: 0 (\"\")  >  2 (\" Super Admin \") | MODULE: 0 (\"\")  >  10160 (\" Brute Force Login Attempt \") | AUTHORITY:  0 (\"\")  > 0 (\" No Access \") | LEVEL: 0 (\"\")  >  2 (\" Super Admin \") | MODULE: 0 (\"\")  >  10180 (\" Bruteforce IP \") | AUTHORITY:  0 (\"\")  > 0 (\" No Access \") | LEVEL: 0 (\"\")  >  2 (\" Super Admin \") | MODULE: 0 (\"\")  >  15010 (\" Addon: Group License \") | AUTHORITY:  0 (\"\")  > 0 (\" No Access \") | LEVEL: 0 (\"\")  >  2 (\" Super Admin \") | MODULE: 0 (\"\")  >  15030 (\" Addon: User License \") | AUTHORITY:  0 (\"\")  > 0 (\" No Access \") | LEVEL: 0 (\"\")  >  2 (\" Super Admin \") | MODULE: 0 (\"\")  >  15050 (\" Addon: Queuing \") | AUTHORITY:  0 (\"\")  > 0 (\" No Access \") | LEVEL: 0 (\"\")  >  2 (\" Super Admin \") | MODULE: 0 (\"\")  >  15070 (\" Addon: Resource \") | AUTHORITY:  0 (\"\")  > 0 (\" No Access \") | LEVEL: 0 (\"\")  >  2 (\" Super Admin \") | MODULE: 0 (\"\")  >  21030 (\" Section \") | AUTHORITY:  0 (\"\")  > 0 (\" No Access \") | LEVEL: 0 (\"\")  >  2 (\" Super Admin \") | MODULE: 0 (\"\")  >  21050 (\" Entrance \") | AUTHORITY:  0 (\"\")  > 0 (\" No Access \") | AUTHORITY:  0 (\"\")  > 4 (\" View/Edit/Delete \") | AUTHORITY:  0 (\"\")  > 4 (\" View/Edit/Delete \") | AUTHORITY:  0 (\"\")  > 4 (\" View/Edit/Delete \") | AUTHORITY:  0 (\"\")  > 4 (\" View/Edit/Delete \") | AUTHORITY:  0 (\"\")  > 4 (\" View/Edit/Delete \") | AUTHORITY:  0 (\"\")  > 4 (\" View/Edit/Delete \") | AUTHORITY:  0 (\"\")  > 4 (\" View/Edit/Delete \") | AUTHORITY:  0 (\"\")  > 4 (\" View/Edit/Delete \") | AUTHORITY:  0 (\"\")  > 4 (\" View/Edit/Delete \") | AUTHORITY:  0 (\"\")  > 4 (\" View/Edit/Delete \") | AUTHORITY:  0 (\"\")  > 4 (\" View/Edit/Delete \") | AUTHORITY:  0 (\"\")  > 4 (\" View/Edit/Delete \") | AUTHORITY:  0 (\"\")  > 4 (\" View/Edit/Delete \") | AUTHORITY:  0 (\"\")  > 4 (\" View/Edit/Delete \") | AUTHORITY:  0 (\"\")  > 4 (\" View/Edit/Delete \") | AUTHORITY:  0 (\"\")  > 4 (\" View/Edit/Delete \") | AUTHORITY:  0 (\"\")  > 4 (\" View/Edit/Delete \") | AUTHORITY:  0 (\"\")  > 4 (\" View/Edit/Delete \") | AUTHORITY:  0 (\"\")  > 4 (\" View/Edit/Delete \") | AUTHORITY:  0 (\"\")  > 4 (\" View/Edit/Delete \") | AUTHORITY:  0 (\"\")  > 4 (\" View/Edit/Delete \") | AUTHORITY:  0 (\"\")  > 4 (\" View/Edit/Delete \") | AUTHORITY:  0 (\"\")  > 4 (\" View/Edit/Delete \") | AUTHORITY:  0 (\"\")  > 4 (\" View/Edit/Delete \") | AUTHORITY:  0 (\"\")  > 4 (\" View/Edit/Delete \") | AUTHORITY:  0 (\"\")  > 4 (\" View/Edit/Delete \") | AUTHORITY:  0 (\"\")  > 4 (\" View/Edit/Delete \") | AUTHORITY:  0 (\"\")  > 4 (\" View/Edit/Delete \") | AUTHORITY:  0 (\"\")  > 4 (\" View/Edit/Delete \") | AUTHORITY:  0 (\"\")  > 4 (\" View/Edit/Delete \") | AUTHORITY:  0 (\"\")  > 4 (\" View/Edit/Delete \") | AUTHORITY:  0 (\"\")  > 4 (\" View/Edit/Delete \") | AUTHORITY:  0 (\"\")  > 4 (\" View/Edit/Delete \") | AUTHORITY:  0 (\"\")  > 4 (\" View/Edit/Delete \") | AUTHORITY:  0 (\"\")  > 4 (\" View/Edit/Delete \") | AUTHORITY:  0 (\"\")  > 4 (\" View/Edit/Delete \") | AUTHORITY:  0 (\"\")  > 4 (\" View/Edit/Delete \") | AUTHORITY:  0 (\"\")  > 4 (\" View/Edit/Delete \") | AUTHORITY:  0 (\"\")  > 4 (\" View/Edit/Delete \") | AUTHORITY:  0 (\"\")  > 4 (\" View/Edit/Delete \") | AUTHORITY:  0 (\"\")  > 4 (\" View/Edit/Delete \") | AUTHORITY:  0 (\"\")  > 4 (\" View/Edit/Delete \") | AUTHORITY:  0 (\"\")  > 4 (\" View/Edit/Delete \") | AUTHORITY:  0 (\"\")  > 4 (\" View/Edit/Delete \") | AUTHORITY:  0 (\"\")  > 4 (\" View/Edit/Delete \") | AUTHORITY:  0 (\"\")  > 4 (\" View/Edit/Delete \") | AUTHORITY:  0 (\"\")  > 4 (\" View/Edit/Delete \") | AUTHORITY:  0 (\"\")  > 4 (\" View/Edit/Delete \") | AUTHORITY:  0 (\"\")  > 4 (\" View/Edit/Delete \") | AUTHORITY:  0 (\"\")  > 4 (\" View/Edit/Delete \") | AUTHORITY:  0 (\"\")  > 4 (\" View/Edit/Delete \") | AUTHORITY:  0 (\"\")  > 4 (\" View/Edit/Delete \") | AUTHORITY:  0 (\"\")  > 4 (\" View/Edit/Delete \") | AUTHORITY:  0 (\"\")  > 4 (\" View/Edit/Delete \") | AUTHORITY:  0 (\"\")  > 4 (\" View/Edit/Delete \") | AUTHORITY:  0 (\"\")  > 4 (\" View/Edit/Delete \") | AUTHORITY:  0 (\"\")  > 4 (\" View/Edit/Delete \") | AUTHORITY:  0 (\"\")  > 4 (\" View/Edi','2021-01-11 15:40:32.280922','Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/87.0.4280.141 Safari/537.36'),(70,'49.146.42.127',1,0,3,0,0,10080,460,0,'add/edit Access rights record','LEVEL: 0 (\"\")  >  2 (\" Super Admin \") | MODULE: 0 (\"\")  >  10120 (\" Devices \") | AUTHORITY:  0 (\"\")  > 0 (\" No Access \") | LEVEL: 0 (\"\")  >  2 (\" Super Admin \") | MODULE: 0 (\"\")  >  10160 (\" Brute Force Login Attempt \") | AUTHORITY:  0 (\"\")  > 0 (\" No Access \") | LEVEL: 0 (\"\")  >  2 (\" Super Admin \") | MODULE: 0 (\"\")  >  10180 (\" Bruteforce IP \") | AUTHORITY:  0 (\"\")  > 0 (\" No Access \") | LEVEL: 0 (\"\")  >  2 (\" Super Admin \") | MODULE: 0 (\"\")  >  15010 (\" Addon: Group License \") | AUTHORITY:  0 (\"\")  > 0 (\" No Access \") | LEVEL: 0 (\"\")  >  2 (\" Super Admin \") | MODULE: 0 (\"\")  >  15030 (\" Addon: User License \") | AUTHORITY:  0 (\"\")  > 0 (\" No Access \") | LEVEL: 0 (\"\")  >  2 (\" Super Admin \") | MODULE: 0 (\"\")  >  15050 (\" Addon: Queuing \") | AUTHORITY:  0 (\"\")  > 0 (\" No Access \") | LEVEL: 0 (\"\")  >  2 (\" Super Admin \") | MODULE: 0 (\"\")  >  15070 (\" Addon: Resource \") | AUTHORITY:  0 (\"\")  > 0 (\" No Access \") | LEVEL: 0 (\"\")  >  2 (\" Super Admin \") | MODULE: 0 (\"\")  >  21030 (\" Section \") | AUTHORITY:  0 (\"\")  > 0 (\" No Access \") | LEVEL: 0 (\"\")  >  2 (\" Super Admin \") | MODULE: 0 (\"\")  >  21050 (\" Entrance \") | AUTHORITY:  0 (\"\")  > 0 (\" No Access \") | AUTHORITY:  0 (\"\")  > 4 (\" View/Edit/Delete \") | AUTHORITY:  0 (\"\")  > 4 (\" View/Edit/Delete \") | AUTHORITY:  0 (\"\")  > 4 (\" View/Edit/Delete \") | AUTHORITY:  0 (\"\")  > 4 (\" View/Edit/Delete \") | AUTHORITY:  0 (\"\")  > 4 (\" View/Edit/Delete \") | AUTHORITY:  0 (\"\")  > 4 (\" View/Edit/Delete \") | AUTHORITY:  0 (\"\")  > 4 (\" View/Edit/Delete \") | AUTHORITY:  0 (\"\")  > 4 (\" View/Edit/Delete \") | AUTHORITY:  0 (\"\")  > 4 (\" View/Edit/Delete \") | AUTHORITY:  0 (\"\")  > 4 (\" View/Edit/Delete \") | AUTHORITY:  0 (\"\")  > 4 (\" View/Edit/Delete \") | AUTHORITY:  0 (\"\")  > 4 (\" View/Edit/Delete \") | AUTHORITY:  0 (\"\")  > 4 (\" View/Edit/Delete \") | AUTHORITY:  0 (\"\")  > 4 (\" View/Edit/Delete \") | AUTHORITY:  0 (\"\")  > 4 (\" View/Edit/Delete \") | AUTHORITY:  0 (\"\")  > 4 (\" View/Edit/Delete \") | AUTHORITY:  0 (\"\")  > 4 (\" View/Edit/Delete \") | AUTHORITY:  0 (\"\")  > 4 (\" View/Edit/Delete \") | AUTHORITY:  0 (\"\")  > 4 (\" View/Edit/Delete \") | AUTHORITY:  0 (\"\")  > 4 (\" View/Edit/Delete \") | AUTHORITY:  0 (\"\")  > 4 (\" View/Edit/Delete \") | AUTHORITY:  0 (\"\")  > 4 (\" View/Edit/Delete \") | AUTHORITY:  0 (\"\")  > 4 (\" View/Edit/Delete \") | AUTHORITY:  0 (\"\")  > 4 (\" View/Edit/Delete \") | AUTHORITY:  0 (\"\")  > 4 (\" View/Edit/Delete \") | AUTHORITY:  0 (\"\")  > 4 (\" View/Edit/Delete \") | AUTHORITY:  0 (\"\")  > 4 (\" View/Edit/Delete \") | AUTHORITY:  0 (\"\")  > 4 (\" View/Edit/Delete \") | AUTHORITY:  0 (\"\")  > 4 (\" View/Edit/Delete \") | AUTHORITY:  0 (\"\")  > 4 (\" View/Edit/Delete \") | AUTHORITY:  0 (\"\")  > 4 (\" View/Edit/Delete \") | AUTHORITY:  0 (\"\")  > 4 (\" View/Edit/Delete \") | AUTHORITY:  0 (\"\")  > 4 (\" View/Edit/Delete \") | AUTHORITY:  0 (\"\")  > 4 (\" View/Edit/Delete \") | AUTHORITY:  0 (\"\")  > 4 (\" View/Edit/Delete \") | AUTHORITY:  0 (\"\")  > 4 (\" View/Edit/Delete \") | AUTHORITY:  0 (\"\")  > 4 (\" View/Edit/Delete \") | AUTHORITY:  0 (\"\")  > 4 (\" View/Edit/Delete \") | AUTHORITY:  0 (\"\")  > 4 (\" View/Edit/Delete \") | AUTHORITY:  0 (\"\")  > 4 (\" View/Edit/Delete \") | AUTHORITY:  0 (\"\")  > 4 (\" View/Edit/Delete \") | AUTHORITY:  0 (\"\")  > 4 (\" View/Edit/Delete \") | AUTHORITY:  0 (\"\")  > 4 (\" View/Edit/Delete \") | AUTHORITY:  0 (\"\")  > 4 (\" View/Edit/Delete \") | AUTHORITY:  0 (\"\")  > 4 (\" View/Edit/Delete \") | AUTHORITY:  0 (\"\")  > 4 (\" View/Edit/Delete \") | AUTHORITY:  0 (\"\")  > 4 (\" View/Edit/Delete \") | AUTHORITY:  0 (\"\")  > 4 (\" View/Edit/Delete \") | AUTHORITY:  0 (\"\")  > 4 (\" View/Edit/Delete \") | AUTHORITY:  0 (\"\")  > 4 (\" View/Edit/Delete \") | AUTHORITY:  0 (\"\")  > 4 (\" View/Edit/Delete \") | AUTHORITY:  0 (\"\")  > 4 (\" View/Edit/Delete \") | AUTHORITY:  0 (\"\")  > 4 (\" View/Edit/Delete \") | AUTHORITY:  0 (\"\")  > 4 (\" View/Edit/Delete \") | AUTHORITY:  0 (\"\")  > 4 (\" View/Edit/Delete \") | AUTHORITY:  0 (\"\")  > 4 (\" View/Edit/Delete \") | AUTHORITY:  0 (\"\")  > 4 (\" View/Edit/Delete \") | AUTHORITY:  0 (\"\")  > 4 (\" View/Edi','2021-01-11 15:40:32.315348','Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/87.0.4280.141 Safari/537.36'),(71,'49.146.42.127',1,0,3,0,0,10080,461,0,'add/edit Access rights record','LEVEL: 0 (\"\")  >  2 (\" Super Admin \") | MODULE: 0 (\"\")  >  10120 (\" Devices \") | AUTHORITY:  0 (\"\")  > 0 (\" No Access \") | LEVEL: 0 (\"\")  >  2 (\" Super Admin \") | MODULE: 0 (\"\")  >  10160 (\" Brute Force Login Attempt \") | AUTHORITY:  0 (\"\")  > 0 (\" No Access \") | LEVEL: 0 (\"\")  >  2 (\" Super Admin \") | MODULE: 0 (\"\")  >  10180 (\" Bruteforce IP \") | AUTHORITY:  0 (\"\")  > 0 (\" No Access \") | LEVEL: 0 (\"\")  >  2 (\" Super Admin \") | MODULE: 0 (\"\")  >  15010 (\" Addon: Group License \") | AUTHORITY:  0 (\"\")  > 0 (\" No Access \") | LEVEL: 0 (\"\")  >  2 (\" Super Admin \") | MODULE: 0 (\"\")  >  15030 (\" Addon: User License \") | AUTHORITY:  0 (\"\")  > 0 (\" No Access \") | LEVEL: 0 (\"\")  >  2 (\" Super Admin \") | MODULE: 0 (\"\")  >  15050 (\" Addon: Queuing \") | AUTHORITY:  0 (\"\")  > 0 (\" No Access \") | LEVEL: 0 (\"\")  >  2 (\" Super Admin \") | MODULE: 0 (\"\")  >  15070 (\" Addon: Resource \") | AUTHORITY:  0 (\"\")  > 0 (\" No Access \") | LEVEL: 0 (\"\")  >  2 (\" Super Admin \") | MODULE: 0 (\"\")  >  21030 (\" Section \") | AUTHORITY:  0 (\"\")  > 0 (\" No Access \") | LEVEL: 0 (\"\")  >  2 (\" Super Admin \") | MODULE: 0 (\"\")  >  21050 (\" Entrance \") | AUTHORITY:  0 (\"\")  > 0 (\" No Access \") | AUTHORITY:  0 (\"\")  > 4 (\" View/Edit/Delete \") | AUTHORITY:  0 (\"\")  > 4 (\" View/Edit/Delete \") | AUTHORITY:  0 (\"\")  > 4 (\" View/Edit/Delete \") | AUTHORITY:  0 (\"\")  > 4 (\" View/Edit/Delete \") | AUTHORITY:  0 (\"\")  > 4 (\" View/Edit/Delete \") | AUTHORITY:  0 (\"\")  > 4 (\" View/Edit/Delete \") | AUTHORITY:  0 (\"\")  > 4 (\" View/Edit/Delete \") | AUTHORITY:  0 (\"\")  > 4 (\" View/Edit/Delete \") | AUTHORITY:  0 (\"\")  > 4 (\" View/Edit/Delete \") | AUTHORITY:  0 (\"\")  > 4 (\" View/Edit/Delete \") | AUTHORITY:  0 (\"\")  > 4 (\" View/Edit/Delete \") | AUTHORITY:  0 (\"\")  > 4 (\" View/Edit/Delete \") | AUTHORITY:  0 (\"\")  > 4 (\" View/Edit/Delete \") | AUTHORITY:  0 (\"\")  > 4 (\" View/Edit/Delete \") | AUTHORITY:  0 (\"\")  > 4 (\" View/Edit/Delete \") | AUTHORITY:  0 (\"\")  > 4 (\" View/Edit/Delete \") | AUTHORITY:  0 (\"\")  > 4 (\" View/Edit/Delete \") | AUTHORITY:  0 (\"\")  > 4 (\" View/Edit/Delete \") | AUTHORITY:  0 (\"\")  > 4 (\" View/Edit/Delete \") | AUTHORITY:  0 (\"\")  > 4 (\" View/Edit/Delete \") | AUTHORITY:  0 (\"\")  > 4 (\" View/Edit/Delete \") | AUTHORITY:  0 (\"\")  > 4 (\" View/Edit/Delete \") | AUTHORITY:  0 (\"\")  > 4 (\" View/Edit/Delete \") | AUTHORITY:  0 (\"\")  > 4 (\" View/Edit/Delete \") | AUTHORITY:  0 (\"\")  > 4 (\" View/Edit/Delete \") | AUTHORITY:  0 (\"\")  > 4 (\" View/Edit/Delete \") | AUTHORITY:  0 (\"\")  > 4 (\" View/Edit/Delete \") | AUTHORITY:  0 (\"\")  > 4 (\" View/Edit/Delete \") | AUTHORITY:  0 (\"\")  > 4 (\" View/Edit/Delete \") | AUTHORITY:  0 (\"\")  > 4 (\" View/Edit/Delete \") | AUTHORITY:  0 (\"\")  > 4 (\" View/Edit/Delete \") | AUTHORITY:  0 (\"\")  > 4 (\" View/Edit/Delete \") | AUTHORITY:  0 (\"\")  > 4 (\" View/Edit/Delete \") | AUTHORITY:  0 (\"\")  > 4 (\" View/Edit/Delete \") | AUTHORITY:  0 (\"\")  > 4 (\" View/Edit/Delete \") | AUTHORITY:  0 (\"\")  > 4 (\" View/Edit/Delete \") | AUTHORITY:  0 (\"\")  > 4 (\" View/Edit/Delete \") | AUTHORITY:  0 (\"\")  > 4 (\" View/Edit/Delete \") | AUTHORITY:  0 (\"\")  > 4 (\" View/Edit/Delete \") | AUTHORITY:  0 (\"\")  > 4 (\" View/Edit/Delete \") | AUTHORITY:  0 (\"\")  > 4 (\" View/Edit/Delete \") | AUTHORITY:  0 (\"\")  > 4 (\" View/Edit/Delete \") | AUTHORITY:  0 (\"\")  > 4 (\" View/Edit/Delete \") | AUTHORITY:  0 (\"\")  > 4 (\" View/Edit/Delete \") | AUTHORITY:  0 (\"\")  > 4 (\" View/Edit/Delete \") | AUTHORITY:  0 (\"\")  > 4 (\" View/Edit/Delete \") | AUTHORITY:  0 (\"\")  > 4 (\" View/Edit/Delete \") | AUTHORITY:  0 (\"\")  > 4 (\" View/Edit/Delete \") | AUTHORITY:  0 (\"\")  > 4 (\" View/Edit/Delete \") | AUTHORITY:  0 (\"\")  > 4 (\" View/Edit/Delete \") | AUTHORITY:  0 (\"\")  > 4 (\" View/Edit/Delete \") | AUTHORITY:  0 (\"\")  > 4 (\" View/Edit/Delete \") | AUTHORITY:  0 (\"\")  > 4 (\" View/Edit/Delete \") | AUTHORITY:  0 (\"\")  > 4 (\" View/Edit/Delete \") | AUTHORITY:  0 (\"\")  > 4 (\" View/Edit/Delete \") | AUTHORITY:  0 (\"\")  > 4 (\" View/Edit/Delete \") | AUTHORITY:  0 (\"\")  > 4 (\" View/Edit/Delete \") | AUTHORITY:  0 (\"\")  > 4 (\" View/Edi','2021-01-11 15:40:32.319634','Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/87.0.4280.141 Safari/537.36'),(72,'49.146.42.127',1,0,3,0,0,10080,462,0,'add/edit Access rights record','LEVEL: 0 (\"\")  >  2 (\" Super Admin \") | MODULE: 0 (\"\")  >  10120 (\" Devices \") | AUTHORITY:  0 (\"\")  > 0 (\" No Access \") | LEVEL: 0 (\"\")  >  2 (\" Super Admin \") | MODULE: 0 (\"\")  >  10160 (\" Brute Force Login Attempt \") | AUTHORITY:  0 (\"\")  > 0 (\" No Access \") | LEVEL: 0 (\"\")  >  2 (\" Super Admin \") | MODULE: 0 (\"\")  >  10180 (\" Bruteforce IP \") | AUTHORITY:  0 (\"\")  > 0 (\" No Access \") | LEVEL: 0 (\"\")  >  2 (\" Super Admin \") | MODULE: 0 (\"\")  >  15010 (\" Addon: Group License \") | AUTHORITY:  0 (\"\")  > 0 (\" No Access \") | LEVEL: 0 (\"\")  >  2 (\" Super Admin \") | MODULE: 0 (\"\")  >  15030 (\" Addon: User License \") | AUTHORITY:  0 (\"\")  > 0 (\" No Access \") | LEVEL: 0 (\"\")  >  2 (\" Super Admin \") | MODULE: 0 (\"\")  >  15050 (\" Addon: Queuing \") | AUTHORITY:  0 (\"\")  > 0 (\" No Access \") | LEVEL: 0 (\"\")  >  2 (\" Super Admin \") | MODULE: 0 (\"\")  >  15070 (\" Addon: Resource \") | AUTHORITY:  0 (\"\")  > 0 (\" No Access \") | LEVEL: 0 (\"\")  >  2 (\" Super Admin \") | MODULE: 0 (\"\")  >  21030 (\" Section \") | AUTHORITY:  0 (\"\")  > 0 (\" No Access \") | LEVEL: 0 (\"\")  >  2 (\" Super Admin \") | MODULE: 0 (\"\")  >  21050 (\" Entrance \") | AUTHORITY:  0 (\"\")  > 0 (\" No Access \") | AUTHORITY:  0 (\"\")  > 4 (\" View/Edit/Delete \") | AUTHORITY:  0 (\"\")  > 4 (\" View/Edit/Delete \") | AUTHORITY:  0 (\"\")  > 4 (\" View/Edit/Delete \") | AUTHORITY:  0 (\"\")  > 4 (\" View/Edit/Delete \") | AUTHORITY:  0 (\"\")  > 4 (\" View/Edit/Delete \") | AUTHORITY:  0 (\"\")  > 4 (\" View/Edit/Delete \") | AUTHORITY:  0 (\"\")  > 4 (\" View/Edit/Delete \") | AUTHORITY:  0 (\"\")  > 4 (\" View/Edit/Delete \") | AUTHORITY:  0 (\"\")  > 4 (\" View/Edit/Delete \") | AUTHORITY:  0 (\"\")  > 4 (\" View/Edit/Delete \") | AUTHORITY:  0 (\"\")  > 4 (\" View/Edit/Delete \") | AUTHORITY:  0 (\"\")  > 4 (\" View/Edit/Delete \") | AUTHORITY:  0 (\"\")  > 4 (\" View/Edit/Delete \") | AUTHORITY:  0 (\"\")  > 4 (\" View/Edit/Delete \") | AUTHORITY:  0 (\"\")  > 4 (\" View/Edit/Delete \") | AUTHORITY:  0 (\"\")  > 4 (\" View/Edit/Delete \") | AUTHORITY:  0 (\"\")  > 4 (\" View/Edit/Delete \") | AUTHORITY:  0 (\"\")  > 4 (\" View/Edit/Delete \") | AUTHORITY:  0 (\"\")  > 4 (\" View/Edit/Delete \") | AUTHORITY:  0 (\"\")  > 4 (\" View/Edit/Delete \") | AUTHORITY:  0 (\"\")  > 4 (\" View/Edit/Delete \") | AUTHORITY:  0 (\"\")  > 4 (\" View/Edit/Delete \") | AUTHORITY:  0 (\"\")  > 4 (\" View/Edit/Delete \") | AUTHORITY:  0 (\"\")  > 4 (\" View/Edit/Delete \") | AUTHORITY:  0 (\"\")  > 4 (\" View/Edit/Delete \") | AUTHORITY:  0 (\"\")  > 4 (\" View/Edit/Delete \") | AUTHORITY:  0 (\"\")  > 4 (\" View/Edit/Delete \") | AUTHORITY:  0 (\"\")  > 4 (\" View/Edit/Delete \") | AUTHORITY:  0 (\"\")  > 4 (\" View/Edit/Delete \") | AUTHORITY:  0 (\"\")  > 4 (\" View/Edit/Delete \") | AUTHORITY:  0 (\"\")  > 4 (\" View/Edit/Delete \") | AUTHORITY:  0 (\"\")  > 4 (\" View/Edit/Delete \") | AUTHORITY:  0 (\"\")  > 4 (\" View/Edit/Delete \") | AUTHORITY:  0 (\"\")  > 4 (\" View/Edit/Delete \") | AUTHORITY:  0 (\"\")  > 4 (\" View/Edit/Delete \") | AUTHORITY:  0 (\"\")  > 4 (\" View/Edit/Delete \") | AUTHORITY:  0 (\"\")  > 4 (\" View/Edit/Delete \") | AUTHORITY:  0 (\"\")  > 4 (\" View/Edit/Delete \") | AUTHORITY:  0 (\"\")  > 4 (\" View/Edit/Delete \") | AUTHORITY:  0 (\"\")  > 4 (\" View/Edit/Delete \") | AUTHORITY:  0 (\"\")  > 4 (\" View/Edit/Delete \") | AUTHORITY:  0 (\"\")  > 4 (\" View/Edit/Delete \") | AUTHORITY:  0 (\"\")  > 4 (\" View/Edit/Delete \") | AUTHORITY:  0 (\"\")  > 4 (\" View/Edit/Delete \") | AUTHORITY:  0 (\"\")  > 4 (\" View/Edit/Delete \") | AUTHORITY:  0 (\"\")  > 4 (\" View/Edit/Delete \") | AUTHORITY:  0 (\"\")  > 4 (\" View/Edit/Delete \") | AUTHORITY:  0 (\"\")  > 4 (\" View/Edit/Delete \") | AUTHORITY:  0 (\"\")  > 4 (\" View/Edit/Delete \") | AUTHORITY:  0 (\"\")  > 4 (\" View/Edit/Delete \") | AUTHORITY:  0 (\"\")  > 4 (\" View/Edit/Delete \") | AUTHORITY:  0 (\"\")  > 4 (\" View/Edit/Delete \") | AUTHORITY:  0 (\"\")  > 4 (\" View/Edit/Delete \") | AUTHORITY:  0 (\"\")  > 4 (\" View/Edit/Delete \") | AUTHORITY:  0 (\"\")  > 4 (\" View/Edit/Delete \") | AUTHORITY:  0 (\"\")  > 4 (\" View/Edit/Delete \") | AUTHORITY:  0 (\"\")  > 4 (\" View/Edit/Delete \") | AUTHORITY:  0 (\"\")  > 4 (\" View/Edi','2021-01-11 15:40:32.324213','Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/87.0.4280.141 Safari/537.36'),(73,'49.146.42.127',1,0,3,0,0,10080,463,0,'add/edit Access rights record','LEVEL: 0 (\"\")  >  2 (\" Super Admin \") | MODULE: 0 (\"\")  >  10120 (\" Devices \") | AUTHORITY:  0 (\"\")  > 0 (\" No Access \") | LEVEL: 0 (\"\")  >  2 (\" Super Admin \") | MODULE: 0 (\"\")  >  10160 (\" Brute Force Login Attempt \") | AUTHORITY:  0 (\"\")  > 0 (\" No Access \") | LEVEL: 0 (\"\")  >  2 (\" Super Admin \") | MODULE: 0 (\"\")  >  10180 (\" Bruteforce IP \") | AUTHORITY:  0 (\"\")  > 0 (\" No Access \") | LEVEL: 0 (\"\")  >  2 (\" Super Admin \") | MODULE: 0 (\"\")  >  15010 (\" Addon: Group License \") | AUTHORITY:  0 (\"\")  > 0 (\" No Access \") | LEVEL: 0 (\"\")  >  2 (\" Super Admin \") | MODULE: 0 (\"\")  >  15030 (\" Addon: User License \") | AUTHORITY:  0 (\"\")  > 0 (\" No Access \") | LEVEL: 0 (\"\")  >  2 (\" Super Admin \") | MODULE: 0 (\"\")  >  15050 (\" Addon: Queuing \") | AUTHORITY:  0 (\"\")  > 0 (\" No Access \") | LEVEL: 0 (\"\")  >  2 (\" Super Admin \") | MODULE: 0 (\"\")  >  15070 (\" Addon: Resource \") | AUTHORITY:  0 (\"\")  > 0 (\" No Access \") | LEVEL: 0 (\"\")  >  2 (\" Super Admin \") | MODULE: 0 (\"\")  >  21030 (\" Section \") | AUTHORITY:  0 (\"\")  > 0 (\" No Access \") | LEVEL: 0 (\"\")  >  2 (\" Super Admin \") | MODULE: 0 (\"\")  >  21050 (\" Entrance \") | AUTHORITY:  0 (\"\")  > 0 (\" No Access \") | AUTHORITY:  0 (\"\")  > 4 (\" View/Edit/Delete \") | AUTHORITY:  0 (\"\")  > 4 (\" View/Edit/Delete \") | AUTHORITY:  0 (\"\")  > 4 (\" View/Edit/Delete \") | AUTHORITY:  0 (\"\")  > 4 (\" View/Edit/Delete \") | AUTHORITY:  0 (\"\")  > 4 (\" View/Edit/Delete \") | AUTHORITY:  0 (\"\")  > 4 (\" View/Edit/Delete \") | AUTHORITY:  0 (\"\")  > 4 (\" View/Edit/Delete \") | AUTHORITY:  0 (\"\")  > 4 (\" View/Edit/Delete \") | AUTHORITY:  0 (\"\")  > 4 (\" View/Edit/Delete \") | AUTHORITY:  0 (\"\")  > 4 (\" View/Edit/Delete \") | AUTHORITY:  0 (\"\")  > 4 (\" View/Edit/Delete \") | AUTHORITY:  0 (\"\")  > 4 (\" View/Edit/Delete \") | AUTHORITY:  0 (\"\")  > 4 (\" View/Edit/Delete \") | AUTHORITY:  0 (\"\")  > 4 (\" View/Edit/Delete \") | AUTHORITY:  0 (\"\")  > 4 (\" View/Edit/Delete \") | AUTHORITY:  0 (\"\")  > 4 (\" View/Edit/Delete \") | AUTHORITY:  0 (\"\")  > 4 (\" View/Edit/Delete \") | AUTHORITY:  0 (\"\")  > 4 (\" View/Edit/Delete \") | AUTHORITY:  0 (\"\")  > 4 (\" View/Edit/Delete \") | AUTHORITY:  0 (\"\")  > 4 (\" View/Edit/Delete \") | AUTHORITY:  0 (\"\")  > 4 (\" View/Edit/Delete \") | AUTHORITY:  0 (\"\")  > 4 (\" View/Edit/Delete \") | AUTHORITY:  0 (\"\")  > 4 (\" View/Edit/Delete \") | AUTHORITY:  0 (\"\")  > 4 (\" View/Edit/Delete \") | AUTHORITY:  0 (\"\")  > 4 (\" View/Edit/Delete \") | AUTHORITY:  0 (\"\")  > 4 (\" View/Edit/Delete \") | AUTHORITY:  0 (\"\")  > 4 (\" View/Edit/Delete \") | AUTHORITY:  0 (\"\")  > 4 (\" View/Edit/Delete \") | AUTHORITY:  0 (\"\")  > 4 (\" View/Edit/Delete \") | AUTHORITY:  0 (\"\")  > 4 (\" View/Edit/Delete \") | AUTHORITY:  0 (\"\")  > 4 (\" View/Edit/Delete \") | AUTHORITY:  0 (\"\")  > 4 (\" View/Edit/Delete \") | AUTHORITY:  0 (\"\")  > 4 (\" View/Edit/Delete \") | AUTHORITY:  0 (\"\")  > 4 (\" View/Edit/Delete \") | AUTHORITY:  0 (\"\")  > 4 (\" View/Edit/Delete \") | AUTHORITY:  0 (\"\")  > 4 (\" View/Edit/Delete \") | AUTHORITY:  0 (\"\")  > 4 (\" View/Edit/Delete \") | AUTHORITY:  0 (\"\")  > 4 (\" View/Edit/Delete \") | AUTHORITY:  0 (\"\")  > 4 (\" View/Edit/Delete \") | AUTHORITY:  0 (\"\")  > 4 (\" View/Edit/Delete \") | AUTHORITY:  0 (\"\")  > 4 (\" View/Edit/Delete \") | AUTHORITY:  0 (\"\")  > 4 (\" View/Edit/Delete \") | AUTHORITY:  0 (\"\")  > 4 (\" View/Edit/Delete \") | AUTHORITY:  0 (\"\")  > 4 (\" View/Edit/Delete \") | AUTHORITY:  0 (\"\")  > 4 (\" View/Edit/Delete \") | AUTHORITY:  0 (\"\")  > 4 (\" View/Edit/Delete \") | AUTHORITY:  0 (\"\")  > 4 (\" View/Edit/Delete \") | AUTHORITY:  0 (\"\")  > 4 (\" View/Edit/Delete \") | AUTHORITY:  0 (\"\")  > 4 (\" View/Edit/Delete \") | AUTHORITY:  0 (\"\")  > 4 (\" View/Edit/Delete \") | AUTHORITY:  0 (\"\")  > 4 (\" View/Edit/Delete \") | AUTHORITY:  0 (\"\")  > 4 (\" View/Edit/Delete \") | AUTHORITY:  0 (\"\")  > 4 (\" View/Edit/Delete \") | AUTHORITY:  0 (\"\")  > 4 (\" View/Edit/Delete \") | AUTHORITY:  0 (\"\")  > 4 (\" View/Edit/Delete \") | AUTHORITY:  0 (\"\")  > 4 (\" View/Edit/Delete \") | AUTHORITY:  0 (\"\")  > 4 (\" View/Edit/Delete \") | AUTHORITY:  0 (\"\")  > 4 (\" View/Edi','2021-01-11 15:40:32.329678','Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/87.0.4280.141 Safari/537.36'),(74,'49.146.42.127',1,0,3,0,0,10080,464,0,'add/edit Access rights record','LEVEL: 0 (\"\")  >  2 (\" Super Admin \") | MODULE: 0 (\"\")  >  10120 (\" Devices \") | AUTHORITY:  0 (\"\")  > 0 (\" No Access \") | LEVEL: 0 (\"\")  >  2 (\" Super Admin \") | MODULE: 0 (\"\")  >  10160 (\" Brute Force Login Attempt \") | AUTHORITY:  0 (\"\")  > 0 (\" No Access \") | LEVEL: 0 (\"\")  >  2 (\" Super Admin \") | MODULE: 0 (\"\")  >  10180 (\" Bruteforce IP \") | AUTHORITY:  0 (\"\")  > 0 (\" No Access \") | LEVEL: 0 (\"\")  >  2 (\" Super Admin \") | MODULE: 0 (\"\")  >  15010 (\" Addon: Group License \") | AUTHORITY:  0 (\"\")  > 0 (\" No Access \") | LEVEL: 0 (\"\")  >  2 (\" Super Admin \") | MODULE: 0 (\"\")  >  15030 (\" Addon: User License \") | AUTHORITY:  0 (\"\")  > 0 (\" No Access \") | LEVEL: 0 (\"\")  >  2 (\" Super Admin \") | MODULE: 0 (\"\")  >  15050 (\" Addon: Queuing \") | AUTHORITY:  0 (\"\")  > 0 (\" No Access \") | LEVEL: 0 (\"\")  >  2 (\" Super Admin \") | MODULE: 0 (\"\")  >  15070 (\" Addon: Resource \") | AUTHORITY:  0 (\"\")  > 0 (\" No Access \") | LEVEL: 0 (\"\")  >  2 (\" Super Admin \") | MODULE: 0 (\"\")  >  21030 (\" Section \") | AUTHORITY:  0 (\"\")  > 0 (\" No Access \") | LEVEL: 0 (\"\")  >  2 (\" Super Admin \") | MODULE: 0 (\"\")  >  21050 (\" Entrance \") | AUTHORITY:  0 (\"\")  > 0 (\" No Access \") | AUTHORITY:  0 (\"\")  > 4 (\" View/Edit/Delete \") | AUTHORITY:  0 (\"\")  > 4 (\" View/Edit/Delete \") | AUTHORITY:  0 (\"\")  > 4 (\" View/Edit/Delete \") | AUTHORITY:  0 (\"\")  > 4 (\" View/Edit/Delete \") | AUTHORITY:  0 (\"\")  > 4 (\" View/Edit/Delete \") | AUTHORITY:  0 (\"\")  > 4 (\" View/Edit/Delete \") | AUTHORITY:  0 (\"\")  > 4 (\" View/Edit/Delete \") | AUTHORITY:  0 (\"\")  > 4 (\" View/Edit/Delete \") | AUTHORITY:  0 (\"\")  > 4 (\" View/Edit/Delete \") | AUTHORITY:  0 (\"\")  > 4 (\" View/Edit/Delete \") | AUTHORITY:  0 (\"\")  > 4 (\" View/Edit/Delete \") | AUTHORITY:  0 (\"\")  > 4 (\" View/Edit/Delete \") | AUTHORITY:  0 (\"\")  > 4 (\" View/Edit/Delete \") | AUTHORITY:  0 (\"\")  > 4 (\" View/Edit/Delete \") | AUTHORITY:  0 (\"\")  > 4 (\" View/Edit/Delete \") | AUTHORITY:  0 (\"\")  > 4 (\" View/Edit/Delete \") | AUTHORITY:  0 (\"\")  > 4 (\" View/Edit/Delete \") | AUTHORITY:  0 (\"\")  > 4 (\" View/Edit/Delete \") | AUTHORITY:  0 (\"\")  > 4 (\" View/Edit/Delete \") | AUTHORITY:  0 (\"\")  > 4 (\" View/Edit/Delete \") | AUTHORITY:  0 (\"\")  > 4 (\" View/Edit/Delete \") | AUTHORITY:  0 (\"\")  > 4 (\" View/Edit/Delete \") | AUTHORITY:  0 (\"\")  > 4 (\" View/Edit/Delete \") | AUTHORITY:  0 (\"\")  > 4 (\" View/Edit/Delete \") | AUTHORITY:  0 (\"\")  > 4 (\" View/Edit/Delete \") | AUTHORITY:  0 (\"\")  > 4 (\" View/Edit/Delete \") | AUTHORITY:  0 (\"\")  > 4 (\" View/Edit/Delete \") | AUTHORITY:  0 (\"\")  > 4 (\" View/Edit/Delete \") | AUTHORITY:  0 (\"\")  > 4 (\" View/Edit/Delete \") | AUTHORITY:  0 (\"\")  > 4 (\" View/Edit/Delete \") | AUTHORITY:  0 (\"\")  > 4 (\" View/Edit/Delete \") | AUTHORITY:  0 (\"\")  > 4 (\" View/Edit/Delete \") | AUTHORITY:  0 (\"\")  > 4 (\" View/Edit/Delete \") | AUTHORITY:  0 (\"\")  > 4 (\" View/Edit/Delete \") | AUTHORITY:  0 (\"\")  > 4 (\" View/Edit/Delete \") | AUTHORITY:  0 (\"\")  > 4 (\" View/Edit/Delete \") | AUTHORITY:  0 (\"\")  > 4 (\" View/Edit/Delete \") | AUTHORITY:  0 (\"\")  > 4 (\" View/Edit/Delete \") | AUTHORITY:  0 (\"\")  > 4 (\" View/Edit/Delete \") | AUTHORITY:  0 (\"\")  > 4 (\" View/Edit/Delete \") | AUTHORITY:  0 (\"\")  > 4 (\" View/Edit/Delete \") | AUTHORITY:  0 (\"\")  > 4 (\" View/Edit/Delete \") | AUTHORITY:  0 (\"\")  > 4 (\" View/Edit/Delete \") | AUTHORITY:  0 (\"\")  > 4 (\" View/Edit/Delete \") | AUTHORITY:  0 (\"\")  > 4 (\" View/Edit/Delete \") | AUTHORITY:  0 (\"\")  > 4 (\" View/Edit/Delete \") | AUTHORITY:  0 (\"\")  > 4 (\" View/Edit/Delete \") | AUTHORITY:  0 (\"\")  > 4 (\" View/Edit/Delete \") | AUTHORITY:  0 (\"\")  > 4 (\" View/Edit/Delete \") | AUTHORITY:  0 (\"\")  > 4 (\" View/Edit/Delete \") | AUTHORITY:  0 (\"\")  > 4 (\" View/Edit/Delete \") | AUTHORITY:  0 (\"\")  > 4 (\" View/Edit/Delete \") | AUTHORITY:  0 (\"\")  > 4 (\" View/Edit/Delete \") | AUTHORITY:  0 (\"\")  > 4 (\" View/Edit/Delete \") | AUTHORITY:  0 (\"\")  > 4 (\" View/Edit/Delete \") | AUTHORITY:  0 (\"\")  > 4 (\" View/Edit/Delete \") | AUTHORITY:  0 (\"\")  > 4 (\" View/Edit/Delete \") | AUTHORITY:  0 (\"\")  > 4 (\" View/Edi','2021-01-11 15:40:32.334132','Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/87.0.4280.141 Safari/537.36'),(75,'49.146.42.127',1,0,3,0,0,10080,465,0,'add/edit Access rights record','LEVEL: 0 (\"\")  >  2 (\" Super Admin \") | MODULE: 0 (\"\")  >  10120 (\" Devices \") | AUTHORITY:  0 (\"\")  > 0 (\" No Access \") | LEVEL: 0 (\"\")  >  2 (\" Super Admin \") | MODULE: 0 (\"\")  >  10160 (\" Brute Force Login Attempt \") | AUTHORITY:  0 (\"\")  > 0 (\" No Access \") | LEVEL: 0 (\"\")  >  2 (\" Super Admin \") | MODULE: 0 (\"\")  >  10180 (\" Bruteforce IP \") | AUTHORITY:  0 (\"\")  > 0 (\" No Access \") | LEVEL: 0 (\"\")  >  2 (\" Super Admin \") | MODULE: 0 (\"\")  >  15010 (\" Addon: Group License \") | AUTHORITY:  0 (\"\")  > 0 (\" No Access \") | LEVEL: 0 (\"\")  >  2 (\" Super Admin \") | MODULE: 0 (\"\")  >  15030 (\" Addon: User License \") | AUTHORITY:  0 (\"\")  > 0 (\" No Access \") | LEVEL: 0 (\"\")  >  2 (\" Super Admin \") | MODULE: 0 (\"\")  >  15050 (\" Addon: Queuing \") | AUTHORITY:  0 (\"\")  > 0 (\" No Access \") | LEVEL: 0 (\"\")  >  2 (\" Super Admin \") | MODULE: 0 (\"\")  >  15070 (\" Addon: Resource \") | AUTHORITY:  0 (\"\")  > 0 (\" No Access \") | LEVEL: 0 (\"\")  >  2 (\" Super Admin \") | MODULE: 0 (\"\")  >  21030 (\" Section \") | AUTHORITY:  0 (\"\")  > 0 (\" No Access \") | LEVEL: 0 (\"\")  >  2 (\" Super Admin \") | MODULE: 0 (\"\")  >  21050 (\" Entrance \") | AUTHORITY:  0 (\"\")  > 0 (\" No Access \") | AUTHORITY:  0 (\"\")  > 4 (\" View/Edit/Delete \") | AUTHORITY:  0 (\"\")  > 4 (\" View/Edit/Delete \") | AUTHORITY:  0 (\"\")  > 4 (\" View/Edit/Delete \") | AUTHORITY:  0 (\"\")  > 4 (\" View/Edit/Delete \") | AUTHORITY:  0 (\"\")  > 4 (\" View/Edit/Delete \") | AUTHORITY:  0 (\"\")  > 4 (\" View/Edit/Delete \") | AUTHORITY:  0 (\"\")  > 4 (\" View/Edit/Delete \") | AUTHORITY:  0 (\"\")  > 4 (\" View/Edit/Delete \") | AUTHORITY:  0 (\"\")  > 4 (\" View/Edit/Delete \") | AUTHORITY:  0 (\"\")  > 4 (\" View/Edit/Delete \") | AUTHORITY:  0 (\"\")  > 4 (\" View/Edit/Delete \") | AUTHORITY:  0 (\"\")  > 4 (\" View/Edit/Delete \") | AUTHORITY:  0 (\"\")  > 4 (\" View/Edit/Delete \") | AUTHORITY:  0 (\"\")  > 4 (\" View/Edit/Delete \") | AUTHORITY:  0 (\"\")  > 4 (\" View/Edit/Delete \") | AUTHORITY:  0 (\"\")  > 4 (\" View/Edit/Delete \") | AUTHORITY:  0 (\"\")  > 4 (\" View/Edit/Delete \") | AUTHORITY:  0 (\"\")  > 4 (\" View/Edit/Delete \") | AUTHORITY:  0 (\"\")  > 4 (\" View/Edit/Delete \") | AUTHORITY:  0 (\"\")  > 4 (\" View/Edit/Delete \") | AUTHORITY:  0 (\"\")  > 4 (\" View/Edit/Delete \") | AUTHORITY:  0 (\"\")  > 4 (\" View/Edit/Delete \") | AUTHORITY:  0 (\"\")  > 4 (\" View/Edit/Delete \") | AUTHORITY:  0 (\"\")  > 4 (\" View/Edit/Delete \") | AUTHORITY:  0 (\"\")  > 4 (\" View/Edit/Delete \") | AUTHORITY:  0 (\"\")  > 4 (\" View/Edit/Delete \") | AUTHORITY:  0 (\"\")  > 4 (\" View/Edit/Delete \") | AUTHORITY:  0 (\"\")  > 4 (\" View/Edit/Delete \") | AUTHORITY:  0 (\"\")  > 4 (\" View/Edit/Delete \") | AUTHORITY:  0 (\"\")  > 4 (\" View/Edit/Delete \") | AUTHORITY:  0 (\"\")  > 4 (\" View/Edit/Delete \") | AUTHORITY:  0 (\"\")  > 4 (\" View/Edit/Delete \") | AUTHORITY:  0 (\"\")  > 4 (\" View/Edit/Delete \") | AUTHORITY:  0 (\"\")  > 4 (\" View/Edit/Delete \") | AUTHORITY:  0 (\"\")  > 4 (\" View/Edit/Delete \") | AUTHORITY:  0 (\"\")  > 4 (\" View/Edit/Delete \") | AUTHORITY:  0 (\"\")  > 4 (\" View/Edit/Delete \") | AUTHORITY:  0 (\"\")  > 4 (\" View/Edit/Delete \") | AUTHORITY:  0 (\"\")  > 4 (\" View/Edit/Delete \") | AUTHORITY:  0 (\"\")  > 4 (\" View/Edit/Delete \") | AUTHORITY:  0 (\"\")  > 4 (\" View/Edit/Delete \") | AUTHORITY:  0 (\"\")  > 4 (\" View/Edit/Delete \") | AUTHORITY:  0 (\"\")  > 4 (\" View/Edit/Delete \") | AUTHORITY:  0 (\"\")  > 4 (\" View/Edit/Delete \") | AUTHORITY:  0 (\"\")  > 4 (\" View/Edit/Delete \") | AUTHORITY:  0 (\"\")  > 4 (\" View/Edit/Delete \") | AUTHORITY:  0 (\"\")  > 4 (\" View/Edit/Delete \") | AUTHORITY:  0 (\"\")  > 4 (\" View/Edit/Delete \") | AUTHORITY:  0 (\"\")  > 4 (\" View/Edit/Delete \") | AUTHORITY:  0 (\"\")  > 4 (\" View/Edit/Delete \") | AUTHORITY:  0 (\"\")  > 4 (\" View/Edit/Delete \") | AUTHORITY:  0 (\"\")  > 4 (\" View/Edit/Delete \") | AUTHORITY:  0 (\"\")  > 4 (\" View/Edit/Delete \") | AUTHORITY:  0 (\"\")  > 4 (\" View/Edit/Delete \") | AUTHORITY:  0 (\"\")  > 4 (\" View/Edit/Delete \") | AUTHORITY:  0 (\"\")  > 4 (\" View/Edit/Delete \") | AUTHORITY:  0 (\"\")  > 4 (\" View/Edit/Delete \") | AUTHORITY:  0 (\"\")  > 4 (\" View/Edi','2021-01-11 15:40:32.338525','Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/87.0.4280.141 Safari/537.36'),(76,'49.146.42.127',1,0,3,0,0,10080,466,0,'add/edit Access rights record','LEVEL: 0 (\"\")  >  2 (\" Super Admin \") | MODULE: 0 (\"\")  >  10120 (\" Devices \") | AUTHORITY:  0 (\"\")  > 0 (\" No Access \") | LEVEL: 0 (\"\")  >  2 (\" Super Admin \") | MODULE: 0 (\"\")  >  10160 (\" Brute Force Login Attempt \") | AUTHORITY:  0 (\"\")  > 0 (\" No Access \") | LEVEL: 0 (\"\")  >  2 (\" Super Admin \") | MODULE: 0 (\"\")  >  10180 (\" Bruteforce IP \") | AUTHORITY:  0 (\"\")  > 0 (\" No Access \") | LEVEL: 0 (\"\")  >  2 (\" Super Admin \") | MODULE: 0 (\"\")  >  15010 (\" Addon: Group License \") | AUTHORITY:  0 (\"\")  > 0 (\" No Access \") | LEVEL: 0 (\"\")  >  2 (\" Super Admin \") | MODULE: 0 (\"\")  >  15030 (\" Addon: User License \") | AUTHORITY:  0 (\"\")  > 0 (\" No Access \") | LEVEL: 0 (\"\")  >  2 (\" Super Admin \") | MODULE: 0 (\"\")  >  15050 (\" Addon: Queuing \") | AUTHORITY:  0 (\"\")  > 0 (\" No Access \") | LEVEL: 0 (\"\")  >  2 (\" Super Admin \") | MODULE: 0 (\"\")  >  15070 (\" Addon: Resource \") | AUTHORITY:  0 (\"\")  > 0 (\" No Access \") | LEVEL: 0 (\"\")  >  2 (\" Super Admin \") | MODULE: 0 (\"\")  >  21030 (\" Section \") | AUTHORITY:  0 (\"\")  > 0 (\" No Access \") | LEVEL: 0 (\"\")  >  2 (\" Super Admin \") | MODULE: 0 (\"\")  >  21050 (\" Entrance \") | AUTHORITY:  0 (\"\")  > 0 (\" No Access \") | AUTHORITY:  0 (\"\")  > 4 (\" View/Edit/Delete \") | AUTHORITY:  0 (\"\")  > 4 (\" View/Edit/Delete \") | AUTHORITY:  0 (\"\")  > 4 (\" View/Edit/Delete \") | AUTHORITY:  0 (\"\")  > 4 (\" View/Edit/Delete \") | AUTHORITY:  0 (\"\")  > 4 (\" View/Edit/Delete \") | AUTHORITY:  0 (\"\")  > 4 (\" View/Edit/Delete \") | AUTHORITY:  0 (\"\")  > 4 (\" View/Edit/Delete \") | AUTHORITY:  0 (\"\")  > 4 (\" View/Edit/Delete \") | AUTHORITY:  0 (\"\")  > 4 (\" View/Edit/Delete \") | AUTHORITY:  0 (\"\")  > 4 (\" View/Edit/Delete \") | AUTHORITY:  0 (\"\")  > 4 (\" View/Edit/Delete \") | AUTHORITY:  0 (\"\")  > 4 (\" View/Edit/Delete \") | AUTHORITY:  0 (\"\")  > 4 (\" View/Edit/Delete \") | AUTHORITY:  0 (\"\")  > 4 (\" View/Edit/Delete \") | AUTHORITY:  0 (\"\")  > 4 (\" View/Edit/Delete \") | AUTHORITY:  0 (\"\")  > 4 (\" View/Edit/Delete \") | AUTHORITY:  0 (\"\")  > 4 (\" View/Edit/Delete \") | AUTHORITY:  0 (\"\")  > 4 (\" View/Edit/Delete \") | AUTHORITY:  0 (\"\")  > 4 (\" View/Edit/Delete \") | AUTHORITY:  0 (\"\")  > 4 (\" View/Edit/Delete \") | AUTHORITY:  0 (\"\")  > 4 (\" View/Edit/Delete \") | AUTHORITY:  0 (\"\")  > 4 (\" View/Edit/Delete \") | AUTHORITY:  0 (\"\")  > 4 (\" View/Edit/Delete \") | AUTHORITY:  0 (\"\")  > 4 (\" View/Edit/Delete \") | AUTHORITY:  0 (\"\")  > 4 (\" View/Edit/Delete \") | AUTHORITY:  0 (\"\")  > 4 (\" View/Edit/Delete \") | AUTHORITY:  0 (\"\")  > 4 (\" View/Edit/Delete \") | AUTHORITY:  0 (\"\")  > 4 (\" View/Edit/Delete \") | AUTHORITY:  0 (\"\")  > 4 (\" View/Edit/Delete \") | AUTHORITY:  0 (\"\")  > 4 (\" View/Edit/Delete \") | AUTHORITY:  0 (\"\")  > 4 (\" View/Edit/Delete \") | AUTHORITY:  0 (\"\")  > 4 (\" View/Edit/Delete \") | AUTHORITY:  0 (\"\")  > 4 (\" View/Edit/Delete \") | AUTHORITY:  0 (\"\")  > 4 (\" View/Edit/Delete \") | AUTHORITY:  0 (\"\")  > 4 (\" View/Edit/Delete \") | AUTHORITY:  0 (\"\")  > 4 (\" View/Edit/Delete \") | AUTHORITY:  0 (\"\")  > 4 (\" View/Edit/Delete \") | AUTHORITY:  0 (\"\")  > 4 (\" View/Edit/Delete \") | AUTHORITY:  0 (\"\")  > 4 (\" View/Edit/Delete \") | AUTHORITY:  0 (\"\")  > 4 (\" View/Edit/Delete \") | AUTHORITY:  0 (\"\")  > 4 (\" View/Edit/Delete \") | AUTHORITY:  0 (\"\")  > 4 (\" View/Edit/Delete \") | AUTHORITY:  0 (\"\")  > 4 (\" View/Edit/Delete \") | AUTHORITY:  0 (\"\")  > 4 (\" View/Edit/Delete \") | AUTHORITY:  0 (\"\")  > 4 (\" View/Edit/Delete \") | AUTHORITY:  0 (\"\")  > 4 (\" View/Edit/Delete \") | AUTHORITY:  0 (\"\")  > 4 (\" View/Edit/Delete \") | AUTHORITY:  0 (\"\")  > 4 (\" View/Edit/Delete \") | AUTHORITY:  0 (\"\")  > 4 (\" View/Edit/Delete \") | AUTHORITY:  0 (\"\")  > 4 (\" View/Edit/Delete \") | AUTHORITY:  0 (\"\")  > 4 (\" View/Edit/Delete \") | AUTHORITY:  0 (\"\")  > 4 (\" View/Edit/Delete \") | AUTHORITY:  0 (\"\")  > 4 (\" View/Edit/Delete \") | AUTHORITY:  0 (\"\")  > 4 (\" View/Edit/Delete \") | AUTHORITY:  0 (\"\")  > 4 (\" View/Edit/Delete \") | AUTHORITY:  0 (\"\")  > 4 (\" View/Edit/Delete \") | AUTHORITY:  0 (\"\")  > 4 (\" View/Edit/Delete \") | AUTHORITY:  0 (\"\")  > 4 (\" View/Edi','2021-01-11 15:40:32.343429','Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/87.0.4280.141 Safari/537.36'),(77,'49.146.42.127',1,0,3,0,0,10080,467,0,'add/edit Access rights record','LEVEL: 0 (\"\")  >  2 (\" Super Admin \") | MODULE: 0 (\"\")  >  10120 (\" Devices \") | AUTHORITY:  0 (\"\")  > 0 (\" No Access \") | LEVEL: 0 (\"\")  >  2 (\" Super Admin \") | MODULE: 0 (\"\")  >  10160 (\" Brute Force Login Attempt \") | AUTHORITY:  0 (\"\")  > 0 (\" No Access \") | LEVEL: 0 (\"\")  >  2 (\" Super Admin \") | MODULE: 0 (\"\")  >  10180 (\" Bruteforce IP \") | AUTHORITY:  0 (\"\")  > 0 (\" No Access \") | LEVEL: 0 (\"\")  >  2 (\" Super Admin \") | MODULE: 0 (\"\")  >  15010 (\" Addon: Group License \") | AUTHORITY:  0 (\"\")  > 0 (\" No Access \") | LEVEL: 0 (\"\")  >  2 (\" Super Admin \") | MODULE: 0 (\"\")  >  15030 (\" Addon: User License \") | AUTHORITY:  0 (\"\")  > 0 (\" No Access \") | LEVEL: 0 (\"\")  >  2 (\" Super Admin \") | MODULE: 0 (\"\")  >  15050 (\" Addon: Queuing \") | AUTHORITY:  0 (\"\")  > 0 (\" No Access \") | LEVEL: 0 (\"\")  >  2 (\" Super Admin \") | MODULE: 0 (\"\")  >  15070 (\" Addon: Resource \") | AUTHORITY:  0 (\"\")  > 0 (\" No Access \") | LEVEL: 0 (\"\")  >  2 (\" Super Admin \") | MODULE: 0 (\"\")  >  21030 (\" Section \") | AUTHORITY:  0 (\"\")  > 0 (\" No Access \") | LEVEL: 0 (\"\")  >  2 (\" Super Admin \") | MODULE: 0 (\"\")  >  21050 (\" Entrance \") | AUTHORITY:  0 (\"\")  > 0 (\" No Access \") | AUTHORITY:  0 (\"\")  > 4 (\" View/Edit/Delete \") | AUTHORITY:  0 (\"\")  > 4 (\" View/Edit/Delete \") | AUTHORITY:  0 (\"\")  > 4 (\" View/Edit/Delete \") | AUTHORITY:  0 (\"\")  > 4 (\" View/Edit/Delete \") | AUTHORITY:  0 (\"\")  > 4 (\" View/Edit/Delete \") | AUTHORITY:  0 (\"\")  > 4 (\" View/Edit/Delete \") | AUTHORITY:  0 (\"\")  > 4 (\" View/Edit/Delete \") | AUTHORITY:  0 (\"\")  > 4 (\" View/Edit/Delete \") | AUTHORITY:  0 (\"\")  > 4 (\" View/Edit/Delete \") | AUTHORITY:  0 (\"\")  > 4 (\" View/Edit/Delete \") | AUTHORITY:  0 (\"\")  > 4 (\" View/Edit/Delete \") | AUTHORITY:  0 (\"\")  > 4 (\" View/Edit/Delete \") | AUTHORITY:  0 (\"\")  > 4 (\" View/Edit/Delete \") | AUTHORITY:  0 (\"\")  > 4 (\" View/Edit/Delete \") | AUTHORITY:  0 (\"\")  > 4 (\" View/Edit/Delete \") | AUTHORITY:  0 (\"\")  > 4 (\" View/Edit/Delete \") | AUTHORITY:  0 (\"\")  > 4 (\" View/Edit/Delete \") | AUTHORITY:  0 (\"\")  > 4 (\" View/Edit/Delete \") | AUTHORITY:  0 (\"\")  > 4 (\" View/Edit/Delete \") | AUTHORITY:  0 (\"\")  > 4 (\" View/Edit/Delete \") | AUTHORITY:  0 (\"\")  > 4 (\" View/Edit/Delete \") | AUTHORITY:  0 (\"\")  > 4 (\" View/Edit/Delete \") | AUTHORITY:  0 (\"\")  > 4 (\" View/Edit/Delete \") | AUTHORITY:  0 (\"\")  > 4 (\" View/Edit/Delete \") | AUTHORITY:  0 (\"\")  > 4 (\" View/Edit/Delete \") | AUTHORITY:  0 (\"\")  > 4 (\" View/Edit/Delete \") | AUTHORITY:  0 (\"\")  > 4 (\" View/Edit/Delete \") | AUTHORITY:  0 (\"\")  > 4 (\" View/Edit/Delete \") | AUTHORITY:  0 (\"\")  > 4 (\" View/Edit/Delete \") | AUTHORITY:  0 (\"\")  > 4 (\" View/Edit/Delete \") | AUTHORITY:  0 (\"\")  > 4 (\" View/Edit/Delete \") | AUTHORITY:  0 (\"\")  > 4 (\" View/Edit/Delete \") | AUTHORITY:  0 (\"\")  > 4 (\" View/Edit/Delete \") | AUTHORITY:  0 (\"\")  > 4 (\" View/Edit/Delete \") | AUTHORITY:  0 (\"\")  > 4 (\" View/Edit/Delete \") | AUTHORITY:  0 (\"\")  > 4 (\" View/Edit/Delete \") | AUTHORITY:  0 (\"\")  > 4 (\" View/Edit/Delete \") | AUTHORITY:  0 (\"\")  > 4 (\" View/Edit/Delete \") | AUTHORITY:  0 (\"\")  > 4 (\" View/Edit/Delete \") | AUTHORITY:  0 (\"\")  > 4 (\" View/Edit/Delete \") | AUTHORITY:  0 (\"\")  > 4 (\" View/Edit/Delete \") | AUTHORITY:  0 (\"\")  > 4 (\" View/Edit/Delete \") | AUTHORITY:  0 (\"\")  > 4 (\" View/Edit/Delete \") | AUTHORITY:  0 (\"\")  > 4 (\" View/Edit/Delete \") | AUTHORITY:  0 (\"\")  > 4 (\" View/Edit/Delete \") | AUTHORITY:  0 (\"\")  > 4 (\" View/Edit/Delete \") | AUTHORITY:  0 (\"\")  > 4 (\" View/Edit/Delete \") | AUTHORITY:  0 (\"\")  > 4 (\" View/Edit/Delete \") | AUTHORITY:  0 (\"\")  > 4 (\" View/Edit/Delete \") | AUTHORITY:  0 (\"\")  > 4 (\" View/Edit/Delete \") | AUTHORITY:  0 (\"\")  > 4 (\" View/Edit/Delete \") | AUTHORITY:  0 (\"\")  > 4 (\" View/Edit/Delete \") | AUTHORITY:  0 (\"\")  > 4 (\" View/Edit/Delete \") | AUTHORITY:  0 (\"\")  > 4 (\" View/Edit/Delete \") | AUTHORITY:  0 (\"\")  > 4 (\" View/Edit/Delete \") | AUTHORITY:  0 (\"\")  > 4 (\" View/Edit/Delete \") | AUTHORITY:  0 (\"\")  > 4 (\" View/Edit/Delete \") | AUTHORITY:  0 (\"\")  > 4 (\" View/Edi','2021-01-11 15:40:32.347851','Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/87.0.4280.141 Safari/537.36'),(78,'49.146.42.127',1,0,6,0,0,21010,1,0,'add/edit Department record','Description: \"  \" > \" Supplies Division \" | Status: \" 0 \" > \" 2 \"','2021-01-11 15:42:44.683835','Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/87.0.4280.88 Safari/537.36'),(79,'49.146.42.127',1,0,6,0,0,21010,2,0,'add/edit Department record','Description: \"  \" > \" Human Resources \" | Status: \" 0 \" > \" 2 \"','2021-01-11 15:44:03.227983','Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/87.0.4280.88 Safari/537.36'),(80,'49.146.42.127',1,0,6,0,0,21010,3,0,'add/edit Department record','Description: \"  \" > \" Records Division \" | Status: \" 0 \" > \" 2 \"','2021-01-11 15:47:29.952577','Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/87.0.4280.88 Safari/537.36'),(81,'49.146.42.127',1,0,6,0,0,21050,1,0,'add/edit Entrance record','Description: \"  \" > \" Entrance \" | Direction: \" 0 \" > \" 2 \" | Status: \" 0 \" > \" 2 \"','2021-01-11 15:47:53.063158','Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/87.0.4280.88 Safari/537.36'),(82,'49.146.42.127',1,0,6,0,0,21050,2,0,'add/edit Entrance record','Description: \"  \" > \" Exit \" | Direction: \" 0 \" > \" 2 \" | Status: \" 0 \" > \" 2 \"','2021-01-11 15:47:59.783115','Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/87.0.4280.88 Safari/537.36'),(83,'49.146.42.127',1,0,6,0,0,21030,1,0,'add/edit Section record','Department: \" 0 \" > \" 2 \" | Description: \"  \" > \" Main \" | Status: \" 0 \" > \" 2 \"','2021-01-11 15:52:18.605781','Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/87.0.4280.88 Safari/537.36'),(84,'49.146.42.127',1,0,3,0,0,40010,1,0,'add/edit Registration record','Department: \" 0 \" > \" 2 \" | Section: \" 0 \" > \" 1 \" | First name: \"  \" > \" asd \" | Middle name: \"  \" > \" asd \" | Last name: \"  \" > \" asd \" | Suffix: \"  \" > \" asd \" | Gender: \" 0 \" > \" 2 \" | Notification Phone Number: \"  \" > \" +639275929044 \" | Emergency Contact Person: \"  \" > \" adsasd \" | Emergency Contact Numbher: \"  \" > \" +639275929044 \" | Status: \" 0 \" > \" 2 \"','2021-01-11 16:20:55.855255','Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/87.0.4280.141 Safari/537.36'),(85,'49.146.42.127',1,0,3,0,0,40010,2,0,'add/edit Registration record','Department: \" 0 \" > \" 2 \" | Section: \" 0 \" > \" 1 \" | First name: \"  \" > \" Aira May \" | Last name: \"  \" > \" Cadiente \" | Gender: \" 0 \" > \" 2 \" | Notification Phone Number: \"  \" > \" +639655460720 \" | Emergency Contact Person: \"  \" > \" A \" | Emergency Contact Numbher: \"  \" > \" +639655460720 \" | Status: \" 0 \" > \" 2 \"','2021-01-11 16:39:01.109162','Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/87.0.4280.88 Safari/537.36'),(86,'49.146.42.127',1,0,3,0,0,40010,3,0,'add/edit Registration record','Department: \" 0 \" > \" 2 \" | Section: \" 0 \" > \" 1 \" | First name: \"  \" > \" Labs \" | Middle name: \"  \" > \" Z. \" | Last name: \"  \" > \" Jay \" | Gender: \" 0 \" > \" 2 \" | Notification Phone Number: \"  \" > \" +639954575836 \" | Emergency Contact Person: \"  \" > \" Zaira Labasan \" | Emergency Contact Numbher: \"  \" > \" +639954575836 \" | Status: \" 0 \" > \" 2 \"','2021-01-13 09:47:04.536229','Mozilla/5.0 (Windows NT 6.3; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/87.0.4280.141 Safari/537.36'),(87,'49.146.42.127',1,0,6,0,0,40050,1,0,'add/edit User record','Department: \" 0 \" > \" 2 \" | Section: \" 0 \" > \" 1 \" | Unique Code: \"  \" > \" DEF.20210113.94817495713.Knd4ASw \" | First name: \"  \" > \" Labs \" | Middle name: \"  \" > \" Z. \" | Last name: \"  \" > \" Jay \" | Gender: \" 0 \" > \" 2 \" | Notification Mobile Number: \"  \" > \" +639954575836 \" | Emergency Contact Person: \"  \" > \" Zaira Labasan \" | Emergency Contact Number: \"  \" > \" +639954575836 \" | Status: \" 0 \" > \" 2 \"','2021-01-13 09:48:17.529839','Mozilla/5.0 (Windows NT 6.3; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/87.0.4280.141 Safari/537.36'),(88,'49.146.42.127',1,0,6,0,0,40010,3,0,'add/edit Registration record','User: \" 0 \" > \" -9223372036854700032 \" | Status: \" 2 \" > \" 4 \"','2021-01-13 09:48:17.532366','Mozilla/5.0 (Windows NT 6.3; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/87.0.4280.141 Safari/537.36'),(89,'49.146.42.127',1,0,6,0,0,40070,1,0,'add/edit Attendance record','User: \" 0 \" > \" 1 \" | Date: \" 1000-01-01 00:00:00.000000 \" > \" 2021-01-13 10:05:56.014748 \" | In: \" 0 \" > \" 2 \" | Out: \" 0 \" > \" 1 \" | Entrance: \"  \" > \" Entrance \" | Device Key: \"  \" > \" cec3ddbdce6dae96.RMX2040 \" | Status: \" 0 \" > \" 2 \"','2021-01-13 10:05:56.024121','Mozilla/5.0 (Linux; Android 10; RMX2040 Build/QP1A.190711.020; wv) AppleWebKit/537.36 (KHTML, like Gecko) Version/4.0 Chrome/78.0.3904.96 Mobile Safari/537.36'),(90,'49.146.42.127',1,0,6,0,0,40070,2,0,'add/edit Attendance record','User: \" 0 \" > \" 1 \" | Date: \" 1000-01-01 00:00:00.000000 \" > \" 2021-01-13 10:06:06.061456 \" | In: \" 0 \" > \" 2 \" | Out: \" 0 \" > \" 1 \" | Entrance: \"  \" > \" Entrance \" | Device Key: \"  \" > \" cec3ddbdce6dae96.RMX2040 \" | Status: \" 0 \" > \" 2 \"','2021-01-13 10:06:06.068493','Mozilla/5.0 (Linux; Android 10; RMX2040 Build/QP1A.190711.020; wv) AppleWebKit/537.36 (KHTML, like Gecko) Version/4.0 Chrome/78.0.3904.96 Mobile Safari/537.36'),(91,'49.146.42.127',1,0,6,0,0,40070,3,0,'add/edit Attendance record','User: \" 0 \" > \" 1 \" | Date: \" 1000-01-01 00:00:00.000000 \" > \" 2021-01-13 10:07:00.484073 \" | In: \" 0 \" > \" 2 \" | Out: \" 0 \" > \" 1 \" | Entrance: \"  \" > \" Entrance \" | Device Key: \"  \" > \" 1fbbebbacafeccbf.Redmi Note 7 \" | Status: \" 0 \" > \" 2 \"','2021-01-13 10:07:00.494280','Mozilla/5.0 (Linux; Android 10; Redmi Note 7 Build/QKQ1.190910.002; wv) AppleWebKit/537.36 (KHTML, like Gecko) Version/4.0 Chrome/87.0.4280.141 Mobile Safari/537.36'),(92,'49.146.42.127',1,0,6,0,0,40070,4,0,'add/edit Attendance record','User: \" 0 \" > \" 1 \" | Date: \" 1000-01-01 00:00:00.000000 \" > \" 2021-01-13 10:11:22.932864 \" | In: \" 0 \" > \" 2 \" | Out: \" 0 \" > \" 1 \" | Entrance: \"  \" > \" Entrance \" | Device Key: \"  \" > \" 1fbbebbacafeccbf.Redmi Note 7 \" | Status: \" 0 \" > \" 2 \"','2021-01-13 10:11:22.939869','Mozilla/5.0 (Linux; Android 10; Redmi Note 7 Build/QKQ1.190910.002; wv) AppleWebKit/537.36 (KHTML, like Gecko) Version/4.0 Chrome/87.0.4280.141 Mobile Safari/537.36'),(93,'49.146.42.127',1,0,6,0,0,40070,5,0,'add/edit Attendance record','User: \" 0 \" > \" 1 \" | Date: \" 1000-01-01 00:00:00.000000 \" > \" 2021-01-13 10:12:21.367750 \" | In: \" 0 \" > \" 2 \" | Out: \" 0 \" > \" 1 \" | Entrance: \"  \" > \" Entrance \" | Device Key: \"  \" > \" 1fbbebbacafeccbf.Redmi Note 7 \" | Status: \" 0 \" > \" 2 \"','2021-01-13 10:12:21.374003','Mozilla/5.0 (Linux; Android 10; Redmi Note 7 Build/QKQ1.190910.002; wv) AppleWebKit/537.36 (KHTML, like Gecko) Version/4.0 Chrome/87.0.4280.141 Mobile Safari/537.36'),(94,'49.146.42.127',1,0,6,0,0,40070,6,0,'add/edit Attendance record','User: \" 0 \" > \" 1 \" | Date: \" 1000-01-01 00:00:00.000000 \" > \" 2021-01-13 10:14:19.185486 \" | In: \" 0 \" > \" 2 \" | Out: \" 0 \" > \" 1 \" | Entrance: \"  \" > \" Entrance \" | Device Key: \"  \" > \" ac5acdbccaaaea50.SM-T295 \" | Status: \" 0 \" > \" 2 \"','2021-01-13 10:14:19.192323','Mozilla/5.0 (Linux; Android 10; SM-T295 Build/QP1A.190711.020; wv) AppleWebKit/537.36 (KHTML, like Gecko) Version/4.0 Chrome/80.0.3987.99 Safari/537.36'),(95,'49.146.42.127',1,0,6,0,0,40070,7,0,'add/edit Attendance record','User: \" 0 \" > \" 1 \" | Date: \" 1000-01-01 00:00:00.000000 \" > \" 2021-01-13 10:15:47.948436 \" | In: \" 0 \" > \" 2 \" | Out: \" 0 \" > \" 1 \" | Entrance: \"  \" > \" Entrance \" | Device Key: \"  \" > \" cec3ddbdce6dae96.RMX2040 \" | Status: \" 0 \" > \" 2 \"','2021-01-13 10:15:47.954967','Mozilla/5.0 (Linux; Android 10; RMX2040 Build/QP1A.190711.020; wv) AppleWebKit/537.36 (KHTML, like Gecko) Version/4.0 Chrome/78.0.3904.96 Mobile Safari/537.36'),(96,'49.146.42.127',1,0,6,0,0,40070,8,0,'add/edit Attendance record','User: \" 0 \" > \" 1 \" | Date: \" 1000-01-01 00:00:00.000000 \" > \" 2021-01-13 10:15:58.101761 \" | In: \" 0 \" > \" 2 \" | Out: \" 0 \" > \" 1 \" | Entrance: \"  \" > \" Entrance \" | Device Key: \"  \" > \" cec3ddbdce6dae96.RMX2040 \" | Status: \" 0 \" > \" 2 \"','2021-01-13 10:15:58.108592','Mozilla/5.0 (Linux; Android 10; RMX2040 Build/QP1A.190711.020; wv) AppleWebKit/537.36 (KHTML, like Gecko) Version/4.0 Chrome/78.0.3904.96 Mobile Safari/537.36'),(97,'49.146.42.127',1,0,6,0,0,40070,9,0,'add/edit Attendance record','User: \" 0 \" > \" 1 \" | Date: \" 1000-01-01 00:00:00.000000 \" > \" 2021-01-13 10:16:35.089700 \" | In: \" 0 \" > \" 2 \" | Out: \" 0 \" > \" 1 \" | Entrance: \"  \" > \" Entrance \" | Device Key: \"  \" > \" cec3ddbdce6dae96.RMX2040 \" | Status: \" 0 \" > \" 2 \"','2021-01-13 10:16:35.096091','Mozilla/5.0 (Linux; Android 10; RMX2040 Build/QP1A.190711.020; wv) AppleWebKit/537.36 (KHTML, like Gecko) Version/4.0 Chrome/78.0.3904.96 Mobile Safari/537.36'),(98,'49.146.42.127',1,0,6,0,0,40070,10,0,'add/edit Attendance record','User: \" 0 \" > \" 1 \" | Date: \" 1000-01-01 00:00:00.000000 \" > \" 2021-01-13 10:17:40.118684 \" | In: \" 0 \" > \" 2 \" | Out: \" 0 \" > \" 1 \" | Entrance: \"  \" > \" Entrance \" | Device Key: \"  \" > \" cec3ddbdce6dae96.RMX2040 \" | Status: \" 0 \" > \" 2 \"','2021-01-13 10:17:40.125506','Mozilla/5.0 (Linux; Android 10; RMX2040 Build/QP1A.190711.020; wv) AppleWebKit/537.36 (KHTML, like Gecko) Version/4.0 Chrome/78.0.3904.96 Mobile Safari/537.36'),(99,'49.146.42.127',1,0,6,0,0,40070,11,0,'add/edit Attendance record','User: \" 0 \" > \" 1 \" | Date: \" 1000-01-01 00:00:00.000000 \" > \" 2021-01-13 10:18:08.525335 \" | In: \" 0 \" > \" 2 \" | Out: \" 0 \" > \" 1 \" | Entrance: \"  \" > \" Entrance \" | Device Key: \"  \" > \" cec3ddbdce6dae96.RMX2040 \" | Status: \" 0 \" > \" 2 \"','2021-01-13 10:18:08.532410','Mozilla/5.0 (Linux; Android 10; RMX2040 Build/QP1A.190711.020; wv) AppleWebKit/537.36 (KHTML, like Gecko) Version/4.0 Chrome/78.0.3904.96 Mobile Safari/537.36'),(100,'49.146.42.127',1,0,6,0,0,40070,12,0,'add/edit Attendance record','User: \" 0 \" > \" 1 \" | Date: \" 1000-01-01 00:00:00.000000 \" > \" 2021-01-13 10:43:29.149519 \" | In: \" 0 \" > \" 2 \" | Out: \" 0 \" > \" 1 \" | Entrance: \"  \" > \" Entrance \" | Device Key: \"  \" > \" ac5acdbccaaaea50.SM-T295 \" | Status: \" 0 \" > \" 2 \"','2021-01-13 10:43:29.158346','Mozilla/5.0 (Linux; Android 10; SM-T295 Build/QP1A.190711.020; wv) AppleWebKit/537.36 (KHTML, like Gecko) Version/4.0 Chrome/80.0.3987.99 Safari/537.36'),(101,'49.146.42.127',1,0,6,0,0,40070,13,0,'add/edit Attendance record','User: \" 0 \" > \" 1 \" | Date: \" 1000-01-01 00:00:00.000000 \" > \" 2021-01-13 10:48:40.071141 \" | In: \" 0 \" > \" 2 \" | Out: \" 0 \" > \" 1 \" | Entrance: \"  \" > \" Entrance \" | Device Key: \"  \" > \" ac5acdbccaaaea50.SM-T295 \" | Status: \" 0 \" > \" 2 \"','2021-01-13 10:48:40.078717','Mozilla/5.0 (Linux; Android 10; SM-T295 Build/QP1A.190711.020; wv) AppleWebKit/537.36 (KHTML, like Gecko) Version/4.0 Chrome/80.0.3987.99 Safari/537.36'),(102,'49.146.42.127',1,0,6,0,0,40070,14,0,'add/edit Attendance record','User: \" 0 \" > \" 1 \" | Date: \" 1000-01-01 00:00:00.000000 \" > \" 2021-01-13 10:48:52.568196 \" | In: \" 0 \" > \" 2 \" | Out: \" 0 \" > \" 1 \" | Entrance: \"  \" > \" Entrance \" | Device Key: \"  \" > \" ac5acdbccaaaea50.SM-T295 \" | Status: \" 0 \" > \" 2 \"','2021-01-13 10:48:52.576392','Mozilla/5.0 (Linux; Android 10; SM-T295 Build/QP1A.190711.020; wv) AppleWebKit/537.36 (KHTML, like Gecko) Version/4.0 Chrome/80.0.3987.99 Safari/537.36'),(103,'49.146.42.127',1,0,6,0,0,40070,15,0,'add/edit Attendance record','User: \" 0 \" > \" 1 \" | Date: \" 1000-01-01 00:00:00.000000 \" > \" 2021-01-13 10:51:17.078042 \" | In: \" 0 \" > \" 2 \" | Out: \" 0 \" > \" 1 \" | Entrance: \"  \" > \" Entrance \" | Device Key: \"  \" > \" ac5acdbccaaaea50.SM-T295 \" | Status: \" 0 \" > \" 2 \"','2021-01-13 10:51:17.318730','Mozilla/5.0 (Linux; Android 10; SM-T295 Build/QP1A.190711.020; wv) AppleWebKit/537.36 (KHTML, like Gecko) Version/4.0 Chrome/80.0.3987.99 Safari/537.36'),(104,'49.146.42.127',1,0,6,0,0,40070,16,0,'add/edit Attendance record','User: \" 0 \" > \" 1 \" | Date: \" 1000-01-01 00:00:00.000000 \" > \" 2021-01-13 10:54:40.520118 \" | In: \" 0 \" > \" 2 \" | Out: \" 0 \" > \" 1 \" | Entrance: \"  \" > \" Entrance \" | Device Key: \"  \" > \" ac5acdbccaaaea50.SM-T295 \" | Status: \" 0 \" > \" 2 \"','2021-01-13 10:54:40.529420','Mozilla/5.0 (Linux; Android 10; SM-T295 Build/QP1A.190711.020; wv) AppleWebKit/537.36 (KHTML, like Gecko) Version/4.0 Chrome/80.0.3987.99 Safari/537.36'),(105,'49.146.42.127',1,0,6,0,0,40070,17,0,'add/edit Attendance record','User: \" 0 \" > \" 1 \" | Date: \" 1000-01-01 00:00:00.000000 \" > \" 2021-01-13 10:54:47.216726 \" | In: \" 0 \" > \" 2 \" | Out: \" 0 \" > \" 1 \" | Entrance: \"  \" > \" Entrance \" | Device Key: \"  \" > \" ac5acdbccaaaea50.SM-T295 \" | Status: \" 0 \" > \" 2 \"','2021-01-13 10:54:47.224079','Mozilla/5.0 (Linux; Android 10; SM-T295 Build/QP1A.190711.020; wv) AppleWebKit/537.36 (KHTML, like Gecko) Version/4.0 Chrome/80.0.3987.99 Safari/537.36'),(106,'49.146.42.127',1,0,6,0,0,40070,18,0,'add/edit Attendance record','User: \" 0 \" > \" 1 \" | Date: \" 1000-01-01 00:00:00.000000 \" > \" 2021-01-13 10:55:12.294850 \" | In: \" 0 \" > \" 2 \" | Out: \" 0 \" > \" 1 \" | Entrance: \"  \" > \" Entrance \" | Device Key: \"  \" > \" ac5acdbccaaaea50.SM-T295 \" | Status: \" 0 \" > \" 2 \"','2021-01-13 10:55:12.304994','Mozilla/5.0 (Linux; Android 10; SM-T295 Build/QP1A.190711.020; wv) AppleWebKit/537.36 (KHTML, like Gecko) Version/4.0 Chrome/80.0.3987.99 Safari/537.36'),(107,'49.146.42.127',1,0,6,0,0,40070,19,0,'add/edit Attendance record','User: \" 0 \" > \" 1 \" | Date: \" 1000-01-01 00:00:00.000000 \" > \" 2021-01-13 10:55:18.557130 \" | In: \" 0 \" > \" 2 \" | Out: \" 0 \" > \" 1 \" | Entrance: \"  \" > \" Entrance \" | Device Key: \"  \" > \" ac5acdbccaaaea50.SM-T295 \" | Status: \" 0 \" > \" 2 \"','2021-01-13 10:55:18.564221','Mozilla/5.0 (Linux; Android 10; SM-T295 Build/QP1A.190711.020; wv) AppleWebKit/537.36 (KHTML, like Gecko) Version/4.0 Chrome/80.0.3987.99 Safari/537.36'),(108,'49.146.42.127',1,0,6,0,0,40070,20,0,'add/edit Attendance record','User: \" 0 \" > \" 1 \" | Date: \" 1000-01-01 00:00:00.000000 \" > \" 2021-01-13 10:55:24.947265 \" | In: \" 0 \" > \" 2 \" | Out: \" 0 \" > \" 1 \" | Entrance: \"  \" > \" Entrance \" | Device Key: \"  \" > \" ac5acdbccaaaea50.SM-T295 \" | Status: \" 0 \" > \" 2 \"','2021-01-13 10:55:24.957702','Mozilla/5.0 (Linux; Android 10; SM-T295 Build/QP1A.190711.020; wv) AppleWebKit/537.36 (KHTML, like Gecko) Version/4.0 Chrome/80.0.3987.99 Safari/537.36'),(109,'49.146.42.127',1,0,6,0,0,40070,21,0,'add/edit Attendance record','User: \" 0 \" > \" 1 \" | Date: \" 1000-01-01 00:00:00.000000 \" > \" 2021-01-13 10:55:33.653929 \" | In: \" 0 \" > \" 2 \" | Out: \" 0 \" > \" 1 \" | Entrance: \"  \" > \" Entrance \" | Device Key: \"  \" > \" ac5acdbccaaaea50.SM-T295 \" | Status: \" 0 \" > \" 2 \"','2021-01-13 10:55:34.437321','Mozilla/5.0 (Linux; Android 10; SM-T295 Build/QP1A.190711.020; wv) AppleWebKit/537.36 (KHTML, like Gecko) Version/4.0 Chrome/80.0.3987.99 Safari/537.36'),(110,'49.146.42.127',1,0,6,0,0,40070,22,0,'add/edit Attendance record','User: \" 0 \" > \" 1 \" | Date: \" 1000-01-01 00:00:00.000000 \" > \" 2021-01-13 10:55:40.891641 \" | In: \" 0 \" > \" 2 \" | Out: \" 0 \" > \" 1 \" | Entrance: \"  \" > \" Entrance \" | Device Key: \"  \" > \" ac5acdbccaaaea50.SM-T295 \" | Status: \" 0 \" > \" 2 \"','2021-01-13 10:55:40.899409','Mozilla/5.0 (Linux; Android 10; SM-T295 Build/QP1A.190711.020; wv) AppleWebKit/537.36 (KHTML, like Gecko) Version/4.0 Chrome/80.0.3987.99 Safari/537.36'),(111,'49.146.42.127',1,0,6,0,0,40070,23,0,'add/edit Attendance record','User: \" 0 \" > \" 1 \" | Date: \" 1000-01-01 00:00:00.000000 \" > \" 2021-01-13 10:55:47.276896 \" | In: \" 0 \" > \" 2 \" | Out: \" 0 \" > \" 1 \" | Entrance: \"  \" > \" Entrance \" | Device Key: \"  \" > \" ac5acdbccaaaea50.SM-T295 \" | Status: \" 0 \" > \" 2 \"','2021-01-13 10:55:49.265341','Mozilla/5.0 (Linux; Android 10; SM-T295 Build/QP1A.190711.020; wv) AppleWebKit/537.36 (KHTML, like Gecko) Version/4.0 Chrome/80.0.3987.99 Safari/537.36'),(112,'49.146.42.127',1,0,6,0,0,40070,24,0,'add/edit Attendance record','User: \" 0 \" > \" 1 \" | Date: \" 1000-01-01 00:00:00.000000 \" > \" 2021-01-13 10:56:01.673791 \" | In: \" 0 \" > \" 2 \" | Out: \" 0 \" > \" 1 \" | Entrance: \"  \" > \" Entrance \" | Device Key: \"  \" > \" ac5acdbccaaaea50.SM-T295 \" | Status: \" 0 \" > \" 2 \"','2021-01-13 10:56:01.681503','Mozilla/5.0 (Linux; Android 10; SM-T295 Build/QP1A.190711.020; wv) AppleWebKit/537.36 (KHTML, like Gecko) Version/4.0 Chrome/80.0.3987.99 Safari/537.36'),(113,'49.146.42.127',1,0,6,0,0,40070,25,0,'add/edit Attendance record','User: \" 0 \" > \" 1 \" | Date: \" 1000-01-01 00:00:00.000000 \" > \" 2021-01-13 10:56:07.930515 \" | In: \" 0 \" > \" 2 \" | Out: \" 0 \" > \" 1 \" | Entrance: \"  \" > \" Entrance \" | Device Key: \"  \" > \" ac5acdbccaaaea50.SM-T295 \" | Status: \" 0 \" > \" 2 \"','2021-01-13 10:56:07.938125','Mozilla/5.0 (Linux; Android 10; SM-T295 Build/QP1A.190711.020; wv) AppleWebKit/537.36 (KHTML, like Gecko) Version/4.0 Chrome/80.0.3987.99 Safari/537.36'),(114,'49.146.42.127',1,0,6,0,0,40070,26,0,'add/edit Attendance record','User: \" 0 \" > \" 1 \" | Date: \" 1000-01-01 00:00:00.000000 \" > \" 2021-01-13 10:56:16.783299 \" | In: \" 0 \" > \" 2 \" | Out: \" 0 \" > \" 1 \" | Entrance: \"  \" > \" Entrance \" | Device Key: \"  \" > \" ac5acdbccaaaea50.SM-T295 \" | Status: \" 0 \" > \" 2 \"','2021-01-13 10:56:16.789950','Mozilla/5.0 (Linux; Android 10; SM-T295 Build/QP1A.190711.020; wv) AppleWebKit/537.36 (KHTML, like Gecko) Version/4.0 Chrome/80.0.3987.99 Safari/537.36'),(115,'49.146.42.127',1,0,6,0,0,40070,27,0,'add/edit Attendance record','User: \" 0 \" > \" 1 \" | Date: \" 1000-01-01 00:00:00.000000 \" > \" 2021-01-13 10:56:58.204772 \" | In: \" 0 \" > \" 2 \" | Out: \" 0 \" > \" 1 \" | Entrance: \"  \" > \" Entrance \" | Device Key: \"  \" > \" ac5acdbccaaaea50.SM-T295 \" | Status: \" 0 \" > \" 2 \"','2021-01-13 10:56:58.211783','Mozilla/5.0 (Linux; Android 10; SM-T295 Build/QP1A.190711.020; wv) AppleWebKit/537.36 (KHTML, like Gecko) Version/4.0 Chrome/80.0.3987.99 Safari/537.36'),(116,'49.146.42.127',1,0,6,0,0,40070,28,0,'add/edit Attendance record','User: \" 0 \" > \" 1 \" | Date: \" 1000-01-01 00:00:00.000000 \" > \" 2021-01-13 10:57:09.504051 \" | In: \" 0 \" > \" 2 \" | Out: \" 0 \" > \" 1 \" | Entrance: \"  \" > \" Entrance \" | Device Key: \"  \" > \" ac5acdbccaaaea50.SM-T295 \" | Status: \" 0 \" > \" 2 \"','2021-01-13 10:57:09.513304','Mozilla/5.0 (Linux; Android 10; SM-T295 Build/QP1A.190711.020; wv) AppleWebKit/537.36 (KHTML, like Gecko) Version/4.0 Chrome/80.0.3987.99 Safari/537.36'),(117,'49.146.42.127',1,0,6,0,0,40070,29,0,'add/edit Attendance record','User: \" 0 \" > \" 1 \" | Date: \" 1000-01-01 00:00:00.000000 \" > \" 2021-01-13 10:57:16.581970 \" | In: \" 0 \" > \" 2 \" | Out: \" 0 \" > \" 1 \" | Entrance: \"  \" > \" Entrance \" | Device Key: \"  \" > \" ac5acdbccaaaea50.SM-T295 \" | Status: \" 0 \" > \" 2 \"','2021-01-13 10:57:16.590495','Mozilla/5.0 (Linux; Android 10; SM-T295 Build/QP1A.190711.020; wv) AppleWebKit/537.36 (KHTML, like Gecko) Version/4.0 Chrome/80.0.3987.99 Safari/537.36'),(118,'49.146.42.127',1,0,6,0,0,40070,30,0,'add/edit Attendance record','User: \" 0 \" > \" 1 \" | Date: \" 1000-01-01 00:00:00.000000 \" > \" 2021-01-13 10:57:24.100958 \" | In: \" 0 \" > \" 2 \" | Out: \" 0 \" > \" 1 \" | Entrance: \"  \" > \" Entrance \" | Device Key: \"  \" > \" ac5acdbccaaaea50.SM-T295 \" | Status: \" 0 \" > \" 2 \"','2021-01-13 10:57:24.107500','Mozilla/5.0 (Linux; Android 10; SM-T295 Build/QP1A.190711.020; wv) AppleWebKit/537.36 (KHTML, like Gecko) Version/4.0 Chrome/80.0.3987.99 Safari/537.36'),(119,'49.146.42.127',1,0,6,0,0,40070,31,0,'add/edit Attendance record','User: \" 0 \" > \" 1 \" | Date: \" 1000-01-01 00:00:00.000000 \" > \" 2021-01-13 10:57:31.256033 \" | In: \" 0 \" > \" 2 \" | Out: \" 0 \" > \" 1 \" | Entrance: \"  \" > \" Entrance \" | Device Key: \"  \" > \" ac5acdbccaaaea50.SM-T295 \" | Status: \" 0 \" > \" 2 \"','2021-01-13 10:57:31.263565','Mozilla/5.0 (Linux; Android 10; SM-T295 Build/QP1A.190711.020; wv) AppleWebKit/537.36 (KHTML, like Gecko) Version/4.0 Chrome/80.0.3987.99 Safari/537.36'),(120,'49.146.42.127',1,0,6,0,0,40070,32,0,'add/edit Attendance record','User: \" 0 \" > \" 1 \" | Date: \" 1000-01-01 00:00:00.000000 \" > \" 2021-01-13 11:02:46.898394 \" | In: \" 0 \" > \" 2 \" | Out: \" 0 \" > \" 1 \" | Entrance: \"  \" > \" Entrance \" | Device Key: \"  \" > \" cec3ddbdce6dae96.RMX2040 \" | Status: \" 0 \" > \" 2 \"','2021-01-13 11:02:46.911163','Mozilla/5.0 (Linux; Android 10; RMX2040 Build/QP1A.190711.020; wv) AppleWebKit/537.36 (KHTML, like Gecko) Version/4.0 Chrome/78.0.3904.96 Mobile Safari/537.36'),(121,'49.146.42.127',1,0,6,0,0,40070,33,0,'add/edit Attendance record','User: \" 0 \" > \" 1 \" | Date: \" 1000-01-01 00:00:00.000000 \" > \" 2021-01-13 11:03:37.417513 \" | In: \" 0 \" > \" 2 \" | Out: \" 0 \" > \" 1 \" | Entrance: \"  \" > \" Entrance \" | Device Key: \"  \" > \" cec3ddbdce6dae96.RMX2040 \" | Status: \" 0 \" > \" 2 \"','2021-01-13 11:03:37.424448','Mozilla/5.0 (Linux; Android 10; RMX2040 Build/QP1A.190711.020; wv) AppleWebKit/537.36 (KHTML, like Gecko) Version/4.0 Chrome/78.0.3904.96 Mobile Safari/537.36'),(122,'49.146.42.127',1,0,6,0,0,40070,34,0,'add/edit Attendance record','User: \" 0 \" > \" 1 \" | Date: \" 1000-01-01 00:00:00.000000 \" > \" 2021-01-13 11:03:44.643093 \" | In: \" 0 \" > \" 2 \" | Out: \" 0 \" > \" 1 \" | Entrance: \"  \" > \" Entrance \" | Device Key: \"  \" > \" cec3ddbdce6dae96.RMX2040 \" | Status: \" 0 \" > \" 2 \"','2021-01-13 11:03:44.650035','Mozilla/5.0 (Linux; Android 10; RMX2040 Build/QP1A.190711.020; wv) AppleWebKit/537.36 (KHTML, like Gecko) Version/4.0 Chrome/78.0.3904.96 Mobile Safari/537.36'),(123,'49.146.42.127',1,0,6,0,0,40070,35,0,'add/edit Attendance record','User: \" 0 \" > \" 1 \" | Date: \" 1000-01-01 00:00:00.000000 \" > \" 2021-01-13 11:04:19.199902 \" | In: \" 0 \" > \" 2 \" | Out: \" 0 \" > \" 1 \" | Entrance: \"  \" > \" Entrance \" | Device Key: \"  \" > \" cec3ddbdce6dae96.RMX2040 \" | Status: \" 0 \" > \" 2 \"','2021-01-13 11:04:19.206054','Mozilla/5.0 (Linux; Android 10; RMX2040 Build/QP1A.190711.020; wv) AppleWebKit/537.36 (KHTML, like Gecko) Version/4.0 Chrome/78.0.3904.96 Mobile Safari/537.36'),(124,'49.146.42.127',1,0,6,0,0,40070,36,0,'add/edit Attendance record','User: \" 0 \" > \" 1 \" | Date: \" 1000-01-01 00:00:00.000000 \" > \" 2021-01-13 11:19:01.362247 \" | In: \" 0 \" > \" 2 \" | Out: \" 0 \" > \" 1 \" | Entrance: \"  \" > \" Entrance \" | Device Key: \"  \" > \" cec3ddbdce6dae96.RMX2040 \" | Status: \" 0 \" > \" 2 \"','2021-01-13 11:19:01.369098','Mozilla/5.0 (Linux; Android 10; RMX2040 Build/QP1A.190711.020; wv) AppleWebKit/537.36 (KHTML, like Gecko) Version/4.0 Chrome/78.0.3904.96 Mobile Safari/537.36'),(125,'49.146.42.127',1,0,6,0,0,40070,37,0,'add/edit Attendance record','User: \" 0 \" > \" 1 \" | Date: \" 1000-01-01 00:00:00.000000 \" > \" 2021-01-13 11:19:38.181228 \" | In: \" 0 \" > \" 2 \" | Out: \" 0 \" > \" 1 \" | Entrance: \"  \" > \" Entrance \" | Device Key: \"  \" > \" cec3ddbdce6dae96.RMX2040 \" | Status: \" 0 \" > \" 2 \"','2021-01-13 11:19:38.188154','Mozilla/5.0 (Linux; Android 10; RMX2040 Build/QP1A.190711.020; wv) AppleWebKit/537.36 (KHTML, like Gecko) Version/4.0 Chrome/78.0.3904.96 Mobile Safari/537.36'),(126,'49.146.42.127',1,0,6,0,0,40070,38,0,'add/edit Attendance record','User: \" 0 \" > \" 1 \" | Date: \" 1000-01-01 00:00:00.000000 \" > \" 2021-01-13 11:20:18.154387 \" | In: \" 0 \" > \" 2 \" | Out: \" 0 \" > \" 1 \" | Entrance: \"  \" > \" Entrance \" | Device Key: \"  \" > \" cec3ddbdce6dae96.RMX2040 \" | Status: \" 0 \" > \" 2 \"','2021-01-13 11:20:18.162834','Mozilla/5.0 (Linux; Android 10; RMX2040 Build/QP1A.190711.020; wv) AppleWebKit/537.36 (KHTML, like Gecko) Version/4.0 Chrome/78.0.3904.96 Mobile Safari/537.36'),(127,'49.146.42.127',1,0,6,0,0,40070,39,0,'add/edit Attendance record','User: \" 0 \" > \" 1 \" | Date: \" 1000-01-01 00:00:00.000000 \" > \" 2021-01-13 11:20:23.894767 \" | In: \" 0 \" > \" 2 \" | Out: \" 0 \" > \" 1 \" | Entrance: \"  \" > \" Entrance \" | Device Key: \"  \" > \" cec3ddbdce6dae96.RMX2040 \" | Status: \" 0 \" > \" 2 \"','2021-01-13 11:20:23.901978','Mozilla/5.0 (Linux; Android 10; RMX2040 Build/QP1A.190711.020; wv) AppleWebKit/537.36 (KHTML, like Gecko) Version/4.0 Chrome/78.0.3904.96 Mobile Safari/537.36'),(128,'49.146.42.127',1,0,6,0,0,40070,40,0,'add/edit Attendance record','User: \" 0 \" > \" 1 \" | Date: \" 1000-01-01 00:00:00.000000 \" > \" 2021-01-13 11:20:31.287906 \" | In: \" 0 \" > \" 2 \" | Out: \" 0 \" > \" 1 \" | Entrance: \"  \" > \" Entrance \" | Device Key: \"  \" > \" cec3ddbdce6dae96.RMX2040 \" | Status: \" 0 \" > \" 2 \"','2021-01-13 11:20:31.294505','Mozilla/5.0 (Linux; Android 10; RMX2040 Build/QP1A.190711.020; wv) AppleWebKit/537.36 (KHTML, like Gecko) Version/4.0 Chrome/78.0.3904.96 Mobile Safari/537.36'),(129,'49.146.42.127',1,0,6,0,0,40070,41,0,'add/edit Attendance record','User: \" 0 \" > \" 1 \" | Date: \" 1000-01-01 00:00:00.000000 \" > \" 2021-01-13 11:20:47.322135 \" | In: \" 0 \" > \" 2 \" | Out: \" 0 \" > \" 1 \" | Entrance: \"  \" > \" Entrance \" | Device Key: \"  \" > \" cec3ddbdce6dae96.RMX2040 \" | Status: \" 0 \" > \" 2 \"','2021-01-13 11:20:48.357097','Mozilla/5.0 (Linux; Android 10; RMX2040 Build/QP1A.190711.020; wv) AppleWebKit/537.36 (KHTML, like Gecko) Version/4.0 Chrome/78.0.3904.96 Mobile Safari/537.36'),(130,'49.146.42.127',1,0,6,0,0,40070,42,0,'add/edit Attendance record','User: \" 0 \" > \" 1 \" | Date: \" 1000-01-01 00:00:00.000000 \" > \" 2021-01-13 11:20:58.933244 \" | In: \" 0 \" > \" 2 \" | Out: \" 0 \" > \" 1 \" | Entrance: \"  \" > \" Entrance \" | Device Key: \"  \" > \" cec3ddbdce6dae96.RMX2040 \" | Status: \" 0 \" > \" 2 \"','2021-01-13 11:20:58.940016','Mozilla/5.0 (Linux; Android 10; RMX2040 Build/QP1A.190711.020; wv) AppleWebKit/537.36 (KHTML, like Gecko) Version/4.0 Chrome/78.0.3904.96 Mobile Safari/537.36'),(131,'49.146.42.127',1,0,6,0,0,40070,43,0,'add/edit Attendance record','User: \" 0 \" > \" 1 \" | Date: \" 1000-01-01 00:00:00.000000 \" > \" 2021-01-13 11:21:07.323220 \" | In: \" 0 \" > \" 2 \" | Out: \" 0 \" > \" 1 \" | Entrance: \"  \" > \" Entrance \" | Device Key: \"  \" > \" cec3ddbdce6dae96.RMX2040 \" | Status: \" 0 \" > \" 2 \"','2021-01-13 11:21:07.329723','Mozilla/5.0 (Linux; Android 10; RMX2040 Build/QP1A.190711.020; wv) AppleWebKit/537.36 (KHTML, like Gecko) Version/4.0 Chrome/78.0.3904.96 Mobile Safari/537.36'),(132,'49.146.42.127',1,0,6,0,0,40070,44,0,'add/edit Attendance record','User: \" 0 \" > \" 1 \" | Date: \" 1000-01-01 00:00:00.000000 \" > \" 2021-01-13 11:21:15.053372 \" | In: \" 0 \" > \" 2 \" | Out: \" 0 \" > \" 1 \" | Entrance: \"  \" > \" Entrance \" | Device Key: \"  \" > \" cec3ddbdce6dae96.RMX2040 \" | Status: \" 0 \" > \" 2 \"','2021-01-13 11:21:15.061402','Mozilla/5.0 (Linux; Android 10; RMX2040 Build/QP1A.190711.020; wv) AppleWebKit/537.36 (KHTML, like Gecko) Version/4.0 Chrome/78.0.3904.96 Mobile Safari/537.36'),(133,'49.146.42.127',1,0,6,0,0,40070,45,0,'add/edit Attendance record','User: \" 0 \" > \" 1 \" | Date: \" 1000-01-01 00:00:00.000000 \" > \" 2021-01-13 11:21:26.428018 \" | In: \" 0 \" > \" 2 \" | Out: \" 0 \" > \" 1 \" | Entrance: \"  \" > \" Entrance \" | Device Key: \"  \" > \" cec3ddbdce6dae96.RMX2040 \" | Status: \" 0 \" > \" 2 \"','2021-01-13 11:21:26.435889','Mozilla/5.0 (Linux; Android 10; RMX2040 Build/QP1A.190711.020; wv) AppleWebKit/537.36 (KHTML, like Gecko) Version/4.0 Chrome/78.0.3904.96 Mobile Safari/537.36'),(134,'49.146.42.127',1,0,6,0,0,40070,46,0,'add/edit Attendance record','User: \" 0 \" > \" 1 \" | Date: \" 1000-01-01 00:00:00.000000 \" > \" 2021-01-13 11:21:34.564027 \" | In: \" 0 \" > \" 2 \" | Out: \" 0 \" > \" 1 \" | Entrance: \"  \" > \" Entrance \" | Device Key: \"  \" > \" cec3ddbdce6dae96.RMX2040 \" | Status: \" 0 \" > \" 2 \"','2021-01-13 11:21:34.570989','Mozilla/5.0 (Linux; Android 10; RMX2040 Build/QP1A.190711.020; wv) AppleWebKit/537.36 (KHTML, like Gecko) Version/4.0 Chrome/78.0.3904.96 Mobile Safari/537.36'),(135,'49.146.42.127',1,0,6,0,0,40070,47,0,'add/edit Attendance record','User: \" 0 \" > \" 1 \" | Date: \" 1000-01-01 00:00:00.000000 \" > \" 2021-01-13 11:23:14.299294 \" | In: \" 0 \" > \" 2 \" | Out: \" 0 \" > \" 1 \" | Entrance: \"  \" > \" Entrance \" | Device Key: \"  \" > \" cec3ddbdce6dae96.RMX2040 \" | Status: \" 0 \" > \" 2 \"','2021-01-13 11:23:14.305928','Mozilla/5.0 (Linux; Android 10; RMX2040 Build/QP1A.190711.020; wv) AppleWebKit/537.36 (KHTML, like Gecko) Version/4.0 Chrome/78.0.3904.96 Mobile Safari/537.36'),(136,'49.146.42.127',1,0,6,0,0,40070,48,0,'add/edit Attendance record','User: \" 0 \" > \" 1 \" | Date: \" 1000-01-01 00:00:00.000000 \" > \" 2021-01-13 11:23:25.356922 \" | In: \" 0 \" > \" 2 \" | Out: \" 0 \" > \" 1 \" | Entrance: \"  \" > \" Entrance \" | Device Key: \"  \" > \" cec3ddbdce6dae96.RMX2040 \" | Status: \" 0 \" > \" 2 \"','2021-01-13 11:23:25.363425','Mozilla/5.0 (Linux; Android 10; RMX2040 Build/QP1A.190711.020; wv) AppleWebKit/537.36 (KHTML, like Gecko) Version/4.0 Chrome/78.0.3904.96 Mobile Safari/537.36'),(137,'49.146.42.127',1,0,6,0,0,40070,49,0,'add/edit Attendance record','User: \" 0 \" > \" 1 \" | Date: \" 1000-01-01 00:00:00.000000 \" > \" 2021-01-13 11:24:31.819277 \" | In: \" 0 \" > \" 2 \" | Out: \" 0 \" > \" 1 \" | Entrance: \"  \" > \" Entrance \" | Device Key: \"  \" > \" cec3ddbdce6dae96.RMX2040 \" | Status: \" 0 \" > \" 2 \"','2021-01-13 11:24:31.826773','Mozilla/5.0 (Linux; Android 10; RMX2040 Build/QP1A.190711.020; wv) AppleWebKit/537.36 (KHTML, like Gecko) Version/4.0 Chrome/78.0.3904.96 Mobile Safari/537.36'),(138,'49.146.42.127',1,0,6,0,0,40070,50,0,'add/edit Attendance record','User: \" 0 \" > \" 1 \" | Date: \" 1000-01-01 00:00:00.000000 \" > \" 2021-01-13 11:24:43.798367 \" | In: \" 0 \" > \" 2 \" | Out: \" 0 \" > \" 1 \" | Entrance: \"  \" > \" Entrance \" | Device Key: \"  \" > \" cec3ddbdce6dae96.RMX2040 \" | Status: \" 0 \" > \" 2 \"','2021-01-13 11:24:43.804862','Mozilla/5.0 (Linux; Android 10; RMX2040 Build/QP1A.190711.020; wv) AppleWebKit/537.36 (KHTML, like Gecko) Version/4.0 Chrome/78.0.3904.96 Mobile Safari/537.36'),(139,'49.146.42.127',1,0,6,0,0,40070,51,0,'add/edit Attendance record','User: \" 0 \" > \" 1 \" | Date: \" 1000-01-01 00:00:00.000000 \" > \" 2021-01-13 11:25:20.238289 \" | In: \" 0 \" > \" 2 \" | Out: \" 0 \" > \" 1 \" | Entrance: \"  \" > \" Entrance \" | Device Key: \"  \" > \" cec3ddbdce6dae96.RMX2040 \" | Status: \" 0 \" > \" 2 \"','2021-01-13 11:25:20.245407','Mozilla/5.0 (Linux; Android 10; RMX2040 Build/QP1A.190711.020; wv) AppleWebKit/537.36 (KHTML, like Gecko) Version/4.0 Chrome/78.0.3904.96 Mobile Safari/537.36'),(140,'49.146.42.127',1,0,6,0,0,40070,52,0,'add/edit Attendance record','User: \" 0 \" > \" 1 \" | Date: \" 1000-01-01 00:00:00.000000 \" > \" 2021-01-13 11:31:07.568224 \" | In: \" 0 \" > \" 2 \" | Out: \" 0 \" > \" 1 \" | Entrance: \"  \" > \" Entrance \" | Device Key: \"  \" > \" cec3ddbdce6dae96.RMX2040 \" | Status: \" 0 \" > \" 2 \"','2021-01-13 11:31:07.575582','Mozilla/5.0 (Linux; Android 10; RMX2040 Build/QP1A.190711.020; wv) AppleWebKit/537.36 (KHTML, like Gecko) Version/4.0 Chrome/78.0.3904.96 Mobile Safari/537.36'),(141,'49.146.42.127',1,0,6,0,0,21030,2,0,'add/edit Section record','Department: \" 0 \" > \" 1 \" | Description: \"  \" > \" Technical Support \" | Status: \" 0 \" > \" 2 \"','2021-01-13 11:58:48.781846','Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/87.0.4280.141 Safari/537.36'),(142,'49.146.42.127',1,0,3,0,0,40010,4,0,'add/edit Registration record','Department: \" 0 \" > \" 1 \" | Section: \" 0 \" > \" 2 \" | First name: \"  \" > \" Quinn Rodney \" | Middle name: \"  \" > \" Clavecilla \" | Last name: \"  \" > \" Daquil \" | Gender: \" 0 \" > \" 1 \" | Notification Phone Number: \"  \" > \" +639954575845 \" | Emergency Contact Person: \"  \" > \" Quinn Rodney Clavecilla Daquil \" | Emergency Contact Numbher: \"  \" > \" +639982077676 \" | Status: \" 0 \" > \" 2 \"','2021-01-13 13:13:52.879130','Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/87.0.4280.141 Safari/537.36'),(143,'49.146.42.127',1,0,6,0,0,40010,4,0,'add/edit Registration record','User: \" 0 \" > \" -9223372036854700032 \" | Gender: \" 1 \" > \" 2 \"','2021-01-13 13:21:15.705405','Mozilla/5.0 (Windows NT 6.3; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/87.0.4280.141 Safari/537.36'),(144,'49.146.42.127',1,0,6,0,0,40010,4,0,'add/edit Registration record','First name: \" Quinn Rodney \" > \" Queen Rodney \"','2021-01-13 13:21:56.762799','Mozilla/5.0 (Windows NT 6.3; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/87.0.4280.141 Safari/537.36'),(145,'49.146.42.127',1,0,6,0,0,40070,53,0,'add/edit Attendance record','User: \" 0 \" > \" 1 \" | Date: \" 1000-01-01 00:00:00.000000 \" > \" 2021-01-13 13:28:11.590191 \" | In: \" 0 \" > \" 2 \" | Out: \" 0 \" > \" 1 \" | Entrance: \"  \" > \" Entrance \" | Device Key: \"  \" > \" cec3ddbdce6dae96.RMX2040 \" | Status: \" 0 \" > \" 2 \"','2021-01-13 13:28:11.596847','Mozilla/5.0 (Linux; Android 10; RMX2040 Build/QP1A.190711.020; wv) AppleWebKit/537.36 (KHTML, like Gecko) Version/4.0 Chrome/78.0.3904.96 Mobile Safari/537.36'),(146,'49.146.42.127',1,0,6,0,0,40070,54,0,'add/edit Attendance record','User: \" 0 \" > \" 1 \" | Date: \" 1000-01-01 00:00:00.000000 \" > \" 2021-01-13 13:28:34.839799 \" | In: \" 0 \" > \" 2 \" | Out: \" 0 \" > \" 1 \" | Entrance: \"  \" > \" Entrance \" | Device Key: \"  \" > \" cec3ddbdce6dae96.RMX2040 \" | Status: \" 0 \" > \" 2 \"','2021-01-13 13:28:34.848274','Mozilla/5.0 (Linux; Android 10; RMX2040 Build/QP1A.190711.020; wv) AppleWebKit/537.36 (KHTML, like Gecko) Version/4.0 Chrome/78.0.3904.96 Mobile Safari/537.36'),(147,'49.146.42.127',1,0,6,0,0,40070,55,0,'add/edit Attendance record','User: \" 0 \" > \" 1 \" | Date: \" 1000-01-01 00:00:00.000000 \" > \" 2021-01-13 13:28:45.457309 \" | In: \" 0 \" > \" 2 \" | Out: \" 0 \" > \" 1 \" | Entrance: \"  \" > \" Entrance \" | Device Key: \"  \" > \" cec3ddbdce6dae96.RMX2040 \" | Status: \" 0 \" > \" 2 \"','2021-01-13 13:28:45.465049','Mozilla/5.0 (Linux; Android 10; RMX2040 Build/QP1A.190711.020; wv) AppleWebKit/537.36 (KHTML, like Gecko) Version/4.0 Chrome/78.0.3904.96 Mobile Safari/537.36'),(148,'49.146.42.127',1,0,6,0,0,40070,56,0,'add/edit Attendance record','User: \" 0 \" > \" 1 \" | Date: \" 1000-01-01 00:00:00.000000 \" > \" 2021-01-13 13:28:52.062835 \" | In: \" 0 \" > \" 2 \" | Out: \" 0 \" > \" 1 \" | Entrance: \"  \" > \" Entrance \" | Device Key: \"  \" > \" cec3ddbdce6dae96.RMX2040 \" | Status: \" 0 \" > \" 2 \"','2021-01-13 13:28:52.072043','Mozilla/5.0 (Linux; Android 10; RMX2040 Build/QP1A.190711.020; wv) AppleWebKit/537.36 (KHTML, like Gecko) Version/4.0 Chrome/78.0.3904.96 Mobile Safari/537.36'),(149,'49.146.42.127',1,0,6,0,0,40070,57,0,'add/edit Attendance record','User: \" 0 \" > \" 1 \" | Date: \" 1000-01-01 00:00:00.000000 \" > \" 2021-01-13 13:29:10.481348 \" | In: \" 0 \" > \" 2 \" | Out: \" 0 \" > \" 1 \" | Entrance: \"  \" > \" Entrance \" | Device Key: \"  \" > \" cec3ddbdce6dae96.RMX2040 \" | Status: \" 0 \" > \" 2 \"','2021-01-13 13:29:10.488064','Mozilla/5.0 (Linux; Android 10; RMX2040 Build/QP1A.190711.020; wv) AppleWebKit/537.36 (KHTML, like Gecko) Version/4.0 Chrome/78.0.3904.96 Mobile Safari/537.36'),(150,'49.146.42.127',1,0,6,0,0,40070,58,0,'add/edit Attendance record','User: \" 0 \" > \" 1 \" | Date: \" 1000-01-01 00:00:00.000000 \" > \" 2021-01-13 13:29:26.859318 \" | In: \" 0 \" > \" 2 \" | Out: \" 0 \" > \" 1 \" | Entrance: \"  \" > \" Entrance \" | Device Key: \"  \" > \" cec3ddbdce6dae96.RMX2040 \" | Status: \" 0 \" > \" 2 \"','2021-01-13 13:29:26.865865','Mozilla/5.0 (Linux; Android 10; RMX2040 Build/QP1A.190711.020; wv) AppleWebKit/537.36 (KHTML, like Gecko) Version/4.0 Chrome/78.0.3904.96 Mobile Safari/537.36'),(152,'49.146.42.127',1,0,6,0,0,40070,60,0,'add/edit Attendance record','User: \" 0 \" > \" 1 \" | Date: \" 1000-01-01 00:00:00.000000 \" > \" 2021-01-13 14:46:03.914961 \" | In: \" 0 \" > \" 2 \" | Out: \" 0 \" > \" 1 \" | Entrance: \"  \" > \" Entrance \" | Device Key: \"  \" > \" DEVICE_UNIQUE_ID.DEVICE_MODEL \" | Status: \" 0 \" > \" 2 \"','2021-01-13 14:46:03.921536','Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/87.0.4280.141 Safari/537.36'),(153,'49.146.42.127',1,0,6,0,0,40070,61,0,'add/edit Attendance record','User: \" 0 \" > \" 1 \" | Date: \" 1000-01-01 00:00:00.000000 \" > \" 2021-01-13 14:46:47.529842 \" | In: \" 0 \" > \" 2 \" | Out: \" 0 \" > \" 1 \" | Entrance: \"  \" > \" Entrance \" | Device Key: \"  \" > \" DEVICE_UNIQUE_ID.DEVICE_MODEL \" | Status: \" 0 \" > \" 2 \"','2021-01-13 14:46:47.538762','Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/87.0.4280.141 Safari/537.36'),(154,'49.146.42.127',1,0,6,0,0,40070,62,0,'add/edit Attendance record','User: \" 0 \" > \" 1 \" | Date: \" 1000-01-01 00:00:00.000000 \" > \" 2021-01-13 14:47:36.824782 \" | In: \" 0 \" > \" 2 \" | Out: \" 0 \" > \" 1 \" | Entrance: \"  \" > \" Entrance \" | Device Key: \"  \" > \" DEVICE_UNIQUE_ID.DEVICE_MODEL \" | Status: \" 0 \" > \" 2 \"','2021-01-13 14:47:36.831664','Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/87.0.4280.141 Safari/537.36'),(155,'49.146.42.127',1,0,6,0,0,40070,63,0,'add/edit Attendance record','User: \" 0 \" > \" 1 \" | Date: \" 1000-01-01 00:00:00.000000 \" > \" 2021-01-13 14:51:51.941252 \" | In: \" 0 \" > \" 2 \" | Out: \" 0 \" > \" 1 \" | Entrance: \"  \" > \" Entrance \" | Device Key: \"  \" > \" DEVICE_UNIQUE_ID.DEVICE_MODEL \" | Status: \" 0 \" > \" 2 \"','2021-01-13 14:51:51.947981','Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/87.0.4280.141 Safari/537.36'),(156,'49.146.42.127',1,0,6,0,0,40070,64,0,'add/edit Attendance record','User: \" 0 \" > \" 1 \" | Date: \" 1000-01-01 00:00:00.000000 \" > \" 2021-01-13 15:04:23.532559 \" | In: \" 0 \" > \" 2 \" | Out: \" 0 \" > \" 1 \" | Entrance: \"  \" > \" Entrance \" | Device Key: \"  \" > \" DEVICE_UNIQUE_ID.DEVICE_MODEL \" | Status: \" 0 \" > \" 2 \"','2021-01-13 15:04:23.539156','Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/87.0.4280.141 Safari/537.36'),(157,'49.146.42.127',1,0,6,0,0,40070,65,0,'add/edit Attendance record','User: \" 0 \" > \" 1 \" | Date: \" 1000-01-01 00:00:00.000000 \" > \" 2021-01-13 15:08:17.860642 \" | In: \" 0 \" > \" 2 \" | Out: \" 0 \" > \" 1 \" | Entrance: \"  \" > \" Entrance \" | Device Key: \"  \" > \" DEVICE_UNIQUE_ID.DEVICE_MODEL \" | Status: \" 0 \" > \" 2 \"','2021-01-13 15:08:17.867712','Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/87.0.4280.141 Safari/537.36'),(158,'49.146.42.127',1,0,6,0,0,40070,66,0,'add/edit Attendance record','User: \" 0 \" > \" 1 \" | Date: \" 1000-01-01 00:00:00.000000 \" > \" 2021-01-13 15:11:55.041242 \" | In: \" 0 \" > \" 2 \" | Out: \" 0 \" > \" 1 \" | Entrance: \"  \" > \" Entrance \" | Device Key: \"  \" > \" cec3ddbdce6dae96.RMX2040 \" | Status: \" 0 \" > \" 2 \"','2021-01-13 15:11:55.047946','Mozilla/5.0 (Linux; Android 10; RMX2040 Build/QP1A.190711.020; wv) AppleWebKit/537.36 (KHTML, like Gecko) Version/4.0 Chrome/78.0.3904.96 Mobile Safari/537.36'),(159,'49.146.42.127',1,0,6,0,0,40070,67,0,'add/edit Attendance record','User: \" 0 \" > \" 1 \" | Date: \" 1000-01-01 00:00:00.000000 \" > \" 2021-01-13 15:13:32.563429 \" | In: \" 0 \" > \" 2 \" | Out: \" 0 \" > \" 1 \" | Entrance: \"  \" > \" Entrance \" | Device Key: \"  \" > \" cec3ddbdce6dae96.RMX2040 \" | Status: \" 0 \" > \" 2 \"','2021-01-13 15:13:32.570078','Mozilla/5.0 (Linux; Android 10; RMX2040 Build/QP1A.190711.020; wv) AppleWebKit/537.36 (KHTML, like Gecko) Version/4.0 Chrome/78.0.3904.96 Mobile Safari/537.36'),(160,'49.146.42.127',1,0,6,0,0,40070,68,0,'add/edit Attendance record','User: \" 0 \" > \" 1 \" | Date: \" 1000-01-01 00:00:00.000000 \" > \" 2021-01-13 15:14:55.686769 \" | In: \" 0 \" > \" 2 \" | Out: \" 0 \" > \" 1 \" | Entrance: \"  \" > \" Entrance \" | Device Key: \"  \" > \" cec3ddbdce6dae96.RMX2040 \" | Status: \" 0 \" > \" 2 \"','2021-01-13 15:14:55.693416','Mozilla/5.0 (Linux; Android 10; RMX2040 Build/QP1A.190711.020; wv) AppleWebKit/537.36 (KHTML, like Gecko) Version/4.0 Chrome/78.0.3904.96 Mobile Safari/537.36'),(161,'49.146.42.127',1,0,6,0,0,40070,69,0,'add/edit Attendance record','User: \" 0 \" > \" 1 \" | Date: \" 1000-01-01 00:00:00.000000 \" > \" 2021-01-13 15:15:15.206798 \" | In: \" 0 \" > \" 2 \" | Out: \" 0 \" > \" 1 \" | Entrance: \"  \" > \" Entrance \" | Device Key: \"  \" > \" cec3ddbdce6dae96.RMX2040 \" | Status: \" 0 \" > \" 2 \"','2021-01-13 15:15:15.213089','Mozilla/5.0 (Linux; Android 10; RMX2040 Build/QP1A.190711.020; wv) AppleWebKit/537.36 (KHTML, like Gecko) Version/4.0 Chrome/78.0.3904.96 Mobile Safari/537.36'),(162,'49.146.42.127',1,0,6,0,0,40070,70,0,'add/edit Attendance record','User: \" 0 \" > \" 1 \" | Date: \" 1000-01-01 00:00:00.000000 \" > \" 2021-01-13 15:30:32.740140 \" | In: \" 0 \" > \" 2 \" | Out: \" 0 \" > \" 1 \" | Entrance: \"  \" > \" Entrance \" | Device Key: \"  \" > \" cec3ddbdce6dae96.RMX2040 \" | Status: \" 0 \" > \" 2 \"','2021-01-13 15:30:32.747352','Mozilla/5.0 (Linux; Android 10; RMX2040 Build/QP1A.190711.020; wv) AppleWebKit/537.36 (KHTML, like Gecko) Version/4.0 Chrome/78.0.3904.96 Mobile Safari/537.36'),(163,'49.146.42.127',1,0,6,0,0,40070,71,0,'add/edit Attendance record','User: \" 0 \" > \" 1 \" | Date: \" 1000-01-01 00:00:00.000000 \" > \" 2021-01-13 15:37:37.318967 \" | In: \" 0 \" > \" 2 \" | Out: \" 0 \" > \" 1 \" | Entrance: \"  \" > \" Entrance \" | Device Key: \"  \" > \" cec3ddbdce6dae96.RMX2040 \" | Status: \" 0 \" > \" 2 \"','2021-01-13 15:37:37.325329','Mozilla/5.0 (Linux; Android 10; RMX2040 Build/QP1A.190711.020; wv) AppleWebKit/537.36 (KHTML, like Gecko) Version/4.0 Chrome/78.0.3904.96 Mobile Safari/537.36'),(164,'49.146.42.127',1,0,6,0,0,40070,72,0,'add/edit Attendance record','User: \" 0 \" > \" 1 \" | Date: \" 1000-01-01 00:00:00.000000 \" > \" 2021-01-13 15:48:08.771526 \" | In: \" 0 \" > \" 2 \" | Out: \" 0 \" > \" 1 \" | Entrance: \"  \" > \" Entrance \" | Device Key: \"  \" > \" cec3ddbdce6dae96.RMX2040 \" | Status: \" 0 \" > \" 2 \"','2021-01-13 15:48:08.778086','Mozilla/5.0 (Linux; Android 10; RMX2040 Build/QP1A.190711.020; wv) AppleWebKit/537.36 (KHTML, like Gecko) Version/4.0 Chrome/78.0.3904.96 Mobile Safari/537.36'),(165,'49.146.42.127',1,0,6,0,0,40070,73,0,'add/edit Attendance record','User: \" 0 \" > \" 1 \" | Date: \" 1000-01-01 00:00:00.000000 \" > \" 2021-01-13 15:48:30.935088 \" | In: \" 0 \" > \" 2 \" | Out: \" 0 \" > \" 1 \" | Entrance: \"  \" > \" Entrance \" | Device Key: \"  \" > \" cec3ddbdce6dae96.RMX2040 \" | Status: \" 0 \" > \" 2 \"','2021-01-13 15:48:30.941830','Mozilla/5.0 (Linux; Android 10; RMX2040 Build/QP1A.190711.020; wv) AppleWebKit/537.36 (KHTML, like Gecko) Version/4.0 Chrome/78.0.3904.96 Mobile Safari/537.36'),(166,'49.146.42.127',1,0,6,0,0,40070,74,0,'add/edit Attendance record','User: \" 0 \" > \" 1 \" | Date: \" 1000-01-01 00:00:00.000000 \" > \" 2021-01-13 15:53:35.894995 \" | In: \" 0 \" > \" 2 \" | Out: \" 0 \" > \" 1 \" | Entrance: \"  \" > \" Entrance \" | Device Key: \"  \" > \" cec3ddbdce6dae96.RMX2040 \" | Status: \" 0 \" > \" 2 \"','2021-01-13 15:53:35.902559','Mozilla/5.0 (Linux; Android 10; RMX2040 Build/QP1A.190711.020; wv) AppleWebKit/537.36 (KHTML, like Gecko) Version/4.0 Chrome/78.0.3904.96 Mobile Safari/537.36'),(167,'49.146.42.127',1,0,6,0,0,40070,75,0,'add/edit Attendance record','User: \" 0 \" > \" 1 \" | Date: \" 1000-01-01 00:00:00.000000 \" > \" 2021-01-13 15:54:07.093086 \" | In: \" 0 \" > \" 2 \" | Out: \" 0 \" > \" 1 \" | Entrance: \"  \" > \" Entrance \" | Device Key: \"  \" > \" cec3ddbdce6dae96.RMX2040 \" | Status: \" 0 \" > \" 2 \"','2021-01-13 15:54:07.101701','Mozilla/5.0 (Linux; Android 10; RMX2040 Build/QP1A.190711.020; wv) AppleWebKit/537.36 (KHTML, like Gecko) Version/4.0 Chrome/78.0.3904.96 Mobile Safari/537.36'),(168,'49.146.42.127',1,0,6,0,0,40070,76,0,'add/edit Attendance record','User: \" 0 \" > \" 1 \" | Date: \" 1000-01-01 00:00:00.000000 \" > \" 2021-01-13 15:54:27.504498 \" | In: \" 0 \" > \" 2 \" | Out: \" 0 \" > \" 1 \" | Entrance: \"  \" > \" Entrance \" | Device Key: \"  \" > \" cec3ddbdce6dae96.RMX2040 \" | Status: \" 0 \" > \" 2 \"','2021-01-13 15:54:27.512195','Mozilla/5.0 (Linux; Android 10; RMX2040 Build/QP1A.190711.020; wv) AppleWebKit/537.36 (KHTML, like Gecko) Version/4.0 Chrome/78.0.3904.96 Mobile Safari/537.36'),(169,'49.146.42.127',1,0,6,0,0,40070,77,0,'add/edit Attendance record','User: \" 0 \" > \" 1 \" | Date: \" 1000-01-01 00:00:00.000000 \" > \" 2021-01-13 15:54:34.125908 \" | In: \" 0 \" > \" 2 \" | Out: \" 0 \" > \" 1 \" | Entrance: \"  \" > \" Entrance \" | Device Key: \"  \" > \" cec3ddbdce6dae96.RMX2040 \" | Status: \" 0 \" > \" 2 \"','2021-01-13 15:54:34.134164','Mozilla/5.0 (Linux; Android 10; RMX2040 Build/QP1A.190711.020; wv) AppleWebKit/537.36 (KHTML, like Gecko) Version/4.0 Chrome/78.0.3904.96 Mobile Safari/537.36'),(170,'49.146.42.127',1,0,6,0,0,40070,78,0,'add/edit Attendance record','User: \" 0 \" > \" 1 \" | Date: \" 1000-01-01 00:00:00.000000 \" > \" 2021-01-13 15:54:53.494644 \" | In: \" 0 \" > \" 2 \" | Out: \" 0 \" > \" 1 \" | Entrance: \"  \" > \" Entrance \" | Device Key: \"  \" > \" cec3ddbdce6dae96.RMX2040 \" | Status: \" 0 \" > \" 2 \"','2021-01-13 15:54:53.501475','Mozilla/5.0 (Linux; Android 10; RMX2040 Build/QP1A.190711.020; wv) AppleWebKit/537.36 (KHTML, like Gecko) Version/4.0 Chrome/78.0.3904.96 Mobile Safari/537.36'),(171,'49.146.42.127',1,0,6,0,0,40070,79,0,'add/edit Attendance record','User: \" 0 \" > \" 1 \" | Date: \" 1000-01-01 00:00:00.000000 \" > \" 2021-01-13 15:55:04.109550 \" | In: \" 0 \" > \" 2 \" | Out: \" 0 \" > \" 1 \" | Entrance: \"  \" > \" Entrance \" | Device Key: \"  \" > \" cec3ddbdce6dae96.RMX2040 \" | Status: \" 0 \" > \" 2 \"','2021-01-13 15:55:04.116839','Mozilla/5.0 (Linux; Android 10; RMX2040 Build/QP1A.190711.020; wv) AppleWebKit/537.36 (KHTML, like Gecko) Version/4.0 Chrome/78.0.3904.96 Mobile Safari/537.36'),(172,'49.146.42.127',1,0,6,0,0,40070,80,0,'add/edit Attendance record','User: \" 0 \" > \" 1 \" | Date: \" 1000-01-01 00:00:00.000000 \" > \" 2021-01-13 15:55:14.606563 \" | In: \" 0 \" > \" 2 \" | Out: \" 0 \" > \" 1 \" | Entrance: \"  \" > \" Entrance \" | Device Key: \"  \" > \" cec3ddbdce6dae96.RMX2040 \" | Status: \" 0 \" > \" 2 \"','2021-01-13 15:55:14.613263','Mozilla/5.0 (Linux; Android 10; RMX2040 Build/QP1A.190711.020; wv) AppleWebKit/537.36 (KHTML, like Gecko) Version/4.0 Chrome/78.0.3904.96 Mobile Safari/537.36'),(173,'49.146.42.127',1,0,6,0,0,40070,81,0,'add/edit Attendance record','User: \" 0 \" > \" 1 \" | Date: \" 1000-01-01 00:00:00.000000 \" > \" 2021-01-13 15:58:20.758431 \" | In: \" 0 \" > \" 2 \" | Out: \" 0 \" > \" 1 \" | Entrance: \"  \" > \" Entrance \" | Device Key: \"  \" > \" cec3ddbdce6dae96.RMX2040 \" | Status: \" 0 \" > \" 2 \"','2021-01-13 15:58:20.765345','Mozilla/5.0 (Linux; Android 10; RMX2040 Build/QP1A.190711.020; wv) AppleWebKit/537.36 (KHTML, like Gecko) Version/4.0 Chrome/78.0.3904.96 Mobile Safari/537.36'),(174,'49.146.42.127',1,0,6,0,0,40070,82,0,'add/edit Attendance record','User: \" 0 \" > \" 1 \" | Date: \" 1000-01-01 00:00:00.000000 \" > \" 2021-01-13 15:58:29.111590 \" | In: \" 0 \" > \" 2 \" | Out: \" 0 \" > \" 1 \" | Entrance: \"  \" > \" Entrance \" | Device Key: \"  \" > \" cec3ddbdce6dae96.RMX2040 \" | Status: \" 0 \" > \" 2 \"','2021-01-13 15:58:29.118286','Mozilla/5.0 (Linux; Android 10; RMX2040 Build/QP1A.190711.020; wv) AppleWebKit/537.36 (KHTML, like Gecko) Version/4.0 Chrome/78.0.3904.96 Mobile Safari/537.36'),(175,'49.146.42.127',1,0,6,0,0,40070,83,0,'add/edit Attendance record','User: \" 0 \" > \" 1 \" | Date: \" 1000-01-01 00:00:00.000000 \" > \" 2021-01-13 15:59:59.504803 \" | In: \" 0 \" > \" 2 \" | Out: \" 0 \" > \" 1 \" | Entrance: \"  \" > \" Entrance \" | Device Key: \"  \" > \" DEVICE_UNIQUE_ID.DEVICE_MODEL \" | Status: \" 0 \" > \" 2 \"','2021-01-13 15:59:59.511391','Mozilla/5.0 (Linux; Android 10; RMX2040 Build/QP1A.190711.020; wv) AppleWebKit/537.36 (KHTML, like Gecko) Version/4.0 Chrome/78.0.3904.96 Mobile Safari/537.36'),(176,'49.146.42.127',1,0,6,0,0,40070,84,0,'add/edit Attendance record','User: \" 0 \" > \" 1 \" | Date: \" 1000-01-01 00:00:00.000000 \" > \" 2021-01-13 16:00:09.331415 \" | In: \" 0 \" > \" 2 \" | Out: \" 0 \" > \" 1 \" | Entrance: \"  \" > \" Entrance \" | Device Key: \"  \" > \" DEVICE_UNIQUE_ID.DEVICE_MODEL \" | Status: \" 0 \" > \" 2 \"','2021-01-13 16:00:09.338384','Mozilla/5.0 (Linux; Android 10; RMX2040 Build/QP1A.190711.020; wv) AppleWebKit/537.36 (KHTML, like Gecko) Version/4.0 Chrome/78.0.3904.96 Mobile Safari/537.36'),(177,'49.146.42.127',1,0,6,0,0,40070,85,0,'add/edit Attendance record','User: \" 0 \" > \" 1 \" | Date: \" 1000-01-01 00:00:00.000000 \" > \" 2021-01-13 16:00:19.775885 \" | In: \" 0 \" > \" 2 \" | Out: \" 0 \" > \" 1 \" | Entrance: \"  \" > \" Entrance \" | Device Key: \"  \" > \" DEVICE_UNIQUE_ID.DEVICE_MODEL \" | Status: \" 0 \" > \" 2 \"','2021-01-13 16:00:19.782595','Mozilla/5.0 (Linux; Android 10; RMX2040 Build/QP1A.190711.020; wv) AppleWebKit/537.36 (KHTML, like Gecko) Version/4.0 Chrome/78.0.3904.96 Mobile Safari/537.36'),(178,'49.146.42.127',1,0,6,0,0,40070,86,0,'add/edit Attendance record','User: \" 0 \" > \" 1 \" | Date: \" 1000-01-01 00:00:00.000000 \" > \" 2021-01-13 16:01:10.073961 \" | In: \" 0 \" > \" 2 \" | Out: \" 0 \" > \" 1 \" | Entrance: \"  \" > \" Entrance \" | Device Key: \"  \" > \" DEVICE_UNIQUE_ID.DEVICE_MODEL \" | Status: \" 0 \" > \" 2 \"','2021-01-13 16:01:10.080296','Mozilla/5.0 (Linux; Android 10; RMX2040 Build/QP1A.190711.020; wv) AppleWebKit/537.36 (KHTML, like Gecko) Version/4.0 Chrome/78.0.3904.96 Mobile Safari/537.36'),(179,'49.146.42.127',1,0,6,0,0,40070,87,0,'add/edit Attendance record','User: \" 0 \" > \" 1 \" | Date: \" 1000-01-01 00:00:00.000000 \" > \" 2021-01-13 16:03:07.177882 \" | In: \" 0 \" > \" 2 \" | Out: \" 0 \" > \" 1 \" | Entrance: \"  \" > \" Entrance \" | Device Key: \"  \" > \" cec3ddbdce6dae96.RMX2040 \" | Status: \" 0 \" > \" 2 \"','2021-01-13 16:03:07.187567','Mozilla/5.0 (Linux; Android 10; RMX2040 Build/QP1A.190711.020; wv) AppleWebKit/537.36 (KHTML, like Gecko) Version/4.0 Chrome/78.0.3904.96 Mobile Safari/537.36'),(180,'49.146.42.127',1,0,6,0,0,40070,88,0,'add/edit Attendance record','User: \" 0 \" > \" 1 \" | Date: \" 1000-01-01 00:00:00.000000 \" > \" 2021-01-13 16:03:20.660935 \" | In: \" 0 \" > \" 2 \" | Out: \" 0 \" > \" 1 \" | Entrance: \"  \" > \" Entrance \" | Device Key: \"  \" > \" cec3ddbdce6dae96.RMX2040 \" | Status: \" 0 \" > \" 2 \"','2021-01-13 16:03:20.667598','Mozilla/5.0 (Linux; Android 10; RMX2040 Build/QP1A.190711.020; wv) AppleWebKit/537.36 (KHTML, like Gecko) Version/4.0 Chrome/78.0.3904.96 Mobile Safari/537.36'),(181,'49.146.42.127',1,0,6,0,0,40070,89,0,'add/edit Attendance record','User: \" 0 \" > \" 1 \" | Date: \" 1000-01-01 00:00:00.000000 \" > \" 2021-01-13 16:08:02.274875 \" | In: \" 0 \" > \" 2 \" | Out: \" 0 \" > \" 1 \" | Entrance: \"  \" > \" Entrance \" | Device Key: \"  \" > \" DEVICE_UNIQUE_ID.DEVICE_MODEL \" | Status: \" 0 \" > \" 2 \"','2021-01-13 16:08:02.281423','Mozilla/5.0 (Linux; Android 10; RMX2040 Build/QP1A.190711.020; wv) AppleWebKit/537.36 (KHTML, like Gecko) Version/4.0 Chrome/78.0.3904.96 Mobile Safari/537.36'),(182,'49.146.42.127',1,0,6,0,0,40070,90,0,'add/edit Attendance record','User: \" 0 \" > \" 1 \" | Date: \" 1000-01-01 00:00:00.000000 \" > \" 2021-01-13 16:08:12.237049 \" | In: \" 0 \" > \" 2 \" | Out: \" 0 \" > \" 1 \" | Entrance: \"  \" > \" Entrance \" | Device Key: \"  \" > \" DEVICE_UNIQUE_ID.DEVICE_MODEL \" | Status: \" 0 \" > \" 2 \"','2021-01-13 16:08:12.243746','Mozilla/5.0 (Linux; Android 10; RMX2040 Build/QP1A.190711.020; wv) AppleWebKit/537.36 (KHTML, like Gecko) Version/4.0 Chrome/78.0.3904.96 Mobile Safari/537.36'),(183,'49.146.42.127',1,0,6,0,0,40070,91,0,'add/edit Attendance record','User: \" 0 \" > \" 1 \" | Date: \" 1000-01-01 00:00:00.000000 \" > \" 2021-01-13 16:08:18.507244 \" | In: \" 0 \" > \" 2 \" | Out: \" 0 \" > \" 1 \" | Entrance: \"  \" > \" Entrance \" | Device Key: \"  \" > \" DEVICE_UNIQUE_ID.DEVICE_MODEL \" | Status: \" 0 \" > \" 2 \"','2021-01-13 16:08:18.513875','Mozilla/5.0 (Linux; Android 10; RMX2040 Build/QP1A.190711.020; wv) AppleWebKit/537.36 (KHTML, like Gecko) Version/4.0 Chrome/78.0.3904.96 Mobile Safari/537.36'),(184,'49.146.42.127',1,0,6,0,0,40070,92,0,'add/edit Attendance record','User: \" 0 \" > \" 1 \" | Date: \" 1000-01-01 00:00:00.000000 \" > \" 2021-01-13 16:08:29.745911 \" | In: \" 0 \" > \" 2 \" | Out: \" 0 \" > \" 1 \" | Entrance: \"  \" > \" Entrance \" | Device Key: \"  \" > \" DEVICE_UNIQUE_ID.DEVICE_MODEL \" | Status: \" 0 \" > \" 2 \"','2021-01-13 16:08:29.752796','Mozilla/5.0 (Linux; Android 10; RMX2040 Build/QP1A.190711.020; wv) AppleWebKit/537.36 (KHTML, like Gecko) Version/4.0 Chrome/78.0.3904.96 Mobile Safari/537.36'),(185,'49.146.42.127',1,0,6,0,0,40070,93,0,'add/edit Attendance record','User: \" 0 \" > \" 1 \" | Date: \" 1000-01-01 00:00:00.000000 \" > \" 2021-01-13 16:08:39.402948 \" | In: \" 0 \" > \" 2 \" | Out: \" 0 \" > \" 1 \" | Entrance: \"  \" > \" Entrance \" | Device Key: \"  \" > \" DEVICE_UNIQUE_ID.DEVICE_MODEL \" | Status: \" 0 \" > \" 2 \"','2021-01-13 16:08:39.409652','Mozilla/5.0 (Linux; Android 10; RMX2040 Build/QP1A.190711.020; wv) AppleWebKit/537.36 (KHTML, like Gecko) Version/4.0 Chrome/78.0.3904.96 Mobile Safari/537.36'),(186,'49.146.42.127',1,0,6,0,0,40070,94,0,'add/edit Attendance record','User: \" 0 \" > \" 1 \" | Date: \" 1000-01-01 00:00:00.000000 \" > \" 2021-01-13 16:09:50.403483 \" | In: \" 0 \" > \" 2 \" | Out: \" 0 \" > \" 1 \" | Entrance: \"  \" > \" Entrance \" | Device Key: \"  \" > \" DEVICE_UNIQUE_ID.DEVICE_MODEL \" | Status: \" 0 \" > \" 2 \"','2021-01-13 16:09:50.410068','Mozilla/5.0 (Linux; Android 10; RMX2040 Build/QP1A.190711.020; wv) AppleWebKit/537.36 (KHTML, like Gecko) Version/4.0 Chrome/78.0.3904.96 Mobile Safari/537.36'),(187,'49.146.42.127',1,0,6,0,0,40070,95,0,'add/edit Attendance record','User: \" 0 \" > \" 1 \" | Date: \" 1000-01-01 00:00:00.000000 \" > \" 2021-01-13 16:10:11.372685 \" | In: \" 0 \" > \" 2 \" | Out: \" 0 \" > \" 1 \" | Entrance: \"  \" > \" Entrance \" | Device Key: \"  \" > \" DEVICE_UNIQUE_ID.DEVICE_MODEL \" | Status: \" 0 \" > \" 2 \"','2021-01-13 16:10:11.386099','Mozilla/5.0 (Linux; Android 10; RMX2040 Build/QP1A.190711.020; wv) AppleWebKit/537.36 (KHTML, like Gecko) Version/4.0 Chrome/78.0.3904.96 Mobile Safari/537.36'),(188,'49.146.42.127',1,0,6,0,0,40070,96,0,'add/edit Attendance record','User: \" 0 \" > \" 1 \" | Date: \" 1000-01-01 00:00:00.000000 \" > \" 2021-01-13 16:10:23.920776 \" | In: \" 0 \" > \" 2 \" | Out: \" 0 \" > \" 1 \" | Entrance: \"  \" > \" Entrance \" | Device Key: \"  \" > \" DEVICE_UNIQUE_ID.DEVICE_MODEL \" | Status: \" 0 \" > \" 2 \"','2021-01-13 16:10:23.927301','Mozilla/5.0 (Linux; Android 10; RMX2040 Build/QP1A.190711.020; wv) AppleWebKit/537.36 (KHTML, like Gecko) Version/4.0 Chrome/78.0.3904.96 Mobile Safari/537.36'),(189,'49.146.42.127',1,0,6,0,0,40070,97,0,'add/edit Attendance record','User: \" 0 \" > \" 1 \" | Date: \" 1000-01-01 00:00:00.000000 \" > \" 2021-01-13 16:10:30.766179 \" | In: \" 0 \" > \" 2 \" | Out: \" 0 \" > \" 1 \" | Entrance: \"  \" > \" Entrance \" | Device Key: \"  \" > \" DEVICE_UNIQUE_ID.DEVICE_MODEL \" | Status: \" 0 \" > \" 2 \"','2021-01-13 16:10:30.772899','Mozilla/5.0 (Linux; Android 10; RMX2040 Build/QP1A.190711.020; wv) AppleWebKit/537.36 (KHTML, like Gecko) Version/4.0 Chrome/78.0.3904.96 Mobile Safari/537.36'),(190,'49.146.42.127',1,0,6,0,0,40070,98,0,'add/edit Attendance record','User: \" 0 \" > \" 1 \" | Date: \" 1000-01-01 00:00:00.000000 \" > \" 2021-01-13 16:10:36.932336 \" | In: \" 0 \" > \" 2 \" | Out: \" 0 \" > \" 1 \" | Entrance: \"  \" > \" Entrance \" | Device Key: \"  \" > \" DEVICE_UNIQUE_ID.DEVICE_MODEL \" | Status: \" 0 \" > \" 2 \"','2021-01-13 16:10:36.939049','Mozilla/5.0 (Linux; Android 10; RMX2040 Build/QP1A.190711.020; wv) AppleWebKit/537.36 (KHTML, like Gecko) Version/4.0 Chrome/78.0.3904.96 Mobile Safari/537.36'),(191,'49.146.42.127',1,0,6,0,0,40070,99,0,'add/edit Attendance record','User: \" 0 \" > \" 1 \" | Date: \" 1000-01-01 00:00:00.000000 \" > \" 2021-01-13 16:10:47.162974 \" | In: \" 0 \" > \" 2 \" | Out: \" 0 \" > \" 1 \" | Entrance: \"  \" > \" Entrance \" | Device Key: \"  \" > \" DEVICE_UNIQUE_ID.DEVICE_MODEL \" | Status: \" 0 \" > \" 2 \"','2021-01-13 16:10:47.169468','Mozilla/5.0 (Linux; Android 10; RMX2040 Build/QP1A.190711.020; wv) AppleWebKit/537.36 (KHTML, like Gecko) Version/4.0 Chrome/78.0.3904.96 Mobile Safari/537.36'),(192,'49.146.42.127',1,0,6,0,0,40070,100,0,'add/edit Attendance record','User: \" 0 \" > \" 1 \" | Date: \" 1000-01-01 00:00:00.000000 \" > \" 2021-01-13 16:11:19.876272 \" | In: \" 0 \" > \" 2 \" | Out: \" 0 \" > \" 1 \" | Entrance: \"  \" > \" Entrance \" | Device Key: \"  \" > \" cec3ddbdce6dae96.RMX2040 \" | Status: \" 0 \" > \" 2 \"','2021-01-13 16:11:19.882846','Mozilla/5.0 (Linux; Android 10; RMX2040 Build/QP1A.190711.020; wv) AppleWebKit/537.36 (KHTML, like Gecko) Version/4.0 Chrome/78.0.3904.96 Mobile Safari/537.36'),(193,'49.146.42.127',1,0,6,0,0,40070,101,0,'add/edit Attendance record','User: \" 0 \" > \" 1 \" | Date: \" 1000-01-01 00:00:00.000000 \" > \" 2021-01-13 16:11:28.674126 \" | In: \" 0 \" > \" 2 \" | Out: \" 0 \" > \" 1 \" | Entrance: \"  \" > \" Entrance \" | Device Key: \"  \" > \" cec3ddbdce6dae96.RMX2040 \" | Status: \" 0 \" > \" 2 \"','2021-01-13 16:11:28.681130','Mozilla/5.0 (Linux; Android 10; RMX2040 Build/QP1A.190711.020; wv) AppleWebKit/537.36 (KHTML, like Gecko) Version/4.0 Chrome/78.0.3904.96 Mobile Safari/537.36'),(194,'49.146.42.127',1,0,6,0,0,40070,102,0,'add/edit Attendance record','User: \" 0 \" > \" 1 \" | Date: \" 1000-01-01 00:00:00.000000 \" > \" 2021-01-13 16:19:02.753507 \" | In: \" 0 \" > \" 2 \" | Out: \" 0 \" > \" 1 \" | Entrance: \"  \" > \" Entrance \" | Device Key: \"  \" > \" DEVICE_UNIQUE_ID.DEVICE_MODEL \" | Status: \" 0 \" > \" 2 \"','2021-01-13 16:19:02.760841','Mozilla/5.0 (Linux; Android 10; RMX2040 Build/QP1A.190711.020; wv) AppleWebKit/537.36 (KHTML, like Gecko) Version/4.0 Chrome/78.0.3904.96 Mobile Safari/537.36'),(195,'49.146.42.127',1,0,6,0,0,40070,103,0,'add/edit Attendance record','User: \" 0 \" > \" 1 \" | Date: \" 1000-01-01 00:00:00.000000 \" > \" 2021-01-13 16:19:10.181236 \" | In: \" 0 \" > \" 2 \" | Out: \" 0 \" > \" 1 \" | Entrance: \"  \" > \" Entrance \" | Device Key: \"  \" > \" DEVICE_UNIQUE_ID.DEVICE_MODEL \" | Status: \" 0 \" > \" 2 \"','2021-01-13 16:19:10.187889','Mozilla/5.0 (Linux; Android 10; RMX2040 Build/QP1A.190711.020; wv) AppleWebKit/537.36 (KHTML, like Gecko) Version/4.0 Chrome/78.0.3904.96 Mobile Safari/537.36'),(196,'49.146.42.127',1,0,6,0,0,40070,104,0,'add/edit Attendance record','User: \" 0 \" > \" 1 \" | Date: \" 1000-01-01 00:00:00.000000 \" > \" 2021-01-13 16:20:47.909156 \" | In: \" 0 \" > \" 2 \" | Out: \" 0 \" > \" 1 \" | Entrance: \"  \" > \" Entrance \" | Device Key: \"  \" > \" DEVICE_UNIQUE_ID.DEVICE_MODEL \" | Status: \" 0 \" > \" 2 \"','2021-01-13 16:20:47.916089','Mozilla/5.0 (Linux; Android 10; RMX2040 Build/QP1A.190711.020; wv) AppleWebKit/537.36 (KHTML, like Gecko) Version/4.0 Chrome/78.0.3904.96 Mobile Safari/537.36'),(197,'49.146.42.127',1,0,6,0,0,40070,105,0,'add/edit Attendance record','User: \" 0 \" > \" 1 \" | Date: \" 1000-01-01 00:00:00.000000 \" > \" 2021-01-13 16:21:06.225162 \" | In: \" 0 \" > \" 2 \" | Out: \" 0 \" > \" 1 \" | Entrance: \"  \" > \" Entrance \" | Device Key: \"  \" > \" DEVICE_UNIQUE_ID.DEVICE_MODEL \" | Status: \" 0 \" > \" 2 \"','2021-01-13 16:21:06.231990','Mozilla/5.0 (Linux; Android 10; RMX2040 Build/QP1A.190711.020; wv) AppleWebKit/537.36 (KHTML, like Gecko) Version/4.0 Chrome/78.0.3904.96 Mobile Safari/537.36'),(198,'49.146.42.127',1,0,6,0,0,40070,106,0,'add/edit Attendance record','User: \" 0 \" > \" 1 \" | Date: \" 1000-01-01 00:00:00.000000 \" > \" 2021-01-13 16:21:13.616020 \" | In: \" 0 \" > \" 2 \" | Out: \" 0 \" > \" 1 \" | Entrance: \"  \" > \" Entrance \" | Device Key: \"  \" > \" DEVICE_UNIQUE_ID.DEVICE_MODEL \" | Status: \" 0 \" > \" 2 \"','2021-01-13 16:21:13.625323','Mozilla/5.0 (Linux; Android 10; RMX2040 Build/QP1A.190711.020; wv) AppleWebKit/537.36 (KHTML, like Gecko) Version/4.0 Chrome/78.0.3904.96 Mobile Safari/537.36'),(199,'49.146.42.127',1,0,6,0,0,40070,107,0,'add/edit Attendance record','User: \" 0 \" > \" 1 \" | Date: \" 1000-01-01 00:00:00.000000 \" > \" 2021-01-13 16:21:23.583395 \" | In: \" 0 \" > \" 2 \" | Out: \" 0 \" > \" 1 \" | Entrance: \"  \" > \" Entrance \" | Device Key: \"  \" > \" DEVICE_UNIQUE_ID.DEVICE_MODEL \" | Status: \" 0 \" > \" 2 \"','2021-01-13 16:21:23.590094','Mozilla/5.0 (Linux; Android 10; RMX2040 Build/QP1A.190711.020; wv) AppleWebKit/537.36 (KHTML, like Gecko) Version/4.0 Chrome/78.0.3904.96 Mobile Safari/537.36'),(200,'49.146.42.127',1,0,6,0,0,40070,108,0,'add/edit Attendance record','User: \" 0 \" > \" 1 \" | Date: \" 1000-01-01 00:00:00.000000 \" > \" 2021-01-13 16:21:32.134172 \" | In: \" 0 \" > \" 2 \" | Out: \" 0 \" > \" 1 \" | Entrance: \"  \" > \" Entrance \" | Device Key: \"  \" > \" DEVICE_UNIQUE_ID.DEVICE_MODEL \" | Status: \" 0 \" > \" 2 \"','2021-01-13 16:21:32.140839','Mozilla/5.0 (Linux; Android 10; RMX2040 Build/QP1A.190711.020; wv) AppleWebKit/537.36 (KHTML, like Gecko) Version/4.0 Chrome/78.0.3904.96 Mobile Safari/537.36'),(201,'49.146.42.127',1,0,6,0,0,40070,109,0,'add/edit Attendance record','User: \" 0 \" > \" 1 \" | Date: \" 1000-01-01 00:00:00.000000 \" > \" 2021-01-13 16:21:38.684484 \" | In: \" 0 \" > \" 2 \" | Out: \" 0 \" > \" 1 \" | Entrance: \"  \" > \" Entrance \" | Device Key: \"  \" > \" DEVICE_UNIQUE_ID.DEVICE_MODEL \" | Status: \" 0 \" > \" 2 \"','2021-01-13 16:21:38.690983','Mozilla/5.0 (Linux; Android 10; RMX2040 Build/QP1A.190711.020; wv) AppleWebKit/537.36 (KHTML, like Gecko) Version/4.0 Chrome/78.0.3904.96 Mobile Safari/537.36'),(202,'49.146.42.127',1,0,6,0,0,40070,110,0,'add/edit Attendance record','User: \" 0 \" > \" 1 \" | Date: \" 1000-01-01 00:00:00.000000 \" > \" 2021-01-13 16:21:45.045178 \" | In: \" 0 \" > \" 2 \" | Out: \" 0 \" > \" 1 \" | Entrance: \"  \" > \" Entrance \" | Device Key: \"  \" > \" DEVICE_UNIQUE_ID.DEVICE_MODEL \" | Status: \" 0 \" > \" 2 \"','2021-01-13 16:21:45.052032','Mozilla/5.0 (Linux; Android 10; RMX2040 Build/QP1A.190711.020; wv) AppleWebKit/537.36 (KHTML, like Gecko) Version/4.0 Chrome/78.0.3904.96 Mobile Safari/537.36'),(203,'49.146.42.127',1,0,6,0,0,40070,111,0,'add/edit Attendance record','User: \" 0 \" > \" 1 \" | Date: \" 1000-01-01 00:00:00.000000 \" > \" 2021-01-13 16:22:00.341817 \" | In: \" 0 \" > \" 2 \" | Out: \" 0 \" > \" 1 \" | Entrance: \"  \" > \" Entrance \" | Device Key: \"  \" > \" cec3ddbdce6dae96.RMX2040 \" | Status: \" 0 \" > \" 2 \"','2021-01-13 16:22:00.350035','Mozilla/5.0 (Linux; Android 10; RMX2040 Build/QP1A.190711.020; wv) AppleWebKit/537.36 (KHTML, like Gecko) Version/4.0 Chrome/78.0.3904.96 Mobile Safari/537.36'),(204,'49.146.42.127',1,0,6,0,0,40070,112,0,'add/edit Attendance record','User: \" 0 \" > \" 1 \" | Date: \" 1000-01-01 00:00:00.000000 \" > \" 2021-01-13 16:22:07.101310 \" | In: \" 0 \" > \" 2 \" | Out: \" 0 \" > \" 1 \" | Entrance: \"  \" > \" Entrance \" | Device Key: \"  \" > \" cec3ddbdce6dae96.RMX2040 \" | Status: \" 0 \" > \" 2 \"','2021-01-13 16:22:07.108156','Mozilla/5.0 (Linux; Android 10; RMX2040 Build/QP1A.190711.020; wv) AppleWebKit/537.36 (KHTML, like Gecko) Version/4.0 Chrome/78.0.3904.96 Mobile Safari/537.36'),(205,'49.146.42.127',1,0,6,0,0,40070,113,0,'add/edit Attendance record','User: \" 0 \" > \" 1 \" | Date: \" 1000-01-01 00:00:00.000000 \" > \" 2021-01-13 16:22:16.522244 \" | In: \" 0 \" > \" 2 \" | Out: \" 0 \" > \" 1 \" | Entrance: \"  \" > \" Entrance \" | Device Key: \"  \" > \" cec3ddbdce6dae96.RMX2040 \" | Status: \" 0 \" > \" 2 \"','2021-01-13 16:22:16.529831','Mozilla/5.0 (Linux; Android 10; RMX2040 Build/QP1A.190711.020; wv) AppleWebKit/537.36 (KHTML, like Gecko) Version/4.0 Chrome/78.0.3904.96 Mobile Safari/537.36'),(206,'49.146.42.127',1,0,6,0,0,40070,114,0,'add/edit Attendance record','User: \" 0 \" > \" 1 \" | Date: \" 1000-01-01 00:00:00.000000 \" > \" 2021-01-13 16:22:24.922936 \" | In: \" 0 \" > \" 2 \" | Out: \" 0 \" > \" 1 \" | Entrance: \"  \" > \" Entrance \" | Device Key: \"  \" > \" cec3ddbdce6dae96.RMX2040 \" | Status: \" 0 \" > \" 2 \"','2021-01-13 16:22:24.930650','Mozilla/5.0 (Linux; Android 10; RMX2040 Build/QP1A.190711.020; wv) AppleWebKit/537.36 (KHTML, like Gecko) Version/4.0 Chrome/78.0.3904.96 Mobile Safari/537.36'),(207,'49.146.42.127',1,0,6,0,0,40070,115,0,'add/edit Attendance record','User: \" 0 \" > \" 1 \" | Date: \" 1000-01-01 00:00:00.000000 \" > \" 2021-01-13 16:22:45.462668 \" | In: \" 0 \" > \" 2 \" | Out: \" 0 \" > \" 1 \" | Entrance: \"  \" > \" Entrance \" | Device Key: \"  \" > \" cec3ddbdce6dae96.RMX2040 \" | Status: \" 0 \" > \" 2 \"','2021-01-13 16:22:45.470520','Mozilla/5.0 (Linux; Android 10; RMX2040 Build/QP1A.190711.020; wv) AppleWebKit/537.36 (KHTML, like Gecko) Version/4.0 Chrome/78.0.3904.96 Mobile Safari/537.36'),(208,'49.146.42.127',1,0,6,0,0,40070,116,0,'add/edit Attendance record','User: \" 0 \" > \" 1 \" | Date: \" 1000-01-01 00:00:00.000000 \" > \" 2021-01-13 16:23:07.371131 \" | In: \" 0 \" > \" 2 \" | Out: \" 0 \" > \" 1 \" | Entrance: \"  \" > \" Entrance \" | Device Key: \"  \" > \" cec3ddbdce6dae96.RMX2040 \" | Status: \" 0 \" > \" 2 \"','2021-01-13 16:23:07.381825','Mozilla/5.0 (Linux; Android 10; RMX2040 Build/QP1A.190711.020; wv) AppleWebKit/537.36 (KHTML, like Gecko) Version/4.0 Chrome/78.0.3904.96 Mobile Safari/537.36'),(209,'49.146.42.127',1,0,6,0,0,40070,117,0,'add/edit Attendance record','User: \" 0 \" > \" 1 \" | Date: \" 1000-01-01 00:00:00.000000 \" > \" 2021-01-13 16:26:14.689888 \" | In: \" 0 \" > \" 2 \" | Out: \" 0 \" > \" 1 \" | Entrance: \"  \" > \" Entrance \" | Device Key: \"  \" > \" cec3ddbdce6dae96.RMX2040 \" | Status: \" 0 \" > \" 2 \"','2021-01-13 16:26:14.696724','Mozilla/5.0 (Linux; Android 10; RMX2040 Build/QP1A.190711.020; wv) AppleWebKit/537.36 (KHTML, like Gecko) Version/4.0 Chrome/78.0.3904.96 Mobile Safari/537.36'),(210,'49.146.42.127',1,0,6,0,0,40070,118,0,'add/edit Attendance record','User: \" 0 \" > \" 1 \" | Date: \" 1000-01-01 00:00:00.000000 \" > \" 2021-01-13 16:26:27.473523 \" | In: \" 0 \" > \" 2 \" | Out: \" 0 \" > \" 1 \" | Entrance: \"  \" > \" Entrance \" | Device Key: \"  \" > \" cec3ddbdce6dae96.RMX2040 \" | Status: \" 0 \" > \" 2 \"','2021-01-13 16:26:27.480069','Mozilla/5.0 (Linux; Android 10; RMX2040 Build/QP1A.190711.020; wv) AppleWebKit/537.36 (KHTML, like Gecko) Version/4.0 Chrome/78.0.3904.96 Mobile Safari/537.36'),(211,'49.146.42.127',1,0,6,0,0,40070,119,0,'add/edit Attendance record','User: \" 0 \" > \" 1 \" | Date: \" 1000-01-01 00:00:00.000000 \" > \" 2021-01-13 16:27:14.904845 \" | In: \" 0 \" > \" 2 \" | Out: \" 0 \" > \" 1 \" | Entrance: \"  \" > \" Entrance \" | Device Key: \"  \" > \" cec3ddbdce6dae96.RMX2040 \" | Status: \" 0 \" > \" 2 \"','2021-01-13 16:27:14.923704','Mozilla/5.0 (Linux; Android 10; RMX2040 Build/QP1A.190711.020; wv) AppleWebKit/537.36 (KHTML, like Gecko) Version/4.0 Chrome/78.0.3904.96 Mobile Safari/537.36'),(212,'49.146.42.127',1,0,6,0,0,40070,120,0,'add/edit Attendance record','User: \" 0 \" > \" 1 \" | Date: \" 1000-01-01 00:00:00.000000 \" > \" 2021-01-13 16:30:17.785693 \" | In: \" 0 \" > \" 2 \" | Out: \" 0 \" > \" 1 \" | Entrance: \"  \" > \" Entrance \" | Device Key: \"  \" > \" cec3ddbdce6dae96.RMX2040 \" | Status: \" 0 \" > \" 2 \"','2021-01-13 16:30:17.795894','Mozilla/5.0 (Linux; Android 10; RMX2040 Build/QP1A.190711.020; wv) AppleWebKit/537.36 (KHTML, like Gecko) Version/4.0 Chrome/78.0.3904.96 Mobile Safari/537.36'),(213,'49.146.42.127',1,0,6,0,0,40070,121,0,'add/edit Attendance record','User: \" 0 \" > \" 1 \" | Date: \" 1000-01-01 00:00:00.000000 \" > \" 2021-01-13 16:30:32.814031 \" | In: \" 0 \" > \" 2 \" | Out: \" 0 \" > \" 1 \" | Entrance: \"  \" > \" Entrance \" | Device Key: \"  \" > \" cec3ddbdce6dae96.RMX2040 \" | Status: \" 0 \" > \" 2 \"','2021-01-13 16:30:32.820523','Mozilla/5.0 (Linux; Android 10; RMX2040 Build/QP1A.190711.020; wv) AppleWebKit/537.36 (KHTML, like Gecko) Version/4.0 Chrome/78.0.3904.96 Mobile Safari/537.36'),(214,'49.146.42.127',1,0,6,0,0,40070,122,0,'add/edit Attendance record','User: \" 0 \" > \" 1 \" | Date: \" 1000-01-01 00:00:00.000000 \" > \" 2021-01-13 16:30:52.511034 \" | In: \" 0 \" > \" 2 \" | Out: \" 0 \" > \" 1 \" | Entrance: \"  \" > \" Entrance \" | Device Key: \"  \" > \" cec3ddbdce6dae96.RMX2040 \" | Status: \" 0 \" > \" 2 \"','2021-01-13 16:30:52.517847','Mozilla/5.0 (Linux; Android 10; RMX2040 Build/QP1A.190711.020; wv) AppleWebKit/537.36 (KHTML, like Gecko) Version/4.0 Chrome/78.0.3904.96 Mobile Safari/537.36'),(215,'49.146.42.127',1,0,6,0,0,40070,123,0,'add/edit Attendance record','User: \" 0 \" > \" 1 \" | Date: \" 1000-01-01 00:00:00.000000 \" > \" 2021-01-13 16:31:15.025861 \" | In: \" 0 \" > \" 2 \" | Out: \" 0 \" > \" 1 \" | Entrance: \"  \" > \" Entrance \" | Device Key: \"  \" > \" cec3ddbdce6dae96.RMX2040 \" | Status: \" 0 \" > \" 2 \"','2021-01-13 16:31:15.032433','Mozilla/5.0 (Linux; Android 10; RMX2040 Build/QP1A.190711.020; wv) AppleWebKit/537.36 (KHTML, like Gecko) Version/4.0 Chrome/78.0.3904.96 Mobile Safari/537.36'),(216,'49.146.42.127',1,0,6,0,0,40070,124,0,'add/edit Attendance record','User: \" 0 \" > \" 1 \" | Date: \" 1000-01-01 00:00:00.000000 \" > \" 2021-01-13 16:31:34.251429 \" | In: \" 0 \" > \" 2 \" | Out: \" 0 \" > \" 1 \" | Entrance: \"  \" > \" Entrance \" | Device Key: \"  \" > \" cec3ddbdce6dae96.RMX2040 \" | Status: \" 0 \" > \" 2 \"','2021-01-13 16:31:34.258098','Mozilla/5.0 (Linux; Android 10; RMX2040 Build/QP1A.190711.020; wv) AppleWebKit/537.36 (KHTML, like Gecko) Version/4.0 Chrome/78.0.3904.96 Mobile Safari/537.36'),(217,'49.146.42.127',1,0,6,0,0,40070,125,0,'add/edit Attendance record','User: \" 0 \" > \" 1 \" | Date: \" 1000-01-01 00:00:00.000000 \" > \" 2021-01-13 16:31:48.095515 \" | In: \" 0 \" > \" 2 \" | Out: \" 0 \" > \" 1 \" | Entrance: \"  \" > \" Entrance \" | Device Key: \"  \" > \" cec3ddbdce6dae96.RMX2040 \" | Status: \" 0 \" > \" 2 \"','2021-01-13 16:31:48.102139','Mozilla/5.0 (Linux; Android 10; RMX2040 Build/QP1A.190711.020; wv) AppleWebKit/537.36 (KHTML, like Gecko) Version/4.0 Chrome/78.0.3904.96 Mobile Safari/537.36'),(218,'49.146.42.127',1,0,6,0,0,40070,126,0,'add/edit Attendance record','User: \" 0 \" > \" 1 \" | Date: \" 1000-01-01 00:00:00.000000 \" > \" 2021-01-13 16:32:02.064913 \" | In: \" 0 \" > \" 2 \" | Out: \" 0 \" > \" 1 \" | Entrance: \"  \" > \" Entrance \" | Device Key: \"  \" > \" cec3ddbdce6dae96.RMX2040 \" | Status: \" 0 \" > \" 2 \"','2021-01-13 16:32:02.071280','Mozilla/5.0 (Linux; Android 10; RMX2040 Build/QP1A.190711.020; wv) AppleWebKit/537.36 (KHTML, like Gecko) Version/4.0 Chrome/78.0.3904.96 Mobile Safari/537.36'),(219,'49.146.42.127',1,0,6,0,0,40070,127,0,'add/edit Attendance record','User: \" 0 \" > \" 1 \" | Date: \" 1000-01-01 00:00:00.000000 \" > \" 2021-01-13 16:32:21.388426 \" | In: \" 0 \" > \" 2 \" | Out: \" 0 \" > \" 1 \" | Entrance: \"  \" > \" Entrance \" | Device Key: \"  \" > \" cec3ddbdce6dae96.RMX2040 \" | Status: \" 0 \" > \" 2 \"','2021-01-13 16:32:21.396231','Mozilla/5.0 (Linux; Android 10; RMX2040 Build/QP1A.190711.020; wv) AppleWebKit/537.36 (KHTML, like Gecko) Version/4.0 Chrome/78.0.3904.96 Mobile Safari/537.36'),(220,'49.146.42.127',1,0,6,0,0,40070,128,0,'add/edit Attendance record','User: \" 0 \" > \" 1 \" | Date: \" 1000-01-01 00:00:00.000000 \" > \" 2021-01-13 16:32:31.256137 \" | In: \" 0 \" > \" 2 \" | Out: \" 0 \" > \" 1 \" | Entrance: \"  \" > \" Entrance \" | Device Key: \"  \" > \" cec3ddbdce6dae96.RMX2040 \" | Status: \" 0 \" > \" 2 \"','2021-01-13 16:32:31.262717','Mozilla/5.0 (Linux; Android 10; RMX2040 Build/QP1A.190711.020; wv) AppleWebKit/537.36 (KHTML, like Gecko) Version/4.0 Chrome/78.0.3904.96 Mobile Safari/537.36'),(221,'49.146.42.127',1,0,6,0,0,40010,4,0,'add/edit Registration record','Gender: \" 2 \" > \" 1 \"','2021-01-13 16:35:18.766726','Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/87.0.4280.141 Safari/537.36'),(222,'49.146.42.127',1,0,6,0,0,21030,3,0,'add/edit Section record','Department: \" 0 \" > \" 1 \" | Description: \"  \" > \" Warehosue Management \" | Status: \" 0 \" > \" 2 \"','2021-01-13 16:48:06.605238','Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/87.0.4280.141 Safari/537.36'),(223,'49.146.42.127',1,0,6,0,0,40070,129,0,'add/edit Attendance record','User: \" 0 \" > \" 1 \" | Date: \" 1000-01-01 00:00:00.000000 \" > \" 2021-01-13 16:49:40.899231 \" | In: \" 0 \" > \" 2 \" | Out: \" 0 \" > \" 1 \" | Entrance: \"  \" > \" Entrance \" | Device Key: \"  \" > \" cec3ddbdce6dae96.RMX2040 \" | Status: \" 0 \" > \" 2 \"','2021-01-13 16:49:40.906556','Mozilla/5.0 (Linux; Android 10; RMX2040 Build/QP1A.190711.020; wv) AppleWebKit/537.36 (KHTML, like Gecko) Version/4.0 Chrome/78.0.3904.96 Mobile Safari/537.36'),(224,'49.146.42.127',1,0,6,0,0,40070,130,0,'add/edit Attendance record','User: \" 0 \" > \" 1 \" | Date: \" 1000-01-01 00:00:00.000000 \" > \" 2021-01-13 16:50:00.594182 \" | In: \" 0 \" > \" 2 \" | Out: \" 0 \" > \" 1 \" | Entrance: \"  \" > \" Entrance \" | Device Key: \"  \" > \" cec3ddbdce6dae96.RMX2040 \" | Status: \" 0 \" > \" 2 \"','2021-01-13 16:50:00.602263','Mozilla/5.0 (Linux; Android 10; RMX2040 Build/QP1A.190711.020; wv) AppleWebKit/537.36 (KHTML, like Gecko) Version/4.0 Chrome/78.0.3904.96 Mobile Safari/537.36'),(225,'49.146.42.127',1,0,6,0,0,40070,131,0,'add/edit Attendance record','User: \" 0 \" > \" 1 \" | Date: \" 1000-01-01 00:00:00.000000 \" > \" 2021-01-13 16:50:25.688539 \" | In: \" 0 \" > \" 2 \" | Out: \" 0 \" > \" 1 \" | Entrance: \"  \" > \" Entrance \" | Device Key: \"  \" > \" cec3ddbdce6dae96.RMX2040 \" | Status: \" 0 \" > \" 2 \"','2021-01-13 16:50:25.697962','Mozilla/5.0 (Linux; Android 10; RMX2040 Build/QP1A.190711.020; wv) AppleWebKit/537.36 (KHTML, like Gecko) Version/4.0 Chrome/78.0.3904.96 Mobile Safari/537.36'),(226,'175.176.90.255',1,0,6,0,0,21010,4,0,'add/edit Department record','Description: \"  \" > \" Department A \" | Status: \" 0 \" > \" 2 \"','2021-01-19 10:15:10.964166','Mozilla/5.0 (Windows NT 6.1; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/86.0.4240.198 Safari/537.36'),(227,'175.176.90.255',1,0,3,0,0,40010,1,0,'add/edit Registration record','Department: \" 0 \" > \" 2 \" | Section: \" 0 \" > \" 1 \" | First name: \"  \" > \" Juan \" | Last name: \"  \" > \" dela Cruz \" | Gender: \" 0 \" > \" 1 \" | Notification Phone Number: \"  \" > \" +639655460720 \" | Emergency Contact Person: \"  \" > \" Juana dela Cruz \" | Emergency Contact Numbher: \"  \" > \" +639655460720 \" | Status: \" 0 \" > \" 2 \"','2021-01-19 10:19:00.098867','Mozilla/5.0 (Windows NT 6.1; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/86.0.4240.198 Safari/537.36'),(228,'175.176.90.255',1,0,6,0,0,40050,1,0,'add/edit User record','Department: \" 0 \" > \" 2 \" | Section: \" 0 \" > \" 1 \" | Unique Code: \"  \" > \" DEF.20210119.102028585893.q6SIZaA \" | First name: \"  \" > \" Juan \" | Last name: \"  \" > \" dela Cruz \" | Gender: \" 0 \" > \" 1 \" | Notification Mobile Number: \"  \" > \" +639655460720 \" | Emergency Contact Person: \"  \" > \" Juana dela Cruz \" | Emergency Contact Number: \"  \" > \" +639655460720 \" | Status: \" 0 \" > \" 2 \"','2021-01-19 10:20:28.612144','Mozilla/5.0 (Windows NT 6.1; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/86.0.4240.198 Safari/537.36'),(229,'175.176.90.255',1,0,6,0,0,40010,1,0,'add/edit Registration record','User: \" 0 \" > \" -9223372036854700032 \" | Status: \" 2 \" > \" 4 \"','2021-01-19 10:20:28.613801','Mozilla/5.0 (Windows NT 6.1; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/86.0.4240.198 Safari/537.36'),(230,'175.176.90.255',1,0,3,0,0,40010,2,0,'add/edit Registration record','Department: \" 0 \" > \" 2 \" | Section: \" 0 \" > \" 1 \" | First name: \"  \" > \" Juana \" | Last name: \"  \" > \" dela Cruz \" | Gender: \" 0 \" > \" 2 \" | Notification Phone Number: \"  \" > \" +639655460720 \" | Emergency Contact Person: \"  \" > \" Juan dela Cruz \" | Emergency Contact Numbher: \"  \" > \" +639655460720 \" | Status: \" 0 \" > \" 2 \"','2021-01-19 10:41:21.667915','Mozilla/5.0 (Windows NT 6.1; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/86.0.4240.198 Safari/537.36'),(231,'175.176.90.255',1,0,6,0,0,40050,2,0,'add/edit User record','Department: \" 0 \" > \" 2 \" | Section: \" 0 \" > \" 1 \" | Unique Code: \"  \" > \" DEF.20210119.104226823125.QfYJ72l \" | First name: \"  \" > \" Juana \" | Last name: \"  \" > \" dela Cruz \" | Gender: \" 0 \" > \" 2 \" | Notification Mobile Number: \"  \" > \" +639655460720 \" | Emergency Contact Person: \"  \" > \" Juan dela Cruz \" | Emergency Contact Number: \"  \" > \" +639655460720 \" | Status: \" 0 \" > \" 2 \"','2021-01-19 10:42:26.831946','Mozilla/5.0 (Windows NT 6.1; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/86.0.4240.198 Safari/537.36'),(232,'175.176.90.255',1,0,6,0,0,40010,2,0,'add/edit Registration record','User: \" 0 \" > \" -9223372036854700032 \" | Status: \" 2 \" > \" 4 \"','2021-01-19 10:42:26.833919','Mozilla/5.0 (Windows NT 6.1; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/86.0.4240.198 Safari/537.36'),(233,'175.176.90.255',1,0,6,0,0,40070,1,0,'add/edit Attendance record','User: \" 0 \" > \" 1 \" | Date: \" 1000-01-01 00:00:00.000000 \" > \" 2021-01-19 10:45:17.612259 \" | In: \" 0 \" > \" 2 \" | Out: \" 0 \" > \" 1 \" | Entrance: \"  \" > \" Entrance \" | Device Key: \"  \" > \" cec3ddbdce6dae96.RMX2040 \" | Status: \" 0 \" > \" 2 \"','2021-01-19 10:45:17.620325','Mozilla/5.0 (Linux; Android 10; RMX2040 Build/QP1A.190711.020; wv) AppleWebKit/537.36 (KHTML, like Gecko) Version/4.0 Chrome/87.0.4280.141 Mobile Safari/537.36'),(234,'175.176.90.255',1,0,3,0,0,10080,468,0,'add/edit Access rights record','LEVEL: 0 (\"\")  >  4 (\" Guard \") | MODULE: 0 (\"\")  >  10040 (\" User Account : level \") | AUTHORITY:  0 (\"\")  > 0 (\" No Access \")','2021-01-19 10:51:03.021743','Mozilla/5.0 (Windows NT 6.1; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/86.0.4240.198 Safari/537.36'),(235,'175.176.90.255',1,0,3,0,0,10080,469,0,'add/edit Access rights record','LEVEL: 0 (\"\")  >  4 (\" Guard \") | MODULE: 0 (\"\")  >  10040 (\" User Account : level \") | AUTHORITY:  0 (\"\")  > 0 (\" No Access \") | LEVEL: 0 (\"\")  >  4 (\" Guard \") | MODULE: 0 (\"\")  >  10060 (\" User Account : member \") | AUTHORITY:  0 (\"\")  > 0 (\" No Access \")','2021-01-19 10:51:03.023934','Mozilla/5.0 (Windows NT 6.1; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/86.0.4240.198 Safari/537.36'),(236,'175.176.90.255',1,0,3,0,0,10080,470,0,'add/edit Access rights record','LEVEL: 0 (\"\")  >  4 (\" Guard \") | MODULE: 0 (\"\")  >  10040 (\" User Account : level \") | AUTHORITY:  0 (\"\")  > 0 (\" No Access \") | LEVEL: 0 (\"\")  >  4 (\" Guard \") | MODULE: 0 (\"\")  >  10060 (\" User Account : member \") | AUTHORITY:  0 (\"\")  > 0 (\" No Access \") | LEVEL: 0 (\"\")  >  4 (\" Guard \") | MODULE: 0 (\"\")  >  10070 (\" User Account : group \") | AUTHORITY:  0 (\"\")  > 0 (\" No Access \")','2021-01-19 10:51:03.025972','Mozilla/5.0 (Windows NT 6.1; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/86.0.4240.198 Safari/537.36'),(237,'175.176.90.255',1,0,3,0,0,10080,471,0,'add/edit Access rights record','LEVEL: 0 (\"\")  >  4 (\" Guard \") | MODULE: 0 (\"\")  >  10040 (\" User Account : level \") | AUTHORITY:  0 (\"\")  > 0 (\" No Access \") | LEVEL: 0 (\"\")  >  4 (\" Guard \") | MODULE: 0 (\"\")  >  10060 (\" User Account : member \") | AUTHORITY:  0 (\"\")  > 0 (\" No Access \") | LEVEL: 0 (\"\")  >  4 (\" Guard \") | MODULE: 0 (\"\")  >  10070 (\" User Account : group \") | AUTHORITY:  0 (\"\")  > 0 (\" No Access \") | LEVEL: 0 (\"\")  >  4 (\" Guard \") | MODULE: 0 (\"\")  >  10080 (\" User Account : access rights \") | AUTHORITY:  0 (\"\")  > 0 (\" No Access \")','2021-01-19 10:51:03.028018','Mozilla/5.0 (Windows NT 6.1; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/86.0.4240.198 Safari/537.36'),(238,'175.176.90.255',1,0,3,0,0,10080,472,0,'add/edit Access rights record','LEVEL: 0 (\"\")  >  4 (\" Guard \") | MODULE: 0 (\"\")  >  10040 (\" User Account : level \") | AUTHORITY:  0 (\"\")  > 0 (\" No Access \") | LEVEL: 0 (\"\")  >  4 (\" Guard \") | MODULE: 0 (\"\")  >  10060 (\" User Account : member \") | AUTHORITY:  0 (\"\")  > 0 (\" No Access \") | LEVEL: 0 (\"\")  >  4 (\" Guard \") | MODULE: 0 (\"\")  >  10070 (\" User Account : group \") | AUTHORITY:  0 (\"\")  > 0 (\" No Access \") | LEVEL: 0 (\"\")  >  4 (\" Guard \") | MODULE: 0 (\"\")  >  10080 (\" User Account : access rights \") | AUTHORITY:  0 (\"\")  > 0 (\" No Access \") | LEVEL: 0 (\"\")  >  4 (\" Guard \") | MODULE: 0 (\"\")  >  10100 (\" Account: server \") | AUTHORITY:  0 (\"\")  > 0 (\" No Access \")','2021-01-19 10:51:03.030694','Mozilla/5.0 (Windows NT 6.1; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/86.0.4240.198 Safari/537.36'),(239,'175.176.90.255',1,0,3,0,0,10080,473,0,'add/edit Access rights record','LEVEL: 0 (\"\")  >  4 (\" Guard \") | MODULE: 0 (\"\")  >  10040 (\" User Account : level \") | AUTHORITY:  0 (\"\")  > 0 (\" No Access \") | LEVEL: 0 (\"\")  >  4 (\" Guard \") | MODULE: 0 (\"\")  >  10060 (\" User Account : member \") | AUTHORITY:  0 (\"\")  > 0 (\" No Access \") | LEVEL: 0 (\"\")  >  4 (\" Guard \") | MODULE: 0 (\"\")  >  10070 (\" User Account : group \") | AUTHORITY:  0 (\"\")  > 0 (\" No Access \") | LEVEL: 0 (\"\")  >  4 (\" Guard \") | MODULE: 0 (\"\")  >  10080 (\" User Account : access rights \") | AUTHORITY:  0 (\"\")  > 0 (\" No Access \") | LEVEL: 0 (\"\")  >  4 (\" Guard \") | MODULE: 0 (\"\")  >  10100 (\" Account: server \") | AUTHORITY:  0 (\"\")  > 0 (\" No Access \") | LEVEL: 0 (\"\")  >  4 (\" Guard \") | MODULE: 0 (\"\")  >  10120 (\" Devices \") | AUTHORITY:  0 (\"\")  > 0 (\" No Access \")','2021-01-19 10:51:03.032853','Mozilla/5.0 (Windows NT 6.1; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/86.0.4240.198 Safari/537.36'),(240,'175.176.90.255',1,0,3,0,0,10080,474,0,'add/edit Access rights record','LEVEL: 0 (\"\")  >  4 (\" Guard \") | MODULE: 0 (\"\")  >  10040 (\" User Account : level \") | AUTHORITY:  0 (\"\")  > 0 (\" No Access \") | LEVEL: 0 (\"\")  >  4 (\" Guard \") | MODULE: 0 (\"\")  >  10060 (\" User Account : member \") | AUTHORITY:  0 (\"\")  > 0 (\" No Access \") | LEVEL: 0 (\"\")  >  4 (\" Guard \") | MODULE: 0 (\"\")  >  10070 (\" User Account : group \") | AUTHORITY:  0 (\"\")  > 0 (\" No Access \") | LEVEL: 0 (\"\")  >  4 (\" Guard \") | MODULE: 0 (\"\")  >  10080 (\" User Account : access rights \") | AUTHORITY:  0 (\"\")  > 0 (\" No Access \") | LEVEL: 0 (\"\")  >  4 (\" Guard \") | MODULE: 0 (\"\")  >  10100 (\" Account: server \") | AUTHORITY:  0 (\"\")  > 0 (\" No Access \") | LEVEL: 0 (\"\")  >  4 (\" Guard \") | MODULE: 0 (\"\")  >  10120 (\" Devices \") | AUTHORITY:  0 (\"\")  > 0 (\" No Access \") | LEVEL: 0 (\"\")  >  4 (\" Guard \") | MODULE: 0 (\"\")  >  10140 (\" User Account : audit trail \") | AUTHORITY:  0 (\"\")  > 0 (\" No Access \")','2021-01-19 10:51:03.034878','Mozilla/5.0 (Windows NT 6.1; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/86.0.4240.198 Safari/537.36'),(241,'175.176.90.255',1,0,3,0,0,10080,475,0,'add/edit Access rights record','LEVEL: 0 (\"\")  >  4 (\" Guard \") | MODULE: 0 (\"\")  >  10040 (\" User Account : level \") | AUTHORITY:  0 (\"\")  > 0 (\" No Access \") | LEVEL: 0 (\"\")  >  4 (\" Guard \") | MODULE: 0 (\"\")  >  10060 (\" User Account : member \") | AUTHORITY:  0 (\"\")  > 0 (\" No Access \") | LEVEL: 0 (\"\")  >  4 (\" Guard \") | MODULE: 0 (\"\")  >  10070 (\" User Account : group \") | AUTHORITY:  0 (\"\")  > 0 (\" No Access \") | LEVEL: 0 (\"\")  >  4 (\" Guard \") | MODULE: 0 (\"\")  >  10080 (\" User Account : access rights \") | AUTHORITY:  0 (\"\")  > 0 (\" No Access \") | LEVEL: 0 (\"\")  >  4 (\" Guard \") | MODULE: 0 (\"\")  >  10100 (\" Account: server \") | AUTHORITY:  0 (\"\")  > 0 (\" No Access \") | LEVEL: 0 (\"\")  >  4 (\" Guard \") | MODULE: 0 (\"\")  >  10120 (\" Devices \") | AUTHORITY:  0 (\"\")  > 0 (\" No Access \") | LEVEL: 0 (\"\")  >  4 (\" Guard \") | MODULE: 0 (\"\")  >  10140 (\" User Account : audit trail \") | AUTHORITY:  0 (\"\")  > 0 (\" No Access \") | LEVEL: 0 (\"\")  >  4 (\" Guard \") | MODULE: 0 (\"\")  >  10160 (\" Brute Force Login Attempt \") | AUTHORITY:  0 (\"\")  > 0 (\" No Access \")','2021-01-19 10:51:03.036870','Mozilla/5.0 (Windows NT 6.1; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/86.0.4240.198 Safari/537.36'),(242,'175.176.90.255',1,0,3,0,0,10080,476,0,'add/edit Access rights record','LEVEL: 0 (\"\")  >  4 (\" Guard \") | MODULE: 0 (\"\")  >  10040 (\" User Account : level \") | AUTHORITY:  0 (\"\")  > 0 (\" No Access \") | LEVEL: 0 (\"\")  >  4 (\" Guard \") | MODULE: 0 (\"\")  >  10060 (\" User Account : member \") | AUTHORITY:  0 (\"\")  > 0 (\" No Access \") | LEVEL: 0 (\"\")  >  4 (\" Guard \") | MODULE: 0 (\"\")  >  10070 (\" User Account : group \") | AUTHORITY:  0 (\"\")  > 0 (\" No Access \") | LEVEL: 0 (\"\")  >  4 (\" Guard \") | MODULE: 0 (\"\")  >  10080 (\" User Account : access rights \") | AUTHORITY:  0 (\"\")  > 0 (\" No Access \") | LEVEL: 0 (\"\")  >  4 (\" Guard \") | MODULE: 0 (\"\")  >  10100 (\" Account: server \") | AUTHORITY:  0 (\"\")  > 0 (\" No Access \") | LEVEL: 0 (\"\")  >  4 (\" Guard \") | MODULE: 0 (\"\")  >  10120 (\" Devices \") | AUTHORITY:  0 (\"\")  > 0 (\" No Access \") | LEVEL: 0 (\"\")  >  4 (\" Guard \") | MODULE: 0 (\"\")  >  10140 (\" User Account : audit trail \") | AUTHORITY:  0 (\"\")  > 0 (\" No Access \") | LEVEL: 0 (\"\")  >  4 (\" Guard \") | MODULE: 0 (\"\")  >  10160 (\" Brute Force Login Attempt \") | AUTHORITY:  0 (\"\")  > 0 (\" No Access \") | LEVEL: 0 (\"\")  >  4 (\" Guard \") | MODULE: 0 (\"\")  >  10180 (\" Bruteforce IP \") | AUTHORITY:  0 (\"\")  > 0 (\" No Access \")','2021-01-19 10:51:03.038831','Mozilla/5.0 (Windows NT 6.1; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/86.0.4240.198 Safari/537.36'),(243,'175.176.90.255',1,0,3,0,0,10080,477,0,'add/edit Access rights record','LEVEL: 0 (\"\")  >  4 (\" Guard \") | MODULE: 0 (\"\")  >  10040 (\" User Account : level \") | AUTHORITY:  0 (\"\")  > 0 (\" No Access \") | LEVEL: 0 (\"\")  >  4 (\" Guard \") | MODULE: 0 (\"\")  >  10060 (\" User Account : member \") | AUTHORITY:  0 (\"\")  > 0 (\" No Access \") | LEVEL: 0 (\"\")  >  4 (\" Guard \") | MODULE: 0 (\"\")  >  10070 (\" User Account : group \") | AUTHORITY:  0 (\"\")  > 0 (\" No Access \") | LEVEL: 0 (\"\")  >  4 (\" Guard \") | MODULE: 0 (\"\")  >  10080 (\" User Account : access rights \") | AUTHORITY:  0 (\"\")  > 0 (\" No Access \") | LEVEL: 0 (\"\")  >  4 (\" Guard \") | MODULE: 0 (\"\")  >  10100 (\" Account: server \") | AUTHORITY:  0 (\"\")  > 0 (\" No Access \") | LEVEL: 0 (\"\")  >  4 (\" Guard \") | MODULE: 0 (\"\")  >  10120 (\" Devices \") | AUTHORITY:  0 (\"\")  > 0 (\" No Access \") | LEVEL: 0 (\"\")  >  4 (\" Guard \") | MODULE: 0 (\"\")  >  10140 (\" User Account : audit trail \") | AUTHORITY:  0 (\"\")  > 0 (\" No Access \") | LEVEL: 0 (\"\")  >  4 (\" Guard \") | MODULE: 0 (\"\")  >  10160 (\" Brute Force Login Attempt \") | AUTHORITY:  0 (\"\")  > 0 (\" No Access \") | LEVEL: 0 (\"\")  >  4 (\" Guard \") | MODULE: 0 (\"\")  >  10180 (\" Bruteforce IP \") | AUTHORITY:  0 (\"\")  > 0 (\" No Access \") | LEVEL: 0 (\"\")  >  4 (\" Guard \") | MODULE: 0 (\"\")  >  15010 (\" Addon: Group License \") | AUTHORITY:  0 (\"\")  > 0 (\" No Access \")','2021-01-19 10:51:03.040848','Mozilla/5.0 (Windows NT 6.1; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/86.0.4240.198 Safari/537.36'),(244,'175.176.90.255',1,0,3,0,0,10080,478,0,'add/edit Access rights record','LEVEL: 0 (\"\")  >  4 (\" Guard \") | MODULE: 0 (\"\")  >  10040 (\" User Account : level \") | AUTHORITY:  0 (\"\")  > 0 (\" No Access \") | LEVEL: 0 (\"\")  >  4 (\" Guard \") | MODULE: 0 (\"\")  >  10060 (\" User Account : member \") | AUTHORITY:  0 (\"\")  > 0 (\" No Access \") | LEVEL: 0 (\"\")  >  4 (\" Guard \") | MODULE: 0 (\"\")  >  10070 (\" User Account : group \") | AUTHORITY:  0 (\"\")  > 0 (\" No Access \") | LEVEL: 0 (\"\")  >  4 (\" Guard \") | MODULE: 0 (\"\")  >  10080 (\" User Account : access rights \") | AUTHORITY:  0 (\"\")  > 0 (\" No Access \") | LEVEL: 0 (\"\")  >  4 (\" Guard \") | MODULE: 0 (\"\")  >  10100 (\" Account: server \") | AUTHORITY:  0 (\"\")  > 0 (\" No Access \") | LEVEL: 0 (\"\")  >  4 (\" Guard \") | MODULE: 0 (\"\")  >  10120 (\" Devices \") | AUTHORITY:  0 (\"\")  > 0 (\" No Access \") | LEVEL: 0 (\"\")  >  4 (\" Guard \") | MODULE: 0 (\"\")  >  10140 (\" User Account : audit trail \") | AUTHORITY:  0 (\"\")  > 0 (\" No Access \") | LEVEL: 0 (\"\")  >  4 (\" Guard \") | MODULE: 0 (\"\")  >  10160 (\" Brute Force Login Attempt \") | AUTHORITY:  0 (\"\")  > 0 (\" No Access \") | LEVEL: 0 (\"\")  >  4 (\" Guard \") | MODULE: 0 (\"\")  >  10180 (\" Bruteforce IP \") | AUTHORITY:  0 (\"\")  > 0 (\" No Access \") | LEVEL: 0 (\"\")  >  4 (\" Guard \") | MODULE: 0 (\"\")  >  15010 (\" Addon: Group License \") | AUTHORITY:  0 (\"\")  > 0 (\" No Access \") | LEVEL: 0 (\"\")  >  4 (\" Guard \") | MODULE: 0 (\"\")  >  15030 (\" Addon: User License \") | AUTHORITY:  0 (\"\")  > 0 (\" No Access \")','2021-01-19 10:51:03.042923','Mozilla/5.0 (Windows NT 6.1; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/86.0.4240.198 Safari/537.36'),(245,'175.176.90.255',1,0,3,0,0,10080,479,0,'add/edit Access rights record','LEVEL: 0 (\"\")  >  4 (\" Guard \") | MODULE: 0 (\"\")  >  10040 (\" User Account : level \") | AUTHORITY:  0 (\"\")  > 0 (\" No Access \") | LEVEL: 0 (\"\")  >  4 (\" Guard \") | MODULE: 0 (\"\")  >  10060 (\" User Account : member \") | AUTHORITY:  0 (\"\")  > 0 (\" No Access \") | LEVEL: 0 (\"\")  >  4 (\" Guard \") | MODULE: 0 (\"\")  >  10070 (\" User Account : group \") | AUTHORITY:  0 (\"\")  > 0 (\" No Access \") | LEVEL: 0 (\"\")  >  4 (\" Guard \") | MODULE: 0 (\"\")  >  10080 (\" User Account : access rights \") | AUTHORITY:  0 (\"\")  > 0 (\" No Access \") | LEVEL: 0 (\"\")  >  4 (\" Guard \") | MODULE: 0 (\"\")  >  10100 (\" Account: server \") | AUTHORITY:  0 (\"\")  > 0 (\" No Access \") | LEVEL: 0 (\"\")  >  4 (\" Guard \") | MODULE: 0 (\"\")  >  10120 (\" Devices \") | AUTHORITY:  0 (\"\")  > 0 (\" No Access \") | LEVEL: 0 (\"\")  >  4 (\" Guard \") | MODULE: 0 (\"\")  >  10140 (\" User Account : audit trail \") | AUTHORITY:  0 (\"\")  > 0 (\" No Access \") | LEVEL: 0 (\"\")  >  4 (\" Guard \") | MODULE: 0 (\"\")  >  10160 (\" Brute Force Login Attempt \") | AUTHORITY:  0 (\"\")  > 0 (\" No Access \") | LEVEL: 0 (\"\")  >  4 (\" Guard \") | MODULE: 0 (\"\")  >  10180 (\" Bruteforce IP \") | AUTHORITY:  0 (\"\")  > 0 (\" No Access \") | LEVEL: 0 (\"\")  >  4 (\" Guard \") | MODULE: 0 (\"\")  >  15010 (\" Addon: Group License \") | AUTHORITY:  0 (\"\")  > 0 (\" No Access \") | LEVEL: 0 (\"\")  >  4 (\" Guard \") | MODULE: 0 (\"\")  >  15030 (\" Addon: User License \") | AUTHORITY:  0 (\"\")  > 0 (\" No Access \") | LEVEL: 0 (\"\")  >  4 (\" Guard \") | MODULE: 0 (\"\")  >  15050 (\" Addon: Queuing \") | AUTHORITY:  0 (\"\")  > 0 (\" No Access \")','2021-01-19 10:51:03.058714','Mozilla/5.0 (Windows NT 6.1; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/86.0.4240.198 Safari/537.36'),(246,'175.176.90.255',1,0,3,0,0,10080,480,0,'add/edit Access rights record','LEVEL: 0 (\"\")  >  4 (\" Guard \") | MODULE: 0 (\"\")  >  10040 (\" User Account : level \") | AUTHORITY:  0 (\"\")  > 0 (\" No Access \") | LEVEL: 0 (\"\")  >  4 (\" Guard \") | MODULE: 0 (\"\")  >  10060 (\" User Account : member \") | AUTHORITY:  0 (\"\")  > 0 (\" No Access \") | LEVEL: 0 (\"\")  >  4 (\" Guard \") | MODULE: 0 (\"\")  >  10070 (\" User Account : group \") | AUTHORITY:  0 (\"\")  > 0 (\" No Access \") | LEVEL: 0 (\"\")  >  4 (\" Guard \") | MODULE: 0 (\"\")  >  10080 (\" User Account : access rights \") | AUTHORITY:  0 (\"\")  > 0 (\" No Access \") | LEVEL: 0 (\"\")  >  4 (\" Guard \") | MODULE: 0 (\"\")  >  10100 (\" Account: server \") | AUTHORITY:  0 (\"\")  > 0 (\" No Access \") | LEVEL: 0 (\"\")  >  4 (\" Guard \") | MODULE: 0 (\"\")  >  10120 (\" Devices \") | AUTHORITY:  0 (\"\")  > 0 (\" No Access \") | LEVEL: 0 (\"\")  >  4 (\" Guard \") | MODULE: 0 (\"\")  >  10140 (\" User Account : audit trail \") | AUTHORITY:  0 (\"\")  > 0 (\" No Access \") | LEVEL: 0 (\"\")  >  4 (\" Guard \") | MODULE: 0 (\"\")  >  10160 (\" Brute Force Login Attempt \") | AUTHORITY:  0 (\"\")  > 0 (\" No Access \") | LEVEL: 0 (\"\")  >  4 (\" Guard \") | MODULE: 0 (\"\")  >  10180 (\" Bruteforce IP \") | AUTHORITY:  0 (\"\")  > 0 (\" No Access \") | LEVEL: 0 (\"\")  >  4 (\" Guard \") | MODULE: 0 (\"\")  >  15010 (\" Addon: Group License \") | AUTHORITY:  0 (\"\")  > 0 (\" No Access \") | LEVEL: 0 (\"\")  >  4 (\" Guard \") | MODULE: 0 (\"\")  >  15030 (\" Addon: User License \") | AUTHORITY:  0 (\"\")  > 0 (\" No Access \") | LEVEL: 0 (\"\")  >  4 (\" Guard \") | MODULE: 0 (\"\")  >  15050 (\" Addon: Queuing \") | AUTHORITY:  0 (\"\")  > 0 (\" No Access \") | LEVEL: 0 (\"\")  >  4 (\" Guard \") | MODULE: 0 (\"\")  >  15070 (\" Addon: Resource \") | AUTHORITY:  0 (\"\")  > 0 (\" No Access \")','2021-01-19 10:51:03.063208','Mozilla/5.0 (Windows NT 6.1; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/86.0.4240.198 Safari/537.36'),(247,'175.176.90.255',1,0,3,0,0,10080,481,0,'add/edit Access rights record','LEVEL: 0 (\"\")  >  4 (\" Guard \") | MODULE: 0 (\"\")  >  10040 (\" User Account : level \") | AUTHORITY:  0 (\"\")  > 0 (\" No Access \") | LEVEL: 0 (\"\")  >  4 (\" Guard \") | MODULE: 0 (\"\")  >  10060 (\" User Account : member \") | AUTHORITY:  0 (\"\")  > 0 (\" No Access \") | LEVEL: 0 (\"\")  >  4 (\" Guard \") | MODULE: 0 (\"\")  >  10070 (\" User Account : group \") | AUTHORITY:  0 (\"\")  > 0 (\" No Access \") | LEVEL: 0 (\"\")  >  4 (\" Guard \") | MODULE: 0 (\"\")  >  10080 (\" User Account : access rights \") | AUTHORITY:  0 (\"\")  > 0 (\" No Access \") | LEVEL: 0 (\"\")  >  4 (\" Guard \") | MODULE: 0 (\"\")  >  10100 (\" Account: server \") | AUTHORITY:  0 (\"\")  > 0 (\" No Access \") | LEVEL: 0 (\"\")  >  4 (\" Guard \") | MODULE: 0 (\"\")  >  10120 (\" Devices \") | AUTHORITY:  0 (\"\")  > 0 (\" No Access \") | LEVEL: 0 (\"\")  >  4 (\" Guard \") | MODULE: 0 (\"\")  >  10140 (\" User Account : audit trail \") | AUTHORITY:  0 (\"\")  > 0 (\" No Access \") | LEVEL: 0 (\"\")  >  4 (\" Guard \") | MODULE: 0 (\"\")  >  10160 (\" Brute Force Login Attempt \") | AUTHORITY:  0 (\"\")  > 0 (\" No Access \") | LEVEL: 0 (\"\")  >  4 (\" Guard \") | MODULE: 0 (\"\")  >  10180 (\" Bruteforce IP \") | AUTHORITY:  0 (\"\")  > 0 (\" No Access \") | LEVEL: 0 (\"\")  >  4 (\" Guard \") | MODULE: 0 (\"\")  >  15010 (\" Addon: Group License \") | AUTHORITY:  0 (\"\")  > 0 (\" No Access \") | LEVEL: 0 (\"\")  >  4 (\" Guard \") | MODULE: 0 (\"\")  >  15030 (\" Addon: User License \") | AUTHORITY:  0 (\"\")  > 0 (\" No Access \") | LEVEL: 0 (\"\")  >  4 (\" Guard \") | MODULE: 0 (\"\")  >  15050 (\" Addon: Queuing \") | AUTHORITY:  0 (\"\")  > 0 (\" No Access \") | LEVEL: 0 (\"\")  >  4 (\" Guard \") | MODULE: 0 (\"\")  >  15070 (\" Addon: Resource \") | AUTHORITY:  0 (\"\")  > 0 (\" No Access \") | LEVEL: 0 (\"\")  >  4 (\" Guard \") | MODULE: 0 (\"\")  >  20010 (\" Settings : religion \") | AUTHORITY:  0 (\"\")  > 0 (\" No Access \")','2021-01-19 10:51:03.065331','Mozilla/5.0 (Windows NT 6.1; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/86.0.4240.198 Safari/537.36'),(248,'175.176.90.255',1,0,3,0,0,10080,482,0,'add/edit Access rights record','LEVEL: 0 (\"\")  >  4 (\" Guard \") | MODULE: 0 (\"\")  >  10040 (\" User Account : level \") | AUTHORITY:  0 (\"\")  > 0 (\" No Access \") | LEVEL: 0 (\"\")  >  4 (\" Guard \") | MODULE: 0 (\"\")  >  10060 (\" User Account : member \") | AUTHORITY:  0 (\"\")  > 0 (\" No Access \") | LEVEL: 0 (\"\")  >  4 (\" Guard \") | MODULE: 0 (\"\")  >  10070 (\" User Account : group \") | AUTHORITY:  0 (\"\")  > 0 (\" No Access \") | LEVEL: 0 (\"\")  >  4 (\" Guard \") | MODULE: 0 (\"\")  >  10080 (\" User Account : access rights \") | AUTHORITY:  0 (\"\")  > 0 (\" No Access \") | LEVEL: 0 (\"\")  >  4 (\" Guard \") | MODULE: 0 (\"\")  >  10100 (\" Account: server \") | AUTHORITY:  0 (\"\")  > 0 (\" No Access \") | LEVEL: 0 (\"\")  >  4 (\" Guard \") | MODULE: 0 (\"\")  >  10120 (\" Devices \") | AUTHORITY:  0 (\"\")  > 0 (\" No Access \") | LEVEL: 0 (\"\")  >  4 (\" Guard \") | MODULE: 0 (\"\")  >  10140 (\" User Account : audit trail \") | AUTHORITY:  0 (\"\")  > 0 (\" No Access \") | LEVEL: 0 (\"\")  >  4 (\" Guard \") | MODULE: 0 (\"\")  >  10160 (\" Brute Force Login Attempt \") | AUTHORITY:  0 (\"\")  > 0 (\" No Access \") | LEVEL: 0 (\"\")  >  4 (\" Guard \") | MODULE: 0 (\"\")  >  10180 (\" Bruteforce IP \") | AUTHORITY:  0 (\"\")  > 0 (\" No Access \") | LEVEL: 0 (\"\")  >  4 (\" Guard \") | MODULE: 0 (\"\")  >  15010 (\" Addon: Group License \") | AUTHORITY:  0 (\"\")  > 0 (\" No Access \") | LEVEL: 0 (\"\")  >  4 (\" Guard \") | MODULE: 0 (\"\")  >  15030 (\" Addon: User License \") | AUTHORITY:  0 (\"\")  > 0 (\" No Access \") | LEVEL: 0 (\"\")  >  4 (\" Guard \") | MODULE: 0 (\"\")  >  15050 (\" Addon: Queuing \") | AUTHORITY:  0 (\"\")  > 0 (\" No Access \") | LEVEL: 0 (\"\")  >  4 (\" Guard \") | MODULE: 0 (\"\")  >  15070 (\" Addon: Resource \") | AUTHORITY:  0 (\"\")  > 0 (\" No Access \") | LEVEL: 0 (\"\")  >  4 (\" Guard \") | MODULE: 0 (\"\")  >  20010 (\" Settings : religion \") | AUTHORITY:  0 (\"\")  > 0 (\" No Access \") | LEVEL: 0 (\"\")  >  4 (\" Guard \") | MODULE: 0 (\"\")  >  20030 (\" Settings: Nationality \") | AUTHORITY:  0 (\"\")  > 0 (\" No Access \")','2021-01-19 10:51:03.067405','Mozilla/5.0 (Windows NT 6.1; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/86.0.4240.198 Safari/537.36'),(249,'175.176.90.255',1,0,3,0,0,10080,483,0,'add/edit Access rights record','LEVEL: 0 (\"\")  >  4 (\" Guard \") | MODULE: 0 (\"\")  >  10040 (\" User Account : level \") | AUTHORITY:  0 (\"\")  > 0 (\" No Access \") | LEVEL: 0 (\"\")  >  4 (\" Guard \") | MODULE: 0 (\"\")  >  10060 (\" User Account : member \") | AUTHORITY:  0 (\"\")  > 0 (\" No Access \") | LEVEL: 0 (\"\")  >  4 (\" Guard \") | MODULE: 0 (\"\")  >  10070 (\" User Account : group \") | AUTHORITY:  0 (\"\")  > 0 (\" No Access \") | LEVEL: 0 (\"\")  >  4 (\" Guard \") | MODULE: 0 (\"\")  >  10080 (\" User Account : access rights \") | AUTHORITY:  0 (\"\")  > 0 (\" No Access \") | LEVEL: 0 (\"\")  >  4 (\" Guard \") | MODULE: 0 (\"\")  >  10100 (\" Account: server \") | AUTHORITY:  0 (\"\")  > 0 (\" No Access \") | LEVEL: 0 (\"\")  >  4 (\" Guard \") | MODULE: 0 (\"\")  >  10120 (\" Devices \") | AUTHORITY:  0 (\"\")  > 0 (\" No Access \") | LEVEL: 0 (\"\")  >  4 (\" Guard \") | MODULE: 0 (\"\")  >  10140 (\" User Account : audit trail \") | AUTHORITY:  0 (\"\")  > 0 (\" No Access \") | LEVEL: 0 (\"\")  >  4 (\" Guard \") | MODULE: 0 (\"\")  >  10160 (\" Brute Force Login Attempt \") | AUTHORITY:  0 (\"\")  > 0 (\" No Access \") | LEVEL: 0 (\"\")  >  4 (\" Guard \") | MODULE: 0 (\"\")  >  10180 (\" Bruteforce IP \") | AUTHORITY:  0 (\"\")  > 0 (\" No Access \") | LEVEL: 0 (\"\")  >  4 (\" Guard \") | MODULE: 0 (\"\")  >  15010 (\" Addon: Group License \") | AUTHORITY:  0 (\"\")  > 0 (\" No Access \") | LEVEL: 0 (\"\")  >  4 (\" Guard \") | MODULE: 0 (\"\")  >  15030 (\" Addon: User License \") | AUTHORITY:  0 (\"\")  > 0 (\" No Access \") | LEVEL: 0 (\"\")  >  4 (\" Guard \") | MODULE: 0 (\"\")  >  15050 (\" Addon: Queuing \") | AUTHORITY:  0 (\"\")  > 0 (\" No Access \") | LEVEL: 0 (\"\")  >  4 (\" Guard \") | MODULE: 0 (\"\")  >  15070 (\" Addon: Resource \") | AUTHORITY:  0 (\"\")  > 0 (\" No Access \") | LEVEL: 0 (\"\")  >  4 (\" Guard \") | MODULE: 0 (\"\")  >  20010 (\" Settings : religion \") | AUTHORITY:  0 (\"\")  > 0 (\" No Access \") | LEVEL: 0 (\"\")  >  4 (\" Guard \") | MODULE: 0 (\"\")  >  20030 (\" Settings: Nationality \") | AUTHORITY:  0 (\"\")  > 0 (\" No Access \") | LEVEL: 0 (\"\")  >  4 (\" Guard \") | MODULE: 0 (\"\")  >  20050 (\" Settings: Address - Country \") | AUTHORITY:  0 (\"\")  > 0 (\" No Access \")','2021-01-19 10:51:03.069493','Mozilla/5.0 (Windows NT 6.1; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/86.0.4240.198 Safari/537.36'),(250,'175.176.90.255',1,0,3,0,0,10080,484,0,'add/edit Access rights record','LEVEL: 0 (\"\")  >  4 (\" Guard \") | MODULE: 0 (\"\")  >  10040 (\" User Account : level \") | AUTHORITY:  0 (\"\")  > 0 (\" No Access \") | LEVEL: 0 (\"\")  >  4 (\" Guard \") | MODULE: 0 (\"\")  >  10060 (\" User Account : member \") | AUTHORITY:  0 (\"\")  > 0 (\" No Access \") | LEVEL: 0 (\"\")  >  4 (\" Guard \") | MODULE: 0 (\"\")  >  10070 (\" User Account : group \") | AUTHORITY:  0 (\"\")  > 0 (\" No Access \") | LEVEL: 0 (\"\")  >  4 (\" Guard \") | MODULE: 0 (\"\")  >  10080 (\" User Account : access rights \") | AUTHORITY:  0 (\"\")  > 0 (\" No Access \") | LEVEL: 0 (\"\")  >  4 (\" Guard \") | MODULE: 0 (\"\")  >  10100 (\" Account: server \") | AUTHORITY:  0 (\"\")  > 0 (\" No Access \") | LEVEL: 0 (\"\")  >  4 (\" Guard \") | MODULE: 0 (\"\")  >  10120 (\" Devices \") | AUTHORITY:  0 (\"\")  > 0 (\" No Access \") | LEVEL: 0 (\"\")  >  4 (\" Guard \") | MODULE: 0 (\"\")  >  10140 (\" User Account : audit trail \") | AUTHORITY:  0 (\"\")  > 0 (\" No Access \") | LEVEL: 0 (\"\")  >  4 (\" Guard \") | MODULE: 0 (\"\")  >  10160 (\" Brute Force Login Attempt \") | AUTHORITY:  0 (\"\")  > 0 (\" No Access \") | LEVEL: 0 (\"\")  >  4 (\" Guard \") | MODULE: 0 (\"\")  >  10180 (\" Bruteforce IP \") | AUTHORITY:  0 (\"\")  > 0 (\" No Access \") | LEVEL: 0 (\"\")  >  4 (\" Guard \") | MODULE: 0 (\"\")  >  15010 (\" Addon: Group License \") | AUTHORITY:  0 (\"\")  > 0 (\" No Access \") | LEVEL: 0 (\"\")  >  4 (\" Guard \") | MODULE: 0 (\"\")  >  15030 (\" Addon: User License \") | AUTHORITY:  0 (\"\")  > 0 (\" No Access \") | LEVEL: 0 (\"\")  >  4 (\" Guard \") | MODULE: 0 (\"\")  >  15050 (\" Addon: Queuing \") | AUTHORITY:  0 (\"\")  > 0 (\" No Access \") | LEVEL: 0 (\"\")  >  4 (\" Guard \") | MODULE: 0 (\"\")  >  15070 (\" Addon: Resource \") | AUTHORITY:  0 (\"\")  > 0 (\" No Access \") | LEVEL: 0 (\"\")  >  4 (\" Guard \") | MODULE: 0 (\"\")  >  20010 (\" Settings : religion \") | AUTHORITY:  0 (\"\")  > 0 (\" No Access \") | LEVEL: 0 (\"\")  >  4 (\" Guard \") | MODULE: 0 (\"\")  >  20030 (\" Settings: Nationality \") | AUTHORITY:  0 (\"\")  > 0 (\" No Access \") | LEVEL: 0 (\"\")  >  4 (\" Guard \") | MODULE: 0 (\"\")  >  20050 (\" Settings: Address - Country \") | AUTHORITY:  0 (\"\")  > 0 (\" No Access \") | LEVEL: 0 (\"\")  >  4 (\" Guard \") | MODULE: 0 (\"\")  >  20070 (\" Settings: Address - Region \") | AUTHORITY:  0 (\"\")  > 0 (\" No Access \")','2021-01-19 10:51:03.071491','Mozilla/5.0 (Windows NT 6.1; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/86.0.4240.198 Safari/537.36'),(251,'175.176.90.255',1,0,3,0,0,10080,485,0,'add/edit Access rights record','LEVEL: 0 (\"\")  >  4 (\" Guard \") | MODULE: 0 (\"\")  >  10040 (\" User Account : level \") | AUTHORITY:  0 (\"\")  > 0 (\" No Access \") | LEVEL: 0 (\"\")  >  4 (\" Guard \") | MODULE: 0 (\"\")  >  10060 (\" User Account : member \") | AUTHORITY:  0 (\"\")  > 0 (\" No Access \") | LEVEL: 0 (\"\")  >  4 (\" Guard \") | MODULE: 0 (\"\")  >  10070 (\" User Account : group \") | AUTHORITY:  0 (\"\")  > 0 (\" No Access \") | LEVEL: 0 (\"\")  >  4 (\" Guard \") | MODULE: 0 (\"\")  >  10080 (\" User Account : access rights \") | AUTHORITY:  0 (\"\")  > 0 (\" No Access \") | LEVEL: 0 (\"\")  >  4 (\" Guard \") | MODULE: 0 (\"\")  >  10100 (\" Account: server \") | AUTHORITY:  0 (\"\")  > 0 (\" No Access \") | LEVEL: 0 (\"\")  >  4 (\" Guard \") | MODULE: 0 (\"\")  >  10120 (\" Devices \") | AUTHORITY:  0 (\"\")  > 0 (\" No Access \") | LEVEL: 0 (\"\")  >  4 (\" Guard \") | MODULE: 0 (\"\")  >  10140 (\" User Account : audit trail \") | AUTHORITY:  0 (\"\")  > 0 (\" No Access \") | LEVEL: 0 (\"\")  >  4 (\" Guard \") | MODULE: 0 (\"\")  >  10160 (\" Brute Force Login Attempt \") | AUTHORITY:  0 (\"\")  > 0 (\" No Access \") | LEVEL: 0 (\"\")  >  4 (\" Guard \") | MODULE: 0 (\"\")  >  10180 (\" Bruteforce IP \") | AUTHORITY:  0 (\"\")  > 0 (\" No Access \") | LEVEL: 0 (\"\")  >  4 (\" Guard \") | MODULE: 0 (\"\")  >  15010 (\" Addon: Group License \") | AUTHORITY:  0 (\"\")  > 0 (\" No Access \") | LEVEL: 0 (\"\")  >  4 (\" Guard \") | MODULE: 0 (\"\")  >  15030 (\" Addon: User License \") | AUTHORITY:  0 (\"\")  > 0 (\" No Access \") | LEVEL: 0 (\"\")  >  4 (\" Guard \") | MODULE: 0 (\"\")  >  15050 (\" Addon: Queuing \") | AUTHORITY:  0 (\"\")  > 0 (\" No Access \") | LEVEL: 0 (\"\")  >  4 (\" Guard \") | MODULE: 0 (\"\")  >  15070 (\" Addon: Resource \") | AUTHORITY:  0 (\"\")  > 0 (\" No Access \") | LEVEL: 0 (\"\")  >  4 (\" Guard \") | MODULE: 0 (\"\")  >  20010 (\" Settings : religion \") | AUTHORITY:  0 (\"\")  > 0 (\" No Access \") | LEVEL: 0 (\"\")  >  4 (\" Guard \") | MODULE: 0 (\"\")  >  20030 (\" Settings: Nationality \") | AUTHORITY:  0 (\"\")  > 0 (\" No Access \") | LEVEL: 0 (\"\")  >  4 (\" Guard \") | MODULE: 0 (\"\")  >  20050 (\" Settings: Address - Country \") | AUTHORITY:  0 (\"\")  > 0 (\" No Access \") | LEVEL: 0 (\"\")  >  4 (\" Guard \") | MODULE: 0 (\"\")  >  20070 (\" Settings: Address - Region \") | AUTHORITY:  0 (\"\")  > 0 (\" No Access \") | LEVEL: 0 (\"\")  >  4 (\" Guard \") | MODULE: 0 (\"\")  >  20090 (\" Settings: Address - Province \") | AUTHORITY:  0 (\"\")  > 0 (\" No Access \")','2021-01-19 10:51:03.073669','Mozilla/5.0 (Windows NT 6.1; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/86.0.4240.198 Safari/537.36'),(252,'175.176.90.255',1,0,3,0,0,10080,486,0,'add/edit Access rights record','LEVEL: 0 (\"\")  >  4 (\" Guard \") | MODULE: 0 (\"\")  >  10040 (\" User Account : level \") | AUTHORITY:  0 (\"\")  > 0 (\" No Access \") | LEVEL: 0 (\"\")  >  4 (\" Guard \") | MODULE: 0 (\"\")  >  10060 (\" User Account : member \") | AUTHORITY:  0 (\"\")  > 0 (\" No Access \") | LEVEL: 0 (\"\")  >  4 (\" Guard \") | MODULE: 0 (\"\")  >  10070 (\" User Account : group \") | AUTHORITY:  0 (\"\")  > 0 (\" No Access \") | LEVEL: 0 (\"\")  >  4 (\" Guard \") | MODULE: 0 (\"\")  >  10080 (\" User Account : access rights \") | AUTHORITY:  0 (\"\")  > 0 (\" No Access \") | LEVEL: 0 (\"\")  >  4 (\" Guard \") | MODULE: 0 (\"\")  >  10100 (\" Account: server \") | AUTHORITY:  0 (\"\")  > 0 (\" No Access \") | LEVEL: 0 (\"\")  >  4 (\" Guard \") | MODULE: 0 (\"\")  >  10120 (\" Devices \") | AUTHORITY:  0 (\"\")  > 0 (\" No Access \") | LEVEL: 0 (\"\")  >  4 (\" Guard \") | MODULE: 0 (\"\")  >  10140 (\" User Account : audit trail \") | AUTHORITY:  0 (\"\")  > 0 (\" No Access \") | LEVEL: 0 (\"\")  >  4 (\" Guard \") | MODULE: 0 (\"\")  >  10160 (\" Brute Force Login Attempt \") | AUTHORITY:  0 (\"\")  > 0 (\" No Access \") | LEVEL: 0 (\"\")  >  4 (\" Guard \") | MODULE: 0 (\"\")  >  10180 (\" Bruteforce IP \") | AUTHORITY:  0 (\"\")  > 0 (\" No Access \") | LEVEL: 0 (\"\")  >  4 (\" Guard \") | MODULE: 0 (\"\")  >  15010 (\" Addon: Group License \") | AUTHORITY:  0 (\"\")  > 0 (\" No Access \") | LEVEL: 0 (\"\")  >  4 (\" Guard \") | MODULE: 0 (\"\")  >  15030 (\" Addon: User License \") | AUTHORITY:  0 (\"\")  > 0 (\" No Access \") | LEVEL: 0 (\"\")  >  4 (\" Guard \") | MODULE: 0 (\"\")  >  15050 (\" Addon: Queuing \") | AUTHORITY:  0 (\"\")  > 0 (\" No Access \") | LEVEL: 0 (\"\")  >  4 (\" Guard \") | MODULE: 0 (\"\")  >  15070 (\" Addon: Resource \") | AUTHORITY:  0 (\"\")  > 0 (\" No Access \") | LEVEL: 0 (\"\")  >  4 (\" Guard \") | MODULE: 0 (\"\")  >  20010 (\" Settings : religion \") | AUTHORITY:  0 (\"\")  > 0 (\" No Access \") | LEVEL: 0 (\"\")  >  4 (\" Guard \") | MODULE: 0 (\"\")  >  20030 (\" Settings: Nationality \") | AUTHORITY:  0 (\"\")  > 0 (\" No Access \") | LEVEL: 0 (\"\")  >  4 (\" Guard \") | MODULE: 0 (\"\")  >  20050 (\" Settings: Address - Country \") | AUTHORITY:  0 (\"\")  > 0 (\" No Access \") | LEVEL: 0 (\"\")  >  4 (\" Guard \") | MODULE: 0 (\"\")  >  20070 (\" Settings: Address - Region \") | AUTHORITY:  0 (\"\")  > 0 (\" No Access \") | LEVEL: 0 (\"\")  >  4 (\" Guard \") | MODULE: 0 (\"\")  >  20090 (\" Settings: Address - Province \") | AUTHORITY:  0 (\"\")  > 0 (\" No Access \") | LEVEL: 0 (\"\")  >  4 (\" Guard \") | MODULE: 0 (\"\")  >  20110 (\" Settings: Address - Municipality \") | AUTHORITY:  0 (\"\")  > 0 (\" No Access \")','2021-01-19 10:51:03.076709','Mozilla/5.0 (Windows NT 6.1; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/86.0.4240.198 Safari/537.36'),(253,'175.176.90.255',1,0,3,0,0,10080,487,0,'add/edit Access rights record','LEVEL: 0 (\"\")  >  4 (\" Guard \") | MODULE: 0 (\"\")  >  10040 (\" User Account : level \") | AUTHORITY:  0 (\"\")  > 0 (\" No Access \") | LEVEL: 0 (\"\")  >  4 (\" Guard \") | MODULE: 0 (\"\")  >  10060 (\" User Account : member \") | AUTHORITY:  0 (\"\")  > 0 (\" No Access \") | LEVEL: 0 (\"\")  >  4 (\" Guard \") | MODULE: 0 (\"\")  >  10070 (\" User Account : group \") | AUTHORITY:  0 (\"\")  > 0 (\" No Access \") | LEVEL: 0 (\"\")  >  4 (\" Guard \") | MODULE: 0 (\"\")  >  10080 (\" User Account : access rights \") | AUTHORITY:  0 (\"\")  > 0 (\" No Access \") | LEVEL: 0 (\"\")  >  4 (\" Guard \") | MODULE: 0 (\"\")  >  10100 (\" Account: server \") | AUTHORITY:  0 (\"\")  > 0 (\" No Access \") | LEVEL: 0 (\"\")  >  4 (\" Guard \") | MODULE: 0 (\"\")  >  10120 (\" Devices \") | AUTHORITY:  0 (\"\")  > 0 (\" No Access \") | LEVEL: 0 (\"\")  >  4 (\" Guard \") | MODULE: 0 (\"\")  >  10140 (\" User Account : audit trail \") | AUTHORITY:  0 (\"\")  > 0 (\" No Access \") | LEVEL: 0 (\"\")  >  4 (\" Guard \") | MODULE: 0 (\"\")  >  10160 (\" Brute Force Login Attempt \") | AUTHORITY:  0 (\"\")  > 0 (\" No Access \") | LEVEL: 0 (\"\")  >  4 (\" Guard \") | MODULE: 0 (\"\")  >  10180 (\" Bruteforce IP \") | AUTHORITY:  0 (\"\")  > 0 (\" No Access \") | LEVEL: 0 (\"\")  >  4 (\" Guard \") | MODULE: 0 (\"\")  >  15010 (\" Addon: Group License \") | AUTHORITY:  0 (\"\")  > 0 (\" No Access \") | LEVEL: 0 (\"\")  >  4 (\" Guard \") | MODULE: 0 (\"\")  >  15030 (\" Addon: User License \") | AUTHORITY:  0 (\"\")  > 0 (\" No Access \") | LEVEL: 0 (\"\")  >  4 (\" Guard \") | MODULE: 0 (\"\")  >  15050 (\" Addon: Queuing \") | AUTHORITY:  0 (\"\")  > 0 (\" No Access \") | LEVEL: 0 (\"\")  >  4 (\" Guard \") | MODULE: 0 (\"\")  >  15070 (\" Addon: Resource \") | AUTHORITY:  0 (\"\")  > 0 (\" No Access \") | LEVEL: 0 (\"\")  >  4 (\" Guard \") | MODULE: 0 (\"\")  >  20010 (\" Settings : religion \") | AUTHORITY:  0 (\"\")  > 0 (\" No Access \") | LEVEL: 0 (\"\")  >  4 (\" Guard \") | MODULE: 0 (\"\")  >  20030 (\" Settings: Nationality \") | AUTHORITY:  0 (\"\")  > 0 (\" No Access \") | LEVEL: 0 (\"\")  >  4 (\" Guard \") | MODULE: 0 (\"\")  >  20050 (\" Settings: Address - Country \") | AUTHORITY:  0 (\"\")  > 0 (\" No Access \") | LEVEL: 0 (\"\")  >  4 (\" Guard \") | MODULE: 0 (\"\")  >  20070 (\" Settings: Address - Region \") | AUTHORITY:  0 (\"\")  > 0 (\" No Access \") | LEVEL: 0 (\"\")  >  4 (\" Guard \") | MODULE: 0 (\"\")  >  20090 (\" Settings: Address - Province \") | AUTHORITY:  0 (\"\")  > 0 (\" No Access \") | LEVEL: 0 (\"\")  >  4 (\" Guard \") | MODULE: 0 (\"\")  >  20110 (\" Settings: Address - Municipality \") | AUTHORITY:  0 (\"\")  > 0 (\" No Access \") | LEVEL: 0 (\"\")  >  4 (\" Guard \") | MODULE: 0 (\"\")  >  21010 (\" Department \") | AUTHORITY:  0 (\"\")  > 0 (\" No Access \")','2021-01-19 10:51:03.078841','Mozilla/5.0 (Windows NT 6.1; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/86.0.4240.198 Safari/537.36'),(254,'175.176.90.255',1,0,3,0,0,10080,488,0,'add/edit Access rights record','LEVEL: 0 (\"\")  >  4 (\" Guard \") | MODULE: 0 (\"\")  >  10040 (\" User Account : level \") | AUTHORITY:  0 (\"\")  > 0 (\" No Access \") | LEVEL: 0 (\"\")  >  4 (\" Guard \") | MODULE: 0 (\"\")  >  10060 (\" User Account : member \") | AUTHORITY:  0 (\"\")  > 0 (\" No Access \") | LEVEL: 0 (\"\")  >  4 (\" Guard \") | MODULE: 0 (\"\")  >  10070 (\" User Account : group \") | AUTHORITY:  0 (\"\")  > 0 (\" No Access \") | LEVEL: 0 (\"\")  >  4 (\" Guard \") | MODULE: 0 (\"\")  >  10080 (\" User Account : access rights \") | AUTHORITY:  0 (\"\")  > 0 (\" No Access \") | LEVEL: 0 (\"\")  >  4 (\" Guard \") | MODULE: 0 (\"\")  >  10100 (\" Account: server \") | AUTHORITY:  0 (\"\")  > 0 (\" No Access \") | LEVEL: 0 (\"\")  >  4 (\" Guard \") | MODULE: 0 (\"\")  >  10120 (\" Devices \") | AUTHORITY:  0 (\"\")  > 0 (\" No Access \") | LEVEL: 0 (\"\")  >  4 (\" Guard \") | MODULE: 0 (\"\")  >  10140 (\" User Account : audit trail \") | AUTHORITY:  0 (\"\")  > 0 (\" No Access \") | LEVEL: 0 (\"\")  >  4 (\" Guard \") | MODULE: 0 (\"\")  >  10160 (\" Brute Force Login Attempt \") | AUTHORITY:  0 (\"\")  > 0 (\" No Access \") | LEVEL: 0 (\"\")  >  4 (\" Guard \") | MODULE: 0 (\"\")  >  10180 (\" Bruteforce IP \") | AUTHORITY:  0 (\"\")  > 0 (\" No Access \") | LEVEL: 0 (\"\")  >  4 (\" Guard \") | MODULE: 0 (\"\")  >  15010 (\" Addon: Group License \") | AUTHORITY:  0 (\"\")  > 0 (\" No Access \") | LEVEL: 0 (\"\")  >  4 (\" Guard \") | MODULE: 0 (\"\")  >  15030 (\" Addon: User License \") | AUTHORITY:  0 (\"\")  > 0 (\" No Access \") | LEVEL: 0 (\"\")  >  4 (\" Guard \") | MODULE: 0 (\"\")  >  15050 (\" Addon: Queuing \") | AUTHORITY:  0 (\"\")  > 0 (\" No Access \") | LEVEL: 0 (\"\")  >  4 (\" Guard \") | MODULE: 0 (\"\")  >  15070 (\" Addon: Resource \") | AUTHORITY:  0 (\"\")  > 0 (\" No Access \") | LEVEL: 0 (\"\")  >  4 (\" Guard \") | MODULE: 0 (\"\")  >  20010 (\" Settings : religion \") | AUTHORITY:  0 (\"\")  > 0 (\" No Access \") | LEVEL: 0 (\"\")  >  4 (\" Guard \") | MODULE: 0 (\"\")  >  20030 (\" Settings: Nationality \") | AUTHORITY:  0 (\"\")  > 0 (\" No Access \") | LEVEL: 0 (\"\")  >  4 (\" Guard \") | MODULE: 0 (\"\")  >  20050 (\" Settings: Address - Country \") | AUTHORITY:  0 (\"\")  > 0 (\" No Access \") | LEVEL: 0 (\"\")  >  4 (\" Guard \") | MODULE: 0 (\"\")  >  20070 (\" Settings: Address - Region \") | AUTHORITY:  0 (\"\")  > 0 (\" No Access \") | LEVEL: 0 (\"\")  >  4 (\" Guard \") | MODULE: 0 (\"\")  >  20090 (\" Settings: Address - Province \") | AUTHORITY:  0 (\"\")  > 0 (\" No Access \") | LEVEL: 0 (\"\")  >  4 (\" Guard \") | MODULE: 0 (\"\")  >  20110 (\" Settings: Address - Municipality \") | AUTHORITY:  0 (\"\")  > 0 (\" No Access \") | LEVEL: 0 (\"\")  >  4 (\" Guard \") | MODULE: 0 (\"\")  >  21010 (\" Department \") | AUTHORITY:  0 (\"\")  > 0 (\" No Access \") | LEVEL: 0 (\"\")  >  4 (\" Guard \") | MODULE: 0 (\"\")  >  21030 (\" Section \") | AUTHORITY:  0 (\"\")  > 0 (\" No Access \")','2021-01-19 10:51:03.080971','Mozilla/5.0 (Windows NT 6.1; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/86.0.4240.198 Safari/537.36'),(255,'175.176.90.255',1,0,3,0,0,10080,489,0,'add/edit Access rights record','LEVEL: 0 (\"\")  >  4 (\" Guard \") | MODULE: 0 (\"\")  >  10040 (\" User Account : level \") | AUTHORITY:  0 (\"\")  > 0 (\" No Access \") | LEVEL: 0 (\"\")  >  4 (\" Guard \") | MODULE: 0 (\"\")  >  10060 (\" User Account : member \") | AUTHORITY:  0 (\"\")  > 0 (\" No Access \") | LEVEL: 0 (\"\")  >  4 (\" Guard \") | MODULE: 0 (\"\")  >  10070 (\" User Account : group \") | AUTHORITY:  0 (\"\")  > 0 (\" No Access \") | LEVEL: 0 (\"\")  >  4 (\" Guard \") | MODULE: 0 (\"\")  >  10080 (\" User Account : access rights \") | AUTHORITY:  0 (\"\")  > 0 (\" No Access \") | LEVEL: 0 (\"\")  >  4 (\" Guard \") | MODULE: 0 (\"\")  >  10100 (\" Account: server \") | AUTHORITY:  0 (\"\")  > 0 (\" No Access \") | LEVEL: 0 (\"\")  >  4 (\" Guard \") | MODULE: 0 (\"\")  >  10120 (\" Devices \") | AUTHORITY:  0 (\"\")  > 0 (\" No Access \") | LEVEL: 0 (\"\")  >  4 (\" Guard \") | MODULE: 0 (\"\")  >  10140 (\" User Account : audit trail \") | AUTHORITY:  0 (\"\")  > 0 (\" No Access \") | LEVEL: 0 (\"\")  >  4 (\" Guard \") | MODULE: 0 (\"\")  >  10160 (\" Brute Force Login Attempt \") | AUTHORITY:  0 (\"\")  > 0 (\" No Access \") | LEVEL: 0 (\"\")  >  4 (\" Guard \") | MODULE: 0 (\"\")  >  10180 (\" Bruteforce IP \") | AUTHORITY:  0 (\"\")  > 0 (\" No Access \") | LEVEL: 0 (\"\")  >  4 (\" Guard \") | MODULE: 0 (\"\")  >  15010 (\" Addon: Group License \") | AUTHORITY:  0 (\"\")  > 0 (\" No Access \") | LEVEL: 0 (\"\")  >  4 (\" Guard \") | MODULE: 0 (\"\")  >  15030 (\" Addon: User License \") | AUTHORITY:  0 (\"\")  > 0 (\" No Access \") | LEVEL: 0 (\"\")  >  4 (\" Guard \") | MODULE: 0 (\"\")  >  15050 (\" Addon: Queuing \") | AUTHORITY:  0 (\"\")  > 0 (\" No Access \") | LEVEL: 0 (\"\")  >  4 (\" Guard \") | MODULE: 0 (\"\")  >  15070 (\" Addon: Resource \") | AUTHORITY:  0 (\"\")  > 0 (\" No Access \") | LEVEL: 0 (\"\")  >  4 (\" Guard \") | MODULE: 0 (\"\")  >  20010 (\" Settings : religion \") | AUTHORITY:  0 (\"\")  > 0 (\" No Access \") | LEVEL: 0 (\"\")  >  4 (\" Guard \") | MODULE: 0 (\"\")  >  20030 (\" Settings: Nationality \") | AUTHORITY:  0 (\"\")  > 0 (\" No Access \") | LEVEL: 0 (\"\")  >  4 (\" Guard \") | MODULE: 0 (\"\")  >  20050 (\" Settings: Address - Country \") | AUTHORITY:  0 (\"\")  > 0 (\" No Access \") | LEVEL: 0 (\"\")  >  4 (\" Guard \") | MODULE: 0 (\"\")  >  20070 (\" Settings: Address - Region \") | AUTHORITY:  0 (\"\")  > 0 (\" No Access \") | LEVEL: 0 (\"\")  >  4 (\" Guard \") | MODULE: 0 (\"\")  >  20090 (\" Settings: Address - Province \") | AUTHORITY:  0 (\"\")  > 0 (\" No Access \") | LEVEL: 0 (\"\")  >  4 (\" Guard \") | MODULE: 0 (\"\")  >  20110 (\" Settings: Address - Municipality \") | AUTHORITY:  0 (\"\")  > 0 (\" No Access \") | LEVEL: 0 (\"\")  >  4 (\" Guard \") | MODULE: 0 (\"\")  >  21010 (\" Department \") | AUTHORITY:  0 (\"\")  > 0 (\" No Access \") | LEVEL: 0 (\"\")  >  4 (\" Guard \") | MODULE: 0 (\"\")  >  21030 (\" Section \") | AUTHORITY:  0 (\"\")  > 0 (\" No Access \") | LEVEL: 0 (\"\")  >  4 (\" Guard \") | MODULE: 0 (\"\")  >  21050 (\" Entrance \") | AUTHORITY:  0 (\"\")  > 0 (\" No Access \")','2021-01-19 10:51:03.083039','Mozilla/5.0 (Windows NT 6.1; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/86.0.4240.198 Safari/537.36'),(256,'175.176.90.255',1,0,3,0,0,10080,490,0,'add/edit Access rights record','LEVEL: 0 (\"\")  >  4 (\" Guard \") | MODULE: 0 (\"\")  >  10040 (\" User Account : level \") | AUTHORITY:  0 (\"\")  > 0 (\" No Access \") | LEVEL: 0 (\"\")  >  4 (\" Guard \") | MODULE: 0 (\"\")  >  10060 (\" User Account : member \") | AUTHORITY:  0 (\"\")  > 0 (\" No Access \") | LEVEL: 0 (\"\")  >  4 (\" Guard \") | MODULE: 0 (\"\")  >  10070 (\" User Account : group \") | AUTHORITY:  0 (\"\")  > 0 (\" No Access \") | LEVEL: 0 (\"\")  >  4 (\" Guard \") | MODULE: 0 (\"\")  >  10080 (\" User Account : access rights \") | AUTHORITY:  0 (\"\")  > 0 (\" No Access \") | LEVEL: 0 (\"\")  >  4 (\" Guard \") | MODULE: 0 (\"\")  >  10100 (\" Account: server \") | AUTHORITY:  0 (\"\")  > 0 (\" No Access \") | LEVEL: 0 (\"\")  >  4 (\" Guard \") | MODULE: 0 (\"\")  >  10120 (\" Devices \") | AUTHORITY:  0 (\"\")  > 0 (\" No Access \") | LEVEL: 0 (\"\")  >  4 (\" Guard \") | MODULE: 0 (\"\")  >  10140 (\" User Account : audit trail \") | AUTHORITY:  0 (\"\")  > 0 (\" No Access \") | LEVEL: 0 (\"\")  >  4 (\" Guard \") | MODULE: 0 (\"\")  >  10160 (\" Brute Force Login Attempt \") | AUTHORITY:  0 (\"\")  > 0 (\" No Access \") | LEVEL: 0 (\"\")  >  4 (\" Guard \") | MODULE: 0 (\"\")  >  10180 (\" Bruteforce IP \") | AUTHORITY:  0 (\"\")  > 0 (\" No Access \") | LEVEL: 0 (\"\")  >  4 (\" Guard \") | MODULE: 0 (\"\")  >  15010 (\" Addon: Group License \") | AUTHORITY:  0 (\"\")  > 0 (\" No Access \") | LEVEL: 0 (\"\")  >  4 (\" Guard \") | MODULE: 0 (\"\")  >  15030 (\" Addon: User License \") | AUTHORITY:  0 (\"\")  > 0 (\" No Access \") | LEVEL: 0 (\"\")  >  4 (\" Guard \") | MODULE: 0 (\"\")  >  15050 (\" Addon: Queuing \") | AUTHORITY:  0 (\"\")  > 0 (\" No Access \") | LEVEL: 0 (\"\")  >  4 (\" Guard \") | MODULE: 0 (\"\")  >  15070 (\" Addon: Resource \") | AUTHORITY:  0 (\"\")  > 0 (\" No Access \") | LEVEL: 0 (\"\")  >  4 (\" Guard \") | MODULE: 0 (\"\")  >  20010 (\" Settings : religion \") | AUTHORITY:  0 (\"\")  > 0 (\" No Access \") | LEVEL: 0 (\"\")  >  4 (\" Guard \") | MODULE: 0 (\"\")  >  20030 (\" Settings: Nationality \") | AUTHORITY:  0 (\"\")  > 0 (\" No Access \") | LEVEL: 0 (\"\")  >  4 (\" Guard \") | MODULE: 0 (\"\")  >  20050 (\" Settings: Address - Country \") | AUTHORITY:  0 (\"\")  > 0 (\" No Access \") | LEVEL: 0 (\"\")  >  4 (\" Guard \") | MODULE: 0 (\"\")  >  20070 (\" Settings: Address - Region \") | AUTHORITY:  0 (\"\")  > 0 (\" No Access \") | LEVEL: 0 (\"\")  >  4 (\" Guard \") | MODULE: 0 (\"\")  >  20090 (\" Settings: Address - Province \") | AUTHORITY:  0 (\"\")  > 0 (\" No Access \") | LEVEL: 0 (\"\")  >  4 (\" Guard \") | MODULE: 0 (\"\")  >  20110 (\" Settings: Address - Municipality \") | AUTHORITY:  0 (\"\")  > 0 (\" No Access \") | LEVEL: 0 (\"\")  >  4 (\" Guard \") | MODULE: 0 (\"\")  >  21010 (\" Department \") | AUTHORITY:  0 (\"\")  > 0 (\" No Access \") | LEVEL: 0 (\"\")  >  4 (\" Guard \") | MODULE: 0 (\"\")  >  21030 (\" Section \") | AUTHORITY:  0 (\"\")  > 0 (\" No Access \") | LEVEL: 0 (\"\")  >  4 (\" Guard \") | MODULE: 0 (\"\")  >  21050 (\" Entrance \") | AUTHORITY:  0 (\"\")  > 0 (\" No Access \") | LEVEL: 0 (\"\")  >  4 (\" Guard \") | MODULE: 0 (\"\")  >  31010 (\" Mobile: Communication RECEIEVE SMS History \") | AUTHORITY:  0 (\"\")  > 0 (\" No Access \")','2021-01-19 10:51:03.085148','Mozilla/5.0 (Windows NT 6.1; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/86.0.4240.198 Safari/537.36'),(257,'175.176.90.255',1,0,3,0,0,10080,491,0,'add/edit Access rights record','LEVEL: 0 (\"\")  >  4 (\" Guard \") | MODULE: 0 (\"\")  >  10040 (\" User Account : level \") | AUTHORITY:  0 (\"\")  > 0 (\" No Access \") | LEVEL: 0 (\"\")  >  4 (\" Guard \") | MODULE: 0 (\"\")  >  10060 (\" User Account : member \") | AUTHORITY:  0 (\"\")  > 0 (\" No Access \") | LEVEL: 0 (\"\")  >  4 (\" Guard \") | MODULE: 0 (\"\")  >  10070 (\" User Account : group \") | AUTHORITY:  0 (\"\")  > 0 (\" No Access \") | LEVEL: 0 (\"\")  >  4 (\" Guard \") | MODULE: 0 (\"\")  >  10080 (\" User Account : access rights \") | AUTHORITY:  0 (\"\")  > 0 (\" No Access \") | LEVEL: 0 (\"\")  >  4 (\" Guard \") | MODULE: 0 (\"\")  >  10100 (\" Account: server \") | AUTHORITY:  0 (\"\")  > 0 (\" No Access \") | LEVEL: 0 (\"\")  >  4 (\" Guard \") | MODULE: 0 (\"\")  >  10120 (\" Devices \") | AUTHORITY:  0 (\"\")  > 0 (\" No Access \") | LEVEL: 0 (\"\")  >  4 (\" Guard \") | MODULE: 0 (\"\")  >  10140 (\" User Account : audit trail \") | AUTHORITY:  0 (\"\")  > 0 (\" No Access \") | LEVEL: 0 (\"\")  >  4 (\" Guard \") | MODULE: 0 (\"\")  >  10160 (\" Brute Force Login Attempt \") | AUTHORITY:  0 (\"\")  > 0 (\" No Access \") | LEVEL: 0 (\"\")  >  4 (\" Guard \") | MODULE: 0 (\"\")  >  10180 (\" Bruteforce IP \") | AUTHORITY:  0 (\"\")  > 0 (\" No Access \") | LEVEL: 0 (\"\")  >  4 (\" Guard \") | MODULE: 0 (\"\")  >  15010 (\" Addon: Group License \") | AUTHORITY:  0 (\"\")  > 0 (\" No Access \") | LEVEL: 0 (\"\")  >  4 (\" Guard \") | MODULE: 0 (\"\")  >  15030 (\" Addon: User License \") | AUTHORITY:  0 (\"\")  > 0 (\" No Access \") | LEVEL: 0 (\"\")  >  4 (\" Guard \") | MODULE: 0 (\"\")  >  15050 (\" Addon: Queuing \") | AUTHORITY:  0 (\"\")  > 0 (\" No Access \") | LEVEL: 0 (\"\")  >  4 (\" Guard \") | MODULE: 0 (\"\")  >  15070 (\" Addon: Resource \") | AUTHORITY:  0 (\"\")  > 0 (\" No Access \") | LEVEL: 0 (\"\")  >  4 (\" Guard \") | MODULE: 0 (\"\")  >  20010 (\" Settings : religion \") | AUTHORITY:  0 (\"\")  > 0 (\" No Access \") | LEVEL: 0 (\"\")  >  4 (\" Guard \") | MODULE: 0 (\"\")  >  20030 (\" Settings: Nationality \") | AUTHORITY:  0 (\"\")  > 0 (\" No Access \") | LEVEL: 0 (\"\")  >  4 (\" Guard \") | MODULE: 0 (\"\")  >  20050 (\" Settings: Address - Country \") | AUTHORITY:  0 (\"\")  > 0 (\" No Access \") | LEVEL: 0 (\"\")  >  4 (\" Guard \") | MODULE: 0 (\"\")  >  20070 (\" Settings: Address - Region \") | AUTHORITY:  0 (\"\")  > 0 (\" No Access \") | LEVEL: 0 (\"\")  >  4 (\" Guard \") | MODULE: 0 (\"\")  >  20090 (\" Settings: Address - Province \") | AUTHORITY:  0 (\"\")  > 0 (\" No Access \") | LEVEL: 0 (\"\")  >  4 (\" Guard \") | MODULE: 0 (\"\")  >  20110 (\" Settings: Address - Municipality \") | AUTHORITY:  0 (\"\")  > 0 (\" No Access \") | LEVEL: 0 (\"\")  >  4 (\" Guard \") | MODULE: 0 (\"\")  >  21010 (\" Department \") | AUTHORITY:  0 (\"\")  > 0 (\" No Access \") | LEVEL: 0 (\"\")  >  4 (\" Guard \") | MODULE: 0 (\"\")  >  21030 (\" Section \") | AUTHORITY:  0 (\"\")  > 0 (\" No Access \") | LEVEL: 0 (\"\")  >  4 (\" Guard \") | MODULE: 0 (\"\")  >  21050 (\" Entrance \") | AUTHORITY:  0 (\"\")  > 0 (\" No Access \") | LEVEL: 0 (\"\")  >  4 (\" Guard \") | MODULE: 0 (\"\")  >  31010 (\" Mobile: Communication RECEIEVE SMS History \") | AUTHORITY:  0 (\"\")  > 0 (\" No Access \") | LEVEL: 0 (\"\")  >  4 (\" Guard \") | MODULE: 0 (\"\")  >  31020 (\" Mobile: Communication SENT SMS History \") | AUTHORITY:  0 (\"\")  > 0 (\" No Access \")','2021-01-19 10:51:03.088838','Mozilla/5.0 (Windows NT 6.1; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/86.0.4240.198 Safari/537.36'),(258,'175.176.90.255',1,0,3,0,0,10080,492,0,'add/edit Access rights record','LEVEL: 0 (\"\")  >  4 (\" Guard \") | MODULE: 0 (\"\")  >  10040 (\" User Account : level \") | AUTHORITY:  0 (\"\")  > 0 (\" No Access \") | LEVEL: 0 (\"\")  >  4 (\" Guard \") | MODULE: 0 (\"\")  >  10060 (\" User Account : member \") | AUTHORITY:  0 (\"\")  > 0 (\" No Access \") | LEVEL: 0 (\"\")  >  4 (\" Guard \") | MODULE: 0 (\"\")  >  10070 (\" User Account : group \") | AUTHORITY:  0 (\"\")  > 0 (\" No Access \") | LEVEL: 0 (\"\")  >  4 (\" Guard \") | MODULE: 0 (\"\")  >  10080 (\" User Account : access rights \") | AUTHORITY:  0 (\"\")  > 0 (\" No Access \") | LEVEL: 0 (\"\")  >  4 (\" Guard \") | MODULE: 0 (\"\")  >  10100 (\" Account: server \") | AUTHORITY:  0 (\"\")  > 0 (\" No Access \") | LEVEL: 0 (\"\")  >  4 (\" Guard \") | MODULE: 0 (\"\")  >  10120 (\" Devices \") | AUTHORITY:  0 (\"\")  > 0 (\" No Access \") | LEVEL: 0 (\"\")  >  4 (\" Guard \") | MODULE: 0 (\"\")  >  10140 (\" User Account : audit trail \") | AUTHORITY:  0 (\"\")  > 0 (\" No Access \") | LEVEL: 0 (\"\")  >  4 (\" Guard \") | MODULE: 0 (\"\")  >  10160 (\" Brute Force Login Attempt \") | AUTHORITY:  0 (\"\")  > 0 (\" No Access \") | LEVEL: 0 (\"\")  >  4 (\" Guard \") | MODULE: 0 (\"\")  >  10180 (\" Bruteforce IP \") | AUTHORITY:  0 (\"\")  > 0 (\" No Access \") | LEVEL: 0 (\"\")  >  4 (\" Guard \") | MODULE: 0 (\"\")  >  15010 (\" Addon: Group License \") | AUTHORITY:  0 (\"\")  > 0 (\" No Access \") | LEVEL: 0 (\"\")  >  4 (\" Guard \") | MODULE: 0 (\"\")  >  15030 (\" Addon: User License \") | AUTHORITY:  0 (\"\")  > 0 (\" No Access \") | LEVEL: 0 (\"\")  >  4 (\" Guard \") | MODULE: 0 (\"\")  >  15050 (\" Addon: Queuing \") | AUTHORITY:  0 (\"\")  > 0 (\" No Access \") | LEVEL: 0 (\"\")  >  4 (\" Guard \") | MODULE: 0 (\"\")  >  15070 (\" Addon: Resource \") | AUTHORITY:  0 (\"\")  > 0 (\" No Access \") | LEVEL: 0 (\"\")  >  4 (\" Guard \") | MODULE: 0 (\"\")  >  20010 (\" Settings : religion \") | AUTHORITY:  0 (\"\")  > 0 (\" No Access \") | LEVEL: 0 (\"\")  >  4 (\" Guard \") | MODULE: 0 (\"\")  >  20030 (\" Settings: Nationality \") | AUTHORITY:  0 (\"\")  > 0 (\" No Access \") | LEVEL: 0 (\"\")  >  4 (\" Guard \") | MODULE: 0 (\"\")  >  20050 (\" Settings: Address - Country \") | AUTHORITY:  0 (\"\")  > 0 (\" No Access \") | LEVEL: 0 (\"\")  >  4 (\" Guard \") | MODULE: 0 (\"\")  >  20070 (\" Settings: Address - Region \") | AUTHORITY:  0 (\"\")  > 0 (\" No Access \") | LEVEL: 0 (\"\")  >  4 (\" Guard \") | MODULE: 0 (\"\")  >  20090 (\" Settings: Address - Province \") | AUTHORITY:  0 (\"\")  > 0 (\" No Access \") | LEVEL: 0 (\"\")  >  4 (\" Guard \") | MODULE: 0 (\"\")  >  20110 (\" Settings: Address - Municipality \") | AUTHORITY:  0 (\"\")  > 0 (\" No Access \") | LEVEL: 0 (\"\")  >  4 (\" Guard \") | MODULE: 0 (\"\")  >  21010 (\" Department \") | AUTHORITY:  0 (\"\")  > 0 (\" No Access \") | LEVEL: 0 (\"\")  >  4 (\" Guard \") | MODULE: 0 (\"\")  >  21030 (\" Section \") | AUTHORITY:  0 (\"\")  > 0 (\" No Access \") | LEVEL: 0 (\"\")  >  4 (\" Guard \") | MODULE: 0 (\"\")  >  21050 (\" Entrance \") | AUTHORITY:  0 (\"\")  > 0 (\" No Access \") | LEVEL: 0 (\"\")  >  4 (\" Guard \") | MODULE: 0 (\"\")  >  31010 (\" Mobile: Communication RECEIEVE SMS History \") | AUTHORITY:  0 (\"\")  > 0 (\" No Access \") | LEVEL: 0 (\"\")  >  4 (\" Guard \") | MODULE: 0 (\"\")  >  31020 (\" Mobile: Communication SENT SMS History \") | AUTHORITY:  0 (\"\")  > 0 (\" No Access \") | LEVEL: 0 (\"\")  >  4 (\" Guard \") | MODULE: 0 (\"\")  >  31025 (\" Mobile: Communication SENT SMS History Per Mobile Number \") | AUTHORITY:  0 (\"\")  > 0 (\" No Access \")','2021-01-19 10:51:03.090960','Mozilla/5.0 (Windows NT 6.1; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/86.0.4240.198 Safari/537.36'),(259,'175.176.90.255',1,0,3,0,0,10080,493,0,'add/edit Access rights record','LEVEL: 0 (\"\")  >  4 (\" Guard \") | MODULE: 0 (\"\")  >  10040 (\" User Account : level \") | AUTHORITY:  0 (\"\")  > 0 (\" No Access \") | LEVEL: 0 (\"\")  >  4 (\" Guard \") | MODULE: 0 (\"\")  >  10060 (\" User Account : member \") | AUTHORITY:  0 (\"\")  > 0 (\" No Access \") | LEVEL: 0 (\"\")  >  4 (\" Guard \") | MODULE: 0 (\"\")  >  10070 (\" User Account : group \") | AUTHORITY:  0 (\"\")  > 0 (\" No Access \") | LEVEL: 0 (\"\")  >  4 (\" Guard \") | MODULE: 0 (\"\")  >  10080 (\" User Account : access rights \") | AUTHORITY:  0 (\"\")  > 0 (\" No Access \") | LEVEL: 0 (\"\")  >  4 (\" Guard \") | MODULE: 0 (\"\")  >  10100 (\" Account: server \") | AUTHORITY:  0 (\"\")  > 0 (\" No Access \") | LEVEL: 0 (\"\")  >  4 (\" Guard \") | MODULE: 0 (\"\")  >  10120 (\" Devices \") | AUTHORITY:  0 (\"\")  > 0 (\" No Access \") | LEVEL: 0 (\"\")  >  4 (\" Guard \") | MODULE: 0 (\"\")  >  10140 (\" User Account : audit trail \") | AUTHORITY:  0 (\"\")  > 0 (\" No Access \") | LEVEL: 0 (\"\")  >  4 (\" Guard \") | MODULE: 0 (\"\")  >  10160 (\" Brute Force Login Attempt \") | AUTHORITY:  0 (\"\")  > 0 (\" No Access \") | LEVEL: 0 (\"\")  >  4 (\" Guard \") | MODULE: 0 (\"\")  >  10180 (\" Bruteforce IP \") | AUTHORITY:  0 (\"\")  > 0 (\" No Access \") | LEVEL: 0 (\"\")  >  4 (\" Guard \") | MODULE: 0 (\"\")  >  15010 (\" Addon: Group License \") | AUTHORITY:  0 (\"\")  > 0 (\" No Access \") | LEVEL: 0 (\"\")  >  4 (\" Guard \") | MODULE: 0 (\"\")  >  15030 (\" Addon: User License \") | AUTHORITY:  0 (\"\")  > 0 (\" No Access \") | LEVEL: 0 (\"\")  >  4 (\" Guard \") | MODULE: 0 (\"\")  >  15050 (\" Addon: Queuing \") | AUTHORITY:  0 (\"\")  > 0 (\" No Access \") | LEVEL: 0 (\"\")  >  4 (\" Guard \") | MODULE: 0 (\"\")  >  15070 (\" Addon: Resource \") | AUTHORITY:  0 (\"\")  > 0 (\" No Access \") | LEVEL: 0 (\"\")  >  4 (\" Guard \") | MODULE: 0 (\"\")  >  20010 (\" Settings : religion \") | AUTHORITY:  0 (\"\")  > 0 (\" No Access \") | LEVEL: 0 (\"\")  >  4 (\" Guard \") | MODULE: 0 (\"\")  >  20030 (\" Settings: Nationality \") | AUTHORITY:  0 (\"\")  > 0 (\" No Access \") | LEVEL: 0 (\"\")  >  4 (\" Guard \") | MODULE: 0 (\"\")  >  20050 (\" Settings: Address - Country \") | AUTHORITY:  0 (\"\")  > 0 (\" No Access \") | LEVEL: 0 (\"\")  >  4 (\" Guard \") | MODULE: 0 (\"\")  >  20070 (\" Settings: Address - Region \") | AUTHORITY:  0 (\"\")  > 0 (\" No Access \") | LEVEL: 0 (\"\")  >  4 (\" Guard \") | MODULE: 0 (\"\")  >  20090 (\" Settings: Address - Province \") | AUTHORITY:  0 (\"\")  > 0 (\" No Access \") | LEVEL: 0 (\"\")  >  4 (\" Guard \") | MODULE: 0 (\"\")  >  20110 (\" Settings: Address - Municipality \") | AUTHORITY:  0 (\"\")  > 0 (\" No Access \") | LEVEL: 0 (\"\")  >  4 (\" Guard \") | MODULE: 0 (\"\")  >  21010 (\" Department \") | AUTHORITY:  0 (\"\")  > 0 (\" No Access \") | LEVEL: 0 (\"\")  >  4 (\" Guard \") | MODULE: 0 (\"\")  >  21030 (\" Section \") | AUTHORITY:  0 (\"\")  > 0 (\" No Access \") | LEVEL: 0 (\"\")  >  4 (\" Guard \") | MODULE: 0 (\"\")  >  21050 (\" Entrance \") | AUTHORITY:  0 (\"\")  > 0 (\" No Access \") | LEVEL: 0 (\"\")  >  4 (\" Guard \") | MODULE: 0 (\"\")  >  31010 (\" Mobile: Communication RECEIEVE SMS History \") | AUTHORITY:  0 (\"\")  > 0 (\" No Access \") | LEVEL: 0 (\"\")  >  4 (\" Guard \") | MODULE: 0 (\"\")  >  31020 (\" Mobile: Communication SENT SMS History \") | AUTHORITY:  0 (\"\")  > 0 (\" No Access \") | LEVEL: 0 (\"\")  >  4 (\" Guard \") | MODULE: 0 (\"\")  >  31025 (\" Mobile: Communication SENT SMS History Per Mobile Number \") | AUTHORITY:  0 (\"\")  > 0 (\" No Access \") | LEVEL: 0 (\"\")  >  4 (\" Guard \") | MODULE: 0 (\"\")  >  31030 (\" Mobile: Communication Notification History \") | AUTHORITY:  0 (\"\")  > 0 (\" No Access \")','2021-01-19 10:51:03.093029','Mozilla/5.0 (Windows NT 6.1; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/86.0.4240.198 Safari/537.36'),(260,'175.176.90.255',1,0,3,0,0,10080,494,0,'add/edit Access rights record','LEVEL: 0 (\"\")  >  4 (\" Guard \") | MODULE: 0 (\"\")  >  10040 (\" User Account : level \") | AUTHORITY:  0 (\"\")  > 0 (\" No Access \") | LEVEL: 0 (\"\")  >  4 (\" Guard \") | MODULE: 0 (\"\")  >  10060 (\" User Account : member \") | AUTHORITY:  0 (\"\")  > 0 (\" No Access \") | LEVEL: 0 (\"\")  >  4 (\" Guard \") | MODULE: 0 (\"\")  >  10070 (\" User Account : group \") | AUTHORITY:  0 (\"\")  > 0 (\" No Access \") | LEVEL: 0 (\"\")  >  4 (\" Guard \") | MODULE: 0 (\"\")  >  10080 (\" User Account : access rights \") | AUTHORITY:  0 (\"\")  > 0 (\" No Access \") | LEVEL: 0 (\"\")  >  4 (\" Guard \") | MODULE: 0 (\"\")  >  10100 (\" Account: server \") | AUTHORITY:  0 (\"\")  > 0 (\" No Access \") | LEVEL: 0 (\"\")  >  4 (\" Guard \") | MODULE: 0 (\"\")  >  10120 (\" Devices \") | AUTHORITY:  0 (\"\")  > 0 (\" No Access \") | LEVEL: 0 (\"\")  >  4 (\" Guard \") | MODULE: 0 (\"\")  >  10140 (\" User Account : audit trail \") | AUTHORITY:  0 (\"\")  > 0 (\" No Access \") | LEVEL: 0 (\"\")  >  4 (\" Guard \") | MODULE: 0 (\"\")  >  10160 (\" Brute Force Login Attempt \") | AUTHORITY:  0 (\"\")  > 0 (\" No Access \") | LEVEL: 0 (\"\")  >  4 (\" Guard \") | MODULE: 0 (\"\")  >  10180 (\" Bruteforce IP \") | AUTHORITY:  0 (\"\")  > 0 (\" No Access \") | LEVEL: 0 (\"\")  >  4 (\" Guard \") | MODULE: 0 (\"\")  >  15010 (\" Addon: Group License \") | AUTHORITY:  0 (\"\")  > 0 (\" No Access \") | LEVEL: 0 (\"\")  >  4 (\" Guard \") | MODULE: 0 (\"\")  >  15030 (\" Addon: User License \") | AUTHORITY:  0 (\"\")  > 0 (\" No Access \") | LEVEL: 0 (\"\")  >  4 (\" Guard \") | MODULE: 0 (\"\")  >  15050 (\" Addon: Queuing \") | AUTHORITY:  0 (\"\")  > 0 (\" No Access \") | LEVEL: 0 (\"\")  >  4 (\" Guard \") | MODULE: 0 (\"\")  >  15070 (\" Addon: Resource \") | AUTHORITY:  0 (\"\")  > 0 (\" No Access \") | LEVEL: 0 (\"\")  >  4 (\" Guard \") | MODULE: 0 (\"\")  >  20010 (\" Settings : religion \") | AUTHORITY:  0 (\"\")  > 0 (\" No Access \") | LEVEL: 0 (\"\")  >  4 (\" Guard \") | MODULE: 0 (\"\")  >  20030 (\" Settings: Nationality \") | AUTHORITY:  0 (\"\")  > 0 (\" No Access \") | LEVEL: 0 (\"\")  >  4 (\" Guard \") | MODULE: 0 (\"\")  >  20050 (\" Settings: Address - Country \") | AUTHORITY:  0 (\"\")  > 0 (\" No Access \") | LEVEL: 0 (\"\")  >  4 (\" Guard \") | MODULE: 0 (\"\")  >  20070 (\" Settings: Address - Region \") | AUTHORITY:  0 (\"\")  > 0 (\" No Access \") | LEVEL: 0 (\"\")  >  4 (\" Guard \") | MODULE: 0 (\"\")  >  20090 (\" Settings: Address - Province \") | AUTHORITY:  0 (\"\")  > 0 (\" No Access \") | LEVEL: 0 (\"\")  >  4 (\" Guard \") | MODULE: 0 (\"\")  >  20110 (\" Settings: Address - Municipality \") | AUTHORITY:  0 (\"\")  > 0 (\" No Access \") | LEVEL: 0 (\"\")  >  4 (\" Guard \") | MODULE: 0 (\"\")  >  21010 (\" Department \") | AUTHORITY:  0 (\"\")  > 0 (\" No Access \") | LEVEL: 0 (\"\")  >  4 (\" Guard \") | MODULE: 0 (\"\")  >  21030 (\" Section \") | AUTHORITY:  0 (\"\")  > 0 (\" No Access \") | LEVEL: 0 (\"\")  >  4 (\" Guard \") | MODULE: 0 (\"\")  >  21050 (\" Entrance \") | AUTHORITY:  0 (\"\")  > 0 (\" No Access \") | LEVEL: 0 (\"\")  >  4 (\" Guard \") | MODULE: 0 (\"\")  >  31010 (\" Mobile: Communication RECEIEVE SMS History \") | AUTHORITY:  0 (\"\")  > 0 (\" No Access \") | LEVEL: 0 (\"\")  >  4 (\" Guard \") | MODULE: 0 (\"\")  >  31020 (\" Mobile: Communication SENT SMS History \") | AUTHORITY:  0 (\"\")  > 0 (\" No Access \") | LEVEL: 0 (\"\")  >  4 (\" Guard \") | MODULE: 0 (\"\")  >  31025 (\" Mobile: Communication SENT SMS History Per Mobile Number \") | AUTHORITY:  0 (\"\")  > 0 (\" No Access \") | LEVEL: 0 (\"\")  >  4 (\" Guard \") | MODULE: 0 (\"\")  >  31030 (\" Mobile: Communication Notification History \") | AUTHORITY:  0 (\"\")  > 0 (\" No Access \") | LEVEL: 0 (\"\")  >  4 (\" Guard \") | MODULE: 0 (\"\")  >  31040 (\" Mobile: Service Codes \") | AUTHORITY:  0 (\"\")  > 0 (\" No Access \")','2021-01-19 10:51:03.095121','Mozilla/5.0 (Windows NT 6.1; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/86.0.4240.198 Safari/537.36'),(261,'175.176.90.255',1,0,3,0,0,10080,495,0,'add/edit Access rights record','LEVEL: 0 (\"\")  >  4 (\" Guard \") | MODULE: 0 (\"\")  >  10040 (\" User Account : level \") | AUTHORITY:  0 (\"\")  > 0 (\" No Access \") | LEVEL: 0 (\"\")  >  4 (\" Guard \") | MODULE: 0 (\"\")  >  10060 (\" User Account : member \") | AUTHORITY:  0 (\"\")  > 0 (\" No Access \") | LEVEL: 0 (\"\")  >  4 (\" Guard \") | MODULE: 0 (\"\")  >  10070 (\" User Account : group \") | AUTHORITY:  0 (\"\")  > 0 (\" No Access \") | LEVEL: 0 (\"\")  >  4 (\" Guard \") | MODULE: 0 (\"\")  >  10080 (\" User Account : access rights \") | AUTHORITY:  0 (\"\")  > 0 (\" No Access \") | LEVEL: 0 (\"\")  >  4 (\" Guard \") | MODULE: 0 (\"\")  >  10100 (\" Account: server \") | AUTHORITY:  0 (\"\")  > 0 (\" No Access \") | LEVEL: 0 (\"\")  >  4 (\" Guard \") | MODULE: 0 (\"\")  >  10120 (\" Devices \") | AUTHORITY:  0 (\"\")  > 0 (\" No Access \") | LEVEL: 0 (\"\")  >  4 (\" Guard \") | MODULE: 0 (\"\")  >  10140 (\" User Account : audit trail \") | AUTHORITY:  0 (\"\")  > 0 (\" No Access \") | LEVEL: 0 (\"\")  >  4 (\" Guard \") | MODULE: 0 (\"\")  >  10160 (\" Brute Force Login Attempt \") | AUTHORITY:  0 (\"\")  > 0 (\" No Access \") | LEVEL: 0 (\"\")  >  4 (\" Guard \") | MODULE: 0 (\"\")  >  10180 (\" Bruteforce IP \") | AUTHORITY:  0 (\"\")  > 0 (\" No Access \") | LEVEL: 0 (\"\")  >  4 (\" Guard \") | MODULE: 0 (\"\")  >  15010 (\" Addon: Group License \") | AUTHORITY:  0 (\"\")  > 0 (\" No Access \") | LEVEL: 0 (\"\")  >  4 (\" Guard \") | MODULE: 0 (\"\")  >  15030 (\" Addon: User License \") | AUTHORITY:  0 (\"\")  > 0 (\" No Access \") | LEVEL: 0 (\"\")  >  4 (\" Guard \") | MODULE: 0 (\"\")  >  15050 (\" Addon: Queuing \") | AUTHORITY:  0 (\"\")  > 0 (\" No Access \") | LEVEL: 0 (\"\")  >  4 (\" Guard \") | MODULE: 0 (\"\")  >  15070 (\" Addon: Resource \") | AUTHORITY:  0 (\"\")  > 0 (\" No Access \") | LEVEL: 0 (\"\")  >  4 (\" Guard \") | MODULE: 0 (\"\")  >  20010 (\" Settings : religion \") | AUTHORITY:  0 (\"\")  > 0 (\" No Access \") | LEVEL: 0 (\"\")  >  4 (\" Guard \") | MODULE: 0 (\"\")  >  20030 (\" Settings: Nationality \") | AUTHORITY:  0 (\"\")  > 0 (\" No Access \") | LEVEL: 0 (\"\")  >  4 (\" Guard \") | MODULE: 0 (\"\")  >  20050 (\" Settings: Address - Country \") | AUTHORITY:  0 (\"\")  > 0 (\" No Access \") | LEVEL: 0 (\"\")  >  4 (\" Guard \") | MODULE: 0 (\"\")  >  20070 (\" Settings: Address - Region \") | AUTHORITY:  0 (\"\")  > 0 (\" No Access \") | LEVEL: 0 (\"\")  >  4 (\" Guard \") | MODULE: 0 (\"\")  >  20090 (\" Settings: Address - Province \") | AUTHORITY:  0 (\"\")  > 0 (\" No Access \") | LEVEL: 0 (\"\")  >  4 (\" Guard \") | MODULE: 0 (\"\")  >  20110 (\" Settings: Address - Municipality \") | AUTHORITY:  0 (\"\")  > 0 (\" No Access \") | LEVEL: 0 (\"\")  >  4 (\" Guard \") | MODULE: 0 (\"\")  >  21010 (\" Department \") | AUTHORITY:  0 (\"\")  > 0 (\" No Access \") | LEVEL: 0 (\"\")  >  4 (\" Guard \") | MODULE: 0 (\"\")  >  21030 (\" Section \") | AUTHORITY:  0 (\"\")  > 0 (\" No Access \") | LEVEL: 0 (\"\")  >  4 (\" Guard \") | MODULE: 0 (\"\")  >  21050 (\" Entrance \") | AUTHORITY:  0 (\"\")  > 0 (\" No Access \") | LEVEL: 0 (\"\")  >  4 (\" Guard \") | MODULE: 0 (\"\")  >  31010 (\" Mobile: Communication RECEIEVE SMS History \") | AUTHORITY:  0 (\"\")  > 0 (\" No Access \") | LEVEL: 0 (\"\")  >  4 (\" Guard \") | MODULE: 0 (\"\")  >  31020 (\" Mobile: Communication SENT SMS History \") | AUTHORITY:  0 (\"\")  > 0 (\" No Access \") | LEVEL: 0 (\"\")  >  4 (\" Guard \") | MODULE: 0 (\"\")  >  31025 (\" Mobile: Communication SENT SMS History Per Mobile Number \") | AUTHORITY:  0 (\"\")  > 0 (\" No Access \") | LEVEL: 0 (\"\")  >  4 (\" Guard \") | MODULE: 0 (\"\")  >  31030 (\" Mobile: Communication Notification History \") | AUTHORITY:  0 (\"\")  > 0 (\" No Access \") | LEVEL: 0 (\"\")  >  4 (\" Guard \") | MODULE: 0 (\"\")  >  31040 (\" Mobile: Service Codes \") | AUTHORITY:  0 (\"\")  > 0 (\" No Access \") | LEVEL: 0 (\"\")  >  4 (\" Guard \") | MODULE: 0 (\"\")  >  31050 (\" Mobile: Shortcode lists \") | AUTHORITY:  0 (\"\")  > 0 (\" No Access \")','2021-01-19 10:51:03.097980','Mozilla/5.0 (Windows NT 6.1; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/86.0.4240.198 Safari/537.36'),(262,'175.176.90.255',1,0,3,0,0,10080,496,0,'add/edit Access rights record','LEVEL: 0 (\"\")  >  4 (\" Guard \") | MODULE: 0 (\"\")  >  10040 (\" User Account : level \") | AUTHORITY:  0 (\"\")  > 0 (\" No Access \") | LEVEL: 0 (\"\")  >  4 (\" Guard \") | MODULE: 0 (\"\")  >  10060 (\" User Account : member \") | AUTHORITY:  0 (\"\")  > 0 (\" No Access \") | LEVEL: 0 (\"\")  >  4 (\" Guard \") | MODULE: 0 (\"\")  >  10070 (\" User Account : group \") | AUTHORITY:  0 (\"\")  > 0 (\" No Access \") | LEVEL: 0 (\"\")  >  4 (\" Guard \") | MODULE: 0 (\"\")  >  10080 (\" User Account : access rights \") | AUTHORITY:  0 (\"\")  > 0 (\" No Access \") | LEVEL: 0 (\"\")  >  4 (\" Guard \") | MODULE: 0 (\"\")  >  10100 (\" Account: server \") | AUTHORITY:  0 (\"\")  > 0 (\" No Access \") | LEVEL: 0 (\"\")  >  4 (\" Guard \") | MODULE: 0 (\"\")  >  10120 (\" Devices \") | AUTHORITY:  0 (\"\")  > 0 (\" No Access \") | LEVEL: 0 (\"\")  >  4 (\" Guard \") | MODULE: 0 (\"\")  >  10140 (\" User Account : audit trail \") | AUTHORITY:  0 (\"\")  > 0 (\" No Access \") | LEVEL: 0 (\"\")  >  4 (\" Guard \") | MODULE: 0 (\"\")  >  10160 (\" Brute Force Login Attempt \") | AUTHORITY:  0 (\"\")  > 0 (\" No Access \") | LEVEL: 0 (\"\")  >  4 (\" Guard \") | MODULE: 0 (\"\")  >  10180 (\" Bruteforce IP \") | AUTHORITY:  0 (\"\")  > 0 (\" No Access \") | LEVEL: 0 (\"\")  >  4 (\" Guard \") | MODULE: 0 (\"\")  >  15010 (\" Addon: Group License \") | AUTHORITY:  0 (\"\")  > 0 (\" No Access \") | LEVEL: 0 (\"\")  >  4 (\" Guard \") | MODULE: 0 (\"\")  >  15030 (\" Addon: User License \") | AUTHORITY:  0 (\"\")  > 0 (\" No Access \") | LEVEL: 0 (\"\")  >  4 (\" Guard \") | MODULE: 0 (\"\")  >  15050 (\" Addon: Queuing \") | AUTHORITY:  0 (\"\")  > 0 (\" No Access \") | LEVEL: 0 (\"\")  >  4 (\" Guard \") | MODULE: 0 (\"\")  >  15070 (\" Addon: Resource \") | AUTHORITY:  0 (\"\")  > 0 (\" No Access \") | LEVEL: 0 (\"\")  >  4 (\" Guard \") | MODULE: 0 (\"\")  >  20010 (\" Settings : religion \") | AUTHORITY:  0 (\"\")  > 0 (\" No Access \") | LEVEL: 0 (\"\")  >  4 (\" Guard \") | MODULE: 0 (\"\")  >  20030 (\" Settings: Nationality \") | AUTHORITY:  0 (\"\")  > 0 (\" No Access \") | LEVEL: 0 (\"\")  >  4 (\" Guard \") | MODULE: 0 (\"\")  >  20050 (\" Settings: Address - Country \") | AUTHORITY:  0 (\"\")  > 0 (\" No Access \") | LEVEL: 0 (\"\")  >  4 (\" Guard \") | MODULE: 0 (\"\")  >  20070 (\" Settings: Address - Region \") | AUTHORITY:  0 (\"\")  > 0 (\" No Access \") | LEVEL: 0 (\"\")  >  4 (\" Guard \") | MODULE: 0 (\"\")  >  20090 (\" Settings: Address - Province \") | AUTHORITY:  0 (\"\")  > 0 (\" No Access \") | LEVEL: 0 (\"\")  >  4 (\" Guard \") | MODULE: 0 (\"\")  >  20110 (\" Settings: Address - Municipality \") | AUTHORITY:  0 (\"\")  > 0 (\" No Access \") | LEVEL: 0 (\"\")  >  4 (\" Guard \") | MODULE: 0 (\"\")  >  21010 (\" Department \") | AUTHORITY:  0 (\"\")  > 0 (\" No Access \") | LEVEL: 0 (\"\")  >  4 (\" Guard \") | MODULE: 0 (\"\")  >  21030 (\" Section \") | AUTHORITY:  0 (\"\")  > 0 (\" No Access \") | LEVEL: 0 (\"\")  >  4 (\" Guard \") | MODULE: 0 (\"\")  >  21050 (\" Entrance \") | AUTHORITY:  0 (\"\")  > 0 (\" No Access \") | LEVEL: 0 (\"\")  >  4 (\" Guard \") | MODULE: 0 (\"\")  >  31010 (\" Mobile: Communication RECEIEVE SMS History \") | AUTHORITY:  0 (\"\")  > 0 (\" No Access \") | LEVEL: 0 (\"\")  >  4 (\" Guard \") | MODULE: 0 (\"\")  >  31020 (\" Mobile: Communication SENT SMS History \") | AUTHORITY:  0 (\"\")  > 0 (\" No Access \") | LEVEL: 0 (\"\")  >  4 (\" Guard \") | MODULE: 0 (\"\")  >  31025 (\" Mobile: Communication SENT SMS History Per Mobile Number \") | AUTHORITY:  0 (\"\")  > 0 (\" No Access \") | LEVEL: 0 (\"\")  >  4 (\" Guard \") | MODULE: 0 (\"\")  >  31030 (\" Mobile: Communication Notification History \") | AUTHORITY:  0 (\"\")  > 0 (\" No Access \") | LEVEL: 0 (\"\")  >  4 (\" Guard \") | MODULE: 0 (\"\")  >  31040 (\" Mobile: Service Codes \") | AUTHORITY:  0 (\"\")  > 0 (\" No Access \") | LEVEL: 0 (\"\")  >  4 (\" Guard \") | MODULE: 0 (\"\")  >  31050 (\" Mobile: Shortcode lists \") | AUTHORITY:  0 (\"\")  > 0 (\" No Access \") | LEVEL: 0 (\"\")  >  4 (\" Guard \") | MODULE: 0 (\"\")  >  31060 (\" Mobile: Load Flow History \") | AUTHORITY:  0 (\"\")  > 0 (\" No Access \")','2021-01-19 10:51:03.100136','Mozilla/5.0 (Windows NT 6.1; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/86.0.4240.198 Safari/537.36'),(263,'175.176.90.255',1,0,3,0,0,10080,497,0,'add/edit Access rights record','LEVEL: 0 (\"\")  >  4 (\" Guard \") | MODULE: 0 (\"\")  >  10040 (\" User Account : level \") | AUTHORITY:  0 (\"\")  > 0 (\" No Access \") | LEVEL: 0 (\"\")  >  4 (\" Guard \") | MODULE: 0 (\"\")  >  10060 (\" User Account : member \") | AUTHORITY:  0 (\"\")  > 0 (\" No Access \") | LEVEL: 0 (\"\")  >  4 (\" Guard \") | MODULE: 0 (\"\")  >  10070 (\" User Account : group \") | AUTHORITY:  0 (\"\")  > 0 (\" No Access \") | LEVEL: 0 (\"\")  >  4 (\" Guard \") | MODULE: 0 (\"\")  >  10080 (\" User Account : access rights \") | AUTHORITY:  0 (\"\")  > 0 (\" No Access \") | LEVEL: 0 (\"\")  >  4 (\" Guard \") | MODULE: 0 (\"\")  >  10100 (\" Account: server \") | AUTHORITY:  0 (\"\")  > 0 (\" No Access \") | LEVEL: 0 (\"\")  >  4 (\" Guard \") | MODULE: 0 (\"\")  >  10120 (\" Devices \") | AUTHORITY:  0 (\"\")  > 0 (\" No Access \") | LEVEL: 0 (\"\")  >  4 (\" Guard \") | MODULE: 0 (\"\")  >  10140 (\" User Account : audit trail \") | AUTHORITY:  0 (\"\")  > 0 (\" No Access \") | LEVEL: 0 (\"\")  >  4 (\" Guard \") | MODULE: 0 (\"\")  >  10160 (\" Brute Force Login Attempt \") | AUTHORITY:  0 (\"\")  > 0 (\" No Access \") | LEVEL: 0 (\"\")  >  4 (\" Guard \") | MODULE: 0 (\"\")  >  10180 (\" Bruteforce IP \") | AUTHORITY:  0 (\"\")  > 0 (\" No Access \") | LEVEL: 0 (\"\")  >  4 (\" Guard \") | MODULE: 0 (\"\")  >  15010 (\" Addon: Group License \") | AUTHORITY:  0 (\"\")  > 0 (\" No Access \") | LEVEL: 0 (\"\")  >  4 (\" Guard \") | MODULE: 0 (\"\")  >  15030 (\" Addon: User License \") | AUTHORITY:  0 (\"\")  > 0 (\" No Access \") | LEVEL: 0 (\"\")  >  4 (\" Guard \") | MODULE: 0 (\"\")  >  15050 (\" Addon: Queuing \") | AUTHORITY:  0 (\"\")  > 0 (\" No Access \") | LEVEL: 0 (\"\")  >  4 (\" Guard \") | MODULE: 0 (\"\")  >  15070 (\" Addon: Resource \") | AUTHORITY:  0 (\"\")  > 0 (\" No Access \") | LEVEL: 0 (\"\")  >  4 (\" Guard \") | MODULE: 0 (\"\")  >  20010 (\" Settings : religion \") | AUTHORITY:  0 (\"\")  > 0 (\" No Access \") | LEVEL: 0 (\"\")  >  4 (\" Guard \") | MODULE: 0 (\"\")  >  20030 (\" Settings: Nationality \") | AUTHORITY:  0 (\"\")  > 0 (\" No Access \") | LEVEL: 0 (\"\")  >  4 (\" Guard \") | MODULE: 0 (\"\")  >  20050 (\" Settings: Address - Country \") | AUTHORITY:  0 (\"\")  > 0 (\" No Access \") | LEVEL: 0 (\"\")  >  4 (\" Guard \") | MODULE: 0 (\"\")  >  20070 (\" Settings: Address - Region \") | AUTHORITY:  0 (\"\")  > 0 (\" No Access \") | LEVEL: 0 (\"\")  >  4 (\" Guard \") | MODULE: 0 (\"\")  >  20090 (\" Settings: Address - Province \") | AUTHORITY:  0 (\"\")  > 0 (\" No Access \") | LEVEL: 0 (\"\")  >  4 (\" Guard \") | MODULE: 0 (\"\")  >  20110 (\" Settings: Address - Municipality \") | AUTHORITY:  0 (\"\")  > 0 (\" No Access \") | LEVEL: 0 (\"\")  >  4 (\" Guard \") | MODULE: 0 (\"\")  >  21010 (\" Department \") | AUTHORITY:  0 (\"\")  > 0 (\" No Access \") | LEVEL: 0 (\"\")  >  4 (\" Guard \") | MODULE: 0 (\"\")  >  21030 (\" Section \") | AUTHORITY:  0 (\"\")  > 0 (\" No Access \") | LEVEL: 0 (\"\")  >  4 (\" Guard \") | MODULE: 0 (\"\")  >  21050 (\" Entrance \") | AUTHORITY:  0 (\"\")  > 0 (\" No Access \") | LEVEL: 0 (\"\")  >  4 (\" Guard \") | MODULE: 0 (\"\")  >  31010 (\" Mobile: Communication RECEIEVE SMS History \") | AUTHORITY:  0 (\"\")  > 0 (\" No Access \") | LEVEL: 0 (\"\")  >  4 (\" Guard \") | MODULE: 0 (\"\")  >  31020 (\" Mobile: Communication SENT SMS History \") | AUTHORITY:  0 (\"\")  > 0 (\" No Access \") | LEVEL: 0 (\"\")  >  4 (\" Guard \") | MODULE: 0 (\"\")  >  31025 (\" Mobile: Communication SENT SMS History Per Mobile Number \") | AUTHORITY:  0 (\"\")  > 0 (\" No Access \") | LEVEL: 0 (\"\")  >  4 (\" Guard \") | MODULE: 0 (\"\")  >  31030 (\" Mobile: Communication Notification History \") | AUTHORITY:  0 (\"\")  > 0 (\" No Access \") | LEVEL: 0 (\"\")  >  4 (\" Guard \") | MODULE: 0 (\"\")  >  31040 (\" Mobile: Service Codes \") | AUTHORITY:  0 (\"\")  > 0 (\" No Access \") | LEVEL: 0 (\"\")  >  4 (\" Guard \") | MODULE: 0 (\"\")  >  31050 (\" Mobile: Shortcode lists \") | AUTHORITY:  0 (\"\")  > 0 (\" No Access \") | LEVEL: 0 (\"\")  >  4 (\" Guard \") | MODULE: 0 (\"\")  >  31060 (\" Mobile: Load Flow History \") | AUTHORITY:  0 (\"\")  > 0 (\" No Access \") | LEVEL: 0 (\"\")  >  4 (\" Guard \") | MODULE: 0 (\"\")  >  31070 (\" Mobile: Volume Control \") | AUTHORITY:  0 (\"\")  > 0 (\" No Access \")','2021-01-19 10:51:03.102852','Mozilla/5.0 (Windows NT 6.1; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/86.0.4240.198 Safari/537.36'),(264,'175.176.90.255',1,0,3,0,0,10080,498,0,'add/edit Access rights record','LEVEL: 0 (\"\")  >  4 (\" Guard \") | MODULE: 0 (\"\")  >  10040 (\" User Account : level \") | AUTHORITY:  0 (\"\")  > 0 (\" No Access \") | LEVEL: 0 (\"\")  >  4 (\" Guard \") | MODULE: 0 (\"\")  >  10060 (\" User Account : member \") | AUTHORITY:  0 (\"\")  > 0 (\" No Access \") | LEVEL: 0 (\"\")  >  4 (\" Guard \") | MODULE: 0 (\"\")  >  10070 (\" User Account : group \") | AUTHORITY:  0 (\"\")  > 0 (\" No Access \") | LEVEL: 0 (\"\")  >  4 (\" Guard \") | MODULE: 0 (\"\")  >  10080 (\" User Account : access rights \") | AUTHORITY:  0 (\"\")  > 0 (\" No Access \") | LEVEL: 0 (\"\")  >  4 (\" Guard \") | MODULE: 0 (\"\")  >  10100 (\" Account: server \") | AUTHORITY:  0 (\"\")  > 0 (\" No Access \") | LEVEL: 0 (\"\")  >  4 (\" Guard \") | MODULE: 0 (\"\")  >  10120 (\" Devices \") | AUTHORITY:  0 (\"\")  > 0 (\" No Access \") | LEVEL: 0 (\"\")  >  4 (\" Guard \") | MODULE: 0 (\"\")  >  10140 (\" User Account : audit trail \") | AUTHORITY:  0 (\"\")  > 0 (\" No Access \") | LEVEL: 0 (\"\")  >  4 (\" Guard \") | MODULE: 0 (\"\")  >  10160 (\" Brute Force Login Attempt \") | AUTHORITY:  0 (\"\")  > 0 (\" No Access \") | LEVEL: 0 (\"\")  >  4 (\" Guard \") | MODULE: 0 (\"\")  >  10180 (\" Bruteforce IP \") | AUTHORITY:  0 (\"\")  > 0 (\" No Access \") | LEVEL: 0 (\"\")  >  4 (\" Guard \") | MODULE: 0 (\"\")  >  15010 (\" Addon: Group License \") | AUTHORITY:  0 (\"\")  > 0 (\" No Access \") | LEVEL: 0 (\"\")  >  4 (\" Guard \") | MODULE: 0 (\"\")  >  15030 (\" Addon: User License \") | AUTHORITY:  0 (\"\")  > 0 (\" No Access \") | LEVEL: 0 (\"\")  >  4 (\" Guard \") | MODULE: 0 (\"\")  >  15050 (\" Addon: Queuing \") | AUTHORITY:  0 (\"\")  > 0 (\" No Access \") | LEVEL: 0 (\"\")  >  4 (\" Guard \") | MODULE: 0 (\"\")  >  15070 (\" Addon: Resource \") | AUTHORITY:  0 (\"\")  > 0 (\" No Access \") | LEVEL: 0 (\"\")  >  4 (\" Guard \") | MODULE: 0 (\"\")  >  20010 (\" Settings : religion \") | AUTHORITY:  0 (\"\")  > 0 (\" No Access \") | LEVEL: 0 (\"\")  >  4 (\" Guard \") | MODULE: 0 (\"\")  >  20030 (\" Settings: Nationality \") | AUTHORITY:  0 (\"\")  > 0 (\" No Access \") | LEVEL: 0 (\"\")  >  4 (\" Guard \") | MODULE: 0 (\"\")  >  20050 (\" Settings: Address - Country \") | AUTHORITY:  0 (\"\")  > 0 (\" No Access \") | LEVEL: 0 (\"\")  >  4 (\" Guard \") | MODULE: 0 (\"\")  >  20070 (\" Settings: Address - Region \") | AUTHORITY:  0 (\"\")  > 0 (\" No Access \") | LEVEL: 0 (\"\")  >  4 (\" Guard \") | MODULE: 0 (\"\")  >  20090 (\" Settings: Address - Province \") | AUTHORITY:  0 (\"\")  > 0 (\" No Access \") | LEVEL: 0 (\"\")  >  4 (\" Guard \") | MODULE: 0 (\"\")  >  20110 (\" Settings: Address - Municipality \") | AUTHORITY:  0 (\"\")  > 0 (\" No Access \") | LEVEL: 0 (\"\")  >  4 (\" Guard \") | MODULE: 0 (\"\")  >  21010 (\" Department \") | AUTHORITY:  0 (\"\")  > 0 (\" No Access \") | LEVEL: 0 (\"\")  >  4 (\" Guard \") | MODULE: 0 (\"\")  >  21030 (\" Section \") | AUTHORITY:  0 (\"\")  > 0 (\" No Access \") | LEVEL: 0 (\"\")  >  4 (\" Guard \") | MODULE: 0 (\"\")  >  21050 (\" Entrance \") | AUTHORITY:  0 (\"\")  > 0 (\" No Access \") | LEVEL: 0 (\"\")  >  4 (\" Guard \") | MODULE: 0 (\"\")  >  31010 (\" Mobile: Communication RECEIEVE SMS History \") | AUTHORITY:  0 (\"\")  > 0 (\" No Access \") | LEVEL: 0 (\"\")  >  4 (\" Guard \") | MODULE: 0 (\"\")  >  31020 (\" Mobile: Communication SENT SMS History \") | AUTHORITY:  0 (\"\")  > 0 (\" No Access \") | LEVEL: 0 (\"\")  >  4 (\" Guard \") | MODULE: 0 (\"\")  >  31025 (\" Mobile: Communication SENT SMS History Per Mobile Number \") | AUTHORITY:  0 (\"\")  > 0 (\" No Access \") | LEVEL: 0 (\"\")  >  4 (\" Guard \") | MODULE: 0 (\"\")  >  31030 (\" Mobile: Communication Notification History \") | AUTHORITY:  0 (\"\")  > 0 (\" No Access \") | LEVEL: 0 (\"\")  >  4 (\" Guard \") | MODULE: 0 (\"\")  >  31040 (\" Mobile: Service Codes \") | AUTHORITY:  0 (\"\")  > 0 (\" No Access \") | LEVEL: 0 (\"\")  >  4 (\" Guard \") | MODULE: 0 (\"\")  >  31050 (\" Mobile: Shortcode lists \") | AUTHORITY:  0 (\"\")  > 0 (\" No Access \") | LEVEL: 0 (\"\")  >  4 (\" Guard \") | MODULE: 0 (\"\")  >  31060 (\" Mobile: Load Flow History \") | AUTHORITY:  0 (\"\")  > 0 (\" No Access \") | LEVEL: 0 (\"\")  >  4 (\" Guard \") | MODULE: 0 (\"\")  >  31070 (\" Mobile: Volume Control \") | AUTHORITY:  0 (\"\")  > 0 (\" No Access \") | LEVEL: 0 (','2021-01-19 10:51:03.105145','Mozilla/5.0 (Windows NT 6.1; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/86.0.4240.198 Safari/537.36'),(265,'175.176.90.255',1,0,3,0,0,10080,499,0,'add/edit Access rights record','LEVEL: 0 (\"\")  >  4 (\" Guard \") | MODULE: 0 (\"\")  >  10040 (\" User Account : level \") | AUTHORITY:  0 (\"\")  > 0 (\" No Access \") | LEVEL: 0 (\"\")  >  4 (\" Guard \") | MODULE: 0 (\"\")  >  10060 (\" User Account : member \") | AUTHORITY:  0 (\"\")  > 0 (\" No Access \") | LEVEL: 0 (\"\")  >  4 (\" Guard \") | MODULE: 0 (\"\")  >  10070 (\" User Account : group \") | AUTHORITY:  0 (\"\")  > 0 (\" No Access \") | LEVEL: 0 (\"\")  >  4 (\" Guard \") | MODULE: 0 (\"\")  >  10080 (\" User Account : access rights \") | AUTHORITY:  0 (\"\")  > 0 (\" No Access \") | LEVEL: 0 (\"\")  >  4 (\" Guard \") | MODULE: 0 (\"\")  >  10100 (\" Account: server \") | AUTHORITY:  0 (\"\")  > 0 (\" No Access \") | LEVEL: 0 (\"\")  >  4 (\" Guard \") | MODULE: 0 (\"\")  >  10120 (\" Devices \") | AUTHORITY:  0 (\"\")  > 0 (\" No Access \") | LEVEL: 0 (\"\")  >  4 (\" Guard \") | MODULE: 0 (\"\")  >  10140 (\" User Account : audit trail \") | AUTHORITY:  0 (\"\")  > 0 (\" No Access \") | LEVEL: 0 (\"\")  >  4 (\" Guard \") | MODULE: 0 (\"\")  >  10160 (\" Brute Force Login Attempt \") | AUTHORITY:  0 (\"\")  > 0 (\" No Access \") | LEVEL: 0 (\"\")  >  4 (\" Guard \") | MODULE: 0 (\"\")  >  10180 (\" Bruteforce IP \") | AUTHORITY:  0 (\"\")  > 0 (\" No Access \") | LEVEL: 0 (\"\")  >  4 (\" Guard \") | MODULE: 0 (\"\")  >  15010 (\" Addon: Group License \") | AUTHORITY:  0 (\"\")  > 0 (\" No Access \") | LEVEL: 0 (\"\")  >  4 (\" Guard \") | MODULE: 0 (\"\")  >  15030 (\" Addon: User License \") | AUTHORITY:  0 (\"\")  > 0 (\" No Access \") | LEVEL: 0 (\"\")  >  4 (\" Guard \") | MODULE: 0 (\"\")  >  15050 (\" Addon: Queuing \") | AUTHORITY:  0 (\"\")  > 0 (\" No Access \") | LEVEL: 0 (\"\")  >  4 (\" Guard \") | MODULE: 0 (\"\")  >  15070 (\" Addon: Resource \") | AUTHORITY:  0 (\"\")  > 0 (\" No Access \") | LEVEL: 0 (\"\")  >  4 (\" Guard \") | MODULE: 0 (\"\")  >  20010 (\" Settings : religion \") | AUTHORITY:  0 (\"\")  > 0 (\" No Access \") | LEVEL: 0 (\"\")  >  4 (\" Guard \") | MODULE: 0 (\"\")  >  20030 (\" Settings: Nationality \") | AUTHORITY:  0 (\"\")  > 0 (\" No Access \") | LEVEL: 0 (\"\")  >  4 (\" Guard \") | MODULE: 0 (\"\")  >  20050 (\" Settings: Address - Country \") | AUTHORITY:  0 (\"\")  > 0 (\" No Access \") | LEVEL: 0 (\"\")  >  4 (\" Guard \") | MODULE: 0 (\"\")  >  20070 (\" Settings: Address - Region \") | AUTHORITY:  0 (\"\")  > 0 (\" No Access \") | LEVEL: 0 (\"\")  >  4 (\" Guard \") | MODULE: 0 (\"\")  >  20090 (\" Settings: Address - Province \") | AUTHORITY:  0 (\"\")  > 0 (\" No Access \") | LEVEL: 0 (\"\")  >  4 (\" Guard \") | MODULE: 0 (\"\")  >  20110 (\" Settings: Address - Municipality \") | AUTHORITY:  0 (\"\")  > 0 (\" No Access \") | LEVEL: 0 (\"\")  >  4 (\" Guard \") | MODULE: 0 (\"\")  >  21010 (\" Department \") | AUTHORITY:  0 (\"\")  > 0 (\" No Access \") | LEVEL: 0 (\"\")  >  4 (\" Guard \") | MODULE: 0 (\"\")  >  21030 (\" Section \") | AUTHORITY:  0 (\"\")  > 0 (\" No Access \") | LEVEL: 0 (\"\")  >  4 (\" Guard \") | MODULE: 0 (\"\")  >  21050 (\" Entrance \") | AUTHORITY:  0 (\"\")  > 0 (\" No Access \") | LEVEL: 0 (\"\")  >  4 (\" Guard \") | MODULE: 0 (\"\")  >  31010 (\" Mobile: Communication RECEIEVE SMS History \") | AUTHORITY:  0 (\"\")  > 0 (\" No Access \") | LEVEL: 0 (\"\")  >  4 (\" Guard \") | MODULE: 0 (\"\")  >  31020 (\" Mobile: Communication SENT SMS History \") | AUTHORITY:  0 (\"\")  > 0 (\" No Access \") | LEVEL: 0 (\"\")  >  4 (\" Guard \") | MODULE: 0 (\"\")  >  31025 (\" Mobile: Communication SENT SMS History Per Mobile Number \") | AUTHORITY:  0 (\"\")  > 0 (\" No Access \") | LEVEL: 0 (\"\")  >  4 (\" Guard \") | MODULE: 0 (\"\")  >  31030 (\" Mobile: Communication Notification History \") | AUTHORITY:  0 (\"\")  > 0 (\" No Access \") | LEVEL: 0 (\"\")  >  4 (\" Guard \") | MODULE: 0 (\"\")  >  31040 (\" Mobile: Service Codes \") | AUTHORITY:  0 (\"\")  > 0 (\" No Access \") | LEVEL: 0 (\"\")  >  4 (\" Guard \") | MODULE: 0 (\"\")  >  31050 (\" Mobile: Shortcode lists \") | AUTHORITY:  0 (\"\")  > 0 (\" No Access \") | LEVEL: 0 (\"\")  >  4 (\" Guard \") | MODULE: 0 (\"\")  >  31060 (\" Mobile: Load Flow History \") | AUTHORITY:  0 (\"\")  > 0 (\" No Access \") | LEVEL: 0 (\"\")  >  4 (\" Guard \") | MODULE: 0 (\"\")  >  31070 (\" Mobile: Volume Control \") | AUTHORITY:  0 (\"\")  > 0 (\" No Access \") | LEVEL: 0 (','2021-01-19 10:51:03.107306','Mozilla/5.0 (Windows NT 6.1; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/86.0.4240.198 Safari/537.36'),(266,'175.176.90.255',1,0,3,0,0,10080,500,0,'add/edit Access rights record','LEVEL: 0 (\"\")  >  4 (\" Guard \") | MODULE: 0 (\"\")  >  10040 (\" User Account : level \") | AUTHORITY:  0 (\"\")  > 0 (\" No Access \") | LEVEL: 0 (\"\")  >  4 (\" Guard \") | MODULE: 0 (\"\")  >  10060 (\" User Account : member \") | AUTHORITY:  0 (\"\")  > 0 (\" No Access \") | LEVEL: 0 (\"\")  >  4 (\" Guard \") | MODULE: 0 (\"\")  >  10070 (\" User Account : group \") | AUTHORITY:  0 (\"\")  > 0 (\" No Access \") | LEVEL: 0 (\"\")  >  4 (\" Guard \") | MODULE: 0 (\"\")  >  10080 (\" User Account : access rights \") | AUTHORITY:  0 (\"\")  > 0 (\" No Access \") | LEVEL: 0 (\"\")  >  4 (\" Guard \") | MODULE: 0 (\"\")  >  10100 (\" Account: server \") | AUTHORITY:  0 (\"\")  > 0 (\" No Access \") | LEVEL: 0 (\"\")  >  4 (\" Guard \") | MODULE: 0 (\"\")  >  10120 (\" Devices \") | AUTHORITY:  0 (\"\")  > 0 (\" No Access \") | LEVEL: 0 (\"\")  >  4 (\" Guard \") | MODULE: 0 (\"\")  >  10140 (\" User Account : audit trail \") | AUTHORITY:  0 (\"\")  > 0 (\" No Access \") | LEVEL: 0 (\"\")  >  4 (\" Guard \") | MODULE: 0 (\"\")  >  10160 (\" Brute Force Login Attempt \") | AUTHORITY:  0 (\"\")  > 0 (\" No Access \") | LEVEL: 0 (\"\")  >  4 (\" Guard \") | MODULE: 0 (\"\")  >  10180 (\" Bruteforce IP \") | AUTHORITY:  0 (\"\")  > 0 (\" No Access \") | LEVEL: 0 (\"\")  >  4 (\" Guard \") | MODULE: 0 (\"\")  >  15010 (\" Addon: Group License \") | AUTHORITY:  0 (\"\")  > 0 (\" No Access \") | LEVEL: 0 (\"\")  >  4 (\" Guard \") | MODULE: 0 (\"\")  >  15030 (\" Addon: User License \") | AUTHORITY:  0 (\"\")  > 0 (\" No Access \") | LEVEL: 0 (\"\")  >  4 (\" Guard \") | MODULE: 0 (\"\")  >  15050 (\" Addon: Queuing \") | AUTHORITY:  0 (\"\")  > 0 (\" No Access \") | LEVEL: 0 (\"\")  >  4 (\" Guard \") | MODULE: 0 (\"\")  >  15070 (\" Addon: Resource \") | AUTHORITY:  0 (\"\")  > 0 (\" No Access \") | LEVEL: 0 (\"\")  >  4 (\" Guard \") | MODULE: 0 (\"\")  >  20010 (\" Settings : religion \") | AUTHORITY:  0 (\"\")  > 0 (\" No Access \") | LEVEL: 0 (\"\")  >  4 (\" Guard \") | MODULE: 0 (\"\")  >  20030 (\" Settings: Nationality \") | AUTHORITY:  0 (\"\")  > 0 (\" No Access \") | LEVEL: 0 (\"\")  >  4 (\" Guard \") | MODULE: 0 (\"\")  >  20050 (\" Settings: Address - Country \") | AUTHORITY:  0 (\"\")  > 0 (\" No Access \") | LEVEL: 0 (\"\")  >  4 (\" Guard \") | MODULE: 0 (\"\")  >  20070 (\" Settings: Address - Region \") | AUTHORITY:  0 (\"\")  > 0 (\" No Access \") | LEVEL: 0 (\"\")  >  4 (\" Guard \") | MODULE: 0 (\"\")  >  20090 (\" Settings: Address - Province \") | AUTHORITY:  0 (\"\")  > 0 (\" No Access \") | LEVEL: 0 (\"\")  >  4 (\" Guard \") | MODULE: 0 (\"\")  >  20110 (\" Settings: Address - Municipality \") | AUTHORITY:  0 (\"\")  > 0 (\" No Access \") | LEVEL: 0 (\"\")  >  4 (\" Guard \") | MODULE: 0 (\"\")  >  21010 (\" Department \") | AUTHORITY:  0 (\"\")  > 0 (\" No Access \") | LEVEL: 0 (\"\")  >  4 (\" Guard \") | MODULE: 0 (\"\")  >  21030 (\" Section \") | AUTHORITY:  0 (\"\")  > 0 (\" No Access \") | LEVEL: 0 (\"\")  >  4 (\" Guard \") | MODULE: 0 (\"\")  >  21050 (\" Entrance \") | AUTHORITY:  0 (\"\")  > 0 (\" No Access \") | LEVEL: 0 (\"\")  >  4 (\" Guard \") | MODULE: 0 (\"\")  >  31010 (\" Mobile: Communication RECEIEVE SMS History \") | AUTHORITY:  0 (\"\")  > 0 (\" No Access \") | LEVEL: 0 (\"\")  >  4 (\" Guard \") | MODULE: 0 (\"\")  >  31020 (\" Mobile: Communication SENT SMS History \") | AUTHORITY:  0 (\"\")  > 0 (\" No Access \") | LEVEL: 0 (\"\")  >  4 (\" Guard \") | MODULE: 0 (\"\")  >  31025 (\" Mobile: Communication SENT SMS History Per Mobile Number \") | AUTHORITY:  0 (\"\")  > 0 (\" No Access \") | LEVEL: 0 (\"\")  >  4 (\" Guard \") | MODULE: 0 (\"\")  >  31030 (\" Mobile: Communication Notification History \") | AUTHORITY:  0 (\"\")  > 0 (\" No Access \") | LEVEL: 0 (\"\")  >  4 (\" Guard \") | MODULE: 0 (\"\")  >  31040 (\" Mobile: Service Codes \") | AUTHORITY:  0 (\"\")  > 0 (\" No Access \") | LEVEL: 0 (\"\")  >  4 (\" Guard \") | MODULE: 0 (\"\")  >  31050 (\" Mobile: Shortcode lists \") | AUTHORITY:  0 (\"\")  > 0 (\" No Access \") | LEVEL: 0 (\"\")  >  4 (\" Guard \") | MODULE: 0 (\"\")  >  31060 (\" Mobile: Load Flow History \") | AUTHORITY:  0 (\"\")  > 0 (\" No Access \") | LEVEL: 0 (\"\")  >  4 (\" Guard \") | MODULE: 0 (\"\")  >  31070 (\" Mobile: Volume Control \") | AUTHORITY:  0 (\"\")  > 0 (\" No Access \") | LEVEL: 0 (','2021-01-19 10:51:03.109481','Mozilla/5.0 (Windows NT 6.1; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/86.0.4240.198 Safari/537.36'),(267,'175.176.90.255',1,0,3,0,0,10080,501,0,'add/edit Access rights record','LEVEL: 0 (\"\")  >  4 (\" Guard \") | MODULE: 0 (\"\")  >  10040 (\" User Account : level \") | AUTHORITY:  0 (\"\")  > 0 (\" No Access \") | LEVEL: 0 (\"\")  >  4 (\" Guard \") | MODULE: 0 (\"\")  >  10060 (\" User Account : member \") | AUTHORITY:  0 (\"\")  > 0 (\" No Access \") | LEVEL: 0 (\"\")  >  4 (\" Guard \") | MODULE: 0 (\"\")  >  10070 (\" User Account : group \") | AUTHORITY:  0 (\"\")  > 0 (\" No Access \") | LEVEL: 0 (\"\")  >  4 (\" Guard \") | MODULE: 0 (\"\")  >  10080 (\" User Account : access rights \") | AUTHORITY:  0 (\"\")  > 0 (\" No Access \") | LEVEL: 0 (\"\")  >  4 (\" Guard \") | MODULE: 0 (\"\")  >  10100 (\" Account: server \") | AUTHORITY:  0 (\"\")  > 0 (\" No Access \") | LEVEL: 0 (\"\")  >  4 (\" Guard \") | MODULE: 0 (\"\")  >  10120 (\" Devices \") | AUTHORITY:  0 (\"\")  > 0 (\" No Access \") | LEVEL: 0 (\"\")  >  4 (\" Guard \") | MODULE: 0 (\"\")  >  10140 (\" User Account : audit trail \") | AUTHORITY:  0 (\"\")  > 0 (\" No Access \") | LEVEL: 0 (\"\")  >  4 (\" Guard \") | MODULE: 0 (\"\")  >  10160 (\" Brute Force Login Attempt \") | AUTHORITY:  0 (\"\")  > 0 (\" No Access \") | LEVEL: 0 (\"\")  >  4 (\" Guard \") | MODULE: 0 (\"\")  >  10180 (\" Bruteforce IP \") | AUTHORITY:  0 (\"\")  > 0 (\" No Access \") | LEVEL: 0 (\"\")  >  4 (\" Guard \") | MODULE: 0 (\"\")  >  15010 (\" Addon: Group License \") | AUTHORITY:  0 (\"\")  > 0 (\" No Access \") | LEVEL: 0 (\"\")  >  4 (\" Guard \") | MODULE: 0 (\"\")  >  15030 (\" Addon: User License \") | AUTHORITY:  0 (\"\")  > 0 (\" No Access \") | LEVEL: 0 (\"\")  >  4 (\" Guard \") | MODULE: 0 (\"\")  >  15050 (\" Addon: Queuing \") | AUTHORITY:  0 (\"\")  > 0 (\" No Access \") | LEVEL: 0 (\"\")  >  4 (\" Guard \") | MODULE: 0 (\"\")  >  15070 (\" Addon: Resource \") | AUTHORITY:  0 (\"\")  > 0 (\" No Access \") | LEVEL: 0 (\"\")  >  4 (\" Guard \") | MODULE: 0 (\"\")  >  20010 (\" Settings : religion \") | AUTHORITY:  0 (\"\")  > 0 (\" No Access \") | LEVEL: 0 (\"\")  >  4 (\" Guard \") | MODULE: 0 (\"\")  >  20030 (\" Settings: Nationality \") | AUTHORITY:  0 (\"\")  > 0 (\" No Access \") | LEVEL: 0 (\"\")  >  4 (\" Guard \") | MODULE: 0 (\"\")  >  20050 (\" Settings: Address - Country \") | AUTHORITY:  0 (\"\")  > 0 (\" No Access \") | LEVEL: 0 (\"\")  >  4 (\" Guard \") | MODULE: 0 (\"\")  >  20070 (\" Settings: Address - Region \") | AUTHORITY:  0 (\"\")  > 0 (\" No Access \") | LEVEL: 0 (\"\")  >  4 (\" Guard \") | MODULE: 0 (\"\")  >  20090 (\" Settings: Address - Province \") | AUTHORITY:  0 (\"\")  > 0 (\" No Access \") | LEVEL: 0 (\"\")  >  4 (\" Guard \") | MODULE: 0 (\"\")  >  20110 (\" Settings: Address - Municipality \") | AUTHORITY:  0 (\"\")  > 0 (\" No Access \") | LEVEL: 0 (\"\")  >  4 (\" Guard \") | MODULE: 0 (\"\")  >  21010 (\" Department \") | AUTHORITY:  0 (\"\")  > 0 (\" No Access \") | LEVEL: 0 (\"\")  >  4 (\" Guard \") | MODULE: 0 (\"\")  >  21030 (\" Section \") | AUTHORITY:  0 (\"\")  > 0 (\" No Access \") | LEVEL: 0 (\"\")  >  4 (\" Guard \") | MODULE: 0 (\"\")  >  21050 (\" Entrance \") | AUTHORITY:  0 (\"\")  > 0 (\" No Access \") | LEVEL: 0 (\"\")  >  4 (\" Guard \") | MODULE: 0 (\"\")  >  31010 (\" Mobile: Communication RECEIEVE SMS History \") | AUTHORITY:  0 (\"\")  > 0 (\" No Access \") | LEVEL: 0 (\"\")  >  4 (\" Guard \") | MODULE: 0 (\"\")  >  31020 (\" Mobile: Communication SENT SMS History \") | AUTHORITY:  0 (\"\")  > 0 (\" No Access \") | LEVEL: 0 (\"\")  >  4 (\" Guard \") | MODULE: 0 (\"\")  >  31025 (\" Mobile: Communication SENT SMS History Per Mobile Number \") | AUTHORITY:  0 (\"\")  > 0 (\" No Access \") | LEVEL: 0 (\"\")  >  4 (\" Guard \") | MODULE: 0 (\"\")  >  31030 (\" Mobile: Communication Notification History \") | AUTHORITY:  0 (\"\")  > 0 (\" No Access \") | LEVEL: 0 (\"\")  >  4 (\" Guard \") | MODULE: 0 (\"\")  >  31040 (\" Mobile: Service Codes \") | AUTHORITY:  0 (\"\")  > 0 (\" No Access \") | LEVEL: 0 (\"\")  >  4 (\" Guard \") | MODULE: 0 (\"\")  >  31050 (\" Mobile: Shortcode lists \") | AUTHORITY:  0 (\"\")  > 0 (\" No Access \") | LEVEL: 0 (\"\")  >  4 (\" Guard \") | MODULE: 0 (\"\")  >  31060 (\" Mobile: Load Flow History \") | AUTHORITY:  0 (\"\")  > 0 (\" No Access \") | LEVEL: 0 (\"\")  >  4 (\" Guard \") | MODULE: 0 (\"\")  >  31070 (\" Mobile: Volume Control \") | AUTHORITY:  0 (\"\")  > 0 (\" No Access \") | LEVEL: 0 (','2021-01-19 10:51:03.112348','Mozilla/5.0 (Windows NT 6.1; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/86.0.4240.198 Safari/537.36'),(268,'175.176.90.255',1,0,6,0,0,10040,4,0,'add/edit Access level record','DESCRIPTION:\"  \" > \" Guard \" | STATUS: 0 (\"  \") > 2 (\" Active \")','2021-01-19 10:51:03.113850','Mozilla/5.0 (Windows NT 6.1; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/86.0.4240.198 Safari/537.36'),(273,'175.176.90.255',1,0,3,0,0,40010,7,0,'add/edit Registration record','Department: \" 0 \" > \" 2 \" | Section: \" 0 \" > \" 1 \" | First name: \"  \" > \" ALI BALOU \" | Middle name: \"  \" > \" E. \" | Last name: \"  \" > \" NANDING \" | Gender: \" 0 \" > \" 1 \" | Notification Phone Number: \"  \" > \" +639061701364 \" | Emergency Contact Person: \"  \" > \" Julia Baretto \" | Emergency Contact Numbher: \"  \" > \" +639353359992 \" | Status: \" 0 \" > \" 2 \"','2021-01-19 11:29:32.175737','Mozilla/5.0 (Windows NT 6.1; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/87.0.4280.141 Safari/537.36'),(275,'175.176.90.255',1,0,3,0,0,40010,9,0,'add/edit Registration record','Department: \" 0 \" > \" 2 \" | Section: \" 0 \" > \" 1 \" | First name: \"  \" > \" Alucard \" | Middle name: \"  \" > \" Leomeord \" | Last name: \"  \" > \" Aldous \" | Suffix: \"  \" > \" CSP \" | Gender: \" 0 \" > \" 1 \" | Notification Phone Number: \"  \" > \" +639757944512 \" | Emergency Contact Person: \"  \" > \" Mahal kong Rency \" | Emergency Contact Numbher: \"  \" > \" +639757944512 \" | Status: \" 0 \" > \" 2 \"','2021-01-19 11:32:39.483784','Mozilla/5.0 (Linux; U; Android 9; en-us; Redmi 6 Build/PPR1.180610.011) AppleWebKit/537.36 (KHTML, like Gecko) Version/4.0 Chrome/61.0.3163.128 Mobile Safari/537.36 XiaoMi/Mint Browser/3.7.2'),(276,'175.176.90.255',1,0,6,0,0,40050,3,0,'add/edit User record','Department: \" 0 \" > \" 2 \" | Section: \" 0 \" > \" 1 \" | Unique Code: \"  \" > \" DEF.20210119.113341292270.4rmQb3q \" | First name: \"  \" > \" ALI BALOU \" | Middle name: \"  \" > \" E. \" | Last name: \"  \" > \" NANDING \" | Gender: \" 0 \" > \" 1 \" | Notification Mobile Number: \"  \" > \" +639061701364 \" | Emergency Contact Person: \"  \" > \" Julia Baretto \" | Emergency Contact Number: \"  \" > \" +639353359992 \" | Status: \" 0 \" > \" 2 \"','2021-01-19 11:33:41.299506','Mozilla/5.0 (Windows NT 6.1; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/87.0.4280.141 Safari/537.36'),(277,'175.176.90.255',1,0,6,0,0,40010,7,0,'add/edit Registration record','User: \" 0 \" > \" -9223372036854700032 \" | Status: \" 2 \" > \" 4 \"','2021-01-19 11:33:41.301131','Mozilla/5.0 (Windows NT 6.1; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/87.0.4280.141 Safari/537.36'),(278,'175.176.90.255',1,0,6,0,0,40050,4,0,'add/edit User record','Department: \" 0 \" > \" 2 \" | Section: \" 0 \" > \" 1 \" | Unique Code: \"  \" > \" DEF.20210119.113444180245.CEWPEE4 \" | First name: \"  \" > \" Alucard \" | Middle name: \"  \" > \" Leomeord \" | Last name: \"  \" > \" Aldous \" | Suffix: \"  \" > \" CSP \" | Gender: \" 0 \" > \" 1 \" | Notification Mobile Number: \"  \" > \" +639757944512 \" | Emergency Contact Person: \"  \" > \" Mahal kong Rency \" | Emergency Contact Number: \"  \" > \" +639757944512 \" | Status: \" 0 \" > \" 2 \"','2021-01-19 11:34:44.187486','Mozilla/5.0 (Windows NT 6.1; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/87.0.4280.141 Safari/537.36'),(279,'175.176.90.255',1,0,6,0,0,40010,9,0,'add/edit Registration record','User: \" 0 \" > \" -9223372036854700032 \" | Status: \" 2 \" > \" 4 \"','2021-01-19 11:34:44.189175','Mozilla/5.0 (Windows NT 6.1; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/87.0.4280.141 Safari/537.36'),(280,'175.176.90.255',1,0,6,0,0,40070,2,0,'add/edit Attendance record','User: \" 0 \" > \" 4 \" | Date: \" 1000-01-01 00:00:00.000000 \" > \" 2021-01-19 11:38:26.897443 \" | In: \" 0 \" > \" 2 \" | Out: \" 0 \" > \" 1 \" | Entrance: \"  \" > \" Exit \" | Device Key: \"  \" > \" cec3ddbdce6dae96.RMX2040 \" | Status: \" 0 \" > \" 2 \"','2021-01-19 11:38:26.904300','Mozilla/5.0 (Linux; Android 10; RMX2040 Build/QP1A.190711.020; wv) AppleWebKit/537.36 (KHTML, like Gecko) Version/4.0 Chrome/87.0.4280.141 Mobile Safari/537.36'),(281,'49.149.75.5',1,0,3,0,0,40010,10,0,'add/edit Registration record','Department: \" 0 \" > \" 2 \" | Section: \" 0 \" > \" 1 \" | First name: \"  \" > \" FAHAD \" | Middle name: \"  \" > \" LUMABAO \" | Last name: \"  \" > \" KUSA \" | Gender: \" 0 \" > \" 1 \" | Notification Phone Number: \"  \" > \" +639974301462 \" | Emergency Contact Person: \"  \" > \" HASMIRA KUSA WAHAB \" | Emergency Contact Numbher: \"  \" > \" +639264626986 \" | Status: \" 0 \" > \" 2 \"','2021-01-19 13:25:25.690550','Mozilla/5.0 (Windows NT 6.1; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/87.0.4280.141 Safari/537.36'),(282,'49.149.75.5',1,0,3,0,0,40010,11,0,'add/edit Registration record','Department: \" 0 \" > \" 2 \" | Section: \" 0 \" > \" 1 \" | First name: \"  \" > \" ALI BALOU \" | Middle name: \"  \" > \" EMBA \" | Last name: \"  \" > \" NANDING \" | Gender: \" 0 \" > \" 1 \" | Notification Phone Number: \"  \" > \" +639061701364 \" | Emergency Contact Person: \"  \" > \" JULIA BARETTO-NANDING \" | Emergency Contact Numbher: \"  \" > \" +639655460720 \" | Status: \" 0 \" > \" 2 \"','2021-01-20 13:53:53.717509','Mozilla/5.0 (Windows NT 6.1; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/87.0.4280.141 Safari/537.36');
/*!40000 ALTER TABLE `account_audit_trail` ENABLE KEYS */;
UNLOCK TABLES;

--
-- Table structure for table `account_bfip`
--

DROP TABLE IF EXISTS `account_bfip`;
/*!40101 SET @saved_cs_client     = @@character_set_client */;
/*!40101 SET character_set_client = utf8 */;
CREATE TABLE `account_bfip` (
  `ACC_BFIP_ID` bigint(20) NOT NULL AUTO_INCREMENT,
  `ACC_BFIP_IP` varchar(255) CHARACTER SET utf8 COLLATE utf8_unicode_ci NOT NULL,
  `ACC_BFIP_DESCRIPTION` varchar(255) CHARACTER SET utf8 COLLATE utf8_unicode_ci NOT NULL,
  `ACC_BFIP_LAST_ACTIVITY` datetime(6) DEFAULT NULL,
  `ACC_BFIP_FAIL_COUNT` bigint(20) NOT NULL,
  `ACC_BFIP_LOCK_COUNT` bigint(20) NOT NULL,
  `ACC_BFIP_SUCCESS_COUNT` bigint(20) NOT NULL,
  `ACC_BFIP_STATUS` tinyint(4) NOT NULL,
  PRIMARY KEY (`ACC_BFIP_ID`),
  UNIQUE KEY `ACC_BFIP_IP` (`ACC_BFIP_IP`)
) ENGINE=InnoDB AUTO_INCREMENT=4 DEFAULT CHARSET=latin1;
/*!40101 SET character_set_client = @saved_cs_client */;

--
-- Dumping data for table `account_bfip`
--

LOCK TABLES `account_bfip` WRITE;
/*!40000 ALTER TABLE `account_bfip` DISABLE KEYS */;
INSERT INTO `account_bfip` (`ACC_BFIP_ID`, `ACC_BFIP_IP`, `ACC_BFIP_DESCRIPTION`, `ACC_BFIP_LAST_ACTIVITY`, `ACC_BFIP_FAIL_COUNT`, `ACC_BFIP_LOCK_COUNT`, `ACC_BFIP_SUCCESS_COUNT`, `ACC_BFIP_STATUS`) VALUES (1,'49.146.42.127','49.146.42.127','2021-01-20 14:12:37.007299',0,0,10,2),(2,'175.176.90.255','175.176.90.255','2021-01-19 10:52:55.016474',3,0,1,2),(3,'49.149.75.5','49.149.75.5','2021-01-20 13:14:27.493692',0,0,2,2);
/*!40000 ALTER TABLE `account_bfip` ENABLE KEYS */;
UNLOCK TABLES;

--
-- Table structure for table `account_bflogin`
--

DROP TABLE IF EXISTS `account_bflogin`;
/*!40101 SET @saved_cs_client     = @@character_set_client */;
/*!40101 SET character_set_client = utf8 */;
CREATE TABLE `account_bflogin` (
  `ACC_BFLOGIN_ID` bigint(20) NOT NULL AUTO_INCREMENT,
  `ACC_BFLOGIN_USERNAME` varchar(400) CHARACTER SET utf8 COLLATE utf8_unicode_ci NOT NULL,
  `ACC_BFLOGIN_PASSWORD` varchar(400) CHARACTER SET utf8 COLLATE utf8_unicode_ci NOT NULL,
  `ACC_BFLOGIN_DATE` datetime(6) DEFAULT NULL,
  `ACC_BFLOGIN_IP` varchar(400) CHARACTER SET utf8 COLLATE utf8_unicode_ci NOT NULL,
  `ACC_BFLOGIN_STATUS` tinyint(4) NOT NULL,
  PRIMARY KEY (`ACC_BFLOGIN_ID`)
) ENGINE=InnoDB AUTO_INCREMENT=25 DEFAULT CHARSET=latin1;
/*!40101 SET character_set_client = @saved_cs_client */;

--
-- Dumping data for table `account_bflogin`
--

LOCK TABLES `account_bflogin` WRITE;
/*!40000 ALTER TABLE `account_bflogin` DISABLE KEYS */;
INSERT INTO `account_bflogin` (`ACC_BFLOGIN_ID`, `ACC_BFLOGIN_USERNAME`, `ACC_BFLOGIN_PASSWORD`, `ACC_BFLOGIN_DATE`, `ACC_BFLOGIN_IP`, `ACC_BFLOGIN_STATUS`) VALUES (23,'administrator','******','2021-01-20 13:14:27.493692','49.149.75.5',2),(24,'administrator','******','2021-01-20 14:12:37.007299','49.146.42.127',2);
/*!40000 ALTER TABLE `account_bflogin` ENABLE KEYS */;
UNLOCK TABLES;

--
-- Table structure for table `account_device`
--

DROP TABLE IF EXISTS `account_device`;
/*!40101 SET @saved_cs_client     = @@character_set_client */;
/*!40101 SET character_set_client = utf8 */;
CREATE TABLE `account_device` (
  `ACC_DEVICE_ID` bigint(20) NOT NULL AUTO_INCREMENT,
  `ACC_DEVICE_DESCRIPTION` varchar(500) CHARACTER SET utf8 COLLATE utf8_unicode_ci NOT NULL,
  `ACC_DEVICE_PUBLIC_KEY` varchar(4000) CHARACTER SET utf8 COLLATE utf8_unicode_ci NOT NULL,
  `ACC_DEVICE_PRIVATE_KEY` varchar(4000) CHARACTER SET utf8 COLLATE utf8_unicode_ci NOT NULL,
  `ACC_DEVICE_PRIVATE_KEY_SALT` varchar(12) CHARACTER SET utf8 COLLATE utf8_unicode_ci NOT NULL,
  `ACC_DEVICE_STATUS` tinyint(4) NOT NULL,
  PRIMARY KEY (`ACC_DEVICE_ID`)
) ENGINE=InnoDB DEFAULT CHARSET=latin1;
/*!40101 SET character_set_client = @saved_cs_client */;

--
-- Dumping data for table `account_device`
--

LOCK TABLES `account_device` WRITE;
/*!40000 ALTER TABLE `account_device` DISABLE KEYS */;
/*!40000 ALTER TABLE `account_device` ENABLE KEYS */;
UNLOCK TABLES;

--
-- Table structure for table `account_group`
--

DROP TABLE IF EXISTS `account_group`;
/*!40101 SET @saved_cs_client     = @@character_set_client */;
/*!40101 SET character_set_client = utf8 */;
CREATE TABLE `account_group` (
  `ACC_GROUP_ID` bigint(20) NOT NULL AUTO_INCREMENT,
  `ACC_GROUP_DESCRIPTION` varchar(500) CHARACTER SET utf8 COLLATE utf8_unicode_ci NOT NULL,
  `ACC_GROUP_STATUS` tinyint(4) NOT NULL,
  `ACC_GROUP_SYSTEM_GENERATED` tinyint(4) NOT NULL,
  PRIMARY KEY (`ACC_GROUP_ID`)
) ENGINE=InnoDB AUTO_INCREMENT=3 DEFAULT CHARSET=latin1;
/*!40101 SET character_set_client = @saved_cs_client */;

--
-- Dumping data for table `account_group`
--

LOCK TABLES `account_group` WRITE;
/*!40000 ALTER TABLE `account_group` DISABLE KEYS */;
INSERT INTO `account_group` (`ACC_GROUP_ID`, `ACC_GROUP_DESCRIPTION`, `ACC_GROUP_STATUS`, `ACC_GROUP_SYSTEM_GENERATED`) VALUES (1,'Regular Users',2,2),(2,'System Admin',2,2);
/*!40000 ALTER TABLE `account_group` ENABLE KEYS */;
UNLOCK TABLES;

--
-- Table structure for table `account_level`
--

DROP TABLE IF EXISTS `account_level`;
/*!40101 SET @saved_cs_client     = @@character_set_client */;
/*!40101 SET character_set_client = utf8 */;
CREATE TABLE `account_level` (
  `ACC_LEVEL_ID` bigint(20) NOT NULL AUTO_INCREMENT,
  `ACC_LEVEL_SERVER_ID` bigint(20) NOT NULL,
  `ACC_LEVEL_TAG_ID` bigint(20) NOT NULL,
  `ACC_LEVEL_DESCRIPTION` varchar(500) CHARACTER SET utf8 COLLATE utf8_unicode_ci NOT NULL,
  `ACC_LEVEL_STATUS` tinyint(4) NOT NULL,
  `ACC_LEVEL_SYSTEM_GENERATED` tinyint(4) NOT NULL,
  PRIMARY KEY (`ACC_LEVEL_ID`)
) ENGINE=InnoDB AUTO_INCREMENT=5 DEFAULT CHARSET=latin1;
/*!40101 SET character_set_client = @saved_cs_client */;

--
-- Dumping data for table `account_level`
--

LOCK TABLES `account_level` WRITE;
/*!40000 ALTER TABLE `account_level` DISABLE KEYS */;
INSERT INTO `account_level` (`ACC_LEVEL_ID`, `ACC_LEVEL_SERVER_ID`, `ACC_LEVEL_TAG_ID`, `ACC_LEVEL_DESCRIPTION`, `ACC_LEVEL_STATUS`, `ACC_LEVEL_SYSTEM_GENERATED`) VALUES (0,0,1,'Unauthenticated Visitor',2,2),(1,0,1,'Visitor',2,2),(2,0,2,'Super Admin',2,2),(3,0,2,'Mobile Admin',2,2),(4,0,0,'Guard',2,1);
/*!40000 ALTER TABLE `account_level` ENABLE KEYS */;
UNLOCK TABLES;

--
-- Table structure for table `account_member`
--

DROP TABLE IF EXISTS `account_member`;
/*!40101 SET @saved_cs_client     = @@character_set_client */;
/*!40101 SET character_set_client = utf8 */;
CREATE TABLE `account_member` (
  `ACC_ACCOUNT_ID` bigint(20) NOT NULL AUTO_INCREMENT,
  `ACC_ACCOUNT_SERVER_ID` bigint(20) NOT NULL,
  `ACC_ACCOUNT_ACC_LEVEL_ID` bigint(20) NOT NULL,
  `ACC_ACCOUNT_ACC_GROUP_ID` bigint(20) NOT NULL,
  `ACC_ACCOUNT_ADD_RESOURCE_ID` bigint(20) NOT NULL,
  `ACC_ACCOUNT_USERNAME` varchar(500) CHARACTER SET utf8 COLLATE utf8_unicode_ci NOT NULL,
  `ACC_ACCOUNT_PASSWORD` varchar(500) CHARACTER SET utf8 COLLATE utf8_unicode_ci NOT NULL,
  `ACC_ACCOUNT_AUTH_CODE` varchar(500) CHARACTER SET utf8 COLLATE utf8_unicode_ci NOT NULL,
  `ACC_ACCOUNT_FIRST_NAME` varchar(500) CHARACTER SET utf8 COLLATE utf8_unicode_ci NOT NULL,
  `ACC_ACCOUNT_MIDDLE_NAME` varchar(500) CHARACTER SET utf8 COLLATE utf8_unicode_ci NOT NULL,
  `ACC_ACCOUNT_LAST_NAME` varchar(500) CHARACTER SET utf8 COLLATE utf8_unicode_ci NOT NULL,
  `ACC_ACCOUNT_POSITION` varchar(500) CHARACTER SET utf8 COLLATE utf8_unicode_ci NOT NULL,
  `ACC_ACCOUNT_SYS_GENDER_ID` bigint(20) NOT NULL,
  `ACC_ACCOUNT_STATUS` tinyint(4) NOT NULL,
  `ACC_ACCOUNT_SYSTEM_GENERATED` tinyint(4) NOT NULL,
  PRIMARY KEY (`ACC_ACCOUNT_ID`)
) ENGINE=InnoDB AUTO_INCREMENT=7 DEFAULT CHARSET=latin1;
/*!40101 SET character_set_client = @saved_cs_client */;

--
-- Dumping data for table `account_member`
--

LOCK TABLES `account_member` WRITE;
/*!40000 ALTER TABLE `account_member` DISABLE KEYS */;
INSERT INTO `account_member` (`ACC_ACCOUNT_ID`, `ACC_ACCOUNT_SERVER_ID`, `ACC_ACCOUNT_ACC_LEVEL_ID`, `ACC_ACCOUNT_ACC_GROUP_ID`, `ACC_ACCOUNT_ADD_RESOURCE_ID`, `ACC_ACCOUNT_USERNAME`, `ACC_ACCOUNT_PASSWORD`, `ACC_ACCOUNT_AUTH_CODE`, `ACC_ACCOUNT_FIRST_NAME`, `ACC_ACCOUNT_MIDDLE_NAME`, `ACC_ACCOUNT_LAST_NAME`, `ACC_ACCOUNT_POSITION`, `ACC_ACCOUNT_SYS_GENDER_ID`, `ACC_ACCOUNT_STATUS`, `ACC_ACCOUNT_SYSTEM_GENERATED`) VALUES (1,0,1,1,0,'visitor','$2y$10$NtfBfHpQXwMS/KYTpvV8b.J18cUajJ7/ubCCjltAOSCvJZuS4anAS','','VISITOR','DEFAULT','ACCOUNT','',2,1,2),(2,0,2,2,0,'admin','NePiE7V4WI85P8qe4GFq4MdUVk7SCIxg6331336639653633326366653437373362386136316562313065393230613730643033376330303334333136373834313333663732633235346262623532643331313162333162313438383632653136336262663165633965373831616561363233313638646532306266316364303038376665323437376334653039333037','','SUPER ADMIN','','SYSTEM','Administrator',1,2,2),(3,0,2,2,0,'system','$2y$10$NtfBfHpQXwMS/KYTpvV8b.J18cUajJ7/ubCCjltAOSCvJZuS4anAS','','SYSTEM',' ','ADMIN','',1,2,2),(4,0,3,2,0,'mobile','d29c0bdf712813be03f228202f33ac7b75a7efda510c910d58dc829e3c492e39677ac7db7cc932845e887d0f1bfcb0e474f855a56499e75ff2c8d0f08117d85b','','MOBILE',' ','ADMIN','',1,2,2),(5,0,2,2,0,'system_automation','6UGlJNVxnQlBOCBoHJdvoYTg6HxKIGrY3862653932616634663463303736643732316230353234616335366436393137626539376633353837663763396262303265333265393534306234326664653562666361303464663234366234323166623633343939313236643238303461343239643537613666323736393835396635356466343138383137393565346532','','AUTOMATION SYSTEM',' ','ADMIN','',1,2,2),(6,0,2,2,0,'administrator','6OT9hTI7oFRoRbXt1QIG8nshjpOqAPuK3366626364373661373062323534626434646136326235353262623436613364393162326431313139656330356430396236613236393831303239303462633138346232363732336539616137636631616533323738633433346664363338623366656162343239386236383035666539303039626561653965393136653665','','Master','','Administrator','Master Administrator',1,2,2);
/*!40000 ALTER TABLE `account_member` ENABLE KEYS */;
UNLOCK TABLES;

--
-- Table structure for table `account_proxy_access`
--

DROP TABLE IF EXISTS `account_proxy_access`;
/*!40101 SET @saved_cs_client     = @@character_set_client */;
/*!40101 SET character_set_client = utf8 */;
CREATE TABLE `account_proxy_access` (
  `ACC_PROXY_ID` bigint(20) NOT NULL AUTO_INCREMENT,
  `ACC_PROXY_AUTH_OWNER` varchar(1000) CHARACTER SET utf8 COLLATE utf8_unicode_ci NOT NULL,
  `ACC_PROXY_AUTH_HASH` varchar(1000) CHARACTER SET utf8 COLLATE utf8_unicode_ci NOT NULL,
  `ACC_PROXY_AUTH_STRING_VALIDATOR` varchar(5000) CHARACTER SET utf8 COLLATE utf8_unicode_ci NOT NULL,
  `ACC_PROXY_AUTH_BINARY_VALIDATOR` varbinary(40000) NOT NULL,
  `ACC_PROXY_STATUS` tinyint(4) NOT NULL,
  PRIMARY KEY (`ACC_PROXY_ID`)
) ENGINE=InnoDB DEFAULT CHARSET=latin1;
/*!40101 SET character_set_client = @saved_cs_client */;

--
-- Dumping data for table `account_proxy_access`
--

LOCK TABLES `account_proxy_access` WRITE;
/*!40000 ALTER TABLE `account_proxy_access` DISABLE KEYS */;
/*!40000 ALTER TABLE `account_proxy_access` ENABLE KEYS */;
UNLOCK TABLES;

--
-- Table structure for table `account_server`
--

DROP TABLE IF EXISTS `account_server`;
/*!40101 SET @saved_cs_client     = @@character_set_client */;
/*!40101 SET character_set_client = utf8 */;
CREATE TABLE `account_server` (
  `ACC_SERVER_ID` bigint(20) NOT NULL AUTO_INCREMENT,
  `ACC_SERVER_SERVER_ID` bigint(20) NOT NULL,
  `ACC_SERVER_TITLE` varchar(500) CHARACTER SET utf8 COLLATE utf8_unicode_ci NOT NULL,
  `ACC_SERVER_DESCRIPTION` varchar(500) CHARACTER SET utf8 COLLATE utf8_unicode_ci NOT NULL,
  `ACC_SERVER_UNIQUE_KEY` varchar(500) CHARACTER SET utf8 COLLATE utf8_unicode_ci NOT NULL,
  `ACC_SERVER_UNIQUE_PREFIX` varchar(50) CHARACTER SET utf8 COLLATE utf8_unicode_ci NOT NULL,
  `ACC_SERVER_IS_MOTHER` tinyint(4) NOT NULL,
  `ACC_SERVER_ADDRESS` varchar(500) CHARACTER SET utf8 COLLATE utf8_unicode_ci NOT NULL,
  `ACC_SERVER_LAST_SYNCHRONIZED` datetime(6) DEFAULT NULL,
  `ACC_SERVER_STATUS` tinyint(4) NOT NULL,
  `ACC_SERVER_SYNC_RESULT_DATASET` varchar(14000) CHARACTER SET utf8 COLLATE utf8_unicode_ci NOT NULL,
  `ACC_SERVER_SYNC_REQUEST_TYPE` tinyint(4) NOT NULL,
  `ACC_SERVER_SYNC_SUCCESS` tinyint(4) NOT NULL,
  `ACC_SERVER_SYSTEM_GENERATED` tinyint(4) NOT NULL,
  PRIMARY KEY (`ACC_SERVER_ID`)
) ENGINE=InnoDB DEFAULT CHARSET=latin1;
/*!40101 SET character_set_client = @saved_cs_client */;

--
-- Dumping data for table `account_server`
--

LOCK TABLES `account_server` WRITE;
/*!40000 ALTER TABLE `account_server` DISABLE KEYS */;
/*!40000 ALTER TABLE `account_server` ENABLE KEYS */;
UNLOCK TABLES;

--
-- Table structure for table `addon_license_group`
--

DROP TABLE IF EXISTS `addon_license_group`;
/*!40101 SET @saved_cs_client     = @@character_set_client */;
/*!40101 SET character_set_client = utf8 */;
CREATE TABLE `addon_license_group` (
  `ADD_GLICENSE_ID` bigint(20) NOT NULL AUTO_INCREMENT,
  `ADD_GLICENSE_ACC_GROUP_ID` bigint(20) NOT NULL,
  `ADD_GLICENSE_DATE_RENEW` datetime(6) DEFAULT NULL,
  `ADD_GLICENSE_DATE_EXPIRY` datetime(6) DEFAULT NULL,
  `ADD_GLICENSE_VOLUME` bigint(20) NOT NULL,
  `ADD_GLICENSE_STATUS` tinyint(4) NOT NULL,
  `ADD_GLICENSE_SYSTEM_GENERATED` tinyint(4) NOT NULL,
  PRIMARY KEY (`ADD_GLICENSE_ID`)
) ENGINE=InnoDB AUTO_INCREMENT=3 DEFAULT CHARSET=latin1;
/*!40101 SET character_set_client = @saved_cs_client */;

--
-- Dumping data for table `addon_license_group`
--

LOCK TABLES `addon_license_group` WRITE;
/*!40000 ALTER TABLE `addon_license_group` DISABLE KEYS */;
INSERT INTO `addon_license_group` (`ADD_GLICENSE_ID`, `ADD_GLICENSE_ACC_GROUP_ID`, `ADD_GLICENSE_DATE_RENEW`, `ADD_GLICENSE_DATE_EXPIRY`, `ADD_GLICENSE_VOLUME`, `ADD_GLICENSE_STATUS`, `ADD_GLICENSE_SYSTEM_GENERATED`) VALUES (1,1,'1900-01-01 00:00:00.000000','1900-01-01 00:00:00.000000',0,2,2),(2,2,'1900-01-01 00:00:00.000000','2300-12-31 23:59:59.999999',999,2,2);
/*!40000 ALTER TABLE `addon_license_group` ENABLE KEYS */;
UNLOCK TABLES;

--
-- Table structure for table `addon_license_user`
--

DROP TABLE IF EXISTS `addon_license_user`;
/*!40101 SET @saved_cs_client     = @@character_set_client */;
/*!40101 SET character_set_client = utf8 */;
CREATE TABLE `addon_license_user` (
  `ADD_ULICENSE_ID` bigint(20) NOT NULL AUTO_INCREMENT,
  `ADD_ULICENSE_ACC_ACCOUNT_ID` bigint(20) NOT NULL,
  `ADD_ULICENSE_DATE_RENEW` datetime(6) DEFAULT NULL,
  `ADD_ULICENSE_DATE_EXPIRY` datetime(6) DEFAULT NULL,
  `ADD_ULICENSE_VOLUME` bigint(20) NOT NULL,
  `ADD_ULICENSE_STATUS` tinyint(4) NOT NULL,
  `ADD_ULICENSE_SYSTEM_GENERATED` tinyint(4) NOT NULL,
  PRIMARY KEY (`ADD_ULICENSE_ID`)
) ENGINE=InnoDB AUTO_INCREMENT=5 DEFAULT CHARSET=latin1;
/*!40101 SET character_set_client = @saved_cs_client */;

--
-- Dumping data for table `addon_license_user`
--

LOCK TABLES `addon_license_user` WRITE;
/*!40000 ALTER TABLE `addon_license_user` DISABLE KEYS */;
INSERT INTO `addon_license_user` (`ADD_ULICENSE_ID`, `ADD_ULICENSE_ACC_ACCOUNT_ID`, `ADD_ULICENSE_DATE_RENEW`, `ADD_ULICENSE_DATE_EXPIRY`, `ADD_ULICENSE_VOLUME`, `ADD_ULICENSE_STATUS`, `ADD_ULICENSE_SYSTEM_GENERATED`) VALUES (1,1,'1900-01-01 00:00:00.000000','1900-01-01 00:00:00.000000',0,2,2),(2,2,'1900-01-01 00:00:00.000000','2300-12-31 23:59:59.999999',999,2,2),(3,3,'1900-01-01 00:00:00.000000','2300-12-31 23:59:59.999999',999,2,2),(4,4,'1900-01-01 00:00:00.000000','2300-12-31 23:59:59.999999',999,2,2);
/*!40000 ALTER TABLE `addon_license_user` ENABLE KEYS */;
UNLOCK TABLES;

--
-- Table structure for table `addon_queuing`
--

DROP TABLE IF EXISTS `addon_queuing`;
/*!40101 SET @saved_cs_client     = @@character_set_client */;
/*!40101 SET character_set_client = utf8 */;
CREATE TABLE `addon_queuing` (
  `ADD_QUEUING_ID` bigint(20) NOT NULL AUTO_INCREMENT,
  `ADD_QUEUING_NUMBER` bigint(20) NOT NULL,
  `ADD_QUEUING_EXTRA_VALUE` varchar(5000) CHARACTER SET utf8 COLLATE utf8_unicode_ci NOT NULL,
  `ADD_QUEUING_PUBLIC_KEY` varchar(500) CHARACTER SET utf8 COLLATE utf8_unicode_ci NOT NULL,
  `ADD_QUEUING_STATION` varchar(500) CHARACTER SET utf8 COLLATE utf8_unicode_ci NOT NULL,
  `ADD_QUEUING_REMARKS` varchar(4000) CHARACTER SET utf8 COLLATE utf8_unicode_ci NOT NULL,
  `ADD_QUEUING_DATE_REQUEST` datetime(6) DEFAULT NULL,
  `ADD_QUEUING_DATE_PROCESSED` datetime(6) DEFAULT NULL,
  `ADD_QUEUING_DATE_LAST_CALLED` datetime(6) DEFAULT NULL,
  `ADD_QUEUING_DATE_LAST_DISPLAYED` datetime(6) DEFAULT NULL,
  `ADD_QUEUING_STATUS` tinyint(4) NOT NULL,
  PRIMARY KEY (`ADD_QUEUING_ID`)
) ENGINE=InnoDB DEFAULT CHARSET=latin1;
/*!40101 SET character_set_client = @saved_cs_client */;

--
-- Dumping data for table `addon_queuing`
--

LOCK TABLES `addon_queuing` WRITE;
/*!40000 ALTER TABLE `addon_queuing` DISABLE KEYS */;
/*!40000 ALTER TABLE `addon_queuing` ENABLE KEYS */;
UNLOCK TABLES;

--
-- Table structure for table `addon_resource`
--

DROP TABLE IF EXISTS `addon_resource`;
/*!40101 SET @saved_cs_client     = @@character_set_client */;
/*!40101 SET character_set_client = utf8 */;
CREATE TABLE `addon_resource` (
  `ADD_RESOURCE_ID` bigint(20) NOT NULL AUTO_INCREMENT,
  `ADD_RESOURCE_GLOBAL_ID` varchar(400) CHARACTER SET utf8 COLLATE utf8_unicode_ci NOT NULL,
  `ADD_RESOURCE_GROUP_KEY` varchar(400) CHARACTER SET utf8 COLLATE utf8_unicode_ci NOT NULL,
  `ADD_RESOURCE_VALUE` varbinary(50000) DEFAULT NULL,
  `ADD_RESOURCE_PARAMETER` varchar(1000) CHARACTER SET utf8 COLLATE utf8_unicode_ci NOT NULL,
  `ADD_RESOURCE_REMARKS` varchar(1000) CHARACTER SET utf8 COLLATE utf8_unicode_ci NOT NULL,
  `ADD_RESOURCE_STATUS` tinyint(4) NOT NULL,
  PRIMARY KEY (`ADD_RESOURCE_ID`)
) ENGINE=InnoDB DEFAULT CHARSET=latin1;
/*!40101 SET character_set_client = @saved_cs_client */;

--
-- Dumping data for table `addon_resource`
--

LOCK TABLES `addon_resource` WRITE;
/*!40000 ALTER TABLE `addon_resource` DISABLE KEYS */;
/*!40000 ALTER TABLE `addon_resource` ENABLE KEYS */;
UNLOCK TABLES;

--
-- Table structure for table `category_address_barangay`
--

DROP TABLE IF EXISTS `category_address_barangay`;
/*!40101 SET @saved_cs_client     = @@character_set_client */;
/*!40101 SET character_set_client = utf8 */;
CREATE TABLE `category_address_barangay` (
  `CAT_BARANGAY_ID` bigint(20) NOT NULL AUTO_INCREMENT,
  `CAT_BARANGAY_GLOBAL_ID` varchar(400) CHARACTER SET utf8 COLLATE utf8_unicode_ci NOT NULL,
  `CAT_BARANGAY_CAT_MUNICIPALITY_ID` bigint(20) NOT NULL,
  `CAT_BARANGAY_CODE` varchar(50) CHARACTER SET utf8 COLLATE utf8_unicode_ci NOT NULL,
  `CAT_BARANGAY_DESCRIPTION` varchar(500) CHARACTER SET utf8 COLLATE utf8_unicode_ci NOT NULL,
  `CAT_BARANGAY_STATUS` tinyint(4) NOT NULL,
  `CAT_BARANGAY_SYSTEM_GENERATED` tinyint(4) NOT NULL,
  PRIMARY KEY (`CAT_BARANGAY_ID`)
) ENGINE=InnoDB DEFAULT CHARSET=latin1;
/*!40101 SET character_set_client = @saved_cs_client */;

--
-- Dumping data for table `category_address_barangay`
--

LOCK TABLES `category_address_barangay` WRITE;
/*!40000 ALTER TABLE `category_address_barangay` DISABLE KEYS */;
/*!40000 ALTER TABLE `category_address_barangay` ENABLE KEYS */;
UNLOCK TABLES;

--
-- Table structure for table `category_address_country`
--

DROP TABLE IF EXISTS `category_address_country`;
/*!40101 SET @saved_cs_client     = @@character_set_client */;
/*!40101 SET character_set_client = utf8 */;
CREATE TABLE `category_address_country` (
  `CAT_COUNTRY_ID` bigint(20) NOT NULL AUTO_INCREMENT,
  `CAT_COUNTRY_GLOBAL_ID` varchar(400) CHARACTER SET utf8 COLLATE utf8_unicode_ci NOT NULL,
  `CAT_COUNTRY_CODE` varchar(50) CHARACTER SET utf8 COLLATE utf8_unicode_ci NOT NULL,
  `CAT_COUNTRY_DESCRIPTION` varchar(500) CHARACTER SET utf8 COLLATE utf8_unicode_ci NOT NULL,
  `CAT_COUNTRY_STATUS` tinyint(4) NOT NULL,
  `CAT_COUNTRY_SYSTEM_GENERATED` tinyint(4) NOT NULL,
  PRIMARY KEY (`CAT_COUNTRY_ID`)
) ENGINE=InnoDB AUTO_INCREMENT=2 DEFAULT CHARSET=latin1;
/*!40101 SET character_set_client = @saved_cs_client */;

--
-- Dumping data for table `category_address_country`
--

LOCK TABLES `category_address_country` WRITE;
/*!40000 ALTER TABLE `category_address_country` DISABLE KEYS */;
INSERT INTO `category_address_country` (`CAT_COUNTRY_ID`, `CAT_COUNTRY_GLOBAL_ID`, `CAT_COUNTRY_CODE`, `CAT_COUNTRY_DESCRIPTION`, `CAT_COUNTRY_STATUS`, `CAT_COUNTRY_SYSTEM_GENERATED`) VALUES (1,'19R4.20180503.150707062922.DYYWK1R','X','Others',2,2);
/*!40000 ALTER TABLE `category_address_country` ENABLE KEYS */;
UNLOCK TABLES;

--
-- Table structure for table `category_address_municipality`
--

DROP TABLE IF EXISTS `category_address_municipality`;
/*!40101 SET @saved_cs_client     = @@character_set_client */;
/*!40101 SET character_set_client = utf8 */;
CREATE TABLE `category_address_municipality` (
  `CAT_MUNICIPALITY_ID` bigint(20) NOT NULL AUTO_INCREMENT,
  `CAT_MUNICIPALITY_GLOBAL_ID` varchar(400) CHARACTER SET utf8 COLLATE utf8_unicode_ci NOT NULL,
  `CAT_MUNICIPALITY_CAT_PROVINCE_ID` bigint(20) NOT NULL,
  `CAT_MUNICIPALITY_CODE` varchar(50) CHARACTER SET utf8 COLLATE utf8_unicode_ci NOT NULL,
  `CAT_MUNICIPALITY_DESCRIPTION` varchar(500) CHARACTER SET utf8 COLLATE utf8_unicode_ci NOT NULL,
  `CAT_MUNICIPALITY_ZIP_CODE` varchar(50) CHARACTER SET utf8 COLLATE utf8_unicode_ci NOT NULL,
  `CAT_MUNICIPALITY_PHONE_CODE` varchar(50) CHARACTER SET utf8 COLLATE utf8_unicode_ci NOT NULL,
  `CAT_MUNICIPALITY_STATUS` tinyint(4) NOT NULL,
  `CAT_MUNICIPALITY_SYSTEM_GENERATED` tinyint(4) NOT NULL,
  PRIMARY KEY (`CAT_MUNICIPALITY_ID`)
) ENGINE=InnoDB AUTO_INCREMENT=2 DEFAULT CHARSET=latin1;
/*!40101 SET character_set_client = @saved_cs_client */;

--
-- Dumping data for table `category_address_municipality`
--

LOCK TABLES `category_address_municipality` WRITE;
/*!40000 ALTER TABLE `category_address_municipality` DISABLE KEYS */;
INSERT INTO `category_address_municipality` (`CAT_MUNICIPALITY_ID`, `CAT_MUNICIPALITY_GLOBAL_ID`, `CAT_MUNICIPALITY_CAT_PROVINCE_ID`, `CAT_MUNICIPALITY_CODE`, `CAT_MUNICIPALITY_DESCRIPTION`, `CAT_MUNICIPALITY_ZIP_CODE`, `CAT_MUNICIPALITY_PHONE_CODE`, `CAT_MUNICIPALITY_STATUS`, `CAT_MUNICIPALITY_SYSTEM_GENERATED`) VALUES (1,'19R4.20180503.150740294444.166XHC3',1,'X','Others','','',2,2);
/*!40000 ALTER TABLE `category_address_municipality` ENABLE KEYS */;
UNLOCK TABLES;

--
-- Table structure for table `category_address_province`
--

DROP TABLE IF EXISTS `category_address_province`;
/*!40101 SET @saved_cs_client     = @@character_set_client */;
/*!40101 SET character_set_client = utf8 */;
CREATE TABLE `category_address_province` (
  `CAT_PROVINCE_ID` bigint(20) NOT NULL AUTO_INCREMENT,
  `CAT_PROVINCE_GLOBAL_ID` varchar(400) CHARACTER SET utf8 COLLATE utf8_unicode_ci NOT NULL,
  `CAT_PROVINCE_CAT_REGION_ID` bigint(20) NOT NULL,
  `CAT_PROVINCE_CODE` varchar(50) CHARACTER SET utf8 COLLATE utf8_unicode_ci NOT NULL,
  `CAT_PROVINCE_DESCRIPTION` varchar(500) CHARACTER SET utf8 COLLATE utf8_unicode_ci NOT NULL,
  `CAT_PROVINCE_STATUS` tinyint(4) NOT NULL,
  `CAT_PROVINCE_SYSTEM_GENERATED` tinyint(4) NOT NULL,
  PRIMARY KEY (`CAT_PROVINCE_ID`)
) ENGINE=InnoDB AUTO_INCREMENT=2 DEFAULT CHARSET=latin1;
/*!40101 SET character_set_client = @saved_cs_client */;

--
-- Dumping data for table `category_address_province`
--

LOCK TABLES `category_address_province` WRITE;
/*!40000 ALTER TABLE `category_address_province` DISABLE KEYS */;
INSERT INTO `category_address_province` (`CAT_PROVINCE_ID`, `CAT_PROVINCE_GLOBAL_ID`, `CAT_PROVINCE_CAT_REGION_ID`, `CAT_PROVINCE_CODE`, `CAT_PROVINCE_DESCRIPTION`, `CAT_PROVINCE_STATUS`, `CAT_PROVINCE_SYSTEM_GENERATED`) VALUES (1,'19R4.20180503.150809771369.3EJ4TOU',1,'X','Others',2,2);
/*!40000 ALTER TABLE `category_address_province` ENABLE KEYS */;
UNLOCK TABLES;

--
-- Table structure for table `category_address_region`
--

DROP TABLE IF EXISTS `category_address_region`;
/*!40101 SET @saved_cs_client     = @@character_set_client */;
/*!40101 SET character_set_client = utf8 */;
CREATE TABLE `category_address_region` (
  `CAT_REGION_ID` bigint(20) NOT NULL AUTO_INCREMENT,
  `CAT_REGION_GLOBAL_ID` varchar(400) CHARACTER SET utf8 COLLATE utf8_unicode_ci NOT NULL,
  `CAT_REGION_CAT_COUNTRY_ID` bigint(20) NOT NULL,
  `CAT_REGION_CODE` varchar(50) CHARACTER SET utf8 COLLATE utf8_unicode_ci NOT NULL,
  `CAT_REGION_DESCRIPTION` varchar(500) CHARACTER SET utf8 COLLATE utf8_unicode_ci NOT NULL,
  `CAT_REGION_STATUS` tinyint(4) NOT NULL,
  `CAT_REGION_SYSTEM_GENERATED` tinyint(4) NOT NULL,
  PRIMARY KEY (`CAT_REGION_ID`)
) ENGINE=InnoDB AUTO_INCREMENT=2 DEFAULT CHARSET=latin1;
/*!40101 SET character_set_client = @saved_cs_client */;

--
-- Dumping data for table `category_address_region`
--

LOCK TABLES `category_address_region` WRITE;
/*!40000 ALTER TABLE `category_address_region` DISABLE KEYS */;
INSERT INTO `category_address_region` (`CAT_REGION_ID`, `CAT_REGION_GLOBAL_ID`, `CAT_REGION_CAT_COUNTRY_ID`, `CAT_REGION_CODE`, `CAT_REGION_DESCRIPTION`, `CAT_REGION_STATUS`, `CAT_REGION_SYSTEM_GENERATED`) VALUES (1,'19R4.20180503.151411011269.MS3PVDS',1,'X','Others',2,2);
/*!40000 ALTER TABLE `category_address_region` ENABLE KEYS */;
UNLOCK TABLES;

--
-- Table structure for table `category_department`
--

DROP TABLE IF EXISTS `category_department`;
/*!40101 SET @saved_cs_client     = @@character_set_client */;
/*!40101 SET character_set_client = utf8 */;
CREATE TABLE `category_department` (
  `CAT_DEPARTMENT_ID` bigint(20) NOT NULL AUTO_INCREMENT,
  `CAT_DEPARTMENT_DESCRIPTION` varchar(400) CHARACTER SET utf8 COLLATE utf8_unicode_ci NOT NULL,
  `CAT_DEPARTMENT_STATUS` tinyint(4) NOT NULL,
  PRIMARY KEY (`CAT_DEPARTMENT_ID`)
) ENGINE=InnoDB AUTO_INCREMENT=5 DEFAULT CHARSET=latin1;
/*!40101 SET character_set_client = @saved_cs_client */;

--
-- Dumping data for table `category_department`
--

LOCK TABLES `category_department` WRITE;
/*!40000 ALTER TABLE `category_department` DISABLE KEYS */;
INSERT INTO `category_department` (`CAT_DEPARTMENT_ID`, `CAT_DEPARTMENT_DESCRIPTION`, `CAT_DEPARTMENT_STATUS`) VALUES (1,'Supplies Division',2),(2,'Human Resources',2),(3,'Records Division',2),(4,'Department A',2);
/*!40000 ALTER TABLE `category_department` ENABLE KEYS */;
UNLOCK TABLES;

--
-- Table structure for table `category_entrance`
--

DROP TABLE IF EXISTS `category_entrance`;
/*!40101 SET @saved_cs_client     = @@character_set_client */;
/*!40101 SET character_set_client = utf8 */;
CREATE TABLE `category_entrance` (
  `CAT_ENTRANCE_ID` bigint(20) NOT NULL AUTO_INCREMENT,
  `CAT_ENTRANCE_DESCRIPTION` varchar(400) CHARACTER SET utf8 COLLATE utf8_unicode_ci NOT NULL,
  `CAT_ENTRANCE_DIRECTION` bigint(20) NOT NULL,
  `CAT_ENTRANCE_STATUS` tinyint(4) NOT NULL,
  PRIMARY KEY (`CAT_ENTRANCE_ID`)
) ENGINE=InnoDB AUTO_INCREMENT=3 DEFAULT CHARSET=latin1;
/*!40101 SET character_set_client = @saved_cs_client */;

--
-- Dumping data for table `category_entrance`
--

LOCK TABLES `category_entrance` WRITE;
/*!40000 ALTER TABLE `category_entrance` DISABLE KEYS */;
INSERT INTO `category_entrance` (`CAT_ENTRANCE_ID`, `CAT_ENTRANCE_DESCRIPTION`, `CAT_ENTRANCE_DIRECTION`, `CAT_ENTRANCE_STATUS`) VALUES (1,'Entrance',2,2),(2,'Exit',2,2);
/*!40000 ALTER TABLE `category_entrance` ENABLE KEYS */;
UNLOCK TABLES;

--
-- Table structure for table `category_nationality`
--

DROP TABLE IF EXISTS `category_nationality`;
/*!40101 SET @saved_cs_client     = @@character_set_client */;
/*!40101 SET character_set_client = utf8 */;
CREATE TABLE `category_nationality` (
  `CAT_NATIONALITY_ID` bigint(20) NOT NULL AUTO_INCREMENT,
  `CAT_NATIONALITY_GLOBAL_ID` varchar(400) CHARACTER SET utf8 COLLATE utf8_unicode_ci NOT NULL,
  `CAT_NATIONALITY_CODE` varchar(50) CHARACTER SET utf8 COLLATE utf8_unicode_ci NOT NULL,
  `CAT_NATIONALITY_DESCRIPTION` varchar(500) CHARACTER SET utf8 COLLATE utf8_unicode_ci NOT NULL,
  `CAT_NATIONALITY_STATUS` tinyint(4) NOT NULL,
  `CAT_NATIONALITY_SYSTEM_GENERATED` tinyint(4) NOT NULL,
  PRIMARY KEY (`CAT_NATIONALITY_ID`)
) ENGINE=InnoDB AUTO_INCREMENT=2 DEFAULT CHARSET=latin1;
/*!40101 SET character_set_client = @saved_cs_client */;

--
-- Dumping data for table `category_nationality`
--

LOCK TABLES `category_nationality` WRITE;
/*!40000 ALTER TABLE `category_nationality` DISABLE KEYS */;
INSERT INTO `category_nationality` (`CAT_NATIONALITY_ID`, `CAT_NATIONALITY_GLOBAL_ID`, `CAT_NATIONALITY_CODE`, `CAT_NATIONALITY_DESCRIPTION`, `CAT_NATIONALITY_STATUS`, `CAT_NATIONALITY_SYSTEM_GENERATED`) VALUES (1,'','','Others',2,1);
/*!40000 ALTER TABLE `category_nationality` ENABLE KEYS */;
UNLOCK TABLES;

--
-- Table structure for table `category_property`
--

DROP TABLE IF EXISTS `category_property`;
/*!40101 SET @saved_cs_client     = @@character_set_client */;
/*!40101 SET character_set_client = utf8 */;
CREATE TABLE `category_property` (
  `CAT_PROPERTY_ID` bigint(20) NOT NULL AUTO_INCREMENT,
  `CAT_PROPERTY_DESCRIPTION` varchar(400) CHARACTER SET utf8 COLLATE utf8_unicode_ci NOT NULL,
  `CAT_PROPERTY_STRING` varchar(4000) CHARACTER SET utf8 COLLATE utf8_unicode_ci NOT NULL,
  `CAT_PROPERTY_NUMERIC` bigint(20) NOT NULL,
  `CAT_PROPERTY_DECIMAL` decimal(18,2) NOT NULL,
  `CAT_PROPERTY_STATUS` tinyint(4) NOT NULL,
  PRIMARY KEY (`CAT_PROPERTY_ID`)
) ENGINE=InnoDB DEFAULT CHARSET=latin1;
/*!40101 SET character_set_client = @saved_cs_client */;

--
-- Dumping data for table `category_property`
--

LOCK TABLES `category_property` WRITE;
/*!40000 ALTER TABLE `category_property` DISABLE KEYS */;
/*!40000 ALTER TABLE `category_property` ENABLE KEYS */;
UNLOCK TABLES;

--
-- Table structure for table `category_religion`
--

DROP TABLE IF EXISTS `category_religion`;
/*!40101 SET @saved_cs_client     = @@character_set_client */;
/*!40101 SET character_set_client = utf8 */;
CREATE TABLE `category_religion` (
  `CAT_RELIGION_ID` bigint(20) NOT NULL AUTO_INCREMENT,
  `CAT_RELIGION_GLOBAL_ID` varchar(400) CHARACTER SET utf8 COLLATE utf8_unicode_ci NOT NULL,
  `CAT_RELIGION_CODE` varchar(50) CHARACTER SET utf8 COLLATE utf8_unicode_ci NOT NULL,
  `CAT_RELIGION_DESCRIPTION` varchar(500) CHARACTER SET utf8 COLLATE utf8_unicode_ci NOT NULL,
  `CAT_RELIGION_STATUS` tinyint(4) NOT NULL,
  `CAT_RELIGION_SYSTEM_GENERATED` tinyint(4) NOT NULL,
  PRIMARY KEY (`CAT_RELIGION_ID`)
) ENGINE=InnoDB AUTO_INCREMENT=2 DEFAULT CHARSET=latin1;
/*!40101 SET character_set_client = @saved_cs_client */;

--
-- Dumping data for table `category_religion`
--

LOCK TABLES `category_religion` WRITE;
/*!40000 ALTER TABLE `category_religion` DISABLE KEYS */;
INSERT INTO `category_religion` (`CAT_RELIGION_ID`, `CAT_RELIGION_GLOBAL_ID`, `CAT_RELIGION_CODE`, `CAT_RELIGION_DESCRIPTION`, `CAT_RELIGION_STATUS`, `CAT_RELIGION_SYSTEM_GENERATED`) VALUES (1,'','','Others',2,1);
/*!40000 ALTER TABLE `category_religion` ENABLE KEYS */;
UNLOCK TABLES;

--
-- Table structure for table `category_section`
--

DROP TABLE IF EXISTS `category_section`;
/*!40101 SET @saved_cs_client     = @@character_set_client */;
/*!40101 SET character_set_client = utf8 */;
CREATE TABLE `category_section` (
  `CAT_SECTION_ID` bigint(20) NOT NULL AUTO_INCREMENT,
  `CAT_SECTION_CAT_DEPARTMENT_ID` bigint(20) NOT NULL,
  `CAT_SECTION_DESCRIPTION` varchar(400) CHARACTER SET utf8 COLLATE utf8_unicode_ci NOT NULL,
  `CAT_SECTION_STATUS` tinyint(4) NOT NULL,
  PRIMARY KEY (`CAT_SECTION_ID`)
) ENGINE=InnoDB AUTO_INCREMENT=4 DEFAULT CHARSET=latin1;
/*!40101 SET character_set_client = @saved_cs_client */;

--
-- Dumping data for table `category_section`
--

LOCK TABLES `category_section` WRITE;
/*!40000 ALTER TABLE `category_section` DISABLE KEYS */;
INSERT INTO `category_section` (`CAT_SECTION_ID`, `CAT_SECTION_CAT_DEPARTMENT_ID`, `CAT_SECTION_DESCRIPTION`, `CAT_SECTION_STATUS`) VALUES (1,2,'Main',2),(2,1,'Technical Support',2),(3,1,'Warehosue Management',2);
/*!40000 ALTER TABLE `category_section` ENABLE KEYS */;
UNLOCK TABLES;

--
-- Table structure for table `mobile_contact`
--

DROP TABLE IF EXISTS `mobile_contact`;
/*!40101 SET @saved_cs_client     = @@character_set_client */;
/*!40101 SET character_set_client = utf8 */;
CREATE TABLE `mobile_contact` (
  `MOB_CONTACT_ID` bigint(20) NOT NULL AUTO_INCREMENT,
  `MOB_CONTACT_ACC_GROUP_ID` bigint(20) NOT NULL,
  `MOB_CONTACT_MOBILE` varchar(50) CHARACTER SET utf8 COLLATE utf8_unicode_ci NOT NULL,
  `MOB_CONTACT_DESCRIPTION` varchar(500) CHARACTER SET utf8 COLLATE utf8_unicode_ci NOT NULL,
  `MOB_CONTACT_STATUS` tinyint(4) NOT NULL,
  PRIMARY KEY (`MOB_CONTACT_ID`)
) ENGINE=InnoDB DEFAULT CHARSET=latin1;
/*!40101 SET character_set_client = @saved_cs_client */;

--
-- Dumping data for table `mobile_contact`
--

LOCK TABLES `mobile_contact` WRITE;
/*!40000 ALTER TABLE `mobile_contact` DISABLE KEYS */;
/*!40000 ALTER TABLE `mobile_contact` ENABLE KEYS */;
UNLOCK TABLES;

--
-- Table structure for table `mobile_inbox`
--

DROP TABLE IF EXISTS `mobile_inbox`;
/*!40101 SET @saved_cs_client     = @@character_set_client */;
/*!40101 SET character_set_client = utf8 */;
CREATE TABLE `mobile_inbox` (
  `MOB_INBOX_ID` bigint(20) NOT NULL AUTO_INCREMENT,
  `MOB_INBOX_TRANSACTION_ID` varchar(500) CHARACTER SET utf8 COLLATE utf8_unicode_ci NOT NULL,
  `MOB_INBOX_SHORTCODE` varchar(500) CHARACTER SET utf8 COLLATE utf8_unicode_ci NOT NULL,
  `MOB_INBOX_COMPANY_CODE` varchar(50) CHARACTER SET utf8 COLLATE utf8_unicode_ci NOT NULL,
  `MOB_INBOX_MOBILE_NUMBER` varchar(500) CHARACTER SET utf8 COLLATE utf8_unicode_ci NOT NULL,
  `MOB_INBOX_SERVICE_CODE` varchar(500) CHARACTER SET utf8 COLLATE utf8_unicode_ci NOT NULL,
  `MOB_INBOX_MESSAGE` varchar(9000) CHARACTER SET utf8 COLLATE utf8_unicode_ci NOT NULL,
  `MOB_INBOX_RESPONSE` varchar(9000) CHARACTER SET utf8 COLLATE utf8_unicode_ci NOT NULL,
  `MOB_INBOX_CHARGE` varchar(500) CHARACTER SET utf8 COLLATE utf8_unicode_ci NOT NULL,
  `MOB_INBOX_TIMESTAMP` datetime(6) DEFAULT NULL,
  `MOB_INBOX_RESULT` varchar(500) CHARACTER SET utf8 COLLATE utf8_unicode_ci NOT NULL,
  `MOB_INBOX_STATUS` tinyint(4) NOT NULL,
  PRIMARY KEY (`MOB_INBOX_ID`)
) ENGINE=InnoDB DEFAULT CHARSET=latin1;
/*!40101 SET character_set_client = @saved_cs_client */;

--
-- Dumping data for table `mobile_inbox`
--

LOCK TABLES `mobile_inbox` WRITE;
/*!40000 ALTER TABLE `mobile_inbox` DISABLE KEYS */;
/*!40000 ALTER TABLE `mobile_inbox` ENABLE KEYS */;
UNLOCK TABLES;

--
-- Table structure for table `mobile_loadflow`
--

DROP TABLE IF EXISTS `mobile_loadflow`;
/*!40101 SET @saved_cs_client     = @@character_set_client */;
/*!40101 SET character_set_client = utf8 */;
CREATE TABLE `mobile_loadflow` (
  `MOB_LOADFLOW_ID` bigint(20) NOT NULL AUTO_INCREMENT,
  `MOB_LOADFLOW_MOBILE_ID` bigint(20) NOT NULL,
  `MOB_LOADFLOW_CODE` varchar(500) CHARACTER SET utf8 COLLATE utf8_unicode_ci NOT NULL,
  `MOB_LOADFLOW_DESCRIPTION` varchar(500) CHARACTER SET utf8 COLLATE utf8_unicode_ci NOT NULL,
  `MOB_LOADFLOW_AMOUNT` decimal(18,2) NOT NULL,
  `MOB_LOADFLOW_TIMESTAMP` datetime(6) DEFAULT NULL,
  `MOB_LOADFLOW_STATUS` tinyint(4) NOT NULL,
  PRIMARY KEY (`MOB_LOADFLOW_ID`)
) ENGINE=InnoDB DEFAULT CHARSET=latin1;
/*!40101 SET character_set_client = @saved_cs_client */;

--
-- Dumping data for table `mobile_loadflow`
--

LOCK TABLES `mobile_loadflow` WRITE;
/*!40000 ALTER TABLE `mobile_loadflow` DISABLE KEYS */;
/*!40000 ALTER TABLE `mobile_loadflow` ENABLE KEYS */;
UNLOCK TABLES;

--
-- Table structure for table `mobile_notification`
--

DROP TABLE IF EXISTS `mobile_notification`;
/*!40101 SET @saved_cs_client     = @@character_set_client */;
/*!40101 SET character_set_client = utf8 */;
CREATE TABLE `mobile_notification` (
  `MOB_NRECEIVER_ID` bigint(20) NOT NULL AUTO_INCREMENT,
  `MOB_NRECEIVER_TRANSACTION_ID` varchar(500) CHARACTER SET utf8 COLLATE utf8_unicode_ci NOT NULL,
  `MOB_NRECEIVER_SHORTCODE` varchar(500) CHARACTER SET utf8 COLLATE utf8_unicode_ci NOT NULL,
  `MOB_NRECEIVER_APPLIED_CHARGE` varchar(500) CHARACTER SET utf8 COLLATE utf8_unicode_ci NOT NULL,
  `MOB_NRECEIVER_TIMESTAMP` datetime(6) DEFAULT NULL,
  `MOB_NRECEIVER_RESULT` varchar(500) CHARACTER SET utf8 COLLATE utf8_unicode_ci NOT NULL,
  `MOB_NRECEIVER_STATUS` tinyint(4) NOT NULL,
  PRIMARY KEY (`MOB_NRECEIVER_ID`)
) ENGINE=InnoDB DEFAULT CHARSET=latin1;
/*!40101 SET character_set_client = @saved_cs_client */;

--
-- Dumping data for table `mobile_notification`
--

LOCK TABLES `mobile_notification` WRITE;
/*!40000 ALTER TABLE `mobile_notification` DISABLE KEYS */;
/*!40000 ALTER TABLE `mobile_notification` ENABLE KEYS */;
UNLOCK TABLES;

--
-- Table structure for table `mobile_outbox`
--

DROP TABLE IF EXISTS `mobile_outbox`;
/*!40101 SET @saved_cs_client     = @@character_set_client */;
/*!40101 SET character_set_client = utf8 */;
CREATE TABLE `mobile_outbox` (
  `MOB_OUTBOX_ID` bigint(20) NOT NULL AUTO_INCREMENT,
  `MOB_OUTBOX_TRANSACTION_ID` varchar(500) CHARACTER SET utf8 COLLATE utf8_unicode_ci NOT NULL,
  `MOB_OUTBOX_SHORTCODE` varchar(500) CHARACTER SET utf8 COLLATE utf8_unicode_ci NOT NULL,
  `MOB_OUTBOX_COMPANY_CODE` varchar(50) CHARACTER SET utf8 COLLATE utf8_unicode_ci NOT NULL,
  `MOB_OUTBOX_MOBILE_NUMBER` varchar(500) CHARACTER SET utf8 COLLATE utf8_unicode_ci NOT NULL,
  `MOB_OUTBOX_MESSAGE` varchar(10000) CHARACTER SET utf8 COLLATE utf8_unicode_ci NOT NULL,
  `MOB_OUTBOX_TIMESTAMP` datetime(6) DEFAULT NULL,
  `MOB_OUTBOX_RESULT` varchar(500) CHARACTER SET utf8 COLLATE utf8_unicode_ci NOT NULL,
  `MOB_OUTBOX_STATUS` tinyint(4) NOT NULL,
  PRIMARY KEY (`MOB_OUTBOX_ID`)
) ENGINE=InnoDB DEFAULT CHARSET=latin1;
/*!40101 SET character_set_client = @saved_cs_client */;

--
-- Dumping data for table `mobile_outbox`
--

LOCK TABLES `mobile_outbox` WRITE;
/*!40000 ALTER TABLE `mobile_outbox` DISABLE KEYS */;
/*!40000 ALTER TABLE `mobile_outbox` ENABLE KEYS */;
UNLOCK TABLES;

--
-- Table structure for table `mobile_outbox_history`
--

DROP TABLE IF EXISTS `mobile_outbox_history`;
/*!40101 SET @saved_cs_client     = @@character_set_client */;
/*!40101 SET character_set_client = utf8 */;
CREATE TABLE `mobile_outbox_history` (
  `MOB_OUTHISTORY_ID` bigint(20) NOT NULL AUTO_INCREMENT,
  `MOB_OUTHISTORY_OUTBOX_ID` bigint(20) NOT NULL,
  `MOB_OUTHISTORY_TRANSACTION_ID` varchar(500) CHARACTER SET utf8 COLLATE utf8_unicode_ci NOT NULL,
  `MOB_OUTHISTORY_MOBILE_NUMBER` varchar(50) CHARACTER SET utf8 COLLATE utf8_unicode_ci NOT NULL,
  `MOB_OUTHISTORY_STATUS` tinyint(4) NOT NULL,
  PRIMARY KEY (`MOB_OUTHISTORY_ID`)
) ENGINE=InnoDB DEFAULT CHARSET=latin1;
/*!40101 SET character_set_client = @saved_cs_client */;

--
-- Dumping data for table `mobile_outbox_history`
--

LOCK TABLES `mobile_outbox_history` WRITE;
/*!40000 ALTER TABLE `mobile_outbox_history` DISABLE KEYS */;
/*!40000 ALTER TABLE `mobile_outbox_history` ENABLE KEYS */;
UNLOCK TABLES;

--
-- Table structure for table `mobile_service_code`
--

DROP TABLE IF EXISTS `mobile_service_code`;
/*!40101 SET @saved_cs_client     = @@character_set_client */;
/*!40101 SET character_set_client = utf8 */;
CREATE TABLE `mobile_service_code` (
  `MOB_SCODE_ID` bigint(20) NOT NULL AUTO_INCREMENT,
  `MOB_SCODE_SHORTCODE` varchar(500) CHARACTER SET utf8 COLLATE utf8_unicode_ci NOT NULL,
  `MOB_SCODE_COMPANY_CODE` varchar(50) CHARACTER SET utf8 COLLATE utf8_unicode_ci NOT NULL,
  `MOB_SCODE_CODE` varchar(500) CHARACTER SET utf8 COLLATE utf8_unicode_ci NOT NULL,
  `MOB_SCODE_RESPONSE` varchar(500) CHARACTER SET utf8 COLLATE utf8_unicode_ci NOT NULL,
  `MOB_SCODE_CHARGE` varchar(500) CHARACTER SET utf8 COLLATE utf8_unicode_ci NOT NULL,
  `MOB_SCODE_FILTER_STATUS` tinyint(4) NOT NULL,
  `MOB_SCODE_FILTER_LIMIT` int(11) NOT NULL,
  `MOB_SCODE_FILTER_TIME` bigint(20) NOT NULL,
  `MOB_SCODE_STATUS` tinyint(4) NOT NULL,
  PRIMARY KEY (`MOB_SCODE_ID`)
) ENGINE=InnoDB AUTO_INCREMENT=7 DEFAULT CHARSET=latin1;
/*!40101 SET character_set_client = @saved_cs_client */;

--
-- Dumping data for table `mobile_service_code`
--

LOCK TABLES `mobile_service_code` WRITE;
/*!40000 ALTER TABLE `mobile_service_code` DISABLE KEYS */;
INSERT INTO `mobile_service_code` (`MOB_SCODE_ID`, `MOB_SCODE_SHORTCODE`, `MOB_SCODE_COMPANY_CODE`, `MOB_SCODE_CODE`, `MOB_SCODE_RESPONSE`, `MOB_SCODE_CHARGE`, `MOB_SCODE_FILTER_STATUS`, `MOB_SCODE_FILTER_LIMIT`, `MOB_SCODE_FILTER_TIME`, `MOB_SCODE_STATUS`) VALUES (1,'29290226','','ON_ERROR','Incorrect code. Please check your code and try again.','P1.00',1,1,0,2),(2,'29290226','','ON_SPAM','Sorry, this service is not available with your number.','P1.00',1,999999,0,2),(3,'29290226','','ON_VOLUME_LIMIT','Similar request has already been processed. Please try again later.','P1.00',1,1,0,2),(4,'29290000','','ON_ERROR','Incorrect code. Please check your code and try again.','P1.00',1,999999,0,2),(5,'29290000','','ON_SPAM','Sorry, this service is not available with your number.','P1.00',1,999999,0,2),(6,'29290000','','ON_VOLUME_LIMIT','Similar request has already been processed. Please try again later.','P1.00',1,999999,0,2);
/*!40000 ALTER TABLE `mobile_service_code` ENABLE KEYS */;
UNLOCK TABLES;

--
-- Table structure for table `mobile_shortcode`
--

DROP TABLE IF EXISTS `mobile_shortcode`;
/*!40101 SET @saved_cs_client     = @@character_set_client */;
/*!40101 SET character_set_client = utf8 */;
CREATE TABLE `mobile_shortcode` (
  `MOB_MOBILE_ID` bigint(20) NOT NULL AUTO_INCREMENT,
  `MOB_MOBILE_GROUP_ID` bigint(20) NOT NULL,
  `MOB_MOBILE_SHORTCODE` varchar(500) CHARACTER SET utf8 COLLATE utf8_unicode_ci NOT NULL,
  `MOB_MOBILE_COMPANY_CODE` varchar(50) CHARACTER SET utf8 COLLATE utf8_unicode_ci NOT NULL,
  `MOB_MOBILE_CLIENT_ID` varchar(500) CHARACTER SET utf8 COLLATE utf8_unicode_ci NOT NULL,
  `MOB_MOBILE_SECRET_KEY` varchar(500) CHARACTER SET utf8 COLLATE utf8_unicode_ci NOT NULL,
  `MOB_MOBILE_LOAD_BALANCE` decimal(18,2) NOT NULL,
  `MOB_MOBILE_STATUS` tinyint(4) NOT NULL,
  PRIMARY KEY (`MOB_MOBILE_ID`)
) ENGINE=InnoDB DEFAULT CHARSET=latin1;
/*!40101 SET character_set_client = @saved_cs_client */;

--
-- Dumping data for table `mobile_shortcode`
--

LOCK TABLES `mobile_shortcode` WRITE;
/*!40000 ALTER TABLE `mobile_shortcode` DISABLE KEYS */;
/*!40000 ALTER TABLE `mobile_shortcode` ENABLE KEYS */;
UNLOCK TABLES;

--
-- Table structure for table `mobile_volume_control`
--

DROP TABLE IF EXISTS `mobile_volume_control`;
/*!40101 SET @saved_cs_client     = @@character_set_client */;
/*!40101 SET character_set_client = utf8 */;
CREATE TABLE `mobile_volume_control` (
  `MOB_VOLCONTROL_ID` bigint(20) NOT NULL AUTO_INCREMENT,
  `MOB_VOLCONTROL_SCODE_ID` bigint(20) NOT NULL,
  `MOB_VOLCONTROL_RESET_TIME` datetime(6) DEFAULT NULL,
  `MOB_VOLCONTROL_MODIFIED_TIME` datetime(6) DEFAULT NULL,
  `MOB_VOLCONTROL_STATUS` tinyint(4) NOT NULL,
  PRIMARY KEY (`MOB_VOLCONTROL_ID`)
) ENGINE=InnoDB DEFAULT CHARSET=latin1;
/*!40101 SET character_set_client = @saved_cs_client */;

--
-- Dumping data for table `mobile_volume_control`
--

LOCK TABLES `mobile_volume_control` WRITE;
/*!40000 ALTER TABLE `mobile_volume_control` DISABLE KEYS */;
/*!40000 ALTER TABLE `mobile_volume_control` ENABLE KEYS */;
UNLOCK TABLES;

--
-- Table structure for table `record_attendance`
--

DROP TABLE IF EXISTS `record_attendance`;
/*!40101 SET @saved_cs_client     = @@character_set_client */;
/*!40101 SET character_set_client = utf8 */;
CREATE TABLE `record_attendance` (
  `REC_ATTENDANCE_ID` bigint(20) NOT NULL AUTO_INCREMENT,
  `REC_ATTENDANCE_REC_USER_ID` bigint(20) NOT NULL,
  `REC_ATTENDANCE_DATE` datetime(6) DEFAULT NULL,
  `REC_ATTENDANCE_IS_IN` tinyint(4) NOT NULL,
  `REC_ATTENDANCE_IS_OUT` tinyint(4) NOT NULL,
  `REC_ATTENDANCE_ENTRANCE` varchar(400) CHARACTER SET utf8 COLLATE utf8_unicode_ci NOT NULL,
  `REC_ATTENDANCE_DEVICE_KEY` varchar(4000) CHARACTER SET utf8 COLLATE utf8_unicode_ci NOT NULL,
  `REC_ATTENDANCE_STATUS` tinyint(4) NOT NULL,
  PRIMARY KEY (`REC_ATTENDANCE_ID`)
) ENGINE=InnoDB AUTO_INCREMENT=3 DEFAULT CHARSET=latin1;
/*!40101 SET character_set_client = @saved_cs_client */;

--
-- Dumping data for table `record_attendance`
--

LOCK TABLES `record_attendance` WRITE;
/*!40000 ALTER TABLE `record_attendance` DISABLE KEYS */;
INSERT INTO `record_attendance` (`REC_ATTENDANCE_ID`, `REC_ATTENDANCE_REC_USER_ID`, `REC_ATTENDANCE_DATE`, `REC_ATTENDANCE_IS_IN`, `REC_ATTENDANCE_IS_OUT`, `REC_ATTENDANCE_ENTRANCE`, `REC_ATTENDANCE_DEVICE_KEY`, `REC_ATTENDANCE_STATUS`) VALUES (1,1,'2021-01-19 10:45:17.612259',2,1,'Entrance','cec3ddbdce6dae96.RMX2040',2),(2,4,'2021-01-19 11:38:26.897443',2,1,'Exit','cec3ddbdce6dae96.RMX2040',2);
/*!40000 ALTER TABLE `record_attendance` ENABLE KEYS */;
UNLOCK TABLES;

--
-- Table structure for table `record_device`
--

DROP TABLE IF EXISTS `record_device`;
/*!40101 SET @saved_cs_client     = @@character_set_client */;
/*!40101 SET character_set_client = utf8 */;
CREATE TABLE `record_device` (
  `REC_DEVICE_ID` bigint(20) NOT NULL AUTO_INCREMENT,
  `REC_DEVICE_CODE` varchar(40) CHARACTER SET utf8 COLLATE utf8_unicode_ci NOT NULL,
  `REC_DEVICE_DESCRIPTION` varchar(400) CHARACTER SET utf8 COLLATE utf8_unicode_ci NOT NULL,
  `REC_DEVICE_ENTRANCE_NAME` varchar(400) CHARACTER SET utf8 COLLATE utf8_unicode_ci NOT NULL,
  `REC_DEVICE_IS_IN` tinyint(4) NOT NULL,
  `REC_DEVICE_STATUS` tinyint(4) NOT NULL,
  PRIMARY KEY (`REC_DEVICE_ID`),
  UNIQUE KEY `REC_DEVICE_CODE` (`REC_DEVICE_CODE`)
) ENGINE=InnoDB DEFAULT CHARSET=latin1;
/*!40101 SET character_set_client = @saved_cs_client */;

--
-- Dumping data for table `record_device`
--

LOCK TABLES `record_device` WRITE;
/*!40000 ALTER TABLE `record_device` DISABLE KEYS */;
/*!40000 ALTER TABLE `record_device` ENABLE KEYS */;
UNLOCK TABLES;

--
-- Table structure for table `record_registration`
--

DROP TABLE IF EXISTS `record_registration`;
/*!40101 SET @saved_cs_client     = @@character_set_client */;
/*!40101 SET character_set_client = utf8 */;
CREATE TABLE `record_registration` (
  `REC_REGISTRATION_ID` bigint(20) NOT NULL AUTO_INCREMENT,
  `REC_REGISTRATION_REC_USER_ID` bigint(20) NOT NULL,
  `REC_REGISTRATION_CAT_DEPARTMENT_ID` bigint(20) NOT NULL,
  `REC_REGISTRATION_CAT_SECTION_ID` bigint(20) NOT NULL,
  `REC_REGISTRATION_FIRST_NAME` varchar(400) CHARACTER SET utf8 COLLATE utf8_unicode_ci NOT NULL,
  `REC_REGISTRATION_MIDDLE_NAME` varchar(400) CHARACTER SET utf8 COLLATE utf8_unicode_ci NOT NULL,
  `REC_REGISTRATION_LAST_NAME` varchar(400) CHARACTER SET utf8 COLLATE utf8_unicode_ci NOT NULL,
  `REC_REGISTRATION_SUFFIX` varchar(40) CHARACTER SET utf8 COLLATE utf8_unicode_ci NOT NULL,
  `REC_REGISTRATION_SYS_GENDER_ID` bigint(20) NOT NULL,
  `REC_REGISTRATION_NOTIFY_PHONE` varchar(40) CHARACTER SET utf8 COLLATE utf8_unicode_ci NOT NULL,
  `REC_REGISTRATION_EMCONTACT_PERSON` varchar(1000) CHARACTER SET utf8 COLLATE utf8_unicode_ci NOT NULL,
  `REC_REGISTRATION_EMCONTACT_NUMBER` varchar(40) CHARACTER SET utf8 COLLATE utf8_unicode_ci NOT NULL,
  `REC_REGISTRATION_STATUS` tinyint(4) NOT NULL,
  PRIMARY KEY (`REC_REGISTRATION_ID`)
) ENGINE=InnoDB AUTO_INCREMENT=12 DEFAULT CHARSET=latin1;
/*!40101 SET character_set_client = @saved_cs_client */;

--
-- Dumping data for table `record_registration`
--

LOCK TABLES `record_registration` WRITE;
/*!40000 ALTER TABLE `record_registration` DISABLE KEYS */;
INSERT INTO `record_registration` (`REC_REGISTRATION_ID`, `REC_REGISTRATION_REC_USER_ID`, `REC_REGISTRATION_CAT_DEPARTMENT_ID`, `REC_REGISTRATION_CAT_SECTION_ID`, `REC_REGISTRATION_FIRST_NAME`, `REC_REGISTRATION_MIDDLE_NAME`, `REC_REGISTRATION_LAST_NAME`, `REC_REGISTRATION_SUFFIX`, `REC_REGISTRATION_SYS_GENDER_ID`, `REC_REGISTRATION_NOTIFY_PHONE`, `REC_REGISTRATION_EMCONTACT_PERSON`, `REC_REGISTRATION_EMCONTACT_NUMBER`, `REC_REGISTRATION_STATUS`) VALUES (1,1,2,1,'Juan','','dela Cruz','',1,'+639655460720','Juana dela Cruz','+639655460720',4),(2,2,2,1,'Juana','','dela Cruz','',2,'+639655460720','Juan dela Cruz','+639655460720',4),(7,3,2,1,'ALI BALOU','E.','NANDING','',1,'+639061701364','Julia Baretto','+639353359992',4),(9,4,2,1,'Alucard','Leomeord','Aldous','CSP',1,'+639757944512','Mahal kong Rency','+639757944512',4),(10,0,2,1,'FAHAD','LUMABAO','KUSA','',1,'+639974301462','HASMIRA KUSA WAHAB','+639264626986',2),(11,0,2,1,'ALI BALOU','EMBA','NANDING','',1,'+639061701364','JULIA BARETTO-NANDING','+639655460720',2);
/*!40000 ALTER TABLE `record_registration` ENABLE KEYS */;
UNLOCK TABLES;

--
-- Table structure for table `record_user`
--

DROP TABLE IF EXISTS `record_user`;
/*!40101 SET @saved_cs_client     = @@character_set_client */;
/*!40101 SET character_set_client = utf8 */;
CREATE TABLE `record_user` (
  `REC_USER_ID` bigint(20) NOT NULL AUTO_INCREMENT,
  `REC_USER_CAT_DEPARTMENT_ID` bigint(20) NOT NULL,
  `REC_USER_CAT_SECTION_ID` bigint(20) NOT NULL,
  `REC_USER_UNIQUE_CODE` varchar(400) CHARACTER SET utf8 COLLATE utf8_unicode_ci NOT NULL,
  `REC_USER_FIRST_NAME` varchar(400) CHARACTER SET utf8 COLLATE utf8_unicode_ci NOT NULL,
  `REC_USER_MIDDLE_NAME` varchar(400) CHARACTER SET utf8 COLLATE utf8_unicode_ci NOT NULL,
  `REC_USER_LAST_NAME` varchar(400) CHARACTER SET utf8 COLLATE utf8_unicode_ci NOT NULL,
  `REC_USER_SUFFIX` varchar(40) CHARACTER SET utf8 COLLATE utf8_unicode_ci NOT NULL,
  `REC_USER_SYS_GENDER_ID` bigint(20) NOT NULL,
  `REC_USER_NOTIFY_PHONE` varchar(40) CHARACTER SET utf8 COLLATE utf8_unicode_ci NOT NULL,
  `REC_USER_EMCONTACT_PERSON` varchar(1000) CHARACTER SET utf8 COLLATE utf8_unicode_ci NOT NULL,
  `REC_USER_EMCONTACT_NUMBER` varchar(40) CHARACTER SET utf8 COLLATE utf8_unicode_ci NOT NULL,
  `REC_USER_ACC_ACCOUNT_ID` bigint(20) NOT NULL,
  `REC_USER_RECORDED_DATE` datetime(6) DEFAULT NULL,
  `REC_USER_STATUS` tinyint(4) NOT NULL,
  PRIMARY KEY (`REC_USER_ID`)
) ENGINE=InnoDB AUTO_INCREMENT=5 DEFAULT CHARSET=latin1;
/*!40101 SET character_set_client = @saved_cs_client */;

--
-- Dumping data for table `record_user`
--

LOCK TABLES `record_user` WRITE;
/*!40000 ALTER TABLE `record_user` DISABLE KEYS */;
INSERT INTO `record_user` (`REC_USER_ID`, `REC_USER_CAT_DEPARTMENT_ID`, `REC_USER_CAT_SECTION_ID`, `REC_USER_UNIQUE_CODE`, `REC_USER_FIRST_NAME`, `REC_USER_MIDDLE_NAME`, `REC_USER_LAST_NAME`, `REC_USER_SUFFIX`, `REC_USER_SYS_GENDER_ID`, `REC_USER_NOTIFY_PHONE`, `REC_USER_EMCONTACT_PERSON`, `REC_USER_EMCONTACT_NUMBER`, `REC_USER_ACC_ACCOUNT_ID`, `REC_USER_RECORDED_DATE`, `REC_USER_STATUS`) VALUES (1,2,1,'DEF.20210119.102028585893.q6SIZaA','Juan','','dela Cruz','',1,'+639655460720','Juana dela Cruz','+639655460720',6,'2021-01-19 10:20:28.567607',2),(2,2,1,'DEF.20210119.104226823125.QfYJ72l','Juana','','dela Cruz','',2,'+639655460720','Juan dela Cruz','+639655460720',6,'2021-01-19 10:42:26.822693',2),(3,2,1,'DEF.20210119.113341292270.4rmQb3q','ALI BALOU','E.','NANDING','',1,'+639061701364','Julia Baretto','+639353359992',6,'2021-01-19 11:33:41.291842',2),(4,2,1,'DEF.20210119.113444180245.CEWPEE4','Alucard','Leomeord','Aldous','CSP',1,'+639757944512','Mahal kong Rency','+639757944512',6,'2021-01-19 11:34:44.179884',2);
/*!40000 ALTER TABLE `record_user` ENABLE KEYS */;
UNLOCK TABLES;

--
-- Table structure for table `system_access_rights_authority`
--

DROP TABLE IF EXISTS `system_access_rights_authority`;
/*!40101 SET @saved_cs_client     = @@character_set_client */;
/*!40101 SET character_set_client = utf8 */;
CREATE TABLE `system_access_rights_authority` (
  `SYS_AUTHORITY_ID` bigint(20) NOT NULL AUTO_INCREMENT,
  `SYS_AUTHORITY_DESCRIPTION` varchar(500) CHARACTER SET utf8 COLLATE utf8_unicode_ci NOT NULL,
  `SYS_AUTHORITY_STATUS` tinyint(4) NOT NULL,
  PRIMARY KEY (`SYS_AUTHORITY_ID`)
) ENGINE=InnoDB AUTO_INCREMENT=6 DEFAULT CHARSET=latin1;
/*!40101 SET character_set_client = @saved_cs_client */;

--
-- Dumping data for table `system_access_rights_authority`
--

LOCK TABLES `system_access_rights_authority` WRITE;
/*!40000 ALTER TABLE `system_access_rights_authority` DISABLE KEYS */;
INSERT INTO `system_access_rights_authority` (`SYS_AUTHORITY_ID`, `SYS_AUTHORITY_DESCRIPTION`, `SYS_AUTHORITY_STATUS`) VALUES (0,'No Access',2),(1,'View Only',2),(2,'View/Add',2),(3,'View/Edit',2),(4,'View/Edit/Delete',2),(5,'Override',2);
/*!40000 ALTER TABLE `system_access_rights_authority` ENABLE KEYS */;
UNLOCK TABLES;

--
-- Table structure for table `system_alpha32`
--

DROP TABLE IF EXISTS `system_alpha32`;
/*!40101 SET @saved_cs_client     = @@character_set_client */;
/*!40101 SET character_set_client = utf8 */;
CREATE TABLE `system_alpha32` (
  `SYS_ALPHA32_ID` bigint(20) NOT NULL AUTO_INCREMENT,
  `SYS_ALPHA32_KEY` varchar(10) CHARACTER SET utf8 COLLATE utf8_unicode_ci NOT NULL,
  PRIMARY KEY (`SYS_ALPHA32_ID`)
) ENGINE=InnoDB AUTO_INCREMENT=32 DEFAULT CHARSET=latin1;
/*!40101 SET character_set_client = @saved_cs_client */;

--
-- Dumping data for table `system_alpha32`
--

LOCK TABLES `system_alpha32` WRITE;
/*!40000 ALTER TABLE `system_alpha32` DISABLE KEYS */;
INSERT INTO `system_alpha32` (`SYS_ALPHA32_ID`, `SYS_ALPHA32_KEY`) VALUES (0,'A'),(1,'B'),(2,'C'),(3,'D'),(4,'E'),(5,'F'),(6,'G'),(7,'H'),(8,'J'),(9,'K'),(10,'L'),(11,'M'),(12,'N'),(13,'P'),(14,'Q'),(15,'R'),(16,'S'),(17,'T'),(18,'U'),(19,'V'),(20,'W'),(21,'X'),(22,'Y'),(23,'Z'),(24,'2'),(25,'3'),(26,'4'),(27,'5'),(28,'6'),(29,'7'),(30,'8'),(31,'9');
/*!40000 ALTER TABLE `system_alpha32` ENABLE KEYS */;
UNLOCK TABLES;

--
-- Table structure for table `system_alpha34`
--

DROP TABLE IF EXISTS `system_alpha34`;
/*!40101 SET @saved_cs_client     = @@character_set_client */;
/*!40101 SET character_set_client = utf8 */;
CREATE TABLE `system_alpha34` (
  `SYS_ALPHA34_ID` bigint(20) NOT NULL AUTO_INCREMENT,
  `SYS_ALPHA34_KEY` varchar(10) CHARACTER SET utf8 COLLATE utf8_unicode_ci NOT NULL,
  PRIMARY KEY (`SYS_ALPHA34_ID`)
) ENGINE=InnoDB AUTO_INCREMENT=34 DEFAULT CHARSET=latin1;
/*!40101 SET character_set_client = @saved_cs_client */;

--
-- Dumping data for table `system_alpha34`
--

LOCK TABLES `system_alpha34` WRITE;
/*!40000 ALTER TABLE `system_alpha34` DISABLE KEYS */;
INSERT INTO `system_alpha34` (`SYS_ALPHA34_ID`, `SYS_ALPHA34_KEY`) VALUES (0,'0'),(1,'1'),(2,'2'),(3,'3'),(4,'4'),(5,'5'),(6,'6'),(7,'7'),(8,'8'),(9,'9'),(10,'A'),(11,'B'),(12,'C'),(13,'D'),(14,'E'),(15,'F'),(16,'G'),(17,'H'),(18,'J'),(19,'K'),(20,'L'),(21,'M'),(22,'N'),(23,'P'),(24,'Q'),(25,'R'),(26,'S'),(27,'T'),(28,'U'),(29,'V'),(30,'W'),(31,'X'),(32,'Y'),(33,'Z');
/*!40000 ALTER TABLE `system_alpha34` ENABLE KEYS */;
UNLOCK TABLES;

--
-- Table structure for table `system_blood_type`
--

DROP TABLE IF EXISTS `system_blood_type`;
/*!40101 SET @saved_cs_client     = @@character_set_client */;
/*!40101 SET character_set_client = utf8 */;
CREATE TABLE `system_blood_type` (
  `SYS_BLOODTYPE_ID` bigint(20) NOT NULL AUTO_INCREMENT,
  `SYS_BLOODTYPE_CODE` varchar(50) CHARACTER SET utf8 COLLATE utf8_unicode_ci NOT NULL,
  `SYS_BLOODTYPE_DESCRIPTION` varchar(500) CHARACTER SET utf8 COLLATE utf8_unicode_ci NOT NULL,
  `SYS_BLOODTYPE_STATUS` tinyint(4) NOT NULL,
  PRIMARY KEY (`SYS_BLOODTYPE_ID`)
) ENGINE=InnoDB AUTO_INCREMENT=10 DEFAULT CHARSET=latin1;
/*!40101 SET character_set_client = @saved_cs_client */;

--
-- Dumping data for table `system_blood_type`
--

LOCK TABLES `system_blood_type` WRITE;
/*!40000 ALTER TABLE `system_blood_type` DISABLE KEYS */;
INSERT INTO `system_blood_type` (`SYS_BLOODTYPE_ID`, `SYS_BLOODTYPE_CODE`, `SYS_BLOODTYPE_DESCRIPTION`, `SYS_BLOODTYPE_STATUS`) VALUES (1,'A+','A Positive',2),(2,'A-','A Negative',2),(3,'B+','B Positive',2),(4,'B-','B Negative',2),(5,'AB+','AB Positive',2),(6,'AB-','AB Negative',2),(7,'O+','O Positive',2),(8,'O-','O Negative',2),(9,'X','Others / Unknown',2);
/*!40000 ALTER TABLE `system_blood_type` ENABLE KEYS */;
UNLOCK TABLES;

--
-- Table structure for table `system_civil_status`
--

DROP TABLE IF EXISTS `system_civil_status`;
/*!40101 SET @saved_cs_client     = @@character_set_client */;
/*!40101 SET character_set_client = utf8 */;
CREATE TABLE `system_civil_status` (
  `SYS_CIVIL_ID` bigint(20) NOT NULL AUTO_INCREMENT,
  `SYS_CIVIL_CODE` varchar(50) CHARACTER SET utf8 COLLATE utf8_unicode_ci NOT NULL,
  `SYS_CIVIL_DESCRIPTION` varchar(500) CHARACTER SET utf8 COLLATE utf8_unicode_ci NOT NULL,
  `SYS_CIVIL_STATUS` tinyint(4) NOT NULL,
  PRIMARY KEY (`SYS_CIVIL_ID`)
) ENGINE=InnoDB AUTO_INCREMENT=5 DEFAULT CHARSET=latin1;
/*!40101 SET character_set_client = @saved_cs_client */;

--
-- Dumping data for table `system_civil_status`
--

LOCK TABLES `system_civil_status` WRITE;
/*!40000 ALTER TABLE `system_civil_status` DISABLE KEYS */;
INSERT INTO `system_civil_status` (`SYS_CIVIL_ID`, `SYS_CIVIL_CODE`, `SYS_CIVIL_DESCRIPTION`, `SYS_CIVIL_STATUS`) VALUES (1,'S','Single',2),(2,'M','Married',2),(3,'D','Divorced',2),(4,'W','Widowed',2);
/*!40000 ALTER TABLE `system_civil_status` ENABLE KEYS */;
UNLOCK TABLES;

--
-- Table structure for table `system_employment_status`
--

DROP TABLE IF EXISTS `system_employment_status`;
/*!40101 SET @saved_cs_client     = @@character_set_client */;
/*!40101 SET character_set_client = utf8 */;
CREATE TABLE `system_employment_status` (
  `SYS_EMPLOYSTATUS_ID` bigint(20) NOT NULL AUTO_INCREMENT,
  `SYS_EMPLOYSTATUS_CODE` varchar(50) CHARACTER SET utf8 COLLATE utf8_unicode_ci NOT NULL,
  `SYS_EMPLOYSTATUS_DESCRIPTION` varchar(500) CHARACTER SET utf8 COLLATE utf8_unicode_ci NOT NULL,
  `SYS_EMPLOYSTATUS_REMARKS` varchar(4000) CHARACTER SET utf8 COLLATE utf8_unicode_ci NOT NULL,
  `SYS_EMPLOYSTATUS_STATUS` tinyint(4) NOT NULL,
  PRIMARY KEY (`SYS_EMPLOYSTATUS_ID`)
) ENGINE=InnoDB AUTO_INCREMENT=8 DEFAULT CHARSET=latin1;
/*!40101 SET character_set_client = @saved_cs_client */;

--
-- Dumping data for table `system_employment_status`
--

LOCK TABLES `system_employment_status` WRITE;
/*!40000 ALTER TABLE `system_employment_status` DISABLE KEYS */;
INSERT INTO `system_employment_status` (`SYS_EMPLOYSTATUS_ID`, `SYS_EMPLOYSTATUS_CODE`, `SYS_EMPLOYSTATUS_DESCRIPTION`, `SYS_EMPLOYSTATUS_REMARKS`, `SYS_EMPLOYSTATUS_STATUS`) VALUES (1,'U','Unemployed','',2),(2,'E','Employed','',2),(3,'S','Self-Employed','',2),(4,'N','Non-Working','Housewives, Disabled, etc.',2),(5,'R','Retired','',2),(6,'ST','Student','',2),(7,'X','Others','',2);
/*!40000 ALTER TABLE `system_employment_status` ENABLE KEYS */;
UNLOCK TABLES;

--
-- Table structure for table `system_gender`
--

DROP TABLE IF EXISTS `system_gender`;
/*!40101 SET @saved_cs_client     = @@character_set_client */;
/*!40101 SET character_set_client = utf8 */;
CREATE TABLE `system_gender` (
  `SYS_GENDER_ID` bigint(20) NOT NULL AUTO_INCREMENT,
  `SYS_GENDER_CODE` varchar(50) CHARACTER SET utf8 COLLATE utf8_unicode_ci NOT NULL,
  `SYS_GENDER_DESCRIPTION` varchar(500) CHARACTER SET utf8 COLLATE utf8_unicode_ci NOT NULL,
  `SYS_GENDER_STATUS` tinyint(4) NOT NULL,
  PRIMARY KEY (`SYS_GENDER_ID`)
) ENGINE=InnoDB AUTO_INCREMENT=3 DEFAULT CHARSET=latin1;
/*!40101 SET character_set_client = @saved_cs_client */;

--
-- Dumping data for table `system_gender`
--

LOCK TABLES `system_gender` WRITE;
/*!40000 ALTER TABLE `system_gender` DISABLE KEYS */;
INSERT INTO `system_gender` (`SYS_GENDER_ID`, `SYS_GENDER_CODE`, `SYS_GENDER_DESCRIPTION`, `SYS_GENDER_STATUS`) VALUES (1,'M','MALE',2),(2,'F','FEMALE',2);
/*!40000 ALTER TABLE `system_gender` ENABLE KEYS */;
UNLOCK TABLES;

--
-- Table structure for table `system_module`
--

DROP TABLE IF EXISTS `system_module`;
/*!40101 SET @saved_cs_client     = @@character_set_client */;
/*!40101 SET character_set_client = utf8 */;
CREATE TABLE `system_module` (
  `SYS_MODULE_ID` bigint(20) NOT NULL,
  `SYS_MODULE_CATEGORY` varchar(50) CHARACTER SET utf8 COLLATE utf8_unicode_ci NOT NULL,
  `SYS_MODULE_KEYWORD` varchar(500) CHARACTER SET utf8 COLLATE utf8_unicode_ci NOT NULL,
  `SYS_MODULE_NAME` varchar(500) CHARACTER SET utf8 COLLATE utf8_unicode_ci NOT NULL,
  `SYS_MODULE_DESCRIPTION` varchar(4000) CHARACTER SET utf8 COLLATE utf8_unicode_ci NOT NULL,
  `SYS_MODULE_SHOW_ACCESS_RIGHTS` tinyint(4) NOT NULL,
  `SYS_MODULE_STATUS` tinyint(4) NOT NULL,
  `SYS_MODULE_SYNC_SAVE_UP_TIMESTAMP` datetime(6) DEFAULT NULL,
  `SYS_MODULE_SYNC_SAVE_DL_TIMESTAMP` datetime(6) DEFAULT NULL,
  `SYS_MODULE_SYNC_DELETE_UP_TIMESTAMP` datetime(6) DEFAULT NULL,
  `SYS_MODULE_SYNC_DELETE_DL_TIMESTAMP` datetime(6) DEFAULT NULL,
  PRIMARY KEY (`SYS_MODULE_ID`)
) ENGINE=InnoDB DEFAULT CHARSET=latin1;
/*!40101 SET character_set_client = @saved_cs_client */;

--
-- Dumping data for table `system_module`
--

LOCK TABLES `system_module` WRITE;
/*!40000 ALTER TABLE `system_module` DISABLE KEYS */;
INSERT INTO `system_module` (`SYS_MODULE_ID`, `SYS_MODULE_CATEGORY`, `SYS_MODULE_KEYWORD`, `SYS_MODULE_NAME`, `SYS_MODULE_DESCRIPTION`, `SYS_MODULE_SHOW_ACCESS_RIGHTS`, `SYS_MODULE_STATUS`, `SYS_MODULE_SYNC_SAVE_UP_TIMESTAMP`, `SYS_MODULE_SYNC_SAVE_DL_TIMESTAMP`, `SYS_MODULE_SYNC_DELETE_UP_TIMESTAMP`, `SYS_MODULE_SYNC_DELETE_DL_TIMESTAMP`) VALUES (10040,'account','account_level','User Account : level','manage/view account levels. Account levels are group of accounts where the same access rights applies',2,2,'0000-00-00 00:00:00.000000','0000-00-00 00:00:00.000000','0000-00-00 00:00:00.000000','0000-00-00 00:00:00.000000'),(10060,'account','account_member','User Account : member','(FOR AUDIT TRAIL ONLY) General module for user account control',2,2,'0000-00-00 00:00:00.000000','0000-00-00 00:00:00.000000','0000-00-00 00:00:00.000000','0000-00-00 00:00:00.000000'),(10070,'account','account_group','User Account : group','(For super admin only) For management of user account groups.',2,2,'0000-00-00 00:00:00.000000','0000-00-00 00:00:00.000000','0000-00-00 00:00:00.000000','0000-00-00 00:00:00.000000'),(10080,'account','account_access_rights','User Account : access rights','enable/disable system features for selected user level can access (for slave accounts only)',2,2,'0000-00-00 00:00:00.000000','0000-00-00 00:00:00.000000','0000-00-00 00:00:00.000000','0000-00-00 00:00:00.000000'),(10100,'account','account_server','Account: server','Manage sync server/client settings.',2,2,'0000-00-00 00:00:00.000000','0000-00-00 00:00:00.000000','0000-00-00 00:00:00.000000','0000-00-00 00:00:00.000000'),(10120,'account','account_device','Devices','Manages the Devices list in this system',2,2,'1000-01-01 00:00:00.000000','1000-01-01 00:00:00.000000','1000-01-01 00:00:00.000000','1000-01-01 00:00:00.000000'),(10140,'account','account_audit_trail','User Account : audit trail','View system activity log.',2,2,'0000-00-00 00:00:00.000000','0000-00-00 00:00:00.000000','0000-00-00 00:00:00.000000','0000-00-00 00:00:00.000000'),(10160,'account','account_bflogin','Brute Force Login Attempt','Manages the Brute Force Login Attempt list in this system',2,2,'1000-01-01 00:00:00.000000','1000-01-01 00:00:00.000000','1000-01-01 00:00:00.000000','1000-01-01 00:00:00.000000'),(10180,'account','account_bfip','Bruteforce IP','Manages the Bruteforce IP list in this system',2,2,'1000-01-01 00:00:00.000000','1000-01-01 00:00:00.000000','1000-01-01 00:00:00.000000','1000-01-01 00:00:00.000000'),(15010,'addon','addon_license_group','Addon: Group License','Handles Group License.',2,2,'0000-00-00 00:00:00.000000','0000-00-00 00:00:00.000000','0000-00-00 00:00:00.000000','0000-00-00 00:00:00.000000'),(15030,'addon','addon_license_user','Addon: User License','Handles User License.',2,2,'0000-00-00 00:00:00.000000','0000-00-00 00:00:00.000000','0000-00-00 00:00:00.000000','0000-00-00 00:00:00.000000'),(15050,'addon','addon_queuing','Addon: Queuing','Handles Queuing Control.',2,2,'0000-00-00 00:00:00.000000','0000-00-00 00:00:00.000000','0000-00-00 00:00:00.000000','0000-00-00 00:00:00.000000'),(15070,'addon','addon_resource','Addon: Resource','Handles user imported resources, such as image, biodata, or any other byte-streams.',2,2,'0000-00-00 00:00:00.000000','0000-00-00 00:00:00.000000','0000-00-00 00:00:00.000000','0000-00-00 00:00:00.000000'),(20010,'category','category_religion','Settings : religion','religions list',2,2,'0000-00-00 00:00:00.000000','0000-00-00 00:00:00.000000','0000-00-00 00:00:00.000000','0000-00-00 00:00:00.000000'),(20030,'category','category_nationality','Settings: Nationality','Manage the list of Nationalities',2,2,'0000-00-00 00:00:00.000000','0000-00-00 00:00:00.000000','0000-00-00 00:00:00.000000','0000-00-00 00:00:00.000000'),(20050,'category','category_address_country','Settings: Address - Country','Manages the country list in this system.',2,2,'1000-01-01 00:00:00.000000','1000-01-01 00:00:00.000000','1000-01-01 00:00:00.000000','1000-01-01 00:00:00.000000'),(20070,'category','category_address_region','Settings: Address - Region','Manages the region list in this system.',2,2,'1000-01-01 00:00:00.000000','1000-01-01 00:00:00.000000','1000-01-01 00:00:00.000000','1000-01-01 00:00:00.000000'),(20090,'category','category_address_province','Settings: Address - Province','Manages the province list in this system.',2,2,'1000-01-01 00:00:00.000000','1000-01-01 00:00:00.000000','1000-01-01 00:00:00.000000','1000-01-01 00:00:00.000000'),(20110,'category','category_address_municipality','Settings: Address - Municipality','Manages the municipality list in this system',2,2,'1000-01-01 00:00:00.000000','1000-01-01 00:00:00.000000','1000-01-01 00:00:00.000000','1000-01-01 00:00:00.000000'),(21010,'category','category_department','Department','Manages the Department list in this system',2,2,'1000-01-01 00:00:00.000000','1000-01-01 00:00:00.000000','1000-01-01 00:00:00.000000','1000-01-01 00:00:00.000000'),(21030,'category','category_section','Section','Manages the Section list in this system',2,2,'1000-01-01 00:00:00.000000','1000-01-01 00:00:00.000000','1000-01-01 00:00:00.000000','1000-01-01 00:00:00.000000'),(21050,'category','category_entrance','Entrance','Manages the Entrance list in this system',2,2,'1000-01-01 00:00:00.000000','1000-01-01 00:00:00.000000','1000-01-01 00:00:00.000000','1000-01-01 00:00:00.000000'),(31010,'mobile','mobile_inbox','Mobile: Communication RECEIEVE SMS History','View RECEIEVE SMS History',2,2,'0000-00-00 00:00:00.000000','0000-00-00 00:00:00.000000','0000-00-00 00:00:00.000000','0000-00-00 00:00:00.000000'),(31020,'mobile','mobile_outbox','Mobile: Communication SENT SMS History','View SENT SMS History',2,2,'0000-00-00 00:00:00.000000','0000-00-00 00:00:00.000000','0000-00-00 00:00:00.000000','0000-00-00 00:00:00.000000'),(31025,'mobile','mobile_outbox_history','Mobile: Communication SENT SMS History Per Mobile Number','View SENT SMS History Per Mobile NUmber',2,2,'0000-00-00 00:00:00.000000','0000-00-00 00:00:00.000000','0000-00-00 00:00:00.000000','0000-00-00 00:00:00.000000'),(31030,'mobile','mobile_notification','Mobile: Communication Notification History','View Notification history.',2,2,'0000-00-00 00:00:00.000000','0000-00-00 00:00:00.000000','0000-00-00 00:00:00.000000','0000-00-00 00:00:00.000000'),(31040,'mobile','mobile_service_code','Mobile: Service Codes','Manage SMS service code categories.',2,2,'0000-00-00 00:00:00.000000','0000-00-00 00:00:00.000000','0000-00-00 00:00:00.000000','0000-00-00 00:00:00.000000'),(31050,'mobile','mobile_shortcode','Mobile: Shortcode lists','Bind mobile shortcode with user accounts.',2,2,'0000-00-00 00:00:00.000000','0000-00-00 00:00:00.000000','0000-00-00 00:00:00.000000','0000-00-00 00:00:00.000000'),(31060,'mobile','mobile_loadflow','Mobile: Load Flow History','Monitors history of Load [in] and [out].',2,2,'0000-00-00 00:00:00.000000','0000-00-00 00:00:00.000000','0000-00-00 00:00:00.000000','0000-00-00 00:00:00.000000'),(31070,'mobile','mobile_volume_control','Mobile: Volume Control','Controls SMS Volume per time interval.',2,2,'0000-00-00 00:00:00.000000','0000-00-00 00:00:00.000000','0000-00-00 00:00:00.000000','0000-00-00 00:00:00.000000'),(40010,'record','record_registration','Registration','Manages the Registration list in this system',2,2,'1000-01-01 00:00:00.000000','1000-01-01 00:00:00.000000','1000-01-01 00:00:00.000000','1000-01-01 00:00:00.000000'),(40050,'record','record_user','User','Manages the User list in this system',2,2,'1000-01-01 00:00:00.000000','1000-01-01 00:00:00.000000','1000-01-01 00:00:00.000000','1000-01-01 00:00:00.000000'),(40070,'record','record_attendance','Attendance','Manages the Attendance list in this system',2,2,'1000-01-01 00:00:00.000000','1000-01-01 00:00:00.000000','1000-01-01 00:00:00.000000','1000-01-01 00:00:00.000000'),(40090,'record','record_device','Device','Manages the Device list in this system',2,2,'1000-01-01 00:00:00.000000','1000-01-01 00:00:00.000000','1000-01-01 00:00:00.000000','1000-01-01 00:00:00.000000'),(50010,'system','system_module','module','access to the list of system modules',1,1,'0000-00-00 00:00:00.000000','0000-00-00 00:00:00.000000','0000-00-00 00:00:00.000000','0000-00-00 00:00:00.000000');
/*!40000 ALTER TABLE `system_module` ENABLE KEYS */;
UNLOCK TABLES;

--
-- Table structure for table `system_null_flag`
--

DROP TABLE IF EXISTS `system_null_flag`;
/*!40101 SET @saved_cs_client     = @@character_set_client */;
/*!40101 SET character_set_client = utf8 */;
CREATE TABLE `system_null_flag` (
  `SYS_FLAG_ID` bigint(20) NOT NULL AUTO_INCREMENT,
  `SYS_NVARCHAR_FLAG` varchar(50) CHARACTER SET utf8 COLLATE utf8_unicode_ci NOT NULL,
  `SYS_BIT_FLAG` int(11) NOT NULL,
  `SYS_INT_FLAG` int(11) NOT NULL,
  `SYS_BIGINT_FLAG` bigint(20) NOT NULL,
  `SYS_DECIMAL_FLAG` decimal(18,2) NOT NULL,
  `SYS_DATETIME_FLAG` datetime(6) DEFAULT NULL,
  `SYS_STRING_DIVIDER_FLAG` varchar(50) CHARACTER SET utf8 COLLATE utf8_unicode_ci NOT NULL,
  PRIMARY KEY (`SYS_FLAG_ID`)
) ENGINE=InnoDB AUTO_INCREMENT=2 DEFAULT CHARSET=latin1;
/*!40101 SET character_set_client = @saved_cs_client */;

--
-- Dumping data for table `system_null_flag`
--

LOCK TABLES `system_null_flag` WRITE;
/*!40000 ALTER TABLE `system_null_flag` DISABLE KEYS */;
INSERT INTO `system_null_flag` (`SYS_FLAG_ID`, `SYS_NVARCHAR_FLAG`, `SYS_BIT_FLAG`, `SYS_INT_FLAG`, `SYS_BIGINT_FLAG`, `SYS_DECIMAL_FLAG`, `SYS_DATETIME_FLAG`, `SYS_STRING_DIVIDER_FLAG`) VALUES (1,'#RAISE_FLAG:NULL;',-1,-2147483647,-9223372036854700000,-9999999999999990.00,'1000-01-01 01:00:00.000000','#RAISE_FLAG:DIVIDER;');
/*!40000 ALTER TABLE `system_null_flag` ENABLE KEYS */;
UNLOCK TABLES;

--
-- Table structure for table `system_settings`
--

DROP TABLE IF EXISTS `system_settings`;
/*!40101 SET @saved_cs_client     = @@character_set_client */;
/*!40101 SET character_set_client = utf8 */;
CREATE TABLE `system_settings` (
  `SYS_SETTINGS_ID` bigint(20) NOT NULL AUTO_INCREMENT,
  `SYS_SETTINGS_GROUP` varchar(400) CHARACTER SET utf8 COLLATE utf8_unicode_ci NOT NULL,
  `SYS_SETTINGS_CODE` varchar(400) CHARACTER SET utf8 COLLATE utf8_unicode_ci NOT NULL,
  `SYS_SETTINGS_DESCRIPTION` varchar(1000) CHARACTER SET utf8 COLLATE utf8_unicode_ci NOT NULL,
  `SYS_SETTINGS_VAL_VARCHAR` varchar(1000) CHARACTER SET utf8 COLLATE utf8_unicode_ci NOT NULL,
  `SYS_SETTINGS_VAL_VARCHAR4K` varchar(4000) CHARACTER SET utf8 COLLATE utf8_unicode_ci NOT NULL,
  `SYS_SETTINGS_VAL_INT` int(11) NOT NULL,
  `SYS_SETTINGS_VAL_BIGINT` bigint(20) NOT NULL,
  `SYS_SETTINGS_VAL_DECIMAL` decimal(18,2) NOT NULL,
  `SYS_SETTINGS_VAL_DATETIME` datetime(6) DEFAULT NULL,
  `SYS_SETTINGS_VAL_TIMESTAMP` datetime(6) DEFAULT NULL,
  `SYS_SETTINGS_STATUS` tinyint(4) NOT NULL,
  PRIMARY KEY (`SYS_SETTINGS_ID`)
) ENGINE=InnoDB AUTO_INCREMENT=7 DEFAULT CHARSET=latin1;
/*!40101 SET character_set_client = @saved_cs_client */;

--
-- Dumping data for table `system_settings`
--

LOCK TABLES `system_settings` WRITE;
/*!40000 ALTER TABLE `system_settings` DISABLE KEYS */;
INSERT INTO `system_settings` (`SYS_SETTINGS_ID`, `SYS_SETTINGS_GROUP`, `SYS_SETTINGS_CODE`, `SYS_SETTINGS_DESCRIPTION`, `SYS_SETTINGS_VAL_VARCHAR`, `SYS_SETTINGS_VAL_VARCHAR4K`, `SYS_SETTINGS_VAL_INT`, `SYS_SETTINGS_VAL_BIGINT`, `SYS_SETTINGS_VAL_DECIMAL`, `SYS_SETTINGS_VAL_DATETIME`, `SYS_SETTINGS_VAL_TIMESTAMP`, `SYS_SETTINGS_STATUS`) VALUES (1,'BRUTEFORCE','BRUTEFORCE_USERNAME_BLOCK_PERIOD','Brute Force Username Protection Period (in minutes)','INT = Default Value\r\nBIGINT = Actual Value\r\n','-',60,60,0.00,'1000-01-01 00:00:00.000000','1000-01-01 00:00:00.000000',2),(2,'BRUTEFORCE','BRUTEFORCE_USERNAME_BLOCK_ATTEMPT','Maximum Failures by Account','INT = Default Value\nBIGINT = Actual Value\n','-',15,15,0.00,'1000-01-01 00:00:00.000000','1000-01-01 00:00:00.000000',2),(3,'BRUTEFORCE','BRUTEFORCE_IP_BLOCK_PERIOD','IP Address-based Brute Force Protection Period (in minutes)','INT = Default Value\nBIGINT = Actual Value\n','-',1440,1440,0.00,'1000-01-01 00:00:00.000000','1000-01-01 00:00:00.000000',2),(4,'BRUTEFORCE','BRUTEFORCE_IP_BLOCK_ATTEMPT','Maximum Failures per IP Address','INT = Default Value\nBIGINT = Actual Value\n','-',15,15,0.00,'1000-01-01 00:00:00.000000','1000-01-01 00:00:00.000000',2),(5,'BRUTEFORCE','BRUTEFORCE_IP_BLOCK_PERMANENT','Maximum Block-out per IP Address before adding to black list','INT = Default Value\nBIGINT = Actual Value\n','-',10,10,0.00,'1000-01-01 00:00:00.000000','1000-01-01 00:00:00.000000',2),(6,'BRUTEFORCE','BRUTEFORCE_LOGIN_RETAIN_PERIOD','Duration for Retaining Login Attempts (in minutes)','INT = Default Value\nBIGINT = Actual Value\n','-',1440,1440,0.00,'1000-01-01 00:00:00.000000','1000-01-01 00:00:00.000000',2);
/*!40000 ALTER TABLE `system_settings` ENABLE KEYS */;
UNLOCK TABLES;

--
-- Table structure for table `system_sort`
--

DROP TABLE IF EXISTS `system_sort`;
/*!40101 SET @saved_cs_client     = @@character_set_client */;
/*!40101 SET character_set_client = utf8 */;
CREATE TABLE `system_sort` (
  `SYS_SORT_ID` bigint(20) NOT NULL AUTO_INCREMENT,
  `SYS_SORT_CODE` varchar(50) CHARACTER SET utf8 COLLATE utf8_unicode_ci NOT NULL,
  `SYS_SORT_DESCRIPTION` varchar(500) CHARACTER SET utf8 COLLATE utf8_unicode_ci NOT NULL,
  `SYS_SORT_STATUS` tinyint(4) NOT NULL,
  PRIMARY KEY (`SYS_SORT_ID`)
) ENGINE=InnoDB AUTO_INCREMENT=3 DEFAULT CHARSET=latin1;
/*!40101 SET character_set_client = @saved_cs_client */;

--
-- Dumping data for table `system_sort`
--

LOCK TABLES `system_sort` WRITE;
/*!40000 ALTER TABLE `system_sort` DISABLE KEYS */;
INSERT INTO `system_sort` (`SYS_SORT_ID`, `SYS_SORT_CODE`, `SYS_SORT_DESCRIPTION`, `SYS_SORT_STATUS`) VALUES (1,'ASC','Ascending',2),(2,'DESC','Descending',2);
/*!40000 ALTER TABLE `system_sort` ENABLE KEYS */;
UNLOCK TABLES;

--
-- Table structure for table `system_status`
--

DROP TABLE IF EXISTS `system_status`;
/*!40101 SET @saved_cs_client     = @@character_set_client */;
/*!40101 SET character_set_client = utf8 */;
CREATE TABLE `system_status` (
  `SYS_STATUS_ID` bigint(20) NOT NULL AUTO_INCREMENT,
  `SYS_STATUS_DESCRIPTION` varchar(500) CHARACTER SET utf8 COLLATE utf8_unicode_ci NOT NULL,
  `SYS_STATUS_DESCRIPTION_2` varchar(500) CHARACTER SET utf8 COLLATE utf8_unicode_ci NOT NULL,
  `SYS_STATUS_DESCRIPTION_3` varchar(500) CHARACTER SET utf8 COLLATE utf8_unicode_ci NOT NULL,
  `SYS_STATUS_STATUS` tinyint(4) NOT NULL,
  PRIMARY KEY (`SYS_STATUS_ID`)
) ENGINE=InnoDB AUTO_INCREMENT=5 DEFAULT CHARSET=latin1;
/*!40101 SET character_set_client = @saved_cs_client */;

--
-- Dumping data for table `system_status`
--

LOCK TABLES `system_status` WRITE;
/*!40000 ALTER TABLE `system_status` DISABLE KEYS */;
INSERT INTO `system_status` (`SYS_STATUS_ID`, `SYS_STATUS_DESCRIPTION`, `SYS_STATUS_DESCRIPTION_2`, `SYS_STATUS_DESCRIPTION_3`, `SYS_STATUS_STATUS`) VALUES (1,'Inactive','Processing','Disabled',2),(2,'Active','Pending','Active',2),(3,'Closed','Rejected','Unapproved',2),(4,'Completed','Processed','NULL',2);
/*!40000 ALTER TABLE `system_status` ENABLE KEYS */;
UNLOCK TABLES;

--
-- Table structure for table `system_timezone`
--

DROP TABLE IF EXISTS `system_timezone`;
/*!40101 SET @saved_cs_client     = @@character_set_client */;
/*!40101 SET character_set_client = utf8 */;
CREATE TABLE `system_timezone` (
  `SYS_TIMEZONE_ID` bigint(20) NOT NULL AUTO_INCREMENT,
  `SYS_TIMEZONE_CODE` varchar(50) CHARACTER SET utf8 COLLATE utf8_unicode_ci NOT NULL,
  `SYS_TIMEZONE_DESCRIPTION` varchar(500) CHARACTER SET utf8 COLLATE utf8_unicode_ci NOT NULL,
  `SYS_TIMEZONE_VALUE` varchar(50) CHARACTER SET utf8 COLLATE utf8_unicode_ci NOT NULL,
  `SYS_TIMEZONE_VALUE_DESCRIPTION` varchar(500) CHARACTER SET utf8 COLLATE utf8_unicode_ci NOT NULL,
  `SYS_TIMEZONE_STATUS` tinyint(4) NOT NULL,
  PRIMARY KEY (`SYS_TIMEZONE_ID`)
) ENGINE=InnoDB AUTO_INCREMENT=2 DEFAULT CHARSET=latin1;
/*!40101 SET character_set_client = @saved_cs_client */;

--
-- Dumping data for table `system_timezone`
--

LOCK TABLES `system_timezone` WRITE;
/*!40000 ALTER TABLE `system_timezone` DISABLE KEYS */;
INSERT INTO `system_timezone` (`SYS_TIMEZONE_ID`, `SYS_TIMEZONE_CODE`, `SYS_TIMEZONE_DESCRIPTION`, `SYS_TIMEZONE_VALUE`, `SYS_TIMEZONE_VALUE_DESCRIPTION`, `SYS_TIMEZONE_STATUS`) VALUES (1,'DEFAULT_TIMEZONE','default time zone used in `SYSTEM_VAR@NOW`(), when `PARAM_USE_DEFAULT_TIMEZONE` is set to True(1).','+08:00','Phil.',2);
/*!40000 ALTER TABLE `system_timezone` ENABLE KEYS */;
UNLOCK TABLES;

--
-- Table structure for table `system_trail_methods`
--

DROP TABLE IF EXISTS `system_trail_methods`;
/*!40101 SET @saved_cs_client     = @@character_set_client */;
/*!40101 SET character_set_client = utf8 */;
CREATE TABLE `system_trail_methods` (
  `SYS_METHOD_ID` bigint(20) NOT NULL AUTO_INCREMENT,
  `SYS_METHOD_CODE` varchar(50) CHARACTER SET utf8 COLLATE utf8_unicode_ci NOT NULL,
  `SYS_METHOD_DESCRIPTION` varchar(500) CHARACTER SET utf8 COLLATE utf8_unicode_ci NOT NULL,
  `SYS_METHOD_STATUS` tinyint(4) NOT NULL,
  PRIMARY KEY (`SYS_METHOD_ID`)
) ENGINE=InnoDB AUTO_INCREMENT=5 DEFAULT CHARSET=latin1;
/*!40101 SET character_set_client = @saved_cs_client */;

--
-- Dumping data for table `system_trail_methods`
--

LOCK TABLES `system_trail_methods` WRITE;
/*!40000 ALTER TABLE `system_trail_methods` DISABLE KEYS */;
INSERT INTO `system_trail_methods` (`SYS_METHOD_ID`, `SYS_METHOD_CODE`, `SYS_METHOD_DESCRIPTION`, `SYS_METHOD_STATUS`) VALUES (1,'SAVE','Add/Edit record',2),(2,'DELETE','Deleted a record',2),(3,'DENY','Request denied due to missing enough access rights',2),(4,'AUTH','Authentication Request',2);
/*!40000 ALTER TABLE `system_trail_methods` ENABLE KEYS */;
UNLOCK TABLES;

--
-- Dumping events for database 'dsadeveloper_youattend'
--

--
-- Dumping routines for database 'dsadeveloper_youattend'
--
/*!50003 DROP FUNCTION IF EXISTS `ACCOUNT_ACCESS_RIGHTS@ACCESS_ID_EXISTS` */;
/*!50003 SET @saved_cs_client      = @@character_set_client */ ;
/*!50003 SET @saved_cs_results     = @@character_set_results */ ;
/*!50003 SET @saved_col_connection = @@collation_connection */ ;
/*!50003 SET character_set_client  = latin1 */ ;
/*!50003 SET character_set_results = latin1 */ ;
/*!50003 SET collation_connection  = latin1_swedish_ci */ ;
/*!50003 SET @saved_sql_mode       = @@sql_mode */ ;
/*!50003 SET sql_mode              = '' */ ;
DELIMITER ;;
CREATE DEFINER=`root`@`localhost` FUNCTION `ACCOUNT_ACCESS_RIGHTS@ACCESS_ID_EXISTS`(
	`PARAM_ACC_ACCESS_ID` BIGINT,
	`DO_NOT_RETURN_INACTIVE_RECORDS` BIT
) RETURNS tinyint(1)
SF_CHECK:
BEGIN

	-- STATUS
	-- ========================================================
	DECLARE STATUS_INACTIVE TINYINT DEFAULT 1;
	DECLARE STATUS_ACTIVE TINYINT DEFAULT 2;
	-- ========================================================

	-- CHECK IF EXISTS
	-- ========================================================
	IF
	(
		SELECT 
			COUNT(`account_access_rights`.`ACC_ACCESS_ID`)
		FROM `account_access_rights`
		WHERE
			`account_access_rights`.`ACC_ACCESS_ID` = PARAM_ACC_ACCESS_ID
		LIMIT 1
	) >= 1
	THEN
		return 1;
	ELSE
		return 0;
	END IF;
	-- ========================================================

	-- SQL Server requires to return value at the end of the function, even not reachable.
	return 0;

END ;;
DELIMITER ;
/*!50003 SET sql_mode              = @saved_sql_mode */ ;
/*!50003 SET character_set_client  = @saved_cs_client */ ;
/*!50003 SET character_set_results = @saved_cs_results */ ;
/*!50003 SET collation_connection  = @saved_col_connection */ ;
/*!50003 DROP FUNCTION IF EXISTS `ACCOUNT_ACCESS_RIGHTS@EDIT_HAS_PERMISSION` */;
/*!50003 SET @saved_cs_client      = @@character_set_client */ ;
/*!50003 SET @saved_cs_results     = @@character_set_results */ ;
/*!50003 SET @saved_col_connection = @@collation_connection */ ;
/*!50003 SET character_set_client  = latin1 */ ;
/*!50003 SET character_set_results = latin1 */ ;
/*!50003 SET collation_connection  = latin1_swedish_ci */ ;
/*!50003 SET @saved_sql_mode       = @@sql_mode */ ;
/*!50003 SET sql_mode              = '' */ ;
DELIMITER ;;
CREATE DEFINER=`root`@`localhost` FUNCTION `ACCOUNT_ACCESS_RIGHTS@EDIT_HAS_PERMISSION`(
	`PARAM_ACC_ACCESS_ACC_LEVEL_ID` BIGINT,
	`PARAM_ACC_ACCESS_SYS_MODULE_ID` BIGINT,
	`PARAM_ACC_ACCESS_SYS_AUTHORITY_ID` INT,
	`PARAM_ACC_ACCESS_AUTHORITY_POINT` BIGINT,
	
	`PARAM_REQUESTER_USERNAME` VARCHAR(500),
	`PARAM_REQUESTER_PASSWORD` VARCHAR(500)
) RETURNS tinyint(1)
SF_CHECK:
BEGIN

	-- INITIALIZE
	-- =================================================
	DECLARE TEMP_ACC_LEVEL_ID BIGINT DEFAULT 0;

	
	-- RETRIEVE ACCESS LEVEL
	-- =================================================
	SET TEMP_ACC_LEVEL_ID = `ACCOUNT_MEMBER@ACC_ACCOUNT_LEVEL_FROM_LOGIN`(PARAM_REQUESTER_USERNAME, PARAM_REQUESTER_PASSWORD);
	IF TEMP_ACC_LEVEL_ID <= 1 THEN
		Return 0;
	END IF;

	
	-- CHECK AUTHORITY ID AND POINT
	-- =================================================
	IF 
	(
		SELECT COUNT(`account_access_rights`.`ACC_ACCESS_ID`)
		FROM `account_access_rights`
		WHERE
			`account_access_rights`.`ACC_ACCESS_ACC_LEVEL_ID` = TEMP_ACC_LEVEL_ID AND
			`account_access_rights`.`ACC_ACCESS_SYS_MODULE_ID` = PARAM_ACC_ACCESS_SYS_MODULE_ID AND
			`account_access_rights`.`ACC_ACCESS_SYS_AUTHORITY_ID` >= PARAM_ACC_ACCESS_SYS_AUTHORITY_ID AND
			`account_access_rights`.`ACC_ACCESS_AUTHORITY_POINT` >= PARAM_ACC_ACCESS_AUTHORITY_POINT
		LIMIT 1
	) >= 1
	THEN
		Return 1;
	
	ELSE
		Return 0;
	
	END IF;
	
	
	-- ================================================
	Return 0;
	
END ;;
DELIMITER ;
/*!50003 SET sql_mode              = @saved_sql_mode */ ;
/*!50003 SET character_set_client  = @saved_cs_client */ ;
/*!50003 SET character_set_results = @saved_cs_results */ ;
/*!50003 SET collation_connection  = @saved_col_connection */ ;
/*!50003 DROP FUNCTION IF EXISTS `ACCOUNT_ACCESS_RIGHTS@HAS_PERMISSION` */;
/*!50003 SET @saved_cs_client      = @@character_set_client */ ;
/*!50003 SET @saved_cs_results     = @@character_set_results */ ;
/*!50003 SET @saved_col_connection = @@collation_connection */ ;
/*!50003 SET character_set_client  = latin1 */ ;
/*!50003 SET character_set_results = latin1 */ ;
/*!50003 SET collation_connection  = latin1_swedish_ci */ ;
/*!50003 SET @saved_sql_mode       = @@sql_mode */ ;
/*!50003 SET sql_mode              = '' */ ;
DELIMITER ;;
CREATE DEFINER=`root`@`localhost` FUNCTION `ACCOUNT_ACCESS_RIGHTS@HAS_PERMISSION`(
	PARAM_REQUESTER_USERNAME VARCHAR(500),
	PARAM_REQUESTER_PASSWORD VARCHAR(500),
	PARAM_SYS_MODULE_ID BIGINT,
	PARAM_SYS_MODULE_KEYWORD VARCHAR(500),
	PARAM_SYS_AUTHORITY_ID TINYINT
) RETURNS bit(1)
SF_CHECK:
BEGIN

	-- Initialize
	-- ========================================================================
	DECLARE TEMP_ERR_MESSAGE VARCHAR(500) DEFAULT '';
	DECLARE ERR BIGINT DEFAULT 0;
	DECLARE PARAM_ACC_LEVEL_ID BIGINT DEFAULT 0;
	-- ========================================================================
	
	-- VALIDATE AUTHORITY ID 
	-- =================================================
	IF PARAM_SYS_AUTHORITY_ID <= 0 THEN
		SET TEMP_ERR_MESSAGE = 'AUTHORITY_ID cannot be set to zero(0) on access check';
		SET ERR = `RAISERROR`(TEMP_ERR_MESSAGE);
	END IF;
	
	-- =================================================
	-- RETRIEVE ACCESS LEVEL
	-- =================================================
	SET PARAM_ACC_LEVEL_ID = `ACCOUNT_MEMBER@ACC_ACCOUNT_LEVEL_FROM_LOGIN`(PARAM_REQUESTER_USERNAME, PARAM_REQUESTER_PASSWORD);
	-- IF Visitor or unauthenticated user, always return false
	IF PARAM_ACC_LEVEL_ID <= 1 THEN
		RETURN 0;
	END IF;

	-- =================================================
	-- RETRIEVE MODULE_ID FROM MODULE_NAME
	-- =================================================
	IF 
		`SYSTEM_VAR@IS_NULL@BIGINT`(PARAM_SYS_MODULE_ID, 1, 1) = 1 AND 
		`SYSTEM_VAR@IS_NULL@NVARCHAR`(PARAM_SYS_MODULE_KEYWORD, 1) = 0
	THEN
		SET PARAM_SYS_MODULE_ID = `SYSTEM_MODULE@SYS_MODULE_ID_FROM_KEYWORD`(PARAM_SYS_MODULE_KEYWORD);
		IF `SYSTEM_VAR@IS_NULL@BIGINT`(PARAM_SYS_MODULE_ID, 1, 1) = 1 THEN
			SET TEMP_ERR_MESSAGE = CONCAT_WS(' ', 'Given module keyword does not exists or inactive:', PARAM_SYS_MODULE_KEYWORD);
			SET ERR = `RAISERROR`(TEMP_ERR_MESSAGE);
		END IF;
	END IF;
		
	-- =================================================
	-- CHECK IF MODULE AT `PARAM_SYS_MODULE_ID` EXISTS
	-- =================================================
	IF `SYSTEM_MODULE@SYS_MODULE_ID_EXISTS`(PARAM_SYS_MODULE_ID, 1) = 0 THEN
		SET TEMP_ERR_MESSAGE = CONCAT_WS(' ', 'Given module ID does not exists or inactive:', PARAM_SYS_MODULE_ID);
		SET ERR = `RAISERROR`(TEMP_ERR_MESSAGE);
	END IF;

	-- =================================================
	-- CHECK IF ACCESS LEVEL AT `PARAM_LEVEL_ID` EXISTS
	-- =================================================
	IF `ACCOUNT_LEVEL@ACC_LEVEL_ID_EXISTS`(PARAM_ACC_LEVEL_ID, 1) = 0 THEN
		SET TEMP_ERR_MESSAGE = CONCAT_WS(' ', 'Given access level does not exists or inactive:', PARAM_ACC_LEVEL_ID);
		SET ERR = `RAISERROR`(TEMP_ERR_MESSAGE);
	END IF;
		
		
	-- =================================================
	-- CHECK MODULE ACCESS RIGHTS
	-- =================================================	
	IF
	(
		SELECT COUNT(`account_access_rights`.`ACC_ACCESS_ID`)
		FROM `account_access_rights`
		WHERE
			`account_access_rights`.`ACC_ACCESS_ACC_LEVEL_ID` = PARAM_ACC_LEVEL_ID AND
			`account_access_rights`.`ACC_ACCESS_SYS_MODULE_ID` = PARAM_SYS_MODULE_ID AND
			`account_access_rights`.`ACC_ACCESS_SYS_AUTHORITY_ID` >= PARAM_SYS_AUTHORITY_ID
		LIMIT 1
	) >= 1
	THEN
		RETURN 1;
	ELSE
		RETURN 0;
	END IF;

	-- LEVEL IS NOT EXISTS OR DISABLED
	RETURN 0;

END ;;
DELIMITER ;
/*!50003 SET sql_mode              = @saved_sql_mode */ ;
/*!50003 SET character_set_client  = @saved_cs_client */ ;
/*!50003 SET character_set_results = @saved_cs_results */ ;
/*!50003 SET collation_connection  = @saved_col_connection */ ;
/*!50003 DROP FUNCTION IF EXISTS `ACCOUNT_ACCESS_RIGHTS@PROXY_PERMISSION` */;
/*!50003 SET @saved_cs_client      = @@character_set_client */ ;
/*!50003 SET @saved_cs_results     = @@character_set_results */ ;
/*!50003 SET @saved_col_connection = @@collation_connection */ ;
/*!50003 SET character_set_client  = latin1 */ ;
/*!50003 SET character_set_results = latin1 */ ;
/*!50003 SET collation_connection  = latin1_swedish_ci */ ;
/*!50003 SET @saved_sql_mode       = @@sql_mode */ ;
/*!50003 SET sql_mode              = '' */ ;
DELIMITER ;;
CREATE DEFINER=`root`@`localhost` FUNCTION `ACCOUNT_ACCESS_RIGHTS@PROXY_PERMISSION`(
	PARAM_REQUESTER_PROXY_ID BIGINT,
	PARAM_REQUESTER_PROXY_PASSWORD VARCHAR(1000),
	PARAM_SYS_MODULE_ID BIGINT,
	PARAM_SYS_MODULE_KEYWORD VARCHAR(500),
	PARAM_SYS_AUTHORITY_ID TINYINT
) RETURNS bit(1)
SF_CHECK:
BEGIN
	
	-- Initialize
	-- ========================================================================
	DECLARE TEMP_ERR_MESSAGE VARCHAR(500) DEFAULT '';
	DECLARE ERR BIGINT DEFAULT 0;
	DECLARE PARAM_ACC_LEVEL_ID BIGINT DEFAULT 0;
	-- ========================================================================
	
	-- VALIDATE AUTHORITY ID 
	-- =================================================
	IF PARAM_SYS_AUTHORITY_ID <= 0 THEN
		SET TEMP_ERR_MESSAGE = 'AUTHORITY_ID cannot be set to zero(0) on access check';
		SET ERR = `RAISERROR`(TEMP_ERR_MESSAGE);
	END IF;
	
	-- =================================================
	-- RETRIEVE ACCESS LEVEL
	-- =================================================
	SET PARAM_ACC_LEVEL_ID = `ACCOUNT_MEMBER@ACC_ACCOUNT_LEVEL_FROM_PROXY_LOGIN`(PARAM_REQUESTER_PROXY_ID, PARAM_REQUESTER_PROXY_PASSWORD);
	-- IF Visitor or unauthenticated user, always return false
	IF PARAM_ACC_LEVEL_ID <= 1 THEN
		RETURN 0;
	END IF;

	-- =================================================
	-- RETRIEVE MODULE_ID FROM MODULE_NAME
	-- =================================================
	IF 
		`SYSTEM_VAR@IS_NULL@BIGINT`(PARAM_SYS_MODULE_ID, 1, 1) = 1 AND 
		`SYSTEM_VAR@IS_NULL@NVARCHAR`(PARAM_SYS_MODULE_KEYWORD, 1) = 0
	THEN
		SET PARAM_SYS_MODULE_ID = `SYSTEM_MODULE@SYS_MODULE_ID_FROM_KEYWORD`(PARAM_SYS_MODULE_KEYWORD);
		IF `SYSTEM_VAR@IS_NULL@BIGINT`(PARAM_SYS_MODULE_ID, 1, 1) = 1 THEN
			SET TEMP_ERR_MESSAGE = CONCAT_WS(' ', 'Given module keyword does not exists or inactive:', PARAM_SYS_MODULE_KEYWORD);
			SET ERR = `RAISERROR`(TEMP_ERR_MESSAGE);
		END IF;
	END IF;
		
	-- =================================================
	-- CHECK IF MODULE AT `PARAM_SYS_MODULE_ID` EXISTS
	-- =================================================
	IF `SYSTEM_MODULE@SYS_MODULE_ID_EXISTS`(PARAM_SYS_MODULE_ID, 1) = 0 THEN
		SET TEMP_ERR_MESSAGE = CONCAT_WS(' ', 'Given module ID does not exists or inactive:', PARAM_SYS_MODULE_ID);
		SET ERR = `RAISERROR`(TEMP_ERR_MESSAGE);
	END IF;

	-- =================================================
	-- CHECK IF ACCESS LEVEL AT `PARAM_LEVEL_ID` EXISTS
	-- =================================================
	IF `ACCOUNT_LEVEL@ACC_LEVEL_ID_EXISTS`(PARAM_ACC_LEVEL_ID, 1) = 0 THEN
		SET TEMP_ERR_MESSAGE = CONCAT_WS(' ', 'Given access level does not exists or inactive:', PARAM_ACC_LEVEL_ID);
		SET ERR = `RAISERROR`(TEMP_ERR_MESSAGE);
	END IF;
		
		
	-- =================================================
	-- CHECK MODULE ACCESS RIGHTS
	-- =================================================	
	IF
	(
		SELECT COUNT(`account_access_rights`.`ACC_ACCESS_ID`)
		FROM `account_access_rights`
		WHERE
			`account_access_rights`.`ACC_ACCESS_ACC_LEVEL_ID` = PARAM_ACC_LEVEL_ID AND
			`account_access_rights`.`ACC_ACCESS_SYS_MODULE_ID` = PARAM_SYS_MODULE_ID AND
			`account_access_rights`.`ACC_ACCESS_SYS_AUTHORITY_ID` >= PARAM_SYS_AUTHORITY_ID
		LIMIT 1
	) >= 1
	THEN
		RETURN 1;
	ELSE
		RETURN 0;
	END IF;

	-- LEVEL IS NOT EXISTS OR DISABLED
	RETURN 0;

END ;;
DELIMITER ;
/*!50003 SET sql_mode              = @saved_sql_mode */ ;
/*!50003 SET character_set_client  = @saved_cs_client */ ;
/*!50003 SET character_set_results = @saved_cs_results */ ;
/*!50003 SET collation_connection  = @saved_col_connection */ ;
/*!50003 DROP FUNCTION IF EXISTS `ACCOUNT_AUDIT_TRAIL@REPLACE_ID` */;
/*!50003 SET @saved_cs_client      = @@character_set_client */ ;
/*!50003 SET @saved_cs_results     = @@character_set_results */ ;
/*!50003 SET @saved_col_connection = @@collation_connection */ ;
/*!50003 SET character_set_client  = latin1 */ ;
/*!50003 SET character_set_results = latin1 */ ;
/*!50003 SET collation_connection  = latin1_swedish_ci */ ;
/*!50003 SET @saved_sql_mode       = @@sql_mode */ ;
/*!50003 SET sql_mode              = '' */ ;
DELIMITER ;;
CREATE DEFINER=`root`@`localhost` FUNCTION `ACCOUNT_AUDIT_TRAIL@REPLACE_ID`(
	`PARAM_OLD_ID` BIGINT,
	`PARAM_NEW_ID` BIGINT,
	`PARAM_ID_HEADER` VARCHAR(500),
	`PARAM_RECORD_CHANGES` VARCHAR(10000)
) RETURNS varchar(10000) CHARSET utf8 COLLATE utf8_unicode_ci
SF_CHECK:
BEGIN

	-- STATUS
	-- ========================================================
	DECLARE STATUS_INACTIVE TINYINT DEFAULT 1;
	DECLARE STATUS_ACTIVE TINYINT DEFAULT 2;
	
	DECLARE PARAM_OLD_ID_HEADER VARCHAR(500) DEFAULT CONCAT_WS(' ', PARAM_ID_HEADER, PARAM_OLD_ID);
	DECLARE PARAM_NEW_ID_HEADER VARCHAR(500) DEFAULT CONCAT_WS(' ', PARAM_ID_HEADER, PARAM_NEW_ID);
	-- ========================================================

	
	-- Update Audit Trail with new ID
	-- ========================================================
	IF 
		CHAR_LENGTH(PARAM_RECORD_CHANGES) >= CHAR_LENGTH(PARAM_OLD_ID_HEADER) AND
		LEFT(PARAM_RECORD_CHANGES, CHAR_LENGTH(PARAM_OLD_ID_HEADER)) = PARAM_OLD_ID_HEADER
	THEN

		-- Replace ID
		SET PARAM_RECORD_CHANGES = 
		CONCAT_WS
		(
			' ', 
			PARAM_NEW_ID_HEADER,
			RIGHT(PARAM_RECORD_CHANGES, CHAR_LENGTH(PARAM_RECORD_CHANGES) - CHAR_LENGTH(PARAM_OLD_ID_HEADER))
		);
		
	END IF;
	-- ========================================================

	
	-- SQL Server requires to return value at the end of the function, even not reachable.
	return PARAM_RECORD_CHANGES;
	
END ;;
DELIMITER ;
/*!50003 SET sql_mode              = @saved_sql_mode */ ;
/*!50003 SET character_set_client  = @saved_cs_client */ ;
/*!50003 SET character_set_results = @saved_cs_results */ ;
/*!50003 SET collation_connection  = @saved_col_connection */ ;
/*!50003 DROP FUNCTION IF EXISTS `ACCOUNT_BFIP@ACC_BFIP_ID_EXISTS` */;
/*!50003 SET @saved_cs_client      = @@character_set_client */ ;
/*!50003 SET @saved_cs_results     = @@character_set_results */ ;
/*!50003 SET @saved_col_connection = @@collation_connection */ ;
/*!50003 SET character_set_client  = latin1 */ ;
/*!50003 SET character_set_results = latin1 */ ;
/*!50003 SET collation_connection  = latin1_swedish_ci */ ;
/*!50003 SET @saved_sql_mode       = @@sql_mode */ ;
/*!50003 SET sql_mode              = '' */ ;
DELIMITER ;;
CREATE DEFINER=`root`@`localhost` FUNCTION `ACCOUNT_BFIP@ACC_BFIP_ID_EXISTS`(
	PARAM_ACC_BFIP_ID BIGINT,
	DO_NOT_RETURN_INACTIVE_RECORDS BIT
) RETURNS tinyint(1)
SF_CHECK:
BEGIN

	-- STATUS
	-- ========================================================
	DECLARE STATUS_INACTIVE TINYINT DEFAULT 1;
	DECLARE STATUS_ACTIVE TINYINT DEFAULT 2;
	DECLARE STATUS_CLOSED TINYINT DEFAULT 3;
	DECLARE STATUS_COMPLETE TINYINT DEFAULT 4;
	-- ========================================================
	
	IF PARAM_ACC_BFIP_ID <= 0 THEN
		RETURN 0;
	END IF;

	-- CHECK IF EXISTS
	-- ========================================================
	IF
	(
		SELECT COUNT(`account_bfip`.`ACC_BFIP_ID`)
		FROM `account_bfip`
		WHERE
			`account_bfip`.`ACC_BFIP_ID` = PARAM_ACC_BFIP_ID 
			AND
			(
				DO_NOT_RETURN_INACTIVE_RECORDS = 0 OR
				`account_bfip`.`ACC_BFIP_STATUS` = STATUS_ACTIVE OR
				`account_bfip`.`ACC_BFIP_STATUS` = STATUS_COMPLETE
			)
		LIMIT 1
	) >= 1
	THEN
		RETURN 1;

	ELSE 
		RETURN 0;
		
	END IF;
	-- ========================================================


	-- SQL Server requires to return value at the end of the function, even not reachable.
	RETURN 0;
	
END ;;
DELIMITER ;
/*!50003 SET sql_mode              = @saved_sql_mode */ ;
/*!50003 SET character_set_client  = @saved_cs_client */ ;
/*!50003 SET character_set_results = @saved_cs_results */ ;
/*!50003 SET collation_connection  = @saved_col_connection */ ;
/*!50003 DROP FUNCTION IF EXISTS `ACCOUNT_BFIP@DESCRIPTION_FROM_ID` */;
/*!50003 SET @saved_cs_client      = @@character_set_client */ ;
/*!50003 SET @saved_cs_results     = @@character_set_results */ ;
/*!50003 SET @saved_col_connection = @@collation_connection */ ;
/*!50003 SET character_set_client  = latin1 */ ;
/*!50003 SET character_set_results = latin1 */ ;
/*!50003 SET collation_connection  = latin1_swedish_ci */ ;
/*!50003 SET @saved_sql_mode       = @@sql_mode */ ;
/*!50003 SET sql_mode              = '' */ ;
DELIMITER ;;
CREATE DEFINER=`root`@`localhost` FUNCTION `ACCOUNT_BFIP@DESCRIPTION_FROM_ID`(
	PARAM_ACC_BFIP_ID BIGINT
) RETURNS varchar(16000) CHARSET utf8 COLLATE utf8_unicode_ci
SF_CHECK:
BEGIN

	-- INITIALIZE
	DECLARE TEMP_DESCRIPTION VARCHAR(16000) DEFAULT '';

	
	-- GET DESCRIPTION
	-- ====================================================================
	IF `ACCOUNT_BFIP@ACC_BFIP_ID_EXISTS`(PARAM_ACC_BFIP_ID, 0) = 1 THEN

		SELECT
			`account_bfip`.`ACC_BFIP_IP`
		INTO
			TEMP_DESCRIPTION
		FROM `account_bfip`
		WHERE
			`account_bfip`.`ACC_BFIP_ID` = PARAM_ACC_BFIP_ID
		LIMIT 1;

	ELSE
		SET TEMP_DESCRIPTION = 'NULL';
	END IF;
	-- ====================================================================

	-- SQL Server requires to return value at the end of the function, even not reachable.
	return TEMP_DESCRIPTION;
END ;;
DELIMITER ;
/*!50003 SET sql_mode              = @saved_sql_mode */ ;
/*!50003 SET character_set_client  = @saved_cs_client */ ;
/*!50003 SET character_set_results = @saved_cs_results */ ;
/*!50003 SET collation_connection  = @saved_col_connection */ ;
/*!50003 DROP FUNCTION IF EXISTS `ACCOUNT_BFIP@ID_FROM_DESCRIPTION` */;
/*!50003 SET @saved_cs_client      = @@character_set_client */ ;
/*!50003 SET @saved_cs_results     = @@character_set_results */ ;
/*!50003 SET @saved_col_connection = @@collation_connection */ ;
/*!50003 SET character_set_client  = latin1 */ ;
/*!50003 SET character_set_results = latin1 */ ;
/*!50003 SET collation_connection  = latin1_swedish_ci */ ;
/*!50003 SET @saved_sql_mode       = @@sql_mode */ ;
/*!50003 SET sql_mode              = '' */ ;
DELIMITER ;;
CREATE DEFINER=`root`@`localhost` FUNCTION `ACCOUNT_BFIP@ID_FROM_DESCRIPTION`(
	PARAM_ACC_BFIP_IP VARCHAR(400)
) RETURNS bigint(20)
SF_CHECK:
BEGIN

	-- INITIALIZE
	DECLARE TEMP_ID BIGINT DEFAULT 0;

	
	-- GET DESCRIPTION
	-- ====================================================================
	IF 
		(
			SELECT COUNT(`account_bfip`.`ACC_BFIP_ID`)
			FROM `account_bfip`
			WHERE
				`account_bfip`.`ACC_BFIP_IP` = PARAM_ACC_BFIP_IP
			LIMIT 1
		) >= 1
	THEN

		SELECT
			`account_bfip`.`ACC_BFIP_ID`
		INTO
			TEMP_ID
		FROM `account_bfip`
		WHERE
			`account_bfip`.`ACC_BFIP_IP` = PARAM_ACC_BFIP_IP
		LIMIT 1;

	END IF;
	-- ====================================================================

	-- SQL Server requires to return value at the end of the function, even not reachable.
	return TEMP_ID;
END ;;
DELIMITER ;
/*!50003 SET sql_mode              = @saved_sql_mode */ ;
/*!50003 SET character_set_client  = @saved_cs_client */ ;
/*!50003 SET character_set_results = @saved_cs_results */ ;
/*!50003 SET collation_connection  = @saved_col_connection */ ;
/*!50003 DROP FUNCTION IF EXISTS `ACCOUNT_BFIP@IS_BANNED` */;
/*!50003 SET @saved_cs_client      = @@character_set_client */ ;
/*!50003 SET @saved_cs_results     = @@character_set_results */ ;
/*!50003 SET @saved_col_connection = @@collation_connection */ ;
/*!50003 SET character_set_client  = latin1 */ ;
/*!50003 SET character_set_results = latin1 */ ;
/*!50003 SET collation_connection  = latin1_swedish_ci */ ;
/*!50003 SET @saved_sql_mode       = @@sql_mode */ ;
/*!50003 SET sql_mode              = '' */ ;
DELIMITER ;;
CREATE DEFINER=`root`@`localhost` FUNCTION `ACCOUNT_BFIP@IS_BANNED`(
	`PARAM_REQUESTER_USERNAME` VARCHAR(500),
	`PARAM_REQUESTER_IP` VARCHAR(1000)
) RETURNS tinyint(1)
SF_CHECK:
BEGIN

	-- STATUS
	-- ========================================================
	DECLARE STATUS_INACTIVE TINYINT DEFAULT 1;
	DECLARE STATUS_ACTIVE TINYINT DEFAULT 2;
	DECLARE STATUS_CLOSED TINYINT DEFAULT 3;
	DECLARE STATUS_COMPLETE TINYINT DEFAULT 4;
	
	-- INITIALIZE
	-- ========================================================
	DECLARE TEMP_ACC_BFIP_STATUS TINYINT DEFAULT 0;
	DECLARE TEMP_NOW DATETIME(6) DEFAULT `SYSTEM_VAR@NOW`('', 1);
	DECLARE TEMP_DATE_FROM DATETIME(6) DEFAULT `SYSTEM_VAR@NOW`('', 1);

	DECLARE BRUTEFORCE_USERNAME_BLOCK_PERIOD TINYINT DEFAULT 0;
	DECLARE BRUTEFORCE_USERNAME_BLOCK_ATTEMPT TINYINT DEFAULT 0;
	

	-- ALLOW IF IP IS NOT YET REGISTERED
	-- ========================================================
	SELECT
		`account_bfip`.`ACC_BFIP_STATUS`
	INTO
		TEMP_ACC_BFIP_STATUS
	FROM `account_bfip`
	WHERE
		`account_bfip`.`ACC_BFIP_IP` = PARAM_REQUESTER_IP
	LIMIT 1;

	IF TEMP_ACC_BFIP_STATUS <= 0 THEN
		RETURN 0;
	END IF;


	-- CHECK IP, IF [BLOCKED - 1] OR [BLACK LISTED - 3]
	-- ========================================================
	IF TEMP_ACC_BFIP_STATUS = STATUS_INACTIVE OR TEMP_ACC_BFIP_STATUS = STATUS_CLOSED THEN
		RETURN 1;
	END IF;
	
	
	-- ABORT IF [WHITE LISTED - 4]
	-- ========================================================
	IF TEMP_ACC_BFIP_STATUS = STATUS_COMPLETE THEN
		RETURN 0;
	END IF;


	-- Get BruteForce Settings [User Block Count, User Block Duration]
	-- ========================================================
	SELECT `system_settings`.`SYS_SETTINGS_VAL_BIGINT`
	INTO BRUTEFORCE_USERNAME_BLOCK_PERIOD
	FROM `system_settings`
	WHERE
		`system_settings`.`SYS_SETTINGS_CODE` = 'BRUTEFORCE_USERNAME_BLOCK_PERIOD'
	LIMIT 1;
	
	SELECT `system_settings`.`SYS_SETTINGS_VAL_BIGINT`
	INTO BRUTEFORCE_USERNAME_BLOCK_ATTEMPT
	FROM `system_settings`
	WHERE
		`system_settings`.`SYS_SETTINGS_CODE` = 'BRUTEFORCE_USERNAME_BLOCK_ATTEMPT'
	LIMIT 1;

	SET TEMP_DATE_FROM = DATE_SUB(TEMP_NOW, INTERVAL BRUTEFORCE_USERNAME_BLOCK_PERIOD MINUTE);
	

	-- CHECK IF USER IS LOCKED
	-- ========================================================
	IF
		BRUTEFORCE_USERNAME_BLOCK_ATTEMPT > 0 AND
		(
			SELECT COUNT(`account_bflogin`.`ACC_BFLOGIN_ID`)
			FROM `account_bflogin`
			WHERE
				`account_bflogin`.`ACC_BFLOGIN_USERNAME` = PARAM_REQUESTER_USERNAME AND
				`account_bflogin`.`ACC_BFLOGIN_DATE` >= TEMP_DATE_FROM AND
				`account_bflogin`.`ACC_BFLOGIN_STATUS` = STATUS_INACTIVE
			LIMIT 1
		) >= BRUTEFORCE_USERNAME_BLOCK_ATTEMPT
	THEN
		RETURN 1;
	END IF;


	-- Non-restricted IP/User
	-- ========================================================
	RETURN 0;
	
END ;;
DELIMITER ;
/*!50003 SET sql_mode              = @saved_sql_mode */ ;
/*!50003 SET character_set_client  = @saved_cs_client */ ;
/*!50003 SET character_set_results = @saved_cs_results */ ;
/*!50003 SET collation_connection  = @saved_col_connection */ ;
/*!50003 DROP FUNCTION IF EXISTS `ACCOUNT_BFLOGIN@ACC_BFLOGIN_ID_EXISTS` */;
/*!50003 SET @saved_cs_client      = @@character_set_client */ ;
/*!50003 SET @saved_cs_results     = @@character_set_results */ ;
/*!50003 SET @saved_col_connection = @@collation_connection */ ;
/*!50003 SET character_set_client  = latin1 */ ;
/*!50003 SET character_set_results = latin1 */ ;
/*!50003 SET collation_connection  = latin1_swedish_ci */ ;
/*!50003 SET @saved_sql_mode       = @@sql_mode */ ;
/*!50003 SET sql_mode              = '' */ ;
DELIMITER ;;
CREATE DEFINER=`root`@`localhost` FUNCTION `ACCOUNT_BFLOGIN@ACC_BFLOGIN_ID_EXISTS`(
	PARAM_ACC_BFLOGIN_ID BIGINT,
	DO_NOT_RETURN_INACTIVE_RECORDS BIT
) RETURNS tinyint(1)
SF_CHECK:
BEGIN

	-- STATUS
	-- ========================================================
	DECLARE STATUS_INACTIVE TINYINT DEFAULT 1;
	DECLARE STATUS_ACTIVE TINYINT DEFAULT 2;
	DECLARE STATUS_CLOSED TINYINT DEFAULT 3;
	DECLARE STATUS_COMPLETE TINYINT DEFAULT 4;
	-- ========================================================
	
	IF PARAM_ACC_BFLOGIN_ID <= 0 THEN
		RETURN 0;
	END IF;

	-- CHECK IF EXISTS
	-- ========================================================
	IF
	(
		SELECT COUNT(`account_bflogin`.`ACC_BFLOGIN_ID`)
		FROM `account_bflogin`
		WHERE
			`account_bflogin`.`ACC_BFLOGIN_ID` = PARAM_ACC_BFLOGIN_ID 
			AND
			(
				DO_NOT_RETURN_INACTIVE_RECORDS = 0 OR
				`account_bflogin`.`ACC_BTFORCE_STATUS` = STATUS_ACTIVE OR
				`account_bflogin`.`ACC_BTFORCE_STATUS` = STATUS_COMPLETE
			)
		LIMIT 1
	) >= 1
	THEN
		RETURN 1;

	ELSE 
		RETURN 0;
		
	END IF;
	-- ========================================================


	-- SQL Server requires to return value at the end of the function, even not reachable.
	RETURN 0;
	
END ;;
DELIMITER ;
/*!50003 SET sql_mode              = @saved_sql_mode */ ;
/*!50003 SET character_set_client  = @saved_cs_client */ ;
/*!50003 SET character_set_results = @saved_cs_results */ ;
/*!50003 SET collation_connection  = @saved_col_connection */ ;
/*!50003 DROP FUNCTION IF EXISTS `ACCOUNT_BFLOGIN@DESCRIPTION_FROM_ID` */;
/*!50003 SET @saved_cs_client      = @@character_set_client */ ;
/*!50003 SET @saved_cs_results     = @@character_set_results */ ;
/*!50003 SET @saved_col_connection = @@collation_connection */ ;
/*!50003 SET character_set_client  = latin1 */ ;
/*!50003 SET character_set_results = latin1 */ ;
/*!50003 SET collation_connection  = latin1_swedish_ci */ ;
/*!50003 SET @saved_sql_mode       = @@sql_mode */ ;
/*!50003 SET sql_mode              = '' */ ;
DELIMITER ;;
CREATE DEFINER=`root`@`localhost` FUNCTION `ACCOUNT_BFLOGIN@DESCRIPTION_FROM_ID`(
	PARAM_ACC_BFLOGIN_ID BIGINT
) RETURNS varchar(16000) CHARSET utf8 COLLATE utf8_unicode_ci
SF_CHECK:
BEGIN

	-- INITIALIZE
	DECLARE TEMP_DESCRIPTION VARCHAR(16000) DEFAULT '';

	
	-- GET DESCRIPTION
	-- ====================================================================
	IF `ACCOUNT_BFLOGIN@ACC_BFLOGIN_ID_EXISTS`(PARAM_ACC_BFLOGIN_ID, 0) = 1 THEN

		SELECT
			`account_bflogin`.`ACC_BFLOGIN_USERNAME`
		INTO
			TEMP_DESCRIPTION
		FROM `account_bflogin`
		WHERE
			`account_bflogin`.`ACC_BFLOGIN_ID` = PARAM_ACC_BFLOGIN_ID
		LIMIT 1;

	ELSE
		SET TEMP_DESCRIPTION = 'NULL';
	END IF;
	-- ====================================================================

	-- SQL Server requires to return value at the end of the function, even not reachable.
	return TEMP_DESCRIPTION;
END ;;
DELIMITER ;
/*!50003 SET sql_mode              = @saved_sql_mode */ ;
/*!50003 SET character_set_client  = @saved_cs_client */ ;
/*!50003 SET character_set_results = @saved_cs_results */ ;
/*!50003 SET collation_connection  = @saved_col_connection */ ;
/*!50003 DROP FUNCTION IF EXISTS `ACCOUNT_BFLOGIN@ID_FROM_DESCRIPTION` */;
/*!50003 SET @saved_cs_client      = @@character_set_client */ ;
/*!50003 SET @saved_cs_results     = @@character_set_results */ ;
/*!50003 SET @saved_col_connection = @@collation_connection */ ;
/*!50003 SET character_set_client  = latin1 */ ;
/*!50003 SET character_set_results = latin1 */ ;
/*!50003 SET collation_connection  = latin1_swedish_ci */ ;
/*!50003 SET @saved_sql_mode       = @@sql_mode */ ;
/*!50003 SET sql_mode              = '' */ ;
DELIMITER ;;
CREATE DEFINER=`root`@`localhost` FUNCTION `ACCOUNT_BFLOGIN@ID_FROM_DESCRIPTION`(
	PARAM_ACC_BFLOGIN_USERNAME VARCHAR(400)
) RETURNS bigint(20)
SF_CHECK:
BEGIN

	-- INITIALIZE
	DECLARE TEMP_ID BIGINT DEFAULT 0;

	
	-- GET DESCRIPTION
	-- ====================================================================
	IF 
		(
			SELECT COUNT(`account_bflogin`.`ACC_BFLOGIN_ID`)
			FROM `account_bflogin`
			WHERE
				`account_bflogin`.`ACC_BFLOGIN_USERNAME` = PARAM_ACC_BFLOGIN_USERNAME
			LIMIT 1
		) >= 1
	THEN

		SELECT
			`account_bflogin`.`ACC_BFLOGIN_ID`
		INTO
			TEMP_ID
		FROM `account_bflogin`
		WHERE
			`account_bflogin`.`ACC_BFLOGIN_USERNAME` = PARAM_ACC_BFLOGIN_USERNAME
		LIMIT 1;

	END IF;
	-- ====================================================================

	-- SQL Server requires to return value at the end of the function, even not reachable.
	return TEMP_ID;
END ;;
DELIMITER ;
/*!50003 SET sql_mode              = @saved_sql_mode */ ;
/*!50003 SET character_set_client  = @saved_cs_client */ ;
/*!50003 SET character_set_results = @saved_cs_results */ ;
/*!50003 SET collation_connection  = @saved_col_connection */ ;
/*!50003 DROP FUNCTION IF EXISTS `ACCOUNT_DEVICE@ACC_DEVICE_ID_EXISTS` */;
/*!50003 SET @saved_cs_client      = @@character_set_client */ ;
/*!50003 SET @saved_cs_results     = @@character_set_results */ ;
/*!50003 SET @saved_col_connection = @@collation_connection */ ;
/*!50003 SET character_set_client  = latin1 */ ;
/*!50003 SET character_set_results = latin1 */ ;
/*!50003 SET collation_connection  = latin1_swedish_ci */ ;
/*!50003 SET @saved_sql_mode       = @@sql_mode */ ;
/*!50003 SET sql_mode              = '' */ ;
DELIMITER ;;
CREATE DEFINER=`root`@`localhost` FUNCTION `ACCOUNT_DEVICE@ACC_DEVICE_ID_EXISTS`(
	PARAM_ACC_DEVICE_ID BIGINT,
	DO_NOT_RETURN_INACTIVE_RECORDS BIT
) RETURNS tinyint(1)
SF_CHECK:
BEGIN

	-- STATUS
	-- ========================================================
	DECLARE STATUS_INACTIVE TINYINT DEFAULT 1;
	DECLARE STATUS_ACTIVE TINYINT DEFAULT 2;
	DECLARE STATUS_CLOSED TINYINT DEFAULT 3;
	DECLARE STATUS_COMPLETE TINYINT DEFAULT 4;
	-- ========================================================
	
	IF PARAM_ACC_DEVICE_ID <= 0 THEN
		RETURN 0;
	END IF;

	-- CHECK IF EXISTS
	-- ========================================================
	IF
	(
		SELECT COUNT(`account_device`.`ACC_DEVICE_ID`)
		FROM `account_device`
		WHERE
			`account_device`.`ACC_DEVICE_ID` = PARAM_ACC_DEVICE_ID 
			AND
			(
				DO_NOT_RETURN_INACTIVE_RECORDS = 0 OR
				`account_device`.`ACC_DEVICE_STATUS` = STATUS_ACTIVE
			)
		LIMIT 1
	) >= 1
	THEN
		RETURN 1;

	ELSE 
		RETURN 0;
		
	END IF;
	-- ========================================================


	-- SQL Server requires to return value at the end of the function, even not reachable.
	RETURN 0;
	
END ;;
DELIMITER ;
/*!50003 SET sql_mode              = @saved_sql_mode */ ;
/*!50003 SET character_set_client  = @saved_cs_client */ ;
/*!50003 SET character_set_results = @saved_cs_results */ ;
/*!50003 SET collation_connection  = @saved_col_connection */ ;
/*!50003 DROP FUNCTION IF EXISTS `ACCOUNT_DEVICE@ACC_DEVICE_ID_FROM_LOGIN` */;
/*!50003 SET @saved_cs_client      = @@character_set_client */ ;
/*!50003 SET @saved_cs_results     = @@character_set_results */ ;
/*!50003 SET @saved_col_connection = @@collation_connection */ ;
/*!50003 SET character_set_client  = latin1 */ ;
/*!50003 SET character_set_results = latin1 */ ;
/*!50003 SET collation_connection  = latin1_swedish_ci */ ;
/*!50003 SET @saved_sql_mode       = @@sql_mode */ ;
/*!50003 SET sql_mode              = '' */ ;
DELIMITER ;;
CREATE DEFINER=`root`@`localhost` FUNCTION `ACCOUNT_DEVICE@ACC_DEVICE_ID_FROM_LOGIN`(
	PARAM_REQUESTER_DEVICE_PUBLIC_KEY VARCHAR(1000),
	PARAM_REQUESTER_DEVICE_PRIVATE_KEY VARCHAR(1000)
) RETURNS bigint(20)
BEGIN

	-- Initialize
	-- .........................................................
	DECLARE PARAM_ACC_DEVICE_ID BIGINT DEFAULT 0;
	
			
	-- RETRIEVE DEVICE
	-- .........................................................
	IF
		(
			SELECT COUNT(`account_device`.`ACC_DEVICE_ID`)
			FROM `account_device`
			WHERE
				BINARY `account_device`.`ACC_DEVICE_PUBLIC_KEY` = PARAM_REQUESTER_DEVICE_PUBLIC_KEY AND
				BINARY `account_device`.`ACC_DEVICE_PRIVATE_KEY` = PARAM_REQUESTER_DEVICE_PRIVATE_KEY
			LIMIT 1
		) > 0
	THEN
		-- RETRIEVE LEVEL
		SELECT
			`account_device`.`ACC_DEVICE_ID`
		INTO
			PARAM_ACC_DEVICE_ID
		FROM `account_device`
		WHERE
			BINARY `account_device`.`ACC_DEVICE_PUBLIC_KEY` = PARAM_REQUESTER_DEVICE_PUBLIC_KEY AND
			BINARY `account_device`.`ACC_DEVICE_PRIVATE_KEY` = PARAM_REQUESTER_DEVICE_PRIVATE_KEY
		LIMIT 1;
	END IF;

	-- Return result
	-- .........................................................
	RETURN PARAM_ACC_DEVICE_ID;

END ;;
DELIMITER ;
/*!50003 SET sql_mode              = @saved_sql_mode */ ;
/*!50003 SET character_set_client  = @saved_cs_client */ ;
/*!50003 SET character_set_results = @saved_cs_results */ ;
/*!50003 SET collation_connection  = @saved_col_connection */ ;
/*!50003 DROP FUNCTION IF EXISTS `ACCOUNT_DEVICE@DESCRIPTION_FROM_ID` */;
/*!50003 SET @saved_cs_client      = @@character_set_client */ ;
/*!50003 SET @saved_cs_results     = @@character_set_results */ ;
/*!50003 SET @saved_col_connection = @@collation_connection */ ;
/*!50003 SET character_set_client  = latin1 */ ;
/*!50003 SET character_set_results = latin1 */ ;
/*!50003 SET collation_connection  = latin1_swedish_ci */ ;
/*!50003 SET @saved_sql_mode       = @@sql_mode */ ;
/*!50003 SET sql_mode              = '' */ ;
DELIMITER ;;
CREATE DEFINER=`root`@`localhost` FUNCTION `ACCOUNT_DEVICE@DESCRIPTION_FROM_ID`(
	PARAM_ACC_DEVICE_ID BIGINT
) RETURNS varchar(16000) CHARSET utf8 COLLATE utf8_unicode_ci
SF_CHECK:
BEGIN

	-- INITIALIZE
	DECLARE TEMP_DESCRIPTION VARCHAR(16000) DEFAULT '';

	
	-- GET DESCRIPTION
	-- ====================================================================
	IF `ACCOUNT_DEVICE@ACC_DEVICE_ID_EXISTS`(PARAM_ACC_DEVICE_ID, 0) = 1 THEN

		SELECT
			`account_device`.`ACC_DEVICE_DESCRIPTION`
		INTO
			TEMP_DESCRIPTION
		FROM `account_device`
		WHERE
			`account_device`.`ACC_DEVICE_ID` = PARAM_ACC_DEVICE_ID
		LIMIT 1;

	ELSE
		SET TEMP_DESCRIPTION = 'NULL';
	END IF;
	-- ====================================================================

	-- SQL Server requires to return value at the end of the function, even not reachable.
	return TEMP_DESCRIPTION;
END ;;
DELIMITER ;
/*!50003 SET sql_mode              = @saved_sql_mode */ ;
/*!50003 SET character_set_client  = @saved_cs_client */ ;
/*!50003 SET character_set_results = @saved_cs_results */ ;
/*!50003 SET collation_connection  = @saved_col_connection */ ;
/*!50003 DROP FUNCTION IF EXISTS `ACCOUNT_DEVICE@HAS_PERMISSION` */;
/*!50003 SET @saved_cs_client      = @@character_set_client */ ;
/*!50003 SET @saved_cs_results     = @@character_set_results */ ;
/*!50003 SET @saved_col_connection = @@collation_connection */ ;
/*!50003 SET character_set_client  = latin1 */ ;
/*!50003 SET character_set_results = latin1 */ ;
/*!50003 SET collation_connection  = latin1_swedish_ci */ ;
/*!50003 SET @saved_sql_mode       = @@sql_mode */ ;
/*!50003 SET sql_mode              = '' */ ;
DELIMITER ;;
CREATE DEFINER=`root`@`localhost` FUNCTION `ACCOUNT_DEVICE@HAS_PERMISSION`(
	PARAM_ACC_DEVICE_PUBLIC_KEY VARCHAR(1000),
	PARAM_ACC_DEVICE_PRIVATE_KEY VARCHAR(1000)
) RETURNS bit(1)
BEGIN

	RETURN 1;

END ;;
DELIMITER ;
/*!50003 SET sql_mode              = @saved_sql_mode */ ;
/*!50003 SET character_set_client  = @saved_cs_client */ ;
/*!50003 SET character_set_results = @saved_cs_results */ ;
/*!50003 SET collation_connection  = @saved_col_connection */ ;
/*!50003 DROP FUNCTION IF EXISTS `ACCOUNT_DEVICE@ID_FROM_PUBLIC_KEY` */;
/*!50003 SET @saved_cs_client      = @@character_set_client */ ;
/*!50003 SET @saved_cs_results     = @@character_set_results */ ;
/*!50003 SET @saved_col_connection = @@collation_connection */ ;
/*!50003 SET character_set_client  = latin1 */ ;
/*!50003 SET character_set_results = latin1 */ ;
/*!50003 SET collation_connection  = latin1_swedish_ci */ ;
/*!50003 SET @saved_sql_mode       = @@sql_mode */ ;
/*!50003 SET sql_mode              = '' */ ;
DELIMITER ;;
CREATE DEFINER=`root`@`localhost` FUNCTION `ACCOUNT_DEVICE@ID_FROM_PUBLIC_KEY`(
	PARAM_ACC_DEVICE_PUBLIC_KEY VARCHAR(400)
) RETURNS bigint(20)
SF_CHECK:
BEGIN

	-- INITIALIZE
	DECLARE TEMP_ACC_DEVICE_ID BIGINT DEFAULT 0;

	
	-- GET DESCRIPTION
	-- ====================================================================
	IF 
		(
			SELECT
				COUNT(`account_device`.`ACC_DEVICE_ID`)
			FROM `account_device`
			WHERE
				`account_device`.`ACC_DEVICE_PUBLIC_KEY` = PARAM_ACC_DEVICE_PUBLIC_KEY
			LIMIT 1
		) >= 1
	THEN

		SELECT
			`account_device`.`ACC_DEVICE_ID`
		INTO
			TEMP_ACC_DEVICE_ID
		FROM `account_device`
		WHERE
			`account_device`.`ACC_DEVICE_PUBLIC_KEY` = PARAM_ACC_DEVICE_PUBLIC_KEY
		LIMIT 1;

	ELSE
		SET TEMP_ACC_DEVICE_ID = 0;
	END IF;
	-- ====================================================================

	-- SQL Server requires to return value at the end of the function, even not reachable.
	return TEMP_ACC_DEVICE_ID;
END ;;
DELIMITER ;
/*!50003 SET sql_mode              = @saved_sql_mode */ ;
/*!50003 SET character_set_client  = @saved_cs_client */ ;
/*!50003 SET character_set_results = @saved_cs_results */ ;
/*!50003 SET collation_connection  = @saved_col_connection */ ;
/*!50003 DROP FUNCTION IF EXISTS `ACCOUNT_DEVICE@IS_SELF` */;
/*!50003 SET @saved_cs_client      = @@character_set_client */ ;
/*!50003 SET @saved_cs_results     = @@character_set_results */ ;
/*!50003 SET @saved_col_connection = @@collation_connection */ ;
/*!50003 SET character_set_client  = latin1 */ ;
/*!50003 SET character_set_results = latin1 */ ;
/*!50003 SET collation_connection  = latin1_swedish_ci */ ;
/*!50003 SET @saved_sql_mode       = @@sql_mode */ ;
/*!50003 SET sql_mode              = '' */ ;
DELIMITER ;;
CREATE DEFINER=`root`@`localhost` FUNCTION `ACCOUNT_DEVICE@IS_SELF`() RETURNS bit(1)
BEGIN

	-- Verify if Connection if come from SELF(LocalHost)
	IF
	(
		SELECT COUNT(`information_schema`.`processlist`.`ID`)
		FROM `information_schema`.`processlist`
		WHERE 
			`information_schema`.`processlist`.`ID` = CONNECTION_ID() AND
			LEFT(`information_schema`.`processlist`.`host`, 10) = 'localhost:'
	) > 0
	THEN
		RETURN 1;
	END IF;

	-- Return False
	RETURN 0;

END ;;
DELIMITER ;
/*!50003 SET sql_mode              = @saved_sql_mode */ ;
/*!50003 SET character_set_client  = @saved_cs_client */ ;
/*!50003 SET character_set_results = @saved_cs_results */ ;
/*!50003 SET collation_connection  = @saved_col_connection */ ;
/*!50003 DROP FUNCTION IF EXISTS `ACCOUNT_DEVICE@PUBLIC_KEY_FROM_ID` */;
/*!50003 SET @saved_cs_client      = @@character_set_client */ ;
/*!50003 SET @saved_cs_results     = @@character_set_results */ ;
/*!50003 SET @saved_col_connection = @@collation_connection */ ;
/*!50003 SET character_set_client  = latin1 */ ;
/*!50003 SET character_set_results = latin1 */ ;
/*!50003 SET collation_connection  = latin1_swedish_ci */ ;
/*!50003 SET @saved_sql_mode       = @@sql_mode */ ;
/*!50003 SET sql_mode              = '' */ ;
DELIMITER ;;
CREATE DEFINER=`root`@`localhost` FUNCTION `ACCOUNT_DEVICE@PUBLIC_KEY_FROM_ID`(
	PARAM_ACC_DEVICE_ID BIGINT
) RETURNS varchar(16000) CHARSET utf8 COLLATE utf8_unicode_ci
SF_CHECK:
BEGIN

	-- INITIALIZE
	DECLARE TEMP_PUBLIC_KEY VARCHAR(16000) DEFAULT '';

	
	-- GET DESCRIPTION
	-- ====================================================================
	IF `ACCOUNT_DEVICE@ACC_DEVICE_ID_EXISTS`(PARAM_ACC_DEVICE_ID, 0) = 1 THEN

		SELECT
			`account_device`.`ACC_DEVICE_PUBLIC_KEY`
		INTO
			TEMP_PUBLIC_KEY
		FROM `account_device`
		WHERE
			`account_device`.`ACC_DEVICE_ID` = PARAM_ACC_DEVICE_ID
		LIMIT 1;

	ELSE
		SET TEMP_PUBLIC_KEY = 'NULL';
	END IF;
	-- ====================================================================

	-- SQL Server requires to return value at the end of the function, even not reachable.
	return TEMP_PUBLIC_KEY;
END ;;
DELIMITER ;
/*!50003 SET sql_mode              = @saved_sql_mode */ ;
/*!50003 SET character_set_client  = @saved_cs_client */ ;
/*!50003 SET character_set_results = @saved_cs_results */ ;
/*!50003 SET collation_connection  = @saved_col_connection */ ;
/*!50003 DROP FUNCTION IF EXISTS `ACCOUNT_GROUP@ACC_GROUP_ID_EXISTS` */;
/*!50003 SET @saved_cs_client      = @@character_set_client */ ;
/*!50003 SET @saved_cs_results     = @@character_set_results */ ;
/*!50003 SET @saved_col_connection = @@collation_connection */ ;
/*!50003 SET character_set_client  = latin1 */ ;
/*!50003 SET character_set_results = latin1 */ ;
/*!50003 SET collation_connection  = latin1_swedish_ci */ ;
/*!50003 SET @saved_sql_mode       = @@sql_mode */ ;
/*!50003 SET sql_mode              = '' */ ;
DELIMITER ;;
CREATE DEFINER=`root`@`localhost` FUNCTION `ACCOUNT_GROUP@ACC_GROUP_ID_EXISTS`(
	PARAM_ACC_GROUP_ID BIGINT,
	DO_NOT_RETURN_INACTIVE_RECORDS BIT
) RETURNS tinyint(1)
SF_CHECK:
BEGIN

	-- STATUS
	-- ========================================================
	DECLARE STATUS_INACTIVE TINYINT DEFAULT 1;
	DECLARE STATUS_ACTIVE TINYINT DEFAULT 2;
	-- ========================================================
	
	IF PARAM_ACC_GROUP_ID <= 0 THEN
		RETURN 0;
	END IF;

	-- CHECK IF EXISTS
	-- ========================================================
	IF
	(
		SELECT COUNT(`account_group`.`ACC_GROUP_ID`)
		FROM `account_group`
		WHERE
			`account_group`.`ACC_GROUP_ID` = PARAM_ACC_GROUP_ID 
			AND
			(
				DO_NOT_RETURN_INACTIVE_RECORDS = 0 OR
				`account_group`.`ACC_GROUP_STATUS` = STATUS_ACTIVE
			)
		LIMIT 1
	) >= 1
	THEN
		RETURN 1;

	ELSE 
		RETURN 0;
		
	END IF;
	-- ========================================================


	-- SQL Server requires to return value at the end of the function, even not reachable.
	RETURN 0;
	
END ;;
DELIMITER ;
/*!50003 SET sql_mode              = @saved_sql_mode */ ;
/*!50003 SET character_set_client  = @saved_cs_client */ ;
/*!50003 SET character_set_results = @saved_cs_results */ ;
/*!50003 SET collation_connection  = @saved_col_connection */ ;
/*!50003 DROP FUNCTION IF EXISTS `ACCOUNT_GROUP@DESCRIPTION_FROM_ID` */;
/*!50003 SET @saved_cs_client      = @@character_set_client */ ;
/*!50003 SET @saved_cs_results     = @@character_set_results */ ;
/*!50003 SET @saved_col_connection = @@collation_connection */ ;
/*!50003 SET character_set_client  = latin1 */ ;
/*!50003 SET character_set_results = latin1 */ ;
/*!50003 SET collation_connection  = latin1_swedish_ci */ ;
/*!50003 SET @saved_sql_mode       = @@sql_mode */ ;
/*!50003 SET sql_mode              = '' */ ;
DELIMITER ;;
CREATE DEFINER=`root`@`localhost` FUNCTION `ACCOUNT_GROUP@DESCRIPTION_FROM_ID`(
	PARAM_ACC_GROUP_ID BIGINT
) RETURNS varchar(16000) CHARSET utf8 COLLATE utf8_unicode_ci
SF_CHECK:
BEGIN

	-- INITIALIZE
	DECLARE TEMP_DESCRIPTION VARCHAR(16000) DEFAULT '';

	
	-- GET DESCRIPTION
	-- ====================================================================
	IF `ACCOUNT_GROUP@ACC_GROUP_ID_EXISTS`(PARAM_ACC_GROUP_ID, 0) = 1 THEN

		SELECT
			`account_group`.`ACC_GROUP_DESCRIPTION`
		INTO
			TEMP_DESCRIPTION
		FROM `account_group`
		WHERE
			`account_group`.`ACC_GROUP_ID` = PARAM_ACC_GROUP_ID
		LIMIT 1;

	ELSE
		SET TEMP_DESCRIPTION = 'NULL';
	END IF;
	-- ====================================================================

	-- SQL Server requires to return value at the end of the function, even not reachable.
	return TEMP_DESCRIPTION;
END ;;
DELIMITER ;
/*!50003 SET sql_mode              = @saved_sql_mode */ ;
/*!50003 SET character_set_client  = @saved_cs_client */ ;
/*!50003 SET character_set_results = @saved_cs_results */ ;
/*!50003 SET collation_connection  = @saved_col_connection */ ;
/*!50003 DROP FUNCTION IF EXISTS `ACCOUNT_LEVEL@ACC_LEVEL_DESCRIPTION_FROM_ID` */;
/*!50003 SET @saved_cs_client      = @@character_set_client */ ;
/*!50003 SET @saved_cs_results     = @@character_set_results */ ;
/*!50003 SET @saved_col_connection = @@collation_connection */ ;
/*!50003 SET character_set_client  = latin1 */ ;
/*!50003 SET character_set_results = latin1 */ ;
/*!50003 SET collation_connection  = latin1_swedish_ci */ ;
/*!50003 SET @saved_sql_mode       = @@sql_mode */ ;
/*!50003 SET sql_mode              = '' */ ;
DELIMITER ;;
CREATE DEFINER=`root`@`localhost` FUNCTION `ACCOUNT_LEVEL@ACC_LEVEL_DESCRIPTION_FROM_ID`(
	`PARAM_ACC_LEVEL_ID` BIGINT
) RETURNS varchar(500) CHARSET utf8 COLLATE utf8_unicode_ci
SF_CHECK:
BEGIN

	DECLARE TEMP_ACC_LEVEL_DESCRIPTION VARCHAR(500) DEFAULT '';

	-- RETRIEVE OFFICE TYPE DESCRIPTION
	-- ===================================================================
	IF `ACCOUNT_LEVEL@ACC_LEVEL_ID_EXISTS`(PARAM_ACC_LEVEL_ID, 0) = 1 THEN
		SELECT
			`account_level`.`ACC_LEVEL_DESCRIPTION`
		INTO
			TEMP_ACC_LEVEL_DESCRIPTION
		FROM `account_level`
		WHERE
			`account_level`.`ACC_LEVEL_ID` = PARAM_ACC_LEVEL_ID
		LIMIT 1;
	END IF;
	-- ===================================================================


	-- SQL Server requires to return value at the end of the function, even not reachable.
	return TEMP_ACC_LEVEL_DESCRIPTION;
	
END ;;
DELIMITER ;
/*!50003 SET sql_mode              = @saved_sql_mode */ ;
/*!50003 SET character_set_client  = @saved_cs_client */ ;
/*!50003 SET character_set_results = @saved_cs_results */ ;
/*!50003 SET collation_connection  = @saved_col_connection */ ;
/*!50003 DROP FUNCTION IF EXISTS `ACCOUNT_LEVEL@ACC_LEVEL_ID_EXISTS` */;
/*!50003 SET @saved_cs_client      = @@character_set_client */ ;
/*!50003 SET @saved_cs_results     = @@character_set_results */ ;
/*!50003 SET @saved_col_connection = @@collation_connection */ ;
/*!50003 SET character_set_client  = latin1 */ ;
/*!50003 SET character_set_results = latin1 */ ;
/*!50003 SET collation_connection  = latin1_swedish_ci */ ;
/*!50003 SET @saved_sql_mode       = @@sql_mode */ ;
/*!50003 SET sql_mode              = '' */ ;
DELIMITER ;;
CREATE DEFINER=`root`@`localhost` FUNCTION `ACCOUNT_LEVEL@ACC_LEVEL_ID_EXISTS`(
	`PARAM_ACC_LEVEL_ID` BIGINT,
	`DO_NOT_RETURN_INACTIVE_RECORDS` BIT
) RETURNS tinyint(1)
SF_CHECK:
BEGIN

	-- STATUS
	-- ========================================================
	DECLARE STATUS_INACTIVE TINYINT DEFAULT 1;
	DECLARE STATUS_ACTIVE TINYINT DEFAULT 2;
	-- ========================================================

	-- CHECK IF EXISTS
	-- ========================================================
	IF
	(
		SELECT COUNT(`account_level`.`ACC_LEVEL_ID`)
		FROM `account_level`
		WHERE
			`account_level`.`ACC_LEVEL_ID` = PARAM_ACC_LEVEL_ID AND
			(
				DO_NOT_RETURN_INACTIVE_RECORDS = 0 OR
				`account_level`.`ACC_LEVEL_STATUS` = STATUS_ACTIVE
			)
		LIMIT 1
	) >= 1
	THEN
		return 1;
	ELSE
		return 0;
	END IF;
	-- ========================================================

	-- SQL Server requires to return value at the end of the function, even not reachable.
	return 0;
	
END ;;
DELIMITER ;
/*!50003 SET sql_mode              = @saved_sql_mode */ ;
/*!50003 SET character_set_client  = @saved_cs_client */ ;
/*!50003 SET character_set_results = @saved_cs_results */ ;
/*!50003 SET collation_connection  = @saved_col_connection */ ;
/*!50003 DROP FUNCTION IF EXISTS `ACCOUNT_LEVEL@ACC_LEVEL_ID_FROM_SERVER_ID` */;
/*!50003 SET @saved_cs_client      = @@character_set_client */ ;
/*!50003 SET @saved_cs_results     = @@character_set_results */ ;
/*!50003 SET @saved_col_connection = @@collation_connection */ ;
/*!50003 SET character_set_client  = latin1 */ ;
/*!50003 SET character_set_results = latin1 */ ;
/*!50003 SET collation_connection  = latin1_swedish_ci */ ;
/*!50003 SET @saved_sql_mode       = @@sql_mode */ ;
/*!50003 SET sql_mode              = '' */ ;
DELIMITER ;;
CREATE DEFINER=`root`@`localhost` FUNCTION `ACCOUNT_LEVEL@ACC_LEVEL_ID_FROM_SERVER_ID`(
	`PARAM_ACC_LEVEL_ID` BIGINT,
	`PARAM_ACC_LEVEL_SERVER_ID` BIGINT,

	`PARAM_ACC_LEVEL_DESCRIPTION` VARCHAR(1000)
) RETURNS tinyint(1)
SF_CHECK:
BEGIN

	-- 1) INITIALIZE
	-- ========================================================
	DECLARE STATUS_INACTIVE TINYINT DEFAULT 1;
	DECLARE STATUS_ACTIVE TINYINT DEFAULT 2;
	
	-- Audit Handler
	DECLARE TEMP_ERR_MESSAGE VARCHAR(500) DEFAULT '';
	DECLARE ERR BIGINT DEFAULT 0;	
	
	
	-- 2) IF BOTH DATA HAS PASSED (AND NOT EXISTS)
	-- ========================================================
	IF
		`SYSTEM_VAR@IS_NULL@BIGINT`(PARAM_ACC_LEVEL_ID, 1) = 0 AND
		`SYSTEM_VAR@IS_NULL@BIGINT`(PARAM_ACC_LEVEL_SERVER_ID, 1) = 0 AND
		(
			SELECT COUNT(`account_level`.`ACC_LEVEL_ID`)
			FROM `account_level`
			WHERE
				`account_level`.`ACC_LEVEL_ID` = PARAM_ACC_LEVEL_ID AND
				`account_level`.`ACC_LEVEL_SERVER_ID` = PARAM_ACC_LEVEL_SERVER_ID
			LIMIT 1
		) <= 0
	THEN
		SET TEMP_ERR_MESSAGE = CONCAT_WS(' ', 'Given ACCESS LEVEL ID does not exists or is inactive.', PARAM_ACC_LEVEL_ID, ':', PARAM_ACC_LEVEL_SERVER_ID);
		SET ERR = `RAISERROR`(TEMP_ERR_MESSAGE);
	END IF;

	
	-- 3) IF ALREADY VALID DATA HAS PASSED
	-- ========================================================
	IF 
		`SYSTEM_VAR@IS_NULL@BIGINT`(PARAM_ACC_LEVEL_ID, 1) = 0 OR
		`SYSTEM_VAR@IS_NULL@BIGINT`(PARAM_ACC_LEVEL_SERVER_ID, 1) = 1
	THEN
		RETURN PARAM_ACC_LEVEL_ID;
	END IF;
	
	
	-- 4) CHECK IF EXISTS
	-- ========================================================
	IF
	(
		SELECT COUNT(`account_level`.`ACC_LEVEL_ID`)
		FROM `account_level`
		WHERE
			`account_level`.`ACC_LEVEL_SERVER_ID` = PARAM_ACC_LEVEL_SERVER_ID
		LIMIT 1
	) >= 1
	THEN
		SELECT
			`account_level`.`ACC_LEVEL_ID`
		INTO
			PARAM_ACC_LEVEL_ID
		FROM `account_level`
		WHERE
			`account_level`.`ACC_LEVEL_SERVER_ID` = PARAM_ACC_LEVEL_SERVER_ID
		LIMIT 1;
		
	
	-- 5) CHECK SIMILAR RECORDS
	-- ========================================================
	ELSEIF
	(
		SELECT COUNT(`account_level`.`ACC_LEVEL_ID`)
		FROM `account_level`
		WHERE
			`account_level`.`ACC_LEVEL_DESCRIPTION` = PARAM_ACC_LEVEL_DESCRIPTION
		LIMIT 1
	) >= 1
	THEN
		SELECT
			`account_level`.`ACC_LEVEL_ID`
		INTO
			PARAM_ACC_LEVEL_ID
		FROM `account_level`
		WHERE
			`account_level`.`ACC_LEVEL_DESCRIPTION` = PARAM_ACC_LEVEL_DESCRIPTION
		LIMIT 1;	
		
	END IF;
	

	-- 6) SQL Server requires to return value at the end of the function, even not reachable.
	-- ========================================================
	return PARAM_ACC_LEVEL_ID;
	
END ;;
DELIMITER ;
/*!50003 SET sql_mode              = @saved_sql_mode */ ;
/*!50003 SET character_set_client  = @saved_cs_client */ ;
/*!50003 SET character_set_results = @saved_cs_results */ ;
/*!50003 SET collation_connection  = @saved_col_connection */ ;
/*!50003 DROP FUNCTION IF EXISTS `ACCOUNT_LEVEL@EDIT_HAS_PERMISSION` */;
/*!50003 SET @saved_cs_client      = @@character_set_client */ ;
/*!50003 SET @saved_cs_results     = @@character_set_results */ ;
/*!50003 SET @saved_col_connection = @@collation_connection */ ;
/*!50003 SET character_set_client  = latin1 */ ;
/*!50003 SET character_set_results = latin1 */ ;
/*!50003 SET collation_connection  = latin1_swedish_ci */ ;
/*!50003 SET @saved_sql_mode       = @@sql_mode */ ;
/*!50003 SET sql_mode              = '' */ ;
DELIMITER ;;
CREATE DEFINER=`root`@`localhost` FUNCTION `ACCOUNT_LEVEL@EDIT_HAS_PERMISSION`(
	PARAM_ACC_ACCESS_ACC_LEVEL_ID BIGINT,
	
	PARAM_REQUESTER_USERNAME VARCHAR(500),
	PARAM_REQUESTER_PASSWORD VARCHAR(500)
) RETURNS bit(1)
SF_CHECK:
BEGIN

	-- INITIALIZE
	-- ...........................................
	DECLARE TEMP_ACC_LEVEL_ID BIGINT DEFAULT 0;

	DECLARE TEMP_ACC_ACCESS_ID BIGINT DEFAULT 0;
	DECLARE TEMP_ACC_ACCESS_SYS_MODULE_ID BIGINT DEFAULT 0;
	DECLARE TEMP_ACC_ACCESS_SYS_AUTHORITY_ID INT DEFAULT 0;
	DECLARE TEMP_ACC_ACCESS_AUTHORITY_POINT BIGINT DEFAULT 0;

	
	-- RETRIEVE ACCESS LEVEL
	-- ...........................................
	SET TEMP_ACC_LEVEL_ID = `ACCOUNT_MEMBER@ACC_ACCOUNT_LEVEL_FROM_LOGIN`(PARAM_REQUESTER_USERNAME, PARAM_REQUESTER_PASSWORD);
	IF TEMP_ACC_LEVEL_ID <= 1 THEN
		RETURN 0;
	END IF;


	-- CANNOT EDIT OWN LEVEL
	-- ...........................................
	IF PARAM_ACC_ACCESS_ACC_LEVEL_ID = TEMP_ACC_LEVEL_ID THEN
		RETURN 0;
	END IF;

	
	-- CHECK ACCESS_RIGHTS UNDER THE LEVEL
	-- ...........................................
	WHILE
	(
		SELECT COUNT(`account_access_rights`.`ACC_ACCESS_ID`)
		FROM `account_access_rights`
		WHERE
			`account_access_rights`.`ACC_ACCESS_ACC_LEVEL_ID` = PARAM_ACC_ACCESS_ACC_LEVEL_ID AND
			`account_access_rights`.`ACC_ACCESS_ID` > TEMP_ACC_ACCESS_ID
		LIMIT 1
	) >= 1
	DO

		-- Fetch Access Rights Data
		SELECT
			`account_access_rights`.`ACC_ACCESS_ID`,
			`account_access_rights`.`ACC_ACCESS_SYS_MODULE_ID`,
			`account_access_rights`.`ACC_ACCESS_SYS_AUTHORITY_ID`,
			`account_access_rights`.`ACC_ACCESS_AUTHORITY_POINT`
		INTO
			TEMP_ACC_ACCESS_ID,
			TEMP_ACC_ACCESS_SYS_MODULE_ID,
			TEMP_ACC_ACCESS_SYS_AUTHORITY_ID,
			TEMP_ACC_ACCESS_AUTHORITY_POINT			
		FROM `account_access_rights`
		WHERE
			`account_access_rights`.`ACC_ACCESS_ACC_LEVEL_ID` = PARAM_ACC_ACCESS_ACC_LEVEL_ID AND
			`account_access_rights`.`ACC_ACCESS_ID` > TEMP_ACC_ACCESS_ID
		ORDER BY 
			`account_access_rights`.`ACC_ACCESS_ID` ASC
		LIMIT 1;


		-- Has Enough authority to assign AR for this level
		IF `ACCOUNT_ACCESS_RIGHTS@EDIT_HAS_PERMISSION`
		(
			PARAM_ACC_ACCESS_ACC_LEVEL_ID,
			TEMP_ACC_ACCESS_SYS_MODULE_ID,
			TEMP_ACC_ACCESS_SYS_AUTHORITY_ID,
			TEMP_ACC_ACCESS_AUTHORITY_POINT,
			
			PARAM_REQUESTER_USERNAME,
			PARAM_REQUESTER_PASSWORD
		) = 0 
		THEN
			RETURN 0;	
		END IF;

	END WHILE;

	
	-- Returns TRUE
	-- ...........................................
	RETURN 1;
	
END ;;
DELIMITER ;
/*!50003 SET sql_mode              = @saved_sql_mode */ ;
/*!50003 SET character_set_client  = @saved_cs_client */ ;
/*!50003 SET character_set_results = @saved_cs_results */ ;
/*!50003 SET collation_connection  = @saved_col_connection */ ;
/*!50003 DROP FUNCTION IF EXISTS `ACCOUNT_MEMBER@ACC_ACCOUNT_GROUP_FROM_LOGIN` */;
/*!50003 SET @saved_cs_client      = @@character_set_client */ ;
/*!50003 SET @saved_cs_results     = @@character_set_results */ ;
/*!50003 SET @saved_col_connection = @@collation_connection */ ;
/*!50003 SET character_set_client  = latin1 */ ;
/*!50003 SET character_set_results = latin1 */ ;
/*!50003 SET collation_connection  = latin1_swedish_ci */ ;
/*!50003 SET @saved_sql_mode       = @@sql_mode */ ;
/*!50003 SET sql_mode              = '' */ ;
DELIMITER ;;
CREATE DEFINER=`root`@`localhost` FUNCTION `ACCOUNT_MEMBER@ACC_ACCOUNT_GROUP_FROM_LOGIN`(
	`PARAM_REQUESTER_USERNAME` VARCHAR(500),
	`PARAM_REQUESTER_PASSWORD` VARCHAR(500)
) RETURNS bigint(20)
SF_CHECK:
BEGIN
	
	-- =================================================
	-- INITIALIZE
	-- =================================================
	DECLARE `PARAM_ACC_GROUP_ID` BIGINT DEFAULT 1; -- if not found, assign [Regular Users]
	DECLARE `PARAM_ACC_ACCOUNT_ID` BIGINT DEFAULT `ACCOUNT_MEMBER@ACC_ACCOUNT_ID_FROM_LOGIN`(PARAM_REQUESTER_USERNAME, PARAM_REQUESTER_PASSWORD);
	
	
	-- =================================================
	-- RETRIEVE ACCESS LEVEL
	-- =================================================
	IF
	(
		SELECT COUNT(`account_member`.`ACC_ACCOUNT_ID`)
		FROM `account_member`
		WHERE
			`account_member`.`ACC_ACCOUNT_ID` = PARAM_ACC_ACCOUNT_ID
		LIMIT 1
	) >= 1
	THEN
		-- RETRIEVE LEVEL
		SELECT
			`account_member`.`ACC_ACCOUNT_ACC_GROUP_ID`
		INTO
			PARAM_ACC_GROUP_ID
		FROM `account_member`
		WHERE
			`account_member`.`ACC_ACCOUNT_ID` = PARAM_ACC_ACCOUNT_ID
		LIMIT 1;
	END IF;

	
	-- RETURN RESULT
	RETURN PARAM_ACC_GROUP_ID;
	
END ;;
DELIMITER ;
/*!50003 SET sql_mode              = @saved_sql_mode */ ;
/*!50003 SET character_set_client  = @saved_cs_client */ ;
/*!50003 SET character_set_results = @saved_cs_results */ ;
/*!50003 SET collation_connection  = @saved_col_connection */ ;
/*!50003 DROP FUNCTION IF EXISTS `ACCOUNT_MEMBER@ACC_ACCOUNT_ID_EXISTS` */;
/*!50003 SET @saved_cs_client      = @@character_set_client */ ;
/*!50003 SET @saved_cs_results     = @@character_set_results */ ;
/*!50003 SET @saved_col_connection = @@collation_connection */ ;
/*!50003 SET character_set_client  = latin1 */ ;
/*!50003 SET character_set_results = latin1 */ ;
/*!50003 SET collation_connection  = latin1_swedish_ci */ ;
/*!50003 SET @saved_sql_mode       = @@sql_mode */ ;
/*!50003 SET sql_mode              = '' */ ;
DELIMITER ;;
CREATE DEFINER=`root`@`localhost` FUNCTION `ACCOUNT_MEMBER@ACC_ACCOUNT_ID_EXISTS`(
	`PARAM_ACC_ACCOUNT_ID` BIGINT,
	`DO_NOT_RETURN_INACTIVE_RECORDS` BIT
) RETURNS tinyint(1)
SF_CHECK:
BEGIN

	-- STATUS
	-- ========================================================
	DECLARE STATUS_INACTIVE TINYINT DEFAULT 1;
	DECLARE STATUS_ACTIVE TINYINT DEFAULT 2;
	-- ========================================================

	IF PARAM_ACC_ACCOUNT_ID <= 0 THEN
		RETURN 0;
	END IF;

	-- CHECK IF EXISTS
	-- ========================================================
	IF
	(
		SELECT COUNT(`account_member`.`ACC_ACCOUNT_ID`)
		FROM `account_member`
		WHERE
			`account_member`.`ACC_ACCOUNT_ID` = PARAM_ACC_ACCOUNT_ID AND
			(
				DO_NOT_RETURN_INACTIVE_RECORDS = 0 OR
				`account_member`.`ACC_ACCOUNT_STATUS` = STATUS_ACTIVE
			)
		LIMIT 1
	) >= 1
	THEN
		return 1;
	ELSE
		return 0;
	END IF;
	-- ========================================================


	-- SQL Server requires to return value at the end of the function, even not reachable.
	return 0;
	
END ;;
DELIMITER ;
/*!50003 SET sql_mode              = @saved_sql_mode */ ;
/*!50003 SET character_set_client  = @saved_cs_client */ ;
/*!50003 SET character_set_results = @saved_cs_results */ ;
/*!50003 SET collation_connection  = @saved_col_connection */ ;
/*!50003 DROP FUNCTION IF EXISTS `ACCOUNT_MEMBER@ACC_ACCOUNT_ID_FROM_LOGIN` */;
/*!50003 SET @saved_cs_client      = @@character_set_client */ ;
/*!50003 SET @saved_cs_results     = @@character_set_results */ ;
/*!50003 SET @saved_col_connection = @@collation_connection */ ;
/*!50003 SET character_set_client  = latin1 */ ;
/*!50003 SET character_set_results = latin1 */ ;
/*!50003 SET collation_connection  = latin1_swedish_ci */ ;
/*!50003 SET @saved_sql_mode       = @@sql_mode */ ;
/*!50003 SET sql_mode              = '' */ ;
DELIMITER ;;
CREATE DEFINER=`root`@`localhost` FUNCTION `ACCOUNT_MEMBER@ACC_ACCOUNT_ID_FROM_LOGIN`(
	`PARAM_REQUESTER_USERNAME` VARCHAR(500),
	`PARAM_REQUESTER_PASSWORD` VARCHAR(500)
) RETURNS bigint(20)
SF_CHECK:
BEGIN

	-- If not authenticated use Visitor class account
	DECLARE PARAM_ACC_ACCOUNT_ID BIGINT DEFAULT 1;
	
	-- =================================================
	-- RETRIEVE ACCESS LEVEL
	-- =================================================
	IF
	(
		SELECT COUNT(`account_member`.`ACC_ACCOUNT_USERNAME`)
		FROM `account_member`
		WHERE
			`account_member`.`ACC_ACCOUNT_USERNAME` = PARAM_REQUESTER_USERNAME AND
			BINARY `account_member`.`ACC_ACCOUNT_PASSWORD` = PARAM_REQUESTER_PASSWORD
		LIMIT 1
	) >= 1
	THEN
		-- RETRIEVE LEVEL
		SELECT
			`account_member`.`ACC_ACCOUNT_ID` INTO PARAM_ACC_ACCOUNT_ID
		FROM `account_member`
		WHERE
			`account_member`.`ACC_ACCOUNT_USERNAME` = PARAM_REQUESTER_USERNAME AND
			BINARY `account_member`.`ACC_ACCOUNT_PASSWORD` = PARAM_REQUESTER_PASSWORD
		LIMIT 1;
	END IF;

	RETURN PARAM_ACC_ACCOUNT_ID;
END ;;
DELIMITER ;
/*!50003 SET sql_mode              = @saved_sql_mode */ ;
/*!50003 SET character_set_client  = @saved_cs_client */ ;
/*!50003 SET character_set_results = @saved_cs_results */ ;
/*!50003 SET collation_connection  = @saved_col_connection */ ;
/*!50003 DROP FUNCTION IF EXISTS `ACCOUNT_MEMBER@ACC_ACCOUNT_ID_FROM_SERVER_ID` */;
/*!50003 SET @saved_cs_client      = @@character_set_client */ ;
/*!50003 SET @saved_cs_results     = @@character_set_results */ ;
/*!50003 SET @saved_col_connection = @@collation_connection */ ;
/*!50003 SET character_set_client  = latin1 */ ;
/*!50003 SET character_set_results = latin1 */ ;
/*!50003 SET collation_connection  = latin1_swedish_ci */ ;
/*!50003 SET @saved_sql_mode       = @@sql_mode */ ;
/*!50003 SET sql_mode              = '' */ ;
DELIMITER ;;
CREATE DEFINER=`root`@`localhost` FUNCTION `ACCOUNT_MEMBER@ACC_ACCOUNT_ID_FROM_SERVER_ID`(
	`PARAM_ACC_ACCOUNT_ID` BIGINT,
	`PARAM_ACC_ACCOUNT_SERVER_ID` BIGINT,

	`PARAM_ACC_ACCOUNT_FIRST_NAME` VARCHAR(1000),
	`PARAM_ACC_ACCOUNT_MIDDLE_NAME` VARCHAR(1000),
	`PARAM_ACC_ACCOUNT_LAST_NAME` VARCHAR(1000)
) RETURNS bigint(20)
SF_CHECK:
BEGIN

	-- 1) INITIALIZE
	-- ========================================================
	DECLARE STATUS_INACTIVE TINYINT DEFAULT 1;
	DECLARE STATUS_ACTIVE TINYINT DEFAULT 2;
	
	-- Audit Handler
	DECLARE TEMP_ERR_MESSAGE VARCHAR(500) DEFAULT '';
	DECLARE ERR BIGINT DEFAULT 0;	
	
	
	-- 2) IF BOTH DATA HAS PASSED (AND NOT EXISTS)
	-- ========================================================
	IF
		`SYSTEM_VAR@IS_NULL@BIGINT`(PARAM_ACC_ACCOUNT_ID, 1) = 0 AND
		`SYSTEM_VAR@IS_NULL@BIGINT`(PARAM_ACC_ACCOUNT_SERVER_ID, 1) = 0 AND
		(
			SELECT COUNT(`account_member`.`ACC_ACCOUNT_ID`)
			FROM `account_member`
			WHERE
				`account_member`.`ACC_ACCOUNT_ID` = PARAM_ACC_ACCOUNT_ID AND
				`account_member`.`ACC_ACCOUNT_SERVER_ID` = PARAM_ACC_ACCOUNT_SERVER_ID
			LIMIT 1
		) <= 0
	THEN
		SET TEMP_ERR_MESSAGE = CONCAT_WS(' ', 'Given ACCOUNT SERVER ID does not exists or is inactive.', PARAM_ACC_ACCOUNT_ID, ':', PARAM_ACC_ACCOUNT_SERVER_ID);
		SET ERR = `RAISERROR`(TEMP_ERR_MESSAGE);
	END IF;

	
	-- 3) IF ALREADY VALID DATA HAS PASSED
	-- ========================================================
	IF 
		`SYSTEM_VAR@IS_NULL@BIGINT`(PARAM_ACC_ACCOUNT_ID, 1) = 0 AND
		`SYSTEM_VAR@IS_NULL@BIGINT`(PARAM_ACC_ACCOUNT_SERVER_ID, 1) = 1
	THEN
		RETURN PARAM_ACC_ACCOUNT_ID;
	END IF;

	
	-- 4) CHECK IF EXISTS
	-- ========================================================
	IF
	(
		SELECT COUNT(`account_member`.`ACC_ACCOUNT_ID`)
		FROM `account_member`
		WHERE
			`account_member`.`ACC_ACCOUNT_SERVER_ID` = PARAM_ACC_ACCOUNT_SERVER_ID
		LIMIT 1
	) >= 1
	THEN
	
		SELECT
			`account_member`.`ACC_ACCOUNT_ID`
		INTO
			PARAM_ACC_ACCOUNT_ID
		FROM `account_member`
		WHERE
			`account_member`.`ACC_ACCOUNT_SERVER_ID` = PARAM_ACC_ACCOUNT_SERVER_ID
		LIMIT 1;
		
	
	-- 5) CHECK SIMILAR RECORDS
	-- ========================================================
	ELSEIF
	(
		SELECT COUNT(`account_member`.`ACC_ACCOUNT_ID`)
		FROM `account_member`
		WHERE
			`account_member`.`ACC_ACCOUNT_FIRST_NAME` = PARAM_ACC_ACCOUNT_FIRST_NAME AND
			`account_member`.`ACC_ACCOUNT_MIDDLE_NAME` = PARAM_ACC_ACCOUNT_MIDDLE_NAME AND
			`account_member`.`ACC_ACCOUNT_LAST_NAME` = PARAM_ACC_ACCOUNT_LAST_NAME
		LIMIT 1
	) >= 1
	THEN
		
		SELECT 
			`account_member`.`ACC_ACCOUNT_ID`
		INTO
			PARAM_ACC_ACCOUNT_ID
		FROM `account_member`
		WHERE
			`account_member`.`ACC_ACCOUNT_FIRST_NAME` = PARAM_ACC_ACCOUNT_FIRST_NAME AND
			`account_member`.`ACC_ACCOUNT_MIDDLE_NAME` = PARAM_ACC_ACCOUNT_MIDDLE_NAME AND
			`account_member`.`ACC_ACCOUNT_LAST_NAME` = PARAM_ACC_ACCOUNT_LAST_NAME
		LIMIT 1;	

	END IF;
	

	-- 6) SQL Server requires to return value at the end of the function, even not reachable.
	-- ========================================================
	return PARAM_ACC_ACCOUNT_ID;
	
END ;;
DELIMITER ;
/*!50003 SET sql_mode              = @saved_sql_mode */ ;
/*!50003 SET character_set_client  = @saved_cs_client */ ;
/*!50003 SET character_set_results = @saved_cs_results */ ;
/*!50003 SET collation_connection  = @saved_col_connection */ ;
/*!50003 DROP FUNCTION IF EXISTS `ACCOUNT_MEMBER@ACC_ACCOUNT_LEVEL_FROM_ACCOUNT_ID` */;
/*!50003 SET @saved_cs_client      = @@character_set_client */ ;
/*!50003 SET @saved_cs_results     = @@character_set_results */ ;
/*!50003 SET @saved_col_connection = @@collation_connection */ ;
/*!50003 SET character_set_client  = latin1 */ ;
/*!50003 SET character_set_results = latin1 */ ;
/*!50003 SET collation_connection  = latin1_swedish_ci */ ;
/*!50003 SET @saved_sql_mode       = @@sql_mode */ ;
/*!50003 SET sql_mode              = '' */ ;
DELIMITER ;;
CREATE DEFINER=`root`@`localhost` FUNCTION `ACCOUNT_MEMBER@ACC_ACCOUNT_LEVEL_FROM_ACCOUNT_ID`(
	`PARAM_ACC_ACCOUNT_ID` BIGINT
) RETURNS bigint(20)
SF_CHECK:
BEGIN

	DECLARE PARAM_ACC_ACCOUNT_LEVEL BIGINT DEFAULT 1;
	
	-- =================================================
	-- RETRIEVE MODULE_ID FROM MODULE_NAME
	-- =================================================
	SELECT
		`account_member`.`ACC_ACCOUNT_ACC_LEVEL_ID` 
	INTO 
		PARAM_ACC_ACCOUNT_LEVEL
	FROM 
		`account_member`
	WHERE
		`ACCOUNT_ID` = PARAM_ACC_ACCOUNT_ID
	LIMIT 1;
	
	return PARAM_ACC_ACCOUNT_LEVEL;
	
END ;;
DELIMITER ;
/*!50003 SET sql_mode              = @saved_sql_mode */ ;
/*!50003 SET character_set_client  = @saved_cs_client */ ;
/*!50003 SET character_set_results = @saved_cs_results */ ;
/*!50003 SET collation_connection  = @saved_col_connection */ ;
/*!50003 DROP FUNCTION IF EXISTS `ACCOUNT_MEMBER@ACC_ACCOUNT_LEVEL_FROM_LOGIN` */;
/*!50003 SET @saved_cs_client      = @@character_set_client */ ;
/*!50003 SET @saved_cs_results     = @@character_set_results */ ;
/*!50003 SET @saved_col_connection = @@collation_connection */ ;
/*!50003 SET character_set_client  = latin1 */ ;
/*!50003 SET character_set_results = latin1 */ ;
/*!50003 SET collation_connection  = latin1_swedish_ci */ ;
/*!50003 SET @saved_sql_mode       = @@sql_mode */ ;
/*!50003 SET sql_mode              = '' */ ;
DELIMITER ;;
CREATE DEFINER=`root`@`localhost` FUNCTION `ACCOUNT_MEMBER@ACC_ACCOUNT_LEVEL_FROM_LOGIN`(
	`PARAM_REQUESTER_USERNAME` VARCHAR(500),
	`PARAM_REQUESTER_PASSWORD` VARCHAR(500)
) RETURNS bigint(20)
SF_CHECK:
BEGIN

	DECLARE `PARAM_ACC_ACCOUNT_LEVEL` BIGINT DEFAULT 1;
	
	-- =================================================
	-- RETRIEVE ACCESS LEVEL
	-- =================================================
	IF
	(
		SELECT COUNT(`account_member`.`ACC_ACCOUNT_USERNAME`)
		FROM `account_member`
		WHERE
			`account_member`.`ACC_ACCOUNT_USERNAME` = PARAM_REQUESTER_USERNAME AND
			BINARY `account_member`.`ACC_ACCOUNT_PASSWORD` = PARAM_REQUESTER_PASSWORD
		LIMIT 1
	) >= 1
	THEN
		-- RETRIEVE LEVEL
		SELECT
			`account_member`.`ACC_ACCOUNT_ACC_LEVEL_ID` INTO PARAM_ACC_ACCOUNT_LEVEL
		FROM `account_member`
		WHERE
			`account_member`.`ACC_ACCOUNT_USERNAME` = PARAM_REQUESTER_USERNAME AND
			BINARY `account_member`.`ACC_ACCOUNT_PASSWORD` = PARAM_REQUESTER_PASSWORD
		LIMIT 1;
	END IF;

	RETURN PARAM_ACC_ACCOUNT_LEVEL;
	
END ;;
DELIMITER ;
/*!50003 SET sql_mode              = @saved_sql_mode */ ;
/*!50003 SET character_set_client  = @saved_cs_client */ ;
/*!50003 SET character_set_results = @saved_cs_results */ ;
/*!50003 SET collation_connection  = @saved_col_connection */ ;
/*!50003 DROP FUNCTION IF EXISTS `ACCOUNT_MEMBER@ACC_ACCOUNT_LEVEL_FROM_PROXY_LOGIN` */;
/*!50003 SET @saved_cs_client      = @@character_set_client */ ;
/*!50003 SET @saved_cs_results     = @@character_set_results */ ;
/*!50003 SET @saved_col_connection = @@collation_connection */ ;
/*!50003 SET character_set_client  = latin1 */ ;
/*!50003 SET character_set_results = latin1 */ ;
/*!50003 SET collation_connection  = latin1_swedish_ci */ ;
/*!50003 SET @saved_sql_mode       = @@sql_mode */ ;
/*!50003 SET sql_mode              = '' */ ;
DELIMITER ;;
CREATE DEFINER=`root`@`localhost` FUNCTION `ACCOUNT_MEMBER@ACC_ACCOUNT_LEVEL_FROM_PROXY_LOGIN`(
	PARAM_REQUESTER_PROXY_ID BIGINT,
	PARAM_REQUESTER_PROXY_PASSWORD VARCHAR(1000)
) RETURNS bigint(20)
SF_CHECK:
BEGIN

	DECLARE `PARAM_ACC_ACCOUNT_LEVEL` BIGINT DEFAULT 1;
	
	-- =================================================
	-- RETRIEVE ACCESS LEVEL
	-- =================================================
	IF
	(
		SELECT COUNT(`account_member`.`ACC_ACCOUNT_USERNAME`)
		FROM `account_member`
		WHERE
			`account_member`.`ACC_ACCOUNT_ID` = PARAM_REQUESTER_PROXY_ID AND
			BINARY `account_member`.`ACC_ACCOUNT_PASSWORD` = PARAM_REQUESTER_PROXY_PASSWORD
		LIMIT 1
	) >= 1
	THEN
		-- RETRIEVE LEVEL
		SELECT
			`account_member`.`ACC_ACCOUNT_ACC_LEVEL_ID` INTO PARAM_ACC_ACCOUNT_LEVEL
		FROM `account_member`
		WHERE
			`account_member`.`ACC_ACCOUNT_ID` = PARAM_REQUESTER_PROXY_ID AND
			BINARY `account_member`.`ACC_ACCOUNT_PASSWORD` = PARAM_REQUESTER_PROXY_PASSWORD
		LIMIT 1;
	END IF;

	RETURN PARAM_ACC_ACCOUNT_LEVEL;
	
END ;;
DELIMITER ;
/*!50003 SET sql_mode              = @saved_sql_mode */ ;
/*!50003 SET character_set_client  = @saved_cs_client */ ;
/*!50003 SET character_set_results = @saved_cs_results */ ;
/*!50003 SET collation_connection  = @saved_col_connection */ ;
/*!50003 DROP FUNCTION IF EXISTS `ACCOUNT_MEMBER@ACC_ACCOUNT_NAME_FROM_ID` */;
/*!50003 SET @saved_cs_client      = @@character_set_client */ ;
/*!50003 SET @saved_cs_results     = @@character_set_results */ ;
/*!50003 SET @saved_col_connection = @@collation_connection */ ;
/*!50003 SET character_set_client  = latin1 */ ;
/*!50003 SET character_set_results = latin1 */ ;
/*!50003 SET collation_connection  = latin1_swedish_ci */ ;
/*!50003 SET @saved_sql_mode       = @@sql_mode */ ;
/*!50003 SET sql_mode              = '' */ ;
DELIMITER ;;
CREATE DEFINER=`root`@`localhost` FUNCTION `ACCOUNT_MEMBER@ACC_ACCOUNT_NAME_FROM_ID`(
	`PARAM_ACC_ACCOUNT_ID` BIGINT
) RETURNS varchar(1500) CHARSET utf8 COLLATE utf8_unicode_ci
SF_CHECK:
BEGIN

	DECLARE PARAM_ACC_ACCOUNT_NAME VARCHAR(1500) DEFAULT '';
	
	-- RETRIEVE ACCOUNT
	-- =================================================
	IF `ACCOUNT_MEMBER@ACC_ACCOUNT_ID_EXISTS`(PARAM_ACC_ACCOUNT_ID, 0) = 1 THEN

		SELECT
			CONCAT_WS
			(
				' ', 
				`account_member`.`ACC_ACCOUNT_FIRST_NAME`,
				`account_member`.`ACC_ACCOUNT_MIDDLE_NAME`,
				`account_member`.`ACC_ACCOUNT_LAST_NAME`
			)
		INTO 
			PARAM_ACC_ACCOUNT_NAME
		FROM `account_member`
		WHERE
			`account_member`.`ACC_ACCOUNT_ID` = PARAM_ACC_ACCOUNT_ID
		LIMIT 1;
		
	END IF;
	-- =================================================
	
	RETURN PARAM_ACC_ACCOUNT_NAME;
END ;;
DELIMITER ;
/*!50003 SET sql_mode              = @saved_sql_mode */ ;
/*!50003 SET character_set_client  = @saved_cs_client */ ;
/*!50003 SET character_set_results = @saved_cs_results */ ;
/*!50003 SET collation_connection  = @saved_col_connection */ ;
/*!50003 DROP FUNCTION IF EXISTS `ACCOUNT_MEMBER@ACC_ACCOUNT_NAME_FROM_LOGIN` */;
/*!50003 SET @saved_cs_client      = @@character_set_client */ ;
/*!50003 SET @saved_cs_results     = @@character_set_results */ ;
/*!50003 SET @saved_col_connection = @@collation_connection */ ;
/*!50003 SET character_set_client  = latin1 */ ;
/*!50003 SET character_set_results = latin1 */ ;
/*!50003 SET collation_connection  = latin1_swedish_ci */ ;
/*!50003 SET @saved_sql_mode       = @@sql_mode */ ;
/*!50003 SET sql_mode              = '' */ ;
DELIMITER ;;
CREATE DEFINER=`root`@`localhost` FUNCTION `ACCOUNT_MEMBER@ACC_ACCOUNT_NAME_FROM_LOGIN`(
	`PARAM_REQUESTER_USERNAME` VARCHAR(500),
	`PARAM_REQUESTER_PASSWORD` VARCHAR(500)
) RETURNS varchar(4000) CHARSET utf8 COLLATE utf8_unicode_ci
BEGIN

	-- Initialize
	-- .........................................................
	DECLARE PARAM_ACC_ACCOUNT_ID BIGINT DEFAULT `ACCOUNT_MEMBER@ACC_ACCOUNT_ID_FROM_LOGIN`(PARAM_REQUESTER_USERNAME, PARAM_REQUESTER_PASSWORD);
	DECLARE PARAM_ACC_ACCOUNT_NAME VARCHAR(4000) DEFAULT `ACCOUNT_MEMBER@ACC_ACCOUNT_NAME_FROM_ID`(PARAM_ACC_ACCOUNT_ID);
	
	-- Return result
	-- .........................................................
	RETURN PARAM_ACC_ACCOUNT_NAME;

END ;;
DELIMITER ;
/*!50003 SET sql_mode              = @saved_sql_mode */ ;
/*!50003 SET character_set_client  = @saved_cs_client */ ;
/*!50003 SET character_set_results = @saved_cs_results */ ;
/*!50003 SET collation_connection  = @saved_col_connection */ ;
/*!50003 DROP FUNCTION IF EXISTS `ACCOUNT_MEMBER@SHORTCODE_HAS_PERMISSION` */;
/*!50003 SET @saved_cs_client      = @@character_set_client */ ;
/*!50003 SET @saved_cs_results     = @@character_set_results */ ;
/*!50003 SET @saved_col_connection = @@collation_connection */ ;
/*!50003 SET character_set_client  = latin1 */ ;
/*!50003 SET character_set_results = latin1 */ ;
/*!50003 SET collation_connection  = latin1_swedish_ci */ ;
/*!50003 SET @saved_sql_mode       = @@sql_mode */ ;
/*!50003 SET sql_mode              = '' */ ;
DELIMITER ;;
CREATE DEFINER=`root`@`localhost` FUNCTION `ACCOUNT_MEMBER@SHORTCODE_HAS_PERMISSION`(
	`PARAM_MOB_MOBILE_ID` BIGINT,
	`PARAM_MOB_MOBILE_SHORTCODE` VARCHAR(500),
	`PARAM_MOB_MOBILE_COMPANY_CODE` VARCHAR(500),
	`PARAM_REQUESTER_USERNAME` VARCHAR(500),
	`PARAM_REQUESTER_PASSWORD` VARCHAR(500)
) RETURNS tinyint(1)
SF_CHECK:
BEGIN
	
	-- =================================================
	-- INITIALIZE
	-- =================================================
	DECLARE TEMP_MOB_PARAM_MOB_MOBILE_ID BIGINT DEFAULT 0;
	DECLARE TEMP_MOB_PARAM_MOB_MOBILE_SHORTCODE VARCHAR(500) DEFAULT '29290000';
	DECLARE TEMP_MOB_MOBILE_COMAPNY_CODE VARCHAR(500) DEFAULT 'NO_COMPANY_CODE';
	DECLARE TEMP_ACC_ACCOUNT_GROUP BIGINT DEFAULT `ACCOUNT_MEMBER@ACC_ACCOUNT_GROUP_FROM_LOGIN`(PARAM_REQUESTER_USERNAME, PARAM_REQUESTER_PASSWORD);
	
	DECLARE TEMP_ERR_MESSAGE VARCHAR(500) DEFAULT '';
	DECLARE ERR BIGINT DEFAULT 0;
	
	
	-- =================================================
	-- RETRIEVE SHORTCODE / COMPANY CODE
	-- =================================================
	IF
	(
		SELECT COUNT(`mobile_shortcode`.`MOB_MOBILE_ID`)
		FROM `mobile_shortcode`
		WHERE
			`mobile_shortcode`.`MOB_MOBILE_GROUP_ID` = TEMP_ACC_ACCOUNT_GROUP
		LIMIT 1
	) >= 1
	THEN
		-- RETRIEVE LEVEL
		SELECT
			`mobile_shortcode`.`MOB_MOBILE_ID`,
			`mobile_shortcode`.`MOB_MOBILE_SHORTCODE`,
			`mobile_shortcode`.`MOB_MOBILE_COMPANY_CODE`
		INTO
			TEMP_MOB_PARAM_MOB_MOBILE_ID,
			TEMP_MOB_PARAM_MOB_MOBILE_SHORTCODE,
			TEMP_MOB_MOBILE_COMAPNY_CODE
			
		FROM `mobile_shortcode`
		WHERE
			`mobile_shortcode`.`MOB_MOBILE_GROUP_ID` = TEMP_ACC_ACCOUNT_GROUP
		LIMIT 1;
	END IF;
	
	
	-- =================================================
	-- RETURN RESULT
	-- =================================================
	IF
		`SYSTEM_VAR@IS_NULL@BIGINT`(PARAM_MOB_MOBILE_ID, 1) = 0 AND
		PARAM_MOB_MOBILE_ID = TEMP_MOB_PARAM_MOB_MOBILE_ID AND
		`SYSTEM_VAR@IS_NULL@NVARCHAR`(PARAM_MOB_MOBILE_SHORTCODE, 1) = 1 AND
		`SYSTEM_VAR@IS_NULL@NVARCHAR`(PARAM_MOB_MOBILE_COMPANY_CODE, 1) = 1
	THEN
		-- SEARCH BY ID: TRUE
		RETURN 1;
	
	
	ELSEIF 
		`SYSTEM_VAR@IS_NULL@BIGINT`(PARAM_MOB_MOBILE_ID, 1) = 1 AND
		PARAM_MOB_MOBILE_SHORTCODE = TEMP_MOB_PARAM_MOB_MOBILE_SHORTCODE AND
		(
			`SYSTEM_VAR@IS_NULL@NVARCHAR`(TEMP_MOB_MOBILE_COMAPNY_CODE, 1) = 1 OR
			PARAM_MOB_MOBILE_COMPANY_CODE = TEMP_MOB_MOBILE_COMAPNY_CODE
		)
	THEN
		-- SEARCH BY SHORTCODE / COMPANY CODE: TRUE
		RETURN 1;
		
		
	ELSEIF 
		`SYSTEM_VAR@IS_NULL@BIGINT`(PARAM_MOB_MOBILE_ID, 1) = 0 AND
		(
			`SYSTEM_VAR@IS_NULL@NVARCHAR`(PARAM_MOB_MOBILE_SHORTCODE, 1) = 0 OR
			`SYSTEM_VAR@IS_NULL@NVARCHAR`(PARAM_MOB_MOBILE_COMPANY_CODE, 1) = 0	
		)
	THEN
		-- INVALID ARGUMENT
		SET ERR = `RAISERROR`('Cannot assign ID together w/ shortcode on HAS PERMISSION check.');
		RETURN 0;
		
		
	ELSE
		-- SET TEMP_ERR_MESSAGE = CONCAT_WS(' ', 'ID:', PARAM_MOB_MOBILE_ID, ', FID:', TEMP_MOB_PARAM_MOB_MOBILE_ID, ', SHC:', PARAM_MOB_MOBILE_SHORTCODE, ', FSHC:', TEMP_MOB_PARAM_MOB_MOBILE_SHORTCODE, ', CC:', PARAM_MOB_MOBILE_COMPANY_CODE, ', TEMP_MOB_MOBILE_COMAPNY_CODE');
		-- SET ERR = `RAISERROR`(TEMP_ERR_MESSAGE);
			
		-- NONE OF THE ABOVE
		RETURN 0;

	END IF;
	
	
	-- =================================================
	-- NEED TO ADD RETURN CODE AT LAST LINE IN SOME SQL VERSION
	-- =================================================	
	RETURN 0;
	
END ;;
DELIMITER ;
/*!50003 SET sql_mode              = @saved_sql_mode */ ;
/*!50003 SET character_set_client  = @saved_cs_client */ ;
/*!50003 SET character_set_results = @saved_cs_results */ ;
/*!50003 SET collation_connection  = @saved_col_connection */ ;
/*!50003 DROP FUNCTION IF EXISTS `ACCOUNT_MEMBER@SYSTEM_PASSWORD` */;
/*!50003 SET @saved_cs_client      = @@character_set_client */ ;
/*!50003 SET @saved_cs_results     = @@character_set_results */ ;
/*!50003 SET @saved_col_connection = @@collation_connection */ ;
/*!50003 SET character_set_client  = latin1 */ ;
/*!50003 SET character_set_results = latin1 */ ;
/*!50003 SET collation_connection  = latin1_swedish_ci */ ;
/*!50003 SET @saved_sql_mode       = @@sql_mode */ ;
/*!50003 SET sql_mode              = '' */ ;
DELIMITER ;;
CREATE DEFINER=`root`@`localhost` FUNCTION `ACCOUNT_MEMBER@SYSTEM_PASSWORD`() RETURNS varchar(500) CHARSET utf8 COLLATE utf8_unicode_ci
SF_CHECK:
BEGIN

	DECLARE `PARAM_ACC_ACCOUNT_USERNAME` VARCHAR(500) DEFAULT 'system';
	DECLARE `PARAM_ACC_ACCOUNT_PASSWORD` VARCHAR(500) DEFAULT '';
	
	-- =================================================
	-- RETRIEVE ACCESS LEVEL
	-- =================================================
	IF
	(
		SELECT COUNT(`account_member`.`ACC_ACCOUNT_USERNAME`)
		FROM `account_member`
		WHERE
			`account_member`.`ACC_ACCOUNT_USERNAME` = PARAM_ACC_ACCOUNT_USERNAME
		LIMIT 1
	) >= 1
	THEN
		-- RETRIEVE USERNAME
		SELECT
			`account_member`.`ACC_ACCOUNT_PASSWORD`
		INTO
			PARAM_ACC_ACCOUNT_PASSWORD
		FROM `account_member`
		WHERE
			`account_member`.`ACC_ACCOUNT_USERNAME` = PARAM_ACC_ACCOUNT_USERNAME
		LIMIT 1;
	END IF;

	RETURN PARAM_ACC_ACCOUNT_PASSWORD;
	
END ;;
DELIMITER ;
/*!50003 SET sql_mode              = @saved_sql_mode */ ;
/*!50003 SET character_set_client  = @saved_cs_client */ ;
/*!50003 SET character_set_results = @saved_cs_results */ ;
/*!50003 SET collation_connection  = @saved_col_connection */ ;
/*!50003 DROP FUNCTION IF EXISTS `ACCOUNT_PROXY_ACCESS@ACC_PROXY_ID_EXISTS` */;
/*!50003 SET @saved_cs_client      = @@character_set_client */ ;
/*!50003 SET @saved_cs_results     = @@character_set_results */ ;
/*!50003 SET @saved_col_connection = @@collation_connection */ ;
/*!50003 SET character_set_client  = latin1 */ ;
/*!50003 SET character_set_results = latin1 */ ;
/*!50003 SET collation_connection  = latin1_swedish_ci */ ;
/*!50003 SET @saved_sql_mode       = @@sql_mode */ ;
/*!50003 SET sql_mode              = '' */ ;
DELIMITER ;;
CREATE DEFINER=`root`@`localhost` FUNCTION `ACCOUNT_PROXY_ACCESS@ACC_PROXY_ID_EXISTS`(
	PARAM_ACC_PROXY_ID BIGINT,
	DO_NOT_RETURN_INACTIVE_RECORDS BIT
) RETURNS tinyint(1)
SF_CHECK:
BEGIN

	-- STATUS
	-- ========================================================
	DECLARE STATUS_INACTIVE TINYINT DEFAULT 1;
	DECLARE STATUS_ACTIVE TINYINT DEFAULT 2;
	DECLARE STATUS_CLOSED TINYINT DEFAULT 3;
	DECLARE STATUS_COMPLETE TINYINT DEFAULT 4;
	-- ========================================================
	
	IF PARAM_ACC_PROXY_ID <= 0 THEN
		RETURN 0;
	END IF;

	-- CHECK IF EXISTS
	-- ========================================================
	IF
	(
		SELECT COUNT(`account_proxy_access`.`ACC_PROXY_ID`)
		FROM `account_proxy_access`
		WHERE
			`account_proxy_access`.`ACC_PROXY_ID` = PARAM_ACC_PROXY_ID 
			AND
			(
				DO_NOT_RETURN_INACTIVE_RECORDS = 0 OR
				`account_proxy_access`.`ACC_PROXY_STATUS` = STATUS_ACTIVE
			)
		LIMIT 1
	) >= 1
	THEN
		RETURN 1;

	ELSE 
		RETURN 0;
		
	END IF;
	-- ========================================================


	-- SQL Server requires to return value at the end of the function, even not reachable.
	RETURN 0;
	
END ;;
DELIMITER ;
/*!50003 SET sql_mode              = @saved_sql_mode */ ;
/*!50003 SET character_set_client  = @saved_cs_client */ ;
/*!50003 SET character_set_results = @saved_cs_results */ ;
/*!50003 SET collation_connection  = @saved_col_connection */ ;
/*!50003 DROP FUNCTION IF EXISTS `ACCOUNT_PROXY_ACCESS@DESCRIPTION_FROM_ID` */;
/*!50003 SET @saved_cs_client      = @@character_set_client */ ;
/*!50003 SET @saved_cs_results     = @@character_set_results */ ;
/*!50003 SET @saved_col_connection = @@collation_connection */ ;
/*!50003 SET character_set_client  = latin1 */ ;
/*!50003 SET character_set_results = latin1 */ ;
/*!50003 SET collation_connection  = latin1_swedish_ci */ ;
/*!50003 SET @saved_sql_mode       = @@sql_mode */ ;
/*!50003 SET sql_mode              = '' */ ;
DELIMITER ;;
CREATE DEFINER=`root`@`localhost` FUNCTION `ACCOUNT_PROXY_ACCESS@DESCRIPTION_FROM_ID`(
	PARAM_ACC_PROXY_ID BIGINT
) RETURNS varchar(16000) CHARSET utf8 COLLATE utf8_unicode_ci
SF_CHECK:
BEGIN

	-- INITIALIZE
	DECLARE TEMP_DESCRIPTION VARCHAR(16000) DEFAULT '';

	
	-- GET DESCRIPTION
	-- ====================================================================
	IF `ACCOUNT_PROXY_ACCESS@ACC_PROXY_ID_EXISTS`(PARAM_ACC_PROXY_ID, 0) = 1 THEN

		SELECT
			`account_proxy_access`.`ACC_PROXY_AUTH_HASH`
		INTO
			TEMP_DESCRIPTION
		FROM `account_proxy_access`
		WHERE
			`account_proxy_access`.`ACC_PROXY_ID` = PARAM_ACC_PROXY_ID
		LIMIT 1;

	ELSE
		SET TEMP_DESCRIPTION = 'NULL';
	END IF;
	-- ====================================================================

	-- SQL Server requires to return value at the end of the function, even not reachable.
	return TEMP_DESCRIPTION;
END ;;
DELIMITER ;
/*!50003 SET sql_mode              = @saved_sql_mode */ ;
/*!50003 SET character_set_client  = @saved_cs_client */ ;
/*!50003 SET character_set_results = @saved_cs_results */ ;
/*!50003 SET collation_connection  = @saved_col_connection */ ;
/*!50003 DROP FUNCTION IF EXISTS `ACCOUNT_PROXY_ACCESS@ID_FROM_DESCRIPTION` */;
/*!50003 SET @saved_cs_client      = @@character_set_client */ ;
/*!50003 SET @saved_cs_results     = @@character_set_results */ ;
/*!50003 SET @saved_col_connection = @@collation_connection */ ;
/*!50003 SET character_set_client  = latin1 */ ;
/*!50003 SET character_set_results = latin1 */ ;
/*!50003 SET collation_connection  = latin1_swedish_ci */ ;
/*!50003 SET @saved_sql_mode       = @@sql_mode */ ;
/*!50003 SET sql_mode              = '' */ ;
DELIMITER ;;
CREATE DEFINER=`root`@`localhost` FUNCTION `ACCOUNT_PROXY_ACCESS@ID_FROM_DESCRIPTION`(
	PARAM_ACC_PROXY_AUTH_HASH VARCHAR(1000)
) RETURNS bigint(20)
SF_CHECK:
BEGIN

	-- INITIALIZE
	DECLARE TEMP_ID BIGINT DEFAULT 0;

	
	-- GET DESCRIPTION
	-- ====================================================================
	IF 
		(
			SELECT COUNT(`account_proxy_access`.`ACC_PROXY_ID`)
			FROM `account_proxy_access`
			WHERE
				`account_proxy_access`.`ACC_PROXY_AUTH_HASH` = PARAM_ACC_PROXY_AUTH_HASH
			LIMIT 1
		) >= 1
	THEN

		SELECT
			`account_proxy_access`.`ACC_PROXY_ID`
		INTO
			TEMP_ID
		FROM `account_proxy_access`
		WHERE
			`account_proxy_access`.`ACC_PROXY_AUTH_HASH` = PARAM_ACC_PROXY_AUTH_HASH
		LIMIT 1;

	END IF;
	-- ====================================================================

	-- SQL Server requires to return value at the end of the function, even not reachable.
	return TEMP_ID;
END ;;
DELIMITER ;
/*!50003 SET sql_mode              = @saved_sql_mode */ ;
/*!50003 SET character_set_client  = @saved_cs_client */ ;
/*!50003 SET character_set_results = @saved_cs_results */ ;
/*!50003 SET collation_connection  = @saved_col_connection */ ;
/*!50003 DROP FUNCTION IF EXISTS `ACCOUNT_PROXY_ACCESS@IS_LEGIT` */;
/*!50003 SET @saved_cs_client      = @@character_set_client */ ;
/*!50003 SET @saved_cs_results     = @@character_set_results */ ;
/*!50003 SET @saved_col_connection = @@collation_connection */ ;
/*!50003 SET character_set_client  = latin1 */ ;
/*!50003 SET character_set_results = latin1 */ ;
/*!50003 SET collation_connection  = latin1_swedish_ci */ ;
/*!50003 SET @saved_sql_mode       = @@sql_mode */ ;
/*!50003 SET sql_mode              = '' */ ;
DELIMITER ;;
CREATE DEFINER=`root`@`localhost` FUNCTION `ACCOUNT_PROXY_ACCESS@IS_LEGIT`(
	PARAM_REQUESTER_PROXY_ID BIGINT,
	PARAM_REQUESTER_PROXY_PASSWORD VARCHAR(1000)
) RETURNS bit(1)
BEGIN

	-- Initialize
	-- _______________________________________________________________________
	
	-- Status
	-- ...........................................
	DECLARE STATUS_INACTIVE TINYINT DEFAULT 1;
	DECLARE STATUS_ACTIVE TINYINT DEFAULT 2;
	DECLARE STATUS_CLOSED TINYINT DEFAULT 3;
	DECLARE STATUS_COMPLETED TINYINT DEFAULT 4;

	-- Audit Handler
	-- ...........................................
	DECLARE TEMP_RECORD_EXISTS BIT DEFAULT 0;
	DECLARE TEMP_MODULE_KEYWORD VARCHAR(500) DEFAULT 'account_proxy_access';
	DECLARE TEMP_SP_OBJECTIVE VARCHAR(500) DEFAULT 'Retrieve Provy Auth Access record';
	DECLARE TEMP_ERR_MESSAGE VARCHAR(500) DEFAULT '';
	DECLARE ERR BIGINT DEFAULT 0;
	DECLARE TEMP_RECORD_CHANGES VARCHAR(16000) DEFAULT '';
	DECLARE TEMP_RECORD_BINDED BIT DEFAULT 0;
	
	DECLARE TEMP_RECORD_BINDED_ID BIGINT DEFAULT 0;
	DECLARE TEMP_RECORD_BINDED_SERVER_ID BIGINT DEFAULT 0;

	-- Authentication
	-- ...........................................
	DECLARE TEMP_ACCESS_RIGHTS_DENIED BIT DEFAULT 0;
	DECLARE TEMP_AUTHENTICATED_ACCOUNT_ID BIGINT DEFAULT 0;
	DECLARE TEMP_AUTHENTICATED_ACCOUNT_LEVEL BIGINT DEFAULT 0;
	DECLARE TEMP_AUTHENTICATED_ACCOUNT_GROUP BIGINT DEFAULT 0;
	
	-- Local Parameters
	-- ...........................................
	DECLARE TEMP_NOW DATETIME(6) DEFAULT `SYSTEM_VAR@NOW`('', 1);
	DECLARE TEMP_RECORD_COUNT BIGINT DEFAULT 0;
	DECLARE TEMP_ACC_PROXY_AUTH_OWNER VARCHAR(1000) DEFAULT '';
	DECLARE TEMP_ACC_PROXY_AUTH_HASH VARCHAR(1000) DEFAULT '';
		
	-- Check NULLs
	-- ...........................................
	DECLARE IS_NULL_ACC_PROXY_ID BIT DEFAULT `SYSTEM_VAR@IS_NULL@BIGINT`(PARAM_REQUESTER_PROXY_ID, 1, 1);
	DECLARE IS_NULL_ACC_PROXY_PASSWORD BIT DEFAULT `SYSTEM_VAR@IS_NULL@NVARCHAR`(PARAM_REQUESTER_PROXY_PASSWORD, 1);


	-- Error Handler
	-- _______________________________________________________________________
	-- Handled at outer block
	

	-- Access Rights [If not yet login]
	-- _______________________________________________________________________
	IF TEMP_AUTHENTICATED_ACCOUNT_ID <= 0 THEN
		-- 'Cannot request proxy when not logged-in'
		RETURN 0;
	END IF;
	
	
	-- Validate Parameters
	-- _______________________________________________________________________
	IF IS_NULL_ACC_PROXY_ID = 1 THEN
		-- 'Proxy ID is required.';
		RETURN 0;	
	END IF;
	IF IS_NULL_ACC_PROXY_PASSWORD = 1 THEN
		-- 'Proxy Password is required.';
		RETURN 0;			
	END IF;
	
	
	-- SELECT ACCOUNTS 
	-- _______________________________________________________________________
	IF
	(
		SELECT COUNT(`account_proxy_access`.`ACC_PROXY_ID`)
		FROM `account_proxy_access`
		WHERE
			`account_proxy_access`.`ACC_PROXY_ID` = PARAM_REQUESTER_PROXY_ID AND 			
			`account_proxy_access`.`ACC_PROXY_AUTH_HASH` = 	PARAM_REQUESTER_PROXY_PASSWORD AND	
			`account_proxy_access`.`ACC_PROXY_STATUS` = STATUS_ACTIVE
		LIMIT 1
	) > 0
	THEN
		RETURN 1;
	END IF;
	
	
	-- Return Result (Invalid Proxy details)
	-- _______________________________________________________________________
	RETURN 0;
		
END ;;
DELIMITER ;
/*!50003 SET sql_mode              = @saved_sql_mode */ ;
/*!50003 SET character_set_client  = @saved_cs_client */ ;
/*!50003 SET character_set_results = @saved_cs_results */ ;
/*!50003 SET collation_connection  = @saved_col_connection */ ;
/*!50003 DROP FUNCTION IF EXISTS `ACCOUNT_SERVER@ACC_SERVER_ID_EXISTS` */;
/*!50003 SET @saved_cs_client      = @@character_set_client */ ;
/*!50003 SET @saved_cs_results     = @@character_set_results */ ;
/*!50003 SET @saved_col_connection = @@collation_connection */ ;
/*!50003 SET character_set_client  = latin1 */ ;
/*!50003 SET character_set_results = latin1 */ ;
/*!50003 SET collation_connection  = latin1_swedish_ci */ ;
/*!50003 SET @saved_sql_mode       = @@sql_mode */ ;
/*!50003 SET sql_mode              = '' */ ;
DELIMITER ;;
CREATE DEFINER=`root`@`localhost` FUNCTION `ACCOUNT_SERVER@ACC_SERVER_ID_EXISTS`(
	`PARAM_ACC_SERVER_ID` BIGINT,
	`DO_NOT_RETURN_INACTIVE_RECORDS` BIT
) RETURNS tinyint(1)
SF_CHECK:
BEGIN

	-- STATUS
	-- ========================================================
	DECLARE STATUS_INACTIVE TINYINT DEFAULT 1;
	DECLARE STATUS_ACTIVE TINYINT DEFAULT 2;
	-- ========================================================

	-- CHECK IF EXISTS
	-- ========================================================
	IF
	(
		SELECT 
			COUNT(`account_server`.`ACC_SERVER_ID`)
		FROM `account_server`
		WHERE
			`account_server`.`ACC_SERVER_ID` = PARAM_ACC_SERVER_ID AND
			(
				DO_NOT_RETURN_INACTIVE_RECORDS = 0 OR
				`account_server`.`ACC_SERVER_STATUS` = STATUS_ACTIVE
			)	
		LIMIT 1
	) >= 1
	THEN
		return 1;
	ELSE
		return 0;
	END IF;
	-- ========================================================

	-- SQL Server requires to return value at the end of the function, even not reachable.
	return 0;

END ;;
DELIMITER ;
/*!50003 SET sql_mode              = @saved_sql_mode */ ;
/*!50003 SET character_set_client  = @saved_cs_client */ ;
/*!50003 SET character_set_results = @saved_cs_results */ ;
/*!50003 SET collation_connection  = @saved_col_connection */ ;
/*!50003 DROP FUNCTION IF EXISTS `ACCOUNT_SERVER@ACC_SERVER_ID_FROM_LOGIN` */;
/*!50003 SET @saved_cs_client      = @@character_set_client */ ;
/*!50003 SET @saved_cs_results     = @@character_set_results */ ;
/*!50003 SET @saved_col_connection = @@collation_connection */ ;
/*!50003 SET character_set_client  = latin1 */ ;
/*!50003 SET character_set_results = latin1 */ ;
/*!50003 SET collation_connection  = latin1_swedish_ci */ ;
/*!50003 SET @saved_sql_mode       = @@sql_mode */ ;
/*!50003 SET sql_mode              = '' */ ;
DELIMITER ;;
CREATE DEFINER=`root`@`localhost` FUNCTION `ACCOUNT_SERVER@ACC_SERVER_ID_FROM_LOGIN`(
	`PARAM_ACC_SERVER_DESCRIPTION` VARCHAR(500),
	`PARAM_ACC_SERVER_UNIQUE_KEY` VARCHAR(500)
) RETURNS bigint(20)
SF_CHECK:
BEGIN

	-- DECLARE LOCAL PARAMETERS
	-- =================================================
	DECLARE STATUS_INACTIVE TINYINT DEFAULT 1;
	DECLARE STATUS_ACTIVE TINYINT DEFAULT 2;
	
	DECLARE PARAM_ACC_SERVER_ID BIGINT DEFAULT 0;
	
	
	
	-- CHECK MODULE ACCESS RIGHTS (CHILD SERVER)
	-- =================================================	
	IF
	(
		SELECT COUNT(`account_server`.`ACC_SERVER_ID`)
		FROM `account_server`
		WHERE
			`account_server`.`ACC_SERVER_DESCRIPTION` = PARAM_ACC_SERVER_DESCRIPTION AND
			BINARY `account_server`.`ACC_SERVER_UNIQUE_KEY` = PARAM_ACC_SERVER_UNIQUE_KEY AND
			`account_server`.`ACC_SERVER_STATUS` = STATUS_ACTIVE
		LIMIT 1
	) >= 1
	THEN
	
		SELECT 
			`account_server`.`ACC_SERVER_ID`
		INTO
			PARAM_ACC_SERVER_ID
		FROM `account_server`
		WHERE
			`account_server`.`ACC_SERVER_DESCRIPTION` = PARAM_ACC_SERVER_DESCRIPTION AND
			BINARY `account_server`.`ACC_SERVER_UNIQUE_KEY` = PARAM_ACC_SERVER_UNIQUE_KEY AND
			`account_server`.`ACC_SERVER_STATUS` = STATUS_ACTIVE
		LIMIT 1;
		
	END IF;

	
	-- LEVEL IS NOT EXISTS OR DISABLED
	return PARAM_ACC_SERVER_ID;

END ;;
DELIMITER ;
/*!50003 SET sql_mode              = @saved_sql_mode */ ;
/*!50003 SET character_set_client  = @saved_cs_client */ ;
/*!50003 SET character_set_results = @saved_cs_results */ ;
/*!50003 SET collation_connection  = @saved_col_connection */ ;
/*!50003 DROP FUNCTION IF EXISTS `ACCOUNT_SERVER@ACC_SERVER_ID_FROM_SERVER_ID` */;
/*!50003 SET @saved_cs_client      = @@character_set_client */ ;
/*!50003 SET @saved_cs_results     = @@character_set_results */ ;
/*!50003 SET @saved_col_connection = @@collation_connection */ ;
/*!50003 SET character_set_client  = latin1 */ ;
/*!50003 SET character_set_results = latin1 */ ;
/*!50003 SET collation_connection  = latin1_swedish_ci */ ;
/*!50003 SET @saved_sql_mode       = @@sql_mode */ ;
/*!50003 SET sql_mode              = '' */ ;
DELIMITER ;;
CREATE DEFINER=`root`@`localhost` FUNCTION `ACCOUNT_SERVER@ACC_SERVER_ID_FROM_SERVER_ID`(
	PARAM_ACC_SERVER_ID BIGINT,
	PARAM_ACC_SERVER_SERVER_ID BIGINT,
	PARAM_ACC_SERVER_DESCRIPTION VARCHAR(500)
) RETURNS bigint(20)
SF_CHECK:
BEGIN

	-- 1) INITIALIZE
	-- .........................................................
	DECLARE STATUS_INACTIVE TINYINT DEFAULT 1;
	DECLARE STATUS_ACTIVE TINYINT DEFAULT 2;
	
	DECLARE TEMP_ERR_MESSAGE VARCHAR(500);
	DECLARE ERR BIGINT DEFAULT 0;
	
	
	-- 2) IF BOTH DATA HAS PASSED (AND NOT EXISTS)
	-- .........................................................
	IF
		`SYSTEM_VAR@IS_NULL@BIGINT`(PARAM_ACC_SERVER_ID, 1, 1) = 0 AND
		`SYSTEM_VAR@IS_NULL@BIGINT`(PARAM_ACC_SERVER_SERVER_ID, 1, 1) = 0 AND
		(
			SELECT COUNT(`account_server`.`ACC_SERVER_ID`)
			FROM `account_server`
			WHERE
				`account_server`.`ACC_SERVER_ID` = PARAM_ACC_SERVER_ID AND
				`account_server`.`ACC_SERVER_SERVER_ID` = PARAM_ACC_SERVER_SERVER_ID
			LIMIT 1
		) <= 0
	THEN
		SET TEMP_ERR_MESSAGE = CONCAT_WS(' ', 'Given SERVER SERVER ID does not exists or is inactive.', PARAM_ACC_SERVER_ID, ':', PARAM_ACC_SERVER_SERVER_ID);
		SET ERR = `RAISERROR`(TEMP_ERR_MESSAGE);
	END IF;

	
	-- 3) IF ALREADY VALID DATA HAS PASSED
	-- .........................................................
	IF 
		`SYSTEM_VAR@IS_NULL@BIGINT`(PARAM_ACC_SERVER_ID, 1, 1) = 0 AND
		`SYSTEM_VAR@IS_NULL@BIGINT`(PARAM_ACC_SERVER_SERVER_ID, 1, 1) = 1
	THEN
		RETURN PARAM_ACC_SERVER_ID;
	END IF;

	
	-- 4) CHECK IF EXISTS
	-- .........................................................
	IF
	(
		SELECT COUNT(`account_server`.`ACC_SERVER_ID`)
		FROM `account_server`
		WHERE
			`account_server`.`ACC_SERVER_SERVER_ID` = PARAM_ACC_SERVER_SERVER_ID
		LIMIT 1
	) >= 1
	THEN

		SELECT 
			`account_server`.`ACC_SERVER_ID`
		INTO
			PARAM_ACC_SERVER_ID
		FROM `account_server`
		WHERE
			`account_server`.`ACC_SERVER_SERVER_ID` = PARAM_ACC_SERVER_SERVER_ID
		LIMIT 1;

	
	-- 5) CHECK SIMILAR RECORDS
	-- .........................................................
	ELSEIF
	(
		SELECT COUNT(`account_server`.`ACC_SERVER_ID`)
		FROM `account_server`
		WHERE
			`account_server`.`ACC_SERVER_DESCRIPTION` = PARAM_ACC_SERVER_DESCRIPTION
		LIMIT 1
	) >= 1
	THEN
		
		SELECT
			`account_server`.`ACC_SERVER_ID`
		INTO
			PARAM_ACC_SERVER_ID
		FROM `account_server`
		WHERE
			`account_server`.`ACC_SERVER_DESCRIPTION` = PARAM_ACC_SERVER_DESCRIPTION
		LIMIT 1;
				
	END IF;
	

	-- 6) Return result
	-- .........................................................
	RETURN PARAM_ACC_SERVER_ID;

END ;;
DELIMITER ;
/*!50003 SET sql_mode              = @saved_sql_mode */ ;
/*!50003 SET character_set_client  = @saved_cs_client */ ;
/*!50003 SET character_set_results = @saved_cs_results */ ;
/*!50003 SET collation_connection  = @saved_col_connection */ ;
/*!50003 DROP FUNCTION IF EXISTS `ACCOUNT_SERVER@HAS_PERMISSION` */;
/*!50003 SET @saved_cs_client      = @@character_set_client */ ;
/*!50003 SET @saved_cs_results     = @@character_set_results */ ;
/*!50003 SET @saved_col_connection = @@collation_connection */ ;
/*!50003 SET character_set_client  = latin1 */ ;
/*!50003 SET character_set_results = latin1 */ ;
/*!50003 SET collation_connection  = latin1_swedish_ci */ ;
/*!50003 SET @saved_sql_mode       = @@sql_mode */ ;
/*!50003 SET sql_mode              = '' */ ;
DELIMITER ;;
CREATE DEFINER=`root`@`localhost` FUNCTION `ACCOUNT_SERVER@HAS_PERMISSION`(
	`PARAM_ACC_SERVER_DESCRIPTION` VARCHAR(500),
	`PARAM_ACC_SERVER_UNIQUE_KEY` VARCHAR(500)
) RETURNS tinyint(1)
SF_CHECK:
BEGIN

	-- DECLARE LOCAL PARAMETERS
	-- =================================================
	DECLARE STATUS_INACTIVE TINYINT DEFAULT 1;
	DECLARE STATUS_ACTIVE TINYINT DEFAULT 2;
	
	
	
	-- CHECK MODULE ACCESS RIGHTS (CHILD SERVER)
	-- =================================================	
	IF
	(
		SELECT COUNT(`account_server`.`ACC_SERVER_ID`)
		FROM `account_server`
		WHERE
			`account_server`.`ACC_SERVER_DESCRIPTION` = PARAM_ACC_SERVER_DESCRIPTION AND
			BINARY `account_server`.`ACC_SERVER_UNIQUE_KEY` = PARAM_ACC_SERVER_UNIQUE_KEY AND
			`account_server`.`ACC_SERVER_STATUS` = STATUS_ACTIVE
		LIMIT 1
	) >= 1
	THEN
		return 1;
	
	ELSE
		return 0;
	END IF;

	
	-- LEVEL IS NOT EXISTS OR DISABLED
	return 0;

END ;;
DELIMITER ;
/*!50003 SET sql_mode              = @saved_sql_mode */ ;
/*!50003 SET character_set_client  = @saved_cs_client */ ;
/*!50003 SET character_set_results = @saved_cs_results */ ;
/*!50003 SET collation_connection  = @saved_col_connection */ ;
/*!50003 DROP FUNCTION IF EXISTS `ACCOUNT_SERVER@MOTHER_ID` */;
/*!50003 SET @saved_cs_client      = @@character_set_client */ ;
/*!50003 SET @saved_cs_results     = @@character_set_results */ ;
/*!50003 SET @saved_col_connection = @@collation_connection */ ;
/*!50003 SET character_set_client  = latin1 */ ;
/*!50003 SET character_set_results = latin1 */ ;
/*!50003 SET collation_connection  = latin1_swedish_ci */ ;
/*!50003 SET @saved_sql_mode       = @@sql_mode */ ;
/*!50003 SET sql_mode              = '' */ ;
DELIMITER ;;
CREATE DEFINER=`root`@`localhost` FUNCTION `ACCOUNT_SERVER@MOTHER_ID`() RETURNS bigint(20)
SF_CHECK:
BEGIN

	-- STATUS
	-- ========================================================
	DECLARE STATUS_INACTIVE TINYINT DEFAULT 1;
	DECLARE STATUS_ACTIVE TINYINT DEFAULT 2;
	
	DECLARE TEMP_SERVER_ID BIGINT DEFAULT 0;
	-- ========================================================

	-- CHECK IF EXISTS
	-- ========================================================
	IF 
	(
		SELECT 
			COUNT(`account_server`.`ACC_SERVER_ID`)
		FROM `account_server`
		WHERE
			`account_server`.`ACC_SERVER_IS_MOTHER` <> STATUS_ACTIVE AND
			`account_server`.`ACC_SERVER_SYSTEM_GENERATED` = STATUS_ACTIVE
		LIMIT 1
	) >= 1
	THEN
		SELECT 
			`account_server`.`ACC_SERVER_ID`
		INTO
			TEMP_SERVER_ID
		FROM `account_server`
		WHERE
			`account_server`.`ACC_SERVER_IS_MOTHER` <> STATUS_ACTIVE AND
			`account_server`.`ACC_SERVER_SYSTEM_GENERATED` = STATUS_ACTIVE
		LIMIT 1;
	END IF;
	-- ========================================================

	-- SQL Server requires to return value at the end of the function, even not reachable.
	return TEMP_SERVER_ID;

END ;;
DELIMITER ;
/*!50003 SET sql_mode              = @saved_sql_mode */ ;
/*!50003 SET character_set_client  = @saved_cs_client */ ;
/*!50003 SET character_set_results = @saved_cs_results */ ;
/*!50003 SET collation_connection  = @saved_col_connection */ ;
/*!50003 DROP FUNCTION IF EXISTS `ACCOUNT_SERVER@SELF_EXISTS` */;
/*!50003 SET @saved_cs_client      = @@character_set_client */ ;
/*!50003 SET @saved_cs_results     = @@character_set_results */ ;
/*!50003 SET @saved_col_connection = @@collation_connection */ ;
/*!50003 SET character_set_client  = latin1 */ ;
/*!50003 SET character_set_results = latin1 */ ;
/*!50003 SET collation_connection  = latin1_swedish_ci */ ;
/*!50003 SET @saved_sql_mode       = @@sql_mode */ ;
/*!50003 SET sql_mode              = '' */ ;
DELIMITER ;;
CREATE DEFINER=`root`@`localhost` FUNCTION `ACCOUNT_SERVER@SELF_EXISTS`() RETURNS tinyint(1)
SF_CHECK:
BEGIN

	-- STATUS
	-- ========================================================
	DECLARE STATUS_INACTIVE TINYINT DEFAULT 1;
	DECLARE STATUS_ACTIVE TINYINT DEFAULT 2;
	-- ========================================================

	-- CHECK IF EXISTS
	-- ========================================================
	IF 
	(
		SELECT 
			COUNT(`account_server`.`ACC_SERVER_ID`)
		FROM `account_server`
		WHERE
			`account_server`.`ACC_SERVER_ADDRESS` = 'SELF' AND
			`account_server`.`ACC_SERVER_SYSTEM_GENERATED` = STATUS_ACTIVE
		LIMIT 1
	) >= 1
	THEN
		return 1;
	ELSE
		return 0;
	END IF;
	-- ========================================================

	-- SQL Server requires to return value at the end of the function, even not reachable.
	return 0;

END ;;
DELIMITER ;
/*!50003 SET sql_mode              = @saved_sql_mode */ ;
/*!50003 SET character_set_client  = @saved_cs_client */ ;
/*!50003 SET character_set_results = @saved_cs_results */ ;
/*!50003 SET collation_connection  = @saved_col_connection */ ;
/*!50003 DROP FUNCTION IF EXISTS `ACCOUNT_SERVER@SELF_ID` */;
/*!50003 SET @saved_cs_client      = @@character_set_client */ ;
/*!50003 SET @saved_cs_results     = @@character_set_results */ ;
/*!50003 SET @saved_col_connection = @@collation_connection */ ;
/*!50003 SET character_set_client  = latin1 */ ;
/*!50003 SET character_set_results = latin1 */ ;
/*!50003 SET collation_connection  = latin1_swedish_ci */ ;
/*!50003 SET @saved_sql_mode       = @@sql_mode */ ;
/*!50003 SET sql_mode              = '' */ ;
DELIMITER ;;
CREATE DEFINER=`root`@`localhost` FUNCTION `ACCOUNT_SERVER@SELF_ID`() RETURNS bigint(20)
SF_CHECK:
BEGIN

	-- STATUS
	-- ========================================================
	DECLARE STATUS_INACTIVE TINYINT DEFAULT 1;
	DECLARE STATUS_ACTIVE TINYINT DEFAULT 2;
	
	DECLARE TEMP_ACC_SERVER_ID BIGINT DEFAULT 0;
	-- ========================================================

	-- CHECK IF EXISTS
	-- ========================================================
	IF 
	(
		SELECT 
			COUNT(`account_server`.`ACC_SERVER_ID`)
		FROM `account_server`
		WHERE
			`account_server`.`ACC_SERVER_ADDRESS` = 'SELF' AND
			`account_server`.`ACC_SERVER_SYSTEM_GENERATED` = STATUS_ACTIVE
		LIMIT 1
	) >= 1
	THEN
		SELECT 
			`account_server`.`ACC_SERVER_ID`
		INTO
			TEMP_ACC_SERVER_ID
		FROM `account_server`
		WHERE
			`account_server`.`ACC_SERVER_ADDRESS` = 'SELF' AND
			`account_server`.`ACC_SERVER_SYSTEM_GENERATED` = STATUS_ACTIVE
		LIMIT 1;
	END IF;
	-- ========================================================

	-- SQL Server requires to return value at the end of the function, even not reachable.
	return TEMP_ACC_SERVER_ID;

END ;;
DELIMITER ;
/*!50003 SET sql_mode              = @saved_sql_mode */ ;
/*!50003 SET character_set_client  = @saved_cs_client */ ;
/*!50003 SET character_set_results = @saved_cs_results */ ;
/*!50003 SET collation_connection  = @saved_col_connection */ ;
/*!50003 DROP FUNCTION IF EXISTS `ADDON_LICENSE_GROUP@ADD_GLICENSE_ID_EXISTS` */;
/*!50003 SET @saved_cs_client      = @@character_set_client */ ;
/*!50003 SET @saved_cs_results     = @@character_set_results */ ;
/*!50003 SET @saved_col_connection = @@collation_connection */ ;
/*!50003 SET character_set_client  = latin1 */ ;
/*!50003 SET character_set_results = latin1 */ ;
/*!50003 SET collation_connection  = latin1_swedish_ci */ ;
/*!50003 SET @saved_sql_mode       = @@sql_mode */ ;
/*!50003 SET sql_mode              = '' */ ;
DELIMITER ;;
CREATE DEFINER=`root`@`localhost` FUNCTION `ADDON_LICENSE_GROUP@ADD_GLICENSE_ID_EXISTS`(
	PARAM_ADD_GLICENSE_ID BIGINT,
	DO_NOT_RETURN_INACTIVE_RECORDS BIT
) RETURNS tinyint(1)
SF_CHECK:
BEGIN

	-- STATUS
	-- ========================================================
	DECLARE STATUS_INACTIVE TINYINT DEFAULT 1;
	DECLARE STATUS_ACTIVE TINYINT DEFAULT 2;
	DECLARE STATUS_CLOSED TINYINT DEFAULT 3;
	DECLARE STATUS_COMPLETE TINYINT DEFAULT 4;
	-- ========================================================
	
	IF PARAM_ADD_GLICENSE_ID <= 0 THEN
		RETURN 0;
	END IF;

	-- CHECK IF EXISTS
	-- ========================================================
	IF
	(
		SELECT COUNT(`addon_license_group`.`ADD_GLICENSE_ID`)
		FROM `addon_license_group`
		WHERE
			`addon_license_group`.`ADD_GLICENSE_ID` = PARAM_ADD_GLICENSE_ID 
			AND
			(
				DO_NOT_RETURN_INACTIVE_RECORDS = 0 OR
				`addon_license_group`.`ADD_GLICENSE_STATUS` = STATUS_ACTIVE
			)
		LIMIT 1
	) >= 1
	THEN
		RETURN 1;

	ELSE 
		RETURN 0;
		
	END IF;
	-- ========================================================


	-- SQL Server requires to return value at the end of the function, even not reachable.
	RETURN 0;
	
END ;;
DELIMITER ;
/*!50003 SET sql_mode              = @saved_sql_mode */ ;
/*!50003 SET character_set_client  = @saved_cs_client */ ;
/*!50003 SET character_set_results = @saved_cs_results */ ;
/*!50003 SET collation_connection  = @saved_col_connection */ ;
/*!50003 DROP FUNCTION IF EXISTS `ADDON_LICENSE_GROUP@DESCRIPTION_FROM_ID` */;
/*!50003 SET @saved_cs_client      = @@character_set_client */ ;
/*!50003 SET @saved_cs_results     = @@character_set_results */ ;
/*!50003 SET @saved_col_connection = @@collation_connection */ ;
/*!50003 SET character_set_client  = latin1 */ ;
/*!50003 SET character_set_results = latin1 */ ;
/*!50003 SET collation_connection  = latin1_swedish_ci */ ;
/*!50003 SET @saved_sql_mode       = @@sql_mode */ ;
/*!50003 SET sql_mode              = '' */ ;
DELIMITER ;;
CREATE DEFINER=`root`@`localhost` FUNCTION `ADDON_LICENSE_GROUP@DESCRIPTION_FROM_ID`(
	PARAM_ADD_GLICENSE_ID BIGINT
) RETURNS varchar(16000) CHARSET utf8 COLLATE utf8_unicode_ci
SF_CHECK:
BEGIN

	-- INITIALIZE
	DECLARE TEMP_DESCRIPTION VARCHAR(16000) DEFAULT '';

	
	-- GET DESCRIPTION
	-- ====================================================================
	IF `ADDON_LICENSE_GROUP@ADD_GLICENSE_ID_EXISTS`(PARAM_ADD_GLICENSE_ID, 0) = 1 THEN

		SELECT
			`addon_license_group`.`ADD_GLICENSE_ACC_GROUP_ID`
		INTO
			TEMP_DESCRIPTION
		FROM `addon_license_group`
		WHERE
			`addon_license_group`.`ADD_GLICENSE_ID` = PARAM_ADD_GLICENSE_ID
		LIMIT 1;

	ELSE
		SET TEMP_DESCRIPTION = 'NULL';
	END IF;
	-- ====================================================================

	-- SQL Server requires to return value at the end of the function, even not reachable.
	return TEMP_DESCRIPTION;
END ;;
DELIMITER ;
/*!50003 SET sql_mode              = @saved_sql_mode */ ;
/*!50003 SET character_set_client  = @saved_cs_client */ ;
/*!50003 SET character_set_results = @saved_cs_results */ ;
/*!50003 SET collation_connection  = @saved_col_connection */ ;
/*!50003 DROP FUNCTION IF EXISTS `ADDON_LICENSE_GROUP@ID_FROM_ACC_GROUP_ID` */;
/*!50003 SET @saved_cs_client      = @@character_set_client */ ;
/*!50003 SET @saved_cs_results     = @@character_set_results */ ;
/*!50003 SET @saved_col_connection = @@collation_connection */ ;
/*!50003 SET character_set_client  = latin1 */ ;
/*!50003 SET character_set_results = latin1 */ ;
/*!50003 SET collation_connection  = latin1_swedish_ci */ ;
/*!50003 SET @saved_sql_mode       = @@sql_mode */ ;
/*!50003 SET sql_mode              = '' */ ;
DELIMITER ;;
CREATE DEFINER=`root`@`localhost` FUNCTION `ADDON_LICENSE_GROUP@ID_FROM_ACC_GROUP_ID`(
	PARAM_ADD_GLICENSE_ACC_GROUP_ID BIGINT
) RETURNS bigint(20)
SF_CHECK:
BEGIN

	-- INITIALIZE
	DECLARE TEMP_ID BIGINT DEFAULT 0;

	
	-- GET DESCRIPTION
	-- ====================================================================
	IF 
		(
			SELECT COUNT(`addon_license_group`.`ADD_GLICENSE_ID`)
			FROM `addon_license_group`
			WHERE
				`addon_license_group`.`ADD_GLICENSE_ACC_GROUP_ID` = PARAM_ADD_GLICENSE_ACC_GROUP_ID
			LIMIT 1
		) >= 1
	THEN

		SELECT
			`addon_license_group`.`ADD_GLICENSE_ID`
		INTO
			TEMP_ID
		FROM `addon_license_group`
		WHERE
			`addon_license_group`.`ADD_GLICENSE_ACC_GROUP_ID` = PARAM_ADD_GLICENSE_ACC_GROUP_ID
		LIMIT 1;

	END IF;
	-- ====================================================================

	-- SQL Server requires to return value at the end of the function, even not reachable.
	return TEMP_ID;
END ;;
DELIMITER ;
/*!50003 SET sql_mode              = @saved_sql_mode */ ;
/*!50003 SET character_set_client  = @saved_cs_client */ ;
/*!50003 SET character_set_results = @saved_cs_results */ ;
/*!50003 SET collation_connection  = @saved_col_connection */ ;
/*!50003 DROP FUNCTION IF EXISTS `ADDON_LICENSE_GROUP@ID_FROM_DESCRIPTION` */;
/*!50003 SET @saved_cs_client      = @@character_set_client */ ;
/*!50003 SET @saved_cs_results     = @@character_set_results */ ;
/*!50003 SET @saved_col_connection = @@collation_connection */ ;
/*!50003 SET character_set_client  = latin1 */ ;
/*!50003 SET character_set_results = latin1 */ ;
/*!50003 SET collation_connection  = latin1_swedish_ci */ ;
/*!50003 SET @saved_sql_mode       = @@sql_mode */ ;
/*!50003 SET sql_mode              = '' */ ;
DELIMITER ;;
CREATE DEFINER=`root`@`localhost` FUNCTION `ADDON_LICENSE_GROUP@ID_FROM_DESCRIPTION`(
	PARAM_ADD_GLICENSE_ACC_GROUP_ID BIGINT
) RETURNS bigint(20)
SF_CHECK:
BEGIN

	-- INITIALIZE
	DECLARE TEMP_ID BIGINT DEFAULT 0;

	
	-- GET DESCRIPTION
	-- ====================================================================
	IF 
		(
			SELECT COUNT(`addon_license_group`.`ADD_GLICENSE_ID`)
			FROM `addon_license_group`
			WHERE
				`addon_license_group`.`ADD_GLICENSE_ACC_GROUP_ID` = PARAM_ADD_GLICENSE_ACC_GROUP_ID
			LIMIT 1
		) >= 1
	THEN

		SELECT
			`addon_license_group`.`ADD_GLICENSE_ID`
		INTO
			TEMP_ID
		FROM `addon_license_group`
		WHERE
			`addon_license_group`.`ADD_GLICENSE_ACC_GROUP_ID` = PARAM_ADD_GLICENSE_ACC_GROUP_ID
		LIMIT 1;

	END IF;
	-- ====================================================================

	-- SQL Server requires to return value at the end of the function, even not reachable.
	return TEMP_ID;
END ;;
DELIMITER ;
/*!50003 SET sql_mode              = @saved_sql_mode */ ;
/*!50003 SET character_set_client  = @saved_cs_client */ ;
/*!50003 SET character_set_results = @saved_cs_results */ ;
/*!50003 SET collation_connection  = @saved_col_connection */ ;
/*!50003 DROP FUNCTION IF EXISTS `ADDON_LICENSE_GROUP@IS_LICENSED` */;
/*!50003 SET @saved_cs_client      = @@character_set_client */ ;
/*!50003 SET @saved_cs_results     = @@character_set_results */ ;
/*!50003 SET @saved_col_connection = @@collation_connection */ ;
/*!50003 SET character_set_client  = latin1 */ ;
/*!50003 SET character_set_results = latin1 */ ;
/*!50003 SET collation_connection  = latin1_swedish_ci */ ;
/*!50003 SET @saved_sql_mode       = @@sql_mode */ ;
/*!50003 SET sql_mode              = '' */ ;
DELIMITER ;;
CREATE DEFINER=`root`@`localhost` FUNCTION `ADDON_LICENSE_GROUP@IS_LICENSED`(
	PARAM_GROUP_ID BIGINT
) RETURNS bigint(20)
SF_CHECK:
BEGIN

	-- INITIALIZE
	-- ====================================================================
	DECLARE TEMP_ID BIGINT DEFAULT 0;
	DECLARE TEMP_NOW DATETIME(6) DEFAULT `SYSTEM_VAR@NOW`('', 1);

	
	-- GET DESCRIPTION
	-- ====================================================================
	IF 
		(
			SELECT COUNT(`addon_license_group`.`ADD_GLICENSE_ID`)
			FROM `addon_license_group`
			WHERE
				`addon_license_group`.`ADD_GLICENSE_ACC_GROUP_ID` = PARAM_GROUP_ID AND
				`addon_license_group`.`ADD_GLICENSE_DATE_EXPIRY` > TEMP_NOW
			LIMIT 1
		) >= 1
	THEN
		return 1;
	END IF;
	

	-- SQL Server requires to return value at the end of the function, even not reachable.
	-- ====================================================================
	return 0;
	
END ;;
DELIMITER ;
/*!50003 SET sql_mode              = @saved_sql_mode */ ;
/*!50003 SET character_set_client  = @saved_cs_client */ ;
/*!50003 SET character_set_results = @saved_cs_results */ ;
/*!50003 SET collation_connection  = @saved_col_connection */ ;
/*!50003 DROP FUNCTION IF EXISTS `ADDON_LICENSE_USER@ADD_ULICENSE_ID_EXISTS` */;
/*!50003 SET @saved_cs_client      = @@character_set_client */ ;
/*!50003 SET @saved_cs_results     = @@character_set_results */ ;
/*!50003 SET @saved_col_connection = @@collation_connection */ ;
/*!50003 SET character_set_client  = latin1 */ ;
/*!50003 SET character_set_results = latin1 */ ;
/*!50003 SET collation_connection  = latin1_swedish_ci */ ;
/*!50003 SET @saved_sql_mode       = @@sql_mode */ ;
/*!50003 SET sql_mode              = '' */ ;
DELIMITER ;;
CREATE DEFINER=`root`@`localhost` FUNCTION `ADDON_LICENSE_USER@ADD_ULICENSE_ID_EXISTS`(
	PARAM_ADD_ULICENSE_ID BIGINT,
	DO_NOT_RETURN_INACTIVE_RECORDS BIT
) RETURNS tinyint(1)
SF_CHECK:
BEGIN

	-- STATUS
	-- ========================================================
	DECLARE STATUS_INACTIVE TINYINT DEFAULT 1;
	DECLARE STATUS_ACTIVE TINYINT DEFAULT 2;
	DECLARE STATUS_CLOSED TINYINT DEFAULT 3;
	DECLARE STATUS_COMPLETE TINYINT DEFAULT 4;
	-- ========================================================
	
	IF PARAM_ADD_ULICENSE_ID <= 0 THEN
		RETURN 0;
	END IF;

	-- CHECK IF EXISTS
	-- ========================================================
	IF
	(
		SELECT COUNT(`addon_license_user`.`ADD_ULICENSE_ID`)
		FROM `addon_license_user`
		WHERE
			`addon_license_user`.`ADD_ULICENSE_ID` = PARAM_ADD_ULICENSE_ID 
			AND
			(
				DO_NOT_RETURN_INACTIVE_RECORDS = 0 OR
				`addon_license_user`.`ADD_ULICENSE_STATUS` = STATUS_ACTIVE
			)
		LIMIT 1
	) >= 1
	THEN
		RETURN 1;

	ELSE 
		RETURN 0;
		
	END IF;
	-- ========================================================


	-- SQL Server requires to return value at the end of the function, even not reachable.
	RETURN 0;
	
END ;;
DELIMITER ;
/*!50003 SET sql_mode              = @saved_sql_mode */ ;
/*!50003 SET character_set_client  = @saved_cs_client */ ;
/*!50003 SET character_set_results = @saved_cs_results */ ;
/*!50003 SET collation_connection  = @saved_col_connection */ ;
/*!50003 DROP FUNCTION IF EXISTS `ADDON_LICENSE_USER@DESCRIPTION_FROM_ID` */;
/*!50003 SET @saved_cs_client      = @@character_set_client */ ;
/*!50003 SET @saved_cs_results     = @@character_set_results */ ;
/*!50003 SET @saved_col_connection = @@collation_connection */ ;
/*!50003 SET character_set_client  = latin1 */ ;
/*!50003 SET character_set_results = latin1 */ ;
/*!50003 SET collation_connection  = latin1_swedish_ci */ ;
/*!50003 SET @saved_sql_mode       = @@sql_mode */ ;
/*!50003 SET sql_mode              = '' */ ;
DELIMITER ;;
CREATE DEFINER=`root`@`localhost` FUNCTION `ADDON_LICENSE_USER@DESCRIPTION_FROM_ID`(
	PARAM_ADD_ULICENSE_ID BIGINT
) RETURNS varchar(16000) CHARSET utf8 COLLATE utf8_unicode_ci
SF_CHECK:
BEGIN

	-- INITIALIZE
	DECLARE TEMP_DESCRIPTION VARCHAR(16000) DEFAULT '';

	
	-- GET DESCRIPTION
	-- ====================================================================
	IF `ADDON_LICENSE_USER@ADD_ULICENSE_ID_EXISTS`(PARAM_ADD_ULICENSE_ID, 0) = 1 THEN

		SELECT
			`addon_license_user`.`ADD_ULICENSE_ACC_ACCOUNT_ID`
		INTO
			TEMP_DESCRIPTION
		FROM `addon_license_user`
		WHERE
			`addon_license_user`.`ADD_ULICENSE_ID` = PARAM_ADD_ULICENSE_ID
		LIMIT 1;

	ELSE
		SET TEMP_DESCRIPTION = 'NULL';
	END IF;
	-- ====================================================================

	-- SQL Server requires to return value at the end of the function, even not reachable.
	return TEMP_DESCRIPTION;
END ;;
DELIMITER ;
/*!50003 SET sql_mode              = @saved_sql_mode */ ;
/*!50003 SET character_set_client  = @saved_cs_client */ ;
/*!50003 SET character_set_results = @saved_cs_results */ ;
/*!50003 SET collation_connection  = @saved_col_connection */ ;
/*!50003 DROP FUNCTION IF EXISTS `ADDON_LICENSE_USER@ID_FROM_ACC_ACCOUNT_ID` */;
/*!50003 SET @saved_cs_client      = @@character_set_client */ ;
/*!50003 SET @saved_cs_results     = @@character_set_results */ ;
/*!50003 SET @saved_col_connection = @@collation_connection */ ;
/*!50003 SET character_set_client  = latin1 */ ;
/*!50003 SET character_set_results = latin1 */ ;
/*!50003 SET collation_connection  = latin1_swedish_ci */ ;
/*!50003 SET @saved_sql_mode       = @@sql_mode */ ;
/*!50003 SET sql_mode              = '' */ ;
DELIMITER ;;
CREATE DEFINER=`root`@`localhost` FUNCTION `ADDON_LICENSE_USER@ID_FROM_ACC_ACCOUNT_ID`(
	PARAM_ADD_ULICENSE_ACC_ACCOUNT_ID BIGINT
) RETURNS bigint(20)
SF_CHECK:
BEGIN

	-- INITIALIZE
	DECLARE TEMP_ID BIGINT DEFAULT 0;

	
	-- GET DESCRIPTION
	-- ====================================================================
	IF 
		(
			SELECT COUNT(`addon_license_user`.`ADD_ULICENSE_ID`)
			FROM `addon_license_user`
			WHERE
				`addon_license_user`.`ADD_ULICENSE_ACC_ACCOUNT_ID` = PARAM_ADD_ULICENSE_ACC_ACCOUNT_ID
			LIMIT 1
		) >= 1
	THEN

		SELECT
			`addon_license_user`.`ADD_ULICENSE_ID`
		INTO
			TEMP_ID
		FROM `addon_license_user`
		WHERE
			`addon_license_user`.`ADD_ULICENSE_ACC_ACCOUNT_ID` = PARAM_ADD_ULICENSE_ACC_ACCOUNT_ID
		LIMIT 1;

	END IF;
	-- ====================================================================

	-- SQL Server requires to return value at the end of the function, even not reachable.
	return TEMP_ID;
END ;;
DELIMITER ;
/*!50003 SET sql_mode              = @saved_sql_mode */ ;
/*!50003 SET character_set_client  = @saved_cs_client */ ;
/*!50003 SET character_set_results = @saved_cs_results */ ;
/*!50003 SET collation_connection  = @saved_col_connection */ ;
/*!50003 DROP FUNCTION IF EXISTS `ADDON_LICENSE_USER@ID_FROM_DESCRIPTION` */;
/*!50003 SET @saved_cs_client      = @@character_set_client */ ;
/*!50003 SET @saved_cs_results     = @@character_set_results */ ;
/*!50003 SET @saved_col_connection = @@collation_connection */ ;
/*!50003 SET character_set_client  = latin1 */ ;
/*!50003 SET character_set_results = latin1 */ ;
/*!50003 SET collation_connection  = latin1_swedish_ci */ ;
/*!50003 SET @saved_sql_mode       = @@sql_mode */ ;
/*!50003 SET sql_mode              = '' */ ;
DELIMITER ;;
CREATE DEFINER=`root`@`localhost` FUNCTION `ADDON_LICENSE_USER@ID_FROM_DESCRIPTION`(
	PARAM_ADD_ULICENSE_ACC_ACCOUNT_ID BIGINT
) RETURNS bigint(20)
SF_CHECK:
BEGIN

	-- INITIALIZE
	DECLARE TEMP_ID BIGINT DEFAULT 0;

	
	-- GET DESCRIPTION
	-- ====================================================================
	IF 
		(
			SELECT COUNT(`addon_license_user`.`ADD_ULICENSE_ID`)
			FROM `addon_license_user`
			WHERE
				`addon_license_user`.`ADD_ULICENSE_ACC_ACCOUNT_ID` = PARAM_ADD_ULICENSE_ACC_ACCOUNT_ID
			LIMIT 1
		) >= 1
	THEN

		SELECT
			`addon_license_user`.`ADD_ULICENSE_ID`
		INTO
			TEMP_ID
		FROM `addon_license_user`
		WHERE
			`addon_license_user`.`ADD_ULICENSE_ACC_ACCOUNT_ID` = PARAM_ADD_ULICENSE_ACC_ACCOUNT_ID
		LIMIT 1;

	END IF;
	-- ====================================================================

	-- SQL Server requires to return value at the end of the function, even not reachable.
	return TEMP_ID;
END ;;
DELIMITER ;
/*!50003 SET sql_mode              = @saved_sql_mode */ ;
/*!50003 SET character_set_client  = @saved_cs_client */ ;
/*!50003 SET character_set_results = @saved_cs_results */ ;
/*!50003 SET collation_connection  = @saved_col_connection */ ;
/*!50003 DROP FUNCTION IF EXISTS `ADDON_LICENSE_USER@IS_LICENSED` */;
/*!50003 SET @saved_cs_client      = @@character_set_client */ ;
/*!50003 SET @saved_cs_results     = @@character_set_results */ ;
/*!50003 SET @saved_col_connection = @@collation_connection */ ;
/*!50003 SET character_set_client  = latin1 */ ;
/*!50003 SET character_set_results = latin1 */ ;
/*!50003 SET collation_connection  = latin1_swedish_ci */ ;
/*!50003 SET @saved_sql_mode       = @@sql_mode */ ;
/*!50003 SET sql_mode              = '' */ ;
DELIMITER ;;
CREATE DEFINER=`root`@`localhost` FUNCTION `ADDON_LICENSE_USER@IS_LICENSED`(
	PARAM_ACCOUNT_ID BIGINT
) RETURNS bigint(20)
SF_CHECK:
BEGIN

	-- INITIALIZE
	-- ====================================================================
	DECLARE TEMP_ID BIGINT DEFAULT 0;
	DECLARE TEMP_NOW DATETIME(6) DEFAULT `SYSTEM_VAR@NOW`('', 1);

	
	-- GET DESCRIPTION
	-- ====================================================================
	IF 
		(
			SELECT COUNT(`addon_license_user`.`ADD_ULICENSE_ID`)
			FROM `addon_license_user`
			WHERE
				`addon_license_user`.`ADD_ULICENSE_ACC_ACCOUNT_ID` = PARAM_ACCOUNT_ID AND
				`addon_license_user`.`ADD_ULICENSE_DATE_EXPIRY` > TEMP_NOW
			LIMIT 1
		) >= 1
	THEN
		return 1;
	END IF;
	

	-- SQL Server requires to return value at the end of the function, even not reachable.
	-- ====================================================================
	return 0;
	
END ;;
DELIMITER ;
/*!50003 SET sql_mode              = @saved_sql_mode */ ;
/*!50003 SET character_set_client  = @saved_cs_client */ ;
/*!50003 SET character_set_results = @saved_cs_results */ ;
/*!50003 SET collation_connection  = @saved_col_connection */ ;
/*!50003 DROP FUNCTION IF EXISTS `ADDON_QUEUING@ADD_QUEUING_ID_EXISTS` */;
/*!50003 SET @saved_cs_client      = @@character_set_client */ ;
/*!50003 SET @saved_cs_results     = @@character_set_results */ ;
/*!50003 SET @saved_col_connection = @@collation_connection */ ;
/*!50003 SET character_set_client  = latin1 */ ;
/*!50003 SET character_set_results = latin1 */ ;
/*!50003 SET collation_connection  = latin1_swedish_ci */ ;
/*!50003 SET @saved_sql_mode       = @@sql_mode */ ;
/*!50003 SET sql_mode              = '' */ ;
DELIMITER ;;
CREATE DEFINER=`root`@`localhost` FUNCTION `ADDON_QUEUING@ADD_QUEUING_ID_EXISTS`(
	PARAM_ADD_QUEUING_ID BIGINT,
	DO_NOT_RETURN_INACTIVE_RECORDS BIT
) RETURNS tinyint(1)
SF_CHECK:
BEGIN

	-- STATUS
	-- ========================================================
	DECLARE STATUS_INACTIVE TINYINT DEFAULT 1;
	DECLARE STATUS_ACTIVE TINYINT DEFAULT 2;
	DECLARE STATUS_CLOSED TINYINT DEFAULT 3;
	DECLARE STATUS_COMPLETE TINYINT DEFAULT 4;
	-- ========================================================
	
	IF PARAM_ADD_QUEUING_ID <= 0 THEN
		RETURN 0;
	END IF;

	-- CHECK IF EXISTS
	-- ========================================================
	IF
	(
		SELECT COUNT(`addon_queuing`.`ADD_QUEUING_ID`)
		FROM `addon_queuing`
		WHERE
			`addon_queuing`.`ADD_QUEUING_ID` = PARAM_ADD_QUEUING_ID 
			AND
			(
				DO_NOT_RETURN_INACTIVE_RECORDS = 0 OR
				`addon_queuing`.`ADD_QUEUING_STATUS` = STATUS_ACTIVE
			)
		LIMIT 1
	) >= 1
	THEN
		RETURN 1;

	ELSE 
		RETURN 0;
		
	END IF;
	-- ========================================================


	-- SQL Server requires to return value at the end of the function, even not reachable.
	RETURN 0;
	
END ;;
DELIMITER ;
/*!50003 SET sql_mode              = @saved_sql_mode */ ;
/*!50003 SET character_set_client  = @saved_cs_client */ ;
/*!50003 SET character_set_results = @saved_cs_results */ ;
/*!50003 SET collation_connection  = @saved_col_connection */ ;
/*!50003 DROP FUNCTION IF EXISTS `ADDON_QUEUING@DESCRIPTION_FROM_ID` */;
/*!50003 SET @saved_cs_client      = @@character_set_client */ ;
/*!50003 SET @saved_cs_results     = @@character_set_results */ ;
/*!50003 SET @saved_col_connection = @@collation_connection */ ;
/*!50003 SET character_set_client  = latin1 */ ;
/*!50003 SET character_set_results = latin1 */ ;
/*!50003 SET collation_connection  = latin1_swedish_ci */ ;
/*!50003 SET @saved_sql_mode       = @@sql_mode */ ;
/*!50003 SET sql_mode              = '' */ ;
DELIMITER ;;
CREATE DEFINER=`root`@`localhost` FUNCTION `ADDON_QUEUING@DESCRIPTION_FROM_ID`(
	PARAM_ADD_QUEUING_ID BIGINT
) RETURNS varchar(16000) CHARSET utf8 COLLATE utf8_unicode_ci
SF_CHECK:
BEGIN

	-- INITIALIZE
	DECLARE TEMP_DESCRIPTION VARCHAR(16000) DEFAULT '';

	
	-- GET DESCRIPTION
	-- ====================================================================
	IF `ADDON_QUEUING@ADD_QUEUING_ID_EXISTS`(PARAM_ADD_QUEUING_ID, 0) = 1 THEN

		SELECT
			`addon_queuing`.`ADD_QUEUING_STATION`
		INTO
			TEMP_DESCRIPTION
		FROM `addon_queuing`
		WHERE
			`addon_queuing`.`ADD_QUEUING_ID` = PARAM_ADD_QUEUING_ID
		LIMIT 1;

	ELSE
		SET TEMP_DESCRIPTION = 'NULL';
	END IF;
	-- ====================================================================

	-- SQL Server requires to return value at the end of the function, even not reachable.
	return TEMP_DESCRIPTION;
END ;;
DELIMITER ;
/*!50003 SET sql_mode              = @saved_sql_mode */ ;
/*!50003 SET character_set_client  = @saved_cs_client */ ;
/*!50003 SET character_set_results = @saved_cs_results */ ;
/*!50003 SET collation_connection  = @saved_col_connection */ ;
/*!50003 DROP FUNCTION IF EXISTS `ADDON_QUEUING@ID_FROM_DESCRIPTION` */;
/*!50003 SET @saved_cs_client      = @@character_set_client */ ;
/*!50003 SET @saved_cs_results     = @@character_set_results */ ;
/*!50003 SET @saved_col_connection = @@collation_connection */ ;
/*!50003 SET character_set_client  = latin1 */ ;
/*!50003 SET character_set_results = latin1 */ ;
/*!50003 SET collation_connection  = latin1_swedish_ci */ ;
/*!50003 SET @saved_sql_mode       = @@sql_mode */ ;
/*!50003 SET sql_mode              = '' */ ;
DELIMITER ;;
CREATE DEFINER=`root`@`localhost` FUNCTION `ADDON_QUEUING@ID_FROM_DESCRIPTION`(
	PARAM_ADD_QUEUING_STATION VARCHAR(500)
) RETURNS bigint(20)
SF_CHECK:
BEGIN

	-- INITIALIZE
	DECLARE TEMP_ID BIGINT DEFAULT 0;

	
	-- GET DESCRIPTION
	-- ====================================================================
	IF 
		(
			SELECT COUNT(`addon_queuing`.`ADD_QUEUING_ID`)
			FROM `addon_queuing`
			WHERE
				`addon_queuing`.`ADD_QUEUING_STATION` = PARAM_ADD_QUEUING_STATION
			LIMIT 1
		) >= 1
	THEN

		SELECT
			`addon_queuing`.`ADD_QUEUING_ID`
		INTO
			TEMP_ID
		FROM `addon_queuing`
		WHERE
			`addon_queuing`.`ADD_QUEUING_STATION` = PARAM_ADD_QUEUING_STATION
		LIMIT 1;

	END IF;
	-- ====================================================================

	-- SQL Server requires to return value at the end of the function, even not reachable.
	return TEMP_ID;
END ;;
DELIMITER ;
/*!50003 SET sql_mode              = @saved_sql_mode */ ;
/*!50003 SET character_set_client  = @saved_cs_client */ ;
/*!50003 SET character_set_results = @saved_cs_results */ ;
/*!50003 SET collation_connection  = @saved_col_connection */ ;
/*!50003 DROP FUNCTION IF EXISTS `ADDON_RESOURCE@ADD_RESOURCE_ID_EXISTS` */;
/*!50003 SET @saved_cs_client      = @@character_set_client */ ;
/*!50003 SET @saved_cs_results     = @@character_set_results */ ;
/*!50003 SET @saved_col_connection = @@collation_connection */ ;
/*!50003 SET character_set_client  = latin1 */ ;
/*!50003 SET character_set_results = latin1 */ ;
/*!50003 SET collation_connection  = latin1_swedish_ci */ ;
/*!50003 SET @saved_sql_mode       = @@sql_mode */ ;
/*!50003 SET sql_mode              = '' */ ;
DELIMITER ;;
CREATE DEFINER=`root`@`localhost` FUNCTION `ADDON_RESOURCE@ADD_RESOURCE_ID_EXISTS`(
	PARAM_ADD_RESOURCE_ID BIGINT,
	DO_NOT_RETURN_INACTIVE_RECORDS BIT
) RETURNS tinyint(1)
SF_CHECK:
BEGIN

	-- STATUS
	-- ========================================================
	DECLARE STATUS_INACTIVE TINYINT DEFAULT 1;
	DECLARE STATUS_ACTIVE TINYINT DEFAULT 2;
	DECLARE STATUS_CLOSED TINYINT DEFAULT 3;
	DECLARE STATUS_COMPLETE TINYINT DEFAULT 4;
	-- ========================================================
	
	IF PARAM_ADD_RESOURCE_ID <= 0 THEN
		RETURN 0;
	END IF;

	-- CHECK IF EXISTS
	-- ========================================================
	IF
	(
		SELECT COUNT(`addon_resource`.`ADD_RESOURCE_ID`)
		FROM `addon_resource`
		WHERE
			`addon_resource`.`ADD_RESOURCE_ID` = PARAM_ADD_RESOURCE_ID 
			AND
			(
				DO_NOT_RETURN_INACTIVE_RECORDS = 0 OR
				`addon_resource`.`ADD_RESOURCE_STATUS` = STATUS_ACTIVE
			)
		LIMIT 1
	) >= 1
	THEN
		RETURN 1;

	ELSE 
		RETURN 0;
		
	END IF;
	-- ========================================================


	-- SQL Server requires to return value at the end of the function, even not reachable.
	RETURN 0;
	
END ;;
DELIMITER ;
/*!50003 SET sql_mode              = @saved_sql_mode */ ;
/*!50003 SET character_set_client  = @saved_cs_client */ ;
/*!50003 SET character_set_results = @saved_cs_results */ ;
/*!50003 SET collation_connection  = @saved_col_connection */ ;
/*!50003 DROP FUNCTION IF EXISTS `ADDON_RESOURCE@DESCRIPTION_FROM_ID` */;
/*!50003 SET @saved_cs_client      = @@character_set_client */ ;
/*!50003 SET @saved_cs_results     = @@character_set_results */ ;
/*!50003 SET @saved_col_connection = @@collation_connection */ ;
/*!50003 SET character_set_client  = latin1 */ ;
/*!50003 SET character_set_results = latin1 */ ;
/*!50003 SET collation_connection  = latin1_swedish_ci */ ;
/*!50003 SET @saved_sql_mode       = @@sql_mode */ ;
/*!50003 SET sql_mode              = '' */ ;
DELIMITER ;;
CREATE DEFINER=`root`@`localhost` FUNCTION `ADDON_RESOURCE@DESCRIPTION_FROM_ID`(
	PARAM_ADD_RESOURCE_ID BIGINT
) RETURNS varchar(16000) CHARSET utf8 COLLATE utf8_unicode_ci
SF_CHECK:
BEGIN

	-- INITIALIZE
	DECLARE TEMP_DESCRIPTION VARCHAR(16000) DEFAULT '';

	
	-- GET DESCRIPTION
	-- ====================================================================
	IF `ADDON_RESOURCE@ADD_RESOURCE_ID_EXISTS`(PARAM_ADD_RESOURCE_ID, 0) = 1 THEN

		SELECT
			`addon_resource`.`ADD_RESOURCE_GROUP_KEY`
		INTO
			TEMP_DESCRIPTION
		FROM `addon_resource`
		WHERE
			`addon_resource`.`ADD_RESOURCE_ID` = PARAM_ADD_RESOURCE_ID
		LIMIT 1;

	ELSE
		SET TEMP_DESCRIPTION = 'NULL';
	END IF;
	-- ====================================================================

	-- SQL Server requires to return value at the end of the function, even not reachable.
	return TEMP_DESCRIPTION;
END ;;
DELIMITER ;
/*!50003 SET sql_mode              = @saved_sql_mode */ ;
/*!50003 SET character_set_client  = @saved_cs_client */ ;
/*!50003 SET character_set_results = @saved_cs_results */ ;
/*!50003 SET collation_connection  = @saved_col_connection */ ;
/*!50003 DROP FUNCTION IF EXISTS `ADDON_RESOURCE@ID_FROM_DESCRIPTION` */;
/*!50003 SET @saved_cs_client      = @@character_set_client */ ;
/*!50003 SET @saved_cs_results     = @@character_set_results */ ;
/*!50003 SET @saved_col_connection = @@collation_connection */ ;
/*!50003 SET character_set_client  = latin1 */ ;
/*!50003 SET character_set_results = latin1 */ ;
/*!50003 SET collation_connection  = latin1_swedish_ci */ ;
/*!50003 SET @saved_sql_mode       = @@sql_mode */ ;
/*!50003 SET sql_mode              = '' */ ;
DELIMITER ;;
CREATE DEFINER=`root`@`localhost` FUNCTION `ADDON_RESOURCE@ID_FROM_DESCRIPTION`(
	PARAM_ADD_RESOURCE_GROUP_KEY VARCHAR(400)
) RETURNS bigint(20)
SF_CHECK:
BEGIN

	-- INITIALIZE
	DECLARE TEMP_ID BIGINT DEFAULT 0;

	
	-- GET DESCRIPTION
	-- ====================================================================
	IF 
		(
			SELECT COUNT(`addon_resource`.`ADD_RESOURCE_ID`)
			FROM `addon_resource`
			WHERE
				`addon_resource`.`ADD_RESOURCE_GROUP_KEY` = PARAM_ADD_RESOURCE_GROUP_KEY
			LIMIT 1
		) >= 1
	THEN

		SELECT
			`addon_resource`.`ADD_RESOURCE_ID`
		INTO
			TEMP_ID
		FROM `addon_resource`
		WHERE
			`addon_resource`.`ADD_RESOURCE_GROUP_KEY` = PARAM_ADD_RESOURCE_GROUP_KEY
		LIMIT 1;

	END IF;
	-- ====================================================================

	-- SQL Server requires to return value at the end of the function, even not reachable.
	return TEMP_ID;
END ;;
DELIMITER ;
/*!50003 SET sql_mode              = @saved_sql_mode */ ;
/*!50003 SET character_set_client  = @saved_cs_client */ ;
/*!50003 SET character_set_results = @saved_cs_results */ ;
/*!50003 SET collation_connection  = @saved_col_connection */ ;
/*!50003 DROP FUNCTION IF EXISTS `CATEGORY_ADDRESS_BARANGAY@CAT_BARANGAY_ID_EXISTS` */;
/*!50003 SET @saved_cs_client      = @@character_set_client */ ;
/*!50003 SET @saved_cs_results     = @@character_set_results */ ;
/*!50003 SET @saved_col_connection = @@collation_connection */ ;
/*!50003 SET character_set_client  = latin1 */ ;
/*!50003 SET character_set_results = latin1 */ ;
/*!50003 SET collation_connection  = latin1_swedish_ci */ ;
/*!50003 SET @saved_sql_mode       = @@sql_mode */ ;
/*!50003 SET sql_mode              = '' */ ;
DELIMITER ;;
CREATE DEFINER=`root`@`localhost` FUNCTION `CATEGORY_ADDRESS_BARANGAY@CAT_BARANGAY_ID_EXISTS`(
	PARAM_CAT_BARANGAY_ID BIGINT,
	DO_NOT_RETURN_INACTIVE_RECORDS BIT
) RETURNS tinyint(1)
SF_CHECK:
BEGIN

	-- STATUS
	-- ========================================================
	DECLARE STATUS_INACTIVE TINYINT DEFAULT 1;
	DECLARE STATUS_ACTIVE TINYINT DEFAULT 2;
	DECLARE STATUS_CLOSED TINYINT DEFAULT 3;
	DECLARE STATUS_COMPLETE TINYINT DEFAULT 4;
	-- ========================================================
	
	IF PARAM_CAT_BARANGAY_ID <= 0 THEN
		RETURN 0;
	END IF;

	-- CHECK IF EXISTS
	-- ========================================================
	IF
	(
		SELECT COUNT(`category_address_barangay`.`CAT_BARANGAY_ID`)
		FROM `category_address_barangay`
		WHERE
			`category_address_barangay`.`CAT_BARANGAY_ID` = PARAM_CAT_BARANGAY_ID 
			AND
			(
				DO_NOT_RETURN_INACTIVE_RECORDS = 0 OR
				`category_address_barangay`.`CAT_BARANGAY_STATUS` = STATUS_ACTIVE
			)
		LIMIT 1
	) >= 1
	THEN
		RETURN 1;

	ELSE 
		RETURN 0;
		
	END IF;
	-- ========================================================


	-- SQL Server requires to return value at the end of the function, even not reachable.
	RETURN 0;
	
END ;;
DELIMITER ;
/*!50003 SET sql_mode              = @saved_sql_mode */ ;
/*!50003 SET character_set_client  = @saved_cs_client */ ;
/*!50003 SET character_set_results = @saved_cs_results */ ;
/*!50003 SET collation_connection  = @saved_col_connection */ ;
/*!50003 DROP FUNCTION IF EXISTS `CATEGORY_ADDRESS_BARANGAY@DESCRIPTION_FROM_ID` */;
/*!50003 SET @saved_cs_client      = @@character_set_client */ ;
/*!50003 SET @saved_cs_results     = @@character_set_results */ ;
/*!50003 SET @saved_col_connection = @@collation_connection */ ;
/*!50003 SET character_set_client  = latin1 */ ;
/*!50003 SET character_set_results = latin1 */ ;
/*!50003 SET collation_connection  = latin1_swedish_ci */ ;
/*!50003 SET @saved_sql_mode       = @@sql_mode */ ;
/*!50003 SET sql_mode              = '' */ ;
DELIMITER ;;
CREATE DEFINER=`root`@`localhost` FUNCTION `CATEGORY_ADDRESS_BARANGAY@DESCRIPTION_FROM_ID`(
	PARAM_CAT_BARANGAY_ID BIGINT
) RETURNS varchar(16000) CHARSET utf8 COLLATE utf8_unicode_ci
SF_CHECK:
BEGIN

	-- INITIALIZE
	DECLARE TEMP_DESCRIPTION VARCHAR(16000) DEFAULT '';

	
	-- GET DESCRIPTION
	-- ====================================================================
	IF `CATEGORY_ADDRESS_BARANGAY@CAT_BARANGAY_ID_EXISTS`(PARAM_CAT_BARANGAY_ID, 0) = 1 THEN

		SELECT
			`category_address_barangay`.`CAT_BARANGAY_DESCRIPTION`
		INTO
			TEMP_DESCRIPTION
		FROM `category_address_barangay`
		WHERE
			`category_address_barangay`.`CAT_BARANGAY_ID` = PARAM_CAT_BARANGAY_ID
		LIMIT 1;

	ELSE
		SET TEMP_DESCRIPTION = 'NULL';
	END IF;
	-- ====================================================================

	-- SQL Server requires to return value at the end of the function, even not reachable.
	return TEMP_DESCRIPTION;
END ;;
DELIMITER ;
/*!50003 SET sql_mode              = @saved_sql_mode */ ;
/*!50003 SET character_set_client  = @saved_cs_client */ ;
/*!50003 SET character_set_results = @saved_cs_results */ ;
/*!50003 SET collation_connection  = @saved_col_connection */ ;
/*!50003 DROP FUNCTION IF EXISTS `CATEGORY_ADDRESS_COUNTRY@CAT_COUNTRY_ID_EXISTS` */;
/*!50003 SET @saved_cs_client      = @@character_set_client */ ;
/*!50003 SET @saved_cs_results     = @@character_set_results */ ;
/*!50003 SET @saved_col_connection = @@collation_connection */ ;
/*!50003 SET character_set_client  = latin1 */ ;
/*!50003 SET character_set_results = latin1 */ ;
/*!50003 SET collation_connection  = latin1_swedish_ci */ ;
/*!50003 SET @saved_sql_mode       = @@sql_mode */ ;
/*!50003 SET sql_mode              = '' */ ;
DELIMITER ;;
CREATE DEFINER=`root`@`localhost` FUNCTION `CATEGORY_ADDRESS_COUNTRY@CAT_COUNTRY_ID_EXISTS`(
	PARAM_CAT_COUNTRY_ID BIGINT,
	DO_NOT_RETURN_INACTIVE_RECORDS BIT
) RETURNS tinyint(1)
SF_CHECK:
BEGIN

	-- STATUS
	-- ========================================================
	DECLARE STATUS_INACTIVE TINYINT DEFAULT 1;
	DECLARE STATUS_ACTIVE TINYINT DEFAULT 2;
	-- ========================================================
	
	IF PARAM_CAT_COUNTRY_ID <= 0 THEN
		RETURN 0;
	END IF;

	-- CHECK IF EXISTS
	-- ========================================================
	IF
	(
		SELECT COUNT(`category_address_country`.`CAT_COUNTRY_ID`)
		FROM `category_address_country`
		WHERE
			`category_address_country`.`CAT_COUNTRY_ID` = PARAM_CAT_COUNTRY_ID 
			AND
			(
				DO_NOT_RETURN_INACTIVE_RECORDS = 0 OR
				`category_address_country`.`CAT_COUNTRY_STATUS` = STATUS_ACTIVE
			)
		LIMIT 1
	) >= 1
	THEN
		RETURN 1;

	ELSE 
		RETURN 0;
		
	END IF;
	-- ========================================================


	-- SQL Server requires to return value at the end of the function, even not reachable.
	RETURN 0;
	
END ;;
DELIMITER ;
/*!50003 SET sql_mode              = @saved_sql_mode */ ;
/*!50003 SET character_set_client  = @saved_cs_client */ ;
/*!50003 SET character_set_results = @saved_cs_results */ ;
/*!50003 SET collation_connection  = @saved_col_connection */ ;
/*!50003 DROP FUNCTION IF EXISTS `CATEGORY_ADDRESS_COUNTRY@DESCRIPTION_FROM_ID` */;
/*!50003 SET @saved_cs_client      = @@character_set_client */ ;
/*!50003 SET @saved_cs_results     = @@character_set_results */ ;
/*!50003 SET @saved_col_connection = @@collation_connection */ ;
/*!50003 SET character_set_client  = latin1 */ ;
/*!50003 SET character_set_results = latin1 */ ;
/*!50003 SET collation_connection  = latin1_swedish_ci */ ;
/*!50003 SET @saved_sql_mode       = @@sql_mode */ ;
/*!50003 SET sql_mode              = '' */ ;
DELIMITER ;;
CREATE DEFINER=`root`@`localhost` FUNCTION `CATEGORY_ADDRESS_COUNTRY@DESCRIPTION_FROM_ID`(
	PARAM_CAT_COUNTRY_ID BIGINT
) RETURNS varchar(16000) CHARSET utf8 COLLATE utf8_unicode_ci
SF_CHECK:
BEGIN

	-- INITIALIZE
	DECLARE TEMP_DESCRIPTION VARCHAR(16000) DEFAULT '';

	
	-- GET DESCRIPTION
	-- ====================================================================
	IF `CATEGORY_ADDRESS_COUNTRY@CAT_COUNTRY_ID_EXISTS`(PARAM_CAT_COUNTRY_ID, 0) = 1 THEN

		SELECT
			`category_address_country`.`CAT_COUNTRY_DESCRIPTION`
		INTO
			TEMP_DESCRIPTION
		FROM `category_address_country`
		WHERE
			`category_address_country`.`CAT_COUNTRY_ID` = PARAM_CAT_COUNTRY_ID
		LIMIT 1;

	ELSE
		SET TEMP_DESCRIPTION = 'NULL';
	END IF;
	-- ====================================================================

	-- SQL Server requires to return value at the end of the function, even not reachable.
	return TEMP_DESCRIPTION;
END ;;
DELIMITER ;
/*!50003 SET sql_mode              = @saved_sql_mode */ ;
/*!50003 SET character_set_client  = @saved_cs_client */ ;
/*!50003 SET character_set_results = @saved_cs_results */ ;
/*!50003 SET collation_connection  = @saved_col_connection */ ;
/*!50003 DROP FUNCTION IF EXISTS `CATEGORY_ADDRESS_MUNICIPALITY@CAT_MUNICIPALITY_ID_EXISTS` */;
/*!50003 SET @saved_cs_client      = @@character_set_client */ ;
/*!50003 SET @saved_cs_results     = @@character_set_results */ ;
/*!50003 SET @saved_col_connection = @@collation_connection */ ;
/*!50003 SET character_set_client  = latin1 */ ;
/*!50003 SET character_set_results = latin1 */ ;
/*!50003 SET collation_connection  = latin1_swedish_ci */ ;
/*!50003 SET @saved_sql_mode       = @@sql_mode */ ;
/*!50003 SET sql_mode              = '' */ ;
DELIMITER ;;
CREATE DEFINER=`root`@`localhost` FUNCTION `CATEGORY_ADDRESS_MUNICIPALITY@CAT_MUNICIPALITY_ID_EXISTS`(
	PARAM_CAT_MUNICIPALITY_ID BIGINT,
	DO_NOT_RETURN_INACTIVE_RECORDS BIT
) RETURNS tinyint(1)
SF_CHECK:
BEGIN

	-- STATUS
	-- ========================================================
	DECLARE STATUS_INACTIVE TINYINT DEFAULT 1;
	DECLARE STATUS_ACTIVE TINYINT DEFAULT 2;
	-- ========================================================
	
	IF PARAM_CAT_MUNICIPALITY_ID <= 0 THEN
		RETURN 0;
	END IF;

	-- CHECK IF EXISTS
	-- ========================================================
	IF
	(
		SELECT COUNT(`category_address_municipality`.`CAT_MUNICIPALITY_ID`)
		FROM `category_address_municipality`
		WHERE
			`category_address_municipality`.`CAT_MUNICIPALITY_ID` = PARAM_CAT_MUNICIPALITY_ID 
			AND
			(
				DO_NOT_RETURN_INACTIVE_RECORDS = 0 OR
				`category_address_municipality`.`CAT_MUNICIPALITY_STATUS` = STATUS_ACTIVE
			)
		LIMIT 1
	) >= 1
	THEN
		RETURN 1;

	ELSE 
		RETURN 0;
		
	END IF;
	-- ========================================================


	-- SQL Server requires to return value at the end of the function, even not reachable.
	RETURN 0;
	
END ;;
DELIMITER ;
/*!50003 SET sql_mode              = @saved_sql_mode */ ;
/*!50003 SET character_set_client  = @saved_cs_client */ ;
/*!50003 SET character_set_results = @saved_cs_results */ ;
/*!50003 SET collation_connection  = @saved_col_connection */ ;
/*!50003 DROP FUNCTION IF EXISTS `CATEGORY_ADDRESS_MUNICIPALITY@DESCRIPTION_FROM_ID` */;
/*!50003 SET @saved_cs_client      = @@character_set_client */ ;
/*!50003 SET @saved_cs_results     = @@character_set_results */ ;
/*!50003 SET @saved_col_connection = @@collation_connection */ ;
/*!50003 SET character_set_client  = latin1 */ ;
/*!50003 SET character_set_results = latin1 */ ;
/*!50003 SET collation_connection  = latin1_swedish_ci */ ;
/*!50003 SET @saved_sql_mode       = @@sql_mode */ ;
/*!50003 SET sql_mode              = '' */ ;
DELIMITER ;;
CREATE DEFINER=`root`@`localhost` FUNCTION `CATEGORY_ADDRESS_MUNICIPALITY@DESCRIPTION_FROM_ID`(
	PARAM_CAT_MUNICIPALITY_ID BIGINT
) RETURNS varchar(16000) CHARSET utf8 COLLATE utf8_unicode_ci
SF_CHECK:
BEGIN

	-- INITIALIZE
	DECLARE TEMP_DESCRIPTION VARCHAR(16000) DEFAULT '';

	
	-- GET DESCRIPTION
	-- ====================================================================
	IF `CATEGORY_ADDRESS_MUNICIPALITY@CAT_MUNICIPALITY_ID_EXISTS`(PARAM_CAT_MUNICIPALITY_ID, 0) = 1 THEN

		SELECT
			`category_address_municipality`.`CAT_MUNICIPALITY_DESCRIPTION`
		INTO
			TEMP_DESCRIPTION
		FROM `category_address_municipality`
		WHERE
			`category_address_municipality`.`CAT_MUNICIPALITY_ID` = PARAM_CAT_MUNICIPALITY_ID
		LIMIT 1;

	ELSE
		SET TEMP_DESCRIPTION = 'NULL';
	END IF;
	-- ====================================================================

	-- SQL Server requires to return value at the end of the function, even not reachable.
	return TEMP_DESCRIPTION;
END ;;
DELIMITER ;
/*!50003 SET sql_mode              = @saved_sql_mode */ ;
/*!50003 SET character_set_client  = @saved_cs_client */ ;
/*!50003 SET character_set_results = @saved_cs_results */ ;
/*!50003 SET collation_connection  = @saved_col_connection */ ;
/*!50003 DROP FUNCTION IF EXISTS `CATEGORY_ADDRESS_PROVINCE@CAT_PROVINCE_ID_EXISTS` */;
/*!50003 SET @saved_cs_client      = @@character_set_client */ ;
/*!50003 SET @saved_cs_results     = @@character_set_results */ ;
/*!50003 SET @saved_col_connection = @@collation_connection */ ;
/*!50003 SET character_set_client  = latin1 */ ;
/*!50003 SET character_set_results = latin1 */ ;
/*!50003 SET collation_connection  = latin1_swedish_ci */ ;
/*!50003 SET @saved_sql_mode       = @@sql_mode */ ;
/*!50003 SET sql_mode              = '' */ ;
DELIMITER ;;
CREATE DEFINER=`root`@`localhost` FUNCTION `CATEGORY_ADDRESS_PROVINCE@CAT_PROVINCE_ID_EXISTS`(
	PARAM_CAT_PROVINCE_ID BIGINT,
	DO_NOT_RETURN_INACTIVE_RECORDS BIT
) RETURNS tinyint(1)
SF_CHECK:
BEGIN

	-- STATUS
	-- ========================================================
	DECLARE STATUS_INACTIVE TINYINT DEFAULT 1;
	DECLARE STATUS_ACTIVE TINYINT DEFAULT 2;
	-- ========================================================
	
	IF PARAM_CAT_PROVINCE_ID <= 0 THEN
		RETURN 0;
	END IF;

	-- CHECK IF EXISTS
	-- ========================================================
	IF
	(
		SELECT COUNT(`category_address_province`.`CAT_PROVINCE_ID`)
		FROM `category_address_province`
		WHERE
			`category_address_province`.`CAT_PROVINCE_ID` = PARAM_CAT_PROVINCE_ID 
			AND
			(
				DO_NOT_RETURN_INACTIVE_RECORDS = 0 OR
				`category_address_province`.`CAT_PROVINCE_STATUS` = STATUS_ACTIVE
			)
		LIMIT 1
	) >= 1
	THEN
		RETURN 1;

	ELSE 
		RETURN 0;
		
	END IF;
	-- ========================================================


	-- SQL Server requires to return value at the end of the function, even not reachable.
	RETURN 0;
	
END ;;
DELIMITER ;
/*!50003 SET sql_mode              = @saved_sql_mode */ ;
/*!50003 SET character_set_client  = @saved_cs_client */ ;
/*!50003 SET character_set_results = @saved_cs_results */ ;
/*!50003 SET collation_connection  = @saved_col_connection */ ;
/*!50003 DROP FUNCTION IF EXISTS `CATEGORY_ADDRESS_PROVINCE@DESCRIPTION_FROM_ID` */;
/*!50003 SET @saved_cs_client      = @@character_set_client */ ;
/*!50003 SET @saved_cs_results     = @@character_set_results */ ;
/*!50003 SET @saved_col_connection = @@collation_connection */ ;
/*!50003 SET character_set_client  = latin1 */ ;
/*!50003 SET character_set_results = latin1 */ ;
/*!50003 SET collation_connection  = latin1_swedish_ci */ ;
/*!50003 SET @saved_sql_mode       = @@sql_mode */ ;
/*!50003 SET sql_mode              = '' */ ;
DELIMITER ;;
CREATE DEFINER=`root`@`localhost` FUNCTION `CATEGORY_ADDRESS_PROVINCE@DESCRIPTION_FROM_ID`(
	PARAM_CAT_PROVINCE_ID BIGINT
) RETURNS varchar(16000) CHARSET utf8 COLLATE utf8_unicode_ci
SF_CHECK:
BEGIN

	-- INITIALIZE
	DECLARE TEMP_DESCRIPTION VARCHAR(16000) DEFAULT '';

	
	-- GET DESCRIPTION
	-- ====================================================================
	IF `CATEGORY_ADDRESS_PROVINCE@CAT_PROVINCE_ID_EXISTS`(PARAM_CAT_PROVINCE_ID, 0) = 1 THEN

		SELECT
			`category_address_province`.`CAT_PROVINCE_DESCRIPTION`
		INTO
			TEMP_DESCRIPTION
		FROM `category_address_province`
		WHERE
			`category_address_province`.`CAT_PROVINCE_ID` = PARAM_CAT_PROVINCE_ID
		LIMIT 1;

	ELSE
		SET TEMP_DESCRIPTION = 'NULL';
	END IF;
	-- ====================================================================

	-- SQL Server requires to return value at the end of the function, even not reachable.
	return TEMP_DESCRIPTION;
END ;;
DELIMITER ;
/*!50003 SET sql_mode              = @saved_sql_mode */ ;
/*!50003 SET character_set_client  = @saved_cs_client */ ;
/*!50003 SET character_set_results = @saved_cs_results */ ;
/*!50003 SET collation_connection  = @saved_col_connection */ ;
/*!50003 DROP FUNCTION IF EXISTS `CATEGORY_ADDRESS_REGION@CAT_REGION_ID_EXISTS` */;
/*!50003 SET @saved_cs_client      = @@character_set_client */ ;
/*!50003 SET @saved_cs_results     = @@character_set_results */ ;
/*!50003 SET @saved_col_connection = @@collation_connection */ ;
/*!50003 SET character_set_client  = latin1 */ ;
/*!50003 SET character_set_results = latin1 */ ;
/*!50003 SET collation_connection  = latin1_swedish_ci */ ;
/*!50003 SET @saved_sql_mode       = @@sql_mode */ ;
/*!50003 SET sql_mode              = '' */ ;
DELIMITER ;;
CREATE DEFINER=`root`@`localhost` FUNCTION `CATEGORY_ADDRESS_REGION@CAT_REGION_ID_EXISTS`(
	PARAM_CAT_REGION_ID BIGINT,
	DO_NOT_RETURN_INACTIVE_RECORDS BIT
) RETURNS tinyint(1)
SF_CHECK:
BEGIN

	-- STATUS
	-- ========================================================
	DECLARE STATUS_INACTIVE TINYINT DEFAULT 1;
	DECLARE STATUS_ACTIVE TINYINT DEFAULT 2;
	-- ========================================================
	
	IF PARAM_CAT_REGION_ID <= 0 THEN
		RETURN 0;
	END IF;

	-- CHECK IF EXISTS
	-- ========================================================
	IF
	(
		SELECT COUNT(`category_address_region`.`CAT_REGION_ID`)
		FROM `category_address_region`
		WHERE
			`category_address_region`.`CAT_REGION_ID` = PARAM_CAT_REGION_ID 
			AND
			(
				DO_NOT_RETURN_INACTIVE_RECORDS = 0 OR
				`category_address_region`.`CAT_REGION_STATUS` = STATUS_ACTIVE
			)
		LIMIT 1
	) >= 1
	THEN
		RETURN 1;

	ELSE 
		RETURN 0;
		
	END IF;
	-- ========================================================


	-- SQL Server requires to return value at the end of the function, even not reachable.
	RETURN 0;
	
END ;;
DELIMITER ;
/*!50003 SET sql_mode              = @saved_sql_mode */ ;
/*!50003 SET character_set_client  = @saved_cs_client */ ;
/*!50003 SET character_set_results = @saved_cs_results */ ;
/*!50003 SET collation_connection  = @saved_col_connection */ ;
/*!50003 DROP FUNCTION IF EXISTS `CATEGORY_ADDRESS_REGION@DESCRIPTION_FROM_ID` */;
/*!50003 SET @saved_cs_client      = @@character_set_client */ ;
/*!50003 SET @saved_cs_results     = @@character_set_results */ ;
/*!50003 SET @saved_col_connection = @@collation_connection */ ;
/*!50003 SET character_set_client  = latin1 */ ;
/*!50003 SET character_set_results = latin1 */ ;
/*!50003 SET collation_connection  = latin1_swedish_ci */ ;
/*!50003 SET @saved_sql_mode       = @@sql_mode */ ;
/*!50003 SET sql_mode              = '' */ ;
DELIMITER ;;
CREATE DEFINER=`root`@`localhost` FUNCTION `CATEGORY_ADDRESS_REGION@DESCRIPTION_FROM_ID`(
	PARAM_CAT_REGION_ID BIGINT
) RETURNS varchar(16000) CHARSET utf8 COLLATE utf8_unicode_ci
SF_CHECK:
BEGIN

	-- INITIALIZE
	DECLARE TEMP_DESCRIPTION VARCHAR(16000) DEFAULT '';

	
	-- GET DESCRIPTION
	-- ====================================================================
	IF `CATEGORY_ADDRESS_REGION@CAT_REGION_ID_EXISTS`(PARAM_CAT_REGION_ID, 0) = 1 THEN

		SELECT
			`category_address_region`.`CAT_REGION_DESCRIPTION`
		INTO
			TEMP_DESCRIPTION
		FROM `category_address_region`
		WHERE
			`category_address_region`.`CAT_REGION_ID` = PARAM_CAT_REGION_ID
		LIMIT 1;

	ELSE
		SET TEMP_DESCRIPTION = 'NULL';
	END IF;
	-- ====================================================================

	-- SQL Server requires to return value at the end of the function, even not reachable.
	return TEMP_DESCRIPTION;
END ;;
DELIMITER ;
/*!50003 SET sql_mode              = @saved_sql_mode */ ;
/*!50003 SET character_set_client  = @saved_cs_client */ ;
/*!50003 SET character_set_results = @saved_cs_results */ ;
/*!50003 SET collation_connection  = @saved_col_connection */ ;
/*!50003 DROP FUNCTION IF EXISTS `CATEGORY_DEPARTMENT@CAT_DEPARTMENT_ID_EXISTS` */;
/*!50003 SET @saved_cs_client      = @@character_set_client */ ;
/*!50003 SET @saved_cs_results     = @@character_set_results */ ;
/*!50003 SET @saved_col_connection = @@collation_connection */ ;
/*!50003 SET character_set_client  = latin1 */ ;
/*!50003 SET character_set_results = latin1 */ ;
/*!50003 SET collation_connection  = latin1_swedish_ci */ ;
/*!50003 SET @saved_sql_mode       = @@sql_mode */ ;
/*!50003 SET sql_mode              = '' */ ;
DELIMITER ;;
CREATE DEFINER=`root`@`localhost` FUNCTION `CATEGORY_DEPARTMENT@CAT_DEPARTMENT_ID_EXISTS`(
	PARAM_CAT_DEPARTMENT_ID BIGINT,
	DO_NOT_RETURN_INACTIVE_RECORDS BIT
) RETURNS tinyint(1)
SF_CHECK:
BEGIN

	-- STATUS
	-- ========================================================
	DECLARE STATUS_INACTIVE TINYINT DEFAULT 1;
	DECLARE STATUS_ACTIVE TINYINT DEFAULT 2;
	DECLARE STATUS_CLOSED TINYINT DEFAULT 3;
	DECLARE STATUS_COMPLETE TINYINT DEFAULT 4;
	-- ========================================================
	
	IF PARAM_CAT_DEPARTMENT_ID <= 0 THEN
		RETURN 0;
	END IF;

	-- CHECK IF EXISTS
	-- ========================================================
	IF
	(
		SELECT COUNT(`category_department`.`CAT_DEPARTMENT_ID`)
		FROM `category_department`
		WHERE
			`category_department`.`CAT_DEPARTMENT_ID` = PARAM_CAT_DEPARTMENT_ID 
			AND
			(
				DO_NOT_RETURN_INACTIVE_RECORDS = 0 OR
				`category_department`.`CAT_DEPARTMENT_STATUS` = STATUS_ACTIVE OR
				`category_department`.`CAT_DEPARTMENT_STATUS` = STATUS_COMPLETE
			)
		LIMIT 1
	) >= 1
	THEN
		RETURN 1;

	ELSE 
		RETURN 0;
		
	END IF;
	-- ========================================================


	-- SQL Server requires to return value at the end of the function, even not reachable.
	RETURN 0;
	
END ;;
DELIMITER ;
/*!50003 SET sql_mode              = @saved_sql_mode */ ;
/*!50003 SET character_set_client  = @saved_cs_client */ ;
/*!50003 SET character_set_results = @saved_cs_results */ ;
/*!50003 SET collation_connection  = @saved_col_connection */ ;
/*!50003 DROP FUNCTION IF EXISTS `CATEGORY_DEPARTMENT@DESCRIPTION_FROM_ID` */;
/*!50003 SET @saved_cs_client      = @@character_set_client */ ;
/*!50003 SET @saved_cs_results     = @@character_set_results */ ;
/*!50003 SET @saved_col_connection = @@collation_connection */ ;
/*!50003 SET character_set_client  = latin1 */ ;
/*!50003 SET character_set_results = latin1 */ ;
/*!50003 SET collation_connection  = latin1_swedish_ci */ ;
/*!50003 SET @saved_sql_mode       = @@sql_mode */ ;
/*!50003 SET sql_mode              = '' */ ;
DELIMITER ;;
CREATE DEFINER=`root`@`localhost` FUNCTION `CATEGORY_DEPARTMENT@DESCRIPTION_FROM_ID`(
	PARAM_CAT_DEPARTMENT_ID BIGINT
) RETURNS varchar(16000) CHARSET utf8 COLLATE utf8_unicode_ci
SF_CHECK:
BEGIN

	-- INITIALIZE
	DECLARE TEMP_DESCRIPTION VARCHAR(16000) DEFAULT '';

	
	-- GET DESCRIPTION
	-- ====================================================================
	IF `CATEGORY_DEPARTMENT@CAT_DEPARTMENT_ID_EXISTS`(PARAM_CAT_DEPARTMENT_ID, 0) = 1 THEN

		SELECT
			`category_department`.`CAT_DEPARTMENT_DESCRIPTION`
		INTO
			TEMP_DESCRIPTION
		FROM `category_department`
		WHERE
			`category_department`.`CAT_DEPARTMENT_ID` = PARAM_CAT_DEPARTMENT_ID
		LIMIT 1;

	ELSE
		SET TEMP_DESCRIPTION = 'NULL';
	END IF;
	-- ====================================================================

	-- SQL Server requires to return value at the end of the function, even not reachable.
	return TEMP_DESCRIPTION;
END ;;
DELIMITER ;
/*!50003 SET sql_mode              = @saved_sql_mode */ ;
/*!50003 SET character_set_client  = @saved_cs_client */ ;
/*!50003 SET character_set_results = @saved_cs_results */ ;
/*!50003 SET collation_connection  = @saved_col_connection */ ;
/*!50003 DROP FUNCTION IF EXISTS `CATEGORY_DEPARTMENT@ID_FROM_DESCRIPTION` */;
/*!50003 SET @saved_cs_client      = @@character_set_client */ ;
/*!50003 SET @saved_cs_results     = @@character_set_results */ ;
/*!50003 SET @saved_col_connection = @@collation_connection */ ;
/*!50003 SET character_set_client  = latin1 */ ;
/*!50003 SET character_set_results = latin1 */ ;
/*!50003 SET collation_connection  = latin1_swedish_ci */ ;
/*!50003 SET @saved_sql_mode       = @@sql_mode */ ;
/*!50003 SET sql_mode              = '' */ ;
DELIMITER ;;
CREATE DEFINER=`root`@`localhost` FUNCTION `CATEGORY_DEPARTMENT@ID_FROM_DESCRIPTION`(
	PARAM_CAT_DEPARTMENT_DESCRIPTION VARCHAR(400)
) RETURNS bigint(20)
SF_CHECK:
BEGIN

	-- INITIALIZE
	DECLARE TEMP_ID BIGINT DEFAULT 0;

	
	-- GET DESCRIPTION
	-- ====================================================================
	IF 
		(
			SELECT COUNT(`category_department`.`CAT_DEPARTMENT_ID`)
			FROM `category_department`
			WHERE
				`category_department`.`CAT_DEPARTMENT_DESCRIPTION` = PARAM_CAT_DEPARTMENT_DESCRIPTION
			LIMIT 1
		) >= 1
	THEN

		SELECT
			`category_department`.`CAT_DEPARTMENT_ID`
		INTO
			TEMP_ID
		FROM `category_department`
		WHERE
			`category_department`.`CAT_DEPARTMENT_DESCRIPTION` = PARAM_CAT_DEPARTMENT_DESCRIPTION
		LIMIT 1;

	END IF;
	-- ====================================================================

	-- SQL Server requires to return value at the end of the function, even not reachable.
	return TEMP_ID;
END ;;
DELIMITER ;
/*!50003 SET sql_mode              = @saved_sql_mode */ ;
/*!50003 SET character_set_client  = @saved_cs_client */ ;
/*!50003 SET character_set_results = @saved_cs_results */ ;
/*!50003 SET collation_connection  = @saved_col_connection */ ;
/*!50003 DROP FUNCTION IF EXISTS `CATEGORY_ENTRANCE@CAT_ENTRANCE_ID_EXISTS` */;
/*!50003 SET @saved_cs_client      = @@character_set_client */ ;
/*!50003 SET @saved_cs_results     = @@character_set_results */ ;
/*!50003 SET @saved_col_connection = @@collation_connection */ ;
/*!50003 SET character_set_client  = latin1 */ ;
/*!50003 SET character_set_results = latin1 */ ;
/*!50003 SET collation_connection  = latin1_swedish_ci */ ;
/*!50003 SET @saved_sql_mode       = @@sql_mode */ ;
/*!50003 SET sql_mode              = '' */ ;
DELIMITER ;;
CREATE DEFINER=`root`@`localhost` FUNCTION `CATEGORY_ENTRANCE@CAT_ENTRANCE_ID_EXISTS`(
	PARAM_CAT_ENTRANCE_ID BIGINT,
	DO_NOT_RETURN_INACTIVE_RECORDS BIT
) RETURNS tinyint(1)
SF_CHECK:
BEGIN

	-- STATUS
	-- ========================================================
	DECLARE STATUS_INACTIVE TINYINT DEFAULT 1;
	DECLARE STATUS_ACTIVE TINYINT DEFAULT 2;
	DECLARE STATUS_CLOSED TINYINT DEFAULT 3;
	DECLARE STATUS_COMPLETE TINYINT DEFAULT 4;
	-- ========================================================
	
	IF PARAM_CAT_ENTRANCE_ID <= 0 THEN
		RETURN 0;
	END IF;

	-- CHECK IF EXISTS
	-- ========================================================
	IF
	(
		SELECT COUNT(`category_entrance`.`CAT_ENTRANCE_ID`)
		FROM `category_entrance`
		WHERE
			`category_entrance`.`CAT_ENTRANCE_ID` = PARAM_CAT_ENTRANCE_ID 
			AND
			(
				DO_NOT_RETURN_INACTIVE_RECORDS = 0 OR
				`category_entrance`.`CAT_ENTRANCE_STATUS` = STATUS_ACTIVE OR
				`category_entrance`.`CAT_ENTRANCE_STATUS` = STATUS_COMPLETE
			)
		LIMIT 1
	) >= 1
	THEN
		RETURN 1;

	ELSE 
		RETURN 0;
		
	END IF;
	-- ========================================================


	-- SQL Server requires to return value at the end of the function, even not reachable.
	RETURN 0;
	
END ;;
DELIMITER ;
/*!50003 SET sql_mode              = @saved_sql_mode */ ;
/*!50003 SET character_set_client  = @saved_cs_client */ ;
/*!50003 SET character_set_results = @saved_cs_results */ ;
/*!50003 SET collation_connection  = @saved_col_connection */ ;
/*!50003 DROP FUNCTION IF EXISTS `CATEGORY_ENTRANCE@DESCRIPTION_FROM_ID` */;
/*!50003 SET @saved_cs_client      = @@character_set_client */ ;
/*!50003 SET @saved_cs_results     = @@character_set_results */ ;
/*!50003 SET @saved_col_connection = @@collation_connection */ ;
/*!50003 SET character_set_client  = latin1 */ ;
/*!50003 SET character_set_results = latin1 */ ;
/*!50003 SET collation_connection  = latin1_swedish_ci */ ;
/*!50003 SET @saved_sql_mode       = @@sql_mode */ ;
/*!50003 SET sql_mode              = '' */ ;
DELIMITER ;;
CREATE DEFINER=`root`@`localhost` FUNCTION `CATEGORY_ENTRANCE@DESCRIPTION_FROM_ID`(
	PARAM_CAT_ENTRANCE_ID BIGINT
) RETURNS varchar(16000) CHARSET utf8 COLLATE utf8_unicode_ci
SF_CHECK:
BEGIN

	-- INITIALIZE
	DECLARE TEMP_DESCRIPTION VARCHAR(16000) DEFAULT '';

	
	-- GET DESCRIPTION
	-- ====================================================================
	IF `CATEGORY_ENTRANCE@CAT_ENTRANCE_ID_EXISTS`(PARAM_CAT_ENTRANCE_ID, 0) = 1 THEN

		SELECT
			`category_entrance`.`CAT_ENTRANCE_DESCRIPTION`
		INTO
			TEMP_DESCRIPTION
		FROM `category_entrance`
		WHERE
			`category_entrance`.`CAT_ENTRANCE_ID` = PARAM_CAT_ENTRANCE_ID
		LIMIT 1;

	ELSE
		SET TEMP_DESCRIPTION = 'NULL';
	END IF;
	-- ====================================================================

	-- SQL Server requires to return value at the end of the function, even not reachable.
	return TEMP_DESCRIPTION;
END ;;
DELIMITER ;
/*!50003 SET sql_mode              = @saved_sql_mode */ ;
/*!50003 SET character_set_client  = @saved_cs_client */ ;
/*!50003 SET character_set_results = @saved_cs_results */ ;
/*!50003 SET collation_connection  = @saved_col_connection */ ;
/*!50003 DROP FUNCTION IF EXISTS `CATEGORY_ENTRANCE@ID_FROM_DESCRIPTION` */;
/*!50003 SET @saved_cs_client      = @@character_set_client */ ;
/*!50003 SET @saved_cs_results     = @@character_set_results */ ;
/*!50003 SET @saved_col_connection = @@collation_connection */ ;
/*!50003 SET character_set_client  = latin1 */ ;
/*!50003 SET character_set_results = latin1 */ ;
/*!50003 SET collation_connection  = latin1_swedish_ci */ ;
/*!50003 SET @saved_sql_mode       = @@sql_mode */ ;
/*!50003 SET sql_mode              = '' */ ;
DELIMITER ;;
CREATE DEFINER=`root`@`localhost` FUNCTION `CATEGORY_ENTRANCE@ID_FROM_DESCRIPTION`(
	PARAM_CAT_ENTRANCE_DESCRIPTION VARCHAR(400)
) RETURNS bigint(20)
SF_CHECK:
BEGIN

	-- INITIALIZE
	DECLARE TEMP_ID BIGINT DEFAULT 0;

	
	-- GET DESCRIPTION
	-- ====================================================================
	IF 
		(
			SELECT COUNT(`category_entrance`.`CAT_ENTRANCE_ID`)
			FROM `category_entrance`
			WHERE
				`category_entrance`.`CAT_ENTRANCE_DESCRIPTION` = PARAM_CAT_ENTRANCE_DESCRIPTION
			LIMIT 1
		) >= 1
	THEN

		SELECT
			`category_entrance`.`CAT_ENTRANCE_ID`
		INTO
			TEMP_ID
		FROM `category_entrance`
		WHERE
			`category_entrance`.`CAT_ENTRANCE_DESCRIPTION` = PARAM_CAT_ENTRANCE_DESCRIPTION
		LIMIT 1;

	END IF;
	-- ====================================================================

	-- SQL Server requires to return value at the end of the function, even not reachable.
	return TEMP_ID;
END ;;
DELIMITER ;
/*!50003 SET sql_mode              = @saved_sql_mode */ ;
/*!50003 SET character_set_client  = @saved_cs_client */ ;
/*!50003 SET character_set_results = @saved_cs_results */ ;
/*!50003 SET collation_connection  = @saved_col_connection */ ;
/*!50003 DROP FUNCTION IF EXISTS `CATEGORY_NATIONALITY@CAT_NATIONALITY_ID_EXISTS` */;
/*!50003 SET @saved_cs_client      = @@character_set_client */ ;
/*!50003 SET @saved_cs_results     = @@character_set_results */ ;
/*!50003 SET @saved_col_connection = @@collation_connection */ ;
/*!50003 SET character_set_client  = latin1 */ ;
/*!50003 SET character_set_results = latin1 */ ;
/*!50003 SET collation_connection  = latin1_swedish_ci */ ;
/*!50003 SET @saved_sql_mode       = @@sql_mode */ ;
/*!50003 SET sql_mode              = '' */ ;
DELIMITER ;;
CREATE DEFINER=`root`@`localhost` FUNCTION `CATEGORY_NATIONALITY@CAT_NATIONALITY_ID_EXISTS`(
	PARAM_CAT_NATIONALITY_ID BIGINT,
	DO_NOT_RETURN_INACTIVE_RECORDS BIT
) RETURNS tinyint(1)
SF_CHECK:
BEGIN

	-- STATUS
	-- ========================================================
	DECLARE STATUS_INACTIVE TINYINT DEFAULT 1;
	DECLARE STATUS_ACTIVE TINYINT DEFAULT 2;
	-- ========================================================
	
	IF PARAM_CAT_NATIONALITY_ID <= 0 THEN
		RETURN 0;
	END IF;

	-- CHECK IF EXISTS
	-- ========================================================
	IF
	(
		SELECT COUNT(`category_nationality`.`CAT_NATIONALITY_ID`)
		FROM `category_nationality`
		WHERE
			`category_nationality`.`CAT_NATIONALITY_ID` = PARAM_CAT_NATIONALITY_ID 
			AND
			(
				DO_NOT_RETURN_INACTIVE_RECORDS = 0 OR
				`category_nationality`.`CAT_NATIONALITY_STATUS` = STATUS_ACTIVE
			)
		LIMIT 1
	) >= 1
	THEN
		RETURN 1;

	ELSE 
		RETURN 0;
		
	END IF;
	-- ========================================================


	-- SQL Server requires to return value at the end of the function, even not reachable.
	RETURN 0;
	
END ;;
DELIMITER ;
/*!50003 SET sql_mode              = @saved_sql_mode */ ;
/*!50003 SET character_set_client  = @saved_cs_client */ ;
/*!50003 SET character_set_results = @saved_cs_results */ ;
/*!50003 SET collation_connection  = @saved_col_connection */ ;
/*!50003 DROP FUNCTION IF EXISTS `CATEGORY_NATIONALITY@DESCRIPTION_FROM_ID` */;
/*!50003 SET @saved_cs_client      = @@character_set_client */ ;
/*!50003 SET @saved_cs_results     = @@character_set_results */ ;
/*!50003 SET @saved_col_connection = @@collation_connection */ ;
/*!50003 SET character_set_client  = latin1 */ ;
/*!50003 SET character_set_results = latin1 */ ;
/*!50003 SET collation_connection  = latin1_swedish_ci */ ;
/*!50003 SET @saved_sql_mode       = @@sql_mode */ ;
/*!50003 SET sql_mode              = '' */ ;
DELIMITER ;;
CREATE DEFINER=`root`@`localhost` FUNCTION `CATEGORY_NATIONALITY@DESCRIPTION_FROM_ID`(
	PARAM_CAT_NATIONALITY_ID BIGINT
) RETURNS varchar(16000) CHARSET utf8 COLLATE utf8_unicode_ci
SF_CHECK:
BEGIN

	-- INITIALIZE
	DECLARE TEMP_DESCRIPTION VARCHAR(16000) DEFAULT '';

	
	-- GET DESCRIPTION
	-- ====================================================================
	IF `CATEGORY_NATIONALITY@CAT_NATIONALITY_ID_EXISTS`(PARAM_CAT_NATIONALITY_ID, 0) = 1 THEN

		SELECT
			`category_nationality`.`CAT_NATIONALITY_DESCRIPTION`
		INTO
			TEMP_DESCRIPTION
		FROM `category_nationality`
		WHERE
			`category_nationality`.`CAT_NATIONALITY_ID` = PARAM_CAT_NATIONALITY_ID
		LIMIT 1;

	ELSE
		SET TEMP_DESCRIPTION = 'NULL';
	END IF;
	-- ====================================================================

	-- SQL Server requires to return value at the end of the function, even not reachable.
	return TEMP_DESCRIPTION;
END ;;
DELIMITER ;
/*!50003 SET sql_mode              = @saved_sql_mode */ ;
/*!50003 SET character_set_client  = @saved_cs_client */ ;
/*!50003 SET character_set_results = @saved_cs_results */ ;
/*!50003 SET collation_connection  = @saved_col_connection */ ;
/*!50003 DROP FUNCTION IF EXISTS `CATEGORY_RELIGION@CAT_RELIGION_ID_EXISTS` */;
/*!50003 SET @saved_cs_client      = @@character_set_client */ ;
/*!50003 SET @saved_cs_results     = @@character_set_results */ ;
/*!50003 SET @saved_col_connection = @@collation_connection */ ;
/*!50003 SET character_set_client  = latin1 */ ;
/*!50003 SET character_set_results = latin1 */ ;
/*!50003 SET collation_connection  = latin1_swedish_ci */ ;
/*!50003 SET @saved_sql_mode       = @@sql_mode */ ;
/*!50003 SET sql_mode              = '' */ ;
DELIMITER ;;
CREATE DEFINER=`root`@`localhost` FUNCTION `CATEGORY_RELIGION@CAT_RELIGION_ID_EXISTS`(
	PARAM_CAT_RELIGION_ID BIGINT,
	DO_NOT_RETURN_INACTIVE_RECORDS BIT
) RETURNS tinyint(1)
SF_CHECK:
BEGIN

	-- STATUS
	-- ========================================================
	DECLARE STATUS_INACTIVE TINYINT DEFAULT 1;
	DECLARE STATUS_ACTIVE TINYINT DEFAULT 2;
	-- ========================================================
	
	IF PARAM_CAT_RELIGION_ID <= 0 THEN
		RETURN 0;
	END IF;

	-- CHECK IF EXISTS
	-- ========================================================
	IF
	(
		SELECT COUNT(`category_religion`.`CAT_RELIGION_ID`)
		FROM `category_religion`
		WHERE
			`category_religion`.`CAT_RELIGION_ID` = PARAM_CAT_RELIGION_ID 
			AND
			(
				DO_NOT_RETURN_INACTIVE_RECORDS = 0 OR
				`category_religion`.`CAT_RELIGION_STATUS` = STATUS_ACTIVE
			)
		LIMIT 1
	) >= 1
	THEN
		RETURN 1;

	ELSE 
		RETURN 0;
		
	END IF;
	-- ========================================================


	-- SQL Server requires to return value at the end of the function, even not reachable.
	RETURN 0;
	
END ;;
DELIMITER ;
/*!50003 SET sql_mode              = @saved_sql_mode */ ;
/*!50003 SET character_set_client  = @saved_cs_client */ ;
/*!50003 SET character_set_results = @saved_cs_results */ ;
/*!50003 SET collation_connection  = @saved_col_connection */ ;
/*!50003 DROP FUNCTION IF EXISTS `CATEGORY_RELIGION@DESCRIPTION_FROM_ID` */;
/*!50003 SET @saved_cs_client      = @@character_set_client */ ;
/*!50003 SET @saved_cs_results     = @@character_set_results */ ;
/*!50003 SET @saved_col_connection = @@collation_connection */ ;
/*!50003 SET character_set_client  = latin1 */ ;
/*!50003 SET character_set_results = latin1 */ ;
/*!50003 SET collation_connection  = latin1_swedish_ci */ ;
/*!50003 SET @saved_sql_mode       = @@sql_mode */ ;
/*!50003 SET sql_mode              = '' */ ;
DELIMITER ;;
CREATE DEFINER=`root`@`localhost` FUNCTION `CATEGORY_RELIGION@DESCRIPTION_FROM_ID`(
	PARAM_CAT_RELIGION_ID BIGINT
) RETURNS varchar(16000) CHARSET utf8 COLLATE utf8_unicode_ci
SF_CHECK:
BEGIN

	-- INITIALIZE
	DECLARE TEMP_DESCRIPTION VARCHAR(16000) DEFAULT '';

	
	-- GET DESCRIPTION
	-- ====================================================================
	IF `CATEGORY_RELIGION@CAT_RELIGION_ID_EXISTS`(PARAM_CAT_RELIGION_ID, 0) = 1 THEN

		SELECT
			`category_religion`.`CAT_RELIGION_DESCRIPTION`
		INTO
			TEMP_DESCRIPTION
		FROM `category_religion`
		WHERE
			`category_religion`.`CAT_RELIGION_ID` = PARAM_CAT_RELIGION_ID
		LIMIT 1;

	ELSE
		SET TEMP_DESCRIPTION = 'NULL';
	END IF;
	-- ====================================================================

	-- SQL Server requires to return value at the end of the function, even not reachable.
	return TEMP_DESCRIPTION;
END ;;
DELIMITER ;
/*!50003 SET sql_mode              = @saved_sql_mode */ ;
/*!50003 SET character_set_client  = @saved_cs_client */ ;
/*!50003 SET character_set_results = @saved_cs_results */ ;
/*!50003 SET collation_connection  = @saved_col_connection */ ;
/*!50003 DROP FUNCTION IF EXISTS `CATEGORY_SECTION@CAT_SECTION_ID_EXISTS` */;
/*!50003 SET @saved_cs_client      = @@character_set_client */ ;
/*!50003 SET @saved_cs_results     = @@character_set_results */ ;
/*!50003 SET @saved_col_connection = @@collation_connection */ ;
/*!50003 SET character_set_client  = latin1 */ ;
/*!50003 SET character_set_results = latin1 */ ;
/*!50003 SET collation_connection  = latin1_swedish_ci */ ;
/*!50003 SET @saved_sql_mode       = @@sql_mode */ ;
/*!50003 SET sql_mode              = '' */ ;
DELIMITER ;;
CREATE DEFINER=`root`@`localhost` FUNCTION `CATEGORY_SECTION@CAT_SECTION_ID_EXISTS`(
	PARAM_CAT_SECTION_ID BIGINT,
	DO_NOT_RETURN_INACTIVE_RECORDS BIT
) RETURNS tinyint(1)
SF_CHECK:
BEGIN

	-- STATUS
	-- ========================================================
	DECLARE STATUS_INACTIVE TINYINT DEFAULT 1;
	DECLARE STATUS_ACTIVE TINYINT DEFAULT 2;
	DECLARE STATUS_CLOSED TINYINT DEFAULT 3;
	DECLARE STATUS_COMPLETE TINYINT DEFAULT 4;
	-- ========================================================
	
	IF PARAM_CAT_SECTION_ID <= 0 THEN
		RETURN 0;
	END IF;

	-- CHECK IF EXISTS
	-- ========================================================
	IF
	(
		SELECT COUNT(`category_section`.`CAT_SECTION_ID`)
		FROM `category_section`
		WHERE
			`category_section`.`CAT_SECTION_ID` = PARAM_CAT_SECTION_ID 
			AND
			(
				DO_NOT_RETURN_INACTIVE_RECORDS = 0 OR
				`category_section`.`CAT_SECTION_STATUS` = STATUS_ACTIVE OR
				`category_section`.`CAT_SECTION_STATUS` = STATUS_COMPLETE
			)
		LIMIT 1
	) >= 1
	THEN
		RETURN 1;

	ELSE 
		RETURN 0;
		
	END IF;
	-- ========================================================


	-- SQL Server requires to return value at the end of the function, even not reachable.
	RETURN 0;
	
END ;;
DELIMITER ;
/*!50003 SET sql_mode              = @saved_sql_mode */ ;
/*!50003 SET character_set_client  = @saved_cs_client */ ;
/*!50003 SET character_set_results = @saved_cs_results */ ;
/*!50003 SET collation_connection  = @saved_col_connection */ ;
/*!50003 DROP FUNCTION IF EXISTS `CATEGORY_SECTION@DESCRIPTION_FROM_ID` */;
/*!50003 SET @saved_cs_client      = @@character_set_client */ ;
/*!50003 SET @saved_cs_results     = @@character_set_results */ ;
/*!50003 SET @saved_col_connection = @@collation_connection */ ;
/*!50003 SET character_set_client  = latin1 */ ;
/*!50003 SET character_set_results = latin1 */ ;
/*!50003 SET collation_connection  = latin1_swedish_ci */ ;
/*!50003 SET @saved_sql_mode       = @@sql_mode */ ;
/*!50003 SET sql_mode              = '' */ ;
DELIMITER ;;
CREATE DEFINER=`root`@`localhost` FUNCTION `CATEGORY_SECTION@DESCRIPTION_FROM_ID`(
	PARAM_CAT_SECTION_ID BIGINT
) RETURNS varchar(16000) CHARSET utf8 COLLATE utf8_unicode_ci
SF_CHECK:
BEGIN

	-- INITIALIZE
	DECLARE TEMP_DESCRIPTION VARCHAR(16000) DEFAULT '';

	
	-- GET DESCRIPTION
	-- ====================================================================
	IF `CATEGORY_SECTION@CAT_SECTION_ID_EXISTS`(PARAM_CAT_SECTION_ID, 0) = 1 THEN

		SELECT
			`category_section`.`CAT_SECTION_DESCRIPTION`
		INTO
			TEMP_DESCRIPTION
		FROM `category_section`
		WHERE
			`category_section`.`CAT_SECTION_ID` = PARAM_CAT_SECTION_ID
		LIMIT 1;

	ELSE
		SET TEMP_DESCRIPTION = 'NULL';
	END IF;
	-- ====================================================================

	-- SQL Server requires to return value at the end of the function, even not reachable.
	return TEMP_DESCRIPTION;
END ;;
DELIMITER ;
/*!50003 SET sql_mode              = @saved_sql_mode */ ;
/*!50003 SET character_set_client  = @saved_cs_client */ ;
/*!50003 SET character_set_results = @saved_cs_results */ ;
/*!50003 SET collation_connection  = @saved_col_connection */ ;
/*!50003 DROP FUNCTION IF EXISTS `CATEGORY_SECTION@ID_FROM_DESCRIPTION` */;
/*!50003 SET @saved_cs_client      = @@character_set_client */ ;
/*!50003 SET @saved_cs_results     = @@character_set_results */ ;
/*!50003 SET @saved_col_connection = @@collation_connection */ ;
/*!50003 SET character_set_client  = latin1 */ ;
/*!50003 SET character_set_results = latin1 */ ;
/*!50003 SET collation_connection  = latin1_swedish_ci */ ;
/*!50003 SET @saved_sql_mode       = @@sql_mode */ ;
/*!50003 SET sql_mode              = '' */ ;
DELIMITER ;;
CREATE DEFINER=`root`@`localhost` FUNCTION `CATEGORY_SECTION@ID_FROM_DESCRIPTION`(
	PARAM_CAT_SECTION_DESCRIPTION VARCHAR(400)
) RETURNS bigint(20)
SF_CHECK:
BEGIN

	-- INITIALIZE
	DECLARE TEMP_ID BIGINT DEFAULT 0;

	
	-- GET DESCRIPTION
	-- ====================================================================
	IF 
		(
			SELECT COUNT(`category_section`.`CAT_SECTION_ID`)
			FROM `category_section`
			WHERE
				`category_section`.`CAT_SECTION_DESCRIPTION` = PARAM_CAT_SECTION_DESCRIPTION
			LIMIT 1
		) >= 1
	THEN

		SELECT
			`category_section`.`CAT_SECTION_ID`
		INTO
			TEMP_ID
		FROM `category_section`
		WHERE
			`category_section`.`CAT_SECTION_DESCRIPTION` = PARAM_CAT_SECTION_DESCRIPTION
		LIMIT 1;

	END IF;
	-- ====================================================================

	-- SQL Server requires to return value at the end of the function, even not reachable.
	return TEMP_ID;
END ;;
DELIMITER ;
/*!50003 SET sql_mode              = @saved_sql_mode */ ;
/*!50003 SET character_set_client  = @saved_cs_client */ ;
/*!50003 SET character_set_results = @saved_cs_results */ ;
/*!50003 SET collation_connection  = @saved_col_connection */ ;
/*!50003 DROP FUNCTION IF EXISTS `FUN_AES_DECRYPTION` */;
/*!50003 SET @saved_cs_client      = @@character_set_client */ ;
/*!50003 SET @saved_cs_results     = @@character_set_results */ ;
/*!50003 SET @saved_col_connection = @@collation_connection */ ;
/*!50003 SET character_set_client  = latin1 */ ;
/*!50003 SET character_set_results = latin1 */ ;
/*!50003 SET collation_connection  = latin1_swedish_ci */ ;
/*!50003 SET @saved_sql_mode       = @@sql_mode */ ;
/*!50003 SET sql_mode              = '' */ ;
DELIMITER ;;
CREATE DEFINER=`root`@`localhost` FUNCTION `FUN_AES_DECRYPTION`(
	PARAM_CIPHER_TEXT VARCHAR(16000),
	PARAM_AES_KEY VARCHAR(32),
	PARAM_ADD_SALT BIT
) RETURNS varchar(16000) CHARSET utf8 COLLATE utf8_unicode_ci
SF_CHECK:
BEGIN

	-- INITIALIZE
	-- ====================================================================
	DECLARE TEMP_DECRYPTED_TEXT VARCHAR(16000) DEFAULT '';
	
	
	-- APPLY AES
	-- ====================================================================
	SET TEMP_DECRYPTED_TEXT = CAST(AES_DECRYPT(UNHEX(PARAM_CIPHER_TEXT), PARAM_AES_KEY) AS CHAR(16000));	
	IF PARAM_ADD_SALT = 1 THEN
		SET TEMP_DECRYPTED_TEXT = RIGHT(TEMP_DECRYPTED_TEXT, CHAR_LENGTH(TEMP_DECRYPTED_TEXT) - 32);
	END IF;

	
	-- RETURN RESULT
	-- ====================================================================
	RETURN TEMP_DECRYPTED_TEXT;
		
END ;;
DELIMITER ;
/*!50003 SET sql_mode              = @saved_sql_mode */ ;
/*!50003 SET character_set_client  = @saved_cs_client */ ;
/*!50003 SET character_set_results = @saved_cs_results */ ;
/*!50003 SET collation_connection  = @saved_col_connection */ ;
/*!50003 DROP FUNCTION IF EXISTS `FUN_AES_ENCRYPTION` */;
/*!50003 SET @saved_cs_client      = @@character_set_client */ ;
/*!50003 SET @saved_cs_results     = @@character_set_results */ ;
/*!50003 SET @saved_col_connection = @@collation_connection */ ;
/*!50003 SET character_set_client  = latin1 */ ;
/*!50003 SET character_set_results = latin1 */ ;
/*!50003 SET collation_connection  = latin1_swedish_ci */ ;
/*!50003 SET @saved_sql_mode       = @@sql_mode */ ;
/*!50003 SET sql_mode              = '' */ ;
DELIMITER ;;
CREATE DEFINER=`root`@`localhost` FUNCTION `FUN_AES_ENCRYPTION`(
	PARAM_PLAIN_TEXT VARCHAR(16000),
	PARAM_AES_KEY VARCHAR(32),
	PARAM_ADD_SALT BIT
) RETURNS varchar(16000) CHARSET utf8 COLLATE utf8_unicode_ci
SF_CHECK:
BEGIN

	-- INITIALIZE
	-- ====================================================================
	DECLARE TEMP_SALT VARCHAR(32) DEFAULT `FUN_RANDOM_STR`(32);
	DECLARE TEMP_ENCRYPTED_TEXT VARCHAR(16000) DEFAULT '';
	
	
	-- APPLY AES
	-- ====================================================================
	IF PARAM_ADD_SALT = 1 THEN
		SET PARAM_PLAIN_TEXT = CONCAT(TEMP_SALT, PARAM_PLAIN_TEXT);
	END IF;
	SET TEMP_ENCRYPTED_TEXT = HEX(AES_ENCRYPT(PARAM_PLAIN_TEXT, PARAM_AES_KEY));

	
	-- RETURN RESULT
	-- ====================================================================
	RETURN TEMP_ENCRYPTED_TEXT;
	
END ;;
DELIMITER ;
/*!50003 SET sql_mode              = @saved_sql_mode */ ;
/*!50003 SET character_set_client  = @saved_cs_client */ ;
/*!50003 SET character_set_results = @saved_cs_results */ ;
/*!50003 SET collation_connection  = @saved_col_connection */ ;
/*!50003 DROP FUNCTION IF EXISTS `FUN_BEGIN_OF_DAY` */;
/*!50003 SET @saved_cs_client      = @@character_set_client */ ;
/*!50003 SET @saved_cs_results     = @@character_set_results */ ;
/*!50003 SET @saved_col_connection = @@collation_connection */ ;
/*!50003 SET character_set_client  = latin1 */ ;
/*!50003 SET character_set_results = latin1 */ ;
/*!50003 SET collation_connection  = latin1_swedish_ci */ ;
/*!50003 SET @saved_sql_mode       = @@sql_mode */ ;
/*!50003 SET sql_mode              = '' */ ;
DELIMITER ;;
CREATE DEFINER=`root`@`localhost` FUNCTION `FUN_BEGIN_OF_DAY`(
	PARAM_DATETIME DATETIME(6)
) RETURNS datetime(6)
SF_CHECK:
BEGIN

	-- INITIALIZE
	-- ====================================================================
	DECLARE TEMP_DATETIME_TEXT VARCHAR(500) DEFAULT '';
	
	
	-- GET DATE ONLY
	-- ====================================================================
	SET TEMP_DATETIME_TEXT = DATE_FORMAT(PARAM_DATETIME,'%Y-%m-%d');
	SET TEMP_DATETIME_TEXT = CONCAT_WS(' ', TEMP_DATETIME_TEXT, '00:00:00.000000');
	
	
	-- Convert to DateTIme
	-- ====================================================================
	SET PARAM_DATETIME = CAST(TEMP_DATETIME_TEXT AS DATETIME(6));

	
	-- RETURN RESULT
	-- ====================================================================
	RETURN PARAM_DATETIME;
		
END ;;
DELIMITER ;
/*!50003 SET sql_mode              = @saved_sql_mode */ ;
/*!50003 SET character_set_client  = @saved_cs_client */ ;
/*!50003 SET character_set_results = @saved_cs_results */ ;
/*!50003 SET collation_connection  = @saved_col_connection */ ;
/*!50003 DROP FUNCTION IF EXISTS `FUN_BEGIN_OF_MONTH` */;
/*!50003 SET @saved_cs_client      = @@character_set_client */ ;
/*!50003 SET @saved_cs_results     = @@character_set_results */ ;
/*!50003 SET @saved_col_connection = @@collation_connection */ ;
/*!50003 SET character_set_client  = latin1 */ ;
/*!50003 SET character_set_results = latin1 */ ;
/*!50003 SET collation_connection  = latin1_swedish_ci */ ;
/*!50003 SET @saved_sql_mode       = @@sql_mode */ ;
/*!50003 SET sql_mode              = '' */ ;
DELIMITER ;;
CREATE DEFINER=`root`@`localhost` FUNCTION `FUN_BEGIN_OF_MONTH`(
	PARAM_DATETIME DATETIME(6)
) RETURNS datetime(6)
SF_CHECK:
BEGIN

	-- INITIALIZE
	-- ====================================================================
	DECLARE TEMP_DATETIME_TEXT VARCHAR(500) DEFAULT '';
	
	
	-- GET DATE ONLY
	-- ====================================================================
	SET TEMP_DATETIME_TEXT = DATE_FORMAT(PARAM_DATETIME,'%Y-%m');
	SET TEMP_DATETIME_TEXT = CONCAT_WS('-', TEMP_DATETIME_TEXT, '01 00:00:00.000000');
	
	
	-- Convert to DateTIme
	-- ====================================================================
	SET PARAM_DATETIME = CAST(TEMP_DATETIME_TEXT AS DATETIME(6));

	
	-- RETURN RESULT
	-- ====================================================================
	RETURN PARAM_DATETIME;
		
END ;;
DELIMITER ;
/*!50003 SET sql_mode              = @saved_sql_mode */ ;
/*!50003 SET character_set_client  = @saved_cs_client */ ;
/*!50003 SET character_set_results = @saved_cs_results */ ;
/*!50003 SET collation_connection  = @saved_col_connection */ ;
/*!50003 DROP FUNCTION IF EXISTS `FUN_DLEFT` */;
/*!50003 SET @saved_cs_client      = @@character_set_client */ ;
/*!50003 SET @saved_cs_results     = @@character_set_results */ ;
/*!50003 SET @saved_col_connection = @@collation_connection */ ;
/*!50003 SET character_set_client  = latin1 */ ;
/*!50003 SET character_set_results = latin1 */ ;
/*!50003 SET collation_connection  = latin1_swedish_ci */ ;
/*!50003 SET @saved_sql_mode       = @@sql_mode */ ;
/*!50003 SET sql_mode              = '' */ ;
DELIMITER ;;
CREATE DEFINER=`root`@`localhost` FUNCTION `FUN_DLEFT`(
	`PARAM_VARCHAR_VALUE` VARCHAR(16000),
	`PARAM_REMOVE_COUNT` INT
) RETURNS varchar(16000) CHARSET utf8 COLLATE utf8_unicode_ci
SF_CHECK:
BEGIN
	
	-- Initialize
	-- ...........................................
	DECLARE TEMP_CHARACTER_LENGTH INT DEFAULT LENGTH(PARAM_VARCHAR_VALUE);
	
	
	-- Remove Characters
	-- ...........................................
	IF TEMP_CHARACTER_LENGTH <= PARAM_REMOVE_COUNT THEN
		SET PARAM_VARCHAR_VALUE = '';
	ELSE
		SET TEMP_CHARACTER_LENGTH = TEMP_CHARACTER_LENGTH - PARAM_REMOVE_COUNT;
		SET PARAM_VARCHAR_VALUE = RIGHT(PARAM_VARCHAR_VALUE, TEMP_CHARACTER_LENGTH);	
	END IF;

	
	-- Return Result
	-- ...........................................
	RETURN PARAM_VARCHAR_VALUE;
	
END ;;
DELIMITER ;
/*!50003 SET sql_mode              = @saved_sql_mode */ ;
/*!50003 SET character_set_client  = @saved_cs_client */ ;
/*!50003 SET character_set_results = @saved_cs_results */ ;
/*!50003 SET collation_connection  = @saved_col_connection */ ;
/*!50003 DROP FUNCTION IF EXISTS `FUN_DRIGHT` */;
/*!50003 SET @saved_cs_client      = @@character_set_client */ ;
/*!50003 SET @saved_cs_results     = @@character_set_results */ ;
/*!50003 SET @saved_col_connection = @@collation_connection */ ;
/*!50003 SET character_set_client  = latin1 */ ;
/*!50003 SET character_set_results = latin1 */ ;
/*!50003 SET collation_connection  = latin1_swedish_ci */ ;
/*!50003 SET @saved_sql_mode       = @@sql_mode */ ;
/*!50003 SET sql_mode              = '' */ ;
DELIMITER ;;
CREATE DEFINER=`root`@`localhost` FUNCTION `FUN_DRIGHT`(
	`PARAM_VARCHAR_VALUE` VARCHAR(16000),
	`PARAM_REMOVE_COUNT` INT
) RETURNS varchar(16000) CHARSET utf8 COLLATE utf8_unicode_ci
SF_CHECK:
BEGIN
	
	-- Initialize
	-- ...........................................
	DECLARE TEMP_CHARACTER_LENGTH INT DEFAULT LENGTH(PARAM_VARCHAR_VALUE);
	
	
	-- Remove Characters
	-- ...........................................
	IF TEMP_CHARACTER_LENGTH <= PARAM_REMOVE_COUNT THEN
		SET PARAM_VARCHAR_VALUE = '';
	ELSE
		SET TEMP_CHARACTER_LENGTH = TEMP_CHARACTER_LENGTH - PARAM_REMOVE_COUNT;
		SET PARAM_VARCHAR_VALUE = LEFT(PARAM_VARCHAR_VALUE, TEMP_CHARACTER_LENGTH);	
	END IF;

	
	-- Return Result
	-- ...........................................
	RETURN PARAM_VARCHAR_VALUE;
	
END ;;
DELIMITER ;
/*!50003 SET sql_mode              = @saved_sql_mode */ ;
/*!50003 SET character_set_client  = @saved_cs_client */ ;
/*!50003 SET character_set_results = @saved_cs_results */ ;
/*!50003 SET collation_connection  = @saved_col_connection */ ;
/*!50003 DROP FUNCTION IF EXISTS `FUN_END_OF_DAY` */;
/*!50003 SET @saved_cs_client      = @@character_set_client */ ;
/*!50003 SET @saved_cs_results     = @@character_set_results */ ;
/*!50003 SET @saved_col_connection = @@collation_connection */ ;
/*!50003 SET character_set_client  = latin1 */ ;
/*!50003 SET character_set_results = latin1 */ ;
/*!50003 SET collation_connection  = latin1_swedish_ci */ ;
/*!50003 SET @saved_sql_mode       = @@sql_mode */ ;
/*!50003 SET sql_mode              = '' */ ;
DELIMITER ;;
CREATE DEFINER=`root`@`localhost` FUNCTION `FUN_END_OF_DAY`(
	PARAM_DATETIME DATETIME(6)
) RETURNS datetime(6)
SF_CHECK:
BEGIN

	-- INITIALIZE
	-- ====================================================================
	DECLARE TEMP_DATETIME_TEXT VARCHAR(500) DEFAULT '';
	
	
	-- GET DATE ONLY
	-- ====================================================================
	SET TEMP_DATETIME_TEXT = DATE_FORMAT(PARAM_DATETIME,'%Y-%m-%d');
	SET TEMP_DATETIME_TEXT = CONCAT_WS(' ', TEMP_DATETIME_TEXT, '23:59:59.999999');
	
	
	-- Convert to DateTIme
	-- ====================================================================
	SET PARAM_DATETIME = CAST(TEMP_DATETIME_TEXT AS DATETIME(6));

	
	-- RETURN RESULT
	-- ====================================================================
	RETURN PARAM_DATETIME;
		
END ;;
DELIMITER ;
/*!50003 SET sql_mode              = @saved_sql_mode */ ;
/*!50003 SET character_set_client  = @saved_cs_client */ ;
/*!50003 SET character_set_results = @saved_cs_results */ ;
/*!50003 SET collation_connection  = @saved_col_connection */ ;
/*!50003 DROP FUNCTION IF EXISTS `FUN_END_OF_MONTH` */;
/*!50003 SET @saved_cs_client      = @@character_set_client */ ;
/*!50003 SET @saved_cs_results     = @@character_set_results */ ;
/*!50003 SET @saved_col_connection = @@collation_connection */ ;
/*!50003 SET character_set_client  = latin1 */ ;
/*!50003 SET character_set_results = latin1 */ ;
/*!50003 SET collation_connection  = latin1_swedish_ci */ ;
/*!50003 SET @saved_sql_mode       = @@sql_mode */ ;
/*!50003 SET sql_mode              = '' */ ;
DELIMITER ;;
CREATE DEFINER=`root`@`localhost` FUNCTION `FUN_END_OF_MONTH`(
	PARAM_DATETIME DATETIME(6)
) RETURNS datetime(6)
SF_CHECK:
BEGIN

	-- INITIALIZE
	-- ====================================================================
	DECLARE TEMP_DATETIME_TEXT VARCHAR(500) DEFAULT '';
	SET PARAM_DATETIME = LAST_DAY(PARAM_DATETIME);
	
	
	-- GET DATE ONLY
	-- ====================================================================
	SET TEMP_DATETIME_TEXT = DATE_FORMAT(PARAM_DATETIME,'%Y-%m-%d');
	SET TEMP_DATETIME_TEXT = CONCAT_WS(' ', TEMP_DATETIME_TEXT, '23:59:59.999999');
	
	
	-- Convert to DateTIme
	-- ====================================================================
	SET PARAM_DATETIME = CAST(TEMP_DATETIME_TEXT AS DATETIME(6));

	
	-- RETURN RESULT
	-- ====================================================================
	RETURN PARAM_DATETIME;
		
END ;;
DELIMITER ;
/*!50003 SET sql_mode              = @saved_sql_mode */ ;
/*!50003 SET character_set_client  = @saved_cs_client */ ;
/*!50003 SET character_set_results = @saved_cs_results */ ;
/*!50003 SET collation_connection  = @saved_col_connection */ ;
/*!50003 DROP FUNCTION IF EXISTS `FUN_IGNORE_DATE` */;
/*!50003 SET @saved_cs_client      = @@character_set_client */ ;
/*!50003 SET @saved_cs_results     = @@character_set_results */ ;
/*!50003 SET @saved_col_connection = @@collation_connection */ ;
/*!50003 SET character_set_client  = latin1 */ ;
/*!50003 SET character_set_results = latin1 */ ;
/*!50003 SET collation_connection  = latin1_swedish_ci */ ;
/*!50003 SET @saved_sql_mode       = @@sql_mode */ ;
/*!50003 SET sql_mode              = '' */ ;
DELIMITER ;;
CREATE DEFINER=`root`@`localhost` FUNCTION `FUN_IGNORE_DATE`(
	PARAM_DATETIME DATETIME(6)
) RETURNS datetime(6)
SF_CHECK:
BEGIN

	-- INITIALIZE
	-- ====================================================================
	DECLARE TEMP_DATETIME_TEXT VARCHAR(500) DEFAULT '';
	
	-- GET DATE ONLY
	-- ====================================================================
	SET TEMP_DATETIME_TEXT = DATE_FORMAT(PARAM_DATETIME,'%H:%i:%s');
	SET TEMP_DATETIME_TEXT = CONCAT_WS(' ', '1000-01-01', TEMP_DATETIME_TEXT);
	
	
	-- Convert to DateTIme
	-- ====================================================================
	SET PARAM_DATETIME = CAST(TEMP_DATETIME_TEXT AS DATETIME(6));

	
	-- RETURN RESULT
	-- ====================================================================
	RETURN PARAM_DATETIME;
		
END ;;
DELIMITER ;
/*!50003 SET sql_mode              = @saved_sql_mode */ ;
/*!50003 SET character_set_client  = @saved_cs_client */ ;
/*!50003 SET character_set_results = @saved_cs_results */ ;
/*!50003 SET collation_connection  = @saved_col_connection */ ;
/*!50003 DROP FUNCTION IF EXISTS `FUN_RANDOM_INT` */;
/*!50003 SET @saved_cs_client      = @@character_set_client */ ;
/*!50003 SET @saved_cs_results     = @@character_set_results */ ;
/*!50003 SET @saved_col_connection = @@collation_connection */ ;
/*!50003 SET character_set_client  = latin1 */ ;
/*!50003 SET character_set_results = latin1 */ ;
/*!50003 SET collation_connection  = latin1_swedish_ci */ ;
/*!50003 SET @saved_sql_mode       = @@sql_mode */ ;
/*!50003 SET sql_mode              = '' */ ;
DELIMITER ;;
CREATE DEFINER=`root`@`localhost` FUNCTION `FUN_RANDOM_INT`(
	`PARAM_MIN_VALUE` INT,
	`PARAM_MAX_VALUE` INT
) RETURNS varchar(500) CHARSET utf8 COLLATE utf8_unicode_ci
SF_CHECK:
BEGIN
	
	-- Return Result
	-- ...........................................
	RETURN  `SYSTEM_VAR@RANDOM`(PARAM_MIN_VALUE, PARAM_MAX_VALUE);
	
END ;;
DELIMITER ;
/*!50003 SET sql_mode              = @saved_sql_mode */ ;
/*!50003 SET character_set_client  = @saved_cs_client */ ;
/*!50003 SET character_set_results = @saved_cs_results */ ;
/*!50003 SET collation_connection  = @saved_col_connection */ ;
/*!50003 DROP FUNCTION IF EXISTS `FUN_RANDOM_STR` */;
/*!50003 SET @saved_cs_client      = @@character_set_client */ ;
/*!50003 SET @saved_cs_results     = @@character_set_results */ ;
/*!50003 SET @saved_col_connection = @@collation_connection */ ;
/*!50003 SET character_set_client  = latin1 */ ;
/*!50003 SET character_set_results = latin1 */ ;
/*!50003 SET collation_connection  = latin1_swedish_ci */ ;
/*!50003 SET @saved_sql_mode       = @@sql_mode */ ;
/*!50003 SET sql_mode              = '' */ ;
DELIMITER ;;
CREATE DEFINER=`root`@`localhost` FUNCTION `FUN_RANDOM_STR`(
	PARAM_STR_LENGTH INT
) RETURNS varchar(500) CHARSET utf8 COLLATE utf8_unicode_ci
SF_CHECK:
BEGIN

	-- Return Result
	-- ...........................................
	RETURN `SYSTEM_VAR@RANDOM_STR`(PARAM_STR_LENGTH);

END ;;
DELIMITER ;
/*!50003 SET sql_mode              = @saved_sql_mode */ ;
/*!50003 SET character_set_client  = @saved_cs_client */ ;
/*!50003 SET character_set_results = @saved_cs_results */ ;
/*!50003 SET collation_connection  = @saved_col_connection */ ;
/*!50003 DROP FUNCTION IF EXISTS `FUN_RANDOM_UNIQUE_ALPHA32` */;
/*!50003 SET @saved_cs_client      = @@character_set_client */ ;
/*!50003 SET @saved_cs_results     = @@character_set_results */ ;
/*!50003 SET @saved_col_connection = @@collation_connection */ ;
/*!50003 SET character_set_client  = latin1 */ ;
/*!50003 SET character_set_results = latin1 */ ;
/*!50003 SET collation_connection  = latin1_swedish_ci */ ;
/*!50003 SET @saved_sql_mode       = @@sql_mode */ ;
/*!50003 SET sql_mode              = '' */ ;
DELIMITER ;;
CREATE DEFINER=`root`@`localhost` FUNCTION `FUN_RANDOM_UNIQUE_ALPHA32`() RETURNS varchar(34) CHARSET utf8 COLLATE utf8_unicode_ci
SF_CHECK:
BEGIN

	-- Return Result
	-- _______________________________________________________________________
	RETURN  `SYSTEM_VAR@RANDOM_UNIQUE_ALPHA32`() ;

	
END ;;
DELIMITER ;
/*!50003 SET sql_mode              = @saved_sql_mode */ ;
/*!50003 SET character_set_client  = @saved_cs_client */ ;
/*!50003 SET character_set_results = @saved_cs_results */ ;
/*!50003 SET collation_connection  = @saved_col_connection */ ;
/*!50003 DROP FUNCTION IF EXISTS `FUN_RANDOM_UNIQUE_INTCHAR` */;
/*!50003 SET @saved_cs_client      = @@character_set_client */ ;
/*!50003 SET @saved_cs_results     = @@character_set_results */ ;
/*!50003 SET @saved_col_connection = @@collation_connection */ ;
/*!50003 SET character_set_client  = latin1 */ ;
/*!50003 SET character_set_results = latin1 */ ;
/*!50003 SET collation_connection  = latin1_swedish_ci */ ;
/*!50003 SET @saved_sql_mode       = @@sql_mode */ ;
/*!50003 SET sql_mode              = '' */ ;
DELIMITER ;;
CREATE DEFINER=`root`@`localhost` FUNCTION `FUN_RANDOM_UNIQUE_INTCHAR`() RETURNS varchar(40) CHARSET utf8 COLLATE utf8_unicode_ci
SF_CHECK:
BEGIN

	-- Return Result
	-- _______________________________________________________________________
	RETURN  `SYSTEM_VAR@RANDOM_UNIQUE_INTCHAR`() ;

END ;;
DELIMITER ;
/*!50003 SET sql_mode              = @saved_sql_mode */ ;
/*!50003 SET character_set_client  = @saved_cs_client */ ;
/*!50003 SET character_set_results = @saved_cs_results */ ;
/*!50003 SET collation_connection  = @saved_col_connection */ ;
/*!50003 DROP FUNCTION IF EXISTS `FUN_RANDOM_UNIQUE_STR` */;
/*!50003 SET @saved_cs_client      = @@character_set_client */ ;
/*!50003 SET @saved_cs_results     = @@character_set_results */ ;
/*!50003 SET @saved_col_connection = @@collation_connection */ ;
/*!50003 SET character_set_client  = latin1 */ ;
/*!50003 SET character_set_results = latin1 */ ;
/*!50003 SET collation_connection  = latin1_swedish_ci */ ;
/*!50003 SET @saved_sql_mode       = @@sql_mode */ ;
/*!50003 SET sql_mode              = '' */ ;
DELIMITER ;;
CREATE DEFINER=`root`@`localhost` FUNCTION `FUN_RANDOM_UNIQUE_STR`() RETURNS varchar(40) CHARSET utf8 COLLATE utf8_unicode_ci
SF_CHECK:
BEGIN

	-- Return Result
	-- _______________________________________________________________________
	RETURN `SYSTEM_VAR@RANDOM_UNIQUE_STR`() ;

END ;;
DELIMITER ;
/*!50003 SET sql_mode              = @saved_sql_mode */ ;
/*!50003 SET character_set_client  = @saved_cs_client */ ;
/*!50003 SET character_set_results = @saved_cs_results */ ;
/*!50003 SET collation_connection  = @saved_col_connection */ ;
/*!50003 DROP FUNCTION IF EXISTS `FUN_SHA512` */;
/*!50003 SET @saved_cs_client      = @@character_set_client */ ;
/*!50003 SET @saved_cs_results     = @@character_set_results */ ;
/*!50003 SET @saved_col_connection = @@collation_connection */ ;
/*!50003 SET character_set_client  = latin1 */ ;
/*!50003 SET character_set_results = latin1 */ ;
/*!50003 SET collation_connection  = latin1_swedish_ci */ ;
/*!50003 SET @saved_sql_mode       = @@sql_mode */ ;
/*!50003 SET sql_mode              = '' */ ;
DELIMITER ;;
CREATE DEFINER=`root`@`localhost` FUNCTION `FUN_SHA512`(
	PARAM_PLAIN_TEXT VARCHAR(16000),
	PARAM_ADD_SALT BIT
) RETURNS varchar(16000) CHARSET utf8 COLLATE utf8_unicode_ci
SF_CHECK:
BEGIN

	-- INITIALIZE
	-- ====================================================================
	DECLARE TEMP_SALT VARCHAR(32) DEFAULT `FUN_RANDOM_STR`(32);
	DECLARE TEMP_HASHED_TEXT VARCHAR(16000) DEFAULT '';
	
	
	-- PREPARE SALT
	-- ====================================================================
	IF PARAM_ADD_SALT = 1 THEN
		SET PARAM_PLAIN_TEXT = CONCAT(TEMP_SALT, PARAM_PLAIN_TEXT);
	END IF;
	
	
	-- APPLY AES
	-- ====================================================================
	SET TEMP_HASHED_TEXT = HEX(SHA2(PARAM_PLAIN_TEXT, 512));
	
	
	-- SALTED POST ACTION
	-- ====================================================================
	IF PARAM_ADD_SALT = 1 THEN
		SET TEMP_HASHED_TEXT = CONCAT(TEMP_SALT, TEMP_HASHED_TEXT);
	END IF;
	
	
	-- RETURN RESULT
	-- ====================================================================
	RETURN TEMP_HASHED_TEXT;
	
END ;;
DELIMITER ;
/*!50003 SET sql_mode              = @saved_sql_mode */ ;
/*!50003 SET character_set_client  = @saved_cs_client */ ;
/*!50003 SET character_set_results = @saved_cs_results */ ;
/*!50003 SET collation_connection  = @saved_col_connection */ ;
/*!50003 DROP FUNCTION IF EXISTS `FUN_SHA512_VERIFY` */;
/*!50003 SET @saved_cs_client      = @@character_set_client */ ;
/*!50003 SET @saved_cs_results     = @@character_set_results */ ;
/*!50003 SET @saved_col_connection = @@collation_connection */ ;
/*!50003 SET character_set_client  = latin1 */ ;
/*!50003 SET character_set_results = latin1 */ ;
/*!50003 SET collation_connection  = latin1_swedish_ci */ ;
/*!50003 SET @saved_sql_mode       = @@sql_mode */ ;
/*!50003 SET sql_mode              = '' */ ;
DELIMITER ;;
CREATE DEFINER=`root`@`localhost` FUNCTION `FUN_SHA512_VERIFY`(
	PARAM_HASHED_TEXT VARCHAR(4000),
	PARAM_PLAIN_TEXT VARCHAR(4000),
	PARAM_ADD_SALT BIT
) RETURNS bit(1)
SF_CHECK:
BEGIN

	-- INITIALIZE
	-- ====================================================================
	DECLARE TEMP_ENCRYPTED_TEXT VARCHAR(4000) DEFAULT '';
	DECLARE TEMP_SALT NVARCHAR(32) DEFAULT '';
	
	
	-- PREPARE SALT
	-- ====================================================================
	IF PARAM_ADD_SALT = 1 THEN
		SET TEMP_SALT = LEFT(PARAM_HASHED_TEXT, 32);
		SET PARAM_PLAIN_TEXT = CONCAT(TEMP_SALT, PARAM_PLAIN_TEXT);
		SET PARAM_HASHED_TEXT = RIGHT(PARAM_HASHED_TEXT, CHAR_LENGTH(PARAM_HASHED_TEXT) - 32);
	END IF;
	
	
	-- APPLY HASH
	-- ====================================================================
	SET PARAM_PLAIN_TEXT = HEX(SHA2(PARAM_PLAIN_TEXT, 512));
	
	
	-- RETURN RESULT
	-- ====================================================================
	IF PARAM_PLAIN_TEXT = PARAM_HASHED_TEXT THEN
		RETURN 1;
	ELSE
		RETURN 0;
	END IF;
	RETURN 0;

END ;;
DELIMITER ;
/*!50003 SET sql_mode              = @saved_sql_mode */ ;
/*!50003 SET character_set_client  = @saved_cs_client */ ;
/*!50003 SET character_set_results = @saved_cs_results */ ;
/*!50003 SET collation_connection  = @saved_col_connection */ ;
/*!50003 DROP FUNCTION IF EXISTS `FUN_STRIP_SPECIAL_CHARS` */;
/*!50003 SET @saved_cs_client      = @@character_set_client */ ;
/*!50003 SET @saved_cs_results     = @@character_set_results */ ;
/*!50003 SET @saved_col_connection = @@collation_connection */ ;
/*!50003 SET character_set_client  = latin1 */ ;
/*!50003 SET character_set_results = latin1 */ ;
/*!50003 SET collation_connection  = latin1_swedish_ci */ ;
/*!50003 SET @saved_sql_mode       = @@sql_mode */ ;
/*!50003 SET sql_mode              = '' */ ;
DELIMITER ;;
CREATE DEFINER=`root`@`localhost` FUNCTION `FUN_STRIP_SPECIAL_CHARS`(
	PARAM_TEXT VARCHAR(4000)
) RETURNS varchar(4000) CHARSET utf8 COLLATE utf8_unicode_ci
SF_CHECK:
BEGIN

	-- REPLACE SPECIAL CHARS
	-- ====================================================================
	IF `SYSTEM_VAR@IS_NULL@NVARCHAR`(PARAM_TEXT, 1) = 0 THEN
		
		SET PARAM_TEXT = REPLACE(PARAM_TEXT, ' ', '');
		
		SET PARAM_TEXT = REPLACE(PARAM_TEXT, '`', '');
		SET PARAM_TEXT = REPLACE(PARAM_TEXT, '~', '');
	
		SET PARAM_TEXT = REPLACE(PARAM_TEXT, '!', '');
		SET PARAM_TEXT = REPLACE(PARAM_TEXT, '@', '');
		SET PARAM_TEXT = REPLACE(PARAM_TEXT, '#', '');
		SET PARAM_TEXT = REPLACE(PARAM_TEXT, '$', '');
		SET PARAM_TEXT = REPLACE(PARAM_TEXT, '%', '');
		SET PARAM_TEXT = REPLACE(PARAM_TEXT, '^', '');
		SET PARAM_TEXT = REPLACE(PARAM_TEXT, '&', '');
		SET PARAM_TEXT = REPLACE(PARAM_TEXT, '*', '');
		SET PARAM_TEXT = REPLACE(PARAM_TEXT, '(', '');
		SET PARAM_TEXT = REPLACE(PARAM_TEXT, ')', '');
		SET PARAM_TEXT = REPLACE(PARAM_TEXT, '-', '');
		SET PARAM_TEXT = REPLACE(PARAM_TEXT, '_', '');
		SET PARAM_TEXT = REPLACE(PARAM_TEXT, '=', '');
		SET PARAM_TEXT = REPLACE(PARAM_TEXT, '+', '');
	
		SET PARAM_TEXT = REPLACE(PARAM_TEXT, '[', '');
		SET PARAM_TEXT = REPLACE(PARAM_TEXT, '{', '');
		SET PARAM_TEXT = REPLACE(PARAM_TEXT, ']', '');
		SET PARAM_TEXT = REPLACE(PARAM_TEXT, '}', '');	
	
		SET PARAM_TEXT = REPLACE(PARAM_TEXT, ';', '');	
		SET PARAM_TEXT = REPLACE(PARAM_TEXT, ':', '');	
		SET PARAM_TEXT = REPLACE(PARAM_TEXT, '\'', '');	
		SET PARAM_TEXT = REPLACE(PARAM_TEXT, '"', '');	
		SET PARAM_TEXT = REPLACE(PARAM_TEXT, '\\', '');	
		SET PARAM_TEXT = REPLACE(PARAM_TEXT, '|', '');	
		
		SET PARAM_TEXT = REPLACE(PARAM_TEXT, ',', '');
		SET PARAM_TEXT = REPLACE(PARAM_TEXT, '<', '');
		SET PARAM_TEXT = REPLACE(PARAM_TEXT, '.', '');
		SET PARAM_TEXT = REPLACE(PARAM_TEXT, '>', '');
		SET PARAM_TEXT = REPLACE(PARAM_TEXT, '/', '');
		SET PARAM_TEXT = REPLACE(PARAM_TEXT, '?', '');
	
	END IF;
	
	-- RETURN RESULT
	-- ====================================================================
	RETURN PARAM_TEXT;

END ;;
DELIMITER ;
/*!50003 SET sql_mode              = @saved_sql_mode */ ;
/*!50003 SET character_set_client  = @saved_cs_client */ ;
/*!50003 SET character_set_results = @saved_cs_results */ ;
/*!50003 SET collation_connection  = @saved_col_connection */ ;
/*!50003 DROP FUNCTION IF EXISTS `MOBILE_CONTACT@DESCRIPTION_FROM_ID` */;
/*!50003 SET @saved_cs_client      = @@character_set_client */ ;
/*!50003 SET @saved_cs_results     = @@character_set_results */ ;
/*!50003 SET @saved_col_connection = @@collation_connection */ ;
/*!50003 SET character_set_client  = latin1 */ ;
/*!50003 SET character_set_results = latin1 */ ;
/*!50003 SET collation_connection  = latin1_swedish_ci */ ;
/*!50003 SET @saved_sql_mode       = @@sql_mode */ ;
/*!50003 SET sql_mode              = '' */ ;
DELIMITER ;;
CREATE DEFINER=`root`@`localhost` FUNCTION `MOBILE_CONTACT@DESCRIPTION_FROM_ID`(
	PARAM_MOB_CONTACT_ID BIGINT
) RETURNS varchar(16000) CHARSET utf8 COLLATE utf8_unicode_ci
SF_CHECK:
BEGIN

	-- INITIALIZE
	DECLARE TEMP_DESCRIPTION VARCHAR(16000) DEFAULT '';

	
	-- GET DESCRIPTION
	-- ====================================================================
	IF `MOBILE_CONTACT@MOB_CONTACT_ID_EXISTS`(PARAM_MOB_CONTACT_ID, 0) = 1 THEN

		SELECT
			`mobile_contact`.`MOB_CONTACT_DESCRIPTION`
		INTO
			TEMP_DESCRIPTION
		FROM `mobile_contact`
		WHERE
			`mobile_contact`.`MOB_CONTACT_ID` = PARAM_MOB_CONTACT_ID
		LIMIT 1;

	ELSE
		SET TEMP_DESCRIPTION = 'NULL';
	END IF;
	-- ====================================================================

	-- SQL Server requires to return value at the end of the function, even not reachable.
	return TEMP_DESCRIPTION;
END ;;
DELIMITER ;
/*!50003 SET sql_mode              = @saved_sql_mode */ ;
/*!50003 SET character_set_client  = @saved_cs_client */ ;
/*!50003 SET character_set_results = @saved_cs_results */ ;
/*!50003 SET collation_connection  = @saved_col_connection */ ;
/*!50003 DROP FUNCTION IF EXISTS `MOBILE_CONTACT@ID_FROM_DESCRIPTION` */;
/*!50003 SET @saved_cs_client      = @@character_set_client */ ;
/*!50003 SET @saved_cs_results     = @@character_set_results */ ;
/*!50003 SET @saved_col_connection = @@collation_connection */ ;
/*!50003 SET character_set_client  = latin1 */ ;
/*!50003 SET character_set_results = latin1 */ ;
/*!50003 SET collation_connection  = latin1_swedish_ci */ ;
/*!50003 SET @saved_sql_mode       = @@sql_mode */ ;
/*!50003 SET sql_mode              = '' */ ;
DELIMITER ;;
CREATE DEFINER=`root`@`localhost` FUNCTION `MOBILE_CONTACT@ID_FROM_DESCRIPTION`(
	PARAM_MOB_CONTACT_DESCRIPTION VARCHAR(500)
) RETURNS bigint(20)
SF_CHECK:
BEGIN

	-- INITIALIZE
	DECLARE TEMP_ID BIGINT DEFAULT 0;

	
	-- GET DESCRIPTION
	-- ====================================================================
	IF 
		(
			SELECT COUNT(`mobile_contact`.`MOB_CONTACT_ID`)
			FROM `mobile_contact`
			WHERE
				`mobile_contact`.`MOB_CONTACT_DESCRIPTION` = PARAM_MOB_CONTACT_DESCRIPTION
			LIMIT 1
		) >= 1
	THEN

		SELECT
			`mobile_contact`.`MOB_CONTACT_ID`
		INTO
			TEMP_ID
		FROM `mobile_contact`
		WHERE
			`mobile_contact`.`MOB_CONTACT_DESCRIPTION` = PARAM_MOB_CONTACT_DESCRIPTION
		LIMIT 1;

	END IF;
	-- ====================================================================

	-- SQL Server requires to return value at the end of the function, even not reachable.
	return TEMP_ID;
END ;;
DELIMITER ;
/*!50003 SET sql_mode              = @saved_sql_mode */ ;
/*!50003 SET character_set_client  = @saved_cs_client */ ;
/*!50003 SET character_set_results = @saved_cs_results */ ;
/*!50003 SET collation_connection  = @saved_col_connection */ ;
/*!50003 DROP FUNCTION IF EXISTS `MOBILE_CONTACT@MOB_CONTACT_ID_EXISTS` */;
/*!50003 SET @saved_cs_client      = @@character_set_client */ ;
/*!50003 SET @saved_cs_results     = @@character_set_results */ ;
/*!50003 SET @saved_col_connection = @@collation_connection */ ;
/*!50003 SET character_set_client  = latin1 */ ;
/*!50003 SET character_set_results = latin1 */ ;
/*!50003 SET collation_connection  = latin1_swedish_ci */ ;
/*!50003 SET @saved_sql_mode       = @@sql_mode */ ;
/*!50003 SET sql_mode              = '' */ ;
DELIMITER ;;
CREATE DEFINER=`root`@`localhost` FUNCTION `MOBILE_CONTACT@MOB_CONTACT_ID_EXISTS`(
	PARAM_MOB_CONTACT_ID BIGINT,
	DO_NOT_RETURN_INACTIVE_RECORDS BIT
) RETURNS tinyint(1)
SF_CHECK:
BEGIN

	-- STATUS
	-- ========================================================
	DECLARE STATUS_INACTIVE TINYINT DEFAULT 1;
	DECLARE STATUS_ACTIVE TINYINT DEFAULT 2;
	DECLARE STATUS_CLOSED TINYINT DEFAULT 3;
	DECLARE STATUS_COMPLETE TINYINT DEFAULT 4;
	-- ========================================================
	
	IF PARAM_MOB_CONTACT_ID <= 0 THEN
		RETURN 0;
	END IF;

	-- CHECK IF EXISTS
	-- ========================================================
	IF
	(
		SELECT COUNT(`mobile_contact`.`MOB_CONTACT_ID`)
		FROM `mobile_contact`
		WHERE
			`mobile_contact`.`MOB_CONTACT_ID` = PARAM_MOB_CONTACT_ID 
			AND
			(
				DO_NOT_RETURN_INACTIVE_RECORDS = 0 OR
				`mobile_contact`.`MOB_CONTACT_STATUS` = STATUS_ACTIVE
			)
		LIMIT 1
	) >= 1
	THEN
		RETURN 1;

	ELSE 
		RETURN 0;
		
	END IF;
	-- ========================================================


	-- SQL Server requires to return value at the end of the function, even not reachable.
	RETURN 0;
	
END ;;
DELIMITER ;
/*!50003 SET sql_mode              = @saved_sql_mode */ ;
/*!50003 SET character_set_client  = @saved_cs_client */ ;
/*!50003 SET character_set_results = @saved_cs_results */ ;
/*!50003 SET collation_connection  = @saved_col_connection */ ;
/*!50003 DROP FUNCTION IF EXISTS `MOBILE_INBOX@INBOX_ID_EXISTS` */;
/*!50003 SET @saved_cs_client      = @@character_set_client */ ;
/*!50003 SET @saved_cs_results     = @@character_set_results */ ;
/*!50003 SET @saved_col_connection = @@collation_connection */ ;
/*!50003 SET character_set_client  = latin1 */ ;
/*!50003 SET character_set_results = latin1 */ ;
/*!50003 SET collation_connection  = latin1_swedish_ci */ ;
/*!50003 SET @saved_sql_mode       = @@sql_mode */ ;
/*!50003 SET sql_mode              = '' */ ;
DELIMITER ;;
CREATE DEFINER=`root`@`localhost` FUNCTION `MOBILE_INBOX@INBOX_ID_EXISTS`(
	`PARAM_MOB_INBOX_ID` BIGINT,
	DO_NOT_RETURN_INACTIVE_RECORDS BIT
) RETURNS tinyint(1)
SF_CHECK:
BEGIN

	-- STATUS
	-- ========================================================
	DECLARE STATUS_INACTIVE TINYINT DEFAULT 1;
	DECLARE STATUS_ACTIVE TINYINT DEFAULT 2;
	-- ========================================================
	
	IF PARAM_MOB_INBOX_ID <= 0 THEN
		RETURN 0;
	END IF;

	-- CHECK IF EXISTS
	-- ========================================================
	IF
	(
		SELECT COUNT(`mobile_inbox`.`MOB_INBOX_ID`)
		FROM `mobile_inbox`
		WHERE
			`mobile_inbox`.`MOB_INBOX_ID` = PARAM_MOB_INBOX_ID 
			AND
			(
				DO_NOT_RETURN_INACTIVE_RECORDS = 0 OR
				`mobile_inbox`.`MOB_INBOX_STATUS` = STATUS_ACTIVE
			)
		LIMIT 1
	) >= 1
	THEN
		RETURN 1;

	ELSE 
		RETURN 0;
		
	END IF;
	-- ========================================================


	-- SQL Server requires to return value at the end of the function, even not reachable.
	RETURN 0;
	
END ;;
DELIMITER ;
/*!50003 SET sql_mode              = @saved_sql_mode */ ;
/*!50003 SET character_set_client  = @saved_cs_client */ ;
/*!50003 SET character_set_results = @saved_cs_results */ ;
/*!50003 SET collation_connection  = @saved_col_connection */ ;
/*!50003 DROP FUNCTION IF EXISTS `MOBILE_LOADFLOW@ID_FROM_DESCRIPTION` */;
/*!50003 SET @saved_cs_client      = @@character_set_client */ ;
/*!50003 SET @saved_cs_results     = @@character_set_results */ ;
/*!50003 SET @saved_col_connection = @@collation_connection */ ;
/*!50003 SET character_set_client  = latin1 */ ;
/*!50003 SET character_set_results = latin1 */ ;
/*!50003 SET collation_connection  = latin1_swedish_ci */ ;
/*!50003 SET @saved_sql_mode       = @@sql_mode */ ;
/*!50003 SET sql_mode              = '' */ ;
DELIMITER ;;
CREATE DEFINER=`root`@`localhost` FUNCTION `MOBILE_LOADFLOW@ID_FROM_DESCRIPTION`(
	`PARAM_MOB_LOADFLOW_CODE` VARCHAR(500)
) RETURNS bigint(20)
SF_CHECK:
BEGIN

	-- INITIALIZE
	DECLARE TEMP_ID BIGINT DEFAULT 0;

	
	-- GET DESCRIPTION
	-- ====================================================================
	IF 
		(
			SELECT COUNT(`mobile_loadflow`.`MOB_LOADFLOW_ID`)
			FROM `mobile_loadflow`
			WHERE
				`mobile_loadflow`.`MOB_LOADFLOW_CODE` = PARAM_MOB_LOADFLOW_CODE
			LIMIT 1
		) >= 1
	THEN

		SELECT
			`mobile_loadflow`.`MOB_LOADFLOW_ID`
		INTO
			TEMP_ID
		FROM `mobile_loadflow`
		WHERE
			`mobile_loadflow`.`MOB_LOADFLOW_CODE` = PARAM_MOB_LOADFLOW_CODE
		LIMIT 1;

	END IF;
	-- ====================================================================

	-- SQL Server requires to return value at the end of the function, even not reachable.
	return TEMP_ID;
END ;;
DELIMITER ;
/*!50003 SET sql_mode              = @saved_sql_mode */ ;
/*!50003 SET character_set_client  = @saved_cs_client */ ;
/*!50003 SET character_set_results = @saved_cs_results */ ;
/*!50003 SET collation_connection  = @saved_col_connection */ ;
/*!50003 DROP FUNCTION IF EXISTS `MOBILE_LOADFLOW@LOADFLOW_ID_EXISTS` */;
/*!50003 SET @saved_cs_client      = @@character_set_client */ ;
/*!50003 SET @saved_cs_results     = @@character_set_results */ ;
/*!50003 SET @saved_col_connection = @@collation_connection */ ;
/*!50003 SET character_set_client  = latin1 */ ;
/*!50003 SET character_set_results = latin1 */ ;
/*!50003 SET collation_connection  = latin1_swedish_ci */ ;
/*!50003 SET @saved_sql_mode       = @@sql_mode */ ;
/*!50003 SET sql_mode              = '' */ ;
DELIMITER ;;
CREATE DEFINER=`root`@`localhost` FUNCTION `MOBILE_LOADFLOW@LOADFLOW_ID_EXISTS`(
	`PARAM_MOB_LOADFLOW_ID` BIGINT,
	`DO_NOT_RETURN_INACTIVE_RECORDS` BIT
) RETURNS tinyint(1)
SF_CHECK:
BEGIN

	-- STATUS
	-- ========================================================
	DECLARE STATUS_INACTIVE TINYINT DEFAULT 1;
	DECLARE STATUS_ACTIVE TINYINT DEFAULT 2;
	-- ========================================================
	
	IF PARAM_MOB_LOADFLOW_ID <= 0 THEN
		RETURN 0;
	END IF;

	-- CHECK IF EXISTS
	-- ========================================================
	IF
	(
		SELECT COUNT(`mobile_loadflow`.`MOB_LOADFLOW_ID`)
		FROM `mobile_loadflow`
		WHERE
			`mobile_loadflow`.`MOB_LOADFLOW_ID` = PARAM_MOB_LOADFLOW_ID 
			AND
			(
				DO_NOT_RETURN_INACTIVE_RECORDS = 0 OR
				`mobile_loadflow`.`MOB_LOADFLOW_STATUS` = STATUS_ACTIVE
			)
		LIMIT 1
	) >= 1
	THEN
		RETURN 1;

	ELSE 
		RETURN 0;
		
	END IF;
	-- ========================================================


	-- SQL Server requires to return value at the end of the function, even not reachable.
	RETURN 0;
	
END ;;
DELIMITER ;
/*!50003 SET sql_mode              = @saved_sql_mode */ ;
/*!50003 SET character_set_client  = @saved_cs_client */ ;
/*!50003 SET character_set_results = @saved_cs_results */ ;
/*!50003 SET collation_connection  = @saved_col_connection */ ;
/*!50003 DROP FUNCTION IF EXISTS `MOBILE_NOTIFICATION@NRECEIVER_ID_EXISTS` */;
/*!50003 SET @saved_cs_client      = @@character_set_client */ ;
/*!50003 SET @saved_cs_results     = @@character_set_results */ ;
/*!50003 SET @saved_col_connection = @@collation_connection */ ;
/*!50003 SET character_set_client  = latin1 */ ;
/*!50003 SET character_set_results = latin1 */ ;
/*!50003 SET collation_connection  = latin1_swedish_ci */ ;
/*!50003 SET @saved_sql_mode       = @@sql_mode */ ;
/*!50003 SET sql_mode              = '' */ ;
DELIMITER ;;
CREATE DEFINER=`root`@`localhost` FUNCTION `MOBILE_NOTIFICATION@NRECEIVER_ID_EXISTS`(
	`PARAM_MOB_NRECEIVER_ID` BIGINT,
	`DO_NOT_RETURN_INACTIVE_RECORDS` BIT
) RETURNS tinyint(1)
SF_CHECK:
BEGIN

	-- STATUS
	-- ========================================================
	DECLARE STATUS_INACTIVE TINYINT DEFAULT 1;
	DECLARE STATUS_ACTIVE TINYINT DEFAULT 2;
	-- ========================================================
	
	IF PARAM_MOB_NRECEIVER_ID <= 0 THEN
		RETURN 0;
	END IF;

	-- CHECK IF EXISTS
	-- ========================================================
	IF
	(
		SELECT COUNT(`mobile_notification`.`MOB_NRECEIVER_ID`)
		FROM `mobile_notification`
		WHERE
			`mobile_notification`.`MOB_NRECEIVER_ID` = PARAM_MOB_NRECEIVER_ID 
			AND
			(
				DO_NOT_RETURN_INACTIVE_RECORDS = 0 OR
				`mobile_notification`.`MOB_NRECEIVER_STATUS` = STATUS_ACTIVE
			)
		LIMIT 1
	) >= 1
	THEN
		RETURN 1;

	ELSE 
		RETURN 0;
		
	END IF;
	-- ========================================================


	-- SQL Server requires to return value at the end of the function, even not reachable.
	RETURN 0;
	
END ;;
DELIMITER ;
/*!50003 SET sql_mode              = @saved_sql_mode */ ;
/*!50003 SET character_set_client  = @saved_cs_client */ ;
/*!50003 SET character_set_results = @saved_cs_results */ ;
/*!50003 SET collation_connection  = @saved_col_connection */ ;
/*!50003 DROP FUNCTION IF EXISTS `MOBILE_OUTBOX_HISTORY@OUTHISTORY_ID_EXISTS` */;
/*!50003 SET @saved_cs_client      = @@character_set_client */ ;
/*!50003 SET @saved_cs_results     = @@character_set_results */ ;
/*!50003 SET @saved_col_connection = @@collation_connection */ ;
/*!50003 SET character_set_client  = latin1 */ ;
/*!50003 SET character_set_results = latin1 */ ;
/*!50003 SET collation_connection  = latin1_swedish_ci */ ;
/*!50003 SET @saved_sql_mode       = @@sql_mode */ ;
/*!50003 SET sql_mode              = '' */ ;
DELIMITER ;;
CREATE DEFINER=`root`@`localhost` FUNCTION `MOBILE_OUTBOX_HISTORY@OUTHISTORY_ID_EXISTS`(
	`PARAM_MOB_OUTHISTORY_ID` BIGINT,
	`DO_NOT_RETURN_INACTIVE_RECORDS` BIT
) RETURNS tinyint(1)
SF_CHECK:
BEGIN

	-- STATUS
	-- ========================================================
	DECLARE STATUS_INACTIVE TINYINT DEFAULT 1;
	DECLARE STATUS_ACTIVE TINYINT DEFAULT 2;
	-- ========================================================
	
	IF PARAM_MOB_OUTHISTORY_ID <= 0 THEN
		RETURN 0;
	END IF;

	-- CHECK IF EXISTS
	-- ========================================================
	IF
	(
		SELECT COUNT(`mobile_outbox_history`.`MOB_OUTHISTORY_ID`)
		FROM `mobile_outbox_history`
		WHERE
			`mobile_outbox_history`.`MOB_OUTHISTORY_ID` = PARAM_MOB_OUTHISTORY_ID 
			AND
			(
				DO_NOT_RETURN_INACTIVE_RECORDS = 0 OR
				`mobile_outbox_history`.`MOB_OUTHISTORY_STATUS` = STATUS_ACTIVE
			)
		LIMIT 1
	) >= 1
	THEN
		RETURN 1;

	ELSE 
		RETURN 0;
		
	END IF;
	-- ========================================================


	-- SQL Server requires to return value at the end of the function, even not reachable.
	RETURN 0;
	
END ;;
DELIMITER ;
/*!50003 SET sql_mode              = @saved_sql_mode */ ;
/*!50003 SET character_set_client  = @saved_cs_client */ ;
/*!50003 SET character_set_results = @saved_cs_results */ ;
/*!50003 SET collation_connection  = @saved_col_connection */ ;
/*!50003 DROP FUNCTION IF EXISTS `MOBILE_SERVICE_CODE@SCODE_ID_EXISTS` */;
/*!50003 SET @saved_cs_client      = @@character_set_client */ ;
/*!50003 SET @saved_cs_results     = @@character_set_results */ ;
/*!50003 SET @saved_col_connection = @@collation_connection */ ;
/*!50003 SET character_set_client  = latin1 */ ;
/*!50003 SET character_set_results = latin1 */ ;
/*!50003 SET collation_connection  = latin1_swedish_ci */ ;
/*!50003 SET @saved_sql_mode       = @@sql_mode */ ;
/*!50003 SET sql_mode              = '' */ ;
DELIMITER ;;
CREATE DEFINER=`root`@`localhost` FUNCTION `MOBILE_SERVICE_CODE@SCODE_ID_EXISTS`(
	`PARAM_MOB_SCODE_ID` BIGINT,
	`DO_NOT_RETURN_INACTIVE_RECORDS` BIT
) RETURNS tinyint(1)
SF_CHECK:
BEGIN

	-- STATUS
	-- ========================================================
	DECLARE STATUS_INACTIVE TINYINT DEFAULT 1;
	DECLARE STATUS_ACTIVE TINYINT DEFAULT 2;
	-- ========================================================
	
	IF PARAM_MOB_SCODE_ID <= 0 THEN
		RETURN 0;
	END IF;

	-- CHECK IF EXISTS
	-- ========================================================
	IF
	(
		SELECT COUNT(`mobile_service_code`.`MOB_SCODE_ID`)
		FROM `mobile_service_code`
		WHERE
			`mobile_service_code`.`MOB_SCODE_ID` = PARAM_MOB_SCODE_ID 
			AND
			(
				DO_NOT_RETURN_INACTIVE_RECORDS = 0 OR
				`mobile_service_code`.`MOB_SCODE_STATUS` = STATUS_ACTIVE
			)
		LIMIT 1
	) >= 1
	THEN
		RETURN 1;

	ELSE 
		RETURN 0;
		
	END IF;
	-- ========================================================


	-- SQL Server requires to return value at the end of the function, even not reachable.
	RETURN 0;
	
END ;;
DELIMITER ;
/*!50003 SET sql_mode              = @saved_sql_mode */ ;
/*!50003 SET character_set_client  = @saved_cs_client */ ;
/*!50003 SET character_set_results = @saved_cs_results */ ;
/*!50003 SET collation_connection  = @saved_col_connection */ ;
/*!50003 DROP FUNCTION IF EXISTS `MOBILE_SHORTCODE@IS_CODE_EDITABLE` */;
/*!50003 SET @saved_cs_client      = @@character_set_client */ ;
/*!50003 SET @saved_cs_results     = @@character_set_results */ ;
/*!50003 SET @saved_col_connection = @@collation_connection */ ;
/*!50003 SET character_set_client  = latin1 */ ;
/*!50003 SET character_set_results = latin1 */ ;
/*!50003 SET collation_connection  = latin1_swedish_ci */ ;
/*!50003 SET @saved_sql_mode       = @@sql_mode */ ;
/*!50003 SET sql_mode              = '' */ ;
DELIMITER ;;
CREATE DEFINER=`root`@`localhost` FUNCTION `MOBILE_SHORTCODE@IS_CODE_EDITABLE`(
	`PARAM_MOD_SHORTCODE` VARCHAR(500),
	`PARAM_MOB_COMPANY_CODE` VARCHAR(500)
) RETURNS tinyint(1)
SF_CHECK:
BEGIN

	-- STATUS
	-- ========================================================
	DECLARE STATUS_INACTIVE TINYINT DEFAULT 1;
	DECLARE STATUS_ACTIVE TINYINT DEFAULT 2;
	-- ========================================================
	
	
	-- INITIALIZE
	-- ========================================================
	DECLARE ERR INT DEFAULT 0;
	DECLARE LIMIT_COUNT INT DEFAULT 250;
	
	-- HANDLE NULL FLAGS
	-- ========================================================
	SET PARAM_MOB_COMPANY_CODE = `SYSTEM_VAR@REPLACE_NULL@NVARCHAR`(PARAM_MOB_COMPANY_CODE, '', 1);
	
	
	-- CHECK INBOX ITEMS
	-- ========================================================
	IF 
	(
		SELECT
			COUNT(DISTINCT `mobile_inbox`.`MOB_INBOX_ID`)		
		FROM `mobile_inbox`
		WHERE
			`mobile_inbox`.`MOB_INBOX_SHORTCODE` = PARAM_MOD_SHORTCODE AND 	
			`mobile_inbox`.`MOB_INBOX_COMPANY_CODE` = PARAM_MOB_COMPANY_CODE
		LIMIT LIMIT_COUNT
	) >= LIMIT_COUNT
	THEN
		RETURN 0;
	END IF;
	
	
	-- CHECK OUTBOX ITEMS
	-- ========================================================
	IF 
	(
		SELECT
			COUNT(DISTINCT `mobile_outbox`.`MOB_OUTBOX_ID`)		
		FROM `mobile_outbox`
		WHERE
			`mobile_outbox`.`MOB_OUTBOX_SHORTCODE` = PARAM_MOD_SHORTCODE AND 	
			`mobile_outbox`.`MOB_OUTBOX_COMPANY_CODE` = PARAM_MOB_COMPANY_CODE
		LIMIT LIMIT_COUNT
	) >= LIMIT_COUNT
	THEN
		RETURN 0;
	END IF;

	
	-- CHECK SERVICE CODE ITEMS
	-- ========================================================
	IF 
	(
		SELECT
			COUNT(DISTINCT `mobile_service_code`.`MOB_SCODE_ID` )		
		FROM `mobile_service_code`
		WHERE
			`mobile_service_code`.`MOB_SCODE_SHORTCODE` = PARAM_MOD_SHORTCODE AND 	
			`mobile_service_code`.`MOB_SCODE_COMPANY_CODE` = PARAM_MOB_COMPANY_CODE
		LIMIT LIMIT_COUNT
	) >= LIMIT_COUNT
	THEN
		RETURN 0;
	END IF;


	-- IS EDITABLE
	RETURN 1;
	
END ;;
DELIMITER ;
/*!50003 SET sql_mode              = @saved_sql_mode */ ;
/*!50003 SET character_set_client  = @saved_cs_client */ ;
/*!50003 SET character_set_results = @saved_cs_results */ ;
/*!50003 SET collation_connection  = @saved_col_connection */ ;
/*!50003 DROP FUNCTION IF EXISTS `MOBILE_SHORTCODE@MOBILE_ID_EXISTS` */;
/*!50003 SET @saved_cs_client      = @@character_set_client */ ;
/*!50003 SET @saved_cs_results     = @@character_set_results */ ;
/*!50003 SET @saved_col_connection = @@collation_connection */ ;
/*!50003 SET character_set_client  = latin1 */ ;
/*!50003 SET character_set_results = latin1 */ ;
/*!50003 SET collation_connection  = latin1_swedish_ci */ ;
/*!50003 SET @saved_sql_mode       = @@sql_mode */ ;
/*!50003 SET sql_mode              = '' */ ;
DELIMITER ;;
CREATE DEFINER=`root`@`localhost` FUNCTION `MOBILE_SHORTCODE@MOBILE_ID_EXISTS`(
	`PARAM_MOB_MOBILE_ID` BIGINT,
	`DO_NOT_RETURN_INACTIVE_RECORDS` BIT
) RETURNS tinyint(1)
SF_CHECK:
BEGIN

	-- STATUS
	-- ========================================================
	DECLARE STATUS_INACTIVE TINYINT DEFAULT 1;
	DECLARE STATUS_ACTIVE TINYINT DEFAULT 2;
	-- ========================================================
	
	IF PARAM_MOB_MOBILE_ID <= 0 THEN
		RETURN 0;
	END IF;

	-- CHECK IF EXISTS
	-- ========================================================
	IF
	(
		SELECT COUNT(`mobile_shortcode`.`MOB_MOBILE_ID`)
		FROM `mobile_shortcode`
		WHERE
			`mobile_shortcode`.`MOB_MOBILE_ID` = PARAM_MOB_MOBILE_ID 
			AND
			(
				DO_NOT_RETURN_INACTIVE_RECORDS = 0 OR
				`mobile_shortcode`.`MOB_MOBILE_STATUS` = STATUS_ACTIVE
			)
		LIMIT 1
	) >= 1
	THEN
		RETURN 1;

	ELSE 
		RETURN 0;
		
	END IF;
	-- ========================================================


	-- SQL Server requires to return value at the end of the function, even not reachable.
	RETURN 0;
	
END ;;
DELIMITER ;
/*!50003 SET sql_mode              = @saved_sql_mode */ ;
/*!50003 SET character_set_client  = @saved_cs_client */ ;
/*!50003 SET character_set_results = @saved_cs_results */ ;
/*!50003 SET collation_connection  = @saved_col_connection */ ;
/*!50003 DROP FUNCTION IF EXISTS `MOBILE_VOLUME_CONTROL@IS_VOLUME_LIMIT` */;
/*!50003 SET @saved_cs_client      = @@character_set_client */ ;
/*!50003 SET @saved_cs_results     = @@character_set_results */ ;
/*!50003 SET @saved_col_connection = @@collation_connection */ ;
/*!50003 SET character_set_client  = latin1 */ ;
/*!50003 SET character_set_results = latin1 */ ;
/*!50003 SET collation_connection  = latin1_swedish_ci */ ;
/*!50003 SET @saved_sql_mode       = @@sql_mode */ ;
/*!50003 SET sql_mode              = '' */ ;
DELIMITER ;;
CREATE DEFINER=`root`@`localhost` FUNCTION `MOBILE_VOLUME_CONTROL@IS_VOLUME_LIMIT`(
	`PARAM_SHORTCODE` VARCHAR(500),
	`PARAM_COMPANY_CODE` VARCHAR(500),
	`PARAM_SERVICE_CODE` VARCHAR(500),
	`PARAM_MOBILE_NUMBER` VARCHAR(500)
) RETURNS tinyint(1)
SF_CHECK:
BEGIN

	-- STATUS
	-- ========================================================
	DECLARE STATUS_INACTIVE TINYINT DEFAULT 1;
	DECLARE STATUS_ACTIVE TINYINT DEFAULT 2;
	-- ========================================================
	
	
	-- INITIALIZE
	-- ========================================================
	DECLARE ERR INT DEFAULT 0;
	DECLARE TEMP_NOW DATETIME DEFAULT `SYSTEM_VAR@NOW`('', 1);
	DECLARE TEMP_NOW_DATE DATE DEFAULT DATE(TEMP_NOW);
	DECLARE TEMP_NOW_TIME TIME DEFAULT TIME(TEMP_NOW);
	
	DECLARE TEMP_SCODE_ID BIGINT DEFAULT 0;
	DECLARE TEMP_SCODE_FILTER_STATUS TINYINT DEFAULT 0;
	
	DECLARE TEMP_VOLUME_PER_INTERVAL BIGINT DEFAULT 0;
	DECLARE TEMP_VOLUME_COUNT BIGINT DEFAULT 0;
	DECLARE TEMP_VOLUME_CURRENT_INTERVAL_TIME DATETIME DEFAULT '00:00:00';
	DECLARE TEMP_VOLUME_CURRENT_INTERVAL_FOUND TINYINT DEFAULT 0;
	DECLARE TEMP_VOLUME_CURRENT_INTERVAL_BEGIN DATETIME DEFAULT '1000-01-01 00:00:00.000000';
	
	-- HANDLE NULL FLAGS
	-- ========================================================
	SET PARAM_COMPANY_CODE = `SYSTEM_VAR@REPLACE_NULL@NVARCHAR`(PARAM_COMPANY_CODE, '', 1);
	
	-- IGNORE CHECKS FOR RESERVED SERVICE CODE
	-- ========================================================
	IF 
		UCASE(PARAM_SERVICE_CODE) = "ON_ERROR" OR
		UCASE(PARAM_SERVICE_CODE) = "ON_VOLUME_LIMIT" OR
		UCASE(PARAM_SERVICE_CODE) = "ON_SPAM"
	THEN
		RETURN 0;
	END IF;
	
	
	-- FETCH SERVICE CODE
	-- ========================================================
	IF 
	(
		SELECT COUNT(`mobile_service_code`.`MOB_SCODE_ID`)
		FROM `mobile_service_code`
		WHERE
			`mobile_service_code`.`MOB_SCODE_SHORTCODE` = PARAM_SHORTCODE AND
			`mobile_service_code`.`MOB_SCODE_COMPANY_CODE` = PARAM_COMPANY_CODE AND 
			`mobile_service_code`.`MOB_SCODE_CODE` = PARAM_SERVICE_CODE
		LIMIT 1
	) >= 1
	THEN
		SELECT 
			`mobile_service_code`.`MOB_SCODE_ID`,
			`mobile_service_code`.`MOB_SCODE_FILTER_STATUS`, 
			`mobile_service_code`.`MOB_SCODE_FILTER_LIMIT`			
		INTO
			TEMP_SCODE_ID,
			TEMP_SCODE_FILTER_STATUS,
			TEMP_VOLUME_PER_INTERVAL		
		FROM `mobile_service_code`
		WHERE
			`mobile_service_code`.`MOB_SCODE_SHORTCODE` = PARAM_SHORTCODE AND
			`mobile_service_code`.`MOB_SCODE_COMPANY_CODE` = PARAM_COMPANY_CODE AND 
			`mobile_service_code`.`MOB_SCODE_CODE` = PARAM_SERVICE_CODE
		LIMIT 1;
		
	ELSE
	
		-- Service Code not found
		RETURN 0;
	
	END IF;
	
	
	-- VOLUME CONTROL 
	-- ========================================================
	IF TEMP_SCODE_FILTER_STATUS = STATUS_INACTIVE THEN
		RETURN 0;
	END IF;
	

	
	-- FETCH GET CURRENT INTERVAL (LATEST ACTIVE RESET-TIME TODAY)
	-- ========================================================
	SELECT
		TIME(`mobile_volume_control`.`MOB_VOLCONTROL_RESET_TIME`),
		1		
	INTO
		TEMP_VOLUME_CURRENT_INTERVAL_TIME,
		TEMP_VOLUME_CURRENT_INTERVAL_FOUND
		
	FROM `mobile_volume_control`
	WHERE
		`mobile_volume_control`.`MOB_VOLCONTROL_SCODE_ID` = TEMP_SCODE_ID AND
		`mobile_volume_control`.`MOB_VOLCONTROL_STATUS` = STATUS_ACTIVE AND
		TIME(`mobile_volume_control`.`MOB_VOLCONTROL_RESET_TIME`) < TEMP_NOW_TIME
	
	ORDER BY
		TIME(`mobile_volume_control`.`MOB_VOLCONTROL_RESET_TIME`) DESC
		
	LIMIT 1;
	
	
	-- FETCH GET CURRENT INTERVAL (LAST ACTIVE RESET-TIME YESTERDAY)
	-- ========================================================	
	IF TEMP_VOLUME_CURRENT_INTERVAL_FOUND = 0 THEN	
		SELECT
			TIME(`mobile_volume_control`.`MOB_VOLCONTROL_RESET_TIME`),
			2
		INTO
			TEMP_VOLUME_CURRENT_INTERVAL_TIME,
			TEMP_VOLUME_CURRENT_INTERVAL_FOUND
			
		FROM `mobile_volume_control`
		WHERE
			`mobile_volume_control`.`MOB_VOLCONTROL_SCODE_ID` = TEMP_SCODE_ID AND
			`mobile_volume_control`.`MOB_VOLCONTROL_STATUS` = STATUS_ACTIVE
		
		ORDER BY
			TIME(`mobile_volume_control`.`MOB_VOLCONTROL_RESET_TIME`) DESC
			
		LIMIT 1;
	END IF;
	
	
	-- COMPUTE CURRENT INTERVAL BEGIN TIME
	-- ========================================================	
	
	-- TODAY'S INTERVAL
	IF TEMP_VOLUME_CURRENT_INTERVAL_FOUND = 1 THEN
	
		SET TEMP_VOLUME_CURRENT_INTERVAL_BEGIN =				
				ADDTIME
				(
					DATE_FORMAT
					(
						TEMP_NOW_DATE, 
						'%Y-%m-%d %k:%H:%s'
					), 
					DATE_FORMAT
					(
						TEMP_VOLUME_CURRENT_INTERVAL_TIME,
						'%k:%H:%s'
					)		
				);
		
	-- CONTINUES INTERVAL FROM YESTERDAY
	ELSEIF TEMP_VOLUME_CURRENT_INTERVAL_FOUND = 2 THEN
		SET TEMP_NOW_DATE = DATE_SUB(TEMP_NOW_DATE, INTERVAL 1 DAY);
		SET TEMP_VOLUME_CURRENT_INTERVAL_BEGIN = 
				ADDTIME
				(
					DATE_FORMAT
					(
						TEMP_NOW_DATE, 
						'%Y-%m-%d %k:%H:%s'
					), 
					DATE_FORMAT
					(
						TEMP_VOLUME_CURRENT_INTERVAL_TIME,
						'%k:%H:%s'
					)		
				);
		
	-- NO RESET INTERVAL (Do all the time check)
	ELSE
		SET TEMP_VOLUME_CURRENT_INTERVAL_BEGIN = '1000-01-01 00:00:00.000000';
	END IF;
	
	
	IF TEMP_VOLUME_CURRENT_INTERVAL_BEGIN IS NULL THEN
		SET ERR = `RAISERROR`('NULL');
	END IF;
		
	
	-- CHECK IF TEXT EXCEEDS THE LIMIT
	-- ========================================================
	IF
	(
		SELECT COUNT(`mobile_inbox`.`MOB_INBOX_ID`)
		FROM `mobile_inbox`
		WHERE
			`mobile_inbox`.`MOB_INBOX_SHORTCODE` = PARAM_SHORTCODE AND
			`mobile_inbox`.`MOB_INBOX_COMPANY_CODE` = PARAM_COMPANY_CODE AND 
			`mobile_inbox`.`MOB_INBOX_MOBILE_NUMBER` = PARAM_MOBILE_NUMBER AND
			`mobile_inbox`.`MOB_INBOX_SERVICE_CODE` = PARAM_SERVICE_CODE AND
			`mobile_inbox`.`MOB_INBOX_TIMESTAMP` >= TEMP_VOLUME_CURRENT_INTERVAL_BEGIN
		LIMIT 1
	) >= 1
	THEN
	
		SELECT 
			COUNT(`mobile_inbox`.`MOB_INBOX_ID`)
		INTO
			TEMP_VOLUME_COUNT
		FROM `mobile_inbox`
		WHERE
			`mobile_inbox`.`MOB_INBOX_SHORTCODE` = PARAM_SHORTCODE AND
			`mobile_inbox`.`MOB_INBOX_COMPANY_CODE` = PARAM_COMPANY_CODE AND 
			`mobile_inbox`.`MOB_INBOX_MOBILE_NUMBER` = PARAM_MOBILE_NUMBER AND
			`mobile_inbox`.`MOB_INBOX_SERVICE_CODE` = PARAM_SERVICE_CODE AND
			`mobile_inbox`.`MOB_INBOX_TIMESTAMP` >= TEMP_VOLUME_CURRENT_INTERVAL_BEGIN
		LIMIT TEMP_VOLUME_PER_INTERVAL;
	
	END IF;

	
	-- CHECK RESULT
	-- ========================================================
	IF TEMP_VOLUME_PER_INTERVAL > TEMP_VOLUME_COUNT THEN
		RETURN 0;
	ELSE
		RETURN 1;
	END IF;

	-- SQL Server requires to return value at the end of the function, even not reachable.
	RETURN 0;
	
END ;;
DELIMITER ;
/*!50003 SET sql_mode              = @saved_sql_mode */ ;
/*!50003 SET character_set_client  = @saved_cs_client */ ;
/*!50003 SET character_set_results = @saved_cs_results */ ;
/*!50003 SET collation_connection  = @saved_col_connection */ ;
/*!50003 DROP FUNCTION IF EXISTS `MOBILE_VOLUME_CONTROL@VOLCONTROL_ID_EXISTS` */;
/*!50003 SET @saved_cs_client      = @@character_set_client */ ;
/*!50003 SET @saved_cs_results     = @@character_set_results */ ;
/*!50003 SET @saved_col_connection = @@collation_connection */ ;
/*!50003 SET character_set_client  = latin1 */ ;
/*!50003 SET character_set_results = latin1 */ ;
/*!50003 SET collation_connection  = latin1_swedish_ci */ ;
/*!50003 SET @saved_sql_mode       = @@sql_mode */ ;
/*!50003 SET sql_mode              = '' */ ;
DELIMITER ;;
CREATE DEFINER=`root`@`localhost` FUNCTION `MOBILE_VOLUME_CONTROL@VOLCONTROL_ID_EXISTS`(
	`PARAM_MOB_VOLCONTROL_ID` BIGINT,
	`DO_NOT_RETURN_INACTIVE_RECORDS` BIT
) RETURNS tinyint(1)
SF_CHECK:
BEGIN

	-- STATUS
	-- ========================================================
	DECLARE STATUS_INACTIVE TINYINT DEFAULT 1;
	DECLARE STATUS_ACTIVE TINYINT DEFAULT 2;
	-- ========================================================
	
	IF PARAM_MOB_VOLCONTROL_ID <= 0 THEN
		RETURN 0;
	END IF;

	-- CHECK IF EXISTS
	-- ========================================================
	IF
	(
		SELECT COUNT(`mobile_volume_control`.`MOB_VOLCONTROL_ID`)
		FROM `mobile_volume_control`
		WHERE
			`mobile_volume_control`.`MOB_VOLCONTROL_ID` = PARAM_MOB_VOLCONTROL_ID 
			AND
			(
				DO_NOT_RETURN_INACTIVE_RECORDS = 0 OR
				`mobile_volume_control`.`MOB_VOLCONTROL_STATUS` = STATUS_ACTIVE
			)
		LIMIT 1
	) >= 1
	THEN
		RETURN 1;

	ELSE 
		RETURN 0;
		
	END IF;
	-- ========================================================


	-- SQL Server requires to return value at the end of the function, even not reachable.
	RETURN 0;
	
END ;;
DELIMITER ;
/*!50003 SET sql_mode              = @saved_sql_mode */ ;
/*!50003 SET character_set_client  = @saved_cs_client */ ;
/*!50003 SET character_set_results = @saved_cs_results */ ;
/*!50003 SET collation_connection  = @saved_col_connection */ ;
/*!50003 DROP FUNCTION IF EXISTS `RAISERROR` */;
/*!50003 SET @saved_cs_client      = @@character_set_client */ ;
/*!50003 SET @saved_cs_results     = @@character_set_results */ ;
/*!50003 SET @saved_col_connection = @@collation_connection */ ;
/*!50003 SET character_set_client  = latin1 */ ;
/*!50003 SET character_set_results = latin1 */ ;
/*!50003 SET collation_connection  = latin1_swedish_ci */ ;
/*!50003 SET @saved_sql_mode       = @@sql_mode */ ;
/*!50003 SET sql_mode              = '' */ ;
DELIMITER ;;
CREATE DEFINER=`root`@`localhost` FUNCTION `RAISERROR`(
	ERR_MESSAGE VARCHAR(500)
) RETURNS int(11)
SF_CHECK:
BEGIN
    SIGNAL SQLSTATE '45000'
    SET MESSAGE_TEXT = ERR_MESSAGE;
    RETURN 0;
END ;;
DELIMITER ;
/*!50003 SET sql_mode              = @saved_sql_mode */ ;
/*!50003 SET character_set_client  = @saved_cs_client */ ;
/*!50003 SET character_set_results = @saved_cs_results */ ;
/*!50003 SET collation_connection  = @saved_col_connection */ ;
/*!50003 DROP FUNCTION IF EXISTS `RECORD_ATTENDANCE@DESCRIPTION_FROM_ID` */;
/*!50003 SET @saved_cs_client      = @@character_set_client */ ;
/*!50003 SET @saved_cs_results     = @@character_set_results */ ;
/*!50003 SET @saved_col_connection = @@collation_connection */ ;
/*!50003 SET character_set_client  = latin1 */ ;
/*!50003 SET character_set_results = latin1 */ ;
/*!50003 SET collation_connection  = latin1_swedish_ci */ ;
/*!50003 SET @saved_sql_mode       = @@sql_mode */ ;
/*!50003 SET sql_mode              = '' */ ;
DELIMITER ;;
CREATE DEFINER=`root`@`localhost` FUNCTION `RECORD_ATTENDANCE@DESCRIPTION_FROM_ID`(
	PARAM_REC_ATTENDANCE_ID BIGINT
) RETURNS varchar(16000) CHARSET utf8 COLLATE utf8_unicode_ci
SF_CHECK:
BEGIN

	-- INITIALIZE
	DECLARE TEMP_DESCRIPTION VARCHAR(16000) DEFAULT '';

	
	-- GET DESCRIPTION
	-- ====================================================================
	IF `RECORD_ATTENDANCE@REC_ATTENDANCE_ID_EXISTS`(PARAM_REC_ATTENDANCE_ID, 0) = 1 THEN

		SELECT
			`record_attendance`.`REC_ATTENDANCE_DATE`
		INTO
			TEMP_DESCRIPTION
		FROM `record_attendance`
		WHERE
			`record_attendance`.`REC_ATTENDANCE_ID` = PARAM_REC_ATTENDANCE_ID
		LIMIT 1;

	ELSE
		SET TEMP_DESCRIPTION = 'NULL';
	END IF;
	-- ====================================================================

	-- SQL Server requires to return value at the end of the function, even not reachable.
	return TEMP_DESCRIPTION;
END ;;
DELIMITER ;
/*!50003 SET sql_mode              = @saved_sql_mode */ ;
/*!50003 SET character_set_client  = @saved_cs_client */ ;
/*!50003 SET character_set_results = @saved_cs_results */ ;
/*!50003 SET collation_connection  = @saved_col_connection */ ;
/*!50003 DROP FUNCTION IF EXISTS `RECORD_ATTENDANCE@ID_FROM_DESCRIPTION` */;
/*!50003 SET @saved_cs_client      = @@character_set_client */ ;
/*!50003 SET @saved_cs_results     = @@character_set_results */ ;
/*!50003 SET @saved_col_connection = @@collation_connection */ ;
/*!50003 SET character_set_client  = latin1 */ ;
/*!50003 SET character_set_results = latin1 */ ;
/*!50003 SET collation_connection  = latin1_swedish_ci */ ;
/*!50003 SET @saved_sql_mode       = @@sql_mode */ ;
/*!50003 SET sql_mode              = '' */ ;
DELIMITER ;;
CREATE DEFINER=`root`@`localhost` FUNCTION `RECORD_ATTENDANCE@ID_FROM_DESCRIPTION`(
	PARAM_REC_ATTENDANCE_DATE DATETIME(6)
) RETURNS bigint(20)
SF_CHECK:
BEGIN

	-- INITIALIZE
	DECLARE TEMP_ID BIGINT DEFAULT 0;

	
	-- GET DESCRIPTION
	-- ====================================================================
	IF 
		(
			SELECT COUNT(`record_attendance`.`REC_ATTENDANCE_ID`)
			FROM `record_attendance`
			WHERE
				`record_attendance`.`REC_ATTENDANCE_DATE` = PARAM_REC_ATTENDANCE_DATE
			LIMIT 1
		) >= 1
	THEN

		SELECT
			`record_attendance`.`REC_ATTENDANCE_ID`
		INTO
			TEMP_ID
		FROM `record_attendance`
		WHERE
			`record_attendance`.`REC_ATTENDANCE_DATE` = PARAM_REC_ATTENDANCE_DATE
		LIMIT 1;

	END IF;
	-- ====================================================================

	-- SQL Server requires to return value at the end of the function, even not reachable.
	return TEMP_ID;
END ;;
DELIMITER ;
/*!50003 SET sql_mode              = @saved_sql_mode */ ;
/*!50003 SET character_set_client  = @saved_cs_client */ ;
/*!50003 SET character_set_results = @saved_cs_results */ ;
/*!50003 SET collation_connection  = @saved_col_connection */ ;
/*!50003 DROP FUNCTION IF EXISTS `RECORD_ATTENDANCE@REC_ATTENDANCE_ID_EXISTS` */;
/*!50003 SET @saved_cs_client      = @@character_set_client */ ;
/*!50003 SET @saved_cs_results     = @@character_set_results */ ;
/*!50003 SET @saved_col_connection = @@collation_connection */ ;
/*!50003 SET character_set_client  = latin1 */ ;
/*!50003 SET character_set_results = latin1 */ ;
/*!50003 SET collation_connection  = latin1_swedish_ci */ ;
/*!50003 SET @saved_sql_mode       = @@sql_mode */ ;
/*!50003 SET sql_mode              = '' */ ;
DELIMITER ;;
CREATE DEFINER=`root`@`localhost` FUNCTION `RECORD_ATTENDANCE@REC_ATTENDANCE_ID_EXISTS`(
	PARAM_REC_ATTENDANCE_ID BIGINT,
	DO_NOT_RETURN_INACTIVE_RECORDS BIT
) RETURNS tinyint(1)
SF_CHECK:
BEGIN

	-- STATUS
	-- ========================================================
	DECLARE STATUS_INACTIVE TINYINT DEFAULT 1;
	DECLARE STATUS_ACTIVE TINYINT DEFAULT 2;
	DECLARE STATUS_CLOSED TINYINT DEFAULT 3;
	DECLARE STATUS_COMPLETE TINYINT DEFAULT 4;
	-- ========================================================
	
	IF PARAM_REC_ATTENDANCE_ID <= 0 THEN
		RETURN 0;
	END IF;

	-- CHECK IF EXISTS
	-- ========================================================
	IF
	(
		SELECT COUNT(`record_attendance`.`REC_ATTENDANCE_ID`)
		FROM `record_attendance`
		WHERE
			`record_attendance`.`REC_ATTENDANCE_ID` = PARAM_REC_ATTENDANCE_ID 
			AND
			(
				DO_NOT_RETURN_INACTIVE_RECORDS = 0 OR
				`record_attendance`.`REC_ATTENDANCE_STATUS` = STATUS_ACTIVE OR
				`record_attendance`.`REC_ATTENDANCE_STATUS` = STATUS_COMPLETE
			)
		LIMIT 1
	) >= 1
	THEN
		RETURN 1;

	ELSE 
		RETURN 0;
		
	END IF;
	-- ========================================================


	-- SQL Server requires to return value at the end of the function, even not reachable.
	RETURN 0;
	
END ;;
DELIMITER ;
/*!50003 SET sql_mode              = @saved_sql_mode */ ;
/*!50003 SET character_set_client  = @saved_cs_client */ ;
/*!50003 SET character_set_results = @saved_cs_results */ ;
/*!50003 SET collation_connection  = @saved_col_connection */ ;
/*!50003 DROP FUNCTION IF EXISTS `RECORD_DEVICE@DESCRIPTION_FROM_ID` */;
/*!50003 SET @saved_cs_client      = @@character_set_client */ ;
/*!50003 SET @saved_cs_results     = @@character_set_results */ ;
/*!50003 SET @saved_col_connection = @@collation_connection */ ;
/*!50003 SET character_set_client  = latin1 */ ;
/*!50003 SET character_set_results = latin1 */ ;
/*!50003 SET collation_connection  = latin1_swedish_ci */ ;
/*!50003 SET @saved_sql_mode       = @@sql_mode */ ;
/*!50003 SET sql_mode              = '' */ ;
DELIMITER ;;
CREATE DEFINER=`root`@`localhost` FUNCTION `RECORD_DEVICE@DESCRIPTION_FROM_ID`(
	PARAM_REC_DEVICE_ID BIGINT
) RETURNS varchar(16000) CHARSET utf8 COLLATE utf8_unicode_ci
SF_CHECK:
BEGIN

	-- INITIALIZE
	DECLARE TEMP_DESCRIPTION VARCHAR(16000) DEFAULT '';

	
	-- GET DESCRIPTION
	-- ====================================================================
	IF `RECORD_DEVICE@REC_DEVICE_ID_EXISTS`(PARAM_REC_DEVICE_ID, 0) = 1 THEN

		SELECT
			`record_device`.`REC_DEVICE_DESCRIPTION`
		INTO
			TEMP_DESCRIPTION
		FROM `record_device`
		WHERE
			`record_device`.`REC_DEVICE_ID` = PARAM_REC_DEVICE_ID
		LIMIT 1;

	ELSE
		SET TEMP_DESCRIPTION = 'NULL';
	END IF;
	-- ====================================================================

	-- SQL Server requires to return value at the end of the function, even not reachable.
	return TEMP_DESCRIPTION;
END ;;
DELIMITER ;
/*!50003 SET sql_mode              = @saved_sql_mode */ ;
/*!50003 SET character_set_client  = @saved_cs_client */ ;
/*!50003 SET character_set_results = @saved_cs_results */ ;
/*!50003 SET collation_connection  = @saved_col_connection */ ;
/*!50003 DROP FUNCTION IF EXISTS `RECORD_DEVICE@ID_FROM_DESCRIPTION` */;
/*!50003 SET @saved_cs_client      = @@character_set_client */ ;
/*!50003 SET @saved_cs_results     = @@character_set_results */ ;
/*!50003 SET @saved_col_connection = @@collation_connection */ ;
/*!50003 SET character_set_client  = latin1 */ ;
/*!50003 SET character_set_results = latin1 */ ;
/*!50003 SET collation_connection  = latin1_swedish_ci */ ;
/*!50003 SET @saved_sql_mode       = @@sql_mode */ ;
/*!50003 SET sql_mode              = '' */ ;
DELIMITER ;;
CREATE DEFINER=`root`@`localhost` FUNCTION `RECORD_DEVICE@ID_FROM_DESCRIPTION`(
	PARAM_REC_DEVICE_DESCRIPTION VARCHAR(400)
) RETURNS bigint(20)
SF_CHECK:
BEGIN

	-- INITIALIZE
	DECLARE TEMP_ID BIGINT DEFAULT 0;

	
	-- GET DESCRIPTION
	-- ====================================================================
	IF 
		(
			SELECT COUNT(`record_device`.`REC_DEVICE_ID`)
			FROM `record_device`
			WHERE
				`record_device`.`REC_DEVICE_DESCRIPTION` = PARAM_REC_DEVICE_DESCRIPTION
			LIMIT 1
		) >= 1
	THEN

		SELECT
			`record_device`.`REC_DEVICE_ID`
		INTO
			TEMP_ID
		FROM `record_device`
		WHERE
			`record_device`.`REC_DEVICE_DESCRIPTION` = PARAM_REC_DEVICE_DESCRIPTION
		LIMIT 1;

	END IF;
	-- ====================================================================

	-- SQL Server requires to return value at the end of the function, even not reachable.
	return TEMP_ID;
END ;;
DELIMITER ;
/*!50003 SET sql_mode              = @saved_sql_mode */ ;
/*!50003 SET character_set_client  = @saved_cs_client */ ;
/*!50003 SET character_set_results = @saved_cs_results */ ;
/*!50003 SET collation_connection  = @saved_col_connection */ ;
/*!50003 DROP FUNCTION IF EXISTS `RECORD_DEVICE@REC_DEVICE_ID_EXISTS` */;
/*!50003 SET @saved_cs_client      = @@character_set_client */ ;
/*!50003 SET @saved_cs_results     = @@character_set_results */ ;
/*!50003 SET @saved_col_connection = @@collation_connection */ ;
/*!50003 SET character_set_client  = latin1 */ ;
/*!50003 SET character_set_results = latin1 */ ;
/*!50003 SET collation_connection  = latin1_swedish_ci */ ;
/*!50003 SET @saved_sql_mode       = @@sql_mode */ ;
/*!50003 SET sql_mode              = '' */ ;
DELIMITER ;;
CREATE DEFINER=`root`@`localhost` FUNCTION `RECORD_DEVICE@REC_DEVICE_ID_EXISTS`(
	PARAM_REC_DEVICE_ID BIGINT,
	DO_NOT_RETURN_INACTIVE_RECORDS BIT
) RETURNS tinyint(1)
SF_CHECK:
BEGIN

	-- STATUS
	-- ========================================================
	DECLARE STATUS_INACTIVE TINYINT DEFAULT 1;
	DECLARE STATUS_ACTIVE TINYINT DEFAULT 2;
	DECLARE STATUS_CLOSED TINYINT DEFAULT 3;
	DECLARE STATUS_COMPLETE TINYINT DEFAULT 4;
	-- ========================================================
	
	IF PARAM_REC_DEVICE_ID <= 0 THEN
		RETURN 0;
	END IF;

	-- CHECK IF EXISTS
	-- ========================================================
	IF
	(
		SELECT COUNT(`record_device`.`REC_DEVICE_ID`)
		FROM `record_device`
		WHERE
			`record_device`.`REC_DEVICE_ID` = PARAM_REC_DEVICE_ID 
			AND
			(
				DO_NOT_RETURN_INACTIVE_RECORDS = 0 OR
				`record_device`.`REC_DEVICE_STATUS` = STATUS_ACTIVE OR
				`record_device`.`REC_DEVICE_STATUS` = STATUS_COMPLETE
			)
		LIMIT 1
	) >= 1
	THEN
		RETURN 1;

	ELSE 
		RETURN 0;
		
	END IF;
	-- ========================================================


	-- SQL Server requires to return value at the end of the function, even not reachable.
	RETURN 0;
	
END ;;
DELIMITER ;
/*!50003 SET sql_mode              = @saved_sql_mode */ ;
/*!50003 SET character_set_client  = @saved_cs_client */ ;
/*!50003 SET character_set_results = @saved_cs_results */ ;
/*!50003 SET collation_connection  = @saved_col_connection */ ;
/*!50003 DROP FUNCTION IF EXISTS `RECORD_REGISTRATION@DESCRIPTION_FROM_ID` */;
/*!50003 SET @saved_cs_client      = @@character_set_client */ ;
/*!50003 SET @saved_cs_results     = @@character_set_results */ ;
/*!50003 SET @saved_col_connection = @@collation_connection */ ;
/*!50003 SET character_set_client  = latin1 */ ;
/*!50003 SET character_set_results = latin1 */ ;
/*!50003 SET collation_connection  = latin1_swedish_ci */ ;
/*!50003 SET @saved_sql_mode       = @@sql_mode */ ;
/*!50003 SET sql_mode              = '' */ ;
DELIMITER ;;
CREATE DEFINER=`root`@`localhost` FUNCTION `RECORD_REGISTRATION@DESCRIPTION_FROM_ID`(
	PARAM_REC_REGISTRATION_ID BIGINT
) RETURNS varchar(16000) CHARSET utf8 COLLATE utf8_unicode_ci
SF_CHECK:
BEGIN

	-- INITIALIZE
	DECLARE TEMP_DESCRIPTION VARCHAR(16000) DEFAULT '';

	
	-- GET DESCRIPTION
	-- ====================================================================
	IF `RECORD_REGISTRATION@REC_REGISTRATION_ID_EXISTS`(PARAM_REC_REGISTRATION_ID, 0) = 1 THEN

		SELECT
			`record_registration`.`REC_REGISTRATION_LAST_NAME`
		INTO
			TEMP_DESCRIPTION
		FROM `record_registration`
		WHERE
			`record_registration`.`REC_REGISTRATION_ID` = PARAM_REC_REGISTRATION_ID
		LIMIT 1;

	ELSE
		SET TEMP_DESCRIPTION = 'NULL';
	END IF;
	-- ====================================================================

	-- SQL Server requires to return value at the end of the function, even not reachable.
	return TEMP_DESCRIPTION;
END ;;
DELIMITER ;
/*!50003 SET sql_mode              = @saved_sql_mode */ ;
/*!50003 SET character_set_client  = @saved_cs_client */ ;
/*!50003 SET character_set_results = @saved_cs_results */ ;
/*!50003 SET collation_connection  = @saved_col_connection */ ;
/*!50003 DROP FUNCTION IF EXISTS `RECORD_REGISTRATION@ID_FROM_DESCRIPTION` */;
/*!50003 SET @saved_cs_client      = @@character_set_client */ ;
/*!50003 SET @saved_cs_results     = @@character_set_results */ ;
/*!50003 SET @saved_col_connection = @@collation_connection */ ;
/*!50003 SET character_set_client  = latin1 */ ;
/*!50003 SET character_set_results = latin1 */ ;
/*!50003 SET collation_connection  = latin1_swedish_ci */ ;
/*!50003 SET @saved_sql_mode       = @@sql_mode */ ;
/*!50003 SET sql_mode              = '' */ ;
DELIMITER ;;
CREATE DEFINER=`root`@`localhost` FUNCTION `RECORD_REGISTRATION@ID_FROM_DESCRIPTION`(
	PARAM_REC_REGISTRATION_LAST_NAME VARCHAR(400)
) RETURNS bigint(20)
SF_CHECK:
BEGIN

	-- INITIALIZE
	DECLARE TEMP_ID BIGINT DEFAULT 0;

	
	-- GET DESCRIPTION
	-- ====================================================================
	IF 
		(
			SELECT COUNT(`record_registration`.`REC_REGISTRATION_ID`)
			FROM `record_registration`
			WHERE
				`record_registration`.`REC_REGISTRATION_LAST_NAME` = PARAM_REC_REGISTRATION_LAST_NAME
			LIMIT 1
		) >= 1
	THEN

		SELECT
			`record_registration`.`REC_REGISTRATION_ID`
		INTO
			TEMP_ID
		FROM `record_registration`
		WHERE
			`record_registration`.`REC_REGISTRATION_LAST_NAME` = PARAM_REC_REGISTRATION_LAST_NAME
		LIMIT 1;

	END IF;
	-- ====================================================================

	-- SQL Server requires to return value at the end of the function, even not reachable.
	return TEMP_ID;
END ;;
DELIMITER ;
/*!50003 SET sql_mode              = @saved_sql_mode */ ;
/*!50003 SET character_set_client  = @saved_cs_client */ ;
/*!50003 SET character_set_results = @saved_cs_results */ ;
/*!50003 SET collation_connection  = @saved_col_connection */ ;
/*!50003 DROP FUNCTION IF EXISTS `RECORD_REGISTRATION@REC_REGISTRATION_ID_EXISTS` */;
/*!50003 SET @saved_cs_client      = @@character_set_client */ ;
/*!50003 SET @saved_cs_results     = @@character_set_results */ ;
/*!50003 SET @saved_col_connection = @@collation_connection */ ;
/*!50003 SET character_set_client  = latin1 */ ;
/*!50003 SET character_set_results = latin1 */ ;
/*!50003 SET collation_connection  = latin1_swedish_ci */ ;
/*!50003 SET @saved_sql_mode       = @@sql_mode */ ;
/*!50003 SET sql_mode              = '' */ ;
DELIMITER ;;
CREATE DEFINER=`root`@`localhost` FUNCTION `RECORD_REGISTRATION@REC_REGISTRATION_ID_EXISTS`(
	PARAM_REC_REGISTRATION_ID BIGINT,
	DO_NOT_RETURN_INACTIVE_RECORDS BIT
) RETURNS tinyint(1)
SF_CHECK:
BEGIN

	-- STATUS
	-- ========================================================
	DECLARE STATUS_INACTIVE TINYINT DEFAULT 1;
	DECLARE STATUS_ACTIVE TINYINT DEFAULT 2;
	DECLARE STATUS_CLOSED TINYINT DEFAULT 3;
	DECLARE STATUS_COMPLETE TINYINT DEFAULT 4;
	-- ========================================================
	
	IF PARAM_REC_REGISTRATION_ID <= 0 THEN
		RETURN 0;
	END IF;

	-- CHECK IF EXISTS
	-- ========================================================
	IF
	(
		SELECT COUNT(`record_registration`.`REC_REGISTRATION_ID`)
		FROM `record_registration`
		WHERE
			`record_registration`.`REC_REGISTRATION_ID` = PARAM_REC_REGISTRATION_ID 
			AND
			(
				DO_NOT_RETURN_INACTIVE_RECORDS = 0 OR
				`record_registration`.`REC_REGISTRATION_STATUS` = STATUS_ACTIVE OR
				`record_registration`.`REC_REGISTRATION_STATUS` = STATUS_COMPLETE
			)
		LIMIT 1
	) >= 1
	THEN
		RETURN 1;

	ELSE 
		RETURN 0;
		
	END IF;
	-- ========================================================


	-- SQL Server requires to return value at the end of the function, even not reachable.
	RETURN 0;
	
END ;;
DELIMITER ;
/*!50003 SET sql_mode              = @saved_sql_mode */ ;
/*!50003 SET character_set_client  = @saved_cs_client */ ;
/*!50003 SET character_set_results = @saved_cs_results */ ;
/*!50003 SET collation_connection  = @saved_col_connection */ ;
/*!50003 DROP FUNCTION IF EXISTS `RECORD_USER@DESCRIPTION_FROM_ID` */;
/*!50003 SET @saved_cs_client      = @@character_set_client */ ;
/*!50003 SET @saved_cs_results     = @@character_set_results */ ;
/*!50003 SET @saved_col_connection = @@collation_connection */ ;
/*!50003 SET character_set_client  = latin1 */ ;
/*!50003 SET character_set_results = latin1 */ ;
/*!50003 SET collation_connection  = latin1_swedish_ci */ ;
/*!50003 SET @saved_sql_mode       = @@sql_mode */ ;
/*!50003 SET sql_mode              = '' */ ;
DELIMITER ;;
CREATE DEFINER=`root`@`localhost` FUNCTION `RECORD_USER@DESCRIPTION_FROM_ID`(
	PARAM_REC_USER_ID BIGINT
) RETURNS varchar(16000) CHARSET utf8 COLLATE utf8_unicode_ci
SF_CHECK:
BEGIN

	-- INITIALIZE
	DECLARE TEMP_DESCRIPTION VARCHAR(16000) DEFAULT '';

	
	-- GET DESCRIPTION
	-- ====================================================================
	IF `RECORD_USER@REC_USER_ID_EXISTS`(PARAM_REC_USER_ID, 0) = 1 THEN

		SELECT
			`record_user`.`REC_USER_LAST_NAME`
		INTO
			TEMP_DESCRIPTION
		FROM `record_user`
		WHERE
			`record_user`.`REC_USER_ID` = PARAM_REC_USER_ID
		LIMIT 1;

	ELSE
		SET TEMP_DESCRIPTION = 'NULL';
	END IF;
	-- ====================================================================

	-- SQL Server requires to return value at the end of the function, even not reachable.
	return TEMP_DESCRIPTION;
END ;;
DELIMITER ;
/*!50003 SET sql_mode              = @saved_sql_mode */ ;
/*!50003 SET character_set_client  = @saved_cs_client */ ;
/*!50003 SET character_set_results = @saved_cs_results */ ;
/*!50003 SET collation_connection  = @saved_col_connection */ ;
/*!50003 DROP FUNCTION IF EXISTS `RECORD_USER@ID_FROM_DESCRIPTION` */;
/*!50003 SET @saved_cs_client      = @@character_set_client */ ;
/*!50003 SET @saved_cs_results     = @@character_set_results */ ;
/*!50003 SET @saved_col_connection = @@collation_connection */ ;
/*!50003 SET character_set_client  = latin1 */ ;
/*!50003 SET character_set_results = latin1 */ ;
/*!50003 SET collation_connection  = latin1_swedish_ci */ ;
/*!50003 SET @saved_sql_mode       = @@sql_mode */ ;
/*!50003 SET sql_mode              = '' */ ;
DELIMITER ;;
CREATE DEFINER=`root`@`localhost` FUNCTION `RECORD_USER@ID_FROM_DESCRIPTION`(
	PARAM_REC_USER_LAST_NAME VARCHAR(400)
) RETURNS bigint(20)
SF_CHECK:
BEGIN

	-- INITIALIZE
	DECLARE TEMP_ID BIGINT DEFAULT 0;

	
	-- GET DESCRIPTION
	-- ====================================================================
	IF 
		(
			SELECT COUNT(`record_user`.`REC_USER_ID`)
			FROM `record_user`
			WHERE
				`record_user`.`REC_USER_LAST_NAME` = PARAM_REC_USER_LAST_NAME
			LIMIT 1
		) >= 1
	THEN

		SELECT
			`record_user`.`REC_USER_ID`
		INTO
			TEMP_ID
		FROM `record_user`
		WHERE
			`record_user`.`REC_USER_LAST_NAME` = PARAM_REC_USER_LAST_NAME
		LIMIT 1;

	END IF;
	-- ====================================================================

	-- SQL Server requires to return value at the end of the function, even not reachable.
	return TEMP_ID;
END ;;
DELIMITER ;
/*!50003 SET sql_mode              = @saved_sql_mode */ ;
/*!50003 SET character_set_client  = @saved_cs_client */ ;
/*!50003 SET character_set_results = @saved_cs_results */ ;
/*!50003 SET collation_connection  = @saved_col_connection */ ;
/*!50003 DROP FUNCTION IF EXISTS `RECORD_USER@REC_USER_ID_EXISTS` */;
/*!50003 SET @saved_cs_client      = @@character_set_client */ ;
/*!50003 SET @saved_cs_results     = @@character_set_results */ ;
/*!50003 SET @saved_col_connection = @@collation_connection */ ;
/*!50003 SET character_set_client  = latin1 */ ;
/*!50003 SET character_set_results = latin1 */ ;
/*!50003 SET collation_connection  = latin1_swedish_ci */ ;
/*!50003 SET @saved_sql_mode       = @@sql_mode */ ;
/*!50003 SET sql_mode              = '' */ ;
DELIMITER ;;
CREATE DEFINER=`root`@`localhost` FUNCTION `RECORD_USER@REC_USER_ID_EXISTS`(
	PARAM_REC_USER_ID BIGINT,
	DO_NOT_RETURN_INACTIVE_RECORDS BIT
) RETURNS tinyint(1)
SF_CHECK:
BEGIN

	-- STATUS
	-- ========================================================
	DECLARE STATUS_INACTIVE TINYINT DEFAULT 1;
	DECLARE STATUS_ACTIVE TINYINT DEFAULT 2;
	DECLARE STATUS_CLOSED TINYINT DEFAULT 3;
	DECLARE STATUS_COMPLETE TINYINT DEFAULT 4;
	-- ========================================================
	
	IF PARAM_REC_USER_ID <= 0 THEN
		RETURN 0;
	END IF;

	-- CHECK IF EXISTS
	-- ========================================================
	IF
	(
		SELECT COUNT(`record_user`.`REC_USER_ID`)
		FROM `record_user`
		WHERE
			`record_user`.`REC_USER_ID` = PARAM_REC_USER_ID 
			AND
			(
				DO_NOT_RETURN_INACTIVE_RECORDS = 0 OR
				`record_user`.`REC_USER_STATUS` = STATUS_ACTIVE OR
				`record_user`.`REC_USER_STATUS` = STATUS_COMPLETE
			)
		LIMIT 1
	) >= 1
	THEN
		RETURN 1;

	ELSE 
		RETURN 0;
		
	END IF;
	-- ========================================================


	-- SQL Server requires to return value at the end of the function, even not reachable.
	RETURN 0;
	
END ;;
DELIMITER ;
/*!50003 SET sql_mode              = @saved_sql_mode */ ;
/*!50003 SET character_set_client  = @saved_cs_client */ ;
/*!50003 SET character_set_results = @saved_cs_results */ ;
/*!50003 SET collation_connection  = @saved_col_connection */ ;
/*!50003 DROP FUNCTION IF EXISTS `SYSTEM_ACCESS_RIGHTS_AUTHORITY@SYS_AUTHORITY_DESCRIPTION_FROM_ID` */;
/*!50003 SET @saved_cs_client      = @@character_set_client */ ;
/*!50003 SET @saved_cs_results     = @@character_set_results */ ;
/*!50003 SET @saved_col_connection = @@collation_connection */ ;
/*!50003 SET character_set_client  = latin1 */ ;
/*!50003 SET character_set_results = latin1 */ ;
/*!50003 SET collation_connection  = latin1_swedish_ci */ ;
/*!50003 SET @saved_sql_mode       = @@sql_mode */ ;
/*!50003 SET sql_mode              = '' */ ;
DELIMITER ;;
CREATE DEFINER=`root`@`localhost` FUNCTION `SYSTEM_ACCESS_RIGHTS_AUTHORITY@SYS_AUTHORITY_DESCRIPTION_FROM_ID`(
	`PARAM_SYS_AUTHORITY_ID` BIGINT
) RETURNS varchar(500) CHARSET utf8 COLLATE utf8_unicode_ci
SF_CHECK:
BEGIN

	DECLARE TEMP_SYS_AUTHORITY_DESCRIPTION NVARCHAR(500) DEFAULT '';

	-- RETRIEVE OFFICE TYPE DESCRIPTION
	-- ===================================================================
	IF `SYSTEM_ACCESS_RIGHTS_AUTHORITY@SYS_AUTHORITY_ID_EXISTS`(PARAM_SYS_AUTHORITY_ID, 0) = 1 THEN
		SELECT
			`system_access_rights_authority`.`SYS_AUTHORITY_DESCRIPTION`
		INTO
			TEMP_SYS_AUTHORITY_DESCRIPTION
		FROM `system_access_rights_authority`
		WHERE
			`system_access_rights_authority`.`SYS_AUTHORITY_ID` = PARAM_SYS_AUTHORITY_ID
		LIMIT 1;
	END IF;
	-- ===================================================================


	-- SQL Server requires to return value at the end of the function, even not reachable.
	return TEMP_SYS_AUTHORITY_DESCRIPTION;

END ;;
DELIMITER ;
/*!50003 SET sql_mode              = @saved_sql_mode */ ;
/*!50003 SET character_set_client  = @saved_cs_client */ ;
/*!50003 SET character_set_results = @saved_cs_results */ ;
/*!50003 SET collation_connection  = @saved_col_connection */ ;
/*!50003 DROP FUNCTION IF EXISTS `SYSTEM_ACCESS_RIGHTS_AUTHORITY@SYS_AUTHORITY_ID_EXISTS` */;
/*!50003 SET @saved_cs_client      = @@character_set_client */ ;
/*!50003 SET @saved_cs_results     = @@character_set_results */ ;
/*!50003 SET @saved_col_connection = @@collation_connection */ ;
/*!50003 SET character_set_client  = latin1 */ ;
/*!50003 SET character_set_results = latin1 */ ;
/*!50003 SET collation_connection  = latin1_swedish_ci */ ;
/*!50003 SET @saved_sql_mode       = @@sql_mode */ ;
/*!50003 SET sql_mode              = '' */ ;
DELIMITER ;;
CREATE DEFINER=`root`@`localhost` FUNCTION `SYSTEM_ACCESS_RIGHTS_AUTHORITY@SYS_AUTHORITY_ID_EXISTS`(
	`PARAM_SYS_AUTHORITY_ID` BIGINT,
	`DO_NOT_RETURN_INACTIVE_RECORDS` BIT
) RETURNS tinyint(1)
SF_CHECK:
BEGIN

	-- STATUS
	-- ========================================================
	DECLARE STATUS_INACTIVE TINYINT DEFAULT 1;
	DECLARE STATUS_ACTIVE TINYINT DEFAULT 2;
	-- ========================================================


	-- CHECK IF EXISTS
	-- ========================================================
	IF
	(
		SELECT COUNT(`system_access_rights_authority`.`SYS_AUTHORITY_ID`)
		FROM `system_access_rights_authority`
		WHERE
			`system_access_rights_authority`.`SYS_AUTHORITY_ID` = PARAM_SYS_AUTHORITY_ID
		LIMIT 1
	) >= 1
	THEN
		return 1;
	ELSE
		return 0;
	END IF;
	-- ========================================================

	-- SQL Server requires to return value at the end of the function, even not reachable.
	return 0;

END ;;
DELIMITER ;
/*!50003 SET sql_mode              = @saved_sql_mode */ ;
/*!50003 SET character_set_client  = @saved_cs_client */ ;
/*!50003 SET character_set_results = @saved_cs_results */ ;
/*!50003 SET collation_connection  = @saved_col_connection */ ;
/*!50003 DROP FUNCTION IF EXISTS `SYSTEM_BLOOD_TYPE@SYS_BLOODTYPE_CODE_FROM_ID` */;
/*!50003 SET @saved_cs_client      = @@character_set_client */ ;
/*!50003 SET @saved_cs_results     = @@character_set_results */ ;
/*!50003 SET @saved_col_connection = @@collation_connection */ ;
/*!50003 SET character_set_client  = latin1 */ ;
/*!50003 SET character_set_results = latin1 */ ;
/*!50003 SET collation_connection  = latin1_swedish_ci */ ;
/*!50003 SET @saved_sql_mode       = @@sql_mode */ ;
/*!50003 SET sql_mode              = '' */ ;
DELIMITER ;;
CREATE DEFINER=`root`@`localhost` FUNCTION `SYSTEM_BLOOD_TYPE@SYS_BLOODTYPE_CODE_FROM_ID`(
	PARAM_SYS_BLOODTYPE_ID TINYINT
) RETURNS varchar(500) CHARSET utf8 COLLATE utf8_unicode_ci
SF_CHECK:
BEGIN

	-- Initialize
	-- .........................................................
	DECLARE TEMP_SYS_BLOODTYPE_CODE VARCHAR(500) DEFAULT '';


	-- GET STATUS TYPE
	-- .........................................................
	IF `SYSTEM_BLOOD_TYPE@SYS_BLOODTYPE_ID_EXISTS`(PARAM_SYS_BLOODTYPE_ID, 0) = 1 THEN

		SELECT
			`system_blood_type`.`SYS_BLOODTYPE_CODE`
		INTO
			TEMP_SYS_BLOODTYPE_CODE
		FROM `system_blood_type`
		WHERE
			`system_blood_type`.`SYS_BLOODTYPE_ID` = PARAM_SYS_BLOODTYPE_ID
		LIMIT 1;
			
	ELSE
		SET TEMP_SYS_BLOODTYPE_CODE = 'NULL';
		
	END IF;


	-- SQL Server requires to return value at the end of the function, even not reachable.
	-- .........................................................
	RETURN TEMP_SYS_BLOODTYPE_CODE;

END ;;
DELIMITER ;
/*!50003 SET sql_mode              = @saved_sql_mode */ ;
/*!50003 SET character_set_client  = @saved_cs_client */ ;
/*!50003 SET character_set_results = @saved_cs_results */ ;
/*!50003 SET collation_connection  = @saved_col_connection */ ;
/*!50003 DROP FUNCTION IF EXISTS `SYSTEM_BLOOD_TYPE@SYS_BLOODTYPE_ID_EXISTS` */;
/*!50003 SET @saved_cs_client      = @@character_set_client */ ;
/*!50003 SET @saved_cs_results     = @@character_set_results */ ;
/*!50003 SET @saved_col_connection = @@collation_connection */ ;
/*!50003 SET character_set_client  = latin1 */ ;
/*!50003 SET character_set_results = latin1 */ ;
/*!50003 SET collation_connection  = latin1_swedish_ci */ ;
/*!50003 SET @saved_sql_mode       = @@sql_mode */ ;
/*!50003 SET sql_mode              = '' */ ;
DELIMITER ;;
CREATE DEFINER=`root`@`localhost` FUNCTION `SYSTEM_BLOOD_TYPE@SYS_BLOODTYPE_ID_EXISTS`(
	PARAM_SYS_BLOODTYPE_ID BIGINT,
	DO_NOT_RETURN_INACTIVE_RECORDS BIT
) RETURNS tinyint(1)
SF_CHECK:
BEGIN

	-- STATUS
	-- ========================================================
	DECLARE STATUS_INACTIVE TINYINT DEFAULT 1;
	DECLARE STATUS_ACTIVE TINYINT DEFAULT 2;
	-- ========================================================
	
	IF PARAM_SYS_BLOODTYPE_ID <= 0 THEN
		RETURN 0;
	END IF;

	-- CHECK IF EXISTS
	-- ========================================================
	IF
	(
		SELECT COUNT(`system_blood_type`.`SYS_BLOODTYPE_ID`)
		FROM `system_blood_type`
		WHERE
			`system_blood_type`.`SYS_BLOODTYPE_ID` = PARAM_SYS_BLOODTYPE_ID 
			AND
			(
				DO_NOT_RETURN_INACTIVE_RECORDS = 0 OR
				`system_blood_type`.`SYS_BLOODTYPE_STATUS` = STATUS_ACTIVE
			)
		LIMIT 1
	) >= 1
	THEN
		RETURN 1;

	ELSE 
		RETURN 0;
		
	END IF;
	-- ========================================================


	-- SQL Server requires to return value at the end of the function, even not reachable.
	RETURN 0;
	
END ;;
DELIMITER ;
/*!50003 SET sql_mode              = @saved_sql_mode */ ;
/*!50003 SET character_set_client  = @saved_cs_client */ ;
/*!50003 SET character_set_results = @saved_cs_results */ ;
/*!50003 SET collation_connection  = @saved_col_connection */ ;
/*!50003 DROP FUNCTION IF EXISTS `SYSTEM_CIVIL_STATUS@SYS_CIVIL_DESCRIPTION_FROM_ID` */;
/*!50003 SET @saved_cs_client      = @@character_set_client */ ;
/*!50003 SET @saved_cs_results     = @@character_set_results */ ;
/*!50003 SET @saved_col_connection = @@collation_connection */ ;
/*!50003 SET character_set_client  = latin1 */ ;
/*!50003 SET character_set_results = latin1 */ ;
/*!50003 SET collation_connection  = latin1_swedish_ci */ ;
/*!50003 SET @saved_sql_mode       = @@sql_mode */ ;
/*!50003 SET sql_mode              = '' */ ;
DELIMITER ;;
CREATE DEFINER=`root`@`localhost` FUNCTION `SYSTEM_CIVIL_STATUS@SYS_CIVIL_DESCRIPTION_FROM_ID`(
	`PARAM_SYS_CIVIL_ID` TINYINT
) RETURNS tinyint(1)
SF_CHECK:
BEGIN

	-- STATUS
	-- ========================================================
	DECLARE STATUS_INACTIVE TINYINT DEFAULT 1;
	DECLARE STATUS_ACTIVE TINYINT DEFAULT 2;
	
	DECLARE TEMP_SYS_CIVIL_DESCRIPTION VARCHAR(500) DEFAULT '';
	-- ========================================================


	-- CHECK IF EXISTS
	-- ========================================================
	IF `SYSTEM_CIVIL_STATUS@SYS_CIVIL_ID_EXISTS`(PARAM_SYS_CIVIL_ID, 0) = 1 THEN
	
		SELECT
			`system_civil_status`.`SYS_CIVIL_DESCRIPTION`
		INTO
			TEMP_SYS_CIVIL_DESCRIPTION
		FROM `system_civil_status`
		WHERE
			`system_civil_status`.`SYS_CIVIL_ID` = PARAM_SYS_CIVIL_ID
		LIMIT 1;
		
	END IF;
	-- ========================================================


	-- SQL Server requires to return value at the end of the function, even not reachable.
	return TEMP_SYS_CIVIL_DESCRIPTION;
	
END ;;
DELIMITER ;
/*!50003 SET sql_mode              = @saved_sql_mode */ ;
/*!50003 SET character_set_client  = @saved_cs_client */ ;
/*!50003 SET character_set_results = @saved_cs_results */ ;
/*!50003 SET collation_connection  = @saved_col_connection */ ;
/*!50003 DROP FUNCTION IF EXISTS `SYSTEM_CIVIL_STATUS@SYS_CIVIL_ID_EXISTS` */;
/*!50003 SET @saved_cs_client      = @@character_set_client */ ;
/*!50003 SET @saved_cs_results     = @@character_set_results */ ;
/*!50003 SET @saved_col_connection = @@collation_connection */ ;
/*!50003 SET character_set_client  = latin1 */ ;
/*!50003 SET character_set_results = latin1 */ ;
/*!50003 SET collation_connection  = latin1_swedish_ci */ ;
/*!50003 SET @saved_sql_mode       = @@sql_mode */ ;
/*!50003 SET sql_mode              = '' */ ;
DELIMITER ;;
CREATE DEFINER=`root`@`localhost` FUNCTION `SYSTEM_CIVIL_STATUS@SYS_CIVIL_ID_EXISTS`(
	`PARAM_SYS_CIVIL_ID` BIGINT,
	`DO_NOT_RETURN_INACTIVE_RECORDS` BIT
) RETURNS tinyint(1)
SF_CHECK:
BEGIN

	-- STATUS
	-- ========================================================
	DECLARE STATUS_INACTIVE TINYINT DEFAULT 1;
	DECLARE STATUS_ACTIVE TINYINT DEFAULT 2;
	-- ========================================================

	IF PARAM_SYS_CIVIL_ID <= 0 THEN
		RETURN 0;
	END IF;

	-- CHECK IF EXISTS
	-- ========================================================
	IF
	(
		SELECT COUNT(`system_civil_status`.`SYS_CIVIL_ID`)
		FROM `system_civil_status`
		WHERE
			`system_civil_status`.`SYS_CIVIL_ID` = PARAM_SYS_CIVIL_ID AND
			(
				DO_NOT_RETURN_INACTIVE_RECORDS = 0 OR
				`system_civil_status`.`SYS_CIVIL_STATUS` = STATUS_ACTIVE
			)
		LIMIT 1
	) >= 1
	THEN
		return 1;
	ELSE
		return 0;
	END IF;
	-- ========================================================


	-- SQL Server requires to return value at the end of the function, even not reachable.
	return 0;
	
END ;;
DELIMITER ;
/*!50003 SET sql_mode              = @saved_sql_mode */ ;
/*!50003 SET character_set_client  = @saved_cs_client */ ;
/*!50003 SET character_set_results = @saved_cs_results */ ;
/*!50003 SET collation_connection  = @saved_col_connection */ ;
/*!50003 DROP FUNCTION IF EXISTS `SYSTEM_GENDER@SYS_GENDER_DESCRIPTION_FROM_ID` */;
/*!50003 SET @saved_cs_client      = @@character_set_client */ ;
/*!50003 SET @saved_cs_results     = @@character_set_results */ ;
/*!50003 SET @saved_col_connection = @@collation_connection */ ;
/*!50003 SET character_set_client  = latin1 */ ;
/*!50003 SET character_set_results = latin1 */ ;
/*!50003 SET collation_connection  = latin1_swedish_ci */ ;
/*!50003 SET @saved_sql_mode       = @@sql_mode */ ;
/*!50003 SET sql_mode              = '' */ ;
DELIMITER ;;
CREATE DEFINER=`root`@`localhost` FUNCTION `SYSTEM_GENDER@SYS_GENDER_DESCRIPTION_FROM_ID`(
	`PARAM_SYS_GENDER_ID` TINYINT
) RETURNS tinyint(1)
SF_CHECK:
BEGIN

	-- STATUS
	-- ========================================================
	DECLARE STATUS_INACTIVE TINYINT DEFAULT 1;
	DECLARE STATUS_ACTIVE TINYINT DEFAULT 2;
	
	DECLARE TEMP_SYS_GENDER_DESCRIPTION VARCHAR(500) DEFAULT '';
	-- ========================================================


	-- CHECK IF EXISTS
	-- ========================================================
	IF
	(
		SELECT COUNT(`system_gender`.`SYS_GENDER_ID`)
		FROM `system_gender`
		WHERE
			`system_gender`.`SYS_GENDER_ID` = PARAM_SYS_GENDER_ID
		LIMIT 1
	) >= 1
	THEN
	
	
		SELECT
			`system_gender`.`SYS_GENDER_DESCRIPTION`
		INTO
			TEMP_SYS_GENDER_DESCRIPTION
		FROM `system_gender`
		WHERE
			`system_gender`.`SYS_GENDER_ID` = PARAM_SYS_GENDER_ID
		LIMIT 1;
		
	END IF;
	-- ========================================================


	-- SQL Server requires to return value at the end of the function, even not reachable.
	return TEMP_SYS_GENDER_DESCRIPTION;
	
END ;;
DELIMITER ;
/*!50003 SET sql_mode              = @saved_sql_mode */ ;
/*!50003 SET character_set_client  = @saved_cs_client */ ;
/*!50003 SET character_set_results = @saved_cs_results */ ;
/*!50003 SET collation_connection  = @saved_col_connection */ ;
/*!50003 DROP FUNCTION IF EXISTS `SYSTEM_GENDER@SYS_GENDER_ID_EXISTS` */;
/*!50003 SET @saved_cs_client      = @@character_set_client */ ;
/*!50003 SET @saved_cs_results     = @@character_set_results */ ;
/*!50003 SET @saved_col_connection = @@collation_connection */ ;
/*!50003 SET character_set_client  = latin1 */ ;
/*!50003 SET character_set_results = latin1 */ ;
/*!50003 SET collation_connection  = latin1_swedish_ci */ ;
/*!50003 SET @saved_sql_mode       = @@sql_mode */ ;
/*!50003 SET sql_mode              = '' */ ;
DELIMITER ;;
CREATE DEFINER=`root`@`localhost` FUNCTION `SYSTEM_GENDER@SYS_GENDER_ID_EXISTS`(
	`PARAM_SYS_GENDER_ID` TINYINT,
	`DO_NOT_RETURN_INACTIVE_RECORDS` BIT
) RETURNS tinyint(1)
SF_CHECK:
BEGIN

	-- STATUS
	-- ========================================================
	DECLARE STATUS_INACTIVE TINYINT DEFAULT 1;
	DECLARE STATUS_ACTIVE TINYINT DEFAULT 2;
	-- ========================================================


	-- CHECK IF EXISTS
	-- ========================================================
	IF
	(
		SELECT COUNT(`system_gender`.`SYS_GENDER_ID`)
		FROM `system_gender`
		WHERE
			`system_gender`.`SYS_GENDER_ID` = PARAM_SYS_GENDER_ID AND
			(
				DO_NOT_RETURN_INACTIVE_RECORDS = 0 OR
				`system_gender`.`SYS_GENDER_STATUS` = STATUS_ACTIVE
			)
	) >= 1
	THEN
		return 1;
	ELSE
		return 0;
	END IF;
	-- ========================================================


	-- SQL Server requires to return value at the end of the function, even not reachable.
	return 0;
	
END ;;
DELIMITER ;
/*!50003 SET sql_mode              = @saved_sql_mode */ ;
/*!50003 SET character_set_client  = @saved_cs_client */ ;
/*!50003 SET character_set_results = @saved_cs_results */ ;
/*!50003 SET collation_connection  = @saved_col_connection */ ;
/*!50003 DROP FUNCTION IF EXISTS `SYSTEM_MODULE@SYS_MODULE_ID_EXISTS` */;
/*!50003 SET @saved_cs_client      = @@character_set_client */ ;
/*!50003 SET @saved_cs_results     = @@character_set_results */ ;
/*!50003 SET @saved_col_connection = @@collation_connection */ ;
/*!50003 SET character_set_client  = latin1 */ ;
/*!50003 SET character_set_results = latin1 */ ;
/*!50003 SET collation_connection  = latin1_swedish_ci */ ;
/*!50003 SET @saved_sql_mode       = @@sql_mode */ ;
/*!50003 SET sql_mode              = '' */ ;
DELIMITER ;;
CREATE DEFINER=`root`@`localhost` FUNCTION `SYSTEM_MODULE@SYS_MODULE_ID_EXISTS`(
	`PARAM_SYS_MODULE_ID` BIGINT,
	`DO_NOT_RETURN_INACTIVE_RECORDS` BIT
) RETURNS tinyint(1)
SF_CHECK:
BEGIN

	-- STATUS
	-- ========================================================
	DECLARE STATUS_INACTIVE TINYINT DEFAULT 1;
	DECLARE STATUS_ACTIVE TINYINT DEFAULT 2;
	-- ========================================================


	-- CHECK IF EXISTS
	-- ========================================================
	IF
	(
		SELECT COUNT(`system_module`.`SYS_MODULE_ID`)
		FROM `system_module`
		WHERE
			`system_module`.`SYS_MODULE_ID` = PARAM_SYS_MODULE_ID AND
			(
				DO_NOT_RETURN_INACTIVE_RECORDS = 0 OR
				`system_module`.`SYS_MODULE_STATUS` = STATUS_ACTIVE
			)
	) >= 1
	THEN
		return 1;
	ELSE
		return 0;
	END IF;
	-- ========================================================

	-- SQL Server requires to return value at the end of the function, even not reachable.
	return 0;
	
END ;;
DELIMITER ;
/*!50003 SET sql_mode              = @saved_sql_mode */ ;
/*!50003 SET character_set_client  = @saved_cs_client */ ;
/*!50003 SET character_set_results = @saved_cs_results */ ;
/*!50003 SET collation_connection  = @saved_col_connection */ ;
/*!50003 DROP FUNCTION IF EXISTS `SYSTEM_MODULE@SYS_MODULE_ID_FROM_KEYWORD` */;
/*!50003 SET @saved_cs_client      = @@character_set_client */ ;
/*!50003 SET @saved_cs_results     = @@character_set_results */ ;
/*!50003 SET @saved_col_connection = @@collation_connection */ ;
/*!50003 SET character_set_client  = latin1 */ ;
/*!50003 SET character_set_results = latin1 */ ;
/*!50003 SET collation_connection  = latin1_swedish_ci */ ;
/*!50003 SET @saved_sql_mode       = @@sql_mode */ ;
/*!50003 SET sql_mode              = '' */ ;
DELIMITER ;;
CREATE DEFINER=`root`@`localhost` FUNCTION `SYSTEM_MODULE@SYS_MODULE_ID_FROM_KEYWORD`(
	`PARAM_SYS_MODULE_KEYWORD` VARCHAR(500)
) RETURNS bigint(20)
SF_CHECK:
BEGIN

	DECLARE PARAM_SYS_MODULE_ID BIGINT DEFAULT 0;
	
	-- =================================================
	-- RETRIEVE MODULE_ID FROM MODULE_KEYWORD
	-- =================================================
	IF
	(
		SELECT COUNT(`system_module`.`SYS_MODULE_KEYWORD`)
		FROM `system_module`
		WHERE
			`system_module`.`SYS_MODULE_KEYWORD` = PARAM_SYS_MODULE_KEYWORD
		LIMIT 1
	) <= 0
	THEN
		RETURN 0;

	ELSE
		SELECT 
			`system_module`.`SYS_MODULE_ID` INTO PARAM_SYS_MODULE_ID
		FROM `system_module`
		WHERE
			`system_module`.`SYS_MODULE_KEYWORD` = PARAM_SYS_MODULE_KEYWORD
		LIMIT 1;

		RETURN PARAM_SYS_MODULE_ID;
	END IF;

	RETURN 0;
	
END ;;
DELIMITER ;
/*!50003 SET sql_mode              = @saved_sql_mode */ ;
/*!50003 SET character_set_client  = @saved_cs_client */ ;
/*!50003 SET character_set_results = @saved_cs_results */ ;
/*!50003 SET collation_connection  = @saved_col_connection */ ;
/*!50003 DROP FUNCTION IF EXISTS `SYSTEM_MODULE@SYS_MODULE_KEYWORD_FROM_MODULE_ID` */;
/*!50003 SET @saved_cs_client      = @@character_set_client */ ;
/*!50003 SET @saved_cs_results     = @@character_set_results */ ;
/*!50003 SET @saved_col_connection = @@collation_connection */ ;
/*!50003 SET character_set_client  = latin1 */ ;
/*!50003 SET character_set_results = latin1 */ ;
/*!50003 SET collation_connection  = latin1_swedish_ci */ ;
/*!50003 SET @saved_sql_mode       = @@sql_mode */ ;
/*!50003 SET sql_mode              = '' */ ;
DELIMITER ;;
CREATE DEFINER=`root`@`localhost` FUNCTION `SYSTEM_MODULE@SYS_MODULE_KEYWORD_FROM_MODULE_ID`(
	PARAM_SYS_MODULE_ID BIGINT
) RETURNS bigint(20)
SF_CHECK:
BEGIN

	-- Initialize
	-- .........................................................
	DECLARE PARAM_SYS_MODULE_KEYWORD VARCHAR(500) DEFAULT '';


	-- Check if module exists
	-- .........................................................
	IF `SYSTEM_MODULE@SYS_MODULE_ID_EXISTS`(PARAM_SYS_MODULE_ID, 0) = 0 THEN
		SET PARAM_SYS_MODULE_KEYWORD = 'NULL';

	ELSE
		-- Get Module Keyword
		SELECT
			`system_module`.`SYS_MODULE_KEYWORD`
		INTO
			PARAM_SYS_MODULE_KEYWORD
		FROM `system_module`
		WHERE
			`system_module`.`SYS_MODULE_ID` = PARAM_SYS_MODULE_ID
		LIMIT 1;
		
	END IF;

	-- Return Result
	return PARAM_SYS_MODULE_KEYWORD;

END ;;
DELIMITER ;
/*!50003 SET sql_mode              = @saved_sql_mode */ ;
/*!50003 SET character_set_client  = @saved_cs_client */ ;
/*!50003 SET character_set_results = @saved_cs_results */ ;
/*!50003 SET collation_connection  = @saved_col_connection */ ;
/*!50003 DROP FUNCTION IF EXISTS `SYSTEM_MODULE@SYS_MODULE_NAME_FROM_ID` */;
/*!50003 SET @saved_cs_client      = @@character_set_client */ ;
/*!50003 SET @saved_cs_results     = @@character_set_results */ ;
/*!50003 SET @saved_col_connection = @@collation_connection */ ;
/*!50003 SET character_set_client  = latin1 */ ;
/*!50003 SET character_set_results = latin1 */ ;
/*!50003 SET collation_connection  = latin1_swedish_ci */ ;
/*!50003 SET @saved_sql_mode       = @@sql_mode */ ;
/*!50003 SET sql_mode              = '' */ ;
DELIMITER ;;
CREATE DEFINER=`root`@`localhost` FUNCTION `SYSTEM_MODULE@SYS_MODULE_NAME_FROM_ID`(
	`PARAM_SYS_MODULE_ID` BIGINT
) RETURNS varchar(500) CHARSET utf8 COLLATE utf8_unicode_ci
SF_CHECK:
BEGIN

	DECLARE PARAM_SYS_MODULE_NAME VARCHAR(500) DEFAULT '';

	-- Check if module exists
	IF `SYSTEM_MODULE@SYS_MODULE_ID_EXISTS`(PARAM_SYS_MODULE_ID, 0) = 1 THEN
		-- Get Module Keyword
		SELECT
			`system_module`.`SYS_MODULE_NAME`
		INTO
			PARAM_SYS_MODULE_NAME
		FROM `system_module`
		WHERE
			`system_module`.`SYS_MODULE_ID` = PARAM_SYS_MODULE_ID
		LIMIT 1;
	END IF;

	-- SQL Server requires to return value at the end of the function, even not reachable.
	return PARAM_SYS_MODULE_NAME;
	
END ;;
DELIMITER ;
/*!50003 SET sql_mode              = @saved_sql_mode */ ;
/*!50003 SET character_set_client  = @saved_cs_client */ ;
/*!50003 SET character_set_results = @saved_cs_results */ ;
/*!50003 SET collation_connection  = @saved_col_connection */ ;
/*!50003 DROP FUNCTION IF EXISTS `SYSTEM_STATUS@IS_ACTIVE_INACTIVE` */;
/*!50003 SET @saved_cs_client      = @@character_set_client */ ;
/*!50003 SET @saved_cs_results     = @@character_set_results */ ;
/*!50003 SET @saved_col_connection = @@collation_connection */ ;
/*!50003 SET character_set_client  = latin1 */ ;
/*!50003 SET character_set_results = latin1 */ ;
/*!50003 SET collation_connection  = latin1_swedish_ci */ ;
/*!50003 SET @saved_sql_mode       = @@sql_mode */ ;
/*!50003 SET sql_mode              = '' */ ;
DELIMITER ;;
CREATE DEFINER=`root`@`localhost` FUNCTION `SYSTEM_STATUS@IS_ACTIVE_INACTIVE`(
	`PARAM_SYS_STATUS_ID` TINYINT
) RETURNS tinyint(1)
SF_CHECK:
BEGIN

	-- STATUS
	-- ========================================================
	DECLARE STATUS_INACTIVE TINYINT DEFAULT 1;
	DECLARE STATUS_ACTIVE TINYINT DEFAULT 2;
	-- ========================================================


	-- CHECK IF EXISTS
	-- ========================================================
	IF
		PARAM_SYS_STATUS_ID = STATUS_INACTIVE OR
		PARAM_SYS_STATUS_ID = STATUS_ACTIVE
	THEN
		return 1;
	ELSE
		return 0;
	END IF;
	-- ========================================================

	-- SQL Server requires to return value at the end of the function, even not reachable.
	return 0;
	
END ;;
DELIMITER ;
/*!50003 SET sql_mode              = @saved_sql_mode */ ;
/*!50003 SET character_set_client  = @saved_cs_client */ ;
/*!50003 SET character_set_results = @saved_cs_results */ ;
/*!50003 SET collation_connection  = @saved_col_connection */ ;
/*!50003 DROP FUNCTION IF EXISTS `SYSTEM_STATUS@SYS_STATUS_DESCRIPTION_2_FROM_ID` */;
/*!50003 SET @saved_cs_client      = @@character_set_client */ ;
/*!50003 SET @saved_cs_results     = @@character_set_results */ ;
/*!50003 SET @saved_col_connection = @@collation_connection */ ;
/*!50003 SET character_set_client  = latin1 */ ;
/*!50003 SET character_set_results = latin1 */ ;
/*!50003 SET collation_connection  = latin1_swedish_ci */ ;
/*!50003 SET @saved_sql_mode       = @@sql_mode */ ;
/*!50003 SET sql_mode              = '' */ ;
DELIMITER ;;
CREATE DEFINER=`root`@`localhost` FUNCTION `SYSTEM_STATUS@SYS_STATUS_DESCRIPTION_2_FROM_ID`(
	`PARAM_SYS_STATUS_ID` TINYINT
) RETURNS varchar(500) CHARSET utf8 COLLATE utf8_unicode_ci
SF_CHECK:
BEGIN

	-- STATUS
	-- ========================================================
	DECLARE STATUS_INACTIVE TINYINT DEFAULT 1;
	DECLARE STATUS_ACTIVE TINYINT DEFAULT 2;
	
	DECLARE TEMP_SYS_STATUS_DESCRIPTION_2 VARCHAR(500) DEFAULT '';
	-- ========================================================


	-- CHECK IF EXISTS
	-- ========================================================
	IF
	(
		SELECT COUNT(`system_status`.`SYS_STATUS_ID`)
		FROM `system_status`
		WHERE
			`system_status`.`SYS_STATUS_ID` = PARAM_SYS_STATUS_ID
		LIMIT 1
	) >= 1
	THEN
	
		SELECT 
			`system_status`.`SYS_STATUS_DESCRIPTION_2`
		INTO
			TEMP_SYS_STATUS_DESCRIPTION_2
		FROM `system_status`
		WHERE
			`system_status`.`SYS_STATUS_ID` = PARAM_SYS_STATUS_ID
		LIMIT 1;

	END IF;
	-- ========================================================


	-- SQL Server requires to return value at the end of the function, even not reachable.
	return TEMP_SYS_STATUS_DESCRIPTION_2;
	
END ;;
DELIMITER ;
/*!50003 SET sql_mode              = @saved_sql_mode */ ;
/*!50003 SET character_set_client  = @saved_cs_client */ ;
/*!50003 SET character_set_results = @saved_cs_results */ ;
/*!50003 SET collation_connection  = @saved_col_connection */ ;
/*!50003 DROP FUNCTION IF EXISTS `SYSTEM_STATUS@SYS_STATUS_DESCRIPTION_FROM_ID` */;
/*!50003 SET @saved_cs_client      = @@character_set_client */ ;
/*!50003 SET @saved_cs_results     = @@character_set_results */ ;
/*!50003 SET @saved_col_connection = @@collation_connection */ ;
/*!50003 SET character_set_client  = latin1 */ ;
/*!50003 SET character_set_results = latin1 */ ;
/*!50003 SET collation_connection  = latin1_swedish_ci */ ;
/*!50003 SET @saved_sql_mode       = @@sql_mode */ ;
/*!50003 SET sql_mode              = '' */ ;
DELIMITER ;;
CREATE DEFINER=`root`@`localhost` FUNCTION `SYSTEM_STATUS@SYS_STATUS_DESCRIPTION_FROM_ID`(
	`PARAM_SYS_STATUS_ID` TINYINT
) RETURNS varchar(500) CHARSET utf8 COLLATE utf8_unicode_ci
SF_CHECK:
BEGIN

	-- STATUS
	-- ========================================================
	DECLARE STATUS_INACTIVE TINYINT DEFAULT 1;
	DECLARE STATUS_ACTIVE TINYINT DEFAULT 2;
	
	DECLARE TEMP_SYS_STATUS_DESCRIPTION VARCHAR(500) DEFAULT '';
	-- ========================================================


	-- CHECK IF EXISTS
	-- ========================================================
	IF
	(
		SELECT COUNT(`system_status`.`SYS_STATUS_ID`)
		FROM `system_status`
		WHERE
			`system_status`.`SYS_STATUS_ID` = PARAM_SYS_STATUS_ID
		LIMIT 1
	) >= 1
	THEN
	
		SELECT 
			`system_status`.`SYS_STATUS_DESCRIPTION`
		INTO
			TEMP_SYS_STATUS_DESCRIPTION
		FROM `system_status`
		WHERE
			`system_status`.`SYS_STATUS_ID` = PARAM_SYS_STATUS_ID
		LIMIT 1;

	END IF;
	-- ========================================================


	-- SQL Server requires to return value at the end of the function, even not reachable.
	return TEMP_SYS_STATUS_DESCRIPTION;
	
END ;;
DELIMITER ;
/*!50003 SET sql_mode              = @saved_sql_mode */ ;
/*!50003 SET character_set_client  = @saved_cs_client */ ;
/*!50003 SET character_set_results = @saved_cs_results */ ;
/*!50003 SET collation_connection  = @saved_col_connection */ ;
/*!50003 DROP FUNCTION IF EXISTS `SYSTEM_STATUS@SYS_STATUS_ID_EXISTS` */;
/*!50003 SET @saved_cs_client      = @@character_set_client */ ;
/*!50003 SET @saved_cs_results     = @@character_set_results */ ;
/*!50003 SET @saved_col_connection = @@collation_connection */ ;
/*!50003 SET character_set_client  = latin1 */ ;
/*!50003 SET character_set_results = latin1 */ ;
/*!50003 SET collation_connection  = latin1_swedish_ci */ ;
/*!50003 SET @saved_sql_mode       = @@sql_mode */ ;
/*!50003 SET sql_mode              = '' */ ;
DELIMITER ;;
CREATE DEFINER=`root`@`localhost` FUNCTION `SYSTEM_STATUS@SYS_STATUS_ID_EXISTS`(
	`PARAM_SYS_STATUS_ID` TINYINT,
	`DO_NOT_RETURN_INACTIVE_RECORDS` BIT
) RETURNS tinyint(1)
SF_CHECK:
BEGIN

	-- STATUS
	-- ========================================================
	DECLARE STATUS_INACTIVE TINYINT DEFAULT 1;
	DECLARE STATUS_ACTIVE TINYINT DEFAULT 2;
	-- ========================================================


	-- CHECK IF EXISTS
	-- ========================================================
	IF
	(
		SELECT COUNT(`system_status`.`SYS_STATUS_ID`)
		FROM `system_status`
		WHERE
			`system_status`.`SYS_STATUS_ID` = PARAM_SYS_STATUS_ID AND
			(
				DO_NOT_RETURN_INACTIVE_RECORDS = 0 OR
				`system_status`.`SYS_STATUS_STATUS` = STATUS_ACTIVE
			)
		LIMIT 1
	) >= 1
	THEN
		return 1;
	ELSE
		return 0;
	END IF;
	-- ========================================================


	-- SQL Server requires to return value at the end of the function, even not reachable.
	return 0;
	
END ;;
DELIMITER ;
/*!50003 SET sql_mode              = @saved_sql_mode */ ;
/*!50003 SET character_set_client  = @saved_cs_client */ ;
/*!50003 SET character_set_results = @saved_cs_results */ ;
/*!50003 SET collation_connection  = @saved_col_connection */ ;
/*!50003 DROP FUNCTION IF EXISTS `SYSTEM_TRAIL_METHOD@SYS_METHOD_ID_EXISTS` */;
/*!50003 SET @saved_cs_client      = @@character_set_client */ ;
/*!50003 SET @saved_cs_results     = @@character_set_results */ ;
/*!50003 SET @saved_col_connection = @@collation_connection */ ;
/*!50003 SET character_set_client  = latin1 */ ;
/*!50003 SET character_set_results = latin1 */ ;
/*!50003 SET collation_connection  = latin1_swedish_ci */ ;
/*!50003 SET @saved_sql_mode       = @@sql_mode */ ;
/*!50003 SET sql_mode              = '' */ ;
DELIMITER ;;
CREATE DEFINER=`root`@`localhost` FUNCTION `SYSTEM_TRAIL_METHOD@SYS_METHOD_ID_EXISTS`(
	`PARAM_SYS_METHOD_ID` BIGINT,
	`DO_NOT_RETURN_INACTIVE_RECORDS` BIT
) RETURNS tinyint(1)
SF_CHECK:
BEGIN

	-- STATUS
	-- ========================================================
	DECLARE STATUS_INACTIVE TINYINT DEFAULT 1;
	DECLARE STATUS_ACTIVE TINYINT DEFAULT 2;
	-- ========================================================

	IF PARAM_SYS_METHOD_ID <= 0 THEN
		RETURN 0;
	END IF;

	-- CHECK IF EXISTS
	-- ========================================================
	IF
	(
		SELECT COUNT(`system_trail_methods`.`SYS_METHOD_ID`)
		FROM `system_trail_methods`
		WHERE
			`system_trail_methods`.`SYS_METHOD_ID` = PARAM_SYS_METHOD_ID AND
			(
				DO_NOT_RETURN_INACTIVE_RECORDS = 0 OR
				`system_trail_methods`.`SYS_METHOD_STATUS` = STATUS_ACTIVE
			)
		LIMIT 1
	) >= 1
	THEN
		return 1;
	ELSE
		return 0;
	END IF;
	-- ========================================================


	-- SQL Server requires to return value at the end of the function, even not reachable.
	return 0;
	
END ;;
DELIMITER ;
/*!50003 SET sql_mode              = @saved_sql_mode */ ;
/*!50003 SET character_set_client  = @saved_cs_client */ ;
/*!50003 SET character_set_results = @saved_cs_results */ ;
/*!50003 SET collation_connection  = @saved_col_connection */ ;
/*!50003 DROP FUNCTION IF EXISTS `SYSTEM_TRAIL_METHOD@SYS_METHOD_ID_FROM_KEYWORD` */;
/*!50003 SET @saved_cs_client      = @@character_set_client */ ;
/*!50003 SET @saved_cs_results     = @@character_set_results */ ;
/*!50003 SET @saved_col_connection = @@collation_connection */ ;
/*!50003 SET character_set_client  = latin1 */ ;
/*!50003 SET character_set_results = latin1 */ ;
/*!50003 SET collation_connection  = latin1_swedish_ci */ ;
/*!50003 SET @saved_sql_mode       = @@sql_mode */ ;
/*!50003 SET sql_mode              = '' */ ;
DELIMITER ;;
CREATE DEFINER=`root`@`localhost` FUNCTION `SYSTEM_TRAIL_METHOD@SYS_METHOD_ID_FROM_KEYWORD`(
	`PARAM_SYS_METHOD_CODE` VARCHAR(16000),
	`DO_NOT_RETURN_INACTIVE_RECORDS` BIT
) RETURNS bigint(20)
SF_CHECK:
BEGIN

	-- STATUS
	-- ========================================================
	DECLARE STATUS_INACTIVE TINYINT DEFAULT 1;
	DECLARE STATUS_ACTIVE TINYINT DEFAULT 2;
	
	DECLARE PARAM_SYS_METHOD_ID BIGINT DEFAULT 0;
	-- ========================================================

	-- CHECK IF EXISTS
	-- ========================================================
	IF
	(
		SELECT COUNT(`system_trail_methods`.`SYS_METHOD_ID`)
		FROM `system_trail_methods`
		WHERE
			`system_trail_methods`.`SYS_METHOD_CODE` = PARAM_SYS_METHOD_CODE AND
			(
				DO_NOT_RETURN_INACTIVE_RECORDS = 0 OR
				`system_trail_methods`.`SYS_METHOD_STATUS` = STATUS_ACTIVE
			)
		LIMIT 1
	) >= 1
	THEN
		SELECT
			`system_trail_methods`.`SYS_METHOD_ID`
		INTO
			PARAM_SYS_METHOD_ID
		FROM `system_trail_methods`
		WHERE
			`system_trail_methods`.`SYS_METHOD_CODE` = PARAM_SYS_METHOD_CODE AND
			(
				DO_NOT_RETURN_INACTIVE_RECORDS = 0 OR
				`system_trail_methods`.`SYS_METHOD_STATUS` = STATUS_ACTIVE
			)
		LIMIT 1;
	END IF;
	-- ========================================================


	-- SQL Server requires to return value at the end of the function, even not reachable.
	return PARAM_SYS_METHOD_ID;
	
END ;;
DELIMITER ;
/*!50003 SET sql_mode              = @saved_sql_mode */ ;
/*!50003 SET character_set_client  = @saved_cs_client */ ;
/*!50003 SET character_set_results = @saved_cs_results */ ;
/*!50003 SET collation_connection  = @saved_col_connection */ ;
/*!50003 DROP FUNCTION IF EXISTS `SYSTEM_VAR@CONCAT_ADD` */;
/*!50003 SET @saved_cs_client      = @@character_set_client */ ;
/*!50003 SET @saved_cs_results     = @@character_set_results */ ;
/*!50003 SET @saved_col_connection = @@collation_connection */ ;
/*!50003 SET character_set_client  = latin1 */ ;
/*!50003 SET character_set_results = latin1 */ ;
/*!50003 SET collation_connection  = latin1_swedish_ci */ ;
/*!50003 SET @saved_sql_mode       = @@sql_mode */ ;
/*!50003 SET sql_mode              = '' */ ;
DELIMITER ;;
CREATE DEFINER=`root`@`localhost` FUNCTION `SYSTEM_VAR@CONCAT_ADD`(
	`PARAM_SEPARATOR` VARCHAR(20),
	`PARAM_BASE_STRING_SET` VARCHAR(16000),
	`PARAM_ADD_STRING` VARCHAR(16000)
) RETURNS varchar(16000) CHARSET utf8 COLLATE utf8_unicode_ci
SF_CHECK:
BEGIN

	IF CHAR_LENGTH(PARAM_BASE_STRING_SET) > 0 THEN
		return CONCAT_WS(PARAM_SEPARATOR, PARAM_BASE_STRING_SET, PARAM_ADD_STRING);
	ELSE 
		return PARAM_ADD_STRING;
	END IF;

	-- SQL Server requires to return value at the end of the function, even not reachable.
	return '';
	
END ;;
DELIMITER ;
/*!50003 SET sql_mode              = @saved_sql_mode */ ;
/*!50003 SET character_set_client  = @saved_cs_client */ ;
/*!50003 SET character_set_results = @saved_cs_results */ ;
/*!50003 SET collation_connection  = @saved_col_connection */ ;
/*!50003 DROP FUNCTION IF EXISTS `SYSTEM_VAR@FIX_STRING` */;
/*!50003 SET @saved_cs_client      = @@character_set_client */ ;
/*!50003 SET @saved_cs_results     = @@character_set_results */ ;
/*!50003 SET @saved_col_connection = @@collation_connection */ ;
/*!50003 SET character_set_client  = latin1 */ ;
/*!50003 SET character_set_results = latin1 */ ;
/*!50003 SET collation_connection  = latin1_swedish_ci */ ;
/*!50003 SET @saved_sql_mode       = @@sql_mode */ ;
/*!50003 SET sql_mode              = '' */ ;
DELIMITER ;;
CREATE DEFINER=`root`@`localhost` FUNCTION `SYSTEM_VAR@FIX_STRING`(
	`PARAM_STRING_VALUE` VARCHAR(500),
	`PARAM_FILL_CHARACTER` VARCHAR(1),
	`PARAM_MIN_SIZE` TINYINT
) RETURNS varchar(500) CHARSET utf8 COLLATE utf8_unicode_ci
SF_CHECK:
BEGIN

	-- INITIALIZE
	-- ========================================================
	DECLARE RESULT_STRING_VALUE VARCHAR(500) DEFAULT PARAM_STRING_VALUE;
	-- ========================================================
	

	-- FILL UPTO MIN_SIZE
	-- ========================================================
	SET PARAM_FILL_CHARACTER = `SYSTEM_VAR@REPLACE_NULL@NVARCHAR`(PARAM_FILL_CHARACTER, '0', 1);
	WHILE CHAR_LENGTH(RESULT_STRING_VALUE) < PARAM_MIN_SIZE DO
		SET RESULT_STRING_VALUE = CONCAT(PARAM_FILL_CHARACTER, RESULT_STRING_VALUE);
	END WHILE;
	-- ========================================================
	
    Return RESULT_STRING_VALUE;
	
END ;;
DELIMITER ;
/*!50003 SET sql_mode              = @saved_sql_mode */ ;
/*!50003 SET character_set_client  = @saved_cs_client */ ;
/*!50003 SET character_set_results = @saved_cs_results */ ;
/*!50003 SET collation_connection  = @saved_col_connection */ ;
/*!50003 DROP FUNCTION IF EXISTS `SYSTEM_VAR@IS_NULL@BIGINT` */;
/*!50003 SET @saved_cs_client      = @@character_set_client */ ;
/*!50003 SET @saved_cs_results     = @@character_set_results */ ;
/*!50003 SET @saved_col_connection = @@collation_connection */ ;
/*!50003 SET character_set_client  = latin1 */ ;
/*!50003 SET character_set_results = latin1 */ ;
/*!50003 SET collation_connection  = latin1_swedish_ci */ ;
/*!50003 SET @saved_sql_mode       = @@sql_mode */ ;
/*!50003 SET sql_mode              = '' */ ;
DELIMITER ;;
CREATE DEFINER=`root`@`localhost` FUNCTION `SYSTEM_VAR@IS_NULL@BIGINT`(
	`PARAM_BIGINT` BIGINT,
	`PARAM_TREAT_ZERO_VALUE_AS_NULL` BIT,
	`PARAM_TREAT_NEGATIVE_AS_NULL` BIT
) RETURNS tinyint(1)
SF_CHECK:
BEGIN

	-- GET NULL FLAG
	-- ===================================
	DECLARE TEMP_NULL_FLAG BIGINT DEFAULT 0;

	SELECT 
		`system_null_flag`.`SYS_BIGINT_FLAG` INTO TEMP_NULL_FLAG
	FROM `system_null_flag`
	WHERE 
		`system_null_flag`.`SYS_FLAG_ID` = 1
	LIMIT 1;
	-- ===================================


	-- VALIDATE IF NULL
	-- ===================================
	IF 
		PARAM_BIGINT IS NULL OR
		PARAM_BIGINT <= TEMP_NULL_FLAG OR
		(
			PARAM_TREAT_ZERO_VALUE_AS_NULL = 1 AND
			PARAM_BIGINT = 0
		) OR
		(
			PARAM_TREAT_NEGATIVE_AS_NULL = 1 AND
			PARAM_BIGINT < 0
		)
	THEN
		return 1;
	ELSE
		return 0;
	END IF;
	
	return 0;
	-- ===================================
	
END ;;
DELIMITER ;
/*!50003 SET sql_mode              = @saved_sql_mode */ ;
/*!50003 SET character_set_client  = @saved_cs_client */ ;
/*!50003 SET character_set_results = @saved_cs_results */ ;
/*!50003 SET collation_connection  = @saved_col_connection */ ;
/*!50003 DROP FUNCTION IF EXISTS `SYSTEM_VAR@IS_NULL@BIT` */;
/*!50003 SET @saved_cs_client      = @@character_set_client */ ;
/*!50003 SET @saved_cs_results     = @@character_set_results */ ;
/*!50003 SET @saved_col_connection = @@collation_connection */ ;
/*!50003 SET character_set_client  = latin1 */ ;
/*!50003 SET character_set_results = latin1 */ ;
/*!50003 SET collation_connection  = latin1_swedish_ci */ ;
/*!50003 SET @saved_sql_mode       = @@sql_mode */ ;
/*!50003 SET sql_mode              = '' */ ;
DELIMITER ;;
CREATE DEFINER=`root`@`localhost` FUNCTION `SYSTEM_VAR@IS_NULL@BIT`(
	`PARAM_BIT` TINYINT,
	`PARAM_TREAT_ZERO_VALUE_AS_NULL` BIT,
	`PARAM_TREAT_NEGATIVE_AS_NULL` BIT
) RETURNS tinyint(1)
SF_CHECK:
BEGIN

	-- GET NULL FLAG
	-- ===================================
	DECLARE TEMP_NULL_FLAG TINYINT DEFAULT 0;

	SELECT `system_null_flag`.`SYS_BIT_FLAG` INTO TEMP_NULL_FLAG
	FROM `system_null_flag`
	WHERE `system_null_flag`.`SYS_FLAG_ID` = 1
	LIMIT 1;
	-- ===================================


	-- VALIDATE IF NULL
	-- ===================================
	IF 
		PARAM_BIT IS NULL OR
		PARAM_BIT <= TEMP_NULL_FLAG OR
		(
			PARAM_TREAT_ZERO_VALUE_AS_NULL = 1 AND
			(
				PARAM_BIT <= 0
			)
		)
	THEN
		return 1;
	ELSE
		return 0;
	END IF;
	
	return 0;
	-- ===================================
	
END ;;
DELIMITER ;
/*!50003 SET sql_mode              = @saved_sql_mode */ ;
/*!50003 SET character_set_client  = @saved_cs_client */ ;
/*!50003 SET character_set_results = @saved_cs_results */ ;
/*!50003 SET collation_connection  = @saved_col_connection */ ;
/*!50003 DROP FUNCTION IF EXISTS `SYSTEM_VAR@IS_NULL@DATETIME` */;
/*!50003 SET @saved_cs_client      = @@character_set_client */ ;
/*!50003 SET @saved_cs_results     = @@character_set_results */ ;
/*!50003 SET @saved_col_connection = @@collation_connection */ ;
/*!50003 SET character_set_client  = latin1 */ ;
/*!50003 SET character_set_results = latin1 */ ;
/*!50003 SET collation_connection  = latin1_swedish_ci */ ;
/*!50003 SET @saved_sql_mode       = @@sql_mode */ ;
/*!50003 SET sql_mode              = '' */ ;
DELIMITER ;;
CREATE DEFINER=`root`@`localhost` FUNCTION `SYSTEM_VAR@IS_NULL@DATETIME`(
	`PARAM_DATETIME` DATETIME(6),
	`PARAM_TREAT_ZERO_VALUE_AS_NULL` BIT
) RETURNS tinyint(1)
SF_CHECK:
BEGIN

	-- GET NULL FLAG
	-- ===================================
	DECLARE TEMP_NULL_FLAG DATETIME(6) DEFAULT '1000-01-01 00:00:00';

	SELECT DATE_ADD(`system_null_flag`.`SYS_DATETIME_FLAG`, INTERVAL 1 SECOND) INTO TEMP_NULL_FLAG
	FROM `system_null_flag`
	WHERE `system_null_flag`.`SYS_FLAG_ID` = 1;
	-- ===================================


	-- VALIDATE IF NULL
	-- ===================================
	IF 
		PARAM_DATETIME IS NULL OR
		PARAM_DATETIME <= TEMP_NULL_FLAG
	THEN
		return 1;
	ELSE
		return 0;
	END IF;
	
	return 0;
	-- ===================================
	
END ;;
DELIMITER ;
/*!50003 SET sql_mode              = @saved_sql_mode */ ;
/*!50003 SET character_set_client  = @saved_cs_client */ ;
/*!50003 SET character_set_results = @saved_cs_results */ ;
/*!50003 SET collation_connection  = @saved_col_connection */ ;
/*!50003 DROP FUNCTION IF EXISTS `SYSTEM_VAR@IS_NULL@DECIMAL` */;
/*!50003 SET @saved_cs_client      = @@character_set_client */ ;
/*!50003 SET @saved_cs_results     = @@character_set_results */ ;
/*!50003 SET @saved_col_connection = @@collation_connection */ ;
/*!50003 SET character_set_client  = latin1 */ ;
/*!50003 SET character_set_results = latin1 */ ;
/*!50003 SET collation_connection  = latin1_swedish_ci */ ;
/*!50003 SET @saved_sql_mode       = @@sql_mode */ ;
/*!50003 SET sql_mode              = '' */ ;
DELIMITER ;;
CREATE DEFINER=`root`@`localhost` FUNCTION `SYSTEM_VAR@IS_NULL@DECIMAL`(
	`PARAM_DECIMAL` DECIMAL(18,2),
	`PARAM_TREAT_ZERO_VALUE_AS_NULL` BIT,
	`PARAM_TREAT_NEGATIVE_AS_NULL` BIT
) RETURNS tinyint(1)
SF_CHECK:
BEGIN

	-- GET NULL FLAG
	-- ===================================
	DECLARE TEMP_NULL_FLAG DECIMAL(18,2) DEFAULT 0;

	SELECT `system_null_flag`.`SYS_DECIMAL_FLAG` INTO TEMP_NULL_FLAG
	FROM `system_null_flag`
	WHERE `system_null_flag`.`SYS_FLAG_ID` = 1
	LIMIT 1;
	-- ===================================



	-- VALIDATE IF NULL
	-- ===================================
	IF 
		PARAM_DECIMAL IS NULL OR
		PARAM_DECIMAL <= TEMP_NULL_FLAG OR
		(
			PARAM_TREAT_ZERO_VALUE_AS_NULL = 1 AND
			PARAM_DECIMAL = 0
		) OR
		(
			PARAM_TREAT_NEGATIVE_AS_NULL = 1 AND
			PARAM_DECIMAL < 0
		)
	THEN
		return 1;
	ELSE
		return 0;
	END IF;
	
	return 0;
	-- ===================================
	
END ;;
DELIMITER ;
/*!50003 SET sql_mode              = @saved_sql_mode */ ;
/*!50003 SET character_set_client  = @saved_cs_client */ ;
/*!50003 SET character_set_results = @saved_cs_results */ ;
/*!50003 SET collation_connection  = @saved_col_connection */ ;
/*!50003 DROP FUNCTION IF EXISTS `SYSTEM_VAR@IS_NULL@INT` */;
/*!50003 SET @saved_cs_client      = @@character_set_client */ ;
/*!50003 SET @saved_cs_results     = @@character_set_results */ ;
/*!50003 SET @saved_col_connection = @@collation_connection */ ;
/*!50003 SET character_set_client  = latin1 */ ;
/*!50003 SET character_set_results = latin1 */ ;
/*!50003 SET collation_connection  = latin1_swedish_ci */ ;
/*!50003 SET @saved_sql_mode       = @@sql_mode */ ;
/*!50003 SET sql_mode              = '' */ ;
DELIMITER ;;
CREATE DEFINER=`root`@`localhost` FUNCTION `SYSTEM_VAR@IS_NULL@INT`(
	`PARAM_INT` INT,
	`PARAM_TREAT_ZERO_VALUE_AS_NULL` BIT,
	`PARAM_TREAT_NEGATIVE_AS_NULL` BIT
) RETURNS tinyint(1)
SF_CHECK:
BEGIN

	-- GET NULL FLAG
	-- ===================================
	DECLARE TEMP_NULL_FLAG INT DEFAULT 0;

	SELECT `system_null_flag`.`SYS_INT_FLAG` INTO TEMP_NULL_FLAG
	FROM `system_null_flag`
	WHERE `system_null_flag`.`SYS_FLAG_ID` = 1
	LIMIT 1;
	-- ===================================



	-- VALIDATE IF NULL
	-- ===================================
	IF 
		PARAM_INT IS NULL OR
		PARAM_INT <= TEMP_NULL_FLAG OR
		(
			PARAM_TREAT_ZERO_VALUE_AS_NULL = 1 AND
			PARAM_INT = 0
		) OR
		(
			PARAM_TREAT_NEGATIVE_AS_NULL = 1 AND
			PARAM_INT < 0
		)
	THEN
		return 1;
	ELSE
		return 0;
	END IF;
	
	return 0;
	-- ===================================
	
END ;;
DELIMITER ;
/*!50003 SET sql_mode              = @saved_sql_mode */ ;
/*!50003 SET character_set_client  = @saved_cs_client */ ;
/*!50003 SET character_set_results = @saved_cs_results */ ;
/*!50003 SET collation_connection  = @saved_col_connection */ ;
/*!50003 DROP FUNCTION IF EXISTS `SYSTEM_VAR@IS_NULL@LONGTEXT` */;
/*!50003 SET @saved_cs_client      = @@character_set_client */ ;
/*!50003 SET @saved_cs_results     = @@character_set_results */ ;
/*!50003 SET @saved_col_connection = @@collation_connection */ ;
/*!50003 SET character_set_client  = latin1 */ ;
/*!50003 SET character_set_results = latin1 */ ;
/*!50003 SET collation_connection  = latin1_swedish_ci */ ;
/*!50003 SET @saved_sql_mode       = @@sql_mode */ ;
/*!50003 SET sql_mode              = '' */ ;
DELIMITER ;;
CREATE DEFINER=`root`@`localhost` FUNCTION `SYSTEM_VAR@IS_NULL@LONGTEXT`(
	`PARAM_LONGTEXT` LONGTEXT,
	`PARAM_TREAT_EMPTY_STRING_AS_NULL` BIT,
	`PARAM_TREAT_NEGATIVE_AS_NULL` BIT
) RETURNS tinyint(1)
SF_CHECK:
BEGIN

	-- GET NULL FLAG
	-- ===================================
	DECLARE TEMP_NULL_FLAG VARCHAR(50) DEFAULT '';

	SELECT `system_null_flag`.`SYS_NVARCHAR_FLAG` INTO TEMP_NULL_FLAG
	FROM `system_null_flag`
	WHERE `system_null_flag`.`SYS_FLAG_ID` = 1
	LIMIT 1;
	-- ===================================


	-- VALIDATE IF NULL
	-- ===================================
	IF 
		PARAM_LONGTEXT IS NULL OR
		PARAM_LONGTEXT = TEMP_NULL_FLAG OR
		(
			PARAM_TREAT_EMPTY_STRING_AS_NULL = 1 AND
			(
				PARAM_LONGTEXT = '&null;' OR
				PARAM_LONGTEXT = ''
			)
		)
	THEN
		return 1;
	ELSE 
		return 0;
	END IF;
	
	return 0;
	-- ===================================
	
END ;;
DELIMITER ;
/*!50003 SET sql_mode              = @saved_sql_mode */ ;
/*!50003 SET character_set_client  = @saved_cs_client */ ;
/*!50003 SET character_set_results = @saved_cs_results */ ;
/*!50003 SET collation_connection  = @saved_col_connection */ ;
/*!50003 DROP FUNCTION IF EXISTS `SYSTEM_VAR@IS_NULL@MEDIUMTEXT` */;
/*!50003 SET @saved_cs_client      = @@character_set_client */ ;
/*!50003 SET @saved_cs_results     = @@character_set_results */ ;
/*!50003 SET @saved_col_connection = @@collation_connection */ ;
/*!50003 SET character_set_client  = latin1 */ ;
/*!50003 SET character_set_results = latin1 */ ;
/*!50003 SET collation_connection  = latin1_swedish_ci */ ;
/*!50003 SET @saved_sql_mode       = @@sql_mode */ ;
/*!50003 SET sql_mode              = '' */ ;
DELIMITER ;;
CREATE DEFINER=`root`@`localhost` FUNCTION `SYSTEM_VAR@IS_NULL@MEDIUMTEXT`(
	`PARAM_MEDIUMTEXT` MEDIUMTEXT,
	`PARAM_TREAT_EMPTY_STRING_AS_NULL` BIT
) RETURNS tinyint(1)
SF_CHECK:
BEGIN

	-- GET NULL FLAG
	-- ===================================
	DECLARE TEMP_NULL_FLAG VARCHAR(50) DEFAULT '';

	SELECT `system_null_flag`.`SYS_NVARCHAR_FLAG` INTO TEMP_NULL_FLAG
	FROM `system_null_flag`
	WHERE `system_null_flag`.`SYS_FLAG_ID` = 1
	LIMIT 1;
	-- ===================================


	-- VALIDATE IF NULL
	-- ===================================
	IF 
		PARAM_MEDIUMTEXT IS NULL OR
		PARAM_MEDIUMTEXT = TEMP_NULL_FLAG OR
		(
			PARAM_TREAT_EMPTY_STRING_AS_NULL = 1 AND
			(
				PARAM_MEDIUMTEXT = '&null;' OR
				PARAM_MEDIUMTEXT = ''
			)
		)
	THEN
		return 1;
	ELSE 
		return 0;
	END IF;
	
	return 0;
	-- ===================================
	
END ;;
DELIMITER ;
/*!50003 SET sql_mode              = @saved_sql_mode */ ;
/*!50003 SET character_set_client  = @saved_cs_client */ ;
/*!50003 SET character_set_results = @saved_cs_results */ ;
/*!50003 SET collation_connection  = @saved_col_connection */ ;
/*!50003 DROP FUNCTION IF EXISTS `SYSTEM_VAR@IS_NULL@NVARCHAR` */;
/*!50003 SET @saved_cs_client      = @@character_set_client */ ;
/*!50003 SET @saved_cs_results     = @@character_set_results */ ;
/*!50003 SET @saved_col_connection = @@collation_connection */ ;
/*!50003 SET character_set_client  = latin1 */ ;
/*!50003 SET character_set_results = latin1 */ ;
/*!50003 SET collation_connection  = latin1_swedish_ci */ ;
/*!50003 SET @saved_sql_mode       = @@sql_mode */ ;
/*!50003 SET sql_mode              = '' */ ;
DELIMITER ;;
CREATE DEFINER=`root`@`localhost` FUNCTION `SYSTEM_VAR@IS_NULL@NVARCHAR`(
	`PARAM_NVARCHAR` VARCHAR(16000),
	`PARAM_TREAT_EMPTY_STRING_AS_NULL` BIT
) RETURNS tinyint(1)
SF_CHECK:
BEGIN

	-- GET NULL FLAG
	-- ===================================
	DECLARE TEMP_NULL_FLAG VARCHAR(50) DEFAULT '';

	SELECT `system_null_flag`.`SYS_NVARCHAR_FLAG` INTO TEMP_NULL_FLAG
	FROM `system_null_flag`
	WHERE `system_null_flag`.`SYS_FLAG_ID` = 1
	LIMIT 1;
	-- ===================================


	-- VALIDATE IF NULL
	-- ===================================
	IF 
		PARAM_NVARCHAR IS NULL OR
		PARAM_NVARCHAR = TEMP_NULL_FLAG OR
		(
			PARAM_TREAT_EMPTY_STRING_AS_NULL = 1 AND
			(
				PARAM_NVARCHAR = '&null;' OR
				PARAM_NVARCHAR = ''
			)
		)
	THEN
		return 1;
	ELSE 
		return 0;
	END IF;
	
	return 0;
	-- ===================================
	
END ;;
DELIMITER ;
/*!50003 SET sql_mode              = @saved_sql_mode */ ;
/*!50003 SET character_set_client  = @saved_cs_client */ ;
/*!50003 SET character_set_results = @saved_cs_results */ ;
/*!50003 SET collation_connection  = @saved_col_connection */ ;
/*!50003 DROP FUNCTION IF EXISTS `SYSTEM_VAR@IS_NULL@TEXT` */;
/*!50003 SET @saved_cs_client      = @@character_set_client */ ;
/*!50003 SET @saved_cs_results     = @@character_set_results */ ;
/*!50003 SET @saved_col_connection = @@collation_connection */ ;
/*!50003 SET character_set_client  = latin1 */ ;
/*!50003 SET character_set_results = latin1 */ ;
/*!50003 SET collation_connection  = latin1_swedish_ci */ ;
/*!50003 SET @saved_sql_mode       = @@sql_mode */ ;
/*!50003 SET sql_mode              = '' */ ;
DELIMITER ;;
CREATE DEFINER=`root`@`localhost` FUNCTION `SYSTEM_VAR@IS_NULL@TEXT`(
	`PARAM_TEXT` TEXT,
	`PARAM_TREAT_EMPTY_STRING_AS_NULL` BIT
) RETURNS tinyint(1)
SF_CHECK:
BEGIN

	-- GET NULL FLAG
	-- ===================================
	DECLARE TEMP_NULL_FLAG VARCHAR(50) DEFAULT '';

	SELECT `system_null_flag`.`SYS_NVARCHAR_FLAG` INTO TEMP_NULL_FLAG
	FROM `system_null_flag`
	WHERE `system_null_flag`.`SYS_FLAG_ID` = 1
	LIMIT 1;
	-- ===================================


	-- VALIDATE IF NULL
	-- ===================================
	IF 
		PARAM_TEXT IS NULL OR
		PARAM_TEXT = TEMP_NULL_FLAG OR
		(
			PARAM_TREAT_EMPTY_STRING_AS_NULL = 1 AND
			(
				PARAM_TEXT = '&null;' OR
				PARAM_TEXT = ''
			)
		)
	THEN
		return 1;
	ELSE 
		return 0;
	END IF;
	
	return 0;
	-- ===================================
	
END ;;
DELIMITER ;
/*!50003 SET sql_mode              = @saved_sql_mode */ ;
/*!50003 SET character_set_client  = @saved_cs_client */ ;
/*!50003 SET character_set_results = @saved_cs_results */ ;
/*!50003 SET collation_connection  = @saved_col_connection */ ;
/*!50003 DROP FUNCTION IF EXISTS `SYSTEM_VAR@IS_NULL@TINYINT` */;
/*!50003 SET @saved_cs_client      = @@character_set_client */ ;
/*!50003 SET @saved_cs_results     = @@character_set_results */ ;
/*!50003 SET @saved_col_connection = @@collation_connection */ ;
/*!50003 SET character_set_client  = latin1 */ ;
/*!50003 SET character_set_results = latin1 */ ;
/*!50003 SET collation_connection  = latin1_swedish_ci */ ;
/*!50003 SET @saved_sql_mode       = @@sql_mode */ ;
/*!50003 SET sql_mode              = '' */ ;
DELIMITER ;;
CREATE DEFINER=`root`@`localhost` FUNCTION `SYSTEM_VAR@IS_NULL@TINYINT`(
	`PARAM_TINYINT` TINYINT,
	`PARAM_TREAT_ZERO_VALUE_AS_NULL` BIT,
	`PARAM_TREAT_NEGATIVE_AS_NULL` BIT
) RETURNS tinyint(1)
SF_CHECK:
BEGIN

	-- VALIDATE IF NULL
	-- ===================================
	IF 
		PARAM_TINYINT IS NULL OR
		PARAM_TINYINT <= 0 
	THEN
		return 1;
	ELSE
		return 0;
	END IF;
	
	return 0;
	-- ===================================
	
END ;;
DELIMITER ;
/*!50003 SET sql_mode              = @saved_sql_mode */ ;
/*!50003 SET character_set_client  = @saved_cs_client */ ;
/*!50003 SET character_set_results = @saved_cs_results */ ;
/*!50003 SET collation_connection  = @saved_col_connection */ ;
/*!50003 DROP FUNCTION IF EXISTS `SYSTEM_VAR@NOW` */;
/*!50003 SET @saved_cs_client      = @@character_set_client */ ;
/*!50003 SET @saved_cs_results     = @@character_set_results */ ;
/*!50003 SET @saved_col_connection = @@collation_connection */ ;
/*!50003 SET character_set_client  = latin1 */ ;
/*!50003 SET character_set_results = latin1 */ ;
/*!50003 SET collation_connection  = latin1_swedish_ci */ ;
/*!50003 SET @saved_sql_mode       = @@sql_mode */ ;
/*!50003 SET sql_mode              = '' */ ;
DELIMITER ;;
CREATE DEFINER=`root`@`localhost` FUNCTION `SYSTEM_VAR@NOW`(
	`PARAM_TIMEZONE` VARCHAR(50),
	`PARAM_USE_DEFAULT_TIMEZONE` BIT
) RETURNS datetime(6)
SF_CHECK:
BEGIN

	-- STATUS
	-- ========================================================
	DECLARE STATUS_INACTIVE TINYINT DEFAULT 1;
	DECLARE STATUS_ACTIVE TINYINT DEFAULT 2;
	
	-- Audit Handler
	DECLARE TEMP_ERR_MESSAGE VARCHAR(500) DEFAULT '';
	DECLARE ERR BIGINT DEFAULT 0;
	
	DECLARE RESULT_DATETIME DATETIME(6) DEFAULT '1000-01-01 00:00:00';
	-- ========================================================
	
	-- Use timezone from settings
	IF PARAM_USE_DEFAULT_TIMEZONE = 1 THEN
	
		-- Check if the default timezone exists
		IF
		(
			SELECT COUNT(`system_timezone`.`SYS_TIMEZONE_ID`)
			FROM `system_timezone`
			WHERE
				`system_timezone`.`SYS_TIMEZONE_CODE` = 'DEFAULT_TIMEZONE' AND
				`system_timezone`.`SYS_TIMEZONE_STATUS` = STATUS_ACTIVE
			LIMIT 1
		) <= 0
		THEN
			SET ERR = `RAISERROR`('Cannot find active `DEFAULT_TIMEZONE` from `system_timezone` table.');
		END IF;
	
	
		-- Get timezone settings
		SELECT
			`system_timezone`.`SYS_TIMEZONE_VALUE`
		INTO
			PARAM_TIMEZONE
		FROM `system_timezone`
		WHERE
			`system_timezone`.`SYS_TIMEZONE_CODE` = 'DEFAULT_TIMEZONE' AND
			`system_timezone`.`SYS_TIMEZONE_STATUS` = STATUS_ACTIVE
		LIMIT 1;
	
	END IF;
	
	-- Return result
	SET RESULT_DATETIME = convert_tz(now(6), @@session.time_zone, PARAM_TIMEZONE);
	Return RESULT_DATETIME;
	
END ;;
DELIMITER ;
/*!50003 SET sql_mode              = @saved_sql_mode */ ;
/*!50003 SET character_set_client  = @saved_cs_client */ ;
/*!50003 SET character_set_results = @saved_cs_results */ ;
/*!50003 SET collation_connection  = @saved_col_connection */ ;
/*!50003 DROP FUNCTION IF EXISTS `SYSTEM_VAR@RANDOM` */;
/*!50003 SET @saved_cs_client      = @@character_set_client */ ;
/*!50003 SET @saved_cs_results     = @@character_set_results */ ;
/*!50003 SET @saved_col_connection = @@collation_connection */ ;
/*!50003 SET character_set_client  = latin1 */ ;
/*!50003 SET character_set_results = latin1 */ ;
/*!50003 SET collation_connection  = latin1_swedish_ci */ ;
/*!50003 SET @saved_sql_mode       = @@sql_mode */ ;
/*!50003 SET sql_mode              = '' */ ;
DELIMITER ;;
CREATE DEFINER=`root`@`localhost` FUNCTION `SYSTEM_VAR@RANDOM`(
	`PARAM_MIN_VALUE` BIGINT,
	`PARAM_MAX_VALUE` BIGINT
) RETURNS bigint(20)
SF_CHECK:
BEGIN
	
	-- Initialize
	-- ...........................................
	RETURN PARAM_MIN_VALUE + 
	(
		(
			ASCII
			(
				LEFT
				(
					AES_ENCRYPT
					(
						LEFT(SHA2((0 + RAND() * (2140000000)), 512), 100), 
						LEFT(SHA2((0 + RAND() * (2140000000)), 512), 100)
					), 1
				)
			) / 256
		) * (PARAM_MAX_VALUE - PARAM_MIN_VALUE)
	);
	
END ;;
DELIMITER ;
/*!50003 SET sql_mode              = @saved_sql_mode */ ;
/*!50003 SET character_set_client  = @saved_cs_client */ ;
/*!50003 SET character_set_results = @saved_cs_results */ ;
/*!50003 SET collation_connection  = @saved_col_connection */ ;
/*!50003 DROP FUNCTION IF EXISTS `SYSTEM_VAR@RANDOM_BASE32` */;
/*!50003 SET @saved_cs_client      = @@character_set_client */ ;
/*!50003 SET @saved_cs_results     = @@character_set_results */ ;
/*!50003 SET @saved_col_connection = @@collation_connection */ ;
/*!50003 SET character_set_client  = latin1 */ ;
/*!50003 SET character_set_results = latin1 */ ;
/*!50003 SET collation_connection  = latin1_swedish_ci */ ;
/*!50003 SET @saved_sql_mode       = @@sql_mode */ ;
/*!50003 SET sql_mode              = '' */ ;
DELIMITER ;;
CREATE DEFINER=`root`@`localhost` FUNCTION `SYSTEM_VAR@RANDOM_BASE32`(
	PARAM_STR_LENGTH INT
) RETURNS varchar(500) CHARSET utf8 COLLATE utf8_unicode_ci
SF_CHECK:
BEGIN

	-- Initialize
	-- ...........................................
	DECLARE PARAM_RANDOM_RESULT VARCHAR(500) DEFAULT '';
	DECLARE PARAM_RANDOM_INT INT DEFAULT 0;

	-- Loop while generated Random String
	WHILE CHAR_LENGTH(PARAM_RANDOM_RESULT) < PARAM_STR_LENGTH
	DO
	
		-- Get character model (ALPHA or NUMERIC)
		SET PARAM_RANDOM_INT = `SYSTEM_VAR@RANDOM`(0, 100);

		-- Get String (Numerics) 
		IF PARAM_RANDOM_INT <= 25 THEN
			SET PARAM_RANDOM_INT = `SYSTEM_VAR@RANDOM`(50, 55);

		-- Get String (All Caps) 
		ELSE 
			SET PARAM_RANDOM_INT = `SYSTEM_VAR@RANDOM`(65, 90);

		END IF;

		-- Add to Result
		SET PARAM_RANDOM_RESULT = CONCAT(PARAM_RANDOM_RESULT , CHAR(PARAM_RANDOM_INT));

	END WHILE;


	-- Return Result
	-- ...........................................
	RETURN PARAM_RANDOM_RESULT;

END ;;
DELIMITER ;
/*!50003 SET sql_mode              = @saved_sql_mode */ ;
/*!50003 SET character_set_client  = @saved_cs_client */ ;
/*!50003 SET character_set_results = @saved_cs_results */ ;
/*!50003 SET collation_connection  = @saved_col_connection */ ;
/*!50003 DROP FUNCTION IF EXISTS `SYSTEM_VAR@RANDOM_STR` */;
/*!50003 SET @saved_cs_client      = @@character_set_client */ ;
/*!50003 SET @saved_cs_results     = @@character_set_results */ ;
/*!50003 SET @saved_col_connection = @@collation_connection */ ;
/*!50003 SET character_set_client  = latin1 */ ;
/*!50003 SET character_set_results = latin1 */ ;
/*!50003 SET collation_connection  = latin1_swedish_ci */ ;
/*!50003 SET @saved_sql_mode       = @@sql_mode */ ;
/*!50003 SET sql_mode              = '' */ ;
DELIMITER ;;
CREATE DEFINER=`root`@`localhost` FUNCTION `SYSTEM_VAR@RANDOM_STR`(
	PARAM_STR_LENGTH INT
) RETURNS varchar(500) CHARSET utf8 COLLATE utf8_unicode_ci
SF_CHECK:
BEGIN

	-- Initialize
	-- ...........................................
	DECLARE PARAM_RANDOM_RESULT VARCHAR(500) DEFAULT '';
	DECLARE PARAM_RANDOM_INT INT DEFAULT 0;

	-- Loop while generated Random String
	WHILE CHAR_LENGTH(PARAM_RANDOM_RESULT) < PARAM_STR_LENGTH
	DO
	
		-- Get character model (ALPHA or NUMERIC)
		SET PARAM_RANDOM_INT = `SYSTEM_VAR@RANDOM`(0, 3);

		-- Get String (Numerics) 
		IF PARAM_RANDOM_INT = 0 THEN
			SET PARAM_RANDOM_INT = `SYSTEM_VAR@RANDOM`(49, 57);

		-- Get String (Small Chars) 
		ELSEIF PARAM_RANDOM_INT = 1 THEN
			SET PARAM_RANDOM_INT = `SYSTEM_VAR@RANDOM`(97, 122);

		-- Get String (All Caps) 
		ELSE 
			SET PARAM_RANDOM_INT = `SYSTEM_VAR@RANDOM`(65, 90);

		END IF;

		-- Add to Result
		SET PARAM_RANDOM_RESULT = CONCAT(PARAM_RANDOM_RESULT , CHAR(PARAM_RANDOM_INT));

	END WHILE;


	-- Return Result
	-- ...........................................
	RETURN PARAM_RANDOM_RESULT;

END ;;
DELIMITER ;
/*!50003 SET sql_mode              = @saved_sql_mode */ ;
/*!50003 SET character_set_client  = @saved_cs_client */ ;
/*!50003 SET character_set_results = @saved_cs_results */ ;
/*!50003 SET collation_connection  = @saved_col_connection */ ;
/*!50003 DROP FUNCTION IF EXISTS `SYSTEM_VAR@RANDOM_UNIQUE_25L` */;
/*!50003 SET @saved_cs_client      = @@character_set_client */ ;
/*!50003 SET @saved_cs_results     = @@character_set_results */ ;
/*!50003 SET @saved_col_connection = @@collation_connection */ ;
/*!50003 SET character_set_client  = latin1 */ ;
/*!50003 SET character_set_results = latin1 */ ;
/*!50003 SET collation_connection  = latin1_swedish_ci */ ;
/*!50003 SET @saved_sql_mode       = @@sql_mode */ ;
/*!50003 SET sql_mode              = '' */ ;
DELIMITER ;;
CREATE DEFINER=`root`@`localhost` FUNCTION `SYSTEM_VAR@RANDOM_UNIQUE_25L`() RETURNS varchar(34) CHARSET utf8 COLLATE utf8_unicode_ci
SF_CHECK:
BEGIN

	-- Initialize
	-- _______________________________________________________________________

	-- Status
	-- ...........................................
	DECLARE STATUS_INACTIVE TINYINT DEFAULT 1;
	DECLARE STATUS_ACTIVE TINYINT DEFAULT 2;
	DECLARE STATUS_CLOSED TINYINT DEFAULT 3;
	DECLARE STATUS_COMPLETED TINYINT DEFAULT 4;

	-- Local Parameters
	-- ...........................................
	DECLARE TEMP_NOW DATETIME(6) DEFAULT `SYSTEM_VAR@NOW`('', 1);
	DECLARE TEMP_ERR_MESSAGE VARCHAR(500) DEFAULT '';
	DECLARE ERR BIGINT DEFAULT 0;
	
	DECLARE TEMP_UNIQUE_RESULT VARCHAR(34) DEFAULT '';
	DECLARE TEMP_PROCESSING_NUM BIGINT DEFAULT 0;
	DECLARE TEMP_PROCESSING_STR VARCHAR(500) DEFAULT 0;
	DECLARE TEMP_SLEEP_LENGTH DECIMAL(18, 6) DEFAULT 0;


	-- Check if SELF exists
	-- _______________________________________________________________________
	IF `ACCOUNT_SERVER@SELF_EXISTS`() = 0 THEN
		SET TEMP_UNIQUE_RESULT = 'DEF';

	ELSE
		-- Get Server Code
		SELECT
			`account_server`.`ACC_SERVER_UNIQUE_PREFIX`
		INTO
			TEMP_UNIQUE_RESULT
		FROM `account_server`
		WHERE
			`account_server`.`ACC_SERVER_ADDRESS` = 'SELF' AND
			`account_server`.`ACC_SERVER_STATUS` = STATUS_ACTIVE AND
			`account_server`.`ACC_SERVER_SYSTEM_GENERATED` = STATUS_ACTIVE
		LIMIT 1;

	END IF;	


	-- Add Current Time(MMDDHHNNSS) as Alpha32(FILL = `0`)
	-- _______________________________________________________________________
	SET TEMP_PROCESSING_STR = CONCAT(DATE_FORMAT(TEMP_NOW, '%m%d'), DATE_FORMAT(TEMP_NOW, '%k%i%s%f'));

	SET TEMP_PROCESSING_NUM = TEMP_PROCESSING_STR;
	SET TEMP_PROCESSING_STR = `SYSTEM_VAR@TO_ALPHA32`(TEMP_PROCESSING_NUM, '0', 11);
	SET TEMP_UNIQUE_RESULT = CONCAT(TEMP_UNIQUE_RESULT, TEMP_PROCESSING_STR);


	-- Add Random String(5)
	-- _______________________________________________________________________
	SET TEMP_PROCESSING_STR = `SYSTEM_VAR@RANDOM_STR`(11);
	SET TEMP_PROCESSING_STR = UCASE(TEMP_PROCESSING_STR);
	SET TEMP_UNIQUE_RESULT = CONCAT(TEMP_UNIQUE_RESULT, TEMP_PROCESSING_STR);


	-- Random Sleep
	-- _______________________________________________________________________
	SET TEMP_SLEEP_LENGTH = `SYSTEM_VAR@RANDOM`(1, 199) / 1000;
	DO SLEEP(TEMP_SLEEP_LENGTH);


	-- Return Result
	-- _______________________________________________________________________
	RETURN TEMP_UNIQUE_RESULT;

END ;;
DELIMITER ;
/*!50003 SET sql_mode              = @saved_sql_mode */ ;
/*!50003 SET character_set_client  = @saved_cs_client */ ;
/*!50003 SET character_set_results = @saved_cs_results */ ;
/*!50003 SET collation_connection  = @saved_col_connection */ ;
/*!50003 DROP FUNCTION IF EXISTS `SYSTEM_VAR@RANDOM_UNIQUE_25LV2` */;
/*!50003 SET @saved_cs_client      = @@character_set_client */ ;
/*!50003 SET @saved_cs_results     = @@character_set_results */ ;
/*!50003 SET @saved_col_connection = @@collation_connection */ ;
/*!50003 SET character_set_client  = latin1 */ ;
/*!50003 SET character_set_results = latin1 */ ;
/*!50003 SET collation_connection  = latin1_swedish_ci */ ;
/*!50003 SET @saved_sql_mode       = @@sql_mode */ ;
/*!50003 SET sql_mode              = '' */ ;
DELIMITER ;;
CREATE DEFINER=`root`@`localhost` FUNCTION `SYSTEM_VAR@RANDOM_UNIQUE_25LV2`() RETURNS varchar(34) CHARSET utf8 COLLATE utf8_unicode_ci
SF_CHECK:
BEGIN

	-- Initialize
	-- _______________________________________________________________________

	-- Status
	-- ...........................................
	DECLARE STATUS_INACTIVE TINYINT DEFAULT 1;
	DECLARE STATUS_ACTIVE TINYINT DEFAULT 2;
	DECLARE STATUS_CLOSED TINYINT DEFAULT 3;
	DECLARE STATUS_COMPLETED TINYINT DEFAULT 4;

	-- Local Parameters
	-- ...........................................
	DECLARE TEMP_NOW DATETIME(6) DEFAULT `SYSTEM_VAR@NOW`('', 1);
	DECLARE TEMP_ERR_MESSAGE VARCHAR(500) DEFAULT '';
	DECLARE ERR BIGINT DEFAULT 0;
	
	DECLARE TEMP_UNIQUE_RESULT VARCHAR(34) DEFAULT '';
	DECLARE TEMP_PROCESSING_NUM BIGINT DEFAULT 0;
	DECLARE TEMP_PROCESSING_STR VARCHAR(500) DEFAULT 0;
	DECLARE TEMP_SLEEP_LENGTH DECIMAL(18, 6) DEFAULT 0;


	-- Check if SELF exists
	-- _______________________________________________________________________
	IF `ACCOUNT_SERVER@SELF_EXISTS`() = 0 THEN
		SET TEMP_UNIQUE_RESULT = 'DEF';

	ELSE
		-- Get Server Code
		SELECT
			`account_server`.`ACC_SERVER_UNIQUE_PREFIX`
		INTO
			TEMP_UNIQUE_RESULT
		FROM `account_server`
		WHERE
			`account_server`.`ACC_SERVER_ADDRESS` = 'SELF' AND
			`account_server`.`ACC_SERVER_STATUS` = STATUS_ACTIVE AND
			`account_server`.`ACC_SERVER_SYSTEM_GENERATED` = STATUS_ACTIVE
		LIMIT 1;

	END IF;	





	-- Add Current Date(YYYYMMDD) as Alpha32(FILL = `0`)
	-- _______________________________________________________________________
	SET TEMP_PROCESSING_STR = DATE_FORMAT(TEMP_NOW, '%Y%m%d');
	
	SET TEMP_PROCESSING_NUM = TEMP_PROCESSING_STR;
	SET TEMP_PROCESSING_STR = `SYSTEM_VAR@TO_ALPHA32`(TEMP_PROCESSING_NUM, '0', 6);
	SET TEMP_UNIQUE_RESULT = CONCAT_WS('', TEMP_UNIQUE_RESULT, TEMP_PROCESSING_STR);


	-- Add Current Time(HHNNSSFFFFFF) as Alpha32(FILL = `0`)
	-- _______________________________________________________________________
	SET TEMP_PROCESSING_STR = DATE_FORMAT(TEMP_NOW, '%k%i%s%f');

	SET TEMP_PROCESSING_NUM = TEMP_PROCESSING_STR;
	SET TEMP_PROCESSING_STR = `SYSTEM_VAR@TO_ALPHA32`(TEMP_PROCESSING_NUM, '0', 8);
	SET TEMP_UNIQUE_RESULT = CONCAT_WS('', TEMP_UNIQUE_RESULT, TEMP_PROCESSING_STR);


	-- Add Random String(7)
	-- _______________________________________________________________________
	SET TEMP_PROCESSING_STR = `SYSTEM_VAR@RANDOM_STR`(8);
	SET TEMP_PROCESSING_STR = UCASE(TEMP_PROCESSING_STR);
	SET TEMP_UNIQUE_RESULT = CONCAT_WS('', TEMP_UNIQUE_RESULT, TEMP_PROCESSING_STR);


	-- Random Sleep
	-- _______________________________________________________________________	
	SET TEMP_SLEEP_LENGTH = `SYSTEM_VAR@RANDOM`(1, 25) / 1000;
	DO SLEEP(TEMP_SLEEP_LENGTH);


	-- Return Result
	-- _______________________________________________________________________
	RETURN TEMP_UNIQUE_RESULT;

END ;;
DELIMITER ;
/*!50003 SET sql_mode              = @saved_sql_mode */ ;
/*!50003 SET character_set_client  = @saved_cs_client */ ;
/*!50003 SET character_set_results = @saved_cs_results */ ;
/*!50003 SET collation_connection  = @saved_col_connection */ ;
/*!50003 DROP FUNCTION IF EXISTS `SYSTEM_VAR@RANDOM_UNIQUE_ALPHA32` */;
/*!50003 SET @saved_cs_client      = @@character_set_client */ ;
/*!50003 SET @saved_cs_results     = @@character_set_results */ ;
/*!50003 SET @saved_col_connection = @@collation_connection */ ;
/*!50003 SET character_set_client  = latin1 */ ;
/*!50003 SET character_set_results = latin1 */ ;
/*!50003 SET collation_connection  = latin1_swedish_ci */ ;
/*!50003 SET @saved_sql_mode       = @@sql_mode */ ;
/*!50003 SET sql_mode              = '' */ ;
DELIMITER ;;
CREATE DEFINER=`root`@`localhost` FUNCTION `SYSTEM_VAR@RANDOM_UNIQUE_ALPHA32`() RETURNS varchar(34) CHARSET utf8 COLLATE utf8_unicode_ci
SF_CHECK:
BEGIN

	-- Initialize
	-- _______________________________________________________________________

	-- Status
	-- ...........................................
	DECLARE STATUS_INACTIVE TINYINT DEFAULT 1;
	DECLARE STATUS_ACTIVE TINYINT DEFAULT 2;
	DECLARE STATUS_CLOSED TINYINT DEFAULT 3;
	DECLARE STATUS_COMPLETED TINYINT DEFAULT 4;

	-- Local Parameters
	-- ...........................................
	DECLARE TEMP_NOW DATETIME(6) DEFAULT `SYSTEM_VAR@NOW`('', 1);
	DECLARE TEMP_ERR_MESSAGE VARCHAR(500) DEFAULT '';
	DECLARE ERR BIGINT DEFAULT 0;
	
	DECLARE TEMP_UNIQUE_RESULT VARCHAR(34) DEFAULT '';
	DECLARE TEMP_PROCESSING_NUM BIGINT DEFAULT 0;
	DECLARE TEMP_PROCESSING_STR VARCHAR(500) DEFAULT 0;


	-- Check if SELF exists
	-- _______________________________________________________________________
	IF `ACCOUNT_SERVER@SELF_EXISTS`() = 0 THEN
		SET TEMP_UNIQUE_RESULT = 'DEF';

	ELSE
		-- Get Server Code
		SELECT
			`account_server`.`ACC_SERVER_UNIQUE_PREFIX`
		INTO
			TEMP_UNIQUE_RESULT
		FROM `account_server`
		WHERE
			`account_server`.`ACC_SERVER_ADDRESS` = 'SELF' AND
			`account_server`.`ACC_SERVER_STATUS` = STATUS_ACTIVE AND
			`account_server`.`ACC_SERVER_SYSTEM_GENERATED` = STATUS_ACTIVE
		LIMIT 1;

	END IF;	





	-- Add Current Date(YYYYMMDD) as Alpha32(FILL = `0`)
	-- _______________________________________________________________________
	SET TEMP_PROCESSING_STR = DATE_FORMAT(TEMP_NOW, '%Y%m%d');
	
	SET TEMP_PROCESSING_NUM = TEMP_PROCESSING_STR;
	SET TEMP_PROCESSING_STR = `SYSTEM_VAR@TO_ALPHA32`(TEMP_PROCESSING_NUM, '0', 6);
	SET TEMP_UNIQUE_RESULT = CONCAT_WS('.', TEMP_UNIQUE_RESULT, TEMP_PROCESSING_STR);


	-- Add Current Time(HHNNSSFFFFFF) as Alpha32(FILL = `0`)
	-- _______________________________________________________________________
	SET TEMP_PROCESSING_STR = DATE_FORMAT(TEMP_NOW, '%k%i%s%f');

	SET TEMP_PROCESSING_NUM = TEMP_PROCESSING_STR;
	SET TEMP_PROCESSING_STR = `SYSTEM_VAR@TO_ALPHA32`(TEMP_PROCESSING_NUM, '0', 8);
	SET TEMP_UNIQUE_RESULT = CONCAT_WS('.', TEMP_UNIQUE_RESULT, TEMP_PROCESSING_STR);


	-- Add Random String(7)
	-- _______________________________________________________________________
	SET TEMP_PROCESSING_STR = `SYSTEM_VAR@RANDOM_STR`(7);
	SET TEMP_PROCESSING_STR = UCASE(TEMP_PROCESSING_STR);
	SET TEMP_UNIQUE_RESULT = CONCAT_WS('.', TEMP_UNIQUE_RESULT, TEMP_PROCESSING_STR);


	-- Return Result
	-- _______________________________________________________________________
	RETURN TEMP_UNIQUE_RESULT;

END ;;
DELIMITER ;
/*!50003 SET sql_mode              = @saved_sql_mode */ ;
/*!50003 SET character_set_client  = @saved_cs_client */ ;
/*!50003 SET character_set_results = @saved_cs_results */ ;
/*!50003 SET collation_connection  = @saved_col_connection */ ;
/*!50003 DROP FUNCTION IF EXISTS `SYSTEM_VAR@RANDOM_UNIQUE_ALPHA32_SHORT` */;
/*!50003 SET @saved_cs_client      = @@character_set_client */ ;
/*!50003 SET @saved_cs_results     = @@character_set_results */ ;
/*!50003 SET @saved_col_connection = @@collation_connection */ ;
/*!50003 SET character_set_client  = latin1 */ ;
/*!50003 SET character_set_results = latin1 */ ;
/*!50003 SET collation_connection  = latin1_swedish_ci */ ;
/*!50003 SET @saved_sql_mode       = @@sql_mode */ ;
/*!50003 SET sql_mode              = '' */ ;
DELIMITER ;;
CREATE DEFINER=`root`@`localhost` FUNCTION `SYSTEM_VAR@RANDOM_UNIQUE_ALPHA32_SHORT`() RETURNS varchar(34) CHARSET utf8 COLLATE utf8_unicode_ci
SF_CHECK:
BEGIN

	-- Initialize
	-- _______________________________________________________________________

	-- Status
	-- ...........................................
	DECLARE STATUS_INACTIVE TINYINT DEFAULT 1;
	DECLARE STATUS_ACTIVE TINYINT DEFAULT 2;
	DECLARE STATUS_CLOSED TINYINT DEFAULT 3;
	DECLARE STATUS_COMPLETED TINYINT DEFAULT 4;

	-- Local Parameters
	-- ...........................................
	DECLARE TEMP_NOW DATETIME(6) DEFAULT `SYSTEM_VAR@NOW`('', 1);
	DECLARE TEMP_ERR_MESSAGE VARCHAR(500) DEFAULT '';
	DECLARE ERR BIGINT DEFAULT 0;
	
	DECLARE TEMP_UNIQUE_RESULT VARCHAR(34) DEFAULT '';
	DECLARE TEMP_PROCESSING_NUM BIGINT DEFAULT 0;
	DECLARE TEMP_PROCESSING_STR VARCHAR(500) DEFAULT 0;


	-- Check if SELF exists
	-- _______________________________________________________________________
	IF `ACCOUNT_SERVER@SELF_EXISTS`() = 0 THEN
		SET TEMP_UNIQUE_RESULT = 'DEF';

	ELSE
		-- Get Server Code
		SELECT
			`account_server`.`ACC_SERVER_UNIQUE_PREFIX`
		INTO
			TEMP_UNIQUE_RESULT
		FROM `account_server`
		WHERE
			`account_server`.`ACC_SERVER_ADDRESS` = 'SELF' AND
			`account_server`.`ACC_SERVER_STATUS` = STATUS_ACTIVE AND
			`account_server`.`ACC_SERVER_SYSTEM_GENERATED` = STATUS_ACTIVE
		LIMIT 1;

	END IF;	


	-- Add Current Date(MMDD) as Alpha32(FILL = `0`)
	-- _______________________________________________________________________
	SET TEMP_PROCESSING_STR = DATE_FORMAT(TEMP_NOW, '%m%d');
	
	SET TEMP_PROCESSING_NUM = TEMP_PROCESSING_STR;
	SET TEMP_PROCESSING_STR = `SYSTEM_VAR@TO_ALPHA32`(TEMP_PROCESSING_NUM, '0', 3);
	SET TEMP_UNIQUE_RESULT = TEMP_PROCESSING_STR;


	-- Add Current Time(HHNNSS) as Alpha32(FILL = `0`)
	-- _______________________________________________________________________
	SET TEMP_PROCESSING_STR = DATE_FORMAT(TEMP_NOW, '%k%i%s');

	SET TEMP_PROCESSING_NUM = TEMP_PROCESSING_STR;
	SET TEMP_PROCESSING_STR = `SYSTEM_VAR@TO_ALPHA32`(TEMP_PROCESSING_NUM, '0', 4);
	SET TEMP_UNIQUE_RESULT = CONCAT(TEMP_UNIQUE_RESULT, TEMP_PROCESSING_STR);


	-- Add Random String(3)
	-- _______________________________________________________________________
	SET TEMP_PROCESSING_STR = `SYSTEM_VAR@RANDOM_STR`(3);
	SET TEMP_PROCESSING_STR = UCASE(TEMP_PROCESSING_STR);
	SET TEMP_UNIQUE_RESULT = CONCAT(TEMP_UNIQUE_RESULT, TEMP_PROCESSING_STR);


	-- Return Result
	-- _______________________________________________________________________
	RETURN TEMP_UNIQUE_RESULT;

END ;;
DELIMITER ;
/*!50003 SET sql_mode              = @saved_sql_mode */ ;
/*!50003 SET character_set_client  = @saved_cs_client */ ;
/*!50003 SET character_set_results = @saved_cs_results */ ;
/*!50003 SET collation_connection  = @saved_col_connection */ ;
/*!50003 DROP FUNCTION IF EXISTS `SYSTEM_VAR@RANDOM_UNIQUE_INTCHAR` */;
/*!50003 SET @saved_cs_client      = @@character_set_client */ ;
/*!50003 SET @saved_cs_results     = @@character_set_results */ ;
/*!50003 SET @saved_col_connection = @@collation_connection */ ;
/*!50003 SET character_set_client  = latin1 */ ;
/*!50003 SET character_set_results = latin1 */ ;
/*!50003 SET collation_connection  = latin1_swedish_ci */ ;
/*!50003 SET @saved_sql_mode       = @@sql_mode */ ;
/*!50003 SET sql_mode              = '' */ ;
DELIMITER ;;
CREATE DEFINER=`root`@`localhost` FUNCTION `SYSTEM_VAR@RANDOM_UNIQUE_INTCHAR`() RETURNS varchar(40) CHARSET utf8 COLLATE utf8_unicode_ci
SF_CHECK:
BEGIN

	-- Initialize
	-- _______________________________________________________________________

	-- Status
	-- ...........................................
	DECLARE STATUS_INACTIVE TINYINT DEFAULT 1;
	DECLARE STATUS_ACTIVE TINYINT DEFAULT 2;
	DECLARE STATUS_CLOSED TINYINT DEFAULT 3;
	DECLARE STATUS_COMPLETED TINYINT DEFAULT 4;

	-- Local Parameters
	-- ...........................................
	DECLARE TEMP_NOW DATETIME(6) DEFAULT `SYSTEM_VAR@NOW`('', 1);
	DECLARE TEMP_ERR_MESSAGE VARCHAR(500) DEFAULT '';
	DECLARE ERR BIGINT DEFAULT 0;

	DECLARE TEMP_UNIQUE_RESULT VARCHAR(40) DEFAULT '';
	DECLARE TEMP_PROCESSING_NUM BIGINT DEFAULT 0;
	DECLARE TEMP_PROCESSING_STR VARCHAR(500) DEFAULT 0;


	-- Check if SELF exists
	-- _______________________________________________________________________



	-- Add Current Date(YYYYMMDD)
	-- _______________________________________________________________________
	SET TEMP_PROCESSING_STR = DATE_FORMAT(TEMP_NOW, '%Y%m%d');
	SET TEMP_UNIQUE_RESULT = TEMP_PROCESSING_STR;


	-- Add Current Time(HHNNSSFFFFFF)
	-- _______________________________________________________________________
	SET TEMP_PROCESSING_STR = DATE_FORMAT(TEMP_NOW, '%k%i%s%f');
	SET TEMP_UNIQUE_RESULT = CONCAT_WS('0', TEMP_UNIQUE_RESULT, TEMP_PROCESSING_STR);


	-- Add Random String(3)
	-- _______________________________________________________________________
	SET TEMP_PROCESSING_STR = `SYSTEM_VAR@RANDOM`(100, 999);
	SET TEMP_UNIQUE_RESULT = CONCAT_WS('0', TEMP_UNIQUE_RESULT, TEMP_PROCESSING_STR);


	-- Return Result
	-- _______________________________________________________________________
	RETURN TEMP_UNIQUE_RESULT;

END ;;
DELIMITER ;
/*!50003 SET sql_mode              = @saved_sql_mode */ ;
/*!50003 SET character_set_client  = @saved_cs_client */ ;
/*!50003 SET character_set_results = @saved_cs_results */ ;
/*!50003 SET collation_connection  = @saved_col_connection */ ;
/*!50003 DROP FUNCTION IF EXISTS `SYSTEM_VAR@RANDOM_UNIQUE_INTCHAR_SHORT` */;
/*!50003 SET @saved_cs_client      = @@character_set_client */ ;
/*!50003 SET @saved_cs_results     = @@character_set_results */ ;
/*!50003 SET @saved_col_connection = @@collation_connection */ ;
/*!50003 SET character_set_client  = latin1 */ ;
/*!50003 SET character_set_results = latin1 */ ;
/*!50003 SET collation_connection  = latin1_swedish_ci */ ;
/*!50003 SET @saved_sql_mode       = @@sql_mode */ ;
/*!50003 SET sql_mode              = '' */ ;
DELIMITER ;;
CREATE DEFINER=`root`@`localhost` FUNCTION `SYSTEM_VAR@RANDOM_UNIQUE_INTCHAR_SHORT`() RETURNS varchar(40) CHARSET utf8 COLLATE utf8_unicode_ci
SF_CHECK:
BEGIN

	-- Initialize
	-- _______________________________________________________________________

	-- Status
	-- ...........................................
	DECLARE STATUS_INACTIVE TINYINT DEFAULT 1;
	DECLARE STATUS_ACTIVE TINYINT DEFAULT 2;
	DECLARE STATUS_CLOSED TINYINT DEFAULT 3;
	DECLARE STATUS_COMPLETED TINYINT DEFAULT 4;

	-- Local Parameters
	-- ...........................................
	DECLARE TEMP_NOW DATETIME(6) DEFAULT `SYSTEM_VAR@NOW`('', 1);
	DECLARE TEMP_ERR_MESSAGE VARCHAR(500) DEFAULT '';
	DECLARE ERR BIGINT DEFAULT 0;

	DECLARE TEMP_UNIQUE_RESULT VARCHAR(40) DEFAULT '';
	DECLARE TEMP_PROCESSING_NUM BIGINT DEFAULT 0;
	DECLARE TEMP_PROCESSING_STR VARCHAR(500) DEFAULT 0;


	-- Check if SELF exists
	-- _______________________________________________________________________



	-- Add Current Date(YYYYMMDD)
	-- _______________________________________________________________________
	SET TEMP_PROCESSING_STR = DATE_FORMAT(TEMP_NOW, '%m%d');
	SET TEMP_UNIQUE_RESULT = TEMP_PROCESSING_STR;


	-- Add Current Time(HHNNSSFFFFFF)
	-- _______________________________________________________________________
	SET TEMP_PROCESSING_STR = DATE_FORMAT(TEMP_NOW, '%k%i%s');
	SET TEMP_UNIQUE_RESULT = CONCAT_WS('-', TEMP_UNIQUE_RESULT, TEMP_PROCESSING_STR);
	SET TEMP_PROCESSING_STR = UCASE(`SYSTEM_VAR@RANDOM_STR`(5));
	SET TEMP_UNIQUE_RESULT = CONCAT_WS('-', TEMP_UNIQUE_RESULT, TEMP_PROCESSING_STR);

	-- Return Result
	-- _______________________________________________________________________
	RETURN TEMP_UNIQUE_RESULT;

END ;;
DELIMITER ;
/*!50003 SET sql_mode              = @saved_sql_mode */ ;
/*!50003 SET character_set_client  = @saved_cs_client */ ;
/*!50003 SET character_set_results = @saved_cs_results */ ;
/*!50003 SET collation_connection  = @saved_col_connection */ ;
/*!50003 DROP FUNCTION IF EXISTS `SYSTEM_VAR@RANDOM_UNIQUE_STR` */;
/*!50003 SET @saved_cs_client      = @@character_set_client */ ;
/*!50003 SET @saved_cs_results     = @@character_set_results */ ;
/*!50003 SET @saved_col_connection = @@collation_connection */ ;
/*!50003 SET character_set_client  = latin1 */ ;
/*!50003 SET character_set_results = latin1 */ ;
/*!50003 SET collation_connection  = latin1_swedish_ci */ ;
/*!50003 SET @saved_sql_mode       = @@sql_mode */ ;
/*!50003 SET sql_mode              = '' */ ;
DELIMITER ;;
CREATE DEFINER=`root`@`localhost` FUNCTION `SYSTEM_VAR@RANDOM_UNIQUE_STR`() RETURNS varchar(40) CHARSET utf8 COLLATE utf8_unicode_ci
SF_CHECK:
BEGIN

	-- Initialize
	-- _______________________________________________________________________

	-- Status
	-- ...........................................
	DECLARE STATUS_INACTIVE TINYINT DEFAULT 1;
	DECLARE STATUS_ACTIVE TINYINT DEFAULT 2;
	DECLARE STATUS_CLOSED TINYINT DEFAULT 3;
	DECLARE STATUS_COMPLETED TINYINT DEFAULT 4;

	-- Local Parameters
	-- ...........................................
	DECLARE TEMP_NOW DATETIME(6) DEFAULT `SYSTEM_VAR@NOW`('', 1);
	DECLARE TEMP_ERR_MESSAGE VARCHAR(500) DEFAULT '';
	DECLARE ERR BIGINT DEFAULT 0;

	DECLARE TEMP_UNIQUE_RESULT VARCHAR(40) DEFAULT '';
	DECLARE TEMP_PROCESSING_NUM BIGINT DEFAULT 0;
	DECLARE TEMP_PROCESSING_STR VARCHAR(500) DEFAULT 0;


	-- Check if SELF exists
	-- _______________________________________________________________________
	IF `ACCOUNT_SERVER@SELF_EXISTS`() = 0 THEN
		SET TEMP_UNIQUE_RESULT = 'DEF';

	ELSE
		-- Get Server Code
		-- _______________________________________________________________________
		SELECT
			`account_server`.`ACC_SERVER_UNIQUE_PREFIX`
		INTO
			TEMP_UNIQUE_RESULT
		FROM `account_server`
		WHERE
			`account_server`.`ACC_SERVER_ADDRESS` = 'SELF' AND
			`account_server`.`ACC_SERVER_STATUS` = STATUS_ACTIVE AND
			`account_server`.`ACC_SERVER_SYSTEM_GENERATED` = STATUS_ACTIVE
		LIMIT 1;

	END IF;	



	-- Add Current Date(YYYYMMDD)
	-- _______________________________________________________________________
	SET TEMP_PROCESSING_STR = DATE_FORMAT(TEMP_NOW, '%Y%m%d');
	SET TEMP_UNIQUE_RESULT = CONCAT_WS('.', TEMP_UNIQUE_RESULT, TEMP_PROCESSING_STR);


	-- Add Current Time(HHNNSSFFFFFF)
	-- _______________________________________________________________________
	SET TEMP_PROCESSING_STR = DATE_FORMAT(TEMP_NOW, '%k%i%s%f');
	SET TEMP_UNIQUE_RESULT = CONCAT_WS('.', TEMP_UNIQUE_RESULT, TEMP_PROCESSING_STR);


	-- Add Random String(5)
	-- _______________________________________________________________________
	SET TEMP_PROCESSING_STR = `SYSTEM_VAR@RANDOM_STR`(7);
	SET TEMP_UNIQUE_RESULT = CONCAT_WS('.', TEMP_UNIQUE_RESULT, TEMP_PROCESSING_STR);


	-- Return Result
	-- _______________________________________________________________________
	RETURN TEMP_UNIQUE_RESULT;

END ;;
DELIMITER ;
/*!50003 SET sql_mode              = @saved_sql_mode */ ;
/*!50003 SET character_set_client  = @saved_cs_client */ ;
/*!50003 SET character_set_results = @saved_cs_results */ ;
/*!50003 SET collation_connection  = @saved_col_connection */ ;
/*!50003 DROP FUNCTION IF EXISTS `SYSTEM_VAR@REPLACE_NULL@BIGINT` */;
/*!50003 SET @saved_cs_client      = @@character_set_client */ ;
/*!50003 SET @saved_cs_results     = @@character_set_results */ ;
/*!50003 SET @saved_col_connection = @@collation_connection */ ;
/*!50003 SET character_set_client  = latin1 */ ;
/*!50003 SET character_set_results = latin1 */ ;
/*!50003 SET collation_connection  = latin1_swedish_ci */ ;
/*!50003 SET @saved_sql_mode       = @@sql_mode */ ;
/*!50003 SET sql_mode              = '' */ ;
DELIMITER ;;
CREATE DEFINER=`root`@`localhost` FUNCTION `SYSTEM_VAR@REPLACE_NULL@BIGINT`(
	`PARAM_CURRENT_BIGINT` BIGINT,
	`PARAM_REPLACE_BIGINT` BIGINT,
	`PARAM_TREAT_ZERO_VALUE_AS_NULL` BIT,
	`PARAM_TREAT_NEGATIVE_AS_NULL` BIT
) RETURNS bigint(20)
SF_CHECK:
BEGIN

	-- GET NULL FLAG
	-- ===================================
	DECLARE TEMP_NULL_FLAG BIGINT DEFAULT 0;

	SELECT `system_null_flag`.`SYS_BIGINT_FLAG` INTO TEMP_NULL_FLAG
	FROM `system_null_flag`
	WHERE `system_null_flag`.`SYS_FLAG_ID` = 1
	LIMIT 1;
	-- ===================================



	-- VALIDATE IF NULL
	-- ===================================
	IF 
		PARAM_CURRENT_BIGINT IS NULL OR
		PARAM_CURRENT_BIGINT <= TEMP_NULL_FLAG OR
		(
			PARAM_TREAT_ZERO_VALUE_AS_NULL = 1 AND
			PARAM_CURRENT_BIGINT = 0
		) OR
		(
			PARAM_TREAT_NEGATIVE_AS_NULL = 1 AND
			PARAM_CURRENT_BIGINT < 0
		)
	THEN
		SET PARAM_CURRENT_BIGINT = PARAM_REPLACE_BIGINT;
	END IF;
	
	return PARAM_CURRENT_BIGINT;
	-- ===================================

END ;;
DELIMITER ;
/*!50003 SET sql_mode              = @saved_sql_mode */ ;
/*!50003 SET character_set_client  = @saved_cs_client */ ;
/*!50003 SET character_set_results = @saved_cs_results */ ;
/*!50003 SET collation_connection  = @saved_col_connection */ ;
/*!50003 DROP FUNCTION IF EXISTS `SYSTEM_VAR@REPLACE_NULL@BIT` */;
/*!50003 SET @saved_cs_client      = @@character_set_client */ ;
/*!50003 SET @saved_cs_results     = @@character_set_results */ ;
/*!50003 SET @saved_col_connection = @@collation_connection */ ;
/*!50003 SET character_set_client  = latin1 */ ;
/*!50003 SET character_set_results = latin1 */ ;
/*!50003 SET collation_connection  = latin1_swedish_ci */ ;
/*!50003 SET @saved_sql_mode       = @@sql_mode */ ;
/*!50003 SET sql_mode              = '' */ ;
DELIMITER ;;
CREATE DEFINER=`root`@`localhost` FUNCTION `SYSTEM_VAR@REPLACE_NULL@BIT`(
	`PARAM_CURRENT_BIT` BIT,
	`PARAM_REPLACE_BIT` BIT,
	`PARAM_TREAT_ZERO_VALUE_AS_NULL` BIT,
	`PARAM_TREAT_NEGATIVE_AS_NULL` BIT
) RETURNS int(11)
SF_CHECK:
BEGIN



	-- VALIDATE IF NULL
	-- ===================================
	IF PARAM_CURRENT_BIT IS NULL THEN
		SET PARAM_CURRENT_BIT = PARAM_REPLACE_BIT;
	END IF;
	
	return PARAM_CURRENT_BIT;
	-- ===================================
	
END ;;
DELIMITER ;
/*!50003 SET sql_mode              = @saved_sql_mode */ ;
/*!50003 SET character_set_client  = @saved_cs_client */ ;
/*!50003 SET character_set_results = @saved_cs_results */ ;
/*!50003 SET collation_connection  = @saved_col_connection */ ;
/*!50003 DROP FUNCTION IF EXISTS `SYSTEM_VAR@REPLACE_NULL@DATETIME` */;
/*!50003 SET @saved_cs_client      = @@character_set_client */ ;
/*!50003 SET @saved_cs_results     = @@character_set_results */ ;
/*!50003 SET @saved_col_connection = @@collation_connection */ ;
/*!50003 SET character_set_client  = latin1 */ ;
/*!50003 SET character_set_results = latin1 */ ;
/*!50003 SET collation_connection  = latin1_swedish_ci */ ;
/*!50003 SET @saved_sql_mode       = @@sql_mode */ ;
/*!50003 SET sql_mode              = '' */ ;
DELIMITER ;;
CREATE DEFINER=`root`@`localhost` FUNCTION `SYSTEM_VAR@REPLACE_NULL@DATETIME`(
	`PARAM_CURRENT_DATETIME` DATETIME(6),
	`PARAM_REPLACE_DATETIME` DATETIME(6),
	`PARAM_TREAT_ZERO_VALUE_AS_NULL` BIT
) RETURNS datetime(6)
SF_CHECK:
BEGIN

	-- GET NULL FLAG
	-- ===================================
	DECLARE TEMP_NULL_FLAG DATETIME(6) DEFAULT '1000-01-01 00:00:00';

	SELECT DATE_ADD(`system_null_flag`.`SYS_DATETIME_FLAG`, INTERVAL 1 SECOND) INTO TEMP_NULL_FLAG
	FROM `system_null_flag`
	WHERE `system_null_flag`.`SYS_FLAG_ID` = 1
	LIMIT 1;
	-- ===================================


	-- VALIDATE IF NULL
	-- ===================================
	IF 
		PARAM_CURRENT_DATETIME IS NULL OR
		PARAM_CURRENT_DATETIME <= TEMP_NULL_FLAG 
	THEN
		SET PARAM_CURRENT_DATETIME = PARAM_REPLACE_DATETIME;
	END IF;
	
	return PARAM_CURRENT_DATETIME;
	-- ===================================
	
END ;;
DELIMITER ;
/*!50003 SET sql_mode              = @saved_sql_mode */ ;
/*!50003 SET character_set_client  = @saved_cs_client */ ;
/*!50003 SET character_set_results = @saved_cs_results */ ;
/*!50003 SET collation_connection  = @saved_col_connection */ ;
/*!50003 DROP FUNCTION IF EXISTS `SYSTEM_VAR@REPLACE_NULL@DECIMAL` */;
/*!50003 SET @saved_cs_client      = @@character_set_client */ ;
/*!50003 SET @saved_cs_results     = @@character_set_results */ ;
/*!50003 SET @saved_col_connection = @@collation_connection */ ;
/*!50003 SET character_set_client  = latin1 */ ;
/*!50003 SET character_set_results = latin1 */ ;
/*!50003 SET collation_connection  = latin1_swedish_ci */ ;
/*!50003 SET @saved_sql_mode       = @@sql_mode */ ;
/*!50003 SET sql_mode              = '' */ ;
DELIMITER ;;
CREATE DEFINER=`root`@`localhost` FUNCTION `SYSTEM_VAR@REPLACE_NULL@DECIMAL`(
	`PARAM_CURRENT_DECIMAL` DECIMAL(18,2),
	`PARAM_REPLACE_DECIMAL` DECIMAL(18,2),
	`PARAM_TREAT_ZERO_VALUE_AS_NULL` BIT,
	`PARAM_TREAT_NEGATIVE_AS_NULL` BIT
) RETURNS decimal(18,2)
SF_CHECK:
BEGIN

	-- GET NULL FLAG
	-- ===================================
	DECLARE TEMP_NULL_FLAG DECIMAL(18,2) DEFAULT 0;

	SELECT `system_null_flag`.`SYS_DECIMAL_FLAG` INTO TEMP_NULL_FLAG
	FROM `system_null_flag`
	WHERE `system_null_flag`.`SYS_FLAG_ID` = 1
	LIMIT 1;
	-- ===================================



	-- VALIDATE IF NULL
	-- ===================================
	IF 
		PARAM_CURRENT_DECIMAL IS NULL OR
		PARAM_CURRENT_DECIMAL <= TEMP_NULL_FLAG OR
		(
			PARAM_TREAT_ZERO_VALUE_AS_NULL = 1 AND
			PARAM_CURRENT_DECIMAL = 0
		) OR
		(
			PARAM_TREAT_NEGATIVE_AS_NULL = 1 AND
			PARAM_CURRENT_DECIMAL < 0
		)
	THEN
		SET PARAM_CURRENT_DECIMAL = PARAM_REPLACE_DECIMAL;
	END IF;
	
	return PARAM_CURRENT_DECIMAL;
	-- ===================================

END ;;
DELIMITER ;
/*!50003 SET sql_mode              = @saved_sql_mode */ ;
/*!50003 SET character_set_client  = @saved_cs_client */ ;
/*!50003 SET character_set_results = @saved_cs_results */ ;
/*!50003 SET collation_connection  = @saved_col_connection */ ;
/*!50003 DROP FUNCTION IF EXISTS `SYSTEM_VAR@REPLACE_NULL@INT` */;
/*!50003 SET @saved_cs_client      = @@character_set_client */ ;
/*!50003 SET @saved_cs_results     = @@character_set_results */ ;
/*!50003 SET @saved_col_connection = @@collation_connection */ ;
/*!50003 SET character_set_client  = latin1 */ ;
/*!50003 SET character_set_results = latin1 */ ;
/*!50003 SET collation_connection  = latin1_swedish_ci */ ;
/*!50003 SET @saved_sql_mode       = @@sql_mode */ ;
/*!50003 SET sql_mode              = '' */ ;
DELIMITER ;;
CREATE DEFINER=`root`@`localhost` FUNCTION `SYSTEM_VAR@REPLACE_NULL@INT`(
	`PARAM_CURRENT_INT` INT,
	`PARAM_REPLACE_INT` INT,
	`PARAM_TREAT_ZERO_VALUE_AS_NULL` BIT,
	`PARAM_TREAT_NEGATIVE_AS_NULL` BIT
) RETURNS int(11)
SF_CHECK:
BEGIN

	-- GET NULL FLAG
	-- ===================================
	DECLARE TEMP_NULL_FLAG INT DEFAULT 0;

	SELECT `system_null_flag`.`SYS_INT_FLAG` INTO TEMP_NULL_FLAG
	FROM `system_null_flag`
	WHERE `system_null_flag`.`SYS_FLAG_ID` = 1
	LIMIT 1;
	-- ===================================


	-- VALIDATE IF NULL
	-- ===================================
	IF 
		PARAM_CURRENT_INT IS NULL OR
		PARAM_CURRENT_INT <= TEMP_NULL_FLAG OR
		(
			PARAM_TREAT_ZERO_VALUE_AS_NULL = 1 AND
			PARAM_CURRENT_INT = 0
		) OR
		(
			PARAM_TREAT_NEGATIVE_AS_NULL = 1 AND
			PARAM_CURRENT_INT < 0
		)
	THEN
		SET PARAM_CURRENT_INT = PARAM_REPLACE_INT;
	END IF;
	
	return PARAM_CURRENT_INT;
	-- ===================================
	
END ;;
DELIMITER ;
/*!50003 SET sql_mode              = @saved_sql_mode */ ;
/*!50003 SET character_set_client  = @saved_cs_client */ ;
/*!50003 SET character_set_results = @saved_cs_results */ ;
/*!50003 SET collation_connection  = @saved_col_connection */ ;
/*!50003 DROP FUNCTION IF EXISTS `SYSTEM_VAR@REPLACE_NULL@LONGTEXT` */;
/*!50003 SET @saved_cs_client      = @@character_set_client */ ;
/*!50003 SET @saved_cs_results     = @@character_set_results */ ;
/*!50003 SET @saved_col_connection = @@collation_connection */ ;
/*!50003 SET character_set_client  = latin1 */ ;
/*!50003 SET character_set_results = latin1 */ ;
/*!50003 SET collation_connection  = latin1_swedish_ci */ ;
/*!50003 SET @saved_sql_mode       = @@sql_mode */ ;
/*!50003 SET sql_mode              = '' */ ;
DELIMITER ;;
CREATE DEFINER=`root`@`localhost` FUNCTION `SYSTEM_VAR@REPLACE_NULL@LONGTEXT`(
	`PARAM_CURRENT_LONGTEXT` LONGTEXT,
	`PARAM_REPLACE_LONGTEXT` LONGTEXT,
	`PARAM_TREAT_EMPTY_STRING_AS_NULL` BIT
) RETURNS longtext CHARSET utf8 COLLATE utf8_unicode_ci
SF_CHECK:
BEGIN

	-- GET NULL FLAG
	-- ===================================
	DECLARE TEMP_NULL_FLAG VARCHAR(50) DEFAULT "";

	SELECT `system_null_flag`.`SYS_NVARCHAR_FLAG` INTO TEMP_NULL_FLAG
	FROM `system_null_flag`
	WHERE `system_null_flag`.`SYS_FLAG_ID` = 1
	LIMIT 1;
	-- ===================================


	-- VALIDATE IF NULL
	-- ===================================
	IF 
		PARAM_CURRENT_LONGTEXT IS NULL OR
		PARAM_CURRENT_LONGTEXT = TEMP_NULL_FLAG OR
		(
			PARAM_TREAT_EMPTY_STRING_AS_NULL = 1 AND
			(
				PARAM_CURRENT_LONGTEXT = '&null;' OR
				PARAM_CURRENT_LONGTEXT = ''
			)
		)
	THEN
		SET PARAM_CURRENT_LONGTEXT = PARAM_REPLACE_LONGTEXT;
	END IF;
	
	return PARAM_CURRENT_LONGTEXT;
	-- ===================================
	
END ;;
DELIMITER ;
/*!50003 SET sql_mode              = @saved_sql_mode */ ;
/*!50003 SET character_set_client  = @saved_cs_client */ ;
/*!50003 SET character_set_results = @saved_cs_results */ ;
/*!50003 SET collation_connection  = @saved_col_connection */ ;
/*!50003 DROP FUNCTION IF EXISTS `SYSTEM_VAR@REPLACE_NULL@MEDIUMTEXT` */;
/*!50003 SET @saved_cs_client      = @@character_set_client */ ;
/*!50003 SET @saved_cs_results     = @@character_set_results */ ;
/*!50003 SET @saved_col_connection = @@collation_connection */ ;
/*!50003 SET character_set_client  = latin1 */ ;
/*!50003 SET character_set_results = latin1 */ ;
/*!50003 SET collation_connection  = latin1_swedish_ci */ ;
/*!50003 SET @saved_sql_mode       = @@sql_mode */ ;
/*!50003 SET sql_mode              = '' */ ;
DELIMITER ;;
CREATE DEFINER=`root`@`localhost` FUNCTION `SYSTEM_VAR@REPLACE_NULL@MEDIUMTEXT`(
	`PARAM_CURRENT_MEDIUMTEXT` MEDIUMTEXT,
	`PARAM_REPLACE_MEDIUMTEXT` MEDIUMTEXT,
	`PARAM_TREAT_EMPTY_STRING_AS_NULL` BIT
) RETURNS mediumtext CHARSET utf8 COLLATE utf8_unicode_ci
SF_CHECK:
BEGIN

	-- GET NULL FLAG
	-- ===================================
	DECLARE TEMP_NULL_FLAG VARCHAR(50) DEFAULT "";

	SELECT `system_null_flag`.`SYS_NVARCHAR_FLAG` INTO TEMP_NULL_FLAG
	FROM `system_null_flag`
	WHERE `system_null_flag`.`SYS_FLAG_ID` = 1
	LIMIT 1;
	-- ===================================


	-- VALIDATE IF NULL
	-- ===================================
	IF 
		PARAM_CURRENT_MEDIUMTEXT IS NULL OR
		PARAM_CURRENT_MEDIUMTEXT = TEMP_NULL_FLAG OR
		(
			PARAM_TREAT_EMPTY_STRING_AS_NULL = 1 AND
			(
				PARAM_CURRENT_MEDIUMTEXT = '&null;' OR
				PARAM_CURRENT_MEDIUMTEXT = ''
			)
		)
	THEN
		SET PARAM_CURRENT_MEDIUMTEXT = PARAM_REPLACE_MEDIUMTEXT;
	END IF;
	
	return PARAM_CURRENT_MEDIUMTEXT;
	-- ===================================
	
END ;;
DELIMITER ;
/*!50003 SET sql_mode              = @saved_sql_mode */ ;
/*!50003 SET character_set_client  = @saved_cs_client */ ;
/*!50003 SET character_set_results = @saved_cs_results */ ;
/*!50003 SET collation_connection  = @saved_col_connection */ ;
/*!50003 DROP FUNCTION IF EXISTS `SYSTEM_VAR@REPLACE_NULL@NVARCHAR` */;
/*!50003 SET @saved_cs_client      = @@character_set_client */ ;
/*!50003 SET @saved_cs_results     = @@character_set_results */ ;
/*!50003 SET @saved_col_connection = @@collation_connection */ ;
/*!50003 SET character_set_client  = latin1 */ ;
/*!50003 SET character_set_results = latin1 */ ;
/*!50003 SET collation_connection  = latin1_swedish_ci */ ;
/*!50003 SET @saved_sql_mode       = @@sql_mode */ ;
/*!50003 SET sql_mode              = '' */ ;
DELIMITER ;;
CREATE DEFINER=`root`@`localhost` FUNCTION `SYSTEM_VAR@REPLACE_NULL@NVARCHAR`(
	`PARAM_CURRENT_NVARCHAR` VARCHAR(16000),
	`PARAM_REPLACE_NVARCHAR` VARCHAR(16000),
	`PARAM_TREAT_EMPTY_STRING_AS_NULL` BIT
) RETURNS varchar(16000) CHARSET utf8 COLLATE utf8_unicode_ci
SF_CHECK:
BEGIN

	-- GET NULL FLAG
	-- ===================================
	DECLARE TEMP_NULL_FLAG VARCHAR(50) DEFAULT "";

	SELECT `system_null_flag`.`SYS_NVARCHAR_FLAG` INTO TEMP_NULL_FLAG
	FROM `system_null_flag`
	WHERE `system_null_flag`.`SYS_FLAG_ID` = 1
	LIMIT 1;
	-- ===================================


	-- VALIDATE IF NULL
	-- ===================================
	IF 
		PARAM_CURRENT_NVARCHAR IS NULL OR
		PARAM_CURRENT_NVARCHAR = TEMP_NULL_FLAG OR
		(
			PARAM_TREAT_EMPTY_STRING_AS_NULL = 1 AND
			(
				PARAM_CURRENT_NVARCHAR = '&null;' OR
				PARAM_CURRENT_NVARCHAR = ''
			)
		)
	THEN
		SET PARAM_CURRENT_NVARCHAR = PARAM_REPLACE_NVARCHAR;
	END IF;
	
	return PARAM_CURRENT_NVARCHAR;
	-- ===================================
	
END ;;
DELIMITER ;
/*!50003 SET sql_mode              = @saved_sql_mode */ ;
/*!50003 SET character_set_client  = @saved_cs_client */ ;
/*!50003 SET character_set_results = @saved_cs_results */ ;
/*!50003 SET collation_connection  = @saved_col_connection */ ;
/*!50003 DROP FUNCTION IF EXISTS `SYSTEM_VAR@REPLACE_NULL@TEXT` */;
/*!50003 SET @saved_cs_client      = @@character_set_client */ ;
/*!50003 SET @saved_cs_results     = @@character_set_results */ ;
/*!50003 SET @saved_col_connection = @@collation_connection */ ;
/*!50003 SET character_set_client  = latin1 */ ;
/*!50003 SET character_set_results = latin1 */ ;
/*!50003 SET collation_connection  = latin1_swedish_ci */ ;
/*!50003 SET @saved_sql_mode       = @@sql_mode */ ;
/*!50003 SET sql_mode              = '' */ ;
DELIMITER ;;
CREATE DEFINER=`root`@`localhost` FUNCTION `SYSTEM_VAR@REPLACE_NULL@TEXT`(
	`PARAM_CURRENT_TEXT` TEXT,
	`PARAM_REPLACE_TEXT` TEXT,
	`PARAM_TREAT_EMPTY_STRING_AS_NULL` BIT
) RETURNS text CHARSET utf8 COLLATE utf8_unicode_ci
SF_CHECK:
BEGIN

	-- GET NULL FLAG
	-- ===================================
	DECLARE TEMP_NULL_FLAG VARCHAR(50) DEFAULT "";

	SELECT `system_null_flag`.`SYS_NVARCHAR_FLAG` INTO TEMP_NULL_FLAG
	FROM `system_null_flag`
	WHERE `system_null_flag`.`SYS_FLAG_ID` = 1
	LIMIT 1;
	-- ===================================


	-- VALIDATE IF NULL
	-- ===================================
	IF 
		PARAM_CURRENT_TEXT IS NULL OR
		PARAM_CURRENT_TEXT = TEMP_NULL_FLAG OR
		(
			PARAM_TREAT_EMPTY_STRING_AS_NULL = 1 AND
			(
				PARAM_CURRENT_TEXT = '&null;' OR
				PARAM_CURRENT_TEXT = ''
			)
		)
	THEN
		SET PARAM_CURRENT_TEXT = PARAM_REPLACE_TEXT;
	END IF;
	
	return PARAM_CURRENT_TEXT;
	-- ===================================
	
END ;;
DELIMITER ;
/*!50003 SET sql_mode              = @saved_sql_mode */ ;
/*!50003 SET character_set_client  = @saved_cs_client */ ;
/*!50003 SET character_set_results = @saved_cs_results */ ;
/*!50003 SET collation_connection  = @saved_col_connection */ ;
/*!50003 DROP FUNCTION IF EXISTS `SYSTEM_VAR@REPLACE_NULL@TINYINT` */;
/*!50003 SET @saved_cs_client      = @@character_set_client */ ;
/*!50003 SET @saved_cs_results     = @@character_set_results */ ;
/*!50003 SET @saved_col_connection = @@collation_connection */ ;
/*!50003 SET character_set_client  = latin1 */ ;
/*!50003 SET character_set_results = latin1 */ ;
/*!50003 SET collation_connection  = latin1_swedish_ci */ ;
/*!50003 SET @saved_sql_mode       = @@sql_mode */ ;
/*!50003 SET sql_mode              = '' */ ;
DELIMITER ;;
CREATE DEFINER=`root`@`localhost` FUNCTION `SYSTEM_VAR@REPLACE_NULL@TINYINT`(
	`PARAM_CURRENT_TINYINT` TINYINT,
	`PARAM_REPLACE_TINYINT` TINYINT,
	`PARAM_TREAT_ZERO_VALUE_AS_NULL` BIT,
	`PARAM_TREAT_NEGATIVE_AS_NULL` BIT
) RETURNS tinyint(4)
SF_CHECK:
BEGIN

	-- VALIDATE IF NULL (TinyInt only consists of 0~255 so 0 will be null)
	-- ===================================
	IF 
		PARAM_CURRENT_TINYINT IS NULL OR
		PARAM_CURRENT_TINYINT <= 0 
	THEN
		SET PARAM_CURRENT_TINYINT = PARAM_REPLACE_TINYINT;
	END IF;
	
	return PARAM_CURRENT_TINYINT;
	-- ===================================
	
END ;;
DELIMITER ;
/*!50003 SET sql_mode              = @saved_sql_mode */ ;
/*!50003 SET character_set_client  = @saved_cs_client */ ;
/*!50003 SET character_set_results = @saved_cs_results */ ;
/*!50003 SET collation_connection  = @saved_col_connection */ ;
/*!50003 DROP FUNCTION IF EXISTS `SYSTEM_VAR@REPLACE_NULL@VARBINARY` */;
/*!50003 SET @saved_cs_client      = @@character_set_client */ ;
/*!50003 SET @saved_cs_results     = @@character_set_results */ ;
/*!50003 SET @saved_col_connection = @@collation_connection */ ;
/*!50003 SET character_set_client  = latin1 */ ;
/*!50003 SET character_set_results = latin1 */ ;
/*!50003 SET collation_connection  = latin1_swedish_ci */ ;
/*!50003 SET @saved_sql_mode       = @@sql_mode */ ;
/*!50003 SET sql_mode              = '' */ ;
DELIMITER ;;
CREATE DEFINER=`root`@`localhost` FUNCTION `SYSTEM_VAR@REPLACE_NULL@VARBINARY`(
	`PARAM_CURRENT_VARBINARY` VARBINARY(50000),
	`PARAM_REPLACE_VARBINARY` VARBINARY(50000),
	`PARAM_TREAT_ZERO_VALUE_AS_NULL` BIT
) RETURNS int(11)
SF_CHECK:
BEGIN



	-- VALIDATE IF NULL
	-- ===================================
	IF PARAM_CURRENT_VARBINARY IS NULL THEN
		SET PARAM_CURRENT_VARBINARY = PARAM_REPLACE_VARBINARY;
	END IF;
	
	return PARAM_CURRENT_VARBINARY;
	-- ===================================
	
END ;;
DELIMITER ;
/*!50003 SET sql_mode              = @saved_sql_mode */ ;
/*!50003 SET character_set_client  = @saved_cs_client */ ;
/*!50003 SET character_set_results = @saved_cs_results */ ;
/*!50003 SET collation_connection  = @saved_col_connection */ ;
/*!50003 DROP FUNCTION IF EXISTS `SYSTEM_VAR@TO_ALPHA32` */;
/*!50003 SET @saved_cs_client      = @@character_set_client */ ;
/*!50003 SET @saved_cs_results     = @@character_set_results */ ;
/*!50003 SET @saved_col_connection = @@collation_connection */ ;
/*!50003 SET character_set_client  = latin1 */ ;
/*!50003 SET character_set_results = latin1 */ ;
/*!50003 SET collation_connection  = latin1_swedish_ci */ ;
/*!50003 SET @saved_sql_mode       = @@sql_mode */ ;
/*!50003 SET sql_mode              = '' */ ;
DELIMITER ;;
CREATE DEFINER=`root`@`localhost` FUNCTION `SYSTEM_VAR@TO_ALPHA32`(
	`PARAM_NUMERIC_VALUE` BIGINT,
	`PARAM_FILL_CHARACTER` VARCHAR(1),
	`PARAM_MIN_SIZE` TINYINT
) RETURNS varchar(50) CHARSET utf8 COLLATE utf8_unicode_ci
SF_CHECK:
BEGIN

	-- INITIALIZE
	-- ========================================================
	DECLARE RESULT_ALPHA_ID VARCHAR(50) DEFAULT '';
	DECLARE SOURCE_ID BIGINT DEFAULT PARAM_NUMERIC_VALUE;
	DECLARE REM_VALUE BIGINT DEFAULT 0;
	
	DECLARE ALPHA32_KEY VARCHAR(1) DEFAULT '';
	DECLARE ALPHA32_COUNT TINYINT DEFAULT 32;
	-- ========================================================
	

	-- COMPRESS VALUE INTO ALPHA32
	-- ========================================================
    WHILE SOURCE_ID > 0 DO
	
		SET REM_VALUE = SOURCE_ID % ALPHA32_COUNT;
		
		-- INDEX_Of
		SELECT
			`system_alpha32`.`SYS_ALPHA32_KEY`
		INTO
			ALPHA32_KEY
		FROM `system_alpha32`
		WHERE
			`system_alpha32`.`SYS_ALPHA32_ID` = REM_VALUE
		LIMIT 1;
		
		SET RESULT_ALPHA_ID = CONCAT(RESULT_ALPHA_ID, ALPHA32_KEY);
		SET SOURCE_ID = (SOURCE_ID - REM_VALUE) / ALPHA32_COUNT;
		
	END WHILE;
	-- ========================================================

	
	-- FILL UPTO MIN_SIZE
	-- ========================================================
	SET PARAM_FILL_CHARACTER = `SYSTEM_VAR@REPLACE_NULL@NVARCHAR`(PARAM_FILL_CHARACTER, '0', 1);
	WHILE CHAR_LENGTH(RESULT_ALPHA_ID) < PARAM_MIN_SIZE DO
		SET RESULT_ALPHA_ID = CONCAT(PARAM_FILL_CHARACTER, RESULT_ALPHA_ID);
	END WHILE;
	-- ========================================================
	
    Return RESULT_ALPHA_ID;
	
END ;;
DELIMITER ;
/*!50003 SET sql_mode              = @saved_sql_mode */ ;
/*!50003 SET character_set_client  = @saved_cs_client */ ;
/*!50003 SET character_set_results = @saved_cs_results */ ;
/*!50003 SET collation_connection  = @saved_col_connection */ ;
/*!50003 DROP FUNCTION IF EXISTS `SYSTEM_VAR@TO_ALPHA34` */;
/*!50003 SET @saved_cs_client      = @@character_set_client */ ;
/*!50003 SET @saved_cs_results     = @@character_set_results */ ;
/*!50003 SET @saved_col_connection = @@collation_connection */ ;
/*!50003 SET character_set_client  = latin1 */ ;
/*!50003 SET character_set_results = latin1 */ ;
/*!50003 SET collation_connection  = latin1_swedish_ci */ ;
/*!50003 SET @saved_sql_mode       = @@sql_mode */ ;
/*!50003 SET sql_mode              = '' */ ;
DELIMITER ;;
CREATE DEFINER=`root`@`localhost` FUNCTION `SYSTEM_VAR@TO_ALPHA34`(
	`PARAM_NUMERIC_VALUE` BIGINT,
	`PARAM_FILL_CHARACTER` VARCHAR(1),
	`PARAM_MIN_SIZE` TINYINT
) RETURNS varchar(50) CHARSET utf8 COLLATE utf8_unicode_ci
SF_CHECK:
BEGIN

	-- INITIALIZE
	-- ========================================================
	DECLARE RESULT_ALPHA_ID VARCHAR(50) DEFAULT '';
	DECLARE SOURCE_ID BIGINT DEFAULT PARAM_NUMERIC_VALUE;
	DECLARE REM_VALUE BIGINT DEFAULT 0;
	
	DECLARE ALPHA34_KEY VARCHAR(1) DEFAULT '';
	DECLARE ALPHA34_COUNT TINYINT DEFAULT 34;
	-- ========================================================
	

	-- COMPRESS VALUE INTO ALPHA34
	-- ========================================================
    WHILE SOURCE_ID > 0 DO
	
		SET REM_VALUE = SOURCE_ID % ALPHA34_COUNT;
		
		-- INDEX_Of
		SELECT
			`system_alpha34`.`SYS_ALPHA34_KEY`
		INTO
			ALPHA34_KEY
		FROM `system_alpha34`
		WHERE
			`system_alpha34`.`SYS_ALPHA34_ID` = REM_VALUE
		LIMIT 1;
		
		SET RESULT_ALPHA_ID = CONCAT(RESULT_ALPHA_ID, ALPHA34_KEY);
		SET SOURCE_ID = (SOURCE_ID - REM_VALUE) / ALPHA34_COUNT;
		
	END WHILE;
	-- ========================================================

	
	-- FILL UPTO MIN_SIZE
	-- ========================================================
	SET PARAM_FILL_CHARACTER = `SYSTEM_VAR@REPLACE_NULL@NVARCHAR`(PARAM_FILL_CHARACTER, '0', 1);
	WHILE CHAR_LENGTH(RESULT_ALPHA_ID) < PARAM_MIN_SIZE DO
		SET RESULT_ALPHA_ID = CONCAT(PARAM_FILL_CHARACTER, RESULT_ALPHA_ID);
	END WHILE;
	-- ========================================================
	
    Return RESULT_ALPHA_ID;
	
END ;;
DELIMITER ;
/*!50003 SET sql_mode              = @saved_sql_mode */ ;
/*!50003 SET character_set_client  = @saved_cs_client */ ;
/*!50003 SET character_set_results = @saved_cs_results */ ;
/*!50003 SET collation_connection  = @saved_col_connection */ ;
/*!50003 DROP PROCEDURE IF EXISTS `ACCOUNT_ACCESS_RIGHTS_DENY` */;
/*!50003 SET @saved_cs_client      = @@character_set_client */ ;
/*!50003 SET @saved_cs_results     = @@character_set_results */ ;
/*!50003 SET @saved_col_connection = @@collation_connection */ ;
/*!50003 SET character_set_client  = latin1 */ ;
/*!50003 SET character_set_results = latin1 */ ;
/*!50003 SET collation_connection  = latin1_swedish_ci */ ;
/*!50003 SET @saved_sql_mode       = @@sql_mode */ ;
/*!50003 SET sql_mode              = '' */ ;
DELIMITER ;;
CREATE DEFINER=`root`@`localhost` PROCEDURE `ACCOUNT_ACCESS_RIGHTS_DENY`(
	IN `PARAM_MODULE_ID` BIGINT,
	IN `PARAM_MODULE_KEYWORD` VARCHAR(1000),
	IN `PARAM_TARGET_ID` BIGINT,
	IN `PARAM_TARGET_SERVER_ID` BIGINT,
	IN `PARAM_TRAIL_DESCRIPTION` VARCHAR(16000),
	IN `PARAM_TRAIL_PARAMETERS` VARCHAR(16000),

	IN `PARAM_REQUESTER_USERNAME` VARCHAR(500),
	IN `PARAM_REQUESTER_PASSWORD` VARCHAR(500),
	IN `PARAM_REQUESTER_PROXY_ID` BIGINT,
	IN `PARAM_REQUESTER_PROXY_PASSWORD` VARCHAR(1000),
	IN `PARAM_REQUESTER_DEVICE_PUBLIC_KEY` VARCHAR(1000),
	IN `PARAM_REQUESTER_DEVICE_PRIVATE_KEY` VARCHAR(1000),
	
	IN `PARAM_REQUESTER_IP` VARCHAR(1000),
	IN `PARAM_UNIQUE_SESSION_ID` VARCHAR(1000),
	IN `PARAM_SOURCE_SERVER_ID` BIGINT,
	IN `PARAM_SUPPRESS_RETURN` BIT
)
SP_GET:
BEGIN

	-- Initialize
	-- ...........................................
	DECLARE ERR BIGINT DEFAULT 0;

	
	-- Error Catch
	-- ...........................................
	DECLARE EXIT HANDLER FOR SQLEXCEPTION
	BEGIN
		RESIGNAL;
	END;
	
	-- Save security breach attempt
	-- ...........................................
	SET PARAM_TRAIL_DESCRIPTION = CONCAT_WS(' ', 'Illegal access to feature:', PARAM_TRAIL_DESCRIPTION);
	CALL `ACCOUNT_AUDIT_TRAIL_SAVE` 
		(
			PARAM_MODULE_ID, 
			PARAM_MODULE_KEYWORD, 
			PARAM_TARGET_ID, 
			PARAM_TARGET_SERVER_ID,
			'DENY',
			PARAM_TRAIL_DESCRIPTION, 
			PARAM_TRAIL_PARAMETERS, 
			
			PARAM_REQUESTER_USERNAME, 
			PARAM_REQUESTER_PASSWORD, 
			PARAM_REQUESTER_PROXY_ID,
			PARAM_REQUESTER_PROXY_PASSWORD,
			PARAM_REQUESTER_DEVICE_PUBLIC_KEY,
			PARAM_REQUESTER_DEVICE_PRIVATE_KEY,			
			
			PARAM_REQUESTER_IP,
			PARAM_UNIQUE_SESSION_ID,
			PARAM_SOURCE_SERVER_ID,
			PARAM_SUPPRESS_RETURN
		);
	
	-- Save security breach attempt
	SET ERR = `RAISERROR`('YOU DON''T HAVE ENOUGHT RIGHTS TO ACCESS THIS FEATURE');

END ;;
DELIMITER ;
/*!50003 SET sql_mode              = @saved_sql_mode */ ;
/*!50003 SET character_set_client  = @saved_cs_client */ ;
/*!50003 SET character_set_results = @saved_cs_results */ ;
/*!50003 SET collation_connection  = @saved_col_connection */ ;
/*!50003 DROP PROCEDURE IF EXISTS `ACCOUNT_ACCESS_RIGHTS_GET` */;
/*!50003 SET @saved_cs_client      = @@character_set_client */ ;
/*!50003 SET @saved_cs_results     = @@character_set_results */ ;
/*!50003 SET @saved_col_connection = @@collation_connection */ ;
/*!50003 SET character_set_client  = latin1 */ ;
/*!50003 SET character_set_results = latin1 */ ;
/*!50003 SET collation_connection  = latin1_swedish_ci */ ;
/*!50003 SET @saved_sql_mode       = @@sql_mode */ ;
/*!50003 SET sql_mode              = '' */ ;
DELIMITER ;;
CREATE DEFINER=`root`@`localhost` PROCEDURE `ACCOUNT_ACCESS_RIGHTS_GET`(
	PARAM_ACC_ACCESS_ID BIGINT,
	PARAM_ACC_ACCESS_SERVER_ID BIGINT,
	PARAM_ACC_ACCESS_ACC_LEVEL_ID BIGINT,
	PARAM_ACC_ACCESS_SYS_MODULE_ID BIGINT,
	PARAM_SYS_MODULE_KEYWORD VARCHAR(500),
	PARAM_ACC_ACCESS_SYS_AUTHORITY_ID BIGINT,
	PARAM_ACC_ACCESS_AUTHORITY_POINT_FROM BIGINT,
	PARAM_ACC_ACCESS_AUTHORITY_POINT_TO BIGINT,
		
	PARAM_ORDER_FIELD VARCHAR(500),
	PARAM_ORDER_TYPE VARCHAR(500),
	PARAM_SKIP BIGINT,
	PARAM_LIMIT BIGINT,

	PARAM_REQUESTER_USERNAME VARCHAR(500),
	PARAM_REQUESTER_PASSWORD VARCHAR(500),
	PARAM_REQUESTER_PROXY_ID BIGINT,
	PARAM_REQUESTER_PROXY_PASSWORD VARCHAR(1000),
	PARAM_REQUESTER_DEVICE_PUBLIC_KEY VARCHAR(1000),
	PARAM_REQUESTER_DEVICE_PRIVATE_KEY VARCHAR(1000),
	
	PARAM_REQUESTER_IP VARCHAR(1000),
	PARAM_UNIQUE_SESSION_ID VARCHAR(1000),
	PARAM_SUPPRESS_RETURN BIT
)
SP_GET:
BEGIN

	-- Initialize
	-- _______________________________________________________________________
	
	-- Status
	-- ...........................................
	DECLARE STATUS_INACTIVE TINYINT DEFAULT 1;
	DECLARE STATUS_ACTIVE TINYINT DEFAULT 2;
	DECLARE STATUS_CLOSED TINYINT DEFAULT 3;
	DECLARE STATUS_COMPLETED TINYINT DEFAULT 4;

	-- Audit Handler
	-- ...........................................
	DECLARE TEMP_RECORD_EXISTS BIT DEFAULT 0;
	DECLARE TEMP_MODULE_KEYWORD VARCHAR(500) DEFAULT 'account_access_rights';
	DECLARE TEMP_SP_OBJECTIVE VARCHAR(500) DEFAULT 'Retrieve Access Rights record';
	DECLARE TEMP_ERR_MESSAGE VARCHAR(500) DEFAULT '';
	DECLARE ERR BIGINT DEFAULT 0;
	DECLARE TEMP_RECORD_CHANGES VARCHAR(16000) DEFAULT '';
	DECLARE TEMP_RECORD_BINDED BIT DEFAULT 0;
	
	DECLARE TEMP_RECORD_BINDED_ID BIGINT DEFAULT 0;
	DECLARE TEMP_RECORD_BINDED_SERVER_ID BIGINT DEFAULT 0;

	-- Authentication
	-- ...........................................
	DECLARE TEMP_ACCESS_RIGHTS_DENIED BIT DEFAULT 0;
	DECLARE TEMP_AUTHENTICATED_ACCOUNT_ID BIGINT DEFAULT `ACCOUNT_MEMBER@ACC_ACCOUNT_ID_FROM_LOGIN`(PARAM_REQUESTER_USERNAME, PARAM_REQUESTER_PASSWORD);
	DECLARE TEMP_AUTHENTICATED_ACCOUNT_LEVEL BIGINT DEFAULT `ACCOUNT_MEMBER@ACC_ACCOUNT_LEVEL_FROM_LOGIN`(PARAM_REQUESTER_USERNAME, PARAM_REQUESTER_PASSWORD);

	-- Local Parameters
	-- ...........................................
	DECLARE TEMP_NOW DATETIME(6) DEFAULT `SYSTEM_VAR@NOW`('', 1);
	DECLARE TEMP_RECORD_COUNT BIGINT DEFAULT 0;

	-- Check NULLs
	-- ...........................................
	DECLARE IS_NULL_ACC_ACCESS_ID BIT DEFAULT `SYSTEM_VAR@IS_NULL@BIGINT`(PARAM_ACC_ACCESS_ID, 1, 1);
	DECLARE IS_NULL_ACC_ACCESS_SERVER_ID BIT DEFAULT `SYSTEM_VAR@IS_NULL@BIGINT`(PARAM_ACC_ACCESS_SERVER_ID, 1, 1);
	DECLARE IS_NULL_ACC_ACCESS_ACC_LEVEL_ID BIT DEFAULT `SYSTEM_VAR@IS_NULL@BIGINT`(PARAM_ACC_ACCESS_ACC_LEVEL_ID, 1, 1);
	DECLARE IS_NULL_ACC_ACCESS_SYS_MODULE_ID BIT DEFAULT `SYSTEM_VAR@IS_NULL@BIGINT`(PARAM_ACC_ACCESS_SYS_MODULE_ID, 1, 1);
	DECLARE IS_NULL_SYS_MODULE_KEYWORD BIT DEFAULT `SYSTEM_VAR@IS_NULL@NVARCHAR`(PARAM_SYS_MODULE_KEYWORD, 1);
	DECLARE IS_NULL_ACC_ACCESS_SYS_AUTHORITY_ID BIT DEFAULT `SYSTEM_VAR@IS_NULL@BIGINT`(PARAM_ACC_ACCESS_SYS_AUTHORITY_ID, 1, 1);
	DECLARE IS_NULL_ACC_ACCESS_AUTHORITY_POINT_FROM BIT DEFAULT `SYSTEM_VAR@IS_NULL@BIGINT`(PARAM_ACC_ACCESS_AUTHORITY_POINT_FROM, 0, 1);
	DECLARE IS_NULL_ACC_ACCESS_AUTHORITY_POINT_TO BIT DEFAULT `SYSTEM_VAR@IS_NULL@BIGINT`(PARAM_ACC_ACCESS_AUTHORITY_POINT_TO, 0, 1);


	-- 2) Try Catch / Throw
	-- _______________________________________________________________________
	DECLARE EXIT HANDLER FOR SQLEXCEPTION
	BEGIN
		RESIGNAL;
	END;

	
	-- Prepare DateTime
	-- _______________________________________________________________________
	

	-- Access Rights [Device]
	-- _______________________________________________________________________
	IF `ACCOUNT_DEVICE@HAS_PERMISSION`(PARAM_REQUESTER_DEVICE_PUBLIC_KEY, PARAM_REQUESTER_DEVICE_PRIVATE_KEY) = 0 THEN
		SET TEMP_ERR_MESSAGE = 'Your device is not authorized yet to access this server.';
		SET ERR = `RAISERROR`(TEMP_ERR_MESSAGE);		
	END IF;
		
		
	-- Access Rights [Account]
	-- _______________________________________________________________________
	IF
		(
			(
				TEMP_AUTHENTICATED_ACCOUNT_LEVEL <> PARAM_ACC_ACCESS_ACC_LEVEL_ID AND
				`ACCOUNT_MEMBER@ACC_ACCOUNT_LEVEL_FROM_PROXY_LOGIN`(PARAM_REQUESTER_PROXY_ID, PARAM_REQUESTER_PROXY_PASSWORD ) <> PARAM_ACC_ACCESS_ACC_LEVEL_ID
			) OR
			`SYSTEM_VAR@IS_NULL@BIGINT`(PARAM_ACC_ACCESS_ACC_LEVEL_ID, 1, 1) = 1
		) AND
		`ACCOUNT_ACCESS_RIGHTS@HAS_PERMISSION`(PARAM_REQUESTER_USERNAME, PARAM_REQUESTER_PASSWORD, 0, TEMP_MODULE_KEYWORD, 1) = 0 
	THEN
		SET TEMP_ACCESS_RIGHTS_DENIED = 1;
		CALL `ACCOUNT_ACCESS_RIGHTS_DENY`
		(
			0, TEMP_MODULE_KEYWORD, 0, 0, TEMP_SP_OBJECTIVE, TEMP_RECORD_CHANGES, 
			PARAM_REQUESTER_USERNAME, PARAM_REQUESTER_PASSWORD, 
			PARAM_REQUESTER_PROXY_ID, PARAM_REQUESTER_PROXY_PASSWORD,
			PARAM_REQUESTER_DEVICE_PUBLIC_KEY, PARAM_REQUESTER_DEVICE_PRIVATE_KEY,
			PARAM_REQUESTER_IP, PARAM_UNIQUE_SESSION_ID,
			0, PARAM_SUPPRESS_RETURN
		);
	END IF;


	-- COUNT RECORD
	-- _______________________________________________________________________
	
	-- Select Fields
	-- ####################################################
	SELECT
		COUNT(DISTINCT `account_access_rights`.`ACC_ACCESS_ID`)
	INTO
		TEMP_RECORD_COUNT

		
	-- INNER JOINS
	-- ####################################################
	FROM `account_access_rights`
		
		-- Add Inner Joins (Per Foreign -key)
		-- ...........................................
		INNER JOIN `account_level` ON
		`account_level`.`ACC_LEVEL_ID` = `account_access_rights`.`ACC_ACCESS_ACC_LEVEL_ID`
		
		-- ~~~~~	
		
		INNER JOIN `system_module` ON
		`system_module`.`SYS_MODULE_ID` = `account_access_rights`.`ACC_ACCESS_SYS_MODULE_ID` AND
		(
			IS_NULL_SYS_MODULE_KEYWORD = 1 OR
			`system_module`.`SYS_MODULE_KEYWORD` = PARAM_SYS_MODULE_KEYWORD 
		)
		
		-- ~~~~~	
		
		INNER JOIN `system_access_rights_authority` ON
		`system_access_rights_authority`.`SYS_AUTHORITY_ID` = `account_access_rights`.`ACC_ACCESS_SYS_AUTHORITY_ID`

		-- Add Optional Left Joins (Per Optional Foreign-key)
		-- ...........................................

	-- CONDITIONS
	-- ####################################################
	WHERE
		(
			IS_NULL_ACC_ACCESS_ID = 1 OR
			`account_access_rights`.`ACC_ACCESS_ID` = PARAM_ACC_ACCESS_ID			
		) AND
		(
			IS_NULL_ACC_ACCESS_SERVER_ID = 1 OR
			`account_access_rights`.`ACC_ACCESS_SERVER_ID` = PARAM_ACC_ACCESS_SERVER_ID			
		) AND
		(
			IS_NULL_ACC_ACCESS_ACC_LEVEL_ID = 1 OR
			`account_access_rights`.`ACC_ACCESS_ACC_LEVEL_ID` = PARAM_ACC_ACCESS_ACC_LEVEL_ID			
		) AND
		(
			IS_NULL_ACC_ACCESS_SYS_MODULE_ID = 1 OR
			`account_access_rights`.`ACC_ACCESS_SYS_MODULE_ID` = PARAM_ACC_ACCESS_SYS_MODULE_ID			
		) AND
		(
			IS_NULL_ACC_ACCESS_SYS_AUTHORITY_ID = 1 OR
			`account_access_rights`.`ACC_ACCESS_SYS_AUTHORITY_ID` = PARAM_ACC_ACCESS_SYS_AUTHORITY_ID			
		) AND
		(
			IS_NULL_ACC_ACCESS_AUTHORITY_POINT_FROM = 1 OR
			`account_access_rights`.`ACC_ACCESS_AUTHORITY_POINT` >= PARAM_ACC_ACCESS_AUTHORITY_POINT_FROM			
		) AND
		(
			IS_NULL_ACC_ACCESS_AUTHORITY_POINT_TO = 1 OR
			`account_access_rights`.`ACC_ACCESS_AUTHORITY_POINT` <= PARAM_ACC_ACCESS_AUTHORITY_POINT_TO			
		);
	
	
	
	-- SELECT ACCOUNTS
	-- _______________________________________________________________________
	
	-- Select Fields
	-- ####################################################
	SELECT
		-- ACCOUNT_ACCESS_RIGHTS DETAILS
		`account_access_rights`.`ACC_ACCESS_ID`, 
		`account_access_rights`.`ACC_ACCESS_SERVER_ID`, 
		`account_access_rights`.`ACC_ACCESS_ACC_LEVEL_ID`, 
		`account_access_rights`.`ACC_ACCESS_SYS_MODULE_ID`, 
		`account_access_rights`.`ACC_ACCESS_SYS_AUTHORITY_ID`, 
		`account_access_rights`.`ACC_ACCESS_AUTHORITY_POINT`
		
		-- Inner join fields
		,
		`account_level`.`ACC_LEVEL_ID`, 
		`account_level`.`ACC_LEVEL_SERVER_ID`, 
		`account_level`.`ACC_LEVEL_TAG_ID`, 
		`account_level`.`ACC_LEVEL_DESCRIPTION`, 
		`account_level`.`ACC_LEVEL_STATUS`, 
		`account_level`.`ACC_LEVEL_SYSTEM_GENERATED`, 

		`system_module`.`SYS_MODULE_ID`, 
		`system_module`.`SYS_MODULE_CATEGORY`, 
		`system_module`.`SYS_MODULE_KEYWORD`, 
		`system_module`.`SYS_MODULE_NAME`, 
		`system_module`.`SYS_MODULE_DESCRIPTION`, 
		`system_module`.`SYS_MODULE_SHOW_ACCESS_RIGHTS`, 
		`system_module`.`SYS_MODULE_STATUS`, 
		`system_module`.`SYS_MODULE_SYNC_SAVE_UP_TIMESTAMP`, 
		`system_module`.`SYS_MODULE_SYNC_SAVE_DL_TIMESTAMP`, 
		`system_module`.`SYS_MODULE_SYNC_DELETE_UP_TIMESTAMP`, 
		`system_module`.`SYS_MODULE_SYNC_DELETE_DL_TIMESTAMP`, 

		`system_access_rights_authority`.`SYS_AUTHORITY_ID`, 
		`system_access_rights_authority`.`SYS_AUTHORITY_DESCRIPTION`, 
		`system_access_rights_authority`.`SYS_AUTHORITY_STATUS`
		
		-- Left join fields
		
	
		, TEMP_RECORD_COUNT AS RECORD_COUNT

		
	-- INNER JOINS
	-- ####################################################
	FROM `account_access_rights`
		
		-- Add Inner Joins (Per Foreign -key)
		-- ...........................................
		INNER JOIN `account_level` ON
		`account_level`.`ACC_LEVEL_ID` = `account_access_rights`.`ACC_ACCESS_ACC_LEVEL_ID`
		
		-- ~~~~~	
		
		INNER JOIN `system_module` ON
		`system_module`.`SYS_MODULE_ID` = `account_access_rights`.`ACC_ACCESS_SYS_MODULE_ID` AND
		(
			IS_NULL_SYS_MODULE_KEYWORD = 1 OR
			`system_module`.`SYS_MODULE_KEYWORD` = PARAM_SYS_MODULE_KEYWORD 
		)
		
		-- ~~~~~	
		
		INNER JOIN `system_access_rights_authority` ON
		`system_access_rights_authority`.`SYS_AUTHORITY_ID` = `account_access_rights`.`ACC_ACCESS_SYS_AUTHORITY_ID`

		-- Add Optional Left Joins (Per Optional Foreign-key)
		-- ...........................................


	-- CONDITIONS
	-- ####################################################
	WHERE
		(
			IS_NULL_ACC_ACCESS_ID = 1 OR
			`account_access_rights`.`ACC_ACCESS_ID` = PARAM_ACC_ACCESS_ID			
		) AND
		(
			IS_NULL_ACC_ACCESS_SERVER_ID = 1 OR
			`account_access_rights`.`ACC_ACCESS_SERVER_ID` = PARAM_ACC_ACCESS_SERVER_ID			
		) AND
		(
			IS_NULL_ACC_ACCESS_ACC_LEVEL_ID = 1 OR
			`account_access_rights`.`ACC_ACCESS_ACC_LEVEL_ID` = PARAM_ACC_ACCESS_ACC_LEVEL_ID			
		) AND
		(
			IS_NULL_ACC_ACCESS_SYS_MODULE_ID = 1 OR
			`account_access_rights`.`ACC_ACCESS_SYS_MODULE_ID` = PARAM_ACC_ACCESS_SYS_MODULE_ID			
		) AND
		(
			IS_NULL_ACC_ACCESS_SYS_AUTHORITY_ID = 1 OR
			`account_access_rights`.`ACC_ACCESS_SYS_AUTHORITY_ID` = PARAM_ACC_ACCESS_SYS_AUTHORITY_ID			
		) AND
		(
			IS_NULL_ACC_ACCESS_AUTHORITY_POINT_FROM = 1 OR
			`account_access_rights`.`ACC_ACCESS_AUTHORITY_POINT` >= PARAM_ACC_ACCESS_AUTHORITY_POINT_FROM			
		) AND
		(
			IS_NULL_ACC_ACCESS_AUTHORITY_POINT_TO = 1 OR
			`account_access_rights`.`ACC_ACCESS_AUTHORITY_POINT` <= PARAM_ACC_ACCESS_AUTHORITY_POINT_TO			
		) 		

	-- ORDER BY
	-- ####################################################
	ORDER BY
		-- ACCOUNT_ACCESS_RIGHTS DETAILS
		-- ...........................................
		CASE WHEN PARAM_ORDER_FIELD = 'ACC_ACCESS_ID' AND PARAM_ORDER_TYPE = 'ASC' THEN `account_access_rights`.`ACC_ACCESS_ID` END ASC, 
		CASE WHEN PARAM_ORDER_FIELD = 'ACC_ACCESS_ID' AND PARAM_ORDER_TYPE = 'DESC' THEN `account_access_rights`.`ACC_ACCESS_ID` END DESC,	
		CASE WHEN PARAM_ORDER_FIELD = 'ACC_ACCESS_SERVER_ID' AND PARAM_ORDER_TYPE = 'ASC' THEN `account_access_rights`.`ACC_ACCESS_SERVER_ID` END ASC, 
		CASE WHEN PARAM_ORDER_FIELD = 'ACC_ACCESS_SERVER_ID' AND PARAM_ORDER_TYPE = 'DESC' THEN `account_access_rights`.`ACC_ACCESS_SERVER_ID` END DESC,	
		CASE WHEN PARAM_ORDER_FIELD = 'ACC_ACCESS_ACC_LEVEL_ID' AND PARAM_ORDER_TYPE = 'ASC' THEN `account_access_rights`.`ACC_ACCESS_ACC_LEVEL_ID` END ASC, 
		CASE WHEN PARAM_ORDER_FIELD = 'ACC_ACCESS_ACC_LEVEL_ID' AND PARAM_ORDER_TYPE = 'DESC' THEN `account_access_rights`.`ACC_ACCESS_ACC_LEVEL_ID` END DESC,	
		CASE WHEN PARAM_ORDER_FIELD = 'ACC_ACCESS_SYS_MODULE_ID' AND PARAM_ORDER_TYPE = 'ASC' THEN `account_access_rights`.`ACC_ACCESS_SYS_MODULE_ID` END ASC, 
		CASE WHEN PARAM_ORDER_FIELD = 'ACC_ACCESS_SYS_MODULE_ID' AND PARAM_ORDER_TYPE = 'DESC' THEN `account_access_rights`.`ACC_ACCESS_SYS_MODULE_ID` END DESC,	
		CASE WHEN PARAM_ORDER_FIELD = 'ACC_ACCESS_SYS_AUTHORITY_ID' AND PARAM_ORDER_TYPE = 'ASC' THEN `account_access_rights`.`ACC_ACCESS_SYS_AUTHORITY_ID` END ASC, 
		CASE WHEN PARAM_ORDER_FIELD = 'ACC_ACCESS_SYS_AUTHORITY_ID' AND PARAM_ORDER_TYPE = 'DESC' THEN `account_access_rights`.`ACC_ACCESS_SYS_AUTHORITY_ID` END DESC,	
		CASE WHEN PARAM_ORDER_FIELD = 'ACC_ACCESS_AUTHORITY_POINT' AND PARAM_ORDER_TYPE = 'ASC' THEN `account_access_rights`.`ACC_ACCESS_AUTHORITY_POINT` END ASC, 
		CASE WHEN PARAM_ORDER_FIELD = 'ACC_ACCESS_AUTHORITY_POINT' AND PARAM_ORDER_TYPE = 'DESC' THEN `account_access_rights`.`ACC_ACCESS_AUTHORITY_POINT` END DESC,	
	
		-- Inner joins
		-- ...........................................
		CASE WHEN PARAM_ORDER_FIELD = 'ACC_LEVEL_ID' AND PARAM_ORDER_TYPE = 'ASC' THEN `account_level`.`ACC_LEVEL_ID` END ASC, 
		CASE WHEN PARAM_ORDER_FIELD = 'ACC_LEVEL_ID' AND PARAM_ORDER_TYPE = 'DESC' THEN `account_level`.`ACC_LEVEL_ID` END DESC,	
		CASE WHEN PARAM_ORDER_FIELD = 'ACC_LEVEL_SERVER_ID' AND PARAM_ORDER_TYPE = 'ASC' THEN `account_level`.`ACC_LEVEL_SERVER_ID` END ASC, 
		CASE WHEN PARAM_ORDER_FIELD = 'ACC_LEVEL_SERVER_ID' AND PARAM_ORDER_TYPE = 'DESC' THEN `account_level`.`ACC_LEVEL_SERVER_ID` END DESC,	
		CASE WHEN PARAM_ORDER_FIELD = 'ACC_LEVEL_TAG_ID' AND PARAM_ORDER_TYPE = 'ASC' THEN `account_level`.`ACC_LEVEL_TAG_ID` END ASC, 
		CASE WHEN PARAM_ORDER_FIELD = 'ACC_LEVEL_TAG_ID' AND PARAM_ORDER_TYPE = 'DESC' THEN `account_level`.`ACC_LEVEL_TAG_ID` END DESC,	
		CASE WHEN PARAM_ORDER_FIELD = 'ACC_LEVEL_DESCRIPTION' AND PARAM_ORDER_TYPE = 'ASC' THEN `account_level`.`ACC_LEVEL_DESCRIPTION` END ASC, 
		CASE WHEN PARAM_ORDER_FIELD = 'ACC_LEVEL_DESCRIPTION' AND PARAM_ORDER_TYPE = 'DESC' THEN `account_level`.`ACC_LEVEL_DESCRIPTION` END DESC,	
		CASE WHEN PARAM_ORDER_FIELD = 'ACC_LEVEL_STATUS' AND PARAM_ORDER_TYPE = 'ASC' THEN `account_level`.`ACC_LEVEL_STATUS` END ASC, 
		CASE WHEN PARAM_ORDER_FIELD = 'ACC_LEVEL_STATUS' AND PARAM_ORDER_TYPE = 'DESC' THEN `account_level`.`ACC_LEVEL_STATUS` END DESC,	
		CASE WHEN PARAM_ORDER_FIELD = 'ACC_LEVEL_SYSTEM_GENERATED' AND PARAM_ORDER_TYPE = 'ASC' THEN `account_level`.`ACC_LEVEL_SYSTEM_GENERATED` END ASC, 
		CASE WHEN PARAM_ORDER_FIELD = 'ACC_LEVEL_SYSTEM_GENERATED' AND PARAM_ORDER_TYPE = 'DESC' THEN `account_level`.`ACC_LEVEL_SYSTEM_GENERATED` END DESC,	
		CASE WHEN PARAM_ORDER_FIELD = 'SYS_MODULE_ID' AND PARAM_ORDER_TYPE = 'ASC' THEN `system_module`.`SYS_MODULE_ID` END ASC, 
		CASE WHEN PARAM_ORDER_FIELD = 'SYS_MODULE_ID' AND PARAM_ORDER_TYPE = 'DESC' THEN `system_module`.`SYS_MODULE_ID` END DESC,	
		CASE WHEN PARAM_ORDER_FIELD = 'SYS_MODULE_CATEGORY' AND PARAM_ORDER_TYPE = 'ASC' THEN `system_module`.`SYS_MODULE_CATEGORY` END ASC, 
		CASE WHEN PARAM_ORDER_FIELD = 'SYS_MODULE_CATEGORY' AND PARAM_ORDER_TYPE = 'DESC' THEN `system_module`.`SYS_MODULE_CATEGORY` END DESC,	
		CASE WHEN PARAM_ORDER_FIELD = 'SYS_MODULE_KEYWORD' AND PARAM_ORDER_TYPE = 'ASC' THEN `system_module`.`SYS_MODULE_KEYWORD` END ASC, 
		CASE WHEN PARAM_ORDER_FIELD = 'SYS_MODULE_KEYWORD' AND PARAM_ORDER_TYPE = 'DESC' THEN `system_module`.`SYS_MODULE_KEYWORD` END DESC,	
		CASE WHEN PARAM_ORDER_FIELD = 'SYS_MODULE_NAME' AND PARAM_ORDER_TYPE = 'ASC' THEN `system_module`.`SYS_MODULE_NAME` END ASC, 
		CASE WHEN PARAM_ORDER_FIELD = 'SYS_MODULE_NAME' AND PARAM_ORDER_TYPE = 'DESC' THEN `system_module`.`SYS_MODULE_NAME` END DESC,	
		CASE WHEN PARAM_ORDER_FIELD = 'SYS_MODULE_DESCRIPTION' AND PARAM_ORDER_TYPE = 'ASC' THEN `system_module`.`SYS_MODULE_DESCRIPTION` END ASC, 
		CASE WHEN PARAM_ORDER_FIELD = 'SYS_MODULE_DESCRIPTION' AND PARAM_ORDER_TYPE = 'DESC' THEN `system_module`.`SYS_MODULE_DESCRIPTION` END DESC,	
		CASE WHEN PARAM_ORDER_FIELD = 'SYS_MODULE_SHOW_ACCESS_RIGHTS' AND PARAM_ORDER_TYPE = 'ASC' THEN `system_module`.`SYS_MODULE_SHOW_ACCESS_RIGHTS` END ASC, 
		CASE WHEN PARAM_ORDER_FIELD = 'SYS_MODULE_SHOW_ACCESS_RIGHTS' AND PARAM_ORDER_TYPE = 'DESC' THEN `system_module`.`SYS_MODULE_SHOW_ACCESS_RIGHTS` END DESC,	
		CASE WHEN PARAM_ORDER_FIELD = 'SYS_MODULE_STATUS' AND PARAM_ORDER_TYPE = 'ASC' THEN `system_module`.`SYS_MODULE_STATUS`	END ASC, 
		CASE WHEN PARAM_ORDER_FIELD = 'SYS_MODULE_STATUS' AND PARAM_ORDER_TYPE = 'DESC' THEN `system_module`.`SYS_MODULE_STATUS` END DESC,	
		CASE WHEN PARAM_ORDER_FIELD = 'SYS_MODULE_SYNC_SAVE_UP_TIMESTAMP' AND PARAM_ORDER_TYPE = 'ASC' THEN `system_module`.`SYS_MODULE_SYNC_SAVE_UP_TIMESTAMP` END ASC, 
		CASE WHEN PARAM_ORDER_FIELD = 'SYS_MODULE_SYNC_SAVE_UP_TIMESTAMP' AND PARAM_ORDER_TYPE = 'DESC' THEN `system_module`.`SYS_MODULE_SYNC_SAVE_UP_TIMESTAMP` END DESC,	
		CASE WHEN PARAM_ORDER_FIELD = 'SYS_MODULE_SYNC_SAVE_DL_TIMESTAMP' AND PARAM_ORDER_TYPE = 'ASC' THEN `system_module`.`SYS_MODULE_SYNC_SAVE_DL_TIMESTAMP` END ASC, 
		CASE WHEN PARAM_ORDER_FIELD = 'SYS_MODULE_SYNC_SAVE_DL_TIMESTAMP' AND PARAM_ORDER_TYPE = 'DESC' THEN `system_module`.`SYS_MODULE_SYNC_SAVE_DL_TIMESTAMP` END DESC,	
		CASE WHEN PARAM_ORDER_FIELD = 'SYS_MODULE_SYNC_DELETE_UP_TIMESTAMP' AND PARAM_ORDER_TYPE = 'ASC' THEN `system_module`.`SYS_MODULE_SYNC_DELETE_UP_TIMESTAMP` END ASC, 
		CASE WHEN PARAM_ORDER_FIELD = 'SYS_MODULE_SYNC_DELETE_UP_TIMESTAMP' AND PARAM_ORDER_TYPE = 'DESC' THEN `system_module`.`SYS_MODULE_SYNC_DELETE_UP_TIMESTAMP` END DESC,	
		CASE WHEN PARAM_ORDER_FIELD = 'SYS_MODULE_SYNC_DELETE_DL_TIMESTAMP' AND PARAM_ORDER_TYPE = 'ASC' THEN `system_module`.`SYS_MODULE_SYNC_DELETE_DL_TIMESTAMP` END ASC, 
		CASE WHEN PARAM_ORDER_FIELD = 'SYS_MODULE_SYNC_DELETE_DL_TIMESTAMP' AND PARAM_ORDER_TYPE = 'DESC' THEN `system_module`.`SYS_MODULE_SYNC_DELETE_DL_TIMESTAMP` END DESC,	
		CASE WHEN PARAM_ORDER_FIELD = 'SYS_AUTHORITY_ID' AND PARAM_ORDER_TYPE = 'ASC' THEN `system_access_rights_authority`.`SYS_AUTHORITY_ID` END ASC, 
		CASE WHEN PARAM_ORDER_FIELD = 'SYS_AUTHORITY_ID' AND PARAM_ORDER_TYPE = 'DESC' THEN `system_access_rights_authority`.`SYS_AUTHORITY_ID` END DESC,	
		CASE WHEN PARAM_ORDER_FIELD = 'SYS_AUTHORITY_DESCRIPTION' AND PARAM_ORDER_TYPE = 'ASC' THEN `system_access_rights_authority`.`SYS_AUTHORITY_DESCRIPTION` END ASC, 
		CASE WHEN PARAM_ORDER_FIELD = 'SYS_AUTHORITY_DESCRIPTION' AND PARAM_ORDER_TYPE = 'DESC' THEN `system_access_rights_authority`.`SYS_AUTHORITY_DESCRIPTION` END DESC,	
		CASE WHEN PARAM_ORDER_FIELD = 'SYS_AUTHORITY_STATUS' AND PARAM_ORDER_TYPE = 'ASC' THEN `system_access_rights_authority`.`SYS_AUTHORITY_STATUS` END ASC, 
		CASE WHEN PARAM_ORDER_FIELD = 'SYS_AUTHORITY_STATUS' AND PARAM_ORDER_TYPE = 'DESC' THEN `system_access_rights_authority`.`SYS_AUTHORITY_STATUS` END DESC,	
	
		-- EXTRA	
		-- ...........................................
		CASE WHEN PARAM_ORDER_FIELD <> 'ACC_ACCESS_SYS_MODULE_ID' THEN `account_access_rights`.`ACC_ACCESS_SYS_MODULE_ID` END ASC
		

	-- LIMIT & OFFSET
	-- ####################################################					
	LIMIT PARAM_SKIP, PARAM_LIMIT;

	
	
	-- EXIT PROCEDURE
	-- _______________________________________________________________________
	LEAVE SP_GET;

END ;;
DELIMITER ;
/*!50003 SET sql_mode              = @saved_sql_mode */ ;
/*!50003 SET character_set_client  = @saved_cs_client */ ;
/*!50003 SET character_set_results = @saved_cs_results */ ;
/*!50003 SET collation_connection  = @saved_col_connection */ ;
/*!50003 DROP PROCEDURE IF EXISTS `ACCOUNT_ACCESS_RIGHTS_PREPARE` */;
/*!50003 SET @saved_cs_client      = @@character_set_client */ ;
/*!50003 SET @saved_cs_results     = @@character_set_results */ ;
/*!50003 SET @saved_col_connection = @@collation_connection */ ;
/*!50003 SET character_set_client  = latin1 */ ;
/*!50003 SET character_set_results = latin1 */ ;
/*!50003 SET collation_connection  = latin1_swedish_ci */ ;
/*!50003 SET @saved_sql_mode       = @@sql_mode */ ;
/*!50003 SET sql_mode              = '' */ ;
DELIMITER ;;
CREATE DEFINER=`root`@`localhost` PROCEDURE `ACCOUNT_ACCESS_RIGHTS_PREPARE`(
	IN `PARAM_ACC_ACCOUNT_LEVEL` BIGINT,
	
	IN `PARAM_REQUESTER_USERNAME` VARCHAR(500),
	IN `PARAM_REQUESTER_PASSWORD` VARCHAR(500),
	IN `PARAM_REQUESTER_PROXY_ID` BIGINT,
	IN `PARAM_REQUESTER_PROXY_PASSWORD` VARCHAR(1000),
	IN `PARAM_REQUESTER_DEVICE_PUBLIC_KEY` VARCHAR(1000),
	IN `PARAM_REQUESTER_DEVICE_PRIVATE_KEY` VARCHAR(1000),
	
	IN `PARAM_REQUESTER_IP` VARCHAR(1000),
	IN `PARAM_UNIQUE_SESSION_ID` VARCHAR(1000),
	IN `PARAM_SUPPRESS_RETURN` BIT
)
SP_SAVE:
BEGIN

	-- Initialize
	-- _______________________________________________________________________
	
	-- Status
	-- ...........................................
	DECLARE STATUS_INACTIVE TINYINT DEFAULT 1;
	DECLARE STATUS_ACTIVE TINYINT DEFAULT 2;
	DECLARE STATUS_CLOSED TINYINT DEFAULT 3;
	DECLARE STATUS_COMPLETED TINYINT DEFAULT 4;
	
	-- Audit Handler
	-- ...........................................
	DECLARE TEMP_RECORD_EXISTS BIT DEFAULT 0;
	DECLARE TEMP_MODULE_KEYWORD VARCHAR(500) DEFAULT 'account_access_rights';
	DECLARE TEMP_SP_OBJECTIVE VARCHAR(500) DEFAULT 'add/edit Access rights record';
	DECLARE TEMP_ERR_MESSAGE VARCHAR(500) DEFAULT '';
	DECLARE ERR BIGINT DEFAULT 0;
	DECLARE TEMP_RECORD_CHANGES VARCHAR(16000) DEFAULT '';
	DECLARE TEMP_RECORD_BINDED BIT DEFAULT 0;
	
	DECLARE TEMP_RECORD_BINDED_ID BIGINT DEFAULT 0;
	DECLARE TEMP_RECORD_BINDED_SERVER_ID BIGINT DEFAULT 0;
		
	-- Authentication
	-- ...........................................
	DECLARE TEMP_ACCESS_RIGHTS_DENIED BIT DEFAULT 0;
	DECLARE TEMP_AUTHENTICATED_ACCOUNT_ID BIGINT DEFAULT `ACCOUNT_MEMBER@ACC_ACCOUNT_ID_FROM_LOGIN`(PARAM_REQUESTER_USERNAME, PARAM_REQUESTER_PASSWORD);
	DECLARE TEMP_AUTHENTICATED_ACCOUNT_LEVEL BIGINT DEFAULT 0;
		
	-- Local Parameters
	-- ...........................................
	DECLARE TEMP_NOW DATETIME(6) DEFAULT `SYSTEM_VAR@NOW`('', 1);
	DECLARE TEMP_RECORD_COUNT BIGINT DEFAULT 0;

	DECLARE TEMP_MODULE_ID BIGINT DEFAULT 0;
	DECLARE TEMP_MODULE_CTR BIGINT DEFAULT 0;

	DECLARE TEMP_ACCESS_ID BIGINT DEFAULT 0;
	DECLARE TEMP_ACCESS_SERVER_ID BIGINT DEFAULT 0;
	


	-- Error Handler
	-- _______________________________________________________________________
	DECLARE EXIT HANDLER FOR SQLEXCEPTION
	BEGIN
		RESIGNAL;
	END;

	

	-- DATA VALIDATION
	-- _______________________________________________________________________
	IF PARAM_ACC_ACCOUNT_LEVEL = 0 THEN
		SET TEMP_ERR_MESSAGE = CONCAT_WS(' ', 'MISSING PARAMETER `PARAM_ACC_ACCOUNT_LEVEL` :', PARAM_ACC_ACCOUNT_LEVEL);
		SET ERR = `RAISERROR`(PARAM_ERR_MESSAGE);
	END IF;
	

	-- CHECK IF LEVEL EXISTS
	-- _______________________________________________________________________
	IF `ACCOUNT_LEVEL@ACC_LEVEL_ID_EXISTS`(PARAM_ACC_ACCOUNT_LEVEL, 0) = 0 THEN
		SET TEMP_ERR_MESSAGE = CONCAT_WS(' ', 'INVALID INDEX IN `PARAM_ACC_ACCOUNT_LEVEL` :', PARAM_ACC_ACCOUNT_LEVEL);
		SET ERR = `RAISERROR`(PARAM_ERR_MESSAGE);
	END IF;

	
	-- Load System Account
	-- _______________________________________________________________________
	SET PARAM_REQUESTER_USERNAME = 'system';
	SET PARAM_REQUESTER_PASSWORD = `ACCOUNT_MEMBER@SYSTEM_PASSWORD`();
	

	-- ADD ACCESS RIGHTS IF NOT YET CREATED
	-- _______________________________________________________________________
	WHILE
	(
		SELECT COUNT(`system_module`.`SYS_MODULE_ID`)
		FROM `system_module`
		WHERE 
			`system_module`.`SYS_MODULE_ID` > TEMP_MODULE_ID AND
			`system_module`.`SYS_MODULE_STATUS` = 2 AND
			`system_module`.`SYS_MODULE_SHOW_ACCESS_RIGHTS` = 2
		LIMIT 1
	) >= 1
	DO
	
		-- RETRIEVE MODULE ID
		-- ...........................................
		SELECT 
			`system_module`.`SYS_MODULE_ID`
		INTO
			TEMP_MODULE_ID
		FROM `system_module`
		WHERE 
			`system_module`.`SYS_MODULE_ID` > TEMP_MODULE_ID AND
			`system_module`.`SYS_MODULE_STATUS` = 2 AND
			`system_module`.`SYS_MODULE_SHOW_ACCESS_RIGHTS` = 2
		ORDER BY 
			`system_module`.`SYS_MODULE_ID` ASC
		LIMIT 1;
		
		
		-- SAVE IF NOT EXISTS
		-- ...........................................
		IF
		(
			SELECT COUNT(`account_access_rights`.`ACC_ACCESS_ID`)
			FROM `account_access_rights`
			WHERE 
				`account_access_rights`.`ACC_ACCESS_ACC_LEVEL_ID` = PARAM_ACC_ACCOUNT_LEVEL AND
				`account_access_rights`.`ACC_ACCESS_SYS_MODULE_ID` = TEMP_MODULE_ID
			LIMIT 1
		) <= 0
		THEN
		
			INSERT INTO `account_access_rights`
			(
				`account_access_rights`.`ACC_ACCESS_SERVER_ID`,
				`account_access_rights`.`ACC_ACCESS_ACC_LEVEL_ID`,
				`account_access_rights`.`ACC_ACCESS_SYS_MODULE_ID`,
				`account_access_rights`.`ACC_ACCESS_SYS_AUTHORITY_ID`,
				`account_access_rights`.`ACC_ACCESS_AUTHORITY_POINT`
			)
			VALUES
			(
				0,
				PARAM_ACC_ACCOUNT_LEVEL,
				TEMP_MODULE_ID,
				0,
				0
			);
			SET TEMP_ACCESS_ID = LAST_INSERT_ID();
			
			
			-- PREPARE AUDIT TRAIL
			-- .....................................................................................................
			SET TEMP_RECORD_CHANGES = 
			`SYSTEM_VAR@CONCAT_ADD`
			(
				' | ', TEMP_RECORD_CHANGES, CONCAT_WS
				(
					' ',
					'LEVEL: 0 ("")',
					' > ', PARAM_ACC_ACCOUNT_LEVEL, '("', `ACCOUNT_LEVEL@ACC_LEVEL_DESCRIPTION_FROM_ID`(PARAM_ACC_ACCOUNT_LEVEL), '")'
				)
			);

			SET TEMP_RECORD_CHANGES = 
			`SYSTEM_VAR@CONCAT_ADD`
			(
				' | ', TEMP_RECORD_CHANGES, CONCAT_WS
				(
					' ',
					'MODULE: 0 ("")',
					' > ', TEMP_MODULE_ID, '("', `SYSTEM_MODULE@SYS_MODULE_NAME_FROM_ID`(TEMP_MODULE_ID), '")'
				)
			);
			
			SET TEMP_RECORD_CHANGES = 
			`SYSTEM_VAR@CONCAT_ADD`
			(
				' | ', TEMP_RECORD_CHANGES, CONCAT_WS
				(
					' ',
					'AUTHORITY:  0 ("")',
					' > 0 ("', `SYSTEM_ACCESS_RIGHTS_AUTHORITY@SYS_AUTHORITY_DESCRIPTION_FROM_ID`(0), '")'
				)
			);
			
			CALL `ACCOUNT_AUDIT_TRAIL_SAVE`
			(
				0, TEMP_MODULE_KEYWORD, TEMP_ACCESS_ID, 0, 'SAVE', TEMP_SP_OBJECTIVE, TEMP_RECORD_CHANGES, 
				PARAM_REQUESTER_USERNAME, PARAM_REQUESTER_PASSWORD, 
				PARAM_REQUESTER_PROXY_ID, PARAM_REQUESTER_PROXY_PASSWORD,
				PARAM_REQUESTER_DEVICE_PUBLIC_KEY, PARAM_REQUESTER_DEVICE_PRIVATE_KEY,
				PARAM_REQUESTER_IP, PARAM_UNIQUE_SESSION_ID,
				0, PARAM_SUPPRESS_RETURN
			);
			-- .....................................................................................................
			
		END IF;
		
		-- Escape if too many modules to handle
		IF TEMP_MODULE_CTR = 9999
		THEN
			SET TEMP_ERR_MESSAGE = CONCAT_WS(' ', 'REQUEST TIME OUT: [TOO MANY MODULES]. LAST PROCESSED MODULE ID :', TEMP_MODULE_ID);
			SET ERR = `RAISERROR`(PARAM_ERR_MESSAGE);
		END IF;
		
		-- COUNT MODULE#
		SET TEMP_MODULE_CTR = TEMP_MODULE_CTR + 1;
		
	END WHILE;
			
			
			
	-- Set All visitor rights to [None]
	-- _______________________________________________________________________
	IF PARAM_ACC_ACCOUNT_LEVEL = 1 THEN
		SET TEMP_ACCESS_ID = 0;
		
		WHILE
		(
			SELECT COUNT(`account_access_rights`.`ACC_ACCESS_ID`)
			FROM `account_access_rights`
			WHERE 
				`account_access_rights`.`ACC_ACCESS_ID` > TEMP_ACCESS_ID AND
				`account_access_rights`.`ACC_ACCESS_ACC_LEVEL_ID` <= 1 AND
				(
					`account_access_rights`.`ACC_ACCESS_SYS_AUTHORITY_ID` <> 0 OR
					`account_access_rights`.`ACC_ACCESS_AUTHORITY_POINT` > 0
				)
			LIMIT 1
		) >= 1
		DO
		
			-- Load access rights ID
			-- ...........................................
			SELECT 
				`account_access_rights`.`ACC_ACCESS_ID`,
				`account_access_rights`.`ACC_ACCESS_SERVER_ID`
			INTO
				TEMP_ACCESS_ID,
				TEMP_ACCESS_SERVER_ID
			FROM `account_access_rights`
			WHERE 
				`account_access_rights`.`ACC_ACCESS_ID` > TEMP_ACCESS_ID AND
				`account_access_rights`.`ACC_ACCESS_ACC_LEVEL_ID` <= 1 AND
				(
					`account_access_rights`.`ACC_ACCESS_SYS_AUTHORITY_ID` <> 0 OR
					`account_access_rights`.`ACC_ACCESS_AUTHORITY_POINT` > 0
				)
			ORDER BY `account_access_rights`.`ACC_ACCESS_ID` ASC
			LIMIT 1;

			
			-- Update access rights
			-- ...........................................
			UPDATE `account_access_rights`
			SET
				`account_access_rights`.`ACC_ACCESS_SYS_AUTHORITY_ID` = 0,
				`account_access_rights`.`ACC_ACCESS_AUTHORITY_POINT` = 0
			WHERE
				`account_access_rights`.`ACC_ACCESS_ID` = TEMP_ACCESS_ID
			LIMIT 1;	
		
		
			-- PREPARE AUDIT TRAIL
			-- .....................................................................................................
			SET TEMP_RECORD_CHANGES = 
			`SYSTEM_VAR@CONCAT_ADD`
			(
				' | ', TEMP_RECORD_CHANGES, CONCAT_WS
				(
					' ',
					'AUTHORITY:  0 ("")',
					' > 0 ("', `SYSTEM_ACCESS_RIGHTS_AUTHORITY@SYS_AUTHORITY_DESCRIPTION_FROM_ID`(0), '")'
				)
			);
			
			CALL `ACCOUNT_AUDIT_TRAIL_SAVE`
			(
				0, TEMP_MODULE_KEYWORD, TEMP_ACCESS_ID, TEMP_ACCESS_SERVER_ID, 'SAVE', TEMP_SP_OBJECTIVE, TEMP_RECORD_CHANGES, 
				PARAM_REQUESTER_USERNAME, PARAM_REQUESTER_PASSWORD, 
				PARAM_REQUESTER_PROXY_ID, PARAM_REQUESTER_PROXY_PASSWORD,
				PARAM_REQUESTER_DEVICE_PUBLIC_KEY, PARAM_REQUESTER_DEVICE_PRIVATE_KEY,
				PARAM_REQUESTER_IP, PARAM_UNIQUE_SESSION_ID,
				0, PARAM_SUPPRESS_RETURN
			);
			-- .....................................................................................................
		
		END WHILE;	
	END IF;

	
	
	-- Set All system admin rights to [Overwrite]
	-- _______________________________________________________________________
	IF PARAM_ACC_ACCOUNT_LEVEL = 2 THEN
		SET TEMP_ACCESS_ID = 0;
		
		WHILE
		(
			SELECT COUNT(`account_access_rights`.`ACC_ACCESS_ID`)
			FROM `account_access_rights`
			WHERE 
				`account_access_rights`.`ACC_ACCESS_ID` > TEMP_ACCESS_ID AND
				`account_access_rights`.`ACC_ACCESS_ACC_LEVEL_ID` = 2 AND
				(
					`account_access_rights`.`ACC_ACCESS_SYS_AUTHORITY_ID` <> 5 OR
					`account_access_rights`.`ACC_ACCESS_AUTHORITY_POINT` < 999999
				)
			LIMIT 1
		) >= 1
		DO
		
			-- Load access rights ID
			-- ...........................................
			SELECT 
				`account_access_rights`.`ACC_ACCESS_ID`,
				`account_access_rights`.`ACC_ACCESS_SERVER_ID`
			INTO
				TEMP_ACCESS_ID,
				TEMP_ACCESS_SERVER_ID
			FROM `account_access_rights`
			WHERE 
				`account_access_rights`.`ACC_ACCESS_ID` > TEMP_ACCESS_ID AND
				`account_access_rights`.`ACC_ACCESS_ACC_LEVEL_ID` = 2 AND
				(
					`account_access_rights`.`ACC_ACCESS_SYS_AUTHORITY_ID` <> 5 OR
					`account_access_rights`.`ACC_ACCESS_AUTHORITY_POINT` < 999999
				)
			ORDER BY `account_access_rights`.`ACC_ACCESS_ID` ASC
			LIMIT 1;

			
			-- Update access rights
			-- ...........................................
			UPDATE `account_access_rights`
			SET
				`account_access_rights`.`ACC_ACCESS_SYS_AUTHORITY_ID` = 5,
				`account_access_rights`.`ACC_ACCESS_AUTHORITY_POINT` = 999999
			WHERE
				`account_access_rights`.`ACC_ACCESS_ID` = TEMP_ACCESS_ID
			LIMIT 1;
		
		
			-- PREPARE AUDIT TRAIL
			-- .....................................................................................................
			SET TEMP_RECORD_CHANGES = 
			`SYSTEM_VAR@CONCAT_ADD`
			(
				' | ', TEMP_RECORD_CHANGES, CONCAT_WS
				(
					' ',
					'AUTHORITY:  0 ("")',
					' > 4 ("', `SYSTEM_ACCESS_RIGHTS_AUTHORITY@SYS_AUTHORITY_DESCRIPTION_FROM_ID`(4), '")'
				)
			);
			
			CALL `ACCOUNT_AUDIT_TRAIL_SAVE`
			(
				0, TEMP_MODULE_KEYWORD, TEMP_ACCESS_ID, TEMP_ACCESS_SERVER_ID, 'SAVE', TEMP_SP_OBJECTIVE, TEMP_RECORD_CHANGES, 
				PARAM_REQUESTER_USERNAME, PARAM_REQUESTER_PASSWORD, 
				PARAM_REQUESTER_PROXY_ID, PARAM_REQUESTER_PROXY_PASSWORD,
				PARAM_REQUESTER_DEVICE_PUBLIC_KEY, PARAM_REQUESTER_DEVICE_PRIVATE_KEY,
				PARAM_REQUESTER_IP, PARAM_UNIQUE_SESSION_ID,
				0, PARAM_SUPPRESS_RETURN
			);
			-- .....................................................................................................
		
		END WHILE;	
	END IF;		
	
	
	-- Set All system mobile admin rights to [Overwrite for mobile modules]
	-- ====================================================================================================================================================================
	IF 
		PARAM_ACC_ACCOUNT_LEVEL = 3 AND
		(
			SELECT COUNT(`account_level`.`ACC_LEVEL_ID`)
			FROM `account_level`
			WHERE
				`account_level`.`ACC_LEVEL_ID` = 3 AND
				`account_level`.`ACC_LEVEL_DESCRIPTION` = 'Mobile Admin' AND
				`account_level`.`ACC_LEVEL_SYSTEM_GENERATED` = 2
			LIMIT 1
		) >= 1
	THEN
		SET TEMP_ACCESS_ID = 0;
		
		WHILE
		(
			SELECT COUNT(`account_access_rights`.`ACC_ACCESS_ID`)
			FROM `account_access_rights`
			WHERE 
				`account_access_rights`.`ACC_ACCESS_ID` > TEMP_ACCESS_ID AND
				`account_access_rights`.`ACC_ACCESS_ACC_LEVEL_ID` = 3 AND
				`account_access_rights`.`ACC_ACCESS_SYS_MODULE_ID` >= 30000 AND
				`account_access_rights`.`ACC_ACCESS_SYS_MODULE_ID` < 40000 AND
				`account_access_rights`.`ACC_ACCESS_SYS_AUTHORITY_ID` <> 5
			LIMIT 1
		) >= 1
		DO
		
			-- Load access rights ID
			SELECT 
				`account_access_rights`.`ACC_ACCESS_ID`,
				`account_access_rights`.`ACC_ACCESS_SERVER_ID`
			INTO
				TEMP_ACCESS_ID,
				TEMP_ACCESS_SERVER_ID
			FROM `account_access_rights`
			WHERE 
				`account_access_rights`.`ACC_ACCESS_ID` > TEMP_ACCESS_ID AND
				`account_access_rights`.`ACC_ACCESS_ACC_LEVEL_ID` = 3 AND
				`account_access_rights`.`ACC_ACCESS_SYS_MODULE_ID` >= 30000 AND
				`account_access_rights`.`ACC_ACCESS_SYS_MODULE_ID` < 40000 AND
				`account_access_rights`.`ACC_ACCESS_SYS_AUTHORITY_ID` <> 5
			ORDER BY `account_access_rights`.`ACC_ACCESS_ID` ASC
			LIMIT 1;

			
			-- Update access rights
			UPDATE `account_access_rights`
			SET
				`account_access_rights`.`ACC_ACCESS_SYS_AUTHORITY_ID` = 5,
				`account_access_rights`.`ACC_ACCESS_AUTHORITY_POINT` = 999999
			WHERE
				`account_access_rights`.`ACC_ACCESS_ID` = TEMP_ACCESS_ID
			LIMIT 1;
		
		
			-- PREPARE AUDIT TRAIL
			-- .....................................................................................................
			SET TEMP_RECORD_CHANGES = 
			`SYSTEM_VAR@CONCAT_ADD`
			(
				' | ', TEMP_RECORD_CHANGES, CONCAT_WS
				(
					' ',
					'AUTHORITY:  0 ("")',
					' > 4 ("', `SYSTEM_ACCESS_RIGHTS_AUTHORITY@SYS_AUTHORITY_DESCRIPTION_FROM_ID`(4), '")'
				)
			);
			
			CALL `ACCOUNT_AUDIT_TRAIL_SAVE`
			(
				0, TEMP_MODULE_KEYWORD, TEMP_ACCESS_ID, TEMP_ACCESS_SERVER_ID, 'SAVE', TEMP_SP_OBJECTIVE, TEMP_RECORD_CHANGES, 
				PARAM_REQUESTER_USERNAME, PARAM_REQUESTER_PASSWORD, 
				PARAM_REQUESTER_PROXY_ID, PARAM_REQUESTER_PROXY_PASSWORD,
				PARAM_REQUESTER_DEVICE_PUBLIC_KEY, PARAM_REQUESTER_DEVICE_PRIVATE_KEY,
				PARAM_REQUESTER_IP, PARAM_UNIQUE_SESSION_ID,
				0, PARAM_SUPPRESS_RETURN
			);
			-- .....................................................................................................
		
		END WHILE;	
	END IF;		
	
END ;;
DELIMITER ;
/*!50003 SET sql_mode              = @saved_sql_mode */ ;
/*!50003 SET character_set_client  = @saved_cs_client */ ;
/*!50003 SET character_set_results = @saved_cs_results */ ;
/*!50003 SET collation_connection  = @saved_col_connection */ ;
/*!50003 DROP PROCEDURE IF EXISTS `ACCOUNT_ACCESS_RIGHTS_SAVE` */;
/*!50003 SET @saved_cs_client      = @@character_set_client */ ;
/*!50003 SET @saved_cs_results     = @@character_set_results */ ;
/*!50003 SET @saved_col_connection = @@collation_connection */ ;
/*!50003 SET character_set_client  = latin1 */ ;
/*!50003 SET character_set_results = latin1 */ ;
/*!50003 SET collation_connection  = latin1_swedish_ci */ ;
/*!50003 SET @saved_sql_mode       = @@sql_mode */ ;
/*!50003 SET sql_mode              = '' */ ;
DELIMITER ;;
CREATE DEFINER=`root`@`localhost` PROCEDURE `ACCOUNT_ACCESS_RIGHTS_SAVE`(
	IN `PARAM_ACC_ACCESS_ID` BIGINT,
	IN `PARAM_ACC_ACCESS_SERVER_ID` BIGINT,
	
	IN `PARAM_ACC_ACCESS_ACC_LEVEL_ID` BIGINT,
	IN `PARAM_ACC_ACCESS_SYS_MODULE_ID` BIGINT,
	IN `PARAM_ACC_ACCESS_SYS_AUTHORITY_ID` INT,
	IN `PARAM_ACC_ACCESS_AUTHORITY_POINT` BIGINT,

	IN `PARAM_REQUESTER_USERNAME` VARCHAR(500),
	IN `PARAM_REQUESTER_PASSWORD` VARCHAR(500),
	IN `PARAM_REQUESTER_PROXY_ID` BIGINT,
	IN `PARAM_REQUESTER_PROXY_PASSWORD` VARCHAR(1000),
	IN `PARAM_REQUESTER_DEVICE_PUBLIC_KEY` VARCHAR(1000),
	IN `PARAM_REQUESTER_DEVICE_PRIVATE_KEY` VARCHAR(1000),
	
	IN `PARAM_REQUESTER_IP` VARCHAR(1000),
	IN `PARAM_UNIQUE_SESSION_ID` VARCHAR(1000),
	IN `PARAM_SUPPRESS_RETURN` BIT,
	
	IN `PARAM_SYNC_SERVER_DESCRIPTION` VARCHAR(500), 
	IN `PARAM_SYNC_SERVER_UNIQUE_KEY` VARCHAR(500)
)
SP_SAVE:
BEGIN

	-- 1) DECLARE LOCAL PARAMETERS
	-- ====================================================================================================================================================================
	
	-- Audit Handler
	-- ...........................................
	DECLARE TEMP_RECORD_EXISTS BIT DEFAULT `ACCOUNT_ACCESS_RIGHTS@ACCESS_ID_EXISTS`(PARAM_ACC_ACCESS_ID, 0);
	DECLARE TEMP_MODULE_KEYWORD VARCHAR(500) DEFAULT 'account_access_rights';
	DECLARE TEMP_SP_OBJECTIVE VARCHAR(500) DEFAULT 'add/edit Access rights record';	
	DECLARE TEMP_ERR_MESSAGE VARCHAR(500) DEFAULT '';
	DECLARE ERR BIGINT DEFAULT 0;
	DECLARE TEMP_RECORD_CHANGES VARCHAR(16000) DEFAULT '';
	DECLARE TEMP_RECORD_BINDED BIT DEFAULT 0;

	-- Authentication
	-- ...........................................
	DECLARE TEMP_ACCESS_RIGHTS_DENIED BIT DEFAULT 0;
	DECLARE TEMP_SYNC_SERVER_ID BIGINT DEFAULT 0;
	DECLARE TEMP_SYNC_IS_SERVER_REQUEST BIT DEFAULT 0;
	DECLARE TEMP_AUTHENTICATED_ACCOUNT_ID BIGINT DEFAULT `ACCOUNT_MEMBER@ACC_ACCOUNT_ID_FROM_LOGIN`(PARAM_REQUESTER_USERNAME, PARAM_REQUESTER_PASSWORD);
	DECLARE TEMP_AUTHENTICATED_ACCOUNT_LEVEL BIGINT DEFAULT `ACCOUNT_MEMBER@ACC_ACCOUNT_LEVEL_FROM_LOGIN`(PARAM_REQUESTER_USERNAME, PARAM_REQUESTER_PASSWORD);
		
	-- Local value holder
	-- ...........................................
	DECLARE TEMP_ACC_ACCESS_SERVER_ID BIGINT DEFAULT 0;
	DECLARE TEMP_ACC_ACCESS_ACC_LEVEL_ID BIGINT DEFAULT 0;
	DECLARE TEMP_ACC_ACCESS_SYS_MODULE_ID BIGINT DEFAULT 0;
	DECLARE TEMP_ACC_ACCESS_SYS_AUTHORITY_ID INT DEFAULT 0;
	DECLARE TEMP_ACC_ACCESS_AUTHORITY_POINT INT DEFAULT 0;
	
	DECLARE TEMP_LEVEL_DESCRIPTION VARCHAR(1000) DEFAULT '';
	
	-- ====================================================================================================================================================================

	
	-- 2) Try Catch / Throw
	-- ====================================================================================================================================================================
	DECLARE EXIT HANDLER FOR SQLEXCEPTION
	BEGIN
		RESIGNAL;
	END;
	-- ====================================================================================================================================================================

	
	-- 3) IF ALREADY EXIST, FILL MISSING DATA
	-- ====================================================================================================================================================================
	IF TEMP_RECORD_EXISTS = 1 THEN
		SELECT
			`account_access_rights`.`ACC_ACCESS_SERVER_ID`,
			`account_access_rights`.`ACC_ACCESS_ACC_LEVEL_ID`,
			`account_access_rights`.`ACC_ACCESS_SYS_MODULE_ID`,
			`account_access_rights`.`ACC_ACCESS_SYS_AUTHORITY_ID`,
			`account_access_rights`.`ACC_ACCESS_AUTHORITY_POINT`
		INTO 
			TEMP_ACC_ACCESS_SERVER_ID,
			TEMP_ACC_ACCESS_ACC_LEVEL_ID,
			TEMP_ACC_ACCESS_SYS_MODULE_ID,
			TEMP_ACC_ACCESS_SYS_AUTHORITY_ID,
			TEMP_ACC_ACCESS_AUTHORITY_POINT
		FROM `account_access_rights`
		WHERE
			`account_access_rights`.`ACC_ACCESS_ID` = PARAM_ACC_ACCESS_ID
		LIMIT 1;

		SET PARAM_ACC_ACCESS_SERVER_ID = `SYSTEM_VAR@REPLACE_NULL@BIGINT`(PARAM_ACC_ACCESS_SERVER_ID, TEMP_ACC_ACCESS_SERVER_ID, 0, 1);
		SET PARAM_ACC_ACCESS_SYS_MODULE_ID = TEMP_ACC_ACCESS_SYS_MODULE_ID;
		SET PARAM_ACC_ACCESS_SYS_AUTHORITY_ID = `SYSTEM_VAR@REPLACE_NULL@INT`(PARAM_ACC_ACCESS_SYS_AUTHORITY_ID, TEMP_ACC_ACCESS_SYS_AUTHORITY_ID, 0, 1);
		SET PARAM_ACC_ACCESS_AUTHORITY_POINT = `SYSTEM_VAR@REPLACE_NULL@BIGINT`(PARAM_ACC_ACCESS_AUTHORITY_POINT, TEMP_ACC_ACCESS_AUTHORITY_POINT, 0, 1);
	ELSE
		SET PARAM_ACC_ACCESS_SERVER_ID = `SYSTEM_VAR@REPLACE_NULL@BIGINT`(PARAM_ACC_ACCESS_SERVER_ID, 0, 0);
		
	END IF;
	-- ====================================================================================================================================================================


	-- 4) PREPARE AUDIT TRAIL
	-- ====================================================================================================================================================================
	
	IF TEMP_ACC_ACCESS_SERVER_ID <> PARAM_ACC_ACCESS_SERVER_ID THEN
		SET TEMP_RECORD_CHANGES = 
		`SYSTEM_VAR@CONCAT_ADD`(' | ', TEMP_RECORD_CHANGES, CONCAT_WS(' ', 'ACCESS SERVER ID:"', TEMP_ACC_ACCESS_SERVER_ID, '" > "', PARAM_ACC_ACCESS_SERVER_ID, '"'));
	END IF;	
	
	IF TEMP_ACC_ACCESS_ACC_LEVEL_ID <> PARAM_ACC_ACCESS_ACC_LEVEL_ID THEN
		SET TEMP_RECORD_CHANGES = 
		`SYSTEM_VAR@CONCAT_ADD`
		(
			' | ', TEMP_RECORD_CHANGES, CONCAT_WS
			(	
				' ',
				'LEVEL: ', TEMP_ACC_ACCESS_ACC_LEVEL_ID, '("', `ACCOUNT_LEVEL@ACC_LEVEL_DESCRIPTION_FROM_ID`(TEMP_ACC_ACCESS_ACC_LEVEL_ID), '")',
				' > ', PARAM_ACC_ACCESS_ACC_LEVEL_ID, '("', `ACCOUNT_LEVEL@ACC_LEVEL_DESCRIPTION_FROM_ID`(PARAM_ACC_ACCESS_ACC_LEVEL_ID), '")'
			)
		);
	END IF;
	
	IF TEMP_ACC_ACCESS_SYS_MODULE_ID <> PARAM_ACC_ACCESS_SYS_MODULE_ID THEN
		SET TEMP_RECORD_CHANGES = 
		`SYSTEM_VAR@CONCAT_ADD`
		(
			' | ', TEMP_RECORD_CHANGES, CONCAT_WS
			(
				' ',
				'MODULE: ', TEMP_ACC_ACCESS_SYS_MODULE_ID, '("', `SYSTEM_MODULE@SYS_MODULE_NAME_FROM_ID`(TEMP_ACC_ACCESS_SYS_MODULE_ID), '")',
				' > ', PARAM_ACC_ACCESS_SYS_MODULE_ID, '("', `SYSTEM_MODULE@SYS_MODULE_NAME_FROM_ID`(PARAM_ACC_ACCESS_SYS_MODULE_ID), '")'
			)
		);
	END IF;
	
	IF TEMP_ACC_ACCESS_SYS_AUTHORITY_ID <> PARAM_ACC_ACCESS_SYS_AUTHORITY_ID THEN
		SET TEMP_RECORD_CHANGES = 
		`SYSTEM_VAR@CONCAT_ADD`
		(
			' | ', TEMP_RECORD_CHANGES, CONCAT_WS
			(
				' ',
				'AUTHORITY: ', TEMP_ACC_ACCESS_SYS_AUTHORITY_ID, '("', `SYSTEM_ACCESS_RIGHTS_AUTHORITY@SYS_AUTHORITY_DESCRIPTION_FROM_ID`(TEMP_ACC_ACCESS_SYS_AUTHORITY_ID), '")',
				' > ', PARAM_ACC_ACCESS_SYS_AUTHORITY_ID, '("', `SYSTEM_ACCESS_RIGHTS_AUTHORITY@SYS_AUTHORITY_DESCRIPTION_FROM_ID`(PARAM_ACC_ACCESS_SYS_AUTHORITY_ID), '")'
			)
		);
	END IF;
	
	IF TEMP_ACC_ACCESS_AUTHORITY_POINT <> PARAM_ACC_ACCESS_AUTHORITY_POINT THEN
		SET TEMP_RECORD_CHANGES = 
		`SYSTEM_VAR@CONCAT_ADD`(' | ', TEMP_RECORD_CHANGES, CONCAT_WS(' ', 'AUTHORITY_POINT:"', TEMP_ACC_ACCESS_AUTHORITY_POINT, '" > "', PARAM_ACC_ACCESS_AUTHORITY_POINT, '"'));
	END IF;	
	
	-- No Changes in data, reject request
	IF CHAR_LENGTH(TEMP_RECORD_CHANGES) = 0 THEN
		IF PARAM_SUPPRESS_RETURN = 0 THEN
			SELECT PARAM_ACC_ACCESS_ID AS INSERTED_ID;
		END IF;
		LEAVE SP_SAVE;
	END IF;
	-- ====================================================================================================================================================================
	
	
	-- 5) VALIDATE
	-- ====================================================================================================================================================================
	
	-- Access Rights [Device]
	-- _______________________________________________________________________
	IF `ACCOUNT_DEVICE@HAS_PERMISSION`(PARAM_REQUESTER_DEVICE_PUBLIC_KEY, PARAM_REQUESTER_DEVICE_PRIVATE_KEY) = 0 THEN
		SET TEMP_ERR_MESSAGE = 'Your device is not authorized yet to access this server.';
		SET ERR = `RAISERROR`(TEMP_ERR_MESSAGE);		
	END IF;
		
		
	-- Access Rights [Account]
	-- _______________________________________________________________________
	IF 
		-- [ADD] Access Rights
		(
			TEMP_RECORD_EXISTS = 0 AND
			`ACCOUNT_ACCESS_RIGHTS@HAS_PERMISSION`(PARAM_REQUESTER_USERNAME, PARAM_REQUESTER_PASSWORD, 0, TEMP_MODULE_KEYWORD, 2) = 0 
		) OR
		
		-- [EDIT] Access Rights
		(
			TEMP_RECORD_EXISTS = 1 AND
			`ACCOUNT_ACCESS_RIGHTS@HAS_PERMISSION`(PARAM_REQUESTER_USERNAME, PARAM_REQUESTER_PASSWORD, 0, TEMP_MODULE_KEYWORD, 3) = 0 
		)
	THEN
		SET TEMP_ACCESS_RIGHTS_DENIED = 1;
		CALL `ACCOUNT_ACCESS_RIGHTS_DENY`
		(
			0, TEMP_MODULE_KEYWORD, PARAM_ACC_ACCESS_ID, PARAM_ACC_ACCESS_SERVER_ID, TEMP_SP_OBJECTIVE, TEMP_RECORD_CHANGES, 
			PARAM_REQUESTER_USERNAME, PARAM_REQUESTER_PASSWORD, 
			PARAM_REQUESTER_PROXY_ID, PARAM_REQUESTER_PROXY_PASSWORD,
			PARAM_REQUESTER_DEVICE_PUBLIC_KEY, PARAM_REQUESTER_DEVICE_PRIVATE_KEY,
			PARAM_REQUESTER_IP, PARAM_UNIQUE_SESSION_ID,
			TEMP_SYNC_SERVER_ID, PARAM_SUPPRESS_RETURN
		);
	END IF;

	-- Access Rights Exists
	-- ####################################################
	IF `ACCOUNT_ACCESS_RIGHTS@ACCESS_ID_EXISTS`(PARAM_ACC_ACCESS_ID, 0) = 0 THEN
		SET TEMP_ERR_MESSAGE = CONCAT_WS(' ', 'Given Access rights does not exists or is inactive. ID:', PARAM_ACC_ACCESS_ID);
		SET ERR = `RAISERROR`(TEMP_ERR_MESSAGE);
	END IF;
	
	-- Authority Points should be positive
	-- ####################################################
	IF PARAM_ACC_ACCESS_AUTHORITY_POINT < 0 THEN
		SET TEMP_ERR_MESSAGE = CONCAT_WS(' ', 'Authority Points should be positive value. Given:', PARAM_ACC_ACCESS_AUTHORITY_POINT);
		SET ERR = `RAISERROR`(TEMP_ERR_MESSAGE);
	END IF;

	-- SYSTEM_GENERATED
	-- ####################################################
	IF
	(
		SELECT COUNT(`account_level`.`ACC_LEVEL_ID`)
		FROM `account_level`
		WHERE
			`account_level`.`ACC_LEVEL_ID` = TEMP_ACC_ACCESS_ACC_LEVEL_ID AND
			`account_level`.`ACC_LEVEL_SYSTEM_GENERATED` = 2
		LIMIT 1
	) >= 1
	THEN
		SET TEMP_LEVEL_DESCRIPTION = `ACCOUNT_LEVEL@ACC_LEVEL_DESCRIPTION_FROM_ID`(TEMP_ACC_ACCESS_ACC_LEVEL_ID);
		CALL `VALIDATION_SYSTEM_GENERATED`(TEMP_ACC_ACCESS_ACC_LEVEL_ID, TEMP_LEVEL_DESCRIPTION, '');
	END IF;

	-- Authority Validation
	-- ####################################################
	IF `SYSTEM_ACCESS_RIGHTS_AUTHORITY@SYS_AUTHORITY_ID_EXISTS`(PARAM_ACC_ACCESS_SYS_AUTHORITY_ID, 1) = 0 THEN
		SET TEMP_ERR_MESSAGE = CONCAT_WS(' ', 'Given Authority type does not exists or is inactive.', PARAM_ACC_ACCESS_SYS_AUTHORITY_ID, '(', `SYSTEM_ACCESS_RIGHTS_AUTHORITY@SYS_AUTHORITY_DESCRIPTION_FROM_ID`(PARAM_ACC_ACCESS_SYS_AUTHORITY_ID), ')');
		SET ERR = `RAISERROR`(TEMP_ERR_MESSAGE);
	END IF;
	
	-- Should not edit own level
	-- ####################################################
	IF PARAM_ACC_ACCESS_ACC_LEVEL_ID = TEMP_AUTHENTICATED_ACCOUNT_LEVEL THEN
		SET TEMP_ERR_MESSAGE = 'You cannot edit own access level.';
		SET ERR = `RAISERROR`(TEMP_ERR_MESSAGE);	
	END IF;
	
	-- Has Enough authority to assign AR for this level
	-- ####################################################
	IF `ACCOUNT_ACCESS_RIGHTS@EDIT_HAS_PERMISSION`
	(
		PARAM_ACC_ACCESS_ACC_LEVEL_ID,
		PARAM_ACC_ACCESS_SYS_MODULE_ID,
		PARAM_ACC_ACCESS_SYS_AUTHORITY_ID,
		PARAM_ACC_ACCESS_AUTHORITY_POINT,
		
		PARAM_REQUESTER_USERNAME,
		PARAM_REQUESTER_PASSWORD
	) = 0 
	THEN
		SET TEMP_ERR_MESSAGE = 'You cannot assign rights greater than the access authority assigned to your account.';
		SET ERR = `RAISERROR`(TEMP_ERR_MESSAGE);	
	END IF;
	
	
	-- ====================================================================================================================================================================


	-- 6) INSERT / UPDATE
	-- ====================================================================================================================================================================
	
	UPDATE `account_access_rights`
	SET
		`account_access_rights`.`ACC_ACCESS_SERVER_ID` = PARAM_ACC_ACCESS_SERVER_ID,
		`account_access_rights`.`ACC_ACCESS_ACC_LEVEL_ID` = TEMP_ACC_ACCESS_ACC_LEVEL_ID,
		`account_access_rights`.`ACC_ACCESS_SYS_MODULE_ID` = TEMP_ACC_ACCESS_SYS_MODULE_ID,
		`account_access_rights`.`ACC_ACCESS_SYS_AUTHORITY_ID` = PARAM_ACC_ACCESS_SYS_AUTHORITY_ID,
		`account_access_rights`.`ACC_ACCESS_AUTHORITY_POINT` = PARAM_ACC_ACCESS_AUTHORITY_POINT
	WHERE
		`account_access_rights`.`ACC_ACCESS_ID` = PARAM_ACC_ACCESS_ID;

	-- ====================================================================================================================================================================
	

	-- 7) AUDIT TRAIL
	-- ====================================================================================================================================================================
	CALL `ACCOUNT_AUDIT_TRAIL_SAVE`
	(
		0, TEMP_MODULE_KEYWORD, PARAM_ACC_ACCESS_ID, PARAM_ACC_ACCESS_SERVER_ID, 'SAVE', TEMP_SP_OBJECTIVE, TEMP_RECORD_CHANGES, 
		PARAM_REQUESTER_USERNAME, PARAM_REQUESTER_PASSWORD, 
		PARAM_REQUESTER_PROXY_ID, PARAM_REQUESTER_PROXY_PASSWORD,
		PARAM_REQUESTER_DEVICE_PUBLIC_KEY, PARAM_REQUESTER_DEVICE_PRIVATE_KEY,
		PARAM_REQUESTER_IP, PARAM_UNIQUE_SESSION_ID,
		TEMP_SYNC_SERVER_ID, PARAM_SUPPRESS_RETURN
	);
	-- ====================================================================================================================================================================
		
	
	-- 8) RETURN RESULT
	-- ====================================================================================================================================================================
	IF PARAM_SUPPRESS_RETURN = 0 THEN
		SELECT PARAM_ACC_ACCESS_ID AS INSERTED_ID;
	END IF;
	LEAVE SP_SAVE;
	-- ====================================================================================================================================================================
			
END ;;
DELIMITER ;
/*!50003 SET sql_mode              = @saved_sql_mode */ ;
/*!50003 SET character_set_client  = @saved_cs_client */ ;
/*!50003 SET character_set_results = @saved_cs_results */ ;
/*!50003 SET collation_connection  = @saved_col_connection */ ;
/*!50003 DROP PROCEDURE IF EXISTS `ACCOUNT_AUDIT_TRAIL_GET` */;
/*!50003 SET @saved_cs_client      = @@character_set_client */ ;
/*!50003 SET @saved_cs_results     = @@character_set_results */ ;
/*!50003 SET @saved_col_connection = @@collation_connection */ ;
/*!50003 SET character_set_client  = latin1 */ ;
/*!50003 SET character_set_results = latin1 */ ;
/*!50003 SET collation_connection  = latin1_swedish_ci */ ;
/*!50003 SET @saved_sql_mode       = @@sql_mode */ ;
/*!50003 SET sql_mode              = '' */ ;
DELIMITER ;;
CREATE DEFINER=`root`@`localhost` PROCEDURE `ACCOUNT_AUDIT_TRAIL_GET`(
	IN `PARAM_ACC_TRAIL_ID` BIGINT,
	IN `PARAM_ACC_TRAIL_REQUEST_IP_ADDRESS` VARCHAR(1000),
	IN `PARAM_ACC_TRAIL_SYS_METHOD_ID` BIGINT,
	IN `PARAM_ACC_TRAIL_ACC_ACCOUNT_ID` BIGINT,
	IN `PARAM_ACC_ACCOUNT_NAME` VARCHAR(4000),
	IN `PARAM_ACC_TRAIL_ACC_SERVER_ID` BIGINT,

	IN `PARAM_ACC_TRAIL_SYS_MODULE_ID` BIGINT,
	IN `PARAM_SYS_MODULE_KEYWORD` VARCHAR(1000),
	IN `PARAM_ACC_TRAIL_TARGET_ID` BIGINT,
	IN `PARAM_ACC_TRAIL_DESCRIPTION` VARCHAR(16000),
	IN `PARAM_ACC_TRAIL_PARAMETERS` VARCHAR(16000),

	IN `PARAM_ACC_TRAIL_TIMESTAMP_FROM` DATETIME(6),
	IN `PARAM_ACC_TRAIL_TIMESTAMP_TO` DATETIME(6),
	IN `PARAM_ACC_TRAIL_UNIQUE_SESSION_ID` VARCHAR(16000),

	IN `PARAM_ORDER_FIELD` VARCHAR(500),
	IN `PARAM_ORDER_TYPE` VARCHAR(500),
	IN `PARAM_SKIP` BIGINT,
	IN `PARAM_LIMIT` BIGINT,

	IN `PARAM_REQUESTER_USERNAME` VARCHAR(500),
	IN `PARAM_REQUESTER_PASSWORD` VARCHAR(500),
	IN `PARAM_REQUESTER_PROXY_ID` BIGINT,
	IN `PARAM_REQUESTER_PROXY_PASSWORD` VARCHAR(1000),
	IN `PARAM_REQUESTER_DEVICE_PUBLIC_KEY` VARCHAR(1000),
	IN `PARAM_REQUESTER_DEVICE_PRIVATE_KEY` VARCHAR(1000),
	
	IN `PARAM_REQUESTER_IP` VARCHAR(1000),
	IN `PARAM_UNIQUE_SESSION_ID` VARCHAR(1000),
	IN `PARAM_SUPPRESS_RETURN` BIT
)
SP_GET:
BEGIN

	-- 1) DECLARE LOCAL PARAMETERS
	-- _______________________________________________________________________
	
	-- Status
	-- ...........................................
	DECLARE STATUS_INACTIVE TINYINT DEFAULT 1;
	DECLARE STATUS_ACTIVE TINYINT DEFAULT 2;
	DECLARE STATUS_CLOSED TINYINT DEFAULT 3;
	DECLARE STATUS_COMPLETED TINYINT DEFAULT 4;
		
		
	-- Audit Handler
	-- ...........................................
	DECLARE TEMP_RECORD_EXISTS BIT DEFAULT 0;
	DECLARE TEMP_MODULE_KEYWORD VARCHAR(500) DEFAULT 'account_audit_trail';
	DECLARE TEMP_SP_OBJECTIVE VARCHAR(500) DEFAULT 'Retrieve Audit Trail record';
	DECLARE TEMP_ERR_MESSAGE VARCHAR(500) DEFAULT '';
	DECLARE ERR BIGINT DEFAULT 0;
	DECLARE TEMP_RECORD_CHANGES NVARCHAR(16000) DEFAULT '';
	DECLARE TEMP_RECORD_BINDED BIT DEFAULT 0;
	
	DECLARE TEMP_RECORD_BINDED_ID BIGINT DEFAULT 0;
	DECLARE TEMP_RECORD_BINDED_SERVER_ID BIGINT DEFAULT 0;
	
	-- Authentication
	-- ...........................................
	DECLARE TEMP_ACCESS_RIGHTS_DENIED BIT DEFAULT 0;
	DECLARE TEMP_AUTHENTICATED_ACCOUNT_ID BIGINT DEFAULT `ACCOUNT_MEMBER@ACC_ACCOUNT_ID_FROM_LOGIN`(@PARAM_REQUESTER_USERNAME, @PARAM_REQUESTER_PASSWORD);
	DECLARE TEMP_AUTHENTICATED_ACCOUNT_LEVEL BIGINT DEFAULT 0;

	-- Local Parameters
	-- ...........................................
	DECLARE TEMP_NOW DATETIME(6) DEFAULT `SYSTEM_VAR@NOW`('', 1);
	DECLARE TEMP_RECORD_COUNT BIGINT DEFAULT 0;
	
	-- Check NULLs
	-- ...........................................
	DECLARE IS_NULL_ACC_TRAIL_ID BIT DEFAULT `SYSTEM_VAR@IS_NULL@BIGINT`(PARAM_ACC_TRAIL_ID, 1, 1);
	DECLARE IS_NULL_ACC_TRAIL_REQUEST_IP_ADDRESS BIT DEFAULT `SYSTEM_VAR@IS_NULL@NVARCHAR`(PARAM_ACC_TRAIL_REQUEST_IP_ADDRESS, 1);
	DECLARE IS_NULL_ACC_TRAIL_SYS_METHOD_ID BIT DEFAULT `SYSTEM_VAR@IS_NULL@BIGINT`(PARAM_ACC_TRAIL_SYS_METHOD_ID, 1, 1);
	DECLARE IS_NULL_ACC_TRAIL_ACC_ACCOUNT_ID BIT DEFAULT `SYSTEM_VAR@IS_NULL@BIGINT`(PARAM_ACC_TRAIL_ACC_ACCOUNT_ID, 1, 1);
	DECLARE IS_NULL_ACC_TRAIL_ACC_SERVER_ID BIT DEFAULT `SYSTEM_VAR@IS_NULL@BIGINT`(PARAM_ACC_TRAIL_ACC_SERVER_ID, 1, 0);
	DECLARE IS_NULL_ACCOUNT_NAME BIT DEFAULT `SYSTEM_VAR@IS_NULL@NVARCHAR`(PARAM_ACC_ACCOUNT_NAME, 1);

	DECLARE IS_NULL_ACC_TRAIL_SYS_MODULE_ID BIT DEFAULT `SYSTEM_VAR@IS_NULL@BIGINT`(PARAM_ACC_TRAIL_SYS_MODULE_ID, 1, 1);
	DECLARE IS_NULL_SYS_MODULE_KEYWORD  BIT DEFAULT `SYSTEM_VAR@IS_NULL@NVARCHAR`(PARAM_SYS_MODULE_KEYWORD, 1);
	DECLARE IS_NULL_ACC_TRAIL_TARGET_ID BIT DEFAULT `SYSTEM_VAR@IS_NULL@BIGINT`(PARAM_ACC_TRAIL_TARGET_ID, 1, 1);
	DECLARE IS_NULL_ACC_TRAIL_DESCRIPTION BIT DEFAULT `SYSTEM_VAR@IS_NULL@NVARCHAR`(PARAM_ACC_TRAIL_DESCRIPTION, 1);
	DECLARE IS_NULL_ACC_TRAIL_PARAMETERS BIT DEFAULT `SYSTEM_VAR@IS_NULL@NVARCHAR`(PARAM_ACC_TRAIL_PARAMETERS, 1) ;

	DECLARE IS_NULL_ACC_TRAIL_TIMESTAMP_FROM BIT DEFAULT `SYSTEM_VAR@IS_NULL@DATETIME`(PARAM_ACC_TRAIL_TIMESTAMP_FROM, 1);
	DECLARE IS_NULL_ACC_TRAIL_TIMESTAMP_TO BIT DEFAULT `SYSTEM_VAR@IS_NULL@DATETIME`(PARAM_ACC_TRAIL_TIMESTAMP_TO, 1);
	DECLARE IS_NULL_ACC_TRAIL_UNIQUE_SESSION_ID BIT DEFAULT `SYSTEM_VAR@IS_NULL@NVARCHAR`(PARAM_ACC_TRAIL_UNIQUE_SESSION_ID, 1);


	-- Error Handler
	-- _______________________________________________________________________
	DECLARE EXIT HANDLER FOR SQLEXCEPTION
	BEGIN
		RESIGNAL;
	END;
	
	
	-- Access Rights [Device]
	-- _______________________________________________________________________
	IF `ACCOUNT_DEVICE@HAS_PERMISSION`(PARAM_REQUESTER_DEVICE_PUBLIC_KEY, PARAM_REQUESTER_DEVICE_PRIVATE_KEY) = 0 THEN
		SET TEMP_ERR_MESSAGE = 'Your device is not authorized yet to access this server.';
		SET ERR = `RAISERROR`(TEMP_ERR_MESSAGE);		
	END IF;
		
		
	-- Access Rights [Account]
	-- _______________________________________________________________________
	IF `ACCOUNT_ACCESS_RIGHTS@HAS_PERMISSION`(PARAM_REQUESTER_USERNAME, PARAM_REQUESTER_PASSWORD, 0, TEMP_MODULE_KEYWORD, 1) = 0 THEN
		CALL `ACCOUNT_ACCESS_RIGHTS_DENY`
		(
			0, TEMP_MODULE_KEYWORD, PARAM_ACC_TRAIL_ID, 0, TEMP_SP_OBJECTIVE, '',
			PARAM_REQUESTER_USERNAME, PARAM_REQUESTER_PASSWORD,
			PARAM_REQUESTER_PROXY_ID, PARAM_REQUESTER_PROXY_PASSWORD,
			PARAM_REQUESTER_DEVICE_PUBLIC_KEY, PARAM_REQUESTER_DEVICE_PRIVATE_KEY,
			PARAM_REQUESTER_IP, PARAM_UNIQUE_SESSION_ID,
			0, PARAM_SUPPRESS_RETURN
		);
	END IF;

	
	-- COUNT AUDIT TRAILS
	-- _______________________________________________________________________
	SELECT
		COUNT(`account_audit_trail`.`ACC_TRAIL_ID`)
	INTO
		TEMP_RECORD_COUNT

	-- INNER JOINS
	-- ####################################################		
	FROM `account_audit_trail`

		INNER JOIN `system_trail_methods` ON
		`system_trail_methods`.`SYS_METHOD_ID` = `account_audit_trail`.`ACC_TRAIL_SYS_METHOD_ID`

		INNER JOIN `system_module` ON
		`system_module`.`SYS_MODULE_ID` = `account_audit_trail`.`ACC_TRAIL_SYS_MODULE_ID` AND
		(
			IS_NULL_SYS_MODULE_KEYWORD = 1 OR
			`system_module`.`SYS_MODULE_KEYWORD` LIKE CONCAT_WS('%', '', PARAM_SYS_MODULE_KEYWORD, '')
		)

			
	-- CONDITIONS
	-- ............................................
	WHERE
		(
			IS_NULL_ACC_TRAIL_ID = 1 OR
			`account_audit_trail`.`ACC_TRAIL_ID` = PARAM_ACC_TRAIL_ID
		) AND
		(
			IS_NULL_ACC_TRAIL_REQUEST_IP_ADDRESS = 1 OR
			`account_audit_trail`.`ACC_TRAIL_REQUEST_IP_ADDRESS` LIKE CONCAT_WS('%', '', PARAM_ACC_TRAIL_REQUEST_IP_ADDRESS, '')
		) AND
		(
			IS_NULL_ACC_TRAIL_SYS_METHOD_ID = 1 OR
			`account_audit_trail`.`ACC_TRAIL_SYS_METHOD_ID` = PARAM_ACC_TRAIL_SYS_METHOD_ID
		) AND
		(
			IS_NULL_ACC_TRAIL_ACC_ACCOUNT_ID = 1 OR
			`account_audit_trail`.`ACC_TRAIL_ACC_ACCOUNT_ID` = PARAM_ACC_TRAIL_ACC_ACCOUNT_ID
		) AND
		(
			IS_NULL_ACC_TRAIL_ACC_SERVER_ID = 1 OR
			`account_audit_trail`.`ACC_TRAIL_ACC_SERVER_ID` = PARAM_ACC_TRAIL_ACC_SERVER_ID
		) AND


		(
			IS_NULL_ACC_TRAIL_SYS_MODULE_ID = 1 OR
			`account_audit_trail`.`ACC_TRAIL_SYS_MODULE_ID` = PARAM_ACC_TRAIL_SYS_MODULE_ID
		) AND
		(
			IS_NULL_ACC_TRAIL_TARGET_ID = 1 OR
			`account_audit_trail`.`ACC_TRAIL_TARGET_ID` = PARAM_ACC_TRAIL_TARGET_ID
		) AND
		(
			IS_NULL_ACC_TRAIL_DESCRIPTION = 1 OR
			`account_audit_trail`.`ACC_TRAIL_DESCRIPTION` LIKE CONCAT_WS('%', '', PARAM_ACC_TRAIL_DESCRIPTION, '')
		) AND
		(
			IS_NULL_ACC_TRAIL_PARAMETERS = 1 OR
			`account_audit_trail`.`ACC_TRAIL_PARAMETERS` LIKE CONCAT_WS('%', '', PARAM_ACC_TRAIL_PARAMETERS, '')
		) AND


		(
			IS_NULL_ACC_TRAIL_TIMESTAMP_FROM = 1 OR
			`account_audit_trail`.`ACC_TRAIL_TIMESTAMP` >= PARAM_ACC_TRAIL_TIMESTAMP_FROM
		) AND
		(
			IS_NULL_ACC_TRAIL_TIMESTAMP_TO = 1 OR
			`account_audit_trail`.`ACC_TRAIL_TIMESTAMP` <= PARAM_ACC_TRAIL_TIMESTAMP_TO
		) AND
		(
			IS_NULL_ACC_TRAIL_UNIQUE_SESSION_ID = 1 OR
			`account_audit_trail`.`ACC_TRAIL_UNIQUE_SESSION_ID` LIKE CONCAT_WS('%', '', PARAM_ACC_TRAIL_UNIQUE_SESSION_ID, '')
		);

		
	-- SELECT ACCOUNTS
	-- _______________________________________________________________________
	SELECT
		TEMP_RECORD_COUNT AS ROW_COUNT,
		
		-- AUDIT TRAIL
		`account_audit_trail`.`ACC_TRAIL_ID`,
		`account_audit_trail`.`ACC_TRAIL_REQUEST_IP_ADDRESS`,
		`account_audit_trail`.`ACC_TRAIL_SYS_METHOD_ID`,
		`account_audit_trail`.`ACC_TRAIL_ACC_ACCOUNT_ID`,
		`account_audit_trail`.`ACC_TRAIL_ACC_SERVER_ID`,
		
		`account_audit_trail`.`ACC_TRAIL_SYS_MODULE_ID`,
		`account_audit_trail`.`ACC_TRAIL_TARGET_ID`,
		`account_audit_trail`.`ACC_TRAIL_DESCRIPTION`,
		`account_audit_trail`.`ACC_TRAIL_PARAMETERS`,

		`account_audit_trail`.`ACC_TRAIL_TIMESTAMP`,
		`account_audit_trail`.`ACC_TRAIL_UNIQUE_SESSION_ID`,

		-- MEMBER
		IF
		(
			`account_member`.`ACC_ACCOUNT_ID` IS NOT NULL, 
			CONCAT_WS
			(
				' ',
				`account_member`.`ACC_ACCOUNT_FIRST_NAME`,
				`account_member`.`ACC_ACCOUNT_MIDDLE_NAME`,
				`account_member`.`ACC_ACCOUNT_LAST_NAME`
			), 
			CONCAT_WS
			(
				' ',
				`account_server`.`ACC_SERVER_DESCRIPTION`, 
				'user'
			)
		) AS ACCOUNT_NAME,
		`account_member`.`ACC_ACCOUNT_ID`,
		`account_member`.`ACC_ACCOUNT_ACC_LEVEL_ID`,
		`account_member`.`ACC_ACCOUNT_USERNAME`,

		`account_member`.`ACC_ACCOUNT_FIRST_NAME`,
		`account_member`.`ACC_ACCOUNT_MIDDLE_NAME`,
		`account_member`.`ACC_ACCOUNT_LAST_NAME`,
		`account_member`.`ACC_ACCOUNT_SYS_GENDER_ID`,
		`account_member`.`ACC_ACCOUNT_STATUS`,
		`account_member`.`ACC_ACCOUNT_SYSTEM_GENERATED`,

		-- SERVER
		`account_server`.`ACC_SERVER_DESCRIPTION`,
		
		-- METHOD_ID
		`system_trail_methods`.`SYS_METHOD_ID`,
		`system_trail_methods`.`SYS_METHOD_CODE`,
		`system_trail_methods`.`SYS_METHOD_DESCRIPTION`,
		`system_trail_methods`.`SYS_METHOD_STATUS`,
		
		-- MODULE
		`system_module`.`SYS_MODULE_ID`,
		`system_module`.`SYS_MODULE_CATEGORY`,
		`system_module`.`SYS_MODULE_KEYWORD`,
		`system_module`.`SYS_MODULE_NAME`,
		`system_module`.`SYS_MODULE_DESCRIPTION`,
		`system_module`.`SYS_MODULE_STATUS`,
		`system_module`.`SYS_MODULE_SHOW_ACCESS_RIGHTS`

	-- INNER JOINS
	-- ####################################################	
	FROM `account_audit_trail`
		LEFT JOIN `account_member` ON
		`account_member`.`ACC_ACCOUNT_ID` = `account_audit_trail`.`ACC_TRAIL_ACC_ACCOUNT_ID` AND
		(
			IS_NULL_ACCOUNT_NAME = 1 OR
			CONCAT
			(
				`account_member`.`ACC_ACCOUNT_FIRST_NAME`, ' ',
				`account_member`.`ACC_ACCOUNT_MIDDLE_NAME`, ' ',
				`account_member`.`ACC_ACCOUNT_LAST_NAME`
			) LIKE
			CONCAT('%', PARAM_ACC_ACCOUNT_NAME, '%')
		)

		LEFT JOIN `account_server` ON
		`account_server`.`ACC_SERVER_ID` = `account_audit_trail`.`ACC_TRAIL_ACC_SERVER_ID`
		
		INNER JOIN `system_trail_methods` ON
		`system_trail_methods`.`SYS_METHOD_ID` = `account_audit_trail`.`ACC_TRAIL_SYS_METHOD_ID`
		
		INNER JOIN `system_module` ON
		`system_module`.`SYS_MODULE_ID` = `account_audit_trail`.`ACC_TRAIL_SYS_MODULE_ID` AND
		(
			IS_NULL_SYS_MODULE_KEYWORD = 1 OR
			`system_module`.`SYS_MODULE_KEYWORD` LIKE CONCAT_WS('%', '', PARAM_SYS_MODULE_KEYWORD, '')
		)

			
	-- CONDITIONS
	-- ####################################################	
	WHERE
		(
			IS_NULL_ACC_TRAIL_ID = 1 OR
			`account_audit_trail`.`ACC_TRAIL_ID` = PARAM_ACC_TRAIL_ID
		) AND
		(
			IS_NULL_ACC_TRAIL_REQUEST_IP_ADDRESS = 1 OR
			`account_audit_trail`.`ACC_TRAIL_REQUEST_IP_ADDRESS` LIKE CONCAT_WS('%', '', PARAM_ACC_TRAIL_REQUEST_IP_ADDRESS, '')
		) AND
		(
			IS_NULL_ACC_TRAIL_SYS_METHOD_ID = 1 OR
			`account_audit_trail`.`ACC_TRAIL_SYS_METHOD_ID` = PARAM_ACC_TRAIL_SYS_METHOD_ID
		) AND
		(
			IS_NULL_ACC_TRAIL_ACC_ACCOUNT_ID = 1 OR
			`account_audit_trail`.`ACC_TRAIL_ACC_ACCOUNT_ID` = PARAM_ACC_TRAIL_ACC_ACCOUNT_ID
		) AND
		(
			IS_NULL_ACC_TRAIL_ACC_SERVER_ID = 1 OR
			`account_audit_trail`.`ACC_TRAIL_ACC_SERVER_ID` = PARAM_ACC_TRAIL_ACC_SERVER_ID
		) AND

		(
			IS_NULL_ACC_TRAIL_SYS_MODULE_ID = 1 OR
			`account_audit_trail`.`ACC_TRAIL_SYS_MODULE_ID` = PARAM_ACC_TRAIL_SYS_MODULE_ID
		) AND
		(
			IS_NULL_ACC_TRAIL_TARGET_ID = 1 OR
			`account_audit_trail`.`ACC_TRAIL_TARGET_ID` = PARAM_ACC_TRAIL_TARGET_ID
		) AND
		(
			IS_NULL_ACC_TRAIL_DESCRIPTION = 1 OR
			`account_audit_trail`.`ACC_TRAIL_DESCRIPTION` LIKE CONCAT_WS('%', '', PARAM_ACC_TRAIL_DESCRIPTION, '')
		) AND
		(
			IS_NULL_ACC_TRAIL_PARAMETERS = 1 OR
			`account_audit_trail`.`ACC_TRAIL_PARAMETERS` LIKE CONCAT_WS('%', '', PARAM_ACC_TRAIL_PARAMETERS, '')
		) AND


		(
			IS_NULL_ACC_TRAIL_TIMESTAMP_FROM = 1 OR
			`account_audit_trail`.`ACC_TRAIL_TIMESTAMP` >= PARAM_ACC_TRAIL_TIMESTAMP_FROM
		) AND
		(
			IS_NULL_ACC_TRAIL_TIMESTAMP_TO = 1 OR
			`account_audit_trail`.`ACC_TRAIL_TIMESTAMP` <= PARAM_ACC_TRAIL_TIMESTAMP_TO
		) AND
		(
			IS_NULL_ACC_TRAIL_UNIQUE_SESSION_ID = 1 OR
			`account_audit_trail`.`ACC_TRAIL_UNIQUE_SESSION_ID` LIKE CONCAT_WS('%', '', PARAM_ACC_TRAIL_UNIQUE_SESSION_ID, '')
		)

	-- ORDER BY
	-- =========================================================================================
	ORDER BY
		-- ACCESS LEVEL
		-- ...........................................
		CASE WHEN PARAM_ORDER_FIELD = 'ACC_TRAIL_ID' AND PARAM_ORDER_TYPE = 'ASC' THEN `account_audit_trail`.`ACC_TRAIL_ID` END ASC, 
		CASE WHEN PARAM_ORDER_FIELD = 'ACC_TRAIL_ID' AND PARAM_ORDER_TYPE = 'DESC' THEN `account_audit_trail`.`ACC_TRAIL_ID` END DESC,	
		CASE WHEN PARAM_ORDER_FIELD = 'ACC_TRAIL_REQUEST_IP_ADDRESS' AND PARAM_ORDER_TYPE = 'ASC' THEN `account_audit_trail`.`ACC_TRAIL_REQUEST_IP_ADDRESS` END ASC, 
		CASE WHEN PARAM_ORDER_FIELD = 'ACC_TRAIL_REQUEST_IP_ADDRESS' AND PARAM_ORDER_TYPE = 'DESC' THEN `account_audit_trail`.`ACC_TRAIL_REQUEST_IP_ADDRESS` END DESC,
		CASE WHEN PARAM_ORDER_FIELD = 'ACC_TRAIL_SYS_METHOD_ID' AND PARAM_ORDER_TYPE = 'ASC' THEN `account_audit_trail`.`ACC_TRAIL_SYS_METHOD_ID` END ASC, 
		CASE WHEN PARAM_ORDER_FIELD = 'ACC_TRAIL_SYS_METHOD_ID' AND PARAM_ORDER_TYPE = 'DESC' THEN `account_audit_trail`.`ACC_TRAIL_SYS_METHOD_ID` END DESC,	
		CASE WHEN PARAM_ORDER_FIELD = 'ACC_TRAIL_ACC_ACCOUNT_ID' AND PARAM_ORDER_TYPE = 'ASC' THEN `account_audit_trail`.`ACC_TRAIL_ACC_ACCOUNT_ID` END ASC, 
		CASE WHEN PARAM_ORDER_FIELD = 'ACC_TRAIL_ACC_ACCOUNT_ID' AND PARAM_ORDER_TYPE = 'DESC' THEN `account_audit_trail`.`ACC_TRAIL_ACC_ACCOUNT_ID` END DESC,
		CASE WHEN PARAM_ORDER_FIELD = 'ACC_TRAIL_ACC_SERVER_ID' AND PARAM_ORDER_TYPE = 'ASC' THEN `account_audit_trail`.`ACC_TRAIL_ACC_SERVER_ID` END ASC, 
		CASE WHEN PARAM_ORDER_FIELD = 'ACC_TRAIL_ACC_SERVER_ID' AND PARAM_ORDER_TYPE = 'DESC' THEN `account_audit_trail`.`ACC_TRAIL_ACC_SERVER_ID` END DESC,		
		
		CASE WHEN PARAM_ORDER_FIELD = 'ACC_TRAIL_SYS_MODULE_ID' AND PARAM_ORDER_TYPE = 'ASC' THEN `account_audit_trail`.`ACC_TRAIL_SYS_MODULE_ID` END ASC, 
		CASE WHEN PARAM_ORDER_FIELD = 'ACC_TRAIL_SYS_MODULE_ID' AND PARAM_ORDER_TYPE = 'DESC' THEN `account_audit_trail`.`ACC_TRAIL_SYS_MODULE_ID` END DESC,
		CASE WHEN PARAM_ORDER_FIELD = 'ACC_TRAIL_TARGET_ID' AND PARAM_ORDER_TYPE = 'ASC' THEN `account_audit_trail`.`ACC_TRAIL_TARGET_ID` END ASC, 
		CASE WHEN PARAM_ORDER_FIELD = 'ACC_TRAIL_TARGET_ID' AND PARAM_ORDER_TYPE = 'DESC' THEN `account_audit_trail`.`ACC_TRAIL_TARGET_ID` END DESC,
		CASE WHEN PARAM_ORDER_FIELD = 'ACC_TRAIL_DESCRIPTION' AND PARAM_ORDER_TYPE = 'ASC' THEN `account_audit_trail`.`ACC_TRAIL_DESCRIPTION` END ASC, 
		CASE WHEN PARAM_ORDER_FIELD = 'ACC_TRAIL_DESCRIPTION' AND PARAM_ORDER_TYPE = 'DESC' THEN `account_audit_trail`.`ACC_TRAIL_DESCRIPTION` END DESC,
		CASE WHEN PARAM_ORDER_FIELD = 'ACC_TRAIL_PARAMETERS' AND PARAM_ORDER_TYPE = 'ASC' THEN `account_audit_trail`.`ACC_TRAIL_PARAMETERS` END ASC, 
		CASE WHEN PARAM_ORDER_FIELD = 'ACC_TRAIL_PARAMETERS' AND PARAM_ORDER_TYPE = 'DESC' THEN `account_audit_trail`.`ACC_TRAIL_PARAMETERS` END DESC,
		
		CASE WHEN PARAM_ORDER_FIELD = 'ACC_TRAIL_TIMESTAMP' AND PARAM_ORDER_TYPE = 'ASC' THEN `account_audit_trail`.`ACC_TRAIL_TIMESTAMP` END ASC, 
		CASE WHEN PARAM_ORDER_FIELD = 'ACC_TRAIL_TIMESTAMP' AND PARAM_ORDER_TYPE = 'DESC' THEN `account_audit_trail`.`ACC_TRAIL_TIMESTAMP` END DESC,
		CASE WHEN PARAM_ORDER_FIELD = 'ACC_TRAIL_UNIQUE_SESSION_ID' AND PARAM_ORDER_TYPE = 'ASC' THEN `account_audit_trail`.`ACC_TRAIL_UNIQUE_SESSION_ID` END ASC, 
		CASE WHEN PARAM_ORDER_FIELD = 'ACC_TRAIL_UNIQUE_SESSION_ID' AND PARAM_ORDER_TYPE = 'DESC' THEN `account_audit_trail`.`ACC_TRAIL_UNIQUE_SESSION_ID` END DESC,


		-- MEMBER
		-- ...........................................
		CASE WHEN PARAM_ORDER_FIELD = 'ACC_ACCOUNT_ID' AND PARAM_ORDER_TYPE = 'ASC' THEN `account_member`.`ACC_ACCOUNT_ID` END ASC, 
		CASE WHEN PARAM_ORDER_FIELD = 'ACC_ACCOUNT_ID' AND PARAM_ORDER_TYPE = 'DESC' THEN `account_member`.`ACC_ACCOUNT_ID` END DESC,	
		CASE WHEN PARAM_ORDER_FIELD = 'ACC_ACCOUNT_ACC_LEVEL_ID' AND PARAM_ORDER_TYPE = 'ASC' THEN `account_member`.`ACC_ACCOUNT_ACC_LEVEL_ID` END ASC, 
		CASE WHEN PARAM_ORDER_FIELD = 'ACC_ACCOUNT_ACC_LEVEL_ID' AND PARAM_ORDER_TYPE = 'DESC' THEN `account_member`.`ACC_ACCOUNT_ACC_LEVEL_ID` END DESC,	
		CASE WHEN PARAM_ORDER_FIELD = 'ACC_ACCOUNT_USERNAME' AND PARAM_ORDER_TYPE = 'ASC' THEN `account_member`.`ACC_ACCOUNT_USERNAME` END ASC, 
		CASE WHEN PARAM_ORDER_FIELD = 'ACC_ACCOUNT_USERNAME' AND PARAM_ORDER_TYPE = 'DESC' THEN `account_member`.`ACC_ACCOUNT_USERNAME` END DESC,

		CASE WHEN PARAM_ORDER_FIELD = 'ACC_ACCOUNT_FIRST_NAME' AND PARAM_ORDER_TYPE = 'ASC' THEN `account_member`.`ACC_ACCOUNT_FIRST_NAME` END ASC, 
		CASE WHEN PARAM_ORDER_FIELD = 'ACC_ACCOUNT_FIRST_NAME' AND PARAM_ORDER_TYPE = 'DESC' THEN `account_member`.`ACC_ACCOUNT_FIRST_NAME` END DESC,
		CASE WHEN PARAM_ORDER_FIELD = 'ACC_ACCOUNT_MIDDLE_NAME' AND PARAM_ORDER_TYPE = 'ASC' THEN `account_member`.`ACC_ACCOUNT_MIDDLE_NAME` END ASC, 
		CASE WHEN PARAM_ORDER_FIELD = 'ACC_ACCOUNT_MIDDLE_NAME' AND PARAM_ORDER_TYPE = 'DESC' THEN `account_member`.`ACC_ACCOUNT_MIDDLE_NAME` END DESC,
		CASE WHEN PARAM_ORDER_FIELD = 'ACC_ACCOUNT_LAST_NAME' AND PARAM_ORDER_TYPE = 'ASC' THEN `account_member`.`ACC_ACCOUNT_LAST_NAME` END ASC, 
		CASE WHEN PARAM_ORDER_FIELD = 'ACC_ACCOUNT_LAST_NAME' AND PARAM_ORDER_TYPE = 'DESC' THEN `account_member`.`ACC_ACCOUNT_LAST_NAME` END DESC,
		CASE WHEN PARAM_ORDER_FIELD = 'ACC_ACCOUNT_SYS_GENDER_ID' AND PARAM_ORDER_TYPE = 'ASC' THEN `account_member`.`ACC_ACCOUNT_SYS_GENDER_ID` END ASC, 
		CASE WHEN PARAM_ORDER_FIELD = 'ACC_ACCOUNT_SYS_GENDER_ID' AND PARAM_ORDER_TYPE = 'DESC' THEN `account_member`.`ACC_ACCOUNT_SYS_GENDER_ID` END DESC,
		CASE WHEN PARAM_ORDER_FIELD = 'ACC_ACCOUNT_STATUS' AND PARAM_ORDER_TYPE = 'ASC' THEN `account_member`.`ACC_ACCOUNT_STATUS` END ASC, 
		CASE WHEN PARAM_ORDER_FIELD = 'ACC_ACCOUNT_STATUS' AND PARAM_ORDER_TYPE = 'DESC' THEN `account_member`.`ACC_ACCOUNT_STATUS` END DESC,
		CASE WHEN PARAM_ORDER_FIELD = 'ACC_ACCOUNT_SYSTEM_GENERATED' AND PARAM_ORDER_TYPE = 'ASC' THEN `account_member`.`ACC_ACCOUNT_SYSTEM_GENERATED` END ASC, 
		CASE WHEN PARAM_ORDER_FIELD = 'ACC_ACCOUNT_SYSTEM_GENERATED' AND PARAM_ORDER_TYPE = 'DESC' THEN `account_member`.`ACC_ACCOUNT_SYSTEM_GENERATED` END DESC,


		-- MODULE
		-- ...........................................
		CASE WHEN PARAM_ORDER_FIELD = 'SYS_MODULE_ID' AND PARAM_ORDER_TYPE = 'ASC' THEN `system_module`.`SYS_MODULE_ID` END ASC, 
		CASE WHEN PARAM_ORDER_FIELD = 'SYS_MODULE_ID' AND PARAM_ORDER_TYPE = 'DESC' THEN `system_module`.`SYS_MODULE_ID` END DESC,
		CASE WHEN PARAM_ORDER_FIELD = 'SYS_MODULE_CATEGORY' AND PARAM_ORDER_TYPE = 'ASC' THEN `system_module`.`SYS_MODULE_CATEGORY` END ASC, 
		CASE WHEN PARAM_ORDER_FIELD = 'SYS_MODULE_CATEGORY' AND PARAM_ORDER_TYPE = 'DESC' THEN `system_module`.`SYS_MODULE_CATEGORY` END DESC,
		CASE WHEN PARAM_ORDER_FIELD = 'SYS_MODULE_KEYWORD' AND PARAM_ORDER_TYPE = 'ASC' THEN `system_module`.`SYS_MODULE_KEYWORD` END ASC, 
		CASE WHEN PARAM_ORDER_FIELD = 'SYS_MODULE_KEYWORD' AND PARAM_ORDER_TYPE = 'DESC' THEN `system_module`.`SYS_MODULE_KEYWORD` END DESC,
 		CASE WHEN PARAM_ORDER_FIELD = 'SYS_MODULE_NAME' AND PARAM_ORDER_TYPE = 'ASC' THEN `system_module`.`SYS_MODULE_NAME` END ASC, 
		CASE WHEN PARAM_ORDER_FIELD = 'SYS_MODULE_NAME' AND PARAM_ORDER_TYPE = 'DESC' THEN `system_module`.`SYS_MODULE_NAME` END DESC,
 		CASE WHEN PARAM_ORDER_FIELD = 'SYS_MODULE_DESCRIPTION' AND PARAM_ORDER_TYPE = 'ASC' THEN `system_module`.`SYS_MODULE_DESCRIPTION` END ASC, 
		CASE WHEN PARAM_ORDER_FIELD = 'SYS_MODULE_DESCRIPTION' AND PARAM_ORDER_TYPE = 'DESC' THEN `system_module`.`SYS_MODULE_DESCRIPTION` END DESC,
 		CASE WHEN PARAM_ORDER_FIELD = 'SYS_MODULE_STATUS' AND PARAM_ORDER_TYPE = 'ASC' THEN `system_module`.`SYS_MODULE_STATUS` END ASC, 
		CASE WHEN PARAM_ORDER_FIELD = 'SYS_MODULE_STATUS' AND PARAM_ORDER_TYPE = 'DESC' THEN `system_module`.`SYS_MODULE_STATUS` END DESC,
 		CASE WHEN PARAM_ORDER_FIELD = 'SYS_MODULE_SHOW_ACCESS_RIGHTS' AND PARAM_ORDER_TYPE = 'ASC' THEN `system_module`.`SYS_MODULE_SHOW_ACCESS_RIGHTS` END ASC, 
		CASE WHEN PARAM_ORDER_FIELD = 'SYS_MODULE_SHOW_ACCESS_RIGHTS' AND PARAM_ORDER_TYPE = 'DESC' THEN `system_module`.`SYS_MODULE_SHOW_ACCESS_RIGHTS` END DESC,
			
		-- EXTRA
		-- ...........................................
		CASE WHEN PARAM_ORDER_FIELD <> 'ACC_TRAIL_TIMESTAMP' THEN `account_audit_trail`.`ACC_TRAIL_TIMESTAMP` END ASC
																											
	LIMIT PARAM_SKIP, PARAM_LIMIT;
	LEAVE SP_GET;
	
END ;;
DELIMITER ;
/*!50003 SET sql_mode              = @saved_sql_mode */ ;
/*!50003 SET character_set_client  = @saved_cs_client */ ;
/*!50003 SET character_set_results = @saved_cs_results */ ;
/*!50003 SET collation_connection  = @saved_col_connection */ ;
/*!50003 DROP PROCEDURE IF EXISTS `ACCOUNT_AUDIT_TRAIL_SAVE` */;
/*!50003 SET @saved_cs_client      = @@character_set_client */ ;
/*!50003 SET @saved_cs_results     = @@character_set_results */ ;
/*!50003 SET @saved_col_connection = @@collation_connection */ ;
/*!50003 SET character_set_client  = latin1 */ ;
/*!50003 SET character_set_results = latin1 */ ;
/*!50003 SET collation_connection  = latin1_swedish_ci */ ;
/*!50003 SET @saved_sql_mode       = @@sql_mode */ ;
/*!50003 SET sql_mode              = '' */ ;
DELIMITER ;;
CREATE DEFINER=`root`@`localhost` PROCEDURE `ACCOUNT_AUDIT_TRAIL_SAVE`(
	IN `PARAM_TRAIL_MODULE_ID` BIGINT,
	IN `PARAM_MODULE_KEYWORD` VARCHAR(1000),
	IN `PARAM_TRAIL_TARGET_ID` BIGINT,
	IN `PARAM_TRAIL_TARGET_SERVER_ID` BIGINT,
	IN `PARAM_METHOD_KEYWORD` VARCHAR(1000),
	IN `PARAM_TRAIL_DESCRIPTION` VARCHAR(500),
	IN `PARAM_TRAIL_PARAMETERS` VARCHAR(4000),
	
	IN `PARAM_REQUESTER_USERNAME` VARCHAR(500),
	IN `PARAM_REQUESTER_PASSWORD` VARCHAR(500),
	IN `PARAM_REQUESTER_PROXY_ID` BIGINT,
	IN `PARAM_REQUESTER_PROXY_PASSWORD` VARCHAR(1000),
	IN `PARAM_REQUESTER_DEVICE_PUBLIC_KEY` VARCHAR(1000),
	IN `PARAM_REQUESTER_DEVICE_PRIVATE_KEY` VARCHAR(1000),
	
	IN `PARAM_TRAIL_REQUEST_IP_ADDRESS` VARCHAR(500),
	IN `PARAM_UNIQUE_SESSION_ID` VARCHAR(1000),
	IN `PARAM_SOURCE_SERVER_ID` BIGINT,
	IN `PARAM_SUPPRESS_RETURN` BIT
)
SP_SAVE:
BEGIN

	-- INITIALIZE
	-- _______________________________________________________________________
	DECLARE STATUS_INACTIVE TINYINT DEFAULT 1;
	DECLARE STATUS_ACTIVE TINYINT DEFAULT 2;
	
	DECLARE PARAM_TRAIL_ID BIGINT DEFAULT 0;
	DECLARE PARAM_METHOD_ID BIGINT DEFAULT 0;
	DECLARE TEMP_AUTHENTICATED_ACCOUNT_ID BIGINT DEFAULT 0;
	DECLARE TEMP_AUTHENTICATED_PROXY_ID BIGINT DEFAULT 0;
	DECLARE TEMP_AUTHENTICATED_DEVICE_ID BIGINT DEFAULT 0;
	
	DECLARE TEMP_ERR_MESSAGE VARCHAR(500) DEFAULT '';
	DECLARE ERR BIGINT DEFAULT 0;
		
		
	-- Error Handler
	-- _______________________________________________________________________
	DECLARE EXIT HANDLER FOR SQLEXCEPTION
	BEGIN
		RESIGNAL;
	END;	
	
	
	-- RETRIEVE ACCOUNT DATA
	-- _______________________________________________________________________
	SET TEMP_AUTHENTICATED_DEVICE_ID = `ACCOUNT_DEVICE@ACC_DEVICE_ID_FROM_LOGIN`(PARAM_REQUESTER_DEVICE_PUBLIC_KEY, PARAM_REQUESTER_DEVICE_PRIVATE_KEY);
	SET TEMP_AUTHENTICATED_ACCOUNT_ID = `ACCOUNT_MEMBER@ACC_ACCOUNT_ID_FROM_LOGIN`(PARAM_REQUESTER_USERNAME, PARAM_REQUESTER_PASSWORD);
			
	IF 
		`ACCOUNT_PROXY_ACCESS@IS_LEGIT`
		(
			PARAM_REQUESTER_PROXY_ID,
			PARAM_REQUESTER_PROXY_PASSWORD
		) = 1
	THEN
		SET TEMP_AUTHENTICATED_PROXY_ID = PARAM_REQUESTER_PROXY_ID;
	END IF;

	
	-- VALIDATION
	-- _______________________________________________________________________
	
	-- RETRIEVE TRAIL_MODULE_ID IF KEYWORD IS GIVEN
	-- ####################################################
	IF `SYSTEM_VAR@IS_NULL@NVARCHAR`(PARAM_MODULE_KEYWORD, 1) = 0 THEN
		SET PARAM_TRAIL_MODULE_ID = `SYSTEM_MODULE@SYS_MODULE_ID_FROM_KEYWORD`(PARAM_MODULE_KEYWORD);
	END IF;

	
	-- CHECK IF THE GIVEN MODULE ID EXISTS
	-- ####################################################
	IF `SYSTEM_MODULE@SYS_MODULE_ID_EXISTS`(PARAM_TRAIL_MODULE_ID, 0) <= 0 THEN
		SET ERR = `RAISERROR`('INVALID INDEX IN `PARAM_TRAIL_MODULE_ID`');
	END IF;

	
	-- CHECK METHOD VALID
	-- ####################################################
	SET PARAM_METHOD_ID = `SYSTEM_TRAIL_METHOD@SYS_METHOD_ID_FROM_KEYWORD`(PARAM_METHOD_KEYWORD, 0);
	IF `SYSTEM_TRAIL_METHOD@SYS_METHOD_ID_EXISTS`(PARAM_METHOD_ID, 1) <= 0 THEN
		SET TEMP_ERR_MESSAGE = CONCAT_WS(' ', 'INVALID METHOD IN `PARAM_METHOD_ID`. KEY:', PARAM_METHOD_KEYWORD);
		SET ERR = `RAISERROR`(TEMP_ERR_MESSAGE);
	END IF;
		
		
	-- INVALID SERVER (CONSIDER 0- AS SELF)
	-- ####################################################
	IF 
		PARAM_SOURCE_SERVER_ID > 0 AND
		`ACCOUNT_SERVER@ACC_SERVER_ID_EXISTS`(PARAM_SOURCE_SERVER_ID, 0) = 0 
	THEN
		SET ERR = `RAISERROR`('INVALID SERVER');
	END IF;
		
		
	-- HANDLE NULLs IN PARAMETER
	-- ####################################################
	SET PARAM_TRAIL_PARAMETERS = `SYSTEM_VAR@REPLACE_NULL@NVARCHAR`(PARAM_TRAIL_PARAMETERS, 'NO DATA', 1);
	IF `SYSTEM_VAR@IS_NULL@BIGINT`(PARAM_TRAIL_TARGET_ID, 1, 1) = 1 THEN
		SET PARAM_TRAIL_TARGET_ID = 0;
	END IF;
	
	-- Unknow machine details
	-- ####################################################
	IF `SYSTEM_VAR@IS_NULL@NVARCHAR`(PARAM_UNIQUE_SESSION_ID, 1) = 1 THEN
		SET PARAM_UNIQUE_SESSION_ID = 'NO DATA';
	END IF;	


	-- NOT YET DOWNLOADED DATA
	-- _______________________________________________________________________
	INSERT INTO
	`account_audit_trail`
	(
		`account_audit_trail`.`ACC_TRAIL_REQUEST_IP_ADDRESS`,
		`account_audit_trail`.`ACC_TRAIL_SYS_METHOD_ID`,	
		`account_audit_trail`.`ACC_TRAIL_ACC_DEVICE_ID`, 
		`account_audit_trail`.`ACC_TRAIL_ACC_ACCOUNT_ID`, 
		`account_audit_trail`.`ACC_TRAIL_PROXY_USER`, 
		`account_audit_trail`.`ACC_TRAIL_ACC_SERVER_ID`,
		
		`account_audit_trail`.`ACC_TRAIL_SYS_MODULE_ID`,
		`account_audit_trail`.`ACC_TRAIL_TARGET_ID`,
		`account_audit_trail`.`ACC_TRAIL_TARGET_SERVER_ID`,
		`account_audit_trail`.`ACC_TRAIL_DESCRIPTION`,
		`account_audit_trail`.`ACC_TRAIL_PARAMETERS`,
		`account_audit_trail`.`ACC_TRAIL_UNIQUE_SESSION_ID`,
		`account_audit_trail`.`ACC_TRAIL_TIMESTAMP`
	)
	VALUES
	(
		PARAM_TRAIL_REQUEST_IP_ADDRESS,
		PARAM_METHOD_ID,
		TEMP_AUTHENTICATED_DEVICE_ID,
		TEMP_AUTHENTICATED_ACCOUNT_ID,
		TEMP_AUTHENTICATED_PROXY_ID,
		PARAM_SOURCE_SERVER_ID,
		
		PARAM_TRAIL_MODULE_ID,
		PARAM_TRAIL_TARGET_ID,
		PARAM_TRAIL_TARGET_SERVER_ID,
		PARAM_TRAIL_DESCRIPTION,
		PARAM_TRAIL_PARAMETERS,
		PARAM_UNIQUE_SESSION_ID,
		`SYSTEM_VAR@NOW`('', 1)
	);
	
	-- Make Sure the next requests won't make audit trail with exactly same Timestamp.
	-- _______________________________________________________________________
	DO SLEEP(0.0001);
	
END ;;
DELIMITER ;
/*!50003 SET sql_mode              = @saved_sql_mode */ ;
/*!50003 SET character_set_client  = @saved_cs_client */ ;
/*!50003 SET character_set_results = @saved_cs_results */ ;
/*!50003 SET collation_connection  = @saved_col_connection */ ;
/*!50003 DROP PROCEDURE IF EXISTS `ACCOUNT_BFIP_GET` */;
/*!50003 SET @saved_cs_client      = @@character_set_client */ ;
/*!50003 SET @saved_cs_results     = @@character_set_results */ ;
/*!50003 SET @saved_col_connection = @@collation_connection */ ;
/*!50003 SET character_set_client  = latin1 */ ;
/*!50003 SET character_set_results = latin1 */ ;
/*!50003 SET collation_connection  = latin1_swedish_ci */ ;
/*!50003 SET @saved_sql_mode       = @@sql_mode */ ;
/*!50003 SET sql_mode              = '' */ ;
DELIMITER ;;
CREATE DEFINER=`root`@`localhost` PROCEDURE `ACCOUNT_BFIP_GET`(
	IN `PARAM_ACC_BFIP_ID` BIGINT,	
	IN `PARAM_ACC_BFIP_IP` VARCHAR(400),	
	IN `PARAM_ACC_BFIP_DESCRIPTION` VARCHAR(400),	
	IN `PARAM_ACC_BFIP_LAST_ACTIVITY_FROM` DATETIME(6),
	IN `PARAM_ACC_BFIP_LAST_ACTIVITY_TO` DATETIME(6),
	IN `PARAM_ACC_BFIP_FAIL_COUNT_FROM` BIGINT,
	IN `PARAM_ACC_BFIP_FAIL_COUNT_TO` BIGINT,
	IN `PARAM_ACC_BFIP_LOCK_COUNT_FROM` BIGINT,
	IN `PARAM_ACC_BFIP_LOCK_COUNT_TO` BIGINT,
	IN `PARAM_ACC_BFIP_SUCCESS_COUNT_FROM` BIGINT,
	IN `PARAM_ACC_BFIP_SUCCESS_COUNT_TO` BIGINT,
	IN `PARAM_ACC_BFIP_STATUS` TINYINT,	
		
	IN `PARAM_ORDER_FIELD` VARCHAR(500),
	IN `PARAM_ORDER_TYPE` VARCHAR(500),
	IN `PARAM_SKIP` BIGINT,
	IN `PARAM_LIMIT` BIGINT,

	IN `PARAM_REQUESTER_USERNAME` VARCHAR(500),
	IN `PARAM_REQUESTER_PASSWORD` VARCHAR(500),
	IN `PARAM_REQUESTER_PROXY_ID` BIGINT,
	IN `PARAM_REQUESTER_PROXY_PASSWORD` VARCHAR(1000),
	IN `PARAM_REQUESTER_DEVICE_PUBLIC_KEY` VARCHAR(1000),
	IN `PARAM_REQUESTER_DEVICE_PRIVATE_KEY` VARCHAR(1000),
	
	IN `PARAM_REQUESTER_IP` VARCHAR(1000),
	IN `PARAM_UNIQUE_SESSION_ID` VARCHAR(1000),
	IN `PARAM_SUPPRESS_RETURN` BIT
)
SP_GET:
BEGIN

	-- Status
	-- =========================================================================================
	DECLARE STATUS_INACTIVE TINYINT DEFAULT 1;
	DECLARE STATUS_ACTIVE TINYINT DEFAULT 2;
	DECLARE STATUS_CLOSED TINYINT DEFAULT 3;
	DECLARE STATUS_COMPLETED TINYINT DEFAULT 4;
	
	-- Audit Handler
	-- =========================================================================================
	DECLARE TEMP_RECORD_EXISTS BIT DEFAULT 0;
	DECLARE TEMP_MODULE_KEYWORD VARCHAR(500) DEFAULT 'account_bfip';
	DECLARE TEMP_SP_OBJECTIVE VARCHAR(500) DEFAULT 'Retrieve Bruteforce IP record';
	DECLARE TEMP_ERR_MESSAGE VARCHAR(500) DEFAULT '';
	DECLARE ERR BIGINT DEFAULT 0;
	DECLARE TEMP_RECORD_CHANGES VARCHAR(16000) DEFAULT '';
	DECLARE TEMP_RECORD_BINDED BIT DEFAULT 0;
	
	DECLARE TEMP_RECORD_BINDED_ID BIGINT DEFAULT 0;
	DECLARE TEMP_RECORD_BINDED_SERVER_ID BIGINT DEFAULT 0;
	
	-- Authentication
	-- =========================================================================================
	DECLARE TEMP_ACCESS_RIGHTS_DENIED BIT DEFAULT 0;
	DECLARE TEMP_AUTHENTICATED_ACCOUNT_ID BIGINT DEFAULT `ACCOUNT_MEMBER@ACC_ACCOUNT_ID_FROM_LOGIN`(PARAM_REQUESTER_USERNAME, PARAM_REQUESTER_PASSWORD);
	DECLARE TEMP_AUTHENTICATED_ACCOUNT_LEVEL BIGINT DEFAULT 0;
	DECLARE TEMP_AUTHENTICATED_ACCOUNT_GROUP BIGINT DEFAULT 0;
	
	-- Local Parameters
	-- =========================================================================================
	DECLARE TEMP_NOW DATETIME(6) DEFAULT `SYSTEM_VAR@NOW`('', 1);
	DECLARE TEMP_RECORD_COUNT BIGINT DEFAULT 0;
	
	
	-- Check NULLs
	-- =========================================================================================
	DECLARE IS_NULL_ACC_BFIP_ID BIT DEFAULT `SYSTEM_VAR@IS_NULL@BIGINT`(PARAM_ACC_BFIP_ID, 1, 1);
	DECLARE IS_NULL_ACC_BFIP_IP BIT DEFAULT `SYSTEM_VAR@IS_NULL@NVARCHAR`(PARAM_ACC_BFIP_IP, 1);
	DECLARE IS_NULL_ACC_BFIP_DESCRIPTION BIT DEFAULT `SYSTEM_VAR@IS_NULL@NVARCHAR`(PARAM_ACC_BFIP_DESCRIPTION, 1);
	DECLARE IS_NULL_ACC_BFIP_LAST_ACTIVITY_FROM BIT DEFAULT `SYSTEM_VAR@IS_NULL@DATETIME`(PARAM_ACC_BFIP_LAST_ACTIVITY_FROM, 1);
	DECLARE IS_NULL_ACC_BFIP_LAST_ACTIVITY_TO BIT DEFAULT `SYSTEM_VAR@IS_NULL@DATETIME`(PARAM_ACC_BFIP_LAST_ACTIVITY_TO, 1);				
	DECLARE IS_NULL_ACC_BFIP_FAIL_COUNT_FROM BIT DEFAULT `SYSTEM_VAR@IS_NULL@BIGINT`(PARAM_ACC_BFIP_FAIL_COUNT_FROM, 1, 1);
	DECLARE IS_NULL_ACC_BFIP_FAIL_COUNT_TO BIT DEFAULT `SYSTEM_VAR@IS_NULL@BIGINT`(PARAM_ACC_BFIP_FAIL_COUNT_TO, 1, 1);
	DECLARE IS_NULL_ACC_BFIP_LOCK_COUNT_FROM BIT DEFAULT `SYSTEM_VAR@IS_NULL@BIGINT`(PARAM_ACC_BFIP_LOCK_COUNT_FROM, 1, 1);
	DECLARE IS_NULL_ACC_BFIP_LOCK_COUNT_TO BIT DEFAULT `SYSTEM_VAR@IS_NULL@BIGINT`(PARAM_ACC_BFIP_LOCK_COUNT_TO, 1, 1);
	DECLARE IS_NULL_ACC_BFIP_SUCCESS_COUNT_FROM BIT DEFAULT `SYSTEM_VAR@IS_NULL@BIGINT`(PARAM_ACC_BFIP_SUCCESS_COUNT_FROM, 1, 1);
	DECLARE IS_NULL_ACC_BFIP_SUCCESS_COUNT_TO BIT DEFAULT `SYSTEM_VAR@IS_NULL@BIGINT`(PARAM_ACC_BFIP_SUCCESS_COUNT_TO, 1, 1);
	DECLARE IS_NULL_ACC_BFIP_STATUS BIT DEFAULT `SYSTEM_VAR@IS_NULL@TINYINT`(PARAM_ACC_BFIP_STATUS, 1, 1);
	
	-- Error Handler
	-- =========================================================================================
	DECLARE EXIT HANDLER FOR SQLEXCEPTION
	BEGIN
		RESIGNAL;
	END;
	
	-- Ignore Time from DateTime (Set Time 00:00:00.000000 and 23:59:59.999999)
	-- =========================================================================================
		
		
	-- Access Rights [Device]
	-- =========================================================================================
	IF `ACCOUNT_DEVICE@HAS_PERMISSION`(PARAM_REQUESTER_DEVICE_PUBLIC_KEY, PARAM_REQUESTER_DEVICE_PRIVATE_KEY) = 0 THEN
		SET TEMP_ERR_MESSAGE = 'Your device is not authorized yet to access this server.';
		SET ERR = `RAISERROR`(TEMP_ERR_MESSAGE);		
	END IF;
		
		
	-- Access Rights [Account]
	-- =========================================================================================
		
	IF 
		`ACCOUNT_ACCESS_RIGHTS@HAS_PERMISSION`(PARAM_REQUESTER_USERNAME, PARAM_REQUESTER_PASSWORD, 0, TEMP_MODULE_KEYWORD, 1) = 0 AND
		`ACCOUNT_ACCESS_RIGHTS@PROXY_PERMISSION`(PARAM_REQUESTER_PROXY_ID, PARAM_REQUESTER_PROXY_PASSWORD, 0, TEMP_MODULE_KEYWORD, 1) = 0
	THEN
		SET TEMP_ACCESS_RIGHTS_DENIED = 1;
		CALL `ACCOUNT_ACCESS_RIGHTS_DENY`
		(
			0, TEMP_MODULE_KEYWORD, 0, 0, TEMP_SP_OBJECTIVE, TEMP_RECORD_CHANGES, 
			PARAM_REQUESTER_USERNAME, PARAM_REQUESTER_PASSWORD, 
			PARAM_REQUESTER_PROXY_ID, PARAM_REQUESTER_PROXY_PASSWORD,
			PARAM_REQUESTER_DEVICE_PUBLIC_KEY, PARAM_REQUESTER_DEVICE_PRIVATE_KEY,
			PARAM_REQUESTER_IP, PARAM_UNIQUE_SESSION_ID,
			0, PARAM_SUPPRESS_RETURN
		);
	END IF;
	
	
	
	-- COUNT RECORD
	-- =========================================================================================
	
	-- SELECT COLUMNS
	-- ####################################################
	SELECT
		COUNT(DISTINCT `account_bfip`.`ACC_BFIP_ID`)
	INTO
		TEMP_RECORD_COUNT

	FROM `account_bfip`
				
		-- Add Inner Joins (Per Foreign-key)
		
	-- CONDITIONS
	-- ####################################################
	WHERE
		(
			IS_NULL_ACC_BFIP_ID = 1 OR
			`account_bfip`.`ACC_BFIP_ID` = PARAM_ACC_BFIP_ID			
		) AND
		(
			IS_NULL_ACC_BFIP_IP = 1 OR
			`account_bfip`.`ACC_BFIP_IP` LIKE CONCAT_WS('%', '', PARAM_ACC_BFIP_IP, '')			
		) AND 		
		(
			IS_NULL_ACC_BFIP_DESCRIPTION = 1 OR
			`account_bfip`.`ACC_BFIP_DESCRIPTION` LIKE CONCAT_WS('%', '', PARAM_ACC_BFIP_DESCRIPTION, '')			
		) AND 		
		(
			IS_NULL_ACC_BFIP_LAST_ACTIVITY_FROM = 1 OR
			`account_bfip`.`ACC_BFIP_LAST_ACTIVITY` >= PARAM_ACC_BFIP_LAST_ACTIVITY_FROM			
		) AND
		(
			IS_NULL_ACC_BFIP_LAST_ACTIVITY_TO = 1 OR
			`account_bfip`.`ACC_BFIP_LAST_ACTIVITY` <= PARAM_ACC_BFIP_LAST_ACTIVITY_TO			
		) AND 		
		(
			IS_NULL_ACC_BFIP_FAIL_COUNT_FROM = 1 OR
			`account_bfip`.`ACC_BFIP_FAIL_COUNT` >= PARAM_ACC_BFIP_FAIL_COUNT_FROM			
		) AND
		(
			IS_NULL_ACC_BFIP_FAIL_COUNT_TO = 1 OR
			`account_bfip`.`ACC_BFIP_FAIL_COUNT` <= PARAM_ACC_BFIP_FAIL_COUNT_TO			
		) AND 		
		(
			IS_NULL_ACC_BFIP_LOCK_COUNT_FROM = 1 OR
			`account_bfip`.`ACC_BFIP_LOCK_COUNT` >= PARAM_ACC_BFIP_LOCK_COUNT_FROM			
		) AND
		(
			IS_NULL_ACC_BFIP_LOCK_COUNT_TO = 1 OR
			`account_bfip`.`ACC_BFIP_LOCK_COUNT` <= PARAM_ACC_BFIP_LOCK_COUNT_TO			
		) AND 		
		(
			IS_NULL_ACC_BFIP_SUCCESS_COUNT_FROM = 1 OR
			`account_bfip`.`ACC_BFIP_SUCCESS_COUNT` >= PARAM_ACC_BFIP_SUCCESS_COUNT_FROM			
		) AND
		(
			IS_NULL_ACC_BFIP_SUCCESS_COUNT_TO = 1 OR
			`account_bfip`.`ACC_BFIP_SUCCESS_COUNT` <= PARAM_ACC_BFIP_SUCCESS_COUNT_TO			
		) AND 		
		(
			IS_NULL_ACC_BFIP_STATUS = 1 OR
			`account_bfip`.`ACC_BFIP_STATUS` = PARAM_ACC_BFIP_STATUS			
		) 
;	

		
		
	-- SELECT RECORDS
	-- =========================================================================================
	
	-- FETCH COLUMNS
	-- ####################################################
	SELECT
		-- ACCOUNT_BFIP DETAILS
		`account_bfip`.`ACC_BFIP_ID`, 
		`account_bfip`.`ACC_BFIP_IP`, 
		`account_bfip`.`ACC_BFIP_DESCRIPTION`, 
		`account_bfip`.`ACC_BFIP_LAST_ACTIVITY`, 
		`account_bfip`.`ACC_BFIP_FAIL_COUNT`, 
		`account_bfip`.`ACC_BFIP_LOCK_COUNT`, 
		`account_bfip`.`ACC_BFIP_SUCCESS_COUNT`, 
		`account_bfip`.`ACC_BFIP_STATUS`,
		IF
		(
			`account_bfip`.`ACC_BFIP_STATUS` = STATUS_INACTIVE, 'Blocked',
			IF
			(
				`account_bfip`.`ACC_BFIP_STATUS` = STATUS_ACTIVE, 'Regular',
				IF
				(
					`account_bfip`.`ACC_BFIP_STATUS` = STATUS_CLOSED, 'Blacklist',
					'Whitelist'
				)
			)
		) AS SYS_STATUS_DESCRIPTION

		-- Sum of Child [Numerics, non-primary/foreign keys, nor status, active/inactive, and system generated.]
		
		
		-- Inner join fields
		
		-- Left join fields
		
		, TEMP_NOW AS SERVER_TIME,
		TEMP_RECORD_COUNT AS RECORD_COUNT

	FROM `account_bfip`
	
		-- Add Inner Joins (Per Foreign-key)
		
		-- Add Optional Left Joins (Per Optional Foreign-key)
		
	-- CONDITIONS
	-- ####################################################
	WHERE
		(
			IS_NULL_ACC_BFIP_ID = 1 OR
			`account_bfip`.`ACC_BFIP_ID` = PARAM_ACC_BFIP_ID			
		) AND
		(
			IS_NULL_ACC_BFIP_IP = 1 OR
			`account_bfip`.`ACC_BFIP_IP` LIKE CONCAT_WS('%', '', PARAM_ACC_BFIP_IP, '')			
		) AND 		
		(
			IS_NULL_ACC_BFIP_DESCRIPTION = 1 OR
			`account_bfip`.`ACC_BFIP_DESCRIPTION` LIKE CONCAT_WS('%', '', PARAM_ACC_BFIP_DESCRIPTION, '')			
		) AND 		
		(
			IS_NULL_ACC_BFIP_LAST_ACTIVITY_FROM = 1 OR
			`account_bfip`.`ACC_BFIP_LAST_ACTIVITY` >= PARAM_ACC_BFIP_LAST_ACTIVITY_FROM			
		) AND
		(
			IS_NULL_ACC_BFIP_LAST_ACTIVITY_TO = 1 OR
			`account_bfip`.`ACC_BFIP_LAST_ACTIVITY` <= PARAM_ACC_BFIP_LAST_ACTIVITY_TO			
		) AND 
		(
			IS_NULL_ACC_BFIP_FAIL_COUNT_FROM = 1 OR
			`account_bfip`.`ACC_BFIP_FAIL_COUNT` >= PARAM_ACC_BFIP_FAIL_COUNT_FROM			
		) AND
		(
			IS_NULL_ACC_BFIP_FAIL_COUNT_TO = 1 OR
			`account_bfip`.`ACC_BFIP_FAIL_COUNT` <= PARAM_ACC_BFIP_FAIL_COUNT_TO			
		) AND 
		(
			IS_NULL_ACC_BFIP_LOCK_COUNT_FROM = 1 OR
			`account_bfip`.`ACC_BFIP_LOCK_COUNT` >= PARAM_ACC_BFIP_LOCK_COUNT_FROM			
		) AND
		(
			IS_NULL_ACC_BFIP_LOCK_COUNT_TO = 1 OR
			`account_bfip`.`ACC_BFIP_LOCK_COUNT` <= PARAM_ACC_BFIP_LOCK_COUNT_TO			
		) AND 
		(
			IS_NULL_ACC_BFIP_SUCCESS_COUNT_FROM = 1 OR
			`account_bfip`.`ACC_BFIP_SUCCESS_COUNT` >= PARAM_ACC_BFIP_SUCCESS_COUNT_FROM			
		) AND
		(
			IS_NULL_ACC_BFIP_SUCCESS_COUNT_TO = 1 OR
			`account_bfip`.`ACC_BFIP_SUCCESS_COUNT` <= PARAM_ACC_BFIP_SUCCESS_COUNT_TO			
		) AND 
		(
			IS_NULL_ACC_BFIP_STATUS = 1 OR
			`account_bfip`.`ACC_BFIP_STATUS` = PARAM_ACC_BFIP_STATUS			
		) 

	-- ORDER BY
	-- ####################################################
	ORDER BY
		-- ACCOUNT_BFIP DETAILS
		CASE WHEN PARAM_ORDER_FIELD = 'ACC_BFIP_ID' AND PARAM_ORDER_TYPE = 'ASC' THEN `account_bfip`.`ACC_BFIP_ID` END ASC, 
		CASE WHEN PARAM_ORDER_FIELD = 'ACC_BFIP_ID' AND PARAM_ORDER_TYPE = 'DESC' THEN `account_bfip`.`ACC_BFIP_ID` END DESC,	
		CASE WHEN PARAM_ORDER_FIELD = 'ACC_BFIP_IP' AND PARAM_ORDER_TYPE = 'ASC' THEN `account_bfip`.`ACC_BFIP_IP` END ASC, 
		CASE WHEN PARAM_ORDER_FIELD = 'ACC_BFIP_IP' AND PARAM_ORDER_TYPE = 'DESC' THEN `account_bfip`.`ACC_BFIP_IP` END DESC,	
		CASE WHEN PARAM_ORDER_FIELD = 'ACC_BFIP_DESCRIPTION' AND PARAM_ORDER_TYPE = 'ASC' THEN `account_bfip`.`ACC_BFIP_DESCRIPTION` END ASC, 
		CASE WHEN PARAM_ORDER_FIELD = 'ACC_BFIP_DESCRIPTION' AND PARAM_ORDER_TYPE = 'DESC' THEN `account_bfip`.`ACC_BFIP_DESCRIPTION` END DESC,	
		CASE WHEN PARAM_ORDER_FIELD = 'ACC_BFIP_LAST_ACTIVITY' AND PARAM_ORDER_TYPE = 'ASC' THEN `account_bfip`.`ACC_BFIP_LAST_ACTIVITY` END ASC, 
		CASE WHEN PARAM_ORDER_FIELD = 'ACC_BFIP_LAST_ACTIVITY' AND PARAM_ORDER_TYPE = 'DESC' THEN `account_bfip`.`ACC_BFIP_LAST_ACTIVITY` END DESC,	
		CASE WHEN PARAM_ORDER_FIELD = 'ACC_BFIP_FAIL_COUNT' AND PARAM_ORDER_TYPE = 'ASC' THEN `account_bfip`.`ACC_BFIP_FAIL_COUNT` END ASC, 
		CASE WHEN PARAM_ORDER_FIELD = 'ACC_BFIP_FAIL_COUNT' AND PARAM_ORDER_TYPE = 'DESC' THEN `account_bfip`.`ACC_BFIP_FAIL_COUNT` END DESC,	
		CASE WHEN PARAM_ORDER_FIELD = 'ACC_BFIP_LOCK_COUNT' AND PARAM_ORDER_TYPE = 'ASC' THEN `account_bfip`.`ACC_BFIP_LOCK_COUNT` END ASC, 
		CASE WHEN PARAM_ORDER_FIELD = 'ACC_BFIP_LOCK_COUNT' AND PARAM_ORDER_TYPE = 'DESC' THEN `account_bfip`.`ACC_BFIP_LOCK_COUNT` END DESC,	
		CASE WHEN PARAM_ORDER_FIELD = 'ACC_BFIP_SUCCESS_COUNT' AND PARAM_ORDER_TYPE = 'ASC' THEN `account_bfip`.`ACC_BFIP_SUCCESS_COUNT` END ASC, 
		CASE WHEN PARAM_ORDER_FIELD = 'ACC_BFIP_SUCCESS_COUNT' AND PARAM_ORDER_TYPE = 'DESC' THEN `account_bfip`.`ACC_BFIP_SUCCESS_COUNT` END DESC,	
		CASE WHEN PARAM_ORDER_FIELD = 'ACC_BFIP_STATUS' AND PARAM_ORDER_TYPE = 'ASC' THEN `account_bfip`.`ACC_BFIP_STATUS` END ASC, 
		CASE WHEN PARAM_ORDER_FIELD = 'ACC_BFIP_STATUS' AND PARAM_ORDER_TYPE = 'DESC' THEN `account_bfip`.`ACC_BFIP_STATUS` END DESC,	

		-- Inner joins
		
		-- EXTRA
		CASE WHEN PARAM_ORDER_FIELD <> 'ACC_BFIP_IP' THEN `account_bfip`.`ACC_BFIP_IP` END ASC
		
	-- LIMIT & OFFSET
	-- ####################################################		
	LIMIT PARAM_SKIP, PARAM_LIMIT;
	
	
	
	-- EXIT PROCEDURE
	-- =========================================================================================
	LEAVE SP_GET;
			
END ;;
DELIMITER ;
/*!50003 SET sql_mode              = @saved_sql_mode */ ;
/*!50003 SET character_set_client  = @saved_cs_client */ ;
/*!50003 SET character_set_results = @saved_cs_results */ ;
/*!50003 SET collation_connection  = @saved_col_connection */ ;
/*!50003 DROP PROCEDURE IF EXISTS `ACCOUNT_BFIP_POST_LOGIN` */;
/*!50003 SET @saved_cs_client      = @@character_set_client */ ;
/*!50003 SET @saved_cs_results     = @@character_set_results */ ;
/*!50003 SET @saved_col_connection = @@collation_connection */ ;
/*!50003 SET character_set_client  = latin1 */ ;
/*!50003 SET character_set_results = latin1 */ ;
/*!50003 SET collation_connection  = latin1_swedish_ci */ ;
/*!50003 SET @saved_sql_mode       = @@sql_mode */ ;
/*!50003 SET sql_mode              = '' */ ;
DELIMITER ;;
CREATE DEFINER=`root`@`localhost` PROCEDURE `ACCOUNT_BFIP_POST_LOGIN`(
	IN `PARAM_LOGIN_RESULT` TINYINT,
	
	IN `PARAM_REQUESTER_USERNAME` VARCHAR(500),
	IN `PARAM_REQUESTER_PASSWORD` VARCHAR(500),
	IN `PARAM_REQUESTER_IP` VARCHAR(1000)
)
SP_POST_LOGIN:
BEGIN


	-- 1) DECLARE LOCAL PARAMETERS
	-- _______________________________________________________________________
	
	-- Status
	-- ...........................................
	DECLARE STATUS_INACTIVE TINYINT DEFAULT 1;
	DECLARE STATUS_ACTIVE TINYINT DEFAULT 2;
	DECLARE STATUS_CLOSED TINYINT DEFAULT 3;
	DECLARE STATUS_COMPLETED TINYINT DEFAULT 4;
	
	-- Local Parameters
	-- ...........................................
	DECLARE TEMP_NOW DATETIME(6) DEFAULT `SYSTEM_VAR@NOW`('', 1);
	DECLARE TEMP_TIME_RANGE DATETIME(6) DEFAULT TEMP_NOW;
	DECLARE TEMP_RECORD_COUNT BIGINT DEFAULT 0;
	
	DECLARE BRUTEFORCE_IP_BLOCK_PERIOD BIGINT DEFAULT 0;
	DECLARE BRUTEFORCE_IP_BLOCK_ATTEMPT BIGINT DEFAULT 0;
	DECLARE BRUTEFORCE_IP_BLOCK_PERMANENT BIGINT DEFAULT 0;
	DECLARE BRUTEFORCE_LOGIN_RETAIN_PERIOD BIGINT DEFAULT 0;

	DECLARE PARAM_ACC_BFIP_ID BIGINT DEFAULT 0;
	DECLARE TEMP_ACC_BFIP_FAIL_COUNT BIGINT DEFAULT 0;
	DECLARE TEMP_ACC_BFIP_LOCK_COUNT BIGINT DEFAULT 0;
	DECLARE TEMP_ACC_BFIP_SUCCESS_COUNT BIGINT DEFAULT 0;
	DECLARE TEMP_ACC_BFIP_STATUS TINYINT DEFAULT 0;
	DECLARE TEMP_ACC_BFLOGIN_STATUS TINYINT DEFAULT 0;

	-- AutoGen Parameters
	-- ...........................................
	DECLARE PARAM_ACC_BFIP_LAST_ACTIVITY DATETIME(6) DEFAULT '1000-01-01 00:00:00.000000'; 


	-- 2) Try Catch / Throw
	-- _______________________________________________________________________
	DECLARE EXIT HANDLER FOR SQLEXCEPTION
	BEGIN
		RESIGNAL;
	END;


	-- 3) Don't keep success login, with same username and IP, if requested in short time frame 
	-- _______________________________________________________________________
	SET TEMP_TIME_RANGE = DATE_SUB(TEMP_NOW, INTERVAL 180 MINUTE);
	IF
		PARAM_LOGIN_RESULT = STATUS_INACTIVE AND
		(
			SELECT COUNT(`account_bflogin`.`ACC_BFLOGIN_ID`)
			FROM `account_bflogin`
			WHERE
				`account_bflogin`.`ACC_BFLOGIN_IP` = PARAM_REQUESTER_IP AND
				`account_bflogin`.`ACC_BFLOGIN_USERNAME` = PARAM_REQUESTER_USERNAME AND
				`account_bflogin`.`ACC_BFLOGIN_DATE` > TEMP_TIME_RANGE AND
				`account_bflogin`.`ACC_BFLOGIN_STATUS` = STATUS_ACTIVE
		) >= 1
	THEN
		LEAVE SP_POST_LOGIN;
	END IF;


	-- 4) Get Bruteforce Settings
	-- _______________________________________________________________________
	SELECT `system_settings`.`SYS_SETTINGS_VAL_BIGINT`
	INTO BRUTEFORCE_IP_BLOCK_PERIOD
	FROM `system_settings`
	WHERE
		`system_settings`.`SYS_SETTINGS_CODE` = 'BRUTEFORCE_IP_BLOCK_PERIOD'
	LIMIT 1;
	
	SELECT `system_settings`.`SYS_SETTINGS_VAL_BIGINT`
	INTO BRUTEFORCE_IP_BLOCK_ATTEMPT
	FROM `system_settings`
	WHERE
		`system_settings`.`SYS_SETTINGS_CODE` = 'BRUTEFORCE_IP_BLOCK_ATTEMPT'
	LIMIT 1;
	
	SELECT `system_settings`.`SYS_SETTINGS_VAL_BIGINT`
	INTO BRUTEFORCE_IP_BLOCK_PERMANENT
	FROM `system_settings`
	WHERE
		`system_settings`.`SYS_SETTINGS_CODE` = 'BRUTEFORCE_IP_BLOCK_PERMANENT'
	LIMIT 1;
	
	SELECT `system_settings`.`SYS_SETTINGS_VAL_BIGINT`
	INTO BRUTEFORCE_LOGIN_RETAIN_PERIOD
	FROM `system_settings`
	WHERE
		`system_settings`.`SYS_SETTINGS_CODE` = 'BRUTEFORCE_LOGIN_RETAIN_PERIOD'
	LIMIT 1;

	
	-- 5) Hide Passwords
	-- _______________________________________________________________________
	SET TEMP_RECORD_COUNT = CHAR_LENGTH(PARAM_REQUESTER_PASSWORD);

	IF PARAM_LOGIN_RESULT = STATUS_INACTIVE THEN
		SET PARAM_REQUESTER_PASSWORD = '******';

	ELSEIF CHAR_LENGTH(PARAM_REQUESTER_PASSWORD) <= 5 THEN
		SET PARAM_REQUESTER_PASSWORD = '';
		WHILE CHAR_LENGTH(PARAM_REQUESTER_PASSWORD) < TEMP_RECORD_COUNT DO
			SET PARAM_REQUESTER_PASSWORD = CONCAT(PARAM_REQUESTER_PASSWORD, "*");
		END WHILE;
	ELSE	
		SET PARAM_REQUESTER_PASSWORD = RIGHT(PARAM_REQUESTER_PASSWORD, 2);	
		WHILE CHAR_LENGTH(PARAM_REQUESTER_PASSWORD) < TEMP_RECORD_COUNT DO
			SET PARAM_REQUESTER_PASSWORD = CONCAT("*", PARAM_REQUESTER_PASSWORD);
		END WHILE;	
	
	END IF;
	
	
	-- 6) Get Existing IP Entry
	-- _______________________________________________________________________
	IF
	(
		SELECT COUNT(`account_bfip`.`ACC_BFIP_ID`)
		FROM `account_bfip`
		WHERE
			`account_bfip`.`ACC_BFIP_IP` = PARAM_REQUESTER_IP
	) <= 0
	THEN
		INSERT INTO
		`account_bfip`
		(
			`account_bfip`.`ACC_BFIP_IP`, 
			`account_bfip`.`ACC_BFIP_DESCRIPTION`, 
			`account_bfip`.`ACC_BFIP_LAST_ACTIVITY`, 
			`account_bfip`.`ACC_BFIP_FAIL_COUNT`, 
			`account_bfip`.`ACC_BFIP_LOCK_COUNT`, 
			`account_bfip`.`ACC_BFIP_SUCCESS_COUNT`, 
			`account_bfip`.`ACC_BFIP_STATUS`
		)
		VALUES
		(
			PARAM_REQUESTER_IP, 
			PARAM_REQUESTER_IP, 
			TEMP_NOW, 
			0, 
			0, 
			0, 
			STATUS_ACTIVE
		);			
		SET PARAM_ACC_BFIP_ID = LAST_INSERT_ID();
		SET TEMP_ACC_BFIP_STATUS = STATUS_ACTIVE;
	
	ELSE
		SELECT
			`account_bfip`.`ACC_BFIP_ID`,
			`account_bfip`.`ACC_BFIP_FAIL_COUNT`, 	
			`account_bfip`.`ACC_BFIP_LOCK_COUNT`, 	
			`account_bfip`.`ACC_BFIP_SUCCESS_COUNT`,
			`account_bfip`.`ACC_BFIP_STATUS`
		INTO
			PARAM_ACC_BFIP_ID,	
			TEMP_ACC_BFIP_FAIL_COUNT, 	
			TEMP_ACC_BFIP_LOCK_COUNT, 	
			TEMP_ACC_BFIP_SUCCESS_COUNT,
			TEMP_ACC_BFIP_STATUS
		FROM `account_bfip`
		WHERE
			`account_bfip`.`ACC_BFIP_IP` = PARAM_REQUESTER_IP
		LIMIT 1;	
	
	END IF;
	
	
	-- 7) Abort if already Blocked/Black Listed/White Listed Accounts
	-- _______________________________________________________________________
	IF TEMP_ACC_BFIP_STATUS <> STATUS_ACTIVE THEN
		LEAVE SP_POST_LOGIN;
	END IF;
	
	
	-- 8) Insert Attempts
	-- _______________________________________________________________________
	IF PARAM_LOGIN_RESULT = STATUS_INACTIVE THEN
		SET TEMP_ACC_BFLOGIN_STATUS = STATUS_ACTIVE;
	ELSE
		SET TEMP_ACC_BFLOGIN_STATUS = STATUS_INACTIVE;
	END IF;
	
	INSERT INTO
	`account_bflogin`
	(
		`account_bflogin`.`ACC_BFLOGIN_USERNAME`, 
		`account_bflogin`.`ACC_BFLOGIN_PASSWORD`, 
		`account_bflogin`.`ACC_BFLOGIN_DATE`, 
		`account_bflogin`.`ACC_BFLOGIN_IP`, 
		`account_bflogin`.`ACC_BFLOGIN_STATUS`
	)
	VALUES
	(
		PARAM_REQUESTER_USERNAME, 
		PARAM_REQUESTER_PASSWORD, 
		TEMP_NOW, 
		PARAM_REQUESTER_IP, 
		TEMP_ACC_BFLOGIN_STATUS
	);	
	

	-- 9) Update Count
	-- _______________________________________________________________________
	IF PARAM_LOGIN_RESULT = 0 THEN
		SET TEMP_ACC_BFIP_FAIL_COUNT = TEMP_ACC_BFIP_FAIL_COUNT + 1;	
		
		-- Block IP with too many failed attempts
		IF 
			TEMP_ACC_BFIP_STATUS = STATUS_ACTIVE AND
			BRUTEFORCE_IP_BLOCK_ATTEMPT <= TEMP_ACC_BFIP_FAIL_COUNT 
		THEN
			SET TEMP_ACC_BFIP_LOCK_COUNT = TEMP_ACC_BFIP_LOCK_COUNT + 1;
			SET TEMP_ACC_BFIP_STATUS = STATUS_INACTIVE;
		END IF;
		
		-- Block IP with too many block history
		IF
			TEMP_ACC_BFIP_STATUS = STATUS_INACTIVE AND
			BRUTEFORCE_IP_BLOCK_PERMANENT <= TEMP_ACC_BFIP_LOCK_COUNT - TEMP_ACC_BFIP_SUCCESS_COUNT
		THEN
			SET TEMP_ACC_BFIP_STATUS = STATUS_CLOSED;
		END IF;
		
	ELSEIF PARAM_LOGIN_RESULT = 1 THEN
		SET TEMP_ACC_BFIP_SUCCESS_COUNT = TEMP_ACC_BFIP_SUCCESS_COUNT + 1;
		
	END IF;
	

			
	-- 10) Update Record
	-- _______________________________________________________________________
	UPDATE `account_bfip`
	SET
		`account_bfip`.`ACC_BFIP_LAST_ACTIVITY` = TEMP_NOW, 
		`account_bfip`.`ACC_BFIP_FAIL_COUNT` = TEMP_ACC_BFIP_FAIL_COUNT, 
		`account_bfip`.`ACC_BFIP_LOCK_COUNT` = TEMP_ACC_BFIP_LOCK_COUNT, 
		`account_bfip`.`ACC_BFIP_SUCCESS_COUNT` = TEMP_ACC_BFIP_SUCCESS_COUNT, 
		`account_bfip`.`ACC_BFIP_STATUS` = TEMP_ACC_BFIP_STATUS
	WHERE
		`account_bfip`.`ACC_BFIP_ID` = PARAM_ACC_BFIP_ID;
	LEAVE SP_POST_LOGIN;


END ;;
DELIMITER ;
/*!50003 SET sql_mode              = @saved_sql_mode */ ;
/*!50003 SET character_set_client  = @saved_cs_client */ ;
/*!50003 SET character_set_results = @saved_cs_results */ ;
/*!50003 SET collation_connection  = @saved_col_connection */ ;
/*!50003 DROP PROCEDURE IF EXISTS `ACCOUNT_BFIP_PRE_LOGIN` */;
/*!50003 SET @saved_cs_client      = @@character_set_client */ ;
/*!50003 SET @saved_cs_results     = @@character_set_results */ ;
/*!50003 SET @saved_col_connection = @@collation_connection */ ;
/*!50003 SET character_set_client  = latin1 */ ;
/*!50003 SET character_set_results = latin1 */ ;
/*!50003 SET collation_connection  = latin1_swedish_ci */ ;
/*!50003 SET @saved_sql_mode       = @@sql_mode */ ;
/*!50003 SET sql_mode              = '' */ ;
DELIMITER ;;
CREATE DEFINER=`root`@`localhost` PROCEDURE `ACCOUNT_BFIP_PRE_LOGIN`(
	IN `PARAM_REQUESTER_IP` VARCHAR(1000)
)
SP_PRE_LOGIN:
BEGIN


	-- 1) DECLARE LOCAL PARAMETERS
	-- _______________________________________________________________________
	
	-- Status
	-- ...........................................
	DECLARE STATUS_INACTIVE TINYINT DEFAULT 1;
	DECLARE STATUS_ACTIVE TINYINT DEFAULT 2;
	DECLARE STATUS_CLOSED TINYINT DEFAULT 3;
	DECLARE STATUS_COMPLETED TINYINT DEFAULT 4;
	
	-- Local Parameters
	-- ...........................................
	DECLARE TEMP_NOW DATETIME(6) DEFAULT `SYSTEM_VAR@NOW`('', 1);
	DECLARE FLUSH_DATE DATETIME(6) DEFAULT TEMP_NOW;
	DECLARE TEMP_RECORD_COUNT BIGINT DEFAULT 0;
	
	DECLARE BRUTEFORCE_IP_BLOCK_PERIOD BIGINT DEFAULT 0;
	DECLARE BRUTEFORCE_IP_BLOCK_ATTEMPT BIGINT DEFAULT 0;
	DECLARE BRUTEFORCE_IP_BLOCK_PERMANENT BIGINT DEFAULT 0;
	DECLARE BRUTEFORCE_LOGIN_RETAIN_PERIOD BIGINT DEFAULT 0;
	
	DECLARE TEMP_ACC_BFIP_ID BIGINT DEFAULT 0;
	DECLARE TEMP_ACC_BFIP_STATUS TINYINT DEFAULT 0;
	
	

	-- AutoGen Parameters
	-- ...........................................
	DECLARE PARAM_ACC_BFIP_LAST_ACTIVITY DATETIME(6) DEFAULT '1000-01-01 00:00:00.000000'; 



	-- 2) Try Catch / Throw
	-- _______________________________________________________________________
	DECLARE EXIT HANDLER FOR SQLEXCEPTION
	BEGIN
		RESIGNAL;
	END;


	-- 3) Get Bruteforce Settings
	-- _______________________________________________________________________
	SELECT `system_settings`.`SYS_SETTINGS_VAL_BIGINT`
	INTO BRUTEFORCE_IP_BLOCK_PERIOD
	FROM `system_settings`
	WHERE
		`system_settings`.`SYS_SETTINGS_CODE` = 'BRUTEFORCE_IP_BLOCK_PERIOD'
	LIMIT 1;
	
	SELECT `system_settings`.`SYS_SETTINGS_VAL_BIGINT`
	INTO BRUTEFORCE_IP_BLOCK_ATTEMPT
	FROM `system_settings`
	WHERE
		`system_settings`.`SYS_SETTINGS_CODE` = 'BRUTEFORCE_IP_BLOCK_ATTEMPT'
	LIMIT 1;
	
	SELECT `system_settings`.`SYS_SETTINGS_VAL_BIGINT`
	INTO BRUTEFORCE_IP_BLOCK_PERMANENT
	FROM `system_settings`
	WHERE
		`system_settings`.`SYS_SETTINGS_CODE` = 'BRUTEFORCE_IP_BLOCK_PERMANENT'
	LIMIT 1;
	
	SELECT `system_settings`.`SYS_SETTINGS_VAL_BIGINT`
	INTO BRUTEFORCE_LOGIN_RETAIN_PERIOD
	FROM `system_settings`
	WHERE
		`system_settings`.`SYS_SETTINGS_CODE` = 'BRUTEFORCE_LOGIN_RETAIN_PERIOD'
	LIMIT 1;



	-- 4) Clean Up Old Login Logs
	-- _______________________________________________________________________
	SET FLUSH_DATE = DATE_SUB(TEMP_NOW, INTERVAL BRUTEFORCE_LOGIN_RETAIN_PERIOD MINUTE);
	DELETE FROM `account_bflogin`
	WHERE
		`account_bflogin`.`ACC_BFLOGIN_DATE` < FLUSH_DATE;
		
		
		
	-- 5) Refresh Failed Attempts, Blocked Status of IP
	-- _______________________________________________________________________
	SET FLUSH_DATE = DATE_SUB(TEMP_NOW, INTERVAL BRUTEFORCE_IP_BLOCK_PERIOD MINUTE);
	
	SELECT
		`account_bfip`.`ACC_BFIP_ID`,
		`account_bfip`.`ACC_BFIP_STATUS`
	INTO
		TEMP_ACC_BFIP_ID,
		TEMP_ACC_BFIP_STATUS
	FROM `account_bfip`
	WHERE
		`account_bfip`.`ACC_BFIP_IP` = PARAM_REQUESTER_IP AND
		`account_bfip`.`ACC_BFIP_LAST_ACTIVITY` < FLUSH_DATE 
	LIMIT 1;


	-- Not Registered / not met the expiry
	IF TEMP_ACC_BFIP_STATUS <= 0 THEN
		LEAVE SP_PRE_LOGIN;
	END IF;
	
	
	-- Lift Blocked Status
	IF TEMP_ACC_BFIP_STATUS = STATUS_INACTIVE THEN
		UPDATE `account_bfip`
		SET
			`account_bfip`.`ACC_BFIP_LAST_ACTIVITY` = TEMP_NOW, 
			`account_bfip`.`ACC_BFIP_FAIL_COUNT` = 0, 
			`account_bfip`.`ACC_BFIP_STATUS` = STATUS_ACTIVE
		WHERE
			`account_bfip`.`ACC_BFIP_ID` = TEMP_ACC_BFIP_ID;	

	-- Lift only the Failed attempts
	ELSE
		UPDATE `account_bfip`
		SET
			`account_bfip`.`ACC_BFIP_LAST_ACTIVITY` = TEMP_NOW, 
			`account_bfip`.`ACC_BFIP_FAIL_COUNT` = 0
		WHERE
			`account_bfip`.`ACC_BFIP_ID` = TEMP_ACC_BFIP_ID;
	END IF;
	LEAVE SP_PRE_LOGIN;


END ;;
DELIMITER ;
/*!50003 SET sql_mode              = @saved_sql_mode */ ;
/*!50003 SET character_set_client  = @saved_cs_client */ ;
/*!50003 SET character_set_results = @saved_cs_results */ ;
/*!50003 SET collation_connection  = @saved_col_connection */ ;
/*!50003 DROP PROCEDURE IF EXISTS `ACCOUNT_BFIP_SAVE` */;
/*!50003 SET @saved_cs_client      = @@character_set_client */ ;
/*!50003 SET @saved_cs_results     = @@character_set_results */ ;
/*!50003 SET @saved_col_connection = @@collation_connection */ ;
/*!50003 SET character_set_client  = latin1 */ ;
/*!50003 SET character_set_results = latin1 */ ;
/*!50003 SET collation_connection  = latin1_swedish_ci */ ;
/*!50003 SET @saved_sql_mode       = @@sql_mode */ ;
/*!50003 SET sql_mode              = '' */ ;
DELIMITER ;;
CREATE DEFINER=`root`@`localhost` PROCEDURE `ACCOUNT_BFIP_SAVE`(
	IN `PARAM_ACC_BFIP_ID` BIGINT,
	IN `PARAM_ACC_BFIP_IP` VARCHAR(400),
	IN `PARAM_ACC_BFIP_DESCRIPTION` VARCHAR(400),
	IN `PARAM_ACC_BFIP_FAIL_COUNT` BIGINT,
	IN `PARAM_ACC_BFIP_LOCK_COUNT` BIGINT,
	IN `PARAM_ACC_BFIP_SUCCESS_COUNT` BIGINT,
	IN `PARAM_ACC_BFIP_STATUS` TINYINT,

	IN `PARAM_REQUESTER_USERNAME` VARCHAR(500),
	IN `PARAM_REQUESTER_PASSWORD` VARCHAR(500),
	IN `PARAM_REQUESTER_PROXY_ID` BIGINT,
	IN `PARAM_REQUESTER_PROXY_PASSWORD` VARCHAR(1000),
	IN `PARAM_REQUESTER_DEVICE_PUBLIC_KEY` VARCHAR(1000),
	IN `PARAM_REQUESTER_DEVICE_PRIVATE_KEY` VARCHAR(1000),
	
	IN `PARAM_REQUESTER_IP` VARCHAR(1000),
	IN `PARAM_UNIQUE_SESSION_ID` VARCHAR(1000),
	IN `PARAM_SUPPRESS_RETURN` BIT,
	
	IN `PARAM_SYNC_SERVER_DESCRIPTION` VARCHAR(500), 
	IN `PARAM_SYNC_SERVER_UNIQUE_KEY` VARCHAR(500)
)
SP_SAVE:
BEGIN


	-- 1) DECLARE LOCAL PARAMETERS
	-- _______________________________________________________________________
	
	-- Status
	-- ...........................................
	DECLARE STATUS_INACTIVE TINYINT DEFAULT 1;
	DECLARE STATUS_ACTIVE TINYINT DEFAULT 2;
	DECLARE STATUS_CLOSED TINYINT DEFAULT 3;
	DECLARE STATUS_COMPLETED TINYINT DEFAULT 4;

	-- Audit Handler
	-- ...........................................
	DECLARE TEMP_RECORD_EXISTS BIT DEFAULT 0;
	DECLARE TEMP_MODULE_KEYWORD VARCHAR(500) DEFAULT 'account_bfip';
	DECLARE TEMP_SP_OBJECTIVE VARCHAR(500) DEFAULT 'add/edit Bruteforce IP record';
	DECLARE TEMP_ERR_MESSAGE VARCHAR(500) DEFAULT '';
	DECLARE ERR BIGINT DEFAULT 0;
	DECLARE TEMP_RECORD_CHANGES VARCHAR(16000) DEFAULT '';
	DECLARE TEMP_RECORD_BINDED BIT DEFAULT 0;

	-- Authentication
	-- ...........................................
	DECLARE TEMP_ACCESS_RIGHTS_DENIED BIT DEFAULT 0;
	DECLARE TEMP_ACCESS_RIGHTS_HAS_OVERRIDE BIT DEFAULT 0;
	DECLARE TEMP_SYNC_SERVER_ID BIGINT DEFAULT 0;
	DECLARE TEMP_SYNC_IS_SERVER_REQUEST BIT DEFAULT 0;
	DECLARE TEMP_AUTHENTICATED_ACCOUNT_ID BIGINT DEFAULT `ACCOUNT_MEMBER@ACC_ACCOUNT_ID_FROM_LOGIN`(PARAM_REQUESTER_USERNAME, PARAM_REQUESTER_PASSWORD);
	DECLARE TEMP_AUTHENTICATED_ACCOUNT_LEVEL BIGINT DEFAULT 0;
	DECLARE TEMP_AUTHENTICATED_ACCOUNT_GROUP BIGINT DEFAULT 0;
	
	-- Local Parameters
	-- ...........................................
	DECLARE TEMP_NOW DATETIME(6) DEFAULT `SYSTEM_VAR@NOW`('', 1);
	DECLARE TEMP_RECORD_COUNT BIGINT DEFAULT 0;

	-- AutoGen Parameters
	-- ...........................................
	DECLARE PARAM_ACC_BFIP_LAST_ACTIVITY DATETIME(6) DEFAULT '1000-01-01 00:00:00.000000'; 
	
	-- Local value holder
	-- ...........................................
	DECLARE TEMP_ACC_BFIP_IP VARCHAR(400) DEFAULT ''; 
	DECLARE TEMP_ACC_BFIP_DESCRIPTION VARCHAR(400) DEFAULT ''; 
	DECLARE TEMP_ACC_BFIP_LAST_ACTIVITY DATETIME(6) DEFAULT '1000-01-01 00:00:00.000000'; 
	DECLARE TEMP_ACC_BFIP_FAIL_COUNT BIGINT DEFAULT 0; 
	DECLARE TEMP_ACC_BFIP_LOCK_COUNT BIGINT DEFAULT 0; 
	DECLARE TEMP_ACC_BFIP_SUCCESS_COUNT BIGINT DEFAULT 0; 
	DECLARE TEMP_ACC_BFIP_STATUS TINYINT DEFAULT 0; 
	
	DECLARE REDUND_ACC_BFIP_ID BIGINT DEFAULT 0; 


	-- 2) Try Catch / Throw
	-- _______________________________________________________________________
	DECLARE EXIT HANDLER FOR SQLEXCEPTION
	BEGIN
		RESIGNAL;
	END;



	-- 3) Prepare SYNC
	-- _______________________________________________________________________

	-- IS RECORD EXISTS		
	-- ####################################################	
	SET TEMP_RECORD_EXISTS = `ACCOUNT_BFIP@ACC_BFIP_ID_EXISTS`(PARAM_ACC_BFIP_ID, 0);

		
		
	-- 4) PREPARE AUTOGEN DATA (IF EXISTS)
	-- _______________________________________________________________________
	IF TEMP_SYNC_IS_SERVER_REQUEST = 0 THEN
		-- Just to keep at least one line within condition
		SET TEMP_SYNC_IS_SERVER_REQUEST = 0;
		
		-- Actual Functionalities here
		-- USE DEFAULT VALUE (String)
		-- USE DEFAULT VALUE (String)
		SET PARAM_ACC_BFIP_LAST_ACTIVITY = TEMP_NOW;
	-- USE CURRENT USER
	END IF;



	-- 5) IF ALREADY EXIST, FILL MISSING DATA
	-- _______________________________________________________________________
	IF TEMP_RECORD_EXISTS = 1 THEN
		SELECT
			`account_bfip`.`ACC_BFIP_IP`, 	
			`account_bfip`.`ACC_BFIP_DESCRIPTION`, 	
			`account_bfip`.`ACC_BFIP_LAST_ACTIVITY`, 	
			`account_bfip`.`ACC_BFIP_FAIL_COUNT`, 	
			`account_bfip`.`ACC_BFIP_LOCK_COUNT`, 	
			`account_bfip`.`ACC_BFIP_SUCCESS_COUNT`, 	
			`account_bfip`.`ACC_BFIP_STATUS`	
		INTO
			TEMP_ACC_BFIP_IP, 	
			TEMP_ACC_BFIP_DESCRIPTION, 	
			TEMP_ACC_BFIP_LAST_ACTIVITY, 	
			TEMP_ACC_BFIP_FAIL_COUNT, 	
			TEMP_ACC_BFIP_LOCK_COUNT, 	
			TEMP_ACC_BFIP_SUCCESS_COUNT, 	
			TEMP_ACC_BFIP_STATUS	

		FROM `account_bfip`
		WHERE
			`account_bfip`.`ACC_BFIP_ID` = PARAM_ACC_BFIP_ID
		LIMIT 1;

		-- Replace NULLs with the existing data.
		SET PARAM_ACC_BFIP_DESCRIPTION = `SYSTEM_VAR@REPLACE_NULL@NVARCHAR`(PARAM_ACC_BFIP_DESCRIPTION, TEMP_ACC_BFIP_DESCRIPTION, 1);
		SET PARAM_ACC_BFIP_STATUS = `SYSTEM_VAR@REPLACE_NULL@TINYINT`(PARAM_ACC_BFIP_STATUS, TEMP_ACC_BFIP_STATUS, 1, 1);
		
		-- AUTO GEN (NON-UPDATABLES)		
		SET PARAM_ACC_BFIP_LAST_ACTIVITY = TEMP_ACC_BFIP_LAST_ACTIVITY;
		
		-- AUTO GEN (UPDATABLE WITH STATUS CHANGE)

		-- AUTO GEN (UPDATABLE WITH STATUS [ACTIVE/INACTIVE] CHANGE)
		
		-- NON-UPDATABLE
		SET PARAM_ACC_BFIP_IP = TEMP_ACC_BFIP_IP;
		SET PARAM_ACC_BFIP_LAST_ACTIVITY = TEMP_ACC_BFIP_LAST_ACTIVITY;
		SET PARAM_ACC_BFIP_FAIL_COUNT = TEMP_ACC_BFIP_FAIL_COUNT;
		SET PARAM_ACC_BFIP_LOCK_COUNT = TEMP_ACC_BFIP_LOCK_COUNT;
		SET PARAM_ACC_BFIP_SUCCESS_COUNT = TEMP_ACC_BFIP_SUCCESS_COUNT;
		
		-- NON-UPDATABLE BUT NULL
		
	ELSE
		SET PARAM_ACC_BFIP_IP = `SYSTEM_VAR@REPLACE_NULL@NVARCHAR`(PARAM_ACC_BFIP_IP, '', 1);
		SET PARAM_ACC_BFIP_DESCRIPTION = `SYSTEM_VAR@REPLACE_NULL@NVARCHAR`(PARAM_ACC_BFIP_DESCRIPTION, '', 1);
		SET PARAM_ACC_BFIP_FAIL_COUNT = `SYSTEM_VAR@REPLACE_NULL@BIGINT`(PARAM_ACC_BFIP_FAIL_COUNT, 0, 1, 1);
		SET PARAM_ACC_BFIP_LOCK_COUNT = `SYSTEM_VAR@REPLACE_NULL@BIGINT`(PARAM_ACC_BFIP_LOCK_COUNT, 0, 1, 1);
		SET PARAM_ACC_BFIP_SUCCESS_COUNT = `SYSTEM_VAR@REPLACE_NULL@BIGINT`(PARAM_ACC_BFIP_SUCCESS_COUNT, 0, 1, 1);
		SET PARAM_ACC_BFIP_STATUS = `SYSTEM_VAR@REPLACE_NULL@TINYINT`(PARAM_ACC_BFIP_STATUS, 0, 1, 1);
		
	END IF;

	

	-- 6) PREPARE AUDIT TRAIL
	-- _______________________________________________________________________
	IF BINARY TEMP_ACC_BFIP_IP <> PARAM_ACC_BFIP_IP THEN
		SET TEMP_RECORD_CHANGES = 
		`SYSTEM_VAR@CONCAT_ADD`(' | ', TEMP_RECORD_CHANGES, CONCAT_WS(' ', 'IP Address: "', TEMP_ACC_BFIP_IP, '" > "', PARAM_ACC_BFIP_IP, '"'));
	END IF;
	IF BINARY TEMP_ACC_BFIP_DESCRIPTION <> PARAM_ACC_BFIP_DESCRIPTION THEN
		SET TEMP_RECORD_CHANGES = 
		`SYSTEM_VAR@CONCAT_ADD`(' | ', TEMP_RECORD_CHANGES, CONCAT_WS(' ', 'Description: "', TEMP_ACC_BFIP_DESCRIPTION, '" > "', PARAM_ACC_BFIP_DESCRIPTION, '"'));
	END IF;
	IF BINARY TEMP_ACC_BFIP_LAST_ACTIVITY <> PARAM_ACC_BFIP_LAST_ACTIVITY THEN
		SET TEMP_RECORD_CHANGES = 
		`SYSTEM_VAR@CONCAT_ADD`(' | ', TEMP_RECORD_CHANGES, CONCAT_WS(' ', 'Last Activity: "', TEMP_ACC_BFIP_LAST_ACTIVITY, '" > "', PARAM_ACC_BFIP_LAST_ACTIVITY, '"'));
	END IF;
	IF TEMP_ACC_BFIP_FAIL_COUNT <> PARAM_ACC_BFIP_FAIL_COUNT THEN
		SET TEMP_RECORD_CHANGES = 
		`SYSTEM_VAR@CONCAT_ADD`(' | ', TEMP_RECORD_CHANGES, CONCAT_WS(' ', 'Fail Count: "', TEMP_ACC_BFIP_FAIL_COUNT, '" > "', PARAM_ACC_BFIP_FAIL_COUNT, '"'));
	END IF;	
	IF TEMP_ACC_BFIP_LOCK_COUNT <> PARAM_ACC_BFIP_LOCK_COUNT THEN
		SET TEMP_RECORD_CHANGES = 
		`SYSTEM_VAR@CONCAT_ADD`(' | ', TEMP_RECORD_CHANGES, CONCAT_WS(' ', 'Lockout Count: "', TEMP_ACC_BFIP_LOCK_COUNT, '" > "', PARAM_ACC_BFIP_LOCK_COUNT, '"'));
	END IF;	
	IF TEMP_ACC_BFIP_SUCCESS_COUNT <> PARAM_ACC_BFIP_SUCCESS_COUNT THEN
		SET TEMP_RECORD_CHANGES = 
		`SYSTEM_VAR@CONCAT_ADD`(' | ', TEMP_RECORD_CHANGES, CONCAT_WS(' ', 'Success Count: "', TEMP_ACC_BFIP_SUCCESS_COUNT, '" > "', PARAM_ACC_BFIP_SUCCESS_COUNT, '"'));
	END IF;	
	IF TEMP_ACC_BFIP_STATUS <> PARAM_ACC_BFIP_STATUS THEN
		SET TEMP_RECORD_CHANGES = 
		`SYSTEM_VAR@CONCAT_ADD`(' | ', TEMP_RECORD_CHANGES, CONCAT_WS(' ', 'Status: "', TEMP_ACC_BFIP_STATUS, '" > "', PARAM_ACC_BFIP_STATUS, '"'));
	END IF;	
		
	-- No Changes in data, reject request
	-- ####################################################
	IF CHARACTER_LENGTH(TEMP_RECORD_CHANGES) = 0 THEN
		IF PARAM_SUPPRESS_RETURN = 0 THEN
			SELECT PARAM_ACC_BFIP_ID AS INSERTED_ID;
		END IF;
		LEAVE SP_SAVE;
	END IF;



	-- 7) VALIDATE
	-- _______________________________________________________________________

	-- Access Rights [Device]
	-- ####################################################
	IF `ACCOUNT_DEVICE@HAS_PERMISSION`(PARAM_REQUESTER_DEVICE_PUBLIC_KEY, PARAM_REQUESTER_DEVICE_PRIVATE_KEY) = 0 THEN
		SET TEMP_ERR_MESSAGE = 'Your device is not authorized yet to access this server.';
		SET ERR = `RAISERROR`(TEMP_ERR_MESSAGE);		
	END IF;
		
		
	-- Access Rights [Account]
	-- ####################################################
	
	IF 
		-- [ADD] Access Rights
		(
			TEMP_RECORD_EXISTS = 0 AND
			`ACCOUNT_ACCESS_RIGHTS@HAS_PERMISSION`(PARAM_REQUESTER_USERNAME, PARAM_REQUESTER_PASSWORD, 0, TEMP_MODULE_KEYWORD, 2) = 0 AND
			`ACCOUNT_ACCESS_RIGHTS@PROXY_PERMISSION`(PARAM_REQUESTER_PROXY_ID, PARAM_REQUESTER_PROXY_PASSWORD, 0, TEMP_MODULE_KEYWORD, 2) = 0
		) OR
		
		-- [EDIT] Access Rights
		(
			TEMP_RECORD_EXISTS = 1 AND
			`ACCOUNT_ACCESS_RIGHTS@HAS_PERMISSION`(PARAM_REQUESTER_USERNAME, PARAM_REQUESTER_PASSWORD, 0, TEMP_MODULE_KEYWORD, 3) = 0 AND
			`ACCOUNT_ACCESS_RIGHTS@PROXY_PERMISSION`(PARAM_REQUESTER_PROXY_ID, PARAM_REQUESTER_PROXY_PASSWORD, 0, TEMP_MODULE_KEYWORD, 3) = 0
		)
	THEN
		SET TEMP_ACCESS_RIGHTS_DENIED = 1;
		CALL `ACCOUNT_ACCESS_RIGHTS_DENY`
		(
			0, TEMP_MODULE_KEYWORD, PARAM_ACC_BFIP_ID, 0, TEMP_SP_OBJECTIVE, TEMP_RECORD_CHANGES, 
			PARAM_REQUESTER_USERNAME, PARAM_REQUESTER_PASSWORD, 
			PARAM_REQUESTER_PROXY_ID, PARAM_REQUESTER_PROXY_PASSWORD,
			PARAM_REQUESTER_DEVICE_PUBLIC_KEY, PARAM_REQUESTER_DEVICE_PRIVATE_KEY,
			PARAM_REQUESTER_IP, PARAM_UNIQUE_SESSION_ID,
			TEMP_SYNC_SERVER_ID, PARAM_SUPPRESS_RETURN
		);
	END IF;
	SET TEMP_ACCESS_RIGHTS_HAS_OVERRIDE = `ACCOUNT_ACCESS_RIGHTS@HAS_PERMISSION`(PARAM_REQUESTER_USERNAME, PARAM_REQUESTER_PASSWORD, 0, TEMP_MODULE_KEYWORD, 4);
	

	-- Validation
	-- ####################################################
	IF TEMP_SYNC_IS_SERVER_REQUEST = 0 THEN
	

		-- FOREIGN KEY EXISTS
		-- ...........................................
		
		-- FOREIGN (OPTIONAL)KEY EXISTS [Validates if not null]
		-- ...........................................
		
		-- IS_ALLOW_NULL = FALSE
		-- ...........................................
				
		-- IS_ALLOW_ZERO = FALSE
		-- ...........................................
		IF PARAM_ACC_BFIP_STATUS = 0 THEN
			CALL `VALIDATION_MISSING_FIELD`('`ACC_BFIP_STATUS`', '`NULL`');
		END IF;		
		
		-- IS_ALLOW_NEGATIVE = FALSE
		-- ...........................................
		IF PARAM_ACC_BFIP_FAIL_COUNT < 0 THEN
			CALL `VALIDATION_NEGATIVE`('`ACC_BFIP_FAIL_COUNT`', PARAM_ACC_BFIP_FAIL_COUNT);
		END IF;		
		IF PARAM_ACC_BFIP_LOCK_COUNT < 0 THEN
			CALL `VALIDATION_NEGATIVE`('`ACC_BFIP_LOCK_COUNT`', PARAM_ACC_BFIP_LOCK_COUNT);
		END IF;		
		IF PARAM_ACC_BFIP_SUCCESS_COUNT < 0 THEN
			CALL `VALIDATION_NEGATIVE`('`ACC_BFIP_SUCCESS_COUNT`', PARAM_ACC_BFIP_SUCCESS_COUNT);
		END IF;		
		IF PARAM_ACC_BFIP_STATUS < 0 THEN
			CALL `VALIDATION_NEGATIVE`('`ACC_BFIP_STATUS`', PARAM_ACC_BFIP_STATUS);
		END IF;		
		
		-- IS_ALLOW_EMPTY_STRING = FALSE
		-- ...........................................
		IF `SYSTEM_VAR@IS_NULL@NVARCHAR`(PARAM_ACC_BFIP_IP, 1) = 1 THEN
			CALL `VALIDATION_MISSING_FIELD`('`ACC_BFIP_IP`', '`NULL`');
		END IF;
		IF `SYSTEM_VAR@IS_NULL@NVARCHAR`(PARAM_ACC_BFIP_DESCRIPTION, 1) = 1 THEN
			CALL `VALIDATION_MISSING_FIELD`('`ACC_BFIP_DESCRIPTION`', '`NULL`');
		END IF;
		IF `SYSTEM_VAR@IS_NULL@DATETIME`(PARAM_ACC_BFIP_LAST_ACTIVITY, 1) = 1 THEN
			CALL `VALIDATION_MISSING_FIELD`('`ACC_BFIP_LAST_ACTIVITY`', '`NULL`');
		END IF;
		
		-- IS_STATUS
		-- ...........................................
		IF `SYSTEM_STATUS@SYS_STATUS_ID_EXISTS`(PARAM_ACC_BFIP_STATUS, 0) = 0 THEN
			SET TEMP_ERR_MESSAGE = CONCAT_WS(' ', 'Given STATUS[Status] does not exists or is inactive. ID: ', PARAM_ACC_BFIP_STATUS);
			SET ERR = `RAISERROR`(TEMP_ERR_MESSAGE);
		END IF;
		
		-- IS STATUS Active / Inactive
		-- ...........................................
		
		-- Minimum / Maximum Value
		-- ...........................................
		
		-- IS_UNIQUE = TRUE
		-- ...........................................
		IF
		(
			SELECT COUNT(`account_bfip`.`ACC_BFIP_ID`)
			FROM `account_bfip`
			WHERE		
				`account_bfip`.`ACC_BFIP_IP` = PARAM_ACC_BFIP_IP AND		
				`account_bfip`.`ACC_BFIP_ID` <> PARAM_ACC_BFIP_ID
		) >= 1
		THEN
			SELECT `account_bfip`.`ACC_BFIP_ID`
			INTO REDUND_ACC_BFIP_ID
			FROM `account_bfip`
			WHERE		
				`account_bfip`.`ACC_BFIP_IP` = PARAM_ACC_BFIP_IP AND		
				`account_bfip`.`ACC_BFIP_ID` <> PARAM_ACC_BFIP_ID		
			LIMIT 1; 
			SET TEMP_ERR_MESSAGE = CONCAT_WS(' ', PARAM_ACC_BFIP_IP, '[', REDUND_ACC_BFIP_ID, ']');
			CALL `VALIDATION_REDUNDANT_ENTRY`(TEMP_ERR_MESSAGE);
		END IF;
		
		-- RECORD IDENTIFIER
		-- ...........................................
		
		
		-- ON_UPDATE VALIDATION 
		-- ...........................................
		IF TEMP_RECORD_EXISTS = 1 THEN	
		
			-- Just to keep at least one line within condition
			SET TEMP_RECORD_EXISTS = 1;
			
		END IF;
		
	END IF;



	-- 8) INSERT / UPDATE
	-- _______________________________________________________________________

	-- INSERT NEW DATA
	-- ####################################################
	IF TEMP_RECORD_EXISTS = 0 THEN

		INSERT INTO
		`account_bfip`
		(
			`account_bfip`.`ACC_BFIP_IP`, 
			`account_bfip`.`ACC_BFIP_DESCRIPTION`, 
			`account_bfip`.`ACC_BFIP_LAST_ACTIVITY`, 
			`account_bfip`.`ACC_BFIP_FAIL_COUNT`, 
			`account_bfip`.`ACC_BFIP_LOCK_COUNT`, 
			`account_bfip`.`ACC_BFIP_SUCCESS_COUNT`, 
			`account_bfip`.`ACC_BFIP_STATUS`
		)
		VALUES
		(
			PARAM_ACC_BFIP_IP, 
			PARAM_ACC_BFIP_DESCRIPTION, 
			PARAM_ACC_BFIP_LAST_ACTIVITY, 
			PARAM_ACC_BFIP_FAIL_COUNT, 
			PARAM_ACC_BFIP_LOCK_COUNT, 
			PARAM_ACC_BFIP_SUCCESS_COUNT, 
			PARAM_ACC_BFIP_STATUS
		);	
		
		-- Update Audit trail with new ID	
		SET PARAM_ACC_BFIP_ID = LAST_INSERT_ID();



	-- UPDATING EXISTING RECORD
	-- ####################################################
	ELSE
		UPDATE `account_bfip`
		SET
			`account_bfip`.`ACC_BFIP_IP` = PARAM_ACC_BFIP_IP, 
			`account_bfip`.`ACC_BFIP_DESCRIPTION` = PARAM_ACC_BFIP_DESCRIPTION, 
			`account_bfip`.`ACC_BFIP_LAST_ACTIVITY` = PARAM_ACC_BFIP_LAST_ACTIVITY, 
			`account_bfip`.`ACC_BFIP_FAIL_COUNT` = PARAM_ACC_BFIP_FAIL_COUNT, 
			`account_bfip`.`ACC_BFIP_LOCK_COUNT` = PARAM_ACC_BFIP_LOCK_COUNT, 
			`account_bfip`.`ACC_BFIP_SUCCESS_COUNT` = PARAM_ACC_BFIP_SUCCESS_COUNT, 
			`account_bfip`.`ACC_BFIP_STATUS` = PARAM_ACC_BFIP_STATUS
		WHERE
			`account_bfip`.`ACC_BFIP_ID` = PARAM_ACC_BFIP_ID;

	END IF;

	
	-- 9) AUDIT TRAIL
	-- _______________________________________________________________________
	CALL `ACCOUNT_AUDIT_TRAIL_SAVE`
	(
		0, TEMP_MODULE_KEYWORD, PARAM_ACC_BFIP_ID, 0, 'SAVE', TEMP_SP_OBJECTIVE, TEMP_RECORD_CHANGES, 
		PARAM_REQUESTER_USERNAME, PARAM_REQUESTER_PASSWORD, 
		PARAM_REQUESTER_PROXY_ID, PARAM_REQUESTER_PROXY_PASSWORD,
		PARAM_REQUESTER_DEVICE_PUBLIC_KEY, PARAM_REQUESTER_DEVICE_PRIVATE_KEY,
		PARAM_REQUESTER_IP, PARAM_UNIQUE_SESSION_ID,
		TEMP_SYNC_SERVER_ID, PARAM_SUPPRESS_RETURN
	);
	

	-- 10) RETURN RESULT
	-- _______________________________________________________________________
	IF PARAM_SUPPRESS_RETURN = 0 THEN
		SELECT 
			PARAM_ACC_BFIP_ID AS INSERTED_ID,
			TEMP_NOW AS SERVER_TIME;
	END IF;
	LEAVE SP_SAVE;


END ;;
DELIMITER ;
/*!50003 SET sql_mode              = @saved_sql_mode */ ;
/*!50003 SET character_set_client  = @saved_cs_client */ ;
/*!50003 SET character_set_results = @saved_cs_results */ ;
/*!50003 SET collation_connection  = @saved_col_connection */ ;
/*!50003 DROP PROCEDURE IF EXISTS `ACCOUNT_BFLOGIN_GET` */;
/*!50003 SET @saved_cs_client      = @@character_set_client */ ;
/*!50003 SET @saved_cs_results     = @@character_set_results */ ;
/*!50003 SET @saved_col_connection = @@collation_connection */ ;
/*!50003 SET character_set_client  = latin1 */ ;
/*!50003 SET character_set_results = latin1 */ ;
/*!50003 SET collation_connection  = latin1_swedish_ci */ ;
/*!50003 SET @saved_sql_mode       = @@sql_mode */ ;
/*!50003 SET sql_mode              = '' */ ;
DELIMITER ;;
CREATE DEFINER=`root`@`localhost` PROCEDURE `ACCOUNT_BFLOGIN_GET`(
	IN `PARAM_ACC_BFLOGIN_ID` BIGINT,	
	IN `PARAM_ACC_BFLOGIN_USERNAME` VARCHAR(400),	
	IN `PARAM_ACC_BFLOGIN_PASSWORD` VARCHAR(400),	
	IN `PARAM_ACC_BFLOGIN_DATE_FROM` DATETIME(6),
	IN `PARAM_ACC_BFLOGIN_DATE_TO` DATETIME(6),
	IN `PARAM_ACC_BFLOGIN_IP` VARCHAR(500),	
	IN `PARAM_ACC_BFLOGIN_STATUS` TINYINT,	
		
	IN `PARAM_ORDER_FIELD` VARCHAR(500),
	IN `PARAM_ORDER_TYPE` VARCHAR(500),
	IN `PARAM_SKIP` BIGINT,
	IN `PARAM_LIMIT` BIGINT,

	IN `PARAM_REQUESTER_USERNAME` VARCHAR(500),
	IN `PARAM_REQUESTER_PASSWORD` VARCHAR(500),
	IN `PARAM_REQUESTER_PROXY_ID` BIGINT,
	IN `PARAM_REQUESTER_PROXY_PASSWORD` VARCHAR(1000),
	IN `PARAM_REQUESTER_DEVICE_PUBLIC_KEY` VARCHAR(1000),
	IN `PARAM_REQUESTER_DEVICE_PRIVATE_KEY` VARCHAR(1000),
	
	IN `PARAM_REQUESTER_IP` VARCHAR(1000),
	IN `PARAM_UNIQUE_SESSION_ID` VARCHAR(1000),
	IN `PARAM_SUPPRESS_RETURN` BIT
)
SP_GET:
BEGIN

	-- Status
	-- =========================================================================================
	DECLARE STATUS_INACTIVE TINYINT DEFAULT 1;
	DECLARE STATUS_ACTIVE TINYINT DEFAULT 2;
	DECLARE STATUS_CLOSED TINYINT DEFAULT 3;
	DECLARE STATUS_COMPLETED TINYINT DEFAULT 4;
	
	-- Audit Handler
	-- =========================================================================================
	DECLARE TEMP_RECORD_EXISTS BIT DEFAULT 0;
	DECLARE TEMP_MODULE_KEYWORD VARCHAR(500) DEFAULT 'account_bflogin';
	DECLARE TEMP_SP_OBJECTIVE VARCHAR(500) DEFAULT 'Retrieve Brute Force Login Attempt record';
	DECLARE TEMP_ERR_MESSAGE VARCHAR(500) DEFAULT '';
	DECLARE ERR BIGINT DEFAULT 0;
	DECLARE TEMP_RECORD_CHANGES VARCHAR(16000) DEFAULT '';
	DECLARE TEMP_RECORD_BINDED BIT DEFAULT 0;
	
	DECLARE TEMP_RECORD_BINDED_ID BIGINT DEFAULT 0;
	DECLARE TEMP_RECORD_BINDED_SERVER_ID BIGINT DEFAULT 0;
	
	-- Authentication
	-- =========================================================================================
	DECLARE TEMP_ACCESS_RIGHTS_DENIED BIT DEFAULT 0;
	DECLARE TEMP_AUTHENTICATED_ACCOUNT_ID BIGINT DEFAULT `ACCOUNT_MEMBER@ACC_ACCOUNT_ID_FROM_LOGIN`(PARAM_REQUESTER_USERNAME, PARAM_REQUESTER_PASSWORD);
	DECLARE TEMP_AUTHENTICATED_ACCOUNT_LEVEL BIGINT DEFAULT 0;
	DECLARE TEMP_AUTHENTICATED_ACCOUNT_GROUP BIGINT DEFAULT 0;
	
	-- Local Parameters
	-- =========================================================================================
	DECLARE TEMP_NOW DATETIME(6) DEFAULT `SYSTEM_VAR@NOW`('', 1);
	DECLARE TEMP_RECORD_COUNT BIGINT DEFAULT 0;
	
	
	-- Check NULLs
	-- =========================================================================================
	DECLARE IS_NULL_ACC_BFLOGIN_ID BIT DEFAULT `SYSTEM_VAR@IS_NULL@BIGINT`(PARAM_ACC_BFLOGIN_ID, 1, 1);
	DECLARE IS_NULL_ACC_BFLOGIN_USERNAME BIT DEFAULT `SYSTEM_VAR@IS_NULL@NVARCHAR`(PARAM_ACC_BFLOGIN_USERNAME, 1);
	DECLARE IS_NULL_ACC_BFLOGIN_PASSWORD BIT DEFAULT `SYSTEM_VAR@IS_NULL@NVARCHAR`(PARAM_ACC_BFLOGIN_PASSWORD, 1);
	DECLARE IS_NULL_ACC_BFLOGIN_DATE_FROM BIT DEFAULT `SYSTEM_VAR@IS_NULL@DATETIME`(PARAM_ACC_BFLOGIN_DATE_FROM, 1);
	DECLARE IS_NULL_ACC_BFLOGIN_DATE_TO BIT DEFAULT `SYSTEM_VAR@IS_NULL@DATETIME`(PARAM_ACC_BFLOGIN_DATE_TO, 1);				
	DECLARE IS_NULL_ACC_BFLOGIN_IP BIT DEFAULT `SYSTEM_VAR@IS_NULL@NVARCHAR`(PARAM_ACC_BFLOGIN_IP, 1);
	DECLARE IS_NULL_ACC_BFLOGIN_STATUS BIT DEFAULT `SYSTEM_VAR@IS_NULL@TINYINT`(PARAM_ACC_BFLOGIN_STATUS, 1, 1);
	
	-- Error Handler
	-- =========================================================================================
	DECLARE EXIT HANDLER FOR SQLEXCEPTION
	BEGIN
		RESIGNAL;
	END;
	
	-- Ignore Time from DateTime (Set Time 00:00:00.000000 and 23:59:59.999999)
	-- =========================================================================================
		
		
	-- Access Rights [Device]
	-- =========================================================================================
	IF `ACCOUNT_DEVICE@HAS_PERMISSION`(PARAM_REQUESTER_DEVICE_PUBLIC_KEY, PARAM_REQUESTER_DEVICE_PRIVATE_KEY) = 0 THEN
		SET TEMP_ERR_MESSAGE = 'Your device is not authorized yet to access this server.';
		SET ERR = `RAISERROR`(TEMP_ERR_MESSAGE);		
	END IF;
		
		
	-- Access Rights [Account]
	-- =========================================================================================
		
	IF 
		`ACCOUNT_ACCESS_RIGHTS@HAS_PERMISSION`(PARAM_REQUESTER_USERNAME, PARAM_REQUESTER_PASSWORD, 0, TEMP_MODULE_KEYWORD, 1) = 0 AND
		`ACCOUNT_ACCESS_RIGHTS@PROXY_PERMISSION`(PARAM_REQUESTER_PROXY_ID, PARAM_REQUESTER_PROXY_PASSWORD, 0, TEMP_MODULE_KEYWORD, 1) = 0
	THEN
		SET TEMP_ACCESS_RIGHTS_DENIED = 1;
		CALL `ACCOUNT_ACCESS_RIGHTS_DENY`
		(
			0, TEMP_MODULE_KEYWORD, 0, 0, TEMP_SP_OBJECTIVE, TEMP_RECORD_CHANGES, 
			PARAM_REQUESTER_USERNAME, PARAM_REQUESTER_PASSWORD, 
			PARAM_REQUESTER_PROXY_ID, PARAM_REQUESTER_PROXY_PASSWORD,
			PARAM_REQUESTER_DEVICE_PUBLIC_KEY, PARAM_REQUESTER_DEVICE_PRIVATE_KEY,
			PARAM_REQUESTER_IP, PARAM_UNIQUE_SESSION_ID,
			0, PARAM_SUPPRESS_RETURN
		);
	END IF;
	
	
	
	-- COUNT RECORD
	-- =========================================================================================
	
	-- SELECT COLUMNS
	-- ####################################################
	SELECT
		COUNT(DISTINCT `account_bflogin`.`ACC_BFLOGIN_ID`)
	INTO
		TEMP_RECORD_COUNT

	FROM `account_bflogin`
				
		-- Add Inner Joins (Per Foreign-key)
		
	-- CONDITIONS
	-- ####################################################
	WHERE
		(
			IS_NULL_ACC_BFLOGIN_ID = 1 OR
			`account_bflogin`.`ACC_BFLOGIN_ID` = PARAM_ACC_BFLOGIN_ID			
		) AND
		(
			IS_NULL_ACC_BFLOGIN_USERNAME = 1 OR
			`account_bflogin`.`ACC_BFLOGIN_USERNAME` LIKE CONCAT_WS('%', '', PARAM_ACC_BFLOGIN_USERNAME, '')			
		) AND 		
		(
			IS_NULL_ACC_BFLOGIN_PASSWORD = 1 OR
			`account_bflogin`.`ACC_BFLOGIN_PASSWORD` LIKE CONCAT_WS('%', '', PARAM_ACC_BFLOGIN_PASSWORD, '')			
		) AND 		
		(
			IS_NULL_ACC_BFLOGIN_DATE_FROM = 1 OR
			`account_bflogin`.`ACC_BFLOGIN_DATE` >= PARAM_ACC_BFLOGIN_DATE_FROM			
		) AND
		(
			IS_NULL_ACC_BFLOGIN_DATE_TO = 1 OR
			`account_bflogin`.`ACC_BFLOGIN_DATE` <= PARAM_ACC_BFLOGIN_DATE_TO			
		) AND 		
		(
			IS_NULL_ACC_BFLOGIN_IP = 1 OR
			`account_bflogin`.`ACC_BFLOGIN_IP` LIKE CONCAT_WS('%', '', PARAM_ACC_BFLOGIN_IP, '')			
		) AND 		
		(
			IS_NULL_ACC_BFLOGIN_STATUS = 1 OR
			`account_bflogin`.`ACC_BFLOGIN_STATUS` = PARAM_ACC_BFLOGIN_STATUS			
		) 
;	

		
		
	-- SELECT RECORDS
	-- =========================================================================================
	
	-- FETCH COLUMNS
	-- ####################################################
	SELECT
		-- ACCOUNT_BFLOGIN DETAILS
		`account_bflogin`.`ACC_BFLOGIN_ID`, 
		`account_bflogin`.`ACC_BFLOGIN_USERNAME`, 
		`account_bflogin`.`ACC_BFLOGIN_PASSWORD`, 
		`account_bflogin`.`ACC_BFLOGIN_DATE`, 
		`account_bflogin`.`ACC_BFLOGIN_IP`, 
		`account_bflogin`.`ACC_BFLOGIN_STATUS`,
		IF(`account_bflogin`.`ACC_BFLOGIN_STATUS` = STATUS_INACTIVE, 'Failed', 'Success') AS SYS_STATUS_DESCRIPTION
		
		-- Sum of Child [Numerics, non-primary/foreign keys, nor status, active/inactive, and system generated.]
		
		
		-- Inner join fields
		
		-- Left join fields
		
		, TEMP_NOW AS SERVER_TIME,
		TEMP_RECORD_COUNT AS RECORD_COUNT

	FROM `account_bflogin`
	
		-- Add Inner Joins (Per Foreign-key)
		
		-- Add Optional Left Joins (Per Optional Foreign-key)
		
	-- CONDITIONS
	-- ####################################################
	WHERE
		(
			IS_NULL_ACC_BFLOGIN_ID = 1 OR
			`account_bflogin`.`ACC_BFLOGIN_ID` = PARAM_ACC_BFLOGIN_ID			
		) AND
		(
			IS_NULL_ACC_BFLOGIN_USERNAME = 1 OR
			`account_bflogin`.`ACC_BFLOGIN_USERNAME` LIKE CONCAT_WS('%', '', PARAM_ACC_BFLOGIN_USERNAME, '')			
		) AND 		
		(
			IS_NULL_ACC_BFLOGIN_PASSWORD = 1 OR
			`account_bflogin`.`ACC_BFLOGIN_PASSWORD` LIKE CONCAT_WS('%', '', PARAM_ACC_BFLOGIN_PASSWORD, '')			
		) AND 		
		(
			IS_NULL_ACC_BFLOGIN_DATE_FROM = 1 OR
			`account_bflogin`.`ACC_BFLOGIN_DATE` >= PARAM_ACC_BFLOGIN_DATE_FROM			
		) AND
		(
			IS_NULL_ACC_BFLOGIN_DATE_TO = 1 OR
			`account_bflogin`.`ACC_BFLOGIN_DATE` <= PARAM_ACC_BFLOGIN_DATE_TO			
		) AND 
		(
			IS_NULL_ACC_BFLOGIN_IP = 1 OR
			`account_bflogin`.`ACC_BFLOGIN_IP` LIKE CONCAT_WS('%', '', PARAM_ACC_BFLOGIN_IP, '')			
		) AND 		
		(
			IS_NULL_ACC_BFLOGIN_STATUS = 1 OR
			`account_bflogin`.`ACC_BFLOGIN_STATUS` = PARAM_ACC_BFLOGIN_STATUS			
		) 

	-- ORDER BY
	-- ####################################################
	ORDER BY
		-- ACCOUNT_BFLOGIN DETAILS
		CASE WHEN PARAM_ORDER_FIELD = 'ACC_BFLOGIN_ID' AND PARAM_ORDER_TYPE = 'ASC' THEN `account_bflogin`.`ACC_BFLOGIN_ID` END ASC, 
		CASE WHEN PARAM_ORDER_FIELD = 'ACC_BFLOGIN_ID' AND PARAM_ORDER_TYPE = 'DESC' THEN `account_bflogin`.`ACC_BFLOGIN_ID` END DESC,	
		CASE WHEN PARAM_ORDER_FIELD = 'ACC_BFLOGIN_USERNAME' AND PARAM_ORDER_TYPE = 'ASC' THEN `account_bflogin`.`ACC_BFLOGIN_USERNAME` END ASC, 
		CASE WHEN PARAM_ORDER_FIELD = 'ACC_BFLOGIN_USERNAME' AND PARAM_ORDER_TYPE = 'DESC' THEN `account_bflogin`.`ACC_BFLOGIN_USERNAME` END DESC,	
		CASE WHEN PARAM_ORDER_FIELD = 'ACC_BFLOGIN_PASSWORD' AND PARAM_ORDER_TYPE = 'ASC' THEN `account_bflogin`.`ACC_BFLOGIN_PASSWORD` END ASC, 
		CASE WHEN PARAM_ORDER_FIELD = 'ACC_BFLOGIN_PASSWORD' AND PARAM_ORDER_TYPE = 'DESC' THEN `account_bflogin`.`ACC_BFLOGIN_PASSWORD` END DESC,	
		CASE WHEN PARAM_ORDER_FIELD = 'ACC_BFLOGIN_DATE' AND PARAM_ORDER_TYPE = 'ASC' THEN `account_bflogin`.`ACC_BFLOGIN_DATE` END ASC, 
		CASE WHEN PARAM_ORDER_FIELD = 'ACC_BFLOGIN_DATE' AND PARAM_ORDER_TYPE = 'DESC' THEN `account_bflogin`.`ACC_BFLOGIN_DATE` END DESC,	
		CASE WHEN PARAM_ORDER_FIELD = 'ACC_BFLOGIN_IP' AND PARAM_ORDER_TYPE = 'ASC' THEN `account_bflogin`.`ACC_BFLOGIN_IP` END ASC, 
		CASE WHEN PARAM_ORDER_FIELD = 'ACC_BFLOGIN_IP' AND PARAM_ORDER_TYPE = 'DESC' THEN `account_bflogin`.`ACC_BFLOGIN_IP` END DESC,	
		CASE WHEN PARAM_ORDER_FIELD = 'ACC_BFLOGIN_STATUS' AND PARAM_ORDER_TYPE = 'ASC' THEN `account_bflogin`.`ACC_BFLOGIN_STATUS` END ASC, 
		CASE WHEN PARAM_ORDER_FIELD = 'ACC_BFLOGIN_STATUS' AND PARAM_ORDER_TYPE = 'DESC' THEN `account_bflogin`.`ACC_BFLOGIN_STATUS` END DESC,	

		-- Inner joins
		
		-- EXTRA
		CASE WHEN PARAM_ORDER_FIELD <> 'ACC_BFLOGIN_DATE' THEN `account_bflogin`.`ACC_BFLOGIN_DATE` END DESC
		
	-- LIMIT & OFFSET
	-- ####################################################		
	LIMIT PARAM_SKIP, PARAM_LIMIT;
	
	
	
	-- EXIT PROCEDURE
	-- =========================================================================================
	LEAVE SP_GET;
			
END ;;
DELIMITER ;
/*!50003 SET sql_mode              = @saved_sql_mode */ ;
/*!50003 SET character_set_client  = @saved_cs_client */ ;
/*!50003 SET character_set_results = @saved_cs_results */ ;
/*!50003 SET collation_connection  = @saved_col_connection */ ;
/*!50003 DROP PROCEDURE IF EXISTS `ACCOUNT_DEVICE_GET` */;
/*!50003 SET @saved_cs_client      = @@character_set_client */ ;
/*!50003 SET @saved_cs_results     = @@character_set_results */ ;
/*!50003 SET @saved_col_connection = @@collation_connection */ ;
/*!50003 SET character_set_client  = latin1 */ ;
/*!50003 SET character_set_results = latin1 */ ;
/*!50003 SET collation_connection  = latin1_swedish_ci */ ;
/*!50003 SET @saved_sql_mode       = @@sql_mode */ ;
/*!50003 SET sql_mode              = '' */ ;
DELIMITER ;;
CREATE DEFINER=`root`@`localhost` PROCEDURE `ACCOUNT_DEVICE_GET`(
	IN `PARAM_ACC_DEVICE_ID` BIGINT,	
	IN `PARAM_ACC_DEVICE_DESCRIPTION` VARCHAR(500),	
	IN `PARAM_ACC_DEVICE_PUBLIC_KEY` VARCHAR(4000),	
	IN `PARAM_ACC_DEVICE_STATUS` TINYINT,	
		
	IN `PARAM_ORDER_FIELD` VARCHAR(500),
	IN `PARAM_ORDER_TYPE` VARCHAR(500),
	IN `PARAM_SKIP` BIGINT,
	IN `PARAM_LIMIT` BIGINT,

	IN `PARAM_REQUESTER_USERNAME` VARCHAR(500),
	IN `PARAM_REQUESTER_PASSWORD` VARCHAR(500),
	IN `PARAM_REQUESTER_PROXY_ID` BIGINT,
	IN `PARAM_REQUESTER_PROXY_PASSWORD` VARCHAR(1000),
	IN `PARAM_REQUESTER_DEVICE_PUBLIC_KEY` VARCHAR(1000),
	IN `PARAM_REQUESTER_DEVICE_PRIVATE_KEY` VARCHAR(1000),
	
	IN `PARAM_REQUESTER_IP` VARCHAR(1000),
	IN `PARAM_UNIQUE_SESSION_ID` VARCHAR(1000),
	IN `PARAM_SUPPRESS_RETURN` BIT
)
SP_GET:
BEGIN

	-- Status
	-- =========================================================================================
	DECLARE STATUS_INACTIVE TINYINT DEFAULT 1;
	DECLARE STATUS_ACTIVE TINYINT DEFAULT 2;
	DECLARE STATUS_CLOSED TINYINT DEFAULT 3;
	DECLARE STATUS_COMPLETED TINYINT DEFAULT 4;
	
	-- Audit Handler
	-- =========================================================================================
	DECLARE TEMP_RECORD_EXISTS BIT DEFAULT 0;
	DECLARE TEMP_MODULE_KEYWORD VARCHAR(500) DEFAULT 'account_device';
	DECLARE TEMP_SP_OBJECTIVE VARCHAR(500) DEFAULT 'Retrieve Devices record';
	DECLARE TEMP_ERR_MESSAGE VARCHAR(500) DEFAULT '';
	DECLARE ERR BIGINT DEFAULT 0;
	DECLARE TEMP_RECORD_CHANGES VARCHAR(16000) DEFAULT '';
	DECLARE TEMP_RECORD_BINDED BIT DEFAULT 0;
	
	DECLARE TEMP_RECORD_BINDED_ID BIGINT DEFAULT 0;
	DECLARE TEMP_RECORD_BINDED_SERVER_ID BIGINT DEFAULT 0;
	
	-- Authentication
	-- =========================================================================================
	DECLARE TEMP_ACCESS_RIGHTS_DENIED BIT DEFAULT 0;
	DECLARE TEMP_AUTHENTICATED_ACCOUNT_ID BIGINT DEFAULT `ACCOUNT_MEMBER@ACC_ACCOUNT_ID_FROM_LOGIN`(PARAM_REQUESTER_USERNAME, PARAM_REQUESTER_PASSWORD);
	DECLARE TEMP_AUTHENTICATED_ACCOUNT_LEVEL BIGINT DEFAULT 0;
	DECLARE TEMP_AUTHENTICATED_ACCOUNT_GROUP BIGINT DEFAULT 0;
	
	-- Local Parameters
	-- =========================================================================================
	DECLARE TEMP_NOW DATETIME(6) DEFAULT `SYSTEM_VAR@NOW`('', 1);
	DECLARE TEMP_RECORD_COUNT BIGINT DEFAULT 0;
	
	
	-- Check NULLs
	-- =========================================================================================
	DECLARE IS_NULL_ACC_DEVICE_ID BIT DEFAULT `SYSTEM_VAR@IS_NULL@BIGINT`(PARAM_ACC_DEVICE_ID, 1, 1);
	DECLARE IS_NULL_ACC_DEVICE_DESCRIPTION BIT DEFAULT `SYSTEM_VAR@IS_NULL@NVARCHAR`(PARAM_ACC_DEVICE_DESCRIPTION, 1);
	DECLARE IS_NULL_ACC_DEVICE_PUBLIC_KEY BIT DEFAULT `SYSTEM_VAR@IS_NULL@NVARCHAR`(PARAM_ACC_DEVICE_PUBLIC_KEY, 1);
	DECLARE IS_NULL_ACC_DEVICE_STATUS BIT DEFAULT `SYSTEM_VAR@IS_NULL@TINYINT`(PARAM_ACC_DEVICE_STATUS, 1, 1);
	
	-- Error Handler
	-- =========================================================================================
	DECLARE EXIT HANDLER FOR SQLEXCEPTION
	BEGIN
		RESIGNAL;
	END;
	
	-- Ignore Time from DateTime (Set Time 00:00:00.000000 and 23:59:59.999999)
	-- =========================================================================================
		
		
	-- Access Rights [Device]
	-- =========================================================================================
	IF `ACCOUNT_DEVICE@HAS_PERMISSION`(PARAM_REQUESTER_DEVICE_PUBLIC_KEY, PARAM_REQUESTER_DEVICE_PRIVATE_KEY) = 0 THEN
		SET TEMP_ERR_MESSAGE = 'Your device is not authorized yet to access this server.';
		SET ERR = `RAISERROR`(TEMP_ERR_MESSAGE);		
	END IF;
		
		
	-- Access Rights [Account]
	-- =========================================================================================
		
	IF `ACCOUNT_ACCESS_RIGHTS@HAS_PERMISSION`(PARAM_REQUESTER_USERNAME, PARAM_REQUESTER_PASSWORD, 0, TEMP_MODULE_KEYWORD, 1) = 0 THEN
		SET TEMP_ACCESS_RIGHTS_DENIED = 1;
		CALL `ACCOUNT_ACCESS_RIGHTS_DENY`
		(
			0, TEMP_MODULE_KEYWORD, 0, 0, TEMP_SP_OBJECTIVE, TEMP_RECORD_CHANGES, 
			PARAM_REQUESTER_USERNAME, PARAM_REQUESTER_PASSWORD, 
			PARAM_REQUESTER_PROXY_ID, PARAM_REQUESTER_PROXY_PASSWORD,
			PARAM_REQUESTER_DEVICE_PUBLIC_KEY, PARAM_REQUESTER_DEVICE_PRIVATE_KEY,
			PARAM_REQUESTER_IP, PARAM_UNIQUE_SESSION_ID,
			0, PARAM_SUPPRESS_RETURN
		);
	END IF;
	
	
	
	-- COUNT RECORD
	-- =========================================================================================
	
	-- SELECT COLUMNS
	-- ####################################################
	SELECT
		COUNT(DISTINCT `account_device`.`ACC_DEVICE_ID`)
	INTO
		TEMP_RECORD_COUNT

	FROM `account_device`
	
		-- Add Inner Joins (Per Foreign-key)
		
		-- Add Optional Left Joins (Per Optional Foreign-key)
		
	-- CONDITIONS
	-- ####################################################
	WHERE
		(
			IS_NULL_ACC_DEVICE_ID = 1 OR
			`account_device`.`ACC_DEVICE_ID` = PARAM_ACC_DEVICE_ID			
		) AND
		(
			IS_NULL_ACC_DEVICE_DESCRIPTION = 1 OR
			`account_device`.`ACC_DEVICE_DESCRIPTION` LIKE CONCAT_WS('%', '', PARAM_ACC_DEVICE_DESCRIPTION, '')			
		) AND 		
		(
			IS_NULL_ACC_DEVICE_PUBLIC_KEY = 1 OR
			`account_device`.`ACC_DEVICE_PUBLIC_KEY` LIKE CONCAT_WS('%', '', PARAM_ACC_DEVICE_PUBLIC_KEY, '')			
		) AND 		
		(
			IS_NULL_ACC_DEVICE_STATUS = 1 OR
			`account_device`.`ACC_DEVICE_STATUS` = PARAM_ACC_DEVICE_STATUS			
		) 
;	

		
		
	-- SELECT RECORDS
	-- =========================================================================================
	
	-- FETCH COLUMNS
	-- ####################################################
	SELECT
		-- ACCOUNT_DEVICE DETAILS
		`account_device`.`ACC_DEVICE_ID`, 
		`account_device`.`ACC_DEVICE_DESCRIPTION`, 
		`account_device`.`ACC_DEVICE_PUBLIC_KEY`, 
		`account_device`.`ACC_DEVICE_PRIVATE_KEY`, 
		`account_device`.`ACC_DEVICE_PRIVATE_KEY_SALT`, 
		`account_device`.`ACC_DEVICE_STATUS`
		
		-- Inner join fields
		
		-- Left join fields
		
		, TEMP_RECORD_COUNT AS RECORD_COUNT

	FROM `account_device`
	
		-- Add Inner Joins (Per Foreign-key)
		
		-- Add Optional Left Joins (Per Optional Foreign-key)
		
	-- CONDITIONS
	-- ####################################################
	WHERE
		(
			IS_NULL_ACC_DEVICE_ID = 1 OR
			`account_device`.`ACC_DEVICE_ID` = PARAM_ACC_DEVICE_ID			
		) AND
		(
			IS_NULL_ACC_DEVICE_DESCRIPTION = 1 OR
			`account_device`.`ACC_DEVICE_DESCRIPTION` LIKE CONCAT_WS('%', '', PARAM_ACC_DEVICE_DESCRIPTION, '')			
		) AND 		
		(
			IS_NULL_ACC_DEVICE_PUBLIC_KEY = 1 OR
			`account_device`.`ACC_DEVICE_PUBLIC_KEY` LIKE CONCAT_WS('%', '', PARAM_ACC_DEVICE_PUBLIC_KEY, '')			
		) AND 		
		(
			IS_NULL_ACC_DEVICE_STATUS = 1 OR
			`account_device`.`ACC_DEVICE_STATUS` = PARAM_ACC_DEVICE_STATUS			
		) 

	-- ORDER BY
	-- ####################################################
	ORDER BY
		-- ACCOUNT_DEVICE DETAILS
		CASE WHEN PARAM_ORDER_FIELD = 'ACC_DEVICE_ID' AND PARAM_ORDER_TYPE = 'ASC' THEN `account_device`.`ACC_DEVICE_ID` END ASC, 
		CASE WHEN PARAM_ORDER_FIELD = 'ACC_DEVICE_ID' AND PARAM_ORDER_TYPE = 'DESC' THEN `account_device`.`ACC_DEVICE_ID` END DESC,	
		CASE WHEN PARAM_ORDER_FIELD = 'ACC_DEVICE_DESCRIPTION' AND PARAM_ORDER_TYPE = 'ASC' THEN `account_device`.`ACC_DEVICE_DESCRIPTION` END ASC, 
		CASE WHEN PARAM_ORDER_FIELD = 'ACC_DEVICE_DESCRIPTION' AND PARAM_ORDER_TYPE = 'DESC' THEN `account_device`.`ACC_DEVICE_DESCRIPTION` END DESC,	
		CASE WHEN PARAM_ORDER_FIELD = 'ACC_DEVICE_PUBLIC_KEY' AND PARAM_ORDER_TYPE = 'ASC' THEN `account_device`.`ACC_DEVICE_PUBLIC_KEY` END ASC, 
		CASE WHEN PARAM_ORDER_FIELD = 'ACC_DEVICE_PUBLIC_KEY' AND PARAM_ORDER_TYPE = 'DESC' THEN `account_device`.`ACC_DEVICE_PUBLIC_KEY` END DESC,	
		CASE WHEN PARAM_ORDER_FIELD = 'ACC_DEVICE_PRIVATE_KEY' AND PARAM_ORDER_TYPE = 'ASC' THEN `account_device`.`ACC_DEVICE_PRIVATE_KEY` END ASC, 
		CASE WHEN PARAM_ORDER_FIELD = 'ACC_DEVICE_PRIVATE_KEY' AND PARAM_ORDER_TYPE = 'DESC' THEN `account_device`.`ACC_DEVICE_PRIVATE_KEY` END DESC,	
		CASE WHEN PARAM_ORDER_FIELD = 'ACC_DEVICE_PRIVATE_KEY_SALT' AND PARAM_ORDER_TYPE = 'ASC' THEN `account_device`.`ACC_DEVICE_PRIVATE_KEY_SALT` END ASC, 
		CASE WHEN PARAM_ORDER_FIELD = 'ACC_DEVICE_PRIVATE_KEY_SALT' AND PARAM_ORDER_TYPE = 'DESC' THEN `account_device`.`ACC_DEVICE_PRIVATE_KEY_SALT` END DESC,	
		CASE WHEN PARAM_ORDER_FIELD = 'ACC_DEVICE_STATUS' AND PARAM_ORDER_TYPE = 'ASC' THEN `account_device`.`ACC_DEVICE_STATUS` END ASC, 
		CASE WHEN PARAM_ORDER_FIELD = 'ACC_DEVICE_STATUS' AND PARAM_ORDER_TYPE = 'DESC' THEN `account_device`.`ACC_DEVICE_STATUS` END DESC,	

		-- Inner joins
		
		-- EXTRA
		CASE WHEN PARAM_ORDER_FIELD <> 'ACC_DEVICE_DESCRIPTION' THEN `account_device`.`ACC_DEVICE_DESCRIPTION` END ASC
		
	-- LIMIT & OFFSET
	-- ####################################################		
	LIMIT PARAM_SKIP, PARAM_LIMIT;
	
	
	
	-- EXIT PROCEDURE
	-- =========================================================================================
	LEAVE SP_GET;
			
END ;;
DELIMITER ;
/*!50003 SET sql_mode              = @saved_sql_mode */ ;
/*!50003 SET character_set_client  = @saved_cs_client */ ;
/*!50003 SET character_set_results = @saved_cs_results */ ;
/*!50003 SET collation_connection  = @saved_col_connection */ ;
/*!50003 DROP PROCEDURE IF EXISTS `ACCOUNT_DEVICE_LOGIN` */;
/*!50003 SET @saved_cs_client      = @@character_set_client */ ;
/*!50003 SET @saved_cs_results     = @@character_set_results */ ;
/*!50003 SET @saved_col_connection = @@collation_connection */ ;
/*!50003 SET character_set_client  = latin1 */ ;
/*!50003 SET character_set_results = latin1 */ ;
/*!50003 SET collation_connection  = latin1_swedish_ci */ ;
/*!50003 SET @saved_sql_mode       = @@sql_mode */ ;
/*!50003 SET sql_mode              = '' */ ;
DELIMITER ;;
CREATE DEFINER=`root`@`localhost` PROCEDURE `ACCOUNT_DEVICE_LOGIN`(
	IN `PARAM_ACC_DEVICE_DESCRIPTION` VARCHAR(500),
	IN `PARAM_ACC_DEVICE_PUBLIC_KEY` VARCHAR(1000),
	IN `PARAM_ACC_DEVICE_PRIVATE_KEY` VARCHAR(1000),

	IN `PARAM_REQUESTER_USERNAME` VARCHAR(500),
	IN `PARAM_REQUESTER_PASSWORD` VARCHAR(500),
	IN `PARAM_REQUESTER_PROXY_ID` BIGINT,
	IN `PARAM_REQUESTER_PROXY_PASSWORD` VARCHAR(1000),
	IN `PARAM_REQUESTER_DEVICE_PUBLIC_KEY` VARCHAR(1000),
	IN `PARAM_REQUESTER_DEVICE_PRIVATE_KEY` VARCHAR(1000),
	
	IN `PARAM_REQUESTER_IP` VARCHAR(1000),
	IN `PARAM_UNIQUE_SESSION_ID` VARCHAR(1000),
	IN `PARAM_SUPPRESS_RETURN` BIT
)
SP_GET:
BEGIN

	-- 1) DECLARE LOCAL PARAMETERS
	-- _______________________________________________________________________
	
	-- Status
	-- ...........................................
	DECLARE STATUS_INACTIVE TINYINT DEFAULT 1;
	DECLARE STATUS_ACTIVE TINYINT DEFAULT 2;
	DECLARE STATUS_CLOSED TINYINT DEFAULT 3;
	DECLARE STATUS_COMPLETED TINYINT DEFAULT 4;

	-- Audit Handler
	-- ...........................................
	DECLARE TEMP_RECORD_EXISTS BIT DEFAULT 0;
	DECLARE TEMP_MODULE_KEYWORD NVARCHAR(500) DEFAULT 'account_device';
	DECLARE TEMP_SP_OBJECTIVE NVARCHAR(500) DEFAULT 'add/edit account_device record';
	DECLARE TEMP_ERR_MESSAGE NVARCHAR(500) DEFAULT '';
	DECLARE ERR BIGINT DEFAULT 0;
	DECLARE TEMP_RECORD_CHANGES NVARCHAR(16000) DEFAULT '';
	DECLARE TEMP_RECORD_BINDED BIT DEFAULT 0;

	-- Authentication
	-- ...........................................
	DECLARE TEMP_ACCESS_RIGHTS_DENIED BIT DEFAULT 0;
	DECLARE TEMP_ACCESS_RIGHTS_HAS_OVERRIDE BIT DEFAULT 0;
	DECLARE TEMP_SYNC_SERVER_ID BIGINT DEFAULT 0;
	DECLARE TEMP_SYNC_IS_SERVER_REQUEST BIT DEFAULT 0;
	DECLARE TEMP_AUTHENTICATED_ACCOUNT_ID BIGINT DEFAULT 0;
	DECLARE TEMP_AUTHENTICATED_ACCOUNT_LEVEL BIGINT DEFAULT 0;
	DECLARE TEMP_AUTHENTICATED_ACCOUNT_GROUP BIGINT DEFAULT 0;

	DECLARE TEMP_NOW DATETIME(6) DEFAULT `SYSTEM_VAR@NOW`('', 1);
	
	-- AutoGen Parameters
	-- ...........................................
 

	-- Local value holder
	-- ...........................................
	DECLARE TEMP_ACC_DEVICE_ID BIGINT DEFAULT 0; 
	DECLARE TEMP_ACC_DEVICE_PRIVATE_KEY VARCHAR(4000) DEFAULT ''; 
	DECLARE TEMP_ACC_DEVICE_STATUS TINYINT DEFAULT STATUS_INACTIVE; 
	

	-- System Generated
	-- ...........................................

	-- Check NULLs
	-- ...........................................
	DECLARE IS_NULL_ACC_DEVICE_DESCRIPTION BIT DEFAULT `SYSTEM_VAR@IS_NULL@NVARCHAR`(PARAM_ACC_DEVICE_DESCRIPTION, 1);
	DECLARE IS_NULL_ACC_DEVICE_PUBLIC_KEY BIT DEFAULT `SYSTEM_VAR@IS_NULL@NVARCHAR`(PARAM_ACC_DEVICE_PUBLIC_KEY, 1);
	DECLARE IS_NULL_ACC_DEVICE_PRIVATE_KEY BIT DEFAULT `SYSTEM_VAR@IS_NULL@NVARCHAR`(PARAM_ACC_DEVICE_PRIVATE_KEY, 1);
	

	-- 2) Try Catch / Throw
	-- _______________________________________________________________________
	DECLARE EXIT HANDLER FOR SQLEXCEPTION
	BEGIN
		RESIGNAL;
	END;


	-- 3) Parameter Validation
	-- _______________________________________________________________________
	IF IS_NULL_ACC_DEVICE_DESCRIPTION = 1 THEN
		SET TEMP_ERR_MESSAGE = 'Machine name is required.';
		SET ERR = `RAISERROR`(TEMP_ERR_MESSAGE);
	END IF;
	IF IS_NULL_ACC_DEVICE_PUBLIC_KEY = 1 THEN
		SET TEMP_ERR_MESSAGE = 'Username is required.';
		SET ERR = `RAISERROR`(TEMP_ERR_MESSAGE);			
	END IF;
	IF IS_NULL_ACC_DEVICE_PRIVATE_KEY = 1 THEN
		SET TEMP_ERR_MESSAGE = 'Username is required.';
		SET ERR = `RAISERROR`(TEMP_ERR_MESSAGE);		
	END IF;
	

	-- 4) Find Device
	-- _______________________________________________________________________
	SELECT
		`account_device`.`ACC_DEVICE_ID`,
		`account_device`.`ACC_DEVICE_PRIVATE_KEY`,
		`account_device`.`ACC_DEVICE_STATUS`
	INTO
		TEMP_ACC_DEVICE_ID,
		TEMP_ACC_DEVICE_PRIVATE_KEY,
		TEMP_ACC_DEVICE_STATUS
	FROM `account_device`
	WHERE
		`account_device`.`ACC_DEVICE_PUBLIC_KEY` = PARAM_ACC_DEVICE_PUBLIC_KEY
	LIMIT 1;


	-- 5.A) Register Device [If not exists]
	-- _______________________________________________________________________
	IF `SYSTEM_VAR@IS_NULL@NVARCHAR`(TEMP_ACC_DEVICE_PRIVATE_KEY, 1) = 1 THEN
	
		-- Prepare Hash
		SET TEMP_ACC_DEVICE_PRIVATE_KEY = `FUN_SHA512`(PARAM_ACC_DEVICE_PRIVATE_KEY, 1);
		
		-- Auto Approve for Own Device (Server itself)
		IF `ACCOUNT_DEVICE@IS_SELF`() = 1 THEN
			SET TEMP_ACC_DEVICE_STATUS = STATUS_ACTIVE;
		END IF;
			
		-- Insert Query
		INSERT INTO
		`account_device`
		(
			`account_device`.`ACC_DEVICE_DESCRIPTION`, 
			`account_device`.`ACC_DEVICE_PUBLIC_KEY`, 
			`account_device`.`ACC_DEVICE_PRIVATE_KEY`, 
			`account_device`.`ACC_DEVICE_STATUS`
		)
		VALUES
		(
			PARAM_ACC_DEVICE_DESCRIPTION, 
			PARAM_ACC_DEVICE_PUBLIC_KEY, 
			TEMP_ACC_DEVICE_PRIVATE_KEY, 
			TEMP_ACC_DEVICE_STATUS
		);	
		
		SET TEMP_ACC_DEVICE_ID = LAST_INSERT_ID();

		-- Continue with login if Own Device
		IF `ACCOUNT_DEVICE@IS_SELF`() = 0 THEN
			LEAVE SP_GET;
		END IF;
		
	END IF;
	
	
	-- 5.B) Validate Auth
	-- _______________________________________________________________________
	IF 
		TEMP_ACC_DEVICE_STATUS <> 2 OR 
		`FUN_SHA512_VERIFY`(TEMP_ACC_DEVICE_PRIVATE_KEY, PARAM_ACC_DEVICE_PRIVATE_KEY, 1) = 0 
	THEN
		LEAVE SP_GET;
	END IF;
	
	
	-- 6) RETURN KEY
	-- _______________________________________________________________________		
	SELECT 
		TEMP_ACC_DEVICE_ID AS ACC_DEVICE_ID,
		TEMP_ACC_DEVICE_PRIVATE_KEY AS PRIVATE_KEY;
	
END ;;
DELIMITER ;
/*!50003 SET sql_mode              = @saved_sql_mode */ ;
/*!50003 SET character_set_client  = @saved_cs_client */ ;
/*!50003 SET character_set_results = @saved_cs_results */ ;
/*!50003 SET collation_connection  = @saved_col_connection */ ;
/*!50003 DROP PROCEDURE IF EXISTS `ACCOUNT_DEVICE_SAVE` */;
/*!50003 SET @saved_cs_client      = @@character_set_client */ ;
/*!50003 SET @saved_cs_results     = @@character_set_results */ ;
/*!50003 SET @saved_col_connection = @@collation_connection */ ;
/*!50003 SET character_set_client  = latin1 */ ;
/*!50003 SET character_set_results = latin1 */ ;
/*!50003 SET collation_connection  = latin1_swedish_ci */ ;
/*!50003 SET @saved_sql_mode       = @@sql_mode */ ;
/*!50003 SET sql_mode              = '' */ ;
DELIMITER ;;
CREATE DEFINER=`root`@`localhost` PROCEDURE `ACCOUNT_DEVICE_SAVE`(
	IN `PARAM_ACC_DEVICE_ID` BIGINT,
	IN `PARAM_ACC_DEVICE_STATUS` TINYINT,

	IN `PARAM_REQUESTER_USERNAME` VARCHAR(500),
	IN `PARAM_REQUESTER_PASSWORD` VARCHAR(500),
	IN `PARAM_REQUESTER_PROXY_ID` BIGINT,
	IN `PARAM_REQUESTER_PROXY_PASSWORD` VARCHAR(1000),
	IN `PARAM_REQUESTER_DEVICE_PUBLIC_KEY` VARCHAR(1000),
	IN `PARAM_REQUESTER_DEVICE_PRIVATE_KEY` VARCHAR(1000),
	
	IN `PARAM_REQUESTER_IP` VARCHAR(1000),
	IN `PARAM_UNIQUE_SESSION_ID` VARCHAR(1000),
	IN `PARAM_SUPPRESS_RETURN` BIT,
	
	IN `PARAM_SYNC_SERVER_DESCRIPTION` VARCHAR(500), 
	IN `PARAM_SYNC_SERVER_UNIQUE_KEY` VARCHAR(500)
)
SP_SAVE:
BEGIN


	-- 1) DECLARE LOCAL PARAMETERS
	-- _______________________________________________________________________
	
	-- Status
	-- ...........................................
	DECLARE STATUS_INACTIVE TINYINT DEFAULT 1;
	DECLARE STATUS_ACTIVE TINYINT DEFAULT 2;
	DECLARE STATUS_CLOSED TINYINT DEFAULT 3;
	DECLARE STATUS_COMPLETED TINYINT DEFAULT 4;

	-- Audit Handler
	-- ...........................................
	DECLARE TEMP_RECORD_EXISTS BIT DEFAULT 0;
	DECLARE TEMP_MODULE_KEYWORD VARCHAR(500) DEFAULT 'account_device';
	DECLARE TEMP_SP_OBJECTIVE VARCHAR(500) DEFAULT 'add/edit Devices record';
	DECLARE TEMP_ERR_MESSAGE VARCHAR(500) DEFAULT '';
	DECLARE ERR BIGINT DEFAULT 0;
	DECLARE TEMP_RECORD_CHANGES VARCHAR(16000) DEFAULT '';
	DECLARE TEMP_RECORD_BINDED BIT DEFAULT 0;

	-- Authentication
	-- ...........................................
	DECLARE TEMP_ACCESS_RIGHTS_DENIED BIT DEFAULT 0;
	DECLARE TEMP_ACCESS_RIGHTS_HAS_OVERRIDE BIT DEFAULT 0;
	DECLARE TEMP_SYNC_SERVER_ID BIGINT DEFAULT 0;
	DECLARE TEMP_SYNC_IS_SERVER_REQUEST BIT DEFAULT 0;
	DECLARE TEMP_AUTHENTICATED_ACCOUNT_ID BIGINT DEFAULT `ACCOUNT_MEMBER@ACC_ACCOUNT_ID_FROM_LOGIN`(PARAM_REQUESTER_USERNAME, PARAM_REQUESTER_PASSWORD);
	DECLARE TEMP_AUTHENTICATED_ACCOUNT_LEVEL BIGINT DEFAULT 0;
	DECLARE TEMP_AUTHENTICATED_ACCOUNT_GROUP BIGINT DEFAULT 0;
	
	-- Local Parameters
	-- ...........................................
	DECLARE TEMP_NOW DATETIME(6) DEFAULT `SYSTEM_VAR@NOW`('', 1);
	DECLARE TEMP_RECORD_COUNT BIGINT DEFAULT 0;

	-- AutoGen Parameters
	-- ...........................................
	
	-- Local value holder
	-- ...........................................
	DECLARE TEMP_ACC_DEVICE_DESCRIPTION VARCHAR(500) DEFAULT ''; 
	DECLARE TEMP_ACC_DEVICE_PUBLIC_KEY VARCHAR(4000) DEFAULT ''; 
	DECLARE TEMP_ACC_DEVICE_PRIVATE_KEY VARCHAR(4000) DEFAULT ''; 
	DECLARE TEMP_ACC_DEVICE_STATUS TINYINT DEFAULT 0; 
	


	-- 2) Try Catch / Throw
	-- _______________________________________________________________________
	DECLARE EXIT HANDLER FOR SQLEXCEPTION
	BEGIN
		RESIGNAL;
	END;



	-- 3) Prepare SYNC
	-- _______________________________________________________________________

	-- IS RECORD EXISTS		
	-- ####################################################	
	SET TEMP_RECORD_EXISTS = `ACCOUNT_DEVICE@ACC_DEVICE_ID_EXISTS`(PARAM_ACC_DEVICE_ID, 0);

		
		
	-- 4) PREPARE AUTOGEN DATA (IF EXISTS)
	-- _______________________________________________________________________
	IF TEMP_SYNC_IS_SERVER_REQUEST = 0 THEN
		-- Just to keep at least one line within condition
		SET TEMP_SYNC_IS_SERVER_REQUEST = 0;
		
		-- Actual Functionalities here
		-- USE DEFAULT VALUE (String)
		-- USE DEFAULT VALUE (String)
	END IF;



	-- 5) IF ALREADY EXIST, FILL MISSING DATA
	-- _______________________________________________________________________
	IF TEMP_RECORD_EXISTS = 1 THEN
	
		SELECT	
			`account_device`.`ACC_DEVICE_STATUS`	
		INTO
			TEMP_ACC_DEVICE_STATUS	
		FROM `account_device`
		WHERE
			`account_device`.`ACC_DEVICE_ID` = PARAM_ACC_DEVICE_ID
		LIMIT 1;

		-- Replace NULLs with the existing data.
		SET PARAM_ACC_DEVICE_STATUS = `SYSTEM_VAR@REPLACE_NULL@TINYINT`(PARAM_ACC_DEVICE_STATUS, TEMP_ACC_DEVICE_STATUS, 1, 1);
		
		-- AUTO GEN (NON-UPDATABLES)		
		
		-- AUTO GEN (UPDATABLE WITH STATUS CHANGE)

		-- AUTO GEN (UPDATABLE WITH STATUS [ACTIVE/INACTIVE] CHANGE)
		
	ELSE
		SET PARAM_ACC_DEVICE_STATUS = `SYSTEM_VAR@REPLACE_NULL@TINYINT`(PARAM_ACC_DEVICE_STATUS, 0, 1, 1);
		
	END IF;

	

	-- 6) PREPARE AUDIT TRAIL
	-- _______________________________________________________________________
	IF TEMP_ACC_DEVICE_STATUS <> PARAM_ACC_DEVICE_STATUS THEN
		SET TEMP_RECORD_CHANGES = 
		`SYSTEM_VAR@CONCAT_ADD`(' | ', TEMP_RECORD_CHANGES, CONCAT_WS(' ', 'Status: "', TEMP_ACC_DEVICE_STATUS, '" > "', PARAM_ACC_DEVICE_STATUS, '"'));
	END IF;	
		
	-- No Changes in data, reject request
	-- ####################################################
	IF CHARACTER_LENGTH(TEMP_RECORD_CHANGES) = 0 THEN
		IF PARAM_SUPPRESS_RETURN = 0 THEN
			SELECT PARAM_ACC_DEVICE_ID AS INSERTED_ID;
		END IF;
		LEAVE SP_SAVE;
	END IF;



	-- 7) VALIDATE
	-- _______________________________________________________________________

	-- Access Rights [Device]
	-- ####################################################
	IF `ACCOUNT_DEVICE@HAS_PERMISSION`(PARAM_REQUESTER_DEVICE_PUBLIC_KEY, PARAM_REQUESTER_DEVICE_PRIVATE_KEY) = 0 THEN
		SET TEMP_ERR_MESSAGE = 'Your device is not authorized yet to access this server.';
		SET ERR = `RAISERROR`(TEMP_ERR_MESSAGE);		
	END IF;
		
		
	-- Access Rights [Account]
	-- ####################################################
	
	IF 
		-- [ADD] Access Rights
		(
			TEMP_RECORD_EXISTS = 0 AND
			`ACCOUNT_ACCESS_RIGHTS@HAS_PERMISSION`(PARAM_REQUESTER_USERNAME, PARAM_REQUESTER_PASSWORD, 0, TEMP_MODULE_KEYWORD, 2) = 0 
		) OR
		
		-- [EDIT] Access Rights
		(
			TEMP_RECORD_EXISTS = 1 AND
			`ACCOUNT_ACCESS_RIGHTS@HAS_PERMISSION`(PARAM_REQUESTER_USERNAME, PARAM_REQUESTER_PASSWORD, 0, TEMP_MODULE_KEYWORD, 3) = 0 
		)
	THEN
		SET TEMP_ACCESS_RIGHTS_DENIED = 1;
		CALL `ACCOUNT_ACCESS_RIGHTS_DENY`
		(
			0, TEMP_MODULE_KEYWORD, PARAM_ACC_DEVICE_ID, 0, TEMP_SP_OBJECTIVE, TEMP_RECORD_CHANGES, 
			PARAM_REQUESTER_USERNAME, PARAM_REQUESTER_PASSWORD, 
			PARAM_REQUESTER_PROXY_ID, PARAM_REQUESTER_PROXY_PASSWORD,
			PARAM_REQUESTER_DEVICE_PUBLIC_KEY, PARAM_REQUESTER_DEVICE_PRIVATE_KEY,
			PARAM_REQUESTER_IP, PARAM_UNIQUE_SESSION_ID,
			TEMP_SYNC_SERVER_ID, PARAM_SUPPRESS_RETURN
		);
	END IF;
	SET TEMP_ACCESS_RIGHTS_HAS_OVERRIDE = `ACCOUNT_ACCESS_RIGHTS@HAS_PERMISSION`(PARAM_REQUESTER_USERNAME, PARAM_REQUESTER_PASSWORD, 0, TEMP_MODULE_KEYWORD, 4);
	

	-- Validation
	-- ####################################################
	IF TEMP_SYNC_IS_SERVER_REQUEST = 0 THEN
	

		-- FOREIGN KEY EXISTS
		-- ...........................................
		
		-- FOREIGN (OPTIONAL)KEY EXISTS [Validates if not null]
		-- ...........................................
		
		-- IS_ALLOW_NULL = FALSE
		-- ...........................................
				
		-- IS_ALLOW_ZERO = FALSE
		-- ...........................................
		IF PARAM_ACC_DEVICE_STATUS = 0 THEN
			CALL `VALIDATION_MISSING_FIELD`('`ACC_DEVICE_STATUS`', '`NULL`');
		END IF;		
		
		-- IS_ALLOW_NEGATIVE = FALSE
		-- ...........................................
		IF PARAM_ACC_DEVICE_STATUS < 0 THEN
			CALL `VALIDATION_NEGATIVE`('`ACC_DEVICE_STATUS`', PARAM_ACC_DEVICE_STATUS);
		END IF;		
		
		-- IS_ALLOW_EMPTY_STRING = FALSE
		-- ...........................................
		
		-- IS_STATUS
		-- ...........................................
		IF `SYSTEM_STATUS@STATUS_ID_EXISTS`(PARAM_ACC_DEVICE_STATUS, 0) = 0 THEN
			SET TEMP_ERR_MESSAGE = CONCAT_WS(' ', 'Given STATUS[Status] does not exists or is inactive. ID: ', PARAM_ACC_DEVICE_STATUS);
			SET ERR = `RAISERROR`(TEMP_ERR_MESSAGE);
		END IF;
		
		-- IS STATUS Active / Inactive
		-- ...........................................
		
		-- Minimum / Maximum Value
		-- ...........................................
		
		-- IS_UNIQUE = TRUE
		-- ...........................................
		
		-- RECORD IDENTIFIER
		-- ...........................................
		
		
		-- ON_UPDATE VALIDATION 
		-- ...........................................
		IF TEMP_RECORD_EXISTS = 1 THEN	
		
			-- Just to keep at least one line within condition
			SET TEMP_RECORD_EXISTS = 1;
			
		END IF;
		
	END IF;



	-- 8) UPDATE
	-- _______________________________________________________________________

	-- UPDATING EXISTING RECORD
	-- ####################################################
	UPDATE `account_device`
	SET
		`account_device`.`ACC_DEVICE_STATUS` = PARAM_ACC_DEVICE_STATUS
	WHERE
		`account_device`.`ACC_DEVICE_ID` = PARAM_ACC_DEVICE_ID;


	
	-- 9) AUDIT TRAIL
	-- _______________________________________________________________________
	CALL `ACCOUNT_AUDIT_TRAIL_SAVE`
	(
		0, TEMP_MODULE_KEYWORD, PARAM_ACC_DEVICE_ID, 0, 'SAVE', TEMP_SP_OBJECTIVE, TEMP_RECORD_CHANGES, 
		PARAM_REQUESTER_USERNAME, PARAM_REQUESTER_PASSWORD, 
		PARAM_REQUESTER_PROXY_ID, PARAM_REQUESTER_PROXY_PASSWORD,
		PARAM_REQUESTER_DEVICE_PUBLIC_KEY, PARAM_REQUESTER_DEVICE_PRIVATE_KEY,
		PARAM_REQUESTER_IP, PARAM_UNIQUE_SESSION_ID,
		TEMP_SYNC_SERVER_ID, PARAM_SUPPRESS_RETURN
	);
	

	-- 10) RETURN RESULT
	-- _______________________________________________________________________
	IF PARAM_SUPPRESS_RETURN = 0 THEN
		SELECT PARAM_ACC_DEVICE_ID AS INSERTED_ID;
	END IF;
	LEAVE SP_SAVE;


END ;;
DELIMITER ;
/*!50003 SET sql_mode              = @saved_sql_mode */ ;
/*!50003 SET character_set_client  = @saved_cs_client */ ;
/*!50003 SET character_set_results = @saved_cs_results */ ;
/*!50003 SET collation_connection  = @saved_col_connection */ ;
/*!50003 DROP PROCEDURE IF EXISTS `ACCOUNT_GROUP_DELETE` */;
/*!50003 SET @saved_cs_client      = @@character_set_client */ ;
/*!50003 SET @saved_cs_results     = @@character_set_results */ ;
/*!50003 SET @saved_col_connection = @@collation_connection */ ;
/*!50003 SET character_set_client  = latin1 */ ;
/*!50003 SET character_set_results = latin1 */ ;
/*!50003 SET collation_connection  = latin1_swedish_ci */ ;
/*!50003 SET @saved_sql_mode       = @@sql_mode */ ;
/*!50003 SET sql_mode              = '' */ ;
DELIMITER ;;
CREATE DEFINER=`root`@`localhost` PROCEDURE `ACCOUNT_GROUP_DELETE`(
	IN `PARAM_ACC_GROUP_ID` BIGINT,

	IN `PARAM_REQUESTER_USERNAME` VARCHAR(500),
	IN `PARAM_REQUESTER_PASSWORD` VARCHAR(500),
	IN `PARAM_REQUESTER_PROXY_ID` BIGINT,
	IN `PARAM_REQUESTER_PROXY_PASSWORD` VARCHAR(1000),
	IN `PARAM_REQUESTER_DEVICE_PUBLIC_KEY` VARCHAR(1000),
	IN `PARAM_REQUESTER_DEVICE_PRIVATE_KEY` VARCHAR(1000),
	
	IN `PARAM_REQUESTER_IP` VARCHAR(1000),
	IN `PARAM_UNIQUE_SESSION_ID` VARCHAR(1000),
	IN `PARAM_SUPPRESS_RETURN` BIT,
	
	IN `PARAM_SYNC_SERVER_DESCRIPTION` VARCHAR(500), 
	IN `PARAM_SYNC_SERVER_UNIQUE_KEY` VARCHAR(500)
)
SP_DELETE:
BEGIN

	-- 1) DECLARE LOCAL PARAMETERS
	-- _______________________________________________________________________
	
	-- Status
	-- ...........................................
	DECLARE STATUS_INACTIVE TINYINT DEFAULT 1;
	DECLARE STATUS_ACTIVE TINYINT DEFAULT 2;
	DECLARE STATUS_CLOSED TINYINT DEFAULT 3;
	DECLARE STATUS_COMPLETED TINYINT DEFAULT 4;
	
	-- Audit Handler
	-- ...........................................
	DECLARE TEMP_RECORD_EXISTS BIT DEFAULT 0;
	DECLARE TEMP_MODULE_KEYWORD VARCHAR(500) DEFAULT 'account_group';
	DECLARE TEMP_SP_OBJECTIVE VARCHAR(500) DEFAULT 'delete Group record';
	DECLARE TEMP_ERR_MESSAGE VARCHAR(500) DEFAULT '';
	DECLARE ERR BIGINT DEFAULT 0;
	DECLARE TEMP_RECORD_CHANGES VARCHAR(16000) DEFAULT '';
	DECLARE TEMP_RECORD_BINDED BIT DEFAULT 0;
	
	DECLARE TEMP_RECORD_BINDED_ID BIGINT DEFAULT 0;
	DECLARE TEMP_RECORD_BINDED_SERVER_ID BIGINT DEFAULT 0;
	
	-- Authentication
	-- ...........................................
	DECLARE TEMP_ACCESS_RIGHTS_DENIED BIT DEFAULT 0;
	DECLARE TEMP_SYNC_SERVER_ID BIGINT DEFAULT 0;
	DECLARE TEMP_SYNC_IS_SERVER_REQUEST BIT DEFAULT 0;
	DECLARE TEMP_AUTHENTICATED_ACCOUNT_ID BIGINT DEFAULT `ACCOUNT_MEMBER@ACC_ACCOUNT_ID_FROM_LOGIN`(PARAM_REQUESTER_USERNAME, PARAM_REQUESTER_PASSWORD);
	DECLARE TEMP_AUTHENTICATED_ACCOUNT_LEVEL BIGINT DEFAULT 0;

	-- Local value holder
	-- ...........................................
	DECLARE TEMP_ACC_GROUP_DESCRIPTION VARCHAR(500) DEFAULT ''; 
	DECLARE TEMP_ACC_GROUP_STATUS TINYINT DEFAULT 0; 
	DECLARE TEMP_ACC_GROUP_SYSTEM_GENERATED TINYINT DEFAULT 0; 

	
	
	-- 2) Try Catch / Throw
	-- _______________________________________________________________________
	DECLARE EXIT HANDLER FOR SQLEXCEPTION
	BEGIN
		RESIGNAL;
	END;

	
	-- 3) Prepare SYNC
	-- _______________________________________________________________________
	
	-- IS RECORD EXISTS		
	-- ####################################################		
	SET TEMP_RECORD_EXISTS = `ACCOUNT_GROUP@ACC_GROUP_ID_EXISTS`(PARAM_ACC_GROUP_ID, 0);


	-- 4) IF ALREADY EXIST, FILL MISSING DATA
	-- _______________________________________________________________________
	IF TEMP_RECORD_EXISTS = 1 THEN
		SELECT
				`account_group`.`ACC_GROUP_DESCRIPTION`, 	
				`account_group`.`ACC_GROUP_STATUS`, 	
				`account_group`.`ACC_GROUP_SYSTEM_GENERATED`	
		INTO
				TEMP_ACC_GROUP_DESCRIPTION, 	
				TEMP_ACC_GROUP_STATUS, 	
				TEMP_ACC_GROUP_SYSTEM_GENERATED	

		FROM `account_group`
		WHERE
			`account_group`.`ACC_GROUP_ID` = PARAM_ACC_GROUP_ID
		LIMIT 1;

	ELSE 
		IF TEMP_SYNC_IS_SERVER_REQUEST = 0 THEN
			SET TEMP_ERR_MESSAGE = CONCAT_WS(' ', 'Given Group does not exists or is inactive. ID:', PARAM_ACC_GROUP_ID);
			SET ERR = `RAISERROR`(TEMP_ERR_MESSAGE);		
		END IF;
		LEAVE SP_DELETE;
		
	END IF;



	-- 5) PREPARE AUDIT TRAIL
	-- _______________________________________________________________________
	
		SET TEMP_RECORD_CHANGES = 
		`SYSTEM_VAR@CONCAT_ADD`(' | ', TEMP_RECORD_CHANGES, CONCAT_WS(' ', 'Description: "', TEMP_ACC_GROUP_DESCRIPTION, '" > " DELETED "'));
		SET TEMP_RECORD_CHANGES = 
		`SYSTEM_VAR@CONCAT_ADD`(' | ', TEMP_RECORD_CHANGES, CONCAT_WS(' ', 'Status: "', TEMP_ACC_GROUP_STATUS, '" > " DELETED "'));
		SET TEMP_RECORD_CHANGES = 
		`SYSTEM_VAR@CONCAT_ADD`(' | ', TEMP_RECORD_CHANGES, CONCAT_WS(' ', 'System Generated: "', TEMP_ACC_GROUP_SYSTEM_GENERATED, '" > " DELETED "'));


	-- 6) VALIDATE
	-- _______________________________________________________________________

	-- Access Rights [Device]
	-- ####################################################	
	IF `ACCOUNT_DEVICE@HAS_PERMISSION`(PARAM_REQUESTER_DEVICE_PUBLIC_KEY, PARAM_REQUESTER_DEVICE_PRIVATE_KEY) = 0 THEN
		SET TEMP_ERR_MESSAGE = 'Your device is not authorized yet to access this server.';
		SET ERR = `RAISERROR`(TEMP_ERR_MESSAGE);		
	END IF;
		
		
	-- Access Rights [Account]
	-- ####################################################	
	IF 
		-- [DELETE] Access Rights
		`ACCOUNT_ACCESS_RIGHTS@HAS_PERMISSION`(PARAM_REQUESTER_USERNAME, PARAM_REQUESTER_PASSWORD, 0, TEMP_MODULE_KEYWORD, 4) = 0 
	THEN
		SET TEMP_ACCESS_RIGHTS_DENIED = 1;
		CALL `ACCOUNT_ACCESS_RIGHTS_DENY`
		(
			0, TEMP_MODULE_KEYWORD, PARAM_ACC_GROUP_ID, 0, TEMP_SP_OBJECTIVE, TEMP_RECORD_CHANGES, 
			PARAM_REQUESTER_USERNAME, PARAM_REQUESTER_PASSWORD, 
			PARAM_REQUESTER_PROXY_ID, PARAM_REQUESTER_PROXY_PASSWORD,
			PARAM_REQUESTER_DEVICE_PUBLIC_KEY, PARAM_REQUESTER_DEVICE_PRIVATE_KEY,
			PARAM_REQUESTER_IP, PARAM_UNIQUE_SESSION_ID,
			TEMP_SYNC_SERVER_ID, PARAM_SUPPRESS_RETURN
		);
	END IF;

	-- System Generated Record (Cannot be deleted)
	-- ####################################################
	IF TEMP_ACC_GROUP_SYSTEM_GENERATED = STATUS_ACTIVE THEN
		CALL `VALIDATION_SYSTEM_GENERATED`
		(
			PARAM_ACC_GROUP_ID,
			TEMP_ACC_GROUP_DESCRIPTION, ''
		);
	END IF;
	
	-- If already used, cannot remove record
	-- ####################################################
	IF
	(
		SELECT
			COUNT(`mobile_contact`.`MOB_CONTACT_ACC_GROUP_ID`)
		FROM `mobile_contact`
		WHERE
			`mobile_contact`.`MOB_CONTACT_ACC_GROUP_ID` = PARAM_ACC_GROUP_ID
		LIMIT 1
	) >= 1 
	THEN
		SET TEMP_RECORD_BINDED = 1;
		SET TEMP_ERR_MESSAGE = 'Contact Phonebook Record';
	END IF;
	IF
	(
		SELECT
			COUNT(`account_member`.`ACC_ACCOUNT_ACC_GROUP_ID`)
		FROM `account_member`
		WHERE
			`account_member`.`ACC_ACCOUNT_ACC_GROUP_ID` = PARAM_ACC_GROUP_ID
		LIMIT 1
	) >= 1 
	THEN
		SET TEMP_RECORD_BINDED = 1;
		SET TEMP_ERR_MESSAGE = 'Registered Member Record';
	END IF;

	-- Leave Re-upload request
	-- ####################################################
	IF TEMP_RECORD_BINDED = 1 THEN
		IF TEMP_SYNC_IS_SERVER_REQUEST = 1 THEN
			
			LEAVE SP_DELETE;
		END IF;

		CALL `VALIDATION_DELETE_LINKED_RECORD`(TEMP_ACC_GROUP_DESCRIPTION, '', TEMP_ERR_MESSAGE); 
	END IF;


	-- 7) DELETE
	-- _______________________________________________________________________
	DELETE FROM `account_group`
	WHERE `account_group`.`ACC_GROUP_ID` = PARAM_ACC_GROUP_ID
	LIMIT 1;


	-- 8) AUDIT TRAIL
	-- _______________________________________________________________________
	CALL `ACCOUNT_AUDIT_TRAIL_SAVE`
	(
		0, TEMP_MODULE_KEYWORD, PARAM_ACC_GROUP_ID, 0, 'DELETE', TEMP_SP_OBJECTIVE, TEMP_RECORD_CHANGES, 
		PARAM_REQUESTER_USERNAME, PARAM_REQUESTER_PASSWORD, 
		PARAM_REQUESTER_PROXY_ID, PARAM_REQUESTER_PROXY_PASSWORD,
		PARAM_REQUESTER_DEVICE_PUBLIC_KEY, PARAM_REQUESTER_DEVICE_PRIVATE_KEY,
		PARAM_REQUESTER_IP, PARAM_UNIQUE_SESSION_ID,
		TEMP_SYNC_SERVER_ID, PARAM_SUPPRESS_RETURN
	);

END ;;
DELIMITER ;
/*!50003 SET sql_mode              = @saved_sql_mode */ ;
/*!50003 SET character_set_client  = @saved_cs_client */ ;
/*!50003 SET character_set_results = @saved_cs_results */ ;
/*!50003 SET collation_connection  = @saved_col_connection */ ;
/*!50003 DROP PROCEDURE IF EXISTS `ACCOUNT_GROUP_GET` */;
/*!50003 SET @saved_cs_client      = @@character_set_client */ ;
/*!50003 SET @saved_cs_results     = @@character_set_results */ ;
/*!50003 SET @saved_col_connection = @@collation_connection */ ;
/*!50003 SET character_set_client  = latin1 */ ;
/*!50003 SET character_set_results = latin1 */ ;
/*!50003 SET collation_connection  = latin1_swedish_ci */ ;
/*!50003 SET @saved_sql_mode       = @@sql_mode */ ;
/*!50003 SET sql_mode              = '' */ ;
DELIMITER ;;
CREATE DEFINER=`root`@`localhost` PROCEDURE `ACCOUNT_GROUP_GET`(
	IN `PARAM_ACC_GROUP_ID` BIGINT,	
	IN `PARAM_ACC_GROUP_DESCRIPTION` VARCHAR(500),	
	IN `PARAM_ACC_GROUP_STATUS` TINYINT,	
	IN `PARAM_ACC_GROUP_SYSTEM_GENERATED` TINYINT,	
		
	IN `PARAM_ORDER_FIELD` VARCHAR(500),
	IN `PARAM_ORDER_TYPE` VARCHAR(500),
	IN `PARAM_SKIP` BIGINT,
	IN `PARAM_LIMIT` BIGINT,

	IN `PARAM_REQUESTER_USERNAME` VARCHAR(500),
	IN `PARAM_REQUESTER_PASSWORD` VARCHAR(500),
	IN `PARAM_REQUESTER_PROXY_ID` BIGINT,
	IN `PARAM_REQUESTER_PROXY_PASSWORD` VARCHAR(1000),
	IN `PARAM_REQUESTER_DEVICE_PUBLIC_KEY` VARCHAR(1000),
	IN `PARAM_REQUESTER_DEVICE_PRIVATE_KEY` VARCHAR(1000),
	
	IN `PARAM_REQUESTER_IP` VARCHAR(1000),
	IN `PARAM_UNIQUE_SESSION_ID` VARCHAR(1000),
	IN `PARAM_SUPPRESS_RETURN` BIT
)
SP_GET:
BEGIN

	-- Status
	-- =========================================================================================
	DECLARE STATUS_INACTIVE TINYINT DEFAULT 1;
	DECLARE STATUS_ACTIVE TINYINT DEFAULT 2;
	DECLARE STATUS_CLOSED TINYINT DEFAULT 3;
	DECLARE STATUS_COMPLETED TINYINT DEFAULT 4;
	
	-- Audit Handler
	-- =========================================================================================
	DECLARE TEMP_RECORD_EXISTS BIT DEFAULT 0;
	DECLARE TEMP_MODULE_KEYWORD VARCHAR(500) DEFAULT 'account_group';
	DECLARE TEMP_SP_OBJECTIVE VARCHAR(500) DEFAULT 'Retrieve Group record';
	DECLARE TEMP_ERR_MESSAGE VARCHAR(500) DEFAULT '';
	DECLARE ERR BIGINT DEFAULT 0;
	DECLARE TEMP_RECORD_CHANGES VARCHAR(16000) DEFAULT '';
	DECLARE TEMP_RECORD_BINDED BIT DEFAULT 0;
	
	DECLARE TEMP_RECORD_BINDED_ID BIGINT DEFAULT 0;
	DECLARE TEMP_RECORD_BINDED_SERVER_ID BIGINT DEFAULT 0;
	
	-- Authentication
	-- =========================================================================================
	DECLARE TEMP_ACCESS_RIGHTS_DENIED BIT DEFAULT 0;
	DECLARE TEMP_AUTHENTICATED_ACCOUNT_ID BIGINT DEFAULT `ACCOUNT_MEMBER@ACC_ACCOUNT_ID_FROM_LOGIN`(PARAM_REQUESTER_USERNAME, PARAM_REQUESTER_PASSWORD);
	DECLARE TEMP_AUTHENTICATED_ACCOUNT_LEVEL BIGINT DEFAULT 0;
	
	-- Local Parameters
	-- =========================================================================================
	DECLARE TEMP_NOW DATETIME(6) DEFAULT `SYSTEM_VAR@NOW`('', 1);
	DECLARE TEMP_RECORD_COUNT BIGINT DEFAULT 0;
	
	
	-- Check NULLs
	-- =========================================================================================
	DECLARE IS_NULL_ACC_GROUP_ID BIT DEFAULT `SYSTEM_VAR@IS_NULL@BIGINT`(PARAM_ACC_GROUP_ID, 1, 1);
	DECLARE IS_NULL_ACC_GROUP_DESCRIPTION BIT DEFAULT `SYSTEM_VAR@IS_NULL@NVARCHAR`(PARAM_ACC_GROUP_DESCRIPTION, 1);
	DECLARE IS_NULL_ACC_GROUP_STATUS BIT DEFAULT `SYSTEM_VAR@IS_NULL@TINYINT`(PARAM_ACC_GROUP_STATUS, 1, 1);
	DECLARE IS_NULL_ACC_GROUP_SYSTEM_GENERATED BIT DEFAULT `SYSTEM_VAR@IS_NULL@TINYINT`(PARAM_ACC_GROUP_SYSTEM_GENERATED, 1, 1);
	
	-- Error Handler
	-- =========================================================================================
	DECLARE EXIT HANDLER FOR SQLEXCEPTION
	BEGIN
		RESIGNAL;
	END;
	
	-- Ignore Time from DateTime (Set Time 00:00:00.000000 and 23:59:59.999999)
	-- =========================================================================================
		
	-- Access Rights
	-- =========================================================================================
	IF `ACCOUNT_ACCESS_RIGHTS@HAS_PERMISSION`(PARAM_REQUESTER_USERNAME, PARAM_REQUESTER_PASSWORD, 0, TEMP_MODULE_KEYWORD, 1) = 0 THEN
		SET TEMP_ACCESS_RIGHTS_DENIED = 1;
		CALL `ACCOUNT_ACCESS_RIGHTS_DENY`
		(
			0, TEMP_MODULE_KEYWORD, 0, 0, TEMP_SP_OBJECTIVE, TEMP_RECORD_CHANGES, 
			PARAM_REQUESTER_USERNAME, PARAM_REQUESTER_PASSWORD, 
			PARAM_REQUESTER_PROXY_ID, PARAM_REQUESTER_PROXY_PASSWORD,
			PARAM_REQUESTER_DEVICE_PUBLIC_KEY, PARAM_REQUESTER_DEVICE_PRIVATE_KEY,
			PARAM_REQUESTER_IP, PARAM_UNIQUE_SESSION_ID,
			0, PARAM_SUPPRESS_RETURN
		);
	END IF;
	
	
	
	-- COUNT RECORD
	-- =========================================================================================
	
	-- SELECT COLUMNS
	-- ####################################################
	SELECT
		COUNT(DISTINCT `account_group`.`ACC_GROUP_ID`)
	INTO
		TEMP_RECORD_COUNT

	FROM `account_group`
	
		-- Add Inner Joins (Per Foreign-key)
		
		-- Add Optional Left Joins (Per Optional Foreign-key)
		
	-- CONDITIONS
	-- ####################################################
	WHERE
		(
			IS_NULL_ACC_GROUP_ID = 1 OR
			`account_group`.`ACC_GROUP_ID` = PARAM_ACC_GROUP_ID			
		) AND
		(
			IS_NULL_ACC_GROUP_DESCRIPTION = 1 OR
			`account_group`.`ACC_GROUP_DESCRIPTION` LIKE CONCAT_WS('%', '', PARAM_ACC_GROUP_DESCRIPTION, '')			
		) AND 		
		(
			IS_NULL_ACC_GROUP_STATUS = 1 OR
			`account_group`.`ACC_GROUP_STATUS` = PARAM_ACC_GROUP_STATUS			
		) AND
		(
			IS_NULL_ACC_GROUP_SYSTEM_GENERATED = 1 OR
			`account_group`.`ACC_GROUP_SYSTEM_GENERATED` = PARAM_ACC_GROUP_SYSTEM_GENERATED			
		) 
;	

		
		
	-- SELECT RECORDS
	-- =========================================================================================
	
	-- FETCH COLUMNS
	-- ####################################################
	SELECT
		-- ACCOUNT_GROUP DETAILS
		`account_group`.`ACC_GROUP_ID`, 
		`account_group`.`ACC_GROUP_DESCRIPTION`, 
		`account_group`.`ACC_GROUP_STATUS`, 
		`account_group`.`ACC_GROUP_SYSTEM_GENERATED`
		
		-- Inner join fields
		
		-- Left join fields
		
		, TEMP_RECORD_COUNT AS RECORD_COUNT

	FROM `account_group`
	
		-- Add Inner Joins (Per Foreign-key)
		
		-- Add Optional Left Joins (Per Optional Foreign-key)
		
	-- CONDITIONS
	-- ####################################################
	WHERE
		(
			IS_NULL_ACC_GROUP_ID = 1 OR
			`account_group`.`ACC_GROUP_ID` = PARAM_ACC_GROUP_ID			
		) AND
		(
			IS_NULL_ACC_GROUP_DESCRIPTION = 1 OR
			`account_group`.`ACC_GROUP_DESCRIPTION` LIKE CONCAT_WS('%', '', PARAM_ACC_GROUP_DESCRIPTION, '')			
		) AND 		
		(
			IS_NULL_ACC_GROUP_STATUS = 1 OR
			`account_group`.`ACC_GROUP_STATUS` = PARAM_ACC_GROUP_STATUS			
		) AND
		(
			IS_NULL_ACC_GROUP_SYSTEM_GENERATED = 1 OR
			`account_group`.`ACC_GROUP_SYSTEM_GENERATED` = PARAM_ACC_GROUP_SYSTEM_GENERATED			
		) 

	-- ORDER BY
	-- ####################################################
	ORDER BY
		-- ACCOUNT_GROUP DETAILS
		CASE WHEN PARAM_ORDER_FIELD = 'ACC_GROUP_ID' AND PARAM_ORDER_TYPE = 'ASC' THEN `account_group`.`ACC_GROUP_ID` END ASC, 
		CASE WHEN PARAM_ORDER_FIELD = 'ACC_GROUP_ID' AND PARAM_ORDER_TYPE = 'DESC' THEN `account_group`.`ACC_GROUP_ID` END DESC,	
		CASE WHEN PARAM_ORDER_FIELD = 'ACC_GROUP_DESCRIPTION' AND PARAM_ORDER_TYPE = 'ASC' THEN `account_group`.`ACC_GROUP_DESCRIPTION` END ASC, 
		CASE WHEN PARAM_ORDER_FIELD = 'ACC_GROUP_DESCRIPTION' AND PARAM_ORDER_TYPE = 'DESC' THEN `account_group`.`ACC_GROUP_DESCRIPTION` END DESC,	
		CASE WHEN PARAM_ORDER_FIELD = 'ACC_GROUP_STATUS' AND PARAM_ORDER_TYPE = 'ASC' THEN `account_group`.`ACC_GROUP_STATUS` END ASC, 
		CASE WHEN PARAM_ORDER_FIELD = 'ACC_GROUP_STATUS' AND PARAM_ORDER_TYPE = 'DESC' THEN `account_group`.`ACC_GROUP_STATUS` END DESC,	
		CASE WHEN PARAM_ORDER_FIELD = 'ACC_GROUP_SYSTEM_GENERATED' AND PARAM_ORDER_TYPE = 'ASC' THEN `account_group`.`ACC_GROUP_SYSTEM_GENERATED` END ASC, 
		CASE WHEN PARAM_ORDER_FIELD = 'ACC_GROUP_SYSTEM_GENERATED' AND PARAM_ORDER_TYPE = 'DESC' THEN `account_group`.`ACC_GROUP_SYSTEM_GENERATED` END DESC,	

		-- Inner joins
		
		-- EXTRA
		CASE WHEN PARAM_ORDER_FIELD <> 'ACC_GROUP_DESCRIPTION' THEN `account_group`.`ACC_GROUP_DESCRIPTION` END ASC
		
	-- LIMIT & OFFSET
	-- ####################################################		
	LIMIT PARAM_SKIP, PARAM_LIMIT;
	
	
	
	-- EXIT PROCEDURE
	-- =========================================================================================
	LEAVE SP_GET;
			
END ;;
DELIMITER ;
/*!50003 SET sql_mode              = @saved_sql_mode */ ;
/*!50003 SET character_set_client  = @saved_cs_client */ ;
/*!50003 SET character_set_results = @saved_cs_results */ ;
/*!50003 SET collation_connection  = @saved_col_connection */ ;
/*!50003 DROP PROCEDURE IF EXISTS `ACCOUNT_GROUP_SAVE` */;
/*!50003 SET @saved_cs_client      = @@character_set_client */ ;
/*!50003 SET @saved_cs_results     = @@character_set_results */ ;
/*!50003 SET @saved_col_connection = @@collation_connection */ ;
/*!50003 SET character_set_client  = latin1 */ ;
/*!50003 SET character_set_results = latin1 */ ;
/*!50003 SET collation_connection  = latin1_swedish_ci */ ;
/*!50003 SET @saved_sql_mode       = @@sql_mode */ ;
/*!50003 SET sql_mode              = '' */ ;
DELIMITER ;;
CREATE DEFINER=`root`@`localhost` PROCEDURE `ACCOUNT_GROUP_SAVE`(
	IN `PARAM_ACC_GROUP_ID` BIGINT,
	IN `PARAM_ACC_GROUP_DESCRIPTION` VARCHAR(500),
	IN `PARAM_ACC_GROUP_STATUS` TINYINT,

	IN `PARAM_REQUESTER_USERNAME` VARCHAR(500),
	IN `PARAM_REQUESTER_PASSWORD` VARCHAR(500),
	IN `PARAM_REQUESTER_PROXY_ID` BIGINT,
	IN `PARAM_REQUESTER_PROXY_PASSWORD` VARCHAR(1000),
	IN `PARAM_REQUESTER_DEVICE_PUBLIC_KEY` VARCHAR(1000),
	IN `PARAM_REQUESTER_DEVICE_PRIVATE_KEY` VARCHAR(1000),
	
	IN `PARAM_REQUESTER_IP` VARCHAR(1000),
	IN `PARAM_UNIQUE_SESSION_ID` VARCHAR(1000),
	IN `PARAM_SUPPRESS_RETURN` BIT,
	
	IN `PARAM_SYNC_SERVER_DESCRIPTION` VARCHAR(500), 
	IN `PARAM_SYNC_SERVER_UNIQUE_KEY` VARCHAR(500)
)
SP_SAVE:
BEGIN


	-- 1) DECLARE LOCAL PARAMETERS
	-- _______________________________________________________________________
	
	-- Status
	-- ...........................................
	DECLARE STATUS_INACTIVE TINYINT DEFAULT 1;
	DECLARE STATUS_ACTIVE TINYINT DEFAULT 2;
	DECLARE STATUS_CLOSED TINYINT DEFAULT 3;
	DECLARE STATUS_COMPLETED TINYINT DEFAULT 4;

	-- Audit Handler
	-- ...........................................
	DECLARE TEMP_RECORD_EXISTS BIT DEFAULT 0;
	DECLARE TEMP_MODULE_KEYWORD VARCHAR(500) DEFAULT 'account_group';
	DECLARE TEMP_SP_OBJECTIVE VARCHAR(500) DEFAULT 'add/edit Group record';
	DECLARE TEMP_ERR_MESSAGE VARCHAR(500) DEFAULT '';
	DECLARE ERR BIGINT DEFAULT 0;
	DECLARE TEMP_RECORD_CHANGES VARCHAR(16000) DEFAULT '';
	DECLARE TEMP_RECORD_BINDED BIT DEFAULT 0;

	-- Authentication
	-- ...........................................
	DECLARE TEMP_ACCESS_RIGHTS_DENIED BIT DEFAULT 0;
	DECLARE TEMP_ACCESS_RIGHTS_HAS_OVERRIDE BIT DEFAULT 0;
	DECLARE TEMP_SYNC_SERVER_ID BIGINT DEFAULT 0;
	DECLARE TEMP_SYNC_IS_SERVER_REQUEST BIT DEFAULT 0;
	DECLARE TEMP_AUTHENTICATED_ACCOUNT_ID BIGINT DEFAULT `ACCOUNT_MEMBER@ACC_ACCOUNT_ID_FROM_LOGIN`(PARAM_REQUESTER_USERNAME, PARAM_REQUESTER_PASSWORD);
	DECLARE TEMP_AUTHENTICATED_ACCOUNT_LEVEL BIGINT DEFAULT 0;
	
	-- Local Parameters
	-- ...........................................
	DECLARE TEMP_NOW DATETIME(6) DEFAULT `SYSTEM_VAR@NOW`('', 1);
	DECLARE TEMP_RECORD_COUNT BIGINT DEFAULT 0;

	-- AutoGen Parameters
	-- ...........................................
	DECLARE PARAM_ACC_GROUP_SYSTEM_GENERATED TINYINT DEFAULT 0; 
	
	-- Local value holder
	-- ...........................................
	DECLARE TEMP_ACC_GROUP_DESCRIPTION VARCHAR(500) DEFAULT ''; 
	DECLARE TEMP_ACC_GROUP_STATUS TINYINT DEFAULT 0; 
	DECLARE TEMP_ACC_GROUP_SYSTEM_GENERATED TINYINT DEFAULT 0; 
	


	-- 2) Try Catch / Throw
	-- _______________________________________________________________________
	DECLARE EXIT HANDLER FOR SQLEXCEPTION
	BEGIN
		RESIGNAL;
	END;



	-- 3) Prepare SYNC
	-- _______________________________________________________________________

	-- IS RECORD EXISTS		
	-- ####################################################	
	SET TEMP_RECORD_EXISTS = `ACCOUNT_GROUP@ACC_GROUP_ID_EXISTS`(PARAM_ACC_GROUP_ID, 0);

		
		
	-- 4) PREPARE AUTOGEN DATA (IF EXISTS)
	-- _______________________________________________________________________
	IF TEMP_SYNC_IS_SERVER_REQUEST = 0 THEN
		-- Just to keep at least one line within condition
		SET TEMP_SYNC_IS_SERVER_REQUEST = 0;
		
		-- Actual Functionalities here
		-- USE DEFAULT VALUE (String)
		-- USE DEFAULT VALUE (String)
		SET PARAM_ACC_GROUP_SYSTEM_GENERATED = 1;
	-- USE TIMESTAMP
	END IF;



	-- 5) IF ALREADY EXIST, FILL MISSING DATA
	-- _______________________________________________________________________
	IF TEMP_RECORD_EXISTS = 1 THEN
		SELECT
			`account_group`.`ACC_GROUP_DESCRIPTION`, 	
			`account_group`.`ACC_GROUP_STATUS`, 	
			`account_group`.`ACC_GROUP_SYSTEM_GENERATED`	
		INTO
			TEMP_ACC_GROUP_DESCRIPTION, 	
			TEMP_ACC_GROUP_STATUS, 	
			TEMP_ACC_GROUP_SYSTEM_GENERATED	

		FROM `account_group`
		WHERE
			`account_group`.`ACC_GROUP_ID` = PARAM_ACC_GROUP_ID
		LIMIT 1;

		-- Replace NULLs with the existing data.
		SET PARAM_ACC_GROUP_DESCRIPTION = `SYSTEM_VAR@REPLACE_NULL@NVARCHAR`(PARAM_ACC_GROUP_DESCRIPTION, TEMP_ACC_GROUP_DESCRIPTION, 1);
		SET PARAM_ACC_GROUP_STATUS = `SYSTEM_VAR@REPLACE_NULL@TINYINT`(PARAM_ACC_GROUP_STATUS, TEMP_ACC_GROUP_STATUS, 1, 1);
		
		-- AUTO GEN (NON-UPDATABLES)		
		SET PARAM_ACC_GROUP_SYSTEM_GENERATED = TEMP_ACC_GROUP_SYSTEM_GENERATED;
		
		-- AUTO GEN (UPDATABLE WITH STATUS CHANGE)

		-- AUTO GEN (UPDATABLE WITH STATUS [ACTIVE/INACTIVE] CHANGE)
		
	ELSE
		SET PARAM_ACC_GROUP_DESCRIPTION = `SYSTEM_VAR@REPLACE_NULL@NVARCHAR`(PARAM_ACC_GROUP_DESCRIPTION, '', 1);
		SET PARAM_ACC_GROUP_STATUS = `SYSTEM_VAR@REPLACE_NULL@TINYINT`(PARAM_ACC_GROUP_STATUS, 0, 1, 1);
		
	END IF;

	

	-- 6) PREPARE AUDIT TRAIL
	-- _______________________________________________________________________
	IF BINARY TEMP_ACC_GROUP_DESCRIPTION <> PARAM_ACC_GROUP_DESCRIPTION THEN
		SET TEMP_RECORD_CHANGES = 
		`SYSTEM_VAR@CONCAT_ADD`(' | ', TEMP_RECORD_CHANGES, CONCAT_WS(' ', 'Description: "', TEMP_ACC_GROUP_DESCRIPTION, '" > "', PARAM_ACC_GROUP_DESCRIPTION, '"'));
	END IF;
	IF TEMP_ACC_GROUP_STATUS <> PARAM_ACC_GROUP_STATUS THEN
		SET TEMP_RECORD_CHANGES = 
		`SYSTEM_VAR@CONCAT_ADD`(' | ', TEMP_RECORD_CHANGES, CONCAT_WS(' ', 'Status: "', TEMP_ACC_GROUP_STATUS, '" > "', PARAM_ACC_GROUP_STATUS, '"'));
	END IF;	
	IF TEMP_ACC_GROUP_SYSTEM_GENERATED <> PARAM_ACC_GROUP_SYSTEM_GENERATED THEN
		SET TEMP_RECORD_CHANGES = 
		`SYSTEM_VAR@CONCAT_ADD`(' | ', TEMP_RECORD_CHANGES, CONCAT_WS(' ', 'System Generated: "', TEMP_ACC_GROUP_SYSTEM_GENERATED, '" > "', PARAM_ACC_GROUP_SYSTEM_GENERATED, '"'));
	END IF;	
		
	-- No Changes in data, reject request
	-- ####################################################
	IF CHARACTER_LENGTH(TEMP_RECORD_CHANGES) = 0 THEN
		IF PARAM_SUPPRESS_RETURN = 0 THEN
			SELECT PARAM_ACC_GROUP_ID AS INSERTED_ID;
		END IF;
		LEAVE SP_SAVE;
	END IF;



	-- 7) VALIDATE
	-- _______________________________________________________________________

	-- Access Rights [Device]
	-- ####################################################
	IF `ACCOUNT_DEVICE@HAS_PERMISSION`(PARAM_REQUESTER_DEVICE_PUBLIC_KEY, PARAM_REQUESTER_DEVICE_PRIVATE_KEY) = 0 THEN
		SET TEMP_ERR_MESSAGE = 'Your device is not authorized yet to access this server.';
		SET ERR = `RAISERROR`(TEMP_ERR_MESSAGE);		
	END IF;
		
		
	-- Access Rights [Account]
	-- ####################################################
	IF 
		-- [ADD] Access Rights
		(
			TEMP_RECORD_EXISTS = 0 AND
			`ACCOUNT_ACCESS_RIGHTS@HAS_PERMISSION`(PARAM_REQUESTER_USERNAME, PARAM_REQUESTER_PASSWORD, 0, TEMP_MODULE_KEYWORD, 2) = 0 
		) OR
		
		-- [EDIT] Access Rights
		(
			TEMP_RECORD_EXISTS = 1 AND
			`ACCOUNT_ACCESS_RIGHTS@HAS_PERMISSION`(PARAM_REQUESTER_USERNAME, PARAM_REQUESTER_PASSWORD, 0, TEMP_MODULE_KEYWORD, 3) = 0 
		)
	THEN
		SET TEMP_ACCESS_RIGHTS_DENIED = 1;
		CALL `ACCOUNT_ACCESS_RIGHTS_DENY`
		(
			0, TEMP_MODULE_KEYWORD, PARAM_ACC_GROUP_ID, 0, TEMP_SP_OBJECTIVE, TEMP_RECORD_CHANGES, 
			PARAM_REQUESTER_USERNAME, PARAM_REQUESTER_PASSWORD, 
			PARAM_REQUESTER_PROXY_ID, PARAM_REQUESTER_PROXY_PASSWORD,
			PARAM_REQUESTER_DEVICE_PUBLIC_KEY, PARAM_REQUESTER_DEVICE_PRIVATE_KEY,
			PARAM_REQUESTER_IP, PARAM_UNIQUE_SESSION_ID,
			TEMP_SYNC_SERVER_ID, PARAM_SUPPRESS_RETURN
		);
	END IF;
	SET TEMP_ACCESS_RIGHTS_HAS_OVERRIDE = `ACCOUNT_ACCESS_RIGHTS@HAS_PERMISSION`(PARAM_REQUESTER_USERNAME, PARAM_REQUESTER_PASSWORD, 0, TEMP_MODULE_KEYWORD, 4);
	

	-- Validation
	-- ####################################################
	IF TEMP_SYNC_IS_SERVER_REQUEST = 0 THEN
	
		-- SYSTEM GENERATED = TRUE
		-- ...........................................
		IF TEMP_ACC_GROUP_SYSTEM_GENERATED = STATUS_ACTIVE THEN
		CALL `VALIDATION_SYSTEM_GENERATED`
		(
			PARAM_ACC_GROUP_ID,
			TEMP_ACC_GROUP_DESCRIPTION, ''
		);
		END IF;

		-- FOREIGN KEY EXISTS
		-- ...........................................
		
		-- FOREIGN (OPTIONAL)KEY EXISTS [Validates if not null]
		-- ...........................................
		
		-- IS_ALLOW_NULL = FALSE
		-- ...........................................
				
		-- IS_ALLOW_ZERO = FALSE
		-- ...........................................
		IF PARAM_ACC_GROUP_STATUS = 0 THEN
			CALL `VALIDATION_MISSING_FIELD`('`ACC_GROUP_STATUS`', '`NULL`');
		END IF;		
		IF PARAM_ACC_GROUP_SYSTEM_GENERATED = 0 THEN
			CALL `VALIDATION_MISSING_FIELD`('`ACC_GROUP_SYSTEM_GENERATED`', '`NULL`');
		END IF;		
		
		-- IS_ALLOW_NEGATIVE = FALSE
		-- ...........................................
		IF PARAM_ACC_GROUP_STATUS < 0 THEN
			CALL `VALIDATION_NEGATIVE`('`ACC_GROUP_STATUS`', PARAM_ACC_GROUP_STATUS);
		END IF;		
		IF PARAM_ACC_GROUP_SYSTEM_GENERATED < 0 THEN
			CALL `VALIDATION_NEGATIVE`('`ACC_GROUP_SYSTEM_GENERATED`', PARAM_ACC_GROUP_SYSTEM_GENERATED);
		END IF;		
		
		-- IS_ALLOW_EMPTY_STRING = FALSE
		-- ...........................................
		IF `SYSTEM_VAR@IS_NULL@NVARCHAR`(PARAM_ACC_GROUP_DESCRIPTION, 1) = 1 THEN
			CALL `VALIDATION_MISSING_FIELD`('`ACC_GROUP_DESCRIPTION`', '`NULL`');
		END IF;
		
		-- IS_STATUS
		-- ...........................................
		IF `SYSTEM_STATUS@SYS_STATUS_ID_EXISTS`(PARAM_ACC_GROUP_STATUS, 0) = 0 THEN
			SET TEMP_ERR_MESSAGE = CONCAT_WS(' ', 'Given STATUS[Status] does not exists or is inactive. ID: ', PARAM_ACC_GROUP_STATUS);
			SET ERR = `RAISERROR`(TEMP_ERR_MESSAGE);
		END IF;
		
		-- IS STATUS Active / Inactive
		-- ...........................................
		
		-- Minimum / Maximum Value
		-- ...........................................
		
		-- IS_UNIQUE = TRUE
		-- ...........................................
		
		-- RECORD IDENTIFIER
		-- ...........................................
		
		
		-- ON_UPDATE VALIDATION 
		-- ...........................................
		IF TEMP_RECORD_EXISTS = 1 THEN	
		
			-- Just to keep at least one line within condition
			SET TEMP_RECORD_EXISTS = 1;
			
		END IF;
		
	END IF;



	-- 8) INSERT / UPDATE
	-- _______________________________________________________________________

	-- INSERT NEW DATA
	-- ####################################################
	IF TEMP_RECORD_EXISTS = 0 THEN

		INSERT INTO
		`account_group`
		(
			`account_group`.`ACC_GROUP_DESCRIPTION`, 
			`account_group`.`ACC_GROUP_STATUS`, 
			`account_group`.`ACC_GROUP_SYSTEM_GENERATED`
		)
		VALUES
		(
			PARAM_ACC_GROUP_DESCRIPTION, 
			PARAM_ACC_GROUP_STATUS, 
			PARAM_ACC_GROUP_SYSTEM_GENERATED
		);	
		
		-- Update Audit trail with new ID	
		SET PARAM_ACC_GROUP_ID = LAST_INSERT_ID();

		CALL `ADDON_LICENSE_GROUP_SAVE`
		(
			0,
			PARAM_ACC_GROUP_ID,
			TEMP_NOW,
			'1900-01-01 00:00:00.000000',
			0,
			STATUS_ACTIVE,

			PARAM_REQUESTER_USERNAME,
			PARAM_REQUESTER_PASSWORD,
			PARAM_REQUESTER_PROXY_ID,
			PARAM_REQUESTER_PROXY_PASSWORD,
			PARAM_REQUESTER_DEVICE_PUBLIC_KEY,
			PARAM_REQUESTER_DEVICE_PRIVATE_KEY,
			
			PARAM_REQUESTER_IP,
			PARAM_UNIQUE_SESSION_ID,
			1,
			
			PARAM_SYNC_SERVER_DESCRIPTION, 
			PARAM_SYNC_SERVER_UNIQUE_KEY
		);
		

	-- UPDATING EXISTING RECORD
	-- ####################################################
	ELSE
		UPDATE `account_group`
		SET
			`account_group`.`ACC_GROUP_DESCRIPTION` = PARAM_ACC_GROUP_DESCRIPTION, 
			`account_group`.`ACC_GROUP_STATUS` = PARAM_ACC_GROUP_STATUS, 
			`account_group`.`ACC_GROUP_SYSTEM_GENERATED` = PARAM_ACC_GROUP_SYSTEM_GENERATED
		WHERE
			`account_group`.`ACC_GROUP_ID` = PARAM_ACC_GROUP_ID;

	END IF;

	
	-- 9) AUDIT TRAIL
	-- _______________________________________________________________________
	CALL `ACCOUNT_AUDIT_TRAIL_SAVE`
	(
		0, TEMP_MODULE_KEYWORD, PARAM_ACC_GROUP_ID, 0, 'SAVE', TEMP_SP_OBJECTIVE, TEMP_RECORD_CHANGES, 
		PARAM_REQUESTER_USERNAME, PARAM_REQUESTER_PASSWORD, 
		PARAM_REQUESTER_PROXY_ID, PARAM_REQUESTER_PROXY_PASSWORD,
		PARAM_REQUESTER_DEVICE_PUBLIC_KEY, PARAM_REQUESTER_DEVICE_PRIVATE_KEY,
		PARAM_REQUESTER_IP, PARAM_UNIQUE_SESSION_ID,
		TEMP_SYNC_SERVER_ID, PARAM_SUPPRESS_RETURN
	);
	

	-- 10) RETURN RESULT
	-- _______________________________________________________________________
	IF PARAM_SUPPRESS_RETURN = 0 THEN
		SELECT PARAM_ACC_GROUP_ID AS INSERTED_ID,
		`ADDON_LICENSE_GROUP@ID_FROM_ACC_GROUP_ID`(PARAM_ACC_GROUP_ID) AS ADD_GLICENSE_ID;
	END IF;
	LEAVE SP_SAVE;


END ;;
DELIMITER ;
/*!50003 SET sql_mode              = @saved_sql_mode */ ;
/*!50003 SET character_set_client  = @saved_cs_client */ ;
/*!50003 SET character_set_results = @saved_cs_results */ ;
/*!50003 SET collation_connection  = @saved_col_connection */ ;
/*!50003 DROP PROCEDURE IF EXISTS `ACCOUNT_LEVEL_DELETE` */;
/*!50003 SET @saved_cs_client      = @@character_set_client */ ;
/*!50003 SET @saved_cs_results     = @@character_set_results */ ;
/*!50003 SET @saved_col_connection = @@collation_connection */ ;
/*!50003 SET character_set_client  = latin1 */ ;
/*!50003 SET character_set_results = latin1 */ ;
/*!50003 SET collation_connection  = latin1_swedish_ci */ ;
/*!50003 SET @saved_sql_mode       = @@sql_mode */ ;
/*!50003 SET sql_mode              = '' */ ;
DELIMITER ;;
CREATE DEFINER=`root`@`localhost` PROCEDURE `ACCOUNT_LEVEL_DELETE`(
	IN `PARAM_ACC_LEVEL_ID` BIGINT,
	IN `PARAM_ACC_LEVEL_SERVER_ID` BIGINT,
	
	IN `PARAM_REQUESTER_USERNAME` VARCHAR(500),
	IN `PARAM_REQUESTER_PASSWORD` VARCHAR(500),
	IN `PARAM_REQUESTER_PROXY_ID` BIGINT,
	IN `PARAM_REQUESTER_PROXY_PASSWORD` VARCHAR(1000),
	IN `PARAM_REQUESTER_DEVICE_PUBLIC_KEY` VARCHAR(1000),
	IN `PARAM_REQUESTER_DEVICE_PRIVATE_KEY` VARCHAR(1000),
	
	IN `PARAM_REQUESTER_IP` VARCHAR(1000),
	IN `PARAM_UNIQUE_SESSION_ID` VARCHAR(1000),
	IN `PARAM_SUPPRESS_RETURN` BIT,
	
	IN `PARAM_SYNC_SERVER_DESCRIPTION` VARCHAR(500), 
	IN `PARAM_SYNC_SERVER_UNIQUE_KEY` VARCHAR(500)
)
SP_DELETE:
BEGIN

	-- 1) DECLARE LOCAL PARAMETERS
	-- ====================================================================================================================================================================
	-- Audit Handler
	DECLARE TEMP_RECORD_EXISTS BIT DEFAULT `ACCOUNT_LEVEL@ACC_LEVEL_ID_EXISTS`(PARAM_ACC_LEVEL_ID, 0);
	DECLARE TEMP_MODULE_KEYWORD VARCHAR(500) DEFAULT 'account_level';
	DECLARE TEMP_SP_OBJECTIVE VARCHAR(500) DEFAULT 'delete Access level record';
	DECLARE TEMP_ERR_MESSAGE VARCHAR(500) DEFAULT '';
	DECLARE ERR BIGINT DEFAULT 0;
	DECLARE TEMP_RECORD_CHANGES VARCHAR(16000) DEFAULT '';
	DECLARE TEMP_RECORD_BINDED BIT DEFAULT 0;

	-- Authentication
	DECLARE TEMP_ACCESS_RIGHTS_DENIED BIT DEFAULT 0;
	DECLARE TEMP_SYNC_SERVER_ID BIGINT DEFAULT 0;
	DECLARE TEMP_SYNC_IS_SERVER_REQUEST BIT DEFAULT 0;
	DECLARE TEMP_AUTHENTICATED_ACCOUNT_ID BIGINT DEFAULT `ACCOUNT_MEMBER@ACC_ACCOUNT_ID_FROM_LOGIN`(PARAM_REQUESTER_USERNAME, PARAM_REQUESTER_PASSWORD);
	DECLARE TEMP_AUTHENTICATED_ACCOUNT_LEVEL BIGINT DEFAULT 0;

	-- Local value holder
	DECLARE TEMP_ACC_LEVEL_SERVER_ID BIGINT DEFAULT 0;
	DECLARE TEMP_ACC_LEVEL_TAG_ID BIGINT DEFAULT 0;
	DECLARE TEMP_ACC_LEVEL_DESCRIPTION VARCHAR(16000) DEFAULT '';
	DECLARE TEMP_ACC_LEVEL_STATUS TINYINT DEFAULT 0;
	DECLARE TEMP_ACC_LEVEL_SYSTEM_GENERATED TINYINT DEFAULT 0;
	-- ====================================================================================================================================================================
	
	
	-- 2) Try Catch / Throw
	-- ====================================================================================================================================================================
	DECLARE EXIT HANDLER FOR SQLEXCEPTION
	BEGIN
		RESIGNAL;
	END;
	-- ====================================================================================================================================================================
	
	
	-- 3) IF ALREADY EXIST, FILL MISSING DATA
	-- ====================================================================================================================================================================
	IF TEMP_RECORD_EXISTS = 1 THEN
	
		SELECT
			`account_level`.`ACC_LEVEL_SERVER_ID`,
			`account_level`.`ACC_LEVEL_TAG_ID`,
			`account_level`.`ACC_LEVEL_DESCRIPTION`,
			`account_level`.`ACC_LEVEL_STATUS`,
			`account_level`.`ACC_LEVEL_SYSTEM_GENERATED`
		INTO
			TEMP_ACC_LEVEL_SERVER_ID,
			TEMP_ACC_LEVEL_TAG_ID,
			TEMP_ACC_LEVEL_DESCRIPTION,
			TEMP_ACC_LEVEL_STATUS,
			TEMP_ACC_LEVEL_SYSTEM_GENERATED
			
		FROM `account_level`
		WHERE
			`account_level`.`ACC_LEVEL_ID` = PARAM_ACC_LEVEL_ID
		LIMIT 1;
		
	ELSE
		SET TEMP_ERR_MESSAGE = CONCAT_WS(' ', 'Given LEVEL does not exists or is inactive. ID: ', PARAM_ACC_LEVEL_ID);
		SET ERR = `RAISERROR`(TEMP_ERR_MESSAGE);			
	END IF;
	-- ====================================================================================================================================================================


	-- 4) PREPARE AUDIT TRAIL
	-- ====================================================================================================================================================================

	SET TEMP_RECORD_CHANGES = 
	`SYSTEM_VAR@CONCAT_ADD`(' | ', TEMP_RECORD_CHANGES, CONCAT_WS(' ', 'LEVEL SERVER ID:"', TEMP_ACC_LEVEL_SERVER_ID, '" > "`DELETE`"'));

	SET TEMP_RECORD_CHANGES = 
	`SYSTEM_VAR@CONCAT_ADD`(' | ', TEMP_RECORD_CHANGES, CONCAT_WS(' ', 'DESCRIPTION:"', TEMP_ACC_LEVEL_DESCRIPTION, '" > "`DELETE`"'));

	SET TEMP_RECORD_CHANGES = 
	`SYSTEM_VAR@CONCAT_ADD`
	(
		' | ', TEMP_RECORD_CHANGES, CONCAT_WS
		(
			' ',
			'STATUS:', TEMP_ACC_LEVEL_STATUS,
			' > `DELETE`'
		)
	);
	-- ====================================================================================================================================================================
	
	
	-- 5) VALIDATE
	-- ====================================================================================================================================================================
	
	-- Access Rights [Device]
	-- ####################################################
	IF `ACCOUNT_DEVICE@HAS_PERMISSION`(PARAM_REQUESTER_DEVICE_PUBLIC_KEY, PARAM_REQUESTER_DEVICE_PRIVATE_KEY) = 0 THEN
		SET TEMP_ERR_MESSAGE = 'Your device is not authorized yet to access this server.';
		SET ERR = `RAISERROR`(TEMP_ERR_MESSAGE);		
	END IF;
		
		
	-- Access Rights [Account]
	-- ####################################################
	IF `ACCOUNT_ACCESS_RIGHTS@HAS_PERMISSION`(PARAM_REQUESTER_USERNAME, PARAM_REQUESTER_PASSWORD, 0, TEMP_MODULE_KEYWORD, 4) = 0 THEN
		SET TEMP_ACCESS_RIGHTS_DENIED = 1;
		CALL `ACCOUNT_ACCESS_RIGHTS_DENY`
		(
			0, TEMP_MODULE_KEYWORD, PARAM_ACC_LEVEL_ID, TEMP_ACC_LEVEL_SERVER_ID, TEMP_SP_OBJECTIVE, TEMP_RECORD_CHANGES, 
			PARAM_REQUESTER_USERNAME, PARAM_REQUESTER_PASSWORD, 
			PARAM_REQUESTER_PROXY_ID, PARAM_REQUESTER_PROXY_PASSWORD,
			PARAM_REQUESTER_DEVICE_PUBLIC_KEY, PARAM_REQUESTER_DEVICE_PRIVATE_KEY,
			PARAM_REQUESTER_IP, PARAM_UNIQUE_SESSION_ID,
			TEMP_SYNC_SERVER_ID, PARAM_SUPPRESS_RETURN
		);
	END IF;
	
	-- Level validation
	-- ####################################################
	IF `ACCOUNT_LEVEL@ACC_LEVEL_ID_EXISTS`(PARAM_ACC_LEVEL_ID, 0) = 0 THEN
		SET TEMP_ERR_MESSAGE = CONCAT_WS(' ', 'Given level does not exists or is inactive.', PARAM_ACC_LEVEL_ID, '(', `ACCOUNT_LEVEL@ACC_LEVEL_DESCRIPTION_FROM_ID`(PARAM_ACC_LEVEL_ID), ')');
		SET ERR = `RAISERROR`(TEMP_ERR_MESSAGE);
	END IF;

	-- SYSTEM_GENERATED
	-- ####################################################
	IF TEMP_ACC_LEVEL_SYSTEM_GENERATED = 2 THEN
		CALL `VALIDATION_SYSTEM_GENERATED`(PARAM_ACC_LEVEL_ID, TEMP_ACC_LEVEL_DESCRIPTION, '');
	END IF;

	-- MEMBER is linked with other data
	-- ####################################################
	IF 
	(
			SELECT COUNT(`account_member`.`ACC_ACCOUNT_ACC_LEVEL_ID`)
			FROM `account_member`
			WHERE
				`account_member`.`ACC_ACCOUNT_ACC_LEVEL_ID` = PARAM_ACC_LEVEL_ID
			LIMIT 1
	) >= 1
	THEN
		SET TEMP_ERR_MESSAGE = TEMP_ACC_LEVEL_DESCRIPTION;
		CALL `VALIDATION_DELETE_LINKED_RECORD`('level', PARAM_ACC_LEVEL_ID, TEMP_ERR_MESSAGE);
	END IF;
	
	-- Should not edit own level
	-- ####################################################
	IF PARAM_ACC_LEVEL_ID = TEMP_AUTHENTICATED_ACCOUNT_LEVEL THEN
		SET TEMP_ERR_MESSAGE = 'You cannot edit your own access level.';
		SET ERR = `RAISERROR`(TEMP_ERR_MESSAGE);	
	END IF;

	-- Has Enough authority to assign AR for this level (or-override)
	-- ####################################################
	IF
		`ACCOUNT_ACCESS_RIGHTS@HAS_PERMISSION`(PARAM_REQUESTER_USERNAME, PARAM_REQUESTER_PASSWORD, 0, TEMP_MODULE_KEYWORD, 5) = 0 AND 
		`ACCOUNT_LEVEL@EDIT_HAS_PERMISSION`
		(
			PARAM_ACC_LEVEL_ID,
		
			PARAM_REQUESTER_USERNAME,
			PARAM_REQUESTER_PASSWORD
		) = 0 
	THEN
		SET TEMP_ERR_MESSAGE = 'You cannot access to account or settings assigned to higher authority.';
		SET ERR = `RAISERROR`(TEMP_ERR_MESSAGE);	
	END IF;
	-- ====================================================================================================================================================================

	
	-- 6) DELETE
	-- ====================================================================================================================================================================
		
	DELETE FROM `account_access_rights`
	WHERE `account_access_rights`.`ACC_ACCESS_ACC_LEVEL_ID` = PARAM_ACC_LEVEL_ID;

	DELETE FROM `account_level`
	WHERE `account_level`.`ACC_LEVEL_ID` = PARAM_ACC_LEVEL_ID
	LIMIT 1;

	-- ====================================================================================================================================================================


	-- 7) AUDIT TRAIL
	-- ====================================================================================================================================================================
	CALL `ACCOUNT_AUDIT_TRAIL_SAVE`
	(
		0, TEMP_MODULE_KEYWORD, PARAM_ACC_LEVEL_ID, TEMP_ACC_LEVEL_SERVER_ID, 'DELETE', TEMP_SP_OBJECTIVE, TEMP_RECORD_CHANGES, 
		PARAM_REQUESTER_USERNAME, PARAM_REQUESTER_PASSWORD, 
		PARAM_REQUESTER_PROXY_ID, PARAM_REQUESTER_PROXY_PASSWORD,
		PARAM_REQUESTER_DEVICE_PUBLIC_KEY, PARAM_REQUESTER_DEVICE_PRIVATE_KEY,
		PARAM_REQUESTER_IP, PARAM_UNIQUE_SESSION_ID,
		TEMP_SYNC_SERVER_ID, PARAM_SUPPRESS_RETURN
	);
	-- ====================================================================================================================================================================
	
END ;;
DELIMITER ;
/*!50003 SET sql_mode              = @saved_sql_mode */ ;
/*!50003 SET character_set_client  = @saved_cs_client */ ;
/*!50003 SET character_set_results = @saved_cs_results */ ;
/*!50003 SET collation_connection  = @saved_col_connection */ ;
/*!50003 DROP PROCEDURE IF EXISTS `ACCOUNT_LEVEL_GET` */;
/*!50003 SET @saved_cs_client      = @@character_set_client */ ;
/*!50003 SET @saved_cs_results     = @@character_set_results */ ;
/*!50003 SET @saved_col_connection = @@collation_connection */ ;
/*!50003 SET character_set_client  = latin1 */ ;
/*!50003 SET character_set_results = latin1 */ ;
/*!50003 SET collation_connection  = latin1_swedish_ci */ ;
/*!50003 SET @saved_sql_mode       = @@sql_mode */ ;
/*!50003 SET sql_mode              = '' */ ;
DELIMITER ;;
CREATE DEFINER=`root`@`localhost` PROCEDURE `ACCOUNT_LEVEL_GET`(
	IN `PARAM_ACC_LEVEL_ID` BIGINT,
	IN `PARAM_ACC_LEVEL_SERVER_ID` BIGINT,
	
	IN `PARAM_ACC_LEVEL_TAG_ID` BIGINT,
	IN `PARAM_ACC_LEVEL_DESCRIPTION` VARCHAR(1000),
	IN `PARAM_ACC_LEVEL_STATUS` TINYINT,
	IN `PARAM_ACC_LEVEL_SYSTEM_GENERATED` TINYINT,
	
	IN `PARAM_ORDER_FIELD` VARCHAR(500),
	IN `PARAM_ORDER_TYPE` VARCHAR(500),
	IN `PARAM_SKIP` BIGINT,
	IN `PARAM_LIMIT` BIGINT,

	IN `PARAM_REQUESTER_USERNAME` VARCHAR(500),
	IN `PARAM_REQUESTER_PASSWORD` VARCHAR(500),
	IN `PARAM_REQUESTER_PROXY_ID` BIGINT,
	IN `PARAM_REQUESTER_PROXY_PASSWORD` VARCHAR(1000),
	IN `PARAM_REQUESTER_DEVICE_PUBLIC_KEY` VARCHAR(1000),
	IN `PARAM_REQUESTER_DEVICE_PRIVATE_KEY` VARCHAR(1000),
	
	IN `PARAM_REQUESTER_IP` VARCHAR(1000),
	IN `PARAM_UNIQUE_SESSION_ID` VARCHAR(1000),
	IN `PARAM_SUPPRESS_RETURN` BIT
)
SP_GET:
BEGIN

	-- Initialize
	-- ========================================================================
	
	-- Status
	-- ...........................................
	DECLARE STATUS_INACTIVE TINYINT DEFAULT 1;
	DECLARE STATUS_ACTIVE TINYINT DEFAULT 2;
	DECLARE STATUS_CLOSED TINYINT DEFAULT 3;
	DECLARE STATUS_COMPLETED TINYINT DEFAULT 4;
		
	-- Audit Handler
	-- ...........................................
	DECLARE TEMP_MODULE_KEYWORD VARCHAR(500) DEFAULT 'account_level';
	DECLARE TEMP_SP_OBJECTIVE VARCHAR(500) DEFAULT 'retrieve access level record';
	DECLARE TEMP_ERR_MESSAGE VARCHAR(500) DEFAULT '';
	DECLARE ERR BIGINT DEFAULT 0;
	DECLARE TEMP_RECORD_CHANGES VARCHAR(16000) DEFAULT '';

	-- Authentication
	-- ...........................................
	DECLARE TEMP_ACCESS_RIGHTS_DENIED BIT DEFAULT 0;
	DECLARE TEMP_AUTHENTICATED_ACCOUNT_ID BIGINT DEFAULT `ACCOUNT_MEMBER@ACC_ACCOUNT_ID_FROM_LOGIN`(PARAM_REQUESTER_USERNAME, PARAM_REQUESTER_PASSWORD);
	DECLARE TEMP_AUTHENTICATED_ACCOUNT_LEVEL BIGINT DEFAULT `ACCOUNT_MEMBER@ACC_ACCOUNT_LEVEL_FROM_LOGIN`(PARAM_REQUESTER_USERNAME, PARAM_REQUESTER_PASSWORD);
	
	-- Check NULLs
	-- ...........................................
	-- ACCOUNT
	DECLARE IS_NULL_ACC_LEVEL_ID BIT DEFAULT `SYSTEM_VAR@IS_NULL@BIGINT`(PARAM_ACC_LEVEL_ID, 1, 1);
	DECLARE IS_NULL_ACC_LEVEL_SERVER_ID BIT DEFAULT `SYSTEM_VAR@IS_NULL@BIGINT`(PARAM_ACC_LEVEL_SERVER_ID, 1, 1);
	
	DECLARE IS_NULL_ACC_LEVEL_TAG_ID BIT DEFAULT `SYSTEM_VAR@IS_NULL@BIGINT`(PARAM_ACC_LEVEL_TAG_ID, 1, 1);
	DECLARE IS_NULL_ACC_LEVEL_DESCRIPTION BIT DEFAULT `SYSTEM_VAR@IS_NULL@NVARCHAR`(PARAM_ACC_LEVEL_DESCRIPTION, 1);
	DECLARE IS_NULL_ACC_LEVEL_STATUS BIT DEFAULT `SYSTEM_VAR@IS_NULL@TINYINT`(PARAM_ACC_LEVEL_STATUS, 1, 1);
	DECLARE IS_NULL_SYSTEM_GENERATED BIT DEFAULT `SYSTEM_VAR@IS_NULL@TINYINT`(PARAM_ACC_LEVEL_SYSTEM_GENERATED, 1, 1);
	
	
	-- Error Handler
	-- =========================================================================================
	DECLARE EXIT HANDLER FOR SQLEXCEPTION
	BEGIN
		RESIGNAL;
	END;
	
	
	-- Access Rights [Device]
	-- _______________________________________________________________________
	IF `ACCOUNT_DEVICE@HAS_PERMISSION`(PARAM_REQUESTER_DEVICE_PUBLIC_KEY, PARAM_REQUESTER_DEVICE_PRIVATE_KEY) = 0 THEN
		SET TEMP_ERR_MESSAGE = 'Your device is not authorized yet to access this server.';
		SET ERR = `RAISERROR`(TEMP_ERR_MESSAGE);		
	END IF;
		
		
	-- Access Rights [Account]
	-- _______________________________________________________________________
	IF `ACCOUNT_ACCESS_RIGHTS@HAS_PERMISSION`(PARAM_REQUESTER_USERNAME, PARAM_REQUESTER_PASSWORD, 0, TEMP_MODULE_KEYWORD, 1) = 0 THEN
		CALL `ACCOUNT_ACCESS_RIGHTS_DENY`
		(
			0, TEMP_MODULE_KEYWORD, PARAM_ACC_LEVEL_ID, 0, TEMP_SP_OBJECTIVE, '', 
			PARAM_REQUESTER_USERNAME, PARAM_REQUESTER_PASSWORD, 
			PARAM_REQUESTER_PROXY_ID, PARAM_REQUESTER_PROXY_PASSWORD,
			PARAM_REQUESTER_DEVICE_PUBLIC_KEY, PARAM_REQUESTER_DEVICE_PRIVATE_KEY,
			PARAM_REQUESTER_IP, PARAM_UNIQUE_SESSION_ID,
			0, PARAM_SUPPRESS_RETURN
		);
	END IF;


	-- SELECT ACCOUNTS
	-- =========================================================================================
	SELECT
		-- ACCESS LEVEL
		`account_level`.`ACC_LEVEL_ID`,
		`account_level`.`ACC_LEVEL_SERVER_ID`,
		
		`account_level`.`ACC_LEVEL_TAG_ID`,
		`account_level`.`ACC_LEVEL_DESCRIPTION`,
		`account_level`.`ACC_LEVEL_STATUS`,
		`account_level`.`ACC_LEVEL_SYSTEM_GENERATED`,

		-- STATUS
		`system_status`.`SYS_STATUS_DESCRIPTION`,
		`system_status`.`SYS_STATUS_STATUS`

	FROM `account_level`
		INNER JOIN `system_status` ON
		`system_status`.`SYS_STATUS_ID` = `account_level`.`ACC_LEVEL_STATUS`
			
	-- CONDITIONS
	-- =========================================================================================
	WHERE
		(
			IS_NULL_ACC_LEVEL_ID = 1 OR
			`account_level`.`ACC_LEVEL_ID` = PARAM_ACC_LEVEL_ID
		) AND
		(
			IS_NULL_ACC_LEVEL_SERVER_ID = 1 OR
			`account_level`.`ACC_LEVEL_SERVER_ID` = PARAM_ACC_LEVEL_SERVER_ID
		) AND
		(
			IS_NULL_ACC_LEVEL_TAG_ID = 1 OR
			`account_level`.`ACC_LEVEL_TAG_ID` = PARAM_ACC_LEVEL_TAG_ID
		) AND
		(
			IS_NULL_ACC_LEVEL_DESCRIPTION = 1 OR
			`account_level`.`ACC_LEVEL_DESCRIPTION` LIKE CONCAT_WS('%', '', PARAM_ACC_LEVEL_DESCRIPTION, '')
		) AND
		(
			IS_NULL_ACC_LEVEL_STATUS = 1 OR
			`account_level`.`ACC_LEVEL_STATUS` = PARAM_ACC_LEVEL_STATUS
		) AND
		(
			PARAM_ACC_LEVEL_SYSTEM_GENERATED = 0 OR
			`account_level`.`ACC_LEVEL_SYSTEM_GENERATED` = PARAM_ACC_LEVEL_SYSTEM_GENERATED
		)

	-- ORDER BY
	-- =========================================================================================
	ORDER BY
		-- LEVEL
		CASE WHEN PARAM_ORDER_FIELD = 'ACC_LEVEL_ID' AND PARAM_ORDER_TYPE = 'ASC' THEN `account_level`.`ACC_LEVEL_ID` END ASC, 
		CASE WHEN PARAM_ORDER_FIELD = 'ACC_LEVEL_ID' AND PARAM_ORDER_TYPE = 'DESC' THEN `account_level`.`ACC_LEVEL_ID` END DESC,	
		CASE WHEN PARAM_ORDER_FIELD = 'ACC_LEVEL_SERVER_ID' AND PARAM_ORDER_TYPE = 'ASC' THEN `account_level`.`ACC_LEVEL_SERVER_ID` END ASC, 
		CASE WHEN PARAM_ORDER_FIELD = 'ACC_LEVEL_SERVER_ID' AND PARAM_ORDER_TYPE = 'DESC' THEN `account_level`.`ACC_LEVEL_SERVER_ID` END DESC,	
		
		CASE WHEN PARAM_ORDER_FIELD = 'ACC_LEVEL_TAG_ID' AND PARAM_ORDER_TYPE = 'ASC' THEN `account_level`.`ACC_LEVEL_TAG_ID` END ASC, 
		CASE WHEN PARAM_ORDER_FIELD = 'ACC_LEVEL_TAG_ID' AND PARAM_ORDER_TYPE = 'DESC' THEN `account_level`.`ACC_LEVEL_TAG_ID` END DESC,	
		CASE WHEN PARAM_ORDER_FIELD = 'ACC_LEVEL_DESCRIPTION' AND PARAM_ORDER_TYPE = 'ASC' THEN `account_level`.`ACC_LEVEL_DESCRIPTION` END ASC, 
		CASE WHEN PARAM_ORDER_FIELD = 'ACC_LEVEL_DESCRIPTION' AND PARAM_ORDER_TYPE = 'DESC' THEN `account_level`.`ACC_LEVEL_DESCRIPTION` END DESC,	

		-- STATUS
		CASE WHEN PARAM_ORDER_FIELD = 'SYS_STATUS_DESCRIPTION' AND PARAM_ORDER_TYPE = 'ASC' THEN `system_status`.`SYS_STATUS_DESCRIPTION` END ASC, 
		CASE WHEN PARAM_ORDER_FIELD = 'SYS_STATUS_DESCRIPTION' AND PARAM_ORDER_TYPE = 'DESC' THEN `system_status`.`SYS_STATUS_DESCRIPTION` END DESC,
								
		-- EXTRA
		CASE WHEN PARAM_ORDER_FIELD <> 'ACC_LEVEL_DESCRIPTION' THEN `account_level`.`ACC_LEVEL_DESCRIPTION` END ASC
																											
	LIMIT PARAM_SKIP, PARAM_LIMIT;
	LEAVE SP_GET;
			
END ;;
DELIMITER ;
/*!50003 SET sql_mode              = @saved_sql_mode */ ;
/*!50003 SET character_set_client  = @saved_cs_client */ ;
/*!50003 SET character_set_results = @saved_cs_results */ ;
/*!50003 SET collation_connection  = @saved_col_connection */ ;
/*!50003 DROP PROCEDURE IF EXISTS `ACCOUNT_LEVEL_SAVE` */;
/*!50003 SET @saved_cs_client      = @@character_set_client */ ;
/*!50003 SET @saved_cs_results     = @@character_set_results */ ;
/*!50003 SET @saved_col_connection = @@collation_connection */ ;
/*!50003 SET character_set_client  = latin1 */ ;
/*!50003 SET character_set_results = latin1 */ ;
/*!50003 SET collation_connection  = latin1_swedish_ci */ ;
/*!50003 SET @saved_sql_mode       = @@sql_mode */ ;
/*!50003 SET sql_mode              = '' */ ;
DELIMITER ;;
CREATE DEFINER=`root`@`localhost` PROCEDURE `ACCOUNT_LEVEL_SAVE`(
	IN `PARAM_ACC_LEVEL_ID` BIGINT,
	IN `PARAM_ACC_LEVEL_SERVER_ID` BIGINT,
	
	IN `PARAM_ACC_LEVEL_TAG_ID` BIGINT,
	IN `PARAM_ACC_LEVEL_DESCRIPTION` VARCHAR(1000),
	IN `PARAM_ACC_LEVEL_STATUS` TINYINT,

	IN `PARAM_REQUESTER_USERNAME` VARCHAR(500),
	IN `PARAM_REQUESTER_PASSWORD` VARCHAR(500),
	IN `PARAM_REQUESTER_PROXY_ID` BIGINT,
	IN `PARAM_REQUESTER_PROXY_PASSWORD` VARCHAR(1000),
	IN `PARAM_REQUESTER_DEVICE_PUBLIC_KEY` VARCHAR(1000),
	IN `PARAM_REQUESTER_DEVICE_PRIVATE_KEY` VARCHAR(1000),
	
	IN `PARAM_REQUESTER_IP` VARCHAR(1000),
	IN `PARAM_UNIQUE_SESSION_ID` VARCHAR(1000),
	IN `PARAM_SUPPRESS_RETURN` BIT,
	
	IN `PARAM_SYNC_SERVER_DESCRIPTION` VARCHAR(500), 
	IN `PARAM_SYNC_SERVER_UNIQUE_KEY` VARCHAR(500)
)
SP_SAVE:
BEGIN

	-- 1) DECLARE LOCAL PARAMETERS
	-- ====================================================================================================================================================================
	
	-- Status
	-- ...........................................
	DECLARE STATUS_INACTIVE TINYINT DEFAULT 1;
	DECLARE STATUS_ACTIVE TINYINT DEFAULT 2;
	DECLARE STATUS_CLOSED TINYINT DEFAULT 3;
	DECLARE STATUS_COMPLETED TINYINT DEFAULT 4;	
		
	-- Audit Handler
	-- ...........................................
	DECLARE TEMP_RECORD_EXISTS BIT DEFAULT `ACCOUNT_LEVEL@ACC_LEVEL_ID_EXISTS`(PARAM_ACC_LEVEL_ID, 0);
	DECLARE TEMP_MODULE_KEYWORD VARCHAR(500) DEFAULT 'account_level';
	DECLARE TEMP_SP_OBJECTIVE VARCHAR(500) DEFAULT 'add/edit Access level record';
	DECLARE TEMP_ERR_MESSAGE VARCHAR(500) DEFAULT '';
	DECLARE ERR BIGINT DEFAULT 0;
	DECLARE TEMP_RECORD_CHANGES VARCHAR(16000) DEFAULT '';
	DECLARE TEMP_RECORD_BINDED BIT DEFAULT 0;
	
	-- Authentication
	-- ...........................................
	DECLARE TEMP_ACCESS_RIGHTS_DENIED BIT DEFAULT 0;
	DECLARE TEMP_SYNC_SERVER_ID BIGINT DEFAULT 0;
	DECLARE TEMP_SYNC_IS_SERVER_REQUEST BIT DEFAULT 0;
	DECLARE TEMP_AUTHENTICATED_ACCOUNT_ID BIGINT DEFAULT `ACCOUNT_MEMBER@ACC_ACCOUNT_ID_FROM_LOGIN`(PARAM_REQUESTER_USERNAME, PARAM_REQUESTER_PASSWORD);
	DECLARE TEMP_AUTHENTICATED_ACCOUNT_LEVEL BIGINT DEFAULT 0;

	DECLARE TEMP_NOW DATETIME(6) DEFAULT `SYSTEM_VAR@NOW`('', 1);
	
	-- Local value holder
	-- ...........................................
	DECLARE TEMP_ACC_LEVEL_SERVER_ID BIGINT DEFAULT 0;
	DECLARE TEMP_ACC_LEVEL_TAG_ID BIGINT DEFAULT 0;
	DECLARE TEMP_ACC_LEVEL_DESCRIPTION VARCHAR(16000) DEFAULT '';
	DECLARE TEMP_ACC_LEVEL_STATUS TINYINT DEFAULT 0;
	DECLARE PARAM_ACC_LEVEL_SYSTEM_GENERATED TINYINT DEFAULT 0;
	DECLARE TEMP_ACC_LEVEL_SYSTEM_GENERATED TINYINT DEFAULT 0;
	
	-- ====================================================================================================================================================================

	
	-- 2) Try Catch / Throw
	-- ====================================================================================================================================================================
	DECLARE EXIT HANDLER FOR SQLEXCEPTION
	BEGIN
		RESIGNAL;
	END;
	-- ====================================================================================================================================================================

	
	-- 3) IF ALREADY EXIST, FILL MISSING DATA
	-- ====================================================================================================================================================================
	IF TEMP_RECORD_EXISTS = 1 THEN

		SELECT
			`account_level`.`ACC_LEVEL_SERVER_ID`,
			`account_level`.`ACC_LEVEL_TAG_ID`,
			`account_level`.`ACC_LEVEL_DESCRIPTION`,
			`account_level`.`ACC_LEVEL_STATUS`,
			`account_level`.`ACC_LEVEL_SYSTEM_GENERATED`
		INTO
			TEMP_ACC_LEVEL_SERVER_ID,
			TEMP_ACC_LEVEL_TAG_ID,
			TEMP_ACC_LEVEL_DESCRIPTION,
			TEMP_ACC_LEVEL_STATUS,
			TEMP_ACC_LEVEL_SYSTEM_GENERATED
		FROM `account_level`
		WHERE
			`account_level`.`ACC_LEVEL_ID` = PARAM_ACC_LEVEL_ID
		LIMIT 1;

		
		SET PARAM_ACC_LEVEL_SERVER_ID = `SYSTEM_VAR@REPLACE_NULL@BIGINT`(PARAM_ACC_LEVEL_SERVER_ID, TEMP_ACC_LEVEL_SERVER_ID, 1, 1);
		SET PARAM_ACC_LEVEL_TAG_ID = `SYSTEM_VAR@REPLACE_NULL@BIGINT`(PARAM_ACC_LEVEL_TAG_ID, TEMP_ACC_LEVEL_TAG_ID, 1, 1);
		SET PARAM_ACC_LEVEL_DESCRIPTION = `SYSTEM_VAR@REPLACE_NULL@NVARCHAR`(PARAM_ACC_LEVEL_DESCRIPTION, TEMP_ACC_LEVEL_DESCRIPTION, 1);
		SET PARAM_ACC_LEVEL_STATUS = `SYSTEM_VAR@REPLACE_NULL@TINYINT`(PARAM_ACC_LEVEL_STATUS, TEMP_ACC_LEVEL_STATUS, 1, 1);
		SET PARAM_ACC_LEVEL_SYSTEM_GENERATED = `SYSTEM_VAR@REPLACE_NULL@TINYINT`(PARAM_ACC_LEVEL_SYSTEM_GENERATED, TEMP_ACC_LEVEL_SYSTEM_GENERATED, 1, 1);
	
	ELSE
		SET PARAM_ACC_LEVEL_SERVER_ID = `SYSTEM_VAR@REPLACE_NULL@BIGINT`(PARAM_ACC_LEVEL_SERVER_ID, 0, 1, 1);
		
	END IF;
	-- ====================================================================================================================================================================


	-- 4) PREPARE AUDIT TRAIL
	-- ====================================================================================================================================================================
	IF BINARY TEMP_ACC_LEVEL_DESCRIPTION <> PARAM_ACC_LEVEL_DESCRIPTION THEN
		SET TEMP_RECORD_CHANGES = 
		`SYSTEM_VAR@CONCAT_ADD`(' | ', TEMP_RECORD_CHANGES, CONCAT_WS(' ', 'DESCRIPTION:"', TEMP_ACC_LEVEL_DESCRIPTION, '" > "', PARAM_ACC_LEVEL_DESCRIPTION, '"'));
	END IF;
	
	IF TEMP_ACC_LEVEL_STATUS <> PARAM_ACC_LEVEL_STATUS THEN
		SET TEMP_RECORD_CHANGES = 
		`SYSTEM_VAR@CONCAT_ADD`
		(
			' | ', TEMP_RECORD_CHANGES, CONCAT_WS
			(
				' ',
				'STATUS:', TEMP_ACC_LEVEL_STATUS, '("', `SYSTEM_STATUS@SYS_STATUS_DESCRIPTION_FROM_ID`(TEMP_ACC_LEVEL_STATUS), '")',
				'>', PARAM_ACC_LEVEL_STATUS, '("', `SYSTEM_STATUS@SYS_STATUS_DESCRIPTION_FROM_ID`(PARAM_ACC_LEVEL_STATUS), '")'
			)
		);
	END IF;
	
	-- No Changes in data, reject request
	IF CHAR_LENGTH(TEMP_RECORD_CHANGES) = 0 THEN
		IF PARAM_SUPPRESS_RETURN = 0 THEN
			SELECT PARAM_ACC_LEVEL_ID AS INSERTED_ID;
		END IF;
		LEAVE SP_SAVE;
	END IF;
	-- ====================================================================================================================================================================
	
	
	-- 5) VALIDATE
	-- ====================================================================================================================================================================
	
	-- Access Rights [Device]
	-- ####################################################
	IF `ACCOUNT_DEVICE@HAS_PERMISSION`(PARAM_REQUESTER_DEVICE_PUBLIC_KEY, PARAM_REQUESTER_DEVICE_PRIVATE_KEY) = 0 THEN
		SET TEMP_ERR_MESSAGE = 'Your device is not authorized yet to access this server.';
		SET ERR = `RAISERROR`(TEMP_ERR_MESSAGE);		
	END IF;
		
		
	-- Access Rights [Account]
	-- ####################################################
	IF 
		-- [ADD] Rights
		(
			TEMP_RECORD_EXISTS = 0 AND
			`ACCOUNT_ACCESS_RIGHTS@HAS_PERMISSION`(PARAM_REQUESTER_USERNAME, PARAM_REQUESTER_PASSWORD, 0, TEMP_MODULE_KEYWORD, 2) = 0 
		) OR
		-- [EDIT] Rights
		(
			TEMP_RECORD_EXISTS = 1 AND
			`ACCOUNT_ACCESS_RIGHTS@HAS_PERMISSION`(PARAM_REQUESTER_USERNAME, PARAM_REQUESTER_PASSWORD, 0, TEMP_MODULE_KEYWORD, 3) = 0 
		)
	THEN
		SET TEMP_ACCESS_RIGHTS_DENIED = 1;
		CALL `ACCOUNT_ACCESS_RIGHTS_DENY`
		(
			0, TEMP_MODULE_KEYWORD, PARAM_ACC_LEVEL_ID, PARAM_ACC_LEVEL_SERVER_ID, TEMP_SP_OBJECTIVE, TEMP_RECORD_CHANGES, 
			PARAM_REQUESTER_USERNAME, PARAM_REQUESTER_PASSWORD, 
			PARAM_REQUESTER_PROXY_ID, PARAM_REQUESTER_PROXY_PASSWORD,
			PARAM_REQUESTER_DEVICE_PUBLIC_KEY, PARAM_REQUESTER_DEVICE_PRIVATE_KEY,
			PARAM_REQUESTER_IP, PARAM_UNIQUE_SESSION_ID,
			TEMP_SYNC_SERVER_ID, PARAM_SUPPRESS_RETURN
		);
	END IF;
	
	-- SYSTEM_GENERATED
	-- ####################################################
	IF TEMP_ACC_LEVEL_SYSTEM_GENERATED = 2 THEN
		CALL `VALIDATION_SYSTEM_GENERATED`(PARAM_ACC_LEVEL_ID, PARAM_ACC_LEVEL_DESCRIPTION, '');
	END IF;

	-- Status Validation
	-- ####################################################
	IF `SYSTEM_STATUS@SYS_STATUS_ID_EXISTS`(PARAM_ACC_LEVEL_STATUS, 0) = 0 THEN
		SET TEMP_ERR_MESSAGE = CONCAT('Given STATUS does not exists or is inactive. ID: ', PARAM_ACC_LEVEL_STATUS);
		SET ERR = `RAISERROR`(TEMP_ERR_MESSAGE);
	END IF;

	-- Missing Fields
	-- ####################################################
	IF `SYSTEM_VAR@IS_NULL@NVARCHAR`(PARAM_ACC_LEVEL_DESCRIPTION, 0) = 1 THEN
		CALL `VALIDATION_MISSING_FIELD`('`ACCESS LEVEL DESCRIPTION`', '`NULL`');
	END IF;

	-- Redundant Entry
	-- ####################################################
	IF
	(
		SELECT COUNT(`account_level`.`ACC_LEVEL_DESCRIPTION`)
		FROM `account_level`
		WHERE
			`account_level`.`ACC_LEVEL_DESCRIPTION` = PARAM_ACC_LEVEL_DESCRIPTION AND
			`account_level`.`ACC_LEVEL_ID` <> PARAM_ACC_LEVEL_ID
		LIMIT 1
	) >= 1
	THEN
		CALL `VALIDATION_REDUNDANT_ENTRY`(PARAM_ACC_LEVEL_DESCRIPTION);
	END	IF;

	-- Should not edit own level
	-- ####################################################
	IF PARAM_ACC_LEVEL_ID = TEMP_AUTHENTICATED_ACCOUNT_LEVEL THEN
		SET TEMP_ERR_MESSAGE = 'You cannot edit your own access level.';
		SET ERR = `RAISERROR`(TEMP_ERR_MESSAGE);	
	END IF;

	-- Has Enough authority to assign AR for this level (or-override)
	-- ####################################################
	IF
		`ACCOUNT_ACCESS_RIGHTS@HAS_PERMISSION`(PARAM_REQUESTER_USERNAME, PARAM_REQUESTER_PASSWORD, 0, TEMP_MODULE_KEYWORD, 5) = 0 AND 
		`ACCOUNT_LEVEL@EDIT_HAS_PERMISSION`
		(
			PARAM_ACC_LEVEL_ID,
		
			PARAM_REQUESTER_USERNAME,
			PARAM_REQUESTER_PASSWORD
		) = 0 
	THEN
		SET TEMP_ERR_MESSAGE = 'You cannot access to account or settings assigned to higher authority.';
		SET ERR = `RAISERROR`(TEMP_ERR_MESSAGE);	
	END IF;
		
	-- ====================================================================================================================================================================
	
	

	-- 6) INSERT / UPDATE
	-- ====================================================================================================================================================================
	
	-- INSERT NEW DATA
	IF TEMP_RECORD_EXISTS = 0 THEN

		INSERT INTO
		`account_level`
		(
			`account_level`.`ACC_LEVEL_SERVER_ID`,
			
			`account_level`.`ACC_LEVEL_TAG_ID`,
			`account_level`.`ACC_LEVEL_DESCRIPTION`,
			`account_level`.`ACC_LEVEL_STATUS`,
			`account_level`.`ACC_LEVEL_SYSTEM_GENERATED`
		)
		VALUES
		(
			PARAM_ACC_LEVEL_SERVER_ID,
			
			PARAM_ACC_LEVEL_TAG_ID,
			PARAM_ACC_LEVEL_DESCRIPTION,
			PARAM_ACC_LEVEL_STATUS,
			1
		);
		
		-- Update Audit trail with new ID
		SET PARAM_ACC_LEVEL_ID = LAST_INSERT_ID();
		
		-- Create access rights
		CALL `ACCOUNT_ACCESS_RIGHTS_PREPARE`
		(
			PARAM_ACC_LEVEL_ID,
			
			PARAM_REQUESTER_USERNAME,
			PARAM_REQUESTER_PASSWORD,
			PARAM_REQUESTER_PROXY_ID,
			PARAM_REQUESTER_PROXY_PASSWORD,
			PARAM_REQUESTER_DEVICE_PUBLIC_KEY,
			PARAM_REQUESTER_DEVICE_PRIVATE_KEY,
				
			PARAM_REQUESTER_IP,
			PARAM_UNIQUE_SESSION_ID,
			PARAM_SUPPRESS_RETURN
		);
	-- ========================================================================


	-- UPDATING EXISTING RECORD
	-- ========================================================================
	ELSE

		UPDATE `account_level`
		SET
			`account_level`.`ACC_LEVEL_SERVER_ID` = PARAM_ACC_LEVEL_SERVER_ID,
			`account_level`.`ACC_LEVEL_TAG_ID` = PARAM_ACC_LEVEL_TAG_ID,
			`account_level`.`ACC_LEVEL_DESCRIPTION` = PARAM_ACC_LEVEL_DESCRIPTION,
			`account_level`.`ACC_LEVEL_STATUS` = PARAM_ACC_LEVEL_STATUS
		WHERE
			`account_level`.`ACC_LEVEL_ID` = PARAM_ACC_LEVEL_ID;
			
	END IF;
	
	-- ====================================================================================================================================================================


	-- 7) AUDIT TRAIL
	-- ====================================================================================================================================================================
	CALL `ACCOUNT_AUDIT_TRAIL_SAVE` 
	(
		0, TEMP_MODULE_KEYWORD, PARAM_ACC_LEVEL_ID, PARAM_ACC_LEVEL_SERVER_ID, 'SAVE', TEMP_SP_OBJECTIVE, TEMP_RECORD_CHANGES, 
		PARAM_REQUESTER_USERNAME, PARAM_REQUESTER_PASSWORD, 
		PARAM_REQUESTER_PROXY_ID, PARAM_REQUESTER_PROXY_PASSWORD,
		PARAM_REQUESTER_DEVICE_PUBLIC_KEY, PARAM_REQUESTER_DEVICE_PRIVATE_KEY,
		PARAM_REQUESTER_IP, PARAM_UNIQUE_SESSION_ID,
		TEMP_SYNC_SERVER_ID, PARAM_SUPPRESS_RETURN
	);
	-- ====================================================================================================================================================================
		

	-- 8) RETURN RESULT
	-- ====================================================================================================================================================================
	IF PARAM_SUPPRESS_RETURN = 0 THEN
		SELECT PARAM_ACC_LEVEL_ID AS INSERTED_ID;
	END IF;
	LEAVE SP_SAVE;
	-- ====================================================================================================================================================================
			
END ;;
DELIMITER ;
/*!50003 SET sql_mode              = @saved_sql_mode */ ;
/*!50003 SET character_set_client  = @saved_cs_client */ ;
/*!50003 SET character_set_results = @saved_cs_results */ ;
/*!50003 SET collation_connection  = @saved_col_connection */ ;
/*!50003 DROP PROCEDURE IF EXISTS `ACCOUNT_MEMBER_DELETE` */;
/*!50003 SET @saved_cs_client      = @@character_set_client */ ;
/*!50003 SET @saved_cs_results     = @@character_set_results */ ;
/*!50003 SET @saved_col_connection = @@collation_connection */ ;
/*!50003 SET character_set_client  = latin1 */ ;
/*!50003 SET character_set_results = latin1 */ ;
/*!50003 SET collation_connection  = latin1_swedish_ci */ ;
/*!50003 SET @saved_sql_mode       = @@sql_mode */ ;
/*!50003 SET sql_mode              = '' */ ;
DELIMITER ;;
CREATE DEFINER=`root`@`localhost` PROCEDURE `ACCOUNT_MEMBER_DELETE`(
	IN `PARAM_ACC_ACCOUNT_ID` BIGINT,
	IN `PARAM_ACC_ACCOUNT_SERVER_ID` BIGINT,

	IN `PARAM_REQUESTER_USERNAME` VARCHAR(500),
	IN `PARAM_REQUESTER_PASSWORD` VARCHAR(500),
	IN `PARAM_REQUESTER_PROXY_ID` BIGINT,
	IN `PARAM_REQUESTER_PROXY_PASSWORD` VARCHAR(1000),
	IN `PARAM_REQUESTER_DEVICE_PUBLIC_KEY` VARCHAR(1000),
	IN `PARAM_REQUESTER_DEVICE_PRIVATE_KEY` VARCHAR(1000),
	
	IN `PARAM_REQUESTER_IP` VARCHAR(1000),
	IN `PARAM_UNIQUE_SESSION_ID` VARCHAR(1000),
	IN `PARAM_SUPPRESS_RETURN` BIT,
	
	IN `PARAM_SYNC_SERVER_DESCRIPTION` VARCHAR(500), 
	IN `PARAM_SYNC_SERVER_UNIQUE_KEY` VARCHAR(500)
)
SP_DELETE:
BEGIN

	-- 1) DECLARE LOCAL PARAMETERS
	-- ====================================================================================================================================================================
	
	-- Status
	-- ...........................................
	DECLARE STATUS_INACTIVE TINYINT DEFAULT 1;
	DECLARE STATUS_ACTIVE TINYINT DEFAULT 2;
	DECLARE STATUS_CLOSED TINYINT DEFAULT 3;
	DECLARE STATUS_COMPLETED TINYINT DEFAULT 4;
		
	-- Audit Handler
	-- ...........................................
	DECLARE TEMP_RECORD_EXISTS BIT DEFAULT 0;
	DECLARE TEMP_MODULE_KEYWORD VARCHAR(500) DEFAULT 'account_member';
	DECLARE TEMP_SP_OBJECTIVE VARCHAR(500) DEFAULT 'delete User account record';
	DECLARE TEMP_ERR_MESSAGE VARCHAR(500) DEFAULT '';
	DECLARE ERR BIGINT DEFAULT 0;
	DECLARE TEMP_RECORD_CHANGES VARCHAR(16000) DEFAULT '';
	DECLARE TEMP_RECORD_BINDED BIT DEFAULT 0;
	
	DECLARE TEMP_RECORD_BINDED_ID BIGINT DEFAULT 0;
	DECLARE TEMP_RECORD_BINDED_SERVER_ID BIGINT DEFAULT 0;
	
	-- Authentication
	-- ...........................................
	DECLARE TEMP_ACCESS_RIGHTS_DENIED BIT DEFAULT 0;
	DECLARE TEMP_SYNC_SERVER_ID BIGINT DEFAULT 0;
	DECLARE TEMP_SYNC_IS_SERVER_REQUEST BIT DEFAULT 0;
	DECLARE TEMP_AUTHENTICATED_ACCOUNT_ID BIGINT DEFAULT `ACCOUNT_MEMBER@ACC_ACCOUNT_ID_FROM_LOGIN`(PARAM_REQUESTER_USERNAME, PARAM_REQUESTER_PASSWORD);
	DECLARE TEMP_AUTHENTICATED_ACCOUNT_LEVEL BIGINT DEFAULT 0;

	-- Local value holder
	-- ...........................................
	DECLARE TEMP_ACC_ACCOUNT_SERVER_ID BIGINT DEFAULT 0;
	DECLARE TEMP_ACC_ACCOUNT_ACC_LEVEL_ID BIGINT DEFAULT 0;

	DECLARE TEMP_ACC_ACCOUNT_USERNAME VARCHAR(1000) DEFAULT '';
	DECLARE TEMP_ACC_ACCOUNT_PASSWORD VARCHAR(1000) DEFAULT '';
	DECLARE TEMP_ACC_ACCOUNT_FIRST_NAME VARCHAR(1000) DEFAULT '';
	DECLARE TEMP_ACC_ACCOUNT_MIDDLE_NAME VARCHAR(1000) DEFAULT '';
	DECLARE TEMP_ACC_ACCOUNT_LAST_NAME VARCHAR(1000) DEFAULT '';

	DECLARE TEMP_ACC_ACCOUNT_SYS_GENDER_ID TINYINT DEFAULT 0;
	DECLARE TEMP_ACC_ACCOUNT_POSITION VARCHAR(1000) DEFAULT '';
	
	DECLARE TEMP_ACC_ACCOUNT_STATUS TINYINT DEFAULT 0;
	DECLARE TEMP_ACC_ACCOUNT_SYSTEM_GENERATED TINYINT DEFAULT 0;
	-- ====================================================================================================================================================================
	
	
	-- 2) Try Catch / Throw
	-- ====================================================================================================================================================================
	DECLARE EXIT HANDLER FOR SQLEXCEPTION
	BEGIN
		RESIGNAL;
	END;
	-- ====================================================================================================================================================================
	
	
	-- 3) Prepare SYNC
	-- ====================================================================================================================================================================

	-- IS SERVE REQUEST
	IF
		`SYSTEM_VAR@IS_NULL@NVARCHAR`(PARAM_SYNC_SERVER_DESCRIPTION, 1) = 0 AND
		`SYSTEM_VAR@IS_NULL@NVARCHAR`(PARAM_SYNC_SERVER_UNIQUE_KEY, 1) = 0
	THEN
	
		-- .....................................................
		
		-- SET REQUEST CAME FROM SYNC 
		SET TEMP_SYNC_IS_SERVER_REQUEST = 1;
					
		-- USE SYSTEM ACCOUNT
		IF `ACCOUNT_SERVER@HAS_PERMISSION`(PARAM_SYNC_SERVER_DESCRIPTION, PARAM_SYNC_SERVER_UNIQUE_KEY) = 1 THEN
			SELECT
				`account_member`.`ACC_ACCOUNT_USERNAME`,
				`account_member`.`ACC_ACCOUNT_PASSWORD`
			INTO
				PARAM_REQUESTER_USERNAME,
				PARAM_REQUESTER_PASSWORD
			FROM `account_member`
			WHERE
				`account_member`.`ACC_ACCOUNT_USERNAME` = 'system'
			LIMIT 1;
		ELSE
			SET PARAM_REQUESTER_USERNAME = '';
			SET PARAM_REQUESTER_PASSWORD = '';
		END IF;
		
		-- GET SERVER ID
		SET TEMP_SYNC_SERVER_ID = `ACCOUNT_SERVER@ACC_SERVER_ID_FROM_LOGIN`(PARAM_SYNC_SERVER_DESCRIPTION, PARAM_SYNC_SERVER_UNIQUE_KEY);
		
		-- .....................................................
	
	
		-- GET LOCAL ID
		SET PARAM_ACC_ACCOUNT_ID = `ACCOUNT_MEMBER@ACC_ACCOUNT_ID_FROM_SERVER_ID`
								(
									PARAM_ACC_ACCOUNT_ID,
									PARAM_ACC_ACCOUNT_SERVER_ID,

									null,
									null,
									null
								);		
	END IF;
	
	-- IS RECORD EXISTS					
	SET TEMP_RECORD_EXISTS = `ACCOUNT_MEMBER@ACC_ACCOUNT_ID_EXISTS`(PARAM_ACC_ACCOUNT_ID, 0);

	-- ====================================================================================================================================================================
		
		
	-- 4) IF ALREADY EXIST, FILL MISSING DATA
	-- ====================================================================================================================================================================
	IF TEMP_RECORD_EXISTS  = 1 THEN
		SELECT
			`account_member`.`ACC_ACCOUNT_SERVER_ID`,
			`account_member`.`ACC_ACCOUNT_ACC_LEVEL_ID`,

			`account_member`.`ACC_ACCOUNT_USERNAME`,
			`account_member`.`ACC_ACCOUNT_PASSWORD`,
			`account_member`.`ACC_ACCOUNT_FIRST_NAME`,
			`account_member`.`ACC_ACCOUNT_MIDDLE_NAME`,
			`account_member`.`ACC_ACCOUNT_LAST_NAME`,

			`account_member`.`ACC_ACCOUNT_SYS_GENDER_ID`,
			`account_member`.`ACC_ACCOUNT_POSITION`,
			
			`account_member`.`ACC_ACCOUNT_STATUS`,
			`account_member`.`ACC_ACCOUNT_SYSTEM_GENERATED`
		INTO
			TEMP_ACC_ACCOUNT_SERVER_ID,
			TEMP_ACC_ACCOUNT_ACC_LEVEL_ID,
			
			TEMP_ACC_ACCOUNT_USERNAME,
			TEMP_ACC_ACCOUNT_PASSWORD,
			TEMP_ACC_ACCOUNT_FIRST_NAME,
			TEMP_ACC_ACCOUNT_MIDDLE_NAME,
			TEMP_ACC_ACCOUNT_LAST_NAME,
			
			TEMP_ACC_ACCOUNT_SYS_GENDER_ID,
			TEMP_ACC_ACCOUNT_POSITION,
			
			TEMP_ACC_ACCOUNT_STATUS,
			TEMP_ACC_ACCOUNT_SYSTEM_GENERATED
			
		FROM `account_member`
		WHERE
			`account_member`.`ACC_ACCOUNT_ID` = PARAM_ACC_ACCOUNT_ID
		LIMIT 1;

	ELSE
		IF TEMP_SYNC_IS_SERVER_REQUEST = 0 THEN
			SET TEMP_ERR_MESSAGE = CONCAT_WS(' ', 'Given MEMBER does not exists or is inactive. ID: ', PARAM_ACC_ACCOUNT_ID);
			SET ERR = `RAISERROR`(TEMP_ERR_MESSAGE);	
		END IF;
		LEAVE SP_DELETE;
	END IF;
	-- ====================================================================================================================================================================
	
	
	-- 5) PREPARE AUDIT TRAIL
	-- ====================================================================================================================================================================
	SET TEMP_RECORD_CHANGES = 
	`SYSTEM_VAR@CONCAT_ADD`(' | ', TEMP_RECORD_CHANGES, CONCAT_WS(' ', 'ACC_ACCOUNT_ID:', PARAM_ACC_ACCOUNT_ID));
	
	SET TEMP_RECORD_CHANGES = 
	`SYSTEM_VAR@CONCAT_ADD`(' | ', TEMP_RECORD_CHANGES, CONCAT_WS(' ', 'ACC_ACCOUNT_SERVER_ID:"', TEMP_ACC_ACCOUNT_SERVER_ID, '" > "DELETED"'));

	SET TEMP_RECORD_CHANGES = 
	`SYSTEM_VAR@CONCAT_ADD`(' | ', TEMP_RECORD_CHANGES, CONCAT_WS(' ', 'USERNAME:"', TEMP_ACC_ACCOUNT_USERNAME, '" > "DELETED"'));

	SET TEMP_RECORD_CHANGES = 
	`SYSTEM_VAR@CONCAT_ADD`(' | ', TEMP_RECORD_CHANGES, CONCAT_WS(' ', 'PASSWORD:"', TEMP_ACC_ACCOUNT_PASSWORD, '" > "DELETED"'));
	
	SET TEMP_RECORD_CHANGES = 
	`SYSTEM_VAR@CONCAT_ADD`(' | ', TEMP_RECORD_CHANGES, CONCAT_WS(' ', 'FIRST NAME:"', TEMP_ACC_ACCOUNT_FIRST_NAME, '" > "DELETED"'));
	
	SET TEMP_RECORD_CHANGES = 
	`SYSTEM_VAR@CONCAT_ADD`(' | ', TEMP_RECORD_CHANGES, CONCAT_WS(' ', 'MIDDLE NAME:"', TEMP_ACC_ACCOUNT_MIDDLE_NAME, '" > "DELETED"'));
	
	SET TEMP_RECORD_CHANGES = 
	`SYSTEM_VAR@CONCAT_ADD`(' | ', TEMP_RECORD_CHANGES, CONCAT_WS(' ', 'LAST NAME:"', TEMP_ACC_ACCOUNT_LAST_NAME, '" > "DELETED"'));

	SET TEMP_RECORD_CHANGES = 
	`SYSTEM_VAR@CONCAT_ADD`
	(
		' | ', TEMP_RECORD_CHANGES, CONCAT_WS
		(
			' ',
			'GENDER: ', TEMP_ACC_ACCOUNT_SYS_GENDER_ID, '("', `SYSTEM_GENDER@SYS_GENDER_DESCRIPTION_FROM_ID`(TEMP_ACC_ACCOUNT_SYS_GENDER_ID), '")',
			' > 0("DELETED")'
		)
	);

	SET TEMP_RECORD_CHANGES = 
	`SYSTEM_VAR@CONCAT_ADD`(' | ', TEMP_RECORD_CHANGES, CONCAT_WS(' ', 'ACC_ACCOUNT_POSITION: "', TEMP_ACC_ACCOUNT_POSITION, '" > "DELETED"'));
	
	SET TEMP_RECORD_CHANGES = 
	`SYSTEM_VAR@CONCAT_ADD`
	(
		' | ', TEMP_RECORD_CHANGES, CONCAT_WS
		(
			' ',
			'STATUS: ', TEMP_ACC_ACCOUNT_STATUS, '("', `SYSTEM_STATUS@SYS_STATUS_DESCRIPTION_FROM_ID`(TEMP_ACC_ACCOUNT_STATUS), '")',
			' > DELETED'
		)
	);
	-- ====================================================================================================================================================================
	
	
	-- 6) VALIDATE
	-- ====================================================================================================================================================================
	
	-- Access Rights [Device]
	-- ####################################################
	IF `ACCOUNT_DEVICE@HAS_PERMISSION`(PARAM_REQUESTER_DEVICE_PUBLIC_KEY, PARAM_REQUESTER_DEVICE_PRIVATE_KEY) = 0 THEN
		SET TEMP_ERR_MESSAGE = 'Your device is not authorized yet to access this server.';
		SET ERR = `RAISERROR`(TEMP_ERR_MESSAGE);		
	END IF;
	
	-- Access Rights [Account] (w/ Exception for editing own Username/Password)
	-- ####################################################
	IF 
		-- [DELETE] Rights
		`ACCOUNT_ACCESS_RIGHTS@HAS_PERMISSION`(PARAM_REQUESTER_USERNAME, PARAM_REQUESTER_PASSWORD, 0, TEMP_MODULE_KEYWORD, 4) = 0 
	THEN
		CALL `ACCOUNT_ACCESS_RIGHTS_DENY`
		(
			0, TEMP_MODULE_KEYWORD, PARAM_ACC_ACCOUNT_ID, TEMP_ACC_ACCOUNT_SERVER_ID, TEMP_SP_OBJECTIVE, TEMP_RECORD_CHANGES, 
			PARAM_REQUESTER_USERNAME, PARAM_REQUESTER_PASSWORD, 
			PARAM_REQUESTER_PROXY_ID, PARAM_REQUESTER_PROXY_PASSWORD,
			PARAM_REQUESTER_DEVICE_PUBLIC_KEY, PARAM_REQUESTER_DEVICE_PRIVATE_KEY,
			PARAM_REQUESTER_IP, PARAM_UNIQUE_SESSION_ID,
			TEMP_SYNC_SERVER_ID, PARAM_SUPPRESS_RETURN
		);
	END IF;

	-- Cannot Delete Self
	-- ####################################################
	IF PARAM_ACC_ACCOUNT_ID = TEMP_AUTHENTICATED_ACCOUNT_ID THEN
		SET TEMP_ERR_MESSAGE = 'You cannot edit your own account.';
		SET ERR = `RAISERROR`(TEMP_ERR_MESSAGE);	
	END IF;

	-- Has Enough authority to access AR for this level (or-override)
	-- ####################################################
	IF
		`ACCOUNT_ACCESS_RIGHTS@HAS_PERMISSION`(PARAM_REQUESTER_USERNAME, PARAM_REQUESTER_PASSWORD, 0, TEMP_MODULE_KEYWORD, 5) = 0 AND 
		`ACCOUNT_LEVEL@EDIT_HAS_PERMISSION`
		(
			TEMP_ACC_ACCOUNT_ACC_LEVEL_ID,
		
			PARAM_REQUESTER_USERNAME,
			PARAM_REQUESTER_PASSWORD
		) = 0 
	THEN
		SET TEMP_ERR_MESSAGE = 'You cannot access to account or settings assigned to higher authority.';
		SET ERR = `RAISERROR`(TEMP_ERR_MESSAGE);	
	END IF;
		
	-- If already used, cannot remove member
	-- ####################################################
	IF
	(
		SELECT	
			COUNT(`account_audit_trail`.`ACC_TRAIL_ID`)
		FROM `account_audit_trail`
		WHERE
			`account_audit_trail`.`ACC_TRAIL_ACC_ACCOUNT_ID` = PARAM_ACC_ACCOUNT_ID
		LIMIT 1
	) >= 1 
	THEN
		SET TEMP_RECORD_BINDED = 1;
		SET TEMP_ERR_MESSAGE = 'AUDIT TRAIL';
	END IF;
	
	-- Leave Re-upload request
	-- ####################################################
	IF TEMP_RECORD_BINDED = 1 THEN
	
		IF TEMP_SYNC_IS_SERVER_REQUEST = 1 THEN
			CALL `ACCOUNT_AUDIT_TRAIL_SAVE`
			(
				0, TEMP_MODULE_KEYWORD, PARAM_ACC_ACCOUNT_ID, TEMP_ACC_ACCOUNT_SERVER_ID, 'SAVE', 'Sync re-upload request', TEMP_RECORD_CHANGES, 
				PARAM_REQUESTER_USERNAME, PARAM_REQUESTER_PASSWORD, 
				PARAM_REQUESTER_PROXY_ID, PARAM_REQUESTER_PROXY_PASSWORD,
				PARAM_REQUESTER_DEVICE_PUBLIC_KEY, PARAM_REQUESTER_DEVICE_PRIVATE_KEY,
				PARAM_REQUESTER_IP, PARAM_UNIQUE_SESSION_ID,
				0, PARAM_SUPPRESS_RETURN
			);		
			LEAVE SP_DELETE;
		END IF;

		CALL `VALIDATION_DELETE_LINKED_RECORD`('Member', PARAM_ACC_ACCOUNT_ID, TEMP_ERR_MESSAGE);
	END IF;
	-- ====================================================================================================================================================================
	
	
	-- 7) DELETE
	-- ====================================================================================================================================================================
	DELETE FROM `account_member`
	WHERE `account_member`.`ACC_ACCOUNT_ID` = PARAM_ACC_ACCOUNT_ID
	LIMIT 1;
	-- ====================================================================================================================================================================
	
	
	-- 8) AUDIT TRAIL
	-- ====================================================================================================================================================================
	CALL `ACCOUNT_AUDIT_TRAIL_SAVE`
	(
		0, TEMP_MODULE_KEYWORD, PARAM_ACC_ACCOUNT_ID, TEMP_ACC_ACCOUNT_SERVER_ID, 'DELETE', TEMP_SP_OBJECTIVE, TEMP_RECORD_CHANGES, 
		PARAM_REQUESTER_USERNAME, PARAM_REQUESTER_PASSWORD, 
		PARAM_REQUESTER_PROXY_ID, PARAM_REQUESTER_PROXY_PASSWORD,
		PARAM_REQUESTER_DEVICE_PUBLIC_KEY, PARAM_REQUESTER_DEVICE_PRIVATE_KEY,
		PARAM_REQUESTER_IP, PARAM_UNIQUE_SESSION_ID,
		TEMP_SYNC_SERVER_ID, PARAM_SUPPRESS_RETURN
	);
	-- ====================================================================================================================================================================
	
END ;;
DELIMITER ;
/*!50003 SET sql_mode              = @saved_sql_mode */ ;
/*!50003 SET character_set_client  = @saved_cs_client */ ;
/*!50003 SET character_set_results = @saved_cs_results */ ;
/*!50003 SET collation_connection  = @saved_col_connection */ ;
/*!50003 DROP PROCEDURE IF EXISTS `ACCOUNT_MEMBER_GET` */;
/*!50003 SET @saved_cs_client      = @@character_set_client */ ;
/*!50003 SET @saved_cs_results     = @@character_set_results */ ;
/*!50003 SET @saved_col_connection = @@collation_connection */ ;
/*!50003 SET character_set_client  = latin1 */ ;
/*!50003 SET character_set_results = latin1 */ ;
/*!50003 SET collation_connection  = latin1_swedish_ci */ ;
/*!50003 SET @saved_sql_mode       = @@sql_mode */ ;
/*!50003 SET sql_mode              = '' */ ;
DELIMITER ;;
CREATE DEFINER=`root`@`localhost` PROCEDURE `ACCOUNT_MEMBER_GET`(
	IN `PARAM_ACC_ACCOUNT_ID` BIGINT,
	IN `PARAM_ACC_ACCOUNT_SERVER_ID` BIGINT,
	IN `PARAM_ACC_ACCOUNT_ACC_LEVEL_ID` BIGINT,
	IN `PARAM_ACC_ACCOUNT_ACC_GROUP_ID` BIGINT,
	
	IN `PARAM_ACC_ACCOUNT_USERNAME` VARCHAR(1000),
	IN `PARAM_ACC_ACCOUNT_NAME` VARCHAR(1000),
	IN `PARAM_ACC_ACCOUNT_FIRST_NAME` VARCHAR(1000),
	IN `PARAM_ACC_ACCOUNT_MIDDLE_NAME` VARCHAR(1000),
	IN `PARAM_ACC_ACCOUNT_LAST_NAME` VARCHAR(1000),

	IN `PARAM_ACC_ACCOUNT_SYS_GENDER_ID` TINYINT,
	IN `PARAM_ACC_ACCOUNT_POSITION` VARCHAR(1000),
	
	IN `PARAM_ACC_ACCOUNT_STATUS` TINYINT,
	IN `PARAM_ACC_ACCOUNT_SYSTEM_GENERATED` TINYINT,
	
	IN `PARAM_ORDER_FIELD` VARCHAR(500),
	IN `PARAM_ORDER_TYPE` VARCHAR(500),
	IN `PARAM_SKIP` BIGINT,
	IN `PARAM_LIMIT` BIGINT,

	IN `PARAM_REQUESTER_USERNAME` VARCHAR(500),
	IN `PARAM_REQUESTER_PASSWORD` VARCHAR(500),
	IN `PARAM_REQUESTER_PROXY_ID` BIGINT,
	IN `PARAM_REQUESTER_PROXY_PASSWORD` VARCHAR(1000),
	IN `PARAM_REQUESTER_DEVICE_PUBLIC_KEY` VARCHAR(1000),
	IN `PARAM_REQUESTER_DEVICE_PRIVATE_KEY` VARCHAR(1000),
	
	IN `PARAM_REQUESTER_IP` VARCHAR(1000),
	IN `PARAM_UNIQUE_SESSION_ID` VARCHAR(1000),
	IN `PARAM_SUPPRESS_RETURN` BIT
)
SP_GET:
BEGIN

	-- Initialize
	-- _______________________________________________________________________
	
	-- Audit Handler
	-- ...........................................
	DECLARE TEMP_MODULE_KEYWORD VARCHAR(500) DEFAULT 'account_member';
	DECLARE TEMP_SP_OBJECTIVE VARCHAR(500) DEFAULT 'retrieve User account record';
	DECLARE TEMP_ERR_MESSAGE VARCHAR(500) DEFAULT '';
	DECLARE ERR BIGINT DEFAULT 0;
	DECLARE TEMP_RECORD_CHANGES VARCHAR(16000) DEFAULT '';
	DECLARE TEMP_RECORD_BINDED BIT DEFAULT 0;

	-- Authentication
	-- ...........................................
	DECLARE TEMP_ACCESS_RIGHTS_DENIED BIT DEFAULT 0;
	DECLARE TEMP_SYNC_SERVER_ID BIGINT DEFAULT 0;
	DECLARE TEMP_SYNC_IS_SERVER_REQUEST BIT DEFAULT 0;
	DECLARE TEMP_AUTHENTICATED_ACC_ACCOUNT_ID BIGINT DEFAULT 0;
	DECLARE TEMP_AUTHENTICATED_ACCOUNT_LEVEL BIGINT DEFAULT 0;

	
	-- Check NULLs
	-- ...........................................
	-- ACCOUNT
	DECLARE IS_NULL_ACC_ACCOUNT_ID BIT DEFAULT `SYSTEM_VAR@IS_NULL@BIGINT`(PARAM_ACC_ACCOUNT_ID, 1, 1);
	DECLARE IS_NULL_ACC_ACCOUNT_SERVER_ID BIT DEFAULT `SYSTEM_VAR@IS_NULL@BIGINT`(PARAM_ACC_ACCOUNT_SERVER_ID, 1, 1);
	DECLARE IS_NULL_ACC_ACCOUNT_ACC_LEVEL_ID BIT DEFAULT `SYSTEM_VAR@IS_NULL@BIGINT`(PARAM_ACC_ACCOUNT_ACC_LEVEL_ID, 1, 1);

	DECLARE IS_NULL_ACC_ACCOUNT_USERNAME BIT DEFAULT `SYSTEM_VAR@IS_NULL@NVARCHAR`(PARAM_ACC_ACCOUNT_USERNAME, 1);
	DECLARE IS_NULL_ACC_ACCOUNT_NAME BIT DEFAULT `SYSTEM_VAR@IS_NULL@NVARCHAR`(PARAM_ACC_ACCOUNT_NAME, 1);
	DECLARE IS_NULL_ACC_ACCOUNT_FIRST_NAME BIT DEFAULT `SYSTEM_VAR@IS_NULL@NVARCHAR`(PARAM_ACC_ACCOUNT_FIRST_NAME, 1);
	DECLARE IS_NULL_ACC_ACCOUNT_MIDDLE_NAME BIT DEFAULT `SYSTEM_VAR@IS_NULL@NVARCHAR`(PARAM_ACC_ACCOUNT_MIDDLE_NAME, 1);
	DECLARE IS_NULL_ACC_ACCOUNT_LAST_NAME BIT DEFAULT `SYSTEM_VAR@IS_NULL@NVARCHAR`(PARAM_ACC_ACCOUNT_LAST_NAME, 1);

	DECLARE IS_NULL_ACC_ACCOUNT_SYS_GENDER_ID BIT DEFAULT `SYSTEM_VAR@IS_NULL@TINYINT`(PARAM_ACC_ACCOUNT_SYS_GENDER_ID, 1, 1);
	DECLARE IS_NULL_ACC_ACCOUNT_POSITION BIT DEFAULT `SYSTEM_VAR@IS_NULL@NVARCHAR`(PARAM_ACC_ACCOUNT_POSITION, 1);
	
	DECLARE IS_NULL_ACC_ACCOUNT_STATUS BIT DEFAULT `SYSTEM_VAR@IS_NULL@TINYINT`(PARAM_ACC_ACCOUNT_STATUS, 1, 1);
	DECLARE IS_NULL_ACC_ACCOUNT_SYSTEM_GENERATED BIT DEFAULT `SYSTEM_VAR@IS_NULL@TINYINT`(PARAM_ACC_ACCOUNT_SYSTEM_GENERATED, 1, 1);
	
	
	-- Error Handler
	-- _______________________________________________________________________
	DECLARE EXIT HANDLER FOR SQLEXCEPTION
	BEGIN
		RESIGNAL;
	END;

	
	-- Access Rights [Device]
	-- _______________________________________________________________________
	IF `ACCOUNT_DEVICE@HAS_PERMISSION`(PARAM_REQUESTER_DEVICE_PUBLIC_KEY, PARAM_REQUESTER_DEVICE_PRIVATE_KEY) = 0 THEN
		SET TEMP_ERR_MESSAGE = 'Your device is not authorized yet to access this server.';
		SET ERR = `RAISERROR`(TEMP_ERR_MESSAGE);		
	END IF;
		
		
	-- Access Rights [Account]
	-- _______________________________________________________________________
	SET TEMP_AUTHENTICATED_ACC_ACCOUNT_ID = `ACCOUNT_MEMBER@ACC_ACCOUNT_ID_FROM_LOGIN`(PARAM_REQUESTER_USERNAME, PARAM_REQUESTER_PASSWORD);
	IF 
		PARAM_ACC_ACCOUNT_ID <> TEMP_AUTHENTICATED_ACC_ACCOUNT_ID AND
		`ACCOUNT_ACCESS_RIGHTS@HAS_PERMISSION`(PARAM_REQUESTER_USERNAME, PARAM_REQUESTER_PASSWORD, 0, TEMP_MODULE_KEYWORD, 1) = 0 
	THEN
		CALL `ACCOUNT_ACCESS_RIGHTS_DENY`
		(
			0, TEMP_MODULE_KEYWORD, PARAM_ACC_ACCOUNT_ID, 0, TEMP_SP_OBJECTIVE, '', 
			PARAM_REQUESTER_USERNAME, PARAM_REQUESTER_PASSWORD, 
			PARAM_REQUESTER_PROXY_ID, PARAM_REQUESTER_PROXY_PASSWORD,
			PARAM_REQUESTER_DEVICE_PUBLIC_KEY, PARAM_REQUESTER_DEVICE_PRIVATE_KEY,
			PARAM_REQUESTER_IP, PARAM_UNIQUE_SESSION_ID,
			0, PARAM_SUPPRESS_RETURN
		);
	END IF;
	
	
	-- SELECT ACCOUNTS
	-- _______________________________________________________________________
	SELECT
		-- ACCOUNT DATA
		`account_member`.`ACC_ACCOUNT_ID`,
		`account_member`.`ACC_ACCOUNT_SERVER_ID`,
		`account_member`.`ACC_ACCOUNT_ACC_LEVEL_ID`,
		`account_member`.`ACC_ACCOUNT_ACC_GROUP_ID`,
		`account_member`.`ACC_ACCOUNT_ADD_RESOURCE_ID`,
		
		`account_member`.`ACC_ACCOUNT_USERNAME`,
		`account_member`.`ACC_ACCOUNT_PASSWORD`,
		CONCAT_WS
		(
			' ',
			`account_member`.`ACC_ACCOUNT_LAST_NAME`, ',',
			`account_member`.`ACC_ACCOUNT_FIRST_NAME`,
			`account_member`.`ACC_ACCOUNT_MIDDLE_NAME`
		) AS ACC_ACCOUNT_NAME,
		`account_member`.`ACC_ACCOUNT_FIRST_NAME`,
		`account_member`.`ACC_ACCOUNT_MIDDLE_NAME`,
		`account_member`.`ACC_ACCOUNT_LAST_NAME`,

		`account_member`.`ACC_ACCOUNT_SYS_GENDER_ID`,
		`account_member`.`ACC_ACCOUNT_POSITION`,
			
		`account_member`.`ACC_ACCOUNT_STATUS`,
		`account_member`.`ACC_ACCOUNT_SYSTEM_GENERATED`,

		-- LEVEL DATA
		`account_level`.`ACC_LEVEL_ID`,
		`account_level`.`ACC_LEVEL_TAG_ID`,
		`account_level`.`ACC_LEVEL_DESCRIPTION` AS ACC_ACCOUNT_ACC_LEVEL_ID_DESCRIPTION,
		`account_level`.`ACC_LEVEL_DESCRIPTION`,
		`account_level`.`ACC_LEVEL_STATUS`,
		
		-- GROUP DATA
		`account_group`.`ACC_GROUP_ID`,			
		`account_group`.`ACC_GROUP_DESCRIPTION` AS ACC_ACCOUNT_ACC_GROUP_ID_DESCRIPTION,
		`account_group`.`ACC_GROUP_DESCRIPTION`,			
		`account_group`.`ACC_GROUP_STATUS`,			
		`account_group`.`ACC_GROUP_SYSTEM_GENERATED`,	
			
		-- GENDER DATA
		`system_gender`.`SYS_GENDER_DESCRIPTION` AS ACC_ACCOUNT_SYS_GENDER_ID_DESCRIPTION,
		`system_gender`.`SYS_GENDER_DESCRIPTION`,
		
		-- Mobile Data
		`mobile_shortcode`.`MOB_MOBILE_ID`,
		`mobile_shortcode`.`MOB_MOBILE_SHORTCODE`,
		`mobile_shortcode`.`MOB_MOBILE_COMPANY_CODE`,

		-- STATUS DATA
		`system_status`.`SYS_STATUS_DESCRIPTION`

	FROM `account_member`
		INNER JOIN `account_level` ON
		`account_level`.`ACC_LEVEL_ID` = `account_member`.`ACC_ACCOUNT_ACC_LEVEL_ID`

		INNER JOIN `account_group` ON
		`account_group`.`ACC_GROUP_ID` = `account_member`.`ACC_ACCOUNT_ACC_GROUP_ID`
		
		INNER JOIN `system_gender` ON
		`system_gender`.`SYS_GENDER_ID` = `account_member`.`ACC_ACCOUNT_SYS_GENDER_ID`

		INNER JOIN `system_status` ON
		`system_status`.`SYS_STATUS_ID` = `account_member`.`ACC_ACCOUNT_STATUS`
		
		LEFT JOIN `mobile_shortcode` ON
		`mobile_shortcode`.`MOB_MOBILE_GROUP_ID` = `account_group`.`ACC_GROUP_ID`
						
	-- CONDITIONS
	-- _______________________________________________________________________
	 WHERE

		-- ACCOUNT
		(
			IS_NULL_ACC_ACCOUNT_ID = 1 OR
			`account_member`.`ACC_ACCOUNT_ID` = PARAM_ACC_ACCOUNT_ID
		) AND
		(
			IS_NULL_ACC_ACCOUNT_SERVER_ID = 1 OR
			`account_member`.`ACC_ACCOUNT_SERVER_ID` = PARAM_ACC_ACCOUNT_SERVER_ID
		) AND
		(
			IS_NULL_ACC_ACCOUNT_ACC_LEVEL_ID = 1 OR
			`account_member`.`ACC_ACCOUNT_ACC_LEVEL_ID` = PARAM_ACC_ACCOUNT_ACC_LEVEL_ID
		) AND


		(
			IS_NULL_ACC_ACCOUNT_USERNAME = 1 OR
			`account_member`.`ACC_ACCOUNT_USERNAME` = PARAM_ACC_ACCOUNT_USERNAME
		) AND
		`account_member`.`ACC_ACCOUNT_USERNAME` <> 'system' AND
		(
			IS_NULL_ACC_ACCOUNT_NAME = 1 OR
			CONCAT_WS(' ', `account_member`.`ACC_ACCOUNT_FIRST_NAME`, `account_member`.`ACC_ACCOUNT_MIDDLE_NAME`, `account_member`.`ACC_ACCOUNT_LAST_NAME`) LIKE 
			CONCAT_WS('%', '', PARAM_ACC_ACCOUNT_NAME, '')
		) AND
		(
			IS_NULL_ACC_ACCOUNT_FIRST_NAME = 1 OR
			`account_member`.`ACC_ACCOUNT_FIRST_NAME` = CONCAT_WS('%', '', PARAM_ACC_ACCOUNT_FIRST_NAME, '')
		) AND
		(
			IS_NULL_ACC_ACCOUNT_MIDDLE_NAME = 1 OR
			`account_member`.`ACC_ACCOUNT_MIDDLE_NAME` = CONCAT_WS('%', '', PARAM_ACC_ACCOUNT_MIDDLE_NAME, '')
		) AND
		(
			IS_NULL_ACC_ACCOUNT_LAST_NAME = 1 OR
			`account_member`.`ACC_ACCOUNT_LAST_NAME` = CONCAT_WS('%', '', PARAM_ACC_ACCOUNT_LAST_NAME, '')
		) AND


		(
			IS_NULL_ACC_ACCOUNT_SYS_GENDER_ID = 1 OR
			`account_member`.`ACC_ACCOUNT_SYS_GENDER_ID` = PARAM_ACC_ACCOUNT_SYS_GENDER_ID
		) AND
		(
			IS_NULL_ACC_ACCOUNT_POSITION = 1 OR
			`account_member`.`ACC_ACCOUNT_POSITION` LIKE CONCAT_WS('%', '', PARAM_ACC_ACCOUNT_POSITION, '')
		) AND
		
		
		(
			IS_NULL_ACC_ACCOUNT_STATUS = 1 OR
			`account_member`.`ACC_ACCOUNT_STATUS` = PARAM_ACC_ACCOUNT_STATUS
		) AND
		(
			PARAM_ACC_ACCOUNT_SYSTEM_GENERATED = 0 OR
			`account_member`.`ACC_ACCOUNT_SYSTEM_GENERATED` = PARAM_ACC_ACCOUNT_SYSTEM_GENERATED
		)

	-- ORDER BY
	-- _______________________________________________________________________
	ORDER BY
		-- ACCOUNT
		CASE WHEN PARAM_ORDER_FIELD = 'ACC_ACCOUNT_ID' AND PARAM_ORDER_TYPE = 'ASC' THEN `account_member`.`ACC_ACCOUNT_ID` END ASC, 
		CASE WHEN PARAM_ORDER_FIELD = 'ACC_ACCOUNT_ID' AND PARAM_ORDER_TYPE = 'DESC' THEN `account_member`.`ACC_ACCOUNT_ID` END DESC,
		CASE WHEN PARAM_ORDER_FIELD = 'ACC_ACCOUNT_SERVER_ID' AND PARAM_ORDER_TYPE = 'ASC' THEN `account_member`.`ACC_ACCOUNT_SERVER_ID` END ASC, 
		CASE WHEN PARAM_ORDER_FIELD = 'ACC_ACCOUNT_SERVER_ID' AND PARAM_ORDER_TYPE = 'DESC' THEN `account_member`.`ACC_ACCOUNT_SERVER_ID` END DESC,
		CASE WHEN PARAM_ORDER_FIELD = 'ACC_ACCOUNT_ACC_LEVEL_ID' AND PARAM_ORDER_TYPE = 'ASC' THEN `account_member`.`ACC_ACCOUNT_ACC_LEVEL_ID` END ASC, 
		CASE WHEN PARAM_ORDER_FIELD = 'ACC_ACCOUNT_ACC_LEVEL_ID' AND PARAM_ORDER_TYPE = 'DESC' THEN `account_member`.`ACC_ACCOUNT_ACC_LEVEL_ID` END DESC,		
		CASE WHEN PARAM_ORDER_FIELD = 'ACC_ACCOUNT_ACC_GROUP_ID' AND PARAM_ORDER_TYPE = 'ASC' THEN `account_member`.`ACC_ACCOUNT_ACC_GROUP_ID` END ASC, 
		CASE WHEN PARAM_ORDER_FIELD = 'ACC_ACCOUNT_ACC_GROUP_ID' AND PARAM_ORDER_TYPE = 'DESC' THEN `account_member`.`ACC_ACCOUNT_ACC_GROUP_ID` END DESC,	
		
		CASE WHEN PARAM_ORDER_FIELD = 'ACC_ACCOUNT_USERNAME' AND PARAM_ORDER_TYPE = 'ASC' THEN `account_member`.`ACC_ACCOUNT_USERNAME` END ASC, 
		CASE WHEN PARAM_ORDER_FIELD = 'ACC_ACCOUNT_USERNAME' AND PARAM_ORDER_TYPE = 'DESC' THEN `account_member`.`ACC_ACCOUNT_USERNAME` END DESC,
		CASE WHEN PARAM_ORDER_FIELD = 'ACC_ACCOUNT_FIRST_NAME' AND PARAM_ORDER_TYPE = 'ASC' THEN `account_member`.`ACC_ACCOUNT_FIRST_NAME` END ASC, 
		CASE WHEN PARAM_ORDER_FIELD = 'ACC_ACCOUNT_FIRST_NAME' AND PARAM_ORDER_TYPE = 'DESC' THEN `account_member`.`ACC_ACCOUNT_FIRST_NAME` END DESC,
		CASE WHEN PARAM_ORDER_FIELD = 'ACC_ACCOUNT_MIDDLE_NAME' AND PARAM_ORDER_TYPE = 'ASC' THEN `account_member`.`ACC_ACCOUNT_MIDDLE_NAME` END ASC, 
		CASE WHEN PARAM_ORDER_FIELD = 'ACC_ACCOUNT_MIDDLE_NAME' AND PARAM_ORDER_TYPE = 'DESC' THEN `account_member`.`ACC_ACCOUNT_MIDDLE_NAME` END DESC,
		CASE WHEN PARAM_ORDER_FIELD = 'ACC_ACCOUNT_LAST_NAME' AND PARAM_ORDER_TYPE = 'ASC' THEN `account_member`.`ACC_ACCOUNT_LAST_NAME` END ASC, 
		CASE WHEN PARAM_ORDER_FIELD = 'ACC_ACCOUNT_LAST_NAME' AND PARAM_ORDER_TYPE = 'DESC' THEN `account_member`.`ACC_ACCOUNT_LAST_NAME` END DESC,

		CASE WHEN PARAM_ORDER_FIELD = 'ACC_ACCOUNT_SYS_GENDER_ID' AND PARAM_ORDER_TYPE = 'ASC' THEN `account_member`.`ACC_ACCOUNT_SYS_GENDER_ID` END ASC, 
		CASE WHEN PARAM_ORDER_FIELD = 'ACC_ACCOUNT_SYS_GENDER_ID' AND PARAM_ORDER_TYPE = 'DESC' THEN `account_member`.`ACC_ACCOUNT_SYS_GENDER_ID` END DESC,
		CASE WHEN PARAM_ORDER_FIELD = 'ACC_ACCOUNT_POSITION' AND PARAM_ORDER_TYPE = 'ASC' THEN `account_member`.`ACC_ACCOUNT_POSITION` END ASC, 
		CASE WHEN PARAM_ORDER_FIELD = 'ACC_ACCOUNT_POSITION' AND PARAM_ORDER_TYPE = 'DESC' THEN `account_member`.`ACC_ACCOUNT_POSITION` END DESC,	
		
		CASE WHEN PARAM_ORDER_FIELD = 'ACC_ACCOUNT_STATUS' AND PARAM_ORDER_TYPE = 'ASC' THEN `account_member`.`ACC_ACCOUNT_STATUS` END ASC, 
		CASE WHEN PARAM_ORDER_FIELD = 'ACC_ACCOUNT_STATUS' AND PARAM_ORDER_TYPE = 'DESC' THEN `account_member`.`ACC_ACCOUNT_STATUS` END DESC,
		CASE WHEN PARAM_ORDER_FIELD = 'ACC_ACCOUNT_SYSTEM_GENERATED' AND PARAM_ORDER_TYPE = 'ASC' THEN `account_member`.`ACC_ACCOUNT_SYSTEM_GENERATED` END ASC, 
		CASE WHEN PARAM_ORDER_FIELD = 'ACC_ACCOUNT_SYSTEM_GENERATED' AND PARAM_ORDER_TYPE = 'DESC' THEN `account_member`.`ACC_ACCOUNT_SYSTEM_GENERATED` END DESC,	
		
		-- LEVEL
		CASE WHEN PARAM_ORDER_FIELD = 'ACC_LEVEL_TAG_ID' AND PARAM_ORDER_TYPE = 'ASC' THEN `account_level`.`ACC_LEVEL_TAG_ID` END ASC, 
		CASE WHEN PARAM_ORDER_FIELD = 'ACC_LEVEL_TAG_ID' AND PARAM_ORDER_TYPE = 'DESC' THEN `account_level`.`ACC_LEVEL_TAG_ID` END DESC,	
		CASE WHEN PARAM_ORDER_FIELD = 'ACC_LEVEL_DESCRIPTION' AND PARAM_ORDER_TYPE = 'ASC' THEN `account_level`.`ACC_LEVEL_DESCRIPTION` END ASC, 
		CASE WHEN PARAM_ORDER_FIELD = 'ACC_LEVEL_DESCRIPTION' AND PARAM_ORDER_TYPE = 'DESC' THEN `account_level`.`ACC_LEVEL_DESCRIPTION` END DESC,	
		
		-- GROUP
		CASE WHEN PARAM_ORDER_FIELD = 'ACC_GROUP_DESCRIPTION' AND PARAM_ORDER_TYPE = 'ASC' THEN `account_group`.`ACC_GROUP_DESCRIPTION` END ASC, 
		CASE WHEN PARAM_ORDER_FIELD = 'ACC_GROUP_DESCRIPTION' AND PARAM_ORDER_TYPE = 'DESC' THEN `account_group`.`ACC_GROUP_DESCRIPTION` END DESC,	
		
		-- GENDER
		CASE WHEN PARAM_ORDER_FIELD = 'SYS_GENDER_DESCRIPTION' AND PARAM_ORDER_TYPE = 'ASC' THEN `system_gender`.`SYS_GENDER_DESCRIPTION` END ASC, 
		CASE WHEN PARAM_ORDER_FIELD = 'SYS_GENDER_DESCRIPTION' AND PARAM_ORDER_TYPE = 'DESC' THEN `system_gender`.`SYS_GENDER_DESCRIPTION` END DESC,

		-- STATUS
		CASE WHEN PARAM_ORDER_FIELD = 'SYS_STATUS_DESCRIPTION' AND PARAM_ORDER_TYPE = 'ASC' THEN `system_status`.`SYS_STATUS_DESCRIPTION` END ASC, 
		CASE WHEN PARAM_ORDER_FIELD = 'SYS_STATUS_DESCRIPTION' AND PARAM_ORDER_TYPE = 'DESC' THEN `system_status`.`SYS_STATUS_DESCRIPTION` END DESC,
			
		-- EXTRA								
		CASE WHEN PARAM_ORDER_FIELD <> 'ACC_ACCOUNT_FIRST_NAME' THEN `account_member`.`ACC_ACCOUNT_FIRST_NAME` END ASC
																										
	LIMIT PARAM_SKIP, PARAM_LIMIT;
	LEAVE SP_GET;

END ;;
DELIMITER ;
/*!50003 SET sql_mode              = @saved_sql_mode */ ;
/*!50003 SET character_set_client  = @saved_cs_client */ ;
/*!50003 SET character_set_results = @saved_cs_results */ ;
/*!50003 SET collation_connection  = @saved_col_connection */ ;
/*!50003 DROP PROCEDURE IF EXISTS `ACCOUNT_MEMBER_LOGIN` */;
/*!50003 SET @saved_cs_client      = @@character_set_client */ ;
/*!50003 SET @saved_cs_results     = @@character_set_results */ ;
/*!50003 SET @saved_col_connection = @@collation_connection */ ;
/*!50003 SET character_set_client  = latin1 */ ;
/*!50003 SET character_set_results = latin1 */ ;
/*!50003 SET collation_connection  = latin1_swedish_ci */ ;
/*!50003 SET @saved_sql_mode       = @@sql_mode */ ;
/*!50003 SET sql_mode              = '' */ ;
DELIMITER ;;
CREATE DEFINER=`root`@`localhost` PROCEDURE `ACCOUNT_MEMBER_LOGIN`(
	IN `PARAM_ACC_ACCOUNT_USERNAME` VARCHAR(1000),
	IN `PARAM_ACC_ACCOUNT_PASSWORD` VARCHAR(1000),

	IN `PARAM_REQUESTER_USERNAME` VARCHAR(500),
	IN `PARAM_REQUESTER_PASSWORD` VARCHAR(500),
	IN `PARAM_REQUESTER_PROXY_ID` BIGINT,
	IN `PARAM_REQUESTER_PROXY_PASSWORD` VARCHAR(1000),
	IN `PARAM_REQUESTER_DEVICE_PUBLIC_KEY` VARCHAR(1000),
	IN `PARAM_REQUESTER_DEVICE_PRIVATE_KEY` VARCHAR(1000),
	
	IN `PARAM_REQUESTER_IP` VARCHAR(1000),
	IN `PARAM_UNIQUE_SESSION_ID` VARCHAR(1000),
	IN `PARAM_SUPPRESS_RETURN` BIT
)
SP_GET:
BEGIN

	-- Initialize
	-- _______________________________________________________________________

	-- Status
	-- ...........................................
	DECLARE STATUS_INACTIVE TINYINT DEFAULT 1;
	DECLARE STATUS_ACTIVE TINYINT DEFAULT 2;
	DECLARE STATUS_CLOSED TINYINT DEFAULT 3;
	DECLARE STATUS_COMPLETED TINYINT DEFAULT 4;

	-- Audit Handler
	-- ...........................................
	DECLARE TEMP_MODULE_KEYWORD VARCHAR(500) DEFAULT 'account_member';
	DECLARE TEMP_SP_OBJECTIVE VARCHAR(500) DEFAULT 'retrieve User account record';
	DECLARE TEMP_ERR_MESSAGE VARCHAR(500) DEFAULT '';
	DECLARE ERR BIGINT DEFAULT 0;
	DECLARE TEMP_RECORD_CHANGES VARCHAR(16000) DEFAULT '';
	DECLARE TEMP_RECORD_BINDED BIT DEFAULT 0;


	-- Authentication
	-- ...........................................
	DECLARE TEMP_ACCESS_RIGHTS_DENIED BIT DEFAULT 0;
	DECLARE TEMP_SYNC_SERVER_ID BIGINT DEFAULT 0;
	DECLARE TEMP_SYNC_IS_SERVER_REQUEST BIT DEFAULT 0;
	DECLARE TEMP_AUTHENTICATED_ACCOUNT_ID BIGINT DEFAULT `ACCOUNT_MEMBER@ACC_ACCOUNT_ID_FROM_LOGIN`(PARAM_REQUESTER_USERNAME, PARAM_REQUESTER_PASSWORD);
	DECLARE TEMP_AUTHENTICATED_ACCOUNT_PASSWORD VARCHAR(4000) DEFAULT 0;
	DECLARE TEMP_AUTHENTICATED_ACCOUNT_LEVEL BIGINT DEFAULT 0;
	DECLARE TEMP_AUTHENTICATED_ACCOUNT_GROUP BIGINT DEFAULT 0;
	
	
	-- Local value holder
	-- ...........................................
	
	
	-- Check NULLs
	-- ...........................................
	DECLARE IS_NULL_ACCOUNT_USERNAME BIT DEFAULT `SYSTEM_VAR@IS_NULL@NVARCHAR`(PARAM_ACC_ACCOUNT_USERNAME, 1);
	DECLARE IS_NULL_ACCOUNT_PASSWORD BIT DEFAULT `SYSTEM_VAR@IS_NULL@NVARCHAR`(PARAM_ACC_ACCOUNT_PASSWORD, 1);
	
	
	-- Error Handler
	-- _______________________________________________________________________
	DECLARE EXIT HANDLER FOR SQLEXCEPTION
	BEGIN
		RESIGNAL;
	END;


	-- Access Rights [Device]
	-- _______________________________________________________________________
	IF `ACCOUNT_DEVICE@HAS_PERMISSION`(PARAM_REQUESTER_DEVICE_PUBLIC_KEY, PARAM_REQUESTER_DEVICE_PRIVATE_KEY) = 0 THEN
		SET TEMP_ERR_MESSAGE = 'Your device is not authorized yet to access this server.';
		SET ERR = `RAISERROR`(TEMP_ERR_MESSAGE);		
	END IF;
	

	-- Parameter Validation
	-- _______________________________________________________________________
	IF IS_NULL_ACCOUNT_USERNAME = 1 THEN
		SET TEMP_ERR_MESSAGE = 'Username is required.';
		SET ERR = `RAISERROR`(TEMP_ERR_MESSAGE);	
	END IF;
	IF IS_NULL_ACCOUNT_PASSWORD = 1 THEN
		SET TEMP_ERR_MESSAGE = 'Password is required.';
		SET ERR = `RAISERROR`(TEMP_ERR_MESSAGE);	
	END IF;		
	IF TEMP_AUTHENTICATED_ACCOUNT_ID > 1 THEN -- Should not allow login when already authenticated
		SET TEMP_ERR_MESSAGE = 'Already authenticated. Must logout first to switch between users.';
		SET ERR = `RAISERROR`(TEMP_ERR_MESSAGE);		
	END IF;
	

	-- Bruteforce Pre-Login Process
	-- _______________________________________________________________________
	CALL `ACCOUNT_BFIP_PRE_LOGIN`
	(
		PARAM_REQUESTER_IP
	);


	-- Check Blocked Status
	-- _______________________________________________________________________
	IF
		`ACCOUNT_BFIP@IS_BANNED`
		(
			PARAM_ACC_ACCOUNT_USERNAME,
			PARAM_REQUESTER_IP
		) = 1
	THEN
		-- SET @TEMP_ERR_MESSAGE = 'Invalid username or password.';
		-- RAISERROR(@TEMP_ERR_MESSAGE, 11, 1);	
		LEAVE SP_GET;
	END IF; 


	-- LOGIN ATTEMPT
	-- _______________________________________________________________________
	
	-- Read Password Salt
	-- ####################################################
	SELECT
		`account_member`.`ACC_ACCOUNT_ID`,
		`account_member`.`ACC_ACCOUNT_ACC_LEVEL_ID`,
		`account_member`.`ACC_ACCOUNT_PASSWORD`
	INTO
		TEMP_AUTHENTICATED_ACCOUNT_ID,
		TEMP_AUTHENTICATED_ACCOUNT_LEVEL,
		TEMP_AUTHENTICATED_ACCOUNT_PASSWORD
	FROM `account_member`
	WHERE
		`account_member`.`ACC_ACCOUNT_USERNAME` = PARAM_ACC_ACCOUNT_USERNAME AND
		`account_member`.`ACC_ACCOUNT_STATUS` = 2
	LIMIT 1;		
	
	-- Checks the result
	-- ####################################################
	IF
		CHAR_LENGTH(TEMP_AUTHENTICATED_ACCOUNT_PASSWORD) <= 0 OR
		`FUN_SHA512_VERIFY`
		(
			TEMP_AUTHENTICATED_ACCOUNT_PASSWORD,
			PARAM_ACC_ACCOUNT_PASSWORD,
			1
		) = 0
	THEN
		-- SET @TEMP_ERR_MESSAGE = 'Invalid username or password.';
		-- RAISERROR(@TEMP_ERR_MESSAGE, 11, 1);		

		CALL `ACCOUNT_BFIP_POST_LOGIN`
		(
			0,
			PARAM_ACC_ACCOUNT_USERNAME,
			PARAM_ACC_ACCOUNT_PASSWORD,
			PARAM_REQUESTER_IP
		);

		LEAVE SP_GET;
	END IF;


	-- Check if Access Level if active (Status = 2)
	-- ####################################################
	IF
		(
			SELECT  COUNT(`account_level`.`ACC_LEVEL_ID`)
			FROM `account_level`
			WHERE
				`account_level`.`ACC_LEVEL_ID` = TEMP_AUTHENTICATED_ACCOUNT_LEVEL AND
				`account_level`.`ACC_LEVEL_STATUS` = STATUS_ACTIVE
			LIMIT 1
		) <= 0
	THEN
		LEAVE SP_GET;
	END IF;


	-- Prepare AccessRights
	-- _______________________________________________________________________

	-- Prepare Server (Self)
	-- _______________________________________________________________________
	-- CALL `ACCOUNT_SERVER_PREPARE`
	-- (
	-- 	PARAM_REQUESTER_USERNAME, PARAM_REQUESTER_PASSWORD,
	-- 	PARAM_REQUESTER_PROXY_ID, PARAM_REQUESTER_PROXY_PASSWORD,
	-- 	PARAM_REQUESTER_DEVICE_PUBLIC_KEY, PARAM_REQUESTER_DEVICE_PRIVATE_KEY,
	-- 	PARAM_REQUESTER_IP,
	-- 	PARAM_UNIQUE_SESSION_ID,
	-- 	1
	-- );
		
	-- Call for prepare Access Rights
	-- ####################################################
	CALL `ACCOUNT_ACCESS_RIGHTS_PREPARE`
	(
		TEMP_AUTHENTICATED_ACCOUNT_LEVEL,
		
		PARAM_ACC_ACCOUNT_USERNAME, PARAM_REQUESTER_PASSWORD,
		PARAM_REQUESTER_PROXY_ID, PARAM_REQUESTER_PROXY_PASSWORD,
		PARAM_REQUESTER_DEVICE_PUBLIC_KEY, PARAM_REQUESTER_DEVICE_PRIVATE_KEY,
		PARAM_REQUESTER_IP,
		PARAM_UNIQUE_SESSION_ID,
		1
	);


	-- Bruteforce Post-Login Process (Success)
	-- _______________________________________________________________________
	CALL `ACCOUNT_BFIP_POST_LOGIN`
	(
		1,
		PARAM_ACC_ACCOUNT_USERNAME,
		PARAM_ACC_ACCOUNT_PASSWORD,
		PARAM_REQUESTER_IP
	);


	-- RETURN RESULT
	-- _______________________________________________________________________
	SELECT
		TEMP_AUTHENTICATED_ACCOUNT_ID AS ACCOUNT_ID,
		TEMP_AUTHENTICATED_ACCOUNT_PASSWORD AS ACCOUNT_PASSWORD;


END ;;
DELIMITER ;
/*!50003 SET sql_mode              = @saved_sql_mode */ ;
/*!50003 SET character_set_client  = @saved_cs_client */ ;
/*!50003 SET character_set_results = @saved_cs_results */ ;
/*!50003 SET collation_connection  = @saved_col_connection */ ;
/*!50003 DROP PROCEDURE IF EXISTS `ACCOUNT_MEMBER_SAVE` */;
/*!50003 SET @saved_cs_client      = @@character_set_client */ ;
/*!50003 SET @saved_cs_results     = @@character_set_results */ ;
/*!50003 SET @saved_col_connection = @@collation_connection */ ;
/*!50003 SET character_set_client  = latin1 */ ;
/*!50003 SET character_set_results = latin1 */ ;
/*!50003 SET collation_connection  = latin1_swedish_ci */ ;
/*!50003 SET @saved_sql_mode       = @@sql_mode */ ;
/*!50003 SET sql_mode              = '' */ ;
DELIMITER ;;
CREATE DEFINER=`root`@`localhost` PROCEDURE `ACCOUNT_MEMBER_SAVE`(
	IN `PARAM_ACC_ACCOUNT_ID` BIGINT,
	IN `PARAM_ACC_ACCOUNT_SERVER_ID` BIGINT,
	IN `PARAM_ACC_ACCOUNT_ACC_LEVEL_ID` BIGINT,
	IN `PARAM_ACC_ACCOUNT_ACC_LEVEL_SERVER_ID` BIGINT,
	IN `PARAM_ACC_ACCOUNT_ACC_GROUP_ID` BIGINT,
	IN `PARAM_ACC_ACCOUNT_ADD_RESOURCE_ID` BIGINT,

	IN `PARAM_ACC_ACCOUNT_USERNAME` VARCHAR(1000),
	IN `PARAM_ACC_ACCOUNT_PASSWORD` VARCHAR(1000),
	IN `PARAM_ACC_ACCOUNT_AUTH_CODE` VARCHAR(1000),
	IN `PARAM_ACC_ACCOUNT_FIRST_NAME` VARCHAR(1000),
	IN `PARAM_ACC_ACCOUNT_MIDDLE_NAME` VARCHAR(1000),
	IN `PARAM_ACC_ACCOUNT_LAST_NAME` VARCHAR(1000),

	IN `PARAM_ACC_ACCOUNT_SYS_GENDER_ID` TINYINT,
	IN `PARAM_ACC_ACCOUNT_POSITION` VARCHAR(1000),
	IN `PARAM_ACC_ACCOUNT_STATUS` TINYINT,
	
	IN `PARAM_REQUESTER_USERNAME` VARCHAR(500),
	IN `PARAM_REQUESTER_PASSWORD` VARCHAR(500),
	IN `PARAM_REQUESTER_PROXY_ID` BIGINT,
	IN `PARAM_REQUESTER_PROXY_PASSWORD` VARCHAR(500),
	IN `PARAM_REQUESTER_DEVICE_PUBLIC_KEY` VARCHAR(500),
	IN `PARAM_REQUESTER_DEVICE_PRIVATE_KEY` VARCHAR(500),  

	IN `PARAM_REQUESTER_IP` VARCHAR(1000),
	IN `PARAM_UNIQUE_SESSION_ID` VARCHAR(1000),
	IN `PARAM_SUPPRESS_RETURN` BIT,
	
	IN `PARAM_SYNC_SERVER_DESCRIPTION` VARCHAR(500), 
	IN `PARAM_SYNC_SERVER_UNIQUE_KEY` VARCHAR(500)
)
SP_SAVE:
BEGIN

	-- 1) DECLARE LOCAL PARAMETERS
	-- ====================================================================================================================================================================
	-- Status
	-- ...........................................
	DECLARE STATUS_INACTIVE TINYINT DEFAULT 1;
	DECLARE STATUS_ACTIVE TINYINT DEFAULT 2;
	DECLARE STATUS_CLOSED TINYINT DEFAULT 3;
	DECLARE STATUS_COMPLETED TINYINT DEFAULT 4;
	
	-- Audit Handler
	-- ...........................................
	DECLARE TEMP_RECORD_EXISTS BIT DEFAULT 0;
	DECLARE TEMP_MODULE_KEYWORD VARCHAR(500) DEFAULT 'account_member';
	DECLARE TEMP_SP_OBJECTIVE VARCHAR(500) DEFAULT 'add/edit account_member record';
	DECLARE TEMP_ERR_MESSAGE VARCHAR(500) DEFAULT '';
	DECLARE ERR BIGINT DEFAULT 0;
	DECLARE TEMP_RECORD_CHANGES VARCHAR(16000) DEFAULT '';
	DECLARE TEMP_RECORD_BINDED BIT DEFAULT 0;

	-- Authentication
	-- ...........................................
	DECLARE TEMP_ACCESS_RIGHTS_DENIED BIT DEFAULT 0;
	DECLARE TEMP_ACCESS_RIGHTS_HAS_OVERRIDE BIT DEFAULT 0;
	DECLARE TEMP_SYNC_SERVER_ID BIGINT DEFAULT 0;
	DECLARE TEMP_SYNC_IS_SERVER_REQUEST BIT DEFAULT 0;
	DECLARE TEMP_AUTHENTICATED_ACCOUNT_ID BIGINT DEFAULT `ACCOUNT_MEMBER@ACC_ACCOUNT_ID_FROM_LOGIN`(PARAM_REQUESTER_USERNAME, PARAM_REQUESTER_PASSWORD);
	DECLARE TEMP_AUTHENTICATED_ACCOUNT_LEVEL BIGINT DEFAULT 0;

	DECLARE TEMP_NOW DATETIME(6) DEFAULT `SYSTEM_VAR@NOW`('', 1);

	-- Local value holder
	-- ...........................................
	DECLARE PARAM_ACC_ACCOUNT_SYSTEM_GENERATED TINYINT DEFAULT 0;
		
	DECLARE TEMP_ACC_ACCOUNT_SERVER_ID BIGINT DEFAULT 0;
	DECLARE TEMP_ACC_ACCOUNT_ACC_LEVEL_ID BIGINT DEFAULT 0;
	DECLARE TEMP_ACC_ACCOUNT_ACC_GROUP_ID BIGINT DEFAULT 0;
	DECLARE TEMP_ACC_ACCOUNT_ADD_RESOURCE_ID BIGINT DEFAULT 0;


	DECLARE TEMP_ACC_ACCOUNT_USERNAME VARCHAR(1000) DEFAULT '';
	DECLARE TEMP_ACC_ACCOUNT_PASSWORD VARCHAR(1000) DEFAULT '';
	DECLARE TEMP_ACC_ACCOUNT_AUTH_CODE VARCHAR(500) DEFAULT ''; 
	DECLARE TEMP_ACC_ACCOUNT_AUTH_CODE_BEFORE_EDIT VARCHAR(500) DEFAULT ''; 
	
	DECLARE TEMP_ACC_ACCOUNT_FIRST_NAME VARCHAR(1000) DEFAULT '';
	DECLARE TEMP_ACC_ACCOUNT_MIDDLE_NAME VARCHAR(1000) DEFAULT '';
	DECLARE TEMP_ACC_ACCOUNT_LAST_NAME VARCHAR(1000) DEFAULT '';

	DECLARE TEMP_ACC_ACCOUNT_GENDER_ID TINYINT DEFAULT 0;
	DECLARE TEMP_ACC_ACCOUNT_POSITION VARCHAR(1000) DEFAULT '';

	DECLARE TEMP_ACC_ACCOUNT_STATUS TINYINT DEFAULT 0;
	DECLARE TEMP_ACC_ACCOUNT_SYSTEM_GENERATED TINYINT DEFAULT 0;

	DECLARE TEMP_ACC_PROXY_AUTH_OWNER VARCHAR(1000) DEFAULT '';	
	DECLARE TEMP_ACC_PROXY_AUTH_HASH VARCHAR(1000) DEFAULT '';
	
	-- ====================================================================================================================================================================

	
	
	-- 2) Try Catch / Throw
	-- ====================================================================================================================================================================
	DECLARE EXIT HANDLER FOR SQLEXCEPTION
	BEGIN
		RESIGNAL;
	END;
	-- ====================================================================================================================================================================
	
	
	-- 3) Prepare SYNC
	-- ====================================================================================================================================================================

	-- IS SERVE REQUEST
	IF
		`SYSTEM_VAR@IS_NULL@NVARCHAR`(PARAM_SYNC_SERVER_DESCRIPTION, 1) = 0 AND
		`SYSTEM_VAR@IS_NULL@NVARCHAR`(PARAM_SYNC_SERVER_UNIQUE_KEY, 1) = 0
	THEN
	
		-- .....................................................
		
		-- SET REQUEST CAME FROM SYNC 
		SET TEMP_SYNC_IS_SERVER_REQUEST = 1;
		
		-- USE SYSTEM ACCOUNT
		IF `ACCOUNT_SERVER@HAS_PERMISSION`(PARAM_SYNC_SERVER_DESCRIPTION, PARAM_SYNC_SERVER_UNIQUE_KEY) = 1 THEN
			SELECT
				`account_member`.`ACC_ACCOUNT_USERNAME`,
				`account_member`.`ACC_ACCOUNT_PASSWORD`
			INTO
				PARAM_REQUESTER_USERNAME,
				PARAM_REQUESTER_PASSWORD
			FROM `account_member`
			WHERE
				`account_member`.`ACC_ACCOUNT_USERNAME` = 'system'
			LIMIT 1;
		ELSE
			SET PARAM_REQUESTER_USERNAME = '';
			SET PARAM_REQUESTER_PASSWORD = '';
		END IF;
		
		-- GET SERVER ID
		SET TEMP_SYNC_SERVER_ID = `ACCOUNT_SERVER@ACC_SERVER_ID_FROM_LOGIN`(PARAM_SYNC_SERVER_DESCRIPTION, PARAM_SYNC_SERVER_UNIQUE_KEY);
		
		-- .....................................................
	
	
		-- GET LOCAL ID
		SET PARAM_ACC_ACCOUNT_ACC_LEVEL_ID = `ACCOUNT_LEVEL@ACC_LEVEL_ID_FROM_SERVER_ID`
							(
								PARAM_ACC_ACCOUNT_ACC_LEVEL_ID,
								PARAM_ACC_ACCOUNT_ACC_LEVEL_SERVER_ID,

								null
							);
						
		SET PARAM_ACC_ACCOUNT_ID = `ACCOUNT_MEMBER@ACC_ACCOUNT_ID_FROM_SERVER_ID`
							(
								PARAM_ACC_ACCOUNT_ID,
								PARAM_ACC_ACCOUNT_SERVER_ID,

								PARAM_ACC_ACCOUNT_FIRST_NAME,
								PARAM_ACC_ACCOUNT_MIDDLE_NAME,
								PARAM_ACC_ACCOUNT_LAST_NAME
							);	

		
	END IF;
	
	-- IS RECORD EXISTS					
	SET TEMP_RECORD_EXISTS = `ACCOUNT_MEMBER@ACC_ACCOUNT_ID_EXISTS`(PARAM_ACC_ACCOUNT_ID, 0);
	
	-- ====================================================================================================================================================================
		
		
	-- 3) IF ALREADY EXIST, FILL MISSING DATA
	-- ====================================================================================================================================================================
	IF TEMP_RECORD_EXISTS = 1 THEN
	
		-- Do not change username / password details on sync.
		-- ...........................................
		IF TEMP_SYNC_IS_SERVER_REQUEST = 1 THEN
			SET PARAM_ACC_ACCOUNT_USERNAME = '';
			SET PARAM_ACC_ACCOUNT_PASSWORD = '';
		END IF;


		SELECT
			`account_member`.`ACC_ACCOUNT_SERVER_ID`,
			`account_member`.`ACC_ACCOUNT_ACC_LEVEL_ID`,
			`account_member`.`ACC_ACCOUNT_ACC_GROUP_ID`,
			`account_member`.`ACC_ACCOUNT_ADD_RESOURCE_ID`,

			`account_member`.`ACC_ACCOUNT_USERNAME`,
			`account_member`.`ACC_ACCOUNT_PASSWORD`,
			`account_member`.`ACC_ACCOUNT_AUTH_CODE`, 	
			
			`account_member`.`ACC_ACCOUNT_FIRST_NAME`,
			`account_member`.`ACC_ACCOUNT_MIDDLE_NAME`,
			`account_member`.`ACC_ACCOUNT_LAST_NAME`,

			`account_member`.`ACC_ACCOUNT_SYS_GENDER_ID`,
			`account_member`.`ACC_ACCOUNT_POSITION`,
	
			`account_member`.`ACC_ACCOUNT_STATUS`,
			`account_member`.`ACC_ACCOUNT_SYSTEM_GENERATED`
		INTO
			TEMP_ACC_ACCOUNT_SERVER_ID,
			TEMP_ACC_ACCOUNT_ACC_LEVEL_ID,
			TEMP_ACC_ACCOUNT_ACC_GROUP_ID,
			TEMP_ACC_ACCOUNT_ADD_RESOURCE_ID,

			TEMP_ACC_ACCOUNT_USERNAME,
			TEMP_ACC_ACCOUNT_PASSWORD,
			TEMP_ACC_ACCOUNT_AUTH_CODE, 	
			
			TEMP_ACC_ACCOUNT_FIRST_NAME,
			TEMP_ACC_ACCOUNT_MIDDLE_NAME,
			TEMP_ACC_ACCOUNT_LAST_NAME,

			TEMP_ACC_ACCOUNT_GENDER_ID,
			TEMP_ACC_ACCOUNT_POSITION,
	
			TEMP_ACC_ACCOUNT_STATUS,
			TEMP_ACC_ACCOUNT_SYSTEM_GENERATED
		FROM `account_member`
		WHERE
			`account_member`.`ACC_ACCOUNT_ID` = PARAM_ACC_ACCOUNT_ID
		LIMIT 1;

	
		-- Replace NULLs with the existing data.
		-- ...........................................
		SET PARAM_ACC_ACCOUNT_SERVER_ID = `SYSTEM_VAR@REPLACE_NULL@BIGINT`(PARAM_ACC_ACCOUNT_SERVER_ID, TEMP_ACC_ACCOUNT_SERVER_ID, 1, 1);
		SET PARAM_ACC_ACCOUNT_ACC_LEVEL_ID = `SYSTEM_VAR@REPLACE_NULL@BIGINT`(PARAM_ACC_ACCOUNT_ACC_LEVEL_ID, TEMP_ACC_ACCOUNT_ACC_LEVEL_ID, 1, 1);
		SET PARAM_ACC_ACCOUNT_ACC_GROUP_ID = `SYSTEM_VAR@REPLACE_NULL@BIGINT`(PARAM_ACC_ACCOUNT_ACC_GROUP_ID, TEMP_ACC_ACCOUNT_ACC_GROUP_ID, 1, 1);
		SET PARAM_ACC_ACCOUNT_ADD_RESOURCE_ID = `SYSTEM_VAR@REPLACE_NULL@BIGINT`(PARAM_ACC_ACCOUNT_ADD_RESOURCE_ID, TEMP_ACC_ACCOUNT_ADD_RESOURCE_ID, 1, 1);
		
		SET PARAM_ACC_ACCOUNT_USERNAME = `SYSTEM_VAR@REPLACE_NULL@NVARCHAR`(PARAM_ACC_ACCOUNT_USERNAME, TEMP_ACC_ACCOUNT_USERNAME, 1);
		SET PARAM_ACC_ACCOUNT_PASSWORD = `SYSTEM_VAR@REPLACE_NULL@NVARCHAR`(PARAM_ACC_ACCOUNT_PASSWORD, TEMP_ACC_ACCOUNT_PASSWORD, 1);
		SET PARAM_ACC_ACCOUNT_AUTH_CODE = `SYSTEM_VAR@REPLACE_NULL@NVARCHAR`(PARAM_ACC_ACCOUNT_AUTH_CODE, TEMP_ACC_ACCOUNT_AUTH_CODE, 1);
		
		SET PARAM_ACC_ACCOUNT_FIRST_NAME = `SYSTEM_VAR@REPLACE_NULL@NVARCHAR`(PARAM_ACC_ACCOUNT_FIRST_NAME, TEMP_ACC_ACCOUNT_FIRST_NAME, 1);
		SET PARAM_ACC_ACCOUNT_MIDDLE_NAME = `SYSTEM_VAR@REPLACE_NULL@NVARCHAR`(PARAM_ACC_ACCOUNT_MIDDLE_NAME, TEMP_ACC_ACCOUNT_MIDDLE_NAME,0);
		SET PARAM_ACC_ACCOUNT_LAST_NAME = `SYSTEM_VAR@REPLACE_NULL@NVARCHAR`(PARAM_ACC_ACCOUNT_LAST_NAME, TEMP_ACC_ACCOUNT_LAST_NAME, 1);

		SET PARAM_ACC_ACCOUNT_SYS_GENDER_ID = `SYSTEM_VAR@REPLACE_NULL@TINYINT`(PARAM_ACC_ACCOUNT_SYS_GENDER_ID, TEMP_ACC_ACCOUNT_GENDER_ID, 1, 1);
		SET PARAM_ACC_ACCOUNT_POSITION = `SYSTEM_VAR@REPLACE_NULL@NVARCHAR`(PARAM_ACC_ACCOUNT_POSITION, TEMP_ACC_ACCOUNT_POSITION, 1);

		SET PARAM_ACC_ACCOUNT_STATUS = `SYSTEM_VAR@REPLACE_NULL@TINYINT`(PARAM_ACC_ACCOUNT_STATUS, TEMP_ACC_ACCOUNT_STATUS, 1, 1);
	
		-- AUTO GEN (NON-UPDATABLES)		
		-- ...........................................
		SET PARAM_ACC_ACCOUNT_SYSTEM_GENERATED = TEMP_ACC_ACCOUNT_SYSTEM_GENERATED;
		
	ELSE
		SET PARAM_ACC_ACCOUNT_SERVER_ID = `SYSTEM_VAR@REPLACE_NULL@BIGINT`(PARAM_ACC_ACCOUNT_SERVER_ID, 0, 1, 1);
		SET PARAM_ACC_ACCOUNT_ACC_LEVEL_ID = `SYSTEM_VAR@REPLACE_NULL@BIGINT`(PARAM_ACC_ACCOUNT_ACC_LEVEL_ID, 0, 1, 1);
		SET PARAM_ACC_ACCOUNT_ACC_GROUP_ID = `SYSTEM_VAR@REPLACE_NULL@BIGINT`(PARAM_ACC_ACCOUNT_ACC_GROUP_ID, 1, 1, 1);
		SET PARAM_ACC_ACCOUNT_ADD_RESOURCE_ID = `SYSTEM_VAR@REPLACE_NULL@BIGINT`(PARAM_ACC_ACCOUNT_ADD_RESOURCE_ID, 0, 1, 1);
		
		SET PARAM_ACC_ACCOUNT_AUTH_CODE = `SYSTEM_VAR@REPLACE_NULL@NVARCHAR`(PARAM_ACC_ACCOUNT_AUTH_CODE , '', 1);
		SET PARAM_ACC_ACCOUNT_POSITION = `SYSTEM_VAR@REPLACE_NULL@NVARCHAR`(PARAM_ACC_ACCOUNT_POSITION, '', 1);
		
	END IF;
	-- ====================================================================================================================================================================

	
	
	-- 4) PREPARE AUDIT TRAIL
	-- ====================================================================================================================================================================
	
	IF TEMP_ACC_ACCOUNT_SERVER_ID <> PARAM_ACC_ACCOUNT_SERVER_ID THEN
		SET TEMP_RECORD_CHANGES = 
		`SYSTEM_VAR@CONCAT_ADD`(' | ', TEMP_RECORD_CHANGES, CONCAT_WS(' ', 'SERVER_ID: "', TEMP_ACC_ACCOUNT_SERVER_ID, '" > "', PARAM_ACC_ACCOUNT_SERVER_ID, '"'));	
	END IF;
	IF PARAM_ACC_ACCOUNT_ACC_LEVEL_ID <> TEMP_ACC_ACCOUNT_ACC_LEVEL_ID THEN
		SET TEMP_RECORD_CHANGES = 
		`SYSTEM_VAR@CONCAT_ADD`(' | ', TEMP_RECORD_CHANGES, CONCAT_WS(' ', 'LEVEL: "', TEMP_ACC_ACCOUNT_ACC_LEVEL_ID, '" > "', PARAM_ACC_ACCOUNT_ACC_LEVEL_ID, '"'));	
	END IF;
	IF PARAM_ACC_ACCOUNT_ACC_GROUP_ID <> TEMP_ACC_ACCOUNT_ACC_GROUP_ID THEN
		SET TEMP_RECORD_CHANGES = 
		`SYSTEM_VAR@CONCAT_ADD`(' | ', TEMP_RECORD_CHANGES, CONCAT_WS(' ', 'GROUP: "', TEMP_ACC_ACCOUNT_ACC_GROUP_ID, '" > "', PARAM_ACC_ACCOUNT_ACC_GROUP_ID, '"'));	
	END IF;
	IF PARAM_ACC_ACCOUNT_ADD_RESOURCE_ID <> TEMP_ACC_ACCOUNT_ADD_RESOURCE_ID THEN
		SET TEMP_RECORD_CHANGES = 
		`SYSTEM_VAR@CONCAT_ADD`(' | ', TEMP_RECORD_CHANGES, CONCAT_WS(' ', 'RESOURCE: "', TEMP_ACC_ACCOUNT_ADD_RESOURCE_ID, '" > "', PARAM_ACC_ACCOUNT_ADD_RESOURCE_ID, '"'));	
	END IF;		
	
	IF BINARY TEMP_ACC_ACCOUNT_USERNAME <> PARAM_ACC_ACCOUNT_USERNAME THEN
		SET TEMP_RECORD_CHANGES = 
		`SYSTEM_VAR@CONCAT_ADD`(' | ', TEMP_RECORD_CHANGES, CONCAT_WS(' ', 'USERNAME: "', TEMP_ACC_ACCOUNT_USERNAME, '" > "', PARAM_ACC_ACCOUNT_USERNAME, '"'));
	END IF;
			
	IF BINARY TEMP_ACC_ACCOUNT_PASSWORD <> PARAM_ACC_ACCOUNT_PASSWORD THEN
	
		-- HASH Password
		-- ####################################################
		SET PARAM_ACC_ACCOUNT_PASSWORD = `FUN_SHA512`(PARAM_ACC_ACCOUNT_PASSWORD, 1);			
		SET TEMP_RECORD_CHANGES = 
		`SYSTEM_VAR@CONCAT_ADD`(' | ', TEMP_RECORD_CHANGES, 'PASSWORD: "******" > "******"');
		
	END IF;
	IF BINARY TEMP_ACC_ACCOUNT_AUTH_CODE <> PARAM_ACC_ACCOUNT_AUTH_CODE THEN
		SET TEMP_RECORD_CHANGES = 
		`SYSTEM_VAR@CONCAT_ADD`(' | ', TEMP_RECORD_CHANGES, 'AUTH CODE: "******" > "******"');			
	END IF;	
	
	IF BINARY TEMP_ACC_ACCOUNT_FIRST_NAME <> PARAM_ACC_ACCOUNT_FIRST_NAME THEN
		SET TEMP_RECORD_CHANGES = 
		`SYSTEM_VAR@CONCAT_ADD`(' | ', TEMP_RECORD_CHANGES, CONCAT_WS(' ', 'FIRST NAME: "', TEMP_ACC_ACCOUNT_FIRST_NAME, '" > "', PARAM_ACC_ACCOUNT_FIRST_NAME, '"'));
	END IF;
	IF BINARY TEMP_ACC_ACCOUNT_MIDDLE_NAME <> PARAM_ACC_ACCOUNT_MIDDLE_NAME THEN
		SET TEMP_RECORD_CHANGES = 
		`SYSTEM_VAR@CONCAT_ADD`(' | ', TEMP_RECORD_CHANGES, CONCAT_WS(' ', 'MIDDLE NAME: "', TEMP_ACC_ACCOUNT_MIDDLE_NAME, '" > "', PARAM_ACC_ACCOUNT_MIDDLE_NAME, '"'));
	END IF;
	IF BINARY TEMP_ACC_ACCOUNT_LAST_NAME <> PARAM_ACC_ACCOUNT_LAST_NAME THEN
		SET TEMP_RECORD_CHANGES = 
		`SYSTEM_VAR@CONCAT_ADD`(' | ', TEMP_RECORD_CHANGES, CONCAT_WS(' ', 'LAST NAME: "', TEMP_ACC_ACCOUNT_LAST_NAME, '" > "', PARAM_ACC_ACCOUNT_LAST_NAME, '"'));
	END IF;
	IF TEMP_ACC_ACCOUNT_GENDER_ID <> PARAM_ACC_ACCOUNT_SYS_GENDER_ID THEN
		SET @TEMP_RECORD_CHANGES = 
		`SYSTEM_VAR@CONCAT_ADD`
		(
			' | ', TEMP_RECORD_CHANGES, CONCAT_WS
			(
				' ',
				'GENDER: ', TEMP_ACC_ACCOUNT_GENDER_ID, ' ("', `SYSTEM_GENDER@SYS_GENDER_DESCRIPTION_FROM_ID`(TEMP_ACC_ACCOUNT_GENDER_ID), '")',
				' > ', PARAM_ACC_ACCOUNT_SYS_GENDER_ID, ' ("', `SYSTEM_GENDER@SYS_GENDER_DESCRIPTION_FROM_ID`(PARAM_ACC_ACCOUNT_SYS_GENDER_ID), '")'
			)
		);
	END IF;

	IF BINARY TEMP_ACC_ACCOUNT_POSITION <> PARAM_ACC_ACCOUNT_POSITION THEN
		SET TEMP_RECORD_CHANGES = 
		`SYSTEM_VAR@CONCAT_ADD`(' | ', TEMP_RECORD_CHANGES, CONCAT_WS(' ', 'ACCOUNT_POSITION: "', TEMP_ACC_ACCOUNT_POSITION, '" > "', PARAM_ACC_ACCOUNT_POSITION, '"'));
	END IF;
	IF TEMP_ACC_ACCOUNT_STATUS <> PARAM_ACC_ACCOUNT_STATUS THEN
		SET TEMP_RECORD_CHANGES = 
		`SYSTEM_VAR@CONCAT_ADD`
		(
			' | ', TEMP_RECORD_CHANGES, CONCAT_WS
			(
				' ',
				'STATUS: ', TEMP_ACC_ACCOUNT_STATUS, '("', `SYSTEM_STATUS@SYS_STATUS_DESCRIPTION_FROM_ID`(TEMP_ACC_ACCOUNT_STATUS), '")',
				' > ', PARAM_ACC_ACCOUNT_STATUS, '("', `SYSTEM_STATUS@SYS_STATUS_DESCRIPTION_FROM_ID`(PARAM_ACC_ACCOUNT_STATUS), '")'
			)
		);
	END IF;

	-- No Changes in data, reject request
	-- ...........................................
	IF CHAR_LENGTH(TEMP_RECORD_CHANGES) = 0 THEN
		IF PARAM_SUPPRESS_RETURN = 0 THEN
			SELECT 
				PARAM_ACC_ACCOUNT_ID AS INSERTED_ID,
				1 AS SAVE_ABORTED;
		END IF;
		LEAVE SP_SAVE;
	END IF;
		
	-- ====================================================================================================================================================================

	
	-- 5) VALIDATE
	-- ====================================================================================================================================================================
	
	IF TEMP_SYNC_IS_SERVER_REQUEST = 0 THEN

		-- When Auth Code is edited
		-- ...........................................
		IF 
			TEMP_ACC_ACCOUNT_AUTH_CODE <> PARAM_ACC_ACCOUNT_AUTH_CODE AND
			`SYSTEM_VAR@IS_NULL@NVARCHAR`(PARAM_ACC_ACCOUNT_AUTH_CODE, 1) = 0
		THEN	
			-- CACHE AuthCode
			-- ####################################################
			SET TEMP_ACC_ACCOUNT_AUTH_CODE_BEFORE_EDIT = TEMP_ACC_ACCOUNT_AUTH_CODE;
			SET TEMP_ACC_ACCOUNT_AUTH_CODE = PARAM_ACC_ACCOUNT_AUTH_CODE;
						
			-- HASH AuthCode
			-- ####################################################
			SET PARAM_ACC_ACCOUNT_AUTH_CODE = `FUN_SHA512`(PARAM_ACC_ACCOUNT_AUTH_CODE , 1);		
		END IF;			
		
		-- Requires AuthCode when Username / Password is edited [If AuthCode is not blank]
		-- ...........................................
		IF 
			TEMP_ACC_ACCOUNT_AUTH_CODE = PARAM_ACC_ACCOUNT_AUTH_CODE AND
			`SYSTEM_VAR@IS_NULL@NVARCHAR`(PARAM_ACC_ACCOUNT_AUTH_CODE, 1) = 1 AND
			`SYSTEM_VAR@IS_NULL@NVARCHAR`(TEMP_ACC_ACCOUNT_AUTH_CODE, 1) = 0 AND
			(
				BINARY TEMP_ACC_ACCOUNT_USERNAME <> PARAM_ACC_ACCOUNT_USERNAME OR
				BINARY TEMP_ACC_ACCOUNT_PASSWORD <> PARAM_ACC_ACCOUNT_PASSWORD
			)
		THEN
			SET TEMP_ERR_MESSAGE = 'Authentication Code is required for changing Username or Password.';
			SET ERR = `RAISERROR`(TEMP_ERR_MESSAGE);		
		END IF;

		-- System Generated
		-- ...........................................
		IF 
			TEMP_ACC_ACCOUNT_SYSTEM_GENERATED = 2 AND
			(
				PARAM_ACC_ACCOUNT_ACC_LEVEL_ID <> TEMP_ACC_ACCOUNT_ACC_LEVEL_ID OR
				PARAM_ACC_ACCOUNT_ACC_GROUP_ID <> TEMP_ACC_ACCOUNT_ACC_GROUP_ID OR

				PARAM_ACC_ACCOUNT_USERNAME <> TEMP_ACC_ACCOUNT_USERNAME OR
				PARAM_ACC_ACCOUNT_FIRST_NAME <> TEMP_ACC_ACCOUNT_FIRST_NAME OR
				PARAM_ACC_ACCOUNT_MIDDLE_NAME <> TEMP_ACC_ACCOUNT_MIDDLE_NAME OR
				PARAM_ACC_ACCOUNT_LAST_NAME <> TEMP_ACC_ACCOUNT_LAST_NAME OR
			
				PARAM_ACC_ACCOUNT_SYS_GENDER_ID <> TEMP_ACC_ACCOUNT_GENDER_ID OR
				PARAM_ACC_ACCOUNT_POSITION <> TEMP_ACC_ACCOUNT_POSITION OR
		
				PARAM_ACC_ACCOUNT_STATUS <> TEMP_ACC_ACCOUNT_STATUS
			)
		THEN
			CALL `VALIDATION_SYSTEM_GENERATED`(PARAM_ACC_ACCOUNT_ID, PARAM_ACC_ACCOUNT_USERNAME, 'password');
		END IF;

	
		-- Access level validation
		-- ...........................................
		IF `ACCOUNT_LEVEL@ACC_LEVEL_ID_EXISTS`(PARAM_ACC_ACCOUNT_ACC_LEVEL_ID, 0) = 0 THEN
			SET TEMP_ERR_MESSAGE = CONCAT_WS(' ', 'Given Access level does not exists or is inactive.', PARAM_ACC_ACCOUNT_ACC_LEVEL_ID, '(', `ACCOUNT_LEVEL@ACC_LEVEL_DESCRIPTION_FROM_ID`(PARAM_ACC_ACCOUNT_ACC_LEVEL_ID), ')');
			SET ERR = `RAISERROR`(TEMP_ERR_MESSAGE);
		END IF;

		-- Group Validation
		-- ...........................................
		IF `ACCOUNT_GROUP@ACC_GROUP_ID_EXISTS`(PARAM_ACC_ACCOUNT_ACC_GROUP_ID,0) = 0 THEN
			SET TEMP_ERR_MESSAGE = CONCAT_WS(' ', 'Given Account Group does not exists or is inactive.', PARAM_ACC_ACCOUNT_ACC_GROUP_ID, '(NULL)');
			SET ERR = `RAISERROR`(TEMP_ERR_MESSAGE);		
		END IF;
		
		-- Profile Picture
		-- ...........................................
		IF 
			PARAM_ACC_ACCOUNT_ADD_RESOURCE_ID > 0 AND
			`ADDON_RESOURCE@ADD_RESOURCE_ID_EXISTS`(PARAM_ACC_ACCOUNT_ADD_RESOURCE_ID, 0) = 0
		THEN
			SET TEMP_ERR_MESSAGE = CONCAT_WS(' ', 'Given Account Profile does not exists or is inactive.', PARAM_ACC_ACCOUNT_ADD_RESOURCE_ID, '(NULL)');
			SET ERR = `RAISERROR`(TEMP_ERR_MESSAGE);				
		END IF;
		
		-- Gender Validation
		-- ...........................................
		IF `SYSTEM_GENDER@SYS_GENDER_ID_EXISTS`(PARAM_ACC_ACCOUNT_SYS_GENDER_ID, 0) = 0 THEN
			SET TEMP_ERR_MESSAGE = CONCAT_WS(' ', 'Given STATUS does not exists or is inactive. ', PARAM_ACC_ACCOUNT_SYS_GENDER_ID);
			SET ERR = `RAISERROR`(TEMP_ERR_MESSAGE);
		END IF;
	
		-- Status Validation
		-- ...........................................
		IF `SYSTEM_STATUS@SYS_STATUS_ID_EXISTS`(PARAM_ACC_ACCOUNT_STATUS, 1) = 0 THEN
			SET TEMP_ERR_MESSAGE = CONCAT_WS(' ', 'Given STATUS does not exists or is inactive. ID: ', PARAM_ACC_ACCOUNT_STATUS);
			SET ERR = `RAISERROR`(TEMP_ERR_MESSAGE);
		END IF;
				
		-- Missing Fields
		-- ...........................................
		IF `SYSTEM_VAR@IS_NULL@NVARCHAR`(PARAM_ACC_ACCOUNT_USERNAME, 1) = 1 THEN
			CALL `VALIDATION_MISSING_FIELD`('`USERNAME`', '`NULL`');
		END IF;
		IF `SYSTEM_VAR@IS_NULL@NVARCHAR`(PARAM_ACC_ACCOUNT_PASSWORD, 1) = 1 THEN
			CALL `VALIDATION_MISSING_FIELD`('`PASSWORD`', '`NULL`');
		END IF;
		IF `SYSTEM_VAR@IS_NULL@NVARCHAR`(PARAM_ACC_ACCOUNT_FIRST_NAME, 1) = 1 THEN
			CALL `VALIDATION_MISSING_FIELD`('`FIRST NAME`', '`NULL`');
		END IF;
		IF `SYSTEM_VAR@IS_NULL@NVARCHAR`(PARAM_ACC_ACCOUNT_LAST_NAME, 1) = 1 THEN
			CALL `VALIDATION_MISSING_FIELD`('`LAST NAME`', '`NULL`');
		END IF;
	
		-- Redundant Entry
		-- ...........................................
		IF
		(
			SELECT COUNT(`account_member`.`ACC_ACCOUNT_USERNAME`)
			FROM `account_member`
			WHERE
				`account_member`.`ACC_ACCOUNT_USERNAME` = PARAM_ACC_ACCOUNT_USERNAME AND
				`account_member`.`ACC_ACCOUNT_ID` <> PARAM_ACC_ACCOUNT_ID
			LIMIT 1
		) >= 1
		THEN
			CALL `VALIDATION_REDUNDANT_ENTRY`(PARAM_ACC_ACCOUNT_USERNAME);
		END IF;

	END IF;
	
	
	-- Access Rights [Device]
	-- ####################################################
	IF `ACCOUNT_DEVICE@HAS_PERMISSION`(PARAM_REQUESTER_DEVICE_PUBLIC_KEY, PARAM_REQUESTER_DEVICE_PRIVATE_KEY) = 0 THEN
		SET TEMP_ERR_MESSAGE = 'Your device is not authorized yet to access this server.';
		SET ERR = `RAISERROR`(TEMP_ERR_MESSAGE);		
	END IF;
	

	-- Access Rights [Account] (w/ Exception for editing own Username/Password), exception on new account.
	-- ####################################################
	IF
		(
			PARAM_ACC_ACCOUNT_ID > 0 OR
			PARAM_ACC_ACCOUNT_ACC_LEVEL_ID <> 1
		) AND 
		PARAM_ACC_ACCOUNT_ID <> TEMP_AUTHENTICATED_ACCOUNT_ID AND 
		`ACCOUNT_ACCESS_RIGHTS@HAS_PERMISSION`(PARAM_REQUESTER_USERNAME, PARAM_REQUESTER_PASSWORD, 0, TEMP_MODULE_KEYWORD, 3) = 0
	THEN
		-- For User with no edit rights, Limited Edit Only
		IF 
			(
				PARAM_ACC_ACCOUNT_ID > 0 AND
				PARAM_ACC_ACCOUNT_ID <> TEMP_AUTHENTICATED_ACCOUNT_ID 
			) OR
			PARAM_ACC_ACCOUNT_ACC_LEVEL_ID  <> TEMP_ACC_ACCOUNT_ACC_LEVEL_ID OR
			PARAM_ACC_ACCOUNT_ACC_GROUP_ID <> TEMP_ACC_ACCOUNT_ACC_GROUP_ID OR
			PARAM_ACC_ACCOUNT_FIRST_NAME <> TEMP_ACC_ACCOUNT_FIRST_NAME OR
			PARAM_ACC_ACCOUNT_MIDDLE_NAME <> TEMP_ACC_ACCOUNT_MIDDLE_NAME OR
			PARAM_ACC_ACCOUNT_LAST_NAME <> TEMP_ACC_ACCOUNT_LAST_NAME OR
		
			PARAM_ACC_ACCOUNT_SYS_GENDER_ID <> TEMP_ACC_ACCOUNT_GENDER_ID OR
			PARAM_ACC_ACCOUNT_STATUS <> TEMP_ACC_ACCOUNT_STATUS				
		THEN
			SET TEMP_ACCESS_RIGHTS_DENIED = 1;
			Call `ACCOUNT_ACCESS_RIGHTS_DENY`
				(
					0, TEMP_MODULE_KEYWORD, PARAM_ACC_ACCOUNT_ID, TEMP_ACC_ACCOUNT_SERVER_ID, TEMP_SP_OBJECTIVE, TEMP_RECORD_CHANGES, 
					PARAM_REQUESTER_USERNAME, PARAM_REQUESTER_PASSWORD, 
					PARAM_REQUESTER_PROXY_ID, PARAM_REQUESTER_PROXY_PASSWORD,
					PARAM_REQUESTER_DEVICE_PUBLIC_KEY, PARAM_REQUESTER_DEVICE_PRIVATE_KEY,
					PARAM_REQUESTER_IP, PARAM_UNIQUE_SESSION_ID,
					TEMP_SYNC_SERVER_ID, PARAM_SUPPRESS_RETURN
				);
		END if;
	END IF;

	-- Access Rights (w/ Exception for editing own Username/Password), when editing own account.
	-- ####################################################
	IF
		PARAM_ACC_ACCOUNT_ID = TEMP_AUTHENTICATED_ACCOUNT_ID AND 
		`ACCOUNT_ACCESS_RIGHTS@HAS_PERMISSION`(PARAM_REQUESTER_USERNAME, PARAM_REQUESTER_PASSWORD, 0, TEMP_MODULE_KEYWORD, 3) = 1
	THEN
		-- For editing own account, Limited Edit Only
		IF 
			PARAM_ACC_ACCOUNT_ACC_LEVEL_ID  <> TEMP_ACC_ACCOUNT_ACC_LEVEL_ID OR
			PARAM_ACC_ACCOUNT_ACC_GROUP_ID <> TEMP_ACC_ACCOUNT_ACC_GROUP_ID OR
			PARAM_ACC_ACCOUNT_FIRST_NAME <> TEMP_ACC_ACCOUNT_FIRST_NAME OR
			PARAM_ACC_ACCOUNT_MIDDLE_NAME <> TEMP_ACC_ACCOUNT_MIDDLE_NAME OR
			PARAM_ACC_ACCOUNT_LAST_NAME <> TEMP_ACC_ACCOUNT_LAST_NAME OR
		
			PARAM_ACC_ACCOUNT_SYS_GENDER_ID <> TEMP_ACC_ACCOUNT_GENDER_ID OR
			PARAM_ACC_ACCOUNT_STATUS <> TEMP_ACC_ACCOUNT_STATUS				
		THEN
			SET TEMP_ERR_MESSAGE = 'You cannot edit your own account (except password).';
			SET ERR = `RAISERROR`(TEMP_ERR_MESSAGE);	
		END IF;
	END IF;


	-- Should not assign levels greater than the user (or override)
	-- ####################################################
	IF
		`ACCOUNT_ACCESS_RIGHTS@HAS_PERMISSION`(PARAM_REQUESTER_USERNAME, PARAM_REQUESTER_PASSWORD, 0, TEMP_MODULE_KEYWORD, 5) = 0 AND 
		PARAM_ACC_ACCOUNT_ACC_LEVEL_ID  <> TEMP_ACC_ACCOUNT_ACC_LEVEL_ID AND
		`ACCOUNT_LEVEL@EDIT_HAS_PERMISSION`
		(
			PARAM_ACC_ACCOUNT_ACC_LEVEL_ID,
		
			PARAM_REQUESTER_USERNAME,
			PARAM_REQUESTER_PASSWORD
		) = 0 		
	THEN
		SET TEMP_ERR_MESSAGE = 'You cannot access to account or settings assigned to higher authority.';
		SET ERR = `RAISERROR`(TEMP_ERR_MESSAGE);	
	END IF;


	
	-- 6) INSERT / UPDATE
	-- _______________________________________________________________________

	-- INSERT NEW DATA
	-- ####################################################
	IF TEMP_RECORD_EXISTS = 0 THEN

		INSERT INTO
		`account_member`
		(
			`account_member`.`ACC_ACCOUNT_SERVER_ID`,
			`account_member`.`ACC_ACCOUNT_ACC_LEVEL_ID`,
			`account_member`.`ACC_ACCOUNT_ACC_GROUP_ID`,
			`account_member`.`ACC_ACCOUNT_ADD_RESOURCE_ID`,

			`account_member`.`ACC_ACCOUNT_USERNAME`,
			`account_member`.`ACC_ACCOUNT_PASSWORD`,
			`account_member`.`ACC_ACCOUNT_AUTH_CODE`, 
			
			`account_member`.`ACC_ACCOUNT_FIRST_NAME`,
			`account_member`.`ACC_ACCOUNT_MIDDLE_NAME`,
			`account_member`.`ACC_ACCOUNT_LAST_NAME`,
	
			`account_member`.`ACC_ACCOUNT_SYS_GENDER_ID`,
			`account_member`.`ACC_ACCOUNT_POSITION`,
		
			`account_member`.`ACC_ACCOUNT_STATUS`,
			`account_member`.`ACC_ACCOUNT_SYSTEM_GENERATED`
		)
		VALUES
		(
			PARAM_ACC_ACCOUNT_SERVER_ID,
			PARAM_ACC_ACCOUNT_ACC_LEVEL_ID,
			PARAM_ACC_ACCOUNT_ACC_GROUP_ID,
			PARAM_ACC_ACCOUNT_ADD_RESOURCE_ID,

			PARAM_ACC_ACCOUNT_USERNAME,
			PARAM_ACC_ACCOUNT_PASSWORD, 
			PARAM_ACC_ACCOUNT_AUTH_CODE, 
			
			PARAM_ACC_ACCOUNT_FIRST_NAME,
			PARAM_ACC_ACCOUNT_MIDDLE_NAME,
			PARAM_ACC_ACCOUNT_LAST_NAME,

			PARAM_ACC_ACCOUNT_SYS_GENDER_ID,
			PARAM_ACC_ACCOUNT_POSITION,
		
			PARAM_ACC_ACCOUNT_STATUS,
			1
		);

		-- Update Audit trail with new ID	
		-- ...........................................
		SET PARAM_ACC_ACCOUNT_ID = LAST_INSERT_ID();

		CALL `ADDON_LICENSE_USER_SAVE`
		(
			0,
			PARAM_ACC_ACCOUNT_ID,
			0,	
			TEMP_NOW,
			'1900-01-01 00:00:00.000000',
			'0',
			STATUS_ACTIVE,

			PARAM_REQUESTER_USERNAME,
			PARAM_REQUESTER_PASSWORD,
			PARAM_REQUESTER_PROXY_ID,
			PARAM_REQUESTER_PROXY_PASSWORD,
			PARAM_REQUESTER_DEVICE_PUBLIC_KEY,
			PARAM_REQUESTER_DEVICE_PRIVATE_KEY,
			
			PARAM_REQUESTER_IP,
			PARAM_UNIQUE_SESSION_ID,
			1,
			
			PARAM_SYNC_SERVER_DESCRIPTION, 
			PARAM_SYNC_SERVER_UNIQUE_KEY
		);

		
		

	-- UPDATING EXISTING RECORD
	-- ####################################################
	ELSE

		UPDATE `account_member`
		SET
			`account_member`.`ACC_ACCOUNT_SERVER_ID` = PARAM_ACC_ACCOUNT_SERVER_ID,
			`account_member`.`ACC_ACCOUNT_ACC_LEVEL_ID` = PARAM_ACC_ACCOUNT_ACC_LEVEL_ID,
			`account_member`.`ACC_ACCOUNT_ACC_GROUP_ID` = PARAM_ACC_ACCOUNT_ACC_GROUP_ID,
			`account_member`.`ACC_ACCOUNT_ADD_RESOURCE_ID` = PARAM_ACC_ACCOUNT_ADD_RESOURCE_ID,

			`account_member`.`ACC_ACCOUNT_USERNAME` = PARAM_ACC_ACCOUNT_USERNAME,
			`account_member`.`ACC_ACCOUNT_PASSWORD` = PARAM_ACC_ACCOUNT_PASSWORD,
			`account_member`.`ACC_ACCOUNT_AUTH_CODE` = PARAM_ACC_ACCOUNT_AUTH_CODE, 
			
			`account_member`.`ACC_ACCOUNT_FIRST_NAME` = PARAM_ACC_ACCOUNT_FIRST_NAME,
			`account_member`.`ACC_ACCOUNT_MIDDLE_NAME` = PARAM_ACC_ACCOUNT_MIDDLE_NAME,
			`account_member`.`ACC_ACCOUNT_LAST_NAME` = PARAM_ACC_ACCOUNT_LAST_NAME,

			`account_member`.`ACC_ACCOUNT_SYS_GENDER_ID` = PARAM_ACC_ACCOUNT_SYS_GENDER_ID,
			`account_member`.`ACC_ACCOUNT_POSITION` = PARAM_ACC_ACCOUNT_POSITION,
		
			`account_member`.`ACC_ACCOUNT_STATUS` = PARAM_ACC_ACCOUNT_STATUS
		WHERE
			`account_member`.`ACC_ACCOUNT_ID` = PARAM_ACC_ACCOUNT_ID;

	END IF;

	
	-- 7) AUDIT TRAIL
	-- ====================================================================================================================================================================
	CALL `ACCOUNT_AUDIT_TRAIL_SAVE`
	(
		0, TEMP_MODULE_KEYWORD, PARAM_ACC_ACCOUNT_ID, TEMP_ACC_ACCOUNT_SERVER_ID, 'SAVE', TEMP_SP_OBJECTIVE, TEMP_RECORD_CHANGES, 
		PARAM_REQUESTER_USERNAME, PARAM_REQUESTER_PASSWORD, 
		PARAM_REQUESTER_PROXY_ID, PARAM_REQUESTER_PROXY_PASSWORD,
		PARAM_REQUESTER_DEVICE_PUBLIC_KEY, PARAM_REQUESTER_DEVICE_PRIVATE_KEY,
		PARAM_REQUESTER_IP, PARAM_UNIQUE_SESSION_ID,
		TEMP_SYNC_SERVER_ID, PARAM_SUPPRESS_RETURN
	);
	-- ====================================================================================================================================================================
	
	
	-- 8) RETURN RESULT
	-- ====================================================================================================================================================================
	IF PARAM_SUPPRESS_RETURN = 0 THEN
		SELECT 
			PARAM_ACC_ACCOUNT_ID AS INSERTED_ID,
			PARAM_ACC_ACCOUNT_PASSWORD AS NEW_PASSWORD,
			`ADDON_LICENSE_USER@ID_FROM_ACC_ACCOUNT_ID`(PARAM_ACC_ACCOUNT_ID) AS ADD_ULICENSE_ID;
	END IF;
	LEAVE SP_SAVE;
	-- ====================================================================================================================================================================


END ;;
DELIMITER ;
/*!50003 SET sql_mode              = @saved_sql_mode */ ;
/*!50003 SET character_set_client  = @saved_cs_client */ ;
/*!50003 SET character_set_results = @saved_cs_results */ ;
/*!50003 SET collation_connection  = @saved_col_connection */ ;
/*!50003 DROP PROCEDURE IF EXISTS `ACCOUNT_MEMBER_SYNC_GET` */;
/*!50003 SET @saved_cs_client      = @@character_set_client */ ;
/*!50003 SET @saved_cs_results     = @@character_set_results */ ;
/*!50003 SET @saved_col_connection = @@collation_connection */ ;
/*!50003 SET character_set_client  = latin1 */ ;
/*!50003 SET character_set_results = latin1 */ ;
/*!50003 SET collation_connection  = latin1_swedish_ci */ ;
/*!50003 SET @saved_sql_mode       = @@sql_mode */ ;
/*!50003 SET sql_mode              = '' */ ;
DELIMITER ;;
CREATE DEFINER=`root`@`localhost` PROCEDURE `ACCOUNT_MEMBER_SYNC_GET`(
	IN `PARAM_ACC_SERVER_ID` BIGINT,
	IN `PARAM_ACC_TRAIL_SYS_METHOD_ID` BIGINT,
	IN `PARAM_ACC_TRAIL_TIMESTAMP_FROM` DATETIME,
	IN `PARAM_ACC_TRAIL_TIMESTAMP_TO` DATETIME,
		
	IN `PARAM_ORDER_FIELD` VARCHAR(500),
	IN `PARAM_ORDER_TYPE` VARCHAR(500),
	IN `PARAM_SKIP` BIGINT,
	IN `PARAM_LIMIT` BIGINT,

	IN `PARAM_REQUESTER_USERNAME` VARCHAR(500),
	IN `PARAM_REQUESTER_PASSWORD` VARCHAR(500),
	IN `PARAM_REQUESTER_IP` VARCHAR(1000),
	IN `PARAM_UNIQUE_SESSION_ID` VARCHAR(1000),
	IN `PARAM_SUPPRESS_RETURN` BIT,
	
	IN `PARAM_SYNC_SERVER_DESCRIPTION` VARCHAR(500), 
	IN `PARAM_SYNC_SERVER_UNIQUE_KEY` VARCHAR(500)
)
SP_GET:
BEGIN
/*
	-- 1) DECLARE LOCAL PARAMETERS
	-- ====================================================================================================================================================================
	DECLARE STATUS_INACTIVE TINYINT DEFAULT 1;
	DECLARE STATUS_ACTIVE TINYINT DEFAULT 2;
	
	-- Audit Handler
	DECLARE TEMP_RECORD_EXISTS BIT DEFAULT 0;
	DECLARE TEMP_MODULE_KEYWORD VARCHAR(500) DEFAULT 'account_server';
	DECLARE TEMP_SP_OBJECTIVE VARCHAR(500) DEFAULT 'synchronizing data; account: member';
	DECLARE TEMP_ERR_MESSAGE VARCHAR(500) DEFAULT '';
	DECLARE ERR BIGINT DEFAULT 0;
	DECLARE TEMP_RECORD_CHANGES VARCHAR(16000) DEFAULT '';
	DECLARE TEMP_RECORD_BINDED BIT DEFAULT 0;
	
	-- Authentication
	DECLARE TEMP_ACCESS_RIGHTS_DENIED BIT DEFAULT 0;
	DECLARE TEMP_SYNC_SERVER_ID BIGINT DEFAULT 0;
	DECLARE TEMP_SYNC_IS_SERVER_REQUEST BIT DEFAULT 0;
	DECLARE TEMP_AUTHENTICATED_ACCOUNT_ID BIGINT DEFAULT `ACCOUNT_MEMBER@ACCOUNT_ID_FROM_LOGIN`(PARAM_REQUESTER_USERNAME, PARAM_REQUESTER_PASSWORD);
	DECLARE TEMP_AUTHENTICATED_ACCOUNT_LEVEL BIGINT DEFAULT 0;
	
	-- Local Parameters
	DECLARE TEMP_MODULE_ID BIGINT DEFAULT `SYSTEM_MODULE@MODULE_ID_FROM_KEYWORD`('account_member');
	
	-- Handle Nulls
	DECLARE IS_NULL_ACC_TRAIL_TIMESTAMP_FROM BIT DEFAULT `SYSTEM_VAR@IS_NULL@DATETIME`(PARAM_ACC_TRAIL_TIMESTAMP_FROM, 1);
	DECLARE IS_NULL_ACC_TRAIL_TIMESTAMP_TO BIT DEFAULT `SYSTEM_VAR@IS_NULL@DATETIME`(PARAM_ACC_TRAIL_TIMESTAMP_TO, 1);
	
	-- ====================================================================================================================================================================	

	
	-- 2) Try Catch / Throw
	-- ====================================================================================================================================================================
	DECLARE EXIT HANDLER FOR SQLEXCEPTION
	BEGIN
		RESIGNAL;
	END;
	-- ====================================================================================================================================================================	
	
	
	-- 3) Prepare SYNC
	-- ====================================================================================================================================================================

	-- IS SERVE REQUEST
	IF
		`SYSTEM_VAR@IS_NULL@NVARCHAR`(PARAM_SYNC_SERVER_DESCRIPTION, 1) = 0 AND
		`SYSTEM_VAR@IS_NULL@NVARCHAR`(PARAM_SYNC_SERVER_UNIQUE_KEY, 1) = 0
	THEN
	
		-- SET REQUEST CAME FROM SYNC 
		SET TEMP_SYNC_IS_SERVER_REQUEST = 1;
		
		-- GET SERVER ID
		SET TEMP_SYNC_SERVER_ID = `ACCOUNT_SERVER@SERVER_ID_FROM_LOGIN`(PARAM_SYNC_SERVER_DESCRIPTION, PARAM_SYNC_SERVER_UNIQUE_KEY);
			
	END IF;

	-- ====================================================================================================================================================================
		
		
	-- 4) VALIDATE
	-- ====================================================================================================================================================================	
	IF 
		`ACCOUNT_SERVER@HAS_PERMISSION`(PARAM_SERVER_DESCRIPTION, PARAM_SERVER_UNIQUE_KEY) = 0 AND
		`ACCOUNT_ACCESS_RIGHTS@HAS_PERMISSION`(PARAM_REQUESTER_USERNAME, PARAM_REQUESTER_PASSWORD, 0, TEMP_MODULE_KEYWORD, 2) = 0 
	THEN
		CALL `ACCOUNT_ACCESS_RIGHTS_DENY`
		(
			0, TEMP_MODULE_KEYWORD, 0, 0, TEMP_SP_OBJECTIVE, '',
			PARAM_REQUESTER_USERNAME, PARAM_REQUESTER_PASSWORD, PARAM_REQUESTER_IP, PARAM_UNIQUE_SESSION_ID,
			TEMP_SYNC_SERVER_ID, PARAM_SUPPRESS_RETURN
		);
	END IF;
	-- ====================================================================================================================================================================	
	
	
	-- 5) SELECT ITEMS
	-- ====================================================================================================================================================================	
	SELECT
			-- ACCOUNT DATA
			`account_member`.`ACC_ACCOUNT_ID`,
			`account_member`.`ACC_ACCOUNT_SERVER_ID`,
			0 AS ACCOUNT_LEVEL_ID,

			'##dummy_account' AS ACCOUNT_USERNAME,
			'******' AS ACCOUNT_PASSWORD,
			`account_member`.`ACC_ACCOUNT_FIRST_NAME`,
			`account_member`.`ACC_ACCOUNT_MIDDLE_NAME`,
			`account_member`.`ACC_ACCOUNT_LAST_NAME`,

			`account_member`.`ACC_ACCOUNT_SYS_GENDER_ID`,
			`account_member`.`ACC_ACCOUNT_POSITION`,
				
			`account_member`.`ACC_ACCOUNT_STATUS`,
			`account_member`.`ACC_ACCOUNT_SYSTEM_GENERATED`,
			
			`account_audit_trail`.`ACC_TRAIL_TARGET_ID`,
			`account_audit_trail`.`ACC_TRAIL_TARGET_SERVER_ID`,
			`account_audit_trail`.`ACC_TRAIL_TIMESTAMP`
		
	FROM `account_audit_trail`
	
		-- Check newer changes if exists
		LEFT JOIN `account_audit_trail` NEWER_CHANGES ON
		NEWER_CHANGES.`ACC_TRAIL_ID` <>	`account_audit_trail`.`ACC_TRAIL_ID` AND
		NEWER_CHANGES.`ACC_TRAIL_TARGET_ID` = `account_audit_trail`.`ACC_TRAIL_TARGET_ID` AND
		NEWER_CHANGES.`ACC_TRAIL_SYS_METHOD_ID` = `account_audit_trail`.`ACC_TRAIL_SYS_METHOD_ID` AND
		NEWER_CHANGES.`ACC_TRAIL_MODULE_ID` = `account_audit_trail`.`ACC_TRAIL_MODULE_ID` AND
		NEWER_CHANGES.`ACC_TRAIL_TIMESTAMP` > `account_audit_trail`.`ACC_TRAIL_TIMESTAMP` AND
		(
			IS_NULL_ACC_TRAIL_TIMESTAMP_TO = 1 OR
			NEWER_CHANGES.`ACC_TRAIL_TIMESTAMP`	<= PARAM_ACC_TRAIL_TIMESTAMP_TO
		)

		-- return record IF STILL EXISTS IN DATABASE, else skip
		INNER JOIN `account_member` ON
		`account_member`.`ACC_ACCOUNT_ID` = `account_audit_trail`.`ACC_TRAIL_TARGET_ID` AND
		`account_member`.`ACC_ACCOUNT_SYSTEM_GENERATED` = STATUS_INACTIVE

	WHERE
		-- Select changes made to record (except changes came from mother server)
		-- Skip if newer changes exists in database (only the latest change will reflected in sync)
		`account_audit_trail`.`ACC_TRAIL_SYS_METHOD_ID` = PARAM_ACC_TRAIL_SYS_METHOD_ID AND
		`account_audit_trail`.`ACC_TRAIL_SERVER_ID` <> PARAM_ACC_SERVER_ID AND
		`account_audit_trail`.`ACC_TRAIL_MODULE_ID` = TEMP_MODULE_ID AND
		(
			IS_NULL_ACC_TRAIL_TIMESTAMP_FROM = 1 OR
			`account_audit_trail`.`ACC_TRAIL_TIMESTAMP` > PARAM_ACC_TRAIL_TIMESTAMP_FROM
		) AND
		(
			IS_NULL_ACC_TRAIL_TIMESTAMP_TO = 1 OR
			`account_audit_trail`.`ACC_TRAIL_TIMESTAMP` <= PARAM_ACC_TRAIL_TIMESTAMP_TO 
		) AND
		NEWER_CHANGES.`ACC_TRAIL_ID` IS NULL
		
	ORDER BY
		`account_audit_trail`.`ACC_TRAIL_TIMESTAMP` ASC
		
	LIMIT PARAM_SKIP, PARAM_LIMIT;
	-- ====================================================================================================================================================================	
		*/
	
END ;;
DELIMITER ;
/*!50003 SET sql_mode              = @saved_sql_mode */ ;
/*!50003 SET character_set_client  = @saved_cs_client */ ;
/*!50003 SET character_set_results = @saved_cs_results */ ;
/*!50003 SET collation_connection  = @saved_col_connection */ ;
/*!50003 DROP PROCEDURE IF EXISTS `ACCOUNT_MEMBER_SYNC_SAVE` */;
/*!50003 SET @saved_cs_client      = @@character_set_client */ ;
/*!50003 SET @saved_cs_results     = @@character_set_results */ ;
/*!50003 SET @saved_col_connection = @@collation_connection */ ;
/*!50003 SET character_set_client  = latin1 */ ;
/*!50003 SET character_set_results = latin1 */ ;
/*!50003 SET collation_connection  = latin1_swedish_ci */ ;
/*!50003 SET @saved_sql_mode       = @@sql_mode */ ;
/*!50003 SET sql_mode              = '' */ ;
DELIMITER ;;
CREATE DEFINER=`root`@`localhost` PROCEDURE `ACCOUNT_MEMBER_SYNC_SAVE`(
	IN `PARAM_ID` BIGINT,
	IN `PARAM_SERVER_ID` BIGINT,

	IN `PARAM_REQUESTER_USERNAME` VARCHAR(500),
	IN `PARAM_REQUESTER_PASSWORD` VARCHAR(500),
	IN `PARAM_REQUESTER_IP` VARCHAR(1000),
	IN `PARAM_UNIQUE_SESSION_ID` VARCHAR(1000),
	IN `PARAM_SUPPRESS_RETURN` BIT
)
SP_SAVE:
BEGIN
/*
	-- 1) DECLARE LOCAL PARAMETERS
	-- ====================================================================================================================================================================
	-- Audit Handler
	DECLARE TEMP_RECORD_EXISTS BIT DEFAULT `ACCOUNT_MEMBER@ACCOUNT_ID_EXISTS`(PARAM_ID, 0);
	DECLARE TEMP_MODULE_KEYWORD VARCHAR(500) DEFAULT 'account_server';
	DECLARE TEMP_SP_OBJECTIVE VARCHAR(500) DEFAULT 'synchronizing data; account: member';
	DECLARE TEMP_ERR_MESSAGE VARCHAR(500) DEFAULT '';
	DECLARE ERR BIGINT DEFAULT 0;
	DECLARE TEMP_RECORD_CHANGES VARCHAR(16000) DEFAULT '';
	DECLARE TEMP_RECORD_BINDED BIT DEFAULT 0;
	
	-- Authentication
	DECLARE TEMP_ACCESS_RIGHTS_DENIED BIT DEFAULT 0;
	DECLARE TEMP_SYNC_SERVER_ID BIGINT DEFAULT 0;
	DECLARE TEMP_SYNC_IS_SERVER_REQUEST BIT DEFAULT 0;
	DECLARE TEMP_AUTHENTICATED_ACCOUNT_ID BIGINT DEFAULT `ACCOUNT_MEMBER@ACCOUNT_ID_FROM_LOGIN`(PARAM_REQUESTER_USERNAME, PARAM_REQUESTER_PASSWORD);
	DECLARE TEMP_AUTHENTICATED_ACCOUNT_LEVEL BIGINT DEFAULT 0;
	
	-- Local Parameters
	DECLARE TEMP_MODULE_ID BIGINT DEFAULT `SYSTEM_MODULE@MODULE_ID_FROM_KEYWORD`('account_member');
	-- ====================================================================================================================================================================	

	
	-- 2) Try Catch / Throw
	-- ====================================================================================================================================================================
	DECLARE EXIT HANDLER FOR SQLEXCEPTION
	BEGIN
		RESIGNAL;
	END;
	-- ====================================================================================================================================================================	
		
		
	-- 3) IF ALREADY EXIST, CHECK SERVER ID IF SAME
	-- ====================================================================================================================================================================
	IF TEMP_RECORD_EXISTS = 1 THEN
	
		IF
		(
			SELECT COUNT(`account_member`.`ACC_ACCOUNT_ID`)
			FROM `account_member`
			WHERE
				`account_member`.`ACC_ACCOUNT_ID` = PARAM_ID AND
				`account_member`.`ACC_ACCOUNT_SERVER_ID` = PARAM_SERVER_ID
			LIMIT 1
		) >= 1
		THEN
			IF PARAM_SUPPRESS_RETURN = 0 THEN
				SELECT PARAM_ID AS INSERTED_ID;		
			END IF;
			LEAVE SP_SAVE;
		END IF;

	ELSE
		-- RECORD NOT FOUND : Happens when source data deleted while sync is processing same record.
		IF PARAM_SUPPRESS_RETURN = 0 THEN
			SELECT PARAM_ID AS INSERTED_ID;		
		END IF;
		LEAVE SP_SAVE;
		
	END IF;
	-- ====================================================================================================================================================================

	
	-- 4) VALIDATE
	-- ====================================================================================================================================================================	
	IF `ACCOUNT_ACCESS_RIGHTS@HAS_PERMISSION`(PARAM_REQUESTER_USERNAME, PARAM_REQUESTER_PASSWORD, 0, TEMP_MODULE_KEYWORD, 2) = 0 THEN
		CALL `ACCOUNT_ACCESS_RIGHTS_DENY`
		(
			0, TEMP_MODULE_KEYWORD, 0, 0, TEMP_SP_OBJECTIVE, '',
			PARAM_REQUESTER_USERNAME, PARAM_REQUESTER_PASSWORD, PARAM_REQUESTER_IP, PARAM_UNIQUE_SESSION_ID,
			TEMP_SYNC_SERVER_ID, PARAM_SUPPRESS_RETURN
		);
	END IF;
	-- ====================================================================================================================================================================	
	
	
	-- 5) SELECT ITEMS
	-- ====================================================================================================================================================================	
	UPDATE `account_member`
	SET 
		`account_member`.`ACC_ACCOUNT_SERVER_ID` = PARAM_SERVER_ID
	WHERE
		`account_member`.`ACC_ACCOUNT_ID` = PARAM_ID
	LIMIT 1;
	-- ====================================================================================================================================================================	
	
	
	-- 6) RETURN RESULT
	-- ====================================================================================================================================================================
	IF PARAM_SUPPRESS_RETURN = 0 THEN
		SELECT PARAM_ID AS INSERTED_ID;
	END IF;
	LEAVE SP_SAVE;
	-- ====================================================================================================================================================================
	*/
END ;;
DELIMITER ;
/*!50003 SET sql_mode              = @saved_sql_mode */ ;
/*!50003 SET character_set_client  = @saved_cs_client */ ;
/*!50003 SET character_set_results = @saved_cs_results */ ;
/*!50003 SET collation_connection  = @saved_col_connection */ ;
/*!50003 DROP PROCEDURE IF EXISTS `ACCOUNT_PROXY_ACCESS_GET` */;
/*!50003 SET @saved_cs_client      = @@character_set_client */ ;
/*!50003 SET @saved_cs_results     = @@character_set_results */ ;
/*!50003 SET @saved_col_connection = @@collation_connection */ ;
/*!50003 SET character_set_client  = latin1 */ ;
/*!50003 SET character_set_results = latin1 */ ;
/*!50003 SET collation_connection  = latin1_swedish_ci */ ;
/*!50003 SET @saved_sql_mode       = @@sql_mode */ ;
/*!50003 SET sql_mode              = '' */ ;
DELIMITER ;;
CREATE DEFINER=`root`@`localhost` PROCEDURE `ACCOUNT_PROXY_ACCESS_GET`(
		
	IN `PARAM_ORDER_FIELD` VARCHAR(500),
	IN `PARAM_ORDER_TYPE` VARCHAR(500),
	IN `PARAM_SKIP` BIGINT,
	IN `PARAM_LIMIT` BIGINT,

	IN `PARAM_REQUESTER_USERNAME` VARCHAR(500),
	IN `PARAM_REQUESTER_PASSWORD` VARCHAR(500),
	IN `PARAM_REQUESTER_PROXY_ID` BIGINT,
	IN `PARAM_REQUESTER_PROXY_PASSWORD` VARCHAR(1000),
	IN `PARAM_REQUESTER_DEVICE_PUBLIC_KEY` VARCHAR(1000),
	IN `PARAM_REQUESTER_DEVICE_PRIVATE_KEY` VARCHAR(1000),
	
	IN `PARAM_REQUESTER_IP` VARCHAR(1000),
	IN `PARAM_UNIQUE_SESSION_ID` VARCHAR(1000),
	IN `PARAM_SUPPRESS_RETURN` BIT
)
SP_GET:
BEGIN

	-- Status
	-- =========================================================================================
	DECLARE STATUS_INACTIVE TINYINT DEFAULT 1;
	DECLARE STATUS_ACTIVE TINYINT DEFAULT 2;
	DECLARE STATUS_CLOSED TINYINT DEFAULT 3;
	DECLARE STATUS_COMPLETED TINYINT DEFAULT 4;
	
	-- Audit Handler
	-- =========================================================================================
	DECLARE TEMP_RECORD_EXISTS BIT DEFAULT 0;
	DECLARE TEMP_MODULE_KEYWORD VARCHAR(500) DEFAULT 'account_proxy_access';
	DECLARE TEMP_SP_OBJECTIVE VARCHAR(500) DEFAULT 'Retrieve Proxy Auth Access record';
	DECLARE TEMP_ERR_MESSAGE VARCHAR(500) DEFAULT '';
	DECLARE ERR BIGINT DEFAULT 0;
	DECLARE TEMP_RECORD_CHANGES VARCHAR(16000) DEFAULT '';
	DECLARE TEMP_RECORD_BINDED BIT DEFAULT 0;
	
	DECLARE TEMP_RECORD_BINDED_ID BIGINT DEFAULT 0;
	DECLARE TEMP_RECORD_BINDED_SERVER_ID BIGINT DEFAULT 0;
	
	-- Authentication
	-- =========================================================================================
	DECLARE TEMP_ACCESS_RIGHTS_DENIED BIT DEFAULT 0;
	DECLARE TEMP_AUTHENTICATED_ACCOUNT_ID BIGINT DEFAULT `ACCOUNT_MEMBER@ACC_ACCOUNT_ID_FROM_LOGIN`(PARAM_REQUESTER_USERNAME, PARAM_REQUESTER_PASSWORD);
	DECLARE TEMP_AUTHENTICATED_ACCOUNT_LEVEL BIGINT DEFAULT 0;
	DECLARE TEMP_AUTHENTICATED_ACCOUNT_GROUP BIGINT DEFAULT 0;
	
	-- Local Parameters
	-- =========================================================================================
	DECLARE TEMP_NOW DATETIME(6) DEFAULT `SYSTEM_VAR@NOW`('', 1);
	DECLARE TEMP_RECORD_COUNT BIGINT DEFAULT 0;
	
	
	-- Check NULLs
	-- =========================================================================================
	
	-- Error Handler
	-- =========================================================================================
	DECLARE EXIT HANDLER FOR SQLEXCEPTION
	BEGIN
		RESIGNAL;
	END;
	
	-- Ignore Time from DateTime (Set Time 00:00:00.000000 and 23:59:59.999999)
	-- =========================================================================================
		
		
	-- Access Rights [Device]
	-- =========================================================================================
	IF `ACCOUNT_DEVICE@HAS_PERMISSION`(PARAM_REQUESTER_DEVICE_PUBLIC_KEY, PARAM_REQUESTER_DEVICE_PRIVATE_KEY) = 0 THEN
		SET TEMP_ERR_MESSAGE = 'Your device is not authorized yet to access this server.';
		SET ERR = `RAISERROR`(TEMP_ERR_MESSAGE);		
	END IF;
		
		
	-- Access Rights [Account]
	-- =========================================================================================
		
	IF `ACCOUNT_ACCESS_RIGHTS@HAS_PERMISSION`(PARAM_REQUESTER_USERNAME, PARAM_REQUESTER_PASSWORD, 0, TEMP_MODULE_KEYWORD, 1) = 0 THEN
		SET TEMP_ACCESS_RIGHTS_DENIED = 1;
		CALL `ACCOUNT_ACCESS_RIGHTS_DENY`
		(
			0, TEMP_MODULE_KEYWORD, 0, 0, TEMP_SP_OBJECTIVE, TEMP_RECORD_CHANGES, 
			PARAM_REQUESTER_USERNAME, PARAM_REQUESTER_PASSWORD, 
			PARAM_REQUESTER_PROXY_ID, PARAM_REQUESTER_PROXY_PASSWORD,
			PARAM_REQUESTER_DEVICE_PUBLIC_KEY, PARAM_REQUESTER_DEVICE_PRIVATE_KEY,
			PARAM_REQUESTER_IP, PARAM_UNIQUE_SESSION_ID,
			0, PARAM_SUPPRESS_RETURN
		);
	END IF;
	
	
	
	-- COUNT RECORD
	-- =========================================================================================
	
	-- SELECT COLUMNS
	-- ####################################################
	SELECT
		COUNT(DISTINCT `account_proxy_access`.`ACC_PROXY_ID`)
	INTO
		TEMP_RECORD_COUNT

	FROM `account_proxy_access`
	
		-- Add Inner Joins (Per Foreign-key)
		
		-- Add Optional Left Joins (Per Optional Foreign-key)
		
	-- CONDITIONS
	-- ####################################################
	WHERE
		`account_proxy_access`.`ACC_PROXY_STATUS` = STATUS_ACTIVE;	

		
		
	-- SELECT RECORDS
	-- =========================================================================================
	
	-- FETCH COLUMNS
	-- ####################################################
	SELECT
		-- ACCOUNT_PROXY_ACCESS DETAILS
		`account_proxy_access`.`ACC_PROXY_ID`, 
		`account_proxy_access`.`ACC_PROXY_AUTH_STRING_VALIDATOR`, 
		`account_proxy_access`.`ACC_PROXY_AUTH_BINARY_VALIDATOR`, 
		`account_proxy_access`.`ACC_PROXY_STATUS`
		
		-- Inner join fields
		
		-- Left join fields
		
		, TEMP_RECORD_COUNT AS RECORD_COUNT

	FROM `account_proxy_access`
	
		-- Add Inner Joins (Per Foreign-key)
		
		-- Add Optional Left Joins (Per Optional Foreign-key)
		
	-- CONDITIONS
	-- ####################################################
	WHERE
		`account_proxy_access`.`ACC_PROXY_STATUS` = STATUS_ACTIVE

	-- ORDER BY
	-- ####################################################
	ORDER BY
		-- ACCOUNT_PROXY_ACCESS DETAILS
		CASE WHEN PARAM_ORDER_FIELD = 'ACC_PROXY_ID' AND PARAM_ORDER_TYPE = 'ASC' THEN `account_proxy_access`.`ACC_PROXY_ID` END ASC, 
		CASE WHEN PARAM_ORDER_FIELD = 'ACC_PROXY_ID' AND PARAM_ORDER_TYPE = 'DESC' THEN `account_proxy_access`.`ACC_PROXY_ID` END DESC,	
		CASE WHEN PARAM_ORDER_FIELD = 'ACC_PROXY_AUTH_STRING_VALIDATOR' AND PARAM_ORDER_TYPE = 'ASC' THEN `account_proxy_access`.`ACC_PROXY_AUTH_STRING_VALIDATOR` END ASC, 
		CASE WHEN PARAM_ORDER_FIELD = 'ACC_PROXY_AUTH_STRING_VALIDATOR' AND PARAM_ORDER_TYPE = 'DESC' THEN `account_proxy_access`.`ACC_PROXY_AUTH_STRING_VALIDATOR` END DESC,	
		CASE WHEN PARAM_ORDER_FIELD = 'ACC_PROXY_AUTH_BINARY_VALIDATOR' AND PARAM_ORDER_TYPE = 'ASC' THEN `account_proxy_access`.`ACC_PROXY_AUTH_BINARY_VALIDATOR` END ASC, 
		CASE WHEN PARAM_ORDER_FIELD = 'ACC_PROXY_AUTH_BINARY_VALIDATOR' AND PARAM_ORDER_TYPE = 'DESC' THEN `account_proxy_access`.`ACC_PROXY_AUTH_BINARY_VALIDATOR` END DESC,	
		CASE WHEN PARAM_ORDER_FIELD = 'ACC_PROXY_STATUS' AND PARAM_ORDER_TYPE = 'ASC' THEN `account_proxy_access`.`ACC_PROXY_STATUS` END ASC, 
		CASE WHEN PARAM_ORDER_FIELD = 'ACC_PROXY_STATUS' AND PARAM_ORDER_TYPE = 'DESC' THEN `account_proxy_access`.`ACC_PROXY_STATUS` END DESC,	

		-- Inner joins
		
		-- EXTRA
		CASE WHEN PARAM_ORDER_FIELD <> 'ACC_PROXY_AUTH_HASH' THEN `account_proxy_access`.`ACC_PROXY_AUTH_HASH` END ASC
		
	-- LIMIT & OFFSET
	-- ####################################################		
	LIMIT PARAM_SKIP, PARAM_LIMIT;
	
	
	
	-- EXIT PROCEDURE
	-- =========================================================================================
	LEAVE SP_GET;
			
END ;;
DELIMITER ;
/*!50003 SET sql_mode              = @saved_sql_mode */ ;
/*!50003 SET character_set_client  = @saved_cs_client */ ;
/*!50003 SET character_set_results = @saved_cs_results */ ;
/*!50003 SET collation_connection  = @saved_col_connection */ ;
/*!50003 DROP PROCEDURE IF EXISTS `ACCOUNT_PROXY_ACCESS_SAVE` */;
/*!50003 SET @saved_cs_client      = @@character_set_client */ ;
/*!50003 SET @saved_cs_results     = @@character_set_results */ ;
/*!50003 SET @saved_col_connection = @@collation_connection */ ;
/*!50003 SET character_set_client  = latin1 */ ;
/*!50003 SET character_set_results = latin1 */ ;
/*!50003 SET collation_connection  = latin1_swedish_ci */ ;
/*!50003 SET @saved_sql_mode       = @@sql_mode */ ;
/*!50003 SET sql_mode              = '' */ ;
DELIMITER ;;
CREATE DEFINER=`root`@`localhost` PROCEDURE `ACCOUNT_PROXY_ACCESS_SAVE`(
	IN `PARAM_ACC_PROXY_ID` BIGINT,
	IN `PARAM_ACC_PROXY_AUTH_OWNER` VARCHAR(1000),
	IN `PARAM_ACC_PROXY_AUTH_HASH` VARCHAR(1000),
	IN `PARAM_ACC_PROXY_AUTH_STRING_VALIDATOR` VARCHAR(5000),
	IN `PARAM_ACC_PROXY_AUTH_BINARY_VALIDATOR` VARBINARY(50000),
	IN `PARAM_ACC_PROXY_STATUS` TINYINT,

	IN `PARAM_REQUESTER_USERNAME` VARCHAR(500),
	IN `PARAM_REQUESTER_PASSWORD` VARCHAR(500),
	IN `PARAM_REQUESTER_PROXY_ID` BIGINT,
	IN `PARAM_REQUESTER_PROXY_PASSWORD` VARCHAR(1000),
	IN `PARAM_REQUESTER_DEVICE_PUBLIC_KEY` VARCHAR(1000),
	IN `PARAM_REQUESTER_DEVICE_PRIVATE_KEY` VARCHAR(1000),
	
	IN `PARAM_REQUESTER_IP` VARCHAR(1000),
	IN `PARAM_UNIQUE_SESSION_ID` VARCHAR(1000),
	IN `PARAM_SUPPRESS_RETURN` BIT,
	
	IN `PARAM_SYNC_SERVER_DESCRIPTION` VARCHAR(500), 
	IN `PARAM_SYNC_SERVER_UNIQUE_KEY` VARCHAR(500)
)
SP_SAVE:
BEGIN


	-- 1) DECLARE LOCAL PARAMETERS
	-- _______________________________________________________________________
	
	-- Status
	-- ...........................................
	DECLARE STATUS_INACTIVE TINYINT DEFAULT 1;
	DECLARE STATUS_ACTIVE TINYINT DEFAULT 2;
	DECLARE STATUS_CLOSED TINYINT DEFAULT 3;
	DECLARE STATUS_COMPLETED TINYINT DEFAULT 4;

	-- Audit Handler
	-- ...........................................
	DECLARE TEMP_RECORD_EXISTS BIT DEFAULT 0;
	DECLARE TEMP_MODULE_KEYWORD VARCHAR(500) DEFAULT 'account_proxy_access';
	DECLARE TEMP_SP_OBJECTIVE VARCHAR(500) DEFAULT 'add/edit Proxy Auth Access record';
	DECLARE TEMP_ERR_MESSAGE VARCHAR(500) DEFAULT '';
	DECLARE ERR BIGINT DEFAULT 0;
	DECLARE TEMP_RECORD_CHANGES VARCHAR(16000) DEFAULT '';
	DECLARE TEMP_RECORD_BINDED BIT DEFAULT 0;

	-- Authentication
	-- ...........................................
	DECLARE TEMP_ACCESS_RIGHTS_DENIED BIT DEFAULT 0;
	DECLARE TEMP_ACCESS_RIGHTS_HAS_OVERRIDE BIT DEFAULT 0;
	DECLARE TEMP_SYNC_SERVER_ID BIGINT DEFAULT 0;
	DECLARE TEMP_SYNC_IS_SERVER_REQUEST BIT DEFAULT 0;
	DECLARE TEMP_AUTHENTICATED_ACCOUNT_ID BIGINT DEFAULT `ACCOUNT_MEMBER@ACC_ACCOUNT_ID_FROM_LOGIN`(PARAM_REQUESTER_USERNAME, PARAM_REQUESTER_PASSWORD);
	DECLARE TEMP_AUTHENTICATED_ACCOUNT_LEVEL BIGINT DEFAULT 0;
	DECLARE TEMP_AUTHENTICATED_ACCOUNT_GROUP BIGINT DEFAULT 0;
	
	-- Local Parameters
	-- ...........................................
	DECLARE TEMP_NOW DATETIME(6) DEFAULT `SYSTEM_VAR@NOW`('', 1);
	DECLARE TEMP_RECORD_COUNT BIGINT DEFAULT 0;

	-- AutoGen Parameters
	-- ...........................................
	
	-- Local value holder
	-- ...........................................
	DECLARE TEMP_ACC_PROXY_AUTH_OWNER VARCHAR(1000) DEFAULT ''; 
	DECLARE TEMP_ACC_PROXY_AUTH_HASH VARCHAR(1000) DEFAULT ''; 
	DECLARE TEMP_ACC_PROXY_AUTH_STRING_VALIDATOR VARCHAR(5000) DEFAULT ''; 
	DECLARE TEMP_ACC_PROXY_AUTH_BINARY_VALIDATOR VARBINARY(50000) DEFAULT null; 
	DECLARE TEMP_ACC_PROXY_STATUS TINYINT DEFAULT 0; 
	


	-- 2) Try Catch / Throw
	-- _______________________________________________________________________
	DECLARE EXIT HANDLER FOR SQLEXCEPTION
	BEGIN
		RESIGNAL;
	END;



	-- 3) Prepare SYNC
	-- _______________________________________________________________________

	-- IS RECORD EXISTS		
	-- ####################################################	
	SET TEMP_RECORD_EXISTS = `ACCOUNT_PROXY_ACCESS@ACC_PROXY_ID_EXISTS`(PARAM_ACC_PROXY_ID, 0);

		
		
	-- 4) PREPARE AUTOGEN DATA (IF EXISTS)
	-- _______________________________________________________________________
	IF TEMP_SYNC_IS_SERVER_REQUEST = 0 THEN
		-- Just to keep at least one line within condition
		SET TEMP_SYNC_IS_SERVER_REQUEST = 0;
		
		-- Actual Functionalities here
		-- USE DEFAULT VALUE (String)
	END IF;



	-- 5) IF ALREADY EXIST, FILL MISSING DATA
	-- _______________________________________________________________________
	IF TEMP_RECORD_EXISTS = 1 THEN
		SELECT
			`account_proxy_access`.`ACC_PROXY_AUTH_OWNER`, 	
			`account_proxy_access`.`ACC_PROXY_AUTH_HASH`, 	
			`account_proxy_access`.`ACC_PROXY_AUTH_STRING_VALIDATOR`, 	
			`account_proxy_access`.`ACC_PROXY_AUTH_BINARY_VALIDATOR`, 	
			`account_proxy_access`.`ACC_PROXY_STATUS`	
		INTO
			TEMP_ACC_PROXY_AUTH_OWNER, 	
			TEMP_ACC_PROXY_AUTH_HASH, 	
			TEMP_ACC_PROXY_AUTH_STRING_VALIDATOR, 	
			TEMP_ACC_PROXY_AUTH_BINARY_VALIDATOR, 	
			TEMP_ACC_PROXY_STATUS	

		FROM `account_proxy_access`
		WHERE
			`account_proxy_access`.`ACC_PROXY_ID` = PARAM_ACC_PROXY_ID
		LIMIT 1;

		-- Replace NULLs with the existing data.
		SET PARAM_ACC_PROXY_AUTH_OWNER = `SYSTEM_VAR@REPLACE_NULL@NVARCHAR`(PARAM_ACC_PROXY_AUTH_OWNER, TEMP_ACC_PROXY_AUTH_OWNER, 1);
		SET PARAM_ACC_PROXY_AUTH_HASH = `SYSTEM_VAR@REPLACE_NULL@NVARCHAR`(PARAM_ACC_PROXY_AUTH_HASH, TEMP_ACC_PROXY_AUTH_HASH, 1);
		SET PARAM_ACC_PROXY_AUTH_STRING_VALIDATOR = `SYSTEM_VAR@REPLACE_NULL@NVARCHAR`(PARAM_ACC_PROXY_AUTH_STRING_VALIDATOR, TEMP_ACC_PROXY_AUTH_STRING_VALIDATOR, 1);
		SET PARAM_ACC_PROXY_AUTH_BINARY_VALIDATOR = `SYSTEM_VAR@REPLACE_NULL@VARBINARY`(PARAM_ACC_PROXY_AUTH_BINARY_VALIDATOR, TEMP_ACC_PROXY_AUTH_BINARY_VALIDATOR, 1, 1);
		SET PARAM_ACC_PROXY_STATUS = `SYSTEM_VAR@REPLACE_NULL@TINYINT`(PARAM_ACC_PROXY_STATUS, TEMP_ACC_PROXY_STATUS, 1, 1);
		
		-- AUTO GEN (NON-UPDATABLES)		
		
		-- AUTO GEN (UPDATABLE WITH STATUS CHANGE)

		-- AUTO GEN (UPDATABLE WITH STATUS [ACTIVE/INACTIVE] CHANGE)
		
	ELSE
		SET PARAM_ACC_PROXY_AUTH_OWNER = `SYSTEM_VAR@REPLACE_NULL@NVARCHAR`(PARAM_ACC_PROXY_AUTH_OWNER, '', 1);
		SET PARAM_ACC_PROXY_AUTH_HASH = `SYSTEM_VAR@REPLACE_NULL@NVARCHAR`(PARAM_ACC_PROXY_AUTH_HASH, '', 1);
		SET PARAM_ACC_PROXY_AUTH_STRING_VALIDATOR = `SYSTEM_VAR@REPLACE_NULL@NVARCHAR`(PARAM_ACC_PROXY_AUTH_STRING_VALIDATOR, '', 1);
		SET PARAM_ACC_PROXY_AUTH_BINARY_VALIDATOR = `SYSTEM_VAR@REPLACE_NULL@VARBINARY`(PARAM_ACC_PROXY_AUTH_BINARY_VALIDATOR, null, 1, 1);
		SET PARAM_ACC_PROXY_STATUS = `SYSTEM_VAR@REPLACE_NULL@TINYINT`(PARAM_ACC_PROXY_STATUS, 0, 1, 1);
		
	END IF;

	

	-- 6) PREPARE AUDIT TRAIL
	-- _______________________________________________________________________
	IF BINARY TEMP_ACC_PROXY_AUTH_OWNER <> PARAM_ACC_PROXY_AUTH_OWNER THEN
		SET TEMP_RECORD_CHANGES = 
		`SYSTEM_VAR@CONCAT_ADD`(' | ', TEMP_RECORD_CHANGES, CONCAT_WS(' ', 'Proxy Authentication Owner: "', TEMP_ACC_PROXY_AUTH_OWNER, '" > "', PARAM_ACC_PROXY_AUTH_OWNER, '"'));
	END IF;
	IF BINARY TEMP_ACC_PROXY_AUTH_HASH <> PARAM_ACC_PROXY_AUTH_HASH THEN
		SET TEMP_RECORD_CHANGES = 
		`SYSTEM_VAR@CONCAT_ADD`(' | ', TEMP_RECORD_CHANGES, CONCAT_WS(' ', 'Authentication Hash: "', TEMP_ACC_PROXY_AUTH_HASH, '" > "', PARAM_ACC_PROXY_AUTH_HASH, '"'));
	END IF;
	IF BINARY TEMP_ACC_PROXY_AUTH_STRING_VALIDATOR <> PARAM_ACC_PROXY_AUTH_STRING_VALIDATOR THEN
		SET TEMP_RECORD_CHANGES = 
		`SYSTEM_VAR@CONCAT_ADD`(' | ', TEMP_RECORD_CHANGES, CONCAT_WS(' ', 'Authentication Validation Data (String): "', TEMP_ACC_PROXY_AUTH_STRING_VALIDATOR, '" > "', PARAM_ACC_PROXY_AUTH_STRING_VALIDATOR, '"'));
	END IF;
	IF TEMP_ACC_PROXY_AUTH_BINARY_VALIDATOR <> PARAM_ACC_PROXY_AUTH_BINARY_VALIDATOR THEN
		SET TEMP_RECORD_CHANGES = 
		`SYSTEM_VAR@CONCAT_ADD`(' | ', TEMP_RECORD_CHANGES, CONCAT_WS(' ', 'Authentication Validation Data (Binary): "', TEMP_ACC_PROXY_AUTH_BINARY_VALIDATOR, '" > "', PARAM_ACC_PROXY_AUTH_BINARY_VALIDATOR, '"'));
	END IF;	
	IF TEMP_ACC_PROXY_STATUS <> PARAM_ACC_PROXY_STATUS THEN
		SET TEMP_RECORD_CHANGES = 
		`SYSTEM_VAR@CONCAT_ADD`(' | ', TEMP_RECORD_CHANGES, CONCAT_WS(' ', 'Status: "', TEMP_ACC_PROXY_STATUS, '" > "', PARAM_ACC_PROXY_STATUS, '"'));
	END IF;	
		
	-- No Changes in data, reject request
	-- ####################################################
	IF CHARACTER_LENGTH(TEMP_RECORD_CHANGES) = 0 THEN
		IF PARAM_SUPPRESS_RETURN = 0 THEN
			SELECT PARAM_ACC_PROXY_ID AS INSERTED_ID;
		END IF;
		LEAVE SP_SAVE;
	END IF;



	-- 7) VALIDATE
	-- _______________________________________________________________________

	-- Access Rights [Device]
	-- ####################################################
	IF `ACCOUNT_DEVICE@HAS_PERMISSION`(PARAM_REQUESTER_DEVICE_PUBLIC_KEY, PARAM_REQUESTER_DEVICE_PRIVATE_KEY) = 0 THEN
		SET TEMP_ERR_MESSAGE = 'Your device is not authorized yet to access this server.';
		SET ERR = `RAISERROR`(TEMP_ERR_MESSAGE);		
	END IF;
		
		
	-- Access Rights [Account]
	-- ####################################################
	
	IF 
		-- [ADD] Access Rights
		(
			TEMP_RECORD_EXISTS = 0 AND
			`ACCOUNT_ACCESS_RIGHTS@HAS_PERMISSION`(PARAM_REQUESTER_USERNAME, PARAM_REQUESTER_PASSWORD, 0, TEMP_MODULE_KEYWORD, 2) = 0 
		) OR
		
		-- [EDIT] Access Rights
		(
			TEMP_RECORD_EXISTS = 1 AND
			`ACCOUNT_ACCESS_RIGHTS@HAS_PERMISSION`(PARAM_REQUESTER_USERNAME, PARAM_REQUESTER_PASSWORD, 0, TEMP_MODULE_KEYWORD, 3) = 0 
		)
	THEN
		SET TEMP_ACCESS_RIGHTS_DENIED = 1;
		CALL `ACCOUNT_ACCESS_RIGHTS_DENY`
		(
			0, TEMP_MODULE_KEYWORD, PARAM_ACC_PROXY_ID, 0, TEMP_SP_OBJECTIVE, TEMP_RECORD_CHANGES, 
			PARAM_REQUESTER_USERNAME, PARAM_REQUESTER_PASSWORD, 
			PARAM_REQUESTER_PROXY_ID, PARAM_REQUESTER_PROXY_PASSWORD,
			PARAM_REQUESTER_DEVICE_PUBLIC_KEY, PARAM_REQUESTER_DEVICE_PRIVATE_KEY,
			PARAM_REQUESTER_IP, PARAM_UNIQUE_SESSION_ID,
			TEMP_SYNC_SERVER_ID, PARAM_SUPPRESS_RETURN
		);
	END IF;
	SET TEMP_ACCESS_RIGHTS_HAS_OVERRIDE = `ACCOUNT_ACCESS_RIGHTS@HAS_PERMISSION`(PARAM_REQUESTER_USERNAME, PARAM_REQUESTER_PASSWORD, 0, TEMP_MODULE_KEYWORD, 4);
	

	-- Validation
	-- ####################################################
	IF TEMP_SYNC_IS_SERVER_REQUEST = 0 THEN
	

		-- FOREIGN KEY EXISTS
		-- ...........................................
		
		-- FOREIGN (OPTIONAL)KEY EXISTS [Validates if not null]
		-- ...........................................
		
		-- IS_ALLOW_NULL = FALSE
		-- ...........................................
				
		-- IS_ALLOW_ZERO = FALSE
		-- ...........................................
		IF PARAM_ACC_PROXY_AUTH_BINARY_VALIDATOR = 0 THEN
			CALL `VALIDATION_MISSING_FIELD`('`ACC_PROXY_AUTH_BINARY_VALIDATOR`', '`NULL`');
		END IF;		
		IF PARAM_ACC_PROXY_STATUS = 0 THEN
			CALL `VALIDATION_MISSING_FIELD`('`ACC_PROXY_STATUS`', '`NULL`');
		END IF;		
		
		-- IS_ALLOW_NEGATIVE = FALSE
		-- ...........................................
		IF PARAM_ACC_PROXY_AUTH_BINARY_VALIDATOR < 0 THEN
			CALL `VALIDATION_NEGATIVE`('`ACC_PROXY_AUTH_BINARY_VALIDATOR`', PARAM_ACC_PROXY_AUTH_BINARY_VALIDATOR);
		END IF;		
		IF PARAM_ACC_PROXY_STATUS < 0 THEN
			CALL `VALIDATION_NEGATIVE`('`ACC_PROXY_STATUS`', PARAM_ACC_PROXY_STATUS);
		END IF;		
		
		-- IS_ALLOW_EMPTY_STRING = FALSE
		-- ...........................................
		IF `SYSTEM_VAR@IS_NULL@NVARCHAR`(PARAM_ACC_PROXY_AUTH_OWNER, 1) = 1 THEN
			CALL `VALIDATION_MISSING_FIELD`('`ACC_PROXY_AUTH_OWNER`', '`NULL`');
		END IF;
		IF `SYSTEM_VAR@IS_NULL@NVARCHAR`(PARAM_ACC_PROXY_AUTH_HASH, 1) = 1 THEN
			CALL `VALIDATION_MISSING_FIELD`('`ACC_PROXY_AUTH_HASH`', '`NULL`');
		END IF;
		IF `SYSTEM_VAR@IS_NULL@NVARCHAR`(PARAM_ACC_PROXY_AUTH_STRING_VALIDATOR, 1) = 1 THEN
			CALL `VALIDATION_MISSING_FIELD`('`ACC_PROXY_AUTH_STRING_VALIDATOR`', '`NULL`');
		END IF;
		
		-- IS_STATUS
		-- ...........................................
		IF `SYSTEM_STATUS@STATUS_ID_EXISTS`(PARAM_ACC_PROXY_STATUS, 0) = 0 THEN
			SET TEMP_ERR_MESSAGE = CONCAT_WS(' ', 'Given STATUS[Status] does not exists or is inactive. ID: ', PARAM_ACC_PROXY_STATUS);
			SET ERR = `RAISERROR`(TEMP_ERR_MESSAGE);
		END IF;
		
		-- IS STATUS Active / Inactive
		-- ...........................................
		
		-- Minimum / Maximum Value
		-- ...........................................
		
		-- IS_UNIQUE = TRUE
		-- ...........................................
		
		-- RECORD IDENTIFIER
		-- ...........................................
		
		
		-- ON_UPDATE VALIDATION 
		-- ...........................................
		IF TEMP_RECORD_EXISTS = 1 THEN	
		
			-- Just to keep at least one line within condition
			SET TEMP_RECORD_EXISTS = 1;
			
		END IF;
		
	END IF;



	-- 8) INSERT / UPDATE
	-- _______________________________________________________________________

	-- INSERT NEW DATA
	-- ####################################################
	IF TEMP_RECORD_EXISTS = 0 THEN

		INSERT INTO
		`account_proxy_access`
		(
			`account_proxy_access`.`ACC_PROXY_AUTH_OWNER`, 
			`account_proxy_access`.`ACC_PROXY_AUTH_HASH`, 
			`account_proxy_access`.`ACC_PROXY_AUTH_STRING_VALIDATOR`, 
			`account_proxy_access`.`ACC_PROXY_AUTH_BINARY_VALIDATOR`, 
			`account_proxy_access`.`ACC_PROXY_STATUS`
		)
		VALUES
		(
			PARAM_ACC_PROXY_AUTH_OWNER, 
			PARAM_ACC_PROXY_AUTH_HASH, 
			PARAM_ACC_PROXY_AUTH_STRING_VALIDATOR, 
			PARAM_ACC_PROXY_AUTH_BINARY_VALIDATOR, 
			PARAM_ACC_PROXY_STATUS
		);	
		
		-- Update Audit trail with new ID	
		SET PARAM_ACC_PROXY_ID = LAST_INSERT_ID();



	-- UPDATING EXISTING RECORD
	-- ####################################################
	ELSE
		UPDATE `account_proxy_access`
		SET
			`account_proxy_access`.`ACC_PROXY_AUTH_OWNER` = PARAM_ACC_PROXY_AUTH_OWNER, 
			`account_proxy_access`.`ACC_PROXY_AUTH_HASH` = PARAM_ACC_PROXY_AUTH_HASH, 
			`account_proxy_access`.`ACC_PROXY_AUTH_STRING_VALIDATOR` = PARAM_ACC_PROXY_AUTH_STRING_VALIDATOR, 
			`account_proxy_access`.`ACC_PROXY_AUTH_BINARY_VALIDATOR` = PARAM_ACC_PROXY_AUTH_BINARY_VALIDATOR, 
			`account_proxy_access`.`ACC_PROXY_STATUS` = PARAM_ACC_PROXY_STATUS
		WHERE
			`account_proxy_access`.`ACC_PROXY_ID` = PARAM_ACC_PROXY_ID;

	END IF;

	
	-- 9) AUDIT TRAIL
	-- _______________________________________________________________________
	CALL `ACCOUNT_AUDIT_TRAIL_SAVE`
	(
		0, TEMP_MODULE_KEYWORD, PARAM_ACC_PROXY_ID, 0, 'SAVE', TEMP_SP_OBJECTIVE, TEMP_RECORD_CHANGES, 
		PARAM_REQUESTER_USERNAME, PARAM_REQUESTER_PASSWORD, 
		PARAM_REQUESTER_PROXY_ID, PARAM_REQUESTER_PROXY_PASSWORD,
		PARAM_REQUESTER_DEVICE_PUBLIC_KEY, PARAM_REQUESTER_DEVICE_PRIVATE_KEY,
		PARAM_REQUESTER_IP, PARAM_UNIQUE_SESSION_ID,
		TEMP_SYNC_SERVER_ID, PARAM_SUPPRESS_RETURN
	);
	

	-- 10) RETURN RESULT
	-- _______________________________________________________________________
	IF PARAM_SUPPRESS_RETURN = 0 THEN
		SELECT PARAM_ACC_PROXY_ID AS INSERTED_ID;
	END IF;
	LEAVE SP_SAVE;


END ;;
DELIMITER ;
/*!50003 SET sql_mode              = @saved_sql_mode */ ;
/*!50003 SET character_set_client  = @saved_cs_client */ ;
/*!50003 SET character_set_results = @saved_cs_results */ ;
/*!50003 SET collation_connection  = @saved_col_connection */ ;
/*!50003 DROP PROCEDURE IF EXISTS `ACCOUNT_PROXY_LOGIN` */;
/*!50003 SET @saved_cs_client      = @@character_set_client */ ;
/*!50003 SET @saved_cs_results     = @@character_set_results */ ;
/*!50003 SET @saved_col_connection = @@collation_connection */ ;
/*!50003 SET character_set_client  = latin1 */ ;
/*!50003 SET character_set_results = latin1 */ ;
/*!50003 SET collation_connection  = latin1_swedish_ci */ ;
/*!50003 SET @saved_sql_mode       = @@sql_mode */ ;
/*!50003 SET sql_mode              = '' */ ;
DELIMITER ;;
CREATE DEFINER=`root`@`localhost` PROCEDURE `ACCOUNT_PROXY_LOGIN`(
	IN `PARAM_ACC_ACCOUNT_USERNAME` VARCHAR(1000),
	IN `PARAM_ACC_ACCOUNT_PASSWORD` VARCHAR(1000),

	IN `PARAM_REQUESTER_USERNAME` VARCHAR(500),
	IN `PARAM_REQUESTER_PASSWORD` VARCHAR(500),
	IN `PARAM_REQUESTER_PROXY_ID` BIGINT,
	IN `PARAM_REQUESTER_PROXY_PASSWORD` VARCHAR(1000),
	IN `PARAM_REQUESTER_DEVICE_PUBLIC_KEY` VARCHAR(1000),
	IN `PARAM_REQUESTER_DEVICE_PRIVATE_KEY` VARCHAR(1000),
	
	IN `PARAM_REQUESTER_IP` VARCHAR(1000),
	IN `PARAM_UNIQUE_SESSION_ID` VARCHAR(1000),
	IN `PARAM_SUPPRESS_RETURN` BIT
)
SP_GET:
BEGIN

	-- Initialize
	-- _______________________________________________________________________

	-- Status
	-- ...........................................
	DECLARE STATUS_INACTIVE TINYINT DEFAULT 1;
	DECLARE STATUS_ACTIVE TINYINT DEFAULT 2;
	DECLARE STATUS_CLOSED TINYINT DEFAULT 3;
	DECLARE STATUS_COMPLETED TINYINT DEFAULT 4;

	-- Audit Handler
	-- ...........................................
	DECLARE TEMP_MODULE_KEYWORD VARCHAR(500) DEFAULT 'account_member';
	DECLARE TEMP_SP_OBJECTIVE VARCHAR(500) DEFAULT 'retrieve User account record';
	DECLARE TEMP_ERR_MESSAGE VARCHAR(500) DEFAULT '';
	DECLARE ERR BIGINT DEFAULT 0;
	DECLARE TEMP_RECORD_CHANGES VARCHAR(16000) DEFAULT '';
	DECLARE TEMP_RECORD_BINDED BIT DEFAULT 0;


	-- Authentication
	-- ...........................................
	DECLARE TEMP_ACCESS_RIGHTS_DENIED BIT DEFAULT 0;
	DECLARE TEMP_SYNC_SERVER_ID BIGINT DEFAULT 0;
	DECLARE TEMP_SYNC_IS_SERVER_REQUEST BIT DEFAULT 0;
	DECLARE TEMP_AUTHENTICATED_ACCOUNT_ID BIGINT DEFAULT `ACCOUNT_MEMBER@ACC_ACCOUNT_ID_FROM_LOGIN`(PARAM_REQUESTER_USERNAME, PARAM_REQUESTER_PASSWORD);
	DECLARE TEMP_AUTHENTICATED_ACCOUNT_PASSWORD VARCHAR(4000) DEFAULT 0;
	DECLARE TEMP_AUTHENTICATED_ACCOUNT_LEVEL BIGINT DEFAULT 0;
	DECLARE TEMP_AUTHENTICATED_ACCOUNT_GROUP BIGINT DEFAULT 0;
	
	
	-- Local value holder
	-- ...........................................
	
	
	-- Check NULLs
	-- ...........................................
	DECLARE IS_NULL_ACCOUNT_USERNAME BIT DEFAULT `SYSTEM_VAR@IS_NULL@NVARCHAR`(PARAM_ACC_ACCOUNT_USERNAME, 1);
	DECLARE IS_NULL_ACCOUNT_PASSWORD BIT DEFAULT `SYSTEM_VAR@IS_NULL@NVARCHAR`(PARAM_ACC_ACCOUNT_PASSWORD, 1);
	
	
	-- Error Handler
	-- _______________________________________________________________________
	DECLARE EXIT HANDLER FOR SQLEXCEPTION
	BEGIN
		RESIGNAL;
	END;


	-- Access Rights [Device]
	-- _______________________________________________________________________
	IF `ACCOUNT_DEVICE@HAS_PERMISSION`(PARAM_REQUESTER_DEVICE_PUBLIC_KEY, PARAM_REQUESTER_DEVICE_PRIVATE_KEY) = 0 THEN
		SET TEMP_ERR_MESSAGE = 'Your device is not authorized yet to access this server.';
		SET ERR = `RAISERROR`(TEMP_ERR_MESSAGE);		
	END IF;
	

	-- Parameter Validation
	-- _______________________________________________________________________
	IF IS_NULL_ACCOUNT_USERNAME = 1 THEN
		SET TEMP_ERR_MESSAGE = 'Username is required.';
		SET ERR = `RAISERROR`(TEMP_ERR_MESSAGE);	
	END IF;
	IF IS_NULL_ACCOUNT_PASSWORD = 1 THEN
		SET TEMP_ERR_MESSAGE = 'Password is required.';
		SET ERR = `RAISERROR`(TEMP_ERR_MESSAGE);	
	END IF;		
	IF TEMP_AUTHENTICATED_ACCOUNT_ID <= 0 THEN -- Should not allow proxy login without been authenticated 
		SET TEMP_ERR_MESSAGE = 'You must login to request for proxy auth.';
		SET ERR = `RAISERROR`(TEMP_ERR_MESSAGE);		
	END IF;
	IF PARAM_ACC_ACCOUNT_USERNAME = PARAM_REQUESTER_USERNAME THEN -- Proxy must not self
		SET TEMP_ERR_MESSAGE = 'Cannot use self as a proxy.';
		SET ERR = `RAISERROR`(TEMP_ERR_MESSAGE);		
	END IF;


	-- LOGIN ATTEMPT
	-- _______________________________________________________________________
	
	-- Read Password Salt
	-- ####################################################
	SELECT
		`account_member`.`ACC_ACCOUNT_ID`,
		`account_member`.`ACC_ACCOUNT_ACC_LEVEL_ID`,
		`account_member`.`ACC_ACCOUNT_PASSWORD`
	INTO
		TEMP_AUTHENTICATED_ACCOUNT_ID,
		TEMP_AUTHENTICATED_ACCOUNT_LEVEL,
		TEMP_AUTHENTICATED_ACCOUNT_PASSWORD
	FROM `account_member`
	WHERE
		`account_member`.`ACC_ACCOUNT_USERNAME` = PARAM_ACC_ACCOUNT_USERNAME AND
		`account_member`.`ACC_ACCOUNT_STATUS` = 2
	LIMIT 1;		
	
	-- Checks the result
	-- ####################################################
	IF
		CHAR_LENGTH(TEMP_AUTHENTICATED_ACCOUNT_PASSWORD) <= 0 OR
		`FUN_SHA512_VERIFY`
		(
			TEMP_AUTHENTICATED_ACCOUNT_PASSWORD,
			PARAM_ACC_ACCOUNT_PASSWORD,
			1
		) = 0
	THEN
		-- SET @TEMP_ERR_MESSAGE = 'Invalid username or password.';
		-- RAISERROR(@TEMP_ERR_MESSAGE, 11, 1);		
		LEAVE SP_GET;
	END IF;


	-- Check if Access Level if active (Status = 2)
	-- ####################################################
	IF
		(
			SELECT  COUNT(`account_level`.`ACC_LEVEL_ID`)
			FROM `account_level`
			WHERE
				`account_level`.`ACC_LEVEL_ID` = TEMP_AUTHENTICATED_ACCOUNT_LEVEL AND
				`account_level`.`ACC_LEVEL_STATUS` = STATUS_ACTIVE
			LIMIT 1
		) <= 0
	THEN
		LEAVE SP_GET;
	END IF;


		
	-- Call for prepare Access Rights
	-- ####################################################
	CALL `ACCOUNT_ACCESS_RIGHTS_PREPARE`
	(
		TEMP_AUTHENTICATED_ACCOUNT_LEVEL,
		
		PARAM_ACC_ACCOUNT_USERNAME, PARAM_REQUESTER_PASSWORD,
		PARAM_REQUESTER_PROXY_ID, PARAM_REQUESTER_PROXY_PASSWORD,
		PARAM_REQUESTER_DEVICE_PUBLIC_KEY, PARAM_REQUESTER_DEVICE_PRIVATE_KEY,
		PARAM_REQUESTER_IP,
		PARAM_UNIQUE_SESSION_ID,
		1
	);

	-- RETURN RESULT
	-- _______________________________________________________________________
	SELECT
		TEMP_AUTHENTICATED_ACCOUNT_ID AS ACCOUNT_ID,
		TEMP_AUTHENTICATED_ACCOUNT_LEVEL AS ACCOUNT_LEVEL,
		TEMP_AUTHENTICATED_ACCOUNT_PASSWORD AS ACCOUNT_PASSWORD;


END ;;
DELIMITER ;
/*!50003 SET sql_mode              = @saved_sql_mode */ ;
/*!50003 SET character_set_client  = @saved_cs_client */ ;
/*!50003 SET character_set_results = @saved_cs_results */ ;
/*!50003 SET collation_connection  = @saved_col_connection */ ;
/*!50003 DROP PROCEDURE IF EXISTS `ACCOUNT_SERVER_DELETE` */;
/*!50003 SET @saved_cs_client      = @@character_set_client */ ;
/*!50003 SET @saved_cs_results     = @@character_set_results */ ;
/*!50003 SET @saved_col_connection = @@collation_connection */ ;
/*!50003 SET character_set_client  = latin1 */ ;
/*!50003 SET character_set_results = latin1 */ ;
/*!50003 SET collation_connection  = latin1_swedish_ci */ ;
/*!50003 SET @saved_sql_mode       = @@sql_mode */ ;
/*!50003 SET sql_mode              = '' */ ;
DELIMITER ;;
CREATE DEFINER=`root`@`localhost` PROCEDURE `ACCOUNT_SERVER_DELETE`(
	IN `PARAM_ACC_SERVER_ID` BIGINT,
	
	IN `PARAM_REQUESTER_USERNAME` VARCHAR(500),
	IN `PARAM_REQUESTER_PASSWORD` VARCHAR(500),
	IN `PARAM_REQUESTER_IP` VARCHAR(1000),
	IN `PARAM_UNIQUE_SESSION_ID` VARCHAR(1000),
	IN `PARAM_SUPPRESS_RETURN` BIT,
	
	IN `PARAM_SYNC_SERVER_DESCRIPTION` VARCHAR(500), 
	IN `PARAM_SYNC_SERVER_UNIQUE_KEY` VARCHAR(500)
)
SP_DELETE:
BEGIN

	-- 1) DECLARE LOCAL PARAMETERS
	-- ====================================================================================================================================================================
	-- Audit Handler
	DECLARE TEMP_RECORD_EXISTS BIT DEFAULT `ACCOUNT_SERVER@ACC_SERVER_ID_EXISTS`(PARAM_ACC_SERVER_ID, 0);
	DECLARE TEMP_MODULE_KEYWORD VARCHAR(500) DEFAULT 'account_server';
	DECLARE TEMP_SP_OBJECTIVE VARCHAR(500) DEFAULT 'delete child server record';
	DECLARE TEMP_ERR_MESSAGE VARCHAR(500) DEFAULT '';
	DECLARE ERR BIGINT DEFAULT 0;
	DECLARE TEMP_RECORD_CHANGES VARCHAR(16000) DEFAULT '';
	DECLARE TEMP_RECORD_BINDED BIT DEFAULT 0;

	-- Authentication
	DECLARE TEMP_ACCESS_RIGHTS_DENIED BIT DEFAULT 0;
	DECLARE TEMP_SYNC_SERVER_ID BIGINT DEFAULT 0;
	DECLARE TEMP_SYNC_IS_SERVER_REQUEST BIT DEFAULT 0;
	DECLARE TEMP_AUTHENTICATED_ACCOUNT_ID BIGINT DEFAULT `ACCOUNT_MEMBER@ACC_ACCOUNT_ID_FROM_LOGIN`(PARAM_REQUESTER_USERNAME, PARAM_REQUESTER_PASSWORD);
	DECLARE TEMP_AUTHENTICATED_ACCOUNT_LEVEL BIGINT DEFAULT 0;

	-- Local value holder
	DECLARE TEMP_SERVER_ID BIGINT DEFAULT 0;	
	DECLARE TEMP_SERVER_TITLE VARCHAR(500) DEFAULT '';
	DECLARE TEMP_SERVER_DESCRIPTION VARCHAR(500) DEFAULT '';
	DECLARE TEMP_SERVER_UNIQUE_KEY VARCHAR(500) DEFAULT '';
	DECLARE TEMP_SERVER_IS_MOTHER TINYINT DEFAULT 0;
	DECLARE TEMP_SERVER_ADDRESS VARCHAR(500) DEFAULT '';
	DECLARE TEMP_SERVER_LAST_SYNCHRONIZED DATETIME(6) DEFAULT '1000-01-01 00:00:00.000000';
	DECLARE TEMP_SERVER_STATUS TINYINT DEFAULT 0;
	
	DECLARE TEMP_SYSTEM_GENERATED TINYINT DEFAULT 0;
	-- ====================================================================================================================================================================
	
	
	-- 2) Try Catch / Throw
	-- ====================================================================================================================================================================
	DECLARE EXIT HANDLER FOR SQLEXCEPTION
	BEGIN
		RESIGNAL;
	END;
	-- ====================================================================================================================================================================
	
	
	-- 3) IF ALREADY EXIST, FILL MISSING DATA
	-- ====================================================================================================================================================================
	IF TEMP_RECORD_EXISTS = 1 THEN
	
		SELECT
			`account_server`.`ACC_SERVER_ID`,
			
			`account_server`.`ACC_SERVER_TITLE`,
			`account_server`.`ACC_SERVER_DESCRIPTION`,
			`account_server`.`ACC_SERVER_UNIQUE_KEY`,
			`account_server`.`ACC_SERVER_IS_MOTHER`,
			`account_server`.`ACC_SERVER_ADDRESS`,
			`account_server`.`ACC_SERVER_LAST_SYNCHRONIZED`,
			`account_server`.`ACC_SERVER_STATUS`,
			
			`account_server`.`ACC_SERVER_SYSTEM_GENERATED`
			
		INTO
			TEMP_SERVER_ID,
			
			TEMP_SERVER_TITLE,
			TEMP_SERVER_DESCRIPTION,
			TEMP_SERVER_UNIQUE_KEY,
			TEMP_SERVER_IS_MOTHER,
			TEMP_SERVER_ADDRESS,
			TEMP_SERVER_LAST_SYNCHRONIZED,
			TEMP_SERVER_STATUS,
			
			TEMP_SYSTEM_GENERATED
			
		FROM `account_server`
		WHERE
			`account_server`.`ACC_SERVER_ID` = PARAM_ACC_SERVER_ID
		LIMIT 1;
		
	ELSE
		SET TEMP_ERR_MESSAGE = CONCAT_WS(' ', 'Given SERVER does not exists or is inactive. ID: ', PARAM_ACC_SERVER_ID);
		SET ERR = `RAISERROR`(TEMP_ERR_MESSAGE);			
	END IF;
	-- ====================================================================================================================================================================


	-- 4) PREPARE AUDIT TRAIL
	-- ====================================================================================================================================================================
	SET TEMP_RECORD_CHANGES = 
	`SYSTEM_VAR@CONCAT_ADD`(' | ', TEMP_RECORD_CHANGES, CONCAT_WS(' ', 'TITLE:"', TEMP_SERVER_TITLE, '" > "DELETED"'));
	
	SET TEMP_RECORD_CHANGES = 
	`SYSTEM_VAR@CONCAT_ADD`(' | ', TEMP_RECORD_CHANGES, CONCAT_WS(' ', 'DESCRIPTION:"', TEMP_SERVER_DESCRIPTION, '" > "DELETED"'));

	SET TEMP_RECORD_CHANGES = 
	`SYSTEM_VAR@CONCAT_ADD`(' | ', TEMP_RECORD_CHANGES, CONCAT_WS(' ', 'UNIQUE KEY:"', TEMP_SERVER_UNIQUE_KEY, '" > "DELETED"'));

	SET TEMP_RECORD_CHANGES = 
	`SYSTEM_VAR@CONCAT_ADD`
	(
		' | ', TEMP_RECORD_CHANGES, CONCAT_WS
		(
			' ',
			'IS MOTHER SERVER: ', TEMP_SERVER_IS_MOTHER, '("', `SYSTEM_STATUS@SYS_STATUS_DESCRIPTION_FROM_ID`(TEMP_SERVER_IS_MOTHER), '")',
			' > 0 ("DELETED")'
		)
	);

	SET TEMP_RECORD_CHANGES = 
	`SYSTEM_VAR@CONCAT_ADD`(' | ', TEMP_RECORD_CHANGES, CONCAT_WS(' ', 'SERVER ADDRESS:"', TEMP_SERVER_ADDRESS, '" > "DELETED"'));

	SET TEMP_RECORD_CHANGES = 
	`SYSTEM_VAR@CONCAT_ADD`(' | ', TEMP_RECORD_CHANGES, CONCAT_WS(' ', 'SYNCHRONIZED DATE:"', TEMP_SERVER_LAST_SYNCHRONIZED, '" > "DELETED"'));

	SET TEMP_RECORD_CHANGES = 
	`SYSTEM_VAR@CONCAT_ADD`
	(
		' | ', TEMP_RECORD_CHANGES, CONCAT_WS
		(
			' ',
			'STATUS: ', TEMP_SERVER_STATUS, '("', `SYSTEM_STATUS@SYS_STATUS_DESCRIPTION_FROM_ID`(TEMP_SERVER_STATUS), '")',
			' > 0 ("DELETED")'
		)
	);
	
	SET TEMP_RECORD_CHANGES = 
	`SYSTEM_VAR@CONCAT_ADD`(' | ', TEMP_RECORD_CHANGES, CONCAT_WS(' ', 'SYNC_RESULT_DATASET: "..." > "DELETED"'));

	-- No Changes in data, reject request
	IF CHAR_LENGTH(TEMP_RECORD_CHANGES) = 0 THEN
		IF PARAM_SUPPRESS_RETURN = 0 THEN
			SELECT PARAM_ACC_SERVER_ID AS INSERTED_ID;
		END IF;	
		LEAVE SP_DELETE;
	END IF;
	-- ====================================================================================================================================================================
	
	
	-- 5) VALIDATE
	-- ====================================================================================================================================================================
	-- Access Rights
	IF `ACCOUNT_ACCESS_RIGHTS@HAS_PERMISSION`(PARAM_REQUESTER_USERNAME, PARAM_REQUESTER_PASSWORD, 0, TEMP_MODULE_KEYWORD, 4) = 0 THEN
		SET TEMP_ACCESS_RIGHTS_DENIED = 1;
		CALL `ACCOUNT_ACCESS_RIGHTS_DENY`
		(
			0, TEMP_MODULE_KEYWORD, PARAM_ACC_SERVER_ID, TEMP_SERVER_ID, TEMP_SP_OBJECTIVE, TEMP_RECORD_CHANGES, 
			PARAM_REQUESTER_USERNAME, PARAM_REQUESTER_PASSWORD, PARAM_REQUESTER_IP, PARAM_UNIQUE_SESSION_ID,
			TEMP_SYNC_SERVER_ID, PARAM_SUPPRESS_RETURN
		);
	END IF;
	
	-- SYSTEM_GENERATED
	IF TEMP_SYSTEM_GENERATED = 2 THEN
		CALL `VALIDATION_SYSTEM_GENERATED`(PARAM_ACC_SERVER_ID, TEMP_SERVER_DESCRIPTION, '');
	END IF;
	-- ====================================================================================================================================================================

	
	-- 6) DELETE
	-- ====================================================================================================================================================================
	DELETE FROM `account_server`
	WHERE `account_server`.`ACC_SERVER_ID` = PARAM_ACC_SERVER_ID
	LIMIT 1;
	-- ====================================================================================================================================================================


	-- 7) AUDIT TRAIL
	-- ====================================================================================================================================================================
	CALL `ACCOUNT_AUDIT_TRAIL_SAVE`
	(
		0, TEMP_MODULE_KEYWORD, PARAM_ACC_SERVER_ID, TEMP_SERVER_ID, 'DELETE', TEMP_SP_OBJECTIVE, TEMP_RECORD_CHANGES, 
		PARAM_REQUESTER_USERNAME, PARAM_REQUESTER_PASSWORD, PARAM_REQUESTER_IP, PARAM_UNIQUE_SESSION_ID,
		TEMP_SYNC_SERVER_ID, PARAM_SUPPRESS_RETURN
	);
	-- ====================================================================================================================================================================
	
END ;;
DELIMITER ;
/*!50003 SET sql_mode              = @saved_sql_mode */ ;
/*!50003 SET character_set_client  = @saved_cs_client */ ;
/*!50003 SET character_set_results = @saved_cs_results */ ;
/*!50003 SET collation_connection  = @saved_col_connection */ ;
/*!50003 DROP PROCEDURE IF EXISTS `ACCOUNT_SERVER_GET` */;
/*!50003 SET @saved_cs_client      = @@character_set_client */ ;
/*!50003 SET @saved_cs_results     = @@character_set_results */ ;
/*!50003 SET @saved_col_connection = @@collation_connection */ ;
/*!50003 SET character_set_client  = latin1 */ ;
/*!50003 SET character_set_results = latin1 */ ;
/*!50003 SET collation_connection  = latin1_swedish_ci */ ;
/*!50003 SET @saved_sql_mode       = @@sql_mode */ ;
/*!50003 SET sql_mode              = '' */ ;
DELIMITER ;;
CREATE DEFINER=`root`@`localhost` PROCEDURE `ACCOUNT_SERVER_GET`(
	IN `PARAM_ACC_SERVER_ID` BIGINT,
	IN `PARAM_ACC_SERVER_TITLE` VARCHAR(500),
	IN `PARAM_ACC_SERVER_DESCRIPTION` VARCHAR(500),
	IN `PARAM_ACC_SERVER_IS_MOTHER` TINYINT,
	IN `PARAM_ACC_SERVER_ADDRESS` VARCHAR(500),
	
	IN `PARAM_ACC_SERVER_LAST_SYNCHRONIZED_FROM` DATETIME(6),
	IN `PARAM_ACC_SERVER_LAST_SYNCHRONIZED_TO` DATETIME(6),
	IN `PARAM_ACC_SERVER_STATUS` TINYINT,
	IN `PARAM_ACC_SERVER_SYSTEM_GENERATED` TINYINT,
	IN `PARAM_LOGIN_ATTEMPT` BIT,
	
	IN `PARAM_ORDER_FIELD` VARCHAR(500),
	IN `PARAM_ORDER_TYPE` VARCHAR(500),
	IN `PARAM_SKIP` BIGINT,
	IN `PARAM_LIMIT` BIGINT,

	IN `PARAM_REQUESTER_USERNAME` VARCHAR(500),
	IN `PARAM_REQUESTER_PASSWORD` VARCHAR(500),
	IN `PARAM_REQUESTER_IP` VARCHAR(1000),
	IN `PARAM_UNIQUE_SESSION_ID` VARCHAR(1000),
	IN `PARAM_SUPPRESS_RETURN` BIT,
	
	IN `PARAM_SYNC_ACC_SERVER_DESCRIPTION` VARCHAR(500), 
	IN `PARAM_SYNC_ACC_SERVER_UNIQUE_KEY` VARCHAR(500)
)
SP_GET:
BEGIN


	
	-- Initialize
	-- ========================================================================
	DECLARE STATUS_INACTIVE TINYINT DEFAULT 1;
	DECLARE STATUS_ACTIVE TINYINT DEFAULT 2;	
	
	-- Audit Handler
	DECLARE TEMP_MODULE_KEYWORD VARCHAR(500) DEFAULT 'account_server';
	DECLARE TEMP_SP_OBJECTIVE VARCHAR(500) DEFAULT 'retrieve child server record';
	DECLARE TEMP_ERR_MESSAGE VARCHAR(500) DEFAULT '';
	DECLARE ERR BIGINT DEFAULT 0;
	DECLARE TEMP_RECORD_CHANGES VARCHAR(16000) DEFAULT '';

	-- Authentication
	DECLARE TEMP_ACCESS_RIGHTS_DENIED BIT DEFAULT 0;
	DECLARE TEMP_SYNC_ACC_SERVER_ID BIGINT DEFAULT 0;
	DECLARE TEMP_SYNC_IS_SERVER_REQUEST BIT DEFAULT 0;
	DECLARE TEMP_AUTHENTICATED_ACCOUNT_ID BIGINT DEFAULT 0;
	DECLARE TEMP_AUTHENTICATED_ACCOUNT_LEVEL BIGINT DEFAULT 0;
	
	-- Check NULLs
	-- =========================================================================================
	DECLARE TEMP_SERVER_SELF_ID BIGINT DEFAULT `ACCOUNT_SERVER@SELF_ID`();
	
	DECLARE IS_NULL_ACC_SERVER_ID BIT DEFAULT `SYSTEM_VAR@IS_NULL@BIGINT`(PARAM_ACC_SERVER_ID, 1);
	DECLARE IS_NULL_ACC_SERVER_TITLE BIT DEFAULT `SYSTEM_VAR@IS_NULL@NVARCHAR`(PARAM_ACC_SERVER_TITLE, 1);
	DECLARE IS_NULL_ACC_SERVER_DESCRIPTION BIT DEFAULT `SYSTEM_VAR@IS_NULL@NVARCHAR`(PARAM_ACC_SERVER_DESCRIPTION, 1);
	DECLARE IS_NULL_ACC_SERVER_IS_MOTHER BIT DEFAULT `SYSTEM_VAR@IS_NULL@TINYINT`(PARAM_ACC_SERVER_IS_MOTHER, 1);
	DECLARE IS_NULL_ACC_SERVER_ADDRESS BIT DEFAULT `SYSTEM_VAR@IS_NULL@NVARCHAR`(PARAM_ACC_SERVER_ADDRESS, 1);
	DECLARE IS_NULL_ACC_SERVER_LAST_SYNCHRONIZED_FROM BIT DEFAULT `SYSTEM_VAR@IS_NULL@DATETIME`(PARAM_ACC_SERVER_LAST_SYNCHRONIZED_FROM, 1);
	DECLARE IS_NULL_ACC_SERVER_LAST_SYNCHRONIZED_TO BIT DEFAULT `SYSTEM_VAR@IS_NULL@DATETIME`(PARAM_ACC_SERVER_LAST_SYNCHRONIZED_TO, 1);
	DECLARE IS_NULL_ACC_SERVER_STATUS BIT DEFAULT `SYSTEM_VAR@IS_NULL@TINYINT`(PARAM_ACC_SERVER_STATUS, 1);
	DECLARE IS_NULL_ACC_SERVER_SYSTEM_GENERATED BIT DEFAULT `SYSTEM_VAR@IS_NULL@TINYINT`(PARAM_ACC_SERVER_SYSTEM_GENERATED, 1);
	
	
	-- Error Handler
	-- =========================================================================================
	DECLARE EXIT HANDLER FOR SQLEXCEPTION
	BEGIN
		RESIGNAL;
	END;
		
	-- Prepare SYNC
	-- ====================================================================================================================================================================

	-- IS SERVE REQUEST
	IF
		`SYSTEM_VAR@IS_NULL@NVARCHAR`(PARAM_SYNC_ACC_SERVER_DESCRIPTION, 1) = 0 AND
		`SYSTEM_VAR@IS_NULL@NVARCHAR`(PARAM_SYNC_ACC_SERVER_UNIQUE_KEY, 1) = 0
	THEN
	
		-- SET REQUEST CAME FROM SYNC 
		SET TEMP_SYNC_IS_SERVER_REQUEST = 1;
		
		-- GET SERVER ID
		SET TEMP_SYNC_ACC_SERVER_ID = `ACCOUNT_SERVER@ACC_SERVER_ID_FROM_LOGIN`(PARAM_SYNC_ACC_SERVER_DESCRIPTION, PARAM_SYNC_ACC_SERVER_UNIQUE_KEY);
			
	END IF;

	
	
	-- ====================================================================================================================================================================
	IF PARAM_LOGIN_ATTEMPT = 1 THEN
	
		-- SELECT ACCOUNTS
		-- =========================================================================================
		SELECT
			-- SERVER DATA
			`account_server`.`ACC_SERVER_ID`,
			`account_server`.`ACC_SERVER_TITLE`,
			`account_server`.`ACC_SERVER_DESCRIPTION`,
			`account_server`.`ACC_SERVER_UNIQUE_KEY`,
			`account_server`.`ACC_SERVER_STATUS`

		FROM `account_server`

		-- CONDITIONS
		-- =========================================================================================
		 WHERE
			`account_server`.`ACC_SERVER_DESCRIPTION` = PARAM_ACC_SERVER_DESCRIPTION AND
			`account_server`.`ACC_SERVER_IS_MOTHER` = STATUS_INACTIVE AND
			`account_server`.`ACC_SERVER_SYSTEM_GENERATED` = STATUS_INACTIVE
		LIMIT 1;
		LEAVE SP_GET;
	
	ELSE
	
		-- Access Rights
		-- =========================================================================================
		-- SET TEMP_AUTHENTICATED_ACCOUNT_ID = `ACCOUNT_MEMBER@ACCOUNT_ID_FROM_LOGIN`(PARAM_REQUESTER_USERNAME, PARAM_REQUESTER_PASSWORD);
		IF 
			`ACCOUNT_ACCESS_RIGHTS@HAS_PERMISSION`(PARAM_REQUESTER_USERNAME, PARAM_REQUESTER_PASSWORD, 0, TEMP_MODULE_KEYWORD, 1) = 0 AND
			TEMP_SYNC_ACC_SERVER_ID <> PARAM_ACC_SERVER_ID
		THEN
			CALL `ACCOUNT_ACCESS_RIGHTS_DENY`
			(
				0, TEMP_MODULE_KEYWORD, PARAM_ACC_SERVER_ID, 0, TEMP_SP_OBJECTIVE, '', 
				PARAM_REQUESTER_USERNAME, PARAM_REQUESTER_PASSWORD, PARAM_REQUESTER_IP, PARAM_UNIQUE_SESSION_ID,
				0, PARAM_SUPPRESS_RETURN
			);
		END IF;

		
		-- RETRIEVE SELF
		IF 
			TEMP_SERVER_SELF_ID = PARAM_ACC_SERVER_ID OR
			PARAM_ACC_SERVER_ADDRESS = 'SELF'
		THEN
		
			-- SELECT ACCOUNTS
			-- =========================================================================================
			SELECT
				-- SELF SERVER DATA
				`account_server`.`ACC_SERVER_ID`,
				`account_server`.`SERVER_SYNC_RESULT_DATASET`
			FROM `account_server`
			WHERE
				`account_server`.`ACC_SERVER_ID` = TEMP_SERVER_SELF_ID							
			LIMIT 1;		
			LEAVE SP_GET;
			
		ELSE
		
		
			-- SELECT ACCOUNTS
			-- =========================================================================================
			SELECT
				-- SERVER DATA
				`account_server`.`ACC_SERVER_ID`,
				`account_server`.`ACC_SERVER_TITLE`,
				`account_server`.`ACC_SERVER_DESCRIPTION`,
				`account_server`.`ACC_SERVER_UNIQUE_KEY`,
				
				`account_server`.`ACC_SERVER_IS_MOTHER`,
				`account_server`.`ACC_SERVER_ADDRESS`,
				`account_server`.`SERVER_LAST_SYNCHRONIZED`,
				`account_server`.`ACC_SERVER_STATUS`,
				
				`account_server`.`SERVER_SYNC_RESULT_DATASET`,
				`account_server`.`ACC_SERVER_SYSTEM_GENERATED`,

				-- STATUS DATA
				`system_status`.`STATUS_DESCRIPTION`

			FROM `account_server`
				INNER JOIN `system_status` ON
				`system_status`.`STATUS_ID` = `account_server`.`ACC_SERVER_STATUS`

			-- CONDITIONS
			-- =========================================================================================
			 WHERE
				(
					IS_NULL_ACC_SERVER_ID = 1 OR
					`account_server`.`ACC_SERVER_ID` = PARAM_ACC_SERVER_ID
				) AND
				
				(
					IS_NULL_ACC_SERVER_TITLE = 1 OR
					`account_server`.`ACC_SERVER_TITLE` = PARAM_ACC_SERVER_TITLE
				) AND
				(
					IS_NULL_ACC_SERVER_DESCRIPTION = 1 OR
					`account_server`.`ACC_SERVER_DESCRIPTION` LIKE CONCAT_WS('%', '', PARAM_ACC_SERVER_DESCRIPTION, '')
				) AND
				(
					IS_NULL_ACC_SERVER_LAST_SYNCHRONIZED_FROM = 1 OR
					`account_server`.`SERVER_LAST_SYNCHRONIZED` >= PARAM_ACC_SERVER_LAST_SYNCHRONIZED_FROM
				) AND		
				(
					IS_NULL_ACC_SERVER_LAST_SYNCHRONIZED_TO = 1 OR
					`account_server`.`SERVER_LAST_SYNCHRONIZED` <= PARAM_ACC_SERVER_LAST_SYNCHRONIZED_TO
				) AND	
				(
					IS_NULL_ACC_SERVER_IS_MOTHER = 1 OR
					`account_server`.`ACC_SERVER_IS_MOTHER` = PARAM_ACC_SERVER_IS_MOTHER
				) AND	
				(
					IS_NULL_ACC_SERVER_ADDRESS = 1 OR
					`account_server`.`ACC_SERVER_ADDRESS` LIKE CONCAT_WS('%', '', PARAM_ACC_SERVER_ADDRESS, '')
				) AND			
				(
					IS_NULL_ACC_SERVER_STATUS = 1 OR
					`account_server`.`ACC_SERVER_STATUS` = PARAM_ACC_SERVER_STATUS
				) AND				
				(
					IS_NULL_ACC_SERVER_SYSTEM_GENERATED = 1 OR
					`account_server`.`ACC_SERVER_SYSTEM_GENERATED` = PARAM_ACC_SERVER_SYSTEM_GENERATED
				)
				

			-- ORDER BY
			-- =========================================================================================
			ORDER BY
				-- SERVER
				CASE WHEN PARAM_ORDER_FIELD = 'ACC_SERVER_ID' AND PARAM_ORDER_TYPE = 'ASC' THEN `account_server`.`ACC_SERVER_ID` END ASC, 
				CASE WHEN PARAM_ORDER_FIELD = 'ACC_SERVER_ID' AND PARAM_ORDER_TYPE = 'DESC' THEN `account_server`.`ACC_SERVER_ID` END DESC,

				CASE WHEN PARAM_ORDER_FIELD = 'ACC_SERVER_TITLE' AND PARAM_ORDER_TYPE = 'ASC' THEN `account_server`.`ACC_SERVER_TITLE` END ASC, 
				CASE WHEN PARAM_ORDER_FIELD = 'ACC_SERVER_TITLE' AND PARAM_ORDER_TYPE = 'DESC' THEN `account_server`.`ACC_SERVER_TITLE` END DESC,				
				CASE WHEN PARAM_ORDER_FIELD = 'ACC_SERVER_DESCRIPTION' AND PARAM_ORDER_TYPE = 'ASC' THEN `account_server`.`ACC_SERVER_DESCRIPTION` END ASC, 
				CASE WHEN PARAM_ORDER_FIELD = 'ACC_SERVER_DESCRIPTION' AND PARAM_ORDER_TYPE = 'DESC' THEN `account_server`.`ACC_SERVER_DESCRIPTION` END DESC,
				CASE WHEN PARAM_ORDER_FIELD = 'ACC_SERVER_IS_MOTHER' AND PARAM_ORDER_TYPE = 'ASC' THEN `account_server`.`ACC_SERVER_IS_MOTHER` END ASC, 
				CASE WHEN PARAM_ORDER_FIELD = 'ACC_SERVER_IS_MOTHER' AND PARAM_ORDER_TYPE = 'DESC' THEN `account_server`.`ACC_SERVER_IS_MOTHER` END DESC,
				CASE WHEN PARAM_ORDER_FIELD = 'ACC_SERVER_ADDRESS' AND PARAM_ORDER_TYPE = 'ASC' THEN `account_server`.`ACC_SERVER_ADDRESS` END ASC, 
				CASE WHEN PARAM_ORDER_FIELD = 'ACC_SERVER_ADDRESS' AND PARAM_ORDER_TYPE = 'DESC' THEN `account_server`.`ACC_SERVER_ADDRESS` END DESC,		
				CASE WHEN PARAM_ORDER_FIELD = 'SERVER_LAST_SYNCHRONIZED' AND PARAM_ORDER_TYPE = 'ASC' THEN `account_server`.`SERVER_LAST_SYNCHRONIZED` END ASC, 
				CASE WHEN PARAM_ORDER_FIELD = 'SERVER_LAST_SYNCHRONIZED' AND PARAM_ORDER_TYPE = 'DESC' THEN `account_server`.`SERVER_LAST_SYNCHRONIZED` END DESC,	
				CASE WHEN PARAM_ORDER_FIELD = 'ACC_SERVER_STATUS' AND PARAM_ORDER_TYPE = 'ASC' THEN `account_server`.`ACC_SERVER_STATUS` END ASC, 
				CASE WHEN PARAM_ORDER_FIELD = 'ACC_SERVER_STATUS' AND PARAM_ORDER_TYPE = 'DESC' THEN `account_server`.`ACC_SERVER_STATUS` END DESC,			
				CASE WHEN PARAM_ORDER_FIELD = 'ACC_SERVER_SYSTEM_GENERATED' AND PARAM_ORDER_TYPE = 'ASC' THEN `account_server`.`ACC_SERVER_SYSTEM_GENERATED` END ASC, 
				CASE WHEN PARAM_ORDER_FIELD = 'ACC_SERVER_SYSTEM_GENERATED' AND PARAM_ORDER_TYPE = 'DESC' THEN `account_server`.`ACC_SERVER_SYSTEM_GENERATED` END DESC,			
				
				-- STATUS
				CASE WHEN PARAM_ORDER_FIELD = 'STATUS_DESCRIPTION' AND PARAM_ORDER_TYPE = 'ASC' THEN `system_status`.`STATUS_DESCRIPTION` END ASC, 
				CASE WHEN PARAM_ORDER_FIELD = 'STATUS_DESCRIPTION' AND PARAM_ORDER_TYPE = 'DESC' THEN `system_status`.`STATUS_DESCRIPTION` END DESC,
					
				-- EXTRA								
				CASE WHEN PARAM_ORDER_FIELD <> 'ACC_SERVER_DESCRIPTION' THEN `account_server`.`ACC_SERVER_DESCRIPTION` END ASC
																												
			LIMIT PARAM_SKIP, PARAM_LIMIT;		
			LEAVE SP_GET;
		
		END IF;
	END IF;
END ;;
DELIMITER ;
/*!50003 SET sql_mode              = @saved_sql_mode */ ;
/*!50003 SET character_set_client  = @saved_cs_client */ ;
/*!50003 SET character_set_results = @saved_cs_results */ ;
/*!50003 SET collation_connection  = @saved_col_connection */ ;
/*!50003 DROP PROCEDURE IF EXISTS `ACCOUNT_SERVER_PREPARE` */;
/*!50003 SET @saved_cs_client      = @@character_set_client */ ;
/*!50003 SET @saved_cs_results     = @@character_set_results */ ;
/*!50003 SET @saved_col_connection = @@collation_connection */ ;
/*!50003 SET character_set_client  = latin1 */ ;
/*!50003 SET character_set_results = latin1 */ ;
/*!50003 SET collation_connection  = latin1_swedish_ci */ ;
/*!50003 SET @saved_sql_mode       = @@sql_mode */ ;
/*!50003 SET sql_mode              = '' */ ;
DELIMITER ;;
CREATE DEFINER=`root`@`localhost` PROCEDURE `ACCOUNT_SERVER_PREPARE`(
	IN `PARAM_ACC_SERVER_DESCRIPTION` VARCHAR(500),
	IN `PARAM_ACC_SERVER_UNIQUE_KEY` VARCHAR(500),
	
	IN `PARAM_REQUESTER_USERNAME` VARCHAR(500),
	IN `PARAM_REQUESTER_PASSWORD` VARCHAR(500),
	IN `PARAM_REQUESTER_IP` VARCHAR(1000),
	IN `PARAM_UNIQUE_SESSION_ID` VARCHAR(1000),
	IN `PARAM_SUPPRESS_RETURN` BIT
)
SP_SAVE:
BEGIN


	-- 1) DECLARE LOCAL PARAMETERS
	-- ====================================================================================================================================================================
	DECLARE STATUS_INACTIVE TINYINT DEFAULT 1;
	DECLARE STATUS_ACTIVE TINYINT DEFAULT 2;
	
	-- Audit Handler
	DECLARE TEMP_RECORD_EXISTS BIT DEFAULT 0;
	DECLARE TEMP_MODULE_KEYWORD VARCHAR(500) DEFAULT 'account_server';
	DECLARE TEMP_SP_OBJECTIVE VARCHAR(500) DEFAULT 'add/edit Server details record';
	DECLARE TEMP_ERR_MESSAGE VARCHAR(500) DEFAULT '';
	DECLARE ERR BIGINT DEFAULT 0;
	DECLARE TEMP_RECORD_CHANGES VARCHAR(16000) DEFAULT '';
	DECLARE TEMP_RECORD_BINDED BIT DEFAULT 0;
	
	-- Authentication
	DECLARE TEMP_ACCESS_RIGHTS_DENIED BIT DEFAULT 0;
	DECLARE TEMP_SYNC_SERVER_ID BIGINT DEFAULT 0;
	DECLARE TEMP_SYNC_IS_SERVER_REQUEST BIT DEFAULT 0;
	DECLARE TEMP_AUTHENTICATED_ACCOUNT_ID BIGINT DEFAULT `ACCOUNT_MEMBER@ACC_ACCOUNT_ID_FROM_LOGIN`(PARAM_REQUESTER_USERNAME, PARAM_REQUESTER_PASSWORD);
	DECLARE TEMP_AUTHENTICATED_ACCOUNT_LEVEL BIGINT DEFAULT 0;
	
	-- Local Parameters
	DECLARE TEMP_ACC_SERVER_ID BIGINT DEFAULT 0;
	DECLARE TEMP_ACC_SERVER_SERVER_ID BIGINT DEFAULT 0;
	DECLARE TEMP_NOW DATETIME(6) DEFAULT `SYSTEM_VAR@NOW`('', 1);
	DECLARE TEMP_SERVER_SYNC_RESULT_DATASET VARCHAR(3) DEFAULT `SYSTEM_VAR@TO_ALPHA32`(`SYSTEM_VAR@RANDOM`(0, 32767), '0', 3);
	DECLARE TEMP_UPDATE_RECORD BIT DEFAULT 0;
	
	
	-- 2) Try Catch / Throw
	-- ====================================================================================================================================================================
	DECLARE EXIT HANDLER FOR SQLEXCEPTION
	BEGIN
		RESIGNAL;
	END;
	-- ====================================================================================================================================================================

	
	-- Check if already prepared
	-- ========================================================
	IF `ACCOUNT_SERVER@SELF_EXISTS`() = 1 THEN
		
		-- CHECK SERVER PC DETAILS DIFFERS FROM DATA STORED IN SQL 
		IF
		(
			SELECT COUNT(`account_server`.`ACC_SERVER_ID`)
			FROM `account_server`
			WHERE
				`account_server`.`ACC_SERVER_DESCRIPTION` = PARAM_ACC_SERVER_DESCRIPTION AND
				`account_server`.`ACC_SERVER_ADDRESS` = 'SELF'
			LIMIT 1
		) <= 0
		THEN
			SELECT 
				`account_server`.`ACC_SERVER_ID`
			INTO
				TEMP_ACC_SERVER_ID
			FROM `account_server`
			WHERE
				`account_server`.`ACC_SERVER_DESCRIPTION` = PARAM_ACC_SERVER_DESCRIPTION AND
				`account_server`.`ACC_SERVER_ADDRESS` = 'SELF'
			LIMIT 1;
		
		
			-- UPDATE SELF
			SET TEMP_UPDATE_RECORD = 1;
			
		END IF;
		
		LEAVE SP_SAVE;
	END IF;	
	
	
	-- Load System Account
	-- ========================================================
	SET PARAM_REQUESTER_USERNAME = 'system';
	SET PARAM_REQUESTER_PASSWORD = `ACCOUNT_MEMBER@SYSTEM_PASSWORD`();
	
	
	-- 4) PREPARE AUDIT TRAIL
	-- ====================================================================================================================================================================
	
	SET TEMP_RECORD_CHANGES = 
	`SYSTEM_VAR@CONCAT_ADD`(' | ', TEMP_RECORD_CHANGES, CONCAT_WS(' ', 'ACC_SERVER_DESCRIPTION: "" > "', PARAM_ACC_SERVER_DESCRIPTION, '"'));

	SET TEMP_RECORD_CHANGES = 
	`SYSTEM_VAR@CONCAT_ADD`(' | ', TEMP_RECORD_CHANGES, CONCAT_WS(' ', 'ACC_SERVER_UNIQUE_KEY: "" > "', PARAM_ACC_SERVER_UNIQUE_KEY, '"'));
	
	SET TEMP_RECORD_CHANGES = 
	`SYSTEM_VAR@CONCAT_ADD`(' | ', TEMP_RECORD_CHANGES, CONCAT_WS(' ', 'LAST_SYNCHRONIZED: "" > "', TEMP_NOW, '"'));
		
	SET TEMP_RECORD_CHANGES = 
	`SYSTEM_VAR@CONCAT_ADD`
	(
		' | ', TEMP_RECORD_CHANGES, CONCAT_WS
		(
			' ',
			'STATUS: 0 (" ")',
			' > ', STATUS_ACTIVE, '("', `SYSTEM_STATUS@SYS_STATUS_DESCRIPTION_FROM_ID`(STATUS_ACTIVE), '")'
		)
	);

	
	SET TEMP_RECORD_CHANGES = 
	`SYSTEM_VAR@CONCAT_ADD`(' | ', TEMP_RECORD_CHANGES, CONCAT_WS(' ', 'SYNC_RESULT_DATASET: "" > "', TEMP_SERVER_SYNC_RESULT_DATASET, '"'));

	SET TEMP_RECORD_CHANGES = 
	`SYSTEM_VAR@CONCAT_ADD`(' | ', TEMP_RECORD_CHANGES, CONCAT_WS(' ', 'SYNC_PENDING_MODULE: "" > "0"'));	
	
	SET TEMP_RECORD_CHANGES = 
	`SYSTEM_VAR@CONCAT_ADD`(' | ', TEMP_RECORD_CHANGES, CONCAT_WS(' ', 'SERVER_SYNC_SUCCESS: "" > "', STATUS_INACTIVE, '"'));	
	-- ====================================================================================================================================================================
	
	
	-- 6) INSERT / UPDATE
	-- ====================================================================================================================================================================
	IF TEMP_UPDATE_RECORD = 0 THEN
	
		INSERT INTO
		`account_server`
		(
			`account_server`.`ACC_SERVER_TITLE`,
			`account_server`.`ACC_SERVER_DESCRIPTION`,
			`account_server`.`ACC_SERVER_UNIQUE_KEY`,
			`account_server`.`ACC_SERVER_IS_MOTHER`,
			`account_server`.`ACC_SERVER_ADDRESS`,
			
			`account_server`.`ACC_SERVER_LAST_SYNCHRONIZED`,
			`account_server`.`ACC_SERVER_STATUS`,
			
			`account_server`.`ACC_SERVER_SYNC_RESULT_DATASET`,
			`account_server`.`ACC_SERVER_SYNC_REQUEST_TYPE`,
			`account_server`.`ACC_SERVER_SYNC_SUCCESS`,
			`account_server`.`ACC_SERVER_SYSTEM_GENERATED`
		)
		VALUES
		(
			'NEW Server',
			PARAM_ACC_SERVER_DESCRIPTION,
			PARAM_ACC_SERVER_UNIQUE_KEY,
			STATUS_INACTIVE,
			'SELF',
			
			'1000-01-01 01:00:00.000000',
			STATUS_ACTIVE,
			
			TEMP_ACC_SERVER_SYNC_RESULT_DATASET,
			0,
			0,
			STATUS_ACTIVE
		);
		
		SET TEMP_ACC_SERVER_ID = LAST_INSERT_ID();
		
	
	ELSE
		UPDATE `account_server`
		SET
			`account_server`.`ACC_SERVER_DESCRIPTION` = PARAM_ACC_SERVER_DESCRIPTION,
			`account_server`.`ACC_SERVER_UNIQUE_KEY` = PARAM_ACC_SERVER_UNIQUE_KEY,
			`account_server`.`ACC_SERVER_IS_MOTHER` = STATUS_INACTIVE,
			`account_server`.`ACC_SERVER_ADDRESS` = 'SELF',
			
			`account_server`.`ACC_SERVER_LAST_SYNCHRONIZED` = '1000-01-01 01:00:00.000000',
			`account_server`.`ACC_SERVER_STATUS` = STATUS_ACTIVE,
			
			`account_server`.`ACC_SERVER_SYNC_RESULT_DATASET` = TEMP_ACC_SERVER_SYNC_RESULT_DATASET,
			`account_server`.`ACC_SERVER_SYSTEM_GENERATED`	= STATUS_ACTIVE
			
		WHERE
			`account_server`.`ACC_SERVER_ID` = TEMP_ACC_SERVER_ID;	
	
	END IF;
	SET TEMP_ACC_SERVER_SERVER_ID = 0;
	-- ====================================================================================================================================================================
	
	
	-- 7) AUDIT TRAIL
	-- ====================================================================================================================================================================
	CALL `ACCOUNT_AUDIT_TRAIL_SAVE`
	(
		0, TEMP_MODULE_KEYWORD, TEMP_ACC_SERVER_ID, TEMP_ACC_SERVER_SERVER_ID, 'SAVE', TEMP_SP_OBJECTIVE, TEMP_RECORD_CHANGES, 
		PARAM_REQUESTER_USERNAME, PARAM_REQUESTER_PASSWORD, PARAM_REQUESTER_IP, PARAM_UNIQUE_SESSION_ID,
		0, PARAM_SUPPRESS_RETURN
	);
	-- ====================================================================================================================================================================
	

END ;;
DELIMITER ;
/*!50003 SET sql_mode              = @saved_sql_mode */ ;
/*!50003 SET character_set_client  = @saved_cs_client */ ;
/*!50003 SET character_set_results = @saved_cs_results */ ;
/*!50003 SET collation_connection  = @saved_col_connection */ ;
/*!50003 DROP PROCEDURE IF EXISTS `ACCOUNT_SERVER_SAVE` */;
/*!50003 SET @saved_cs_client      = @@character_set_client */ ;
/*!50003 SET @saved_cs_results     = @@character_set_results */ ;
/*!50003 SET @saved_col_connection = @@collation_connection */ ;
/*!50003 SET character_set_client  = latin1 */ ;
/*!50003 SET character_set_results = latin1 */ ;
/*!50003 SET collation_connection  = latin1_swedish_ci */ ;
/*!50003 SET @saved_sql_mode       = @@sql_mode */ ;
/*!50003 SET sql_mode              = '' */ ;
DELIMITER ;;
CREATE DEFINER=`root`@`localhost` PROCEDURE `ACCOUNT_SERVER_SAVE`(
	IN `PARAM_ACC_SERVER_ID` BIGINT,
	
	IN `PARAM_ACC_SERVER_TITLE` VARCHAR(500),
	IN `PARAM_ACC_SERVER_DESCRIPTION` VARCHAR(500),
	IN `PARAM_ACC_SERVER_UNIQUE_KEY` VARCHAR(500),
	IN `PARAM_ACC_SERVER_IS_MOTHER` TINYINT,
	IN `PARAM_ACC_SERVER_ADDRESS` VARCHAR(500),
	
	IN `PARAM_ACC_SERVER_LAST_SYNCHRONIZED` DATETIME(6),
	IN `PARAM_ACC_SERVER_STATUS` TINYINT,
	
	IN `PARAM_ACC_SERVER_SYNC_RESULT_DATASET` MEDIUMTEXT,

	IN `PARAM_REQUESTER_USERNAME` VARCHAR(500),
	IN `PARAM_REQUESTER_PASSWORD` VARCHAR(500),
	IN `PARAM_REQUESTER_IP` VARCHAR(1000),
	IN `PARAM_UNIQUE_SESSION_ID` VARCHAR(1000),
	IN `PARAM_SUPPRESS_RETURN` BIT,
	
	IN `PARAM_SYNC_SERVER_DESCRIPTION` VARCHAR(500), 
	IN `PARAM_SYNC_SERVER_UNIQUE_KEY` VARCHAR(500)
)
SP_SAVE:
BEGIN
	-- NOTE: User interaction should be limited to STATUS only.
	-- OTHERWISE, it should be automatically managed with SYNCHRONIZE requests.
	
	-- EXCEPTION: Workstation number of self

	-- 1) DECLARE LOCAL PARAMETERS
	-- ====================================================================================================================================================================
	DECLARE STATUS_INACTIVE TINYINT DEFAULT 1;
	DECLARE STATUS_ACTIVE TINYINT DEFAULT 2;
	DECLARE STATUS_CLOSED TINYINT DEFAULT 3;

	-- Audit Handler
	DECLARE TEMP_RECORD_EXISTS BIT DEFAULT `ACCOUNT_SERVER@ACC_SERVER_ID_EXISTS`(PARAM_ACC_SERVER_ID, 0);
	DECLARE TEMP_MODULE_KEYWORD VARCHAR(500) DEFAULT 'account_server';
	DECLARE TEMP_SP_OBJECTIVE VARCHAR(500) DEFAULT 'retrieve child server record';
	DECLARE TEMP_ERR_MESSAGE VARCHAR(500) DEFAULT '';
	DECLARE ERR BIGINT DEFAULT 0;
	DECLARE TEMP_RECORD_CHANGES VARCHAR(16000) DEFAULT '';
	DECLARE TEMP_RECORD_BINDED BIT DEFAULT 0;
	
	-- Authentication
	DECLARE TEMP_ACCESS_RIGHTS_DENIED BIT DEFAULT 0;
	DECLARE TEMP_SYNC_SERVER_ID BIGINT DEFAULT 0;
	DECLARE TEMP_SYNC_IS_SERVER_REQUEST BIT DEFAULT 0;
	DECLARE TEMP_AUTHENTICATED_ACCOUNT_ID BIGINT DEFAULT `ACCOUNT_MEMBER@ACC_ACCOUNT_ID_FROM_LOGIN`(PARAM_REQUESTER_USERNAME, PARAM_REQUESTER_PASSWORD);
	DECLARE TEMP_AUTHENTICATED_ACCOUNT_LEVEL BIGINT DEFAULT 0;

	-- Local value holder
	DECLARE TEMP_SERVER_SELF_ID BIGINT DEFAULT `ACCOUNT_SERVER@SELF_ID`();
	
	DECLARE TEMP_SERVER_ID BIGINT DEFAULT 0;
	DECLARE TEMP_SERVER_SERVER_ID BIGINT DEFAULT 0;
	
	DECLARE TEMP_SERVER_TITLE VARCHAR(500) DEFAULT '';
	DECLARE TEMP_SERVER_DESCRIPTION VARCHAR(500) DEFAULT '';
	DECLARE TEMP_SERVER_UNIQUE_KEY VARCHAR(500) DEFAULT '';
	DECLARE TEMP_SERVER_IS_MOTHER TINYINT DEFAULT 0;
	DECLARE TEMP_SERVER_ADDRESS VARCHAR(500) DEFAULT '';
	DECLARE TEMP_SERVER_LAST_SYNCHRONIZED DATETIME(6) DEFAULT '1000-01-01 00:00:00.000000';
	DECLARE TEMP_SERVER_STATUS TINYINT DEFAULT 0;
		
	DECLARE TEMP_SERVER_SYNC_RESULT_DATASET MEDIUMTEXT DEFAULT '';
	DECLARE TEMP_SYSTEM_GENERATED TINYINT DEFAULT 0;
	
	-- ====================================================================================================================================================================

	
	-- 2) Try Catch / Throw
	-- ====================================================================================================================================================================
	DECLARE EXIT HANDLER FOR SQLEXCEPTION
	BEGIN
		RESIGNAL;
	END;
	-- ====================================================================================================================================================================

	
	-- 3) Prepare SYNC
	-- ====================================================================================================================================================================

	-- IS SERVE REQUEST
	IF
		`SYSTEM_VAR@IS_NULL@NVARCHAR`(PARAM_SYNC_SERVER_DESCRIPTION, 1) = 0 AND
		`SYSTEM_VAR@IS_NULL@NVARCHAR`(PARAM_SYNC_SERVER_UNIQUE_KEY, 1) = 0
	THEN
	
		-- .....................................................
		
		-- SET REQUEST CAME FROM SYNC 
		SET TEMP_SYNC_IS_SERVER_REQUEST = 1;
		
		-- USE SYSTEM ACCOUNT (IF SERVER HAS PERMISSION)
		IF `ACCOUNT_SERVER@HAS_PERMISSION`(PARAM_SYNC_SERVER_DESCRIPTION, PARAM_SYNC_SERVER_UNIQUE_KEY) = 1 THEN
			SELECT
				`account_member`.`ACC_ACCOUNT_USERNAME`,
				`account_member`.`ACC_ACCOUNT_PASSWORD`
			INTO
				PARAM_REQUESTER_USERNAME,
				PARAM_REQUESTER_PASSWORD
			FROM `account_member`
			WHERE
				`account_member`.`ACC_ACCOUNT_USERNAME` = 'system'
			LIMIT 1;
		ELSE
			SET PARAM_REQUESTER_USERNAME = '';
			SET PARAM_REQUESTER_PASSWORD = '';
		END IF;
		
		-- GET SERVER ID
		SET TEMP_SYNC_SERVER_ID = `ACCOUNT_SERVER@ACC_SERVER_ID_FROM_LOGIN`(PARAM_SYNC_SERVER_DESCRIPTION, PARAM_SYNC_SERVER_UNIQUE_KEY);
											
		-- .....................................................
		
		-- GET LOCAL ID
		-- ...........................................
		SET PARAM_ACC_SERVER_ID = `ACCOUNT_SERVER@ACC_SERVER_ID_FROM_SERVER_ID`
								(
									PARAM_ACC_SERVER_ID,
									PARAM_ACC_SERVER_SERVER_ID,

									PARAM_ACC_SERVER_DESCRIPTION
								);
	END IF;
	
	
	
	-- IS RECORD EXISTS					
	SET TEMP_RECORD_EXISTS = `ACCOUNT_SERVER@ACC_SERVER_ID_EXISTS`(PARAM_ACC_SERVER_ID, 0);

	-- ====================================================================================================================================================================
		
		
	-- 3) IF ALREADY EXIST, FILL MISSING DATA
	-- ====================================================================================================================================================================
	IF TEMP_RECORD_EXISTS = 1 THEN
		SELECT
			`account_server`.`ACC_SERVER_SERVER_ID`,
			
			`account_server`.`ACC_SERVER_TITLE`,
			`account_server`.`ACC_SERVER_DESCRIPTION`,
			`account_server`.`ACC_SERVER_UNIQUE_KEY`,
			`account_server`.`ACC_SERVER_IS_MOTHER`,
			`account_server`.`ACC_SERVER_ADDRESS`,
			`account_server`.`ACC_SERVER_LAST_SYNCHRONIZED`,
			`account_server`.`ACC_SERVER_STATUS`,
			
			`account_server`.`ACC_SERVER_SYNC_RESULT_DATASET`,	
			`account_server`.`ACC_SERVER_SYSTEM_GENERATED`
			
		INTO
			TEMP_SERVER_SERVER_ID,
			
			TEMP_SERVER_TITLE,
			TEMP_SERVER_DESCRIPTION,
			TEMP_SERVER_UNIQUE_KEY,
			TEMP_SERVER_IS_MOTHER,
			TEMP_SERVER_ADDRESS,
			TEMP_SERVER_LAST_SYNCHRONIZED,
			TEMP_SERVER_STATUS,
			
			TEMP_SERVER_SYNC_RESULT_DATASET,
			TEMP_SYSTEM_GENERATED
			
		FROM `account_server`
		WHERE
			`account_server`.`ACC_SERVER_ID` = PARAM_ACC_SERVER_ID
		LIMIT 1;
		
		SET PARAM_ACC_SERVER_TITLE = `SYSTEM_VAR@REPLACE_NULL@NVARCHAR`(PARAM_ACC_SERVER_TITLE, TEMP_SERVER_TITLE, 1);
		SET PARAM_ACC_SERVER_DESCRIPTION = `SYSTEM_VAR@REPLACE_NULL@NVARCHAR`(PARAM_ACC_SERVER_DESCRIPTION, TEMP_SERVER_DESCRIPTION, 1);
		SET PARAM_ACC_SERVER_UNIQUE_KEY = `SYSTEM_VAR@REPLACE_NULL@NVARCHAR`(PARAM_ACC_SERVER_UNIQUE_KEY, TEMP_SERVER_UNIQUE_KEY, 1);
		
		SET PARAM_ACC_SERVER_IS_MOTHER = `SYSTEM_VAR@REPLACE_NULL@TINYINT`(PARAM_ACC_SERVER_IS_MOTHER, TEMP_SERVER_IS_MOTHER, 1);
		SET PARAM_ACC_SERVER_ADDRESS = `SYSTEM_VAR@REPLACE_NULL@NVARCHAR`(PARAM_ACC_SERVER_ADDRESS, TEMP_SERVER_ADDRESS, 1);
		SET PARAM_ACC_SERVER_LAST_SYNCHRONIZED = `SYSTEM_VAR@REPLACE_NULL@DATETIME`(PARAM_ACC_SERVER_LAST_SYNCHRONIZED, TEMP_SERVER_LAST_SYNCHRONIZED, 1);
		SET PARAM_ACC_SERVER_STATUS = `SYSTEM_VAR@REPLACE_NULL@TINYINT`(PARAM_ACC_SERVER_STATUS, TEMP_SERVER_STATUS, 1);
		
		SET PARAM_ACC_SERVER_SYNC_RESULT_DATASET = `SYSTEM_VAR@REPLACE_NULL@MEDIUMTEXT`(PARAM_ACC_SERVER_SYNC_RESULT_DATASET, TEMP_SERVER_SYNC_RESULT_DATASET, 0);
		
	ELSE
		SET PARAM_ACC_SERVER_SYNC_RESULT_DATASET = `SYSTEM_VAR@REPLACE_NULL@MEDIUMTEXT`(PARAM_ACC_SERVER_SYNC_RESULT_DATASET, '', 1);		
	
	END IF;
	-- ====================================================================================================================================================================

	
	-- 4) PREPARE AUDIT TRAIL
	-- ====================================================================================================================================================================
	IF BINARY TEMP_SERVER_TITLE <> PARAM_ACC_SERVER_TITLE THEN
		SET TEMP_RECORD_CHANGES = 
		`SYSTEM_VAR@CONCAT_ADD`(' | ', TEMP_RECORD_CHANGES, CONCAT_WS(' ', 'TITLE:"', TEMP_SERVER_TITLE, '" > "', PARAM_ACC_SERVER_TITLE, '"'));
	END IF;
	
	IF BINARY TEMP_SERVER_DESCRIPTION <> PARAM_ACC_SERVER_DESCRIPTION THEN
		SET TEMP_RECORD_CHANGES = 
		`SYSTEM_VAR@CONCAT_ADD`(' | ', TEMP_RECORD_CHANGES, CONCAT_WS(' ', 'DESCRIPTION:"', TEMP_SERVER_DESCRIPTION, '" > "', PARAM_ACC_SERVER_DESCRIPTION, '"'));
	END IF;

	IF BINARY TEMP_SERVER_UNIQUE_KEY <> PARAM_ACC_SERVER_UNIQUE_KEY THEN
		SET TEMP_RECORD_CHANGES = 
		`SYSTEM_VAR@CONCAT_ADD`(' | ', TEMP_RECORD_CHANGES, CONCAT_WS(' ', 'UNIQUE KEY:"', TEMP_SERVER_UNIQUE_KEY, '" > "', PARAM_ACC_SERVER_UNIQUE_KEY, '"'));
	END IF;
	
	IF TEMP_SERVER_IS_MOTHER <> PARAM_ACC_SERVER_IS_MOTHER THEN
		SET TEMP_RECORD_CHANGES = 
		`SYSTEM_VAR@CONCAT_ADD`
		(
			' | ', TEMP_RECORD_CHANGES, CONCAT_WS
			(
				' ',
				'IS MOTHER SERVER: ', TEMP_SERVER_IS_MOTHER, '("', `SYSTEM_STATUS@SYS_STATUS_DESCRIPTION_FROM_ID`(TEMP_SERVER_IS_MOTHER), '")',
				' > ', PARAM_ACC_SERVER_IS_MOTHER, '("', `SYSTEM_STATUS@SYS_STATUS_DESCRIPTION_FROM_ID`(PARAM_ACC_SERVER_IS_MOTHER), '")'
			)
		);
	END IF;
	
	IF BINARY TEMP_SERVER_ADDRESS <> PARAM_ACC_SERVER_ADDRESS THEN
		SET TEMP_RECORD_CHANGES = 
		`SYSTEM_VAR@CONCAT_ADD`(' | ', TEMP_RECORD_CHANGES, CONCAT_WS(' ', 'SERVER ADDRESS:"', TEMP_SERVER_ADDRESS, '" > "', PARAM_ACC_SERVER_ADDRESS, '"'));
	END IF;
	
	IF TEMP_SERVER_LAST_SYNCHRONIZED <> PARAM_ACC_SERVER_LAST_SYNCHRONIZED THEN
		SET TEMP_RECORD_CHANGES = 
		`SYSTEM_VAR@CONCAT_ADD`(' | ', TEMP_RECORD_CHANGES, CONCAT_WS(' ', 'SYNCHRONIZED DATE:"', TEMP_SERVER_LAST_SYNCHRONIZED, '" > "', PARAM_ACC_SERVER_LAST_SYNCHRONIZED, '"'));
	END IF;
	
	IF TEMP_SERVER_STATUS <> PARAM_ACC_SERVER_STATUS THEN
		SET TEMP_RECORD_CHANGES = 
		`SYSTEM_VAR@CONCAT_ADD`
		(
			' | ', TEMP_RECORD_CHANGES, CONCAT_WS
			(
				' ',
				'STATUS: ', TEMP_SERVER_STATUS, '("', `SYSTEM_STATUS@SYS_STATUS_DESCRIPTION_FROM_ID`(TEMP_SERVER_STATUS), '")',
				' > ', PARAM_ACC_SERVER_STATUS, '("', `SYSTEM_STATUS@SYS_STATUS_DESCRIPTION_FROM_ID`(PARAM_ACC_SERVER_STATUS), '")'
			)
		);
	END IF;
	
	IF BINARY TEMP_SERVER_SYNC_RESULT_DATASET <> PARAM_ACC_SERVER_SYNC_RESULT_DATASET THEN
		SET TEMP_RECORD_CHANGES = 
		`SYSTEM_VAR@CONCAT_ADD`(' | ', TEMP_RECORD_CHANGES, CONCAT_WS(' ', 'SYNC_RESULT_DATASET: "..." > "..."'));
	END IF;
	
	-- No Changes in data, reject request
	IF CHAR_LENGTH(TEMP_RECORD_CHANGES) = 0 THEN
		IF PARAM_SUPPRESS_RETURN = 0 THEN
			SELECT PARAM_ACC_SERVER_ID AS INSERTED_ID;
		END IF;	
		LEAVE SP_SAVE;
	END IF;
	-- ====================================================================================================================================================================

	
	-- 5) VALIDATE
	-- ====================================================================================================================================================================	
	-- Access Rights
	IF 
		-- [ADD] Rights
		(
			TEMP_RECORD_EXISTS = 0 AND
			`ACCOUNT_ACCESS_RIGHTS@HAS_PERMISSION`(PARAM_REQUESTER_USERNAME, PARAM_REQUESTER_PASSWORD, 0, TEMP_MODULE_KEYWORD, 2) = 0 AND
			(
				`SYSTEM_VAR@IS_NULL@BIGINT`(PARAM_ACC_SERVER_ID, 1, 1) = 0 OR
				PARAM_ACC_SERVER_ADDRESS <> 'CLIENT' OR
				PARAM_ACC_SERVER_STATUS <> STATUS_CLOSED
			)
		) OR
		-- [EDIT] Rights
		(
			TEMP_RECORD_EXISTS = 1 AND
			`ACCOUNT_ACCESS_RIGHTS@HAS_PERMISSION`(PARAM_REQUESTER_USERNAME, PARAM_REQUESTER_PASSWORD, 0, TEMP_MODULE_KEYWORD, 3) = 0 
		)
	THEN
		SET TEMP_ACCESS_RIGHTS_DENIED = 1;
		CALL `ACCOUNT_ACCESS_RIGHTS_DENY`
		(
			0, TEMP_MODULE_KEYWORD, PARAM_ACC_SERVER_ID, TEMP_SERVER_SERVER_ID, TEMP_SP_OBJECTIVE, 'NONE', 
			PARAM_REQUESTER_USERNAME, PARAM_REQUESTER_PASSWORD, PARAM_REQUESTER_IP, PARAM_UNIQUE_SESSION_ID,
			TEMP_SYNC_SERVER_ID, PARAM_SUPPRESS_RETURN
		);
	END IF;
		
	-- SYSTEM_GENERATED
	IF 
		TEMP_SYSTEM_GENERATED = 2 AND
		(
			TEMP_SERVER_SELF_ID <> TEMP_SERVER_SELF_ID OR
			
			TEMP_SERVER_DESCRIPTION <> PARAM_ACC_SERVER_DESCRIPTION OR
			TEMP_SERVER_ADDRESS <> PARAM_ACC_SERVER_ADDRESS OR
			TEMP_SERVER_LAST_SYNCHRONIZED <> PARAM_ACC_SERVER_LAST_SYNCHRONIZED OR
			TEMP_SERVER_STATUS <> PARAM_ACC_SERVER_STATUS 
		)
	THEN
		CALL `VALIDATION_SYSTEM_GENERATED`(PARAM_ACC_SERVER_ID, 'SELECTED SERVER', 'SERVER_SYNC_RESULT_DATASET');
	END IF;
	
	-- Status Validation
	IF `SYSTEM_STATUS@SYS_STATUS_ID_EXISTS`(PARAM_ACC_SERVER_STATUS, 1) = 0 THEN
		SET TEMP_ERR_MESSAGE = CONCAT_WS(' ', 'Given STATUS does not exists or is inactive. ID: ', PARAM_ACC_SERVER_STATUS);
		SET ERR = `RAISERROR`(TEMP_ERR_MESSAGE);
	END IF;
		
	-- Missing Fields
	IF `SYSTEM_VAR@IS_NULL@NVARCHAR`(PARAM_ACC_SERVER_DESCRIPTION, 1) = 1 THEN
		CALL `VALIDATION_MISSING_FIELD`('`SERVER_DESCRIPTION`', '`NULL`');
	END IF;
	
	-- (Should not accept UNIQUE KEY requests from user, but it should came from server sync request)
	IF `SYSTEM_VAR@IS_NULL@NVARCHAR`(PARAM_ACC_SERVER_UNIQUE_KEY, 1) = 1 THEN
		CALL `VALIDATION_MISSING_FIELD`('`SERVER_UNIQUE_KEY`', '`NULL`');
	END IF;
	
	-- If mother requires legit ADDRESS
	IF 
		PARAM_ACC_SERVER_IS_MOTHER = STATUS_ACTIVE AND
		TEMP_SERVER_ADDRESS <> PARAM_ACC_SERVER_ADDRESS
	THEN
		CALL `VALIDATION_MISSING_FIELD`('`SERVER_ADDRESS`', '`NULL`');
	END IF;
	
	-- Last synchronized, should not older than one stored in database.
	IF TEMP_SERVER_LAST_SYNCHRONIZED > PARAM_ACC_SERVER_LAST_SYNCHRONIZED THEN
		SET TEMP_ERR_MESSAGE = CONCAT_WS(' ', 'Given LAST_SYNCHRONIZED is invalid. ID: ', PARAM_ACC_SERVER_LAST_SYNCHRONIZED);
		SET ERR = `RAISERROR`(TEMP_ERR_MESSAGE);
	END IF;
	
	-- Uneditables
	IF TEMP_RECORD_EXISTS = 1 THEN
		-- Unique Key
		IF TEMP_SERVER_UNIQUE_KEY <> PARAM_ACC_SERVER_UNIQUE_KEY THEN
			SET ERR = `RAISERROR`('UNIQUE KEY value is not editable.');
		END IF;
	
		-- Cannot edit IS MOTHER value
		IF TEMP_SERVER_IS_MOTHER <> PARAM_ACC_SERVER_IS_MOTHER THEN
			SET ERR= `RAISERROR`('IS_MOTHER value is not editable.');
		END IF;
	END IF;
	
	-- Use existing mother info ID (if not ignore)
	IF 
		PARAM_ACC_SERVER_IS_MOTHER = STATUS_ACTIVE AND
		(
			SELECT
				COUNT(`account_server`.`ACC_SERVER_ID`)
			FROM `account_server`
			WHERE
				`account_server`.`ACC_SERVER_ID` <> PARAM_ACC_SERVER_ID AND
				`account_server`.`ACC_SERVER_IS_MOTHER` = STATUS_ACTIVE
			LIMIT 1
		) >= 1
	THEN
		SET ERR= RAISERROR('Cannot create more than one mother server.');
	END IF;

	-- Redundant Entry
	IF
	(
		SELECT
			COUNT(`account_server`.`ACC_SERVER_ID`)
		FROM `account_server`
		WHERE
			`account_server`.`ACC_SERVER_ID` <> PARAM_ACC_SERVER_ID AND
			`account_server`.`ACC_SERVER_DESCRIPTION` = PARAM_ACC_SERVER_DESCRIPTION
		LIMIT 1
	) >= 1
	THEN
		CALL `VALIDATION_REDUNDANT_ENTRY`(PARAM_ACC_SERVER_DESCRIPTION);
	END IF;
	-- ====================================================================================================================================================================


	
	-- 6) INSERT / UPDATE
	-- ====================================================================================================================================================================
	
	-- INSERT NEW DATA
	IF TEMP_RECORD_EXISTS = 0 THEN
	
		INSERT INTO
		`account_server`
		(
			`account_server`.`ACC_SERVER_TITLE`,
			`account_server`.`ACC_SERVER_DESCRIPTION`,
			`account_server`.`ACC_SERVER_UNIQUE_KEY`,
			`account_server`.`ACC_SERVER_IS_MOTHER`,
			`account_server`.`ACC_SERVER_ADDRESS`,
			`account_server`.`ACC_SERVER_LAST_SYNCHRONIZED`,
			`account_server`.`ACC_SERVER_STATUS`,
			
			`account_server`.`ACC_SERVER_SYNC_RESULT_DATASET`,	
			`account_server`.`ACC_SERVER_SYSTEM_GENERATED`
		)
		VALUES
		(
			PARAM_ACC_SERVER_TITLE,
			PARAM_ACC_SERVER_DESCRIPTION,
			PARAM_ACC_SERVER_UNIQUE_KEY,
			PARAM_ACC_SERVER_IS_MOTHER,
			PARAM_ACC_SERVER_ADDRESS,
			PARAM_ACC_SERVER_LAST_SYNCHRONIZED,
			PARAM_ACC_SERVER_STATUS,
			
			PARAM_ACC_SERVER_SYNC_RESULT_DATASET,
			STATUS_INACTIVE
		);

		-- Update Audit trail with new ID
		SET PARAM_ACC_SERVER_ID = LAST_INSERT_ID();
		
	-- ========================================================================


	-- UPDATING EXISTING RECORD
	-- ========================================================================
	ELSE
		UPDATE `account_server`
		SET
			`account_server`.`ACC_SERVER_TITLE` = PARAM_ACC_SERVER_TITLE,
			`account_server`.`ACC_SERVER_DESCRIPTION` = PARAM_ACC_SERVER_DESCRIPTION,
			`account_server`.`ACC_SERVER_ADDRESS` = PARAM_ACC_SERVER_ADDRESS,
			`account_server`.`ACC_SERVER_LAST_SYNCHRONIZED` = PARAM_ACC_SERVER_LAST_SYNCHRONIZED,
			`account_server`.`ACC_SERVER_STATUS` = PARAM_ACC_SERVER_STATUS,
			
			`account_server`.`ACC_SERVER_SYNC_RESULT_DATASET` = PARAM_ACC_SERVER_SYNC_RESULT_DATASET
			
		WHERE
			`account_server`.`ACC_SERVER_ID` = PARAM_ACC_SERVER_ID;
			
	END IF;
	-- ====================================================================================================================================================================
	
		
	-- 7) AUDIT TRAIL
	-- ====================================================================================================================================================================
	CALL `ACCOUNT_AUDIT_TRAIL_SAVE`
	(
		0, TEMP_MODULE_KEYWORD, PARAM_ACC_SERVER_ID, TEMP_SERVER_SERVER_ID, 'SAVE', TEMP_SP_OBJECTIVE, TEMP_RECORD_CHANGES, 
		PARAM_REQUESTER_USERNAME, PARAM_REQUESTER_PASSWORD, PARAM_REQUESTER_IP, PARAM_UNIQUE_SESSION_ID,
		TEMP_SYNC_SERVER_ID, PARAM_SUPPRESS_RETURN
	);
	-- ====================================================================================================================================================================
	
	
	-- 8) RETURN RESULT
	-- ====================================================================================================================================================================
	IF PARAM_SUPPRESS_RETURN = 0 THEN
		SELECT PARAM_ACC_SERVER_ID AS INSERTED_ID;
	END IF;	
	LEAVE SP_SAVE;
	-- ====================================================================================================================================================================

END ;;
DELIMITER ;
/*!50003 SET sql_mode              = @saved_sql_mode */ ;
/*!50003 SET character_set_client  = @saved_cs_client */ ;
/*!50003 SET character_set_results = @saved_cs_results */ ;
/*!50003 SET collation_connection  = @saved_col_connection */ ;
/*!50003 DROP PROCEDURE IF EXISTS `ACCOUNT_SERVER_SYNC_DELETE` */;
/*!50003 SET @saved_cs_client      = @@character_set_client */ ;
/*!50003 SET @saved_cs_results     = @@character_set_results */ ;
/*!50003 SET @saved_col_connection = @@collation_connection */ ;
/*!50003 SET character_set_client  = latin1 */ ;
/*!50003 SET character_set_results = latin1 */ ;
/*!50003 SET collation_connection  = latin1_swedish_ci */ ;
/*!50003 SET @saved_sql_mode       = @@sql_mode */ ;
/*!50003 SET sql_mode              = '' */ ;
DELIMITER ;;
CREATE DEFINER=`root`@`localhost` PROCEDURE `ACCOUNT_SERVER_SYNC_DELETE`(
	IN `PARAM_SERVER_ID` BIGINT,
	IN `PARAM_TRAIL_METHOD_ID` BIGINT,
	IN `PARAM_TRAIL_TIMESTAMP_FROM` DATETIME(6),
	IN `PARAM_TRAIL_TIMESTAMP_TO` DATETIME(6),
	
	IN `PARAM_MODULE_KEYWORD` VARCHAR(500),
	IN `PARAM_TRAIL_IS_CLIENT_TO_SERVER` BIT,
		
	IN `PARAM_ORDER_FIELD` VARCHAR(500),
	IN `PARAM_ORDER_TYPE` VARCHAR(500),
	IN `PARAM_SKIP` BIGINT,
	IN `PARAM_LIMIT` BIGINT,

	IN `PARAM_REQUESTER_USERNAME` VARCHAR(500),
	IN `PARAM_REQUESTER_PASSWORD` VARCHAR(500),
	IN `PARAM_REQUESTER_IP` VARCHAR(1000),
	IN `PARAM_UNIQUE_SESSION_ID` VARCHAR(1000),
	IN `PARAM_SUPPRESS_RETURN` BIT,
	
	IN `PARAM_SYNC_SERVER_DESCRIPTION` VARCHAR(500), 
	IN `PARAM_SYNC_SERVER_UNIQUE_KEY` VARCHAR(500)
)
SP_GET:
BEGIN
/*
	-- 1) DECLARE LOCAL PARAMETERS
	-- ====================================================================================================================================================================
	DECLARE STATUS_INACTIVE TINYINT DEFAULT 1;
	DECLARE STATUS_ACTIVE TINYINT DEFAULT 2;
	
	-- Audit Handler
	DECLARE TEMP_RECORD_EXISTS BIT DEFAULT 0;
	DECLARE TEMP_MODULE_KEYWORD VARCHAR(500) DEFAULT PARAM_MODULE_KEYWORD;
	DECLARE TEMP_SP_OBJECTIVE VARCHAR(500) DEFAULT CONCAT_WS(' ', 'synchronizing data;', PARAM_MODULE_KEYWORD);
	DECLARE TEMP_ERR_MESSAGE VARCHAR(500) DEFAULT '';
	DECLARE ERR BIGINT DEFAULT 0;
	DECLARE TEMP_RECORD_CHANGES VARCHAR(16000) DEFAULT '';
	DECLARE TEMP_RECORD_BINDED BIT DEFAULT 0;
	
	-- Authentication
	DECLARE TEMP_ACCESS_RIGHTS_DENIED BIT DEFAULT 0;
	DECLARE TEMP_SYNC_SERVER_ID BIGINT DEFAULT 0;
	DECLARE TEMP_SYNC_IS_SERVER_REQUEST BIT DEFAULT 0;
	DECLARE TEMP_AUTHENTICATED_ACCOUNT_ID BIGINT DEFAULT `ACCOUNT_MEMBER@ACCOUNT_ID_FROM_LOGIN`(PARAM_REQUESTER_USERNAME, PARAM_REQUESTER_PASSWORD);
	DECLARE TEMP_AUTHENTICATED_ACCOUNT_LEVEL BIGINT DEFAULT 0;
	
	-- Local Parameters
	DECLARE TEMP_MODULE_ID BIGINT DEFAULT `SYSTEM_MODULE@MODULE_ID_FROM_KEYWORD`(PARAM_MODULE_KEYWORD);
	-- ====================================================================================================================================================================	

	
	-- 2) Try Catch / Throw
	-- ====================================================================================================================================================================
	DECLARE EXIT HANDLER FOR SQLEXCEPTION
	BEGIN
		RESIGNAL;
	END;
	-- ====================================================================================================================================================================	
	
	
	-- 3) Prepare SYNC
	-- ====================================================================================================================================================================

	-- IS SERVE REQUEST
	IF
		`SYSTEM_VAR@IS_NULL@NVARCHAR`(PARAM_SYNC_SERVER_DESCRIPTION, 1) = 0 AND
		`SYSTEM_VAR@IS_NULL@NVARCHAR`(PARAM_SYNC_SERVER_UNIQUE_KEY, 1) = 0
	THEN
	
		-- SET REQUEST CAME FROM SYNC 
		SET TEMP_SYNC_IS_SERVER_REQUEST = 1;
		
		-- GET SERVER ID
		SET TEMP_SYNC_SERVER_ID = `ACCOUNT_SERVER@SERVER_ID_FROM_LOGIN`(PARAM_SYNC_SERVER_DESCRIPTION, PARAM_SYNC_SERVER_UNIQUE_KEY);
			
	END IF;

	-- ====================================================================================================================================================================
		

	-- 4) VALIDATE
	-- ====================================================================================================================================================================	
	IF 
		`ACCOUNT_SERVER@HAS_PERMISSION`(PARAM_SYNC_SERVER_DESCRIPTION, PARAM_SYNC_SERVER_UNIQUE_KEY) = 0 AND
		`ACCOUNT_ACCESS_RIGHTS@HAS_PERMISSION`(PARAM_REQUESTER_USERNAME, PARAM_REQUESTER_PASSWORD, 0, TEMP_MODULE_KEYWORD, 2) = 0 
	THEN
		CALL `ACCOUNT_ACCESS_RIGHTS_DENY`
		(
			0, TEMP_MODULE_KEYWORD, 0, 0, TEMP_SP_OBJECTIVE, '',
			PARAM_REQUESTER_USERNAME, PARAM_REQUESTER_PASSWORD, PARAM_REQUESTER_IP, PARAM_UNIQUE_SESSION_ID,
			TEMP_SYNC_SERVER_ID, PARAM_SUPPRESS_RETURN
		);
	END IF;
	
	IF `SYSTEM_MODULE@MODULE_ID_EXISTS`(TEMP_MODULE_ID, 1) = 0 THEN
		SET TEMP_ERR_MESSAGE = CONCAT_WS(' ', 'Given Module does not exists or is inactive. ID: ', TEMP_MODULE_ID, PARAM_MODULE_KEYWORD);
		SET ERR = `RAISERROR`(TEMP_ERR_MESSAGE);
	END IF;
	-- ====================================================================================================================================================================	
	
	
	-- 5) SELECT ITEMS
	-- ====================================================================================================================================================================	
	SELECT
		`account_audit_trail`.`TRAIL_TARGET_ID`,
		`account_audit_trail`.`TRAIL_TARGET_SERVER_ID`,
		`account_audit_trail`.`TRAIL_MODULE_ID`,
		`account_audit_trail`.`TRAIL_TIMESTAMP`
		
	FROM `account_audit_trail`
	WHERE
		-- Select changes made to record (except changes came from mother server)
		-- Skip if newer changes exists in database (only the latest change will reflected in sync)
		`account_audit_trail`.`TRAIL_METHOD_ID` = PARAM_TRAIL_METHOD_ID AND
		`account_audit_trail`.`TRAIL_SERVER_ID` <> PARAM_SERVER_ID AND
		(
			PARAM_TRAIL_IS_CLIENT_TO_SERVER = 0 OR
			`account_audit_trail`.`TRAIL_TARGET_SERVER_ID` > 0
		) AND
		`account_audit_trail`.`TRAIL_MODULE_ID` = TEMP_MODULE_ID AND
		`account_audit_trail`.`TRAIL_TIMESTAMP` > PARAM_TRAIL_TIMESTAMP_FROM AND
		`account_audit_trail`.`TRAIL_TIMESTAMP` <= PARAM_TRAIL_TIMESTAMP_TO
		
	ORDER BY
		`account_audit_trail`.`TRAIL_TIMESTAMP` ASC
		
	LIMIT PARAM_SKIP, PARAM_LIMIT;
	-- ====================================================================================================================================================================	
*/		
END ;;
DELIMITER ;
/*!50003 SET sql_mode              = @saved_sql_mode */ ;
/*!50003 SET character_set_client  = @saved_cs_client */ ;
/*!50003 SET character_set_results = @saved_cs_results */ ;
/*!50003 SET collation_connection  = @saved_col_connection */ ;
/*!50003 DROP PROCEDURE IF EXISTS `ACCOUNT_SERVER_SYNC_GET` */;
/*!50003 SET @saved_cs_client      = @@character_set_client */ ;
/*!50003 SET @saved_cs_results     = @@character_set_results */ ;
/*!50003 SET @saved_col_connection = @@collation_connection */ ;
/*!50003 SET character_set_client  = latin1 */ ;
/*!50003 SET character_set_results = latin1 */ ;
/*!50003 SET collation_connection  = latin1_swedish_ci */ ;
/*!50003 SET @saved_sql_mode       = @@sql_mode */ ;
/*!50003 SET sql_mode              = '' */ ;
DELIMITER ;;
CREATE DEFINER=`root`@`localhost` PROCEDURE `ACCOUNT_SERVER_SYNC_GET`(
	IN `PARAM_SERVER_ID` BIGINT,
	IN `PARAM_TRAIL_METHOD_ID` BIGINT,
	IN `PARAM_TRAIL_TIMESTAMP_FROM` DATETIME(6),
	IN `PARAM_TRAIL_TIMESTAMP_TO` DATETIME(6),
		
	IN `PARAM_ORDER_FIELD` VARCHAR(500),
	IN `PARAM_ORDER_TYPE` VARCHAR(500),
	IN `PARAM_SKIP` BIGINT,
	IN `PARAM_LIMIT` BIGINT,

	IN `PARAM_REQUESTER_USERNAME` VARCHAR(500),
	IN `PARAM_REQUESTER_PASSWORD` VARCHAR(500),
	IN `PARAM_REQUESTER_IP` VARCHAR(1000),
	IN `PARAM_UNIQUE_SESSION_ID` VARCHAR(1000),
	IN `PARAM_SUPPRESS_RETURN` BIT,
	
	IN `PARAM_SYNC_SERVER_DESCRIPTION` VARCHAR(500), 
	IN `PARAM_SYNC_SERVER_UNIQUE_KEY` VARCHAR(500)
)
SP_GET:
BEGIN
/*
	-- 1) DECLARE LOCAL PARAMETERS
	-- ====================================================================================================================================================================
	-- Audit Handler
	DECLARE TEMP_RECORD_EXISTS BIT DEFAULT 0;
	DECLARE TEMP_MODULE_KEYWORD VARCHAR(500) DEFAULT 'account_server';
	DECLARE TEMP_SP_OBJECTIVE VARCHAR(500) DEFAULT 'synchronizing data; account: server';
	DECLARE TEMP_ERR_MESSAGE VARCHAR(500) DEFAULT '';
	DECLARE ERR BIGINT DEFAULT 0;
	DECLARE TEMP_RECORD_CHANGES VARCHAR(16000) DEFAULT '';
	DECLARE TEMP_RECORD_BINDED BIT DEFAULT 0;
	
	-- Authentication
	DECLARE TEMP_ACCESS_RIGHTS_DENIED BIT DEFAULT 0;
	DECLARE TEMP_SYNC_SERVER_ID BIGINT DEFAULT 0;
	DECLARE TEMP_SYNC_IS_SERVER_REQUEST BIT DEFAULT 0;
	DECLARE TEMP_AUTHENTICATED_ACCOUNT_ID BIGINT DEFAULT `ACCOUNT_MEMBER@ACCOUNT_ID_FROM_LOGIN`(PARAM_REQUESTER_USERNAME, PARAM_REQUESTER_PASSWORD);
	DECLARE TEMP_AUTHENTICATED_ACCOUNT_LEVEL BIGINT DEFAULT 0;
	
	-- Local Parameters
	DECLARE TEMP_MODULE_ID BIGINT DEFAULT `SYSTEM_MODULE@MODULE_ID_FROM_KEYWORD`('account_server');
	
	-- Handle Nulls
	DECLARE IS_NULL_TRAIL_TIMESTAMP_FROM BIT DEFAULT `SYSTEM_VAR@IS_NULL@DATETIME`(PARAM_TRAIL_TIMESTAMP_FROM, 1);
	DECLARE IS_NULL_TRAIL_TIMESTAMP_TO BIT DEFAULT `SYSTEM_VAR@IS_NULL@DATETIME`(PARAM_TRAIL_TIMESTAMP_TO, 1);

	-- ====================================================================================================================================================================	

	
	-- 2) Try Catch / Throw
	-- ====================================================================================================================================================================
	DECLARE EXIT HANDLER FOR SQLEXCEPTION
	BEGIN
		RESIGNAL;
	END;
	-- ====================================================================================================================================================================	
	
	
	-- 3) Prepare SYNC
	-- ====================================================================================================================================================================

	-- IS SERVE REQUEST
	IF
		`SYSTEM_VAR@IS_NULL@NVARCHAR`(PARAM_SYNC_SERVER_DESCRIPTION, 1) = 0 AND
		`SYSTEM_VAR@IS_NULL@NVARCHAR`(PARAM_SYNC_SERVER_UNIQUE_KEY, 1) = 0
	THEN
		SET TEMP_SYNC_IS_SERVER_REQUEST = 1;
		
		-- GET SERVER ID
		SET TEMP_SYNC_SERVER_ID = `ACCOUNT_SERVER@SERVER_ID_FROM_LOGIN`(PARAM_SYNC_SERVER_DESCRIPTION, PARAM_SYNC_SERVER_UNIQUE_KEY);
	
	END IF;

	-- ====================================================================================================================================================================

		
	-- 4) VALIDATE
	-- ====================================================================================================================================================================	
	IF 
		`ACCOUNT_SERVER@HAS_PERMISSION`(PARAM_SYNC_SERVER_DESCRIPTION, PARAM_SYNC_SERVER_UNIQUE_KEY) = 0 AND
		`ACCOUNT_ACCESS_RIGHTS@HAS_PERMISSION`(PARAM_REQUESTER_USERNAME, PARAM_REQUESTER_PASSWORD, 0, TEMP_MODULE_KEYWORD, 2) = 0 
	THEN
		CALL `ACCOUNT_ACCESS_RIGHTS_DENY`
		(
			0, TEMP_MODULE_KEYWORD, 0, 0, TEMP_SP_OBJECTIVE, '',
			PARAM_REQUESTER_USERNAME, PARAM_REQUESTER_PASSWORD, PARAM_REQUESTER_IP, PARAM_UNIQUE_SESSION_ID,
			TEMP_SYNC_SERVER_ID, PARAM_SUPPRESS_RETURN
		);
	END IF;
	-- ====================================================================================================================================================================	
	
	
	-- 4) SELECT ITEMS
	-- ====================================================================================================================================================================	
	SELECT
		-- SERVER DATA
		`account_server`.`SERVER_ID`,
		`account_server`.`SERVER_TITLE`,
		`account_server`.`SERVER_DESCRIPTION`,
		`account_server`.`SERVER_UNIQUE_KEY`,
		`account_server`.`SERVER_STATUS`,
		
		`account_audit_trail`.`TRAIL_TARGET_ID`,
		`account_audit_trail`.`TRAIL_TARGET_SERVER_ID`,
		`account_audit_trail`.`TRAIL_MODULE_ID`,
		`account_audit_trail`.`TRAIL_TIMESTAMP`
		
	FROM `account_audit_trail`
	
		-- Check newer changes if exists
		LEFT JOIN `account_audit_trail` NEWER_CHANGES ON
		NEWER_CHANGES.`TRAIL_ID` <>	`account_audit_trail`.`TRAIL_ID` AND
		NEWER_CHANGES.`TRAIL_TARGET_ID` = `account_audit_trail`.`TRAIL_TARGET_ID` AND
		NEWER_CHANGES.`TRAIL_METHOD_ID` = `account_audit_trail`.`TRAIL_METHOD_ID` AND
		NEWER_CHANGES.`TRAIL_MODULE_ID` = `account_audit_trail`.`TRAIL_MODULE_ID` AND
		(
			IS_NULL_TRAIL_TIMESTAMP_FROM = 1 OR
			NEWER_CHANGES.`TRAIL_TIMESTAMP` > `account_audit_trail`.`TRAIL_TIMESTAMP`
		) AND
		(
			IS_NULL_TRAIL_TIMESTAMP_TO = 1 OR
			NEWER_CHANGES.`TRAIL_TIMESTAMP`	<= PARAM_TRAIL_TIMESTAMP_TO
		)
		
		-- return record IF STILL EXISTS IN DATABASE, else skip
		INNER JOIN `account_server` ON
		`account_server`.`SERVER_ID`  = `account_audit_trail`.`TRAIL_TARGET_ID`
		
	WHERE
		-- Select changes made to record (except changes came from mother server)
		-- Skip if newer changes exists in database (only the latest change will reflected in sync)
		`account_audit_trail`.`TRAIL_METHOD_ID` = PARAM_TRAIL_METHOD_ID AND
		`account_audit_trail`.`TRAIL_SERVER_ID` <> PARAM_SERVER_ID AND
		`account_audit_trail`.`TRAIL_MODULE_ID` = TEMP_MODULE_ID AND
		(
			IS_NULL_TRAIL_TIMESTAMP_FROM = 1 OR
			`account_audit_trail`.`TRAIL_TIMESTAMP` > PARAM_TRAIL_TIMESTAMP_FROM
		) AND
		(
			IS_NULL_TRAIL_TIMESTAMP_TO = 1 OR
			`account_audit_trail`.`TRAIL_TIMESTAMP` <= PARAM_TRAIL_TIMESTAMP_TO 
		) AND
		NEWER_CHANGES.`TRAIL_ID` IS NULL
		
	ORDER BY
		`account_audit_trail`.`TRAIL_TIMESTAMP` ASC
		
	LIMIT PARAM_SKIP, PARAM_LIMIT;
	LEAVE SP_GET;
	-- ====================================================================================================================================================================	
*/			
END ;;
DELIMITER ;
/*!50003 SET sql_mode              = @saved_sql_mode */ ;
/*!50003 SET character_set_client  = @saved_cs_client */ ;
/*!50003 SET character_set_results = @saved_cs_results */ ;
/*!50003 SET collation_connection  = @saved_col_connection */ ;
/*!50003 DROP PROCEDURE IF EXISTS `ADDON_LICENSE_GROUP_DELETE` */;
/*!50003 SET @saved_cs_client      = @@character_set_client */ ;
/*!50003 SET @saved_cs_results     = @@character_set_results */ ;
/*!50003 SET @saved_col_connection = @@collation_connection */ ;
/*!50003 SET character_set_client  = latin1 */ ;
/*!50003 SET character_set_results = latin1 */ ;
/*!50003 SET collation_connection  = latin1_swedish_ci */ ;
/*!50003 SET @saved_sql_mode       = @@sql_mode */ ;
/*!50003 SET sql_mode              = '' */ ;
DELIMITER ;;
CREATE DEFINER=`root`@`localhost` PROCEDURE `ADDON_LICENSE_GROUP_DELETE`(
	IN `PARAM_ADD_GLICENSE_ID` BIGINT,

	IN `PARAM_REQUESTER_USERNAME` VARCHAR(500),
	IN `PARAM_REQUESTER_PASSWORD` VARCHAR(500),
	IN `PARAM_REQUESTER_PROXY_ID` BIGINT,
	IN `PARAM_REQUESTER_PROXY_PASSWORD` VARCHAR(1000),
	IN `PARAM_REQUESTER_DEVICE_PUBLIC_KEY` VARCHAR(1000),
	IN `PARAM_REQUESTER_DEVICE_PRIVATE_KEY` VARCHAR(1000),
	
	IN `PARAM_REQUESTER_IP` VARCHAR(1000),
	IN `PARAM_UNIQUE_SESSION_ID` VARCHAR(1000),
	IN `PARAM_SUPPRESS_RETURN` BIT,
	
	IN `PARAM_SYNC_SERVER_DESCRIPTION` VARCHAR(500), 
	IN `PARAM_SYNC_SERVER_UNIQUE_KEY` VARCHAR(500)
)
SP_DELETE:
BEGIN

	-- 1) DECLARE LOCAL PARAMETERS
	-- _______________________________________________________________________
	
	-- Status
	-- ...........................................
	DECLARE STATUS_INACTIVE TINYINT DEFAULT 1;
	DECLARE STATUS_ACTIVE TINYINT DEFAULT 2;
	DECLARE STATUS_CLOSED TINYINT DEFAULT 3;
	DECLARE STATUS_COMPLETED TINYINT DEFAULT 4;
	
	-- Audit Handler
	-- ...........................................
	DECLARE TEMP_RECORD_EXISTS BIT DEFAULT 0;
	DECLARE TEMP_MODULE_KEYWORD VARCHAR(500) DEFAULT 'addon_license_group';
	DECLARE TEMP_SP_OBJECTIVE VARCHAR(500) DEFAULT 'delete Group License record';
	DECLARE TEMP_ERR_MESSAGE VARCHAR(500) DEFAULT '';
	DECLARE ERR BIGINT DEFAULT 0;
	DECLARE TEMP_RECORD_CHANGES VARCHAR(16000) DEFAULT '';
	DECLARE TEMP_RECORD_BINDED BIT DEFAULT 0;
	
	DECLARE TEMP_RECORD_BINDED_ID BIGINT DEFAULT 0;
	DECLARE TEMP_RECORD_BINDED_SERVER_ID BIGINT DEFAULT 0;
	
	-- Authentication
	-- ...........................................
	DECLARE TEMP_ACCESS_RIGHTS_DENIED BIT DEFAULT 0;
	DECLARE TEMP_SYNC_SERVER_ID BIGINT DEFAULT 0;
	DECLARE TEMP_SYNC_IS_SERVER_REQUEST BIT DEFAULT 0;
	DECLARE TEMP_AUTHENTICATED_ACCOUNT_ID BIGINT DEFAULT `ACCOUNT_MEMBER@ACC_ACCOUNT_ID_FROM_LOGIN`(PARAM_REQUESTER_USERNAME, PARAM_REQUESTER_PASSWORD);
	DECLARE TEMP_AUTHENTICATED_ACCOUNT_LEVEL BIGINT DEFAULT 0;
	DECLARE TEMP_AUTHENTICATED_ACCOUNT_GROUP BIGINT DEFAULT 0;

	-- Local value holder
	-- ...........................................
		DECLARE TEMP_ADD_GLICENSE_ACC_GROUP_ID BIGINT DEFAULT 0; 
		DECLARE TEMP_ADD_GLICENSE_DATE_RENEW DATETIME(6) DEFAULT '1000-01-01 00:00:00.000000'; 
		DECLARE TEMP_ADD_GLICENSE_DATE_EXPIRY DATETIME(6) DEFAULT '1000-01-01 00:00:00.000000'; 
		DECLARE TEMP_ADD_GLICENSE_VOLUME BIGINT DEFAULT 0; 
		DECLARE TEMP_ADD_GLICENSE_STATUS TINYINT DEFAULT 0; 
		DECLARE TEMP_ADD_GLICENSE_SYSTEM_GENERATED TINYINT DEFAULT 0; 

	
	
	-- 2) Try Catch / Throw
	-- _______________________________________________________________________
	DECLARE EXIT HANDLER FOR SQLEXCEPTION
	BEGIN
		RESIGNAL;
	END;

	
	-- 3) Prepare SYNC
	-- _______________________________________________________________________
	
	-- IS RECORD EXISTS		
	-- ####################################################		
	SET TEMP_RECORD_EXISTS = `ADDON_LICENSE_GROUP@ADD_GLICENSE_ID_EXISTS`(PARAM_ADD_GLICENSE_ID, 0);


	-- 4) IF ALREADY EXIST, FILL MISSING DATA
	-- _______________________________________________________________________
	IF TEMP_RECORD_EXISTS = 1 THEN
		SELECT
				`addon_license_group`.`ADD_GLICENSE_ACC_GROUP_ID`, 	
				`addon_license_group`.`ADD_GLICENSE_DATE_RENEW`, 	
				`addon_license_group`.`ADD_GLICENSE_DATE_EXPIRY`, 	
				`addon_license_group`.`ADD_GLICENSE_VOLUME`, 	
				`addon_license_group`.`ADD_GLICENSE_STATUS`, 	
				`addon_license_group`.`ADD_GLICENSE_SYSTEM_GENERATED`	
		INTO
				TEMP_ADD_GLICENSE_ACC_GROUP_ID, 	
				TEMP_ADD_GLICENSE_DATE_RENEW, 	
				TEMP_ADD_GLICENSE_DATE_EXPIRY, 	
				TEMP_ADD_GLICENSE_VOLUME, 	
				TEMP_ADD_GLICENSE_STATUS, 	
				TEMP_ADD_GLICENSE_SYSTEM_GENERATED	

		FROM `addon_license_group`
		WHERE
			`addon_license_group`.`ADD_GLICENSE_ID` = PARAM_ADD_GLICENSE_ID
		LIMIT 1;

	ELSE 
		IF TEMP_SYNC_IS_SERVER_REQUEST = 0 THEN
			SET TEMP_ERR_MESSAGE = CONCAT_WS(' ', 'Given Group License does not exists or is inactive. ID:', PARAM_ADD_GLICENSE_ID);
			SET ERR = `RAISERROR`(TEMP_ERR_MESSAGE);		
		END IF;
		LEAVE SP_DELETE;
		
	END IF;



	-- 5) PREPARE AUDIT TRAIL
	-- _______________________________________________________________________
	
		SET TEMP_RECORD_CHANGES = 
		`SYSTEM_VAR@CONCAT_ADD`(' | ', TEMP_RECORD_CHANGES, CONCAT_WS(' ', 'Group: "', TEMP_ADD_GLICENSE_ACC_GROUP_ID, '" > " DELETED "'));
		SET TEMP_RECORD_CHANGES = 
		`SYSTEM_VAR@CONCAT_ADD`(' | ', TEMP_RECORD_CHANGES, CONCAT_WS(' ', 'Renewal date: "', TEMP_ADD_GLICENSE_DATE_RENEW, '" > " DELETED "'));
		SET TEMP_RECORD_CHANGES = 
		`SYSTEM_VAR@CONCAT_ADD`(' | ', TEMP_RECORD_CHANGES, CONCAT_WS(' ', 'Expiry Date: "', TEMP_ADD_GLICENSE_DATE_EXPIRY, '" > " DELETED "'));
		SET TEMP_RECORD_CHANGES = 
		`SYSTEM_VAR@CONCAT_ADD`(' | ', TEMP_RECORD_CHANGES, CONCAT_WS(' ', 'License Volume: "', TEMP_ADD_GLICENSE_VOLUME, '" > " DELETED "'));
		SET TEMP_RECORD_CHANGES = 
		`SYSTEM_VAR@CONCAT_ADD`(' | ', TEMP_RECORD_CHANGES, CONCAT_WS(' ', 'Status: "', TEMP_ADD_GLICENSE_STATUS, '" > " DELETED "'));
		SET TEMP_RECORD_CHANGES = 
		`SYSTEM_VAR@CONCAT_ADD`(' | ', TEMP_RECORD_CHANGES, CONCAT_WS(' ', 'System Generated: "', TEMP_ADD_GLICENSE_SYSTEM_GENERATED, '" > " DELETED "'));


	-- 6) VALIDATE
	-- _______________________________________________________________________
	
	-- Access Rights [Device]
	-- ####################################################
	IF `ACCOUNT_DEVICE@HAS_PERMISSION`(PARAM_REQUESTER_DEVICE_PUBLIC_KEY, PARAM_REQUESTER_DEVICE_PRIVATE_KEY) = 0 THEN
		SET TEMP_ERR_MESSAGE = 'Your device is not authorized yet to access this server.';
		SET ERR = `RAISERROR`(TEMP_ERR_MESSAGE);		
	END IF;
		
		
	-- Access Rights [Account]
	-- ####################################################	
	-- Check if accessing a record outside own group.
	SET TEMP_AUTHENTICATED_ACCOUNT_GROUP = `ACCOUNT_MEMBER@ACC_ACCOUNT_GROUP_FROM_LOGIN`(PARAM_REQUESTER_USERNAME, PARAM_REQUESTER_PASSWORD);
	IF TEMP_AUTHENTICATED_ACCOUNT_GROUP <> TEMP_ADD_GLICENSE_ACC_GROUP_ID THEN
		IF `ACCOUNT_ACCESS_RIGHTS@HAS_PERMISSION`(PARAM_REQUESTER_USERNAME, PARAM_REQUESTER_PASSWORD, 0, TEMP_MODULE_KEYWORD, 4) = 0 THEN
			SET TEMP_ACCESS_RIGHTS_DENIED = 1;
			CALL `ACCOUNT_ACCESS_RIGHTS_DENY`
			(
				0, TEMP_MODULE_KEYWORD, 0, 0, TEMP_SP_OBJECTIVE, TEMP_RECORD_CHANGES, 
				PARAM_REQUESTER_USERNAME, PARAM_REQUESTER_PASSWORD, 
				PARAM_REQUESTER_PROXY_ID, PARAM_REQUESTER_PROXY_PASSWORD,
				PARAM_REQUESTER_DEVICE_PUBLIC_KEY, PARAM_REQUESTER_DEVICE_PRIVATE_KEY,
				PARAM_REQUESTER_IP, PARAM_UNIQUE_SESSION_ID,
				0, PARAM_SUPPRESS_RETURN
			);
		END IF;					
	END IF;
	
	IF 
		-- [DELETE] Access Rights
		`ACCOUNT_ACCESS_RIGHTS@HAS_PERMISSION`(PARAM_REQUESTER_USERNAME, PARAM_REQUESTER_PASSWORD, 0, TEMP_MODULE_KEYWORD, 4) = 0 
	THEN
		SET TEMP_ACCESS_RIGHTS_DENIED = 1;
		CALL `ACCOUNT_ACCESS_RIGHTS_DENY`
		(
			0, TEMP_MODULE_KEYWORD, PARAM_ADD_GLICENSE_ID, 0, TEMP_SP_OBJECTIVE, TEMP_RECORD_CHANGES, 
			PARAM_REQUESTER_USERNAME, PARAM_REQUESTER_PASSWORD, 
			PARAM_REQUESTER_PROXY_ID, PARAM_REQUESTER_PROXY_PASSWORD,
			PARAM_REQUESTER_DEVICE_PUBLIC_KEY, PARAM_REQUESTER_DEVICE_PRIVATE_KEY,
			PARAM_REQUESTER_IP, PARAM_UNIQUE_SESSION_ID,
			TEMP_SYNC_SERVER_ID, PARAM_SUPPRESS_RETURN
		);
	END IF;

	-- System Generated Record (Cannot be deleted)
	-- ####################################################
	IF TEMP_ADD_GLICENSE_SYSTEM_GENERATED = STATUS_ACTIVE THEN
		CALL `VALIDATION_SYSTEM_GENERATED`
		(
			PARAM_ADD_GLICENSE_ID,
			TEMP_ADD_GLICENSE_ACC_GROUP_ID, ''
		);
	END IF;
	
	-- If already used, cannot remove record
	-- ####################################################

	-- Leave Re-upload request
	-- ####################################################
	IF TEMP_RECORD_BINDED = 1 THEN
		IF TEMP_SYNC_IS_SERVER_REQUEST = 1 THEN
			
			LEAVE SP_DELETE;
		END IF;

		CALL `VALIDATION_DELETE_LINKED_RECORD`(TEMP_ADD_GLICENSE_ACC_GROUP_ID, '', TEMP_ERR_MESSAGE); 
	END IF;


	-- 7) DELETE
	-- _______________________________________________________________________
	DELETE FROM `addon_license_group`
	WHERE `addon_license_group`.`ADD_GLICENSE_ID` = PARAM_ADD_GLICENSE_ID
	LIMIT 1;


	-- 8) AUDIT TRAIL
	-- _______________________________________________________________________
	CALL `ACCOUNT_AUDIT_TRAIL_SAVE`
	(
		0, TEMP_MODULE_KEYWORD, PARAM_ADD_GLICENSE_ID, 0, 'DELETE', TEMP_SP_OBJECTIVE, TEMP_RECORD_CHANGES, 
		PARAM_REQUESTER_USERNAME, PARAM_REQUESTER_PASSWORD, 
		PARAM_REQUESTER_PROXY_ID, PARAM_REQUESTER_PROXY_PASSWORD,
		PARAM_REQUESTER_DEVICE_PUBLIC_KEY, PARAM_REQUESTER_DEVICE_PRIVATE_KEY,
		PARAM_REQUESTER_IP, PARAM_UNIQUE_SESSION_ID,
		TEMP_SYNC_SERVER_ID, PARAM_SUPPRESS_RETURN
	);

END ;;
DELIMITER ;
/*!50003 SET sql_mode              = @saved_sql_mode */ ;
/*!50003 SET character_set_client  = @saved_cs_client */ ;
/*!50003 SET character_set_results = @saved_cs_results */ ;
/*!50003 SET collation_connection  = @saved_col_connection */ ;
/*!50003 DROP PROCEDURE IF EXISTS `ADDON_LICENSE_GROUP_GET` */;
/*!50003 SET @saved_cs_client      = @@character_set_client */ ;
/*!50003 SET @saved_cs_results     = @@character_set_results */ ;
/*!50003 SET @saved_col_connection = @@collation_connection */ ;
/*!50003 SET character_set_client  = latin1 */ ;
/*!50003 SET character_set_results = latin1 */ ;
/*!50003 SET collation_connection  = latin1_swedish_ci */ ;
/*!50003 SET @saved_sql_mode       = @@sql_mode */ ;
/*!50003 SET sql_mode              = '' */ ;
DELIMITER ;;
CREATE DEFINER=`root`@`localhost` PROCEDURE `ADDON_LICENSE_GROUP_GET`(
	IN `PARAM_ADD_GLICENSE_ID` BIGINT,	
	IN `PARAM_ADD_GLICENSE_ACC_GROUP_ID` BIGINT,	
	IN `PARAM_ADD_GLICENSE_DATE_RENEW_FROM` DATETIME(6),
	IN `PARAM_ADD_GLICENSE_DATE_RENEW_TO` DATETIME(6),
	IN `PARAM_ADD_GLICENSE_DATE_EXPIRY_FROM` DATETIME(6),
	IN `PARAM_ADD_GLICENSE_DATE_EXPIRY_TO` DATETIME(6),
	IN `PARAM_ADD_GLICENSE_VOLUME_FROM` BIGINT,
	IN `PARAM_ADD_GLICENSE_VOLUME_TO` BIGINT,
	IN `PARAM_ADD_GLICENSE_STATUS` TINYINT,	
	IN `PARAM_ADD_GLICENSE_SYSTEM_GENERATED` TINYINT,	
		
	IN `PARAM_ORDER_FIELD` VARCHAR(500),
	IN `PARAM_ORDER_TYPE` VARCHAR(500),
	IN `PARAM_SKIP` BIGINT,
	IN `PARAM_LIMIT` BIGINT,

	IN `PARAM_REQUESTER_USERNAME` VARCHAR(500),
	IN `PARAM_REQUESTER_PASSWORD` VARCHAR(500),
	IN `PARAM_REQUESTER_PROXY_ID` BIGINT,
	IN `PARAM_REQUESTER_PROXY_PASSWORD` VARCHAR(1000),
	IN `PARAM_REQUESTER_DEVICE_PUBLIC_KEY` VARCHAR(1000),
	IN `PARAM_REQUESTER_DEVICE_PRIVATE_KEY` VARCHAR(1000),
	
	IN `PARAM_REQUESTER_IP` VARCHAR(1000),
	IN `PARAM_UNIQUE_SESSION_ID` VARCHAR(1000),
	IN `PARAM_SUPPRESS_RETURN` BIT
)
SP_GET:
BEGIN

	-- Status
	-- =========================================================================================
	DECLARE STATUS_INACTIVE TINYINT DEFAULT 1;
	DECLARE STATUS_ACTIVE TINYINT DEFAULT 2;
	DECLARE STATUS_CLOSED TINYINT DEFAULT 3;
	DECLARE STATUS_COMPLETED TINYINT DEFAULT 4;
	
	-- Audit Handler
	-- =========================================================================================
	DECLARE TEMP_RECORD_EXISTS BIT DEFAULT 0;
	DECLARE TEMP_MODULE_KEYWORD VARCHAR(500) DEFAULT 'addon_license_group';
	DECLARE TEMP_SP_OBJECTIVE VARCHAR(500) DEFAULT 'Retrieve Group License record';
	DECLARE TEMP_ERR_MESSAGE VARCHAR(500) DEFAULT '';
	DECLARE ERR BIGINT DEFAULT 0;
	DECLARE TEMP_RECORD_CHANGES VARCHAR(16000) DEFAULT '';
	DECLARE TEMP_RECORD_BINDED BIT DEFAULT 0;
	
	DECLARE TEMP_RECORD_BINDED_ID BIGINT DEFAULT 0;
	DECLARE TEMP_RECORD_BINDED_SERVER_ID BIGINT DEFAULT 0;
	
	-- Authentication
	-- =========================================================================================
	DECLARE TEMP_ACCESS_RIGHTS_DENIED BIT DEFAULT 0;
	DECLARE TEMP_AUTHENTICATED_ACCOUNT_ID BIGINT DEFAULT `ACCOUNT_MEMBER@ACC_ACCOUNT_ID_FROM_LOGIN`(PARAM_REQUESTER_USERNAME, PARAM_REQUESTER_PASSWORD);
	DECLARE TEMP_AUTHENTICATED_ACCOUNT_LEVEL BIGINT DEFAULT 0;
	DECLARE TEMP_AUTHENTICATED_ACCOUNT_GROUP BIGINT DEFAULT 0;
	
	-- Local Parameters
	-- =========================================================================================
	DECLARE TEMP_NOW DATETIME(6) DEFAULT `SYSTEM_VAR@NOW`('', 1);
	DECLARE TEMP_RECORD_COUNT BIGINT DEFAULT 0;
	
	
	-- Check NULLs
	-- =========================================================================================
	DECLARE IS_NULL_ADD_GLICENSE_ID BIT DEFAULT `SYSTEM_VAR@IS_NULL@BIGINT`(PARAM_ADD_GLICENSE_ID, 1, 1);
	DECLARE IS_NULL_ADD_GLICENSE_ACC_GROUP_ID BIT DEFAULT `SYSTEM_VAR@IS_NULL@BIGINT`(PARAM_ADD_GLICENSE_ACC_GROUP_ID, 1, 1);
	DECLARE IS_NULL_ADD_GLICENSE_DATE_RENEW_FROM BIT DEFAULT `SYSTEM_VAR@IS_NULL@DATETIME`(PARAM_ADD_GLICENSE_DATE_RENEW_FROM, 1);
	DECLARE IS_NULL_ADD_GLICENSE_DATE_RENEW_TO BIT DEFAULT `SYSTEM_VAR@IS_NULL@DATETIME`(PARAM_ADD_GLICENSE_DATE_RENEW_TO, 1);				
	DECLARE IS_NULL_ADD_GLICENSE_DATE_EXPIRY_FROM BIT DEFAULT `SYSTEM_VAR@IS_NULL@DATETIME`(PARAM_ADD_GLICENSE_DATE_EXPIRY_FROM, 1);
	DECLARE IS_NULL_ADD_GLICENSE_DATE_EXPIRY_TO BIT DEFAULT `SYSTEM_VAR@IS_NULL@DATETIME`(PARAM_ADD_GLICENSE_DATE_EXPIRY_TO, 1);				
	DECLARE IS_NULL_ADD_GLICENSE_VOLUME_FROM BIT DEFAULT `SYSTEM_VAR@IS_NULL@BIGINT`(PARAM_ADD_GLICENSE_VOLUME_FROM, 1, 1);
	DECLARE IS_NULL_ADD_GLICENSE_VOLUME_TO BIT DEFAULT `SYSTEM_VAR@IS_NULL@BIGINT`(PARAM_ADD_GLICENSE_VOLUME_TO, 1, 1);
	DECLARE IS_NULL_ADD_GLICENSE_STATUS BIT DEFAULT `SYSTEM_VAR@IS_NULL@TINYINT`(PARAM_ADD_GLICENSE_STATUS, 1, 1);
	DECLARE IS_NULL_ADD_GLICENSE_SYSTEM_GENERATED BIT DEFAULT `SYSTEM_VAR@IS_NULL@TINYINT`(PARAM_ADD_GLICENSE_SYSTEM_GENERATED, 1, 1);
	
	-- Error Handler
	-- =========================================================================================
	DECLARE EXIT HANDLER FOR SQLEXCEPTION
	BEGIN
		RESIGNAL;
	END;
	
	-- Ignore Time from DateTime (Set Time 00:00:00.000000 and 23:59:59.999999)
	-- =========================================================================================
		
		
	-- Access Rights [Device]
	-- =========================================================================================
	IF `ACCOUNT_DEVICE@HAS_PERMISSION`(PARAM_REQUESTER_DEVICE_PUBLIC_KEY, PARAM_REQUESTER_DEVICE_PRIVATE_KEY) = 0 THEN
		SET TEMP_ERR_MESSAGE = 'Your device is not authorized yet to access this server.';
		SET ERR = `RAISERROR`(TEMP_ERR_MESSAGE);		
	END IF;
		
		
	-- Access Rights [Account]
	-- =========================================================================================
	-- Check if accessing a record outside own group.
	SET TEMP_AUTHENTICATED_ACCOUNT_GROUP = `ACCOUNT_MEMBER@ACC_ACCOUNT_GROUP_FROM_LOGIN`(PARAM_REQUESTER_USERNAME, PARAM_REQUESTER_PASSWORD);
	IF TEMP_AUTHENTICATED_ACCOUNT_GROUP <> PARAM_ADD_GLICENSE_ACC_GROUP_ID THEN
		IF `ACCOUNT_ACCESS_RIGHTS@HAS_PERMISSION`(PARAM_REQUESTER_USERNAME, PARAM_REQUESTER_PASSWORD, 0, TEMP_MODULE_KEYWORD, 4) = 0 THEN
			SET TEMP_ACCESS_RIGHTS_DENIED = 1;
			CALL `ACCOUNT_ACCESS_RIGHTS_DENY`
			(
				0, TEMP_MODULE_KEYWORD, 0, 0, TEMP_SP_OBJECTIVE, TEMP_RECORD_CHANGES, 
				PARAM_REQUESTER_USERNAME, PARAM_REQUESTER_PASSWORD, 
				PARAM_REQUESTER_PROXY_ID, PARAM_REQUESTER_PROXY_PASSWORD,
				PARAM_REQUESTER_DEVICE_PUBLIC_KEY, PARAM_REQUESTER_DEVICE_PRIVATE_KEY,
				PARAM_REQUESTER_IP, PARAM_UNIQUE_SESSION_ID,
				0, PARAM_SUPPRESS_RETURN
			);
		END IF;					
	END IF;
		
	IF `ACCOUNT_ACCESS_RIGHTS@HAS_PERMISSION`(PARAM_REQUESTER_USERNAME, PARAM_REQUESTER_PASSWORD, 0, TEMP_MODULE_KEYWORD, 1) = 0 THEN
		SET TEMP_ACCESS_RIGHTS_DENIED = 1;
		CALL `ACCOUNT_ACCESS_RIGHTS_DENY`
		(
			0, TEMP_MODULE_KEYWORD, 0, 0, TEMP_SP_OBJECTIVE, TEMP_RECORD_CHANGES, 
			PARAM_REQUESTER_USERNAME, PARAM_REQUESTER_PASSWORD, 
			PARAM_REQUESTER_PROXY_ID, PARAM_REQUESTER_PROXY_PASSWORD,
			PARAM_REQUESTER_DEVICE_PUBLIC_KEY, PARAM_REQUESTER_DEVICE_PRIVATE_KEY,
			PARAM_REQUESTER_IP, PARAM_UNIQUE_SESSION_ID,
			0, PARAM_SUPPRESS_RETURN
		);
	END IF;
	
	
	
	-- COUNT RECORD
	-- =========================================================================================
	
	-- SELECT COLUMNS
	-- ####################################################
	SELECT
		COUNT(DISTINCT `addon_license_group`.`ADD_GLICENSE_ID`)
	INTO
		TEMP_RECORD_COUNT

	FROM `addon_license_group`
	
		-- Add Inner Joins (Per Foreign-key)
		INNER JOIN `account_group` ON
		`account_group`.`ACC_GROUP_ID` = `addon_license_group`.`ADD_GLICENSE_ACC_GROUP_ID`
		
		-- Add Optional Left Joins (Per Optional Foreign-key)
		
	-- CONDITIONS
	-- ####################################################
	WHERE
		(
			IS_NULL_ADD_GLICENSE_ID = 1 OR
			`addon_license_group`.`ADD_GLICENSE_ID` = PARAM_ADD_GLICENSE_ID			
		) AND
		(
			IS_NULL_ADD_GLICENSE_ACC_GROUP_ID = 1 OR
			`addon_license_group`.`ADD_GLICENSE_ACC_GROUP_ID` = PARAM_ADD_GLICENSE_ACC_GROUP_ID			
		) AND
		(
			IS_NULL_ADD_GLICENSE_DATE_RENEW_FROM = 1 OR
			`addon_license_group`.`ADD_GLICENSE_DATE_RENEW` >= PARAM_ADD_GLICENSE_DATE_RENEW_FROM			
		) AND
		(
			IS_NULL_ADD_GLICENSE_DATE_RENEW_TO = 1 OR
			`addon_license_group`.`ADD_GLICENSE_DATE_RENEW` <= PARAM_ADD_GLICENSE_DATE_RENEW_TO			
		) AND 		
		(
			IS_NULL_ADD_GLICENSE_DATE_EXPIRY_FROM = 1 OR
			`addon_license_group`.`ADD_GLICENSE_DATE_EXPIRY` >= PARAM_ADD_GLICENSE_DATE_EXPIRY_FROM			
		) AND
		(
			IS_NULL_ADD_GLICENSE_DATE_EXPIRY_TO = 1 OR
			`addon_license_group`.`ADD_GLICENSE_DATE_EXPIRY` <= PARAM_ADD_GLICENSE_DATE_EXPIRY_TO			
		) AND 		
		(
			IS_NULL_ADD_GLICENSE_VOLUME_FROM = 1 OR
			`addon_license_group`.`ADD_GLICENSE_VOLUME` >= PARAM_ADD_GLICENSE_VOLUME_FROM			
		) AND
		(
			IS_NULL_ADD_GLICENSE_VOLUME_TO = 1 OR
			`addon_license_group`.`ADD_GLICENSE_VOLUME` <= PARAM_ADD_GLICENSE_VOLUME_TO			
		) AND 		
		(
			IS_NULL_ADD_GLICENSE_STATUS = 1 OR
			`addon_license_group`.`ADD_GLICENSE_STATUS` = PARAM_ADD_GLICENSE_STATUS			
		) AND
		(
			IS_NULL_ADD_GLICENSE_SYSTEM_GENERATED = 1 OR
			`addon_license_group`.`ADD_GLICENSE_SYSTEM_GENERATED` = PARAM_ADD_GLICENSE_SYSTEM_GENERATED			
		) 
;	

		
		
	-- SELECT RECORDS
	-- =========================================================================================
	
	-- FETCH COLUMNS
	-- ####################################################
	SELECT
		-- ADDON_LICENSE_GROUP DETAILS
		`addon_license_group`.`ADD_GLICENSE_ID`, 
		`addon_license_group`.`ADD_GLICENSE_ACC_GROUP_ID`, 
		`addon_license_group`.`ADD_GLICENSE_DATE_RENEW`, 
		`addon_license_group`.`ADD_GLICENSE_DATE_EXPIRY`, 
		`addon_license_group`.`ADD_GLICENSE_VOLUME`, 
		`addon_license_group`.`ADD_GLICENSE_STATUS`, 
		`addon_license_group`.`ADD_GLICENSE_SYSTEM_GENERATED`
		
		-- Inner join fields
		, 
		`account_group`.`ACC_GROUP_ID`, 
		`account_group`.`ACC_GROUP_DESCRIPTION`, 
		`account_group`.`ACC_GROUP_STATUS`, 
		`account_group`.`ACC_GROUP_SYSTEM_GENERATED`
		
		-- Left join fields
		
		, TEMP_NOW AS SERVER_TIME,
		TEMP_RECORD_COUNT AS RECORD_COUNT

	FROM `addon_license_group`
	
		-- Add Inner Joins (Per Foreign-key)
		INNER JOIN `account_group` ON
		`account_group`.`ACC_GROUP_ID` = `addon_license_group`.`ADD_GLICENSE_ACC_GROUP_ID`
		
		-- Add Optional Left Joins (Per Optional Foreign-key)
		
	-- CONDITIONS
	-- ####################################################
	WHERE
		(
			IS_NULL_ADD_GLICENSE_ID = 1 OR
			`addon_license_group`.`ADD_GLICENSE_ID` = PARAM_ADD_GLICENSE_ID			
		) AND
		(
			IS_NULL_ADD_GLICENSE_ACC_GROUP_ID = 1 OR
			`addon_license_group`.`ADD_GLICENSE_ACC_GROUP_ID` = PARAM_ADD_GLICENSE_ACC_GROUP_ID			
		) AND
		(
			IS_NULL_ADD_GLICENSE_DATE_RENEW_FROM = 1 OR
			`addon_license_group`.`ADD_GLICENSE_DATE_RENEW` >= PARAM_ADD_GLICENSE_DATE_RENEW_FROM			
		) AND
		(
			IS_NULL_ADD_GLICENSE_DATE_RENEW_TO = 1 OR
			`addon_license_group`.`ADD_GLICENSE_DATE_RENEW` <= PARAM_ADD_GLICENSE_DATE_RENEW_TO			
		) AND 
		(
			IS_NULL_ADD_GLICENSE_DATE_EXPIRY_FROM = 1 OR
			`addon_license_group`.`ADD_GLICENSE_DATE_EXPIRY` >= PARAM_ADD_GLICENSE_DATE_EXPIRY_FROM			
		) AND
		(
			IS_NULL_ADD_GLICENSE_DATE_EXPIRY_TO = 1 OR
			`addon_license_group`.`ADD_GLICENSE_DATE_EXPIRY` <= PARAM_ADD_GLICENSE_DATE_EXPIRY_TO			
		) AND 
		(
			IS_NULL_ADD_GLICENSE_VOLUME_FROM = 1 OR
			`addon_license_group`.`ADD_GLICENSE_VOLUME` >= PARAM_ADD_GLICENSE_VOLUME_FROM			
		) AND
		(
			IS_NULL_ADD_GLICENSE_VOLUME_TO = 1 OR
			`addon_license_group`.`ADD_GLICENSE_VOLUME` <= PARAM_ADD_GLICENSE_VOLUME_TO			
		) AND 
		(
			IS_NULL_ADD_GLICENSE_STATUS = 1 OR
			`addon_license_group`.`ADD_GLICENSE_STATUS` = PARAM_ADD_GLICENSE_STATUS			
		) AND
		(
			IS_NULL_ADD_GLICENSE_SYSTEM_GENERATED = 1 OR
			`addon_license_group`.`ADD_GLICENSE_SYSTEM_GENERATED` = PARAM_ADD_GLICENSE_SYSTEM_GENERATED			
		) 

	-- ORDER BY
	-- ####################################################
	ORDER BY
		-- ADDON_LICENSE_GROUP DETAILS
		CASE WHEN PARAM_ORDER_FIELD = 'ADD_GLICENSE_ID' AND PARAM_ORDER_TYPE = 'ASC' THEN `addon_license_group`.`ADD_GLICENSE_ID` END ASC, 
		CASE WHEN PARAM_ORDER_FIELD = 'ADD_GLICENSE_ID' AND PARAM_ORDER_TYPE = 'DESC' THEN `addon_license_group`.`ADD_GLICENSE_ID` END DESC,	
		CASE WHEN PARAM_ORDER_FIELD = 'ADD_GLICENSE_ACC_GROUP_ID' AND PARAM_ORDER_TYPE = 'ASC' THEN `addon_license_group`.`ADD_GLICENSE_ACC_GROUP_ID` END ASC, 
		CASE WHEN PARAM_ORDER_FIELD = 'ADD_GLICENSE_ACC_GROUP_ID' AND PARAM_ORDER_TYPE = 'DESC' THEN `addon_license_group`.`ADD_GLICENSE_ACC_GROUP_ID` END DESC,	
		CASE WHEN PARAM_ORDER_FIELD = 'ADD_GLICENSE_DATE_RENEW' AND PARAM_ORDER_TYPE = 'ASC' THEN `addon_license_group`.`ADD_GLICENSE_DATE_RENEW` END ASC, 
		CASE WHEN PARAM_ORDER_FIELD = 'ADD_GLICENSE_DATE_RENEW' AND PARAM_ORDER_TYPE = 'DESC' THEN `addon_license_group`.`ADD_GLICENSE_DATE_RENEW` END DESC,	
		CASE WHEN PARAM_ORDER_FIELD = 'ADD_GLICENSE_DATE_EXPIRY' AND PARAM_ORDER_TYPE = 'ASC' THEN `addon_license_group`.`ADD_GLICENSE_DATE_EXPIRY` END ASC, 
		CASE WHEN PARAM_ORDER_FIELD = 'ADD_GLICENSE_DATE_EXPIRY' AND PARAM_ORDER_TYPE = 'DESC' THEN `addon_license_group`.`ADD_GLICENSE_DATE_EXPIRY` END DESC,	
		CASE WHEN PARAM_ORDER_FIELD = 'ADD_GLICENSE_VOLUME' AND PARAM_ORDER_TYPE = 'ASC' THEN `addon_license_group`.`ADD_GLICENSE_VOLUME` END ASC, 
		CASE WHEN PARAM_ORDER_FIELD = 'ADD_GLICENSE_VOLUME' AND PARAM_ORDER_TYPE = 'DESC' THEN `addon_license_group`.`ADD_GLICENSE_VOLUME` END DESC,	
		CASE WHEN PARAM_ORDER_FIELD = 'ADD_GLICENSE_STATUS' AND PARAM_ORDER_TYPE = 'ASC' THEN `addon_license_group`.`ADD_GLICENSE_STATUS` END ASC, 
		CASE WHEN PARAM_ORDER_FIELD = 'ADD_GLICENSE_STATUS' AND PARAM_ORDER_TYPE = 'DESC' THEN `addon_license_group`.`ADD_GLICENSE_STATUS` END DESC,	
		CASE WHEN PARAM_ORDER_FIELD = 'ADD_GLICENSE_SYSTEM_GENERATED' AND PARAM_ORDER_TYPE = 'ASC' THEN `addon_license_group`.`ADD_GLICENSE_SYSTEM_GENERATED` END ASC, 
		CASE WHEN PARAM_ORDER_FIELD = 'ADD_GLICENSE_SYSTEM_GENERATED' AND PARAM_ORDER_TYPE = 'DESC' THEN `addon_license_group`.`ADD_GLICENSE_SYSTEM_GENERATED` END DESC,	

		-- Inner joins
		CASE WHEN PARAM_ORDER_FIELD = 'ACC_GROUP_ID' AND PARAM_ORDER_TYPE = 'ASC' THEN `account_group`.`ACC_GROUP_ID` END ASC, 
		CASE WHEN PARAM_ORDER_FIELD = 'ACC_GROUP_ID' AND PARAM_ORDER_TYPE = 'DESC' THEN `account_group`.`ACC_GROUP_ID` END DESC,	
		CASE WHEN PARAM_ORDER_FIELD = 'ACC_GROUP_DESCRIPTION' AND PARAM_ORDER_TYPE = 'ASC' THEN `account_group`.`ACC_GROUP_DESCRIPTION` END ASC, 
		CASE WHEN PARAM_ORDER_FIELD = 'ACC_GROUP_DESCRIPTION' AND PARAM_ORDER_TYPE = 'DESC' THEN `account_group`.`ACC_GROUP_DESCRIPTION` END DESC,	
		CASE WHEN PARAM_ORDER_FIELD = 'ACC_GROUP_STATUS' AND PARAM_ORDER_TYPE = 'ASC' THEN `account_group`.`ACC_GROUP_STATUS` END ASC, 
		CASE WHEN PARAM_ORDER_FIELD = 'ACC_GROUP_STATUS' AND PARAM_ORDER_TYPE = 'DESC' THEN `account_group`.`ACC_GROUP_STATUS` END DESC,	
		CASE WHEN PARAM_ORDER_FIELD = 'ACC_GROUP_SYSTEM_GENERATED' AND PARAM_ORDER_TYPE = 'ASC' THEN `account_group`.`ACC_GROUP_SYSTEM_GENERATED` END ASC, 
		CASE WHEN PARAM_ORDER_FIELD = 'ACC_GROUP_SYSTEM_GENERATED' AND PARAM_ORDER_TYPE = 'DESC' THEN `account_group`.`ACC_GROUP_SYSTEM_GENERATED` END DESC,	
		
		-- EXTRA
		CASE WHEN PARAM_ORDER_FIELD <> 'ADD_GLICENSE_ACC_GROUP_ID' THEN `addon_license_group`.`ADD_GLICENSE_ACC_GROUP_ID` END ASC
		
	-- LIMIT & OFFSET
	-- ####################################################		
	LIMIT PARAM_SKIP, PARAM_LIMIT;
	
	
	
	-- EXIT PROCEDURE
	-- =========================================================================================
	LEAVE SP_GET;
			
END ;;
DELIMITER ;
/*!50003 SET sql_mode              = @saved_sql_mode */ ;
/*!50003 SET character_set_client  = @saved_cs_client */ ;
/*!50003 SET character_set_results = @saved_cs_results */ ;
/*!50003 SET collation_connection  = @saved_col_connection */ ;
/*!50003 DROP PROCEDURE IF EXISTS `ADDON_LICENSE_GROUP_SAVE` */;
/*!50003 SET @saved_cs_client      = @@character_set_client */ ;
/*!50003 SET @saved_cs_results     = @@character_set_results */ ;
/*!50003 SET @saved_col_connection = @@collation_connection */ ;
/*!50003 SET character_set_client  = latin1 */ ;
/*!50003 SET character_set_results = latin1 */ ;
/*!50003 SET collation_connection  = latin1_swedish_ci */ ;
/*!50003 SET @saved_sql_mode       = @@sql_mode */ ;
/*!50003 SET sql_mode              = '' */ ;
DELIMITER ;;
CREATE DEFINER=`root`@`localhost` PROCEDURE `ADDON_LICENSE_GROUP_SAVE`(
	IN `PARAM_ADD_GLICENSE_ID` BIGINT,
	IN `PARAM_ADD_GLICENSE_ACC_GROUP_ID` BIGINT,
	IN `PARAM_ADD_GLICENSE_DATE_RENEW` DATETIME(6),
	IN `PARAM_ADD_GLICENSE_DATE_EXPIRY` DATETIME(6),
	IN `PARAM_ADD_GLICENSE_VOLUME` BIGINT,
	IN `PARAM_ADD_GLICENSE_STATUS` TINYINT,

	IN `PARAM_REQUESTER_USERNAME` VARCHAR(500),
	IN `PARAM_REQUESTER_PASSWORD` VARCHAR(500),
	IN `PARAM_REQUESTER_PROXY_ID` BIGINT,
	IN `PARAM_REQUESTER_PROXY_PASSWORD` VARCHAR(1000),
	IN `PARAM_REQUESTER_DEVICE_PUBLIC_KEY` VARCHAR(1000),
	IN `PARAM_REQUESTER_DEVICE_PRIVATE_KEY` VARCHAR(1000),
	
	IN `PARAM_REQUESTER_IP` VARCHAR(1000),
	IN `PARAM_UNIQUE_SESSION_ID` VARCHAR(1000),
	IN `PARAM_SUPPRESS_RETURN` BIT,
	
	IN `PARAM_SYNC_SERVER_DESCRIPTION` VARCHAR(500), 
	IN `PARAM_SYNC_SERVER_UNIQUE_KEY` VARCHAR(500)
)
SP_SAVE:
BEGIN


	-- 1) DECLARE LOCAL PARAMETERS
	-- _______________________________________________________________________
	
	-- Status
	-- ...........................................
	DECLARE STATUS_INACTIVE TINYINT DEFAULT 1;
	DECLARE STATUS_ACTIVE TINYINT DEFAULT 2;
	DECLARE STATUS_CLOSED TINYINT DEFAULT 3;
	DECLARE STATUS_COMPLETED TINYINT DEFAULT 4;

	-- Audit Handler
	-- ...........................................
	DECLARE TEMP_RECORD_EXISTS BIT DEFAULT 0;
	DECLARE TEMP_MODULE_KEYWORD VARCHAR(500) DEFAULT 'addon_license_group';
	DECLARE TEMP_SP_OBJECTIVE VARCHAR(500) DEFAULT 'add/edit Group License record';
	DECLARE TEMP_ERR_MESSAGE VARCHAR(500) DEFAULT '';
	DECLARE ERR BIGINT DEFAULT 0;
	DECLARE TEMP_RECORD_CHANGES VARCHAR(16000) DEFAULT '';
	DECLARE TEMP_RECORD_BINDED BIT DEFAULT 0;

	-- Authentication
	-- ...........................................
	DECLARE TEMP_ACCESS_RIGHTS_DENIED BIT DEFAULT 0;
	DECLARE TEMP_ACCESS_RIGHTS_HAS_OVERRIDE BIT DEFAULT 0;
	DECLARE TEMP_SYNC_SERVER_ID BIGINT DEFAULT 0;
	DECLARE TEMP_SYNC_IS_SERVER_REQUEST BIT DEFAULT 0;
	DECLARE TEMP_AUTHENTICATED_ACCOUNT_ID BIGINT DEFAULT `ACCOUNT_MEMBER@ACC_ACCOUNT_ID_FROM_LOGIN`(PARAM_REQUESTER_USERNAME, PARAM_REQUESTER_PASSWORD);
	DECLARE TEMP_AUTHENTICATED_ACCOUNT_LEVEL BIGINT DEFAULT 0;
	DECLARE TEMP_AUTHENTICATED_ACCOUNT_GROUP BIGINT DEFAULT 0;
	
	-- Local Parameters
	-- ...........................................
	DECLARE TEMP_NOW DATETIME(6) DEFAULT `SYSTEM_VAR@NOW`('', 1);
	DECLARE TEMP_RECORD_COUNT BIGINT DEFAULT 0;

	-- AutoGen Parameters
	-- ...........................................
	DECLARE PARAM_ADD_GLICENSE_SYSTEM_GENERATED TINYINT DEFAULT 0; 
	
	-- Local value holder
	-- ...........................................
	DECLARE TEMP_ADD_GLICENSE_ACC_GROUP_ID BIGINT DEFAULT 0; 
	DECLARE TEMP_ADD_GLICENSE_DATE_RENEW DATETIME(6) DEFAULT '1000-01-01 00:00:00.000000'; 
	DECLARE TEMP_ADD_GLICENSE_DATE_EXPIRY DATETIME(6) DEFAULT '1000-01-01 00:00:00.000000'; 
	DECLARE TEMP_ADD_GLICENSE_VOLUME BIGINT DEFAULT 0; 
	DECLARE TEMP_ADD_GLICENSE_STATUS TINYINT DEFAULT 0; 
	DECLARE TEMP_ADD_GLICENSE_SYSTEM_GENERATED TINYINT DEFAULT 0; 
	


	-- 2) Try Catch / Throw
	-- _______________________________________________________________________
	DECLARE EXIT HANDLER FOR SQLEXCEPTION
	BEGIN
		RESIGNAL;
	END;



	-- 3) Prepare SYNC
	-- _______________________________________________________________________

	-- IS RECORD EXISTS		
	-- ####################################################	
	SET TEMP_RECORD_EXISTS = `ADDON_LICENSE_GROUP@ADD_GLICENSE_ID_EXISTS`(PARAM_ADD_GLICENSE_ID, 0);

		
		
	-- 4) PREPARE AUTOGEN DATA (IF EXISTS)
	-- _______________________________________________________________________
	IF TEMP_SYNC_IS_SERVER_REQUEST = 0 THEN
		-- Just to keep at least one line within condition
		SET TEMP_SYNC_IS_SERVER_REQUEST = 0;
		
		-- Actual Functionalities here
		-- USE DEFAULT VALUE (String)
		-- USE DEFAULT VALUE (String)
		SET PARAM_ADD_GLICENSE_SYSTEM_GENERATED = 1;
	-- USE TIMESTAMP
	END IF;



	-- 5) IF ALREADY EXIST, FILL MISSING DATA
	-- _______________________________________________________________________
	IF TEMP_RECORD_EXISTS = 1 THEN
		SELECT
			`addon_license_group`.`ADD_GLICENSE_ACC_GROUP_ID`, 	
			`addon_license_group`.`ADD_GLICENSE_DATE_RENEW`, 	
			`addon_license_group`.`ADD_GLICENSE_DATE_EXPIRY`, 	
			`addon_license_group`.`ADD_GLICENSE_VOLUME`, 	
			`addon_license_group`.`ADD_GLICENSE_STATUS`, 	
			`addon_license_group`.`ADD_GLICENSE_SYSTEM_GENERATED`	
		INTO
			TEMP_ADD_GLICENSE_ACC_GROUP_ID, 	
			TEMP_ADD_GLICENSE_DATE_RENEW, 	
			TEMP_ADD_GLICENSE_DATE_EXPIRY, 	
			TEMP_ADD_GLICENSE_VOLUME, 	
			TEMP_ADD_GLICENSE_STATUS, 	
			TEMP_ADD_GLICENSE_SYSTEM_GENERATED	

		FROM `addon_license_group`
		WHERE
			`addon_license_group`.`ADD_GLICENSE_ID` = PARAM_ADD_GLICENSE_ID
		LIMIT 1;

		-- Replace NULLs with the existing data.
		SET PARAM_ADD_GLICENSE_ACC_GROUP_ID = `SYSTEM_VAR@REPLACE_NULL@BIGINT`(PARAM_ADD_GLICENSE_ACC_GROUP_ID, TEMP_ADD_GLICENSE_ACC_GROUP_ID, 1, 1);
		SET PARAM_ADD_GLICENSE_DATE_RENEW = `SYSTEM_VAR@REPLACE_NULL@DATETIME`(PARAM_ADD_GLICENSE_DATE_RENEW, TEMP_ADD_GLICENSE_DATE_RENEW, 1);
		SET PARAM_ADD_GLICENSE_DATE_EXPIRY = `SYSTEM_VAR@REPLACE_NULL@DATETIME`(PARAM_ADD_GLICENSE_DATE_EXPIRY, TEMP_ADD_GLICENSE_DATE_EXPIRY, 1);
		SET PARAM_ADD_GLICENSE_VOLUME = `SYSTEM_VAR@REPLACE_NULL@BIGINT`(PARAM_ADD_GLICENSE_VOLUME, TEMP_ADD_GLICENSE_VOLUME, 0, 1);
		SET PARAM_ADD_GLICENSE_STATUS = `SYSTEM_VAR@REPLACE_NULL@TINYINT`(PARAM_ADD_GLICENSE_STATUS, TEMP_ADD_GLICENSE_STATUS, 1, 1);
		
		-- NON-UPDATABLE
		
		-- NON-UPDATABLE BUT NULL
		
		-- AUTO GEN (NON-UPDATABLES)		
		SET PARAM_ADD_GLICENSE_SYSTEM_GENERATED = TEMP_ADD_GLICENSE_SYSTEM_GENERATED;
		
		-- AUTO GEN (UPDATABLE WITH STATUS CHANGE)

		-- AUTO GEN (UPDATABLE WITH STATUS [ACTIVE/INACTIVE] CHANGE)
		
	ELSE
		SET PARAM_ADD_GLICENSE_ACC_GROUP_ID = `SYSTEM_VAR@REPLACE_NULL@BIGINT`(PARAM_ADD_GLICENSE_ACC_GROUP_ID, 0, 1, 1);
		SET PARAM_ADD_GLICENSE_DATE_RENEW = `SYSTEM_VAR@REPLACE_NULL@DATETIME`(PARAM_ADD_GLICENSE_DATE_RENEW, '1000-01-01 00:00:00.000000', 1);
		SET PARAM_ADD_GLICENSE_DATE_EXPIRY = `SYSTEM_VAR@REPLACE_NULL@DATETIME`(PARAM_ADD_GLICENSE_DATE_EXPIRY, '1000-01-01 00:00:00.000000', 1);
		SET PARAM_ADD_GLICENSE_VOLUME = `SYSTEM_VAR@REPLACE_NULL@BIGINT`(PARAM_ADD_GLICENSE_VOLUME, 0, 0, 1);
		SET PARAM_ADD_GLICENSE_STATUS = `SYSTEM_VAR@REPLACE_NULL@TINYINT`(PARAM_ADD_GLICENSE_STATUS, 0, 1, 1);
		
	END IF;

	

	-- 6) PREPARE AUDIT TRAIL
	-- _______________________________________________________________________
	IF TEMP_ADD_GLICENSE_ACC_GROUP_ID <> PARAM_ADD_GLICENSE_ACC_GROUP_ID THEN
		SET TEMP_RECORD_CHANGES = 
		`SYSTEM_VAR@CONCAT_ADD`(' | ', TEMP_RECORD_CHANGES, CONCAT_WS(' ', 'Group: "', TEMP_ADD_GLICENSE_ACC_GROUP_ID, '" > "', PARAM_ADD_GLICENSE_ACC_GROUP_ID, '"'));
	END IF;	
	IF BINARY TEMP_ADD_GLICENSE_DATE_RENEW <> PARAM_ADD_GLICENSE_DATE_RENEW THEN
		SET TEMP_RECORD_CHANGES = 
		`SYSTEM_VAR@CONCAT_ADD`(' | ', TEMP_RECORD_CHANGES, CONCAT_WS(' ', 'Renewal date: "', TEMP_ADD_GLICENSE_DATE_RENEW, '" > "', PARAM_ADD_GLICENSE_DATE_RENEW, '"'));
	END IF;
	IF BINARY TEMP_ADD_GLICENSE_DATE_EXPIRY <> PARAM_ADD_GLICENSE_DATE_EXPIRY THEN
		SET TEMP_RECORD_CHANGES = 
		`SYSTEM_VAR@CONCAT_ADD`(' | ', TEMP_RECORD_CHANGES, CONCAT_WS(' ', 'Expiry Date: "', TEMP_ADD_GLICENSE_DATE_EXPIRY, '" > "', PARAM_ADD_GLICENSE_DATE_EXPIRY, '"'));
	END IF;
	IF TEMP_ADD_GLICENSE_VOLUME <> PARAM_ADD_GLICENSE_VOLUME THEN
		SET TEMP_RECORD_CHANGES = 
		`SYSTEM_VAR@CONCAT_ADD`(' | ', TEMP_RECORD_CHANGES, CONCAT_WS(' ', 'License Volume: "', TEMP_ADD_GLICENSE_VOLUME, '" > "', PARAM_ADD_GLICENSE_VOLUME, '"'));
	END IF;	
	IF TEMP_ADD_GLICENSE_STATUS <> PARAM_ADD_GLICENSE_STATUS THEN
		SET TEMP_RECORD_CHANGES = 
		`SYSTEM_VAR@CONCAT_ADD`(' | ', TEMP_RECORD_CHANGES, CONCAT_WS(' ', 'Status: "', TEMP_ADD_GLICENSE_STATUS, '" > "', PARAM_ADD_GLICENSE_STATUS, '"'));
	END IF;	
	IF TEMP_ADD_GLICENSE_SYSTEM_GENERATED <> PARAM_ADD_GLICENSE_SYSTEM_GENERATED THEN
		SET TEMP_RECORD_CHANGES = 
		`SYSTEM_VAR@CONCAT_ADD`(' | ', TEMP_RECORD_CHANGES, CONCAT_WS(' ', 'System Generated: "', TEMP_ADD_GLICENSE_SYSTEM_GENERATED, '" > "', PARAM_ADD_GLICENSE_SYSTEM_GENERATED, '"'));
	END IF;	
		
	-- No Changes in data, reject request
	-- ####################################################
	IF CHARACTER_LENGTH(TEMP_RECORD_CHANGES) = 0 THEN
		IF PARAM_SUPPRESS_RETURN = 0 THEN
			SELECT PARAM_ADD_GLICENSE_ID AS INSERTED_ID;
		END IF;
		LEAVE SP_SAVE;
	END IF;



	-- 7) VALIDATE
	-- _______________________________________________________________________

	-- Access Rights [Device]
	-- ####################################################
	IF `ACCOUNT_DEVICE@HAS_PERMISSION`(PARAM_REQUESTER_DEVICE_PUBLIC_KEY, PARAM_REQUESTER_DEVICE_PRIVATE_KEY) = 0 THEN
		SET TEMP_ERR_MESSAGE = 'Your device is not authorized yet to access this server.';
		SET ERR = `RAISERROR`(TEMP_ERR_MESSAGE);		
	END IF;
		
		
	-- Access Rights [Account]
	-- ####################################################
	-- Check if accessing a record outside own group.
	SET TEMP_AUTHENTICATED_ACCOUNT_GROUP = `ACCOUNT_MEMBER@ACC_ACCOUNT_GROUP_FROM_LOGIN`(PARAM_REQUESTER_USERNAME, PARAM_REQUESTER_PASSWORD);
	IF TEMP_AUTHENTICATED_ACCOUNT_GROUP <> PARAM_ADD_GLICENSE_ACC_GROUP_ID THEN
		IF `ACCOUNT_ACCESS_RIGHTS@HAS_PERMISSION`(PARAM_REQUESTER_USERNAME, PARAM_REQUESTER_PASSWORD, 0, TEMP_MODULE_KEYWORD, 4) = 0 THEN
			SET TEMP_ACCESS_RIGHTS_DENIED = 1;
			CALL `ACCOUNT_ACCESS_RIGHTS_DENY`
			(
				0, TEMP_MODULE_KEYWORD, 0, 0, TEMP_SP_OBJECTIVE, TEMP_RECORD_CHANGES, 
				PARAM_REQUESTER_USERNAME, PARAM_REQUESTER_PASSWORD, 
				PARAM_REQUESTER_PROXY_ID, PARAM_REQUESTER_PROXY_PASSWORD,
				PARAM_REQUESTER_DEVICE_PUBLIC_KEY, PARAM_REQUESTER_DEVICE_PRIVATE_KEY,
				PARAM_REQUESTER_IP, PARAM_UNIQUE_SESSION_ID,
				0, PARAM_SUPPRESS_RETURN
			);
		END IF;					
	END IF;
	
	IF 
		-- [ADD] Access Rights
		(
			TEMP_RECORD_EXISTS = 0 AND
			`ACCOUNT_ACCESS_RIGHTS@HAS_PERMISSION`(PARAM_REQUESTER_USERNAME, PARAM_REQUESTER_PASSWORD, 0, TEMP_MODULE_KEYWORD, 2) = 0 
		) OR
		
		-- [EDIT] Access Rights
		(
			TEMP_RECORD_EXISTS = 1 AND
			`ACCOUNT_ACCESS_RIGHTS@HAS_PERMISSION`(PARAM_REQUESTER_USERNAME, PARAM_REQUESTER_PASSWORD, 0, TEMP_MODULE_KEYWORD, 3) = 0 
		)
	THEN
		SET TEMP_ACCESS_RIGHTS_DENIED = 1;
		CALL `ACCOUNT_ACCESS_RIGHTS_DENY`
		(
			0, TEMP_MODULE_KEYWORD, PARAM_ADD_GLICENSE_ID, 0, TEMP_SP_OBJECTIVE, TEMP_RECORD_CHANGES, 
			PARAM_REQUESTER_USERNAME, PARAM_REQUESTER_PASSWORD, 
			PARAM_REQUESTER_PROXY_ID, PARAM_REQUESTER_PROXY_PASSWORD,
			PARAM_REQUESTER_DEVICE_PUBLIC_KEY, PARAM_REQUESTER_DEVICE_PRIVATE_KEY,
			PARAM_REQUESTER_IP, PARAM_UNIQUE_SESSION_ID,
			TEMP_SYNC_SERVER_ID, PARAM_SUPPRESS_RETURN
		);
	END IF;
	SET TEMP_ACCESS_RIGHTS_HAS_OVERRIDE = `ACCOUNT_ACCESS_RIGHTS@HAS_PERMISSION`(PARAM_REQUESTER_USERNAME, PARAM_REQUESTER_PASSWORD, 0, TEMP_MODULE_KEYWORD, 4);
	

	-- Validation
	-- ####################################################
	IF TEMP_SYNC_IS_SERVER_REQUEST = 0 THEN
	
		-- SYSTEM GENERATED = TRUE
		-- ...........................................
		IF TEMP_ADD_GLICENSE_SYSTEM_GENERATED = STATUS_ACTIVE THEN
		CALL `VALIDATION_SYSTEM_GENERATED`
		(
			PARAM_ADD_GLICENSE_ID,
			TEMP_ADD_GLICENSE_ACC_GROUP_ID, ''
		);
		END IF;

		-- FOREIGN KEY EXISTS
		-- ...........................................
		IF `ACCOUNT_GROUP@ACC_GROUP_ID_EXISTS`(PARAM_ADD_GLICENSE_ACC_GROUP_ID, 0) =  0 THEN
			SET TEMP_ERR_MESSAGE = CONCAT_WS(' ', 'Given Group does not exists or is inactive. ID: ', PARAM_ADD_GLICENSE_ACC_GROUP_ID);
			SET ERR = `RAISERROR`(TEMP_ERR_MESSAGE);
		END IF;
		
		-- FOREIGN (OPTIONAL)KEY EXISTS [Validates if not null]
		-- ...........................................
		
		-- IS_ALLOW_NULL = FALSE
		-- ...........................................
				
		-- IS_ALLOW_ZERO = FALSE
		-- ...........................................
		IF PARAM_ADD_GLICENSE_STATUS = 0 THEN
			CALL `VALIDATION_MISSING_FIELD`('`ADD_GLICENSE_STATUS`', '`NULL`');
		END IF;		
		IF PARAM_ADD_GLICENSE_SYSTEM_GENERATED = 0 THEN
			CALL `VALIDATION_MISSING_FIELD`('`ADD_GLICENSE_SYSTEM_GENERATED`', '`NULL`');
		END IF;		
		
		-- IS_ALLOW_NEGATIVE = FALSE
		-- ...........................................
		IF PARAM_ADD_GLICENSE_VOLUME < 0 THEN
			CALL `VALIDATION_NEGATIVE`('`ADD_GLICENSE_VOLUME`', PARAM_ADD_GLICENSE_VOLUME);
		END IF;		
		IF PARAM_ADD_GLICENSE_STATUS < 0 THEN
			CALL `VALIDATION_NEGATIVE`('`ADD_GLICENSE_STATUS`', PARAM_ADD_GLICENSE_STATUS);
		END IF;		
		IF PARAM_ADD_GLICENSE_SYSTEM_GENERATED < 0 THEN
			CALL `VALIDATION_NEGATIVE`('`ADD_GLICENSE_SYSTEM_GENERATED`', PARAM_ADD_GLICENSE_SYSTEM_GENERATED);
		END IF;		
		
		-- IS_ALLOW_EMPTY_STRING = FALSE
		-- ...........................................
		IF `SYSTEM_VAR@IS_NULL@DATETIME`(PARAM_ADD_GLICENSE_DATE_RENEW, 1) = 1 THEN
			CALL `VALIDATION_MISSING_FIELD`('`ADD_GLICENSE_DATE_RENEW`', '`NULL`');
		END IF;
		IF `SYSTEM_VAR@IS_NULL@DATETIME`(PARAM_ADD_GLICENSE_DATE_EXPIRY, 1) = 1 THEN
			CALL `VALIDATION_MISSING_FIELD`('`ADD_GLICENSE_DATE_EXPIRY`', '`NULL`');
		END IF;
		
		-- IS_STATUS
		-- ...........................................
		IF `SYSTEM_STATUS@SYS_STATUS_ID_EXISTS`(PARAM_ADD_GLICENSE_STATUS, 0) = 0 THEN
			SET TEMP_ERR_MESSAGE = CONCAT_WS(' ', 'Given STATUS[Status] does not exists or is inactive. ID: ', PARAM_ADD_GLICENSE_STATUS);
			SET ERR = `RAISERROR`(TEMP_ERR_MESSAGE);
		END IF;
		
		-- IS STATUS Active / Inactive
		-- ...........................................
		
		-- Minimum / Maximum Value
		-- ...........................................
		
		-- IS_UNIQUE = TRUE
		-- ...........................................
		IF
		(
			SELECT COUNT(`addon_license_group`.`ADD_GLICENSE_ID`)
			FROM `addon_license_group`
			WHERE		
				`addon_license_group`.`ADD_GLICENSE_ACC_GROUP_ID` = PARAM_ADD_GLICENSE_ACC_GROUP_ID AND		
				`addon_license_group`.`ADD_GLICENSE_ID` <> PARAM_ADD_GLICENSE_ID
		) >= 1
		THEN
			CALL `VALIDATION_REDUNDANT_ENTRY`(PARAM_ADD_GLICENSE_ACC_GROUP_ID);
		END IF;
		
		-- RECORD IDENTIFIER
		-- ...........................................
		
		
		-- ON_UPDATE VALIDATION 
		-- ...........................................
		IF TEMP_RECORD_EXISTS = 1 THEN	
		
			-- Just to keep at least one line within condition
			SET TEMP_RECORD_EXISTS = 1;
			
		END IF;
		
	END IF;



	-- 8) INSERT / UPDATE
	-- _______________________________________________________________________

	-- INSERT NEW DATA
	-- ####################################################
	IF TEMP_RECORD_EXISTS = 0 THEN

		INSERT INTO
		`addon_license_group`
		(
			`addon_license_group`.`ADD_GLICENSE_ACC_GROUP_ID`, 
			`addon_license_group`.`ADD_GLICENSE_DATE_RENEW`, 
			`addon_license_group`.`ADD_GLICENSE_DATE_EXPIRY`, 
			`addon_license_group`.`ADD_GLICENSE_VOLUME`, 
			`addon_license_group`.`ADD_GLICENSE_STATUS`, 
			`addon_license_group`.`ADD_GLICENSE_SYSTEM_GENERATED`
		)
		VALUES
		(
			PARAM_ADD_GLICENSE_ACC_GROUP_ID, 
			PARAM_ADD_GLICENSE_DATE_RENEW, 
			PARAM_ADD_GLICENSE_DATE_EXPIRY, 
			PARAM_ADD_GLICENSE_VOLUME, 
			PARAM_ADD_GLICENSE_STATUS, 
			PARAM_ADD_GLICENSE_SYSTEM_GENERATED
		);	
		
		-- Update Audit trail with new ID	
		SET PARAM_ADD_GLICENSE_ID = LAST_INSERT_ID();



	-- UPDATING EXISTING RECORD
	-- ####################################################
	ELSE
		UPDATE `addon_license_group`
		SET
			`addon_license_group`.`ADD_GLICENSE_ACC_GROUP_ID` = PARAM_ADD_GLICENSE_ACC_GROUP_ID, 
			`addon_license_group`.`ADD_GLICENSE_DATE_RENEW` = PARAM_ADD_GLICENSE_DATE_RENEW, 
			`addon_license_group`.`ADD_GLICENSE_DATE_EXPIRY` = PARAM_ADD_GLICENSE_DATE_EXPIRY, 
			`addon_license_group`.`ADD_GLICENSE_VOLUME` = PARAM_ADD_GLICENSE_VOLUME, 
			`addon_license_group`.`ADD_GLICENSE_STATUS` = PARAM_ADD_GLICENSE_STATUS, 
			`addon_license_group`.`ADD_GLICENSE_SYSTEM_GENERATED` = PARAM_ADD_GLICENSE_SYSTEM_GENERATED
		WHERE
			`addon_license_group`.`ADD_GLICENSE_ID` = PARAM_ADD_GLICENSE_ID;

	END IF;

	
	-- 9) AUDIT TRAIL
	-- _______________________________________________________________________
	CALL `ACCOUNT_AUDIT_TRAIL_SAVE`
	(
		0, TEMP_MODULE_KEYWORD, PARAM_ADD_GLICENSE_ID, 0, 'SAVE', TEMP_SP_OBJECTIVE, TEMP_RECORD_CHANGES, 
		PARAM_REQUESTER_USERNAME, PARAM_REQUESTER_PASSWORD, 
		PARAM_REQUESTER_PROXY_ID, PARAM_REQUESTER_PROXY_PASSWORD,
		PARAM_REQUESTER_DEVICE_PUBLIC_KEY, PARAM_REQUESTER_DEVICE_PRIVATE_KEY,
		PARAM_REQUESTER_IP, PARAM_UNIQUE_SESSION_ID,
		TEMP_SYNC_SERVER_ID, PARAM_SUPPRESS_RETURN
	);
	

	-- 10) RETURN RESULT
	-- _______________________________________________________________________
	IF PARAM_SUPPRESS_RETURN = 0 THEN
		SELECT 
			PARAM_ADD_GLICENSE_ID AS INSERTED_ID,
			TEMP_NOW AS SERVER_TIME;
	END IF;
	LEAVE SP_SAVE;


END ;;
DELIMITER ;
/*!50003 SET sql_mode              = @saved_sql_mode */ ;
/*!50003 SET character_set_client  = @saved_cs_client */ ;
/*!50003 SET character_set_results = @saved_cs_results */ ;
/*!50003 SET collation_connection  = @saved_col_connection */ ;
/*!50003 DROP PROCEDURE IF EXISTS `ADDON_LICENSE_USER_DELETE` */;
/*!50003 SET @saved_cs_client      = @@character_set_client */ ;
/*!50003 SET @saved_cs_results     = @@character_set_results */ ;
/*!50003 SET @saved_col_connection = @@collation_connection */ ;
/*!50003 SET character_set_client  = latin1 */ ;
/*!50003 SET character_set_results = latin1 */ ;
/*!50003 SET collation_connection  = latin1_swedish_ci */ ;
/*!50003 SET @saved_sql_mode       = @@sql_mode */ ;
/*!50003 SET sql_mode              = '' */ ;
DELIMITER ;;
CREATE DEFINER=`root`@`localhost` PROCEDURE `ADDON_LICENSE_USER_DELETE`(
	IN `PARAM_ADD_ULICENSE_ID` BIGINT,

	IN `PARAM_REQUESTER_USERNAME` VARCHAR(500),
	IN `PARAM_REQUESTER_PASSWORD` VARCHAR(500),
	IN `PARAM_REQUESTER_PROXY_ID` BIGINT,
	IN `PARAM_REQUESTER_PROXY_PASSWORD` VARCHAR(1000),
	IN `PARAM_REQUESTER_DEVICE_PUBLIC_KEY` VARCHAR(1000),
	IN `PARAM_REQUESTER_DEVICE_PRIVATE_KEY` VARCHAR(1000),
	
	IN `PARAM_REQUESTER_IP` VARCHAR(1000),
	IN `PARAM_UNIQUE_SESSION_ID` VARCHAR(1000),
	IN `PARAM_SUPPRESS_RETURN` BIT,
	
	IN `PARAM_SYNC_SERVER_DESCRIPTION` VARCHAR(500), 
	IN `PARAM_SYNC_SERVER_UNIQUE_KEY` VARCHAR(500)
)
SP_DELETE:
BEGIN

	-- 1) DECLARE LOCAL PARAMETERS
	-- _______________________________________________________________________
	
	-- Status
	-- ...........................................
	DECLARE STATUS_INACTIVE TINYINT DEFAULT 1;
	DECLARE STATUS_ACTIVE TINYINT DEFAULT 2;
	DECLARE STATUS_CLOSED TINYINT DEFAULT 3;
	DECLARE STATUS_COMPLETED TINYINT DEFAULT 4;
	
	-- Audit Handler
	-- ...........................................
	DECLARE TEMP_RECORD_EXISTS BIT DEFAULT 0;
	DECLARE TEMP_MODULE_KEYWORD VARCHAR(500) DEFAULT 'addon_license_user';
	DECLARE TEMP_SP_OBJECTIVE VARCHAR(500) DEFAULT 'delete User License record';
	DECLARE TEMP_ERR_MESSAGE VARCHAR(500) DEFAULT '';
	DECLARE ERR BIGINT DEFAULT 0;
	DECLARE TEMP_RECORD_CHANGES VARCHAR(16000) DEFAULT '';
	DECLARE TEMP_RECORD_BINDED BIT DEFAULT 0;
	
	DECLARE TEMP_RECORD_BINDED_ID BIGINT DEFAULT 0;
	DECLARE TEMP_RECORD_BINDED_SERVER_ID BIGINT DEFAULT 0;
	
	-- Authentication
	-- ...........................................
	DECLARE TEMP_ACCESS_RIGHTS_DENIED BIT DEFAULT 0;
	DECLARE TEMP_SYNC_SERVER_ID BIGINT DEFAULT 0;
	DECLARE TEMP_SYNC_IS_SERVER_REQUEST BIT DEFAULT 0;
	DECLARE TEMP_AUTHENTICATED_ACCOUNT_ID BIGINT DEFAULT `ACCOUNT_MEMBER@ACC_ACCOUNT_ID_FROM_LOGIN`(PARAM_REQUESTER_USERNAME, PARAM_REQUESTER_PASSWORD);
	DECLARE TEMP_AUTHENTICATED_ACCOUNT_LEVEL BIGINT DEFAULT 0;
	DECLARE TEMP_AUTHENTICATED_ACCOUNT_GROUP BIGINT DEFAULT 0;

	-- Local value holder
	-- ...........................................
		DECLARE TEMP_ADD_ULICENSE_ACC_ACCOUNT_ID BIGINT DEFAULT 0; 
		DECLARE TEMP_ADD_ULICENSE_DATE_RENEW DATETIME(6) DEFAULT '1000-01-01 00:00:00.000000'; 
		DECLARE TEMP_ADD_ULICENSE_DATE_EXPIRY DATETIME(6) DEFAULT '1000-01-01 00:00:00.000000'; 
		DECLARE TEMP_ADD_ULICENSE_VOLUME BIGINT DEFAULT 0; 
		DECLARE TEMP_ADD_ULICENSE_STATUS TINYINT DEFAULT 0; 
		DECLARE TEMP_ADD_ULICENSE_SYSTEM_GENERATED TINYINT DEFAULT 0; 

	
	
	-- 2) Try Catch / Throw
	-- _______________________________________________________________________
	DECLARE EXIT HANDLER FOR SQLEXCEPTION
	BEGIN
		RESIGNAL;
	END;

	
	-- 3) Prepare SYNC
	-- _______________________________________________________________________
	
	-- IS RECORD EXISTS		
	-- ####################################################		
	SET TEMP_RECORD_EXISTS = `ADDON_LICENSE_USER@ADD_ULICENSE_ID_EXISTS`(PARAM_ADD_ULICENSE_ID, 0);


	-- 4) IF ALREADY EXIST, FILL MISSING DATA
	-- _______________________________________________________________________
	IF TEMP_RECORD_EXISTS = 1 THEN
		SELECT
				`addon_license_user`.`ADD_ULICENSE_ACC_ACCOUNT_ID`, 	
				`addon_license_user`.`ADD_ULICENSE_DATE_RENEW`, 	
				`addon_license_user`.`ADD_ULICENSE_DATE_EXPIRY`, 	
				`addon_license_user`.`ADD_ULICENSE_VOLUME`, 	
				`addon_license_user`.`ADD_ULICENSE_STATUS`, 	
				`addon_license_user`.`ADD_ULICENSE_SYSTEM_GENERATED`	
		INTO
				TEMP_ADD_ULICENSE_ACC_ACCOUNT_ID, 	
				TEMP_ADD_ULICENSE_DATE_RENEW, 	
				TEMP_ADD_ULICENSE_DATE_EXPIRY, 	
				TEMP_ADD_ULICENSE_VOLUME, 	
				TEMP_ADD_ULICENSE_STATUS, 	
				TEMP_ADD_ULICENSE_SYSTEM_GENERATED	

		FROM `addon_license_user`
		WHERE
			`addon_license_user`.`ADD_ULICENSE_ID` = PARAM_ADD_ULICENSE_ID
		LIMIT 1;

	ELSE 
		IF TEMP_SYNC_IS_SERVER_REQUEST = 0 THEN
			SET TEMP_ERR_MESSAGE = CONCAT_WS(' ', 'Given User License does not exists or is inactive. ID:', PARAM_ADD_ULICENSE_ID);
			SET ERR = `RAISERROR`(TEMP_ERR_MESSAGE);		
		END IF;
		LEAVE SP_DELETE;
		
	END IF;



	-- 5) PREPARE AUDIT TRAIL
	-- _______________________________________________________________________
	
		SET TEMP_RECORD_CHANGES = 
		`SYSTEM_VAR@CONCAT_ADD`(' | ', TEMP_RECORD_CHANGES, CONCAT_WS(' ', 'User Account: "', TEMP_ADD_ULICENSE_ACC_ACCOUNT_ID, '" > " DELETED "'));
		SET TEMP_RECORD_CHANGES = 
		`SYSTEM_VAR@CONCAT_ADD`(' | ', TEMP_RECORD_CHANGES, CONCAT_WS(' ', 'Renewal Date: "', TEMP_ADD_ULICENSE_DATE_RENEW, '" > " DELETED "'));
		SET TEMP_RECORD_CHANGES = 
		`SYSTEM_VAR@CONCAT_ADD`(' | ', TEMP_RECORD_CHANGES, CONCAT_WS(' ', 'Expiry Date: "', TEMP_ADD_ULICENSE_DATE_EXPIRY, '" > " DELETED "'));
		SET TEMP_RECORD_CHANGES = 
		`SYSTEM_VAR@CONCAT_ADD`(' | ', TEMP_RECORD_CHANGES, CONCAT_WS(' ', 'Volume: "', TEMP_ADD_ULICENSE_VOLUME, '" > " DELETED "'));
		SET TEMP_RECORD_CHANGES = 
		`SYSTEM_VAR@CONCAT_ADD`(' | ', TEMP_RECORD_CHANGES, CONCAT_WS(' ', 'Status: "', TEMP_ADD_ULICENSE_STATUS, '" > " DELETED "'));
		SET TEMP_RECORD_CHANGES = 
		`SYSTEM_VAR@CONCAT_ADD`(' | ', TEMP_RECORD_CHANGES, CONCAT_WS(' ', 'System Generated: "', TEMP_ADD_ULICENSE_SYSTEM_GENERATED, '" > " DELETED "'));


	-- 6) VALIDATE
	-- _______________________________________________________________________
	
	-- Access Rights [Device]
	-- ####################################################
	IF `ACCOUNT_DEVICE@HAS_PERMISSION`(PARAM_REQUESTER_DEVICE_PUBLIC_KEY, PARAM_REQUESTER_DEVICE_PRIVATE_KEY) = 0 THEN
		SET TEMP_ERR_MESSAGE = 'Your device is not authorized yet to access this server.';
		SET ERR = `RAISERROR`(TEMP_ERR_MESSAGE);		
	END IF;
		
		
	-- Access Rights [Account]
	-- ####################################################	
	
	IF 
		-- [DELETE] Access Rights
		`ACCOUNT_ACCESS_RIGHTS@HAS_PERMISSION`(PARAM_REQUESTER_USERNAME, PARAM_REQUESTER_PASSWORD, 0, TEMP_MODULE_KEYWORD, 4) = 0 
	THEN
		SET TEMP_ACCESS_RIGHTS_DENIED = 1;
		CALL `ACCOUNT_ACCESS_RIGHTS_DENY`
		(
			0, TEMP_MODULE_KEYWORD, PARAM_ADD_ULICENSE_ID, 0, TEMP_SP_OBJECTIVE, TEMP_RECORD_CHANGES, 
			PARAM_REQUESTER_USERNAME, PARAM_REQUESTER_PASSWORD, 
			PARAM_REQUESTER_PROXY_ID, PARAM_REQUESTER_PROXY_PASSWORD,
			PARAM_REQUESTER_DEVICE_PUBLIC_KEY, PARAM_REQUESTER_DEVICE_PRIVATE_KEY,
			PARAM_REQUESTER_IP, PARAM_UNIQUE_SESSION_ID,
			TEMP_SYNC_SERVER_ID, PARAM_SUPPRESS_RETURN
		);
	END IF;

	-- System Generated Record (Cannot be deleted)
	-- ####################################################
	IF TEMP_ADD_ULICENSE_SYSTEM_GENERATED = STATUS_ACTIVE THEN
		CALL `VALIDATION_SYSTEM_GENERATED`
		(
			PARAM_ADD_ULICENSE_ID,
			TEMP_ADD_ULICENSE_ACC_ACCOUNT_ID, ''
		);
	END IF;
	
	-- If already used, cannot remove record
	-- ####################################################

	-- Leave Re-upload request
	-- ####################################################
	IF TEMP_RECORD_BINDED = 1 THEN
		IF TEMP_SYNC_IS_SERVER_REQUEST = 1 THEN
			
			LEAVE SP_DELETE;
		END IF;

		CALL `VALIDATION_DELETE_LINKED_RECORD`(TEMP_ADD_ULICENSE_ACC_ACCOUNT_ID, '', TEMP_ERR_MESSAGE); 
	END IF;


	-- 7) DELETE
	-- _______________________________________________________________________
	DELETE FROM `addon_license_user`
	WHERE `addon_license_user`.`ADD_ULICENSE_ID` = PARAM_ADD_ULICENSE_ID
	LIMIT 1;


	-- 8) AUDIT TRAIL
	-- _______________________________________________________________________
	CALL `ACCOUNT_AUDIT_TRAIL_SAVE`
	(
		0, TEMP_MODULE_KEYWORD, PARAM_ADD_ULICENSE_ID, 0, 'DELETE', TEMP_SP_OBJECTIVE, TEMP_RECORD_CHANGES, 
		PARAM_REQUESTER_USERNAME, PARAM_REQUESTER_PASSWORD, 
		PARAM_REQUESTER_PROXY_ID, PARAM_REQUESTER_PROXY_PASSWORD,
		PARAM_REQUESTER_DEVICE_PUBLIC_KEY, PARAM_REQUESTER_DEVICE_PRIVATE_KEY,
		PARAM_REQUESTER_IP, PARAM_UNIQUE_SESSION_ID,
		TEMP_SYNC_SERVER_ID, PARAM_SUPPRESS_RETURN
	);

END ;;
DELIMITER ;
/*!50003 SET sql_mode              = @saved_sql_mode */ ;
/*!50003 SET character_set_client  = @saved_cs_client */ ;
/*!50003 SET character_set_results = @saved_cs_results */ ;
/*!50003 SET collation_connection  = @saved_col_connection */ ;
/*!50003 DROP PROCEDURE IF EXISTS `ADDON_LICENSE_USER_GET` */;
/*!50003 SET @saved_cs_client      = @@character_set_client */ ;
/*!50003 SET @saved_cs_results     = @@character_set_results */ ;
/*!50003 SET @saved_col_connection = @@collation_connection */ ;
/*!50003 SET character_set_client  = latin1 */ ;
/*!50003 SET character_set_results = latin1 */ ;
/*!50003 SET collation_connection  = latin1_swedish_ci */ ;
/*!50003 SET @saved_sql_mode       = @@sql_mode */ ;
/*!50003 SET sql_mode              = '' */ ;
DELIMITER ;;
CREATE DEFINER=`root`@`localhost` PROCEDURE `ADDON_LICENSE_USER_GET`(
	IN `PARAM_ADD_ULICENSE_ID` BIGINT,	
	IN `PARAM_ADD_ULICENSE_ACC_ACCOUNT_ID` BIGINT,	
	IN `PARAM_ADD_ULICENSE_DATE_RENEW_FROM` DATETIME(6),
	IN `PARAM_ADD_ULICENSE_DATE_RENEW_TO` DATETIME(6),
	IN `PARAM_ADD_ULICENSE_DATE_EXPIRY_FROM` DATETIME(6),
	IN `PARAM_ADD_ULICENSE_DATE_EXPIRY_TO` DATETIME(6),
	IN `PARAM_ADD_ULICENSE_VOLUME_FROM` BIGINT,
	IN `PARAM_ADD_ULICENSE_VOLUME_TO` BIGINT,
	IN `PARAM_ADD_ULICENSE_STATUS` TINYINT,	
	IN `PARAM_ADD_ULICENSE_SYSTEM_GENERATED` TINYINT,	
		
	IN `PARAM_ORDER_FIELD` VARCHAR(500),
	IN `PARAM_ORDER_TYPE` VARCHAR(500),
	IN `PARAM_SKIP` BIGINT,
	IN `PARAM_LIMIT` BIGINT,

	IN `PARAM_REQUESTER_USERNAME` VARCHAR(500),
	IN `PARAM_REQUESTER_PASSWORD` VARCHAR(500),
	IN `PARAM_REQUESTER_PROXY_ID` BIGINT,
	IN `PARAM_REQUESTER_PROXY_PASSWORD` VARCHAR(1000),
	IN `PARAM_REQUESTER_DEVICE_PUBLIC_KEY` VARCHAR(1000),
	IN `PARAM_REQUESTER_DEVICE_PRIVATE_KEY` VARCHAR(1000),
	
	IN `PARAM_REQUESTER_IP` VARCHAR(1000),
	IN `PARAM_UNIQUE_SESSION_ID` VARCHAR(1000),
	IN `PARAM_SUPPRESS_RETURN` BIT
)
SP_GET:
BEGIN

	-- Status
	-- =========================================================================================
	DECLARE STATUS_INACTIVE TINYINT DEFAULT 1;
	DECLARE STATUS_ACTIVE TINYINT DEFAULT 2;
	DECLARE STATUS_CLOSED TINYINT DEFAULT 3;
	DECLARE STATUS_COMPLETED TINYINT DEFAULT 4;
	
	-- Audit Handler
	-- =========================================================================================
	DECLARE TEMP_RECORD_EXISTS BIT DEFAULT 0;
	DECLARE TEMP_MODULE_KEYWORD VARCHAR(500) DEFAULT 'addon_license_user';
	DECLARE TEMP_SP_OBJECTIVE VARCHAR(500) DEFAULT 'Retrieve User License record';
	DECLARE TEMP_ERR_MESSAGE VARCHAR(500) DEFAULT '';
	DECLARE ERR BIGINT DEFAULT 0;
	DECLARE TEMP_RECORD_CHANGES VARCHAR(16000) DEFAULT '';
	DECLARE TEMP_RECORD_BINDED BIT DEFAULT 0;
	
	DECLARE TEMP_RECORD_BINDED_ID BIGINT DEFAULT 0;
	DECLARE TEMP_RECORD_BINDED_SERVER_ID BIGINT DEFAULT 0;
	
	-- Authentication
	-- =========================================================================================
	DECLARE TEMP_ACCESS_RIGHTS_DENIED BIT DEFAULT 0;
	DECLARE TEMP_AUTHENTICATED_ACCOUNT_ID BIGINT DEFAULT `ACCOUNT_MEMBER@ACC_ACCOUNT_ID_FROM_LOGIN`(PARAM_REQUESTER_USERNAME, PARAM_REQUESTER_PASSWORD);
	DECLARE TEMP_AUTHENTICATED_ACCOUNT_LEVEL BIGINT DEFAULT 0;
	DECLARE TEMP_AUTHENTICATED_ACCOUNT_GROUP BIGINT DEFAULT 0;
	
	-- Local Parameters
	-- =========================================================================================
	DECLARE TEMP_NOW DATETIME(6) DEFAULT `SYSTEM_VAR@NOW`('', 1);
	DECLARE TEMP_RECORD_COUNT BIGINT DEFAULT 0;
	
	
	-- Check NULLs
	-- =========================================================================================
	DECLARE IS_NULL_ADD_ULICENSE_ID BIT DEFAULT `SYSTEM_VAR@IS_NULL@BIGINT`(PARAM_ADD_ULICENSE_ID, 1, 1);
	DECLARE IS_NULL_ADD_ULICENSE_ACC_ACCOUNT_ID BIT DEFAULT `SYSTEM_VAR@IS_NULL@BIGINT`(PARAM_ADD_ULICENSE_ACC_ACCOUNT_ID, 1, 1);
	DECLARE IS_NULL_ADD_ULICENSE_DATE_RENEW_FROM BIT DEFAULT `SYSTEM_VAR@IS_NULL@DATETIME`(PARAM_ADD_ULICENSE_DATE_RENEW_FROM, 1);
	DECLARE IS_NULL_ADD_ULICENSE_DATE_RENEW_TO BIT DEFAULT `SYSTEM_VAR@IS_NULL@DATETIME`(PARAM_ADD_ULICENSE_DATE_RENEW_TO, 1);				
	DECLARE IS_NULL_ADD_ULICENSE_DATE_EXPIRY_FROM BIT DEFAULT `SYSTEM_VAR@IS_NULL@DATETIME`(PARAM_ADD_ULICENSE_DATE_EXPIRY_FROM, 1);
	DECLARE IS_NULL_ADD_ULICENSE_DATE_EXPIRY_TO BIT DEFAULT `SYSTEM_VAR@IS_NULL@DATETIME`(PARAM_ADD_ULICENSE_DATE_EXPIRY_TO, 1);				
	DECLARE IS_NULL_ADD_ULICENSE_VOLUME_FROM BIT DEFAULT `SYSTEM_VAR@IS_NULL@BIGINT`(PARAM_ADD_ULICENSE_VOLUME_FROM, 1, 1);
	DECLARE IS_NULL_ADD_ULICENSE_VOLUME_TO BIT DEFAULT `SYSTEM_VAR@IS_NULL@BIGINT`(PARAM_ADD_ULICENSE_VOLUME_TO, 1, 1);
	DECLARE IS_NULL_ADD_ULICENSE_STATUS BIT DEFAULT `SYSTEM_VAR@IS_NULL@TINYINT`(PARAM_ADD_ULICENSE_STATUS, 1, 1);
	DECLARE IS_NULL_ADD_ULICENSE_SYSTEM_GENERATED BIT DEFAULT `SYSTEM_VAR@IS_NULL@TINYINT`(PARAM_ADD_ULICENSE_SYSTEM_GENERATED, 1, 1);
	
	-- Error Handler
	-- =========================================================================================
	DECLARE EXIT HANDLER FOR SQLEXCEPTION
	BEGIN
		RESIGNAL;
	END;
	
	-- Ignore Time from DateTime (Set Time 00:00:00.000000 and 23:59:59.999999)
	-- =========================================================================================
		
		
	-- Access Rights [Device]
	-- =========================================================================================
	IF `ACCOUNT_DEVICE@HAS_PERMISSION`(PARAM_REQUESTER_DEVICE_PUBLIC_KEY, PARAM_REQUESTER_DEVICE_PRIVATE_KEY) = 0 THEN
		SET TEMP_ERR_MESSAGE = 'Your device is not authorized yet to access this server.';
		SET ERR = `RAISERROR`(TEMP_ERR_MESSAGE);		
	END IF;
		
		
	-- Access Rights [Account]
	-- =========================================================================================
		
	IF `ACCOUNT_ACCESS_RIGHTS@HAS_PERMISSION`(PARAM_REQUESTER_USERNAME, PARAM_REQUESTER_PASSWORD, 0, TEMP_MODULE_KEYWORD, 1) = 0 THEN
		SET TEMP_ACCESS_RIGHTS_DENIED = 1;
		CALL `ACCOUNT_ACCESS_RIGHTS_DENY`
		(
			0, TEMP_MODULE_KEYWORD, 0, 0, TEMP_SP_OBJECTIVE, TEMP_RECORD_CHANGES, 
			PARAM_REQUESTER_USERNAME, PARAM_REQUESTER_PASSWORD, 
			PARAM_REQUESTER_PROXY_ID, PARAM_REQUESTER_PROXY_PASSWORD,
			PARAM_REQUESTER_DEVICE_PUBLIC_KEY, PARAM_REQUESTER_DEVICE_PRIVATE_KEY,
			PARAM_REQUESTER_IP, PARAM_UNIQUE_SESSION_ID,
			0, PARAM_SUPPRESS_RETURN
		);
	END IF;
	
	
	
	-- COUNT RECORD
	-- =========================================================================================
	
	-- SELECT COLUMNS
	-- ####################################################
	SELECT
		COUNT(DISTINCT `addon_license_user`.`ADD_ULICENSE_ID`)
	INTO
		TEMP_RECORD_COUNT

	FROM `addon_license_user`
	
		-- Add Inner Joins (Per Foreign-key)
		INNER JOIN `account_member` ON
		`account_member`.`ACC_ACCOUNT_ID` = `addon_license_user`.`ADD_ULICENSE_ACC_ACCOUNT_ID`
		
		-- Add Optional Left Joins (Per Optional Foreign-key)
		
	-- CONDITIONS
	-- ####################################################
	WHERE
		(
			IS_NULL_ADD_ULICENSE_ID = 1 OR
			`addon_license_user`.`ADD_ULICENSE_ID` = PARAM_ADD_ULICENSE_ID			
		) AND
		(
			IS_NULL_ADD_ULICENSE_ACC_ACCOUNT_ID = 1 OR
			`addon_license_user`.`ADD_ULICENSE_ACC_ACCOUNT_ID` = PARAM_ADD_ULICENSE_ACC_ACCOUNT_ID			
		) AND
		(
			IS_NULL_ADD_ULICENSE_DATE_RENEW_FROM = 1 OR
			`addon_license_user`.`ADD_ULICENSE_DATE_RENEW` >= PARAM_ADD_ULICENSE_DATE_RENEW_FROM			
		) AND
		(
			IS_NULL_ADD_ULICENSE_DATE_RENEW_TO = 1 OR
			`addon_license_user`.`ADD_ULICENSE_DATE_RENEW` <= PARAM_ADD_ULICENSE_DATE_RENEW_TO			
		) AND 		
		(
			IS_NULL_ADD_ULICENSE_DATE_EXPIRY_FROM = 1 OR
			`addon_license_user`.`ADD_ULICENSE_DATE_EXPIRY` >= PARAM_ADD_ULICENSE_DATE_EXPIRY_FROM			
		) AND
		(
			IS_NULL_ADD_ULICENSE_DATE_EXPIRY_TO = 1 OR
			`addon_license_user`.`ADD_ULICENSE_DATE_EXPIRY` <= PARAM_ADD_ULICENSE_DATE_EXPIRY_TO			
		) AND 		
		(
			IS_NULL_ADD_ULICENSE_VOLUME_FROM = 1 OR
			`addon_license_user`.`ADD_ULICENSE_VOLUME` >= PARAM_ADD_ULICENSE_VOLUME_FROM			
		) AND
		(
			IS_NULL_ADD_ULICENSE_VOLUME_TO = 1 OR
			`addon_license_user`.`ADD_ULICENSE_VOLUME` <= PARAM_ADD_ULICENSE_VOLUME_TO			
		) AND 		
		(
			IS_NULL_ADD_ULICENSE_STATUS = 1 OR
			`addon_license_user`.`ADD_ULICENSE_STATUS` = PARAM_ADD_ULICENSE_STATUS			
		) AND
		(
			IS_NULL_ADD_ULICENSE_SYSTEM_GENERATED = 1 OR
			`addon_license_user`.`ADD_ULICENSE_SYSTEM_GENERATED` = PARAM_ADD_ULICENSE_SYSTEM_GENERATED			
		) 
;	

		
		
	-- SELECT RECORDS
	-- =========================================================================================
	
	-- FETCH COLUMNS
	-- ####################################################
	SELECT
		-- ADDON_LICENSE_USER DETAILS
		`addon_license_user`.`ADD_ULICENSE_ID`, 
		`addon_license_user`.`ADD_ULICENSE_ACC_ACCOUNT_ID`, 
		`addon_license_user`.`ADD_ULICENSE_DATE_RENEW`, 
		`addon_license_user`.`ADD_ULICENSE_DATE_EXPIRY`, 
		`addon_license_user`.`ADD_ULICENSE_VOLUME`, 
		`addon_license_user`.`ADD_ULICENSE_STATUS`, 
		`addon_license_user`.`ADD_ULICENSE_SYSTEM_GENERATED`
		
		-- Inner join fields
		, 
		`account_member`.`ACC_ACCOUNT_ID`, 
		`account_member`.`ACC_ACCOUNT_SERVER_ID`, 
		`account_member`.`ACC_ACCOUNT_ACC_LEVEL_ID`, 
		`account_member`.`ACC_ACCOUNT_ACC_GROUP_ID`, 
		`account_member`.`ACC_ACCOUNT_ADD_RESOURCE_ID`, 
		`account_member`.`ACC_ACCOUNT_USERNAME`, 
		`account_member`.`ACC_ACCOUNT_PASSWORD`, 
		`account_member`.`ACC_ACCOUNT_AUTH_CODE`, 
		`account_member`.`ACC_ACCOUNT_FIRST_NAME`, 
		`account_member`.`ACC_ACCOUNT_MIDDLE_NAME`, 
		`account_member`.`ACC_ACCOUNT_LAST_NAME`, 
		`account_member`.`ACC_ACCOUNT_POSITION`, 
		`account_member`.`ACC_ACCOUNT_SYS_GENDER_ID`, 
		`account_member`.`ACC_ACCOUNT_STATUS`, 
		`account_member`.`ACC_ACCOUNT_SYSTEM_GENERATED`
		
		-- Left join fields
		
		, TEMP_NOW AS SERVER_TIME,
		TEMP_RECORD_COUNT AS RECORD_COUNT

	FROM `addon_license_user`
	
		-- Add Inner Joins (Per Foreign-key)
		INNER JOIN `account_member` ON
		`account_member`.`ACC_ACCOUNT_ID` = `addon_license_user`.`ADD_ULICENSE_ACC_ACCOUNT_ID`
		
		-- Add Optional Left Joins (Per Optional Foreign-key)
		
	-- CONDITIONS
	-- ####################################################
	WHERE
		(
			IS_NULL_ADD_ULICENSE_ID = 1 OR
			`addon_license_user`.`ADD_ULICENSE_ID` = PARAM_ADD_ULICENSE_ID			
		) AND
		(
			IS_NULL_ADD_ULICENSE_ACC_ACCOUNT_ID = 1 OR
			`addon_license_user`.`ADD_ULICENSE_ACC_ACCOUNT_ID` = PARAM_ADD_ULICENSE_ACC_ACCOUNT_ID			
		) AND
		(
			IS_NULL_ADD_ULICENSE_DATE_RENEW_FROM = 1 OR
			`addon_license_user`.`ADD_ULICENSE_DATE_RENEW` >= PARAM_ADD_ULICENSE_DATE_RENEW_FROM			
		) AND
		(
			IS_NULL_ADD_ULICENSE_DATE_RENEW_TO = 1 OR
			`addon_license_user`.`ADD_ULICENSE_DATE_RENEW` <= PARAM_ADD_ULICENSE_DATE_RENEW_TO			
		) AND 
		(
			IS_NULL_ADD_ULICENSE_DATE_EXPIRY_FROM = 1 OR
			`addon_license_user`.`ADD_ULICENSE_DATE_EXPIRY` >= PARAM_ADD_ULICENSE_DATE_EXPIRY_FROM			
		) AND
		(
			IS_NULL_ADD_ULICENSE_DATE_EXPIRY_TO = 1 OR
			`addon_license_user`.`ADD_ULICENSE_DATE_EXPIRY` <= PARAM_ADD_ULICENSE_DATE_EXPIRY_TO			
		) AND 
		(
			IS_NULL_ADD_ULICENSE_VOLUME_FROM = 1 OR
			`addon_license_user`.`ADD_ULICENSE_VOLUME` >= PARAM_ADD_ULICENSE_VOLUME_FROM			
		) AND
		(
			IS_NULL_ADD_ULICENSE_VOLUME_TO = 1 OR
			`addon_license_user`.`ADD_ULICENSE_VOLUME` <= PARAM_ADD_ULICENSE_VOLUME_TO			
		) AND 
		(
			IS_NULL_ADD_ULICENSE_STATUS = 1 OR
			`addon_license_user`.`ADD_ULICENSE_STATUS` = PARAM_ADD_ULICENSE_STATUS			
		) AND
		(
			IS_NULL_ADD_ULICENSE_SYSTEM_GENERATED = 1 OR
			`addon_license_user`.`ADD_ULICENSE_SYSTEM_GENERATED` = PARAM_ADD_ULICENSE_SYSTEM_GENERATED			
		) 

	-- ORDER BY
	-- ####################################################
	ORDER BY
		-- ADDON_LICENSE_USER DETAILS
		CASE WHEN PARAM_ORDER_FIELD = 'ADD_ULICENSE_ID' AND PARAM_ORDER_TYPE = 'ASC' THEN `addon_license_user`.`ADD_ULICENSE_ID` END ASC, 
		CASE WHEN PARAM_ORDER_FIELD = 'ADD_ULICENSE_ID' AND PARAM_ORDER_TYPE = 'DESC' THEN `addon_license_user`.`ADD_ULICENSE_ID` END DESC,	
		CASE WHEN PARAM_ORDER_FIELD = 'ADD_ULICENSE_ACC_ACCOUNT_ID' AND PARAM_ORDER_TYPE = 'ASC' THEN `addon_license_user`.`ADD_ULICENSE_ACC_ACCOUNT_ID` END ASC, 
		CASE WHEN PARAM_ORDER_FIELD = 'ADD_ULICENSE_ACC_ACCOUNT_ID' AND PARAM_ORDER_TYPE = 'DESC' THEN `addon_license_user`.`ADD_ULICENSE_ACC_ACCOUNT_ID` END DESC,	
		CASE WHEN PARAM_ORDER_FIELD = 'ADD_ULICENSE_DATE_RENEW' AND PARAM_ORDER_TYPE = 'ASC' THEN `addon_license_user`.`ADD_ULICENSE_DATE_RENEW` END ASC, 
		CASE WHEN PARAM_ORDER_FIELD = 'ADD_ULICENSE_DATE_RENEW' AND PARAM_ORDER_TYPE = 'DESC' THEN `addon_license_user`.`ADD_ULICENSE_DATE_RENEW` END DESC,	
		CASE WHEN PARAM_ORDER_FIELD = 'ADD_ULICENSE_DATE_EXPIRY' AND PARAM_ORDER_TYPE = 'ASC' THEN `addon_license_user`.`ADD_ULICENSE_DATE_EXPIRY` END ASC, 
		CASE WHEN PARAM_ORDER_FIELD = 'ADD_ULICENSE_DATE_EXPIRY' AND PARAM_ORDER_TYPE = 'DESC' THEN `addon_license_user`.`ADD_ULICENSE_DATE_EXPIRY` END DESC,	
		CASE WHEN PARAM_ORDER_FIELD = 'ADD_ULICENSE_VOLUME' AND PARAM_ORDER_TYPE = 'ASC' THEN `addon_license_user`.`ADD_ULICENSE_VOLUME` END ASC, 
		CASE WHEN PARAM_ORDER_FIELD = 'ADD_ULICENSE_VOLUME' AND PARAM_ORDER_TYPE = 'DESC' THEN `addon_license_user`.`ADD_ULICENSE_VOLUME` END DESC,	
		CASE WHEN PARAM_ORDER_FIELD = 'ADD_ULICENSE_STATUS' AND PARAM_ORDER_TYPE = 'ASC' THEN `addon_license_user`.`ADD_ULICENSE_STATUS` END ASC, 
		CASE WHEN PARAM_ORDER_FIELD = 'ADD_ULICENSE_STATUS' AND PARAM_ORDER_TYPE = 'DESC' THEN `addon_license_user`.`ADD_ULICENSE_STATUS` END DESC,	
		CASE WHEN PARAM_ORDER_FIELD = 'ADD_ULICENSE_SYSTEM_GENERATED' AND PARAM_ORDER_TYPE = 'ASC' THEN `addon_license_user`.`ADD_ULICENSE_SYSTEM_GENERATED` END ASC, 
		CASE WHEN PARAM_ORDER_FIELD = 'ADD_ULICENSE_SYSTEM_GENERATED' AND PARAM_ORDER_TYPE = 'DESC' THEN `addon_license_user`.`ADD_ULICENSE_SYSTEM_GENERATED` END DESC,	

		-- Inner joins
		CASE WHEN PARAM_ORDER_FIELD = 'ACC_ACCOUNT_ID' AND PARAM_ORDER_TYPE = 'ASC' THEN `account_member`.`ACC_ACCOUNT_ID` END ASC, 
		CASE WHEN PARAM_ORDER_FIELD = 'ACC_ACCOUNT_ID' AND PARAM_ORDER_TYPE = 'DESC' THEN `account_member`.`ACC_ACCOUNT_ID` END DESC,	
		CASE WHEN PARAM_ORDER_FIELD = 'ACC_ACCOUNT_SERVER_ID' AND PARAM_ORDER_TYPE = 'ASC' THEN `account_member`.`ACC_ACCOUNT_SERVER_ID` END ASC, 
		CASE WHEN PARAM_ORDER_FIELD = 'ACC_ACCOUNT_SERVER_ID' AND PARAM_ORDER_TYPE = 'DESC' THEN `account_member`.`ACC_ACCOUNT_SERVER_ID` END DESC,	
		CASE WHEN PARAM_ORDER_FIELD = 'ACC_ACCOUNT_ACC_LEVEL_ID' AND PARAM_ORDER_TYPE = 'ASC' THEN `account_member`.`ACC_ACCOUNT_ACC_LEVEL_ID` END ASC, 
		CASE WHEN PARAM_ORDER_FIELD = 'ACC_ACCOUNT_ACC_LEVEL_ID' AND PARAM_ORDER_TYPE = 'DESC' THEN `account_member`.`ACC_ACCOUNT_ACC_LEVEL_ID` END DESC,	
		CASE WHEN PARAM_ORDER_FIELD = 'ACC_ACCOUNT_ACC_GROUP_ID' AND PARAM_ORDER_TYPE = 'ASC' THEN `account_member`.`ACC_ACCOUNT_ACC_GROUP_ID` END ASC, 
		CASE WHEN PARAM_ORDER_FIELD = 'ACC_ACCOUNT_ACC_GROUP_ID' AND PARAM_ORDER_TYPE = 'DESC' THEN `account_member`.`ACC_ACCOUNT_ACC_GROUP_ID` END DESC,	
		CASE WHEN PARAM_ORDER_FIELD = 'ACC_ACCOUNT_ADD_RESOURCE_ID' AND PARAM_ORDER_TYPE = 'ASC' THEN `account_member`.`ACC_ACCOUNT_ADD_RESOURCE_ID` END ASC, 
		CASE WHEN PARAM_ORDER_FIELD = 'ACC_ACCOUNT_ADD_RESOURCE_ID' AND PARAM_ORDER_TYPE = 'DESC' THEN `account_member`.`ACC_ACCOUNT_ADD_RESOURCE_ID` END DESC,	
		CASE WHEN PARAM_ORDER_FIELD = 'ACC_ACCOUNT_USERNAME' AND PARAM_ORDER_TYPE = 'ASC' THEN `account_member`.`ACC_ACCOUNT_USERNAME` END ASC, 
		CASE WHEN PARAM_ORDER_FIELD = 'ACC_ACCOUNT_USERNAME' AND PARAM_ORDER_TYPE = 'DESC' THEN `account_member`.`ACC_ACCOUNT_USERNAME` END DESC,	
		CASE WHEN PARAM_ORDER_FIELD = 'ACC_ACCOUNT_PASSWORD' AND PARAM_ORDER_TYPE = 'ASC' THEN `account_member`.`ACC_ACCOUNT_PASSWORD` END ASC, 
		CASE WHEN PARAM_ORDER_FIELD = 'ACC_ACCOUNT_PASSWORD' AND PARAM_ORDER_TYPE = 'DESC' THEN `account_member`.`ACC_ACCOUNT_PASSWORD` END DESC,	
		CASE WHEN PARAM_ORDER_FIELD = 'ACC_ACCOUNT_AUTH_CODE' AND PARAM_ORDER_TYPE = 'ASC' THEN `account_member`.`ACC_ACCOUNT_AUTH_CODE` END ASC, 
		CASE WHEN PARAM_ORDER_FIELD = 'ACC_ACCOUNT_AUTH_CODE' AND PARAM_ORDER_TYPE = 'DESC' THEN `account_member`.`ACC_ACCOUNT_AUTH_CODE` END DESC,	
		CASE WHEN PARAM_ORDER_FIELD = 'ACC_ACCOUNT_FIRST_NAME' AND PARAM_ORDER_TYPE = 'ASC' THEN `account_member`.`ACC_ACCOUNT_FIRST_NAME` END ASC, 
		CASE WHEN PARAM_ORDER_FIELD = 'ACC_ACCOUNT_FIRST_NAME' AND PARAM_ORDER_TYPE = 'DESC' THEN `account_member`.`ACC_ACCOUNT_FIRST_NAME` END DESC,	
		CASE WHEN PARAM_ORDER_FIELD = 'ACC_ACCOUNT_MIDDLE_NAME' AND PARAM_ORDER_TYPE = 'ASC' THEN `account_member`.`ACC_ACCOUNT_MIDDLE_NAME` END ASC, 
		CASE WHEN PARAM_ORDER_FIELD = 'ACC_ACCOUNT_MIDDLE_NAME' AND PARAM_ORDER_TYPE = 'DESC' THEN `account_member`.`ACC_ACCOUNT_MIDDLE_NAME` END DESC,	
		CASE WHEN PARAM_ORDER_FIELD = 'ACC_ACCOUNT_LAST_NAME' AND PARAM_ORDER_TYPE = 'ASC' THEN `account_member`.`ACC_ACCOUNT_LAST_NAME` END ASC, 
		CASE WHEN PARAM_ORDER_FIELD = 'ACC_ACCOUNT_LAST_NAME' AND PARAM_ORDER_TYPE = 'DESC' THEN `account_member`.`ACC_ACCOUNT_LAST_NAME` END DESC,	
		CASE WHEN PARAM_ORDER_FIELD = 'ACC_ACCOUNT_POSITION' AND PARAM_ORDER_TYPE = 'ASC' THEN `account_member`.`ACC_ACCOUNT_POSITION` END ASC, 
		CASE WHEN PARAM_ORDER_FIELD = 'ACC_ACCOUNT_POSITION' AND PARAM_ORDER_TYPE = 'DESC' THEN `account_member`.`ACC_ACCOUNT_POSITION` END DESC,	
		CASE WHEN PARAM_ORDER_FIELD = 'ACC_ACCOUNT_SYS_GENDER_ID' AND PARAM_ORDER_TYPE = 'ASC' THEN `account_member`.`ACC_ACCOUNT_SYS_GENDER_ID` END ASC, 
		CASE WHEN PARAM_ORDER_FIELD = 'ACC_ACCOUNT_SYS_GENDER_ID' AND PARAM_ORDER_TYPE = 'DESC' THEN `account_member`.`ACC_ACCOUNT_SYS_GENDER_ID` END DESC,	
		CASE WHEN PARAM_ORDER_FIELD = 'ACC_ACCOUNT_STATUS' AND PARAM_ORDER_TYPE = 'ASC' THEN `account_member`.`ACC_ACCOUNT_STATUS` END ASC, 
		CASE WHEN PARAM_ORDER_FIELD = 'ACC_ACCOUNT_STATUS' AND PARAM_ORDER_TYPE = 'DESC' THEN `account_member`.`ACC_ACCOUNT_STATUS` END DESC,	
		CASE WHEN PARAM_ORDER_FIELD = 'ACC_ACCOUNT_SYSTEM_GENERATED' AND PARAM_ORDER_TYPE = 'ASC' THEN `account_member`.`ACC_ACCOUNT_SYSTEM_GENERATED` END ASC, 
		CASE WHEN PARAM_ORDER_FIELD = 'ACC_ACCOUNT_SYSTEM_GENERATED' AND PARAM_ORDER_TYPE = 'DESC' THEN `account_member`.`ACC_ACCOUNT_SYSTEM_GENERATED` END DESC,	
		
		-- EXTRA
		CASE WHEN PARAM_ORDER_FIELD <> 'ADD_ULICENSE_ACC_ACCOUNT_ID' THEN `addon_license_user`.`ADD_ULICENSE_ACC_ACCOUNT_ID` END ASC
		
	-- LIMIT & OFFSET
	-- ####################################################		
	LIMIT PARAM_SKIP, PARAM_LIMIT;
	
	
	
	-- EXIT PROCEDURE
	-- =========================================================================================
	LEAVE SP_GET;
			
END ;;
DELIMITER ;
/*!50003 SET sql_mode              = @saved_sql_mode */ ;
/*!50003 SET character_set_client  = @saved_cs_client */ ;
/*!50003 SET character_set_results = @saved_cs_results */ ;
/*!50003 SET collation_connection  = @saved_col_connection */ ;
/*!50003 DROP PROCEDURE IF EXISTS `ADDON_LICENSE_USER_SAVE` */;
/*!50003 SET @saved_cs_client      = @@character_set_client */ ;
/*!50003 SET @saved_cs_results     = @@character_set_results */ ;
/*!50003 SET @saved_col_connection = @@collation_connection */ ;
/*!50003 SET character_set_client  = latin1 */ ;
/*!50003 SET character_set_results = latin1 */ ;
/*!50003 SET collation_connection  = latin1_swedish_ci */ ;
/*!50003 SET @saved_sql_mode       = @@sql_mode */ ;
/*!50003 SET sql_mode              = '' */ ;
DELIMITER ;;
CREATE DEFINER=`root`@`localhost` PROCEDURE `ADDON_LICENSE_USER_SAVE`(
	IN `PARAM_ADD_ULICENSE_ID` BIGINT,
	IN `PARAM_ADD_ULICENSE_ACC_ACCOUNT_ID` BIGINT,
	IN `PARAM_ADD_ULICENSE_ACC_ACCOUNT_SERVER_ID` BIGINT,	
	IN `PARAM_ADD_ULICENSE_DATE_RENEW` DATETIME(6),
	IN `PARAM_ADD_ULICENSE_DATE_EXPIRY` DATETIME(6),
	IN `PARAM_ADD_ULICENSE_VOLUME` BIGINT,
	IN `PARAM_ADD_ULICENSE_STATUS` TINYINT,

	IN `PARAM_REQUESTER_USERNAME` VARCHAR(500),
	IN `PARAM_REQUESTER_PASSWORD` VARCHAR(500),
	IN `PARAM_REQUESTER_PROXY_ID` BIGINT,
	IN `PARAM_REQUESTER_PROXY_PASSWORD` VARCHAR(1000),
	IN `PARAM_REQUESTER_DEVICE_PUBLIC_KEY` VARCHAR(1000),
	IN `PARAM_REQUESTER_DEVICE_PRIVATE_KEY` VARCHAR(1000),
	
	IN `PARAM_REQUESTER_IP` VARCHAR(1000),
	IN `PARAM_UNIQUE_SESSION_ID` VARCHAR(1000),
	IN `PARAM_SUPPRESS_RETURN` BIT,
	
	IN `PARAM_SYNC_SERVER_DESCRIPTION` VARCHAR(500), 
	IN `PARAM_SYNC_SERVER_UNIQUE_KEY` VARCHAR(500)
)
SP_SAVE:
BEGIN


	-- 1) DECLARE LOCAL PARAMETERS
	-- _______________________________________________________________________
	
	-- Status
	-- ...........................................
	DECLARE STATUS_INACTIVE TINYINT DEFAULT 1;
	DECLARE STATUS_ACTIVE TINYINT DEFAULT 2;
	DECLARE STATUS_CLOSED TINYINT DEFAULT 3;
	DECLARE STATUS_COMPLETED TINYINT DEFAULT 4;

	-- Audit Handler
	-- ...........................................
	DECLARE TEMP_RECORD_EXISTS BIT DEFAULT 0;
	DECLARE TEMP_MODULE_KEYWORD VARCHAR(500) DEFAULT 'addon_license_user';
	DECLARE TEMP_SP_OBJECTIVE VARCHAR(500) DEFAULT 'add/edit User License record';
	DECLARE TEMP_ERR_MESSAGE VARCHAR(500) DEFAULT '';
	DECLARE ERR BIGINT DEFAULT 0;
	DECLARE TEMP_RECORD_CHANGES VARCHAR(16000) DEFAULT '';
	DECLARE TEMP_RECORD_BINDED BIT DEFAULT 0;

	-- Authentication
	-- ...........................................
	DECLARE TEMP_ACCESS_RIGHTS_DENIED BIT DEFAULT 0;
	DECLARE TEMP_ACCESS_RIGHTS_HAS_OVERRIDE BIT DEFAULT 0;
	DECLARE TEMP_SYNC_SERVER_ID BIGINT DEFAULT 0;
	DECLARE TEMP_SYNC_IS_SERVER_REQUEST BIT DEFAULT 0;
	DECLARE TEMP_AUTHENTICATED_ACCOUNT_ID BIGINT DEFAULT `ACCOUNT_MEMBER@ACC_ACCOUNT_ID_FROM_LOGIN`(PARAM_REQUESTER_USERNAME, PARAM_REQUESTER_PASSWORD);
	DECLARE TEMP_AUTHENTICATED_ACCOUNT_LEVEL BIGINT DEFAULT 0;
	DECLARE TEMP_AUTHENTICATED_ACCOUNT_GROUP BIGINT DEFAULT 0;
	
	-- Local Parameters
	-- ...........................................
	DECLARE TEMP_NOW DATETIME(6) DEFAULT `SYSTEM_VAR@NOW`('', 1);
	DECLARE TEMP_RECORD_COUNT BIGINT DEFAULT 0;

	-- AutoGen Parameters
	-- ...........................................
	DECLARE PARAM_ADD_ULICENSE_SYSTEM_GENERATED TINYINT DEFAULT 0; 
	
	-- Local value holder
	-- ...........................................
	DECLARE TEMP_ADD_ULICENSE_ACC_ACCOUNT_ID BIGINT DEFAULT 0; 
	DECLARE TEMP_ADD_ULICENSE_DATE_RENEW DATETIME(6) DEFAULT '1000-01-01 00:00:00.000000'; 
	DECLARE TEMP_ADD_ULICENSE_DATE_EXPIRY DATETIME(6) DEFAULT '1000-01-01 00:00:00.000000'; 
	DECLARE TEMP_ADD_ULICENSE_VOLUME BIGINT DEFAULT 0; 
	DECLARE TEMP_ADD_ULICENSE_STATUS TINYINT DEFAULT 0; 
	DECLARE TEMP_ADD_ULICENSE_SYSTEM_GENERATED TINYINT DEFAULT 0; 
	


	-- 2) Try Catch / Throw
	-- _______________________________________________________________________
	DECLARE EXIT HANDLER FOR SQLEXCEPTION
	BEGIN
		RESIGNAL;
	END;



	-- 3) Prepare SYNC
	-- _______________________________________________________________________

	-- IS RECORD EXISTS		
	-- ####################################################	
	SET TEMP_RECORD_EXISTS = `ADDON_LICENSE_USER@ADD_ULICENSE_ID_EXISTS`(PARAM_ADD_ULICENSE_ID, 0);

		
		
	-- 4) PREPARE AUTOGEN DATA (IF EXISTS)
	-- _______________________________________________________________________
	IF TEMP_SYNC_IS_SERVER_REQUEST = 0 THEN
		-- Just to keep at least one line within condition
		SET TEMP_SYNC_IS_SERVER_REQUEST = 0;
		
		-- Actual Functionalities here
		-- USE DEFAULT VALUE (String)
		-- USE DEFAULT VALUE (String)
		SET PARAM_ADD_ULICENSE_SYSTEM_GENERATED = 1;
	-- USE TIMESTAMP
	END IF;



	-- 5) IF ALREADY EXIST, FILL MISSING DATA
	-- _______________________________________________________________________
	IF TEMP_RECORD_EXISTS = 1 THEN
		SELECT
			`addon_license_user`.`ADD_ULICENSE_ACC_ACCOUNT_ID`, 	
			`addon_license_user`.`ADD_ULICENSE_DATE_RENEW`, 	
			`addon_license_user`.`ADD_ULICENSE_DATE_EXPIRY`, 	
			`addon_license_user`.`ADD_ULICENSE_VOLUME`, 	
			`addon_license_user`.`ADD_ULICENSE_STATUS`, 	
			`addon_license_user`.`ADD_ULICENSE_SYSTEM_GENERATED`	
		INTO
			TEMP_ADD_ULICENSE_ACC_ACCOUNT_ID, 	
			TEMP_ADD_ULICENSE_DATE_RENEW, 	
			TEMP_ADD_ULICENSE_DATE_EXPIRY, 	
			TEMP_ADD_ULICENSE_VOLUME, 	
			TEMP_ADD_ULICENSE_STATUS, 	
			TEMP_ADD_ULICENSE_SYSTEM_GENERATED	

		FROM `addon_license_user`
		WHERE
			`addon_license_user`.`ADD_ULICENSE_ID` = PARAM_ADD_ULICENSE_ID
		LIMIT 1;

		-- Replace NULLs with the existing data.
		SET PARAM_ADD_ULICENSE_ACC_ACCOUNT_ID = `SYSTEM_VAR@REPLACE_NULL@BIGINT`(PARAM_ADD_ULICENSE_ACC_ACCOUNT_ID, TEMP_ADD_ULICENSE_ACC_ACCOUNT_ID, 1, 1);
		SET PARAM_ADD_ULICENSE_DATE_RENEW = `SYSTEM_VAR@REPLACE_NULL@DATETIME`(PARAM_ADD_ULICENSE_DATE_RENEW, TEMP_ADD_ULICENSE_DATE_RENEW, 1);
		SET PARAM_ADD_ULICENSE_DATE_EXPIRY = `SYSTEM_VAR@REPLACE_NULL@DATETIME`(PARAM_ADD_ULICENSE_DATE_EXPIRY, TEMP_ADD_ULICENSE_DATE_EXPIRY, 1);
		SET PARAM_ADD_ULICENSE_VOLUME = `SYSTEM_VAR@REPLACE_NULL@BIGINT`(PARAM_ADD_ULICENSE_VOLUME, TEMP_ADD_ULICENSE_VOLUME, 0, 1);
		SET PARAM_ADD_ULICENSE_STATUS = `SYSTEM_VAR@REPLACE_NULL@TINYINT`(PARAM_ADD_ULICENSE_STATUS, TEMP_ADD_ULICENSE_STATUS, 1, 1);
		
		-- NON-UPDATABLE
		
		-- NON-UPDATABLE BUT NULL
		
		-- AUTO GEN (NON-UPDATABLES)		
		SET PARAM_ADD_ULICENSE_SYSTEM_GENERATED = TEMP_ADD_ULICENSE_SYSTEM_GENERATED;
		
		-- AUTO GEN (UPDATABLE WITH STATUS CHANGE)

		-- AUTO GEN (UPDATABLE WITH STATUS [ACTIVE/INACTIVE] CHANGE)
		
	ELSE
		SET PARAM_ADD_ULICENSE_ACC_ACCOUNT_ID = `SYSTEM_VAR@REPLACE_NULL@BIGINT`(PARAM_ADD_ULICENSE_ACC_ACCOUNT_ID, 0, 1, 1);
		SET PARAM_ADD_ULICENSE_DATE_RENEW = `SYSTEM_VAR@REPLACE_NULL@DATETIME`(PARAM_ADD_ULICENSE_DATE_RENEW, '1000-01-01 00:00:00.000000', 1);
		SET PARAM_ADD_ULICENSE_DATE_EXPIRY = `SYSTEM_VAR@REPLACE_NULL@DATETIME`(PARAM_ADD_ULICENSE_DATE_EXPIRY, '1000-01-01 00:00:00.000000', 1);
		SET PARAM_ADD_ULICENSE_VOLUME = `SYSTEM_VAR@REPLACE_NULL@BIGINT`(PARAM_ADD_ULICENSE_VOLUME, 0, 0, 1);
		SET PARAM_ADD_ULICENSE_STATUS = `SYSTEM_VAR@REPLACE_NULL@TINYINT`(PARAM_ADD_ULICENSE_STATUS, 0, 1, 1);
		
	END IF;

	

	-- 6) PREPARE AUDIT TRAIL
	-- _______________________________________________________________________
	IF TEMP_ADD_ULICENSE_ACC_ACCOUNT_ID <> PARAM_ADD_ULICENSE_ACC_ACCOUNT_ID THEN
		SET TEMP_RECORD_CHANGES = 
		`SYSTEM_VAR@CONCAT_ADD`(' | ', TEMP_RECORD_CHANGES, CONCAT_WS(' ', 'User Account: "', TEMP_ADD_ULICENSE_ACC_ACCOUNT_ID, '" > "', PARAM_ADD_ULICENSE_ACC_ACCOUNT_ID, '"'));
	END IF;	
	IF BINARY TEMP_ADD_ULICENSE_DATE_RENEW <> PARAM_ADD_ULICENSE_DATE_RENEW THEN
		SET TEMP_RECORD_CHANGES = 
		`SYSTEM_VAR@CONCAT_ADD`(' | ', TEMP_RECORD_CHANGES, CONCAT_WS(' ', 'Renewal Date: "', TEMP_ADD_ULICENSE_DATE_RENEW, '" > "', PARAM_ADD_ULICENSE_DATE_RENEW, '"'));
	END IF;
	IF BINARY TEMP_ADD_ULICENSE_DATE_EXPIRY <> PARAM_ADD_ULICENSE_DATE_EXPIRY THEN
		SET TEMP_RECORD_CHANGES = 
		`SYSTEM_VAR@CONCAT_ADD`(' | ', TEMP_RECORD_CHANGES, CONCAT_WS(' ', 'Expiry Date: "', TEMP_ADD_ULICENSE_DATE_EXPIRY, '" > "', PARAM_ADD_ULICENSE_DATE_EXPIRY, '"'));
	END IF;
	IF TEMP_ADD_ULICENSE_VOLUME <> PARAM_ADD_ULICENSE_VOLUME THEN
		SET TEMP_RECORD_CHANGES = 
		`SYSTEM_VAR@CONCAT_ADD`(' | ', TEMP_RECORD_CHANGES, CONCAT_WS(' ', 'Volume: "', TEMP_ADD_ULICENSE_VOLUME, '" > "', PARAM_ADD_ULICENSE_VOLUME, '"'));
	END IF;	
	IF TEMP_ADD_ULICENSE_STATUS <> PARAM_ADD_ULICENSE_STATUS THEN
		SET TEMP_RECORD_CHANGES = 
		`SYSTEM_VAR@CONCAT_ADD`(' | ', TEMP_RECORD_CHANGES, CONCAT_WS(' ', 'Status: "', TEMP_ADD_ULICENSE_STATUS, '" > "', PARAM_ADD_ULICENSE_STATUS, '"'));
	END IF;	
	IF TEMP_ADD_ULICENSE_SYSTEM_GENERATED <> PARAM_ADD_ULICENSE_SYSTEM_GENERATED THEN
		SET TEMP_RECORD_CHANGES = 
		`SYSTEM_VAR@CONCAT_ADD`(' | ', TEMP_RECORD_CHANGES, CONCAT_WS(' ', 'System Generated: "', TEMP_ADD_ULICENSE_SYSTEM_GENERATED, '" > "', PARAM_ADD_ULICENSE_SYSTEM_GENERATED, '"'));
	END IF;	
		
	-- No Changes in data, reject request
	-- ####################################################
	IF CHARACTER_LENGTH(TEMP_RECORD_CHANGES) = 0 THEN
		IF PARAM_SUPPRESS_RETURN = 0 THEN
			SELECT PARAM_ADD_ULICENSE_ID AS INSERTED_ID;
		END IF;
		LEAVE SP_SAVE;
	END IF;



	-- 7) VALIDATE
	-- _______________________________________________________________________

	-- Access Rights [Device]
	-- ####################################################
	IF `ACCOUNT_DEVICE@HAS_PERMISSION`(PARAM_REQUESTER_DEVICE_PUBLIC_KEY, PARAM_REQUESTER_DEVICE_PRIVATE_KEY) = 0 THEN
		SET TEMP_ERR_MESSAGE = 'Your device is not authorized yet to access this server.';
		SET ERR = `RAISERROR`(TEMP_ERR_MESSAGE);		
	END IF;
		
		
	-- Access Rights [Account]
	-- ####################################################
	
	IF 
		-- [ADD] Access Rights
		(
			TEMP_RECORD_EXISTS = 0 AND
			`ACCOUNT_ACCESS_RIGHTS@HAS_PERMISSION`(PARAM_REQUESTER_USERNAME, PARAM_REQUESTER_PASSWORD, 0, TEMP_MODULE_KEYWORD, 2) = 0 
		) OR
		
		-- [EDIT] Access Rights
		(
			TEMP_RECORD_EXISTS = 1 AND
			`ACCOUNT_ACCESS_RIGHTS@HAS_PERMISSION`(PARAM_REQUESTER_USERNAME, PARAM_REQUESTER_PASSWORD, 0, TEMP_MODULE_KEYWORD, 3) = 0 
		)
	THEN
		SET TEMP_ACCESS_RIGHTS_DENIED = 1;
		CALL `ACCOUNT_ACCESS_RIGHTS_DENY`
		(
			0, TEMP_MODULE_KEYWORD, PARAM_ADD_ULICENSE_ID, 0, TEMP_SP_OBJECTIVE, TEMP_RECORD_CHANGES, 
			PARAM_REQUESTER_USERNAME, PARAM_REQUESTER_PASSWORD, 
			PARAM_REQUESTER_PROXY_ID, PARAM_REQUESTER_PROXY_PASSWORD,
			PARAM_REQUESTER_DEVICE_PUBLIC_KEY, PARAM_REQUESTER_DEVICE_PRIVATE_KEY,
			PARAM_REQUESTER_IP, PARAM_UNIQUE_SESSION_ID,
			TEMP_SYNC_SERVER_ID, PARAM_SUPPRESS_RETURN
		);
	END IF;
	SET TEMP_ACCESS_RIGHTS_HAS_OVERRIDE = `ACCOUNT_ACCESS_RIGHTS@HAS_PERMISSION`(PARAM_REQUESTER_USERNAME, PARAM_REQUESTER_PASSWORD, 0, TEMP_MODULE_KEYWORD, 4);
	

	-- Validation
	-- ####################################################
	IF TEMP_SYNC_IS_SERVER_REQUEST = 0 THEN
	
		-- SYSTEM GENERATED = TRUE
		-- ...........................................
		IF TEMP_ADD_ULICENSE_SYSTEM_GENERATED = STATUS_ACTIVE THEN
		CALL `VALIDATION_SYSTEM_GENERATED`
		(
			PARAM_ADD_ULICENSE_ID,
			TEMP_ADD_ULICENSE_ACC_ACCOUNT_ID, ''
		);
		END IF;

		-- FOREIGN KEY EXISTS
		-- ...........................................
		IF `ACCOUNT_MEMBER@ACC_ACCOUNT_ID_EXISTS`(PARAM_ADD_ULICENSE_ACC_ACCOUNT_ID, 0) =  0 THEN
			SET TEMP_ERR_MESSAGE = CONCAT_WS(' ', 'Given User Account does not exists or is inactive. ID: ', PARAM_ADD_ULICENSE_ACC_ACCOUNT_ID);
			SET ERR = `RAISERROR`(TEMP_ERR_MESSAGE);
		END IF;
		
		-- FOREIGN (OPTIONAL)KEY EXISTS [Validates if not null]
		-- ...........................................
		
		-- IS_ALLOW_NULL = FALSE
		-- ...........................................
				
		-- IS_ALLOW_ZERO = FALSE
		-- ...........................................
		IF PARAM_ADD_ULICENSE_STATUS = 0 THEN
			CALL `VALIDATION_MISSING_FIELD`('`ADD_ULICENSE_STATUS`', '`NULL`');
		END IF;		
		IF PARAM_ADD_ULICENSE_SYSTEM_GENERATED = 0 THEN
			CALL `VALIDATION_MISSING_FIELD`('`ADD_ULICENSE_SYSTEM_GENERATED`', '`NULL`');
		END IF;		
		
		-- IS_ALLOW_NEGATIVE = FALSE
		-- ...........................................
		IF PARAM_ADD_ULICENSE_VOLUME < 0 THEN
			CALL `VALIDATION_NEGATIVE`('`ADD_ULICENSE_VOLUME`', PARAM_ADD_ULICENSE_VOLUME);
		END IF;		
		IF PARAM_ADD_ULICENSE_STATUS < 0 THEN
			CALL `VALIDATION_NEGATIVE`('`ADD_ULICENSE_STATUS`', PARAM_ADD_ULICENSE_STATUS);
		END IF;		
		IF PARAM_ADD_ULICENSE_SYSTEM_GENERATED < 0 THEN
			CALL `VALIDATION_NEGATIVE`('`ADD_ULICENSE_SYSTEM_GENERATED`', PARAM_ADD_ULICENSE_SYSTEM_GENERATED);
		END IF;		
		
		-- IS_ALLOW_EMPTY_STRING = FALSE
		-- ...........................................
		IF `SYSTEM_VAR@IS_NULL@DATETIME`(PARAM_ADD_ULICENSE_DATE_RENEW, 1) = 1 THEN
			CALL `VALIDATION_MISSING_FIELD`('`ADD_ULICENSE_DATE_RENEW`', '`NULL`');
		END IF;
		IF `SYSTEM_VAR@IS_NULL@DATETIME`(PARAM_ADD_ULICENSE_DATE_EXPIRY, 1) = 1 THEN
			CALL `VALIDATION_MISSING_FIELD`('`ADD_ULICENSE_DATE_EXPIRY`', '`NULL`');
		END IF;
		
		-- IS_STATUS
		-- ...........................................
		IF `SYSTEM_STATUS@SYS_STATUS_ID_EXISTS`(PARAM_ADD_ULICENSE_STATUS, 0) = 0 THEN
			SET TEMP_ERR_MESSAGE = CONCAT_WS(' ', 'Given STATUS[Status] does not exists or is inactive. ID: ', PARAM_ADD_ULICENSE_STATUS);
			SET ERR = `RAISERROR`(TEMP_ERR_MESSAGE);
		END IF;
		
		-- IS STATUS Active / Inactive
		-- ...........................................
		
		-- Minimum / Maximum Value
		-- ...........................................
		
		-- IS_UNIQUE = TRUE
		-- ...........................................
		IF
		(
			SELECT COUNT(`addon_license_user`.`ADD_ULICENSE_ID`)
			FROM `addon_license_user`
			WHERE		
				`addon_license_user`.`ADD_ULICENSE_ACC_ACCOUNT_ID` = PARAM_ADD_ULICENSE_ACC_ACCOUNT_ID AND		
				`addon_license_user`.`ADD_ULICENSE_ID` <> PARAM_ADD_ULICENSE_ID
		) >= 1
		THEN
			CALL `VALIDATION_REDUNDANT_ENTRY`(PARAM_ADD_ULICENSE_ACC_ACCOUNT_ID);
		END IF;
		
		-- RECORD IDENTIFIER
		-- ...........................................
		
		
		-- ON_UPDATE VALIDATION 
		-- ...........................................
		IF TEMP_RECORD_EXISTS = 1 THEN	
		
			-- Just to keep at least one line within condition
			SET TEMP_RECORD_EXISTS = 1;
			
		END IF;
		
	END IF;



	-- 8) INSERT / UPDATE
	-- _______________________________________________________________________

	-- INSERT NEW DATA
	-- ####################################################
	IF TEMP_RECORD_EXISTS = 0 THEN

		INSERT INTO
		`addon_license_user`
		(
			`addon_license_user`.`ADD_ULICENSE_ACC_ACCOUNT_ID`, 
			`addon_license_user`.`ADD_ULICENSE_DATE_RENEW`, 
			`addon_license_user`.`ADD_ULICENSE_DATE_EXPIRY`, 
			`addon_license_user`.`ADD_ULICENSE_VOLUME`, 
			`addon_license_user`.`ADD_ULICENSE_STATUS`, 
			`addon_license_user`.`ADD_ULICENSE_SYSTEM_GENERATED`
		)
		VALUES
		(
			PARAM_ADD_ULICENSE_ACC_ACCOUNT_ID, 
			PARAM_ADD_ULICENSE_DATE_RENEW, 
			PARAM_ADD_ULICENSE_DATE_EXPIRY, 
			PARAM_ADD_ULICENSE_VOLUME, 
			PARAM_ADD_ULICENSE_STATUS, 
			PARAM_ADD_ULICENSE_SYSTEM_GENERATED
		);	
		
		-- Update Audit trail with new ID	
		SET PARAM_ADD_ULICENSE_ID = LAST_INSERT_ID();



	-- UPDATING EXISTING RECORD
	-- ####################################################
	ELSE
		UPDATE `addon_license_user`
		SET
			`addon_license_user`.`ADD_ULICENSE_ACC_ACCOUNT_ID` = PARAM_ADD_ULICENSE_ACC_ACCOUNT_ID, 
			`addon_license_user`.`ADD_ULICENSE_DATE_RENEW` = PARAM_ADD_ULICENSE_DATE_RENEW, 
			`addon_license_user`.`ADD_ULICENSE_DATE_EXPIRY` = PARAM_ADD_ULICENSE_DATE_EXPIRY, 
			`addon_license_user`.`ADD_ULICENSE_VOLUME` = PARAM_ADD_ULICENSE_VOLUME, 
			`addon_license_user`.`ADD_ULICENSE_STATUS` = PARAM_ADD_ULICENSE_STATUS, 
			`addon_license_user`.`ADD_ULICENSE_SYSTEM_GENERATED` = PARAM_ADD_ULICENSE_SYSTEM_GENERATED
		WHERE
			`addon_license_user`.`ADD_ULICENSE_ID` = PARAM_ADD_ULICENSE_ID;

	END IF;

	
	-- 9) AUDIT TRAIL
	-- _______________________________________________________________________
	CALL `ACCOUNT_AUDIT_TRAIL_SAVE`
	(
		0, TEMP_MODULE_KEYWORD, PARAM_ADD_ULICENSE_ID, 0, 'SAVE', TEMP_SP_OBJECTIVE, TEMP_RECORD_CHANGES, 
		PARAM_REQUESTER_USERNAME, PARAM_REQUESTER_PASSWORD, 
		PARAM_REQUESTER_PROXY_ID, PARAM_REQUESTER_PROXY_PASSWORD,
		PARAM_REQUESTER_DEVICE_PUBLIC_KEY, PARAM_REQUESTER_DEVICE_PRIVATE_KEY,
		PARAM_REQUESTER_IP, PARAM_UNIQUE_SESSION_ID,
		TEMP_SYNC_SERVER_ID, PARAM_SUPPRESS_RETURN
	);
	

	-- 10) RETURN RESULT
	-- _______________________________________________________________________
	IF PARAM_SUPPRESS_RETURN = 0 THEN
		SELECT 
			PARAM_ADD_ULICENSE_ID AS INSERTED_ID,
			TEMP_NOW AS SERVER_TIME;
	END IF;
	LEAVE SP_SAVE;


END ;;
DELIMITER ;
/*!50003 SET sql_mode              = @saved_sql_mode */ ;
/*!50003 SET character_set_client  = @saved_cs_client */ ;
/*!50003 SET character_set_results = @saved_cs_results */ ;
/*!50003 SET collation_connection  = @saved_col_connection */ ;
/*!50003 DROP PROCEDURE IF EXISTS `ADDON_QUEUING_DELETE` */;
/*!50003 SET @saved_cs_client      = @@character_set_client */ ;
/*!50003 SET @saved_cs_results     = @@character_set_results */ ;
/*!50003 SET @saved_col_connection = @@collation_connection */ ;
/*!50003 SET character_set_client  = latin1 */ ;
/*!50003 SET character_set_results = latin1 */ ;
/*!50003 SET collation_connection  = latin1_swedish_ci */ ;
/*!50003 SET @saved_sql_mode       = @@sql_mode */ ;
/*!50003 SET sql_mode              = '' */ ;
DELIMITER ;;
CREATE DEFINER=`root`@`localhost` PROCEDURE `ADDON_QUEUING_DELETE`(
	IN `PARAM_ADD_QUEUING_ID` BIGINT,

	IN `PARAM_REQUESTER_USERNAME` VARCHAR(500),
	IN `PARAM_REQUESTER_PASSWORD` VARCHAR(500),
	IN `PARAM_REQUESTER_PROXY_ID` BIGINT,
	IN `PARAM_REQUESTER_PROXY_PASSWORD` VARCHAR(1000),
	IN `PARAM_REQUESTER_DEVICE_PUBLIC_KEY` VARCHAR(1000),
	IN `PARAM_REQUESTER_DEVICE_PRIVATE_KEY` VARCHAR(1000),
	
	IN `PARAM_REQUESTER_IP` VARCHAR(1000),
	IN `PARAM_UNIQUE_SESSION_ID` VARCHAR(1000),
	IN `PARAM_SUPPRESS_RETURN` BIT,
	
	IN `PARAM_SYNC_SERVER_DESCRIPTION` VARCHAR(500), 
	IN `PARAM_SYNC_SERVER_UNIQUE_KEY` VARCHAR(500)
)
SP_DELETE:
BEGIN

	-- 1) DECLARE LOCAL PARAMETERS
	-- _______________________________________________________________________
	
	-- Status
	-- ...........................................
	DECLARE STATUS_INACTIVE TINYINT DEFAULT 1;
	DECLARE STATUS_ACTIVE TINYINT DEFAULT 2;
	DECLARE STATUS_CLOSED TINYINT DEFAULT 3;
	DECLARE STATUS_COMPLETED TINYINT DEFAULT 4;
	
	-- Audit Handler
	-- ...........................................
	DECLARE TEMP_RECORD_EXISTS BIT DEFAULT 0;
	DECLARE TEMP_MODULE_KEYWORD VARCHAR(500) DEFAULT 'addon_queuing';
	DECLARE TEMP_SP_OBJECTIVE VARCHAR(500) DEFAULT 'delete Queuing record';
	DECLARE TEMP_ERR_MESSAGE VARCHAR(500) DEFAULT '';
	DECLARE ERR BIGINT DEFAULT 0;
	DECLARE TEMP_RECORD_CHANGES VARCHAR(16000) DEFAULT '';
	DECLARE TEMP_RECORD_BINDED BIT DEFAULT 0;
	
	DECLARE TEMP_RECORD_BINDED_ID BIGINT DEFAULT 0;
	DECLARE TEMP_RECORD_BINDED_SERVER_ID BIGINT DEFAULT 0;
	
	-- Authentication
	-- ...........................................
	DECLARE TEMP_ACCESS_RIGHTS_DENIED BIT DEFAULT 0;
	DECLARE TEMP_SYNC_SERVER_ID BIGINT DEFAULT 0;
	DECLARE TEMP_SYNC_IS_SERVER_REQUEST BIT DEFAULT 0;
	DECLARE TEMP_AUTHENTICATED_ACCOUNT_ID BIGINT DEFAULT `ACCOUNT_MEMBER@ACC_ACCOUNT_ID_FROM_LOGIN`(PARAM_REQUESTER_USERNAME, PARAM_REQUESTER_PASSWORD);
	DECLARE TEMP_AUTHENTICATED_ACCOUNT_LEVEL BIGINT DEFAULT 0;
	DECLARE TEMP_AUTHENTICATED_ACCOUNT_GROUP BIGINT DEFAULT 0;

	-- Local value holder
	-- ...........................................
	DECLARE TEMP_ADD_QUEUING_NUMBER BIGINT DEFAULT 0; 
	DECLARE TEMP_ADD_QUEUING_EXTRA_VALUE VARCHAR(5000) DEFAULT ''; 
	DECLARE TEMP_ADD_QUEUING_PUBLIC_KEY VARCHAR(500) DEFAULT ''; 
	DECLARE TEMP_ADD_QUEUING_STATION VARCHAR(500) DEFAULT ''; 
	DECLARE TEMP_ADD_QUEUING_REMARKS VARCHAR(4000) DEFAULT ''; 
	DECLARE TEMP_ADD_QUEUING_DATE_REQUEST DATETIME(6) DEFAULT '1000-01-01 00:00:00.000000'; 
	DECLARE TEMP_ADD_QUEUING_DATE_PROCESSED DATETIME(6) DEFAULT '1000-01-01 00:00:00.000000'; 
	DECLARE TEMP_ADD_QUEUING_DATE_LAST_CALLED DATETIME(6) DEFAULT '1000-01-01 00:00:00.000000'; 
	DECLARE TEMP_ADD_QUEUING_DATE_LAST_DISPLAYED DATETIME(6) DEFAULT '1000-01-01 00:00:00.000000'; 
	DECLARE TEMP_ADD_QUEUING_STATUS TINYINT DEFAULT 0; 

	
	
	-- 2) Try Catch / Throw
	-- _______________________________________________________________________
	DECLARE EXIT HANDLER FOR SQLEXCEPTION
	BEGIN
		RESIGNAL;
	END;

	
	-- 3) Prepare SYNC
	-- _______________________________________________________________________
	
	-- IS RECORD EXISTS		
	-- ####################################################		
	SET TEMP_RECORD_EXISTS = `ADDON_QUEUING@ADD_QUEUING_ID_EXISTS`(PARAM_ADD_QUEUING_ID, 0);


	-- 4) IF ALREADY EXIST, FILL MISSING DATA
	-- _______________________________________________________________________
	IF TEMP_RECORD_EXISTS = 1 THEN
		SELECT
				`addon_queuing`.`ADD_QUEUING_NUMBER`, 	
				`addon_queuing`.`ADD_QUEUING_EXTRA_VALUE`, 	
				`addon_queuing`.`ADD_QUEUING_PUBLIC_KEY`, 	
				`addon_queuing`.`ADD_QUEUING_STATION`, 	
				`addon_queuing`.`ADD_QUEUING_REMARKS`, 	
				`addon_queuing`.`ADD_QUEUING_DATE_REQUEST`, 	
				`addon_queuing`.`ADD_QUEUING_DATE_PROCESSED`, 	
				`addon_queuing`.`ADD_QUEUING_DATE_LAST_CALLED`, 	
				`addon_queuing`.`ADD_QUEUING_DATE_LAST_DISPLAYED`, 	
				`addon_queuing`.`ADD_QUEUING_STATUS`	
		INTO
				TEMP_ADD_QUEUING_NUMBER, 	
				TEMP_ADD_QUEUING_EXTRA_VALUE, 	
				TEMP_ADD_QUEUING_PUBLIC_KEY, 	
				TEMP_ADD_QUEUING_STATION, 	
				TEMP_ADD_QUEUING_REMARKS, 	
				TEMP_ADD_QUEUING_DATE_REQUEST, 	
				TEMP_ADD_QUEUING_DATE_PROCESSED, 	
				TEMP_ADD_QUEUING_DATE_LAST_CALLED, 	
				TEMP_ADD_QUEUING_DATE_LAST_DISPLAYED, 	
				TEMP_ADD_QUEUING_STATUS	

		FROM `addon_queuing`
		WHERE
			`addon_queuing`.`ADD_QUEUING_ID` = PARAM_ADD_QUEUING_ID
		LIMIT 1;

	ELSE 
		IF TEMP_SYNC_IS_SERVER_REQUEST = 0 THEN
			SET TEMP_ERR_MESSAGE = CONCAT_WS(' ', 'Given Queuing does not exists or is inactive. ID:', PARAM_ADD_QUEUING_ID);
			SET ERR = `RAISERROR`(TEMP_ERR_MESSAGE);		
		END IF;
		LEAVE SP_DELETE;
		
	END IF;



	-- 5) PREPARE AUDIT TRAIL
	-- _______________________________________________________________________
	
		SET TEMP_RECORD_CHANGES = 
		`SYSTEM_VAR@CONCAT_ADD`(' | ', TEMP_RECORD_CHANGES, CONCAT_WS(' ', 'Queuing Number: "', TEMP_ADD_QUEUING_NUMBER, '" > " DELETED "'));
		SET TEMP_RECORD_CHANGES = 
		`SYSTEM_VAR@CONCAT_ADD`(' | ', TEMP_RECORD_CHANGES, CONCAT_WS(' ', 'Request details to Forward: "', TEMP_ADD_QUEUING_EXTRA_VALUE, '" > " DELETED "'));
		SET TEMP_RECORD_CHANGES = 
		`SYSTEM_VAR@CONCAT_ADD`(' | ', TEMP_RECORD_CHANGES, CONCAT_WS(' ', 'Device Public Key: "', TEMP_ADD_QUEUING_PUBLIC_KEY, '" > " DELETED "'));
		SET TEMP_RECORD_CHANGES = 
		`SYSTEM_VAR@CONCAT_ADD`(' | ', TEMP_RECORD_CHANGES, CONCAT_WS(' ', 'Processing Workstation (Teller) Name: "', TEMP_ADD_QUEUING_STATION, '" > " DELETED "'));
		SET TEMP_RECORD_CHANGES = 
		`SYSTEM_VAR@CONCAT_ADD`(' | ', TEMP_RECORD_CHANGES, CONCAT_WS(' ', 'Remarks: "', TEMP_ADD_QUEUING_REMARKS, '" > " DELETED "'));
		SET TEMP_RECORD_CHANGES = 
		`SYSTEM_VAR@CONCAT_ADD`(' | ', TEMP_RECORD_CHANGES, CONCAT_WS(' ', 'Date Requested: "', TEMP_ADD_QUEUING_DATE_REQUEST, '" > " DELETED "'));
		SET TEMP_RECORD_CHANGES = 
		`SYSTEM_VAR@CONCAT_ADD`(' | ', TEMP_RECORD_CHANGES, CONCAT_WS(' ', 'Date Processed: "', TEMP_ADD_QUEUING_DATE_PROCESSED, '" > " DELETED "'));
		SET TEMP_RECORD_CHANGES = 
		`SYSTEM_VAR@CONCAT_ADD`(' | ', TEMP_RECORD_CHANGES, CONCAT_WS(' ', 'Time Last Called: "', TEMP_ADD_QUEUING_DATE_LAST_CALLED, '" > " DELETED "'));
		SET TEMP_RECORD_CHANGES = 
		`SYSTEM_VAR@CONCAT_ADD`(' | ', TEMP_RECORD_CHANGES, CONCAT_WS(' ', 'Time Last displayed to customer: "', TEMP_ADD_QUEUING_DATE_LAST_DISPLAYED, '" > " DELETED "'));
		SET TEMP_RECORD_CHANGES = 
		`SYSTEM_VAR@CONCAT_ADD`(' | ', TEMP_RECORD_CHANGES, CONCAT_WS(' ', 'Status: "', TEMP_ADD_QUEUING_STATUS, '" > " DELETED "'));


	-- 6) VALIDATE
	-- _______________________________________________________________________
	
	-- Access Rights [Device]
	-- ####################################################
	IF `ACCOUNT_DEVICE@HAS_PERMISSION`(PARAM_REQUESTER_DEVICE_PUBLIC_KEY, PARAM_REQUESTER_DEVICE_PRIVATE_KEY) = 0 THEN
		SET TEMP_ERR_MESSAGE = 'Your device is not authorized yet to access this server.';
		SET ERR = `RAISERROR`(TEMP_ERR_MESSAGE);		
	END IF;
		
		
	-- Access Rights [Account]
	-- ####################################################	
	
	IF 
		-- [DELETE] Access Rights
		`ACCOUNT_ACCESS_RIGHTS@HAS_PERMISSION`(PARAM_REQUESTER_USERNAME, PARAM_REQUESTER_PASSWORD, 0, TEMP_MODULE_KEYWORD, 4) = 0 
	THEN
		SET TEMP_ACCESS_RIGHTS_DENIED = 1;
		CALL `ACCOUNT_ACCESS_RIGHTS_DENY`
		(
			0, TEMP_MODULE_KEYWORD, PARAM_ADD_QUEUING_ID, 0, TEMP_SP_OBJECTIVE, TEMP_RECORD_CHANGES, 
			PARAM_REQUESTER_USERNAME, PARAM_REQUESTER_PASSWORD, 
			PARAM_REQUESTER_PROXY_ID, PARAM_REQUESTER_PROXY_PASSWORD,
			PARAM_REQUESTER_DEVICE_PUBLIC_KEY, PARAM_REQUESTER_DEVICE_PRIVATE_KEY,
			PARAM_REQUESTER_IP, PARAM_UNIQUE_SESSION_ID,
			TEMP_SYNC_SERVER_ID, PARAM_SUPPRESS_RETURN
		);
	END IF;

	
	-- If already used, cannot remove record
	-- ####################################################

	-- Leave Re-upload request
	-- ####################################################
	IF TEMP_RECORD_BINDED = 1 THEN
		IF TEMP_SYNC_IS_SERVER_REQUEST = 1 THEN
			
			LEAVE SP_DELETE;
		END IF;

		CALL `VALIDATION_DELETE_LINKED_RECORD`(TEMP_ADD_QUEUING_STATION, '', TEMP_ERR_MESSAGE); 
	END IF;


	-- 7) DELETE
	-- _______________________________________________________________________
	DELETE FROM `addon_queuing`
	WHERE `addon_queuing`.`ADD_QUEUING_ID` = PARAM_ADD_QUEUING_ID
	LIMIT 1;


	-- 8) AUDIT TRAIL
	-- _______________________________________________________________________
	CALL `ACCOUNT_AUDIT_TRAIL_SAVE`
	(
		0, TEMP_MODULE_KEYWORD, PARAM_ADD_QUEUING_ID, 0, 'DELETE', TEMP_SP_OBJECTIVE, TEMP_RECORD_CHANGES, 
		PARAM_REQUESTER_USERNAME, PARAM_REQUESTER_PASSWORD, 
		PARAM_REQUESTER_PROXY_ID, PARAM_REQUESTER_PROXY_PASSWORD,
		PARAM_REQUESTER_DEVICE_PUBLIC_KEY, PARAM_REQUESTER_DEVICE_PRIVATE_KEY,
		PARAM_REQUESTER_IP, PARAM_UNIQUE_SESSION_ID,
		TEMP_SYNC_SERVER_ID, PARAM_SUPPRESS_RETURN
	);

END ;;
DELIMITER ;
/*!50003 SET sql_mode              = @saved_sql_mode */ ;
/*!50003 SET character_set_client  = @saved_cs_client */ ;
/*!50003 SET character_set_results = @saved_cs_results */ ;
/*!50003 SET collation_connection  = @saved_col_connection */ ;
/*!50003 DROP PROCEDURE IF EXISTS `ADDON_QUEUING_GET` */;
/*!50003 SET @saved_cs_client      = @@character_set_client */ ;
/*!50003 SET @saved_cs_results     = @@character_set_results */ ;
/*!50003 SET @saved_col_connection = @@collation_connection */ ;
/*!50003 SET character_set_client  = latin1 */ ;
/*!50003 SET character_set_results = latin1 */ ;
/*!50003 SET collation_connection  = latin1_swedish_ci */ ;
/*!50003 SET @saved_sql_mode       = @@sql_mode */ ;
/*!50003 SET sql_mode              = '' */ ;
DELIMITER ;;
CREATE DEFINER=`root`@`localhost` PROCEDURE `ADDON_QUEUING_GET`(
	IN `PARAM_ADD_QUEUING_ID` BIGINT,	
	IN `PARAM_ADD_QUEUING_NUMBER_FROM` BIGINT,
	IN `PARAM_ADD_QUEUING_NUMBER_TO` BIGINT,
	IN `PARAM_ADD_QUEUING_EXTRA_VALUE` VARCHAR(5000),	
	IN `PARAM_ADD_QUEUING_PUBLIC_KEY` VARCHAR(500),	
	IN `PARAM_ADD_QUEUING_STATION` VARCHAR(500),	
	IN `PARAM_ADD_QUEUING_REMARKS` VARCHAR(4000),	
	IN `PARAM_ADD_QUEUING_DATE_REQUEST_FROM` DATETIME(6),
	IN `PARAM_ADD_QUEUING_DATE_REQUEST_TO` DATETIME(6),
	IN `PARAM_ADD_QUEUING_DATE_PROCESSED_FROM` DATETIME(6),
	IN `PARAM_ADD_QUEUING_DATE_PROCESSED_TO` DATETIME(6),
	IN `PARAM_ADD_QUEUING_DATE_LAST_CALLED_FROM` DATETIME(6),
	IN `PARAM_ADD_QUEUING_DATE_LAST_CALLED_TO` DATETIME(6),
	IN `PARAM_ADD_QUEUING_DATE_LAST_DISPLAYED_FROM` DATETIME(6),
	IN `PARAM_ADD_QUEUING_DATE_LAST_DISPLAYED_TO` DATETIME(6),
	IN `PARAM_ADD_QUEUING_STATUS` TINYINT,	
		
	IN `PARAM_ORDER_FIELD` VARCHAR(500),
	IN `PARAM_ORDER_TYPE` VARCHAR(500),
	IN `PARAM_SKIP` BIGINT,
	IN `PARAM_LIMIT` BIGINT,

	IN `PARAM_REQUESTER_USERNAME` VARCHAR(500),
	IN `PARAM_REQUESTER_PASSWORD` VARCHAR(500),
	IN `PARAM_REQUESTER_PROXY_ID` BIGINT,
	IN `PARAM_REQUESTER_PROXY_PASSWORD` VARCHAR(1000),
	IN `PARAM_REQUESTER_DEVICE_PUBLIC_KEY` VARCHAR(1000),
	IN `PARAM_REQUESTER_DEVICE_PRIVATE_KEY` VARCHAR(1000),
	
	IN `PARAM_REQUESTER_IP` VARCHAR(1000),
	IN `PARAM_UNIQUE_SESSION_ID` VARCHAR(1000),
	IN `PARAM_SUPPRESS_RETURN` BIT
)
SP_GET:
BEGIN

	-- Status
	-- =========================================================================================
	DECLARE STATUS_INACTIVE TINYINT DEFAULT 1;
	DECLARE STATUS_ACTIVE TINYINT DEFAULT 2;
	DECLARE STATUS_CLOSED TINYINT DEFAULT 3;
	DECLARE STATUS_COMPLETED TINYINT DEFAULT 4;
	
	-- Audit Handler
	-- =========================================================================================
	DECLARE TEMP_RECORD_EXISTS BIT DEFAULT 0;
	DECLARE TEMP_MODULE_KEYWORD VARCHAR(500) DEFAULT 'addon_queuing';
	DECLARE TEMP_SP_OBJECTIVE VARCHAR(500) DEFAULT 'Retrieve Queuing record';
	DECLARE TEMP_ERR_MESSAGE VARCHAR(500) DEFAULT '';
	DECLARE ERR BIGINT DEFAULT 0;
	DECLARE TEMP_RECORD_CHANGES VARCHAR(16000) DEFAULT '';
	DECLARE TEMP_RECORD_BINDED BIT DEFAULT 0;
	
	DECLARE TEMP_RECORD_BINDED_ID BIGINT DEFAULT 0;
	DECLARE TEMP_RECORD_BINDED_SERVER_ID BIGINT DEFAULT 0;
	
	-- Authentication
	-- =========================================================================================
	DECLARE TEMP_ACCESS_RIGHTS_DENIED BIT DEFAULT 0;
	DECLARE TEMP_AUTHENTICATED_ACCOUNT_ID BIGINT DEFAULT `ACCOUNT_MEMBER@ACC_ACCOUNT_ID_FROM_LOGIN`(PARAM_REQUESTER_USERNAME, PARAM_REQUESTER_PASSWORD);
	DECLARE TEMP_AUTHENTICATED_ACCOUNT_LEVEL BIGINT DEFAULT 0;
	DECLARE TEMP_AUTHENTICATED_ACCOUNT_GROUP BIGINT DEFAULT 0;
	
	-- Local Parameters
	-- =========================================================================================
	DECLARE TEMP_NOW DATETIME(6) DEFAULT `SYSTEM_VAR@NOW`('', 1);
	DECLARE TEMP_RECORD_COUNT BIGINT DEFAULT 0;
	
	
	-- Check NULLs
	-- =========================================================================================
	DECLARE IS_NULL_ADD_QUEUING_ID BIT DEFAULT `SYSTEM_VAR@IS_NULL@BIGINT`(PARAM_ADD_QUEUING_ID, 1, 1);
	DECLARE IS_NULL_ADD_QUEUING_NUMBER_FROM BIT DEFAULT `SYSTEM_VAR@IS_NULL@BIGINT`(PARAM_ADD_QUEUING_NUMBER_FROM, 1, 1);
	DECLARE IS_NULL_ADD_QUEUING_NUMBER_TO BIT DEFAULT `SYSTEM_VAR@IS_NULL@BIGINT`(PARAM_ADD_QUEUING_NUMBER_TO, 1, 1);
	DECLARE IS_NULL_ADD_QUEUING_EXTRA_VALUE BIT DEFAULT `SYSTEM_VAR@IS_NULL@NVARCHAR`(PARAM_ADD_QUEUING_EXTRA_VALUE, 1);
	DECLARE IS_NULL_ADD_QUEUING_PUBLIC_KEY BIT DEFAULT `SYSTEM_VAR@IS_NULL@NVARCHAR`(PARAM_ADD_QUEUING_PUBLIC_KEY, 1);
	DECLARE IS_NULL_ADD_QUEUING_STATION BIT DEFAULT `SYSTEM_VAR@IS_NULL@NVARCHAR`(PARAM_ADD_QUEUING_STATION, 0);
	DECLARE IS_NULL_ADD_QUEUING_REMARKS BIT DEFAULT `SYSTEM_VAR@IS_NULL@NVARCHAR`(PARAM_ADD_QUEUING_REMARKS, 0);
	DECLARE IS_NULL_ADD_QUEUING_DATE_REQUEST_FROM BIT DEFAULT `SYSTEM_VAR@IS_NULL@DATETIME`(PARAM_ADD_QUEUING_DATE_REQUEST_FROM, 1);
	DECLARE IS_NULL_ADD_QUEUING_DATE_REQUEST_TO BIT DEFAULT `SYSTEM_VAR@IS_NULL@DATETIME`(PARAM_ADD_QUEUING_DATE_REQUEST_TO, 1);				
	DECLARE IS_NULL_ADD_QUEUING_DATE_PROCESSED_FROM BIT DEFAULT `SYSTEM_VAR@IS_NULL@DATETIME`(PARAM_ADD_QUEUING_DATE_PROCESSED_FROM, 1);
	DECLARE IS_NULL_ADD_QUEUING_DATE_PROCESSED_TO BIT DEFAULT `SYSTEM_VAR@IS_NULL@DATETIME`(PARAM_ADD_QUEUING_DATE_PROCESSED_TO, 1);				
	DECLARE IS_NULL_ADD_QUEUING_DATE_LAST_CALLED_FROM BIT DEFAULT `SYSTEM_VAR@IS_NULL@DATETIME`(PARAM_ADD_QUEUING_DATE_LAST_CALLED_FROM, 1);
	DECLARE IS_NULL_ADD_QUEUING_DATE_LAST_CALLED_TO BIT DEFAULT `SYSTEM_VAR@IS_NULL@DATETIME`(PARAM_ADD_QUEUING_DATE_LAST_CALLED_TO, 1);				
	DECLARE IS_NULL_ADD_QUEUING_DATE_LAST_DISPLAYED_FROM BIT DEFAULT `SYSTEM_VAR@IS_NULL@DATETIME`(PARAM_ADD_QUEUING_DATE_LAST_DISPLAYED_FROM, 1);
	DECLARE IS_NULL_ADD_QUEUING_DATE_LAST_DISPLAYED_TO BIT DEFAULT `SYSTEM_VAR@IS_NULL@DATETIME`(PARAM_ADD_QUEUING_DATE_LAST_DISPLAYED_TO, 1);				
	DECLARE IS_NULL_ADD_QUEUING_STATUS BIT DEFAULT `SYSTEM_VAR@IS_NULL@TINYINT`(PARAM_ADD_QUEUING_STATUS, 1, 1);
	
	-- Error Handler
	-- =========================================================================================
	DECLARE EXIT HANDLER FOR SQLEXCEPTION
	BEGIN
		RESIGNAL;
	END;
	
	-- Ignore Time from DateTime (Set Time 00:00:00.000000 and 23:59:59.999999)
	-- =========================================================================================
		
		
	-- Access Rights [Device]
	-- =========================================================================================
	IF `ACCOUNT_DEVICE@HAS_PERMISSION`(PARAM_REQUESTER_DEVICE_PUBLIC_KEY, PARAM_REQUESTER_DEVICE_PRIVATE_KEY) = 0 THEN
		SET TEMP_ERR_MESSAGE = 'Your device is not authorized yet to access this server.';
		SET ERR = `RAISERROR`(TEMP_ERR_MESSAGE);		
	END IF;
		
		
	-- Access Rights [Account]
	-- =========================================================================================
		
	IF `ACCOUNT_ACCESS_RIGHTS@HAS_PERMISSION`(PARAM_REQUESTER_USERNAME, PARAM_REQUESTER_PASSWORD, 0, TEMP_MODULE_KEYWORD, 1) = 0 THEN
		SET TEMP_ACCESS_RIGHTS_DENIED = 1;
		CALL `ACCOUNT_ACCESS_RIGHTS_DENY`
		(
			0, TEMP_MODULE_KEYWORD, 0, 0, TEMP_SP_OBJECTIVE, TEMP_RECORD_CHANGES, 
			PARAM_REQUESTER_USERNAME, PARAM_REQUESTER_PASSWORD, 
			PARAM_REQUESTER_PROXY_ID, PARAM_REQUESTER_PROXY_PASSWORD,
			PARAM_REQUESTER_DEVICE_PUBLIC_KEY, PARAM_REQUESTER_DEVICE_PRIVATE_KEY,
			PARAM_REQUESTER_IP, PARAM_UNIQUE_SESSION_ID,
			0, PARAM_SUPPRESS_RETURN
		);
	END IF;
	
	
	
	-- COUNT RECORD
	-- =========================================================================================
	
	-- SELECT COLUMNS
	-- ####################################################
	SELECT
		COUNT(DISTINCT `addon_queuing`.`ADD_QUEUING_ID`)
	INTO
		TEMP_RECORD_COUNT

	FROM `addon_queuing`
	
		-- Add Inner Joins (Per Foreign-key)
		
		-- Add Optional Left Joins (Per Optional Foreign-key)
		
	-- CONDITIONS
	-- ####################################################
	WHERE
		(
			IS_NULL_ADD_QUEUING_ID = 1 OR
			`addon_queuing`.`ADD_QUEUING_ID` = PARAM_ADD_QUEUING_ID			
		) AND
		(
			IS_NULL_ADD_QUEUING_NUMBER_FROM = 1 OR
			`addon_queuing`.`ADD_QUEUING_NUMBER` >= PARAM_ADD_QUEUING_NUMBER_FROM			
		) AND
		(
			IS_NULL_ADD_QUEUING_NUMBER_TO = 1 OR
			`addon_queuing`.`ADD_QUEUING_NUMBER` <= PARAM_ADD_QUEUING_NUMBER_TO			
		) AND 		
		(
			IS_NULL_ADD_QUEUING_EXTRA_VALUE = 1 OR
			`addon_queuing`.`ADD_QUEUING_EXTRA_VALUE` LIKE CONCAT_WS('%', '', PARAM_ADD_QUEUING_EXTRA_VALUE, '')			
		) AND 		
		(
			IS_NULL_ADD_QUEUING_PUBLIC_KEY = 1 OR
			`addon_queuing`.`ADD_QUEUING_PUBLIC_KEY` LIKE CONCAT_WS('%', '', PARAM_ADD_QUEUING_PUBLIC_KEY, '')			
		) AND 		
		(
			IS_NULL_ADD_QUEUING_STATION = 1 OR
			`addon_queuing`.`ADD_QUEUING_STATION` LIKE CONCAT_WS('%', '', PARAM_ADD_QUEUING_STATION, '')			
		) AND 		
		(
			IS_NULL_ADD_QUEUING_REMARKS = 1 OR
			`addon_queuing`.`ADD_QUEUING_REMARKS` LIKE CONCAT_WS('%', '', PARAM_ADD_QUEUING_REMARKS, '')			
		) AND 		
		(
			IS_NULL_ADD_QUEUING_DATE_REQUEST_FROM = 1 OR
			`addon_queuing`.`ADD_QUEUING_DATE_REQUEST` >= PARAM_ADD_QUEUING_DATE_REQUEST_FROM			
		) AND
		(
			IS_NULL_ADD_QUEUING_DATE_REQUEST_TO = 1 OR
			`addon_queuing`.`ADD_QUEUING_DATE_REQUEST` <= PARAM_ADD_QUEUING_DATE_REQUEST_TO			
		) AND 		
		(
			IS_NULL_ADD_QUEUING_DATE_PROCESSED_FROM = 1 OR
			`addon_queuing`.`ADD_QUEUING_DATE_PROCESSED` >= PARAM_ADD_QUEUING_DATE_PROCESSED_FROM			
		) AND
		(
			IS_NULL_ADD_QUEUING_DATE_PROCESSED_TO = 1 OR
			`addon_queuing`.`ADD_QUEUING_DATE_PROCESSED` <= PARAM_ADD_QUEUING_DATE_PROCESSED_TO			
		) AND 		
		(
			IS_NULL_ADD_QUEUING_DATE_LAST_CALLED_FROM = 1 OR
			`addon_queuing`.`ADD_QUEUING_DATE_LAST_CALLED` >= PARAM_ADD_QUEUING_DATE_LAST_CALLED_FROM			
		) AND
		(
			IS_NULL_ADD_QUEUING_DATE_LAST_CALLED_TO = 1 OR
			`addon_queuing`.`ADD_QUEUING_DATE_LAST_CALLED` <= PARAM_ADD_QUEUING_DATE_LAST_CALLED_TO			
		) AND 		
		(
			IS_NULL_ADD_QUEUING_DATE_LAST_DISPLAYED_FROM = 1 OR
			`addon_queuing`.`ADD_QUEUING_DATE_LAST_DISPLAYED` >= PARAM_ADD_QUEUING_DATE_LAST_DISPLAYED_FROM			
		) AND
		(
			IS_NULL_ADD_QUEUING_DATE_LAST_DISPLAYED_TO = 1 OR
			`addon_queuing`.`ADD_QUEUING_DATE_LAST_DISPLAYED` <= PARAM_ADD_QUEUING_DATE_LAST_DISPLAYED_TO			
		) AND 		
		(
			IS_NULL_ADD_QUEUING_STATUS = 1 OR
			`addon_queuing`.`ADD_QUEUING_STATUS` = PARAM_ADD_QUEUING_STATUS			
		) 
;	

		
		
	-- SELECT RECORDS
	-- =========================================================================================
	
	-- FETCH COLUMNS
	-- ####################################################
	SELECT
		-- ADDON_QUEUING DETAILS
		`addon_queuing`.`ADD_QUEUING_ID`, 
		`addon_queuing`.`ADD_QUEUING_NUMBER`, 
		`addon_queuing`.`ADD_QUEUING_EXTRA_VALUE`, 
		`addon_queuing`.`ADD_QUEUING_PUBLIC_KEY`, 
		`addon_queuing`.`ADD_QUEUING_STATION`, 
		`addon_queuing`.`ADD_QUEUING_REMARKS`, 
		`addon_queuing`.`ADD_QUEUING_DATE_REQUEST`, 
		`addon_queuing`.`ADD_QUEUING_DATE_PROCESSED`, 
		`addon_queuing`.`ADD_QUEUING_DATE_LAST_CALLED`, 
		`addon_queuing`.`ADD_QUEUING_DATE_LAST_DISPLAYED`, 
		`addon_queuing`.`ADD_QUEUING_STATUS`
		
		-- Inner join fields
		
		-- Left join fields
		
		, TEMP_RECORD_COUNT AS RECORD_COUNT

	FROM `addon_queuing`
	
		-- Add Inner Joins (Per Foreign-key)
		
		-- Add Optional Left Joins (Per Optional Foreign-key)
		
	-- CONDITIONS
	-- ####################################################
	WHERE
		(
			IS_NULL_ADD_QUEUING_ID = 1 OR
			`addon_queuing`.`ADD_QUEUING_ID` = PARAM_ADD_QUEUING_ID			
		) AND
		(
			IS_NULL_ADD_QUEUING_NUMBER_FROM = 1 OR
			`addon_queuing`.`ADD_QUEUING_NUMBER` >= PARAM_ADD_QUEUING_NUMBER_FROM			
		) AND
		(
			IS_NULL_ADD_QUEUING_NUMBER_TO = 1 OR
			`addon_queuing`.`ADD_QUEUING_NUMBER` <= PARAM_ADD_QUEUING_NUMBER_TO			
		) AND 
		(
			IS_NULL_ADD_QUEUING_EXTRA_VALUE = 1 OR
			`addon_queuing`.`ADD_QUEUING_EXTRA_VALUE` LIKE CONCAT_WS('%', '', PARAM_ADD_QUEUING_EXTRA_VALUE, '')			
		) AND 		
		(
			IS_NULL_ADD_QUEUING_PUBLIC_KEY = 1 OR
			`addon_queuing`.`ADD_QUEUING_PUBLIC_KEY` LIKE CONCAT_WS('%', '', PARAM_ADD_QUEUING_PUBLIC_KEY, '')			
		) AND 		
		(
			IS_NULL_ADD_QUEUING_STATION = 1 OR
			`addon_queuing`.`ADD_QUEUING_STATION` LIKE CONCAT_WS('%', '', PARAM_ADD_QUEUING_STATION, '')			
		) AND 		
		(
			IS_NULL_ADD_QUEUING_REMARKS = 1 OR
			`addon_queuing`.`ADD_QUEUING_REMARKS` LIKE CONCAT_WS('%', '', PARAM_ADD_QUEUING_REMARKS, '')			
		) AND 		
		(
			IS_NULL_ADD_QUEUING_DATE_REQUEST_FROM = 1 OR
			`addon_queuing`.`ADD_QUEUING_DATE_REQUEST` >= PARAM_ADD_QUEUING_DATE_REQUEST_FROM			
		) AND
		(
			IS_NULL_ADD_QUEUING_DATE_REQUEST_TO = 1 OR
			`addon_queuing`.`ADD_QUEUING_DATE_REQUEST` <= PARAM_ADD_QUEUING_DATE_REQUEST_TO			
		) AND 
		(
			IS_NULL_ADD_QUEUING_DATE_PROCESSED_FROM = 1 OR
			`addon_queuing`.`ADD_QUEUING_DATE_PROCESSED` >= PARAM_ADD_QUEUING_DATE_PROCESSED_FROM			
		) AND
		(
			IS_NULL_ADD_QUEUING_DATE_PROCESSED_TO = 1 OR
			`addon_queuing`.`ADD_QUEUING_DATE_PROCESSED` <= PARAM_ADD_QUEUING_DATE_PROCESSED_TO			
		) AND 
		(
			IS_NULL_ADD_QUEUING_DATE_LAST_CALLED_FROM = 1 OR
			`addon_queuing`.`ADD_QUEUING_DATE_LAST_CALLED` >= PARAM_ADD_QUEUING_DATE_LAST_CALLED_FROM			
		) AND
		(
			IS_NULL_ADD_QUEUING_DATE_LAST_CALLED_TO = 1 OR
			`addon_queuing`.`ADD_QUEUING_DATE_LAST_CALLED` <= PARAM_ADD_QUEUING_DATE_LAST_CALLED_TO			
		) AND 
		(
			IS_NULL_ADD_QUEUING_DATE_LAST_DISPLAYED_FROM = 1 OR
			`addon_queuing`.`ADD_QUEUING_DATE_LAST_DISPLAYED` >= PARAM_ADD_QUEUING_DATE_LAST_DISPLAYED_FROM			
		) AND
		(
			IS_NULL_ADD_QUEUING_DATE_LAST_DISPLAYED_TO = 1 OR
			`addon_queuing`.`ADD_QUEUING_DATE_LAST_DISPLAYED` <= PARAM_ADD_QUEUING_DATE_LAST_DISPLAYED_TO			
		) AND 
		(
			IS_NULL_ADD_QUEUING_STATUS = 1 OR
			`addon_queuing`.`ADD_QUEUING_STATUS` = PARAM_ADD_QUEUING_STATUS			
		) 

	-- ORDER BY
	-- ####################################################
	ORDER BY
		-- ADDON_QUEUING DETAILS
		CASE WHEN PARAM_ORDER_FIELD = 'ADD_QUEUING_ID' AND PARAM_ORDER_TYPE = 'ASC' THEN `addon_queuing`.`ADD_QUEUING_ID` END ASC, 
		CASE WHEN PARAM_ORDER_FIELD = 'ADD_QUEUING_ID' AND PARAM_ORDER_TYPE = 'DESC' THEN `addon_queuing`.`ADD_QUEUING_ID` END DESC,	
		CASE WHEN PARAM_ORDER_FIELD = 'ADD_QUEUING_NUMBER' AND PARAM_ORDER_TYPE = 'ASC' THEN `addon_queuing`.`ADD_QUEUING_NUMBER` END ASC, 
		CASE WHEN PARAM_ORDER_FIELD = 'ADD_QUEUING_NUMBER' AND PARAM_ORDER_TYPE = 'DESC' THEN `addon_queuing`.`ADD_QUEUING_NUMBER` END DESC,	
		CASE WHEN PARAM_ORDER_FIELD = 'ADD_QUEUING_EXTRA_VALUE' AND PARAM_ORDER_TYPE = 'ASC' THEN `addon_queuing`.`ADD_QUEUING_EXTRA_VALUE` END ASC, 
		CASE WHEN PARAM_ORDER_FIELD = 'ADD_QUEUING_EXTRA_VALUE' AND PARAM_ORDER_TYPE = 'DESC' THEN `addon_queuing`.`ADD_QUEUING_EXTRA_VALUE` END DESC,	
		CASE WHEN PARAM_ORDER_FIELD = 'ADD_QUEUING_PUBLIC_KEY' AND PARAM_ORDER_TYPE = 'ASC' THEN `addon_queuing`.`ADD_QUEUING_PUBLIC_KEY` END ASC, 
		CASE WHEN PARAM_ORDER_FIELD = 'ADD_QUEUING_PUBLIC_KEY' AND PARAM_ORDER_TYPE = 'DESC' THEN `addon_queuing`.`ADD_QUEUING_PUBLIC_KEY` END DESC,	
		CASE WHEN PARAM_ORDER_FIELD = 'ADD_QUEUING_STATION' AND PARAM_ORDER_TYPE = 'ASC' THEN `addon_queuing`.`ADD_QUEUING_STATION` END ASC, 
		CASE WHEN PARAM_ORDER_FIELD = 'ADD_QUEUING_STATION' AND PARAM_ORDER_TYPE = 'DESC' THEN `addon_queuing`.`ADD_QUEUING_STATION` END DESC,	
		CASE WHEN PARAM_ORDER_FIELD = 'ADD_QUEUING_REMARKS' AND PARAM_ORDER_TYPE = 'ASC' THEN `addon_queuing`.`ADD_QUEUING_REMARKS` END ASC, 
		CASE WHEN PARAM_ORDER_FIELD = 'ADD_QUEUING_REMARKS' AND PARAM_ORDER_TYPE = 'DESC' THEN `addon_queuing`.`ADD_QUEUING_REMARKS` END DESC,	
		CASE WHEN PARAM_ORDER_FIELD = 'ADD_QUEUING_DATE_REQUEST' AND PARAM_ORDER_TYPE = 'ASC' THEN `addon_queuing`.`ADD_QUEUING_DATE_REQUEST` END ASC, 
		CASE WHEN PARAM_ORDER_FIELD = 'ADD_QUEUING_DATE_REQUEST' AND PARAM_ORDER_TYPE = 'DESC' THEN `addon_queuing`.`ADD_QUEUING_DATE_REQUEST` END DESC,	
		CASE WHEN PARAM_ORDER_FIELD = 'ADD_QUEUING_DATE_PROCESSED' AND PARAM_ORDER_TYPE = 'ASC' THEN `addon_queuing`.`ADD_QUEUING_DATE_PROCESSED` END ASC, 
		CASE WHEN PARAM_ORDER_FIELD = 'ADD_QUEUING_DATE_PROCESSED' AND PARAM_ORDER_TYPE = 'DESC' THEN `addon_queuing`.`ADD_QUEUING_DATE_PROCESSED` END DESC,	
		CASE WHEN PARAM_ORDER_FIELD = 'ADD_QUEUING_DATE_LAST_CALLED' AND PARAM_ORDER_TYPE = 'ASC' THEN `addon_queuing`.`ADD_QUEUING_DATE_LAST_CALLED` END ASC, 
		CASE WHEN PARAM_ORDER_FIELD = 'ADD_QUEUING_DATE_LAST_CALLED' AND PARAM_ORDER_TYPE = 'DESC' THEN `addon_queuing`.`ADD_QUEUING_DATE_LAST_CALLED` END DESC,	
		CASE WHEN PARAM_ORDER_FIELD = 'ADD_QUEUING_DATE_LAST_DISPLAYED' AND PARAM_ORDER_TYPE = 'ASC' THEN `addon_queuing`.`ADD_QUEUING_DATE_LAST_DISPLAYED` END ASC, 
		CASE WHEN PARAM_ORDER_FIELD = 'ADD_QUEUING_DATE_LAST_DISPLAYED' AND PARAM_ORDER_TYPE = 'DESC' THEN `addon_queuing`.`ADD_QUEUING_DATE_LAST_DISPLAYED` END DESC,	
		CASE WHEN PARAM_ORDER_FIELD = 'ADD_QUEUING_STATUS' AND PARAM_ORDER_TYPE = 'ASC' THEN `addon_queuing`.`ADD_QUEUING_STATUS` END ASC, 
		CASE WHEN PARAM_ORDER_FIELD = 'ADD_QUEUING_STATUS' AND PARAM_ORDER_TYPE = 'DESC' THEN `addon_queuing`.`ADD_QUEUING_STATUS` END DESC,	

		-- Inner joins
		
		-- EXTRA
		CASE WHEN PARAM_ORDER_FIELD <> 'ADD_QUEUING_DATE_REQUEST' THEN `addon_queuing`.`ADD_QUEUING_DATE_REQUEST` END ASC
		
	-- LIMIT & OFFSET
	-- ####################################################		
	LIMIT PARAM_SKIP, PARAM_LIMIT;
	
	
	
	-- EXIT PROCEDURE
	-- =========================================================================================
	LEAVE SP_GET;
			
END ;;
DELIMITER ;
/*!50003 SET sql_mode              = @saved_sql_mode */ ;
/*!50003 SET character_set_client  = @saved_cs_client */ ;
/*!50003 SET character_set_results = @saved_cs_results */ ;
/*!50003 SET collation_connection  = @saved_col_connection */ ;
/*!50003 DROP PROCEDURE IF EXISTS `ADDON_RESOURCE_DELETE` */;
/*!50003 SET @saved_cs_client      = @@character_set_client */ ;
/*!50003 SET @saved_cs_results     = @@character_set_results */ ;
/*!50003 SET @saved_col_connection = @@collation_connection */ ;
/*!50003 SET character_set_client  = latin1 */ ;
/*!50003 SET character_set_results = latin1 */ ;
/*!50003 SET collation_connection  = latin1_swedish_ci */ ;
/*!50003 SET @saved_sql_mode       = @@sql_mode */ ;
/*!50003 SET sql_mode              = '' */ ;
DELIMITER ;;
CREATE DEFINER=`root`@`localhost` PROCEDURE `ADDON_RESOURCE_DELETE`(
	IN `PARAM_ADD_RESOURCE_ID` BIGINT,

	IN `PARAM_REQUESTER_USERNAME` VARCHAR(500),
	IN `PARAM_REQUESTER_PASSWORD` VARCHAR(500),
	IN `PARAM_REQUESTER_PROXY_ID` BIGINT,
	IN `PARAM_REQUESTER_PROXY_PASSWORD` VARCHAR(1000),
	IN `PARAM_REQUESTER_DEVICE_PUBLIC_KEY` VARCHAR(1000),
	IN `PARAM_REQUESTER_DEVICE_PRIVATE_KEY` VARCHAR(1000),
	
	IN `PARAM_REQUESTER_IP` VARCHAR(1000),
	IN `PARAM_UNIQUE_SESSION_ID` VARCHAR(1000),
	IN `PARAM_SUPPRESS_RETURN` BIT,
	
	IN `PARAM_SYNC_SERVER_DESCRIPTION` VARCHAR(500), 
	IN `PARAM_SYNC_SERVER_UNIQUE_KEY` VARCHAR(500)
)
SP_DELETE:
BEGIN

	-- 1) DECLARE LOCAL PARAMETERS
	-- _______________________________________________________________________
	
	-- Status
	-- ...........................................
	DECLARE STATUS_INACTIVE TINYINT DEFAULT 1;
	DECLARE STATUS_ACTIVE TINYINT DEFAULT 2;
	DECLARE STATUS_CLOSED TINYINT DEFAULT 3;
	DECLARE STATUS_COMPLETED TINYINT DEFAULT 4;
	
	-- Audit Handler
	-- ...........................................
	DECLARE TEMP_RECORD_EXISTS BIT DEFAULT 0;
	DECLARE TEMP_MODULE_KEYWORD VARCHAR(500) DEFAULT 'addon_resource';
	DECLARE TEMP_SP_OBJECTIVE VARCHAR(500) DEFAULT 'delete Resource record';
	DECLARE TEMP_ERR_MESSAGE VARCHAR(500) DEFAULT '';
	DECLARE ERR BIGINT DEFAULT 0;
	DECLARE TEMP_RECORD_CHANGES VARCHAR(16000) DEFAULT '';
	DECLARE TEMP_RECORD_BINDED BIT DEFAULT 0;
	
	DECLARE TEMP_RECORD_BINDED_ID BIGINT DEFAULT 0;
	DECLARE TEMP_RECORD_BINDED_SERVER_ID BIGINT DEFAULT 0;
	
	-- Authentication
	-- ...........................................
	DECLARE TEMP_ACCESS_RIGHTS_DENIED BIT DEFAULT 0;
	DECLARE TEMP_SYNC_SERVER_ID BIGINT DEFAULT 0;
	DECLARE TEMP_SYNC_IS_SERVER_REQUEST BIT DEFAULT 0;
	DECLARE TEMP_AUTHENTICATED_ACCOUNT_ID BIGINT DEFAULT `ACCOUNT_MEMBER@ACC_ACCOUNT_ID_FROM_LOGIN`(PARAM_REQUESTER_USERNAME, PARAM_REQUESTER_PASSWORD);
	DECLARE TEMP_AUTHENTICATED_ACCOUNT_LEVEL BIGINT DEFAULT 0;
	DECLARE TEMP_AUTHENTICATED_ACCOUNT_GROUP BIGINT DEFAULT 0;

	-- Local value holder
	-- ...........................................
	DECLARE TEMP_ADD_RESOURCE_GLOBAL_ID VARCHAR(400) DEFAULT ''; 
	DECLARE TEMP_ADD_RESOURCE_GROUP_KEY VARCHAR(400) DEFAULT ''; 
	DECLARE TEMP_ADD_RESOURCE_VALUE VARBINARY(50000) DEFAULT null; 
	DECLARE TEMP_ADD_RESOURCE_PARAMETER VARCHAR(1000) DEFAULT ''; 
	DECLARE TEMP_ADD_RESOURCE_REMARKS VARCHAR(1000) DEFAULT ''; 
	DECLARE TEMP_ADD_RESOURCE_STATUS TINYINT DEFAULT 0; 

	
	
	-- 2) Try Catch / Throw
	-- _______________________________________________________________________
	DECLARE EXIT HANDLER FOR SQLEXCEPTION
	BEGIN
		RESIGNAL;
	END;

	
	-- 3) Prepare SYNC
	-- _______________________________________________________________________
	
	-- IS RECORD EXISTS		
	-- ####################################################		
	SET TEMP_RECORD_EXISTS = `ADDON_RESOURCE@ADD_RESOURCE_ID_EXISTS`(PARAM_ADD_RESOURCE_ID, 0);


	-- 4) IF ALREADY EXIST, FILL MISSING DATA
	-- _______________________________________________________________________
	IF TEMP_RECORD_EXISTS = 1 THEN
		SELECT
				`addon_resource`.`ADD_RESOURCE_GLOBAL_ID`, 	
				`addon_resource`.`ADD_RESOURCE_GROUP_KEY`, 	
				`addon_resource`.`ADD_RESOURCE_VALUE`, 	
				`addon_resource`.`ADD_RESOURCE_PARAMETER`, 	
				`addon_resource`.`ADD_RESOURCE_REMARKS`, 	
				`addon_resource`.`ADD_RESOURCE_STATUS`	
		INTO
				TEMP_ADD_RESOURCE_GLOBAL_ID, 	
				TEMP_ADD_RESOURCE_GROUP_KEY, 	
				TEMP_ADD_RESOURCE_VALUE, 	
				TEMP_ADD_RESOURCE_PARAMETER, 	
				TEMP_ADD_RESOURCE_REMARKS, 	
				TEMP_ADD_RESOURCE_STATUS	

		FROM `addon_resource`
		WHERE
			`addon_resource`.`ADD_RESOURCE_ID` = PARAM_ADD_RESOURCE_ID
		LIMIT 1;

	ELSE 
		IF TEMP_SYNC_IS_SERVER_REQUEST = 0 THEN
			SET TEMP_ERR_MESSAGE = CONCAT_WS(' ', 'Given Resource does not exists or is inactive. ID:', PARAM_ADD_RESOURCE_ID);
			SET ERR = `RAISERROR`(TEMP_ERR_MESSAGE);		
		END IF;
		LEAVE SP_DELETE;
		
	END IF;



	-- 5) PREPARE AUDIT TRAIL
	-- _______________________________________________________________________
	
		SET TEMP_RECORD_CHANGES = 
		`SYSTEM_VAR@CONCAT_ADD`(' | ', TEMP_RECORD_CHANGES, CONCAT_WS(' ', 'Sync ID: "', TEMP_ADD_RESOURCE_GLOBAL_ID, '" > " DELETED "'));
		SET TEMP_RECORD_CHANGES = 
		`SYSTEM_VAR@CONCAT_ADD`(' | ', TEMP_RECORD_CHANGES, CONCAT_WS(' ', 'Resource Grouping Key: "', TEMP_ADD_RESOURCE_GROUP_KEY, '" > " DELETED "'));
		SET TEMP_RECORD_CHANGES = 
		`SYSTEM_VAR@CONCAT_ADD`(' | ', TEMP_RECORD_CHANGES, CONCAT_WS(' ', 'Resource data: "', TEMP_ADD_RESOURCE_VALUE, '" > " DELETED "'));
		SET TEMP_RECORD_CHANGES = 
		`SYSTEM_VAR@CONCAT_ADD`(' | ', TEMP_RECORD_CHANGES, CONCAT_WS(' ', 'Parameter: "', TEMP_ADD_RESOURCE_PARAMETER, '" > " DELETED "'));
		SET TEMP_RECORD_CHANGES = 
		`SYSTEM_VAR@CONCAT_ADD`(' | ', TEMP_RECORD_CHANGES, CONCAT_WS(' ', 'Remarks: "', TEMP_ADD_RESOURCE_REMARKS, '" > " DELETED "'));
		SET TEMP_RECORD_CHANGES = 
		`SYSTEM_VAR@CONCAT_ADD`(' | ', TEMP_RECORD_CHANGES, CONCAT_WS(' ', 'Status: "', TEMP_ADD_RESOURCE_STATUS, '" > " DELETED "'));


	-- 6) VALIDATE
	-- _______________________________________________________________________
	
	-- Access Rights [Device]
	-- ####################################################
	IF `ACCOUNT_DEVICE@HAS_PERMISSION`(PARAM_REQUESTER_DEVICE_PUBLIC_KEY, PARAM_REQUESTER_DEVICE_PRIVATE_KEY) = 0 THEN
		SET TEMP_ERR_MESSAGE = 'Your device is not authorized yet to access this server.';
		SET ERR = `RAISERROR`(TEMP_ERR_MESSAGE);		
	END IF;
		
		
	-- Access Rights [Account]
	-- ####################################################	
	
	IF 
		-- [DELETE] Access Rights
		`ACCOUNT_ACCESS_RIGHTS@HAS_PERMISSION`(PARAM_REQUESTER_USERNAME, PARAM_REQUESTER_PASSWORD, 0, TEMP_MODULE_KEYWORD, 4) = 0 
	THEN
		SET TEMP_ACCESS_RIGHTS_DENIED = 1;
		CALL `ACCOUNT_ACCESS_RIGHTS_DENY`
		(
			0, TEMP_MODULE_KEYWORD, PARAM_ADD_RESOURCE_ID, 0, TEMP_SP_OBJECTIVE, TEMP_RECORD_CHANGES, 
			PARAM_REQUESTER_USERNAME, PARAM_REQUESTER_PASSWORD, 
			PARAM_REQUESTER_PROXY_ID, PARAM_REQUESTER_PROXY_PASSWORD,
			PARAM_REQUESTER_DEVICE_PUBLIC_KEY, PARAM_REQUESTER_DEVICE_PRIVATE_KEY,
			PARAM_REQUESTER_IP, PARAM_UNIQUE_SESSION_ID,
			TEMP_SYNC_SERVER_ID, PARAM_SUPPRESS_RETURN
		);
	END IF;

	
	-- If already used, cannot remove record
	-- ####################################################
	IF
	(
		SELECT
			COUNT(`account_member`.`ACC_ACCOUNT_ADD_RESOURCE_ID`)
		FROM `account_member`
		WHERE
			`account_member`.`ACC_ACCOUNT_ADD_RESOURCE_ID` = PARAM_ADD_RESOURCE_ID
		LIMIT 1
	) >= 1 
	THEN
		SET TEMP_RECORD_BINDED = 1;
		SET TEMP_ERR_MESSAGE = 'Registered Member Record';
	END IF;

	-- Leave Re-upload request
	-- ####################################################
	IF TEMP_RECORD_BINDED = 1 THEN
		IF TEMP_SYNC_IS_SERVER_REQUEST = 1 THEN
			
			LEAVE SP_DELETE;
		END IF;

		CALL `VALIDATION_DELETE_LINKED_RECORD`(TEMP_ADD_RESOURCE_GROUP_KEY, '', TEMP_ERR_MESSAGE); 
	END IF;


	-- 7) DELETE
	-- _______________________________________________________________________
	DELETE FROM `addon_resource`
	WHERE `addon_resource`.`ADD_RESOURCE_ID` = PARAM_ADD_RESOURCE_ID
	LIMIT 1;


	-- 8) AUDIT TRAIL
	-- _______________________________________________________________________
	CALL `ACCOUNT_AUDIT_TRAIL_SAVE`
	(
		0, TEMP_MODULE_KEYWORD, PARAM_ADD_RESOURCE_ID, 0, 'DELETE', TEMP_SP_OBJECTIVE, TEMP_RECORD_CHANGES, 
		PARAM_REQUESTER_USERNAME, PARAM_REQUESTER_PASSWORD, 
		PARAM_REQUESTER_PROXY_ID, PARAM_REQUESTER_PROXY_PASSWORD,
		PARAM_REQUESTER_DEVICE_PUBLIC_KEY, PARAM_REQUESTER_DEVICE_PRIVATE_KEY,
		PARAM_REQUESTER_IP, PARAM_UNIQUE_SESSION_ID,
		TEMP_SYNC_SERVER_ID, PARAM_SUPPRESS_RETURN
	);

END ;;
DELIMITER ;
/*!50003 SET sql_mode              = @saved_sql_mode */ ;
/*!50003 SET character_set_client  = @saved_cs_client */ ;
/*!50003 SET character_set_results = @saved_cs_results */ ;
/*!50003 SET collation_connection  = @saved_col_connection */ ;
/*!50003 DROP PROCEDURE IF EXISTS `ADDON_RESOURCE_GET` */;
/*!50003 SET @saved_cs_client      = @@character_set_client */ ;
/*!50003 SET @saved_cs_results     = @@character_set_results */ ;
/*!50003 SET @saved_col_connection = @@collation_connection */ ;
/*!50003 SET character_set_client  = latin1 */ ;
/*!50003 SET character_set_results = latin1 */ ;
/*!50003 SET collation_connection  = latin1_swedish_ci */ ;
/*!50003 SET @saved_sql_mode       = @@sql_mode */ ;
/*!50003 SET sql_mode              = '' */ ;
DELIMITER ;;
CREATE DEFINER=`root`@`localhost` PROCEDURE `ADDON_RESOURCE_GET`(
	IN `PARAM_ADD_RESOURCE_ID` BIGINT,	
	IN `PARAM_ADD_RESOURCE_GLOBAL_ID` VARCHAR(400),	
	IN `PARAM_ADD_RESOURCE_GROUP_KEY` VARCHAR(400),	
	IN `PARAM_ADD_RESOURCE_PARAMETER` VARCHAR(1000),	
	IN `PARAM_ADD_RESOURCE_REMARKS` VARCHAR(1000),	
	IN `PARAM_ADD_RESOURCE_STATUS` TINYINT,	
		
	IN `PARAM_ORDER_FIELD` VARCHAR(500),
	IN `PARAM_ORDER_TYPE` VARCHAR(500),
	IN `PARAM_SKIP` BIGINT,
	IN `PARAM_LIMIT` BIGINT,

	IN `PARAM_REQUESTER_USERNAME` VARCHAR(500),
	IN `PARAM_REQUESTER_PASSWORD` VARCHAR(500),
	IN `PARAM_REQUESTER_PROXY_ID` BIGINT,
	IN `PARAM_REQUESTER_PROXY_PASSWORD` VARCHAR(1000),
	IN `PARAM_REQUESTER_DEVICE_PUBLIC_KEY` VARCHAR(1000),
	IN `PARAM_REQUESTER_DEVICE_PRIVATE_KEY` VARCHAR(1000),
	
	IN `PARAM_REQUESTER_IP` VARCHAR(1000),
	IN `PARAM_UNIQUE_SESSION_ID` VARCHAR(1000),
	IN `PARAM_SUPPRESS_RETURN` BIT
)
SP_GET:
BEGIN

	-- Status
	-- =========================================================================================
	DECLARE STATUS_INACTIVE TINYINT DEFAULT 1;
	DECLARE STATUS_ACTIVE TINYINT DEFAULT 2;
	DECLARE STATUS_CLOSED TINYINT DEFAULT 3;
	DECLARE STATUS_COMPLETED TINYINT DEFAULT 4;
	
	-- Audit Handler
	-- =========================================================================================
	DECLARE TEMP_RECORD_EXISTS BIT DEFAULT 0;
	DECLARE TEMP_MODULE_KEYWORD VARCHAR(500) DEFAULT 'addon_resource';
	DECLARE TEMP_SP_OBJECTIVE VARCHAR(500) DEFAULT 'Retrieve Resource record';
	DECLARE TEMP_ERR_MESSAGE VARCHAR(500) DEFAULT '';
	DECLARE ERR BIGINT DEFAULT 0;
	DECLARE TEMP_RECORD_CHANGES VARCHAR(16000) DEFAULT '';
	DECLARE TEMP_RECORD_BINDED BIT DEFAULT 0;
	
	DECLARE TEMP_RECORD_BINDED_ID BIGINT DEFAULT 0;
	DECLARE TEMP_RECORD_BINDED_SERVER_ID BIGINT DEFAULT 0;
	
	-- Authentication
	-- =========================================================================================
	DECLARE TEMP_ACCESS_RIGHTS_DENIED BIT DEFAULT 0;
	DECLARE TEMP_AUTHENTICATED_ACCOUNT_ID BIGINT DEFAULT `ACCOUNT_MEMBER@ACC_ACCOUNT_ID_FROM_LOGIN`(PARAM_REQUESTER_USERNAME, PARAM_REQUESTER_PASSWORD);
	DECLARE TEMP_AUTHENTICATED_ACCOUNT_LEVEL BIGINT DEFAULT 0;
	DECLARE TEMP_AUTHENTICATED_ACCOUNT_GROUP BIGINT DEFAULT 0;
	
	-- Local Parameters
	-- =========================================================================================
	DECLARE TEMP_NOW DATETIME(6) DEFAULT `SYSTEM_VAR@NOW`('', 1);
	DECLARE TEMP_RECORD_COUNT BIGINT DEFAULT 0;
	
	
	-- Check NULLs
	-- =========================================================================================
	DECLARE IS_NULL_ADD_RESOURCE_ID BIT DEFAULT `SYSTEM_VAR@IS_NULL@BIGINT`(PARAM_ADD_RESOURCE_ID, 1, 1);
	DECLARE IS_NULL_ADD_RESOURCE_GLOBAL_ID BIT DEFAULT `SYSTEM_VAR@IS_NULL@NVARCHAR`(PARAM_ADD_RESOURCE_GLOBAL_ID, 1);
	DECLARE IS_NULL_ADD_RESOURCE_GROUP_KEY BIT DEFAULT `SYSTEM_VAR@IS_NULL@NVARCHAR`(PARAM_ADD_RESOURCE_GROUP_KEY, 1);
	DECLARE IS_NULL_ADD_RESOURCE_PARAMETER BIT DEFAULT `SYSTEM_VAR@IS_NULL@NVARCHAR`(PARAM_ADD_RESOURCE_PARAMETER, 0);
	DECLARE IS_NULL_ADD_RESOURCE_REMARKS BIT DEFAULT `SYSTEM_VAR@IS_NULL@NVARCHAR`(PARAM_ADD_RESOURCE_REMARKS, 0);
	DECLARE IS_NULL_ADD_RESOURCE_STATUS BIT DEFAULT `SYSTEM_VAR@IS_NULL@TINYINT`(PARAM_ADD_RESOURCE_STATUS, 1, 1);
	
	-- Error Handler
	-- =========================================================================================
	DECLARE EXIT HANDLER FOR SQLEXCEPTION
	BEGIN
		RESIGNAL;
	END;
	
	-- Ignore Time from DateTime (Set Time 00:00:00.000000 and 23:59:59.999999)
	-- =========================================================================================
		
		
	-- Access Rights [Device]
	-- =========================================================================================
	IF `ACCOUNT_DEVICE@HAS_PERMISSION`(PARAM_REQUESTER_DEVICE_PUBLIC_KEY, PARAM_REQUESTER_DEVICE_PRIVATE_KEY) = 0 THEN
		SET TEMP_ERR_MESSAGE = 'Your device is not authorized yet to access this server.';
		SET ERR = `RAISERROR`(TEMP_ERR_MESSAGE);		
	END IF;
		
		
	-- Access Rights [Account]
	-- =========================================================================================
		
	IF `ACCOUNT_ACCESS_RIGHTS@HAS_PERMISSION`(PARAM_REQUESTER_USERNAME, PARAM_REQUESTER_PASSWORD, 0, TEMP_MODULE_KEYWORD, 1) = 0 THEN
		SET TEMP_ACCESS_RIGHTS_DENIED = 1;
		CALL `ACCOUNT_ACCESS_RIGHTS_DENY`
		(
			0, TEMP_MODULE_KEYWORD, 0, 0, TEMP_SP_OBJECTIVE, TEMP_RECORD_CHANGES, 
			PARAM_REQUESTER_USERNAME, PARAM_REQUESTER_PASSWORD, 
			PARAM_REQUESTER_PROXY_ID, PARAM_REQUESTER_PROXY_PASSWORD,
			PARAM_REQUESTER_DEVICE_PUBLIC_KEY, PARAM_REQUESTER_DEVICE_PRIVATE_KEY,
			PARAM_REQUESTER_IP, PARAM_UNIQUE_SESSION_ID,
			0, PARAM_SUPPRESS_RETURN
		);
	END IF;
	
	
	
	-- COUNT RECORD
	-- =========================================================================================
	
	-- SELECT COLUMNS
	-- ####################################################
	SELECT
		COUNT(DISTINCT `addon_resource`.`ADD_RESOURCE_ID`)
	INTO
		TEMP_RECORD_COUNT

	FROM `addon_resource`
	
		-- Add Inner Joins (Per Foreign-key)
		
		-- Add Optional Left Joins (Per Optional Foreign-key)
		
	-- CONDITIONS
	-- ####################################################
	WHERE
		(
			IS_NULL_ADD_RESOURCE_ID = 1 OR
			`addon_resource`.`ADD_RESOURCE_ID` = PARAM_ADD_RESOURCE_ID			
		) AND
		(
			IS_NULL_ADD_RESOURCE_GLOBAL_ID = 1 OR
			`addon_resource`.`ADD_RESOURCE_GLOBAL_ID` LIKE CONCAT_WS('%', '', PARAM_ADD_RESOURCE_GLOBAL_ID, '')			
		) AND 		
		(
			IS_NULL_ADD_RESOURCE_GROUP_KEY = 1 OR
			`addon_resource`.`ADD_RESOURCE_GROUP_KEY` LIKE CONCAT_WS('%', '', PARAM_ADD_RESOURCE_GROUP_KEY, '')			
		) AND 		
		(
			IS_NULL_ADD_RESOURCE_PARAMETER = 1 OR
			`addon_resource`.`ADD_RESOURCE_PARAMETER` LIKE CONCAT_WS('%', '', PARAM_ADD_RESOURCE_PARAMETER, '')			
		) AND 		
		(
			IS_NULL_ADD_RESOURCE_REMARKS = 1 OR
			`addon_resource`.`ADD_RESOURCE_REMARKS` LIKE CONCAT_WS('%', '', PARAM_ADD_RESOURCE_REMARKS, '')			
		) AND 		
		(
			IS_NULL_ADD_RESOURCE_STATUS = 1 OR
			`addon_resource`.`ADD_RESOURCE_STATUS` = PARAM_ADD_RESOURCE_STATUS			
		) 
;	

		
		
	-- SELECT RECORDS
	-- =========================================================================================
	
	-- FETCH COLUMNS
	-- ####################################################
	SELECT
		-- ADDON_RESOURCE DETAILS
		`addon_resource`.`ADD_RESOURCE_ID`, 
		`addon_resource`.`ADD_RESOURCE_GLOBAL_ID`, 
		`addon_resource`.`ADD_RESOURCE_GROUP_KEY`, 
		`addon_resource`.`ADD_RESOURCE_VALUE`, 
		`addon_resource`.`ADD_RESOURCE_PARAMETER`, 
		`addon_resource`.`ADD_RESOURCE_REMARKS`, 
		`addon_resource`.`ADD_RESOURCE_STATUS`
		
		-- Inner join fields
		
		-- Left join fields
		
		, TEMP_RECORD_COUNT AS RECORD_COUNT

	FROM `addon_resource`
	
		-- Add Inner Joins (Per Foreign-key)
		
		-- Add Optional Left Joins (Per Optional Foreign-key)
		
	-- CONDITIONS
	-- ####################################################
	WHERE
		(
			IS_NULL_ADD_RESOURCE_ID = 1 OR
			`addon_resource`.`ADD_RESOURCE_ID` = PARAM_ADD_RESOURCE_ID			
		) AND
		(
			IS_NULL_ADD_RESOURCE_GLOBAL_ID = 1 OR
			`addon_resource`.`ADD_RESOURCE_GLOBAL_ID` LIKE CONCAT_WS('%', '', PARAM_ADD_RESOURCE_GLOBAL_ID, '')			
		) AND 		
		(
			IS_NULL_ADD_RESOURCE_GROUP_KEY = 1 OR
			`addon_resource`.`ADD_RESOURCE_GROUP_KEY` LIKE CONCAT_WS('%', '', PARAM_ADD_RESOURCE_GROUP_KEY, '')			
		) AND 		
		(
			IS_NULL_ADD_RESOURCE_PARAMETER = 1 OR
			`addon_resource`.`ADD_RESOURCE_PARAMETER` LIKE CONCAT_WS('%', '', PARAM_ADD_RESOURCE_PARAMETER, '')			
		) AND 		
		(
			IS_NULL_ADD_RESOURCE_REMARKS = 1 OR
			`addon_resource`.`ADD_RESOURCE_REMARKS` LIKE CONCAT_WS('%', '', PARAM_ADD_RESOURCE_REMARKS, '')			
		) AND 		
		(
			IS_NULL_ADD_RESOURCE_STATUS = 1 OR
			`addon_resource`.`ADD_RESOURCE_STATUS` = PARAM_ADD_RESOURCE_STATUS			
		) 

	-- ORDER BY
	-- ####################################################
	ORDER BY
		-- ADDON_RESOURCE DETAILS
		CASE WHEN PARAM_ORDER_FIELD = 'ADD_RESOURCE_ID' AND PARAM_ORDER_TYPE = 'ASC' THEN `addon_resource`.`ADD_RESOURCE_ID` END ASC, 
		CASE WHEN PARAM_ORDER_FIELD = 'ADD_RESOURCE_ID' AND PARAM_ORDER_TYPE = 'DESC' THEN `addon_resource`.`ADD_RESOURCE_ID` END DESC,	
		CASE WHEN PARAM_ORDER_FIELD = 'ADD_RESOURCE_GLOBAL_ID' AND PARAM_ORDER_TYPE = 'ASC' THEN `addon_resource`.`ADD_RESOURCE_GLOBAL_ID` END ASC, 
		CASE WHEN PARAM_ORDER_FIELD = 'ADD_RESOURCE_GLOBAL_ID' AND PARAM_ORDER_TYPE = 'DESC' THEN `addon_resource`.`ADD_RESOURCE_GLOBAL_ID` END DESC,	
		CASE WHEN PARAM_ORDER_FIELD = 'ADD_RESOURCE_GROUP_KEY' AND PARAM_ORDER_TYPE = 'ASC' THEN `addon_resource`.`ADD_RESOURCE_GROUP_KEY` END ASC, 
		CASE WHEN PARAM_ORDER_FIELD = 'ADD_RESOURCE_GROUP_KEY' AND PARAM_ORDER_TYPE = 'DESC' THEN `addon_resource`.`ADD_RESOURCE_GROUP_KEY` END DESC,	
		CASE WHEN PARAM_ORDER_FIELD = 'ADD_RESOURCE_VALUE' AND PARAM_ORDER_TYPE = 'ASC' THEN `addon_resource`.`ADD_RESOURCE_VALUE` END ASC, 
		CASE WHEN PARAM_ORDER_FIELD = 'ADD_RESOURCE_VALUE' AND PARAM_ORDER_TYPE = 'DESC' THEN `addon_resource`.`ADD_RESOURCE_VALUE` END DESC,	
		CASE WHEN PARAM_ORDER_FIELD = 'ADD_RESOURCE_PARAMETER' AND PARAM_ORDER_TYPE = 'ASC' THEN `addon_resource`.`ADD_RESOURCE_PARAMETER` END ASC, 
		CASE WHEN PARAM_ORDER_FIELD = 'ADD_RESOURCE_PARAMETER' AND PARAM_ORDER_TYPE = 'DESC' THEN `addon_resource`.`ADD_RESOURCE_PARAMETER` END DESC,	
		CASE WHEN PARAM_ORDER_FIELD = 'ADD_RESOURCE_REMARKS' AND PARAM_ORDER_TYPE = 'ASC' THEN `addon_resource`.`ADD_RESOURCE_REMARKS` END ASC, 
		CASE WHEN PARAM_ORDER_FIELD = 'ADD_RESOURCE_REMARKS' AND PARAM_ORDER_TYPE = 'DESC' THEN `addon_resource`.`ADD_RESOURCE_REMARKS` END DESC,	
		CASE WHEN PARAM_ORDER_FIELD = 'ADD_RESOURCE_STATUS' AND PARAM_ORDER_TYPE = 'ASC' THEN `addon_resource`.`ADD_RESOURCE_STATUS` END ASC, 
		CASE WHEN PARAM_ORDER_FIELD = 'ADD_RESOURCE_STATUS' AND PARAM_ORDER_TYPE = 'DESC' THEN `addon_resource`.`ADD_RESOURCE_STATUS` END DESC,	

		-- Inner joins
		
		-- EXTRA
		CASE WHEN PARAM_ORDER_FIELD <> 'ADD_RESOURCE_GROUP_KEY' THEN `addon_resource`.`ADD_RESOURCE_GROUP_KEY` END ASC
		
	-- LIMIT & OFFSET
	-- ####################################################		
	LIMIT PARAM_SKIP, PARAM_LIMIT;
	
	
	
	-- EXIT PROCEDURE
	-- =========================================================================================
	LEAVE SP_GET;
			
END ;;
DELIMITER ;
/*!50003 SET sql_mode              = @saved_sql_mode */ ;
/*!50003 SET character_set_client  = @saved_cs_client */ ;
/*!50003 SET character_set_results = @saved_cs_results */ ;
/*!50003 SET collation_connection  = @saved_col_connection */ ;
/*!50003 DROP PROCEDURE IF EXISTS `ADDON_RESOURCE_SAVE` */;
/*!50003 SET @saved_cs_client      = @@character_set_client */ ;
/*!50003 SET @saved_cs_results     = @@character_set_results */ ;
/*!50003 SET @saved_col_connection = @@collation_connection */ ;
/*!50003 SET character_set_client  = latin1 */ ;
/*!50003 SET character_set_results = latin1 */ ;
/*!50003 SET collation_connection  = latin1_swedish_ci */ ;
/*!50003 SET @saved_sql_mode       = @@sql_mode */ ;
/*!50003 SET sql_mode              = '' */ ;
DELIMITER ;;
CREATE DEFINER=`root`@`localhost` PROCEDURE `ADDON_RESOURCE_SAVE`(
	IN `PARAM_ADD_RESOURCE_ID` BIGINT,
	IN `PARAM_ADD_RESOURCE_GROUP_KEY` VARCHAR(400),
	IN `PARAM_ADD_RESOURCE_VALUE` VARBINARY(50000),
	IN `PARAM_ADD_RESOURCE_PARAMETER` VARCHAR(1000),
	IN `PARAM_ADD_RESOURCE_REMARKS` VARCHAR(1000),
	IN `PARAM_ADD_RESOURCE_STATUS` TINYINT,

	IN `PARAM_REQUESTER_USERNAME` VARCHAR(500),
	IN `PARAM_REQUESTER_PASSWORD` VARCHAR(500),
	IN `PARAM_REQUESTER_PROXY_ID` BIGINT,
	IN `PARAM_REQUESTER_PROXY_PASSWORD` VARCHAR(1000),
	IN `PARAM_REQUESTER_DEVICE_PUBLIC_KEY` VARCHAR(1000),
	IN `PARAM_REQUESTER_DEVICE_PRIVATE_KEY` VARCHAR(1000),
	
	IN `PARAM_REQUESTER_IP` VARCHAR(1000),
	IN `PARAM_UNIQUE_SESSION_ID` VARCHAR(1000),
	IN `PARAM_SUPPRESS_RETURN` BIT,
	
	IN `PARAM_SYNC_SERVER_DESCRIPTION` VARCHAR(500), 
	IN `PARAM_SYNC_SERVER_UNIQUE_KEY` VARCHAR(500)
)
SP_SAVE:
BEGIN


	-- 1) DECLARE LOCAL PARAMETERS
	-- _______________________________________________________________________
	
	-- Status
	-- ...........................................
	DECLARE STATUS_INACTIVE TINYINT DEFAULT 1;
	DECLARE STATUS_ACTIVE TINYINT DEFAULT 2;
	DECLARE STATUS_CLOSED TINYINT DEFAULT 3;
	DECLARE STATUS_COMPLETED TINYINT DEFAULT 4;

	-- Audit Handler
	-- ...........................................
	DECLARE TEMP_RECORD_EXISTS BIT DEFAULT 0;
	DECLARE TEMP_MODULE_KEYWORD VARCHAR(500) DEFAULT 'addon_resource';
	DECLARE TEMP_SP_OBJECTIVE VARCHAR(500) DEFAULT 'add/edit Resource record';
	DECLARE TEMP_ERR_MESSAGE VARCHAR(500) DEFAULT '';
	DECLARE ERR BIGINT DEFAULT 0;
	DECLARE TEMP_RECORD_CHANGES VARCHAR(16000) DEFAULT '';
	DECLARE TEMP_RECORD_BINDED BIT DEFAULT 0;

	-- Authentication
	-- ...........................................
	DECLARE TEMP_ACCESS_RIGHTS_DENIED BIT DEFAULT 0;
	DECLARE TEMP_ACCESS_RIGHTS_HAS_OVERRIDE BIT DEFAULT 0;
	DECLARE TEMP_SYNC_SERVER_ID BIGINT DEFAULT 0;
	DECLARE TEMP_SYNC_IS_SERVER_REQUEST BIT DEFAULT 0;
	DECLARE TEMP_AUTHENTICATED_ACCOUNT_ID BIGINT DEFAULT `ACCOUNT_MEMBER@ACC_ACCOUNT_ID_FROM_LOGIN`(PARAM_REQUESTER_USERNAME, PARAM_REQUESTER_PASSWORD);
	DECLARE TEMP_AUTHENTICATED_ACCOUNT_LEVEL BIGINT DEFAULT 0;
	DECLARE TEMP_AUTHENTICATED_ACCOUNT_GROUP BIGINT DEFAULT 0;
	
	-- Local Parameters
	-- ...........................................
	DECLARE TEMP_NOW DATETIME(6) DEFAULT `SYSTEM_VAR@NOW`('', 1);
	DECLARE TEMP_RECORD_COUNT BIGINT DEFAULT 0;

	-- AutoGen Parameters
	-- ...........................................
	DECLARE PARAM_ADD_RESOURCE_GLOBAL_ID VARCHAR(400) DEFAULT ''; 
	
	-- Local value holder
	-- ...........................................
	DECLARE TEMP_ADD_RESOURCE_GLOBAL_ID VARCHAR(400) DEFAULT ''; 
	DECLARE TEMP_ADD_RESOURCE_GROUP_KEY VARCHAR(400) DEFAULT ''; 
	DECLARE TEMP_ADD_RESOURCE_VALUE VARBINARY(50000) DEFAULT null; 
	DECLARE TEMP_ADD_RESOURCE_PARAMETER VARCHAR(1000) DEFAULT ''; 
	DECLARE TEMP_ADD_RESOURCE_REMARKS VARCHAR(1000) DEFAULT ''; 
	DECLARE TEMP_ADD_RESOURCE_STATUS TINYINT DEFAULT 0; 
	


	-- 2) Try Catch / Throw
	-- _______________________________________________________________________
	DECLARE EXIT HANDLER FOR SQLEXCEPTION
	BEGIN
		RESIGNAL;
	END;



	-- 3) Prepare SYNC
	-- _______________________________________________________________________

	-- IS RECORD EXISTS		
	-- ####################################################	
	SET TEMP_RECORD_EXISTS = `ADDON_RESOURCE@ADD_RESOURCE_ID_EXISTS`(PARAM_ADD_RESOURCE_ID, 0);

		
		
	-- 4) PREPARE AUTOGEN DATA (IF EXISTS)
	-- _______________________________________________________________________
	IF TEMP_SYNC_IS_SERVER_REQUEST = 0 THEN
		-- Just to keep at least one line within condition
		SET TEMP_SYNC_IS_SERVER_REQUEST = 0;
		
		-- Actual Functionalities here
		-- USE DEFAULT VALUE (String)
		-- USE DEFAULT VALUE (String)
		SET PARAM_ADD_RESOURCE_GLOBAL_ID = `SYSTEM_VAR@RANDOM_UNIQUE_ALPHA32`;
	END IF;



	-- 5) IF ALREADY EXIST, FILL MISSING DATA
	-- _______________________________________________________________________
	IF TEMP_RECORD_EXISTS = 1 THEN
		SELECT
			`addon_resource`.`ADD_RESOURCE_GLOBAL_ID`, 	
			`addon_resource`.`ADD_RESOURCE_GROUP_KEY`, 	
			`addon_resource`.`ADD_RESOURCE_VALUE`, 	
			`addon_resource`.`ADD_RESOURCE_PARAMETER`, 	
			`addon_resource`.`ADD_RESOURCE_REMARKS`, 	
			`addon_resource`.`ADD_RESOURCE_STATUS`	
		INTO
			TEMP_ADD_RESOURCE_GLOBAL_ID, 	
			TEMP_ADD_RESOURCE_GROUP_KEY, 	
			TEMP_ADD_RESOURCE_VALUE, 	
			TEMP_ADD_RESOURCE_PARAMETER, 	
			TEMP_ADD_RESOURCE_REMARKS, 	
			TEMP_ADD_RESOURCE_STATUS	

		FROM `addon_resource`
		WHERE
			`addon_resource`.`ADD_RESOURCE_ID` = PARAM_ADD_RESOURCE_ID
		LIMIT 1;

		-- Replace NULLs with the existing data.
		SET PARAM_ADD_RESOURCE_GROUP_KEY = `SYSTEM_VAR@REPLACE_NULL@NVARCHAR`(PARAM_ADD_RESOURCE_GROUP_KEY, TEMP_ADD_RESOURCE_GROUP_KEY, 1);
		SET PARAM_ADD_RESOURCE_VALUE = `SYSTEM_VAR@REPLACE_NULL@VARBINARY`(PARAM_ADD_RESOURCE_VALUE, TEMP_ADD_RESOURCE_VALUE, 1, 1);
		SET PARAM_ADD_RESOURCE_PARAMETER = `SYSTEM_VAR@REPLACE_NULL@NVARCHAR`(PARAM_ADD_RESOURCE_PARAMETER, TEMP_ADD_RESOURCE_PARAMETER, 0);
		SET PARAM_ADD_RESOURCE_REMARKS = `SYSTEM_VAR@REPLACE_NULL@NVARCHAR`(PARAM_ADD_RESOURCE_REMARKS, TEMP_ADD_RESOURCE_REMARKS, 0);
		SET PARAM_ADD_RESOURCE_STATUS = `SYSTEM_VAR@REPLACE_NULL@TINYINT`(PARAM_ADD_RESOURCE_STATUS, TEMP_ADD_RESOURCE_STATUS, 1, 1);
		
		-- AUTO GEN (NON-UPDATABLES)		
		SET PARAM_ADD_RESOURCE_GLOBAL_ID = TEMP_ADD_RESOURCE_GLOBAL_ID;
		
		-- AUTO GEN (UPDATABLE WITH STATUS CHANGE)

		-- AUTO GEN (UPDATABLE WITH STATUS [ACTIVE/INACTIVE] CHANGE)
		
	ELSE
		SET PARAM_ADD_RESOURCE_GROUP_KEY = `SYSTEM_VAR@REPLACE_NULL@NVARCHAR`(PARAM_ADD_RESOURCE_GROUP_KEY, '', 1);
		SET PARAM_ADD_RESOURCE_VALUE = `SYSTEM_VAR@REPLACE_NULL@VARBINARY`(PARAM_ADD_RESOURCE_VALUE, null, 1, 1);
		SET PARAM_ADD_RESOURCE_PARAMETER = `SYSTEM_VAR@REPLACE_NULL@NVARCHAR`(PARAM_ADD_RESOURCE_PARAMETER, '', 0);
		SET PARAM_ADD_RESOURCE_REMARKS = `SYSTEM_VAR@REPLACE_NULL@NVARCHAR`(PARAM_ADD_RESOURCE_REMARKS, '', 0);
		SET PARAM_ADD_RESOURCE_STATUS = `SYSTEM_VAR@REPLACE_NULL@TINYINT`(PARAM_ADD_RESOURCE_STATUS, 0, 1, 1);
		
	END IF;

	

	-- 6) PREPARE AUDIT TRAIL
	-- _______________________________________________________________________
	IF BINARY TEMP_ADD_RESOURCE_GLOBAL_ID <> PARAM_ADD_RESOURCE_GLOBAL_ID THEN
		SET TEMP_RECORD_CHANGES = 
		`SYSTEM_VAR@CONCAT_ADD`(' | ', TEMP_RECORD_CHANGES, CONCAT_WS(' ', 'Sync ID: "', TEMP_ADD_RESOURCE_GLOBAL_ID, '" > "', PARAM_ADD_RESOURCE_GLOBAL_ID, '"'));
	END IF;
	IF BINARY TEMP_ADD_RESOURCE_GROUP_KEY <> PARAM_ADD_RESOURCE_GROUP_KEY THEN
		SET TEMP_RECORD_CHANGES = 
		`SYSTEM_VAR@CONCAT_ADD`(' | ', TEMP_RECORD_CHANGES, CONCAT_WS(' ', 'Resource Grouping Key: "', TEMP_ADD_RESOURCE_GROUP_KEY, '" > "', PARAM_ADD_RESOURCE_GROUP_KEY, '"'));
	END IF;
	IF TEMP_ADD_RESOURCE_VALUE <> PARAM_ADD_RESOURCE_VALUE THEN
		SET TEMP_RECORD_CHANGES = 
		`SYSTEM_VAR@CONCAT_ADD`(' | ', TEMP_RECORD_CHANGES, CONCAT_WS(' ', 'Resource data: "', TEMP_ADD_RESOURCE_VALUE, '" > "', PARAM_ADD_RESOURCE_VALUE, '"'));
	END IF;	
	IF BINARY TEMP_ADD_RESOURCE_PARAMETER <> PARAM_ADD_RESOURCE_PARAMETER THEN
		SET TEMP_RECORD_CHANGES = 
		`SYSTEM_VAR@CONCAT_ADD`(' | ', TEMP_RECORD_CHANGES, CONCAT_WS(' ', 'Parameter: "', TEMP_ADD_RESOURCE_PARAMETER, '" > "', PARAM_ADD_RESOURCE_PARAMETER, '"'));
	END IF;
	IF BINARY TEMP_ADD_RESOURCE_REMARKS <> PARAM_ADD_RESOURCE_REMARKS THEN
		SET TEMP_RECORD_CHANGES = 
		`SYSTEM_VAR@CONCAT_ADD`(' | ', TEMP_RECORD_CHANGES, CONCAT_WS(' ', 'Remarks: "', TEMP_ADD_RESOURCE_REMARKS, '" > "', PARAM_ADD_RESOURCE_REMARKS, '"'));
	END IF;
	IF TEMP_ADD_RESOURCE_STATUS <> PARAM_ADD_RESOURCE_STATUS THEN
		SET TEMP_RECORD_CHANGES = 
		`SYSTEM_VAR@CONCAT_ADD`(' | ', TEMP_RECORD_CHANGES, CONCAT_WS(' ', 'Status: "', TEMP_ADD_RESOURCE_STATUS, '" > "', PARAM_ADD_RESOURCE_STATUS, '"'));
	END IF;	
		
	-- No Changes in data, reject request
	-- ####################################################
	IF CHARACTER_LENGTH(TEMP_RECORD_CHANGES) = 0 THEN
		IF PARAM_SUPPRESS_RETURN = 0 THEN
			SELECT PARAM_ADD_RESOURCE_ID AS INSERTED_ID;
		END IF;
		LEAVE SP_SAVE;
	END IF;



	-- 7) VALIDATE
	-- _______________________________________________________________________

	-- Access Rights [Device]
	-- ####################################################
	IF `ACCOUNT_DEVICE@HAS_PERMISSION`(PARAM_REQUESTER_DEVICE_PUBLIC_KEY, PARAM_REQUESTER_DEVICE_PRIVATE_KEY) = 0 THEN
		SET TEMP_ERR_MESSAGE = 'Your device is not authorized yet to access this server.';
		SET ERR = `RAISERROR`(TEMP_ERR_MESSAGE);		
	END IF;
		
		
	-- Access Rights [Account]
	-- ####################################################
	
	IF 
		-- [ADD] Access Rights
		(
			TEMP_RECORD_EXISTS = 0 AND
			`ACCOUNT_ACCESS_RIGHTS@HAS_PERMISSION`(PARAM_REQUESTER_USERNAME, PARAM_REQUESTER_PASSWORD, 0, TEMP_MODULE_KEYWORD, 2) = 0 
		) OR
		
		-- [EDIT] Access Rights
		(
			TEMP_RECORD_EXISTS = 1 AND
			`ACCOUNT_ACCESS_RIGHTS@HAS_PERMISSION`(PARAM_REQUESTER_USERNAME, PARAM_REQUESTER_PASSWORD, 0, TEMP_MODULE_KEYWORD, 3) = 0 
		)
	THEN
		SET TEMP_ACCESS_RIGHTS_DENIED = 1;
		CALL `ACCOUNT_ACCESS_RIGHTS_DENY`
		(
			0, TEMP_MODULE_KEYWORD, PARAM_ADD_RESOURCE_ID, 0, TEMP_SP_OBJECTIVE, TEMP_RECORD_CHANGES, 
			PARAM_REQUESTER_USERNAME, PARAM_REQUESTER_PASSWORD, 
			PARAM_REQUESTER_PROXY_ID, PARAM_REQUESTER_PROXY_PASSWORD,
			PARAM_REQUESTER_DEVICE_PUBLIC_KEY, PARAM_REQUESTER_DEVICE_PRIVATE_KEY,
			PARAM_REQUESTER_IP, PARAM_UNIQUE_SESSION_ID,
			TEMP_SYNC_SERVER_ID, PARAM_SUPPRESS_RETURN
		);
	END IF;
	SET TEMP_ACCESS_RIGHTS_HAS_OVERRIDE = `ACCOUNT_ACCESS_RIGHTS@HAS_PERMISSION`(PARAM_REQUESTER_USERNAME, PARAM_REQUESTER_PASSWORD, 0, TEMP_MODULE_KEYWORD, 4);
	

	-- Validation
	-- ####################################################
	IF TEMP_SYNC_IS_SERVER_REQUEST = 0 THEN
	

		-- FOREIGN KEY EXISTS
		-- ...........................................
		
		-- FOREIGN (OPTIONAL)KEY EXISTS [Validates if not null]
		-- ...........................................
		
		-- IS_ALLOW_NULL = FALSE
		-- ...........................................
		IF PARAM_ADD_RESOURCE_PARAMETER IS NULL THEN
			CALL `VALIDATION_MISSING_FIELD`('`ADD_RESOURCE_PARAMETER`', '`NULL`');
		END IF;
		IF PARAM_ADD_RESOURCE_REMARKS IS NULL THEN
			CALL `VALIDATION_MISSING_FIELD`('`ADD_RESOURCE_REMARKS`', '`NULL`');
		END IF;
				
		-- IS_ALLOW_ZERO = FALSE
		-- ...........................................
		IF PARAM_ADD_RESOURCE_VALUE = 0 THEN
			CALL `VALIDATION_MISSING_FIELD`('`ADD_RESOURCE_VALUE`', '`NULL`');
		END IF;		
		IF PARAM_ADD_RESOURCE_STATUS = 0 THEN
			CALL `VALIDATION_MISSING_FIELD`('`ADD_RESOURCE_STATUS`', '`NULL`');
		END IF;		
		
		-- IS_ALLOW_NEGATIVE = FALSE
		-- ...........................................
		IF PARAM_ADD_RESOURCE_VALUE < 0 THEN
			CALL `VALIDATION_NEGATIVE`('`ADD_RESOURCE_VALUE`', PARAM_ADD_RESOURCE_VALUE);
		END IF;		
		IF PARAM_ADD_RESOURCE_STATUS < 0 THEN
			CALL `VALIDATION_NEGATIVE`('`ADD_RESOURCE_STATUS`', PARAM_ADD_RESOURCE_STATUS);
		END IF;		
		
		-- IS_ALLOW_EMPTY_STRING = FALSE
		-- ...........................................
		IF `SYSTEM_VAR@IS_NULL@NVARCHAR`(PARAM_ADD_RESOURCE_GLOBAL_ID, 1) = 1 THEN
			CALL `VALIDATION_MISSING_FIELD`('`ADD_RESOURCE_GLOBAL_ID`', '`NULL`');
		END IF;
		IF `SYSTEM_VAR@IS_NULL@NVARCHAR`(PARAM_ADD_RESOURCE_GROUP_KEY, 1) = 1 THEN
			CALL `VALIDATION_MISSING_FIELD`('`ADD_RESOURCE_GROUP_KEY`', '`NULL`');
		END IF;
		
		-- IS_STATUS
		-- ...........................................
		IF `SYSTEM_STATUS@STATUS_ID_EXISTS`(PARAM_ADD_RESOURCE_STATUS, 0) = 0 THEN
			SET TEMP_ERR_MESSAGE = CONCAT_WS(' ', 'Given STATUS[Status] does not exists or is inactive. ID: ', PARAM_ADD_RESOURCE_STATUS);
			SET ERR = `RAISERROR`(TEMP_ERR_MESSAGE);
		END IF;
		
		-- IS STATUS Active / Inactive
		-- ...........................................
		
		-- Minimum / Maximum Value
		-- ...........................................
		
		-- IS_UNIQUE = TRUE
		-- ...........................................
		IF
		(
			SELECT COUNT(`addon_resource`.`ADD_RESOURCE_ID`)
			FROM `addon_resource`
			WHERE		
				`addon_resource`.`ADD_RESOURCE_GLOBAL_ID` = PARAM_ADD_RESOURCE_GLOBAL_ID AND		
				`addon_resource`.`ADD_RESOURCE_ID` <> PARAM_ADD_RESOURCE_ID
		) >= 1
		THEN
			CALL `VALIDATION_REDUNDANT_ENTRY`(PARAM_ADD_RESOURCE_GROUP_KEY);
		END IF;
		
		-- RECORD IDENTIFIER
		-- ...........................................
		
		
		-- ON_UPDATE VALIDATION 
		-- ...........................................
		IF TEMP_RECORD_EXISTS = 1 THEN	
		
			-- Just to keep at least one line within condition
			SET TEMP_RECORD_EXISTS = 1;
			
		END IF;
		
	END IF;



	-- 8) INSERT / UPDATE
	-- _______________________________________________________________________

	-- INSERT NEW DATA
	-- ####################################################
	IF TEMP_RECORD_EXISTS = 0 THEN

		INSERT INTO
		`addon_resource`
		(
			`addon_resource`.`ADD_RESOURCE_GLOBAL_ID`, 
			`addon_resource`.`ADD_RESOURCE_GROUP_KEY`, 
			`addon_resource`.`ADD_RESOURCE_VALUE`, 
			`addon_resource`.`ADD_RESOURCE_PARAMETER`, 
			`addon_resource`.`ADD_RESOURCE_REMARKS`, 
			`addon_resource`.`ADD_RESOURCE_STATUS`
		)
		VALUES
		(
			PARAM_ADD_RESOURCE_GLOBAL_ID, 
			PARAM_ADD_RESOURCE_GROUP_KEY, 
			PARAM_ADD_RESOURCE_VALUE, 
			PARAM_ADD_RESOURCE_PARAMETER, 
			PARAM_ADD_RESOURCE_REMARKS, 
			PARAM_ADD_RESOURCE_STATUS
		);	
		
		-- Update Audit trail with new ID	
		SET PARAM_ADD_RESOURCE_ID = LAST_INSERT_ID();



	-- UPDATING EXISTING RECORD
	-- ####################################################
	ELSE
		UPDATE `addon_resource`
		SET
			`addon_resource`.`ADD_RESOURCE_GLOBAL_ID` = PARAM_ADD_RESOURCE_GLOBAL_ID, 
			`addon_resource`.`ADD_RESOURCE_GROUP_KEY` = PARAM_ADD_RESOURCE_GROUP_KEY, 
			`addon_resource`.`ADD_RESOURCE_VALUE` = PARAM_ADD_RESOURCE_VALUE, 
			`addon_resource`.`ADD_RESOURCE_PARAMETER` = PARAM_ADD_RESOURCE_PARAMETER, 
			`addon_resource`.`ADD_RESOURCE_REMARKS` = PARAM_ADD_RESOURCE_REMARKS, 
			`addon_resource`.`ADD_RESOURCE_STATUS` = PARAM_ADD_RESOURCE_STATUS
		WHERE
			`addon_resource`.`ADD_RESOURCE_ID` = PARAM_ADD_RESOURCE_ID;

	END IF;

	
	-- 9) AUDIT TRAIL
	-- _______________________________________________________________________
	CALL `ACCOUNT_AUDIT_TRAIL_SAVE`
	(
		0, TEMP_MODULE_KEYWORD, PARAM_ADD_RESOURCE_ID, 0, 'SAVE', TEMP_SP_OBJECTIVE, TEMP_RECORD_CHANGES, 
		PARAM_REQUESTER_USERNAME, PARAM_REQUESTER_PASSWORD, 
		PARAM_REQUESTER_PROXY_ID, PARAM_REQUESTER_PROXY_PASSWORD,
		PARAM_REQUESTER_DEVICE_PUBLIC_KEY, PARAM_REQUESTER_DEVICE_PRIVATE_KEY,
		PARAM_REQUESTER_IP, PARAM_UNIQUE_SESSION_ID,
		TEMP_SYNC_SERVER_ID, PARAM_SUPPRESS_RETURN
	);
	

	-- 10) RETURN RESULT
	-- _______________________________________________________________________
	IF PARAM_SUPPRESS_RETURN = 0 THEN
		SELECT PARAM_ADD_RESOURCE_ID AS INSERTED_ID;
	END IF;
	LEAVE SP_SAVE;


END ;;
DELIMITER ;
/*!50003 SET sql_mode              = @saved_sql_mode */ ;
/*!50003 SET character_set_client  = @saved_cs_client */ ;
/*!50003 SET character_set_results = @saved_cs_results */ ;
/*!50003 SET collation_connection  = @saved_col_connection */ ;
/*!50003 DROP PROCEDURE IF EXISTS `CATEGORY_ADDRESS_BARANGAY_DELETE` */;
/*!50003 SET @saved_cs_client      = @@character_set_client */ ;
/*!50003 SET @saved_cs_results     = @@character_set_results */ ;
/*!50003 SET @saved_col_connection = @@collation_connection */ ;
/*!50003 SET character_set_client  = latin1 */ ;
/*!50003 SET character_set_results = latin1 */ ;
/*!50003 SET collation_connection  = latin1_swedish_ci */ ;
/*!50003 SET @saved_sql_mode       = @@sql_mode */ ;
/*!50003 SET sql_mode              = '' */ ;
DELIMITER ;;
CREATE DEFINER=`root`@`localhost` PROCEDURE `CATEGORY_ADDRESS_BARANGAY_DELETE`(
	IN `PARAM_CAT_BARANGAY_ID` BIGINT,

	IN `PARAM_REQUESTER_USERNAME` VARCHAR(500),
	IN `PARAM_REQUESTER_PASSWORD` VARCHAR(500),
	IN `PARAM_REQUESTER_PROXY_ID` BIGINT,
	IN `PARAM_REQUESTER_PROXY_PASSWORD` VARCHAR(1000),
	IN `PARAM_REQUESTER_DEVICE_PUBLIC_KEY` VARCHAR(1000),
	IN `PARAM_REQUESTER_DEVICE_PRIVATE_KEY` VARCHAR(1000),
	
	IN `PARAM_REQUESTER_IP` VARCHAR(1000),
	IN `PARAM_UNIQUE_SESSION_ID` VARCHAR(1000),
	IN `PARAM_SUPPRESS_RETURN` BIT,
	
	IN `PARAM_SYNC_SERVER_DESCRIPTION` VARCHAR(500), 
	IN `PARAM_SYNC_SERVER_UNIQUE_KEY` VARCHAR(500)
)
SP_DELETE:
BEGIN

	-- 1) DECLARE LOCAL PARAMETERS
	-- _______________________________________________________________________
	
	-- Status
	-- ...........................................
	DECLARE STATUS_INACTIVE TINYINT DEFAULT 1;
	DECLARE STATUS_ACTIVE TINYINT DEFAULT 2;
	DECLARE STATUS_CLOSED TINYINT DEFAULT 3;
	DECLARE STATUS_COMPLETED TINYINT DEFAULT 4;
	
	-- Audit Handler
	-- ...........................................
	DECLARE TEMP_RECORD_EXISTS BIT DEFAULT 0;
	DECLARE TEMP_MODULE_KEYWORD VARCHAR(500) DEFAULT 'category_address_barangay';
	DECLARE TEMP_SP_OBJECTIVE VARCHAR(500) DEFAULT 'delete Address: Barangay record';
	DECLARE TEMP_ERR_MESSAGE VARCHAR(500) DEFAULT '';
	DECLARE ERR BIGINT DEFAULT 0;
	DECLARE TEMP_RECORD_CHANGES VARCHAR(16000) DEFAULT '';
	DECLARE TEMP_RECORD_BINDED BIT DEFAULT 0;
	
	DECLARE TEMP_RECORD_BINDED_ID BIGINT DEFAULT 0;
	DECLARE TEMP_RECORD_BINDED_SERVER_ID BIGINT DEFAULT 0;
	
	-- Authentication
	-- ...........................................
	DECLARE TEMP_ACCESS_RIGHTS_DENIED BIT DEFAULT 0;
	DECLARE TEMP_SYNC_SERVER_ID BIGINT DEFAULT 0;
	DECLARE TEMP_SYNC_IS_SERVER_REQUEST BIT DEFAULT 0;
	DECLARE TEMP_AUTHENTICATED_ACCOUNT_ID BIGINT DEFAULT `ACCOUNT_MEMBER@ACC_ACCOUNT_ID_FROM_LOGIN`(PARAM_REQUESTER_USERNAME, PARAM_REQUESTER_PASSWORD);
	DECLARE TEMP_AUTHENTICATED_ACCOUNT_LEVEL BIGINT DEFAULT 0;
	DECLARE TEMP_AUTHENTICATED_ACCOUNT_GROUP BIGINT DEFAULT 0;

	-- Local value holder
	-- ...........................................
		DECLARE TEMP_CAT_BARANGAY_GLOBAL_ID VARCHAR(400) DEFAULT ''; 
		DECLARE TEMP_CAT_BARANGAY_CAT_MUNICIPALITY_ID BIGINT DEFAULT 0; 
		DECLARE TEMP_CAT_BARANGAY_CODE VARCHAR(50) DEFAULT ''; 
		DECLARE TEMP_CAT_BARANGAY_DESCRIPTION VARCHAR(500) DEFAULT ''; 
		DECLARE TEMP_CAT_BARANGAY_STATUS TINYINT DEFAULT 0; 
		DECLARE TEMP_CAT_BARANGAY_SYSTEM_GENERATED TINYINT DEFAULT 0; 

	
	
	-- 2) Try Catch / Throw
	-- _______________________________________________________________________
	DECLARE EXIT HANDLER FOR SQLEXCEPTION
	BEGIN
		RESIGNAL;
	END;

	
	-- 3) Prepare SYNC
	-- _______________________________________________________________________
	
	-- IS RECORD EXISTS		
	-- ####################################################		
	SET TEMP_RECORD_EXISTS = `CATEGORY_ADDRESS_BARANGAY@CAT_BARANGAY_ID_EXISTS`(PARAM_CAT_BARANGAY_ID, 0);


	-- 4) IF ALREADY EXIST, FILL MISSING DATA
	-- _______________________________________________________________________
	IF TEMP_RECORD_EXISTS = 1 THEN
		SELECT
				`category_address_barangay`.`CAT_BARANGAY_GLOBAL_ID`, 	
				`category_address_barangay`.`CAT_BARANGAY_CAT_MUNICIPALITY_ID`, 	
				`category_address_barangay`.`CAT_BARANGAY_CODE`, 	
				`category_address_barangay`.`CAT_BARANGAY_DESCRIPTION`, 	
				`category_address_barangay`.`CAT_BARANGAY_STATUS`, 	
				`category_address_barangay`.`CAT_BARANGAY_SYSTEM_GENERATED`	
		INTO
				TEMP_CAT_BARANGAY_GLOBAL_ID, 	
				TEMP_CAT_BARANGAY_CAT_MUNICIPALITY_ID, 	
				TEMP_CAT_BARANGAY_CODE, 	
				TEMP_CAT_BARANGAY_DESCRIPTION, 	
				TEMP_CAT_BARANGAY_STATUS, 	
				TEMP_CAT_BARANGAY_SYSTEM_GENERATED	

		FROM `category_address_barangay`
		WHERE
			`category_address_barangay`.`CAT_BARANGAY_ID` = PARAM_CAT_BARANGAY_ID
		LIMIT 1;

	ELSE 
		IF TEMP_SYNC_IS_SERVER_REQUEST = 0 THEN
			SET TEMP_ERR_MESSAGE = CONCAT_WS(' ', 'Given Address: Barangay does not exists or is inactive. ID:', PARAM_CAT_BARANGAY_ID);
			SET ERR = `RAISERROR`(TEMP_ERR_MESSAGE);		
		END IF;
		LEAVE SP_DELETE;
		
	END IF;



	-- 5) PREPARE AUDIT TRAIL
	-- _______________________________________________________________________
	
		SET TEMP_RECORD_CHANGES = 
		`SYSTEM_VAR@CONCAT_ADD`(' | ', TEMP_RECORD_CHANGES, CONCAT_WS(' ', 'Sync ID: "', TEMP_CAT_BARANGAY_GLOBAL_ID, '" > " DELETED "'));
		SET TEMP_RECORD_CHANGES = 
		`SYSTEM_VAR@CONCAT_ADD`(' | ', TEMP_RECORD_CHANGES, CONCAT_WS(' ', 'Municipality: "', TEMP_CAT_BARANGAY_CAT_MUNICIPALITY_ID, '" > " DELETED "'));
		SET TEMP_RECORD_CHANGES = 
		`SYSTEM_VAR@CONCAT_ADD`(' | ', TEMP_RECORD_CHANGES, CONCAT_WS(' ', 'Code: "', TEMP_CAT_BARANGAY_CODE, '" > " DELETED "'));
		SET TEMP_RECORD_CHANGES = 
		`SYSTEM_VAR@CONCAT_ADD`(' | ', TEMP_RECORD_CHANGES, CONCAT_WS(' ', 'Description: "', TEMP_CAT_BARANGAY_DESCRIPTION, '" > " DELETED "'));
		SET TEMP_RECORD_CHANGES = 
		`SYSTEM_VAR@CONCAT_ADD`(' | ', TEMP_RECORD_CHANGES, CONCAT_WS(' ', 'Status: "', TEMP_CAT_BARANGAY_STATUS, '" > " DELETED "'));
		SET TEMP_RECORD_CHANGES = 
		`SYSTEM_VAR@CONCAT_ADD`(' | ', TEMP_RECORD_CHANGES, CONCAT_WS(' ', 'System Generated: "', TEMP_CAT_BARANGAY_SYSTEM_GENERATED, '" > " DELETED "'));


	-- 6) VALIDATE
	-- _______________________________________________________________________
	
	-- Access Rights [Device]
	-- ####################################################
	IF `ACCOUNT_DEVICE@HAS_PERMISSION`(PARAM_REQUESTER_DEVICE_PUBLIC_KEY, PARAM_REQUESTER_DEVICE_PRIVATE_KEY) = 0 THEN
		SET TEMP_ERR_MESSAGE = 'Your device is not authorized yet to access this server.';
		SET ERR = `RAISERROR`(TEMP_ERR_MESSAGE);		
	END IF;
		
		
	-- Access Rights [Account]
	-- ####################################################	
	
	IF 
		-- [DELETE] Access Rights
		`ACCOUNT_ACCESS_RIGHTS@HAS_PERMISSION`(PARAM_REQUESTER_USERNAME, PARAM_REQUESTER_PASSWORD, 0, TEMP_MODULE_KEYWORD, 4) = 0 
	THEN
		SET TEMP_ACCESS_RIGHTS_DENIED = 1;
		CALL `ACCOUNT_ACCESS_RIGHTS_DENY`
		(
			0, TEMP_MODULE_KEYWORD, PARAM_CAT_BARANGAY_ID, 0, TEMP_SP_OBJECTIVE, TEMP_RECORD_CHANGES, 
			PARAM_REQUESTER_USERNAME, PARAM_REQUESTER_PASSWORD, 
			PARAM_REQUESTER_PROXY_ID, PARAM_REQUESTER_PROXY_PASSWORD,
			PARAM_REQUESTER_DEVICE_PUBLIC_KEY, PARAM_REQUESTER_DEVICE_PRIVATE_KEY,
			PARAM_REQUESTER_IP, PARAM_UNIQUE_SESSION_ID,
			TEMP_SYNC_SERVER_ID, PARAM_SUPPRESS_RETURN
		);
	END IF;

	-- System Generated Record (Cannot be deleted)
	-- ####################################################
	IF TEMP_CAT_BARANGAY_SYSTEM_GENERATED = STATUS_ACTIVE THEN
		CALL `VALIDATION_SYSTEM_GENERATED`
		(
			PARAM_CAT_BARANGAY_ID,
			TEMP_CAT_BARANGAY_DESCRIPTION, ''
		);
	END IF;
	
	-- If already used, cannot remove record
	-- ####################################################
	IF
	(
		SELECT
			COUNT(`record_combatants`.`REC_COMBATANT_CAT_BARANGAY_ID`)
		FROM `record_combatants`
		WHERE
			`record_combatants`.`REC_COMBATANT_CAT_BARANGAY_ID` = PARAM_CAT_BARANGAY_ID
		LIMIT 1
	) >= 1 
	THEN
		SET TEMP_RECORD_BINDED = 1;
		SET TEMP_ERR_MESSAGE = 'Combatant Information Record';
	END IF;

	-- Leave Re-upload request
	-- ####################################################
	IF TEMP_RECORD_BINDED = 1 THEN
		IF TEMP_SYNC_IS_SERVER_REQUEST = 1 THEN
			
			LEAVE SP_DELETE;
		END IF;

		CALL `VALIDATION_DELETE_LINKED_RECORD`(TEMP_CAT_BARANGAY_DESCRIPTION, '', TEMP_ERR_MESSAGE); 
	END IF;


	-- 7) DELETE
	-- _______________________________________________________________________
	DELETE FROM `category_address_barangay`
	WHERE `category_address_barangay`.`CAT_BARANGAY_ID` = PARAM_CAT_BARANGAY_ID
	LIMIT 1;


	-- 8) AUDIT TRAIL
	-- _______________________________________________________________________
	CALL `ACCOUNT_AUDIT_TRAIL_SAVE`
	(
		0, TEMP_MODULE_KEYWORD, PARAM_CAT_BARANGAY_ID, 0, 'DELETE', TEMP_SP_OBJECTIVE, TEMP_RECORD_CHANGES, 
		PARAM_REQUESTER_USERNAME, PARAM_REQUESTER_PASSWORD, 
		PARAM_REQUESTER_PROXY_ID, PARAM_REQUESTER_PROXY_PASSWORD,
		PARAM_REQUESTER_DEVICE_PUBLIC_KEY, PARAM_REQUESTER_DEVICE_PRIVATE_KEY,
		PARAM_REQUESTER_IP, PARAM_UNIQUE_SESSION_ID,
		TEMP_SYNC_SERVER_ID, PARAM_SUPPRESS_RETURN
	);

END ;;
DELIMITER ;
/*!50003 SET sql_mode              = @saved_sql_mode */ ;
/*!50003 SET character_set_client  = @saved_cs_client */ ;
/*!50003 SET character_set_results = @saved_cs_results */ ;
/*!50003 SET collation_connection  = @saved_col_connection */ ;
/*!50003 DROP PROCEDURE IF EXISTS `CATEGORY_ADDRESS_BARANGAY_GET` */;
/*!50003 SET @saved_cs_client      = @@character_set_client */ ;
/*!50003 SET @saved_cs_results     = @@character_set_results */ ;
/*!50003 SET @saved_col_connection = @@collation_connection */ ;
/*!50003 SET character_set_client  = latin1 */ ;
/*!50003 SET character_set_results = latin1 */ ;
/*!50003 SET collation_connection  = latin1_swedish_ci */ ;
/*!50003 SET @saved_sql_mode       = @@sql_mode */ ;
/*!50003 SET sql_mode              = '' */ ;
DELIMITER ;;
CREATE DEFINER=`root`@`localhost` PROCEDURE `CATEGORY_ADDRESS_BARANGAY_GET`(
	IN `PARAM_CAT_BARANGAY_ID` BIGINT,	
	IN `PARAM_CAT_BARANGAY_GLOBAL_ID` VARCHAR(400),	
	IN `PARAM_CAT_BARANGAY_CAT_MUNICIPALITY_ID` BIGINT,	
	IN `PARAM_CAT_BARANGAY_CODE` VARCHAR(50),	
	IN `PARAM_CAT_BARANGAY_DESCRIPTION` VARCHAR(500),	
	IN `PARAM_CAT_BARANGAY_STATUS` TINYINT,	
	IN `PARAM_CAT_BARANGAY_SYSTEM_GENERATED` TINYINT,	
		
	IN `PARAM_ORDER_FIELD` VARCHAR(500),
	IN `PARAM_ORDER_TYPE` VARCHAR(500),
	IN `PARAM_SKIP` BIGINT,
	IN `PARAM_LIMIT` BIGINT,

	IN `PARAM_REQUESTER_USERNAME` VARCHAR(500),
	IN `PARAM_REQUESTER_PASSWORD` VARCHAR(500),
	IN `PARAM_REQUESTER_PROXY_ID` BIGINT,
	IN `PARAM_REQUESTER_PROXY_PASSWORD` VARCHAR(1000),
	IN `PARAM_REQUESTER_DEVICE_PUBLIC_KEY` VARCHAR(1000),
	IN `PARAM_REQUESTER_DEVICE_PRIVATE_KEY` VARCHAR(1000),
	
	IN `PARAM_REQUESTER_IP` VARCHAR(1000),
	IN `PARAM_UNIQUE_SESSION_ID` VARCHAR(1000),
	IN `PARAM_SUPPRESS_RETURN` BIT
)
SP_GET:
BEGIN

	-- Status
	-- =========================================================================================
	DECLARE STATUS_INACTIVE TINYINT DEFAULT 1;
	DECLARE STATUS_ACTIVE TINYINT DEFAULT 2;
	DECLARE STATUS_CLOSED TINYINT DEFAULT 3;
	DECLARE STATUS_COMPLETED TINYINT DEFAULT 4;
	
	-- Audit Handler
	-- =========================================================================================
	DECLARE TEMP_RECORD_EXISTS BIT DEFAULT 0;
	DECLARE TEMP_MODULE_KEYWORD VARCHAR(500) DEFAULT 'category_address_barangay';
	DECLARE TEMP_SP_OBJECTIVE VARCHAR(500) DEFAULT 'Retrieve Address: Barangay record';
	DECLARE TEMP_ERR_MESSAGE VARCHAR(500) DEFAULT '';
	DECLARE ERR BIGINT DEFAULT 0;
	DECLARE TEMP_RECORD_CHANGES VARCHAR(16000) DEFAULT '';
	DECLARE TEMP_RECORD_BINDED BIT DEFAULT 0;
	
	DECLARE TEMP_RECORD_BINDED_ID BIGINT DEFAULT 0;
	DECLARE TEMP_RECORD_BINDED_SERVER_ID BIGINT DEFAULT 0;
	
	-- Authentication
	-- =========================================================================================
	DECLARE TEMP_ACCESS_RIGHTS_DENIED BIT DEFAULT 0;
	DECLARE TEMP_AUTHENTICATED_ACCOUNT_ID BIGINT DEFAULT `ACCOUNT_MEMBER@ACC_ACCOUNT_ID_FROM_LOGIN`(PARAM_REQUESTER_USERNAME, PARAM_REQUESTER_PASSWORD);
	DECLARE TEMP_AUTHENTICATED_ACCOUNT_LEVEL BIGINT DEFAULT 0;
	DECLARE TEMP_AUTHENTICATED_ACCOUNT_GROUP BIGINT DEFAULT 0;
	
	-- Local Parameters
	-- =========================================================================================
	DECLARE TEMP_NOW DATETIME(6) DEFAULT `SYSTEM_VAR@NOW`('', 1);
	DECLARE TEMP_RECORD_COUNT BIGINT DEFAULT 0;
	
	
	-- Check NULLs
	-- =========================================================================================
	DECLARE IS_NULL_CAT_BARANGAY_ID BIT DEFAULT `SYSTEM_VAR@IS_NULL@BIGINT`(PARAM_CAT_BARANGAY_ID, 1, 1);
	DECLARE IS_NULL_CAT_BARANGAY_GLOBAL_ID BIT DEFAULT `SYSTEM_VAR@IS_NULL@NVARCHAR`(PARAM_CAT_BARANGAY_GLOBAL_ID, 1);
	DECLARE IS_NULL_CAT_BARANGAY_CAT_MUNICIPALITY_ID BIT DEFAULT `SYSTEM_VAR@IS_NULL@BIGINT`(PARAM_CAT_BARANGAY_CAT_MUNICIPALITY_ID, 1, 1);
	DECLARE IS_NULL_CAT_BARANGAY_CODE BIT DEFAULT `SYSTEM_VAR@IS_NULL@NVARCHAR`(PARAM_CAT_BARANGAY_CODE, 1);
	DECLARE IS_NULL_CAT_BARANGAY_DESCRIPTION BIT DEFAULT `SYSTEM_VAR@IS_NULL@NVARCHAR`(PARAM_CAT_BARANGAY_DESCRIPTION, 1);
	DECLARE IS_NULL_CAT_BARANGAY_STATUS BIT DEFAULT `SYSTEM_VAR@IS_NULL@TINYINT`(PARAM_CAT_BARANGAY_STATUS, 1, 1);
	DECLARE IS_NULL_CAT_BARANGAY_SYSTEM_GENERATED BIT DEFAULT `SYSTEM_VAR@IS_NULL@TINYINT`(PARAM_CAT_BARANGAY_SYSTEM_GENERATED, 1, 1);
	
	-- Error Handler
	-- =========================================================================================
	DECLARE EXIT HANDLER FOR SQLEXCEPTION
	BEGIN
		RESIGNAL;
	END;
	
	-- Ignore Time from DateTime (Set Time 00:00:00.000000 and 23:59:59.999999)
	-- =========================================================================================
		
		
	-- Access Rights [Device]
	-- =========================================================================================
	IF `ACCOUNT_DEVICE@HAS_PERMISSION`(PARAM_REQUESTER_DEVICE_PUBLIC_KEY, PARAM_REQUESTER_DEVICE_PRIVATE_KEY) = 0 THEN
		SET TEMP_ERR_MESSAGE = 'Your device is not authorized yet to access this server.';
		SET ERR = `RAISERROR`(TEMP_ERR_MESSAGE);		
	END IF;
		
		
	-- Access Rights [Account]
	-- =========================================================================================
		
	
	
	
	-- COUNT RECORD
	-- =========================================================================================
	
	-- SELECT COLUMNS
	-- ####################################################
	SELECT
		COUNT(DISTINCT `category_address_barangay`.`CAT_BARANGAY_ID`)
	INTO
		TEMP_RECORD_COUNT

	FROM `category_address_barangay`
	
		-- Add Inner Joins (Per Foreign-key)
		INNER JOIN `category_address_municipality` ON
		`category_address_municipality`.`CAT_MUNICIPALITY_ID` = `category_address_barangay`.`CAT_BARANGAY_CAT_MUNICIPALITY_ID`
		
		-- Add Optional Left Joins (Per Optional Foreign-key)
		
	-- CONDITIONS
	-- ####################################################
	WHERE
		(
			IS_NULL_CAT_BARANGAY_ID = 1 OR
			`category_address_barangay`.`CAT_BARANGAY_ID` = PARAM_CAT_BARANGAY_ID			
		) AND
		(
			IS_NULL_CAT_BARANGAY_GLOBAL_ID = 1 OR
			`category_address_barangay`.`CAT_BARANGAY_GLOBAL_ID` LIKE CONCAT_WS('%', '', PARAM_CAT_BARANGAY_GLOBAL_ID, '')			
		) AND 		
		(
			IS_NULL_CAT_BARANGAY_CAT_MUNICIPALITY_ID = 1 OR
			`category_address_barangay`.`CAT_BARANGAY_CAT_MUNICIPALITY_ID` = PARAM_CAT_BARANGAY_CAT_MUNICIPALITY_ID			
		) AND
		(
			IS_NULL_CAT_BARANGAY_CODE = 1 OR
			`category_address_barangay`.`CAT_BARANGAY_CODE` LIKE CONCAT_WS('%', '', PARAM_CAT_BARANGAY_CODE, '')			
		) AND 		
		(
			IS_NULL_CAT_BARANGAY_DESCRIPTION = 1 OR
			`category_address_barangay`.`CAT_BARANGAY_DESCRIPTION` LIKE CONCAT_WS('%', '', PARAM_CAT_BARANGAY_DESCRIPTION, '')			
		) AND 		
		(
			IS_NULL_CAT_BARANGAY_STATUS = 1 OR
			`category_address_barangay`.`CAT_BARANGAY_STATUS` = PARAM_CAT_BARANGAY_STATUS			
		) AND
		(
			IS_NULL_CAT_BARANGAY_SYSTEM_GENERATED = 1 OR
			`category_address_barangay`.`CAT_BARANGAY_SYSTEM_GENERATED` = PARAM_CAT_BARANGAY_SYSTEM_GENERATED			
		) 
;	

		
		
	-- SELECT RECORDS
	-- =========================================================================================
	
	-- FETCH COLUMNS
	-- ####################################################
	SELECT
		-- CATEGORY_ADDRESS_BARANGAY DETAILS
		`category_address_barangay`.`CAT_BARANGAY_ID`, 
		`category_address_barangay`.`CAT_BARANGAY_GLOBAL_ID`, 
		`category_address_barangay`.`CAT_BARANGAY_CAT_MUNICIPALITY_ID`, 
		`category_address_barangay`.`CAT_BARANGAY_CODE`, 
		`category_address_barangay`.`CAT_BARANGAY_DESCRIPTION`, 
		`category_address_barangay`.`CAT_BARANGAY_STATUS`, 
		`category_address_barangay`.`CAT_BARANGAY_SYSTEM_GENERATED`
		
		-- Inner join fields
		, 
		`category_address_municipality`.`CAT_MUNICIPALITY_ID`, 
		`category_address_municipality`.`CAT_MUNICIPALITY_GLOBAL_ID`, 
		`category_address_municipality`.`CAT_MUNICIPALITY_CAT_PROVINCE_ID`, 
		`category_address_municipality`.`CAT_MUNICIPALITY_CODE`, 
		`category_address_municipality`.`CAT_MUNICIPALITY_DESCRIPTION`, 
		`category_address_municipality`.`CAT_MUNICIPALITY_ZIP_CODE`, 
		`category_address_municipality`.`CAT_MUNICIPALITY_PHONE_CODE`, 
		`category_address_municipality`.`CAT_MUNICIPALITY_STATUS`, 
		`category_address_municipality`.`CAT_MUNICIPALITY_SYSTEM_GENERATED`
		
		-- Left join fields
		
		, TEMP_RECORD_COUNT AS RECORD_COUNT

	FROM `category_address_barangay`
	
		-- Add Inner Joins (Per Foreign-key)
		INNER JOIN `category_address_municipality` ON
		`category_address_municipality`.`CAT_MUNICIPALITY_ID` = `category_address_barangay`.`CAT_BARANGAY_CAT_MUNICIPALITY_ID`
		
		-- Add Optional Left Joins (Per Optional Foreign-key)
		
	-- CONDITIONS
	-- ####################################################
	WHERE
		(
			IS_NULL_CAT_BARANGAY_ID = 1 OR
			`category_address_barangay`.`CAT_BARANGAY_ID` = PARAM_CAT_BARANGAY_ID			
		) AND
		(
			IS_NULL_CAT_BARANGAY_GLOBAL_ID = 1 OR
			`category_address_barangay`.`CAT_BARANGAY_GLOBAL_ID` LIKE CONCAT_WS('%', '', PARAM_CAT_BARANGAY_GLOBAL_ID, '')			
		) AND 		
		(
			IS_NULL_CAT_BARANGAY_CAT_MUNICIPALITY_ID = 1 OR
			`category_address_barangay`.`CAT_BARANGAY_CAT_MUNICIPALITY_ID` = PARAM_CAT_BARANGAY_CAT_MUNICIPALITY_ID			
		) AND
		(
			IS_NULL_CAT_BARANGAY_CODE = 1 OR
			`category_address_barangay`.`CAT_BARANGAY_CODE` LIKE CONCAT_WS('%', '', PARAM_CAT_BARANGAY_CODE, '')			
		) AND 		
		(
			IS_NULL_CAT_BARANGAY_DESCRIPTION = 1 OR
			`category_address_barangay`.`CAT_BARANGAY_DESCRIPTION` LIKE CONCAT_WS('%', '', PARAM_CAT_BARANGAY_DESCRIPTION, '')			
		) AND 		
		(
			IS_NULL_CAT_BARANGAY_STATUS = 1 OR
			`category_address_barangay`.`CAT_BARANGAY_STATUS` = PARAM_CAT_BARANGAY_STATUS			
		) AND
		(
			IS_NULL_CAT_BARANGAY_SYSTEM_GENERATED = 1 OR
			`category_address_barangay`.`CAT_BARANGAY_SYSTEM_GENERATED` = PARAM_CAT_BARANGAY_SYSTEM_GENERATED			
		) 

	-- ORDER BY
	-- ####################################################
	ORDER BY
		-- CATEGORY_ADDRESS_BARANGAY DETAILS
		CASE WHEN PARAM_ORDER_FIELD = 'CAT_BARANGAY_ID' AND PARAM_ORDER_TYPE = 'ASC' THEN `category_address_barangay`.`CAT_BARANGAY_ID` END ASC, 
		CASE WHEN PARAM_ORDER_FIELD = 'CAT_BARANGAY_ID' AND PARAM_ORDER_TYPE = 'DESC' THEN `category_address_barangay`.`CAT_BARANGAY_ID` END DESC,	
		CASE WHEN PARAM_ORDER_FIELD = 'CAT_BARANGAY_GLOBAL_ID' AND PARAM_ORDER_TYPE = 'ASC' THEN `category_address_barangay`.`CAT_BARANGAY_GLOBAL_ID` END ASC, 
		CASE WHEN PARAM_ORDER_FIELD = 'CAT_BARANGAY_GLOBAL_ID' AND PARAM_ORDER_TYPE = 'DESC' THEN `category_address_barangay`.`CAT_BARANGAY_GLOBAL_ID` END DESC,	
		CASE WHEN PARAM_ORDER_FIELD = 'CAT_BARANGAY_CAT_MUNICIPALITY_ID' AND PARAM_ORDER_TYPE = 'ASC' THEN `category_address_barangay`.`CAT_BARANGAY_CAT_MUNICIPALITY_ID` END ASC, 
		CASE WHEN PARAM_ORDER_FIELD = 'CAT_BARANGAY_CAT_MUNICIPALITY_ID' AND PARAM_ORDER_TYPE = 'DESC' THEN `category_address_barangay`.`CAT_BARANGAY_CAT_MUNICIPALITY_ID` END DESC,	
		CASE WHEN PARAM_ORDER_FIELD = 'CAT_BARANGAY_CODE' AND PARAM_ORDER_TYPE = 'ASC' THEN `category_address_barangay`.`CAT_BARANGAY_CODE` END ASC, 
		CASE WHEN PARAM_ORDER_FIELD = 'CAT_BARANGAY_CODE' AND PARAM_ORDER_TYPE = 'DESC' THEN `category_address_barangay`.`CAT_BARANGAY_CODE` END DESC,	
		CASE WHEN PARAM_ORDER_FIELD = 'CAT_BARANGAY_DESCRIPTION' AND PARAM_ORDER_TYPE = 'ASC' THEN `category_address_barangay`.`CAT_BARANGAY_DESCRIPTION` END ASC, 
		CASE WHEN PARAM_ORDER_FIELD = 'CAT_BARANGAY_DESCRIPTION' AND PARAM_ORDER_TYPE = 'DESC' THEN `category_address_barangay`.`CAT_BARANGAY_DESCRIPTION` END DESC,	
		CASE WHEN PARAM_ORDER_FIELD = 'CAT_BARANGAY_STATUS' AND PARAM_ORDER_TYPE = 'ASC' THEN `category_address_barangay`.`CAT_BARANGAY_STATUS` END ASC, 
		CASE WHEN PARAM_ORDER_FIELD = 'CAT_BARANGAY_STATUS' AND PARAM_ORDER_TYPE = 'DESC' THEN `category_address_barangay`.`CAT_BARANGAY_STATUS` END DESC,	
		CASE WHEN PARAM_ORDER_FIELD = 'CAT_BARANGAY_SYSTEM_GENERATED' AND PARAM_ORDER_TYPE = 'ASC' THEN `category_address_barangay`.`CAT_BARANGAY_SYSTEM_GENERATED` END ASC, 
		CASE WHEN PARAM_ORDER_FIELD = 'CAT_BARANGAY_SYSTEM_GENERATED' AND PARAM_ORDER_TYPE = 'DESC' THEN `category_address_barangay`.`CAT_BARANGAY_SYSTEM_GENERATED` END DESC,	

		-- Inner joins
		CASE WHEN PARAM_ORDER_FIELD = 'CAT_MUNICIPALITY_ID' AND PARAM_ORDER_TYPE = 'ASC' THEN `category_address_municipality`.`CAT_MUNICIPALITY_ID` END ASC, 
		CASE WHEN PARAM_ORDER_FIELD = 'CAT_MUNICIPALITY_ID' AND PARAM_ORDER_TYPE = 'DESC' THEN `category_address_municipality`.`CAT_MUNICIPALITY_ID` END DESC,	
		CASE WHEN PARAM_ORDER_FIELD = 'CAT_MUNICIPALITY_GLOBAL_ID' AND PARAM_ORDER_TYPE = 'ASC' THEN `category_address_municipality`.`CAT_MUNICIPALITY_GLOBAL_ID` END ASC, 
		CASE WHEN PARAM_ORDER_FIELD = 'CAT_MUNICIPALITY_GLOBAL_ID' AND PARAM_ORDER_TYPE = 'DESC' THEN `category_address_municipality`.`CAT_MUNICIPALITY_GLOBAL_ID` END DESC,	
		CASE WHEN PARAM_ORDER_FIELD = 'CAT_MUNICIPALITY_CAT_PROVINCE_ID' AND PARAM_ORDER_TYPE = 'ASC' THEN `category_address_municipality`.`CAT_MUNICIPALITY_CAT_PROVINCE_ID` END ASC, 
		CASE WHEN PARAM_ORDER_FIELD = 'CAT_MUNICIPALITY_CAT_PROVINCE_ID' AND PARAM_ORDER_TYPE = 'DESC' THEN `category_address_municipality`.`CAT_MUNICIPALITY_CAT_PROVINCE_ID` END DESC,	
		CASE WHEN PARAM_ORDER_FIELD = 'CAT_MUNICIPALITY_CODE' AND PARAM_ORDER_TYPE = 'ASC' THEN `category_address_municipality`.`CAT_MUNICIPALITY_CODE` END ASC, 
		CASE WHEN PARAM_ORDER_FIELD = 'CAT_MUNICIPALITY_CODE' AND PARAM_ORDER_TYPE = 'DESC' THEN `category_address_municipality`.`CAT_MUNICIPALITY_CODE` END DESC,	
		CASE WHEN PARAM_ORDER_FIELD = 'CAT_MUNICIPALITY_DESCRIPTION' AND PARAM_ORDER_TYPE = 'ASC' THEN `category_address_municipality`.`CAT_MUNICIPALITY_DESCRIPTION` END ASC, 
		CASE WHEN PARAM_ORDER_FIELD = 'CAT_MUNICIPALITY_DESCRIPTION' AND PARAM_ORDER_TYPE = 'DESC' THEN `category_address_municipality`.`CAT_MUNICIPALITY_DESCRIPTION` END DESC,	
		CASE WHEN PARAM_ORDER_FIELD = 'CAT_MUNICIPALITY_ZIP_CODE' AND PARAM_ORDER_TYPE = 'ASC' THEN `category_address_municipality`.`CAT_MUNICIPALITY_ZIP_CODE` END ASC, 
		CASE WHEN PARAM_ORDER_FIELD = 'CAT_MUNICIPALITY_ZIP_CODE' AND PARAM_ORDER_TYPE = 'DESC' THEN `category_address_municipality`.`CAT_MUNICIPALITY_ZIP_CODE` END DESC,	
		CASE WHEN PARAM_ORDER_FIELD = 'CAT_MUNICIPALITY_PHONE_CODE' AND PARAM_ORDER_TYPE = 'ASC' THEN `category_address_municipality`.`CAT_MUNICIPALITY_PHONE_CODE` END ASC, 
		CASE WHEN PARAM_ORDER_FIELD = 'CAT_MUNICIPALITY_PHONE_CODE' AND PARAM_ORDER_TYPE = 'DESC' THEN `category_address_municipality`.`CAT_MUNICIPALITY_PHONE_CODE` END DESC,	
		CASE WHEN PARAM_ORDER_FIELD = 'CAT_MUNICIPALITY_STATUS' AND PARAM_ORDER_TYPE = 'ASC' THEN `category_address_municipality`.`CAT_MUNICIPALITY_STATUS` END ASC, 
		CASE WHEN PARAM_ORDER_FIELD = 'CAT_MUNICIPALITY_STATUS' AND PARAM_ORDER_TYPE = 'DESC' THEN `category_address_municipality`.`CAT_MUNICIPALITY_STATUS` END DESC,	
		CASE WHEN PARAM_ORDER_FIELD = 'CAT_MUNICIPALITY_SYSTEM_GENERATED' AND PARAM_ORDER_TYPE = 'ASC' THEN `category_address_municipality`.`CAT_MUNICIPALITY_SYSTEM_GENERATED` END ASC, 
		CASE WHEN PARAM_ORDER_FIELD = 'CAT_MUNICIPALITY_SYSTEM_GENERATED' AND PARAM_ORDER_TYPE = 'DESC' THEN `category_address_municipality`.`CAT_MUNICIPALITY_SYSTEM_GENERATED` END DESC,	
		
		-- EXTRA
		CASE WHEN PARAM_ORDER_FIELD <> 'CAT_BARANGAY_DESCRIPTION' THEN `category_address_barangay`.`CAT_BARANGAY_DESCRIPTION` END ASC
		
	-- LIMIT & OFFSET
	-- ####################################################		
	LIMIT PARAM_SKIP, PARAM_LIMIT;
	
	
	
	-- EXIT PROCEDURE
	-- =========================================================================================
	LEAVE SP_GET;
			
END ;;
DELIMITER ;
/*!50003 SET sql_mode              = @saved_sql_mode */ ;
/*!50003 SET character_set_client  = @saved_cs_client */ ;
/*!50003 SET character_set_results = @saved_cs_results */ ;
/*!50003 SET collation_connection  = @saved_col_connection */ ;
/*!50003 DROP PROCEDURE IF EXISTS `CATEGORY_ADDRESS_BARANGAY_SAVE` */;
/*!50003 SET @saved_cs_client      = @@character_set_client */ ;
/*!50003 SET @saved_cs_results     = @@character_set_results */ ;
/*!50003 SET @saved_col_connection = @@collation_connection */ ;
/*!50003 SET character_set_client  = latin1 */ ;
/*!50003 SET character_set_results = latin1 */ ;
/*!50003 SET collation_connection  = latin1_swedish_ci */ ;
/*!50003 SET @saved_sql_mode       = @@sql_mode */ ;
/*!50003 SET sql_mode              = '' */ ;
DELIMITER ;;
CREATE DEFINER=`root`@`localhost` PROCEDURE `CATEGORY_ADDRESS_BARANGAY_SAVE`(
	IN `PARAM_CAT_BARANGAY_ID` BIGINT,
	IN `PARAM_CAT_BARANGAY_CAT_MUNICIPALITY_ID` BIGINT,
	IN `PARAM_CAT_BARANGAY_CODE` VARCHAR(50),
	IN `PARAM_CAT_BARANGAY_DESCRIPTION` VARCHAR(500),
	IN `PARAM_CAT_BARANGAY_STATUS` TINYINT,

	IN `PARAM_REQUESTER_USERNAME` VARCHAR(500),
	IN `PARAM_REQUESTER_PASSWORD` VARCHAR(500),
	IN `PARAM_REQUESTER_PROXY_ID` BIGINT,
	IN `PARAM_REQUESTER_PROXY_PASSWORD` VARCHAR(1000),
	IN `PARAM_REQUESTER_DEVICE_PUBLIC_KEY` VARCHAR(1000),
	IN `PARAM_REQUESTER_DEVICE_PRIVATE_KEY` VARCHAR(1000),
	
	IN `PARAM_REQUESTER_IP` VARCHAR(1000),
	IN `PARAM_UNIQUE_SESSION_ID` VARCHAR(1000),
	IN `PARAM_SUPPRESS_RETURN` BIT,
	
	IN `PARAM_SYNC_SERVER_DESCRIPTION` VARCHAR(500), 
	IN `PARAM_SYNC_SERVER_UNIQUE_KEY` VARCHAR(500)
)
SP_SAVE:
BEGIN


	-- 1) DECLARE LOCAL PARAMETERS
	-- _______________________________________________________________________
	
	-- Status
	-- ...........................................
	DECLARE STATUS_INACTIVE TINYINT DEFAULT 1;
	DECLARE STATUS_ACTIVE TINYINT DEFAULT 2;
	DECLARE STATUS_CLOSED TINYINT DEFAULT 3;
	DECLARE STATUS_COMPLETED TINYINT DEFAULT 4;

	-- Audit Handler
	-- ...........................................
	DECLARE TEMP_RECORD_EXISTS BIT DEFAULT 0;
	DECLARE TEMP_MODULE_KEYWORD VARCHAR(500) DEFAULT 'category_address_barangay';
	DECLARE TEMP_SP_OBJECTIVE VARCHAR(500) DEFAULT 'add/edit Address: Barangay record';
	DECLARE TEMP_ERR_MESSAGE VARCHAR(500) DEFAULT '';
	DECLARE ERR BIGINT DEFAULT 0;
	DECLARE TEMP_RECORD_CHANGES VARCHAR(16000) DEFAULT '';
	DECLARE TEMP_RECORD_BINDED BIT DEFAULT 0;

	-- Authentication
	-- ...........................................
	DECLARE TEMP_ACCESS_RIGHTS_DENIED BIT DEFAULT 0;
	DECLARE TEMP_ACCESS_RIGHTS_HAS_OVERRIDE BIT DEFAULT 0;
	DECLARE TEMP_SYNC_SERVER_ID BIGINT DEFAULT 0;
	DECLARE TEMP_SYNC_IS_SERVER_REQUEST BIT DEFAULT 0;
	DECLARE TEMP_AUTHENTICATED_ACCOUNT_ID BIGINT DEFAULT `ACCOUNT_MEMBER@ACC_ACCOUNT_ID_FROM_LOGIN`(PARAM_REQUESTER_USERNAME, PARAM_REQUESTER_PASSWORD);
	DECLARE TEMP_AUTHENTICATED_ACCOUNT_LEVEL BIGINT DEFAULT 0;
	DECLARE TEMP_AUTHENTICATED_ACCOUNT_GROUP BIGINT DEFAULT 0;
	
	-- Local Parameters
	-- ...........................................
	DECLARE TEMP_NOW DATETIME(6) DEFAULT `SYSTEM_VAR@NOW`('', 1);
	DECLARE TEMP_RECORD_COUNT BIGINT DEFAULT 0;

	-- AutoGen Parameters
	-- ...........................................
	DECLARE PARAM_CAT_BARANGAY_GLOBAL_ID VARCHAR(400) DEFAULT ''; 
	DECLARE PARAM_CAT_BARANGAY_SYSTEM_GENERATED TINYINT DEFAULT 0; 
	
	-- Local value holder
	-- ...........................................
	DECLARE TEMP_CAT_BARANGAY_GLOBAL_ID VARCHAR(400) DEFAULT ''; 
	DECLARE TEMP_CAT_BARANGAY_CAT_MUNICIPALITY_ID BIGINT DEFAULT 0; 
	DECLARE TEMP_CAT_BARANGAY_CODE VARCHAR(50) DEFAULT ''; 
	DECLARE TEMP_CAT_BARANGAY_DESCRIPTION VARCHAR(500) DEFAULT ''; 
	DECLARE TEMP_CAT_BARANGAY_STATUS TINYINT DEFAULT 0; 
	DECLARE TEMP_CAT_BARANGAY_SYSTEM_GENERATED TINYINT DEFAULT 0; 
	


	-- 2) Try Catch / Throw
	-- _______________________________________________________________________
	DECLARE EXIT HANDLER FOR SQLEXCEPTION
	BEGIN
		RESIGNAL;
	END;



	-- 3) Prepare SYNC
	-- _______________________________________________________________________

	-- IS RECORD EXISTS		
	-- ####################################################	
	SET TEMP_RECORD_EXISTS = `CATEGORY_ADDRESS_BARANGAY@CAT_BARANGAY_ID_EXISTS`(PARAM_CAT_BARANGAY_ID, 0);

		
		
	-- 4) PREPARE AUTOGEN DATA (IF EXISTS)
	-- _______________________________________________________________________
	IF TEMP_SYNC_IS_SERVER_REQUEST = 0 THEN
		-- Just to keep at least one line within condition
		SET TEMP_SYNC_IS_SERVER_REQUEST = 0;
		
		-- Actual Functionalities here
		-- USE DEFAULT VALUE (String)
		-- USE DEFAULT VALUE (String)
		SET PARAM_CAT_BARANGAY_GLOBAL_ID = `SYSTEM_VAR@RANDOM_UNIQUE_ALPHA32`;
		-- USE DEFAULT VALUE (String)
		SET PARAM_CAT_BARANGAY_SYSTEM_GENERATED = 1;
	-- USE TIMESTAMP
	END IF;



	-- 5) IF ALREADY EXIST, FILL MISSING DATA
	-- _______________________________________________________________________
	IF TEMP_RECORD_EXISTS = 1 THEN
		SELECT
			`category_address_barangay`.`CAT_BARANGAY_GLOBAL_ID`, 	
			`category_address_barangay`.`CAT_BARANGAY_CAT_MUNICIPALITY_ID`, 	
			`category_address_barangay`.`CAT_BARANGAY_CODE`, 	
			`category_address_barangay`.`CAT_BARANGAY_DESCRIPTION`, 	
			`category_address_barangay`.`CAT_BARANGAY_STATUS`, 	
			`category_address_barangay`.`CAT_BARANGAY_SYSTEM_GENERATED`	
		INTO
			TEMP_CAT_BARANGAY_GLOBAL_ID, 	
			TEMP_CAT_BARANGAY_CAT_MUNICIPALITY_ID, 	
			TEMP_CAT_BARANGAY_CODE, 	
			TEMP_CAT_BARANGAY_DESCRIPTION, 	
			TEMP_CAT_BARANGAY_STATUS, 	
			TEMP_CAT_BARANGAY_SYSTEM_GENERATED	

		FROM `category_address_barangay`
		WHERE
			`category_address_barangay`.`CAT_BARANGAY_ID` = PARAM_CAT_BARANGAY_ID
		LIMIT 1;

		-- Replace NULLs with the existing data.
		SET PARAM_CAT_BARANGAY_CAT_MUNICIPALITY_ID = `SYSTEM_VAR@REPLACE_NULL@BIGINT`(PARAM_CAT_BARANGAY_CAT_MUNICIPALITY_ID, TEMP_CAT_BARANGAY_CAT_MUNICIPALITY_ID, 1, 1);
		SET PARAM_CAT_BARANGAY_CODE = `SYSTEM_VAR@REPLACE_NULL@NVARCHAR`(PARAM_CAT_BARANGAY_CODE, TEMP_CAT_BARANGAY_CODE, 1);
		SET PARAM_CAT_BARANGAY_DESCRIPTION = `SYSTEM_VAR@REPLACE_NULL@NVARCHAR`(PARAM_CAT_BARANGAY_DESCRIPTION, TEMP_CAT_BARANGAY_DESCRIPTION, 1);
		SET PARAM_CAT_BARANGAY_STATUS = `SYSTEM_VAR@REPLACE_NULL@TINYINT`(PARAM_CAT_BARANGAY_STATUS, TEMP_CAT_BARANGAY_STATUS, 1, 1);
		
		-- AUTO GEN (NON-UPDATABLES)		
		SET PARAM_CAT_BARANGAY_GLOBAL_ID = TEMP_CAT_BARANGAY_GLOBAL_ID;
		SET PARAM_CAT_BARANGAY_SYSTEM_GENERATED = TEMP_CAT_BARANGAY_SYSTEM_GENERATED;
		
		-- AUTO GEN (UPDATABLE WITH STATUS CHANGE)

		-- AUTO GEN (UPDATABLE WITH STATUS [ACTIVE/INACTIVE] CHANGE)
		
	ELSE
		SET PARAM_CAT_BARANGAY_CAT_MUNICIPALITY_ID = `SYSTEM_VAR@REPLACE_NULL@BIGINT`(PARAM_CAT_BARANGAY_CAT_MUNICIPALITY_ID, 0, 1, 1);
		SET PARAM_CAT_BARANGAY_CODE = `SYSTEM_VAR@REPLACE_NULL@NVARCHAR`(PARAM_CAT_BARANGAY_CODE, '', 1);
		SET PARAM_CAT_BARANGAY_DESCRIPTION = `SYSTEM_VAR@REPLACE_NULL@NVARCHAR`(PARAM_CAT_BARANGAY_DESCRIPTION, '', 1);
		SET PARAM_CAT_BARANGAY_STATUS = `SYSTEM_VAR@REPLACE_NULL@TINYINT`(PARAM_CAT_BARANGAY_STATUS, 0, 1, 1);
		
	END IF;

	

	-- 6) PREPARE AUDIT TRAIL
	-- _______________________________________________________________________
	IF BINARY TEMP_CAT_BARANGAY_GLOBAL_ID <> PARAM_CAT_BARANGAY_GLOBAL_ID THEN
		SET TEMP_RECORD_CHANGES = 
		`SYSTEM_VAR@CONCAT_ADD`(' | ', TEMP_RECORD_CHANGES, CONCAT_WS(' ', 'Sync ID: "', TEMP_CAT_BARANGAY_GLOBAL_ID, '" > "', PARAM_CAT_BARANGAY_GLOBAL_ID, '"'));
	END IF;
	IF TEMP_CAT_BARANGAY_CAT_MUNICIPALITY_ID <> PARAM_CAT_BARANGAY_CAT_MUNICIPALITY_ID THEN
		SET TEMP_RECORD_CHANGES = 
		`SYSTEM_VAR@CONCAT_ADD`(' | ', TEMP_RECORD_CHANGES, CONCAT_WS(' ', 'Municipality: "', TEMP_CAT_BARANGAY_CAT_MUNICIPALITY_ID, '" > "', PARAM_CAT_BARANGAY_CAT_MUNICIPALITY_ID, '"'));
	END IF;	
	IF BINARY TEMP_CAT_BARANGAY_CODE <> PARAM_CAT_BARANGAY_CODE THEN
		SET TEMP_RECORD_CHANGES = 
		`SYSTEM_VAR@CONCAT_ADD`(' | ', TEMP_RECORD_CHANGES, CONCAT_WS(' ', 'Code: "', TEMP_CAT_BARANGAY_CODE, '" > "', PARAM_CAT_BARANGAY_CODE, '"'));
	END IF;
	IF BINARY TEMP_CAT_BARANGAY_DESCRIPTION <> PARAM_CAT_BARANGAY_DESCRIPTION THEN
		SET TEMP_RECORD_CHANGES = 
		`SYSTEM_VAR@CONCAT_ADD`(' | ', TEMP_RECORD_CHANGES, CONCAT_WS(' ', 'Description: "', TEMP_CAT_BARANGAY_DESCRIPTION, '" > "', PARAM_CAT_BARANGAY_DESCRIPTION, '"'));
	END IF;
	IF TEMP_CAT_BARANGAY_STATUS <> PARAM_CAT_BARANGAY_STATUS THEN
		SET TEMP_RECORD_CHANGES = 
		`SYSTEM_VAR@CONCAT_ADD`(' | ', TEMP_RECORD_CHANGES, CONCAT_WS(' ', 'Status: "', TEMP_CAT_BARANGAY_STATUS, '" > "', PARAM_CAT_BARANGAY_STATUS, '"'));
	END IF;	
	IF TEMP_CAT_BARANGAY_SYSTEM_GENERATED <> PARAM_CAT_BARANGAY_SYSTEM_GENERATED THEN
		SET TEMP_RECORD_CHANGES = 
		`SYSTEM_VAR@CONCAT_ADD`(' | ', TEMP_RECORD_CHANGES, CONCAT_WS(' ', 'System Generated: "', TEMP_CAT_BARANGAY_SYSTEM_GENERATED, '" > "', PARAM_CAT_BARANGAY_SYSTEM_GENERATED, '"'));
	END IF;	
		
	-- No Changes in data, reject request
	-- ####################################################
	IF CHARACTER_LENGTH(TEMP_RECORD_CHANGES) = 0 THEN
		IF PARAM_SUPPRESS_RETURN = 0 THEN
			SELECT PARAM_CAT_BARANGAY_ID AS INSERTED_ID;
		END IF;
		LEAVE SP_SAVE;
	END IF;



	-- 7) VALIDATE
	-- _______________________________________________________________________

	-- Access Rights [Device]
	-- ####################################################
	IF `ACCOUNT_DEVICE@HAS_PERMISSION`(PARAM_REQUESTER_DEVICE_PUBLIC_KEY, PARAM_REQUESTER_DEVICE_PRIVATE_KEY) = 0 THEN
		SET TEMP_ERR_MESSAGE = 'Your device is not authorized yet to access this server.';
		SET ERR = `RAISERROR`(TEMP_ERR_MESSAGE);		
	END IF;
		
		
	-- Access Rights [Account]
	-- ####################################################
	
	IF 
		-- [ADD] Access Rights
		(
			TEMP_RECORD_EXISTS = 0 AND
			`ACCOUNT_ACCESS_RIGHTS@HAS_PERMISSION`(PARAM_REQUESTER_USERNAME, PARAM_REQUESTER_PASSWORD, 0, TEMP_MODULE_KEYWORD, 2) = 0 
		) OR
		
		-- [EDIT] Access Rights
		(
			TEMP_RECORD_EXISTS = 1 AND
			`ACCOUNT_ACCESS_RIGHTS@HAS_PERMISSION`(PARAM_REQUESTER_USERNAME, PARAM_REQUESTER_PASSWORD, 0, TEMP_MODULE_KEYWORD, 3) = 0 
		)
	THEN
		SET TEMP_ACCESS_RIGHTS_DENIED = 1;
		CALL `ACCOUNT_ACCESS_RIGHTS_DENY`
		(
			0, TEMP_MODULE_KEYWORD, PARAM_CAT_BARANGAY_ID, 0, TEMP_SP_OBJECTIVE, TEMP_RECORD_CHANGES, 
			PARAM_REQUESTER_USERNAME, PARAM_REQUESTER_PASSWORD, 
			PARAM_REQUESTER_PROXY_ID, PARAM_REQUESTER_PROXY_PASSWORD,
			PARAM_REQUESTER_DEVICE_PUBLIC_KEY, PARAM_REQUESTER_DEVICE_PRIVATE_KEY,
			PARAM_REQUESTER_IP, PARAM_UNIQUE_SESSION_ID,
			TEMP_SYNC_SERVER_ID, PARAM_SUPPRESS_RETURN
		);
	END IF;
	SET TEMP_ACCESS_RIGHTS_HAS_OVERRIDE = `ACCOUNT_ACCESS_RIGHTS@HAS_PERMISSION`(PARAM_REQUESTER_USERNAME, PARAM_REQUESTER_PASSWORD, 0, TEMP_MODULE_KEYWORD, 4);
	

	-- Validation
	-- ####################################################
	IF TEMP_SYNC_IS_SERVER_REQUEST = 0 THEN
	
		-- SYSTEM GENERATED = TRUE
		-- ...........................................
		IF TEMP_CAT_BARANGAY_SYSTEM_GENERATED = STATUS_ACTIVE THEN
		CALL `VALIDATION_SYSTEM_GENERATED`
		(
			PARAM_CAT_BARANGAY_ID,
			TEMP_CAT_BARANGAY_DESCRIPTION, ''
		);
		END IF;

		-- FOREIGN KEY EXISTS
		-- ...........................................
		IF `CATEGORY_ADDRESS_MUNICIPALITY@CAT_MUNICIPALITY_ID_EXISTS`(PARAM_CAT_BARANGAY_CAT_MUNICIPALITY_ID, 0) =  0 THEN
			SET TEMP_ERR_MESSAGE = CONCAT_WS(' ', 'Given Municipality does not exists or is inactive. ID: ', PARAM_CAT_BARANGAY_CAT_MUNICIPALITY_ID);
			SET ERR = `RAISERROR`(TEMP_ERR_MESSAGE);
		END IF;
		
		-- FOREIGN (OPTIONAL)KEY EXISTS [Validates if not null]
		-- ...........................................
		
		-- IS_ALLOW_NULL = FALSE
		-- ...........................................
				
		-- IS_ALLOW_ZERO = FALSE
		-- ...........................................
		IF PARAM_CAT_BARANGAY_STATUS = 0 THEN
			CALL `VALIDATION_MISSING_FIELD`('`CAT_BARANGAY_STATUS`', '`NULL`');
		END IF;		
		IF PARAM_CAT_BARANGAY_SYSTEM_GENERATED = 0 THEN
			CALL `VALIDATION_MISSING_FIELD`('`CAT_BARANGAY_SYSTEM_GENERATED`', '`NULL`');
		END IF;		
		
		-- IS_ALLOW_NEGATIVE = FALSE
		-- ...........................................
		IF PARAM_CAT_BARANGAY_STATUS < 0 THEN
			CALL `VALIDATION_NEGATIVE`('`CAT_BARANGAY_STATUS`', PARAM_CAT_BARANGAY_STATUS);
		END IF;		
		IF PARAM_CAT_BARANGAY_SYSTEM_GENERATED < 0 THEN
			CALL `VALIDATION_NEGATIVE`('`CAT_BARANGAY_SYSTEM_GENERATED`', PARAM_CAT_BARANGAY_SYSTEM_GENERATED);
		END IF;		
		
		-- IS_ALLOW_EMPTY_STRING = FALSE
		-- ...........................................
		IF `SYSTEM_VAR@IS_NULL@NVARCHAR`(PARAM_CAT_BARANGAY_GLOBAL_ID, 1) = 1 THEN
			CALL `VALIDATION_MISSING_FIELD`('`CAT_BARANGAY_GLOBAL_ID`', '`NULL`');
		END IF;
		IF `SYSTEM_VAR@IS_NULL@NVARCHAR`(PARAM_CAT_BARANGAY_CODE, 1) = 1 THEN
			CALL `VALIDATION_MISSING_FIELD`('`CAT_BARANGAY_CODE`', '`NULL`');
		END IF;
		IF `SYSTEM_VAR@IS_NULL@NVARCHAR`(PARAM_CAT_BARANGAY_DESCRIPTION, 1) = 1 THEN
			CALL `VALIDATION_MISSING_FIELD`('`CAT_BARANGAY_DESCRIPTION`', '`NULL`');
		END IF;
		
		-- IS_STATUS
		-- ...........................................
		IF `SYSTEM_STATUS@STATUS_ID_EXISTS`(PARAM_CAT_BARANGAY_STATUS, 0) = 0 THEN
			SET TEMP_ERR_MESSAGE = CONCAT_WS(' ', 'Given STATUS[Status] does not exists or is inactive. ID: ', PARAM_CAT_BARANGAY_STATUS);
			SET ERR = `RAISERROR`(TEMP_ERR_MESSAGE);
		END IF;
		
		-- IS STATUS Active / Inactive
		-- ...........................................
		
		-- Minimum / Maximum Value
		-- ...........................................
		
		-- IS_UNIQUE = TRUE
		-- ...........................................
		IF
		(
			SELECT COUNT(`category_address_barangay`.`CAT_BARANGAY_ID`)
			FROM `category_address_barangay`
			WHERE		
				`category_address_barangay`.`CAT_BARANGAY_GLOBAL_ID` = PARAM_CAT_BARANGAY_GLOBAL_ID AND		
				`category_address_barangay`.`CAT_BARANGAY_ID` <> PARAM_CAT_BARANGAY_ID
		) >= 1
		THEN
			CALL `VALIDATION_REDUNDANT_ENTRY`(PARAM_CAT_BARANGAY_DESCRIPTION);
		END IF;
		
		-- RECORD IDENTIFIER
		-- ...........................................
		IF
		(
			SELECT COUNT(`category_address_barangay`.`CAT_BARANGAY_ID`)
			FROM `category_address_barangay`
			WHERE
				`category_address_barangay`.`CAT_BARANGAY_CAT_MUNICIPALITY_ID` = PARAM_CAT_BARANGAY_CAT_MUNICIPALITY_ID AND
				`category_address_barangay`.`CAT_BARANGAY_DESCRIPTION` = PARAM_CAT_BARANGAY_DESCRIPTION AND
				`category_address_barangay`.`CAT_BARANGAY_ID` <> PARAM_CAT_BARANGAY_ID
		) >= 1
		THEN
			CALL `VALIDATION_REDUNDANT_ENTRY`(PARAM_CAT_BARANGAY_DESCRIPTION);
		END IF;
		
		
		-- ON_UPDATE VALIDATION 
		-- ...........................................
		IF TEMP_RECORD_EXISTS = 1 THEN	
		
			-- Just to keep at least one line within condition
			SET TEMP_RECORD_EXISTS = 1;
			
		END IF;
		
	END IF;



	-- 8) INSERT / UPDATE
	-- _______________________________________________________________________

	-- INSERT NEW DATA
	-- ####################################################
	IF TEMP_RECORD_EXISTS = 0 THEN

		INSERT INTO
		`category_address_barangay`
		(
			`category_address_barangay`.`CAT_BARANGAY_GLOBAL_ID`, 
			`category_address_barangay`.`CAT_BARANGAY_CAT_MUNICIPALITY_ID`, 
			`category_address_barangay`.`CAT_BARANGAY_CODE`, 
			`category_address_barangay`.`CAT_BARANGAY_DESCRIPTION`, 
			`category_address_barangay`.`CAT_BARANGAY_STATUS`, 
			`category_address_barangay`.`CAT_BARANGAY_SYSTEM_GENERATED`
		)
		VALUES
		(
			PARAM_CAT_BARANGAY_GLOBAL_ID, 
			PARAM_CAT_BARANGAY_CAT_MUNICIPALITY_ID, 
			PARAM_CAT_BARANGAY_CODE, 
			PARAM_CAT_BARANGAY_DESCRIPTION, 
			PARAM_CAT_BARANGAY_STATUS, 
			PARAM_CAT_BARANGAY_SYSTEM_GENERATED
		);	
		
		-- Update Audit trail with new ID	
		SET PARAM_CAT_BARANGAY_ID = LAST_INSERT_ID();



	-- UPDATING EXISTING RECORD
	-- ####################################################
	ELSE
		UPDATE `category_address_barangay`
		SET
			`category_address_barangay`.`CAT_BARANGAY_GLOBAL_ID` = PARAM_CAT_BARANGAY_GLOBAL_ID, 
			`category_address_barangay`.`CAT_BARANGAY_CAT_MUNICIPALITY_ID` = PARAM_CAT_BARANGAY_CAT_MUNICIPALITY_ID, 
			`category_address_barangay`.`CAT_BARANGAY_CODE` = PARAM_CAT_BARANGAY_CODE, 
			`category_address_barangay`.`CAT_BARANGAY_DESCRIPTION` = PARAM_CAT_BARANGAY_DESCRIPTION, 
			`category_address_barangay`.`CAT_BARANGAY_STATUS` = PARAM_CAT_BARANGAY_STATUS, 
			`category_address_barangay`.`CAT_BARANGAY_SYSTEM_GENERATED` = PARAM_CAT_BARANGAY_SYSTEM_GENERATED
		WHERE
			`category_address_barangay`.`CAT_BARANGAY_ID` = PARAM_CAT_BARANGAY_ID;

	END IF;

	
	-- 9) AUDIT TRAIL
	-- _______________________________________________________________________
	CALL `ACCOUNT_AUDIT_TRAIL_SAVE`
	(
		0, TEMP_MODULE_KEYWORD, PARAM_CAT_BARANGAY_ID, 0, 'SAVE', TEMP_SP_OBJECTIVE, TEMP_RECORD_CHANGES, 
		PARAM_REQUESTER_USERNAME, PARAM_REQUESTER_PASSWORD, 
		PARAM_REQUESTER_PROXY_ID, PARAM_REQUESTER_PROXY_PASSWORD,
		PARAM_REQUESTER_DEVICE_PUBLIC_KEY, PARAM_REQUESTER_DEVICE_PRIVATE_KEY,
		PARAM_REQUESTER_IP, PARAM_UNIQUE_SESSION_ID,
		TEMP_SYNC_SERVER_ID, PARAM_SUPPRESS_RETURN
	);
	

	-- 10) RETURN RESULT
	-- _______________________________________________________________________
	IF PARAM_SUPPRESS_RETURN = 0 THEN
		SELECT PARAM_CAT_BARANGAY_ID AS INSERTED_ID;
	END IF;
	LEAVE SP_SAVE;


END ;;
DELIMITER ;
/*!50003 SET sql_mode              = @saved_sql_mode */ ;
/*!50003 SET character_set_client  = @saved_cs_client */ ;
/*!50003 SET character_set_results = @saved_cs_results */ ;
/*!50003 SET collation_connection  = @saved_col_connection */ ;
/*!50003 DROP PROCEDURE IF EXISTS `CATEGORY_ADDRESS_COUNTRY_DELETE` */;
/*!50003 SET @saved_cs_client      = @@character_set_client */ ;
/*!50003 SET @saved_cs_results     = @@character_set_results */ ;
/*!50003 SET @saved_col_connection = @@collation_connection */ ;
/*!50003 SET character_set_client  = latin1 */ ;
/*!50003 SET character_set_results = latin1 */ ;
/*!50003 SET collation_connection  = latin1_swedish_ci */ ;
/*!50003 SET @saved_sql_mode       = @@sql_mode */ ;
/*!50003 SET sql_mode              = '' */ ;
DELIMITER ;;
CREATE DEFINER=`root`@`localhost` PROCEDURE `CATEGORY_ADDRESS_COUNTRY_DELETE`(
	IN `PARAM_CAT_COUNTRY_ID` BIGINT,

	IN `PARAM_REQUESTER_USERNAME` VARCHAR(500),
	IN `PARAM_REQUESTER_PASSWORD` VARCHAR(500),
	IN `PARAM_REQUESTER_PROXY_ID` BIGINT,
	IN `PARAM_REQUESTER_PROXY_PASSWORD` VARCHAR(1000),
	IN `PARAM_REQUESTER_DEVICE_PUBLIC_KEY` VARCHAR(1000),
	IN `PARAM_REQUESTER_DEVICE_PRIVATE_KEY` VARCHAR(1000),
	
	IN `PARAM_REQUESTER_IP` VARCHAR(1000),
	IN `PARAM_UNIQUE_SESSION_ID` VARCHAR(1000),
	IN `PARAM_SUPPRESS_RETURN` BIT,
	
	IN `PARAM_SYNC_SERVER_DESCRIPTION` VARCHAR(500), 
	IN `PARAM_SYNC_SERVER_UNIQUE_KEY` VARCHAR(500)
)
SP_DELETE:
BEGIN

	-- 1) DECLARE LOCAL PARAMETERS
	-- _______________________________________________________________________
	
	-- Status
	-- ...........................................
	DECLARE STATUS_INACTIVE TINYINT DEFAULT 1;
	DECLARE STATUS_ACTIVE TINYINT DEFAULT 2;
	DECLARE STATUS_CLOSED TINYINT DEFAULT 3;
	DECLARE STATUS_COMPLETED TINYINT DEFAULT 4;
	
	-- Audit Handler
	-- ...........................................
	DECLARE TEMP_RECORD_EXISTS BIT DEFAULT 0;
	DECLARE TEMP_MODULE_KEYWORD VARCHAR(500) DEFAULT 'category_address_country';
	DECLARE TEMP_SP_OBJECTIVE VARCHAR(500) DEFAULT 'delete Address: Country record';
	DECLARE TEMP_ERR_MESSAGE VARCHAR(500) DEFAULT '';
	DECLARE ERR BIGINT DEFAULT 0;
	DECLARE TEMP_RECORD_CHANGES VARCHAR(16000) DEFAULT '';
	DECLARE TEMP_RECORD_BINDED BIT DEFAULT 0;
	
	DECLARE TEMP_RECORD_BINDED_ID BIGINT DEFAULT 0;
	DECLARE TEMP_RECORD_BINDED_SERVER_ID BIGINT DEFAULT 0;
	
	-- Authentication
	-- ...........................................
	DECLARE TEMP_ACCESS_RIGHTS_DENIED BIT DEFAULT 0;
	DECLARE TEMP_SYNC_SERVER_ID BIGINT DEFAULT 0;
	DECLARE TEMP_SYNC_IS_SERVER_REQUEST BIT DEFAULT 0;
	DECLARE TEMP_AUTHENTICATED_ACCOUNT_ID BIGINT DEFAULT `ACCOUNT_MEMBER@ACC_ACCOUNT_ID_FROM_LOGIN`(PARAM_REQUESTER_USERNAME, PARAM_REQUESTER_PASSWORD);
	DECLARE TEMP_AUTHENTICATED_ACCOUNT_LEVEL BIGINT DEFAULT 0;
	DECLARE TEMP_AUTHENTICATED_ACCOUNT_GROUP BIGINT DEFAULT 0;

	-- Local value holder
	-- ...........................................
		DECLARE TEMP_CAT_COUNTRY_GLOBAL_ID VARCHAR(400) DEFAULT ''; 
		DECLARE TEMP_CAT_COUNTRY_CODE VARCHAR(50) DEFAULT ''; 
		DECLARE TEMP_CAT_COUNTRY_DESCRIPTION VARCHAR(500) DEFAULT ''; 
		DECLARE TEMP_CAT_COUNTRY_STATUS TINYINT DEFAULT 0; 
		DECLARE TEMP_CAT_COUNTRY_SYSTEM_GENERATED TINYINT DEFAULT 0; 

	
	
	-- 2) Try Catch / Throw
	-- _______________________________________________________________________
	DECLARE EXIT HANDLER FOR SQLEXCEPTION
	BEGIN
		RESIGNAL;
	END;

	
	-- 3) Prepare SYNC
	-- _______________________________________________________________________
	
	-- IS RECORD EXISTS		
	-- ####################################################		
	SET TEMP_RECORD_EXISTS = `CATEGORY_ADDRESS_COUNTRY@CAT_COUNTRY_ID_EXISTS`(PARAM_CAT_COUNTRY_ID, 0);


	-- 4) IF ALREADY EXIST, FILL MISSING DATA
	-- _______________________________________________________________________
	IF TEMP_RECORD_EXISTS = 1 THEN
		SELECT
				`category_address_country`.`CAT_COUNTRY_GLOBAL_ID`, 	
				`category_address_country`.`CAT_COUNTRY_CODE`, 	
				`category_address_country`.`CAT_COUNTRY_DESCRIPTION`, 	
				`category_address_country`.`CAT_COUNTRY_STATUS`, 	
				`category_address_country`.`CAT_COUNTRY_SYSTEM_GENERATED`	
		INTO
				TEMP_CAT_COUNTRY_GLOBAL_ID, 	
				TEMP_CAT_COUNTRY_CODE, 	
				TEMP_CAT_COUNTRY_DESCRIPTION, 	
				TEMP_CAT_COUNTRY_STATUS, 	
				TEMP_CAT_COUNTRY_SYSTEM_GENERATED	

		FROM `category_address_country`
		WHERE
			`category_address_country`.`CAT_COUNTRY_ID` = PARAM_CAT_COUNTRY_ID
		LIMIT 1;

	ELSE 
		IF TEMP_SYNC_IS_SERVER_REQUEST = 0 THEN
			SET TEMP_ERR_MESSAGE = CONCAT_WS(' ', 'Given Address: Country does not exists or is inactive. ID:', PARAM_CAT_COUNTRY_ID);
			SET ERR = `RAISERROR`(TEMP_ERR_MESSAGE);		
		END IF;
		LEAVE SP_DELETE;
		
	END IF;



	-- 5) PREPARE AUDIT TRAIL
	-- _______________________________________________________________________
	
		SET TEMP_RECORD_CHANGES = 
		`SYSTEM_VAR@CONCAT_ADD`(' | ', TEMP_RECORD_CHANGES, CONCAT_WS(' ', 'Sync ID: "', TEMP_CAT_COUNTRY_GLOBAL_ID, '" > " DELETED "'));
		SET TEMP_RECORD_CHANGES = 
		`SYSTEM_VAR@CONCAT_ADD`(' | ', TEMP_RECORD_CHANGES, CONCAT_WS(' ', 'Unique Code: "', TEMP_CAT_COUNTRY_CODE, '" > " DELETED "'));
		SET TEMP_RECORD_CHANGES = 
		`SYSTEM_VAR@CONCAT_ADD`(' | ', TEMP_RECORD_CHANGES, CONCAT_WS(' ', 'Description: "', TEMP_CAT_COUNTRY_DESCRIPTION, '" > " DELETED "'));
		SET TEMP_RECORD_CHANGES = 
		`SYSTEM_VAR@CONCAT_ADD`(' | ', TEMP_RECORD_CHANGES, CONCAT_WS(' ', 'Status: "', TEMP_CAT_COUNTRY_STATUS, '" > " DELETED "'));
		SET TEMP_RECORD_CHANGES = 
		`SYSTEM_VAR@CONCAT_ADD`(' | ', TEMP_RECORD_CHANGES, CONCAT_WS(' ', 'System Generated: "', TEMP_CAT_COUNTRY_SYSTEM_GENERATED, '" > " DELETED "'));


	-- 6) VALIDATE
	-- _______________________________________________________________________
	
	-- Access Rights [Device]
	-- ####################################################
	IF `ACCOUNT_DEVICE@HAS_PERMISSION`(PARAM_REQUESTER_DEVICE_PUBLIC_KEY, PARAM_REQUESTER_DEVICE_PRIVATE_KEY) = 0 THEN
		SET TEMP_ERR_MESSAGE = 'Your device is not authorized yet to access this server.';
		SET ERR = `RAISERROR`(TEMP_ERR_MESSAGE);		
	END IF;
		
		
	-- Access Rights [Account]
	-- ####################################################	
	
	IF 
		-- [DELETE] Access Rights
		`ACCOUNT_ACCESS_RIGHTS@HAS_PERMISSION`(PARAM_REQUESTER_USERNAME, PARAM_REQUESTER_PASSWORD, 0, TEMP_MODULE_KEYWORD, 4) = 0 
	THEN
		SET TEMP_ACCESS_RIGHTS_DENIED = 1;
		CALL `ACCOUNT_ACCESS_RIGHTS_DENY`
		(
			0, TEMP_MODULE_KEYWORD, PARAM_CAT_COUNTRY_ID, 0, TEMP_SP_OBJECTIVE, TEMP_RECORD_CHANGES, 
			PARAM_REQUESTER_USERNAME, PARAM_REQUESTER_PASSWORD, 
			PARAM_REQUESTER_PROXY_ID, PARAM_REQUESTER_PROXY_PASSWORD,
			PARAM_REQUESTER_DEVICE_PUBLIC_KEY, PARAM_REQUESTER_DEVICE_PRIVATE_KEY,
			PARAM_REQUESTER_IP, PARAM_UNIQUE_SESSION_ID,
			TEMP_SYNC_SERVER_ID, PARAM_SUPPRESS_RETURN
		);
	END IF;

	-- System Generated Record (Cannot be deleted)
	-- ####################################################
	IF TEMP_CAT_COUNTRY_SYSTEM_GENERATED = STATUS_ACTIVE THEN
		CALL `VALIDATION_SYSTEM_GENERATED`
		(
			PARAM_CAT_COUNTRY_ID,
			TEMP_CAT_COUNTRY_DESCRIPTION, ''
		);
	END IF;
	
	-- If already used, cannot remove record
	-- ####################################################
	IF
	(
		SELECT
			COUNT(`category_address_region`.`CAT_REGION_CAT_COUNTRY_ID`)
		FROM `category_address_region`
		WHERE
			`category_address_region`.`CAT_REGION_CAT_COUNTRY_ID` = PARAM_CAT_COUNTRY_ID
		LIMIT 1
	) >= 1 
	THEN
		SET TEMP_RECORD_BINDED = 1;
		SET TEMP_ERR_MESSAGE = 'Address: Region Record';
	END IF;
	IF
	(
		SELECT
			COUNT(`category_branch`.`CAT_BRANCH_CAT_COUNTRY_ID`)
		FROM `category_branch`
		WHERE
			`category_branch`.`CAT_BRANCH_CAT_COUNTRY_ID` = PARAM_CAT_COUNTRY_ID
		LIMIT 1
	) >= 1 
	THEN
		SET TEMP_RECORD_BINDED = 1;
		SET TEMP_ERR_MESSAGE = 'Branch Record';
	END IF;
	IF
	(
		SELECT
			COUNT(`record_combatants`.`REC_COMBATANT_CAT_COUNTRY_ID`)
		FROM `record_combatants`
		WHERE
			`record_combatants`.`REC_COMBATANT_CAT_COUNTRY_ID` = PARAM_CAT_COUNTRY_ID
		LIMIT 1
	) >= 1 
	THEN
		SET TEMP_RECORD_BINDED = 1;
		SET TEMP_ERR_MESSAGE = 'Combatant Information Record';
	END IF;

	-- Leave Re-upload request
	-- ####################################################
	IF TEMP_RECORD_BINDED = 1 THEN
		IF TEMP_SYNC_IS_SERVER_REQUEST = 1 THEN
			
			LEAVE SP_DELETE;
		END IF;

		CALL `VALIDATION_DELETE_LINKED_RECORD`(TEMP_CAT_COUNTRY_DESCRIPTION, '', TEMP_ERR_MESSAGE); 
	END IF;


	-- 7) DELETE
	-- _______________________________________________________________________
	DELETE FROM `category_address_country`
	WHERE `category_address_country`.`CAT_COUNTRY_ID` = PARAM_CAT_COUNTRY_ID
	LIMIT 1;


	-- 8) AUDIT TRAIL
	-- _______________________________________________________________________
	CALL `ACCOUNT_AUDIT_TRAIL_SAVE`
	(
		0, TEMP_MODULE_KEYWORD, PARAM_CAT_COUNTRY_ID, 0, 'DELETE', TEMP_SP_OBJECTIVE, TEMP_RECORD_CHANGES, 
		PARAM_REQUESTER_USERNAME, PARAM_REQUESTER_PASSWORD, 
		PARAM_REQUESTER_PROXY_ID, PARAM_REQUESTER_PROXY_PASSWORD,
		PARAM_REQUESTER_DEVICE_PUBLIC_KEY, PARAM_REQUESTER_DEVICE_PRIVATE_KEY,
		PARAM_REQUESTER_IP, PARAM_UNIQUE_SESSION_ID,
		TEMP_SYNC_SERVER_ID, PARAM_SUPPRESS_RETURN
	);

END ;;
DELIMITER ;
/*!50003 SET sql_mode              = @saved_sql_mode */ ;
/*!50003 SET character_set_client  = @saved_cs_client */ ;
/*!50003 SET character_set_results = @saved_cs_results */ ;
/*!50003 SET collation_connection  = @saved_col_connection */ ;
/*!50003 DROP PROCEDURE IF EXISTS `CATEGORY_ADDRESS_COUNTRY_GET` */;
/*!50003 SET @saved_cs_client      = @@character_set_client */ ;
/*!50003 SET @saved_cs_results     = @@character_set_results */ ;
/*!50003 SET @saved_col_connection = @@collation_connection */ ;
/*!50003 SET character_set_client  = latin1 */ ;
/*!50003 SET character_set_results = latin1 */ ;
/*!50003 SET collation_connection  = latin1_swedish_ci */ ;
/*!50003 SET @saved_sql_mode       = @@sql_mode */ ;
/*!50003 SET sql_mode              = '' */ ;
DELIMITER ;;
CREATE DEFINER=`root`@`localhost` PROCEDURE `CATEGORY_ADDRESS_COUNTRY_GET`(
	IN `PARAM_CAT_COUNTRY_ID` BIGINT,	
	IN `PARAM_CAT_COUNTRY_GLOBAL_ID` VARCHAR(400),	
	IN `PARAM_CAT_COUNTRY_CODE` VARCHAR(50),	
	IN `PARAM_CAT_COUNTRY_DESCRIPTION` VARCHAR(500),	
	IN `PARAM_CAT_COUNTRY_STATUS` TINYINT,	
	IN `PARAM_CAT_COUNTRY_SYSTEM_GENERATED` TINYINT,	
		
	IN `PARAM_ORDER_FIELD` VARCHAR(500),
	IN `PARAM_ORDER_TYPE` VARCHAR(500),
	IN `PARAM_SKIP` BIGINT,
	IN `PARAM_LIMIT` BIGINT,

	IN `PARAM_REQUESTER_USERNAME` VARCHAR(500),
	IN `PARAM_REQUESTER_PASSWORD` VARCHAR(500),
	IN `PARAM_REQUESTER_PROXY_ID` BIGINT,
	IN `PARAM_REQUESTER_PROXY_PASSWORD` VARCHAR(1000),
	IN `PARAM_REQUESTER_DEVICE_PUBLIC_KEY` VARCHAR(1000),
	IN `PARAM_REQUESTER_DEVICE_PRIVATE_KEY` VARCHAR(1000),
	
	IN `PARAM_REQUESTER_IP` VARCHAR(1000),
	IN `PARAM_UNIQUE_SESSION_ID` VARCHAR(1000),
	IN `PARAM_SUPPRESS_RETURN` BIT
)
SP_GET:
BEGIN

	-- Status
	-- =========================================================================================
	DECLARE STATUS_INACTIVE TINYINT DEFAULT 1;
	DECLARE STATUS_ACTIVE TINYINT DEFAULT 2;
	DECLARE STATUS_CLOSED TINYINT DEFAULT 3;
	DECLARE STATUS_COMPLETED TINYINT DEFAULT 4;
	
	-- Audit Handler
	-- =========================================================================================
	DECLARE TEMP_RECORD_EXISTS BIT DEFAULT 0;
	DECLARE TEMP_MODULE_KEYWORD VARCHAR(500) DEFAULT 'category_address_country';
	DECLARE TEMP_SP_OBJECTIVE VARCHAR(500) DEFAULT 'Retrieve Address: Country record';
	DECLARE TEMP_ERR_MESSAGE VARCHAR(500) DEFAULT '';
	DECLARE ERR BIGINT DEFAULT 0;
	DECLARE TEMP_RECORD_CHANGES VARCHAR(16000) DEFAULT '';
	DECLARE TEMP_RECORD_BINDED BIT DEFAULT 0;
	
	DECLARE TEMP_RECORD_BINDED_ID BIGINT DEFAULT 0;
	DECLARE TEMP_RECORD_BINDED_SERVER_ID BIGINT DEFAULT 0;
	
	-- Authentication
	-- =========================================================================================
	DECLARE TEMP_ACCESS_RIGHTS_DENIED BIT DEFAULT 0;
	DECLARE TEMP_AUTHENTICATED_ACCOUNT_ID BIGINT DEFAULT `ACCOUNT_MEMBER@ACC_ACCOUNT_ID_FROM_LOGIN`(PARAM_REQUESTER_USERNAME, PARAM_REQUESTER_PASSWORD);
	DECLARE TEMP_AUTHENTICATED_ACCOUNT_LEVEL BIGINT DEFAULT 0;
	DECLARE TEMP_AUTHENTICATED_ACCOUNT_GROUP BIGINT DEFAULT 0;
	
	-- Local Parameters
	-- =========================================================================================
	DECLARE TEMP_NOW DATETIME(6) DEFAULT `SYSTEM_VAR@NOW`('', 1);
	DECLARE TEMP_RECORD_COUNT BIGINT DEFAULT 0;
	
	
	-- Check NULLs
	-- =========================================================================================
	DECLARE IS_NULL_CAT_COUNTRY_ID BIT DEFAULT `SYSTEM_VAR@IS_NULL@BIGINT`(PARAM_CAT_COUNTRY_ID, 1, 1);
	DECLARE IS_NULL_CAT_COUNTRY_GLOBAL_ID BIT DEFAULT `SYSTEM_VAR@IS_NULL@NVARCHAR`(PARAM_CAT_COUNTRY_GLOBAL_ID, 1);
	DECLARE IS_NULL_CAT_COUNTRY_CODE BIT DEFAULT `SYSTEM_VAR@IS_NULL@NVARCHAR`(PARAM_CAT_COUNTRY_CODE, 0);
	DECLARE IS_NULL_CAT_COUNTRY_DESCRIPTION BIT DEFAULT `SYSTEM_VAR@IS_NULL@NVARCHAR`(PARAM_CAT_COUNTRY_DESCRIPTION, 1);
	DECLARE IS_NULL_CAT_COUNTRY_STATUS BIT DEFAULT `SYSTEM_VAR@IS_NULL@TINYINT`(PARAM_CAT_COUNTRY_STATUS, 1, 1);
	DECLARE IS_NULL_CAT_COUNTRY_SYSTEM_GENERATED BIT DEFAULT `SYSTEM_VAR@IS_NULL@TINYINT`(PARAM_CAT_COUNTRY_SYSTEM_GENERATED, 1, 1);
	
	-- Error Handler
	-- =========================================================================================
	DECLARE EXIT HANDLER FOR SQLEXCEPTION
	BEGIN
		RESIGNAL;
	END;
	
	-- Ignore Time from DateTime (Set Time 00:00:00.000000 and 23:59:59.999999)
	-- =========================================================================================
		
		
	-- Access Rights [Device]
	-- =========================================================================================
	IF `ACCOUNT_DEVICE@HAS_PERMISSION`(PARAM_REQUESTER_DEVICE_PUBLIC_KEY, PARAM_REQUESTER_DEVICE_PRIVATE_KEY) = 0 THEN
		SET TEMP_ERR_MESSAGE = 'Your device is not authorized yet to access this server.';
		SET ERR = `RAISERROR`(TEMP_ERR_MESSAGE);		
	END IF;
		
		
	-- Access Rights [Account]
	-- =========================================================================================
		
	
	
	
	-- COUNT RECORD
	-- =========================================================================================
	
	-- SELECT COLUMNS
	-- ####################################################
	SELECT
		COUNT(DISTINCT `category_address_country`.`CAT_COUNTRY_ID`)
	INTO
		TEMP_RECORD_COUNT

	FROM `category_address_country`
	
		-- Add Inner Joins (Per Foreign-key)
		
		-- Add Optional Left Joins (Per Optional Foreign-key)
		
	-- CONDITIONS
	-- ####################################################
	WHERE
		(
			IS_NULL_CAT_COUNTRY_ID = 1 OR
			`category_address_country`.`CAT_COUNTRY_ID` = PARAM_CAT_COUNTRY_ID			
		) AND
		(
			IS_NULL_CAT_COUNTRY_GLOBAL_ID = 1 OR
			`category_address_country`.`CAT_COUNTRY_GLOBAL_ID` LIKE CONCAT_WS('%', '', PARAM_CAT_COUNTRY_GLOBAL_ID, '')			
		) AND 		
		(
			IS_NULL_CAT_COUNTRY_CODE = 1 OR
			`category_address_country`.`CAT_COUNTRY_CODE` LIKE CONCAT_WS('%', '', PARAM_CAT_COUNTRY_CODE, '')			
		) AND 		
		(
			IS_NULL_CAT_COUNTRY_DESCRIPTION = 1 OR
			`category_address_country`.`CAT_COUNTRY_DESCRIPTION` LIKE CONCAT_WS('%', '', PARAM_CAT_COUNTRY_DESCRIPTION, '')			
		) AND 		
		(
			IS_NULL_CAT_COUNTRY_STATUS = 1 OR
			`category_address_country`.`CAT_COUNTRY_STATUS` = PARAM_CAT_COUNTRY_STATUS			
		) AND
		(
			IS_NULL_CAT_COUNTRY_SYSTEM_GENERATED = 1 OR
			`category_address_country`.`CAT_COUNTRY_SYSTEM_GENERATED` = PARAM_CAT_COUNTRY_SYSTEM_GENERATED			
		) 
;	

		
		
	-- SELECT RECORDS
	-- =========================================================================================
	
	-- FETCH COLUMNS
	-- ####################################################
	SELECT
		-- CATEGORY_ADDRESS_COUNTRY DETAILS
		`category_address_country`.`CAT_COUNTRY_ID`, 
		`category_address_country`.`CAT_COUNTRY_GLOBAL_ID`, 
		`category_address_country`.`CAT_COUNTRY_CODE`, 
		`category_address_country`.`CAT_COUNTRY_DESCRIPTION`, 
		`category_address_country`.`CAT_COUNTRY_STATUS`, 
		`category_address_country`.`CAT_COUNTRY_SYSTEM_GENERATED`
		
		-- Inner join fields
		
		-- Left join fields
		
		, TEMP_RECORD_COUNT AS RECORD_COUNT

	FROM `category_address_country`
	
		-- Add Inner Joins (Per Foreign-key)
		
		-- Add Optional Left Joins (Per Optional Foreign-key)
		
	-- CONDITIONS
	-- ####################################################
	WHERE
		(
			IS_NULL_CAT_COUNTRY_ID = 1 OR
			`category_address_country`.`CAT_COUNTRY_ID` = PARAM_CAT_COUNTRY_ID			
		) AND
		(
			IS_NULL_CAT_COUNTRY_GLOBAL_ID = 1 OR
			`category_address_country`.`CAT_COUNTRY_GLOBAL_ID` LIKE CONCAT_WS('%', '', PARAM_CAT_COUNTRY_GLOBAL_ID, '')			
		) AND 		
		(
			IS_NULL_CAT_COUNTRY_CODE = 1 OR
			`category_address_country`.`CAT_COUNTRY_CODE` LIKE CONCAT_WS('%', '', PARAM_CAT_COUNTRY_CODE, '')			
		) AND 		
		(
			IS_NULL_CAT_COUNTRY_DESCRIPTION = 1 OR
			`category_address_country`.`CAT_COUNTRY_DESCRIPTION` LIKE CONCAT_WS('%', '', PARAM_CAT_COUNTRY_DESCRIPTION, '')			
		) AND 		
		(
			IS_NULL_CAT_COUNTRY_STATUS = 1 OR
			`category_address_country`.`CAT_COUNTRY_STATUS` = PARAM_CAT_COUNTRY_STATUS			
		) AND
		(
			IS_NULL_CAT_COUNTRY_SYSTEM_GENERATED = 1 OR
			`category_address_country`.`CAT_COUNTRY_SYSTEM_GENERATED` = PARAM_CAT_COUNTRY_SYSTEM_GENERATED			
		) 

	-- ORDER BY
	-- ####################################################
	ORDER BY
		-- CATEGORY_ADDRESS_COUNTRY DETAILS
		CASE WHEN PARAM_ORDER_FIELD = 'CAT_COUNTRY_ID' AND PARAM_ORDER_TYPE = 'ASC' THEN `category_address_country`.`CAT_COUNTRY_ID` END ASC, 
		CASE WHEN PARAM_ORDER_FIELD = 'CAT_COUNTRY_ID' AND PARAM_ORDER_TYPE = 'DESC' THEN `category_address_country`.`CAT_COUNTRY_ID` END DESC,	
		CASE WHEN PARAM_ORDER_FIELD = 'CAT_COUNTRY_GLOBAL_ID' AND PARAM_ORDER_TYPE = 'ASC' THEN `category_address_country`.`CAT_COUNTRY_GLOBAL_ID` END ASC, 
		CASE WHEN PARAM_ORDER_FIELD = 'CAT_COUNTRY_GLOBAL_ID' AND PARAM_ORDER_TYPE = 'DESC' THEN `category_address_country`.`CAT_COUNTRY_GLOBAL_ID` END DESC,	
		CASE WHEN PARAM_ORDER_FIELD = 'CAT_COUNTRY_CODE' AND PARAM_ORDER_TYPE = 'ASC' THEN `category_address_country`.`CAT_COUNTRY_CODE` END ASC, 
		CASE WHEN PARAM_ORDER_FIELD = 'CAT_COUNTRY_CODE' AND PARAM_ORDER_TYPE = 'DESC' THEN `category_address_country`.`CAT_COUNTRY_CODE` END DESC,	
		CASE WHEN PARAM_ORDER_FIELD = 'CAT_COUNTRY_DESCRIPTION' AND PARAM_ORDER_TYPE = 'ASC' THEN `category_address_country`.`CAT_COUNTRY_DESCRIPTION` END ASC, 
		CASE WHEN PARAM_ORDER_FIELD = 'CAT_COUNTRY_DESCRIPTION' AND PARAM_ORDER_TYPE = 'DESC' THEN `category_address_country`.`CAT_COUNTRY_DESCRIPTION` END DESC,	
		CASE WHEN PARAM_ORDER_FIELD = 'CAT_COUNTRY_STATUS' AND PARAM_ORDER_TYPE = 'ASC' THEN `category_address_country`.`CAT_COUNTRY_STATUS` END ASC, 
		CASE WHEN PARAM_ORDER_FIELD = 'CAT_COUNTRY_STATUS' AND PARAM_ORDER_TYPE = 'DESC' THEN `category_address_country`.`CAT_COUNTRY_STATUS` END DESC,	
		CASE WHEN PARAM_ORDER_FIELD = 'CAT_COUNTRY_SYSTEM_GENERATED' AND PARAM_ORDER_TYPE = 'ASC' THEN `category_address_country`.`CAT_COUNTRY_SYSTEM_GENERATED` END ASC, 
		CASE WHEN PARAM_ORDER_FIELD = 'CAT_COUNTRY_SYSTEM_GENERATED' AND PARAM_ORDER_TYPE = 'DESC' THEN `category_address_country`.`CAT_COUNTRY_SYSTEM_GENERATED` END DESC,	

		-- Inner joins
		
		-- EXTRA
		CASE WHEN PARAM_ORDER_FIELD <> 'CAT_COUNTRY_DESCRIPTION' THEN `category_address_country`.`CAT_COUNTRY_DESCRIPTION` END ASC
		
	-- LIMIT & OFFSET
	-- ####################################################		
	LIMIT PARAM_SKIP, PARAM_LIMIT;
	
	
	
	-- EXIT PROCEDURE
	-- =========================================================================================
	LEAVE SP_GET;
			
END ;;
DELIMITER ;
/*!50003 SET sql_mode              = @saved_sql_mode */ ;
/*!50003 SET character_set_client  = @saved_cs_client */ ;
/*!50003 SET character_set_results = @saved_cs_results */ ;
/*!50003 SET collation_connection  = @saved_col_connection */ ;
/*!50003 DROP PROCEDURE IF EXISTS `CATEGORY_ADDRESS_COUNTRY_SAVE` */;
/*!50003 SET @saved_cs_client      = @@character_set_client */ ;
/*!50003 SET @saved_cs_results     = @@character_set_results */ ;
/*!50003 SET @saved_col_connection = @@collation_connection */ ;
/*!50003 SET character_set_client  = latin1 */ ;
/*!50003 SET character_set_results = latin1 */ ;
/*!50003 SET collation_connection  = latin1_swedish_ci */ ;
/*!50003 SET @saved_sql_mode       = @@sql_mode */ ;
/*!50003 SET sql_mode              = '' */ ;
DELIMITER ;;
CREATE DEFINER=`root`@`localhost` PROCEDURE `CATEGORY_ADDRESS_COUNTRY_SAVE`(
	IN `PARAM_CAT_COUNTRY_ID` BIGINT,
	IN `PARAM_CAT_COUNTRY_CODE` VARCHAR(50),
	IN `PARAM_CAT_COUNTRY_DESCRIPTION` VARCHAR(500),
	IN `PARAM_CAT_COUNTRY_STATUS` TINYINT,

	IN `PARAM_REQUESTER_USERNAME` VARCHAR(500),
	IN `PARAM_REQUESTER_PASSWORD` VARCHAR(500),
	IN `PARAM_REQUESTER_PROXY_ID` BIGINT,
	IN `PARAM_REQUESTER_PROXY_PASSWORD` VARCHAR(1000),
	IN `PARAM_REQUESTER_DEVICE_PUBLIC_KEY` VARCHAR(1000),
	IN `PARAM_REQUESTER_DEVICE_PRIVATE_KEY` VARCHAR(1000),
	
	IN `PARAM_REQUESTER_IP` VARCHAR(1000),
	IN `PARAM_UNIQUE_SESSION_ID` VARCHAR(1000),
	IN `PARAM_SUPPRESS_RETURN` BIT,
	
	IN `PARAM_SYNC_SERVER_DESCRIPTION` VARCHAR(500), 
	IN `PARAM_SYNC_SERVER_UNIQUE_KEY` VARCHAR(500)
)
SP_SAVE:
BEGIN


	-- 1) DECLARE LOCAL PARAMETERS
	-- _______________________________________________________________________
	
	-- Status
	-- ...........................................
	DECLARE STATUS_INACTIVE TINYINT DEFAULT 1;
	DECLARE STATUS_ACTIVE TINYINT DEFAULT 2;
	DECLARE STATUS_CLOSED TINYINT DEFAULT 3;
	DECLARE STATUS_COMPLETED TINYINT DEFAULT 4;

	-- Audit Handler
	-- ...........................................
	DECLARE TEMP_RECORD_EXISTS BIT DEFAULT 0;
	DECLARE TEMP_MODULE_KEYWORD VARCHAR(500) DEFAULT 'category_address_country';
	DECLARE TEMP_SP_OBJECTIVE VARCHAR(500) DEFAULT 'add/edit Address: Country record';
	DECLARE TEMP_ERR_MESSAGE VARCHAR(500) DEFAULT '';
	DECLARE ERR BIGINT DEFAULT 0;
	DECLARE TEMP_RECORD_CHANGES VARCHAR(16000) DEFAULT '';
	DECLARE TEMP_RECORD_BINDED BIT DEFAULT 0;

	-- Authentication
	-- ...........................................
	DECLARE TEMP_ACCESS_RIGHTS_DENIED BIT DEFAULT 0;
	DECLARE TEMP_ACCESS_RIGHTS_HAS_OVERRIDE BIT DEFAULT 0;
	DECLARE TEMP_SYNC_SERVER_ID BIGINT DEFAULT 0;
	DECLARE TEMP_SYNC_IS_SERVER_REQUEST BIT DEFAULT 0;
	DECLARE TEMP_AUTHENTICATED_ACCOUNT_ID BIGINT DEFAULT `ACCOUNT_MEMBER@ACC_ACCOUNT_ID_FROM_LOGIN`(PARAM_REQUESTER_USERNAME, PARAM_REQUESTER_PASSWORD);
	DECLARE TEMP_AUTHENTICATED_ACCOUNT_LEVEL BIGINT DEFAULT 0;
	DECLARE TEMP_AUTHENTICATED_ACCOUNT_GROUP BIGINT DEFAULT 0;
	
	-- Local Parameters
	-- ...........................................
	DECLARE TEMP_NOW DATETIME(6) DEFAULT `SYSTEM_VAR@NOW`('', 1);
	DECLARE TEMP_RECORD_COUNT BIGINT DEFAULT 0;

	-- AutoGen Parameters
	-- ...........................................
	DECLARE PARAM_CAT_COUNTRY_GLOBAL_ID VARCHAR(400) DEFAULT ''; 
	DECLARE PARAM_CAT_COUNTRY_SYSTEM_GENERATED TINYINT DEFAULT 0; 
	
	-- Local value holder
	-- ...........................................
	DECLARE TEMP_CAT_COUNTRY_GLOBAL_ID VARCHAR(400) DEFAULT ''; 
	DECLARE TEMP_CAT_COUNTRY_CODE VARCHAR(50) DEFAULT ''; 
	DECLARE TEMP_CAT_COUNTRY_DESCRIPTION VARCHAR(500) DEFAULT ''; 
	DECLARE TEMP_CAT_COUNTRY_STATUS TINYINT DEFAULT 0; 
	DECLARE TEMP_CAT_COUNTRY_SYSTEM_GENERATED TINYINT DEFAULT 0; 
	


	-- 2) Try Catch / Throw
	-- _______________________________________________________________________
	DECLARE EXIT HANDLER FOR SQLEXCEPTION
	BEGIN
		RESIGNAL;
	END;



	-- 3) Prepare SYNC
	-- _______________________________________________________________________

	-- IS RECORD EXISTS		
	-- ####################################################	
	SET TEMP_RECORD_EXISTS = `CATEGORY_ADDRESS_COUNTRY@CAT_COUNTRY_ID_EXISTS`(PARAM_CAT_COUNTRY_ID, 0);

		
		
	-- 4) PREPARE AUTOGEN DATA (IF EXISTS)
	-- _______________________________________________________________________
	IF TEMP_SYNC_IS_SERVER_REQUEST = 0 THEN
		-- Just to keep at least one line within condition
		SET TEMP_SYNC_IS_SERVER_REQUEST = 0;
		
		-- Actual Functionalities here
		-- USE DEFAULT VALUE (String)
		-- USE DEFAULT VALUE (String)
		SET PARAM_CAT_COUNTRY_GLOBAL_ID = `SYSTEM_VAR@RANDOM_UNIQUE_ALPHA32`;
		-- USE DEFAULT VALUE (String)
		SET PARAM_CAT_COUNTRY_SYSTEM_GENERATED = 1;
	-- USE TIMESTAMP
	END IF;



	-- 5) IF ALREADY EXIST, FILL MISSING DATA
	-- _______________________________________________________________________
	IF TEMP_RECORD_EXISTS = 1 THEN
		SELECT
			`category_address_country`.`CAT_COUNTRY_GLOBAL_ID`, 	
			`category_address_country`.`CAT_COUNTRY_CODE`, 	
			`category_address_country`.`CAT_COUNTRY_DESCRIPTION`, 	
			`category_address_country`.`CAT_COUNTRY_STATUS`, 	
			`category_address_country`.`CAT_COUNTRY_SYSTEM_GENERATED`	
		INTO
			TEMP_CAT_COUNTRY_GLOBAL_ID, 	
			TEMP_CAT_COUNTRY_CODE, 	
			TEMP_CAT_COUNTRY_DESCRIPTION, 	
			TEMP_CAT_COUNTRY_STATUS, 	
			TEMP_CAT_COUNTRY_SYSTEM_GENERATED	

		FROM `category_address_country`
		WHERE
			`category_address_country`.`CAT_COUNTRY_ID` = PARAM_CAT_COUNTRY_ID
		LIMIT 1;

		-- Replace NULLs with the existing data.
		SET PARAM_CAT_COUNTRY_CODE = `SYSTEM_VAR@REPLACE_NULL@NVARCHAR`(PARAM_CAT_COUNTRY_CODE, TEMP_CAT_COUNTRY_CODE, 0);
		SET PARAM_CAT_COUNTRY_DESCRIPTION = `SYSTEM_VAR@REPLACE_NULL@NVARCHAR`(PARAM_CAT_COUNTRY_DESCRIPTION, TEMP_CAT_COUNTRY_DESCRIPTION, 1);
		SET PARAM_CAT_COUNTRY_STATUS = `SYSTEM_VAR@REPLACE_NULL@TINYINT`(PARAM_CAT_COUNTRY_STATUS, TEMP_CAT_COUNTRY_STATUS, 1, 1);
		
		-- AUTO GEN (NON-UPDATABLES)		
		SET PARAM_CAT_COUNTRY_GLOBAL_ID = TEMP_CAT_COUNTRY_GLOBAL_ID;
		SET PARAM_CAT_COUNTRY_SYSTEM_GENERATED = TEMP_CAT_COUNTRY_SYSTEM_GENERATED;
		
		-- AUTO GEN (UPDATABLE WITH STATUS CHANGE)

		-- AUTO GEN (UPDATABLE WITH STATUS [ACTIVE/INACTIVE] CHANGE)
		
	ELSE
		SET PARAM_CAT_COUNTRY_CODE = `SYSTEM_VAR@REPLACE_NULL@NVARCHAR`(PARAM_CAT_COUNTRY_CODE, '', 0);
		SET PARAM_CAT_COUNTRY_DESCRIPTION = `SYSTEM_VAR@REPLACE_NULL@NVARCHAR`(PARAM_CAT_COUNTRY_DESCRIPTION, '', 1);
		SET PARAM_CAT_COUNTRY_STATUS = `SYSTEM_VAR@REPLACE_NULL@TINYINT`(PARAM_CAT_COUNTRY_STATUS, 0, 1, 1);
		
	END IF;

	

	-- 6) PREPARE AUDIT TRAIL
	-- _______________________________________________________________________
	IF BINARY TEMP_CAT_COUNTRY_GLOBAL_ID <> PARAM_CAT_COUNTRY_GLOBAL_ID THEN
		SET TEMP_RECORD_CHANGES = 
		`SYSTEM_VAR@CONCAT_ADD`(' | ', TEMP_RECORD_CHANGES, CONCAT_WS(' ', 'Sync ID: "', TEMP_CAT_COUNTRY_GLOBAL_ID, '" > "', PARAM_CAT_COUNTRY_GLOBAL_ID, '"'));
	END IF;
	IF BINARY TEMP_CAT_COUNTRY_CODE <> PARAM_CAT_COUNTRY_CODE THEN
		SET TEMP_RECORD_CHANGES = 
		`SYSTEM_VAR@CONCAT_ADD`(' | ', TEMP_RECORD_CHANGES, CONCAT_WS(' ', 'Unique Code: "', TEMP_CAT_COUNTRY_CODE, '" > "', PARAM_CAT_COUNTRY_CODE, '"'));
	END IF;
	IF BINARY TEMP_CAT_COUNTRY_DESCRIPTION <> PARAM_CAT_COUNTRY_DESCRIPTION THEN
		SET TEMP_RECORD_CHANGES = 
		`SYSTEM_VAR@CONCAT_ADD`(' | ', TEMP_RECORD_CHANGES, CONCAT_WS(' ', 'Description: "', TEMP_CAT_COUNTRY_DESCRIPTION, '" > "', PARAM_CAT_COUNTRY_DESCRIPTION, '"'));
	END IF;
	IF TEMP_CAT_COUNTRY_STATUS <> PARAM_CAT_COUNTRY_STATUS THEN
		SET TEMP_RECORD_CHANGES = 
		`SYSTEM_VAR@CONCAT_ADD`(' | ', TEMP_RECORD_CHANGES, CONCAT_WS(' ', 'Status: "', TEMP_CAT_COUNTRY_STATUS, '" > "', PARAM_CAT_COUNTRY_STATUS, '"'));
	END IF;	
	IF TEMP_CAT_COUNTRY_SYSTEM_GENERATED <> PARAM_CAT_COUNTRY_SYSTEM_GENERATED THEN
		SET TEMP_RECORD_CHANGES = 
		`SYSTEM_VAR@CONCAT_ADD`(' | ', TEMP_RECORD_CHANGES, CONCAT_WS(' ', 'System Generated: "', TEMP_CAT_COUNTRY_SYSTEM_GENERATED, '" > "', PARAM_CAT_COUNTRY_SYSTEM_GENERATED, '"'));
	END IF;	
		
	-- No Changes in data, reject request
	-- ####################################################
	IF CHARACTER_LENGTH(TEMP_RECORD_CHANGES) = 0 THEN
		IF PARAM_SUPPRESS_RETURN = 0 THEN
			SELECT PARAM_CAT_COUNTRY_ID AS INSERTED_ID;
		END IF;
		LEAVE SP_SAVE;
	END IF;



	-- 7) VALIDATE
	-- _______________________________________________________________________

	-- Access Rights [Device]
	-- ####################################################
	IF `ACCOUNT_DEVICE@HAS_PERMISSION`(PARAM_REQUESTER_DEVICE_PUBLIC_KEY, PARAM_REQUESTER_DEVICE_PRIVATE_KEY) = 0 THEN
		SET TEMP_ERR_MESSAGE = 'Your device is not authorized yet to access this server.';
		SET ERR = `RAISERROR`(TEMP_ERR_MESSAGE);		
	END IF;
		
		
	-- Access Rights [Account]
	-- ####################################################
	
	IF 
		-- [ADD] Access Rights
		(
			TEMP_RECORD_EXISTS = 0 AND
			`ACCOUNT_ACCESS_RIGHTS@HAS_PERMISSION`(PARAM_REQUESTER_USERNAME, PARAM_REQUESTER_PASSWORD, 0, TEMP_MODULE_KEYWORD, 2) = 0 
		) OR
		
		-- [EDIT] Access Rights
		(
			TEMP_RECORD_EXISTS = 1 AND
			`ACCOUNT_ACCESS_RIGHTS@HAS_PERMISSION`(PARAM_REQUESTER_USERNAME, PARAM_REQUESTER_PASSWORD, 0, TEMP_MODULE_KEYWORD, 3) = 0 
		)
	THEN
		SET TEMP_ACCESS_RIGHTS_DENIED = 1;
		CALL `ACCOUNT_ACCESS_RIGHTS_DENY`
		(
			0, TEMP_MODULE_KEYWORD, PARAM_CAT_COUNTRY_ID, 0, TEMP_SP_OBJECTIVE, TEMP_RECORD_CHANGES, 
			PARAM_REQUESTER_USERNAME, PARAM_REQUESTER_PASSWORD, 
			PARAM_REQUESTER_PROXY_ID, PARAM_REQUESTER_PROXY_PASSWORD,
			PARAM_REQUESTER_DEVICE_PUBLIC_KEY, PARAM_REQUESTER_DEVICE_PRIVATE_KEY,
			PARAM_REQUESTER_IP, PARAM_UNIQUE_SESSION_ID,
			TEMP_SYNC_SERVER_ID, PARAM_SUPPRESS_RETURN
		);
	END IF;
	SET TEMP_ACCESS_RIGHTS_HAS_OVERRIDE = `ACCOUNT_ACCESS_RIGHTS@HAS_PERMISSION`(PARAM_REQUESTER_USERNAME, PARAM_REQUESTER_PASSWORD, 0, TEMP_MODULE_KEYWORD, 4);
	

	-- Validation
	-- ####################################################
	IF TEMP_SYNC_IS_SERVER_REQUEST = 0 THEN
	
		-- SYSTEM GENERATED = TRUE
		-- ...........................................
		IF TEMP_CAT_COUNTRY_SYSTEM_GENERATED = STATUS_ACTIVE THEN
		CALL `VALIDATION_SYSTEM_GENERATED`
		(
			PARAM_CAT_COUNTRY_ID,
			TEMP_CAT_COUNTRY_DESCRIPTION, ''
		);
		END IF;

		-- FOREIGN KEY EXISTS
		-- ...........................................
		
		-- FOREIGN (OPTIONAL)KEY EXISTS [Validates if not null]
		-- ...........................................
		
		-- IS_ALLOW_NULL = FALSE
		-- ...........................................
		IF PARAM_CAT_COUNTRY_CODE IS NULL THEN
			CALL `VALIDATION_MISSING_FIELD`('`CAT_COUNTRY_CODE`', '`NULL`');
		END IF;
				
		-- IS_ALLOW_ZERO = FALSE
		-- ...........................................
		IF PARAM_CAT_COUNTRY_STATUS = 0 THEN
			CALL `VALIDATION_MISSING_FIELD`('`CAT_COUNTRY_STATUS`', '`NULL`');
		END IF;		
		IF PARAM_CAT_COUNTRY_SYSTEM_GENERATED = 0 THEN
			CALL `VALIDATION_MISSING_FIELD`('`CAT_COUNTRY_SYSTEM_GENERATED`', '`NULL`');
		END IF;		
		
		-- IS_ALLOW_NEGATIVE = FALSE
		-- ...........................................
		IF PARAM_CAT_COUNTRY_STATUS < 0 THEN
			CALL `VALIDATION_NEGATIVE`('`CAT_COUNTRY_STATUS`', PARAM_CAT_COUNTRY_STATUS);
		END IF;		
		IF PARAM_CAT_COUNTRY_SYSTEM_GENERATED < 0 THEN
			CALL `VALIDATION_NEGATIVE`('`CAT_COUNTRY_SYSTEM_GENERATED`', PARAM_CAT_COUNTRY_SYSTEM_GENERATED);
		END IF;		
		
		-- IS_ALLOW_EMPTY_STRING = FALSE
		-- ...........................................
		IF `SYSTEM_VAR@IS_NULL@NVARCHAR`(PARAM_CAT_COUNTRY_GLOBAL_ID, 1) = 1 THEN
			CALL `VALIDATION_MISSING_FIELD`('`CAT_COUNTRY_GLOBAL_ID`', '`NULL`');
		END IF;
		IF `SYSTEM_VAR@IS_NULL@NVARCHAR`(PARAM_CAT_COUNTRY_DESCRIPTION, 1) = 1 THEN
			CALL `VALIDATION_MISSING_FIELD`('`CAT_COUNTRY_DESCRIPTION`', '`NULL`');
		END IF;
		
		-- IS_STATUS
		-- ...........................................
		IF `SYSTEM_STATUS@STATUS_ID_EXISTS`(PARAM_CAT_COUNTRY_STATUS, 0) = 0 THEN
			SET TEMP_ERR_MESSAGE = CONCAT_WS(' ', 'Given STATUS[Status] does not exists or is inactive. ID: ', PARAM_CAT_COUNTRY_STATUS);
			SET ERR = `RAISERROR`(TEMP_ERR_MESSAGE);
		END IF;
		
		-- IS STATUS Active / Inactive
		-- ...........................................
		
		-- Minimum / Maximum Value
		-- ...........................................
		
		-- IS_UNIQUE = TRUE
		-- ...........................................
		IF
		(
			SELECT COUNT(`category_address_country`.`CAT_COUNTRY_ID`)
			FROM `category_address_country`
			WHERE		
				`category_address_country`.`CAT_COUNTRY_GLOBAL_ID` = PARAM_CAT_COUNTRY_GLOBAL_ID AND		
				`category_address_country`.`CAT_COUNTRY_ID` <> PARAM_CAT_COUNTRY_ID
		) >= 1
		THEN
			CALL `VALIDATION_REDUNDANT_ENTRY`(PARAM_CAT_COUNTRY_DESCRIPTION);
		END IF;
		IF
		(
			SELECT COUNT(`category_address_country`.`CAT_COUNTRY_ID`)
			FROM `category_address_country`
			WHERE		
				`category_address_country`.`CAT_COUNTRY_DESCRIPTION` = PARAM_CAT_COUNTRY_DESCRIPTION AND		
				`category_address_country`.`CAT_COUNTRY_ID` <> PARAM_CAT_COUNTRY_ID
		) >= 1
		THEN
			CALL `VALIDATION_REDUNDANT_ENTRY`(PARAM_CAT_COUNTRY_DESCRIPTION);
		END IF;
		
		-- RECORD IDENTIFIER
		-- ...........................................
		
		
		-- ON_UPDATE VALIDATION 
		-- ...........................................
		IF TEMP_RECORD_EXISTS = 1 THEN	
		
			-- Just to keep at least one line within condition
			SET TEMP_RECORD_EXISTS = 1;
			
		END IF;
		
	END IF;



	-- 8) INSERT / UPDATE
	-- _______________________________________________________________________

	-- INSERT NEW DATA
	-- ####################################################
	IF TEMP_RECORD_EXISTS = 0 THEN

		INSERT INTO
		`category_address_country`
		(
			`category_address_country`.`CAT_COUNTRY_GLOBAL_ID`, 
			`category_address_country`.`CAT_COUNTRY_CODE`, 
			`category_address_country`.`CAT_COUNTRY_DESCRIPTION`, 
			`category_address_country`.`CAT_COUNTRY_STATUS`, 
			`category_address_country`.`CAT_COUNTRY_SYSTEM_GENERATED`
		)
		VALUES
		(
			PARAM_CAT_COUNTRY_GLOBAL_ID, 
			PARAM_CAT_COUNTRY_CODE, 
			PARAM_CAT_COUNTRY_DESCRIPTION, 
			PARAM_CAT_COUNTRY_STATUS, 
			PARAM_CAT_COUNTRY_SYSTEM_GENERATED
		);	
		
		-- Update Audit trail with new ID	
		SET PARAM_CAT_COUNTRY_ID = LAST_INSERT_ID();



	-- UPDATING EXISTING RECORD
	-- ####################################################
	ELSE
		UPDATE `category_address_country`
		SET
			`category_address_country`.`CAT_COUNTRY_GLOBAL_ID` = PARAM_CAT_COUNTRY_GLOBAL_ID, 
			`category_address_country`.`CAT_COUNTRY_CODE` = PARAM_CAT_COUNTRY_CODE, 
			`category_address_country`.`CAT_COUNTRY_DESCRIPTION` = PARAM_CAT_COUNTRY_DESCRIPTION, 
			`category_address_country`.`CAT_COUNTRY_STATUS` = PARAM_CAT_COUNTRY_STATUS, 
			`category_address_country`.`CAT_COUNTRY_SYSTEM_GENERATED` = PARAM_CAT_COUNTRY_SYSTEM_GENERATED
		WHERE
			`category_address_country`.`CAT_COUNTRY_ID` = PARAM_CAT_COUNTRY_ID;

	END IF;

	
	-- 9) AUDIT TRAIL
	-- _______________________________________________________________________
	CALL `ACCOUNT_AUDIT_TRAIL_SAVE`
	(
		0, TEMP_MODULE_KEYWORD, PARAM_CAT_COUNTRY_ID, 0, 'SAVE', TEMP_SP_OBJECTIVE, TEMP_RECORD_CHANGES, 
		PARAM_REQUESTER_USERNAME, PARAM_REQUESTER_PASSWORD, 
		PARAM_REQUESTER_PROXY_ID, PARAM_REQUESTER_PROXY_PASSWORD,
		PARAM_REQUESTER_DEVICE_PUBLIC_KEY, PARAM_REQUESTER_DEVICE_PRIVATE_KEY,
		PARAM_REQUESTER_IP, PARAM_UNIQUE_SESSION_ID,
		TEMP_SYNC_SERVER_ID, PARAM_SUPPRESS_RETURN
	);
	

	-- 10) RETURN RESULT
	-- _______________________________________________________________________
	IF PARAM_SUPPRESS_RETURN = 0 THEN
		SELECT PARAM_CAT_COUNTRY_ID AS INSERTED_ID;
	END IF;
	LEAVE SP_SAVE;


END ;;
DELIMITER ;
/*!50003 SET sql_mode              = @saved_sql_mode */ ;
/*!50003 SET character_set_client  = @saved_cs_client */ ;
/*!50003 SET character_set_results = @saved_cs_results */ ;
/*!50003 SET collation_connection  = @saved_col_connection */ ;
/*!50003 DROP PROCEDURE IF EXISTS `CATEGORY_ADDRESS_MUNICIPALITY_DELETE` */;
/*!50003 SET @saved_cs_client      = @@character_set_client */ ;
/*!50003 SET @saved_cs_results     = @@character_set_results */ ;
/*!50003 SET @saved_col_connection = @@collation_connection */ ;
/*!50003 SET character_set_client  = latin1 */ ;
/*!50003 SET character_set_results = latin1 */ ;
/*!50003 SET collation_connection  = latin1_swedish_ci */ ;
/*!50003 SET @saved_sql_mode       = @@sql_mode */ ;
/*!50003 SET sql_mode              = '' */ ;
DELIMITER ;;
CREATE DEFINER=`root`@`localhost` PROCEDURE `CATEGORY_ADDRESS_MUNICIPALITY_DELETE`(
	IN `PARAM_CAT_MUNICIPALITY_ID` BIGINT,

	IN `PARAM_REQUESTER_USERNAME` VARCHAR(500),
	IN `PARAM_REQUESTER_PASSWORD` VARCHAR(500),
	IN `PARAM_REQUESTER_PROXY_ID` BIGINT,
	IN `PARAM_REQUESTER_PROXY_PASSWORD` VARCHAR(1000),
	IN `PARAM_REQUESTER_DEVICE_PUBLIC_KEY` VARCHAR(1000),
	IN `PARAM_REQUESTER_DEVICE_PRIVATE_KEY` VARCHAR(1000),
	
	IN `PARAM_REQUESTER_IP` VARCHAR(1000),
	IN `PARAM_UNIQUE_SESSION_ID` VARCHAR(1000),
	IN `PARAM_SUPPRESS_RETURN` BIT,
	
	IN `PARAM_SYNC_SERVER_DESCRIPTION` VARCHAR(500), 
	IN `PARAM_SYNC_SERVER_UNIQUE_KEY` VARCHAR(500)
)
SP_DELETE:
BEGIN

	-- 1) DECLARE LOCAL PARAMETERS
	-- _______________________________________________________________________
	
	-- Status
	-- ...........................................
	DECLARE STATUS_INACTIVE TINYINT DEFAULT 1;
	DECLARE STATUS_ACTIVE TINYINT DEFAULT 2;
	DECLARE STATUS_CLOSED TINYINT DEFAULT 3;
	DECLARE STATUS_COMPLETED TINYINT DEFAULT 4;
	
	-- Audit Handler
	-- ...........................................
	DECLARE TEMP_RECORD_EXISTS BIT DEFAULT 0;
	DECLARE TEMP_MODULE_KEYWORD VARCHAR(500) DEFAULT 'category_address_municipality';
	DECLARE TEMP_SP_OBJECTIVE VARCHAR(500) DEFAULT 'delete Address: Municipality record';
	DECLARE TEMP_ERR_MESSAGE VARCHAR(500) DEFAULT '';
	DECLARE ERR BIGINT DEFAULT 0;
	DECLARE TEMP_RECORD_CHANGES VARCHAR(16000) DEFAULT '';
	DECLARE TEMP_RECORD_BINDED BIT DEFAULT 0;
	
	DECLARE TEMP_RECORD_BINDED_ID BIGINT DEFAULT 0;
	DECLARE TEMP_RECORD_BINDED_SERVER_ID BIGINT DEFAULT 0;
	
	-- Authentication
	-- ...........................................
	DECLARE TEMP_ACCESS_RIGHTS_DENIED BIT DEFAULT 0;
	DECLARE TEMP_SYNC_SERVER_ID BIGINT DEFAULT 0;
	DECLARE TEMP_SYNC_IS_SERVER_REQUEST BIT DEFAULT 0;
	DECLARE TEMP_AUTHENTICATED_ACCOUNT_ID BIGINT DEFAULT `ACCOUNT_MEMBER@ACC_ACCOUNT_ID_FROM_LOGIN`(PARAM_REQUESTER_USERNAME, PARAM_REQUESTER_PASSWORD);
	DECLARE TEMP_AUTHENTICATED_ACCOUNT_LEVEL BIGINT DEFAULT 0;
	DECLARE TEMP_AUTHENTICATED_ACCOUNT_GROUP BIGINT DEFAULT 0;

	-- Local value holder
	-- ...........................................
		DECLARE TEMP_CAT_MUNICIPALITY_GLOBAL_ID VARCHAR(400) DEFAULT ''; 
		DECLARE TEMP_CAT_MUNICIPALITY_CAT_PROVINCE_ID BIGINT DEFAULT 0; 
		DECLARE TEMP_CAT_MUNICIPALITY_CODE VARCHAR(50) DEFAULT ''; 
		DECLARE TEMP_CAT_MUNICIPALITY_DESCRIPTION VARCHAR(500) DEFAULT ''; 
		DECLARE TEMP_CAT_MUNICIPALITY_ZIP_CODE VARCHAR(50) DEFAULT ''; 
		DECLARE TEMP_CAT_MUNICIPALITY_PHONE_CODE VARCHAR(50) DEFAULT ''; 
		DECLARE TEMP_CAT_MUNICIPALITY_STATUS TINYINT DEFAULT 0; 
		DECLARE TEMP_CAT_MUNICIPALITY_SYSTEM_GENERATED TINYINT DEFAULT 0; 

	
	
	-- 2) Try Catch / Throw
	-- _______________________________________________________________________
	DECLARE EXIT HANDLER FOR SQLEXCEPTION
	BEGIN
		RESIGNAL;
	END;

	
	-- 3) Prepare SYNC
	-- _______________________________________________________________________
	
	-- IS RECORD EXISTS		
	-- ####################################################		
	SET TEMP_RECORD_EXISTS = `CATEGORY_ADDRESS_MUNICIPALITY@CAT_MUNICIPALITY_ID_EXISTS`(PARAM_CAT_MUNICIPALITY_ID, 0);


	-- 4) IF ALREADY EXIST, FILL MISSING DATA
	-- _______________________________________________________________________
	IF TEMP_RECORD_EXISTS = 1 THEN
		SELECT
				`category_address_municipality`.`CAT_MUNICIPALITY_GLOBAL_ID`, 	
				`category_address_municipality`.`CAT_MUNICIPALITY_CAT_PROVINCE_ID`, 	
				`category_address_municipality`.`CAT_MUNICIPALITY_CODE`, 	
				`category_address_municipality`.`CAT_MUNICIPALITY_DESCRIPTION`, 	
				`category_address_municipality`.`CAT_MUNICIPALITY_ZIP_CODE`, 	
				`category_address_municipality`.`CAT_MUNICIPALITY_PHONE_CODE`, 	
				`category_address_municipality`.`CAT_MUNICIPALITY_STATUS`, 	
				`category_address_municipality`.`CAT_MUNICIPALITY_SYSTEM_GENERATED`	
		INTO
				TEMP_CAT_MUNICIPALITY_GLOBAL_ID, 	
				TEMP_CAT_MUNICIPALITY_CAT_PROVINCE_ID, 	
				TEMP_CAT_MUNICIPALITY_CODE, 	
				TEMP_CAT_MUNICIPALITY_DESCRIPTION, 	
				TEMP_CAT_MUNICIPALITY_ZIP_CODE, 	
				TEMP_CAT_MUNICIPALITY_PHONE_CODE, 	
				TEMP_CAT_MUNICIPALITY_STATUS, 	
				TEMP_CAT_MUNICIPALITY_SYSTEM_GENERATED	

		FROM `category_address_municipality`
		WHERE
			`category_address_municipality`.`CAT_MUNICIPALITY_ID` = PARAM_CAT_MUNICIPALITY_ID
		LIMIT 1;

	ELSE 
		IF TEMP_SYNC_IS_SERVER_REQUEST = 0 THEN
			SET TEMP_ERR_MESSAGE = CONCAT_WS(' ', 'Given Address: Municipality does not exists or is inactive. ID:', PARAM_CAT_MUNICIPALITY_ID);
			SET ERR = `RAISERROR`(TEMP_ERR_MESSAGE);		
		END IF;
		LEAVE SP_DELETE;
		
	END IF;



	-- 5) PREPARE AUDIT TRAIL
	-- _______________________________________________________________________
	
		SET TEMP_RECORD_CHANGES = 
		`SYSTEM_VAR@CONCAT_ADD`(' | ', TEMP_RECORD_CHANGES, CONCAT_WS(' ', 'Sync ID: "', TEMP_CAT_MUNICIPALITY_GLOBAL_ID, '" > " DELETED "'));
		SET TEMP_RECORD_CHANGES = 
		`SYSTEM_VAR@CONCAT_ADD`(' | ', TEMP_RECORD_CHANGES, CONCAT_WS(' ', 'Province: "', TEMP_CAT_MUNICIPALITY_CAT_PROVINCE_ID, '" > " DELETED "'));
		SET TEMP_RECORD_CHANGES = 
		`SYSTEM_VAR@CONCAT_ADD`(' | ', TEMP_RECORD_CHANGES, CONCAT_WS(' ', 'Short Code: "', TEMP_CAT_MUNICIPALITY_CODE, '" > " DELETED "'));
		SET TEMP_RECORD_CHANGES = 
		`SYSTEM_VAR@CONCAT_ADD`(' | ', TEMP_RECORD_CHANGES, CONCAT_WS(' ', 'Description: "', TEMP_CAT_MUNICIPALITY_DESCRIPTION, '" > " DELETED "'));
		SET TEMP_RECORD_CHANGES = 
		`SYSTEM_VAR@CONCAT_ADD`(' | ', TEMP_RECORD_CHANGES, CONCAT_WS(' ', 'ZIP Code: "', TEMP_CAT_MUNICIPALITY_ZIP_CODE, '" > " DELETED "'));
		SET TEMP_RECORD_CHANGES = 
		`SYSTEM_VAR@CONCAT_ADD`(' | ', TEMP_RECORD_CHANGES, CONCAT_WS(' ', 'Phone Number Area Code: "', TEMP_CAT_MUNICIPALITY_PHONE_CODE, '" > " DELETED "'));
		SET TEMP_RECORD_CHANGES = 
		`SYSTEM_VAR@CONCAT_ADD`(' | ', TEMP_RECORD_CHANGES, CONCAT_WS(' ', 'Status: "', TEMP_CAT_MUNICIPALITY_STATUS, '" > " DELETED "'));
		SET TEMP_RECORD_CHANGES = 
		`SYSTEM_VAR@CONCAT_ADD`(' | ', TEMP_RECORD_CHANGES, CONCAT_WS(' ', 'System Generated: "', TEMP_CAT_MUNICIPALITY_SYSTEM_GENERATED, '" > " DELETED "'));


	-- 6) VALIDATE
	-- _______________________________________________________________________
	
	-- Access Rights [Device]
	-- ####################################################
	IF `ACCOUNT_DEVICE@HAS_PERMISSION`(PARAM_REQUESTER_DEVICE_PUBLIC_KEY, PARAM_REQUESTER_DEVICE_PRIVATE_KEY) = 0 THEN
		SET TEMP_ERR_MESSAGE = 'Your device is not authorized yet to access this server.';
		SET ERR = `RAISERROR`(TEMP_ERR_MESSAGE);		
	END IF;
		
		
	-- Access Rights [Account]
	-- ####################################################	
	
	IF 
		-- [DELETE] Access Rights
		`ACCOUNT_ACCESS_RIGHTS@HAS_PERMISSION`(PARAM_REQUESTER_USERNAME, PARAM_REQUESTER_PASSWORD, 0, TEMP_MODULE_KEYWORD, 4) = 0 
	THEN
		SET TEMP_ACCESS_RIGHTS_DENIED = 1;
		CALL `ACCOUNT_ACCESS_RIGHTS_DENY`
		(
			0, TEMP_MODULE_KEYWORD, PARAM_CAT_MUNICIPALITY_ID, 0, TEMP_SP_OBJECTIVE, TEMP_RECORD_CHANGES, 
			PARAM_REQUESTER_USERNAME, PARAM_REQUESTER_PASSWORD, 
			PARAM_REQUESTER_PROXY_ID, PARAM_REQUESTER_PROXY_PASSWORD,
			PARAM_REQUESTER_DEVICE_PUBLIC_KEY, PARAM_REQUESTER_DEVICE_PRIVATE_KEY,
			PARAM_REQUESTER_IP, PARAM_UNIQUE_SESSION_ID,
			TEMP_SYNC_SERVER_ID, PARAM_SUPPRESS_RETURN
		);
	END IF;

	-- System Generated Record (Cannot be deleted)
	-- ####################################################
	IF TEMP_CAT_MUNICIPALITY_SYSTEM_GENERATED = STATUS_ACTIVE THEN
		CALL `VALIDATION_SYSTEM_GENERATED`
		(
			PARAM_CAT_MUNICIPALITY_ID,
			TEMP_CAT_MUNICIPALITY_DESCRIPTION, ''
		);
	END IF;
	
	-- If already used, cannot remove record
	-- ####################################################
	IF
	(
		SELECT
			COUNT(`category_address_barangay`.`CAT_BARANGAY_CAT_MUNICIPALITY_ID`)
		FROM `category_address_barangay`
		WHERE
			`category_address_barangay`.`CAT_BARANGAY_CAT_MUNICIPALITY_ID` = PARAM_CAT_MUNICIPALITY_ID
		LIMIT 1
	) >= 1 
	THEN
		SET TEMP_RECORD_BINDED = 1;
		SET TEMP_ERR_MESSAGE = 'Address: Barangay Record';
	END IF;
	IF
	(
		SELECT
			COUNT(`category_branch`.`CAT_BRANCH_CAT_MUNICIPALITY_ID`)
		FROM `category_branch`
		WHERE
			`category_branch`.`CAT_BRANCH_CAT_MUNICIPALITY_ID` = PARAM_CAT_MUNICIPALITY_ID
		LIMIT 1
	) >= 1 
	THEN
		SET TEMP_RECORD_BINDED = 1;
		SET TEMP_ERR_MESSAGE = 'Branch Record';
	END IF;
	IF
	(
		SELECT
			COUNT(`record_combatants`.`REC_COMBATANT_CAT_MUNICIPALITY_ID`)
		FROM `record_combatants`
		WHERE
			`record_combatants`.`REC_COMBATANT_CAT_MUNICIPALITY_ID` = PARAM_CAT_MUNICIPALITY_ID
		LIMIT 1
	) >= 1 
	THEN
		SET TEMP_RECORD_BINDED = 1;
		SET TEMP_ERR_MESSAGE = 'Combatant Information Record';
	END IF;

	-- Leave Re-upload request
	-- ####################################################
	IF TEMP_RECORD_BINDED = 1 THEN
		IF TEMP_SYNC_IS_SERVER_REQUEST = 1 THEN
			
			LEAVE SP_DELETE;
		END IF;

		CALL `VALIDATION_DELETE_LINKED_RECORD`(TEMP_CAT_MUNICIPALITY_DESCRIPTION, '', TEMP_ERR_MESSAGE); 
	END IF;


	-- 7) DELETE
	-- _______________________________________________________________________
	DELETE FROM `category_address_municipality`
	WHERE `category_address_municipality`.`CAT_MUNICIPALITY_ID` = PARAM_CAT_MUNICIPALITY_ID
	LIMIT 1;


	-- 8) AUDIT TRAIL
	-- _______________________________________________________________________
	CALL `ACCOUNT_AUDIT_TRAIL_SAVE`
	(
		0, TEMP_MODULE_KEYWORD, PARAM_CAT_MUNICIPALITY_ID, 0, 'DELETE', TEMP_SP_OBJECTIVE, TEMP_RECORD_CHANGES, 
		PARAM_REQUESTER_USERNAME, PARAM_REQUESTER_PASSWORD, 
		PARAM_REQUESTER_PROXY_ID, PARAM_REQUESTER_PROXY_PASSWORD,
		PARAM_REQUESTER_DEVICE_PUBLIC_KEY, PARAM_REQUESTER_DEVICE_PRIVATE_KEY,
		PARAM_REQUESTER_IP, PARAM_UNIQUE_SESSION_ID,
		TEMP_SYNC_SERVER_ID, PARAM_SUPPRESS_RETURN
	);

END ;;
DELIMITER ;
/*!50003 SET sql_mode              = @saved_sql_mode */ ;
/*!50003 SET character_set_client  = @saved_cs_client */ ;
/*!50003 SET character_set_results = @saved_cs_results */ ;
/*!50003 SET collation_connection  = @saved_col_connection */ ;
/*!50003 DROP PROCEDURE IF EXISTS `CATEGORY_ADDRESS_MUNICIPALITY_GET` */;
/*!50003 SET @saved_cs_client      = @@character_set_client */ ;
/*!50003 SET @saved_cs_results     = @@character_set_results */ ;
/*!50003 SET @saved_col_connection = @@collation_connection */ ;
/*!50003 SET character_set_client  = latin1 */ ;
/*!50003 SET character_set_results = latin1 */ ;
/*!50003 SET collation_connection  = latin1_swedish_ci */ ;
/*!50003 SET @saved_sql_mode       = @@sql_mode */ ;
/*!50003 SET sql_mode              = '' */ ;
DELIMITER ;;
CREATE DEFINER=`root`@`localhost` PROCEDURE `CATEGORY_ADDRESS_MUNICIPALITY_GET`(
	IN `PARAM_CAT_MUNICIPALITY_ID` BIGINT,	
	IN `PARAM_CAT_MUNICIPALITY_GLOBAL_ID` VARCHAR(400),	
	IN `PARAM_CAT_MUNICIPALITY_CAT_PROVINCE_ID` BIGINT,	
	IN `PARAM_CAT_MUNICIPALITY_CODE` VARCHAR(50),	
	IN `PARAM_CAT_MUNICIPALITY_DESCRIPTION` VARCHAR(500),	
	IN `PARAM_CAT_MUNICIPALITY_ZIP_CODE` VARCHAR(50),	
	IN `PARAM_CAT_MUNICIPALITY_PHONE_CODE` VARCHAR(50),	
	IN `PARAM_CAT_MUNICIPALITY_STATUS` TINYINT,	
	IN `PARAM_CAT_MUNICIPALITY_SYSTEM_GENERATED` TINYINT,	
		
	IN `PARAM_ORDER_FIELD` VARCHAR(500),
	IN `PARAM_ORDER_TYPE` VARCHAR(500),
	IN `PARAM_SKIP` BIGINT,
	IN `PARAM_LIMIT` BIGINT,

	IN `PARAM_REQUESTER_USERNAME` VARCHAR(500),
	IN `PARAM_REQUESTER_PASSWORD` VARCHAR(500),
	IN `PARAM_REQUESTER_PROXY_ID` BIGINT,
	IN `PARAM_REQUESTER_PROXY_PASSWORD` VARCHAR(1000),
	IN `PARAM_REQUESTER_DEVICE_PUBLIC_KEY` VARCHAR(1000),
	IN `PARAM_REQUESTER_DEVICE_PRIVATE_KEY` VARCHAR(1000),
	
	IN `PARAM_REQUESTER_IP` VARCHAR(1000),
	IN `PARAM_UNIQUE_SESSION_ID` VARCHAR(1000),
	IN `PARAM_SUPPRESS_RETURN` BIT
)
SP_GET:
BEGIN

	-- Status
	-- =========================================================================================
	DECLARE STATUS_INACTIVE TINYINT DEFAULT 1;
	DECLARE STATUS_ACTIVE TINYINT DEFAULT 2;
	DECLARE STATUS_CLOSED TINYINT DEFAULT 3;
	DECLARE STATUS_COMPLETED TINYINT DEFAULT 4;
	
	-- Audit Handler
	-- =========================================================================================
	DECLARE TEMP_RECORD_EXISTS BIT DEFAULT 0;
	DECLARE TEMP_MODULE_KEYWORD VARCHAR(500) DEFAULT 'category_address_municipality';
	DECLARE TEMP_SP_OBJECTIVE VARCHAR(500) DEFAULT 'Retrieve Address: Municipality record';
	DECLARE TEMP_ERR_MESSAGE VARCHAR(500) DEFAULT '';
	DECLARE ERR BIGINT DEFAULT 0;
	DECLARE TEMP_RECORD_CHANGES VARCHAR(16000) DEFAULT '';
	DECLARE TEMP_RECORD_BINDED BIT DEFAULT 0;
	
	DECLARE TEMP_RECORD_BINDED_ID BIGINT DEFAULT 0;
	DECLARE TEMP_RECORD_BINDED_SERVER_ID BIGINT DEFAULT 0;
	
	-- Authentication
	-- =========================================================================================
	DECLARE TEMP_ACCESS_RIGHTS_DENIED BIT DEFAULT 0;
	DECLARE TEMP_AUTHENTICATED_ACCOUNT_ID BIGINT DEFAULT `ACCOUNT_MEMBER@ACC_ACCOUNT_ID_FROM_LOGIN`(PARAM_REQUESTER_USERNAME, PARAM_REQUESTER_PASSWORD);
	DECLARE TEMP_AUTHENTICATED_ACCOUNT_LEVEL BIGINT DEFAULT 0;
	DECLARE TEMP_AUTHENTICATED_ACCOUNT_GROUP BIGINT DEFAULT 0;
	
	-- Local Parameters
	-- =========================================================================================
	DECLARE TEMP_NOW DATETIME(6) DEFAULT `SYSTEM_VAR@NOW`('', 1);
	DECLARE TEMP_RECORD_COUNT BIGINT DEFAULT 0;
	
	
	-- Check NULLs
	-- =========================================================================================
	DECLARE IS_NULL_CAT_MUNICIPALITY_ID BIT DEFAULT `SYSTEM_VAR@IS_NULL@BIGINT`(PARAM_CAT_MUNICIPALITY_ID, 1, 1);
	DECLARE IS_NULL_CAT_MUNICIPALITY_GLOBAL_ID BIT DEFAULT `SYSTEM_VAR@IS_NULL@NVARCHAR`(PARAM_CAT_MUNICIPALITY_GLOBAL_ID, 1);
	DECLARE IS_NULL_CAT_MUNICIPALITY_CAT_PROVINCE_ID BIT DEFAULT `SYSTEM_VAR@IS_NULL@BIGINT`(PARAM_CAT_MUNICIPALITY_CAT_PROVINCE_ID, 1, 1);
	DECLARE IS_NULL_CAT_MUNICIPALITY_CODE BIT DEFAULT `SYSTEM_VAR@IS_NULL@NVARCHAR`(PARAM_CAT_MUNICIPALITY_CODE, 0);
	DECLARE IS_NULL_CAT_MUNICIPALITY_DESCRIPTION BIT DEFAULT `SYSTEM_VAR@IS_NULL@NVARCHAR`(PARAM_CAT_MUNICIPALITY_DESCRIPTION, 1);
	DECLARE IS_NULL_CAT_MUNICIPALITY_ZIP_CODE BIT DEFAULT `SYSTEM_VAR@IS_NULL@NVARCHAR`(PARAM_CAT_MUNICIPALITY_ZIP_CODE, 0);
	DECLARE IS_NULL_CAT_MUNICIPALITY_PHONE_CODE BIT DEFAULT `SYSTEM_VAR@IS_NULL@NVARCHAR`(PARAM_CAT_MUNICIPALITY_PHONE_CODE, 0);
	DECLARE IS_NULL_CAT_MUNICIPALITY_STATUS BIT DEFAULT `SYSTEM_VAR@IS_NULL@TINYINT`(PARAM_CAT_MUNICIPALITY_STATUS, 1, 1);
	DECLARE IS_NULL_CAT_MUNICIPALITY_SYSTEM_GENERATED BIT DEFAULT `SYSTEM_VAR@IS_NULL@TINYINT`(PARAM_CAT_MUNICIPALITY_SYSTEM_GENERATED, 1, 1);
	
	-- Error Handler
	-- =========================================================================================
	DECLARE EXIT HANDLER FOR SQLEXCEPTION
	BEGIN
		RESIGNAL;
	END;
	
	-- Ignore Time from DateTime (Set Time 00:00:00.000000 and 23:59:59.999999)
	-- =========================================================================================
		
		
	-- Access Rights [Device]
	-- =========================================================================================
	IF `ACCOUNT_DEVICE@HAS_PERMISSION`(PARAM_REQUESTER_DEVICE_PUBLIC_KEY, PARAM_REQUESTER_DEVICE_PRIVATE_KEY) = 0 THEN
		SET TEMP_ERR_MESSAGE = 'Your device is not authorized yet to access this server.';
		SET ERR = `RAISERROR`(TEMP_ERR_MESSAGE);		
	END IF;
		
		
	-- Access Rights [Account]
	-- =========================================================================================
		
	
	
	
	-- COUNT RECORD
	-- =========================================================================================
	
	-- SELECT COLUMNS
	-- ####################################################
	SELECT
		COUNT(DISTINCT `category_address_municipality`.`CAT_MUNICIPALITY_ID`)
	INTO
		TEMP_RECORD_COUNT

	FROM `category_address_municipality`
	
		-- Add Inner Joins (Per Foreign-key)
		INNER JOIN `category_address_province` ON
		`category_address_province`.`CAT_PROVINCE_ID` = `category_address_municipality`.`CAT_MUNICIPALITY_CAT_PROVINCE_ID`
		
		-- Add Optional Left Joins (Per Optional Foreign-key)
		
	-- CONDITIONS
	-- ####################################################
	WHERE
		(
			IS_NULL_CAT_MUNICIPALITY_ID = 1 OR
			`category_address_municipality`.`CAT_MUNICIPALITY_ID` = PARAM_CAT_MUNICIPALITY_ID			
		) AND
		(
			IS_NULL_CAT_MUNICIPALITY_GLOBAL_ID = 1 OR
			`category_address_municipality`.`CAT_MUNICIPALITY_GLOBAL_ID` LIKE CONCAT_WS('%', '', PARAM_CAT_MUNICIPALITY_GLOBAL_ID, '')			
		) AND 		
		(
			IS_NULL_CAT_MUNICIPALITY_CAT_PROVINCE_ID = 1 OR
			`category_address_municipality`.`CAT_MUNICIPALITY_CAT_PROVINCE_ID` = PARAM_CAT_MUNICIPALITY_CAT_PROVINCE_ID			
		) AND
		(
			IS_NULL_CAT_MUNICIPALITY_CODE = 1 OR
			`category_address_municipality`.`CAT_MUNICIPALITY_CODE` LIKE CONCAT_WS('%', '', PARAM_CAT_MUNICIPALITY_CODE, '')			
		) AND 		
		(
			IS_NULL_CAT_MUNICIPALITY_DESCRIPTION = 1 OR
			`category_address_municipality`.`CAT_MUNICIPALITY_DESCRIPTION` LIKE CONCAT_WS('%', '', PARAM_CAT_MUNICIPALITY_DESCRIPTION, '')			
		) AND 		
		(
			IS_NULL_CAT_MUNICIPALITY_ZIP_CODE = 1 OR
			`category_address_municipality`.`CAT_MUNICIPALITY_ZIP_CODE` LIKE CONCAT_WS('%', '', PARAM_CAT_MUNICIPALITY_ZIP_CODE, '')			
		) AND 		
		(
			IS_NULL_CAT_MUNICIPALITY_PHONE_CODE = 1 OR
			`category_address_municipality`.`CAT_MUNICIPALITY_PHONE_CODE` LIKE CONCAT_WS('%', '', PARAM_CAT_MUNICIPALITY_PHONE_CODE, '')			
		) AND 		
		(
			IS_NULL_CAT_MUNICIPALITY_STATUS = 1 OR
			`category_address_municipality`.`CAT_MUNICIPALITY_STATUS` = PARAM_CAT_MUNICIPALITY_STATUS			
		) AND
		(
			IS_NULL_CAT_MUNICIPALITY_SYSTEM_GENERATED = 1 OR
			`category_address_municipality`.`CAT_MUNICIPALITY_SYSTEM_GENERATED` = PARAM_CAT_MUNICIPALITY_SYSTEM_GENERATED			
		) 
;	

		
		
	-- SELECT RECORDS
	-- =========================================================================================
	
	-- FETCH COLUMNS
	-- ####################################################
	SELECT
		-- CATEGORY_ADDRESS_MUNICIPALITY DETAILS
		`category_address_municipality`.`CAT_MUNICIPALITY_ID`, 
		`category_address_municipality`.`CAT_MUNICIPALITY_GLOBAL_ID`, 
		`category_address_municipality`.`CAT_MUNICIPALITY_CAT_PROVINCE_ID`, 
		`category_address_municipality`.`CAT_MUNICIPALITY_CODE`, 
		`category_address_municipality`.`CAT_MUNICIPALITY_DESCRIPTION`, 
		`category_address_municipality`.`CAT_MUNICIPALITY_ZIP_CODE`, 
		`category_address_municipality`.`CAT_MUNICIPALITY_PHONE_CODE`, 
		`category_address_municipality`.`CAT_MUNICIPALITY_STATUS`, 
		`category_address_municipality`.`CAT_MUNICIPALITY_SYSTEM_GENERATED`
		
		-- Inner join fields
		, 
		`category_address_province`.`CAT_PROVINCE_ID`, 
		`category_address_province`.`CAT_PROVINCE_GLOBAL_ID`, 
		`category_address_province`.`CAT_PROVINCE_CAT_REGION_ID`, 
		`category_address_province`.`CAT_PROVINCE_CODE`, 
		`category_address_province`.`CAT_PROVINCE_DESCRIPTION`, 
		`category_address_province`.`CAT_PROVINCE_STATUS`, 
		`category_address_province`.`CAT_PROVINCE_SYSTEM_GENERATED`
		
		-- Left join fields
		
		, TEMP_RECORD_COUNT AS RECORD_COUNT

	FROM `category_address_municipality`
	
		-- Add Inner Joins (Per Foreign-key)
		INNER JOIN `category_address_province` ON
		`category_address_province`.`CAT_PROVINCE_ID` = `category_address_municipality`.`CAT_MUNICIPALITY_CAT_PROVINCE_ID`
		
		-- Add Optional Left Joins (Per Optional Foreign-key)
		
	-- CONDITIONS
	-- ####################################################
	WHERE
		(
			IS_NULL_CAT_MUNICIPALITY_ID = 1 OR
			`category_address_municipality`.`CAT_MUNICIPALITY_ID` = PARAM_CAT_MUNICIPALITY_ID			
		) AND
		(
			IS_NULL_CAT_MUNICIPALITY_GLOBAL_ID = 1 OR
			`category_address_municipality`.`CAT_MUNICIPALITY_GLOBAL_ID` LIKE CONCAT_WS('%', '', PARAM_CAT_MUNICIPALITY_GLOBAL_ID, '')			
		) AND 		
		(
			IS_NULL_CAT_MUNICIPALITY_CAT_PROVINCE_ID = 1 OR
			`category_address_municipality`.`CAT_MUNICIPALITY_CAT_PROVINCE_ID` = PARAM_CAT_MUNICIPALITY_CAT_PROVINCE_ID			
		) AND
		(
			IS_NULL_CAT_MUNICIPALITY_CODE = 1 OR
			`category_address_municipality`.`CAT_MUNICIPALITY_CODE` LIKE CONCAT_WS('%', '', PARAM_CAT_MUNICIPALITY_CODE, '')			
		) AND 		
		(
			IS_NULL_CAT_MUNICIPALITY_DESCRIPTION = 1 OR
			`category_address_municipality`.`CAT_MUNICIPALITY_DESCRIPTION` LIKE CONCAT_WS('%', '', PARAM_CAT_MUNICIPALITY_DESCRIPTION, '')			
		) AND 		
		(
			IS_NULL_CAT_MUNICIPALITY_ZIP_CODE = 1 OR
			`category_address_municipality`.`CAT_MUNICIPALITY_ZIP_CODE` LIKE CONCAT_WS('%', '', PARAM_CAT_MUNICIPALITY_ZIP_CODE, '')			
		) AND 		
		(
			IS_NULL_CAT_MUNICIPALITY_PHONE_CODE = 1 OR
			`category_address_municipality`.`CAT_MUNICIPALITY_PHONE_CODE` LIKE CONCAT_WS('%', '', PARAM_CAT_MUNICIPALITY_PHONE_CODE, '')			
		) AND 		
		(
			IS_NULL_CAT_MUNICIPALITY_STATUS = 1 OR
			`category_address_municipality`.`CAT_MUNICIPALITY_STATUS` = PARAM_CAT_MUNICIPALITY_STATUS			
		) AND
		(
			IS_NULL_CAT_MUNICIPALITY_SYSTEM_GENERATED = 1 OR
			`category_address_municipality`.`CAT_MUNICIPALITY_SYSTEM_GENERATED` = PARAM_CAT_MUNICIPALITY_SYSTEM_GENERATED			
		) 

	-- ORDER BY
	-- ####################################################
	ORDER BY
		-- CATEGORY_ADDRESS_MUNICIPALITY DETAILS
		CASE WHEN PARAM_ORDER_FIELD = 'CAT_MUNICIPALITY_ID' AND PARAM_ORDER_TYPE = 'ASC' THEN `category_address_municipality`.`CAT_MUNICIPALITY_ID` END ASC, 
		CASE WHEN PARAM_ORDER_FIELD = 'CAT_MUNICIPALITY_ID' AND PARAM_ORDER_TYPE = 'DESC' THEN `category_address_municipality`.`CAT_MUNICIPALITY_ID` END DESC,	
		CASE WHEN PARAM_ORDER_FIELD = 'CAT_MUNICIPALITY_GLOBAL_ID' AND PARAM_ORDER_TYPE = 'ASC' THEN `category_address_municipality`.`CAT_MUNICIPALITY_GLOBAL_ID` END ASC, 
		CASE WHEN PARAM_ORDER_FIELD = 'CAT_MUNICIPALITY_GLOBAL_ID' AND PARAM_ORDER_TYPE = 'DESC' THEN `category_address_municipality`.`CAT_MUNICIPALITY_GLOBAL_ID` END DESC,	
		CASE WHEN PARAM_ORDER_FIELD = 'CAT_MUNICIPALITY_CAT_PROVINCE_ID' AND PARAM_ORDER_TYPE = 'ASC' THEN `category_address_municipality`.`CAT_MUNICIPALITY_CAT_PROVINCE_ID` END ASC, 
		CASE WHEN PARAM_ORDER_FIELD = 'CAT_MUNICIPALITY_CAT_PROVINCE_ID' AND PARAM_ORDER_TYPE = 'DESC' THEN `category_address_municipality`.`CAT_MUNICIPALITY_CAT_PROVINCE_ID` END DESC,	
		CASE WHEN PARAM_ORDER_FIELD = 'CAT_MUNICIPALITY_CODE' AND PARAM_ORDER_TYPE = 'ASC' THEN `category_address_municipality`.`CAT_MUNICIPALITY_CODE` END ASC, 
		CASE WHEN PARAM_ORDER_FIELD = 'CAT_MUNICIPALITY_CODE' AND PARAM_ORDER_TYPE = 'DESC' THEN `category_address_municipality`.`CAT_MUNICIPALITY_CODE` END DESC,	
		CASE WHEN PARAM_ORDER_FIELD = 'CAT_MUNICIPALITY_DESCRIPTION' AND PARAM_ORDER_TYPE = 'ASC' THEN `category_address_municipality`.`CAT_MUNICIPALITY_DESCRIPTION` END ASC, 
		CASE WHEN PARAM_ORDER_FIELD = 'CAT_MUNICIPALITY_DESCRIPTION' AND PARAM_ORDER_TYPE = 'DESC' THEN `category_address_municipality`.`CAT_MUNICIPALITY_DESCRIPTION` END DESC,	
		CASE WHEN PARAM_ORDER_FIELD = 'CAT_MUNICIPALITY_ZIP_CODE' AND PARAM_ORDER_TYPE = 'ASC' THEN `category_address_municipality`.`CAT_MUNICIPALITY_ZIP_CODE` END ASC, 
		CASE WHEN PARAM_ORDER_FIELD = 'CAT_MUNICIPALITY_ZIP_CODE' AND PARAM_ORDER_TYPE = 'DESC' THEN `category_address_municipality`.`CAT_MUNICIPALITY_ZIP_CODE` END DESC,	
		CASE WHEN PARAM_ORDER_FIELD = 'CAT_MUNICIPALITY_PHONE_CODE' AND PARAM_ORDER_TYPE = 'ASC' THEN `category_address_municipality`.`CAT_MUNICIPALITY_PHONE_CODE` END ASC, 
		CASE WHEN PARAM_ORDER_FIELD = 'CAT_MUNICIPALITY_PHONE_CODE' AND PARAM_ORDER_TYPE = 'DESC' THEN `category_address_municipality`.`CAT_MUNICIPALITY_PHONE_CODE` END DESC,	
		CASE WHEN PARAM_ORDER_FIELD = 'CAT_MUNICIPALITY_STATUS' AND PARAM_ORDER_TYPE = 'ASC' THEN `category_address_municipality`.`CAT_MUNICIPALITY_STATUS` END ASC, 
		CASE WHEN PARAM_ORDER_FIELD = 'CAT_MUNICIPALITY_STATUS' AND PARAM_ORDER_TYPE = 'DESC' THEN `category_address_municipality`.`CAT_MUNICIPALITY_STATUS` END DESC,	
		CASE WHEN PARAM_ORDER_FIELD = 'CAT_MUNICIPALITY_SYSTEM_GENERATED' AND PARAM_ORDER_TYPE = 'ASC' THEN `category_address_municipality`.`CAT_MUNICIPALITY_SYSTEM_GENERATED` END ASC, 
		CASE WHEN PARAM_ORDER_FIELD = 'CAT_MUNICIPALITY_SYSTEM_GENERATED' AND PARAM_ORDER_TYPE = 'DESC' THEN `category_address_municipality`.`CAT_MUNICIPALITY_SYSTEM_GENERATED` END DESC,	

		-- Inner joins
		CASE WHEN PARAM_ORDER_FIELD = 'CAT_PROVINCE_ID' AND PARAM_ORDER_TYPE = 'ASC' THEN `category_address_province`.`CAT_PROVINCE_ID` END ASC, 
		CASE WHEN PARAM_ORDER_FIELD = 'CAT_PROVINCE_ID' AND PARAM_ORDER_TYPE = 'DESC' THEN `category_address_province`.`CAT_PROVINCE_ID` END DESC,	
		CASE WHEN PARAM_ORDER_FIELD = 'CAT_PROVINCE_GLOBAL_ID' AND PARAM_ORDER_TYPE = 'ASC' THEN `category_address_province`.`CAT_PROVINCE_GLOBAL_ID` END ASC, 
		CASE WHEN PARAM_ORDER_FIELD = 'CAT_PROVINCE_GLOBAL_ID' AND PARAM_ORDER_TYPE = 'DESC' THEN `category_address_province`.`CAT_PROVINCE_GLOBAL_ID` END DESC,	
		CASE WHEN PARAM_ORDER_FIELD = 'CAT_PROVINCE_CAT_REGION_ID' AND PARAM_ORDER_TYPE = 'ASC' THEN `category_address_province`.`CAT_PROVINCE_CAT_REGION_ID` END ASC, 
		CASE WHEN PARAM_ORDER_FIELD = 'CAT_PROVINCE_CAT_REGION_ID' AND PARAM_ORDER_TYPE = 'DESC' THEN `category_address_province`.`CAT_PROVINCE_CAT_REGION_ID` END DESC,	
		CASE WHEN PARAM_ORDER_FIELD = 'CAT_PROVINCE_CODE' AND PARAM_ORDER_TYPE = 'ASC' THEN `category_address_province`.`CAT_PROVINCE_CODE` END ASC, 
		CASE WHEN PARAM_ORDER_FIELD = 'CAT_PROVINCE_CODE' AND PARAM_ORDER_TYPE = 'DESC' THEN `category_address_province`.`CAT_PROVINCE_CODE` END DESC,	
		CASE WHEN PARAM_ORDER_FIELD = 'CAT_PROVINCE_DESCRIPTION' AND PARAM_ORDER_TYPE = 'ASC' THEN `category_address_province`.`CAT_PROVINCE_DESCRIPTION` END ASC, 
		CASE WHEN PARAM_ORDER_FIELD = 'CAT_PROVINCE_DESCRIPTION' AND PARAM_ORDER_TYPE = 'DESC' THEN `category_address_province`.`CAT_PROVINCE_DESCRIPTION` END DESC,	
		CASE WHEN PARAM_ORDER_FIELD = 'CAT_PROVINCE_STATUS' AND PARAM_ORDER_TYPE = 'ASC' THEN `category_address_province`.`CAT_PROVINCE_STATUS` END ASC, 
		CASE WHEN PARAM_ORDER_FIELD = 'CAT_PROVINCE_STATUS' AND PARAM_ORDER_TYPE = 'DESC' THEN `category_address_province`.`CAT_PROVINCE_STATUS` END DESC,	
		CASE WHEN PARAM_ORDER_FIELD = 'CAT_PROVINCE_SYSTEM_GENERATED' AND PARAM_ORDER_TYPE = 'ASC' THEN `category_address_province`.`CAT_PROVINCE_SYSTEM_GENERATED` END ASC, 
		CASE WHEN PARAM_ORDER_FIELD = 'CAT_PROVINCE_SYSTEM_GENERATED' AND PARAM_ORDER_TYPE = 'DESC' THEN `category_address_province`.`CAT_PROVINCE_SYSTEM_GENERATED` END DESC,	
		
		-- EXTRA
		CASE WHEN PARAM_ORDER_FIELD <> 'CAT_MUNICIPALITY_DESCRIPTION' THEN `category_address_municipality`.`CAT_MUNICIPALITY_DESCRIPTION` END ASC
		
	-- LIMIT & OFFSET
	-- ####################################################		
	LIMIT PARAM_SKIP, PARAM_LIMIT;
	
	
	
	-- EXIT PROCEDURE
	-- =========================================================================================
	LEAVE SP_GET;
			
END ;;
DELIMITER ;
/*!50003 SET sql_mode              = @saved_sql_mode */ ;
/*!50003 SET character_set_client  = @saved_cs_client */ ;
/*!50003 SET character_set_results = @saved_cs_results */ ;
/*!50003 SET collation_connection  = @saved_col_connection */ ;
/*!50003 DROP PROCEDURE IF EXISTS `CATEGORY_ADDRESS_MUNICIPALITY_SAVE` */;
/*!50003 SET @saved_cs_client      = @@character_set_client */ ;
/*!50003 SET @saved_cs_results     = @@character_set_results */ ;
/*!50003 SET @saved_col_connection = @@collation_connection */ ;
/*!50003 SET character_set_client  = latin1 */ ;
/*!50003 SET character_set_results = latin1 */ ;
/*!50003 SET collation_connection  = latin1_swedish_ci */ ;
/*!50003 SET @saved_sql_mode       = @@sql_mode */ ;
/*!50003 SET sql_mode              = '' */ ;
DELIMITER ;;
CREATE DEFINER=`root`@`localhost` PROCEDURE `CATEGORY_ADDRESS_MUNICIPALITY_SAVE`(
	IN `PARAM_CAT_MUNICIPALITY_ID` BIGINT,
	IN `PARAM_CAT_MUNICIPALITY_CAT_PROVINCE_ID` BIGINT,
	IN `PARAM_CAT_MUNICIPALITY_CODE` VARCHAR(50),
	IN `PARAM_CAT_MUNICIPALITY_DESCRIPTION` VARCHAR(500),
	IN `PARAM_CAT_MUNICIPALITY_ZIP_CODE` VARCHAR(50),
	IN `PARAM_CAT_MUNICIPALITY_PHONE_CODE` VARCHAR(50),
	IN `PARAM_CAT_MUNICIPALITY_STATUS` TINYINT,

	IN `PARAM_REQUESTER_USERNAME` VARCHAR(500),
	IN `PARAM_REQUESTER_PASSWORD` VARCHAR(500),
	IN `PARAM_REQUESTER_PROXY_ID` BIGINT,
	IN `PARAM_REQUESTER_PROXY_PASSWORD` VARCHAR(1000),
	IN `PARAM_REQUESTER_DEVICE_PUBLIC_KEY` VARCHAR(1000),
	IN `PARAM_REQUESTER_DEVICE_PRIVATE_KEY` VARCHAR(1000),
	
	IN `PARAM_REQUESTER_IP` VARCHAR(1000),
	IN `PARAM_UNIQUE_SESSION_ID` VARCHAR(1000),
	IN `PARAM_SUPPRESS_RETURN` BIT,
	
	IN `PARAM_SYNC_SERVER_DESCRIPTION` VARCHAR(500), 
	IN `PARAM_SYNC_SERVER_UNIQUE_KEY` VARCHAR(500)
)
SP_SAVE:
BEGIN


	-- 1) DECLARE LOCAL PARAMETERS
	-- _______________________________________________________________________
	
	-- Status
	-- ...........................................
	DECLARE STATUS_INACTIVE TINYINT DEFAULT 1;
	DECLARE STATUS_ACTIVE TINYINT DEFAULT 2;
	DECLARE STATUS_CLOSED TINYINT DEFAULT 3;
	DECLARE STATUS_COMPLETED TINYINT DEFAULT 4;

	-- Audit Handler
	-- ...........................................
	DECLARE TEMP_RECORD_EXISTS BIT DEFAULT 0;
	DECLARE TEMP_MODULE_KEYWORD VARCHAR(500) DEFAULT 'category_address_municipality';
	DECLARE TEMP_SP_OBJECTIVE VARCHAR(500) DEFAULT 'add/edit Address: Municipality record';
	DECLARE TEMP_ERR_MESSAGE VARCHAR(500) DEFAULT '';
	DECLARE ERR BIGINT DEFAULT 0;
	DECLARE TEMP_RECORD_CHANGES VARCHAR(16000) DEFAULT '';
	DECLARE TEMP_RECORD_BINDED BIT DEFAULT 0;

	-- Authentication
	-- ...........................................
	DECLARE TEMP_ACCESS_RIGHTS_DENIED BIT DEFAULT 0;
	DECLARE TEMP_ACCESS_RIGHTS_HAS_OVERRIDE BIT DEFAULT 0;
	DECLARE TEMP_SYNC_SERVER_ID BIGINT DEFAULT 0;
	DECLARE TEMP_SYNC_IS_SERVER_REQUEST BIT DEFAULT 0;
	DECLARE TEMP_AUTHENTICATED_ACCOUNT_ID BIGINT DEFAULT `ACCOUNT_MEMBER@ACC_ACCOUNT_ID_FROM_LOGIN`(PARAM_REQUESTER_USERNAME, PARAM_REQUESTER_PASSWORD);
	DECLARE TEMP_AUTHENTICATED_ACCOUNT_LEVEL BIGINT DEFAULT 0;
	DECLARE TEMP_AUTHENTICATED_ACCOUNT_GROUP BIGINT DEFAULT 0;
	
	-- Local Parameters
	-- ...........................................
	DECLARE TEMP_NOW DATETIME(6) DEFAULT `SYSTEM_VAR@NOW`('', 1);
	DECLARE TEMP_RECORD_COUNT BIGINT DEFAULT 0;

	-- AutoGen Parameters
	-- ...........................................
	DECLARE PARAM_CAT_MUNICIPALITY_GLOBAL_ID VARCHAR(400) DEFAULT ''; 
	DECLARE PARAM_CAT_MUNICIPALITY_SYSTEM_GENERATED TINYINT DEFAULT 0; 
	
	-- Local value holder
	-- ...........................................
	DECLARE TEMP_CAT_MUNICIPALITY_GLOBAL_ID VARCHAR(400) DEFAULT ''; 
	DECLARE TEMP_CAT_MUNICIPALITY_CAT_PROVINCE_ID BIGINT DEFAULT 0; 
	DECLARE TEMP_CAT_MUNICIPALITY_CODE VARCHAR(50) DEFAULT ''; 
	DECLARE TEMP_CAT_MUNICIPALITY_DESCRIPTION VARCHAR(500) DEFAULT ''; 
	DECLARE TEMP_CAT_MUNICIPALITY_ZIP_CODE VARCHAR(50) DEFAULT ''; 
	DECLARE TEMP_CAT_MUNICIPALITY_PHONE_CODE VARCHAR(50) DEFAULT ''; 
	DECLARE TEMP_CAT_MUNICIPALITY_STATUS TINYINT DEFAULT 0; 
	DECLARE TEMP_CAT_MUNICIPALITY_SYSTEM_GENERATED TINYINT DEFAULT 0; 
	


	-- 2) Try Catch / Throw
	-- _______________________________________________________________________
	DECLARE EXIT HANDLER FOR SQLEXCEPTION
	BEGIN
		RESIGNAL;
	END;



	-- 3) Prepare SYNC
	-- _______________________________________________________________________

	-- IS RECORD EXISTS		
	-- ####################################################	
	SET TEMP_RECORD_EXISTS = `CATEGORY_ADDRESS_MUNICIPALITY@CAT_MUNICIPALITY_ID_EXISTS`(PARAM_CAT_MUNICIPALITY_ID, 0);

		
		
	-- 4) PREPARE AUTOGEN DATA (IF EXISTS)
	-- _______________________________________________________________________
	IF TEMP_SYNC_IS_SERVER_REQUEST = 0 THEN
		-- Just to keep at least one line within condition
		SET TEMP_SYNC_IS_SERVER_REQUEST = 0;
		
		-- Actual Functionalities here
		-- USE DEFAULT VALUE (String)
		-- USE DEFAULT VALUE (String)
		SET PARAM_CAT_MUNICIPALITY_GLOBAL_ID = `SYSTEM_VAR@RANDOM_UNIQUE_ALPHA32`;
		-- USE DEFAULT VALUE (String)
		SET PARAM_CAT_MUNICIPALITY_SYSTEM_GENERATED = 1;
	-- USE TIMESTAMP
	END IF;



	-- 5) IF ALREADY EXIST, FILL MISSING DATA
	-- _______________________________________________________________________
	IF TEMP_RECORD_EXISTS = 1 THEN
		SELECT
			`category_address_municipality`.`CAT_MUNICIPALITY_GLOBAL_ID`, 	
			`category_address_municipality`.`CAT_MUNICIPALITY_CAT_PROVINCE_ID`, 	
			`category_address_municipality`.`CAT_MUNICIPALITY_CODE`, 	
			`category_address_municipality`.`CAT_MUNICIPALITY_DESCRIPTION`, 	
			`category_address_municipality`.`CAT_MUNICIPALITY_ZIP_CODE`, 	
			`category_address_municipality`.`CAT_MUNICIPALITY_PHONE_CODE`, 	
			`category_address_municipality`.`CAT_MUNICIPALITY_STATUS`, 	
			`category_address_municipality`.`CAT_MUNICIPALITY_SYSTEM_GENERATED`	
		INTO
			TEMP_CAT_MUNICIPALITY_GLOBAL_ID, 	
			TEMP_CAT_MUNICIPALITY_CAT_PROVINCE_ID, 	
			TEMP_CAT_MUNICIPALITY_CODE, 	
			TEMP_CAT_MUNICIPALITY_DESCRIPTION, 	
			TEMP_CAT_MUNICIPALITY_ZIP_CODE, 	
			TEMP_CAT_MUNICIPALITY_PHONE_CODE, 	
			TEMP_CAT_MUNICIPALITY_STATUS, 	
			TEMP_CAT_MUNICIPALITY_SYSTEM_GENERATED	

		FROM `category_address_municipality`
		WHERE
			`category_address_municipality`.`CAT_MUNICIPALITY_ID` = PARAM_CAT_MUNICIPALITY_ID
		LIMIT 1;

		-- Replace NULLs with the existing data.
		SET PARAM_CAT_MUNICIPALITY_CAT_PROVINCE_ID = `SYSTEM_VAR@REPLACE_NULL@BIGINT`(PARAM_CAT_MUNICIPALITY_CAT_PROVINCE_ID, TEMP_CAT_MUNICIPALITY_CAT_PROVINCE_ID, 1, 1);
		SET PARAM_CAT_MUNICIPALITY_CODE = `SYSTEM_VAR@REPLACE_NULL@NVARCHAR`(PARAM_CAT_MUNICIPALITY_CODE, TEMP_CAT_MUNICIPALITY_CODE, 0);
		SET PARAM_CAT_MUNICIPALITY_DESCRIPTION = `SYSTEM_VAR@REPLACE_NULL@NVARCHAR`(PARAM_CAT_MUNICIPALITY_DESCRIPTION, TEMP_CAT_MUNICIPALITY_DESCRIPTION, 1);
		SET PARAM_CAT_MUNICIPALITY_ZIP_CODE = `SYSTEM_VAR@REPLACE_NULL@NVARCHAR`(PARAM_CAT_MUNICIPALITY_ZIP_CODE, TEMP_CAT_MUNICIPALITY_ZIP_CODE, 0);
		SET PARAM_CAT_MUNICIPALITY_PHONE_CODE = `SYSTEM_VAR@REPLACE_NULL@NVARCHAR`(PARAM_CAT_MUNICIPALITY_PHONE_CODE, TEMP_CAT_MUNICIPALITY_PHONE_CODE, 0);
		SET PARAM_CAT_MUNICIPALITY_STATUS = `SYSTEM_VAR@REPLACE_NULL@TINYINT`(PARAM_CAT_MUNICIPALITY_STATUS, TEMP_CAT_MUNICIPALITY_STATUS, 1, 1);
		
		-- AUTO GEN (NON-UPDATABLES)		
		SET PARAM_CAT_MUNICIPALITY_GLOBAL_ID = TEMP_CAT_MUNICIPALITY_GLOBAL_ID;
		SET PARAM_CAT_MUNICIPALITY_SYSTEM_GENERATED = TEMP_CAT_MUNICIPALITY_SYSTEM_GENERATED;
		
		-- AUTO GEN (UPDATABLE WITH STATUS CHANGE)

		-- AUTO GEN (UPDATABLE WITH STATUS [ACTIVE/INACTIVE] CHANGE)
		
	ELSE
		SET PARAM_CAT_MUNICIPALITY_CAT_PROVINCE_ID = `SYSTEM_VAR@REPLACE_NULL@BIGINT`(PARAM_CAT_MUNICIPALITY_CAT_PROVINCE_ID, 0, 1, 1);
		SET PARAM_CAT_MUNICIPALITY_CODE = `SYSTEM_VAR@REPLACE_NULL@NVARCHAR`(PARAM_CAT_MUNICIPALITY_CODE, '', 0);
		SET PARAM_CAT_MUNICIPALITY_DESCRIPTION = `SYSTEM_VAR@REPLACE_NULL@NVARCHAR`(PARAM_CAT_MUNICIPALITY_DESCRIPTION, '', 1);
		SET PARAM_CAT_MUNICIPALITY_ZIP_CODE = `SYSTEM_VAR@REPLACE_NULL@NVARCHAR`(PARAM_CAT_MUNICIPALITY_ZIP_CODE, '', 0);
		SET PARAM_CAT_MUNICIPALITY_PHONE_CODE = `SYSTEM_VAR@REPLACE_NULL@NVARCHAR`(PARAM_CAT_MUNICIPALITY_PHONE_CODE, '', 0);
		SET PARAM_CAT_MUNICIPALITY_STATUS = `SYSTEM_VAR@REPLACE_NULL@TINYINT`(PARAM_CAT_MUNICIPALITY_STATUS, 0, 1, 1);
		
	END IF;

	

	-- 6) PREPARE AUDIT TRAIL
	-- _______________________________________________________________________
	IF BINARY TEMP_CAT_MUNICIPALITY_GLOBAL_ID <> PARAM_CAT_MUNICIPALITY_GLOBAL_ID THEN
		SET TEMP_RECORD_CHANGES = 
		`SYSTEM_VAR@CONCAT_ADD`(' | ', TEMP_RECORD_CHANGES, CONCAT_WS(' ', 'Sync ID: "', TEMP_CAT_MUNICIPALITY_GLOBAL_ID, '" > "', PARAM_CAT_MUNICIPALITY_GLOBAL_ID, '"'));
	END IF;
	IF TEMP_CAT_MUNICIPALITY_CAT_PROVINCE_ID <> PARAM_CAT_MUNICIPALITY_CAT_PROVINCE_ID THEN
		SET TEMP_RECORD_CHANGES = 
		`SYSTEM_VAR@CONCAT_ADD`(' | ', TEMP_RECORD_CHANGES, CONCAT_WS(' ', 'Province: "', TEMP_CAT_MUNICIPALITY_CAT_PROVINCE_ID, '" > "', PARAM_CAT_MUNICIPALITY_CAT_PROVINCE_ID, '"'));
	END IF;	
	IF BINARY TEMP_CAT_MUNICIPALITY_CODE <> PARAM_CAT_MUNICIPALITY_CODE THEN
		SET TEMP_RECORD_CHANGES = 
		`SYSTEM_VAR@CONCAT_ADD`(' | ', TEMP_RECORD_CHANGES, CONCAT_WS(' ', 'Short Code: "', TEMP_CAT_MUNICIPALITY_CODE, '" > "', PARAM_CAT_MUNICIPALITY_CODE, '"'));
	END IF;
	IF BINARY TEMP_CAT_MUNICIPALITY_DESCRIPTION <> PARAM_CAT_MUNICIPALITY_DESCRIPTION THEN
		SET TEMP_RECORD_CHANGES = 
		`SYSTEM_VAR@CONCAT_ADD`(' | ', TEMP_RECORD_CHANGES, CONCAT_WS(' ', 'Description: "', TEMP_CAT_MUNICIPALITY_DESCRIPTION, '" > "', PARAM_CAT_MUNICIPALITY_DESCRIPTION, '"'));
	END IF;
	IF BINARY TEMP_CAT_MUNICIPALITY_ZIP_CODE <> PARAM_CAT_MUNICIPALITY_ZIP_CODE THEN
		SET TEMP_RECORD_CHANGES = 
		`SYSTEM_VAR@CONCAT_ADD`(' | ', TEMP_RECORD_CHANGES, CONCAT_WS(' ', 'ZIP Code: "', TEMP_CAT_MUNICIPALITY_ZIP_CODE, '" > "', PARAM_CAT_MUNICIPALITY_ZIP_CODE, '"'));
	END IF;
	IF BINARY TEMP_CAT_MUNICIPALITY_PHONE_CODE <> PARAM_CAT_MUNICIPALITY_PHONE_CODE THEN
		SET TEMP_RECORD_CHANGES = 
		`SYSTEM_VAR@CONCAT_ADD`(' | ', TEMP_RECORD_CHANGES, CONCAT_WS(' ', 'Phone Number Area Code: "', TEMP_CAT_MUNICIPALITY_PHONE_CODE, '" > "', PARAM_CAT_MUNICIPALITY_PHONE_CODE, '"'));
	END IF;
	IF TEMP_CAT_MUNICIPALITY_STATUS <> PARAM_CAT_MUNICIPALITY_STATUS THEN
		SET TEMP_RECORD_CHANGES = 
		`SYSTEM_VAR@CONCAT_ADD`(' | ', TEMP_RECORD_CHANGES, CONCAT_WS(' ', 'Status: "', TEMP_CAT_MUNICIPALITY_STATUS, '" > "', PARAM_CAT_MUNICIPALITY_STATUS, '"'));
	END IF;	
	IF TEMP_CAT_MUNICIPALITY_SYSTEM_GENERATED <> PARAM_CAT_MUNICIPALITY_SYSTEM_GENERATED THEN
		SET TEMP_RECORD_CHANGES = 
		`SYSTEM_VAR@CONCAT_ADD`(' | ', TEMP_RECORD_CHANGES, CONCAT_WS(' ', 'System Generated: "', TEMP_CAT_MUNICIPALITY_SYSTEM_GENERATED, '" > "', PARAM_CAT_MUNICIPALITY_SYSTEM_GENERATED, '"'));
	END IF;	
		
	-- No Changes in data, reject request
	-- ####################################################
	IF CHARACTER_LENGTH(TEMP_RECORD_CHANGES) = 0 THEN
		IF PARAM_SUPPRESS_RETURN = 0 THEN
			SELECT PARAM_CAT_MUNICIPALITY_ID AS INSERTED_ID;
		END IF;
		LEAVE SP_SAVE;
	END IF;



	-- 7) VALIDATE
	-- _______________________________________________________________________

	-- Access Rights [Device]
	-- ####################################################
	IF `ACCOUNT_DEVICE@HAS_PERMISSION`(PARAM_REQUESTER_DEVICE_PUBLIC_KEY, PARAM_REQUESTER_DEVICE_PRIVATE_KEY) = 0 THEN
		SET TEMP_ERR_MESSAGE = 'Your device is not authorized yet to access this server.';
		SET ERR = `RAISERROR`(TEMP_ERR_MESSAGE);		
	END IF;
		
		
	-- Access Rights [Account]
	-- ####################################################
	
	IF 
		-- [ADD] Access Rights
		(
			TEMP_RECORD_EXISTS = 0 AND
			`ACCOUNT_ACCESS_RIGHTS@HAS_PERMISSION`(PARAM_REQUESTER_USERNAME, PARAM_REQUESTER_PASSWORD, 0, TEMP_MODULE_KEYWORD, 2) = 0 
		) OR
		
		-- [EDIT] Access Rights
		(
			TEMP_RECORD_EXISTS = 1 AND
			`ACCOUNT_ACCESS_RIGHTS@HAS_PERMISSION`(PARAM_REQUESTER_USERNAME, PARAM_REQUESTER_PASSWORD, 0, TEMP_MODULE_KEYWORD, 3) = 0 
		)
	THEN
		SET TEMP_ACCESS_RIGHTS_DENIED = 1;
		CALL `ACCOUNT_ACCESS_RIGHTS_DENY`
		(
			0, TEMP_MODULE_KEYWORD, PARAM_CAT_MUNICIPALITY_ID, 0, TEMP_SP_OBJECTIVE, TEMP_RECORD_CHANGES, 
			PARAM_REQUESTER_USERNAME, PARAM_REQUESTER_PASSWORD, 
			PARAM_REQUESTER_PROXY_ID, PARAM_REQUESTER_PROXY_PASSWORD,
			PARAM_REQUESTER_DEVICE_PUBLIC_KEY, PARAM_REQUESTER_DEVICE_PRIVATE_KEY,
			PARAM_REQUESTER_IP, PARAM_UNIQUE_SESSION_ID,
			TEMP_SYNC_SERVER_ID, PARAM_SUPPRESS_RETURN
		);
	END IF;
	SET TEMP_ACCESS_RIGHTS_HAS_OVERRIDE = `ACCOUNT_ACCESS_RIGHTS@HAS_PERMISSION`(PARAM_REQUESTER_USERNAME, PARAM_REQUESTER_PASSWORD, 0, TEMP_MODULE_KEYWORD, 4);
	

	-- Validation
	-- ####################################################
	IF TEMP_SYNC_IS_SERVER_REQUEST = 0 THEN
	
		-- SYSTEM GENERATED = TRUE
		-- ...........................................
		IF TEMP_CAT_MUNICIPALITY_SYSTEM_GENERATED = STATUS_ACTIVE THEN
		CALL `VALIDATION_SYSTEM_GENERATED`
		(
			PARAM_CAT_MUNICIPALITY_ID,
			TEMP_CAT_MUNICIPALITY_DESCRIPTION, ''
		);
		END IF;

		-- FOREIGN KEY EXISTS
		-- ...........................................
		IF `CATEGORY_ADDRESS_PROVINCE@CAT_PROVINCE_ID_EXISTS`(PARAM_CAT_MUNICIPALITY_CAT_PROVINCE_ID, 0) =  0 THEN
			SET TEMP_ERR_MESSAGE = CONCAT_WS(' ', 'Given Province does not exists or is inactive. ID: ', PARAM_CAT_MUNICIPALITY_CAT_PROVINCE_ID);
			SET ERR = `RAISERROR`(TEMP_ERR_MESSAGE);
		END IF;
		
		-- FOREIGN (OPTIONAL)KEY EXISTS [Validates if not null]
		-- ...........................................
		
		-- IS_ALLOW_NULL = FALSE
		-- ...........................................
		IF PARAM_CAT_MUNICIPALITY_CODE IS NULL THEN
			CALL `VALIDATION_MISSING_FIELD`('`CAT_MUNICIPALITY_CODE`', '`NULL`');
		END IF;
		IF PARAM_CAT_MUNICIPALITY_ZIP_CODE IS NULL THEN
			CALL `VALIDATION_MISSING_FIELD`('`CAT_MUNICIPALITY_ZIP_CODE`', '`NULL`');
		END IF;
		IF PARAM_CAT_MUNICIPALITY_PHONE_CODE IS NULL THEN
			CALL `VALIDATION_MISSING_FIELD`('`CAT_MUNICIPALITY_PHONE_CODE`', '`NULL`');
		END IF;
				
		-- IS_ALLOW_ZERO = FALSE
		-- ...........................................
		IF PARAM_CAT_MUNICIPALITY_STATUS = 0 THEN
			CALL `VALIDATION_MISSING_FIELD`('`CAT_MUNICIPALITY_STATUS`', '`NULL`');
		END IF;		
		IF PARAM_CAT_MUNICIPALITY_SYSTEM_GENERATED = 0 THEN
			CALL `VALIDATION_MISSING_FIELD`('`CAT_MUNICIPALITY_SYSTEM_GENERATED`', '`NULL`');
		END IF;		
		
		-- IS_ALLOW_NEGATIVE = FALSE
		-- ...........................................
		IF PARAM_CAT_MUNICIPALITY_STATUS < 0 THEN
			CALL `VALIDATION_NEGATIVE`('`CAT_MUNICIPALITY_STATUS`', PARAM_CAT_MUNICIPALITY_STATUS);
		END IF;		
		IF PARAM_CAT_MUNICIPALITY_SYSTEM_GENERATED < 0 THEN
			CALL `VALIDATION_NEGATIVE`('`CAT_MUNICIPALITY_SYSTEM_GENERATED`', PARAM_CAT_MUNICIPALITY_SYSTEM_GENERATED);
		END IF;		
		
		-- IS_ALLOW_EMPTY_STRING = FALSE
		-- ...........................................
		IF `SYSTEM_VAR@IS_NULL@NVARCHAR`(PARAM_CAT_MUNICIPALITY_GLOBAL_ID, 1) = 1 THEN
			CALL `VALIDATION_MISSING_FIELD`('`CAT_MUNICIPALITY_GLOBAL_ID`', '`NULL`');
		END IF;
		IF `SYSTEM_VAR@IS_NULL@NVARCHAR`(PARAM_CAT_MUNICIPALITY_DESCRIPTION, 1) = 1 THEN
			CALL `VALIDATION_MISSING_FIELD`('`CAT_MUNICIPALITY_DESCRIPTION`', '`NULL`');
		END IF;
		
		-- IS_STATUS
		-- ...........................................
		IF `SYSTEM_STATUS@STATUS_ID_EXISTS`(PARAM_CAT_MUNICIPALITY_STATUS, 0) = 0 THEN
			SET TEMP_ERR_MESSAGE = CONCAT_WS(' ', 'Given STATUS[Status] does not exists or is inactive. ID: ', PARAM_CAT_MUNICIPALITY_STATUS);
			SET ERR = `RAISERROR`(TEMP_ERR_MESSAGE);
		END IF;
		
		-- IS STATUS Active / Inactive
		-- ...........................................
		
		-- Minimum / Maximum Value
		-- ...........................................
		
		-- IS_UNIQUE = TRUE
		-- ...........................................
		IF
		(
			SELECT COUNT(`category_address_municipality`.`CAT_MUNICIPALITY_ID`)
			FROM `category_address_municipality`
			WHERE		
				`category_address_municipality`.`CAT_MUNICIPALITY_GLOBAL_ID` = PARAM_CAT_MUNICIPALITY_GLOBAL_ID AND		
				`category_address_municipality`.`CAT_MUNICIPALITY_ID` <> PARAM_CAT_MUNICIPALITY_ID
		) >= 1
		THEN
			CALL `VALIDATION_REDUNDANT_ENTRY`(PARAM_CAT_MUNICIPALITY_DESCRIPTION);
		END IF;
		
		-- RECORD IDENTIFIER
		-- ...........................................
		IF
		(
			SELECT COUNT(`category_address_municipality`.`CAT_MUNICIPALITY_ID`)
			FROM `category_address_municipality`
			WHERE
				`category_address_municipality`.`CAT_MUNICIPALITY_CAT_PROVINCE_ID` = PARAM_CAT_MUNICIPALITY_CAT_PROVINCE_ID AND
				`category_address_municipality`.`CAT_MUNICIPALITY_DESCRIPTION` = PARAM_CAT_MUNICIPALITY_DESCRIPTION AND
				`category_address_municipality`.`CAT_MUNICIPALITY_ID` <> PARAM_CAT_MUNICIPALITY_ID
		) >= 1
		THEN
			CALL `VALIDATION_REDUNDANT_ENTRY`(PARAM_CAT_MUNICIPALITY_DESCRIPTION);
		END IF;
		
		
		-- ON_UPDATE VALIDATION 
		-- ...........................................
		IF TEMP_RECORD_EXISTS = 1 THEN	
		
			-- Just to keep at least one line within condition
			SET TEMP_RECORD_EXISTS = 1;
			
		END IF;
		
	END IF;



	-- 8) INSERT / UPDATE
	-- _______________________________________________________________________

	-- INSERT NEW DATA
	-- ####################################################
	IF TEMP_RECORD_EXISTS = 0 THEN

		INSERT INTO
		`category_address_municipality`
		(
			`category_address_municipality`.`CAT_MUNICIPALITY_GLOBAL_ID`, 
			`category_address_municipality`.`CAT_MUNICIPALITY_CAT_PROVINCE_ID`, 
			`category_address_municipality`.`CAT_MUNICIPALITY_CODE`, 
			`category_address_municipality`.`CAT_MUNICIPALITY_DESCRIPTION`, 
			`category_address_municipality`.`CAT_MUNICIPALITY_ZIP_CODE`, 
			`category_address_municipality`.`CAT_MUNICIPALITY_PHONE_CODE`, 
			`category_address_municipality`.`CAT_MUNICIPALITY_STATUS`, 
			`category_address_municipality`.`CAT_MUNICIPALITY_SYSTEM_GENERATED`
		)
		VALUES
		(
			PARAM_CAT_MUNICIPALITY_GLOBAL_ID, 
			PARAM_CAT_MUNICIPALITY_CAT_PROVINCE_ID, 
			PARAM_CAT_MUNICIPALITY_CODE, 
			PARAM_CAT_MUNICIPALITY_DESCRIPTION, 
			PARAM_CAT_MUNICIPALITY_ZIP_CODE, 
			PARAM_CAT_MUNICIPALITY_PHONE_CODE, 
			PARAM_CAT_MUNICIPALITY_STATUS, 
			PARAM_CAT_MUNICIPALITY_SYSTEM_GENERATED
		);	
		
		-- Update Audit trail with new ID	
		SET PARAM_CAT_MUNICIPALITY_ID = LAST_INSERT_ID();



	-- UPDATING EXISTING RECORD
	-- ####################################################
	ELSE
		UPDATE `category_address_municipality`
		SET
			`category_address_municipality`.`CAT_MUNICIPALITY_GLOBAL_ID` = PARAM_CAT_MUNICIPALITY_GLOBAL_ID, 
			`category_address_municipality`.`CAT_MUNICIPALITY_CAT_PROVINCE_ID` = PARAM_CAT_MUNICIPALITY_CAT_PROVINCE_ID, 
			`category_address_municipality`.`CAT_MUNICIPALITY_CODE` = PARAM_CAT_MUNICIPALITY_CODE, 
			`category_address_municipality`.`CAT_MUNICIPALITY_DESCRIPTION` = PARAM_CAT_MUNICIPALITY_DESCRIPTION, 
			`category_address_municipality`.`CAT_MUNICIPALITY_ZIP_CODE` = PARAM_CAT_MUNICIPALITY_ZIP_CODE, 
			`category_address_municipality`.`CAT_MUNICIPALITY_PHONE_CODE` = PARAM_CAT_MUNICIPALITY_PHONE_CODE, 
			`category_address_municipality`.`CAT_MUNICIPALITY_STATUS` = PARAM_CAT_MUNICIPALITY_STATUS, 
			`category_address_municipality`.`CAT_MUNICIPALITY_SYSTEM_GENERATED` = PARAM_CAT_MUNICIPALITY_SYSTEM_GENERATED
		WHERE
			`category_address_municipality`.`CAT_MUNICIPALITY_ID` = PARAM_CAT_MUNICIPALITY_ID;

	END IF;

	
	-- 9) AUDIT TRAIL
	-- _______________________________________________________________________
	CALL `ACCOUNT_AUDIT_TRAIL_SAVE`
	(
		0, TEMP_MODULE_KEYWORD, PARAM_CAT_MUNICIPALITY_ID, 0, 'SAVE', TEMP_SP_OBJECTIVE, TEMP_RECORD_CHANGES, 
		PARAM_REQUESTER_USERNAME, PARAM_REQUESTER_PASSWORD, 
		PARAM_REQUESTER_PROXY_ID, PARAM_REQUESTER_PROXY_PASSWORD,
		PARAM_REQUESTER_DEVICE_PUBLIC_KEY, PARAM_REQUESTER_DEVICE_PRIVATE_KEY,
		PARAM_REQUESTER_IP, PARAM_UNIQUE_SESSION_ID,
		TEMP_SYNC_SERVER_ID, PARAM_SUPPRESS_RETURN
	);
	

	-- 10) RETURN RESULT
	-- _______________________________________________________________________
	IF PARAM_SUPPRESS_RETURN = 0 THEN
		SELECT PARAM_CAT_MUNICIPALITY_ID AS INSERTED_ID;
	END IF;
	LEAVE SP_SAVE;


END ;;
DELIMITER ;
/*!50003 SET sql_mode              = @saved_sql_mode */ ;
/*!50003 SET character_set_client  = @saved_cs_client */ ;
/*!50003 SET character_set_results = @saved_cs_results */ ;
/*!50003 SET collation_connection  = @saved_col_connection */ ;
/*!50003 DROP PROCEDURE IF EXISTS `CATEGORY_ADDRESS_PROVINCE_DELETE` */;
/*!50003 SET @saved_cs_client      = @@character_set_client */ ;
/*!50003 SET @saved_cs_results     = @@character_set_results */ ;
/*!50003 SET @saved_col_connection = @@collation_connection */ ;
/*!50003 SET character_set_client  = latin1 */ ;
/*!50003 SET character_set_results = latin1 */ ;
/*!50003 SET collation_connection  = latin1_swedish_ci */ ;
/*!50003 SET @saved_sql_mode       = @@sql_mode */ ;
/*!50003 SET sql_mode              = '' */ ;
DELIMITER ;;
CREATE DEFINER=`root`@`localhost` PROCEDURE `CATEGORY_ADDRESS_PROVINCE_DELETE`(
	IN `PARAM_CAT_PROVINCE_ID` BIGINT,

	IN `PARAM_REQUESTER_USERNAME` VARCHAR(500),
	IN `PARAM_REQUESTER_PASSWORD` VARCHAR(500),
	IN `PARAM_REQUESTER_PROXY_ID` BIGINT,
	IN `PARAM_REQUESTER_PROXY_PASSWORD` VARCHAR(1000),
	IN `PARAM_REQUESTER_DEVICE_PUBLIC_KEY` VARCHAR(1000),
	IN `PARAM_REQUESTER_DEVICE_PRIVATE_KEY` VARCHAR(1000),
	
	IN `PARAM_REQUESTER_IP` VARCHAR(1000),
	IN `PARAM_UNIQUE_SESSION_ID` VARCHAR(1000),
	IN `PARAM_SUPPRESS_RETURN` BIT,
	
	IN `PARAM_SYNC_SERVER_DESCRIPTION` VARCHAR(500), 
	IN `PARAM_SYNC_SERVER_UNIQUE_KEY` VARCHAR(500)
)
SP_DELETE:
BEGIN

	-- 1) DECLARE LOCAL PARAMETERS
	-- _______________________________________________________________________
	
	-- Status
	-- ...........................................
	DECLARE STATUS_INACTIVE TINYINT DEFAULT 1;
	DECLARE STATUS_ACTIVE TINYINT DEFAULT 2;
	DECLARE STATUS_CLOSED TINYINT DEFAULT 3;
	DECLARE STATUS_COMPLETED TINYINT DEFAULT 4;
	
	-- Audit Handler
	-- ...........................................
	DECLARE TEMP_RECORD_EXISTS BIT DEFAULT 0;
	DECLARE TEMP_MODULE_KEYWORD VARCHAR(500) DEFAULT 'category_address_province';
	DECLARE TEMP_SP_OBJECTIVE VARCHAR(500) DEFAULT 'delete Address: Province record';
	DECLARE TEMP_ERR_MESSAGE VARCHAR(500) DEFAULT '';
	DECLARE ERR BIGINT DEFAULT 0;
	DECLARE TEMP_RECORD_CHANGES VARCHAR(16000) DEFAULT '';
	DECLARE TEMP_RECORD_BINDED BIT DEFAULT 0;
	
	DECLARE TEMP_RECORD_BINDED_ID BIGINT DEFAULT 0;
	DECLARE TEMP_RECORD_BINDED_SERVER_ID BIGINT DEFAULT 0;
	
	-- Authentication
	-- ...........................................
	DECLARE TEMP_ACCESS_RIGHTS_DENIED BIT DEFAULT 0;
	DECLARE TEMP_SYNC_SERVER_ID BIGINT DEFAULT 0;
	DECLARE TEMP_SYNC_IS_SERVER_REQUEST BIT DEFAULT 0;
	DECLARE TEMP_AUTHENTICATED_ACCOUNT_ID BIGINT DEFAULT `ACCOUNT_MEMBER@ACC_ACCOUNT_ID_FROM_LOGIN`(PARAM_REQUESTER_USERNAME, PARAM_REQUESTER_PASSWORD);
	DECLARE TEMP_AUTHENTICATED_ACCOUNT_LEVEL BIGINT DEFAULT 0;
	DECLARE TEMP_AUTHENTICATED_ACCOUNT_GROUP BIGINT DEFAULT 0;

	-- Local value holder
	-- ...........................................
		DECLARE TEMP_CAT_PROVINCE_GLOBAL_ID VARCHAR(400) DEFAULT ''; 
		DECLARE TEMP_CAT_PROVINCE_CAT_REGION_ID BIGINT DEFAULT 0; 
		DECLARE TEMP_CAT_PROVINCE_CODE VARCHAR(50) DEFAULT ''; 
		DECLARE TEMP_CAT_PROVINCE_DESCRIPTION VARCHAR(500) DEFAULT ''; 
		DECLARE TEMP_CAT_PROVINCE_STATUS TINYINT DEFAULT 0; 
		DECLARE TEMP_CAT_PROVINCE_SYSTEM_GENERATED TINYINT DEFAULT 0; 

	
	
	-- 2) Try Catch / Throw
	-- _______________________________________________________________________
	DECLARE EXIT HANDLER FOR SQLEXCEPTION
	BEGIN
		RESIGNAL;
	END;

	
	-- 3) Prepare SYNC
	-- _______________________________________________________________________
	
	-- IS RECORD EXISTS		
	-- ####################################################		
	SET TEMP_RECORD_EXISTS = `CATEGORY_ADDRESS_PROVINCE@CAT_PROVINCE_ID_EXISTS`(PARAM_CAT_PROVINCE_ID, 0);


	-- 4) IF ALREADY EXIST, FILL MISSING DATA
	-- _______________________________________________________________________
	IF TEMP_RECORD_EXISTS = 1 THEN
		SELECT
				`category_address_province`.`CAT_PROVINCE_GLOBAL_ID`, 	
				`category_address_province`.`CAT_PROVINCE_CAT_REGION_ID`, 	
				`category_address_province`.`CAT_PROVINCE_CODE`, 	
				`category_address_province`.`CAT_PROVINCE_DESCRIPTION`, 	
				`category_address_province`.`CAT_PROVINCE_STATUS`, 	
				`category_address_province`.`CAT_PROVINCE_SYSTEM_GENERATED`	
		INTO
				TEMP_CAT_PROVINCE_GLOBAL_ID, 	
				TEMP_CAT_PROVINCE_CAT_REGION_ID, 	
				TEMP_CAT_PROVINCE_CODE, 	
				TEMP_CAT_PROVINCE_DESCRIPTION, 	
				TEMP_CAT_PROVINCE_STATUS, 	
				TEMP_CAT_PROVINCE_SYSTEM_GENERATED	

		FROM `category_address_province`
		WHERE
			`category_address_province`.`CAT_PROVINCE_ID` = PARAM_CAT_PROVINCE_ID
		LIMIT 1;

	ELSE 
		IF TEMP_SYNC_IS_SERVER_REQUEST = 0 THEN
			SET TEMP_ERR_MESSAGE = CONCAT_WS(' ', 'Given Address: Province does not exists or is inactive. ID:', PARAM_CAT_PROVINCE_ID);
			SET ERR = `RAISERROR`(TEMP_ERR_MESSAGE);		
		END IF;
		LEAVE SP_DELETE;
		
	END IF;



	-- 5) PREPARE AUDIT TRAIL
	-- _______________________________________________________________________
	
		SET TEMP_RECORD_CHANGES = 
		`SYSTEM_VAR@CONCAT_ADD`(' | ', TEMP_RECORD_CHANGES, CONCAT_WS(' ', 'Sync ID: "', TEMP_CAT_PROVINCE_GLOBAL_ID, '" > " DELETED "'));
		SET TEMP_RECORD_CHANGES = 
		`SYSTEM_VAR@CONCAT_ADD`(' | ', TEMP_RECORD_CHANGES, CONCAT_WS(' ', 'Region: "', TEMP_CAT_PROVINCE_CAT_REGION_ID, '" > " DELETED "'));
		SET TEMP_RECORD_CHANGES = 
		`SYSTEM_VAR@CONCAT_ADD`(' | ', TEMP_RECORD_CHANGES, CONCAT_WS(' ', 'Short Code: "', TEMP_CAT_PROVINCE_CODE, '" > " DELETED "'));
		SET TEMP_RECORD_CHANGES = 
		`SYSTEM_VAR@CONCAT_ADD`(' | ', TEMP_RECORD_CHANGES, CONCAT_WS(' ', 'Description: "', TEMP_CAT_PROVINCE_DESCRIPTION, '" > " DELETED "'));
		SET TEMP_RECORD_CHANGES = 
		`SYSTEM_VAR@CONCAT_ADD`(' | ', TEMP_RECORD_CHANGES, CONCAT_WS(' ', 'Status: "', TEMP_CAT_PROVINCE_STATUS, '" > " DELETED "'));
		SET TEMP_RECORD_CHANGES = 
		`SYSTEM_VAR@CONCAT_ADD`(' | ', TEMP_RECORD_CHANGES, CONCAT_WS(' ', 'System Generated: "', TEMP_CAT_PROVINCE_SYSTEM_GENERATED, '" > " DELETED "'));


	-- 6) VALIDATE
	-- _______________________________________________________________________
	
	-- Access Rights [Device]
	-- ####################################################
	IF `ACCOUNT_DEVICE@HAS_PERMISSION`(PARAM_REQUESTER_DEVICE_PUBLIC_KEY, PARAM_REQUESTER_DEVICE_PRIVATE_KEY) = 0 THEN
		SET TEMP_ERR_MESSAGE = 'Your device is not authorized yet to access this server.';
		SET ERR = `RAISERROR`(TEMP_ERR_MESSAGE);		
	END IF;
		
		
	-- Access Rights [Account]
	-- ####################################################	
	
	IF 
		-- [DELETE] Access Rights
		`ACCOUNT_ACCESS_RIGHTS@HAS_PERMISSION`(PARAM_REQUESTER_USERNAME, PARAM_REQUESTER_PASSWORD, 0, TEMP_MODULE_KEYWORD, 4) = 0 
	THEN
		SET TEMP_ACCESS_RIGHTS_DENIED = 1;
		CALL `ACCOUNT_ACCESS_RIGHTS_DENY`
		(
			0, TEMP_MODULE_KEYWORD, PARAM_CAT_PROVINCE_ID, 0, TEMP_SP_OBJECTIVE, TEMP_RECORD_CHANGES, 
			PARAM_REQUESTER_USERNAME, PARAM_REQUESTER_PASSWORD, 
			PARAM_REQUESTER_PROXY_ID, PARAM_REQUESTER_PROXY_PASSWORD,
			PARAM_REQUESTER_DEVICE_PUBLIC_KEY, PARAM_REQUESTER_DEVICE_PRIVATE_KEY,
			PARAM_REQUESTER_IP, PARAM_UNIQUE_SESSION_ID,
			TEMP_SYNC_SERVER_ID, PARAM_SUPPRESS_RETURN
		);
	END IF;

	-- System Generated Record (Cannot be deleted)
	-- ####################################################
	IF TEMP_CAT_PROVINCE_SYSTEM_GENERATED = STATUS_ACTIVE THEN
		CALL `VALIDATION_SYSTEM_GENERATED`
		(
			PARAM_CAT_PROVINCE_ID,
			TEMP_CAT_PROVINCE_DESCRIPTION, ''
		);
	END IF;
	
	-- If already used, cannot remove record
	-- ####################################################
	IF
	(
		SELECT
			COUNT(`category_address_municipality`.`CAT_MUNICIPALITY_CAT_PROVINCE_ID`)
		FROM `category_address_municipality`
		WHERE
			`category_address_municipality`.`CAT_MUNICIPALITY_CAT_PROVINCE_ID` = PARAM_CAT_PROVINCE_ID
		LIMIT 1
	) >= 1 
	THEN
		SET TEMP_RECORD_BINDED = 1;
		SET TEMP_ERR_MESSAGE = 'Address: Municipality Record';
	END IF;
	IF
	(
		SELECT
			COUNT(`category_branch`.`CAT_BRANCH_CAT_PROVINCE_ID`)
		FROM `category_branch`
		WHERE
			`category_branch`.`CAT_BRANCH_CAT_PROVINCE_ID` = PARAM_CAT_PROVINCE_ID
		LIMIT 1
	) >= 1 
	THEN
		SET TEMP_RECORD_BINDED = 1;
		SET TEMP_ERR_MESSAGE = 'Branch Record';
	END IF;
	IF
	(
		SELECT
			COUNT(`record_combatants`.`REC_COMBATANT_CAT_PROVINCE_ID`)
		FROM `record_combatants`
		WHERE
			`record_combatants`.`REC_COMBATANT_CAT_PROVINCE_ID` = PARAM_CAT_PROVINCE_ID
		LIMIT 1
	) >= 1 
	THEN
		SET TEMP_RECORD_BINDED = 1;
		SET TEMP_ERR_MESSAGE = 'Combatant Information Record';
	END IF;

	-- Leave Re-upload request
	-- ####################################################
	IF TEMP_RECORD_BINDED = 1 THEN
		IF TEMP_SYNC_IS_SERVER_REQUEST = 1 THEN
			
			LEAVE SP_DELETE;
		END IF;

		CALL `VALIDATION_DELETE_LINKED_RECORD`(TEMP_CAT_PROVINCE_DESCRIPTION, '', TEMP_ERR_MESSAGE); 
	END IF;


	-- 7) DELETE
	-- _______________________________________________________________________
	DELETE FROM `category_address_province`
	WHERE `category_address_province`.`CAT_PROVINCE_ID` = PARAM_CAT_PROVINCE_ID
	LIMIT 1;


	-- 8) AUDIT TRAIL
	-- _______________________________________________________________________
	CALL `ACCOUNT_AUDIT_TRAIL_SAVE`
	(
		0, TEMP_MODULE_KEYWORD, PARAM_CAT_PROVINCE_ID, 0, 'DELETE', TEMP_SP_OBJECTIVE, TEMP_RECORD_CHANGES, 
		PARAM_REQUESTER_USERNAME, PARAM_REQUESTER_PASSWORD, 
		PARAM_REQUESTER_PROXY_ID, PARAM_REQUESTER_PROXY_PASSWORD,
		PARAM_REQUESTER_DEVICE_PUBLIC_KEY, PARAM_REQUESTER_DEVICE_PRIVATE_KEY,
		PARAM_REQUESTER_IP, PARAM_UNIQUE_SESSION_ID,
		TEMP_SYNC_SERVER_ID, PARAM_SUPPRESS_RETURN
	);

END ;;
DELIMITER ;
/*!50003 SET sql_mode              = @saved_sql_mode */ ;
/*!50003 SET character_set_client  = @saved_cs_client */ ;
/*!50003 SET character_set_results = @saved_cs_results */ ;
/*!50003 SET collation_connection  = @saved_col_connection */ ;
/*!50003 DROP PROCEDURE IF EXISTS `CATEGORY_ADDRESS_PROVINCE_GET` */;
/*!50003 SET @saved_cs_client      = @@character_set_client */ ;
/*!50003 SET @saved_cs_results     = @@character_set_results */ ;
/*!50003 SET @saved_col_connection = @@collation_connection */ ;
/*!50003 SET character_set_client  = latin1 */ ;
/*!50003 SET character_set_results = latin1 */ ;
/*!50003 SET collation_connection  = latin1_swedish_ci */ ;
/*!50003 SET @saved_sql_mode       = @@sql_mode */ ;
/*!50003 SET sql_mode              = '' */ ;
DELIMITER ;;
CREATE DEFINER=`root`@`localhost` PROCEDURE `CATEGORY_ADDRESS_PROVINCE_GET`(
	IN `PARAM_CAT_PROVINCE_ID` BIGINT,	
	IN `PARAM_CAT_PROVINCE_GLOBAL_ID` VARCHAR(400),	
	IN `PARAM_CAT_PROVINCE_CAT_REGION_ID` BIGINT,	
	IN `PARAM_CAT_PROVINCE_CODE` VARCHAR(50),	
	IN `PARAM_CAT_PROVINCE_DESCRIPTION` VARCHAR(500),	
	IN `PARAM_CAT_PROVINCE_STATUS` TINYINT,	
	IN `PARAM_CAT_PROVINCE_SYSTEM_GENERATED` TINYINT,	
		
	IN `PARAM_ORDER_FIELD` VARCHAR(500),
	IN `PARAM_ORDER_TYPE` VARCHAR(500),
	IN `PARAM_SKIP` BIGINT,
	IN `PARAM_LIMIT` BIGINT,

	IN `PARAM_REQUESTER_USERNAME` VARCHAR(500),
	IN `PARAM_REQUESTER_PASSWORD` VARCHAR(500),
	IN `PARAM_REQUESTER_PROXY_ID` BIGINT,
	IN `PARAM_REQUESTER_PROXY_PASSWORD` VARCHAR(1000),
	IN `PARAM_REQUESTER_DEVICE_PUBLIC_KEY` VARCHAR(1000),
	IN `PARAM_REQUESTER_DEVICE_PRIVATE_KEY` VARCHAR(1000),
	
	IN `PARAM_REQUESTER_IP` VARCHAR(1000),
	IN `PARAM_UNIQUE_SESSION_ID` VARCHAR(1000),
	IN `PARAM_SUPPRESS_RETURN` BIT
)
SP_GET:
BEGIN

	-- Status
	-- =========================================================================================
	DECLARE STATUS_INACTIVE TINYINT DEFAULT 1;
	DECLARE STATUS_ACTIVE TINYINT DEFAULT 2;
	DECLARE STATUS_CLOSED TINYINT DEFAULT 3;
	DECLARE STATUS_COMPLETED TINYINT DEFAULT 4;
	
	-- Audit Handler
	-- =========================================================================================
	DECLARE TEMP_RECORD_EXISTS BIT DEFAULT 0;
	DECLARE TEMP_MODULE_KEYWORD VARCHAR(500) DEFAULT 'category_address_province';
	DECLARE TEMP_SP_OBJECTIVE VARCHAR(500) DEFAULT 'Retrieve Address: Province record';
	DECLARE TEMP_ERR_MESSAGE VARCHAR(500) DEFAULT '';
	DECLARE ERR BIGINT DEFAULT 0;
	DECLARE TEMP_RECORD_CHANGES VARCHAR(16000) DEFAULT '';
	DECLARE TEMP_RECORD_BINDED BIT DEFAULT 0;
	
	DECLARE TEMP_RECORD_BINDED_ID BIGINT DEFAULT 0;
	DECLARE TEMP_RECORD_BINDED_SERVER_ID BIGINT DEFAULT 0;
	
	-- Authentication
	-- =========================================================================================
	DECLARE TEMP_ACCESS_RIGHTS_DENIED BIT DEFAULT 0;
	DECLARE TEMP_AUTHENTICATED_ACCOUNT_ID BIGINT DEFAULT `ACCOUNT_MEMBER@ACC_ACCOUNT_ID_FROM_LOGIN`(PARAM_REQUESTER_USERNAME, PARAM_REQUESTER_PASSWORD);
	DECLARE TEMP_AUTHENTICATED_ACCOUNT_LEVEL BIGINT DEFAULT 0;
	DECLARE TEMP_AUTHENTICATED_ACCOUNT_GROUP BIGINT DEFAULT 0;
	
	-- Local Parameters
	-- =========================================================================================
	DECLARE TEMP_NOW DATETIME(6) DEFAULT `SYSTEM_VAR@NOW`('', 1);
	DECLARE TEMP_RECORD_COUNT BIGINT DEFAULT 0;
	
	
	-- Check NULLs
	-- =========================================================================================
	DECLARE IS_NULL_CAT_PROVINCE_ID BIT DEFAULT `SYSTEM_VAR@IS_NULL@BIGINT`(PARAM_CAT_PROVINCE_ID, 1, 1);
	DECLARE IS_NULL_CAT_PROVINCE_GLOBAL_ID BIT DEFAULT `SYSTEM_VAR@IS_NULL@NVARCHAR`(PARAM_CAT_PROVINCE_GLOBAL_ID, 1);
	DECLARE IS_NULL_CAT_PROVINCE_CAT_REGION_ID BIT DEFAULT `SYSTEM_VAR@IS_NULL@BIGINT`(PARAM_CAT_PROVINCE_CAT_REGION_ID, 1, 1);
	DECLARE IS_NULL_CAT_PROVINCE_CODE BIT DEFAULT `SYSTEM_VAR@IS_NULL@NVARCHAR`(PARAM_CAT_PROVINCE_CODE, 0);
	DECLARE IS_NULL_CAT_PROVINCE_DESCRIPTION BIT DEFAULT `SYSTEM_VAR@IS_NULL@NVARCHAR`(PARAM_CAT_PROVINCE_DESCRIPTION, 1);
	DECLARE IS_NULL_CAT_PROVINCE_STATUS BIT DEFAULT `SYSTEM_VAR@IS_NULL@TINYINT`(PARAM_CAT_PROVINCE_STATUS, 1, 1);
	DECLARE IS_NULL_CAT_PROVINCE_SYSTEM_GENERATED BIT DEFAULT `SYSTEM_VAR@IS_NULL@TINYINT`(PARAM_CAT_PROVINCE_SYSTEM_GENERATED, 1, 1);
	
	-- Error Handler
	-- =========================================================================================
	DECLARE EXIT HANDLER FOR SQLEXCEPTION
	BEGIN
		RESIGNAL;
	END;
	
	-- Ignore Time from DateTime (Set Time 00:00:00.000000 and 23:59:59.999999)
	-- =========================================================================================
		
		
	-- Access Rights [Device]
	-- =========================================================================================
	IF `ACCOUNT_DEVICE@HAS_PERMISSION`(PARAM_REQUESTER_DEVICE_PUBLIC_KEY, PARAM_REQUESTER_DEVICE_PRIVATE_KEY) = 0 THEN
		SET TEMP_ERR_MESSAGE = 'Your device is not authorized yet to access this server.';
		SET ERR = `RAISERROR`(TEMP_ERR_MESSAGE);		
	END IF;
		
		
	-- Access Rights [Account]
	-- =========================================================================================
		
	
	
	
	-- COUNT RECORD
	-- =========================================================================================
	
	-- SELECT COLUMNS
	-- ####################################################
	SELECT
		COUNT(DISTINCT `category_address_province`.`CAT_PROVINCE_ID`)
	INTO
		TEMP_RECORD_COUNT

	FROM `category_address_province`
	
		-- Add Inner Joins (Per Foreign-key)
		INNER JOIN `category_address_region` ON
		`category_address_region`.`CAT_REGION_ID` = `category_address_province`.`CAT_PROVINCE_CAT_REGION_ID`
		
		-- Add Optional Left Joins (Per Optional Foreign-key)
		
	-- CONDITIONS
	-- ####################################################
	WHERE
		(
			IS_NULL_CAT_PROVINCE_ID = 1 OR
			`category_address_province`.`CAT_PROVINCE_ID` = PARAM_CAT_PROVINCE_ID			
		) AND
		(
			IS_NULL_CAT_PROVINCE_GLOBAL_ID = 1 OR
			`category_address_province`.`CAT_PROVINCE_GLOBAL_ID` LIKE CONCAT_WS('%', '', PARAM_CAT_PROVINCE_GLOBAL_ID, '')			
		) AND 		
		(
			IS_NULL_CAT_PROVINCE_CAT_REGION_ID = 1 OR
			`category_address_province`.`CAT_PROVINCE_CAT_REGION_ID` = PARAM_CAT_PROVINCE_CAT_REGION_ID			
		) AND
		(
			IS_NULL_CAT_PROVINCE_CODE = 1 OR
			`category_address_province`.`CAT_PROVINCE_CODE` LIKE CONCAT_WS('%', '', PARAM_CAT_PROVINCE_CODE, '')			
		) AND 		
		(
			IS_NULL_CAT_PROVINCE_DESCRIPTION = 1 OR
			`category_address_province`.`CAT_PROVINCE_DESCRIPTION` LIKE CONCAT_WS('%', '', PARAM_CAT_PROVINCE_DESCRIPTION, '')			
		) AND 		
		(
			IS_NULL_CAT_PROVINCE_STATUS = 1 OR
			`category_address_province`.`CAT_PROVINCE_STATUS` = PARAM_CAT_PROVINCE_STATUS			
		) AND
		(
			IS_NULL_CAT_PROVINCE_SYSTEM_GENERATED = 1 OR
			`category_address_province`.`CAT_PROVINCE_SYSTEM_GENERATED` = PARAM_CAT_PROVINCE_SYSTEM_GENERATED			
		) 
;	

		
		
	-- SELECT RECORDS
	-- =========================================================================================
	
	-- FETCH COLUMNS
	-- ####################################################
	SELECT
		-- CATEGORY_ADDRESS_PROVINCE DETAILS
		`category_address_province`.`CAT_PROVINCE_ID`, 
		`category_address_province`.`CAT_PROVINCE_GLOBAL_ID`, 
		`category_address_province`.`CAT_PROVINCE_CAT_REGION_ID`, 
		`category_address_province`.`CAT_PROVINCE_CODE`, 
		`category_address_province`.`CAT_PROVINCE_DESCRIPTION`, 
		`category_address_province`.`CAT_PROVINCE_STATUS`, 
		`category_address_province`.`CAT_PROVINCE_SYSTEM_GENERATED`
		
		-- Inner join fields
		, 
		`category_address_region`.`CAT_REGION_ID`, 
		`category_address_region`.`CAT_REGION_GLOBAL_ID`, 
		`category_address_region`.`CAT_REGION_CAT_COUNTRY_ID`, 
		`category_address_region`.`CAT_REGION_CODE`, 
		`category_address_region`.`CAT_REGION_DESCRIPTION`, 
		`category_address_region`.`CAT_REGION_STATUS`, 
		`category_address_region`.`CAT_REGION_SYSTEM_GENERATED`
		
		-- Left join fields
		
		, TEMP_RECORD_COUNT AS RECORD_COUNT

	FROM `category_address_province`
	
		-- Add Inner Joins (Per Foreign-key)
		INNER JOIN `category_address_region` ON
		`category_address_region`.`CAT_REGION_ID` = `category_address_province`.`CAT_PROVINCE_CAT_REGION_ID`
		
		-- Add Optional Left Joins (Per Optional Foreign-key)
		
	-- CONDITIONS
	-- ####################################################
	WHERE
		(
			IS_NULL_CAT_PROVINCE_ID = 1 OR
			`category_address_province`.`CAT_PROVINCE_ID` = PARAM_CAT_PROVINCE_ID			
		) AND
		(
			IS_NULL_CAT_PROVINCE_GLOBAL_ID = 1 OR
			`category_address_province`.`CAT_PROVINCE_GLOBAL_ID` LIKE CONCAT_WS('%', '', PARAM_CAT_PROVINCE_GLOBAL_ID, '')			
		) AND 		
		(
			IS_NULL_CAT_PROVINCE_CAT_REGION_ID = 1 OR
			`category_address_province`.`CAT_PROVINCE_CAT_REGION_ID` = PARAM_CAT_PROVINCE_CAT_REGION_ID			
		) AND
		(
			IS_NULL_CAT_PROVINCE_CODE = 1 OR
			`category_address_province`.`CAT_PROVINCE_CODE` LIKE CONCAT_WS('%', '', PARAM_CAT_PROVINCE_CODE, '')			
		) AND 		
		(
			IS_NULL_CAT_PROVINCE_DESCRIPTION = 1 OR
			`category_address_province`.`CAT_PROVINCE_DESCRIPTION` LIKE CONCAT_WS('%', '', PARAM_CAT_PROVINCE_DESCRIPTION, '')			
		) AND 		
		(
			IS_NULL_CAT_PROVINCE_STATUS = 1 OR
			`category_address_province`.`CAT_PROVINCE_STATUS` = PARAM_CAT_PROVINCE_STATUS			
		) AND
		(
			IS_NULL_CAT_PROVINCE_SYSTEM_GENERATED = 1 OR
			`category_address_province`.`CAT_PROVINCE_SYSTEM_GENERATED` = PARAM_CAT_PROVINCE_SYSTEM_GENERATED			
		) 

	-- ORDER BY
	-- ####################################################
	ORDER BY
		-- CATEGORY_ADDRESS_PROVINCE DETAILS
		CASE WHEN PARAM_ORDER_FIELD = 'CAT_PROVINCE_ID' AND PARAM_ORDER_TYPE = 'ASC' THEN `category_address_province`.`CAT_PROVINCE_ID` END ASC, 
		CASE WHEN PARAM_ORDER_FIELD = 'CAT_PROVINCE_ID' AND PARAM_ORDER_TYPE = 'DESC' THEN `category_address_province`.`CAT_PROVINCE_ID` END DESC,	
		CASE WHEN PARAM_ORDER_FIELD = 'CAT_PROVINCE_GLOBAL_ID' AND PARAM_ORDER_TYPE = 'ASC' THEN `category_address_province`.`CAT_PROVINCE_GLOBAL_ID` END ASC, 
		CASE WHEN PARAM_ORDER_FIELD = 'CAT_PROVINCE_GLOBAL_ID' AND PARAM_ORDER_TYPE = 'DESC' THEN `category_address_province`.`CAT_PROVINCE_GLOBAL_ID` END DESC,	
		CASE WHEN PARAM_ORDER_FIELD = 'CAT_PROVINCE_CAT_REGION_ID' AND PARAM_ORDER_TYPE = 'ASC' THEN `category_address_province`.`CAT_PROVINCE_CAT_REGION_ID` END ASC, 
		CASE WHEN PARAM_ORDER_FIELD = 'CAT_PROVINCE_CAT_REGION_ID' AND PARAM_ORDER_TYPE = 'DESC' THEN `category_address_province`.`CAT_PROVINCE_CAT_REGION_ID` END DESC,	
		CASE WHEN PARAM_ORDER_FIELD = 'CAT_PROVINCE_CODE' AND PARAM_ORDER_TYPE = 'ASC' THEN `category_address_province`.`CAT_PROVINCE_CODE` END ASC, 
		CASE WHEN PARAM_ORDER_FIELD = 'CAT_PROVINCE_CODE' AND PARAM_ORDER_TYPE = 'DESC' THEN `category_address_province`.`CAT_PROVINCE_CODE` END DESC,	
		CASE WHEN PARAM_ORDER_FIELD = 'CAT_PROVINCE_DESCRIPTION' AND PARAM_ORDER_TYPE = 'ASC' THEN `category_address_province`.`CAT_PROVINCE_DESCRIPTION` END ASC, 
		CASE WHEN PARAM_ORDER_FIELD = 'CAT_PROVINCE_DESCRIPTION' AND PARAM_ORDER_TYPE = 'DESC' THEN `category_address_province`.`CAT_PROVINCE_DESCRIPTION` END DESC,	
		CASE WHEN PARAM_ORDER_FIELD = 'CAT_PROVINCE_STATUS' AND PARAM_ORDER_TYPE = 'ASC' THEN `category_address_province`.`CAT_PROVINCE_STATUS` END ASC, 
		CASE WHEN PARAM_ORDER_FIELD = 'CAT_PROVINCE_STATUS' AND PARAM_ORDER_TYPE = 'DESC' THEN `category_address_province`.`CAT_PROVINCE_STATUS` END DESC,	
		CASE WHEN PARAM_ORDER_FIELD = 'CAT_PROVINCE_SYSTEM_GENERATED' AND PARAM_ORDER_TYPE = 'ASC' THEN `category_address_province`.`CAT_PROVINCE_SYSTEM_GENERATED` END ASC, 
		CASE WHEN PARAM_ORDER_FIELD = 'CAT_PROVINCE_SYSTEM_GENERATED' AND PARAM_ORDER_TYPE = 'DESC' THEN `category_address_province`.`CAT_PROVINCE_SYSTEM_GENERATED` END DESC,	

		-- Inner joins
		CASE WHEN PARAM_ORDER_FIELD = 'CAT_REGION_ID' AND PARAM_ORDER_TYPE = 'ASC' THEN `category_address_region`.`CAT_REGION_ID` END ASC, 
		CASE WHEN PARAM_ORDER_FIELD = 'CAT_REGION_ID' AND PARAM_ORDER_TYPE = 'DESC' THEN `category_address_region`.`CAT_REGION_ID` END DESC,	
		CASE WHEN PARAM_ORDER_FIELD = 'CAT_REGION_GLOBAL_ID' AND PARAM_ORDER_TYPE = 'ASC' THEN `category_address_region`.`CAT_REGION_GLOBAL_ID` END ASC, 
		CASE WHEN PARAM_ORDER_FIELD = 'CAT_REGION_GLOBAL_ID' AND PARAM_ORDER_TYPE = 'DESC' THEN `category_address_region`.`CAT_REGION_GLOBAL_ID` END DESC,	
		CASE WHEN PARAM_ORDER_FIELD = 'CAT_REGION_CAT_COUNTRY_ID' AND PARAM_ORDER_TYPE = 'ASC' THEN `category_address_region`.`CAT_REGION_CAT_COUNTRY_ID` END ASC, 
		CASE WHEN PARAM_ORDER_FIELD = 'CAT_REGION_CAT_COUNTRY_ID' AND PARAM_ORDER_TYPE = 'DESC' THEN `category_address_region`.`CAT_REGION_CAT_COUNTRY_ID` END DESC,	
		CASE WHEN PARAM_ORDER_FIELD = 'CAT_REGION_CODE' AND PARAM_ORDER_TYPE = 'ASC' THEN `category_address_region`.`CAT_REGION_CODE` END ASC, 
		CASE WHEN PARAM_ORDER_FIELD = 'CAT_REGION_CODE' AND PARAM_ORDER_TYPE = 'DESC' THEN `category_address_region`.`CAT_REGION_CODE` END DESC,	
		CASE WHEN PARAM_ORDER_FIELD = 'CAT_REGION_DESCRIPTION' AND PARAM_ORDER_TYPE = 'ASC' THEN `category_address_region`.`CAT_REGION_DESCRIPTION` END ASC, 
		CASE WHEN PARAM_ORDER_FIELD = 'CAT_REGION_DESCRIPTION' AND PARAM_ORDER_TYPE = 'DESC' THEN `category_address_region`.`CAT_REGION_DESCRIPTION` END DESC,	
		CASE WHEN PARAM_ORDER_FIELD = 'CAT_REGION_STATUS' AND PARAM_ORDER_TYPE = 'ASC' THEN `category_address_region`.`CAT_REGION_STATUS` END ASC, 
		CASE WHEN PARAM_ORDER_FIELD = 'CAT_REGION_STATUS' AND PARAM_ORDER_TYPE = 'DESC' THEN `category_address_region`.`CAT_REGION_STATUS` END DESC,	
		CASE WHEN PARAM_ORDER_FIELD = 'CAT_REGION_SYSTEM_GENERATED' AND PARAM_ORDER_TYPE = 'ASC' THEN `category_address_region`.`CAT_REGION_SYSTEM_GENERATED` END ASC, 
		CASE WHEN PARAM_ORDER_FIELD = 'CAT_REGION_SYSTEM_GENERATED' AND PARAM_ORDER_TYPE = 'DESC' THEN `category_address_region`.`CAT_REGION_SYSTEM_GENERATED` END DESC,	
		
		-- EXTRA
		CASE WHEN PARAM_ORDER_FIELD <> 'CAT_PROVINCE_DESCRIPTION' THEN `category_address_province`.`CAT_PROVINCE_DESCRIPTION` END ASC
		
	-- LIMIT & OFFSET
	-- ####################################################		
	LIMIT PARAM_SKIP, PARAM_LIMIT;
	
	
	
	-- EXIT PROCEDURE
	-- =========================================================================================
	LEAVE SP_GET;
			
END ;;
DELIMITER ;
/*!50003 SET sql_mode              = @saved_sql_mode */ ;
/*!50003 SET character_set_client  = @saved_cs_client */ ;
/*!50003 SET character_set_results = @saved_cs_results */ ;
/*!50003 SET collation_connection  = @saved_col_connection */ ;
/*!50003 DROP PROCEDURE IF EXISTS `CATEGORY_ADDRESS_PROVINCE_SAVE` */;
/*!50003 SET @saved_cs_client      = @@character_set_client */ ;
/*!50003 SET @saved_cs_results     = @@character_set_results */ ;
/*!50003 SET @saved_col_connection = @@collation_connection */ ;
/*!50003 SET character_set_client  = latin1 */ ;
/*!50003 SET character_set_results = latin1 */ ;
/*!50003 SET collation_connection  = latin1_swedish_ci */ ;
/*!50003 SET @saved_sql_mode       = @@sql_mode */ ;
/*!50003 SET sql_mode              = '' */ ;
DELIMITER ;;
CREATE DEFINER=`root`@`localhost` PROCEDURE `CATEGORY_ADDRESS_PROVINCE_SAVE`(
	IN `PARAM_CAT_PROVINCE_ID` BIGINT,
	IN `PARAM_CAT_PROVINCE_CAT_REGION_ID` BIGINT,
	IN `PARAM_CAT_PROVINCE_CODE` VARCHAR(50),
	IN `PARAM_CAT_PROVINCE_DESCRIPTION` VARCHAR(500),
	IN `PARAM_CAT_PROVINCE_STATUS` TINYINT,

	IN `PARAM_REQUESTER_USERNAME` VARCHAR(500),
	IN `PARAM_REQUESTER_PASSWORD` VARCHAR(500),
	IN `PARAM_REQUESTER_PROXY_ID` BIGINT,
	IN `PARAM_REQUESTER_PROXY_PASSWORD` VARCHAR(1000),
	IN `PARAM_REQUESTER_DEVICE_PUBLIC_KEY` VARCHAR(1000),
	IN `PARAM_REQUESTER_DEVICE_PRIVATE_KEY` VARCHAR(1000),
	
	IN `PARAM_REQUESTER_IP` VARCHAR(1000),
	IN `PARAM_UNIQUE_SESSION_ID` VARCHAR(1000),
	IN `PARAM_SUPPRESS_RETURN` BIT,
	
	IN `PARAM_SYNC_SERVER_DESCRIPTION` VARCHAR(500), 
	IN `PARAM_SYNC_SERVER_UNIQUE_KEY` VARCHAR(500)
)
SP_SAVE:
BEGIN


	-- 1) DECLARE LOCAL PARAMETERS
	-- _______________________________________________________________________
	
	-- Status
	-- ...........................................
	DECLARE STATUS_INACTIVE TINYINT DEFAULT 1;
	DECLARE STATUS_ACTIVE TINYINT DEFAULT 2;
	DECLARE STATUS_CLOSED TINYINT DEFAULT 3;
	DECLARE STATUS_COMPLETED TINYINT DEFAULT 4;

	-- Audit Handler
	-- ...........................................
	DECLARE TEMP_RECORD_EXISTS BIT DEFAULT 0;
	DECLARE TEMP_MODULE_KEYWORD VARCHAR(500) DEFAULT 'category_address_province';
	DECLARE TEMP_SP_OBJECTIVE VARCHAR(500) DEFAULT 'add/edit Address: Province record';
	DECLARE TEMP_ERR_MESSAGE VARCHAR(500) DEFAULT '';
	DECLARE ERR BIGINT DEFAULT 0;
	DECLARE TEMP_RECORD_CHANGES VARCHAR(16000) DEFAULT '';
	DECLARE TEMP_RECORD_BINDED BIT DEFAULT 0;

	-- Authentication
	-- ...........................................
	DECLARE TEMP_ACCESS_RIGHTS_DENIED BIT DEFAULT 0;
	DECLARE TEMP_ACCESS_RIGHTS_HAS_OVERRIDE BIT DEFAULT 0;
	DECLARE TEMP_SYNC_SERVER_ID BIGINT DEFAULT 0;
	DECLARE TEMP_SYNC_IS_SERVER_REQUEST BIT DEFAULT 0;
	DECLARE TEMP_AUTHENTICATED_ACCOUNT_ID BIGINT DEFAULT `ACCOUNT_MEMBER@ACC_ACCOUNT_ID_FROM_LOGIN`(PARAM_REQUESTER_USERNAME, PARAM_REQUESTER_PASSWORD);
	DECLARE TEMP_AUTHENTICATED_ACCOUNT_LEVEL BIGINT DEFAULT 0;
	DECLARE TEMP_AUTHENTICATED_ACCOUNT_GROUP BIGINT DEFAULT 0;
	
	-- Local Parameters
	-- ...........................................
	DECLARE TEMP_NOW DATETIME(6) DEFAULT `SYSTEM_VAR@NOW`('', 1);
	DECLARE TEMP_RECORD_COUNT BIGINT DEFAULT 0;

	-- AutoGen Parameters
	-- ...........................................
	DECLARE PARAM_CAT_PROVINCE_GLOBAL_ID VARCHAR(400) DEFAULT ''; 
	DECLARE PARAM_CAT_PROVINCE_SYSTEM_GENERATED TINYINT DEFAULT 0; 
	
	-- Local value holder
	-- ...........................................
	DECLARE TEMP_CAT_PROVINCE_GLOBAL_ID VARCHAR(400) DEFAULT ''; 
	DECLARE TEMP_CAT_PROVINCE_CAT_REGION_ID BIGINT DEFAULT 0; 
	DECLARE TEMP_CAT_PROVINCE_CODE VARCHAR(50) DEFAULT ''; 
	DECLARE TEMP_CAT_PROVINCE_DESCRIPTION VARCHAR(500) DEFAULT ''; 
	DECLARE TEMP_CAT_PROVINCE_STATUS TINYINT DEFAULT 0; 
	DECLARE TEMP_CAT_PROVINCE_SYSTEM_GENERATED TINYINT DEFAULT 0; 
	


	-- 2) Try Catch / Throw
	-- _______________________________________________________________________
	DECLARE EXIT HANDLER FOR SQLEXCEPTION
	BEGIN
		RESIGNAL;
	END;



	-- 3) Prepare SYNC
	-- _______________________________________________________________________

	-- IS RECORD EXISTS		
	-- ####################################################	
	SET TEMP_RECORD_EXISTS = `CATEGORY_ADDRESS_PROVINCE@CAT_PROVINCE_ID_EXISTS`(PARAM_CAT_PROVINCE_ID, 0);

		
		
	-- 4) PREPARE AUTOGEN DATA (IF EXISTS)
	-- _______________________________________________________________________
	IF TEMP_SYNC_IS_SERVER_REQUEST = 0 THEN
		-- Just to keep at least one line within condition
		SET TEMP_SYNC_IS_SERVER_REQUEST = 0;
		
		-- Actual Functionalities here
		-- USE DEFAULT VALUE (String)
		-- USE DEFAULT VALUE (String)
		SET PARAM_CAT_PROVINCE_GLOBAL_ID = `SYSTEM_VAR@RANDOM_UNIQUE_ALPHA32`;
		-- USE DEFAULT VALUE (String)
		SET PARAM_CAT_PROVINCE_SYSTEM_GENERATED = 1;
	-- USE TIMESTAMP
	END IF;



	-- 5) IF ALREADY EXIST, FILL MISSING DATA
	-- _______________________________________________________________________
	IF TEMP_RECORD_EXISTS = 1 THEN
		SELECT
			`category_address_province`.`CAT_PROVINCE_GLOBAL_ID`, 	
			`category_address_province`.`CAT_PROVINCE_CAT_REGION_ID`, 	
			`category_address_province`.`CAT_PROVINCE_CODE`, 	
			`category_address_province`.`CAT_PROVINCE_DESCRIPTION`, 	
			`category_address_province`.`CAT_PROVINCE_STATUS`, 	
			`category_address_province`.`CAT_PROVINCE_SYSTEM_GENERATED`	
		INTO
			TEMP_CAT_PROVINCE_GLOBAL_ID, 	
			TEMP_CAT_PROVINCE_CAT_REGION_ID, 	
			TEMP_CAT_PROVINCE_CODE, 	
			TEMP_CAT_PROVINCE_DESCRIPTION, 	
			TEMP_CAT_PROVINCE_STATUS, 	
			TEMP_CAT_PROVINCE_SYSTEM_GENERATED	

		FROM `category_address_province`
		WHERE
			`category_address_province`.`CAT_PROVINCE_ID` = PARAM_CAT_PROVINCE_ID
		LIMIT 1;

		-- Replace NULLs with the existing data.
		SET PARAM_CAT_PROVINCE_CAT_REGION_ID = `SYSTEM_VAR@REPLACE_NULL@BIGINT`(PARAM_CAT_PROVINCE_CAT_REGION_ID, TEMP_CAT_PROVINCE_CAT_REGION_ID, 1, 1);
		SET PARAM_CAT_PROVINCE_CODE = `SYSTEM_VAR@REPLACE_NULL@NVARCHAR`(PARAM_CAT_PROVINCE_CODE, TEMP_CAT_PROVINCE_CODE, 0);
		SET PARAM_CAT_PROVINCE_DESCRIPTION = `SYSTEM_VAR@REPLACE_NULL@NVARCHAR`(PARAM_CAT_PROVINCE_DESCRIPTION, TEMP_CAT_PROVINCE_DESCRIPTION, 1);
		SET PARAM_CAT_PROVINCE_STATUS = `SYSTEM_VAR@REPLACE_NULL@TINYINT`(PARAM_CAT_PROVINCE_STATUS, TEMP_CAT_PROVINCE_STATUS, 1, 1);
		
		-- AUTO GEN (NON-UPDATABLES)		
		SET PARAM_CAT_PROVINCE_GLOBAL_ID = TEMP_CAT_PROVINCE_GLOBAL_ID;
		SET PARAM_CAT_PROVINCE_SYSTEM_GENERATED = TEMP_CAT_PROVINCE_SYSTEM_GENERATED;
		
		-- AUTO GEN (UPDATABLE WITH STATUS CHANGE)

		-- AUTO GEN (UPDATABLE WITH STATUS [ACTIVE/INACTIVE] CHANGE)
		
	ELSE
		SET PARAM_CAT_PROVINCE_CAT_REGION_ID = `SYSTEM_VAR@REPLACE_NULL@BIGINT`(PARAM_CAT_PROVINCE_CAT_REGION_ID, 0, 1, 1);
		SET PARAM_CAT_PROVINCE_CODE = `SYSTEM_VAR@REPLACE_NULL@NVARCHAR`(PARAM_CAT_PROVINCE_CODE, '', 0);
		SET PARAM_CAT_PROVINCE_DESCRIPTION = `SYSTEM_VAR@REPLACE_NULL@NVARCHAR`(PARAM_CAT_PROVINCE_DESCRIPTION, '', 1);
		SET PARAM_CAT_PROVINCE_STATUS = `SYSTEM_VAR@REPLACE_NULL@TINYINT`(PARAM_CAT_PROVINCE_STATUS, 0, 1, 1);
		
	END IF;

	

	-- 6) PREPARE AUDIT TRAIL
	-- _______________________________________________________________________
	IF BINARY TEMP_CAT_PROVINCE_GLOBAL_ID <> PARAM_CAT_PROVINCE_GLOBAL_ID THEN
		SET TEMP_RECORD_CHANGES = 
		`SYSTEM_VAR@CONCAT_ADD`(' | ', TEMP_RECORD_CHANGES, CONCAT_WS(' ', 'Sync ID: "', TEMP_CAT_PROVINCE_GLOBAL_ID, '" > "', PARAM_CAT_PROVINCE_GLOBAL_ID, '"'));
	END IF;
	IF TEMP_CAT_PROVINCE_CAT_REGION_ID <> PARAM_CAT_PROVINCE_CAT_REGION_ID THEN
		SET TEMP_RECORD_CHANGES = 
		`SYSTEM_VAR@CONCAT_ADD`(' | ', TEMP_RECORD_CHANGES, CONCAT_WS(' ', 'Region: "', TEMP_CAT_PROVINCE_CAT_REGION_ID, '" > "', PARAM_CAT_PROVINCE_CAT_REGION_ID, '"'));
	END IF;	
	IF BINARY TEMP_CAT_PROVINCE_CODE <> PARAM_CAT_PROVINCE_CODE THEN
		SET TEMP_RECORD_CHANGES = 
		`SYSTEM_VAR@CONCAT_ADD`(' | ', TEMP_RECORD_CHANGES, CONCAT_WS(' ', 'Short Code: "', TEMP_CAT_PROVINCE_CODE, '" > "', PARAM_CAT_PROVINCE_CODE, '"'));
	END IF;
	IF BINARY TEMP_CAT_PROVINCE_DESCRIPTION <> PARAM_CAT_PROVINCE_DESCRIPTION THEN
		SET TEMP_RECORD_CHANGES = 
		`SYSTEM_VAR@CONCAT_ADD`(' | ', TEMP_RECORD_CHANGES, CONCAT_WS(' ', 'Description: "', TEMP_CAT_PROVINCE_DESCRIPTION, '" > "', PARAM_CAT_PROVINCE_DESCRIPTION, '"'));
	END IF;
	IF TEMP_CAT_PROVINCE_STATUS <> PARAM_CAT_PROVINCE_STATUS THEN
		SET TEMP_RECORD_CHANGES = 
		`SYSTEM_VAR@CONCAT_ADD`(' | ', TEMP_RECORD_CHANGES, CONCAT_WS(' ', 'Status: "', TEMP_CAT_PROVINCE_STATUS, '" > "', PARAM_CAT_PROVINCE_STATUS, '"'));
	END IF;	
	IF TEMP_CAT_PROVINCE_SYSTEM_GENERATED <> PARAM_CAT_PROVINCE_SYSTEM_GENERATED THEN
		SET TEMP_RECORD_CHANGES = 
		`SYSTEM_VAR@CONCAT_ADD`(' | ', TEMP_RECORD_CHANGES, CONCAT_WS(' ', 'System Generated: "', TEMP_CAT_PROVINCE_SYSTEM_GENERATED, '" > "', PARAM_CAT_PROVINCE_SYSTEM_GENERATED, '"'));
	END IF;	
		
	-- No Changes in data, reject request
	-- ####################################################
	IF CHARACTER_LENGTH(TEMP_RECORD_CHANGES) = 0 THEN
		IF PARAM_SUPPRESS_RETURN = 0 THEN
			SELECT PARAM_CAT_PROVINCE_ID AS INSERTED_ID;
		END IF;
		LEAVE SP_SAVE;
	END IF;



	-- 7) VALIDATE
	-- _______________________________________________________________________

	-- Access Rights [Device]
	-- ####################################################
	IF `ACCOUNT_DEVICE@HAS_PERMISSION`(PARAM_REQUESTER_DEVICE_PUBLIC_KEY, PARAM_REQUESTER_DEVICE_PRIVATE_KEY) = 0 THEN
		SET TEMP_ERR_MESSAGE = 'Your device is not authorized yet to access this server.';
		SET ERR = `RAISERROR`(TEMP_ERR_MESSAGE);		
	END IF;
		
		
	-- Access Rights [Account]
	-- ####################################################
	
	IF 
		-- [ADD] Access Rights
		(
			TEMP_RECORD_EXISTS = 0 AND
			`ACCOUNT_ACCESS_RIGHTS@HAS_PERMISSION`(PARAM_REQUESTER_USERNAME, PARAM_REQUESTER_PASSWORD, 0, TEMP_MODULE_KEYWORD, 2) = 0 
		) OR
		
		-- [EDIT] Access Rights
		(
			TEMP_RECORD_EXISTS = 1 AND
			`ACCOUNT_ACCESS_RIGHTS@HAS_PERMISSION`(PARAM_REQUESTER_USERNAME, PARAM_REQUESTER_PASSWORD, 0, TEMP_MODULE_KEYWORD, 3) = 0 
		)
	THEN
		SET TEMP_ACCESS_RIGHTS_DENIED = 1;
		CALL `ACCOUNT_ACCESS_RIGHTS_DENY`
		(
			0, TEMP_MODULE_KEYWORD, PARAM_CAT_PROVINCE_ID, 0, TEMP_SP_OBJECTIVE, TEMP_RECORD_CHANGES, 
			PARAM_REQUESTER_USERNAME, PARAM_REQUESTER_PASSWORD, 
			PARAM_REQUESTER_PROXY_ID, PARAM_REQUESTER_PROXY_PASSWORD,
			PARAM_REQUESTER_DEVICE_PUBLIC_KEY, PARAM_REQUESTER_DEVICE_PRIVATE_KEY,
			PARAM_REQUESTER_IP, PARAM_UNIQUE_SESSION_ID,
			TEMP_SYNC_SERVER_ID, PARAM_SUPPRESS_RETURN
		);
	END IF;
	SET TEMP_ACCESS_RIGHTS_HAS_OVERRIDE = `ACCOUNT_ACCESS_RIGHTS@HAS_PERMISSION`(PARAM_REQUESTER_USERNAME, PARAM_REQUESTER_PASSWORD, 0, TEMP_MODULE_KEYWORD, 4);
	

	-- Validation
	-- ####################################################
	IF TEMP_SYNC_IS_SERVER_REQUEST = 0 THEN
	
		-- SYSTEM GENERATED = TRUE
		-- ...........................................
		IF TEMP_CAT_PROVINCE_SYSTEM_GENERATED = STATUS_ACTIVE THEN
		CALL `VALIDATION_SYSTEM_GENERATED`
		(
			PARAM_CAT_PROVINCE_ID,
			TEMP_CAT_PROVINCE_DESCRIPTION, ''
		);
		END IF;

		-- FOREIGN KEY EXISTS
		-- ...........................................
		IF `CATEGORY_ADDRESS_REGION@CAT_REGION_ID_EXISTS`(PARAM_CAT_PROVINCE_CAT_REGION_ID, 0) =  0 THEN
			SET TEMP_ERR_MESSAGE = CONCAT_WS(' ', 'Given Region does not exists or is inactive. ID: ', PARAM_CAT_PROVINCE_CAT_REGION_ID);
			SET ERR = `RAISERROR`(TEMP_ERR_MESSAGE);
		END IF;
		
		-- FOREIGN (OPTIONAL)KEY EXISTS [Validates if not null]
		-- ...........................................
		
		-- IS_ALLOW_NULL = FALSE
		-- ...........................................
		IF PARAM_CAT_PROVINCE_CODE IS NULL THEN
			CALL `VALIDATION_MISSING_FIELD`('`CAT_PROVINCE_CODE`', '`NULL`');
		END IF;
				
		-- IS_ALLOW_ZERO = FALSE
		-- ...........................................
		IF PARAM_CAT_PROVINCE_STATUS = 0 THEN
			CALL `VALIDATION_MISSING_FIELD`('`CAT_PROVINCE_STATUS`', '`NULL`');
		END IF;		
		IF PARAM_CAT_PROVINCE_SYSTEM_GENERATED = 0 THEN
			CALL `VALIDATION_MISSING_FIELD`('`CAT_PROVINCE_SYSTEM_GENERATED`', '`NULL`');
		END IF;		
		
		-- IS_ALLOW_NEGATIVE = FALSE
		-- ...........................................
		IF PARAM_CAT_PROVINCE_STATUS < 0 THEN
			CALL `VALIDATION_NEGATIVE`('`CAT_PROVINCE_STATUS`', PARAM_CAT_PROVINCE_STATUS);
		END IF;		
		IF PARAM_CAT_PROVINCE_SYSTEM_GENERATED < 0 THEN
			CALL `VALIDATION_NEGATIVE`('`CAT_PROVINCE_SYSTEM_GENERATED`', PARAM_CAT_PROVINCE_SYSTEM_GENERATED);
		END IF;		
		
		-- IS_ALLOW_EMPTY_STRING = FALSE
		-- ...........................................
		IF `SYSTEM_VAR@IS_NULL@NVARCHAR`(PARAM_CAT_PROVINCE_GLOBAL_ID, 1) = 1 THEN
			CALL `VALIDATION_MISSING_FIELD`('`CAT_PROVINCE_GLOBAL_ID`', '`NULL`');
		END IF;
		IF `SYSTEM_VAR@IS_NULL@NVARCHAR`(PARAM_CAT_PROVINCE_DESCRIPTION, 1) = 1 THEN
			CALL `VALIDATION_MISSING_FIELD`('`CAT_PROVINCE_DESCRIPTION`', '`NULL`');
		END IF;
		
		-- IS_STATUS
		-- ...........................................
		IF `SYSTEM_STATUS@STATUS_ID_EXISTS`(PARAM_CAT_PROVINCE_STATUS, 0) = 0 THEN
			SET TEMP_ERR_MESSAGE = CONCAT_WS(' ', 'Given STATUS[Status] does not exists or is inactive. ID: ', PARAM_CAT_PROVINCE_STATUS);
			SET ERR = `RAISERROR`(TEMP_ERR_MESSAGE);
		END IF;
		
		-- IS STATUS Active / Inactive
		-- ...........................................
		
		-- Minimum / Maximum Value
		-- ...........................................
		
		-- IS_UNIQUE = TRUE
		-- ...........................................
		IF
		(
			SELECT COUNT(`category_address_province`.`CAT_PROVINCE_ID`)
			FROM `category_address_province`
			WHERE		
				`category_address_province`.`CAT_PROVINCE_GLOBAL_ID` = PARAM_CAT_PROVINCE_GLOBAL_ID AND		
				`category_address_province`.`CAT_PROVINCE_ID` <> PARAM_CAT_PROVINCE_ID
		) >= 1
		THEN
			CALL `VALIDATION_REDUNDANT_ENTRY`(PARAM_CAT_PROVINCE_DESCRIPTION);
		END IF;
		
		-- RECORD IDENTIFIER
		-- ...........................................
		IF
		(
			SELECT COUNT(`category_address_province`.`CAT_PROVINCE_ID`)
			FROM `category_address_province`
			WHERE
				`category_address_province`.`CAT_PROVINCE_CAT_REGION_ID` = PARAM_CAT_PROVINCE_CAT_REGION_ID AND
				`category_address_province`.`CAT_PROVINCE_DESCRIPTION` = PARAM_CAT_PROVINCE_DESCRIPTION AND
				`category_address_province`.`CAT_PROVINCE_ID` <> PARAM_CAT_PROVINCE_ID
		) >= 1
		THEN
			CALL `VALIDATION_REDUNDANT_ENTRY`(PARAM_CAT_PROVINCE_DESCRIPTION);
		END IF;
		
		
		-- ON_UPDATE VALIDATION 
		-- ...........................................
		IF TEMP_RECORD_EXISTS = 1 THEN	
		
			-- Just to keep at least one line within condition
			SET TEMP_RECORD_EXISTS = 1;
			
		END IF;
		
	END IF;



	-- 8) INSERT / UPDATE
	-- _______________________________________________________________________

	-- INSERT NEW DATA
	-- ####################################################
	IF TEMP_RECORD_EXISTS = 0 THEN

		INSERT INTO
		`category_address_province`
		(
			`category_address_province`.`CAT_PROVINCE_GLOBAL_ID`, 
			`category_address_province`.`CAT_PROVINCE_CAT_REGION_ID`, 
			`category_address_province`.`CAT_PROVINCE_CODE`, 
			`category_address_province`.`CAT_PROVINCE_DESCRIPTION`, 
			`category_address_province`.`CAT_PROVINCE_STATUS`, 
			`category_address_province`.`CAT_PROVINCE_SYSTEM_GENERATED`
		)
		VALUES
		(
			PARAM_CAT_PROVINCE_GLOBAL_ID, 
			PARAM_CAT_PROVINCE_CAT_REGION_ID, 
			PARAM_CAT_PROVINCE_CODE, 
			PARAM_CAT_PROVINCE_DESCRIPTION, 
			PARAM_CAT_PROVINCE_STATUS, 
			PARAM_CAT_PROVINCE_SYSTEM_GENERATED
		);	
		
		-- Update Audit trail with new ID	
		SET PARAM_CAT_PROVINCE_ID = LAST_INSERT_ID();



	-- UPDATING EXISTING RECORD
	-- ####################################################
	ELSE
		UPDATE `category_address_province`
		SET
			`category_address_province`.`CAT_PROVINCE_GLOBAL_ID` = PARAM_CAT_PROVINCE_GLOBAL_ID, 
			`category_address_province`.`CAT_PROVINCE_CAT_REGION_ID` = PARAM_CAT_PROVINCE_CAT_REGION_ID, 
			`category_address_province`.`CAT_PROVINCE_CODE` = PARAM_CAT_PROVINCE_CODE, 
			`category_address_province`.`CAT_PROVINCE_DESCRIPTION` = PARAM_CAT_PROVINCE_DESCRIPTION, 
			`category_address_province`.`CAT_PROVINCE_STATUS` = PARAM_CAT_PROVINCE_STATUS, 
			`category_address_province`.`CAT_PROVINCE_SYSTEM_GENERATED` = PARAM_CAT_PROVINCE_SYSTEM_GENERATED
		WHERE
			`category_address_province`.`CAT_PROVINCE_ID` = PARAM_CAT_PROVINCE_ID;

	END IF;

	
	-- 9) AUDIT TRAIL
	-- _______________________________________________________________________
	CALL `ACCOUNT_AUDIT_TRAIL_SAVE`
	(
		0, TEMP_MODULE_KEYWORD, PARAM_CAT_PROVINCE_ID, 0, 'SAVE', TEMP_SP_OBJECTIVE, TEMP_RECORD_CHANGES, 
		PARAM_REQUESTER_USERNAME, PARAM_REQUESTER_PASSWORD, 
		PARAM_REQUESTER_PROXY_ID, PARAM_REQUESTER_PROXY_PASSWORD,
		PARAM_REQUESTER_DEVICE_PUBLIC_KEY, PARAM_REQUESTER_DEVICE_PRIVATE_KEY,
		PARAM_REQUESTER_IP, PARAM_UNIQUE_SESSION_ID,
		TEMP_SYNC_SERVER_ID, PARAM_SUPPRESS_RETURN
	);
	

	-- 10) RETURN RESULT
	-- _______________________________________________________________________
	IF PARAM_SUPPRESS_RETURN = 0 THEN
		SELECT PARAM_CAT_PROVINCE_ID AS INSERTED_ID;
	END IF;
	LEAVE SP_SAVE;


END ;;
DELIMITER ;
/*!50003 SET sql_mode              = @saved_sql_mode */ ;
/*!50003 SET character_set_client  = @saved_cs_client */ ;
/*!50003 SET character_set_results = @saved_cs_results */ ;
/*!50003 SET collation_connection  = @saved_col_connection */ ;
/*!50003 DROP PROCEDURE IF EXISTS `CATEGORY_ADDRESS_REGION_DELETE` */;
/*!50003 SET @saved_cs_client      = @@character_set_client */ ;
/*!50003 SET @saved_cs_results     = @@character_set_results */ ;
/*!50003 SET @saved_col_connection = @@collation_connection */ ;
/*!50003 SET character_set_client  = latin1 */ ;
/*!50003 SET character_set_results = latin1 */ ;
/*!50003 SET collation_connection  = latin1_swedish_ci */ ;
/*!50003 SET @saved_sql_mode       = @@sql_mode */ ;
/*!50003 SET sql_mode              = '' */ ;
DELIMITER ;;
CREATE DEFINER=`root`@`localhost` PROCEDURE `CATEGORY_ADDRESS_REGION_DELETE`(
	IN `PARAM_CAT_REGION_ID` BIGINT,

	IN `PARAM_REQUESTER_USERNAME` VARCHAR(500),
	IN `PARAM_REQUESTER_PASSWORD` VARCHAR(500),
	IN `PARAM_REQUESTER_PROXY_ID` BIGINT,
	IN `PARAM_REQUESTER_PROXY_PASSWORD` VARCHAR(1000),
	IN `PARAM_REQUESTER_DEVICE_PUBLIC_KEY` VARCHAR(1000),
	IN `PARAM_REQUESTER_DEVICE_PRIVATE_KEY` VARCHAR(1000),
	
	IN `PARAM_REQUESTER_IP` VARCHAR(1000),
	IN `PARAM_UNIQUE_SESSION_ID` VARCHAR(1000),
	IN `PARAM_SUPPRESS_RETURN` BIT,
	
	IN `PARAM_SYNC_SERVER_DESCRIPTION` VARCHAR(500), 
	IN `PARAM_SYNC_SERVER_UNIQUE_KEY` VARCHAR(500)
)
SP_DELETE:
BEGIN

	-- 1) DECLARE LOCAL PARAMETERS
	-- _______________________________________________________________________
	
	-- Status
	-- ...........................................
	DECLARE STATUS_INACTIVE TINYINT DEFAULT 1;
	DECLARE STATUS_ACTIVE TINYINT DEFAULT 2;
	DECLARE STATUS_CLOSED TINYINT DEFAULT 3;
	DECLARE STATUS_COMPLETED TINYINT DEFAULT 4;
	
	-- Audit Handler
	-- ...........................................
	DECLARE TEMP_RECORD_EXISTS BIT DEFAULT 0;
	DECLARE TEMP_MODULE_KEYWORD VARCHAR(500) DEFAULT 'category_address_region';
	DECLARE TEMP_SP_OBJECTIVE VARCHAR(500) DEFAULT 'delete Address: Region record';
	DECLARE TEMP_ERR_MESSAGE VARCHAR(500) DEFAULT '';
	DECLARE ERR BIGINT DEFAULT 0;
	DECLARE TEMP_RECORD_CHANGES VARCHAR(16000) DEFAULT '';
	DECLARE TEMP_RECORD_BINDED BIT DEFAULT 0;
	
	DECLARE TEMP_RECORD_BINDED_ID BIGINT DEFAULT 0;
	DECLARE TEMP_RECORD_BINDED_SERVER_ID BIGINT DEFAULT 0;
	
	-- Authentication
	-- ...........................................
	DECLARE TEMP_ACCESS_RIGHTS_DENIED BIT DEFAULT 0;
	DECLARE TEMP_SYNC_SERVER_ID BIGINT DEFAULT 0;
	DECLARE TEMP_SYNC_IS_SERVER_REQUEST BIT DEFAULT 0;
	DECLARE TEMP_AUTHENTICATED_ACCOUNT_ID BIGINT DEFAULT `ACCOUNT_MEMBER@ACC_ACCOUNT_ID_FROM_LOGIN`(PARAM_REQUESTER_USERNAME, PARAM_REQUESTER_PASSWORD);
	DECLARE TEMP_AUTHENTICATED_ACCOUNT_LEVEL BIGINT DEFAULT 0;
	DECLARE TEMP_AUTHENTICATED_ACCOUNT_GROUP BIGINT DEFAULT 0;

	-- Local value holder
	-- ...........................................
		DECLARE TEMP_CAT_REGION_GLOBAL_ID VARCHAR(400) DEFAULT ''; 
		DECLARE TEMP_CAT_REGION_CAT_COUNTRY_ID BIGINT DEFAULT 0; 
		DECLARE TEMP_CAT_REGION_CODE VARCHAR(50) DEFAULT ''; 
		DECLARE TEMP_CAT_REGION_DESCRIPTION VARCHAR(500) DEFAULT ''; 
		DECLARE TEMP_CAT_REGION_STATUS TINYINT DEFAULT 0; 
		DECLARE TEMP_CAT_REGION_SYSTEM_GENERATED TINYINT DEFAULT 0; 

	
	
	-- 2) Try Catch / Throw
	-- _______________________________________________________________________
	DECLARE EXIT HANDLER FOR SQLEXCEPTION
	BEGIN
		RESIGNAL;
	END;

	
	-- 3) Prepare SYNC
	-- _______________________________________________________________________
	
	-- IS RECORD EXISTS		
	-- ####################################################		
	SET TEMP_RECORD_EXISTS = `CATEGORY_ADDRESS_REGION@CAT_REGION_ID_EXISTS`(PARAM_CAT_REGION_ID, 0);


	-- 4) IF ALREADY EXIST, FILL MISSING DATA
	-- _______________________________________________________________________
	IF TEMP_RECORD_EXISTS = 1 THEN
		SELECT
				`category_address_region`.`CAT_REGION_GLOBAL_ID`, 	
				`category_address_region`.`CAT_REGION_CAT_COUNTRY_ID`, 	
				`category_address_region`.`CAT_REGION_CODE`, 	
				`category_address_region`.`CAT_REGION_DESCRIPTION`, 	
				`category_address_region`.`CAT_REGION_STATUS`, 	
				`category_address_region`.`CAT_REGION_SYSTEM_GENERATED`	
		INTO
				TEMP_CAT_REGION_GLOBAL_ID, 	
				TEMP_CAT_REGION_CAT_COUNTRY_ID, 	
				TEMP_CAT_REGION_CODE, 	
				TEMP_CAT_REGION_DESCRIPTION, 	
				TEMP_CAT_REGION_STATUS, 	
				TEMP_CAT_REGION_SYSTEM_GENERATED	

		FROM `category_address_region`
		WHERE
			`category_address_region`.`CAT_REGION_ID` = PARAM_CAT_REGION_ID
		LIMIT 1;

	ELSE 
		IF TEMP_SYNC_IS_SERVER_REQUEST = 0 THEN
			SET TEMP_ERR_MESSAGE = CONCAT_WS(' ', 'Given Address: Region does not exists or is inactive. ID:', PARAM_CAT_REGION_ID);
			SET ERR = `RAISERROR`(TEMP_ERR_MESSAGE);		
		END IF;
		LEAVE SP_DELETE;
		
	END IF;



	-- 5) PREPARE AUDIT TRAIL
	-- _______________________________________________________________________
	
		SET TEMP_RECORD_CHANGES = 
		`SYSTEM_VAR@CONCAT_ADD`(' | ', TEMP_RECORD_CHANGES, CONCAT_WS(' ', 'ID: "', TEMP_CAT_REGION_GLOBAL_ID, '" > " DELETED "'));
		SET TEMP_RECORD_CHANGES = 
		`SYSTEM_VAR@CONCAT_ADD`(' | ', TEMP_RECORD_CHANGES, CONCAT_WS(' ', 'Country: "', TEMP_CAT_REGION_CAT_COUNTRY_ID, '" > " DELETED "'));
		SET TEMP_RECORD_CHANGES = 
		`SYSTEM_VAR@CONCAT_ADD`(' | ', TEMP_RECORD_CHANGES, CONCAT_WS(' ', 'Short Description: "', TEMP_CAT_REGION_CODE, '" > " DELETED "'));
		SET TEMP_RECORD_CHANGES = 
		`SYSTEM_VAR@CONCAT_ADD`(' | ', TEMP_RECORD_CHANGES, CONCAT_WS(' ', 'Description: "', TEMP_CAT_REGION_DESCRIPTION, '" > " DELETED "'));
		SET TEMP_RECORD_CHANGES = 
		`SYSTEM_VAR@CONCAT_ADD`(' | ', TEMP_RECORD_CHANGES, CONCAT_WS(' ', 'Status: "', TEMP_CAT_REGION_STATUS, '" > " DELETED "'));
		SET TEMP_RECORD_CHANGES = 
		`SYSTEM_VAR@CONCAT_ADD`(' | ', TEMP_RECORD_CHANGES, CONCAT_WS(' ', 'System Generated: "', TEMP_CAT_REGION_SYSTEM_GENERATED, '" > " DELETED "'));


	-- 6) VALIDATE
	-- _______________________________________________________________________
	
	-- Access Rights [Device]
	-- ####################################################
	IF `ACCOUNT_DEVICE@HAS_PERMISSION`(PARAM_REQUESTER_DEVICE_PUBLIC_KEY, PARAM_REQUESTER_DEVICE_PRIVATE_KEY) = 0 THEN
		SET TEMP_ERR_MESSAGE = 'Your device is not authorized yet to access this server.';
		SET ERR = `RAISERROR`(TEMP_ERR_MESSAGE);		
	END IF;
		
		
	-- Access Rights [Account]
	-- ####################################################	
	
	IF 
		-- [DELETE] Access Rights
		`ACCOUNT_ACCESS_RIGHTS@HAS_PERMISSION`(PARAM_REQUESTER_USERNAME, PARAM_REQUESTER_PASSWORD, 0, TEMP_MODULE_KEYWORD, 4) = 0 
	THEN
		SET TEMP_ACCESS_RIGHTS_DENIED = 1;
		CALL `ACCOUNT_ACCESS_RIGHTS_DENY`
		(
			0, TEMP_MODULE_KEYWORD, PARAM_CAT_REGION_ID, 0, TEMP_SP_OBJECTIVE, TEMP_RECORD_CHANGES, 
			PARAM_REQUESTER_USERNAME, PARAM_REQUESTER_PASSWORD, 
			PARAM_REQUESTER_PROXY_ID, PARAM_REQUESTER_PROXY_PASSWORD,
			PARAM_REQUESTER_DEVICE_PUBLIC_KEY, PARAM_REQUESTER_DEVICE_PRIVATE_KEY,
			PARAM_REQUESTER_IP, PARAM_UNIQUE_SESSION_ID,
			TEMP_SYNC_SERVER_ID, PARAM_SUPPRESS_RETURN
		);
	END IF;

	-- System Generated Record (Cannot be deleted)
	-- ####################################################
	IF TEMP_CAT_REGION_SYSTEM_GENERATED = STATUS_ACTIVE THEN
		CALL `VALIDATION_SYSTEM_GENERATED`
		(
			PARAM_CAT_REGION_ID,
			TEMP_CAT_REGION_DESCRIPTION, ''
		);
	END IF;
	
	-- If already used, cannot remove record
	-- ####################################################
	IF
	(
		SELECT
			COUNT(`category_address_province`.`CAT_PROVINCE_CAT_REGION_ID`)
		FROM `category_address_province`
		WHERE
			`category_address_province`.`CAT_PROVINCE_CAT_REGION_ID` = PARAM_CAT_REGION_ID
		LIMIT 1
	) >= 1 
	THEN
		SET TEMP_RECORD_BINDED = 1;
		SET TEMP_ERR_MESSAGE = 'Address: Province Record';
	END IF;
	IF
	(
		SELECT
			COUNT(`category_branch`.`CAT_BRANCH_CAT_REGION_ID`)
		FROM `category_branch`
		WHERE
			`category_branch`.`CAT_BRANCH_CAT_REGION_ID` = PARAM_CAT_REGION_ID
		LIMIT 1
	) >= 1 
	THEN
		SET TEMP_RECORD_BINDED = 1;
		SET TEMP_ERR_MESSAGE = 'Branch Record';
	END IF;
	IF
	(
		SELECT
			COUNT(`record_combatants`.`REC_COMBATANT_CAT_REGION_ID`)
		FROM `record_combatants`
		WHERE
			`record_combatants`.`REC_COMBATANT_CAT_REGION_ID` = PARAM_CAT_REGION_ID
		LIMIT 1
	) >= 1 
	THEN
		SET TEMP_RECORD_BINDED = 1;
		SET TEMP_ERR_MESSAGE = 'Combatant Information Record';
	END IF;

	-- Leave Re-upload request
	-- ####################################################
	IF TEMP_RECORD_BINDED = 1 THEN
		IF TEMP_SYNC_IS_SERVER_REQUEST = 1 THEN
			
			LEAVE SP_DELETE;
		END IF;

		CALL `VALIDATION_DELETE_LINKED_RECORD`(TEMP_CAT_REGION_DESCRIPTION, '', TEMP_ERR_MESSAGE); 
	END IF;


	-- 7) DELETE
	-- _______________________________________________________________________
	DELETE FROM `category_address_region`
	WHERE `category_address_region`.`CAT_REGION_ID` = PARAM_CAT_REGION_ID
	LIMIT 1;


	-- 8) AUDIT TRAIL
	-- _______________________________________________________________________
	CALL `ACCOUNT_AUDIT_TRAIL_SAVE`
	(
		0, TEMP_MODULE_KEYWORD, PARAM_CAT_REGION_ID, 0, 'DELETE', TEMP_SP_OBJECTIVE, TEMP_RECORD_CHANGES, 
		PARAM_REQUESTER_USERNAME, PARAM_REQUESTER_PASSWORD, 
		PARAM_REQUESTER_PROXY_ID, PARAM_REQUESTER_PROXY_PASSWORD,
		PARAM_REQUESTER_DEVICE_PUBLIC_KEY, PARAM_REQUESTER_DEVICE_PRIVATE_KEY,
		PARAM_REQUESTER_IP, PARAM_UNIQUE_SESSION_ID,
		TEMP_SYNC_SERVER_ID, PARAM_SUPPRESS_RETURN
	);

END ;;
DELIMITER ;
/*!50003 SET sql_mode              = @saved_sql_mode */ ;
/*!50003 SET character_set_client  = @saved_cs_client */ ;
/*!50003 SET character_set_results = @saved_cs_results */ ;
/*!50003 SET collation_connection  = @saved_col_connection */ ;
/*!50003 DROP PROCEDURE IF EXISTS `CATEGORY_ADDRESS_REGION_GET` */;
/*!50003 SET @saved_cs_client      = @@character_set_client */ ;
/*!50003 SET @saved_cs_results     = @@character_set_results */ ;
/*!50003 SET @saved_col_connection = @@collation_connection */ ;
/*!50003 SET character_set_client  = latin1 */ ;
/*!50003 SET character_set_results = latin1 */ ;
/*!50003 SET collation_connection  = latin1_swedish_ci */ ;
/*!50003 SET @saved_sql_mode       = @@sql_mode */ ;
/*!50003 SET sql_mode              = '' */ ;
DELIMITER ;;
CREATE DEFINER=`root`@`localhost` PROCEDURE `CATEGORY_ADDRESS_REGION_GET`(
	IN `PARAM_CAT_REGION_ID` BIGINT,	
	IN `PARAM_CAT_REGION_GLOBAL_ID` VARCHAR(400),	
	IN `PARAM_CAT_REGION_CAT_COUNTRY_ID` BIGINT,	
	IN `PARAM_CAT_REGION_CODE` VARCHAR(50),	
	IN `PARAM_CAT_REGION_DESCRIPTION` VARCHAR(500),	
	IN `PARAM_CAT_REGION_STATUS` TINYINT,	
	IN `PARAM_CAT_REGION_SYSTEM_GENERATED` TINYINT,	
		
	IN `PARAM_ORDER_FIELD` VARCHAR(500),
	IN `PARAM_ORDER_TYPE` VARCHAR(500),
	IN `PARAM_SKIP` BIGINT,
	IN `PARAM_LIMIT` BIGINT,

	IN `PARAM_REQUESTER_USERNAME` VARCHAR(500),
	IN `PARAM_REQUESTER_PASSWORD` VARCHAR(500),
	IN `PARAM_REQUESTER_PROXY_ID` BIGINT,
	IN `PARAM_REQUESTER_PROXY_PASSWORD` VARCHAR(1000),
	IN `PARAM_REQUESTER_DEVICE_PUBLIC_KEY` VARCHAR(1000),
	IN `PARAM_REQUESTER_DEVICE_PRIVATE_KEY` VARCHAR(1000),
	
	IN `PARAM_REQUESTER_IP` VARCHAR(1000),
	IN `PARAM_UNIQUE_SESSION_ID` VARCHAR(1000),
	IN `PARAM_SUPPRESS_RETURN` BIT
)
SP_GET:
BEGIN

	-- Status
	-- =========================================================================================
	DECLARE STATUS_INACTIVE TINYINT DEFAULT 1;
	DECLARE STATUS_ACTIVE TINYINT DEFAULT 2;
	DECLARE STATUS_CLOSED TINYINT DEFAULT 3;
	DECLARE STATUS_COMPLETED TINYINT DEFAULT 4;
	
	-- Audit Handler
	-- =========================================================================================
	DECLARE TEMP_RECORD_EXISTS BIT DEFAULT 0;
	DECLARE TEMP_MODULE_KEYWORD VARCHAR(500) DEFAULT 'category_address_region';
	DECLARE TEMP_SP_OBJECTIVE VARCHAR(500) DEFAULT 'Retrieve Address: Region record';
	DECLARE TEMP_ERR_MESSAGE VARCHAR(500) DEFAULT '';
	DECLARE ERR BIGINT DEFAULT 0;
	DECLARE TEMP_RECORD_CHANGES VARCHAR(16000) DEFAULT '';
	DECLARE TEMP_RECORD_BINDED BIT DEFAULT 0;
	
	DECLARE TEMP_RECORD_BINDED_ID BIGINT DEFAULT 0;
	DECLARE TEMP_RECORD_BINDED_SERVER_ID BIGINT DEFAULT 0;
	
	-- Authentication
	-- =========================================================================================
	DECLARE TEMP_ACCESS_RIGHTS_DENIED BIT DEFAULT 0;
	DECLARE TEMP_AUTHENTICATED_ACCOUNT_ID BIGINT DEFAULT `ACCOUNT_MEMBER@ACC_ACCOUNT_ID_FROM_LOGIN`(PARAM_REQUESTER_USERNAME, PARAM_REQUESTER_PASSWORD);
	DECLARE TEMP_AUTHENTICATED_ACCOUNT_LEVEL BIGINT DEFAULT 0;
	DECLARE TEMP_AUTHENTICATED_ACCOUNT_GROUP BIGINT DEFAULT 0;
	
	-- Local Parameters
	-- =========================================================================================
	DECLARE TEMP_NOW DATETIME(6) DEFAULT `SYSTEM_VAR@NOW`('', 1);
	DECLARE TEMP_RECORD_COUNT BIGINT DEFAULT 0;
	
	
	-- Check NULLs
	-- =========================================================================================
	DECLARE IS_NULL_CAT_REGION_ID BIT DEFAULT `SYSTEM_VAR@IS_NULL@BIGINT`(PARAM_CAT_REGION_ID, 1, 1);
	DECLARE IS_NULL_CAT_REGION_GLOBAL_ID BIT DEFAULT `SYSTEM_VAR@IS_NULL@NVARCHAR`(PARAM_CAT_REGION_GLOBAL_ID, 1);
	DECLARE IS_NULL_CAT_REGION_CAT_COUNTRY_ID BIT DEFAULT `SYSTEM_VAR@IS_NULL@BIGINT`(PARAM_CAT_REGION_CAT_COUNTRY_ID, 1, 1);
	DECLARE IS_NULL_CAT_REGION_CODE BIT DEFAULT `SYSTEM_VAR@IS_NULL@NVARCHAR`(PARAM_CAT_REGION_CODE, 0);
	DECLARE IS_NULL_CAT_REGION_DESCRIPTION BIT DEFAULT `SYSTEM_VAR@IS_NULL@NVARCHAR`(PARAM_CAT_REGION_DESCRIPTION, 1);
	DECLARE IS_NULL_CAT_REGION_STATUS BIT DEFAULT `SYSTEM_VAR@IS_NULL@TINYINT`(PARAM_CAT_REGION_STATUS, 1, 1);
	DECLARE IS_NULL_CAT_REGION_SYSTEM_GENERATED BIT DEFAULT `SYSTEM_VAR@IS_NULL@TINYINT`(PARAM_CAT_REGION_SYSTEM_GENERATED, 1, 1);
	
	-- Error Handler
	-- =========================================================================================
	DECLARE EXIT HANDLER FOR SQLEXCEPTION
	BEGIN
		RESIGNAL;
	END;
	
	-- Ignore Time from DateTime (Set Time 00:00:00.000000 and 23:59:59.999999)
	-- =========================================================================================
		
		
	-- Access Rights [Device]
	-- =========================================================================================
	IF `ACCOUNT_DEVICE@HAS_PERMISSION`(PARAM_REQUESTER_DEVICE_PUBLIC_KEY, PARAM_REQUESTER_DEVICE_PRIVATE_KEY) = 0 THEN
		SET TEMP_ERR_MESSAGE = 'Your device is not authorized yet to access this server.';
		SET ERR = `RAISERROR`(TEMP_ERR_MESSAGE);		
	END IF;
		
		
	-- Access Rights [Account]
	-- =========================================================================================
		
	
	
	
	-- COUNT RECORD
	-- =========================================================================================
	
	-- SELECT COLUMNS
	-- ####################################################
	SELECT
		COUNT(DISTINCT `category_address_region`.`CAT_REGION_ID`)
	INTO
		TEMP_RECORD_COUNT

	FROM `category_address_region`
	
		-- Add Inner Joins (Per Foreign-key)
		INNER JOIN `category_address_country` ON
		`category_address_country`.`CAT_COUNTRY_ID` = `category_address_region`.`CAT_REGION_CAT_COUNTRY_ID`
		
		-- Add Optional Left Joins (Per Optional Foreign-key)
		
	-- CONDITIONS
	-- ####################################################
	WHERE
		(
			IS_NULL_CAT_REGION_ID = 1 OR
			`category_address_region`.`CAT_REGION_ID` = PARAM_CAT_REGION_ID			
		) AND
		(
			IS_NULL_CAT_REGION_GLOBAL_ID = 1 OR
			`category_address_region`.`CAT_REGION_GLOBAL_ID` LIKE CONCAT_WS('%', '', PARAM_CAT_REGION_GLOBAL_ID, '')			
		) AND 		
		(
			IS_NULL_CAT_REGION_CAT_COUNTRY_ID = 1 OR
			`category_address_region`.`CAT_REGION_CAT_COUNTRY_ID` = PARAM_CAT_REGION_CAT_COUNTRY_ID			
		) AND
		(
			IS_NULL_CAT_REGION_CODE = 1 OR
			`category_address_region`.`CAT_REGION_CODE` LIKE CONCAT_WS('%', '', PARAM_CAT_REGION_CODE, '')			
		) AND 		
		(
			IS_NULL_CAT_REGION_DESCRIPTION = 1 OR
			`category_address_region`.`CAT_REGION_DESCRIPTION` LIKE CONCAT_WS('%', '', PARAM_CAT_REGION_DESCRIPTION, '')			
		) AND 		
		(
			IS_NULL_CAT_REGION_STATUS = 1 OR
			`category_address_region`.`CAT_REGION_STATUS` = PARAM_CAT_REGION_STATUS			
		) AND
		(
			IS_NULL_CAT_REGION_SYSTEM_GENERATED = 1 OR
			`category_address_region`.`CAT_REGION_SYSTEM_GENERATED` = PARAM_CAT_REGION_SYSTEM_GENERATED			
		) 
;	

		
		
	-- SELECT RECORDS
	-- =========================================================================================
	
	-- FETCH COLUMNS
	-- ####################################################
	SELECT
		-- CATEGORY_ADDRESS_REGION DETAILS
		`category_address_region`.`CAT_REGION_ID`, 
		`category_address_region`.`CAT_REGION_GLOBAL_ID`, 
		`category_address_region`.`CAT_REGION_CAT_COUNTRY_ID`, 
		`category_address_region`.`CAT_REGION_CODE`, 
		`category_address_region`.`CAT_REGION_DESCRIPTION`, 
		`category_address_region`.`CAT_REGION_STATUS`, 
		`category_address_region`.`CAT_REGION_SYSTEM_GENERATED`
		
		-- Inner join fields
		, 
		`category_address_country`.`CAT_COUNTRY_ID`, 
		`category_address_country`.`CAT_COUNTRY_GLOBAL_ID`, 
		`category_address_country`.`CAT_COUNTRY_CODE`, 
		`category_address_country`.`CAT_COUNTRY_DESCRIPTION`, 
		`category_address_country`.`CAT_COUNTRY_STATUS`, 
		`category_address_country`.`CAT_COUNTRY_SYSTEM_GENERATED`
		
		-- Left join fields
		
		, TEMP_RECORD_COUNT AS RECORD_COUNT

	FROM `category_address_region`
	
		-- Add Inner Joins (Per Foreign-key)
		INNER JOIN `category_address_country` ON
		`category_address_country`.`CAT_COUNTRY_ID` = `category_address_region`.`CAT_REGION_CAT_COUNTRY_ID`
		
		-- Add Optional Left Joins (Per Optional Foreign-key)
		
	-- CONDITIONS
	-- ####################################################
	WHERE
		(
			IS_NULL_CAT_REGION_ID = 1 OR
			`category_address_region`.`CAT_REGION_ID` = PARAM_CAT_REGION_ID			
		) AND
		(
			IS_NULL_CAT_REGION_GLOBAL_ID = 1 OR
			`category_address_region`.`CAT_REGION_GLOBAL_ID` LIKE CONCAT_WS('%', '', PARAM_CAT_REGION_GLOBAL_ID, '')			
		) AND 		
		(
			IS_NULL_CAT_REGION_CAT_COUNTRY_ID = 1 OR
			`category_address_region`.`CAT_REGION_CAT_COUNTRY_ID` = PARAM_CAT_REGION_CAT_COUNTRY_ID			
		) AND
		(
			IS_NULL_CAT_REGION_CODE = 1 OR
			`category_address_region`.`CAT_REGION_CODE` LIKE CONCAT_WS('%', '', PARAM_CAT_REGION_CODE, '')			
		) AND 		
		(
			IS_NULL_CAT_REGION_DESCRIPTION = 1 OR
			`category_address_region`.`CAT_REGION_DESCRIPTION` LIKE CONCAT_WS('%', '', PARAM_CAT_REGION_DESCRIPTION, '')			
		) AND 		
		(
			IS_NULL_CAT_REGION_STATUS = 1 OR
			`category_address_region`.`CAT_REGION_STATUS` = PARAM_CAT_REGION_STATUS			
		) AND
		(
			IS_NULL_CAT_REGION_SYSTEM_GENERATED = 1 OR
			`category_address_region`.`CAT_REGION_SYSTEM_GENERATED` = PARAM_CAT_REGION_SYSTEM_GENERATED			
		) 

	-- ORDER BY
	-- ####################################################
	ORDER BY
		-- CATEGORY_ADDRESS_REGION DETAILS
		CASE WHEN PARAM_ORDER_FIELD = 'CAT_REGION_ID' AND PARAM_ORDER_TYPE = 'ASC' THEN `category_address_region`.`CAT_REGION_ID` END ASC, 
		CASE WHEN PARAM_ORDER_FIELD = 'CAT_REGION_ID' AND PARAM_ORDER_TYPE = 'DESC' THEN `category_address_region`.`CAT_REGION_ID` END DESC,	
		CASE WHEN PARAM_ORDER_FIELD = 'CAT_REGION_GLOBAL_ID' AND PARAM_ORDER_TYPE = 'ASC' THEN `category_address_region`.`CAT_REGION_GLOBAL_ID` END ASC, 
		CASE WHEN PARAM_ORDER_FIELD = 'CAT_REGION_GLOBAL_ID' AND PARAM_ORDER_TYPE = 'DESC' THEN `category_address_region`.`CAT_REGION_GLOBAL_ID` END DESC,	
		CASE WHEN PARAM_ORDER_FIELD = 'CAT_REGION_CAT_COUNTRY_ID' AND PARAM_ORDER_TYPE = 'ASC' THEN `category_address_region`.`CAT_REGION_CAT_COUNTRY_ID` END ASC, 
		CASE WHEN PARAM_ORDER_FIELD = 'CAT_REGION_CAT_COUNTRY_ID' AND PARAM_ORDER_TYPE = 'DESC' THEN `category_address_region`.`CAT_REGION_CAT_COUNTRY_ID` END DESC,	
		CASE WHEN PARAM_ORDER_FIELD = 'CAT_REGION_CODE' AND PARAM_ORDER_TYPE = 'ASC' THEN `category_address_region`.`CAT_REGION_CODE` END ASC, 
		CASE WHEN PARAM_ORDER_FIELD = 'CAT_REGION_CODE' AND PARAM_ORDER_TYPE = 'DESC' THEN `category_address_region`.`CAT_REGION_CODE` END DESC,	
		CASE WHEN PARAM_ORDER_FIELD = 'CAT_REGION_DESCRIPTION' AND PARAM_ORDER_TYPE = 'ASC' THEN `category_address_region`.`CAT_REGION_DESCRIPTION` END ASC, 
		CASE WHEN PARAM_ORDER_FIELD = 'CAT_REGION_DESCRIPTION' AND PARAM_ORDER_TYPE = 'DESC' THEN `category_address_region`.`CAT_REGION_DESCRIPTION` END DESC,	
		CASE WHEN PARAM_ORDER_FIELD = 'CAT_REGION_STATUS' AND PARAM_ORDER_TYPE = 'ASC' THEN `category_address_region`.`CAT_REGION_STATUS` END ASC, 
		CASE WHEN PARAM_ORDER_FIELD = 'CAT_REGION_STATUS' AND PARAM_ORDER_TYPE = 'DESC' THEN `category_address_region`.`CAT_REGION_STATUS` END DESC,	
		CASE WHEN PARAM_ORDER_FIELD = 'CAT_REGION_SYSTEM_GENERATED' AND PARAM_ORDER_TYPE = 'ASC' THEN `category_address_region`.`CAT_REGION_SYSTEM_GENERATED` END ASC, 
		CASE WHEN PARAM_ORDER_FIELD = 'CAT_REGION_SYSTEM_GENERATED' AND PARAM_ORDER_TYPE = 'DESC' THEN `category_address_region`.`CAT_REGION_SYSTEM_GENERATED` END DESC,	

		-- Inner joins
		CASE WHEN PARAM_ORDER_FIELD = 'CAT_COUNTRY_ID' AND PARAM_ORDER_TYPE = 'ASC' THEN `category_address_country`.`CAT_COUNTRY_ID` END ASC, 
		CASE WHEN PARAM_ORDER_FIELD = 'CAT_COUNTRY_ID' AND PARAM_ORDER_TYPE = 'DESC' THEN `category_address_country`.`CAT_COUNTRY_ID` END DESC,	
		CASE WHEN PARAM_ORDER_FIELD = 'CAT_COUNTRY_GLOBAL_ID' AND PARAM_ORDER_TYPE = 'ASC' THEN `category_address_country`.`CAT_COUNTRY_GLOBAL_ID` END ASC, 
		CASE WHEN PARAM_ORDER_FIELD = 'CAT_COUNTRY_GLOBAL_ID' AND PARAM_ORDER_TYPE = 'DESC' THEN `category_address_country`.`CAT_COUNTRY_GLOBAL_ID` END DESC,	
		CASE WHEN PARAM_ORDER_FIELD = 'CAT_COUNTRY_CODE' AND PARAM_ORDER_TYPE = 'ASC' THEN `category_address_country`.`CAT_COUNTRY_CODE` END ASC, 
		CASE WHEN PARAM_ORDER_FIELD = 'CAT_COUNTRY_CODE' AND PARAM_ORDER_TYPE = 'DESC' THEN `category_address_country`.`CAT_COUNTRY_CODE` END DESC,	
		CASE WHEN PARAM_ORDER_FIELD = 'CAT_COUNTRY_DESCRIPTION' AND PARAM_ORDER_TYPE = 'ASC' THEN `category_address_country`.`CAT_COUNTRY_DESCRIPTION` END ASC, 
		CASE WHEN PARAM_ORDER_FIELD = 'CAT_COUNTRY_DESCRIPTION' AND PARAM_ORDER_TYPE = 'DESC' THEN `category_address_country`.`CAT_COUNTRY_DESCRIPTION` END DESC,	
		CASE WHEN PARAM_ORDER_FIELD = 'CAT_COUNTRY_STATUS' AND PARAM_ORDER_TYPE = 'ASC' THEN `category_address_country`.`CAT_COUNTRY_STATUS` END ASC, 
		CASE WHEN PARAM_ORDER_FIELD = 'CAT_COUNTRY_STATUS' AND PARAM_ORDER_TYPE = 'DESC' THEN `category_address_country`.`CAT_COUNTRY_STATUS` END DESC,	
		CASE WHEN PARAM_ORDER_FIELD = 'CAT_COUNTRY_SYSTEM_GENERATED' AND PARAM_ORDER_TYPE = 'ASC' THEN `category_address_country`.`CAT_COUNTRY_SYSTEM_GENERATED` END ASC, 
		CASE WHEN PARAM_ORDER_FIELD = 'CAT_COUNTRY_SYSTEM_GENERATED' AND PARAM_ORDER_TYPE = 'DESC' THEN `category_address_country`.`CAT_COUNTRY_SYSTEM_GENERATED` END DESC,	
		
		-- EXTRA
		CASE WHEN PARAM_ORDER_FIELD <> 'CAT_REGION_DESCRIPTION' THEN `category_address_region`.`CAT_REGION_DESCRIPTION` END ASC
		
	-- LIMIT & OFFSET
	-- ####################################################		
	LIMIT PARAM_SKIP, PARAM_LIMIT;
	
	
	
	-- EXIT PROCEDURE
	-- =========================================================================================
	LEAVE SP_GET;
			
END ;;
DELIMITER ;
/*!50003 SET sql_mode              = @saved_sql_mode */ ;
/*!50003 SET character_set_client  = @saved_cs_client */ ;
/*!50003 SET character_set_results = @saved_cs_results */ ;
/*!50003 SET collation_connection  = @saved_col_connection */ ;
/*!50003 DROP PROCEDURE IF EXISTS `CATEGORY_ADDRESS_REGION_SAVE` */;
/*!50003 SET @saved_cs_client      = @@character_set_client */ ;
/*!50003 SET @saved_cs_results     = @@character_set_results */ ;
/*!50003 SET @saved_col_connection = @@collation_connection */ ;
/*!50003 SET character_set_client  = latin1 */ ;
/*!50003 SET character_set_results = latin1 */ ;
/*!50003 SET collation_connection  = latin1_swedish_ci */ ;
/*!50003 SET @saved_sql_mode       = @@sql_mode */ ;
/*!50003 SET sql_mode              = '' */ ;
DELIMITER ;;
CREATE DEFINER=`root`@`localhost` PROCEDURE `CATEGORY_ADDRESS_REGION_SAVE`(
	IN `PARAM_CAT_REGION_ID` BIGINT,
	IN `PARAM_CAT_REGION_CAT_COUNTRY_ID` BIGINT,
	IN `PARAM_CAT_REGION_CODE` VARCHAR(50),
	IN `PARAM_CAT_REGION_DESCRIPTION` VARCHAR(500),
	IN `PARAM_CAT_REGION_STATUS` TINYINT,

	IN `PARAM_REQUESTER_USERNAME` VARCHAR(500),
	IN `PARAM_REQUESTER_PASSWORD` VARCHAR(500),
	IN `PARAM_REQUESTER_PROXY_ID` BIGINT,
	IN `PARAM_REQUESTER_PROXY_PASSWORD` VARCHAR(1000),
	IN `PARAM_REQUESTER_DEVICE_PUBLIC_KEY` VARCHAR(1000),
	IN `PARAM_REQUESTER_DEVICE_PRIVATE_KEY` VARCHAR(1000),
	
	IN `PARAM_REQUESTER_IP` VARCHAR(1000),
	IN `PARAM_UNIQUE_SESSION_ID` VARCHAR(1000),
	IN `PARAM_SUPPRESS_RETURN` BIT,
	
	IN `PARAM_SYNC_SERVER_DESCRIPTION` VARCHAR(500), 
	IN `PARAM_SYNC_SERVER_UNIQUE_KEY` VARCHAR(500)
)
SP_SAVE:
BEGIN


	-- 1) DECLARE LOCAL PARAMETERS
	-- _______________________________________________________________________
	
	-- Status
	-- ...........................................
	DECLARE STATUS_INACTIVE TINYINT DEFAULT 1;
	DECLARE STATUS_ACTIVE TINYINT DEFAULT 2;
	DECLARE STATUS_CLOSED TINYINT DEFAULT 3;
	DECLARE STATUS_COMPLETED TINYINT DEFAULT 4;

	-- Audit Handler
	-- ...........................................
	DECLARE TEMP_RECORD_EXISTS BIT DEFAULT 0;
	DECLARE TEMP_MODULE_KEYWORD VARCHAR(500) DEFAULT 'category_address_region';
	DECLARE TEMP_SP_OBJECTIVE VARCHAR(500) DEFAULT 'add/edit Address: Region record';
	DECLARE TEMP_ERR_MESSAGE VARCHAR(500) DEFAULT '';
	DECLARE ERR BIGINT DEFAULT 0;
	DECLARE TEMP_RECORD_CHANGES VARCHAR(16000) DEFAULT '';
	DECLARE TEMP_RECORD_BINDED BIT DEFAULT 0;

	-- Authentication
	-- ...........................................
	DECLARE TEMP_ACCESS_RIGHTS_DENIED BIT DEFAULT 0;
	DECLARE TEMP_ACCESS_RIGHTS_HAS_OVERRIDE BIT DEFAULT 0;
	DECLARE TEMP_SYNC_SERVER_ID BIGINT DEFAULT 0;
	DECLARE TEMP_SYNC_IS_SERVER_REQUEST BIT DEFAULT 0;
	DECLARE TEMP_AUTHENTICATED_ACCOUNT_ID BIGINT DEFAULT `ACCOUNT_MEMBER@ACC_ACCOUNT_ID_FROM_LOGIN`(PARAM_REQUESTER_USERNAME, PARAM_REQUESTER_PASSWORD);
	DECLARE TEMP_AUTHENTICATED_ACCOUNT_LEVEL BIGINT DEFAULT 0;
	DECLARE TEMP_AUTHENTICATED_ACCOUNT_GROUP BIGINT DEFAULT 0;
	
	-- Local Parameters
	-- ...........................................
	DECLARE TEMP_NOW DATETIME(6) DEFAULT `SYSTEM_VAR@NOW`('', 1);
	DECLARE TEMP_RECORD_COUNT BIGINT DEFAULT 0;

	-- AutoGen Parameters
	-- ...........................................
	DECLARE PARAM_CAT_REGION_GLOBAL_ID VARCHAR(400) DEFAULT ''; 
	DECLARE PARAM_CAT_REGION_SYSTEM_GENERATED TINYINT DEFAULT 0; 
	
	-- Local value holder
	-- ...........................................
	DECLARE TEMP_CAT_REGION_GLOBAL_ID VARCHAR(400) DEFAULT ''; 
	DECLARE TEMP_CAT_REGION_CAT_COUNTRY_ID BIGINT DEFAULT 0; 
	DECLARE TEMP_CAT_REGION_CODE VARCHAR(50) DEFAULT ''; 
	DECLARE TEMP_CAT_REGION_DESCRIPTION VARCHAR(500) DEFAULT ''; 
	DECLARE TEMP_CAT_REGION_STATUS TINYINT DEFAULT 0; 
	DECLARE TEMP_CAT_REGION_SYSTEM_GENERATED TINYINT DEFAULT 0; 
	


	-- 2) Try Catch / Throw
	-- _______________________________________________________________________
	DECLARE EXIT HANDLER FOR SQLEXCEPTION
	BEGIN
		RESIGNAL;
	END;



	-- 3) Prepare SYNC
	-- _______________________________________________________________________

	-- IS RECORD EXISTS		
	-- ####################################################	
	SET TEMP_RECORD_EXISTS = `CATEGORY_ADDRESS_REGION@CAT_REGION_ID_EXISTS`(PARAM_CAT_REGION_ID, 0);

		
		
	-- 4) PREPARE AUTOGEN DATA (IF EXISTS)
	-- _______________________________________________________________________
	IF TEMP_SYNC_IS_SERVER_REQUEST = 0 THEN
		-- Just to keep at least one line within condition
		SET TEMP_SYNC_IS_SERVER_REQUEST = 0;
		
		-- Actual Functionalities here
		-- USE DEFAULT VALUE (String)
		-- USE DEFAULT VALUE (String)
		SET PARAM_CAT_REGION_GLOBAL_ID = `SYSTEM_VAR@RANDOM_UNIQUE_ALPHA32`;
		-- USE DEFAULT VALUE (String)
		SET PARAM_CAT_REGION_SYSTEM_GENERATED = 1;
	-- USE TIMESTAMP
	END IF;



	-- 5) IF ALREADY EXIST, FILL MISSING DATA
	-- _______________________________________________________________________
	IF TEMP_RECORD_EXISTS = 1 THEN
		SELECT
			`category_address_region`.`CAT_REGION_GLOBAL_ID`, 	
			`category_address_region`.`CAT_REGION_CAT_COUNTRY_ID`, 	
			`category_address_region`.`CAT_REGION_CODE`, 	
			`category_address_region`.`CAT_REGION_DESCRIPTION`, 	
			`category_address_region`.`CAT_REGION_STATUS`, 	
			`category_address_region`.`CAT_REGION_SYSTEM_GENERATED`	
		INTO
			TEMP_CAT_REGION_GLOBAL_ID, 	
			TEMP_CAT_REGION_CAT_COUNTRY_ID, 	
			TEMP_CAT_REGION_CODE, 	
			TEMP_CAT_REGION_DESCRIPTION, 	
			TEMP_CAT_REGION_STATUS, 	
			TEMP_CAT_REGION_SYSTEM_GENERATED	

		FROM `category_address_region`
		WHERE
			`category_address_region`.`CAT_REGION_ID` = PARAM_CAT_REGION_ID
		LIMIT 1;

		-- Replace NULLs with the existing data.
		SET PARAM_CAT_REGION_CAT_COUNTRY_ID = `SYSTEM_VAR@REPLACE_NULL@BIGINT`(PARAM_CAT_REGION_CAT_COUNTRY_ID, TEMP_CAT_REGION_CAT_COUNTRY_ID, 1, 1);
		SET PARAM_CAT_REGION_CODE = `SYSTEM_VAR@REPLACE_NULL@NVARCHAR`(PARAM_CAT_REGION_CODE, TEMP_CAT_REGION_CODE, 0);
		SET PARAM_CAT_REGION_DESCRIPTION = `SYSTEM_VAR@REPLACE_NULL@NVARCHAR`(PARAM_CAT_REGION_DESCRIPTION, TEMP_CAT_REGION_DESCRIPTION, 1);
		SET PARAM_CAT_REGION_STATUS = `SYSTEM_VAR@REPLACE_NULL@TINYINT`(PARAM_CAT_REGION_STATUS, TEMP_CAT_REGION_STATUS, 1, 1);
		
		-- AUTO GEN (NON-UPDATABLES)		
		SET PARAM_CAT_REGION_GLOBAL_ID = TEMP_CAT_REGION_GLOBAL_ID;
		SET PARAM_CAT_REGION_SYSTEM_GENERATED = TEMP_CAT_REGION_SYSTEM_GENERATED;
		
		-- AUTO GEN (UPDATABLE WITH STATUS CHANGE)

		-- AUTO GEN (UPDATABLE WITH STATUS [ACTIVE/INACTIVE] CHANGE)
		
	ELSE
		SET PARAM_CAT_REGION_CAT_COUNTRY_ID = `SYSTEM_VAR@REPLACE_NULL@BIGINT`(PARAM_CAT_REGION_CAT_COUNTRY_ID, 0, 1, 1);
		SET PARAM_CAT_REGION_CODE = `SYSTEM_VAR@REPLACE_NULL@NVARCHAR`(PARAM_CAT_REGION_CODE, '', 0);
		SET PARAM_CAT_REGION_DESCRIPTION = `SYSTEM_VAR@REPLACE_NULL@NVARCHAR`(PARAM_CAT_REGION_DESCRIPTION, '', 1);
		SET PARAM_CAT_REGION_STATUS = `SYSTEM_VAR@REPLACE_NULL@TINYINT`(PARAM_CAT_REGION_STATUS, 0, 1, 1);
		
	END IF;

	

	-- 6) PREPARE AUDIT TRAIL
	-- _______________________________________________________________________
	IF BINARY TEMP_CAT_REGION_GLOBAL_ID <> PARAM_CAT_REGION_GLOBAL_ID THEN
		SET TEMP_RECORD_CHANGES = 
		`SYSTEM_VAR@CONCAT_ADD`(' | ', TEMP_RECORD_CHANGES, CONCAT_WS(' ', 'ID: "', TEMP_CAT_REGION_GLOBAL_ID, '" > "', PARAM_CAT_REGION_GLOBAL_ID, '"'));
	END IF;
	IF TEMP_CAT_REGION_CAT_COUNTRY_ID <> PARAM_CAT_REGION_CAT_COUNTRY_ID THEN
		SET TEMP_RECORD_CHANGES = 
		`SYSTEM_VAR@CONCAT_ADD`(' | ', TEMP_RECORD_CHANGES, CONCAT_WS(' ', 'Country: "', TEMP_CAT_REGION_CAT_COUNTRY_ID, '" > "', PARAM_CAT_REGION_CAT_COUNTRY_ID, '"'));
	END IF;	
	IF BINARY TEMP_CAT_REGION_CODE <> PARAM_CAT_REGION_CODE THEN
		SET TEMP_RECORD_CHANGES = 
		`SYSTEM_VAR@CONCAT_ADD`(' | ', TEMP_RECORD_CHANGES, CONCAT_WS(' ', 'Short Description: "', TEMP_CAT_REGION_CODE, '" > "', PARAM_CAT_REGION_CODE, '"'));
	END IF;
	IF BINARY TEMP_CAT_REGION_DESCRIPTION <> PARAM_CAT_REGION_DESCRIPTION THEN
		SET TEMP_RECORD_CHANGES = 
		`SYSTEM_VAR@CONCAT_ADD`(' | ', TEMP_RECORD_CHANGES, CONCAT_WS(' ', 'Description: "', TEMP_CAT_REGION_DESCRIPTION, '" > "', PARAM_CAT_REGION_DESCRIPTION, '"'));
	END IF;
	IF TEMP_CAT_REGION_STATUS <> PARAM_CAT_REGION_STATUS THEN
		SET TEMP_RECORD_CHANGES = 
		`SYSTEM_VAR@CONCAT_ADD`(' | ', TEMP_RECORD_CHANGES, CONCAT_WS(' ', 'Status: "', TEMP_CAT_REGION_STATUS, '" > "', PARAM_CAT_REGION_STATUS, '"'));
	END IF;	
	IF TEMP_CAT_REGION_SYSTEM_GENERATED <> PARAM_CAT_REGION_SYSTEM_GENERATED THEN
		SET TEMP_RECORD_CHANGES = 
		`SYSTEM_VAR@CONCAT_ADD`(' | ', TEMP_RECORD_CHANGES, CONCAT_WS(' ', 'System Generated: "', TEMP_CAT_REGION_SYSTEM_GENERATED, '" > "', PARAM_CAT_REGION_SYSTEM_GENERATED, '"'));
	END IF;	
		
	-- No Changes in data, reject request
	-- ####################################################
	IF CHARACTER_LENGTH(TEMP_RECORD_CHANGES) = 0 THEN
		IF PARAM_SUPPRESS_RETURN = 0 THEN
			SELECT PARAM_CAT_REGION_ID AS INSERTED_ID;
		END IF;
		LEAVE SP_SAVE;
	END IF;



	-- 7) VALIDATE
	-- _______________________________________________________________________

	-- Access Rights [Device]
	-- ####################################################
	IF `ACCOUNT_DEVICE@HAS_PERMISSION`(PARAM_REQUESTER_DEVICE_PUBLIC_KEY, PARAM_REQUESTER_DEVICE_PRIVATE_KEY) = 0 THEN
		SET TEMP_ERR_MESSAGE = 'Your device is not authorized yet to access this server.';
		SET ERR = `RAISERROR`(TEMP_ERR_MESSAGE);		
	END IF;
		
		
	-- Access Rights [Account]
	-- ####################################################
	
	IF 
		-- [ADD] Access Rights
		(
			TEMP_RECORD_EXISTS = 0 AND
			`ACCOUNT_ACCESS_RIGHTS@HAS_PERMISSION`(PARAM_REQUESTER_USERNAME, PARAM_REQUESTER_PASSWORD, 0, TEMP_MODULE_KEYWORD, 2) = 0 
		) OR
		
		-- [EDIT] Access Rights
		(
			TEMP_RECORD_EXISTS = 1 AND
			`ACCOUNT_ACCESS_RIGHTS@HAS_PERMISSION`(PARAM_REQUESTER_USERNAME, PARAM_REQUESTER_PASSWORD, 0, TEMP_MODULE_KEYWORD, 3) = 0 
		)
	THEN
		SET TEMP_ACCESS_RIGHTS_DENIED = 1;
		CALL `ACCOUNT_ACCESS_RIGHTS_DENY`
		(
			0, TEMP_MODULE_KEYWORD, PARAM_CAT_REGION_ID, 0, TEMP_SP_OBJECTIVE, TEMP_RECORD_CHANGES, 
			PARAM_REQUESTER_USERNAME, PARAM_REQUESTER_PASSWORD, 
			PARAM_REQUESTER_PROXY_ID, PARAM_REQUESTER_PROXY_PASSWORD,
			PARAM_REQUESTER_DEVICE_PUBLIC_KEY, PARAM_REQUESTER_DEVICE_PRIVATE_KEY,
			PARAM_REQUESTER_IP, PARAM_UNIQUE_SESSION_ID,
			TEMP_SYNC_SERVER_ID, PARAM_SUPPRESS_RETURN
		);
	END IF;
	SET TEMP_ACCESS_RIGHTS_HAS_OVERRIDE = `ACCOUNT_ACCESS_RIGHTS@HAS_PERMISSION`(PARAM_REQUESTER_USERNAME, PARAM_REQUESTER_PASSWORD, 0, TEMP_MODULE_KEYWORD, 4);
	

	-- Validation
	-- ####################################################
	IF TEMP_SYNC_IS_SERVER_REQUEST = 0 THEN
	
		-- SYSTEM GENERATED = TRUE
		-- ...........................................
		IF TEMP_CAT_REGION_SYSTEM_GENERATED = STATUS_ACTIVE THEN
		CALL `VALIDATION_SYSTEM_GENERATED`
		(
			PARAM_CAT_REGION_ID,
			TEMP_CAT_REGION_DESCRIPTION, ''
		);
		END IF;

		-- FOREIGN KEY EXISTS
		-- ...........................................
		IF `CATEGORY_ADDRESS_COUNTRY@CAT_COUNTRY_ID_EXISTS`(PARAM_CAT_REGION_CAT_COUNTRY_ID, 0) =  0 THEN
			SET TEMP_ERR_MESSAGE = CONCAT_WS(' ', 'Given Country does not exists or is inactive. ID: ', PARAM_CAT_REGION_CAT_COUNTRY_ID);
			SET ERR = `RAISERROR`(TEMP_ERR_MESSAGE);
		END IF;
		
		-- FOREIGN (OPTIONAL)KEY EXISTS [Validates if not null]
		-- ...........................................
		
		-- IS_ALLOW_NULL = FALSE
		-- ...........................................
		IF PARAM_CAT_REGION_CODE IS NULL THEN
			CALL `VALIDATION_MISSING_FIELD`('`CAT_REGION_CODE`', '`NULL`');
		END IF;
				
		-- IS_ALLOW_ZERO = FALSE
		-- ...........................................
		IF PARAM_CAT_REGION_STATUS = 0 THEN
			CALL `VALIDATION_MISSING_FIELD`('`CAT_REGION_STATUS`', '`NULL`');
		END IF;		
		IF PARAM_CAT_REGION_SYSTEM_GENERATED = 0 THEN
			CALL `VALIDATION_MISSING_FIELD`('`CAT_REGION_SYSTEM_GENERATED`', '`NULL`');
		END IF;		
		
		-- IS_ALLOW_NEGATIVE = FALSE
		-- ...........................................
		IF PARAM_CAT_REGION_STATUS < 0 THEN
			CALL `VALIDATION_NEGATIVE`('`CAT_REGION_STATUS`', PARAM_CAT_REGION_STATUS);
		END IF;		
		IF PARAM_CAT_REGION_SYSTEM_GENERATED < 0 THEN
			CALL `VALIDATION_NEGATIVE`('`CAT_REGION_SYSTEM_GENERATED`', PARAM_CAT_REGION_SYSTEM_GENERATED);
		END IF;		
		
		-- IS_ALLOW_EMPTY_STRING = FALSE
		-- ...........................................
		IF `SYSTEM_VAR@IS_NULL@NVARCHAR`(PARAM_CAT_REGION_GLOBAL_ID, 1) = 1 THEN
			CALL `VALIDATION_MISSING_FIELD`('`CAT_REGION_GLOBAL_ID`', '`NULL`');
		END IF;
		IF `SYSTEM_VAR@IS_NULL@NVARCHAR`(PARAM_CAT_REGION_DESCRIPTION, 1) = 1 THEN
			CALL `VALIDATION_MISSING_FIELD`('`CAT_REGION_DESCRIPTION`', '`NULL`');
		END IF;
		
		-- IS_STATUS
		-- ...........................................
		IF `SYSTEM_STATUS@STATUS_ID_EXISTS`(PARAM_CAT_REGION_STATUS, 0) = 0 THEN
			SET TEMP_ERR_MESSAGE = CONCAT_WS(' ', 'Given STATUS[Status] does not exists or is inactive. ID: ', PARAM_CAT_REGION_STATUS);
			SET ERR = `RAISERROR`(TEMP_ERR_MESSAGE);
		END IF;
		
		-- IS STATUS Active / Inactive
		-- ...........................................
		
		-- Minimum / Maximum Value
		-- ...........................................
		
		-- IS_UNIQUE = TRUE
		-- ...........................................
		IF
		(
			SELECT COUNT(`category_address_region`.`CAT_REGION_ID`)
			FROM `category_address_region`
			WHERE		
				`category_address_region`.`CAT_REGION_GLOBAL_ID` = PARAM_CAT_REGION_GLOBAL_ID AND		
				`category_address_region`.`CAT_REGION_ID` <> PARAM_CAT_REGION_ID
		) >= 1
		THEN
			CALL `VALIDATION_REDUNDANT_ENTRY`(PARAM_CAT_REGION_DESCRIPTION);
		END IF;
		
		-- RECORD IDENTIFIER
		-- ...........................................
		IF
		(
			SELECT COUNT(`category_address_region`.`CAT_REGION_ID`)
			FROM `category_address_region`
			WHERE
				`category_address_region`.`CAT_REGION_CAT_COUNTRY_ID` = PARAM_CAT_REGION_CAT_COUNTRY_ID AND
				`category_address_region`.`CAT_REGION_DESCRIPTION` = PARAM_CAT_REGION_DESCRIPTION AND
				`category_address_region`.`CAT_REGION_ID` <> PARAM_CAT_REGION_ID
		) >= 1
		THEN
			CALL `VALIDATION_REDUNDANT_ENTRY`(PARAM_CAT_REGION_DESCRIPTION);
		END IF;
		
		
		-- ON_UPDATE VALIDATION 
		-- ...........................................
		IF TEMP_RECORD_EXISTS = 1 THEN	
		
			-- Just to keep at least one line within condition
			SET TEMP_RECORD_EXISTS = 1;
			
		END IF;
		
	END IF;



	-- 8) INSERT / UPDATE
	-- _______________________________________________________________________

	-- INSERT NEW DATA
	-- ####################################################
	IF TEMP_RECORD_EXISTS = 0 THEN

		INSERT INTO
		`category_address_region`
		(
			`category_address_region`.`CAT_REGION_GLOBAL_ID`, 
			`category_address_region`.`CAT_REGION_CAT_COUNTRY_ID`, 
			`category_address_region`.`CAT_REGION_CODE`, 
			`category_address_region`.`CAT_REGION_DESCRIPTION`, 
			`category_address_region`.`CAT_REGION_STATUS`, 
			`category_address_region`.`CAT_REGION_SYSTEM_GENERATED`
		)
		VALUES
		(
			PARAM_CAT_REGION_GLOBAL_ID, 
			PARAM_CAT_REGION_CAT_COUNTRY_ID, 
			PARAM_CAT_REGION_CODE, 
			PARAM_CAT_REGION_DESCRIPTION, 
			PARAM_CAT_REGION_STATUS, 
			PARAM_CAT_REGION_SYSTEM_GENERATED
		);	
		
		-- Update Audit trail with new ID	
		SET PARAM_CAT_REGION_ID = LAST_INSERT_ID();



	-- UPDATING EXISTING RECORD
	-- ####################################################
	ELSE
		UPDATE `category_address_region`
		SET
			`category_address_region`.`CAT_REGION_GLOBAL_ID` = PARAM_CAT_REGION_GLOBAL_ID, 
			`category_address_region`.`CAT_REGION_CAT_COUNTRY_ID` = PARAM_CAT_REGION_CAT_COUNTRY_ID, 
			`category_address_region`.`CAT_REGION_CODE` = PARAM_CAT_REGION_CODE, 
			`category_address_region`.`CAT_REGION_DESCRIPTION` = PARAM_CAT_REGION_DESCRIPTION, 
			`category_address_region`.`CAT_REGION_STATUS` = PARAM_CAT_REGION_STATUS, 
			`category_address_region`.`CAT_REGION_SYSTEM_GENERATED` = PARAM_CAT_REGION_SYSTEM_GENERATED
		WHERE
			`category_address_region`.`CAT_REGION_ID` = PARAM_CAT_REGION_ID;

	END IF;

	
	-- 9) AUDIT TRAIL
	-- _______________________________________________________________________
	CALL `ACCOUNT_AUDIT_TRAIL_SAVE`
	(
		0, TEMP_MODULE_KEYWORD, PARAM_CAT_REGION_ID, 0, 'SAVE', TEMP_SP_OBJECTIVE, TEMP_RECORD_CHANGES, 
		PARAM_REQUESTER_USERNAME, PARAM_REQUESTER_PASSWORD, 
		PARAM_REQUESTER_PROXY_ID, PARAM_REQUESTER_PROXY_PASSWORD,
		PARAM_REQUESTER_DEVICE_PUBLIC_KEY, PARAM_REQUESTER_DEVICE_PRIVATE_KEY,
		PARAM_REQUESTER_IP, PARAM_UNIQUE_SESSION_ID,
		TEMP_SYNC_SERVER_ID, PARAM_SUPPRESS_RETURN
	);
	

	-- 10) RETURN RESULT
	-- _______________________________________________________________________
	IF PARAM_SUPPRESS_RETURN = 0 THEN
		SELECT PARAM_CAT_REGION_ID AS INSERTED_ID;
	END IF;
	LEAVE SP_SAVE;


END ;;
DELIMITER ;
/*!50003 SET sql_mode              = @saved_sql_mode */ ;
/*!50003 SET character_set_client  = @saved_cs_client */ ;
/*!50003 SET character_set_results = @saved_cs_results */ ;
/*!50003 SET collation_connection  = @saved_col_connection */ ;
/*!50003 DROP PROCEDURE IF EXISTS `CATEGORY_DEPARTMENT_DELETE` */;
/*!50003 SET @saved_cs_client      = @@character_set_client */ ;
/*!50003 SET @saved_cs_results     = @@character_set_results */ ;
/*!50003 SET @saved_col_connection = @@collation_connection */ ;
/*!50003 SET character_set_client  = latin1 */ ;
/*!50003 SET character_set_results = latin1 */ ;
/*!50003 SET collation_connection  = latin1_swedish_ci */ ;
/*!50003 SET @saved_sql_mode       = @@sql_mode */ ;
/*!50003 SET sql_mode              = '' */ ;
DELIMITER ;;
CREATE DEFINER=`root`@`localhost` PROCEDURE `CATEGORY_DEPARTMENT_DELETE`(
	IN `PARAM_CAT_DEPARTMENT_ID` BIGINT,

	IN `PARAM_REQUESTER_USERNAME` VARCHAR(500),
	IN `PARAM_REQUESTER_PASSWORD` VARCHAR(500),
	IN `PARAM_REQUESTER_PROXY_ID` BIGINT,
	IN `PARAM_REQUESTER_PROXY_PASSWORD` VARCHAR(1000),
	IN `PARAM_REQUESTER_DEVICE_PUBLIC_KEY` VARCHAR(1000),
	IN `PARAM_REQUESTER_DEVICE_PRIVATE_KEY` VARCHAR(1000),
	
	IN `PARAM_REQUESTER_IP` VARCHAR(1000),
	IN `PARAM_UNIQUE_SESSION_ID` VARCHAR(1000),
	IN `PARAM_SUPPRESS_RETURN` BIT,
	
	IN `PARAM_SYNC_SERVER_DESCRIPTION` VARCHAR(500), 
	IN `PARAM_SYNC_SERVER_UNIQUE_KEY` VARCHAR(500)
)
SP_DELETE:
BEGIN

	-- 1) DECLARE LOCAL PARAMETERS
	-- _______________________________________________________________________
	
	-- Status
	-- ...........................................
	DECLARE STATUS_INACTIVE TINYINT DEFAULT 1;
	DECLARE STATUS_ACTIVE TINYINT DEFAULT 2;
	DECLARE STATUS_CLOSED TINYINT DEFAULT 3;
	DECLARE STATUS_COMPLETED TINYINT DEFAULT 4;
	
	-- Audit Handler
	-- ...........................................
	DECLARE TEMP_RECORD_EXISTS BIT DEFAULT 0;
	DECLARE TEMP_MODULE_KEYWORD VARCHAR(500) DEFAULT 'category_department';
	DECLARE TEMP_SP_OBJECTIVE VARCHAR(500) DEFAULT 'delete Department record';
	DECLARE TEMP_ERR_MESSAGE VARCHAR(500) DEFAULT '';
	DECLARE ERR BIGINT DEFAULT 0;
	DECLARE TEMP_RECORD_CHANGES VARCHAR(16000) DEFAULT '';
	DECLARE TEMP_RECORD_BINDED BIT DEFAULT 0;
	
	DECLARE TEMP_RECORD_BINDED_ID BIGINT DEFAULT 0;
	DECLARE TEMP_RECORD_BINDED_SERVER_ID BIGINT DEFAULT 0;
	
	-- Authentication
	-- ...........................................
	DECLARE TEMP_ACCESS_RIGHTS_DENIED BIT DEFAULT 0;
	DECLARE TEMP_SYNC_SERVER_ID BIGINT DEFAULT 0;
	DECLARE TEMP_SYNC_IS_SERVER_REQUEST BIT DEFAULT 0;
	DECLARE TEMP_AUTHENTICATED_ACCOUNT_ID BIGINT DEFAULT `ACCOUNT_MEMBER@ACC_ACCOUNT_ID_FROM_LOGIN`(PARAM_REQUESTER_USERNAME, PARAM_REQUESTER_PASSWORD);
	DECLARE TEMP_AUTHENTICATED_ACCOUNT_LEVEL BIGINT DEFAULT 0;
	DECLARE TEMP_AUTHENTICATED_ACCOUNT_GROUP BIGINT DEFAULT 0;

	-- Local value holder
	-- ...........................................
		DECLARE TEMP_CAT_DEPARTMENT_DESCRIPTION VARCHAR(400) DEFAULT ''; 
		DECLARE TEMP_CAT_DEPARTMENT_STATUS TINYINT DEFAULT 0; 

	
	
	-- 2) Try Catch / Throw
	-- _______________________________________________________________________
	DECLARE EXIT HANDLER FOR SQLEXCEPTION
	BEGIN
		RESIGNAL;
	END;

	
	-- 3) Prepare SYNC
	-- _______________________________________________________________________
	
	-- IS RECORD EXISTS		
	-- ####################################################		
	SET TEMP_RECORD_EXISTS = `CATEGORY_DEPARTMENT@CAT_DEPARTMENT_ID_EXISTS`(PARAM_CAT_DEPARTMENT_ID, 0);


	-- 4) IF ALREADY EXIST, FILL MISSING DATA
	-- _______________________________________________________________________
	IF TEMP_RECORD_EXISTS = 1 THEN
		SELECT
				`category_department`.`CAT_DEPARTMENT_DESCRIPTION`, 	
				`category_department`.`CAT_DEPARTMENT_STATUS`	
		INTO
				TEMP_CAT_DEPARTMENT_DESCRIPTION, 	
				TEMP_CAT_DEPARTMENT_STATUS	

		FROM `category_department`
		WHERE
			`category_department`.`CAT_DEPARTMENT_ID` = PARAM_CAT_DEPARTMENT_ID
		LIMIT 1;

	ELSE 
		IF TEMP_SYNC_IS_SERVER_REQUEST = 0 THEN
			SET TEMP_ERR_MESSAGE = CONCAT_WS(' ', 'Given Department does not exists or is inactive. ID:', PARAM_CAT_DEPARTMENT_ID);
			SET ERR = `RAISERROR`(TEMP_ERR_MESSAGE);		
		END IF;
		LEAVE SP_DELETE;
		
	END IF;



	-- 5) PREPARE AUDIT TRAIL
	-- _______________________________________________________________________
	
		SET TEMP_RECORD_CHANGES = 
		`SYSTEM_VAR@CONCAT_ADD`(' | ', TEMP_RECORD_CHANGES, CONCAT_WS(' ', 'Description: "', TEMP_CAT_DEPARTMENT_DESCRIPTION, '" > " DELETED "'));
		SET TEMP_RECORD_CHANGES = 
		`SYSTEM_VAR@CONCAT_ADD`(' | ', TEMP_RECORD_CHANGES, CONCAT_WS(' ', 'Status: "', TEMP_CAT_DEPARTMENT_STATUS, '" > " DELETED "'));


	-- 6) VALIDATE
	-- _______________________________________________________________________
	
	-- Access Rights [Device]
	-- ####################################################
	IF `ACCOUNT_DEVICE@HAS_PERMISSION`(PARAM_REQUESTER_DEVICE_PUBLIC_KEY, PARAM_REQUESTER_DEVICE_PRIVATE_KEY) = 0 THEN
		SET TEMP_ERR_MESSAGE = 'Your device is not authorized yet to access this server.';
		SET ERR = `RAISERROR`(TEMP_ERR_MESSAGE);		
	END IF;
		
		
	-- Access Rights [Account]
	-- ####################################################	
	
	IF 
		-- [DELETE] Access Rights
		`ACCOUNT_ACCESS_RIGHTS@HAS_PERMISSION`(PARAM_REQUESTER_USERNAME, PARAM_REQUESTER_PASSWORD, 0, TEMP_MODULE_KEYWORD, 4) = 0 AND
		`ACCOUNT_ACCESS_RIGHTS@PROXY_PERMISSION`(PARAM_REQUESTER_PROXY_ID, PARAM_REQUESTER_PROXY_PASSWORD, 0, TEMP_MODULE_KEYWORD, 4) = 0
	THEN
		SET TEMP_ACCESS_RIGHTS_DENIED = 1;
		CALL `ACCOUNT_ACCESS_RIGHTS_DENY`
		(
			0, TEMP_MODULE_KEYWORD, PARAM_CAT_DEPARTMENT_ID, 0, TEMP_SP_OBJECTIVE, TEMP_RECORD_CHANGES, 
			PARAM_REQUESTER_USERNAME, PARAM_REQUESTER_PASSWORD, 
			PARAM_REQUESTER_PROXY_ID, PARAM_REQUESTER_PROXY_PASSWORD,
			PARAM_REQUESTER_DEVICE_PUBLIC_KEY, PARAM_REQUESTER_DEVICE_PRIVATE_KEY,
			PARAM_REQUESTER_IP, PARAM_UNIQUE_SESSION_ID,
			TEMP_SYNC_SERVER_ID, PARAM_SUPPRESS_RETURN
		);
	END IF;

	
	-- If already used, cannot remove record
	-- ####################################################
	IF
	(
		SELECT
			COUNT(`category_section`.`CAT_SECTION_CAT_DEPARTMENT_ID`)
		FROM `category_section`
		WHERE
			`category_section`.`CAT_SECTION_CAT_DEPARTMENT_ID` = PARAM_CAT_DEPARTMENT_ID
		LIMIT 1
	) >= 1 
	THEN
		SET TEMP_RECORD_BINDED = 1;
		SET TEMP_ERR_MESSAGE = 'Section Record';
	END IF;
	IF
	(
		SELECT
			COUNT(`record_user`.`REC_USER_CAT_DEPARTMENT_ID`)
		FROM `record_user`
		WHERE
			`record_user`.`REC_USER_CAT_DEPARTMENT_ID` = PARAM_CAT_DEPARTMENT_ID
		LIMIT 1
	) >= 1 
	THEN
		SET TEMP_RECORD_BINDED = 1;
		SET TEMP_ERR_MESSAGE = 'User Record';
	END IF;
	IF
	(
		SELECT
			COUNT(`record_registration`.`REC_REGISTRATION_CAT_DEPARTMENT_ID`)
		FROM `record_registration`
		WHERE
			`record_registration`.`REC_REGISTRATION_CAT_DEPARTMENT_ID` = PARAM_CAT_DEPARTMENT_ID
		LIMIT 1
	) >= 1 
	THEN
		SET TEMP_RECORD_BINDED = 1;
		SET TEMP_ERR_MESSAGE = 'Registration Record';
	END IF;

	-- Leave Re-upload request
	-- ####################################################
	IF TEMP_RECORD_BINDED = 1 THEN
		IF TEMP_SYNC_IS_SERVER_REQUEST = 1 THEN
			
			LEAVE SP_DELETE;
		END IF;

		CALL `VALIDATION_DELETE_LINKED_RECORD`(TEMP_CAT_DEPARTMENT_DESCRIPTION, '', TEMP_ERR_MESSAGE); 
	END IF;


	-- 7) DELETE
	-- _______________________________________________________________________
	DELETE FROM `category_department`
	WHERE `category_department`.`CAT_DEPARTMENT_ID` = PARAM_CAT_DEPARTMENT_ID
	LIMIT 1;


	-- 8) AUDIT TRAIL
	-- _______________________________________________________________________
	CALL `ACCOUNT_AUDIT_TRAIL_SAVE`
	(
		0, TEMP_MODULE_KEYWORD, PARAM_CAT_DEPARTMENT_ID, 0, 'DELETE', TEMP_SP_OBJECTIVE, TEMP_RECORD_CHANGES, 
		PARAM_REQUESTER_USERNAME, PARAM_REQUESTER_PASSWORD, 
		PARAM_REQUESTER_PROXY_ID, PARAM_REQUESTER_PROXY_PASSWORD,
		PARAM_REQUESTER_DEVICE_PUBLIC_KEY, PARAM_REQUESTER_DEVICE_PRIVATE_KEY,
		PARAM_REQUESTER_IP, PARAM_UNIQUE_SESSION_ID,
		TEMP_SYNC_SERVER_ID, PARAM_SUPPRESS_RETURN
	);

END ;;
DELIMITER ;
/*!50003 SET sql_mode              = @saved_sql_mode */ ;
/*!50003 SET character_set_client  = @saved_cs_client */ ;
/*!50003 SET character_set_results = @saved_cs_results */ ;
/*!50003 SET collation_connection  = @saved_col_connection */ ;
/*!50003 DROP PROCEDURE IF EXISTS `CATEGORY_DEPARTMENT_GET` */;
/*!50003 SET @saved_cs_client      = @@character_set_client */ ;
/*!50003 SET @saved_cs_results     = @@character_set_results */ ;
/*!50003 SET @saved_col_connection = @@collation_connection */ ;
/*!50003 SET character_set_client  = latin1 */ ;
/*!50003 SET character_set_results = latin1 */ ;
/*!50003 SET collation_connection  = latin1_swedish_ci */ ;
/*!50003 SET @saved_sql_mode       = @@sql_mode */ ;
/*!50003 SET sql_mode              = '' */ ;
DELIMITER ;;
CREATE DEFINER=`root`@`localhost` PROCEDURE `CATEGORY_DEPARTMENT_GET`(
	IN `PARAM_CAT_DEPARTMENT_ID` BIGINT,	
	IN `PARAM_CAT_DEPARTMENT_DESCRIPTION` VARCHAR(400),	
	IN `PARAM_CAT_DEPARTMENT_STATUS` TINYINT,	
		
	IN `PARAM_ORDER_FIELD` VARCHAR(500),
	IN `PARAM_ORDER_TYPE` VARCHAR(500),
	IN `PARAM_SKIP` BIGINT,
	IN `PARAM_LIMIT` BIGINT,

	IN `PARAM_REQUESTER_USERNAME` VARCHAR(500),
	IN `PARAM_REQUESTER_PASSWORD` VARCHAR(500),
	IN `PARAM_REQUESTER_PROXY_ID` BIGINT,
	IN `PARAM_REQUESTER_PROXY_PASSWORD` VARCHAR(1000),
	IN `PARAM_REQUESTER_DEVICE_PUBLIC_KEY` VARCHAR(1000),
	IN `PARAM_REQUESTER_DEVICE_PRIVATE_KEY` VARCHAR(1000),
	
	IN `PARAM_REQUESTER_IP` VARCHAR(1000),
	IN `PARAM_UNIQUE_SESSION_ID` VARCHAR(1000),
	IN `PARAM_SUPPRESS_RETURN` BIT
)
SP_GET:
BEGIN

	-- Status
	-- =========================================================================================
	DECLARE STATUS_INACTIVE TINYINT DEFAULT 1;
	DECLARE STATUS_ACTIVE TINYINT DEFAULT 2;
	DECLARE STATUS_CLOSED TINYINT DEFAULT 3;
	DECLARE STATUS_COMPLETED TINYINT DEFAULT 4;
	
	-- Audit Handler
	-- =========================================================================================
	DECLARE TEMP_RECORD_EXISTS BIT DEFAULT 0;
	DECLARE TEMP_MODULE_KEYWORD VARCHAR(500) DEFAULT 'category_department';
	DECLARE TEMP_SP_OBJECTIVE VARCHAR(500) DEFAULT 'Retrieve Department record';
	DECLARE TEMP_ERR_MESSAGE VARCHAR(500) DEFAULT '';
	DECLARE ERR BIGINT DEFAULT 0;
	DECLARE TEMP_RECORD_CHANGES VARCHAR(16000) DEFAULT '';
	DECLARE TEMP_RECORD_BINDED BIT DEFAULT 0;
	
	DECLARE TEMP_RECORD_BINDED_ID BIGINT DEFAULT 0;
	DECLARE TEMP_RECORD_BINDED_SERVER_ID BIGINT DEFAULT 0;
	
	-- Authentication
	-- =========================================================================================
	DECLARE TEMP_ACCESS_RIGHTS_DENIED BIT DEFAULT 0;
	DECLARE TEMP_AUTHENTICATED_ACCOUNT_ID BIGINT DEFAULT `ACCOUNT_MEMBER@ACC_ACCOUNT_ID_FROM_LOGIN`(PARAM_REQUESTER_USERNAME, PARAM_REQUESTER_PASSWORD);
	DECLARE TEMP_AUTHENTICATED_ACCOUNT_LEVEL BIGINT DEFAULT 0;
	DECLARE TEMP_AUTHENTICATED_ACCOUNT_GROUP BIGINT DEFAULT 0;
	
	-- Local Parameters
	-- =========================================================================================
	DECLARE TEMP_NOW DATETIME(6) DEFAULT `SYSTEM_VAR@NOW`('', 1);
	DECLARE TEMP_RECORD_COUNT BIGINT DEFAULT 0;
	
	
	-- Check NULLs
	-- =========================================================================================
	DECLARE IS_NULL_CAT_DEPARTMENT_ID BIT DEFAULT `SYSTEM_VAR@IS_NULL@BIGINT`(PARAM_CAT_DEPARTMENT_ID, 1, 1);
	DECLARE IS_NULL_CAT_DEPARTMENT_DESCRIPTION BIT DEFAULT `SYSTEM_VAR@IS_NULL@NVARCHAR`(PARAM_CAT_DEPARTMENT_DESCRIPTION, 1);
	DECLARE IS_NULL_CAT_DEPARTMENT_STATUS BIT DEFAULT `SYSTEM_VAR@IS_NULL@TINYINT`(PARAM_CAT_DEPARTMENT_STATUS, 1, 1);
	
	-- Error Handler
	-- =========================================================================================
	DECLARE EXIT HANDLER FOR SQLEXCEPTION
	BEGIN
		RESIGNAL;
	END;
	
	-- Ignore Time from DateTime (Set Time 00:00:00.000000 and 23:59:59.999999)
	-- =========================================================================================
		
		
	-- Access Rights [Device]
	-- =========================================================================================
	IF `ACCOUNT_DEVICE@HAS_PERMISSION`(PARAM_REQUESTER_DEVICE_PUBLIC_KEY, PARAM_REQUESTER_DEVICE_PRIVATE_KEY) = 0 THEN
		SET TEMP_ERR_MESSAGE = 'Your device is not authorized yet to access this server.';
		SET ERR = `RAISERROR`(TEMP_ERR_MESSAGE);		
	END IF;
		
		
	-- Access Rights [Account]
	-- =========================================================================================
		
	
	
	
	-- COUNT RECORD
	-- =========================================================================================
	
	-- SELECT COLUMNS
	-- ####################################################
	SELECT
		COUNT(DISTINCT `category_department`.`CAT_DEPARTMENT_ID`)
	INTO
		TEMP_RECORD_COUNT

	FROM `category_department`
				
		-- Add Inner Joins (Per Foreign-key)
		
	-- CONDITIONS
	-- ####################################################
	WHERE
		(
			IS_NULL_CAT_DEPARTMENT_ID = 1 OR
			`category_department`.`CAT_DEPARTMENT_ID` = PARAM_CAT_DEPARTMENT_ID			
		) AND
		(
			IS_NULL_CAT_DEPARTMENT_DESCRIPTION = 1 OR
			`category_department`.`CAT_DEPARTMENT_DESCRIPTION` LIKE CONCAT_WS('%', '', PARAM_CAT_DEPARTMENT_DESCRIPTION, '')			
		) AND 		
		(
			IS_NULL_CAT_DEPARTMENT_STATUS = 1 OR
			`category_department`.`CAT_DEPARTMENT_STATUS` = PARAM_CAT_DEPARTMENT_STATUS			
		) 
;	

		
		
	-- SELECT RECORDS
	-- =========================================================================================
	
	-- FETCH COLUMNS
	-- ####################################################
	SELECT
		-- CATEGORY_DEPARTMENT DETAILS
		`category_department`.`CAT_DEPARTMENT_ID`, 
		`category_department`.`CAT_DEPARTMENT_DESCRIPTION`, 
		`category_department`.`CAT_DEPARTMENT_STATUS`
		
		-- Sum of Child [Numerics, non-primary/foreign keys, nor status, active/inactive, and system generated.]
		
		
		-- Inner join fields
		
		-- Left join fields
		
		, TEMP_NOW AS SERVER_TIME,
		TEMP_RECORD_COUNT AS RECORD_COUNT

	FROM `category_department`
	
		-- Add Inner Joins (Per Foreign-key)
		
		-- Add Optional Left Joins (Per Optional Foreign-key)
		
	-- CONDITIONS
	-- ####################################################
	WHERE
		(
			IS_NULL_CAT_DEPARTMENT_ID = 1 OR
			`category_department`.`CAT_DEPARTMENT_ID` = PARAM_CAT_DEPARTMENT_ID			
		) AND
		(
			IS_NULL_CAT_DEPARTMENT_DESCRIPTION = 1 OR
			`category_department`.`CAT_DEPARTMENT_DESCRIPTION` LIKE CONCAT_WS('%', '', PARAM_CAT_DEPARTMENT_DESCRIPTION, '')			
		) AND 		
		(
			IS_NULL_CAT_DEPARTMENT_STATUS = 1 OR
			`category_department`.`CAT_DEPARTMENT_STATUS` = PARAM_CAT_DEPARTMENT_STATUS			
		) 

	-- ORDER BY
	-- ####################################################
	ORDER BY
		-- CATEGORY_DEPARTMENT DETAILS
		CASE WHEN PARAM_ORDER_FIELD = 'CAT_DEPARTMENT_ID' AND PARAM_ORDER_TYPE = 'ASC' THEN `category_department`.`CAT_DEPARTMENT_ID` END ASC, 
		CASE WHEN PARAM_ORDER_FIELD = 'CAT_DEPARTMENT_ID' AND PARAM_ORDER_TYPE = 'DESC' THEN `category_department`.`CAT_DEPARTMENT_ID` END DESC,	
		CASE WHEN PARAM_ORDER_FIELD = 'CAT_DEPARTMENT_DESCRIPTION' AND PARAM_ORDER_TYPE = 'ASC' THEN `category_department`.`CAT_DEPARTMENT_DESCRIPTION` END ASC, 
		CASE WHEN PARAM_ORDER_FIELD = 'CAT_DEPARTMENT_DESCRIPTION' AND PARAM_ORDER_TYPE = 'DESC' THEN `category_department`.`CAT_DEPARTMENT_DESCRIPTION` END DESC,	
		CASE WHEN PARAM_ORDER_FIELD = 'CAT_DEPARTMENT_STATUS' AND PARAM_ORDER_TYPE = 'ASC' THEN `category_department`.`CAT_DEPARTMENT_STATUS` END ASC, 
		CASE WHEN PARAM_ORDER_FIELD = 'CAT_DEPARTMENT_STATUS' AND PARAM_ORDER_TYPE = 'DESC' THEN `category_department`.`CAT_DEPARTMENT_STATUS` END DESC,	

		-- Inner joins
		
		-- EXTRA
		CASE WHEN PARAM_ORDER_FIELD <> 'CAT_DEPARTMENT_DESCRIPTION' THEN `category_department`.`CAT_DEPARTMENT_DESCRIPTION` END ASC
		
	-- LIMIT & OFFSET
	-- ####################################################		
	LIMIT PARAM_SKIP, PARAM_LIMIT;
	
	
	
	-- EXIT PROCEDURE
	-- =========================================================================================
	LEAVE SP_GET;
			
END ;;
DELIMITER ;
/*!50003 SET sql_mode              = @saved_sql_mode */ ;
/*!50003 SET character_set_client  = @saved_cs_client */ ;
/*!50003 SET character_set_results = @saved_cs_results */ ;
/*!50003 SET collation_connection  = @saved_col_connection */ ;
/*!50003 DROP PROCEDURE IF EXISTS `CATEGORY_DEPARTMENT_SAVE` */;
/*!50003 SET @saved_cs_client      = @@character_set_client */ ;
/*!50003 SET @saved_cs_results     = @@character_set_results */ ;
/*!50003 SET @saved_col_connection = @@collation_connection */ ;
/*!50003 SET character_set_client  = latin1 */ ;
/*!50003 SET character_set_results = latin1 */ ;
/*!50003 SET collation_connection  = latin1_swedish_ci */ ;
/*!50003 SET @saved_sql_mode       = @@sql_mode */ ;
/*!50003 SET sql_mode              = '' */ ;
DELIMITER ;;
CREATE DEFINER=`root`@`localhost` PROCEDURE `CATEGORY_DEPARTMENT_SAVE`(
	IN `PARAM_CAT_DEPARTMENT_ID` BIGINT,
	IN `PARAM_CAT_DEPARTMENT_DESCRIPTION` VARCHAR(400),
	IN `PARAM_CAT_DEPARTMENT_STATUS` TINYINT,

	IN `PARAM_REQUESTER_USERNAME` VARCHAR(500),
	IN `PARAM_REQUESTER_PASSWORD` VARCHAR(500),
	IN `PARAM_REQUESTER_PROXY_ID` BIGINT,
	IN `PARAM_REQUESTER_PROXY_PASSWORD` VARCHAR(1000),
	IN `PARAM_REQUESTER_DEVICE_PUBLIC_KEY` VARCHAR(1000),
	IN `PARAM_REQUESTER_DEVICE_PRIVATE_KEY` VARCHAR(1000),
	
	IN `PARAM_REQUESTER_IP` VARCHAR(1000),
	IN `PARAM_UNIQUE_SESSION_ID` VARCHAR(1000),
	IN `PARAM_SUPPRESS_RETURN` BIT,
	
	IN `PARAM_SYNC_SERVER_DESCRIPTION` VARCHAR(500), 
	IN `PARAM_SYNC_SERVER_UNIQUE_KEY` VARCHAR(500)
)
SP_SAVE:
BEGIN


	-- 1) DECLARE LOCAL PARAMETERS
	-- _______________________________________________________________________
	
	-- Status
	-- ...........................................
	DECLARE STATUS_INACTIVE TINYINT DEFAULT 1;
	DECLARE STATUS_ACTIVE TINYINT DEFAULT 2;
	DECLARE STATUS_CLOSED TINYINT DEFAULT 3;
	DECLARE STATUS_COMPLETED TINYINT DEFAULT 4;

	-- Audit Handler
	-- ...........................................
	DECLARE TEMP_RECORD_EXISTS BIT DEFAULT 0;
	DECLARE TEMP_MODULE_KEYWORD VARCHAR(500) DEFAULT 'category_department';
	DECLARE TEMP_SP_OBJECTIVE VARCHAR(500) DEFAULT 'add/edit Department record';
	DECLARE TEMP_ERR_MESSAGE VARCHAR(500) DEFAULT '';
	DECLARE ERR BIGINT DEFAULT 0;
	DECLARE TEMP_RECORD_CHANGES VARCHAR(16000) DEFAULT '';
	DECLARE TEMP_RECORD_BINDED BIT DEFAULT 0;

	-- Authentication
	-- ...........................................
	DECLARE TEMP_ACCESS_RIGHTS_DENIED BIT DEFAULT 0;
	DECLARE TEMP_ACCESS_RIGHTS_HAS_OVERRIDE BIT DEFAULT 0;
	DECLARE TEMP_SYNC_SERVER_ID BIGINT DEFAULT 0;
	DECLARE TEMP_SYNC_IS_SERVER_REQUEST BIT DEFAULT 0;
	DECLARE TEMP_AUTHENTICATED_ACCOUNT_ID BIGINT DEFAULT `ACCOUNT_MEMBER@ACC_ACCOUNT_ID_FROM_LOGIN`(PARAM_REQUESTER_USERNAME, PARAM_REQUESTER_PASSWORD);
	DECLARE TEMP_AUTHENTICATED_ACCOUNT_LEVEL BIGINT DEFAULT 0;
	DECLARE TEMP_AUTHENTICATED_ACCOUNT_GROUP BIGINT DEFAULT 0;
	
	-- Local Parameters
	-- ...........................................
	DECLARE TEMP_NOW DATETIME(6) DEFAULT `SYSTEM_VAR@NOW`('', 1);
	DECLARE TEMP_RECORD_COUNT BIGINT DEFAULT 0;

	-- AutoGen Parameters
	-- ...........................................
	
	-- Local value holder
	-- ...........................................
	DECLARE TEMP_CAT_DEPARTMENT_DESCRIPTION VARCHAR(400) DEFAULT ''; 
	DECLARE TEMP_CAT_DEPARTMENT_STATUS TINYINT DEFAULT 0; 
	
	DECLARE REDUND_CAT_DEPARTMENT_ID BIGINT DEFAULT 0; 


	-- 2) Try Catch / Throw
	-- _______________________________________________________________________
	DECLARE EXIT HANDLER FOR SQLEXCEPTION
	BEGIN
		RESIGNAL;
	END;



	-- 3) Prepare SYNC
	-- _______________________________________________________________________

	-- IS RECORD EXISTS		
	-- ####################################################	
	SET TEMP_RECORD_EXISTS = `CATEGORY_DEPARTMENT@CAT_DEPARTMENT_ID_EXISTS`(PARAM_CAT_DEPARTMENT_ID, 0);

		
		
	-- 4) PREPARE AUTOGEN DATA (IF EXISTS)
	-- _______________________________________________________________________
	IF TEMP_SYNC_IS_SERVER_REQUEST = 0 THEN
		-- Just to keep at least one line within condition
		SET TEMP_SYNC_IS_SERVER_REQUEST = 0;
		
		-- Actual Functionalities here
		-- USE DEFAULT VALUE (String)
	END IF;



	-- 5) IF ALREADY EXIST, FILL MISSING DATA
	-- _______________________________________________________________________
	IF TEMP_RECORD_EXISTS = 1 THEN
		SELECT
			`category_department`.`CAT_DEPARTMENT_DESCRIPTION`, 	
			`category_department`.`CAT_DEPARTMENT_STATUS`	
		INTO
			TEMP_CAT_DEPARTMENT_DESCRIPTION, 	
			TEMP_CAT_DEPARTMENT_STATUS	

		FROM `category_department`
		WHERE
			`category_department`.`CAT_DEPARTMENT_ID` = PARAM_CAT_DEPARTMENT_ID
		LIMIT 1;

		-- Replace NULLs with the existing data.
		SET PARAM_CAT_DEPARTMENT_DESCRIPTION = `SYSTEM_VAR@REPLACE_NULL@NVARCHAR`(PARAM_CAT_DEPARTMENT_DESCRIPTION, TEMP_CAT_DEPARTMENT_DESCRIPTION, 1);
		SET PARAM_CAT_DEPARTMENT_STATUS = `SYSTEM_VAR@REPLACE_NULL@TINYINT`(PARAM_CAT_DEPARTMENT_STATUS, TEMP_CAT_DEPARTMENT_STATUS, 1, 1);
		
		-- AUTO GEN (NON-UPDATABLES)		
		
		-- AUTO GEN (UPDATABLE WITH STATUS CHANGE)

		-- AUTO GEN (UPDATABLE WITH STATUS [ACTIVE/INACTIVE] CHANGE)
		
		-- NON-UPDATABLE
		
		-- NON-UPDATABLE BUT NULL
		
	ELSE
		SET PARAM_CAT_DEPARTMENT_DESCRIPTION = `SYSTEM_VAR@REPLACE_NULL@NVARCHAR`(PARAM_CAT_DEPARTMENT_DESCRIPTION, '', 1);
		SET PARAM_CAT_DEPARTMENT_STATUS = `SYSTEM_VAR@REPLACE_NULL@TINYINT`(PARAM_CAT_DEPARTMENT_STATUS, 0, 1, 1);
		
	END IF;

	

	-- 6) PREPARE AUDIT TRAIL
	-- _______________________________________________________________________
	IF BINARY TEMP_CAT_DEPARTMENT_DESCRIPTION <> PARAM_CAT_DEPARTMENT_DESCRIPTION THEN
		SET TEMP_RECORD_CHANGES = 
		`SYSTEM_VAR@CONCAT_ADD`(' | ', TEMP_RECORD_CHANGES, CONCAT_WS(' ', 'Description: "', TEMP_CAT_DEPARTMENT_DESCRIPTION, '" > "', PARAM_CAT_DEPARTMENT_DESCRIPTION, '"'));
	END IF;
	IF TEMP_CAT_DEPARTMENT_STATUS <> PARAM_CAT_DEPARTMENT_STATUS THEN
		SET TEMP_RECORD_CHANGES = 
		`SYSTEM_VAR@CONCAT_ADD`(' | ', TEMP_RECORD_CHANGES, CONCAT_WS(' ', 'Status: "', TEMP_CAT_DEPARTMENT_STATUS, '" > "', PARAM_CAT_DEPARTMENT_STATUS, '"'));
	END IF;	
		
	-- No Changes in data, reject request
	-- ####################################################
	IF CHARACTER_LENGTH(TEMP_RECORD_CHANGES) = 0 THEN
		IF PARAM_SUPPRESS_RETURN = 0 THEN
			SELECT PARAM_CAT_DEPARTMENT_ID AS INSERTED_ID;
		END IF;
		LEAVE SP_SAVE;
	END IF;



	-- 7) VALIDATE
	-- _______________________________________________________________________

	-- Access Rights [Device]
	-- ####################################################
	IF `ACCOUNT_DEVICE@HAS_PERMISSION`(PARAM_REQUESTER_DEVICE_PUBLIC_KEY, PARAM_REQUESTER_DEVICE_PRIVATE_KEY) = 0 THEN
		SET TEMP_ERR_MESSAGE = 'Your device is not authorized yet to access this server.';
		SET ERR = `RAISERROR`(TEMP_ERR_MESSAGE);		
	END IF;
		
		
	-- Access Rights [Account]
	-- ####################################################
	
	IF 
		-- [ADD] Access Rights
		(
			TEMP_RECORD_EXISTS = 0 AND
			`ACCOUNT_ACCESS_RIGHTS@HAS_PERMISSION`(PARAM_REQUESTER_USERNAME, PARAM_REQUESTER_PASSWORD, 0, TEMP_MODULE_KEYWORD, 2) = 0 AND
			`ACCOUNT_ACCESS_RIGHTS@PROXY_PERMISSION`(PARAM_REQUESTER_PROXY_ID, PARAM_REQUESTER_PROXY_PASSWORD, 0, TEMP_MODULE_KEYWORD, 2) = 0
		) OR
		
		-- [EDIT] Access Rights
		(
			TEMP_RECORD_EXISTS = 1 AND
			`ACCOUNT_ACCESS_RIGHTS@HAS_PERMISSION`(PARAM_REQUESTER_USERNAME, PARAM_REQUESTER_PASSWORD, 0, TEMP_MODULE_KEYWORD, 3) = 0 AND
			`ACCOUNT_ACCESS_RIGHTS@PROXY_PERMISSION`(PARAM_REQUESTER_PROXY_ID, PARAM_REQUESTER_PROXY_PASSWORD, 0, TEMP_MODULE_KEYWORD, 3) = 0
		)
	THEN
		SET TEMP_ACCESS_RIGHTS_DENIED = 1;
		CALL `ACCOUNT_ACCESS_RIGHTS_DENY`
		(
			0, TEMP_MODULE_KEYWORD, PARAM_CAT_DEPARTMENT_ID, 0, TEMP_SP_OBJECTIVE, TEMP_RECORD_CHANGES, 
			PARAM_REQUESTER_USERNAME, PARAM_REQUESTER_PASSWORD, 
			PARAM_REQUESTER_PROXY_ID, PARAM_REQUESTER_PROXY_PASSWORD,
			PARAM_REQUESTER_DEVICE_PUBLIC_KEY, PARAM_REQUESTER_DEVICE_PRIVATE_KEY,
			PARAM_REQUESTER_IP, PARAM_UNIQUE_SESSION_ID,
			TEMP_SYNC_SERVER_ID, PARAM_SUPPRESS_RETURN
		);
	END IF;
	SET TEMP_ACCESS_RIGHTS_HAS_OVERRIDE = `ACCOUNT_ACCESS_RIGHTS@HAS_PERMISSION`(PARAM_REQUESTER_USERNAME, PARAM_REQUESTER_PASSWORD, 0, TEMP_MODULE_KEYWORD, 4);
	

	-- Validation
	-- ####################################################
	IF TEMP_SYNC_IS_SERVER_REQUEST = 0 THEN
	

		-- FOREIGN KEY EXISTS
		-- ...........................................
		
		-- FOREIGN (OPTIONAL)KEY EXISTS [Validates if not null]
		-- ...........................................
		
		-- IS_ALLOW_NULL = FALSE
		-- ...........................................
				
		-- IS_ALLOW_ZERO = FALSE
		-- ...........................................
		IF PARAM_CAT_DEPARTMENT_STATUS = 0 THEN
			CALL `VALIDATION_MISSING_FIELD`('`CAT_DEPARTMENT_STATUS`', '`NULL`');
		END IF;		
		
		-- IS_ALLOW_NEGATIVE = FALSE
		-- ...........................................
		IF PARAM_CAT_DEPARTMENT_STATUS < 0 THEN
			CALL `VALIDATION_NEGATIVE`('`CAT_DEPARTMENT_STATUS`', PARAM_CAT_DEPARTMENT_STATUS);
		END IF;		
		
		-- IS_ALLOW_EMPTY_STRING = FALSE
		-- ...........................................
		IF `SYSTEM_VAR@IS_NULL@NVARCHAR`(PARAM_CAT_DEPARTMENT_DESCRIPTION, 1) = 1 THEN
			CALL `VALIDATION_MISSING_FIELD`('`CAT_DEPARTMENT_DESCRIPTION`', '`NULL`');
		END IF;
		
		-- IS_STATUS
		-- ...........................................
		IF `SYSTEM_STATUS@SYS_STATUS_ID_EXISTS`(PARAM_CAT_DEPARTMENT_STATUS, 0) = 0 THEN
			SET TEMP_ERR_MESSAGE = CONCAT_WS(' ', 'Given STATUS[Status] does not exists or is inactive. ID: ', PARAM_CAT_DEPARTMENT_STATUS);
			SET ERR = `RAISERROR`(TEMP_ERR_MESSAGE);
		END IF;
		
		-- IS STATUS Active / Inactive
		-- ...........................................
		
		-- Minimum / Maximum Value
		-- ...........................................
		
		-- IS_UNIQUE = TRUE
		-- ...........................................
		IF
		(
			SELECT COUNT(`category_department`.`CAT_DEPARTMENT_ID`)
			FROM `category_department`
			WHERE		
				`category_department`.`CAT_DEPARTMENT_DESCRIPTION` = PARAM_CAT_DEPARTMENT_DESCRIPTION AND		
				`category_department`.`CAT_DEPARTMENT_ID` <> PARAM_CAT_DEPARTMENT_ID
		) >= 1
		THEN
			SELECT `category_department`.`CAT_DEPARTMENT_ID`
			INTO REDUND_CAT_DEPARTMENT_ID
			FROM `category_department`
			WHERE		
				`category_department`.`CAT_DEPARTMENT_DESCRIPTION` = PARAM_CAT_DEPARTMENT_DESCRIPTION AND		
				`category_department`.`CAT_DEPARTMENT_ID` <> PARAM_CAT_DEPARTMENT_ID		
			LIMIT 1; 
			SET TEMP_ERR_MESSAGE = CONCAT_WS(' ', PARAM_CAT_DEPARTMENT_DESCRIPTION, '[', REDUND_CAT_DEPARTMENT_ID, ']');
			CALL `VALIDATION_REDUNDANT_ENTRY`(TEMP_ERR_MESSAGE);
		END IF;
		
		-- RECORD IDENTIFIER
		-- ...........................................
		
		
		-- ON_UPDATE VALIDATION 
		-- ...........................................
		IF TEMP_RECORD_EXISTS = 1 THEN	
		
			-- Just to keep at least one line within condition
			SET TEMP_RECORD_EXISTS = 1;
			
		END IF;
		
	END IF;



	-- 8) INSERT / UPDATE
	-- _______________________________________________________________________

	-- INSERT NEW DATA
	-- ####################################################
	IF TEMP_RECORD_EXISTS = 0 THEN

		INSERT INTO
		`category_department`
		(
			`category_department`.`CAT_DEPARTMENT_DESCRIPTION`, 
			`category_department`.`CAT_DEPARTMENT_STATUS`
		)
		VALUES
		(
			PARAM_CAT_DEPARTMENT_DESCRIPTION, 
			PARAM_CAT_DEPARTMENT_STATUS
		);	
		
		-- Update Audit trail with new ID	
		SET PARAM_CAT_DEPARTMENT_ID = LAST_INSERT_ID();



	-- UPDATING EXISTING RECORD
	-- ####################################################
	ELSE
		UPDATE `category_department`
		SET
			`category_department`.`CAT_DEPARTMENT_DESCRIPTION` = PARAM_CAT_DEPARTMENT_DESCRIPTION, 
			`category_department`.`CAT_DEPARTMENT_STATUS` = PARAM_CAT_DEPARTMENT_STATUS
		WHERE
			`category_department`.`CAT_DEPARTMENT_ID` = PARAM_CAT_DEPARTMENT_ID;

	END IF;

	
	-- 9) AUDIT TRAIL
	-- _______________________________________________________________________
	CALL `ACCOUNT_AUDIT_TRAIL_SAVE`
	(
		0, TEMP_MODULE_KEYWORD, PARAM_CAT_DEPARTMENT_ID, 0, 'SAVE', TEMP_SP_OBJECTIVE, TEMP_RECORD_CHANGES, 
		PARAM_REQUESTER_USERNAME, PARAM_REQUESTER_PASSWORD, 
		PARAM_REQUESTER_PROXY_ID, PARAM_REQUESTER_PROXY_PASSWORD,
		PARAM_REQUESTER_DEVICE_PUBLIC_KEY, PARAM_REQUESTER_DEVICE_PRIVATE_KEY,
		PARAM_REQUESTER_IP, PARAM_UNIQUE_SESSION_ID,
		TEMP_SYNC_SERVER_ID, PARAM_SUPPRESS_RETURN
	);
	

	-- 10) RETURN RESULT
	-- _______________________________________________________________________
	IF PARAM_SUPPRESS_RETURN = 0 THEN
		SELECT 
			PARAM_CAT_DEPARTMENT_ID AS INSERTED_ID,
			TEMP_NOW AS SERVER_TIME;
	END IF;
	LEAVE SP_SAVE;


END ;;
DELIMITER ;
/*!50003 SET sql_mode              = @saved_sql_mode */ ;
/*!50003 SET character_set_client  = @saved_cs_client */ ;
/*!50003 SET character_set_results = @saved_cs_results */ ;
/*!50003 SET collation_connection  = @saved_col_connection */ ;
/*!50003 DROP PROCEDURE IF EXISTS `CATEGORY_ENTRANCE_DELETE` */;
/*!50003 SET @saved_cs_client      = @@character_set_client */ ;
/*!50003 SET @saved_cs_results     = @@character_set_results */ ;
/*!50003 SET @saved_col_connection = @@collation_connection */ ;
/*!50003 SET character_set_client  = latin1 */ ;
/*!50003 SET character_set_results = latin1 */ ;
/*!50003 SET collation_connection  = latin1_swedish_ci */ ;
/*!50003 SET @saved_sql_mode       = @@sql_mode */ ;
/*!50003 SET sql_mode              = '' */ ;
DELIMITER ;;
CREATE DEFINER=`root`@`localhost` PROCEDURE `CATEGORY_ENTRANCE_DELETE`(
	IN `PARAM_CAT_ENTRANCE_ID` BIGINT,

	IN `PARAM_REQUESTER_USERNAME` VARCHAR(500),
	IN `PARAM_REQUESTER_PASSWORD` VARCHAR(500),
	IN `PARAM_REQUESTER_PROXY_ID` BIGINT,
	IN `PARAM_REQUESTER_PROXY_PASSWORD` VARCHAR(1000),
	IN `PARAM_REQUESTER_DEVICE_PUBLIC_KEY` VARCHAR(1000),
	IN `PARAM_REQUESTER_DEVICE_PRIVATE_KEY` VARCHAR(1000),
	
	IN `PARAM_REQUESTER_IP` VARCHAR(1000),
	IN `PARAM_UNIQUE_SESSION_ID` VARCHAR(1000),
	IN `PARAM_SUPPRESS_RETURN` BIT,
	
	IN `PARAM_SYNC_SERVER_DESCRIPTION` VARCHAR(500), 
	IN `PARAM_SYNC_SERVER_UNIQUE_KEY` VARCHAR(500)
)
SP_DELETE:
BEGIN

	-- 1) DECLARE LOCAL PARAMETERS
	-- _______________________________________________________________________
	
	-- Status
	-- ...........................................
	DECLARE STATUS_INACTIVE TINYINT DEFAULT 1;
	DECLARE STATUS_ACTIVE TINYINT DEFAULT 2;
	DECLARE STATUS_CLOSED TINYINT DEFAULT 3;
	DECLARE STATUS_COMPLETED TINYINT DEFAULT 4;
	
	-- Audit Handler
	-- ...........................................
	DECLARE TEMP_RECORD_EXISTS BIT DEFAULT 0;
	DECLARE TEMP_MODULE_KEYWORD VARCHAR(500) DEFAULT 'category_entrance';
	DECLARE TEMP_SP_OBJECTIVE VARCHAR(500) DEFAULT 'delete Entrance record';
	DECLARE TEMP_ERR_MESSAGE VARCHAR(500) DEFAULT '';
	DECLARE ERR BIGINT DEFAULT 0;
	DECLARE TEMP_RECORD_CHANGES VARCHAR(16000) DEFAULT '';
	DECLARE TEMP_RECORD_BINDED BIT DEFAULT 0;
	
	DECLARE TEMP_RECORD_BINDED_ID BIGINT DEFAULT 0;
	DECLARE TEMP_RECORD_BINDED_SERVER_ID BIGINT DEFAULT 0;
	
	-- Authentication
	-- ...........................................
	DECLARE TEMP_ACCESS_RIGHTS_DENIED BIT DEFAULT 0;
	DECLARE TEMP_SYNC_SERVER_ID BIGINT DEFAULT 0;
	DECLARE TEMP_SYNC_IS_SERVER_REQUEST BIT DEFAULT 0;
	DECLARE TEMP_AUTHENTICATED_ACCOUNT_ID BIGINT DEFAULT `ACCOUNT_MEMBER@ACC_ACCOUNT_ID_FROM_LOGIN`(PARAM_REQUESTER_USERNAME, PARAM_REQUESTER_PASSWORD);
	DECLARE TEMP_AUTHENTICATED_ACCOUNT_LEVEL BIGINT DEFAULT 0;
	DECLARE TEMP_AUTHENTICATED_ACCOUNT_GROUP BIGINT DEFAULT 0;

	-- Local value holder
	-- ...........................................
		DECLARE TEMP_CAT_ENTRANCE_DESCRIPTION VARCHAR(400) DEFAULT ''; 
		DECLARE TEMP_CAT_ENTRANCE_DIRECTION BIGINT DEFAULT 0; 
		DECLARE TEMP_CAT_ENTRANCE_STATUS TINYINT DEFAULT 0; 

	
	
	-- 2) Try Catch / Throw
	-- _______________________________________________________________________
	DECLARE EXIT HANDLER FOR SQLEXCEPTION
	BEGIN
		RESIGNAL;
	END;

	
	-- 3) Prepare SYNC
	-- _______________________________________________________________________
	
	-- IS RECORD EXISTS		
	-- ####################################################		
	SET TEMP_RECORD_EXISTS = `CATEGORY_ENTRANCE@CAT_ENTRANCE_ID_EXISTS`(PARAM_CAT_ENTRANCE_ID, 0);


	-- 4) IF ALREADY EXIST, FILL MISSING DATA
	-- _______________________________________________________________________
	IF TEMP_RECORD_EXISTS = 1 THEN
		SELECT
				`category_entrance`.`CAT_ENTRANCE_DESCRIPTION`, 	
				`category_entrance`.`CAT_ENTRANCE_DIRECTION`, 	
				`category_entrance`.`CAT_ENTRANCE_STATUS`	
		INTO
				TEMP_CAT_ENTRANCE_DESCRIPTION, 	
				TEMP_CAT_ENTRANCE_DIRECTION, 	
				TEMP_CAT_ENTRANCE_STATUS	

		FROM `category_entrance`
		WHERE
			`category_entrance`.`CAT_ENTRANCE_ID` = PARAM_CAT_ENTRANCE_ID
		LIMIT 1;

	ELSE 
		IF TEMP_SYNC_IS_SERVER_REQUEST = 0 THEN
			SET TEMP_ERR_MESSAGE = CONCAT_WS(' ', 'Given Entrance does not exists or is inactive. ID:', PARAM_CAT_ENTRANCE_ID);
			SET ERR = `RAISERROR`(TEMP_ERR_MESSAGE);		
		END IF;
		LEAVE SP_DELETE;
		
	END IF;



	-- 5) PREPARE AUDIT TRAIL
	-- _______________________________________________________________________
	
		SET TEMP_RECORD_CHANGES = 
		`SYSTEM_VAR@CONCAT_ADD`(' | ', TEMP_RECORD_CHANGES, CONCAT_WS(' ', 'Description: "', TEMP_CAT_ENTRANCE_DESCRIPTION, '" > " DELETED "'));
		SET TEMP_RECORD_CHANGES = 
		`SYSTEM_VAR@CONCAT_ADD`(' | ', TEMP_RECORD_CHANGES, CONCAT_WS(' ', 'Direction: "', TEMP_CAT_ENTRANCE_DIRECTION, '" > " DELETED "'));
		SET TEMP_RECORD_CHANGES = 
		`SYSTEM_VAR@CONCAT_ADD`(' | ', TEMP_RECORD_CHANGES, CONCAT_WS(' ', 'Status: "', TEMP_CAT_ENTRANCE_STATUS, '" > " DELETED "'));


	-- 6) VALIDATE
	-- _______________________________________________________________________
	
	-- Access Rights [Device]
	-- ####################################################
	IF `ACCOUNT_DEVICE@HAS_PERMISSION`(PARAM_REQUESTER_DEVICE_PUBLIC_KEY, PARAM_REQUESTER_DEVICE_PRIVATE_KEY) = 0 THEN
		SET TEMP_ERR_MESSAGE = 'Your device is not authorized yet to access this server.';
		SET ERR = `RAISERROR`(TEMP_ERR_MESSAGE);		
	END IF;
		
		
	-- Access Rights [Account]
	-- ####################################################	
	
	IF 
		-- [DELETE] Access Rights
		`ACCOUNT_ACCESS_RIGHTS@HAS_PERMISSION`(PARAM_REQUESTER_USERNAME, PARAM_REQUESTER_PASSWORD, 0, TEMP_MODULE_KEYWORD, 4) = 0 AND
		`ACCOUNT_ACCESS_RIGHTS@PROXY_PERMISSION`(PARAM_REQUESTER_PROXY_ID, PARAM_REQUESTER_PROXY_PASSWORD, 0, TEMP_MODULE_KEYWORD, 4) = 0
	THEN
		SET TEMP_ACCESS_RIGHTS_DENIED = 1;
		CALL `ACCOUNT_ACCESS_RIGHTS_DENY`
		(
			0, TEMP_MODULE_KEYWORD, PARAM_CAT_ENTRANCE_ID, 0, TEMP_SP_OBJECTIVE, TEMP_RECORD_CHANGES, 
			PARAM_REQUESTER_USERNAME, PARAM_REQUESTER_PASSWORD, 
			PARAM_REQUESTER_PROXY_ID, PARAM_REQUESTER_PROXY_PASSWORD,
			PARAM_REQUESTER_DEVICE_PUBLIC_KEY, PARAM_REQUESTER_DEVICE_PRIVATE_KEY,
			PARAM_REQUESTER_IP, PARAM_UNIQUE_SESSION_ID,
			TEMP_SYNC_SERVER_ID, PARAM_SUPPRESS_RETURN
		);
	END IF;

	
	-- If already used, cannot remove record
	-- ####################################################

	-- Leave Re-upload request
	-- ####################################################
	IF TEMP_RECORD_BINDED = 1 THEN
		IF TEMP_SYNC_IS_SERVER_REQUEST = 1 THEN
			
			LEAVE SP_DELETE;
		END IF;

		CALL `VALIDATION_DELETE_LINKED_RECORD`(TEMP_CAT_ENTRANCE_DESCRIPTION, '', TEMP_ERR_MESSAGE); 
	END IF;


	-- 7) DELETE
	-- _______________________________________________________________________
	DELETE FROM `category_entrance`
	WHERE `category_entrance`.`CAT_ENTRANCE_ID` = PARAM_CAT_ENTRANCE_ID
	LIMIT 1;


	-- 8) AUDIT TRAIL
	-- _______________________________________________________________________
	CALL `ACCOUNT_AUDIT_TRAIL_SAVE`
	(
		0, TEMP_MODULE_KEYWORD, PARAM_CAT_ENTRANCE_ID, 0, 'DELETE', TEMP_SP_OBJECTIVE, TEMP_RECORD_CHANGES, 
		PARAM_REQUESTER_USERNAME, PARAM_REQUESTER_PASSWORD, 
		PARAM_REQUESTER_PROXY_ID, PARAM_REQUESTER_PROXY_PASSWORD,
		PARAM_REQUESTER_DEVICE_PUBLIC_KEY, PARAM_REQUESTER_DEVICE_PRIVATE_KEY,
		PARAM_REQUESTER_IP, PARAM_UNIQUE_SESSION_ID,
		TEMP_SYNC_SERVER_ID, PARAM_SUPPRESS_RETURN
	);

END ;;
DELIMITER ;
/*!50003 SET sql_mode              = @saved_sql_mode */ ;
/*!50003 SET character_set_client  = @saved_cs_client */ ;
/*!50003 SET character_set_results = @saved_cs_results */ ;
/*!50003 SET collation_connection  = @saved_col_connection */ ;
/*!50003 DROP PROCEDURE IF EXISTS `CATEGORY_ENTRANCE_GET` */;
/*!50003 SET @saved_cs_client      = @@character_set_client */ ;
/*!50003 SET @saved_cs_results     = @@character_set_results */ ;
/*!50003 SET @saved_col_connection = @@collation_connection */ ;
/*!50003 SET character_set_client  = latin1 */ ;
/*!50003 SET character_set_results = latin1 */ ;
/*!50003 SET collation_connection  = latin1_swedish_ci */ ;
/*!50003 SET @saved_sql_mode       = @@sql_mode */ ;
/*!50003 SET sql_mode              = '' */ ;
DELIMITER ;;
CREATE DEFINER=`root`@`localhost` PROCEDURE `CATEGORY_ENTRANCE_GET`(
	IN `PARAM_CAT_ENTRANCE_ID` BIGINT,	
	IN `PARAM_CAT_ENTRANCE_DESCRIPTION` VARCHAR(400),	
	IN `PARAM_CAT_ENTRANCE_DIRECTION` BIGINT,	
	IN `PARAM_CAT_ENTRANCE_STATUS` TINYINT,	
		
	IN `PARAM_ORDER_FIELD` VARCHAR(500),
	IN `PARAM_ORDER_TYPE` VARCHAR(500),
	IN `PARAM_SKIP` BIGINT,
	IN `PARAM_LIMIT` BIGINT,

	IN `PARAM_REQUESTER_USERNAME` VARCHAR(500),
	IN `PARAM_REQUESTER_PASSWORD` VARCHAR(500),
	IN `PARAM_REQUESTER_PROXY_ID` BIGINT,
	IN `PARAM_REQUESTER_PROXY_PASSWORD` VARCHAR(1000),
	IN `PARAM_REQUESTER_DEVICE_PUBLIC_KEY` VARCHAR(1000),
	IN `PARAM_REQUESTER_DEVICE_PRIVATE_KEY` VARCHAR(1000),
	
	IN `PARAM_REQUESTER_IP` VARCHAR(1000),
	IN `PARAM_UNIQUE_SESSION_ID` VARCHAR(1000),
	IN `PARAM_SUPPRESS_RETURN` BIT
)
SP_GET:
BEGIN

	-- Status
	-- =========================================================================================
	DECLARE STATUS_INACTIVE TINYINT DEFAULT 1;
	DECLARE STATUS_ACTIVE TINYINT DEFAULT 2;
	DECLARE STATUS_CLOSED TINYINT DEFAULT 3;
	DECLARE STATUS_COMPLETED TINYINT DEFAULT 4;
	
	-- Audit Handler
	-- =========================================================================================
	DECLARE TEMP_RECORD_EXISTS BIT DEFAULT 0;
	DECLARE TEMP_MODULE_KEYWORD VARCHAR(500) DEFAULT 'category_entrance';
	DECLARE TEMP_SP_OBJECTIVE VARCHAR(500) DEFAULT 'Retrieve Entrance record';
	DECLARE TEMP_ERR_MESSAGE VARCHAR(500) DEFAULT '';
	DECLARE ERR BIGINT DEFAULT 0;
	DECLARE TEMP_RECORD_CHANGES VARCHAR(16000) DEFAULT '';
	DECLARE TEMP_RECORD_BINDED BIT DEFAULT 0;
	
	DECLARE TEMP_RECORD_BINDED_ID BIGINT DEFAULT 0;
	DECLARE TEMP_RECORD_BINDED_SERVER_ID BIGINT DEFAULT 0;
	
	-- Authentication
	-- =========================================================================================
	DECLARE TEMP_ACCESS_RIGHTS_DENIED BIT DEFAULT 0;
	DECLARE TEMP_AUTHENTICATED_ACCOUNT_ID BIGINT DEFAULT `ACCOUNT_MEMBER@ACC_ACCOUNT_ID_FROM_LOGIN`(PARAM_REQUESTER_USERNAME, PARAM_REQUESTER_PASSWORD);
	DECLARE TEMP_AUTHENTICATED_ACCOUNT_LEVEL BIGINT DEFAULT 0;
	DECLARE TEMP_AUTHENTICATED_ACCOUNT_GROUP BIGINT DEFAULT 0;
	
	-- Local Parameters
	-- =========================================================================================
	DECLARE TEMP_NOW DATETIME(6) DEFAULT `SYSTEM_VAR@NOW`('', 1);
	DECLARE TEMP_RECORD_COUNT BIGINT DEFAULT 0;
	
	
	-- Check NULLs
	-- =========================================================================================
	DECLARE IS_NULL_CAT_ENTRANCE_ID BIT DEFAULT `SYSTEM_VAR@IS_NULL@BIGINT`(PARAM_CAT_ENTRANCE_ID, 1, 1);
	DECLARE IS_NULL_CAT_ENTRANCE_DESCRIPTION BIT DEFAULT `SYSTEM_VAR@IS_NULL@NVARCHAR`(PARAM_CAT_ENTRANCE_DESCRIPTION, 1);
	DECLARE IS_NULL_CAT_ENTRANCE_DIRECTION BIT DEFAULT `SYSTEM_VAR@IS_NULL@BIGINT`(PARAM_CAT_ENTRANCE_DIRECTION, 1, 1);
	DECLARE IS_NULL_CAT_ENTRANCE_STATUS BIT DEFAULT `SYSTEM_VAR@IS_NULL@TINYINT`(PARAM_CAT_ENTRANCE_STATUS, 1, 1);
	
	-- Error Handler
	-- =========================================================================================
	DECLARE EXIT HANDLER FOR SQLEXCEPTION
	BEGIN
		RESIGNAL;
	END;
	
	-- Ignore Time from DateTime (Set Time 00:00:00.000000 and 23:59:59.999999)
	-- =========================================================================================
		
		
	-- Access Rights [Device]
	-- =========================================================================================
	IF `ACCOUNT_DEVICE@HAS_PERMISSION`(PARAM_REQUESTER_DEVICE_PUBLIC_KEY, PARAM_REQUESTER_DEVICE_PRIVATE_KEY) = 0 THEN
		SET TEMP_ERR_MESSAGE = 'Your device is not authorized yet to access this server.';
		SET ERR = `RAISERROR`(TEMP_ERR_MESSAGE);		
	END IF;
		
		
	-- Access Rights [Account]
	-- =========================================================================================
		
	
	
	
	-- COUNT RECORD
	-- =========================================================================================
	
	-- SELECT COLUMNS
	-- ####################################################
	SELECT
		COUNT(DISTINCT `category_entrance`.`CAT_ENTRANCE_ID`)
	INTO
		TEMP_RECORD_COUNT

	FROM `category_entrance`
				
		-- Add Inner Joins (Per Foreign-key)
		
	-- CONDITIONS
	-- ####################################################
	WHERE
		(
			IS_NULL_CAT_ENTRANCE_ID = 1 OR
			`category_entrance`.`CAT_ENTRANCE_ID` = PARAM_CAT_ENTRANCE_ID			
		) AND
		(
			IS_NULL_CAT_ENTRANCE_DESCRIPTION = 1 OR
			`category_entrance`.`CAT_ENTRANCE_DESCRIPTION` LIKE CONCAT_WS('%', '', PARAM_CAT_ENTRANCE_DESCRIPTION, '')			
		) AND 		
		(
			IS_NULL_CAT_ENTRANCE_DIRECTION = 1 OR
			`category_entrance`.`CAT_ENTRANCE_DIRECTION` = PARAM_CAT_ENTRANCE_DIRECTION			
		) AND
		(
			IS_NULL_CAT_ENTRANCE_STATUS = 1 OR
			`category_entrance`.`CAT_ENTRANCE_STATUS` = PARAM_CAT_ENTRANCE_STATUS			
		) 
;	

		
		
	-- SELECT RECORDS
	-- =========================================================================================
	
	-- FETCH COLUMNS
	-- ####################################################
	SELECT
		-- CATEGORY_ENTRANCE DETAILS
		`category_entrance`.`CAT_ENTRANCE_ID`, 
		`category_entrance`.`CAT_ENTRANCE_DESCRIPTION`, 
		`category_entrance`.`CAT_ENTRANCE_DIRECTION`, 
		IF
		(
			`category_entrance`.`CAT_ENTRANCE_DIRECTION` = 1, 'Out',
			IF
			(
				`category_entrance`.`CAT_ENTRANCE_DIRECTION` = 2, 'In',
				'Two-way'
			)
		) AS CAT_ENTRANCE_DIRECTION_VALUE,
		`category_entrance`.`CAT_ENTRANCE_STATUS`
		
		-- Sum of Child [Numerics, non-primary/foreign keys, nor status, active/inactive, and system generated.]
		
		
		-- Inner join fields
		
		-- Left join fields
		
		, TEMP_NOW AS SERVER_TIME,
		TEMP_RECORD_COUNT AS RECORD_COUNT

	FROM `category_entrance`
	
		-- Add Inner Joins (Per Foreign-key)
		
		-- Add Optional Left Joins (Per Optional Foreign-key)
		
	-- CONDITIONS
	-- ####################################################
	WHERE
		(
			IS_NULL_CAT_ENTRANCE_ID = 1 OR
			`category_entrance`.`CAT_ENTRANCE_ID` = PARAM_CAT_ENTRANCE_ID			
		) AND
		(
			IS_NULL_CAT_ENTRANCE_DESCRIPTION = 1 OR
			`category_entrance`.`CAT_ENTRANCE_DESCRIPTION` LIKE CONCAT_WS('%', '', PARAM_CAT_ENTRANCE_DESCRIPTION, '')			
		) AND 		
		(
			IS_NULL_CAT_ENTRANCE_DIRECTION = 1 OR
			`category_entrance`.`CAT_ENTRANCE_DIRECTION` = PARAM_CAT_ENTRANCE_DIRECTION			
		) AND
		(
			IS_NULL_CAT_ENTRANCE_STATUS = 1 OR
			`category_entrance`.`CAT_ENTRANCE_STATUS` = PARAM_CAT_ENTRANCE_STATUS			
		) 

	-- ORDER BY
	-- ####################################################
	ORDER BY
		-- CATEGORY_ENTRANCE DETAILS
		CASE WHEN PARAM_ORDER_FIELD = 'CAT_ENTRANCE_ID' AND PARAM_ORDER_TYPE = 'ASC' THEN `category_entrance`.`CAT_ENTRANCE_ID` END ASC, 
		CASE WHEN PARAM_ORDER_FIELD = 'CAT_ENTRANCE_ID' AND PARAM_ORDER_TYPE = 'DESC' THEN `category_entrance`.`CAT_ENTRANCE_ID` END DESC,	
		CASE WHEN PARAM_ORDER_FIELD = 'CAT_ENTRANCE_DESCRIPTION' AND PARAM_ORDER_TYPE = 'ASC' THEN `category_entrance`.`CAT_ENTRANCE_DESCRIPTION` END ASC, 
		CASE WHEN PARAM_ORDER_FIELD = 'CAT_ENTRANCE_DESCRIPTION' AND PARAM_ORDER_TYPE = 'DESC' THEN `category_entrance`.`CAT_ENTRANCE_DESCRIPTION` END DESC,	
		CASE WHEN PARAM_ORDER_FIELD = 'CAT_ENTRANCE_DIRECTION' AND PARAM_ORDER_TYPE = 'ASC' THEN `category_entrance`.`CAT_ENTRANCE_DIRECTION` END ASC, 
		CASE WHEN PARAM_ORDER_FIELD = 'CAT_ENTRANCE_DIRECTION' AND PARAM_ORDER_TYPE = 'DESC' THEN `category_entrance`.`CAT_ENTRANCE_DIRECTION` END DESC,	
		CASE WHEN PARAM_ORDER_FIELD = 'CAT_ENTRANCE_STATUS' AND PARAM_ORDER_TYPE = 'ASC' THEN `category_entrance`.`CAT_ENTRANCE_STATUS` END ASC, 
		CASE WHEN PARAM_ORDER_FIELD = 'CAT_ENTRANCE_STATUS' AND PARAM_ORDER_TYPE = 'DESC' THEN `category_entrance`.`CAT_ENTRANCE_STATUS` END DESC,	

		-- Inner joins
		
		-- EXTRA
		CASE WHEN PARAM_ORDER_FIELD <> 'CAT_ENTRANCE_DESCRIPTION' THEN `category_entrance`.`CAT_ENTRANCE_DESCRIPTION` END ASC
		
	-- LIMIT & OFFSET
	-- ####################################################		
	LIMIT PARAM_SKIP, PARAM_LIMIT;
	
	
	
	-- EXIT PROCEDURE
	-- =========================================================================================
	LEAVE SP_GET;
			
END ;;
DELIMITER ;
/*!50003 SET sql_mode              = @saved_sql_mode */ ;
/*!50003 SET character_set_client  = @saved_cs_client */ ;
/*!50003 SET character_set_results = @saved_cs_results */ ;
/*!50003 SET collation_connection  = @saved_col_connection */ ;
/*!50003 DROP PROCEDURE IF EXISTS `CATEGORY_ENTRANCE_SAVE` */;
/*!50003 SET @saved_cs_client      = @@character_set_client */ ;
/*!50003 SET @saved_cs_results     = @@character_set_results */ ;
/*!50003 SET @saved_col_connection = @@collation_connection */ ;
/*!50003 SET character_set_client  = latin1 */ ;
/*!50003 SET character_set_results = latin1 */ ;
/*!50003 SET collation_connection  = latin1_swedish_ci */ ;
/*!50003 SET @saved_sql_mode       = @@sql_mode */ ;
/*!50003 SET sql_mode              = '' */ ;
DELIMITER ;;
CREATE DEFINER=`root`@`localhost` PROCEDURE `CATEGORY_ENTRANCE_SAVE`(
	IN `PARAM_CAT_ENTRANCE_ID` BIGINT,
	IN `PARAM_CAT_ENTRANCE_DESCRIPTION` VARCHAR(400),
	IN `PARAM_CAT_ENTRANCE_DIRECTION` BIGINT,
	IN `PARAM_CAT_ENTRANCE_STATUS` TINYINT,

	IN `PARAM_REQUESTER_USERNAME` VARCHAR(500),
	IN `PARAM_REQUESTER_PASSWORD` VARCHAR(500),
	IN `PARAM_REQUESTER_PROXY_ID` BIGINT,
	IN `PARAM_REQUESTER_PROXY_PASSWORD` VARCHAR(1000),
	IN `PARAM_REQUESTER_DEVICE_PUBLIC_KEY` VARCHAR(1000),
	IN `PARAM_REQUESTER_DEVICE_PRIVATE_KEY` VARCHAR(1000),
	
	IN `PARAM_REQUESTER_IP` VARCHAR(1000),
	IN `PARAM_UNIQUE_SESSION_ID` VARCHAR(1000),
	IN `PARAM_SUPPRESS_RETURN` BIT,
	
	IN `PARAM_SYNC_SERVER_DESCRIPTION` VARCHAR(500), 
	IN `PARAM_SYNC_SERVER_UNIQUE_KEY` VARCHAR(500)
)
SP_SAVE:
BEGIN


	-- 1) DECLARE LOCAL PARAMETERS
	-- _______________________________________________________________________
	
	-- Status
	-- ...........................................
	DECLARE STATUS_INACTIVE TINYINT DEFAULT 1;
	DECLARE STATUS_ACTIVE TINYINT DEFAULT 2;
	DECLARE STATUS_CLOSED TINYINT DEFAULT 3;
	DECLARE STATUS_COMPLETED TINYINT DEFAULT 4;

	-- Audit Handler
	-- ...........................................
	DECLARE TEMP_RECORD_EXISTS BIT DEFAULT 0;
	DECLARE TEMP_MODULE_KEYWORD VARCHAR(500) DEFAULT 'category_entrance';
	DECLARE TEMP_SP_OBJECTIVE VARCHAR(500) DEFAULT 'add/edit Entrance record';
	DECLARE TEMP_ERR_MESSAGE VARCHAR(500) DEFAULT '';
	DECLARE ERR BIGINT DEFAULT 0;
	DECLARE TEMP_RECORD_CHANGES VARCHAR(16000) DEFAULT '';
	DECLARE TEMP_RECORD_BINDED BIT DEFAULT 0;

	-- Authentication
	-- ...........................................
	DECLARE TEMP_ACCESS_RIGHTS_DENIED BIT DEFAULT 0;
	DECLARE TEMP_ACCESS_RIGHTS_HAS_OVERRIDE BIT DEFAULT 0;
	DECLARE TEMP_SYNC_SERVER_ID BIGINT DEFAULT 0;
	DECLARE TEMP_SYNC_IS_SERVER_REQUEST BIT DEFAULT 0;
	DECLARE TEMP_AUTHENTICATED_ACCOUNT_ID BIGINT DEFAULT `ACCOUNT_MEMBER@ACC_ACCOUNT_ID_FROM_LOGIN`(PARAM_REQUESTER_USERNAME, PARAM_REQUESTER_PASSWORD);
	DECLARE TEMP_AUTHENTICATED_ACCOUNT_LEVEL BIGINT DEFAULT 0;
	DECLARE TEMP_AUTHENTICATED_ACCOUNT_GROUP BIGINT DEFAULT 0;
	
	-- Local Parameters
	-- ...........................................
	DECLARE TEMP_NOW DATETIME(6) DEFAULT `SYSTEM_VAR@NOW`('', 1);
	DECLARE TEMP_RECORD_COUNT BIGINT DEFAULT 0;

	-- AutoGen Parameters
	-- ...........................................
	
	-- Local value holder
	-- ...........................................
	DECLARE TEMP_CAT_ENTRANCE_DESCRIPTION VARCHAR(400) DEFAULT ''; 
	DECLARE TEMP_CAT_ENTRANCE_DIRECTION BIGINT DEFAULT 0; 
	DECLARE TEMP_CAT_ENTRANCE_STATUS TINYINT DEFAULT 0; 
	
	DECLARE REDUND_CAT_ENTRANCE_ID BIGINT DEFAULT 0; 


	-- 2) Try Catch / Throw
	-- _______________________________________________________________________
	DECLARE EXIT HANDLER FOR SQLEXCEPTION
	BEGIN
		RESIGNAL;
	END;



	-- 3) Prepare SYNC
	-- _______________________________________________________________________

	-- IS RECORD EXISTS		
	-- ####################################################	
	SET TEMP_RECORD_EXISTS = `CATEGORY_ENTRANCE@CAT_ENTRANCE_ID_EXISTS`(PARAM_CAT_ENTRANCE_ID, 0);

		
		
	-- 4) PREPARE AUTOGEN DATA (IF EXISTS)
	-- _______________________________________________________________________
	IF TEMP_SYNC_IS_SERVER_REQUEST = 0 THEN
		-- Just to keep at least one line within condition
		SET TEMP_SYNC_IS_SERVER_REQUEST = 0;
		
		-- Actual Functionalities here
		-- USE DEFAULT VALUE (String)
	END IF;



	-- 5) IF ALREADY EXIST, FILL MISSING DATA
	-- _______________________________________________________________________
	IF TEMP_RECORD_EXISTS = 1 THEN
		SELECT
			`category_entrance`.`CAT_ENTRANCE_DESCRIPTION`, 	
			`category_entrance`.`CAT_ENTRANCE_DIRECTION`, 	
			`category_entrance`.`CAT_ENTRANCE_STATUS`	
		INTO
			TEMP_CAT_ENTRANCE_DESCRIPTION, 	
			TEMP_CAT_ENTRANCE_DIRECTION, 	
			TEMP_CAT_ENTRANCE_STATUS	

		FROM `category_entrance`
		WHERE
			`category_entrance`.`CAT_ENTRANCE_ID` = PARAM_CAT_ENTRANCE_ID
		LIMIT 1;

		-- Replace NULLs with the existing data.
		SET PARAM_CAT_ENTRANCE_DESCRIPTION = `SYSTEM_VAR@REPLACE_NULL@NVARCHAR`(PARAM_CAT_ENTRANCE_DESCRIPTION, TEMP_CAT_ENTRANCE_DESCRIPTION, 1);
		SET PARAM_CAT_ENTRANCE_DIRECTION = `SYSTEM_VAR@REPLACE_NULL@BIGINT`(PARAM_CAT_ENTRANCE_DIRECTION, TEMP_CAT_ENTRANCE_DIRECTION, 1, 1);
		SET PARAM_CAT_ENTRANCE_STATUS = `SYSTEM_VAR@REPLACE_NULL@TINYINT`(PARAM_CAT_ENTRANCE_STATUS, TEMP_CAT_ENTRANCE_STATUS, 1, 1);
		
		-- AUTO GEN (NON-UPDATABLES)		
		
		-- AUTO GEN (UPDATABLE WITH STATUS CHANGE)

		-- AUTO GEN (UPDATABLE WITH STATUS [ACTIVE/INACTIVE] CHANGE)
		
		-- NON-UPDATABLE
		
		-- NON-UPDATABLE BUT NULL
		
	ELSE
		SET PARAM_CAT_ENTRANCE_DESCRIPTION = `SYSTEM_VAR@REPLACE_NULL@NVARCHAR`(PARAM_CAT_ENTRANCE_DESCRIPTION, '', 1);
		SET PARAM_CAT_ENTRANCE_DIRECTION = `SYSTEM_VAR@REPLACE_NULL@BIGINT`(PARAM_CAT_ENTRANCE_DIRECTION, 0, 1, 1);
		SET PARAM_CAT_ENTRANCE_STATUS = `SYSTEM_VAR@REPLACE_NULL@TINYINT`(PARAM_CAT_ENTRANCE_STATUS, 0, 1, 1);
		
	END IF;

	

	-- 6) PREPARE AUDIT TRAIL
	-- _______________________________________________________________________
	IF BINARY TEMP_CAT_ENTRANCE_DESCRIPTION <> PARAM_CAT_ENTRANCE_DESCRIPTION THEN
		SET TEMP_RECORD_CHANGES = 
		`SYSTEM_VAR@CONCAT_ADD`(' | ', TEMP_RECORD_CHANGES, CONCAT_WS(' ', 'Description: "', TEMP_CAT_ENTRANCE_DESCRIPTION, '" > "', PARAM_CAT_ENTRANCE_DESCRIPTION, '"'));
	END IF;
	IF TEMP_CAT_ENTRANCE_DIRECTION <> PARAM_CAT_ENTRANCE_DIRECTION THEN
		SET TEMP_RECORD_CHANGES = 
		`SYSTEM_VAR@CONCAT_ADD`(' | ', TEMP_RECORD_CHANGES, CONCAT_WS(' ', 'Direction: "', TEMP_CAT_ENTRANCE_DIRECTION, '" > "', PARAM_CAT_ENTRANCE_DIRECTION, '"'));
	END IF;	
	IF TEMP_CAT_ENTRANCE_STATUS <> PARAM_CAT_ENTRANCE_STATUS THEN
		SET TEMP_RECORD_CHANGES = 
		`SYSTEM_VAR@CONCAT_ADD`(' | ', TEMP_RECORD_CHANGES, CONCAT_WS(' ', 'Status: "', TEMP_CAT_ENTRANCE_STATUS, '" > "', PARAM_CAT_ENTRANCE_STATUS, '"'));
	END IF;	
		
	-- No Changes in data, reject request
	-- ####################################################
	IF CHARACTER_LENGTH(TEMP_RECORD_CHANGES) = 0 THEN
		IF PARAM_SUPPRESS_RETURN = 0 THEN
			SELECT PARAM_CAT_ENTRANCE_ID AS INSERTED_ID;
		END IF;
		LEAVE SP_SAVE;
	END IF;



	-- 7) VALIDATE
	-- _______________________________________________________________________

	-- Access Rights [Device]
	-- ####################################################
	IF `ACCOUNT_DEVICE@HAS_PERMISSION`(PARAM_REQUESTER_DEVICE_PUBLIC_KEY, PARAM_REQUESTER_DEVICE_PRIVATE_KEY) = 0 THEN
		SET TEMP_ERR_MESSAGE = 'Your device is not authorized yet to access this server.';
		SET ERR = `RAISERROR`(TEMP_ERR_MESSAGE);		
	END IF;
		
		
	-- Access Rights [Account]
	-- ####################################################
	
	IF 
		-- [ADD] Access Rights
		(
			TEMP_RECORD_EXISTS = 0 AND
			`ACCOUNT_ACCESS_RIGHTS@HAS_PERMISSION`(PARAM_REQUESTER_USERNAME, PARAM_REQUESTER_PASSWORD, 0, TEMP_MODULE_KEYWORD, 2) = 0 AND
			`ACCOUNT_ACCESS_RIGHTS@PROXY_PERMISSION`(PARAM_REQUESTER_PROXY_ID, PARAM_REQUESTER_PROXY_PASSWORD, 0, TEMP_MODULE_KEYWORD, 2) = 0
		) OR
		
		-- [EDIT] Access Rights
		(
			TEMP_RECORD_EXISTS = 1 AND
			`ACCOUNT_ACCESS_RIGHTS@HAS_PERMISSION`(PARAM_REQUESTER_USERNAME, PARAM_REQUESTER_PASSWORD, 0, TEMP_MODULE_KEYWORD, 3) = 0 AND
			`ACCOUNT_ACCESS_RIGHTS@PROXY_PERMISSION`(PARAM_REQUESTER_PROXY_ID, PARAM_REQUESTER_PROXY_PASSWORD, 0, TEMP_MODULE_KEYWORD, 3) = 0
		)
	THEN
		SET TEMP_ACCESS_RIGHTS_DENIED = 1;
		CALL `ACCOUNT_ACCESS_RIGHTS_DENY`
		(
			0, TEMP_MODULE_KEYWORD, PARAM_CAT_ENTRANCE_ID, 0, TEMP_SP_OBJECTIVE, TEMP_RECORD_CHANGES, 
			PARAM_REQUESTER_USERNAME, PARAM_REQUESTER_PASSWORD, 
			PARAM_REQUESTER_PROXY_ID, PARAM_REQUESTER_PROXY_PASSWORD,
			PARAM_REQUESTER_DEVICE_PUBLIC_KEY, PARAM_REQUESTER_DEVICE_PRIVATE_KEY,
			PARAM_REQUESTER_IP, PARAM_UNIQUE_SESSION_ID,
			TEMP_SYNC_SERVER_ID, PARAM_SUPPRESS_RETURN
		);
	END IF;
	SET TEMP_ACCESS_RIGHTS_HAS_OVERRIDE = `ACCOUNT_ACCESS_RIGHTS@HAS_PERMISSION`(PARAM_REQUESTER_USERNAME, PARAM_REQUESTER_PASSWORD, 0, TEMP_MODULE_KEYWORD, 4);
	

	-- Validation
	-- ####################################################
	IF TEMP_SYNC_IS_SERVER_REQUEST = 0 THEN
	

		-- FOREIGN KEY EXISTS
		-- ...........................................
		
		-- FOREIGN (OPTIONAL)KEY EXISTS [Validates if not null]
		-- ...........................................
		
		-- IS_ALLOW_NULL = FALSE
		-- ...........................................
				
		-- IS_ALLOW_ZERO = FALSE
		-- ...........................................
		IF PARAM_CAT_ENTRANCE_DIRECTION = 0 THEN
			CALL `VALIDATION_MISSING_FIELD`('`CAT_ENTRANCE_DIRECTION`', '`NULL`');
		END IF;		
		IF PARAM_CAT_ENTRANCE_STATUS = 0 THEN
			CALL `VALIDATION_MISSING_FIELD`('`CAT_ENTRANCE_STATUS`', '`NULL`');
		END IF;		
		
		-- IS_ALLOW_NEGATIVE = FALSE
		-- ...........................................
		IF PARAM_CAT_ENTRANCE_DIRECTION < 0 THEN
			CALL `VALIDATION_NEGATIVE`('`CAT_ENTRANCE_DIRECTION`', PARAM_CAT_ENTRANCE_DIRECTION);
		END IF;		
		IF PARAM_CAT_ENTRANCE_STATUS < 0 THEN
			CALL `VALIDATION_NEGATIVE`('`CAT_ENTRANCE_STATUS`', PARAM_CAT_ENTRANCE_STATUS);
		END IF;		
		
		-- IS_ALLOW_EMPTY_STRING = FALSE
		-- ...........................................
		IF `SYSTEM_VAR@IS_NULL@NVARCHAR`(PARAM_CAT_ENTRANCE_DESCRIPTION, 1) = 1 THEN
			CALL `VALIDATION_MISSING_FIELD`('`CAT_ENTRANCE_DESCRIPTION`', '`NULL`');
		END IF;
		
		-- IS_STATUS
		-- ...........................................
		IF `SYSTEM_STATUS@SYS_STATUS_ID_EXISTS`(PARAM_CAT_ENTRANCE_STATUS, 0) = 0 THEN
			SET TEMP_ERR_MESSAGE = CONCAT_WS(' ', 'Given STATUS[Status] does not exists or is inactive. ID: ', PARAM_CAT_ENTRANCE_STATUS);
			SET ERR = `RAISERROR`(TEMP_ERR_MESSAGE);
		END IF;
		
		-- IS STATUS Active / Inactive
		-- ...........................................
		
		-- Minimum / Maximum Value
		-- ...........................................
		
		-- IS_UNIQUE = TRUE
		-- ...........................................
		IF
		(
			SELECT COUNT(`category_entrance`.`CAT_ENTRANCE_ID`)
			FROM `category_entrance`
			WHERE		
				`category_entrance`.`CAT_ENTRANCE_DESCRIPTION` = PARAM_CAT_ENTRANCE_DESCRIPTION AND		
				`category_entrance`.`CAT_ENTRANCE_ID` <> PARAM_CAT_ENTRANCE_ID
		) >= 1
		THEN
			SELECT `category_entrance`.`CAT_ENTRANCE_ID`
			INTO REDUND_CAT_ENTRANCE_ID
			FROM `category_entrance`
			WHERE		
				`category_entrance`.`CAT_ENTRANCE_DESCRIPTION` = PARAM_CAT_ENTRANCE_DESCRIPTION AND		
				`category_entrance`.`CAT_ENTRANCE_ID` <> PARAM_CAT_ENTRANCE_ID		
			LIMIT 1; 
			SET TEMP_ERR_MESSAGE = CONCAT_WS(' ', PARAM_CAT_ENTRANCE_DESCRIPTION, '[', REDUND_CAT_ENTRANCE_ID, ']');
			CALL `VALIDATION_REDUNDANT_ENTRY`(TEMP_ERR_MESSAGE);
		END IF;
		
		-- RECORD IDENTIFIER
		-- ...........................................
		
		
		-- ON_UPDATE VALIDATION 
		-- ...........................................
		IF TEMP_RECORD_EXISTS = 1 THEN	
		
			-- Just to keep at least one line within condition
			SET TEMP_RECORD_EXISTS = 1;
			
		END IF;
		
	END IF;



	-- 8) INSERT / UPDATE
	-- _______________________________________________________________________

	-- INSERT NEW DATA
	-- ####################################################
	IF TEMP_RECORD_EXISTS = 0 THEN

		INSERT INTO
		`category_entrance`
		(
			`category_entrance`.`CAT_ENTRANCE_DESCRIPTION`, 
			`category_entrance`.`CAT_ENTRANCE_DIRECTION`, 
			`category_entrance`.`CAT_ENTRANCE_STATUS`
		)
		VALUES
		(
			PARAM_CAT_ENTRANCE_DESCRIPTION, 
			PARAM_CAT_ENTRANCE_DIRECTION, 
			PARAM_CAT_ENTRANCE_STATUS
		);	
		
		-- Update Audit trail with new ID	
		SET PARAM_CAT_ENTRANCE_ID = LAST_INSERT_ID();



	-- UPDATING EXISTING RECORD
	-- ####################################################
	ELSE
		UPDATE `category_entrance`
		SET
			`category_entrance`.`CAT_ENTRANCE_DESCRIPTION` = PARAM_CAT_ENTRANCE_DESCRIPTION, 
			`category_entrance`.`CAT_ENTRANCE_DIRECTION` = PARAM_CAT_ENTRANCE_DIRECTION, 
			`category_entrance`.`CAT_ENTRANCE_STATUS` = PARAM_CAT_ENTRANCE_STATUS
		WHERE
			`category_entrance`.`CAT_ENTRANCE_ID` = PARAM_CAT_ENTRANCE_ID;

	END IF;

	
	-- 9) AUDIT TRAIL
	-- _______________________________________________________________________
	CALL `ACCOUNT_AUDIT_TRAIL_SAVE`
	(
		0, TEMP_MODULE_KEYWORD, PARAM_CAT_ENTRANCE_ID, 0, 'SAVE', TEMP_SP_OBJECTIVE, TEMP_RECORD_CHANGES, 
		PARAM_REQUESTER_USERNAME, PARAM_REQUESTER_PASSWORD, 
		PARAM_REQUESTER_PROXY_ID, PARAM_REQUESTER_PROXY_PASSWORD,
		PARAM_REQUESTER_DEVICE_PUBLIC_KEY, PARAM_REQUESTER_DEVICE_PRIVATE_KEY,
		PARAM_REQUESTER_IP, PARAM_UNIQUE_SESSION_ID,
		TEMP_SYNC_SERVER_ID, PARAM_SUPPRESS_RETURN
	);
	

	-- 10) RETURN RESULT
	-- _______________________________________________________________________
	IF PARAM_SUPPRESS_RETURN = 0 THEN
		SELECT 
			PARAM_CAT_ENTRANCE_ID AS INSERTED_ID,
			TEMP_NOW AS SERVER_TIME;
	END IF;
	LEAVE SP_SAVE;


END ;;
DELIMITER ;
/*!50003 SET sql_mode              = @saved_sql_mode */ ;
/*!50003 SET character_set_client  = @saved_cs_client */ ;
/*!50003 SET character_set_results = @saved_cs_results */ ;
/*!50003 SET collation_connection  = @saved_col_connection */ ;
/*!50003 DROP PROCEDURE IF EXISTS `CATEGORY_NATIONALITY_DELETE` */;
/*!50003 SET @saved_cs_client      = @@character_set_client */ ;
/*!50003 SET @saved_cs_results     = @@character_set_results */ ;
/*!50003 SET @saved_col_connection = @@collation_connection */ ;
/*!50003 SET character_set_client  = latin1 */ ;
/*!50003 SET character_set_results = latin1 */ ;
/*!50003 SET collation_connection  = latin1_swedish_ci */ ;
/*!50003 SET @saved_sql_mode       = @@sql_mode */ ;
/*!50003 SET sql_mode              = '' */ ;
DELIMITER ;;
CREATE DEFINER=`root`@`localhost` PROCEDURE `CATEGORY_NATIONALITY_DELETE`(
	IN `PARAM_CAT_NATIONALITY_ID` BIGINT,

	IN `PARAM_REQUESTER_USERNAME` VARCHAR(500),
	IN `PARAM_REQUESTER_PASSWORD` VARCHAR(500),
	IN `PARAM_REQUESTER_PROXY_ID` BIGINT,
	IN `PARAM_REQUESTER_PROXY_PASSWORD` VARCHAR(1000),
	IN `PARAM_REQUESTER_DEVICE_PUBLIC_KEY` VARCHAR(1000),
	IN `PARAM_REQUESTER_DEVICE_PRIVATE_KEY` VARCHAR(1000),
	
	IN `PARAM_REQUESTER_IP` VARCHAR(1000),
	IN `PARAM_UNIQUE_SESSION_ID` VARCHAR(1000),
	IN `PARAM_SUPPRESS_RETURN` BIT,
	
	IN `PARAM_SYNC_SERVER_DESCRIPTION` VARCHAR(500), 
	IN `PARAM_SYNC_SERVER_UNIQUE_KEY` VARCHAR(500)
)
SP_DELETE:
BEGIN

	-- 1) DECLARE LOCAL PARAMETERS
	-- _______________________________________________________________________
	
	-- Status
	-- ...........................................
	DECLARE STATUS_INACTIVE TINYINT DEFAULT 1;
	DECLARE STATUS_ACTIVE TINYINT DEFAULT 2;
	DECLARE STATUS_CLOSED TINYINT DEFAULT 3;
	DECLARE STATUS_COMPLETED TINYINT DEFAULT 4;
	
	-- Audit Handler
	-- ...........................................
	DECLARE TEMP_RECORD_EXISTS BIT DEFAULT 0;
	DECLARE TEMP_MODULE_KEYWORD VARCHAR(500) DEFAULT 'category_nationality';
	DECLARE TEMP_SP_OBJECTIVE VARCHAR(500) DEFAULT 'delete Nationality record';
	DECLARE TEMP_ERR_MESSAGE VARCHAR(500) DEFAULT '';
	DECLARE ERR BIGINT DEFAULT 0;
	DECLARE TEMP_RECORD_CHANGES VARCHAR(16000) DEFAULT '';
	DECLARE TEMP_RECORD_BINDED BIT DEFAULT 0;
	
	DECLARE TEMP_RECORD_BINDED_ID BIGINT DEFAULT 0;
	DECLARE TEMP_RECORD_BINDED_SERVER_ID BIGINT DEFAULT 0;
	
	-- Authentication
	-- ...........................................
	DECLARE TEMP_ACCESS_RIGHTS_DENIED BIT DEFAULT 0;
	DECLARE TEMP_SYNC_SERVER_ID BIGINT DEFAULT 0;
	DECLARE TEMP_SYNC_IS_SERVER_REQUEST BIT DEFAULT 0;
	DECLARE TEMP_AUTHENTICATED_ACCOUNT_ID BIGINT DEFAULT `ACCOUNT_MEMBER@ACC_ACCOUNT_ID_FROM_LOGIN`(PARAM_REQUESTER_USERNAME, PARAM_REQUESTER_PASSWORD);
	DECLARE TEMP_AUTHENTICATED_ACCOUNT_LEVEL BIGINT DEFAULT 0;
	DECLARE TEMP_AUTHENTICATED_ACCOUNT_GROUP BIGINT DEFAULT 0;

	-- Local value holder
	-- ...........................................
		DECLARE TEMP_CAT_NATIONALITY_GLOBAL_ID VARCHAR(400) DEFAULT ''; 
		DECLARE TEMP_CAT_NATIONALITY_CODE VARCHAR(50) DEFAULT ''; 
		DECLARE TEMP_CAT_NATIONALITY_DESCRIPTION VARCHAR(500) DEFAULT ''; 
		DECLARE TEMP_CAT_NATIONALITY_STATUS TINYINT DEFAULT 0; 
		DECLARE TEMP_CAT_NATIONALITY_SYSTEM_GENERATED TINYINT DEFAULT 0; 

	
	
	-- 2) Try Catch / Throw
	-- _______________________________________________________________________
	DECLARE EXIT HANDLER FOR SQLEXCEPTION
	BEGIN
		RESIGNAL;
	END;

	
	-- 3) Prepare SYNC
	-- _______________________________________________________________________
	
	-- IS RECORD EXISTS		
	-- ####################################################		
	SET TEMP_RECORD_EXISTS = `CATEGORY_NATIONALITY@CAT_NATIONALITY_ID_EXISTS`(PARAM_CAT_NATIONALITY_ID, 0);


	-- 4) IF ALREADY EXIST, FILL MISSING DATA
	-- _______________________________________________________________________
	IF TEMP_RECORD_EXISTS = 1 THEN
		SELECT
				`category_nationality`.`CAT_NATIONALITY_GLOBAL_ID`, 	
				`category_nationality`.`CAT_NATIONALITY_CODE`, 	
				`category_nationality`.`CAT_NATIONALITY_DESCRIPTION`, 	
				`category_nationality`.`CAT_NATIONALITY_STATUS`, 	
				`category_nationality`.`CAT_NATIONALITY_SYSTEM_GENERATED`	
		INTO
				TEMP_CAT_NATIONALITY_GLOBAL_ID, 	
				TEMP_CAT_NATIONALITY_CODE, 	
				TEMP_CAT_NATIONALITY_DESCRIPTION, 	
				TEMP_CAT_NATIONALITY_STATUS, 	
				TEMP_CAT_NATIONALITY_SYSTEM_GENERATED	

		FROM `category_nationality`
		WHERE
			`category_nationality`.`CAT_NATIONALITY_ID` = PARAM_CAT_NATIONALITY_ID
		LIMIT 1;

	ELSE 
		IF TEMP_SYNC_IS_SERVER_REQUEST = 0 THEN
			SET TEMP_ERR_MESSAGE = CONCAT_WS(' ', 'Given Nationality does not exists or is inactive. ID:', PARAM_CAT_NATIONALITY_ID);
			SET ERR = `RAISERROR`(TEMP_ERR_MESSAGE);		
		END IF;
		LEAVE SP_DELETE;
		
	END IF;



	-- 5) PREPARE AUDIT TRAIL
	-- _______________________________________________________________________
	
		SET TEMP_RECORD_CHANGES = 
		`SYSTEM_VAR@CONCAT_ADD`(' | ', TEMP_RECORD_CHANGES, CONCAT_WS(' ', 'Sync ID: "', TEMP_CAT_NATIONALITY_GLOBAL_ID, '" > " DELETED "'));
		SET TEMP_RECORD_CHANGES = 
		`SYSTEM_VAR@CONCAT_ADD`(' | ', TEMP_RECORD_CHANGES, CONCAT_WS(' ', 'Unique Identifier: "', TEMP_CAT_NATIONALITY_CODE, '" > " DELETED "'));
		SET TEMP_RECORD_CHANGES = 
		`SYSTEM_VAR@CONCAT_ADD`(' | ', TEMP_RECORD_CHANGES, CONCAT_WS(' ', 'Description: "', TEMP_CAT_NATIONALITY_DESCRIPTION, '" > " DELETED "'));
		SET TEMP_RECORD_CHANGES = 
		`SYSTEM_VAR@CONCAT_ADD`(' | ', TEMP_RECORD_CHANGES, CONCAT_WS(' ', 'Status: "', TEMP_CAT_NATIONALITY_STATUS, '" > " DELETED "'));
		SET TEMP_RECORD_CHANGES = 
		`SYSTEM_VAR@CONCAT_ADD`(' | ', TEMP_RECORD_CHANGES, CONCAT_WS(' ', 'System Generated: "', TEMP_CAT_NATIONALITY_SYSTEM_GENERATED, '" > " DELETED "'));


	-- 6) VALIDATE
	-- _______________________________________________________________________
	
	-- Access Rights [Device]
	-- ####################################################
	IF `ACCOUNT_DEVICE@HAS_PERMISSION`(PARAM_REQUESTER_DEVICE_PUBLIC_KEY, PARAM_REQUESTER_DEVICE_PRIVATE_KEY) = 0 THEN
		SET TEMP_ERR_MESSAGE = 'Your device is not authorized yet to access this server.';
		SET ERR = `RAISERROR`(TEMP_ERR_MESSAGE);		
	END IF;
		
		
	-- Access Rights [Account]
	-- ####################################################	
	
	IF 
		-- [DELETE] Access Rights
		`ACCOUNT_ACCESS_RIGHTS@HAS_PERMISSION`(PARAM_REQUESTER_USERNAME, PARAM_REQUESTER_PASSWORD, 0, TEMP_MODULE_KEYWORD, 4) = 0 
	THEN
		SET TEMP_ACCESS_RIGHTS_DENIED = 1;
		CALL `ACCOUNT_ACCESS_RIGHTS_DENY`
		(
			0, TEMP_MODULE_KEYWORD, PARAM_CAT_NATIONALITY_ID, 0, TEMP_SP_OBJECTIVE, TEMP_RECORD_CHANGES, 
			PARAM_REQUESTER_USERNAME, PARAM_REQUESTER_PASSWORD, 
			PARAM_REQUESTER_PROXY_ID, PARAM_REQUESTER_PROXY_PASSWORD,
			PARAM_REQUESTER_DEVICE_PUBLIC_KEY, PARAM_REQUESTER_DEVICE_PRIVATE_KEY,
			PARAM_REQUESTER_IP, PARAM_UNIQUE_SESSION_ID,
			TEMP_SYNC_SERVER_ID, PARAM_SUPPRESS_RETURN
		);
	END IF;

	-- System Generated Record (Cannot be deleted)
	-- ####################################################
	IF TEMP_CAT_NATIONALITY_SYSTEM_GENERATED = STATUS_ACTIVE THEN
		CALL `VALIDATION_SYSTEM_GENERATED`
		(
			PARAM_CAT_NATIONALITY_ID,
			TEMP_CAT_NATIONALITY_DESCRIPTION, ''
		);
	END IF;
	
	-- If already used, cannot remove record
	-- ####################################################

	-- Leave Re-upload request
	-- ####################################################
	IF TEMP_RECORD_BINDED = 1 THEN
		IF TEMP_SYNC_IS_SERVER_REQUEST = 1 THEN
			
			LEAVE SP_DELETE;
		END IF;

		CALL `VALIDATION_DELETE_LINKED_RECORD`(TEMP_CAT_NATIONALITY_DESCRIPTION, '', TEMP_ERR_MESSAGE); 
	END IF;


	-- 7) DELETE
	-- _______________________________________________________________________
	DELETE FROM `category_nationality`
	WHERE `category_nationality`.`CAT_NATIONALITY_ID` = PARAM_CAT_NATIONALITY_ID
	LIMIT 1;


	-- 8) AUDIT TRAIL
	-- _______________________________________________________________________
	CALL `ACCOUNT_AUDIT_TRAIL_SAVE`
	(
		0, TEMP_MODULE_KEYWORD, PARAM_CAT_NATIONALITY_ID, 0, 'DELETE', TEMP_SP_OBJECTIVE, TEMP_RECORD_CHANGES, 
		PARAM_REQUESTER_USERNAME, PARAM_REQUESTER_PASSWORD, 
		PARAM_REQUESTER_PROXY_ID, PARAM_REQUESTER_PROXY_PASSWORD,
		PARAM_REQUESTER_DEVICE_PUBLIC_KEY, PARAM_REQUESTER_DEVICE_PRIVATE_KEY,
		PARAM_REQUESTER_IP, PARAM_UNIQUE_SESSION_ID,
		TEMP_SYNC_SERVER_ID, PARAM_SUPPRESS_RETURN
	);

END ;;
DELIMITER ;
/*!50003 SET sql_mode              = @saved_sql_mode */ ;
/*!50003 SET character_set_client  = @saved_cs_client */ ;
/*!50003 SET character_set_results = @saved_cs_results */ ;
/*!50003 SET collation_connection  = @saved_col_connection */ ;
/*!50003 DROP PROCEDURE IF EXISTS `CATEGORY_NATIONALITY_GET` */;
/*!50003 SET @saved_cs_client      = @@character_set_client */ ;
/*!50003 SET @saved_cs_results     = @@character_set_results */ ;
/*!50003 SET @saved_col_connection = @@collation_connection */ ;
/*!50003 SET character_set_client  = latin1 */ ;
/*!50003 SET character_set_results = latin1 */ ;
/*!50003 SET collation_connection  = latin1_swedish_ci */ ;
/*!50003 SET @saved_sql_mode       = @@sql_mode */ ;
/*!50003 SET sql_mode              = '' */ ;
DELIMITER ;;
CREATE DEFINER=`root`@`localhost` PROCEDURE `CATEGORY_NATIONALITY_GET`(
	IN `PARAM_CAT_NATIONALITY_ID` BIGINT,	
	IN `PARAM_CAT_NATIONALITY_GLOBAL_ID` VARCHAR(400),	
	IN `PARAM_CAT_NATIONALITY_CODE` VARCHAR(50),	
	IN `PARAM_CAT_NATIONALITY_DESCRIPTION` VARCHAR(500),	
	IN `PARAM_CAT_NATIONALITY_STATUS` TINYINT,	
	IN `PARAM_CAT_NATIONALITY_SYSTEM_GENERATED` TINYINT,	
		
	IN `PARAM_ORDER_FIELD` VARCHAR(500),
	IN `PARAM_ORDER_TYPE` VARCHAR(500),
	IN `PARAM_SKIP` BIGINT,
	IN `PARAM_LIMIT` BIGINT,

	IN `PARAM_REQUESTER_USERNAME` VARCHAR(500),
	IN `PARAM_REQUESTER_PASSWORD` VARCHAR(500),
	IN `PARAM_REQUESTER_PROXY_ID` BIGINT,
	IN `PARAM_REQUESTER_PROXY_PASSWORD` VARCHAR(1000),
	IN `PARAM_REQUESTER_DEVICE_PUBLIC_KEY` VARCHAR(1000),
	IN `PARAM_REQUESTER_DEVICE_PRIVATE_KEY` VARCHAR(1000),
	
	IN `PARAM_REQUESTER_IP` VARCHAR(1000),
	IN `PARAM_UNIQUE_SESSION_ID` VARCHAR(1000),
	IN `PARAM_SUPPRESS_RETURN` BIT
)
SP_GET:
BEGIN

	-- Status
	-- =========================================================================================
	DECLARE STATUS_INACTIVE TINYINT DEFAULT 1;
	DECLARE STATUS_ACTIVE TINYINT DEFAULT 2;
	DECLARE STATUS_CLOSED TINYINT DEFAULT 3;
	DECLARE STATUS_COMPLETED TINYINT DEFAULT 4;
	
	-- Audit Handler
	-- =========================================================================================
	DECLARE TEMP_RECORD_EXISTS BIT DEFAULT 0;
	DECLARE TEMP_MODULE_KEYWORD VARCHAR(500) DEFAULT 'category_nationality';
	DECLARE TEMP_SP_OBJECTIVE VARCHAR(500) DEFAULT 'Retrieve Nationality record';
	DECLARE TEMP_ERR_MESSAGE VARCHAR(500) DEFAULT '';
	DECLARE ERR BIGINT DEFAULT 0;
	DECLARE TEMP_RECORD_CHANGES VARCHAR(16000) DEFAULT '';
	DECLARE TEMP_RECORD_BINDED BIT DEFAULT 0;
	
	DECLARE TEMP_RECORD_BINDED_ID BIGINT DEFAULT 0;
	DECLARE TEMP_RECORD_BINDED_SERVER_ID BIGINT DEFAULT 0;
	
	-- Authentication
	-- =========================================================================================
	DECLARE TEMP_ACCESS_RIGHTS_DENIED BIT DEFAULT 0;
	DECLARE TEMP_AUTHENTICATED_ACCOUNT_ID BIGINT DEFAULT `ACCOUNT_MEMBER@ACC_ACCOUNT_ID_FROM_LOGIN`(PARAM_REQUESTER_USERNAME, PARAM_REQUESTER_PASSWORD);
	DECLARE TEMP_AUTHENTICATED_ACCOUNT_LEVEL BIGINT DEFAULT 0;
	DECLARE TEMP_AUTHENTICATED_ACCOUNT_GROUP BIGINT DEFAULT 0;
	
	-- Local Parameters
	-- =========================================================================================
	DECLARE TEMP_NOW DATETIME(6) DEFAULT `SYSTEM_VAR@NOW`('', 1);
	DECLARE TEMP_RECORD_COUNT BIGINT DEFAULT 0;
	
	
	-- Check NULLs
	-- =========================================================================================
	DECLARE IS_NULL_CAT_NATIONALITY_ID BIT DEFAULT `SYSTEM_VAR@IS_NULL@BIGINT`(PARAM_CAT_NATIONALITY_ID, 1, 1);
	DECLARE IS_NULL_CAT_NATIONALITY_GLOBAL_ID BIT DEFAULT `SYSTEM_VAR@IS_NULL@NVARCHAR`(PARAM_CAT_NATIONALITY_GLOBAL_ID, 1);
	DECLARE IS_NULL_CAT_NATIONALITY_CODE BIT DEFAULT `SYSTEM_VAR@IS_NULL@NVARCHAR`(PARAM_CAT_NATIONALITY_CODE, 1);
	DECLARE IS_NULL_CAT_NATIONALITY_DESCRIPTION BIT DEFAULT `SYSTEM_VAR@IS_NULL@NVARCHAR`(PARAM_CAT_NATIONALITY_DESCRIPTION, 1);
	DECLARE IS_NULL_CAT_NATIONALITY_STATUS BIT DEFAULT `SYSTEM_VAR@IS_NULL@TINYINT`(PARAM_CAT_NATIONALITY_STATUS, 1, 1);
	DECLARE IS_NULL_CAT_NATIONALITY_SYSTEM_GENERATED BIT DEFAULT `SYSTEM_VAR@IS_NULL@TINYINT`(PARAM_CAT_NATIONALITY_SYSTEM_GENERATED, 1, 1);
	
	-- Error Handler
	-- =========================================================================================
	DECLARE EXIT HANDLER FOR SQLEXCEPTION
	BEGIN
		RESIGNAL;
	END;
	
	-- Ignore Time from DateTime (Set Time 00:00:00.000000 and 23:59:59.999999)
	-- =========================================================================================
		
		
	-- Access Rights [Device]
	-- =========================================================================================
	IF `ACCOUNT_DEVICE@HAS_PERMISSION`(PARAM_REQUESTER_DEVICE_PUBLIC_KEY, PARAM_REQUESTER_DEVICE_PRIVATE_KEY) = 0 THEN
		SET TEMP_ERR_MESSAGE = 'Your device is not authorized yet to access this server.';
		SET ERR = `RAISERROR`(TEMP_ERR_MESSAGE);		
	END IF;
		
		
	-- Access Rights [Account]
	-- =========================================================================================
		
	
	
	
	-- COUNT RECORD
	-- =========================================================================================
	
	-- SELECT COLUMNS
	-- ####################################################
	SELECT
		COUNT(DISTINCT `category_nationality`.`CAT_NATIONALITY_ID`)
	INTO
		TEMP_RECORD_COUNT

	FROM `category_nationality`
	
		-- Add Inner Joins (Per Foreign-key)
		
		-- Add Optional Left Joins (Per Optional Foreign-key)
		
	-- CONDITIONS
	-- ####################################################
	WHERE
		(
			IS_NULL_CAT_NATIONALITY_ID = 1 OR
			`category_nationality`.`CAT_NATIONALITY_ID` = PARAM_CAT_NATIONALITY_ID			
		) AND
		(
			IS_NULL_CAT_NATIONALITY_GLOBAL_ID = 1 OR
			`category_nationality`.`CAT_NATIONALITY_GLOBAL_ID` LIKE CONCAT_WS('%', '', PARAM_CAT_NATIONALITY_GLOBAL_ID, '')			
		) AND 		
		(
			IS_NULL_CAT_NATIONALITY_CODE = 1 OR
			`category_nationality`.`CAT_NATIONALITY_CODE` LIKE CONCAT_WS('%', '', PARAM_CAT_NATIONALITY_CODE, '')			
		) AND 		
		(
			IS_NULL_CAT_NATIONALITY_DESCRIPTION = 1 OR
			`category_nationality`.`CAT_NATIONALITY_DESCRIPTION` LIKE CONCAT_WS('%', '', PARAM_CAT_NATIONALITY_DESCRIPTION, '')			
		) AND 		
		(
			IS_NULL_CAT_NATIONALITY_STATUS = 1 OR
			`category_nationality`.`CAT_NATIONALITY_STATUS` = PARAM_CAT_NATIONALITY_STATUS			
		) AND
		(
			IS_NULL_CAT_NATIONALITY_SYSTEM_GENERATED = 1 OR
			`category_nationality`.`CAT_NATIONALITY_SYSTEM_GENERATED` = PARAM_CAT_NATIONALITY_SYSTEM_GENERATED			
		) 
;	

		
		
	-- SELECT RECORDS
	-- =========================================================================================
	
	-- FETCH COLUMNS
	-- ####################################################
	SELECT
		-- CATEGORY_NATIONALITY DETAILS
		`category_nationality`.`CAT_NATIONALITY_ID`, 
		`category_nationality`.`CAT_NATIONALITY_GLOBAL_ID`, 
		`category_nationality`.`CAT_NATIONALITY_CODE`, 
		`category_nationality`.`CAT_NATIONALITY_DESCRIPTION`, 
		`category_nationality`.`CAT_NATIONALITY_STATUS`, 
		`category_nationality`.`CAT_NATIONALITY_SYSTEM_GENERATED`
		
		-- Inner join fields
		
		-- Left join fields
		
		, TEMP_RECORD_COUNT AS RECORD_COUNT

	FROM `category_nationality`
	
		-- Add Inner Joins (Per Foreign-key)
		
		-- Add Optional Left Joins (Per Optional Foreign-key)
		
	-- CONDITIONS
	-- ####################################################
	WHERE
		(
			IS_NULL_CAT_NATIONALITY_ID = 1 OR
			`category_nationality`.`CAT_NATIONALITY_ID` = PARAM_CAT_NATIONALITY_ID			
		) AND
		(
			IS_NULL_CAT_NATIONALITY_GLOBAL_ID = 1 OR
			`category_nationality`.`CAT_NATIONALITY_GLOBAL_ID` LIKE CONCAT_WS('%', '', PARAM_CAT_NATIONALITY_GLOBAL_ID, '')			
		) AND 		
		(
			IS_NULL_CAT_NATIONALITY_CODE = 1 OR
			`category_nationality`.`CAT_NATIONALITY_CODE` LIKE CONCAT_WS('%', '', PARAM_CAT_NATIONALITY_CODE, '')			
		) AND 		
		(
			IS_NULL_CAT_NATIONALITY_DESCRIPTION = 1 OR
			`category_nationality`.`CAT_NATIONALITY_DESCRIPTION` LIKE CONCAT_WS('%', '', PARAM_CAT_NATIONALITY_DESCRIPTION, '')			
		) AND 		
		(
			IS_NULL_CAT_NATIONALITY_STATUS = 1 OR
			`category_nationality`.`CAT_NATIONALITY_STATUS` = PARAM_CAT_NATIONALITY_STATUS			
		) AND
		(
			IS_NULL_CAT_NATIONALITY_SYSTEM_GENERATED = 1 OR
			`category_nationality`.`CAT_NATIONALITY_SYSTEM_GENERATED` = PARAM_CAT_NATIONALITY_SYSTEM_GENERATED			
		) 

	-- ORDER BY
	-- ####################################################
	ORDER BY
		-- CATEGORY_NATIONALITY DETAILS
		CASE WHEN PARAM_ORDER_FIELD = 'CAT_NATIONALITY_ID' AND PARAM_ORDER_TYPE = 'ASC' THEN `category_nationality`.`CAT_NATIONALITY_ID` END ASC, 
		CASE WHEN PARAM_ORDER_FIELD = 'CAT_NATIONALITY_ID' AND PARAM_ORDER_TYPE = 'DESC' THEN `category_nationality`.`CAT_NATIONALITY_ID` END DESC,	
		CASE WHEN PARAM_ORDER_FIELD = 'CAT_NATIONALITY_GLOBAL_ID' AND PARAM_ORDER_TYPE = 'ASC' THEN `category_nationality`.`CAT_NATIONALITY_GLOBAL_ID` END ASC, 
		CASE WHEN PARAM_ORDER_FIELD = 'CAT_NATIONALITY_GLOBAL_ID' AND PARAM_ORDER_TYPE = 'DESC' THEN `category_nationality`.`CAT_NATIONALITY_GLOBAL_ID` END DESC,	
		CASE WHEN PARAM_ORDER_FIELD = 'CAT_NATIONALITY_CODE' AND PARAM_ORDER_TYPE = 'ASC' THEN `category_nationality`.`CAT_NATIONALITY_CODE` END ASC, 
		CASE WHEN PARAM_ORDER_FIELD = 'CAT_NATIONALITY_CODE' AND PARAM_ORDER_TYPE = 'DESC' THEN `category_nationality`.`CAT_NATIONALITY_CODE` END DESC,	
		CASE WHEN PARAM_ORDER_FIELD = 'CAT_NATIONALITY_DESCRIPTION' AND PARAM_ORDER_TYPE = 'ASC' THEN `category_nationality`.`CAT_NATIONALITY_DESCRIPTION` END ASC, 
		CASE WHEN PARAM_ORDER_FIELD = 'CAT_NATIONALITY_DESCRIPTION' AND PARAM_ORDER_TYPE = 'DESC' THEN `category_nationality`.`CAT_NATIONALITY_DESCRIPTION` END DESC,	
		CASE WHEN PARAM_ORDER_FIELD = 'CAT_NATIONALITY_STATUS' AND PARAM_ORDER_TYPE = 'ASC' THEN `category_nationality`.`CAT_NATIONALITY_STATUS` END ASC, 
		CASE WHEN PARAM_ORDER_FIELD = 'CAT_NATIONALITY_STATUS' AND PARAM_ORDER_TYPE = 'DESC' THEN `category_nationality`.`CAT_NATIONALITY_STATUS` END DESC,	
		CASE WHEN PARAM_ORDER_FIELD = 'CAT_NATIONALITY_SYSTEM_GENERATED' AND PARAM_ORDER_TYPE = 'ASC' THEN `category_nationality`.`CAT_NATIONALITY_SYSTEM_GENERATED` END ASC, 
		CASE WHEN PARAM_ORDER_FIELD = 'CAT_NATIONALITY_SYSTEM_GENERATED' AND PARAM_ORDER_TYPE = 'DESC' THEN `category_nationality`.`CAT_NATIONALITY_SYSTEM_GENERATED` END DESC,	

		-- Inner joins
		
		-- EXTRA
		CASE WHEN PARAM_ORDER_FIELD <> 'CAT_NATIONALITY_DESCRIPTION' THEN `category_nationality`.`CAT_NATIONALITY_DESCRIPTION` END ASC
		
	-- LIMIT & OFFSET
	-- ####################################################		
	LIMIT PARAM_SKIP, PARAM_LIMIT;
	
	
	
	-- EXIT PROCEDURE
	-- =========================================================================================
	LEAVE SP_GET;
			
END ;;
DELIMITER ;
/*!50003 SET sql_mode              = @saved_sql_mode */ ;
/*!50003 SET character_set_client  = @saved_cs_client */ ;
/*!50003 SET character_set_results = @saved_cs_results */ ;
/*!50003 SET collation_connection  = @saved_col_connection */ ;
/*!50003 DROP PROCEDURE IF EXISTS `CATEGORY_NATIONALITY_SAVE` */;
/*!50003 SET @saved_cs_client      = @@character_set_client */ ;
/*!50003 SET @saved_cs_results     = @@character_set_results */ ;
/*!50003 SET @saved_col_connection = @@collation_connection */ ;
/*!50003 SET character_set_client  = latin1 */ ;
/*!50003 SET character_set_results = latin1 */ ;
/*!50003 SET collation_connection  = latin1_swedish_ci */ ;
/*!50003 SET @saved_sql_mode       = @@sql_mode */ ;
/*!50003 SET sql_mode              = '' */ ;
DELIMITER ;;
CREATE DEFINER=`root`@`localhost` PROCEDURE `CATEGORY_NATIONALITY_SAVE`(
	IN `PARAM_CAT_NATIONALITY_ID` BIGINT,
	IN `PARAM_CAT_NATIONALITY_CODE` VARCHAR(50),
	IN `PARAM_CAT_NATIONALITY_DESCRIPTION` VARCHAR(500),
	IN `PARAM_CAT_NATIONALITY_STATUS` TINYINT,

	IN `PARAM_REQUESTER_USERNAME` VARCHAR(500),
	IN `PARAM_REQUESTER_PASSWORD` VARCHAR(500),
	IN `PARAM_REQUESTER_PROXY_ID` BIGINT,
	IN `PARAM_REQUESTER_PROXY_PASSWORD` VARCHAR(1000),
	IN `PARAM_REQUESTER_DEVICE_PUBLIC_KEY` VARCHAR(1000),
	IN `PARAM_REQUESTER_DEVICE_PRIVATE_KEY` VARCHAR(1000),
	
	IN `PARAM_REQUESTER_IP` VARCHAR(1000),
	IN `PARAM_UNIQUE_SESSION_ID` VARCHAR(1000),
	IN `PARAM_SUPPRESS_RETURN` BIT,
	
	IN `PARAM_SYNC_SERVER_DESCRIPTION` VARCHAR(500), 
	IN `PARAM_SYNC_SERVER_UNIQUE_KEY` VARCHAR(500)
)
SP_SAVE:
BEGIN


	-- 1) DECLARE LOCAL PARAMETERS
	-- _______________________________________________________________________
	
	-- Status
	-- ...........................................
	DECLARE STATUS_INACTIVE TINYINT DEFAULT 1;
	DECLARE STATUS_ACTIVE TINYINT DEFAULT 2;
	DECLARE STATUS_CLOSED TINYINT DEFAULT 3;
	DECLARE STATUS_COMPLETED TINYINT DEFAULT 4;

	-- Audit Handler
	-- ...........................................
	DECLARE TEMP_RECORD_EXISTS BIT DEFAULT 0;
	DECLARE TEMP_MODULE_KEYWORD VARCHAR(500) DEFAULT 'category_nationality';
	DECLARE TEMP_SP_OBJECTIVE VARCHAR(500) DEFAULT 'add/edit Nationality record';
	DECLARE TEMP_ERR_MESSAGE VARCHAR(500) DEFAULT '';
	DECLARE ERR BIGINT DEFAULT 0;
	DECLARE TEMP_RECORD_CHANGES VARCHAR(16000) DEFAULT '';
	DECLARE TEMP_RECORD_BINDED BIT DEFAULT 0;

	-- Authentication
	-- ...........................................
	DECLARE TEMP_ACCESS_RIGHTS_DENIED BIT DEFAULT 0;
	DECLARE TEMP_ACCESS_RIGHTS_HAS_OVERRIDE BIT DEFAULT 0;
	DECLARE TEMP_SYNC_SERVER_ID BIGINT DEFAULT 0;
	DECLARE TEMP_SYNC_IS_SERVER_REQUEST BIT DEFAULT 0;
	DECLARE TEMP_AUTHENTICATED_ACCOUNT_ID BIGINT DEFAULT `ACCOUNT_MEMBER@ACC_ACCOUNT_ID_FROM_LOGIN`(PARAM_REQUESTER_USERNAME, PARAM_REQUESTER_PASSWORD);
	DECLARE TEMP_AUTHENTICATED_ACCOUNT_LEVEL BIGINT DEFAULT 0;
	DECLARE TEMP_AUTHENTICATED_ACCOUNT_GROUP BIGINT DEFAULT 0;
	
	-- Local Parameters
	-- ...........................................
	DECLARE TEMP_NOW DATETIME(6) DEFAULT `SYSTEM_VAR@NOW`('', 1);
	DECLARE TEMP_RECORD_COUNT BIGINT DEFAULT 0;

	-- AutoGen Parameters
	-- ...........................................
	DECLARE PARAM_CAT_NATIONALITY_GLOBAL_ID VARCHAR(400) DEFAULT ''; 
	DECLARE PARAM_CAT_NATIONALITY_SYSTEM_GENERATED TINYINT DEFAULT 0; 
	
	-- Local value holder
	-- ...........................................
	DECLARE TEMP_CAT_NATIONALITY_GLOBAL_ID VARCHAR(400) DEFAULT ''; 
	DECLARE TEMP_CAT_NATIONALITY_CODE VARCHAR(50) DEFAULT ''; 
	DECLARE TEMP_CAT_NATIONALITY_DESCRIPTION VARCHAR(500) DEFAULT ''; 
	DECLARE TEMP_CAT_NATIONALITY_STATUS TINYINT DEFAULT 0; 
	DECLARE TEMP_CAT_NATIONALITY_SYSTEM_GENERATED TINYINT DEFAULT 0; 
	


	-- 2) Try Catch / Throw
	-- _______________________________________________________________________
	DECLARE EXIT HANDLER FOR SQLEXCEPTION
	BEGIN
		RESIGNAL;
	END;



	-- 3) Prepare SYNC
	-- _______________________________________________________________________

	-- IS RECORD EXISTS		
	-- ####################################################	
	SET TEMP_RECORD_EXISTS = `CATEGORY_NATIONALITY@CAT_NATIONALITY_ID_EXISTS`(PARAM_CAT_NATIONALITY_ID, 0);

		
		
	-- 4) PREPARE AUTOGEN DATA (IF EXISTS)
	-- _______________________________________________________________________
	IF TEMP_SYNC_IS_SERVER_REQUEST = 0 THEN
		-- Just to keep at least one line within condition
		SET TEMP_SYNC_IS_SERVER_REQUEST = 0;
		
		-- Actual Functionalities here
		-- USE DEFAULT VALUE (String)
		-- USE DEFAULT VALUE (String)
		SET PARAM_CAT_NATIONALITY_GLOBAL_ID = `SYSTEM_VAR@RANDOM_UNIQUE_ALPHA32`;
		-- USE DEFAULT VALUE (String)
		SET PARAM_CAT_NATIONALITY_SYSTEM_GENERATED = 1;
	-- USE TIMESTAMP
	END IF;



	-- 5) IF ALREADY EXIST, FILL MISSING DATA
	-- _______________________________________________________________________
	IF TEMP_RECORD_EXISTS = 1 THEN
		SELECT
			`category_nationality`.`CAT_NATIONALITY_GLOBAL_ID`, 	
			`category_nationality`.`CAT_NATIONALITY_CODE`, 	
			`category_nationality`.`CAT_NATIONALITY_DESCRIPTION`, 	
			`category_nationality`.`CAT_NATIONALITY_STATUS`, 	
			`category_nationality`.`CAT_NATIONALITY_SYSTEM_GENERATED`	
		INTO
			TEMP_CAT_NATIONALITY_GLOBAL_ID, 	
			TEMP_CAT_NATIONALITY_CODE, 	
			TEMP_CAT_NATIONALITY_DESCRIPTION, 	
			TEMP_CAT_NATIONALITY_STATUS, 	
			TEMP_CAT_NATIONALITY_SYSTEM_GENERATED	

		FROM `category_nationality`
		WHERE
			`category_nationality`.`CAT_NATIONALITY_ID` = PARAM_CAT_NATIONALITY_ID
		LIMIT 1;

		-- Replace NULLs with the existing data.
		SET PARAM_CAT_NATIONALITY_CODE = `SYSTEM_VAR@REPLACE_NULL@NVARCHAR`(PARAM_CAT_NATIONALITY_CODE, TEMP_CAT_NATIONALITY_CODE, 1);
		SET PARAM_CAT_NATIONALITY_DESCRIPTION = `SYSTEM_VAR@REPLACE_NULL@NVARCHAR`(PARAM_CAT_NATIONALITY_DESCRIPTION, TEMP_CAT_NATIONALITY_DESCRIPTION, 1);
		SET PARAM_CAT_NATIONALITY_STATUS = `SYSTEM_VAR@REPLACE_NULL@TINYINT`(PARAM_CAT_NATIONALITY_STATUS, TEMP_CAT_NATIONALITY_STATUS, 1, 1);
		
		-- AUTO GEN (NON-UPDATABLES)		
		SET PARAM_CAT_NATIONALITY_GLOBAL_ID = TEMP_CAT_NATIONALITY_GLOBAL_ID;
		SET PARAM_CAT_NATIONALITY_SYSTEM_GENERATED = TEMP_CAT_NATIONALITY_SYSTEM_GENERATED;
		
		-- AUTO GEN (UPDATABLE WITH STATUS CHANGE)

		-- AUTO GEN (UPDATABLE WITH STATUS [ACTIVE/INACTIVE] CHANGE)
		
	ELSE
		SET PARAM_CAT_NATIONALITY_CODE = `SYSTEM_VAR@REPLACE_NULL@NVARCHAR`(PARAM_CAT_NATIONALITY_CODE, '', 1);
		SET PARAM_CAT_NATIONALITY_DESCRIPTION = `SYSTEM_VAR@REPLACE_NULL@NVARCHAR`(PARAM_CAT_NATIONALITY_DESCRIPTION, '', 1);
		SET PARAM_CAT_NATIONALITY_STATUS = `SYSTEM_VAR@REPLACE_NULL@TINYINT`(PARAM_CAT_NATIONALITY_STATUS, 0, 1, 1);
		
	END IF;

	

	-- 6) PREPARE AUDIT TRAIL
	-- _______________________________________________________________________
	IF BINARY TEMP_CAT_NATIONALITY_GLOBAL_ID <> PARAM_CAT_NATIONALITY_GLOBAL_ID THEN
		SET TEMP_RECORD_CHANGES = 
		`SYSTEM_VAR@CONCAT_ADD`(' | ', TEMP_RECORD_CHANGES, CONCAT_WS(' ', 'Sync ID: "', TEMP_CAT_NATIONALITY_GLOBAL_ID, '" > "', PARAM_CAT_NATIONALITY_GLOBAL_ID, '"'));
	END IF;
	IF BINARY TEMP_CAT_NATIONALITY_CODE <> PARAM_CAT_NATIONALITY_CODE THEN
		SET TEMP_RECORD_CHANGES = 
		`SYSTEM_VAR@CONCAT_ADD`(' | ', TEMP_RECORD_CHANGES, CONCAT_WS(' ', 'Unique Identifier: "', TEMP_CAT_NATIONALITY_CODE, '" > "', PARAM_CAT_NATIONALITY_CODE, '"'));
	END IF;
	IF BINARY TEMP_CAT_NATIONALITY_DESCRIPTION <> PARAM_CAT_NATIONALITY_DESCRIPTION THEN
		SET TEMP_RECORD_CHANGES = 
		`SYSTEM_VAR@CONCAT_ADD`(' | ', TEMP_RECORD_CHANGES, CONCAT_WS(' ', 'Description: "', TEMP_CAT_NATIONALITY_DESCRIPTION, '" > "', PARAM_CAT_NATIONALITY_DESCRIPTION, '"'));
	END IF;
	IF TEMP_CAT_NATIONALITY_STATUS <> PARAM_CAT_NATIONALITY_STATUS THEN
		SET TEMP_RECORD_CHANGES = 
		`SYSTEM_VAR@CONCAT_ADD`(' | ', TEMP_RECORD_CHANGES, CONCAT_WS(' ', 'Status: "', TEMP_CAT_NATIONALITY_STATUS, '" > "', PARAM_CAT_NATIONALITY_STATUS, '"'));
	END IF;	
	IF TEMP_CAT_NATIONALITY_SYSTEM_GENERATED <> PARAM_CAT_NATIONALITY_SYSTEM_GENERATED THEN
		SET TEMP_RECORD_CHANGES = 
		`SYSTEM_VAR@CONCAT_ADD`(' | ', TEMP_RECORD_CHANGES, CONCAT_WS(' ', 'System Generated: "', TEMP_CAT_NATIONALITY_SYSTEM_GENERATED, '" > "', PARAM_CAT_NATIONALITY_SYSTEM_GENERATED, '"'));
	END IF;	
		
	-- No Changes in data, reject request
	-- ####################################################
	IF CHARACTER_LENGTH(TEMP_RECORD_CHANGES) = 0 THEN
		IF PARAM_SUPPRESS_RETURN = 0 THEN
			SELECT PARAM_CAT_NATIONALITY_ID AS INSERTED_ID;
		END IF;
		LEAVE SP_SAVE;
	END IF;



	-- 7) VALIDATE
	-- _______________________________________________________________________

	-- Access Rights [Device]
	-- ####################################################
	IF `ACCOUNT_DEVICE@HAS_PERMISSION`(PARAM_REQUESTER_DEVICE_PUBLIC_KEY, PARAM_REQUESTER_DEVICE_PRIVATE_KEY) = 0 THEN
		SET TEMP_ERR_MESSAGE = 'Your device is not authorized yet to access this server.';
		SET ERR = `RAISERROR`(TEMP_ERR_MESSAGE);		
	END IF;
		
		
	-- Access Rights [Account]
	-- ####################################################
	
	IF 
		-- [ADD] Access Rights
		(
			TEMP_RECORD_EXISTS = 0 AND
			`ACCOUNT_ACCESS_RIGHTS@HAS_PERMISSION`(PARAM_REQUESTER_USERNAME, PARAM_REQUESTER_PASSWORD, 0, TEMP_MODULE_KEYWORD, 2) = 0 
		) OR
		
		-- [EDIT] Access Rights
		(
			TEMP_RECORD_EXISTS = 1 AND
			`ACCOUNT_ACCESS_RIGHTS@HAS_PERMISSION`(PARAM_REQUESTER_USERNAME, PARAM_REQUESTER_PASSWORD, 0, TEMP_MODULE_KEYWORD, 3) = 0 
		)
	THEN
		SET TEMP_ACCESS_RIGHTS_DENIED = 1;
		CALL `ACCOUNT_ACCESS_RIGHTS_DENY`
		(
			0, TEMP_MODULE_KEYWORD, PARAM_CAT_NATIONALITY_ID, 0, TEMP_SP_OBJECTIVE, TEMP_RECORD_CHANGES, 
			PARAM_REQUESTER_USERNAME, PARAM_REQUESTER_PASSWORD, 
			PARAM_REQUESTER_PROXY_ID, PARAM_REQUESTER_PROXY_PASSWORD,
			PARAM_REQUESTER_DEVICE_PUBLIC_KEY, PARAM_REQUESTER_DEVICE_PRIVATE_KEY,
			PARAM_REQUESTER_IP, PARAM_UNIQUE_SESSION_ID,
			TEMP_SYNC_SERVER_ID, PARAM_SUPPRESS_RETURN
		);
	END IF;
	SET TEMP_ACCESS_RIGHTS_HAS_OVERRIDE = `ACCOUNT_ACCESS_RIGHTS@HAS_PERMISSION`(PARAM_REQUESTER_USERNAME, PARAM_REQUESTER_PASSWORD, 0, TEMP_MODULE_KEYWORD, 4);
	

	-- Validation
	-- ####################################################
	IF TEMP_SYNC_IS_SERVER_REQUEST = 0 THEN
	
		-- SYSTEM GENERATED = TRUE
		-- ...........................................
		IF TEMP_CAT_NATIONALITY_SYSTEM_GENERATED = STATUS_ACTIVE THEN
		CALL `VALIDATION_SYSTEM_GENERATED`
		(
			PARAM_CAT_NATIONALITY_ID,
			TEMP_CAT_NATIONALITY_DESCRIPTION, ''
		);
		END IF;

		-- FOREIGN KEY EXISTS
		-- ...........................................
		
		-- FOREIGN (OPTIONAL)KEY EXISTS [Validates if not null]
		-- ...........................................
		
		-- IS_ALLOW_NULL = FALSE
		-- ...........................................
				
		-- IS_ALLOW_ZERO = FALSE
		-- ...........................................
		IF PARAM_CAT_NATIONALITY_STATUS = 0 THEN
			CALL `VALIDATION_MISSING_FIELD`('`CAT_NATIONALITY_STATUS`', '`NULL`');
		END IF;		
		IF PARAM_CAT_NATIONALITY_SYSTEM_GENERATED = 0 THEN
			CALL `VALIDATION_MISSING_FIELD`('`CAT_NATIONALITY_SYSTEM_GENERATED`', '`NULL`');
		END IF;		
		
		-- IS_ALLOW_NEGATIVE = FALSE
		-- ...........................................
		IF PARAM_CAT_NATIONALITY_STATUS < 0 THEN
			CALL `VALIDATION_NEGATIVE`('`CAT_NATIONALITY_STATUS`', PARAM_CAT_NATIONALITY_STATUS);
		END IF;		
		IF PARAM_CAT_NATIONALITY_SYSTEM_GENERATED < 0 THEN
			CALL `VALIDATION_NEGATIVE`('`CAT_NATIONALITY_SYSTEM_GENERATED`', PARAM_CAT_NATIONALITY_SYSTEM_GENERATED);
		END IF;		
		
		-- IS_ALLOW_EMPTY_STRING = FALSE
		-- ...........................................
		IF `SYSTEM_VAR@IS_NULL@NVARCHAR`(PARAM_CAT_NATIONALITY_GLOBAL_ID, 1) = 1 THEN
			CALL `VALIDATION_MISSING_FIELD`('`CAT_NATIONALITY_GLOBAL_ID`', '`NULL`');
		END IF;
		IF `SYSTEM_VAR@IS_NULL@NVARCHAR`(PARAM_CAT_NATIONALITY_CODE, 1) = 1 THEN
			CALL `VALIDATION_MISSING_FIELD`('`CAT_NATIONALITY_CODE`', '`NULL`');
		END IF;
		IF `SYSTEM_VAR@IS_NULL@NVARCHAR`(PARAM_CAT_NATIONALITY_DESCRIPTION, 1) = 1 THEN
			CALL `VALIDATION_MISSING_FIELD`('`CAT_NATIONALITY_DESCRIPTION`', '`NULL`');
		END IF;
		
		-- IS_STATUS
		-- ...........................................
		IF `SYSTEM_STATUS@STATUS_ID_EXISTS`(PARAM_CAT_NATIONALITY_STATUS, 0) = 0 THEN
			SET TEMP_ERR_MESSAGE = CONCAT_WS(' ', 'Given STATUS[Status] does not exists or is inactive. ID: ', PARAM_CAT_NATIONALITY_STATUS);
			SET ERR = `RAISERROR`(TEMP_ERR_MESSAGE);
		END IF;
		
		-- IS STATUS Active / Inactive
		-- ...........................................
		
		-- Minimum / Maximum Value
		-- ...........................................
		
		-- IS_UNIQUE = TRUE
		-- ...........................................
		IF
		(
			SELECT COUNT(`category_nationality`.`CAT_NATIONALITY_ID`)
			FROM `category_nationality`
			WHERE		
				`category_nationality`.`CAT_NATIONALITY_GLOBAL_ID` = PARAM_CAT_NATIONALITY_GLOBAL_ID AND		
				`category_nationality`.`CAT_NATIONALITY_ID` <> PARAM_CAT_NATIONALITY_ID
		) >= 1
		THEN
			CALL `VALIDATION_REDUNDANT_ENTRY`(PARAM_CAT_NATIONALITY_DESCRIPTION);
		END IF;
		IF
		(
			SELECT COUNT(`category_nationality`.`CAT_NATIONALITY_ID`)
			FROM `category_nationality`
			WHERE		
				`category_nationality`.`CAT_NATIONALITY_DESCRIPTION` = PARAM_CAT_NATIONALITY_DESCRIPTION AND		
				`category_nationality`.`CAT_NATIONALITY_ID` <> PARAM_CAT_NATIONALITY_ID
		) >= 1
		THEN
			CALL `VALIDATION_REDUNDANT_ENTRY`(PARAM_CAT_NATIONALITY_DESCRIPTION);
		END IF;
		
		-- RECORD IDENTIFIER
		-- ...........................................
		
		
		-- ON_UPDATE VALIDATION 
		-- ...........................................
		IF TEMP_RECORD_EXISTS = 1 THEN	
		
			-- Just to keep at least one line within condition
			SET TEMP_RECORD_EXISTS = 1;
			
		END IF;
		
	END IF;



	-- 8) INSERT / UPDATE
	-- _______________________________________________________________________

	-- INSERT NEW DATA
	-- ####################################################
	IF TEMP_RECORD_EXISTS = 0 THEN

		INSERT INTO
		`category_nationality`
		(
			`category_nationality`.`CAT_NATIONALITY_GLOBAL_ID`, 
			`category_nationality`.`CAT_NATIONALITY_CODE`, 
			`category_nationality`.`CAT_NATIONALITY_DESCRIPTION`, 
			`category_nationality`.`CAT_NATIONALITY_STATUS`, 
			`category_nationality`.`CAT_NATIONALITY_SYSTEM_GENERATED`
		)
		VALUES
		(
			PARAM_CAT_NATIONALITY_GLOBAL_ID, 
			PARAM_CAT_NATIONALITY_CODE, 
			PARAM_CAT_NATIONALITY_DESCRIPTION, 
			PARAM_CAT_NATIONALITY_STATUS, 
			PARAM_CAT_NATIONALITY_SYSTEM_GENERATED
		);	
		
		-- Update Audit trail with new ID	
		SET PARAM_CAT_NATIONALITY_ID = LAST_INSERT_ID();



	-- UPDATING EXISTING RECORD
	-- ####################################################
	ELSE
		UPDATE `category_nationality`
		SET
			`category_nationality`.`CAT_NATIONALITY_GLOBAL_ID` = PARAM_CAT_NATIONALITY_GLOBAL_ID, 
			`category_nationality`.`CAT_NATIONALITY_CODE` = PARAM_CAT_NATIONALITY_CODE, 
			`category_nationality`.`CAT_NATIONALITY_DESCRIPTION` = PARAM_CAT_NATIONALITY_DESCRIPTION, 
			`category_nationality`.`CAT_NATIONALITY_STATUS` = PARAM_CAT_NATIONALITY_STATUS, 
			`category_nationality`.`CAT_NATIONALITY_SYSTEM_GENERATED` = PARAM_CAT_NATIONALITY_SYSTEM_GENERATED
		WHERE
			`category_nationality`.`CAT_NATIONALITY_ID` = PARAM_CAT_NATIONALITY_ID;

	END IF;

	
	-- 9) AUDIT TRAIL
	-- _______________________________________________________________________
	CALL `ACCOUNT_AUDIT_TRAIL_SAVE`
	(
		0, TEMP_MODULE_KEYWORD, PARAM_CAT_NATIONALITY_ID, 0, 'SAVE', TEMP_SP_OBJECTIVE, TEMP_RECORD_CHANGES, 
		PARAM_REQUESTER_USERNAME, PARAM_REQUESTER_PASSWORD, 
		PARAM_REQUESTER_PROXY_ID, PARAM_REQUESTER_PROXY_PASSWORD,
		PARAM_REQUESTER_DEVICE_PUBLIC_KEY, PARAM_REQUESTER_DEVICE_PRIVATE_KEY,
		PARAM_REQUESTER_IP, PARAM_UNIQUE_SESSION_ID,
		TEMP_SYNC_SERVER_ID, PARAM_SUPPRESS_RETURN
	);
	

	-- 10) RETURN RESULT
	-- _______________________________________________________________________
	IF PARAM_SUPPRESS_RETURN = 0 THEN
		SELECT PARAM_CAT_NATIONALITY_ID AS INSERTED_ID;
	END IF;
	LEAVE SP_SAVE;


END ;;
DELIMITER ;
/*!50003 SET sql_mode              = @saved_sql_mode */ ;
/*!50003 SET character_set_client  = @saved_cs_client */ ;
/*!50003 SET character_set_results = @saved_cs_results */ ;
/*!50003 SET collation_connection  = @saved_col_connection */ ;
/*!50003 DROP PROCEDURE IF EXISTS `CATEGORY_RELIGION_DELETE` */;
/*!50003 SET @saved_cs_client      = @@character_set_client */ ;
/*!50003 SET @saved_cs_results     = @@character_set_results */ ;
/*!50003 SET @saved_col_connection = @@collation_connection */ ;
/*!50003 SET character_set_client  = latin1 */ ;
/*!50003 SET character_set_results = latin1 */ ;
/*!50003 SET collation_connection  = latin1_swedish_ci */ ;
/*!50003 SET @saved_sql_mode       = @@sql_mode */ ;
/*!50003 SET sql_mode              = '' */ ;
DELIMITER ;;
CREATE DEFINER=`root`@`localhost` PROCEDURE `CATEGORY_RELIGION_DELETE`(
	IN `PARAM_CAT_RELIGION_ID` BIGINT,

	IN `PARAM_REQUESTER_USERNAME` VARCHAR(500),
	IN `PARAM_REQUESTER_PASSWORD` VARCHAR(500),
	IN `PARAM_REQUESTER_PROXY_ID` BIGINT,
	IN `PARAM_REQUESTER_PROXY_PASSWORD` VARCHAR(1000),
	IN `PARAM_REQUESTER_DEVICE_PUBLIC_KEY` VARCHAR(1000),
	IN `PARAM_REQUESTER_DEVICE_PRIVATE_KEY` VARCHAR(1000),
	
	IN `PARAM_REQUESTER_IP` VARCHAR(1000),
	IN `PARAM_UNIQUE_SESSION_ID` VARCHAR(1000),
	IN `PARAM_SUPPRESS_RETURN` BIT,
	
	IN `PARAM_SYNC_SERVER_DESCRIPTION` VARCHAR(500), 
	IN `PARAM_SYNC_SERVER_UNIQUE_KEY` VARCHAR(500)
)
SP_DELETE:
BEGIN

	-- 1) DECLARE LOCAL PARAMETERS
	-- _______________________________________________________________________
	
	-- Status
	-- ...........................................
	DECLARE STATUS_INACTIVE TINYINT DEFAULT 1;
	DECLARE STATUS_ACTIVE TINYINT DEFAULT 2;
	DECLARE STATUS_CLOSED TINYINT DEFAULT 3;
	DECLARE STATUS_COMPLETED TINYINT DEFAULT 4;
	
	-- Audit Handler
	-- ...........................................
	DECLARE TEMP_RECORD_EXISTS BIT DEFAULT 0;
	DECLARE TEMP_MODULE_KEYWORD VARCHAR(500) DEFAULT 'category_religion';
	DECLARE TEMP_SP_OBJECTIVE VARCHAR(500) DEFAULT 'delete Religion record';
	DECLARE TEMP_ERR_MESSAGE VARCHAR(500) DEFAULT '';
	DECLARE ERR BIGINT DEFAULT 0;
	DECLARE TEMP_RECORD_CHANGES VARCHAR(16000) DEFAULT '';
	DECLARE TEMP_RECORD_BINDED BIT DEFAULT 0;
	
	DECLARE TEMP_RECORD_BINDED_ID BIGINT DEFAULT 0;
	DECLARE TEMP_RECORD_BINDED_SERVER_ID BIGINT DEFAULT 0;
	
	-- Authentication
	-- ...........................................
	DECLARE TEMP_ACCESS_RIGHTS_DENIED BIT DEFAULT 0;
	DECLARE TEMP_SYNC_SERVER_ID BIGINT DEFAULT 0;
	DECLARE TEMP_SYNC_IS_SERVER_REQUEST BIT DEFAULT 0;
	DECLARE TEMP_AUTHENTICATED_ACCOUNT_ID BIGINT DEFAULT `ACCOUNT_MEMBER@ACC_ACCOUNT_ID_FROM_LOGIN`(PARAM_REQUESTER_USERNAME, PARAM_REQUESTER_PASSWORD);
	DECLARE TEMP_AUTHENTICATED_ACCOUNT_LEVEL BIGINT DEFAULT 0;
	DECLARE TEMP_AUTHENTICATED_ACCOUNT_GROUP BIGINT DEFAULT 0;

	-- Local value holder
	-- ...........................................
		DECLARE TEMP_CAT_RELIGION_GLOBAL_ID VARCHAR(400) DEFAULT ''; 
		DECLARE TEMP_CAT_RELIGION_CODE VARCHAR(50) DEFAULT ''; 
		DECLARE TEMP_CAT_RELIGION_DESCRIPTION VARCHAR(500) DEFAULT ''; 
		DECLARE TEMP_CAT_RELIGION_STATUS TINYINT DEFAULT 0; 
		DECLARE TEMP_CAT_RELIGION_SYSTEM_GENERATED TINYINT DEFAULT 0; 

	
	
	-- 2) Try Catch / Throw
	-- _______________________________________________________________________
	DECLARE EXIT HANDLER FOR SQLEXCEPTION
	BEGIN
		RESIGNAL;
	END;

	
	-- 3) Prepare SYNC
	-- _______________________________________________________________________
	
	-- IS RECORD EXISTS		
	-- ####################################################		
	SET TEMP_RECORD_EXISTS = `CATEGORY_RELIGION@CAT_RELIGION_ID_EXISTS`(PARAM_CAT_RELIGION_ID, 0);


	-- 4) IF ALREADY EXIST, FILL MISSING DATA
	-- _______________________________________________________________________
	IF TEMP_RECORD_EXISTS = 1 THEN
		SELECT
				`category_religion`.`CAT_RELIGION_GLOBAL_ID`, 	
				`category_religion`.`CAT_RELIGION_CODE`, 	
				`category_religion`.`CAT_RELIGION_DESCRIPTION`, 	
				`category_religion`.`CAT_RELIGION_STATUS`, 	
				`category_religion`.`CAT_RELIGION_SYSTEM_GENERATED`	
		INTO
				TEMP_CAT_RELIGION_GLOBAL_ID, 	
				TEMP_CAT_RELIGION_CODE, 	
				TEMP_CAT_RELIGION_DESCRIPTION, 	
				TEMP_CAT_RELIGION_STATUS, 	
				TEMP_CAT_RELIGION_SYSTEM_GENERATED	

		FROM `category_religion`
		WHERE
			`category_religion`.`CAT_RELIGION_ID` = PARAM_CAT_RELIGION_ID
		LIMIT 1;

	ELSE 
		IF TEMP_SYNC_IS_SERVER_REQUEST = 0 THEN
			SET TEMP_ERR_MESSAGE = CONCAT_WS(' ', 'Given Religion does not exists or is inactive. ID:', PARAM_CAT_RELIGION_ID);
			SET ERR = `RAISERROR`(TEMP_ERR_MESSAGE);		
		END IF;
		LEAVE SP_DELETE;
		
	END IF;



	-- 5) PREPARE AUDIT TRAIL
	-- _______________________________________________________________________
	
		SET TEMP_RECORD_CHANGES = 
		`SYSTEM_VAR@CONCAT_ADD`(' | ', TEMP_RECORD_CHANGES, CONCAT_WS(' ', 'Sync ID: "', TEMP_CAT_RELIGION_GLOBAL_ID, '" > " DELETED "'));
		SET TEMP_RECORD_CHANGES = 
		`SYSTEM_VAR@CONCAT_ADD`(' | ', TEMP_RECORD_CHANGES, CONCAT_WS(' ', 'Unique Identifier Code: "', TEMP_CAT_RELIGION_CODE, '" > " DELETED "'));
		SET TEMP_RECORD_CHANGES = 
		`SYSTEM_VAR@CONCAT_ADD`(' | ', TEMP_RECORD_CHANGES, CONCAT_WS(' ', 'Description: "', TEMP_CAT_RELIGION_DESCRIPTION, '" > " DELETED "'));
		SET TEMP_RECORD_CHANGES = 
		`SYSTEM_VAR@CONCAT_ADD`(' | ', TEMP_RECORD_CHANGES, CONCAT_WS(' ', 'Status: "', TEMP_CAT_RELIGION_STATUS, '" > " DELETED "'));
		SET TEMP_RECORD_CHANGES = 
		`SYSTEM_VAR@CONCAT_ADD`(' | ', TEMP_RECORD_CHANGES, CONCAT_WS(' ', 'System Generated: "', TEMP_CAT_RELIGION_SYSTEM_GENERATED, '" > " DELETED "'));


	-- 6) VALIDATE
	-- _______________________________________________________________________
	
	-- Access Rights [Device]
	-- ####################################################
	IF `ACCOUNT_DEVICE@HAS_PERMISSION`(PARAM_REQUESTER_DEVICE_PUBLIC_KEY, PARAM_REQUESTER_DEVICE_PRIVATE_KEY) = 0 THEN
		SET TEMP_ERR_MESSAGE = 'Your device is not authorized yet to access this server.';
		SET ERR = `RAISERROR`(TEMP_ERR_MESSAGE);		
	END IF;
		
		
	-- Access Rights [Account]
	-- ####################################################	
	
	IF 
		-- [DELETE] Access Rights
		`ACCOUNT_ACCESS_RIGHTS@HAS_PERMISSION`(PARAM_REQUESTER_USERNAME, PARAM_REQUESTER_PASSWORD, 0, TEMP_MODULE_KEYWORD, 4) = 0 
	THEN
		SET TEMP_ACCESS_RIGHTS_DENIED = 1;
		CALL `ACCOUNT_ACCESS_RIGHTS_DENY`
		(
			0, TEMP_MODULE_KEYWORD, PARAM_CAT_RELIGION_ID, 0, TEMP_SP_OBJECTIVE, TEMP_RECORD_CHANGES, 
			PARAM_REQUESTER_USERNAME, PARAM_REQUESTER_PASSWORD, 
			PARAM_REQUESTER_PROXY_ID, PARAM_REQUESTER_PROXY_PASSWORD,
			PARAM_REQUESTER_DEVICE_PUBLIC_KEY, PARAM_REQUESTER_DEVICE_PRIVATE_KEY,
			PARAM_REQUESTER_IP, PARAM_UNIQUE_SESSION_ID,
			TEMP_SYNC_SERVER_ID, PARAM_SUPPRESS_RETURN
		);
	END IF;

	-- System Generated Record (Cannot be deleted)
	-- ####################################################
	IF TEMP_CAT_RELIGION_SYSTEM_GENERATED = STATUS_ACTIVE THEN
		CALL `VALIDATION_SYSTEM_GENERATED`
		(
			PARAM_CAT_RELIGION_ID,
			TEMP_CAT_RELIGION_DESCRIPTION, ''
		);
	END IF;
	
	-- If already used, cannot remove record
	-- ####################################################

	-- Leave Re-upload request
	-- ####################################################
	IF TEMP_RECORD_BINDED = 1 THEN
		IF TEMP_SYNC_IS_SERVER_REQUEST = 1 THEN
			
			LEAVE SP_DELETE;
		END IF;

		CALL `VALIDATION_DELETE_LINKED_RECORD`(TEMP_CAT_RELIGION_DESCRIPTION, '', TEMP_ERR_MESSAGE); 
	END IF;


	-- 7) DELETE
	-- _______________________________________________________________________
	DELETE FROM `category_religion`
	WHERE `category_religion`.`CAT_RELIGION_ID` = PARAM_CAT_RELIGION_ID
	LIMIT 1;


	-- 8) AUDIT TRAIL
	-- _______________________________________________________________________
	CALL `ACCOUNT_AUDIT_TRAIL_SAVE`
	(
		0, TEMP_MODULE_KEYWORD, PARAM_CAT_RELIGION_ID, 0, 'DELETE', TEMP_SP_OBJECTIVE, TEMP_RECORD_CHANGES, 
		PARAM_REQUESTER_USERNAME, PARAM_REQUESTER_PASSWORD, 
		PARAM_REQUESTER_PROXY_ID, PARAM_REQUESTER_PROXY_PASSWORD,
		PARAM_REQUESTER_DEVICE_PUBLIC_KEY, PARAM_REQUESTER_DEVICE_PRIVATE_KEY,
		PARAM_REQUESTER_IP, PARAM_UNIQUE_SESSION_ID,
		TEMP_SYNC_SERVER_ID, PARAM_SUPPRESS_RETURN
	);

END ;;
DELIMITER ;
/*!50003 SET sql_mode              = @saved_sql_mode */ ;
/*!50003 SET character_set_client  = @saved_cs_client */ ;
/*!50003 SET character_set_results = @saved_cs_results */ ;
/*!50003 SET collation_connection  = @saved_col_connection */ ;
/*!50003 DROP PROCEDURE IF EXISTS `CATEGORY_RELIGION_GET` */;
/*!50003 SET @saved_cs_client      = @@character_set_client */ ;
/*!50003 SET @saved_cs_results     = @@character_set_results */ ;
/*!50003 SET @saved_col_connection = @@collation_connection */ ;
/*!50003 SET character_set_client  = latin1 */ ;
/*!50003 SET character_set_results = latin1 */ ;
/*!50003 SET collation_connection  = latin1_swedish_ci */ ;
/*!50003 SET @saved_sql_mode       = @@sql_mode */ ;
/*!50003 SET sql_mode              = '' */ ;
DELIMITER ;;
CREATE DEFINER=`root`@`localhost` PROCEDURE `CATEGORY_RELIGION_GET`(
	IN `PARAM_CAT_RELIGION_ID` BIGINT,	
	IN `PARAM_CAT_RELIGION_GLOBAL_ID` VARCHAR(400),	
	IN `PARAM_CAT_RELIGION_CODE` VARCHAR(50),	
	IN `PARAM_CAT_RELIGION_DESCRIPTION` VARCHAR(500),	
	IN `PARAM_CAT_RELIGION_STATUS` TINYINT,	
	IN `PARAM_CAT_RELIGION_SYSTEM_GENERATED` TINYINT,	
		
	IN `PARAM_ORDER_FIELD` VARCHAR(500),
	IN `PARAM_ORDER_TYPE` VARCHAR(500),
	IN `PARAM_SKIP` BIGINT,
	IN `PARAM_LIMIT` BIGINT,

	IN `PARAM_REQUESTER_USERNAME` VARCHAR(500),
	IN `PARAM_REQUESTER_PASSWORD` VARCHAR(500),
	IN `PARAM_REQUESTER_PROXY_ID` BIGINT,
	IN `PARAM_REQUESTER_PROXY_PASSWORD` VARCHAR(1000),
	IN `PARAM_REQUESTER_DEVICE_PUBLIC_KEY` VARCHAR(1000),
	IN `PARAM_REQUESTER_DEVICE_PRIVATE_KEY` VARCHAR(1000),
	
	IN `PARAM_REQUESTER_IP` VARCHAR(1000),
	IN `PARAM_UNIQUE_SESSION_ID` VARCHAR(1000),
	IN `PARAM_SUPPRESS_RETURN` BIT
)
SP_GET:
BEGIN

	-- Status
	-- =========================================================================================
	DECLARE STATUS_INACTIVE TINYINT DEFAULT 1;
	DECLARE STATUS_ACTIVE TINYINT DEFAULT 2;
	DECLARE STATUS_CLOSED TINYINT DEFAULT 3;
	DECLARE STATUS_COMPLETED TINYINT DEFAULT 4;
	
	-- Audit Handler
	-- =========================================================================================
	DECLARE TEMP_RECORD_EXISTS BIT DEFAULT 0;
	DECLARE TEMP_MODULE_KEYWORD VARCHAR(500) DEFAULT 'category_religion';
	DECLARE TEMP_SP_OBJECTIVE VARCHAR(500) DEFAULT 'Retrieve Religion record';
	DECLARE TEMP_ERR_MESSAGE VARCHAR(500) DEFAULT '';
	DECLARE ERR BIGINT DEFAULT 0;
	DECLARE TEMP_RECORD_CHANGES VARCHAR(16000) DEFAULT '';
	DECLARE TEMP_RECORD_BINDED BIT DEFAULT 0;
	
	DECLARE TEMP_RECORD_BINDED_ID BIGINT DEFAULT 0;
	DECLARE TEMP_RECORD_BINDED_SERVER_ID BIGINT DEFAULT 0;
	
	-- Authentication
	-- =========================================================================================
	DECLARE TEMP_ACCESS_RIGHTS_DENIED BIT DEFAULT 0;
	DECLARE TEMP_AUTHENTICATED_ACCOUNT_ID BIGINT DEFAULT `ACCOUNT_MEMBER@ACC_ACCOUNT_ID_FROM_LOGIN`(PARAM_REQUESTER_USERNAME, PARAM_REQUESTER_PASSWORD);
	DECLARE TEMP_AUTHENTICATED_ACCOUNT_LEVEL BIGINT DEFAULT 0;
	DECLARE TEMP_AUTHENTICATED_ACCOUNT_GROUP BIGINT DEFAULT 0;
	
	-- Local Parameters
	-- =========================================================================================
	DECLARE TEMP_NOW DATETIME(6) DEFAULT `SYSTEM_VAR@NOW`('', 1);
	DECLARE TEMP_RECORD_COUNT BIGINT DEFAULT 0;
	
	
	-- Check NULLs
	-- =========================================================================================
	DECLARE IS_NULL_CAT_RELIGION_ID BIT DEFAULT `SYSTEM_VAR@IS_NULL@BIGINT`(PARAM_CAT_RELIGION_ID, 1, 1);
	DECLARE IS_NULL_CAT_RELIGION_GLOBAL_ID BIT DEFAULT `SYSTEM_VAR@IS_NULL@NVARCHAR`(PARAM_CAT_RELIGION_GLOBAL_ID, 1);
	DECLARE IS_NULL_CAT_RELIGION_CODE BIT DEFAULT `SYSTEM_VAR@IS_NULL@NVARCHAR`(PARAM_CAT_RELIGION_CODE, 1);
	DECLARE IS_NULL_CAT_RELIGION_DESCRIPTION BIT DEFAULT `SYSTEM_VAR@IS_NULL@NVARCHAR`(PARAM_CAT_RELIGION_DESCRIPTION, 1);
	DECLARE IS_NULL_CAT_RELIGION_STATUS BIT DEFAULT `SYSTEM_VAR@IS_NULL@TINYINT`(PARAM_CAT_RELIGION_STATUS, 1, 1);
	DECLARE IS_NULL_CAT_RELIGION_SYSTEM_GENERATED BIT DEFAULT `SYSTEM_VAR@IS_NULL@TINYINT`(PARAM_CAT_RELIGION_SYSTEM_GENERATED, 1, 1);
	
	-- Error Handler
	-- =========================================================================================
	DECLARE EXIT HANDLER FOR SQLEXCEPTION
	BEGIN
		RESIGNAL;
	END;
	
	-- Ignore Time from DateTime (Set Time 00:00:00.000000 and 23:59:59.999999)
	-- =========================================================================================
		
		
	-- Access Rights [Device]
	-- =========================================================================================
	IF `ACCOUNT_DEVICE@HAS_PERMISSION`(PARAM_REQUESTER_DEVICE_PUBLIC_KEY, PARAM_REQUESTER_DEVICE_PRIVATE_KEY) = 0 THEN
		SET TEMP_ERR_MESSAGE = 'Your device is not authorized yet to access this server.';
		SET ERR = `RAISERROR`(TEMP_ERR_MESSAGE);		
	END IF;
		
		
	-- Access Rights [Account]
	-- =========================================================================================
		
	
	
	
	-- COUNT RECORD
	-- =========================================================================================
	
	-- SELECT COLUMNS
	-- ####################################################
	SELECT
		COUNT(DISTINCT `category_religion`.`CAT_RELIGION_ID`)
	INTO
		TEMP_RECORD_COUNT

	FROM `category_religion`
	
		-- Add Inner Joins (Per Foreign-key)
		
		-- Add Optional Left Joins (Per Optional Foreign-key)
		
	-- CONDITIONS
	-- ####################################################
	WHERE
		(
			IS_NULL_CAT_RELIGION_ID = 1 OR
			`category_religion`.`CAT_RELIGION_ID` = PARAM_CAT_RELIGION_ID			
		) AND
		(
			IS_NULL_CAT_RELIGION_GLOBAL_ID = 1 OR
			`category_religion`.`CAT_RELIGION_GLOBAL_ID` LIKE CONCAT_WS('%', '', PARAM_CAT_RELIGION_GLOBAL_ID, '')			
		) AND 		
		(
			IS_NULL_CAT_RELIGION_CODE = 1 OR
			`category_religion`.`CAT_RELIGION_CODE` LIKE CONCAT_WS('%', '', PARAM_CAT_RELIGION_CODE, '')			
		) AND 		
		(
			IS_NULL_CAT_RELIGION_DESCRIPTION = 1 OR
			`category_religion`.`CAT_RELIGION_DESCRIPTION` LIKE CONCAT_WS('%', '', PARAM_CAT_RELIGION_DESCRIPTION, '')			
		) AND 		
		(
			IS_NULL_CAT_RELIGION_STATUS = 1 OR
			`category_religion`.`CAT_RELIGION_STATUS` = PARAM_CAT_RELIGION_STATUS			
		) AND
		(
			IS_NULL_CAT_RELIGION_SYSTEM_GENERATED = 1 OR
			`category_religion`.`CAT_RELIGION_SYSTEM_GENERATED` = PARAM_CAT_RELIGION_SYSTEM_GENERATED			
		) 
;	

		
		
	-- SELECT RECORDS
	-- =========================================================================================
	
	-- FETCH COLUMNS
	-- ####################################################
	SELECT
		-- CATEGORY_RELIGION DETAILS
		`category_religion`.`CAT_RELIGION_ID`, 
		`category_religion`.`CAT_RELIGION_GLOBAL_ID`, 
		`category_religion`.`CAT_RELIGION_CODE`, 
		`category_religion`.`CAT_RELIGION_DESCRIPTION`, 
		`category_religion`.`CAT_RELIGION_STATUS`, 
		`category_religion`.`CAT_RELIGION_SYSTEM_GENERATED`
		
		-- Inner join fields
		
		-- Left join fields
		
		, TEMP_RECORD_COUNT AS RECORD_COUNT

	FROM `category_religion`
	
		-- Add Inner Joins (Per Foreign-key)
		
		-- Add Optional Left Joins (Per Optional Foreign-key)
		
	-- CONDITIONS
	-- ####################################################
	WHERE
		(
			IS_NULL_CAT_RELIGION_ID = 1 OR
			`category_religion`.`CAT_RELIGION_ID` = PARAM_CAT_RELIGION_ID			
		) AND
		(
			IS_NULL_CAT_RELIGION_GLOBAL_ID = 1 OR
			`category_religion`.`CAT_RELIGION_GLOBAL_ID` LIKE CONCAT_WS('%', '', PARAM_CAT_RELIGION_GLOBAL_ID, '')			
		) AND 		
		(
			IS_NULL_CAT_RELIGION_CODE = 1 OR
			`category_religion`.`CAT_RELIGION_CODE` LIKE CONCAT_WS('%', '', PARAM_CAT_RELIGION_CODE, '')			
		) AND 		
		(
			IS_NULL_CAT_RELIGION_DESCRIPTION = 1 OR
			`category_religion`.`CAT_RELIGION_DESCRIPTION` LIKE CONCAT_WS('%', '', PARAM_CAT_RELIGION_DESCRIPTION, '')			
		) AND 		
		(
			IS_NULL_CAT_RELIGION_STATUS = 1 OR
			`category_religion`.`CAT_RELIGION_STATUS` = PARAM_CAT_RELIGION_STATUS			
		) AND
		(
			IS_NULL_CAT_RELIGION_SYSTEM_GENERATED = 1 OR
			`category_religion`.`CAT_RELIGION_SYSTEM_GENERATED` = PARAM_CAT_RELIGION_SYSTEM_GENERATED			
		) 

	-- ORDER BY
	-- ####################################################
	ORDER BY
		-- CATEGORY_RELIGION DETAILS
		CASE WHEN PARAM_ORDER_FIELD = 'CAT_RELIGION_ID' AND PARAM_ORDER_TYPE = 'ASC' THEN `category_religion`.`CAT_RELIGION_ID` END ASC, 
		CASE WHEN PARAM_ORDER_FIELD = 'CAT_RELIGION_ID' AND PARAM_ORDER_TYPE = 'DESC' THEN `category_religion`.`CAT_RELIGION_ID` END DESC,	
		CASE WHEN PARAM_ORDER_FIELD = 'CAT_RELIGION_GLOBAL_ID' AND PARAM_ORDER_TYPE = 'ASC' THEN `category_religion`.`CAT_RELIGION_GLOBAL_ID` END ASC, 
		CASE WHEN PARAM_ORDER_FIELD = 'CAT_RELIGION_GLOBAL_ID' AND PARAM_ORDER_TYPE = 'DESC' THEN `category_religion`.`CAT_RELIGION_GLOBAL_ID` END DESC,	
		CASE WHEN PARAM_ORDER_FIELD = 'CAT_RELIGION_CODE' AND PARAM_ORDER_TYPE = 'ASC' THEN `category_religion`.`CAT_RELIGION_CODE` END ASC, 
		CASE WHEN PARAM_ORDER_FIELD = 'CAT_RELIGION_CODE' AND PARAM_ORDER_TYPE = 'DESC' THEN `category_religion`.`CAT_RELIGION_CODE` END DESC,	
		CASE WHEN PARAM_ORDER_FIELD = 'CAT_RELIGION_DESCRIPTION' AND PARAM_ORDER_TYPE = 'ASC' THEN `category_religion`.`CAT_RELIGION_DESCRIPTION` END ASC, 
		CASE WHEN PARAM_ORDER_FIELD = 'CAT_RELIGION_DESCRIPTION' AND PARAM_ORDER_TYPE = 'DESC' THEN `category_religion`.`CAT_RELIGION_DESCRIPTION` END DESC,	
		CASE WHEN PARAM_ORDER_FIELD = 'CAT_RELIGION_STATUS' AND PARAM_ORDER_TYPE = 'ASC' THEN `category_religion`.`CAT_RELIGION_STATUS` END ASC, 
		CASE WHEN PARAM_ORDER_FIELD = 'CAT_RELIGION_STATUS' AND PARAM_ORDER_TYPE = 'DESC' THEN `category_religion`.`CAT_RELIGION_STATUS` END DESC,	
		CASE WHEN PARAM_ORDER_FIELD = 'CAT_RELIGION_SYSTEM_GENERATED' AND PARAM_ORDER_TYPE = 'ASC' THEN `category_religion`.`CAT_RELIGION_SYSTEM_GENERATED` END ASC, 
		CASE WHEN PARAM_ORDER_FIELD = 'CAT_RELIGION_SYSTEM_GENERATED' AND PARAM_ORDER_TYPE = 'DESC' THEN `category_religion`.`CAT_RELIGION_SYSTEM_GENERATED` END DESC,	

		-- Inner joins
		
		-- EXTRA
		CASE WHEN PARAM_ORDER_FIELD <> 'CAT_RELIGION_DESCRIPTION' THEN `category_religion`.`CAT_RELIGION_DESCRIPTION` END ASC
		
	-- LIMIT & OFFSET
	-- ####################################################		
	LIMIT PARAM_SKIP, PARAM_LIMIT;
	
	
	
	-- EXIT PROCEDURE
	-- =========================================================================================
	LEAVE SP_GET;
			
END ;;
DELIMITER ;
/*!50003 SET sql_mode              = @saved_sql_mode */ ;
/*!50003 SET character_set_client  = @saved_cs_client */ ;
/*!50003 SET character_set_results = @saved_cs_results */ ;
/*!50003 SET collation_connection  = @saved_col_connection */ ;
/*!50003 DROP PROCEDURE IF EXISTS `CATEGORY_RELIGION_SAVE` */;
/*!50003 SET @saved_cs_client      = @@character_set_client */ ;
/*!50003 SET @saved_cs_results     = @@character_set_results */ ;
/*!50003 SET @saved_col_connection = @@collation_connection */ ;
/*!50003 SET character_set_client  = latin1 */ ;
/*!50003 SET character_set_results = latin1 */ ;
/*!50003 SET collation_connection  = latin1_swedish_ci */ ;
/*!50003 SET @saved_sql_mode       = @@sql_mode */ ;
/*!50003 SET sql_mode              = '' */ ;
DELIMITER ;;
CREATE DEFINER=`root`@`localhost` PROCEDURE `CATEGORY_RELIGION_SAVE`(
	IN `PARAM_CAT_RELIGION_ID` BIGINT,
	IN `PARAM_CAT_RELIGION_CODE` VARCHAR(50),
	IN `PARAM_CAT_RELIGION_DESCRIPTION` VARCHAR(500),
	IN `PARAM_CAT_RELIGION_STATUS` TINYINT,

	IN `PARAM_REQUESTER_USERNAME` VARCHAR(500),
	IN `PARAM_REQUESTER_PASSWORD` VARCHAR(500),
	IN `PARAM_REQUESTER_PROXY_ID` BIGINT,
	IN `PARAM_REQUESTER_PROXY_PASSWORD` VARCHAR(1000),
	IN `PARAM_REQUESTER_DEVICE_PUBLIC_KEY` VARCHAR(1000),
	IN `PARAM_REQUESTER_DEVICE_PRIVATE_KEY` VARCHAR(1000),
	
	IN `PARAM_REQUESTER_IP` VARCHAR(1000),
	IN `PARAM_UNIQUE_SESSION_ID` VARCHAR(1000),
	IN `PARAM_SUPPRESS_RETURN` BIT,
	
	IN `PARAM_SYNC_SERVER_DESCRIPTION` VARCHAR(500), 
	IN `PARAM_SYNC_SERVER_UNIQUE_KEY` VARCHAR(500)
)
SP_SAVE:
BEGIN


	-- 1) DECLARE LOCAL PARAMETERS
	-- _______________________________________________________________________
	
	-- Status
	-- ...........................................
	DECLARE STATUS_INACTIVE TINYINT DEFAULT 1;
	DECLARE STATUS_ACTIVE TINYINT DEFAULT 2;
	DECLARE STATUS_CLOSED TINYINT DEFAULT 3;
	DECLARE STATUS_COMPLETED TINYINT DEFAULT 4;

	-- Audit Handler
	-- ...........................................
	DECLARE TEMP_RECORD_EXISTS BIT DEFAULT 0;
	DECLARE TEMP_MODULE_KEYWORD VARCHAR(500) DEFAULT 'category_religion';
	DECLARE TEMP_SP_OBJECTIVE VARCHAR(500) DEFAULT 'add/edit Religion record';
	DECLARE TEMP_ERR_MESSAGE VARCHAR(500) DEFAULT '';
	DECLARE ERR BIGINT DEFAULT 0;
	DECLARE TEMP_RECORD_CHANGES VARCHAR(16000) DEFAULT '';
	DECLARE TEMP_RECORD_BINDED BIT DEFAULT 0;

	-- Authentication
	-- ...........................................
	DECLARE TEMP_ACCESS_RIGHTS_DENIED BIT DEFAULT 0;
	DECLARE TEMP_ACCESS_RIGHTS_HAS_OVERRIDE BIT DEFAULT 0;
	DECLARE TEMP_SYNC_SERVER_ID BIGINT DEFAULT 0;
	DECLARE TEMP_SYNC_IS_SERVER_REQUEST BIT DEFAULT 0;
	DECLARE TEMP_AUTHENTICATED_ACCOUNT_ID BIGINT DEFAULT `ACCOUNT_MEMBER@ACC_ACCOUNT_ID_FROM_LOGIN`(PARAM_REQUESTER_USERNAME, PARAM_REQUESTER_PASSWORD);
	DECLARE TEMP_AUTHENTICATED_ACCOUNT_LEVEL BIGINT DEFAULT 0;
	DECLARE TEMP_AUTHENTICATED_ACCOUNT_GROUP BIGINT DEFAULT 0;
	
	-- Local Parameters
	-- ...........................................
	DECLARE TEMP_NOW DATETIME(6) DEFAULT `SYSTEM_VAR@NOW`('', 1);
	DECLARE TEMP_RECORD_COUNT BIGINT DEFAULT 0;

	-- AutoGen Parameters
	-- ...........................................
	DECLARE PARAM_CAT_RELIGION_GLOBAL_ID VARCHAR(400) DEFAULT ''; 
	DECLARE PARAM_CAT_RELIGION_SYSTEM_GENERATED TINYINT DEFAULT 0; 
	
	-- Local value holder
	-- ...........................................
	DECLARE TEMP_CAT_RELIGION_GLOBAL_ID VARCHAR(400) DEFAULT ''; 
	DECLARE TEMP_CAT_RELIGION_CODE VARCHAR(50) DEFAULT ''; 
	DECLARE TEMP_CAT_RELIGION_DESCRIPTION VARCHAR(500) DEFAULT ''; 
	DECLARE TEMP_CAT_RELIGION_STATUS TINYINT DEFAULT 0; 
	DECLARE TEMP_CAT_RELIGION_SYSTEM_GENERATED TINYINT DEFAULT 0; 
	


	-- 2) Try Catch / Throw
	-- _______________________________________________________________________
	DECLARE EXIT HANDLER FOR SQLEXCEPTION
	BEGIN
		RESIGNAL;
	END;



	-- 3) Prepare SYNC
	-- _______________________________________________________________________

	-- IS RECORD EXISTS		
	-- ####################################################	
	SET TEMP_RECORD_EXISTS = `CATEGORY_RELIGION@CAT_RELIGION_ID_EXISTS`(PARAM_CAT_RELIGION_ID, 0);

		
		
	-- 4) PREPARE AUTOGEN DATA (IF EXISTS)
	-- _______________________________________________________________________
	IF TEMP_SYNC_IS_SERVER_REQUEST = 0 THEN
		-- Just to keep at least one line within condition
		SET TEMP_SYNC_IS_SERVER_REQUEST = 0;
		
		-- Actual Functionalities here
		-- USE DEFAULT VALUE (String)
		-- USE DEFAULT VALUE (String)
		SET PARAM_CAT_RELIGION_GLOBAL_ID = `SYSTEM_VAR@RANDOM_UNIQUE_ALPHA32`;
		-- USE DEFAULT VALUE (String)
		SET PARAM_CAT_RELIGION_SYSTEM_GENERATED = 1;
	-- USE TIMESTAMP
	END IF;



	-- 5) IF ALREADY EXIST, FILL MISSING DATA
	-- _______________________________________________________________________
	IF TEMP_RECORD_EXISTS = 1 THEN
		SELECT
			`category_religion`.`CAT_RELIGION_GLOBAL_ID`, 	
			`category_religion`.`CAT_RELIGION_CODE`, 	
			`category_religion`.`CAT_RELIGION_DESCRIPTION`, 	
			`category_religion`.`CAT_RELIGION_STATUS`, 	
			`category_religion`.`CAT_RELIGION_SYSTEM_GENERATED`	
		INTO
			TEMP_CAT_RELIGION_GLOBAL_ID, 	
			TEMP_CAT_RELIGION_CODE, 	
			TEMP_CAT_RELIGION_DESCRIPTION, 	
			TEMP_CAT_RELIGION_STATUS, 	
			TEMP_CAT_RELIGION_SYSTEM_GENERATED	

		FROM `category_religion`
		WHERE
			`category_religion`.`CAT_RELIGION_ID` = PARAM_CAT_RELIGION_ID
		LIMIT 1;

		-- Replace NULLs with the existing data.
		SET PARAM_CAT_RELIGION_CODE = `SYSTEM_VAR@REPLACE_NULL@NVARCHAR`(PARAM_CAT_RELIGION_CODE, TEMP_CAT_RELIGION_CODE, 1);
		SET PARAM_CAT_RELIGION_DESCRIPTION = `SYSTEM_VAR@REPLACE_NULL@NVARCHAR`(PARAM_CAT_RELIGION_DESCRIPTION, TEMP_CAT_RELIGION_DESCRIPTION, 1);
		SET PARAM_CAT_RELIGION_STATUS = `SYSTEM_VAR@REPLACE_NULL@TINYINT`(PARAM_CAT_RELIGION_STATUS, TEMP_CAT_RELIGION_STATUS, 1, 1);
		
		-- AUTO GEN (NON-UPDATABLES)		
		SET PARAM_CAT_RELIGION_GLOBAL_ID = TEMP_CAT_RELIGION_GLOBAL_ID;
		SET PARAM_CAT_RELIGION_SYSTEM_GENERATED = TEMP_CAT_RELIGION_SYSTEM_GENERATED;
		
		-- AUTO GEN (UPDATABLE WITH STATUS CHANGE)

		-- AUTO GEN (UPDATABLE WITH STATUS [ACTIVE/INACTIVE] CHANGE)
		
	ELSE
		SET PARAM_CAT_RELIGION_CODE = `SYSTEM_VAR@REPLACE_NULL@NVARCHAR`(PARAM_CAT_RELIGION_CODE, '', 1);
		SET PARAM_CAT_RELIGION_DESCRIPTION = `SYSTEM_VAR@REPLACE_NULL@NVARCHAR`(PARAM_CAT_RELIGION_DESCRIPTION, '', 1);
		SET PARAM_CAT_RELIGION_STATUS = `SYSTEM_VAR@REPLACE_NULL@TINYINT`(PARAM_CAT_RELIGION_STATUS, 0, 1, 1);
		
	END IF;

	

	-- 6) PREPARE AUDIT TRAIL
	-- _______________________________________________________________________
	IF BINARY TEMP_CAT_RELIGION_GLOBAL_ID <> PARAM_CAT_RELIGION_GLOBAL_ID THEN
		SET TEMP_RECORD_CHANGES = 
		`SYSTEM_VAR@CONCAT_ADD`(' | ', TEMP_RECORD_CHANGES, CONCAT_WS(' ', 'Sync ID: "', TEMP_CAT_RELIGION_GLOBAL_ID, '" > "', PARAM_CAT_RELIGION_GLOBAL_ID, '"'));
	END IF;
	IF BINARY TEMP_CAT_RELIGION_CODE <> PARAM_CAT_RELIGION_CODE THEN
		SET TEMP_RECORD_CHANGES = 
		`SYSTEM_VAR@CONCAT_ADD`(' | ', TEMP_RECORD_CHANGES, CONCAT_WS(' ', 'Unique Identifier Code: "', TEMP_CAT_RELIGION_CODE, '" > "', PARAM_CAT_RELIGION_CODE, '"'));
	END IF;
	IF BINARY TEMP_CAT_RELIGION_DESCRIPTION <> PARAM_CAT_RELIGION_DESCRIPTION THEN
		SET TEMP_RECORD_CHANGES = 
		`SYSTEM_VAR@CONCAT_ADD`(' | ', TEMP_RECORD_CHANGES, CONCAT_WS(' ', 'Description: "', TEMP_CAT_RELIGION_DESCRIPTION, '" > "', PARAM_CAT_RELIGION_DESCRIPTION, '"'));
	END IF;
	IF TEMP_CAT_RELIGION_STATUS <> PARAM_CAT_RELIGION_STATUS THEN
		SET TEMP_RECORD_CHANGES = 
		`SYSTEM_VAR@CONCAT_ADD`(' | ', TEMP_RECORD_CHANGES, CONCAT_WS(' ', 'Status: "', TEMP_CAT_RELIGION_STATUS, '" > "', PARAM_CAT_RELIGION_STATUS, '"'));
	END IF;	
	IF TEMP_CAT_RELIGION_SYSTEM_GENERATED <> PARAM_CAT_RELIGION_SYSTEM_GENERATED THEN
		SET TEMP_RECORD_CHANGES = 
		`SYSTEM_VAR@CONCAT_ADD`(' | ', TEMP_RECORD_CHANGES, CONCAT_WS(' ', 'System Generated: "', TEMP_CAT_RELIGION_SYSTEM_GENERATED, '" > "', PARAM_CAT_RELIGION_SYSTEM_GENERATED, '"'));
	END IF;	
		
	-- No Changes in data, reject request
	-- ####################################################
	IF CHARACTER_LENGTH(TEMP_RECORD_CHANGES) = 0 THEN
		IF PARAM_SUPPRESS_RETURN = 0 THEN
			SELECT PARAM_CAT_RELIGION_ID AS INSERTED_ID;
		END IF;
		LEAVE SP_SAVE;
	END IF;



	-- 7) VALIDATE
	-- _______________________________________________________________________

	-- Access Rights [Device]
	-- ####################################################
	IF `ACCOUNT_DEVICE@HAS_PERMISSION`(PARAM_REQUESTER_DEVICE_PUBLIC_KEY, PARAM_REQUESTER_DEVICE_PRIVATE_KEY) = 0 THEN
		SET TEMP_ERR_MESSAGE = 'Your device is not authorized yet to access this server.';
		SET ERR = `RAISERROR`(TEMP_ERR_MESSAGE);		
	END IF;
		
		
	-- Access Rights [Account]
	-- ####################################################
	
	IF 
		-- [ADD] Access Rights
		(
			TEMP_RECORD_EXISTS = 0 AND
			`ACCOUNT_ACCESS_RIGHTS@HAS_PERMISSION`(PARAM_REQUESTER_USERNAME, PARAM_REQUESTER_PASSWORD, 0, TEMP_MODULE_KEYWORD, 2) = 0 
		) OR
		
		-- [EDIT] Access Rights
		(
			TEMP_RECORD_EXISTS = 1 AND
			`ACCOUNT_ACCESS_RIGHTS@HAS_PERMISSION`(PARAM_REQUESTER_USERNAME, PARAM_REQUESTER_PASSWORD, 0, TEMP_MODULE_KEYWORD, 3) = 0 
		)
	THEN
		SET TEMP_ACCESS_RIGHTS_DENIED = 1;
		CALL `ACCOUNT_ACCESS_RIGHTS_DENY`
		(
			0, TEMP_MODULE_KEYWORD, PARAM_CAT_RELIGION_ID, 0, TEMP_SP_OBJECTIVE, TEMP_RECORD_CHANGES, 
			PARAM_REQUESTER_USERNAME, PARAM_REQUESTER_PASSWORD, 
			PARAM_REQUESTER_PROXY_ID, PARAM_REQUESTER_PROXY_PASSWORD,
			PARAM_REQUESTER_DEVICE_PUBLIC_KEY, PARAM_REQUESTER_DEVICE_PRIVATE_KEY,
			PARAM_REQUESTER_IP, PARAM_UNIQUE_SESSION_ID,
			TEMP_SYNC_SERVER_ID, PARAM_SUPPRESS_RETURN
		);
	END IF;
	SET TEMP_ACCESS_RIGHTS_HAS_OVERRIDE = `ACCOUNT_ACCESS_RIGHTS@HAS_PERMISSION`(PARAM_REQUESTER_USERNAME, PARAM_REQUESTER_PASSWORD, 0, TEMP_MODULE_KEYWORD, 4);
	

	-- Validation
	-- ####################################################
	IF TEMP_SYNC_IS_SERVER_REQUEST = 0 THEN
	
		-- SYSTEM GENERATED = TRUE
		-- ...........................................
		IF TEMP_CAT_RELIGION_SYSTEM_GENERATED = STATUS_ACTIVE THEN
		CALL `VALIDATION_SYSTEM_GENERATED`
		(
			PARAM_CAT_RELIGION_ID,
			TEMP_CAT_RELIGION_DESCRIPTION, ''
		);
		END IF;

		-- FOREIGN KEY EXISTS
		-- ...........................................
		
		-- FOREIGN (OPTIONAL)KEY EXISTS [Validates if not null]
		-- ...........................................
		
		-- IS_ALLOW_NULL = FALSE
		-- ...........................................
				
		-- IS_ALLOW_ZERO = FALSE
		-- ...........................................
		IF PARAM_CAT_RELIGION_STATUS = 0 THEN
			CALL `VALIDATION_MISSING_FIELD`('`CAT_RELIGION_STATUS`', '`NULL`');
		END IF;		
		IF PARAM_CAT_RELIGION_SYSTEM_GENERATED = 0 THEN
			CALL `VALIDATION_MISSING_FIELD`('`CAT_RELIGION_SYSTEM_GENERATED`', '`NULL`');
		END IF;		
		
		-- IS_ALLOW_NEGATIVE = FALSE
		-- ...........................................
		IF PARAM_CAT_RELIGION_STATUS < 0 THEN
			CALL `VALIDATION_NEGATIVE`('`CAT_RELIGION_STATUS`', PARAM_CAT_RELIGION_STATUS);
		END IF;		
		IF PARAM_CAT_RELIGION_SYSTEM_GENERATED < 0 THEN
			CALL `VALIDATION_NEGATIVE`('`CAT_RELIGION_SYSTEM_GENERATED`', PARAM_CAT_RELIGION_SYSTEM_GENERATED);
		END IF;		
		
		-- IS_ALLOW_EMPTY_STRING = FALSE
		-- ...........................................
		IF `SYSTEM_VAR@IS_NULL@NVARCHAR`(PARAM_CAT_RELIGION_GLOBAL_ID, 1) = 1 THEN
			CALL `VALIDATION_MISSING_FIELD`('`CAT_RELIGION_GLOBAL_ID`', '`NULL`');
		END IF;
		IF `SYSTEM_VAR@IS_NULL@NVARCHAR`(PARAM_CAT_RELIGION_CODE, 1) = 1 THEN
			CALL `VALIDATION_MISSING_FIELD`('`CAT_RELIGION_CODE`', '`NULL`');
		END IF;
		IF `SYSTEM_VAR@IS_NULL@NVARCHAR`(PARAM_CAT_RELIGION_DESCRIPTION, 1) = 1 THEN
			CALL `VALIDATION_MISSING_FIELD`('`CAT_RELIGION_DESCRIPTION`', '`NULL`');
		END IF;
		
		-- IS_STATUS
		-- ...........................................
		IF `SYSTEM_STATUS@STATUS_ID_EXISTS`(PARAM_CAT_RELIGION_STATUS, 0) = 0 THEN
			SET TEMP_ERR_MESSAGE = CONCAT_WS(' ', 'Given STATUS[Status] does not exists or is inactive. ID: ', PARAM_CAT_RELIGION_STATUS);
			SET ERR = `RAISERROR`(TEMP_ERR_MESSAGE);
		END IF;
		
		-- IS STATUS Active / Inactive
		-- ...........................................
		
		-- Minimum / Maximum Value
		-- ...........................................
		
		-- IS_UNIQUE = TRUE
		-- ...........................................
		IF
		(
			SELECT COUNT(`category_religion`.`CAT_RELIGION_ID`)
			FROM `category_religion`
			WHERE		
				`category_religion`.`CAT_RELIGION_GLOBAL_ID` = PARAM_CAT_RELIGION_GLOBAL_ID AND		
				`category_religion`.`CAT_RELIGION_ID` <> PARAM_CAT_RELIGION_ID
		) >= 1
		THEN
			CALL `VALIDATION_REDUNDANT_ENTRY`(PARAM_CAT_RELIGION_DESCRIPTION);
		END IF;
		IF
		(
			SELECT COUNT(`category_religion`.`CAT_RELIGION_ID`)
			FROM `category_religion`
			WHERE		
				`category_religion`.`CAT_RELIGION_DESCRIPTION` = PARAM_CAT_RELIGION_DESCRIPTION AND		
				`category_religion`.`CAT_RELIGION_ID` <> PARAM_CAT_RELIGION_ID
		) >= 1
		THEN
			CALL `VALIDATION_REDUNDANT_ENTRY`(PARAM_CAT_RELIGION_DESCRIPTION);
		END IF;
		
		-- RECORD IDENTIFIER
		-- ...........................................
		
		
		-- ON_UPDATE VALIDATION 
		-- ...........................................
		IF TEMP_RECORD_EXISTS = 1 THEN	
		
			-- Just to keep at least one line within condition
			SET TEMP_RECORD_EXISTS = 1;
			
		END IF;
		
	END IF;



	-- 8) INSERT / UPDATE
	-- _______________________________________________________________________

	-- INSERT NEW DATA
	-- ####################################################
	IF TEMP_RECORD_EXISTS = 0 THEN

		INSERT INTO
		`category_religion`
		(
			`category_religion`.`CAT_RELIGION_GLOBAL_ID`, 
			`category_religion`.`CAT_RELIGION_CODE`, 
			`category_religion`.`CAT_RELIGION_DESCRIPTION`, 
			`category_religion`.`CAT_RELIGION_STATUS`, 
			`category_religion`.`CAT_RELIGION_SYSTEM_GENERATED`
		)
		VALUES
		(
			PARAM_CAT_RELIGION_GLOBAL_ID, 
			PARAM_CAT_RELIGION_CODE, 
			PARAM_CAT_RELIGION_DESCRIPTION, 
			PARAM_CAT_RELIGION_STATUS, 
			PARAM_CAT_RELIGION_SYSTEM_GENERATED
		);	
		
		-- Update Audit trail with new ID	
		SET PARAM_CAT_RELIGION_ID = LAST_INSERT_ID();



	-- UPDATING EXISTING RECORD
	-- ####################################################
	ELSE
		UPDATE `category_religion`
		SET
			`category_religion`.`CAT_RELIGION_GLOBAL_ID` = PARAM_CAT_RELIGION_GLOBAL_ID, 
			`category_religion`.`CAT_RELIGION_CODE` = PARAM_CAT_RELIGION_CODE, 
			`category_religion`.`CAT_RELIGION_DESCRIPTION` = PARAM_CAT_RELIGION_DESCRIPTION, 
			`category_religion`.`CAT_RELIGION_STATUS` = PARAM_CAT_RELIGION_STATUS, 
			`category_religion`.`CAT_RELIGION_SYSTEM_GENERATED` = PARAM_CAT_RELIGION_SYSTEM_GENERATED
		WHERE
			`category_religion`.`CAT_RELIGION_ID` = PARAM_CAT_RELIGION_ID;

	END IF;

	
	-- 9) AUDIT TRAIL
	-- _______________________________________________________________________
	CALL `ACCOUNT_AUDIT_TRAIL_SAVE`
	(
		0, TEMP_MODULE_KEYWORD, PARAM_CAT_RELIGION_ID, 0, 'SAVE', TEMP_SP_OBJECTIVE, TEMP_RECORD_CHANGES, 
		PARAM_REQUESTER_USERNAME, PARAM_REQUESTER_PASSWORD, 
		PARAM_REQUESTER_PROXY_ID, PARAM_REQUESTER_PROXY_PASSWORD,
		PARAM_REQUESTER_DEVICE_PUBLIC_KEY, PARAM_REQUESTER_DEVICE_PRIVATE_KEY,
		PARAM_REQUESTER_IP, PARAM_UNIQUE_SESSION_ID,
		TEMP_SYNC_SERVER_ID, PARAM_SUPPRESS_RETURN
	);
	

	-- 10) RETURN RESULT
	-- _______________________________________________________________________
	IF PARAM_SUPPRESS_RETURN = 0 THEN
		SELECT PARAM_CAT_RELIGION_ID AS INSERTED_ID;
	END IF;
	LEAVE SP_SAVE;


END ;;
DELIMITER ;
/*!50003 SET sql_mode              = @saved_sql_mode */ ;
/*!50003 SET character_set_client  = @saved_cs_client */ ;
/*!50003 SET character_set_results = @saved_cs_results */ ;
/*!50003 SET collation_connection  = @saved_col_connection */ ;
/*!50003 DROP PROCEDURE IF EXISTS `CATEGORY_SECTION_DELETE` */;
/*!50003 SET @saved_cs_client      = @@character_set_client */ ;
/*!50003 SET @saved_cs_results     = @@character_set_results */ ;
/*!50003 SET @saved_col_connection = @@collation_connection */ ;
/*!50003 SET character_set_client  = latin1 */ ;
/*!50003 SET character_set_results = latin1 */ ;
/*!50003 SET collation_connection  = latin1_swedish_ci */ ;
/*!50003 SET @saved_sql_mode       = @@sql_mode */ ;
/*!50003 SET sql_mode              = '' */ ;
DELIMITER ;;
CREATE DEFINER=`root`@`localhost` PROCEDURE `CATEGORY_SECTION_DELETE`(
	IN `PARAM_CAT_SECTION_ID` BIGINT,

	IN `PARAM_REQUESTER_USERNAME` VARCHAR(500),
	IN `PARAM_REQUESTER_PASSWORD` VARCHAR(500),
	IN `PARAM_REQUESTER_PROXY_ID` BIGINT,
	IN `PARAM_REQUESTER_PROXY_PASSWORD` VARCHAR(1000),
	IN `PARAM_REQUESTER_DEVICE_PUBLIC_KEY` VARCHAR(1000),
	IN `PARAM_REQUESTER_DEVICE_PRIVATE_KEY` VARCHAR(1000),
	
	IN `PARAM_REQUESTER_IP` VARCHAR(1000),
	IN `PARAM_UNIQUE_SESSION_ID` VARCHAR(1000),
	IN `PARAM_SUPPRESS_RETURN` BIT,
	
	IN `PARAM_SYNC_SERVER_DESCRIPTION` VARCHAR(500), 
	IN `PARAM_SYNC_SERVER_UNIQUE_KEY` VARCHAR(500)
)
SP_DELETE:
BEGIN

	-- 1) DECLARE LOCAL PARAMETERS
	-- _______________________________________________________________________
	
	-- Status
	-- ...........................................
	DECLARE STATUS_INACTIVE TINYINT DEFAULT 1;
	DECLARE STATUS_ACTIVE TINYINT DEFAULT 2;
	DECLARE STATUS_CLOSED TINYINT DEFAULT 3;
	DECLARE STATUS_COMPLETED TINYINT DEFAULT 4;
	
	-- Audit Handler
	-- ...........................................
	DECLARE TEMP_RECORD_EXISTS BIT DEFAULT 0;
	DECLARE TEMP_MODULE_KEYWORD VARCHAR(500) DEFAULT 'category_section';
	DECLARE TEMP_SP_OBJECTIVE VARCHAR(500) DEFAULT 'delete Section record';
	DECLARE TEMP_ERR_MESSAGE VARCHAR(500) DEFAULT '';
	DECLARE ERR BIGINT DEFAULT 0;
	DECLARE TEMP_RECORD_CHANGES VARCHAR(16000) DEFAULT '';
	DECLARE TEMP_RECORD_BINDED BIT DEFAULT 0;
	
	DECLARE TEMP_RECORD_BINDED_ID BIGINT DEFAULT 0;
	DECLARE TEMP_RECORD_BINDED_SERVER_ID BIGINT DEFAULT 0;
	
	-- Authentication
	-- ...........................................
	DECLARE TEMP_ACCESS_RIGHTS_DENIED BIT DEFAULT 0;
	DECLARE TEMP_SYNC_SERVER_ID BIGINT DEFAULT 0;
	DECLARE TEMP_SYNC_IS_SERVER_REQUEST BIT DEFAULT 0;
	DECLARE TEMP_AUTHENTICATED_ACCOUNT_ID BIGINT DEFAULT `ACCOUNT_MEMBER@ACC_ACCOUNT_ID_FROM_LOGIN`(PARAM_REQUESTER_USERNAME, PARAM_REQUESTER_PASSWORD);
	DECLARE TEMP_AUTHENTICATED_ACCOUNT_LEVEL BIGINT DEFAULT 0;
	DECLARE TEMP_AUTHENTICATED_ACCOUNT_GROUP BIGINT DEFAULT 0;

	-- Local value holder
	-- ...........................................
		DECLARE TEMP_CAT_SECTION_CAT_DEPARTMENT_ID BIGINT DEFAULT 0; 
		DECLARE TEMP_CAT_SECTION_DESCRIPTION VARCHAR(400) DEFAULT ''; 
		DECLARE TEMP_CAT_SECTION_STATUS TINYINT DEFAULT 0; 

	
	
	-- 2) Try Catch / Throw
	-- _______________________________________________________________________
	DECLARE EXIT HANDLER FOR SQLEXCEPTION
	BEGIN
		RESIGNAL;
	END;

	
	-- 3) Prepare SYNC
	-- _______________________________________________________________________
	
	-- IS RECORD EXISTS		
	-- ####################################################		
	SET TEMP_RECORD_EXISTS = `CATEGORY_SECTION@CAT_SECTION_ID_EXISTS`(PARAM_CAT_SECTION_ID, 0);


	-- 4) IF ALREADY EXIST, FILL MISSING DATA
	-- _______________________________________________________________________
	IF TEMP_RECORD_EXISTS = 1 THEN
		SELECT
				`category_section`.`CAT_SECTION_CAT_DEPARTMENT_ID`, 	
				`category_section`.`CAT_SECTION_DESCRIPTION`, 	
				`category_section`.`CAT_SECTION_STATUS`	
		INTO
				TEMP_CAT_SECTION_CAT_DEPARTMENT_ID, 	
				TEMP_CAT_SECTION_DESCRIPTION, 	
				TEMP_CAT_SECTION_STATUS	

		FROM `category_section`
		WHERE
			`category_section`.`CAT_SECTION_ID` = PARAM_CAT_SECTION_ID
		LIMIT 1;

	ELSE 
		IF TEMP_SYNC_IS_SERVER_REQUEST = 0 THEN
			SET TEMP_ERR_MESSAGE = CONCAT_WS(' ', 'Given Section does not exists or is inactive. ID:', PARAM_CAT_SECTION_ID);
			SET ERR = `RAISERROR`(TEMP_ERR_MESSAGE);		
		END IF;
		LEAVE SP_DELETE;
		
	END IF;



	-- 5) PREPARE AUDIT TRAIL
	-- _______________________________________________________________________
	
		SET TEMP_RECORD_CHANGES = 
		`SYSTEM_VAR@CONCAT_ADD`(' | ', TEMP_RECORD_CHANGES, CONCAT_WS(' ', 'Department: "', TEMP_CAT_SECTION_CAT_DEPARTMENT_ID, '" > " DELETED "'));
		SET TEMP_RECORD_CHANGES = 
		`SYSTEM_VAR@CONCAT_ADD`(' | ', TEMP_RECORD_CHANGES, CONCAT_WS(' ', 'Description: "', TEMP_CAT_SECTION_DESCRIPTION, '" > " DELETED "'));
		SET TEMP_RECORD_CHANGES = 
		`SYSTEM_VAR@CONCAT_ADD`(' | ', TEMP_RECORD_CHANGES, CONCAT_WS(' ', 'Status: "', TEMP_CAT_SECTION_STATUS, '" > " DELETED "'));


	-- 6) VALIDATE
	-- _______________________________________________________________________
	
	-- Access Rights [Device]
	-- ####################################################
	IF `ACCOUNT_DEVICE@HAS_PERMISSION`(PARAM_REQUESTER_DEVICE_PUBLIC_KEY, PARAM_REQUESTER_DEVICE_PRIVATE_KEY) = 0 THEN
		SET TEMP_ERR_MESSAGE = 'Your device is not authorized yet to access this server.';
		SET ERR = `RAISERROR`(TEMP_ERR_MESSAGE);		
	END IF;
		
		
	-- Access Rights [Account]
	-- ####################################################	
	
	IF 
		-- [DELETE] Access Rights
		`ACCOUNT_ACCESS_RIGHTS@HAS_PERMISSION`(PARAM_REQUESTER_USERNAME, PARAM_REQUESTER_PASSWORD, 0, TEMP_MODULE_KEYWORD, 4) = 0 AND
		`ACCOUNT_ACCESS_RIGHTS@PROXY_PERMISSION`(PARAM_REQUESTER_PROXY_ID, PARAM_REQUESTER_PROXY_PASSWORD, 0, TEMP_MODULE_KEYWORD, 4) = 0
	THEN
		SET TEMP_ACCESS_RIGHTS_DENIED = 1;
		CALL `ACCOUNT_ACCESS_RIGHTS_DENY`
		(
			0, TEMP_MODULE_KEYWORD, PARAM_CAT_SECTION_ID, 0, TEMP_SP_OBJECTIVE, TEMP_RECORD_CHANGES, 
			PARAM_REQUESTER_USERNAME, PARAM_REQUESTER_PASSWORD, 
			PARAM_REQUESTER_PROXY_ID, PARAM_REQUESTER_PROXY_PASSWORD,
			PARAM_REQUESTER_DEVICE_PUBLIC_KEY, PARAM_REQUESTER_DEVICE_PRIVATE_KEY,
			PARAM_REQUESTER_IP, PARAM_UNIQUE_SESSION_ID,
			TEMP_SYNC_SERVER_ID, PARAM_SUPPRESS_RETURN
		);
	END IF;

	
	-- If already used, cannot remove record
	-- ####################################################
	IF
	(
		SELECT
			COUNT(`record_user`.`REC_USER_CAT_SECTION_ID`)
		FROM `record_user`
		WHERE
			`record_user`.`REC_USER_CAT_SECTION_ID` = PARAM_CAT_SECTION_ID
		LIMIT 1
	) >= 1 
	THEN
		SET TEMP_RECORD_BINDED = 1;
		SET TEMP_ERR_MESSAGE = 'User Record';
	END IF;
	IF
	(
		SELECT
			COUNT(`record_registration`.`REC_REGISTRATION_CAT_SECTION_ID`)
		FROM `record_registration`
		WHERE
			`record_registration`.`REC_REGISTRATION_CAT_SECTION_ID` = PARAM_CAT_SECTION_ID
		LIMIT 1
	) >= 1 
	THEN
		SET TEMP_RECORD_BINDED = 1;
		SET TEMP_ERR_MESSAGE = 'Registration Record';
	END IF;

	-- Leave Re-upload request
	-- ####################################################
	IF TEMP_RECORD_BINDED = 1 THEN
		IF TEMP_SYNC_IS_SERVER_REQUEST = 1 THEN
			
			LEAVE SP_DELETE;
		END IF;

		CALL `VALIDATION_DELETE_LINKED_RECORD`(TEMP_CAT_SECTION_DESCRIPTION, '', TEMP_ERR_MESSAGE); 
	END IF;


	-- 7) DELETE
	-- _______________________________________________________________________
	DELETE FROM `category_section`
	WHERE `category_section`.`CAT_SECTION_ID` = PARAM_CAT_SECTION_ID
	LIMIT 1;


	-- 8) AUDIT TRAIL
	-- _______________________________________________________________________
	CALL `ACCOUNT_AUDIT_TRAIL_SAVE`
	(
		0, TEMP_MODULE_KEYWORD, PARAM_CAT_SECTION_ID, 0, 'DELETE', TEMP_SP_OBJECTIVE, TEMP_RECORD_CHANGES, 
		PARAM_REQUESTER_USERNAME, PARAM_REQUESTER_PASSWORD, 
		PARAM_REQUESTER_PROXY_ID, PARAM_REQUESTER_PROXY_PASSWORD,
		PARAM_REQUESTER_DEVICE_PUBLIC_KEY, PARAM_REQUESTER_DEVICE_PRIVATE_KEY,
		PARAM_REQUESTER_IP, PARAM_UNIQUE_SESSION_ID,
		TEMP_SYNC_SERVER_ID, PARAM_SUPPRESS_RETURN
	);

END ;;
DELIMITER ;
/*!50003 SET sql_mode              = @saved_sql_mode */ ;
/*!50003 SET character_set_client  = @saved_cs_client */ ;
/*!50003 SET character_set_results = @saved_cs_results */ ;
/*!50003 SET collation_connection  = @saved_col_connection */ ;
/*!50003 DROP PROCEDURE IF EXISTS `CATEGORY_SECTION_GET` */;
/*!50003 SET @saved_cs_client      = @@character_set_client */ ;
/*!50003 SET @saved_cs_results     = @@character_set_results */ ;
/*!50003 SET @saved_col_connection = @@collation_connection */ ;
/*!50003 SET character_set_client  = latin1 */ ;
/*!50003 SET character_set_results = latin1 */ ;
/*!50003 SET collation_connection  = latin1_swedish_ci */ ;
/*!50003 SET @saved_sql_mode       = @@sql_mode */ ;
/*!50003 SET sql_mode              = '' */ ;
DELIMITER ;;
CREATE DEFINER=`root`@`localhost` PROCEDURE `CATEGORY_SECTION_GET`(
	IN `PARAM_CAT_SECTION_ID` BIGINT,	
	IN `PARAM_CAT_SECTION_CAT_DEPARTMENT_ID` BIGINT,	
	IN `PARAM_CAT_SECTION_DESCRIPTION` VARCHAR(400),	
	IN `PARAM_CAT_SECTION_STATUS` TINYINT,	
		
	IN `PARAM_ORDER_FIELD` VARCHAR(500),
	IN `PARAM_ORDER_TYPE` VARCHAR(500),
	IN `PARAM_SKIP` BIGINT,
	IN `PARAM_LIMIT` BIGINT,

	IN `PARAM_REQUESTER_USERNAME` VARCHAR(500),
	IN `PARAM_REQUESTER_PASSWORD` VARCHAR(500),
	IN `PARAM_REQUESTER_PROXY_ID` BIGINT,
	IN `PARAM_REQUESTER_PROXY_PASSWORD` VARCHAR(1000),
	IN `PARAM_REQUESTER_DEVICE_PUBLIC_KEY` VARCHAR(1000),
	IN `PARAM_REQUESTER_DEVICE_PRIVATE_KEY` VARCHAR(1000),
	
	IN `PARAM_REQUESTER_IP` VARCHAR(1000),
	IN `PARAM_UNIQUE_SESSION_ID` VARCHAR(1000),
	IN `PARAM_SUPPRESS_RETURN` BIT
)
SP_GET:
BEGIN

	-- Status
	-- =========================================================================================
	DECLARE STATUS_INACTIVE TINYINT DEFAULT 1;
	DECLARE STATUS_ACTIVE TINYINT DEFAULT 2;
	DECLARE STATUS_CLOSED TINYINT DEFAULT 3;
	DECLARE STATUS_COMPLETED TINYINT DEFAULT 4;
	
	-- Audit Handler
	-- =========================================================================================
	DECLARE TEMP_RECORD_EXISTS BIT DEFAULT 0;
	DECLARE TEMP_MODULE_KEYWORD VARCHAR(500) DEFAULT 'category_section';
	DECLARE TEMP_SP_OBJECTIVE VARCHAR(500) DEFAULT 'Retrieve Section record';
	DECLARE TEMP_ERR_MESSAGE VARCHAR(500) DEFAULT '';
	DECLARE ERR BIGINT DEFAULT 0;
	DECLARE TEMP_RECORD_CHANGES VARCHAR(16000) DEFAULT '';
	DECLARE TEMP_RECORD_BINDED BIT DEFAULT 0;
	
	DECLARE TEMP_RECORD_BINDED_ID BIGINT DEFAULT 0;
	DECLARE TEMP_RECORD_BINDED_SERVER_ID BIGINT DEFAULT 0;
	
	-- Authentication
	-- =========================================================================================
	DECLARE TEMP_ACCESS_RIGHTS_DENIED BIT DEFAULT 0;
	DECLARE TEMP_AUTHENTICATED_ACCOUNT_ID BIGINT DEFAULT `ACCOUNT_MEMBER@ACC_ACCOUNT_ID_FROM_LOGIN`(PARAM_REQUESTER_USERNAME, PARAM_REQUESTER_PASSWORD);
	DECLARE TEMP_AUTHENTICATED_ACCOUNT_LEVEL BIGINT DEFAULT 0;
	DECLARE TEMP_AUTHENTICATED_ACCOUNT_GROUP BIGINT DEFAULT 0;
	
	-- Local Parameters
	-- =========================================================================================
	DECLARE TEMP_NOW DATETIME(6) DEFAULT `SYSTEM_VAR@NOW`('', 1);
	DECLARE TEMP_RECORD_COUNT BIGINT DEFAULT 0;
	
	
	-- Check NULLs
	-- =========================================================================================
	DECLARE IS_NULL_CAT_SECTION_ID BIT DEFAULT `SYSTEM_VAR@IS_NULL@BIGINT`(PARAM_CAT_SECTION_ID, 1, 1);
	DECLARE IS_NULL_CAT_SECTION_CAT_DEPARTMENT_ID BIT DEFAULT `SYSTEM_VAR@IS_NULL@BIGINT`(PARAM_CAT_SECTION_CAT_DEPARTMENT_ID, 1, 1);
	DECLARE IS_NULL_CAT_SECTION_DESCRIPTION BIT DEFAULT `SYSTEM_VAR@IS_NULL@NVARCHAR`(PARAM_CAT_SECTION_DESCRIPTION, 1);
	DECLARE IS_NULL_CAT_SECTION_STATUS BIT DEFAULT `SYSTEM_VAR@IS_NULL@TINYINT`(PARAM_CAT_SECTION_STATUS, 1, 1);
	
	-- Error Handler
	-- =========================================================================================
	DECLARE EXIT HANDLER FOR SQLEXCEPTION
	BEGIN
		RESIGNAL;
	END;
	
	-- Ignore Time from DateTime (Set Time 00:00:00.000000 and 23:59:59.999999)
	-- =========================================================================================
		
		
	-- Access Rights [Device]
	-- =========================================================================================
	IF `ACCOUNT_DEVICE@HAS_PERMISSION`(PARAM_REQUESTER_DEVICE_PUBLIC_KEY, PARAM_REQUESTER_DEVICE_PRIVATE_KEY) = 0 THEN
		SET TEMP_ERR_MESSAGE = 'Your device is not authorized yet to access this server.';
		SET ERR = `RAISERROR`(TEMP_ERR_MESSAGE);		
	END IF;
		
		
	-- Access Rights [Account]
	-- =========================================================================================
		
	
	
	
	-- COUNT RECORD
	-- =========================================================================================
	
	-- SELECT COLUMNS
	-- ####################################################
	SELECT
		COUNT(DISTINCT `category_section`.`CAT_SECTION_ID`)
	INTO
		TEMP_RECORD_COUNT

	FROM `category_section`
				
		-- Add Inner Joins (Per Foreign-key)
		INNER JOIN `category_department` ON
		`category_department`.`CAT_DEPARTMENT_ID` = `category_section`.`CAT_SECTION_CAT_DEPARTMENT_ID`
			
			
		
	-- CONDITIONS
	-- ####################################################
	WHERE
		(
			IS_NULL_CAT_SECTION_ID = 1 OR
			`category_section`.`CAT_SECTION_ID` = PARAM_CAT_SECTION_ID			
		) AND
		(
			IS_NULL_CAT_SECTION_CAT_DEPARTMENT_ID = 1 OR
			`category_section`.`CAT_SECTION_CAT_DEPARTMENT_ID` = PARAM_CAT_SECTION_CAT_DEPARTMENT_ID			
		) AND
		(
			IS_NULL_CAT_SECTION_DESCRIPTION = 1 OR
			`category_section`.`CAT_SECTION_DESCRIPTION` LIKE CONCAT_WS('%', '', PARAM_CAT_SECTION_DESCRIPTION, '')			
		) AND 		
		(
			IS_NULL_CAT_SECTION_STATUS = 1 OR
			`category_section`.`CAT_SECTION_STATUS` = PARAM_CAT_SECTION_STATUS			
		) 
;	

		
		
	-- SELECT RECORDS
	-- =========================================================================================
	
	-- FETCH COLUMNS
	-- ####################################################
	SELECT
		-- CATEGORY_SECTION DETAILS
		`category_section`.`CAT_SECTION_ID`, 
		`category_section`.`CAT_SECTION_CAT_DEPARTMENT_ID`, 
		`category_section`.`CAT_SECTION_DESCRIPTION`, 
		`category_section`.`CAT_SECTION_STATUS`
		
		-- Sum of Child [Numerics, non-primary/foreign keys, nor status, active/inactive, and system generated.]
		
		
		-- Inner join fields
		, 
		`category_department`.`CAT_DEPARTMENT_ID`,	
		`category_department`.`CAT_DEPARTMENT_DESCRIPTION` AS CAT_SECTION_CAT_DEPARTMENT_ID_DESCRIPTION,
		`category_department`.`CAT_DEPARTMENT_DESCRIPTION`,	
		`category_department`.`CAT_DEPARTMENT_STATUS`	
		
		-- Left join fields
		
		, TEMP_NOW AS SERVER_TIME,
		TEMP_RECORD_COUNT AS RECORD_COUNT

	FROM `category_section`
	
		-- Add Inner Joins (Per Foreign-key)
		INNER JOIN `category_department` ON
		`category_department`.`CAT_DEPARTMENT_ID` = `category_section`.`CAT_SECTION_CAT_DEPARTMENT_ID`
			
			
		
		-- Add Optional Left Joins (Per Optional Foreign-key)
		
	-- CONDITIONS
	-- ####################################################
	WHERE
		(
			IS_NULL_CAT_SECTION_ID = 1 OR
			`category_section`.`CAT_SECTION_ID` = PARAM_CAT_SECTION_ID			
		) AND
		(
			IS_NULL_CAT_SECTION_CAT_DEPARTMENT_ID = 1 OR
			`category_section`.`CAT_SECTION_CAT_DEPARTMENT_ID` = PARAM_CAT_SECTION_CAT_DEPARTMENT_ID			
		) AND
		(
			IS_NULL_CAT_SECTION_DESCRIPTION = 1 OR
			`category_section`.`CAT_SECTION_DESCRIPTION` LIKE CONCAT_WS('%', '', PARAM_CAT_SECTION_DESCRIPTION, '')			
		) AND 		
		(
			IS_NULL_CAT_SECTION_STATUS = 1 OR
			`category_section`.`CAT_SECTION_STATUS` = PARAM_CAT_SECTION_STATUS			
		) 

	-- ORDER BY
	-- ####################################################
	ORDER BY
		-- CATEGORY_SECTION DETAILS
		CASE WHEN PARAM_ORDER_FIELD = 'CAT_SECTION_ID' AND PARAM_ORDER_TYPE = 'ASC' THEN `category_section`.`CAT_SECTION_ID` END ASC, 
		CASE WHEN PARAM_ORDER_FIELD = 'CAT_SECTION_ID' AND PARAM_ORDER_TYPE = 'DESC' THEN `category_section`.`CAT_SECTION_ID` END DESC,	
		CASE WHEN PARAM_ORDER_FIELD = 'CAT_SECTION_CAT_DEPARTMENT_ID' AND PARAM_ORDER_TYPE = 'ASC' THEN `category_section`.`CAT_SECTION_CAT_DEPARTMENT_ID` END ASC, 
		CASE WHEN PARAM_ORDER_FIELD = 'CAT_SECTION_CAT_DEPARTMENT_ID' AND PARAM_ORDER_TYPE = 'DESC' THEN `category_section`.`CAT_SECTION_CAT_DEPARTMENT_ID` END DESC,	
		CASE WHEN PARAM_ORDER_FIELD = 'CAT_SECTION_DESCRIPTION' AND PARAM_ORDER_TYPE = 'ASC' THEN `category_section`.`CAT_SECTION_DESCRIPTION` END ASC, 
		CASE WHEN PARAM_ORDER_FIELD = 'CAT_SECTION_DESCRIPTION' AND PARAM_ORDER_TYPE = 'DESC' THEN `category_section`.`CAT_SECTION_DESCRIPTION` END DESC,	
		CASE WHEN PARAM_ORDER_FIELD = 'CAT_SECTION_STATUS' AND PARAM_ORDER_TYPE = 'ASC' THEN `category_section`.`CAT_SECTION_STATUS` END ASC, 
		CASE WHEN PARAM_ORDER_FIELD = 'CAT_SECTION_STATUS' AND PARAM_ORDER_TYPE = 'DESC' THEN `category_section`.`CAT_SECTION_STATUS` END DESC,	

		-- Inner joins
		CASE WHEN PARAM_ORDER_FIELD = 'CAT_DEPARTMENT_ID' AND PARAM_ORDER_TYPE = 'ASC' THEN `category_department`.`CAT_DEPARTMENT_ID` END ASC, 
		CASE WHEN PARAM_ORDER_FIELD = 'CAT_DEPARTMENT_ID' AND PARAM_ORDER_TYPE = 'DESC' THEN `category_department`.`CAT_DEPARTMENT_ID` END DESC,
		CASE WHEN PARAM_ORDER_FIELD = 'CAT_DEPARTMENT_DESCRIPTION' AND PARAM_ORDER_TYPE = 'ASC' THEN `category_department`.`CAT_DEPARTMENT_DESCRIPTION` END ASC, 
		CASE WHEN PARAM_ORDER_FIELD = 'CAT_DEPARTMENT_DESCRIPTION' AND PARAM_ORDER_TYPE = 'DESC' THEN `category_department`.`CAT_DEPARTMENT_DESCRIPTION` END DESC,
		CASE WHEN PARAM_ORDER_FIELD = 'CAT_DEPARTMENT_STATUS' AND PARAM_ORDER_TYPE = 'ASC' THEN `category_department`.`CAT_DEPARTMENT_STATUS` END ASC, 
		CASE WHEN PARAM_ORDER_FIELD = 'CAT_DEPARTMENT_STATUS' AND PARAM_ORDER_TYPE = 'DESC' THEN `category_department`.`CAT_DEPARTMENT_STATUS` END DESC,
		
		-- EXTRA
		CASE WHEN PARAM_ORDER_FIELD <> 'CAT_SECTION_DESCRIPTION' THEN `category_section`.`CAT_SECTION_DESCRIPTION` END ASC
		
	-- LIMIT & OFFSET
	-- ####################################################		
	LIMIT PARAM_SKIP, PARAM_LIMIT;
	
	
	
	-- EXIT PROCEDURE
	-- =========================================================================================
	LEAVE SP_GET;
			
END ;;
DELIMITER ;
/*!50003 SET sql_mode              = @saved_sql_mode */ ;
/*!50003 SET character_set_client  = @saved_cs_client */ ;
/*!50003 SET character_set_results = @saved_cs_results */ ;
/*!50003 SET collation_connection  = @saved_col_connection */ ;
/*!50003 DROP PROCEDURE IF EXISTS `CATEGORY_SECTION_SAVE` */;
/*!50003 SET @saved_cs_client      = @@character_set_client */ ;
/*!50003 SET @saved_cs_results     = @@character_set_results */ ;
/*!50003 SET @saved_col_connection = @@collation_connection */ ;
/*!50003 SET character_set_client  = latin1 */ ;
/*!50003 SET character_set_results = latin1 */ ;
/*!50003 SET collation_connection  = latin1_swedish_ci */ ;
/*!50003 SET @saved_sql_mode       = @@sql_mode */ ;
/*!50003 SET sql_mode              = '' */ ;
DELIMITER ;;
CREATE DEFINER=`root`@`localhost` PROCEDURE `CATEGORY_SECTION_SAVE`(
	IN `PARAM_CAT_SECTION_ID` BIGINT,
	IN `PARAM_CAT_SECTION_CAT_DEPARTMENT_ID` BIGINT,
	IN `PARAM_CAT_SECTION_DESCRIPTION` VARCHAR(400),
	IN `PARAM_CAT_SECTION_STATUS` TINYINT,

	IN `PARAM_REQUESTER_USERNAME` VARCHAR(500),
	IN `PARAM_REQUESTER_PASSWORD` VARCHAR(500),
	IN `PARAM_REQUESTER_PROXY_ID` BIGINT,
	IN `PARAM_REQUESTER_PROXY_PASSWORD` VARCHAR(1000),
	IN `PARAM_REQUESTER_DEVICE_PUBLIC_KEY` VARCHAR(1000),
	IN `PARAM_REQUESTER_DEVICE_PRIVATE_KEY` VARCHAR(1000),
	
	IN `PARAM_REQUESTER_IP` VARCHAR(1000),
	IN `PARAM_UNIQUE_SESSION_ID` VARCHAR(1000),
	IN `PARAM_SUPPRESS_RETURN` BIT,
	
	IN `PARAM_SYNC_SERVER_DESCRIPTION` VARCHAR(500), 
	IN `PARAM_SYNC_SERVER_UNIQUE_KEY` VARCHAR(500)
)
SP_SAVE:
BEGIN


	-- 1) DECLARE LOCAL PARAMETERS
	-- _______________________________________________________________________
	
	-- Status
	-- ...........................................
	DECLARE STATUS_INACTIVE TINYINT DEFAULT 1;
	DECLARE STATUS_ACTIVE TINYINT DEFAULT 2;
	DECLARE STATUS_CLOSED TINYINT DEFAULT 3;
	DECLARE STATUS_COMPLETED TINYINT DEFAULT 4;

	-- Audit Handler
	-- ...........................................
	DECLARE TEMP_RECORD_EXISTS BIT DEFAULT 0;
	DECLARE TEMP_MODULE_KEYWORD VARCHAR(500) DEFAULT 'category_section';
	DECLARE TEMP_SP_OBJECTIVE VARCHAR(500) DEFAULT 'add/edit Section record';
	DECLARE TEMP_ERR_MESSAGE VARCHAR(500) DEFAULT '';
	DECLARE ERR BIGINT DEFAULT 0;
	DECLARE TEMP_RECORD_CHANGES VARCHAR(16000) DEFAULT '';
	DECLARE TEMP_RECORD_BINDED BIT DEFAULT 0;

	-- Authentication
	-- ...........................................
	DECLARE TEMP_ACCESS_RIGHTS_DENIED BIT DEFAULT 0;
	DECLARE TEMP_ACCESS_RIGHTS_HAS_OVERRIDE BIT DEFAULT 0;
	DECLARE TEMP_SYNC_SERVER_ID BIGINT DEFAULT 0;
	DECLARE TEMP_SYNC_IS_SERVER_REQUEST BIT DEFAULT 0;
	DECLARE TEMP_AUTHENTICATED_ACCOUNT_ID BIGINT DEFAULT `ACCOUNT_MEMBER@ACC_ACCOUNT_ID_FROM_LOGIN`(PARAM_REQUESTER_USERNAME, PARAM_REQUESTER_PASSWORD);
	DECLARE TEMP_AUTHENTICATED_ACCOUNT_LEVEL BIGINT DEFAULT 0;
	DECLARE TEMP_AUTHENTICATED_ACCOUNT_GROUP BIGINT DEFAULT 0;
	
	-- Local Parameters
	-- ...........................................
	DECLARE TEMP_NOW DATETIME(6) DEFAULT `SYSTEM_VAR@NOW`('', 1);
	DECLARE TEMP_RECORD_COUNT BIGINT DEFAULT 0;

	-- AutoGen Parameters
	-- ...........................................
	
	-- Local value holder
	-- ...........................................
	DECLARE TEMP_CAT_SECTION_CAT_DEPARTMENT_ID BIGINT DEFAULT 0; 
	DECLARE TEMP_CAT_SECTION_DESCRIPTION VARCHAR(400) DEFAULT ''; 
	DECLARE TEMP_CAT_SECTION_STATUS TINYINT DEFAULT 0; 
	
	DECLARE REDUND_CAT_SECTION_ID BIGINT DEFAULT 0; 


	-- 2) Try Catch / Throw
	-- _______________________________________________________________________
	DECLARE EXIT HANDLER FOR SQLEXCEPTION
	BEGIN
		RESIGNAL;
	END;



	-- 3) Prepare SYNC
	-- _______________________________________________________________________

	-- IS RECORD EXISTS		
	-- ####################################################	
	SET TEMP_RECORD_EXISTS = `CATEGORY_SECTION@CAT_SECTION_ID_EXISTS`(PARAM_CAT_SECTION_ID, 0);

		
		
	-- 4) PREPARE AUTOGEN DATA (IF EXISTS)
	-- _______________________________________________________________________
	IF TEMP_SYNC_IS_SERVER_REQUEST = 0 THEN
		-- Just to keep at least one line within condition
		SET TEMP_SYNC_IS_SERVER_REQUEST = 0;
		
		-- Actual Functionalities here
		-- USE DEFAULT VALUE (String)
	END IF;



	-- 5) IF ALREADY EXIST, FILL MISSING DATA
	-- _______________________________________________________________________
	IF TEMP_RECORD_EXISTS = 1 THEN
		SELECT
			`category_section`.`CAT_SECTION_CAT_DEPARTMENT_ID`, 	
			`category_section`.`CAT_SECTION_DESCRIPTION`, 	
			`category_section`.`CAT_SECTION_STATUS`	
		INTO
			TEMP_CAT_SECTION_CAT_DEPARTMENT_ID, 	
			TEMP_CAT_SECTION_DESCRIPTION, 	
			TEMP_CAT_SECTION_STATUS	

		FROM `category_section`
		WHERE
			`category_section`.`CAT_SECTION_ID` = PARAM_CAT_SECTION_ID
		LIMIT 1;

		-- Replace NULLs with the existing data.
		SET PARAM_CAT_SECTION_CAT_DEPARTMENT_ID = `SYSTEM_VAR@REPLACE_NULL@BIGINT`(PARAM_CAT_SECTION_CAT_DEPARTMENT_ID, TEMP_CAT_SECTION_CAT_DEPARTMENT_ID, 1, 1);
		SET PARAM_CAT_SECTION_DESCRIPTION = `SYSTEM_VAR@REPLACE_NULL@NVARCHAR`(PARAM_CAT_SECTION_DESCRIPTION, TEMP_CAT_SECTION_DESCRIPTION, 1);
		SET PARAM_CAT_SECTION_STATUS = `SYSTEM_VAR@REPLACE_NULL@TINYINT`(PARAM_CAT_SECTION_STATUS, TEMP_CAT_SECTION_STATUS, 1, 1);
		
		-- AUTO GEN (NON-UPDATABLES)		
		
		-- AUTO GEN (UPDATABLE WITH STATUS CHANGE)

		-- AUTO GEN (UPDATABLE WITH STATUS [ACTIVE/INACTIVE] CHANGE)
		
		-- NON-UPDATABLE
		
		-- NON-UPDATABLE BUT NULL
		
	ELSE
		SET PARAM_CAT_SECTION_CAT_DEPARTMENT_ID = `SYSTEM_VAR@REPLACE_NULL@BIGINT`(PARAM_CAT_SECTION_CAT_DEPARTMENT_ID, 0, 1, 1);
		SET PARAM_CAT_SECTION_DESCRIPTION = `SYSTEM_VAR@REPLACE_NULL@NVARCHAR`(PARAM_CAT_SECTION_DESCRIPTION, '', 1);
		SET PARAM_CAT_SECTION_STATUS = `SYSTEM_VAR@REPLACE_NULL@TINYINT`(PARAM_CAT_SECTION_STATUS, 0, 1, 1);
		
	END IF;

	

	-- 6) PREPARE AUDIT TRAIL
	-- _______________________________________________________________________
	IF TEMP_CAT_SECTION_CAT_DEPARTMENT_ID <> PARAM_CAT_SECTION_CAT_DEPARTMENT_ID THEN
		SET TEMP_RECORD_CHANGES = 
		`SYSTEM_VAR@CONCAT_ADD`(' | ', TEMP_RECORD_CHANGES, CONCAT_WS(' ', 'Department: "', TEMP_CAT_SECTION_CAT_DEPARTMENT_ID, '" > "', PARAM_CAT_SECTION_CAT_DEPARTMENT_ID, '"'));
	END IF;	
	IF BINARY TEMP_CAT_SECTION_DESCRIPTION <> PARAM_CAT_SECTION_DESCRIPTION THEN
		SET TEMP_RECORD_CHANGES = 
		`SYSTEM_VAR@CONCAT_ADD`(' | ', TEMP_RECORD_CHANGES, CONCAT_WS(' ', 'Description: "', TEMP_CAT_SECTION_DESCRIPTION, '" > "', PARAM_CAT_SECTION_DESCRIPTION, '"'));
	END IF;
	IF TEMP_CAT_SECTION_STATUS <> PARAM_CAT_SECTION_STATUS THEN
		SET TEMP_RECORD_CHANGES = 
		`SYSTEM_VAR@CONCAT_ADD`(' | ', TEMP_RECORD_CHANGES, CONCAT_WS(' ', 'Status: "', TEMP_CAT_SECTION_STATUS, '" > "', PARAM_CAT_SECTION_STATUS, '"'));
	END IF;	
		
	-- No Changes in data, reject request
	-- ####################################################
	IF CHARACTER_LENGTH(TEMP_RECORD_CHANGES) = 0 THEN
		IF PARAM_SUPPRESS_RETURN = 0 THEN
			SELECT PARAM_CAT_SECTION_ID AS INSERTED_ID;
		END IF;
		LEAVE SP_SAVE;
	END IF;



	-- 7) VALIDATE
	-- _______________________________________________________________________

	-- Access Rights [Device]
	-- ####################################################
	IF `ACCOUNT_DEVICE@HAS_PERMISSION`(PARAM_REQUESTER_DEVICE_PUBLIC_KEY, PARAM_REQUESTER_DEVICE_PRIVATE_KEY) = 0 THEN
		SET TEMP_ERR_MESSAGE = 'Your device is not authorized yet to access this server.';
		SET ERR = `RAISERROR`(TEMP_ERR_MESSAGE);		
	END IF;
		
		
	-- Access Rights [Account]
	-- ####################################################
	
	IF 
		-- [ADD] Access Rights
		(
			TEMP_RECORD_EXISTS = 0 AND
			`ACCOUNT_ACCESS_RIGHTS@HAS_PERMISSION`(PARAM_REQUESTER_USERNAME, PARAM_REQUESTER_PASSWORD, 0, TEMP_MODULE_KEYWORD, 2) = 0 AND
			`ACCOUNT_ACCESS_RIGHTS@PROXY_PERMISSION`(PARAM_REQUESTER_PROXY_ID, PARAM_REQUESTER_PROXY_PASSWORD, 0, TEMP_MODULE_KEYWORD, 2) = 0
		) OR
		
		-- [EDIT] Access Rights
		(
			TEMP_RECORD_EXISTS = 1 AND
			`ACCOUNT_ACCESS_RIGHTS@HAS_PERMISSION`(PARAM_REQUESTER_USERNAME, PARAM_REQUESTER_PASSWORD, 0, TEMP_MODULE_KEYWORD, 3) = 0 AND
			`ACCOUNT_ACCESS_RIGHTS@PROXY_PERMISSION`(PARAM_REQUESTER_PROXY_ID, PARAM_REQUESTER_PROXY_PASSWORD, 0, TEMP_MODULE_KEYWORD, 3) = 0
		)
	THEN
		SET TEMP_ACCESS_RIGHTS_DENIED = 1;
		CALL `ACCOUNT_ACCESS_RIGHTS_DENY`
		(
			0, TEMP_MODULE_KEYWORD, PARAM_CAT_SECTION_ID, 0, TEMP_SP_OBJECTIVE, TEMP_RECORD_CHANGES, 
			PARAM_REQUESTER_USERNAME, PARAM_REQUESTER_PASSWORD, 
			PARAM_REQUESTER_PROXY_ID, PARAM_REQUESTER_PROXY_PASSWORD,
			PARAM_REQUESTER_DEVICE_PUBLIC_KEY, PARAM_REQUESTER_DEVICE_PRIVATE_KEY,
			PARAM_REQUESTER_IP, PARAM_UNIQUE_SESSION_ID,
			TEMP_SYNC_SERVER_ID, PARAM_SUPPRESS_RETURN
		);
	END IF;
	SET TEMP_ACCESS_RIGHTS_HAS_OVERRIDE = `ACCOUNT_ACCESS_RIGHTS@HAS_PERMISSION`(PARAM_REQUESTER_USERNAME, PARAM_REQUESTER_PASSWORD, 0, TEMP_MODULE_KEYWORD, 4);
	

	-- Validation
	-- ####################################################
	IF TEMP_SYNC_IS_SERVER_REQUEST = 0 THEN
	

		-- FOREIGN KEY EXISTS
		-- ...........................................
		IF `CATEGORY_DEPARTMENT@CAT_DEPARTMENT_ID_EXISTS`(PARAM_CAT_SECTION_CAT_DEPARTMENT_ID, 0) =  0 THEN
			SET TEMP_ERR_MESSAGE = CONCAT_WS(' ', 'Given Department does not exists or is inactive. ID: ', PARAM_CAT_SECTION_CAT_DEPARTMENT_ID);
			SET ERR = `RAISERROR`(TEMP_ERR_MESSAGE);
		END IF;
		
		-- FOREIGN (OPTIONAL)KEY EXISTS [Validates if not null]
		-- ...........................................
		
		-- IS_ALLOW_NULL = FALSE
		-- ...........................................
				
		-- IS_ALLOW_ZERO = FALSE
		-- ...........................................
		IF PARAM_CAT_SECTION_STATUS = 0 THEN
			CALL `VALIDATION_MISSING_FIELD`('`CAT_SECTION_STATUS`', '`NULL`');
		END IF;		
		
		-- IS_ALLOW_NEGATIVE = FALSE
		-- ...........................................
		IF PARAM_CAT_SECTION_STATUS < 0 THEN
			CALL `VALIDATION_NEGATIVE`('`CAT_SECTION_STATUS`', PARAM_CAT_SECTION_STATUS);
		END IF;		
		
		-- IS_ALLOW_EMPTY_STRING = FALSE
		-- ...........................................
		IF `SYSTEM_VAR@IS_NULL@NVARCHAR`(PARAM_CAT_SECTION_DESCRIPTION, 1) = 1 THEN
			CALL `VALIDATION_MISSING_FIELD`('`CAT_SECTION_DESCRIPTION`', '`NULL`');
		END IF;
		
		-- IS_STATUS
		-- ...........................................
		IF `SYSTEM_STATUS@SYS_STATUS_ID_EXISTS`(PARAM_CAT_SECTION_STATUS, 0) = 0 THEN
			SET TEMP_ERR_MESSAGE = CONCAT_WS(' ', 'Given STATUS[Status] does not exists or is inactive. ID: ', PARAM_CAT_SECTION_STATUS);
			SET ERR = `RAISERROR`(TEMP_ERR_MESSAGE);
		END IF;
		
		-- IS STATUS Active / Inactive
		-- ...........................................
		
		-- Minimum / Maximum Value
		-- ...........................................
		
		-- IS_UNIQUE = TRUE
		-- ...........................................
		
		-- RECORD IDENTIFIER
		-- ...........................................
		IF
		(
			SELECT COUNT(`category_section`.`CAT_SECTION_ID`)
			FROM `category_section`
			WHERE
				`category_section`.`CAT_SECTION_CAT_DEPARTMENT_ID` = PARAM_CAT_SECTION_CAT_DEPARTMENT_ID AND
				`category_section`.`CAT_SECTION_DESCRIPTION` = PARAM_CAT_SECTION_DESCRIPTION AND
				`category_section`.`CAT_SECTION_ID` <> PARAM_CAT_SECTION_ID
		) >= 1
		THEN
		
			SELECT `category_section`.`CAT_SECTION_ID`
			INTO REDUND_CAT_SECTION_ID
			FROM `category_section`
			WHERE
				`category_section`.`CAT_SECTION_CAT_DEPARTMENT_ID` = PARAM_CAT_SECTION_CAT_DEPARTMENT_ID AND
				`category_section`.`CAT_SECTION_DESCRIPTION` = PARAM_CAT_SECTION_DESCRIPTION AND
				`category_section`.`CAT_SECTION_ID` <> PARAM_CAT_SECTION_ID
			LIMIT 1;
				
			SET TEMP_ERR_MESSAGE = CONCAT_WS(' ', PARAM_CAT_SECTION_DESCRIPTION, '[', REDUND_CAT_SECTION_ID, ']');
			CALL `VALIDATION_REDUNDANT_ENTRY`(TEMP_ERR_MESSAGE);
		END IF;
		
		
		-- ON_UPDATE VALIDATION 
		-- ...........................................
		IF TEMP_RECORD_EXISTS = 1 THEN	
		
			-- Just to keep at least one line within condition
			SET TEMP_RECORD_EXISTS = 1;
			
		END IF;
		
	END IF;



	-- 8) INSERT / UPDATE
	-- _______________________________________________________________________

	-- INSERT NEW DATA
	-- ####################################################
	IF TEMP_RECORD_EXISTS = 0 THEN

		INSERT INTO
		`category_section`
		(
			`category_section`.`CAT_SECTION_CAT_DEPARTMENT_ID`, 
			`category_section`.`CAT_SECTION_DESCRIPTION`, 
			`category_section`.`CAT_SECTION_STATUS`
		)
		VALUES
		(
			PARAM_CAT_SECTION_CAT_DEPARTMENT_ID, 
			PARAM_CAT_SECTION_DESCRIPTION, 
			PARAM_CAT_SECTION_STATUS
		);	
		
		-- Update Audit trail with new ID	
		SET PARAM_CAT_SECTION_ID = LAST_INSERT_ID();



	-- UPDATING EXISTING RECORD
	-- ####################################################
	ELSE
		UPDATE `category_section`
		SET
			`category_section`.`CAT_SECTION_CAT_DEPARTMENT_ID` = PARAM_CAT_SECTION_CAT_DEPARTMENT_ID, 
			`category_section`.`CAT_SECTION_DESCRIPTION` = PARAM_CAT_SECTION_DESCRIPTION, 
			`category_section`.`CAT_SECTION_STATUS` = PARAM_CAT_SECTION_STATUS
		WHERE
			`category_section`.`CAT_SECTION_ID` = PARAM_CAT_SECTION_ID;

	END IF;

	
	-- 9) AUDIT TRAIL
	-- _______________________________________________________________________
	CALL `ACCOUNT_AUDIT_TRAIL_SAVE`
	(
		0, TEMP_MODULE_KEYWORD, PARAM_CAT_SECTION_ID, 0, 'SAVE', TEMP_SP_OBJECTIVE, TEMP_RECORD_CHANGES, 
		PARAM_REQUESTER_USERNAME, PARAM_REQUESTER_PASSWORD, 
		PARAM_REQUESTER_PROXY_ID, PARAM_REQUESTER_PROXY_PASSWORD,
		PARAM_REQUESTER_DEVICE_PUBLIC_KEY, PARAM_REQUESTER_DEVICE_PRIVATE_KEY,
		PARAM_REQUESTER_IP, PARAM_UNIQUE_SESSION_ID,
		TEMP_SYNC_SERVER_ID, PARAM_SUPPRESS_RETURN
	);
	

	-- 10) RETURN RESULT
	-- _______________________________________________________________________
	IF PARAM_SUPPRESS_RETURN = 0 THEN
		SELECT 
			PARAM_CAT_SECTION_ID AS INSERTED_ID,
			TEMP_NOW AS SERVER_TIME;
	END IF;
	LEAVE SP_SAVE;


END ;;
DELIMITER ;
/*!50003 SET sql_mode              = @saved_sql_mode */ ;
/*!50003 SET character_set_client  = @saved_cs_client */ ;
/*!50003 SET character_set_results = @saved_cs_results */ ;
/*!50003 SET collation_connection  = @saved_col_connection */ ;
/*!50003 DROP PROCEDURE IF EXISTS `MOBILE_CONTACT_DELETE` */;
/*!50003 SET @saved_cs_client      = @@character_set_client */ ;
/*!50003 SET @saved_cs_results     = @@character_set_results */ ;
/*!50003 SET @saved_col_connection = @@collation_connection */ ;
/*!50003 SET character_set_client  = latin1 */ ;
/*!50003 SET character_set_results = latin1 */ ;
/*!50003 SET collation_connection  = latin1_swedish_ci */ ;
/*!50003 SET @saved_sql_mode       = @@sql_mode */ ;
/*!50003 SET sql_mode              = '' */ ;
DELIMITER ;;
CREATE DEFINER=`root`@`localhost` PROCEDURE `MOBILE_CONTACT_DELETE`(
	IN `PARAM_MOB_CONTACT_ID` BIGINT,

	IN `PARAM_REQUESTER_USERNAME` VARCHAR(500),
	IN `PARAM_REQUESTER_PASSWORD` VARCHAR(500),
	IN `PARAM_REQUESTER_IP` VARCHAR(1000),
	IN `PARAM_UNIQUE_SESSION_ID` VARCHAR(1000),
	IN `PARAM_SUPPRESS_RETURN` BIT,
	
	IN `PARAM_SYNC_SERVER_DESCRIPTION` VARCHAR(500), 
	IN `PARAM_SYNC_SERVER_UNIQUE_KEY` VARCHAR(500)
)
SP_DELETE:
BEGIN

	-- 1) DECLARE LOCAL PARAMETERS
	-- _______________________________________________________________________
	
	-- Status
	-- ...........................................
	DECLARE STATUS_INACTIVE TINYINT DEFAULT 1;
	DECLARE STATUS_ACTIVE TINYINT DEFAULT 2;
	DECLARE STATUS_CLOSED TINYINT DEFAULT 3;
	DECLARE STATUS_COMPLETED TINYINT DEFAULT 4;
	
	-- Audit Handler
	-- ...........................................
	DECLARE TEMP_RECORD_EXISTS BIT DEFAULT 0;
	DECLARE TEMP_MODULE_KEYWORD VARCHAR(500) DEFAULT 'mobile_contact';
	DECLARE TEMP_SP_OBJECTIVE VARCHAR(500) DEFAULT 'delete Contact Phonebook record';
	DECLARE TEMP_ERR_MESSAGE VARCHAR(500) DEFAULT '';
	DECLARE ERR BIGINT DEFAULT 0;
	DECLARE TEMP_RECORD_CHANGES VARCHAR(16000) DEFAULT '';
	DECLARE TEMP_RECORD_BINDED BIT DEFAULT 0;
	
	DECLARE TEMP_RECORD_BINDED_ID BIGINT DEFAULT 0;
	DECLARE TEMP_RECORD_BINDED_SERVER_ID BIGINT DEFAULT 0;
	
	-- Authentication
	-- ...........................................
	DECLARE TEMP_ACCESS_RIGHTS_DENIED BIT DEFAULT 0;
	DECLARE TEMP_SYNC_SERVER_ID BIGINT DEFAULT 0;
	DECLARE TEMP_SYNC_IS_SERVER_REQUEST BIT DEFAULT 0;
	DECLARE TEMP_AUTHENTICATED_ACCOUNT_ID BIGINT DEFAULT `ACCOUNT_MEMBER@ACC_ACCOUNT_ID_FROM_LOGIN`(PARAM_REQUESTER_USERNAME, PARAM_REQUESTER_PASSWORD);
	DECLARE TEMP_AUTHENTICATED_ACCOUNT_LEVEL BIGINT DEFAULT 0;
	DECLARE TEMP_AUTHENTICATED_ACCOUNT_GROUP BIGINT DEFAULT 0;

	-- Local value holder
	-- ...........................................
		DECLARE TEMP_MOB_CONTACT_ACC_GROUP_ID BIGINT DEFAULT 0; 
		DECLARE TEMP_MOB_CONTACT_MOBILE VARCHAR(50) DEFAULT ''; 
		DECLARE TEMP_MOB_CONTACT_DESCRIPTION VARCHAR(500) DEFAULT ''; 
		DECLARE TEMP_MOB_CONTACT_STATUS TINYINT DEFAULT 0; 

	
	
	-- 2) Try Catch / Throw
	-- _______________________________________________________________________
	DECLARE EXIT HANDLER FOR SQLEXCEPTION
	BEGIN
		RESIGNAL;
	END;

	
	-- 3) Prepare SYNC
	-- _______________________________________________________________________
	
	-- IS RECORD EXISTS		
	-- ####################################################		
	SET TEMP_RECORD_EXISTS = `MOBILE_CONTACT@MOB_CONTACT_ID_EXISTS`(PARAM_MOB_CONTACT_ID, 0);


	-- 4) IF ALREADY EXIST, FILL MISSING DATA
	-- _______________________________________________________________________
	IF TEMP_RECORD_EXISTS = 1 THEN
		SELECT
				`mobile_contact`.`MOB_CONTACT_ACC_GROUP_ID`, 	
				`mobile_contact`.`MOB_CONTACT_MOBILE`, 	
				`mobile_contact`.`MOB_CONTACT_DESCRIPTION`, 	
				`mobile_contact`.`MOB_CONTACT_STATUS`	
		INTO
				TEMP_MOB_CONTACT_ACC_GROUP_ID, 	
				TEMP_MOB_CONTACT_MOBILE, 	
				TEMP_MOB_CONTACT_DESCRIPTION, 	
				TEMP_MOB_CONTACT_STATUS	

		FROM `mobile_contact`
		WHERE
			`mobile_contact`.`MOB_CONTACT_ID` = PARAM_MOB_CONTACT_ID
		LIMIT 1;

	ELSE 
		IF TEMP_SYNC_IS_SERVER_REQUEST = 0 THEN
			SET TEMP_ERR_MESSAGE = CONCAT_WS(' ', 'Given Contact Phonebook does not exists or is inactive. ID:', PARAM_MOB_CONTACT_ID);
			SET ERR = `RAISERROR`(TEMP_ERR_MESSAGE);		
		END IF;
		LEAVE SP_DELETE;
		
	END IF;



	-- 5) PREPARE AUDIT TRAIL
	-- _______________________________________________________________________
	
		SET TEMP_RECORD_CHANGES = 
		`SYSTEM_VAR@CONCAT_ADD`(' | ', TEMP_RECORD_CHANGES, CONCAT_WS(' ', 'User Group: "', TEMP_MOB_CONTACT_ACC_GROUP_ID, '" > " DELETED "'));
		SET TEMP_RECORD_CHANGES = 
		`SYSTEM_VAR@CONCAT_ADD`(' | ', TEMP_RECORD_CHANGES, CONCAT_WS(' ', 'Mobile Number: "', TEMP_MOB_CONTACT_MOBILE, '" > " DELETED "'));
		SET TEMP_RECORD_CHANGES = 
		`SYSTEM_VAR@CONCAT_ADD`(' | ', TEMP_RECORD_CHANGES, CONCAT_WS(' ', 'Description: "', TEMP_MOB_CONTACT_DESCRIPTION, '" > " DELETED "'));
		SET TEMP_RECORD_CHANGES = 
		`SYSTEM_VAR@CONCAT_ADD`(' | ', TEMP_RECORD_CHANGES, CONCAT_WS(' ', 'Status: "', TEMP_MOB_CONTACT_STATUS, '" > " DELETED "'));


	-- 6) VALIDATE
	-- _______________________________________________________________________

	-- Access Rights
	-- ####################################################	
	-- Check if accessing a record outside own group.
	SET TEMP_AUTHENTICATED_ACCOUNT_GROUP = `ACCOUNT_MEMBER@ACC_ACCOUNT_GROUP_FROM_LOGIN`(PARAM_REQUESTER_USERNAME, PARAM_REQUESTER_PASSWORD);
	IF TEMP_AUTHENTICATED_ACCOUNT_GROUP <> TEMP_MOB_CONTACT_ACC_GROUP_ID THEN
		IF `ACCOUNT_ACCESS_RIGHTS@HAS_PERMISSION`(PARAM_REQUESTER_USERNAME, PARAM_REQUESTER_PASSWORD, 0, TEMP_MODULE_KEYWORD, 4) = 0 THEN
			SET TEMP_ACCESS_RIGHTS_DENIED = 1;
			CALL `ACCOUNT_ACCESS_RIGHTS_DENY`
			(
				0, TEMP_MODULE_KEYWORD, 0, 0, TEMP_SP_OBJECTIVE, TEMP_RECORD_CHANGES, 
				PARAM_REQUESTER_USERNAME, PARAM_REQUESTER_PASSWORD, PARAM_REQUESTER_IP, PARAM_UNIQUE_SESSION_ID,
				0, PARAM_SUPPRESS_RETURN
			);
		END IF;					
	END IF;
	
	IF 
		-- [DELETE] Access Rights
		`ACCOUNT_ACCESS_RIGHTS@HAS_PERMISSION`(PARAM_REQUESTER_USERNAME, PARAM_REQUESTER_PASSWORD, 0, TEMP_MODULE_KEYWORD, 4) = 0 
	THEN
		SET TEMP_ACCESS_RIGHTS_DENIED = 1;
		CALL `ACCOUNT_ACCESS_RIGHTS_DENY`
		(
			0, TEMP_MODULE_KEYWORD, PARAM_MOB_CONTACT_ID, 0, TEMP_SP_OBJECTIVE, TEMP_RECORD_CHANGES, 
			PARAM_REQUESTER_USERNAME, PARAM_REQUESTER_PASSWORD, PARAM_REQUESTER_IP, PARAM_UNIQUE_SESSION_ID,
			TEMP_SYNC_SERVER_ID, PARAM_SUPPRESS_RETURN
		);
	END IF;

	
	-- If already used, cannot remove record
	-- ####################################################

	-- Leave Re-upload request
	-- ####################################################
	IF TEMP_RECORD_BINDED = 1 THEN
		IF TEMP_SYNC_IS_SERVER_REQUEST = 1 THEN
			
			LEAVE SP_DELETE;
		END IF;

		CALL `VALIDATION_DELETE_LINKED_RECORD`(TEMP_MOB_CONTACT_DESCRIPTION, '', TEMP_ERR_MESSAGE); 
	END IF;


	-- 7) DELETE
	-- _______________________________________________________________________
	DELETE FROM `mobile_contact`
	WHERE `mobile_contact`.`MOB_CONTACT_ID` = PARAM_MOB_CONTACT_ID
	LIMIT 1;


	-- 8) AUDIT TRAIL
	-- _______________________________________________________________________
	CALL `ACCOUNT_AUDIT_TRAIL_SAVE`
	(
		0, TEMP_MODULE_KEYWORD, PARAM_MOB_CONTACT_ID, 0, 'DELETE', TEMP_SP_OBJECTIVE, TEMP_RECORD_CHANGES, 
		PARAM_REQUESTER_USERNAME, PARAM_REQUESTER_PASSWORD, PARAM_REQUESTER_IP, PARAM_UNIQUE_SESSION_ID,
		TEMP_SYNC_SERVER_ID, PARAM_SUPPRESS_RETURN
	);

END ;;
DELIMITER ;
/*!50003 SET sql_mode              = @saved_sql_mode */ ;
/*!50003 SET character_set_client  = @saved_cs_client */ ;
/*!50003 SET character_set_results = @saved_cs_results */ ;
/*!50003 SET collation_connection  = @saved_col_connection */ ;
/*!50003 DROP PROCEDURE IF EXISTS `MOBILE_CONTACT_GET` */;
/*!50003 SET @saved_cs_client      = @@character_set_client */ ;
/*!50003 SET @saved_cs_results     = @@character_set_results */ ;
/*!50003 SET @saved_col_connection = @@collation_connection */ ;
/*!50003 SET character_set_client  = latin1 */ ;
/*!50003 SET character_set_results = latin1 */ ;
/*!50003 SET collation_connection  = latin1_swedish_ci */ ;
/*!50003 SET @saved_sql_mode       = @@sql_mode */ ;
/*!50003 SET sql_mode              = '' */ ;
DELIMITER ;;
CREATE DEFINER=`root`@`localhost` PROCEDURE `MOBILE_CONTACT_GET`(
	IN `PARAM_MOB_CONTACT_ID` BIGINT,	
	IN `PARAM_MOB_CONTACT_ACC_GROUP_ID` BIGINT,	
	IN `PARAM_MOB_CONTACT_MOBILE` VARCHAR(50),	
	IN `PARAM_MOB_CONTACT_DESCRIPTION` VARCHAR(500),	
	IN `PARAM_MOB_CONTACT_STATUS` TINYINT,	
		
	IN `PARAM_ORDER_FIELD` VARCHAR(500),
	IN `PARAM_ORDER_TYPE` VARCHAR(500),
	IN `PARAM_SKIP` BIGINT,
	IN `PARAM_LIMIT` BIGINT,

	IN `PARAM_REQUESTER_USERNAME` VARCHAR(500),
	IN `PARAM_REQUESTER_PASSWORD` VARCHAR(500),
	IN `PARAM_REQUESTER_IP` VARCHAR(1000),
	IN `PARAM_UNIQUE_SESSION_ID` VARCHAR(1000),
	IN `PARAM_SUPPRESS_RETURN` BIT
)
SP_GET:
BEGIN

	-- Status
	-- =========================================================================================
	DECLARE STATUS_INACTIVE TINYINT DEFAULT 1;
	DECLARE STATUS_ACTIVE TINYINT DEFAULT 2;
	DECLARE STATUS_CLOSED TINYINT DEFAULT 3;
	DECLARE STATUS_COMPLETED TINYINT DEFAULT 4;
	
	-- Audit Handler
	-- =========================================================================================
	DECLARE TEMP_RECORD_EXISTS BIT DEFAULT 0;
	DECLARE TEMP_MODULE_KEYWORD VARCHAR(500) DEFAULT 'mobile_contact';
	DECLARE TEMP_SP_OBJECTIVE VARCHAR(500) DEFAULT 'Retrieve Contact Phonebook record';
	DECLARE TEMP_ERR_MESSAGE VARCHAR(500) DEFAULT '';
	DECLARE ERR BIGINT DEFAULT 0;
	DECLARE TEMP_RECORD_CHANGES VARCHAR(16000) DEFAULT '';
	DECLARE TEMP_RECORD_BINDED BIT DEFAULT 0;
	
	DECLARE TEMP_RECORD_BINDED_ID BIGINT DEFAULT 0;
	DECLARE TEMP_RECORD_BINDED_SERVER_ID BIGINT DEFAULT 0;
	
	-- Authentication
	-- =========================================================================================
	DECLARE TEMP_ACCESS_RIGHTS_DENIED BIT DEFAULT 0;
	DECLARE TEMP_AUTHENTICATED_ACCOUNT_ID BIGINT DEFAULT `ACCOUNT_MEMBER@ACC_ACCOUNT_ID_FROM_LOGIN`(PARAM_REQUESTER_USERNAME, PARAM_REQUESTER_PASSWORD);
	DECLARE TEMP_AUTHENTICATED_ACCOUNT_LEVEL BIGINT DEFAULT 0;
	DECLARE TEMP_AUTHENTICATED_ACCOUNT_GROUP BIGINT DEFAULT 0;
	
	-- Local Parameters
	-- =========================================================================================
	DECLARE TEMP_NOW DATETIME(6) DEFAULT `SYSTEM_VAR@NOW`('', 1);
	DECLARE TEMP_RECORD_COUNT BIGINT DEFAULT 0;
	
	
	-- Check NULLs
	-- =========================================================================================
	DECLARE IS_NULL_MOB_CONTACT_ID BIT DEFAULT `SYSTEM_VAR@IS_NULL@BIGINT`(PARAM_MOB_CONTACT_ID, 1, 1);
	DECLARE IS_NULL_MOB_CONTACT_ACC_GROUP_ID BIT DEFAULT `SYSTEM_VAR@IS_NULL@BIGINT`(PARAM_MOB_CONTACT_ACC_GROUP_ID, 1, 1);
	DECLARE IS_NULL_MOB_CONTACT_MOBILE BIT DEFAULT `SYSTEM_VAR@IS_NULL@NVARCHAR`(PARAM_MOB_CONTACT_MOBILE, 1);
	DECLARE IS_NULL_MOB_CONTACT_DESCRIPTION BIT DEFAULT `SYSTEM_VAR@IS_NULL@NVARCHAR`(PARAM_MOB_CONTACT_DESCRIPTION, 1);
	DECLARE IS_NULL_MOB_CONTACT_STATUS BIT DEFAULT `SYSTEM_VAR@IS_NULL@TINYINT`(PARAM_MOB_CONTACT_STATUS, 1, 1);
	
	-- Error Handler
	-- =========================================================================================
	DECLARE EXIT HANDLER FOR SQLEXCEPTION
	BEGIN
		RESIGNAL;
	END;
	
	-- Ignore Time from DateTime (Set Time 00:00:00.000000 and 23:59:59.999999)
	-- =========================================================================================
		
	-- Access Rights
	-- =========================================================================================
	-- Check if accessing a record outside own group.
	SET TEMP_AUTHENTICATED_ACCOUNT_GROUP = `ACCOUNT_MEMBER@ACC_ACCOUNT_GROUP_FROM_LOGIN`(PARAM_REQUESTER_USERNAME, PARAM_REQUESTER_PASSWORD);
	IF TEMP_AUTHENTICATED_ACCOUNT_GROUP <> PARAM_MOB_CONTACT_ACC_GROUP_ID THEN
		IF `ACCOUNT_ACCESS_RIGHTS@HAS_PERMISSION`(PARAM_REQUESTER_USERNAME, PARAM_REQUESTER_PASSWORD, 0, TEMP_MODULE_KEYWORD, 4) = 0 THEN
			SET TEMP_ACCESS_RIGHTS_DENIED = 1;
			CALL `ACCOUNT_ACCESS_RIGHTS_DENY`
			(
				0, TEMP_MODULE_KEYWORD, 0, 0, TEMP_SP_OBJECTIVE, TEMP_RECORD_CHANGES, 
				PARAM_REQUESTER_USERNAME, PARAM_REQUESTER_PASSWORD, PARAM_REQUESTER_IP, PARAM_UNIQUE_SESSION_ID,
				0, PARAM_SUPPRESS_RETURN
			);
		END IF;					
	END IF;
		
	IF `ACCOUNT_ACCESS_RIGHTS@HAS_PERMISSION`(PARAM_REQUESTER_USERNAME, PARAM_REQUESTER_PASSWORD, 0, TEMP_MODULE_KEYWORD, 1) = 0 THEN
		SET TEMP_ACCESS_RIGHTS_DENIED = 1;
		CALL `ACCOUNT_ACCESS_RIGHTS_DENY`
		(
			0, TEMP_MODULE_KEYWORD, 0, 0, TEMP_SP_OBJECTIVE, TEMP_RECORD_CHANGES, 
			PARAM_REQUESTER_USERNAME, PARAM_REQUESTER_PASSWORD, PARAM_REQUESTER_IP, PARAM_UNIQUE_SESSION_ID,
			0, PARAM_SUPPRESS_RETURN
		);
	END IF;
	
	
	
	-- COUNT RECORD
	-- =========================================================================================
	
	-- SELECT COLUMNS
	-- ####################################################
	SELECT
		COUNT(DISTINCT `mobile_contact`.`MOB_CONTACT_ID`)
	INTO
		TEMP_RECORD_COUNT

	FROM `mobile_contact`
	
		-- Add Inner Joins (Per Foreign-key)
		INNER JOIN `account_group` ON
		`account_group`.`ACC_GROUP_ID` = `mobile_contact`.`MOB_CONTACT_ACC_GROUP_ID`
		
		-- Add Optional Left Joins (Per Optional Foreign-key)
		
	-- CONDITIONS
	-- ####################################################
	WHERE
		(
			IS_NULL_MOB_CONTACT_ID = 1 OR
			`mobile_contact`.`MOB_CONTACT_ID` = PARAM_MOB_CONTACT_ID			
		) AND
		(
			IS_NULL_MOB_CONTACT_ACC_GROUP_ID = 1 OR
			`mobile_contact`.`MOB_CONTACT_ACC_GROUP_ID` = PARAM_MOB_CONTACT_ACC_GROUP_ID			
		) AND
		(
			IS_NULL_MOB_CONTACT_MOBILE = 1 OR
			`mobile_contact`.`MOB_CONTACT_MOBILE` LIKE CONCAT_WS('%', '', PARAM_MOB_CONTACT_MOBILE, '')			
		) AND 		
		(
			IS_NULL_MOB_CONTACT_DESCRIPTION = 1 OR
			`mobile_contact`.`MOB_CONTACT_DESCRIPTION` LIKE CONCAT_WS('%', '', PARAM_MOB_CONTACT_DESCRIPTION, '')			
		) AND 		
		(
			IS_NULL_MOB_CONTACT_STATUS = 1 OR
			`mobile_contact`.`MOB_CONTACT_STATUS` = PARAM_MOB_CONTACT_STATUS			
		) 
;	

		
		
	-- SELECT RECORDS
	-- =========================================================================================
	
	-- FETCH COLUMNS
	-- ####################################################
	SELECT
		-- MOBILE_CONTACT DETAILS
		`mobile_contact`.`MOB_CONTACT_ID`, 
		`mobile_contact`.`MOB_CONTACT_ACC_GROUP_ID`, 
		`mobile_contact`.`MOB_CONTACT_MOBILE`, 
		`mobile_contact`.`MOB_CONTACT_DESCRIPTION`, 
		`mobile_contact`.`MOB_CONTACT_STATUS`
		
		-- Inner join fields
		, 
		`account_group`.`ACC_GROUP_ID`, 
		`account_group`.`ACC_GROUP_DESCRIPTION`, 
		`account_group`.`ACC_GROUP_STATUS`, 
		`account_group`.`ACC_GROUP_SYSTEM_GENERATED`
		
		-- Left join fields
		
		, TEMP_RECORD_COUNT AS RECORD_COUNT

	FROM `mobile_contact`
	
		-- Add Inner Joins (Per Foreign-key)
		INNER JOIN `account_group` ON
		`account_group`.`ACC_GROUP_ID` = `mobile_contact`.`MOB_CONTACT_ACC_GROUP_ID`
		
		-- Add Optional Left Joins (Per Optional Foreign-key)
		
	-- CONDITIONS
	-- ####################################################
	WHERE
		(
			IS_NULL_MOB_CONTACT_ID = 1 OR
			`mobile_contact`.`MOB_CONTACT_ID` = PARAM_MOB_CONTACT_ID			
		) AND
		(
			IS_NULL_MOB_CONTACT_ACC_GROUP_ID = 1 OR
			`mobile_contact`.`MOB_CONTACT_ACC_GROUP_ID` = PARAM_MOB_CONTACT_ACC_GROUP_ID			
		) AND
		(
			IS_NULL_MOB_CONTACT_MOBILE = 1 OR
			`mobile_contact`.`MOB_CONTACT_MOBILE` LIKE CONCAT_WS('%', '', PARAM_MOB_CONTACT_MOBILE, '')			
		) AND 		
		(
			IS_NULL_MOB_CONTACT_DESCRIPTION = 1 OR
			`mobile_contact`.`MOB_CONTACT_DESCRIPTION` LIKE CONCAT_WS('%', '', PARAM_MOB_CONTACT_DESCRIPTION, '')			
		) AND 		
		(
			IS_NULL_MOB_CONTACT_STATUS = 1 OR
			`mobile_contact`.`MOB_CONTACT_STATUS` = PARAM_MOB_CONTACT_STATUS			
		) 

	-- ORDER BY
	-- ####################################################
	ORDER BY
		-- MOBILE_CONTACT DETAILS
		CASE WHEN PARAM_ORDER_FIELD = 'MOB_CONTACT_ID' AND PARAM_ORDER_TYPE = 'ASC' THEN `mobile_contact`.`MOB_CONTACT_ID` END ASC, 
		CASE WHEN PARAM_ORDER_FIELD = 'MOB_CONTACT_ID' AND PARAM_ORDER_TYPE = 'DESC' THEN `mobile_contact`.`MOB_CONTACT_ID` END DESC,	
		CASE WHEN PARAM_ORDER_FIELD = 'MOB_CONTACT_ACC_GROUP_ID' AND PARAM_ORDER_TYPE = 'ASC' THEN `mobile_contact`.`MOB_CONTACT_ACC_GROUP_ID` END ASC, 
		CASE WHEN PARAM_ORDER_FIELD = 'MOB_CONTACT_ACC_GROUP_ID' AND PARAM_ORDER_TYPE = 'DESC' THEN `mobile_contact`.`MOB_CONTACT_ACC_GROUP_ID` END DESC,	
		CASE WHEN PARAM_ORDER_FIELD = 'MOB_CONTACT_MOBILE' AND PARAM_ORDER_TYPE = 'ASC' THEN `mobile_contact`.`MOB_CONTACT_MOBILE` END ASC, 
		CASE WHEN PARAM_ORDER_FIELD = 'MOB_CONTACT_MOBILE' AND PARAM_ORDER_TYPE = 'DESC' THEN `mobile_contact`.`MOB_CONTACT_MOBILE` END DESC,	
		CASE WHEN PARAM_ORDER_FIELD = 'MOB_CONTACT_DESCRIPTION' AND PARAM_ORDER_TYPE = 'ASC' THEN `mobile_contact`.`MOB_CONTACT_DESCRIPTION` END ASC, 
		CASE WHEN PARAM_ORDER_FIELD = 'MOB_CONTACT_DESCRIPTION' AND PARAM_ORDER_TYPE = 'DESC' THEN `mobile_contact`.`MOB_CONTACT_DESCRIPTION` END DESC,	
		CASE WHEN PARAM_ORDER_FIELD = 'MOB_CONTACT_STATUS' AND PARAM_ORDER_TYPE = 'ASC' THEN `mobile_contact`.`MOB_CONTACT_STATUS` END ASC, 
		CASE WHEN PARAM_ORDER_FIELD = 'MOB_CONTACT_STATUS' AND PARAM_ORDER_TYPE = 'DESC' THEN `mobile_contact`.`MOB_CONTACT_STATUS` END DESC,	

		-- Inner joins
		CASE WHEN PARAM_ORDER_FIELD = 'ACC_GROUP_ID' AND PARAM_ORDER_TYPE = 'ASC' THEN `account_group`.`ACC_GROUP_ID` END ASC, 
		CASE WHEN PARAM_ORDER_FIELD = 'ACC_GROUP_ID' AND PARAM_ORDER_TYPE = 'DESC' THEN `account_group`.`ACC_GROUP_ID` END DESC,	
		CASE WHEN PARAM_ORDER_FIELD = 'ACC_GROUP_DESCRIPTION' AND PARAM_ORDER_TYPE = 'ASC' THEN `account_group`.`ACC_GROUP_DESCRIPTION` END ASC, 
		CASE WHEN PARAM_ORDER_FIELD = 'ACC_GROUP_DESCRIPTION' AND PARAM_ORDER_TYPE = 'DESC' THEN `account_group`.`ACC_GROUP_DESCRIPTION` END DESC,	
		CASE WHEN PARAM_ORDER_FIELD = 'ACC_GROUP_STATUS' AND PARAM_ORDER_TYPE = 'ASC' THEN `account_group`.`ACC_GROUP_STATUS` END ASC, 
		CASE WHEN PARAM_ORDER_FIELD = 'ACC_GROUP_STATUS' AND PARAM_ORDER_TYPE = 'DESC' THEN `account_group`.`ACC_GROUP_STATUS` END DESC,	
		CASE WHEN PARAM_ORDER_FIELD = 'ACC_GROUP_SYSTEM_GENERATED' AND PARAM_ORDER_TYPE = 'ASC' THEN `account_group`.`ACC_GROUP_SYSTEM_GENERATED` END ASC, 
		CASE WHEN PARAM_ORDER_FIELD = 'ACC_GROUP_SYSTEM_GENERATED' AND PARAM_ORDER_TYPE = 'DESC' THEN `account_group`.`ACC_GROUP_SYSTEM_GENERATED` END DESC,	
		
		-- EXTRA
		CASE WHEN PARAM_ORDER_FIELD <> 'MOB_CONTACT_DESCRIPTION' THEN `mobile_contact`.`MOB_CONTACT_DESCRIPTION` END DESC
		
	-- LIMIT & OFFSET
	-- ####################################################		
	LIMIT PARAM_SKIP, PARAM_LIMIT;
	
	
	
	-- EXIT PROCEDURE
	-- =========================================================================================
	LEAVE SP_GET;
			
END ;;
DELIMITER ;
/*!50003 SET sql_mode              = @saved_sql_mode */ ;
/*!50003 SET character_set_client  = @saved_cs_client */ ;
/*!50003 SET character_set_results = @saved_cs_results */ ;
/*!50003 SET collation_connection  = @saved_col_connection */ ;
/*!50003 DROP PROCEDURE IF EXISTS `MOBILE_CONTACT_SAVE` */;
/*!50003 SET @saved_cs_client      = @@character_set_client */ ;
/*!50003 SET @saved_cs_results     = @@character_set_results */ ;
/*!50003 SET @saved_col_connection = @@collation_connection */ ;
/*!50003 SET character_set_client  = latin1 */ ;
/*!50003 SET character_set_results = latin1 */ ;
/*!50003 SET collation_connection  = latin1_swedish_ci */ ;
/*!50003 SET @saved_sql_mode       = @@sql_mode */ ;
/*!50003 SET sql_mode              = '' */ ;
DELIMITER ;;
CREATE DEFINER=`root`@`localhost` PROCEDURE `MOBILE_CONTACT_SAVE`(
	IN `PARAM_MOB_CONTACT_ID` BIGINT,
	IN `PARAM_MOB_CONTACT_ACC_GROUP_ID` BIGINT,
	IN `PARAM_MOB_CONTACT_MOBILE` VARCHAR(50),
	IN `PARAM_MOB_CONTACT_DESCRIPTION` VARCHAR(500),
	IN `PARAM_MOB_CONTACT_STATUS` TINYINT,

	IN `PARAM_REQUESTER_USERNAME` VARCHAR(500),
	IN `PARAM_REQUESTER_PASSWORD` VARCHAR(500),
	IN `PARAM_REQUESTER_IP` VARCHAR(1000),
	IN `PARAM_UNIQUE_SESSION_ID` VARCHAR(1000),
	IN `PARAM_SUPPRESS_RETURN` BIT,
	
	IN `PARAM_SYNC_SERVER_DESCRIPTION` VARCHAR(500), 
	IN `PARAM_SYNC_SERVER_UNIQUE_KEY` VARCHAR(500)
)
SP_SAVE:
BEGIN


	-- 1) DECLARE LOCAL PARAMETERS
	-- _______________________________________________________________________
	
	-- Status
	-- ...........................................
	DECLARE STATUS_INACTIVE TINYINT DEFAULT 1;
	DECLARE STATUS_ACTIVE TINYINT DEFAULT 2;
	DECLARE STATUS_CLOSED TINYINT DEFAULT 3;
	DECLARE STATUS_COMPLETED TINYINT DEFAULT 4;

	-- Audit Handler
	-- ...........................................
	DECLARE TEMP_RECORD_EXISTS BIT DEFAULT 0;
	DECLARE TEMP_MODULE_KEYWORD VARCHAR(500) DEFAULT 'mobile_contact';
	DECLARE TEMP_SP_OBJECTIVE VARCHAR(500) DEFAULT 'add/edit Contact Phonebook record';
	DECLARE TEMP_ERR_MESSAGE VARCHAR(500) DEFAULT '';
	DECLARE ERR BIGINT DEFAULT 0;
	DECLARE TEMP_RECORD_CHANGES VARCHAR(16000) DEFAULT '';
	DECLARE TEMP_RECORD_BINDED BIT DEFAULT 0;

	-- Authentication
	-- ...........................................
	DECLARE TEMP_ACCESS_RIGHTS_DENIED BIT DEFAULT 0;
	DECLARE TEMP_ACCESS_RIGHTS_HAS_OVERRIDE BIT DEFAULT 0;
	DECLARE TEMP_SYNC_SERVER_ID BIGINT DEFAULT 0;
	DECLARE TEMP_SYNC_IS_SERVER_REQUEST BIT DEFAULT 0;
	DECLARE TEMP_AUTHENTICATED_ACCOUNT_ID BIGINT DEFAULT `ACCOUNT_MEMBER@ACC_ACCOUNT_ID_FROM_LOGIN`(PARAM_REQUESTER_USERNAME, PARAM_REQUESTER_PASSWORD);
	DECLARE TEMP_AUTHENTICATED_ACCOUNT_LEVEL BIGINT DEFAULT 0;
	DECLARE TEMP_AUTHENTICATED_ACCOUNT_GROUP BIGINT DEFAULT 0;
	
	-- Local Parameters
	-- ...........................................
	DECLARE TEMP_NOW DATETIME(6) DEFAULT `SYSTEM_VAR@NOW`('', 1);
	DECLARE TEMP_RECORD_COUNT BIGINT DEFAULT 0;

	-- AutoGen Parameters
	-- ...........................................
	
	-- Local value holder
	-- ...........................................
	DECLARE TEMP_MOB_CONTACT_ACC_GROUP_ID BIGINT DEFAULT 0; 
	DECLARE TEMP_MOB_CONTACT_MOBILE VARCHAR(50) DEFAULT ''; 
	DECLARE TEMP_MOB_CONTACT_DESCRIPTION VARCHAR(500) DEFAULT ''; 
	DECLARE TEMP_MOB_CONTACT_STATUS TINYINT DEFAULT 0; 
	


	-- 2) Try Catch / Throw
	-- _______________________________________________________________________
	DECLARE EXIT HANDLER FOR SQLEXCEPTION
	BEGIN
		RESIGNAL;
	END;



	-- 3) Prepare SYNC
	-- _______________________________________________________________________

	-- IS RECORD EXISTS		
	-- ####################################################	
	SET TEMP_RECORD_EXISTS = `MOBILE_CONTACT@MOB_CONTACT_ID_EXISTS`(PARAM_MOB_CONTACT_ID, 0);

		
		
	-- 4) PREPARE AUTOGEN DATA (IF EXISTS)
	-- _______________________________________________________________________
	IF TEMP_SYNC_IS_SERVER_REQUEST = 0 THEN
		-- Just to keep at least one line within condition
		SET TEMP_SYNC_IS_SERVER_REQUEST = 0;
		
		-- Actual Functionalities here
		-- USE DEFAULT VALUE (String)
	END IF;



	-- 5) IF ALREADY EXIST, FILL MISSING DATA
	-- _______________________________________________________________________
	IF TEMP_RECORD_EXISTS = 1 THEN
		SELECT
			`mobile_contact`.`MOB_CONTACT_ACC_GROUP_ID`, 	
			`mobile_contact`.`MOB_CONTACT_MOBILE`, 	
			`mobile_contact`.`MOB_CONTACT_DESCRIPTION`, 	
			`mobile_contact`.`MOB_CONTACT_STATUS`	
		INTO
			TEMP_MOB_CONTACT_ACC_GROUP_ID, 	
			TEMP_MOB_CONTACT_MOBILE, 	
			TEMP_MOB_CONTACT_DESCRIPTION, 	
			TEMP_MOB_CONTACT_STATUS	

		FROM `mobile_contact`
		WHERE
			`mobile_contact`.`MOB_CONTACT_ID` = PARAM_MOB_CONTACT_ID
		LIMIT 1;

		-- Replace NULLs with the existing data.
		SET PARAM_MOB_CONTACT_ACC_GROUP_ID = `SYSTEM_VAR@REPLACE_NULL@BIGINT`(PARAM_MOB_CONTACT_ACC_GROUP_ID, TEMP_MOB_CONTACT_ACC_GROUP_ID, 1, 1);
		SET PARAM_MOB_CONTACT_MOBILE = `SYSTEM_VAR@REPLACE_NULL@NVARCHAR`(PARAM_MOB_CONTACT_MOBILE, TEMP_MOB_CONTACT_MOBILE, 1);
		SET PARAM_MOB_CONTACT_DESCRIPTION = `SYSTEM_VAR@REPLACE_NULL@NVARCHAR`(PARAM_MOB_CONTACT_DESCRIPTION, TEMP_MOB_CONTACT_DESCRIPTION, 1);
		SET PARAM_MOB_CONTACT_STATUS = `SYSTEM_VAR@REPLACE_NULL@TINYINT`(PARAM_MOB_CONTACT_STATUS, TEMP_MOB_CONTACT_STATUS, 1, 1);
		
		-- AUTO GEN (NON-UPDATABLES)		
		
		-- AUTO GEN (UPDATABLE WITH STATUS CHANGE)

		-- AUTO GEN (UPDATABLE WITH STATUS [ACTIVE/INACTIVE] CHANGE)
		
	ELSE
		SET PARAM_MOB_CONTACT_ACC_GROUP_ID = `SYSTEM_VAR@REPLACE_NULL@BIGINT`(PARAM_MOB_CONTACT_ACC_GROUP_ID, 0, 1, 1);
		SET PARAM_MOB_CONTACT_MOBILE = `SYSTEM_VAR@REPLACE_NULL@NVARCHAR`(PARAM_MOB_CONTACT_MOBILE, '', 1);
		SET PARAM_MOB_CONTACT_DESCRIPTION = `SYSTEM_VAR@REPLACE_NULL@NVARCHAR`(PARAM_MOB_CONTACT_DESCRIPTION, '', 1);
		SET PARAM_MOB_CONTACT_STATUS = `SYSTEM_VAR@REPLACE_NULL@TINYINT`(PARAM_MOB_CONTACT_STATUS, 0, 1, 1);
		
	END IF;

	

	-- 6) PREPARE AUDIT TRAIL
	-- _______________________________________________________________________
	IF TEMP_MOB_CONTACT_ACC_GROUP_ID <> PARAM_MOB_CONTACT_ACC_GROUP_ID THEN
		SET TEMP_RECORD_CHANGES = 
		`SYSTEM_VAR@CONCAT_ADD`(' | ', TEMP_RECORD_CHANGES, CONCAT_WS(' ', 'User Group: "', TEMP_MOB_CONTACT_ACC_GROUP_ID, '" > "', PARAM_MOB_CONTACT_ACC_GROUP_ID, '"'));
	END IF;	
	IF BINARY TEMP_MOB_CONTACT_MOBILE <> PARAM_MOB_CONTACT_MOBILE THEN
		SET TEMP_RECORD_CHANGES = 
		`SYSTEM_VAR@CONCAT_ADD`(' | ', TEMP_RECORD_CHANGES, CONCAT_WS(' ', 'Mobile Number: "', TEMP_MOB_CONTACT_MOBILE, '" > "', PARAM_MOB_CONTACT_MOBILE, '"'));
	END IF;
	IF BINARY TEMP_MOB_CONTACT_DESCRIPTION <> PARAM_MOB_CONTACT_DESCRIPTION THEN
		SET TEMP_RECORD_CHANGES = 
		`SYSTEM_VAR@CONCAT_ADD`(' | ', TEMP_RECORD_CHANGES, CONCAT_WS(' ', 'Description: "', TEMP_MOB_CONTACT_DESCRIPTION, '" > "', PARAM_MOB_CONTACT_DESCRIPTION, '"'));
	END IF;
	IF TEMP_MOB_CONTACT_STATUS <> PARAM_MOB_CONTACT_STATUS THEN
		SET TEMP_RECORD_CHANGES = 
		`SYSTEM_VAR@CONCAT_ADD`(' | ', TEMP_RECORD_CHANGES, CONCAT_WS(' ', 'Status: "', TEMP_MOB_CONTACT_STATUS, '" > "', PARAM_MOB_CONTACT_STATUS, '"'));
	END IF;	
		
	-- No Changes in data, reject request
	-- ####################################################
	IF CHARACTER_LENGTH(TEMP_RECORD_CHANGES) = 0 THEN
		IF PARAM_SUPPRESS_RETURN = 0 THEN
			SELECT PARAM_MOB_CONTACT_ID AS INSERTED_ID;
		END IF;
		LEAVE SP_SAVE;
	END IF;



	-- 7) VALIDATE
	-- _______________________________________________________________________

	-- Access Rights
	-- ####################################################
	-- Check if accessing a record outside own group.
	SET TEMP_AUTHENTICATED_ACCOUNT_GROUP = `ACCOUNT_MEMBER@ACC_ACCOUNT_GROUP_FROM_LOGIN`(PARAM_REQUESTER_USERNAME, PARAM_REQUESTER_PASSWORD);
	IF TEMP_AUTHENTICATED_ACCOUNT_GROUP <> PARAM_MOB_CONTACT_ACC_GROUP_ID THEN
		IF `ACCOUNT_ACCESS_RIGHTS@HAS_PERMISSION`(PARAM_REQUESTER_USERNAME, PARAM_REQUESTER_PASSWORD, 0, TEMP_MODULE_KEYWORD, 4) = 0 THEN
			SET TEMP_ACCESS_RIGHTS_DENIED = 1;
			CALL `ACCOUNT_ACCESS_RIGHTS_DENY`
			(
				0, TEMP_MODULE_KEYWORD, 0, 0, TEMP_SP_OBJECTIVE, TEMP_RECORD_CHANGES, 
				PARAM_REQUESTER_USERNAME, PARAM_REQUESTER_PASSWORD, PARAM_REQUESTER_IP, PARAM_UNIQUE_SESSION_ID,
				0, PARAM_SUPPRESS_RETURN
			);
		END IF;					
	END IF;
	
	IF 
		-- [ADD] Access Rights
		(
			TEMP_RECORD_EXISTS = 0 AND
			`ACCOUNT_ACCESS_RIGHTS@HAS_PERMISSION`(PARAM_REQUESTER_USERNAME, PARAM_REQUESTER_PASSWORD, 0, TEMP_MODULE_KEYWORD, 2) = 0 
		) OR
		
		-- [EDIT] Access Rights
		(
			TEMP_RECORD_EXISTS = 1 AND
			`ACCOUNT_ACCESS_RIGHTS@HAS_PERMISSION`(PARAM_REQUESTER_USERNAME, PARAM_REQUESTER_PASSWORD, 0, TEMP_MODULE_KEYWORD, 3) = 0 
		)
	THEN
		SET TEMP_ACCESS_RIGHTS_DENIED = 1;
		CALL `ACCOUNT_ACCESS_RIGHTS_DENY`
		(
			0, TEMP_MODULE_KEYWORD, PARAM_MOB_CONTACT_ID, 0, TEMP_SP_OBJECTIVE, TEMP_RECORD_CHANGES, 
			PARAM_REQUESTER_USERNAME, PARAM_REQUESTER_PASSWORD, PARAM_REQUESTER_IP, PARAM_UNIQUE_SESSION_ID,
			TEMP_SYNC_SERVER_ID, PARAM_SUPPRESS_RETURN
		);
	END IF;
	SET TEMP_ACCESS_RIGHTS_HAS_OVERRIDE = `ACCOUNT_ACCESS_RIGHTS@HAS_PERMISSION`(PARAM_REQUESTER_USERNAME, PARAM_REQUESTER_PASSWORD, 0, TEMP_MODULE_KEYWORD, 4);
	

	-- Validation
	-- ####################################################
	IF TEMP_SYNC_IS_SERVER_REQUEST = 0 THEN
	

		-- FOREIGN KEY EXISTS
		-- ...........................................
		IF `ACCOUNT_GROUP@ACC_GROUP_ID_EXISTS`(PARAM_MOB_CONTACT_ACC_GROUP_ID, 0) =  0 THEN
			SET TEMP_ERR_MESSAGE = CONCAT_WS(' ', 'Given User Group does not exists or is inactive. ID: ', PARAM_MOB_CONTACT_ACC_GROUP_ID);
			SET ERR = `RAISERROR`(TEMP_ERR_MESSAGE);
		END IF;
		
		-- FOREIGN (OPTIONAL)KEY EXISTS [Validates if not null]
		-- ...........................................
		
		-- IS_ALLOW_NULL = FALSE
		-- ...........................................
				
		-- IS_ALLOW_ZERO = FALSE
		-- ...........................................
		IF PARAM_MOB_CONTACT_STATUS = 0 THEN
			CALL `VALIDATION_MISSING_FIELD`('`MOB_CONTACT_STATUS`', '`NULL`');
		END IF;		
		
		-- IS_ALLOW_NEGATIVE = FALSE
		-- ...........................................
		IF PARAM_MOB_CONTACT_STATUS < 0 THEN
			CALL `VALIDATION_NEGATIVE`('`MOB_CONTACT_STATUS`', PARAM_MOB_CONTACT_STATUS);
		END IF;		
		
		-- IS_ALLOW_EMPTY_STRING = FALSE
		-- ...........................................
		IF `SYSTEM_VAR@IS_NULL@NVARCHAR`(PARAM_MOB_CONTACT_MOBILE, 1) = 1 THEN
			CALL `VALIDATION_MISSING_FIELD`('`MOB_CONTACT_MOBILE`', '`NULL`');
		END IF;
		IF `SYSTEM_VAR@IS_NULL@NVARCHAR`(PARAM_MOB_CONTACT_DESCRIPTION, 1) = 1 THEN
			CALL `VALIDATION_MISSING_FIELD`('`MOB_CONTACT_DESCRIPTION`', '`NULL`');
		END IF;
		
		-- IS_STATUS
		-- ...........................................
		IF `SYSTEM_STATUS@STATUS_ID_EXISTS`(PARAM_MOB_CONTACT_STATUS, 0) = 0 THEN
			SET TEMP_ERR_MESSAGE = CONCAT_WS(' ', 'Given STATUS[Status] does not exists or is inactive. ID: ', PARAM_MOB_CONTACT_STATUS);
			SET ERR = `RAISERROR`(TEMP_ERR_MESSAGE);
		END IF;
		
		-- IS STATUS Active / Inactive
		-- ...........................................
		
		-- Minimum / Maximum Value
		-- ...........................................
		
		-- IS_UNIQUE = TRUE
		-- ...........................................
		
		-- RECORD IDENTIFIER
		-- ...........................................
		IF
		(
			SELECT COUNT(`mobile_contact`.`MOB_CONTACT_ID`)
			FROM `mobile_contact`
			WHERE
				`mobile_contact`.`MOB_CONTACT_ACC_GROUP_ID` = PARAM_MOB_CONTACT_ACC_GROUP_ID AND
				`mobile_contact`.`MOB_CONTACT_MOBILE` = PARAM_MOB_CONTACT_MOBILE AND
				`mobile_contact`.`MOB_CONTACT_ID` <> PARAM_MOB_CONTACT_ID
		) >= 1
		THEN
			CALL `VALIDATION_REDUNDANT_ENTRY`(PARAM_MOB_CONTACT_DESCRIPTION);
		END IF;
		
		
		-- ON_UPDATE VALIDATION 
		-- ...........................................
		IF TEMP_RECORD_EXISTS = 1 THEN	
		
			-- Just to keep at least one line within condition
			SET TEMP_RECORD_EXISTS = 1;
			
		END IF;
		
	END IF;



	-- 8) INSERT / UPDATE
	-- _______________________________________________________________________

	-- INSERT NEW DATA
	-- ####################################################
	IF TEMP_RECORD_EXISTS = 0 THEN

		INSERT INTO
		`mobile_contact`
		(
			`mobile_contact`.`MOB_CONTACT_ACC_GROUP_ID`, 
			`mobile_contact`.`MOB_CONTACT_MOBILE`, 
			`mobile_contact`.`MOB_CONTACT_DESCRIPTION`, 
			`mobile_contact`.`MOB_CONTACT_STATUS`
		)
		VALUES
		(
			PARAM_MOB_CONTACT_ACC_GROUP_ID, 
			PARAM_MOB_CONTACT_MOBILE, 
			PARAM_MOB_CONTACT_DESCRIPTION, 
			PARAM_MOB_CONTACT_STATUS
		);	
		
		-- Update Audit trail with new ID	
		SET PARAM_MOB_CONTACT_ID = LAST_INSERT_ID();



	-- UPDATING EXISTING RECORD
	-- ####################################################
	ELSE
		UPDATE `mobile_contact`
		SET
			`mobile_contact`.`MOB_CONTACT_ACC_GROUP_ID` = PARAM_MOB_CONTACT_ACC_GROUP_ID, 
			`mobile_contact`.`MOB_CONTACT_MOBILE` = PARAM_MOB_CONTACT_MOBILE, 
			`mobile_contact`.`MOB_CONTACT_DESCRIPTION` = PARAM_MOB_CONTACT_DESCRIPTION, 
			`mobile_contact`.`MOB_CONTACT_STATUS` = PARAM_MOB_CONTACT_STATUS
		WHERE
			`mobile_contact`.`MOB_CONTACT_ID` = PARAM_MOB_CONTACT_ID;

	END IF;

	
	-- 9) AUDIT TRAIL
	-- _______________________________________________________________________
	CALL `ACCOUNT_AUDIT_TRAIL_SAVE`
	(
		0, TEMP_MODULE_KEYWORD, PARAM_MOB_CONTACT_ID, 0, 'SAVE', TEMP_SP_OBJECTIVE, TEMP_RECORD_CHANGES, 
		PARAM_REQUESTER_USERNAME, PARAM_REQUESTER_PASSWORD, PARAM_REQUESTER_IP, PARAM_UNIQUE_SESSION_ID,
		TEMP_SYNC_SERVER_ID, PARAM_SUPPRESS_RETURN
	);
	

	-- 10) RETURN RESULT
	-- _______________________________________________________________________
	IF PARAM_SUPPRESS_RETURN = 0 THEN
		SELECT PARAM_MOB_CONTACT_ID AS INSERTED_ID;
	END IF;
	LEAVE SP_SAVE;


END ;;
DELIMITER ;
/*!50003 SET sql_mode              = @saved_sql_mode */ ;
/*!50003 SET character_set_client  = @saved_cs_client */ ;
/*!50003 SET character_set_results = @saved_cs_results */ ;
/*!50003 SET collation_connection  = @saved_col_connection */ ;
/*!50003 DROP PROCEDURE IF EXISTS `RECORD_ATTENDANCE_DELETE` */;
/*!50003 SET @saved_cs_client      = @@character_set_client */ ;
/*!50003 SET @saved_cs_results     = @@character_set_results */ ;
/*!50003 SET @saved_col_connection = @@collation_connection */ ;
/*!50003 SET character_set_client  = latin1 */ ;
/*!50003 SET character_set_results = latin1 */ ;
/*!50003 SET collation_connection  = latin1_swedish_ci */ ;
/*!50003 SET @saved_sql_mode       = @@sql_mode */ ;
/*!50003 SET sql_mode              = '' */ ;
DELIMITER ;;
CREATE DEFINER=`root`@`localhost` PROCEDURE `RECORD_ATTENDANCE_DELETE`(
	IN `PARAM_REC_ATTENDANCE_ID` BIGINT,

	IN `PARAM_REQUESTER_USERNAME` VARCHAR(500),
	IN `PARAM_REQUESTER_PASSWORD` VARCHAR(500),
	IN `PARAM_REQUESTER_PROXY_ID` BIGINT,
	IN `PARAM_REQUESTER_PROXY_PASSWORD` VARCHAR(1000),
	IN `PARAM_REQUESTER_DEVICE_PUBLIC_KEY` VARCHAR(1000),
	IN `PARAM_REQUESTER_DEVICE_PRIVATE_KEY` VARCHAR(1000),
	
	IN `PARAM_REQUESTER_IP` VARCHAR(1000),
	IN `PARAM_UNIQUE_SESSION_ID` VARCHAR(1000),
	IN `PARAM_SUPPRESS_RETURN` BIT,
	
	IN `PARAM_SYNC_SERVER_DESCRIPTION` VARCHAR(500), 
	IN `PARAM_SYNC_SERVER_UNIQUE_KEY` VARCHAR(500)
)
SP_DELETE:
BEGIN

	-- 1) DECLARE LOCAL PARAMETERS
	-- _______________________________________________________________________
	
	-- Status
	-- ...........................................
	DECLARE STATUS_INACTIVE TINYINT DEFAULT 1;
	DECLARE STATUS_ACTIVE TINYINT DEFAULT 2;
	DECLARE STATUS_CLOSED TINYINT DEFAULT 3;
	DECLARE STATUS_COMPLETED TINYINT DEFAULT 4;
	
	-- Audit Handler
	-- ...........................................
	DECLARE TEMP_RECORD_EXISTS BIT DEFAULT 0;
	DECLARE TEMP_MODULE_KEYWORD VARCHAR(500) DEFAULT 'record_attendance';
	DECLARE TEMP_SP_OBJECTIVE VARCHAR(500) DEFAULT 'delete Attendance record';
	DECLARE TEMP_ERR_MESSAGE VARCHAR(500) DEFAULT '';
	DECLARE ERR BIGINT DEFAULT 0;
	DECLARE TEMP_RECORD_CHANGES VARCHAR(16000) DEFAULT '';
	DECLARE TEMP_RECORD_BINDED BIT DEFAULT 0;
	
	DECLARE TEMP_RECORD_BINDED_ID BIGINT DEFAULT 0;
	DECLARE TEMP_RECORD_BINDED_SERVER_ID BIGINT DEFAULT 0;
	
	-- Authentication
	-- ...........................................
	DECLARE TEMP_ACCESS_RIGHTS_DENIED BIT DEFAULT 0;
	DECLARE TEMP_SYNC_SERVER_ID BIGINT DEFAULT 0;
	DECLARE TEMP_SYNC_IS_SERVER_REQUEST BIT DEFAULT 0;
	DECLARE TEMP_AUTHENTICATED_ACCOUNT_ID BIGINT DEFAULT `ACCOUNT_MEMBER@ACC_ACCOUNT_ID_FROM_LOGIN`(PARAM_REQUESTER_USERNAME, PARAM_REQUESTER_PASSWORD);
	DECLARE TEMP_AUTHENTICATED_ACCOUNT_LEVEL BIGINT DEFAULT 0;
	DECLARE TEMP_AUTHENTICATED_ACCOUNT_GROUP BIGINT DEFAULT 0;

	-- Local value holder
	-- ...........................................
		DECLARE TEMP_REC_ATTENDANCE_REC_USER_ID BIGINT DEFAULT 0; 
		DECLARE TEMP_REC_ATTENDANCE_DATE DATETIME(6) DEFAULT '1000-01-01 00:00:00.000000'; 
		DECLARE TEMP_REC_ATTENDANCE_IS_IN TINYINT DEFAULT 0; 
		DECLARE TEMP_REC_ATTENDANCE_IS_OUT TINYINT DEFAULT 0; 
		DECLARE TEMP_REC_ATTENDANCE_ENTRANCE VARCHAR(400) DEFAULT ''; 
		DECLARE TEMP_REC_ATTENDANCE_DEVICE_KEY VARCHAR(4000) DEFAULT ''; 
		DECLARE TEMP_REC_ATTENDANCE_STATUS TINYINT DEFAULT 0; 

	
	
	-- 2) Try Catch / Throw
	-- _______________________________________________________________________
	DECLARE EXIT HANDLER FOR SQLEXCEPTION
	BEGIN
		RESIGNAL;
	END;

	
	-- 3) Prepare SYNC
	-- _______________________________________________________________________
	
	-- IS RECORD EXISTS		
	-- ####################################################		
	SET TEMP_RECORD_EXISTS = `RECORD_ATTENDANCE@REC_ATTENDANCE_ID_EXISTS`(PARAM_REC_ATTENDANCE_ID, 0);


	-- 4) IF ALREADY EXIST, FILL MISSING DATA
	-- _______________________________________________________________________
	IF TEMP_RECORD_EXISTS = 1 THEN
		SELECT
				`record_attendance`.`REC_ATTENDANCE_REC_USER_ID`, 	
				`record_attendance`.`REC_ATTENDANCE_DATE`, 	
				`record_attendance`.`REC_ATTENDANCE_IS_IN`, 	
				`record_attendance`.`REC_ATTENDANCE_IS_OUT`, 	
				`record_attendance`.`REC_ATTENDANCE_ENTRANCE`, 	
				`record_attendance`.`REC_ATTENDANCE_DEVICE_KEY`, 	
				`record_attendance`.`REC_ATTENDANCE_STATUS`	
		INTO
				TEMP_REC_ATTENDANCE_REC_USER_ID, 	
				TEMP_REC_ATTENDANCE_DATE, 	
				TEMP_REC_ATTENDANCE_IS_IN, 	
				TEMP_REC_ATTENDANCE_IS_OUT, 	
				TEMP_REC_ATTENDANCE_ENTRANCE, 	
				TEMP_REC_ATTENDANCE_DEVICE_KEY, 	
				TEMP_REC_ATTENDANCE_STATUS	

		FROM `record_attendance`
		WHERE
			`record_attendance`.`REC_ATTENDANCE_ID` = PARAM_REC_ATTENDANCE_ID
		LIMIT 1;

	ELSE 
		IF TEMP_SYNC_IS_SERVER_REQUEST = 0 THEN
			SET TEMP_ERR_MESSAGE = CONCAT_WS(' ', 'Given Attendance does not exists or is inactive. ID:', PARAM_REC_ATTENDANCE_ID);
			SET ERR = `RAISERROR`(TEMP_ERR_MESSAGE);		
		END IF;
		LEAVE SP_DELETE;
		
	END IF;



	-- 5) PREPARE AUDIT TRAIL
	-- _______________________________________________________________________
	
		SET TEMP_RECORD_CHANGES = 
		`SYSTEM_VAR@CONCAT_ADD`(' | ', TEMP_RECORD_CHANGES, CONCAT_WS(' ', 'User: "', TEMP_REC_ATTENDANCE_REC_USER_ID, '" > " DELETED "'));
		SET TEMP_RECORD_CHANGES = 
		`SYSTEM_VAR@CONCAT_ADD`(' | ', TEMP_RECORD_CHANGES, CONCAT_WS(' ', 'Date: "', TEMP_REC_ATTENDANCE_DATE, '" > " DELETED "'));
		SET TEMP_RECORD_CHANGES = 
		`SYSTEM_VAR@CONCAT_ADD`(' | ', TEMP_RECORD_CHANGES, CONCAT_WS(' ', 'In: "', TEMP_REC_ATTENDANCE_IS_IN, '" > " DELETED "'));
		SET TEMP_RECORD_CHANGES = 
		`SYSTEM_VAR@CONCAT_ADD`(' | ', TEMP_RECORD_CHANGES, CONCAT_WS(' ', 'Out: "', TEMP_REC_ATTENDANCE_IS_OUT, '" > " DELETED "'));
		SET TEMP_RECORD_CHANGES = 
		`SYSTEM_VAR@CONCAT_ADD`(' | ', TEMP_RECORD_CHANGES, CONCAT_WS(' ', 'Entrance: "', TEMP_REC_ATTENDANCE_ENTRANCE, '" > " DELETED "'));
		SET TEMP_RECORD_CHANGES = 
		`SYSTEM_VAR@CONCAT_ADD`(' | ', TEMP_RECORD_CHANGES, CONCAT_WS(' ', 'Device Key: "', TEMP_REC_ATTENDANCE_DEVICE_KEY, '" > " DELETED "'));
		SET TEMP_RECORD_CHANGES = 
		`SYSTEM_VAR@CONCAT_ADD`(' | ', TEMP_RECORD_CHANGES, CONCAT_WS(' ', 'Status: "', TEMP_REC_ATTENDANCE_STATUS, '" > " DELETED "'));


	-- 6) VALIDATE
	-- _______________________________________________________________________
	
	-- Access Rights [Device]
	-- ####################################################
	IF `ACCOUNT_DEVICE@HAS_PERMISSION`(PARAM_REQUESTER_DEVICE_PUBLIC_KEY, PARAM_REQUESTER_DEVICE_PRIVATE_KEY) = 0 THEN
		SET TEMP_ERR_MESSAGE = 'Your device is not authorized yet to access this server.';
		SET ERR = `RAISERROR`(TEMP_ERR_MESSAGE);		
	END IF;
		
		
	-- Access Rights [Account]
	-- ####################################################	
	
	IF 
		-- [DELETE] Access Rights
		`ACCOUNT_ACCESS_RIGHTS@HAS_PERMISSION`(PARAM_REQUESTER_USERNAME, PARAM_REQUESTER_PASSWORD, 0, TEMP_MODULE_KEYWORD, 4) = 0 AND
		`ACCOUNT_ACCESS_RIGHTS@PROXY_PERMISSION`(PARAM_REQUESTER_PROXY_ID, PARAM_REQUESTER_PROXY_PASSWORD, 0, TEMP_MODULE_KEYWORD, 4) = 0
	THEN
		SET TEMP_ACCESS_RIGHTS_DENIED = 1;
		CALL `ACCOUNT_ACCESS_RIGHTS_DENY`
		(
			0, TEMP_MODULE_KEYWORD, PARAM_REC_ATTENDANCE_ID, 0, TEMP_SP_OBJECTIVE, TEMP_RECORD_CHANGES, 
			PARAM_REQUESTER_USERNAME, PARAM_REQUESTER_PASSWORD, 
			PARAM_REQUESTER_PROXY_ID, PARAM_REQUESTER_PROXY_PASSWORD,
			PARAM_REQUESTER_DEVICE_PUBLIC_KEY, PARAM_REQUESTER_DEVICE_PRIVATE_KEY,
			PARAM_REQUESTER_IP, PARAM_UNIQUE_SESSION_ID,
			TEMP_SYNC_SERVER_ID, PARAM_SUPPRESS_RETURN
		);
	END IF;

	
	-- If already used, cannot remove record
	-- ####################################################

	-- Leave Re-upload request
	-- ####################################################
	IF TEMP_RECORD_BINDED = 1 THEN
		IF TEMP_SYNC_IS_SERVER_REQUEST = 1 THEN
			
			LEAVE SP_DELETE;
		END IF;

		CALL `VALIDATION_DELETE_LINKED_RECORD`(TEMP_REC_ATTENDANCE_DATE, '', TEMP_ERR_MESSAGE); 
	END IF;


	-- 7) DELETE
	-- _______________________________________________________________________
	DELETE FROM `record_attendance`
	WHERE `record_attendance`.`REC_ATTENDANCE_ID` = PARAM_REC_ATTENDANCE_ID
	LIMIT 1;


	-- 8) AUDIT TRAIL
	-- _______________________________________________________________________
	CALL `ACCOUNT_AUDIT_TRAIL_SAVE`
	(
		0, TEMP_MODULE_KEYWORD, PARAM_REC_ATTENDANCE_ID, 0, 'DELETE', TEMP_SP_OBJECTIVE, TEMP_RECORD_CHANGES, 
		PARAM_REQUESTER_USERNAME, PARAM_REQUESTER_PASSWORD, 
		PARAM_REQUESTER_PROXY_ID, PARAM_REQUESTER_PROXY_PASSWORD,
		PARAM_REQUESTER_DEVICE_PUBLIC_KEY, PARAM_REQUESTER_DEVICE_PRIVATE_KEY,
		PARAM_REQUESTER_IP, PARAM_UNIQUE_SESSION_ID,
		TEMP_SYNC_SERVER_ID, PARAM_SUPPRESS_RETURN
	);

END ;;
DELIMITER ;
/*!50003 SET sql_mode              = @saved_sql_mode */ ;
/*!50003 SET character_set_client  = @saved_cs_client */ ;
/*!50003 SET character_set_results = @saved_cs_results */ ;
/*!50003 SET collation_connection  = @saved_col_connection */ ;
/*!50003 DROP PROCEDURE IF EXISTS `RECORD_ATTENDANCE_GET` */;
/*!50003 SET @saved_cs_client      = @@character_set_client */ ;
/*!50003 SET @saved_cs_results     = @@character_set_results */ ;
/*!50003 SET @saved_col_connection = @@collation_connection */ ;
/*!50003 SET character_set_client  = latin1 */ ;
/*!50003 SET character_set_results = latin1 */ ;
/*!50003 SET collation_connection  = latin1_swedish_ci */ ;
/*!50003 SET @saved_sql_mode       = @@sql_mode */ ;
/*!50003 SET sql_mode              = '' */ ;
DELIMITER ;;
CREATE DEFINER=`root`@`localhost` PROCEDURE `RECORD_ATTENDANCE_GET`(
	IN `PARAM_REC_ATTENDANCE_ID` BIGINT,	
	IN `PARAM_REC_ATTENDANCE_REC_USER_ID` BIGINT,	

	IN `PARAM_REC_ATTENDANCE_DATE_FROM` DATETIME(6),
	IN `PARAM_REC_ATTENDANCE_DATE_TO` DATETIME(6),
	IN `PARAM_REC_ATTENDANCE_IS_IN` TINYINT,	
	IN `PARAM_REC_ATTENDANCE_IS_OUT` TINYINT,	
	IN `PARAM_REC_ATTENDANCE_ENTRANCE` VARCHAR(400),	
	IN `PARAM_REC_ATTENDANCE_DEVICE_KEY` VARCHAR(4000),	
	IN `PARAM_REC_ATTENDANCE_STATUS` TINYINT,	
		
	IN `PARAM_REC_USER_CAT_DEPARTMENT_ID` BIGINT,
	IN `PARAM_REC_STUDENT_CAT_SECTION_ID` BIGINT,

	IN `PARAM_ORDER_FIELD` VARCHAR(500),
	IN `PARAM_ORDER_TYPE` VARCHAR(500),
	IN `PARAM_SKIP` BIGINT,
	IN `PARAM_LIMIT` BIGINT,

	IN `PARAM_REQUESTER_USERNAME` VARCHAR(500),
	IN `PARAM_REQUESTER_PASSWORD` VARCHAR(500),
	IN `PARAM_REQUESTER_PROXY_ID` BIGINT,
	IN `PARAM_REQUESTER_PROXY_PASSWORD` VARCHAR(1000),
	IN `PARAM_REQUESTER_DEVICE_PUBLIC_KEY` VARCHAR(1000),
	IN `PARAM_REQUESTER_DEVICE_PRIVATE_KEY` VARCHAR(1000),
	
	IN `PARAM_REQUESTER_IP` VARCHAR(1000),
	IN `PARAM_UNIQUE_SESSION_ID` VARCHAR(1000),
	IN `PARAM_SUPPRESS_RETURN` BIT
)
SP_GET:
BEGIN

	-- Status
	-- =========================================================================================
	DECLARE STATUS_INACTIVE TINYINT DEFAULT 1;
	DECLARE STATUS_ACTIVE TINYINT DEFAULT 2;
	DECLARE STATUS_CLOSED TINYINT DEFAULT 3;
	DECLARE STATUS_COMPLETED TINYINT DEFAULT 4;
	
	-- Audit Handler
	-- =========================================================================================
	DECLARE TEMP_RECORD_EXISTS BIT DEFAULT 0;
	DECLARE TEMP_MODULE_KEYWORD VARCHAR(500) DEFAULT 'record_attendance';
	DECLARE TEMP_SP_OBJECTIVE VARCHAR(500) DEFAULT 'Retrieve Attendance record';
	DECLARE TEMP_ERR_MESSAGE VARCHAR(500) DEFAULT '';
	DECLARE ERR BIGINT DEFAULT 0;
	DECLARE TEMP_RECORD_CHANGES VARCHAR(16000) DEFAULT '';
	DECLARE TEMP_RECORD_BINDED BIT DEFAULT 0;
	
	DECLARE TEMP_RECORD_BINDED_ID BIGINT DEFAULT 0;
	DECLARE TEMP_RECORD_BINDED_SERVER_ID BIGINT DEFAULT 0;
	
	-- Authentication
	-- =========================================================================================
	DECLARE TEMP_ACCESS_RIGHTS_DENIED BIT DEFAULT 0;
	DECLARE TEMP_AUTHENTICATED_ACCOUNT_ID BIGINT DEFAULT `ACCOUNT_MEMBER@ACC_ACCOUNT_ID_FROM_LOGIN`(PARAM_REQUESTER_USERNAME, PARAM_REQUESTER_PASSWORD);
	DECLARE TEMP_AUTHENTICATED_ACCOUNT_LEVEL BIGINT DEFAULT 0;
	DECLARE TEMP_AUTHENTICATED_ACCOUNT_GROUP BIGINT DEFAULT 0;
	
	-- Local Parameters
	-- =========================================================================================
	DECLARE TEMP_NOW DATETIME(6) DEFAULT `SYSTEM_VAR@NOW`('', 1);
	DECLARE TEMP_RECORD_COUNT BIGINT DEFAULT 0;
	
	
	-- Check NULLs
	-- =========================================================================================
	DECLARE IS_NULL_REC_ATTENDANCE_ID BIT DEFAULT `SYSTEM_VAR@IS_NULL@BIGINT`(PARAM_REC_ATTENDANCE_ID, 1, 1);	

	DECLARE IS_NULL_REC_ATTENDANCE_REC_USER_ID BIT DEFAULT `SYSTEM_VAR@IS_NULL@BIGINT`(PARAM_REC_ATTENDANCE_REC_USER_ID, 1, 1);
	DECLARE IS_NULL_REC_ATTENDANCE_DATE_FROM BIT DEFAULT `SYSTEM_VAR@IS_NULL@DATETIME`(PARAM_REC_ATTENDANCE_DATE_FROM, 1);
	DECLARE IS_NULL_REC_ATTENDANCE_DATE_TO BIT DEFAULT `SYSTEM_VAR@IS_NULL@DATETIME`(PARAM_REC_ATTENDANCE_DATE_TO, 1);				
	DECLARE IS_NULL_REC_ATTENDANCE_IS_IN BIT DEFAULT `SYSTEM_VAR@IS_NULL@TINYINT`(PARAM_REC_ATTENDANCE_IS_IN, 1, 1);
	DECLARE IS_NULL_REC_ATTENDANCE_IS_OUT BIT DEFAULT `SYSTEM_VAR@IS_NULL@TINYINT`(PARAM_REC_ATTENDANCE_IS_OUT, 1, 1);
	DECLARE IS_NULL_REC_ATTENDANCE_ENTRANCE BIT DEFAULT `SYSTEM_VAR@IS_NULL@NVARCHAR`(PARAM_REC_ATTENDANCE_ENTRANCE, 1);
	DECLARE IS_NULL_REC_ATTENDANCE_DEVICE_KEY BIT DEFAULT `SYSTEM_VAR@IS_NULL@NVARCHAR`(PARAM_REC_ATTENDANCE_DEVICE_KEY, 1);
	DECLARE IS_NULL_REC_ATTENDANCE_STATUS BIT DEFAULT `SYSTEM_VAR@IS_NULL@TINYINT`(PARAM_REC_ATTENDANCE_STATUS, 1, 1);
	
	DECLARE IS_NULL_REC_USER_CAT_DEPARTMENT_ID BIT DEFAULT `SYSTEM_VAR@IS_NULL@BIGINT`(PARAM_REC_USER_CAT_DEPARTMENT_ID, 1, 1);
	DECLARE IS_NULL_REC_STUDENT_CAT_SECTION_ID BIT DEFAULT `SYSTEM_VAR@IS_NULL@BIGINT`(PARAM_REC_STUDENT_CAT_SECTION_ID, 1, 1);
	

	-- Error Handler
	-- =========================================================================================
	DECLARE EXIT HANDLER FOR SQLEXCEPTION
	BEGIN
		RESIGNAL;
	END;
	
	-- Ignore Time from DateTime (Set Time 00:00:00.000000 and 23:59:59.999999)
	-- =========================================================================================
		
		
	-- Access Rights [Device]
	-- =========================================================================================
	IF `ACCOUNT_DEVICE@HAS_PERMISSION`(PARAM_REQUESTER_DEVICE_PUBLIC_KEY, PARAM_REQUESTER_DEVICE_PRIVATE_KEY) = 0 THEN
		SET TEMP_ERR_MESSAGE = 'Your device is not authorized yet to access this server.';
		SET ERR = `RAISERROR`(TEMP_ERR_MESSAGE);		
	END IF;
		
		
	-- Access Rights [Account]
	-- =========================================================================================
		
	IF 
		`ACCOUNT_ACCESS_RIGHTS@HAS_PERMISSION`(PARAM_REQUESTER_USERNAME, PARAM_REQUESTER_PASSWORD, 0, TEMP_MODULE_KEYWORD, 1) = 0 AND
		`ACCOUNT_ACCESS_RIGHTS@PROXY_PERMISSION`(PARAM_REQUESTER_PROXY_ID, PARAM_REQUESTER_PROXY_PASSWORD, 0, TEMP_MODULE_KEYWORD, 1) = 0
	THEN
		SET TEMP_ACCESS_RIGHTS_DENIED = 1;
		CALL `ACCOUNT_ACCESS_RIGHTS_DENY`
		(
			0, TEMP_MODULE_KEYWORD, 0, 0, TEMP_SP_OBJECTIVE, TEMP_RECORD_CHANGES, 
			PARAM_REQUESTER_USERNAME, PARAM_REQUESTER_PASSWORD, 
			PARAM_REQUESTER_PROXY_ID, PARAM_REQUESTER_PROXY_PASSWORD,
			PARAM_REQUESTER_DEVICE_PUBLIC_KEY, PARAM_REQUESTER_DEVICE_PRIVATE_KEY,
			PARAM_REQUESTER_IP, PARAM_UNIQUE_SESSION_ID,
			0, PARAM_SUPPRESS_RETURN
		);
	END IF;
	
	
	
	-- COUNT RECORD
	-- =========================================================================================
	
	-- SELECT COLUMNS
	-- ####################################################
	SELECT
		COUNT(DISTINCT `record_attendance`.`REC_ATTENDANCE_ID`)
	INTO
		TEMP_RECORD_COUNT

	FROM `record_attendance`
				
		-- Add Inner Joins (Per Foreign-key)
		INNER JOIN `record_user` ON
		`record_user`.`REC_USER_ID` = `record_attendance`.`REC_ATTENDANCE_REC_USER_ID` AND
		(
			IS_NULL_REC_USER_CAT_DEPARTMENT_ID  = 1 OR
			`record_user`.`REC_USER_CAT_DEPARTMENT_ID` =  PARAM_REC_USER_CAT_DEPARTMENT_ID
		) AND
		(
			IS_NULL_REC_STUDENT_CAT_SECTION_ID = 1 OR
			`record_user`.`REC_USER_CAT_SECTION_ID` =  PARAM_REC_STUDENT_CAT_SECTION_ID
		) 

		INNER JOIN `category_department` ON
		`category_department`.`CAT_DEPARTMENT_ID` = `record_user`.`REC_USER_CAT_DEPARTMENT_ID`		
		
	-- CONDITIONS
	-- ####################################################
	WHERE
		(
			IS_NULL_REC_ATTENDANCE_ID = 1 OR
			`record_attendance`.`REC_ATTENDANCE_ID` = PARAM_REC_ATTENDANCE_ID			
		) AND
		(
			IS_NULL_REC_ATTENDANCE_REC_USER_ID = 1 OR
			`record_attendance`.`REC_ATTENDANCE_REC_USER_ID` = PARAM_REC_ATTENDANCE_REC_USER_ID			
		) AND
		(
			IS_NULL_REC_ATTENDANCE_DATE_FROM = 1 OR
			`record_attendance`.`REC_ATTENDANCE_DATE` >= PARAM_REC_ATTENDANCE_DATE_FROM			
		) AND
		(
			IS_NULL_REC_ATTENDANCE_DATE_TO = 1 OR
			`record_attendance`.`REC_ATTENDANCE_DATE` <= PARAM_REC_ATTENDANCE_DATE_TO			
		) AND 		
		(
			IS_NULL_REC_ATTENDANCE_IS_IN = 1 OR
			`record_attendance`.`REC_ATTENDANCE_IS_IN` = PARAM_REC_ATTENDANCE_IS_IN			
		) AND
		(
			IS_NULL_REC_ATTENDANCE_IS_OUT = 1 OR
			`record_attendance`.`REC_ATTENDANCE_IS_OUT` = PARAM_REC_ATTENDANCE_IS_OUT			
		) AND
		(
			IS_NULL_REC_ATTENDANCE_ENTRANCE = 1 OR
			`record_attendance`.`REC_ATTENDANCE_ENTRANCE` LIKE CONCAT_WS('%', '', PARAM_REC_ATTENDANCE_ENTRANCE, '')			
		) AND 		
		(
			IS_NULL_REC_ATTENDANCE_DEVICE_KEY = 1 OR
			`record_attendance`.`REC_ATTENDANCE_DEVICE_KEY` LIKE CONCAT_WS('%', '', PARAM_REC_ATTENDANCE_DEVICE_KEY, '')			
		) AND 		
		(
			IS_NULL_REC_ATTENDANCE_STATUS = 1 OR
			`record_attendance`.`REC_ATTENDANCE_STATUS` = PARAM_REC_ATTENDANCE_STATUS			
		) 
;	

		
		
	-- SELECT RECORDS
	-- =========================================================================================
	
	-- FETCH COLUMNS
	-- ####################################################
	SELECT
		-- RECORD_ATTENDANCE DETAILS
		`record_attendance`.`REC_ATTENDANCE_ID`, 
		`record_attendance`.`REC_ATTENDANCE_REC_USER_ID`, 
		`record_attendance`.`REC_ATTENDANCE_DATE`, 
		`record_attendance`.`REC_ATTENDANCE_IS_IN`, 
		`record_attendance`.`REC_ATTENDANCE_IS_OUT`, 
		`record_attendance`.`REC_ATTENDANCE_ENTRANCE`, 
		`record_attendance`.`REC_ATTENDANCE_DEVICE_KEY`, 
		`record_attendance`.`REC_ATTENDANCE_STATUS`,
		IF
		(
			`record_attendance`.`REC_ATTENDANCE_IS_IN` = STATUS_ACTIVE,
			'IN', 'OUT'
		) AS REC_ATTENDANCE_IS_INOUT,
		
		-- Sum of Child [Numerics, non-primary/foreign keys, nor status, active/inactive, and system generated.]
		
		
		-- Inner join fields
		`record_user`.`REC_USER_ID`,	
		`record_user`.`REC_USER_CAT_DEPARTMENT_ID`,	
		`record_user`.`REC_USER_CAT_SECTION_ID`,	
		`record_user`.`REC_USER_UNIQUE_CODE`,	
		CONCAT_WS
		(
			' ',
			`record_user`.`REC_USER_LAST_NAME`, ',',
			`record_user`.`REC_USER_FIRST_NAME`,	
			`record_user`.`REC_USER_MIDDLE_NAME`,
			`record_user`.`REC_USER_SUFFIX`
		) AS REC_USER_NAME,
		`record_user`.`REC_USER_FIRST_NAME`,	
		`record_user`.`REC_USER_MIDDLE_NAME`,	
		`record_user`.`REC_USER_LAST_NAME` AS REC_ATTENDANCE_REC_USER_ID_DESCRIPTION,
		`record_user`.`REC_USER_LAST_NAME`,	
		`record_user`.`REC_USER_SUFFIX`,	
		`record_user`.`REC_USER_SYS_GENDER_ID`,	
		`record_user`.`REC_USER_NOTIFY_PHONE`,	
		`record_user`.`REC_USER_EMCONTACT_PERSON`,	
		`record_user`.`REC_USER_EMCONTACT_NUMBER`,	
		`record_user`.`REC_USER_STATUS`,
		
		`category_department`.`CAT_DEPARTMENT_ID`,	
		`category_department`.`CAT_DEPARTMENT_DESCRIPTION` AS REC_USER_CAT_DEPARTMENT_ID_DESCRIPTION,
		`category_department`.`CAT_DEPARTMENT_DESCRIPTION`,	
		`category_department`.`CAT_DEPARTMENT_STATUS`,	

		-- Left join fields
		TEMP_NOW AS SERVER_TIME,
		TEMP_RECORD_COUNT AS RECORD_COUNT

	FROM `record_attendance`
	
		-- Add Inner Joins (Per Foreign-key)
		INNER JOIN `record_user` ON
		`record_user`.`REC_USER_ID` = `record_attendance`.`REC_ATTENDANCE_REC_USER_ID` AND
		(
			IS_NULL_REC_USER_CAT_DEPARTMENT_ID  = 1 OR
			`record_user`.`REC_USER_CAT_DEPARTMENT_ID` =  PARAM_REC_USER_CAT_DEPARTMENT_ID
		) AND
		(
			IS_NULL_REC_STUDENT_CAT_SECTION_ID = 1 OR
			`record_user`.`REC_USER_CAT_SECTION_ID` =  PARAM_REC_STUDENT_CAT_SECTION_ID
		)	
		
		-- Add Optional Left Joins (Per Optional Foreign-key)
		INNER JOIN `category_department` ON
		`category_department`.`CAT_DEPARTMENT_ID` = `record_user`.`REC_USER_CAT_DEPARTMENT_ID`

	-- CONDITIONS
	-- ####################################################
	WHERE
		(
			IS_NULL_REC_ATTENDANCE_ID = 1 OR
			`record_attendance`.`REC_ATTENDANCE_ID` = PARAM_REC_ATTENDANCE_ID			
		) AND
		(
			IS_NULL_REC_ATTENDANCE_REC_USER_ID = 1 OR
			`record_attendance`.`REC_ATTENDANCE_REC_USER_ID` = PARAM_REC_ATTENDANCE_REC_USER_ID			
		) AND
		(
			IS_NULL_REC_ATTENDANCE_DATE_FROM = 1 OR
			`record_attendance`.`REC_ATTENDANCE_DATE` >= PARAM_REC_ATTENDANCE_DATE_FROM			
		) AND
		(
			IS_NULL_REC_ATTENDANCE_DATE_TO = 1 OR
			`record_attendance`.`REC_ATTENDANCE_DATE` <= PARAM_REC_ATTENDANCE_DATE_TO			
		) AND 
		(
			IS_NULL_REC_ATTENDANCE_IS_IN = 1 OR
			`record_attendance`.`REC_ATTENDANCE_IS_IN` = PARAM_REC_ATTENDANCE_IS_IN			
		) AND
		(
			IS_NULL_REC_ATTENDANCE_IS_OUT = 1 OR
			`record_attendance`.`REC_ATTENDANCE_IS_OUT` = PARAM_REC_ATTENDANCE_IS_OUT			
		) AND
		(
			IS_NULL_REC_ATTENDANCE_ENTRANCE = 1 OR
			`record_attendance`.`REC_ATTENDANCE_ENTRANCE` LIKE CONCAT_WS('%', '', PARAM_REC_ATTENDANCE_ENTRANCE, '')			
		) AND 		
		(
			IS_NULL_REC_ATTENDANCE_DEVICE_KEY = 1 OR
			`record_attendance`.`REC_ATTENDANCE_DEVICE_KEY` LIKE CONCAT_WS('%', '', PARAM_REC_ATTENDANCE_DEVICE_KEY, '')			
		) AND 		
		(
			IS_NULL_REC_ATTENDANCE_STATUS = 1 OR
			`record_attendance`.`REC_ATTENDANCE_STATUS` = PARAM_REC_ATTENDANCE_STATUS			
		) 

	-- ORDER BY
	-- ####################################################
	ORDER BY
		-- RECORD_ATTENDANCE DETAILS
		CASE WHEN PARAM_ORDER_FIELD = 'REC_ATTENDANCE_ID' AND PARAM_ORDER_TYPE = 'ASC' THEN `record_attendance`.`REC_ATTENDANCE_ID` END ASC, 
		CASE WHEN PARAM_ORDER_FIELD = 'REC_ATTENDANCE_ID' AND PARAM_ORDER_TYPE = 'DESC' THEN `record_attendance`.`REC_ATTENDANCE_ID` END DESC,	
		CASE WHEN PARAM_ORDER_FIELD = 'REC_ATTENDANCE_REC_USER_ID' AND PARAM_ORDER_TYPE = 'ASC' THEN `record_attendance`.`REC_ATTENDANCE_REC_USER_ID` END ASC, 
		CASE WHEN PARAM_ORDER_FIELD = 'REC_ATTENDANCE_REC_USER_ID' AND PARAM_ORDER_TYPE = 'DESC' THEN `record_attendance`.`REC_ATTENDANCE_REC_USER_ID` END DESC,	
		CASE WHEN PARAM_ORDER_FIELD = 'REC_ATTENDANCE_DATE' AND PARAM_ORDER_TYPE = 'ASC' THEN `record_attendance`.`REC_ATTENDANCE_DATE` END ASC, 
		CASE WHEN PARAM_ORDER_FIELD = 'REC_ATTENDANCE_DATE' AND PARAM_ORDER_TYPE = 'DESC' THEN `record_attendance`.`REC_ATTENDANCE_DATE` END DESC,	
		CASE WHEN PARAM_ORDER_FIELD = 'REC_ATTENDANCE_IS_IN' AND PARAM_ORDER_TYPE = 'ASC' THEN `record_attendance`.`REC_ATTENDANCE_IS_IN` END ASC, 
		CASE WHEN PARAM_ORDER_FIELD = 'REC_ATTENDANCE_IS_IN' AND PARAM_ORDER_TYPE = 'DESC' THEN `record_attendance`.`REC_ATTENDANCE_IS_IN` END DESC,	
		CASE WHEN PARAM_ORDER_FIELD = 'REC_ATTENDANCE_IS_OUT' AND PARAM_ORDER_TYPE = 'ASC' THEN `record_attendance`.`REC_ATTENDANCE_IS_OUT` END ASC, 
		CASE WHEN PARAM_ORDER_FIELD = 'REC_ATTENDANCE_IS_OUT' AND PARAM_ORDER_TYPE = 'DESC' THEN `record_attendance`.`REC_ATTENDANCE_IS_OUT` END DESC,	
		CASE WHEN PARAM_ORDER_FIELD = 'REC_ATTENDANCE_ENTRANCE' AND PARAM_ORDER_TYPE = 'ASC' THEN `record_attendance`.`REC_ATTENDANCE_ENTRANCE` END ASC, 
		CASE WHEN PARAM_ORDER_FIELD = 'REC_ATTENDANCE_ENTRANCE' AND PARAM_ORDER_TYPE = 'DESC' THEN `record_attendance`.`REC_ATTENDANCE_ENTRANCE` END DESC,	
		CASE WHEN PARAM_ORDER_FIELD = 'REC_ATTENDANCE_DEVICE_KEY' AND PARAM_ORDER_TYPE = 'ASC' THEN `record_attendance`.`REC_ATTENDANCE_DEVICE_KEY` END ASC, 
		CASE WHEN PARAM_ORDER_FIELD = 'REC_ATTENDANCE_DEVICE_KEY' AND PARAM_ORDER_TYPE = 'DESC' THEN `record_attendance`.`REC_ATTENDANCE_DEVICE_KEY` END DESC,	
		CASE WHEN PARAM_ORDER_FIELD = 'REC_ATTENDANCE_STATUS' AND PARAM_ORDER_TYPE = 'ASC' THEN `record_attendance`.`REC_ATTENDANCE_STATUS` END ASC, 
		CASE WHEN PARAM_ORDER_FIELD = 'REC_ATTENDANCE_STATUS' AND PARAM_ORDER_TYPE = 'DESC' THEN `record_attendance`.`REC_ATTENDANCE_STATUS` END DESC,	

		-- Inner joins
		CASE WHEN PARAM_ORDER_FIELD = 'REC_USER_ID' AND PARAM_ORDER_TYPE = 'ASC' THEN `record_user`.`REC_USER_ID` END ASC, 
		CASE WHEN PARAM_ORDER_FIELD = 'REC_USER_ID' AND PARAM_ORDER_TYPE = 'DESC' THEN `record_user`.`REC_USER_ID` END DESC,
		CASE WHEN PARAM_ORDER_FIELD = 'REC_USER_CAT_DEPARTMENT_ID' AND PARAM_ORDER_TYPE = 'ASC' THEN `record_user`.`REC_USER_CAT_DEPARTMENT_ID` END ASC, 
		CASE WHEN PARAM_ORDER_FIELD = 'REC_USER_CAT_DEPARTMENT_ID' AND PARAM_ORDER_TYPE = 'DESC' THEN `record_user`.`REC_USER_CAT_DEPARTMENT_ID` END DESC,
		CASE WHEN PARAM_ORDER_FIELD = 'REC_USER_CAT_SECTION_ID' AND PARAM_ORDER_TYPE = 'ASC' THEN `record_user`.`REC_USER_CAT_SECTION_ID` END ASC, 
		CASE WHEN PARAM_ORDER_FIELD = 'REC_USER_CAT_SECTION_ID' AND PARAM_ORDER_TYPE = 'DESC' THEN `record_user`.`REC_USER_CAT_SECTION_ID` END DESC,
		CASE WHEN PARAM_ORDER_FIELD = 'REC_USER_UNIQUE_CODE' AND PARAM_ORDER_TYPE = 'ASC' THEN `record_user`.`REC_USER_UNIQUE_CODE` END ASC, 
		CASE WHEN PARAM_ORDER_FIELD = 'REC_USER_UNIQUE_CODE' AND PARAM_ORDER_TYPE = 'DESC' THEN `record_user`.`REC_USER_UNIQUE_CODE` END DESC,
		CASE WHEN PARAM_ORDER_FIELD = 'REC_USER_FIRST_NAME' AND PARAM_ORDER_TYPE = 'ASC' THEN `record_user`.`REC_USER_FIRST_NAME` END ASC, 
		CASE WHEN PARAM_ORDER_FIELD = 'REC_USER_FIRST_NAME' AND PARAM_ORDER_TYPE = 'DESC' THEN `record_user`.`REC_USER_FIRST_NAME` END DESC,
		CASE WHEN PARAM_ORDER_FIELD = 'REC_USER_MIDDLE_NAME' AND PARAM_ORDER_TYPE = 'ASC' THEN `record_user`.`REC_USER_MIDDLE_NAME` END ASC, 
		CASE WHEN PARAM_ORDER_FIELD = 'REC_USER_MIDDLE_NAME' AND PARAM_ORDER_TYPE = 'DESC' THEN `record_user`.`REC_USER_MIDDLE_NAME` END DESC,
		CASE WHEN PARAM_ORDER_FIELD = 'REC_USER_LAST_NAME' AND PARAM_ORDER_TYPE = 'ASC' THEN `record_user`.`REC_USER_LAST_NAME` END ASC, 
		CASE WHEN PARAM_ORDER_FIELD = 'REC_USER_LAST_NAME' AND PARAM_ORDER_TYPE = 'DESC' THEN `record_user`.`REC_USER_LAST_NAME` END DESC,
		CASE WHEN PARAM_ORDER_FIELD = 'REC_USER_SUFFIX' AND PARAM_ORDER_TYPE = 'ASC' THEN `record_user`.`REC_USER_SUFFIX` END ASC, 
		CASE WHEN PARAM_ORDER_FIELD = 'REC_USER_SUFFIX' AND PARAM_ORDER_TYPE = 'DESC' THEN `record_user`.`REC_USER_SUFFIX` END DESC,
		CASE WHEN PARAM_ORDER_FIELD = 'REC_USER_SYS_GENDER_ID' AND PARAM_ORDER_TYPE = 'ASC' THEN `record_user`.`REC_USER_SYS_GENDER_ID` END ASC, 
		CASE WHEN PARAM_ORDER_FIELD = 'REC_USER_SYS_GENDER_ID' AND PARAM_ORDER_TYPE = 'DESC' THEN `record_user`.`REC_USER_SYS_GENDER_ID` END DESC,
		CASE WHEN PARAM_ORDER_FIELD = 'REC_USER_NOTIFY_PHONE' AND PARAM_ORDER_TYPE = 'ASC' THEN `record_user`.`REC_USER_NOTIFY_PHONE` END ASC, 
		CASE WHEN PARAM_ORDER_FIELD = 'REC_USER_NOTIFY_PHONE' AND PARAM_ORDER_TYPE = 'DESC' THEN `record_user`.`REC_USER_NOTIFY_PHONE` END DESC,
		CASE WHEN PARAM_ORDER_FIELD = 'REC_USER_EMCONTACT_PERSON' AND PARAM_ORDER_TYPE = 'ASC' THEN `record_user`.`REC_USER_EMCONTACT_PERSON` END ASC, 
		CASE WHEN PARAM_ORDER_FIELD = 'REC_USER_EMCONTACT_PERSON' AND PARAM_ORDER_TYPE = 'DESC' THEN `record_user`.`REC_USER_EMCONTACT_PERSON` END DESC,
		CASE WHEN PARAM_ORDER_FIELD = 'REC_USER_EMCONTACT_NUMBER' AND PARAM_ORDER_TYPE = 'ASC' THEN `record_user`.`REC_USER_EMCONTACT_NUMBER` END ASC, 
		CASE WHEN PARAM_ORDER_FIELD = 'REC_USER_EMCONTACT_NUMBER' AND PARAM_ORDER_TYPE = 'DESC' THEN `record_user`.`REC_USER_EMCONTACT_NUMBER` END DESC,
		CASE WHEN PARAM_ORDER_FIELD = 'REC_USER_STATUS' AND PARAM_ORDER_TYPE = 'ASC' THEN `record_user`.`REC_USER_STATUS` END ASC, 
		CASE WHEN PARAM_ORDER_FIELD = 'REC_USER_STATUS' AND PARAM_ORDER_TYPE = 'DESC' THEN `record_user`.`REC_USER_STATUS` END DESC,
		
		-- EXTRA
		CASE WHEN PARAM_ORDER_FIELD <> 'REC_ATTENDANCE_DATE' THEN `record_attendance`.`REC_ATTENDANCE_DATE` END DESC
		
	-- LIMIT & OFFSET
	-- ####################################################		
	LIMIT PARAM_SKIP, PARAM_LIMIT;
	
	
	
	-- EXIT PROCEDURE
	-- =========================================================================================
	LEAVE SP_GET;
			
END ;;
DELIMITER ;
/*!50003 SET sql_mode              = @saved_sql_mode */ ;
/*!50003 SET character_set_client  = @saved_cs_client */ ;
/*!50003 SET character_set_results = @saved_cs_results */ ;
/*!50003 SET collation_connection  = @saved_col_connection */ ;
/*!50003 DROP PROCEDURE IF EXISTS `RECORD_ATTENDANCE_PASS` */;
/*!50003 SET @saved_cs_client      = @@character_set_client */ ;
/*!50003 SET @saved_cs_results     = @@character_set_results */ ;
/*!50003 SET @saved_col_connection = @@collation_connection */ ;
/*!50003 SET character_set_client  = latin1 */ ;
/*!50003 SET character_set_results = latin1 */ ;
/*!50003 SET collation_connection  = latin1_swedish_ci */ ;
/*!50003 SET @saved_sql_mode       = @@sql_mode */ ;
/*!50003 SET sql_mode              = '' */ ;
DELIMITER ;;
CREATE DEFINER=`root`@`localhost` PROCEDURE `RECORD_ATTENDANCE_PASS`(
	IN `PARAM_CAT_ENTRANCE_ID` BIGINT,
	IN `PARAM_REC_USER_UNIQUE_CODE` VARCHAR(400),
	IN `PARAM_REC_ATTENDANCE_DEVICE_KEY` VARCHAR(4000),

	IN `PARAM_REQUESTER_USERNAME` VARCHAR(500),
	IN `PARAM_REQUESTER_PASSWORD` VARCHAR(500),
	IN `PARAM_REQUESTER_PROXY_ID` BIGINT,
	IN `PARAM_REQUESTER_PROXY_PASSWORD` VARCHAR(1000),
	IN `PARAM_REQUESTER_DEVICE_PUBLIC_KEY` VARCHAR(1000),
	IN `PARAM_REQUESTER_DEVICE_PRIVATE_KEY` VARCHAR(1000),
	
	IN `PARAM_REQUESTER_IP` VARCHAR(1000),
	IN `PARAM_UNIQUE_SESSION_ID` VARCHAR(1000),
	IN `PARAM_SUPPRESS_RETURN` BIT,
	
	IN `PARAM_SYNC_SERVER_DESCRIPTION` VARCHAR(500), 
	IN `PARAM_SYNC_SERVER_UNIQUE_KEY` VARCHAR(500)
)
SP_SAVE:
BEGIN


	-- 1) DECLARE LOCAL PARAMETERS
	-- _______________________________________________________________________
	
	-- Status
	-- ...........................................
	DECLARE STATUS_INACTIVE TINYINT DEFAULT 1;
	DECLARE STATUS_ACTIVE TINYINT DEFAULT 2;
	DECLARE STATUS_CLOSED TINYINT DEFAULT 3;
	DECLARE STATUS_COMPLETED TINYINT DEFAULT 4;

	-- Audit Handler
	-- ...........................................
	DECLARE TEMP_RECORD_EXISTS BIT DEFAULT 0;
	DECLARE TEMP_MODULE_KEYWORD VARCHAR(500) DEFAULT 'record_attendance';
	DECLARE TEMP_SP_OBJECTIVE VARCHAR(500) DEFAULT 'add/edit Attendance record';
	DECLARE TEMP_ERR_MESSAGE VARCHAR(500) DEFAULT '';
	DECLARE ERR BIGINT DEFAULT 0;
	DECLARE TEMP_RECORD_CHANGES VARCHAR(16000) DEFAULT '';
	DECLARE TEMP_RECORD_BINDED BIT DEFAULT 0;

	-- Authentication
	-- ...........................................
	DECLARE TEMP_ACCESS_RIGHTS_DENIED BIT DEFAULT 0;
	DECLARE TEMP_ACCESS_RIGHTS_HAS_OVERRIDE BIT DEFAULT 0;
	DECLARE TEMP_SYNC_SERVER_ID BIGINT DEFAULT 0;
	DECLARE TEMP_SYNC_IS_SERVER_REQUEST BIT DEFAULT 0;
	DECLARE TEMP_AUTHENTICATED_ACCOUNT_ID BIGINT DEFAULT `ACCOUNT_MEMBER@ACC_ACCOUNT_ID_FROM_LOGIN`(PARAM_REQUESTER_USERNAME, PARAM_REQUESTER_PASSWORD);
	DECLARE TEMP_AUTHENTICATED_ACCOUNT_LEVEL BIGINT DEFAULT 0;
	DECLARE TEMP_AUTHENTICATED_ACCOUNT_GROUP BIGINT DEFAULT 0;
	
	-- Local Parameters
	-- ...........................................
	DECLARE TEMP_NOW DATETIME(6) DEFAULT `SYSTEM_VAR@NOW`('', 1);
	DECLARE TEMP_RECORD_COUNT BIGINT DEFAULT 0;

	-- AutoGen Parameters
	-- ...........................................
	DECLARE PARAM_REC_ATTENDANCE_DATE DATETIME(6) DEFAULT '1000-01-01 00:00:00.000000'; 
	
	-- Local value holder
	-- ...........................................
	DECLARE TEMP_REC_ATTENDANCE_REC_USER_ID BIGINT DEFAULT 0; 
	DECLARE TEMP_REC_ATTENDANCE_DATE DATETIME(6) DEFAULT '1000-01-01 00:00:00.000000'; 
	DECLARE TEMP_REC_ATTENDANCE_IS_IN TINYINT DEFAULT 0; 
	DECLARE TEMP_REC_ATTENDANCE_IS_OUT TINYINT DEFAULT 0; 
	DECLARE TEMP_REC_ATTENDANCE_ENTRANCE VARCHAR(400) DEFAULT ''; 
	DECLARE TEMP_REC_ATTENDANCE_DEVICE_KEY VARCHAR(4000) DEFAULT ''; 
	DECLARE TEMP_REC_ATTENDANCE_STATUS TINYINT DEFAULT 0; 
	
	DECLARE REDUND_REC_ATTENDANCE_ID BIGINT DEFAULT 0; 

	DECLARE TEMP_CAT_ENTRANCE_DIRECTION BIGINT DEFAULT 0; 
	DECLARE PARAM_REC_ATTENDANCE_REC_USER_ID BIGINT DEFAULT 0;
	DECLARE PARAM_REC_ATTENDANCE_IS_IN TINYINT DEFAULT 0;
	DECLARE PARAM_REC_ATTENDANCE_IS_OUT TINYINT DEFAULT 0;
	DECLARE PARAM_REC_ATTENDANCE_ENTRANCE VARCHAR(400) DEFAULT ''; 
	

	-- 2) Try Catch / Throw
	-- _______________________________________________________________________
	DECLARE EXIT HANDLER FOR SQLEXCEPTION
	BEGIN
		RESIGNAL;
	END;


	-- 7) VALIDATE
	-- _______________________________________________________________________

	-- Access Rights [Device]
	-- ####################################################
	IF `ACCOUNT_DEVICE@HAS_PERMISSION`(PARAM_REQUESTER_DEVICE_PUBLIC_KEY, PARAM_REQUESTER_DEVICE_PRIVATE_KEY) = 0 THEN
		SET TEMP_ERR_MESSAGE = 'Your device is not authorized yet to access this server.';
		SET ERR = `RAISERROR`(TEMP_ERR_MESSAGE);		
	END IF;
		
		
	-- Access Rights [Account]
	-- ####################################################
	
	IF 
		-- [ADD] Access Rights
		(
			TEMP_RECORD_EXISTS = 0 AND
			`ACCOUNT_ACCESS_RIGHTS@HAS_PERMISSION`(PARAM_REQUESTER_USERNAME, PARAM_REQUESTER_PASSWORD, 0, TEMP_MODULE_KEYWORD, 2) = 0 AND
			`ACCOUNT_ACCESS_RIGHTS@PROXY_PERMISSION`(PARAM_REQUESTER_PROXY_ID, PARAM_REQUESTER_PROXY_PASSWORD, 0, TEMP_MODULE_KEYWORD, 2) = 0
		) OR
		
		-- [EDIT] Access Rights
		(
			TEMP_RECORD_EXISTS = 1 AND
			`ACCOUNT_ACCESS_RIGHTS@HAS_PERMISSION`(PARAM_REQUESTER_USERNAME, PARAM_REQUESTER_PASSWORD, 0, TEMP_MODULE_KEYWORD, 3) = 0 AND
			`ACCOUNT_ACCESS_RIGHTS@PROXY_PERMISSION`(PARAM_REQUESTER_PROXY_ID, PARAM_REQUESTER_PROXY_PASSWORD, 0, TEMP_MODULE_KEYWORD, 3) = 0
		)
	THEN
		SET TEMP_ACCESS_RIGHTS_DENIED = 1;
		CALL `ACCOUNT_ACCESS_RIGHTS_DENY`
		(
			0, TEMP_MODULE_KEYWORD, PARAM_REC_ATTENDANCE_ID, 0, TEMP_SP_OBJECTIVE, TEMP_RECORD_CHANGES, 
			PARAM_REQUESTER_USERNAME, PARAM_REQUESTER_PASSWORD, 
			PARAM_REQUESTER_PROXY_ID, PARAM_REQUESTER_PROXY_PASSWORD,
			PARAM_REQUESTER_DEVICE_PUBLIC_KEY, PARAM_REQUESTER_DEVICE_PRIVATE_KEY,
			PARAM_REQUESTER_IP, PARAM_UNIQUE_SESSION_ID,
			TEMP_SYNC_SERVER_ID, PARAM_SUPPRESS_RETURN
		);
	END IF;
	SET TEMP_ACCESS_RIGHTS_HAS_OVERRIDE = `ACCOUNT_ACCESS_RIGHTS@HAS_PERMISSION`(PARAM_REQUESTER_USERNAME, PARAM_REQUESTER_PASSWORD, 0, TEMP_MODULE_KEYWORD, 4);
	

	-- Validation
	-- _______________________________________________________________________

	
	-- Get USER_ID
	-- ####################################################
	IF
	(
		SELECT COUNT(`record_user`.`REC_USER_ID`)
		FROM `record_user`
		WHERE
			`record_user`.`REC_USER_UNIQUE_CODE` = PARAM_REC_USER_UNIQUE_CODE AND
			`record_user`.`REC_USER_STATUS` = STATUS_ACTIVE
	) <= 0
	THEN
		SET ERR = `RAISERROR`('Invalid User.');
	END IF;
	
	SELECT `record_user`.`REC_USER_ID`
	INTO PARAM_REC_ATTENDANCE_REC_USER_ID 
	FROM `record_user`
	WHERE
		`record_user`.`REC_USER_UNIQUE_CODE` = PARAM_REC_USER_UNIQUE_CODE AND
		`record_user`.`REC_USER_STATUS` = STATUS_ACTIVE
	LIMIT 1;


	-- Get Entrance Data
	-- ####################################################
	IF
	(
		SELECT COUNT(`category_entrance`.`CAT_ENTRANCE_DESCRIPTION`)
	
	FROM `category_entrance`
	
	WHERE
	
		`category_entrance`.`CAT_ENTRANCE_ID` = PARAM_CAT_ENTRANCE_ID
	) <= 0	
	THEN
		SET ERR = `RAISERROR`('Invalid Entrance.');
	END IF;

	SELECT
		`category_entrance`.`CAT_ENTRANCE_DESCRIPTION`,
		`category_entrance`.`CAT_ENTRANCE_DIRECTION`
	INTO
		PARAM_REC_ATTENDANCE_ENTRANCE,
		TEMP_CAT_ENTRANCE_DIRECTION
	FROM `category_entrance`
	WHERE
		`category_entrance`.`CAT_ENTRANCE_ID` = PARAM_CAT_ENTRANCE_ID
	LIMIT 1;

	 
	-- OUT
	IF TEMP_CAT_ENTRANCE_DIRECTION = STATUS_INACTIVE THEN
		SET PARAM_REC_ATTENDANCE_IS_IN = STATUS_INACTIVE;
		SET PARAM_REC_ATTENDANCE_IS_OUT = STATUS_ACTIVE;	
		
	-- IN
	ELSEIF TEMP_CAT_ENTRANCE_DIRECTION = STATUS_ACTIVE THEN
		SET PARAM_REC_ATTENDANCE_IS_IN = STATUS_ACTIVE;
		SET PARAM_REC_ATTENDANCE_IS_OUT = STATUS_INACTIVE;
		
	-- BOTH
	ELSEIF TEMP_CAT_ENTRANCE_DIRECTION = STATUS_CLOSED THEN
	
		-- Initialize
		SET TEMP_REC_ATTENDANCE_IS_IN = STATUS_INACTIVE;
		SET TEMP_REC_ATTENDANCE_DATE = DATE_SUB(TEMP_NOW, INTERVAL 24 HOUR);
		
		-- Get Prev Entrance History, within 24hrs
		IF
		(
			SELECT COUNT(`record_attendance`.`REC_ATTENDANCE_IS_IN`)
			FROM `record_attendance`
			WHERE
				`record_attendance`.`REC_ATTENDANCE_REC_USER_ID` = PARAM_REC_ATTENDANCE_REC_USER_ID AND
				`record_attendance`.`REC_ATTENDANCE_DATE` >= TEMP_REC_ATTENDANCE_DATE
		) >= 1
		THEN
			SELECT 
				`record_attendance`.`REC_ATTENDANCE_IS_IN`
			INTO
				TEMP_REC_ATTENDANCE_IS_IN
			FROM `record_attendance`
			WHERE
				`record_attendance`.`REC_ATTENDANCE_REC_USER_ID` = PARAM_REC_ATTENDANCE_REC_USER_ID AND
				`record_attendance`.`REC_ATTENDANCE_DATE` >= TEMP_REC_ATTENDANCE_DATE
			ORDER BY `record_attendance`.`REC_ATTENDANCE_DATE` DESC 
			LIMIT 1;
		END IF;
		
		-- Set Value
		IF TEMP_REC_ATTENDANCE_IS_IN = STATUS_INACTIVE THEN
			SET PARAM_REC_ATTENDANCE_IS_IN = STATUS_ACTIVE;
			SET PARAM_REC_ATTENDANCE_IS_OUT = STATUS_INACTIVE;			
		ELSEIF TEMP_REC_ATTENDANCE_IS_IN = STATUS_ACTIVE THEN
			SET PARAM_REC_ATTENDANCE_IS_IN = STATUS_INACTIVE;
			SET PARAM_REC_ATTENDANCE_IS_OUT = STATUS_ACTIVE;	
		END IF;
	
	ELSE
		SET ERR = `RAISERROR`('Invalid Entrance Settings.');
	END IF;
	

	-- Save Attendance Info
	-- ####################################################
	CALL `RECORD_ATTENDANCE_SAVE`
	(
		-1,
		PARAM_REC_ATTENDANCE_REC_USER_ID,
		PARAM_REC_ATTENDANCE_IS_IN,
		PARAM_REC_ATTENDANCE_IS_OUT,
		PARAM_REC_ATTENDANCE_ENTRANCE,
		PARAM_REC_ATTENDANCE_DEVICE_KEY,
		STATUS_ACTIVE,

		PARAM_REQUESTER_USERNAME,
		PARAM_REQUESTER_PASSWORD,
		PARAM_REQUESTER_PROXY_ID,
		PARAM_REQUESTER_PROXY_PASSWORD,
		PARAM_REQUESTER_DEVICE_PUBLIC_KEY,
		PARAM_REQUESTER_DEVICE_PRIVATE_KEY,
		
		PARAM_REQUESTER_IP,
		PARAM_UNIQUE_SESSION_ID,
		1,
		
		PARAM_SYNC_SERVER_DESCRIPTION, 
		PARAM_SYNC_SERVER_UNIQUE_KEY
	);
	
	
	-- FETCH COLUMNS
	-- ####################################################
	SELECT
		-- RECORD_USER DETAILS
		`record_user`.`REC_USER_ID`, 
		`record_user`.`REC_USER_CAT_DEPARTMENT_ID`, 
		`record_user`.`REC_USER_CAT_SECTION_ID`, 
		`record_user`.`REC_USER_UNIQUE_CODE`, 

		CONCAT_WS
		(
			' ',
			`record_user`.`REC_USER_LAST_NAME`, ',',
			`record_user`.`REC_USER_FIRST_NAME`,
			`record_user`.`REC_USER_MIDDLE_NAME`,
			`record_user`.`REC_USER_SUFFIX`
		) AS REC_USER_NAME,

		`record_user`.`REC_USER_FIRST_NAME`, 
		`record_user`.`REC_USER_MIDDLE_NAME`, 
		`record_user`.`REC_USER_LAST_NAME`, 
		`record_user`.`REC_USER_SUFFIX`, 
		`record_user`.`REC_USER_SYS_GENDER_ID`, 
		`record_user`.`REC_USER_NOTIFY_PHONE`, 
		`record_user`.`REC_USER_EMCONTACT_PERSON`, 
		`record_user`.`REC_USER_EMCONTACT_NUMBER`, 
		`record_user`.`REC_USER_STATUS`,
		
		-- In/Out
		IF(PARAM_REC_ATTENDANCE_IS_IN = STATUS_ACTIVE, 'In', 'Out') AS REC_ATTENDANCE_DIRECTION,
		PARAM_REC_ATTENDANCE_IS_IN AS REC_ATTENDANCE_IS_IN,
		PARAM_REC_ATTENDANCE_IS_OUT AS REC_ATTENDANCE_IS_OUT,	
		
		-- Inner join fields
		`category_department`.`CAT_DEPARTMENT_ID`,	
		`category_department`.`CAT_DEPARTMENT_DESCRIPTION` AS REC_USER_CAT_DEPARTMENT_ID_DESCRIPTION,
		`category_department`.`CAT_DEPARTMENT_DESCRIPTION`,	
		`category_department`.`CAT_DEPARTMENT_STATUS`,	

		`category_section`.`CAT_SECTION_ID`,	
		`category_section`.`CAT_SECTION_CAT_DEPARTMENT_ID`,	
		`category_section`.`CAT_SECTION_DESCRIPTION` AS REC_USER_CAT_SECTION_ID_DESCRIPTION,
		`category_section`.`CAT_SECTION_DESCRIPTION`,	
		`category_section`.`CAT_SECTION_STATUS`,	

		`system_gender`.`SYS_GENDER_ID`,	
		`system_gender`.`SYS_GENDER_CODE`,	
		`system_gender`.`SYS_GENDER_DESCRIPTION` AS REC_USER_SYS_GENDER_ID_DESCRIPTION,
		`system_gender`.`SYS_GENDER_DESCRIPTION`,	
		`system_gender`.`SYS_GENDER_STATUS`,
		
		-- Left join fields
		PARAM_REC_ATTENDANCE_ENTRANCE AS REC_ATTENDANCE_ENTRANCE,
		TEMP_NOW AS SERVER_TIME,
		TEMP_RECORD_COUNT AS RECORD_COUNT

	FROM `record_user`
	
		-- Add Inner Joins (Per Foreign-key)
		INNER JOIN `category_department` ON
		`category_department`.`CAT_DEPARTMENT_ID` = `record_user`.`REC_USER_CAT_DEPARTMENT_ID`
			
		-- ~~~~~	
			
		INNER JOIN `category_section` ON
		`category_section`.`CAT_SECTION_ID` = `record_user`.`REC_USER_CAT_SECTION_ID`
			
		-- ~~~~~	
			
		INNER JOIN `system_gender` ON
		`system_gender`.`SYS_GENDER_ID` = `record_user`.`REC_USER_SYS_GENDER_ID`
			
	-- CONDITIONS
	-- ####################################################
	WHERE
		`record_user`.`REC_USER_ID` = PARAM_REC_ATTENDANCE_REC_USER_ID	
	LIMIT 1;


	-- Handle auto in/out entrance (inout = 3)
	-- ####################################################
	LEAVE SP_SAVE;

END ;;
DELIMITER ;
/*!50003 SET sql_mode              = @saved_sql_mode */ ;
/*!50003 SET character_set_client  = @saved_cs_client */ ;
/*!50003 SET character_set_results = @saved_cs_results */ ;
/*!50003 SET collation_connection  = @saved_col_connection */ ;
/*!50003 DROP PROCEDURE IF EXISTS `RECORD_ATTENDANCE_SAVE` */;
/*!50003 SET @saved_cs_client      = @@character_set_client */ ;
/*!50003 SET @saved_cs_results     = @@character_set_results */ ;
/*!50003 SET @saved_col_connection = @@collation_connection */ ;
/*!50003 SET character_set_client  = latin1 */ ;
/*!50003 SET character_set_results = latin1 */ ;
/*!50003 SET collation_connection  = latin1_swedish_ci */ ;
/*!50003 SET @saved_sql_mode       = @@sql_mode */ ;
/*!50003 SET sql_mode              = '' */ ;
DELIMITER ;;
CREATE DEFINER=`root`@`localhost` PROCEDURE `RECORD_ATTENDANCE_SAVE`(
	IN `PARAM_REC_ATTENDANCE_ID` BIGINT,
	IN `PARAM_REC_ATTENDANCE_REC_USER_ID` BIGINT,
	IN `PARAM_REC_ATTENDANCE_IS_IN` TINYINT,
	IN `PARAM_REC_ATTENDANCE_IS_OUT` TINYINT,
	IN `PARAM_REC_ATTENDANCE_ENTRANCE` VARCHAR(400),
	IN `PARAM_REC_ATTENDANCE_DEVICE_KEY` VARCHAR(4000),
	IN `PARAM_REC_ATTENDANCE_STATUS` TINYINT,

	IN `PARAM_REQUESTER_USERNAME` VARCHAR(500),
	IN `PARAM_REQUESTER_PASSWORD` VARCHAR(500),
	IN `PARAM_REQUESTER_PROXY_ID` BIGINT,
	IN `PARAM_REQUESTER_PROXY_PASSWORD` VARCHAR(1000),
	IN `PARAM_REQUESTER_DEVICE_PUBLIC_KEY` VARCHAR(1000),
	IN `PARAM_REQUESTER_DEVICE_PRIVATE_KEY` VARCHAR(1000),
	
	IN `PARAM_REQUESTER_IP` VARCHAR(1000),
	IN `PARAM_UNIQUE_SESSION_ID` VARCHAR(1000),
	IN `PARAM_SUPPRESS_RETURN` BIT,
	
	IN `PARAM_SYNC_SERVER_DESCRIPTION` VARCHAR(500), 
	IN `PARAM_SYNC_SERVER_UNIQUE_KEY` VARCHAR(500)
)
SP_SAVE:
BEGIN


	-- 1) DECLARE LOCAL PARAMETERS
	-- _______________________________________________________________________
	
	-- Status
	-- ...........................................
	DECLARE STATUS_INACTIVE TINYINT DEFAULT 1;
	DECLARE STATUS_ACTIVE TINYINT DEFAULT 2;
	DECLARE STATUS_CLOSED TINYINT DEFAULT 3;
	DECLARE STATUS_COMPLETED TINYINT DEFAULT 4;

	-- Audit Handler
	-- ...........................................
	DECLARE TEMP_RECORD_EXISTS BIT DEFAULT 0;
	DECLARE TEMP_MODULE_KEYWORD VARCHAR(500) DEFAULT 'record_attendance';
	DECLARE TEMP_SP_OBJECTIVE VARCHAR(500) DEFAULT 'add/edit Attendance record';
	DECLARE TEMP_ERR_MESSAGE VARCHAR(500) DEFAULT '';
	DECLARE ERR BIGINT DEFAULT 0;
	DECLARE TEMP_RECORD_CHANGES VARCHAR(16000) DEFAULT '';
	DECLARE TEMP_RECORD_BINDED BIT DEFAULT 0;

	-- Authentication
	-- ...........................................
	DECLARE TEMP_ACCESS_RIGHTS_DENIED BIT DEFAULT 0;
	DECLARE TEMP_ACCESS_RIGHTS_HAS_OVERRIDE BIT DEFAULT 0;
	DECLARE TEMP_SYNC_SERVER_ID BIGINT DEFAULT 0;
	DECLARE TEMP_SYNC_IS_SERVER_REQUEST BIT DEFAULT 0;
	DECLARE TEMP_AUTHENTICATED_ACCOUNT_ID BIGINT DEFAULT `ACCOUNT_MEMBER@ACC_ACCOUNT_ID_FROM_LOGIN`(PARAM_REQUESTER_USERNAME, PARAM_REQUESTER_PASSWORD);
	DECLARE TEMP_AUTHENTICATED_ACCOUNT_LEVEL BIGINT DEFAULT 0;
	DECLARE TEMP_AUTHENTICATED_ACCOUNT_GROUP BIGINT DEFAULT 0;
	
	-- Local Parameters
	-- ...........................................
	DECLARE TEMP_NOW DATETIME(6) DEFAULT `SYSTEM_VAR@NOW`('', 1);
	DECLARE TEMP_RECORD_COUNT BIGINT DEFAULT 0;

	-- AutoGen Parameters
	-- ...........................................
	DECLARE PARAM_REC_ATTENDANCE_DATE DATETIME(6) DEFAULT '1000-01-01 00:00:00.000000'; 
	
	-- Local value holder
	-- ...........................................
	DECLARE TEMP_REC_ATTENDANCE_REC_USER_ID BIGINT DEFAULT 0; 
	DECLARE TEMP_REC_ATTENDANCE_DATE DATETIME(6) DEFAULT '1000-01-01 00:00:00.000000'; 
	DECLARE TEMP_REC_ATTENDANCE_IS_IN TINYINT DEFAULT 0; 
	DECLARE TEMP_REC_ATTENDANCE_IS_OUT TINYINT DEFAULT 0; 
	DECLARE TEMP_REC_ATTENDANCE_ENTRANCE VARCHAR(400) DEFAULT ''; 
	DECLARE TEMP_REC_ATTENDANCE_DEVICE_KEY VARCHAR(4000) DEFAULT ''; 
	DECLARE TEMP_REC_ATTENDANCE_STATUS TINYINT DEFAULT 0; 
	
	DECLARE REDUND_REC_ATTENDANCE_ID BIGINT DEFAULT 0; 


	-- 2) Try Catch / Throw
	-- _______________________________________________________________________
	DECLARE EXIT HANDLER FOR SQLEXCEPTION
	BEGIN
		RESIGNAL;
	END;



	-- 3) Prepare SYNC
	-- _______________________________________________________________________

	-- IS RECORD EXISTS		
	-- ####################################################	
	SET TEMP_RECORD_EXISTS = `RECORD_ATTENDANCE@REC_ATTENDANCE_ID_EXISTS`(PARAM_REC_ATTENDANCE_ID, 0);

		
		
	-- 4) PREPARE AUTOGEN DATA (IF EXISTS)
	-- _______________________________________________________________________
	IF TEMP_SYNC_IS_SERVER_REQUEST = 0 THEN
		-- Just to keep at least one line within condition
		SET TEMP_SYNC_IS_SERVER_REQUEST = 0;
		
		-- Actual Functionalities here
		-- USE DEFAULT VALUE (String)
		-- USE DEFAULT VALUE (String)
		SET PARAM_REC_ATTENDANCE_DATE = TEMP_NOW;
	-- USE CURRENT USER
	END IF;



	-- 5) IF ALREADY EXIST, FILL MISSING DATA
	-- _______________________________________________________________________
	IF TEMP_RECORD_EXISTS = 1 THEN
		SELECT
			`record_attendance`.`REC_ATTENDANCE_REC_USER_ID`, 	
			`record_attendance`.`REC_ATTENDANCE_DATE`, 	
			`record_attendance`.`REC_ATTENDANCE_IS_IN`, 	
			`record_attendance`.`REC_ATTENDANCE_IS_OUT`, 	
			`record_attendance`.`REC_ATTENDANCE_ENTRANCE`, 	
			`record_attendance`.`REC_ATTENDANCE_DEVICE_KEY`, 	
			`record_attendance`.`REC_ATTENDANCE_STATUS`	
		INTO
			TEMP_REC_ATTENDANCE_REC_USER_ID, 	
			TEMP_REC_ATTENDANCE_DATE, 	
			TEMP_REC_ATTENDANCE_IS_IN, 	
			TEMP_REC_ATTENDANCE_IS_OUT, 	
			TEMP_REC_ATTENDANCE_ENTRANCE, 	
			TEMP_REC_ATTENDANCE_DEVICE_KEY, 	
			TEMP_REC_ATTENDANCE_STATUS	

		FROM `record_attendance`
		WHERE
			`record_attendance`.`REC_ATTENDANCE_ID` = PARAM_REC_ATTENDANCE_ID
		LIMIT 1;

		-- Replace NULLs with the existing data.
		SET PARAM_REC_ATTENDANCE_IS_IN = `SYSTEM_VAR@REPLACE_NULL@TINYINT`(PARAM_REC_ATTENDANCE_IS_IN, TEMP_REC_ATTENDANCE_IS_IN, 1, 1);
		SET PARAM_REC_ATTENDANCE_IS_OUT = `SYSTEM_VAR@REPLACE_NULL@TINYINT`(PARAM_REC_ATTENDANCE_IS_OUT, TEMP_REC_ATTENDANCE_IS_OUT, 1, 1);
		SET PARAM_REC_ATTENDANCE_ENTRANCE = `SYSTEM_VAR@REPLACE_NULL@NVARCHAR`(PARAM_REC_ATTENDANCE_ENTRANCE, TEMP_REC_ATTENDANCE_ENTRANCE, 1);
		SET PARAM_REC_ATTENDANCE_DEVICE_KEY = `SYSTEM_VAR@REPLACE_NULL@NVARCHAR`(PARAM_REC_ATTENDANCE_DEVICE_KEY, TEMP_REC_ATTENDANCE_DEVICE_KEY, 1);
		SET PARAM_REC_ATTENDANCE_STATUS = `SYSTEM_VAR@REPLACE_NULL@TINYINT`(PARAM_REC_ATTENDANCE_STATUS, TEMP_REC_ATTENDANCE_STATUS, 1, 1);
		
		-- AUTO GEN (NON-UPDATABLES)		
		SET PARAM_REC_ATTENDANCE_DATE = TEMP_REC_ATTENDANCE_DATE;
		
		-- AUTO GEN (UPDATABLE WITH STATUS CHANGE)

		-- AUTO GEN (UPDATABLE WITH STATUS [ACTIVE/INACTIVE] CHANGE)
		
		-- NON-UPDATABLE
		SET PARAM_REC_ATTENDANCE_REC_USER_ID = TEMP_REC_ATTENDANCE_REC_USER_ID;
		SET PARAM_REC_ATTENDANCE_DATE = TEMP_REC_ATTENDANCE_DATE;
		
		-- NON-UPDATABLE BUT NULL
		
	ELSE
		SET PARAM_REC_ATTENDANCE_REC_USER_ID = `SYSTEM_VAR@REPLACE_NULL@BIGINT`(PARAM_REC_ATTENDANCE_REC_USER_ID, 0, 1, 1);
		SET PARAM_REC_ATTENDANCE_IS_IN = `SYSTEM_VAR@REPLACE_NULL@TINYINT`(PARAM_REC_ATTENDANCE_IS_IN, 0, 1, 1);
		SET PARAM_REC_ATTENDANCE_IS_OUT = `SYSTEM_VAR@REPLACE_NULL@TINYINT`(PARAM_REC_ATTENDANCE_IS_OUT, 0, 1, 1);
		SET PARAM_REC_ATTENDANCE_ENTRANCE = `SYSTEM_VAR@REPLACE_NULL@NVARCHAR`(PARAM_REC_ATTENDANCE_ENTRANCE, '', 1);
		SET PARAM_REC_ATTENDANCE_DEVICE_KEY = `SYSTEM_VAR@REPLACE_NULL@NVARCHAR`(PARAM_REC_ATTENDANCE_DEVICE_KEY, '', 1);
		SET PARAM_REC_ATTENDANCE_STATUS = `SYSTEM_VAR@REPLACE_NULL@TINYINT`(PARAM_REC_ATTENDANCE_STATUS, 0, 1, 1);
		
	END IF;

	

	-- 6) PREPARE AUDIT TRAIL
	-- _______________________________________________________________________
	IF TEMP_REC_ATTENDANCE_REC_USER_ID <> PARAM_REC_ATTENDANCE_REC_USER_ID THEN
		SET TEMP_RECORD_CHANGES = 
		`SYSTEM_VAR@CONCAT_ADD`(' | ', TEMP_RECORD_CHANGES, CONCAT_WS(' ', 'User: "', TEMP_REC_ATTENDANCE_REC_USER_ID, '" > "', PARAM_REC_ATTENDANCE_REC_USER_ID, '"'));
	END IF;	
	IF BINARY TEMP_REC_ATTENDANCE_DATE <> PARAM_REC_ATTENDANCE_DATE THEN
		SET TEMP_RECORD_CHANGES = 
		`SYSTEM_VAR@CONCAT_ADD`(' | ', TEMP_RECORD_CHANGES, CONCAT_WS(' ', 'Date: "', TEMP_REC_ATTENDANCE_DATE, '" > "', PARAM_REC_ATTENDANCE_DATE, '"'));
	END IF;
	IF TEMP_REC_ATTENDANCE_IS_IN <> PARAM_REC_ATTENDANCE_IS_IN THEN
		SET TEMP_RECORD_CHANGES = 
		`SYSTEM_VAR@CONCAT_ADD`(' | ', TEMP_RECORD_CHANGES, CONCAT_WS(' ', 'In: "', TEMP_REC_ATTENDANCE_IS_IN, '" > "', PARAM_REC_ATTENDANCE_IS_IN, '"'));
	END IF;	
	IF TEMP_REC_ATTENDANCE_IS_OUT <> PARAM_REC_ATTENDANCE_IS_OUT THEN
		SET TEMP_RECORD_CHANGES = 
		`SYSTEM_VAR@CONCAT_ADD`(' | ', TEMP_RECORD_CHANGES, CONCAT_WS(' ', 'Out: "', TEMP_REC_ATTENDANCE_IS_OUT, '" > "', PARAM_REC_ATTENDANCE_IS_OUT, '"'));
	END IF;	
	IF BINARY TEMP_REC_ATTENDANCE_ENTRANCE <> PARAM_REC_ATTENDANCE_ENTRANCE THEN
		SET TEMP_RECORD_CHANGES = 
		`SYSTEM_VAR@CONCAT_ADD`(' | ', TEMP_RECORD_CHANGES, CONCAT_WS(' ', 'Entrance: "', TEMP_REC_ATTENDANCE_ENTRANCE, '" > "', PARAM_REC_ATTENDANCE_ENTRANCE, '"'));
	END IF;
	IF BINARY TEMP_REC_ATTENDANCE_DEVICE_KEY <> PARAM_REC_ATTENDANCE_DEVICE_KEY THEN
		SET TEMP_RECORD_CHANGES = 
		`SYSTEM_VAR@CONCAT_ADD`(' | ', TEMP_RECORD_CHANGES, CONCAT_WS(' ', 'Device Key: "', TEMP_REC_ATTENDANCE_DEVICE_KEY, '" > "', PARAM_REC_ATTENDANCE_DEVICE_KEY, '"'));
	END IF;
	IF TEMP_REC_ATTENDANCE_STATUS <> PARAM_REC_ATTENDANCE_STATUS THEN
		SET TEMP_RECORD_CHANGES = 
		`SYSTEM_VAR@CONCAT_ADD`(' | ', TEMP_RECORD_CHANGES, CONCAT_WS(' ', 'Status: "', TEMP_REC_ATTENDANCE_STATUS, '" > "', PARAM_REC_ATTENDANCE_STATUS, '"'));
	END IF;	
		
	-- No Changes in data, reject request
	-- ####################################################
	IF CHARACTER_LENGTH(TEMP_RECORD_CHANGES) = 0 THEN
		IF PARAM_SUPPRESS_RETURN = 0 THEN
			SELECT PARAM_REC_ATTENDANCE_ID AS INSERTED_ID;
		END IF;
		LEAVE SP_SAVE;
	END IF;



	-- 7) VALIDATE
	-- _______________________________________________________________________

	-- Access Rights [Device]
	-- ####################################################
	IF `ACCOUNT_DEVICE@HAS_PERMISSION`(PARAM_REQUESTER_DEVICE_PUBLIC_KEY, PARAM_REQUESTER_DEVICE_PRIVATE_KEY) = 0 THEN
		SET TEMP_ERR_MESSAGE = 'Your device is not authorized yet to access this server.';
		SET ERR = `RAISERROR`(TEMP_ERR_MESSAGE);		
	END IF;
		
		
	-- Access Rights [Account]
	-- ####################################################
	
	IF 
		-- [ADD] Access Rights
		(
			TEMP_RECORD_EXISTS = 0 AND
			`ACCOUNT_ACCESS_RIGHTS@HAS_PERMISSION`(PARAM_REQUESTER_USERNAME, PARAM_REQUESTER_PASSWORD, 0, TEMP_MODULE_KEYWORD, 2) = 0 AND
			`ACCOUNT_ACCESS_RIGHTS@PROXY_PERMISSION`(PARAM_REQUESTER_PROXY_ID, PARAM_REQUESTER_PROXY_PASSWORD, 0, TEMP_MODULE_KEYWORD, 2) = 0
		) OR
		
		-- [EDIT] Access Rights
		(
			TEMP_RECORD_EXISTS = 1 AND
			`ACCOUNT_ACCESS_RIGHTS@HAS_PERMISSION`(PARAM_REQUESTER_USERNAME, PARAM_REQUESTER_PASSWORD, 0, TEMP_MODULE_KEYWORD, 3) = 0 AND
			`ACCOUNT_ACCESS_RIGHTS@PROXY_PERMISSION`(PARAM_REQUESTER_PROXY_ID, PARAM_REQUESTER_PROXY_PASSWORD, 0, TEMP_MODULE_KEYWORD, 3) = 0
		)
	THEN
		SET TEMP_ACCESS_RIGHTS_DENIED = 1;
		CALL `ACCOUNT_ACCESS_RIGHTS_DENY`
		(
			0, TEMP_MODULE_KEYWORD, PARAM_REC_ATTENDANCE_ID, 0, TEMP_SP_OBJECTIVE, TEMP_RECORD_CHANGES, 
			PARAM_REQUESTER_USERNAME, PARAM_REQUESTER_PASSWORD, 
			PARAM_REQUESTER_PROXY_ID, PARAM_REQUESTER_PROXY_PASSWORD,
			PARAM_REQUESTER_DEVICE_PUBLIC_KEY, PARAM_REQUESTER_DEVICE_PRIVATE_KEY,
			PARAM_REQUESTER_IP, PARAM_UNIQUE_SESSION_ID,
			TEMP_SYNC_SERVER_ID, PARAM_SUPPRESS_RETURN
		);
	END IF;
	SET TEMP_ACCESS_RIGHTS_HAS_OVERRIDE = `ACCOUNT_ACCESS_RIGHTS@HAS_PERMISSION`(PARAM_REQUESTER_USERNAME, PARAM_REQUESTER_PASSWORD, 0, TEMP_MODULE_KEYWORD, 4);
	

	-- Validation
	-- ####################################################
	IF TEMP_SYNC_IS_SERVER_REQUEST = 0 THEN
	

		-- FOREIGN KEY EXISTS
		-- ...........................................
		IF `RECORD_USER@REC_USER_ID_EXISTS`(PARAM_REC_ATTENDANCE_REC_USER_ID, 0) =  0 THEN
			SET TEMP_ERR_MESSAGE = CONCAT_WS(' ', 'Given User does not exists or is inactive. ID: ', PARAM_REC_ATTENDANCE_REC_USER_ID);
			SET ERR = `RAISERROR`(TEMP_ERR_MESSAGE);
		END IF;
		
		-- FOREIGN (OPTIONAL)KEY EXISTS [Validates if not null]
		-- ...........................................
		
		-- IS_ALLOW_NULL = FALSE
		-- ...........................................
				
		-- IS_ALLOW_ZERO = FALSE
		-- ...........................................
		IF PARAM_REC_ATTENDANCE_IS_IN = 0 THEN
			CALL `VALIDATION_MISSING_FIELD`('`REC_ATTENDANCE_IS_IN`', '`NULL`');
		END IF;		
		IF PARAM_REC_ATTENDANCE_IS_OUT = 0 THEN
			CALL `VALIDATION_MISSING_FIELD`('`REC_ATTENDANCE_IS_OUT`', '`NULL`');
		END IF;		
		IF PARAM_REC_ATTENDANCE_STATUS = 0 THEN
			CALL `VALIDATION_MISSING_FIELD`('`REC_ATTENDANCE_STATUS`', '`NULL`');
		END IF;		
		
		-- IS_ALLOW_NEGATIVE = FALSE
		-- ...........................................
		IF PARAM_REC_ATTENDANCE_IS_IN < 0 THEN
			CALL `VALIDATION_NEGATIVE`('`REC_ATTENDANCE_IS_IN`', PARAM_REC_ATTENDANCE_IS_IN);
		END IF;		
		IF PARAM_REC_ATTENDANCE_IS_OUT < 0 THEN
			CALL `VALIDATION_NEGATIVE`('`REC_ATTENDANCE_IS_OUT`', PARAM_REC_ATTENDANCE_IS_OUT);
		END IF;		
		IF PARAM_REC_ATTENDANCE_STATUS < 0 THEN
			CALL `VALIDATION_NEGATIVE`('`REC_ATTENDANCE_STATUS`', PARAM_REC_ATTENDANCE_STATUS);
		END IF;		
		
		-- IS_ALLOW_EMPTY_STRING = FALSE
		-- ...........................................
		IF `SYSTEM_VAR@IS_NULL@DATETIME`(PARAM_REC_ATTENDANCE_DATE, 1) = 1 THEN
			CALL `VALIDATION_MISSING_FIELD`('`REC_ATTENDANCE_DATE`', '`NULL`');
		END IF;
		IF `SYSTEM_VAR@IS_NULL@NVARCHAR`(PARAM_REC_ATTENDANCE_ENTRANCE, 1) = 1 THEN
			CALL `VALIDATION_MISSING_FIELD`('`REC_ATTENDANCE_ENTRANCE`', '`NULL`');
		END IF;
		IF `SYSTEM_VAR@IS_NULL@NVARCHAR`(PARAM_REC_ATTENDANCE_DEVICE_KEY, 1) = 1 THEN
			CALL `VALIDATION_MISSING_FIELD`('`REC_ATTENDANCE_DEVICE_KEY`', '`NULL`');
		END IF;
		
		-- IS_STATUS
		-- ...........................................
		IF `SYSTEM_STATUS@SYS_STATUS_ID_EXISTS`(PARAM_REC_ATTENDANCE_STATUS, 0) = 0 THEN
			SET TEMP_ERR_MESSAGE = CONCAT_WS(' ', 'Given STATUS[Status] does not exists or is inactive. ID: ', PARAM_REC_ATTENDANCE_STATUS);
			SET ERR = `RAISERROR`(TEMP_ERR_MESSAGE);
		END IF;
		
		-- IS STATUS Active / Inactive
		-- ...........................................
		IF `SYSTEM_STATUS@IS_ACTIVE_INACTIVE`(PARAM_REC_ATTENDANCE_IS_IN) = 0 THEN
			SET TEMP_ERR_MESSAGE = CONCAT_WS(' ', 'Given STATUS[In] accepts ACTIVE/IN-ACTIVE only. ID: ', PARAM_REC_ATTENDANCE_IS_IN);
			SET ERR = `RAISERROR`(TEMP_ERR_MESSAGE);
		END IF;
		IF `SYSTEM_STATUS@IS_ACTIVE_INACTIVE`(PARAM_REC_ATTENDANCE_IS_OUT) = 0 THEN
			SET TEMP_ERR_MESSAGE = CONCAT_WS(' ', 'Given STATUS[Out] accepts ACTIVE/IN-ACTIVE only. ID: ', PARAM_REC_ATTENDANCE_IS_OUT);
			SET ERR = `RAISERROR`(TEMP_ERR_MESSAGE);
		END IF;
		
		-- Minimum / Maximum Value
		-- ...........................................
		
		-- IS_UNIQUE = TRUE
		-- ...........................................
		
		-- RECORD IDENTIFIER
		-- ...........................................
		
		
		-- ON_UPDATE VALIDATION 
		-- ...........................................
		IF TEMP_RECORD_EXISTS = 1 THEN	
		
			-- Just to keep at least one line within condition
			SET TEMP_RECORD_EXISTS = 1;
			
		END IF;
		
	END IF;



	-- 8) INSERT / UPDATE
	-- _______________________________________________________________________

	-- INSERT NEW DATA
	-- ####################################################
	IF TEMP_RECORD_EXISTS = 0 THEN

		INSERT INTO
		`record_attendance`
		(
			`record_attendance`.`REC_ATTENDANCE_REC_USER_ID`, 
			`record_attendance`.`REC_ATTENDANCE_DATE`, 
			`record_attendance`.`REC_ATTENDANCE_IS_IN`, 
			`record_attendance`.`REC_ATTENDANCE_IS_OUT`, 
			`record_attendance`.`REC_ATTENDANCE_ENTRANCE`, 
			`record_attendance`.`REC_ATTENDANCE_DEVICE_KEY`, 
			`record_attendance`.`REC_ATTENDANCE_STATUS`
		)
		VALUES
		(
			PARAM_REC_ATTENDANCE_REC_USER_ID, 
			PARAM_REC_ATTENDANCE_DATE, 
			PARAM_REC_ATTENDANCE_IS_IN, 
			PARAM_REC_ATTENDANCE_IS_OUT, 
			PARAM_REC_ATTENDANCE_ENTRANCE, 
			PARAM_REC_ATTENDANCE_DEVICE_KEY, 
			PARAM_REC_ATTENDANCE_STATUS
		);	
		
		-- Update Audit trail with new ID	
		SET PARAM_REC_ATTENDANCE_ID = LAST_INSERT_ID();



	-- UPDATING EXISTING RECORD
	-- ####################################################
	ELSE
		UPDATE `record_attendance`
		SET
			`record_attendance`.`REC_ATTENDANCE_REC_USER_ID` = PARAM_REC_ATTENDANCE_REC_USER_ID, 
			`record_attendance`.`REC_ATTENDANCE_DATE` = PARAM_REC_ATTENDANCE_DATE, 
			`record_attendance`.`REC_ATTENDANCE_IS_IN` = PARAM_REC_ATTENDANCE_IS_IN, 
			`record_attendance`.`REC_ATTENDANCE_IS_OUT` = PARAM_REC_ATTENDANCE_IS_OUT, 
			`record_attendance`.`REC_ATTENDANCE_ENTRANCE` = PARAM_REC_ATTENDANCE_ENTRANCE, 
			`record_attendance`.`REC_ATTENDANCE_DEVICE_KEY` = PARAM_REC_ATTENDANCE_DEVICE_KEY, 
			`record_attendance`.`REC_ATTENDANCE_STATUS` = PARAM_REC_ATTENDANCE_STATUS
		WHERE
			`record_attendance`.`REC_ATTENDANCE_ID` = PARAM_REC_ATTENDANCE_ID;

	END IF;

	
	-- 9) AUDIT TRAIL
	-- _______________________________________________________________________
	CALL `ACCOUNT_AUDIT_TRAIL_SAVE`
	(
		0, TEMP_MODULE_KEYWORD, PARAM_REC_ATTENDANCE_ID, 0, 'SAVE', TEMP_SP_OBJECTIVE, TEMP_RECORD_CHANGES, 
		PARAM_REQUESTER_USERNAME, PARAM_REQUESTER_PASSWORD, 
		PARAM_REQUESTER_PROXY_ID, PARAM_REQUESTER_PROXY_PASSWORD,
		PARAM_REQUESTER_DEVICE_PUBLIC_KEY, PARAM_REQUESTER_DEVICE_PRIVATE_KEY,
		PARAM_REQUESTER_IP, PARAM_UNIQUE_SESSION_ID,
		TEMP_SYNC_SERVER_ID, PARAM_SUPPRESS_RETURN
	);
	

	-- 10) RETURN RESULT
	-- _______________________________________________________________________
	IF PARAM_SUPPRESS_RETURN = 0 THEN
		SELECT 
			PARAM_REC_ATTENDANCE_ID AS INSERTED_ID,
			TEMP_NOW AS SERVER_TIME;
	END IF;
	LEAVE SP_SAVE;


END ;;
DELIMITER ;
/*!50003 SET sql_mode              = @saved_sql_mode */ ;
/*!50003 SET character_set_client  = @saved_cs_client */ ;
/*!50003 SET character_set_results = @saved_cs_results */ ;
/*!50003 SET collation_connection  = @saved_col_connection */ ;
/*!50003 DROP PROCEDURE IF EXISTS `RECORD_DEVICE_DELETE` */;
/*!50003 SET @saved_cs_client      = @@character_set_client */ ;
/*!50003 SET @saved_cs_results     = @@character_set_results */ ;
/*!50003 SET @saved_col_connection = @@collation_connection */ ;
/*!50003 SET character_set_client  = latin1 */ ;
/*!50003 SET character_set_results = latin1 */ ;
/*!50003 SET collation_connection  = latin1_swedish_ci */ ;
/*!50003 SET @saved_sql_mode       = @@sql_mode */ ;
/*!50003 SET sql_mode              = '' */ ;
DELIMITER ;;
CREATE DEFINER=`root`@`localhost` PROCEDURE `RECORD_DEVICE_DELETE`(
	IN `PARAM_REC_DEVICE_ID` BIGINT,

	IN `PARAM_REQUESTER_USERNAME` VARCHAR(500),
	IN `PARAM_REQUESTER_PASSWORD` VARCHAR(500),
	IN `PARAM_REQUESTER_PROXY_ID` BIGINT,
	IN `PARAM_REQUESTER_PROXY_PASSWORD` VARCHAR(1000),
	IN `PARAM_REQUESTER_DEVICE_PUBLIC_KEY` VARCHAR(1000),
	IN `PARAM_REQUESTER_DEVICE_PRIVATE_KEY` VARCHAR(1000),
	
	IN `PARAM_REQUESTER_IP` VARCHAR(1000),
	IN `PARAM_UNIQUE_SESSION_ID` VARCHAR(1000),
	IN `PARAM_SUPPRESS_RETURN` BIT,
	
	IN `PARAM_SYNC_SERVER_DESCRIPTION` VARCHAR(500), 
	IN `PARAM_SYNC_SERVER_UNIQUE_KEY` VARCHAR(500)
)
SP_DELETE:
BEGIN

	-- 1) DECLARE LOCAL PARAMETERS
	-- _______________________________________________________________________
	
	-- Status
	-- ...........................................
	DECLARE STATUS_INACTIVE TINYINT DEFAULT 1;
	DECLARE STATUS_ACTIVE TINYINT DEFAULT 2;
	DECLARE STATUS_CLOSED TINYINT DEFAULT 3;
	DECLARE STATUS_COMPLETED TINYINT DEFAULT 4;
	
	-- Audit Handler
	-- ...........................................
	DECLARE TEMP_RECORD_EXISTS BIT DEFAULT 0;
	DECLARE TEMP_MODULE_KEYWORD VARCHAR(500) DEFAULT 'record_device';
	DECLARE TEMP_SP_OBJECTIVE VARCHAR(500) DEFAULT 'delete Device record';
	DECLARE TEMP_ERR_MESSAGE VARCHAR(500) DEFAULT '';
	DECLARE ERR BIGINT DEFAULT 0;
	DECLARE TEMP_RECORD_CHANGES VARCHAR(16000) DEFAULT '';
	DECLARE TEMP_RECORD_BINDED BIT DEFAULT 0;
	
	DECLARE TEMP_RECORD_BINDED_ID BIGINT DEFAULT 0;
	DECLARE TEMP_RECORD_BINDED_SERVER_ID BIGINT DEFAULT 0;
	
	-- Authentication
	-- ...........................................
	DECLARE TEMP_ACCESS_RIGHTS_DENIED BIT DEFAULT 0;
	DECLARE TEMP_SYNC_SERVER_ID BIGINT DEFAULT 0;
	DECLARE TEMP_SYNC_IS_SERVER_REQUEST BIT DEFAULT 0;
	DECLARE TEMP_AUTHENTICATED_ACCOUNT_ID BIGINT DEFAULT `ACCOUNT_MEMBER@ACC_ACCOUNT_ID_FROM_LOGIN`(PARAM_REQUESTER_USERNAME, PARAM_REQUESTER_PASSWORD);
	DECLARE TEMP_AUTHENTICATED_ACCOUNT_LEVEL BIGINT DEFAULT 0;
	DECLARE TEMP_AUTHENTICATED_ACCOUNT_GROUP BIGINT DEFAULT 0;

	-- Local value holder
	-- ...........................................
		DECLARE TEMP_REC_DEVICE_CODE VARCHAR(40) DEFAULT ''; 
		DECLARE TEMP_REC_DEVICE_DESCRIPTION VARCHAR(400) DEFAULT ''; 
		DECLARE TEMP_REC_DEVICE_ENTRANCE_NAME VARCHAR(400) DEFAULT ''; 
		DECLARE TEMP_REC_DEVICE_IS_IN TINYINT DEFAULT 0; 
		DECLARE TEMP_REC_DEVICE_STATUS TINYINT DEFAULT 0; 

	
	
	-- 2) Try Catch / Throw
	-- _______________________________________________________________________
	DECLARE EXIT HANDLER FOR SQLEXCEPTION
	BEGIN
		RESIGNAL;
	END;

	
	-- 3) Prepare SYNC
	-- _______________________________________________________________________
	
	-- IS RECORD EXISTS		
	-- ####################################################		
	SET TEMP_RECORD_EXISTS = `RECORD_DEVICE@REC_DEVICE_ID_EXISTS`(PARAM_REC_DEVICE_ID, 0);


	-- 4) IF ALREADY EXIST, FILL MISSING DATA
	-- _______________________________________________________________________
	IF TEMP_RECORD_EXISTS = 1 THEN
		SELECT
				`record_device`.`REC_DEVICE_CODE`, 	
				`record_device`.`REC_DEVICE_DESCRIPTION`, 	
				`record_device`.`REC_DEVICE_ENTRANCE_NAME`, 	
				`record_device`.`REC_DEVICE_IS_IN`, 	
				`record_device`.`REC_DEVICE_STATUS`	
		INTO
				TEMP_REC_DEVICE_CODE, 	
				TEMP_REC_DEVICE_DESCRIPTION, 	
				TEMP_REC_DEVICE_ENTRANCE_NAME, 	
				TEMP_REC_DEVICE_IS_IN, 	
				TEMP_REC_DEVICE_STATUS	

		FROM `record_device`
		WHERE
			`record_device`.`REC_DEVICE_ID` = PARAM_REC_DEVICE_ID
		LIMIT 1;

	ELSE 
		IF TEMP_SYNC_IS_SERVER_REQUEST = 0 THEN
			SET TEMP_ERR_MESSAGE = CONCAT_WS(' ', 'Given Device does not exists or is inactive. ID:', PARAM_REC_DEVICE_ID);
			SET ERR = `RAISERROR`(TEMP_ERR_MESSAGE);		
		END IF;
		LEAVE SP_DELETE;
		
	END IF;



	-- 5) PREPARE AUDIT TRAIL
	-- _______________________________________________________________________
	
		SET TEMP_RECORD_CHANGES = 
		`SYSTEM_VAR@CONCAT_ADD`(' | ', TEMP_RECORD_CHANGES, CONCAT_WS(' ', 'Unique Code: "', TEMP_REC_DEVICE_CODE, '" > " DELETED "'));
		SET TEMP_RECORD_CHANGES = 
		`SYSTEM_VAR@CONCAT_ADD`(' | ', TEMP_RECORD_CHANGES, CONCAT_WS(' ', 'Description: "', TEMP_REC_DEVICE_DESCRIPTION, '" > " DELETED "'));
		SET TEMP_RECORD_CHANGES = 
		`SYSTEM_VAR@CONCAT_ADD`(' | ', TEMP_RECORD_CHANGES, CONCAT_WS(' ', 'Entrance Name: "', TEMP_REC_DEVICE_ENTRANCE_NAME, '" > " DELETED "'));
		SET TEMP_RECORD_CHANGES = 
		`SYSTEM_VAR@CONCAT_ADD`(' | ', TEMP_RECORD_CHANGES, CONCAT_WS(' ', 'Is In: "', TEMP_REC_DEVICE_IS_IN, '" > " DELETED "'));
		SET TEMP_RECORD_CHANGES = 
		`SYSTEM_VAR@CONCAT_ADD`(' | ', TEMP_RECORD_CHANGES, CONCAT_WS(' ', 'Status: "', TEMP_REC_DEVICE_STATUS, '" > " DELETED "'));


	-- 6) VALIDATE
	-- _______________________________________________________________________
	
	-- Access Rights [Device]
	-- ####################################################
	IF `ACCOUNT_DEVICE@HAS_PERMISSION`(PARAM_REQUESTER_DEVICE_PUBLIC_KEY, PARAM_REQUESTER_DEVICE_PRIVATE_KEY) = 0 THEN
		SET TEMP_ERR_MESSAGE = 'Your device is not authorized yet to access this server.';
		SET ERR = `RAISERROR`(TEMP_ERR_MESSAGE);		
	END IF;
		
		
	-- Access Rights [Account]
	-- ####################################################	
	
	IF 
		-- [DELETE] Access Rights
		`ACCOUNT_ACCESS_RIGHTS@HAS_PERMISSION`(PARAM_REQUESTER_USERNAME, PARAM_REQUESTER_PASSWORD, 0, TEMP_MODULE_KEYWORD, 4) = 0 AND
		`ACCOUNT_ACCESS_RIGHTS@PROXY_PERMISSION`(PARAM_REQUESTER_PROXY_ID, PARAM_REQUESTER_PROXY_PASSWORD, 0, TEMP_MODULE_KEYWORD, 4) = 0
	THEN
		SET TEMP_ACCESS_RIGHTS_DENIED = 1;
		CALL `ACCOUNT_ACCESS_RIGHTS_DENY`
		(
			0, TEMP_MODULE_KEYWORD, PARAM_REC_DEVICE_ID, 0, TEMP_SP_OBJECTIVE, TEMP_RECORD_CHANGES, 
			PARAM_REQUESTER_USERNAME, PARAM_REQUESTER_PASSWORD, 
			PARAM_REQUESTER_PROXY_ID, PARAM_REQUESTER_PROXY_PASSWORD,
			PARAM_REQUESTER_DEVICE_PUBLIC_KEY, PARAM_REQUESTER_DEVICE_PRIVATE_KEY,
			PARAM_REQUESTER_IP, PARAM_UNIQUE_SESSION_ID,
			TEMP_SYNC_SERVER_ID, PARAM_SUPPRESS_RETURN
		);
	END IF;

	
	-- If already used, cannot remove record
	-- ####################################################

	-- Leave Re-upload request
	-- ####################################################
	IF TEMP_RECORD_BINDED = 1 THEN
		IF TEMP_SYNC_IS_SERVER_REQUEST = 1 THEN
			
			LEAVE SP_DELETE;
		END IF;

		CALL `VALIDATION_DELETE_LINKED_RECORD`(TEMP_REC_DEVICE_DESCRIPTION, '', TEMP_ERR_MESSAGE); 
	END IF;


	-- 7) DELETE
	-- _______________________________________________________________________
	DELETE FROM `record_device`
	WHERE `record_device`.`REC_DEVICE_ID` = PARAM_REC_DEVICE_ID
	LIMIT 1;


	-- 8) AUDIT TRAIL
	-- _______________________________________________________________________
	CALL `ACCOUNT_AUDIT_TRAIL_SAVE`
	(
		0, TEMP_MODULE_KEYWORD, PARAM_REC_DEVICE_ID, 0, 'DELETE', TEMP_SP_OBJECTIVE, TEMP_RECORD_CHANGES, 
		PARAM_REQUESTER_USERNAME, PARAM_REQUESTER_PASSWORD, 
		PARAM_REQUESTER_PROXY_ID, PARAM_REQUESTER_PROXY_PASSWORD,
		PARAM_REQUESTER_DEVICE_PUBLIC_KEY, PARAM_REQUESTER_DEVICE_PRIVATE_KEY,
		PARAM_REQUESTER_IP, PARAM_UNIQUE_SESSION_ID,
		TEMP_SYNC_SERVER_ID, PARAM_SUPPRESS_RETURN
	);

END ;;
DELIMITER ;
/*!50003 SET sql_mode              = @saved_sql_mode */ ;
/*!50003 SET character_set_client  = @saved_cs_client */ ;
/*!50003 SET character_set_results = @saved_cs_results */ ;
/*!50003 SET collation_connection  = @saved_col_connection */ ;
/*!50003 DROP PROCEDURE IF EXISTS `RECORD_DEVICE_GET` */;
/*!50003 SET @saved_cs_client      = @@character_set_client */ ;
/*!50003 SET @saved_cs_results     = @@character_set_results */ ;
/*!50003 SET @saved_col_connection = @@collation_connection */ ;
/*!50003 SET character_set_client  = latin1 */ ;
/*!50003 SET character_set_results = latin1 */ ;
/*!50003 SET collation_connection  = latin1_swedish_ci */ ;
/*!50003 SET @saved_sql_mode       = @@sql_mode */ ;
/*!50003 SET sql_mode              = '' */ ;
DELIMITER ;;
CREATE DEFINER=`root`@`localhost` PROCEDURE `RECORD_DEVICE_GET`(
	IN `PARAM_REC_DEVICE_ID` BIGINT,	
	IN `PARAM_REC_DEVICE_CODE` VARCHAR(40),	
	IN `PARAM_REC_DEVICE_DESCRIPTION` VARCHAR(400),	
	IN `PARAM_REC_DEVICE_ENTRANCE_NAME` VARCHAR(400),	
	IN `PARAM_REC_DEVICE_IS_IN` TINYINT,	
	IN `PARAM_REC_DEVICE_STATUS` TINYINT,	
		
	IN `PARAM_ORDER_FIELD` VARCHAR(500),
	IN `PARAM_ORDER_TYPE` VARCHAR(500),
	IN `PARAM_SKIP` BIGINT,
	IN `PARAM_LIMIT` BIGINT,

	IN `PARAM_REQUESTER_USERNAME` VARCHAR(500),
	IN `PARAM_REQUESTER_PASSWORD` VARCHAR(500),
	IN `PARAM_REQUESTER_PROXY_ID` BIGINT,
	IN `PARAM_REQUESTER_PROXY_PASSWORD` VARCHAR(1000),
	IN `PARAM_REQUESTER_DEVICE_PUBLIC_KEY` VARCHAR(1000),
	IN `PARAM_REQUESTER_DEVICE_PRIVATE_KEY` VARCHAR(1000),
	
	IN `PARAM_REQUESTER_IP` VARCHAR(1000),
	IN `PARAM_UNIQUE_SESSION_ID` VARCHAR(1000),
	IN `PARAM_SUPPRESS_RETURN` BIT
)
SP_GET:
BEGIN

	-- Status
	-- =========================================================================================
	DECLARE STATUS_INACTIVE TINYINT DEFAULT 1;
	DECLARE STATUS_ACTIVE TINYINT DEFAULT 2;
	DECLARE STATUS_CLOSED TINYINT DEFAULT 3;
	DECLARE STATUS_COMPLETED TINYINT DEFAULT 4;
	
	-- Audit Handler
	-- =========================================================================================
	DECLARE TEMP_RECORD_EXISTS BIT DEFAULT 0;
	DECLARE TEMP_MODULE_KEYWORD VARCHAR(500) DEFAULT 'record_device';
	DECLARE TEMP_SP_OBJECTIVE VARCHAR(500) DEFAULT 'Retrieve Device record';
	DECLARE TEMP_ERR_MESSAGE VARCHAR(500) DEFAULT '';
	DECLARE ERR BIGINT DEFAULT 0;
	DECLARE TEMP_RECORD_CHANGES VARCHAR(16000) DEFAULT '';
	DECLARE TEMP_RECORD_BINDED BIT DEFAULT 0;
	
	DECLARE TEMP_RECORD_BINDED_ID BIGINT DEFAULT 0;
	DECLARE TEMP_RECORD_BINDED_SERVER_ID BIGINT DEFAULT 0;
	
	-- Authentication
	-- =========================================================================================
	DECLARE TEMP_ACCESS_RIGHTS_DENIED BIT DEFAULT 0;
	DECLARE TEMP_AUTHENTICATED_ACCOUNT_ID BIGINT DEFAULT `ACCOUNT_MEMBER@ACC_ACCOUNT_ID_FROM_LOGIN`(PARAM_REQUESTER_USERNAME, PARAM_REQUESTER_PASSWORD);
	DECLARE TEMP_AUTHENTICATED_ACCOUNT_LEVEL BIGINT DEFAULT 0;
	DECLARE TEMP_AUTHENTICATED_ACCOUNT_GROUP BIGINT DEFAULT 0;
	
	-- Local Parameters
	-- =========================================================================================
	DECLARE TEMP_NOW DATETIME(6) DEFAULT `SYSTEM_VAR@NOW`('', 1);
	DECLARE TEMP_RECORD_COUNT BIGINT DEFAULT 0;
	
	
	-- Check NULLs
	-- =========================================================================================
	DECLARE IS_NULL_REC_DEVICE_ID BIT DEFAULT `SYSTEM_VAR@IS_NULL@BIGINT`(PARAM_REC_DEVICE_ID, 1, 1);
	DECLARE IS_NULL_REC_DEVICE_CODE BIT DEFAULT `SYSTEM_VAR@IS_NULL@NVARCHAR`(PARAM_REC_DEVICE_CODE, 1);
	DECLARE IS_NULL_REC_DEVICE_DESCRIPTION BIT DEFAULT `SYSTEM_VAR@IS_NULL@NVARCHAR`(PARAM_REC_DEVICE_DESCRIPTION, 1);
	DECLARE IS_NULL_REC_DEVICE_ENTRANCE_NAME BIT DEFAULT `SYSTEM_VAR@IS_NULL@NVARCHAR`(PARAM_REC_DEVICE_ENTRANCE_NAME, 1);
	DECLARE IS_NULL_REC_DEVICE_IS_IN BIT DEFAULT `SYSTEM_VAR@IS_NULL@TINYINT`(PARAM_REC_DEVICE_IS_IN, 1, 1);
	DECLARE IS_NULL_REC_DEVICE_STATUS BIT DEFAULT `SYSTEM_VAR@IS_NULL@TINYINT`(PARAM_REC_DEVICE_STATUS, 1, 1);
	
	-- Error Handler
	-- =========================================================================================
	DECLARE EXIT HANDLER FOR SQLEXCEPTION
	BEGIN
		RESIGNAL;
	END;
	
	-- Ignore Time from DateTime (Set Time 00:00:00.000000 and 23:59:59.999999)
	-- =========================================================================================
		
		
	-- Access Rights [Device]
	-- =========================================================================================
	IF `ACCOUNT_DEVICE@HAS_PERMISSION`(PARAM_REQUESTER_DEVICE_PUBLIC_KEY, PARAM_REQUESTER_DEVICE_PRIVATE_KEY) = 0 THEN
		SET TEMP_ERR_MESSAGE = 'Your device is not authorized yet to access this server.';
		SET ERR = `RAISERROR`(TEMP_ERR_MESSAGE);		
	END IF;
		
		
	-- Access Rights [Account]
	-- =========================================================================================
		
	IF 
		`ACCOUNT_ACCESS_RIGHTS@HAS_PERMISSION`(PARAM_REQUESTER_USERNAME, PARAM_REQUESTER_PASSWORD, 0, TEMP_MODULE_KEYWORD, 1) = 0 AND
		`ACCOUNT_ACCESS_RIGHTS@PROXY_PERMISSION`(PARAM_REQUESTER_PROXY_ID, PARAM_REQUESTER_PROXY_PASSWORD, 0, TEMP_MODULE_KEYWORD, 1) = 0
	THEN
		SET TEMP_ACCESS_RIGHTS_DENIED = 1;
		CALL `ACCOUNT_ACCESS_RIGHTS_DENY`
		(
			0, TEMP_MODULE_KEYWORD, 0, 0, TEMP_SP_OBJECTIVE, TEMP_RECORD_CHANGES, 
			PARAM_REQUESTER_USERNAME, PARAM_REQUESTER_PASSWORD, 
			PARAM_REQUESTER_PROXY_ID, PARAM_REQUESTER_PROXY_PASSWORD,
			PARAM_REQUESTER_DEVICE_PUBLIC_KEY, PARAM_REQUESTER_DEVICE_PRIVATE_KEY,
			PARAM_REQUESTER_IP, PARAM_UNIQUE_SESSION_ID,
			0, PARAM_SUPPRESS_RETURN
		);
	END IF;
	
	
	
	-- COUNT RECORD
	-- =========================================================================================
	
	-- SELECT COLUMNS
	-- ####################################################
	SELECT
		COUNT(DISTINCT `record_device`.`REC_DEVICE_ID`)
	INTO
		TEMP_RECORD_COUNT

	FROM `record_device`
				
		-- Add Inner Joins (Per Foreign-key)
		
	-- CONDITIONS
	-- ####################################################
	WHERE
		(
			IS_NULL_REC_DEVICE_ID = 1 OR
			`record_device`.`REC_DEVICE_ID` = PARAM_REC_DEVICE_ID			
		) AND
		(
			IS_NULL_REC_DEVICE_CODE = 1 OR
			`record_device`.`REC_DEVICE_CODE` LIKE CONCAT_WS('%', '', PARAM_REC_DEVICE_CODE, '')			
		) AND 		
		(
			IS_NULL_REC_DEVICE_DESCRIPTION = 1 OR
			`record_device`.`REC_DEVICE_DESCRIPTION` LIKE CONCAT_WS('%', '', PARAM_REC_DEVICE_DESCRIPTION, '')			
		) AND 		
		(
			IS_NULL_REC_DEVICE_ENTRANCE_NAME = 1 OR
			`record_device`.`REC_DEVICE_ENTRANCE_NAME` LIKE CONCAT_WS('%', '', PARAM_REC_DEVICE_ENTRANCE_NAME, '')			
		) AND 		
		(
			IS_NULL_REC_DEVICE_IS_IN = 1 OR
			`record_device`.`REC_DEVICE_IS_IN` = PARAM_REC_DEVICE_IS_IN			
		) AND
		(
			IS_NULL_REC_DEVICE_STATUS = 1 OR
			`record_device`.`REC_DEVICE_STATUS` = PARAM_REC_DEVICE_STATUS			
		) 
;	

		
		
	-- SELECT RECORDS
	-- =========================================================================================
	
	-- FETCH COLUMNS
	-- ####################################################
	SELECT
		-- RECORD_DEVICE DETAILS
		`record_device`.`REC_DEVICE_ID`, 
		`record_device`.`REC_DEVICE_CODE`, 
		`record_device`.`REC_DEVICE_DESCRIPTION`, 
		`record_device`.`REC_DEVICE_ENTRANCE_NAME`, 
		`record_device`.`REC_DEVICE_IS_IN`, 
		`record_device`.`REC_DEVICE_STATUS`
		
		-- Sum of Child [Numerics, non-primary/foreign keys, nor status, active/inactive, and system generated.]
		
		
		-- Inner join fields
		
		-- Left join fields
		
		, TEMP_NOW AS SERVER_TIME,
		TEMP_RECORD_COUNT AS RECORD_COUNT

	FROM `record_device`
	
		-- Add Inner Joins (Per Foreign-key)
		
		-- Add Optional Left Joins (Per Optional Foreign-key)
		
	-- CONDITIONS
	-- ####################################################
	WHERE
		(
			IS_NULL_REC_DEVICE_ID = 1 OR
			`record_device`.`REC_DEVICE_ID` = PARAM_REC_DEVICE_ID			
		) AND
		(
			IS_NULL_REC_DEVICE_CODE = 1 OR
			`record_device`.`REC_DEVICE_CODE` LIKE CONCAT_WS('%', '', PARAM_REC_DEVICE_CODE, '')			
		) AND 		
		(
			IS_NULL_REC_DEVICE_DESCRIPTION = 1 OR
			`record_device`.`REC_DEVICE_DESCRIPTION` LIKE CONCAT_WS('%', '', PARAM_REC_DEVICE_DESCRIPTION, '')			
		) AND 		
		(
			IS_NULL_REC_DEVICE_ENTRANCE_NAME = 1 OR
			`record_device`.`REC_DEVICE_ENTRANCE_NAME` LIKE CONCAT_WS('%', '', PARAM_REC_DEVICE_ENTRANCE_NAME, '')			
		) AND 		
		(
			IS_NULL_REC_DEVICE_IS_IN = 1 OR
			`record_device`.`REC_DEVICE_IS_IN` = PARAM_REC_DEVICE_IS_IN			
		) AND
		(
			IS_NULL_REC_DEVICE_STATUS = 1 OR
			`record_device`.`REC_DEVICE_STATUS` = PARAM_REC_DEVICE_STATUS			
		) 

	-- ORDER BY
	-- ####################################################
	ORDER BY
		-- RECORD_DEVICE DETAILS
		CASE WHEN PARAM_ORDER_FIELD = 'REC_DEVICE_ID' AND PARAM_ORDER_TYPE = 'ASC' THEN `record_device`.`REC_DEVICE_ID` END ASC, 
		CASE WHEN PARAM_ORDER_FIELD = 'REC_DEVICE_ID' AND PARAM_ORDER_TYPE = 'DESC' THEN `record_device`.`REC_DEVICE_ID` END DESC,	
		CASE WHEN PARAM_ORDER_FIELD = 'REC_DEVICE_CODE' AND PARAM_ORDER_TYPE = 'ASC' THEN `record_device`.`REC_DEVICE_CODE` END ASC, 
		CASE WHEN PARAM_ORDER_FIELD = 'REC_DEVICE_CODE' AND PARAM_ORDER_TYPE = 'DESC' THEN `record_device`.`REC_DEVICE_CODE` END DESC,	
		CASE WHEN PARAM_ORDER_FIELD = 'REC_DEVICE_DESCRIPTION' AND PARAM_ORDER_TYPE = 'ASC' THEN `record_device`.`REC_DEVICE_DESCRIPTION` END ASC, 
		CASE WHEN PARAM_ORDER_FIELD = 'REC_DEVICE_DESCRIPTION' AND PARAM_ORDER_TYPE = 'DESC' THEN `record_device`.`REC_DEVICE_DESCRIPTION` END DESC,	
		CASE WHEN PARAM_ORDER_FIELD = 'REC_DEVICE_ENTRANCE_NAME' AND PARAM_ORDER_TYPE = 'ASC' THEN `record_device`.`REC_DEVICE_ENTRANCE_NAME` END ASC, 
		CASE WHEN PARAM_ORDER_FIELD = 'REC_DEVICE_ENTRANCE_NAME' AND PARAM_ORDER_TYPE = 'DESC' THEN `record_device`.`REC_DEVICE_ENTRANCE_NAME` END DESC,	
		CASE WHEN PARAM_ORDER_FIELD = 'REC_DEVICE_IS_IN' AND PARAM_ORDER_TYPE = 'ASC' THEN `record_device`.`REC_DEVICE_IS_IN` END ASC, 
		CASE WHEN PARAM_ORDER_FIELD = 'REC_DEVICE_IS_IN' AND PARAM_ORDER_TYPE = 'DESC' THEN `record_device`.`REC_DEVICE_IS_IN` END DESC,	
		CASE WHEN PARAM_ORDER_FIELD = 'REC_DEVICE_STATUS' AND PARAM_ORDER_TYPE = 'ASC' THEN `record_device`.`REC_DEVICE_STATUS` END ASC, 
		CASE WHEN PARAM_ORDER_FIELD = 'REC_DEVICE_STATUS' AND PARAM_ORDER_TYPE = 'DESC' THEN `record_device`.`REC_DEVICE_STATUS` END DESC,	

		-- Inner joins
		
		-- EXTRA
		CASE WHEN PARAM_ORDER_FIELD <> 'REC_DEVICE_DESCRIPTION' THEN `record_device`.`REC_DEVICE_DESCRIPTION` END ASC
		
	-- LIMIT & OFFSET
	-- ####################################################		
	LIMIT PARAM_SKIP, PARAM_LIMIT;
	
	
	
	-- EXIT PROCEDURE
	-- =========================================================================================
	LEAVE SP_GET;
			
END ;;
DELIMITER ;
/*!50003 SET sql_mode              = @saved_sql_mode */ ;
/*!50003 SET character_set_client  = @saved_cs_client */ ;
/*!50003 SET character_set_results = @saved_cs_results */ ;
/*!50003 SET collation_connection  = @saved_col_connection */ ;
/*!50003 DROP PROCEDURE IF EXISTS `RECORD_DEVICE_SAVE` */;
/*!50003 SET @saved_cs_client      = @@character_set_client */ ;
/*!50003 SET @saved_cs_results     = @@character_set_results */ ;
/*!50003 SET @saved_col_connection = @@collation_connection */ ;
/*!50003 SET character_set_client  = latin1 */ ;
/*!50003 SET character_set_results = latin1 */ ;
/*!50003 SET collation_connection  = latin1_swedish_ci */ ;
/*!50003 SET @saved_sql_mode       = @@sql_mode */ ;
/*!50003 SET sql_mode              = '' */ ;
DELIMITER ;;
CREATE DEFINER=`root`@`localhost` PROCEDURE `RECORD_DEVICE_SAVE`(
	IN `PARAM_REC_DEVICE_ID` BIGINT,
	IN `PARAM_REC_DEVICE_CODE` VARCHAR(40),
	IN `PARAM_REC_DEVICE_DESCRIPTION` VARCHAR(400),
	IN `PARAM_REC_DEVICE_ENTRANCE_NAME` VARCHAR(400),
	IN `PARAM_REC_DEVICE_IS_IN` TINYINT,
	IN `PARAM_REC_DEVICE_STATUS` TINYINT,

	IN `PARAM_REQUESTER_USERNAME` VARCHAR(500),
	IN `PARAM_REQUESTER_PASSWORD` VARCHAR(500),
	IN `PARAM_REQUESTER_PROXY_ID` BIGINT,
	IN `PARAM_REQUESTER_PROXY_PASSWORD` VARCHAR(1000),
	IN `PARAM_REQUESTER_DEVICE_PUBLIC_KEY` VARCHAR(1000),
	IN `PARAM_REQUESTER_DEVICE_PRIVATE_KEY` VARCHAR(1000),
	
	IN `PARAM_REQUESTER_IP` VARCHAR(1000),
	IN `PARAM_UNIQUE_SESSION_ID` VARCHAR(1000),
	IN `PARAM_SUPPRESS_RETURN` BIT,
	
	IN `PARAM_SYNC_SERVER_DESCRIPTION` VARCHAR(500), 
	IN `PARAM_SYNC_SERVER_UNIQUE_KEY` VARCHAR(500)
)
SP_SAVE:
BEGIN


	-- 1) DECLARE LOCAL PARAMETERS
	-- _______________________________________________________________________
	
	-- Status
	-- ...........................................
	DECLARE STATUS_INACTIVE TINYINT DEFAULT 1;
	DECLARE STATUS_ACTIVE TINYINT DEFAULT 2;
	DECLARE STATUS_CLOSED TINYINT DEFAULT 3;
	DECLARE STATUS_COMPLETED TINYINT DEFAULT 4;

	-- Audit Handler
	-- ...........................................
	DECLARE TEMP_RECORD_EXISTS BIT DEFAULT 0;
	DECLARE TEMP_MODULE_KEYWORD VARCHAR(500) DEFAULT 'record_device';
	DECLARE TEMP_SP_OBJECTIVE VARCHAR(500) DEFAULT 'add/edit Device record';
	DECLARE TEMP_ERR_MESSAGE VARCHAR(500) DEFAULT '';
	DECLARE ERR BIGINT DEFAULT 0;
	DECLARE TEMP_RECORD_CHANGES VARCHAR(16000) DEFAULT '';
	DECLARE TEMP_RECORD_BINDED BIT DEFAULT 0;

	-- Authentication
	-- ...........................................
	DECLARE TEMP_ACCESS_RIGHTS_DENIED BIT DEFAULT 0;
	DECLARE TEMP_ACCESS_RIGHTS_HAS_OVERRIDE BIT DEFAULT 0;
	DECLARE TEMP_SYNC_SERVER_ID BIGINT DEFAULT 0;
	DECLARE TEMP_SYNC_IS_SERVER_REQUEST BIT DEFAULT 0;
	DECLARE TEMP_AUTHENTICATED_ACCOUNT_ID BIGINT DEFAULT `ACCOUNT_MEMBER@ACC_ACCOUNT_ID_FROM_LOGIN`(PARAM_REQUESTER_USERNAME, PARAM_REQUESTER_PASSWORD);
	DECLARE TEMP_AUTHENTICATED_ACCOUNT_LEVEL BIGINT DEFAULT 0;
	DECLARE TEMP_AUTHENTICATED_ACCOUNT_GROUP BIGINT DEFAULT 0;
	
	-- Local Parameters
	-- ...........................................
	DECLARE TEMP_NOW DATETIME(6) DEFAULT `SYSTEM_VAR@NOW`('', 1);
	DECLARE TEMP_RECORD_COUNT BIGINT DEFAULT 0;

	-- AutoGen Parameters
	-- ...........................................
	
	-- Local value holder
	-- ...........................................
	DECLARE TEMP_REC_DEVICE_CODE VARCHAR(40) DEFAULT ''; 
	DECLARE TEMP_REC_DEVICE_DESCRIPTION VARCHAR(400) DEFAULT ''; 
	DECLARE TEMP_REC_DEVICE_ENTRANCE_NAME VARCHAR(400) DEFAULT ''; 
	DECLARE TEMP_REC_DEVICE_IS_IN TINYINT DEFAULT 0; 
	DECLARE TEMP_REC_DEVICE_STATUS TINYINT DEFAULT 0; 
	
	DECLARE REDUND_REC_DEVICE_ID BIGINT DEFAULT 0; 


	-- 2) Try Catch / Throw
	-- _______________________________________________________________________
	DECLARE EXIT HANDLER FOR SQLEXCEPTION
	BEGIN
		RESIGNAL;
	END;



	-- 3) Prepare SYNC
	-- _______________________________________________________________________

	-- IS RECORD EXISTS		
	-- ####################################################	
	SET TEMP_RECORD_EXISTS = `RECORD_DEVICE@REC_DEVICE_ID_EXISTS`(PARAM_REC_DEVICE_ID, 0);

		
		
	-- 4) PREPARE AUTOGEN DATA (IF EXISTS)
	-- _______________________________________________________________________
	IF TEMP_SYNC_IS_SERVER_REQUEST = 0 THEN
		-- Just to keep at least one line within condition
		SET TEMP_SYNC_IS_SERVER_REQUEST = 0;
		
		-- Actual Functionalities here
		-- USE DEFAULT VALUE (String)
	END IF;



	-- 5) IF ALREADY EXIST, FILL MISSING DATA
	-- _______________________________________________________________________
	IF TEMP_RECORD_EXISTS = 1 THEN
		SELECT
			`record_device`.`REC_DEVICE_CODE`, 	
			`record_device`.`REC_DEVICE_DESCRIPTION`, 	
			`record_device`.`REC_DEVICE_ENTRANCE_NAME`, 	
			`record_device`.`REC_DEVICE_IS_IN`, 	
			`record_device`.`REC_DEVICE_STATUS`	
		INTO
			TEMP_REC_DEVICE_CODE, 	
			TEMP_REC_DEVICE_DESCRIPTION, 	
			TEMP_REC_DEVICE_ENTRANCE_NAME, 	
			TEMP_REC_DEVICE_IS_IN, 	
			TEMP_REC_DEVICE_STATUS	

		FROM `record_device`
		WHERE
			`record_device`.`REC_DEVICE_ID` = PARAM_REC_DEVICE_ID
		LIMIT 1;

		-- Replace NULLs with the existing data.
		SET PARAM_REC_DEVICE_ENTRANCE_NAME = `SYSTEM_VAR@REPLACE_NULL@NVARCHAR`(PARAM_REC_DEVICE_ENTRANCE_NAME, TEMP_REC_DEVICE_ENTRANCE_NAME, 1);
		SET PARAM_REC_DEVICE_IS_IN = `SYSTEM_VAR@REPLACE_NULL@TINYINT`(PARAM_REC_DEVICE_IS_IN, TEMP_REC_DEVICE_IS_IN, 1, 1);
		SET PARAM_REC_DEVICE_STATUS = `SYSTEM_VAR@REPLACE_NULL@TINYINT`(PARAM_REC_DEVICE_STATUS, TEMP_REC_DEVICE_STATUS, 1, 1);
		
		-- AUTO GEN (NON-UPDATABLES)		
		
		-- AUTO GEN (UPDATABLE WITH STATUS CHANGE)

		-- AUTO GEN (UPDATABLE WITH STATUS [ACTIVE/INACTIVE] CHANGE)
		
		-- NON-UPDATABLE
		SET PARAM_REC_DEVICE_CODE = TEMP_REC_DEVICE_CODE;
		SET PARAM_REC_DEVICE_DESCRIPTION = TEMP_REC_DEVICE_DESCRIPTION;
		
		-- NON-UPDATABLE BUT NULL
		
	ELSE
		SET PARAM_REC_DEVICE_CODE = `SYSTEM_VAR@REPLACE_NULL@NVARCHAR`(PARAM_REC_DEVICE_CODE, '', 1);
		SET PARAM_REC_DEVICE_DESCRIPTION = `SYSTEM_VAR@REPLACE_NULL@NVARCHAR`(PARAM_REC_DEVICE_DESCRIPTION, '', 1);
		SET PARAM_REC_DEVICE_ENTRANCE_NAME = `SYSTEM_VAR@REPLACE_NULL@NVARCHAR`(PARAM_REC_DEVICE_ENTRANCE_NAME, '', 1);
		SET PARAM_REC_DEVICE_IS_IN = `SYSTEM_VAR@REPLACE_NULL@TINYINT`(PARAM_REC_DEVICE_IS_IN, 0, 1, 1);
		SET PARAM_REC_DEVICE_STATUS = `SYSTEM_VAR@REPLACE_NULL@TINYINT`(PARAM_REC_DEVICE_STATUS, 0, 1, 1);
		
	END IF;

	

	-- 6) PREPARE AUDIT TRAIL
	-- _______________________________________________________________________
	IF BINARY TEMP_REC_DEVICE_CODE <> PARAM_REC_DEVICE_CODE THEN
		SET TEMP_RECORD_CHANGES = 
		`SYSTEM_VAR@CONCAT_ADD`(' | ', TEMP_RECORD_CHANGES, CONCAT_WS(' ', 'Unique Code: "', TEMP_REC_DEVICE_CODE, '" > "', PARAM_REC_DEVICE_CODE, '"'));
	END IF;
	IF BINARY TEMP_REC_DEVICE_DESCRIPTION <> PARAM_REC_DEVICE_DESCRIPTION THEN
		SET TEMP_RECORD_CHANGES = 
		`SYSTEM_VAR@CONCAT_ADD`(' | ', TEMP_RECORD_CHANGES, CONCAT_WS(' ', 'Description: "', TEMP_REC_DEVICE_DESCRIPTION, '" > "', PARAM_REC_DEVICE_DESCRIPTION, '"'));
	END IF;
	IF BINARY TEMP_REC_DEVICE_ENTRANCE_NAME <> PARAM_REC_DEVICE_ENTRANCE_NAME THEN
		SET TEMP_RECORD_CHANGES = 
		`SYSTEM_VAR@CONCAT_ADD`(' | ', TEMP_RECORD_CHANGES, CONCAT_WS(' ', 'Entrance Name: "', TEMP_REC_DEVICE_ENTRANCE_NAME, '" > "', PARAM_REC_DEVICE_ENTRANCE_NAME, '"'));
	END IF;
	IF TEMP_REC_DEVICE_IS_IN <> PARAM_REC_DEVICE_IS_IN THEN
		SET TEMP_RECORD_CHANGES = 
		`SYSTEM_VAR@CONCAT_ADD`(' | ', TEMP_RECORD_CHANGES, CONCAT_WS(' ', 'Is In: "', TEMP_REC_DEVICE_IS_IN, '" > "', PARAM_REC_DEVICE_IS_IN, '"'));
	END IF;	
	IF TEMP_REC_DEVICE_STATUS <> PARAM_REC_DEVICE_STATUS THEN
		SET TEMP_RECORD_CHANGES = 
		`SYSTEM_VAR@CONCAT_ADD`(' | ', TEMP_RECORD_CHANGES, CONCAT_WS(' ', 'Status: "', TEMP_REC_DEVICE_STATUS, '" > "', PARAM_REC_DEVICE_STATUS, '"'));
	END IF;	
		
	-- No Changes in data, reject request
	-- ####################################################
	IF CHARACTER_LENGTH(TEMP_RECORD_CHANGES) = 0 THEN
		IF PARAM_SUPPRESS_RETURN = 0 THEN
			SELECT PARAM_REC_DEVICE_ID AS INSERTED_ID;
		END IF;
		LEAVE SP_SAVE;
	END IF;



	-- 7) VALIDATE
	-- _______________________________________________________________________

	-- Access Rights [Device]
	-- ####################################################
	IF `ACCOUNT_DEVICE@HAS_PERMISSION`(PARAM_REQUESTER_DEVICE_PUBLIC_KEY, PARAM_REQUESTER_DEVICE_PRIVATE_KEY) = 0 THEN
		SET TEMP_ERR_MESSAGE = 'Your device is not authorized yet to access this server.';
		SET ERR = `RAISERROR`(TEMP_ERR_MESSAGE);		
	END IF;
		
		
	-- Access Rights [Account]
	-- ####################################################
	
	IF 
		-- [ADD] Access Rights
		(
			TEMP_RECORD_EXISTS = 0 AND
			`ACCOUNT_ACCESS_RIGHTS@HAS_PERMISSION`(PARAM_REQUESTER_USERNAME, PARAM_REQUESTER_PASSWORD, 0, TEMP_MODULE_KEYWORD, 2) = 0 AND
			`ACCOUNT_ACCESS_RIGHTS@PROXY_PERMISSION`(PARAM_REQUESTER_PROXY_ID, PARAM_REQUESTER_PROXY_PASSWORD, 0, TEMP_MODULE_KEYWORD, 2) = 0
		) OR
		
		-- [EDIT] Access Rights
		(
			TEMP_RECORD_EXISTS = 1 AND
			`ACCOUNT_ACCESS_RIGHTS@HAS_PERMISSION`(PARAM_REQUESTER_USERNAME, PARAM_REQUESTER_PASSWORD, 0, TEMP_MODULE_KEYWORD, 3) = 0 AND
			`ACCOUNT_ACCESS_RIGHTS@PROXY_PERMISSION`(PARAM_REQUESTER_PROXY_ID, PARAM_REQUESTER_PROXY_PASSWORD, 0, TEMP_MODULE_KEYWORD, 3) = 0
		)
	THEN
		SET TEMP_ACCESS_RIGHTS_DENIED = 1;
		CALL `ACCOUNT_ACCESS_RIGHTS_DENY`
		(
			0, TEMP_MODULE_KEYWORD, PARAM_REC_DEVICE_ID, 0, TEMP_SP_OBJECTIVE, TEMP_RECORD_CHANGES, 
			PARAM_REQUESTER_USERNAME, PARAM_REQUESTER_PASSWORD, 
			PARAM_REQUESTER_PROXY_ID, PARAM_REQUESTER_PROXY_PASSWORD,
			PARAM_REQUESTER_DEVICE_PUBLIC_KEY, PARAM_REQUESTER_DEVICE_PRIVATE_KEY,
			PARAM_REQUESTER_IP, PARAM_UNIQUE_SESSION_ID,
			TEMP_SYNC_SERVER_ID, PARAM_SUPPRESS_RETURN
		);
	END IF;
	SET TEMP_ACCESS_RIGHTS_HAS_OVERRIDE = `ACCOUNT_ACCESS_RIGHTS@HAS_PERMISSION`(PARAM_REQUESTER_USERNAME, PARAM_REQUESTER_PASSWORD, 0, TEMP_MODULE_KEYWORD, 4);
	

	-- Validation
	-- ####################################################
	IF TEMP_SYNC_IS_SERVER_REQUEST = 0 THEN
	

		-- FOREIGN KEY EXISTS
		-- ...........................................
		
		-- FOREIGN (OPTIONAL)KEY EXISTS [Validates if not null]
		-- ...........................................
		
		-- IS_ALLOW_NULL = FALSE
		-- ...........................................
				
		-- IS_ALLOW_ZERO = FALSE
		-- ...........................................
		IF PARAM_REC_DEVICE_IS_IN = 0 THEN
			CALL `VALIDATION_MISSING_FIELD`('`REC_DEVICE_IS_IN`', '`NULL`');
		END IF;		
		IF PARAM_REC_DEVICE_STATUS = 0 THEN
			CALL `VALIDATION_MISSING_FIELD`('`REC_DEVICE_STATUS`', '`NULL`');
		END IF;		
		
		-- IS_ALLOW_NEGATIVE = FALSE
		-- ...........................................
		IF PARAM_REC_DEVICE_IS_IN < 0 THEN
			CALL `VALIDATION_NEGATIVE`('`REC_DEVICE_IS_IN`', PARAM_REC_DEVICE_IS_IN);
		END IF;		
		IF PARAM_REC_DEVICE_STATUS < 0 THEN
			CALL `VALIDATION_NEGATIVE`('`REC_DEVICE_STATUS`', PARAM_REC_DEVICE_STATUS);
		END IF;		
		
		-- IS_ALLOW_EMPTY_STRING = FALSE
		-- ...........................................
		IF `SYSTEM_VAR@IS_NULL@NVARCHAR`(PARAM_REC_DEVICE_CODE, 1) = 1 THEN
			CALL `VALIDATION_MISSING_FIELD`('`REC_DEVICE_CODE`', '`NULL`');
		END IF;
		IF `SYSTEM_VAR@IS_NULL@NVARCHAR`(PARAM_REC_DEVICE_DESCRIPTION, 1) = 1 THEN
			CALL `VALIDATION_MISSING_FIELD`('`REC_DEVICE_DESCRIPTION`', '`NULL`');
		END IF;
		IF `SYSTEM_VAR@IS_NULL@NVARCHAR`(PARAM_REC_DEVICE_ENTRANCE_NAME, 1) = 1 THEN
			CALL `VALIDATION_MISSING_FIELD`('`REC_DEVICE_ENTRANCE_NAME`', '`NULL`');
		END IF;
		
		-- IS_STATUS
		-- ...........................................
		IF `SYSTEM_STATUS@SYS_STATUS_ID_EXISTS`(PARAM_REC_DEVICE_STATUS, 0) = 0 THEN
			SET TEMP_ERR_MESSAGE = CONCAT_WS(' ', 'Given STATUS[Status] does not exists or is inactive. ID: ', PARAM_REC_DEVICE_STATUS);
			SET ERR = `RAISERROR`(TEMP_ERR_MESSAGE);
		END IF;
		
		-- IS STATUS Active / Inactive
		-- ...........................................
		IF `SYSTEM_STATUS@IS_ACTIVE_INACTIVE`(PARAM_REC_DEVICE_IS_IN) = 0 THEN
			SET TEMP_ERR_MESSAGE = CONCAT_WS(' ', 'Given STATUS[Is In] accepts ACTIVE/IN-ACTIVE only. ID: ', PARAM_REC_DEVICE_IS_IN);
			SET ERR = `RAISERROR`(TEMP_ERR_MESSAGE);
		END IF;
		
		-- Minimum / Maximum Value
		-- ...........................................
		
		-- IS_UNIQUE = TRUE
		-- ...........................................
		IF
		(
			SELECT COUNT(`record_device`.`REC_DEVICE_ID`)
			FROM `record_device`
			WHERE		
				`record_device`.`REC_DEVICE_CODE` = PARAM_REC_DEVICE_CODE AND		
				`record_device`.`REC_DEVICE_ID` <> PARAM_REC_DEVICE_ID
		) >= 1
		THEN
			SELECT `record_device`.`REC_DEVICE_ID`
			INTO REDUND_REC_DEVICE_ID
			FROM `record_device`
			WHERE		
				`record_device`.`REC_DEVICE_CODE` = PARAM_REC_DEVICE_CODE AND		
				`record_device`.`REC_DEVICE_ID` <> PARAM_REC_DEVICE_ID		
			LIMIT 1; 
			SET TEMP_ERR_MESSAGE = CONCAT_WS(' ', PARAM_REC_DEVICE_DESCRIPTION, '[', REDUND_REC_DEVICE_ID, ']');
			CALL `VALIDATION_REDUNDANT_ENTRY`(TEMP_ERR_MESSAGE);
		END IF;
		
		-- RECORD IDENTIFIER
		-- ...........................................
		
		
		-- ON_UPDATE VALIDATION 
		-- ...........................................
		IF TEMP_RECORD_EXISTS = 1 THEN	
		
			-- Just to keep at least one line within condition
			SET TEMP_RECORD_EXISTS = 1;
			
		END IF;
		
	END IF;



	-- 8) INSERT / UPDATE
	-- _______________________________________________________________________

	-- INSERT NEW DATA
	-- ####################################################
	IF TEMP_RECORD_EXISTS = 0 THEN

		INSERT INTO
		`record_device`
		(
			`record_device`.`REC_DEVICE_CODE`, 
			`record_device`.`REC_DEVICE_DESCRIPTION`, 
			`record_device`.`REC_DEVICE_ENTRANCE_NAME`, 
			`record_device`.`REC_DEVICE_IS_IN`, 
			`record_device`.`REC_DEVICE_STATUS`
		)
		VALUES
		(
			PARAM_REC_DEVICE_CODE, 
			PARAM_REC_DEVICE_DESCRIPTION, 
			PARAM_REC_DEVICE_ENTRANCE_NAME, 
			PARAM_REC_DEVICE_IS_IN, 
			PARAM_REC_DEVICE_STATUS
		);	
		
		-- Update Audit trail with new ID	
		SET PARAM_REC_DEVICE_ID = LAST_INSERT_ID();



	-- UPDATING EXISTING RECORD
	-- ####################################################
	ELSE
		UPDATE `record_device`
		SET
			`record_device`.`REC_DEVICE_CODE` = PARAM_REC_DEVICE_CODE, 
			`record_device`.`REC_DEVICE_DESCRIPTION` = PARAM_REC_DEVICE_DESCRIPTION, 
			`record_device`.`REC_DEVICE_ENTRANCE_NAME` = PARAM_REC_DEVICE_ENTRANCE_NAME, 
			`record_device`.`REC_DEVICE_IS_IN` = PARAM_REC_DEVICE_IS_IN, 
			`record_device`.`REC_DEVICE_STATUS` = PARAM_REC_DEVICE_STATUS
		WHERE
			`record_device`.`REC_DEVICE_ID` = PARAM_REC_DEVICE_ID;

	END IF;

	
	-- 9) AUDIT TRAIL
	-- _______________________________________________________________________
	CALL `ACCOUNT_AUDIT_TRAIL_SAVE`
	(
		0, TEMP_MODULE_KEYWORD, PARAM_REC_DEVICE_ID, 0, 'SAVE', TEMP_SP_OBJECTIVE, TEMP_RECORD_CHANGES, 
		PARAM_REQUESTER_USERNAME, PARAM_REQUESTER_PASSWORD, 
		PARAM_REQUESTER_PROXY_ID, PARAM_REQUESTER_PROXY_PASSWORD,
		PARAM_REQUESTER_DEVICE_PUBLIC_KEY, PARAM_REQUESTER_DEVICE_PRIVATE_KEY,
		PARAM_REQUESTER_IP, PARAM_UNIQUE_SESSION_ID,
		TEMP_SYNC_SERVER_ID, PARAM_SUPPRESS_RETURN
	);
	

	-- 10) RETURN RESULT
	-- _______________________________________________________________________
	IF PARAM_SUPPRESS_RETURN = 0 THEN
		SELECT 
			PARAM_REC_DEVICE_ID AS INSERTED_ID,
			TEMP_NOW AS SERVER_TIME;
	END IF;
	LEAVE SP_SAVE;


END ;;
DELIMITER ;
/*!50003 SET sql_mode              = @saved_sql_mode */ ;
/*!50003 SET character_set_client  = @saved_cs_client */ ;
/*!50003 SET character_set_results = @saved_cs_results */ ;
/*!50003 SET collation_connection  = @saved_col_connection */ ;
/*!50003 DROP PROCEDURE IF EXISTS `RECORD_REGISTRATION_DELETE` */;
/*!50003 SET @saved_cs_client      = @@character_set_client */ ;
/*!50003 SET @saved_cs_results     = @@character_set_results */ ;
/*!50003 SET @saved_col_connection = @@collation_connection */ ;
/*!50003 SET character_set_client  = latin1 */ ;
/*!50003 SET character_set_results = latin1 */ ;
/*!50003 SET collation_connection  = latin1_swedish_ci */ ;
/*!50003 SET @saved_sql_mode       = @@sql_mode */ ;
/*!50003 SET sql_mode              = '' */ ;
DELIMITER ;;
CREATE DEFINER=`root`@`localhost` PROCEDURE `RECORD_REGISTRATION_DELETE`(
	IN `PARAM_REC_REGISTRATION_ID` BIGINT,

	IN `PARAM_REQUESTER_USERNAME` VARCHAR(500),
	IN `PARAM_REQUESTER_PASSWORD` VARCHAR(500),
	IN `PARAM_REQUESTER_PROXY_ID` BIGINT,
	IN `PARAM_REQUESTER_PROXY_PASSWORD` VARCHAR(1000),
	IN `PARAM_REQUESTER_DEVICE_PUBLIC_KEY` VARCHAR(1000),
	IN `PARAM_REQUESTER_DEVICE_PRIVATE_KEY` VARCHAR(1000),
	
	IN `PARAM_REQUESTER_IP` VARCHAR(1000),
	IN `PARAM_UNIQUE_SESSION_ID` VARCHAR(1000),
	IN `PARAM_SUPPRESS_RETURN` BIT,
	
	IN `PARAM_SYNC_SERVER_DESCRIPTION` VARCHAR(500), 
	IN `PARAM_SYNC_SERVER_UNIQUE_KEY` VARCHAR(500)
)
SP_DELETE:
BEGIN

	-- 1) DECLARE LOCAL PARAMETERS
	-- _______________________________________________________________________
	
	-- Status
	-- ...........................................
	DECLARE STATUS_INACTIVE TINYINT DEFAULT 1;
	DECLARE STATUS_ACTIVE TINYINT DEFAULT 2;
	DECLARE STATUS_CLOSED TINYINT DEFAULT 3;
	DECLARE STATUS_COMPLETED TINYINT DEFAULT 4;
	
	-- Audit Handler
	-- ...........................................
	DECLARE TEMP_RECORD_EXISTS BIT DEFAULT 0;
	DECLARE TEMP_MODULE_KEYWORD VARCHAR(500) DEFAULT 'record_registration';
	DECLARE TEMP_SP_OBJECTIVE VARCHAR(500) DEFAULT 'delete Registration record';
	DECLARE TEMP_ERR_MESSAGE VARCHAR(500) DEFAULT '';
	DECLARE ERR BIGINT DEFAULT 0;
	DECLARE TEMP_RECORD_CHANGES VARCHAR(16000) DEFAULT '';
	DECLARE TEMP_RECORD_BINDED BIT DEFAULT 0;
	
	DECLARE TEMP_RECORD_BINDED_ID BIGINT DEFAULT 0;
	DECLARE TEMP_RECORD_BINDED_SERVER_ID BIGINT DEFAULT 0;
	
	-- Authentication
	-- ...........................................
	DECLARE TEMP_ACCESS_RIGHTS_DENIED BIT DEFAULT 0;
	DECLARE TEMP_SYNC_SERVER_ID BIGINT DEFAULT 0;
	DECLARE TEMP_SYNC_IS_SERVER_REQUEST BIT DEFAULT 0;
	DECLARE TEMP_AUTHENTICATED_ACCOUNT_ID BIGINT DEFAULT `ACCOUNT_MEMBER@ACC_ACCOUNT_ID_FROM_LOGIN`(PARAM_REQUESTER_USERNAME, PARAM_REQUESTER_PASSWORD);
	DECLARE TEMP_AUTHENTICATED_ACCOUNT_LEVEL BIGINT DEFAULT 0;
	DECLARE TEMP_AUTHENTICATED_ACCOUNT_GROUP BIGINT DEFAULT 0;

	-- Local value holder
	-- ...........................................
		DECLARE TEMP_REC_REGISTRATION_REC_USER_ID BIGINT DEFAULT 0; 
		DECLARE TEMP_REC_REGISTRATION_CAT_DEPARTMENT_ID BIGINT DEFAULT 0; 
		DECLARE TEMP_REC_REGISTRATION_CAT_SECTION_ID BIGINT DEFAULT 0; 
		DECLARE TEMP_REC_REGISTRATION_FIRST_NAME VARCHAR(400) DEFAULT ''; 
		DECLARE TEMP_REC_REGISTRATION_MIDDLE_NAME VARCHAR(400) DEFAULT ''; 
		DECLARE TEMP_REC_REGISTRATION_LAST_NAME VARCHAR(400) DEFAULT ''; 
		DECLARE TEMP_REC_REGISTRATION_SUFFIX VARCHAR(40) DEFAULT ''; 
		DECLARE TEMP_REC_REGISTRATION_SYS_GENDER_ID BIGINT DEFAULT 0; 
		DECLARE TEMP_REC_REGISTRATION_NOTIFY_PHONE VARCHAR(40) DEFAULT ''; 
		DECLARE TEMP_REC_REGISTRATION_EMCONTACT_PERSON VARCHAR(1000) DEFAULT ''; 
		DECLARE TEMP_REC_REGISTRATION_EMCONTACT_NUMBER VARCHAR(40) DEFAULT ''; 
		DECLARE TEMP_REC_REGISTRATION_STATUS TINYINT DEFAULT 0; 

	
	
	-- 2) Try Catch / Throw
	-- _______________________________________________________________________
	DECLARE EXIT HANDLER FOR SQLEXCEPTION
	BEGIN
		RESIGNAL;
	END;

	
	-- 3) Prepare SYNC
	-- _______________________________________________________________________
	
	-- IS RECORD EXISTS		
	-- ####################################################		
	SET TEMP_RECORD_EXISTS = `RECORD_REGISTRATION@REC_REGISTRATION_ID_EXISTS`(PARAM_REC_REGISTRATION_ID, 0);


	-- 4) IF ALREADY EXIST, FILL MISSING DATA
	-- _______________________________________________________________________
	IF TEMP_RECORD_EXISTS = 1 THEN
		SELECT
				`record_registration`.`REC_REGISTRATION_REC_USER_ID`, 	
				`record_registration`.`REC_REGISTRATION_CAT_DEPARTMENT_ID`, 	
				`record_registration`.`REC_REGISTRATION_CAT_SECTION_ID`, 	
				`record_registration`.`REC_REGISTRATION_FIRST_NAME`, 	
				`record_registration`.`REC_REGISTRATION_MIDDLE_NAME`, 	
				`record_registration`.`REC_REGISTRATION_LAST_NAME`, 	
				`record_registration`.`REC_REGISTRATION_SUFFIX`, 	
				`record_registration`.`REC_REGISTRATION_SYS_GENDER_ID`, 	
				`record_registration`.`REC_REGISTRATION_NOTIFY_PHONE`, 	
				`record_registration`.`REC_REGISTRATION_EMCONTACT_PERSON`, 	
				`record_registration`.`REC_REGISTRATION_EMCONTACT_NUMBER`, 	
				`record_registration`.`REC_REGISTRATION_STATUS`	
		INTO
				TEMP_REC_REGISTRATION_REC_USER_ID, 	
				TEMP_REC_REGISTRATION_CAT_DEPARTMENT_ID, 	
				TEMP_REC_REGISTRATION_CAT_SECTION_ID, 	
				TEMP_REC_REGISTRATION_FIRST_NAME, 	
				TEMP_REC_REGISTRATION_MIDDLE_NAME, 	
				TEMP_REC_REGISTRATION_LAST_NAME, 	
				TEMP_REC_REGISTRATION_SUFFIX, 	
				TEMP_REC_REGISTRATION_SYS_GENDER_ID, 	
				TEMP_REC_REGISTRATION_NOTIFY_PHONE, 	
				TEMP_REC_REGISTRATION_EMCONTACT_PERSON, 	
				TEMP_REC_REGISTRATION_EMCONTACT_NUMBER, 	
				TEMP_REC_REGISTRATION_STATUS	

		FROM `record_registration`
		WHERE
			`record_registration`.`REC_REGISTRATION_ID` = PARAM_REC_REGISTRATION_ID
		LIMIT 1;

	ELSE 
		IF TEMP_SYNC_IS_SERVER_REQUEST = 0 THEN
			SET TEMP_ERR_MESSAGE = CONCAT_WS(' ', 'Given Registration does not exists or is inactive. ID:', PARAM_REC_REGISTRATION_ID);
			SET ERR = `RAISERROR`(TEMP_ERR_MESSAGE);		
		END IF;
		LEAVE SP_DELETE;
		
	END IF;



	-- 5) PREPARE AUDIT TRAIL
	-- _______________________________________________________________________
	
		SET TEMP_RECORD_CHANGES = 
		`SYSTEM_VAR@CONCAT_ADD`(' | ', TEMP_RECORD_CHANGES, CONCAT_WS(' ', 'User: "', TEMP_REC_REGISTRATION_REC_USER_ID, '" > " DELETED "'));
		SET TEMP_RECORD_CHANGES = 
		`SYSTEM_VAR@CONCAT_ADD`(' | ', TEMP_RECORD_CHANGES, CONCAT_WS(' ', 'Department: "', TEMP_REC_REGISTRATION_CAT_DEPARTMENT_ID, '" > " DELETED "'));
		SET TEMP_RECORD_CHANGES = 
		`SYSTEM_VAR@CONCAT_ADD`(' | ', TEMP_RECORD_CHANGES, CONCAT_WS(' ', 'Section: "', TEMP_REC_REGISTRATION_CAT_SECTION_ID, '" > " DELETED "'));
		SET TEMP_RECORD_CHANGES = 
		`SYSTEM_VAR@CONCAT_ADD`(' | ', TEMP_RECORD_CHANGES, CONCAT_WS(' ', 'First name: "', TEMP_REC_REGISTRATION_FIRST_NAME, '" > " DELETED "'));
		SET TEMP_RECORD_CHANGES = 
		`SYSTEM_VAR@CONCAT_ADD`(' | ', TEMP_RECORD_CHANGES, CONCAT_WS(' ', 'Middle name: "', TEMP_REC_REGISTRATION_MIDDLE_NAME, '" > " DELETED "'));
		SET TEMP_RECORD_CHANGES = 
		`SYSTEM_VAR@CONCAT_ADD`(' | ', TEMP_RECORD_CHANGES, CONCAT_WS(' ', 'Last name: "', TEMP_REC_REGISTRATION_LAST_NAME, '" > " DELETED "'));
		SET TEMP_RECORD_CHANGES = 
		`SYSTEM_VAR@CONCAT_ADD`(' | ', TEMP_RECORD_CHANGES, CONCAT_WS(' ', 'Suffix: "', TEMP_REC_REGISTRATION_SUFFIX, '" > " DELETED "'));
		SET TEMP_RECORD_CHANGES = 
		`SYSTEM_VAR@CONCAT_ADD`(' | ', TEMP_RECORD_CHANGES, CONCAT_WS(' ', 'Gender: "', TEMP_REC_REGISTRATION_SYS_GENDER_ID, '" > " DELETED "'));
		SET TEMP_RECORD_CHANGES = 
		`SYSTEM_VAR@CONCAT_ADD`(' | ', TEMP_RECORD_CHANGES, CONCAT_WS(' ', 'Notification Phone Number: "', TEMP_REC_REGISTRATION_NOTIFY_PHONE, '" > " DELETED "'));
		SET TEMP_RECORD_CHANGES = 
		`SYSTEM_VAR@CONCAT_ADD`(' | ', TEMP_RECORD_CHANGES, CONCAT_WS(' ', 'Emergency Contact Person: "', TEMP_REC_REGISTRATION_EMCONTACT_PERSON, '" > " DELETED "'));
		SET TEMP_RECORD_CHANGES = 
		`SYSTEM_VAR@CONCAT_ADD`(' | ', TEMP_RECORD_CHANGES, CONCAT_WS(' ', 'Emergency Contact Numbher: "', TEMP_REC_REGISTRATION_EMCONTACT_NUMBER, '" > " DELETED "'));
		SET TEMP_RECORD_CHANGES = 
		`SYSTEM_VAR@CONCAT_ADD`(' | ', TEMP_RECORD_CHANGES, CONCAT_WS(' ', 'Status: "', TEMP_REC_REGISTRATION_STATUS, '" > " DELETED "'));


	-- 6) VALIDATE
	-- _______________________________________________________________________
	
	-- Access Rights [Device]
	-- ####################################################
	IF `ACCOUNT_DEVICE@HAS_PERMISSION`(PARAM_REQUESTER_DEVICE_PUBLIC_KEY, PARAM_REQUESTER_DEVICE_PRIVATE_KEY) = 0 THEN
		SET TEMP_ERR_MESSAGE = 'Your device is not authorized yet to access this server.';
		SET ERR = `RAISERROR`(TEMP_ERR_MESSAGE);		
	END IF;
		
		
	-- Access Rights [Account]
	-- ####################################################	
	
	IF 
		-- [DELETE] Access Rights
		`ACCOUNT_ACCESS_RIGHTS@HAS_PERMISSION`(PARAM_REQUESTER_USERNAME, PARAM_REQUESTER_PASSWORD, 0, TEMP_MODULE_KEYWORD, 4) = 0 AND
		`ACCOUNT_ACCESS_RIGHTS@PROXY_PERMISSION`(PARAM_REQUESTER_PROXY_ID, PARAM_REQUESTER_PROXY_PASSWORD, 0, TEMP_MODULE_KEYWORD, 4) = 0
	THEN
		SET TEMP_ACCESS_RIGHTS_DENIED = 1;
		CALL `ACCOUNT_ACCESS_RIGHTS_DENY`
		(
			0, TEMP_MODULE_KEYWORD, PARAM_REC_REGISTRATION_ID, 0, TEMP_SP_OBJECTIVE, TEMP_RECORD_CHANGES, 
			PARAM_REQUESTER_USERNAME, PARAM_REQUESTER_PASSWORD, 
			PARAM_REQUESTER_PROXY_ID, PARAM_REQUESTER_PROXY_PASSWORD,
			PARAM_REQUESTER_DEVICE_PUBLIC_KEY, PARAM_REQUESTER_DEVICE_PRIVATE_KEY,
			PARAM_REQUESTER_IP, PARAM_UNIQUE_SESSION_ID,
			TEMP_SYNC_SERVER_ID, PARAM_SUPPRESS_RETURN
		);
	END IF;

	
	-- If already used, cannot remove record
	-- ####################################################

	-- Leave Re-upload request
	-- ####################################################
	IF TEMP_RECORD_BINDED = 1 THEN
		IF TEMP_SYNC_IS_SERVER_REQUEST = 1 THEN
			
			LEAVE SP_DELETE;
		END IF;

		CALL `VALIDATION_DELETE_LINKED_RECORD`(TEMP_REC_REGISTRATION_LAST_NAME, '', TEMP_ERR_MESSAGE); 
	END IF;


	-- 7) DELETE
	-- _______________________________________________________________________
	DELETE FROM `record_registration`
	WHERE `record_registration`.`REC_REGISTRATION_ID` = PARAM_REC_REGISTRATION_ID
	LIMIT 1;


	-- 8) AUDIT TRAIL
	-- _______________________________________________________________________
	CALL `ACCOUNT_AUDIT_TRAIL_SAVE`
	(
		0, TEMP_MODULE_KEYWORD, PARAM_REC_REGISTRATION_ID, 0, 'DELETE', TEMP_SP_OBJECTIVE, TEMP_RECORD_CHANGES, 
		PARAM_REQUESTER_USERNAME, PARAM_REQUESTER_PASSWORD, 
		PARAM_REQUESTER_PROXY_ID, PARAM_REQUESTER_PROXY_PASSWORD,
		PARAM_REQUESTER_DEVICE_PUBLIC_KEY, PARAM_REQUESTER_DEVICE_PRIVATE_KEY,
		PARAM_REQUESTER_IP, PARAM_UNIQUE_SESSION_ID,
		TEMP_SYNC_SERVER_ID, PARAM_SUPPRESS_RETURN
	);

END ;;
DELIMITER ;
/*!50003 SET sql_mode              = @saved_sql_mode */ ;
/*!50003 SET character_set_client  = @saved_cs_client */ ;
/*!50003 SET character_set_results = @saved_cs_results */ ;
/*!50003 SET collation_connection  = @saved_col_connection */ ;
/*!50003 DROP PROCEDURE IF EXISTS `RECORD_REGISTRATION_GET` */;
/*!50003 SET @saved_cs_client      = @@character_set_client */ ;
/*!50003 SET @saved_cs_results     = @@character_set_results */ ;
/*!50003 SET @saved_col_connection = @@collation_connection */ ;
/*!50003 SET character_set_client  = latin1 */ ;
/*!50003 SET character_set_results = latin1 */ ;
/*!50003 SET collation_connection  = latin1_swedish_ci */ ;
/*!50003 SET @saved_sql_mode       = @@sql_mode */ ;
/*!50003 SET sql_mode              = '' */ ;
DELIMITER ;;
CREATE DEFINER=`root`@`localhost` PROCEDURE `RECORD_REGISTRATION_GET`(
	IN `PARAM_REC_REGISTRATION_ID` BIGINT,	
	IN `PARAM_REC_REGISTRATION_REC_USER_ID` BIGINT,	
	IN `PARAM_REC_REGISTRATION_CAT_DEPARTMENT_ID` BIGINT,	
	IN `PARAM_REC_REGISTRATION_CAT_SECTION_ID` BIGINT,	
	IN `PARAM_REC_REGISTRATION_FIRST_NAME` VARCHAR(400),	
	IN `PARAM_REC_REGISTRATION_MIDDLE_NAME` VARCHAR(400),	
	IN `PARAM_REC_REGISTRATION_LAST_NAME` VARCHAR(400),	
	IN `PARAM_REC_REGISTRATION_SUFFIX` VARCHAR(40),	
	IN `PARAM_REC_REGISTRATION_SYS_GENDER_ID` BIGINT,	
	IN `PARAM_REC_REGISTRATION_NOTIFY_PHONE` VARCHAR(40),	
	IN `PARAM_REC_REGISTRATION_EMCONTACT_PERSON` VARCHAR(1000),	
	IN `PARAM_REC_REGISTRATION_EMCONTACT_NUMBER` VARCHAR(40),	
	IN `PARAM_REC_REGISTRATION_STATUS` TINYINT,	
		
	IN `PARAM_ORDER_FIELD` VARCHAR(500),
	IN `PARAM_ORDER_TYPE` VARCHAR(500),
	IN `PARAM_SKIP` BIGINT,
	IN `PARAM_LIMIT` BIGINT,

	IN `PARAM_REQUESTER_USERNAME` VARCHAR(500),
	IN `PARAM_REQUESTER_PASSWORD` VARCHAR(500),
	IN `PARAM_REQUESTER_PROXY_ID` BIGINT,
	IN `PARAM_REQUESTER_PROXY_PASSWORD` VARCHAR(1000),
	IN `PARAM_REQUESTER_DEVICE_PUBLIC_KEY` VARCHAR(1000),
	IN `PARAM_REQUESTER_DEVICE_PRIVATE_KEY` VARCHAR(1000),
	
	IN `PARAM_REQUESTER_IP` VARCHAR(1000),
	IN `PARAM_UNIQUE_SESSION_ID` VARCHAR(1000),
	IN `PARAM_SUPPRESS_RETURN` BIT
)
SP_GET:
BEGIN

	-- Status
	-- =========================================================================================
	DECLARE STATUS_INACTIVE TINYINT DEFAULT 1;
	DECLARE STATUS_ACTIVE TINYINT DEFAULT 2;
	DECLARE STATUS_CLOSED TINYINT DEFAULT 3;
	DECLARE STATUS_COMPLETED TINYINT DEFAULT 4;
	
	-- Audit Handler
	-- =========================================================================================
	DECLARE TEMP_RECORD_EXISTS BIT DEFAULT 0;
	DECLARE TEMP_MODULE_KEYWORD VARCHAR(500) DEFAULT 'record_registration';
	DECLARE TEMP_SP_OBJECTIVE VARCHAR(500) DEFAULT 'Retrieve Registration record';
	DECLARE TEMP_ERR_MESSAGE VARCHAR(500) DEFAULT '';
	DECLARE ERR BIGINT DEFAULT 0;
	DECLARE TEMP_RECORD_CHANGES VARCHAR(16000) DEFAULT '';
	DECLARE TEMP_RECORD_BINDED BIT DEFAULT 0;
	
	DECLARE TEMP_RECORD_BINDED_ID BIGINT DEFAULT 0;
	DECLARE TEMP_RECORD_BINDED_SERVER_ID BIGINT DEFAULT 0;
	
	-- Authentication
	-- =========================================================================================
	DECLARE TEMP_ACCESS_RIGHTS_DENIED BIT DEFAULT 0;
	DECLARE TEMP_AUTHENTICATED_ACCOUNT_ID BIGINT DEFAULT `ACCOUNT_MEMBER@ACC_ACCOUNT_ID_FROM_LOGIN`(PARAM_REQUESTER_USERNAME, PARAM_REQUESTER_PASSWORD);
	DECLARE TEMP_AUTHENTICATED_ACCOUNT_LEVEL BIGINT DEFAULT 0;
	DECLARE TEMP_AUTHENTICATED_ACCOUNT_GROUP BIGINT DEFAULT 0;
	
	-- Local Parameters
	-- =========================================================================================
	DECLARE TEMP_NOW DATETIME(6) DEFAULT `SYSTEM_VAR@NOW`('', 1);
	DECLARE TEMP_RECORD_COUNT BIGINT DEFAULT 0;
	
	
	-- Check NULLs
	-- =========================================================================================
	DECLARE IS_NULL_REC_REGISTRATION_ID BIT DEFAULT `SYSTEM_VAR@IS_NULL@BIGINT`(PARAM_REC_REGISTRATION_ID, 1, 1);
	DECLARE IS_NULL_REC_REGISTRATION_REC_USER_ID BIT DEFAULT `SYSTEM_VAR@IS_NULL@BIGINT`(PARAM_REC_REGISTRATION_REC_USER_ID, 0, 1);
	DECLARE IS_NULL_REC_REGISTRATION_CAT_DEPARTMENT_ID BIT DEFAULT `SYSTEM_VAR@IS_NULL@BIGINT`(PARAM_REC_REGISTRATION_CAT_DEPARTMENT_ID, 1, 1);
	DECLARE IS_NULL_REC_REGISTRATION_CAT_SECTION_ID BIT DEFAULT `SYSTEM_VAR@IS_NULL@BIGINT`(PARAM_REC_REGISTRATION_CAT_SECTION_ID, 1, 1);
	DECLARE IS_NULL_REC_REGISTRATION_FIRST_NAME BIT DEFAULT `SYSTEM_VAR@IS_NULL@NVARCHAR`(PARAM_REC_REGISTRATION_FIRST_NAME, 1);
	DECLARE IS_NULL_REC_REGISTRATION_MIDDLE_NAME BIT DEFAULT `SYSTEM_VAR@IS_NULL@NVARCHAR`(PARAM_REC_REGISTRATION_MIDDLE_NAME, 0);
	DECLARE IS_NULL_REC_REGISTRATION_LAST_NAME BIT DEFAULT `SYSTEM_VAR@IS_NULL@NVARCHAR`(PARAM_REC_REGISTRATION_LAST_NAME, 1);
	DECLARE IS_NULL_REC_REGISTRATION_SUFFIX BIT DEFAULT `SYSTEM_VAR@IS_NULL@NVARCHAR`(PARAM_REC_REGISTRATION_SUFFIX, 0);
	DECLARE IS_NULL_REC_REGISTRATION_SYS_GENDER_ID BIT DEFAULT `SYSTEM_VAR@IS_NULL@BIGINT`(PARAM_REC_REGISTRATION_SYS_GENDER_ID, 1, 1);
	DECLARE IS_NULL_REC_REGISTRATION_NOTIFY_PHONE BIT DEFAULT `SYSTEM_VAR@IS_NULL@NVARCHAR`(PARAM_REC_REGISTRATION_NOTIFY_PHONE, 1);
	DECLARE IS_NULL_REC_REGISTRATION_EMCONTACT_PERSON BIT DEFAULT `SYSTEM_VAR@IS_NULL@NVARCHAR`(PARAM_REC_REGISTRATION_EMCONTACT_PERSON, 0);
	DECLARE IS_NULL_REC_REGISTRATION_EMCONTACT_NUMBER BIT DEFAULT `SYSTEM_VAR@IS_NULL@NVARCHAR`(PARAM_REC_REGISTRATION_EMCONTACT_NUMBER, 0);
	DECLARE IS_NULL_REC_REGISTRATION_STATUS BIT DEFAULT `SYSTEM_VAR@IS_NULL@TINYINT`(PARAM_REC_REGISTRATION_STATUS, 1, 1);
	
	-- Error Handler
	-- =========================================================================================
	DECLARE EXIT HANDLER FOR SQLEXCEPTION
	BEGIN
		RESIGNAL;
	END;
	
	-- Ignore Time from DateTime (Set Time 00:00:00.000000 and 23:59:59.999999)
	-- =========================================================================================
		
		
	-- Access Rights [Device]
	-- =========================================================================================
	IF `ACCOUNT_DEVICE@HAS_PERMISSION`(PARAM_REQUESTER_DEVICE_PUBLIC_KEY, PARAM_REQUESTER_DEVICE_PRIVATE_KEY) = 0 THEN
		SET TEMP_ERR_MESSAGE = 'Your device is not authorized yet to access this server.';
		SET ERR = `RAISERROR`(TEMP_ERR_MESSAGE);		
	END IF;
		
		
	-- Access Rights [Account]
	-- =========================================================================================
		
	IF 
		`ACCOUNT_ACCESS_RIGHTS@HAS_PERMISSION`(PARAM_REQUESTER_USERNAME, PARAM_REQUESTER_PASSWORD, 0, TEMP_MODULE_KEYWORD, 1) = 0 AND
		`ACCOUNT_ACCESS_RIGHTS@PROXY_PERMISSION`(PARAM_REQUESTER_PROXY_ID, PARAM_REQUESTER_PROXY_PASSWORD, 0, TEMP_MODULE_KEYWORD, 1) = 0
	THEN
		SET TEMP_ACCESS_RIGHTS_DENIED = 1;
		CALL `ACCOUNT_ACCESS_RIGHTS_DENY`
		(
			0, TEMP_MODULE_KEYWORD, 0, 0, TEMP_SP_OBJECTIVE, TEMP_RECORD_CHANGES, 
			PARAM_REQUESTER_USERNAME, PARAM_REQUESTER_PASSWORD, 
			PARAM_REQUESTER_PROXY_ID, PARAM_REQUESTER_PROXY_PASSWORD,
			PARAM_REQUESTER_DEVICE_PUBLIC_KEY, PARAM_REQUESTER_DEVICE_PRIVATE_KEY,
			PARAM_REQUESTER_IP, PARAM_UNIQUE_SESSION_ID,
			0, PARAM_SUPPRESS_RETURN
		);
	END IF;
	
	
	
	-- COUNT RECORD
	-- =========================================================================================
	
	-- SELECT COLUMNS
	-- ####################################################
	SELECT
		COUNT(DISTINCT `record_registration`.`REC_REGISTRATION_ID`)
	INTO
		TEMP_RECORD_COUNT

	FROM `record_registration`
				
		-- Add Inner Joins (Per Foreign-key)
		INNER JOIN `category_department` ON
		`category_department`.`CAT_DEPARTMENT_ID` = `record_registration`.`REC_REGISTRATION_CAT_DEPARTMENT_ID`
			
		-- ~~~~~	
			
		INNER JOIN `category_section` ON
		`category_section`.`CAT_SECTION_ID` = `record_registration`.`REC_REGISTRATION_CAT_SECTION_ID`
			
		-- ~~~~~	
			
		INNER JOIN `system_gender` ON
		`system_gender`.`SYS_GENDER_ID` = `record_registration`.`REC_REGISTRATION_SYS_GENDER_ID`
			
			
		
	-- CONDITIONS
	-- ####################################################
	WHERE
		(
			IS_NULL_REC_REGISTRATION_ID = 1 OR
			`record_registration`.`REC_REGISTRATION_ID` = PARAM_REC_REGISTRATION_ID			
		) AND
		(
			IS_NULL_REC_REGISTRATION_REC_USER_ID = 1 OR
			`record_registration`.`REC_REGISTRATION_REC_USER_ID` = PARAM_REC_REGISTRATION_REC_USER_ID			
		) AND
		(
			IS_NULL_REC_REGISTRATION_CAT_DEPARTMENT_ID = 1 OR
			`record_registration`.`REC_REGISTRATION_CAT_DEPARTMENT_ID` = PARAM_REC_REGISTRATION_CAT_DEPARTMENT_ID			
		) AND
		(
			IS_NULL_REC_REGISTRATION_CAT_SECTION_ID = 1 OR
			`record_registration`.`REC_REGISTRATION_CAT_SECTION_ID` = PARAM_REC_REGISTRATION_CAT_SECTION_ID			
		) AND
		(
			IS_NULL_REC_REGISTRATION_FIRST_NAME = 1 OR
			`record_registration`.`REC_REGISTRATION_FIRST_NAME` LIKE CONCAT_WS('%', '', PARAM_REC_REGISTRATION_FIRST_NAME, '')			
		) AND 		
		(
			IS_NULL_REC_REGISTRATION_MIDDLE_NAME = 1 OR
			`record_registration`.`REC_REGISTRATION_MIDDLE_NAME` LIKE CONCAT_WS('%', '', PARAM_REC_REGISTRATION_MIDDLE_NAME, '')			
		) AND 		
		(
			IS_NULL_REC_REGISTRATION_LAST_NAME = 1 OR
			`record_registration`.`REC_REGISTRATION_LAST_NAME` LIKE CONCAT_WS('%', '', PARAM_REC_REGISTRATION_LAST_NAME, '')			
		) AND 		
		(
			IS_NULL_REC_REGISTRATION_SUFFIX = 1 OR
			`record_registration`.`REC_REGISTRATION_SUFFIX` LIKE CONCAT_WS('%', '', PARAM_REC_REGISTRATION_SUFFIX, '')			
		) AND 		
		(
			IS_NULL_REC_REGISTRATION_SYS_GENDER_ID = 1 OR
			`record_registration`.`REC_REGISTRATION_SYS_GENDER_ID` = PARAM_REC_REGISTRATION_SYS_GENDER_ID			
		) AND
		(
			IS_NULL_REC_REGISTRATION_NOTIFY_PHONE = 1 OR
			`record_registration`.`REC_REGISTRATION_NOTIFY_PHONE` LIKE CONCAT_WS('%', '', PARAM_REC_REGISTRATION_NOTIFY_PHONE, '')			
		) AND 		
		(
			IS_NULL_REC_REGISTRATION_EMCONTACT_PERSON = 1 OR
			`record_registration`.`REC_REGISTRATION_EMCONTACT_PERSON` LIKE CONCAT_WS('%', '', PARAM_REC_REGISTRATION_EMCONTACT_PERSON, '')			
		) AND 		
		(
			IS_NULL_REC_REGISTRATION_EMCONTACT_NUMBER = 1 OR
			`record_registration`.`REC_REGISTRATION_EMCONTACT_NUMBER` LIKE CONCAT_WS('%', '', PARAM_REC_REGISTRATION_EMCONTACT_NUMBER, '')			
		) AND 		
		(
			IS_NULL_REC_REGISTRATION_STATUS = 1 OR
			`record_registration`.`REC_REGISTRATION_STATUS` = PARAM_REC_REGISTRATION_STATUS			
		) 
;	

		
		
	-- SELECT RECORDS
	-- =========================================================================================
	
	-- FETCH COLUMNS
	-- ####################################################
	SELECT
		-- RECORD_REGISTRATION DETAILS
		`record_registration`.`REC_REGISTRATION_ID`, 
		`record_registration`.`REC_REGISTRATION_REC_USER_ID`, 
		`record_registration`.`REC_REGISTRATION_CAT_DEPARTMENT_ID`, 
		`record_registration`.`REC_REGISTRATION_CAT_SECTION_ID`, 

		CONCAT_WS
		(
			' ',
			`record_registration`.`REC_REGISTRATION_LAST_NAME`, ',',
			`record_registration`.`REC_REGISTRATION_FIRST_NAME`, 
			`record_registration`.`REC_REGISTRATION_MIDDLE_NAME`, 
			`record_registration`.`REC_REGISTRATION_SUFFIX`
		) AS REC_REGISTRATION_NAME,

		`record_registration`.`REC_REGISTRATION_FIRST_NAME`, 
		`record_registration`.`REC_REGISTRATION_MIDDLE_NAME`, 
		`record_registration`.`REC_REGISTRATION_LAST_NAME`, 
		`record_registration`.`REC_REGISTRATION_SUFFIX`, 
		`record_registration`.`REC_REGISTRATION_SYS_GENDER_ID`, 
		`record_registration`.`REC_REGISTRATION_NOTIFY_PHONE`, 
		`record_registration`.`REC_REGISTRATION_EMCONTACT_PERSON`, 
		`record_registration`.`REC_REGISTRATION_EMCONTACT_NUMBER`, 
		`record_registration`.`REC_REGISTRATION_STATUS`
		
		-- Sum of Child [Numerics, non-primary/foreign keys, nor status, active/inactive, and system generated.]
		
		
		-- Inner join fields
		, 
		`category_department`.`CAT_DEPARTMENT_ID`,	
		`category_department`.`CAT_DEPARTMENT_DESCRIPTION` AS REC_REGISTRATION_CAT_DEPARTMENT_ID_DESCRIPTION,
		`category_department`.`CAT_DEPARTMENT_DESCRIPTION`,	
		`category_department`.`CAT_DEPARTMENT_STATUS`,	
		`category_section`.`CAT_SECTION_ID`,	
		`category_section`.`CAT_SECTION_CAT_DEPARTMENT_ID`,	
		`category_section`.`CAT_SECTION_DESCRIPTION` AS REC_REGISTRATION_CAT_SECTION_ID_DESCRIPTION,
		`category_section`.`CAT_SECTION_DESCRIPTION`,	
		`category_section`.`CAT_SECTION_STATUS`,	
		`system_gender`.`SYS_GENDER_ID`,	
		`system_gender`.`SYS_GENDER_CODE`,	
		`system_gender`.`SYS_GENDER_DESCRIPTION` AS REC_REGISTRATION_SYS_GENDER_ID_DESCRIPTION,
		`system_gender`.`SYS_GENDER_DESCRIPTION`,	
		`system_gender`.`SYS_GENDER_STATUS`	
		
		-- Left join fields
		, 
		`record_user`.`REC_USER_ID`,
		`record_user`.`REC_USER_CAT_DEPARTMENT_ID`,
		`record_user`.`REC_USER_CAT_SECTION_ID`,
		`record_user`.`REC_USER_UNIQUE_CODE`,
		`record_user`.`REC_USER_FIRST_NAME`,
		`record_user`.`REC_USER_MIDDLE_NAME`,
		`record_user`.`REC_USER_LAST_NAME` AS REC_REGISTRATION_REC_USER_ID_DESCRIPTION,
		`record_user`.`REC_USER_LAST_NAME`,
		`record_user`.`REC_USER_SUFFIX`,
		`record_user`.`REC_USER_SYS_GENDER_ID`,
		`record_user`.`REC_USER_NOTIFY_PHONE`,
		`record_user`.`REC_USER_EMCONTACT_PERSON`,
		`record_user`.`REC_USER_EMCONTACT_NUMBER`,
		`record_user`.`REC_USER_STATUS`
		
		, TEMP_NOW AS SERVER_TIME,
		TEMP_RECORD_COUNT AS RECORD_COUNT

	FROM `record_registration`
	
		-- Add Inner Joins (Per Foreign-key)
		INNER JOIN `category_department` ON
		`category_department`.`CAT_DEPARTMENT_ID` = `record_registration`.`REC_REGISTRATION_CAT_DEPARTMENT_ID`
			
		-- ~~~~~	
			
		INNER JOIN `category_section` ON
		`category_section`.`CAT_SECTION_ID` = `record_registration`.`REC_REGISTRATION_CAT_SECTION_ID`
			
		-- ~~~~~	
			
		INNER JOIN `system_gender` ON
		`system_gender`.`SYS_GENDER_ID` = `record_registration`.`REC_REGISTRATION_SYS_GENDER_ID`
			
			
		
		-- Add Optional Left Joins (Per Optional Foreign-key)
		LEFT JOIN `record_user` ON
		`record_user`.`REC_USER_ID` = `record_registration`.`REC_REGISTRATION_REC_USER_ID`
			
				
		
	-- CONDITIONS
	-- ####################################################
	WHERE
		(
			IS_NULL_REC_REGISTRATION_ID = 1 OR
			`record_registration`.`REC_REGISTRATION_ID` = PARAM_REC_REGISTRATION_ID			
		) AND
		(
			IS_NULL_REC_REGISTRATION_REC_USER_ID = 1 OR
			`record_registration`.`REC_REGISTRATION_REC_USER_ID` = PARAM_REC_REGISTRATION_REC_USER_ID			
		) AND
		(
			IS_NULL_REC_REGISTRATION_CAT_DEPARTMENT_ID = 1 OR
			`record_registration`.`REC_REGISTRATION_CAT_DEPARTMENT_ID` = PARAM_REC_REGISTRATION_CAT_DEPARTMENT_ID			
		) AND
		(
			IS_NULL_REC_REGISTRATION_CAT_SECTION_ID = 1 OR
			`record_registration`.`REC_REGISTRATION_CAT_SECTION_ID` = PARAM_REC_REGISTRATION_CAT_SECTION_ID			
		) AND
		(
			IS_NULL_REC_REGISTRATION_FIRST_NAME = 1 OR
			`record_registration`.`REC_REGISTRATION_FIRST_NAME` LIKE CONCAT_WS('%', '', PARAM_REC_REGISTRATION_FIRST_NAME, '')			
		) AND 		
		(
			IS_NULL_REC_REGISTRATION_MIDDLE_NAME = 1 OR
			`record_registration`.`REC_REGISTRATION_MIDDLE_NAME` LIKE CONCAT_WS('%', '', PARAM_REC_REGISTRATION_MIDDLE_NAME, '')			
		) AND 		
		(
			IS_NULL_REC_REGISTRATION_LAST_NAME = 1 OR
			`record_registration`.`REC_REGISTRATION_LAST_NAME` LIKE CONCAT_WS('%', '', PARAM_REC_REGISTRATION_LAST_NAME, '')			
		) AND 		
		(
			IS_NULL_REC_REGISTRATION_SUFFIX = 1 OR
			`record_registration`.`REC_REGISTRATION_SUFFIX` LIKE CONCAT_WS('%', '', PARAM_REC_REGISTRATION_SUFFIX, '')			
		) AND 		
		(
			IS_NULL_REC_REGISTRATION_SYS_GENDER_ID = 1 OR
			`record_registration`.`REC_REGISTRATION_SYS_GENDER_ID` = PARAM_REC_REGISTRATION_SYS_GENDER_ID			
		) AND
		(
			IS_NULL_REC_REGISTRATION_NOTIFY_PHONE = 1 OR
			`record_registration`.`REC_REGISTRATION_NOTIFY_PHONE` LIKE CONCAT_WS('%', '', PARAM_REC_REGISTRATION_NOTIFY_PHONE, '')			
		) AND 		
		(
			IS_NULL_REC_REGISTRATION_EMCONTACT_PERSON = 1 OR
			`record_registration`.`REC_REGISTRATION_EMCONTACT_PERSON` LIKE CONCAT_WS('%', '', PARAM_REC_REGISTRATION_EMCONTACT_PERSON, '')			
		) AND 		
		(
			IS_NULL_REC_REGISTRATION_EMCONTACT_NUMBER = 1 OR
			`record_registration`.`REC_REGISTRATION_EMCONTACT_NUMBER` LIKE CONCAT_WS('%', '', PARAM_REC_REGISTRATION_EMCONTACT_NUMBER, '')			
		) AND 		
		(
			IS_NULL_REC_REGISTRATION_STATUS = 1 OR
			`record_registration`.`REC_REGISTRATION_STATUS` = PARAM_REC_REGISTRATION_STATUS			
		) 

	-- ORDER BY
	-- ####################################################
	ORDER BY
		-- RECORD_REGISTRATION DETAILS
		CASE WHEN PARAM_ORDER_FIELD = 'REC_REGISTRATION_ID' AND PARAM_ORDER_TYPE = 'ASC' THEN `record_registration`.`REC_REGISTRATION_ID` END ASC, 
		CASE WHEN PARAM_ORDER_FIELD = 'REC_REGISTRATION_ID' AND PARAM_ORDER_TYPE = 'DESC' THEN `record_registration`.`REC_REGISTRATION_ID` END DESC,	
		CASE WHEN PARAM_ORDER_FIELD = 'REC_REGISTRATION_REC_USER_ID' AND PARAM_ORDER_TYPE = 'ASC' THEN `record_registration`.`REC_REGISTRATION_REC_USER_ID` END ASC, 
		CASE WHEN PARAM_ORDER_FIELD = 'REC_REGISTRATION_REC_USER_ID' AND PARAM_ORDER_TYPE = 'DESC' THEN `record_registration`.`REC_REGISTRATION_REC_USER_ID` END DESC,	
		CASE WHEN PARAM_ORDER_FIELD = 'REC_REGISTRATION_CAT_DEPARTMENT_ID' AND PARAM_ORDER_TYPE = 'ASC' THEN `record_registration`.`REC_REGISTRATION_CAT_DEPARTMENT_ID` END ASC, 
		CASE WHEN PARAM_ORDER_FIELD = 'REC_REGISTRATION_CAT_DEPARTMENT_ID' AND PARAM_ORDER_TYPE = 'DESC' THEN `record_registration`.`REC_REGISTRATION_CAT_DEPARTMENT_ID` END DESC,	
		CASE WHEN PARAM_ORDER_FIELD = 'REC_REGISTRATION_CAT_SECTION_ID' AND PARAM_ORDER_TYPE = 'ASC' THEN `record_registration`.`REC_REGISTRATION_CAT_SECTION_ID` END ASC, 
		CASE WHEN PARAM_ORDER_FIELD = 'REC_REGISTRATION_CAT_SECTION_ID' AND PARAM_ORDER_TYPE = 'DESC' THEN `record_registration`.`REC_REGISTRATION_CAT_SECTION_ID` END DESC,	
		CASE WHEN PARAM_ORDER_FIELD = 'REC_REGISTRATION_FIRST_NAME' AND PARAM_ORDER_TYPE = 'ASC' THEN `record_registration`.`REC_REGISTRATION_FIRST_NAME` END ASC, 
		CASE WHEN PARAM_ORDER_FIELD = 'REC_REGISTRATION_FIRST_NAME' AND PARAM_ORDER_TYPE = 'DESC' THEN `record_registration`.`REC_REGISTRATION_FIRST_NAME` END DESC,	
		CASE WHEN PARAM_ORDER_FIELD = 'REC_REGISTRATION_MIDDLE_NAME' AND PARAM_ORDER_TYPE = 'ASC' THEN `record_registration`.`REC_REGISTRATION_MIDDLE_NAME` END ASC, 
		CASE WHEN PARAM_ORDER_FIELD = 'REC_REGISTRATION_MIDDLE_NAME' AND PARAM_ORDER_TYPE = 'DESC' THEN `record_registration`.`REC_REGISTRATION_MIDDLE_NAME` END DESC,	
		CASE WHEN PARAM_ORDER_FIELD = 'REC_REGISTRATION_LAST_NAME' AND PARAM_ORDER_TYPE = 'ASC' THEN `record_registration`.`REC_REGISTRATION_LAST_NAME` END ASC, 
		CASE WHEN PARAM_ORDER_FIELD = 'REC_REGISTRATION_LAST_NAME' AND PARAM_ORDER_TYPE = 'DESC' THEN `record_registration`.`REC_REGISTRATION_LAST_NAME` END DESC,	
		CASE WHEN PARAM_ORDER_FIELD = 'REC_REGISTRATION_SUFFIX' AND PARAM_ORDER_TYPE = 'ASC' THEN `record_registration`.`REC_REGISTRATION_SUFFIX` END ASC, 
		CASE WHEN PARAM_ORDER_FIELD = 'REC_REGISTRATION_SUFFIX' AND PARAM_ORDER_TYPE = 'DESC' THEN `record_registration`.`REC_REGISTRATION_SUFFIX` END DESC,	
		CASE WHEN PARAM_ORDER_FIELD = 'REC_REGISTRATION_SYS_GENDER_ID' AND PARAM_ORDER_TYPE = 'ASC' THEN `record_registration`.`REC_REGISTRATION_SYS_GENDER_ID` END ASC, 
		CASE WHEN PARAM_ORDER_FIELD = 'REC_REGISTRATION_SYS_GENDER_ID' AND PARAM_ORDER_TYPE = 'DESC' THEN `record_registration`.`REC_REGISTRATION_SYS_GENDER_ID` END DESC,	
		CASE WHEN PARAM_ORDER_FIELD = 'REC_REGISTRATION_NOTIFY_PHONE' AND PARAM_ORDER_TYPE = 'ASC' THEN `record_registration`.`REC_REGISTRATION_NOTIFY_PHONE` END ASC, 
		CASE WHEN PARAM_ORDER_FIELD = 'REC_REGISTRATION_NOTIFY_PHONE' AND PARAM_ORDER_TYPE = 'DESC' THEN `record_registration`.`REC_REGISTRATION_NOTIFY_PHONE` END DESC,	
		CASE WHEN PARAM_ORDER_FIELD = 'REC_REGISTRATION_EMCONTACT_PERSON' AND PARAM_ORDER_TYPE = 'ASC' THEN `record_registration`.`REC_REGISTRATION_EMCONTACT_PERSON` END ASC, 
		CASE WHEN PARAM_ORDER_FIELD = 'REC_REGISTRATION_EMCONTACT_PERSON' AND PARAM_ORDER_TYPE = 'DESC' THEN `record_registration`.`REC_REGISTRATION_EMCONTACT_PERSON` END DESC,	
		CASE WHEN PARAM_ORDER_FIELD = 'REC_REGISTRATION_EMCONTACT_NUMBER' AND PARAM_ORDER_TYPE = 'ASC' THEN `record_registration`.`REC_REGISTRATION_EMCONTACT_NUMBER` END ASC, 
		CASE WHEN PARAM_ORDER_FIELD = 'REC_REGISTRATION_EMCONTACT_NUMBER' AND PARAM_ORDER_TYPE = 'DESC' THEN `record_registration`.`REC_REGISTRATION_EMCONTACT_NUMBER` END DESC,	
		CASE WHEN PARAM_ORDER_FIELD = 'REC_REGISTRATION_STATUS' AND PARAM_ORDER_TYPE = 'ASC' THEN `record_registration`.`REC_REGISTRATION_STATUS` END ASC, 
		CASE WHEN PARAM_ORDER_FIELD = 'REC_REGISTRATION_STATUS' AND PARAM_ORDER_TYPE = 'DESC' THEN `record_registration`.`REC_REGISTRATION_STATUS` END DESC,	

		-- Inner joins
		CASE WHEN PARAM_ORDER_FIELD = 'CAT_DEPARTMENT_ID' AND PARAM_ORDER_TYPE = 'ASC' THEN `category_department`.`CAT_DEPARTMENT_ID` END ASC, 
		CASE WHEN PARAM_ORDER_FIELD = 'CAT_DEPARTMENT_ID' AND PARAM_ORDER_TYPE = 'DESC' THEN `category_department`.`CAT_DEPARTMENT_ID` END DESC,
		CASE WHEN PARAM_ORDER_FIELD = 'CAT_DEPARTMENT_DESCRIPTION' AND PARAM_ORDER_TYPE = 'ASC' THEN `category_department`.`CAT_DEPARTMENT_DESCRIPTION` END ASC, 
		CASE WHEN PARAM_ORDER_FIELD = 'CAT_DEPARTMENT_DESCRIPTION' AND PARAM_ORDER_TYPE = 'DESC' THEN `category_department`.`CAT_DEPARTMENT_DESCRIPTION` END DESC,
		CASE WHEN PARAM_ORDER_FIELD = 'CAT_DEPARTMENT_STATUS' AND PARAM_ORDER_TYPE = 'ASC' THEN `category_department`.`CAT_DEPARTMENT_STATUS` END ASC, 
		CASE WHEN PARAM_ORDER_FIELD = 'CAT_DEPARTMENT_STATUS' AND PARAM_ORDER_TYPE = 'DESC' THEN `category_department`.`CAT_DEPARTMENT_STATUS` END DESC,
		CASE WHEN PARAM_ORDER_FIELD = 'CAT_SECTION_ID' AND PARAM_ORDER_TYPE = 'ASC' THEN `category_section`.`CAT_SECTION_ID` END ASC, 
		CASE WHEN PARAM_ORDER_FIELD = 'CAT_SECTION_ID' AND PARAM_ORDER_TYPE = 'DESC' THEN `category_section`.`CAT_SECTION_ID` END DESC,
		CASE WHEN PARAM_ORDER_FIELD = 'CAT_SECTION_CAT_DEPARTMENT_ID' AND PARAM_ORDER_TYPE = 'ASC' THEN `category_section`.`CAT_SECTION_CAT_DEPARTMENT_ID` END ASC, 
		CASE WHEN PARAM_ORDER_FIELD = 'CAT_SECTION_CAT_DEPARTMENT_ID' AND PARAM_ORDER_TYPE = 'DESC' THEN `category_section`.`CAT_SECTION_CAT_DEPARTMENT_ID` END DESC,
		CASE WHEN PARAM_ORDER_FIELD = 'CAT_SECTION_DESCRIPTION' AND PARAM_ORDER_TYPE = 'ASC' THEN `category_section`.`CAT_SECTION_DESCRIPTION` END ASC, 
		CASE WHEN PARAM_ORDER_FIELD = 'CAT_SECTION_DESCRIPTION' AND PARAM_ORDER_TYPE = 'DESC' THEN `category_section`.`CAT_SECTION_DESCRIPTION` END DESC,
		CASE WHEN PARAM_ORDER_FIELD = 'CAT_SECTION_STATUS' AND PARAM_ORDER_TYPE = 'ASC' THEN `category_section`.`CAT_SECTION_STATUS` END ASC, 
		CASE WHEN PARAM_ORDER_FIELD = 'CAT_SECTION_STATUS' AND PARAM_ORDER_TYPE = 'DESC' THEN `category_section`.`CAT_SECTION_STATUS` END DESC,
		CASE WHEN PARAM_ORDER_FIELD = 'SYS_GENDER_ID' AND PARAM_ORDER_TYPE = 'ASC' THEN `system_gender`.`SYS_GENDER_ID` END ASC, 
		CASE WHEN PARAM_ORDER_FIELD = 'SYS_GENDER_ID' AND PARAM_ORDER_TYPE = 'DESC' THEN `system_gender`.`SYS_GENDER_ID` END DESC,
		CASE WHEN PARAM_ORDER_FIELD = 'SYS_GENDER_CODE' AND PARAM_ORDER_TYPE = 'ASC' THEN `system_gender`.`SYS_GENDER_CODE` END ASC, 
		CASE WHEN PARAM_ORDER_FIELD = 'SYS_GENDER_CODE' AND PARAM_ORDER_TYPE = 'DESC' THEN `system_gender`.`SYS_GENDER_CODE` END DESC,
		CASE WHEN PARAM_ORDER_FIELD = 'SYS_GENDER_DESCRIPTION' AND PARAM_ORDER_TYPE = 'ASC' THEN `system_gender`.`SYS_GENDER_DESCRIPTION` END ASC, 
		CASE WHEN PARAM_ORDER_FIELD = 'SYS_GENDER_DESCRIPTION' AND PARAM_ORDER_TYPE = 'DESC' THEN `system_gender`.`SYS_GENDER_DESCRIPTION` END DESC,
		CASE WHEN PARAM_ORDER_FIELD = 'SYS_GENDER_STATUS' AND PARAM_ORDER_TYPE = 'ASC' THEN `system_gender`.`SYS_GENDER_STATUS` END ASC, 
		CASE WHEN PARAM_ORDER_FIELD = 'SYS_GENDER_STATUS' AND PARAM_ORDER_TYPE = 'DESC' THEN `system_gender`.`SYS_GENDER_STATUS` END DESC,
		
		-- EXTRA
		CASE WHEN PARAM_ORDER_FIELD <> 'REC_REGISTRATION_LAST_NAME' THEN `record_registration`.`REC_REGISTRATION_LAST_NAME` END ASC
		
	-- LIMIT & OFFSET
	-- ####################################################		
	LIMIT PARAM_SKIP, PARAM_LIMIT;
	
	
	
	-- EXIT PROCEDURE
	-- =========================================================================================
	LEAVE SP_GET;
			
END ;;
DELIMITER ;
/*!50003 SET sql_mode              = @saved_sql_mode */ ;
/*!50003 SET character_set_client  = @saved_cs_client */ ;
/*!50003 SET character_set_results = @saved_cs_results */ ;
/*!50003 SET collation_connection  = @saved_col_connection */ ;
/*!50003 DROP PROCEDURE IF EXISTS `RECORD_REGISTRATION_SAVE` */;
/*!50003 SET @saved_cs_client      = @@character_set_client */ ;
/*!50003 SET @saved_cs_results     = @@character_set_results */ ;
/*!50003 SET @saved_col_connection = @@collation_connection */ ;
/*!50003 SET character_set_client  = latin1 */ ;
/*!50003 SET character_set_results = latin1 */ ;
/*!50003 SET collation_connection  = latin1_swedish_ci */ ;
/*!50003 SET @saved_sql_mode       = @@sql_mode */ ;
/*!50003 SET sql_mode              = '' */ ;
DELIMITER ;;
CREATE DEFINER=`root`@`localhost` PROCEDURE `RECORD_REGISTRATION_SAVE`(
	IN `PARAM_REC_REGISTRATION_ID` BIGINT,
	IN `PARAM_REC_REGISTRATION_REC_USER_ID` BIGINT,
	IN `PARAM_REC_REGISTRATION_CAT_DEPARTMENT_ID` BIGINT,
	IN `PARAM_REC_REGISTRATION_CAT_SECTION_ID` BIGINT,
	IN `PARAM_REC_REGISTRATION_FIRST_NAME` VARCHAR(400),
	IN `PARAM_REC_REGISTRATION_MIDDLE_NAME` VARCHAR(400),
	IN `PARAM_REC_REGISTRATION_LAST_NAME` VARCHAR(400),
	IN `PARAM_REC_REGISTRATION_SUFFIX` VARCHAR(40),
	IN `PARAM_REC_REGISTRATION_SYS_GENDER_ID` BIGINT,
	IN `PARAM_REC_REGISTRATION_NOTIFY_PHONE` VARCHAR(40),
	IN `PARAM_REC_REGISTRATION_EMCONTACT_PERSON` VARCHAR(1000),
	IN `PARAM_REC_REGISTRATION_EMCONTACT_NUMBER` VARCHAR(40),
	IN `PARAM_REC_REGISTRATION_STATUS` TINYINT,

	IN `PARAM_REQUESTER_USERNAME` VARCHAR(500),
	IN `PARAM_REQUESTER_PASSWORD` VARCHAR(500),
	IN `PARAM_REQUESTER_PROXY_ID` BIGINT,
	IN `PARAM_REQUESTER_PROXY_PASSWORD` VARCHAR(1000),
	IN `PARAM_REQUESTER_DEVICE_PUBLIC_KEY` VARCHAR(1000),
	IN `PARAM_REQUESTER_DEVICE_PRIVATE_KEY` VARCHAR(1000),
	
	IN `PARAM_REQUESTER_IP` VARCHAR(1000),
	IN `PARAM_UNIQUE_SESSION_ID` VARCHAR(1000),
	IN `PARAM_SUPPRESS_RETURN` BIT,
	
	IN `PARAM_SYNC_SERVER_DESCRIPTION` VARCHAR(500), 
	IN `PARAM_SYNC_SERVER_UNIQUE_KEY` VARCHAR(500)
)
SP_SAVE:
BEGIN


	-- 1) DECLARE LOCAL PARAMETERS
	-- _______________________________________________________________________
	
	-- Status
	-- ...........................................
	DECLARE STATUS_INACTIVE TINYINT DEFAULT 1;
	DECLARE STATUS_ACTIVE TINYINT DEFAULT 2;
	DECLARE STATUS_CLOSED TINYINT DEFAULT 3;
	DECLARE STATUS_COMPLETED TINYINT DEFAULT 4;

	-- Audit Handler
	-- ...........................................
	DECLARE TEMP_RECORD_EXISTS BIT DEFAULT 0;
	DECLARE TEMP_MODULE_KEYWORD VARCHAR(500) DEFAULT 'record_registration';
	DECLARE TEMP_SP_OBJECTIVE VARCHAR(500) DEFAULT 'add/edit Registration record';
	DECLARE TEMP_ERR_MESSAGE VARCHAR(500) DEFAULT '';
	DECLARE ERR BIGINT DEFAULT 0;
	DECLARE TEMP_RECORD_CHANGES VARCHAR(16000) DEFAULT '';
	DECLARE TEMP_RECORD_BINDED BIT DEFAULT 0;

	-- Authentication
	-- ...........................................
	DECLARE TEMP_ACCESS_RIGHTS_DENIED BIT DEFAULT 0;
	DECLARE TEMP_ACCESS_RIGHTS_HAS_OVERRIDE BIT DEFAULT 0;
	DECLARE TEMP_SYNC_SERVER_ID BIGINT DEFAULT 0;
	DECLARE TEMP_SYNC_IS_SERVER_REQUEST BIT DEFAULT 0;
	DECLARE TEMP_AUTHENTICATED_ACCOUNT_ID BIGINT DEFAULT `ACCOUNT_MEMBER@ACC_ACCOUNT_ID_FROM_LOGIN`(PARAM_REQUESTER_USERNAME, PARAM_REQUESTER_PASSWORD);
	DECLARE TEMP_AUTHENTICATED_ACCOUNT_LEVEL BIGINT DEFAULT 0;
	DECLARE TEMP_AUTHENTICATED_ACCOUNT_GROUP BIGINT DEFAULT 0;
	
	-- Local Parameters
	-- ...........................................
	DECLARE TEMP_NOW DATETIME(6) DEFAULT `SYSTEM_VAR@NOW`('', 1);
	DECLARE TEMP_RECORD_COUNT BIGINT DEFAULT 0;

	-- AutoGen Parameters
	-- ...........................................
	
	-- Local value holder
	-- ...........................................
	DECLARE TEMP_REC_REGISTRATION_REC_USER_ID BIGINT DEFAULT 0; 
	DECLARE TEMP_REC_REGISTRATION_CAT_DEPARTMENT_ID BIGINT DEFAULT 0; 
	DECLARE TEMP_REC_REGISTRATION_CAT_SECTION_ID BIGINT DEFAULT 0; 
	DECLARE TEMP_REC_REGISTRATION_FIRST_NAME VARCHAR(400) DEFAULT ''; 
	DECLARE TEMP_REC_REGISTRATION_MIDDLE_NAME VARCHAR(400) DEFAULT ''; 
	DECLARE TEMP_REC_REGISTRATION_LAST_NAME VARCHAR(400) DEFAULT ''; 
	DECLARE TEMP_REC_REGISTRATION_SUFFIX VARCHAR(40) DEFAULT ''; 
	DECLARE TEMP_REC_REGISTRATION_SYS_GENDER_ID BIGINT DEFAULT 0; 
	DECLARE TEMP_REC_REGISTRATION_NOTIFY_PHONE VARCHAR(40) DEFAULT ''; 
	DECLARE TEMP_REC_REGISTRATION_EMCONTACT_PERSON VARCHAR(1000) DEFAULT ''; 
	DECLARE TEMP_REC_REGISTRATION_EMCONTACT_NUMBER VARCHAR(40) DEFAULT ''; 
	DECLARE TEMP_REC_REGISTRATION_STATUS TINYINT DEFAULT 0; 
	
	DECLARE REDUND_REC_REGISTRATION_ID BIGINT DEFAULT 0; 


	-- 2) Try Catch / Throw
	-- _______________________________________________________________________
	DECLARE EXIT HANDLER FOR SQLEXCEPTION
	BEGIN
		RESIGNAL;
	END;



	-- 3) Prepare SYNC
	-- _______________________________________________________________________

	-- IS RECORD EXISTS		
	-- ####################################################	
	SET TEMP_RECORD_EXISTS = `RECORD_REGISTRATION@REC_REGISTRATION_ID_EXISTS`(PARAM_REC_REGISTRATION_ID, 0);

		
		
	-- 4) PREPARE AUTOGEN DATA (IF EXISTS)
	-- _______________________________________________________________________
	IF TEMP_SYNC_IS_SERVER_REQUEST = 0 THEN
		-- Just to keep at least one line within condition
		SET TEMP_SYNC_IS_SERVER_REQUEST = 0;
		
		-- Actual Functionalities here
		-- USE DEFAULT VALUE (String)
	END IF;



	-- 5) IF ALREADY EXIST, FILL MISSING DATA
	-- _______________________________________________________________________
	IF TEMP_RECORD_EXISTS = 1 THEN
		SELECT
			`record_registration`.`REC_REGISTRATION_REC_USER_ID`, 	
			`record_registration`.`REC_REGISTRATION_CAT_DEPARTMENT_ID`, 	
			`record_registration`.`REC_REGISTRATION_CAT_SECTION_ID`, 	
			`record_registration`.`REC_REGISTRATION_FIRST_NAME`, 	
			`record_registration`.`REC_REGISTRATION_MIDDLE_NAME`, 	
			`record_registration`.`REC_REGISTRATION_LAST_NAME`, 	
			`record_registration`.`REC_REGISTRATION_SUFFIX`, 	
			`record_registration`.`REC_REGISTRATION_SYS_GENDER_ID`, 	
			`record_registration`.`REC_REGISTRATION_NOTIFY_PHONE`, 	
			`record_registration`.`REC_REGISTRATION_EMCONTACT_PERSON`, 	
			`record_registration`.`REC_REGISTRATION_EMCONTACT_NUMBER`, 	
			`record_registration`.`REC_REGISTRATION_STATUS`	
		INTO
			TEMP_REC_REGISTRATION_REC_USER_ID, 	
			TEMP_REC_REGISTRATION_CAT_DEPARTMENT_ID, 	
			TEMP_REC_REGISTRATION_CAT_SECTION_ID, 	
			TEMP_REC_REGISTRATION_FIRST_NAME, 	
			TEMP_REC_REGISTRATION_MIDDLE_NAME, 	
			TEMP_REC_REGISTRATION_LAST_NAME, 	
			TEMP_REC_REGISTRATION_SUFFIX, 	
			TEMP_REC_REGISTRATION_SYS_GENDER_ID, 	
			TEMP_REC_REGISTRATION_NOTIFY_PHONE, 	
			TEMP_REC_REGISTRATION_EMCONTACT_PERSON, 	
			TEMP_REC_REGISTRATION_EMCONTACT_NUMBER, 	
			TEMP_REC_REGISTRATION_STATUS	

		FROM `record_registration`
		WHERE
			`record_registration`.`REC_REGISTRATION_ID` = PARAM_REC_REGISTRATION_ID
		LIMIT 1;

		-- Replace NULLs with the existing data.
		SET PARAM_REC_REGISTRATION_CAT_DEPARTMENT_ID = `SYSTEM_VAR@REPLACE_NULL@BIGINT`(PARAM_REC_REGISTRATION_CAT_DEPARTMENT_ID, TEMP_REC_REGISTRATION_CAT_DEPARTMENT_ID, 1, 1);
		SET PARAM_REC_REGISTRATION_CAT_SECTION_ID = `SYSTEM_VAR@REPLACE_NULL@BIGINT`(PARAM_REC_REGISTRATION_CAT_SECTION_ID, TEMP_REC_REGISTRATION_CAT_SECTION_ID, 1, 1);
		SET PARAM_REC_REGISTRATION_FIRST_NAME = `SYSTEM_VAR@REPLACE_NULL@NVARCHAR`(PARAM_REC_REGISTRATION_FIRST_NAME, TEMP_REC_REGISTRATION_FIRST_NAME, 1);
		SET PARAM_REC_REGISTRATION_MIDDLE_NAME = `SYSTEM_VAR@REPLACE_NULL@NVARCHAR`(PARAM_REC_REGISTRATION_MIDDLE_NAME, TEMP_REC_REGISTRATION_MIDDLE_NAME, 0);
		SET PARAM_REC_REGISTRATION_LAST_NAME = `SYSTEM_VAR@REPLACE_NULL@NVARCHAR`(PARAM_REC_REGISTRATION_LAST_NAME, TEMP_REC_REGISTRATION_LAST_NAME, 1);
		SET PARAM_REC_REGISTRATION_SUFFIX = `SYSTEM_VAR@REPLACE_NULL@NVARCHAR`(PARAM_REC_REGISTRATION_SUFFIX, TEMP_REC_REGISTRATION_SUFFIX, 0);
		SET PARAM_REC_REGISTRATION_SYS_GENDER_ID = `SYSTEM_VAR@REPLACE_NULL@BIGINT`(PARAM_REC_REGISTRATION_SYS_GENDER_ID, TEMP_REC_REGISTRATION_SYS_GENDER_ID, 1, 1);
		SET PARAM_REC_REGISTRATION_NOTIFY_PHONE = `SYSTEM_VAR@REPLACE_NULL@NVARCHAR`(PARAM_REC_REGISTRATION_NOTIFY_PHONE, TEMP_REC_REGISTRATION_NOTIFY_PHONE, 1);
		SET PARAM_REC_REGISTRATION_EMCONTACT_PERSON = `SYSTEM_VAR@REPLACE_NULL@NVARCHAR`(PARAM_REC_REGISTRATION_EMCONTACT_PERSON, TEMP_REC_REGISTRATION_EMCONTACT_PERSON, 0);
		SET PARAM_REC_REGISTRATION_EMCONTACT_NUMBER = `SYSTEM_VAR@REPLACE_NULL@NVARCHAR`(PARAM_REC_REGISTRATION_EMCONTACT_NUMBER, TEMP_REC_REGISTRATION_EMCONTACT_NUMBER, 0);
		SET PARAM_REC_REGISTRATION_STATUS = `SYSTEM_VAR@REPLACE_NULL@TINYINT`(PARAM_REC_REGISTRATION_STATUS, TEMP_REC_REGISTRATION_STATUS, 1, 1);
		
		-- AUTO GEN (NON-UPDATABLES)		
		
		-- AUTO GEN (UPDATABLE WITH STATUS CHANGE)

		-- AUTO GEN (UPDATABLE WITH STATUS [ACTIVE/INACTIVE] CHANGE)
		
		-- NON-UPDATABLE
		
		-- NON-UPDATABLE BUT NULL
		SET PARAM_REC_REGISTRATION_REC_USER_ID = `SYSTEM_VAR@REPLACE_NULL@BIGINT`(TEMP_REC_REGISTRATION_REC_USER_ID, PARAM_REC_REGISTRATION_REC_USER_ID, 1, 1);
		
	ELSE
		SET PARAM_REC_REGISTRATION_REC_USER_ID = `SYSTEM_VAR@REPLACE_NULL@BIGINT`(PARAM_REC_REGISTRATION_REC_USER_ID, 0, 0, 1);
		SET PARAM_REC_REGISTRATION_CAT_DEPARTMENT_ID = `SYSTEM_VAR@REPLACE_NULL@BIGINT`(PARAM_REC_REGISTRATION_CAT_DEPARTMENT_ID, 0, 1, 1);
		SET PARAM_REC_REGISTRATION_CAT_SECTION_ID = `SYSTEM_VAR@REPLACE_NULL@BIGINT`(PARAM_REC_REGISTRATION_CAT_SECTION_ID, 0, 1, 1);
		SET PARAM_REC_REGISTRATION_FIRST_NAME = `SYSTEM_VAR@REPLACE_NULL@NVARCHAR`(PARAM_REC_REGISTRATION_FIRST_NAME, '', 1);
		SET PARAM_REC_REGISTRATION_MIDDLE_NAME = `SYSTEM_VAR@REPLACE_NULL@NVARCHAR`(PARAM_REC_REGISTRATION_MIDDLE_NAME, '', 0);
		SET PARAM_REC_REGISTRATION_LAST_NAME = `SYSTEM_VAR@REPLACE_NULL@NVARCHAR`(PARAM_REC_REGISTRATION_LAST_NAME, '', 1);
		SET PARAM_REC_REGISTRATION_SUFFIX = `SYSTEM_VAR@REPLACE_NULL@NVARCHAR`(PARAM_REC_REGISTRATION_SUFFIX, '', 0);
		SET PARAM_REC_REGISTRATION_SYS_GENDER_ID = `SYSTEM_VAR@REPLACE_NULL@BIGINT`(PARAM_REC_REGISTRATION_SYS_GENDER_ID, 0, 1, 1);
		SET PARAM_REC_REGISTRATION_NOTIFY_PHONE = `SYSTEM_VAR@REPLACE_NULL@NVARCHAR`(PARAM_REC_REGISTRATION_NOTIFY_PHONE, '', 1);
		SET PARAM_REC_REGISTRATION_EMCONTACT_PERSON = `SYSTEM_VAR@REPLACE_NULL@NVARCHAR`(PARAM_REC_REGISTRATION_EMCONTACT_PERSON, '', 0);
		SET PARAM_REC_REGISTRATION_EMCONTACT_NUMBER = `SYSTEM_VAR@REPLACE_NULL@NVARCHAR`(PARAM_REC_REGISTRATION_EMCONTACT_NUMBER, '', 0);
		SET PARAM_REC_REGISTRATION_STATUS = `SYSTEM_VAR@REPLACE_NULL@TINYINT`(PARAM_REC_REGISTRATION_STATUS, 0, 1, 1);
		
	END IF;

	

	-- 6) PREPARE AUDIT TRAIL
	-- _______________________________________________________________________
	IF TEMP_REC_REGISTRATION_REC_USER_ID <> PARAM_REC_REGISTRATION_REC_USER_ID THEN
		SET TEMP_RECORD_CHANGES = 
		`SYSTEM_VAR@CONCAT_ADD`(' | ', TEMP_RECORD_CHANGES, CONCAT_WS(' ', 'User: "', TEMP_REC_REGISTRATION_REC_USER_ID, '" > "', PARAM_REC_REGISTRATION_REC_USER_ID, '"'));
	END IF;	
	IF TEMP_REC_REGISTRATION_CAT_DEPARTMENT_ID <> PARAM_REC_REGISTRATION_CAT_DEPARTMENT_ID THEN
		SET TEMP_RECORD_CHANGES = 
		`SYSTEM_VAR@CONCAT_ADD`(' | ', TEMP_RECORD_CHANGES, CONCAT_WS(' ', 'Department: "', TEMP_REC_REGISTRATION_CAT_DEPARTMENT_ID, '" > "', PARAM_REC_REGISTRATION_CAT_DEPARTMENT_ID, '"'));
	END IF;	
	IF TEMP_REC_REGISTRATION_CAT_SECTION_ID <> PARAM_REC_REGISTRATION_CAT_SECTION_ID THEN
		SET TEMP_RECORD_CHANGES = 
		`SYSTEM_VAR@CONCAT_ADD`(' | ', TEMP_RECORD_CHANGES, CONCAT_WS(' ', 'Section: "', TEMP_REC_REGISTRATION_CAT_SECTION_ID, '" > "', PARAM_REC_REGISTRATION_CAT_SECTION_ID, '"'));
	END IF;	
	IF BINARY TEMP_REC_REGISTRATION_FIRST_NAME <> PARAM_REC_REGISTRATION_FIRST_NAME THEN
		SET TEMP_RECORD_CHANGES = 
		`SYSTEM_VAR@CONCAT_ADD`(' | ', TEMP_RECORD_CHANGES, CONCAT_WS(' ', 'First name: "', TEMP_REC_REGISTRATION_FIRST_NAME, '" > "', PARAM_REC_REGISTRATION_FIRST_NAME, '"'));
	END IF;
	IF BINARY TEMP_REC_REGISTRATION_MIDDLE_NAME <> PARAM_REC_REGISTRATION_MIDDLE_NAME THEN
		SET TEMP_RECORD_CHANGES = 
		`SYSTEM_VAR@CONCAT_ADD`(' | ', TEMP_RECORD_CHANGES, CONCAT_WS(' ', 'Middle name: "', TEMP_REC_REGISTRATION_MIDDLE_NAME, '" > "', PARAM_REC_REGISTRATION_MIDDLE_NAME, '"'));
	END IF;
	IF BINARY TEMP_REC_REGISTRATION_LAST_NAME <> PARAM_REC_REGISTRATION_LAST_NAME THEN
		SET TEMP_RECORD_CHANGES = 
		`SYSTEM_VAR@CONCAT_ADD`(' | ', TEMP_RECORD_CHANGES, CONCAT_WS(' ', 'Last name: "', TEMP_REC_REGISTRATION_LAST_NAME, '" > "', PARAM_REC_REGISTRATION_LAST_NAME, '"'));
	END IF;
	IF BINARY TEMP_REC_REGISTRATION_SUFFIX <> PARAM_REC_REGISTRATION_SUFFIX THEN
		SET TEMP_RECORD_CHANGES = 
		`SYSTEM_VAR@CONCAT_ADD`(' | ', TEMP_RECORD_CHANGES, CONCAT_WS(' ', 'Suffix: "', TEMP_REC_REGISTRATION_SUFFIX, '" > "', PARAM_REC_REGISTRATION_SUFFIX, '"'));
	END IF;
	IF TEMP_REC_REGISTRATION_SYS_GENDER_ID <> PARAM_REC_REGISTRATION_SYS_GENDER_ID THEN
		SET TEMP_RECORD_CHANGES = 
		`SYSTEM_VAR@CONCAT_ADD`(' | ', TEMP_RECORD_CHANGES, CONCAT_WS(' ', 'Gender: "', TEMP_REC_REGISTRATION_SYS_GENDER_ID, '" > "', PARAM_REC_REGISTRATION_SYS_GENDER_ID, '"'));
	END IF;	
	IF BINARY TEMP_REC_REGISTRATION_NOTIFY_PHONE <> PARAM_REC_REGISTRATION_NOTIFY_PHONE THEN
		SET TEMP_RECORD_CHANGES = 
		`SYSTEM_VAR@CONCAT_ADD`(' | ', TEMP_RECORD_CHANGES, CONCAT_WS(' ', 'Notification Phone Number: "', TEMP_REC_REGISTRATION_NOTIFY_PHONE, '" > "', PARAM_REC_REGISTRATION_NOTIFY_PHONE, '"'));
	END IF;
	IF BINARY TEMP_REC_REGISTRATION_EMCONTACT_PERSON <> PARAM_REC_REGISTRATION_EMCONTACT_PERSON THEN
		SET TEMP_RECORD_CHANGES = 
		`SYSTEM_VAR@CONCAT_ADD`(' | ', TEMP_RECORD_CHANGES, CONCAT_WS(' ', 'Emergency Contact Person: "', TEMP_REC_REGISTRATION_EMCONTACT_PERSON, '" > "', PARAM_REC_REGISTRATION_EMCONTACT_PERSON, '"'));
	END IF;
	IF BINARY TEMP_REC_REGISTRATION_EMCONTACT_NUMBER <> PARAM_REC_REGISTRATION_EMCONTACT_NUMBER THEN
		SET TEMP_RECORD_CHANGES = 
		`SYSTEM_VAR@CONCAT_ADD`(' | ', TEMP_RECORD_CHANGES, CONCAT_WS(' ', 'Emergency Contact Numbher: "', TEMP_REC_REGISTRATION_EMCONTACT_NUMBER, '" > "', PARAM_REC_REGISTRATION_EMCONTACT_NUMBER, '"'));
	END IF;
	IF TEMP_REC_REGISTRATION_STATUS <> PARAM_REC_REGISTRATION_STATUS THEN
		SET TEMP_RECORD_CHANGES = 
		`SYSTEM_VAR@CONCAT_ADD`(' | ', TEMP_RECORD_CHANGES, CONCAT_WS(' ', 'Status: "', TEMP_REC_REGISTRATION_STATUS, '" > "', PARAM_REC_REGISTRATION_STATUS, '"'));
	END IF;	
		
	-- No Changes in data, reject request
	-- ####################################################
	IF CHARACTER_LENGTH(TEMP_RECORD_CHANGES) = 0 THEN
		IF PARAM_SUPPRESS_RETURN = 0 THEN
			SELECT PARAM_REC_REGISTRATION_ID AS INSERTED_ID;
		END IF;
		LEAVE SP_SAVE;
	END IF;



	-- 7) VALIDATE
	-- _______________________________________________________________________

	-- Access Rights [Device]
	-- ####################################################
	IF `ACCOUNT_DEVICE@HAS_PERMISSION`(PARAM_REQUESTER_DEVICE_PUBLIC_KEY, PARAM_REQUESTER_DEVICE_PRIVATE_KEY) = 0 THEN
		SET TEMP_ERR_MESSAGE = 'Your device is not authorized yet to access this server.';
		SET ERR = `RAISERROR`(TEMP_ERR_MESSAGE);		
	END IF;
		
		
	-- Access Rights [Account]
	-- ####################################################
	
	IF 
		-- [ADD] Access Rights
		(
			TEMP_RECORD_EXISTS = 0 AND
			`ACCOUNT_ACCESS_RIGHTS@HAS_PERMISSION`(PARAM_REQUESTER_USERNAME, PARAM_REQUESTER_PASSWORD, 0, TEMP_MODULE_KEYWORD, 2) = 0 AND
			`ACCOUNT_ACCESS_RIGHTS@PROXY_PERMISSION`(PARAM_REQUESTER_PROXY_ID, PARAM_REQUESTER_PROXY_PASSWORD, 0, TEMP_MODULE_KEYWORD, 2) = 0
		) OR
		
		-- [EDIT] Access Rights
		(
			TEMP_RECORD_EXISTS = 1 AND
			`ACCOUNT_ACCESS_RIGHTS@HAS_PERMISSION`(PARAM_REQUESTER_USERNAME, PARAM_REQUESTER_PASSWORD, 0, TEMP_MODULE_KEYWORD, 3) = 0 AND
			`ACCOUNT_ACCESS_RIGHTS@PROXY_PERMISSION`(PARAM_REQUESTER_PROXY_ID, PARAM_REQUESTER_PROXY_PASSWORD, 0, TEMP_MODULE_KEYWORD, 3) = 0
		)
	THEN
		SET TEMP_ACCESS_RIGHTS_DENIED = 1;
		CALL `ACCOUNT_ACCESS_RIGHTS_DENY`
		(
			0, TEMP_MODULE_KEYWORD, PARAM_REC_REGISTRATION_ID, 0, TEMP_SP_OBJECTIVE, TEMP_RECORD_CHANGES, 
			PARAM_REQUESTER_USERNAME, PARAM_REQUESTER_PASSWORD, 
			PARAM_REQUESTER_PROXY_ID, PARAM_REQUESTER_PROXY_PASSWORD,
			PARAM_REQUESTER_DEVICE_PUBLIC_KEY, PARAM_REQUESTER_DEVICE_PRIVATE_KEY,
			PARAM_REQUESTER_IP, PARAM_UNIQUE_SESSION_ID,
			TEMP_SYNC_SERVER_ID, PARAM_SUPPRESS_RETURN
		);
	END IF;
	SET TEMP_ACCESS_RIGHTS_HAS_OVERRIDE = `ACCOUNT_ACCESS_RIGHTS@HAS_PERMISSION`(PARAM_REQUESTER_USERNAME, PARAM_REQUESTER_PASSWORD, 0, TEMP_MODULE_KEYWORD, 4);
	

	-- Validation
	-- ####################################################
	IF TEMP_SYNC_IS_SERVER_REQUEST = 0 THEN
	

		-- FOREIGN KEY EXISTS
		-- ...........................................
		IF `CATEGORY_DEPARTMENT@CAT_DEPARTMENT_ID_EXISTS`(PARAM_REC_REGISTRATION_CAT_DEPARTMENT_ID, 0) =  0 THEN
			SET TEMP_ERR_MESSAGE = CONCAT_WS(' ', 'Given Department does not exists or is inactive. ID: ', PARAM_REC_REGISTRATION_CAT_DEPARTMENT_ID);
			SET ERR = `RAISERROR`(TEMP_ERR_MESSAGE);
		END IF;
		IF `CATEGORY_SECTION@CAT_SECTION_ID_EXISTS`(PARAM_REC_REGISTRATION_CAT_SECTION_ID, 0) =  0 THEN
			SET TEMP_ERR_MESSAGE = CONCAT_WS(' ', 'Given Section does not exists or is inactive. ID: ', PARAM_REC_REGISTRATION_CAT_SECTION_ID);
			SET ERR = `RAISERROR`(TEMP_ERR_MESSAGE);
		END IF;
		IF `SYSTEM_GENDER@SYS_GENDER_ID_EXISTS`(PARAM_REC_REGISTRATION_SYS_GENDER_ID, 0) =  0 THEN
			SET TEMP_ERR_MESSAGE = CONCAT_WS(' ', 'Given Gender does not exists or is inactive. ID: ', PARAM_REC_REGISTRATION_SYS_GENDER_ID);
			SET ERR = `RAISERROR`(TEMP_ERR_MESSAGE);
		END IF;
		
		-- FOREIGN (OPTIONAL)KEY EXISTS [Validates if not null]
		-- ...........................................
		IF 
			`SYSTEM_VAR@IS_NULL@BIGINT`(PARAM_REC_REGISTRATION_REC_USER_ID, 1, 1) = 0 AND
			`RECORD_USER@REC_USER_ID_EXISTS`(PARAM_REC_REGISTRATION_REC_USER_ID, 0) =  0 
		THEN
			SET TEMP_ERR_MESSAGE = CONCAT_WS(' ', 'Given User does not exists or is inactive. ID: ', PARAM_REC_REGISTRATION_REC_USER_ID);
			SET ERR = `RAISERROR`(TEMP_ERR_MESSAGE);
		END IF;
		
		-- IS_ALLOW_NULL = FALSE
		-- ...........................................
		IF PARAM_REC_REGISTRATION_MIDDLE_NAME IS NULL THEN
			CALL `VALIDATION_MISSING_FIELD`('`REC_REGISTRATION_MIDDLE_NAME`', '`NULL`');
		END IF;
		IF PARAM_REC_REGISTRATION_SUFFIX IS NULL THEN
			CALL `VALIDATION_MISSING_FIELD`('`REC_REGISTRATION_SUFFIX`', '`NULL`');
		END IF;
		IF PARAM_REC_REGISTRATION_EMCONTACT_PERSON IS NULL THEN
			CALL `VALIDATION_MISSING_FIELD`('`REC_REGISTRATION_EMCONTACT_PERSON`', '`NULL`');
		END IF;
		IF PARAM_REC_REGISTRATION_EMCONTACT_NUMBER IS NULL THEN
			CALL `VALIDATION_MISSING_FIELD`('`REC_REGISTRATION_EMCONTACT_NUMBER`', '`NULL`');
		END IF;
				
		-- IS_ALLOW_ZERO = FALSE
		-- ...........................................
		IF PARAM_REC_REGISTRATION_STATUS = 0 THEN
			CALL `VALIDATION_MISSING_FIELD`('`REC_REGISTRATION_STATUS`', '`NULL`');
		END IF;		
		
		-- IS_ALLOW_NEGATIVE = FALSE
		-- ...........................................
		IF PARAM_REC_REGISTRATION_STATUS < 0 THEN
			CALL `VALIDATION_NEGATIVE`('`REC_REGISTRATION_STATUS`', PARAM_REC_REGISTRATION_STATUS);
		END IF;		
		
		-- IS_ALLOW_EMPTY_STRING = FALSE
		-- ...........................................
		IF `SYSTEM_VAR@IS_NULL@NVARCHAR`(PARAM_REC_REGISTRATION_FIRST_NAME, 1) = 1 THEN
			CALL `VALIDATION_MISSING_FIELD`('`REC_REGISTRATION_FIRST_NAME`', '`NULL`');
		END IF;
		IF `SYSTEM_VAR@IS_NULL@NVARCHAR`(PARAM_REC_REGISTRATION_LAST_NAME, 1) = 1 THEN
			CALL `VALIDATION_MISSING_FIELD`('`REC_REGISTRATION_LAST_NAME`', '`NULL`');
		END IF;
		IF `SYSTEM_VAR@IS_NULL@NVARCHAR`(PARAM_REC_REGISTRATION_NOTIFY_PHONE, 1) = 1 THEN
			CALL `VALIDATION_MISSING_FIELD`('`REC_REGISTRATION_NOTIFY_PHONE`', '`NULL`');
		END IF;
		
		-- IS_STATUS
		-- ...........................................
		IF `SYSTEM_STATUS@SYS_STATUS_ID_EXISTS`(PARAM_REC_REGISTRATION_STATUS, 0) = 0 THEN
			SET TEMP_ERR_MESSAGE = CONCAT_WS(' ', 'Given STATUS[Status] does not exists or is inactive. ID: ', PARAM_REC_REGISTRATION_STATUS);
			SET ERR = `RAISERROR`(TEMP_ERR_MESSAGE);
		END IF;
		
		-- IS STATUS Active / Inactive
		-- ...........................................
		
		-- Minimum / Maximum Value
		-- ...........................................
		
		-- IS_UNIQUE = TRUE
		-- ...........................................
		
		-- RECORD IDENTIFIER
		-- ...........................................
		
		
		-- ON_UPDATE VALIDATION 
		-- ...........................................
		IF TEMP_RECORD_EXISTS = 1 THEN	
		
			-- Just to keep at least one line within condition
			SET TEMP_RECORD_EXISTS = 1;
			
		END IF;
		
	END IF;



	-- 8) INSERT / UPDATE
	-- _______________________________________________________________________

	-- INSERT NEW DATA
	-- ####################################################
	IF TEMP_RECORD_EXISTS = 0 THEN

		INSERT INTO
		`record_registration`
		(
			`record_registration`.`REC_REGISTRATION_REC_USER_ID`, 
			`record_registration`.`REC_REGISTRATION_CAT_DEPARTMENT_ID`, 
			`record_registration`.`REC_REGISTRATION_CAT_SECTION_ID`, 
			`record_registration`.`REC_REGISTRATION_FIRST_NAME`, 
			`record_registration`.`REC_REGISTRATION_MIDDLE_NAME`, 
			`record_registration`.`REC_REGISTRATION_LAST_NAME`, 
			`record_registration`.`REC_REGISTRATION_SUFFIX`, 
			`record_registration`.`REC_REGISTRATION_SYS_GENDER_ID`, 
			`record_registration`.`REC_REGISTRATION_NOTIFY_PHONE`, 
			`record_registration`.`REC_REGISTRATION_EMCONTACT_PERSON`, 
			`record_registration`.`REC_REGISTRATION_EMCONTACT_NUMBER`, 
			`record_registration`.`REC_REGISTRATION_STATUS`
		)
		VALUES
		(
			PARAM_REC_REGISTRATION_REC_USER_ID, 
			PARAM_REC_REGISTRATION_CAT_DEPARTMENT_ID, 
			PARAM_REC_REGISTRATION_CAT_SECTION_ID, 
			PARAM_REC_REGISTRATION_FIRST_NAME, 
			PARAM_REC_REGISTRATION_MIDDLE_NAME, 
			PARAM_REC_REGISTRATION_LAST_NAME, 
			PARAM_REC_REGISTRATION_SUFFIX, 
			PARAM_REC_REGISTRATION_SYS_GENDER_ID, 
			PARAM_REC_REGISTRATION_NOTIFY_PHONE, 
			PARAM_REC_REGISTRATION_EMCONTACT_PERSON, 
			PARAM_REC_REGISTRATION_EMCONTACT_NUMBER, 
			PARAM_REC_REGISTRATION_STATUS
		);	
		
		-- Update Audit trail with new ID	
		SET PARAM_REC_REGISTRATION_ID = LAST_INSERT_ID();



	-- UPDATING EXISTING RECORD
	-- ####################################################
	ELSE
		UPDATE `record_registration`
		SET
			`record_registration`.`REC_REGISTRATION_REC_USER_ID` = PARAM_REC_REGISTRATION_REC_USER_ID, 
			`record_registration`.`REC_REGISTRATION_CAT_DEPARTMENT_ID` = PARAM_REC_REGISTRATION_CAT_DEPARTMENT_ID, 
			`record_registration`.`REC_REGISTRATION_CAT_SECTION_ID` = PARAM_REC_REGISTRATION_CAT_SECTION_ID, 
			`record_registration`.`REC_REGISTRATION_FIRST_NAME` = PARAM_REC_REGISTRATION_FIRST_NAME, 
			`record_registration`.`REC_REGISTRATION_MIDDLE_NAME` = PARAM_REC_REGISTRATION_MIDDLE_NAME, 
			`record_registration`.`REC_REGISTRATION_LAST_NAME` = PARAM_REC_REGISTRATION_LAST_NAME, 
			`record_registration`.`REC_REGISTRATION_SUFFIX` = PARAM_REC_REGISTRATION_SUFFIX, 
			`record_registration`.`REC_REGISTRATION_SYS_GENDER_ID` = PARAM_REC_REGISTRATION_SYS_GENDER_ID, 
			`record_registration`.`REC_REGISTRATION_NOTIFY_PHONE` = PARAM_REC_REGISTRATION_NOTIFY_PHONE, 
			`record_registration`.`REC_REGISTRATION_EMCONTACT_PERSON` = PARAM_REC_REGISTRATION_EMCONTACT_PERSON, 
			`record_registration`.`REC_REGISTRATION_EMCONTACT_NUMBER` = PARAM_REC_REGISTRATION_EMCONTACT_NUMBER, 
			`record_registration`.`REC_REGISTRATION_STATUS` = PARAM_REC_REGISTRATION_STATUS
		WHERE
			`record_registration`.`REC_REGISTRATION_ID` = PARAM_REC_REGISTRATION_ID;

		IF 
			`SYSTEM_VAR@IS_NULL@BIGINT`(TEMP_REC_REGISTRATION_REC_USER_ID, 1, 1) = 1 AND 
			TEMP_REC_REGISTRATION_STATUS <> PARAM_REC_REGISTRATION_STATUS AND
			PARAM_REC_REGISTRATION_STATUS = STATUS_COMPLETED
		THEN
			-- Create User from registration
			CALL `RECORD_USER_SAVE`
			(
				0,
				PARAM_REC_REGISTRATION_CAT_DEPARTMENT_ID,
				PARAM_REC_REGISTRATION_CAT_SECTION_ID,
				PARAM_REC_REGISTRATION_FIRST_NAME,
				PARAM_REC_REGISTRATION_MIDDLE_NAME,
				PARAM_REC_REGISTRATION_LAST_NAME,
				PARAM_REC_REGISTRATION_SUFFIX,
				PARAM_REC_REGISTRATION_SYS_GENDER_ID,
				PARAM_REC_REGISTRATION_NOTIFY_PHONE,
				PARAM_REC_REGISTRATION_EMCONTACT_PERSON,
				PARAM_REC_REGISTRATION_EMCONTACT_NUMBER,
				STATUS_ACTIVE,

				PARAM_REQUESTER_USERNAME,
				PARAM_REQUESTER_PASSWORD,
				PARAM_REQUESTER_PROXY_ID,
				PARAM_REQUESTER_PROXY_PASSWORD,
				PARAM_REQUESTER_DEVICE_PUBLIC_KEY,
				PARAM_REQUESTER_DEVICE_PRIVATE_KEY,
	
				PARAM_REQUESTER_IP,
				PARAM_UNIQUE_SESSION_ID,
				PARAM_SUPPRESS_RETURN,
	
				PARAM_SYNC_SERVER_DESCRIPTION, 
				PARAM_SYNC_SERVER_UNIQUE_KEY
			);

			-- Get Inserted ID
			SELECT `REC_USER_ID`
			INTO PARAM_REC_REGISTRATION_REC_USER_ID
			FROM USER_SAVE_RESULT
			LIMIT 1;

			-- Update Record
			UPDATE `record_registration`
	
		SET
	
			`record_registration`.`REC_REGISTRATION_REC_USER_ID` = PARAM_REC_REGISTRATION_REC_USER_ID
	
		WHERE
	
			`record_registration`.`REC_REGISTRATION_ID` = PARAM_REC_REGISTRATION_ID;

		END IF;
	END IF;

	
	-- 9) AUDIT TRAIL
	-- _______________________________________________________________________
	CALL `ACCOUNT_AUDIT_TRAIL_SAVE`
	(
		0, TEMP_MODULE_KEYWORD, PARAM_REC_REGISTRATION_ID, 0, 'SAVE', TEMP_SP_OBJECTIVE, TEMP_RECORD_CHANGES, 
		PARAM_REQUESTER_USERNAME, PARAM_REQUESTER_PASSWORD, 
		PARAM_REQUESTER_PROXY_ID, PARAM_REQUESTER_PROXY_PASSWORD,
		PARAM_REQUESTER_DEVICE_PUBLIC_KEY, PARAM_REQUESTER_DEVICE_PRIVATE_KEY,
		PARAM_REQUESTER_IP, PARAM_UNIQUE_SESSION_ID,
		TEMP_SYNC_SERVER_ID, PARAM_SUPPRESS_RETURN
	);
	

	-- 10) RETURN RESULT
	-- _______________________________________________________________________
	IF PARAM_SUPPRESS_RETURN = 0 THEN
		SELECT 
			PARAM_REC_REGISTRATION_ID AS INSERTED_ID,
			TEMP_NOW AS SERVER_TIME;
	END IF;
	LEAVE SP_SAVE;


END ;;
DELIMITER ;
/*!50003 SET sql_mode              = @saved_sql_mode */ ;
/*!50003 SET character_set_client  = @saved_cs_client */ ;
/*!50003 SET character_set_results = @saved_cs_results */ ;
/*!50003 SET collation_connection  = @saved_col_connection */ ;
/*!50003 DROP PROCEDURE IF EXISTS `RECORD_USER_DELETE` */;
/*!50003 SET @saved_cs_client      = @@character_set_client */ ;
/*!50003 SET @saved_cs_results     = @@character_set_results */ ;
/*!50003 SET @saved_col_connection = @@collation_connection */ ;
/*!50003 SET character_set_client  = latin1 */ ;
/*!50003 SET character_set_results = latin1 */ ;
/*!50003 SET collation_connection  = latin1_swedish_ci */ ;
/*!50003 SET @saved_sql_mode       = @@sql_mode */ ;
/*!50003 SET sql_mode              = '' */ ;
DELIMITER ;;
CREATE DEFINER=`root`@`localhost` PROCEDURE `RECORD_USER_DELETE`(
	IN `PARAM_REC_USER_ID` BIGINT,

	IN `PARAM_REQUESTER_USERNAME` VARCHAR(500),
	IN `PARAM_REQUESTER_PASSWORD` VARCHAR(500),
	IN `PARAM_REQUESTER_PROXY_ID` BIGINT,
	IN `PARAM_REQUESTER_PROXY_PASSWORD` VARCHAR(1000),
	IN `PARAM_REQUESTER_DEVICE_PUBLIC_KEY` VARCHAR(1000),
	IN `PARAM_REQUESTER_DEVICE_PRIVATE_KEY` VARCHAR(1000),
	
	IN `PARAM_REQUESTER_IP` VARCHAR(1000),
	IN `PARAM_UNIQUE_SESSION_ID` VARCHAR(1000),
	IN `PARAM_SUPPRESS_RETURN` BIT,
	
	IN `PARAM_SYNC_SERVER_DESCRIPTION` VARCHAR(500), 
	IN `PARAM_SYNC_SERVER_UNIQUE_KEY` VARCHAR(500)
)
SP_DELETE:
BEGIN

	-- 1) DECLARE LOCAL PARAMETERS
	-- _______________________________________________________________________
	
	-- Status
	-- ...........................................
	DECLARE STATUS_INACTIVE TINYINT DEFAULT 1;
	DECLARE STATUS_ACTIVE TINYINT DEFAULT 2;
	DECLARE STATUS_CLOSED TINYINT DEFAULT 3;
	DECLARE STATUS_COMPLETED TINYINT DEFAULT 4;
	
	-- Audit Handler
	-- ...........................................
	DECLARE TEMP_RECORD_EXISTS BIT DEFAULT 0;
	DECLARE TEMP_MODULE_KEYWORD VARCHAR(500) DEFAULT 'record_user';
	DECLARE TEMP_SP_OBJECTIVE VARCHAR(500) DEFAULT 'delete User record';
	DECLARE TEMP_ERR_MESSAGE VARCHAR(500) DEFAULT '';
	DECLARE ERR BIGINT DEFAULT 0;
	DECLARE TEMP_RECORD_CHANGES VARCHAR(16000) DEFAULT '';
	DECLARE TEMP_RECORD_BINDED BIT DEFAULT 0;
	
	DECLARE TEMP_RECORD_BINDED_ID BIGINT DEFAULT 0;
	DECLARE TEMP_RECORD_BINDED_SERVER_ID BIGINT DEFAULT 0;
	
	-- Authentication
	-- ...........................................
	DECLARE TEMP_ACCESS_RIGHTS_DENIED BIT DEFAULT 0;
	DECLARE TEMP_SYNC_SERVER_ID BIGINT DEFAULT 0;
	DECLARE TEMP_SYNC_IS_SERVER_REQUEST BIT DEFAULT 0;
	DECLARE TEMP_AUTHENTICATED_ACCOUNT_ID BIGINT DEFAULT `ACCOUNT_MEMBER@ACC_ACCOUNT_ID_FROM_LOGIN`(PARAM_REQUESTER_USERNAME, PARAM_REQUESTER_PASSWORD);
	DECLARE TEMP_AUTHENTICATED_ACCOUNT_LEVEL BIGINT DEFAULT 0;
	DECLARE TEMP_AUTHENTICATED_ACCOUNT_GROUP BIGINT DEFAULT 0;

	-- Local value holder
	-- ...........................................
		DECLARE TEMP_REC_USER_CAT_DEPARTMENT_ID BIGINT DEFAULT 0; 
		DECLARE TEMP_REC_USER_CAT_SECTION_ID BIGINT DEFAULT 0; 
		DECLARE TEMP_REC_USER_UNIQUE_CODE VARCHAR(400) DEFAULT ''; 
		DECLARE TEMP_REC_USER_FIRST_NAME VARCHAR(400) DEFAULT ''; 
		DECLARE TEMP_REC_USER_MIDDLE_NAME VARCHAR(400) DEFAULT ''; 
		DECLARE TEMP_REC_USER_LAST_NAME VARCHAR(400) DEFAULT ''; 
		DECLARE TEMP_REC_USER_SUFFIX VARCHAR(40) DEFAULT ''; 
		DECLARE TEMP_REC_USER_SYS_GENDER_ID BIGINT DEFAULT 0; 
		DECLARE TEMP_REC_USER_NOTIFY_PHONE VARCHAR(40) DEFAULT ''; 
		DECLARE TEMP_REC_USER_EMCONTACT_PERSON VARCHAR(1000) DEFAULT ''; 
		DECLARE TEMP_REC_USER_EMCONTACT_NUMBER VARCHAR(40) DEFAULT ''; 
		DECLARE TEMP_REC_USER_STATUS TINYINT DEFAULT 0; 

	
	
	-- 2) Try Catch / Throw
	-- _______________________________________________________________________
	DECLARE EXIT HANDLER FOR SQLEXCEPTION
	BEGIN
		RESIGNAL;
	END;

	
	-- 3) Prepare SYNC
	-- _______________________________________________________________________
	
	-- IS RECORD EXISTS		
	-- ####################################################		
	SET TEMP_RECORD_EXISTS = `RECORD_USER@REC_USER_ID_EXISTS`(PARAM_REC_USER_ID, 0);


	-- 4) IF ALREADY EXIST, FILL MISSING DATA
	-- _______________________________________________________________________
	IF TEMP_RECORD_EXISTS = 1 THEN
		SELECT
				`record_user`.`REC_USER_CAT_DEPARTMENT_ID`, 	
				`record_user`.`REC_USER_CAT_SECTION_ID`, 	
				`record_user`.`REC_USER_UNIQUE_CODE`, 	
				`record_user`.`REC_USER_FIRST_NAME`, 	
				`record_user`.`REC_USER_MIDDLE_NAME`, 	
				`record_user`.`REC_USER_LAST_NAME`, 	
				`record_user`.`REC_USER_SUFFIX`, 	
				`record_user`.`REC_USER_SYS_GENDER_ID`, 	
				`record_user`.`REC_USER_NOTIFY_PHONE`, 	
				`record_user`.`REC_USER_EMCONTACT_PERSON`, 	
				`record_user`.`REC_USER_EMCONTACT_NUMBER`, 	
				`record_user`.`REC_USER_STATUS`	
		INTO
				TEMP_REC_USER_CAT_DEPARTMENT_ID, 	
				TEMP_REC_USER_CAT_SECTION_ID, 	
				TEMP_REC_USER_UNIQUE_CODE, 	
				TEMP_REC_USER_FIRST_NAME, 	
				TEMP_REC_USER_MIDDLE_NAME, 	
				TEMP_REC_USER_LAST_NAME, 	
				TEMP_REC_USER_SUFFIX, 	
				TEMP_REC_USER_SYS_GENDER_ID, 	
				TEMP_REC_USER_NOTIFY_PHONE, 	
				TEMP_REC_USER_EMCONTACT_PERSON, 	
				TEMP_REC_USER_EMCONTACT_NUMBER, 	
				TEMP_REC_USER_STATUS	

		FROM `record_user`
		WHERE
			`record_user`.`REC_USER_ID` = PARAM_REC_USER_ID
		LIMIT 1;

	ELSE 
		IF TEMP_SYNC_IS_SERVER_REQUEST = 0 THEN
			SET TEMP_ERR_MESSAGE = CONCAT_WS(' ', 'Given User does not exists or is inactive. ID:', PARAM_REC_USER_ID);
			SET ERR = `RAISERROR`(TEMP_ERR_MESSAGE);		
		END IF;
		LEAVE SP_DELETE;
		
	END IF;



	-- 5) PREPARE AUDIT TRAIL
	-- _______________________________________________________________________
	
		SET TEMP_RECORD_CHANGES = 
		`SYSTEM_VAR@CONCAT_ADD`(' | ', TEMP_RECORD_CHANGES, CONCAT_WS(' ', 'Department: "', TEMP_REC_USER_CAT_DEPARTMENT_ID, '" > " DELETED "'));
		SET TEMP_RECORD_CHANGES = 
		`SYSTEM_VAR@CONCAT_ADD`(' | ', TEMP_RECORD_CHANGES, CONCAT_WS(' ', 'Section: "', TEMP_REC_USER_CAT_SECTION_ID, '" > " DELETED "'));
		SET TEMP_RECORD_CHANGES = 
		`SYSTEM_VAR@CONCAT_ADD`(' | ', TEMP_RECORD_CHANGES, CONCAT_WS(' ', 'Unique Code: "', TEMP_REC_USER_UNIQUE_CODE, '" > " DELETED "'));
		SET TEMP_RECORD_CHANGES = 
		`SYSTEM_VAR@CONCAT_ADD`(' | ', TEMP_RECORD_CHANGES, CONCAT_WS(' ', 'First name: "', TEMP_REC_USER_FIRST_NAME, '" > " DELETED "'));
		SET TEMP_RECORD_CHANGES = 
		`SYSTEM_VAR@CONCAT_ADD`(' | ', TEMP_RECORD_CHANGES, CONCAT_WS(' ', 'Middle name: "', TEMP_REC_USER_MIDDLE_NAME, '" > " DELETED "'));
		SET TEMP_RECORD_CHANGES = 
		`SYSTEM_VAR@CONCAT_ADD`(' | ', TEMP_RECORD_CHANGES, CONCAT_WS(' ', 'Last name: "', TEMP_REC_USER_LAST_NAME, '" > " DELETED "'));
		SET TEMP_RECORD_CHANGES = 
		`SYSTEM_VAR@CONCAT_ADD`(' | ', TEMP_RECORD_CHANGES, CONCAT_WS(' ', 'Suffix: "', TEMP_REC_USER_SUFFIX, '" > " DELETED "'));
		SET TEMP_RECORD_CHANGES = 
		`SYSTEM_VAR@CONCAT_ADD`(' | ', TEMP_RECORD_CHANGES, CONCAT_WS(' ', 'Gender: "', TEMP_REC_USER_SYS_GENDER_ID, '" > " DELETED "'));
		SET TEMP_RECORD_CHANGES = 
		`SYSTEM_VAR@CONCAT_ADD`(' | ', TEMP_RECORD_CHANGES, CONCAT_WS(' ', 'Notification Mobile Number: "', TEMP_REC_USER_NOTIFY_PHONE, '" > " DELETED "'));
		SET TEMP_RECORD_CHANGES = 
		`SYSTEM_VAR@CONCAT_ADD`(' | ', TEMP_RECORD_CHANGES, CONCAT_WS(' ', 'Emergency Contact Person: "', TEMP_REC_USER_EMCONTACT_PERSON, '" > " DELETED "'));
		SET TEMP_RECORD_CHANGES = 
		`SYSTEM_VAR@CONCAT_ADD`(' | ', TEMP_RECORD_CHANGES, CONCAT_WS(' ', 'Emergency Contact Number: "', TEMP_REC_USER_EMCONTACT_NUMBER, '" > " DELETED "'));
		SET TEMP_RECORD_CHANGES = 
		`SYSTEM_VAR@CONCAT_ADD`(' | ', TEMP_RECORD_CHANGES, CONCAT_WS(' ', 'Status: "', TEMP_REC_USER_STATUS, '" > " DELETED "'));


	-- 6) VALIDATE
	-- _______________________________________________________________________
	
	-- Access Rights [Device]
	-- ####################################################
	IF `ACCOUNT_DEVICE@HAS_PERMISSION`(PARAM_REQUESTER_DEVICE_PUBLIC_KEY, PARAM_REQUESTER_DEVICE_PRIVATE_KEY) = 0 THEN
		SET TEMP_ERR_MESSAGE = 'Your device is not authorized yet to access this server.';
		SET ERR = `RAISERROR`(TEMP_ERR_MESSAGE);		
	END IF;
		
		
	-- Access Rights [Account]
	-- ####################################################	
	
	IF 
		-- [DELETE] Access Rights
		`ACCOUNT_ACCESS_RIGHTS@HAS_PERMISSION`(PARAM_REQUESTER_USERNAME, PARAM_REQUESTER_PASSWORD, 0, TEMP_MODULE_KEYWORD, 4) = 0 AND
		`ACCOUNT_ACCESS_RIGHTS@PROXY_PERMISSION`(PARAM_REQUESTER_PROXY_ID, PARAM_REQUESTER_PROXY_PASSWORD, 0, TEMP_MODULE_KEYWORD, 4) = 0
	THEN
		SET TEMP_ACCESS_RIGHTS_DENIED = 1;
		CALL `ACCOUNT_ACCESS_RIGHTS_DENY`
		(
			0, TEMP_MODULE_KEYWORD, PARAM_REC_USER_ID, 0, TEMP_SP_OBJECTIVE, TEMP_RECORD_CHANGES, 
			PARAM_REQUESTER_USERNAME, PARAM_REQUESTER_PASSWORD, 
			PARAM_REQUESTER_PROXY_ID, PARAM_REQUESTER_PROXY_PASSWORD,
			PARAM_REQUESTER_DEVICE_PUBLIC_KEY, PARAM_REQUESTER_DEVICE_PRIVATE_KEY,
			PARAM_REQUESTER_IP, PARAM_UNIQUE_SESSION_ID,
			TEMP_SYNC_SERVER_ID, PARAM_SUPPRESS_RETURN
		);
	END IF;

	
	-- If already used, cannot remove record
	-- ####################################################
	IF
	(
		SELECT
			COUNT(`record_attendance`.`REC_ATTENDANCE_REC_USER_ID`)
		FROM `record_attendance`
		WHERE
			`record_attendance`.`REC_ATTENDANCE_REC_USER_ID` = PARAM_REC_USER_ID
		LIMIT 1
	) >= 1 
	THEN
		SET TEMP_RECORD_BINDED = 1;
		SET TEMP_ERR_MESSAGE = 'Attendance Record';
	END IF;

	-- Leave Re-upload request
	-- ####################################################
	IF TEMP_RECORD_BINDED = 1 THEN
		IF TEMP_SYNC_IS_SERVER_REQUEST = 1 THEN
			
			LEAVE SP_DELETE;
		END IF;

		CALL `VALIDATION_DELETE_LINKED_RECORD`(TEMP_REC_USER_LAST_NAME, '', TEMP_ERR_MESSAGE); 
	END IF;


	-- 7) DELETE
	-- _______________________________________________________________________
	DELETE FROM `record_user`
	WHERE `record_user`.`REC_USER_ID` = PARAM_REC_USER_ID
	LIMIT 1;


	-- 8) AUDIT TRAIL
	-- _______________________________________________________________________
	CALL `ACCOUNT_AUDIT_TRAIL_SAVE`
	(
		0, TEMP_MODULE_KEYWORD, PARAM_REC_USER_ID, 0, 'DELETE', TEMP_SP_OBJECTIVE, TEMP_RECORD_CHANGES, 
		PARAM_REQUESTER_USERNAME, PARAM_REQUESTER_PASSWORD, 
		PARAM_REQUESTER_PROXY_ID, PARAM_REQUESTER_PROXY_PASSWORD,
		PARAM_REQUESTER_DEVICE_PUBLIC_KEY, PARAM_REQUESTER_DEVICE_PRIVATE_KEY,
		PARAM_REQUESTER_IP, PARAM_UNIQUE_SESSION_ID,
		TEMP_SYNC_SERVER_ID, PARAM_SUPPRESS_RETURN
	);

END ;;
DELIMITER ;
/*!50003 SET sql_mode              = @saved_sql_mode */ ;
/*!50003 SET character_set_client  = @saved_cs_client */ ;
/*!50003 SET character_set_results = @saved_cs_results */ ;
/*!50003 SET collation_connection  = @saved_col_connection */ ;
/*!50003 DROP PROCEDURE IF EXISTS `RECORD_USER_GET` */;
/*!50003 SET @saved_cs_client      = @@character_set_client */ ;
/*!50003 SET @saved_cs_results     = @@character_set_results */ ;
/*!50003 SET @saved_col_connection = @@collation_connection */ ;
/*!50003 SET character_set_client  = latin1 */ ;
/*!50003 SET character_set_results = latin1 */ ;
/*!50003 SET collation_connection  = latin1_swedish_ci */ ;
/*!50003 SET @saved_sql_mode       = @@sql_mode */ ;
/*!50003 SET sql_mode              = '' */ ;
DELIMITER ;;
CREATE DEFINER=`root`@`localhost` PROCEDURE `RECORD_USER_GET`(
	IN `PARAM_REC_USER_ID` BIGINT,	
	IN `PARAM_REC_USER_CAT_DEPARTMENT_ID` BIGINT,	
	IN `PARAM_REC_USER_CAT_SECTION_ID` BIGINT,	
	IN `PARAM_REC_USER_UNIQUE_CODE` VARCHAR(400),	
	IN `PARAM_REC_USER_FIRST_NAME` VARCHAR(400),	
	IN `PARAM_REC_USER_MIDDLE_NAME` VARCHAR(400),	
	IN `PARAM_REC_USER_LAST_NAME` VARCHAR(400),	
	IN `PARAM_REC_USER_SUFFIX` VARCHAR(40),	
	IN `PARAM_REC_USER_SYS_GENDER_ID` BIGINT,	
	IN `PARAM_REC_USER_NOTIFY_PHONE` VARCHAR(40),	
	IN `PARAM_REC_USER_EMCONTACT_PERSON` VARCHAR(1000),	
	IN `PARAM_REC_USER_EMCONTACT_NUMBER` VARCHAR(40),	
	IN `PARAM_REC_USER_STATUS` TINYINT,	
		
	IN `PARAM_ORDER_FIELD` VARCHAR(500),
	IN `PARAM_ORDER_TYPE` VARCHAR(500),
	IN `PARAM_SKIP` BIGINT,
	IN `PARAM_LIMIT` BIGINT,

	IN `PARAM_REQUESTER_USERNAME` VARCHAR(500),
	IN `PARAM_REQUESTER_PASSWORD` VARCHAR(500),
	IN `PARAM_REQUESTER_PROXY_ID` BIGINT,
	IN `PARAM_REQUESTER_PROXY_PASSWORD` VARCHAR(1000),
	IN `PARAM_REQUESTER_DEVICE_PUBLIC_KEY` VARCHAR(1000),
	IN `PARAM_REQUESTER_DEVICE_PRIVATE_KEY` VARCHAR(1000),
	
	IN `PARAM_REQUESTER_IP` VARCHAR(1000),
	IN `PARAM_UNIQUE_SESSION_ID` VARCHAR(1000),
	IN `PARAM_SUPPRESS_RETURN` BIT
)
SP_GET:
BEGIN

	-- Status
	-- =========================================================================================
	DECLARE STATUS_INACTIVE TINYINT DEFAULT 1;
	DECLARE STATUS_ACTIVE TINYINT DEFAULT 2;
	DECLARE STATUS_CLOSED TINYINT DEFAULT 3;
	DECLARE STATUS_COMPLETED TINYINT DEFAULT 4;
	
	-- Audit Handler
	-- =========================================================================================
	DECLARE TEMP_RECORD_EXISTS BIT DEFAULT 0;
	DECLARE TEMP_MODULE_KEYWORD VARCHAR(500) DEFAULT 'record_user';
	DECLARE TEMP_SP_OBJECTIVE VARCHAR(500) DEFAULT 'Retrieve User record';
	DECLARE TEMP_ERR_MESSAGE VARCHAR(500) DEFAULT '';
	DECLARE ERR BIGINT DEFAULT 0;
	DECLARE TEMP_RECORD_CHANGES VARCHAR(16000) DEFAULT '';
	DECLARE TEMP_RECORD_BINDED BIT DEFAULT 0;
	
	DECLARE TEMP_RECORD_BINDED_ID BIGINT DEFAULT 0;
	DECLARE TEMP_RECORD_BINDED_SERVER_ID BIGINT DEFAULT 0;
	
	-- Authentication
	-- =========================================================================================
	DECLARE TEMP_ACCESS_RIGHTS_DENIED BIT DEFAULT 0;
	DECLARE TEMP_AUTHENTICATED_ACCOUNT_ID BIGINT DEFAULT `ACCOUNT_MEMBER@ACC_ACCOUNT_ID_FROM_LOGIN`(PARAM_REQUESTER_USERNAME, PARAM_REQUESTER_PASSWORD);
	DECLARE TEMP_AUTHENTICATED_ACCOUNT_LEVEL BIGINT DEFAULT 0;
	DECLARE TEMP_AUTHENTICATED_ACCOUNT_GROUP BIGINT DEFAULT 0;
	
	-- Local Parameters
	-- =========================================================================================
	DECLARE TEMP_NOW DATETIME(6) DEFAULT `SYSTEM_VAR@NOW`('', 1);
	DECLARE TEMP_RECORD_COUNT BIGINT DEFAULT 0;
	
	
	-- Check NULLs
	-- =========================================================================================
	DECLARE IS_NULL_REC_USER_ID BIT DEFAULT `SYSTEM_VAR@IS_NULL@BIGINT`(PARAM_REC_USER_ID, 1, 1);
	DECLARE IS_NULL_REC_USER_CAT_DEPARTMENT_ID BIT DEFAULT `SYSTEM_VAR@IS_NULL@BIGINT`(PARAM_REC_USER_CAT_DEPARTMENT_ID, 1, 1);
	DECLARE IS_NULL_REC_USER_CAT_SECTION_ID BIT DEFAULT `SYSTEM_VAR@IS_NULL@BIGINT`(PARAM_REC_USER_CAT_SECTION_ID, 1, 1);
	DECLARE IS_NULL_REC_USER_UNIQUE_CODE BIT DEFAULT `SYSTEM_VAR@IS_NULL@NVARCHAR`(PARAM_REC_USER_UNIQUE_CODE, 1);
	DECLARE IS_NULL_REC_USER_FIRST_NAME BIT DEFAULT `SYSTEM_VAR@IS_NULL@NVARCHAR`(PARAM_REC_USER_FIRST_NAME, 1);
	DECLARE IS_NULL_REC_USER_MIDDLE_NAME BIT DEFAULT `SYSTEM_VAR@IS_NULL@NVARCHAR`(PARAM_REC_USER_MIDDLE_NAME, 0);
	DECLARE IS_NULL_REC_USER_LAST_NAME BIT DEFAULT `SYSTEM_VAR@IS_NULL@NVARCHAR`(PARAM_REC_USER_LAST_NAME, 1);
	DECLARE IS_NULL_REC_USER_SUFFIX BIT DEFAULT `SYSTEM_VAR@IS_NULL@NVARCHAR`(PARAM_REC_USER_SUFFIX, 0);
	DECLARE IS_NULL_REC_USER_SYS_GENDER_ID BIT DEFAULT `SYSTEM_VAR@IS_NULL@BIGINT`(PARAM_REC_USER_SYS_GENDER_ID, 1, 1);
	DECLARE IS_NULL_REC_USER_NOTIFY_PHONE BIT DEFAULT `SYSTEM_VAR@IS_NULL@NVARCHAR`(PARAM_REC_USER_NOTIFY_PHONE, 1);
	DECLARE IS_NULL_REC_USER_EMCONTACT_PERSON BIT DEFAULT `SYSTEM_VAR@IS_NULL@NVARCHAR`(PARAM_REC_USER_EMCONTACT_PERSON, 0);
	DECLARE IS_NULL_REC_USER_EMCONTACT_NUMBER BIT DEFAULT `SYSTEM_VAR@IS_NULL@NVARCHAR`(PARAM_REC_USER_EMCONTACT_NUMBER, 0);
	DECLARE IS_NULL_REC_USER_STATUS BIT DEFAULT `SYSTEM_VAR@IS_NULL@TINYINT`(PARAM_REC_USER_STATUS, 1, 1);
	
	-- Error Handler
	-- =========================================================================================
	DECLARE EXIT HANDLER FOR SQLEXCEPTION
	BEGIN
		RESIGNAL;
	END;
	
	-- Ignore Time from DateTime (Set Time 00:00:00.000000 and 23:59:59.999999)
	-- =========================================================================================
		
		
	-- Access Rights [Device]
	-- =========================================================================================
	IF `ACCOUNT_DEVICE@HAS_PERMISSION`(PARAM_REQUESTER_DEVICE_PUBLIC_KEY, PARAM_REQUESTER_DEVICE_PRIVATE_KEY) = 0 THEN
		SET TEMP_ERR_MESSAGE = 'Your device is not authorized yet to access this server.';
		SET ERR = `RAISERROR`(TEMP_ERR_MESSAGE);		
	END IF;
		
		
	-- Access Rights [Account]
	-- =========================================================================================	
	IF 
		`ACCOUNT_ACCESS_RIGHTS@HAS_PERMISSION`(PARAM_REQUESTER_USERNAME, PARAM_REQUESTER_PASSWORD, 0, TEMP_MODULE_KEYWORD, 1) = 0 AND
		`ACCOUNT_ACCESS_RIGHTS@PROXY_PERMISSION`(PARAM_REQUESTER_PROXY_ID, PARAM_REQUESTER_PROXY_PASSWORD, 0, TEMP_MODULE_KEYWORD, 1) = 0
	THEN
		SET TEMP_ACCESS_RIGHTS_DENIED = 1;
		CALL `ACCOUNT_ACCESS_RIGHTS_DENY`
		(
			0, TEMP_MODULE_KEYWORD, 0, 0, TEMP_SP_OBJECTIVE, TEMP_RECORD_CHANGES, 
			PARAM_REQUESTER_USERNAME, PARAM_REQUESTER_PASSWORD, 
			PARAM_REQUESTER_PROXY_ID, PARAM_REQUESTER_PROXY_PASSWORD,
			PARAM_REQUESTER_DEVICE_PUBLIC_KEY, PARAM_REQUESTER_DEVICE_PRIVATE_KEY,
			PARAM_REQUESTER_IP, PARAM_UNIQUE_SESSION_ID,
			0, PARAM_SUPPRESS_RETURN
		);
	END IF;

	-- For view only rights, access is limited to active users
	IF 
		`ACCOUNT_ACCESS_RIGHTS@HAS_PERMISSION`(PARAM_REQUESTER_USERNAME, PARAM_REQUESTER_PASSWORD, 0, TEMP_MODULE_KEYWORD, 2) = 0 AND
		`ACCOUNT_ACCESS_RIGHTS@PROXY_PERMISSION`(PARAM_REQUESTER_PROXY_ID, PARAM_REQUESTER_PROXY_PASSWORD, 0, TEMP_MODULE_KEYWORD, 2) = 0
	THEN
		SET IS_NULL_REC_USER_STATUS = 0;
		SET PARAM_REC_USER_STATUS = STATUS_ACTIVE;
	END IF;	
	
	
	-- COUNT RECORD
	-- =========================================================================================
	
	-- SELECT COLUMNS
	-- ####################################################
	SELECT
		COUNT(DISTINCT `record_user`.`REC_USER_ID`)
	INTO
		TEMP_RECORD_COUNT

	FROM `record_user`
				
		-- Add Inner Joins (Per Foreign-key)
		INNER JOIN `category_department` ON
		`category_department`.`CAT_DEPARTMENT_ID` = `record_user`.`REC_USER_CAT_DEPARTMENT_ID`
			
		-- ~~~~~	
			
		INNER JOIN `category_section` ON
		`category_section`.`CAT_SECTION_ID` = `record_user`.`REC_USER_CAT_SECTION_ID`
			
		-- ~~~~~	
			
		INNER JOIN `system_gender` ON
		`system_gender`.`SYS_GENDER_ID` = `record_user`.`REC_USER_SYS_GENDER_ID`
			
		-- ~~~~~	
			
		INNER JOIN `account_member` ON
		`account_member`.`ACC_ACCOUNT_ID` = `record_user`.`REC_USER_ACC_ACCOUNT_ID`		
		
	-- CONDITIONS
	-- ####################################################
	WHERE
		(
			IS_NULL_REC_USER_ID = 1 OR
			`record_user`.`REC_USER_ID` = PARAM_REC_USER_ID			
		) AND
		(
			IS_NULL_REC_USER_CAT_DEPARTMENT_ID = 1 OR
			`record_user`.`REC_USER_CAT_DEPARTMENT_ID` = PARAM_REC_USER_CAT_DEPARTMENT_ID			
		) AND
		(
			IS_NULL_REC_USER_CAT_SECTION_ID = 1 OR
			`record_user`.`REC_USER_CAT_SECTION_ID` = PARAM_REC_USER_CAT_SECTION_ID			
		) AND
		(
			IS_NULL_REC_USER_UNIQUE_CODE = 1 OR
			`record_user`.`REC_USER_UNIQUE_CODE` LIKE CONCAT_WS('%', '', PARAM_REC_USER_UNIQUE_CODE, '')			
		) AND 		
		(
			IS_NULL_REC_USER_FIRST_NAME = 1 OR
			`record_user`.`REC_USER_FIRST_NAME` LIKE CONCAT_WS('%', '', PARAM_REC_USER_FIRST_NAME, '')			
		) AND 		
		(
			IS_NULL_REC_USER_MIDDLE_NAME = 1 OR
			`record_user`.`REC_USER_MIDDLE_NAME` LIKE CONCAT_WS('%', '', PARAM_REC_USER_MIDDLE_NAME, '')			
		) AND 		
		(
			IS_NULL_REC_USER_LAST_NAME = 1 OR
			`record_user`.`REC_USER_LAST_NAME` LIKE CONCAT_WS('%', '', PARAM_REC_USER_LAST_NAME, '')			
		) AND 		
		(
			IS_NULL_REC_USER_SUFFIX = 1 OR
			`record_user`.`REC_USER_SUFFIX` LIKE CONCAT_WS('%', '', PARAM_REC_USER_SUFFIX, '')			
		) AND 		
		(
			IS_NULL_REC_USER_SYS_GENDER_ID = 1 OR
			`record_user`.`REC_USER_SYS_GENDER_ID` = PARAM_REC_USER_SYS_GENDER_ID			
		) AND
		(
			IS_NULL_REC_USER_NOTIFY_PHONE = 1 OR
			`record_user`.`REC_USER_NOTIFY_PHONE` LIKE CONCAT_WS('%', '', PARAM_REC_USER_NOTIFY_PHONE, '')			
		) AND 		
		(
			IS_NULL_REC_USER_EMCONTACT_PERSON = 1 OR
			`record_user`.`REC_USER_EMCONTACT_PERSON` LIKE CONCAT_WS('%', '', PARAM_REC_USER_EMCONTACT_PERSON, '')			
		) AND 		
		(
			IS_NULL_REC_USER_EMCONTACT_NUMBER = 1 OR
			`record_user`.`REC_USER_EMCONTACT_NUMBER` LIKE CONCAT_WS('%', '', PARAM_REC_USER_EMCONTACT_NUMBER, '')			
		) AND 		
		(
			IS_NULL_REC_USER_STATUS = 1 OR
			`record_user`.`REC_USER_STATUS` = PARAM_REC_USER_STATUS			
		) 
;	

		
		
	-- SELECT RECORDS
	-- =========================================================================================
	
	-- FETCH COLUMNS
	-- ####################################################
	SELECT
		-- RECORD_USER DETAILS
		`record_user`.`REC_USER_ID`, 
		`record_user`.`REC_USER_CAT_DEPARTMENT_ID`, 
		`record_user`.`REC_USER_CAT_SECTION_ID`, 
		`record_user`.`REC_USER_UNIQUE_CODE`, 

		CONCAT_WS
		(
			' ',
			`record_user`.`REC_USER_LAST_NAME`, ',',
			`record_user`.`REC_USER_FIRST_NAME`,
			`record_user`.`REC_USER_MIDDLE_NAME`,
			`record_user`.`REC_USER_SUFFIX`
		) AS REC_USER_NAME,

		`record_user`.`REC_USER_FIRST_NAME`, 
		`record_user`.`REC_USER_MIDDLE_NAME`, 
		`record_user`.`REC_USER_LAST_NAME`, 
		`record_user`.`REC_USER_SUFFIX`, 
		`record_user`.`REC_USER_SYS_GENDER_ID`, 
		`record_user`.`REC_USER_NOTIFY_PHONE`, 
		`record_user`.`REC_USER_EMCONTACT_PERSON`, 
		`record_user`.`REC_USER_EMCONTACT_NUMBER`, 

		`record_user`.`REC_USER_ACC_ACCOUNT_ID`, 
	
	`record_user`.`REC_USER_RECORDED_DATE`, 
		`record_user`.`REC_USER_STATUS`
		
		-- Sum of Child [Numerics, non-primary/foreign keys, nor status, active/inactive, and system generated.]
		
		
		-- Inner join fields
		, 
		`category_department`.`CAT_DEPARTMENT_ID`,	
		`category_department`.`CAT_DEPARTMENT_DESCRIPTION` AS REC_USER_CAT_DEPARTMENT_ID_DESCRIPTION,
		`category_department`.`CAT_DEPARTMENT_DESCRIPTION`,	
		`category_department`.`CAT_DEPARTMENT_STATUS`,	
		`category_section`.`CAT_SECTION_ID`,	
		`category_section`.`CAT_SECTION_CAT_DEPARTMENT_ID`,	
		`category_section`.`CAT_SECTION_DESCRIPTION` AS REC_USER_CAT_SECTION_ID_DESCRIPTION,
		`category_section`.`CAT_SECTION_DESCRIPTION`,	
		`category_section`.`CAT_SECTION_STATUS`,	
		`system_gender`.`SYS_GENDER_ID`,	
		`system_gender`.`SYS_GENDER_CODE`,	
		`system_gender`.`SYS_GENDER_DESCRIPTION` AS REC_USER_SYS_GENDER_ID_DESCRIPTION,
		`system_gender`.`SYS_GENDER_DESCRIPTION`,	
		`system_gender`.`SYS_GENDER_STATUS`,

		`account_member`.`ACC_ACCOUNT_ID`,	
		`account_member`.`ACC_ACCOUNT_SERVER_ID`,	
		`account_member`.`ACC_ACCOUNT_ACC_LEVEL_ID`,	
		`account_member`.`ACC_ACCOUNT_ACC_GROUP_ID`,	
		`account_member`.`ACC_ACCOUNT_ADD_RESOURCE_ID`,	
		`account_member`.`ACC_ACCOUNT_USERNAME` AS REC_USER_ACC_ACCOUNT_ID_DESCRIPTION,
		`account_member`.`ACC_ACCOUNT_USERNAME`,	
		`account_member`.`ACC_ACCOUNT_PASSWORD`,	
		`account_member`.`ACC_ACCOUNT_AUTH_CODE`,	
		CONCAT_WS
		( 
					' ',
			`account_member`.`ACC_ACCOUNT_LAST_NAME`, ', ',
				`account_member`.`ACC_ACCOUNT_FIRST_NAME`,
			`account_member`.`ACC_ACCOUNT_MIDDLE_NAME`
		) AS ACC_ACCOUNT_NAME,
		`account_member`.`ACC_ACCOUNT_FIRST_NAME`, 				
		`account_member`.`ACC_ACCOUNT_MIDDLE_NAME`,	
		`account_member`.`ACC_ACCOUNT_LAST_NAME`,	
		`account_member`.`ACC_ACCOUNT_POSITION`,	
		`account_member`.`ACC_ACCOUNT_SYS_GENDER_ID`,	
		`account_member`.`ACC_ACCOUNT_STATUS`,	
		`account_member`.`ACC_ACCOUNT_SYSTEM_GENERATED`,
		
		-- Left join fields
		TEMP_NOW AS SERVER_TIME,
		TEMP_RECORD_COUNT AS RECORD_COUNT

	FROM `record_user`
	
		-- Add Inner Joins (Per Foreign-key)
		INNER JOIN `category_department` ON
		`category_department`.`CAT_DEPARTMENT_ID` = `record_user`.`REC_USER_CAT_DEPARTMENT_ID`
			
		-- ~~~~~	
			
		INNER JOIN `category_section` ON
		`category_section`.`CAT_SECTION_ID` = `record_user`.`REC_USER_CAT_SECTION_ID`
			
		-- ~~~~~	
			
		INNER JOIN `system_gender` ON
		`system_gender`.`SYS_GENDER_ID` = `record_user`.`REC_USER_SYS_GENDER_ID`
			
		-- ~~~~~	
			
		INNER JOIN `account_member` ON
		`account_member`.`ACC_ACCOUNT_ID` = `record_user`.`REC_USER_ACC_ACCOUNT_ID`			
		
		-- Add Optional Left Joins (Per Optional Foreign-key)
		
	-- CONDITIONS
	-- ####################################################
	WHERE
		(
			IS_NULL_REC_USER_ID = 1 OR
			`record_user`.`REC_USER_ID` = PARAM_REC_USER_ID			
		) AND
		(
			IS_NULL_REC_USER_CAT_DEPARTMENT_ID = 1 OR
			`record_user`.`REC_USER_CAT_DEPARTMENT_ID` = PARAM_REC_USER_CAT_DEPARTMENT_ID			
		) AND
		(
			IS_NULL_REC_USER_CAT_SECTION_ID = 1 OR
			`record_user`.`REC_USER_CAT_SECTION_ID` = PARAM_REC_USER_CAT_SECTION_ID			
		) AND
		(
			IS_NULL_REC_USER_UNIQUE_CODE = 1 OR
			`record_user`.`REC_USER_UNIQUE_CODE` LIKE CONCAT_WS('%', '', PARAM_REC_USER_UNIQUE_CODE, '')			
		) AND 		
		(
			IS_NULL_REC_USER_FIRST_NAME = 1 OR
			`record_user`.`REC_USER_FIRST_NAME` LIKE CONCAT_WS('%', '', PARAM_REC_USER_FIRST_NAME, '')			
		) AND 		
		(
			IS_NULL_REC_USER_MIDDLE_NAME = 1 OR
			`record_user`.`REC_USER_MIDDLE_NAME` LIKE CONCAT_WS('%', '', PARAM_REC_USER_MIDDLE_NAME, '')			
		) AND 		
		(
			IS_NULL_REC_USER_LAST_NAME = 1 OR
			`record_user`.`REC_USER_LAST_NAME` LIKE CONCAT_WS('%', '', PARAM_REC_USER_LAST_NAME, '')			
		) AND 		
		(
			IS_NULL_REC_USER_SUFFIX = 1 OR
			`record_user`.`REC_USER_SUFFIX` LIKE CONCAT_WS('%', '', PARAM_REC_USER_SUFFIX, '')			
		) AND 		
		(
			IS_NULL_REC_USER_SYS_GENDER_ID = 1 OR
			`record_user`.`REC_USER_SYS_GENDER_ID` = PARAM_REC_USER_SYS_GENDER_ID			
		) AND
		(
			IS_NULL_REC_USER_NOTIFY_PHONE = 1 OR
			`record_user`.`REC_USER_NOTIFY_PHONE` LIKE CONCAT_WS('%', '', PARAM_REC_USER_NOTIFY_PHONE, '')			
		) AND 		
		(
			IS_NULL_REC_USER_EMCONTACT_PERSON = 1 OR
			`record_user`.`REC_USER_EMCONTACT_PERSON` LIKE CONCAT_WS('%', '', PARAM_REC_USER_EMCONTACT_PERSON, '')			
		) AND 		
		(
			IS_NULL_REC_USER_EMCONTACT_NUMBER = 1 OR
			`record_user`.`REC_USER_EMCONTACT_NUMBER` LIKE CONCAT_WS('%', '', PARAM_REC_USER_EMCONTACT_NUMBER, '')			
		) AND 		
		(
			IS_NULL_REC_USER_STATUS = 1 OR
			`record_user`.`REC_USER_STATUS` = PARAM_REC_USER_STATUS			
		) 

	-- ORDER BY
	-- ####################################################
	ORDER BY
		-- RECORD_USER DETAILS
		CASE WHEN PARAM_ORDER_FIELD = 'REC_USER_ID' AND PARAM_ORDER_TYPE = 'ASC' THEN `record_user`.`REC_USER_ID` END ASC, 
		CASE WHEN PARAM_ORDER_FIELD = 'REC_USER_ID' AND PARAM_ORDER_TYPE = 'DESC' THEN `record_user`.`REC_USER_ID` END DESC,	
		CASE WHEN PARAM_ORDER_FIELD = 'REC_USER_CAT_DEPARTMENT_ID' AND PARAM_ORDER_TYPE = 'ASC' THEN `record_user`.`REC_USER_CAT_DEPARTMENT_ID` END ASC, 
		CASE WHEN PARAM_ORDER_FIELD = 'REC_USER_CAT_DEPARTMENT_ID' AND PARAM_ORDER_TYPE = 'DESC' THEN `record_user`.`REC_USER_CAT_DEPARTMENT_ID` END DESC,	
		CASE WHEN PARAM_ORDER_FIELD = 'REC_USER_CAT_SECTION_ID' AND PARAM_ORDER_TYPE = 'ASC' THEN `record_user`.`REC_USER_CAT_SECTION_ID` END ASC, 
		CASE WHEN PARAM_ORDER_FIELD = 'REC_USER_CAT_SECTION_ID' AND PARAM_ORDER_TYPE = 'DESC' THEN `record_user`.`REC_USER_CAT_SECTION_ID` END DESC,	
		CASE WHEN PARAM_ORDER_FIELD = 'REC_USER_UNIQUE_CODE' AND PARAM_ORDER_TYPE = 'ASC' THEN `record_user`.`REC_USER_UNIQUE_CODE` END ASC, 
		CASE WHEN PARAM_ORDER_FIELD = 'REC_USER_UNIQUE_CODE' AND PARAM_ORDER_TYPE = 'DESC' THEN `record_user`.`REC_USER_UNIQUE_CODE` END DESC,	
		CASE WHEN PARAM_ORDER_FIELD = 'REC_USER_FIRST_NAME' AND PARAM_ORDER_TYPE = 'ASC' THEN `record_user`.`REC_USER_FIRST_NAME` END ASC, 
		CASE WHEN PARAM_ORDER_FIELD = 'REC_USER_FIRST_NAME' AND PARAM_ORDER_TYPE = 'DESC' THEN `record_user`.`REC_USER_FIRST_NAME` END DESC,	
		CASE WHEN PARAM_ORDER_FIELD = 'REC_USER_MIDDLE_NAME' AND PARAM_ORDER_TYPE = 'ASC' THEN `record_user`.`REC_USER_MIDDLE_NAME` END ASC, 
		CASE WHEN PARAM_ORDER_FIELD = 'REC_USER_MIDDLE_NAME' AND PARAM_ORDER_TYPE = 'DESC' THEN `record_user`.`REC_USER_MIDDLE_NAME` END DESC,	
		CASE WHEN PARAM_ORDER_FIELD = 'REC_USER_LAST_NAME' AND PARAM_ORDER_TYPE = 'ASC' THEN `record_user`.`REC_USER_LAST_NAME` END ASC, 
		CASE WHEN PARAM_ORDER_FIELD = 'REC_USER_LAST_NAME' AND PARAM_ORDER_TYPE = 'DESC' THEN `record_user`.`REC_USER_LAST_NAME` END DESC,	
		CASE WHEN PARAM_ORDER_FIELD = 'REC_USER_SUFFIX' AND PARAM_ORDER_TYPE = 'ASC' THEN `record_user`.`REC_USER_SUFFIX` END ASC, 
		CASE WHEN PARAM_ORDER_FIELD = 'REC_USER_SUFFIX' AND PARAM_ORDER_TYPE = 'DESC' THEN `record_user`.`REC_USER_SUFFIX` END DESC,	
		CASE WHEN PARAM_ORDER_FIELD = 'REC_USER_SYS_GENDER_ID' AND PARAM_ORDER_TYPE = 'ASC' THEN `record_user`.`REC_USER_SYS_GENDER_ID` END ASC, 
		CASE WHEN PARAM_ORDER_FIELD = 'REC_USER_SYS_GENDER_ID' AND PARAM_ORDER_TYPE = 'DESC' THEN `record_user`.`REC_USER_SYS_GENDER_ID` END DESC,	
		CASE WHEN PARAM_ORDER_FIELD = 'REC_USER_NOTIFY_PHONE' AND PARAM_ORDER_TYPE = 'ASC' THEN `record_user`.`REC_USER_NOTIFY_PHONE` END ASC, 
		CASE WHEN PARAM_ORDER_FIELD = 'REC_USER_NOTIFY_PHONE' AND PARAM_ORDER_TYPE = 'DESC' THEN `record_user`.`REC_USER_NOTIFY_PHONE` END DESC,	
		CASE WHEN PARAM_ORDER_FIELD = 'REC_USER_EMCONTACT_PERSON' AND PARAM_ORDER_TYPE = 'ASC' THEN `record_user`.`REC_USER_EMCONTACT_PERSON` END ASC, 
		CASE WHEN PARAM_ORDER_FIELD = 'REC_USER_EMCONTACT_PERSON' AND PARAM_ORDER_TYPE = 'DESC' THEN `record_user`.`REC_USER_EMCONTACT_PERSON` END DESC,	
		CASE WHEN PARAM_ORDER_FIELD = 'REC_USER_EMCONTACT_NUMBER' AND PARAM_ORDER_TYPE = 'ASC' THEN `record_user`.`REC_USER_EMCONTACT_NUMBER` END ASC, 
		CASE WHEN PARAM_ORDER_FIELD = 'REC_USER_EMCONTACT_NUMBER' AND PARAM_ORDER_TYPE = 'DESC' THEN `record_user`.`REC_USER_EMCONTACT_NUMBER` END DESC,	

		CASE WHEN PARAM_ORDER_FIELD = 'REC_USER_RECORDED_DATE' AND PARAM_ORDER_TYPE = 'ASC' THEN `record_user`.`REC_USER_RECORDED_DATE` END ASC, 
		CASE WHEN PARAM_ORDER_FIELD = 'REC_USER_RECORDED_DATE' AND PARAM_ORDER_TYPE = 'DESC' THEN `record_user`.`REC_USER_RECORDED_DATE` END DESC,	

		CASE WHEN PARAM_ORDER_FIELD = 'REC_USER_STATUS' AND PARAM_ORDER_TYPE = 'ASC' THEN `record_user`.`REC_USER_STATUS` END ASC, 
		CASE WHEN PARAM_ORDER_FIELD = 'REC_USER_STATUS' AND PARAM_ORDER_TYPE = 'DESC' THEN `record_user`.`REC_USER_STATUS` END DESC,	

		-- Inner joins
		CASE WHEN PARAM_ORDER_FIELD = 'CAT_DEPARTMENT_ID' AND PARAM_ORDER_TYPE = 'ASC' THEN `category_department`.`CAT_DEPARTMENT_ID` END ASC, 
		CASE WHEN PARAM_ORDER_FIELD = 'CAT_DEPARTMENT_ID' AND PARAM_ORDER_TYPE = 'DESC' THEN `category_department`.`CAT_DEPARTMENT_ID` END DESC,
		CASE WHEN PARAM_ORDER_FIELD = 'CAT_DEPARTMENT_DESCRIPTION' AND PARAM_ORDER_TYPE = 'ASC' THEN `category_department`.`CAT_DEPARTMENT_DESCRIPTION` END ASC, 
		CASE WHEN PARAM_ORDER_FIELD = 'CAT_DEPARTMENT_DESCRIPTION' AND PARAM_ORDER_TYPE = 'DESC' THEN `category_department`.`CAT_DEPARTMENT_DESCRIPTION` END DESC,
		CASE WHEN PARAM_ORDER_FIELD = 'CAT_DEPARTMENT_STATUS' AND PARAM_ORDER_TYPE = 'ASC' THEN `category_department`.`CAT_DEPARTMENT_STATUS` END ASC, 
		CASE WHEN PARAM_ORDER_FIELD = 'CAT_DEPARTMENT_STATUS' AND PARAM_ORDER_TYPE = 'DESC' THEN `category_department`.`CAT_DEPARTMENT_STATUS` END DESC,
		CASE WHEN PARAM_ORDER_FIELD = 'CAT_SECTION_ID' AND PARAM_ORDER_TYPE = 'ASC' THEN `category_section`.`CAT_SECTION_ID` END ASC, 
		CASE WHEN PARAM_ORDER_FIELD = 'CAT_SECTION_ID' AND PARAM_ORDER_TYPE = 'DESC' THEN `category_section`.`CAT_SECTION_ID` END DESC,
		CASE WHEN PARAM_ORDER_FIELD = 'CAT_SECTION_CAT_DEPARTMENT_ID' AND PARAM_ORDER_TYPE = 'ASC' THEN `category_section`.`CAT_SECTION_CAT_DEPARTMENT_ID` END ASC, 
		CASE WHEN PARAM_ORDER_FIELD = 'CAT_SECTION_CAT_DEPARTMENT_ID' AND PARAM_ORDER_TYPE = 'DESC' THEN `category_section`.`CAT_SECTION_CAT_DEPARTMENT_ID` END DESC,
		CASE WHEN PARAM_ORDER_FIELD = 'CAT_SECTION_DESCRIPTION' AND PARAM_ORDER_TYPE = 'ASC' THEN `category_section`.`CAT_SECTION_DESCRIPTION` END ASC, 
		CASE WHEN PARAM_ORDER_FIELD = 'CAT_SECTION_DESCRIPTION' AND PARAM_ORDER_TYPE = 'DESC' THEN `category_section`.`CAT_SECTION_DESCRIPTION` END DESC,
		CASE WHEN PARAM_ORDER_FIELD = 'CAT_SECTION_STATUS' AND PARAM_ORDER_TYPE = 'ASC' THEN `category_section`.`CAT_SECTION_STATUS` END ASC, 
		CASE WHEN PARAM_ORDER_FIELD = 'CAT_SECTION_STATUS' AND PARAM_ORDER_TYPE = 'DESC' THEN `category_section`.`CAT_SECTION_STATUS` END DESC,
		CASE WHEN PARAM_ORDER_FIELD = 'SYS_GENDER_ID' AND PARAM_ORDER_TYPE = 'ASC' THEN `system_gender`.`SYS_GENDER_ID` END ASC, 
		CASE WHEN PARAM_ORDER_FIELD = 'SYS_GENDER_ID' AND PARAM_ORDER_TYPE = 'DESC' THEN `system_gender`.`SYS_GENDER_ID` END DESC,
		CASE WHEN PARAM_ORDER_FIELD = 'SYS_GENDER_CODE' AND PARAM_ORDER_TYPE = 'ASC' THEN `system_gender`.`SYS_GENDER_CODE` END ASC, 
		CASE WHEN PARAM_ORDER_FIELD = 'SYS_GENDER_CODE' AND PARAM_ORDER_TYPE = 'DESC' THEN `system_gender`.`SYS_GENDER_CODE` END DESC,
		CASE WHEN PARAM_ORDER_FIELD = 'SYS_GENDER_DESCRIPTION' AND PARAM_ORDER_TYPE = 'ASC' THEN `system_gender`.`SYS_GENDER_DESCRIPTION` END ASC, 
		CASE WHEN PARAM_ORDER_FIELD = 'SYS_GENDER_DESCRIPTION' AND PARAM_ORDER_TYPE = 'DESC' THEN `system_gender`.`SYS_GENDER_DESCRIPTION` END DESC,
		CASE WHEN PARAM_ORDER_FIELD = 'SYS_GENDER_STATUS' AND PARAM_ORDER_TYPE = 'ASC' THEN `system_gender`.`SYS_GENDER_STATUS` END ASC, 
		CASE WHEN PARAM_ORDER_FIELD = 'SYS_GENDER_STATUS' AND PARAM_ORDER_TYPE = 'DESC' THEN `system_gender`.`SYS_GENDER_STATUS` END DESC,
		
		-- EXTRA
		CASE WHEN PARAM_ORDER_FIELD <> 'REC_USER_LAST_NAME' THEN `record_user`.`REC_USER_LAST_NAME` END ASC
		
	-- LIMIT & OFFSET
	-- ####################################################		
	LIMIT PARAM_SKIP, PARAM_LIMIT;
	
	
	
	-- EXIT PROCEDURE
	-- =========================================================================================
	LEAVE SP_GET;
			
END ;;
DELIMITER ;
/*!50003 SET sql_mode              = @saved_sql_mode */ ;
/*!50003 SET character_set_client  = @saved_cs_client */ ;
/*!50003 SET character_set_results = @saved_cs_results */ ;
/*!50003 SET collation_connection  = @saved_col_connection */ ;
/*!50003 DROP PROCEDURE IF EXISTS `RECORD_USER_SAVE` */;
/*!50003 SET @saved_cs_client      = @@character_set_client */ ;
/*!50003 SET @saved_cs_results     = @@character_set_results */ ;
/*!50003 SET @saved_col_connection = @@collation_connection */ ;
/*!50003 SET character_set_client  = latin1 */ ;
/*!50003 SET character_set_results = latin1 */ ;
/*!50003 SET collation_connection  = latin1_swedish_ci */ ;
/*!50003 SET @saved_sql_mode       = @@sql_mode */ ;
/*!50003 SET sql_mode              = '' */ ;
DELIMITER ;;
CREATE DEFINER=`root`@`localhost` PROCEDURE `RECORD_USER_SAVE`(
	IN `PARAM_REC_USER_ID` BIGINT,
	IN `PARAM_REC_USER_CAT_DEPARTMENT_ID` BIGINT,
	IN `PARAM_REC_USER_CAT_SECTION_ID` BIGINT,
	IN `PARAM_REC_USER_FIRST_NAME` VARCHAR(400),
	IN `PARAM_REC_USER_MIDDLE_NAME` VARCHAR(400),
	IN `PARAM_REC_USER_LAST_NAME` VARCHAR(400),
	IN `PARAM_REC_USER_SUFFIX` VARCHAR(40),
	IN `PARAM_REC_USER_SYS_GENDER_ID` BIGINT,
	IN `PARAM_REC_USER_NOTIFY_PHONE` VARCHAR(40),
	IN `PARAM_REC_USER_EMCONTACT_PERSON` VARCHAR(1000),
	IN `PARAM_REC_USER_EMCONTACT_NUMBER` VARCHAR(40),
	IN `PARAM_REC_USER_STATUS` TINYINT,

	IN `PARAM_REQUESTER_USERNAME` VARCHAR(500),
	IN `PARAM_REQUESTER_PASSWORD` VARCHAR(500),
	IN `PARAM_REQUESTER_PROXY_ID` BIGINT,
	IN `PARAM_REQUESTER_PROXY_PASSWORD` VARCHAR(1000),
	IN `PARAM_REQUESTER_DEVICE_PUBLIC_KEY` VARCHAR(1000),
	IN `PARAM_REQUESTER_DEVICE_PRIVATE_KEY` VARCHAR(1000),
	
	IN `PARAM_REQUESTER_IP` VARCHAR(1000),
	IN `PARAM_UNIQUE_SESSION_ID` VARCHAR(1000),
	IN `PARAM_SUPPRESS_RETURN` BIT,
	
	IN `PARAM_SYNC_SERVER_DESCRIPTION` VARCHAR(500), 
	IN `PARAM_SYNC_SERVER_UNIQUE_KEY` VARCHAR(500)
)
SP_SAVE:
BEGIN


	-- 1) DECLARE LOCAL PARAMETERS
	-- _______________________________________________________________________
	
	-- Status
	-- ...........................................
	DECLARE STATUS_INACTIVE TINYINT DEFAULT 1;
	DECLARE STATUS_ACTIVE TINYINT DEFAULT 2;
	DECLARE STATUS_CLOSED TINYINT DEFAULT 3;
	DECLARE STATUS_COMPLETED TINYINT DEFAULT 4;

	-- Audit Handler
	-- ...........................................
	DECLARE TEMP_RECORD_EXISTS BIT DEFAULT 0;
	DECLARE TEMP_MODULE_KEYWORD VARCHAR(500) DEFAULT 'record_user';
	DECLARE TEMP_SP_OBJECTIVE VARCHAR(500) DEFAULT 'add/edit User record';
	DECLARE TEMP_ERR_MESSAGE VARCHAR(500) DEFAULT '';
	DECLARE ERR BIGINT DEFAULT 0;
	DECLARE TEMP_RECORD_CHANGES VARCHAR(16000) DEFAULT '';
	DECLARE TEMP_RECORD_BINDED BIT DEFAULT 0;

	-- Authentication
	-- ...........................................
	DECLARE TEMP_ACCESS_RIGHTS_DENIED BIT DEFAULT 0;
	DECLARE TEMP_ACCESS_RIGHTS_HAS_OVERRIDE BIT DEFAULT 0;
	DECLARE TEMP_SYNC_SERVER_ID BIGINT DEFAULT 0;
	DECLARE TEMP_SYNC_IS_SERVER_REQUEST BIT DEFAULT 0;
	DECLARE TEMP_AUTHENTICATED_ACCOUNT_ID BIGINT DEFAULT `ACCOUNT_MEMBER@ACC_ACCOUNT_ID_FROM_LOGIN`(PARAM_REQUESTER_USERNAME, PARAM_REQUESTER_PASSWORD);
	DECLARE TEMP_AUTHENTICATED_ACCOUNT_LEVEL BIGINT DEFAULT 0;
	DECLARE TEMP_AUTHENTICATED_ACCOUNT_GROUP BIGINT DEFAULT 0;
	
	-- Local Parameters
	-- ...........................................
	DECLARE TEMP_NOW DATETIME(6) DEFAULT `SYSTEM_VAR@NOW`('', 1);
	DECLARE TEMP_RECORD_COUNT BIGINT DEFAULT 0;

	-- AutoGen Parameters
	-- ...........................................
	DECLARE PARAM_REC_USER_UNIQUE_CODE VARCHAR(400) DEFAULT ''; 
	
	-- Local value holder
	-- ...........................................
	DECLARE TEMP_REC_USER_CAT_DEPARTMENT_ID BIGINT DEFAULT 0; 
	DECLARE TEMP_REC_USER_CAT_SECTION_ID BIGINT DEFAULT 0; 
	DECLARE TEMP_REC_USER_UNIQUE_CODE VARCHAR(400) DEFAULT ''; 
	DECLARE TEMP_REC_USER_FIRST_NAME VARCHAR(400) DEFAULT ''; 
	DECLARE TEMP_REC_USER_MIDDLE_NAME VARCHAR(400) DEFAULT ''; 
	DECLARE TEMP_REC_USER_LAST_NAME VARCHAR(400) DEFAULT ''; 
	DECLARE TEMP_REC_USER_SUFFIX VARCHAR(40) DEFAULT ''; 
	DECLARE TEMP_REC_USER_SYS_GENDER_ID BIGINT DEFAULT 0; 
	DECLARE TEMP_REC_USER_NOTIFY_PHONE VARCHAR(40) DEFAULT ''; 
	DECLARE TEMP_REC_USER_EMCONTACT_PERSON VARCHAR(1000) DEFAULT ''; 
	DECLARE TEMP_REC_USER_EMCONTACT_NUMBER VARCHAR(40) DEFAULT ''; 
	DECLARE TEMP_REC_USER_STATUS TINYINT DEFAULT 0; 
	
	DECLARE REDUND_REC_USER_ID BIGINT DEFAULT 0; 


	-- 2) Try Catch / Throw
	-- _______________________________________________________________________
	DECLARE EXIT HANDLER FOR SQLEXCEPTION
	BEGIN
		RESIGNAL;
	END;



	-- 3) Prepare SYNC
	-- _______________________________________________________________________

	-- Dispose and create temp table for caching result
	-- ####################################################	
	DROP TEMPORARY TABLE IF EXISTS USER_SAVE_RESULT;
	CREATE TEMPORARY TABLE IF NOT EXISTS USER_SAVE_RESULT(REC_USER_ID BIGINT);


	-- IS RECORD EXISTS		
	-- ####################################################	
	SET TEMP_RECORD_EXISTS = `RECORD_USER@REC_USER_ID_EXISTS`(PARAM_REC_USER_ID, 0);

		
		
	-- 4) PREPARE AUTOGEN DATA (IF EXISTS)
	-- _______________________________________________________________________
	IF TEMP_SYNC_IS_SERVER_REQUEST = 0 THEN
		-- Just to keep at least one line within condition
		SET TEMP_SYNC_IS_SERVER_REQUEST = 0;
		
		-- Actual Functionalities here
		-- USE DEFAULT VALUE (String)
		-- USE DEFAULT VALUE (String)
		SET PARAM_REC_USER_UNIQUE_CODE = `SYSTEM_VAR@RANDOM_UNIQUE_STR`();
	END IF;



	-- 5) IF ALREADY EXIST, FILL MISSING DATA
	-- _______________________________________________________________________
	IF TEMP_RECORD_EXISTS = 1 THEN
		SELECT
			`record_user`.`REC_USER_CAT_DEPARTMENT_ID`, 	
			`record_user`.`REC_USER_CAT_SECTION_ID`, 	
			`record_user`.`REC_USER_UNIQUE_CODE`, 	
			`record_user`.`REC_USER_FIRST_NAME`, 	
			`record_user`.`REC_USER_MIDDLE_NAME`, 	
			`record_user`.`REC_USER_LAST_NAME`, 	
			`record_user`.`REC_USER_SUFFIX`, 	
			`record_user`.`REC_USER_SYS_GENDER_ID`, 	
			`record_user`.`REC_USER_NOTIFY_PHONE`, 	
			`record_user`.`REC_USER_EMCONTACT_PERSON`, 	
			`record_user`.`REC_USER_EMCONTACT_NUMBER`, 	
			`record_user`.`REC_USER_STATUS`	
		INTO
			TEMP_REC_USER_CAT_DEPARTMENT_ID, 	
			TEMP_REC_USER_CAT_SECTION_ID, 	
			TEMP_REC_USER_UNIQUE_CODE, 	
			TEMP_REC_USER_FIRST_NAME, 	
			TEMP_REC_USER_MIDDLE_NAME, 	
			TEMP_REC_USER_LAST_NAME, 	
			TEMP_REC_USER_SUFFIX, 	
			TEMP_REC_USER_SYS_GENDER_ID, 	
			TEMP_REC_USER_NOTIFY_PHONE, 	
			TEMP_REC_USER_EMCONTACT_PERSON, 	
			TEMP_REC_USER_EMCONTACT_NUMBER, 	
			TEMP_REC_USER_STATUS	

		FROM `record_user`
		WHERE
			`record_user`.`REC_USER_ID` = PARAM_REC_USER_ID
		LIMIT 1;

		-- Replace NULLs with the existing data.
		SET PARAM_REC_USER_CAT_DEPARTMENT_ID = `SYSTEM_VAR@REPLACE_NULL@BIGINT`(PARAM_REC_USER_CAT_DEPARTMENT_ID, TEMP_REC_USER_CAT_DEPARTMENT_ID, 1, 1);
		SET PARAM_REC_USER_CAT_SECTION_ID = `SYSTEM_VAR@REPLACE_NULL@BIGINT`(PARAM_REC_USER_CAT_SECTION_ID, TEMP_REC_USER_CAT_SECTION_ID, 1, 1);
		SET PARAM_REC_USER_FIRST_NAME = `SYSTEM_VAR@REPLACE_NULL@NVARCHAR`(PARAM_REC_USER_FIRST_NAME, TEMP_REC_USER_FIRST_NAME, 1);
		SET PARAM_REC_USER_MIDDLE_NAME = `SYSTEM_VAR@REPLACE_NULL@NVARCHAR`(PARAM_REC_USER_MIDDLE_NAME, TEMP_REC_USER_MIDDLE_NAME, 0);
		SET PARAM_REC_USER_LAST_NAME = `SYSTEM_VAR@REPLACE_NULL@NVARCHAR`(PARAM_REC_USER_LAST_NAME, TEMP_REC_USER_LAST_NAME, 1);
		SET PARAM_REC_USER_SUFFIX = `SYSTEM_VAR@REPLACE_NULL@NVARCHAR`(PARAM_REC_USER_SUFFIX, TEMP_REC_USER_SUFFIX, 0);
		SET PARAM_REC_USER_SYS_GENDER_ID = `SYSTEM_VAR@REPLACE_NULL@BIGINT`(PARAM_REC_USER_SYS_GENDER_ID, TEMP_REC_USER_SYS_GENDER_ID, 1, 1);
		SET PARAM_REC_USER_NOTIFY_PHONE = `SYSTEM_VAR@REPLACE_NULL@NVARCHAR`(PARAM_REC_USER_NOTIFY_PHONE, TEMP_REC_USER_NOTIFY_PHONE, 1);
		SET PARAM_REC_USER_EMCONTACT_PERSON = `SYSTEM_VAR@REPLACE_NULL@NVARCHAR`(PARAM_REC_USER_EMCONTACT_PERSON, TEMP_REC_USER_EMCONTACT_PERSON, 0);
		SET PARAM_REC_USER_EMCONTACT_NUMBER = `SYSTEM_VAR@REPLACE_NULL@NVARCHAR`(PARAM_REC_USER_EMCONTACT_NUMBER, TEMP_REC_USER_EMCONTACT_NUMBER, 0);
		SET PARAM_REC_USER_STATUS = `SYSTEM_VAR@REPLACE_NULL@TINYINT`(PARAM_REC_USER_STATUS, TEMP_REC_USER_STATUS, 1, 1);
		
		-- AUTO GEN (NON-UPDATABLES)		
		SET PARAM_REC_USER_UNIQUE_CODE = TEMP_REC_USER_UNIQUE_CODE;
		
		-- AUTO GEN (UPDATABLE WITH STATUS CHANGE)

		-- AUTO GEN (UPDATABLE WITH STATUS [ACTIVE/INACTIVE] CHANGE)
		
		-- NON-UPDATABLE
		SET PARAM_REC_USER_UNIQUE_CODE = TEMP_REC_USER_UNIQUE_CODE;
		
		-- NON-UPDATABLE BUT NULL
		
	ELSE
		SET PARAM_REC_USER_CAT_DEPARTMENT_ID = `SYSTEM_VAR@REPLACE_NULL@BIGINT`(PARAM_REC_USER_CAT_DEPARTMENT_ID, 0, 1, 1);
		SET PARAM_REC_USER_CAT_SECTION_ID = `SYSTEM_VAR@REPLACE_NULL@BIGINT`(PARAM_REC_USER_CAT_SECTION_ID, 0, 1, 1);
		SET PARAM_REC_USER_FIRST_NAME = `SYSTEM_VAR@REPLACE_NULL@NVARCHAR`(PARAM_REC_USER_FIRST_NAME, '', 1);
		SET PARAM_REC_USER_MIDDLE_NAME = `SYSTEM_VAR@REPLACE_NULL@NVARCHAR`(PARAM_REC_USER_MIDDLE_NAME, '', 0);
		SET PARAM_REC_USER_LAST_NAME = `SYSTEM_VAR@REPLACE_NULL@NVARCHAR`(PARAM_REC_USER_LAST_NAME, '', 1);
		SET PARAM_REC_USER_SUFFIX = `SYSTEM_VAR@REPLACE_NULL@NVARCHAR`(PARAM_REC_USER_SUFFIX, '', 0);
		SET PARAM_REC_USER_SYS_GENDER_ID = `SYSTEM_VAR@REPLACE_NULL@BIGINT`(PARAM_REC_USER_SYS_GENDER_ID, 0, 1, 1);
		SET PARAM_REC_USER_NOTIFY_PHONE = `SYSTEM_VAR@REPLACE_NULL@NVARCHAR`(PARAM_REC_USER_NOTIFY_PHONE, '', 1);
		SET PARAM_REC_USER_EMCONTACT_PERSON = `SYSTEM_VAR@REPLACE_NULL@NVARCHAR`(PARAM_REC_USER_EMCONTACT_PERSON, '', 0);
		SET PARAM_REC_USER_EMCONTACT_NUMBER = `SYSTEM_VAR@REPLACE_NULL@NVARCHAR`(PARAM_REC_USER_EMCONTACT_NUMBER, '', 0);
		SET PARAM_REC_USER_STATUS = `SYSTEM_VAR@REPLACE_NULL@TINYINT`(PARAM_REC_USER_STATUS, 0, 1, 1);
		
	END IF;

	

	-- 6) PREPARE AUDIT TRAIL
	-- _______________________________________________________________________
	IF TEMP_REC_USER_CAT_DEPARTMENT_ID <> PARAM_REC_USER_CAT_DEPARTMENT_ID THEN
		SET TEMP_RECORD_CHANGES = 
		`SYSTEM_VAR@CONCAT_ADD`(' | ', TEMP_RECORD_CHANGES, CONCAT_WS(' ', 'Department: "', TEMP_REC_USER_CAT_DEPARTMENT_ID, '" > "', PARAM_REC_USER_CAT_DEPARTMENT_ID, '"'));
	END IF;	
	IF TEMP_REC_USER_CAT_SECTION_ID <> PARAM_REC_USER_CAT_SECTION_ID THEN
		SET TEMP_RECORD_CHANGES = 
		`SYSTEM_VAR@CONCAT_ADD`(' | ', TEMP_RECORD_CHANGES, CONCAT_WS(' ', 'Section: "', TEMP_REC_USER_CAT_SECTION_ID, '" > "', PARAM_REC_USER_CAT_SECTION_ID, '"'));
	END IF;	
	IF BINARY TEMP_REC_USER_UNIQUE_CODE <> PARAM_REC_USER_UNIQUE_CODE THEN
		SET TEMP_RECORD_CHANGES = 
		`SYSTEM_VAR@CONCAT_ADD`(' | ', TEMP_RECORD_CHANGES, CONCAT_WS(' ', 'Unique Code: "', TEMP_REC_USER_UNIQUE_CODE, '" > "', PARAM_REC_USER_UNIQUE_CODE, '"'));
	END IF;
	IF BINARY TEMP_REC_USER_FIRST_NAME <> PARAM_REC_USER_FIRST_NAME THEN
		SET TEMP_RECORD_CHANGES = 
		`SYSTEM_VAR@CONCAT_ADD`(' | ', TEMP_RECORD_CHANGES, CONCAT_WS(' ', 'First name: "', TEMP_REC_USER_FIRST_NAME, '" > "', PARAM_REC_USER_FIRST_NAME, '"'));
	END IF;
	IF BINARY TEMP_REC_USER_MIDDLE_NAME <> PARAM_REC_USER_MIDDLE_NAME THEN
		SET TEMP_RECORD_CHANGES = 
		`SYSTEM_VAR@CONCAT_ADD`(' | ', TEMP_RECORD_CHANGES, CONCAT_WS(' ', 'Middle name: "', TEMP_REC_USER_MIDDLE_NAME, '" > "', PARAM_REC_USER_MIDDLE_NAME, '"'));
	END IF;
	IF BINARY TEMP_REC_USER_LAST_NAME <> PARAM_REC_USER_LAST_NAME THEN
		SET TEMP_RECORD_CHANGES = 
		`SYSTEM_VAR@CONCAT_ADD`(' | ', TEMP_RECORD_CHANGES, CONCAT_WS(' ', 'Last name: "', TEMP_REC_USER_LAST_NAME, '" > "', PARAM_REC_USER_LAST_NAME, '"'));
	END IF;
	IF BINARY TEMP_REC_USER_SUFFIX <> PARAM_REC_USER_SUFFIX THEN
		SET TEMP_RECORD_CHANGES = 
		`SYSTEM_VAR@CONCAT_ADD`(' | ', TEMP_RECORD_CHANGES, CONCAT_WS(' ', 'Suffix: "', TEMP_REC_USER_SUFFIX, '" > "', PARAM_REC_USER_SUFFIX, '"'));
	END IF;
	IF TEMP_REC_USER_SYS_GENDER_ID <> PARAM_REC_USER_SYS_GENDER_ID THEN
		SET TEMP_RECORD_CHANGES = 
		`SYSTEM_VAR@CONCAT_ADD`(' | ', TEMP_RECORD_CHANGES, CONCAT_WS(' ', 'Gender: "', TEMP_REC_USER_SYS_GENDER_ID, '" > "', PARAM_REC_USER_SYS_GENDER_ID, '"'));
	END IF;	
	IF BINARY TEMP_REC_USER_NOTIFY_PHONE <> PARAM_REC_USER_NOTIFY_PHONE THEN
		SET TEMP_RECORD_CHANGES = 
		`SYSTEM_VAR@CONCAT_ADD`(' | ', TEMP_RECORD_CHANGES, CONCAT_WS(' ', 'Notification Mobile Number: "', TEMP_REC_USER_NOTIFY_PHONE, '" > "', PARAM_REC_USER_NOTIFY_PHONE, '"'));
	END IF;
	IF BINARY TEMP_REC_USER_EMCONTACT_PERSON <> PARAM_REC_USER_EMCONTACT_PERSON THEN
		SET TEMP_RECORD_CHANGES = 
		`SYSTEM_VAR@CONCAT_ADD`(' | ', TEMP_RECORD_CHANGES, CONCAT_WS(' ', 'Emergency Contact Person: "', TEMP_REC_USER_EMCONTACT_PERSON, '" > "', PARAM_REC_USER_EMCONTACT_PERSON, '"'));
	END IF;
	IF BINARY TEMP_REC_USER_EMCONTACT_NUMBER <> PARAM_REC_USER_EMCONTACT_NUMBER THEN
		SET TEMP_RECORD_CHANGES = 
		`SYSTEM_VAR@CONCAT_ADD`(' | ', TEMP_RECORD_CHANGES, CONCAT_WS(' ', 'Emergency Contact Number: "', TEMP_REC_USER_EMCONTACT_NUMBER, '" > "', PARAM_REC_USER_EMCONTACT_NUMBER, '"'));
	END IF;
	IF TEMP_REC_USER_STATUS <> PARAM_REC_USER_STATUS THEN
		SET TEMP_RECORD_CHANGES = 
		`SYSTEM_VAR@CONCAT_ADD`(' | ', TEMP_RECORD_CHANGES, CONCAT_WS(' ', 'Status: "', TEMP_REC_USER_STATUS, '" > "', PARAM_REC_USER_STATUS, '"'));
	END IF;	
		
	-- No Changes in data, reject request
	-- ####################################################
	IF CHARACTER_LENGTH(TEMP_RECORD_CHANGES) = 0 THEN
		IF PARAM_SUPPRESS_RETURN = 0 THEN
			SELECT PARAM_REC_USER_ID AS INSERTED_ID;
		END IF;
		LEAVE SP_SAVE;
	END IF;



	-- 7) VALIDATE
	-- _______________________________________________________________________

	-- Access Rights [Device]
	-- ####################################################
	IF `ACCOUNT_DEVICE@HAS_PERMISSION`(PARAM_REQUESTER_DEVICE_PUBLIC_KEY, PARAM_REQUESTER_DEVICE_PRIVATE_KEY) = 0 THEN
		SET TEMP_ERR_MESSAGE = 'Your device is not authorized yet to access this server.';
		SET ERR = `RAISERROR`(TEMP_ERR_MESSAGE);		
	END IF;
		
		
	-- Access Rights [Account]
	-- ####################################################
	
	IF 
		-- [ADD] Access Rights
		(
			TEMP_RECORD_EXISTS = 0 AND
			`ACCOUNT_ACCESS_RIGHTS@HAS_PERMISSION`(PARAM_REQUESTER_USERNAME, PARAM_REQUESTER_PASSWORD, 0, TEMP_MODULE_KEYWORD, 2) = 0 AND
			`ACCOUNT_ACCESS_RIGHTS@PROXY_PERMISSION`(PARAM_REQUESTER_PROXY_ID, PARAM_REQUESTER_PROXY_PASSWORD, 0, TEMP_MODULE_KEYWORD, 2) = 0
		) OR
		
		-- [EDIT] Access Rights
		(
			TEMP_RECORD_EXISTS = 1 AND
			`ACCOUNT_ACCESS_RIGHTS@HAS_PERMISSION`(PARAM_REQUESTER_USERNAME, PARAM_REQUESTER_PASSWORD, 0, TEMP_MODULE_KEYWORD, 3) = 0 AND
			`ACCOUNT_ACCESS_RIGHTS@PROXY_PERMISSION`(PARAM_REQUESTER_PROXY_ID, PARAM_REQUESTER_PROXY_PASSWORD, 0, TEMP_MODULE_KEYWORD, 3) = 0
		)
	THEN
		SET TEMP_ACCESS_RIGHTS_DENIED = 1;
		CALL `ACCOUNT_ACCESS_RIGHTS_DENY`
		(
			0, TEMP_MODULE_KEYWORD, PARAM_REC_USER_ID, 0, TEMP_SP_OBJECTIVE, TEMP_RECORD_CHANGES, 
			PARAM_REQUESTER_USERNAME, PARAM_REQUESTER_PASSWORD, 
			PARAM_REQUESTER_PROXY_ID, PARAM_REQUESTER_PROXY_PASSWORD,
			PARAM_REQUESTER_DEVICE_PUBLIC_KEY, PARAM_REQUESTER_DEVICE_PRIVATE_KEY,
			PARAM_REQUESTER_IP, PARAM_UNIQUE_SESSION_ID,
			TEMP_SYNC_SERVER_ID, PARAM_SUPPRESS_RETURN
		);
	END IF;
	SET TEMP_ACCESS_RIGHTS_HAS_OVERRIDE = `ACCOUNT_ACCESS_RIGHTS@HAS_PERMISSION`(PARAM_REQUESTER_USERNAME, PARAM_REQUESTER_PASSWORD, 0, TEMP_MODULE_KEYWORD, 4);
	

	-- Validation
	-- ####################################################
	IF TEMP_SYNC_IS_SERVER_REQUEST = 0 THEN
	

		-- FOREIGN KEY EXISTS
		-- ...........................................
		IF `CATEGORY_DEPARTMENT@CAT_DEPARTMENT_ID_EXISTS`(PARAM_REC_USER_CAT_DEPARTMENT_ID, 0) =  0 THEN
			SET TEMP_ERR_MESSAGE = CONCAT_WS(' ', 'Given Department does not exists or is inactive. ID: ', PARAM_REC_USER_CAT_DEPARTMENT_ID);
			SET ERR = `RAISERROR`(TEMP_ERR_MESSAGE);
		END IF;
		IF `CATEGORY_SECTION@CAT_SECTION_ID_EXISTS`(PARAM_REC_USER_CAT_SECTION_ID, 0) =  0 THEN
			SET TEMP_ERR_MESSAGE = CONCAT_WS(' ', 'Given Section does not exists or is inactive. ID: ', PARAM_REC_USER_CAT_SECTION_ID);
			SET ERR = `RAISERROR`(TEMP_ERR_MESSAGE);
		END IF;
		IF `SYSTEM_GENDER@SYS_GENDER_ID_EXISTS`(PARAM_REC_USER_SYS_GENDER_ID, 0) =  0 THEN
			SET TEMP_ERR_MESSAGE = CONCAT_WS(' ', 'Given Gender does not exists or is inactive. ID: ', PARAM_REC_USER_SYS_GENDER_ID);
			SET ERR = `RAISERROR`(TEMP_ERR_MESSAGE);
		END IF;
		
		-- FOREIGN (OPTIONAL)KEY EXISTS [Validates if not null]
		-- ...........................................
		
		-- IS_ALLOW_NULL = FALSE
		-- ...........................................
		IF PARAM_REC_USER_MIDDLE_NAME IS NULL THEN
			CALL `VALIDATION_MISSING_FIELD`('`REC_USER_MIDDLE_NAME`', '`NULL`');
		END IF;
		IF PARAM_REC_USER_SUFFIX IS NULL THEN
			CALL `VALIDATION_MISSING_FIELD`('`REC_USER_SUFFIX`', '`NULL`');
		END IF;
		IF PARAM_REC_USER_EMCONTACT_PERSON IS NULL THEN
			CALL `VALIDATION_MISSING_FIELD`('`REC_USER_EMCONTACT_PERSON`', '`NULL`');
		END IF;
		IF PARAM_REC_USER_EMCONTACT_NUMBER IS NULL THEN
			CALL `VALIDATION_MISSING_FIELD`('`REC_USER_EMCONTACT_NUMBER`', '`NULL`');
		END IF;
				
		-- IS_ALLOW_ZERO = FALSE
		-- ...........................................
		IF PARAM_REC_USER_STATUS = 0 THEN
			CALL `VALIDATION_MISSING_FIELD`('`REC_USER_STATUS`', '`NULL`');
		END IF;		
		
		-- IS_ALLOW_NEGATIVE = FALSE
		-- ...........................................
		IF PARAM_REC_USER_STATUS < 0 THEN
			CALL `VALIDATION_NEGATIVE`('`REC_USER_STATUS`', PARAM_REC_USER_STATUS);
		END IF;		
		
		-- IS_ALLOW_EMPTY_STRING = FALSE
		-- ...........................................
		IF `SYSTEM_VAR@IS_NULL@NVARCHAR`(PARAM_REC_USER_UNIQUE_CODE, 1) = 1 THEN
			CALL `VALIDATION_MISSING_FIELD`('`REC_USER_UNIQUE_CODE`', '`NULL`');
		END IF;
		IF `SYSTEM_VAR@IS_NULL@NVARCHAR`(PARAM_REC_USER_FIRST_NAME, 1) = 1 THEN
			CALL `VALIDATION_MISSING_FIELD`('`REC_USER_FIRST_NAME`', '`NULL`');
		END IF;
		IF `SYSTEM_VAR@IS_NULL@NVARCHAR`(PARAM_REC_USER_LAST_NAME, 1) = 1 THEN
			CALL `VALIDATION_MISSING_FIELD`('`REC_USER_LAST_NAME`', '`NULL`');
		END IF;
		IF `SYSTEM_VAR@IS_NULL@NVARCHAR`(PARAM_REC_USER_NOTIFY_PHONE, 1) = 1 THEN
			CALL `VALIDATION_MISSING_FIELD`('`REC_USER_NOTIFY_PHONE`', '`NULL`');
		END IF;
		
		-- IS_STATUS
		-- ...........................................
		IF `SYSTEM_STATUS@SYS_STATUS_ID_EXISTS`(PARAM_REC_USER_STATUS, 0) = 0 THEN
			SET TEMP_ERR_MESSAGE = CONCAT_WS(' ', 'Given STATUS[Status] does not exists or is inactive. ID: ', PARAM_REC_USER_STATUS);
			SET ERR = `RAISERROR`(TEMP_ERR_MESSAGE);
		END IF;
		
		-- IS STATUS Active / Inactive
		-- ...........................................
		
		-- Minimum / Maximum Value
		-- ...........................................
		
		-- IS_UNIQUE = TRUE
		-- ...........................................
		IF
		(
			SELECT COUNT(`record_user`.`REC_USER_ID`)
			FROM `record_user`
			WHERE		
				`record_user`.`REC_USER_UNIQUE_CODE` = PARAM_REC_USER_UNIQUE_CODE AND		
				`record_user`.`REC_USER_ID` <> PARAM_REC_USER_ID
		) >= 1
		THEN
			SELECT `record_user`.`REC_USER_ID`
			INTO REDUND_REC_USER_ID
			FROM `record_user`
			WHERE		
				`record_user`.`REC_USER_UNIQUE_CODE` = PARAM_REC_USER_UNIQUE_CODE AND		
				`record_user`.`REC_USER_ID` <> PARAM_REC_USER_ID		
			LIMIT 1; 
			SET TEMP_ERR_MESSAGE = CONCAT_WS(' ', PARAM_REC_USER_LAST_NAME, '[', REDUND_REC_USER_ID, ']');
			CALL `VALIDATION_REDUNDANT_ENTRY`(TEMP_ERR_MESSAGE);
		END IF;
		
		-- RECORD IDENTIFIER
		-- ...........................................
		
		
		-- ON_UPDATE VALIDATION 
		-- ...........................................
		IF TEMP_RECORD_EXISTS = 1 THEN	
		
			-- Just to keep at least one line within condition
			SET TEMP_RECORD_EXISTS = 1;
			
		END IF;
		
	END IF;



	-- 8) INSERT / UPDATE
	-- _______________________________________________________________________

	-- INSERT NEW DATA
	-- ####################################################
	IF TEMP_RECORD_EXISTS = 0 THEN

		INSERT INTO
		`record_user`
		(
			`record_user`.`REC_USER_CAT_DEPARTMENT_ID`, 
			`record_user`.`REC_USER_CAT_SECTION_ID`, 
			`record_user`.`REC_USER_UNIQUE_CODE`, 
			`record_user`.`REC_USER_FIRST_NAME`, 
			`record_user`.`REC_USER_MIDDLE_NAME`, 
			`record_user`.`REC_USER_LAST_NAME`, 
			`record_user`.`REC_USER_SUFFIX`, 
			`record_user`.`REC_USER_SYS_GENDER_ID`, 
			`record_user`.`REC_USER_NOTIFY_PHONE`, 
			`record_user`.`REC_USER_EMCONTACT_PERSON`, 
			`record_user`.`REC_USER_EMCONTACT_NUMBER`, 

			`record_user`.`REC_USER_ACC_ACCOUNT_ID`, 
			`record_user`.`REC_USER_RECORDED_DATE`, 		

			`record_user`.`REC_USER_STATUS`
		)
		VALUES
		(
			PARAM_REC_USER_CAT_DEPARTMENT_ID, 
			PARAM_REC_USER_CAT_SECTION_ID, 
			PARAM_REC_USER_UNIQUE_CODE, 
			PARAM_REC_USER_FIRST_NAME, 
			PARAM_REC_USER_MIDDLE_NAME, 
			PARAM_REC_USER_LAST_NAME, 
			PARAM_REC_USER_SUFFIX, 
			PARAM_REC_USER_SYS_GENDER_ID, 
			PARAM_REC_USER_NOTIFY_PHONE, 
			PARAM_REC_USER_EMCONTACT_PERSON, 
			PARAM_REC_USER_EMCONTACT_NUMBER, 

			TEMP_AUTHENTICATED_ACCOUNT_ID,
			TEMP_NOW,

			PARAM_REC_USER_STATUS
		);	
		
		-- Update Audit trail with new ID	
		SET PARAM_REC_USER_ID = LAST_INSERT_ID();

		-- Save to Temp Table
		INSERT INTO USER_SAVE_RESULT(REC_USER_ID)
		VALUE(PARAM_REC_USER_ID);
	


	-- UPDATING EXISTING RECORD
	-- ####################################################
	ELSE
		UPDATE `record_user`
		SET
			`record_user`.`REC_USER_CAT_DEPARTMENT_ID` = PARAM_REC_USER_CAT_DEPARTMENT_ID, 
			`record_user`.`REC_USER_CAT_SECTION_ID` = PARAM_REC_USER_CAT_SECTION_ID, 
			`record_user`.`REC_USER_UNIQUE_CODE` = PARAM_REC_USER_UNIQUE_CODE, 
			`record_user`.`REC_USER_FIRST_NAME` = PARAM_REC_USER_FIRST_NAME, 
			`record_user`.`REC_USER_MIDDLE_NAME` = PARAM_REC_USER_MIDDLE_NAME, 
			`record_user`.`REC_USER_LAST_NAME` = PARAM_REC_USER_LAST_NAME, 
			`record_user`.`REC_USER_SUFFIX` = PARAM_REC_USER_SUFFIX, 
			`record_user`.`REC_USER_SYS_GENDER_ID` = PARAM_REC_USER_SYS_GENDER_ID, 
			`record_user`.`REC_USER_NOTIFY_PHONE` = PARAM_REC_USER_NOTIFY_PHONE, 
			`record_user`.`REC_USER_EMCONTACT_PERSON` = PARAM_REC_USER_EMCONTACT_PERSON, 
			`record_user`.`REC_USER_EMCONTACT_NUMBER` = PARAM_REC_USER_EMCONTACT_NUMBER, 
			`record_user`.`REC_USER_STATUS` = PARAM_REC_USER_STATUS
		WHERE
			`record_user`.`REC_USER_ID` = PARAM_REC_USER_ID;

	END IF;

	
	-- 9) AUDIT TRAIL
	-- _______________________________________________________________________
	CALL `ACCOUNT_AUDIT_TRAIL_SAVE`
	(
		0, TEMP_MODULE_KEYWORD, PARAM_REC_USER_ID, 0, 'SAVE', TEMP_SP_OBJECTIVE, TEMP_RECORD_CHANGES, 
		PARAM_REQUESTER_USERNAME, PARAM_REQUESTER_PASSWORD, 
		PARAM_REQUESTER_PROXY_ID, PARAM_REQUESTER_PROXY_PASSWORD,
		PARAM_REQUESTER_DEVICE_PUBLIC_KEY, PARAM_REQUESTER_DEVICE_PRIVATE_KEY,
		PARAM_REQUESTER_IP, PARAM_UNIQUE_SESSION_ID,
		TEMP_SYNC_SERVER_ID, PARAM_SUPPRESS_RETURN
	);
	

	-- 10) RETURN RESULT
	-- _______________________________________________________________________
	IF PARAM_SUPPRESS_RETURN = 0 THEN
		SELECT 
			PARAM_REC_USER_ID AS INSERTED_ID,
			TEMP_NOW AS SERVER_TIME;
	END IF;
	LEAVE SP_SAVE;


END ;;
DELIMITER ;
/*!50003 SET sql_mode              = @saved_sql_mode */ ;
/*!50003 SET character_set_client  = @saved_cs_client */ ;
/*!50003 SET character_set_results = @saved_cs_results */ ;
/*!50003 SET collation_connection  = @saved_col_connection */ ;
/*!50003 DROP PROCEDURE IF EXISTS `STRING_SPLIT` */;
/*!50003 SET @saved_cs_client      = @@character_set_client */ ;
/*!50003 SET @saved_cs_results     = @@character_set_results */ ;
/*!50003 SET @saved_col_connection = @@collation_connection */ ;
/*!50003 SET character_set_client  = latin1 */ ;
/*!50003 SET character_set_results = latin1 */ ;
/*!50003 SET collation_connection  = latin1_swedish_ci */ ;
/*!50003 SET @saved_sql_mode       = @@sql_mode */ ;
/*!50003 SET sql_mode              = '' */ ;
DELIMITER ;;
CREATE DEFINER=`root`@`localhost` PROCEDURE `STRING_SPLIT`(
	IN `STRING_TO_SPLIT` VARCHAR(16000),
	IN `PARAM_SPLIT_CHARACTER` VARCHAR(1)
)
SP_GET:
BEGIN

	DECLARE SPLIT_RESULT VARCHAR(500) DEFAULT '';
	DECLARE CURRENT_INDEX INT DEFAULT 0;	
	
	-- Audit Handler
	DECLARE ERR BIGINT DEFAULT 0;	
	
	-- Dispose and create temp table for caching result
	DROP TEMPORARY TABLE IF EXISTS SPLIT_RESULT;
	CREATE TEMPORARY TABLE IF NOT EXISTS SPLIT_RESULT(SPLIT_ID BIGINT NOT NULL AUTO_INCREMENT PRIMARY KEY, SPLIT_VALUE VARCHAR(500));

	-- Split Items
	WHILE LOCATE(PARAM_SPLIT_CHARACTER, STRING_TO_SPLIT) > 0
	DO
		SET CURRENT_INDEX = LOCATE(PARAM_SPLIT_CHARACTER, STRING_TO_SPLIT) ; 
		SET SPLIT_RESULT = SUBSTRING(STRING_TO_SPLIT, 1, CURRENT_INDEX - 1);

		INSERT INTO
		SPLIT_RESULT
		(
			SPLIT_VALUE
		)
		VALUE
		(
			SPLIT_RESULT
		);

		SET STRING_TO_SPLIT = SUBSTRING(STRING_TO_SPLIT, CURRENT_INDEX + 1, LENGTH(STRING_TO_SPLIT) - CURRENT_INDEX);
	END WHILE;

	-- Cache Result
	INSERT INTO
	SPLIT_RESULT
	(
		SPLIT_VALUE
	)
	VALUE
	(
		STRING_TO_SPLIT
	);
			
END ;;
DELIMITER ;
/*!50003 SET sql_mode              = @saved_sql_mode */ ;
/*!50003 SET character_set_client  = @saved_cs_client */ ;
/*!50003 SET character_set_results = @saved_cs_results */ ;
/*!50003 SET collation_connection  = @saved_col_connection */ ;
/*!50003 DROP PROCEDURE IF EXISTS `SYSTEM_ACCESS_RIGHTS_AUTHORITY_GET` */;
/*!50003 SET @saved_cs_client      = @@character_set_client */ ;
/*!50003 SET @saved_cs_results     = @@character_set_results */ ;
/*!50003 SET @saved_col_connection = @@collation_connection */ ;
/*!50003 SET character_set_client  = latin1 */ ;
/*!50003 SET character_set_results = latin1 */ ;
/*!50003 SET collation_connection  = latin1_swedish_ci */ ;
/*!50003 SET @saved_sql_mode       = @@sql_mode */ ;
/*!50003 SET sql_mode              = '' */ ;
DELIMITER ;;
CREATE DEFINER=`root`@`localhost` PROCEDURE `SYSTEM_ACCESS_RIGHTS_AUTHORITY_GET`(
	IN `PARAM_SYS_AUTHORITY_ID` BIGINT,	
	IN `PARAM_SYS_AUTHORITY_DESCRIPTION` VARCHAR(500),	
	IN `PARAM_SYS_AUTHORITY_STATUS` TINYINT,	
		
	IN `PARAM_ORDER_FIELD` VARCHAR(500),
	IN `PARAM_ORDER_TYPE` VARCHAR(500),
	IN `PARAM_SKIP` BIGINT,
	IN `PARAM_LIMIT` BIGINT,

	IN `PARAM_REQUESTER_USERNAME` VARCHAR(500),
	IN `PARAM_REQUESTER_PASSWORD` VARCHAR(500),
	IN `PARAM_REQUESTER_PROXY_ID` BIGINT,
	IN `PARAM_REQUESTER_PROXY_PASSWORD` VARCHAR(1000),
	IN `PARAM_REQUESTER_DEVICE_PUBLIC_KEY` VARCHAR(1000),
	IN `PARAM_REQUESTER_DEVICE_PRIVATE_KEY` VARCHAR(1000),
	
	IN `PARAM_REQUESTER_IP` VARCHAR(1000),
	IN `PARAM_UNIQUE_SESSION_ID` VARCHAR(1000),
	IN `PARAM_SUPPRESS_RETURN` BIT
)
SP_GET:
BEGIN

	-- Status
	-- =========================================================================================
	DECLARE STATUS_INACTIVE TINYINT DEFAULT 1;
	DECLARE STATUS_ACTIVE TINYINT DEFAULT 2;
	DECLARE STATUS_CLOSED TINYINT DEFAULT 3;
	DECLARE STATUS_COMPLETED TINYINT DEFAULT 4;
	
	-- Audit Handler
	-- =========================================================================================
	DECLARE TEMP_RECORD_EXISTS BIT DEFAULT 0;
	DECLARE TEMP_MODULE_KEYWORD VARCHAR(500) DEFAULT 'system_access_rights_authority';
	DECLARE TEMP_SP_OBJECTIVE VARCHAR(500) DEFAULT 'Retrieve Access Rights Authorities record';
	DECLARE TEMP_ERR_MESSAGE VARCHAR(500) DEFAULT '';
	DECLARE ERR BIGINT DEFAULT 0;
	DECLARE TEMP_RECORD_CHANGES VARCHAR(16000) DEFAULT '';
	DECLARE TEMP_RECORD_BINDED BIT DEFAULT 0;
	
	DECLARE TEMP_RECORD_BINDED_ID BIGINT DEFAULT 0;
	DECLARE TEMP_RECORD_BINDED_SERVER_ID BIGINT DEFAULT 0;
	
	-- Authentication
	-- =========================================================================================
	DECLARE TEMP_ACCESS_RIGHTS_DENIED BIT DEFAULT 0;
	DECLARE TEMP_AUTHENTICATED_ACCOUNT_ID BIGINT DEFAULT `ACCOUNT_MEMBER@ACC_ACCOUNT_ID_FROM_LOGIN`(PARAM_REQUESTER_USERNAME, PARAM_REQUESTER_PASSWORD);
	DECLARE TEMP_AUTHENTICATED_ACCOUNT_LEVEL BIGINT DEFAULT 0;
	DECLARE TEMP_AUTHENTICATED_ACCOUNT_GROUP BIGINT DEFAULT 0;
	
	-- Local Parameters
	-- =========================================================================================
	DECLARE TEMP_NOW DATETIME(6) DEFAULT `SYSTEM_VAR@NOW`('', 1);
	DECLARE TEMP_RECORD_COUNT BIGINT DEFAULT 0;
	
	
	-- Check NULLs
	-- =========================================================================================
	DECLARE IS_NULL_SYS_AUTHORITY_ID BIT DEFAULT `SYSTEM_VAR@IS_NULL@BIGINT`(PARAM_SYS_AUTHORITY_ID, 1, 1);
	DECLARE IS_NULL_SYS_AUTHORITY_DESCRIPTION BIT DEFAULT `SYSTEM_VAR@IS_NULL@NVARCHAR`(PARAM_SYS_AUTHORITY_DESCRIPTION, 1);
	DECLARE IS_NULL_SYS_AUTHORITY_STATUS BIT DEFAULT `SYSTEM_VAR@IS_NULL@TINYINT`(PARAM_SYS_AUTHORITY_STATUS, 1, 1);
	
	-- Error Handler
	-- =========================================================================================
	DECLARE EXIT HANDLER FOR SQLEXCEPTION
	BEGIN
		RESIGNAL;
	END;
	
	-- Ignore Time from DateTime (Set Time 00:00:00.000000 and 23:59:59.999999)
	-- =========================================================================================
		
		
	-- Access Rights [Device]
	-- =========================================================================================

		
		
	-- Access Rights [Account]
	-- =========================================================================================
		
	
	
	
	-- COUNT RECORD
	-- =========================================================================================
	
	-- SELECT COLUMNS
	-- ####################################################
	SELECT
		COUNT(DISTINCT `system_access_rights_authority`.`SYS_AUTHORITY_ID`)
	INTO
		TEMP_RECORD_COUNT

	FROM `system_access_rights_authority`
	
		-- Add Inner Joins (Per Foreign-key)
		
		-- Add Optional Left Joins (Per Optional Foreign-key)
		
	-- CONDITIONS
	-- ####################################################
	WHERE
		(
			IS_NULL_SYS_AUTHORITY_ID = 1 OR
			`system_access_rights_authority`.`SYS_AUTHORITY_ID` = PARAM_SYS_AUTHORITY_ID			
		) AND
		(
			IS_NULL_SYS_AUTHORITY_DESCRIPTION = 1 OR
			`system_access_rights_authority`.`SYS_AUTHORITY_DESCRIPTION` LIKE CONCAT_WS('%', '', PARAM_SYS_AUTHORITY_DESCRIPTION, '')			
		) AND 		
		(
			IS_NULL_SYS_AUTHORITY_STATUS = 1 OR
			`system_access_rights_authority`.`SYS_AUTHORITY_STATUS` = PARAM_SYS_AUTHORITY_STATUS			
		) 
;	

		
		
	-- SELECT RECORDS
	-- =========================================================================================
	
	-- FETCH COLUMNS
	-- ####################################################
	SELECT
		-- SYSTEM_ACCESS_RIGHTS_AUTHORITY DETAILS
		`system_access_rights_authority`.`SYS_AUTHORITY_ID`, 
		`system_access_rights_authority`.`SYS_AUTHORITY_DESCRIPTION`, 
		`system_access_rights_authority`.`SYS_AUTHORITY_STATUS`
		
		-- Inner join fields
		
		-- Left join fields
		
		, TEMP_RECORD_COUNT AS RECORD_COUNT

	FROM `system_access_rights_authority`
	
		-- Add Inner Joins (Per Foreign-key)
		
		-- Add Optional Left Joins (Per Optional Foreign-key)
		
	-- CONDITIONS
	-- ####################################################
	WHERE
		(
			IS_NULL_SYS_AUTHORITY_ID = 1 OR
			`system_access_rights_authority`.`SYS_AUTHORITY_ID` = PARAM_SYS_AUTHORITY_ID			
		) AND
		(
			IS_NULL_SYS_AUTHORITY_DESCRIPTION = 1 OR
			`system_access_rights_authority`.`SYS_AUTHORITY_DESCRIPTION` LIKE CONCAT_WS('%', '', PARAM_SYS_AUTHORITY_DESCRIPTION, '')			
		) AND 		
		(
			IS_NULL_SYS_AUTHORITY_STATUS = 1 OR
			`system_access_rights_authority`.`SYS_AUTHORITY_STATUS` = PARAM_SYS_AUTHORITY_STATUS			
		) 

	-- ORDER BY
	-- ####################################################
	ORDER BY
		-- SYSTEM_ACCESS_RIGHTS_AUTHORITY DETAILS
		CASE WHEN PARAM_ORDER_FIELD = 'SYS_AUTHORITY_ID' AND PARAM_ORDER_TYPE = 'ASC' THEN `system_access_rights_authority`.`SYS_AUTHORITY_ID` END ASC, 
		CASE WHEN PARAM_ORDER_FIELD = 'SYS_AUTHORITY_ID' AND PARAM_ORDER_TYPE = 'DESC' THEN `system_access_rights_authority`.`SYS_AUTHORITY_ID` END DESC,	
		CASE WHEN PARAM_ORDER_FIELD = 'SYS_AUTHORITY_DESCRIPTION' AND PARAM_ORDER_TYPE = 'ASC' THEN `system_access_rights_authority`.`SYS_AUTHORITY_DESCRIPTION` END ASC, 
		CASE WHEN PARAM_ORDER_FIELD = 'SYS_AUTHORITY_DESCRIPTION' AND PARAM_ORDER_TYPE = 'DESC' THEN `system_access_rights_authority`.`SYS_AUTHORITY_DESCRIPTION` END DESC,	
		CASE WHEN PARAM_ORDER_FIELD = 'SYS_AUTHORITY_STATUS' AND PARAM_ORDER_TYPE = 'ASC' THEN `system_access_rights_authority`.`SYS_AUTHORITY_STATUS` END ASC, 
		CASE WHEN PARAM_ORDER_FIELD = 'SYS_AUTHORITY_STATUS' AND PARAM_ORDER_TYPE = 'DESC' THEN `system_access_rights_authority`.`SYS_AUTHORITY_STATUS` END DESC,	

		-- Inner joins
		
		-- EXTRA
		CASE WHEN PARAM_ORDER_FIELD <> 'SYS_AUTHORITY_DESCRIPTION' THEN `system_access_rights_authority`.`SYS_AUTHORITY_DESCRIPTION` END ASC
		
	-- LIMIT & OFFSET
	-- ####################################################		
	LIMIT PARAM_SKIP, PARAM_LIMIT;
	
	
	
	-- EXIT PROCEDURE
	-- =========================================================================================
	LEAVE SP_GET;
			
END ;;
DELIMITER ;
/*!50003 SET sql_mode              = @saved_sql_mode */ ;
/*!50003 SET character_set_client  = @saved_cs_client */ ;
/*!50003 SET character_set_results = @saved_cs_results */ ;
/*!50003 SET collation_connection  = @saved_col_connection */ ;
/*!50003 DROP PROCEDURE IF EXISTS `SYSTEM_BLOOD_TYPE_GET` */;
/*!50003 SET @saved_cs_client      = @@character_set_client */ ;
/*!50003 SET @saved_cs_results     = @@character_set_results */ ;
/*!50003 SET @saved_col_connection = @@collation_connection */ ;
/*!50003 SET character_set_client  = latin1 */ ;
/*!50003 SET character_set_results = latin1 */ ;
/*!50003 SET collation_connection  = latin1_swedish_ci */ ;
/*!50003 SET @saved_sql_mode       = @@sql_mode */ ;
/*!50003 SET sql_mode              = '' */ ;
DELIMITER ;;
CREATE DEFINER=`root`@`localhost` PROCEDURE `SYSTEM_BLOOD_TYPE_GET`(
	IN `PARAM_SYS_BLOODTYPE_ID` BIGINT,	
	IN `PARAM_SYS_BLOODTYPE_CODE` VARCHAR(50),	
	IN `PARAM_SYS_BLOODTYPE_DESCRIPTION` VARCHAR(500),	
	IN `PARAM_SYS_BLOODTYPE_STATUS` TINYINT,	
		
	IN `PARAM_ORDER_FIELD` VARCHAR(500),
	IN `PARAM_ORDER_TYPE` VARCHAR(500),
	IN `PARAM_SKIP` BIGINT,
	IN `PARAM_LIMIT` BIGINT,

	IN `PARAM_REQUESTER_USERNAME` VARCHAR(500),
	IN `PARAM_REQUESTER_PASSWORD` VARCHAR(500),
	IN `PARAM_REQUESTER_PROXY_ID` BIGINT,
	IN `PARAM_REQUESTER_PROXY_PASSWORD` VARCHAR(1000),
	IN `PARAM_REQUESTER_DEVICE_PUBLIC_KEY` VARCHAR(1000),
	IN `PARAM_REQUESTER_DEVICE_PRIVATE_KEY` VARCHAR(1000),
	
	IN `PARAM_REQUESTER_IP` VARCHAR(1000),
	IN `PARAM_UNIQUE_SESSION_ID` VARCHAR(1000),
	IN `PARAM_SUPPRESS_RETURN` BIT
)
SP_GET:
BEGIN

	-- Status
	-- =========================================================================================
	DECLARE STATUS_INACTIVE TINYINT DEFAULT 1;
	DECLARE STATUS_ACTIVE TINYINT DEFAULT 2;
	DECLARE STATUS_CLOSED TINYINT DEFAULT 3;
	DECLARE STATUS_COMPLETED TINYINT DEFAULT 4;
	
	-- Audit Handler
	-- =========================================================================================
	DECLARE TEMP_RECORD_EXISTS BIT DEFAULT 0;
	DECLARE TEMP_MODULE_KEYWORD VARCHAR(500) DEFAULT 'system_blood_type';
	DECLARE TEMP_SP_OBJECTIVE VARCHAR(500) DEFAULT 'Retrieve Blood Type record';
	DECLARE TEMP_ERR_MESSAGE VARCHAR(500) DEFAULT '';
	DECLARE ERR BIGINT DEFAULT 0;
	DECLARE TEMP_RECORD_CHANGES VARCHAR(16000) DEFAULT '';
	DECLARE TEMP_RECORD_BINDED BIT DEFAULT 0;
	
	DECLARE TEMP_RECORD_BINDED_ID BIGINT DEFAULT 0;
	DECLARE TEMP_RECORD_BINDED_SERVER_ID BIGINT DEFAULT 0;
	
	-- Authentication
	-- =========================================================================================
	DECLARE TEMP_ACCESS_RIGHTS_DENIED BIT DEFAULT 0;
	DECLARE TEMP_AUTHENTICATED_ACCOUNT_ID BIGINT DEFAULT `ACCOUNT_MEMBER@ACC_ACCOUNT_ID_FROM_LOGIN`(PARAM_REQUESTER_USERNAME, PARAM_REQUESTER_PASSWORD);
	DECLARE TEMP_AUTHENTICATED_ACCOUNT_LEVEL BIGINT DEFAULT 0;
	DECLARE TEMP_AUTHENTICATED_ACCOUNT_GROUP BIGINT DEFAULT 0;
	
	-- Local Parameters
	-- =========================================================================================
	DECLARE TEMP_NOW DATETIME(6) DEFAULT `SYSTEM_VAR@NOW`('', 1);
	DECLARE TEMP_RECORD_COUNT BIGINT DEFAULT 0;
	
	
	-- Check NULLs
	-- =========================================================================================
	DECLARE IS_NULL_SYS_BLOODTYPE_ID BIT DEFAULT `SYSTEM_VAR@IS_NULL@BIGINT`(PARAM_SYS_BLOODTYPE_ID, 1, 1);
	DECLARE IS_NULL_SYS_BLOODTYPE_CODE BIT DEFAULT `SYSTEM_VAR@IS_NULL@NVARCHAR`(PARAM_SYS_BLOODTYPE_CODE, 0);
	DECLARE IS_NULL_SYS_BLOODTYPE_DESCRIPTION BIT DEFAULT `SYSTEM_VAR@IS_NULL@NVARCHAR`(PARAM_SYS_BLOODTYPE_DESCRIPTION, 1);
	DECLARE IS_NULL_SYS_BLOODTYPE_STATUS BIT DEFAULT `SYSTEM_VAR@IS_NULL@TINYINT`(PARAM_SYS_BLOODTYPE_STATUS, 1, 1);
	
	-- Error Handler
	-- =========================================================================================
	DECLARE EXIT HANDLER FOR SQLEXCEPTION
	BEGIN
		RESIGNAL;
	END;
	
	-- Ignore Time from DateTime (Set Time 00:00:00.000000 and 23:59:59.999999)
	-- =========================================================================================
		
		
	-- Access Rights [Device]
	-- =========================================================================================

		
		
	-- Access Rights [Account]
	-- =========================================================================================
		
	
	
	
	-- COUNT RECORD
	-- =========================================================================================
	
	-- SELECT COLUMNS
	-- ####################################################
	SELECT
		COUNT(DISTINCT `system_blood_type`.`SYS_BLOODTYPE_ID`)
	INTO
		TEMP_RECORD_COUNT

	FROM `system_blood_type`
	
		-- Add Inner Joins (Per Foreign-key)
		
		-- Add Optional Left Joins (Per Optional Foreign-key)
		
	-- CONDITIONS
	-- ####################################################
	WHERE
		(
			IS_NULL_SYS_BLOODTYPE_ID = 1 OR
			`system_blood_type`.`SYS_BLOODTYPE_ID` = PARAM_SYS_BLOODTYPE_ID			
		) AND
		(
			IS_NULL_SYS_BLOODTYPE_CODE = 1 OR
			`system_blood_type`.`SYS_BLOODTYPE_CODE` LIKE CONCAT_WS('%', '', PARAM_SYS_BLOODTYPE_CODE, '')			
		) AND 		
		(
			IS_NULL_SYS_BLOODTYPE_DESCRIPTION = 1 OR
			`system_blood_type`.`SYS_BLOODTYPE_DESCRIPTION` LIKE CONCAT_WS('%', '', PARAM_SYS_BLOODTYPE_DESCRIPTION, '')			
		) AND 		
		(
			IS_NULL_SYS_BLOODTYPE_STATUS = 1 OR
			`system_blood_type`.`SYS_BLOODTYPE_STATUS` = PARAM_SYS_BLOODTYPE_STATUS			
		) 
;	

		
		
	-- SELECT RECORDS
	-- =========================================================================================
	
	-- FETCH COLUMNS
	-- ####################################################
	SELECT
		-- SYSTEM_BLOOD_TYPE DETAILS
		`system_blood_type`.`SYS_BLOODTYPE_ID`, 
		`system_blood_type`.`SYS_BLOODTYPE_CODE`, 
		`system_blood_type`.`SYS_BLOODTYPE_DESCRIPTION`, 
		`system_blood_type`.`SYS_BLOODTYPE_STATUS`
		
		-- Inner join fields
		
		-- Left join fields
		
		, TEMP_RECORD_COUNT AS RECORD_COUNT

	FROM `system_blood_type`
	
		-- Add Inner Joins (Per Foreign-key)
		
		-- Add Optional Left Joins (Per Optional Foreign-key)
		
	-- CONDITIONS
	-- ####################################################
	WHERE
		(
			IS_NULL_SYS_BLOODTYPE_ID = 1 OR
			`system_blood_type`.`SYS_BLOODTYPE_ID` = PARAM_SYS_BLOODTYPE_ID			
		) AND
		(
			IS_NULL_SYS_BLOODTYPE_CODE = 1 OR
			`system_blood_type`.`SYS_BLOODTYPE_CODE` LIKE CONCAT_WS('%', '', PARAM_SYS_BLOODTYPE_CODE, '')			
		) AND 		
		(
			IS_NULL_SYS_BLOODTYPE_DESCRIPTION = 1 OR
			`system_blood_type`.`SYS_BLOODTYPE_DESCRIPTION` LIKE CONCAT_WS('%', '', PARAM_SYS_BLOODTYPE_DESCRIPTION, '')			
		) AND 		
		(
			IS_NULL_SYS_BLOODTYPE_STATUS = 1 OR
			`system_blood_type`.`SYS_BLOODTYPE_STATUS` = PARAM_SYS_BLOODTYPE_STATUS			
		) 

	-- ORDER BY
	-- ####################################################
	ORDER BY
		-- SYSTEM_BLOOD_TYPE DETAILS
		CASE WHEN PARAM_ORDER_FIELD = 'SYS_BLOODTYPE_ID' AND PARAM_ORDER_TYPE = 'ASC' THEN `system_blood_type`.`SYS_BLOODTYPE_ID` END ASC, 
		CASE WHEN PARAM_ORDER_FIELD = 'SYS_BLOODTYPE_ID' AND PARAM_ORDER_TYPE = 'DESC' THEN `system_blood_type`.`SYS_BLOODTYPE_ID` END DESC,	
		CASE WHEN PARAM_ORDER_FIELD = 'SYS_BLOODTYPE_CODE' AND PARAM_ORDER_TYPE = 'ASC' THEN `system_blood_type`.`SYS_BLOODTYPE_CODE` END ASC, 
		CASE WHEN PARAM_ORDER_FIELD = 'SYS_BLOODTYPE_CODE' AND PARAM_ORDER_TYPE = 'DESC' THEN `system_blood_type`.`SYS_BLOODTYPE_CODE` END DESC,	
		CASE WHEN PARAM_ORDER_FIELD = 'SYS_BLOODTYPE_DESCRIPTION' AND PARAM_ORDER_TYPE = 'ASC' THEN `system_blood_type`.`SYS_BLOODTYPE_DESCRIPTION` END ASC, 
		CASE WHEN PARAM_ORDER_FIELD = 'SYS_BLOODTYPE_DESCRIPTION' AND PARAM_ORDER_TYPE = 'DESC' THEN `system_blood_type`.`SYS_BLOODTYPE_DESCRIPTION` END DESC,	
		CASE WHEN PARAM_ORDER_FIELD = 'SYS_BLOODTYPE_STATUS' AND PARAM_ORDER_TYPE = 'ASC' THEN `system_blood_type`.`SYS_BLOODTYPE_STATUS` END ASC, 
		CASE WHEN PARAM_ORDER_FIELD = 'SYS_BLOODTYPE_STATUS' AND PARAM_ORDER_TYPE = 'DESC' THEN `system_blood_type`.`SYS_BLOODTYPE_STATUS` END DESC,	

		-- Inner joins
		
		-- EXTRA
		CASE WHEN PARAM_ORDER_FIELD <> 'SYS_BLOODTYPE_DESCRIPTION' THEN `system_blood_type`.`SYS_BLOODTYPE_DESCRIPTION` END ASC
		
	-- LIMIT & OFFSET
	-- ####################################################		
	LIMIT PARAM_SKIP, PARAM_LIMIT;
	
	
	
	-- EXIT PROCEDURE
	-- =========================================================================================
	LEAVE SP_GET;
			
END ;;
DELIMITER ;
/*!50003 SET sql_mode              = @saved_sql_mode */ ;
/*!50003 SET character_set_client  = @saved_cs_client */ ;
/*!50003 SET character_set_results = @saved_cs_results */ ;
/*!50003 SET collation_connection  = @saved_col_connection */ ;
/*!50003 DROP PROCEDURE IF EXISTS `SYSTEM_CIVIL_STATUS_GET` */;
/*!50003 SET @saved_cs_client      = @@character_set_client */ ;
/*!50003 SET @saved_cs_results     = @@character_set_results */ ;
/*!50003 SET @saved_col_connection = @@collation_connection */ ;
/*!50003 SET character_set_client  = latin1 */ ;
/*!50003 SET character_set_results = latin1 */ ;
/*!50003 SET collation_connection  = latin1_swedish_ci */ ;
/*!50003 SET @saved_sql_mode       = @@sql_mode */ ;
/*!50003 SET sql_mode              = '' */ ;
DELIMITER ;;
CREATE DEFINER=`root`@`localhost` PROCEDURE `SYSTEM_CIVIL_STATUS_GET`(
	IN `PARAM_SYS_CIVIL_ID` BIGINT,	
	IN `PARAM_SYS_CIVIL_CODE` VARCHAR(50),	
	IN `PARAM_SYS_CIVIL_DESCRIPTION` VARCHAR(500),	
	IN `PARAM_SYS_CIVIL_STATUS` TINYINT,	
		
	IN `PARAM_ORDER_FIELD` VARCHAR(500),
	IN `PARAM_ORDER_TYPE` VARCHAR(500),
	IN `PARAM_SKIP` BIGINT,
	IN `PARAM_LIMIT` BIGINT,

	IN `PARAM_REQUESTER_USERNAME` VARCHAR(500),
	IN `PARAM_REQUESTER_PASSWORD` VARCHAR(500),
	IN `PARAM_REQUESTER_PROXY_ID` BIGINT,
	IN `PARAM_REQUESTER_PROXY_PASSWORD` VARCHAR(1000),
	IN `PARAM_REQUESTER_DEVICE_PUBLIC_KEY` VARCHAR(1000),
	IN `PARAM_REQUESTER_DEVICE_PRIVATE_KEY` VARCHAR(1000),
	
	IN `PARAM_REQUESTER_IP` VARCHAR(1000),
	IN `PARAM_UNIQUE_SESSION_ID` VARCHAR(1000),
	IN `PARAM_SUPPRESS_RETURN` BIT
)
SP_GET:
BEGIN

	-- Status
	-- =========================================================================================
	DECLARE STATUS_INACTIVE TINYINT DEFAULT 1;
	DECLARE STATUS_ACTIVE TINYINT DEFAULT 2;
	DECLARE STATUS_CLOSED TINYINT DEFAULT 3;
	DECLARE STATUS_COMPLETED TINYINT DEFAULT 4;
	
	-- Audit Handler
	-- =========================================================================================
	DECLARE TEMP_RECORD_EXISTS BIT DEFAULT 0;
	DECLARE TEMP_MODULE_KEYWORD VARCHAR(500) DEFAULT 'system_civil_status';
	DECLARE TEMP_SP_OBJECTIVE VARCHAR(500) DEFAULT 'Retrieve Civil Status record';
	DECLARE TEMP_ERR_MESSAGE VARCHAR(500) DEFAULT '';
	DECLARE ERR BIGINT DEFAULT 0;
	DECLARE TEMP_RECORD_CHANGES VARCHAR(16000) DEFAULT '';
	DECLARE TEMP_RECORD_BINDED BIT DEFAULT 0;
	
	DECLARE TEMP_RECORD_BINDED_ID BIGINT DEFAULT 0;
	DECLARE TEMP_RECORD_BINDED_SERVER_ID BIGINT DEFAULT 0;
	
	-- Authentication
	-- =========================================================================================
	DECLARE TEMP_ACCESS_RIGHTS_DENIED BIT DEFAULT 0;
	DECLARE TEMP_AUTHENTICATED_ACCOUNT_ID BIGINT DEFAULT `ACCOUNT_MEMBER@ACC_ACCOUNT_ID_FROM_LOGIN`(PARAM_REQUESTER_USERNAME, PARAM_REQUESTER_PASSWORD);
	DECLARE TEMP_AUTHENTICATED_ACCOUNT_LEVEL BIGINT DEFAULT 0;
	DECLARE TEMP_AUTHENTICATED_ACCOUNT_GROUP BIGINT DEFAULT 0;
	
	-- Local Parameters
	-- =========================================================================================
	DECLARE TEMP_NOW DATETIME(6) DEFAULT `SYSTEM_VAR@NOW`('', 1);
	DECLARE TEMP_RECORD_COUNT BIGINT DEFAULT 0;
	
	
	-- Check NULLs
	-- =========================================================================================
	DECLARE IS_NULL_SYS_CIVIL_ID BIT DEFAULT `SYSTEM_VAR@IS_NULL@BIGINT`(PARAM_SYS_CIVIL_ID, 1, 1);
	DECLARE IS_NULL_SYS_CIVIL_CODE BIT DEFAULT `SYSTEM_VAR@IS_NULL@NVARCHAR`(PARAM_SYS_CIVIL_CODE, 0);
	DECLARE IS_NULL_SYS_CIVIL_DESCRIPTION BIT DEFAULT `SYSTEM_VAR@IS_NULL@NVARCHAR`(PARAM_SYS_CIVIL_DESCRIPTION, 1);
	DECLARE IS_NULL_SYS_CIVIL_STATUS BIT DEFAULT `SYSTEM_VAR@IS_NULL@TINYINT`(PARAM_SYS_CIVIL_STATUS, 1, 1);
	
	-- Error Handler
	-- =========================================================================================
	DECLARE EXIT HANDLER FOR SQLEXCEPTION
	BEGIN
		RESIGNAL;
	END;
	
	-- Ignore Time from DateTime (Set Time 00:00:00.000000 and 23:59:59.999999)
	-- =========================================================================================
		
		
	-- Access Rights [Device]
	-- =========================================================================================

		
	-- Access Rights [Account]
	-- =========================================================================================	
	
	
	-- COUNT RECORD
	-- =========================================================================================
	
	-- SELECT COLUMNS
	-- ####################################################
	SELECT
		COUNT(DISTINCT `system_civil_status`.`SYS_CIVIL_ID`)
	INTO
		TEMP_RECORD_COUNT

	FROM `system_civil_status`
	
		-- Add Inner Joins (Per Foreign-key)
		
		-- Add Optional Left Joins (Per Optional Foreign-key)
		
	-- CONDITIONS
	-- ####################################################
	WHERE
		(
			IS_NULL_SYS_CIVIL_ID = 1 OR
			`system_civil_status`.`SYS_CIVIL_ID` = PARAM_SYS_CIVIL_ID			
		) AND
		(
			IS_NULL_SYS_CIVIL_CODE = 1 OR
			`system_civil_status`.`SYS_CIVIL_CODE` LIKE CONCAT_WS('%', '', PARAM_SYS_CIVIL_CODE, '')			
		) AND 		
		(
			IS_NULL_SYS_CIVIL_DESCRIPTION = 1 OR
			`system_civil_status`.`SYS_CIVIL_DESCRIPTION` LIKE CONCAT_WS('%', '', PARAM_SYS_CIVIL_DESCRIPTION, '')			
		) AND 		
		(
			IS_NULL_SYS_CIVIL_STATUS = 1 OR
			`system_civil_status`.`SYS_CIVIL_STATUS` = PARAM_SYS_CIVIL_STATUS			
		) 
;	

		
		
	-- SELECT RECORDS
	-- =========================================================================================
	
	-- FETCH COLUMNS
	-- ####################################################
	SELECT
		-- SYSTEM_CIVIL_STATUS DETAILS
		`system_civil_status`.`SYS_CIVIL_ID`, 
		`system_civil_status`.`SYS_CIVIL_CODE`, 
		`system_civil_status`.`SYS_CIVIL_DESCRIPTION`, 
		`system_civil_status`.`SYS_CIVIL_STATUS`
		
		-- Inner join fields
		
		-- Left join fields
		
		, TEMP_RECORD_COUNT AS RECORD_COUNT

	FROM `system_civil_status`
	
		-- Add Inner Joins (Per Foreign-key)
		
		-- Add Optional Left Joins (Per Optional Foreign-key)
		
	-- CONDITIONS
	-- ####################################################
	WHERE
		(
			IS_NULL_SYS_CIVIL_ID = 1 OR
			`system_civil_status`.`SYS_CIVIL_ID` = PARAM_SYS_CIVIL_ID			
		) AND
		(
			IS_NULL_SYS_CIVIL_CODE = 1 OR
			`system_civil_status`.`SYS_CIVIL_CODE` LIKE CONCAT_WS('%', '', PARAM_SYS_CIVIL_CODE, '')			
		) AND 		
		(
			IS_NULL_SYS_CIVIL_DESCRIPTION = 1 OR
			`system_civil_status`.`SYS_CIVIL_DESCRIPTION` LIKE CONCAT_WS('%', '', PARAM_SYS_CIVIL_DESCRIPTION, '')			
		) AND 		
		(
			IS_NULL_SYS_CIVIL_STATUS = 1 OR
			`system_civil_status`.`SYS_CIVIL_STATUS` = PARAM_SYS_CIVIL_STATUS			
		) 

	-- ORDER BY
	-- ####################################################
	ORDER BY
		-- SYSTEM_CIVIL_STATUS DETAILS
		CASE WHEN PARAM_ORDER_FIELD = 'SYS_CIVIL_ID' AND PARAM_ORDER_TYPE = 'ASC' THEN `system_civil_status`.`SYS_CIVIL_ID` END ASC, 
		CASE WHEN PARAM_ORDER_FIELD = 'SYS_CIVIL_ID' AND PARAM_ORDER_TYPE = 'DESC' THEN `system_civil_status`.`SYS_CIVIL_ID` END DESC,	
		CASE WHEN PARAM_ORDER_FIELD = 'SYS_CIVIL_CODE' AND PARAM_ORDER_TYPE = 'ASC' THEN `system_civil_status`.`SYS_CIVIL_CODE` END ASC, 
		CASE WHEN PARAM_ORDER_FIELD = 'SYS_CIVIL_CODE' AND PARAM_ORDER_TYPE = 'DESC' THEN `system_civil_status`.`SYS_CIVIL_CODE` END DESC,	
		CASE WHEN PARAM_ORDER_FIELD = 'SYS_CIVIL_DESCRIPTION' AND PARAM_ORDER_TYPE = 'ASC' THEN `system_civil_status`.`SYS_CIVIL_DESCRIPTION` END ASC, 
		CASE WHEN PARAM_ORDER_FIELD = 'SYS_CIVIL_DESCRIPTION' AND PARAM_ORDER_TYPE = 'DESC' THEN `system_civil_status`.`SYS_CIVIL_DESCRIPTION` END DESC,	
		CASE WHEN PARAM_ORDER_FIELD = 'SYS_CIVIL_STATUS' AND PARAM_ORDER_TYPE = 'ASC' THEN `system_civil_status`.`SYS_CIVIL_STATUS` END ASC, 
		CASE WHEN PARAM_ORDER_FIELD = 'SYS_CIVIL_STATUS' AND PARAM_ORDER_TYPE = 'DESC' THEN `system_civil_status`.`SYS_CIVIL_STATUS` END DESC,	

		-- Inner joins
		
		-- EXTRA
		CASE WHEN PARAM_ORDER_FIELD <> 'SYS_CIVIL_DESCRIPTION' THEN `system_civil_status`.`SYS_CIVIL_DESCRIPTION` END ASC
		
	-- LIMIT & OFFSET
	-- ####################################################		
	LIMIT PARAM_SKIP, PARAM_LIMIT;
	
	
	
	-- EXIT PROCEDURE
	-- =========================================================================================
	LEAVE SP_GET;
			
END ;;
DELIMITER ;
/*!50003 SET sql_mode              = @saved_sql_mode */ ;
/*!50003 SET character_set_client  = @saved_cs_client */ ;
/*!50003 SET character_set_results = @saved_cs_results */ ;
/*!50003 SET collation_connection  = @saved_col_connection */ ;
/*!50003 DROP PROCEDURE IF EXISTS `SYSTEM_EMPLOYMENT_STATUS_GET` */;
/*!50003 SET @saved_cs_client      = @@character_set_client */ ;
/*!50003 SET @saved_cs_results     = @@character_set_results */ ;
/*!50003 SET @saved_col_connection = @@collation_connection */ ;
/*!50003 SET character_set_client  = latin1 */ ;
/*!50003 SET character_set_results = latin1 */ ;
/*!50003 SET collation_connection  = latin1_swedish_ci */ ;
/*!50003 SET @saved_sql_mode       = @@sql_mode */ ;
/*!50003 SET sql_mode              = '' */ ;
DELIMITER ;;
CREATE DEFINER=`root`@`localhost` PROCEDURE `SYSTEM_EMPLOYMENT_STATUS_GET`(
	IN `PARAM_SYS_EMPLOYSTATUS_ID` BIGINT,	
	IN `PARAM_SYS_EMPLOYSTATUS_CODE` VARCHAR(50),	
	IN `PARAM_SYS_EMPLOYSTATUS_DESCRIPTION` VARCHAR(500),	
	IN `PARAM_SYS_EMPLOYSTATUS_REMARKS` VARCHAR(4000),	
	IN `PARAM_SYS_EMPLOYSTATUS_STATUS` TINYINT,	
		
	IN `PARAM_ORDER_FIELD` VARCHAR(500),
	IN `PARAM_ORDER_TYPE` VARCHAR(500),
	IN `PARAM_SKIP` BIGINT,
	IN `PARAM_LIMIT` BIGINT,

	IN `PARAM_REQUESTER_USERNAME` VARCHAR(500),
	IN `PARAM_REQUESTER_PASSWORD` VARCHAR(500),
	IN `PARAM_REQUESTER_PROXY_ID` BIGINT,
	IN `PARAM_REQUESTER_PROXY_PASSWORD` VARCHAR(1000),
	IN `PARAM_REQUESTER_DEVICE_PUBLIC_KEY` VARCHAR(1000),
	IN `PARAM_REQUESTER_DEVICE_PRIVATE_KEY` VARCHAR(1000),
	
	IN `PARAM_REQUESTER_IP` VARCHAR(1000),
	IN `PARAM_UNIQUE_SESSION_ID` VARCHAR(1000),
	IN `PARAM_SUPPRESS_RETURN` BIT
)
SP_GET:
BEGIN

	-- Status
	-- =========================================================================================
	DECLARE STATUS_INACTIVE TINYINT DEFAULT 1;
	DECLARE STATUS_ACTIVE TINYINT DEFAULT 2;
	DECLARE STATUS_CLOSED TINYINT DEFAULT 3;
	DECLARE STATUS_COMPLETED TINYINT DEFAULT 4;
	
	-- Audit Handler
	-- =========================================================================================
	DECLARE TEMP_RECORD_EXISTS BIT DEFAULT 0;
	DECLARE TEMP_MODULE_KEYWORD VARCHAR(500) DEFAULT 'system_employment_status';
	DECLARE TEMP_SP_OBJECTIVE VARCHAR(500) DEFAULT 'Retrieve Employement Status record';
	DECLARE TEMP_ERR_MESSAGE VARCHAR(500) DEFAULT '';
	DECLARE ERR BIGINT DEFAULT 0;
	DECLARE TEMP_RECORD_CHANGES VARCHAR(16000) DEFAULT '';
	DECLARE TEMP_RECORD_BINDED BIT DEFAULT 0;
	
	DECLARE TEMP_RECORD_BINDED_ID BIGINT DEFAULT 0;
	DECLARE TEMP_RECORD_BINDED_SERVER_ID BIGINT DEFAULT 0;
	
	-- Authentication
	-- =========================================================================================
	DECLARE TEMP_ACCESS_RIGHTS_DENIED BIT DEFAULT 0;
	DECLARE TEMP_AUTHENTICATED_ACCOUNT_ID BIGINT DEFAULT `ACCOUNT_MEMBER@ACC_ACCOUNT_ID_FROM_LOGIN`(PARAM_REQUESTER_USERNAME, PARAM_REQUESTER_PASSWORD);
	DECLARE TEMP_AUTHENTICATED_ACCOUNT_LEVEL BIGINT DEFAULT 0;
	DECLARE TEMP_AUTHENTICATED_ACCOUNT_GROUP BIGINT DEFAULT 0;
	
	-- Local Parameters
	-- =========================================================================================
	DECLARE TEMP_NOW DATETIME(6) DEFAULT `SYSTEM_VAR@NOW`('', 1);
	DECLARE TEMP_RECORD_COUNT BIGINT DEFAULT 0;
	
	
	-- Check NULLs
	-- =========================================================================================
	DECLARE IS_NULL_SYS_EMPLOYSTATUS_ID BIT DEFAULT `SYSTEM_VAR@IS_NULL@BIGINT`(PARAM_SYS_EMPLOYSTATUS_ID, 1, 1);
	DECLARE IS_NULL_SYS_EMPLOYSTATUS_CODE BIT DEFAULT `SYSTEM_VAR@IS_NULL@NVARCHAR`(PARAM_SYS_EMPLOYSTATUS_CODE, 0);
	DECLARE IS_NULL_SYS_EMPLOYSTATUS_DESCRIPTION BIT DEFAULT `SYSTEM_VAR@IS_NULL@NVARCHAR`(PARAM_SYS_EMPLOYSTATUS_DESCRIPTION, 1);
	DECLARE IS_NULL_SYS_EMPLOYSTATUS_REMARKS BIT DEFAULT `SYSTEM_VAR@IS_NULL@NVARCHAR`(PARAM_SYS_EMPLOYSTATUS_REMARKS, 0);
	DECLARE IS_NULL_SYS_EMPLOYSTATUS_STATUS BIT DEFAULT `SYSTEM_VAR@IS_NULL@TINYINT`(PARAM_SYS_EMPLOYSTATUS_STATUS, 1, 1);
	
	-- Error Handler
	-- =========================================================================================
	DECLARE EXIT HANDLER FOR SQLEXCEPTION
	BEGIN
		RESIGNAL;
	END;
	
	-- Ignore Time from DateTime (Set Time 00:00:00.000000 and 23:59:59.999999)
	-- =========================================================================================
		
		
	-- Access Rights [Device]
	-- =========================================================================================
	IF `ACCOUNT_DEVICE@HAS_PERMISSION`(PARAM_REQUESTER_DEVICE_PUBLIC_KEY, PARAM_REQUESTER_DEVICE_PRIVATE_KEY) = 0 THEN
		SET TEMP_ERR_MESSAGE = 'Your device is not authorized yet to access this server.';
		SET ERR = `RAISERROR`(TEMP_ERR_MESSAGE);		
	END IF;
		
		
	-- Access Rights [Account]
	-- =========================================================================================
		
	
	
	
	-- COUNT RECORD
	-- =========================================================================================
	
	-- SELECT COLUMNS
	-- ####################################################
	SELECT
		COUNT(DISTINCT `system_employment_status`.`SYS_EMPLOYSTATUS_ID`)
	INTO
		TEMP_RECORD_COUNT

	FROM `system_employment_status`
	
		-- Add Inner Joins (Per Foreign-key)
		
		-- Add Optional Left Joins (Per Optional Foreign-key)
		
	-- CONDITIONS
	-- ####################################################
	WHERE
		(
			IS_NULL_SYS_EMPLOYSTATUS_ID = 1 OR
			`system_employment_status`.`SYS_EMPLOYSTATUS_ID` = PARAM_SYS_EMPLOYSTATUS_ID			
		) AND
		(
			IS_NULL_SYS_EMPLOYSTATUS_CODE = 1 OR
			`system_employment_status`.`SYS_EMPLOYSTATUS_CODE` LIKE CONCAT_WS('%', '', PARAM_SYS_EMPLOYSTATUS_CODE, '')			
		) AND 		
		(
			IS_NULL_SYS_EMPLOYSTATUS_DESCRIPTION = 1 OR
			`system_employment_status`.`SYS_EMPLOYSTATUS_DESCRIPTION` LIKE CONCAT_WS('%', '', PARAM_SYS_EMPLOYSTATUS_DESCRIPTION, '')			
		) AND 		
		(
			IS_NULL_SYS_EMPLOYSTATUS_REMARKS = 1 OR
			`system_employment_status`.`SYS_EMPLOYSTATUS_REMARKS` LIKE CONCAT_WS('%', '', PARAM_SYS_EMPLOYSTATUS_REMARKS, '')			
		) AND 		
		(
			IS_NULL_SYS_EMPLOYSTATUS_STATUS = 1 OR
			`system_employment_status`.`SYS_EMPLOYSTATUS_STATUS` = PARAM_SYS_EMPLOYSTATUS_STATUS			
		) 
;	

		
		
	-- SELECT RECORDS
	-- =========================================================================================
	
	-- FETCH COLUMNS
	-- ####################################################
	SELECT
		-- SYSTEM_EMPLOYMENT_STATUS DETAILS
		`system_employment_status`.`SYS_EMPLOYSTATUS_ID`, 
		`system_employment_status`.`SYS_EMPLOYSTATUS_CODE`, 
		`system_employment_status`.`SYS_EMPLOYSTATUS_DESCRIPTION`, 
		`system_employment_status`.`SYS_EMPLOYSTATUS_REMARKS`, 
		`system_employment_status`.`SYS_EMPLOYSTATUS_STATUS`
		
		-- Inner join fields
		
		-- Left join fields
		
		, TEMP_RECORD_COUNT AS RECORD_COUNT

	FROM `system_employment_status`
	
		-- Add Inner Joins (Per Foreign-key)
		
		-- Add Optional Left Joins (Per Optional Foreign-key)
		
	-- CONDITIONS
	-- ####################################################
	WHERE
		(
			IS_NULL_SYS_EMPLOYSTATUS_ID = 1 OR
			`system_employment_status`.`SYS_EMPLOYSTATUS_ID` = PARAM_SYS_EMPLOYSTATUS_ID			
		) AND
		(
			IS_NULL_SYS_EMPLOYSTATUS_CODE = 1 OR
			`system_employment_status`.`SYS_EMPLOYSTATUS_CODE` LIKE CONCAT_WS('%', '', PARAM_SYS_EMPLOYSTATUS_CODE, '')			
		) AND 		
		(
			IS_NULL_SYS_EMPLOYSTATUS_DESCRIPTION = 1 OR
			`system_employment_status`.`SYS_EMPLOYSTATUS_DESCRIPTION` LIKE CONCAT_WS('%', '', PARAM_SYS_EMPLOYSTATUS_DESCRIPTION, '')			
		) AND 		
		(
			IS_NULL_SYS_EMPLOYSTATUS_REMARKS = 1 OR
			`system_employment_status`.`SYS_EMPLOYSTATUS_REMARKS` LIKE CONCAT_WS('%', '', PARAM_SYS_EMPLOYSTATUS_REMARKS, '')			
		) AND 		
		(
			IS_NULL_SYS_EMPLOYSTATUS_STATUS = 1 OR
			`system_employment_status`.`SYS_EMPLOYSTATUS_STATUS` = PARAM_SYS_EMPLOYSTATUS_STATUS			
		) 

	-- ORDER BY
	-- ####################################################
	ORDER BY
		-- SYSTEM_EMPLOYMENT_STATUS DETAILS
		CASE WHEN PARAM_ORDER_FIELD = 'SYS_EMPLOYSTATUS_ID' AND PARAM_ORDER_TYPE = 'ASC' THEN `system_employment_status`.`SYS_EMPLOYSTATUS_ID` END ASC, 
		CASE WHEN PARAM_ORDER_FIELD = 'SYS_EMPLOYSTATUS_ID' AND PARAM_ORDER_TYPE = 'DESC' THEN `system_employment_status`.`SYS_EMPLOYSTATUS_ID` END DESC,	
		CASE WHEN PARAM_ORDER_FIELD = 'SYS_EMPLOYSTATUS_CODE' AND PARAM_ORDER_TYPE = 'ASC' THEN `system_employment_status`.`SYS_EMPLOYSTATUS_CODE` END ASC, 
		CASE WHEN PARAM_ORDER_FIELD = 'SYS_EMPLOYSTATUS_CODE' AND PARAM_ORDER_TYPE = 'DESC' THEN `system_employment_status`.`SYS_EMPLOYSTATUS_CODE` END DESC,	
		CASE WHEN PARAM_ORDER_FIELD = 'SYS_EMPLOYSTATUS_DESCRIPTION' AND PARAM_ORDER_TYPE = 'ASC' THEN `system_employment_status`.`SYS_EMPLOYSTATUS_DESCRIPTION` END ASC, 
		CASE WHEN PARAM_ORDER_FIELD = 'SYS_EMPLOYSTATUS_DESCRIPTION' AND PARAM_ORDER_TYPE = 'DESC' THEN `system_employment_status`.`SYS_EMPLOYSTATUS_DESCRIPTION` END DESC,	
		CASE WHEN PARAM_ORDER_FIELD = 'SYS_EMPLOYSTATUS_REMARKS' AND PARAM_ORDER_TYPE = 'ASC' THEN `system_employment_status`.`SYS_EMPLOYSTATUS_REMARKS` END ASC, 
		CASE WHEN PARAM_ORDER_FIELD = 'SYS_EMPLOYSTATUS_REMARKS' AND PARAM_ORDER_TYPE = 'DESC' THEN `system_employment_status`.`SYS_EMPLOYSTATUS_REMARKS` END DESC,	
		CASE WHEN PARAM_ORDER_FIELD = 'SYS_EMPLOYSTATUS_STATUS' AND PARAM_ORDER_TYPE = 'ASC' THEN `system_employment_status`.`SYS_EMPLOYSTATUS_STATUS` END ASC, 
		CASE WHEN PARAM_ORDER_FIELD = 'SYS_EMPLOYSTATUS_STATUS' AND PARAM_ORDER_TYPE = 'DESC' THEN `system_employment_status`.`SYS_EMPLOYSTATUS_STATUS` END DESC,	

		-- Inner joins
		
		-- EXTRA
		CASE WHEN PARAM_ORDER_FIELD <> 'SYS_EMPLOYSTATUS_DESCRIPTION' THEN `system_employment_status`.`SYS_EMPLOYSTATUS_DESCRIPTION` END ASC
		
	-- LIMIT & OFFSET
	-- ####################################################		
	LIMIT PARAM_SKIP, PARAM_LIMIT;
	
	
	
	-- EXIT PROCEDURE
	-- =========================================================================================
	LEAVE SP_GET;
			
END ;;
DELIMITER ;
/*!50003 SET sql_mode              = @saved_sql_mode */ ;
/*!50003 SET character_set_client  = @saved_cs_client */ ;
/*!50003 SET character_set_results = @saved_cs_results */ ;
/*!50003 SET collation_connection  = @saved_col_connection */ ;
/*!50003 DROP PROCEDURE IF EXISTS `SYSTEM_GENDER_GET` */;
/*!50003 SET @saved_cs_client      = @@character_set_client */ ;
/*!50003 SET @saved_cs_results     = @@character_set_results */ ;
/*!50003 SET @saved_col_connection = @@collation_connection */ ;
/*!50003 SET character_set_client  = latin1 */ ;
/*!50003 SET character_set_results = latin1 */ ;
/*!50003 SET collation_connection  = latin1_swedish_ci */ ;
/*!50003 SET @saved_sql_mode       = @@sql_mode */ ;
/*!50003 SET sql_mode              = '' */ ;
DELIMITER ;;
CREATE DEFINER=`root`@`localhost` PROCEDURE `SYSTEM_GENDER_GET`(
	IN `PARAM_SYS_GENDER_ID` BIGINT,	
	IN `PARAM_SYS_GENDER_CODE` VARCHAR(50),	
	IN `PARAM_SYS_GENDER_DESCRIPTION` VARCHAR(500),	
	IN `PARAM_SYS_GENDER_STATUS` TINYINT,	
		
	IN `PARAM_ORDER_FIELD` VARCHAR(500),
	IN `PARAM_ORDER_TYPE` VARCHAR(500),
	IN `PARAM_SKIP` BIGINT,
	IN `PARAM_LIMIT` BIGINT,

	IN `PARAM_REQUESTER_USERNAME` VARCHAR(500),
	IN `PARAM_REQUESTER_PASSWORD` VARCHAR(500),
	IN `PARAM_REQUESTER_PROXY_ID` BIGINT,
	IN `PARAM_REQUESTER_PROXY_PASSWORD` VARCHAR(1000),
	IN `PARAM_REQUESTER_DEVICE_PUBLIC_KEY` VARCHAR(1000),
	IN `PARAM_REQUESTER_DEVICE_PRIVATE_KEY` VARCHAR(1000),
	
	IN `PARAM_REQUESTER_IP` VARCHAR(1000),
	IN `PARAM_UNIQUE_SESSION_ID` VARCHAR(1000),
	IN `PARAM_SUPPRESS_RETURN` BIT
)
SP_GET:
BEGIN

	-- Status
	-- =========================================================================================
	DECLARE STATUS_INACTIVE TINYINT DEFAULT 1;
	DECLARE STATUS_ACTIVE TINYINT DEFAULT 2;
	DECLARE STATUS_CLOSED TINYINT DEFAULT 3;
	DECLARE STATUS_COMPLETED TINYINT DEFAULT 4;
	
	-- Audit Handler
	-- =========================================================================================
	DECLARE TEMP_RECORD_EXISTS BIT DEFAULT 0;
	DECLARE TEMP_MODULE_KEYWORD VARCHAR(500) DEFAULT 'system_gender';
	DECLARE TEMP_SP_OBJECTIVE VARCHAR(500) DEFAULT 'Retrieve Gender record';
	DECLARE TEMP_ERR_MESSAGE VARCHAR(500) DEFAULT '';
	DECLARE ERR BIGINT DEFAULT 0;
	DECLARE TEMP_RECORD_CHANGES VARCHAR(16000) DEFAULT '';
	DECLARE TEMP_RECORD_BINDED BIT DEFAULT 0;
	
	DECLARE TEMP_RECORD_BINDED_ID BIGINT DEFAULT 0;
	DECLARE TEMP_RECORD_BINDED_SERVER_ID BIGINT DEFAULT 0;
	
	-- Authentication
	-- =========================================================================================
	DECLARE TEMP_ACCESS_RIGHTS_DENIED BIT DEFAULT 0;
	DECLARE TEMP_AUTHENTICATED_ACCOUNT_ID BIGINT DEFAULT `ACCOUNT_MEMBER@ACC_ACCOUNT_ID_FROM_LOGIN`(PARAM_REQUESTER_USERNAME, PARAM_REQUESTER_PASSWORD);
	DECLARE TEMP_AUTHENTICATED_ACCOUNT_LEVEL BIGINT DEFAULT 0;
	DECLARE TEMP_AUTHENTICATED_ACCOUNT_GROUP BIGINT DEFAULT 0;
	
	-- Local Parameters
	-- =========================================================================================
	DECLARE TEMP_NOW DATETIME(6) DEFAULT `SYSTEM_VAR@NOW`('', 1);
	DECLARE TEMP_RECORD_COUNT BIGINT DEFAULT 0;
	
	
	-- Check NULLs
	-- =========================================================================================
	DECLARE IS_NULL_SYS_GENDER_ID BIT DEFAULT `SYSTEM_VAR@IS_NULL@BIGINT`(PARAM_SYS_GENDER_ID, 1, 1);
	DECLARE IS_NULL_SYS_GENDER_CODE BIT DEFAULT `SYSTEM_VAR@IS_NULL@NVARCHAR`(PARAM_SYS_GENDER_CODE, 0);
	DECLARE IS_NULL_SYS_GENDER_DESCRIPTION BIT DEFAULT `SYSTEM_VAR@IS_NULL@NVARCHAR`(PARAM_SYS_GENDER_DESCRIPTION, 1);
	DECLARE IS_NULL_SYS_GENDER_STATUS BIT DEFAULT `SYSTEM_VAR@IS_NULL@TINYINT`(PARAM_SYS_GENDER_STATUS, 1, 1);
	
	-- Error Handler
	-- =========================================================================================
	DECLARE EXIT HANDLER FOR SQLEXCEPTION
	BEGIN
		RESIGNAL;
	END;
	
	-- Ignore Time from DateTime (Set Time 00:00:00.000000 and 23:59:59.999999)
	-- =========================================================================================
		
		
	-- Access Rights [Device]
	-- =========================================================================================

		
		
	-- Access Rights [Account]
	-- =========================================================================================
		
	
	
	
	-- COUNT RECORD
	-- =========================================================================================
	
	-- SELECT COLUMNS
	-- ####################################################
	SELECT
		COUNT(DISTINCT `system_gender`.`SYS_GENDER_ID`)
	INTO
		TEMP_RECORD_COUNT

	FROM `system_gender`
	
		-- Add Inner Joins (Per Foreign-key)
		
		-- Add Optional Left Joins (Per Optional Foreign-key)
		
	-- CONDITIONS
	-- ####################################################
	WHERE
		(
			IS_NULL_SYS_GENDER_ID = 1 OR
			`system_gender`.`SYS_GENDER_ID` = PARAM_SYS_GENDER_ID			
		) AND
		(
			IS_NULL_SYS_GENDER_CODE = 1 OR
			`system_gender`.`SYS_GENDER_CODE` LIKE CONCAT_WS('%', '', PARAM_SYS_GENDER_CODE, '')			
		) AND 		
		(
			IS_NULL_SYS_GENDER_DESCRIPTION = 1 OR
			`system_gender`.`SYS_GENDER_DESCRIPTION` LIKE CONCAT_WS('%', '', PARAM_SYS_GENDER_DESCRIPTION, '')			
		) AND 		
		(
			IS_NULL_SYS_GENDER_STATUS = 1 OR
			`system_gender`.`SYS_GENDER_STATUS` = PARAM_SYS_GENDER_STATUS			
		) 
;	

		
		
	-- SELECT RECORDS
	-- =========================================================================================
	
	-- FETCH COLUMNS
	-- ####################################################
	SELECT
		-- SYSTEM_GENDER DETAILS
		`system_gender`.`SYS_GENDER_ID`, 
		`system_gender`.`SYS_GENDER_CODE`, 
		`system_gender`.`SYS_GENDER_DESCRIPTION`, 
		`system_gender`.`SYS_GENDER_STATUS`
		
		-- Inner join fields
		
		-- Left join fields
		
		, TEMP_RECORD_COUNT AS RECORD_COUNT

	FROM `system_gender`
	
		-- Add Inner Joins (Per Foreign-key)
		
		-- Add Optional Left Joins (Per Optional Foreign-key)
		
	-- CONDITIONS
	-- ####################################################
	WHERE
		(
			IS_NULL_SYS_GENDER_ID = 1 OR
			`system_gender`.`SYS_GENDER_ID` = PARAM_SYS_GENDER_ID			
		) AND
		(
			IS_NULL_SYS_GENDER_CODE = 1 OR
			`system_gender`.`SYS_GENDER_CODE` LIKE CONCAT_WS('%', '', PARAM_SYS_GENDER_CODE, '')			
		) AND 		
		(
			IS_NULL_SYS_GENDER_DESCRIPTION = 1 OR
			`system_gender`.`SYS_GENDER_DESCRIPTION` LIKE CONCAT_WS('%', '', PARAM_SYS_GENDER_DESCRIPTION, '')			
		) AND 		
		(
			IS_NULL_SYS_GENDER_STATUS = 1 OR
			`system_gender`.`SYS_GENDER_STATUS` = PARAM_SYS_GENDER_STATUS			
		) 

	-- ORDER BY
	-- ####################################################
	ORDER BY
		-- SYSTEM_GENDER DETAILS
		CASE WHEN PARAM_ORDER_FIELD = 'SYS_GENDER_ID' AND PARAM_ORDER_TYPE = 'ASC' THEN `system_gender`.`SYS_GENDER_ID` END ASC, 
		CASE WHEN PARAM_ORDER_FIELD = 'SYS_GENDER_ID' AND PARAM_ORDER_TYPE = 'DESC' THEN `system_gender`.`SYS_GENDER_ID` END DESC,	
		CASE WHEN PARAM_ORDER_FIELD = 'SYS_GENDER_CODE' AND PARAM_ORDER_TYPE = 'ASC' THEN `system_gender`.`SYS_GENDER_CODE` END ASC, 
		CASE WHEN PARAM_ORDER_FIELD = 'SYS_GENDER_CODE' AND PARAM_ORDER_TYPE = 'DESC' THEN `system_gender`.`SYS_GENDER_CODE` END DESC,	
		CASE WHEN PARAM_ORDER_FIELD = 'SYS_GENDER_DESCRIPTION' AND PARAM_ORDER_TYPE = 'ASC' THEN `system_gender`.`SYS_GENDER_DESCRIPTION` END ASC, 
		CASE WHEN PARAM_ORDER_FIELD = 'SYS_GENDER_DESCRIPTION' AND PARAM_ORDER_TYPE = 'DESC' THEN `system_gender`.`SYS_GENDER_DESCRIPTION` END DESC,	
		CASE WHEN PARAM_ORDER_FIELD = 'SYS_GENDER_STATUS' AND PARAM_ORDER_TYPE = 'ASC' THEN `system_gender`.`SYS_GENDER_STATUS` END ASC, 
		CASE WHEN PARAM_ORDER_FIELD = 'SYS_GENDER_STATUS' AND PARAM_ORDER_TYPE = 'DESC' THEN `system_gender`.`SYS_GENDER_STATUS` END DESC,	

		-- Inner joins
		
		-- EXTRA
		CASE WHEN PARAM_ORDER_FIELD <> 'SYS_GENDER_DESCRIPTION' THEN `system_gender`.`SYS_GENDER_DESCRIPTION` END ASC
		
	-- LIMIT & OFFSET
	-- ####################################################		
	LIMIT PARAM_SKIP, PARAM_LIMIT;
	
	
	
	-- EXIT PROCEDURE
	-- =========================================================================================
	LEAVE SP_GET;
			
END ;;
DELIMITER ;
/*!50003 SET sql_mode              = @saved_sql_mode */ ;
/*!50003 SET character_set_client  = @saved_cs_client */ ;
/*!50003 SET character_set_results = @saved_cs_results */ ;
/*!50003 SET collation_connection  = @saved_col_connection */ ;
/*!50003 DROP PROCEDURE IF EXISTS `SYSTEM_MODULE_GET` */;
/*!50003 SET @saved_cs_client      = @@character_set_client */ ;
/*!50003 SET @saved_cs_results     = @@character_set_results */ ;
/*!50003 SET @saved_col_connection = @@collation_connection */ ;
/*!50003 SET character_set_client  = latin1 */ ;
/*!50003 SET character_set_results = latin1 */ ;
/*!50003 SET collation_connection  = latin1_swedish_ci */ ;
/*!50003 SET @saved_sql_mode       = @@sql_mode */ ;
/*!50003 SET sql_mode              = '' */ ;
DELIMITER ;;
CREATE DEFINER=`root`@`localhost` PROCEDURE `SYSTEM_MODULE_GET`(
	IN `PARAM_SYS_MODULE_ID` BIGINT,	
	IN `PARAM_SYS_MODULE_CATEGORY` VARCHAR(50),	
	IN `PARAM_SYS_MODULE_KEYWORD` VARCHAR(500),	
	IN `PARAM_SYS_MODULE_NAME` VARCHAR(500),	
	IN `PARAM_SYS_MODULE_DESCRIPTION` VARCHAR(4000),	
	IN `PARAM_SYS_MODULE_SHOW_ACCESS_RIGHTS` TINYINT,	
	IN `PARAM_SYS_MODULE_STATUS` TINYINT,	
	IN `PARAM_SYS_MODULE_SYNC_SAVE_UP_TIMESTAMP_FROM` DATETIME(6),
	IN `PARAM_SYS_MODULE_SYNC_SAVE_UP_TIMESTAMP_TO` DATETIME(6),
	IN `PARAM_SYS_MODULE_SYNC_SAVE_DL_TIMESTAMP_FROM` DATETIME(6),
	IN `PARAM_SYS_MODULE_SYNC_SAVE_DL_TIMESTAMP_TO` DATETIME(6),
	IN `PARAM_SYS_MODULE_SYNC_DELETE_UP_TIMESTAMP_FROM` DATETIME(6),
	IN `PARAM_SYS_MODULE_SYNC_DELETE_UP_TIMESTAMP_TO` DATETIME(6),
	IN `PARAM_SYS_MODULE_SYNC_DELETE_DL_TIMESTAMP_FROM` DATETIME(6),
	IN `PARAM_SYS_MODULE_SYNC_DELETE_DL_TIMESTAMP_TO` DATETIME(6),
		
	IN `PARAM_ORDER_FIELD` VARCHAR(500),
	IN `PARAM_ORDER_TYPE` VARCHAR(500),
	IN `PARAM_SKIP` BIGINT,
	IN `PARAM_LIMIT` BIGINT,

	IN `PARAM_REQUESTER_USERNAME` VARCHAR(500),
	IN `PARAM_REQUESTER_PASSWORD` VARCHAR(500),
	IN `PARAM_REQUESTER_PROXY_ID` BIGINT,
	IN `PARAM_REQUESTER_PROXY_PASSWORD` VARCHAR(1000),
	IN `PARAM_REQUESTER_DEVICE_PUBLIC_KEY` VARCHAR(1000),
	IN `PARAM_REQUESTER_DEVICE_PRIVATE_KEY` VARCHAR(1000),
	
	IN `PARAM_REQUESTER_IP` VARCHAR(1000),
	IN `PARAM_UNIQUE_SESSION_ID` VARCHAR(1000),
	IN `PARAM_SUPPRESS_RETURN` BIT
)
SP_GET:
BEGIN

	-- Status
	-- =========================================================================================
	DECLARE STATUS_INACTIVE TINYINT DEFAULT 1;
	DECLARE STATUS_ACTIVE TINYINT DEFAULT 2;
	DECLARE STATUS_CLOSED TINYINT DEFAULT 3;
	DECLARE STATUS_COMPLETED TINYINT DEFAULT 4;
	
	-- Audit Handler
	-- =========================================================================================
	DECLARE TEMP_RECORD_EXISTS BIT DEFAULT 0;
	DECLARE TEMP_MODULE_KEYWORD VARCHAR(500) DEFAULT 'system_module';
	DECLARE TEMP_SP_OBJECTIVE VARCHAR(500) DEFAULT 'Retrieve Modules record';
	DECLARE TEMP_ERR_MESSAGE VARCHAR(500) DEFAULT '';
	DECLARE ERR BIGINT DEFAULT 0;
	DECLARE TEMP_RECORD_CHANGES VARCHAR(16000) DEFAULT '';
	DECLARE TEMP_RECORD_BINDED BIT DEFAULT 0;
	
	DECLARE TEMP_RECORD_BINDED_ID BIGINT DEFAULT 0;
	DECLARE TEMP_RECORD_BINDED_SERVER_ID BIGINT DEFAULT 0;
	
	-- Authentication
	-- =========================================================================================
	DECLARE TEMP_ACCESS_RIGHTS_DENIED BIT DEFAULT 0;
	DECLARE TEMP_AUTHENTICATED_ACCOUNT_ID BIGINT DEFAULT `ACCOUNT_MEMBER@ACC_ACCOUNT_ID_FROM_LOGIN`(PARAM_REQUESTER_USERNAME, PARAM_REQUESTER_PASSWORD);
	DECLARE TEMP_AUTHENTICATED_ACCOUNT_LEVEL BIGINT DEFAULT 0;
	DECLARE TEMP_AUTHENTICATED_ACCOUNT_GROUP BIGINT DEFAULT 0;
	
	-- Local Parameters
	-- =========================================================================================
	DECLARE TEMP_NOW DATETIME(6) DEFAULT `SYSTEM_VAR@NOW`('', 1);
	DECLARE TEMP_RECORD_COUNT BIGINT DEFAULT 0;
	
	
	-- Check NULLs
	-- =========================================================================================
	DECLARE IS_NULL_SYS_MODULE_ID BIT DEFAULT `SYSTEM_VAR@IS_NULL@BIGINT`(PARAM_SYS_MODULE_ID, 1, 1);
	DECLARE IS_NULL_SYS_MODULE_CATEGORY BIT DEFAULT `SYSTEM_VAR@IS_NULL@NVARCHAR`(PARAM_SYS_MODULE_CATEGORY, 1);
	DECLARE IS_NULL_SYS_MODULE_KEYWORD BIT DEFAULT `SYSTEM_VAR@IS_NULL@NVARCHAR`(PARAM_SYS_MODULE_KEYWORD, 1);
	DECLARE IS_NULL_SYS_MODULE_NAME BIT DEFAULT `SYSTEM_VAR@IS_NULL@NVARCHAR`(PARAM_SYS_MODULE_NAME, 1);
	DECLARE IS_NULL_SYS_MODULE_DESCRIPTION BIT DEFAULT `SYSTEM_VAR@IS_NULL@NVARCHAR`(PARAM_SYS_MODULE_DESCRIPTION, 1);
	DECLARE IS_NULL_SYS_MODULE_SHOW_ACCESS_RIGHTS BIT DEFAULT `SYSTEM_VAR@IS_NULL@TINYINT`(PARAM_SYS_MODULE_SHOW_ACCESS_RIGHTS, 1, 1);
	DECLARE IS_NULL_SYS_MODULE_STATUS BIT DEFAULT `SYSTEM_VAR@IS_NULL@TINYINT`(PARAM_SYS_MODULE_STATUS, 1, 1);
	DECLARE IS_NULL_SYS_MODULE_SYNC_SAVE_UP_TIMESTAMP_FROM BIT DEFAULT `SYSTEM_VAR@IS_NULL@DATETIME`(PARAM_SYS_MODULE_SYNC_SAVE_UP_TIMESTAMP_FROM, 1);
	DECLARE IS_NULL_SYS_MODULE_SYNC_SAVE_UP_TIMESTAMP_TO BIT DEFAULT `SYSTEM_VAR@IS_NULL@DATETIME`(PARAM_SYS_MODULE_SYNC_SAVE_UP_TIMESTAMP_TO, 1);				
	DECLARE IS_NULL_SYS_MODULE_SYNC_SAVE_DL_TIMESTAMP_FROM BIT DEFAULT `SYSTEM_VAR@IS_NULL@DATETIME`(PARAM_SYS_MODULE_SYNC_SAVE_DL_TIMESTAMP_FROM, 1);
	DECLARE IS_NULL_SYS_MODULE_SYNC_SAVE_DL_TIMESTAMP_TO BIT DEFAULT `SYSTEM_VAR@IS_NULL@DATETIME`(PARAM_SYS_MODULE_SYNC_SAVE_DL_TIMESTAMP_TO, 1);				
	DECLARE IS_NULL_SYS_MODULE_SYNC_DELETE_UP_TIMESTAMP_FROM BIT DEFAULT `SYSTEM_VAR@IS_NULL@DATETIME`(PARAM_SYS_MODULE_SYNC_DELETE_UP_TIMESTAMP_FROM, 1);
	DECLARE IS_NULL_SYS_MODULE_SYNC_DELETE_UP_TIMESTAMP_TO BIT DEFAULT `SYSTEM_VAR@IS_NULL@DATETIME`(PARAM_SYS_MODULE_SYNC_DELETE_UP_TIMESTAMP_TO, 1);				
	DECLARE IS_NULL_SYS_MODULE_SYNC_DELETE_DL_TIMESTAMP_FROM BIT DEFAULT `SYSTEM_VAR@IS_NULL@DATETIME`(PARAM_SYS_MODULE_SYNC_DELETE_DL_TIMESTAMP_FROM, 1);
	DECLARE IS_NULL_SYS_MODULE_SYNC_DELETE_DL_TIMESTAMP_TO BIT DEFAULT `SYSTEM_VAR@IS_NULL@DATETIME`(PARAM_SYS_MODULE_SYNC_DELETE_DL_TIMESTAMP_TO, 1);				
	
	-- Error Handler
	-- =========================================================================================
	DECLARE EXIT HANDLER FOR SQLEXCEPTION
	BEGIN
		RESIGNAL;
	END;
	
	-- Ignore Time from DateTime (Set Time 00:00:00.000000 and 23:59:59.999999)
	-- =========================================================================================
		
		
	-- Access Rights [Device]
	-- =========================================================================================
		
		
	-- Access Rights [Account]
	-- =========================================================================================
	
	
	
	-- COUNT RECORD
	-- =========================================================================================
	
	-- SELECT COLUMNS
	-- ####################################################
	SELECT
		COUNT(DISTINCT `system_module`.`SYS_MODULE_ID`)
	INTO
		TEMP_RECORD_COUNT

	FROM `system_module`
	
		-- Add Inner Joins (Per Foreign-key)
		
		-- Add Optional Left Joins (Per Optional Foreign-key)
		
	-- CONDITIONS
	-- ####################################################
	WHERE
		(
			IS_NULL_SYS_MODULE_ID = 1 OR
			`system_module`.`SYS_MODULE_ID` = PARAM_SYS_MODULE_ID			
		) AND
		(
			IS_NULL_SYS_MODULE_CATEGORY = 1 OR
			`system_module`.`SYS_MODULE_CATEGORY` LIKE CONCAT_WS('%', '', PARAM_SYS_MODULE_CATEGORY, '')			
		) AND 		
		(
			IS_NULL_SYS_MODULE_KEYWORD = 1 OR
			`system_module`.`SYS_MODULE_KEYWORD` LIKE CONCAT_WS('%', '', PARAM_SYS_MODULE_KEYWORD, '')			
		) AND 		
		(
			IS_NULL_SYS_MODULE_NAME = 1 OR
			`system_module`.`SYS_MODULE_NAME` LIKE CONCAT_WS('%', '', PARAM_SYS_MODULE_NAME, '')			
		) AND 		
		(
			IS_NULL_SYS_MODULE_DESCRIPTION = 1 OR
			`system_module`.`SYS_MODULE_DESCRIPTION` LIKE CONCAT_WS('%', '', PARAM_SYS_MODULE_DESCRIPTION, '')			
		) AND 		
		(
			IS_NULL_SYS_MODULE_SHOW_ACCESS_RIGHTS = 1 OR
			`system_module`.`SYS_MODULE_SHOW_ACCESS_RIGHTS` = PARAM_SYS_MODULE_SHOW_ACCESS_RIGHTS			
		) AND
		(
			IS_NULL_SYS_MODULE_STATUS = 1 OR
			`system_module`.`SYS_MODULE_STATUS` = PARAM_SYS_MODULE_STATUS			
		) AND
		(
			IS_NULL_SYS_MODULE_SYNC_SAVE_UP_TIMESTAMP_FROM = 1 OR
			`system_module`.`SYS_MODULE_SYNC_SAVE_UP_TIMESTAMP` >= PARAM_SYS_MODULE_SYNC_SAVE_UP_TIMESTAMP_FROM			
		) AND
		(
			IS_NULL_SYS_MODULE_SYNC_SAVE_UP_TIMESTAMP_TO = 1 OR
			`system_module`.`SYS_MODULE_SYNC_SAVE_UP_TIMESTAMP` <= PARAM_SYS_MODULE_SYNC_SAVE_UP_TIMESTAMP_TO			
		) AND 		
		(
			IS_NULL_SYS_MODULE_SYNC_SAVE_DL_TIMESTAMP_FROM = 1 OR
			`system_module`.`SYS_MODULE_SYNC_SAVE_DL_TIMESTAMP` >= PARAM_SYS_MODULE_SYNC_SAVE_DL_TIMESTAMP_FROM			
		) AND
		(
			IS_NULL_SYS_MODULE_SYNC_SAVE_DL_TIMESTAMP_TO = 1 OR
			`system_module`.`SYS_MODULE_SYNC_SAVE_DL_TIMESTAMP` <= PARAM_SYS_MODULE_SYNC_SAVE_DL_TIMESTAMP_TO			
		) AND 		
		(
			IS_NULL_SYS_MODULE_SYNC_DELETE_UP_TIMESTAMP_FROM = 1 OR
			`system_module`.`SYS_MODULE_SYNC_DELETE_UP_TIMESTAMP` >= PARAM_SYS_MODULE_SYNC_DELETE_UP_TIMESTAMP_FROM			
		) AND
		(
			IS_NULL_SYS_MODULE_SYNC_DELETE_UP_TIMESTAMP_TO = 1 OR
			`system_module`.`SYS_MODULE_SYNC_DELETE_UP_TIMESTAMP` <= PARAM_SYS_MODULE_SYNC_DELETE_UP_TIMESTAMP_TO			
		) AND 		
		(
			IS_NULL_SYS_MODULE_SYNC_DELETE_DL_TIMESTAMP_FROM = 1 OR
			`system_module`.`SYS_MODULE_SYNC_DELETE_DL_TIMESTAMP` >= PARAM_SYS_MODULE_SYNC_DELETE_DL_TIMESTAMP_FROM			
		) AND
		(
			IS_NULL_SYS_MODULE_SYNC_DELETE_DL_TIMESTAMP_TO = 1 OR
			`system_module`.`SYS_MODULE_SYNC_DELETE_DL_TIMESTAMP` <= PARAM_SYS_MODULE_SYNC_DELETE_DL_TIMESTAMP_TO			
		) 		
;	

		
		
	-- SELECT RECORDS
	-- =========================================================================================
	
	-- FETCH COLUMNS
	-- ####################################################
	SELECT
		-- SYSTEM_MODULE DETAILS
		`system_module`.`SYS_MODULE_ID`, 
		`system_module`.`SYS_MODULE_CATEGORY`, 
		`system_module`.`SYS_MODULE_KEYWORD`, 
		`system_module`.`SYS_MODULE_NAME`, 
		`system_module`.`SYS_MODULE_DESCRIPTION`, 
		`system_module`.`SYS_MODULE_SHOW_ACCESS_RIGHTS`, 
		`system_module`.`SYS_MODULE_STATUS`, 
		`system_module`.`SYS_MODULE_SYNC_SAVE_UP_TIMESTAMP`, 
		`system_module`.`SYS_MODULE_SYNC_SAVE_DL_TIMESTAMP`, 
		`system_module`.`SYS_MODULE_SYNC_DELETE_UP_TIMESTAMP`, 
		`system_module`.`SYS_MODULE_SYNC_DELETE_DL_TIMESTAMP`
		
		-- Inner join fields
		
		-- Left join fields
		
		, TEMP_RECORD_COUNT AS RECORD_COUNT

	FROM `system_module`
	
		-- Add Inner Joins (Per Foreign-key)
		
		-- Add Optional Left Joins (Per Optional Foreign-key)
		
	-- CONDITIONS
	-- ####################################################
	WHERE
		(
			IS_NULL_SYS_MODULE_ID = 1 OR
			`system_module`.`SYS_MODULE_ID` = PARAM_SYS_MODULE_ID			
		) AND
		(
			IS_NULL_SYS_MODULE_CATEGORY = 1 OR
			`system_module`.`SYS_MODULE_CATEGORY` LIKE CONCAT_WS('%', '', PARAM_SYS_MODULE_CATEGORY, '')			
		) AND 		
		(
			IS_NULL_SYS_MODULE_KEYWORD = 1 OR
			`system_module`.`SYS_MODULE_KEYWORD` LIKE CONCAT_WS('%', '', PARAM_SYS_MODULE_KEYWORD, '')			
		) AND 		
		(
			IS_NULL_SYS_MODULE_NAME = 1 OR
			`system_module`.`SYS_MODULE_NAME` LIKE CONCAT_WS('%', '', PARAM_SYS_MODULE_NAME, '')			
		) AND 		
		(
			IS_NULL_SYS_MODULE_DESCRIPTION = 1 OR
			`system_module`.`SYS_MODULE_DESCRIPTION` LIKE CONCAT_WS('%', '', PARAM_SYS_MODULE_DESCRIPTION, '')			
		) AND 		
		(
			IS_NULL_SYS_MODULE_SHOW_ACCESS_RIGHTS = 1 OR
			`system_module`.`SYS_MODULE_SHOW_ACCESS_RIGHTS` = PARAM_SYS_MODULE_SHOW_ACCESS_RIGHTS			
		) AND
		(
			IS_NULL_SYS_MODULE_STATUS = 1 OR
			`system_module`.`SYS_MODULE_STATUS` = PARAM_SYS_MODULE_STATUS			
		) AND
		(
			IS_NULL_SYS_MODULE_SYNC_SAVE_UP_TIMESTAMP_FROM = 1 OR
			`system_module`.`SYS_MODULE_SYNC_SAVE_UP_TIMESTAMP` >= PARAM_SYS_MODULE_SYNC_SAVE_UP_TIMESTAMP_FROM			
		) AND
		(
			IS_NULL_SYS_MODULE_SYNC_SAVE_UP_TIMESTAMP_TO = 1 OR
			`system_module`.`SYS_MODULE_SYNC_SAVE_UP_TIMESTAMP` <= PARAM_SYS_MODULE_SYNC_SAVE_UP_TIMESTAMP_TO			
		) AND 
		(
			IS_NULL_SYS_MODULE_SYNC_SAVE_DL_TIMESTAMP_FROM = 1 OR
			`system_module`.`SYS_MODULE_SYNC_SAVE_DL_TIMESTAMP` >= PARAM_SYS_MODULE_SYNC_SAVE_DL_TIMESTAMP_FROM			
		) AND
		(
			IS_NULL_SYS_MODULE_SYNC_SAVE_DL_TIMESTAMP_TO = 1 OR
			`system_module`.`SYS_MODULE_SYNC_SAVE_DL_TIMESTAMP` <= PARAM_SYS_MODULE_SYNC_SAVE_DL_TIMESTAMP_TO			
		) AND 
		(
			IS_NULL_SYS_MODULE_SYNC_DELETE_UP_TIMESTAMP_FROM = 1 OR
			`system_module`.`SYS_MODULE_SYNC_DELETE_UP_TIMESTAMP` >= PARAM_SYS_MODULE_SYNC_DELETE_UP_TIMESTAMP_FROM			
		) AND
		(
			IS_NULL_SYS_MODULE_SYNC_DELETE_UP_TIMESTAMP_TO = 1 OR
			`system_module`.`SYS_MODULE_SYNC_DELETE_UP_TIMESTAMP` <= PARAM_SYS_MODULE_SYNC_DELETE_UP_TIMESTAMP_TO			
		) AND 
		(
			IS_NULL_SYS_MODULE_SYNC_DELETE_DL_TIMESTAMP_FROM = 1 OR
			`system_module`.`SYS_MODULE_SYNC_DELETE_DL_TIMESTAMP` >= PARAM_SYS_MODULE_SYNC_DELETE_DL_TIMESTAMP_FROM			
		) AND
		(
			IS_NULL_SYS_MODULE_SYNC_DELETE_DL_TIMESTAMP_TO = 1 OR
			`system_module`.`SYS_MODULE_SYNC_DELETE_DL_TIMESTAMP` <= PARAM_SYS_MODULE_SYNC_DELETE_DL_TIMESTAMP_TO			
		) 

	-- ORDER BY
	-- ####################################################
	ORDER BY
		-- SYSTEM_MODULE DETAILS
		CASE WHEN PARAM_ORDER_FIELD = 'SYS_MODULE_ID' AND PARAM_ORDER_TYPE = 'ASC' THEN `system_module`.`SYS_MODULE_ID` END ASC, 
		CASE WHEN PARAM_ORDER_FIELD = 'SYS_MODULE_ID' AND PARAM_ORDER_TYPE = 'DESC' THEN `system_module`.`SYS_MODULE_ID` END DESC,	
		CASE WHEN PARAM_ORDER_FIELD = 'SYS_MODULE_CATEGORY' AND PARAM_ORDER_TYPE = 'ASC' THEN `system_module`.`SYS_MODULE_CATEGORY` END ASC, 
		CASE WHEN PARAM_ORDER_FIELD = 'SYS_MODULE_CATEGORY' AND PARAM_ORDER_TYPE = 'DESC' THEN `system_module`.`SYS_MODULE_CATEGORY` END DESC,	
		CASE WHEN PARAM_ORDER_FIELD = 'SYS_MODULE_KEYWORD' AND PARAM_ORDER_TYPE = 'ASC' THEN `system_module`.`SYS_MODULE_KEYWORD` END ASC, 
		CASE WHEN PARAM_ORDER_FIELD = 'SYS_MODULE_KEYWORD' AND PARAM_ORDER_TYPE = 'DESC' THEN `system_module`.`SYS_MODULE_KEYWORD` END DESC,	
		CASE WHEN PARAM_ORDER_FIELD = 'SYS_MODULE_NAME' AND PARAM_ORDER_TYPE = 'ASC' THEN `system_module`.`SYS_MODULE_NAME` END ASC, 
		CASE WHEN PARAM_ORDER_FIELD = 'SYS_MODULE_NAME' AND PARAM_ORDER_TYPE = 'DESC' THEN `system_module`.`SYS_MODULE_NAME` END DESC,	
		CASE WHEN PARAM_ORDER_FIELD = 'SYS_MODULE_DESCRIPTION' AND PARAM_ORDER_TYPE = 'ASC' THEN `system_module`.`SYS_MODULE_DESCRIPTION` END ASC, 
		CASE WHEN PARAM_ORDER_FIELD = 'SYS_MODULE_DESCRIPTION' AND PARAM_ORDER_TYPE = 'DESC' THEN `system_module`.`SYS_MODULE_DESCRIPTION` END DESC,	
		CASE WHEN PARAM_ORDER_FIELD = 'SYS_MODULE_SHOW_ACCESS_RIGHTS' AND PARAM_ORDER_TYPE = 'ASC' THEN `system_module`.`SYS_MODULE_SHOW_ACCESS_RIGHTS` END ASC, 
		CASE WHEN PARAM_ORDER_FIELD = 'SYS_MODULE_SHOW_ACCESS_RIGHTS' AND PARAM_ORDER_TYPE = 'DESC' THEN `system_module`.`SYS_MODULE_SHOW_ACCESS_RIGHTS` END DESC,	
		CASE WHEN PARAM_ORDER_FIELD = 'SYS_MODULE_STATUS' AND PARAM_ORDER_TYPE = 'ASC' THEN `system_module`.`SYS_MODULE_STATUS` END ASC, 
		CASE WHEN PARAM_ORDER_FIELD = 'SYS_MODULE_STATUS' AND PARAM_ORDER_TYPE = 'DESC' THEN `system_module`.`SYS_MODULE_STATUS` END DESC,	
		CASE WHEN PARAM_ORDER_FIELD = 'SYS_MODULE_SYNC_SAVE_UP_TIMESTAMP' AND PARAM_ORDER_TYPE = 'ASC' THEN `system_module`.`SYS_MODULE_SYNC_SAVE_UP_TIMESTAMP` END ASC, 
		CASE WHEN PARAM_ORDER_FIELD = 'SYS_MODULE_SYNC_SAVE_UP_TIMESTAMP' AND PARAM_ORDER_TYPE = 'DESC' THEN `system_module`.`SYS_MODULE_SYNC_SAVE_UP_TIMESTAMP` END DESC,	
		CASE WHEN PARAM_ORDER_FIELD = 'SYS_MODULE_SYNC_SAVE_DL_TIMESTAMP' AND PARAM_ORDER_TYPE = 'ASC' THEN `system_module`.`SYS_MODULE_SYNC_SAVE_DL_TIMESTAMP` END ASC, 
		CASE WHEN PARAM_ORDER_FIELD = 'SYS_MODULE_SYNC_SAVE_DL_TIMESTAMP' AND PARAM_ORDER_TYPE = 'DESC' THEN `system_module`.`SYS_MODULE_SYNC_SAVE_DL_TIMESTAMP` END DESC,	
		CASE WHEN PARAM_ORDER_FIELD = 'SYS_MODULE_SYNC_DELETE_UP_TIMESTAMP' AND PARAM_ORDER_TYPE = 'ASC' THEN `system_module`.`SYS_MODULE_SYNC_DELETE_UP_TIMESTAMP` END ASC, 
		CASE WHEN PARAM_ORDER_FIELD = 'SYS_MODULE_SYNC_DELETE_UP_TIMESTAMP' AND PARAM_ORDER_TYPE = 'DESC' THEN `system_module`.`SYS_MODULE_SYNC_DELETE_UP_TIMESTAMP` END DESC,	
		CASE WHEN PARAM_ORDER_FIELD = 'SYS_MODULE_SYNC_DELETE_DL_TIMESTAMP' AND PARAM_ORDER_TYPE = 'ASC' THEN `system_module`.`SYS_MODULE_SYNC_DELETE_DL_TIMESTAMP` END ASC, 
		CASE WHEN PARAM_ORDER_FIELD = 'SYS_MODULE_SYNC_DELETE_DL_TIMESTAMP' AND PARAM_ORDER_TYPE = 'DESC' THEN `system_module`.`SYS_MODULE_SYNC_DELETE_DL_TIMESTAMP` END DESC,	

		-- Inner joins
		
		-- EXTRA
		CASE WHEN PARAM_ORDER_FIELD <> 'SYS_MODULE_KEYWORD' THEN `system_module`.`SYS_MODULE_KEYWORD` END ASC
		
	-- LIMIT & OFFSET
	-- ####################################################		
	LIMIT PARAM_SKIP, PARAM_LIMIT;
	
	
	
	-- EXIT PROCEDURE
	-- =========================================================================================
	LEAVE SP_GET;
			
END ;;
DELIMITER ;
/*!50003 SET sql_mode              = @saved_sql_mode */ ;
/*!50003 SET character_set_client  = @saved_cs_client */ ;
/*!50003 SET character_set_results = @saved_cs_results */ ;
/*!50003 SET collation_connection  = @saved_col_connection */ ;
/*!50003 DROP PROCEDURE IF EXISTS `SYSTEM_MODULE_SAVE` */;
/*!50003 SET @saved_cs_client      = @@character_set_client */ ;
/*!50003 SET @saved_cs_results     = @@character_set_results */ ;
/*!50003 SET @saved_col_connection = @@collation_connection */ ;
/*!50003 SET character_set_client  = latin1 */ ;
/*!50003 SET character_set_results = latin1 */ ;
/*!50003 SET collation_connection  = latin1_swedish_ci */ ;
/*!50003 SET @saved_sql_mode       = @@sql_mode */ ;
/*!50003 SET sql_mode              = '' */ ;
DELIMITER ;;
CREATE DEFINER=`root`@`localhost` PROCEDURE `SYSTEM_MODULE_SAVE`(
	IN `PARAM_SYS_MODULE_ID` BIGINT,
	IN `PARAM_SYS_MODULE_KEYWORD` VARCHAR(500),
	
	IN `PARAM_SYS_MODULE_SYNC_SAVE_UP_TIMESTAMP` DATETIME(6),
	IN `PARAM_SYS_MODULE_SYNC_SAVE_DL_TIMESTAMP` DATETIME(6),
	IN `PARAM_SYS_MODULE_SYNC_DELETE_UP_TIMESTAMP` DATETIME(6),
	IN `PARAM_SYS_MODULE_SYNC_DELETE_DL_TIMESTAMP` DATETIME(6),
	IN `PARAM_SUPPRESS_DATETIME_ERROR` BIT,
		
	IN `PARAM_REQUESTER_USERNAME` VARCHAR(500),
	IN `PARAM_REQUESTER_PASSWORD` VARCHAR(500),
	IN `PARAM_REQUESTER_PROXY_ID` BIGINT,
	IN `PARAM_REQUESTER_PROXY_PASSWORD` VARCHAR(1000),
	IN `PARAM_REQUESTER_DEVICE_PUBLIC_KEY` VARCHAR(1000),
	IN `PARAM_REQUESTER_DEVICE_PRIVATE_KEY` VARCHAR(1000),
	
	IN `PARAM_REQUESTER_IP` VARCHAR(1000),
	IN `PARAM_UNIQUE_SESSION_ID` VARCHAR(1000),
	IN `PARAM_SUPPRESS_RETURN` BIT
)
SP_SAVE:
BEGIN
	
	-- 1) DECLARE LOCAL PARAMETERS
	-- _______________________________________________________________________
		
	-- Status
	-- ...........................................
	DECLARE STATUS_INACTIVE TINYINT DEFAULT 1;
	DECLARE STATUS_ACTIVE TINYINT DEFAULT 2;
	DECLARE STATUS_CLOSED TINYINT DEFAULT 3;
	DECLARE STATUS_COMPLETED TINYINT DEFAULT 4;

	-- Audit Handler
	-- ...........................................
	DECLARE TEMP_RECORD_EXISTS BIT DEFAULT 0;
	DECLARE TEMP_MODULE_KEYWORD VARCHAR(500) DEFAULT 'system_module';
	DECLARE TEMP_SP_OBJECTIVE VARCHAR(500) DEFAULT 'add/edit system_module record';
	DECLARE TEMP_ERR_MESSAGE VARCHAR(500) DEFAULT '';
	DECLARE ERR BIGINT DEFAULT 0;
	DECLARE TEMP_RECORD_CHANGES NVARCHAR(16000) DEFAULT '';
	DECLARE TEMP_RECORD_BINDED BIT DEFAULT 0;
		
	-- Authentication
	-- ...........................................
	DECLARE TEMP_ACCESS_RIGHTS_DENIED BIT DEFAULT 0;
	DECLARE TEMP_ACCESS_RIGHTS_HAS_OVERRIDE BIT DEFAULT 0;
	DECLARE TEMP_SYNC_SERVER_ID BIGINT DEFAULT 0;
	DECLARE TEMP_SYNC_IS_SERVER_REQUEST BIT DEFAULT 0;
	DECLARE TEMP_AUTHENTICATED_ACCOUNT_ID BIGINT DEFAULT `ACCOUNT_MEMBER@ACC_ACCOUNT_ID_FROM_LOGIN`(PARAM_REQUESTER_USERNAME, PARAM_REQUESTER_PASSWORD);
	DECLARE TEMP_AUTHENTICATED_ACCOUNT_LEVEL BIGINT DEFAULT `ACCOUNT_MEMBER@ACC_ACCOUNT_LEVEL_FROM_LOGIN`(PARAM_REQUESTER_USERNAME, PARAM_REQUESTER_PASSWORD);
		
	DECLARE TEMP_NOW DATETIME(6) DEFAULT `SYSTEM_VAR@NOW`('', 1);
		
	-- Local value holder
	-- ...........................................
	DECLARE TEMP_SYS_MODULE_KEYWORD VARCHAR(500) DEFAULT ''; 

	DECLARE TEMP_SYS_MODULE_SYNC_SAVE_UP_TIMESTAMP DATETIME(6) DEFAULT '1000-01-01 00:00:00.000000'; 
	DECLARE TEMP_SYS_MODULE_SYNC_SAVE_DL_TIMESTAMP DATETIME(6) DEFAULT '1000-01-01 00:00:00.000000'; 
	DECLARE TEMP_SYS_MODULE_SYNC_DELETE_UP_TIMESTAMP DATETIME(6) DEFAULT '1000-01-01 00:00:00.000000'; 
	DECLARE TEMP_SYS_MODULE_SYNC_DELETE_DL_TIMESTAMP DATETIME(6) DEFAULT '1000-01-01 00:00:00.000000'; 
		
	-- 2) Try Catch / Throw
	-- ====================================================================================================================================================================
	DECLARE EXIT HANDLER FOR SQLEXCEPTION
	BEGIN
		RESIGNAL;
	END;
	-- ====================================================================================================================================================================

	
	
	-- 3) IF ALREADY EXIST, FILL MISSING DATA
	-- ====================================================================================================================================================================
	IF
	(
		SELECT COUNT(`system_module`.`SYS_MODULE_ID`)
		FROM `system_module`
		WHERE
			`system_module`.`SYS_MODULE_ID` = PARAM_SYS_MODULE_ID OR
			`system_module`.`SYS_MODULE_CATEGORY` = PARAM_SYS_MODULE_KEYWORD
		LIMIT 1
	)
	THEN
		SET TEMP_RECORD_EXISTS = 1;
	ELSE
		SET TEMP_RECORD_EXISTS = 0;
	END IF;
	
	IF TEMP_RECORD_EXISTS = 1 THEN
	
		SELECT
			`system_module`.`SYS_MODULE_ID`,
			`system_module`.`SYS_MODULE_SYNC_SAVE_UP_TIMESTAMP`,
			`system_module`.`SYS_MODULE_SYNC_SAVE_DL_TIMESTAMP`,
			`system_module`.`SYS_MODULE_SYNC_DELETE_UP_TIMESTAMP`,
			`system_module`.`SYS_MODULE_SYNC_DELETE_DL_TIMESTAMP`
			
		INTO 
			PARAM_SYS_MODULE_ID,
			TEMP_SYS_MODULE_SYNC_SAVE_UP_TIMESTAMP,
			TEMP_SYS_MODULE_SYNC_SAVE_DL_TIMESTAMP,
			TEMP_SYS_MODULE_SYNC_DELETE_UP_TIMESTAMP,
			TEMP_SYS_MODULE_SYNC_DELETE_DL_TIMESTAMP

		FROM `account_access_rights`
		WHERE
			`system_module`.`SYS_MODULE_ID` = PARAM_SYS_MODULE_ID OR
			`system_module`.`SYS_MODULE_CATEGORY` = PARAM_SYS_MODULE_KEYWORD
		LIMIT 1;

		SET PARAM_SYS_MODULE_SYNC_SAVE_UP_TIMESTAMP = `SYSTEM_VAR@REPLACE_NULL@DATETIME`(PARAM_SYS_MODULE_SYNC_SAVE_UP_TIMESTAMP, TEMP_SYS_MODULE_SYNC_SAVE_UP_TIMESTAMP, 0);
		SET PARAM_SYS_MODULE_SYNC_SAVE_DL_TIMESTAMP = `SYSTEM_VAR@REPLACE_NULL@DATETIME`(PARAM_SYS_MODULE_SYNC_SAVE_DL_TIMESTAMP, TEMP_SYS_MODULE_SYNC_SAVE_DL_TIMESTAMP, 0);
		SET PARAM_SYS_MODULE_SYNC_DELETE_UP_TIMESTAMP = `SYSTEM_VAR@REPLACE_NULL@DATETIME`(PARAM_SYS_MODULE_SYNC_DELETE_UP_TIMESTAMP, TEMP_SYS_MODULE_SYNC_DELETE_UP_TIMESTAMP, 0);
		SET PARAM_SYS_MODULE_SYNC_DELETE_DL_TIMESTAMP = `SYSTEM_VAR@REPLACE_NULL@DATETIME`(PARAM_SYS_MODULE_SYNC_DELETE_DL_TIMESTAMP, TEMP_SYS_MODULE_SYNC_DELETE_DL_TIMESTAMP, 0);	
	ELSE
		SET TEMP_ERR_MESSAGE = CONCAT_WS(' ', 'Given MODULE does not exists or is inactive. ID: ', PARAM_SYS_MODULE_ID, PARAM_SYS_MODULE_KEYWORD);
		SET ERR = `RAISERROR`(TEMP_ERR_MESSAGE);		
	END IF;
	-- ====================================================================================================================================================================

	
	-- X) PRE-VALIDATE
	-- ====================================================================================================================================================================
	-- Should not update DateTime older than currently set
	IF PARAM_SYS_MODULE_SYNC_SAVE_UP_TIMESTAMP < TEMP_SYS_MODULE_SYNC_SAVE_UP_TIMESTAMP THEN
		IF PARAM_SUPPRESS_DATETIME_ERROR = 0 THEN
			SET TEMP_ERR_MESSAGE = CONCAT_WS(' ', 'SYNC TIMESTAMP (SAVE-UPLOAD) cannot not be older than currently saved', 'FROM:', TEMP_SYS_MODULE_SYNC_SAVE_UP_TIMESTAMP, 'TO:', PARAM_SYS_MODULE_SYNC_SAVE_UP_TIMESTAMP);
			SET ERR = `RAISERROR`(TEMP_ERR_MESSAGE);	
		ELSE
			SET PARAM_SYS_MODULE_SYNC_SAVE_UP_TIMESTAMP = TEMP_SYS_MODULE_SYNC_SAVE_UP_TIMESTAMP;
		END IF;
	END IF;
	
	IF PARAM_SYS_MODULE_SYNC_SAVE_DL_TIMESTAMP < TEMP_SYS_MODULE_SYNC_SAVE_DL_TIMESTAMP THEN
		IF PARAM_SUPPRESS_DATETIME_ERROR = 0 THEN
			SET TEMP_ERR_MESSAGE = CONCAT_WS(' ', 'SYNC TIMESTAMP (SAVE-DOWNLOAD) cannot not be older than currently saved', 'FROM:', TEMP_SYS_MODULE_SYNC_SAVE_DL_TIMESTAMP, 'TO:', PARAM_SYS_MODULE_SYNC_SAVE_DL_TIMESTAMP);
			SET ERR = `RAISERROR`(TEMP_ERR_MESSAGE);
		ELSE
			SET PARAM_SYS_MODULE_SYNC_SAVE_DL_TIMESTAMP = TEMP_SYS_MODULE_SYNC_SAVE_DL_TIMESTAMP;
		END IF;
	END IF;
	
	IF PARAM_SYS_MODULE_SYNC_DELETE_UP_TIMESTAMP < TEMP_SYS_MODULE_SYNC_DELETE_UP_TIMESTAMP THEN
		IF PARAM_SUPPRESS_DATETIME_ERROR = 0 THEN
			SET TEMP_ERR_MESSAGE = CONCAT_WS(' ', 'SYNC TIMESTAMP (DELETE-UPLOAD) cannot not be older than currently saved', 'FROM:', TEMP_SYS_MODULE_SYNC_DELETE_UP_TIMESTAMP, 'TO:', PARAM_SYS_MODULE_SYNC_DELETE_UP_TIMESTAMP);
			SET ERR = `RAISERROR`(TEMP_ERR_MESSAGE);
		ELSE
			SET PARAM_SYS_MODULE_SYNC_DELETE_UP_TIMESTAMP = TEMP_SYS_MODULE_SYNC_DELETE_UP_TIMESTAMP;
		END IF;
	END IF;	
	
	IF PARAM_SYS_MODULE_SYNC_DELETE_DL_TIMESTAMP < TEMP_SYS_MODULE_SYNC_DELETE_DL_TIMESTAMP THEN
		IF PARAM_SUPPRESS_DATETIME_ERROR = 0 THEN
			SET TEMP_ERR_MESSAGE = CONCAT_WS(' ', 'SYNC TIMESTAMP (DELETE-DOWNLOAD) cannot not be older than currently saved', 'FROM:', TEMP_SYS_MODULE_SYNC_DELETE_DL_TIMESTAMP, 'TO:', PARAM_SYS_MODULE_SYNC_DELETE_DL_TIMESTAMP);
			SET ERR = `RAISERROR`(TEMP_ERR_MESSAGE);
		ELSE
			SET PARAM_SYS_MODULE_SYNC_DELETE_DL_TIMESTAMP = TEMP_SYS_MODULE_SYNC_DELETE_DL_TIMESTAMP;
		END IF;
	END IF;	
	
	
	-- 4) PREPARE AUDIT TRAIL
	-- ====================================================================================================================================================================
	SET TEMP_RECORD_CHANGES = '';
	IF TEMP_SYS_MODULE_SYNC_SAVE_UP_TIMESTAMP <> PARAM_SYS_MODULE_SYNC_SAVE_UP_TIMESTAMP THEN
		SET TEMP_RECORD_CHANGES = 
		`SYSTEM_VAR@CONCAT_ADD`(' | ', TEMP_RECORD_CHANGES, CONCAT_WS(' ', 'SAVE UPLOAD TIMESTAMP:"', TEMP_SYS_MODULE_SYNC_SAVE_UP_TIMESTAMP, '" > "', PARAM_SYS_MODULE_SYNC_SAVE_UP_TIMESTAMP, '"'));
	END IF;

	IF TEMP_SYS_MODULE_SYNC_SAVE_DL_TIMESTAMP <> PARAM_SYS_MODULE_SYNC_SAVE_DL_TIMESTAMP THEN
		SET TEMP_RECORD_CHANGES = 
		`SYSTEM_VAR@CONCAT_ADD`(' | ', TEMP_RECORD_CHANGES, CONCAT_WS(' ', 'SAVE DOWNLOAD TIMESTAMP:"', TEMP_SYS_MODULE_SYNC_SAVE_DL_TIMESTAMP, '" > "', PARAM_SYS_MODULE_SYNC_SAVE_DL_TIMESTAMP, '"'));
	END IF;
	
	IF TEMP_SYS_MODULE_SYNC_DELETE_UP_TIMESTAMP <> PARAM_SYS_MODULE_SYNC_DELETE_UP_TIMESTAMP THEN
		SET TEMP_RECORD_CHANGES = 
		`SYSTEM_VAR@CONCAT_ADD`(' | ', TEMP_RECORD_CHANGES, CONCAT_WS(' ', 'DELETE UPLOAD TIMESTAMP:"', TEMP_SYS_MODULE_SYNC_DELETE_UP_TIMESTAMP, '" > "', PARAM_SYS_MODULE_SYNC_DELETE_UP_TIMESTAMP, '"'));
	END IF;
	
	IF TEMP_SYS_MODULE_SYNC_DELETE_DL_TIMESTAMP <> PARAM_SYS_MODULE_SYNC_DELETE_DL_TIMESTAMP THEN
		SET TEMP_RECORD_CHANGES = 
		`SYSTEM_VAR@CONCAT_ADD`(' | ', TEMP_RECORD_CHANGES, CONCAT_WS(' ', 'DELETE DOWNLOAD TIMESTAMP:"', TEMP_SYS_MODULE_SYNC_DELETE_DL_TIMESTAMP, '" > "', PARAM_SYS_MODULE_SYNC_DELETE_DL_TIMESTAMP, '"'));
	END IF;
	
	-- No Changes in data, reject request
	IF CHAR_LENGTH(TEMP_RECORD_CHANGES) = 0 THEN
		IF PARAM_SUPPRESS_RETURN = 0 THEN
			SELECT PARAM_SYS_MODULE_ID AS INSERTED_ID;
		ELSE
			LEAVE SP_SAVE;
		END IF;
	END IF;
	-- ====================================================================================================================================================================
	
	
	-- 5) VALIDATE
	-- ====================================================================================================================================================================
	
	-- Access Rights
	IF `ACCOUNT_ACCESS_RIGHTS@HAS_PERMISSION`(PARAM_REQUESTER_USERNAME, PARAM_REQUESTER_PASSWORD, 0, TEMP_SYS_MODULE_KEYWORD, 2) = 0 THEN
		SET TEMP_ACCESS_RIGHTS_DENIED = 1;
		CALL `ACCOUNT_ACCESS_RIGHTS_DENY`
		(
			0, TEMP_SYS_MODULE_KEYWORD, PARAM_SYS_MODULE_ID, 0, TEMP_SP_OBJECTIVE, TEMP_RECORD_CHANGES, 
			PARAM_REQUESTER_USERNAME, PARAM_REQUESTER_PASSWORD, 
			PARAM_REQUESTER_PROXY_ID, PARAM_REQUESTER_PROXY_PASSWORD,
			PARAM_REQUESTER_DEVICE_PUBLIC_KEY, PARAM_REQUESTER_DEVICE_PRIVATE_KEY,
			PARAM_REQUESTER_IP, PARAM_UNIQUE_SESSION_ID,
			TEMP_SYNC_SERVER_ID, PARAM_SUPPRESS_RETURN
		);
	END IF;
	
	-- ====================================================================================================================================================================


	-- 6) INSERT / UPDATE
	-- ====================================================================================================================================================================
	
	UPDATE `system_module`
	SET
		`system_module`.`SYS_MODULE_SYNC_SAVE_UP_TIMESTAMP` = PARAM_SYS_MODULE_SYNC_SAVE_UP_TIMESTAMP,
		`system_module`.`SYS_MODULE_SYNC_SAVE_DL_TIMESTAMP` = PARAM_SYS_MODULE_SYNC_SAVE_DL_TIMESTAMP,
		`system_module`.`SYS_MODULE_SYNC_DELETE_UP_TIMESTAMP` = PARAM_SYS_MODULE_SYNC_DELETE_UP_TIMESTAMP,
		`system_module`.`SYS_MODULE_SYNC_DELETE_DL_TIMESTAMP` = PARAM_SYS_MODULE_SYNC_DELETE_DL_TIMESTAMP

	WHERE
		`system_module`.`SYS_MODULE_ID` = PARAM_SYS_MODULE_ID;

	-- ====================================================================================================================================================================
	

	-- 7) AUDIT TRAIL
	-- ====================================================================================================================================================================
	CALL `ACCOUNT_AUDIT_TRAIL_SAVE`
	(
		0, TEMP_SYS_MODULE_KEYWORD, PARAM_SYS_MODULE_ID, 0, 'SAVE', TEMP_SP_OBJECTIVE, TEMP_RECORD_CHANGES, 
		PARAM_REQUESTER_USERNAME, PARAM_REQUESTER_PASSWORD, 
		PARAM_REQUESTER_PROXY_ID, PARAM_REQUESTER_PROXY_PASSWORD,
		PARAM_REQUESTER_DEVICE_PUBLIC_KEY, PARAM_REQUESTER_DEVICE_PRIVATE_KEY,
		PARAM_REQUESTER_IP, PARAM_UNIQUE_SESSION_ID,
		TEMP_SYNC_SERVER_ID, PARAM_SUPPRESS_RETURN
	);
	-- ====================================================================================================================================================================
		
	
	-- 8) RETURN RESULT
	-- ====================================================================================================================================================================
	IF PARAM_SUPPRESS_RETURN = 0 THEN
		SELECT PARAM_SYS_MODULE_ID AS INSERTED_ID;
	ELSE
		LEAVE SP_SAVE;
	END IF;
	-- ====================================================================================================================================================================

			
END ;;
DELIMITER ;
/*!50003 SET sql_mode              = @saved_sql_mode */ ;
/*!50003 SET character_set_client  = @saved_cs_client */ ;
/*!50003 SET character_set_results = @saved_cs_results */ ;
/*!50003 SET collation_connection  = @saved_col_connection */ ;
/*!50003 DROP PROCEDURE IF EXISTS `SYSTEM_SORT_BUFFER` */;
/*!50003 SET @saved_cs_client      = @@character_set_client */ ;
/*!50003 SET @saved_cs_results     = @@character_set_results */ ;
/*!50003 SET @saved_col_connection = @@collation_connection */ ;
/*!50003 SET character_set_client  = latin1 */ ;
/*!50003 SET character_set_results = latin1 */ ;
/*!50003 SET collation_connection  = latin1_swedish_ci */ ;
/*!50003 SET @saved_sql_mode       = @@sql_mode */ ;
/*!50003 SET sql_mode              = '' */ ;
DELIMITER ;;
CREATE DEFINER=`root`@`localhost` PROCEDURE `SYSTEM_SORT_BUFFER`()
SP_GET:
BEGIN

	-- Audit Handler
	DECLARE ERR BIGINT DEFAULT 0;
	
	-- Required in SELECT STATEMENT required large amount of inner joins.
	-- Must called (from PHP) before the SP calls for SELECT.
	DECLARE PARAM_BUFFER_SIZE BIGINT DEFAULT 1024 * 1024;
	IF @@GLOBAL.sort_buffer_size <> PARAM_BUFFER_SIZE THEN
		SET GLOBAL sort_buffer_size = PARAM_BUFFER_SIZE;
	END IF;	
	
END ;;
DELIMITER ;
/*!50003 SET sql_mode              = @saved_sql_mode */ ;
/*!50003 SET character_set_client  = @saved_cs_client */ ;
/*!50003 SET character_set_results = @saved_cs_results */ ;
/*!50003 SET collation_connection  = @saved_col_connection */ ;
/*!50003 DROP PROCEDURE IF EXISTS `SYSTEM_SORT_GET` */;
/*!50003 SET @saved_cs_client      = @@character_set_client */ ;
/*!50003 SET @saved_cs_results     = @@character_set_results */ ;
/*!50003 SET @saved_col_connection = @@collation_connection */ ;
/*!50003 SET character_set_client  = latin1 */ ;
/*!50003 SET character_set_results = latin1 */ ;
/*!50003 SET collation_connection  = latin1_swedish_ci */ ;
/*!50003 SET @saved_sql_mode       = @@sql_mode */ ;
/*!50003 SET sql_mode              = '' */ ;
DELIMITER ;;
CREATE DEFINER=`root`@`localhost` PROCEDURE `SYSTEM_SORT_GET`(
	IN `PARAM_SYS_SORT_ID` BIGINT,	
	IN `PARAM_SYS_SORT_CODE` VARCHAR(50),	
	IN `PARAM_SYS_SORT_DESCRIPTION` VARCHAR(500),	
	IN `PARAM_SYS_SORT_STATUS` TINYINT,	
		
	IN `PARAM_ORDER_FIELD` VARCHAR(500),
	IN `PARAM_ORDER_TYPE` VARCHAR(500),
	IN `PARAM_SKIP` BIGINT,
	IN `PARAM_LIMIT` BIGINT,

	IN `PARAM_REQUESTER_USERNAME` VARCHAR(500),
	IN `PARAM_REQUESTER_PASSWORD` VARCHAR(500),
	IN `PARAM_REQUESTER_PROXY_ID` BIGINT,
	IN `PARAM_REQUESTER_PROXY_PASSWORD` VARCHAR(1000),
	IN `PARAM_REQUESTER_DEVICE_PUBLIC_KEY` VARCHAR(1000),
	IN `PARAM_REQUESTER_DEVICE_PRIVATE_KEY` VARCHAR(1000),
	
	IN `PARAM_REQUESTER_IP` VARCHAR(1000),
	IN `PARAM_UNIQUE_SESSION_ID` VARCHAR(1000),
	IN `PARAM_SUPPRESS_RETURN` BIT
)
SP_GET:
BEGIN

	-- Status
	-- =========================================================================================
	DECLARE STATUS_INACTIVE TINYINT DEFAULT 1;
	DECLARE STATUS_ACTIVE TINYINT DEFAULT 2;
	DECLARE STATUS_CLOSED TINYINT DEFAULT 3;
	DECLARE STATUS_COMPLETED TINYINT DEFAULT 4;
	
	-- Audit Handler
	-- =========================================================================================
	DECLARE TEMP_RECORD_EXISTS BIT DEFAULT 0;
	DECLARE TEMP_MODULE_KEYWORD VARCHAR(500) DEFAULT 'system_sort';
	DECLARE TEMP_SP_OBJECTIVE VARCHAR(500) DEFAULT 'Retrieve Sort record';
	DECLARE TEMP_ERR_MESSAGE VARCHAR(500) DEFAULT '';
	DECLARE ERR BIGINT DEFAULT 0;
	DECLARE TEMP_RECORD_CHANGES VARCHAR(16000) DEFAULT '';
	DECLARE TEMP_RECORD_BINDED BIT DEFAULT 0;
	
	DECLARE TEMP_RECORD_BINDED_ID BIGINT DEFAULT 0;
	DECLARE TEMP_RECORD_BINDED_SERVER_ID BIGINT DEFAULT 0;
	
	-- Authentication
	-- =========================================================================================
	DECLARE TEMP_ACCESS_RIGHTS_DENIED BIT DEFAULT 0;
	DECLARE TEMP_AUTHENTICATED_ACCOUNT_ID BIGINT DEFAULT `ACCOUNT_MEMBER@ACC_ACCOUNT_ID_FROM_LOGIN`(PARAM_REQUESTER_USERNAME, PARAM_REQUESTER_PASSWORD);
	DECLARE TEMP_AUTHENTICATED_ACCOUNT_LEVEL BIGINT DEFAULT 0;
	DECLARE TEMP_AUTHENTICATED_ACCOUNT_GROUP BIGINT DEFAULT 0;
	
	-- Local Parameters
	-- =========================================================================================
	DECLARE TEMP_NOW DATETIME(6) DEFAULT `SYSTEM_VAR@NOW`('', 1);
	DECLARE TEMP_RECORD_COUNT BIGINT DEFAULT 0;
	
	
	-- Check NULLs
	-- =========================================================================================
	DECLARE IS_NULL_SYS_SORT_ID BIT DEFAULT `SYSTEM_VAR@IS_NULL@BIGINT`(PARAM_SYS_SORT_ID, 1, 1);
	DECLARE IS_NULL_SYS_SORT_CODE BIT DEFAULT `SYSTEM_VAR@IS_NULL@NVARCHAR`(PARAM_SYS_SORT_CODE, 1);
	DECLARE IS_NULL_SYS_SORT_DESCRIPTION BIT DEFAULT `SYSTEM_VAR@IS_NULL@NVARCHAR`(PARAM_SYS_SORT_DESCRIPTION, 1);
	DECLARE IS_NULL_SYS_SORT_STATUS BIT DEFAULT `SYSTEM_VAR@IS_NULL@TINYINT`(PARAM_SYS_SORT_STATUS, 1, 1);
	
	-- Error Handler
	-- =========================================================================================
	DECLARE EXIT HANDLER FOR SQLEXCEPTION
	BEGIN
		RESIGNAL;
	END;
	
	-- Ignore Time from DateTime (Set Time 00:00:00.000000 and 23:59:59.999999)
	-- =========================================================================================
		
		
	-- Access Rights [Device]
	-- =========================================================================================
		
		
	-- Access Rights [Account]
	-- =========================================================================================
	
	
	
	-- COUNT RECORD
	-- =========================================================================================
	
	-- SELECT COLUMNS
	-- ####################################################
	SELECT
		COUNT(DISTINCT `system_sort`.`SYS_SORT_ID`)
	INTO
		TEMP_RECORD_COUNT

	FROM `system_sort`
	
		-- Add Inner Joins (Per Foreign-key)
		
		-- Add Optional Left Joins (Per Optional Foreign-key)
		
	-- CONDITIONS
	-- ####################################################
	WHERE
		(
			IS_NULL_SYS_SORT_ID = 1 OR
			`system_sort`.`SYS_SORT_ID` = PARAM_SYS_SORT_ID			
		) AND
		(
			IS_NULL_SYS_SORT_CODE = 1 OR
			`system_sort`.`SYS_SORT_CODE` LIKE CONCAT_WS('%', '', PARAM_SYS_SORT_CODE, '')			
		) AND 		
		(
			IS_NULL_SYS_SORT_DESCRIPTION = 1 OR
			`system_sort`.`SYS_SORT_DESCRIPTION` LIKE CONCAT_WS('%', '', PARAM_SYS_SORT_DESCRIPTION, '')			
		) AND 		
		(
			IS_NULL_SYS_SORT_STATUS = 1 OR
			`system_sort`.`SYS_SORT_STATUS` = PARAM_SYS_SORT_STATUS			
		) 
;	

		
		
	-- SELECT RECORDS
	-- =========================================================================================
	
	-- FETCH COLUMNS
	-- ####################################################
	SELECT
		-- SYSTEM_SORT DETAILS
		`system_sort`.`SYS_SORT_ID`, 
		`system_sort`.`SYS_SORT_CODE`, 
		`system_sort`.`SYS_SORT_DESCRIPTION`, 
		`system_sort`.`SYS_SORT_STATUS`
		
		-- Inner join fields
		
		-- Left join fields
		
		, TEMP_RECORD_COUNT AS RECORD_COUNT

	FROM `system_sort`
	
		-- Add Inner Joins (Per Foreign-key)
		
		-- Add Optional Left Joins (Per Optional Foreign-key)
		
	-- CONDITIONS
	-- ####################################################
	WHERE
		(
			IS_NULL_SYS_SORT_ID = 1 OR
			`system_sort`.`SYS_SORT_ID` = PARAM_SYS_SORT_ID			
		) AND
		(
			IS_NULL_SYS_SORT_CODE = 1 OR
			`system_sort`.`SYS_SORT_CODE` LIKE CONCAT_WS('%', '', PARAM_SYS_SORT_CODE, '')			
		) AND 		
		(
			IS_NULL_SYS_SORT_DESCRIPTION = 1 OR
			`system_sort`.`SYS_SORT_DESCRIPTION` LIKE CONCAT_WS('%', '', PARAM_SYS_SORT_DESCRIPTION, '')			
		) AND 		
		(
			IS_NULL_SYS_SORT_STATUS = 1 OR
			`system_sort`.`SYS_SORT_STATUS` = PARAM_SYS_SORT_STATUS			
		) 

	-- ORDER BY
	-- ####################################################
	ORDER BY
		-- SYSTEM_SORT DETAILS
		CASE WHEN PARAM_ORDER_FIELD = 'SYS_SORT_ID' AND PARAM_ORDER_TYPE = 'ASC' THEN `system_sort`.`SYS_SORT_ID` END ASC, 
		CASE WHEN PARAM_ORDER_FIELD = 'SYS_SORT_ID' AND PARAM_ORDER_TYPE = 'DESC' THEN `system_sort`.`SYS_SORT_ID` END DESC,	
		CASE WHEN PARAM_ORDER_FIELD = 'SYS_SORT_CODE' AND PARAM_ORDER_TYPE = 'ASC' THEN `system_sort`.`SYS_SORT_CODE` END ASC, 
		CASE WHEN PARAM_ORDER_FIELD = 'SYS_SORT_CODE' AND PARAM_ORDER_TYPE = 'DESC' THEN `system_sort`.`SYS_SORT_CODE` END DESC,	
		CASE WHEN PARAM_ORDER_FIELD = 'SYS_SORT_DESCRIPTION' AND PARAM_ORDER_TYPE = 'ASC' THEN `system_sort`.`SYS_SORT_DESCRIPTION` END ASC, 
		CASE WHEN PARAM_ORDER_FIELD = 'SYS_SORT_DESCRIPTION' AND PARAM_ORDER_TYPE = 'DESC' THEN `system_sort`.`SYS_SORT_DESCRIPTION` END DESC,	
		CASE WHEN PARAM_ORDER_FIELD = 'SYS_SORT_STATUS' AND PARAM_ORDER_TYPE = 'ASC' THEN `system_sort`.`SYS_SORT_STATUS` END ASC, 
		CASE WHEN PARAM_ORDER_FIELD = 'SYS_SORT_STATUS' AND PARAM_ORDER_TYPE = 'DESC' THEN `system_sort`.`SYS_SORT_STATUS` END DESC,	

		-- Inner joins
		
		-- EXTRA
		CASE WHEN PARAM_ORDER_FIELD <> 'SYS_SORT_DESCRIPTION' THEN `system_sort`.`SYS_SORT_DESCRIPTION` END ASC
		
	-- LIMIT & OFFSET
	-- ####################################################		
	LIMIT PARAM_SKIP, PARAM_LIMIT;
	
	
	
	-- EXIT PROCEDURE
	-- =========================================================================================
	LEAVE SP_GET;
			
END ;;
DELIMITER ;
/*!50003 SET sql_mode              = @saved_sql_mode */ ;
/*!50003 SET character_set_client  = @saved_cs_client */ ;
/*!50003 SET character_set_results = @saved_cs_results */ ;
/*!50003 SET collation_connection  = @saved_col_connection */ ;
/*!50003 DROP PROCEDURE IF EXISTS `SYSTEM_STATUS_GET` */;
/*!50003 SET @saved_cs_client      = @@character_set_client */ ;
/*!50003 SET @saved_cs_results     = @@character_set_results */ ;
/*!50003 SET @saved_col_connection = @@collation_connection */ ;
/*!50003 SET character_set_client  = latin1 */ ;
/*!50003 SET character_set_results = latin1 */ ;
/*!50003 SET collation_connection  = latin1_swedish_ci */ ;
/*!50003 SET @saved_sql_mode       = @@sql_mode */ ;
/*!50003 SET sql_mode              = '' */ ;
DELIMITER ;;
CREATE DEFINER=`root`@`localhost` PROCEDURE `SYSTEM_STATUS_GET`(
	IN `PARAM_SYS_STATUS_ID` BIGINT,	
	IN `PARAM_SYS_STATUS_DESCRIPTION` VARCHAR(500),	
	IN `PARAM_SYS_STATUS_DESCRIPTION_2` VARCHAR(500),	
	IN `PARAM_SYS_STATUS_DESCRIPTION_3` VARCHAR(500),	
	IN `PARAM_SYS_STATUS_STATUS` TINYINT,	
		
	IN `PARAM_ORDER_FIELD` VARCHAR(500),
	IN `PARAM_ORDER_TYPE` VARCHAR(500),
	IN `PARAM_SKIP` BIGINT,
	IN `PARAM_LIMIT` BIGINT,

	IN `PARAM_REQUESTER_USERNAME` VARCHAR(500),
	IN `PARAM_REQUESTER_PASSWORD` VARCHAR(500),
	IN `PARAM_REQUESTER_PROXY_ID` BIGINT,
	IN `PARAM_REQUESTER_PROXY_PASSWORD` VARCHAR(1000),
	IN `PARAM_REQUESTER_DEVICE_PUBLIC_KEY` VARCHAR(1000),
	IN `PARAM_REQUESTER_DEVICE_PRIVATE_KEY` VARCHAR(1000),
	
	IN `PARAM_REQUESTER_IP` VARCHAR(1000),
	IN `PARAM_UNIQUE_SESSION_ID` VARCHAR(1000),
	IN `PARAM_SUPPRESS_RETURN` BIT
)
SP_GET:
BEGIN

	-- Status
	-- =========================================================================================
	DECLARE STATUS_INACTIVE TINYINT DEFAULT 1;
	DECLARE STATUS_ACTIVE TINYINT DEFAULT 2;
	DECLARE STATUS_CLOSED TINYINT DEFAULT 3;
	DECLARE STATUS_COMPLETED TINYINT DEFAULT 4;
	
	-- Audit Handler
	-- =========================================================================================
	DECLARE TEMP_RECORD_EXISTS BIT DEFAULT 0;
	DECLARE TEMP_MODULE_KEYWORD VARCHAR(500) DEFAULT 'system_status';
	DECLARE TEMP_SP_OBJECTIVE VARCHAR(500) DEFAULT 'Retrieve Status record';
	DECLARE TEMP_ERR_MESSAGE VARCHAR(500) DEFAULT '';
	DECLARE ERR BIGINT DEFAULT 0;
	DECLARE TEMP_RECORD_CHANGES VARCHAR(16000) DEFAULT '';
	DECLARE TEMP_RECORD_BINDED BIT DEFAULT 0;
	
	DECLARE TEMP_RECORD_BINDED_ID BIGINT DEFAULT 0;
	DECLARE TEMP_RECORD_BINDED_SERVER_ID BIGINT DEFAULT 0;
	
	-- Authentication
	-- =========================================================================================
	DECLARE TEMP_ACCESS_RIGHTS_DENIED BIT DEFAULT 0;
	DECLARE TEMP_AUTHENTICATED_ACCOUNT_ID BIGINT DEFAULT `ACCOUNT_MEMBER@ACC_ACCOUNT_ID_FROM_LOGIN`(PARAM_REQUESTER_USERNAME, PARAM_REQUESTER_PASSWORD);
	DECLARE TEMP_AUTHENTICATED_ACCOUNT_LEVEL BIGINT DEFAULT 0;
	DECLARE TEMP_AUTHENTICATED_ACCOUNT_GROUP BIGINT DEFAULT 0;
	
	-- Local Parameters
	-- =========================================================================================
	DECLARE TEMP_NOW DATETIME(6) DEFAULT `SYSTEM_VAR@NOW`('', 1);
	DECLARE TEMP_RECORD_COUNT BIGINT DEFAULT 0;
	
	
	-- Check NULLs
	-- =========================================================================================
	DECLARE IS_NULL_SYS_STATUS_ID BIT DEFAULT `SYSTEM_VAR@IS_NULL@BIGINT`(PARAM_SYS_STATUS_ID, 1, 1);
	DECLARE IS_NULL_SYS_STATUS_DESCRIPTION BIT DEFAULT `SYSTEM_VAR@IS_NULL@NVARCHAR`(PARAM_SYS_STATUS_DESCRIPTION, 1);
	DECLARE IS_NULL_SYS_STATUS_DESCRIPTION_2 BIT DEFAULT `SYSTEM_VAR@IS_NULL@NVARCHAR`(PARAM_SYS_STATUS_DESCRIPTION_2, 1);
	DECLARE IS_NULL_SYS_STATUS_DESCRIPTION_3 BIT DEFAULT `SYSTEM_VAR@IS_NULL@NVARCHAR`(PARAM_SYS_STATUS_DESCRIPTION_3, 1);
	DECLARE IS_NULL_SYS_STATUS_STATUS BIT DEFAULT `SYSTEM_VAR@IS_NULL@TINYINT`(PARAM_SYS_STATUS_STATUS, 1, 1);
	
	-- Error Handler
	-- =========================================================================================
	DECLARE EXIT HANDLER FOR SQLEXCEPTION
	BEGIN
		RESIGNAL;
	END;
	
	-- Ignore Time from DateTime (Set Time 00:00:00.000000 and 23:59:59.999999)
	-- =========================================================================================
		
		
	-- Access Rights [Device]
	-- =========================================================================================

		
	-- Access Rights [Account]
	-- =========================================================================================
		
	
	
	
	-- COUNT RECORD
	-- =========================================================================================
	
	-- SELECT COLUMNS
	-- ####################################################
	SELECT
		COUNT(DISTINCT `system_status`.`SYS_STATUS_ID`)
	INTO
		TEMP_RECORD_COUNT

	FROM `system_status`
	
		-- Add Inner Joins (Per Foreign-key)
		
		-- Add Optional Left Joins (Per Optional Foreign-key)
		
	-- CONDITIONS
	-- ####################################################
	WHERE
		(
			IS_NULL_SYS_STATUS_ID = 1 OR
			`system_status`.`SYS_STATUS_ID` = PARAM_SYS_STATUS_ID			
		) AND
		(
			IS_NULL_SYS_STATUS_DESCRIPTION = 1 OR
			`system_status`.`SYS_STATUS_DESCRIPTION` LIKE CONCAT_WS('%', '', PARAM_SYS_STATUS_DESCRIPTION, '')			
		) AND 		
		(
			IS_NULL_SYS_STATUS_DESCRIPTION_2 = 1 OR
			`system_status`.`SYS_STATUS_DESCRIPTION_2` LIKE CONCAT_WS('%', '', PARAM_SYS_STATUS_DESCRIPTION_2, '')			
		) AND 		
		(
			IS_NULL_SYS_STATUS_DESCRIPTION_3 = 1 OR
			`system_status`.`SYS_STATUS_DESCRIPTION_3` LIKE CONCAT_WS('%', '', PARAM_SYS_STATUS_DESCRIPTION_3, '')			
		) AND 		
		(
			IS_NULL_SYS_STATUS_STATUS = 1 OR
			`system_status`.`SYS_STATUS_STATUS` = PARAM_SYS_STATUS_STATUS			
		) 
;	

		
		
	-- SELECT RECORDS
	-- =========================================================================================
	
	-- FETCH COLUMNS
	-- ####################################################
	SELECT
		-- SYSTEM_STATUS DETAILS
		`system_status`.`SYS_STATUS_ID`, 
		`system_status`.`SYS_STATUS_DESCRIPTION`, 
		`system_status`.`SYS_STATUS_DESCRIPTION_2`, 
		`system_status`.`SYS_STATUS_DESCRIPTION_3`, 
		`system_status`.`SYS_STATUS_STATUS`
		
		-- Inner join fields
		
		-- Left join fields
		
		, TEMP_RECORD_COUNT AS RECORD_COUNT

	FROM `system_status`
	
		-- Add Inner Joins (Per Foreign-key)
		
		-- Add Optional Left Joins (Per Optional Foreign-key)
		
	-- CONDITIONS
	-- ####################################################
	WHERE
		(
			IS_NULL_SYS_STATUS_ID = 1 OR
			`system_status`.`SYS_STATUS_ID` = PARAM_SYS_STATUS_ID			
		) AND
		(
			IS_NULL_SYS_STATUS_DESCRIPTION = 1 OR
			`system_status`.`SYS_STATUS_DESCRIPTION` LIKE CONCAT_WS('%', '', PARAM_SYS_STATUS_DESCRIPTION, '')			
		) AND 		
		(
			IS_NULL_SYS_STATUS_DESCRIPTION_2 = 1 OR
			`system_status`.`SYS_STATUS_DESCRIPTION_2` LIKE CONCAT_WS('%', '', PARAM_SYS_STATUS_DESCRIPTION_2, '')			
		) AND 		
		(
			IS_NULL_SYS_STATUS_DESCRIPTION_3 = 1 OR
			`system_status`.`SYS_STATUS_DESCRIPTION_3` LIKE CONCAT_WS('%', '', PARAM_SYS_STATUS_DESCRIPTION_3, '')			
		) AND 		
		(
			IS_NULL_SYS_STATUS_STATUS = 1 OR
			`system_status`.`SYS_STATUS_STATUS` = PARAM_SYS_STATUS_STATUS			
		) 

	-- ORDER BY
	-- ####################################################
	ORDER BY
		-- SYSTEM_STATUS DETAILS
		CASE WHEN PARAM_ORDER_FIELD = 'SYS_STATUS_ID' AND PARAM_ORDER_TYPE = 'ASC' THEN `system_status`.`SYS_STATUS_ID` END ASC, 
		CASE WHEN PARAM_ORDER_FIELD = 'SYS_STATUS_ID' AND PARAM_ORDER_TYPE = 'DESC' THEN `system_status`.`SYS_STATUS_ID` END DESC,	
		CASE WHEN PARAM_ORDER_FIELD = 'SYS_STATUS_DESCRIPTION' AND PARAM_ORDER_TYPE = 'ASC' THEN `system_status`.`SYS_STATUS_DESCRIPTION` END ASC, 
		CASE WHEN PARAM_ORDER_FIELD = 'SYS_STATUS_DESCRIPTION' AND PARAM_ORDER_TYPE = 'DESC' THEN `system_status`.`SYS_STATUS_DESCRIPTION` END DESC,	
		CASE WHEN PARAM_ORDER_FIELD = 'SYS_STATUS_DESCRIPTION_2' AND PARAM_ORDER_TYPE = 'ASC' THEN `system_status`.`SYS_STATUS_DESCRIPTION_2` END ASC, 
		CASE WHEN PARAM_ORDER_FIELD = 'SYS_STATUS_DESCRIPTION_2' AND PARAM_ORDER_TYPE = 'DESC' THEN `system_status`.`SYS_STATUS_DESCRIPTION_2` END DESC,	
		CASE WHEN PARAM_ORDER_FIELD = 'SYS_STATUS_DESCRIPTION_3' AND PARAM_ORDER_TYPE = 'ASC' THEN `system_status`.`SYS_STATUS_DESCRIPTION_3` END ASC, 
		CASE WHEN PARAM_ORDER_FIELD = 'SYS_STATUS_DESCRIPTION_3' AND PARAM_ORDER_TYPE = 'DESC' THEN `system_status`.`SYS_STATUS_DESCRIPTION_3` END DESC,	
		CASE WHEN PARAM_ORDER_FIELD = 'SYS_STATUS_STATUS' AND PARAM_ORDER_TYPE = 'ASC' THEN `system_status`.`SYS_STATUS_STATUS` END ASC, 
		CASE WHEN PARAM_ORDER_FIELD = 'SYS_STATUS_STATUS' AND PARAM_ORDER_TYPE = 'DESC' THEN `system_status`.`SYS_STATUS_STATUS` END DESC,	

		-- Inner joins
		
		-- EXTRA
		CASE WHEN PARAM_ORDER_FIELD <> 'SYS_STATUS_DESCRIPTION' THEN `system_status`.`SYS_STATUS_DESCRIPTION` END ASC
		
	-- LIMIT & OFFSET
	-- ####################################################		
	LIMIT PARAM_SKIP, PARAM_LIMIT;
	
	
	
	-- EXIT PROCEDURE
	-- =========================================================================================
	LEAVE SP_GET;
			
END ;;
DELIMITER ;
/*!50003 SET sql_mode              = @saved_sql_mode */ ;
/*!50003 SET character_set_client  = @saved_cs_client */ ;
/*!50003 SET character_set_results = @saved_cs_results */ ;
/*!50003 SET collation_connection  = @saved_col_connection */ ;
/*!50003 DROP PROCEDURE IF EXISTS `VALIDATION_DELETE_LINKED_RECORD` */;
/*!50003 SET @saved_cs_client      = @@character_set_client */ ;
/*!50003 SET @saved_cs_results     = @@character_set_results */ ;
/*!50003 SET @saved_col_connection = @@collation_connection */ ;
/*!50003 SET character_set_client  = latin1 */ ;
/*!50003 SET character_set_results = latin1 */ ;
/*!50003 SET collation_connection  = latin1_swedish_ci */ ;
/*!50003 SET @saved_sql_mode       = @@sql_mode */ ;
/*!50003 SET sql_mode              = '' */ ;
DELIMITER ;;
CREATE DEFINER=`root`@`localhost` PROCEDURE `VALIDATION_DELETE_LINKED_RECORD`(
	IN `PARAM_FIELD_NAME` VARCHAR(4000),
	IN `PARAM_ENTRY_ID` VARCHAR(500),
	IN `PARAM_ENTRY_DESCRIPTION` VARCHAR(8000)
)
SP_SAVE:
BEGIN

	-- Initialize
	-- =================================================
	DECLARE TEMP_ERR_MESSAGE VARCHAR(16000) DEFAULT '';
	DECLARE ERR BIGINT DEFAULT 0;
	-- =================================================
	
	-- 2) Try Catch / Throw
	-- ====================================================================================================================================================================
	DECLARE EXIT HANDLER FOR SQLEXCEPTION
	BEGIN
		RESIGNAL;
	END;
	-- ====================================================================================================================================================================

	SET TEMP_ERR_MESSAGE = CONCAT_WS(' ', 'Cannot delete', PARAM_FIELD_NAME, 'which is already linked with other records.', PARAM_ENTRY_ID, '(', PARAM_ENTRY_DESCRIPTION, ')');
	SET ERR = `RAISERROR`(TEMP_ERR_MESSAGE);
		
END ;;
DELIMITER ;
/*!50003 SET sql_mode              = @saved_sql_mode */ ;
/*!50003 SET character_set_client  = @saved_cs_client */ ;
/*!50003 SET character_set_results = @saved_cs_results */ ;
/*!50003 SET collation_connection  = @saved_col_connection */ ;
/*!50003 DROP PROCEDURE IF EXISTS `VALIDATION_MISSING_FIELD` */;
/*!50003 SET @saved_cs_client      = @@character_set_client */ ;
/*!50003 SET @saved_cs_results     = @@character_set_results */ ;
/*!50003 SET @saved_col_connection = @@collation_connection */ ;
/*!50003 SET character_set_client  = latin1 */ ;
/*!50003 SET character_set_results = latin1 */ ;
/*!50003 SET collation_connection  = latin1_swedish_ci */ ;
/*!50003 SET @saved_sql_mode       = @@sql_mode */ ;
/*!50003 SET sql_mode              = '' */ ;
DELIMITER ;;
CREATE DEFINER=`root`@`localhost` PROCEDURE `VALIDATION_MISSING_FIELD`(
	IN `PARAM_FIELD_NAME` VARCHAR(4000),
	IN `PARAM_ENTRY_NAME` VARCHAR(8000)
)
SP_SAVE:
BEGIN

	-- Initialize
	-- =================================================
	DECLARE TEMP_ERR_MESSAGE VARCHAR(16000) DEFAULT '';
	DECLARE ERR BIGINT DEFAULT 0;
	-- =================================================
	
	-- 2) Try Catch / Throw
	-- ====================================================================================================================================================================
	DECLARE EXIT HANDLER FOR SQLEXCEPTION
	BEGIN
		RESIGNAL;
	END;
	-- ====================================================================================================================================================================

	SET TEMP_ERR_MESSAGE = CONCAT_WS(' ', 'Missing entry found ', PARAM_FIELD_NAME, 'in:', PARAM_ENTRY_NAME);
	SET ERR = `RAISERROR`(TEMP_ERR_MESSAGE);
		
END ;;
DELIMITER ;
/*!50003 SET sql_mode              = @saved_sql_mode */ ;
/*!50003 SET character_set_client  = @saved_cs_client */ ;
/*!50003 SET character_set_results = @saved_cs_results */ ;
/*!50003 SET collation_connection  = @saved_col_connection */ ;
/*!50003 DROP PROCEDURE IF EXISTS `VALIDATION_NEGATIVE` */;
/*!50003 SET @saved_cs_client      = @@character_set_client */ ;
/*!50003 SET @saved_cs_results     = @@character_set_results */ ;
/*!50003 SET @saved_col_connection = @@collation_connection */ ;
/*!50003 SET character_set_client  = latin1 */ ;
/*!50003 SET character_set_results = latin1 */ ;
/*!50003 SET collation_connection  = latin1_swedish_ci */ ;
/*!50003 SET @saved_sql_mode       = @@sql_mode */ ;
/*!50003 SET sql_mode              = '' */ ;
DELIMITER ;;
CREATE DEFINER=`root`@`localhost` PROCEDURE `VALIDATION_NEGATIVE`(
	IN `PARAM_FIELD_NAME` VARCHAR(4000),
	IN `PARAM_ENTRY_VALUE` VARCHAR(8000)
)
SP_SAVE:
BEGIN

	-- Initialize
	-- =================================================
	DECLARE TEMP_ERR_MESSAGE VARCHAR(16000) DEFAULT '';
	DECLARE ERR BIGINT DEFAULT 0;
	-- =================================================
	
	-- 2) Try Catch / Throw
	-- ====================================================================================================================================================================
	DECLARE EXIT HANDLER FOR SQLEXCEPTION
	BEGIN
		RESIGNAL;
	END;
	-- ====================================================================================================================================================================

	SET TEMP_ERR_MESSAGE = CONCAT_WS(' ', 'Cannot assign negative value to ', PARAM_FIELD_NAME, '. Given:', PARAM_ENTRY_VALUE);
	SET ERR = `RAISERROR`(TEMP_ERR_MESSAGE);
		
END ;;
DELIMITER ;
/*!50003 SET sql_mode              = @saved_sql_mode */ ;
/*!50003 SET character_set_client  = @saved_cs_client */ ;
/*!50003 SET character_set_results = @saved_cs_results */ ;
/*!50003 SET collation_connection  = @saved_col_connection */ ;
/*!50003 DROP PROCEDURE IF EXISTS `VALIDATION_REDUNDANT_ENTRY` */;
/*!50003 SET @saved_cs_client      = @@character_set_client */ ;
/*!50003 SET @saved_cs_results     = @@character_set_results */ ;
/*!50003 SET @saved_col_connection = @@collation_connection */ ;
/*!50003 SET character_set_client  = latin1 */ ;
/*!50003 SET character_set_results = latin1 */ ;
/*!50003 SET collation_connection  = latin1_swedish_ci */ ;
/*!50003 SET @saved_sql_mode       = @@sql_mode */ ;
/*!50003 SET sql_mode              = '' */ ;
DELIMITER ;;
CREATE DEFINER=`root`@`localhost` PROCEDURE `VALIDATION_REDUNDANT_ENTRY`(
	IN PARAM_ENTRY_NAME VARCHAR(16000)
)
SP_SAVE:
BEGIN

	-- Initialize
	-- =================================================
	DECLARE TEMP_ERR_MESSAGE VARCHAR(16000) DEFAULT '';
	DECLARE ERR BIGINT DEFAULT 0;
	-- =================================================
	
	-- Error Handler
	-- =========================================================================================
	DECLARE EXIT HANDLER FOR SQLEXCEPTION
	BEGIN
		RESIGNAL;
	END;

	SET TEMP_ERR_MESSAGE = CONCAT_WS(' ', 'Similar entry already exists in: ', PARAM_ENTRY_NAME);
	SET ERR = `RAISERROR`(TEMP_ERR_MESSAGE);

END ;;
DELIMITER ;
/*!50003 SET sql_mode              = @saved_sql_mode */ ;
/*!50003 SET character_set_client  = @saved_cs_client */ ;
/*!50003 SET character_set_results = @saved_cs_results */ ;
/*!50003 SET collation_connection  = @saved_col_connection */ ;
/*!50003 DROP PROCEDURE IF EXISTS `VALIDATION_SYSTEM_GENERATED` */;
/*!50003 SET @saved_cs_client      = @@character_set_client */ ;
/*!50003 SET @saved_cs_results     = @@character_set_results */ ;
/*!50003 SET @saved_col_connection = @@collation_connection */ ;
/*!50003 SET character_set_client  = latin1 */ ;
/*!50003 SET character_set_results = latin1 */ ;
/*!50003 SET collation_connection  = latin1_swedish_ci */ ;
/*!50003 SET @saved_sql_mode       = @@sql_mode */ ;
/*!50003 SET sql_mode              = '' */ ;
DELIMITER ;;
CREATE DEFINER=`root`@`localhost` PROCEDURE `VALIDATION_SYSTEM_GENERATED`(
	IN `PARAM_RECORD_ID` BIGINT,
	IN `PARAM_RECORD_DESCRIPTION` VARCHAR(16000),
	IN `PARAM_EXCEPTION` VARCHAR(16000)
)
SP_SAVE:
BEGIN

	-- Initialize
	-- =================================================
	DECLARE TEMP_ERR_MESSAGE VARCHAR(16000) DEFAULT '';
	DECLARE ERR BIGINT DEFAULT 0;
	-- =================================================
	
	
	-- Error Handler
	-- =========================================================================================
	DECLARE EXIT HANDLER FOR SQLEXCEPTION
	BEGIN
		RESIGNAL;
	END;


	SET TEMP_ERR_MESSAGE = CONCAT_WS(' ', 'Not allowed to edit/delete system generated contents:', PARAM_RECORD_ID, '("', PARAM_RECORD_DESCRIPTION, '")');
	IF CHAR_LENGTH(PARAM_EXCEPTION) > 1 THEN
		SET TEMP_ERR_MESSAGE = CONCAT_WS(' ', TEMP_ERR_MESSAGE, '. Except:', PARAM_EXCEPTION);
	END IF;

	SET ERR = `RAISERROR`(TEMP_ERR_MESSAGE);


END ;;
DELIMITER ;
/*!50003 SET sql_mode              = @saved_sql_mode */ ;
/*!50003 SET character_set_client  = @saved_cs_client */ ;
/*!50003 SET character_set_results = @saved_cs_results */ ;
/*!50003 SET collation_connection  = @saved_col_connection */ ;
/*!50003 DROP PROCEDURE IF EXISTS `VALIDATION_UNAVAILABLE_RECORD` */;
/*!50003 SET @saved_cs_client      = @@character_set_client */ ;
/*!50003 SET @saved_cs_results     = @@character_set_results */ ;
/*!50003 SET @saved_col_connection = @@collation_connection */ ;
/*!50003 SET character_set_client  = latin1 */ ;
/*!50003 SET character_set_results = latin1 */ ;
/*!50003 SET collation_connection  = latin1_swedish_ci */ ;
/*!50003 SET @saved_sql_mode       = @@sql_mode */ ;
/*!50003 SET sql_mode              = '' */ ;
DELIMITER ;;
CREATE DEFINER=`root`@`localhost` PROCEDURE `VALIDATION_UNAVAILABLE_RECORD`(
	IN `PARAM_FIELD_NAME` VARCHAR(500),
	IN `PARAM_ENTRY_ID` VARCHAR(500),
	IN `PARAM_ENTRY_DESCRIPTION` VARCHAR(2000)
)
SP_SAVE:
BEGIN

	-- Initialize
	-- =================================================
	DECLARE TEMP_ERR_MESSAGE VARCHAR(16000) DEFAULT '';
	DECLARE ERR BIGINT DEFAULT 0;
	
	
	-- 2) Try Catch / Throw
	-- ====================================================================================================================================================================
	DECLARE EXIT HANDLER FOR SQLEXCEPTION
	BEGIN
		RESIGNAL;
	END;
	
	
	-- RAISE ERROR
	-- ====================================================================================================================================================================
	IF `SYSTEM_VAR@IS_NULL@NVARCHAR`(PARAM_ENTRY_DESCRIPTION, 1) = 0 THEN
		SET TEMP_ERR_MESSAGE = CONCAT_WS(' ', 'Given', PARAM_FIELD_NAME, 'does not exists or is inactive.', PARAM_ENTRY_ID, '(', PARAM_ENTRY_DESCRIPTION, ')');
	ELSE
		SET TEMP_ERR_MESSAGE = CONCAT_WS(' ', 'Given', PARAM_FIELD_NAME, 'does not exists or is inactive.', PARAM_ENTRY_ID);
	END IF;
	
	SET ERR = `RAISERROR`(TEMP_ERR_MESSAGE);
		
END ;;
DELIMITER ;
/*!50003 SET sql_mode              = @saved_sql_mode */ ;
/*!50003 SET character_set_client  = @saved_cs_client */ ;
/*!50003 SET character_set_results = @saved_cs_results */ ;
/*!50003 SET collation_connection  = @saved_col_connection */ ;
/*!50003 DROP PROCEDURE IF EXISTS `VALIDATION_UNEDITABLE` */;
/*!50003 SET @saved_cs_client      = @@character_set_client */ ;
/*!50003 SET @saved_cs_results     = @@character_set_results */ ;
/*!50003 SET @saved_col_connection = @@collation_connection */ ;
/*!50003 SET character_set_client  = latin1 */ ;
/*!50003 SET character_set_results = latin1 */ ;
/*!50003 SET collation_connection  = latin1_swedish_ci */ ;
/*!50003 SET @saved_sql_mode       = @@sql_mode */ ;
/*!50003 SET sql_mode              = '' */ ;
DELIMITER ;;
CREATE DEFINER=`root`@`localhost` PROCEDURE `VALIDATION_UNEDITABLE`(
	IN `PARAM_FIELD_NAME` VARCHAR(4000)
)
SP_SAVE:
BEGIN

	-- Initialize
	-- =================================================
	DECLARE TEMP_ERR_MESSAGE VARCHAR(16000) DEFAULT '';
	DECLARE ERR BIGINT DEFAULT 0;
	-- =================================================
	
	-- 2) Try Catch / Throw
	-- ====================================================================================================================================================================
	DECLARE EXIT HANDLER FOR SQLEXCEPTION
	BEGIN
		RESIGNAL;
	END;
	-- ====================================================================================================================================================================

	SET TEMP_ERR_MESSAGE = CONCAT_WS(' ', 'You have not enought rights to edit a value for ', PARAM_FIELD_NAME);
	SET ERR = `RAISERROR`(TEMP_ERR_MESSAGE);
		
END ;;
DELIMITER ;
/*!50003 SET sql_mode              = @saved_sql_mode */ ;
/*!50003 SET character_set_client  = @saved_cs_client */ ;
/*!50003 SET character_set_results = @saved_cs_results */ ;
/*!50003 SET collation_connection  = @saved_col_connection */ ;
/*!40103 SET TIME_ZONE=@OLD_TIME_ZONE */;

/*!40101 SET SQL_MODE=@OLD_SQL_MODE */;
/*!40014 SET FOREIGN_KEY_CHECKS=@OLD_FOREIGN_KEY_CHECKS */;
/*!40014 SET UNIQUE_CHECKS=@OLD_UNIQUE_CHECKS */;
/*!40101 SET CHARACTER_SET_CLIENT=@OLD_CHARACTER_SET_CLIENT */;
/*!40101 SET CHARACTER_SET_RESULTS=@OLD_CHARACTER_SET_RESULTS */;
/*!40101 SET COLLATION_CONNECTION=@OLD_COLLATION_CONNECTION */;
/*!40111 SET SQL_NOTES=@OLD_SQL_NOTES */;

-- Dump completed on 2021-01-20  1:11:47
