SET SQL_MODE = "NO_AUTO_VALUE_ON_ZERO";
SET time_zone = "+00:00";

/*!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 */;


DELIMITER $$
CREATE PROCEDURE `proc_delete_unit_safe` (IN `p_unit_id` CHAR(10), IN `p_productid` CHAR(30))   BEGIN
  DECLARE v_total BIGINT DEFAULT 0;
  -- hitung pemakaian (pakai query dinamis seperti sebelumnya)
  SET SESSION group_concat_max_len = 1000000;

  SELECT GROUP_CONCAT(
    CONCAT('SELECT COUNT(*) AS c FROM `', TABLE_NAME, '` WHERE `unit` = ', QUOTE(p_unit_id), ' AND `productid` = ', QUOTE(p_productid))
    SEPARATOR ' UNION ALL '
  ) INTO @sql
  FROM INFORMATION_SCHEMA.COLUMNS
  WHERE COLUMN_NAME='unit' AND TABLE_SCHEMA = DATABASE();

  IF @sql IS NOT NULL AND @sql <> '' THEN
    SET @sql = CONCAT('SELECT SUM(c) INTO @total_used FROM (', @sql, ') x;');
    PREPARE s FROM @sql; EXECUTE s; DEALLOCATE PREPARE s;
    SET v_total = IFNULL(@total_used,0);
  END IF;
  SELECT v_total AS total_used;
END$$

CREATE PROCEDURE `proc_rename_unit_cascade` (IN `p_old_name` CHAR(10), IN `p_new_name` VARCHAR(10), IN `p_productid` CHAR(30))   BEGIN
  DECLARE done INT DEFAULT 0;
  DECLARE v_table VARCHAR(64);

  DECLARE cur CURSOR FOR
    SELECT c1.TABLE_NAME
    FROM INFORMATION_SCHEMA.COLUMNS c1
    JOIN INFORMATION_SCHEMA.COLUMNS c2
      ON c2.TABLE_SCHEMA = c1.TABLE_SCHEMA
     AND c2.TABLE_NAME   = c1.TABLE_NAME
     AND c2.COLUMN_NAME  = 'productid'
    WHERE c1.TABLE_SCHEMA = DATABASE()
      AND c1.COLUMN_NAME  = 'unit'
    GROUP BY c1.TABLE_NAME;

  DECLARE CONTINUE HANDLER FOR NOT FOUND SET done = 1;

  START TRANSACTION;

  OPEN cur;

  read_loop: LOOP
    FETCH cur INTO v_table;
    IF done = 1 THEN
      LEAVE read_loop;
    END IF;

    SET @sql = CONCAT(
      'UPDATE `', REPLACE(v_table,'`','``'), '` ',
      'SET `unit` = ', QUOTE(p_new_name),
      ' WHERE `unit` = ', QUOTE(p_old_name),
      ' AND `productid` = ', QUOTE(p_productid)
    );

    PREPARE s FROM @sql;
    EXECUTE s;
    DEALLOCATE PREPARE s;
  END LOOP;

  CLOSE cur;

  COMMIT;
END$$

CREATE PROCEDURE `sp_sales_pivot_month_division` (IN `p_from` DATE, IN `p_to` DATE)   BEGIN
  DECLARE v_cols LONGTEXT;
  DECLARE v_sql  LONGTEXT;

  SET @from := p_from;
  SET @to_exclusive := DATE_ADD(p_to, INTERVAL 1 DAY);

  SET SESSION group_concat_max_len = 1000000;

  /* 1. Kolom pivot per division (dinamis) */
  SELECT GROUP_CONCAT(
           DISTINCT CONCAT(
             'SUM(CASE WHEN s.division = ', QUOTE(d.id),
             ' THEN IF(s.kind=0, s.salestotal, -s.salestotal) ELSE 0 END) AS `',
             REPLACE(d.description,'`',''), '`'
           )
           ORDER BY d.description
           SEPARATOR ', '
         )
  INTO v_cols
  FROM division d
  JOIN sales s
    ON s.division = d.id
   AND s.salesdate >= @from
   AND s.salesdate <  @to_exclusive;

  /* 2. Query utama + kolom TOTAL */
  IF v_cols IS NULL OR v_cols = '' THEN
    SET v_sql = 'SELECT NULL AS `month`, NULL AS `Total` WHERE ? IS NOT NULL AND ? IS NOT NULL AND 1=0';
  ELSE
    SET v_sql = CONCAT(
      'SELECT DATE_FORMAT(s.salesdate, ''%b-%y'') AS `month`, ',
      v_cols, ',
      SUM(IF(s.kind=0, s.salestotal, -s.salestotal)) AS `Total`
      FROM sales s
      JOIN division d ON d.id = s.division
      WHERE s.salesdate >= ? AND s.salesdate < ?
      GROUP BY DATE_FORMAT(s.salesdate, ''%b-%y'')
      ORDER BY DATE_FORMAT(s.salesdate, ''%Y-%m'')'
    );
  END IF;

  SET @sql := v_sql;
  PREPARE stmt FROM @sql;
  EXECUTE stmt USING @from, @to_exclusive;
  DEALLOCATE PREPARE stmt;
END$$

CREATE PROCEDURE `sp_sales_pivot_year_division` (IN `p_year_from` INT, IN `p_year_to` INT)   BEGIN
  DECLARE v_cols LONGTEXT;
  DECLARE v_sql  LONGTEXT;

  SET @year_from := p_year_from;
  SET @year_to   := p_year_to;

  SET SESSION group_concat_max_len = 1000000;

  /* 1. Kolom pivot per division (dinamis) */
  SELECT GROUP_CONCAT(
           DISTINCT CONCAT(
             'SUM(CASE WHEN s.division = ', QUOTE(d.id),
             ' THEN IF(s.kind=0, s.salestotal, -s.salestotal) ELSE 0 END) AS `',
             REPLACE(d.description,'`',''), '`'
           )
           ORDER BY d.description
           SEPARATOR ', '
         )
  INTO v_cols
  FROM division d
  JOIN sales s
    ON s.division = d.id
   AND YEAR(s.salesdate) BETWEEN @year_from AND @year_to;

  /* 2. Query utama + kolom TOTAL */
  IF v_cols IS NULL OR v_cols = '' THEN

    SET v_sql = 'SELECT NULL AS `year`, NULL AS `Total` WHERE ? IS NOT NULL AND ? IS NOT NULL AND 1=0';

  ELSE

    SET v_sql = CONCAT(
      'SELECT 
         YEAR(s.salesdate) AS `year`, ',
         v_cols, ',
         SUM(IF(s.kind=0, s.salestotal, -s.salestotal)) AS `Total`
       FROM sales s
       JOIN division d ON d.id = s.division
       WHERE YEAR(s.salesdate) BETWEEN ? AND ?
       GROUP BY YEAR(s.salesdate)
       ORDER BY YEAR(s.salesdate)'
    );

  END IF;
  SET @sql := v_sql;
  PREPARE stmt FROM @sql;
  IF v_cols IS NULL OR v_cols = '' THEN
    EXECUTE stmt;
  ELSE
    EXECUTE stmt USING @year_from, @year_to;
  END IF;

  DEALLOCATE PREPARE stmt;

END$$

DELIMITER ;

CREATE TABLE `account` (
  `id` char(30) NOT NULL DEFAULT '',
  `name` varchar(150) NOT NULL DEFAULT '',
  `accountgroup` char(30) NOT NULL DEFAULT '',
  `accountcategory` tinyint(4) NOT NULL DEFAULT 0,
  `accounttype` tinyint(4) DEFAULT NULL,
  `isgroup` tinyint(1) NOT NULL DEFAULT 0,
  `usercreate` char(16) NOT NULL DEFAULT '',
  `useredit` char(16) NOT NULL DEFAULT '',
  `updatetimestamp` timestamp NOT NULL DEFAULT current_timestamp() ON UPDATE current_timestamp()
) ENGINE=InnoDB DEFAULT CHARSET=utf8mb4 COLLATE=utf8mb4_unicode_ci;

CREATE TABLE `address` (
  `id` bigint(20) UNSIGNED NOT NULL,
  `addresslabel` varchar(50) NOT NULL DEFAULT 'Rumah',
  `country` int(11) NOT NULL DEFAULT 0,
  `countryname` varchar(50) NOT NULL DEFAULT '',
  `province` int(11) NOT NULL DEFAULT 0,
  `provincename` varchar(50) NOT NULL DEFAULT '',
  `city` int(11) NOT NULL DEFAULT 0,
  `cityname` varchar(50) NOT NULL DEFAULT '',
  `subdistrict` int(11) NOT NULL DEFAULT 0,
  `subdistrictname` varchar(50) NOT NULL DEFAULT '',
  `address` text DEFAULT NULL,
  `postal_code` varchar(50) NOT NULL DEFAULT ''
) ENGINE=InnoDB DEFAULT CHARSET=utf8mb4 COLLATE=utf8mb4_unicode_ci;

CREATE TABLE `attendance` (
  `id` bigint(20) UNSIGNED NOT NULL,
  `employeeid` char(30) NOT NULL DEFAULT '',
  `name` varchar(100) NOT NULL DEFAULT '',
  `checkin` datetime DEFAULT NULL,
  `checkout` datetime DEFAULT NULL,
  `notes` varchar(255) DEFAULT '',
  `workinghourid` bigint(20) NOT NULL,
  `late` int(11) DEFAULT NULL,
  `overtime` float DEFAULT NULL,
  `workinghour` float DEFAULT NULL,
  `imagecheckin` varchar(255) DEFAULT '[]',
  `imagecheckout` varchar(255) DEFAULT '[]',
  `latitudecheckin` float DEFAULT NULL,
  `longitudecheckin` float DEFAULT NULL,
  `latitudecheckout` float DEFAULT NULL,
  `longitudecheckout` float DEFAULT NULL,
  `kioskdeviceid` bigint(20) UNSIGNED DEFAULT NULL,
  `verifymethod` varchar(30) NOT NULL DEFAULT '',
  `verifyscore` decimal(10,6) DEFAULT NULL,
  `verifylivenessscore` decimal(10,6) DEFAULT NULL,
  `usercreate` char(16) NOT NULL DEFAULT '',
  `useredit` char(16) NOT NULL DEFAULT '',
  `cancelled` tinyint(1) NOT NULL DEFAULT 0,
  `updatetimestamp` timestamp NOT NULL DEFAULT current_timestamp() ON UPDATE current_timestamp()
) ENGINE=InnoDB DEFAULT CHARSET=utf8mb4 COLLATE=utf8mb4_unicode_ci;

CREATE TABLE `attendancekioskdevice` (
  `id` bigint(20) UNSIGNED NOT NULL,
  `name` varchar(100) NOT NULL DEFAULT '',
  `employeegroup` varchar(512) NOT NULL DEFAULT '[]',
  `locationname` varchar(150) NOT NULL DEFAULT '',
  `latitude` decimal(10,7) NOT NULL DEFAULT 0.0000000,
  `longitude` decimal(10,7) NOT NULL DEFAULT 0.0000000,
  `isactive` smallint(6) NOT NULL DEFAULT 1,
  `engineprovider` varchar(30) NOT NULL DEFAULT 'face_api',
  `adminpin` varchar(10) NOT NULL DEFAULT '0000',
  `scanidwithcamera` smallint(6) NOT NULL DEFAULT 0,
  `allowplaceholderverify` smallint(6) NOT NULL DEFAULT 0,
  `engineconfig` text NOT NULL DEFAULT '',
  `additionalinfo` mediumtext NOT NULL DEFAULT '',
  `notes` varchar(255) DEFAULT '',
  `usercreate` char(16) NOT NULL DEFAULT '',
  `useredit` char(16) NOT NULL DEFAULT '',
  `updatetimestamp` timestamp NOT NULL DEFAULT current_timestamp() ON UPDATE current_timestamp()
) ENGINE=InnoDB DEFAULT CHARSET=utf8mb4 COLLATE=utf8mb4_unicode_ci;

INSERT INTO `attendancekioskdevice` (`id`, `name`, `employeegroup`, `locationname`, `latitude`, `longitude`, `isactive`, `engineprovider`, `adminpin`, `scanidwithcamera`, `allowplaceholderverify`, `engineconfig`, `additionalinfo`, `notes`, `usercreate`, `useredit`, `updatetimestamp`) VALUES
(1, 'Default Attendance Kiosk', '[]', '', 0.0000000, 0.0000000, 1, 'face_api', '0000', 1, 0, '', '<div style=\"font-family: Arial, sans-serif; color: #1f2937; line-height: 1.5;\"><h3 style=\"margin: 0 0 8px; font-size: 18px;\">Welcome to the Attendance Kiosk</h3><p style=\"margin: 0 0 10px;\">Please follow these steps before submitting your attendance:</p><ol style=\"margin: 0 0 10px 18px; padding: 0;\"><li>Scan or enter your employee ID.</li><li>Look at the camera and follow the verification instruction.</li><li>Wait for the confirmation message before leaving.</li></ol><p style=\"margin: 0; font-size: 13px; color: #4b5563;\">If you need help, please contact your supervisor or HR team.</p></div>', '', 'system', 'system', '2026-05-16 16:49:38');

CREATE TABLE `attendanceverifylog` (
  `id` bigint(20) UNSIGNED NOT NULL,
  `employeeid` char(30) NOT NULL DEFAULT '',
  `attendanceid` bigint(20) UNSIGNED DEFAULT NULL,
  `kioskdeviceid` bigint(20) UNSIGNED DEFAULT NULL,
  `mode` varchar(20) NOT NULL DEFAULT '',
  `matchscore` decimal(10,6) DEFAULT NULL,
  `livenessscore` decimal(10,6) DEFAULT NULL,
  `challenge` varchar(100) NOT NULL DEFAULT '',
  `result` varchar(30) NOT NULL DEFAULT '',
  `snapshot` varchar(255) DEFAULT '',
  `notes` varchar(255) DEFAULT '',
  `usercreate` char(16) NOT NULL DEFAULT '',
  `useredit` char(16) NOT NULL DEFAULT '',
  `createdat` datetime NOT NULL DEFAULT current_timestamp(),
  `updatetimestamp` timestamp NOT NULL DEFAULT current_timestamp() ON UPDATE current_timestamp()
) ENGINE=InnoDB DEFAULT CHARSET=utf8mb4 COLLATE=utf8mb4_unicode_ci;

CREATE TABLE `authorityrequest` (
  `id` bigint(20) UNSIGNED NOT NULL,
  `userid` char(16) NOT NULL DEFAULT '',
  `touserid` char(16) NOT NULL DEFAULT '',
  `kind` char(6) NOT NULL DEFAULT '',
  `reference` char(30) NOT NULL DEFAULT '',
  `memo` varchar(50) NOT NULL DEFAULT '',
  `approved` tinyint(1) NOT NULL,
  `daterequest` datetime NOT NULL,
  `dateapproved` datetime DEFAULT NULL,
  `done` tinyint(1) NOT NULL DEFAULT 0
) ENGINE=InnoDB DEFAULT CHARSET=utf8mb4 COLLATE=utf8mb4_unicode_ci;

CREATE TABLE `authors` (
  `id` char(30) NOT NULL DEFAULT '',
  `name` varchar(100) NOT NULL DEFAULT '',
  `address` varchar(200) NOT NULL DEFAULT '',
  `usercreate` char(16) NOT NULL DEFAULT '',
  `useredit` char(16) NOT NULL DEFAULT '',
  `updatetimestamp` timestamp NOT NULL DEFAULT current_timestamp() ON UPDATE current_timestamp()
) ENGINE=InnoDB DEFAULT CHARSET=utf8mb4 COLLATE=utf8mb4_unicode_ci;

CREATE TABLE `cogs` (
  `id` bigint(20) UNSIGNED NOT NULL,
  `transid` char(30) NOT NULL DEFAULT '',
  `transdate` datetime DEFAULT NULL,
  `division` char(10) DEFAULT '',
  `productid` char(30) NOT NULL DEFAULT '',
  `snproduct` varchar(100) NOT NULL DEFAULT '',
  `expireddate` date DEFAULT NULL,
  `qty` double NOT NULL DEFAULT 0,
  `cost` double NOT NULL DEFAULT 0,
  `cogs` double NOT NULL DEFAULT 0,
  `usercreate` char(16) NOT NULL DEFAULT '',
  `useredit` char(16) NOT NULL DEFAULT '',
  `updatetimestamp` timestamp NOT NULL DEFAULT current_timestamp() ON UPDATE current_timestamp()
) ENGINE=InnoDB DEFAULT CHARSET=utf8mb4 COLLATE=utf8mb4_unicode_ci;

CREATE TABLE `company` (
  `id` int(11) NOT NULL DEFAULT 1,
  `name` varchar(200) NOT NULL DEFAULT '',
  `provincename` varchar(50) NOT NULL DEFAULT '',
  `cityname` varchar(50) NOT NULL DEFAULT '',
  `subdistrictname` varchar(50) NOT NULL DEFAULT '',
  `address` varchar(200) NOT NULL DEFAULT '',
  `country` char(3) NOT NULL DEFAULT '',
  `postcode` varchar(10) NOT NULL DEFAULT '',
  `telephone` varchar(45) NOT NULL DEFAULT '',
  `faximile` varchar(45) NOT NULL DEFAULT '',
  `email` varchar(100) NOT NULL DEFAULT '',
  `website` varchar(100) NOT NULL DEFAULT '',
  `motto` varchar(200) NOT NULL DEFAULT '',
  `taxid` varchar(100) NOT NULL DEFAULT '',
  `taxiddate` datetime DEFAULT NULL,
  `currentdate` date DEFAULT NULL,
  `defcurrency` char(3) NOT NULL DEFAULT '',
  `usercreate` char(16) NOT NULL DEFAULT '',
  `useredit` char(16) NOT NULL DEFAULT '',
  `updatetimestamp` timestamp NOT NULL DEFAULT current_timestamp() ON UPDATE current_timestamp(),
  `logo` text DEFAULT NULL,
  `general_log` tinyint(1) NOT NULL DEFAULT 0,
  `locationlat` double NOT NULL DEFAULT 0,
  `locationlng` double NOT NULL DEFAULT 0,
  `cachetype` int(11) NOT NULL DEFAULT 0,
  `layout` text NOT NULL,
  `customstyle` mediumtext DEFAULT NULL,
  `inventorytransferaccount` char(30) NOT NULL,
  `digitmoney` int(11) NOT NULL DEFAULT 0,
  `digitproduct` int(11) NOT NULL DEFAULT 0,
  `paypal_client_id` varchar(200) NOT NULL DEFAULT '',
  `paypal_secret` varchar(200) NOT NULL DEFAULT '',
  `paypal_sandbox` int(11) NOT NULL DEFAULT 1,
  `paypal_enabled` int(11) NOT NULL DEFAULT 0,
  `stripe_api_key` varchar(200) NOT NULL DEFAULT '',
  `stripe_secret` varchar(200) NOT NULL DEFAULT '',
  `stripe_sandbox` int(11) NOT NULL DEFAULT 1,
  `stripe_enabled` int(11) NOT NULL DEFAULT 0,
  `midtrans_server_key` varchar(200) NOT NULL DEFAULT '',
  `midtrans_client_key` varchar(200) NOT NULL DEFAULT '',
  `midtrans_sandbox` int(11) NOT NULL DEFAULT 1,
  `midtrans_enabled` int(11) NOT NULL DEFAULT 0,
  `timezone` varchar(100) NOT NULL DEFAULT 'Asia/Jakarta'
) ENGINE=InnoDB DEFAULT CHARSET=utf8mb4 COLLATE=utf8mb4_unicode_ci;

CREATE TABLE `countries` (
  `id` char(3) NOT NULL DEFAULT '',
  `country` varchar(100) NOT NULL DEFAULT '',
  `isactive` smallint(6) NOT NULL DEFAULT 1
) ENGINE=InnoDB DEFAULT CHARSET=utf8mb4 COLLATE=utf8mb4_unicode_ci;

INSERT INTO `countries` (`id`, `country`, `isactive`) VALUES
('ABW', 'Aruba', 0),
('AGO', 'Angola', 0),
('AIA', 'Anguilla', 0),
('ALB', 'Albania', 0),
('AND', 'Andorra', 0),
('ANT', 'Netherlands Antilles', 0),
('ARE', 'United Arab Emirates', 0),
('ARG', 'Argentina', 0),
('ARM', 'Armenia', 0),
('ASM', 'American Samoa', 0),
('ATA', 'Antarctica', 0),
('ATF', 'French Southern Lands', 0),
('ATG', 'Antigua and Barbuda', 0),
('AUS', 'Australia', 0),
('AUT', 'Austria', 0),
('AZE', 'Azerbaijan', 0),
('BDI', 'Burundi', 0),
('BEL', 'Belgium', 0),
('BEN', 'Benin', 0),
('BFA', 'Burkina Faso', 0),
('BGD', 'Bangladesh', 0),
('BGR', 'Bulgaria', 0),
('BHR', 'Bahrain', 0),
('BHS', 'Bahamas', 0),
('BIH', 'Bosnia and Herzegovina', 0),
('BLM', 'Saint Barthélemy', 0),
('BLR', 'Belarus', 0),
('BLZ', 'Belize', 0),
('BMU', 'Bermuda', 0),
('BOL', 'Bolivia', 0),
('BRA', 'Brazil', 0),
('BRB', 'Barbados', 0),
('BRN', 'Brunei Darussalam', 0),
('BTN', 'Bhutan', 0),
('BVT', 'Bouvet Island', 0),
('BWA', 'Botswana', 0),
('CAF', 'Central African Republic', 0),
('CAN', 'Canada', 0),
('CCK', 'Cocos (Keeling) Islands', 0),
('CHE', 'Switzerland', 0),
('CHL', 'Chile', 0),
('CHN', 'China', 0),
('CIV', 'Côte d\'Ivoire', 0),
('CMR', 'Cameroon', 0),
('COD', 'Congo (Kinshasa)', 0),
('COG', 'Congo (Brazzaville)', 0),
('COK', 'Cook Islands', 0),
('COL', 'Colombia', 0),
('COM', 'Comoros', 0),
('CPV', 'Cape Verde', 0),
('CRI', 'Costa Rica', 0),
('CUB', 'Cuba', 0),
('CXR', 'Christmas Island', 0),
('CYM', 'Cayman Islands', 0),
('CYP', 'Cyprus', 0),
('CZE', 'Czech Republic', 0),
('DEU', 'Germany', 0),
('DJI', 'Djibouti', 0),
('DMA', 'Dominica', 0),
('DNK', 'Denmark', 0),
('DOM', 'Dominican Republic', 0),
('DZA', 'Algeria', 0),
('ECU', 'Ecuador', 0),
('EGY', 'Egypt', 0),
('ERI', 'Eritrea', 0),
('ESH', 'Western Sahara', 0),
('ESP', 'Spain', 0),
('EST', 'Estonia', 0),
('ETH', 'Ethiopia', 0),
('FIN', 'Finland', 0),
('FJI', 'Fiji', 0),
('FLK', 'Falkland Islands', 0),
('FRA', 'France', 0),
('FRO', 'Faroe Islands', 0),
('FSM', 'Micronesia', 0),
('GAB', 'Gabon', 0),
('GBR', 'United Kingdom', 0),
('GEO', 'Georgia', 0),
('GGY', 'Guernsey', 0),
('GHA', 'Ghana', 0),
('GIB', 'Gibraltar', 0),
('GIN', 'Guinea', 0),
('GLP', 'Guadeloupe', 0),
('GMB', 'Gambia', 0),
('GNB', 'Guinea-Bissau', 0),
('GNQ', 'Equatorial Guinea', 0),
('GRC', 'Greece', 0),
('GRD', 'Grenada', 0),
('GRL', 'Greenland', 0),
('GTM', 'Guatemala', 0),
('GUF', 'French Guiana', 0),
('GUM', 'Guam', 0),
('GUY', 'Guyana', 0),
('HKG', 'Hong Kong', 0),
('HMD', 'Heard and McDonald Islands', 0),
('HND', 'Honduras', 0),
('HRV', 'Croatia', 0),
('HTI', 'Haiti', 0),
('HUN', 'Hungary', 0),
('IDN', 'Indonesia', 1),
('IMN', 'Isle of Man', 0),
('IND', 'India', 0),
('IOT', 'British Indian Ocean Territory', 0),
('IRL', 'Ireland', 0),
('IRN', 'Iran', 0),
('IRQ', 'Iraq', 0),
('ISL', 'Iceland', 0),
('ISR', 'Israel', 0),
('ITA', 'Italy', 0),
('JAM', 'Jamaica', 0),
('JEY', 'Jersey', 0),
('JOR', 'Jordan', 0),
('JPN', 'Japan', 0),
('KAZ', 'Kazakhstan', 0),
('KEN', 'Kenya', 0),
('KGZ', 'Kyrgyzstan', 0),
('KHM', 'Cambodia', 0),
('KIR', 'Kiribati', 0),
('KNA', 'Saint Kitts and Nevis', 0),
('KOR', 'Korea, South', 0),
('KWT', 'Kuwait', 0),
('LAO', 'Laos', 0),
('LBN', 'Lebanon', 0),
('LBR', 'Liberia', 0),
('LBY', 'Libya', 0),
('LCA', 'Saint Lucia', 0),
('LIE', 'Liechtenstein', 0),
('LKA', 'Sri Lanka', 0),
('LSO', 'Lesotho', 0),
('LTU', 'Lithuania', 0),
('LUX', 'Luxembourg', 0),
('LVA', 'Latvia', 0),
('MAC', 'Macau', 0),
('MAF', 'Saint Martin (French part)', 0),
('MAR', 'Morocco', 0),
('MCO', 'Monaco', 0),
('MDA', 'Moldova', 0),
('MDG', 'Madagascar', 0),
('MDV', 'Maldives', 0),
('MEX', 'Mexico', 0),
('MHL', 'Marshall Islands', 0),
('MKD', 'Macedonia', 0),
('MLI', 'Mali', 0),
('MLT', 'Malta', 0),
('MMR', 'Myanmar', 0),
('MNE', 'Montenegro', 0),
('MNG', 'Mongolia', 0),
('MNP', 'Northern Mariana Islands', 0),
('MOZ', 'Mozambique', 0),
('MRT', 'Mauritania', 0),
('MSR', 'Montserrat', 0),
('MTQ', 'Martinique', 0),
('MUS', 'Mauritius', 0),
('MWI', 'Malawi', 0),
('MYS', 'Malaysia', 0),
('MYT', 'Mayotte', 0),
('NAM', 'Namibia', 0),
('NCL', 'New Caledonia', 0),
('NER', 'Niger', 0),
('NFK', 'Norfolk Island', 0),
('NGA', 'Nigeria', 0),
('NIC', 'Nicaragua', 0),
('NIU', 'Niue', 0),
('NLD', 'Netherlands', 0),
('NOR', 'Norway', 0),
('NPL', 'Nepal', 0),
('NRU', 'Nauru', 0),
('NZL', 'New Zealand', 0),
('OMN', 'Oman', 0),
('PAK', 'Pakistan', 0),
('PAN', 'Panama', 0),
('PCN', 'Pitcairn', 0),
('PER', 'Peru', 0),
('PHL', 'Philippines', 0),
('PLW', 'Palau', 0),
('PNG', 'Papua New Guinea', 0),
('POL', 'Poland', 0),
('PRI', 'Puerto Rico', 0),
('PRK', 'Korea, North', 0),
('PRT', 'Portugal', 0),
('PRY', 'Paraguay', 0),
('PSE', 'Palestine', 0),
('PYF', 'French Polynesia', 0),
('QAT', 'Qatar', 0),
('REU', 'Reunion', 0),
('ROU', 'Romania', 0),
('RUS', 'Russian Federation', 0),
('RWA', 'Rwanda', 0),
('SAU', 'Saudi Arabia', 0),
('SDN', 'Sudan', 0),
('SEN', 'Senegal', 0),
('SGP', 'Singapore', 0),
('SGS', 'South Georgia and South Sandwich Islands', 0),
('SHN', 'Saint Helena', 0),
('SJM', 'Svalbard and Jan Mayen Islands', 0),
('SLB', 'Solomon Islands', 0),
('SLE', 'Sierra Leone', 0),
('SLV', 'El Salvador', 0),
('SMR', 'San Marino', 0),
('SOM', 'Somalia', 0),
('SPM', 'Saint Pierre and Miquelon', 0),
('SRB', 'Serbia', 0),
('STP', 'Sao Tome and Principe', 0),
('SUR', 'Suriname', 0),
('SVK', 'Slovakia', 0),
('SVN', 'Slovenia', 0),
('SWE', 'Sweden', 0),
('SWZ', 'Swaziland', 0),
('SYC', 'Seychelles', 0),
('SYR', 'Syria', 0),
('TCA', 'Turks and Caicos Islands', 0),
('TCD', 'Chad', 0),
('TGO', 'Togo', 0),
('THA', 'Thailand', 0),
('TJK', 'Tajikistan', 0),
('TKL', 'Tokelau', 0),
('TKM', 'Turkmenistan', 0),
('TLS', 'Timor-Leste', 0),
('TON', 'Tonga', 0),
('TTO', 'Trinidad and Tobago', 0),
('TUN', 'Tunisia', 0),
('TUR', 'Turkey', 0),
('TUV', 'Tuvalu', 0),
('TWN', 'Taiwan', 0),
('TZA', 'Tanzania', 0),
('UGA', 'Uganda', 0),
('UKR', 'Ukraine', 0),
('UMI', 'United States Minor Outlying Islands', 0),
('URY', 'Uruguay', 0),
('USA', 'United States of America', 0),
('UZB', 'Uzbekistan', 0),
('VAT', 'Vatican City', 0),
('VCT', 'Saint Vincent and the Grenadines', 0),
('VEN', 'Venezuela', 0),
('VGB', 'Virgin Islands, British', 0),
('VIR', 'Virgin Islands, U.S.', 0),
('VNM', 'Vietnam', 0),
('VUT', 'Vanuatu', 0),
('WLF', 'Wallis and Futuna Islands', 0),
('WSM', 'Samoa', 0),
('YEM', 'Yemen', 0),
('ZAF', 'South Africa', 0),
('ZMB', 'Zambia', 0),
('ZWE', 'Zimbabwe', 0);

CREATE TABLE `currencies` (
  `id` char(3) NOT NULL DEFAULT '',
  `name` varchar(45) NOT NULL DEFAULT '',
  `symbol` varchar(5) NOT NULL DEFAULT '',
  `isactive` smallint(6) NOT NULL DEFAULT 1,
  `rate` double NOT NULL DEFAULT 1
) ENGINE=InnoDB DEFAULT CHARSET=utf8mb4 COLLATE=utf8mb4_unicode_ci;

INSERT INTO `currencies` (`id`, `name`, `symbol`, `isactive`, `rate`) VALUES
('AFN', 'Afghanis', '؋', 0, 1),
('ALL', 'Leke', 'Lek', 0, 1),
('ANG', 'Guilders', 'ƒ', 0, 1),
('ARS', 'Pesos', '$', 0, 1),
('AUD', 'Dollars', '$', 0, 1),
('AWG', 'Guilders', 'ƒ', 0, 1),
('AZN', 'New Manats', 'ман', 0, 1),
('BAM', 'Convertible Marka', 'KM', 0, 1),
('BBD', 'Dollars', '$', 0, 1),
('BGN', 'Leva', 'лв', 0, 1),
('BMD', 'Dollars', '$', 0, 1),
('BND', 'Dollars', '$', 0, 1),
('BOB', 'Bolivianos', '$b', 0, 1),
('BRL', 'Reais', 'R$', 0, 1),
('BSD', 'Dollars', '$', 0, 1),
('BWP', 'Pula', 'P', 0, 1),
('BYR', 'Rubles', 'p.', 0, 1),
('BZD', 'Dollars', 'BZ$', 0, 1),
('CAD', 'Dollars', '$', 0, 1),
('CHF', 'Switzerland Francs', 'CHF', 0, 1),
('CLP', 'Pesos', '$', 0, 1),
('CNY', 'Yuan Renminbi', '¥', 0, 1),
('COP', 'Pesos', '$', 0, 1),
('CRC', 'ColÃƒÆ’Ã‚Â³n', '₡', 0, 1),
('CUP', 'Pesos', '₱', 0, 1),
('CZK', 'Koruny', 'Kč', 0, 1),
('DKK', 'Kroner', 'kr', 0, 1),
('DOP', 'Pesos', 'RD$', 0, 1),
('EGP', 'Pounds', '£', 0, 1),
('EUR', 'Euro', '€', 0, 1),
('FJD', 'Dollars', '$', 0, 1),
('FKP', 'Pounds', '£', 0, 1),
('GBP', 'Pounds', '£', 0, 1),
('GGP', 'Pounds', '£', 0, 1),
('GHC', 'Cedis', '¢', 0, 1),
('GIP', 'Pounds', '£', 0, 1),
('GTQ', 'Quetzales', 'Q', 0, 1),
('GYD', 'Dollars', '$', 0, 1),
('HKD', 'Dollars', '$', 0, 1),
('HNL', 'Lempiras', 'L', 0, 1),
('HRK', 'Kuna', 'kn', 0, 1),
('HUF', 'Forint', 'Ft', 0, 1),
('IDR', 'Rupiah', 'Rp', 1, 1),
('ILS', 'New Shekels', '₪', 0, 1),
('IMP', 'Pounds', '£', 0, 1),
('INR', 'Rupees', '₹', 0, 1),
('IRR', 'Rials', '﷼', 0, 1),
('ISK', 'Kronur', 'kr', 0, 1),
('JEP', 'Pounds', '£', 0, 1),
('JMD', 'Dollars', 'J$', 0, 1),
('JPY', 'Yen', '¥', 0, 1),
('KGS', 'Soms', 'лв', 0, 1),
('KHR', 'Riels', '៛', 0, 1),
('KPW', 'Won', '₩', 0, 1),
('KRW', 'Won', '₩', 0, 1),
('KYD', 'Dollars', '$', 0, 1),
('KZT', 'Tenge', 'лв', 0, 1),
('LAK', 'Kips', '₭', 0, 1),
('LBP', 'Pounds', '£', 0, 1),
('LKR', 'Rupees', '₨', 0, 1),
('LRD', 'Dollars', '$', 0, 1),
('LTL', 'Litai', 'Lt', 0, 1),
('LVL', 'Lati', 'Ls', 0, 1),
('MKD', 'Denars', 'ден', 0, 1),
('MNT', 'Tugriks', '₮', 0, 1),
('MUR', 'Rupees', '₨', 0, 1),
('MXN', 'Pesos', '$', 0, 1),
('MYR', 'Ringgits', 'RM', 0, 1),
('MZN', 'Meticais', 'MT', 0, 1),
('NAD', 'Dollars', '$', 0, 1),
('NGN', 'Nairas', '₦', 0, 1),
('NIO', 'Cordobas', 'C$', 0, 1),
('NOK', 'Krone', 'kr', 0, 1),
('NPR', 'Rupees', '₨', 0, 1),
('NZD', 'Dollars', '$', 0, 1),
('OMR', 'Rials', '﷼', 0, 1),
('PAB', 'Balboa', 'B/.', 0, 1),
('PEN', 'Nuevos Soles', 'S/.', 0, 1),
('PHP', 'Pesos', 'Php', 0, 1),
('PKR', 'Rupees', '₨', 0, 1),
('PLN', 'Zlotych', 'zł', 0, 1),
('PYG', 'Guarani', 'Gs', 0, 1),
('QAR', 'Rials', '﷼', 0, 1),
('RON', 'New Lei', 'lei', 0, 1),
('RSD', 'Dinars', 'Дин.', 0, 1),
('RUB', 'Rubles', 'руб', 0, 1),
('SAR', 'Riyals', '﷼', 0, 1),
('SBD', 'Dollars', '$', 0, 1),
('SCR', 'Rupees', '₨', 0, 1),
('SEK', 'Kronor', 'kr', 0, 1),
('SGD', 'Dollars', '$', 0, 1),
('SHP', 'Pounds', '£', 0, 1),
('SOS', 'Shillings', 'S', 0, 1),
('SRD', 'Dollars', '$', 0, 1),
('SVC', 'Colones', '$', 0, 1),
('SYP', 'Pounds', '£', 0, 1),
('THB', 'Baht', '฿', 0, 1),
('TRL', 'Liras', '£', 0, 1),
('TRY', 'Lira', '₺', 0, 1),
('TTD', 'Dollars', 'TT$', 0, 1),
('TVD', 'Dollars', '$', 0, 1),
('TWD', 'New Dollars', 'NT$', 0, 1),
('UAH', 'Hryvnia', '₴', 0, 1),
('USD', 'Dollars', '$', 0, 1),
('UYU', 'Pesos', '$U', 0, 1),
('UZS', 'Sums', 'лв', 0, 1),
('VEF', 'Bolivares Fuertes', 'Bs', 0, 1),
('VND', 'Dong', '₫', 0, 1),
('XCD', 'Dollars', '$', 0, 1),
('YER', 'Rials', '﷼', 0, 1),
('ZAR', 'Rand', 'R', 0, 1),
('ZWD', 'Zimbabwe Dollars', 'Z$', 0, 1);

CREATE TABLE `customer` (
  `id` char(30) NOT NULL DEFAULT '',
  `name` varchar(100) NOT NULL DEFAULT '',
  `customergroup` char(30) NOT NULL DEFAULT '',
  `address` varchar(200) NOT NULL DEFAULT '',
  `shipto` text DEFAULT NULL,
  `telephone` varchar(50) NOT NULL DEFAULT '',
  `faximile` varchar(50) NOT NULL DEFAULT '',
  `mobilephone` varchar(50) NOT NULL DEFAULT '',
  `category` tinyint(4) NOT NULL DEFAULT 0 COMMENT '0=PERSONAL, 1=COMPANY',
  `contactperson` varchar(100) NOT NULL DEFAULT '',
  `religion` int(10) UNSIGNED NOT NULL DEFAULT 0,
  `birthdate` date DEFAULT NULL,
  `sex` tinyint(4) NOT NULL DEFAULT 0 COMMENT '0=MALE, 1=FEMALE',
  `email` varchar(100) NOT NULL DEFAULT '',
  `loginpassword` varchar(100) NOT NULL DEFAULT '',
  `website` varchar(100) NOT NULL DEFAULT '',
  `country` char(3) NOT NULL DEFAULT '',
  `creditlimit` double NOT NULL DEFAULT 0,
  `creditlimittype` tinyint(4) NOT NULL DEFAULT 0,
  `registerdate` date DEFAULT NULL,
  `activeuntil` date DEFAULT '2099-12-31',
  `taxid` varchar(50) NOT NULL DEFAULT '',
  `taxiddate` date DEFAULT NULL,
  `taxable` smallint(6) NOT NULL DEFAULT 0,
  `termofpayment` varchar(30) NOT NULL DEFAULT '' COMMENT '2/10, n/30\nCOD (Cash On Delivery)',
  `isactive` smallint(6) NOT NULL DEFAULT 1,
  `defsalesmanid` char(30) NOT NULL DEFAULT '',
  `salesdiscrules` text DEFAULT NULL,
  `salesproductrewardrules` text DEFAULT NULL,
  `salespointrewardrules` text DEFAULT NULL,
  `paymentdiscrules` text DEFAULT NULL,
  `receivableacc` char(30) NOT NULL DEFAULT '',
  `rewardacc` char(30) NOT NULL DEFAULT '',
  `salesdiscacc` char(30) NOT NULL DEFAULT '',
  `gainlossreceivableacc` char(30) NOT NULL DEFAULT '',
  `point` double NOT NULL DEFAULT 0,
  `usercreate` char(16) NOT NULL DEFAULT '',
  `useredit` char(16) NOT NULL DEFAULT '',
  `pricelevel` int(11) NOT NULL DEFAULT 1,
  `updatetimestamp` timestamp NOT NULL DEFAULT current_timestamp() ON UPDATE current_timestamp(),
  `image` varchar(255) DEFAULT '[]'
) ENGINE=InnoDB DEFAULT CHARSET=utf8mb4 COLLATE=utf8mb4_unicode_ci;

CREATE TABLE `customerbalance` (
  `transid` bigint(20) UNSIGNED NOT NULL,
  `salesid` char(30) NOT NULL DEFAULT '',
  `salesidref` char(30) NOT NULL DEFAULT '',
  `division` char(10) NOT NULL DEFAULT '',
  `customerid` char(30) NOT NULL DEFAULT '',
  `transdate` datetime DEFAULT NULL,
  `debit` double NOT NULL DEFAULT 0,
  `credit` double NOT NULL DEFAULT 0,
  `currtrans` char(3) NOT NULL DEFAULT '',
  `ratedefault` double NOT NULL DEFAULT 0,
  `rateused` double NOT NULL DEFAULT 0,
  `usercreate` char(16) NOT NULL DEFAULT '',
  `useredit` char(16) NOT NULL DEFAULT '',
  `updatetimestamp` timestamp NOT NULL DEFAULT current_timestamp() ON UPDATE current_timestamp()
) ENGINE=InnoDB DEFAULT CHARSET=utf8mb4 COLLATE=utf8mb4_unicode_ci;

CREATE TABLE `customerdisplay` (
  `id` int(11) NOT NULL,
  `name` varchar(50) NOT NULL DEFAULT '',
  `intervalplay` int(11) NOT NULL DEFAULT 8,
  `duration` int(11) NOT NULL DEFAULT 1,
  `bgclass` varchar(50) NOT NULL DEFAULT '',
  `published` int(11) NOT NULL DEFAULT 1,
  `slideheight` int(11) NOT NULL DEFAULT 500,
  `showarrow` int(11) NOT NULL DEFAULT 1,
  `shownavigation` int(11) NOT NULL DEFAULT 1,
  `autoplay` int(11) NOT NULL DEFAULT 1
) ENGINE=InnoDB DEFAULT CHARSET=utf8mb4 COLLATE=utf8mb4_unicode_ci;

INSERT INTO `customerdisplay` (`id`, `name`, `intervalplay`, `duration`, `bgclass`, `published`, `slideheight`, `showarrow`, `shownavigation`, `autoplay`) VALUES
(1, 'Customer Display 2', 8, 1, '', 1, 864, 0, 0, 1);

CREATE TABLE `customerdp` (
  `transid` char(30) NOT NULL,
  `division` char(10) NOT NULL DEFAULT '',
  `customerid` char(30) DEFAULT NULL,
  `customername` varchar(100) NOT NULL DEFAULT '',
  `customeraddress` varchar(200) NOT NULL DEFAULT '',
  `transdate` datetime DEFAULT NULL,
  `paymenttype` int(10) UNSIGNED DEFAULT NULL,
  `downpaymenttype` int(10) UNSIGNED NOT NULL,
  `kind` int(10) UNSIGNED NOT NULL DEFAULT 0,
  `debit` double NOT NULL DEFAULT 0,
  `credit` double NOT NULL DEFAULT 0,
  `memo` text DEFAULT NULL,
  `printed` smallint(6) NOT NULL DEFAULT 0,
  `currtrans` char(3) NOT NULL DEFAULT '',
  `ratedefault` double NOT NULL DEFAULT 0,
  `rateused` double NOT NULL DEFAULT 0,
  `usercreate` char(16) NOT NULL DEFAULT '',
  `useredit` char(16) NOT NULL DEFAULT '',
  `updatetimestamp` timestamp NOT NULL DEFAULT current_timestamp() ON UPDATE current_timestamp()
) ENGINE=InnoDB DEFAULT CHARSET=utf8mb4 COLLATE=utf8mb4_unicode_ci;

CREATE TABLE `customergiro` (
  `id` bigint(20) UNSIGNED NOT NULL,
  `transid` char(30) NOT NULL DEFAULT '',
  `transidref` char(30) NOT NULL DEFAULT '',
  `transdate` datetime DEFAULT NULL,
  `customerid` char(30) NOT NULL DEFAULT '',
  `customername` varchar(100) NOT NULL DEFAULT '',
  `customeraddress` varchar(200) NOT NULL DEFAULT '',
  `accepted` smallint(6) NOT NULL DEFAULT 0,
  `duedate` datetime DEFAULT NULL,
  `accepteddate` datetime DEFAULT NULL,
  `giroin` double NOT NULL DEFAULT 0,
  `giroout` double NOT NULL DEFAULT 0,
  `paymenttype` int(10) UNSIGNED NOT NULL,
  `paymentref` varchar(100) NOT NULL DEFAULT '',
  `currtrans` char(3) NOT NULL DEFAULT '',
  `ratedefault` double NOT NULL DEFAULT 0,
  `rateused` double NOT NULL DEFAULT 0,
  `division` char(10) NOT NULL DEFAULT '',
  `kind` smallint(6) NOT NULL DEFAULT 0,
  `jtid` char(30) NOT NULL DEFAULT '',
  `usercreate` char(16) NOT NULL DEFAULT '',
  `useredit` char(16) NOT NULL DEFAULT '',
  `updatetimestamp` timestamp NOT NULL DEFAULT current_timestamp() ON UPDATE current_timestamp()
) ENGINE=InnoDB DEFAULT CHARSET=utf8mb4 COLLATE=utf8mb4_unicode_ci;

CREATE TABLE `customergroup` (
  `id` char(30) NOT NULL DEFAULT '',
  `description` varchar(100) NOT NULL DEFAULT '',
  `salesdiscrules` text DEFAULT NULL,
  `salesproductrewardrules` text DEFAULT NULL,
  `salespointrewardrules` text DEFAULT NULL,
  `paymentdiscrules` text DEFAULT NULL,
  `receivableacc` char(30) NOT NULL DEFAULT '',
  `rewardacc` char(30) NOT NULL DEFAULT '',
  `salesdiscacc` char(30) NOT NULL DEFAULT '',
  `gainlossreceivableacc` char(30) NOT NULL DEFAULT '',
  `usercreate` char(16) NOT NULL DEFAULT '',
  `useredit` char(16) NOT NULL DEFAULT '',
  `updatetimestamp` timestamp NOT NULL DEFAULT current_timestamp() ON UPDATE current_timestamp()
) ENGINE=InnoDB DEFAULT CHARSET=utf8mb4 COLLATE=utf8mb4_unicode_ci;

CREATE TABLE `customerguide` (
  `id` char(30) NOT NULL DEFAULT '',
  `name` varchar(50) NOT NULL DEFAULT '',
  `description` varchar(100) NOT NULL DEFAULT '',
  `customerid` char(30) NOT NULL DEFAULT '',
  `usercreate` char(16) NOT NULL DEFAULT '',
  `useredit` char(16) NOT NULL DEFAULT '',
  `image` blob DEFAULT NULL,
  `updatetimestamp` timestamp NOT NULL DEFAULT current_timestamp() ON UPDATE current_timestamp()
) ENGINE=InnoDB DEFAULT CHARSET=utf8mb4 COLLATE=utf8mb4_unicode_ci;

CREATE TABLE `customernote` (
  `transid` bigint(20) UNSIGNED NOT NULL,
  `transdate` date DEFAULT NULL,
  `transtime` time DEFAULT NULL,
  `customerid` char(30) NOT NULL DEFAULT '',
  `customername` varchar(100) NOT NULL DEFAULT '',
  `customeraddress` varchar(200) NOT NULL DEFAULT '',
  `customercreditlimit` double NOT NULL DEFAULT 0,
  `customercreditlimittype` tinyint(4) NOT NULL DEFAULT 0,
  `customernoteid` char(5) NOT NULL DEFAULT '',
  `notes` text DEFAULT NULL,
  `division` char(10) NOT NULL DEFAULT '',
  `usercreate` char(16) NOT NULL DEFAULT '',
  `useredit` char(16) NOT NULL DEFAULT '',
  `updatetimestamp` timestamp NOT NULL DEFAULT current_timestamp() ON UPDATE current_timestamp()
) ENGINE=InnoDB DEFAULT CHARSET=utf8mb4 COLLATE=utf8mb4_unicode_ci;

CREATE TABLE `customernotes` (
  `id` char(5) NOT NULL DEFAULT '',
  `name` varchar(100) NOT NULL DEFAULT '',
  `usercreate` char(16) NOT NULL DEFAULT '',
  `useredit` char(16) NOT NULL DEFAULT '',
  `updatetimestamp` timestamp NOT NULL DEFAULT current_timestamp() ON UPDATE current_timestamp()
) ENGINE=InnoDB DEFAULT CHARSET=utf8mb4 COLLATE=utf8mb4_unicode_ci;

INSERT INTO `customernotes` (`id`, `name`, `usercreate`, `useredit`, `updatetimestamp`) VALUES
('001', 'Umum', 'admin', '', '2024-02-05 14:57:09');

CREATE TABLE `deliveryorder` (
  `salesid` char(30) NOT NULL DEFAULT '',
  `salesidref` char(30) NOT NULL DEFAULT '',
  `salesorder` char(30) NOT NULL DEFAULT '',
  `salesdate` date DEFAULT NULL,
  `salestime` time DEFAULT NULL,
  `kind` int(11) NOT NULL DEFAULT 0,
  `customerid` char(30) NOT NULL DEFAULT '',
  `customername` varchar(100) NOT NULL DEFAULT '',
  `customeraddress` varchar(200) NOT NULL DEFAULT '',
  `salesmanid` char(30) NOT NULL DEFAULT '',
  `salesmanname` varchar(100) NOT NULL DEFAULT '',
  `shipto` text DEFAULT NULL,
  `memo` text DEFAULT NULL,
  `memoedit` text DEFAULT NULL,
  `division` char(10) NOT NULL DEFAULT '',
  `printed` smallint(6) NOT NULL DEFAULT 0,
  `shipment` int(10) UNSIGNED NOT NULL DEFAULT 1,
  `usercreate` char(16) NOT NULL DEFAULT '',
  `useredit` char(16) NOT NULL DEFAULT '',
  `packed` int(11) NOT NULL DEFAULT 0,
  `updatetimestamp` timestamp NOT NULL DEFAULT current_timestamp() ON UPDATE current_timestamp()
) ENGINE=InnoDB DEFAULT CHARSET=utf8mb4 COLLATE=utf8mb4_unicode_ci;

CREATE TABLE `deliveryorderdetail` (
  `transid` bigint(20) UNSIGNED NOT NULL,
  `transdate` datetime DEFAULT NULL,
  `salesid` char(30) NOT NULL DEFAULT '',
  `salesidref` char(30) NOT NULL DEFAULT '',
  `productid` char(30) NOT NULL DEFAULT '',
  `productname` varchar(100) NOT NULL DEFAULT '',
  `snproduct` varchar(100) NOT NULL DEFAULT '',
  `expireddate` date DEFAULT NULL,
  `qty` double NOT NULL DEFAULT 0,
  `unit` char(10) NOT NULL DEFAULT '',
  `unitqty` double NOT NULL DEFAULT 0,
  `memo` text DEFAULT NULL,
  `departement` char(10) NOT NULL DEFAULT '',
  `usercreate` char(16) NOT NULL DEFAULT '',
  `useredit` char(16) NOT NULL DEFAULT '',
  `updatetimestamp` timestamp NOT NULL DEFAULT current_timestamp() ON UPDATE current_timestamp()
) ENGINE=InnoDB DEFAULT CHARSET=utf8mb4 COLLATE=utf8mb4_unicode_ci;

CREATE TABLE `deliveryorderrewarddetail` (
  `transid` bigint(20) UNSIGNED NOT NULL,
  `transdate` datetime DEFAULT NULL,
  `salesid` char(30) NOT NULL DEFAULT '',
  `salesidref` char(30) NOT NULL DEFAULT '',
  `productid` char(30) NOT NULL DEFAULT '',
  `productname` varchar(100) NOT NULL DEFAULT '',
  `snproduct` varchar(100) NOT NULL DEFAULT '',
  `expireddate` date DEFAULT NULL,
  `qty` double NOT NULL DEFAULT 0,
  `unit` char(10) NOT NULL DEFAULT '',
  `unitqty` double NOT NULL DEFAULT 0,
  `memo` text DEFAULT NULL,
  `departement` char(10) NOT NULL DEFAULT '',
  `usercreate` char(16) NOT NULL DEFAULT '',
  `useredit` char(16) NOT NULL DEFAULT '',
  `updatetimestamp` timestamp NOT NULL DEFAULT current_timestamp() ON UPDATE current_timestamp()
) ENGINE=InnoDB DEFAULT CHARSET=utf8mb4 COLLATE=utf8mb4_unicode_ci;

CREATE TABLE `departement` (
  `id` char(10) NOT NULL DEFAULT '',
  `name` varchar(50) NOT NULL DEFAULT '',
  `description` varchar(150) NOT NULL DEFAULT '',
  `isactive` smallint(5) UNSIGNED NOT NULL DEFAULT 1,
  `division` char(10) NOT NULL,
  `usercreate` char(16) NOT NULL DEFAULT '',
  `useredit` char(16) NOT NULL DEFAULT '',
  `updatetimestamp` timestamp NOT NULL DEFAULT current_timestamp() ON UPDATE current_timestamp()
) ENGINE=InnoDB DEFAULT CHARSET=utf8mb4 COLLATE=utf8mb4_unicode_ci;

CREATE TABLE `depreciationrecords` (
  `transid` bigint(20) UNSIGNED NOT NULL,
  `fixedassetid` char(30) NOT NULL DEFAULT '',
  `transdate` date DEFAULT NULL,
  `debit` double NOT NULL DEFAULT 0,
  `credit` double NOT NULL DEFAULT 0,
  `journalid` char(30) NOT NULL DEFAULT '',
  `usercreate` char(16) NOT NULL DEFAULT '',
  `useredit` char(16) NOT NULL DEFAULT '',
  `updatetimestamp` timestamp NOT NULL DEFAULT current_timestamp() ON UPDATE current_timestamp()
) ENGINE=InnoDB DEFAULT CHARSET=utf8mb4 COLLATE=utf8mb4_unicode_ci;

CREATE TABLE `discountdays` (
  `adate` date NOT NULL,
  `description` varchar(100) NOT NULL DEFAULT ''
) ENGINE=InnoDB DEFAULT CHARSET=utf8mb4 COLLATE=utf8mb4_unicode_ci;

CREATE TABLE `division` (
  `id` char(10) NOT NULL DEFAULT '',
  `description` varchar(100) NOT NULL DEFAULT '',
  `acumsalesdisc` smallint(6) NOT NULL DEFAULT 1,
  `updlastsalesmanidtocust` smallint(6) NOT NULL DEFAULT 0,
  `frmsupplierdpid` varchar(20) NOT NULL DEFAULT '',
  `frmpurchaserequisitionid` varchar(20) NOT NULL DEFAULT '',
  `frmpurchaseorderid` varchar(20) NOT NULL DEFAULT '',
  `frmgoodsreceiptid` varchar(20) NOT NULL DEFAULT '',
  `frmpurchaseid` varchar(20) NOT NULL DEFAULT '',
  `frmpurchasereturnid` varchar(20) NOT NULL DEFAULT '',
  `frmpurchasepaymentid` varchar(20) NOT NULL DEFAULT '',
  `frmpayableadjustid` varchar(20) NOT NULL DEFAULT '',
  `frmcustomerdpid` varchar(20) NOT NULL DEFAULT '',
  `frmsalesorderid` varchar(20) NOT NULL DEFAULT '',
  `frmdeliveryorderid` varchar(20) NOT NULL DEFAULT '',
  `frmsalesid` varchar(20) NOT NULL DEFAULT '',
  `frmtaxid` varchar(30) NOT NULL DEFAULT '',
  `frmsalesreturnid` varchar(20) NOT NULL DEFAULT '',
  `frmsalespaymentid` varchar(20) NOT NULL DEFAULT '',
  `frmreceivableadjustid` varchar(20) NOT NULL DEFAULT '',
  `frmrentalreturnid` varchar(20) NOT NULL DEFAULT '',
  `frminventoryid` varchar(20) NOT NULL DEFAULT '',
  `frmjournalentryid` varchar(20) NOT NULL DEFAULT '',
  `frmmanufactureid` varchar(20) NOT NULL DEFAULT '',
  `frmpayrollid` varchar(20) NOT NULL DEFAULT '',
  `supplierdpidno` bigint(20) UNSIGNED NOT NULL DEFAULT 0,
  `purchaserequisitionidno` bigint(20) UNSIGNED NOT NULL DEFAULT 0,
  `purchaseorderidno` bigint(20) UNSIGNED NOT NULL DEFAULT 0,
  `goodsreceiptidno` bigint(20) UNSIGNED NOT NULL DEFAULT 0,
  `purchaseidno` bigint(20) UNSIGNED NOT NULL DEFAULT 0,
  `purchasereturnidno` bigint(20) UNSIGNED NOT NULL DEFAULT 0,
  `purchasepaymentidno` bigint(20) UNSIGNED NOT NULL DEFAULT 0,
  `payableadjustidno` bigint(20) UNSIGNED NOT NULL DEFAULT 0,
  `customerdpidno` bigint(20) UNSIGNED NOT NULL DEFAULT 0,
  `salesorderidno` bigint(20) UNSIGNED NOT NULL DEFAULT 0,
  `deliveryorderidno` bigint(20) UNSIGNED NOT NULL DEFAULT 0,
  `salesidno` bigint(20) UNSIGNED NOT NULL DEFAULT 0,
  `taxidno` bigint(20) UNSIGNED NOT NULL DEFAULT 0,
  `salesreturnidno` bigint(20) UNSIGNED NOT NULL DEFAULT 0,
  `salespaymentidno` bigint(20) UNSIGNED NOT NULL DEFAULT 0,
  `receivableadjustidno` bigint(20) UNSIGNED NOT NULL DEFAULT 0,
  `rentalreturnidno` bigint(20) UNSIGNED NOT NULL DEFAULT 0,
  `inventoryidno` bigint(20) UNSIGNED NOT NULL DEFAULT 0,
  `journalentryidno` bigint(20) UNSIGNED NOT NULL DEFAULT 0,
  `manufactureidno` bigint(20) UNSIGNED NOT NULL DEFAULT 0,
  `payrollidno` bigint(20) UNSIGNED NOT NULL DEFAULT 0,
  `retainedearningacc` char(30) NOT NULL DEFAULT '',
  `exchangerateacc` char(30) NOT NULL DEFAULT '',
  `profitlossdiffcashacc` char(30) NOT NULL DEFAULT '',
  `usercreate` char(16) NOT NULL DEFAULT '',
  `useredit` char(16) NOT NULL DEFAULT '',
  `updatetimestamp` timestamp NOT NULL DEFAULT current_timestamp() ON UPDATE current_timestamp()
) ENGINE=InnoDB DEFAULT CHARSET=utf8mb4 COLLATE=utf8mb4_unicode_ci;

CREATE TABLE `employee` (
  `id` char(30) NOT NULL DEFAULT '',
  `name` varchar(100) NOT NULL DEFAULT '',
  `employeegroup` char(30) NOT NULL DEFAULT '',
  `address` varchar(200) NOT NULL DEFAULT '',
  `telephone` varchar(50) NOT NULL DEFAULT '',
  `faximile` varchar(50) NOT NULL DEFAULT '',
  `mobilephone` varchar(50) NOT NULL DEFAULT '',
  `salarystructure` int(10) UNSIGNED NOT NULL DEFAULT 0,
  `website` varchar(100) NOT NULL DEFAULT '',
  `religion` int(10) UNSIGNED NOT NULL DEFAULT 0,
  `birthdate` datetime DEFAULT NULL,
  `sex` tinyint(4) DEFAULT 0 COMMENT '0=MALE, 1=FEMALE',
  `email` varchar(100) NOT NULL DEFAULT '',
  `creditlimit` double NOT NULL DEFAULT 0,
  `registerdate` datetime DEFAULT NULL,
  `activeuntil` datetime DEFAULT '2099-12-31 00:00:00',
  `taxid` varchar(50) NOT NULL DEFAULT '',
  `isactive` smallint(6) NOT NULL DEFAULT 1,
  `country` char(3) NOT NULL DEFAULT '',
  `taxtype` tinyint(4) NOT NULL DEFAULT 0,
  `occupation` varchar(100) NOT NULL DEFAULT '',
  `bankaccount` varchar(30) NOT NULL DEFAULT '',
  `bankname` varchar(30) NOT NULL DEFAULT '',
  `usercreate` char(16) NOT NULL DEFAULT '',
  `useredit` char(16) NOT NULL DEFAULT '',
  `updatetimestamp` timestamp NOT NULL DEFAULT current_timestamp() ON UPDATE current_timestamp(),
  `image` varchar(255) DEFAULT '[]',
  `loginattendance` int(11) NOT NULL DEFAULT 0,
  `loginpassword` varchar(255) NOT NULL DEFAULT '',
  `userid` char(16) DEFAULT ''
) ENGINE=InnoDB DEFAULT CHARSET=utf8mb4 COLLATE=utf8mb4_unicode_ci;

CREATE TABLE `employeeface` (
  `id` bigint(20) UNSIGNED NOT NULL,
  `employeeid` char(30) NOT NULL DEFAULT '',
  `templatedata` mediumtext DEFAULT NULL,
  `templateversion` varchar(50) NOT NULL DEFAULT '',
  `qualityscore` decimal(10,6) DEFAULT NULL,
  `isactive` smallint(6) NOT NULL DEFAULT 1,
  `notes` varchar(255) DEFAULT '',
  `usercreate` char(16) NOT NULL DEFAULT '',
  `useredit` char(16) NOT NULL DEFAULT '',
  `updatetimestamp` timestamp NOT NULL DEFAULT current_timestamp() ON UPDATE current_timestamp()
) ENGINE=InnoDB DEFAULT CHARSET=utf8mb4 COLLATE=utf8mb4_unicode_ci;

CREATE TABLE `employeefaceenrollment` (
  `id` bigint(20) UNSIGNED NOT NULL,
  `employeeid` char(30) NOT NULL DEFAULT '',
  `snapshot1` varchar(255) DEFAULT '',
  `snapshot2` varchar(255) DEFAULT '',
  `snapshot3` varchar(255) DEFAULT '',
  `qualityscore` decimal(10,6) DEFAULT NULL,
  `status` varchar(30) NOT NULL DEFAULT 'draft',
  `notes` varchar(255) DEFAULT '',
  `usercreate` char(16) NOT NULL DEFAULT '',
  `useredit` char(16) NOT NULL DEFAULT '',
  `updatetimestamp` timestamp NOT NULL DEFAULT current_timestamp() ON UPDATE current_timestamp()
) ENGINE=InnoDB DEFAULT CHARSET=utf8mb4 COLLATE=utf8mb4_unicode_ci;

CREATE TABLE `employeegroup` (
  `id` char(30) NOT NULL DEFAULT '',
  `description` varchar(100) NOT NULL DEFAULT '',
  `usercreate` char(16) NOT NULL DEFAULT '',
  `useredit` char(16) NOT NULL DEFAULT '',
  `updatetimestamp` timestamp NOT NULL DEFAULT current_timestamp() ON UPDATE current_timestamp()
) ENGINE=InnoDB DEFAULT CHARSET=utf8mb4 COLLATE=utf8mb4_unicode_ci;

CREATE TABLE `employeesalaries` (
  `id` bigint(20) UNSIGNED NOT NULL,
  `employeeid` char(30) NOT NULL DEFAULT '',
  `salaryid` int(10) UNSIGNED NOT NULL DEFAULT 0,
  `kind` int(11) NOT NULL DEFAULT 1 COMMENT '1=fixed, 2=input, 3=formula',
  `defaultvalue` double NOT NULL DEFAULT 0,
  `formula` text NOT NULL,
  `usercreate` char(16) NOT NULL DEFAULT '',
  `weight` int(11) NOT NULL DEFAULT 0,
  `useredit` char(16) NOT NULL DEFAULT '',
  `updatetimestamp` timestamp NOT NULL DEFAULT current_timestamp() ON UPDATE current_timestamp()
) ENGINE=InnoDB DEFAULT CHARSET=utf8mb4 COLLATE=utf8mb4_unicode_ci;

CREATE TABLE `excratehistories` (
  `transid` bigint(20) UNSIGNED NOT NULL,
  `id` char(3) NOT NULL DEFAULT '',
  `rate` double NOT NULL DEFAULT 1,
  `user` char(16) NOT NULL DEFAULT '',
  `updatetimestamp` timestamp NOT NULL DEFAULT current_timestamp() ON UPDATE current_timestamp()
) ENGINE=InnoDB DEFAULT CHARSET=utf8mb4 COLLATE=utf8mb4_unicode_ci;

CREATE TABLE `factories` (
  `id` char(30) NOT NULL DEFAULT '',
  `name` varchar(100) NOT NULL DEFAULT '',
  `address` varchar(200) NOT NULL DEFAULT '',
  `usercreate` char(16) NOT NULL DEFAULT '',
  `useredit` char(16) NOT NULL DEFAULT '',
  `updatetimestamp` timestamp NOT NULL DEFAULT current_timestamp() ON UPDATE current_timestamp()
) ENGINE=InnoDB DEFAULT CHARSET=utf8mb4 COLLATE=utf8mb4_unicode_ci;

CREATE TABLE `filteroperands` (
  `id` int(11) NOT NULL,
  `fieldtype` varchar(50) NOT NULL DEFAULT '0',
  `value` varchar(50) NOT NULL DEFAULT '0',
  `label` varchar(50) NOT NULL DEFAULT '0'
) ENGINE=InnoDB DEFAULT CHARSET=utf8mb4 COLLATE=utf8mb4_unicode_ci;

INSERT INTO `filteroperands` (`id`, `fieldtype`, `value`, `label`) VALUES
(1, 'text', '', ''),
(2, 'text', '=', '='),
(3, 'text', 'like', 'like'),
(4, 'date', '', ''),
(5, 'date', '=', '='),
(6, 'date', 'between', 'between'),
(7, 'date', '>=', '>='),
(8, 'date', '<=', '<='),
(9, 'datetime', '', ''),
(10, 'datetime', '=', '='),
(11, 'datetime', 'between', 'between'),
(12, 'datetime', '>=', '>='),
(13, 'datetime', '<=', '<='),
(14, 'time', '', ''),
(15, 'time', '=', '='),
(16, 'time', 'between', 'between'),
(17, 'time', '>=', '>='),
(18, 'time', '<=', '<='),
(19, 'decimal', '', ''),
(20, 'decimal', '=', '='),
(21, 'decimal', 'between', 'between'),
(22, 'decimal', '>=', '>='),
(23, 'decimal', '<=', '<='),
(24, 'decimal', '<', '<'),
(25, 'decimal', '>', '>'),
(26, 'integer', '', ''),
(27, 'integer', '=', '='),
(28, 'integer', 'between', 'between'),
(29, 'integer', '>=', '>='),
(30, 'integer', '<=', '<='),
(31, 'integer', '<', '<'),
(32, 'integer', '>', '>');

CREATE TABLE `fixedasset` (
  `id` char(30) NOT NULL DEFAULT '',
  `name` varchar(50) NOT NULL DEFAULT '',
  `description` varchar(100) NOT NULL DEFAULT '',
  `fagroup` char(30) NOT NULL DEFAULT '',
  `division` char(10) NOT NULL DEFAULT '',
  `departement` char(10) NOT NULL DEFAULT '',
  `acquisitiondate` date DEFAULT NULL,
  `cost` double NOT NULL DEFAULT 0,
  `usefullife` double NOT NULL DEFAULT 0,
  `depreciationrate` double NOT NULL DEFAULT 0,
  `salvagevalue` double NOT NULL DEFAULT 0,
  `currentvalue` double NOT NULL DEFAULT 0,
  `journalid` varchar(30) NOT NULL DEFAULT '',
  `journaldate` datetime NOT NULL,
  `usercreate` char(16) NOT NULL DEFAULT '',
  `useredit` char(16) NOT NULL DEFAULT '',
  `active` smallint(6) NOT NULL DEFAULT 1,
  `accountid` char(30) NOT NULL DEFAULT '',
  `updatetimestamp` timestamp NOT NULL DEFAULT current_timestamp() ON UPDATE current_timestamp()
) ENGINE=InnoDB DEFAULT CHARSET=utf8mb4 COLLATE=utf8mb4_unicode_ci;

CREATE TABLE `fixedassetdepreciation` (
  `transid` bigint(20) UNSIGNED NOT NULL,
  `transdate` date DEFAULT NULL,
  `division` char(10) NOT NULL DEFAULT '',
  `journalid` char(30) NOT NULL DEFAULT '',
  `memo` varchar(100) NOT NULL DEFAULT '',
  `usercreate` char(16) NOT NULL DEFAULT '',
  `useredit` char(16) NOT NULL DEFAULT '',
  `updatetimestamp` timestamp NOT NULL DEFAULT current_timestamp() ON UPDATE current_timestamp()
) ENGINE=InnoDB DEFAULT CHARSET=utf8mb4 COLLATE=utf8mb4_unicode_ci;

CREATE TABLE `fixedassetdispose` (
  `transid` bigint(20) UNSIGNED NOT NULL,
  `fixedassetid` char(30) NOT NULL DEFAULT '',
  `name` varchar(50) NOT NULL DEFAULT '',
  `description` varchar(100) NOT NULL DEFAULT '',
  `division` char(10) NOT NULL DEFAULT '',
  `departement` char(10) NOT NULL DEFAULT '',
  `acquisitiondate` date DEFAULT NULL,
  `cost` double NOT NULL DEFAULT 0,
  `usefullife` double NOT NULL DEFAULT 0,
  `depreciationrate` double NOT NULL DEFAULT 0,
  `salvagevalue` double NOT NULL DEFAULT 0,
  `bookedvalue` double NOT NULL DEFAULT 0,
  `currentvalue` double NOT NULL DEFAULT 0,
  `journalid` varchar(30) NOT NULL DEFAULT '',
  `journaldate` datetime NOT NULL,
  `salesprice` double NOT NULL DEFAULT 0,
  `profitloss` double NOT NULL DEFAULT 0,
  `usercreate` char(16) NOT NULL DEFAULT '',
  `useredit` char(16) NOT NULL DEFAULT '',
  `active` smallint(6) NOT NULL DEFAULT 1,
  `accountid` char(30) NOT NULL DEFAULT '',
  `updatetimestamp` timestamp NOT NULL DEFAULT current_timestamp() ON UPDATE current_timestamp()
) ENGINE=InnoDB DEFAULT CHARSET=utf8mb4 COLLATE=utf8mb4_unicode_ci;

CREATE TABLE `fixedassetgroup` (
  `id` char(30) NOT NULL DEFAULT '',
  `name` varchar(50) NOT NULL DEFAULT '',
  `description` varchar(100) NOT NULL DEFAULT '',
  `depreciationmethod` smallint(6) NOT NULL DEFAULT 0,
  `fixedassetacc` char(30) NOT NULL DEFAULT '',
  `depreciationacc` char(30) NOT NULL DEFAULT '',
  `expenseacc` char(30) NOT NULL DEFAULT '',
  `gainlostacc` char(30) NOT NULL DEFAULT '',
  `usercreate` char(16) NOT NULL DEFAULT '',
  `useredit` char(16) NOT NULL DEFAULT '',
  `updatetimestamp` timestamp NOT NULL DEFAULT current_timestamp() ON UPDATE current_timestamp()
) ENGINE=InnoDB DEFAULT CHARSET=utf8mb4 COLLATE=utf8mb4_unicode_ci;

CREATE TABLE `goodsreceipt` (
  `purchaseid` char(30) NOT NULL DEFAULT '',
  `purchaseidref` char(30) NOT NULL DEFAULT '',
  `purchaseorder` char(30) NOT NULL DEFAULT '',
  `purchasedate` date DEFAULT NULL,
  `purchasetime` time DEFAULT NULL,
  `kind` int(11) NOT NULL DEFAULT 0,
  `supplierid` char(30) NOT NULL DEFAULT '',
  `suppliername` varchar(100) NOT NULL DEFAULT '',
  `supplieraddress` varchar(200) NOT NULL DEFAULT '',
  `purchaser` char(30) NOT NULL DEFAULT '',
  `purchasername` varchar(100) NOT NULL DEFAULT '',
  `memo` text DEFAULT NULL,
  `memoedit` text DEFAULT NULL,
  `division` char(10) NOT NULL DEFAULT '',
  `printed` smallint(6) NOT NULL DEFAULT 0,
  `shipment` int(10) UNSIGNED NOT NULL DEFAULT 1,
  `usercreate` char(16) NOT NULL DEFAULT '',
  `useredit` char(16) NOT NULL DEFAULT '',
  `updatetimestamp` timestamp NOT NULL DEFAULT current_timestamp() ON UPDATE current_timestamp()
) ENGINE=InnoDB DEFAULT CHARSET=utf8mb4 COLLATE=utf8mb4_unicode_ci;

CREATE TABLE `goodsreceiptdetail` (
  `transid` bigint(20) UNSIGNED NOT NULL,
  `transdate` datetime DEFAULT NULL,
  `purchaseid` char(30) NOT NULL DEFAULT '',
  `purchaseidref` char(30) NOT NULL DEFAULT '',
  `productid` char(30) NOT NULL DEFAULT '',
  `productname` varchar(100) NOT NULL DEFAULT '',
  `snproduct` varchar(100) NOT NULL DEFAULT '',
  `expireddate` date DEFAULT NULL,
  `qty` double NOT NULL DEFAULT 0,
  `unit` char(10) NOT NULL DEFAULT '',
  `unitqty` double NOT NULL DEFAULT 0,
  `memo` text DEFAULT NULL,
  `departement` char(10) NOT NULL DEFAULT '',
  `usercreate` char(16) NOT NULL DEFAULT '',
  `useredit` char(16) NOT NULL DEFAULT '',
  `updatetimestamp` timestamp NOT NULL DEFAULT current_timestamp() ON UPDATE current_timestamp()
) ENGINE=InnoDB DEFAULT CHARSET=utf8mb4 COLLATE=utf8mb4_unicode_ci;

CREATE TABLE `goodsreceiptrewarddetail` (
  `transid` bigint(20) UNSIGNED NOT NULL,
  `transdate` datetime DEFAULT NULL,
  `purchaseid` char(30) NOT NULL DEFAULT '',
  `purchaseidref` char(30) NOT NULL DEFAULT '',
  `productid` char(30) NOT NULL DEFAULT '',
  `productname` varchar(100) NOT NULL DEFAULT '',
  `snproduct` varchar(100) NOT NULL DEFAULT '',
  `expireddate` date DEFAULT NULL,
  `qty` double NOT NULL DEFAULT 0,
  `unit` char(10) NOT NULL DEFAULT '',
  `unitqty` double NOT NULL DEFAULT 0,
  `memo` text DEFAULT NULL,
  `departement` char(10) NOT NULL DEFAULT '',
  `usercreate` char(16) NOT NULL DEFAULT '',
  `useredit` char(16) NOT NULL DEFAULT '',
  `updatetimestamp` timestamp NOT NULL DEFAULT current_timestamp() ON UPDATE current_timestamp()
) ENGINE=InnoDB DEFAULT CHARSET=utf8mb4 COLLATE=utf8mb4_unicode_ci;

CREATE TABLE `groupid` (
  `id` char(30) NOT NULL DEFAULT '',
  `name` varchar(100) NOT NULL DEFAULT '',
  `customerid` char(30) NOT NULL DEFAULT '',
  `supplierid` char(30) NOT NULL DEFAULT '',
  `salesmanid` char(30) NOT NULL DEFAULT '',
  `servicedoerid` char(30) NOT NULL DEFAULT '',
  `employeeid` char(30) NOT NULL DEFAULT '',
  `usercreate` char(16) NOT NULL DEFAULT '',
  `useredit` char(16) NOT NULL DEFAULT '',
  `updatetimestamp` timestamp NOT NULL DEFAULT current_timestamp() ON UPDATE current_timestamp()
) ENGINE=InnoDB DEFAULT CHARSET=utf8mb4 COLLATE=utf8mb4_unicode_ci;

CREATE TABLE `holidays` (
  `adate` date NOT NULL,
  `description` varchar(100) NOT NULL DEFAULT ''
) ENGINE=InnoDB DEFAULT CHARSET=utf8mb4 COLLATE=utf8mb4_unicode_ci;

INSERT INTO `holidays` (`adate`, `description`) VALUES
('2011-02-01', 'Tahun baru Masehi'),
('2011-02-03', 'Tahun baru Imlek'),
('2011-02-15', 'Maulid Nabi Muhammad SAW'),
('2011-03-05', 'Tahun baru Saka'),
('2011-04-22', 'Wafat Yesus Kristus'),
('2011-05-17', 'Hari raya Waisak'),
('2011-06-02', 'Kenaikan Yesus Kristus'),
('2011-06-29', 'Isra\' Mi\'raj Nabi Muhammad SAW'),
('2011-08-17', 'Hari Kemerdekaan RI'),
('2011-08-30', 'Hari raya Idul Fitri'),
('2011-08-31', 'Hari raya Idul Fitri'),
('2011-11-06', 'Hari raya Idul Adha'),
('2011-11-27', 'Tahun baru Hijriyah'),
('2011-12-25', 'Hari raya Natal');

CREATE TABLE `inputpayablebal` (
  `id` char(30) NOT NULL DEFAULT '',
  `transdate` date DEFAULT NULL,
  `transtime` time DEFAULT NULL,
  `division` char(10) NOT NULL DEFAULT '',
  `accountid` char(30) NOT NULL DEFAULT '',
  `memo` varchar(200) NOT NULL DEFAULT '',
  `usercreate` char(16) NOT NULL DEFAULT '',
  `useredit` char(16) NOT NULL DEFAULT '',
  `updatetimestamp` timestamp NOT NULL DEFAULT current_timestamp() ON UPDATE current_timestamp()
) ENGINE=InnoDB DEFAULT CHARSET=utf8mb4 COLLATE=utf8mb4_unicode_ci;

CREATE TABLE `inputreceivablebal` (
  `id` char(30) NOT NULL DEFAULT '',
  `transdate` date DEFAULT NULL,
  `transtime` time DEFAULT NULL,
  `division` char(10) NOT NULL DEFAULT '',
  `accountid` char(30) NOT NULL DEFAULT '',
  `memo` varchar(200) NOT NULL DEFAULT '',
  `usercreate` char(16) NOT NULL DEFAULT '',
  `useredit` char(16) NOT NULL DEFAULT '',
  `updatetimestamp` timestamp NOT NULL DEFAULT current_timestamp() ON UPDATE current_timestamp()
) ENGINE=InnoDB DEFAULT CHARSET=utf8mb4 COLLATE=utf8mb4_unicode_ci;

CREATE TABLE `inventory` (
  `id` bigint(20) UNSIGNED NOT NULL,
  `transid` char(30) NOT NULL DEFAULT '',
  `transdate` datetime DEFAULT NULL,
  `departement` char(10) NOT NULL DEFAULT '',
  `division` char(10) NOT NULL DEFAULT '',
  `productid` char(30) NOT NULL DEFAULT '',
  `snproduct` varchar(100) NOT NULL DEFAULT '',
  `expireddate` date DEFAULT NULL,
  `invin` double NOT NULL DEFAULT 0,
  `invout` double NOT NULL DEFAULT 0,
  `transtype` tinyint(4) NOT NULL DEFAULT 0,
  `memo` varchar(200) NOT NULL DEFAULT '',
  `usercreate` char(16) NOT NULL DEFAULT '',
  `useredit` char(16) NOT NULL DEFAULT '',
  `updatetimestamp` timestamp NOT NULL DEFAULT current_timestamp() ON UPDATE current_timestamp()
) ENGINE=InnoDB DEFAULT CHARSET=utf8mb4 COLLATE=utf8mb4_unicode_ci;

CREATE TABLE `inventoryadjust` (
  `id` char(30) NOT NULL DEFAULT '',
  `transdate` date DEFAULT NULL,
  `transtime` time DEFAULT NULL,
  `division` char(10) NOT NULL DEFAULT '',
  `departement` char(10) NOT NULL DEFAULT '',
  `accountid` char(30) NOT NULL DEFAULT '',
  `memo` varchar(250) NOT NULL DEFAULT '',
  `memoedit` varchar(250) NOT NULL DEFAULT '',
  `posted` smallint(6) NOT NULL DEFAULT 0,
  `usercreate` char(16) NOT NULL DEFAULT '',
  `useredit` char(16) NOT NULL DEFAULT '',
  `updatetimestamp` timestamp NOT NULL DEFAULT current_timestamp() ON UPDATE current_timestamp()
) ENGINE=InnoDB DEFAULT CHARSET=utf8mb4 COLLATE=utf8mb4_unicode_ci;

CREATE TABLE `inventoryadjustdetail` (
  `id` bigint(20) UNSIGNED NOT NULL,
  `transid` char(30) NOT NULL DEFAULT '',
  `transdate` datetime DEFAULT NULL,
  `productid` char(30) NOT NULL DEFAULT '',
  `productname` varchar(100) NOT NULL DEFAULT '',
  `snproduct` varchar(100) NOT NULL DEFAULT '',
  `expireddate` date DEFAULT NULL,
  `unit` char(10) NOT NULL DEFAULT '',
  `cogs` double NOT NULL DEFAULT 0,
  `recorded` double NOT NULL DEFAULT 0,
  `physical` double NOT NULL DEFAULT 0,
  `inqty` double DEFAULT 0,
  `outqty` double DEFAULT 0,
  `invalue` double DEFAULT 0,
  `outvalue` double DEFAULT 0,
  `memo` varchar(200) NOT NULL DEFAULT '',
  `usercreate` char(16) NOT NULL DEFAULT '',
  `useredit` char(16) NOT NULL DEFAULT '',
  `updatetimestamp` timestamp NOT NULL DEFAULT current_timestamp() ON UPDATE current_timestamp()
) ENGINE=InnoDB DEFAULT CHARSET=utf8mb4 COLLATE=utf8mb4_unicode_ci;

CREATE TABLE `inventoryin` (
  `id` char(30) NOT NULL DEFAULT '',
  `transdate` date DEFAULT NULL,
  `transtime` time DEFAULT NULL,
  `division` char(10) NOT NULL DEFAULT '',
  `departement` char(10) NOT NULL DEFAULT '',
  `accountid` char(30) NOT NULL DEFAULT '',
  `memo` varchar(200) NOT NULL DEFAULT '',
  `usercreate` char(16) NOT NULL DEFAULT '',
  `useredit` char(16) NOT NULL DEFAULT '',
  `updatetimestamp` timestamp NOT NULL DEFAULT current_timestamp() ON UPDATE current_timestamp()
) ENGINE=InnoDB DEFAULT CHARSET=utf8mb4 COLLATE=utf8mb4_unicode_ci;

CREATE TABLE `inventoryindetail` (
  `id` bigint(20) UNSIGNED NOT NULL,
  `transid` char(30) NOT NULL DEFAULT '',
  `transdate` datetime DEFAULT NULL,
  `productid` char(30) NOT NULL DEFAULT '',
  `productname` varchar(100) NOT NULL DEFAULT '',
  `usesn` smallint(6) NOT NULL DEFAULT 0,
  `snproduct` varchar(100) NOT NULL DEFAULT '',
  `expireddate` date DEFAULT NULL,
  `unit` char(10) NOT NULL DEFAULT '',
  `qty` double DEFAULT 0,
  `unitqty` double DEFAULT 0,
  `cogs` double DEFAULT 0,
  `subtotal` double DEFAULT 0,
  `memo` varchar(200) NOT NULL DEFAULT '',
  `usercreate` char(16) NOT NULL DEFAULT '',
  `useredit` char(16) NOT NULL DEFAULT '',
  `updatetimestamp` timestamp NOT NULL DEFAULT current_timestamp() ON UPDATE current_timestamp()
) ENGINE=InnoDB DEFAULT CHARSET=utf8mb4 COLLATE=utf8mb4_unicode_ci;

CREATE TABLE `inventorymoving` (
  `id` char(30) NOT NULL DEFAULT '',
  `transdate` date DEFAULT NULL,
  `transtime` time DEFAULT NULL,
  `fromdivision` char(10) NOT NULL DEFAULT '',
  `fromdepartement` char(10) NOT NULL DEFAULT '',
  `todivision` char(10) NOT NULL DEFAULT '',
  `todepartement` char(10) NOT NULL DEFAULT '',
  `approved` int(11) NOT NULL DEFAULT 1,
  `memo` varchar(250) NOT NULL DEFAULT '',
  `memoedit` varchar(250) NOT NULL DEFAULT '',
  `usercreate` char(16) NOT NULL DEFAULT '',
  `useredit` char(16) NOT NULL DEFAULT '',
  `updatetimestamp` timestamp NOT NULL DEFAULT current_timestamp() ON UPDATE current_timestamp()
) ENGINE=InnoDB DEFAULT CHARSET=utf8mb4 COLLATE=utf8mb4_unicode_ci;

CREATE TABLE `inventorymovingdetail` (
  `id` bigint(20) UNSIGNED NOT NULL,
  `transid` char(30) NOT NULL DEFAULT '',
  `transdate` datetime DEFAULT NULL,
  `productid` char(30) NOT NULL DEFAULT '',
  `productname` varchar(100) NOT NULL DEFAULT '',
  `usesn` smallint(6) NOT NULL DEFAULT 0,
  `snproduct` varchar(100) NOT NULL DEFAULT '',
  `expireddate` date DEFAULT NULL,
  `unit` char(10) NOT NULL DEFAULT '',
  `qty` double DEFAULT 0,
  `unitqty` double DEFAULT 0,
  `memo` varchar(200) NOT NULL DEFAULT '',
  `usercreate` char(16) NOT NULL DEFAULT '',
  `useredit` char(16) NOT NULL DEFAULT '',
  `updatetimestamp` timestamp NOT NULL DEFAULT current_timestamp() ON UPDATE current_timestamp()
) ENGINE=InnoDB DEFAULT CHARSET=utf8mb4 COLLATE=utf8mb4_unicode_ci;

CREATE TABLE `inventoryout` (
  `id` char(30) NOT NULL DEFAULT '',
  `transdate` date DEFAULT NULL,
  `transtime` time DEFAULT NULL,
  `division` char(10) NOT NULL DEFAULT '',
  `departement` char(10) NOT NULL DEFAULT '',
  `accountid` char(30) NOT NULL DEFAULT '',
  `accountname` varchar(150) NOT NULL DEFAULT '',
  `memo` varchar(200) NOT NULL DEFAULT '',
  `usercreate` char(16) NOT NULL DEFAULT '',
  `useredit` char(16) NOT NULL DEFAULT '',
  `updatetimestamp` timestamp NOT NULL DEFAULT current_timestamp() ON UPDATE current_timestamp()
) ENGINE=InnoDB DEFAULT CHARSET=utf8mb4 COLLATE=utf8mb4_unicode_ci;

CREATE TABLE `inventoryoutdetail` (
  `id` bigint(20) UNSIGNED NOT NULL,
  `transid` char(30) NOT NULL DEFAULT '',
  `transdate` datetime DEFAULT NULL,
  `productid` char(30) NOT NULL DEFAULT '',
  `productname` varchar(100) NOT NULL DEFAULT '',
  `usesn` smallint(6) NOT NULL DEFAULT 0,
  `snproduct` varchar(100) NOT NULL DEFAULT '',
  `expireddate` date DEFAULT NULL,
  `unit` char(10) NOT NULL DEFAULT '',
  `qty` double DEFAULT 0,
  `unitqty` double DEFAULT 0,
  `cogs` double DEFAULT 0,
  `subtotal` double DEFAULT 0,
  `memo` varchar(200) NOT NULL DEFAULT '',
  `usercreate` char(16) NOT NULL DEFAULT '',
  `useredit` char(16) NOT NULL DEFAULT '',
  `updatetimestamp` timestamp NOT NULL DEFAULT current_timestamp() ON UPDATE current_timestamp()
) ENGINE=InnoDB DEFAULT CHARSET=utf8mb4 COLLATE=utf8mb4_unicode_ci;

CREATE TABLE `journal` (
  `jtid` varchar(30) NOT NULL DEFAULT '',
  `jtdate` date DEFAULT NULL,
  `jttime` time DEFAULT NULL,
  `memo` varchar(100) NOT NULL DEFAULT '',
  `memoedit` varchar(100) NOT NULL DEFAULT '',
  `division` char(10) NOT NULL DEFAULT '',
  `journalvalue` double NOT NULL DEFAULT 0,
  `printed` smallint(6) NOT NULL DEFAULT 0,
  `approved` int(11) NOT NULL DEFAULT 1,
  `usercreate` char(16) NOT NULL DEFAULT '',
  `useredit` char(16) NOT NULL DEFAULT '',
  `updatetimestamp` timestamp NOT NULL DEFAULT current_timestamp() ON UPDATE current_timestamp()
) ENGINE=InnoDB DEFAULT CHARSET=utf8mb4 COLLATE=utf8mb4_unicode_ci;

CREATE TABLE `journalclose` (
  `jtid` varchar(30) NOT NULL DEFAULT '',
  `jtdate` date DEFAULT NULL,
  `jttime` time DEFAULT NULL,
  `accountid` char(30) NOT NULL DEFAULT '',
  `accountname` varchar(150) NOT NULL DEFAULT '',
  `journalvalue` double NOT NULL DEFAULT 0,
  `memo` varchar(100) NOT NULL DEFAULT '',
  `memoedit` varchar(100) NOT NULL DEFAULT '',
  `division` char(10) NOT NULL DEFAULT '',
  `printed` smallint(6) NOT NULL DEFAULT 0,
  `usercreate` char(16) NOT NULL DEFAULT '',
  `useredit` char(16) NOT NULL DEFAULT '',
  `updatetimestamp` timestamp NOT NULL DEFAULT current_timestamp() ON UPDATE current_timestamp()
) ENGINE=InnoDB DEFAULT CHARSET=utf8mb4 COLLATE=utf8mb4_unicode_ci;

CREATE TABLE `journalexpense` (
  `jtid` varchar(30) NOT NULL DEFAULT '',
  `jtdate` date DEFAULT NULL,
  `jttime` time DEFAULT NULL,
  `paymenttype` int(10) UNSIGNED NOT NULL,
  `approved` int(11) NOT NULL DEFAULT 1,
  `journalvalue` double NOT NULL DEFAULT 0,
  `memo` varchar(100) NOT NULL DEFAULT '',
  `memoedit` varchar(100) NOT NULL DEFAULT '',
  `division` char(10) NOT NULL DEFAULT '',
  `printed` smallint(6) NOT NULL DEFAULT 0,
  `usercreate` char(16) NOT NULL DEFAULT '',
  `useredit` char(16) NOT NULL DEFAULT '',
  `updatetimestamp` timestamp NOT NULL DEFAULT current_timestamp() ON UPDATE current_timestamp()
) ENGINE=InnoDB DEFAULT CHARSET=utf8mb4 COLLATE=utf8mb4_unicode_ci;

CREATE TABLE `journalexpensedetail` (
  `id` bigint(20) UNSIGNED NOT NULL,
  `jtid` varchar(30) NOT NULL DEFAULT '',
  `memo` varchar(100) NOT NULL DEFAULT '',
  `accountid` char(30) NOT NULL DEFAULT '',
  `accountname` varchar(150) NOT NULL DEFAULT '',
  `value` double NOT NULL DEFAULT 0,
  `updatetimestamp` timestamp NOT NULL DEFAULT current_timestamp() ON UPDATE current_timestamp()
) ENGINE=InnoDB DEFAULT CHARSET=utf8mb4 COLLATE=utf8mb4_unicode_ci;

CREATE TABLE `journalrevenue` (
  `jtid` varchar(30) NOT NULL DEFAULT '',
  `jtdate` date DEFAULT NULL,
  `jttime` time DEFAULT NULL,
  `paymenttype` int(10) UNSIGNED NOT NULL,
  `approved` int(11) NOT NULL DEFAULT 1,
  `journalvalue` double NOT NULL DEFAULT 0,
  `memo` varchar(100) NOT NULL DEFAULT '',
  `memoedit` varchar(100) NOT NULL DEFAULT '',
  `division` char(10) NOT NULL DEFAULT '',
  `printed` smallint(6) NOT NULL DEFAULT 0,
  `usercreate` char(16) NOT NULL DEFAULT '',
  `useredit` char(16) NOT NULL DEFAULT '',
  `updatetimestamp` timestamp NOT NULL DEFAULT current_timestamp() ON UPDATE current_timestamp()
) ENGINE=InnoDB DEFAULT CHARSET=utf8mb4 COLLATE=utf8mb4_unicode_ci;

CREATE TABLE `journalrevenuedetail` (
  `id` bigint(20) UNSIGNED NOT NULL,
  `jtid` varchar(30) NOT NULL DEFAULT '',
  `memo` varchar(100) NOT NULL DEFAULT '',
  `accountid` char(30) NOT NULL DEFAULT '',
  `accountname` varchar(150) NOT NULL DEFAULT '',
  `value` double NOT NULL DEFAULT 0,
  `updatetimestamp` timestamp NOT NULL DEFAULT current_timestamp() ON UPDATE current_timestamp()
) ENGINE=InnoDB DEFAULT CHARSET=utf8mb4 COLLATE=utf8mb4_unicode_ci;

CREATE TABLE `journaltrans` (
  `id` bigint(20) UNSIGNED NOT NULL,
  `jtid` varchar(30) NOT NULL DEFAULT '',
  `jtdate` datetime DEFAULT NULL,
  `memo` varchar(100) NOT NULL DEFAULT '',
  `accountid` char(30) NOT NULL DEFAULT '',
  `accountname` varchar(150) NOT NULL DEFAULT '',
  `debit` double NOT NULL DEFAULT 0,
  `credit` double NOT NULL DEFAULT 0,
  `division` char(10) NOT NULL DEFAULT '',
  `reftransaction` char(50) NOT NULL DEFAULT '',
  `approved` int(11) NOT NULL DEFAULT 1,
  `usercreate` char(16) NOT NULL DEFAULT '',
  `useredit` char(16) NOT NULL DEFAULT '',
  `updatetimestamp` timestamp NOT NULL DEFAULT current_timestamp() ON UPDATE current_timestamp()
) ENGINE=InnoDB DEFAULT CHARSET=utf8mb4 COLLATE=utf8mb4_unicode_ci;

CREATE TABLE `langoverrides` (
  `id` bigint(20) UNSIGNED NOT NULL,
  `lang` varchar(20) NOT NULL,
  `langkey` varchar(255) NOT NULL,
  `value` text NOT NULL,
  `usercreate` varchar(100) DEFAULT NULL,
  `useredit` varchar(100) DEFAULT NULL,
  `updatetimestamp` timestamp NOT NULL DEFAULT current_timestamp() ON UPDATE current_timestamp()
) ENGINE=InnoDB DEFAULT CHARSET=utf8mb4 COLLATE=utf8mb4_unicode_ci;

CREATE TABLE `logtransactions` (
  `id` bigint(20) UNSIGNED NOT NULL,
  `userid` char(16) NOT NULL DEFAULT '',
  `summary` tinytext NOT NULL,
  `transtimestamp` timestamp NOT NULL DEFAULT current_timestamp(),
  `fromtransaction` varchar(100) NOT NULL DEFAULT '0'
) ENGINE=InnoDB DEFAULT CHARSET=utf8mb4 COLLATE=utf8mb4_unicode_ci;

CREATE TABLE `mrpbomcomponent` (
  `id` bigint(20) UNSIGNED NOT NULL,
  `mrpproduct` char(30) NOT NULL DEFAULT '',
  `productid` char(30) NOT NULL DEFAULT '',
  `productname` varchar(100) NOT NULL DEFAULT '0',
  `qty` double NOT NULL DEFAULT 0,
  `unit` char(10) NOT NULL DEFAULT '',
  `usercreate` char(16) NOT NULL DEFAULT '',
  `useredit` char(16) NOT NULL DEFAULT '',
  `updatetimestamp` timestamp NOT NULL DEFAULT current_timestamp() ON UPDATE current_timestamp()
) ENGINE=InnoDB DEFAULT CHARSET=utf8mb4 COLLATE=utf8mb4_unicode_ci;

CREATE TABLE `mrpbomoperation` (
  `id` bigint(20) UNSIGNED NOT NULL,
  `mrpproduct` char(30) NOT NULL DEFAULT '0',
  `operationid` bigint(20) UNSIGNED NOT NULL DEFAULT 0,
  `name` varchar(100) NOT NULL DEFAULT '',
  `unitoperation` varchar(10) NOT NULL DEFAULT '',
  `labourcost` double NOT NULL DEFAULT 0,
  `duration` double NOT NULL DEFAULT 0,
  `unitduration` varchar(10) NOT NULL DEFAULT '',
  `usercreate` char(16) NOT NULL DEFAULT '',
  `useredit` char(16) NOT NULL DEFAULT '',
  `updatetimestamp` timestamp NOT NULL DEFAULT current_timestamp() ON UPDATE current_timestamp()
) ENGINE=InnoDB DEFAULT CHARSET=utf8mb4 COLLATE=utf8mb4_unicode_ci;

CREATE TABLE `mrpoperation` (
  `id` bigint(20) UNSIGNED NOT NULL,
  `name` varchar(100) NOT NULL DEFAULT '',
  `unitoperation` varchar(10) NOT NULL DEFAULT '',
  `labourcost` double NOT NULL DEFAULT 0,
  `duration` double NOT NULL DEFAULT 0,
  `unitduration` varchar(10) NOT NULL DEFAULT '',
  `workcenter` bigint(20) UNSIGNED NOT NULL DEFAULT 0,
  `isactive` smallint(6) NOT NULL DEFAULT 1,
  `wageaccount` char(30) NOT NULL DEFAULT '',
  `usercreate` char(16) NOT NULL DEFAULT '',
  `useredit` char(16) NOT NULL DEFAULT '',
  `updatetimestamp` timestamp NOT NULL DEFAULT current_timestamp() ON UPDATE current_timestamp()
) ENGINE=InnoDB DEFAULT CHARSET=utf8mb4 COLLATE=utf8mb4_unicode_ci;

CREATE TABLE `mrporder` (
  `transid` char(30) NOT NULL DEFAULT '',
  `division` char(10) NOT NULL DEFAULT '',
  `departement` char(10) NOT NULL DEFAULT '',
  `workcenter` bigint(20) UNSIGNED NOT NULL DEFAULT 0,
  `createfromsales` tinyint(4) NOT NULL DEFAULT 1,
  `salesid` char(30) NOT NULL DEFAULT '',
  `salesproduct` char(30) NOT NULL DEFAULT '',
  `productid` char(30) NOT NULL DEFAULT '',
  `productname` varchar(100) NOT NULL DEFAULT '',
  `qtyorder` double NOT NULL DEFAULT 0,
  `qtyfail` double NOT NULL DEFAULT 0,
  `qtyproduced` double NOT NULL DEFAULT 0,
  `unit` char(10) NOT NULL DEFAULT '',
  `snproduct` varchar(100) NOT NULL DEFAULT '',
  `expireddate` date DEFAULT NULL,
  `memo` text NOT NULL,
  `orderdate` datetime DEFAULT NULL,
  `startdate` datetime DEFAULT NULL,
  `expfinishdate` datetime DEFAULT NULL,
  `deadlinedate` datetime DEFAULT NULL,
  `realfinishdate` datetime DEFAULT NULL,
  `status` tinyint(4) NOT NULL DEFAULT 0 COMMENT '0=order, 1=ready, 2=process, 3=finish, 4=release',
  `oldcogs` double NOT NULL DEFAULT 0,
  `newcogs` double NOT NULL DEFAULT 0,
  `usercreate` char(16) NOT NULL DEFAULT '',
  `useredit` char(16) NOT NULL DEFAULT '',
  `updatetimestamp` timestamp NOT NULL DEFAULT current_timestamp() ON UPDATE current_timestamp()
) ENGINE=InnoDB DEFAULT CHARSET=utf8mb4 COLLATE=utf8mb4_unicode_ci;

CREATE TABLE `mrpordercomponent` (
  `id` bigint(20) UNSIGNED NOT NULL,
  `mrporder` char(30) NOT NULL DEFAULT '',
  `productid` char(30) NOT NULL DEFAULT '',
  `productname` varchar(100) NOT NULL DEFAULT '0',
  `qty` double NOT NULL DEFAULT 0,
  `totalqty` double NOT NULL DEFAULT 0,
  `riilqty` double NOT NULL DEFAULT 0,
  `diffqty` double NOT NULL DEFAULT 0,
  `unit` char(10) NOT NULL DEFAULT '',
  `snproduct` varchar(100) NOT NULL DEFAULT '',
  `expireddate` date DEFAULT NULL,
  `cogs` double NOT NULL DEFAULT 0,
  `subtotal` double NOT NULL DEFAULT 0,
  `usercreate` char(16) NOT NULL DEFAULT '',
  `useredit` char(16) NOT NULL DEFAULT '',
  `updatetimestamp` timestamp NOT NULL DEFAULT current_timestamp() ON UPDATE current_timestamp()
) ENGINE=InnoDB DEFAULT CHARSET=utf8mb4 COLLATE=utf8mb4_unicode_ci;

CREATE TABLE `mrpworkcenter` (
  `id` bigint(20) UNSIGNED NOT NULL,
  `name` varchar(100) NOT NULL DEFAULT '',
  `division` char(10) NOT NULL DEFAULT '',
  `productiondepartement` char(10) NOT NULL DEFAULT '',
  `storedepartement` char(10) NOT NULL DEFAULT '',
  `memo` text NOT NULL,
  `usercreate` char(16) NOT NULL DEFAULT '',
  `useredit` char(16) NOT NULL DEFAULT '',
  `updatetimestamp` timestamp NOT NULL DEFAULT current_timestamp() ON UPDATE current_timestamp()
) ENGINE=InnoDB DEFAULT CHARSET=utf8mb4 COLLATE=utf8mb4_unicode_ci;

CREATE TABLE `mrpworkorder` (
  `id` bigint(20) UNSIGNED NOT NULL,
  `mrporder` char(30) NOT NULL DEFAULT '',
  `operationid` bigint(20) UNSIGNED NOT NULL DEFAULT 0,
  `name` varchar(100) NOT NULL DEFAULT '',
  `qtyorder` double NOT NULL DEFAULT 0,
  `qtyfail` double NOT NULL DEFAULT 0,
  `qtyproduced` double NOT NULL DEFAULT 0,
  `unitoperation` varchar(10) NOT NULL DEFAULT '',
  `labourcost` double NOT NULL DEFAULT 0,
  `totallabourcost` double NOT NULL DEFAULT 0,
  `duration` double NOT NULL DEFAULT 0,
  `totalduration` double NOT NULL DEFAULT 0,
  `unitduration` varchar(10) NOT NULL DEFAULT '',
  `orderdate` datetime DEFAULT NULL,
  `startdate` datetime DEFAULT NULL,
  `expfinishdate` datetime DEFAULT NULL,
  `deadlinedate` datetime DEFAULT NULL,
  `realfinishdate` datetime DEFAULT NULL,
  `status` tinyint(4) NOT NULL DEFAULT 0 COMMENT '0=order, 1=ready, 2=process, 3=finish',
  `usercreate` char(16) NOT NULL DEFAULT '',
  `useredit` char(16) NOT NULL DEFAULT '',
  `updatetimestamp` timestamp NOT NULL DEFAULT current_timestamp() ON UPDATE current_timestamp()
) ENGINE=InnoDB DEFAULT CHARSET=utf8mb4 COLLATE=utf8mb4_unicode_ci;

CREATE TABLE `mrpworkorderemployee` (
  `id` bigint(20) UNSIGNED NOT NULL,
  `workorderid` bigint(20) UNSIGNED NOT NULL DEFAULT 0,
  `employeeid` char(30) NOT NULL DEFAULT '',
  `name` varchar(100) NOT NULL DEFAULT '',
  `qty` double NOT NULL DEFAULT 0,
  `unitoperation` varchar(10) NOT NULL DEFAULT '',
  `updatetimestamp` timestamp NOT NULL DEFAULT current_timestamp() ON UPDATE current_timestamp()
) ENGINE=InnoDB DEFAULT CHARSET=utf8mb4 COLLATE=utf8mb4_unicode_ci;

CREATE TABLE `onlinepayments` (
  `id` int(11) NOT NULL,
  `order_id` varchar(100) NOT NULL,
  `gateway` varchar(50) NOT NULL,
  `amount` decimal(18,8) NOT NULL,
  `currency` varchar(10) NOT NULL,
  `status` enum('pending','paid','failed','cancelled') NOT NULL DEFAULT 'pending',
  `transaction_reference` varchar(255) NOT NULL DEFAULT '',
  `created_at` timestamp NULL DEFAULT current_timestamp(),
  `updated_at` timestamp NULL DEFAULT current_timestamp() ON UPDATE current_timestamp()
) ENGINE=InnoDB DEFAULT CHARSET=utf8mb4 COLLATE=utf8mb4_unicode_ci;

CREATE TABLE `payableadjust` (
  `transid` char(30) NOT NULL DEFAULT '',
  `transdate` date DEFAULT NULL,
  `transtime` time DEFAULT NULL,
  `supplierid` char(30) NOT NULL DEFAULT '',
  `suppliername` varchar(100) NOT NULL DEFAULT '',
  `supplieraddress` varchar(200) NOT NULL DEFAULT '',
  `currtrans` char(3) NOT NULL DEFAULT '',
  `ratedefault` double NOT NULL DEFAULT 0,
  `rateused` double NOT NULL DEFAULT 0,
  `expensestype` int(10) UNSIGNED NOT NULL,
  `debit` double NOT NULL DEFAULT 0,
  `credit` double NOT NULL DEFAULT 0,
  `memo` varchar(250) NOT NULL DEFAULT '',
  `memoedit` varchar(250) NOT NULL DEFAULT '',
  `division` char(10) NOT NULL DEFAULT '',
  `printed` smallint(6) NOT NULL DEFAULT 0,
  `usercreate` char(16) NOT NULL DEFAULT '',
  `useredit` char(16) NOT NULL DEFAULT '',
  `updatetimestamp` timestamp NOT NULL DEFAULT current_timestamp() ON UPDATE current_timestamp()
) ENGINE=InnoDB DEFAULT CHARSET=utf8mb4 COLLATE=utf8mb4_unicode_ci;

CREATE TABLE `payablepayment` (
  `transid` char(30) NOT NULL DEFAULT '',
  `transdate` date DEFAULT NULL,
  `transtime` time DEFAULT NULL,
  `supplierid` char(30) NOT NULL DEFAULT '',
  `suppliername` varchar(100) NOT NULL DEFAULT '',
  `supplieraddress` varchar(200) NOT NULL DEFAULT '',
  `currtrans` char(3) NOT NULL DEFAULT '',
  `ratedefault` double NOT NULL DEFAULT 0,
  `rateused` double NOT NULL DEFAULT 0,
  `paymenttype` int(10) UNSIGNED NOT NULL,
  `kind` int(10) UNSIGNED NOT NULL DEFAULT 0,
  `refpayment` varchar(30) NOT NULL DEFAULT '',
  `amount` double NOT NULL DEFAULT 0,
  `discountvalue` double NOT NULL DEFAULT 0,
  `netpayment` double NOT NULL DEFAULT 0,
  `memo` varchar(250) NOT NULL DEFAULT '',
  `memoedit` varchar(250) NOT NULL DEFAULT '',
  `division` char(10) NOT NULL DEFAULT '',
  `accepted` smallint(6) NOT NULL DEFAULT 0,
  `duedate` date DEFAULT NULL,
  `accepteddate` date DEFAULT NULL,
  `printed` smallint(6) NOT NULL DEFAULT 0,
  `usercreate` char(16) NOT NULL DEFAULT '',
  `useredit` char(16) NOT NULL DEFAULT '',
  `updatetimestamp` timestamp NOT NULL DEFAULT current_timestamp() ON UPDATE current_timestamp()
) ENGINE=InnoDB DEFAULT CHARSET=utf8mb4 COLLATE=utf8mb4_unicode_ci;

CREATE TABLE `paymentdiscrules` (
  `id` int(10) UNSIGNED NOT NULL DEFAULT 0,
  `description` varchar(100) NOT NULL DEFAULT '',
  `displayname` varchar(20) NOT NULL DEFAULT '',
  `formula` text DEFAULT NULL,
  `kind` int(11) NOT NULL DEFAULT 0,
  `usercreate` char(16) NOT NULL DEFAULT '',
  `useredit` char(16) NOT NULL DEFAULT '',
  `updatetimestamp` timestamp NOT NULL DEFAULT current_timestamp() ON UPDATE current_timestamp()
) ENGINE=InnoDB DEFAULT CHARSET=utf8mb4 COLLATE=utf8mb4_unicode_ci;

CREATE TABLE `paymenttype` (
  `id` int(10) UNSIGNED NOT NULL DEFAULT 0,
  `name` varchar(50) NOT NULL DEFAULT '',
  `description` varchar(100) NOT NULL DEFAULT '',
  `paymentacc` char(30) NOT NULL DEFAULT '',
  `cashdiscacc` char(30) NOT NULL DEFAULT '',
  `expenseacc` char(30) NOT NULL DEFAULT '',
  `defexpense` float NOT NULL DEFAULT 0,
  `kind` smallint(6) NOT NULL DEFAULT 0,
  `qrcode` varchar(255) NOT NULL DEFAULT '[]',
  `pointpayment` double NOT NULL DEFAULT 0,
  `isactive` int(11) NOT NULL DEFAULT 1,
  `usercreate` char(16) NOT NULL DEFAULT '',
  `useredit` char(16) NOT NULL DEFAULT '',
  `updatetimestamp` timestamp NOT NULL DEFAULT current_timestamp() ON UPDATE current_timestamp()
) ENGINE=InnoDB DEFAULT CHARSET=utf8mb4 COLLATE=utf8mb4_unicode_ci;

CREATE TABLE `pointofsales` (
  `id` bigint(20) UNSIGNED NOT NULL,
  `name` varchar(50) NOT NULL DEFAULT '',
  `productgroup` text NOT NULL,
  `paymenttype` text NOT NULL,
  `paymentdefault` int(10) UNSIGNED NOT NULL DEFAULT 0,
  `customerdefault` char(30) NOT NULL DEFAULT '',
  `salesmandefault` char(30) NOT NULL DEFAULT '',
  `servicedoerdefault` char(30) NOT NULL DEFAULT '',
  `division` char(10) NOT NULL DEFAULT '',
  `departement` char(10) NOT NULL DEFAULT '',
  `shipment` int(10) UNSIGNED NOT NULL DEFAULT 0,
  `postingsummary` int(11) NOT NULL DEFAULT 0,
  `user` char(16) NOT NULL DEFAULT '',
  `openingdate` datetime DEFAULT NULL,
  `closingdate` datetime DEFAULT NULL,
  `status` int(11) DEFAULT 0,
  `printcashier` int(11) DEFAULT NULL,
  `printorder` text DEFAULT NULL,
  `frmsalesid` varchar(50) DEFAULT '',
  `currentsalesid` int(11) DEFAULT 0,
  `beginningbalance` double DEFAULT 0,
  `currentbalance` double DEFAULT 0,
  `endbalance` double DEFAULT 0,
  `showcategory` int(11) DEFAULT 1,
  `cacheproduct` int(11) DEFAULT NULL,
  `layout` int(11) DEFAULT 0,
  `showimage` int(11) DEFAULT 0,
  `usetable` int(11) DEFAULT 0,
  `orderfromvisitor` int(11) NOT NULL DEFAULT 0,
  `tables` text DEFAULT NULL,
  `autoprint` int(11) DEFAULT 1,
  `autofillpayment` int(11) DEFAULT 0,
  `customerdisplayconnect` int(11) DEFAULT 0,
  `slideid` int(11) DEFAULT 0,
  `printdensity` int(11) DEFAULT 0,
  `printasimage` int(11) DEFAULT 0,
  `paperwidth` float DEFAULT 80,
  `orderdesign` varchar(100) NOT NULL DEFAULT 'posorder.posorder',
  `cashierdesign` varchar(100) NOT NULL DEFAULT 'poscashier.poscashier',
  `reportdesign` varchar(100) NOT NULL DEFAULT 'posreport.posreport',
  `sourcecash` char(30) NOT NULL DEFAULT '',
  `barcodedecoder` int(11) NOT NULL DEFAULT 0,
  `barcodedecoderformat` varchar(50) NOT NULL DEFAULT ''
) ENGINE=InnoDB DEFAULT CHARSET=utf8mb4 COLLATE=utf8mb4_unicode_ci;

CREATE TABLE `poshistories` (
  `id` bigint(20) UNSIGNED NOT NULL,
  `name` varchar(50) NOT NULL DEFAULT '',
  `posid` bigint(20) UNSIGNED NOT NULL,
  `user` char(16) NOT NULL DEFAULT '',
  `openingdate` datetime DEFAULT NULL,
  `closingdate` datetime DEFAULT NULL,
  `beginningbalance` double DEFAULT 0,
  `endbalance` double DEFAULT 0,
  `diffcash` double DEFAULT 0,
  `invoicecount` int(11) NOT NULL DEFAULT 0,
  `productcount` int(11) NOT NULL DEFAULT 0,
  `rewardcount` int(11) NOT NULL DEFAULT 0,
  `customercount` int(11) NOT NULL DEFAULT 0,
  `totalsales` double NOT NULL DEFAULT 0
) ENGINE=InnoDB DEFAULT CHARSET=utf8mb4 COLLATE=utf8mb4_unicode_ci;

CREATE TABLE `posprintcashier` (
  `id` bigint(20) UNSIGNED NOT NULL,
  `name` varchar(50) NOT NULL DEFAULT '',
  `apsserver` varchar(50) NOT NULL DEFAULT '',
  `active` int(11) NOT NULL DEFAULT 1,
  `apsandroid` int(11) NOT NULL DEFAULT 0,
  `usercreate` char(16) NOT NULL DEFAULT '',
  `useredit` char(16) NOT NULL DEFAULT '',
  `updatetimestamp` timestamp NOT NULL DEFAULT current_timestamp() ON UPDATE current_timestamp()
) ENGINE=InnoDB DEFAULT CHARSET=utf8mb4 COLLATE=utf8mb4_unicode_ci;

INSERT INTO `posprintcashier` (`id`, `name`, `apsserver`, `active`, `apsandroid`, `usercreate`, `useredit`, `updatetimestamp`) VALUES
(1, 'Printer 1', 'http://127.0.0.1:8001', 1, 0, 'admin', 'admin', '2024-06-26 09:03:52');

CREATE TABLE `posprintorder` (
  `id` bigint(20) UNSIGNED NOT NULL,
  `name` varchar(50) NOT NULL DEFAULT '',
  `apsserver` varchar(50) NOT NULL DEFAULT '',
  `productgroup` text NOT NULL,
  `active` int(11) NOT NULL DEFAULT 1,
  `apsandroid` int(11) NOT NULL DEFAULT 0,
  `usercreate` char(16) NOT NULL DEFAULT '',
  `useredit` char(16) NOT NULL DEFAULT '',
  `updatetimestamp` timestamp NOT NULL DEFAULT current_timestamp() ON UPDATE current_timestamp()
) ENGINE=InnoDB DEFAULT CHARSET=utf8mb4 COLLATE=utf8mb4_unicode_ci;

INSERT INTO `posprintorder` (`id`, `name`, `apsserver`, `productgroup`, `active`, `apsandroid`, `usercreate`, `useredit`, `updatetimestamp`) VALUES
(1, 'Printer Dapur 1', 'http://localhost:8001', '[\"11\",\"21\",\"22\"]', 1, 0, 'admin', 'admin', '2025-12-03 20:58:18');

CREATE TABLE `postable` (
  `id` int(11) NOT NULL,
  `name` varchar(100) NOT NULL DEFAULT '',
  `guestcount` int(11) NOT NULL DEFAULT 0,
  `visitorname` varchar(50) NOT NULL DEFAULT '',
  `isactive` int(11) DEFAULT 1,
  `tablegroup` bigint(20) UNSIGNED DEFAULT 0,
  `isrent` int(11) DEFAULT 0,
  `customerid` char(30) DEFAULT '',
  `productid` char(30) DEFAULT '',
  `timeunit` char(10) DEFAULT '',
  `secondtimeunit` char(10) DEFAULT '',
  `notiftimebeforefinish` double DEFAULT 0,
  `limittimestart` double DEFAULT 0,
  `limittimefinish` double DEFAULT 0,
  `minrentperiod` double DEFAULT 0,
  `commandstart` varchar(1000) DEFAULT '',
  `commandwarning` varchar(1000) DEFAULT '',
  `commandfinish` varchar(1000) DEFAULT '',
  `rentqty` double NOT NULL DEFAULT 0,
  `starttime` datetime DEFAULT NULL,
  `finishtime` datetime DEFAULT NULL,
  `unlimited` int(11) DEFAULT 0,
  `salesid` char(30) DEFAULT '',
  `isordervisitor` int(11) NOT NULL DEFAULT 0,
  `firstorder` int(11) NOT NULL DEFAULT 0,
  `usercreate` char(16) NOT NULL DEFAULT '',
  `useredit` char(16) NOT NULL DEFAULT '',
  `updatetimestamp` timestamp NOT NULL DEFAULT current_timestamp() ON UPDATE current_timestamp()
) ENGINE=InnoDB DEFAULT CHARSET=utf8mb4 COLLATE=utf8mb4_unicode_ci;

CREATE TABLE `postablegroup` (
  `id` bigint(20) UNSIGNED NOT NULL,
  `name` varchar(50) NOT NULL DEFAULT '',
  `isactive` int(11) NOT NULL DEFAULT 1,
  `usercreate` char(16) NOT NULL DEFAULT '',
  `useredit` char(16) NOT NULL DEFAULT '',
  `updatetimestamp` timestamp NOT NULL DEFAULT current_timestamp() ON UPDATE current_timestamp()
) ENGINE=InnoDB DEFAULT CHARSET=utf8mb4 COLLATE=utf8mb4_unicode_ci;

CREATE TABLE `product` (
  `id` char(30) NOT NULL DEFAULT '',
  `aliasid` char(30) NOT NULL DEFAULT '',
  `name` varchar(100) NOT NULL DEFAULT '',
  `description` text NOT NULL,
  `productgroup` char(30) NOT NULL DEFAULT '',
  `supplier` char(30) NOT NULL DEFAULT '',
  `category` tinyint(4) DEFAULT 0 COMMENT '0=INVENTORY, 1=SERVICE',
  `factory` char(30) NOT NULL DEFAULT '',
  `brand` char(5) NOT NULL DEFAULT '',
  `usesn` smallint(6) NOT NULL DEFAULT 0,
  `minimum` double NOT NULL DEFAULT 0,
  `maximum` double NOT NULL DEFAULT 0,
  `minimumreorder` double NOT NULL DEFAULT 0,
  `defaultreorder` double NOT NULL DEFAULT 0,
  `taxtype` tinyint(4) NOT NULL DEFAULT 0,
  `author` char(30) NOT NULL DEFAULT '',
  `dwidth` double NOT NULL DEFAULT 0,
  `dheight` double NOT NULL DEFAULT 0,
  `dlength` double NOT NULL DEFAULT 0,
  `weight` double NOT NULL DEFAULT 0,
  `salesdiscrules` text DEFAULT NULL,
  `salesmancommrules` text DEFAULT NULL,
  `salesproductrewardrules` text DEFAULT NULL,
  `salespointrewardrules` text DEFAULT NULL,
  `servicedoercommrules` text DEFAULT NULL,
  `inventoryacc` char(30) NOT NULL DEFAULT '',
  `cogsacc` char(30) NOT NULL DEFAULT '',
  `salesacc` char(30) NOT NULL DEFAULT '',
  `salesdiscacc` char(30) NOT NULL DEFAULT '',
  `salesreturnacc` char(30) NOT NULL DEFAULT '',
  `isactive` smallint(6) NOT NULL DEFAULT 1,
  `usercreate` char(16) NOT NULL DEFAULT '',
  `useredit` char(16) NOT NULL DEFAULT '',
  `updatetimestamp` timestamp NOT NULL DEFAULT current_timestamp() ON UPDATE current_timestamp(),
  `image` varchar(255) DEFAULT '[]',
  `availableinpos` int(11) NOT NULL DEFAULT 1
) ENGINE=InnoDB DEFAULT CHARSET=utf8mb4 COLLATE=utf8mb4_unicode_ci;

CREATE TABLE `productassemble` (
  `id` char(30) NOT NULL DEFAULT '',
  `transdate` datetime DEFAULT NULL,
  `transtime` time DEFAULT NULL,
  `division` char(10) NOT NULL DEFAULT '',
  `departement` char(10) NOT NULL DEFAULT '',
  `productid` char(30) NOT NULL DEFAULT '',
  `productname` varchar(100) NOT NULL DEFAULT '',
  `snproduct` varchar(100) NOT NULL DEFAULT '',
  `expireddate` date DEFAULT NULL,
  `unit` char(10) NOT NULL DEFAULT '',
  `qty` double DEFAULT 0,
  `cogs` double DEFAULT 0,
  `memo` varchar(200) NOT NULL DEFAULT '',
  `usercreate` char(16) NOT NULL DEFAULT '',
  `useredit` char(16) NOT NULL DEFAULT '',
  `updatetimestamp` timestamp NOT NULL DEFAULT current_timestamp() ON UPDATE current_timestamp()
) ENGINE=InnoDB DEFAULT CHARSET=utf8mb4 COLLATE=utf8mb4_unicode_ci;

CREATE TABLE `productassembledetail` (
  `id` bigint(20) UNSIGNED NOT NULL,
  `transid` char(30) NOT NULL DEFAULT '',
  `transdate` datetime DEFAULT NULL,
  `productid` char(30) NOT NULL DEFAULT '',
  `productname` varchar(100) NOT NULL DEFAULT '',
  `snproduct` varchar(100) NOT NULL DEFAULT '',
  `expireddate` date DEFAULT NULL,
  `unit` char(10) NOT NULL DEFAULT '',
  `qty` double DEFAULT 0,
  `cogs` double DEFAULT 0,
  `subtotal` double DEFAULT 0,
  `memo` varchar(200) NOT NULL DEFAULT '',
  `usercreate` char(16) NOT NULL DEFAULT '',
  `useredit` char(16) NOT NULL DEFAULT '',
  `updatetimestamp` timestamp NOT NULL DEFAULT current_timestamp() ON UPDATE current_timestamp()
) ENGINE=InnoDB DEFAULT CHARSET=utf8mb4 COLLATE=utf8mb4_unicode_ci;

CREATE TABLE `productbrand` (
  `id` char(5) NOT NULL DEFAULT '',
  `name` varchar(45) NOT NULL DEFAULT '',
  `usercreate` char(16) NOT NULL DEFAULT '',
  `useredit` char(16) NOT NULL DEFAULT '',
  `updatetimestamp` timestamp NOT NULL DEFAULT current_timestamp() ON UPDATE current_timestamp()
) ENGINE=InnoDB DEFAULT CHARSET=utf8mb4 COLLATE=utf8mb4_unicode_ci;

CREATE TABLE `productdisassemble` (
  `id` char(30) NOT NULL DEFAULT '',
  `transdate` datetime DEFAULT NULL,
  `transtime` time DEFAULT NULL,
  `division` char(10) NOT NULL DEFAULT '',
  `departement` char(10) NOT NULL DEFAULT '',
  `productid` char(30) NOT NULL DEFAULT '',
  `productname` varchar(100) NOT NULL DEFAULT '',
  `snproduct` varchar(100) NOT NULL DEFAULT '',
  `expireddate` date DEFAULT NULL,
  `unit` char(10) NOT NULL DEFAULT '',
  `qty` double DEFAULT 0,
  `cogs` double DEFAULT 0,
  `memo` varchar(200) NOT NULL DEFAULT '',
  `usercreate` char(16) NOT NULL DEFAULT '',
  `useredit` char(16) NOT NULL DEFAULT '',
  `updatetimestamp` timestamp NOT NULL DEFAULT current_timestamp() ON UPDATE current_timestamp()
) ENGINE=InnoDB DEFAULT CHARSET=utf8mb4 COLLATE=utf8mb4_unicode_ci;

CREATE TABLE `productdisassembledetail` (
  `id` bigint(20) UNSIGNED NOT NULL,
  `transid` char(30) NOT NULL DEFAULT '',
  `transdate` datetime DEFAULT NULL,
  `productid` char(30) NOT NULL DEFAULT '',
  `productname` varchar(100) NOT NULL DEFAULT '',
  `snproduct` varchar(100) NOT NULL DEFAULT '',
  `expireddate` date DEFAULT NULL,
  `unit` char(10) NOT NULL DEFAULT '',
  `qty` double DEFAULT 0,
  `cogs` double DEFAULT 0,
  `subtotal` double DEFAULT 0,
  `memo` varchar(200) NOT NULL DEFAULT '',
  `usercreate` char(16) NOT NULL DEFAULT '',
  `useredit` char(16) NOT NULL DEFAULT '',
  `updatetimestamp` timestamp NOT NULL DEFAULT current_timestamp() ON UPDATE current_timestamp()
) ENGINE=InnoDB DEFAULT CHARSET=utf8mb4 COLLATE=utf8mb4_unicode_ci;

CREATE TABLE `productgroup` (
  `id` char(30) NOT NULL DEFAULT '',
  `name` varchar(100) NOT NULL DEFAULT '',
  `salesdiscrules` text DEFAULT NULL,
  `salesmancommrules` text DEFAULT NULL,
  `salesproductrewardrules` text DEFAULT NULL,
  `salespointrewardrules` text DEFAULT NULL,
  `servicedoercommrules` text DEFAULT NULL,
  `inventoryacc` char(30) NOT NULL DEFAULT '',
  `cogsacc` char(30) DEFAULT '',
  `salesacc` char(30) NOT NULL DEFAULT '',
  `salesdiscacc` char(30) NOT NULL DEFAULT '',
  `salesreturnacc` char(30) NOT NULL DEFAULT '',
  `usercreate` char(16) NOT NULL DEFAULT '',
  `useredit` char(16) NOT NULL DEFAULT '',
  `updatetimestamp` timestamp NOT NULL DEFAULT current_timestamp() ON UPDATE current_timestamp()
) ENGINE=InnoDB DEFAULT CHARSET=utf8mb4 COLLATE=utf8mb4_unicode_ci;

CREATE TABLE `productpackage` (
  `transid` bigint(20) UNSIGNED NOT NULL,
  `packageid` char(30) NOT NULL DEFAULT '',
  `productid` char(30) NOT NULL DEFAULT '',
  `productname` varchar(100) NOT NULL DEFAULT '',
  `qty` double NOT NULL DEFAULT 0,
  `cogs` double NOT NULL DEFAULT 0,
  `subtotal` double NOT NULL DEFAULT 0,
  `usercreate` char(16) NOT NULL DEFAULT '',
  `useredit` char(16) NOT NULL DEFAULT '',
  `updatetimestamp` timestamp NOT NULL DEFAULT current_timestamp() ON UPDATE current_timestamp()
) ENGINE=InnoDB DEFAULT CHARSET=utf8mb4 COLLATE=utf8mb4_unicode_ci;

CREATE TABLE `productsalesvariant` (
  `id` bigint(20) UNSIGNED NOT NULL,
  `name` varchar(100) NOT NULL DEFAULT '',
  `extraprice` double NOT NULL DEFAULT 0,
  `productgroup` char(30) NOT NULL DEFAULT '',
  `isactive` smallint(6) NOT NULL DEFAULT 1,
  `usercreate` char(16) NOT NULL DEFAULT '',
  `useredit` char(16) NOT NULL DEFAULT '',
  `updatetimestamp` timestamp NOT NULL DEFAULT current_timestamp() ON UPDATE current_timestamp()
) ENGINE=InnoDB DEFAULT CHARSET=utf8mb4 COLLATE=utf8mb4_unicode_ci;

CREATE TABLE `purchase` (
  `purchaseid` char(30) NOT NULL DEFAULT '',
  `purchaseidref` char(30) NOT NULL DEFAULT '',
  `purchaseorder` char(30) NOT NULL DEFAULT '',
  `purchasedate` date DEFAULT NULL,
  `purchasetime` time DEFAULT NULL,
  `kind` int(11) NOT NULL DEFAULT 0,
  `purchasetype` smallint(6) NOT NULL DEFAULT 0 COMMENT '0=CASH, 1=CASH ON DELIVERY, 2=CREDIT',
  `earlydiscdays` int(11) NOT NULL DEFAULT 0,
  `earlydiscvalue` double NOT NULL DEFAULT 0,
  `duedays` int(11) NOT NULL DEFAULT 0,
  `supplierid` char(30) NOT NULL DEFAULT '',
  `suppliername` varchar(100) NOT NULL DEFAULT '',
  `supplieraddress` varchar(200) NOT NULL DEFAULT '',
  `suppliercreditlimit` double NOT NULL DEFAULT 0,
  `suppliertaxid` varchar(50) NOT NULL DEFAULT '',
  `supplierbalance` double NOT NULL DEFAULT 0,
  `currtrans` char(3) NOT NULL DEFAULT '',
  `ratedefault` double NOT NULL DEFAULT 0,
  `rateused` double NOT NULL DEFAULT 0,
  `purchaser` char(30) NOT NULL DEFAULT '',
  `purchasername` varchar(100) NOT NULL DEFAULT '',
  `purchasepercentdisc` double NOT NULL DEFAULT 0,
  `returnpercentdisc` double NOT NULL DEFAULT 0,
  `purchasevaluedisc` double NOT NULL DEFAULT 0,
  `returnvaluedisc` double NOT NULL DEFAULT 0,
  `pointbalance` double NOT NULL DEFAULT 0,
  `purchasepoint` double NOT NULL DEFAULT 0,
  `returnpoint` double NOT NULL DEFAULT 0,
  `currpointbalance` double NOT NULL DEFAULT 0,
  `purchasetotal` double NOT NULL DEFAULT 0,
  `memo` text DEFAULT NULL,
  `memoedit` text DEFAULT NULL,
  `division` char(10) NOT NULL DEFAULT '',
  `printed` smallint(6) NOT NULL DEFAULT 0,
  `shipment` int(10) UNSIGNED NOT NULL DEFAULT 1,
  `dateaccepted` datetime DEFAULT NULL,
  `accepted` smallint(6) NOT NULL DEFAULT 1,
  `paidinfull` smallint(6) NOT NULL DEFAULT 0,
  `paidinfulldate` date DEFAULT NULL,
  `paidinfullref` char(30) NOT NULL DEFAULT '',
  `usercreate` char(16) NOT NULL DEFAULT '',
  `useredit` char(16) NOT NULL DEFAULT '',
  `updatetimestamp` timestamp NOT NULL DEFAULT current_timestamp() ON UPDATE current_timestamp()
) ENGINE=InnoDB DEFAULT CHARSET=utf8mb4 COLLATE=utf8mb4_unicode_ci;

CREATE TABLE `purchasedetail` (
  `transid` bigint(20) UNSIGNED NOT NULL,
  `transdate` datetime DEFAULT NULL,
  `purchaseid` char(30) NOT NULL DEFAULT '',
  `purchaseidref` char(30) NOT NULL DEFAULT '',
  `productid` char(30) NOT NULL DEFAULT '',
  `productname` varchar(100) NOT NULL DEFAULT '',
  `usesn` int(11) NOT NULL DEFAULT 0,
  `snproduct` varchar(100) NOT NULL DEFAULT '',
  `expireddate` date DEFAULT NULL,
  `purchaseqty` double NOT NULL DEFAULT 0,
  `returnqty` double NOT NULL DEFAULT 0,
  `unit` char(10) NOT NULL DEFAULT '',
  `unitqty` double NOT NULL DEFAULT 0,
  `price` double NOT NULL DEFAULT 0,
  `grossamount` double NOT NULL DEFAULT 0,
  `taxid` tinyint(4) NOT NULL DEFAULT 0,
  `purchasetax` double NOT NULL DEFAULT 0,
  `returntax` double NOT NULL DEFAULT 0,
  `percentdisc` varchar(50) NOT NULL DEFAULT '',
  `discformula` varchar(50) NOT NULL DEFAULT '',
  `valuedisc` double NOT NULL DEFAULT 0,
  `netamount` double NOT NULL DEFAULT 0,
  `memo` text DEFAULT NULL,
  `departement` char(10) NOT NULL DEFAULT '',
  `usercreate` char(16) NOT NULL DEFAULT '',
  `useredit` char(16) NOT NULL DEFAULT '',
  `updatetimestamp` timestamp NOT NULL DEFAULT current_timestamp() ON UPDATE current_timestamp()
) ENGINE=InnoDB DEFAULT CHARSET=utf8mb4 COLLATE=utf8mb4_unicode_ci;

CREATE TABLE `purchaseexpenses` (
  `id` int(10) UNSIGNED NOT NULL DEFAULT 0,
  `name` varchar(50) NOT NULL DEFAULT '',
  `description` varchar(100) NOT NULL DEFAULT '',
  `purchaseexpacc` char(30) NOT NULL DEFAULT '',
  `usercreate` char(16) NOT NULL DEFAULT '',
  `useredit` char(16) NOT NULL DEFAULT '',
  `updatetimestamp` timestamp NOT NULL DEFAULT current_timestamp() ON UPDATE current_timestamp()
) ENGINE=InnoDB DEFAULT CHARSET=utf8mb4 COLLATE=utf8mb4_unicode_ci;

CREATE TABLE `purchaseexpensesdetail` (
  `transid` bigint(20) UNSIGNED NOT NULL,
  `purchaseid` char(30) NOT NULL DEFAULT '',
  `purchaseidref` char(30) NOT NULL DEFAULT '',
  `transdate` datetime DEFAULT NULL,
  `kind` int(11) NOT NULL DEFAULT 0,
  `purchaseexpid` int(10) UNSIGNED NOT NULL,
  `debit` double NOT NULL DEFAULT 0,
  `credit` double NOT NULL DEFAULT 0,
  `memo` text DEFAULT NULL,
  `currtrans` char(3) NOT NULL DEFAULT '',
  `ratedefault` double NOT NULL DEFAULT 0,
  `rateused` double NOT NULL DEFAULT 0,
  `usercreate` char(16) NOT NULL DEFAULT '',
  `useredit` char(16) NOT NULL DEFAULT '',
  `updatetimestamp` timestamp NOT NULL DEFAULT current_timestamp() ON UPDATE current_timestamp()
) ENGINE=InnoDB DEFAULT CHARSET=utf8mb4 COLLATE=utf8mb4_unicode_ci;

CREATE TABLE `purchaseextratax` (
  `transid` bigint(20) UNSIGNED NOT NULL,
  `transdate` datetime DEFAULT NULL,
  `purchaseid` char(30) NOT NULL DEFAULT '',
  `purchaseidref` char(30) NOT NULL DEFAULT '',
  `productid` char(30) NOT NULL DEFAULT '',
  `productname` varchar(100) NOT NULL DEFAULT '',
  `purchaseqty` double NOT NULL DEFAULT 0,
  `returnqty` double NOT NULL DEFAULT 0,
  `unit` char(10) NOT NULL DEFAULT '',
  `grossamount` double NOT NULL DEFAULT 0,
  `taxid` tinyint(4) NOT NULL DEFAULT 0,
  `purchasetax` double NOT NULL DEFAULT 0,
  `returntax` double NOT NULL DEFAULT 0,
  `usercreate` char(16) NOT NULL DEFAULT '',
  `useredit` char(16) NOT NULL DEFAULT '',
  `updatetimestamp` timestamp NOT NULL DEFAULT current_timestamp() ON UPDATE current_timestamp()
) ENGINE=InnoDB DEFAULT CHARSET=utf8mb4 COLLATE=utf8mb4_unicode_ci;

CREATE TABLE `purchaseorder` (
  `purchaseid` char(30) NOT NULL DEFAULT '',
  `purchaseidref` char(30) NOT NULL DEFAULT '',
  `purchaserequisition` char(30) NOT NULL DEFAULT '',
  `purchasedate` date DEFAULT NULL,
  `purchasetime` time DEFAULT NULL,
  `kind` int(11) NOT NULL DEFAULT 0,
  `purchasetype` smallint(6) NOT NULL DEFAULT 0 COMMENT '0=CASH, 1=CASH ON DELIVERY, 2=CREDIT',
  `earlydiscdays` int(11) NOT NULL DEFAULT 0,
  `earlydiscvalue` double NOT NULL DEFAULT 0,
  `duedays` int(11) NOT NULL DEFAULT 0,
  `supplierid` char(30) NOT NULL DEFAULT '',
  `suppliername` varchar(100) NOT NULL DEFAULT '',
  `supplieraddress` varchar(200) NOT NULL DEFAULT '',
  `suppliercreditlimit` double NOT NULL DEFAULT 0,
  `suppliertaxid` varchar(50) NOT NULL DEFAULT '',
  `supplierbalance` double NOT NULL DEFAULT 0,
  `currtrans` char(3) NOT NULL DEFAULT '',
  `ratedefault` double NOT NULL DEFAULT 0,
  `rateused` double NOT NULL DEFAULT 0,
  `purchaser` char(30) NOT NULL DEFAULT '',
  `purchasername` varchar(100) NOT NULL DEFAULT '',
  `purchasepercentdisc` double NOT NULL DEFAULT 0,
  `returnpercentdisc` double NOT NULL DEFAULT 0,
  `purchasevaluedisc` double NOT NULL DEFAULT 0,
  `returnvaluedisc` double NOT NULL DEFAULT 0,
  `pointbalance` double NOT NULL DEFAULT 0,
  `purchasepoint` double NOT NULL DEFAULT 0,
  `returnpoint` double NOT NULL DEFAULT 0,
  `currpointbalance` double NOT NULL DEFAULT 0,
  `purchasetotal` double NOT NULL DEFAULT 0,
  `memo` text DEFAULT NULL,
  `memoedit` text DEFAULT NULL,
  `division` char(10) NOT NULL DEFAULT '',
  `printed` smallint(6) NOT NULL DEFAULT 0,
  `shipment` int(10) UNSIGNED NOT NULL DEFAULT 1,
  `dateaccepted` datetime DEFAULT NULL,
  `accepted` smallint(6) NOT NULL DEFAULT 1,
  `paidinfull` smallint(6) NOT NULL DEFAULT 0,
  `paidinfulldate` date DEFAULT NULL,
  `paidinfullref` char(30) NOT NULL DEFAULT '',
  `usercreate` char(16) NOT NULL DEFAULT '',
  `useredit` char(16) NOT NULL DEFAULT '',
  `updatetimestamp` timestamp NOT NULL DEFAULT current_timestamp() ON UPDATE current_timestamp()
) ENGINE=InnoDB DEFAULT CHARSET=utf8mb4 COLLATE=utf8mb4_unicode_ci;

CREATE TABLE `purchaseorderdetail` (
  `transid` bigint(20) UNSIGNED NOT NULL,
  `transdate` datetime DEFAULT NULL,
  `purchaseid` char(30) NOT NULL DEFAULT '',
  `purchaseidref` char(30) NOT NULL DEFAULT '',
  `productid` char(30) NOT NULL DEFAULT '',
  `productname` varchar(100) NOT NULL DEFAULT '',
  `usesn` int(11) NOT NULL DEFAULT 0,
  `snproduct` varchar(100) NOT NULL DEFAULT '',
  `expireddate` date DEFAULT NULL,
  `purchaseqty` double NOT NULL DEFAULT 0,
  `returnqty` double NOT NULL DEFAULT 0,
  `unit` char(10) NOT NULL DEFAULT '',
  `unitqty` double NOT NULL DEFAULT 0,
  `price` double NOT NULL DEFAULT 0,
  `grossamount` double NOT NULL DEFAULT 0,
  `taxid` tinyint(4) NOT NULL DEFAULT 0,
  `purchasetax` double NOT NULL DEFAULT 0,
  `returntax` double NOT NULL DEFAULT 0,
  `percentdisc` varchar(50) NOT NULL DEFAULT '',
  `discformula` varchar(50) NOT NULL DEFAULT '',
  `valuedisc` double NOT NULL DEFAULT 0,
  `netamount` double NOT NULL DEFAULT 0,
  `memo` text DEFAULT NULL,
  `departement` char(10) NOT NULL DEFAULT '',
  `usercreate` char(16) NOT NULL DEFAULT '',
  `useredit` char(16) NOT NULL DEFAULT '',
  `updatetimestamp` timestamp NOT NULL DEFAULT current_timestamp() ON UPDATE current_timestamp()
) ENGINE=InnoDB DEFAULT CHARSET=utf8mb4 COLLATE=utf8mb4_unicode_ci;

CREATE TABLE `purchaseorderexpensesdetail` (
  `transid` bigint(20) UNSIGNED NOT NULL,
  `purchaseid` char(30) NOT NULL DEFAULT '',
  `purchaseidref` char(30) NOT NULL DEFAULT '',
  `transdate` datetime DEFAULT NULL,
  `kind` int(11) NOT NULL DEFAULT 0,
  `purchaseexpid` int(10) UNSIGNED NOT NULL,
  `debit` double NOT NULL DEFAULT 0,
  `credit` double NOT NULL DEFAULT 0,
  `memo` text DEFAULT NULL,
  `currtrans` char(3) NOT NULL DEFAULT '',
  `ratedefault` double NOT NULL DEFAULT 0,
  `rateused` double NOT NULL DEFAULT 0,
  `usercreate` char(16) NOT NULL DEFAULT '',
  `useredit` char(16) NOT NULL DEFAULT '',
  `updatetimestamp` timestamp NOT NULL DEFAULT current_timestamp() ON UPDATE current_timestamp()
) ENGINE=InnoDB DEFAULT CHARSET=utf8mb4 COLLATE=utf8mb4_unicode_ci;

CREATE TABLE `purchaseorderextratax` (
  `transid` bigint(20) UNSIGNED NOT NULL,
  `transdate` datetime DEFAULT NULL,
  `purchaseid` char(30) NOT NULL DEFAULT '',
  `purchaseidref` char(30) NOT NULL DEFAULT '',
  `productid` char(30) NOT NULL DEFAULT '',
  `productname` varchar(100) NOT NULL DEFAULT '',
  `purchaseqty` double NOT NULL DEFAULT 0,
  `returnqty` double NOT NULL DEFAULT 0,
  `unit` char(10) NOT NULL DEFAULT '',
  `grossamount` double NOT NULL DEFAULT 0,
  `taxid` tinyint(4) NOT NULL DEFAULT 0,
  `purchasetax` double NOT NULL DEFAULT 0,
  `returntax` double NOT NULL DEFAULT 0,
  `usercreate` char(16) NOT NULL DEFAULT '',
  `useredit` char(16) NOT NULL DEFAULT '',
  `updatetimestamp` timestamp NOT NULL DEFAULT current_timestamp() ON UPDATE current_timestamp()
) ENGINE=InnoDB DEFAULT CHARSET=utf8mb4 COLLATE=utf8mb4_unicode_ci;

CREATE TABLE `purchaseorderpayments` (
  `transid` bigint(20) UNSIGNED NOT NULL,
  `purchaseid` char(30) NOT NULL DEFAULT '',
  `purchaseidref` char(30) NOT NULL DEFAULT '',
  `transdate` datetime DEFAULT NULL,
  `debit` double NOT NULL DEFAULT 0,
  `credit` double NOT NULL DEFAULT 0,
  `discountpercent` double NOT NULL DEFAULT 0,
  `discountvalue` double NOT NULL DEFAULT 0,
  `duedate` date DEFAULT NULL,
  `accepted` smallint(6) NOT NULL DEFAULT 0,
  `kind` smallint(6) NOT NULL DEFAULT 0,
  `paymenttype` int(10) UNSIGNED NOT NULL,
  `refpayment` varchar(30) NOT NULL,
  `currtrans` char(3) NOT NULL DEFAULT '',
  `ratedefault` double NOT NULL DEFAULT 0,
  `rateused` double NOT NULL DEFAULT 0,
  `usercreate` char(16) NOT NULL DEFAULT '',
  `useredit` char(16) NOT NULL DEFAULT '',
  `updatetimestamp` timestamp NOT NULL DEFAULT current_timestamp() ON UPDATE current_timestamp()
) ENGINE=InnoDB DEFAULT CHARSET=utf8mb4 COLLATE=utf8mb4_unicode_ci;

CREATE TABLE `purchaseorderpoint` (
  `transid` bigint(20) UNSIGNED NOT NULL,
  `transdate` datetime DEFAULT NULL,
  `purchaseid` char(30) NOT NULL DEFAULT '',
  `purchaseidref` char(30) NOT NULL DEFAULT '',
  `supplier` char(30) NOT NULL DEFAULT '',
  `qtyin` double NOT NULL DEFAULT 0,
  `qtyout` double NOT NULL DEFAULT 0,
  `usercreate` char(16) NOT NULL DEFAULT '',
  `useredit` char(16) NOT NULL DEFAULT '',
  `updatetimestamp` timestamp NOT NULL DEFAULT current_timestamp() ON UPDATE current_timestamp()
) ENGINE=InnoDB DEFAULT CHARSET=utf8mb4 COLLATE=utf8mb4_unicode_ci;

CREATE TABLE `purchaseorderrewarddetail` (
  `transid` bigint(20) UNSIGNED NOT NULL,
  `transdate` datetime DEFAULT NULL,
  `purchaseid` char(30) NOT NULL DEFAULT '',
  `purchaseidref` char(30) NOT NULL DEFAULT '',
  `productid` char(30) NOT NULL DEFAULT '',
  `productname` varchar(100) NOT NULL DEFAULT '',
  `snproduct` varchar(100) NOT NULL DEFAULT '',
  `expireddate` date DEFAULT NULL,
  `purchaseqty` double NOT NULL DEFAULT 0,
  `returnqty` double NOT NULL DEFAULT 0,
  `unit` char(10) NOT NULL DEFAULT '',
  `unitqty` double NOT NULL DEFAULT 0,
  `price` double NOT NULL DEFAULT 0,
  `grossamount` double NOT NULL DEFAULT 0,
  `taxid` tinyint(4) NOT NULL DEFAULT 0,
  `purchasetax` double NOT NULL DEFAULT 0,
  `returntax` double NOT NULL DEFAULT 0,
  `netamount` double NOT NULL DEFAULT 0,
  `memo` text DEFAULT NULL,
  `departement` char(10) NOT NULL DEFAULT '',
  `usercreate` char(16) NOT NULL DEFAULT '',
  `useredit` char(16) NOT NULL DEFAULT '',
  `updatetimestamp` timestamp NOT NULL DEFAULT current_timestamp() ON UPDATE current_timestamp()
) ENGINE=InnoDB DEFAULT CHARSET=utf8mb4 COLLATE=utf8mb4_unicode_ci;

CREATE TABLE `purchasepayments` (
  `transid` bigint(20) UNSIGNED NOT NULL,
  `purchaseid` char(30) NOT NULL DEFAULT '',
  `purchaseidref` char(30) NOT NULL DEFAULT '',
  `transdate` datetime DEFAULT NULL,
  `debit` double NOT NULL DEFAULT 0,
  `credit` double NOT NULL DEFAULT 0,
  `discountpercent` double NOT NULL DEFAULT 0,
  `discountvalue` double NOT NULL DEFAULT 0,
  `duedate` date DEFAULT NULL,
  `accepted` smallint(6) NOT NULL DEFAULT 0,
  `kind` smallint(6) NOT NULL DEFAULT 0,
  `paymenttype` int(10) UNSIGNED NOT NULL,
  `refpayment` varchar(30) NOT NULL,
  `currtrans` char(3) NOT NULL DEFAULT '',
  `ratedefault` double NOT NULL DEFAULT 0,
  `rateused` double NOT NULL DEFAULT 0,
  `usercreate` char(16) NOT NULL DEFAULT '',
  `useredit` char(16) NOT NULL DEFAULT '',
  `updatetimestamp` timestamp NOT NULL DEFAULT current_timestamp() ON UPDATE current_timestamp()
) ENGINE=InnoDB DEFAULT CHARSET=utf8mb4 COLLATE=utf8mb4_unicode_ci;

CREATE TABLE `purchasepoint` (
  `transid` bigint(20) UNSIGNED NOT NULL,
  `transdate` datetime DEFAULT NULL,
  `purchaseid` char(30) NOT NULL DEFAULT '',
  `purchaseidref` char(30) NOT NULL DEFAULT '',
  `supplier` char(30) NOT NULL DEFAULT '',
  `qtyin` double NOT NULL DEFAULT 0,
  `qtyout` double NOT NULL DEFAULT 0,
  `usercreate` char(16) NOT NULL DEFAULT '',
  `useredit` char(16) NOT NULL DEFAULT '',
  `updatetimestamp` timestamp NOT NULL DEFAULT current_timestamp() ON UPDATE current_timestamp()
) ENGINE=InnoDB DEFAULT CHARSET=utf8mb4 COLLATE=utf8mb4_unicode_ci;

CREATE TABLE `purchaserequisition` (
  `requisitionid` char(30) NOT NULL DEFAULT '',
  `requisitionidref` char(30) NOT NULL DEFAULT '',
  `requisitiondate` date DEFAULT NULL,
  `requisitiontime` time DEFAULT NULL,
  `requisitionstatus` int(11) NOT NULL DEFAULT 0,
  `approvaluser` char(16) NOT NULL DEFAULT '',
  `approvalusername` varchar(100) NOT NULL DEFAULT '',
  `requisitiontotal` double NOT NULL DEFAULT 0,
  `memo` text DEFAULT NULL,
  `memoedit` text DEFAULT NULL,
  `division` char(10) NOT NULL DEFAULT '',
  `usercreate` char(16) NOT NULL DEFAULT '',
  `useredit` char(16) NOT NULL DEFAULT '',
  `updatetimestamp` timestamp NOT NULL DEFAULT current_timestamp() ON UPDATE current_timestamp()
) ENGINE=InnoDB DEFAULT CHARSET=utf8mb4 COLLATE=utf8mb4_unicode_ci;

CREATE TABLE `purchaserequisitiondetail` (
  `transid` bigint(20) UNSIGNED NOT NULL,
  `transdate` datetime DEFAULT NULL,
  `requisitionid` char(30) NOT NULL DEFAULT '',
  `requisitionidref` char(30) NOT NULL DEFAULT '',
  `supplierid` char(30) NOT NULL DEFAULT '',
  `suppliername` varchar(100) NOT NULL DEFAULT '',
  `departement` char(10) NOT NULL DEFAULT '',
  `productid` char(30) NOT NULL DEFAULT '',
  `productname` varchar(100) NOT NULL DEFAULT '',
  `availablestock` double NOT NULL DEFAULT 0,
  `requestqty` double NOT NULL DEFAULT 0,
  `orderedqty` double NOT NULL DEFAULT 0,
  `remainingqty` double NOT NULL DEFAULT 0,
  `unit` char(10) NOT NULL DEFAULT '',
  `unitqty` double NOT NULL DEFAULT 0,
  `estprice` double NOT NULL DEFAULT 0,
  `estamount` double NOT NULL DEFAULT 0,
  `memo` text DEFAULT NULL,
  `usercreate` char(16) NOT NULL DEFAULT '',
  `useredit` char(16) NOT NULL DEFAULT '',
  `updatetimestamp` timestamp NOT NULL DEFAULT current_timestamp() ON UPDATE current_timestamp()
) ENGINE=InnoDB DEFAULT CHARSET=utf8mb4 COLLATE=utf8mb4_unicode_ci;

CREATE TABLE `purchaserewarddetail` (
  `transid` bigint(20) UNSIGNED NOT NULL,
  `transdate` datetime DEFAULT NULL,
  `purchaseid` char(30) NOT NULL DEFAULT '',
  `purchaseidref` char(30) NOT NULL DEFAULT '',
  `productid` char(30) NOT NULL DEFAULT '',
  `productname` varchar(100) NOT NULL DEFAULT '',
  `snproduct` varchar(100) NOT NULL DEFAULT '',
  `expireddate` date DEFAULT NULL,
  `purchaseqty` double NOT NULL DEFAULT 0,
  `returnqty` double NOT NULL DEFAULT 0,
  `unit` char(10) NOT NULL DEFAULT '',
  `unitqty` double NOT NULL DEFAULT 0,
  `price` double NOT NULL DEFAULT 0,
  `grossamount` double NOT NULL DEFAULT 0,
  `taxid` tinyint(4) NOT NULL DEFAULT 0,
  `purchasetax` double NOT NULL DEFAULT 0,
  `returntax` double NOT NULL DEFAULT 0,
  `netamount` double NOT NULL DEFAULT 0,
  `memo` text DEFAULT NULL,
  `departement` char(10) NOT NULL DEFAULT '',
  `usercreate` char(16) NOT NULL DEFAULT '',
  `useredit` char(16) NOT NULL DEFAULT '',
  `updatetimestamp` timestamp NOT NULL DEFAULT current_timestamp() ON UPDATE current_timestamp()
) ENGINE=InnoDB DEFAULT CHARSET=utf8mb4 COLLATE=utf8mb4_unicode_ci;

CREATE TABLE `receivableadjust` (
  `transid` char(30) NOT NULL DEFAULT '',
  `transdate` date DEFAULT NULL,
  `transtime` time DEFAULT NULL,
  `customerid` char(30) NOT NULL DEFAULT '',
  `customername` varchar(100) NOT NULL DEFAULT '',
  `customeraddress` varchar(200) NOT NULL DEFAULT '',
  `currtrans` char(3) NOT NULL DEFAULT '',
  `ratedefault` double NOT NULL DEFAULT 0,
  `rateused` double NOT NULL DEFAULT 0,
  `expensestype` int(10) UNSIGNED NOT NULL,
  `debit` double NOT NULL DEFAULT 0,
  `credit` double NOT NULL DEFAULT 0,
  `memo` varchar(250) NOT NULL DEFAULT '',
  `memoedit` varchar(250) NOT NULL DEFAULT '',
  `division` char(10) NOT NULL DEFAULT '',
  `printed` smallint(6) NOT NULL DEFAULT 0,
  `usercreate` char(16) NOT NULL DEFAULT '',
  `useredit` char(16) NOT NULL DEFAULT '',
  `updatetimestamp` timestamp NOT NULL DEFAULT current_timestamp() ON UPDATE current_timestamp()
) ENGINE=InnoDB DEFAULT CHARSET=utf8mb4 COLLATE=utf8mb4_unicode_ci;

CREATE TABLE `receivablepayment` (
  `transid` char(30) NOT NULL DEFAULT '',
  `transdate` date DEFAULT NULL,
  `transtime` time DEFAULT NULL,
  `customerid` char(30) NOT NULL DEFAULT '',
  `customername` varchar(100) NOT NULL DEFAULT '',
  `customeraddress` varchar(200) NOT NULL DEFAULT '',
  `currtrans` char(3) NOT NULL DEFAULT '',
  `ratedefault` double NOT NULL DEFAULT 0,
  `rateused` double NOT NULL DEFAULT 0,
  `paymenttype` int(10) UNSIGNED NOT NULL,
  `kind` int(10) UNSIGNED NOT NULL DEFAULT 0,
  `refpayment` varchar(30) NOT NULL DEFAULT '',
  `amount` double NOT NULL DEFAULT 0,
  `discountvalue` double NOT NULL DEFAULT 0,
  `netpayment` double NOT NULL DEFAULT 0,
  `memo` varchar(250) NOT NULL DEFAULT '',
  `memoedit` varchar(250) NOT NULL DEFAULT '',
  `division` char(10) NOT NULL DEFAULT '',
  `accepted` smallint(6) NOT NULL DEFAULT 0,
  `duedate` date DEFAULT NULL,
  `accepteddate` date DEFAULT NULL,
  `printed` smallint(6) NOT NULL DEFAULT 0,
  `usercreate` char(16) NOT NULL DEFAULT '',
  `useredit` char(16) NOT NULL DEFAULT '',
  `updatetimestamp` timestamp NOT NULL DEFAULT current_timestamp() ON UPDATE current_timestamp()
) ENGINE=InnoDB DEFAULT CHARSET=utf8mb4 COLLATE=utf8mb4_unicode_ci;

CREATE TABLE `religions` (
  `id` int(10) UNSIGNED NOT NULL,
  `name` varchar(100) NOT NULL DEFAULT ''
) ENGINE=InnoDB DEFAULT CHARSET=utf8mb4 COLLATE=utf8mb4_unicode_ci;

CREATE TABLE `rentalreturn` (
  `transid` char(30) NOT NULL DEFAULT '',
  `salesid` char(30) NOT NULL DEFAULT '',
  `transdate` date DEFAULT NULL,
  `transtime` time DEFAULT NULL,
  `customerid` char(30) NOT NULL DEFAULT '',
  `customername` varchar(100) NOT NULL DEFAULT '',
  `customeraddress` varchar(200) NOT NULL DEFAULT '',
  `invoicenotpaid` double NOT NULL DEFAULT 0,
  `totalpayment` double NOT NULL DEFAULT 0,
  `receivablebalance` double NOT NULL DEFAULT 0,
  `memo` text DEFAULT NULL,
  `memoedit` text DEFAULT NULL,
  `division` char(10) NOT NULL DEFAULT '',
  `usercreate` char(16) NOT NULL DEFAULT '',
  `useredit` char(16) NOT NULL DEFAULT '',
  `updatetimestamp` timestamp NOT NULL DEFAULT current_timestamp() ON UPDATE current_timestamp()
) ENGINE=InnoDB DEFAULT CHARSET=utf8mb4 COLLATE=utf8mb4_unicode_ci;

CREATE TABLE `rentalreturndetail` (
  `transid` bigint(20) UNSIGNED NOT NULL,
  `transdate` datetime DEFAULT NULL,
  `rentalreturnid` char(30) NOT NULL DEFAULT '',
  `productid` char(30) NOT NULL DEFAULT '',
  `productname` varchar(100) NOT NULL DEFAULT '',
  `snproduct` varchar(100) NOT NULL DEFAULT '',
  `expireddate` date DEFAULT NULL,
  `qty` double NOT NULL DEFAULT 0,
  `unit` char(10) NOT NULL DEFAULT '',
  `unitqty` double NOT NULL DEFAULT 0,
  `memo` text DEFAULT NULL,
  `departement` char(10) NOT NULL DEFAULT '',
  `usercreate` char(16) NOT NULL DEFAULT '',
  `useredit` char(16) NOT NULL DEFAULT '',
  `updatetimestamp` timestamp NOT NULL DEFAULT current_timestamp() ON UPDATE current_timestamp()
) ENGINE=InnoDB DEFAULT CHARSET=utf8mb4 COLLATE=utf8mb4_unicode_ci;

CREATE TABLE `roles` (
  `id` varchar(50) NOT NULL,
  `name` varchar(50) NOT NULL DEFAULT '',
  `menus` text DEFAULT NULL,
  `defaultdivision` char(10) DEFAULT NULL,
  `lockdivision` int(11) NOT NULL DEFAULT 0,
  `defaultcustomer` char(30) DEFAULT NULL,
  `lockcustomer` int(11) NOT NULL DEFAULT 0,
  `defaultsupplier` char(30) DEFAULT NULL,
  `locksupplier` int(11) NOT NULL DEFAULT 0,
  `defaultdepartement` char(10) DEFAULT NULL,
  `lockdepartement` int(11) NOT NULL DEFAULT 0,
  `defaultsalesman` char(30) DEFAULT NULL,
  `locksalesman` int(11) NOT NULL DEFAULT 0,
  `defaultservicedoer` char(30) DEFAULT NULL,
  `lockservicedoer` int(11) NOT NULL DEFAULT 0,
  `approvaljournal` int(11) NOT NULL DEFAULT 0,
  `approvalinvmoving` int(11) NOT NULL DEFAULT 1,
  `defaultcurrency` char(3) DEFAULT NULL,
  `lockcurrency` int(11) NOT NULL DEFAULT 0,
  `defaultemployee` char(10) DEFAULT NULL,
  `lockemployee` int(11) NOT NULL DEFAULT 0,
  `defaultshipment` int(10) UNSIGNED NOT NULL DEFAULT 0,
  `lockshipment` int(11) NOT NULL DEFAULT 0,
  `defaultpayment` int(10) UNSIGNED NOT NULL DEFAULT 0,
  `lockpayment` int(11) NOT NULL DEFAULT 0,
  `useextratax` int(11) NOT NULL DEFAULT 0,
  `usesnproduct` int(11) NOT NULL DEFAULT 0,
  `closepos` int(11) NOT NULL DEFAULT 1,
  `showsalespricehistory` int(11) NOT NULL DEFAULT 1,
  `showpurchasepricehistory` int(11) NOT NULL DEFAULT 1,
  `lockdatetime` int(11) NOT NULL DEFAULT 0,
  `locksalesprice` int(11) NOT NULL DEFAULT 0,
  `locksalesdisc` int(11) NOT NULL DEFAULT 0,
  `sellbelowcogs` int(11) NOT NULL DEFAULT 0,
  `productgroup` text DEFAULT NULL,
  `customergroup` text DEFAULT NULL,
  `suppliergroup` text DEFAULT NULL,
  `employeegroup` text DEFAULT NULL,
  `salesmangroup` text DEFAULT NULL,
  `servicedoergroup` text DEFAULT NULL,
  `divisionlist` text DEFAULT NULL,
  `departementlist` text DEFAULT NULL,
  `useotherstax` smallint(6) NOT NULL DEFAULT 0,
  `checkinventoryavailable` int(11) NOT NULL DEFAULT 0
) ENGINE=InnoDB DEFAULT CHARSET=utf8mb4 COLLATE=utf8mb4_unicode_ci;

CREATE TABLE `salaries` (
  `id` int(10) UNSIGNED NOT NULL DEFAULT 0,
  `name` varchar(100) NOT NULL DEFAULT '',
  `description` varchar(200) NOT NULL DEFAULT '',
  `account` char(30) NOT NULL DEFAULT '',
  `kind` int(11) NOT NULL DEFAULT 0,
  `usercreate` char(16) NOT NULL DEFAULT '',
  `useredit` char(16) NOT NULL DEFAULT '',
  `updatetimestamp` timestamp NOT NULL DEFAULT current_timestamp() ON UPDATE current_timestamp()
) ENGINE=InnoDB DEFAULT CHARSET=utf8mb4 COLLATE=utf8mb4_unicode_ci;

CREATE TABLE `salariesrecord` (
  `transid` bigint(20) UNSIGNED NOT NULL,
  `refid` char(30) NOT NULL DEFAULT '',
  `employeeid` char(30) NOT NULL DEFAULT '',
  `salaryid` int(10) UNSIGNED NOT NULL DEFAULT 0,
  `salaryname` varchar(100) NOT NULL DEFAULT '',
  `kind` int(11) NOT NULL DEFAULT 1 COMMENT '1=fixed, 2=input, 3=formula',
  `formula` text NOT NULL,
  `variables` text NOT NULL,
  `debit` double NOT NULL DEFAULT 0,
  `credit` double NOT NULL DEFAULT 0,
  `transdate` datetime DEFAULT NULL,
  `posted` int(11) DEFAULT 0,
  `usercreate` char(16) NOT NULL DEFAULT '',
  `useredit` char(16) NOT NULL DEFAULT '',
  `updatetimestamp` timestamp NOT NULL DEFAULT current_timestamp() ON UPDATE current_timestamp()
) ENGINE=InnoDB DEFAULT CHARSET=utf8mb4 COLLATE=utf8mb4_unicode_ci;

CREATE TABLE `salarypayments` (
  `transid` char(30) NOT NULL DEFAULT '',
  `transdate` date DEFAULT NULL,
  `transtime` time DEFAULT NULL,
  `division` char(10) NOT NULL DEFAULT '',
  `employeeid` char(30) NOT NULL DEFAULT '',
  `employeename` varchar(100) NOT NULL DEFAULT '',
  `employeeaddress` varchar(200) NOT NULL DEFAULT '',
  `salarybalance` double NOT NULL DEFAULT 0,
  `salaryid` int(10) UNSIGNED NOT NULL DEFAULT 0,
  `paymentvalue` double NOT NULL DEFAULT 0,
  `paymenttype` int(10) UNSIGNED NOT NULL,
  `refpayment` varchar(30) NOT NULL,
  `usercreate` char(16) NOT NULL DEFAULT '',
  `useredit` char(16) NOT NULL DEFAULT ''
) ENGINE=InnoDB DEFAULT CHARSET=utf8mb4 COLLATE=utf8mb4_unicode_ci;

CREATE TABLE `salaryperiod` (
  `id` char(30) NOT NULL DEFAULT '',
  `description` varchar(100) NOT NULL DEFAULT '',
  `fromdate` datetime DEFAULT NULL,
  `todate` datetime DEFAULT NULL,
  `posted` tinyint(1) NOT NULL DEFAULT 0,
  `division` varchar(10) NOT NULL DEFAULT '',
  `accountid` char(30) NOT NULL DEFAULT '',
  `postingdate` datetime DEFAULT NULL,
  `employeegroup` char(30) NOT NULL DEFAULT '',
  `usercreate` char(16) NOT NULL DEFAULT '',
  `useredit` char(16) NOT NULL DEFAULT '',
  `updatetimestamp` timestamp NOT NULL DEFAULT current_timestamp()
) ENGINE=InnoDB DEFAULT CHARSET=utf8mb4 COLLATE=utf8mb4_unicode_ci;

CREATE TABLE `salaryperioddetail` (
  `transid` bigint(20) UNSIGNED NOT NULL,
  `salaryperiod` char(30) NOT NULL DEFAULT '',
  `employeeid` char(30) NOT NULL DEFAULT '',
  `employeename` varchar(100) DEFAULT '',
  `postingdate` datetime DEFAULT NULL,
  `totalsalary` double DEFAULT 0,
  `usercreate` char(16) NOT NULL DEFAULT '',
  `useredit` char(16) NOT NULL DEFAULT '',
  `updatetimestamp` timestamp NOT NULL DEFAULT current_timestamp()
) ENGINE=InnoDB DEFAULT CHARSET=utf8mb4 COLLATE=utf8mb4_unicode_ci;

CREATE TABLE `salarystructure` (
  `id` int(10) UNSIGNED NOT NULL DEFAULT 0,
  `description` varchar(100) NOT NULL DEFAULT '',
  `usercreate` char(16) NOT NULL DEFAULT '',
  `useredit` char(16) NOT NULL DEFAULT '',
  `updatetimestamp` timestamp NOT NULL DEFAULT current_timestamp() ON UPDATE current_timestamp()
) ENGINE=InnoDB DEFAULT CHARSET=utf8mb4 COLLATE=utf8mb4_unicode_ci;

CREATE TABLE `salarystructuredetail` (
  `id` bigint(20) UNSIGNED NOT NULL,
  `salarystructure` int(10) UNSIGNED NOT NULL DEFAULT 0,
  `salaryid` int(10) UNSIGNED NOT NULL DEFAULT 0,
  `kind` int(11) NOT NULL DEFAULT 1 COMMENT '1=fixed, 2=input, 3=formula',
  `defaultvalue` double NOT NULL DEFAULT 0,
  `formula` text NOT NULL,
  `usercreate` char(16) NOT NULL DEFAULT '',
  `weight` int(11) NOT NULL DEFAULT 0,
  `useredit` char(16) NOT NULL DEFAULT '',
  `updatetimestamp` timestamp NOT NULL DEFAULT current_timestamp() ON UPDATE current_timestamp()
) ENGINE=InnoDB DEFAULT CHARSET=utf8mb4 COLLATE=utf8mb4_unicode_ci;

CREATE TABLE `sales` (
  `salesid` char(30) NOT NULL DEFAULT '',
  `salesidref` char(30) NOT NULL DEFAULT '',
  `salesorder` char(30) NOT NULL DEFAULT '',
  `salesdate` date DEFAULT NULL,
  `salestime` time DEFAULT NULL,
  `kind` int(11) NOT NULL DEFAULT 1,
  `salestype` smallint(6) NOT NULL DEFAULT 0 COMMENT '0=CASH, 1=CASH ON DELIVERY, 2=CREDIT',
  `earlydiscdays` int(11) NOT NULL DEFAULT 0,
  `earlydiscvalue` double NOT NULL DEFAULT 0,
  `duedays` int(11) NOT NULL DEFAULT 0,
  `customerid` char(30) NOT NULL DEFAULT '',
  `customername` varchar(100) NOT NULL DEFAULT '',
  `customeraddress` varchar(200) NOT NULL DEFAULT '',
  `customercreditlimit` double NOT NULL DEFAULT 0,
  `customercreditlimittype` tinyint(4) NOT NULL DEFAULT 0,
  `customertaxid` varchar(50) NOT NULL DEFAULT '',
  `customertaxable` smallint(6) NOT NULL DEFAULT 0,
  `customerbalance` double NOT NULL DEFAULT 0,
  `pricelevel` smallint(6) NOT NULL DEFAULT 1,
  `currtrans` char(3) NOT NULL DEFAULT '',
  `ratedefault` double NOT NULL DEFAULT 0,
  `rateused` double NOT NULL DEFAULT 0,
  `salesmanid` char(30) NOT NULL DEFAULT '',
  `billto` char(30) NOT NULL DEFAULT '',
  `billtoname` varchar(100) NOT NULL DEFAULT '',
  `billtocreditlimit` double NOT NULL DEFAULT 0,
  `salesmanname` varchar(100) NOT NULL DEFAULT '',
  `shipto` text DEFAULT NULL,
  `salespercentdisc` double NOT NULL DEFAULT 0,
  `returnpercentdisc` double NOT NULL DEFAULT 0,
  `salesvaluedisc` double NOT NULL DEFAULT 0,
  `returnvaluedisc` double NOT NULL DEFAULT 0,
  `pointbalance` double NOT NULL DEFAULT 0,
  `salespoint` double NOT NULL DEFAULT 0,
  `returnpoint` double NOT NULL DEFAULT 0,
  `currpointbalance` double NOT NULL DEFAULT 0,
  `salestotal` double NOT NULL DEFAULT 0,
  `memo` text DEFAULT NULL,
  `memoedit` text DEFAULT NULL,
  `division` char(10) NOT NULL DEFAULT '',
  `printed` smallint(6) NOT NULL DEFAULT 0,
  `taxprinted` smallint(6) NOT NULL DEFAULT 0,
  `shipment` int(10) UNSIGNED NOT NULL DEFAULT 1,
  `dateaccepted` datetime DEFAULT NULL,
  `accepted` smallint(6) NOT NULL DEFAULT 1,
  `paidinfull` smallint(6) NOT NULL DEFAULT 0,
  `paidinfulldate` date DEFAULT NULL,
  `paidinfullref` char(30) NOT NULL DEFAULT '',
  `usercreate` char(16) NOT NULL DEFAULT '',
  `useredit` char(16) NOT NULL DEFAULT '',
  `posted` smallint(6) NOT NULL DEFAULT 1,
  `packed` int(11) NOT NULL DEFAULT 0,
  `posid` int(11) NOT NULL DEFAULT 0,
  `renttrans` int(11) NOT NULL DEFAULT 0,
  `rentaltime` int(11) NOT NULL DEFAULT 0,
  `rentaltimeunit` varchar(10) NOT NULL DEFAULT '',
  `rentfinishtime` datetime DEFAULT NULL,
  `rentfinishstatus` int(11) DEFAULT 0,
  `updatetimestamp` timestamp NOT NULL DEFAULT current_timestamp() ON UPDATE current_timestamp()
) ENGINE=InnoDB DEFAULT CHARSET=utf8mb4 COLLATE=utf8mb4_unicode_ci;

CREATE TABLE `salesdetail` (
  `transid` bigint(20) UNSIGNED NOT NULL,
  `transdate` datetime DEFAULT NULL,
  `salesid` char(30) NOT NULL DEFAULT '',
  `salesidref` char(30) NOT NULL DEFAULT '',
  `productid` char(30) NOT NULL DEFAULT '',
  `productname` varchar(100) NOT NULL DEFAULT '',
  `usesn` int(11) NOT NULL DEFAULT 0,
  `snproduct` varchar(100) NOT NULL DEFAULT '',
  `expireddate` date DEFAULT NULL,
  `salesqty` double NOT NULL DEFAULT 0,
  `returnqty` double NOT NULL DEFAULT 0,
  `unit` char(10) NOT NULL DEFAULT '',
  `unitqty` double NOT NULL DEFAULT 0,
  `price` double NOT NULL DEFAULT 0,
  `grossamount` double NOT NULL DEFAULT 0,
  `taxid` tinyint(4) NOT NULL DEFAULT 0,
  `salestax` double NOT NULL DEFAULT 0,
  `returntax` double NOT NULL DEFAULT 0,
  `percentdisc` varchar(50) NOT NULL DEFAULT '',
  `discformula` varchar(50) NOT NULL DEFAULT '',
  `valuedisc` double NOT NULL DEFAULT 0,
  `netamount` double NOT NULL DEFAULT 0,
  `cogs` double NOT NULL DEFAULT 0,
  `memo` text DEFAULT NULL,
  `departement` char(10) NOT NULL DEFAULT '',
  `servicedoerid` char(30) NOT NULL DEFAULT '',
  `servicedoername` varchar(100) NOT NULL DEFAULT '',
  `usercreate` char(16) NOT NULL DEFAULT '',
  `useredit` char(16) NOT NULL DEFAULT '',
  `updatetimestamp` timestamp NOT NULL DEFAULT current_timestamp() ON UPDATE current_timestamp()
) ENGINE=InnoDB DEFAULT CHARSET=utf8mb4 COLLATE=utf8mb4_unicode_ci;

CREATE TABLE `salesdiscrules` (
  `id` int(10) UNSIGNED NOT NULL DEFAULT 0,
  `description` varchar(100) NOT NULL DEFAULT '',
  `displayname` varchar(20) NOT NULL DEFAULT '',
  `formula` text DEFAULT NULL,
  `category` int(11) NOT NULL DEFAULT 0,
  `kind` int(11) NOT NULL DEFAULT 0,
  `usercreate` char(16) NOT NULL DEFAULT '',
  `useredit` char(16) NOT NULL DEFAULT '',
  `updatetimestamp` timestamp NOT NULL DEFAULT current_timestamp() ON UPDATE current_timestamp()
) ENGINE=InnoDB DEFAULT CHARSET=utf8mb4 COLLATE=utf8mb4_unicode_ci;

CREATE TABLE `salesexpenses` (
  `id` int(10) UNSIGNED NOT NULL DEFAULT 0,
  `name` varchar(50) NOT NULL DEFAULT '',
  `description` varchar(100) NOT NULL DEFAULT '',
  `salesexpacc` char(30) NOT NULL DEFAULT '',
  `usercreate` char(16) NOT NULL DEFAULT '',
  `useredit` char(16) NOT NULL DEFAULT '',
  `updatetimestamp` timestamp NOT NULL DEFAULT current_timestamp() ON UPDATE current_timestamp()
) ENGINE=InnoDB DEFAULT CHARSET=utf8mb4 COLLATE=utf8mb4_unicode_ci;

CREATE TABLE `salesexpensesdetail` (
  `transid` bigint(20) UNSIGNED NOT NULL,
  `salesid` char(30) NOT NULL DEFAULT '',
  `salesidref` char(30) NOT NULL DEFAULT '',
  `transdate` datetime DEFAULT NULL,
  `kind` int(11) NOT NULL DEFAULT 0,
  `salesexpid` int(10) UNSIGNED NOT NULL,
  `debit` double NOT NULL DEFAULT 0,
  `credit` double NOT NULL DEFAULT 0,
  `memo` text DEFAULT NULL,
  `currtrans` char(3) NOT NULL DEFAULT '',
  `ratedefault` double NOT NULL DEFAULT 0,
  `rateused` double NOT NULL DEFAULT 0,
  `usercreate` char(16) NOT NULL DEFAULT '',
  `useredit` char(16) NOT NULL DEFAULT '',
  `updatetimestamp` timestamp NOT NULL DEFAULT current_timestamp() ON UPDATE current_timestamp()
) ENGINE=InnoDB DEFAULT CHARSET=utf8mb4 COLLATE=utf8mb4_unicode_ci;

CREATE TABLE `salesextratax` (
  `transid` bigint(20) UNSIGNED NOT NULL,
  `transdate` datetime DEFAULT NULL,
  `salesid` char(30) NOT NULL DEFAULT '',
  `salesidref` char(30) NOT NULL DEFAULT '',
  `productid` char(30) NOT NULL DEFAULT '',
  `productname` varchar(100) NOT NULL DEFAULT '',
  `salesqty` double NOT NULL DEFAULT 0,
  `returnqty` double NOT NULL DEFAULT 0,
  `unit` char(10) NOT NULL DEFAULT '',
  `grossamount` double NOT NULL DEFAULT 0,
  `taxid` tinyint(4) NOT NULL DEFAULT 0,
  `salestax` double NOT NULL DEFAULT 0,
  `returntax` double NOT NULL DEFAULT 0,
  `usercreate` char(16) NOT NULL DEFAULT '',
  `useredit` char(16) NOT NULL DEFAULT '',
  `updatetimestamp` timestamp NOT NULL DEFAULT current_timestamp() ON UPDATE current_timestamp()
) ENGINE=InnoDB DEFAULT CHARSET=utf8mb4 COLLATE=utf8mb4_unicode_ci;

CREATE TABLE `salesman` (
  `id` char(30) NOT NULL DEFAULT '',
  `name` varchar(100) NOT NULL DEFAULT '',
  `salesmangroup` char(30) NOT NULL DEFAULT '',
  `address` varchar(200) NOT NULL DEFAULT '',
  `telephone` varchar(50) NOT NULL DEFAULT '',
  `faximile` varchar(50) NOT NULL DEFAULT '',
  `mobilephone` varchar(50) NOT NULL DEFAULT '',
  `category` tinyint(4) NOT NULL DEFAULT 0 COMMENT '0=PERSONAL, 1=COMPANY',
  `contactperson` varchar(100) NOT NULL DEFAULT '',
  `religion` int(10) UNSIGNED NOT NULL DEFAULT 0,
  `birthdate` date DEFAULT NULL,
  `sex` tinyint(4) NOT NULL DEFAULT 0 COMMENT '0=MALE, 1=FEMALE',
  `email` varchar(100) NOT NULL DEFAULT '',
  `website` varchar(100) NOT NULL DEFAULT '',
  `creditlimit` double NOT NULL DEFAULT 0,
  `registerdate` date DEFAULT NULL,
  `activeuntil` date DEFAULT '2099-12-31',
  `country` char(3) NOT NULL DEFAULT '',
  `isactive` smallint(6) NOT NULL DEFAULT 1,
  `commisionrules` text DEFAULT NULL,
  `payablecommacc` char(30) NOT NULL DEFAULT '',
  `expensecommacc` char(30) NOT NULL DEFAULT '',
  `usercreate` char(16) NOT NULL DEFAULT '',
  `useredit` char(16) NOT NULL DEFAULT '',
  `updatetimestamp` timestamp NOT NULL DEFAULT current_timestamp() ON UPDATE current_timestamp(),
  `image` varchar(255) DEFAULT '[]'
) ENGINE=InnoDB DEFAULT CHARSET=utf8mb4 COLLATE=utf8mb4_unicode_ci;

CREATE TABLE `salesmancommperiod` (
  `id` bigint(20) UNSIGNED NOT NULL DEFAULT 0,
  `fromdate` date DEFAULT NULL,
  `fromtime` time DEFAULT NULL,
  `todate` date DEFAULT NULL,
  `totime` time DEFAULT NULL,
  `minsalesretur` tinyint(1) NOT NULL DEFAULT 1,
  `onlypaidsales` tinyint(1) NOT NULL DEFAULT 0,
  `onlyproductpaid` tinyint(1) NOT NULL DEFAULT 0,
  `onlyacceptedpaid` tinyint(1) NOT NULL DEFAULT 1,
  `accumrules` tinyint(1) NOT NULL DEFAULT 0,
  `includereceivable` tinyint(1) NOT NULL DEFAULT 1,
  `mintransdisc` tinyint(1) NOT NULL DEFAULT 1,
  `minproductdisc` tinyint(1) NOT NULL DEFAULT 1,
  `onlypaidinfull` tinyint(1) NOT NULL DEFAULT 0,
  `notlatereceivables` tinyint(1) NOT NULL DEFAULT 0,
  `posted` tinyint(1) NOT NULL DEFAULT 0,
  `currtrans` char(3) NOT NULL DEFAULT '',
  `division` varchar(10) NOT NULL DEFAULT '',
  `formula` text DEFAULT NULL,
  `refid` char(30) NOT NULL DEFAULT '',
  `postdate` date DEFAULT NULL,
  `posttime` time DEFAULT NULL,
  `salaryid` int(10) UNSIGNED NOT NULL DEFAULT 0,
  `groups` varchar(100) NOT NULL DEFAULT '',
  `updatetimestamp` timestamp NOT NULL DEFAULT current_timestamp()
) ENGINE=InnoDB DEFAULT CHARSET=utf8mb4 COLLATE=utf8mb4_unicode_ci;

CREATE TABLE `salesmancommrules` (
  `id` int(10) UNSIGNED NOT NULL DEFAULT 0,
  `description` varchar(100) NOT NULL DEFAULT '',
  `displayname` varchar(20) NOT NULL DEFAULT '',
  `category` int(11) NOT NULL DEFAULT 0,
  `formula` text DEFAULT NULL,
  `usercreate` char(16) NOT NULL DEFAULT '',
  `useredit` char(16) NOT NULL DEFAULT '',
  `updatetimestamp` timestamp NOT NULL DEFAULT current_timestamp() ON UPDATE current_timestamp()
) ENGINE=InnoDB DEFAULT CHARSET=utf8mb4 COLLATE=utf8mb4_unicode_ci;

CREATE TABLE `salesmancommvar` (
  `varname` char(10) NOT NULL DEFAULT '',
  `varvalue` double NOT NULL DEFAULT 0,
  `description` varchar(50) NOT NULL DEFAULT ''
) ENGINE=InnoDB DEFAULT CHARSET=utf8mb4 COLLATE=utf8mb4_unicode_ci;

CREATE TABLE `salesmancommvarrecords` (
  `transid` bigint(20) UNSIGNED NOT NULL,
  `periodid` bigint(20) UNSIGNED NOT NULL,
  `varname` char(10) NOT NULL DEFAULT '',
  `varvalue` double NOT NULL DEFAULT 0,
  `description` varchar(50) NOT NULL DEFAULT ''
) ENGINE=InnoDB DEFAULT CHARSET=utf8mb4 COLLATE=utf8mb4_unicode_ci;

CREATE TABLE `salesmandetail` (
  `groupid` char(30) NOT NULL DEFAULT '',
  `salesmanid` char(30) NOT NULL DEFAULT '',
  `salesmanname` varchar(100) NOT NULL DEFAULT '',
  `percent` double NOT NULL DEFAULT 0,
  `memo` varchar(100) NOT NULL DEFAULT '',
  `usercreate` char(16) NOT NULL DEFAULT '',
  `useredit` char(16) NOT NULL DEFAULT '',
  `updatetimestamp` timestamp NOT NULL DEFAULT current_timestamp() ON UPDATE current_timestamp()
) ENGINE=InnoDB DEFAULT CHARSET=utf8mb4 COLLATE=utf8mb4_unicode_ci;

CREATE TABLE `salesmangroup` (
  `id` char(30) NOT NULL DEFAULT '',
  `description` varchar(100) NOT NULL DEFAULT '',
  `commisionrules` text DEFAULT NULL,
  `payablecommacc` char(30) NOT NULL DEFAULT '',
  `expensecommacc` char(30) NOT NULL DEFAULT '',
  `usercreate` char(16) NOT NULL DEFAULT '',
  `useredit` char(16) NOT NULL DEFAULT '',
  `updatetimestamp` timestamp NOT NULL DEFAULT current_timestamp() ON UPDATE current_timestamp()
) ENGINE=InnoDB DEFAULT CHARSET=utf8mb4 COLLATE=utf8mb4_unicode_ci;

CREATE TABLE `salesmanrecorddetail` (
  `transid` bigint(20) UNSIGNED NOT NULL,
  `periodid` bigint(20) UNSIGNED NOT NULL,
  `salesmanid` char(30) NOT NULL DEFAULT '',
  `salesmanname` varchar(100) NOT NULL DEFAULT '',
  `productid` char(30) NOT NULL DEFAULT '',
  `productname` varchar(100) NOT NULL DEFAULT '',
  `salestargetqty` double NOT NULL DEFAULT 0,
  `salestargetvalue` double NOT NULL DEFAULT 0,
  `salesrealqty` double NOT NULL DEFAULT 0,
  `salesrealvalue` double NOT NULL DEFAULT 0,
  `percentqty` double NOT NULL DEFAULT 0,
  `percentvalue` double NOT NULL DEFAULT 0,
  `profit` double NOT NULL DEFAULT 0,
  `commission` double NOT NULL DEFAULT 0,
  `kind` int(11) NOT NULL DEFAULT 0,
  `usercreate` char(16) NOT NULL DEFAULT '',
  `useredit` char(16) NOT NULL DEFAULT '',
  `updatetimestamp` timestamp NOT NULL DEFAULT current_timestamp()
) ENGINE=InnoDB DEFAULT CHARSET=utf8mb4 COLLATE=utf8mb4_unicode_ci;

CREATE TABLE `salesmanrecords` (
  `id` bigint(20) UNSIGNED NOT NULL,
  `periodid` bigint(20) UNSIGNED NOT NULL,
  `salesmanid` char(30) NOT NULL DEFAULT '',
  `salesmanname` varchar(100) NOT NULL DEFAULT '',
  `salesmanaddress` varchar(200) NOT NULL DEFAULT '',
  `receivable` double NOT NULL DEFAULT 0,
  `salestarget` double NOT NULL DEFAULT 0,
  `salesreal` double NOT NULL DEFAULT 0,
  `salespaid` double NOT NULL DEFAULT 0,
  `salespaymentaccepted` double NOT NULL DEFAULT 0,
  `percent` double NOT NULL DEFAULT 0,
  `profit` double NOT NULL DEFAULT 0,
  `commission` double NOT NULL DEFAULT 0,
  `productcommission` double NOT NULL DEFAULT 0,
  `receivablecommission` double NOT NULL DEFAULT 0,
  `totalcommission` double NOT NULL DEFAULT 0,
  `commissionpaid` double NOT NULL DEFAULT 0,
  `usercreate` char(16) NOT NULL DEFAULT '',
  `useredit` char(16) NOT NULL DEFAULT '',
  `updatetimestamp` timestamp NOT NULL DEFAULT current_timestamp()
) ENGINE=InnoDB DEFAULT CHARSET=utf8mb4 COLLATE=utf8mb4_unicode_ci;

CREATE TABLE `salesorder` (
  `salesid` char(30) NOT NULL DEFAULT '',
  `salesidref` char(30) NOT NULL DEFAULT '',
  `salesdate` date DEFAULT NULL,
  `salestime` time DEFAULT NULL,
  `kind` int(11) NOT NULL DEFAULT 0,
  `salestype` smallint(6) NOT NULL DEFAULT 0 COMMENT '0=CASH, 1=CASH ON DELIVERY, 2=CREDIT',
  `earlydiscdays` int(11) NOT NULL DEFAULT 0,
  `earlydiscvalue` double NOT NULL DEFAULT 0,
  `duedays` int(11) NOT NULL DEFAULT 0,
  `customerid` char(30) NOT NULL DEFAULT '',
  `customername` varchar(100) NOT NULL DEFAULT '',
  `customeraddress` varchar(200) NOT NULL DEFAULT '',
  `customercreditlimit` double NOT NULL DEFAULT 0,
  `customercreditlimittype` tinyint(4) NOT NULL DEFAULT 0,
  `customertaxid` varchar(50) NOT NULL DEFAULT '',
  `customertaxable` smallint(6) NOT NULL DEFAULT 0,
  `customerbalance` double NOT NULL DEFAULT 0,
  `pricelevel` smallint(6) NOT NULL DEFAULT 1,
  `currtrans` char(3) NOT NULL DEFAULT '',
  `ratedefault` double NOT NULL DEFAULT 0,
  `rateused` double NOT NULL DEFAULT 0,
  `salesmanid` char(30) NOT NULL DEFAULT '',
  `billto` char(30) NOT NULL DEFAULT '',
  `billtoname` varchar(100) NOT NULL DEFAULT '',
  `billtocreditlimit` double NOT NULL DEFAULT 0,
  `salesmanname` varchar(100) NOT NULL DEFAULT '',
  `shipto` text DEFAULT NULL,
  `salespercentdisc` double NOT NULL DEFAULT 0,
  `returnpercentdisc` double NOT NULL DEFAULT 0,
  `salesvaluedisc` double NOT NULL DEFAULT 0,
  `returnvaluedisc` double NOT NULL DEFAULT 0,
  `pointbalance` double NOT NULL DEFAULT 0,
  `salespoint` double NOT NULL DEFAULT 0,
  `returnpoint` double NOT NULL DEFAULT 0,
  `currpointbalance` double NOT NULL DEFAULT 0,
  `salestotal` double NOT NULL DEFAULT 0,
  `memo` text DEFAULT NULL,
  `memoedit` text DEFAULT NULL,
  `division` char(10) NOT NULL DEFAULT '',
  `printed` smallint(6) NOT NULL DEFAULT 0,
  `taxprinted` smallint(6) NOT NULL DEFAULT 0,
  `shipment` int(10) UNSIGNED NOT NULL DEFAULT 1,
  `dateaccepted` datetime DEFAULT NULL,
  `accepted` smallint(6) NOT NULL DEFAULT 1,
  `paidinfull` smallint(6) NOT NULL DEFAULT 0,
  `paidinfulldate` date DEFAULT NULL,
  `paidinfullref` char(30) NOT NULL DEFAULT '',
  `taxprint` tinyint(1) NOT NULL DEFAULT 0,
  `taxprintid` varchar(30) NOT NULL DEFAULT '',
  `usercreate` char(16) NOT NULL DEFAULT '',
  `useredit` char(16) NOT NULL DEFAULT '',
  `posted` smallint(6) NOT NULL DEFAULT 1,
  `packed` int(11) NOT NULL DEFAULT 0,
  `updatetimestamp` timestamp NOT NULL DEFAULT current_timestamp() ON UPDATE current_timestamp()
) ENGINE=InnoDB DEFAULT CHARSET=utf8mb4 COLLATE=utf8mb4_unicode_ci;

CREATE TABLE `salesorderdetail` (
  `transid` bigint(20) UNSIGNED NOT NULL,
  `transdate` datetime DEFAULT NULL,
  `salesid` char(30) NOT NULL DEFAULT '',
  `salesidref` char(30) NOT NULL DEFAULT '',
  `productid` char(30) NOT NULL DEFAULT '',
  `productname` varchar(100) NOT NULL DEFAULT '',
  `usesn` int(11) NOT NULL DEFAULT 0,
  `snproduct` varchar(100) NOT NULL DEFAULT '',
  `expireddate` date DEFAULT NULL,
  `salesqty` double NOT NULL DEFAULT 0,
  `returnqty` double NOT NULL DEFAULT 0,
  `unit` char(10) NOT NULL DEFAULT '',
  `unitqty` double NOT NULL DEFAULT 0,
  `price` double NOT NULL DEFAULT 0,
  `grossamount` double NOT NULL DEFAULT 0,
  `taxid` tinyint(4) NOT NULL DEFAULT 0,
  `salestax` double NOT NULL DEFAULT 0,
  `returntax` double NOT NULL DEFAULT 0,
  `percentdisc` varchar(50) NOT NULL DEFAULT '',
  `discformula` varchar(50) NOT NULL DEFAULT '',
  `valuedisc` double NOT NULL DEFAULT 0,
  `netamount` double NOT NULL DEFAULT 0,
  `cogs` double NOT NULL DEFAULT 0,
  `memo` text DEFAULT NULL,
  `departement` char(10) NOT NULL DEFAULT '',
  `servicedoerid` char(30) NOT NULL DEFAULT '',
  `servicedoername` varchar(100) NOT NULL DEFAULT '',
  `usercreate` char(16) NOT NULL DEFAULT '',
  `useredit` char(16) NOT NULL DEFAULT '',
  `updatetimestamp` timestamp NOT NULL DEFAULT current_timestamp() ON UPDATE current_timestamp()
) ENGINE=InnoDB DEFAULT CHARSET=utf8mb4 COLLATE=utf8mb4_unicode_ci;

CREATE TABLE `salesorderexpensesdetail` (
  `transid` bigint(20) UNSIGNED NOT NULL,
  `salesid` char(30) NOT NULL DEFAULT '',
  `salesidref` char(30) NOT NULL DEFAULT '',
  `transdate` datetime DEFAULT NULL,
  `kind` int(11) NOT NULL DEFAULT 0,
  `salesexpid` int(10) UNSIGNED NOT NULL,
  `debit` double NOT NULL DEFAULT 0,
  `credit` double NOT NULL DEFAULT 0,
  `memo` text DEFAULT NULL,
  `currtrans` char(3) NOT NULL DEFAULT '',
  `ratedefault` double NOT NULL DEFAULT 0,
  `rateused` double NOT NULL DEFAULT 0,
  `usercreate` char(16) NOT NULL DEFAULT '',
  `useredit` char(16) NOT NULL DEFAULT '',
  `updatetimestamp` timestamp NOT NULL DEFAULT current_timestamp() ON UPDATE current_timestamp()
) ENGINE=InnoDB DEFAULT CHARSET=utf8mb4 COLLATE=utf8mb4_unicode_ci;

CREATE TABLE `salesorderextratax` (
  `transid` bigint(20) UNSIGNED NOT NULL,
  `transdate` datetime DEFAULT NULL,
  `salesid` char(30) NOT NULL DEFAULT '',
  `salesidref` char(30) NOT NULL DEFAULT '',
  `productid` char(30) NOT NULL DEFAULT '',
  `productname` varchar(100) NOT NULL DEFAULT '',
  `salesqty` double NOT NULL DEFAULT 0,
  `returnqty` double NOT NULL DEFAULT 0,
  `unit` char(10) NOT NULL DEFAULT '',
  `grossamount` double NOT NULL DEFAULT 0,
  `taxid` tinyint(4) NOT NULL DEFAULT 0,
  `salestax` double NOT NULL DEFAULT 0,
  `returntax` double NOT NULL DEFAULT 0,
  `usercreate` char(16) NOT NULL DEFAULT '',
  `useredit` char(16) NOT NULL DEFAULT '',
  `updatetimestamp` timestamp NOT NULL DEFAULT current_timestamp() ON UPDATE current_timestamp()
) ENGINE=InnoDB DEFAULT CHARSET=utf8mb4 COLLATE=utf8mb4_unicode_ci;

CREATE TABLE `salesorderpayments` (
  `transid` bigint(20) UNSIGNED NOT NULL,
  `salesid` char(30) NOT NULL DEFAULT '',
  `salesidref` char(30) NOT NULL DEFAULT '',
  `transdate` datetime DEFAULT NULL,
  `debit` double NOT NULL DEFAULT 0,
  `credit` double NOT NULL DEFAULT 0,
  `discountpercent` double NOT NULL DEFAULT 0,
  `discountvalue` double NOT NULL DEFAULT 0,
  `expensepercent` double NOT NULL DEFAULT 0,
  `expensevalue` double NOT NULL DEFAULT 0,
  `duedate` date DEFAULT NULL,
  `accepted` smallint(6) NOT NULL DEFAULT 0,
  `kind` smallint(6) NOT NULL DEFAULT 0,
  `paymenttype` int(10) UNSIGNED NOT NULL,
  `refpayment` varchar(30) NOT NULL,
  `currtrans` char(3) NOT NULL DEFAULT '',
  `ratedefault` double NOT NULL DEFAULT 0,
  `rateused` double NOT NULL DEFAULT 0,
  `usercreate` char(16) NOT NULL DEFAULT '',
  `useredit` char(16) NOT NULL DEFAULT '',
  `updatetimestamp` timestamp NOT NULL DEFAULT current_timestamp() ON UPDATE current_timestamp()
) ENGINE=InnoDB DEFAULT CHARSET=utf8mb4 COLLATE=utf8mb4_unicode_ci;

CREATE TABLE `salesorderpoint` (
  `transid` bigint(20) UNSIGNED NOT NULL,
  `transdate` datetime DEFAULT NULL,
  `salesid` char(30) NOT NULL DEFAULT '',
  `salesidref` char(30) NOT NULL DEFAULT '',
  `customer` char(30) NOT NULL DEFAULT '',
  `qtyin` double NOT NULL DEFAULT 0,
  `qtyout` double NOT NULL DEFAULT 0,
  `usercreate` char(16) NOT NULL DEFAULT '',
  `useredit` char(16) NOT NULL DEFAULT '',
  `updatetimestamp` timestamp NOT NULL DEFAULT current_timestamp() ON UPDATE current_timestamp()
) ENGINE=InnoDB DEFAULT CHARSET=utf8mb4 COLLATE=utf8mb4_unicode_ci;

CREATE TABLE `salesorderrewarddetail` (
  `transid` bigint(20) UNSIGNED NOT NULL,
  `transdate` datetime DEFAULT NULL,
  `salesid` char(30) NOT NULL DEFAULT '',
  `salesidref` char(30) NOT NULL DEFAULT '',
  `productid` char(30) NOT NULL DEFAULT '',
  `productname` varchar(100) NOT NULL DEFAULT '',
  `snproduct` varchar(100) NOT NULL DEFAULT '',
  `expireddate` date DEFAULT NULL,
  `salesqty` double NOT NULL DEFAULT 0,
  `returnqty` double NOT NULL DEFAULT 0,
  `unit` char(10) NOT NULL DEFAULT '',
  `unitqty` double NOT NULL DEFAULT 0,
  `price` double NOT NULL DEFAULT 0,
  `grossamount` double NOT NULL DEFAULT 0,
  `taxid` tinyint(4) NOT NULL DEFAULT 0,
  `salestax` double NOT NULL DEFAULT 0,
  `returntax` double NOT NULL DEFAULT 0,
  `netamount` double NOT NULL DEFAULT 0,
  `memo` text DEFAULT NULL,
  `departement` char(10) NOT NULL DEFAULT '',
  `usercreate` char(16) NOT NULL DEFAULT '',
  `useredit` char(16) NOT NULL DEFAULT '',
  `updatetimestamp` timestamp NOT NULL DEFAULT current_timestamp() ON UPDATE current_timestamp()
) ENGINE=InnoDB DEFAULT CHARSET=utf8mb4 COLLATE=utf8mb4_unicode_ci;

CREATE TABLE `salespayments` (
  `transid` bigint(20) UNSIGNED NOT NULL,
  `salesid` char(30) NOT NULL DEFAULT '',
  `salesidref` char(30) NOT NULL DEFAULT '',
  `transdate` datetime DEFAULT NULL,
  `debit` double NOT NULL DEFAULT 0,
  `credit` double NOT NULL DEFAULT 0,
  `discountpercent` double NOT NULL DEFAULT 0,
  `discountvalue` double NOT NULL DEFAULT 0,
  `expensepercent` double NOT NULL DEFAULT 0,
  `expensevalue` double NOT NULL DEFAULT 0,
  `duedate` date DEFAULT NULL,
  `accepted` smallint(6) NOT NULL DEFAULT 0,
  `kind` smallint(6) NOT NULL DEFAULT 0,
  `paymenttype` int(10) UNSIGNED NOT NULL,
  `pointtotal` double NOT NULL DEFAULT 0,
  `pointpayment` double NOT NULL DEFAULT 0,
  `refpayment` varchar(30) NOT NULL,
  `currtrans` char(3) NOT NULL DEFAULT '',
  `ratedefault` double NOT NULL DEFAULT 0,
  `rateused` double NOT NULL DEFAULT 0,
  `usercreate` char(16) NOT NULL DEFAULT '',
  `useredit` char(16) NOT NULL DEFAULT '',
  `updatetimestamp` timestamp NOT NULL DEFAULT current_timestamp() ON UPDATE current_timestamp()
) ENGINE=InnoDB DEFAULT CHARSET=utf8mb4 COLLATE=utf8mb4_unicode_ci;

CREATE TABLE `salespoint` (
  `transid` bigint(20) UNSIGNED NOT NULL,
  `transdate` datetime DEFAULT NULL,
  `salesid` char(30) NOT NULL DEFAULT '',
  `salesidref` char(30) NOT NULL DEFAULT '',
  `customer` char(30) NOT NULL DEFAULT '',
  `qtyin` double NOT NULL DEFAULT 0,
  `qtyout` double NOT NULL DEFAULT 0,
  `usercreate` char(16) NOT NULL DEFAULT '',
  `useredit` char(16) NOT NULL DEFAULT '',
  `updatetimestamp` timestamp NOT NULL DEFAULT current_timestamp() ON UPDATE current_timestamp()
) ENGINE=InnoDB DEFAULT CHARSET=utf8mb4 COLLATE=utf8mb4_unicode_ci;

CREATE TABLE `salespointrewardrules` (
  `id` int(10) UNSIGNED NOT NULL DEFAULT 0,
  `description` varchar(100) NOT NULL DEFAULT '',
  `displayname` varchar(20) NOT NULL DEFAULT '',
  `formula` text DEFAULT NULL COMMENT 'TO GET POINT',
  `category` int(11) NOT NULL DEFAULT 0,
  `usercreate` char(16) NOT NULL DEFAULT '',
  `useredit` char(16) NOT NULL DEFAULT '',
  `updatetimestamp` timestamp NOT NULL DEFAULT current_timestamp() ON UPDATE current_timestamp()
) ENGINE=InnoDB DEFAULT CHARSET=utf8mb4 COLLATE=utf8mb4_unicode_ci;

CREATE TABLE `salesproductrewardrules` (
  `id` int(10) UNSIGNED NOT NULL DEFAULT 0,
  `description` varchar(100) NOT NULL DEFAULT '',
  `displayname` varchar(20) DEFAULT '',
  `formula` text DEFAULT NULL COMMENT 'TO GET PRODUCT REWARD QUANTITY',
  `category` int(11) NOT NULL DEFAULT 0,
  `productid` char(30) NOT NULL DEFAULT '',
  `unit` char(10) NOT NULL DEFAULT '',
  `departement` char(10) NOT NULL DEFAULT '',
  `usercreate` char(16) NOT NULL DEFAULT '',
  `useredit` char(16) NOT NULL DEFAULT '',
  `updatetimestamp` timestamp NOT NULL DEFAULT current_timestamp() ON UPDATE current_timestamp()
) ENGINE=InnoDB DEFAULT CHARSET=utf8mb4 COLLATE=utf8mb4_unicode_ci;

CREATE TABLE `salesrewarddetail` (
  `transid` bigint(20) UNSIGNED NOT NULL,
  `transdate` datetime DEFAULT NULL,
  `salesid` char(30) NOT NULL DEFAULT '',
  `salesidref` char(30) NOT NULL DEFAULT '',
  `productid` char(30) NOT NULL DEFAULT '',
  `productname` varchar(100) NOT NULL DEFAULT '',
  `snproduct` varchar(100) NOT NULL DEFAULT '',
  `expireddate` date DEFAULT NULL,
  `salesqty` double NOT NULL DEFAULT 0,
  `returnqty` double NOT NULL DEFAULT 0,
  `unit` char(10) NOT NULL DEFAULT '',
  `unitqty` double NOT NULL DEFAULT 0,
  `price` double NOT NULL DEFAULT 0,
  `grossamount` double NOT NULL DEFAULT 0,
  `taxid` tinyint(4) NOT NULL DEFAULT 0,
  `salestax` double NOT NULL DEFAULT 0,
  `returntax` double NOT NULL DEFAULT 0,
  `netamount` double NOT NULL DEFAULT 0,
  `memo` text DEFAULT NULL,
  `departement` char(10) NOT NULL DEFAULT '',
  `usercreate` char(16) NOT NULL DEFAULT '',
  `useredit` char(16) NOT NULL DEFAULT '',
  `updatetimestamp` timestamp NOT NULL DEFAULT current_timestamp() ON UPDATE current_timestamp()
) ENGINE=InnoDB DEFAULT CHARSET=utf8mb4 COLLATE=utf8mb4_unicode_ci;

CREATE TABLE `schoolclass` (
  `id` char(50) NOT NULL DEFAULT '',
  `name` varchar(100) NOT NULL DEFAULT '',
  `description` text NOT NULL,
  `schoollevel` char(50) NOT NULL DEFAULT '',
  `logo` varchar(255) NOT NULL DEFAULT '[]',
  `usercreate` char(16) NOT NULL DEFAULT '',
  `useredit` char(16) NOT NULL DEFAULT '',
  `updatetimestamp` timestamp NOT NULL DEFAULT current_timestamp() ON UPDATE current_timestamp()
) ENGINE=InnoDB DEFAULT CHARSET=utf8mb4 COLLATE=utf8mb4_unicode_ci;

CREATE TABLE `schoolexam` (
  `id` char(50) NOT NULL DEFAULT '',
  `name` varchar(100) NOT NULL DEFAULT '',
  `shortname` varchar(50) NOT NULL DEFAULT '',
  `usercreate` char(16) NOT NULL DEFAULT '',
  `useredit` char(16) NOT NULL DEFAULT '',
  `updatetimestamp` timestamp NOT NULL DEFAULT current_timestamp() ON UPDATE current_timestamp()
) ENGINE=InnoDB DEFAULT CHARSET=utf8mb4 COLLATE=utf8mb4_unicode_ci;

CREATE TABLE `schoolextrascore` (
  `id` char(50) NOT NULL DEFAULT '',
  `name` varchar(100) DEFAULT '',
  `description` text DEFAULT NULL,
  `extrascoregroup` char(50) DEFAULT NULL,
  `scoringtype` bigint(20) NOT NULL DEFAULT 1,
  `usercreate` char(16) NOT NULL DEFAULT '',
  `useredit` char(16) NOT NULL DEFAULT '',
  `updatetimestamp` timestamp NOT NULL DEFAULT current_timestamp() ON UPDATE current_timestamp()
) ENGINE=InnoDB DEFAULT CHARSET=utf8mb4 COLLATE=utf8mb4_unicode_ci;

CREATE TABLE `schoolextrascoregroup` (
  `id` char(50) NOT NULL DEFAULT '',
  `name` varchar(50) DEFAULT '',
  `description` text DEFAULT NULL,
  `usercreate` char(16) NOT NULL DEFAULT '',
  `useredit` char(16) NOT NULL DEFAULT '',
  `updatetimestamp` timestamp NOT NULL DEFAULT current_timestamp() ON UPDATE current_timestamp()
) ENGINE=InnoDB DEFAULT CHARSET=utf8mb4 COLLATE=utf8mb4_unicode_ci;

CREATE TABLE `schoollesson` (
  `id` char(50) NOT NULL DEFAULT '',
  `name` varchar(100) DEFAULT '',
  `description` text DEFAULT NULL,
  `lessongroup` char(50) DEFAULT '',
  `scoringtype` bigint(20) NOT NULL DEFAULT 1,
  `usercreate` char(16) NOT NULL DEFAULT '',
  `useredit` char(16) NOT NULL DEFAULT '',
  `updatetimestamp` timestamp NOT NULL DEFAULT current_timestamp() ON UPDATE current_timestamp()
) ENGINE=InnoDB DEFAULT CHARSET=utf8mb4 COLLATE=utf8mb4_unicode_ci;

CREATE TABLE `schoollessonclass` (
  `id` bigint(20) NOT NULL,
  `schoolsubclass` char(50) NOT NULL DEFAULT '',
  `schoollesson` char(50) NOT NULL DEFAULT '',
  `schoollessonname` varchar(100) NOT NULL DEFAULT '0',
  `schoolteacher` char(50) NOT NULL DEFAULT '',
  `usercreate` char(16) NOT NULL DEFAULT '',
  `useredit` char(16) NOT NULL DEFAULT '',
  `updatetimestamp` timestamp NOT NULL DEFAULT current_timestamp() ON UPDATE current_timestamp()
) ENGINE=InnoDB DEFAULT CHARSET=utf8mb4 COLLATE=utf8mb4_unicode_ci;

CREATE TABLE `schoollessongroup` (
  `id` char(50) NOT NULL DEFAULT '',
  `name` varchar(50) DEFAULT '',
  `description` text DEFAULT NULL,
  `usercreate` char(16) NOT NULL DEFAULT '',
  `useredit` char(16) NOT NULL DEFAULT '',
  `updatetimestamp` timestamp NOT NULL DEFAULT current_timestamp() ON UPDATE current_timestamp()
) ENGINE=InnoDB DEFAULT CHARSET=utf8mb4 COLLATE=utf8mb4_unicode_ci;

CREATE TABLE `schoollessonteacher` (
  `id` bigint(20) NOT NULL,
  `schoollesson` char(50) NOT NULL DEFAULT '',
  `schoollessonname` varchar(100) NOT NULL DEFAULT '',
  `schoolsubclass` char(50) NOT NULL DEFAULT '',
  `schoolteacher` char(50) NOT NULL DEFAULT '',
  `usercreate` char(16) NOT NULL DEFAULT '',
  `useredit` char(16) NOT NULL DEFAULT '',
  `updatetimestamp` timestamp NOT NULL DEFAULT current_timestamp() ON UPDATE current_timestamp()
) ENGINE=InnoDB DEFAULT CHARSET=utf8mb4 COLLATE=utf8mb4_unicode_ci;

CREATE TABLE `schoollevel` (
  `id` char(50) NOT NULL DEFAULT '',
  `name` varchar(100) NOT NULL DEFAULT '',
  `description` text NOT NULL,
  `logo` varchar(255) NOT NULL DEFAULT '[]',
  `headmaster` char(50) NOT NULL DEFAULT '',
  `country` char(3) NOT NULL DEFAULT '',
  `provincename` varchar(50) NOT NULL DEFAULT '',
  `cityname` varchar(50) NOT NULL DEFAULT '',
  `subdistrictname` varchar(50) NOT NULL DEFAULT '',
  `address` varchar(200) NOT NULL DEFAULT '',
  `postcode` varchar(10) NOT NULL DEFAULT '',
  `telephone` varchar(45) NOT NULL DEFAULT '',
  `email` varchar(100) NOT NULL DEFAULT '',
  `website` varchar(100) NOT NULL DEFAULT '',
  `usercreate` char(16) NOT NULL DEFAULT '',
  `useredit` char(16) NOT NULL DEFAULT '',
  `updatetimestamp` timestamp NOT NULL DEFAULT current_timestamp() ON UPDATE current_timestamp()
) ENGINE=InnoDB DEFAULT CHARSET=utf8mb4 COLLATE=utf8mb4_unicode_ci;

CREATE TABLE `schoolpayment` (
  `id` char(50) NOT NULL DEFAULT '',
  `name` varchar(100) DEFAULT '',
  `paymentgroup` char(50) DEFAULT '',
  `receivableacc` char(30) NOT NULL DEFAULT '',
  `unearnedrevenueacc` char(30) NOT NULL DEFAULT '',
  `revenueacc` char(30) NOT NULL DEFAULT '',
  `paymentdiscacc` char(30) NOT NULL DEFAULT '',
  `usercreate` char(16) NOT NULL DEFAULT '',
  `useredit` char(16) NOT NULL DEFAULT '',
  `updatetimestamp` timestamp NOT NULL DEFAULT current_timestamp() ON UPDATE current_timestamp()
) ENGINE=InnoDB DEFAULT CHARSET=utf8mb4 COLLATE=utf8mb4_unicode_ci;

CREATE TABLE `schoolpaymentgroup` (
  `id` char(50) NOT NULL DEFAULT '',
  `name` varchar(100) DEFAULT '',
  `usercreate` char(16) NOT NULL DEFAULT '',
  `useredit` char(16) NOT NULL DEFAULT '',
  `updatetimestamp` timestamp NOT NULL DEFAULT current_timestamp() ON UPDATE current_timestamp()
) ENGINE=InnoDB DEFAULT CHARSET=utf8mb4 COLLATE=utf8mb4_unicode_ci;

CREATE TABLE `schoolpaymentpackage` (
  `id` bigint(20) NOT NULL,
  `schoolsubclass` text NOT NULL,
  `name` varchar(100) NOT NULL DEFAULT '',
  `usercreate` char(16) NOT NULL DEFAULT '',
  `useredit` char(16) NOT NULL DEFAULT '',
  `updatetimestamp` timestamp NOT NULL DEFAULT current_timestamp() ON UPDATE current_timestamp()
) ENGINE=InnoDB DEFAULT CHARSET=utf8mb4 COLLATE=utf8mb4_unicode_ci;

CREATE TABLE `schoolpaymentpackagedetail` (
  `id` bigint(20) NOT NULL,
  `schoolpaymentpackage` bigint(20) NOT NULL DEFAULT 0,
  `schoolpayment` char(50) NOT NULL DEFAULT '',
  `schoolpaymentname` varchar(100) NOT NULL DEFAULT '',
  `required` int(11) NOT NULL DEFAULT 0,
  `total` double NOT NULL DEFAULT 0,
  `instalment` double NOT NULL DEFAULT 0,
  `weight` int(11) NOT NULL DEFAULT 0,
  `usercreate` char(16) NOT NULL DEFAULT '',
  `useredit` char(16) NOT NULL DEFAULT '',
  `updatetimestamp` timestamp NOT NULL DEFAULT current_timestamp() ON UPDATE current_timestamp()
) ENGINE=InnoDB DEFAULT CHARSET=utf8mb4 COLLATE=utf8mb4_unicode_ci;

CREATE TABLE `schoolperiod` (
  `id` char(50) NOT NULL DEFAULT '',
  `name` varchar(100) NOT NULL DEFAULT '',
  `periodbegin` date DEFAULT NULL,
  `periodend` date DEFAULT NULL,
  `usercreate` char(16) NOT NULL DEFAULT '',
  `useredit` char(16) NOT NULL DEFAULT '',
  `updatetimestamp` timestamp NOT NULL DEFAULT current_timestamp() ON UPDATE current_timestamp()
) ENGINE=InnoDB DEFAULT CHARSET=utf8mb4 COLLATE=utf8mb4_unicode_ci;

CREATE TABLE `schoolscoringtype` (
  `id` bigint(20) NOT NULL,
  `name` varchar(50) DEFAULT '',
  `description` text DEFAULT NULL,
  `usercreate` char(16) NOT NULL DEFAULT '',
  `useredit` char(16) NOT NULL DEFAULT '',
  `updatetimestamp` timestamp NOT NULL DEFAULT current_timestamp() ON UPDATE current_timestamp()
) ENGINE=InnoDB DEFAULT CHARSET=utf8mb4 COLLATE=utf8mb4_unicode_ci;

CREATE TABLE `schoolscoringtyperange` (
  `id` bigint(20) NOT NULL,
  `schoolscoringtype` bigint(20) NOT NULL DEFAULT 0,
  `minvalue` float DEFAULT 1,
  `maxvalue` float DEFAULT 1,
  `shortdescription` varchar(100) DEFAULT NULL,
  `description` text DEFAULT NULL,
  `usercreate` char(16) NOT NULL DEFAULT '',
  `useredit` char(16) NOT NULL DEFAULT '',
  `updatetimestamp` timestamp NOT NULL DEFAULT current_timestamp() ON UPDATE current_timestamp()
) ENGINE=InnoDB DEFAULT CHARSET=utf8mb4 COLLATE=utf8mb4_unicode_ci;

CREATE TABLE `schoolstudent` (
  `id` char(50) NOT NULL DEFAULT '',
  `name` varchar(200) NOT NULL DEFAULT '',
  `schoolclass` char(50) NOT NULL DEFAULT '',
  `schoolsubclass` char(50) NOT NULL DEFAULT '',
  `country` char(3) NOT NULL DEFAULT '',
  `provincename` varchar(50) NOT NULL DEFAULT '',
  `cityname` varchar(50) NOT NULL DEFAULT '',
  `subdistrictname` varchar(50) NOT NULL DEFAULT '',
  `address` varchar(200) NOT NULL DEFAULT '',
  `postcode` varchar(10) NOT NULL DEFAULT '',
  `telephone` varchar(45) NOT NULL DEFAULT '',
  `email` varchar(100) NOT NULL DEFAULT '',
  `website` varchar(100) NOT NULL DEFAULT '',
  `photo` varchar(255) DEFAULT '[]',
  `motto` varchar(200) NOT NULL DEFAULT '',
  `religion` int(10) UNSIGNED NOT NULL DEFAULT 0,
  `birthdate` date DEFAULT NULL,
  `sex` tinyint(4) NOT NULL DEFAULT 0 COMMENT '0=MALE, 1=FEMALE',
  `registerdate` datetime DEFAULT NULL,
  `activeuntil` datetime DEFAULT '2099-12-31 00:00:00',
  `status` bigint(20) NOT NULL DEFAULT 1,
  `dorm` bigint(20) NOT NULL,
  `usercreate` char(16) NOT NULL DEFAULT '',
  `useredit` char(16) NOT NULL DEFAULT '',
  `updatetimestamp` timestamp NOT NULL DEFAULT current_timestamp() ON UPDATE current_timestamp()
) ENGINE=InnoDB DEFAULT CHARSET=utf8mb4 COLLATE=utf8mb4_unicode_ci;

CREATE TABLE `schoolstudentdorm` (
  `id` bigint(20) NOT NULL,
  `name` varchar(100) NOT NULL DEFAULT '',
  `dormheadmaster` char(50) NOT NULL DEFAULT '',
  `usercreate` char(16) NOT NULL DEFAULT '',
  `useredit` char(16) NOT NULL DEFAULT '',
  `updatetimestamp` timestamp NOT NULL DEFAULT current_timestamp() ON UPDATE current_timestamp()
) ENGINE=InnoDB DEFAULT CHARSET=utf8mb4 COLLATE=utf8mb4_unicode_ci;

CREATE TABLE `schoolstudentpayment` (
  `id` bigint(20) NOT NULL,
  `division` char(10) NOT NULL DEFAULT '',
  `jtid` varchar(30) NOT NULL DEFAULT '',
  `transdate` datetime DEFAULT NULL,
  `schoolsubclass` char(50) NOT NULL DEFAULT '',
  `schoolstudent` char(50) NOT NULL DEFAULT '',
  `schoolstudentname` varchar(100) NOT NULL DEFAULT '',
  `paymenttype` int(10) UNSIGNED NOT NULL DEFAULT 0,
  `kind` smallint(5) UNSIGNED NOT NULL DEFAULT 0,
  `totalpayment` double NOT NULL DEFAULT 0,
  `accepted` int(10) UNSIGNED NOT NULL DEFAULT 0,
  `memo` varchar(255) NOT NULL DEFAULT '',
  `usercreate` char(16) NOT NULL DEFAULT '',
  `useredit` char(16) NOT NULL DEFAULT '',
  `updatetimestamp` timestamp NOT NULL DEFAULT current_timestamp() ON UPDATE current_timestamp()
) ENGINE=InnoDB DEFAULT CHARSET=utf8mb4 COLLATE=utf8mb4_unicode_ci;

CREATE TABLE `schoolstudentpaymentdetail` (
  `id` bigint(20) NOT NULL,
  `parent` bigint(20) NOT NULL DEFAULT 0,
  `schoolstudent` char(50) NOT NULL DEFAULT '',
  `schoolsubclass` char(50) NOT NULL DEFAULT '',
  `schoolpayment` char(50) NOT NULL DEFAULT '',
  `schoolpaymentname` varchar(100) NOT NULL DEFAULT '',
  `transdate` datetime DEFAULT NULL,
  `payment` double NOT NULL DEFAULT 0,
  `discount` double NOT NULL DEFAULT 0,
  `subtotal` double NOT NULL DEFAULT 0,
  `usercreate` char(16) NOT NULL DEFAULT '',
  `useredit` char(16) NOT NULL DEFAULT '',
  `updatetimestamp` timestamp NOT NULL DEFAULT current_timestamp() ON UPDATE current_timestamp()
) ENGINE=InnoDB DEFAULT CHARSET=utf8mb4 COLLATE=utf8mb4_unicode_ci;

CREATE TABLE `schoolstudentpaymentschedule` (
  `id` bigint(20) NOT NULL,
  `division` char(10) NOT NULL DEFAULT '',
  `jtid` varchar(30) NOT NULL DEFAULT '',
  `transdate` datetime DEFAULT NULL,
  `schoolsubclass` char(50) NOT NULL DEFAULT '',
  `schoolstudent` char(50) NOT NULL DEFAULT '',
  `schoolstudentname` varchar(100) NOT NULL DEFAULT '',
  `schoolpaymentpackage` bigint(20) NOT NULL DEFAULT 0,
  `schoolpaymentpackagename` varchar(100) NOT NULL DEFAULT '',
  `usercreate` char(16) NOT NULL DEFAULT '',
  `useredit` char(16) NOT NULL DEFAULT '',
  `updatetimestamp` timestamp NOT NULL DEFAULT current_timestamp() ON UPDATE current_timestamp()
) ENGINE=InnoDB DEFAULT CHARSET=utf8mb4 COLLATE=utf8mb4_unicode_ci;

CREATE TABLE `schoolstudentscore` (
  `id` bigint(20) NOT NULL,
  `schoolteacher` char(50) NOT NULL DEFAULT '',
  `schoolsubclass` char(50) NOT NULL DEFAULT '',
  `schoolperiod` char(50) NOT NULL DEFAULT '',
  `schoollesson` char(50) NOT NULL DEFAULT '',
  `schoolexam` char(50) NOT NULL DEFAULT '',
  `scoringtype` bigint(20) NOT NULL DEFAULT 0,
  `description` char(255) NOT NULL DEFAULT '',
  `usercreate` char(16) NOT NULL DEFAULT '',
  `useredit` char(16) NOT NULL DEFAULT '',
  `updatetimestamp` timestamp NOT NULL DEFAULT current_timestamp() ON UPDATE current_timestamp()
) ENGINE=InnoDB DEFAULT CHARSET=utf8mb4 COLLATE=utf8mb4_unicode_ci;

CREATE TABLE `schoolstudentscoredetail` (
  `id` bigint(20) NOT NULL,
  `schoolstudentscore` bigint(20) NOT NULL DEFAULT 0,
  `schoolteacher` char(50) NOT NULL DEFAULT '',
  `schoolsubclass` char(50) NOT NULL DEFAULT '',
  `schoolperiod` char(50) NOT NULL DEFAULT '',
  `schoollesson` char(50) NOT NULL DEFAULT '',
  `scoringtype` bigint(20) NOT NULL DEFAULT 0,
  `schoolexam` char(50) NOT NULL DEFAULT '',
  `schoolstudent` char(50) NOT NULL DEFAULT '',
  `schoolstudentname` varchar(200) NOT NULL DEFAULT '',
  `lessonscore` float NOT NULL DEFAULT 0,
  `description` text NOT NULL,
  `shortdescription` varchar(100) NOT NULL DEFAULT '0',
  `usercreate` char(16) NOT NULL DEFAULT '',
  `useredit` char(16) NOT NULL DEFAULT '',
  `updatetimestamp` timestamp NOT NULL DEFAULT current_timestamp() ON UPDATE current_timestamp()
) ENGINE=InnoDB DEFAULT CHARSET=utf8mb4 COLLATE=utf8mb4_unicode_ci;

CREATE TABLE `schoolstudentsextrascore` (
  `id` bigint(20) NOT NULL,
  `schoolteacher` char(50) NOT NULL DEFAULT '',
  `schoolsubclass` char(50) NOT NULL DEFAULT '',
  `schoolperiod` char(50) NOT NULL DEFAULT '',
  `schoolextrascoregroup` char(50) NOT NULL DEFAULT '',
  `schoolextrascore` char(50) NOT NULL DEFAULT '',
  `schoolexam` char(50) NOT NULL DEFAULT '',
  `scoringtype` bigint(20) NOT NULL DEFAULT 0,
  `description` char(255) NOT NULL DEFAULT '',
  `usercreate` char(16) NOT NULL DEFAULT '',
  `useredit` char(16) NOT NULL DEFAULT '',
  `updatetimestamp` timestamp NOT NULL DEFAULT current_timestamp() ON UPDATE current_timestamp()
) ENGINE=InnoDB DEFAULT CHARSET=utf8mb4 COLLATE=utf8mb4_unicode_ci;

CREATE TABLE `schoolstudentsextrascoredetail` (
  `id` bigint(20) NOT NULL,
  `schoolstudentsextrascore` bigint(20) NOT NULL DEFAULT 0,
  `schoolteacher` char(50) NOT NULL DEFAULT '',
  `schoolsubclass` char(50) NOT NULL DEFAULT '',
  `schoolperiod` char(50) NOT NULL DEFAULT '',
  `schoolextrascore` char(50) NOT NULL DEFAULT '',
  `scoringtype` bigint(20) NOT NULL DEFAULT 0,
  `schoolexam` char(50) NOT NULL DEFAULT '',
  `schoolstudent` char(50) NOT NULL DEFAULT '',
  `schoolstudentname` varchar(200) NOT NULL DEFAULT '',
  `lessonscore` float NOT NULL DEFAULT 0,
  `description` text NOT NULL,
  `shortdescription` varchar(100) NOT NULL DEFAULT '0',
  `usercreate` char(16) NOT NULL DEFAULT '',
  `useredit` char(16) NOT NULL DEFAULT '',
  `updatetimestamp` timestamp NOT NULL DEFAULT current_timestamp() ON UPDATE current_timestamp()
) ENGINE=InnoDB DEFAULT CHARSET=utf8mb4 COLLATE=utf8mb4_unicode_ci;

CREATE TABLE `schoolstudentstatus` (
  `id` bigint(20) NOT NULL,
  `name` varchar(100) NOT NULL DEFAULT '',
  `usercreate` char(16) NOT NULL DEFAULT '',
  `useredit` char(16) NOT NULL DEFAULT '',
  `updatetimestamp` timestamp NOT NULL DEFAULT current_timestamp() ON UPDATE current_timestamp()
) ENGINE=InnoDB DEFAULT CHARSET=utf8mb4 COLLATE=utf8mb4_unicode_ci;

CREATE TABLE `schoolstupaymentscheduledetail` (
  `id` bigint(20) NOT NULL,
  `parent` bigint(20) NOT NULL DEFAULT 0,
  `schoolstudent` char(50) NOT NULL DEFAULT '',
  `schoolsubclass` char(50) NOT NULL DEFAULT '',
  `schoolpayment` char(50) NOT NULL DEFAULT '',
  `schoolpaymentname` varchar(100) NOT NULL DEFAULT '',
  `transdate` datetime DEFAULT NULL,
  `required` int(11) NOT NULL DEFAULT 0,
  `total` double NOT NULL DEFAULT 0,
  `instalment` double NOT NULL DEFAULT 0,
  `weight` int(11) NOT NULL DEFAULT 0,
  `usercreate` char(16) NOT NULL DEFAULT '',
  `useredit` char(16) NOT NULL DEFAULT '',
  `updatetimestamp` timestamp NOT NULL DEFAULT current_timestamp() ON UPDATE current_timestamp()
) ENGINE=InnoDB DEFAULT CHARSET=utf8mb4 COLLATE=utf8mb4_unicode_ci;

CREATE TABLE `schoolsubclass` (
  `id` char(50) NOT NULL DEFAULT '',
  `name` varchar(100) NOT NULL DEFAULT '',
  `description` text NOT NULL,
  `schoolclass` char(50) NOT NULL DEFAULT '',
  `homeroomteacher` char(50) NOT NULL DEFAULT '',
  `headofclass` varchar(200) NOT NULL DEFAULT '',
  `logo` varchar(255) NOT NULL DEFAULT '[]',
  `usercreate` char(16) NOT NULL DEFAULT '',
  `useredit` char(16) NOT NULL DEFAULT '',
  `updatetimestamp` timestamp NOT NULL DEFAULT current_timestamp() ON UPDATE current_timestamp()
) ENGINE=InnoDB DEFAULT CHARSET=utf8mb4 COLLATE=utf8mb4_unicode_ci;

CREATE TABLE `schoolteacher` (
  `id` char(50) NOT NULL DEFAULT '',
  `name` varchar(200) NOT NULL DEFAULT '',
  `country` char(3) NOT NULL DEFAULT '',
  `provincename` varchar(50) NOT NULL DEFAULT '',
  `cityname` varchar(50) NOT NULL DEFAULT '',
  `subdistrictname` varchar(50) NOT NULL DEFAULT '',
  `address` varchar(200) NOT NULL DEFAULT '',
  `postcode` varchar(10) NOT NULL DEFAULT '',
  `telephone` varchar(45) NOT NULL DEFAULT '',
  `email` varchar(100) NOT NULL DEFAULT '',
  `website` varchar(100) NOT NULL DEFAULT '',
  `photo` varchar(255) DEFAULT '[]',
  `motto` varchar(200) NOT NULL DEFAULT '',
  `signature` varchar(255) NOT NULL DEFAULT '[]',
  `isactive` int(11) NOT NULL DEFAULT 1,
  `userid` char(16) NOT NULL DEFAULT '',
  `usercreate` char(16) NOT NULL DEFAULT '',
  `useredit` char(16) NOT NULL DEFAULT '',
  `updatetimestamp` timestamp NOT NULL DEFAULT current_timestamp() ON UPDATE current_timestamp(),
  `religion` int(10) UNSIGNED NOT NULL DEFAULT 0,
  `birthdate` date DEFAULT NULL,
  `sex` tinyint(4) NOT NULL DEFAULT 0 COMMENT '0=MALE, 1=FEMALE',
  `registerdate` datetime DEFAULT NULL,
  `activeuntil` datetime DEFAULT '2099-12-31 00:00:00'
) ENGINE=InnoDB DEFAULT CHARSET=utf8mb4 COLLATE=utf8mb4_unicode_ci;

CREATE TABLE `servicedoer` (
  `id` char(30) NOT NULL DEFAULT '',
  `name` varchar(100) NOT NULL DEFAULT '',
  `servicedoergroup` char(30) NOT NULL DEFAULT '',
  `address` varchar(200) NOT NULL DEFAULT '',
  `telephone` varchar(50) NOT NULL DEFAULT '',
  `faximile` varchar(50) NOT NULL DEFAULT '',
  `mobilephone` varchar(50) NOT NULL DEFAULT '',
  `category` tinyint(4) NOT NULL DEFAULT 0 COMMENT '0=PERSONAL, 1=COMPANY',
  `religion` int(10) UNSIGNED NOT NULL DEFAULT 0,
  `birthdate` datetime DEFAULT NULL,
  `sex` tinyint(4) NOT NULL DEFAULT 0 COMMENT '0=MALE, 1=FEMALE',
  `email` varchar(100) NOT NULL DEFAULT '',
  `country` char(3) NOT NULL DEFAULT '',
  `registerdate` date DEFAULT NULL,
  `activeuntil` date NOT NULL DEFAULT '2999-12-31',
  `isactive` smallint(6) NOT NULL DEFAULT 1,
  `commisionrules` text DEFAULT NULL,
  `payablecommacc` char(30) NOT NULL DEFAULT '',
  `expensecommacc` char(30) NOT NULL DEFAULT '',
  `contactperson` varchar(100) NOT NULL DEFAULT '',
  `website` varchar(100) NOT NULL DEFAULT '',
  `usercreate` char(16) NOT NULL DEFAULT '',
  `useredit` char(16) NOT NULL DEFAULT '',
  `updatetimestamp` timestamp NOT NULL DEFAULT current_timestamp() ON UPDATE current_timestamp(),
  `image` varchar(255) DEFAULT '[]'
) ENGINE=InnoDB DEFAULT CHARSET=utf8mb4 COLLATE=utf8mb4_unicode_ci;

CREATE TABLE `servicedoercommperiod` (
  `id` bigint(20) UNSIGNED NOT NULL DEFAULT 0,
  `fromdate` date DEFAULT NULL,
  `fromtime` time DEFAULT NULL,
  `todate` date DEFAULT NULL,
  `totime` time DEFAULT NULL,
  `minsalesretur` tinyint(1) NOT NULL DEFAULT 1,
  `accumrules` tinyint(1) NOT NULL DEFAULT 0,
  `minproductdisc` tinyint(1) NOT NULL DEFAULT 1,
  `posted` tinyint(1) NOT NULL DEFAULT 0,
  `currtrans` char(3) NOT NULL DEFAULT '',
  `division` varchar(10) NOT NULL DEFAULT '',
  `formula` text DEFAULT NULL,
  `refid` char(30) NOT NULL DEFAULT '',
  `postdate` date DEFAULT NULL,
  `posttime` time DEFAULT NULL,
  `salaryid` int(10) UNSIGNED NOT NULL DEFAULT 0,
  `groups` varchar(100) NOT NULL DEFAULT '',
  `updatetimestamp` timestamp NOT NULL DEFAULT current_timestamp()
) ENGINE=InnoDB DEFAULT CHARSET=utf8mb4 COLLATE=utf8mb4_unicode_ci;

CREATE TABLE `servicedoercommrules` (
  `id` int(10) UNSIGNED NOT NULL DEFAULT 0,
  `description` varchar(100) NOT NULL DEFAULT '',
  `displayname` varchar(20) NOT NULL DEFAULT '',
  `category` int(11) NOT NULL DEFAULT 0,
  `formula` text DEFAULT NULL,
  `usercreate` char(16) NOT NULL DEFAULT '',
  `useredit` char(16) NOT NULL DEFAULT '',
  `updatetimestamp` timestamp NOT NULL DEFAULT current_timestamp() ON UPDATE current_timestamp()
) ENGINE=InnoDB DEFAULT CHARSET=utf8mb4 COLLATE=utf8mb4_unicode_ci;

CREATE TABLE `servicedoercommvar` (
  `varname` char(10) NOT NULL DEFAULT '',
  `varvalue` double NOT NULL DEFAULT 0,
  `description` varchar(50) NOT NULL DEFAULT ''
) ENGINE=InnoDB DEFAULT CHARSET=utf8mb4 COLLATE=utf8mb4_unicode_ci;

CREATE TABLE `servicedoercommvarrecords` (
  `transid` bigint(20) UNSIGNED NOT NULL,
  `periodid` bigint(20) UNSIGNED NOT NULL,
  `varname` char(10) NOT NULL DEFAULT '',
  `varvalue` double NOT NULL DEFAULT 0,
  `description` varchar(50) NOT NULL DEFAULT ''
) ENGINE=InnoDB DEFAULT CHARSET=utf8mb4 COLLATE=utf8mb4_unicode_ci;

CREATE TABLE `servicedoerdetail` (
  `groupid` char(30) NOT NULL DEFAULT '',
  `servicedoerid` char(30) NOT NULL DEFAULT '',
  `percent` double NOT NULL DEFAULT 0,
  `memo` varchar(100) NOT NULL DEFAULT '',
  `usercreate` char(16) NOT NULL DEFAULT '',
  `useredit` char(16) NOT NULL DEFAULT '',
  `updatetimestamp` timestamp NOT NULL DEFAULT current_timestamp() ON UPDATE current_timestamp()
) ENGINE=InnoDB DEFAULT CHARSET=utf8mb4 COLLATE=utf8mb4_unicode_ci;

CREATE TABLE `servicedoergroup` (
  `id` char(30) NOT NULL DEFAULT '',
  `description` varchar(100) NOT NULL DEFAULT '',
  `commisionrules` text DEFAULT NULL,
  `payablecommacc` char(30) NOT NULL DEFAULT '',
  `expensecommacc` char(30) NOT NULL DEFAULT '',
  `usercreate` char(16) NOT NULL DEFAULT '',
  `useredit` char(16) NOT NULL DEFAULT '',
  `updatetimestamp` timestamp NOT NULL DEFAULT current_timestamp() ON UPDATE current_timestamp()
) ENGINE=InnoDB DEFAULT CHARSET=utf8mb4 COLLATE=utf8mb4_unicode_ci;

CREATE TABLE `servicedoerrecorddetail` (
  `transid` bigint(20) UNSIGNED NOT NULL,
  `periodid` bigint(20) UNSIGNED NOT NULL,
  `servicedoerid` char(30) NOT NULL DEFAULT '',
  `productid` char(30) NOT NULL DEFAULT '',
  `salestargetqty` double NOT NULL DEFAULT 0,
  `salestargetvalue` double NOT NULL DEFAULT 0,
  `salesrealqty` double NOT NULL DEFAULT 0,
  `salesrealvalue` double NOT NULL DEFAULT 0,
  `percentqty` double NOT NULL DEFAULT 0,
  `percentvalue` double NOT NULL DEFAULT 0,
  `profit` double NOT NULL DEFAULT 0,
  `commission` double NOT NULL DEFAULT 0,
  `usercreate` char(16) NOT NULL DEFAULT '',
  `useredit` char(16) NOT NULL DEFAULT '',
  `updatetimestamp` timestamp NOT NULL DEFAULT current_timestamp()
) ENGINE=InnoDB DEFAULT CHARSET=utf8mb4 COLLATE=utf8mb4_unicode_ci;

CREATE TABLE `servicedoerrecords` (
  `id` bigint(20) UNSIGNED NOT NULL,
  `periodid` bigint(20) UNSIGNED NOT NULL,
  `servicedoerid` char(30) NOT NULL DEFAULT '',
  `salestarget` double NOT NULL DEFAULT 0,
  `salesreal` double NOT NULL DEFAULT 0,
  `percent` double NOT NULL DEFAULT 0,
  `profit` double NOT NULL DEFAULT 0,
  `commission` double NOT NULL DEFAULT 0,
  `productcommission` double NOT NULL DEFAULT 0,
  `totalcommission` double NOT NULL DEFAULT 0,
  `commissionpaid` double NOT NULL DEFAULT 0,
  `usercreate` char(16) NOT NULL DEFAULT '',
  `useredit` char(16) NOT NULL DEFAULT '',
  `updatetimestamp` timestamp NOT NULL DEFAULT current_timestamp()
) ENGINE=InnoDB DEFAULT CHARSET=utf8mb4 COLLATE=utf8mb4_unicode_ci;

CREATE TABLE `shipments` (
  `id` int(10) UNSIGNED NOT NULL DEFAULT 1,
  `name` varchar(50) NOT NULL DEFAULT '',
  `description` varchar(100) NOT NULL DEFAULT '',
  `usercreate` char(16) NOT NULL DEFAULT '',
  `useredit` char(16) NOT NULL DEFAULT '',
  `updatetimestamp` timestamp NOT NULL DEFAULT current_timestamp() ON UPDATE current_timestamp()
) ENGINE=InnoDB DEFAULT CHARSET=utf8mb4 COLLATE=utf8mb4_unicode_ci;

CREATE TABLE `slidedata` (
  `id` bigint(20) NOT NULL,
  `slideid` int(11) NOT NULL DEFAULT 0,
  `type` int(11) NOT NULL DEFAULT 1,
  `image` text DEFAULT NULL,
  `video` varchar(100) NOT NULL DEFAULT '',
  `backgroundclass` varchar(50) NOT NULL DEFAULT '',
  `animation` text DEFAULT NULL,
  `weight` int(11) NOT NULL DEFAULT 1
) ENGINE=InnoDB DEFAULT CHARSET=utf8mb4 COLLATE=utf8mb4_unicode_ci;

INSERT INTO `slidedata` (`id`, `slideid`, `type`, `image`, `video`, `backgroundclass`, `animation`, `weight`) VALUES
(1, 1, 1, '[{\"img\":\"\\/api\\/assets\\/slidedata\\/17493440710349.webp\",\"caption\":\"\",\"subtitle\":\"\"}]', '', '', '{\"effectin\":\"random\",\"effectout\":\"random\",\"effectexist\":\"rubberBand\",\"infinite\":false}', 1),
(2, 1, 1, '[{\"img\":\"\\/api\\/assets\\/slidedata\\/17493441451288.webp\",\"caption\":\"\",\"subtitle\":\"\"}]', '', '', '{\"effectin\":\"random\",\"effectout\":\"random\",\"effectexist\":\"rubberBand\",\"infinite\":false}', 1);

CREATE TABLE `slideelements` (
  `id` bigint(20) NOT NULL,
  `type` int(11) NOT NULL DEFAULT 1,
  `html` text DEFAULT NULL,
  `image` text DEFAULT NULL,
  `animation` text DEFAULT NULL,
  `position` int(11) NOT NULL DEFAULT 1,
  `slidedataid` bigint(20) NOT NULL DEFAULT 1
) ENGINE=InnoDB DEFAULT CHARSET=utf8mb4 COLLATE=utf8mb4_unicode_ci;

INSERT INTO `slideelements` (`id`, `type`, `html`, `image`, `animation`, `position`, `slidedataid`) VALUES
(1, 1, '<h2><span class=\"__se__t-shadow\" style=\"color: rgb(250, 224, 212)\">Promo Akhir Tahun</span></h2>', '[]', '{\"effectin\":\"random\",\"effectout\":\"random\",\"effectexist\":\"shakeX\",\"infinite\":true}', 1, 2);

CREATE TABLE `supplier` (
  `id` char(30) NOT NULL DEFAULT '',
  `name` varchar(100) NOT NULL DEFAULT '',
  `suppliergroup` char(30) NOT NULL DEFAULT '',
  `address` varchar(200) NOT NULL DEFAULT '',
  `telephone` varchar(50) NOT NULL DEFAULT '',
  `faximile` varchar(50) NOT NULL DEFAULT '',
  `mobilephone` varchar(50) NOT NULL DEFAULT '',
  `category` tinyint(4) NOT NULL DEFAULT 0 COMMENT '0=PERSONAL, 1=COMPANY',
  `contactperson` varchar(100) NOT NULL DEFAULT '',
  `religion` int(10) UNSIGNED NOT NULL DEFAULT 1,
  `birthdate` date DEFAULT NULL,
  `sex` tinyint(4) NOT NULL DEFAULT 0 COMMENT '0=MALE, 1=FEMALE',
  `email` varchar(100) NOT NULL DEFAULT '',
  `website` varchar(100) NOT NULL DEFAULT '',
  `country` char(3) NOT NULL DEFAULT '',
  `creditlimit` double NOT NULL DEFAULT 0,
  `registerdate` date DEFAULT NULL,
  `activeuntil` date NOT NULL DEFAULT '2099-12-31',
  `taxid` varchar(50) NOT NULL DEFAULT '',
  `isactive` smallint(6) NOT NULL DEFAULT 1,
  `payableacc` char(30) NOT NULL DEFAULT '',
  `accruedpayableacc` char(30) NOT NULL DEFAULT '',
  `rewardacc` char(30) NOT NULL,
  `purchasediscacc` char(30) NOT NULL DEFAULT '',
  `gainlosspayableacc` char(30) NOT NULL DEFAULT '',
  `termofpayment` varchar(30) NOT NULL DEFAULT '' COMMENT '2/10, n/30\nCOD (Cash On Delivery)',
  `usercreate` char(16) NOT NULL DEFAULT '',
  `useredit` char(16) NOT NULL DEFAULT '',
  `updatetimestamp` timestamp NOT NULL DEFAULT current_timestamp() ON UPDATE current_timestamp(),
  `image` varchar(255) DEFAULT '[]'
) ENGINE=InnoDB DEFAULT CHARSET=utf8mb4 COLLATE=utf8mb4_unicode_ci;

CREATE TABLE `supplierbalance` (
  `transid` bigint(20) UNSIGNED NOT NULL,
  `purchaseid` char(30) NOT NULL DEFAULT '',
  `purchaseidref` char(30) NOT NULL DEFAULT '',
  `division` char(10) NOT NULL DEFAULT '',
  `supplierid` char(30) NOT NULL DEFAULT '',
  `transdate` datetime DEFAULT NULL,
  `debit` double NOT NULL DEFAULT 0,
  `credit` double NOT NULL DEFAULT 0,
  `currtrans` char(3) NOT NULL DEFAULT '',
  `ratedefault` double NOT NULL DEFAULT 0,
  `rateused` double NOT NULL DEFAULT 0,
  `usercreate` char(16) NOT NULL DEFAULT '',
  `useredit` char(16) NOT NULL DEFAULT '',
  `updatetimestamp` timestamp NOT NULL DEFAULT current_timestamp() ON UPDATE current_timestamp()
) ENGINE=InnoDB DEFAULT CHARSET=utf8mb4 COLLATE=utf8mb4_unicode_ci;

CREATE TABLE `supplierdp` (
  `transid` char(30) NOT NULL,
  `division` char(10) NOT NULL DEFAULT '',
  `supplierid` char(30) DEFAULT NULL,
  `suppliername` varchar(100) NOT NULL DEFAULT '',
  `supplieraddress` varchar(200) NOT NULL DEFAULT '',
  `transdate` datetime DEFAULT NULL,
  `paymenttype` int(10) UNSIGNED DEFAULT NULL,
  `downpaymenttype` int(10) UNSIGNED NOT NULL,
  `kind` int(10) UNSIGNED NOT NULL DEFAULT 0,
  `debit` double NOT NULL DEFAULT 0,
  `credit` double NOT NULL DEFAULT 0,
  `memo` text DEFAULT NULL,
  `printed` smallint(6) NOT NULL DEFAULT 0,
  `currtrans` char(3) NOT NULL DEFAULT '',
  `ratedefault` double NOT NULL DEFAULT 0,
  `rateused` double NOT NULL DEFAULT 0,
  `usercreate` char(16) NOT NULL DEFAULT '',
  `useredit` char(16) NOT NULL DEFAULT '',
  `updatetimestamp` timestamp NOT NULL DEFAULT current_timestamp() ON UPDATE current_timestamp()
) ENGINE=InnoDB DEFAULT CHARSET=utf8mb4 COLLATE=utf8mb4_unicode_ci;

CREATE TABLE `suppliergiro` (
  `id` bigint(20) UNSIGNED NOT NULL,
  `transid` char(30) NOT NULL DEFAULT '',
  `transidref` char(30) NOT NULL DEFAULT '',
  `transdate` datetime DEFAULT NULL,
  `supplierid` char(30) NOT NULL DEFAULT '',
  `suppliername` varchar(100) NOT NULL DEFAULT '',
  `supplieraddress` varchar(200) NOT NULL DEFAULT '',
  `accepted` smallint(6) NOT NULL DEFAULT 0,
  `duedate` datetime DEFAULT NULL,
  `accepteddate` datetime DEFAULT NULL,
  `giroin` double NOT NULL DEFAULT 0,
  `giroout` double NOT NULL DEFAULT 0,
  `paymenttype` int(10) UNSIGNED NOT NULL,
  `paymentref` varchar(100) NOT NULL DEFAULT '',
  `currtrans` char(3) NOT NULL DEFAULT '',
  `ratedefault` double NOT NULL DEFAULT 0,
  `rateused` double NOT NULL DEFAULT 0,
  `division` char(10) NOT NULL DEFAULT '',
  `kind` smallint(6) NOT NULL DEFAULT 0,
  `jtid` char(30) NOT NULL DEFAULT '',
  `usercreate` char(16) NOT NULL DEFAULT '',
  `useredit` char(16) NOT NULL DEFAULT '',
  `updatetimestamp` timestamp NOT NULL DEFAULT current_timestamp() ON UPDATE current_timestamp()
) ENGINE=InnoDB DEFAULT CHARSET=utf8mb4 COLLATE=utf8mb4_unicode_ci;

CREATE TABLE `suppliergroup` (
  `id` char(30) NOT NULL DEFAULT '',
  `description` varchar(100) NOT NULL DEFAULT '',
  `payableacc` char(30) NOT NULL DEFAULT '',
  `accruedpayableacc` char(30) NOT NULL DEFAULT '',
  `rewardacc` char(30) NOT NULL DEFAULT '',
  `purchasediscacc` char(30) NOT NULL DEFAULT '',
  `gainlosspayableacc` char(30) NOT NULL DEFAULT '',
  `usercreate` char(16) NOT NULL DEFAULT '',
  `useredit` char(16) NOT NULL DEFAULT '',
  `updatetimestamp` timestamp NOT NULL DEFAULT current_timestamp() ON UPDATE current_timestamp()
) ENGINE=InnoDB DEFAULT CHARSET=utf8mb4 COLLATE=utf8mb4_unicode_ci;

CREATE TABLE `tableroles` (
  `id` bigint(20) NOT NULL,
  `tablename` varchar(50) NOT NULL DEFAULT '',
  `roles` varchar(50) NOT NULL DEFAULT '0',
  `allowedit` int(11) NOT NULL DEFAULT 1,
  `allowdelete` int(11) NOT NULL DEFAULT 1,
  `onlyselfdata` int(11) NOT NULL DEFAULT 0
) ENGINE=InnoDB DEFAULT CHARSET=utf8mb4 COLLATE=utf8mb4_unicode_ci;

CREATE TABLE `taxes` (
  `id` tinyint(4) NOT NULL DEFAULT 0,
  `name` varchar(20) NOT NULL DEFAULT '',
  `description` varchar(50) NOT NULL DEFAULT '',
  `percent` double NOT NULL DEFAULT 0,
  `inclusive` smallint(6) NOT NULL DEFAULT 0,
  `tax_code` varchar(10) NOT NULL DEFAULT '01',
  `taxoutacc` char(30) DEFAULT NULL,
  `taxinacc` char(30) DEFAULT NULL,
  `usercreate` char(16) NOT NULL DEFAULT '',
  `useredit` char(16) NOT NULL DEFAULT '',
  `updatetimestamp` timestamp NOT NULL DEFAULT current_timestamp() ON UPDATE current_timestamp()
) ENGINE=InnoDB DEFAULT CHARSET=utf8mb4 COLLATE=utf8mb4_unicode_ci;

CREATE TABLE `themecolors` (
  `id` bigint(20) UNSIGNED NOT NULL,
  `primarycolor` varchar(7) NOT NULL DEFAULT '#027BE3',
  `secondarycolor` varchar(7) NOT NULL DEFAULT '#26A69A',
  `accentcolor` varchar(7) NOT NULL DEFAULT '#9C27B0',
  `darkcolor` varchar(7) NOT NULL DEFAULT '#1d1d1d',
  `positivecolor` varchar(7) NOT NULL DEFAULT '#21BA45',
  `negativecolor` varchar(7) NOT NULL DEFAULT '#C10015',
  `infocolor` varchar(7) NOT NULL DEFAULT '#31CCEC',
  `warningcolor` varchar(7) NOT NULL DEFAULT '#F2C037',
  `themename` varchar(50) NOT NULL DEFAULT ''
) ENGINE=InnoDB DEFAULT CHARSET=utf8mb4 COLLATE=utf8mb4_unicode_ci;

INSERT INTO `themecolors` (`id`, `primarycolor`, `secondarycolor`, `accentcolor`, `darkcolor`, `positivecolor`, `negativecolor`, `infocolor`, `warningcolor`, `themename`) VALUES
(1, '#027BE3', '#26A69A', '#9C27B0', '#1e2b45', '#21BA45', '#C10015', '#31CCEC', '#F2C037', 'Default'),
(2, '#1ab863', '#0f9689', '#94fa05', '#25382c', '#12dbd5', '#9e0b1c', '#1ba7f7', '#f5bb1b', 'Green'),
(3, '#a8a41b', '#c26d1d', '#a9f037', '#544b23', '#21BA45', '#C10015', '#7adcf0', '#d4d63a', 'Brown'),
(4, '#770e87', '#76347d', '#c642eb', '#2b1c2b', '#d39adb', '#f21839', '#f252b0', '#6f2073', 'Purple'),
(5, '#990c24', '#b56219', '#f51414', '#140404', '#8bb518', '#C10015', '#853a47', '#ebb944', 'Dark red '),
(6, '#f7b705', '#a8914f', '#e0c475', '#694e03', '#d1a326', '#f55920', '#9c9e24', '#F2C037', 'Yellow'),
(7, '#6f7478', '#9ba8a7', '#a78cab', '#2b2a2a', '#4e9c60', '#e3293f', '#7f9599', '#c7b689', 'Black'),
(8, '#4d918f', '#1f998d', '#500ead', '#1e2b45', '#21cca1', '#b5071c', '#50bcfa', '#F2C037', 'Tosca'),
(9, '#1ab863', '#a0e381', '#94fa05', '#25382c', '#e0d42b', '#826d70', '#7dff03', '#f5bb1b', 'Green Custom');

CREATE TABLE `trackemployee` (
  `id` bigint(20) UNSIGNED NOT NULL,
  `employeeid` char(30) NOT NULL DEFAULT '',
  `attendanceid` bigint(20) UNSIGNED NOT NULL DEFAULT 0,
  `name` varchar(100) NOT NULL DEFAULT '',
  `checkin` datetime DEFAULT NULL,
  `checkout` datetime DEFAULT NULL,
  `notes` varchar(255) DEFAULT '',
  `workinghour` float DEFAULT NULL,
  `imagecheckin` varchar(255) DEFAULT '[]',
  `imagecheckout` varchar(255) DEFAULT '[]',
  `latitudecheckin` float DEFAULT NULL,
  `longitudecheckin` float DEFAULT NULL,
  `latitudecheckout` float DEFAULT NULL,
  `longitudecheckout` float DEFAULT NULL,
  `usercreate` char(16) NOT NULL DEFAULT '',
  `useredit` char(16) NOT NULL DEFAULT '',
  `updatetimestamp` timestamp NOT NULL DEFAULT current_timestamp() ON UPDATE current_timestamp()
) ENGINE=InnoDB DEFAULT CHARSET=utf8mb4 COLLATE=utf8mb4_unicode_ci;

CREATE TABLE `trexpenses` (
  `id` bigint(20) UNSIGNED NOT NULL,
  `accountid` char(30) NOT NULL DEFAULT '',
  `fromdate` date DEFAULT NULL,
  `todate` date DEFAULT NULL,
  `exptarget` double NOT NULL DEFAULT 0,
  `expreal` double NOT NULL DEFAULT 0,
  `percent` double NOT NULL DEFAULT 0,
  `usercreate` char(16) NOT NULL DEFAULT '',
  `useredit` char(16) NOT NULL DEFAULT '',
  `updatetimestamp` timestamp NOT NULL DEFAULT current_timestamp() ON UPDATE current_timestamp()
) ENGINE=InnoDB DEFAULT CHARSET=utf8mb4 COLLATE=utf8mb4_unicode_ci;

CREATE TABLE `trproduct` (
  `id` bigint(20) UNSIGNED NOT NULL,
  `productid` char(30) NOT NULL DEFAULT '',
  `fromdate` date DEFAULT NULL,
  `todate` date DEFAULT NULL,
  `salestarget` double NOT NULL DEFAULT 0,
  `salesreal` double NOT NULL DEFAULT 0,
  `percent` double NOT NULL DEFAULT 0,
  `usercreate` char(16) NOT NULL DEFAULT '',
  `useredit` char(16) NOT NULL DEFAULT '',
  `updatetimestamp` timestamp NOT NULL DEFAULT current_timestamp() ON UPDATE current_timestamp()
) ENGINE=InnoDB DEFAULT CHARSET=utf8mb4 COLLATE=utf8mb4_unicode_ci;

CREATE TABLE `trrevenues` (
  `id` bigint(20) UNSIGNED NOT NULL,
  `accountid` char(30) NOT NULL DEFAULT '',
  `fromdate` date DEFAULT NULL,
  `todate` date DEFAULT NULL,
  `revtarget` double NOT NULL DEFAULT 0,
  `revreal` double NOT NULL DEFAULT 0,
  `percent` double NOT NULL DEFAULT 0,
  `usercreate` char(16) NOT NULL DEFAULT '',
  `useredit` char(16) NOT NULL DEFAULT '',
  `updatetimestamp` timestamp NOT NULL DEFAULT current_timestamp() ON UPDATE current_timestamp()
) ENGINE=InnoDB DEFAULT CHARSET=utf8mb4 COLLATE=utf8mb4_unicode_ci;

CREATE TABLE `units` (
  `id` bigint(20) UNSIGNED NOT NULL,
  `name` char(10) NOT NULL DEFAULT '',
  `productid` char(30) NOT NULL DEFAULT '',
  `quantity` double NOT NULL DEFAULT 1,
  `costprice` double NOT NULL DEFAULT 0,
  `purchasedisc` double NOT NULL DEFAULT 0,
  `purchasetax` double NOT NULL DEFAULT 0,
  `netpurchase` double NOT NULL DEFAULT 0,
  `salesprice1` double NOT NULL DEFAULT 0,
  `salesprice2` double NOT NULL DEFAULT 0,
  `salesprice3` double NOT NULL DEFAULT 0,
  `salesprice4` double NOT NULL DEFAULT 0,
  `salesprice5` double NOT NULL DEFAULT 0,
  `salesprice6` double NOT NULL DEFAULT 0,
  `salesprice7` double NOT NULL DEFAULT 0,
  `salesdiscqty1` double NOT NULL DEFAULT 0,
  `salesdiscprice1` double NOT NULL DEFAULT 0,
  `salesdiscqty2` double NOT NULL DEFAULT 0,
  `salesdiscprice2` double NOT NULL DEFAULT 0,
  `salesdiscqty3` double NOT NULL DEFAULT 0,
  `salesdiscprice3` double NOT NULL DEFAULT 0,
  `salesdisc` double NOT NULL DEFAULT 0,
  `salesdiscformula` varchar(50) NOT NULL DEFAULT '',
  `divisionid` varchar(512) NOT NULL DEFAULT '[]',
  `departementid` varchar(512) NOT NULL DEFAULT '[]',
  `isactive` smallint(6) NOT NULL DEFAULT 1,
  `usercreate` char(16) NOT NULL DEFAULT '',
  `useredit` char(16) NOT NULL DEFAULT '',
  `updatetimestamp` timestamp NOT NULL DEFAULT current_timestamp() ON UPDATE current_timestamp()
) ENGINE=InnoDB DEFAULT CHARSET=utf8mb4 COLLATE=utf8mb4_unicode_ci;

CREATE TABLE `users` (
  `id` char(16) NOT NULL DEFAULT '',
  `userpassword` char(100) NOT NULL DEFAULT '',
  `name` varchar(100) NOT NULL DEFAULT '',
  `description` varchar(200) NOT NULL DEFAULT '',
  `usercreate` char(16) NOT NULL DEFAULT '',
  `isactive` smallint(6) NOT NULL DEFAULT 1,
  `useredit` char(16) NOT NULL DEFAULT '',
  `updatetimestamp` timestamp NOT NULL DEFAULT current_timestamp() ON UPDATE current_timestamp(),
  `photo` varchar(255) DEFAULT '',
  `lastlogin` datetime DEFAULT NULL,
  `roles` varchar(50) DEFAULT NULL
) ENGINE=InnoDB DEFAULT CHARSET=utf8mb4 COLLATE=utf8mb4_unicode_ci;

CREATE TABLE `vehicle` (
  `id` bigint(20) UNSIGNED NOT NULL,
  `platenumber` varchar(20) NOT NULL DEFAULT '',
  `name` varchar(100) NOT NULL DEFAULT '',
  `modelid` bigint(20) UNSIGNED NOT NULL,
  `division` char(10) DEFAULT NULL,
  `departement` char(10) DEFAULT NULL,
  `defaultdriverid` char(30) DEFAULT NULL,
  `fueltypeid` char(10) NOT NULL DEFAULT '',
  `ownershiptype` tinyint(4) NOT NULL DEFAULT 0 COMMENT '0=owned, 1=leased, 2=rented, 3=employee_owned',
  `vehiclestatus` tinyint(4) NOT NULL DEFAULT 0 COMMENT '0=active, 1=in_service, 2=inactive, 3=disposed',
  `odometerunit` tinyint(4) NOT NULL DEFAULT 0 COMMENT '0=km, 1=mi',
  `currentodometer` double NOT NULL DEFAULT 0,
  `hourused` int(11) NOT NULL DEFAULT 0,
  `yearmanufacture` int(11) NOT NULL DEFAULT 0,
  `yearmodel` int(11) NOT NULL DEFAULT 0,
  `vin` varchar(50) NOT NULL DEFAULT '',
  `chassisnumber` varchar(50) NOT NULL DEFAULT '',
  `enginenumber` varchar(50) NOT NULL DEFAULT '',
  `licensenumber` varchar(50) NOT NULL DEFAULT '',
  `color` varchar(30) NOT NULL DEFAULT '',
  `transmissiontype` tinyint(4) NOT NULL DEFAULT 0 COMMENT '0=manual, 1=automatic, 2=cvt, 9=other',
  `acquisitiondate` date DEFAULT NULL,
  `disposaldate` date DEFAULT NULL,
  `purchasevalue` double NOT NULL DEFAULT 0,
  `insurancenumber` varchar(50) NOT NULL DEFAULT '',
  `insuranceexpirydate` date DEFAULT NULL,
  `registrationexpirydate` date DEFAULT NULL,
  `inspectionexpirydate` date DEFAULT NULL,
  `notes` text DEFAULT NULL,
  `usercreate` char(16) NOT NULL DEFAULT '',
  `useredit` char(16) NOT NULL DEFAULT '',
  `updatetimestamp` timestamp NOT NULL DEFAULT current_timestamp() ON UPDATE current_timestamp()
) ENGINE=InnoDB DEFAULT CHARSET=utf8mb4 COLLATE=utf8mb4_unicode_ci;

CREATE TABLE `vehiclebrand` (
  `id` bigint(20) UNSIGNED NOT NULL,
  `name` varchar(100) NOT NULL DEFAULT '',
  `notes` varchar(255) NOT NULL DEFAULT '',
  `isactive` smallint(6) NOT NULL DEFAULT 1,
  `usercreate` char(16) NOT NULL DEFAULT '',
  `useredit` char(16) NOT NULL DEFAULT '',
  `updatetimestamp` timestamp NOT NULL DEFAULT current_timestamp() ON UPDATE current_timestamp()
) ENGINE=InnoDB DEFAULT CHARSET=utf8mb4 COLLATE=utf8mb4_unicode_ci;

INSERT INTO `vehiclebrand` (`id`, `name`, `notes`, `isactive`, `usercreate`, `useredit`, `updatetimestamp`) VALUES
(1, 'Toyota', '', 1, 'admin', '', '2026-04-02 00:04:57'),
(2, 'Honda', '', 1, 'admin', '', '2026-04-02 00:04:57'),
(3, 'Suzuki', '', 1, 'admin', '', '2026-04-02 00:04:57'),
(4, 'Mitsubishi', '', 1, 'admin', '', '2026-04-02 00:04:57'),
(5, 'Nissan', '', 1, 'admin', '', '2026-04-02 00:04:57'),
(6, 'Isuzu', '', 1, 'admin', '', '2026-04-02 00:04:57'),
(7, 'Ford', '', 1, 'admin', '', '2026-04-02 00:04:57'),
(8, 'Mercedes-Benz', '', 1, 'admin', '', '2026-04-02 00:04:57'),
(9, 'HINO', '', 1, 'admin', '', '2026-04-02 00:04:57'),
(10, 'BYD', '', 1, 'admin', '', '2026-04-02 00:04:57'),
(11, 'Tesla', '', 1, 'admin', '', '2026-04-02 00:04:57'),
(12, 'Yamaha', '', 1, 'admin', '', '2026-04-02 00:04:57'),
(13, 'Kawasaki', '', 1, 'admin', '', '2026-04-02 00:04:57'),
(14, 'TVS', '', 1, 'admin', '', '2026-04-02 00:04:57'),
(15, 'Bajaj', '', 1, 'admin', '', '2026-04-02 00:04:57'),
(16, 'Caterpillar', '', 1, 'admin', '', '2026-04-02 00:04:57'),
(17, 'Komatsu', '', 1, 'admin', '', '2026-04-02 00:04:57'),
(18, 'Hitachi', '', 1, 'admin', '', '2026-04-02 00:04:57'),
(19, 'Volvo', '', 1, 'admin', '', '2026-04-02 00:04:57'),
(20, 'Kobelco', '', 1, 'admin', '', '2026-04-02 00:04:57'),
(21, 'John Deere', '', 1, 'admin', '', '2026-04-02 00:04:57'),
(22, 'XCMG', '', 1, 'admin', '', '2026-04-02 00:04:57'),
(23, 'SANY', '', 1, 'admin', '', '2026-04-02 00:04:57'),
(24, 'Hyundai', '', 1, 'admin', '', '2026-04-02 00:04:57'),
(25, 'Samsung', '', 1, 'admin', '', '2026-04-02 00:04:57'),
(26, 'Wuling', '', 1, 'admin', '', '2026-04-02 00:04:57'),
(27, 'Daewoo', '', 1, 'admin', '', '2026-04-02 00:04:57'),
(28, 'Rolls-Royce', '', 1, 'admin', '', '2026-04-02 00:04:57');

CREATE TABLE `vehicledocument` (
  `id` bigint(20) UNSIGNED NOT NULL,
  `vehicleid` bigint(20) UNSIGNED NOT NULL,
  `documenttype` tinyint(4) NOT NULL DEFAULT 0 COMMENT '0=registration, 1=insurance, 2=inspection, 3=lease, 4=permit, 9=other',
  `documentnumber` varchar(50) NOT NULL DEFAULT '',
  `issueddate` date DEFAULT NULL,
  `expirydate` date DEFAULT NULL,
  `reminderdate` date DEFAULT NULL,
  `amount` double NOT NULL DEFAULT 0,
  `notes` varchar(255) NOT NULL DEFAULT '',
  `images` text NOT NULL,
  `usercreate` char(16) NOT NULL DEFAULT '',
  `useredit` char(16) NOT NULL DEFAULT '',
  `updatetimestamp` timestamp NOT NULL DEFAULT current_timestamp() ON UPDATE current_timestamp()
) ENGINE=InnoDB DEFAULT CHARSET=utf8mb4 COLLATE=utf8mb4_unicode_ci;

CREATE TABLE `vehiclefuellog` (
  `id` bigint(20) UNSIGNED NOT NULL,
  `division` char(10) DEFAULT '',
  `departement` char(10) DEFAULT '',
  `vehicleid` bigint(20) UNSIGNED NOT NULL,
  `tripid` varchar(30) DEFAULT '',
  `driverid` char(30) DEFAULT NULL,
  `vendorid` char(30) DEFAULT NULL,
  `fueltypeid` char(10) NOT NULL DEFAULT '',
  `transdatetime` datetime DEFAULT NULL,
  `odometervalue` double NOT NULL DEFAULT 0,
  `quantity` double NOT NULL DEFAULT 0,
  `unitprice` double NOT NULL DEFAULT 0,
  `totalamount` double NOT NULL DEFAULT 0,
  `fulltank` smallint(6) NOT NULL DEFAULT 0,
  `stationname` varchar(100) NOT NULL DEFAULT '',
  `receiptnumber` varchar(50) NOT NULL DEFAULT '',
  `notes` varchar(255) NOT NULL DEFAULT '',
  `usercreate` char(16) NOT NULL DEFAULT '',
  `useredit` char(16) NOT NULL DEFAULT '',
  `updatetimestamp` timestamp NOT NULL DEFAULT current_timestamp() ON UPDATE current_timestamp()
) ENGINE=InnoDB DEFAULT CHARSET=utf8mb4 COLLATE=utf8mb4_unicode_ci;

CREATE TABLE `vehiclefueltype` (
  `id` char(10) NOT NULL DEFAULT '',
  `name` varchar(50) NOT NULL DEFAULT '',
  `productid` char(30) NOT NULL DEFAULT '',
  `notes` varchar(255) NOT NULL DEFAULT '',
  `expenseacc` char(30) NOT NULL,
  `isactive` smallint(6) NOT NULL DEFAULT 1,
  `usercreate` char(16) NOT NULL DEFAULT '',
  `useredit` char(16) NOT NULL DEFAULT '',
  `updatetimestamp` timestamp NOT NULL DEFAULT current_timestamp() ON UPDATE current_timestamp()
) ENGINE=InnoDB DEFAULT CHARSET=utf8mb4 COLLATE=utf8mb4_unicode_ci;

CREATE TABLE `vehiclemaintenance` (
  `id` varchar(30) NOT NULL DEFAULT '',
  `division` char(10) NOT NULL DEFAULT '',
  `departement` char(10) NOT NULL DEFAULT '',
  `vehicleid` bigint(20) UNSIGNED NOT NULL,
  `categoryid` bigint(20) UNSIGNED NOT NULL,
  `vendorid` char(30) DEFAULT NULL,
  `requestedby` char(30) DEFAULT NULL,
  `servicedatetime` datetime DEFAULT NULL,
  `completedatetime` datetime DEFAULT NULL,
  `odometervalue` double NOT NULL DEFAULT 0,
  `maintenancetype` tinyint(4) NOT NULL DEFAULT 0 COMMENT '0=preventive, 1=corrective, 2=emergency',
  `complaint` text DEFAULT NULL,
  `diagnosis` text DEFAULT NULL,
  `workperformed` text DEFAULT NULL,
  `laborcost` double NOT NULL DEFAULT 0,
  `partscost` double NOT NULL DEFAULT 0,
  `othercost` double NOT NULL DEFAULT 0,
  `totalcost` double NOT NULL DEFAULT 0,
  `nextservicedate` date DEFAULT NULL,
  `nextserviceodometer` double NOT NULL DEFAULT 0,
  `maintenancestatus` tinyint(4) NOT NULL DEFAULT 0 COMMENT '0=draft, 1=approved, 2=done, 3=cancelled',
  `notes` text DEFAULT NULL,
  `usercreate` char(16) NOT NULL DEFAULT '',
  `useredit` char(16) NOT NULL DEFAULT '',
  `updatetimestamp` timestamp NOT NULL DEFAULT current_timestamp() ON UPDATE current_timestamp()
) ENGINE=InnoDB DEFAULT CHARSET=utf8mb4 COLLATE=utf8mb4_unicode_ci;

CREATE TABLE `vehiclemaintenancecategory` (
  `id` bigint(20) UNSIGNED NOT NULL,
  `name` varchar(100) NOT NULL DEFAULT '',
  `intervaldays` int(11) NOT NULL DEFAULT 0,
  `intervaldistance` double NOT NULL DEFAULT 0,
  `expenseacc` char(30) NOT NULL DEFAULT '',
  `notes` varchar(255) NOT NULL DEFAULT '',
  `isactive` smallint(6) NOT NULL DEFAULT 1,
  `usercreate` char(16) NOT NULL DEFAULT '',
  `useredit` char(16) NOT NULL DEFAULT '',
  `updatetimestamp` timestamp NOT NULL DEFAULT current_timestamp() ON UPDATE current_timestamp()
) ENGINE=InnoDB DEFAULT CHARSET=utf8mb4 COLLATE=utf8mb4_unicode_ci;

CREATE TABLE `vehiclemaintenancepart` (
  `id` bigint(20) UNSIGNED NOT NULL,
  `maintenanceid` varchar(30) NOT NULL DEFAULT '',
  `productid` char(30) NOT NULL DEFAULT '',
  `description` varchar(150) NOT NULL DEFAULT '',
  `quantity` double NOT NULL DEFAULT 0,
  `unitname` varchar(20) NOT NULL DEFAULT '',
  `unitcost` double NOT NULL DEFAULT 0,
  `subtotal` double NOT NULL DEFAULT 0,
  `notes` varchar(255) NOT NULL DEFAULT '',
  `usercreate` char(16) NOT NULL DEFAULT '',
  `useredit` char(16) NOT NULL DEFAULT '',
  `updatetimestamp` timestamp NOT NULL DEFAULT current_timestamp() ON UPDATE current_timestamp()
) ENGINE=InnoDB DEFAULT CHARSET=utf8mb4 COLLATE=utf8mb4_unicode_ci;

CREATE TABLE `vehiclemodel` (
  `id` bigint(20) UNSIGNED NOT NULL,
  `brandid` bigint(20) UNSIGNED NOT NULL,
  `name` varchar(100) NOT NULL DEFAULT '',
  `vehicletypeid` bigint(20) UNSIGNED NOT NULL,
  `defaultfueltypeid` char(10) DEFAULT NULL,
  `seatcapacity` int(11) NOT NULL DEFAULT 0,
  `loadcapacitykg` double NOT NULL DEFAULT 0,
  `fueltankcapacity` double NOT NULL DEFAULT 0,
  `notes` varchar(255) NOT NULL DEFAULT '',
  `isactive` smallint(6) NOT NULL DEFAULT 1,
  `usercreate` char(16) NOT NULL DEFAULT '',
  `useredit` char(16) NOT NULL DEFAULT '',
  `updatetimestamp` timestamp NOT NULL DEFAULT current_timestamp() ON UPDATE current_timestamp()
) ENGINE=InnoDB DEFAULT CHARSET=utf8mb4 COLLATE=utf8mb4_unicode_ci;

CREATE TABLE `vehicleroute` (
  `id` bigint(20) UNSIGNED NOT NULL,
  `name` varchar(100) NOT NULL DEFAULT '',
  `routelengthkm` double NOT NULL DEFAULT 0,
  `notes` varchar(255) NOT NULL DEFAULT '',
  `isactive` smallint(6) NOT NULL DEFAULT 1,
  `usercreate` char(16) NOT NULL DEFAULT '',
  `useredit` char(16) NOT NULL DEFAULT '',
  `updatetimestamp` timestamp NOT NULL DEFAULT current_timestamp() ON UPDATE current_timestamp()
) ENGINE=InnoDB DEFAULT CHARSET=utf8mb4 COLLATE=utf8mb4_unicode_ci;

CREATE TABLE `vehicletrip` (
  `id` varchar(30) NOT NULL,
  `division` char(10) NOT NULL DEFAULT '',
  `departement` char(10) NOT NULL DEFAULT '',
  `vehicleid` bigint(20) UNSIGNED NOT NULL,
  `fueltypeid` char(10) NOT NULL DEFAULT '',
  `driverid` char(30) NOT NULL DEFAULT '',
  `transdate` date DEFAULT NULL,
  `startdatetime` datetime DEFAULT NULL,
  `enddatetime` datetime DEFAULT NULL,
  `tripdurationhour` int(11) NOT NULL DEFAULT 0,
  `routeid` bigint(20) UNSIGNED DEFAULT NULL,
  `routelengthkm` double NOT NULL DEFAULT 0,
  `loadquantity` int(11) NOT NULL DEFAULT 0,
  `purpose` varchar(255) NOT NULL DEFAULT '',
  `customername` varchar(100) NOT NULL DEFAULT '',
  `odometerstart` double NOT NULL DEFAULT 0,
  `odometerend` double NOT NULL DEFAULT 0,
  `distancetotal` double NOT NULL DEFAULT 0,
  `fuelqtyused` double NOT NULL DEFAULT 0,
  `fuelcosttotal` double NOT NULL DEFAULT 0,
  `tripstatus` tinyint(4) NOT NULL DEFAULT 0 COMMENT '0=draft, 1=ongoing, 2=done, 3=cancelled',
  `notes` text DEFAULT NULL,
  `usercreate` char(16) NOT NULL DEFAULT '',
  `useredit` char(16) NOT NULL DEFAULT '',
  `updatetimestamp` timestamp NOT NULL DEFAULT current_timestamp() ON UPDATE current_timestamp()
) ENGINE=InnoDB DEFAULT CHARSET=utf8mb4 COLLATE=utf8mb4_unicode_ci;

CREATE TABLE `vehicletype` (
  `id` bigint(20) UNSIGNED NOT NULL,
  `name` varchar(100) NOT NULL DEFAULT '',
  `notes` varchar(255) NOT NULL DEFAULT '',
  `isactive` smallint(6) NOT NULL DEFAULT 1,
  `usercreate` char(16) NOT NULL DEFAULT '',
  `useredit` char(16) NOT NULL DEFAULT '',
  `updatetimestamp` timestamp NOT NULL DEFAULT current_timestamp() ON UPDATE current_timestamp()
) ENGINE=InnoDB DEFAULT CHARSET=utf8mb4 COLLATE=utf8mb4_unicode_ci;

INSERT INTO `vehicletype` (`id`, `name`, `notes`, `isactive`, `usercreate`, `useredit`, `updatetimestamp`) VALUES
(1, 'Bus', '', 1, '', '', '2026-03-31 06:48:22'),
(2, 'Car', '', 1, '', '', '2026-03-31 06:48:22'),
(3, 'Heavy Equipment', '', 1, '', '', '2026-03-31 06:48:22'),
(4, 'Motorcycle', '', 1, '', '', '2026-03-31 06:48:22'),
(5, 'Other', '', 1, '', '', '2026-03-31 06:48:22'),
(6, 'TAG BOAT', '', 1, 'admin', '', '2026-03-31 06:56:04'),
(7, 'Truck', '', 1, '', '', '2026-03-31 06:48:22'),
(8, 'Van', '', 1, '', '', '2026-03-31 06:48:22');

CREATE TABLE `version` (
  `id` bigint(20) UNSIGNED NOT NULL,
  `version` char(20) NOT NULL DEFAULT '',
  `updatetimestamp` timestamp NOT NULL DEFAULT current_timestamp() ON UPDATE current_timestamp()
) ENGINE=InnoDB DEFAULT CHARSET=utf8mb4 COLLATE=utf8mb4_unicode_ci;

INSERT INTO `version` (`id`, `version`, `updatetimestamp`) VALUES
(1, '8.1.5400', '2026-05-28 21:09:56');

CREATE TABLE `virtualtrans` (
  `id` int(11) NOT NULL,
  `transaction_id` char(50) NOT NULL,
  `userid` char(50) NOT NULL,
  `operation` enum('insert','update','delete') NOT NULL,
  `table_name` varchar(64) NOT NULL,
  `sql_text` text NOT NULL,
  `bindings` longtext NOT NULL,
  `delete_files` text NOT NULL,
  `created_at` datetime DEFAULT current_timestamp()
) ENGINE=InnoDB DEFAULT CHARSET=utf8mb4 COLLATE=utf8mb4_unicode_ci;
CREATE TABLE `vw_salesdiscrules` (
`key_type` varchar(1)
,`value` varchar(73)
,`label` varchar(73)
);
CREATE TABLE `vw_salespointrewardrules` (
`key_type` varchar(1)
,`value` varchar(73)
,`label` varchar(73)
);

CREATE TABLE `workinghours` (
  `id` bigint(20) NOT NULL,
  `name` varchar(50) NOT NULL DEFAULT '',
  `startcheckin` time DEFAULT NULL,
  `endcheckout` time DEFAULT NULL,
  `latecheckin` time DEFAULT NULL,
  `overtime` time DEFAULT NULL,
  `enableinputstart` time DEFAULT NULL,
  `enableinputend` time DEFAULT NULL,
  `employeegroup` tinytext DEFAULT NULL,
  `usercreate` char(16) NOT NULL DEFAULT '',
  `useredit` char(16) NOT NULL DEFAULT '',
  `updatetimestamp` timestamp NOT NULL DEFAULT current_timestamp() ON UPDATE current_timestamp()
) ENGINE=InnoDB DEFAULT CHARSET=utf8mb4 COLLATE=utf8mb4_unicode_ci;


ALTER TABLE `account`
  ADD PRIMARY KEY (`id`);

ALTER TABLE `address`
  ADD PRIMARY KEY (`id`);

ALTER TABLE `attendance`
  ADD PRIMARY KEY (`id`),
  ADD KEY `employeeid` (`employeeid`),
  ADD KEY `kioskdeviceid` (`kioskdeviceid`),
  ADD KEY `verifymethod` (`verifymethod`);

ALTER TABLE `attendancekioskdevice`
  ADD PRIMARY KEY (`id`),
  ADD KEY `isactive` (`isactive`);

ALTER TABLE `attendanceverifylog`
  ADD PRIMARY KEY (`id`),
  ADD KEY `employeeid` (`employeeid`),
  ADD KEY `attendanceid` (`attendanceid`),
  ADD KEY `kioskdeviceid` (`kioskdeviceid`),
  ADD KEY `result` (`result`);

ALTER TABLE `authorityrequest`
  ADD PRIMARY KEY (`id`),
  ADD KEY `userid` (`userid`),
  ADD KEY `touserid` (`touserid`);

ALTER TABLE `authors`
  ADD PRIMARY KEY (`id`);

ALTER TABLE `cogs`
  ADD PRIMARY KEY (`id`) USING BTREE,
  ADD KEY `productid` (`productid`) USING BTREE,
  ADD KEY `FK_cogs_division` (`division`);

ALTER TABLE `company`
  ADD PRIMARY KEY (`id`),
  ADD KEY `inventorytransferaccount` (`inventorytransferaccount`);

ALTER TABLE `countries`
  ADD PRIMARY KEY (`id`);

ALTER TABLE `currencies`
  ADD PRIMARY KEY (`id`);

ALTER TABLE `customer`
  ADD PRIMARY KEY (`id`),
  ADD KEY `customergroup` (`customergroup`),
  ADD KEY `receivableacc` (`receivableacc`),
  ADD KEY `rewardacc` (`rewardacc`),
  ADD KEY `salesdiscacc` (`salesdiscacc`),
  ADD KEY `gainlossreceivableacc` (`gainlossreceivableacc`),
  ADD KEY `customer_ibfk_6` (`defsalesmanid`);

ALTER TABLE `customerbalance`
  ADD PRIMARY KEY (`transid`) USING BTREE,
  ADD KEY `customerid` (`customerid`) USING BTREE,
  ADD KEY `FK_customerbalance_division` (`division`);

ALTER TABLE `customerdisplay`
  ADD PRIMARY KEY (`id`);

ALTER TABLE `customerdp`
  ADD PRIMARY KEY (`transid`),
  ADD KEY `division` (`division`),
  ADD KEY `customerid` (`customerid`),
  ADD KEY `paymenttype` (`paymenttype`),
  ADD KEY `downpaymenttype` (`downpaymenttype`);

ALTER TABLE `customergiro`
  ADD PRIMARY KEY (`id`),
  ADD KEY `customerid` (`customerid`),
  ADD KEY `division` (`division`),
  ADD KEY `paymenttype` (`paymenttype`);

ALTER TABLE `customergroup`
  ADD PRIMARY KEY (`id`),
  ADD KEY `receivableacc` (`receivableacc`),
  ADD KEY `rewardacc` (`rewardacc`),
  ADD KEY `salesdiscacc` (`salesdiscacc`),
  ADD KEY `gainlossreceivableacc` (`gainlossreceivableacc`);

ALTER TABLE `customerguide`
  ADD PRIMARY KEY (`id`);

ALTER TABLE `customernote`
  ADD PRIMARY KEY (`transid`),
  ADD KEY `division` (`division`),
  ADD KEY `customerid` (`customerid`),
  ADD KEY `customernote_ibfk_3` (`customernoteid`);

ALTER TABLE `customernotes`
  ADD PRIMARY KEY (`id`);

ALTER TABLE `deliveryorder`
  ADD PRIMARY KEY (`salesid`),
  ADD KEY `division` (`division`),
  ADD KEY `salesmanid` (`salesmanid`),
  ADD KEY `customerid` (`customerid`),
  ADD KEY `shipment` (`shipment`);

ALTER TABLE `deliveryorderdetail`
  ADD PRIMARY KEY (`transid`),
  ADD KEY `salesid` (`salesid`),
  ADD KEY `productid` (`productid`),
  ADD KEY `departement` (`departement`),
  ADD KEY `salesidref` (`salesidref`);

ALTER TABLE `deliveryorderrewarddetail`
  ADD PRIMARY KEY (`transid`),
  ADD KEY `salesid` (`salesid`),
  ADD KEY `salesidref` (`salesidref`),
  ADD KEY `productid` (`productid`),
  ADD KEY `departement` (`departement`);

ALTER TABLE `departement`
  ADD PRIMARY KEY (`id`),
  ADD KEY `FK_departement_1` (`division`);

ALTER TABLE `depreciationrecords`
  ADD PRIMARY KEY (`transid`),
  ADD KEY `fixedassetid` (`fixedassetid`);

ALTER TABLE `discountdays`
  ADD PRIMARY KEY (`adate`);

ALTER TABLE `division`
  ADD PRIMARY KEY (`id`),
  ADD KEY `FK_division_1` (`retainedearningacc`),
  ADD KEY `FK_division_2` (`exchangerateacc`),
  ADD KEY `FK_division_3` (`profitlossdiffcashacc`);

ALTER TABLE `employee`
  ADD PRIMARY KEY (`id`),
  ADD KEY `employeegroup` (`employeegroup`),
  ADD KEY `taxes` (`taxtype`),
  ADD KEY `salarystructure` (`salarystructure`) USING BTREE;

ALTER TABLE `employeeface`
  ADD PRIMARY KEY (`id`),
  ADD KEY `employeeid` (`employeeid`),
  ADD KEY `employeeid_isactive` (`employeeid`,`isactive`);

ALTER TABLE `employeefaceenrollment`
  ADD PRIMARY KEY (`id`),
  ADD KEY `employeeid` (`employeeid`),
  ADD KEY `status` (`status`);

ALTER TABLE `employeegroup`
  ADD PRIMARY KEY (`id`);

ALTER TABLE `employeesalaries`
  ADD PRIMARY KEY (`id`) USING BTREE,
  ADD KEY `employeeid` (`employeeid`) USING BTREE,
  ADD KEY `salaryid` (`salaryid`) USING BTREE;

ALTER TABLE `excratehistories`
  ADD PRIMARY KEY (`transid`),
  ADD KEY `excratehistories_ibfk_1` (`id`);

ALTER TABLE `factories`
  ADD PRIMARY KEY (`id`);

ALTER TABLE `filteroperands`
  ADD PRIMARY KEY (`id`);

ALTER TABLE `fixedasset`
  ADD PRIMARY KEY (`id`),
  ADD KEY `fagroup` (`fagroup`),
  ADD KEY `division` (`division`),
  ADD KEY `departement` (`departement`),
  ADD KEY `accountid` (`accountid`) USING BTREE;

ALTER TABLE `fixedassetdepreciation`
  ADD PRIMARY KEY (`transid`) USING BTREE,
  ADD KEY `division` (`division`) USING BTREE;

ALTER TABLE `fixedassetdispose`
  ADD PRIMARY KEY (`transid`) USING BTREE,
  ADD KEY `division` (`division`) USING BTREE,
  ADD KEY `departement` (`departement`) USING BTREE,
  ADD KEY `accountid` (`accountid`) USING BTREE;

ALTER TABLE `fixedassetgroup`
  ADD PRIMARY KEY (`id`),
  ADD KEY `fixedassetacc` (`fixedassetacc`),
  ADD KEY `depreciationacc` (`depreciationacc`),
  ADD KEY `expenseacc` (`expenseacc`),
  ADD KEY `gainlostacc` (`gainlostacc`);

ALTER TABLE `goodsreceipt`
  ADD PRIMARY KEY (`purchaseid`),
  ADD KEY `division` (`division`),
  ADD KEY `purchaser` (`purchaser`),
  ADD KEY `supplierid` (`supplierid`),
  ADD KEY `shipment` (`shipment`);

ALTER TABLE `goodsreceiptdetail`
  ADD PRIMARY KEY (`transid`),
  ADD KEY `purchaseid` (`purchaseid`),
  ADD KEY `productid` (`productid`),
  ADD KEY `departement` (`departement`),
  ADD KEY `purchaseidref` (`purchaseidref`);

ALTER TABLE `goodsreceiptrewarddetail`
  ADD PRIMARY KEY (`transid`),
  ADD KEY `purchaseid` (`purchaseid`),
  ADD KEY `purchaseidref` (`purchaseidref`),
  ADD KEY `productid` (`productid`),
  ADD KEY `departement` (`departement`);

ALTER TABLE `groupid`
  ADD PRIMARY KEY (`id`);

ALTER TABLE `holidays`
  ADD PRIMARY KEY (`adate`);

ALTER TABLE `inputpayablebal`
  ADD PRIMARY KEY (`id`),
  ADD KEY `division` (`division`),
  ADD KEY `accountid` (`accountid`);

ALTER TABLE `inputreceivablebal`
  ADD PRIMARY KEY (`id`),
  ADD KEY `division` (`division`),
  ADD KEY `accountid` (`accountid`);

ALTER TABLE `inventory`
  ADD PRIMARY KEY (`id`),
  ADD KEY `departement` (`departement`),
  ADD KEY `division` (`division`),
  ADD KEY `productid` (`productid`);

ALTER TABLE `inventoryadjust`
  ADD PRIMARY KEY (`id`),
  ADD KEY `inventoryadjust_ibfk_1` (`division`),
  ADD KEY `FK_inventoryadjust_departement` (`departement`),
  ADD KEY `FK_inventoryadjust_account` (`accountid`);

ALTER TABLE `inventoryadjustdetail`
  ADD PRIMARY KEY (`id`),
  ADD KEY `productid` (`productid`),
  ADD KEY `transid` (`transid`),
  ADD KEY `inventoryadjustdetail_ibfk_5` (`unit`);

ALTER TABLE `inventoryin`
  ADD PRIMARY KEY (`id`),
  ADD KEY `division` (`division`),
  ADD KEY `departement` (`departement`),
  ADD KEY `accountid` (`accountid`);

ALTER TABLE `inventoryindetail`
  ADD PRIMARY KEY (`id`),
  ADD KEY `productid` (`productid`),
  ADD KEY `transid` (`transid`),
  ADD KEY `inventoryindetail_ibfk_3` (`unit`);

ALTER TABLE `inventorymoving`
  ADD PRIMARY KEY (`id`),
  ADD KEY `inventorymoving_ibfk_1` (`fromdivision`),
  ADD KEY `inventorymoving_ibfk_2` (`fromdepartement`),
  ADD KEY `inventorymoving_ibfk_3` (`todivision`),
  ADD KEY `inventorymoving_ibfk_4` (`todepartement`);

ALTER TABLE `inventorymovingdetail`
  ADD PRIMARY KEY (`id`),
  ADD KEY `productid` (`productid`),
  ADD KEY `transid` (`transid`),
  ADD KEY `inventorymovingdetail_ibfk_3` (`unit`);

ALTER TABLE `inventoryout`
  ADD PRIMARY KEY (`id`),
  ADD KEY `division` (`division`),
  ADD KEY `departement` (`departement`),
  ADD KEY `accountid` (`accountid`);

ALTER TABLE `inventoryoutdetail`
  ADD PRIMARY KEY (`id`),
  ADD KEY `productid` (`productid`),
  ADD KEY `transid` (`transid`),
  ADD KEY `inventoryoutdetail_ibfk_3` (`unit`);

ALTER TABLE `journal`
  ADD PRIMARY KEY (`jtid`),
  ADD KEY `division` (`division`);

ALTER TABLE `journalclose`
  ADD PRIMARY KEY (`jtid`),
  ADD KEY `division` (`division`),
  ADD KEY `accountid` (`accountid`);

ALTER TABLE `journalexpense`
  ADD PRIMARY KEY (`jtid`),
  ADD KEY `division` (`division`),
  ADD KEY `paymenttype` (`paymenttype`);

ALTER TABLE `journalexpensedetail`
  ADD PRIMARY KEY (`id`),
  ADD KEY `accountid` (`accountid`),
  ADD KEY `journalexpensedetail_ibfk_2` (`jtid`);

ALTER TABLE `journalrevenue`
  ADD PRIMARY KEY (`jtid`),
  ADD KEY `division` (`division`),
  ADD KEY `paymenttype` (`paymenttype`);

ALTER TABLE `journalrevenuedetail`
  ADD PRIMARY KEY (`id`),
  ADD KEY `accountid` (`accountid`),
  ADD KEY `journalrevenuedetail_ibfk_2` (`jtid`);

ALTER TABLE `journaltrans`
  ADD PRIMARY KEY (`id`),
  ADD KEY `accountid` (`accountid`),
  ADD KEY `division` (`division`);

ALTER TABLE `langoverrides`
  ADD PRIMARY KEY (`id`),
  ADD UNIQUE KEY `uq_lang_overrides_lang_key` (`lang`,`langkey`),
  ADD KEY `idx_lang_overrides_lang` (`lang`),
  ADD KEY `idx_lang_overrides_key` (`langkey`);

ALTER TABLE `logtransactions`
  ADD PRIMARY KEY (`id`);

ALTER TABLE `mrpbomcomponent`
  ADD PRIMARY KEY (`id`) USING BTREE,
  ADD KEY `FK_mrpbomcomponent_product` (`productid`),
  ADD KEY `FK_mrpbomcomponent_product_2` (`mrpproduct`);

ALTER TABLE `mrpbomoperation`
  ADD PRIMARY KEY (`id`) USING BTREE,
  ADD KEY `FK_mrpbomoperation_mrpoperation` (`operationid`),
  ADD KEY `FK_mrpbomoperation_product` (`mrpproduct`);

ALTER TABLE `mrpoperation`
  ADD PRIMARY KEY (`id`) USING BTREE,
  ADD KEY `FK_mrpoperation_mrpworkcenter` (`workcenter`),
  ADD KEY `FK_mrpoperation_wageaccount` (`wageaccount`);

ALTER TABLE `mrporder`
  ADD PRIMARY KEY (`transid`) USING BTREE,
  ADD KEY `FK_mrporder_product` (`productid`) USING BTREE,
  ADD KEY `FK_mrporder_division` (`division`),
  ADD KEY `FK_mrporder_departement` (`departement`);

ALTER TABLE `mrpordercomponent`
  ADD PRIMARY KEY (`id`) USING BTREE,
  ADD KEY `FK_mrpordercomponent_product` (`productid`) USING BTREE,
  ADD KEY `FK_mrpordercomponent_mrporder` (`mrporder`) USING BTREE;

ALTER TABLE `mrpworkcenter`
  ADD PRIMARY KEY (`id`) USING BTREE,
  ADD KEY `FK_mrpworkcenter_division` (`division`) USING BTREE,
  ADD KEY `FK_mrpworkcenter_productiondepartement` (`productiondepartement`) USING BTREE,
  ADD KEY `FK_mrpworkcenter_storedepartement` (`storedepartement`) USING BTREE;

ALTER TABLE `mrpworkorder`
  ADD PRIMARY KEY (`id`) USING BTREE,
  ADD KEY `FK_mrpworkorder_mrpoperation` (`operationid`) USING BTREE,
  ADD KEY `FK_mrpworkorder_mrporder` (`mrporder`);

ALTER TABLE `mrpworkorderemployee`
  ADD PRIMARY KEY (`id`) USING BTREE,
  ADD KEY `FK_mrpworkorderemployee_mrpworkorder` (`workorderid`),
  ADD KEY `FK_mrpworkorderemployee_employee` (`employeeid`);

ALTER TABLE `onlinepayments`
  ADD PRIMARY KEY (`id`) USING BTREE;

ALTER TABLE `payableadjust`
  ADD PRIMARY KEY (`transid`),
  ADD KEY `division` (`division`),
  ADD KEY `supplierid` (`supplierid`),
  ADD KEY `expensestype` (`expensestype`);

ALTER TABLE `payablepayment`
  ADD PRIMARY KEY (`transid`),
  ADD KEY `division` (`division`),
  ADD KEY `supplierid` (`supplierid`),
  ADD KEY `paymenttype` (`paymenttype`);

ALTER TABLE `paymentdiscrules`
  ADD PRIMARY KEY (`id`);

ALTER TABLE `paymenttype`
  ADD PRIMARY KEY (`id`),
  ADD KEY `paymenttype_ibfk_1` (`paymentacc`),
  ADD KEY `paymenttype_ibfk_2` (`cashdiscacc`),
  ADD KEY `paymenttype_ibfk_3` (`expenseacc`);

ALTER TABLE `pointofsales`
  ADD PRIMARY KEY (`id`),
  ADD KEY `FK_pointofsales_paymenttype` (`paymentdefault`),
  ADD KEY `FK_pointofsales_customer` (`customerdefault`),
  ADD KEY `FK_pointofsales_salesman` (`salesmandefault`),
  ADD KEY `FK_pointofsales_division` (`division`),
  ADD KEY `FK_pointofsales_departement` (`departement`),
  ADD KEY `FK_pointofsales_shipments` (`shipment`),
  ADD KEY `FK_pointofsales_servicedoer` (`servicedoerdefault`),
  ADD KEY `FK_pointofsales_account` (`sourcecash`);

ALTER TABLE `poshistories`
  ADD PRIMARY KEY (`id`) USING BTREE,
  ADD KEY `FK_poshistories_posid` (`posid`) USING BTREE;

ALTER TABLE `posprintcashier`
  ADD PRIMARY KEY (`id`);

ALTER TABLE `posprintorder`
  ADD PRIMARY KEY (`id`) USING BTREE;

ALTER TABLE `postable`
  ADD PRIMARY KEY (`id`) USING BTREE,
  ADD KEY `FK_postable_customer` (`customerid`),
  ADD KEY `FK_postable_postablegroup` (`tablegroup`);

ALTER TABLE `postablegroup`
  ADD PRIMARY KEY (`id`) USING BTREE;

ALTER TABLE `product`
  ADD PRIMARY KEY (`id`),
  ADD KEY `author` (`author`),
  ADD KEY `factory` (`factory`),
  ADD KEY `supplier` (`supplier`),
  ADD KEY `productgroup` (`productgroup`),
  ADD KEY `taxtype` (`taxtype`),
  ADD KEY `cogsacc` (`cogsacc`),
  ADD KEY `inventoryacc` (`inventoryacc`),
  ADD KEY `salesacc` (`salesacc`),
  ADD KEY `salesdiscacc` (`salesdiscacc`),
  ADD KEY `salesreturnacc` (`salesreturnacc`),
  ADD KEY `brand` (`brand`);

ALTER TABLE `productassemble`
  ADD PRIMARY KEY (`id`),
  ADD KEY `division` (`division`),
  ADD KEY `departement` (`departement`),
  ADD KEY `productid` (`productid`),
  ADD KEY `productassemble_ibfk_4` (`unit`);

ALTER TABLE `productassembledetail`
  ADD PRIMARY KEY (`id`),
  ADD KEY `productid` (`productid`),
  ADD KEY `transid` (`transid`),
  ADD KEY `productassembledetail_ibfk_3` (`unit`);

ALTER TABLE `productbrand`
  ADD PRIMARY KEY (`id`);

ALTER TABLE `productdisassemble`
  ADD PRIMARY KEY (`id`),
  ADD KEY `division` (`division`),
  ADD KEY `departement` (`departement`),
  ADD KEY `productid` (`productid`),
  ADD KEY `productdisassemble_ibfk_4` (`unit`);

ALTER TABLE `productdisassembledetail`
  ADD PRIMARY KEY (`id`),
  ADD KEY `productid` (`productid`),
  ADD KEY `transid` (`transid`),
  ADD KEY `productdisassembledetail_ibfk_3` (`unit`);

ALTER TABLE `productgroup`
  ADD PRIMARY KEY (`id`),
  ADD KEY `cogsacc` (`cogsacc`),
  ADD KEY `inventoryacc` (`inventoryacc`),
  ADD KEY `salesacc` (`salesacc`),
  ADD KEY `salesdiscacc` (`salesdiscacc`),
  ADD KEY `salesreturnacc` (`salesreturnacc`);

ALTER TABLE `productpackage`
  ADD PRIMARY KEY (`transid`),
  ADD KEY `packageid` (`packageid`),
  ADD KEY `productid` (`productid`);

ALTER TABLE `productsalesvariant`
  ADD PRIMARY KEY (`id`),
  ADD KEY `productgroup` (`productgroup`);

ALTER TABLE `purchase`
  ADD PRIMARY KEY (`purchaseid`),
  ADD KEY `division` (`division`),
  ADD KEY `purchaser` (`purchaser`),
  ADD KEY `supplierid` (`supplierid`),
  ADD KEY `shipment` (`shipment`);

ALTER TABLE `purchasedetail`
  ADD PRIMARY KEY (`transid`),
  ADD KEY `purchaseid` (`purchaseid`),
  ADD KEY `productid` (`productid`),
  ADD KEY `taxid` (`taxid`),
  ADD KEY `departement` (`departement`),
  ADD KEY `purchaseidref` (`purchaseidref`);

ALTER TABLE `purchaseexpenses`
  ADD PRIMARY KEY (`id`),
  ADD KEY `purchaseexpacc` (`purchaseexpacc`);

ALTER TABLE `purchaseexpensesdetail`
  ADD PRIMARY KEY (`transid`),
  ADD KEY `purchaseid` (`purchaseid`),
  ADD KEY `purchaseexpid` (`purchaseexpid`),
  ADD KEY `purchaseidref` (`purchaseidref`);

ALTER TABLE `purchaseextratax`
  ADD PRIMARY KEY (`transid`),
  ADD KEY `purchaseid` (`purchaseid`),
  ADD KEY `productid` (`productid`),
  ADD KEY `taxid` (`taxid`),
  ADD KEY `purchaseidref` (`purchaseidref`);

ALTER TABLE `purchaseorder`
  ADD PRIMARY KEY (`purchaseid`),
  ADD KEY `division` (`division`),
  ADD KEY `purchaser` (`purchaser`),
  ADD KEY `supplierid` (`supplierid`),
  ADD KEY `shipment` (`shipment`);

ALTER TABLE `purchaseorderdetail`
  ADD PRIMARY KEY (`transid`),
  ADD KEY `purchaseid` (`purchaseid`),
  ADD KEY `productid` (`productid`),
  ADD KEY `taxid` (`taxid`),
  ADD KEY `departement` (`departement`),
  ADD KEY `purchaseidref` (`purchaseidref`);

ALTER TABLE `purchaseorderexpensesdetail`
  ADD PRIMARY KEY (`transid`),
  ADD KEY `purchaseid` (`purchaseid`),
  ADD KEY `purchaseexpid` (`purchaseexpid`),
  ADD KEY `purchaseidref` (`purchaseidref`);

ALTER TABLE `purchaseorderextratax`
  ADD PRIMARY KEY (`transid`),
  ADD KEY `purchaseid` (`purchaseid`),
  ADD KEY `productid` (`productid`),
  ADD KEY `taxid` (`taxid`),
  ADD KEY `purchaseidref` (`purchaseidref`);

ALTER TABLE `purchaseorderpayments`
  ADD PRIMARY KEY (`transid`),
  ADD KEY `purchaseid` (`purchaseid`),
  ADD KEY `purchaseidref` (`purchaseidref`),
  ADD KEY `paymenttype` (`paymenttype`);

ALTER TABLE `purchaseorderpoint`
  ADD PRIMARY KEY (`transid`) USING BTREE,
  ADD KEY `purchaseid` (`purchaseid`) USING BTREE,
  ADD KEY `purchaseidref` (`purchaseidref`) USING BTREE,
  ADD KEY `supplier` (`supplier`) USING BTREE;

ALTER TABLE `purchaseorderrewarddetail`
  ADD PRIMARY KEY (`transid`),
  ADD KEY `purchaseid` (`purchaseid`),
  ADD KEY `purchaseidref` (`purchaseidref`),
  ADD KEY `productid` (`productid`),
  ADD KEY `departement` (`departement`);

ALTER TABLE `purchasepayments`
  ADD PRIMARY KEY (`transid`),
  ADD KEY `purchaseid` (`purchaseid`),
  ADD KEY `purchaseidref` (`purchaseidref`),
  ADD KEY `paymenttype` (`paymenttype`);

ALTER TABLE `purchasepoint`
  ADD PRIMARY KEY (`transid`),
  ADD KEY `purchaseid` (`purchaseid`),
  ADD KEY `purchaseidref` (`purchaseidref`),
  ADD KEY `supplier` (`supplier`);

ALTER TABLE `purchaserequisition`
  ADD PRIMARY KEY (`requisitionid`),
  ADD KEY `division` (`division`),
  ADD KEY `approvaluser` (`approvaluser`);

ALTER TABLE `purchaserequisitiondetail`
  ADD PRIMARY KEY (`transid`),
  ADD KEY `requisitionid` (`requisitionid`),
  ADD KEY `requisitionidref` (`requisitionidref`),
  ADD KEY `supplierid` (`supplierid`),
  ADD KEY `departement` (`departement`),
  ADD KEY `productid` (`productid`);

ALTER TABLE `purchaserewarddetail`
  ADD PRIMARY KEY (`transid`),
  ADD KEY `purchaseid` (`purchaseid`),
  ADD KEY `purchaseidref` (`purchaseidref`),
  ADD KEY `productid` (`productid`),
  ADD KEY `departement` (`departement`);

ALTER TABLE `receivableadjust`
  ADD PRIMARY KEY (`transid`),
  ADD KEY `division` (`division`),
  ADD KEY `customerid` (`customerid`),
  ADD KEY `expensestype` (`expensestype`);

ALTER TABLE `receivablepayment`
  ADD PRIMARY KEY (`transid`),
  ADD KEY `division` (`division`),
  ADD KEY `customerid` (`customerid`),
  ADD KEY `paymenttype` (`paymenttype`);

ALTER TABLE `religions`
  ADD PRIMARY KEY (`id`);

ALTER TABLE `rentalreturn`
  ADD PRIMARY KEY (`transid`) USING BTREE,
  ADD KEY `division` (`division`) USING BTREE,
  ADD KEY `customerid` (`customerid`) USING BTREE,
  ADD KEY `FK_rentalreturn_sales` (`salesid`) USING BTREE;

ALTER TABLE `rentalreturndetail`
  ADD PRIMARY KEY (`transid`) USING BTREE,
  ADD KEY `rentalreturnid` (`rentalreturnid`) USING BTREE,
  ADD KEY `productid` (`productid`) USING BTREE,
  ADD KEY `departement` (`departement`) USING BTREE;

ALTER TABLE `roles`
  ADD PRIMARY KEY (`id`),
  ADD KEY `division_ibfk` (`defaultdivision`),
  ADD KEY `departement_ibfk` (`defaultdepartement`),
  ADD KEY `customer_ibfk` (`defaultcustomer`),
  ADD KEY `supplier_ibfk` (`defaultsupplier`),
  ADD KEY `salesman_ibfk` (`defaultsalesman`),
  ADD KEY `servicedoer_ibfk` (`defaultservicedoer`),
  ADD KEY `currency_ibfk` (`defaultcurrency`),
  ADD KEY `employee_ibfk` (`defaultemployee`),
  ADD KEY `shipment_ibfk` (`defaultshipment`),
  ADD KEY `payment_ibfk` (`defaultpayment`);

ALTER TABLE `salaries`
  ADD PRIMARY KEY (`id`),
  ADD KEY `salaries_ibfk_1` (`account`);

ALTER TABLE `salariesrecord`
  ADD PRIMARY KEY (`transid`) USING BTREE,
  ADD KEY `employeeid` (`employeeid`) USING BTREE,
  ADD KEY `salaryid` (`salaryid`) USING BTREE;

ALTER TABLE `salarypayments`
  ADD PRIMARY KEY (`transid`) USING BTREE,
  ADD KEY `division` (`division`),
  ADD KEY `employeeid` (`employeeid`),
  ADD KEY `salaryid` (`salaryid`),
  ADD KEY `paymenttype` (`paymenttype`);

ALTER TABLE `salaryperiod`
  ADD PRIMARY KEY (`id`) USING BTREE,
  ADD KEY `salaryperiod_ibfk_2` (`division`) USING BTREE,
  ADD KEY `salaryperiod_ibfk_1` (`employeegroup`) USING BTREE,
  ADD KEY `FK_salaryperiod_account` (`accountid`);

ALTER TABLE `salaryperioddetail`
  ADD PRIMARY KEY (`transid`) USING BTREE,
  ADD KEY `employeeid` (`employeeid`) USING BTREE;

ALTER TABLE `salarystructure`
  ADD PRIMARY KEY (`id`);

ALTER TABLE `salarystructuredetail`
  ADD PRIMARY KEY (`id`) USING BTREE,
  ADD KEY `salaryid` (`salaryid`) USING BTREE,
  ADD KEY `employeelevel` (`salarystructure`) USING BTREE;

ALTER TABLE `sales`
  ADD PRIMARY KEY (`salesid`),
  ADD KEY `division` (`division`),
  ADD KEY `salesmanid` (`salesmanid`),
  ADD KEY `customerid` (`customerid`),
  ADD KEY `shipment` (`shipment`),
  ADD KEY `sales_ibfk_5` (`billto`);

ALTER TABLE `salesdetail`
  ADD PRIMARY KEY (`transid`),
  ADD KEY `salesid` (`salesid`),
  ADD KEY `productid` (`productid`),
  ADD KEY `taxid` (`taxid`),
  ADD KEY `departement` (`departement`),
  ADD KEY `salesidref` (`salesidref`),
  ADD KEY `servicedoerid` (`servicedoerid`);

ALTER TABLE `salesdiscrules`
  ADD PRIMARY KEY (`id`);

ALTER TABLE `salesexpenses`
  ADD PRIMARY KEY (`id`),
  ADD KEY `salesexpacc` (`salesexpacc`);

ALTER TABLE `salesexpensesdetail`
  ADD PRIMARY KEY (`transid`),
  ADD KEY `salesid` (`salesid`),
  ADD KEY `salesexpid` (`salesexpid`),
  ADD KEY `salesidref` (`salesidref`);

ALTER TABLE `salesextratax`
  ADD PRIMARY KEY (`transid`),
  ADD KEY `salesid` (`salesid`),
  ADD KEY `productid` (`productid`),
  ADD KEY `taxid` (`taxid`),
  ADD KEY `salesidref` (`salesidref`);

ALTER TABLE `salesman`
  ADD PRIMARY KEY (`id`),
  ADD KEY `salesmangroup` (`salesmangroup`),
  ADD KEY `payablecommacc` (`payablecommacc`),
  ADD KEY `expensecommacc` (`expensecommacc`);

ALTER TABLE `salesmancommperiod`
  ADD PRIMARY KEY (`id`),
  ADD KEY `salesmancommperiod_ibfk_1` (`salaryid`),
  ADD KEY `salesmancommperiod_ibfk_2` (`division`);

ALTER TABLE `salesmancommrules`
  ADD PRIMARY KEY (`id`);

ALTER TABLE `salesmancommvar`
  ADD PRIMARY KEY (`varname`);

ALTER TABLE `salesmancommvarrecords`
  ADD PRIMARY KEY (`transid`),
  ADD KEY `salesmancommvarrecords_ibfk_1` (`periodid`);

ALTER TABLE `salesmandetail`
  ADD PRIMARY KEY (`groupid`,`salesmanid`),
  ADD KEY `salesmanid` (`salesmanid`);

ALTER TABLE `salesmangroup`
  ADD PRIMARY KEY (`id`),
  ADD KEY `payablecommacc` (`payablecommacc`),
  ADD KEY `expensecommacc` (`expensecommacc`);

ALTER TABLE `salesmanrecorddetail`
  ADD PRIMARY KEY (`transid`),
  ADD KEY `salesmanid` (`salesmanid`),
  ADD KEY `productid` (`productid`),
  ADD KEY `salesmanrecorddetail_ibfk_3` (`periodid`);

ALTER TABLE `salesmanrecords`
  ADD PRIMARY KEY (`id`),
  ADD KEY `salesmanid` (`salesmanid`),
  ADD KEY `salesmanrecords_ibfk_2` (`periodid`);

ALTER TABLE `salesorder`
  ADD PRIMARY KEY (`salesid`),
  ADD KEY `division` (`division`),
  ADD KEY `salesmanid` (`salesmanid`),
  ADD KEY `customerid` (`customerid`),
  ADD KEY `shipment` (`shipment`);

ALTER TABLE `salesorderdetail`
  ADD PRIMARY KEY (`transid`),
  ADD KEY `salesid` (`salesid`),
  ADD KEY `productid` (`productid`),
  ADD KEY `taxid` (`taxid`),
  ADD KEY `departement` (`departement`),
  ADD KEY `salesidref` (`salesidref`),
  ADD KEY `servicedoerid` (`servicedoerid`);

ALTER TABLE `salesorderexpensesdetail`
  ADD PRIMARY KEY (`transid`),
  ADD KEY `salesid` (`salesid`),
  ADD KEY `salesexpid` (`salesexpid`),
  ADD KEY `salesidref` (`salesidref`);

ALTER TABLE `salesorderextratax`
  ADD PRIMARY KEY (`transid`),
  ADD KEY `salesid` (`salesid`),
  ADD KEY `productid` (`productid`),
  ADD KEY `taxid` (`taxid`),
  ADD KEY `salesidref` (`salesidref`);

ALTER TABLE `salesorderpayments`
  ADD PRIMARY KEY (`transid`),
  ADD KEY `salesid` (`salesid`),
  ADD KEY `salesidref` (`salesidref`),
  ADD KEY `paymenttype` (`paymenttype`);

ALTER TABLE `salesorderpoint`
  ADD PRIMARY KEY (`transid`),
  ADD KEY `salesid` (`salesid`),
  ADD KEY `salesidref` (`salesidref`),
  ADD KEY `customer` (`customer`);

ALTER TABLE `salesorderrewarddetail`
  ADD PRIMARY KEY (`transid`),
  ADD KEY `salesid` (`salesid`),
  ADD KEY `salesidref` (`salesidref`),
  ADD KEY `productid` (`productid`),
  ADD KEY `departement` (`departement`);

ALTER TABLE `salespayments`
  ADD PRIMARY KEY (`transid`),
  ADD KEY `salesid` (`salesid`),
  ADD KEY `salesidref` (`salesidref`),
  ADD KEY `paymenttype` (`paymenttype`);

ALTER TABLE `salespoint`
  ADD PRIMARY KEY (`transid`),
  ADD KEY `salesid` (`salesid`),
  ADD KEY `salesidref` (`salesidref`),
  ADD KEY `customer` (`customer`);

ALTER TABLE `salespointrewardrules`
  ADD PRIMARY KEY (`id`);

ALTER TABLE `salesproductrewardrules`
  ADD PRIMARY KEY (`id`),
  ADD KEY `productid` (`productid`),
  ADD KEY `departement` (`departement`);

ALTER TABLE `salesrewarddetail`
  ADD PRIMARY KEY (`transid`),
  ADD KEY `salesid` (`salesid`),
  ADD KEY `salesidref` (`salesidref`),
  ADD KEY `productid` (`productid`),
  ADD KEY `departement` (`departement`);

ALTER TABLE `schoolclass`
  ADD PRIMARY KEY (`id`) USING BTREE,
  ADD KEY `FK_schoolclass_schoollevel` (`schoollevel`);

ALTER TABLE `schoolexam`
  ADD PRIMARY KEY (`id`);

ALTER TABLE `schoolextrascore`
  ADD PRIMARY KEY (`id`),
  ADD KEY `FK_schoolextrascore_schoolscoringtype` (`scoringtype`),
  ADD KEY `FK_schoolextrascore_schoolextrascoregroup` (`extrascoregroup`);

ALTER TABLE `schoolextrascoregroup`
  ADD PRIMARY KEY (`id`) USING BTREE;

ALTER TABLE `schoollesson`
  ADD PRIMARY KEY (`id`),
  ADD KEY `FK_schoollesson_schoolscoringtype` (`scoringtype`),
  ADD KEY `FK_schoollesson_schoollessongroup` (`lessongroup`);

ALTER TABLE `schoollessonclass`
  ADD PRIMARY KEY (`id`),
  ADD KEY `FK_schoollessonclass_schoolsubclass` (`schoolsubclass`),
  ADD KEY `FK_schoollessonclass_schoollesson` (`schoollesson`),
  ADD KEY `FK_schoollessonclass_schoolteacher` (`schoolteacher`);

ALTER TABLE `schoollessongroup`
  ADD PRIMARY KEY (`id`) USING BTREE;

ALTER TABLE `schoollessonteacher`
  ADD PRIMARY KEY (`id`) USING BTREE,
  ADD KEY `FK_schoollessonteacher_schoolsubclass` (`schoolsubclass`) USING BTREE,
  ADD KEY `FK_schoollessonteacher_schoollesson` (`schoollesson`) USING BTREE,
  ADD KEY `FK_schoollessonteacher_schoolteacher` (`schoolteacher`);

ALTER TABLE `schoollevel`
  ADD PRIMARY KEY (`id`),
  ADD KEY `FK_schoollevel_schoolteacher` (`headmaster`);

ALTER TABLE `schoolpayment`
  ADD PRIMARY KEY (`id`) USING BTREE,
  ADD KEY `FK_schoolpayment_schoolpaymentgroup` (`paymentgroup`) USING BTREE,
  ADD KEY `FK_schoolpayment_receivable` (`receivableacc`),
  ADD KEY `FK_schoolpayment_revenue` (`revenueacc`),
  ADD KEY `FK_schoolpayment_account` (`unearnedrevenueacc`),
  ADD KEY `FK_schoolpayment_account_2` (`paymentdiscacc`);

ALTER TABLE `schoolpaymentgroup`
  ADD PRIMARY KEY (`id`) USING BTREE;

ALTER TABLE `schoolpaymentpackage`
  ADD PRIMARY KEY (`id`) USING BTREE;

ALTER TABLE `schoolpaymentpackagedetail`
  ADD PRIMARY KEY (`id`) USING BTREE,
  ADD KEY `FK_schoolpaymentpackagedetail_schoolpaymentpackage` (`schoolpaymentpackage`) USING BTREE,
  ADD KEY `FK_schoolpaymentpackagedetail_schoolpayment` (`schoolpayment`) USING BTREE;

ALTER TABLE `schoolperiod`
  ADD PRIMARY KEY (`id`) USING BTREE;

ALTER TABLE `schoolscoringtype`
  ADD PRIMARY KEY (`id`) USING BTREE;

ALTER TABLE `schoolscoringtyperange`
  ADD PRIMARY KEY (`id`) USING BTREE,
  ADD KEY `FK_schoolscoringtyperange_schoolscoringtype` (`schoolscoringtype`);

ALTER TABLE `schoolstudent`
  ADD PRIMARY KEY (`id`) USING BTREE,
  ADD KEY `FK_schoolstudent_schoolclass` (`schoolclass`),
  ADD KEY `FK_schoolstudent_schoolsubclass` (`schoolsubclass`),
  ADD KEY `FK_schoolstudent_schoolstudentstatus` (`status`),
  ADD KEY `FK_schoolstudent_schoolstudentdorm` (`dorm`) USING BTREE;

ALTER TABLE `schoolstudentdorm`
  ADD PRIMARY KEY (`id`) USING BTREE,
  ADD KEY `FK_schoolstudentdorm_schoolteacher` (`dormheadmaster`);

ALTER TABLE `schoolstudentpayment`
  ADD PRIMARY KEY (`id`) USING BTREE,
  ADD KEY `school` (`schoolstudent`) USING BTREE,
  ADD KEY `FK_schoolstudentpayment_schoolsubclass` (`schoolsubclass`) USING BTREE,
  ADD KEY `FK_schoolstudentpayment_division` (`division`) USING BTREE,
  ADD KEY `FK_schoolstudentpayment_paymenttype` (`paymenttype`);

ALTER TABLE `schoolstudentpaymentdetail`
  ADD PRIMARY KEY (`id`) USING BTREE,
  ADD KEY `school` (`schoolstudent`) USING BTREE,
  ADD KEY `FK_schoolstudentpaymentdetail_schoolpayment` (`schoolpayment`) USING BTREE,
  ADD KEY `FK_schoolstudentpaymentdetail_schoolsubclass` (`schoolsubclass`) USING BTREE,
  ADD KEY `FK_schoolstudentpaymentdetail_schoolstudentpayment` (`parent`);

ALTER TABLE `schoolstudentpaymentschedule`
  ADD PRIMARY KEY (`id`) USING BTREE,
  ADD KEY `school` (`schoolstudent`) USING BTREE,
  ADD KEY `FK_schoolstudentpaymentschedule_schoolpaymentpackage` (`schoolpaymentpackage`) USING BTREE,
  ADD KEY `FK_schoolstudentpaymentschedule_schoolsubclass` (`schoolsubclass`) USING BTREE,
  ADD KEY `FK_schoolstudentpaymentschedule_division` (`division`);

ALTER TABLE `schoolstudentscore`
  ADD PRIMARY KEY (`id`) USING BTREE,
  ADD KEY `FK_schoolstudentscore_schoolsubclass` (`schoolsubclass`) USING BTREE,
  ADD KEY `FK_schoolstudentscore_schoollesson` (`schoollesson`) USING BTREE,
  ADD KEY `FK_schoolstudentscore_schoolteacher` (`schoolteacher`) USING BTREE,
  ADD KEY `FK_schoolstudentscore_schoolperiod` (`schoolperiod`),
  ADD KEY `FK_schoolstudentscore_schoolscoringtype` (`scoringtype`),
  ADD KEY `FK_schoolstudentscore_schoolexam` (`schoolexam`);

ALTER TABLE `schoolstudentscoredetail`
  ADD PRIMARY KEY (`id`) USING BTREE,
  ADD KEY `FK_schoolstudentscoredetail_schoolsubclass` (`schoolsubclass`) USING BTREE,
  ADD KEY `FK_schoolstudentscoredetail_schoollesson` (`schoollesson`) USING BTREE,
  ADD KEY `FK_schoolstudentscoredetail_schoolteacher` (`schoolteacher`) USING BTREE,
  ADD KEY `FK_schoolstudentscoredetail_schoolstudent` (`schoolstudent`) USING BTREE,
  ADD KEY `FK_schoolstudentscoredetail_schoolperiod` (`schoolperiod`) USING BTREE,
  ADD KEY `FK_schoolstudentscoredetail_scoringtype` (`scoringtype`) USING BTREE,
  ADD KEY `FK_schoolstudentscoredetail_schoolexam` (`schoolexam`),
  ADD KEY `FK_schoolstudentscoredetail_schoolstudentscore` (`schoolstudentscore`);

ALTER TABLE `schoolstudentsextrascore`
  ADD PRIMARY KEY (`id`) USING BTREE,
  ADD KEY `FK_schoolstudentsextrascore_schoolsubclass` (`schoolsubclass`) USING BTREE,
  ADD KEY `FK_schoolstudentsextrascore_schoolextrascore` (`schoolextrascore`) USING BTREE,
  ADD KEY `FK_schoolstudentsextrascore_schoolextrascoregroup` (`schoolextrascoregroup`) USING BTREE,
  ADD KEY `FK_schoolstudentsextrascore_schoolteacher` (`schoolteacher`) USING BTREE,
  ADD KEY `FK_schoolstudentsextrascore_schoolperiod` (`schoolperiod`),
  ADD KEY `FK_schoolstudentsextrascore_schoolscoringtype` (`scoringtype`),
  ADD KEY `FK_schoolstudentsextrascore_schoolexam` (`schoolexam`);

ALTER TABLE `schoolstudentsextrascoredetail`
  ADD PRIMARY KEY (`id`) USING BTREE,
  ADD KEY `FK_schoolstudentsextrascoredetail_schoolsubclass` (`schoolsubclass`) USING BTREE,
  ADD KEY `FK_schoolstudentsextrascoredetail_schoolextrascore` (`schoolextrascore`) USING BTREE,
  ADD KEY `FK_schoolstudentsextrascoredetail_schoolteacher` (`schoolteacher`) USING BTREE,
  ADD KEY `FK_schoolstudentsextrascoredetail_schoolstudent` (`schoolstudent`) USING BTREE,
  ADD KEY `FK_schoolstudentsextrascoredetail_schoolperiod` (`schoolperiod`) USING BTREE,
  ADD KEY `FK_schoolstudentsextrascoredetail_scoringtype` (`scoringtype`) USING BTREE,
  ADD KEY `FK_schoolstudentsextrascoredetail_schoolexam` (`schoolexam`),
  ADD KEY `FK_schoolstudentsextrascoredetail_schoolstudentsextrascore` (`schoolstudentsextrascore`);

ALTER TABLE `schoolstudentstatus`
  ADD PRIMARY KEY (`id`) USING BTREE;

ALTER TABLE `schoolstupaymentscheduledetail`
  ADD PRIMARY KEY (`id`) USING BTREE,
  ADD KEY `school` (`schoolstudent`) USING BTREE,
  ADD KEY `FK_schoolstudentpayment_schoolpayment` (`schoolpayment`) USING BTREE,
  ADD KEY `FK_schoolstupaymentscheddetail_schoolsubclass` (`schoolsubclass`);

ALTER TABLE `schoolsubclass`
  ADD PRIMARY KEY (`id`) USING BTREE,
  ADD KEY `FK_schoolsubclass_schoolclass` (`schoolclass`),
  ADD KEY `FK_schoolsubclass_schoolteacher` (`homeroomteacher`);

ALTER TABLE `schoolteacher`
  ADD PRIMARY KEY (`id`) USING BTREE;

ALTER TABLE `servicedoer`
  ADD PRIMARY KEY (`id`),
  ADD KEY `servicedoergroup` (`servicedoergroup`),
  ADD KEY `payablecommacc` (`payablecommacc`),
  ADD KEY `expensecommacc` (`expensecommacc`);

ALTER TABLE `servicedoercommperiod`
  ADD PRIMARY KEY (`id`),
  ADD KEY `servicedoercommperiod_ibfk_1` (`salaryid`),
  ADD KEY `servicedoercommperiod_ibfk_2` (`division`);

ALTER TABLE `servicedoercommrules`
  ADD PRIMARY KEY (`id`);

ALTER TABLE `servicedoercommvar`
  ADD PRIMARY KEY (`varname`);

ALTER TABLE `servicedoercommvarrecords`
  ADD PRIMARY KEY (`transid`),
  ADD KEY `servicedoercommvarrecords_ibfk_1` (`periodid`);

ALTER TABLE `servicedoerdetail`
  ADD PRIMARY KEY (`groupid`,`servicedoerid`),
  ADD KEY `servicedoerid` (`servicedoerid`);

ALTER TABLE `servicedoergroup`
  ADD PRIMARY KEY (`id`),
  ADD KEY `payablecommacc` (`payablecommacc`),
  ADD KEY `expensecommacc` (`expensecommacc`);

ALTER TABLE `servicedoerrecorddetail`
  ADD PRIMARY KEY (`transid`),
  ADD KEY `servicedoerid` (`servicedoerid`),
  ADD KEY `productid` (`productid`),
  ADD KEY `servicedoerrecorddetail_ibfk_3` (`periodid`);

ALTER TABLE `servicedoerrecords`
  ADD PRIMARY KEY (`id`),
  ADD KEY `servicedoerid` (`servicedoerid`),
  ADD KEY `servicedoerrecords_ibfk_2` (`periodid`);

ALTER TABLE `shipments`
  ADD PRIMARY KEY (`id`);

ALTER TABLE `slidedata`
  ADD PRIMARY KEY (`id`),
  ADD KEY `FK_slidedata_slide` (`slideid`) USING BTREE;

ALTER TABLE `slideelements`
  ADD PRIMARY KEY (`id`),
  ADD KEY `FK_slideelements_slidedata` (`slidedataid`);

ALTER TABLE `supplier`
  ADD PRIMARY KEY (`id`),
  ADD KEY `suppliergroup` (`suppliergroup`),
  ADD KEY `payableacc` (`payableacc`),
  ADD KEY `rewardacc` (`rewardacc`),
  ADD KEY `purchasediscacc` (`purchasediscacc`),
  ADD KEY `gainlosspayableacc` (`gainlosspayableacc`),
  ADD KEY `supplier_ibfk_6` (`accruedpayableacc`);

ALTER TABLE `supplierbalance`
  ADD PRIMARY KEY (`transid`) USING BTREE,
  ADD KEY `supplierid` (`supplierid`) USING BTREE,
  ADD KEY `FK_supplierbalance_division` (`division`);

ALTER TABLE `supplierdp`
  ADD PRIMARY KEY (`transid`),
  ADD KEY `division` (`division`),
  ADD KEY `supplierid` (`supplierid`),
  ADD KEY `paymenttype` (`paymenttype`),
  ADD KEY `downpaymenttype` (`downpaymenttype`);

ALTER TABLE `suppliergiro`
  ADD PRIMARY KEY (`id`),
  ADD KEY `supplierid` (`supplierid`),
  ADD KEY `division` (`division`),
  ADD KEY `paymenttype` (`paymenttype`);

ALTER TABLE `suppliergroup`
  ADD PRIMARY KEY (`id`),
  ADD KEY `payableacc` (`payableacc`),
  ADD KEY `rewardacc` (`rewardacc`),
  ADD KEY `purchasediscacc` (`purchasediscacc`),
  ADD KEY `gainlosspayableacc` (`gainlosspayableacc`),
  ADD KEY `suppliergroup_ibfk_6` (`accruedpayableacc`);

ALTER TABLE `tableroles`
  ADD PRIMARY KEY (`id`),
  ADD KEY `FK_tableroles_roles` (`roles`);

ALTER TABLE `taxes`
  ADD PRIMARY KEY (`id`),
  ADD KEY `taxoutacc` (`taxoutacc`),
  ADD KEY `taxinacc` (`taxinacc`);

ALTER TABLE `themecolors`
  ADD PRIMARY KEY (`id`);

ALTER TABLE `trackemployee`
  ADD PRIMARY KEY (`id`) USING BTREE,
  ADD KEY `employeeid` (`employeeid`) USING BTREE,
  ADD KEY `FK_trackemployee_attendance` (`attendanceid`);

ALTER TABLE `trexpenses`
  ADD PRIMARY KEY (`id`);

ALTER TABLE `trproduct`
  ADD PRIMARY KEY (`id`);

ALTER TABLE `trrevenues`
  ADD PRIMARY KEY (`id`);

ALTER TABLE `units`
  ADD PRIMARY KEY (`id`),
  ADD KEY `productid` (`productid`);

ALTER TABLE `users`
  ADD PRIMARY KEY (`id`),
  ADD KEY `FK_users_roles` (`roles`);

ALTER TABLE `vehicle`
  ADD PRIMARY KEY (`id`),
  ADD UNIQUE KEY `uq_vehicle_platenumber` (`platenumber`),
  ADD KEY `idx_vehicle_modelid` (`modelid`),
  ADD KEY `idx_vehicle_division` (`division`),
  ADD KEY `idx_vehicle_departement` (`departement`),
  ADD KEY `idx_vehicle_defaultdriverid` (`defaultdriverid`),
  ADD KEY `idx_vehicle_fueltypeid` (`fueltypeid`);

ALTER TABLE `vehiclebrand`
  ADD PRIMARY KEY (`id`);

ALTER TABLE `vehicledocument`
  ADD PRIMARY KEY (`id`),
  ADD KEY `idx_vehicledocument_vehicleid` (`vehicleid`);

ALTER TABLE `vehiclefuellog`
  ADD PRIMARY KEY (`id`),
  ADD KEY `idx_vehiclefuellog_vehicleid` (`vehicleid`),
  ADD KEY `idx_vehiclefuellog_driverid` (`driverid`),
  ADD KEY `idx_vehiclefuellog_vendorid` (`vendorid`),
  ADD KEY `idx_vehiclefuellog_fueltypeid` (`fueltypeid`),
  ADD KEY `idx_vehiclefuellog_transdatetime` (`transdatetime`),
  ADD KEY `idx_vehiclefuellog_tripid` (`tripid`) USING BTREE,
  ADD KEY `idx_vehiclefuellog_division` (`division`) USING BTREE,
  ADD KEY `idx_vehiclefuellog_departement` (`departement`) USING BTREE;

ALTER TABLE `vehiclefueltype`
  ADD PRIMARY KEY (`id`),
  ADD KEY `FK_vehiclefueltype_product` (`productid`),
  ADD KEY `FK_vehiclefueltype_expenseacc` (`expenseacc`);

ALTER TABLE `vehiclemaintenance`
  ADD PRIMARY KEY (`id`),
  ADD KEY `idx_vehiclemaintenance_vehicleid` (`vehicleid`),
  ADD KEY `idx_vehiclemaintenance_categoryid` (`categoryid`),
  ADD KEY `idx_vehiclemaintenance_vendorid` (`vendorid`),
  ADD KEY `idx_vehiclemaintenance_requestedby` (`requestedby`),
  ADD KEY `idx_vehiclemaintenance_servicedatetime` (`servicedatetime`),
  ADD KEY `idx_vehiclemaintenance_division` (`division`),
  ADD KEY `idx_vehiclemaintenance_departement` (`departement`);

ALTER TABLE `vehiclemaintenancecategory`
  ADD PRIMARY KEY (`id`),
  ADD KEY `FK_vehiclemaintenancecategory_account` (`expenseacc`);

ALTER TABLE `vehiclemaintenancepart`
  ADD PRIMARY KEY (`id`),
  ADD KEY `idx_vehiclemaintenancepart_maintenanceid` (`maintenanceid`),
  ADD KEY `idx_vehiclemaintenancepart_productid` (`productid`);

ALTER TABLE `vehiclemodel`
  ADD PRIMARY KEY (`id`),
  ADD KEY `idx_vehiclemodel_brandid` (`brandid`),
  ADD KEY `idx_vehiclemodel_defaultfueltypeid` (`defaultfueltypeid`),
  ADD KEY `idx_vehiclemodel_vehicletypeid` (`vehicletypeid`);

ALTER TABLE `vehicleroute`
  ADD PRIMARY KEY (`id`);

ALTER TABLE `vehicletrip`
  ADD PRIMARY KEY (`id`),
  ADD KEY `idx_vehicletrip_vehicleid` (`vehicleid`),
  ADD KEY `idx_vehicletrip_driverid` (`driverid`),
  ADD KEY `idx_vehicletrip_tripdate` (`transdate`),
  ADD KEY `idx_vehicletrip_routeid` (`routeid`),
  ADD KEY `idx_vehicletrip_fueltypeid` (`fueltypeid`) USING BTREE,
  ADD KEY `idx_vehicletrip_division` (`division`),
  ADD KEY `idx_vehicletrip_departement` (`departement`);

ALTER TABLE `vehicletype`
  ADD PRIMARY KEY (`id`);

ALTER TABLE `version`
  ADD PRIMARY KEY (`id`);

ALTER TABLE `virtualtrans`
  ADD PRIMARY KEY (`id`) USING BTREE;

ALTER TABLE `workinghours`
  ADD PRIMARY KEY (`id`);


ALTER TABLE `address`
  MODIFY `id` bigint(20) UNSIGNED NOT NULL AUTO_INCREMENT;

ALTER TABLE `attendance`
  MODIFY `id` bigint(20) UNSIGNED NOT NULL AUTO_INCREMENT;

ALTER TABLE `attendancekioskdevice`
  MODIFY `id` bigint(20) UNSIGNED NOT NULL AUTO_INCREMENT, AUTO_INCREMENT=2;

ALTER TABLE `attendanceverifylog`
  MODIFY `id` bigint(20) UNSIGNED NOT NULL AUTO_INCREMENT;

ALTER TABLE `authorityrequest`
  MODIFY `id` bigint(20) UNSIGNED NOT NULL AUTO_INCREMENT;

ALTER TABLE `cogs`
  MODIFY `id` bigint(20) UNSIGNED NOT NULL AUTO_INCREMENT;

ALTER TABLE `customerbalance`
  MODIFY `transid` bigint(20) UNSIGNED NOT NULL AUTO_INCREMENT;

ALTER TABLE `customerdisplay`
  MODIFY `id` int(11) NOT NULL AUTO_INCREMENT, AUTO_INCREMENT=2;

ALTER TABLE `customergiro`
  MODIFY `id` bigint(20) UNSIGNED NOT NULL AUTO_INCREMENT;

ALTER TABLE `customernote`
  MODIFY `transid` bigint(20) UNSIGNED NOT NULL AUTO_INCREMENT;

ALTER TABLE `deliveryorderdetail`
  MODIFY `transid` bigint(20) UNSIGNED NOT NULL AUTO_INCREMENT;

ALTER TABLE `deliveryorderrewarddetail`
  MODIFY `transid` bigint(20) UNSIGNED NOT NULL AUTO_INCREMENT;

ALTER TABLE `depreciationrecords`
  MODIFY `transid` bigint(20) UNSIGNED NOT NULL AUTO_INCREMENT;

ALTER TABLE `employeeface`
  MODIFY `id` bigint(20) UNSIGNED NOT NULL AUTO_INCREMENT;

ALTER TABLE `employeefaceenrollment`
  MODIFY `id` bigint(20) UNSIGNED NOT NULL AUTO_INCREMENT;

ALTER TABLE `employeesalaries`
  MODIFY `id` bigint(20) UNSIGNED NOT NULL AUTO_INCREMENT;

ALTER TABLE `excratehistories`
  MODIFY `transid` bigint(20) UNSIGNED NOT NULL AUTO_INCREMENT;

ALTER TABLE `filteroperands`
  MODIFY `id` int(11) NOT NULL AUTO_INCREMENT, AUTO_INCREMENT=33;

ALTER TABLE `fixedassetdepreciation`
  MODIFY `transid` bigint(20) UNSIGNED NOT NULL AUTO_INCREMENT;

ALTER TABLE `fixedassetdispose`
  MODIFY `transid` bigint(20) UNSIGNED NOT NULL AUTO_INCREMENT;

ALTER TABLE `goodsreceiptdetail`
  MODIFY `transid` bigint(20) UNSIGNED NOT NULL AUTO_INCREMENT;

ALTER TABLE `goodsreceiptrewarddetail`
  MODIFY `transid` bigint(20) UNSIGNED NOT NULL AUTO_INCREMENT;

ALTER TABLE `inventory`
  MODIFY `id` bigint(20) UNSIGNED NOT NULL AUTO_INCREMENT;

ALTER TABLE `inventoryadjustdetail`
  MODIFY `id` bigint(20) UNSIGNED NOT NULL AUTO_INCREMENT;

ALTER TABLE `inventoryindetail`
  MODIFY `id` bigint(20) UNSIGNED NOT NULL AUTO_INCREMENT;

ALTER TABLE `inventorymovingdetail`
  MODIFY `id` bigint(20) UNSIGNED NOT NULL AUTO_INCREMENT;

ALTER TABLE `inventoryoutdetail`
  MODIFY `id` bigint(20) UNSIGNED NOT NULL AUTO_INCREMENT;

ALTER TABLE `journalexpensedetail`
  MODIFY `id` bigint(20) UNSIGNED NOT NULL AUTO_INCREMENT;

ALTER TABLE `journalrevenuedetail`
  MODIFY `id` bigint(20) UNSIGNED NOT NULL AUTO_INCREMENT;

ALTER TABLE `journaltrans`
  MODIFY `id` bigint(20) UNSIGNED NOT NULL AUTO_INCREMENT;

ALTER TABLE `langoverrides`
  MODIFY `id` bigint(20) UNSIGNED NOT NULL AUTO_INCREMENT;

ALTER TABLE `logtransactions`
  MODIFY `id` bigint(20) UNSIGNED NOT NULL AUTO_INCREMENT;

ALTER TABLE `mrpbomcomponent`
  MODIFY `id` bigint(20) UNSIGNED NOT NULL AUTO_INCREMENT;

ALTER TABLE `mrpbomoperation`
  MODIFY `id` bigint(20) UNSIGNED NOT NULL AUTO_INCREMENT;

ALTER TABLE `mrpoperation`
  MODIFY `id` bigint(20) UNSIGNED NOT NULL AUTO_INCREMENT;

ALTER TABLE `mrpordercomponent`
  MODIFY `id` bigint(20) UNSIGNED NOT NULL AUTO_INCREMENT;

ALTER TABLE `mrpworkcenter`
  MODIFY `id` bigint(20) UNSIGNED NOT NULL AUTO_INCREMENT;

ALTER TABLE `mrpworkorder`
  MODIFY `id` bigint(20) UNSIGNED NOT NULL AUTO_INCREMENT;

ALTER TABLE `mrpworkorderemployee`
  MODIFY `id` bigint(20) UNSIGNED NOT NULL AUTO_INCREMENT;

ALTER TABLE `onlinepayments`
  MODIFY `id` int(11) NOT NULL AUTO_INCREMENT;

ALTER TABLE `pointofsales`
  MODIFY `id` bigint(20) UNSIGNED NOT NULL AUTO_INCREMENT;

ALTER TABLE `poshistories`
  MODIFY `id` bigint(20) UNSIGNED NOT NULL AUTO_INCREMENT;

ALTER TABLE `posprintcashier`
  MODIFY `id` bigint(20) UNSIGNED NOT NULL AUTO_INCREMENT, AUTO_INCREMENT=2;

ALTER TABLE `posprintorder`
  MODIFY `id` bigint(20) UNSIGNED NOT NULL AUTO_INCREMENT, AUTO_INCREMENT=2;

ALTER TABLE `postable`
  MODIFY `id` int(11) NOT NULL AUTO_INCREMENT;

ALTER TABLE `postablegroup`
  MODIFY `id` bigint(20) UNSIGNED NOT NULL AUTO_INCREMENT;

ALTER TABLE `productassembledetail`
  MODIFY `id` bigint(20) UNSIGNED NOT NULL AUTO_INCREMENT;

ALTER TABLE `productdisassembledetail`
  MODIFY `id` bigint(20) UNSIGNED NOT NULL AUTO_INCREMENT;

ALTER TABLE `productpackage`
  MODIFY `transid` bigint(20) UNSIGNED NOT NULL AUTO_INCREMENT;

ALTER TABLE `productsalesvariant`
  MODIFY `id` bigint(20) UNSIGNED NOT NULL AUTO_INCREMENT;

ALTER TABLE `purchasedetail`
  MODIFY `transid` bigint(20) UNSIGNED NOT NULL AUTO_INCREMENT;

ALTER TABLE `purchaseexpensesdetail`
  MODIFY `transid` bigint(20) UNSIGNED NOT NULL AUTO_INCREMENT;

ALTER TABLE `purchaseextratax`
  MODIFY `transid` bigint(20) UNSIGNED NOT NULL AUTO_INCREMENT;

ALTER TABLE `purchaseorderdetail`
  MODIFY `transid` bigint(20) UNSIGNED NOT NULL AUTO_INCREMENT;

ALTER TABLE `purchaseorderexpensesdetail`
  MODIFY `transid` bigint(20) UNSIGNED NOT NULL AUTO_INCREMENT;

ALTER TABLE `purchaseorderextratax`
  MODIFY `transid` bigint(20) UNSIGNED NOT NULL AUTO_INCREMENT;

ALTER TABLE `purchaseorderpayments`
  MODIFY `transid` bigint(20) UNSIGNED NOT NULL AUTO_INCREMENT;

ALTER TABLE `purchaseorderpoint`
  MODIFY `transid` bigint(20) UNSIGNED NOT NULL AUTO_INCREMENT;

ALTER TABLE `purchaseorderrewarddetail`
  MODIFY `transid` bigint(20) UNSIGNED NOT NULL AUTO_INCREMENT;

ALTER TABLE `purchasepayments`
  MODIFY `transid` bigint(20) UNSIGNED NOT NULL AUTO_INCREMENT;

ALTER TABLE `purchasepoint`
  MODIFY `transid` bigint(20) UNSIGNED NOT NULL AUTO_INCREMENT;

ALTER TABLE `purchaserequisitiondetail`
  MODIFY `transid` bigint(20) UNSIGNED NOT NULL AUTO_INCREMENT, AUTO_INCREMENT=5;

ALTER TABLE `purchaserewarddetail`
  MODIFY `transid` bigint(20) UNSIGNED NOT NULL AUTO_INCREMENT;

ALTER TABLE `religions`
  MODIFY `id` int(10) UNSIGNED NOT NULL AUTO_INCREMENT;

ALTER TABLE `rentalreturndetail`
  MODIFY `transid` bigint(20) UNSIGNED NOT NULL AUTO_INCREMENT;

ALTER TABLE `salariesrecord`
  MODIFY `transid` bigint(20) UNSIGNED NOT NULL AUTO_INCREMENT;

ALTER TABLE `salaryperioddetail`
  MODIFY `transid` bigint(20) UNSIGNED NOT NULL AUTO_INCREMENT;

ALTER TABLE `salarystructuredetail`
  MODIFY `id` bigint(20) UNSIGNED NOT NULL AUTO_INCREMENT;

ALTER TABLE `salesdetail`
  MODIFY `transid` bigint(20) UNSIGNED NOT NULL AUTO_INCREMENT;

ALTER TABLE `salesexpensesdetail`
  MODIFY `transid` bigint(20) UNSIGNED NOT NULL AUTO_INCREMENT;

ALTER TABLE `salesextratax`
  MODIFY `transid` bigint(20) UNSIGNED NOT NULL AUTO_INCREMENT;

ALTER TABLE `salesmancommvarrecords`
  MODIFY `transid` bigint(20) UNSIGNED NOT NULL AUTO_INCREMENT;

ALTER TABLE `salesmanrecorddetail`
  MODIFY `transid` bigint(20) UNSIGNED NOT NULL AUTO_INCREMENT;

ALTER TABLE `salesmanrecords`
  MODIFY `id` bigint(20) UNSIGNED NOT NULL AUTO_INCREMENT;

ALTER TABLE `salesorderdetail`
  MODIFY `transid` bigint(20) UNSIGNED NOT NULL AUTO_INCREMENT;

ALTER TABLE `salesorderexpensesdetail`
  MODIFY `transid` bigint(20) UNSIGNED NOT NULL AUTO_INCREMENT;

ALTER TABLE `salesorderextratax`
  MODIFY `transid` bigint(20) UNSIGNED NOT NULL AUTO_INCREMENT;

ALTER TABLE `salesorderpayments`
  MODIFY `transid` bigint(20) UNSIGNED NOT NULL AUTO_INCREMENT;

ALTER TABLE `salesorderpoint`
  MODIFY `transid` bigint(20) UNSIGNED NOT NULL AUTO_INCREMENT;

ALTER TABLE `salesorderrewarddetail`
  MODIFY `transid` bigint(20) UNSIGNED NOT NULL AUTO_INCREMENT;

ALTER TABLE `salespayments`
  MODIFY `transid` bigint(20) UNSIGNED NOT NULL AUTO_INCREMENT;

ALTER TABLE `salespoint`
  MODIFY `transid` bigint(20) UNSIGNED NOT NULL AUTO_INCREMENT;

ALTER TABLE `salesrewarddetail`
  MODIFY `transid` bigint(20) UNSIGNED NOT NULL AUTO_INCREMENT;

ALTER TABLE `schoollessonclass`
  MODIFY `id` bigint(20) NOT NULL AUTO_INCREMENT;

ALTER TABLE `schoollessonteacher`
  MODIFY `id` bigint(20) NOT NULL AUTO_INCREMENT;

ALTER TABLE `schoolpaymentpackage`
  MODIFY `id` bigint(20) NOT NULL AUTO_INCREMENT;

ALTER TABLE `schoolpaymentpackagedetail`
  MODIFY `id` bigint(20) NOT NULL AUTO_INCREMENT;

ALTER TABLE `schoolscoringtype`
  MODIFY `id` bigint(20) NOT NULL AUTO_INCREMENT, AUTO_INCREMENT=2;

ALTER TABLE `schoolscoringtyperange`
  MODIFY `id` bigint(20) NOT NULL AUTO_INCREMENT;

ALTER TABLE `schoolstudentdorm`
  MODIFY `id` bigint(20) NOT NULL AUTO_INCREMENT, AUTO_INCREMENT=2;

ALTER TABLE `schoolstudentpayment`
  MODIFY `id` bigint(20) NOT NULL AUTO_INCREMENT;

ALTER TABLE `schoolstudentpaymentdetail`
  MODIFY `id` bigint(20) NOT NULL AUTO_INCREMENT;

ALTER TABLE `schoolstudentpaymentschedule`
  MODIFY `id` bigint(20) NOT NULL AUTO_INCREMENT;

ALTER TABLE `schoolstudentscore`
  MODIFY `id` bigint(20) NOT NULL AUTO_INCREMENT;

ALTER TABLE `schoolstudentscoredetail`
  MODIFY `id` bigint(20) NOT NULL AUTO_INCREMENT;

ALTER TABLE `schoolstudentsextrascore`
  MODIFY `id` bigint(20) NOT NULL AUTO_INCREMENT, AUTO_INCREMENT=3;

ALTER TABLE `schoolstudentsextrascoredetail`
  MODIFY `id` bigint(20) NOT NULL AUTO_INCREMENT, AUTO_INCREMENT=5;

ALTER TABLE `schoolstudentstatus`
  MODIFY `id` bigint(20) NOT NULL AUTO_INCREMENT, AUTO_INCREMENT=5;

ALTER TABLE `schoolstupaymentscheduledetail`
  MODIFY `id` bigint(20) NOT NULL AUTO_INCREMENT;

ALTER TABLE `servicedoercommvarrecords`
  MODIFY `transid` bigint(20) UNSIGNED NOT NULL AUTO_INCREMENT;

ALTER TABLE `servicedoerrecorddetail`
  MODIFY `transid` bigint(20) UNSIGNED NOT NULL AUTO_INCREMENT;

ALTER TABLE `servicedoerrecords`
  MODIFY `id` bigint(20) UNSIGNED NOT NULL AUTO_INCREMENT;

ALTER TABLE `slidedata`
  MODIFY `id` bigint(20) NOT NULL AUTO_INCREMENT, AUTO_INCREMENT=3;

ALTER TABLE `slideelements`
  MODIFY `id` bigint(20) NOT NULL AUTO_INCREMENT, AUTO_INCREMENT=2;

ALTER TABLE `supplierbalance`
  MODIFY `transid` bigint(20) UNSIGNED NOT NULL AUTO_INCREMENT;

ALTER TABLE `suppliergiro`
  MODIFY `id` bigint(20) UNSIGNED NOT NULL AUTO_INCREMENT;

ALTER TABLE `tableroles`
  MODIFY `id` bigint(20) NOT NULL AUTO_INCREMENT;

ALTER TABLE `themecolors`
  MODIFY `id` bigint(20) UNSIGNED NOT NULL AUTO_INCREMENT, AUTO_INCREMENT=10;

ALTER TABLE `trackemployee`
  MODIFY `id` bigint(20) UNSIGNED NOT NULL AUTO_INCREMENT;

ALTER TABLE `trexpenses`
  MODIFY `id` bigint(20) UNSIGNED NOT NULL AUTO_INCREMENT;

ALTER TABLE `trproduct`
  MODIFY `id` bigint(20) UNSIGNED NOT NULL AUTO_INCREMENT;

ALTER TABLE `trrevenues`
  MODIFY `id` bigint(20) UNSIGNED NOT NULL AUTO_INCREMENT;

ALTER TABLE `units`
  MODIFY `id` bigint(20) UNSIGNED NOT NULL AUTO_INCREMENT;

ALTER TABLE `vehicle`
  MODIFY `id` bigint(20) UNSIGNED NOT NULL AUTO_INCREMENT, AUTO_INCREMENT=5;

ALTER TABLE `vehiclebrand`
  MODIFY `id` bigint(20) UNSIGNED NOT NULL AUTO_INCREMENT, AUTO_INCREMENT=29;

ALTER TABLE `vehicledocument`
  MODIFY `id` bigint(20) UNSIGNED NOT NULL AUTO_INCREMENT;

ALTER TABLE `vehiclefuellog`
  MODIFY `id` bigint(20) UNSIGNED NOT NULL AUTO_INCREMENT, AUTO_INCREMENT=7;

ALTER TABLE `vehiclemaintenancecategory`
  MODIFY `id` bigint(20) UNSIGNED NOT NULL AUTO_INCREMENT, AUTO_INCREMENT=9;

ALTER TABLE `vehiclemaintenancepart`
  MODIFY `id` bigint(20) UNSIGNED NOT NULL AUTO_INCREMENT;

ALTER TABLE `vehiclemodel`
  MODIFY `id` bigint(20) UNSIGNED NOT NULL AUTO_INCREMENT;

ALTER TABLE `vehicleroute`
  MODIFY `id` bigint(20) UNSIGNED NOT NULL AUTO_INCREMENT;

ALTER TABLE `vehicletype`
  MODIFY `id` bigint(20) UNSIGNED NOT NULL AUTO_INCREMENT, AUTO_INCREMENT=9;

ALTER TABLE `version`
  MODIFY `id` bigint(20) UNSIGNED NOT NULL AUTO_INCREMENT, AUTO_INCREMENT=2;

ALTER TABLE `virtualtrans`
  MODIFY `id` int(11) NOT NULL AUTO_INCREMENT;

ALTER TABLE `workinghours`
  MODIFY `id` bigint(20) NOT NULL AUTO_INCREMENT;
DROP TABLE IF EXISTS `vw_salesdiscrules`;

CREATE ALGORITHM=UNDEFINED SQL SECURITY DEFINER VIEW `vw_salesdiscrules`  AS SELECT '0' AS `key_type`, concat('product.',`information_schema`.`columns`.`COLUMN_NAME`) AS `value`, concat('product.',`information_schema`.`columns`.`COLUMN_NAME`) AS `label` FROM `information_schema`.`columns` WHERE `information_schema`.`columns`.`TABLE_SCHEMA` = database() AND `information_schema`.`columns`.`TABLE_NAME` = 'product'union all select '0' AS `key_type`,concat('customer.',`information_schema`.`columns`.`COLUMN_NAME`) AS `value`,concat('customer.',`information_schema`.`columns`.`COLUMN_NAME`) AS `label` from `information_schema`.`columns` where `information_schema`.`columns`.`TABLE_SCHEMA` = database() and `information_schema`.`columns`.`TABLE_NAME` = 'customer' union all select '0' AS `key_type`,concat('salesman.',`information_schema`.`columns`.`COLUMN_NAME`) AS `value`,concat('salesman.',`information_schema`.`columns`.`COLUMN_NAME`) AS `label` from `information_schema`.`columns` where `information_schema`.`columns`.`TABLE_SCHEMA` = database() and `information_schema`.`columns`.`TABLE_NAME` = 'salesman' union all select '0' AS `key_type`,concat('unit.',`information_schema`.`columns`.`COLUMN_NAME`) AS `value`,concat('unit.',`information_schema`.`columns`.`COLUMN_NAME`) AS `label` from `information_schema`.`columns` where `information_schema`.`columns`.`TABLE_SCHEMA` = database() and `information_schema`.`columns`.`TABLE_NAME` = 'units' union all select '0' AS `key_type`,concat('detail.',`information_schema`.`columns`.`COLUMN_NAME`) AS `value`,concat('detail.',`information_schema`.`columns`.`COLUMN_NAME`) AS `label` from `information_schema`.`columns` where `information_schema`.`columns`.`TABLE_SCHEMA` = database() and `information_schema`.`columns`.`TABLE_NAME` = 'salesdetail' union all select '0' AS `key_type`,'salestotal' AS `value`,'salestotal' AS `label` union all select '1' AS `key_type`,concat('customer.',`information_schema`.`columns`.`COLUMN_NAME`) AS `value`,concat('customer.',`information_schema`.`columns`.`COLUMN_NAME`) AS `label` from `information_schema`.`columns` where `information_schema`.`columns`.`TABLE_SCHEMA` = database() and `information_schema`.`columns`.`TABLE_NAME` = 'customer' union all select '1' AS `key_type`,concat('salesman.',`information_schema`.`columns`.`COLUMN_NAME`) AS `value`,concat('salesman.',`information_schema`.`columns`.`COLUMN_NAME`) AS `label` from `information_schema`.`columns` where `information_schema`.`columns`.`TABLE_SCHEMA` = database() and `information_schema`.`columns`.`TABLE_NAME` = 'salesman' union all select '1' AS `key_type`,concat('sales.',`information_schema`.`columns`.`COLUMN_NAME`) AS `value`,concat('sales.',`information_schema`.`columns`.`COLUMN_NAME`) AS `label` from `information_schema`.`columns` where `information_schema`.`columns`.`TABLE_SCHEMA` = database() and `information_schema`.`columns`.`TABLE_NAME` = 'sales' union all select '1' AS `key_type`,concat('detail.',`information_schema`.`columns`.`COLUMN_NAME`) AS `value`,concat('detail.',`information_schema`.`columns`.`COLUMN_NAME`) AS `label` from `information_schema`.`columns` where `information_schema`.`columns`.`TABLE_SCHEMA` = database() and `information_schema`.`columns`.`TABLE_NAME` = 'salesdetail' union all select '1' AS `key_type`,'salesgross' AS `value`,'salesgross' AS `label` union all select '1' AS `key_type`,'brandsummary.[Product brand ID]' AS `value`,'brandsummary.[Product brand ID]' AS `label` union all select '1' AS `key_type`,'suppliersummary.[Supplier ID]' AS `value`,'suppliersummary.[Supplier ID]' AS `label` union all select '1' AS `key_type`,'factorysummary.[Factory ID]' AS `value`,'factorysummary.[Factory ID]' AS `label` union all select '1' AS `key_type`,'productgroupsummary.[Product Group ID]' AS `value`,'productgroupsummary.[Product Group ID]' AS `label`  ;
DROP TABLE IF EXISTS `vw_salespointrewardrules`;

CREATE ALGORITHM=UNDEFINED SQL SECURITY DEFINER VIEW `vw_salespointrewardrules`  AS SELECT '0' AS `key_type`, concat('customer.',`information_schema`.`columns`.`COLUMN_NAME`) AS `value`, concat('customer.',`information_schema`.`columns`.`COLUMN_NAME`) AS `label` FROM `information_schema`.`columns` WHERE `information_schema`.`columns`.`TABLE_SCHEMA` = database() AND `information_schema`.`columns`.`TABLE_NAME` = 'customer'union all select '0' AS `key_type`,concat('salesman.',`information_schema`.`columns`.`COLUMN_NAME`) AS `value`,concat('salesman.',`information_schema`.`columns`.`COLUMN_NAME`) AS `label` from `information_schema`.`columns` where `information_schema`.`columns`.`TABLE_SCHEMA` = database() and `information_schema`.`columns`.`TABLE_NAME` = 'salesman' union all select '0' AS `key_type`,concat('sales.',`information_schema`.`columns`.`COLUMN_NAME`) AS `value`,concat('sales.',`information_schema`.`columns`.`COLUMN_NAME`) AS `label` from `information_schema`.`columns` where `information_schema`.`columns`.`TABLE_SCHEMA` = database() and `information_schema`.`columns`.`TABLE_NAME` = 'sales' union all select '0' AS `key_type`,'salestotal' AS `value`,'salestotal' AS `label` union all select '0' AS `key_type`,'brandsummary.[Product brand ID]' AS `value`,'brandsummary.[Product brand ID]' AS `label` union all select '0' AS `key_type`,'suppliersummary.[Supplier ID]' AS `value`,'suppliersummary.[Supplier ID]' AS `label` union all select '0' AS `key_type`,'factorysummary.[Factory ID]' AS `value`,'factorysummary.[Factory ID]' AS `label` union all select '0' AS `key_type`,'productgroupsummary.[Product Group ID]' AS `value`,'productgroupsummary.[Product Group ID]' AS `label` union all select '0' AS `key_type`,concat('detail.',`information_schema`.`columns`.`COLUMN_NAME`) AS `value`,concat('detail.',`information_schema`.`columns`.`COLUMN_NAME`) AS `label` from `information_schema`.`columns` where `information_schema`.`columns`.`TABLE_SCHEMA` = database() and `information_schema`.`columns`.`TABLE_NAME` = 'salesdetail' union all select '1' AS `key_type`,concat('customer.',`information_schema`.`columns`.`COLUMN_NAME`) AS `value`,concat('customer.',`information_schema`.`columns`.`COLUMN_NAME`) AS `label` from `information_schema`.`columns` where `information_schema`.`columns`.`TABLE_SCHEMA` = database() and `information_schema`.`columns`.`TABLE_NAME` = 'customer' union all select '1' AS `key_type`,concat('salesman.',`information_schema`.`columns`.`COLUMN_NAME`) AS `value`,concat('salesman.',`information_schema`.`columns`.`COLUMN_NAME`) AS `label` from `information_schema`.`columns` where `information_schema`.`columns`.`TABLE_SCHEMA` = database() and `information_schema`.`columns`.`TABLE_NAME` = 'salesman' union all select '1' AS `key_type`,concat('sales.',`information_schema`.`columns`.`COLUMN_NAME`) AS `value`,concat('sales.',`information_schema`.`columns`.`COLUMN_NAME`) AS `label` from `information_schema`.`columns` where `information_schema`.`columns`.`TABLE_SCHEMA` = database() and `information_schema`.`columns`.`TABLE_NAME` = 'sales' union all select '1' AS `key_type`,'salestotal' AS `value`,'salestotal' AS `label` union all select '1' AS `key_type`,'brandsummary.[Product brand ID]' AS `value`,'brandsummary.[Product brand ID]' AS `label` union all select '1' AS `key_type`,'suppliersummary.[Supplier ID]' AS `value`,'suppliersummary.[Supplier ID]' AS `label` union all select '1' AS `key_type`,'factorysummary.[Factory ID]' AS `value`,'factorysummary.[Factory ID]' AS `label` union all select '1' AS `key_type`,'productgroupsummary.[Product Group ID]' AS `value`,'productgroupsummary.[Product Group ID]' AS `label`  ;


ALTER TABLE `attendance`
  ADD CONSTRAINT `FK_attendance_employee` FOREIGN KEY (`employeeid`) REFERENCES `employee` (`id`) ON UPDATE CASCADE,
  ADD CONSTRAINT `attendance_ibfk_kioskdevice` FOREIGN KEY (`kioskdeviceid`) REFERENCES `attendancekioskdevice` (`id`) ON UPDATE CASCADE;

ALTER TABLE `attendanceverifylog`
  ADD CONSTRAINT `attendanceverifylog_ibfk_1` FOREIGN KEY (`employeeid`) REFERENCES `employee` (`id`) ON UPDATE CASCADE,
  ADD CONSTRAINT `attendanceverifylog_ibfk_2` FOREIGN KEY (`attendanceid`) REFERENCES `attendance` (`id`) ON UPDATE CASCADE,
  ADD CONSTRAINT `attendanceverifylog_ibfk_3` FOREIGN KEY (`kioskdeviceid`) REFERENCES `attendancekioskdevice` (`id`) ON UPDATE CASCADE;

ALTER TABLE `authorityrequest`
  ADD CONSTRAINT `FK_authorityrequest_1` FOREIGN KEY (`userid`) REFERENCES `users` (`id`) ON UPDATE CASCADE,
  ADD CONSTRAINT `FK_authorityrequest_2` FOREIGN KEY (`touserid`) REFERENCES `users` (`id`) ON UPDATE CASCADE;

ALTER TABLE `cogs`
  ADD CONSTRAINT `FK_cogs_division` FOREIGN KEY (`division`) REFERENCES `division` (`id`) ON UPDATE CASCADE,
  ADD CONSTRAINT `cogs_ibfk_1` FOREIGN KEY (`productid`) REFERENCES `product` (`id`) ON UPDATE CASCADE;

ALTER TABLE `company`
  ADD CONSTRAINT `company_ibfk_1` FOREIGN KEY (`inventorytransferaccount`) REFERENCES `account` (`id`) ON UPDATE CASCADE;

ALTER TABLE `customer`
  ADD CONSTRAINT `customer_ibfk_1` FOREIGN KEY (`customergroup`) REFERENCES `customergroup` (`id`) ON UPDATE CASCADE,
  ADD CONSTRAINT `customer_ibfk_2` FOREIGN KEY (`receivableacc`) REFERENCES `account` (`id`) ON UPDATE CASCADE,
  ADD CONSTRAINT `customer_ibfk_3` FOREIGN KEY (`rewardacc`) REFERENCES `account` (`id`) ON UPDATE CASCADE,
  ADD CONSTRAINT `customer_ibfk_4` FOREIGN KEY (`salesdiscacc`) REFERENCES `account` (`id`) ON UPDATE CASCADE,
  ADD CONSTRAINT `customer_ibfk_5` FOREIGN KEY (`gainlossreceivableacc`) REFERENCES `account` (`id`) ON UPDATE CASCADE,
  ADD CONSTRAINT `customer_ibfk_6` FOREIGN KEY (`defsalesmanid`) REFERENCES `salesman` (`id`) ON UPDATE CASCADE;

ALTER TABLE `customerbalance`
  ADD CONSTRAINT `FK_customerbalance_division` FOREIGN KEY (`division`) REFERENCES `division` (`id`) ON UPDATE CASCADE,
  ADD CONSTRAINT `customerbalance_ibfk_1` FOREIGN KEY (`customerid`) REFERENCES `customer` (`id`) ON UPDATE CASCADE;

ALTER TABLE `customerdp`
  ADD CONSTRAINT `customerdp_ibfk_1` FOREIGN KEY (`division`) REFERENCES `division` (`id`) ON UPDATE CASCADE,
  ADD CONSTRAINT `customerdp_ibfk_2` FOREIGN KEY (`customerid`) REFERENCES `customer` (`id`) ON UPDATE CASCADE,
  ADD CONSTRAINT `customerdp_ibfk_3` FOREIGN KEY (`paymenttype`) REFERENCES `paymenttype` (`id`) ON UPDATE CASCADE,
  ADD CONSTRAINT `customerdp_ibfk_4` FOREIGN KEY (`downpaymenttype`) REFERENCES `paymenttype` (`id`) ON UPDATE CASCADE;

ALTER TABLE `customergiro`
  ADD CONSTRAINT `customergiro_ibfk_1` FOREIGN KEY (`customerid`) REFERENCES `customer` (`id`) ON UPDATE CASCADE,
  ADD CONSTRAINT `customergiro_ibfk_2` FOREIGN KEY (`division`) REFERENCES `division` (`id`) ON UPDATE CASCADE,
  ADD CONSTRAINT `customergiro_ibfk_3` FOREIGN KEY (`paymenttype`) REFERENCES `paymenttype` (`id`) ON UPDATE CASCADE;

ALTER TABLE `customergroup`
  ADD CONSTRAINT `customergroup_ibfk_1` FOREIGN KEY (`receivableacc`) REFERENCES `account` (`id`) ON UPDATE CASCADE,
  ADD CONSTRAINT `customergroup_ibfk_3` FOREIGN KEY (`rewardacc`) REFERENCES `account` (`id`) ON UPDATE CASCADE,
  ADD CONSTRAINT `customergroup_ibfk_5` FOREIGN KEY (`salesdiscacc`) REFERENCES `account` (`id`) ON UPDATE CASCADE,
  ADD CONSTRAINT `customergroup_ibfk_6` FOREIGN KEY (`gainlossreceivableacc`) REFERENCES `account` (`id`) ON UPDATE CASCADE;

ALTER TABLE `customernote`
  ADD CONSTRAINT `customernote_ibfk_1` FOREIGN KEY (`division`) REFERENCES `division` (`id`) ON UPDATE CASCADE,
  ADD CONSTRAINT `customernote_ibfk_2` FOREIGN KEY (`customerid`) REFERENCES `customer` (`id`) ON UPDATE CASCADE,
  ADD CONSTRAINT `customernote_ibfk_3` FOREIGN KEY (`customernoteid`) REFERENCES `customernotes` (`id`) ON UPDATE CASCADE;

ALTER TABLE `deliveryorder`
  ADD CONSTRAINT `deliveryorder_ibfk_1` FOREIGN KEY (`division`) REFERENCES `division` (`id`) ON UPDATE CASCADE,
  ADD CONSTRAINT `deliveryorder_ibfk_2` FOREIGN KEY (`salesmanid`) REFERENCES `salesman` (`id`) ON UPDATE CASCADE,
  ADD CONSTRAINT `deliveryorder_ibfk_3` FOREIGN KEY (`customerid`) REFERENCES `customer` (`id`) ON UPDATE CASCADE,
  ADD CONSTRAINT `deliveryorder_ibfk_4` FOREIGN KEY (`shipment`) REFERENCES `shipments` (`id`) ON UPDATE CASCADE;

ALTER TABLE `deliveryorderdetail`
  ADD CONSTRAINT `deliveryorderdetail_ibfk_1` FOREIGN KEY (`salesid`) REFERENCES `deliveryorder` (`salesid`) ON UPDATE CASCADE,
  ADD CONSTRAINT `deliveryorderdetail_ibfk_2` FOREIGN KEY (`productid`) REFERENCES `product` (`id`) ON UPDATE CASCADE,
  ADD CONSTRAINT `deliveryorderdetail_ibfk_3` FOREIGN KEY (`departement`) REFERENCES `departement` (`id`) ON UPDATE CASCADE,
  ADD CONSTRAINT `deliveryorderdetail_ibfk_4` FOREIGN KEY (`salesidref`) REFERENCES `deliveryorder` (`salesid`) ON UPDATE CASCADE;

ALTER TABLE `deliveryorderrewarddetail`
  ADD CONSTRAINT `FK_deliveryorderrewarddetail_1` FOREIGN KEY (`salesid`) REFERENCES `deliveryorder` (`salesid`) ON UPDATE CASCADE,
  ADD CONSTRAINT `FK_deliveryorderrewarddetail_2` FOREIGN KEY (`salesidref`) REFERENCES `deliveryorder` (`salesid`) ON UPDATE CASCADE,
  ADD CONSTRAINT `FK_deliveryorderrewarddetail_3` FOREIGN KEY (`productid`) REFERENCES `product` (`id`) ON UPDATE CASCADE,
  ADD CONSTRAINT `FK_deliveryorderrewarddetail_4` FOREIGN KEY (`departement`) REFERENCES `departement` (`id`) ON UPDATE CASCADE;

ALTER TABLE `departement`
  ADD CONSTRAINT `FK_departement_1` FOREIGN KEY (`division`) REFERENCES `division` (`id`) ON UPDATE CASCADE;

ALTER TABLE `depreciationrecords`
  ADD CONSTRAINT `depreciationrecords_ibfk_1` FOREIGN KEY (`fixedassetid`) REFERENCES `fixedasset` (`id`) ON UPDATE CASCADE;

ALTER TABLE `division`
  ADD CONSTRAINT `FK_division_1` FOREIGN KEY (`retainedearningacc`) REFERENCES `account` (`id`) ON UPDATE CASCADE,
  ADD CONSTRAINT `FK_division_2` FOREIGN KEY (`exchangerateacc`) REFERENCES `account` (`id`) ON UPDATE CASCADE,
  ADD CONSTRAINT `FK_division_3` FOREIGN KEY (`profitlossdiffcashacc`) REFERENCES `account` (`id`) ON UPDATE CASCADE;

ALTER TABLE `employee`
  ADD CONSTRAINT `employee_ibfk_1` FOREIGN KEY (`employeegroup`) REFERENCES `employeegroup` (`id`) ON UPDATE CASCADE,
  ADD CONSTRAINT `employee_ibfk_2` FOREIGN KEY (`salarystructure`) REFERENCES `salarystructure` (`id`) ON UPDATE CASCADE,
  ADD CONSTRAINT `employee_ibfk_3` FOREIGN KEY (`taxtype`) REFERENCES `taxes` (`id`) ON UPDATE CASCADE;

ALTER TABLE `employeeface`
  ADD CONSTRAINT `employeeface_ibfk_1` FOREIGN KEY (`employeeid`) REFERENCES `employee` (`id`) ON UPDATE CASCADE;

ALTER TABLE `employeefaceenrollment`
  ADD CONSTRAINT `employeefaceenrollment_ibfk_1` FOREIGN KEY (`employeeid`) REFERENCES `employee` (`id`) ON UPDATE CASCADE;

ALTER TABLE `employeesalaries`
  ADD CONSTRAINT `employeesalaries_ibfk_1` FOREIGN KEY (`employeeid`) REFERENCES `employee` (`id`) ON UPDATE CASCADE,
  ADD CONSTRAINT `employeesalaries_ibfk_2` FOREIGN KEY (`salaryid`) REFERENCES `salaries` (`id`) ON UPDATE CASCADE;

ALTER TABLE `excratehistories`
  ADD CONSTRAINT `excratehistories_ibfk_1` FOREIGN KEY (`id`) REFERENCES `currencies` (`id`) ON UPDATE CASCADE;

ALTER TABLE `fixedasset`
  ADD CONSTRAINT `fixedasset_ibfk_1` FOREIGN KEY (`fagroup`) REFERENCES `fixedassetgroup` (`id`) ON UPDATE CASCADE,
  ADD CONSTRAINT `fixedasset_ibfk_2` FOREIGN KEY (`division`) REFERENCES `division` (`id`) ON UPDATE CASCADE,
  ADD CONSTRAINT `fixedasset_ibfk_3` FOREIGN KEY (`departement`) REFERENCES `departement` (`id`) ON UPDATE CASCADE,
  ADD CONSTRAINT `fixedasset_ibfk_4` FOREIGN KEY (`accountid`) REFERENCES `account` (`id`) ON UPDATE CASCADE;

ALTER TABLE `fixedassetdepreciation`
  ADD CONSTRAINT `fixedassetdepreciation_ibfk_1` FOREIGN KEY (`division`) REFERENCES `division` (`id`) ON UPDATE CASCADE;

ALTER TABLE `fixedassetdispose`
  ADD CONSTRAINT `fixedassetdispose_ibfk_1` FOREIGN KEY (`division`) REFERENCES `division` (`id`) ON UPDATE CASCADE,
  ADD CONSTRAINT `fixedassetdispose_ibfk_2` FOREIGN KEY (`departement`) REFERENCES `departement` (`id`) ON UPDATE CASCADE,
  ADD CONSTRAINT `fixedassetdispose_ibfk_3` FOREIGN KEY (`accountid`) REFERENCES `account` (`id`) ON UPDATE CASCADE;

ALTER TABLE `fixedassetgroup`
  ADD CONSTRAINT `fixedassetgroup_ibfk_1` FOREIGN KEY (`fixedassetacc`) REFERENCES `account` (`id`) ON UPDATE CASCADE,
  ADD CONSTRAINT `fixedassetgroup_ibfk_2` FOREIGN KEY (`depreciationacc`) REFERENCES `account` (`id`) ON UPDATE CASCADE,
  ADD CONSTRAINT `fixedassetgroup_ibfk_3` FOREIGN KEY (`expenseacc`) REFERENCES `account` (`id`) ON UPDATE CASCADE,
  ADD CONSTRAINT `fixedassetgroup_ibfk_4` FOREIGN KEY (`gainlostacc`) REFERENCES `account` (`id`) ON UPDATE CASCADE;

ALTER TABLE `goodsreceipt`
  ADD CONSTRAINT `goodsreceipt_ibfk_1` FOREIGN KEY (`division`) REFERENCES `division` (`id`) ON UPDATE CASCADE,
  ADD CONSTRAINT `goodsreceipt_ibfk_2` FOREIGN KEY (`purchaser`) REFERENCES `employee` (`id`) ON UPDATE CASCADE,
  ADD CONSTRAINT `goodsreceipt_ibfk_3` FOREIGN KEY (`supplierid`) REFERENCES `supplier` (`id`) ON UPDATE CASCADE,
  ADD CONSTRAINT `goodsreceipt_ibfk_4` FOREIGN KEY (`shipment`) REFERENCES `shipments` (`id`) ON UPDATE CASCADE;

ALTER TABLE `goodsreceiptdetail`
  ADD CONSTRAINT `goodsreceiptdetail_ibfk_1` FOREIGN KEY (`purchaseid`) REFERENCES `goodsreceipt` (`purchaseid`) ON UPDATE CASCADE,
  ADD CONSTRAINT `goodsreceiptdetail_ibfk_2` FOREIGN KEY (`productid`) REFERENCES `product` (`id`) ON UPDATE CASCADE,
  ADD CONSTRAINT `goodsreceiptdetail_ibfk_3` FOREIGN KEY (`departement`) REFERENCES `departement` (`id`) ON UPDATE CASCADE,
  ADD CONSTRAINT `goodsreceiptdetail_ibfk_4` FOREIGN KEY (`purchaseidref`) REFERENCES `goodsreceipt` (`purchaseid`) ON UPDATE CASCADE;

ALTER TABLE `goodsreceiptrewarddetail`
  ADD CONSTRAINT `FK_goodsreceiptrewarddetail_1` FOREIGN KEY (`purchaseid`) REFERENCES `goodsreceipt` (`purchaseid`) ON UPDATE CASCADE,
  ADD CONSTRAINT `FK_goodsreceiptrewarddetail_2` FOREIGN KEY (`purchaseidref`) REFERENCES `goodsreceipt` (`purchaseid`) ON UPDATE CASCADE,
  ADD CONSTRAINT `FK_goodsreceiptrewarddetail_3` FOREIGN KEY (`productid`) REFERENCES `product` (`id`) ON UPDATE CASCADE,
  ADD CONSTRAINT `FK_goodsreceiptrewarddetail_4` FOREIGN KEY (`departement`) REFERENCES `departement` (`id`) ON UPDATE CASCADE;

ALTER TABLE `inputpayablebal`
  ADD CONSTRAINT `inputpayablebal_ibfk_1` FOREIGN KEY (`division`) REFERENCES `division` (`id`) ON UPDATE CASCADE,
  ADD CONSTRAINT `inputpayablebal_ibfk_2` FOREIGN KEY (`accountid`) REFERENCES `account` (`id`) ON UPDATE CASCADE;

ALTER TABLE `inputreceivablebal`
  ADD CONSTRAINT `inputreceivablebal_ibfk_1` FOREIGN KEY (`division`) REFERENCES `division` (`id`) ON UPDATE CASCADE,
  ADD CONSTRAINT `inputreceivablebal_ibfk_2` FOREIGN KEY (`accountid`) REFERENCES `account` (`id`) ON UPDATE CASCADE;

ALTER TABLE `inventory`
  ADD CONSTRAINT `inventory_ibfk_1` FOREIGN KEY (`departement`) REFERENCES `departement` (`id`) ON UPDATE CASCADE,
  ADD CONSTRAINT `inventory_ibfk_2` FOREIGN KEY (`division`) REFERENCES `division` (`id`) ON UPDATE CASCADE,
  ADD CONSTRAINT `inventory_ibfk_3` FOREIGN KEY (`productid`) REFERENCES `product` (`id`) ON UPDATE CASCADE;

ALTER TABLE `inventoryadjust`
  ADD CONSTRAINT `FK_inventoryadjust_account` FOREIGN KEY (`accountid`) REFERENCES `account` (`id`) ON UPDATE CASCADE,
  ADD CONSTRAINT `FK_inventoryadjust_departement` FOREIGN KEY (`departement`) REFERENCES `departement` (`id`) ON UPDATE CASCADE,
  ADD CONSTRAINT `inventoryadjust_division` FOREIGN KEY (`division`) REFERENCES `division` (`id`) ON UPDATE CASCADE;

ALTER TABLE `inventoryadjustdetail`
  ADD CONSTRAINT `inventoryadjustdetail_ibfk_1` FOREIGN KEY (`productid`) REFERENCES `product` (`id`) ON UPDATE CASCADE,
  ADD CONSTRAINT `inventoryadjustdetail_ibfk_2` FOREIGN KEY (`transid`) REFERENCES `inventoryadjust` (`id`) ON UPDATE CASCADE;

ALTER TABLE `inventoryin`
  ADD CONSTRAINT `inventoryin_ibfk_1` FOREIGN KEY (`division`) REFERENCES `division` (`id`) ON UPDATE CASCADE,
  ADD CONSTRAINT `inventoryin_ibfk_2` FOREIGN KEY (`departement`) REFERENCES `departement` (`id`) ON UPDATE CASCADE,
  ADD CONSTRAINT `inventoryin_ibfk_3` FOREIGN KEY (`accountid`) REFERENCES `account` (`id`) ON UPDATE CASCADE;

ALTER TABLE `inventoryindetail`
  ADD CONSTRAINT `inventoryindetail_ibfk_1` FOREIGN KEY (`productid`) REFERENCES `product` (`id`) ON UPDATE CASCADE,
  ADD CONSTRAINT `inventoryindetail_ibfk_2` FOREIGN KEY (`transid`) REFERENCES `inventoryin` (`id`) ON UPDATE CASCADE;

ALTER TABLE `inventorymoving`
  ADD CONSTRAINT `inventorymoving_ibfk_1` FOREIGN KEY (`fromdivision`) REFERENCES `division` (`id`) ON UPDATE CASCADE,
  ADD CONSTRAINT `inventorymoving_ibfk_2` FOREIGN KEY (`fromdepartement`) REFERENCES `departement` (`id`) ON UPDATE CASCADE,
  ADD CONSTRAINT `inventorymoving_ibfk_3` FOREIGN KEY (`todivision`) REFERENCES `division` (`id`) ON UPDATE CASCADE,
  ADD CONSTRAINT `inventorymoving_ibfk_4` FOREIGN KEY (`todepartement`) REFERENCES `departement` (`id`) ON UPDATE CASCADE;

ALTER TABLE `inventorymovingdetail`
  ADD CONSTRAINT `inventorymovingdetail_ibfk_1` FOREIGN KEY (`productid`) REFERENCES `product` (`id`) ON UPDATE CASCADE,
  ADD CONSTRAINT `inventorymovingdetail_ibfk_2` FOREIGN KEY (`transid`) REFERENCES `inventorymoving` (`id`) ON UPDATE CASCADE;

ALTER TABLE `inventoryout`
  ADD CONSTRAINT `inventoryout_ibfk_1` FOREIGN KEY (`division`) REFERENCES `division` (`id`) ON UPDATE CASCADE,
  ADD CONSTRAINT `inventoryout_ibfk_2` FOREIGN KEY (`departement`) REFERENCES `departement` (`id`) ON UPDATE CASCADE,
  ADD CONSTRAINT `inventoryout_ibfk_3` FOREIGN KEY (`accountid`) REFERENCES `account` (`id`) ON UPDATE CASCADE;

ALTER TABLE `inventoryoutdetail`
  ADD CONSTRAINT `inventoryoutdetail_ibfk_1` FOREIGN KEY (`productid`) REFERENCES `product` (`id`) ON UPDATE CASCADE,
  ADD CONSTRAINT `inventoryoutdetail_ibfk_2` FOREIGN KEY (`transid`) REFERENCES `inventoryout` (`id`) ON UPDATE CASCADE;

ALTER TABLE `journal`
  ADD CONSTRAINT `journal_ibfk_1` FOREIGN KEY (`division`) REFERENCES `division` (`id`) ON UPDATE CASCADE;

ALTER TABLE `journalclose`
  ADD CONSTRAINT `journalclose_ibfk_1` FOREIGN KEY (`division`) REFERENCES `division` (`id`) ON UPDATE CASCADE,
  ADD CONSTRAINT `journalclose_ibfk_2` FOREIGN KEY (`accountid`) REFERENCES `account` (`id`) ON UPDATE CASCADE;

ALTER TABLE `journalexpense`
  ADD CONSTRAINT `journalexpense_ibfk_1` FOREIGN KEY (`division`) REFERENCES `division` (`id`) ON UPDATE CASCADE,
  ADD CONSTRAINT `journalexpense_ibfk_2` FOREIGN KEY (`paymenttype`) REFERENCES `paymenttype` (`id`) ON UPDATE CASCADE;

ALTER TABLE `journalexpensedetail`
  ADD CONSTRAINT `journalexpensedetail_ibfk_1` FOREIGN KEY (`accountid`) REFERENCES `account` (`id`) ON UPDATE CASCADE,
  ADD CONSTRAINT `journalexpensedetail_ibfk_2` FOREIGN KEY (`jtid`) REFERENCES `journalexpense` (`jtid`) ON UPDATE CASCADE;

ALTER TABLE `journalrevenue`
  ADD CONSTRAINT `journalrevenue_ibfk_1` FOREIGN KEY (`division`) REFERENCES `division` (`id`) ON UPDATE CASCADE,
  ADD CONSTRAINT `journalrevenue_ibfk_2` FOREIGN KEY (`paymenttype`) REFERENCES `paymenttype` (`id`) ON UPDATE CASCADE;

ALTER TABLE `journalrevenuedetail`
  ADD CONSTRAINT `journalrevenuedetail_ibfk_1` FOREIGN KEY (`accountid`) REFERENCES `account` (`id`) ON UPDATE CASCADE,
  ADD CONSTRAINT `journalrevenuedetail_ibfk_2` FOREIGN KEY (`jtid`) REFERENCES `journalrevenue` (`jtid`) ON UPDATE CASCADE;

ALTER TABLE `journaltrans`
  ADD CONSTRAINT `journaltrans_ibfk_1` FOREIGN KEY (`accountid`) REFERENCES `account` (`id`) ON UPDATE CASCADE,
  ADD CONSTRAINT `journaltrans_ibfk_2` FOREIGN KEY (`division`) REFERENCES `division` (`id`) ON UPDATE CASCADE;

ALTER TABLE `mrpbomcomponent`
  ADD CONSTRAINT `FK_mrpbomcomponent_product` FOREIGN KEY (`productid`) REFERENCES `product` (`id`) ON UPDATE CASCADE,
  ADD CONSTRAINT `FK_mrpbomcomponent_product_2` FOREIGN KEY (`mrpproduct`) REFERENCES `product` (`id`) ON UPDATE CASCADE;

ALTER TABLE `mrpbomoperation`
  ADD CONSTRAINT `FK_mrpbomoperation_mrpoperation` FOREIGN KEY (`operationid`) REFERENCES `mrpoperation` (`id`) ON UPDATE CASCADE,
  ADD CONSTRAINT `FK_mrpbomoperation_product` FOREIGN KEY (`mrpproduct`) REFERENCES `product` (`id`) ON UPDATE CASCADE;

ALTER TABLE `mrpoperation`
  ADD CONSTRAINT `FK_mrpoperation_mrpworkcenter` FOREIGN KEY (`workcenter`) REFERENCES `mrpworkcenter` (`id`) ON UPDATE CASCADE,
  ADD CONSTRAINT `FK_mrpoperation_wageaccount` FOREIGN KEY (`wageaccount`) REFERENCES `account` (`id`) ON UPDATE CASCADE;

ALTER TABLE `mrporder`
  ADD CONSTRAINT `FK_mrporder_departement` FOREIGN KEY (`departement`) REFERENCES `departement` (`id`) ON UPDATE CASCADE,
  ADD CONSTRAINT `FK_mrporder_division` FOREIGN KEY (`division`) REFERENCES `division` (`id`) ON UPDATE CASCADE,
  ADD CONSTRAINT `FK_mrporder_product` FOREIGN KEY (`productid`) REFERENCES `product` (`id`) ON UPDATE CASCADE;

ALTER TABLE `mrpordercomponent`
  ADD CONSTRAINT `FK_mrpordercomponent_mrporder` FOREIGN KEY (`mrporder`) REFERENCES `mrporder` (`transid`) ON UPDATE CASCADE,
  ADD CONSTRAINT `FK_mrpordercomponent_productid` FOREIGN KEY (`productid`) REFERENCES `product` (`id`) ON UPDATE CASCADE;

ALTER TABLE `mrpworkcenter`
  ADD CONSTRAINT `FK_mrpworkcenter_productiondepartement` FOREIGN KEY (`productiondepartement`) REFERENCES `departement` (`id`) ON UPDATE CASCADE,
  ADD CONSTRAINT `FK_mrpworkcenter_storedepartement` FOREIGN KEY (`storedepartement`) REFERENCES `departement` (`id`) ON UPDATE CASCADE;

ALTER TABLE `mrpworkorder`
  ADD CONSTRAINT `FK_mrpworkorder_mrpoperation` FOREIGN KEY (`operationid`) REFERENCES `mrpoperation` (`id`) ON UPDATE CASCADE,
  ADD CONSTRAINT `FK_mrpworkorder_mrporder` FOREIGN KEY (`mrporder`) REFERENCES `mrporder` (`transid`) ON UPDATE CASCADE;

ALTER TABLE `mrpworkorderemployee`
  ADD CONSTRAINT `FK_mrpworkorderemployee_employee` FOREIGN KEY (`employeeid`) REFERENCES `employee` (`id`) ON UPDATE CASCADE,
  ADD CONSTRAINT `FK_mrpworkorderemployee_mrpworkorder` FOREIGN KEY (`workorderid`) REFERENCES `mrpworkorder` (`id`) ON UPDATE CASCADE;

ALTER TABLE `payableadjust`
  ADD CONSTRAINT `payableadjust_ibfk_1` FOREIGN KEY (`division`) REFERENCES `division` (`id`) ON UPDATE CASCADE,
  ADD CONSTRAINT `payableadjust_ibfk_2` FOREIGN KEY (`supplierid`) REFERENCES `supplier` (`id`) ON UPDATE CASCADE,
  ADD CONSTRAINT `payableadjust_ibfk_3` FOREIGN KEY (`expensestype`) REFERENCES `purchaseexpenses` (`id`) ON UPDATE CASCADE;

ALTER TABLE `payablepayment`
  ADD CONSTRAINT `payablepayment_ibfk_1` FOREIGN KEY (`division`) REFERENCES `division` (`id`) ON UPDATE CASCADE,
  ADD CONSTRAINT `payablepayment_ibfk_2` FOREIGN KEY (`supplierid`) REFERENCES `supplier` (`id`) ON UPDATE CASCADE,
  ADD CONSTRAINT `payablepayment_ibfk_3` FOREIGN KEY (`paymenttype`) REFERENCES `paymenttype` (`id`) ON UPDATE CASCADE;

ALTER TABLE `paymenttype`
  ADD CONSTRAINT `paymenttype_ibfk_1` FOREIGN KEY (`paymentacc`) REFERENCES `account` (`id`) ON UPDATE CASCADE,
  ADD CONSTRAINT `paymenttype_ibfk_2` FOREIGN KEY (`cashdiscacc`) REFERENCES `account` (`id`) ON UPDATE CASCADE,
  ADD CONSTRAINT `paymenttype_ibfk_3` FOREIGN KEY (`expenseacc`) REFERENCES `account` (`id`) ON UPDATE CASCADE;

ALTER TABLE `pointofsales`
  ADD CONSTRAINT `FK_pointofsales_account` FOREIGN KEY (`sourcecash`) REFERENCES `account` (`id`) ON UPDATE CASCADE,
  ADD CONSTRAINT `FK_pointofsales_customer` FOREIGN KEY (`customerdefault`) REFERENCES `customer` (`id`) ON UPDATE CASCADE,
  ADD CONSTRAINT `FK_pointofsales_departement` FOREIGN KEY (`departement`) REFERENCES `departement` (`id`) ON UPDATE CASCADE,
  ADD CONSTRAINT `FK_pointofsales_division` FOREIGN KEY (`division`) REFERENCES `division` (`id`) ON UPDATE CASCADE,
  ADD CONSTRAINT `FK_pointofsales_paymenttype` FOREIGN KEY (`paymentdefault`) REFERENCES `paymenttype` (`id`) ON UPDATE CASCADE,
  ADD CONSTRAINT `FK_pointofsales_salesman` FOREIGN KEY (`salesmandefault`) REFERENCES `salesman` (`id`) ON UPDATE CASCADE,
  ADD CONSTRAINT `FK_pointofsales_servicedoer` FOREIGN KEY (`servicedoerdefault`) REFERENCES `servicedoer` (`id`) ON UPDATE CASCADE,
  ADD CONSTRAINT `FK_pointofsales_shipments` FOREIGN KEY (`shipment`) REFERENCES `shipments` (`id`) ON UPDATE CASCADE;

ALTER TABLE `poshistories`
  ADD CONSTRAINT `FK_poshistories_posid` FOREIGN KEY (`posid`) REFERENCES `pointofsales` (`id`) ON UPDATE CASCADE;

ALTER TABLE `postable`
  ADD CONSTRAINT `FK_postable_customer` FOREIGN KEY (`customerid`) REFERENCES `customer` (`id`) ON UPDATE CASCADE,
  ADD CONSTRAINT `FK_postable_postablegroup` FOREIGN KEY (`tablegroup`) REFERENCES `postablegroup` (`id`) ON UPDATE CASCADE;

ALTER TABLE `product`
  ADD CONSTRAINT `product_ibfk_1` FOREIGN KEY (`author`) REFERENCES `authors` (`id`) ON UPDATE CASCADE,
  ADD CONSTRAINT `product_ibfk_10` FOREIGN KEY (`supplier`) REFERENCES `supplier` (`id`) ON UPDATE CASCADE,
  ADD CONSTRAINT `product_ibfk_11` FOREIGN KEY (`productgroup`) REFERENCES `productgroup` (`id`) ON UPDATE CASCADE,
  ADD CONSTRAINT `product_ibfk_12` FOREIGN KEY (`taxtype`) REFERENCES `taxes` (`id`) ON UPDATE CASCADE,
  ADD CONSTRAINT `product_ibfk_13` FOREIGN KEY (`cogsacc`) REFERENCES `account` (`id`) ON UPDATE CASCADE,
  ADD CONSTRAINT `product_ibfk_14` FOREIGN KEY (`inventoryacc`) REFERENCES `account` (`id`) ON UPDATE CASCADE,
  ADD CONSTRAINT `product_ibfk_3` FOREIGN KEY (`salesacc`) REFERENCES `account` (`id`) ON UPDATE CASCADE,
  ADD CONSTRAINT `product_ibfk_4` FOREIGN KEY (`salesdiscacc`) REFERENCES `account` (`id`) ON UPDATE CASCADE,
  ADD CONSTRAINT `product_ibfk_5` FOREIGN KEY (`salesreturnacc`) REFERENCES `account` (`id`) ON UPDATE CASCADE,
  ADD CONSTRAINT `product_ibfk_8` FOREIGN KEY (`brand`) REFERENCES `productbrand` (`id`) ON UPDATE CASCADE,
  ADD CONSTRAINT `product_ibfk_9` FOREIGN KEY (`factory`) REFERENCES `factories` (`id`) ON UPDATE CASCADE;

ALTER TABLE `productassemble`
  ADD CONSTRAINT `productassemble_ibfk_1` FOREIGN KEY (`division`) REFERENCES `division` (`id`) ON UPDATE CASCADE,
  ADD CONSTRAINT `productassemble_ibfk_2` FOREIGN KEY (`departement`) REFERENCES `departement` (`id`) ON UPDATE CASCADE,
  ADD CONSTRAINT `productassemble_ibfk_3` FOREIGN KEY (`productid`) REFERENCES `product` (`id`) ON UPDATE CASCADE;

ALTER TABLE `productassembledetail`
  ADD CONSTRAINT `productassembledetail_ibfk_1` FOREIGN KEY (`productid`) REFERENCES `product` (`id`) ON UPDATE CASCADE,
  ADD CONSTRAINT `productassembledetail_ibfk_2` FOREIGN KEY (`transid`) REFERENCES `productassemble` (`id`) ON UPDATE CASCADE;

ALTER TABLE `productdisassemble`
  ADD CONSTRAINT `productdisassemble_ibfk_1` FOREIGN KEY (`division`) REFERENCES `division` (`id`) ON UPDATE CASCADE,
  ADD CONSTRAINT `productdisassemble_ibfk_2` FOREIGN KEY (`departement`) REFERENCES `departement` (`id`) ON UPDATE CASCADE,
  ADD CONSTRAINT `productdisassemble_ibfk_3` FOREIGN KEY (`productid`) REFERENCES `product` (`id`) ON UPDATE CASCADE;

ALTER TABLE `productdisassembledetail`
  ADD CONSTRAINT `productdisassembledetail_ibfk_1` FOREIGN KEY (`productid`) REFERENCES `product` (`id`) ON UPDATE CASCADE,
  ADD CONSTRAINT `productdisassembledetail_ibfk_2` FOREIGN KEY (`transid`) REFERENCES `productdisassemble` (`id`) ON UPDATE CASCADE;

ALTER TABLE `productgroup`
  ADD CONSTRAINT `productgroup_ibfk_1` FOREIGN KEY (`cogsacc`) REFERENCES `account` (`id`) ON UPDATE CASCADE,
  ADD CONSTRAINT `productgroup_ibfk_2` FOREIGN KEY (`inventoryacc`) REFERENCES `account` (`id`) ON UPDATE CASCADE,
  ADD CONSTRAINT `productgroup_ibfk_4` FOREIGN KEY (`salesacc`) REFERENCES `account` (`id`) ON UPDATE CASCADE,
  ADD CONSTRAINT `productgroup_ibfk_5` FOREIGN KEY (`salesdiscacc`) REFERENCES `account` (`id`) ON UPDATE CASCADE,
  ADD CONSTRAINT `productgroup_ibfk_6` FOREIGN KEY (`salesreturnacc`) REFERENCES `account` (`id`) ON UPDATE CASCADE;

ALTER TABLE `productpackage`
  ADD CONSTRAINT `productpackage_ibfk_1` FOREIGN KEY (`packageid`) REFERENCES `product` (`id`) ON UPDATE CASCADE,
  ADD CONSTRAINT `productpackage_ibfk_2` FOREIGN KEY (`productid`) REFERENCES `product` (`id`) ON UPDATE CASCADE;

ALTER TABLE `productsalesvariant`
  ADD CONSTRAINT `productsalesvariant_ibfk_1` FOREIGN KEY (`productgroup`) REFERENCES `productgroup` (`id`) ON UPDATE CASCADE;

ALTER TABLE `purchase`
  ADD CONSTRAINT `purchase_ibfk_1` FOREIGN KEY (`division`) REFERENCES `division` (`id`) ON UPDATE CASCADE,
  ADD CONSTRAINT `purchase_ibfk_2` FOREIGN KEY (`purchaser`) REFERENCES `employee` (`id`) ON UPDATE CASCADE,
  ADD CONSTRAINT `purchase_ibfk_3` FOREIGN KEY (`supplierid`) REFERENCES `supplier` (`id`) ON UPDATE CASCADE,
  ADD CONSTRAINT `purchase_ibfk_4` FOREIGN KEY (`shipment`) REFERENCES `shipments` (`id`) ON UPDATE CASCADE;

ALTER TABLE `purchasedetail`
  ADD CONSTRAINT `purchasedetail_ibfk_1` FOREIGN KEY (`purchaseid`) REFERENCES `purchase` (`purchaseid`) ON UPDATE CASCADE,
  ADD CONSTRAINT `purchasedetail_ibfk_2` FOREIGN KEY (`productid`) REFERENCES `product` (`id`) ON UPDATE CASCADE,
  ADD CONSTRAINT `purchasedetail_ibfk_3` FOREIGN KEY (`departement`) REFERENCES `departement` (`id`) ON UPDATE CASCADE,
  ADD CONSTRAINT `purchasedetail_ibfk_4` FOREIGN KEY (`taxid`) REFERENCES `taxes` (`id`) ON UPDATE CASCADE,
  ADD CONSTRAINT `purchasedetail_ibfk_5` FOREIGN KEY (`purchaseidref`) REFERENCES `purchase` (`purchaseid`) ON UPDATE CASCADE;

ALTER TABLE `purchaseexpenses`
  ADD CONSTRAINT `purchaseexpenses_ibfk_1` FOREIGN KEY (`purchaseexpacc`) REFERENCES `account` (`id`) ON UPDATE CASCADE;

ALTER TABLE `purchaseexpensesdetail`
  ADD CONSTRAINT `purchaseexpensesdetail_ibfk_1` FOREIGN KEY (`purchaseidref`) REFERENCES `purchase` (`purchaseid`) ON UPDATE CASCADE,
  ADD CONSTRAINT `purchaseexpensesdetail_ibfk_2` FOREIGN KEY (`purchaseexpid`) REFERENCES `purchaseexpenses` (`id`) ON UPDATE CASCADE;

ALTER TABLE `purchaseextratax`
  ADD CONSTRAINT `purchaseextratax_ibfk_1` FOREIGN KEY (`purchaseid`) REFERENCES `purchase` (`purchaseid`) ON UPDATE CASCADE,
  ADD CONSTRAINT `purchaseextratax_ibfk_2` FOREIGN KEY (`productid`) REFERENCES `product` (`id`) ON UPDATE CASCADE,
  ADD CONSTRAINT `purchaseextratax_ibfk_3` FOREIGN KEY (`taxid`) REFERENCES `taxes` (`id`) ON UPDATE CASCADE,
  ADD CONSTRAINT `purchaseextratax_ibfk_4` FOREIGN KEY (`purchaseidref`) REFERENCES `purchase` (`purchaseid`) ON UPDATE CASCADE;

ALTER TABLE `purchaseorder`
  ADD CONSTRAINT `purchaseorder_ibfk_1` FOREIGN KEY (`division`) REFERENCES `division` (`id`) ON UPDATE CASCADE,
  ADD CONSTRAINT `purchaseorder_ibfk_2` FOREIGN KEY (`purchaser`) REFERENCES `employee` (`id`) ON UPDATE CASCADE,
  ADD CONSTRAINT `purchaseorder_ibfk_3` FOREIGN KEY (`supplierid`) REFERENCES `supplier` (`id`) ON UPDATE CASCADE,
  ADD CONSTRAINT `purchaseorder_ibfk_4` FOREIGN KEY (`shipment`) REFERENCES `shipments` (`id`) ON UPDATE CASCADE;

ALTER TABLE `purchaseorderdetail`
  ADD CONSTRAINT `purchaseorderdetail_ibfk_1` FOREIGN KEY (`purchaseid`) REFERENCES `purchaseorder` (`purchaseid`) ON UPDATE CASCADE,
  ADD CONSTRAINT `purchaseorderdetail_ibfk_2` FOREIGN KEY (`productid`) REFERENCES `product` (`id`) ON UPDATE CASCADE,
  ADD CONSTRAINT `purchaseorderdetail_ibfk_3` FOREIGN KEY (`departement`) REFERENCES `departement` (`id`) ON UPDATE CASCADE,
  ADD CONSTRAINT `purchaseorderdetail_ibfk_4` FOREIGN KEY (`taxid`) REFERENCES `taxes` (`id`) ON UPDATE CASCADE,
  ADD CONSTRAINT `purchaseorderdetail_ibfk_5` FOREIGN KEY (`purchaseidref`) REFERENCES `purchaseorder` (`purchaseid`) ON UPDATE CASCADE;

ALTER TABLE `purchaseorderexpensesdetail`
  ADD CONSTRAINT `purchaseorderexpensesdetail_ibfk_1` FOREIGN KEY (`purchaseidref`) REFERENCES `purchaseorder` (`purchaseid`) ON UPDATE CASCADE,
  ADD CONSTRAINT `purchaseorderexpensesdetail_ibfk_2` FOREIGN KEY (`purchaseexpid`) REFERENCES `purchaseexpenses` (`id`) ON UPDATE CASCADE;

ALTER TABLE `purchaseorderextratax`
  ADD CONSTRAINT `purchaseorderextratax_ibfk_1` FOREIGN KEY (`purchaseid`) REFERENCES `purchaseorder` (`purchaseid`) ON UPDATE CASCADE,
  ADD CONSTRAINT `purchaseorderextratax_ibfk_2` FOREIGN KEY (`productid`) REFERENCES `product` (`id`) ON UPDATE CASCADE,
  ADD CONSTRAINT `purchaseorderextratax_ibfk_3` FOREIGN KEY (`taxid`) REFERENCES `taxes` (`id`) ON UPDATE CASCADE,
  ADD CONSTRAINT `purchaseorderextratax_ibfk_4` FOREIGN KEY (`purchaseidref`) REFERENCES `purchaseorder` (`purchaseid`) ON UPDATE CASCADE;

ALTER TABLE `purchaseorderpayments`
  ADD CONSTRAINT `purchaseorderpayments_ibfk_1` FOREIGN KEY (`purchaseidref`) REFERENCES `purchaseorder` (`purchaseid`) ON UPDATE CASCADE,
  ADD CONSTRAINT `purchaseorderpayments_ibfk_2` FOREIGN KEY (`paymenttype`) REFERENCES `paymenttype` (`id`) ON UPDATE CASCADE;

ALTER TABLE `purchaseorderpoint`
  ADD CONSTRAINT `FK_purchaseorderpoint_1` FOREIGN KEY (`purchaseid`) REFERENCES `purchase` (`purchaseid`) ON UPDATE CASCADE,
  ADD CONSTRAINT `FK_purchaseorderpoint_2` FOREIGN KEY (`purchaseidref`) REFERENCES `purchase` (`purchaseid`) ON UPDATE CASCADE,
  ADD CONSTRAINT `FK_purchaseorderpoint_3` FOREIGN KEY (`supplier`) REFERENCES `supplier` (`id`) ON UPDATE CASCADE;

ALTER TABLE `purchaseorderrewarddetail`
  ADD CONSTRAINT `FK_purchaseorderrewarddetail_1` FOREIGN KEY (`purchaseid`) REFERENCES `purchaseorder` (`purchaseid`) ON UPDATE CASCADE,
  ADD CONSTRAINT `FK_purchaseorderrewarddetail_2` FOREIGN KEY (`purchaseidref`) REFERENCES `purchaseorder` (`purchaseid`) ON UPDATE CASCADE,
  ADD CONSTRAINT `FK_purchaseorderrewarddetail_3` FOREIGN KEY (`productid`) REFERENCES `product` (`id`) ON UPDATE CASCADE,
  ADD CONSTRAINT `FK_purchaseorderrewarddetail_4` FOREIGN KEY (`departement`) REFERENCES `departement` (`id`) ON UPDATE CASCADE;

ALTER TABLE `purchasepayments`
  ADD CONSTRAINT `purchasepayments_ibfk_1` FOREIGN KEY (`purchaseidref`) REFERENCES `purchase` (`purchaseid`) ON UPDATE CASCADE,
  ADD CONSTRAINT `purchasepayments_ibfk_2` FOREIGN KEY (`paymenttype`) REFERENCES `paymenttype` (`id`) ON UPDATE CASCADE;

ALTER TABLE `purchasepoint`
  ADD CONSTRAINT `FK_purchasepoint_1` FOREIGN KEY (`purchaseid`) REFERENCES `purchase` (`purchaseid`) ON UPDATE CASCADE,
  ADD CONSTRAINT `FK_purchasepoint_2` FOREIGN KEY (`purchaseidref`) REFERENCES `purchase` (`purchaseid`) ON UPDATE CASCADE,
  ADD CONSTRAINT `FK_purchasepoint_3` FOREIGN KEY (`supplier`) REFERENCES `supplier` (`id`) ON UPDATE CASCADE;

ALTER TABLE `purchaserewarddetail`
  ADD CONSTRAINT `FK_purchaserewarddetail_1` FOREIGN KEY (`purchaseid`) REFERENCES `purchase` (`purchaseid`) ON UPDATE CASCADE,
  ADD CONSTRAINT `FK_purchaserewarddetail_2` FOREIGN KEY (`purchaseidref`) REFERENCES `purchase` (`purchaseid`) ON UPDATE CASCADE,
  ADD CONSTRAINT `FK_purchaserewarddetail_3` FOREIGN KEY (`productid`) REFERENCES `product` (`id`) ON UPDATE CASCADE,
  ADD CONSTRAINT `FK_purchaserewarddetail_4` FOREIGN KEY (`departement`) REFERENCES `departement` (`id`) ON UPDATE CASCADE;

ALTER TABLE `receivableadjust`
  ADD CONSTRAINT `receivableadjust_ibfk_1` FOREIGN KEY (`division`) REFERENCES `division` (`id`) ON UPDATE CASCADE,
  ADD CONSTRAINT `receivableadjust_ibfk_2` FOREIGN KEY (`customerid`) REFERENCES `customer` (`id`) ON UPDATE CASCADE,
  ADD CONSTRAINT `receivableadjust_ibfk_3` FOREIGN KEY (`expensestype`) REFERENCES `salesexpenses` (`id`) ON UPDATE CASCADE;

ALTER TABLE `receivablepayment`
  ADD CONSTRAINT `receivablepayment_ibfk_1` FOREIGN KEY (`division`) REFERENCES `division` (`id`) ON UPDATE CASCADE,
  ADD CONSTRAINT `receivablepayment_ibfk_2` FOREIGN KEY (`customerid`) REFERENCES `customer` (`id`) ON UPDATE CASCADE,
  ADD CONSTRAINT `receivablepayment_ibfk_3` FOREIGN KEY (`paymenttype`) REFERENCES `paymenttype` (`id`) ON UPDATE CASCADE;

ALTER TABLE `rentalreturn`
  ADD CONSTRAINT `rentalreturn_ibfk_1` FOREIGN KEY (`division`) REFERENCES `division` (`id`) ON UPDATE CASCADE,
  ADD CONSTRAINT `rentalreturn_ibfk_2` FOREIGN KEY (`customerid`) REFERENCES `customer` (`id`) ON UPDATE CASCADE,
  ADD CONSTRAINT `rentalreturn_ibfk_3` FOREIGN KEY (`salesid`) REFERENCES `sales` (`salesid`) ON UPDATE CASCADE;

ALTER TABLE `rentalreturndetail`
  ADD CONSTRAINT `rentalreturndetail_ibfk_1` FOREIGN KEY (`rentalreturnid`) REFERENCES `rentalreturn` (`transid`) ON UPDATE CASCADE,
  ADD CONSTRAINT `rentalreturndetail_ibfk_2` FOREIGN KEY (`productid`) REFERENCES `product` (`id`) ON UPDATE CASCADE,
  ADD CONSTRAINT `rentalreturndetail_ibfk_3` FOREIGN KEY (`departement`) REFERENCES `departement` (`id`) ON UPDATE CASCADE;

ALTER TABLE `roles`
  ADD CONSTRAINT `currency_ibfk` FOREIGN KEY (`defaultcurrency`) REFERENCES `currencies` (`id`) ON DELETE NO ACTION ON UPDATE CASCADE,
  ADD CONSTRAINT `customer_ibfk` FOREIGN KEY (`defaultcustomer`) REFERENCES `customer` (`id`) ON DELETE NO ACTION ON UPDATE CASCADE,
  ADD CONSTRAINT `departement_ibfk` FOREIGN KEY (`defaultdepartement`) REFERENCES `departement` (`id`) ON DELETE NO ACTION ON UPDATE CASCADE,
  ADD CONSTRAINT `division_ibfk` FOREIGN KEY (`defaultdivision`) REFERENCES `division` (`id`) ON DELETE NO ACTION ON UPDATE CASCADE,
  ADD CONSTRAINT `employee_ibfk` FOREIGN KEY (`defaultemployee`) REFERENCES `employee` (`id`) ON DELETE NO ACTION ON UPDATE CASCADE,
  ADD CONSTRAINT `payment_ibfk` FOREIGN KEY (`defaultpayment`) REFERENCES `paymenttype` (`id`) ON DELETE NO ACTION ON UPDATE CASCADE,
  ADD CONSTRAINT `salesman_ibfk` FOREIGN KEY (`defaultsalesman`) REFERENCES `salesman` (`id`) ON DELETE NO ACTION ON UPDATE CASCADE,
  ADD CONSTRAINT `servicedoer_ibfk` FOREIGN KEY (`defaultservicedoer`) REFERENCES `servicedoer` (`id`) ON DELETE NO ACTION ON UPDATE CASCADE,
  ADD CONSTRAINT `shipment_ibfk` FOREIGN KEY (`defaultshipment`) REFERENCES `shipments` (`id`) ON DELETE NO ACTION ON UPDATE CASCADE,
  ADD CONSTRAINT `supplier_ibfk` FOREIGN KEY (`defaultsupplier`) REFERENCES `supplier` (`id`) ON DELETE NO ACTION ON UPDATE CASCADE;

ALTER TABLE `salaries`
  ADD CONSTRAINT `salaries_ibfk_1` FOREIGN KEY (`account`) REFERENCES `account` (`id`) ON UPDATE CASCADE;

ALTER TABLE `salariesrecord`
  ADD CONSTRAINT `salariesrecord_ibfk_1` FOREIGN KEY (`employeeid`) REFERENCES `employee` (`id`) ON UPDATE CASCADE,
  ADD CONSTRAINT `salariesrecord_ibfk_2` FOREIGN KEY (`salaryid`) REFERENCES `salaries` (`id`) ON UPDATE CASCADE;

ALTER TABLE `salarypayments`
  ADD CONSTRAINT `salarypayments_ibfk_1` FOREIGN KEY (`paymenttype`) REFERENCES `paymenttype` (`id`) ON UPDATE CASCADE,
  ADD CONSTRAINT `salarypayments_ibfk_2` FOREIGN KEY (`employeeid`) REFERENCES `employee` (`id`) ON UPDATE CASCADE,
  ADD CONSTRAINT `salarypayments_ibfk_3` FOREIGN KEY (`salaryid`) REFERENCES `salaries` (`id`) ON UPDATE CASCADE,
  ADD CONSTRAINT `salarypayments_ibfk_4` FOREIGN KEY (`division`) REFERENCES `division` (`id`) ON UPDATE CASCADE;

ALTER TABLE `salaryperiod`
  ADD CONSTRAINT `FK_salaryperiod_account` FOREIGN KEY (`accountid`) REFERENCES `account` (`id`) ON UPDATE CASCADE,
  ADD CONSTRAINT `salaryperiod_ibfk_2` FOREIGN KEY (`division`) REFERENCES `division` (`id`) ON UPDATE CASCADE;

ALTER TABLE `salaryperioddetail`
  ADD CONSTRAINT `salaryperioddetail_ibfk_1` FOREIGN KEY (`employeeid`) REFERENCES `employee` (`id`) ON UPDATE CASCADE;

ALTER TABLE `salarystructuredetail`
  ADD CONSTRAINT `salarystructuredetail_ibfk_1` FOREIGN KEY (`salarystructure`) REFERENCES `salarystructure` (`id`) ON UPDATE CASCADE,
  ADD CONSTRAINT `salarystructuredetail_ibfk_2` FOREIGN KEY (`salaryid`) REFERENCES `salaries` (`id`) ON UPDATE CASCADE;

ALTER TABLE `sales`
  ADD CONSTRAINT `sales_ibfk_1` FOREIGN KEY (`division`) REFERENCES `division` (`id`) ON UPDATE CASCADE,
  ADD CONSTRAINT `sales_ibfk_2` FOREIGN KEY (`salesmanid`) REFERENCES `salesman` (`id`) ON UPDATE CASCADE,
  ADD CONSTRAINT `sales_ibfk_3` FOREIGN KEY (`customerid`) REFERENCES `customer` (`id`) ON UPDATE CASCADE,
  ADD CONSTRAINT `sales_ibfk_4` FOREIGN KEY (`shipment`) REFERENCES `shipments` (`id`) ON UPDATE CASCADE,
  ADD CONSTRAINT `sales_ibfk_5` FOREIGN KEY (`billto`) REFERENCES `customer` (`id`) ON UPDATE CASCADE;

ALTER TABLE `salesdetail`
  ADD CONSTRAINT `salesdetail_ibfk_1` FOREIGN KEY (`salesid`) REFERENCES `sales` (`salesid`) ON UPDATE CASCADE,
  ADD CONSTRAINT `salesdetail_ibfk_2` FOREIGN KEY (`productid`) REFERENCES `product` (`id`) ON UPDATE CASCADE,
  ADD CONSTRAINT `salesdetail_ibfk_3` FOREIGN KEY (`departement`) REFERENCES `departement` (`id`) ON UPDATE CASCADE,
  ADD CONSTRAINT `salesdetail_ibfk_4` FOREIGN KEY (`taxid`) REFERENCES `taxes` (`id`) ON UPDATE CASCADE,
  ADD CONSTRAINT `salesdetail_ibfk_5` FOREIGN KEY (`salesidref`) REFERENCES `sales` (`salesid`) ON UPDATE CASCADE,
  ADD CONSTRAINT `salesdetail_ibfk_6` FOREIGN KEY (`servicedoerid`) REFERENCES `servicedoer` (`id`) ON UPDATE CASCADE;

ALTER TABLE `salesexpenses`
  ADD CONSTRAINT `salesexpenses_ibfk_1` FOREIGN KEY (`salesexpacc`) REFERENCES `account` (`id`) ON UPDATE CASCADE;

ALTER TABLE `salesexpensesdetail`
  ADD CONSTRAINT `salesexpensesdetail_ibfk_1` FOREIGN KEY (`salesidref`) REFERENCES `sales` (`salesid`) ON UPDATE CASCADE,
  ADD CONSTRAINT `salesexpensesdetail_ibfk_2` FOREIGN KEY (`salesexpid`) REFERENCES `salesexpenses` (`id`) ON UPDATE CASCADE;

ALTER TABLE `salesextratax`
  ADD CONSTRAINT `salesextratax_ibfk_1` FOREIGN KEY (`salesid`) REFERENCES `sales` (`salesid`) ON UPDATE CASCADE,
  ADD CONSTRAINT `salesextratax_ibfk_2` FOREIGN KEY (`productid`) REFERENCES `product` (`id`) ON UPDATE CASCADE,
  ADD CONSTRAINT `salesextratax_ibfk_3` FOREIGN KEY (`taxid`) REFERENCES `taxes` (`id`) ON UPDATE CASCADE,
  ADD CONSTRAINT `salesextratax_ibfk_4` FOREIGN KEY (`salesidref`) REFERENCES `sales` (`salesid`) ON UPDATE CASCADE;

ALTER TABLE `salesman`
  ADD CONSTRAINT `salesman_ibfk_1` FOREIGN KEY (`salesmangroup`) REFERENCES `salesmangroup` (`id`) ON UPDATE CASCADE,
  ADD CONSTRAINT `salesman_ibfk_2` FOREIGN KEY (`payablecommacc`) REFERENCES `account` (`id`) ON UPDATE CASCADE,
  ADD CONSTRAINT `salesman_ibfk_3` FOREIGN KEY (`expensecommacc`) REFERENCES `account` (`id`) ON UPDATE CASCADE;

ALTER TABLE `salesmancommperiod`
  ADD CONSTRAINT `salesmancommperiod_ibfk_1` FOREIGN KEY (`salaryid`) REFERENCES `salaries` (`id`) ON UPDATE CASCADE,
  ADD CONSTRAINT `salesmancommperiod_ibfk_2` FOREIGN KEY (`division`) REFERENCES `division` (`id`) ON UPDATE CASCADE;

ALTER TABLE `salesmancommvarrecords`
  ADD CONSTRAINT `salesmancommvarrecords_ibfk_1` FOREIGN KEY (`periodid`) REFERENCES `salesmancommperiod` (`id`) ON UPDATE CASCADE;

ALTER TABLE `salesmandetail`
  ADD CONSTRAINT `salesmandetail_ibfk_1` FOREIGN KEY (`groupid`) REFERENCES `salesman` (`id`) ON UPDATE CASCADE,
  ADD CONSTRAINT `salesmandetail_ibfk_2` FOREIGN KEY (`salesmanid`) REFERENCES `salesman` (`id`) ON UPDATE CASCADE;

ALTER TABLE `salesmangroup`
  ADD CONSTRAINT `salesmangroup_ibfk_1` FOREIGN KEY (`payablecommacc`) REFERENCES `account` (`id`) ON UPDATE CASCADE,
  ADD CONSTRAINT `salesmangroup_ibfk_2` FOREIGN KEY (`expensecommacc`) REFERENCES `account` (`id`) ON UPDATE CASCADE;

ALTER TABLE `salesmanrecorddetail`
  ADD CONSTRAINT `salesmanrecorddetail_ibfk_1` FOREIGN KEY (`salesmanid`) REFERENCES `salesman` (`id`) ON UPDATE CASCADE,
  ADD CONSTRAINT `salesmanrecorddetail_ibfk_2` FOREIGN KEY (`productid`) REFERENCES `product` (`id`) ON UPDATE CASCADE,
  ADD CONSTRAINT `salesmanrecorddetail_ibfk_3` FOREIGN KEY (`periodid`) REFERENCES `salesmancommperiod` (`id`) ON UPDATE CASCADE;

ALTER TABLE `salesmanrecords`
  ADD CONSTRAINT `salesmanrecords_ibfk_1` FOREIGN KEY (`salesmanid`) REFERENCES `salesman` (`id`) ON UPDATE CASCADE,
  ADD CONSTRAINT `salesmanrecords_ibfk_2` FOREIGN KEY (`periodid`) REFERENCES `salesmancommperiod` (`id`) ON UPDATE CASCADE;

ALTER TABLE `salesorder`
  ADD CONSTRAINT `salesorder_ibfk_1` FOREIGN KEY (`division`) REFERENCES `division` (`id`) ON UPDATE CASCADE,
  ADD CONSTRAINT `salesorder_ibfk_2` FOREIGN KEY (`salesmanid`) REFERENCES `salesman` (`id`) ON UPDATE CASCADE,
  ADD CONSTRAINT `salesorder_ibfk_3` FOREIGN KEY (`customerid`) REFERENCES `customer` (`id`) ON UPDATE CASCADE,
  ADD CONSTRAINT `salesorder_ibfk_4` FOREIGN KEY (`shipment`) REFERENCES `shipments` (`id`) ON UPDATE CASCADE;

ALTER TABLE `salesorderdetail`
  ADD CONSTRAINT `salesorderdetail_ibfk_1` FOREIGN KEY (`salesid`) REFERENCES `salesorder` (`salesid`) ON UPDATE CASCADE,
  ADD CONSTRAINT `salesorderdetail_ibfk_2` FOREIGN KEY (`productid`) REFERENCES `product` (`id`) ON UPDATE CASCADE,
  ADD CONSTRAINT `salesorderdetail_ibfk_3` FOREIGN KEY (`departement`) REFERENCES `departement` (`id`) ON UPDATE CASCADE,
  ADD CONSTRAINT `salesorderdetail_ibfk_4` FOREIGN KEY (`taxid`) REFERENCES `taxes` (`id`) ON UPDATE CASCADE,
  ADD CONSTRAINT `salesorderdetail_ibfk_5` FOREIGN KEY (`salesidref`) REFERENCES `salesorder` (`salesid`) ON UPDATE CASCADE,
  ADD CONSTRAINT `salesorderdetail_ibfk_6` FOREIGN KEY (`servicedoerid`) REFERENCES `servicedoer` (`id`) ON UPDATE CASCADE;

ALTER TABLE `salesorderexpensesdetail`
  ADD CONSTRAINT `salesorderexpensesdetail_ibfk_1` FOREIGN KEY (`salesidref`) REFERENCES `salesorder` (`salesid`) ON UPDATE CASCADE,
  ADD CONSTRAINT `salesorderexpensesdetail_ibfk_2` FOREIGN KEY (`salesexpid`) REFERENCES `salesexpenses` (`id`) ON UPDATE CASCADE;

ALTER TABLE `salesorderextratax`
  ADD CONSTRAINT `salesorderextratax_ibfk_1` FOREIGN KEY (`salesid`) REFERENCES `salesorder` (`salesid`) ON UPDATE CASCADE,
  ADD CONSTRAINT `salesorderextratax_ibfk_2` FOREIGN KEY (`productid`) REFERENCES `product` (`id`) ON UPDATE CASCADE,
  ADD CONSTRAINT `salesorderextratax_ibfk_3` FOREIGN KEY (`taxid`) REFERENCES `taxes` (`id`) ON UPDATE CASCADE,
  ADD CONSTRAINT `salesorderextratax_ibfk_4` FOREIGN KEY (`salesidref`) REFERENCES `salesorder` (`salesid`) ON UPDATE CASCADE;

ALTER TABLE `salesorderpayments`
  ADD CONSTRAINT `salesorderpayments_ibfk_1` FOREIGN KEY (`salesidref`) REFERENCES `salesorder` (`salesid`) ON UPDATE CASCADE,
  ADD CONSTRAINT `salesorderpayments_ibfk_2` FOREIGN KEY (`paymenttype`) REFERENCES `paymenttype` (`id`) ON UPDATE CASCADE;

ALTER TABLE `salesorderpoint`
  ADD CONSTRAINT `FK_salesorderpoint_1` FOREIGN KEY (`salesid`) REFERENCES `salesorder` (`salesid`) ON UPDATE CASCADE,
  ADD CONSTRAINT `FK_salesorderpoint_2` FOREIGN KEY (`salesidref`) REFERENCES `salesorder` (`salesid`) ON UPDATE CASCADE,
  ADD CONSTRAINT `FK_salesorderpoint_3` FOREIGN KEY (`customer`) REFERENCES `customer` (`id`) ON UPDATE CASCADE;

ALTER TABLE `salesorderrewarddetail`
  ADD CONSTRAINT `FK_salesorderrewarddetail_1` FOREIGN KEY (`salesid`) REFERENCES `salesorder` (`salesid`) ON UPDATE CASCADE,
  ADD CONSTRAINT `FK_salesorderrewarddetail_2` FOREIGN KEY (`salesidref`) REFERENCES `salesorder` (`salesid`) ON UPDATE CASCADE,
  ADD CONSTRAINT `FK_salesorderrewarddetail_3` FOREIGN KEY (`productid`) REFERENCES `product` (`id`) ON UPDATE CASCADE,
  ADD CONSTRAINT `FK_salesorderrewarddetail_4` FOREIGN KEY (`departement`) REFERENCES `departement` (`id`) ON UPDATE CASCADE;

ALTER TABLE `salespayments`
  ADD CONSTRAINT `salespayments_ibfk_1` FOREIGN KEY (`salesidref`) REFERENCES `sales` (`salesid`) ON UPDATE CASCADE,
  ADD CONSTRAINT `salespayments_ibfk_2` FOREIGN KEY (`paymenttype`) REFERENCES `paymenttype` (`id`) ON UPDATE CASCADE;

ALTER TABLE `salespoint`
  ADD CONSTRAINT `FK_salespoint_1` FOREIGN KEY (`salesid`) REFERENCES `sales` (`salesid`) ON UPDATE CASCADE,
  ADD CONSTRAINT `FK_salespoint_2` FOREIGN KEY (`salesidref`) REFERENCES `sales` (`salesid`) ON UPDATE CASCADE,
  ADD CONSTRAINT `FK_salespoint_3` FOREIGN KEY (`customer`) REFERENCES `customer` (`id`) ON UPDATE CASCADE;

ALTER TABLE `salesproductrewardrules`
  ADD CONSTRAINT `salesproductrewardrules_ibfk_1` FOREIGN KEY (`productid`) REFERENCES `product` (`id`) ON UPDATE CASCADE,
  ADD CONSTRAINT `salesproductrewardrules_ibfk_2` FOREIGN KEY (`departement`) REFERENCES `departement` (`id`) ON UPDATE CASCADE;

ALTER TABLE `salesrewarddetail`
  ADD CONSTRAINT `FK_salesrewarddetail_1` FOREIGN KEY (`salesid`) REFERENCES `sales` (`salesid`) ON UPDATE CASCADE,
  ADD CONSTRAINT `FK_salesrewarddetail_2` FOREIGN KEY (`salesidref`) REFERENCES `sales` (`salesid`) ON UPDATE CASCADE,
  ADD CONSTRAINT `FK_salesrewarddetail_3` FOREIGN KEY (`productid`) REFERENCES `product` (`id`) ON UPDATE CASCADE,
  ADD CONSTRAINT `FK_salesrewarddetail_4` FOREIGN KEY (`departement`) REFERENCES `departement` (`id`) ON UPDATE CASCADE;

ALTER TABLE `schoolclass`
  ADD CONSTRAINT `FK_schoolclass_schoollevel` FOREIGN KEY (`schoollevel`) REFERENCES `schoollevel` (`id`) ON UPDATE CASCADE;

ALTER TABLE `schoolextrascore`
  ADD CONSTRAINT `FK_schoolextrascore_schoolextrascoregroup` FOREIGN KEY (`extrascoregroup`) REFERENCES `schoolextrascoregroup` (`id`) ON UPDATE CASCADE;

ALTER TABLE `schoollesson`
  ADD CONSTRAINT `FK_schoollesson_schoollessongroup` FOREIGN KEY (`lessongroup`) REFERENCES `schoollessongroup` (`id`) ON UPDATE CASCADE,
  ADD CONSTRAINT `FK_schoollesson_schoolscoringtype` FOREIGN KEY (`scoringtype`) REFERENCES `schoolscoringtype` (`id`) ON UPDATE CASCADE;

ALTER TABLE `schoollessonclass`
  ADD CONSTRAINT `FK_schoollessonclass_schoollesson` FOREIGN KEY (`schoollesson`) REFERENCES `schoollesson` (`id`) ON UPDATE CASCADE,
  ADD CONSTRAINT `FK_schoollessonclass_schoolsubclass` FOREIGN KEY (`schoolsubclass`) REFERENCES `schoolsubclass` (`id`) ON UPDATE CASCADE,
  ADD CONSTRAINT `FK_schoollessonclass_schoolteacher` FOREIGN KEY (`schoolteacher`) REFERENCES `schoolteacher` (`id`) ON UPDATE CASCADE;

ALTER TABLE `schoollessonteacher`
  ADD CONSTRAINT `FK_schoollessonteacher_schoollesson` FOREIGN KEY (`schoollesson`) REFERENCES `schoollesson` (`id`) ON UPDATE CASCADE,
  ADD CONSTRAINT `FK_schoollessonteacher_schoolsubclass` FOREIGN KEY (`schoolsubclass`) REFERENCES `schoolsubclass` (`id`) ON UPDATE CASCADE,
  ADD CONSTRAINT `FK_schoollessonteacher_schoolteacher` FOREIGN KEY (`schoolteacher`) REFERENCES `schoolteacher` (`id`) ON UPDATE CASCADE;

ALTER TABLE `schoollevel`
  ADD CONSTRAINT `FK_schoollevel_schoolteacher` FOREIGN KEY (`headmaster`) REFERENCES `schoolteacher` (`id`) ON UPDATE CASCADE;

ALTER TABLE `schoolpayment`
  ADD CONSTRAINT `FK_schoolpayment_account` FOREIGN KEY (`unearnedrevenueacc`) REFERENCES `account` (`id`) ON UPDATE CASCADE,
  ADD CONSTRAINT `FK_schoolpayment_account_2` FOREIGN KEY (`paymentdiscacc`) REFERENCES `account` (`id`) ON UPDATE CASCADE,
  ADD CONSTRAINT `FK_schoolpayment_receivable` FOREIGN KEY (`receivableacc`) REFERENCES `account` (`id`) ON UPDATE CASCADE,
  ADD CONSTRAINT `FK_schoolpayment_revenue` FOREIGN KEY (`revenueacc`) REFERENCES `account` (`id`) ON UPDATE CASCADE,
  ADD CONSTRAINT `FK_schoolpayment_schoolpaymentgroup` FOREIGN KEY (`paymentgroup`) REFERENCES `schoolpaymentgroup` (`id`) ON UPDATE CASCADE;

ALTER TABLE `schoolpaymentpackagedetail`
  ADD CONSTRAINT `FK_schoolpaymentpackagedetail_schoolpayment` FOREIGN KEY (`schoolpayment`) REFERENCES `schoolpayment` (`id`) ON UPDATE CASCADE,
  ADD CONSTRAINT `FK_schoolpaymentpackagedetail_schoolpaymentpackage` FOREIGN KEY (`schoolpaymentpackage`) REFERENCES `schoolpaymentpackage` (`id`) ON UPDATE CASCADE;

ALTER TABLE `schoolscoringtyperange`
  ADD CONSTRAINT `FK_schoolscoringtyperange_schoolscoringtype` FOREIGN KEY (`schoolscoringtype`) REFERENCES `schoolscoringtype` (`id`) ON UPDATE CASCADE;

ALTER TABLE `schoolstudent`
  ADD CONSTRAINT `FK_schoolstudent_schoolclass` FOREIGN KEY (`schoolclass`) REFERENCES `schoolclass` (`id`) ON UPDATE CASCADE,
  ADD CONSTRAINT `FK_schoolstudent_schoolstudentdorm` FOREIGN KEY (`dorm`) REFERENCES `schoolstudentdorm` (`id`) ON UPDATE CASCADE,
  ADD CONSTRAINT `FK_schoolstudent_schoolstudentstatus` FOREIGN KEY (`status`) REFERENCES `schoolstudentstatus` (`id`) ON UPDATE CASCADE,
  ADD CONSTRAINT `FK_schoolstudent_schoolsubclass` FOREIGN KEY (`schoolsubclass`) REFERENCES `schoolsubclass` (`id`) ON UPDATE CASCADE;

ALTER TABLE `schoolstudentdorm`
  ADD CONSTRAINT `FK_schoolstudentdorm_schoolteacher` FOREIGN KEY (`dormheadmaster`) REFERENCES `schoolteacher` (`id`) ON UPDATE CASCADE;

ALTER TABLE `schoolstudentpayment`
  ADD CONSTRAINT `FK_schoolstudentpayment_division` FOREIGN KEY (`division`) REFERENCES `division` (`id`) ON UPDATE CASCADE,
  ADD CONSTRAINT `FK_schoolstudentpayment_paymenttype` FOREIGN KEY (`paymenttype`) REFERENCES `paymenttype` (`id`) ON UPDATE CASCADE,
  ADD CONSTRAINT `FK_schoolstudentpayment_schoolstudent` FOREIGN KEY (`schoolstudent`) REFERENCES `schoolstudent` (`id`) ON UPDATE CASCADE,
  ADD CONSTRAINT `FK_schoolstudentpayment_schoolsubclass` FOREIGN KEY (`schoolsubclass`) REFERENCES `schoolsubclass` (`id`) ON UPDATE CASCADE;

ALTER TABLE `schoolstudentpaymentdetail`
  ADD CONSTRAINT `FK_schoolstudentpaymentdetail_schoolpayment` FOREIGN KEY (`schoolpayment`) REFERENCES `schoolpayment` (`id`) ON UPDATE CASCADE,
  ADD CONSTRAINT `FK_schoolstudentpaymentdetail_schoolstudent` FOREIGN KEY (`schoolstudent`) REFERENCES `schoolstudent` (`id`) ON UPDATE CASCADE,
  ADD CONSTRAINT `FK_schoolstudentpaymentdetail_schoolstudentpayment` FOREIGN KEY (`parent`) REFERENCES `schoolstudentpayment` (`id`) ON UPDATE CASCADE,
  ADD CONSTRAINT `FK_schoolstudentpaymentdetail_schoolsubclass` FOREIGN KEY (`schoolsubclass`) REFERENCES `schoolsubclass` (`id`) ON UPDATE CASCADE;

ALTER TABLE `schoolstudentpaymentschedule`
  ADD CONSTRAINT `FK_schoolstudentpaymentschedule_division` FOREIGN KEY (`division`) REFERENCES `division` (`id`) ON UPDATE CASCADE,
  ADD CONSTRAINT `FK_schoolstudentpaymentschedule_schoolpaymentpackage` FOREIGN KEY (`schoolpaymentpackage`) REFERENCES `schoolpaymentpackage` (`id`) ON UPDATE CASCADE,
  ADD CONSTRAINT `FK_schoolstudentpaymentschedule_schoolstudent` FOREIGN KEY (`schoolstudent`) REFERENCES `schoolstudent` (`id`) ON UPDATE CASCADE,
  ADD CONSTRAINT `FK_schoolstudentpaymentschedule_schoolsubclass` FOREIGN KEY (`schoolsubclass`) REFERENCES `schoolsubclass` (`id`) ON UPDATE CASCADE;

ALTER TABLE `schoolstudentscore`
  ADD CONSTRAINT `FK_schoolstudentscore_schoolexam` FOREIGN KEY (`schoolexam`) REFERENCES `schoolexam` (`id`) ON UPDATE CASCADE,
  ADD CONSTRAINT `FK_schoolstudentscore_schoollesson` FOREIGN KEY (`schoollesson`) REFERENCES `schoollesson` (`id`) ON UPDATE CASCADE,
  ADD CONSTRAINT `FK_schoolstudentscore_schoolperiod` FOREIGN KEY (`schoolperiod`) REFERENCES `schoolperiod` (`id`) ON UPDATE CASCADE,
  ADD CONSTRAINT `FK_schoolstudentscore_schoolscoringtype` FOREIGN KEY (`scoringtype`) REFERENCES `schoolscoringtype` (`id`) ON UPDATE CASCADE,
  ADD CONSTRAINT `FK_schoolstudentscore_schoolsubclass` FOREIGN KEY (`schoolsubclass`) REFERENCES `schoolsubclass` (`id`) ON UPDATE CASCADE,
  ADD CONSTRAINT `FK_schoolstudentscore_schoolteacher` FOREIGN KEY (`schoolteacher`) REFERENCES `schoolteacher` (`id`) ON UPDATE CASCADE;

ALTER TABLE `schoolstudentscoredetail`
  ADD CONSTRAINT `FK_schoolstudentscoredetail_schoolexam` FOREIGN KEY (`schoolexam`) REFERENCES `schoolexam` (`id`) ON UPDATE CASCADE,
  ADD CONSTRAINT `FK_schoolstudentscoredetail_schoollesson` FOREIGN KEY (`schoollesson`) REFERENCES `schoollesson` (`id`) ON UPDATE CASCADE,
  ADD CONSTRAINT `FK_schoolstudentscoredetail_schoolperiod` FOREIGN KEY (`schoolperiod`) REFERENCES `schoolperiod` (`id`) ON UPDATE CASCADE,
  ADD CONSTRAINT `FK_schoolstudentscoredetail_schoolstudent` FOREIGN KEY (`schoolstudent`) REFERENCES `schoolstudent` (`id`) ON UPDATE CASCADE,
  ADD CONSTRAINT `FK_schoolstudentscoredetail_schoolstudentscore` FOREIGN KEY (`schoolstudentscore`) REFERENCES `schoolstudentscore` (`id`) ON UPDATE CASCADE,
  ADD CONSTRAINT `FK_schoolstudentscoredetail_schoolsubclass` FOREIGN KEY (`schoolsubclass`) REFERENCES `schoolsubclass` (`id`) ON UPDATE CASCADE,
  ADD CONSTRAINT `FK_schoolstudentscoredetail_schoolteacher` FOREIGN KEY (`schoolteacher`) REFERENCES `schoolteacher` (`id`) ON UPDATE CASCADE,
  ADD CONSTRAINT `FK_schoolstudentscoredetail_scoringtype` FOREIGN KEY (`scoringtype`) REFERENCES `schoolscoringtype` (`id`) ON UPDATE CASCADE;

ALTER TABLE `schoolstudentsextrascore`
  ADD CONSTRAINT `FK_schoolstudentsextrascore_schoolexam` FOREIGN KEY (`schoolexam`) REFERENCES `schoolexam` (`id`) ON UPDATE CASCADE,
  ADD CONSTRAINT `FK_schoolstudentsextrascore_schoolextrascore` FOREIGN KEY (`schoolextrascore`) REFERENCES `schoolextrascore` (`id`) ON UPDATE CASCADE,
  ADD CONSTRAINT `FK_schoolstudentsextrascore_schoolextrascoregroup` FOREIGN KEY (`schoolextrascoregroup`) REFERENCES `schoolextrascoregroup` (`id`) ON UPDATE CASCADE,
  ADD CONSTRAINT `FK_schoolstudentsextrascore_schoolperiod` FOREIGN KEY (`schoolperiod`) REFERENCES `schoolperiod` (`id`) ON UPDATE CASCADE,
  ADD CONSTRAINT `FK_schoolstudentsextrascore_schoolscoringtype` FOREIGN KEY (`scoringtype`) REFERENCES `schoolscoringtype` (`id`) ON UPDATE CASCADE,
  ADD CONSTRAINT `FK_schoolstudentsextrascore_schoolsubclass` FOREIGN KEY (`schoolsubclass`) REFERENCES `schoolsubclass` (`id`) ON UPDATE CASCADE,
  ADD CONSTRAINT `FK_schoolstudentsextrascore_schoolteacher` FOREIGN KEY (`schoolteacher`) REFERENCES `schoolteacher` (`id`) ON UPDATE CASCADE;

ALTER TABLE `schoolstudentsextrascoredetail`
  ADD CONSTRAINT `FK_schoolstudentsextrascoredetail_schoolexam` FOREIGN KEY (`schoolexam`) REFERENCES `schoolexam` (`id`) ON UPDATE CASCADE,
  ADD CONSTRAINT `FK_schoolstudentsextrascoredetail_schoolextrascore` FOREIGN KEY (`schoolextrascore`) REFERENCES `schoolextrascore` (`id`) ON UPDATE CASCADE,
  ADD CONSTRAINT `FK_schoolstudentsextrascoredetail_schoolperiod` FOREIGN KEY (`schoolperiod`) REFERENCES `schoolperiod` (`id`) ON UPDATE CASCADE,
  ADD CONSTRAINT `FK_schoolstudentsextrascoredetail_schoolstudent` FOREIGN KEY (`schoolstudent`) REFERENCES `schoolstudent` (`id`) ON UPDATE CASCADE,
  ADD CONSTRAINT `FK_schoolstudentsextrascoredetail_schoolstudentsextrascore` FOREIGN KEY (`schoolstudentsextrascore`) REFERENCES `schoolstudentsextrascore` (`id`) ON UPDATE CASCADE,
  ADD CONSTRAINT `FK_schoolstudentsextrascoredetail_schoolsubclass` FOREIGN KEY (`schoolsubclass`) REFERENCES `schoolsubclass` (`id`) ON UPDATE CASCADE,
  ADD CONSTRAINT `FK_schoolstudentsextrascoredetail_schoolteacher` FOREIGN KEY (`schoolteacher`) REFERENCES `schoolteacher` (`id`) ON UPDATE CASCADE,
  ADD CONSTRAINT `FK_schoolstudentsextrascoredetail_scoringtype` FOREIGN KEY (`scoringtype`) REFERENCES `schoolscoringtype` (`id`) ON UPDATE CASCADE;

ALTER TABLE `schoolstupaymentscheduledetail`
  ADD CONSTRAINT `FK_schoolstupaymentscheddetail_schoolpayment` FOREIGN KEY (`schoolpayment`) REFERENCES `schoolpayment` (`id`) ON UPDATE CASCADE,
  ADD CONSTRAINT `FK_schoolstupaymentscheddetail_schoolstudent` FOREIGN KEY (`schoolstudent`) REFERENCES `schoolstudent` (`id`) ON UPDATE CASCADE,
  ADD CONSTRAINT `FK_schoolstupaymentscheddetail_schoolsubclass` FOREIGN KEY (`schoolsubclass`) REFERENCES `schoolsubclass` (`id`) ON UPDATE CASCADE;

ALTER TABLE `schoolsubclass`
  ADD CONSTRAINT `FK_schoolsubclass_schoolclass` FOREIGN KEY (`schoolclass`) REFERENCES `schoolclass` (`id`) ON UPDATE CASCADE,
  ADD CONSTRAINT `FK_schoolsubclass_schoolteacher` FOREIGN KEY (`homeroomteacher`) REFERENCES `schoolteacher` (`id`) ON UPDATE CASCADE;

ALTER TABLE `servicedoer`
  ADD CONSTRAINT `servicedoer_ibfk_1` FOREIGN KEY (`servicedoergroup`) REFERENCES `servicedoergroup` (`id`) ON UPDATE CASCADE,
  ADD CONSTRAINT `servicedoer_ibfk_2` FOREIGN KEY (`payablecommacc`) REFERENCES `account` (`id`) ON UPDATE CASCADE,
  ADD CONSTRAINT `servicedoer_ibfk_3` FOREIGN KEY (`expensecommacc`) REFERENCES `account` (`id`) ON UPDATE CASCADE;

ALTER TABLE `servicedoercommperiod`
  ADD CONSTRAINT `servicedoercommperiod_ibfk_1` FOREIGN KEY (`salaryid`) REFERENCES `salaries` (`id`) ON UPDATE CASCADE,
  ADD CONSTRAINT `servicedoercommperiod_ibfk_2` FOREIGN KEY (`division`) REFERENCES `division` (`id`) ON UPDATE CASCADE;

ALTER TABLE `servicedoercommvarrecords`
  ADD CONSTRAINT `servicedoercommvarrecords_ibfk_1` FOREIGN KEY (`periodid`) REFERENCES `servicedoercommperiod` (`id`) ON UPDATE CASCADE;

ALTER TABLE `servicedoerdetail`
  ADD CONSTRAINT `servicedoerdetail_ibfk_1` FOREIGN KEY (`groupid`) REFERENCES `servicedoer` (`id`) ON UPDATE CASCADE,
  ADD CONSTRAINT `servicedoerdetail_ibfk_2` FOREIGN KEY (`servicedoerid`) REFERENCES `servicedoer` (`id`) ON UPDATE CASCADE;

ALTER TABLE `servicedoergroup`
  ADD CONSTRAINT `servicedoergroup_ibfk_1` FOREIGN KEY (`payablecommacc`) REFERENCES `account` (`id`) ON UPDATE CASCADE,
  ADD CONSTRAINT `servicedoergroup_ibfk_2` FOREIGN KEY (`expensecommacc`) REFERENCES `account` (`id`) ON UPDATE CASCADE;

ALTER TABLE `servicedoerrecorddetail`
  ADD CONSTRAINT `servicedoerrecorddetail_ibfk_1` FOREIGN KEY (`servicedoerid`) REFERENCES `servicedoer` (`id`) ON UPDATE CASCADE,
  ADD CONSTRAINT `servicedoerrecorddetail_ibfk_2` FOREIGN KEY (`productid`) REFERENCES `product` (`id`) ON UPDATE CASCADE,
  ADD CONSTRAINT `servicedoerrecorddetail_ibfk_3` FOREIGN KEY (`periodid`) REFERENCES `servicedoercommperiod` (`id`) ON UPDATE CASCADE;

ALTER TABLE `servicedoerrecords`
  ADD CONSTRAINT `servicedoerrecords_ibfk_1` FOREIGN KEY (`servicedoerid`) REFERENCES `servicedoer` (`id`) ON UPDATE CASCADE,
  ADD CONSTRAINT `servicedoerrecords_ibfk_2` FOREIGN KEY (`periodid`) REFERENCES `servicedoercommperiod` (`id`) ON UPDATE CASCADE;

ALTER TABLE `slidedata`
  ADD CONSTRAINT `FK_slidedata_slide` FOREIGN KEY (`slideid`) REFERENCES `customerdisplay` (`id`) ON UPDATE CASCADE;

ALTER TABLE `slideelements`
  ADD CONSTRAINT `FK_slideelements_slidedata` FOREIGN KEY (`slidedataid`) REFERENCES `slidedata` (`id`) ON UPDATE CASCADE;

ALTER TABLE `supplier`
  ADD CONSTRAINT `supplier_ibfk_1` FOREIGN KEY (`suppliergroup`) REFERENCES `suppliergroup` (`id`) ON UPDATE CASCADE,
  ADD CONSTRAINT `supplier_ibfk_2` FOREIGN KEY (`payableacc`) REFERENCES `account` (`id`) ON UPDATE CASCADE,
  ADD CONSTRAINT `supplier_ibfk_3` FOREIGN KEY (`rewardacc`) REFERENCES `account` (`id`) ON UPDATE CASCADE,
  ADD CONSTRAINT `supplier_ibfk_4` FOREIGN KEY (`purchasediscacc`) REFERENCES `account` (`id`) ON UPDATE CASCADE,
  ADD CONSTRAINT `supplier_ibfk_5` FOREIGN KEY (`gainlosspayableacc`) REFERENCES `account` (`id`) ON UPDATE CASCADE,
  ADD CONSTRAINT `supplier_ibfk_6` FOREIGN KEY (`accruedpayableacc`) REFERENCES `account` (`id`) ON UPDATE CASCADE;

ALTER TABLE `supplierbalance`
  ADD CONSTRAINT `FK_supplierbalance_division` FOREIGN KEY (`division`) REFERENCES `division` (`id`) ON UPDATE CASCADE,
  ADD CONSTRAINT `supplierbalance_ibfk_1` FOREIGN KEY (`supplierid`) REFERENCES `supplier` (`id`) ON UPDATE CASCADE;

ALTER TABLE `supplierdp`
  ADD CONSTRAINT `supplierdp_ibfk_1` FOREIGN KEY (`division`) REFERENCES `division` (`id`) ON UPDATE CASCADE,
  ADD CONSTRAINT `supplierdp_ibfk_2` FOREIGN KEY (`supplierid`) REFERENCES `supplier` (`id`) ON UPDATE CASCADE,
  ADD CONSTRAINT `supplierdp_ibfk_3` FOREIGN KEY (`paymenttype`) REFERENCES `paymenttype` (`id`) ON UPDATE CASCADE,
  ADD CONSTRAINT `supplierdp_ibfk_4` FOREIGN KEY (`downpaymenttype`) REFERENCES `paymenttype` (`id`) ON UPDATE CASCADE;

ALTER TABLE `suppliergiro`
  ADD CONSTRAINT `suppliergiro_ibfk_1` FOREIGN KEY (`supplierid`) REFERENCES `supplier` (`id`) ON UPDATE CASCADE,
  ADD CONSTRAINT `suppliergiro_ibfk_2` FOREIGN KEY (`division`) REFERENCES `division` (`id`) ON UPDATE CASCADE,
  ADD CONSTRAINT `suppliergiro_ibfk_3` FOREIGN KEY (`paymenttype`) REFERENCES `paymenttype` (`id`) ON UPDATE CASCADE;

ALTER TABLE `suppliergroup`
  ADD CONSTRAINT `suppliergroup_ibfk_1` FOREIGN KEY (`payableacc`) REFERENCES `account` (`id`) ON UPDATE CASCADE,
  ADD CONSTRAINT `suppliergroup_ibfk_3` FOREIGN KEY (`rewardacc`) REFERENCES `account` (`id`) ON UPDATE CASCADE,
  ADD CONSTRAINT `suppliergroup_ibfk_4` FOREIGN KEY (`purchasediscacc`) REFERENCES `account` (`id`) ON UPDATE CASCADE,
  ADD CONSTRAINT `suppliergroup_ibfk_5` FOREIGN KEY (`gainlosspayableacc`) REFERENCES `account` (`id`) ON UPDATE CASCADE,
  ADD CONSTRAINT `suppliergroup_ibfk_6` FOREIGN KEY (`accruedpayableacc`) REFERENCES `account` (`id`) ON UPDATE CASCADE;

ALTER TABLE `tableroles`
  ADD CONSTRAINT `FK_tableroles_roles` FOREIGN KEY (`roles`) REFERENCES `roles` (`id`) ON UPDATE CASCADE;

ALTER TABLE `taxes`
  ADD CONSTRAINT `taxes_ibfk_1` FOREIGN KEY (`taxoutacc`) REFERENCES `account` (`id`) ON UPDATE CASCADE,
  ADD CONSTRAINT `taxes_ibfk_2` FOREIGN KEY (`taxinacc`) REFERENCES `account` (`id`) ON UPDATE CASCADE;

ALTER TABLE `trackemployee`
  ADD CONSTRAINT `FK_trackemployee_attendance` FOREIGN KEY (`attendanceid`) REFERENCES `attendance` (`id`) ON UPDATE CASCADE,
  ADD CONSTRAINT `FK_trackemployee_employee` FOREIGN KEY (`employeeid`) REFERENCES `employee` (`id`) ON UPDATE CASCADE;

ALTER TABLE `units`
  ADD CONSTRAINT `productunit_ibfk_1` FOREIGN KEY (`productid`) REFERENCES `product` (`id`) ON UPDATE CASCADE;

ALTER TABLE `users`
  ADD CONSTRAINT `FK_users_roles` FOREIGN KEY (`roles`) REFERENCES `roles` (`id`) ON UPDATE CASCADE;

ALTER TABLE `vehicle`
  ADD CONSTRAINT `fk_vehicle_departement` FOREIGN KEY (`departement`) REFERENCES `departement` (`id`) ON UPDATE CASCADE,
  ADD CONSTRAINT `fk_vehicle_division` FOREIGN KEY (`division`) REFERENCES `division` (`id`) ON UPDATE CASCADE,
  ADD CONSTRAINT `fk_vehicle_driver` FOREIGN KEY (`defaultdriverid`) REFERENCES `employee` (`id`) ON UPDATE CASCADE,
  ADD CONSTRAINT `fk_vehicle_fueltype` FOREIGN KEY (`fueltypeid`) REFERENCES `vehiclefueltype` (`id`) ON UPDATE CASCADE,
  ADD CONSTRAINT `fk_vehicle_model` FOREIGN KEY (`modelid`) REFERENCES `vehiclemodel` (`id`) ON UPDATE CASCADE;

ALTER TABLE `vehicledocument`
  ADD CONSTRAINT `fk_vehicledocument_vehicle` FOREIGN KEY (`vehicleid`) REFERENCES `vehicle` (`id`) ON UPDATE CASCADE;

ALTER TABLE `vehiclefuellog`
  ADD CONSTRAINT `fk_vehiclefuellog_departement` FOREIGN KEY (`departement`) REFERENCES `departement` (`id`) ON UPDATE CASCADE,
  ADD CONSTRAINT `fk_vehiclefuellog_division` FOREIGN KEY (`division`) REFERENCES `division` (`id`) ON UPDATE CASCADE,
  ADD CONSTRAINT `fk_vehiclefuellog_driver` FOREIGN KEY (`driverid`) REFERENCES `employee` (`id`) ON UPDATE CASCADE,
  ADD CONSTRAINT `fk_vehiclefuellog_fueltype` FOREIGN KEY (`fueltypeid`) REFERENCES `vehiclefueltype` (`id`) ON UPDATE CASCADE,
  ADD CONSTRAINT `fk_vehiclefuellog_tripid` FOREIGN KEY (`tripid`) REFERENCES `vehicletrip` (`id`) ON UPDATE CASCADE,
  ADD CONSTRAINT `fk_vehiclefuellog_vehicle` FOREIGN KEY (`vehicleid`) REFERENCES `vehicle` (`id`) ON UPDATE CASCADE,
  ADD CONSTRAINT `fk_vehiclefuellog_vendor` FOREIGN KEY (`vendorid`) REFERENCES `supplier` (`id`) ON UPDATE CASCADE;

ALTER TABLE `vehiclefueltype`
  ADD CONSTRAINT `FK_vehiclefueltype_expenseacc` FOREIGN KEY (`expenseacc`) REFERENCES `account` (`id`) ON UPDATE CASCADE,
  ADD CONSTRAINT `FK_vehiclefueltype_product` FOREIGN KEY (`productid`) REFERENCES `product` (`id`) ON UPDATE CASCADE;

ALTER TABLE `vehiclemaintenance`
  ADD CONSTRAINT `fk_vehiclemaintenance_category` FOREIGN KEY (`categoryid`) REFERENCES `vehiclemaintenancecategory` (`id`) ON UPDATE CASCADE,
  ADD CONSTRAINT `fk_vehiclemaintenance_departement` FOREIGN KEY (`departement`) REFERENCES `departement` (`id`) ON UPDATE CASCADE,
  ADD CONSTRAINT `fk_vehiclemaintenance_division` FOREIGN KEY (`division`) REFERENCES `division` (`id`) ON UPDATE CASCADE,
  ADD CONSTRAINT `fk_vehiclemaintenance_requestedby` FOREIGN KEY (`requestedby`) REFERENCES `employee` (`id`) ON UPDATE CASCADE,
  ADD CONSTRAINT `fk_vehiclemaintenance_vehicle` FOREIGN KEY (`vehicleid`) REFERENCES `vehicle` (`id`) ON UPDATE CASCADE,
  ADD CONSTRAINT `fk_vehiclemaintenance_vendor` FOREIGN KEY (`vendorid`) REFERENCES `supplier` (`id`) ON UPDATE CASCADE;

ALTER TABLE `vehiclemaintenancecategory`
  ADD CONSTRAINT `FK_vehiclemaintenancecategory_account` FOREIGN KEY (`expenseacc`) REFERENCES `account` (`id`) ON UPDATE CASCADE;

ALTER TABLE `vehiclemaintenancepart`
  ADD CONSTRAINT `FK_vehiclemaintenancepart_vehiclemaintenance` FOREIGN KEY (`maintenanceid`) REFERENCES `vehiclemaintenance` (`id`) ON UPDATE CASCADE,
  ADD CONSTRAINT `fk_vehiclemaintenancepart_product` FOREIGN KEY (`productid`) REFERENCES `product` (`id`) ON UPDATE CASCADE;

ALTER TABLE `vehiclemodel`
  ADD CONSTRAINT `fk_vehiclemodel_brand` FOREIGN KEY (`brandid`) REFERENCES `vehiclebrand` (`id`) ON UPDATE CASCADE,
  ADD CONSTRAINT `fk_vehiclemodel_fueltype` FOREIGN KEY (`defaultfueltypeid`) REFERENCES `vehiclefueltype` (`id`) ON UPDATE CASCADE,
  ADD CONSTRAINT `fk_vehiclemodel_type` FOREIGN KEY (`vehicletypeid`) REFERENCES `vehicletype` (`id`) ON UPDATE CASCADE;

ALTER TABLE `vehicletrip`
  ADD CONSTRAINT `fk_vehicletrip_departement` FOREIGN KEY (`departement`) REFERENCES `departement` (`id`) ON UPDATE CASCADE,
  ADD CONSTRAINT `fk_vehicletrip_division` FOREIGN KEY (`division`) REFERENCES `division` (`id`) ON UPDATE CASCADE,
  ADD CONSTRAINT `fk_vehicletrip_driver` FOREIGN KEY (`driverid`) REFERENCES `employee` (`id`) ON UPDATE CASCADE,
  ADD CONSTRAINT `fk_vehicletrip_fueltypeid` FOREIGN KEY (`fueltypeid`) REFERENCES `vehiclefueltype` (`id`) ON UPDATE CASCADE,
  ADD CONSTRAINT `fk_vehicletrip_route` FOREIGN KEY (`routeid`) REFERENCES `vehicleroute` (`id`) ON UPDATE CASCADE,
  ADD CONSTRAINT `fk_vehicletrip_vehicle` FOREIGN KEY (`vehicleid`) REFERENCES `vehicle` (`id`) ON UPDATE CASCADE;

/*!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 */;
