CREATE TABLE `paymentproposal` (
  `paymentkey` int(11) unsigned NOT NULL auto_increment,
  `paymentcode` varchar(20) NOT NULL default '',
  `cashbooktypecode` varchar(20) NOT NULL default '',
  `paymentdate` date default NULL,
  `paymentacccode` varchar(20) NOT NULL default '',
  `acccode` varchar(20) NOT NULL default '',
  `payto` varchar(50) NOT NULL default '',
  `descr` varchar(200) NOT NULL default '',
  `chequeno` varchar(20) NOT NULL default '',
  `multi` enum('Y','N') NOT NULL default 'N',
  `amount` decimal(20,2) NOT NULL default '0.00',
  `staffcode` varchar(20) NOT NULL default '',
  `areacode` varchar(20) NOT NULL default '',
  `remark1` varchar(200) NOT NULL,
  `remark2` varchar(200) NOT NULL,
  `remark3` varchar(200) NOT NULL,
  `remark4` varchar(200) NOT NULL,
  `remark5` varchar(200) NOT NULL,
  `remark6` varchar(200) NOT NULL,
  `remark7` varchar(200) NOT NULL,
  `remark8` varchar(200) NOT NULL,
  `note` mediumtext,
  `departmentcode` varchar(20) NOT NULL default '',
  `jobcode` varchar(20) NOT NULL default '',
  `cancelled` enum('Y','N') NOT NULL default 'N',
  `cancelledremark` varchar(200) NOT NULL,
  `done` enum('Y','N') NOT NULL default 'N',
  `curcode` varchar(20) NOT NULL,
  `currate` decimal(20,8) unsigned NOT NULL default '1.00000000',
  `localamount` decimal(20,2) NOT NULL default '0.00',
  `bankchargeacccode` varchar(20) NOT NULL default '',
  `bcurcode` varchar(20) NOT NULL default '',
  `bcurrate` decimal(20,8) unsigned NOT NULL default '1.00000000',
  `bamount` decimal(20,2) NOT NULL default '0.00',
  `bankcharges` decimal(20,2) NOT NULL default '0.00',
  `blocalcurrate` decimal(20,8) unsigned NOT NULL default '1.00000000',
  `blocalamount` decimal(20,2) NOT NULL default '0.00',
  `localbankcharges` decimal(20,2) NOT NULL default '0.00',
  `lastmodified` timestamp NOT NULL default CURRENT_TIMESTAMP on update CURRENT_TIMESTAMP,
  `approval` enum('Y','N') NOT NULL default 'N',
  `approvalby` varchar(20) NOT NULL,
  `approvaldatetime` datetime default NULL,
  `approvalremark` mediumtext,
  `generated` enum('Y','N') NOT NULL default 'N',
  `actualpaymentcode` varchar(20) NOT NULL default '',
  PRIMARY KEY  (`paymentkey`),
  UNIQUE KEY `ipcode` (`paymentcode`),
  KEY `ippdate` (`paymentdate`),
  KEY `ipppaymentacccode` (`paymentacccode`),
  KEY `ippacccode` (`acccode`),
  KEY `ippchequeno` (`chequeno`),
  KEY `ippmulti` (`multi`),
  KEY `ippdepartmentcode` (`departmentcode`),
  KEY `ippstaffcode` (`staffcode`),
  KEY `ippareacode` (`areacode`),
  KEY `ippcancelled` (`cancelled`),
  KEY `ippcurcode` (`curcode`),
  KEY `ippcashbooktypecode` (`cashbooktypecode`),
  KEY `ippjobcode` (`jobcode`),
  KEY `ippbankchargeacccode` (`bankchargeacccode`),
  KEY `ippbcurcode` (`bcurcode`),
  KEY `ippactualpaymentcode` (`actualpaymentcode`)
) ENGINE=INNODB DEFAULT CHARSET=latin1;

CREATE TABLE `pickinglist` (
  `pickinglistkey` int(11) unsigned NOT NULL auto_increment,
  `pickinglistcode` varchar(20) NOT NULL default '',
  `pickinglistdate` date default NULL,
  `refno` varchar(20) NOT NULL default '',
  `vehicleno` varchar(20) NOT NULL default '',
  `transporter` varchar(20) NOT NULL default '',
  `descr` varchar(200) NOT NULL default '',
  `note` mediumtext,
  `dolist` mediumtext,
  `invlist` mediumtext,
  `created` datetime default NULL,
  `modified` datetime default NULL,
  `done` enum('Y','N') NOT NULL default 'N',
  PRIMARY KEY  (`pickinglistkey`),
  UNIQUE KEY `iplcode` (`pickinglistcode`),
  KEY `ipldate` (`pickinglistdate`),
  KEY `iplrefno` (`refno`)
) ENGINE=INNODB DEFAULT CHARSET=latin1;

CREATE TABLE `pickinglistdoc` (
  `pickinglistkey` int(11) unsigned NOT NULL default '0',
  `pos` int(11) unsigned NOT NULL default '0',
  `pickinglistcode` varchar(20) NOT NULL default '',
  `doctype` varchar(5) NOT NULL default '',
  `docno` varchar(30) NOT NULL default '',
  PRIMARY KEY  (`pickinglistkey`,`pos`),
  KEY `ipldcode` (`pickinglistcode`),
  KEY `ipliddocno` (`docno`)
) ENGINE=INNODB DEFAULT CHARSET=latin1;

CREATE TABLE `pickinglistitem` (
  `pickinglistkey` int(11) unsigned NOT NULL default '0',
  `pickinglistcode` varchar(20) NOT NULL default '',
  `itemno` int(11) unsigned NOT NULL default '0',
  `stockcode` varchar(30) NOT NULL default '',
  `descr` varchar(200) NOT NULL default '',
  `qty` decimal(20,6) default NULL,
  `uom` varchar(20) NOT NULL default '',
  `stockpackagecode` varchar(20) NOT NULL,
  PRIMARY KEY  (`pickinglistkey`,`itemno`),
  KEY `iplicode` (`pickinglistcode`),
  KEY `iplistockcode` (`stockcode`),
  KEY `iplistockpackagecode` (`stockpackagecode`)
) ENGINE=INNODB DEFAULT CHARSET=latin1;

CREATE TABLE `presetacc` (
  `presetacckey` int(11) unsigned NOT NULL auto_increment,
  `presetacccode` varchar(20) NOT NULL default '',
  `descr` varchar(200) NOT NULL default '',
  `category` enum('GL','DEBTOR','CREDITOR','SALES','PURCHASES','STOCK') NOT NULL default 'GL',
  `acccode` varchar(20) NOT NULL default '',
  `module` int(10) unsigned NOT NULL default '1',
  PRIMARY KEY  (`presetacckey`),
  UNIQUE KEY `iacode` (`presetacccode`)
) ENGINE=INNODB DEFAULT CHARSET=latin1;

CREATE TABLE `presetreceiptno` (
  `presetreceiptnokey` int(11) unsigned NOT NULL auto_increment,
  `presetreceiptnocode` varchar(20) NOT NULL default '',
  `staffcode` varchar(20) NOT NULL default '',
  `descr` varchar(200) NOT NULL default '',
  `prefix` varchar(20) NOT NULL default '',
  `suffix` varchar(20) NOT NULL default '',
  `noofdigit` int(11) unsigned NOT NULL default '0',
  `receiptnofrom` int(11) unsigned NOT NULL default '0',
  `receiptnoto` int(11) unsigned NOT NULL default '0',
  `inactive` enum('Y','N') NOT NULL default 'N',
  `done` enum('Y','N') NOT NULL default 'N',
  `lastmodified` timestamp NOT NULL default CURRENT_TIMESTAMP on update CURRENT_TIMESTAMP,
  PRIMARY KEY  (`presetreceiptnokey`),
  UNIQUE KEY `iprncode` (`presetreceiptnocode`),
  KEY `iprnstaffcode` (`staffcode`),
  KEY `iprninactive` (`inactive`)
) ENGINE=INNODB DEFAULT CHARSET=latin1;

CREATE TABLE `pricebook` (
  `pricebookkey` int(11) unsigned NOT NULL auto_increment,
  `alldebtor` enum('Y','N') NOT NULL default 'N',
  `debtorcode` varchar(20) NOT NULL default '',
  `categorycode` varchar(20) NOT NULL default '',
  `groupcode` varchar(20) NOT NULL default '',
  `pricecategorycode` varchar(20) NOT NULL default '',
  `pricecategorypos` smallint(5) unsigned NOT NULL default '0',
  `stockcode` varchar(30) NOT NULL default '',
  `stockcategorycode` varchar(20) NOT NULL default '',
  `allstocklocation` enum('Y','N') NOT NULL default 'Y',
  `stocklocationcode` varchar(20) NOT NULL default '',
  `uom` varchar(20) NOT NULL default '',
  `alluom` enum('Y','N') NOT NULL default 'N',
  `pricetype` enum('PRICE','DISCOUNT','MARKUP','PRICEDISCOUNT') NOT NULL default 'PRICE',
  `unitprice` decimal(20,6) NOT NULL default '0.000000',
  `discountformat` varchar(100) default NULL,
  `markup` decimal(20,2) default NULL,
  `minimumqty` decimal(20,6) default NULL,
  `inactive` enum('Y','N') NOT NULL default 'N',
  `lastmodified` timestamp NOT NULL default CURRENT_TIMESTAMP on update CURRENT_TIMESTAMP,
  PRIMARY KEY  (`pricebookkey`),
  KEY `ipbkstockcodeuom` (`stockcode`,`uom`),
  KEY `ipbkalldebtor` (`alldebtor`),
  KEY `ipbkdebtorcode` (`debtorcode`),
  KEY `ipbkcategorycode` (`categorycode`),
  KEY `ipbkstockcategorycode` (`stockcategorycode`),
  KEY `ipbkallstocklocation` (`allstocklocation`),
  KEY `ipbkstocklocationcode` (`stocklocationcode`),
  KEY `ipbkalluom` (`alluom`),
  KEY `ipbkpricecategorycode` (`pricecategorycode`),
  KEY `ipbkgroupcode` (`groupcode`)
) ENGINE=INNODB DEFAULT CHARSET=latin1;

CREATE TABLE `pricebookadvance` (
  `pricebookadvancekey` int(11) unsigned NOT NULL auto_increment,
  `pricebookadvancecode` varchar(20) NOT NULL default '',
  `descr` varchar(200) NOT NULL default '',
  `datefrom` date NOT NULL default '0000-00-00',
  `dateto` date NOT NULL default '0000-00-00',
  `inactive` enum('Y','N') NOT NULL default 'N',
  `done` enum('Y','N') NOT NULL default 'N',
  `lastmodified` timestamp NOT NULL default CURRENT_TIMESTAMP on update CURRENT_TIMESTAMP,
  PRIMARY KEY  (`pricebookadvancekey`),
  UNIQUE KEY `ipbkapricebookadvancecode` (`pricebookadvancecode`),
  KEY `ipbkadatefromto` (`datefrom`,`dateto`),
  KEY `ipbkadateto` (`dateto`)
) ENGINE=INNODB DEFAULT CHARSET=latin1;

CREATE TABLE `pricebookadvanceitem` (
  `pricebookadvancekey` int(11) unsigned NOT NULL default '0',
  `pricebookadvancecode` varchar(20) NOT NULL default '',
  `pos` int(11) unsigned NOT NULL default '0',
  `alldebtor` enum('Y','N') NOT NULL default 'N',
  `debtorcode` varchar(20) NOT NULL default '',
  `categorycode` varchar(20) NOT NULL default '',
  `allstocklocation` enum('Y','N') NOT NULL default 'Y',
  `stocklocationcode` varchar(20) NOT NULL default '',
  `stockcode` varchar(30) NOT NULL default '',
  `stockcategorycode` varchar(20) NOT NULL default '',
  `stockgroupcode` varchar(20) NOT NULL default '',
  `stockclasscode` varchar(20) NOT NULL default '',
  `stockbrandcode` varchar(20) NOT NULL default '',
  `stockmodelcode` varchar(20) NOT NULL default '',
  `uom` varchar(20) NOT NULL default '',
  `alluom` enum('Y','N') NOT NULL default 'N',
  `pricetype` enum('PRICE','DISCOUNT','MARKUP','PRICEDISCOUNT') NOT NULL default 'PRICE',
  `unitprice` decimal(20,6) NOT NULL default '0.000000',
  `discountformat` varchar(100) NOT NULL default '',
  `markup` decimal(20,2) default NULL,
  `minimumqty` decimal(20,6) default NULL,
  PRIMARY KEY  (`pricebookadvancekey`,`pos`),
  UNIQUE KEY `ipbkaicodepos` (`pricebookadvancecode`,`pos`),
  KEY `ipbkaialldebtor` (`alldebtor`),
  KEY `ipbkaidebtorcode` (`debtorcode`),
  KEY `ipbkaicategorycode` (`categorycode`),
  KEY `ipbkaiallstocklocation` (`allstocklocation`),
  KEY `ipbkaistocklocationcode` (`stocklocationcode`),
  KEY `ipbkaistockcode` (`stockcode`),
  KEY `ipbkaistockcategorycode` (`stockcategorycode`),
  KEY `ipbkaistockgroupcode` (`stockgroupcode`),
  KEY `ipbkaistockclasscode` (`stockclasscode`),
  KEY `ipbkaistockbrandcode` (`stockbrandcode`),
  KEY `ipbkaistockmodelcode` (`stockmodelcode`),
  KEY `ipbkaiuom` (`uom`),
  KEY `ipbkaialluom` (`alluom`)
) ENGINE=INNODB DEFAULT CHARSET=latin1;

CREATE TABLE `pricecategory` (
  `pricecategorykey` int(11) unsigned NOT NULL auto_increment,
  `pricecategorycode` varchar(20) NOT NULL default '',
  `descr` varchar(200) NOT NULL default '',
  `inactive` enum('Y','N') NOT NULL default 'N',
  `done` enum('Y','N') NOT NULL default 'N',
  `lastmodified` timestamp NOT NULL default CURRENT_TIMESTAMP on update CURRENT_TIMESTAMP,
  PRIMARY KEY  (`pricecategorykey`),
  UNIQUE KEY `iccode` (`pricecategorycode`),
  KEY `ipcatinactive` (`inactive`)
) ENGINE=INNODB DEFAULT CHARSET=latin1;

CREATE TABLE `privilege` (
  `privcode` varchar(50) NOT NULL default '',
  `descr` varchar(100) NOT NULL default '',
  `privcategory` varchar(50) NOT NULL default '',
  `privtype` varchar(50) NOT NULL default '',
  `module` int(10) unsigned NOT NULL default '1',
  `priv1` varchar(30) NOT NULL default '',
  `priv2` varchar(30) NOT NULL default '',
  `priv3` varchar(30) NOT NULL default '',
  `priv4` varchar(30) NOT NULL default '',
  `priv5` varchar(30) NOT NULL default '',
  `priv6` varchar(30) NOT NULL default '',
  `priv7` varchar(30) NOT NULL default '',
  `priv8` varchar(30) NOT NULL default '',
  `priv9` varchar(30) NOT NULL default '',
  `priv10` varchar(30) NOT NULL default '',
  `priv11` varchar(30) NOT NULL default '',
  `priv12` varchar(30) NOT NULL default '',
  `priv13` varchar(30) NOT NULL default '',
  `priv14` varchar(30) NOT NULL default '',
  `priv15` varchar(30) NOT NULL default '',
  `priv16` varchar(30) NOT NULL default '',
  `priv17` varchar(30) NOT NULL default '',
  `priv18` varchar(30) NOT NULL default '',
  `priv19` varchar(30) NOT NULL default '',
  `priv20` varchar(30) NOT NULL default '',
  `priv21` varchar(30) NOT NULL default '',
  `priv22` varchar(30) NOT NULL default '',
  `priv23` varchar(30) NOT NULL default '',
  `priv24` varchar(30) NOT NULL default '',
  `priv25` varchar(30) NOT NULL default '',
  `compname` varchar(100) NOT NULL default '',
  `usercategory` int(10) unsigned NOT NULL default '1',
  PRIMARY KEY  (`privcode`),
  UNIQUE KEY `iprivdescr` (`descr`),
  KEY `iprivcategory` (`privcategory`)
) ENGINE=INNODB DEFAULT CHARSET=latin1;

CREATE TABLE `promoter` (
  `promoterkey` int(11) unsigned NOT NULL auto_increment,
  `promotercode` varchar(20) NOT NULL default '',
  `descr` varchar(200) NOT NULL default '',
  `inactive` enum('Y','N') NOT NULL default 'N',
  `commission` decimal(20,2) NOT NULL default '0.00',
  `iscommissionbystockgroup` enum('Y','N') NOT NULL default 'N',
  `promotercommissionbystockgroupcode` varchar(200) NOT NULL default '',
  `done` enum('Y','N') NOT NULL default 'N',
  `lastmodified` timestamp NOT NULL default CURRENT_TIMESTAMP on update CURRENT_TIMESTAMP,
  PRIMARY KEY  (`promoterkey`),
  UNIQUE KEY `ipmtcode` (`promotercode`),
  KEY `ipmtinactive` (`inactive`),
  KEY `ippromotercommissionbystockgroupcode` (`promotercommissionbystockgroupcode`)
) ENGINE=INNODB DEFAULT CHARSET=latin1;

CREATE TABLE `promotercommissionbystockgroup` (
  `promotercommissionbystockgroupkey` int(11) unsigned NOT NULL auto_increment,
  `promotercommissionbystockgroupcode` varchar(20) NOT NULL default '',
  `descr` varchar(200) NOT NULL default '',
  PRIMARY KEY  (`promotercommissionbystockgroupkey`),
  UNIQUE KEY `icmbaode` (`promotercommissionbystockgroupcode`)
) ENGINE=INNODB DEFAULT CHARSET=latin1;

CREATE TABLE `promotercommissionbystockgroupitem` (
  `promotercommissionbystockgroupcode` varchar(20) NOT NULL default '',
  `stockgroupcode` varchar(20) NOT NULL default '',
  `commissionpercent` decimal(20,2) NOT NULL default '0.00',
  PRIMARY KEY  (`promotercommissionbystockgroupcode`,`stockgroupcode`)
) ENGINE=INNODB DEFAULT CHARSET=latin1;

CREATE TABLE `promotionbook` (
  `promotionbookkey` int(11) unsigned NOT NULL auto_increment,
  `promotionbookcode` varchar(20) NOT NULL default '',
  `descr` varchar(200) NOT NULL default '',
  `datefrom` date NOT NULL default '0000-00-00',
  `dateto` date NOT NULL default '0000-00-00',
  `disablememberdiscount` enum('Y','N') NOT NULL default 'Y',
  `done` enum('Y','N') NOT NULL default 'N',
  `lastmodified` timestamp NOT NULL default CURRENT_TIMESTAMP on update CURRENT_TIMESTAMP,
  PRIMARY KEY  (`promotionbookkey`),
  UNIQUE KEY `ipmbkpromotionbookcode` (`promotionbookcode`),
  KEY `ipmbkdatefromto` (`datefrom`,`dateto`),
  KEY `ipmbkdateto` (`dateto`)
) ENGINE=INNODB DEFAULT CHARSET=latin1;

CREATE TABLE `promotionbookitem` (
  `promotionbookkey` int(10) unsigned NOT NULL default '0',
  `promotionbookcode` varchar(20) NOT NULL default '',
  `pos` int(11) unsigned NOT NULL default '0',
  `allstocklocation` enum('Y','N') NOT NULL default 'Y',
  `stocklocationcode` varchar(20) NOT NULL default '',
  `stockcode` varchar(30) NOT NULL default '',
  `stockcategorycode` varchar(20) NOT NULL default '',
  `stockgroupcode` varchar(20) NOT NULL default '',
  `stockclasscode` varchar(20) NOT NULL default '',
  `stockbrandcode` varchar(20) NOT NULL default '',
  `stockmodelcode` varchar(20) NOT NULL default '',
  `membertypecode` varchar(20) NOT NULL,
  `uom` varchar(20) NOT NULL default '',
  `alluom` enum('Y','N') NOT NULL default 'N',
  `pricetype` enum('PRICE','DISCOUNT') NOT NULL default 'PRICE',
  `unitprice` decimal(20,6) NOT NULL default '0.000000',
  `discountformat` varchar(100) NOT NULL default '',
  `minimumqty` decimal(20,6) default NULL,
  PRIMARY KEY  (`promotionbookkey`,`pos`),
  UNIQUE KEY `ipmbkicodepos` (`promotionbookcode`,`pos`),
  KEY `ipmbkiallstocklocation` (`allstocklocation`),
  KEY `ipmbkistocklocationcode` (`stocklocationcode`),
  KEY `ipmbkistockcode` (`stockcode`),
  KEY `ipmbkistockcategorycode` (`stockcategorycode`),
  KEY `ipmbkistockgroupcode` (`stockgroupcode`),
  KEY `ipmbkistockclasscode` (`stockclasscode`),
  KEY `ipmbkistockbrandcode` (`stockbrandcode`),
  KEY `ipmbkistockmodelcode` (`stockmodelcode`),
  KEY `ipmbkiuom` (`uom`),
  KEY `ipmbkialluom` (`alluom`),
  KEY `ipmbkimembertypecode` (`membertypecode`)
) ENGINE=INNODB DEFAULT CHARSET=latin1;

CREATE TABLE `promotionitem` (
  `promotionitemkey` int(11) unsigned NOT NULL auto_increment,
  `stockcode` varchar(30) NOT NULL default '',
  `datefrom` date default NULL,
  `dateto` date default NULL,
  `promotiontype` enum('None','Discount','Price','FOC') default NULL,
  `uom` varchar(20) NOT NULL default '',
  `discountpercent1` decimal(20,2) default NULL,
  `discountpercent2` decimal(20,2) default NULL,
  `discountvalue` decimal(20,2) default NULL,
  `unitprice` decimal(20,6) default NULL,
  `minimumqty` decimal(20,6) default '0.000000',
  `focstockcode` varchar(30) NOT NULL default '',
  `foctype` enum('Fixed','Multiply') NOT NULL default 'Fixed',
  `focuom` varchar(20) NOT NULL default '',
  `focqty` decimal(20,6) default NULL,
  `lastmodified` timestamp NOT NULL default CURRENT_TIMESTAMP on update CURRENT_TIMESTAMP,
  PRIMARY KEY  (`promotionitemkey`),
  UNIQUE KEY `ipmtistockcode` (`stockcode`),
  KEY `ipmtidatefromto` (`datefrom`,`dateto`),
  KEY `ipmtidateto` (`dateto`),
  KEY `ipmtiuom` (`uom`),
  KEY `ipmtifocstockcode` (`focstockcode`)
) ENGINE=INNODB DEFAULT CHARSET=latin1;

CREATE TABLE `purchasescn` (
  `purchasescnkey` int(11) unsigned NOT NULL auto_increment,
  `purchasescncode` varchar(20) NOT NULL default '',
  `purchasescndate` date default NULL,
  `creditorcode` varchar(20) NOT NULL default '',
  `staffcode` varchar(20) NOT NULL default '',
  `areacode` varchar(20) NOT NULL default '',
  `descr` varchar(200) NOT NULL default '',
  `validity` varchar(100) NOT NULL default '',
  `deliveryterm` varchar(100) NOT NULL default '',
  `refno` varchar(20) NOT NULL default '',
  `address1` varchar(200) NOT NULL default '',
  `address2` varchar(200) NOT NULL default '',
  `address3` varchar(200) NOT NULL default '',
  `address4` varchar(200) NOT NULL default '',
  `attention` varchar(200) NOT NULL default '',
  `phone` varchar(30) NOT NULL default '',
  `fax` varchar(30) NOT NULL default '',
  `discountamount` decimal(20,2) NOT NULL,
  `amountbeforediscount` decimal(20,2) NOT NULL,
  `amount` decimal(20,2) NOT NULL default '0.00',
  `taxamount` decimal(20,2) NOT NULL default '0.00',
  `amountaftertax` decimal(20,2) NOT NULL default '0.00',
  `localtaxamount` decimal(20,2) NOT NULL default '0.00',
  `localamountaftertax` decimal(20,2) NOT NULL default '0.00',
  `note` mediumtext,
  `remark1` varchar(100) NOT NULL,
  `remark2` varchar(100) NOT NULL,
  `remark3` varchar(100) NOT NULL,
  `remark4` varchar(100) NOT NULL,
  `remark5` varchar(100) NOT NULL,
  `remark6` varchar(100) NOT NULL,
  `remark7` varchar(100) NOT NULL,
  `remark8` varchar(100) NOT NULL,
  `globaldiscountacccode` varchar(20) NOT NULL default '',
  `globalpurchasesacccode` varchar(20) NOT NULL default '',
  `globaltaxacccode` varchar(20) NOT NULL default '',
  `roundingadjacccode` varchar(20) NOT NULL default '',
  `cardchargeacccode` varchar(20) NOT NULL default '',
  `globaldepartment` enum('Y','N') NOT NULL default 'Y',
  `departmentcode` varchar(20) NOT NULL default '',
  `globaljob` enum('Y','N') NOT NULL default 'N',
  `jobcode` varchar(20) NOT NULL default '',
  `globalstocklocation` enum('Y','N') NOT NULL default 'Y',
  `stocklocationcode` varchar(20) NOT NULL default '',
  `cancelled` enum('Y','N') NOT NULL default 'N',
  `itemformatkey` int(11) unsigned NOT NULL default '0',
  `creditorcnkey` int(11) unsigned NOT NULL default '0',
  `created` datetime default NULL,
  `modified` datetime default NULL,
  `done` enum('Y','N') NOT NULL default 'N',
  `curcode` varchar(20) NOT NULL,
  `currate` decimal(20,8) unsigned NOT NULL default '1.00000000',
  `localdiscountamount` decimal(20,2) NOT NULL,
  `localamountbeforediscount` decimal(20,2) NOT NULL,
  `localamount` decimal(20,2) NOT NULL default '0.00',
  `creditorcnno` varchar(30) NOT NULL,
  `ref1` varchar(30) NOT NULL,
  `ref2` varchar(30) NOT NULL,
  `ref3` varchar(30) NOT NULL,
  `ref4` varchar(30) NOT NULL,
  `postaccountvalue` enum('Y','N') NOT NULL default 'Y',
  `poststockvalue` enum('Y','N') NOT NULL default 'Y',
  `postingdate` date default NULL,
  `lastmodified` timestamp NOT NULL default CURRENT_TIMESTAMP on update CURRENT_TIMESTAMP,
  `creditorname` varchar(200) NOT NULL default '',
  `city` varchar(50) NOT NULL default '',
  `postalcode` varchar(10) NOT NULL default '',
  `state` varchar(50) NOT NULL default '',
  `countrycode` varchar(50) NOT NULL default '',
  `branchcode` varchar(20) NOT NULL default '',
  `branchname` varchar(200) NOT NULL default '',
  `branchcontactperson` varchar(200) NOT NULL default '',
  `branchphone` varchar(30) NOT NULL default '',
  `branchfax` varchar(30) NOT NULL default '',
  `branchemail` varchar(200) NOT NULL default '',
  `branchaddress1` varchar(200) NOT NULL default '',
  `branchaddress2` varchar(200) NOT NULL default '',
  `branchaddress3` varchar(200) NOT NULL default '',
  `branchaddress4` varchar(200) NOT NULL default '',
  `branchcity` varchar(50) NOT NULL default '',
  `branchpostalcode` varchar(10) NOT NULL default '',
  `branchstate` varchar(50) NOT NULL default '',
  `branchcountrycode` varchar(50) NOT NULL default '',
  `servicechargeacccode` varchar(20) NOT NULL default '',
  `fromoldversion` enum('Y','N') NOT NULL default 'N',
  PRIMARY KEY  (`purchasescnkey`),
  UNIQUE KEY `ipcncode` (`purchasescncode`),
  KEY `ipcndate` (`purchasescndate`),
  KEY `ipcncreditorcode` (`creditorcode`),
  KEY `ipcnstaffcode` (`staffcode`),
  KEY `ipcnrefno` (`refno`),
  KEY `ipcnglobalpurchasesacccode` (`globalpurchasesacccode`),
  KEY `ipcndepartmentcode` (`departmentcode`),
  KEY `ipcnstocklocationcode` (`stocklocationcode`),
  KEY `ipcncancelled` (`cancelled`),
  KEY `ipcnareacode` (`areacode`),
  KEY `ipcncurcode` (`curcode`),
  KEY `ipcnpostaccountvalue` (`postaccountvalue`),
  KEY `ipcnpoststockvalue` (`poststockvalue`),
  KEY `ipcnpostingdate` (`postingdate`),
  KEY `ipcnjobcode` (`jobcode`),
  KEY `ipcnglobaltaxacccode` (`globaltaxacccode`),
  KEY `ipcnglobaldiscountacccode` (`globaldiscountacccode`),
  KEY `ipcnroundingadjacccode` (`roundingadjacccode`),
  KEY `ipcncardchargeacccode` (`cardchargeacccode`),
  KEY `ipcncountrycode` (`countrycode`),
  KEY `ipcnbranchcountrycode` (`branchcountrycode`),
  KEY `ipcnservicechargeacccode` (`servicechargeacccode`)
) ENGINE=INNODB DEFAULT CHARSET=latin1;

CREATE TABLE `purchasescnid` (
  `purchasescnkey` int(11) unsigned NOT NULL default '0',
  `id` int(11) unsigned NOT NULL default '0',
  PRIMARY KEY  (`purchasescnkey`,`id`)
) ENGINE=INNODB DEFAULT CHARSET=latin1;

CREATE TABLE `purchasescnitem` (
  `purchasescnkey` int(11) unsigned NOT NULL default '0',
  `purchasescncode` varchar(20) NOT NULL default '',
  `id` int(11) unsigned NOT NULL default '0',
  `pos` int(11) unsigned NOT NULL default '0',
  `itemno` varchar(10) NOT NULL default '',
  `stockcode` varchar(30) NOT NULL default '',
  `descr` varchar(200) NOT NULL default '',
  `moredescr` text,
  `qty` decimal(20,6) default NULL,
  `unitprice` decimal(20,6) default NULL,
  `uom` varchar(20) NOT NULL default '',
  `uomrate` double NOT NULL default '1',
  `qtybaseuom` decimal(20,6) NOT NULL default '0.000000',
  `unitpricebaseuom` double NOT NULL default '0',
  `discountformat` varchar(100) default NULL,
  `discountamount` decimal(20,2) default NULL,
  `amountbeforediscount` decimal(20,2) default NULL,
  `amount` decimal(20,2) default NULL,
  `gsttypecode` varchar(20) NOT NULL default '',
  `purchasestaxpercentage` decimal(20,2) default NULL,
  `purchasestaxamount` decimal(20,2) default NULL,
  `amountaftertax` decimal(20,2) default NULL,
  `acccode` varchar(20) NOT NULL default '',
  `departmentcode` varchar(20) NOT NULL default '',
  `jobcode` varchar(20) NOT NULL default '',
  `stocklocationcode` varchar(20) NOT NULL default '',
  `creditoritemcode` varchar(30) NOT NULL default '',
  `barcode` varchar(30) NOT NULL default '',
  `remark1` varchar(100) NOT NULL,
  `remark2` varchar(100) NOT NULL,
  `remark3` varchar(100) NOT NULL,
  `remark4` varchar(100) NOT NULL,
  `rowtype` enum('','TOTALUP','ITEMDISCOUNT','ITEMSERVICETAX','ITEMMISCCHARGES','FOOTERDISCOUNT','FOOTERSERVICETAX','FOOTERMISCCHARGES') NOT NULL,
  `foc` enum('Y','N') NOT NULL default 'N',
  `packingqty` decimal(20,6) default NULL,
  `packinguom` varchar(20) NOT NULL default '',
  `packingrate` decimal(20,6) default NULL,
  `serialno` text,
  `batchno` varchar(30) NOT NULL default '',
  `curcode` varchar(20) NOT NULL default '',
  `curprice` decimal(20,6) default NULL,
  `currate` decimal(20,8) unsigned default NULL,
  `recommendpricebaseuom` decimal(20,6) unsigned NOT NULL default '0.000000',
  `weightrate` decimal(20,6) unsigned NOT NULL default '0.000000',
  `weightuom` varchar(20) NOT NULL default '',
  `weightqty` decimal(20,6) unsigned NOT NULL default '0.000000',
  `weightloosed` decimal(20,6) unsigned NOT NULL default '0.000000',
  `totalweight` decimal(20,6) unsigned NOT NULL default '0.000000',
  `volumerate` decimal(20,6) unsigned NOT NULL default '0.000000',
  `volumeuom` varchar(20) NOT NULL default '',
  `volumeqty` decimal(20,6) unsigned NOT NULL default '0.000000',
  `volumeloosed` decimal(20,6) unsigned NOT NULL default '0.000000',
  `totalvolume` decimal(20,6) unsigned NOT NULL default '0.000000',
  `supplypurchase` enum('None','Supply','Purchase') NOT NULL default 'None',
  `taxsubtract` enum('Y','N') NOT NULL default 'N',
  `taxableamount` decimal(20,2) NOT NULL default '0.00',
  `taxablelocalamount` decimal(20,2) NOT NULL default '0.00',
  `amountaftertaxsubtract` decimal(20,2) NOT NULL default '0.00',
  `localamountaftertaxsubtract` decimal(20,2) NOT NULL default '0.00',
  `purchasestaxlocalamount` decimal(20,2) NOT NULL default '0.00',
  `taxadjustment` decimal(20,2) NOT NULL default '0.00',
  `taxlocaladjustment` decimal(20,2) NOT NULL default '0.00',
  `taxtotalamount` decimal(20,2) NOT NULL default '0.00',
  `taxtotallocalamount` decimal(20,2) NOT NULL default '0.00',
  `ourpocode` varchar(20) NOT NULL default '',
  `ourpodate` date default NULL,
  `taxpermitno` varchar(50) NOT NULL default '',
  `taxacccode` varchar(20) NOT NULL default '',
  `purchasesinvoicecode` varchar(20) NOT NULL default '',
  `purchasesinvoicedate` date default NULL,
  `reason` varchar(200) NOT NULL default '',
  PRIMARY KEY  (`purchasescnkey`,`pos`),
  UNIQUE KEY `ipcnikeyid` (`purchasescnkey`,`id`),
  KEY `ipcnibarcode` (`barcode`),
  KEY `ipcnifoc` (`foc`),
  KEY `ipcnicode` (`purchasescncode`),
  KEY `ipcnistockcode` (`stockcode`),
  KEY `ipcniacccode` (`acccode`),
  KEY `ipcnidepartmentcode` (`departmentcode`),
  KEY `ipcnistocklocationcode` (`stocklocationcode`),
  KEY `ipcnibatchno` (`batchno`),
  KEY `ipcnijobcode` (`jobcode`),
  KEY `ipcnigsttypecode` (`gsttypecode`),
  KEY `ipcniitaxacccode` (`taxacccode`)
) ENGINE=INNODB DEFAULT CHARSET=latin1;

CREATE TABLE `purchasesdn` (
  `purchasesdnkey` int(11) unsigned NOT NULL auto_increment,
  `purchasesdncode` varchar(20) NOT NULL default '',
  `purchasesdndate` date default NULL,
  `creditorcode` varchar(20) NOT NULL default '',
  `termcode` varchar(20) NOT NULL default '',
  `staffcode` varchar(20) NOT NULL default '',
  `areacode` varchar(20) NOT NULL default '',
  `descr` varchar(200) NOT NULL default '',
  `validity` varchar(100) NOT NULL default '',
  `deliveryterm` varchar(100) NOT NULL default '',
  `refno` varchar(20) NOT NULL default '',
  `address1` varchar(200) NOT NULL default '',
  `address2` varchar(200) NOT NULL default '',
  `address3` varchar(200) NOT NULL default '',
  `address4` varchar(200) NOT NULL default '',
  `attention` varchar(200) NOT NULL default '',
  `phone` varchar(30) NOT NULL default '',
  `fax` varchar(30) NOT NULL default '',
  `discountamount` decimal(20,2) NOT NULL,
  `amountbeforediscount` decimal(20,2) NOT NULL,
  `amount` decimal(20,2) NOT NULL default '0.00',
  `taxamount` decimal(20,2) NOT NULL default '0.00',
  `amountaftertax` decimal(20,2) NOT NULL default '0.00',
  `localtaxamount` decimal(20,2) NOT NULL default '0.00',
  `localamountaftertax` decimal(20,2) NOT NULL default '0.00',
  `note` mediumtext,
  `remark1` varchar(100) NOT NULL,
  `remark2` varchar(100) NOT NULL,
  `remark3` varchar(100) NOT NULL,
  `remark4` varchar(100) NOT NULL,
  `remark5` varchar(100) NOT NULL,
  `remark6` varchar(100) NOT NULL,
  `remark7` varchar(100) NOT NULL,
  `remark8` varchar(100) NOT NULL,
  `globaldiscountacccode` varchar(20) NOT NULL default '',
  `globalpurchasesacccode` varchar(20) NOT NULL default '',
  `globaltaxacccode` varchar(20) NOT NULL default '',
  `roundingadjacccode` varchar(20) NOT NULL default '',
  `cardchargeacccode` varchar(20) NOT NULL default '',
  `globaldepartment` enum('Y','N') NOT NULL default 'Y',
  `departmentcode` varchar(20) NOT NULL default '',
  `globaljob` enum('Y','N') NOT NULL default 'N',
  `jobcode` varchar(20) NOT NULL default '',
  `globalstocklocation` enum('Y','N') NOT NULL default 'Y',
  `stocklocationcode` varchar(20) NOT NULL default '',
  `cancelled` enum('Y','N') NOT NULL default 'N',
  `itemformatkey` int(11) unsigned NOT NULL default '0',
  `creditordnkey` int(11) unsigned NOT NULL default '0',
  `created` datetime default NULL,
  `modified` datetime default NULL,
  `done` enum('Y','N') NOT NULL default 'N',
  `lcost1` decimal(20,2) NOT NULL default '0.00',
  `lcost2` decimal(20,2) NOT NULL default '0.00',
  `lcost3` decimal(20,2) NOT NULL default '0.00',
  `curcode` varchar(20) NOT NULL,
  `currate` decimal(20,8) unsigned NOT NULL default '1.00000000',
  `localdiscountamount` decimal(20,2) NOT NULL,
  `localamountbeforediscount` decimal(20,2) NOT NULL,
  `localamount` decimal(20,2) NOT NULL default '0.00',
  `locallcost1` decimal(20,2) NOT NULL default '0.00',
  `locallcost2` decimal(20,2) NOT NULL default '0.00',
  `locallcost3` decimal(20,2) NOT NULL default '0.00',
  `creditordnno` varchar(30) NOT NULL,
  `ref1` varchar(30) NOT NULL,
  `ref2` varchar(30) NOT NULL,
  `ref3` varchar(30) NOT NULL,
  `ref4` varchar(30) NOT NULL,
  `postaccountvalue` enum('Y','N') NOT NULL default 'Y',
  `poststockvalue` enum('Y','N') NOT NULL default 'Y',
  `postingdate` date default NULL,
  `lastmodified` timestamp NOT NULL default CURRENT_TIMESTAMP on update CURRENT_TIMESTAMP,
  `creditorname` varchar(200) NOT NULL default '',
  `city` varchar(50) NOT NULL default '',
  `postalcode` varchar(10) NOT NULL default '',
  `state` varchar(50) NOT NULL default '',
  `countrycode` varchar(50) NOT NULL default '',
  `branchcode` varchar(20) NOT NULL default '',
  `branchname` varchar(200) NOT NULL default '',
  `branchcontactperson` varchar(200) NOT NULL default '',
  `branchphone` varchar(30) NOT NULL default '',
  `branchfax` varchar(30) NOT NULL default '',
  `branchemail` varchar(200) NOT NULL default '',
  `branchaddress1` varchar(200) NOT NULL default '',
  `branchaddress2` varchar(200) NOT NULL default '',
  `branchaddress3` varchar(200) NOT NULL default '',
  `branchaddress4` varchar(200) NOT NULL default '',
  `branchcity` varchar(50) NOT NULL default '',
  `branchpostalcode` varchar(10) NOT NULL default '',
  `branchstate` varchar(50) NOT NULL default '',
  `branchcountrycode` varchar(50) NOT NULL default '',
  `servicechargeacccode` varchar(20) NOT NULL default '',
  `fromoldversion` enum('Y','N') NOT NULL default 'N',
  PRIMARY KEY  (`purchasesdnkey`),
  UNIQUE KEY `ipdncode` (`purchasesdncode`),
  KEY `ipdndate` (`purchasesdndate`),
  KEY `ipdncreditorcode` (`creditorcode`),
  KEY `ipdntermcode` (`termcode`),
  KEY `ipdnstaffcode` (`staffcode`),
  KEY `ipdnrefno` (`refno`),
  KEY `ipdnglobalpurchasesacccode` (`globalpurchasesacccode`),
  KEY `ipdndepartmentcode` (`departmentcode`),
  KEY `ipdnstocklocationcode` (`stocklocationcode`),
  KEY `ipdncancelled` (`cancelled`),
  KEY `ipdnareacode` (`areacode`),
  KEY `ipdncurcode` (`curcode`),
  KEY `ipdnpostaccountvalue` (`postaccountvalue`),
  KEY `ipdnpoststockvalue` (`poststockvalue`),
  KEY `ipdnpostingdate` (`postingdate`),
  KEY `ipdnjobcode` (`jobcode`),
  KEY `ipdnglobaltaxacccode` (`globaltaxacccode`),
  KEY `ipdnglobaldiscountacccode` (`globaldiscountacccode`),
  KEY `ipdnroundingadjacccode` (`roundingadjacccode`),
  KEY `ipdncardchargeacccode` (`cardchargeacccode`),
  KEY `ipdncountrycode` (`countrycode`),
  KEY `ipdnbranchcountrycode` (`branchcountrycode`),
  KEY `ipdnservicechargeacccode` (`servicechargeacccode`)
) ENGINE=INNODB DEFAULT CHARSET=latin1;

CREATE TABLE `purchasesdnid` (
  `purchasesdnkey` int(11) unsigned NOT NULL default '0',
  `id` int(11) unsigned NOT NULL default '0',
  PRIMARY KEY  (`purchasesdnkey`,`id`)
) ENGINE=INNODB DEFAULT CHARSET=latin1;

CREATE TABLE `purchasesdnitem` (
  `purchasesdnkey` int(11) unsigned NOT NULL default '0',
  `purchasesdncode` varchar(20) NOT NULL default '',
  `id` int(11) unsigned NOT NULL default '0',
  `pos` int(11) unsigned NOT NULL default '0',
  `itemno` varchar(10) NOT NULL default '',
  `stockcode` varchar(30) NOT NULL default '',
  `descr` varchar(200) NOT NULL default '',
  `moredescr` text,
  `qty` decimal(20,6) default NULL,
  `unitprice` decimal(20,6) default NULL,
  `uom` varchar(20) NOT NULL default '',
  `uomrate` double NOT NULL default '1',
  `qtybaseuom` decimal(20,6) NOT NULL default '0.000000',
  `unitpricebaseuom` double NOT NULL default '0',
  `discountformat` varchar(100) default NULL,
  `discountamount` decimal(20,2) default NULL,
  `amountbeforediscount` decimal(20,2) default NULL,
  `amount` decimal(20,2) default NULL,
  `gsttypecode` varchar(20) NOT NULL default '',
  `purchasestaxpercentage` decimal(20,2) default NULL,
  `purchasestaxamount` decimal(20,2) default NULL,
  `amountaftertax` decimal(20,2) default NULL,
  `acccode` varchar(20) NOT NULL default '',
  `departmentcode` varchar(20) NOT NULL default '',
  `jobcode` varchar(20) NOT NULL default '',
  `stocklocationcode` varchar(20) NOT NULL default '',
  `creditoritemcode` varchar(30) NOT NULL default '',
  `barcode` varchar(30) NOT NULL default '',
  `remark1` varchar(100) NOT NULL,
  `remark2` varchar(100) NOT NULL,
  `remark3` varchar(100) NOT NULL,
  `remark4` varchar(100) NOT NULL,
  `rowtype` enum('','TOTALUP','ITEMDISCOUNT','ITEMSERVICETAX','ITEMMISCCHARGES','FOOTERDISCOUNT','FOOTERSERVICETAX','FOOTERMISCCHARGES') NOT NULL,
  `foc` enum('Y','N') NOT NULL default 'N',
  `packingqty` decimal(20,6) default NULL,
  `packinguom` varchar(20) NOT NULL default '',
  `packingrate` decimal(20,6) default NULL,
  `serialno` text,
  `lcost1` decimal(20,2) default NULL,
  `lcost2` decimal(20,2) default NULL,
  `lcost3` decimal(20,2) default NULL,
  `batchno` varchar(30) NOT NULL default '',
  `curcode` varchar(20) NOT NULL default '',
  `curprice` decimal(20,6) default NULL,
  `currate` decimal(20,8) unsigned default NULL,
  `recommendpricebaseuom` decimal(20,6) unsigned NOT NULL default '0.000000',
  `weightrate` decimal(20,6) unsigned NOT NULL default '0.000000',
  `weightuom` varchar(20) NOT NULL default '',
  `weightqty` decimal(20,6) unsigned NOT NULL default '0.000000',
  `weightloosed` decimal(20,6) unsigned NOT NULL default '0.000000',
  `totalweight` decimal(20,6) unsigned NOT NULL default '0.000000',
  `volumerate` decimal(20,6) unsigned NOT NULL default '0.000000',
  `volumeuom` varchar(20) NOT NULL default '',
  `volumeqty` decimal(20,6) unsigned NOT NULL default '0.000000',
  `volumeloosed` decimal(20,6) unsigned NOT NULL default '0.000000',
  `totalvolume` decimal(20,6) unsigned NOT NULL default '0.000000',
  `lcosttype1` enum('Value','Quantity') NOT NULL default 'Value',
  `lcosttype2` enum('Value','Quantity') NOT NULL default 'Value',
  `lcosttype3` enum('Value','Quantity') NOT NULL default 'Value',
  `supplypurchase` enum('None','Supply','Purchase') NOT NULL default 'None',
  `taxsubtract` enum('Y','N') NOT NULL default 'N',
  `taxableamount` decimal(20,2) NOT NULL default '0.00',
  `taxablelocalamount` decimal(20,2) NOT NULL default '0.00',
  `amountaftertaxsubtract` decimal(20,2) NOT NULL default '0.00',
  `localamountaftertaxsubtract` decimal(20,2) NOT NULL default '0.00',
  `purchasestaxlocalamount` decimal(20,2) NOT NULL default '0.00',
  `taxadjustment` decimal(20,2) NOT NULL default '0.00',
  `taxlocaladjustment` decimal(20,2) NOT NULL default '0.00',
  `taxtotalamount` decimal(20,2) NOT NULL default '0.00',
  `taxtotallocalamount` decimal(20,2) NOT NULL default '0.00',
  `ourpocode` varchar(20) NOT NULL default '',
  `ourpodate` date default NULL,
  `taxpermitno` varchar(50) NOT NULL default '',
  `taxacccode` varchar(20) NOT NULL default '',
  `purchasesinvoicecode` varchar(20) NOT NULL default '',
  `purchasesinvoicedate` date default NULL,
  `reason` varchar(200) NOT NULL default '',
  PRIMARY KEY  (`purchasesdnkey`,`pos`),
  UNIQUE KEY `ipdnikeyid` (`purchasesdnkey`,`id`),
  KEY `ipdnicode` (`purchasesdncode`),
  KEY `ipdnistockcode` (`stockcode`),
  KEY `ipdniacccode` (`acccode`),
  KEY `ipdnidepartmentcode` (`departmentcode`),
  KEY `ipdnistocklocationcode` (`stocklocationcode`),
  KEY `ipdnibarcode` (`barcode`),
  KEY `ipdnifoc` (`foc`),
  KEY `ipdnibatchno` (`batchno`),
  KEY `ipdnijobcode` (`jobcode`),
  KEY `ipdnigsttypecode` (`gsttypecode`),
  KEY `ipdniitaxacccode` (`taxacccode`)
) ENGINE=INNODB DEFAULT CHARSET=latin1;

CREATE TABLE `purchasesinvoice` (
  `purchasesinvoicekey` int(11) unsigned NOT NULL auto_increment,
  `purchasesinvoicecode` varchar(20) NOT NULL default '',
  `purchasesinvoicedate` date default NULL,
  `purchasesinvoicepostingdate` date default NULL,
  `creditorcode` varchar(20) NOT NULL default '',
  `termcode` varchar(20) NOT NULL default '',
  `staffcode` varchar(20) NOT NULL default '',
  `areacode` varchar(20) NOT NULL default '',
  `descr` varchar(200) NOT NULL default '',
  `validity` varchar(100) NOT NULL default '',
  `deliveryterm` varchar(100) NOT NULL default '',
  `refno` varchar(20) NOT NULL default '',
  `address1` varchar(200) NOT NULL default '',
  `address2` varchar(200) NOT NULL default '',
  `address3` varchar(200) NOT NULL default '',
  `address4` varchar(200) NOT NULL default '',
  `attention` varchar(200) NOT NULL default '',
  `phone` varchar(30) NOT NULL default '',
  `fax` varchar(30) NOT NULL default '',
  `discountamount` decimal(20,2) NOT NULL,
  `amountbeforediscount` decimal(20,2) NOT NULL,
  `amount` decimal(20,2) NOT NULL default '0.00',
  `taxamount` decimal(20,2) NOT NULL default '0.00',
  `amountaftertax` decimal(20,2) NOT NULL default '0.00',
  `localtaxamount` decimal(20,2) NOT NULL default '0.00',
  `localamountaftertax` decimal(20,2) NOT NULL default '0.00',
  `note` mediumtext,
  `remark1` varchar(100) NOT NULL,
  `remark2` varchar(100) NOT NULL,
  `remark3` varchar(100) NOT NULL,
  `remark4` varchar(100) NOT NULL,
  `remark5` varchar(100) NOT NULL,
  `remark6` varchar(100) NOT NULL,
  `remark7` varchar(100) NOT NULL,
  `remark8` varchar(100) NOT NULL,
  `globaldiscountacccode` varchar(20) NOT NULL default '',
  `globalpurchasesacccode` varchar(20) NOT NULL default '',
  `globaltaxacccode` varchar(20) NOT NULL default '',
  `roundingadjacccode` varchar(20) NOT NULL default '',
  `cardchargeacccode` varchar(20) NOT NULL default '',
  `globaldepartment` enum('Y','N') NOT NULL default 'Y',
  `departmentcode` varchar(20) NOT NULL default '',
  `globaljob` enum('Y','N') NOT NULL default 'N',
  `jobcode` varchar(20) NOT NULL default '',
  `globalstocklocation` enum('Y','N') NOT NULL default 'Y',
  `stocklocationcode` varchar(20) NOT NULL default '',
  `received` enum('Y','N') NOT NULL default 'Y',
  `receiveddate` date default NULL,
  `cancelled` enum('Y','N') NOT NULL default 'N',
  `itemformatkey` int(11) unsigned NOT NULL default '0',
  `billkey` int(11) unsigned NOT NULL default '0',
  `created` datetime default NULL,
  `modified` datetime default NULL,
  `done` enum('Y','N') NOT NULL default 'N',
  `lcost1` decimal(20,2) NOT NULL default '0.00',
  `lcost2` decimal(20,2) NOT NULL default '0.00',
  `lcost3` decimal(20,2) NOT NULL default '0.00',
  `curcode` varchar(20) NOT NULL,
  `currate` decimal(20,8) unsigned NOT NULL default '1.00000000',
  `localdiscountamount` decimal(20,2) NOT NULL,
  `localamountbeforediscount` decimal(20,2) NOT NULL,
  `localamount` decimal(20,2) NOT NULL default '0.00',
  `locallcost1` decimal(20,2) NOT NULL default '0.00',
  `locallcost2` decimal(20,2) NOT NULL default '0.00',
  `locallcost3` decimal(20,2) NOT NULL default '0.00',
  `creditordono` varchar(30) NOT NULL,
  `creditorinvno` varchar(30) NOT NULL,
  `ref1` varchar(30) NOT NULL,
  `ref2` varchar(30) NOT NULL,
  `ref3` varchar(30) NOT NULL,
  `ref4` varchar(30) NOT NULL,
  `postaccountvalue` enum('Y','N') NOT NULL default 'Y',
  `poststockvalue` enum('Y','N') NOT NULL default 'Y',
  `grnaccrual` enum('Y','N') NOT NULL default 'N',
  `accrualacccode` varchar(20) NOT NULL default '',
  `accrualamount` decimal(20,2) NOT NULL default '0.00',
  `accruallocalamount` decimal(20,2) NOT NULL default '0.00',
  `accrualdepartmentcode` varchar(20) NOT NULL default '',
  `accrualjobcode` varchar(20) NOT NULL default '',
  `lastmodified` timestamp NOT NULL default CURRENT_TIMESTAMP on update CURRENT_TIMESTAMP,
  `creditorname` varchar(200) NOT NULL default '',
  `city` varchar(50) NOT NULL default '',
  `postalcode` varchar(10) NOT NULL default '',
  `state` varchar(50) NOT NULL default '',
  `countrycode` varchar(50) NOT NULL default '',
  `branchcode` varchar(20) NOT NULL default '',
  `branchname` varchar(200) NOT NULL default '',
  `branchcontactperson` varchar(200) NOT NULL default '',
  `branchphone` varchar(30) NOT NULL default '',
  `branchfax` varchar(30) NOT NULL default '',
  `branchemail` varchar(200) NOT NULL default '',
  `branchaddress1` varchar(200) NOT NULL default '',
  `branchaddress2` varchar(200) NOT NULL default '',
  `branchaddress3` varchar(200) NOT NULL default '',
  `branchaddress4` varchar(200) NOT NULL default '',
  `branchcity` varchar(50) NOT NULL default '',
  `branchpostalcode` varchar(10) NOT NULL default '',
  `branchstate` varchar(50) NOT NULL default '',
  `branchcountrycode` varchar(50) NOT NULL default '',
  `servicechargeacccode` varchar(20) NOT NULL default '',
  `selfbillinvoice` enum('Y','N') NOT NULL default 'N',
  `selfbillinvoiceapprovalno` varchar(50) NOT NULL default '',
  `selfbillinvoiceapprovaldate` date default NULL,
  `fromoldversion` enum('Y','N') NOT NULL default 'N',
  PRIMARY KEY  (`purchasesinvoicekey`),
  UNIQUE KEY `ipicode` (`purchasesinvoicecode`),
  KEY `ipidate` (`purchasesinvoicedate`),
  KEY `ipipostingdate` (`purchasesinvoicepostingdate`),
  KEY `ipicreditorcode` (`creditorcode`),
  KEY `ipitermcode` (`termcode`),
  KEY `ipistaffcode` (`staffcode`),
  KEY `ipirefno` (`refno`),
  KEY `ipiglobalpurchasesacccode` (`globalpurchasesacccode`),
  KEY `ipidepartmentcode` (`departmentcode`),
  KEY `ipistocklocationcode` (`stocklocationcode`),
  KEY `ipireceived` (`received`),
  KEY `ipireceiveddate` (`receiveddate`),
  KEY `ipicancelled` (`cancelled`),
  KEY `ipiareacode` (`areacode`),
  KEY `ipicurcode` (`curcode`),
  KEY `ipipostaccountvalue` (`postaccountvalue`),
  KEY `ipipoststockvalue` (`poststockvalue`),
  KEY `ipiaccrualacccode` (`accrualacccode`),
  KEY `ipiaccrualdepartmentcode` (`accrualdepartmentcode`),
  KEY `ipijobcode` (`jobcode`),
  KEY `ipiaccrualjobcode` (`accrualjobcode`),
  KEY `ipiglobaltaxacccode` (`globaltaxacccode`),
  KEY `ipiglobaldiscountacccode` (`globaldiscountacccode`),
  KEY `ipiroundingadjacccode` (`roundingadjacccode`),
  KEY `ipicardchargeacccode` (`cardchargeacccode`),
  KEY `ipicountrycode` (`countrycode`),
  KEY `ipibranchcountrycode` (`branchcountrycode`),
  KEY `ipiservicechargeacccode` (`servicechargeacccode`),
  KEY `ipiselfbillinvoiceapprovalno` (`selfbillinvoiceapprovalno`)
) ENGINE=INNODB DEFAULT CHARSET=latin1;

CREATE TABLE `purchasesinvoiceid` (
  `purchasesinvoicekey` int(11) unsigned NOT NULL default '0',
  `id` int(11) unsigned NOT NULL default '0',
  PRIMARY KEY  (`purchasesinvoicekey`,`id`)
) ENGINE=INNODB DEFAULT CHARSET=latin1;

CREATE TABLE `purchasesinvoiceitem` (
  `purchasesinvoicekey` int(11) unsigned NOT NULL default '0',
  `purchasesinvoicecode` varchar(20) NOT NULL default '',
  `id` int(11) unsigned NOT NULL default '0',
  `pos` int(11) unsigned NOT NULL default '0',
  `itemno` varchar(10) NOT NULL default '',
  `stockcode` varchar(30) NOT NULL default '',
  `descr` varchar(200) NOT NULL default '',
  `moredescr` text,
  `qty` decimal(20,6) default NULL,
  `unitprice` decimal(20,6) default NULL,
  `uom` varchar(20) NOT NULL default '',
  `uomrate` double NOT NULL default '1',
  `qtybaseuom` decimal(20,6) NOT NULL default '0.000000',
  `unitpricebaseuom` double NOT NULL default '0',
  `discountformat` varchar(100) default NULL,
  `discountamount` decimal(20,2) default NULL,
  `amountbeforediscount` decimal(20,2) default NULL,
  `amount` decimal(20,2) default NULL,
  `gsttypecode` varchar(20) NOT NULL default '',
  `purchasestaxpercentage` decimal(20,2) default NULL,
  `purchasestaxamount` decimal(20,2) default NULL,
  `amountaftertax` decimal(20,2) default NULL,
  `acccode` varchar(20) NOT NULL default '',
  `departmentcode` varchar(20) NOT NULL default '',
  `jobcode` varchar(20) NOT NULL default '',
  `stocklocationcode` varchar(20) NOT NULL default '',
  `fromdoctype` varchar(5) NOT NULL default '',
  `fromdockey` int(11) unsigned default NULL,
  `fromdocid` int(11) unsigned default NULL,
  `fromdoccode` varchar(20) NOT NULL default '',
  `receiveddate` date default NULL,
  `creditoritemcode` varchar(30) NOT NULL default '',
  `barcode` varchar(30) NOT NULL default '',
  `remark1` varchar(100) NOT NULL,
  `remark2` varchar(100) NOT NULL,
  `remark3` varchar(100) NOT NULL,
  `remark4` varchar(100) NOT NULL,
  `rowtype` enum('','TOTALUP','ITEMDISCOUNT','ITEMSERVICETAX','ITEMMISCCHARGES','FOOTERDISCOUNT','FOOTERSERVICETAX','FOOTERMISCCHARGES') NOT NULL,
  `foc` enum('Y','N') NOT NULL default 'N',
  `packingqty` decimal(20,6) default NULL,
  `packinguom` varchar(20) NOT NULL default '',
  `packingrate` decimal(20,6) default NULL,
  `serialno` text,
  `lcost1` decimal(20,2) default NULL,
  `lcost2` decimal(20,2) default NULL,
  `lcost3` decimal(20,2) default NULL,
  `batchno` varchar(30) NOT NULL default '',
  `curcode` varchar(20) NOT NULL default '',
  `curprice` decimal(20,6) default NULL,
  `currate` decimal(20,8) unsigned default NULL,
  `recommendpricebaseuom` decimal(20,6) unsigned NOT NULL default '0.000000',
  `weightrate` decimal(20,6) unsigned NOT NULL default '0.000000',
  `weightuom` varchar(20) NOT NULL default '',
  `weightqty` decimal(20,6) unsigned NOT NULL default '0.000000',
  `weightloosed` decimal(20,6) unsigned NOT NULL default '0.000000',
  `totalweight` decimal(20,6) unsigned NOT NULL default '0.000000',
  `volumerate` decimal(20,6) unsigned NOT NULL default '0.000000',
  `volumeuom` varchar(20) NOT NULL default '',
  `volumeqty` decimal(20,6) unsigned NOT NULL default '0.000000',
  `volumeloosed` decimal(20,6) unsigned NOT NULL default '0.000000',
  `totalvolume` decimal(20,6) unsigned NOT NULL default '0.000000',
  `lcosttype1` enum('Value','Quantity') NOT NULL default 'Value',
  `lcosttype2` enum('Value','Quantity') NOT NULL default 'Value',
  `lcosttype3` enum('Value','Quantity') NOT NULL default 'Value',
  `supplypurchase` enum('None','Supply','Purchase') NOT NULL default 'None',
  `taxsubtract` enum('Y','N') NOT NULL default 'N',
  `taxableamount` decimal(20,2) NOT NULL default '0.00',
  `taxablelocalamount` decimal(20,2) NOT NULL default '0.00',
  `amountaftertaxsubtract` decimal(20,2) NOT NULL default '0.00',
  `localamountaftertaxsubtract` decimal(20,2) NOT NULL default '0.00',
  `purchasestaxlocalamount` decimal(20,2) NOT NULL default '0.00',
  `taxadjustment` decimal(20,2) NOT NULL default '0.00',
  `taxlocaladjustment` decimal(20,2) NOT NULL default '0.00',
  `taxtotalamount` decimal(20,2) NOT NULL default '0.00',
  `taxtotallocalamount` decimal(20,2) NOT NULL default '0.00',
  `ourpocode` varchar(20) NOT NULL default '',
  `ourpodate` date default NULL,
  `taxpermitno` varchar(50) NOT NULL default '',
  `taxacccode` varchar(20) NOT NULL default '',
  PRIMARY KEY  (`purchasesinvoicekey`,`pos`),
  UNIQUE KEY `ipiikeyid` (`purchasesinvoicekey`,`id`),
  KEY `ipiicode` (`purchasesinvoicecode`),
  KEY `ipiistockcode` (`stockcode`),
  KEY `ipiiacccode` (`acccode`),
  KEY `ipiidepartmentcode` (`departmentcode`),
  KEY `ipiistocklocationcode` (`stocklocationcode`),
  KEY `ipiifromdoctypekeypos` (`fromdoctype`,`fromdockey`,`fromdocid`),
  KEY `ipiibarcode` (`barcode`),
  KEY `ipiifoc` (`foc`),
  KEY `ipiibatchno` (`batchno`),
  KEY `ipiijobcode` (`jobcode`),
  KEY `ipiigsttypecode` (`gsttypecode`),
  KEY `ipiitaxacccode` (`taxacccode`)
) ENGINE=INNODB DEFAULT CHARSET=latin1;

CREATE TABLE `purchasesmemo` (
  `purchasesmemokey` int(11) unsigned NOT NULL auto_increment,
  `purchasesmemocode` varchar(20) NOT NULL default '',
  `purchasesmemodate` date default NULL,
  `memotypecode` varchar(20) NOT NULL default '',
  `creditorcode` varchar(20) NOT NULL default '',
  `termcode` varchar(20) NOT NULL default '',
  `staffcode` varchar(20) NOT NULL default '',
  `areacode` varchar(20) NOT NULL default '',
  `descr` varchar(200) NOT NULL default '',
  `validity` varchar(100) NOT NULL default '',
  `deliveryterm` varchar(100) NOT NULL default '',
  `refno` varchar(20) NOT NULL default '',
  `address1` varchar(200) NOT NULL default '',
  `address2` varchar(200) NOT NULL default '',
  `address3` varchar(200) NOT NULL default '',
  `address4` varchar(200) NOT NULL default '',
  `attention` varchar(200) NOT NULL default '',
  `phone` varchar(30) NOT NULL default '',
  `fax` varchar(30) NOT NULL default '',
  `discountamount` decimal(20,2) NOT NULL,
  `amountbeforediscount` decimal(20,2) NOT NULL,
  `amount` decimal(20,2) NOT NULL default '0.00',
  `taxamount` decimal(20,2) NOT NULL default '0.00',
  `amountaftertax` decimal(20,2) NOT NULL default '0.00',
  `localtaxamount` decimal(20,2) NOT NULL default '0.00',
  `localamountaftertax` decimal(20,2) NOT NULL default '0.00',
  `note` mediumtext,
  `remark1` varchar(100) NOT NULL,
  `remark2` varchar(100) NOT NULL,
  `remark3` varchar(100) NOT NULL,
  `remark4` varchar(100) NOT NULL,
  `remark5` varchar(100) NOT NULL,
  `remark6` varchar(100) NOT NULL,
  `remark7` varchar(100) NOT NULL,
  `remark8` varchar(100) NOT NULL,
  `globaldepartment` enum('Y','N') NOT NULL default 'Y',
  `departmentcode` varchar(20) NOT NULL default '',
  `globaljob` enum('Y','N') NOT NULL default 'N',
  `jobcode` varchar(20) NOT NULL default '',
  `globalstocklocation` enum('Y','N') NOT NULL default 'Y',
  `stocklocationcode` varchar(20) NOT NULL default '',
  `cancelled` enum('Y','N') NOT NULL default 'N',
  `poststockvalue` enum('Y','N') NOT NULL default 'Y',
  `itemformatkey` int(11) unsigned NOT NULL default '0',
  `created` datetime default NULL,
  `modified` datetime default NULL,
  `done` enum('Y','N') NOT NULL default 'N',
  `lcost1` decimal(20,2) NOT NULL default '0.00',
  `lcost2` decimal(20,2) NOT NULL default '0.00',
  `lcost3` decimal(20,2) NOT NULL default '0.00',
  `curcode` varchar(20) NOT NULL,
  `currate` decimal(20,8) unsigned NOT NULL default '1.00000000',
  `localdiscountamount` decimal(20,2) NOT NULL,
  `localamountbeforediscount` decimal(20,2) NOT NULL,
  `localamount` decimal(20,2) NOT NULL default '0.00',
  `locallcost1` decimal(20,2) NOT NULL default '0.00',
  `locallcost2` decimal(20,2) NOT NULL default '0.00',
  `locallcost3` decimal(20,2) NOT NULL default '0.00',
  `ref1` varchar(30) NOT NULL,
  `ref2` varchar(30) NOT NULL,
  `ref3` varchar(30) NOT NULL,
  `ref4` varchar(30) NOT NULL,
  `lastmodified` timestamp NOT NULL default CURRENT_TIMESTAMP on update CURRENT_TIMESTAMP,
  `creditorname` varchar(200) NOT NULL default '',
  `city` varchar(50) NOT NULL default '',
  `postalcode` varchar(10) NOT NULL default '',
  `state` varchar(50) NOT NULL default '',
  `countrycode` varchar(50) NOT NULL default '',
  `branchcode` varchar(20) NOT NULL default '',
  `branchname` varchar(200) NOT NULL default '',
  `branchcontactperson` varchar(200) NOT NULL default '',
  `branchphone` varchar(30) NOT NULL default '',
  `branchfax` varchar(30) NOT NULL default '',
  `branchemail` varchar(200) NOT NULL default '',
  `branchaddress1` varchar(200) NOT NULL default '',
  `branchaddress2` varchar(200) NOT NULL default '',
  `branchaddress3` varchar(200) NOT NULL default '',
  `branchaddress4` varchar(200) NOT NULL default '',
  `branchcity` varchar(50) NOT NULL default '',
  `branchpostalcode` varchar(10) NOT NULL default '',
  `branchstate` varchar(50) NOT NULL default '',
  `branchcountrycode` varchar(50) NOT NULL default '',
  `fromoldversion` enum('Y','N') NOT NULL default 'N',
  PRIMARY KEY  (`purchasesmemokey`),
  UNIQUE KEY `ipmcode` (`purchasesmemocode`),
  KEY `ipmdate` (`purchasesmemodate`),
  KEY `ipmmemotypecode` (`memotypecode`),
  KEY `ipmcreditorcode` (`creditorcode`),
  KEY `ipmtermcode` (`termcode`),
  KEY `ipmstaffcode` (`staffcode`),
  KEY `ipmrefno` (`refno`),
  KEY `ipmdepartmentcode` (`departmentcode`),
  KEY `ipmstocklocationcode` (`stocklocationcode`),
  KEY `ipmcancelled` (`cancelled`),
  KEY `ipmpoststockvalue` (`poststockvalue`),
  KEY `ipmareacode` (`areacode`),
  KEY `ipmcurcode` (`curcode`),
  KEY `ipmjobcode` (`jobcode`),
  KEY `ipmcountrycode` (`countrycode`),
  KEY `ipmbranchcountrycode` (`branchcountrycode`)
) ENGINE=INNODB DEFAULT CHARSET=latin1;

CREATE TABLE `purchasesmemoid` (
  `purchasesmemokey` int(11) unsigned NOT NULL default '0',
  `id` int(11) unsigned NOT NULL default '0',
  PRIMARY KEY  (`purchasesmemokey`,`id`)
) ENGINE=INNODB DEFAULT CHARSET=latin1;

CREATE TABLE `purchasesmemoitem` (
  `purchasesmemokey` int(11) unsigned NOT NULL default '0',
  `purchasesmemocode` varchar(20) NOT NULL default '',
  `id` int(11) unsigned NOT NULL default '0',
  `pos` int(11) unsigned NOT NULL default '0',
  `itemno` varchar(10) NOT NULL default '',
  `stockcode` varchar(30) NOT NULL default '',
  `descr` varchar(200) NOT NULL default '',
  `moredescr` text,
  `qty` decimal(20,6) default NULL,
  `unitprice` decimal(20,6) default NULL,
  `uom` varchar(20) NOT NULL default '',
  `uomrate` double NOT NULL default '1',
  `qtybaseuom` decimal(20,6) NOT NULL default '0.000000',
  `unitpricebaseuom` double NOT NULL default '0',
  `discountformat` varchar(100) default NULL,
  `discountamount` decimal(20,2) default NULL,
  `amountbeforediscount` decimal(20,2) default NULL,
  `amount` decimal(20,2) default NULL,
  `gsttypecode` varchar(20) NOT NULL default '',
  `purchasestaxpercentage` decimal(20,2) default NULL,
  `purchasestaxamount` decimal(20,2) default NULL,
  `amountaftertax` decimal(20,2) default NULL,
  `departmentcode` varchar(20) NOT NULL default '',
  `jobcode` varchar(20) NOT NULL default '',
  `stocklocationcode` varchar(20) NOT NULL default '',
  `creditoritemcode` varchar(30) NOT NULL default '',
  `barcode` varchar(30) NOT NULL default '',
  `remark1` varchar(100) NOT NULL,
  `remark2` varchar(100) NOT NULL,
  `remark3` varchar(100) NOT NULL,
  `remark4` varchar(100) NOT NULL,
  `rowtype` enum('','TOTALUP','ITEMDISCOUNT','ITEMSERVICETAX','ITEMMISCCHARGES','FOOTERDISCOUNT','FOOTERSERVICETAX','FOOTERMISCCHARGES') NOT NULL,
  `foc` enum('Y','N') NOT NULL default 'N',
  `packingqty` decimal(20,6) default NULL,
  `packinguom` varchar(20) NOT NULL default '',
  `packingrate` decimal(20,6) default NULL,
  `serialno` text,
  `lcost1` decimal(20,2) default NULL,
  `lcost2` decimal(20,2) default NULL,
  `lcost3` decimal(20,2) default NULL,
  `batchno` varchar(30) NOT NULL default '',
  `curcode` varchar(20) NOT NULL default '',
  `curprice` decimal(20,6) default NULL,
  `currate` decimal(20,8) unsigned default NULL,
  `recommendpricebaseuom` decimal(20,6) unsigned NOT NULL default '0.000000',
  `weightrate` decimal(20,6) unsigned NOT NULL default '0.000000',
  `weightuom` varchar(20) NOT NULL default '',
  `weightqty` decimal(20,6) unsigned NOT NULL default '0.000000',
  `weightloosed` decimal(20,6) unsigned NOT NULL default '0.000000',
  `totalweight` decimal(20,6) unsigned NOT NULL default '0.000000',
  `volumerate` decimal(20,6) unsigned NOT NULL default '0.000000',
  `volumeuom` varchar(20) NOT NULL default '',
  `volumeqty` decimal(20,6) unsigned NOT NULL default '0.000000',
  `volumeloosed` decimal(20,6) unsigned NOT NULL default '0.000000',
  `totalvolume` decimal(20,6) unsigned NOT NULL default '0.000000',
  `lcosttype1` enum('Value','Quantity') NOT NULL default 'Value',
  `lcosttype2` enum('Value','Quantity') NOT NULL default 'Value',
  `lcosttype3` enum('Value','Quantity') NOT NULL default 'Value',
  `supplypurchase` enum('None','Supply','Purchase') NOT NULL default 'None',
  `taxsubtract` enum('Y','N') NOT NULL default 'N',
  `taxableamount` decimal(20,2) NOT NULL default '0.00',
  `taxablelocalamount` decimal(20,2) NOT NULL default '0.00',
  `amountaftertaxsubtract` decimal(20,2) NOT NULL default '0.00',
  `localamountaftertaxsubtract` decimal(20,2) NOT NULL default '0.00',
  `purchasestaxlocalamount` decimal(20,2) NOT NULL default '0.00',
  `taxadjustment` decimal(20,2) NOT NULL default '0.00',
  `taxlocaladjustment` decimal(20,2) NOT NULL default '0.00',
  `taxtotalamount` decimal(20,2) NOT NULL default '0.00',
  `taxtotallocalamount` decimal(20,2) NOT NULL default '0.00',
  PRIMARY KEY  (`purchasesmemokey`,`pos`),
  UNIQUE KEY `ipmikeyid` (`purchasesmemokey`,`id`),
  KEY `ipmicode` (`purchasesmemocode`),
  KEY `ipmistockcode` (`stockcode`),
  KEY `ipmidepartmentcode` (`departmentcode`),
  KEY `ipmistocklocationcode` (`stocklocationcode`),
  KEY `ipmibarcode` (`barcode`),
  KEY `ipmifoc` (`foc`),
  KEY `ipmibatchno` (`batchno`),
  KEY `ipmijobcode` (`jobcode`),
  KEY `ipmigsttypecode` (`gsttypecode`)
) ENGINE=INNODB DEFAULT CHARSET=latin1;

CREATE TABLE `purchasesorder` (
  `purchasesorderkey` int(11) unsigned NOT NULL auto_increment,
  `purchasesordercode` varchar(20) NOT NULL default '',
  `purchasesorderdate` date default NULL,
  `creditorcode` varchar(20) NOT NULL default '',
  `termcode` varchar(20) NOT NULL default '',
  `staffcode` varchar(20) NOT NULL default '',
  `areacode` varchar(20) NOT NULL default '',
  `descr` varchar(200) NOT NULL default '',
  `validity` varchar(100) NOT NULL default '',
  `deliveryterm` varchar(100) NOT NULL default '',
  `refno` varchar(20) NOT NULL default '',
  `address1` varchar(200) NOT NULL default '',
  `address2` varchar(200) NOT NULL default '',
  `address3` varchar(200) NOT NULL default '',
  `address4` varchar(200) NOT NULL default '',
  `attention` varchar(200) NOT NULL default '',
  `phone` varchar(30) NOT NULL default '',
  `fax` varchar(30) NOT NULL default '',
  `discountamount` decimal(20,2) NOT NULL,
  `amountbeforediscount` decimal(20,2) NOT NULL,
  `amount` decimal(20,2) NOT NULL default '0.00',
  `taxamount` decimal(20,2) NOT NULL default '0.00',
  `amountaftertax` decimal(20,2) NOT NULL default '0.00',
  `localtaxamount` decimal(20,2) NOT NULL default '0.00',
  `localamountaftertax` decimal(20,2) NOT NULL default '0.00',
  `note` mediumtext,
  `remark1` varchar(100) NOT NULL,
  `remark2` varchar(100) NOT NULL,
  `remark3` varchar(100) NOT NULL,
  `remark4` varchar(100) NOT NULL,
  `remark5` varchar(100) NOT NULL,
  `remark6` varchar(100) NOT NULL,
  `remark7` varchar(100) NOT NULL,
  `remark8` varchar(100) NOT NULL,
  `globaldepartment` enum('Y','N') NOT NULL default 'Y',
  `departmentcode` varchar(20) NOT NULL default '',
  `globaljob` enum('Y','N') NOT NULL default 'N',
  `jobcode` varchar(20) NOT NULL default '',
  `globalstocklocation` enum('Y','N') NOT NULL default 'Y',
  `stocklocationcode` varchar(20) NOT NULL default '',
  `closed` enum('Y','N') NOT NULL default 'N',
  `cancelled` enum('Y','N') NOT NULL default 'N',
  `itemformatkey` int(11) unsigned NOT NULL default '0',
  `created` datetime default NULL,
  `modified` datetime default NULL,
  `done` enum('Y','N') NOT NULL default 'N',
  `curcode` varchar(20) NOT NULL,
  `currate` decimal(20,8) unsigned NOT NULL default '1.00000000',
  `localdiscountamount` decimal(20,2) NOT NULL,
  `localamountbeforediscount` decimal(20,2) NOT NULL,
  `localamount` decimal(20,2) NOT NULL default '0.00',
  `ref1` varchar(30) NOT NULL,
  `ref2` varchar(30) NOT NULL,
  `ref3` varchar(30) NOT NULL,
  `ref4` varchar(30) NOT NULL,
  `lastmodified` timestamp NOT NULL default CURRENT_TIMESTAMP on update CURRENT_TIMESTAMP,
  `creditorname` varchar(200) NOT NULL default '',
  `directshipment` enum('Y','N') NOT NULL default 'N',
  `debtorcode` varchar(20) NOT NULL default '',
  `grnkey` int(11) unsigned NOT NULL default '0',
  `deliveryorderkey` int(11) unsigned NOT NULL default '0',
  `requiredate` date default NULL,
  `city` varchar(50) NOT NULL default '',
  `postalcode` varchar(10) NOT NULL default '',
  `state` varchar(50) NOT NULL default '',
  `countrycode` varchar(50) NOT NULL default '',
  `branchcode` varchar(20) NOT NULL default '',
  `branchname` varchar(200) NOT NULL default '',
  `branchcontactperson` varchar(200) NOT NULL default '',
  `branchphone` varchar(30) NOT NULL default '',
  `branchfax` varchar(30) NOT NULL default '',
  `branchemail` varchar(200) NOT NULL default '',
  `branchaddress1` varchar(200) NOT NULL default '',
  `branchaddress2` varchar(200) NOT NULL default '',
  `branchaddress3` varchar(200) NOT NULL default '',
  `branchaddress4` varchar(200) NOT NULL default '',
  `branchcity` varchar(50) NOT NULL default '',
  `branchpostalcode` varchar(10) NOT NULL default '',
  `branchstate` varchar(50) NOT NULL default '',
  `branchcountrycode` varchar(50) NOT NULL default '',
  `fromoldversion` enum('Y','N') NOT NULL default 'N',
  PRIMARY KEY  (`purchasesorderkey`),
  UNIQUE KEY `ipocode` (`purchasesordercode`),
  KEY `ipodate` (`purchasesorderdate`),
  KEY `ipocreditorcode` (`creditorcode`),
  KEY `ipotermcode` (`termcode`),
  KEY `ipostaffcode` (`staffcode`),
  KEY `iporefno` (`refno`),
  KEY `ipodepartmentcode` (`departmentcode`),
  KEY `ipostocklocationcode` (`stocklocationcode`),
  KEY `ipoclosed` (`closed`),
  KEY `ipoareacode` (`areacode`),
  KEY `ipocurcode` (`curcode`),
  KEY `ipocancelled` (`cancelled`),
  KEY `ipojobcode` (`jobcode`),
  KEY `iporequiredate` (`requiredate`),
  KEY `ipocountrycode` (`countrycode`),
  KEY `ipobranchcountrycode` (`branchcountrycode`)
) ENGINE=INNODB DEFAULT CHARSET=latin1;

CREATE TABLE `purchasesorderid` (
  `purchasesorderkey` int(11) unsigned NOT NULL default '0',
  `id` int(11) unsigned NOT NULL default '0',
  PRIMARY KEY  (`purchasesorderkey`,`id`)
) ENGINE=INNODB DEFAULT CHARSET=latin1;

CREATE TABLE `purchasesorderitem` (
  `purchasesorderkey` int(11) unsigned NOT NULL default '0',
  `purchasesordercode` varchar(20) NOT NULL default '',
  `id` int(11) unsigned NOT NULL default '0',
  `pos` int(11) unsigned NOT NULL default '0',
  `itemno` varchar(10) NOT NULL default '',
  `stockcode` varchar(30) NOT NULL default '',
  `descr` varchar(200) NOT NULL default '',
  `moredescr` text,
  `qty` decimal(20,6) default NULL,
  `unitprice` decimal(20,6) default NULL,
  `uom` varchar(20) NOT NULL default '',
  `uomrate` double NOT NULL default '1',
  `qtybaseuom` decimal(20,6) NOT NULL default '0.000000',
  `unitpricebaseuom` double NOT NULL default '0',
  `discountformat` varchar(100) default NULL,
  `discountamount` decimal(20,2) default NULL,
  `amountbeforediscount` decimal(20,2) default NULL,
  `amount` decimal(20,2) default NULL,
  `gsttypecode` varchar(20) NOT NULL default '',
  `purchasestaxpercentage` decimal(20,2) default NULL,
  `purchasestaxamount` decimal(20,2) default NULL,
  `amountaftertax` decimal(20,2) default NULL,
  `departmentcode` varchar(20) NOT NULL default '',
  `jobcode` varchar(20) NOT NULL default '',
  `stocklocationcode` varchar(20) NOT NULL default '',
  `fromdoctype` varchar(5) NOT NULL default '',
  `fromdockey` int(11) unsigned default NULL,
  `fromdocid` int(11) unsigned default NULL,
  `fromdoccode` varchar(20) NOT NULL default '',
  `creditoritemcode` varchar(30) NOT NULL default '',
  `barcode` varchar(30) NOT NULL default '',
  `remark1` varchar(100) NOT NULL,
  `remark2` varchar(100) NOT NULL,
  `remark3` varchar(100) NOT NULL,
  `remark4` varchar(100) NOT NULL,
  `rowtype` enum('','TOTALUP','ITEMDISCOUNT','ITEMSERVICETAX','ITEMMISCCHARGES','FOOTERDISCOUNT','FOOTERSERVICETAX','FOOTERMISCCHARGES') NOT NULL,
  `foc` enum('Y','N') NOT NULL default 'N',
  `packingqty` decimal(20,6) default NULL,
  `packinguom` varchar(20) NOT NULL default '',
  `packingrate` decimal(20,6) default NULL,
  `batchno` varchar(30) NOT NULL default '',
  `curcode` varchar(20) NOT NULL default '',
  `curprice` decimal(20,6) default NULL,
  `currate` decimal(20,8) unsigned default NULL,
  `recommendpricebaseuom` decimal(20,6) unsigned NOT NULL default '0.000000',
  `weightrate` decimal(20,6) unsigned NOT NULL default '0.000000',
  `weightuom` varchar(20) NOT NULL default '',
  `weightqty` decimal(20,6) unsigned NOT NULL default '0.000000',
  `weightloosed` decimal(20,6) unsigned NOT NULL default '0.000000',
  `totalweight` decimal(20,6) unsigned NOT NULL default '0.000000',
  `volumerate` decimal(20,6) unsigned NOT NULL default '0.000000',
  `volumeuom` varchar(20) NOT NULL default '',
  `volumeqty` decimal(20,6) unsigned NOT NULL default '0.000000',
  `volumeloosed` decimal(20,6) unsigned NOT NULL default '0.000000',
  `totalvolume` decimal(20,6) unsigned NOT NULL default '0.000000',
  `requiredate` date default NULL,
  `supplypurchase` enum('None','Supply','Purchase') NOT NULL default 'None',
  `taxsubtract` enum('Y','N') NOT NULL default 'N',
  `taxableamount` decimal(20,2) NOT NULL default '0.00',
  `taxablelocalamount` decimal(20,2) NOT NULL default '0.00',
  `amountaftertaxsubtract` decimal(20,2) NOT NULL default '0.00',
  `localamountaftertaxsubtract` decimal(20,2) NOT NULL default '0.00',
  `purchasestaxlocalamount` decimal(20,2) NOT NULL default '0.00',
  `taxadjustment` decimal(20,2) NOT NULL default '0.00',
  `taxlocaladjustment` decimal(20,2) NOT NULL default '0.00',
  `taxtotalamount` decimal(20,2) NOT NULL default '0.00',
  `taxtotallocalamount` decimal(20,2) NOT NULL default '0.00',
  PRIMARY KEY  (`purchasesorderkey`,`pos`),
  UNIQUE KEY `ipoikeyid` (`purchasesorderkey`,`id`),
  KEY `ipoicode` (`purchasesordercode`),
  KEY `ipoistockcode` (`stockcode`),
  KEY `ipoidepartmentcode` (`departmentcode`),
  KEY `ipoistocklocationcode` (`stocklocationcode`),
  KEY `ipoibarcode` (`barcode`),
  KEY `ipoifoc` (`foc`),
  KEY `ipoifromdoctypekeypos` (`fromdoctype`,`fromdockey`,`fromdocid`),
  KEY `ipoijobcode` (`jobcode`),
  KEY `ipoigsttypecode` (`gsttypecode`),
  KEY `ipoibatchno` (`batchno`),
  KEY `ipoirequiredate` (`requiredate`)
) ENGINE=INNODB DEFAULT CHARSET=latin1;

CREATE TABLE `purchasesrequest` (
  `purchasesrequestkey` int(11) unsigned NOT NULL auto_increment,
  `purchasesrequestcode` varchar(20) NOT NULL default '',
  `purchasesrequestdate` date default NULL,
  `creditorcode` varchar(20) NOT NULL default '',
  `termcode` varchar(20) NOT NULL default '',
  `staffcode` varchar(20) NOT NULL default '',
  `areacode` varchar(20) NOT NULL default '',
  `descr` varchar(200) NOT NULL default '',
  `validity` varchar(100) NOT NULL default '',
  `deliveryterm` varchar(100) NOT NULL default '',
  `refno` varchar(20) NOT NULL default '',
  `address1` varchar(200) NOT NULL default '',
  `address2` varchar(200) NOT NULL default '',
  `address3` varchar(200) NOT NULL default '',
  `address4` varchar(200) NOT NULL default '',
  `attention` varchar(200) NOT NULL default '',
  `phone` varchar(30) NOT NULL default '',
  `fax` varchar(30) NOT NULL default '',
  `discountamount` decimal(20,2) NOT NULL,
  `amountbeforediscount` decimal(20,2) NOT NULL,
  `amount` decimal(20,2) NOT NULL default '0.00',
  `taxamount` decimal(20,2) NOT NULL default '0.00',
  `amountaftertax` decimal(20,2) NOT NULL default '0.00',
  `localtaxamount` decimal(20,2) NOT NULL default '0.00',
  `localamountaftertax` decimal(20,2) NOT NULL default '0.00',
  `note` mediumtext,
  `remark1` varchar(100) NOT NULL,
  `remark2` varchar(100) NOT NULL,
  `remark3` varchar(100) NOT NULL,
  `remark4` varchar(100) NOT NULL,
  `remark5` varchar(100) NOT NULL,
  `remark6` varchar(100) NOT NULL,
  `remark7` varchar(100) NOT NULL,
  `remark8` varchar(100) NOT NULL,
  `globaldepartment` enum('Y','N') NOT NULL default 'Y',
  `departmentcode` varchar(20) NOT NULL default '',
  `globaljob` enum('Y','N') NOT NULL default 'N',
  `jobcode` varchar(20) NOT NULL default '',
  `globalstocklocation` enum('Y','N') NOT NULL default 'Y',
  `stocklocationcode` varchar(20) NOT NULL default '',
  `closed` enum('Y','N') NOT NULL default 'N',
  `itemformatkey` int(11) unsigned NOT NULL default '0',
  `created` datetime default NULL,
  `modified` datetime default NULL,
  `done` enum('Y','N') NOT NULL default 'N',
  `curcode` varchar(20) NOT NULL,
  `currate` decimal(20,8) unsigned NOT NULL default '1.00000000',
  `localdiscountamount` decimal(20,2) NOT NULL,
  `localamountbeforediscount` decimal(20,2) NOT NULL,
  `localamount` decimal(20,2) NOT NULL default '0.00',
  `approval` enum('Y','N') NOT NULL default 'N',
  `approvalby` varchar(20) NOT NULL,
  `approvaldatetime` datetime default NULL,
  `approvalremark` mediumtext,
  `ref1` varchar(30) NOT NULL,
  `ref2` varchar(30) NOT NULL,
  `ref3` varchar(30) NOT NULL,
  `ref4` varchar(30) NOT NULL,
  `approval2` enum('Y','N') NOT NULL default 'N',
  `approvalby2` varchar(20) NOT NULL,
  `approvaldatetime2` datetime default NULL,
  `approvalremark2` mediumtext,
  `approval3` enum('Y','N') NOT NULL default 'N',
  `approvalby3` varchar(20) NOT NULL,
  `approvaldatetime3` datetime default NULL,
  `approvalremark3` mediumtext,
  `closedremark` varchar(200) default NULL,
  `lastmodified` timestamp NOT NULL default CURRENT_TIMESTAMP on update CURRENT_TIMESTAMP,
  `creditorname` varchar(200) NOT NULL default '',
  `city` varchar(50) NOT NULL default '',
  `postalcode` varchar(10) NOT NULL default '',
  `state` varchar(50) NOT NULL default '',
  `countrycode` varchar(50) NOT NULL default '',
  `branchcode` varchar(20) NOT NULL default '',
  `branchname` varchar(200) NOT NULL default '',
  `branchcontactperson` varchar(200) NOT NULL default '',
  `branchphone` varchar(30) NOT NULL default '',
  `branchfax` varchar(30) NOT NULL default '',
  `branchemail` varchar(200) NOT NULL default '',
  `branchaddress1` varchar(200) NOT NULL default '',
  `branchaddress2` varchar(200) NOT NULL default '',
  `branchaddress3` varchar(200) NOT NULL default '',
  `branchaddress4` varchar(200) NOT NULL default '',
  `branchcity` varchar(50) NOT NULL default '',
  `branchpostalcode` varchar(10) NOT NULL default '',
  `branchstate` varchar(50) NOT NULL default '',
  `branchcountrycode` varchar(50) NOT NULL default '',
  `fromoldversion` enum('Y','N') NOT NULL default 'N',
  PRIMARY KEY  (`purchasesrequestkey`),
  UNIQUE KEY `iprcode` (`purchasesrequestcode`),
  KEY `iprdate` (`purchasesrequestdate`),
  KEY `iprcreditorcode` (`creditorcode`),
  KEY `iprtermcode` (`termcode`),
  KEY `iprstaffcode` (`staffcode`),
  KEY `iprrefno` (`refno`),
  KEY `iprdepartmentcode` (`departmentcode`),
  KEY `iprstocklocationcode` (`stocklocationcode`),
  KEY `iprareacode` (`areacode`),
  KEY `iprapproval` (`approval`),
  KEY `iprcurcode` (`curcode`),
  KEY `iprclosed` (`closed`),
  KEY `iprapproval2` (`approval2`),
  KEY `iprapproval3` (`approval3`),
  KEY `iprjobcode` (`jobcode`),
  KEY `iprcountrycode` (`countrycode`),
  KEY `iprbranchcountrycode` (`branchcountrycode`)
) ENGINE=INNODB DEFAULT CHARSET=latin1;

CREATE TABLE `purchasesrequestid` (
  `purchasesrequestkey` int(11) unsigned NOT NULL default '0',
  `id` int(11) unsigned NOT NULL default '0',
  PRIMARY KEY  (`purchasesrequestkey`,`id`)
) ENGINE=INNODB DEFAULT CHARSET=latin1;

CREATE TABLE `purchasesrequestitem` (
  `purchasesrequestkey` int(11) unsigned NOT NULL default '0',
  `purchasesrequestcode` varchar(20) NOT NULL default '',
  `id` int(11) unsigned NOT NULL default '0',
  `pos` int(11) unsigned NOT NULL default '0',
  `itemno` varchar(10) NOT NULL default '',
  `stockcode` varchar(30) NOT NULL default '',
  `descr` varchar(200) NOT NULL default '',
  `moredescr` text,
  `qty` decimal(20,6) default NULL,
  `unitprice` decimal(20,6) default NULL,
  `uom` varchar(20) NOT NULL default '',
  `uomrate` double NOT NULL default '1',
  `qtybaseuom` decimal(20,6) NOT NULL default '0.000000',
  `unitpricebaseuom` double NOT NULL default '0',
  `discountformat` varchar(100) default NULL,
  `discountamount` decimal(20,2) default NULL,
  `amountbeforediscount` decimal(20,2) default NULL,
  `amount` decimal(20,2) default NULL,
  `gsttypecode` varchar(20) NOT NULL default '',
  `purchasestaxpercentage` decimal(20,2) default NULL,
  `purchasestaxamount` decimal(20,2) default NULL,
  `amountaftertax` decimal(20,2) default NULL,
  `departmentcode` varchar(20) NOT NULL default '',
  `jobcode` varchar(20) NOT NULL default '',
  `stocklocationcode` varchar(20) NOT NULL default '',
  `creditoritemcode` varchar(30) NOT NULL default '',
  `barcode` varchar(30) NOT NULL default '',
  `remark1` varchar(100) NOT NULL,
  `remark2` varchar(100) NOT NULL,
  `remark3` varchar(100) NOT NULL,
  `remark4` varchar(100) NOT NULL,
  `rowtype` enum('','TOTALUP','ITEMDISCOUNT','ITEMSERVICETAX','ITEMMISCCHARGES','FOOTERDISCOUNT','FOOTERSERVICETAX','FOOTERMISCCHARGES') NOT NULL,
  `foc` enum('Y','N') NOT NULL default 'N',
  `packingqty` decimal(20,6) default NULL,
  `packinguom` varchar(20) NOT NULL default '',
  `packingrate` decimal(20,6) default NULL,
  `batchno` varchar(30) NOT NULL default '',
  `curcode` varchar(20) NOT NULL default '',
  `curprice` decimal(20,6) default NULL,
  `currate` decimal(20,8) unsigned default NULL,
  `recommendpricebaseuom` decimal(20,6) unsigned NOT NULL default '0.000000',
  `weightrate` decimal(20,6) unsigned NOT NULL default '0.000000',
  `weightuom` varchar(20) NOT NULL default '',
  `weightqty` decimal(20,6) unsigned NOT NULL default '0.000000',
  `weightloosed` decimal(20,6) unsigned NOT NULL default '0.000000',
  `totalweight` decimal(20,6) unsigned NOT NULL default '0.000000',
  `volumerate` decimal(20,6) unsigned NOT NULL default '0.000000',
  `volumeuom` varchar(20) NOT NULL default '',
  `volumeqty` decimal(20,6) unsigned NOT NULL default '0.000000',
  `volumeloosed` decimal(20,6) unsigned NOT NULL default '0.000000',
  `totalvolume` decimal(20,6) unsigned NOT NULL default '0.000000',
  `supplypurchase` enum('None','Supply','Purchase') NOT NULL default 'None',
  `taxsubtract` enum('Y','N') NOT NULL default 'N',
  `taxableamount` decimal(20,2) NOT NULL default '0.00',
  `taxablelocalamount` decimal(20,2) NOT NULL default '0.00',
  `amountaftertaxsubtract` decimal(20,2) NOT NULL default '0.00',
  `localamountaftertaxsubtract` decimal(20,2) NOT NULL default '0.00',
  `purchasestaxlocalamount` decimal(20,2) NOT NULL default '0.00',
  `taxadjustment` decimal(20,2) NOT NULL default '0.00',
  `taxlocaladjustment` decimal(20,2) NOT NULL default '0.00',
  `taxtotalamount` decimal(20,2) NOT NULL default '0.00',
  `taxtotallocalamount` decimal(20,2) NOT NULL default '0.00',
  PRIMARY KEY  (`purchasesrequestkey`,`pos`),
  UNIQUE KEY `iprikeyid` (`purchasesrequestkey`,`id`),
  KEY `ipricode` (`purchasesrequestcode`),
  KEY `ipristockcode` (`stockcode`),
  KEY `ipridepartmentcode` (`departmentcode`),
  KEY `ipristocklocationcode` (`stocklocationcode`),
  KEY `ipribarcode` (`barcode`),
  KEY `iprifoc` (`foc`),
  KEY `iprijobcode` (`jobcode`),
  KEY `iprigsttypecode` (`gsttypecode`),
  KEY `ipribatchno` (`batchno`)
) ENGINE=INNODB DEFAULT CHARSET=latin1;

CREATE TABLE `purchasestransferred` (
  `doctype` varchar(5) NOT NULL default '',
  `dockey` int(11) unsigned NOT NULL default '0',
  `docid` int(11) unsigned NOT NULL default '0',
  `totype` varchar(5) NOT NULL default '',
  `tokey` int(11) unsigned NOT NULL default '0',
  `toid` int(11) unsigned NOT NULL default '0',
  `touom` varchar(20) NOT NULL default '',
  `touomrate` double NOT NULL default '1',
  `toqty` decimal(20,6) NOT NULL default '0.000000',
  `toqtybaseuom` decimal(20,6) NOT NULL default '0.000000',
  PRIMARY KEY  (`doctype`,`dockey`,`docid`,`totype`,`tokey`,`toid`),
  KEY `iptftotypekeyid` (`totype`,`tokey`,`toid`)
) ENGINE=INNODB DEFAULT CHARSET=latin1;

CREATE TABLE `quotation` (
  `quotationkey` int(11) unsigned NOT NULL auto_increment,
  `quotationcode` varchar(20) NOT NULL default '',
  `quotationdate` date default NULL,
  `debtorcode` varchar(20) NOT NULL default '',
  `termcode` varchar(20) NOT NULL default '',
  `staffcode` varchar(20) NOT NULL default '',
  `areacode` varchar(20) NOT NULL default '',
  `descr` varchar(200) NOT NULL default '',
  `validity` varchar(100) NOT NULL default '',
  `deliveryterm` varchar(100) NOT NULL default '',
  `refno` varchar(20) NOT NULL default '',
  `address1` varchar(200) NOT NULL default '',
  `address2` varchar(200) NOT NULL default '',
  `address3` varchar(200) NOT NULL default '',
  `address4` varchar(200) NOT NULL default '',
  `city` varchar(50) NOT NULL default '',
  `postalcode` varchar(10) NOT NULL default '',
  `state` varchar(50) NOT NULL default '',
  `countrycode` varchar(50) NOT NULL default '',
  `attention` varchar(200) NOT NULL default '',
  `phone` varchar(30) NOT NULL default '',
  `fax` varchar(30) NOT NULL default '',
  `discountamount` decimal(20,2) NOT NULL,
  `amountbeforediscount` decimal(20,2) NOT NULL,
  `amount` decimal(20,2) NOT NULL default '0.00',
  `taxamount` decimal(20,2) NOT NULL default '0.00',
  `amountaftertax` decimal(20,2) NOT NULL default '0.00',
  `note` mediumtext,
  `remark1` varchar(100) NOT NULL,
  `remark2` varchar(100) NOT NULL,
  `remark3` varchar(100) NOT NULL,
  `remark4` varchar(100) NOT NULL,
  `remark5` varchar(100) NOT NULL,
  `remark6` varchar(100) NOT NULL,
  `remark7` varchar(100) NOT NULL,
  `remark8` varchar(100) NOT NULL,
  `globaldepartment` enum('Y','N') NOT NULL default 'Y',
  `departmentcode` varchar(20) NOT NULL default '',
  `globaljob` enum('Y','N') NOT NULL default 'N',
  `jobcode` varchar(20) NOT NULL default '',
  `globalstocklocation` enum('Y','N') NOT NULL default 'Y',
  `stocklocationcode` varchar(20) NOT NULL default '',
  `closed` enum('Y','N') NOT NULL default 'N',
  `itemformatkey` int(10) unsigned NOT NULL default '0',
  `created` datetime default NULL,
  `modified` datetime default NULL,
  `done` enum('Y','N') NOT NULL default 'N',
  `branchcode` varchar(20) NOT NULL default '',
  `branchname` varchar(200) NOT NULL default '',
  `docontactperson` varchar(200) NOT NULL default '',
  `dophone` varchar(30) NOT NULL default '',
  `dofax` varchar(30) NOT NULL default '',
  `doemail` varchar(200) NOT NULL default '',
  `doaddress1` varchar(200) NOT NULL default '',
  `doaddress2` varchar(200) NOT NULL default '',
  `doaddress3` varchar(200) NOT NULL default '',
  `doaddress4` varchar(200) NOT NULL default '',
  `docity` varchar(50) NOT NULL default '',
  `dopostalcode` varchar(10) NOT NULL default '',
  `dostate` varchar(50) NOT NULL default '',
  `docountrycode` varchar(50) NOT NULL default '',
  `transactioncost` enum('Y','N') NOT NULL default 'N',
  `curcode` varchar(20) NOT NULL,
  `currate` decimal(20,8) unsigned NOT NULL default '1.00000000',
  `localdiscountamount` decimal(20,2) NOT NULL,
  `localamountbeforediscount` decimal(20,2) NOT NULL,
  `localamount` decimal(20,2) NOT NULL default '0.00',
  `localtaxamount` decimal(20,2) NOT NULL default '0.00',
  `localamountaftertax` decimal(20,2) NOT NULL default '0.00',
  `approval` enum('Y','N') NOT NULL default 'N',
  `approvalby` varchar(20) NOT NULL,
  `approvaldatetime` datetime default NULL,
  `approvalremark` mediumtext,
  `ref1` varchar(30) NOT NULL,
  `ref2` varchar(30) NOT NULL,
  `ref3` varchar(30) NOT NULL,
  `ref4` varchar(30) NOT NULL,
  `lastmodified` timestamp NOT NULL default CURRENT_TIMESTAMP on update CURRENT_TIMESTAMP,
  `salesleadkey` int(10) unsigned NOT NULL default '0',
  `debtorname` varchar(200) NOT NULL default '',
  `fromoldversion` enum('Y','N') NOT NULL default 'N',
  PRIMARY KEY  (`quotationkey`),
  UNIQUE KEY `iquocode` (`quotationcode`),
  KEY `iquodate` (`quotationdate`),
  KEY `iquodebtorcode` (`debtorcode`),
  KEY `iquotermcode` (`termcode`),
  KEY `iquostaffcode` (`staffcode`),
  KEY `iquorefno` (`refno`),
  KEY `iquodepartmentcode` (`departmentcode`),
  KEY `iquostocklocationcode` (`stocklocationcode`),
  KEY `iquoareacode` (`areacode`),
  KEY `iquoapproval` (`approval`),
  KEY `iquocurcode` (`curcode`),
  KEY `iquoclosed` (`closed`),
  KEY `iquojobcode` (`jobcode`),
  KEY `iquosalesleadkey` (`salesleadkey`),
  KEY `iquocountrycode` (`countrycode`),
  KEY `iquodocountrycode` (`docountrycode`)
) ENGINE=INNODB DEFAULT CHARSET=latin1;

CREATE TABLE `quotationid` (
  `quotationkey` int(11) unsigned NOT NULL default '0',
  `id` int(11) unsigned NOT NULL default '0',
  PRIMARY KEY  (`quotationkey`,`id`)
) ENGINE=INNODB DEFAULT CHARSET=latin1;

CREATE TABLE `quotationitem` (
  `quotationkey` int(11) unsigned NOT NULL default '0',
  `quotationcode` varchar(20) NOT NULL default '',
  `id` int(11) unsigned NOT NULL default '0',
  `pos` int(11) unsigned NOT NULL default '0',
  `itemno` varchar(10) NOT NULL default '',
  `stockcode` varchar(30) NOT NULL default '',
  `descr` varchar(200) NOT NULL default '',
  `moredescr` text,
  `qty` decimal(20,6) default NULL,
  `unitprice` decimal(20,6) default NULL,
  `uom` varchar(20) NOT NULL default '',
  `uomrate` double NOT NULL default '1',
  `qtybaseuom` decimal(20,6) NOT NULL default '0.000000',
  `unitpricebaseuom` double NOT NULL default '0',
  `discountformat` varchar(100) default NULL,
  `discountamount` decimal(20,2) default NULL,
  `amountbeforediscount` decimal(20,2) default NULL,
  `amount` decimal(20,2) default NULL,
  `gsttypecode` varchar(20) NOT NULL default '',
  `stockpackagegsttypecode` varchar(20) NOT NULL default '',
  `salestaxpercentage` decimal(20,2) default NULL,
  `salestaxamount` decimal(20,2) default NULL,
  `amountaftertax` decimal(20,2) default NULL,
  `departmentcode` varchar(20) NOT NULL default '',
  `jobcode` varchar(20) NOT NULL default '',
  `stocklocationcode` varchar(20) NOT NULL default '',
  `debtoritemcode` varchar(30) NOT NULL default '',
  `barcode` varchar(30) NOT NULL default '',
  `remark1` varchar(100) NOT NULL,
  `remark2` varchar(100) NOT NULL,
  `remark3` varchar(100) NOT NULL,
  `remark4` varchar(100) NOT NULL,
  `rowtype` enum('','TOTALUP','ITEMDISCOUNT','ITEMSERVICETAX','ITEMMISCCHARGES','FOOTERDISCOUNT','FOOTERSERVICETAX','FOOTERMISCCHARGES') NOT NULL,
  `foc` enum('Y','N') NOT NULL default 'N',
  `packingqty` decimal(20,6) default NULL,
  `packinguom` varchar(20) NOT NULL default '',
  `packingrate` decimal(20,6) default NULL,
  `costtype` enum('Costing Method','Manual') NOT NULL default 'Manual',
  `unitcost` decimal(20,2) NOT NULL default '0.00',
  `stockpackagecode` varchar(20) NOT NULL,
  `stockpackageid` int(11) unsigned NOT NULL default '0',
  `stockpackagerate` double default NULL,
  `stockpackageqty` decimal(20,6) default NULL,
  `stockpackageunitprice` decimal(20,6) default NULL,
  `stockpackageamount` decimal(20,2) default NULL,
  `stockpackagesalestaxpercentage` decimal(20,2) default NULL,
  `stockpackagesalestaxamount` decimal(20,2) default NULL,
  `stockpackageamountaftertax` decimal(20,2) default NULL,
  `batchno` varchar(30) NOT NULL default '',
  `curcode` varchar(20) NOT NULL default '',
  `curprice` decimal(20,6) default NULL,
  `currate` decimal(20,8) unsigned default NULL,
  `recommendpricebaseuom` decimal(20,6) unsigned NOT NULL default '0.000000',
  `weightrate` decimal(20,6) unsigned NOT NULL default '0.000000',
  `weightuom` varchar(20) NOT NULL default '',
  `weightqty` decimal(20,6) unsigned NOT NULL default '0.000000',
  `weightloosed` decimal(20,6) unsigned NOT NULL default '0.000000',
  `totalweight` decimal(20,6) unsigned NOT NULL default '0.000000',
  `volumerate` decimal(20,6) unsigned NOT NULL default '0.000000',
  `volumeuom` varchar(20) NOT NULL default '',
  `volumeqty` decimal(20,6) unsigned NOT NULL default '0.000000',
  `volumeloosed` decimal(20,6) unsigned NOT NULL default '0.000000',
  `totalvolume` decimal(20,6) unsigned NOT NULL default '0.000000',
  `supplypurchase` enum('None','Supply','Purchase') NOT NULL default 'None',
  `taxsubtract` enum('Y','N') NOT NULL default 'N',
  `taxableamount` decimal(20,2) NOT NULL default '0.00',
  `taxablelocalamount` decimal(20,2) NOT NULL default '0.00',
  `amountaftertaxsubtract` decimal(20,2) NOT NULL default '0.00',
  `localamountaftertaxsubtract` decimal(20,2) NOT NULL default '0.00',
  `salestaxlocalamount` decimal(20,2) NOT NULL default '0.00',
  `taxadjustment` decimal(20,2) NOT NULL default '0.00',
  `taxlocaladjustment` decimal(20,2) NOT NULL default '0.00',
  `taxtotalamount` decimal(20,2) NOT NULL default '0.00',
  `taxtotallocalamount` decimal(20,2) NOT NULL default '0.00',
  `stockpackagesupplypurchase` enum('None','Supply','Purchase') NOT NULL default 'None',
  `stockpackagetaxsubtract` enum('Y','N') NOT NULL default 'N',
  `stockpackagetaxableamount` decimal(20,2) NOT NULL default '0.00',
  `stockpackagetaxablelocalamount` decimal(20,2) NOT NULL default '0.00',
  `stockpackageamountaftertaxsubtract` decimal(20,2) NOT NULL default '0.00',
  `stockpackagelocalamountaftertaxsubtract` decimal(20,2) NOT NULL default '0.00',
  `stockpackagesalestaxlocalamount` decimal(20,2) NOT NULL default '0.00',
  `stockpackagetaxadjustment` decimal(20,2) NOT NULL default '0.00',
  `stockpackagetaxlocaladjustment` decimal(20,2) NOT NULL default '0.00',
  `stockpackagetaxtotalamount` decimal(20,2) NOT NULL default '0.00',
  `stockpackagetaxtotallocalamount` decimal(20,2) NOT NULL default '0.00',
  PRIMARY KEY  (`quotationkey`,`pos`),
  UNIQUE KEY `iquoikeyid` (`quotationkey`,`id`),
  KEY `iquoicode` (`quotationcode`),
  KEY `iquoistockcode` (`stockcode`),
  KEY `iquoidepartmentcode` (`departmentcode`),
  KEY `iquoistocklocationcode` (`stocklocationcode`),
  KEY `iquoibarcode` (`barcode`),
  KEY `iqouifoc` (`foc`),
  KEY `iquoistockpackagecode` (`stockpackagecode`),
  KEY `iquoistockpackageid` (`stockpackageid`),
  KEY `iquoijobcode` (`jobcode`),
  KEY `iquoigsttypecode` (`gsttypecode`),
  KEY `iquoistockpackagegsttypecode` (`stockpackagegsttypecode`),
  KEY `iqouibatchno` (`batchno`)
) ENGINE=INNODB DEFAULT CHARSET=latin1;

CREATE TABLE `receipt` (
  `receiptkey` int(11) unsigned NOT NULL auto_increment,
  `receiptcode` varchar(20) NOT NULL default '',
  `cashbooktypecode` varchar(20) NOT NULL default '',
  `receiptdate` date default NULL,
  `receiptacccode` varchar(20) NOT NULL default '',
  `acccode` varchar(20) NOT NULL default '',
  `receivedfrom` varchar(50) NOT NULL default '',
  `descr` varchar(200) NOT NULL default '',
  `chequeno` varchar(20) NOT NULL default '',
  `multi` enum('Y','N') NOT NULL default 'N',
  `amount` decimal(20,2) NOT NULL default '0.00',
  `staffcode` varchar(20) NOT NULL default '',
  `areacode` varchar(20) NOT NULL default '',
  `remark1` varchar(200) NOT NULL,
  `remark2` varchar(200) NOT NULL,
  `remark3` varchar(200) NOT NULL,
  `remark4` varchar(200) NOT NULL,
  `remark5` varchar(200) NOT NULL,
  `remark6` varchar(200) NOT NULL,
  `remark7` varchar(200) NOT NULL,
  `remark8` varchar(200) NOT NULL,
  `note` mediumtext,
  `departmentcode` varchar(20) NOT NULL default '',
  `jobcode` varchar(20) NOT NULL default '',
  `cancelled` enum('Y','N') NOT NULL default 'N',
  `cancelledremark` varchar(200) NOT NULL,
  `done` enum('Y','N') NOT NULL default 'N',
  `curcode` varchar(20) NOT NULL,
  `currate` decimal(20,8) unsigned NOT NULL default '1.00000000',
  `localamount` decimal(20,2) NOT NULL default '0.00',
  `chequereceiveddate` date default NULL,
  `chequeissuedby` varchar(200) NOT NULL default '',
  `datedrawable` date default NULL,
  `bankandlocality` varchar(200) NOT NULL default '',
  `trno` varchar(20) NOT NULL,
  `bankchargeacccode` varchar(20) NOT NULL default '',
  `bcurcode` varchar(20) NOT NULL default '',
  `bcurrate` decimal(20,8) unsigned NOT NULL default '1.00000000',
  `bamount` decimal(20,2) NOT NULL default '0.00',
  `bankcharges` decimal(20,2) NOT NULL default '0.00',
  `blocalcurrate` decimal(20,8) unsigned NOT NULL default '1.00000000',
  `blocalamount` decimal(20,2) NOT NULL default '0.00',
  `localbankcharges` decimal(20,2) NOT NULL default '0.00',
  `lastmodified` timestamp NOT NULL default CURRENT_TIMESTAMP on update CURRENT_TIMESTAMP,
  `totaltaxableamount` decimal(20,2) NOT NULL default '0.00',
  `totaltaxablelocalamount` decimal(20,2) NOT NULL default '0.00',
  `totaltaxamount` decimal(20,2) NOT NULL default '0.00',
  `totaltaxlocalamount` decimal(20,2) NOT NULL default '0.00',
  `totalamountaftertaxsubtract` decimal(20,2) NOT NULL default '0.00',
  `totallocalamountaftertaxsubtract` decimal(20,2) NOT NULL default '0.00',
  `fromdoctype` varchar(5) NOT NULL default '',
  `fromdockey` int(11) unsigned default '0',
  `fromdoccode` varchar(20) NOT NULL default '',
  `baddebtgsttypecode` varchar(20) NOT NULL default '',
  `debtorgstbaddebtrecovercode1st` varchar(20) NOT NULL default '',
  `journaldebtorgstbaddebtrecovercode1st` varchar(20) NOT NULL default '',
  PRIMARY KEY  (`receiptkey`),
  UNIQUE KEY `ircode` (`receiptcode`),
  KEY `irdate` (`receiptdate`),
  KEY `irreceiptacccode` (`receiptacccode`),
  KEY `iracccode` (`acccode`),
  KEY `irchequeno` (`chequeno`),
  KEY `irmulti` (`multi`),
  KEY `irdepartmentcode` (`departmentcode`),
  KEY `irstaffcode` (`staffcode`),
  KEY `irareacode` (`areacode`),
  KEY `ircancelled` (`cancelled`),
  KEY `ircurcode` (`curcode`),
  KEY `ircashbooktypecode` (`cashbooktypecode`),
  KEY `irjobcode` (`jobcode`),
  KEY `irbankchargeacccode` (`bankchargeacccode`),
  KEY `irbcurcode` (`bcurcode`),
  KEY `irfromdoctype` (`fromdoctype`),
  KEY `ipfromdockey` (`fromdockey`),
  KEY `irfromdoccode` (`fromdoccode`),
  KEY `irbaddebtgsttypecode` (`baddebtgsttypecode`),
  KEY `irdebtorgstbaddebtrecovercode1st` (`debtorgstbaddebtrecovercode1st`),
  KEY `irjournaldebtorgstbaddebtrecovercode1st` (`journaldebtorgstbaddebtrecovercode1st`)
) ENGINE=INNODB DEFAULT CHARSET=latin1;

CREATE TABLE `receiptmulti` (
  `receiptkey` int(11) unsigned NOT NULL default '0',
  `receiptcode` varchar(20) NOT NULL default '',
  `pos` int(11) unsigned NOT NULL default '0',
  `acccode` varchar(20) NOT NULL default '',
  `descr` varchar(200) NOT NULL default '',
  `descr2` varchar(200) NOT NULL default '',
  `subamount` decimal(20,2) NOT NULL default '0.00',
  `staffcode` varchar(20) NOT NULL default '',
  `departmentcode` varchar(20) NOT NULL default '',
  `jobcode` varchar(20) NOT NULL default '',
  `localsubamount` decimal(20,2) NOT NULL default '0.00',
  `refno` varchar(20) NOT NULL default '',
  `refno2` varchar(20) NOT NULL default '',
  `splitprint` enum('Y','N') NOT NULL default 'N',
  `amountbeforetax` decimal(20,2) NOT NULL default '0.00',
  `localamountbeforetax` decimal(20,2) NOT NULL default '0.00',
  `gsttypecode` varchar(20) NOT NULL default '',
  `supplypurchase` enum('None','Supply','Purchase') NOT NULL default 'None',
  `taxpercentage` decimal(20,2) default NULL,
  `taxacccode` varchar(20) NOT NULL default '',
  `taxsubtract` enum('Y','N') NOT NULL default 'N',
  `taxableamount` decimal(20,2) NOT NULL default '0.00',
  `taxablelocalamount` decimal(20,2) NOT NULL default '0.00',
  `amountaftertaxsubtract` decimal(20,2) NOT NULL default '0.00',
  `localamountaftertaxsubtract` decimal(20,2) NOT NULL default '0.00',
  `taxamount` decimal(20,2) NOT NULL default '0.00',
  `taxlocalamount` decimal(20,2) NOT NULL default '0.00',
  `taxadjustment` decimal(20,2) NOT NULL default '0.00',
  `taxlocaladjustment` decimal(20,2) NOT NULL default '0.00',
  `taxtotalamount` decimal(20,2) NOT NULL default '0.00',
  `taxtotallocalamount` decimal(20,2) NOT NULL default '0.00',
  `taxrefno` varchar(50) NOT NULL default '',
  PRIMARY KEY  (`receiptkey`,`pos`),
  KEY `irmacccode` (`acccode`),
  KEY `irmcode` (`receiptcode`),
  KEY `irmdepartmentcode` (`departmentcode`),
  KEY `irmjobcode` (`jobcode`),
  KEY `irmstaffcode` (`staffcode`),
  KEY `irmgsttypecode` (`gsttypecode`),
  KEY `irmtaxacccode` (`taxacccode`)
) ENGINE=INNODB DEFAULT CHARSET=latin1;

CREATE TABLE `recuringjournaltemplate` (
  `recuringjournaltemplatekey` int(11) unsigned NOT NULL auto_increment,
  `recuringjournaltemplatecode` varchar(20) NOT NULL default '',
  `descr` varchar(200) NOT NULL default '',
  `refno` varchar(20) NOT NULL default '',
  `inactive` enum('Y','N') NOT NULL default 'N',
  `journalnoformatkey` int(11) unsigned NOT NULL default '0',
  `journalbooktypecode` varchar(20) NOT NULL default '',
  `journaldescr` varchar(200) NOT NULL default '',
  `lastjournalgenerateddate` datetime default NULL,
  `done` enum('Y','N') NOT NULL default 'N',
  PRIMARY KEY  (`recuringjournaltemplatekey`),
  UNIQUE KEY `irjtcode` (`recuringjournaltemplatecode`),
  KEY `irjtinactive` (`inactive`)
) ENGINE=INNODB DEFAULT CHARSET=latin1;

CREATE TABLE `recuringjournaltemplatemulti` (
  `recuringjournaltemplatekey` int(11) unsigned NOT NULL default '0',
  `pos` int(11) unsigned NOT NULL default '0',
  `acccode` varchar(20) NOT NULL default '',
  `descr` varchar(200) NOT NULL default '',
  `descr2` varchar(200) NOT NULL default '',
  `refno` varchar(20) NOT NULL default '',
  `refno2` varchar(20) NOT NULL default '',
  `debit` decimal(20,2) NOT NULL default '0.00',
  `credit` decimal(20,2) NOT NULL default '0.00',
  `staffcode` varchar(20) NOT NULL default '',
  `departmentcode` varchar(20) NOT NULL default '',
  `jobcode` varchar(20) NOT NULL default '',
  `curcode` varchar(20) NOT NULL,
  `currate` decimal(20,8) unsigned NOT NULL default '1.00000000',
  `localdebit` decimal(20,2) NOT NULL default '0.00',
  `localcredit` decimal(20,2) NOT NULL default '0.00',
  `postingdate` date default NULL,
  `remark1` varchar(200) NOT NULL default '',
  `remark2` varchar(200) NOT NULL default '',
  `printtype` enum('J','R','P') NOT NULL default 'J',
  `gsttypecode` varchar(20) NOT NULL default '',
  `supplypurchase` enum('None','Supply','Purchase') NOT NULL default 'None',
  `taxpercentage` decimal(20,2) default NULL,
  `taxacccode` varchar(20) NOT NULL default '',
  `taxsubtract` enum('Y','N') NOT NULL default 'N',
  `taxablelocaldebit` decimal(20,2) NOT NULL default '0.00',
  `taxablelocalcredit` decimal(20,2) NOT NULL default '0.00',
  `taxlocaldebit` decimal(20,2) NOT NULL default '0.00',
  `taxlocalcredit` decimal(20,2) NOT NULL default '0.00',
  `taxadjustment` decimal(20,2) NOT NULL default '0.00',
  `localdebitaftertaxsubtract` decimal(20,2) NOT NULL default '0.00',
  `localcreditaftertaxsubtract` decimal(20,2) NOT NULL default '0.00',
  `totallocaldebit` decimal(20,2) NOT NULL default '0.00',
  `totallocalcredit` decimal(20,2) NOT NULL default '0.00',
  `taxpermitno` varchar(50) NOT NULL default '',
  `taxexportcountrycode` varchar(50) NOT NULL default '',
  `taxrefno` varchar(50) NOT NULL default '',
  PRIMARY KEY  (`recuringjournaltemplatekey`,`pos`),
  KEY `irjtacccode` (`acccode`),
  KEY `irjtdepartmentcode` (`departmentcode`),
  KEY `irjtcurcode` (`curcode`),
  KEY `irjtjobcode` (`jobcode`),
  KEY `irjtstaffcode` (`staffcode`),
  KEY `irjtgsttypecode` (`gsttypecode`),
  KEY `irjttaxacccode` (`taxacccode`),
  KEY `irjttaxexportcountrycode` (`taxexportcountrycode`)
) ENGINE=INNODB DEFAULT CHARSET=latin1;

CREATE TABLE `recuringpaymenttemplate` (
  `recuringpaymenttemplatekey` int(11) unsigned NOT NULL auto_increment,
  `recuringpaymenttemplatecode` varchar(20) NOT NULL default '',
  `descr` varchar(200) NOT NULL default '',
  `inactive` enum('Y','N') NOT NULL default 'N',
  `paymentnoformatkey` int(11) unsigned NOT NULL default '0',
  `cashbooktypecode` varchar(20) NOT NULL default '',
  `paymentacccode` varchar(20) NOT NULL default '',
  `acccode` varchar(20) NOT NULL default '',
  `payto` varchar(50) NOT NULL default '',
  `paymentdescr` varchar(200) NOT NULL default '',
  `autochequeno` enum('Y','N') NOT NULL default 'N',
  `chequenoformatkey` int(11) unsigned NOT NULL default '0',
  `multi` enum('Y','N') NOT NULL default 'N',
  `amount` decimal(20,2) NOT NULL default '0.00',
  `staffcode` varchar(20) NOT NULL default '',
  `areacode` varchar(20) NOT NULL default '',
  `remark1` varchar(200) NOT NULL,
  `remark2` varchar(200) NOT NULL,
  `remark3` varchar(200) NOT NULL,
  `remark4` varchar(200) NOT NULL,
  `remark5` varchar(200) NOT NULL,
  `remark6` varchar(200) NOT NULL,
  `remark7` varchar(200) NOT NULL,
  `remark8` varchar(200) NOT NULL,
  `note` mediumtext,
  `departmentcode` varchar(20) NOT NULL default '',
  `jobcode` varchar(20) NOT NULL default '',
  `cancelled` enum('Y','N') NOT NULL default 'N',
  `cancelledremark` varchar(200) NOT NULL,
  `done` enum('Y','N') NOT NULL default 'N',
  `curcode` varchar(20) NOT NULL,
  `currate` decimal(20,8) unsigned NOT NULL default '1.00000000',
  `localamount` decimal(20,2) NOT NULL default '0.00',
  `bankchargeacccode` varchar(20) NOT NULL default '',
  `bcurcode` varchar(20) NOT NULL default '',
  `bcurrate` decimal(20,8) unsigned NOT NULL default '1.00000000',
  `bamount` decimal(20,2) NOT NULL default '0.00',
  `bankcharges` decimal(20,2) NOT NULL default '0.00',
  `blocalcurrate` decimal(20,8) unsigned NOT NULL default '1.00000000',
  `blocalamount` decimal(20,2) NOT NULL default '0.00',
  `localbankcharges` decimal(20,2) NOT NULL default '0.00',
  `lastpaymentgenerateddate` datetime default NULL,
  `totaltaxableamount` decimal(20,2) NOT NULL default '0.00',
  `totaltaxablelocalamount` decimal(20,2) NOT NULL default '0.00',
  `totaltaxamount` decimal(20,2) NOT NULL default '0.00',
  `totaltaxlocalamount` decimal(20,2) NOT NULL default '0.00',
  `totalamountaftertaxsubtract` decimal(20,2) NOT NULL default '0.00',
  `totallocalamountaftertaxsubtract` decimal(20,2) NOT NULL default '0.00',
  PRIMARY KEY  (`recuringpaymenttemplatekey`),
  UNIQUE KEY `irptcode` (`recuringpaymenttemplatecode`),
  KEY `irptinactive` (`inactive`)
) ENGINE=INNODB DEFAULT CHARSET=latin1;

CREATE TABLE `recuringpaymenttemplatemulti` (
  `recuringpaymenttemplatekey` int(11) unsigned NOT NULL default '0',
  `pos` int(11) unsigned NOT NULL default '0',
  `acccode` varchar(20) NOT NULL default '',
  `descr` varchar(200) NOT NULL default '',
  `descr2` varchar(200) NOT NULL default '',
  `subamount` decimal(20,2) NOT NULL default '0.00',
  `staffcode` varchar(20) NOT NULL default '',
  `departmentcode` varchar(20) NOT NULL default '',
  `jobcode` varchar(20) NOT NULL default '',
  `localsubamount` decimal(20,2) NOT NULL default '0.00',
  `refno` varchar(20) NOT NULL default '',
  `refno2` varchar(20) NOT NULL default '',
  `splitprint` enum('Y','N') NOT NULL default 'N',
  `amountbeforetax` decimal(20,2) NOT NULL default '0.00',
  `localamountbeforetax` decimal(20,2) NOT NULL default '0.00',
  `gsttypecode` varchar(20) NOT NULL default '',
  `supplypurchase` enum('None','Supply','Purchase') NOT NULL default 'None',
  `taxpercentage` decimal(20,2) default NULL,
  `taxacccode` varchar(20) NOT NULL default '',
  `taxsubtract` enum('Y','N') NOT NULL default 'N',
  `taxableamount` decimal(20,2) NOT NULL default '0.00',
  `taxablelocalamount` decimal(20,2) NOT NULL default '0.00',
  `amountaftertaxsubtract` decimal(20,2) NOT NULL default '0.00',
  `localamountaftertaxsubtract` decimal(20,2) NOT NULL default '0.00',
  `taxamount` decimal(20,2) NOT NULL default '0.00',
  `taxlocalamount` decimal(20,2) NOT NULL default '0.00',
  `taxadjustment` decimal(20,2) NOT NULL default '0.00',
  `taxlocaladjustment` decimal(20,2) NOT NULL default '0.00',
  `taxtotalamount` decimal(20,2) NOT NULL default '0.00',
  `taxtotallocalamount` decimal(20,2) NOT NULL default '0.00',
  `taxrefno` varchar(50) NOT NULL default '',
  PRIMARY KEY  (`recuringpaymenttemplatekey`,`pos`),
  KEY `irptacccode` (`acccode`),
  KEY `irptdepartmentcode` (`departmentcode`),
  KEY `irptjobcode` (`jobcode`),
  KEY `irptstaffcode` (`staffcode`),
  KEY `irpmgsttypecode` (`gsttypecode`),
  KEY `irpmtaxacccode` (`taxacccode`)
) ENGINE=INNODB DEFAULT CHARSET=latin1;

CREATE TABLE `remoteapprovalinfo` (
  `remoteapprovalinfokey` int(11) unsigned NOT NULL auto_increment,
  `doctype` varchar(5) NOT NULL default '',
  `docdate` date default NULL,
  `doccode` varchar(20) NOT NULL default '',
  `acccode` varchar(20) NOT NULL default '',
  `accname` varchar(200) NOT NULL default '',
  `loginusercode` varchar(20) NOT NULL default '',
  `approvalusercode` varchar(20) NOT NULL default '',
  `approve` enum('Y','N') NOT NULL default 'N',
  `reject` enum('Y','N') NOT NULL default 'N',
  `approvaltype` varchar(250) default '',
  `remark` varchar(250) default '',
  `detailinfo` mediumblob,
  `reason` varchar(250) NOT NULL default '',
  PRIMARY KEY  (`remoteapprovalinfokey`),
  KEY `irapidoctypecode` (`doctype`,`doccode`)
) ENGINE=INNODB DEFAULT CHARSET=latin1;

CREATE TABLE `report` (
  `reporttype` varchar(30) NOT NULL default '',
  `reportcode` varchar(20) NOT NULL default '',
  `descr` varchar(200) NOT NULL default '',
  `reportblob` mediumblob,
  `printername` varchar(250) NOT NULL default '',
  `lastmodified` timestamp NOT NULL default CURRENT_TIMESTAMP on update CURRENT_TIMESTAMP,
  PRIMARY KEY  (`reporttype`,`reportcode`)
) ENGINE=INNODB DEFAULT CHARSET=latin1;

CREATE TABLE `reportaudittrail` (
  `formname` varchar(100) NOT NULL default '',
  `formcode` varchar(50) NOT NULL default '',
  `version` int(10) unsigned NOT NULL,
  `actiondatetime` datetime NOT NULL default '0000-00-00 00:00:00',
  `action` varchar(20) NOT NULL default '',
  `usercode` varchar(20) NOT NULL default '',
  `remarks` varchar(250) default '',
  `dockeylist` mediumtext,
  `doccodelist` longtext,
  PRIMARY KEY  (`formcode`,`formname`,`version`)
) ENGINE=INNODB DEFAULT CHARSET=latin1;

CREATE TABLE `reportfilter` (
  `reportfilterkey` int(11) unsigned NOT NULL auto_increment,
  `reportcode` varchar(20) NOT NULL default '',
  `fieldcode` varchar(50) NOT NULL default '',
  `descr` varchar(100) NOT NULL default '',
  `type` varchar(20) NOT NULL default '',
  `isselective` enum('Y','N') NOT NULL default 'N',
  `isrange` enum('Y','N') NOT NULL default 'N',
  PRIMARY KEY  (`reportfilterkey`),
  UNIQUE KEY `idrmfilter` (`reportcode`,`fieldcode`)
) ENGINE=INNODB DEFAULT CHARSET=latin1;

CREATE TABLE `reportmanager` (
  `reportkey` int(11) unsigned NOT NULL auto_increment,
  `reportcode` varchar(20) NOT NULL default '',
  `reporttype` varchar(50) NOT NULL default '',
  `system` enum('Y','N') NOT NULL default 'N',
  `descr` varchar(100) NOT NULL default '',
  `beforecommand` mediumtext,
  `selectcommand` mediumtext,
  `aftercommand` mediumtext,
  `moduletype` int(11) NOT NULL default '-1',
  `pos` int(11) NOT NULL default '1',
  `formaname` varchar(50) NOT NULL default '',
  PRIMARY KEY  (`reportkey`),
  UNIQUE KEY `idrmcodesystem` (`reportcode`,`system`)
) ENGINE=INNODB DEFAULT CHARSET=latin1;

CREATE TABLE `reportseq` (
  `reporttype` varchar(30) NOT NULL default '',
  `reportcode` varchar(20) NOT NULL default '',
  `seq` int(11) NOT NULL default '0',
  `usercode` varchar(20) NOT NULL default '',
  PRIMARY KEY  (`reporttype`,`reportcode`,`usercode`)
) ENGINE=INNODB DEFAULT CHARSET=latin1;

CREATE TABLE `rmaclaim` (
  `rmaclaimkey` int(11) unsigned NOT NULL auto_increment,
  `rmaclaimcode` varchar(20) NOT NULL default '',
  `rmaclaimdate` date default NULL,
  `creditorcode` varchar(20) NOT NULL default '',
  `termcode` varchar(20) NOT NULL default '',
  `staffcode` varchar(20) NOT NULL default '',
  `areacode` varchar(20) NOT NULL default '',
  `descr` varchar(200) NOT NULL default '',
  `refno` varchar(20) NOT NULL default '',
  `ourrefno` varchar(20) NOT NULL default '',
  `attention` varchar(200) NOT NULL default '',
  `address1` varchar(200) NOT NULL default '',
  `address2` varchar(200) NOT NULL default '',
  `address3` varchar(200) NOT NULL default '',
  `address4` varchar(200) NOT NULL default '',
  `phone` varchar(30) NOT NULL default '',
  `fax` varchar(30) NOT NULL default '',
  `note` mediumtext,
  `remark1` varchar(100) NOT NULL,
  `remark2` varchar(100) NOT NULL,
  `remark3` varchar(100) NOT NULL,
  `remark4` varchar(100) NOT NULL,
  `remark5` varchar(100) NOT NULL,
  `remark6` varchar(100) NOT NULL,
  `remark7` varchar(100) NOT NULL,
  `remark8` varchar(100) NOT NULL,
  `globaldepartment` enum('Y','N') NOT NULL default 'Y',
  `departmentcode` varchar(20) NOT NULL default '',
  `globaljob` enum('Y','N') NOT NULL default 'N',
  `jobcode` varchar(20) NOT NULL default '',
  `globalstocklocation` enum('Y','N') NOT NULL default 'Y',
  `stocklocationcode` varchar(20) NOT NULL default '',
  `closed` enum('Y','N') NOT NULL default 'N',
  `cancelled` enum('Y','N') NOT NULL default 'N',
  `itemformatkey` int(10) unsigned NOT NULL default '0',
  `created` datetime default NULL,
  `modified` datetime default NULL,
  `done` enum('Y','N') NOT NULL default 'N',
  `curcode` varchar(20) NOT NULL,
  `currate` decimal(20,8) unsigned NOT NULL default '1.00000000',
  PRIMARY KEY  (`rmaclaimkey`),
  UNIQUE KEY `irmaccode` (`rmaclaimcode`),
  KEY `irmacdate` (`rmaclaimdate`),
  KEY `irmaccreditorcode` (`creditorcode`),
  KEY `irmactermcode` (`termcode`),
  KEY `irmacstaffcode` (`staffcode`),
  KEY `irmacrefno` (`refno`),
  KEY `irmacdepartmentcode` (`departmentcode`),
  KEY `irmacstocklocationcode` (`stocklocationcode`),
  KEY `irmacclosed` (`closed`),
  KEY `irmacareacode` (`areacode`),
  KEY `irmaccurcode` (`curcode`),
  KEY `irmacjobcode` (`jobcode`)
) ENGINE=INNODB DEFAULT CHARSET=latin1;

CREATE TABLE `rmaclaimid` (
  `rmaclaimkey` int(11) unsigned NOT NULL default '0',
  `id` int(11) unsigned NOT NULL default '0',
  PRIMARY KEY  (`rmaclaimkey`,`id`)
) ENGINE=INNODB DEFAULT CHARSET=latin1;

CREATE TABLE `rmaclaimitem` (
  `rmaclaimkey` int(11) unsigned NOT NULL default '0',
  `rmaclaimcode` varchar(20) NOT NULL default '',
  `id` int(11) unsigned NOT NULL default '0',
  `pos` int(11) unsigned NOT NULL default '0',
  `itemno` varchar(10) NOT NULL default '',
  `stockserialno` varchar(30) NOT NULL default '',
  `stockcode` varchar(30) NOT NULL default '',
  `descr` varchar(200) NOT NULL default '',
  `moredescr` text,
  `uom` varchar(20) NOT NULL default '',
  `departmentcode` varchar(20) NOT NULL default '',
  `jobcode` varchar(20) NOT NULL default '',
  `stocklocationcode` varchar(20) NOT NULL default '',
  `symptoms` varchar(100) NOT NULL,
  `comewith` varchar(100) NOT NULL,
  `remark1` varchar(100) NOT NULL,
  `remark2` varchar(100) NOT NULL,
  `remark3` varchar(100) NOT NULL,
  `remark4` varchar(100) NOT NULL,
  `fromdoctype` varchar(5) NOT NULL default '',
  `fromdockey` int(11) unsigned default NULL,
  `fromdocid` int(11) unsigned default NULL,
  `fromdoccode` varchar(20) NOT NULL default '',
  `qty` decimal(20,6) default NULL,
  `unitprice` decimal(20,6) default NULL,
  `amount` decimal(20,2) default NULL,
  `serviceitemcode` varchar(20) NOT NULL default '',
  PRIMARY KEY  (`rmaclaimkey`,`pos`),
  UNIQUE KEY `irmacikeyid` (`rmaclaimkey`,`id`),
  KEY `irmacicode` (`rmaclaimcode`),
  KEY `irmacistockcode` (`stockcode`),
  KEY `irmacidepartmentcode` (`departmentcode`),
  KEY `irmacistocklocationcode` (`stocklocationcode`),
  KEY `irmacifromdoctypekeypos` (`fromdoctype`,`fromdockey`,`fromdocid`),
  KEY `irmacijobcode` (`jobcode`),
  KEY `irmaciserviceitemcode` (`serviceitemcode`)
) ENGINE=INNODB DEFAULT CHARSET=latin1;

CREATE TABLE `rmaclaimreturn` (
  `rmaclaimreturnkey` int(11) unsigned NOT NULL auto_increment,
  `rmaclaimreturncode` varchar(20) NOT NULL default '',
  `rmaclaimreturndate` date default NULL,
  `creditorcode` varchar(20) NOT NULL default '',
  `termcode` varchar(20) NOT NULL default '',
  `staffcode` varchar(20) NOT NULL default '',
  `areacode` varchar(20) NOT NULL default '',
  `descr` varchar(200) NOT NULL default '',
  `refno` varchar(20) NOT NULL default '',
  `ourrefno` varchar(20) NOT NULL default '',
  `attention` varchar(200) NOT NULL default '',
  `address1` varchar(200) NOT NULL default '',
  `address2` varchar(200) NOT NULL default '',
  `address3` varchar(200) NOT NULL default '',
  `address4` varchar(200) NOT NULL default '',
  `phone` varchar(30) NOT NULL default '',
  `fax` varchar(30) NOT NULL default '',
  `note` mediumtext,
  `remark1` varchar(100) NOT NULL,
  `remark2` varchar(100) NOT NULL,
  `remark3` varchar(100) NOT NULL,
  `remark4` varchar(100) NOT NULL,
  `remark5` varchar(100) NOT NULL,
  `remark6` varchar(100) NOT NULL,
  `remark7` varchar(100) NOT NULL,
  `remark8` varchar(100) NOT NULL,
  `globaldepartment` enum('Y','N') NOT NULL default 'Y',
  `departmentcode` varchar(20) NOT NULL default '',
  `globaljob` enum('Y','N') NOT NULL default 'N',
  `jobcode` varchar(20) NOT NULL default '',
  `globalstocklocation` enum('Y','N') NOT NULL default 'Y',
  `stocklocationcode` varchar(20) NOT NULL default '',
  `closed` enum('Y','N') NOT NULL default 'N',
  `cancelled` enum('Y','N') NOT NULL default 'N',
  `itemformatkey` int(10) unsigned NOT NULL default '0',
  `created` datetime default NULL,
  `modified` datetime default NULL,
  `done` enum('Y','N') NOT NULL default 'N',
  `curcode` varchar(20) NOT NULL,
  `currate` decimal(20,8) unsigned NOT NULL default '1.00000000',
  `poststockvalue` enum('Y','N') NOT NULL default 'N',
  `stockreceivedkey` int(11) unsigned default '0',
  PRIMARY KEY  (`rmaclaimreturnkey`),
  UNIQUE KEY `irmacrcode` (`rmaclaimreturncode`),
  KEY `irmacrdate` (`rmaclaimreturndate`),
  KEY `irmacrcreditorcode` (`creditorcode`),
  KEY `irmacrtermcode` (`termcode`),
  KEY `irmacrstaffcode` (`staffcode`),
  KEY `irmacrrefno` (`refno`),
  KEY `irmacrdepartmentcode` (`departmentcode`),
  KEY `irmacrstocklocationcode` (`stocklocationcode`),
  KEY `irmacrclosed` (`closed`),
  KEY `irmacrareacode` (`areacode`),
  KEY `irmacrcurcode` (`curcode`),
  KEY `irmacrjobcode` (`jobcode`),
  KEY `irmacrpoststockvalue` (`poststockvalue`)
) ENGINE=INNODB DEFAULT CHARSET=latin1;

CREATE TABLE `rmaclaimreturnid` (
  `rmaclaimreturnkey` int(11) unsigned NOT NULL default '0',
  `id` int(11) unsigned NOT NULL default '0',
  PRIMARY KEY  (`rmaclaimreturnkey`,`id`)
) ENGINE=INNODB DEFAULT CHARSET=latin1;

CREATE TABLE `rmaclaimreturnitem` (
  `rmaclaimreturnkey` int(11) unsigned NOT NULL default '0',
  `rmaclaimreturncode` varchar(20) NOT NULL default '',
  `id` int(11) unsigned NOT NULL default '0',
  `pos` int(11) unsigned NOT NULL default '0',
  `itemno` varchar(10) NOT NULL default '',
  `rmastockserialno` varchar(30) NOT NULL default '',
  `stockserialno` varchar(30) NOT NULL default '',
  `stockcode` varchar(30) NOT NULL default '',
  `descr` varchar(200) NOT NULL default '',
  `moredescr` text,
  `uom` varchar(20) NOT NULL default '',
  `departmentcode` varchar(20) NOT NULL default '',
  `jobcode` varchar(20) NOT NULL default '',
  `stocklocationcode` varchar(20) NOT NULL default '',
  `symptoms` varchar(100) NOT NULL,
  `comewith` varchar(100) NOT NULL,
  `remark1` varchar(100) NOT NULL,
  `remark2` varchar(100) NOT NULL,
  `remark3` varchar(100) NOT NULL,
  `remark4` varchar(100) NOT NULL,
  `fromdoctype` varchar(5) NOT NULL default '',
  `fromdockey` int(11) unsigned default NULL,
  `fromdocid` int(11) unsigned default NULL,
  `fromdoccode` varchar(20) NOT NULL default '',
  `qty` decimal(20,6) default NULL,
  `unitprice` decimal(20,6) default NULL,
  `amount` decimal(20,2) default NULL,
  `serviceitemcode` varchar(20) NOT NULL default '',
  PRIMARY KEY  (`rmaclaimreturnkey`,`pos`),
  UNIQUE KEY `irmacrikeyid` (`rmaclaimreturnkey`,`id`),
  KEY `irmacricode` (`rmaclaimreturncode`),
  KEY `irmacristockcode` (`stockcode`),
  KEY `irmacridepartmentcode` (`departmentcode`),
  KEY `irmacristocklocationcode` (`stocklocationcode`),
  KEY `irmacrifromdoctypekeypos` (`fromdoctype`,`fromdockey`,`fromdocid`),
  KEY `irmacrijobcode` (`jobcode`),
  KEY `irmacriserviceitemcode` (`serviceitemcode`)
) ENGINE=INNODB DEFAULT CHARSET=latin1;

CREATE TABLE `rmadelivery` (
  `rmadeliverykey` int(11) unsigned NOT NULL auto_increment,
  `rmadeliverycode` varchar(20) NOT NULL default '',
  `rmadeliverydate` date default NULL,
  `debtorcode` varchar(20) NOT NULL default '',
  `termcode` varchar(20) NOT NULL default '',
  `staffcode` varchar(20) NOT NULL default '',
  `areacode` varchar(20) NOT NULL default '',
  `descr` varchar(200) NOT NULL default '',
  `refno` varchar(20) NOT NULL default '',
  `ourrefno` varchar(20) NOT NULL default '',
  `attention` varchar(200) NOT NULL default '',
  `address1` varchar(200) NOT NULL default '',
  `address2` varchar(200) NOT NULL default '',
  `address3` varchar(200) NOT NULL default '',
  `address4` varchar(200) NOT NULL default '',
  `phone` varchar(30) NOT NULL default '',
  `fax` varchar(30) NOT NULL default '',
  `note` mediumtext,
  `remark1` varchar(100) NOT NULL,
  `remark2` varchar(100) NOT NULL,
  `remark3` varchar(100) NOT NULL,
  `remark4` varchar(100) NOT NULL,
  `remark5` varchar(100) NOT NULL,
  `remark6` varchar(100) NOT NULL,
  `remark7` varchar(100) NOT NULL,
  `remark8` varchar(100) NOT NULL,
  `globaldepartment` enum('Y','N') NOT NULL default 'Y',
  `departmentcode` varchar(20) NOT NULL default '',
  `globaljob` enum('Y','N') NOT NULL default 'N',
  `jobcode` varchar(20) NOT NULL default '',
  `globalstocklocation` enum('Y','N') NOT NULL default 'Y',
  `stocklocationcode` varchar(20) NOT NULL default '',
  `closed` enum('Y','N') NOT NULL default 'N',
  `cancelled` enum('Y','N') NOT NULL default 'N',
  `itemformatkey` int(10) unsigned NOT NULL default '0',
  `created` datetime default NULL,
  `modified` datetime default NULL,
  `done` enum('Y','N') NOT NULL default 'N',
  `curcode` varchar(20) NOT NULL,
  `currate` decimal(20,8) unsigned NOT NULL default '1.00000000',
  `poststockvalue` enum('Y','N') NOT NULL default 'N',
  `stockissuekey` int(11) unsigned default NULL,
  PRIMARY KEY  (`rmadeliverykey`),
  UNIQUE KEY `irmadcode` (`rmadeliverycode`),
  KEY `irmaddate` (`rmadeliverydate`),
  KEY `irmaddebtorcode` (`debtorcode`),
  KEY `irmadtermcode` (`termcode`),
  KEY `irmadstaffcode` (`staffcode`),
  KEY `irmadrefno` (`refno`),
  KEY `irmaddepartmentcode` (`departmentcode`),
  KEY `irmadstocklocationcode` (`stocklocationcode`),
  KEY `irmadclosed` (`closed`),
  KEY `irmadareacode` (`areacode`),
  KEY `irmadcurcode` (`curcode`),
  KEY `irmadjobcode` (`jobcode`),
  KEY `irmadpoststockvalue` (`poststockvalue`)
) ENGINE=INNODB DEFAULT CHARSET=latin1;

CREATE TABLE `rmadeliveryid` (
  `rmadeliverykey` int(11) unsigned NOT NULL default '0',
  `id` int(11) unsigned NOT NULL default '0',
  PRIMARY KEY  (`rmadeliverykey`,`id`)
) ENGINE=INNODB DEFAULT CHARSET=latin1;

CREATE TABLE `rmadeliveryitem` (
  `rmadeliverykey` int(11) unsigned NOT NULL default '0',
  `rmadeliverycode` varchar(20) NOT NULL default '',
  `id` int(11) unsigned NOT NULL default '0',
  `pos` int(11) unsigned NOT NULL default '0',
  `itemno` varchar(10) NOT NULL default '',
  `rmastockserialno` varchar(30) NOT NULL default '',
  `stockserialno` varchar(30) NOT NULL default '',
  `stockcode` varchar(30) NOT NULL default '',
  `descr` varchar(200) NOT NULL default '',
  `moredescr` text,
  `uom` varchar(20) NOT NULL default '',
  `departmentcode` varchar(20) NOT NULL default '',
  `jobcode` varchar(20) NOT NULL default '',
  `stocklocationcode` varchar(20) NOT NULL default '',
  `symptoms` varchar(100) NOT NULL,
  `comewith` varchar(100) NOT NULL,
  `remark1` varchar(100) NOT NULL,
  `remark2` varchar(100) NOT NULL,
  `remark3` varchar(100) NOT NULL,
  `remark4` varchar(100) NOT NULL,
  `fromdoctype` varchar(5) NOT NULL default '',
  `fromdockey` int(11) unsigned default NULL,
  `fromdocid` int(11) unsigned default NULL,
  `fromdoccode` varchar(20) NOT NULL default '',
  `qty` decimal(20,6) default NULL,
  `unitprice` decimal(20,6) default NULL,
  `amount` decimal(20,2) default NULL,
  `serviceitemcode` varchar(20) NOT NULL default '',
  PRIMARY KEY  (`rmadeliverykey`,`pos`),
  UNIQUE KEY `irmadikeyid` (`rmadeliverykey`,`id`),
  KEY `irmadicode` (`rmadeliverycode`),
  KEY `irmadistockcode` (`stockcode`),
  KEY `irmadidepartmentcode` (`departmentcode`),
  KEY `irmadistocklocationcode` (`stocklocationcode`),
  KEY `irmadifromdoctypekeypos` (`fromdoctype`,`fromdockey`,`fromdocid`),
  KEY `irmadijobcode` (`jobcode`),
  KEY `irmadiserviceitemcode` (`serviceitemcode`)
) ENGINE=INNODB DEFAULT CHARSET=latin1;

CREATE TABLE `rmain` (
  `rmainkey` int(11) unsigned NOT NULL auto_increment,
  `rmaincode` varchar(20) NOT NULL default '',
  `rmaindate` date default NULL,
  `boughtdate` date default NULL,
  `debtorcode` varchar(20) NOT NULL default '',
  `termcode` varchar(20) NOT NULL default '',
  `staffcode` varchar(20) NOT NULL default '',
  `areacode` varchar(20) NOT NULL default '',
  `descr` varchar(200) NOT NULL default '',
  `refno` varchar(20) NOT NULL default '',
  `ourrefno` varchar(20) NOT NULL default '',
  `attention` varchar(200) NOT NULL default '',
  `address1` varchar(200) NOT NULL default '',
  `address2` varchar(200) NOT NULL default '',
  `address3` varchar(200) NOT NULL default '',
  `address4` varchar(200) NOT NULL default '',
  `phone` varchar(30) NOT NULL default '',
  `fax` varchar(30) NOT NULL default '',
  `note` mediumtext,
  `remark1` varchar(100) NOT NULL,
  `remark2` varchar(100) NOT NULL,
  `remark3` varchar(100) NOT NULL,
  `remark4` varchar(100) NOT NULL,
  `remark5` varchar(100) NOT NULL,
  `remark6` varchar(100) NOT NULL,
  `remark7` varchar(100) NOT NULL,
  `remark8` varchar(100) NOT NULL,
  `globaldepartment` enum('Y','N') NOT NULL default 'Y',
  `departmentcode` varchar(20) NOT NULL default '',
  `globaljob` enum('Y','N') NOT NULL default 'N',
  `jobcode` varchar(20) NOT NULL default '',
  `globalstocklocation` enum('Y','N') NOT NULL default 'Y',
  `stocklocationcode` varchar(20) NOT NULL default '',
  `closed` enum('Y','N') NOT NULL default 'N',
  `itemformatkey` int(10) unsigned NOT NULL default '0',
  `created` datetime default NULL,
  `modified` datetime default NULL,
  `done` enum('Y','N') NOT NULL default 'N',
  `curcode` varchar(20) NOT NULL,
  `currate` decimal(20,8) unsigned NOT NULL default '1.00000000',
  PRIMARY KEY  (`rmainkey`),
  UNIQUE KEY `irmaincode` (`rmaincode`),
  KEY `irmaindate` (`rmaindate`),
  KEY `irmaindebtorcode` (`debtorcode`),
  KEY `irmaintermcode` (`termcode`),
  KEY `irmainstaffcode` (`staffcode`),
  KEY `irmainrefno` (`refno`),
  KEY `irmaindepartmentcode` (`departmentcode`),
  KEY `irmainstocklocationcode` (`stocklocationcode`),
  KEY `irmainclosed` (`closed`),
  KEY `irmainareacode` (`areacode`),
  KEY `irmaincurcode` (`curcode`),
  KEY `irmainjobcode` (`jobcode`)
) ENGINE=INNODB DEFAULT CHARSET=latin1;

CREATE TABLE `rmainid` (
  `rmainkey` int(11) unsigned NOT NULL default '0',
  `id` int(11) unsigned NOT NULL default '0',
  PRIMARY KEY  (`rmainkey`,`id`)
) ENGINE=INNODB DEFAULT CHARSET=latin1;

CREATE TABLE `rmainitem` (
  `rmainkey` int(11) unsigned NOT NULL default '0',
  `rmaincode` varchar(20) NOT NULL default '',
  `id` int(11) unsigned NOT NULL default '0',
  `pos` int(11) unsigned NOT NULL default '0',
  `itemno` varchar(10) NOT NULL default '',
  `stockserialno` varchar(30) NOT NULL default '',
  `stockcode` varchar(30) NOT NULL default '',
  `descr` varchar(200) NOT NULL default '',
  `moredescr` text,
  `uom` varchar(20) NOT NULL default '',
  `underwarranty` enum('Y','N') NOT NULL default 'Y',
  `departmentcode` varchar(20) NOT NULL default '',
  `jobcode` varchar(20) NOT NULL default '',
  `stocklocationcode` varchar(20) NOT NULL default '',
  `symptoms` varchar(100) NOT NULL,
  `comewith` varchar(100) NOT NULL,
  `remark1` varchar(100) NOT NULL,
  `remark2` varchar(100) NOT NULL,
  `remark3` varchar(100) NOT NULL,
  `remark4` varchar(100) NOT NULL,
  `qty` decimal(20,6) default NULL,
  `unitprice` decimal(20,6) default NULL,
  `amount` decimal(20,2) default NULL,
  `serviceitemcode` varchar(20) NOT NULL default '',
  PRIMARY KEY  (`rmainkey`,`pos`),
  UNIQUE KEY `irmainikeyid` (`rmainkey`,`id`),
  KEY `irmainicode` (`rmaincode`),
  KEY `irmainistockcode` (`stockcode`),
  KEY `irmainidepartmentcode` (`departmentcode`),
  KEY `irmainistocklocationcode` (`stocklocationcode`),
  KEY `irmainijobcode` (`jobcode`),
  KEY `irmainiserviceitemcode` (`serviceitemcode`)
) ENGINE=INNODB DEFAULT CHARSET=latin1;

CREATE TABLE `salescn` (
  `salescnkey` int(11) unsigned NOT NULL auto_increment,
  `salescncode` varchar(20) NOT NULL default '',
  `salescndate` date default NULL,
  `debtorcode` varchar(20) NOT NULL default '',
  `staffcode` varchar(20) NOT NULL default '',
  `areacode` varchar(20) NOT NULL default '',
  `descr` varchar(200) NOT NULL default '',
  `validity` varchar(100) NOT NULL default '',
  `deliveryterm` varchar(100) NOT NULL default '',
  `refno` varchar(20) NOT NULL default '',
  `address1` varchar(200) NOT NULL default '',
  `address2` varchar(200) NOT NULL default '',
  `address3` varchar(200) NOT NULL default '',
  `address4` varchar(200) NOT NULL default '',
  `city` varchar(50) NOT NULL default '',
  `postalcode` varchar(10) NOT NULL default '',
  `state` varchar(50) NOT NULL default '',
  `countrycode` varchar(50) NOT NULL default '',
  `attention` varchar(200) NOT NULL default '',
  `phone` varchar(30) NOT NULL default '',
  `fax` varchar(30) NOT NULL default '',
  `discountamount` decimal(20,2) NOT NULL,
  `amountbeforediscount` decimal(20,2) NOT NULL,
  `amount` decimal(20,2) NOT NULL default '0.00',
  `taxamount` decimal(20,2) NOT NULL default '0.00',
  `amountaftertax` decimal(20,2) NOT NULL default '0.00',
  `note` mediumtext,
  `remark1` varchar(100) NOT NULL,
  `remark2` varchar(100) NOT NULL,
  `remark3` varchar(100) NOT NULL,
  `remark4` varchar(100) NOT NULL,
  `remark5` varchar(100) NOT NULL,
  `remark6` varchar(100) NOT NULL,
  `remark7` varchar(100) NOT NULL,
  `remark8` varchar(100) NOT NULL,
  `globaldiscountacccode` varchar(20) NOT NULL default '',
  `globalsalesacccode` varchar(20) NOT NULL default '',
  `globaltaxacccode` varchar(20) NOT NULL default '',
  `globaldepartment` enum('Y','N') NOT NULL default 'Y',
  `departmentcode` varchar(20) NOT NULL default '',
  `globaljob` enum('Y','N') NOT NULL default 'N',
  `jobcode` varchar(20) NOT NULL default '',
  `globalstocklocation` enum('Y','N') NOT NULL default 'Y',
  `stocklocationcode` varchar(20) NOT NULL default '',
  `cancelled` enum('Y','N') NOT NULL default 'N',
  `itemformatkey` int(11) unsigned NOT NULL default '0',
  `debtorcnkey` int(11) unsigned NOT NULL default '0',
  `created` datetime default NULL,
  `modified` datetime default NULL,
  `done` enum('Y','N') NOT NULL default 'N',
  `ispos` enum('Y','N') NOT NULL default 'N',
  `countercode` varchar(20) NOT NULL default '',
  `cashiercode` varchar(20) NOT NULL default '',
  `supervisorcode` varchar(20) NOT NULL default '',
  `clientcreated` datetime default NULL,
  `branchcode` varchar(20) NOT NULL default '',
  `branchname` varchar(200) NOT NULL default '',
  `docontactperson` varchar(200) NOT NULL default '',
  `dophone` varchar(30) NOT NULL default '',
  `dofax` varchar(30) NOT NULL default '',
  `doemail` varchar(200) NOT NULL default '',
  `doaddress1` varchar(200) NOT NULL default '',
  `doaddress2` varchar(200) NOT NULL default '',
  `doaddress3` varchar(200) NOT NULL default '',
  `doaddress4` varchar(200) NOT NULL default '',
  `docity` varchar(50) NOT NULL default '',
  `dopostalcode` varchar(10) NOT NULL default '',
  `dostate` varchar(50) NOT NULL default '',
  `docountrycode` varchar(50) NOT NULL default '',
  `roundingadjacccode` varchar(20) NOT NULL default '',
  `cardchargeacccode` varchar(20) NOT NULL default '',
  `curcode` varchar(20) NOT NULL,
  `currate` decimal(20,8) unsigned NOT NULL default '1.00000000',
  `localdiscountamount` decimal(20,2) NOT NULL,
  `localamountbeforediscount` decimal(20,2) NOT NULL,
  `localamount` decimal(20,2) NOT NULL default '0.00',
  `localtaxamount` decimal(20,2) NOT NULL default '0.00',
  `localamountaftertax` decimal(20,2) NOT NULL default '0.00',
  `membercode` varchar(50) NOT NULL,
  `promotercode` varchar(20) NOT NULL,
  `ref1` varchar(30) NOT NULL,
  `ref2` varchar(30) NOT NULL,
  `ref3` varchar(30) NOT NULL,
  `ref4` varchar(30) NOT NULL,
  `postaccountvalue` enum('Y','N') NOT NULL default 'Y',
  `poststockvalue` enum('Y','N') NOT NULL default 'Y',
  `postingdate` date default NULL,
  `lastmodified` timestamp NOT NULL default CURRENT_TIMESTAMP on update CURRENT_TIMESTAMP,
  `accsalesamount` decimal(20,2) NOT NULL default '0.00',
  `accdiscountamount` decimal(20,2) NOT NULL default '0.00',
  `acctaxamount` decimal(20,2) NOT NULL default '0.00',
  `accotheramount` decimal(20,2) NOT NULL default '0.00',
  `salesleadkey` int(10) unsigned NOT NULL default '0',
  `debtorname` varchar(200) NOT NULL default '',
  `servicechargeacccode` varchar(20) NOT NULL default '',
  `fromoldversion` enum('Y','N') NOT NULL default 'N',
  PRIMARY KEY  (`salescnkey`),
  UNIQUE KEY `isdncode` (`salescncode`),
  KEY `iscndate` (`salescndate`),
  KEY `iscndebtorcode` (`debtorcode`),
  KEY `iscnstaffcode` (`staffcode`),
  KEY `iscnrefno` (`refno`),
  KEY `iscnglobalsalesacccode` (`globalsalesacccode`),
  KEY `iscnglobaltaxacccode` (`globaltaxacccode`),
  KEY `iscndepartmentcode` (`departmentcode`),
  KEY `iscnstocklocationcode` (`stocklocationcode`),
  KEY `iscncancelled` (`cancelled`),
  KEY `iscnareacode` (`areacode`),
  KEY `iscnispos` (`ispos`),
  KEY `iscncountercode` (`countercode`),
  KEY `iscncashiercode` (`cashiercode`),
  KEY `iscnsupervisorcode` (`supervisorcode`),
  KEY `iscncurcode` (`curcode`),
  KEY `iscnglobaldiscountacccode` (`globaldiscountacccode`),
  KEY `iscnmembercode` (`membercode`),
  KEY `iscnpromotercode` (`promotercode`),
  KEY `iscnpostaccountvalue` (`postaccountvalue`),
  KEY `iscnpoststockvalue` (`poststockvalue`),
  KEY `iscnpostingdate` (`postingdate`),
  KEY `iscnjobcode` (`jobcode`),
  KEY `iscnsalesleadkey` (`salesleadkey`),
  KEY `iscnroundingadjacccode` (`roundingadjacccode`),
  KEY `iscncardchargeacccode` (`cardchargeacccode`),
  KEY `iscncountrycode` (`countrycode`),
  KEY `iscndocountrycode` (`docountrycode`),
  KEY `iscnservicechargeacccode` (`servicechargeacccode`)
) ENGINE=INNODB DEFAULT CHARSET=latin1;

CREATE TABLE `salescnid` (
  `salescnkey` int(11) unsigned NOT NULL default '0',
  `id` int(11) unsigned NOT NULL default '0',
  PRIMARY KEY  (`salescnkey`,`id`)
) ENGINE=INNODB DEFAULT CHARSET=latin1;

CREATE TABLE `salescnitem` (
  `salescnkey` int(11) unsigned NOT NULL default '0',
  `salescncode` varchar(20) NOT NULL default '',
  `id` int(11) unsigned NOT NULL default '0',
  `pos` int(11) unsigned NOT NULL default '0',
  `itemno` varchar(10) NOT NULL default '',
  `stockcode` varchar(30) NOT NULL default '',
  `descr` varchar(200) NOT NULL default '',
  `moredescr` text,
  `qty` decimal(20,6) default NULL,
  `unitprice` decimal(20,6) default NULL,
  `uom` varchar(20) NOT NULL default '',
  `uomrate` double NOT NULL default '1',
  `qtybaseuom` decimal(20,6) NOT NULL default '0.000000',
  `unitpricebaseuom` double NOT NULL default '0',
  `discountformat` varchar(100) default NULL,
  `discountamount` decimal(20,2) default NULL,
  `amountbeforediscount` decimal(20,2) default NULL,
  `amount` decimal(20,2) default NULL,
  `gsttypecode` varchar(20) NOT NULL default '',
  `stockpackagegsttypecode` varchar(20) NOT NULL default '',
  `salestaxpercentage` decimal(20,2) default NULL,
  `salestaxamount` decimal(20,2) default NULL,
  `amountaftertax` decimal(20,2) default NULL,
  `acccode` varchar(20) NOT NULL default '',
  `departmentcode` varchar(20) NOT NULL default '',
  `jobcode` varchar(20) NOT NULL default '',
  `stocklocationcode` varchar(20) NOT NULL default '',
  `fromdoctype` varchar(5) NOT NULL default '',
  `fromdockey` int(11) unsigned default NULL,
  `fromdocid` int(11) unsigned default NULL,
  `fromdoccode` varchar(20) NOT NULL default '',
  `debtoritemcode` varchar(30) NOT NULL default '',
  `barcode` varchar(30) NOT NULL default '',
  `remark1` varchar(100) NOT NULL,
  `remark2` varchar(100) NOT NULL,
  `remark3` varchar(100) NOT NULL,
  `remark4` varchar(100) NOT NULL,
  `rowtype` enum('','TOTALUP','ITEMDISCOUNT','ITEMSERVICETAX','ITEMMISCCHARGES','FOOTERDISCOUNT','FOOTERSERVICETAX','FOOTERMISCCHARGES') NOT NULL,
  `foc` enum('Y','N') NOT NULL default 'N',
  `packingqty` decimal(20,6) default NULL,
  `packinguom` varchar(20) NOT NULL default '',
  `packingrate` decimal(20,6) default NULL,
  `stockpackagecode` varchar(20) NOT NULL,
  `stockpackageid` int(11) unsigned NOT NULL default '0',
  `stockpackagerate` double default NULL,
  `stockpackageqty` decimal(20,6) default NULL,
  `stockpackageunitprice` decimal(20,6) default NULL,
  `stockpackageamount` decimal(20,2) default NULL,
  `stockpackagesalestaxpercentage` decimal(20,2) default NULL,
  `stockpackagesalestaxamount` decimal(20,2) default NULL,
  `stockpackageamountaftertax` decimal(20,2) default NULL,
  `serialno` text,
  `batchno` varchar(30) NOT NULL default '',
  `curcode` varchar(20) NOT NULL default '',
  `curprice` decimal(20,6) default NULL,
  `currate` decimal(20,8) unsigned default NULL,
  `recommendpricebaseuom` decimal(20,6) unsigned NOT NULL default '0.000000',
  `weightrate` decimal(20,6) unsigned NOT NULL default '0.000000',
  `weightuom` varchar(20) NOT NULL default '',
  `weightqty` decimal(20,6) unsigned NOT NULL default '0.000000',
  `weightloosed` decimal(20,6) unsigned NOT NULL default '0.000000',
  `totalweight` decimal(20,6) unsigned NOT NULL default '0.000000',
  `volumerate` decimal(20,6) unsigned NOT NULL default '0.000000',
  `volumeuom` varchar(20) NOT NULL default '',
  `volumeqty` decimal(20,6) unsigned NOT NULL default '0.000000',
  `volumeloosed` decimal(20,6) unsigned NOT NULL default '0.000000',
  `totalvolume` decimal(20,6) unsigned NOT NULL default '0.000000',
  `supplypurchase` enum('None','Supply','Purchase') NOT NULL default 'None',
  `taxsubtract` enum('Y','N') NOT NULL default 'N',
  `taxableamount` decimal(20,2) NOT NULL default '0.00',
  `taxablelocalamount` decimal(20,2) NOT NULL default '0.00',
  `amountaftertaxsubtract` decimal(20,2) NOT NULL default '0.00',
  `localamountaftertaxsubtract` decimal(20,2) NOT NULL default '0.00',
  `salestaxlocalamount` decimal(20,2) NOT NULL default '0.00',
  `taxadjustment` decimal(20,2) NOT NULL default '0.00',
  `taxlocaladjustment` decimal(20,2) NOT NULL default '0.00',
  `taxtotalamount` decimal(20,2) NOT NULL default '0.00',
  `taxtotallocalamount` decimal(20,2) NOT NULL default '0.00',
  `ourinvcode` varchar(20) NOT NULL default '',
  `ourinvdate` date default NULL,
  `taxpermitno` varchar(50) NOT NULL default '',
  `taxacccode` varchar(20) NOT NULL default '',
  `taxexportcountrycode` varchar(50) NOT NULL default '',
  `yourpocode` varchar(20) NOT NULL default '',
  `yourpodate` date default NULL,
  `reason` varchar(200) NOT NULL default '',
  `stockpackagesupplypurchase` enum('None','Supply','Purchase') NOT NULL default 'None',
  `stockpackagetaxsubtract` enum('Y','N') NOT NULL default 'N',
  `stockpackagetaxableamount` decimal(20,2) NOT NULL default '0.00',
  `stockpackagetaxablelocalamount` decimal(20,2) NOT NULL default '0.00',
  `stockpackageamountaftertaxsubtract` decimal(20,2) NOT NULL default '0.00',
  `stockpackagelocalamountaftertaxsubtract` decimal(20,2) NOT NULL default '0.00',
  `stockpackagesalestaxlocalamount` decimal(20,2) NOT NULL default '0.00',
  `stockpackagetaxadjustment` decimal(20,2) NOT NULL default '0.00',
  `stockpackagetaxlocaladjustment` decimal(20,2) NOT NULL default '0.00',
  `stockpackagetaxtotalamount` decimal(20,2) NOT NULL default '0.00',
  `stockpackagetaxtotallocalamount` decimal(20,2) NOT NULL default '0.00',
  PRIMARY KEY  (`salescnkey`,`pos`),
  UNIQUE KEY `isdnikeyid` (`salescnkey`,`id`),
  KEY `iscnicode` (`salescncode`),
  KEY `iscnistockcode` (`stockcode`),
  KEY `iscniacccode` (`acccode`),
  KEY `iscnidepartmentcode` (`departmentcode`),
  KEY `iscnistocklocationcode` (`stocklocationcode`),
  KEY `iscnibarcode` (`barcode`),
  KEY `iscnifoc` (`foc`),
  KEY `iscnistockpackagecode` (`stockpackagecode`),
  KEY `iscnistockpackageid` (`stockpackageid`),
  KEY `iscnibatchno` (`batchno`),
  KEY `iscnijobcode` (`jobcode`),
  KEY `iscnigsttypecode` (`gsttypecode`),
  KEY `iscnistockpackagegsttypecode` (`stockpackagegsttypecode`),
  KEY `iscnifromdoctypekeypos` (`fromdoctype`,`fromdockey`,`fromdocid`),
  KEY `iscnitaxacccode` (`taxacccode`),
  KEY `iscnitaxexportcountrycode` (`taxexportcountrycode`)
) ENGINE=INNODB DEFAULT CHARSET=latin1;

CREATE TABLE `salesdn` (
  `salesdnkey` int(11) unsigned NOT NULL auto_increment,
  `salesdncode` varchar(20) NOT NULL default '',
  `salesdndate` date default NULL,
  `debtorcode` varchar(20) NOT NULL default '',
  `termcode` varchar(20) NOT NULL default '',
  `staffcode` varchar(20) NOT NULL default '',
  `areacode` varchar(20) NOT NULL default '',
  `descr` varchar(200) NOT NULL default '',
  `validity` varchar(100) NOT NULL default '',
  `deliveryterm` varchar(100) NOT NULL default '',
  `refno` varchar(20) NOT NULL default '',
  `address1` varchar(200) NOT NULL default '',
  `address2` varchar(200) NOT NULL default '',
  `address3` varchar(200) NOT NULL default '',
  `address4` varchar(200) NOT NULL default '',
  `city` varchar(50) NOT NULL default '',
  `postalcode` varchar(10) NOT NULL default '',
  `state` varchar(50) NOT NULL default '',
  `countrycode` varchar(50) NOT NULL default '',
  `attention` varchar(200) NOT NULL default '',
  `phone` varchar(30) NOT NULL default '',
  `fax` varchar(30) NOT NULL default '',
  `discountamount` decimal(20,2) NOT NULL,
  `amountbeforediscount` decimal(20,2) NOT NULL,
  `amount` decimal(20,2) NOT NULL default '0.00',
  `taxamount` decimal(20,2) NOT NULL default '0.00',
  `amountaftertax` decimal(20,2) NOT NULL default '0.00',
  `note` mediumtext,
  `remark1` varchar(100) NOT NULL,
  `remark2` varchar(100) NOT NULL,
  `remark3` varchar(100) NOT NULL,
  `remark4` varchar(100) NOT NULL,
  `remark5` varchar(100) NOT NULL,
  `remark6` varchar(100) NOT NULL,
  `remark7` varchar(100) NOT NULL,
  `remark8` varchar(100) NOT NULL,
  `globaldiscountacccode` varchar(20) NOT NULL default '',
  `globalsalesacccode` varchar(20) NOT NULL default '',
  `globaltaxacccode` varchar(20) NOT NULL default '',
  `globaldepartment` enum('Y','N') NOT NULL default 'Y',
  `departmentcode` varchar(20) NOT NULL default '',
  `globaljob` enum('Y','N') NOT NULL default 'N',
  `jobcode` varchar(20) NOT NULL default '',
  `globalstocklocation` enum('Y','N') NOT NULL default 'Y',
  `stocklocationcode` varchar(20) NOT NULL default '',
  `cancelled` enum('Y','N') NOT NULL default 'N',
  `itemformatkey` int(11) unsigned NOT NULL default '0',
  `debtordnkey` int(11) unsigned NOT NULL default '0',
  `created` datetime default NULL,
  `modified` datetime default NULL,
  `done` enum('Y','N') NOT NULL default 'N',
  `branchcode` varchar(20) NOT NULL default '',
  `branchname` varchar(200) NOT NULL default '',
  `docontactperson` varchar(200) NOT NULL default '',
  `dophone` varchar(30) NOT NULL default '',
  `dofax` varchar(30) NOT NULL default '',
  `doemail` varchar(200) NOT NULL default '',
  `doaddress1` varchar(200) NOT NULL default '',
  `doaddress2` varchar(200) NOT NULL default '',
  `doaddress3` varchar(200) NOT NULL default '',
  `doaddress4` varchar(200) NOT NULL default '',
  `docity` varchar(50) NOT NULL default '',
  `dopostalcode` varchar(10) NOT NULL default '',
  `dostate` varchar(50) NOT NULL default '',
  `docountrycode` varchar(50) NOT NULL default '',
  `roundingadjacccode` varchar(20) NOT NULL default '',
  `cardchargeacccode` varchar(20) NOT NULL default '',
  `curcode` varchar(20) NOT NULL,
  `currate` decimal(20,8) unsigned NOT NULL default '1.00000000',
  `localdiscountamount` decimal(20,2) NOT NULL,
  `localamountbeforediscount` decimal(20,2) NOT NULL,
  `localamount` decimal(20,2) NOT NULL default '0.00',
  `localtaxamount` decimal(20,2) NOT NULL default '0.00',
  `localamountaftertax` decimal(20,2) NOT NULL default '0.00',
  `ref1` varchar(30) NOT NULL,
  `ref2` varchar(30) NOT NULL,
  `ref3` varchar(30) NOT NULL,
  `ref4` varchar(30) NOT NULL,
  `postaccountvalue` enum('Y','N') NOT NULL default 'Y',
  `poststockvalue` enum('Y','N') NOT NULL default 'Y',
  `postingdate` date default NULL,
  `lastmodified` timestamp NOT NULL default CURRENT_TIMESTAMP on update CURRENT_TIMESTAMP,
  `accsalesamount` decimal(20,2) NOT NULL default '0.00',
  `accdiscountamount` decimal(20,2) NOT NULL default '0.00',
  `acctaxamount` decimal(20,2) NOT NULL default '0.00',
  `accotheramount` decimal(20,2) NOT NULL default '0.00',
  `salesleadkey` int(10) unsigned NOT NULL default '0',
  `debtorname` varchar(200) NOT NULL default '',
  `servicechargeacccode` varchar(20) NOT NULL default '',
  `fromoldversion` enum('Y','N') NOT NULL default 'N',
  PRIMARY KEY  (`salesdnkey`),
  UNIQUE KEY `isdncode` (`salesdncode`),
  KEY `isdndate` (`salesdndate`),
  KEY `isdndebtorcode` (`debtorcode`),
  KEY `isdntermcode` (`termcode`),
  KEY `isdnstaffcode` (`staffcode`),
  KEY `isdnrefno` (`refno`),
  KEY `isdnglobalsalesacccode` (`globalsalesacccode`),
  KEY `isdnglobaltaxacccode` (`globaltaxacccode`),
  KEY `isdndepartmentcode` (`departmentcode`),
  KEY `isdnstocklocationcode` (`stocklocationcode`),
  KEY `isdncancelled` (`cancelled`),
  KEY `isdnareacode` (`areacode`),
  KEY `isdncurcode` (`curcode`),
  KEY `isdnglobaldiscountacccode` (`globaldiscountacccode`),
  KEY `isdnpostaccountvalue` (`postaccountvalue`),
  KEY `isdnpoststockvalue` (`poststockvalue`),
  KEY `isdnpostingdate` (`postingdate`),
  KEY `isdnjobcode` (`jobcode`),
  KEY `isdnsalesleadkey` (`salesleadkey`),
  KEY `isdnroundingadjacccode` (`roundingadjacccode`),
  KEY `isdncardchargeacccode` (`cardchargeacccode`),
  KEY `isdncountrycode` (`countrycode`),
  KEY `isdndocountrycode` (`docountrycode`),
  KEY `isdnservicechargeacccode` (`servicechargeacccode`)
) ENGINE=INNODB DEFAULT CHARSET=latin1;

CREATE TABLE `salesdnid` (
  `salesdnkey` int(11) unsigned NOT NULL default '0',
  `id` int(11) unsigned NOT NULL default '0',
  PRIMARY KEY  (`salesdnkey`,`id`)
) ENGINE=INNODB DEFAULT CHARSET=latin1;

CREATE TABLE `salesdnitem` (
  `salesdnkey` int(11) unsigned NOT NULL default '0',
  `salesdncode` varchar(20) NOT NULL default '',
  `id` int(11) unsigned NOT NULL default '0',
  `pos` int(11) unsigned NOT NULL default '0',
  `itemno` varchar(10) NOT NULL default '',
  `stockcode` varchar(30) NOT NULL default '',
  `descr` varchar(200) NOT NULL default '',
  `moredescr` text,
  `qty` decimal(20,6) default NULL,
  `unitprice` decimal(20,6) default NULL,
  `uom` varchar(20) NOT NULL default '',
  `uomrate` double NOT NULL default '1',
  `qtybaseuom` decimal(20,6) NOT NULL default '0.000000',
  `unitpricebaseuom` double NOT NULL default '0',
  `discountformat` varchar(100) default NULL,
  `discountamount` decimal(20,2) default NULL,
  `amountbeforediscount` decimal(20,2) default NULL,
  `amount` decimal(20,2) default NULL,
  `gsttypecode` varchar(20) NOT NULL default '',
  `stockpackagegsttypecode` varchar(20) NOT NULL default '',
  `salestaxpercentage` decimal(20,2) default NULL,
  `salestaxamount` decimal(20,2) default NULL,
  `amountaftertax` decimal(20,2) default NULL,
  `acccode` varchar(20) NOT NULL default '',
  `departmentcode` varchar(20) NOT NULL default '',
  `jobcode` varchar(20) NOT NULL default '',
  `stocklocationcode` varchar(20) NOT NULL default '',
  `debtoritemcode` varchar(30) NOT NULL default '',
  `barcode` varchar(30) NOT NULL default '',
  `remark1` varchar(100) NOT NULL,
  `remark2` varchar(100) NOT NULL,
  `remark3` varchar(100) NOT NULL,
  `remark4` varchar(100) NOT NULL,
  `rowtype` enum('','TOTALUP','ITEMDISCOUNT','ITEMSERVICETAX','ITEMMISCCHARGES','FOOTERDISCOUNT','FOOTERSERVICETAX','FOOTERMISCCHARGES') NOT NULL,
  `foc` enum('Y','N') NOT NULL default 'N',
  `packingqty` decimal(20,6) default NULL,
  `packinguom` varchar(20) NOT NULL default '',
  `packingrate` decimal(20,6) default NULL,
  `stockpackagecode` varchar(20) NOT NULL,
  `stockpackageid` int(11) unsigned NOT NULL default '0',
  `stockpackagerate` double default NULL,
  `stockpackageqty` decimal(20,6) default NULL,
  `stockpackageunitprice` decimal(20,6) default NULL,
  `stockpackageamount` decimal(20,2) default NULL,
  `stockpackagesalestaxpercentage` decimal(20,2) default NULL,
  `stockpackagesalestaxamount` decimal(20,2) default NULL,
  `stockpackageamountaftertax` decimal(20,2) default NULL,
  `serialno` text,
  `batchno` varchar(30) NOT NULL default '',
  `curcode` varchar(20) NOT NULL default '',
  `curprice` decimal(20,6) default NULL,
  `currate` decimal(20,8) unsigned default NULL,
  `recommendpricebaseuom` decimal(20,6) unsigned NOT NULL default '0.000000',
  `weightrate` decimal(20,6) unsigned NOT NULL default '0.000000',
  `weightuom` varchar(20) NOT NULL default '',
  `weightqty` decimal(20,6) unsigned NOT NULL default '0.000000',
  `weightloosed` decimal(20,6) unsigned NOT NULL default '0.000000',
  `totalweight` decimal(20,6) unsigned NOT NULL default '0.000000',
  `volumerate` decimal(20,6) unsigned NOT NULL default '0.000000',
  `volumeuom` varchar(20) NOT NULL default '',
  `volumeqty` decimal(20,6) unsigned NOT NULL default '0.000000',
  `volumeloosed` decimal(20,6) unsigned NOT NULL default '0.000000',
  `totalvolume` decimal(20,6) unsigned NOT NULL default '0.000000',
  `supplypurchase` enum('None','Supply','Purchase') NOT NULL default 'None',
  `taxsubtract` enum('Y','N') NOT NULL default 'N',
  `taxableamount` decimal(20,2) NOT NULL default '0.00',
  `taxablelocalamount` decimal(20,2) NOT NULL default '0.00',
  `amountaftertaxsubtract` decimal(20,2) NOT NULL default '0.00',
  `localamountaftertaxsubtract` decimal(20,2) NOT NULL default '0.00',
  `salestaxlocalamount` decimal(20,2) NOT NULL default '0.00',
  `taxadjustment` decimal(20,2) NOT NULL default '0.00',
  `taxlocaladjustment` decimal(20,2) NOT NULL default '0.00',
  `taxtotalamount` decimal(20,2) NOT NULL default '0.00',
  `taxtotallocalamount` decimal(20,2) NOT NULL default '0.00',
  `ourinvcode` varchar(20) NOT NULL default '',
  `ourinvdate` date default NULL,
  `taxpermitno` varchar(50) NOT NULL default '',
  `taxacccode` varchar(20) NOT NULL default '',
  `taxexportcountrycode` varchar(50) NOT NULL default '',
  `yourpocode` varchar(20) NOT NULL default '',
  `yourpodate` date default NULL,
  `reason` varchar(200) NOT NULL default '',
  `stockpackagesupplypurchase` enum('None','Supply','Purchase') NOT NULL default 'None',
  `stockpackagetaxsubtract` enum('Y','N') NOT NULL default 'N',
  `stockpackagetaxableamount` decimal(20,2) NOT NULL default '0.00',
  `stockpackagetaxablelocalamount` decimal(20,2) NOT NULL default '0.00',
  `stockpackageamountaftertaxsubtract` decimal(20,2) NOT NULL default '0.00',
  `stockpackagelocalamountaftertaxsubtract` decimal(20,2) NOT NULL default '0.00',
  `stockpackagesalestaxlocalamount` decimal(20,2) NOT NULL default '0.00',
  `stockpackagetaxadjustment` decimal(20,2) NOT NULL default '0.00',
  `stockpackagetaxlocaladjustment` decimal(20,2) NOT NULL default '0.00',
  `stockpackagetaxtotalamount` decimal(20,2) NOT NULL default '0.00',
  `stockpackagetaxtotallocalamount` decimal(20,2) NOT NULL default '0.00',
  PRIMARY KEY  (`salesdnkey`,`pos`),
  UNIQUE KEY `isdnikeyid` (`salesdnkey`,`id`),
  KEY `isdnicode` (`salesdncode`),
  KEY `isdnistockcode` (`stockcode`),
  KEY `isdniacccode` (`acccode`),
  KEY `isdnidepartmentcode` (`departmentcode`),
  KEY `isdnistocklocationcode` (`stocklocationcode`),
  KEY `isdnibarcode` (`barcode`),
  KEY `isdnifoc` (`foc`),
  KEY `isdnistockpackagecode` (`stockpackagecode`),
  KEY `isdnistockpackageid` (`stockpackageid`),
  KEY `isdnibatchno` (`batchno`),
  KEY `isdnijobcode` (`jobcode`),
  KEY `isdnigsttypecode` (`gsttypecode`),
  KEY `isdnistockpackagegsttypecode` (`stockpackagegsttypecode`),
  KEY `isdnitaxacccode` (`taxacccode`),
  KEY `isdnitaxexportcountrycode` (`taxexportcountrycode`)
) ENGINE=INNODB DEFAULT CHARSET=latin1;

CREATE TABLE `salesinvoice` (
  `salesinvoicekey` int(11) unsigned NOT NULL auto_increment,
  `salesinvoicecode` varchar(20) NOT NULL default '',
  `salesinvoicedate` date default NULL,
  `debtorcode` varchar(20) NOT NULL default '',
  `termcode` varchar(20) NOT NULL default '',
  `staffcode` varchar(20) NOT NULL default '',
  `areacode` varchar(20) NOT NULL default '',
  `descr` varchar(200) NOT NULL default '',
  `validity` varchar(100) NOT NULL default '',
  `deliveryterm` varchar(100) NOT NULL default '',
  `refno` varchar(20) NOT NULL default '',
  `address1` varchar(200) NOT NULL default '',
  `address2` varchar(200) NOT NULL default '',
  `address3` varchar(200) NOT NULL default '',
  `address4` varchar(200) NOT NULL default '',
  `city` varchar(50) NOT NULL default '',
  `postalcode` varchar(10) NOT NULL default '',
  `state` varchar(50) NOT NULL default '',
  `countrycode` varchar(50) NOT NULL default '',
  `attention` varchar(200) NOT NULL default '',
  `phone` varchar(30) NOT NULL default '',
  `fax` varchar(30) NOT NULL default '',
  `discountamount` decimal(20,2) NOT NULL,
  `amountbeforediscount` decimal(20,2) NOT NULL,
  `amount` decimal(20,2) NOT NULL default '0.00',
  `taxamount` decimal(20,2) NOT NULL default '0.00',
  `amountaftertax` decimal(20,2) NOT NULL default '0.00',
  `totaldepositamount` decimal(20,2) NOT NULL default '0.00',
  `note` mediumtext,
  `remark1` varchar(100) NOT NULL,
  `remark2` varchar(100) NOT NULL,
  `remark3` varchar(100) NOT NULL,
  `remark4` varchar(100) NOT NULL,
  `remark5` varchar(100) NOT NULL,
  `remark6` varchar(100) NOT NULL,
  `remark7` varchar(100) NOT NULL,
  `remark8` varchar(100) NOT NULL,
  `globaldiscountacccode` varchar(20) NOT NULL default '',
  `globalsalesacccode` varchar(20) NOT NULL default '',
  `globaltaxacccode` varchar(20) NOT NULL default '',
  `globaldepartment` enum('Y','N') NOT NULL default 'Y',
  `departmentcode` varchar(20) NOT NULL default '',
  `globaljob` enum('Y','N') NOT NULL default 'N',
  `jobcode` varchar(20) NOT NULL default '',
  `globalstocklocation` enum('Y','N') NOT NULL default 'Y',
  `stocklocationcode` varchar(20) NOT NULL default '',
  `cancelled` enum('Y','N') NOT NULL default 'N',
  `itemformatkey` int(11) unsigned NOT NULL default '0',
  `invoicekey` int(11) unsigned NOT NULL default '0',
  `created` datetime default NULL,
  `modified` datetime default NULL,
  `done` enum('Y','N') NOT NULL default 'N',
  `ispos` enum('Y','N') NOT NULL default 'N',
  `countercode` varchar(20) NOT NULL default '',
  `cashiercode` varchar(20) NOT NULL default '',
  `promotercode` varchar(20) NOT NULL default '',
  `cashreceive` decimal(20,2) NOT NULL default '0.00',
  `creditcard1amount` decimal(20,2) NOT NULL default '0.00',
  `creditcard2amount` decimal(20,2) NOT NULL default '0.00',
  `creditcardtype1` varchar(20) NOT NULL default '',
  `creditcardno1` varchar(50) NOT NULL default '',
  `creditcardnameoncard1` varchar(200) NOT NULL default '',
  `creditcardexpireddate1` varchar(10) NOT NULL default '',
  `creditcardapprovalcode1` varchar(50) NOT NULL default '',
  `creditcardbankname1` varchar(100) NOT NULL,
  `creditcardchargepercent1` decimal(20,2) NOT NULL default '0.00',
  `creditcardchargeamount1` decimal(20,2) NOT NULL default '0.00',
  `creditcardtype2` varchar(20) NOT NULL default '',
  `creditcardno2` varchar(50) NOT NULL default '',
  `creditcardnameoncard2` varchar(200) NOT NULL default '',
  `creditcardexpireddate2` varchar(10) NOT NULL default '',
  `creditcardapprovalcode2` varchar(50) NOT NULL default '',
  `creditcardbankname2` varchar(100) NOT NULL,
  `creditcardchargepercent2` decimal(20,2) NOT NULL default '0.00',
  `creditcardchargeamount2` decimal(20,2) NOT NULL default '0.00',
  `cashpayment` decimal(20,2) NOT NULL default '0.00',
  `voidapproval` varchar(20) NOT NULL default '',
  `membercode` varchar(50) NOT NULL default '',
  `memberdiscount` decimal(20,2) NOT NULL default '0.00',
  `clientcreated` datetime default NULL,
  `branchcode` varchar(20) NOT NULL default '',
  `branchname` varchar(200) NOT NULL default '',
  `docontactperson` varchar(200) NOT NULL default '',
  `dophone` varchar(30) NOT NULL default '',
  `dofax` varchar(30) NOT NULL default '',
  `doemail` varchar(200) NOT NULL default '',
  `doaddress1` varchar(200) NOT NULL default '',
  `doaddress2` varchar(200) NOT NULL default '',
  `doaddress3` varchar(200) NOT NULL default '',
  `doaddress4` varchar(200) NOT NULL default '',
  `docity` varchar(50) NOT NULL default '',
  `dopostalcode` varchar(10) NOT NULL default '',
  `dostate` varchar(50) NOT NULL default '',
  `docountrycode` varchar(50) NOT NULL default '',
  `transactioncost` enum('Y','N') NOT NULL default 'N',
  `iscashsales` enum('Y','N') NOT NULL default 'N',
  `cashacccode` varchar(20) NOT NULL default '',
  `creditcardacccode` varchar(20) NOT NULL default '',
  `creditcard2acccode` varchar(20) NOT NULL default '',
  `roundingadjacccode` varchar(20) NOT NULL default '',
  `paymentjournalkey` int(11) unsigned default NULL,
  `cashsalesacccode` varchar(20) NOT NULL default '',
  `cardchargeacccode` varchar(20) NOT NULL default '',
  `curcode` varchar(20) NOT NULL,
  `currate` decimal(20,8) unsigned NOT NULL default '1.00000000',
  `localdiscountamount` decimal(20,2) NOT NULL,
  `localamountbeforediscount` decimal(20,2) NOT NULL,
  `localamount` decimal(20,2) NOT NULL default '0.00',
  `localtaxamount` decimal(20,2) NOT NULL default '0.00',
  `localamountaftertax` decimal(20,2) NOT NULL default '0.00',
  `localtotaldepositamount` decimal(20,2) NOT NULL default '0.00',
  `tourgroupcode` varchar(20) default '',
  `cashpaycurcode1` varchar(20) NOT NULL,
  `cashpaycurrate1` decimal(20,8) unsigned NOT NULL default '1.00000000',
  `cashpay1` decimal(20,2) NOT NULL default '0.00',
  `localcashpay1` decimal(20,2) NOT NULL default '0.00',
  `cashpaycurcode2` varchar(20) NOT NULL,
  `cashpaycurrate2` decimal(20,8) unsigned NOT NULL default '1.00000000',
  `cashpay2` decimal(20,2) NOT NULL default '0.00',
  `localcashpay2` decimal(20,2) NOT NULL default '0.00',
  `cashpaycurcode3` varchar(20) NOT NULL,
  `cashpaycurrate3` decimal(20,8) unsigned NOT NULL default '1.00000000',
  `cashpay3` decimal(20,2) NOT NULL default '0.00',
  `localcashpay3` decimal(20,2) NOT NULL default '0.00',
  `confirmed` enum('Y','N') NOT NULL default 'N',
  `ref1` varchar(30) NOT NULL,
  `ref2` varchar(30) NOT NULL,
  `ref3` varchar(30) NOT NULL,
  `ref4` varchar(30) NOT NULL,
  `postaccountvalue` enum('Y','N') NOT NULL default 'Y',
  `poststockvalue` enum('Y','N') NOT NULL default 'Y',
  `postingdate` date default NULL,
  `customerreceived` enum('Y','N') NOT NULL default 'Y',
  `customerreceiveddate` date default NULL,
  `debitcardamount` decimal(20,2) NOT NULL default '0.00',
  `debitcarddescr` varchar(200) NOT NULL default '',
  `debitcardrefno` varchar(20) NOT NULL default '',
  `chequeamount` decimal(20,2) NOT NULL default '0.00',
  `chequedescr` varchar(200) NOT NULL default '',
  `chequeno` varchar(20) NOT NULL default '',
  `debitcardacccode` varchar(20) NOT NULL default '',
  `chequeacccode` varchar(20) NOT NULL default '',
  `cashreceiptdepositamount` decimal(20,2) NOT NULL default '0.00',
  `cashreceiptdepositcode` varchar(20) NOT NULL default '',
  `lastmodified` timestamp NOT NULL default CURRENT_TIMESTAMP on update CURRENT_TIMESTAMP,
  `accsalesamount` decimal(20,2) NOT NULL default '0.00',
  `accdiscountamount` decimal(20,2) NOT NULL default '0.00',
  `acctaxamount` decimal(20,2) NOT NULL default '0.00',
  `accotheramount` decimal(20,2) NOT NULL default '0.00',
  `creditcardpaymenttype1` varchar(20) NOT NULL default '',
  `creditcardpaymenttype2` varchar(20) NOT NULL default '',
  `debtorname` varchar(200) NOT NULL default '',
  `creditcardmerchantchargeacccode` varchar(20) NOT NULL default '',
  `creditcardmerchantchargepercent` decimal(20,2) NOT NULL default '0.00',
  `creditcardmerchantchargeamount` decimal(20,2) NOT NULL default '0.00',
  `collectionplancode` varchar(20) NOT NULL default '',
  `salesleadkey` int(10) unsigned NOT NULL default '0',
  `shipment` enum('Y','N') NOT NULL default 'N',
  `shipmentrequiredate` date default NULL,
  `vouchercode` text,
  `voucheramount` decimal(20,2) default NULL,
  `voucheracccode` varchar(20) NOT NULL default '',
  `totalpointcollect` decimal(20,2) default NULL,
  `pointpayment` decimal(20,2) default NULL,
  `pointpaymentvalue` decimal(20,2) default NULL,
  `pointpaymentacccode` varchar(20) NOT NULL default '',
  `servicechargeacccode` varchar(20) NOT NULL default '',
  `depositjournalkey` int(11) unsigned default NULL,
  `depositliabilityacccode` varchar(20) NOT NULL default '',
  `depositgsttypecode` varchar(20) NOT NULL default '',
  `depositsupplypurchase` enum('None','Supply','Purchase') NOT NULL default 'None',
  `deposittaxpercentage` decimal(20,2) default NULL,
  `deposittaxacccode` varchar(20) NOT NULL default '',
  `deposittaxsubtract` enum('Y','N') NOT NULL default 'N',
  `deposittaxableamount` decimal(20,2) NOT NULL default '0.00',
  `deposittaxablelocalamount` decimal(20,2) NOT NULL default '0.00',
  `deposittaxamount` decimal(20,2) NOT NULL default '0.00',
  `deposittaxlocalamount` decimal(20,2) NOT NULL default '0.00',
  `depositamountaftertaxsubtract` decimal(20,2) NOT NULL default '0.00',
  `depositlocalamountaftertaxsubtract` decimal(20,2) NOT NULL default '0.00',
  `fromoldversion` enum('Y','N') NOT NULL default 'N',
  PRIMARY KEY  (`salesinvoicekey`),
  UNIQUE KEY `isicode` (`salesinvoicecode`),
  KEY `isidate` (`salesinvoicedate`),
  KEY `isidebtorcode` (`debtorcode`),
  KEY `isitermcode` (`termcode`),
  KEY `isistaffcode` (`staffcode`),
  KEY `isirefno` (`refno`),
  KEY `isiglobalsalesacccode` (`globalsalesacccode`),
  KEY `isiglobaltaxacccode` (`globaltaxacccode`),
  KEY `isidepartmentcode` (`departmentcode`),
  KEY `isistocklocationcode` (`stocklocationcode`),
  KEY `isicancelled` (`cancelled`),
  KEY `isiispos` (`ispos`),
  KEY `isicountercode` (`countercode`),
  KEY `isicashiercode` (`cashiercode`),
  KEY `isipromotercode` (`promotercode`),
  KEY `isivoidapproval` (`voidapproval`),
  KEY `isimembercode` (`membercode`),
  KEY `isiareacode` (`areacode`),
  KEY `isiclientcreated` (`clientcreated`),
  KEY `isicurcode` (`curcode`),
  KEY `isitourgroupcode` (`tourgroupcode`),
  KEY `isicashpaycurcode1` (`cashpaycurcode1`),
  KEY `isicashpaycurcode2` (`cashpaycurcode2`),
  KEY `isicashpaycurcode3` (`cashpaycurcode3`),
  KEY `isiglobaldiscountacccode` (`globaldiscountacccode`),
  KEY `isiconfirmed` (`confirmed`),
  KEY `isiiscashsales` (`iscashsales`),
  KEY `isicashacccode` (`cashacccode`),
  KEY `isicreditcardacccode` (`creditcardacccode`),
  KEY `isicreditcard2acccode` (`creditcard2acccode`),
  KEY `isiroundingadjacccode` (`roundingadjacccode`),
  KEY `isipaymentjournalkey` (`paymentjournalkey`),
  KEY `isicashsalesacccode` (`cashsalesacccode`),
  KEY `isicardchargeacccode` (`cardchargeacccode`),
  KEY `isipostaccountvalue` (`postaccountvalue`),
  KEY `isipoststockvalue` (`poststockvalue`),
  KEY `isipostingdate` (`postingdate`),
  KEY `isicustomerreceived` (`customerreceived`),
  KEY `isicustomerreceiveddate` (`customerreceiveddate`),
  KEY `isicreditcardpaymenttype1` (`creditcardpaymenttype1`),
  KEY `isicreditcardpaymenttype2` (`creditcardpaymenttype2`),
  KEY `isijobcode` (`jobcode`),
  KEY `isicollectionplancode` (`collectionplancode`),
  KEY `isisalesleadkey` (`salesleadkey`),
  KEY `isishipment` (`shipment`),
  KEY `isivoucheracccode` (`voucheracccode`),
  KEY `isipointpaymentacccode` (`pointpaymentacccode`),
  KEY `isicreditcardmerchantchargeacccode` (`creditcardmerchantchargeacccode`),
  KEY `isicountrycode` (`countrycode`),
  KEY `isidocountrycode` (`docountrycode`),
  KEY `isiservicechargeacccode` (`servicechargeacccode`),
  KEY `isidepositjournalkey` (`depositjournalkey`),
  KEY `isidepositliabilityacccode` (`depositliabilityacccode`),
  KEY `isidepositgsttypecode` (`depositgsttypecode`),
  KEY `isideposittaxacccode` (`deposittaxacccode`)
) ENGINE=INNODB DEFAULT CHARSET=latin1;

CREATE TABLE `salesinvoiceid` (
  `salesinvoicekey` int(11) unsigned NOT NULL default '0',
  `id` int(11) unsigned NOT NULL default '0',
  PRIMARY KEY  (`salesinvoicekey`,`id`)
) ENGINE=INNODB DEFAULT CHARSET=latin1;

CREATE TABLE `salesinvoiceitem` (
  `salesinvoicekey` int(11) unsigned NOT NULL default '0',
  `salesinvoicecode` varchar(20) NOT NULL default '',
  `id` int(11) unsigned NOT NULL default '0',
  `pos` int(11) unsigned NOT NULL default '0',
  `itemno` varchar(10) NOT NULL default '',
  `stockcode` varchar(30) NOT NULL default '',
  `descr` varchar(200) NOT NULL default '',
  `moredescr` text,
  `qty` decimal(20,6) default NULL,
  `unitprice` decimal(20,6) default NULL,
  `uom` varchar(20) NOT NULL default '',
  `uomrate` double NOT NULL default '1',
  `qtybaseuom` decimal(20,6) NOT NULL default '0.000000',
  `unitpricebaseuom` double NOT NULL default '0',
  `discountformat` varchar(100) default NULL,
  `discountamount` decimal(20,2) default NULL,
  `amountbeforediscount` decimal(20,2) default NULL,
  `amount` decimal(20,2) default NULL,
  `gsttypecode` varchar(20) NOT NULL default '',
  `stockpackagegsttypecode` varchar(20) NOT NULL default '',
  `salestaxpercentage` decimal(20,2) default NULL,
  `salestaxamount` decimal(20,2) default NULL,
  `amountaftertax` decimal(20,2) default NULL,
  `acccode` varchar(20) NOT NULL default '',
  `departmentcode` varchar(20) NOT NULL default '',
  `jobcode` varchar(20) NOT NULL default '',
  `stocklocationcode` varchar(20) NOT NULL default '',
  `fromdoctype` varchar(5) NOT NULL default '',
  `fromdockey` int(11) unsigned default NULL,
  `fromdocid` int(11) unsigned default NULL,
  `fromdoccode` varchar(20) NOT NULL default '',
  `debtoritemcode` varchar(30) NOT NULL default '',
  `barcode` varchar(30) NOT NULL default '',
  `remark1` varchar(100) NOT NULL,
  `remark2` varchar(100) NOT NULL,
  `remark3` varchar(100) NOT NULL,
  `remark4` varchar(100) NOT NULL,
  `rowtype` enum('','TOTALUP','ITEMDISCOUNT','ITEMSERVICETAX','ITEMMISCCHARGES','FOOTERDISCOUNT','FOOTERSERVICETAX','FOOTERMISCCHARGES') NOT NULL,
  `foc` enum('Y','N') NOT NULL default 'N',
  `packingqty` decimal(20,6) default NULL,
  `packinguom` varchar(20) NOT NULL default '',
  `packingrate` decimal(20,6) default NULL,
  `costtype` enum('Costing Method','Manual') NOT NULL default 'Manual',
  `unitcost` decimal(20,2) NOT NULL default '0.00',
  `stockpackagecode` varchar(20) NOT NULL,
  `stockpackageid` int(11) unsigned NOT NULL default '0',
  `stockpackagerate` double default NULL,
  `stockpackageqty` decimal(20,6) default NULL,
  `stockpackageunitprice` decimal(20,6) default NULL,
  `stockpackageamount` decimal(20,2) default NULL,
  `stockpackagesalestaxpercentage` decimal(20,2) default NULL,
  `stockpackagesalestaxamount` decimal(20,2) default NULL,
  `stockpackageamountaftertax` decimal(20,2) default NULL,
  `serialno` text,
  `batchno` varchar(30) NOT NULL default '',
  `curcode` varchar(20) NOT NULL default '',
  `curprice` decimal(20,6) default NULL,
  `currate` decimal(20,8) unsigned default NULL,
  `recommendpricebaseuom` decimal(20,6) unsigned NOT NULL default '0.000000',
  `weightrate` decimal(20,6) unsigned NOT NULL default '0.000000',
  `weightuom` varchar(20) NOT NULL default '',
  `weightqty` decimal(20,6) unsigned NOT NULL default '0.000000',
  `weightloosed` decimal(20,6) unsigned NOT NULL default '0.000000',
  `totalweight` decimal(20,6) unsigned NOT NULL default '0.000000',
  `volumerate` decimal(20,6) unsigned NOT NULL default '0.000000',
  `volumeuom` varchar(20) NOT NULL default '',
  `volumeqty` decimal(20,6) unsigned NOT NULL default '0.000000',
  `volumeloosed` decimal(20,6) unsigned NOT NULL default '0.000000',
  `totalvolume` decimal(20,6) unsigned NOT NULL default '0.000000',
  `itempointcollect` decimal(20,2) default NULL,
  `supplypurchase` enum('None','Supply','Purchase') NOT NULL default 'None',
  `taxsubtract` enum('Y','N') NOT NULL default 'N',
  `taxableamount` decimal(20,2) NOT NULL default '0.00',
  `taxablelocalamount` decimal(20,2) NOT NULL default '0.00',
  `amountaftertaxsubtract` decimal(20,2) NOT NULL default '0.00',
  `localamountaftertaxsubtract` decimal(20,2) NOT NULL default '0.00',
  `salestaxlocalamount` decimal(20,2) NOT NULL default '0.00',
  `taxadjustment` decimal(20,2) NOT NULL default '0.00',
  `taxlocaladjustment` decimal(20,2) NOT NULL default '0.00',
  `taxtotalamount` decimal(20,2) NOT NULL default '0.00',
  `taxtotallocalamount` decimal(20,2) NOT NULL default '0.00',
  `oursocode` varchar(20) NOT NULL default '',
  `oursodate` date default NULL,
  `taxpermitno` varchar(50) NOT NULL default '',
  `taxacccode` varchar(20) NOT NULL default '',
  `taxexportcountrycode` varchar(50) NOT NULL default '',
  `ourdocode` varchar(20) NOT NULL default '',
  `ourdodate` date default NULL,
  `yourpocode` varchar(20) NOT NULL default '',
  `yourpodate` date default NULL,
  `stockpackagesupplypurchase` enum('None','Supply','Purchase') NOT NULL default 'None',
  `stockpackagetaxsubtract` enum('Y','N') NOT NULL default 'N',
  `stockpackagetaxableamount` decimal(20,2) NOT NULL default '0.00',
  `stockpackagetaxablelocalamount` decimal(20,2) NOT NULL default '0.00',
  `stockpackageamountaftertaxsubtract` decimal(20,2) NOT NULL default '0.00',
  `stockpackagelocalamountaftertaxsubtract` decimal(20,2) NOT NULL default '0.00',
  `stockpackagesalestaxlocalamount` decimal(20,2) NOT NULL default '0.00',
  `stockpackagetaxadjustment` decimal(20,2) NOT NULL default '0.00',
  `stockpackagetaxlocaladjustment` decimal(20,2) NOT NULL default '0.00',
  `stockpackagetaxtotalamount` decimal(20,2) NOT NULL default '0.00',
  `stockpackagetaxtotallocalamount` decimal(20,2) NOT NULL default '0.00',
  PRIMARY KEY  (`salesinvoicekey`,`pos`),
  UNIQUE KEY `isiikeyid` (`salesinvoicekey`,`id`),
  KEY `isiicode` (`salesinvoicecode`),
  KEY `isiistockcode` (`stockcode`),
  KEY `isiiacccode` (`acccode`),
  KEY `isiidepartmentcode` (`departmentcode`),
  KEY `isiistocklocationcode` (`stocklocationcode`),
  KEY `isiifromdoctypekeypos` (`fromdoctype`,`fromdockey`,`fromdocid`),
  KEY `isiibarcode` (`barcode`),
  KEY `isiifoc` (`foc`),
  KEY `isiistockpackagecode` (`stockpackagecode`),
  KEY `isiistockpackageid` (`stockpackageid`),
  KEY `isiibatchno` (`batchno`),
  KEY `isiijobcode` (`jobcode`),
  KEY `isiigsttypecode` (`gsttypecode`),
  KEY `isiistockpackagegsttypecode` (`stockpackagegsttypecode`),
  KEY `isiitaxacccode` (`taxacccode`),
  KEY `isiitaxexportcountrycode` (`taxexportcountrycode`)
) ENGINE=INNODB DEFAULT CHARSET=latin1;

CREATE TABLE `salesinvoicepacking` (
  `salesinvoicekey` int(11) unsigned NOT NULL default '0',
  `salesinvoicecode` varchar(20) NOT NULL default '',
  `pos` int(11) unsigned NOT NULL default '0',
  `palletno` varchar(20) NOT NULL default '',
  `stockcode` varchar(30) NOT NULL default '',
  `descr` varchar(200) NOT NULL default '',
  `qty` decimal(20,6) default NULL,
  `uom` varchar(20) NOT NULL default '',
  `netweight` decimal(20,6) default NULL,
  PRIMARY KEY  (`salesinvoicekey`,`pos`),
  KEY `sipcode` (`salesinvoicecode`),
  KEY `sipstockcode` (`stockcode`)
) ENGINE=INNODB DEFAULT CHARSET=latin1;

CREATE TABLE `salesinvoicetemplate` (
  `salesinvoicetemplatekey` int(11) unsigned NOT NULL auto_increment,
  `salesinvoicetemplatecode` varchar(20) NOT NULL default '',
  `salesinvoicetemplatedate` date default NULL,
  `debtorcode` varchar(20) NOT NULL default '',
  `termcode` varchar(20) NOT NULL default '',
  `staffcode` varchar(20) NOT NULL default '',
  `areacode` varchar(20) NOT NULL default '',
  `descr` varchar(200) NOT NULL default '',
  `validity` varchar(100) NOT NULL default '',
  `deliveryterm` varchar(100) NOT NULL default '',
  `refno` varchar(20) NOT NULL default '',
  `address1` varchar(200) NOT NULL default '',
  `address2` varchar(200) NOT NULL default '',
  `address3` varchar(200) NOT NULL default '',
  `address4` varchar(200) NOT NULL default '',
  `city` varchar(50) NOT NULL default '',
  `postalcode` varchar(10) NOT NULL default '',
  `state` varchar(50) NOT NULL default '',
  `countrycode` varchar(50) NOT NULL default '',
  `attention` varchar(200) NOT NULL default '',
  `phone` varchar(30) NOT NULL default '',
  `fax` varchar(30) NOT NULL default '',
  `discountamount` decimal(20,2) NOT NULL,
  `amountbeforediscount` decimal(20,2) NOT NULL,
  `amount` decimal(20,2) NOT NULL default '0.00',
  `taxamount` decimal(20,2) NOT NULL default '0.00',
  `amountaftertax` decimal(20,2) NOT NULL default '0.00',
  `note` mediumtext,
  `remark1` varchar(100) NOT NULL,
  `remark2` varchar(100) NOT NULL,
  `remark3` varchar(100) NOT NULL,
  `remark4` varchar(100) NOT NULL,
  `remark5` varchar(100) NOT NULL,
  `remark6` varchar(100) NOT NULL,
  `remark7` varchar(100) NOT NULL,
  `remark8` varchar(100) NOT NULL,
  `globaldepartment` enum('Y','N') NOT NULL default 'Y',
  `departmentcode` varchar(20) NOT NULL default '',
  `globaljob` enum('Y','N') NOT NULL default 'N',
  `jobcode` varchar(20) NOT NULL default '',
  `globalstocklocation` enum('Y','N') NOT NULL default 'Y',
  `stocklocationcode` varchar(20) NOT NULL default '',
  `inactive` enum('Y','N') NOT NULL default 'N',
  `itemformatkey` int(10) unsigned NOT NULL default '0',
  `created` datetime default NULL,
  `modified` datetime default NULL,
  `done` enum('Y','N') NOT NULL default 'N',
  `branchcode` varchar(20) NOT NULL default '',
  `branchname` varchar(200) NOT NULL default '',
  `docontactperson` varchar(200) NOT NULL default '',
  `dophone` varchar(30) NOT NULL default '',
  `dofax` varchar(30) NOT NULL default '',
  `doemail` varchar(200) NOT NULL default '',
  `doaddress1` varchar(200) NOT NULL default '',
  `doaddress2` varchar(200) NOT NULL default '',
  `doaddress3` varchar(200) NOT NULL default '',
  `doaddress4` varchar(200) NOT NULL default '',
  `docity` varchar(50) NOT NULL default '',
  `dopostalcode` varchar(10) NOT NULL default '',
  `dostate` varchar(50) NOT NULL default '',
  `docountrycode` varchar(50) NOT NULL default '',
  `transactioncost` enum('Y','N') NOT NULL default 'N',
  `curcode` varchar(20) NOT NULL,
  `currate` decimal(20,8) unsigned NOT NULL default '1.00000000',
  `localdiscountamount` decimal(20,2) NOT NULL,
  `localamountbeforediscount` decimal(20,2) NOT NULL,
  `localamount` decimal(20,2) NOT NULL default '0.00',
  `localtaxamount` decimal(20,2) NOT NULL default '0.00',
  `localamountaftertax` decimal(20,2) NOT NULL default '0.00',
  `ref1` varchar(30) NOT NULL,
  `ref2` varchar(30) NOT NULL,
  `ref3` varchar(30) NOT NULL,
  `ref4` varchar(30) NOT NULL,
  `lastmodified` timestamp NOT NULL default CURRENT_TIMESTAMP on update CURRENT_TIMESTAMP,
  PRIMARY KEY  (`salesinvoicetemplatekey`),
  UNIQUE KEY `isitcode` (`salesinvoicetemplatecode`),
  KEY `isitdate` (`salesinvoicetemplatedate`),
  KEY `isitdebtorcode` (`debtorcode`),
  KEY `isittermcode` (`termcode`),
  KEY `isitstaffcode` (`staffcode`),
  KEY `isitrefno` (`refno`),
  KEY `isitdepartmentcode` (`departmentcode`),
  KEY `isitstocklocationcode` (`stocklocationcode`),
  KEY `isitareacode` (`areacode`),
  KEY `isitcurcode` (`curcode`),
  KEY `isitinactive` (`inactive`),
  KEY `isitjobcode` (`jobcode`),
  KEY `isitcountrycode` (`countrycode`),
  KEY `isitdocountrycode` (`docountrycode`)
) ENGINE=INNODB DEFAULT CHARSET=latin1;

CREATE TABLE `salesinvoicetemplateid` (
  `salesinvoicetemplatekey` int(11) unsigned NOT NULL default '0',
  `id` int(11) unsigned NOT NULL default '0',
  PRIMARY KEY  (`salesinvoicetemplatekey`,`id`)
) ENGINE=INNODB DEFAULT CHARSET=latin1;

CREATE TABLE `salesinvoicetemplateitem` (
  `salesinvoicetemplatekey` int(11) unsigned NOT NULL default '0',
  `salesinvoicetemplatecode` varchar(20) NOT NULL default '',
  `id` int(11) unsigned NOT NULL default '0',
  `pos` int(11) unsigned NOT NULL default '0',
  `itemno` varchar(10) NOT NULL default '',
  `stockcode` varchar(30) NOT NULL default '',
  `descr` varchar(200) NOT NULL default '',
  `moredescr` text,
  `qty` decimal(20,6) default NULL,
  `unitprice` decimal(20,6) default NULL,
  `uom` varchar(20) NOT NULL default '',
  `uomrate` double NOT NULL default '1',
  `qtybaseuom` decimal(20,6) NOT NULL default '0.000000',
  `unitpricebaseuom` double NOT NULL default '0',
  `discountformat` varchar(100) default NULL,
  `discountamount` decimal(20,2) default NULL,
  `amountbeforediscount` decimal(20,2) default NULL,
  `amount` decimal(20,2) default NULL,
  `gsttypecode` varchar(20) NOT NULL default '',
  `stockpackagegsttypecode` varchar(20) NOT NULL default '',
  `salestaxpercentage` decimal(20,2) default NULL,
  `salestaxamount` decimal(20,2) default NULL,
  `amountaftertax` decimal(20,2) default NULL,
  `departmentcode` varchar(20) NOT NULL default '',
  `jobcode` varchar(20) NOT NULL default '',
  `stocklocationcode` varchar(20) NOT NULL default '',
  `debtoritemcode` varchar(30) NOT NULL default '',
  `barcode` varchar(30) NOT NULL default '',
  `remark1` varchar(100) NOT NULL,
  `remark2` varchar(100) NOT NULL,
  `remark3` varchar(100) NOT NULL,
  `remark4` varchar(100) NOT NULL,
  `rowtype` enum('','TOTALUP','ITEMDISCOUNT','ITEMSERVICETAX','ITEMMISCCHARGES','FOOTERDISCOUNT','FOOTERSERVICETAX','FOOTERMISCCHARGES') NOT NULL,
  `foc` enum('Y','N') NOT NULL default 'N',
  `packingqty` decimal(20,6) default NULL,
  `packinguom` varchar(20) NOT NULL default '',
  `packingrate` decimal(20,6) default NULL,
  `costtype` enum('Costing Method','Manual') NOT NULL default 'Manual',
  `unitcost` decimal(20,2) NOT NULL default '0.00',
  `stockpackagecode` varchar(20) NOT NULL,
  `stockpackageid` int(11) unsigned NOT NULL default '0',
  `stockpackagerate` double default NULL,
  `stockpackageqty` decimal(20,6) default NULL,
  `stockpackageunitprice` decimal(20,6) default NULL,
  `stockpackageamount` decimal(20,2) default NULL,
  `stockpackagesalestaxpercentage` decimal(20,2) default NULL,
  `stockpackagesalestaxamount` decimal(20,2) default NULL,
  `stockpackageamountaftertax` decimal(20,2) default NULL,
  `batchno` varchar(30) NOT NULL default '',
  `curcode` varchar(20) NOT NULL default '',
  `curprice` decimal(20,6) default NULL,
  `currate` decimal(20,8) unsigned default NULL,
  `recommendpricebaseuom` decimal(20,6) unsigned NOT NULL default '0.000000',
  `weightrate` decimal(20,6) unsigned NOT NULL default '0.000000',
  `weightuom` varchar(20) NOT NULL default '',
  `weightqty` decimal(20,6) unsigned NOT NULL default '0.000000',
  `weightloosed` decimal(20,6) unsigned NOT NULL default '0.000000',
  `totalweight` decimal(20,6) unsigned NOT NULL default '0.000000',
  `volumerate` decimal(20,6) unsigned NOT NULL default '0.000000',
  `volumeuom` varchar(20) NOT NULL default '',
  `volumeqty` decimal(20,6) unsigned NOT NULL default '0.000000',
  `volumeloosed` decimal(20,6) unsigned NOT NULL default '0.000000',
  `totalvolume` decimal(20,6) unsigned NOT NULL default '0.000000',
  `supplypurchase` enum('None','Supply','Purchase') NOT NULL default 'None',
  `taxsubtract` enum('Y','N') NOT NULL default 'N',
  `taxableamount` decimal(20,2) NOT NULL default '0.00',
  `taxablelocalamount` decimal(20,2) NOT NULL default '0.00',
  `amountaftertaxsubtract` decimal(20,2) NOT NULL default '0.00',
  `localamountaftertaxsubtract` decimal(20,2) NOT NULL default '0.00',
  `salestaxlocalamount` decimal(20,2) NOT NULL default '0.00',
  `taxadjustment` decimal(20,2) NOT NULL default '0.00',
  `taxlocaladjustment` decimal(20,2) NOT NULL default '0.00',
  `taxtotalamount` decimal(20,2) NOT NULL default '0.00',
  `taxtotallocalamount` decimal(20,2) NOT NULL default '0.00',
  `stockpackagesupplypurchase` enum('None','Supply','Purchase') NOT NULL default 'None',
  `stockpackagetaxsubtract` enum('Y','N') NOT NULL default 'N',
  `stockpackagetaxableamount` decimal(20,2) NOT NULL default '0.00',
  `stockpackagetaxablelocalamount` decimal(20,2) NOT NULL default '0.00',
  `stockpackageamountaftertaxsubtract` decimal(20,2) NOT NULL default '0.00',
  `stockpackagelocalamountaftertaxsubtract` decimal(20,2) NOT NULL default '0.00',
  `stockpackagesalestaxlocalamount` decimal(20,2) NOT NULL default '0.00',
  `stockpackagetaxadjustment` decimal(20,2) NOT NULL default '0.00',
  `stockpackagetaxlocaladjustment` decimal(20,2) NOT NULL default '0.00',
  `stockpackagetaxtotalamount` decimal(20,2) NOT NULL default '0.00',
  `stockpackagetaxtotallocalamount` decimal(20,2) NOT NULL default '0.00',
  PRIMARY KEY  (`salesinvoicetemplatekey`,`pos`),
  UNIQUE KEY `isitikeyid` (`salesinvoicetemplatekey`,`id`),
  KEY `isiticode` (`salesinvoicetemplatecode`),
  KEY `isitistockcode` (`stockcode`),
  KEY `isitidepartmentcode` (`departmentcode`),
  KEY `isitistocklocationcode` (`stocklocationcode`),
  KEY `isitibarcode` (`barcode`),
  KEY `isitifoc` (`foc`),
  KEY `isitistockpackagecode` (`stockpackagecode`),
  KEY `isitistockpackageid` (`stockpackageid`),
  KEY `isitijobcode` (`jobcode`),
  KEY `isitigsttypecode` (`gsttypecode`),
  KEY `isitistockpackagegsttypecode` (`stockpackagegsttypecode`),
  KEY `isitibatchno` (`batchno`)
) ENGINE=INNODB DEFAULT CHARSET=latin1;

CREATE TABLE `salesinvoicetemplateplaninvoiceddate` (
  `salesinvoicetemplatekey` int(11) unsigned NOT NULL default '0',
  `planinvoicedate` date default NULL,
  `pos` int(11) unsigned NOT NULL default '0',
  PRIMARY KEY  (`salesinvoicetemplatekey`,`pos`)
) ENGINE=INNODB DEFAULT CHARSET=latin1;

CREATE TABLE `saleslead` (
  `salesleadkey` int(11) unsigned NOT NULL auto_increment,
  `salesleadcode` varchar(20) NOT NULL default '',
  `salesleaddate` date default NULL,
  `salesleadsourcecode` varchar(20) NOT NULL default '',
  `salesleadstatuscode` varchar(20) NOT NULL default '',
  `debtorcode` varchar(20) NOT NULL default '',
  `name` varchar(200) NOT NULL default '',
  `name2` varchar(200) NOT NULL default '',
  `regno` varchar(30) NOT NULL default '',
  `businessform` varchar(200) NOT NULL default '',
  `curcode` varchar(20) NOT NULL,
  `categorycode` varchar(20) NOT NULL default '',
  `termcode` varchar(20) NOT NULL default '',
  `areacode` varchar(20) NOT NULL default '',
  `address1` varchar(200) NOT NULL default '',
  `address2` varchar(200) NOT NULL default '',
  `address3` varchar(200) NOT NULL default '',
  `address4` varchar(200) NOT NULL default '',
  `phone` varchar(30) NOT NULL default '',
  `phone2` varchar(30) NOT NULL default '',
  `fax` varchar(30) NOT NULL default '',
  `fax2` varchar(30) NOT NULL default '',
  `email` varchar(200) NOT NULL default '',
  `email2` varchar(200) NOT NULL default '',
  `homepage` varchar(200) NOT NULL default '',
  `contactperson` varchar(200) NOT NULL default '',
  `contactpersonposition` varchar(200) NOT NULL default '',
  `staffcode` varchar(20) NOT NULL default '',
  `descr` varchar(200) NOT NULL default '',
  `descr2` varchar(200) NOT NULL default '',
  `note` mediumtext,
  `remark1` varchar(100) NOT NULL,
  `remark2` varchar(100) NOT NULL,
  `remark3` varchar(100) NOT NULL,
  `remark4` varchar(100) NOT NULL,
  `remark5` varchar(100) NOT NULL,
  `remark6` varchar(100) NOT NULL,
  `remark7` varchar(100) NOT NULL,
  `remark8` varchar(100) NOT NULL,
  `departmentcode` varchar(20) NOT NULL default '',
  `jobcode` varchar(20) NOT NULL default '',
  `stocklocationcode` varchar(20) NOT NULL default '',
  `referraldebtorcode` varchar(20) NOT NULL default '',
  `recommendedby` varchar(20) NOT NULL default '',
  `saleswinprobability` int(11) unsigned NOT NULL default '0',
  `salesclosed` enum('Win','Lost','Open') NOT NULL default 'Open',
  `salesclosedreason` varchar(200) NOT NULL default '',
  `salescloseddate` date default NULL,
  `done` enum('Y','N') NOT NULL default 'N',
  `salesleadtypecode` varchar(20) NOT NULL default '',
  `salesleadcategorycode` varchar(20) NOT NULL default '',
  `salesleadgroupcode` varchar(20) NOT NULL default '',
  `salesleadseveritycode` varchar(20) NOT NULL default '',
  `city` varchar(50) NOT NULL default '',
  `postalcode` char(10) NOT NULL default '',
  `state` varchar(50) NOT NULL default '',
  `countrycode` varchar(50) NOT NULL default '',
  PRIMARY KEY  (`salesleadkey`),
  UNIQUE KEY `isfslcode` (`salesleadcode`),
  KEY `isfsldate` (`salesleaddate`),
  KEY `isfsldebtorcode` (`debtorcode`),
  KEY `isfsltermcode` (`termcode`),
  KEY `isfslstaffcode` (`staffcode`),
  KEY `isfsldepartmentcode` (`departmentcode`),
  KEY `isfslstocklocationcode` (`stocklocationcode`),
  KEY `isfslareacode` (`areacode`),
  KEY `isfslreferraldebtorcode` (`referraldebtorcode`),
  KEY `isfslcurcode` (`curcode`),
  KEY `isfslcategorycode` (`categorycode`),
  KEY `isfsljobcode` (`jobcode`),
  KEY `isfslsalesleadsourcecode` (`salesleadsourcecode`),
  KEY `isfslsalesleadstatuscode` (`salesleadstatuscode`),
  KEY `islsalesleadtypecode` (`salesleadtypecode`),
  KEY `islsalesleadcategorycode` (`salesleadcategorycode`),
  KEY `islsalesleadgroupcode` (`salesleadgroupcode`),
  KEY `islsalesleadseveritycode` (`salesleadseveritycode`),
  KEY `islcity` (`city`),
  KEY `islstate` (`state`),
  KEY `islcountrycode` (`countrycode`)
) ENGINE=INNODB DEFAULT CHARSET=latin1;

CREATE TABLE `salesleadcategory` (
  `salesleadcategorykey` int(11) unsigned NOT NULL auto_increment,
  `salesleadcategorycode` varchar(20) NOT NULL default '',
  `descr` varchar(200) NOT NULL default '',
  `inactive` enum('Y','N') NOT NULL default 'N',
  `done` enum('Y','N') NOT NULL default 'N',
  `lastmodified` timestamp NOT NULL default CURRENT_TIMESTAMP on update CURRENT_TIMESTAMP,
  PRIMARY KEY  (`salesleadcategorykey`),
  UNIQUE KEY `isfslccode` (`salesleadcategorycode`),
  KEY `isfslcinactive` (`inactive`)
) ENGINE=INNODB DEFAULT CHARSET=latin1;

CREATE TABLE `salesleadgroup` (
  `salesleadgroupkey` int(11) unsigned NOT NULL auto_increment,
  `salesleadgroupcode` varchar(20) NOT NULL default '',
  `descr` varchar(200) NOT NULL default '',
  `inactive` enum('Y','N') NOT NULL default 'N',
  `done` enum('Y','N') NOT NULL default 'N',
  `lastmodified` timestamp NOT NULL default CURRENT_TIMESTAMP on update CURRENT_TIMESTAMP,
  PRIMARY KEY  (`salesleadgroupkey`),
  UNIQUE KEY `isfslgcode` (`salesleadgroupcode`),
  KEY `isfslginactive` (`inactive`)
) ENGINE=INNODB DEFAULT CHARSET=latin1;

CREATE TABLE `salesleadinterestedproduct` (
  `salesleadkey` int(11) unsigned NOT NULL,
  `salesleadcode` varchar(20) NOT NULL default '',
  `pos` int(11) unsigned NOT NULL default '0',
  `stockcode` varchar(30) NOT NULL default '',
  `stockname` varchar(200) NOT NULL default '',
  `descr` varchar(200) NOT NULL default '',
  `qty` decimal(20,6) default NULL,
  PRIMARY KEY (`salesleadkey`,`pos`),
  KEY `isfslipsalesleadcode` (`salesleadcode`),
  KEY `isfslipstockcode` (`stockcode`)
) ENGINE=INNODB DEFAULT CHARSET=latin1;

CREATE TABLE `salesleadseverity` (
  `salesleadseveritykey` int(11) unsigned NOT NULL auto_increment,
  `salesleadseveritycode` varchar(20) NOT NULL default '',
  `descr` varchar(200) NOT NULL default '',
  `inactive` enum('Y','N') NOT NULL default 'N',
  `done` enum('Y','N') NOT NULL default 'N',
  `lastmodified` timestamp NOT NULL default CURRENT_TIMESTAMP on update CURRENT_TIMESTAMP,
  PRIMARY KEY  (`salesleadseveritykey`),
  UNIQUE KEY `isfslscode` (`salesleadseveritycode`),
  KEY `isfslsinactive` (`inactive`)
) ENGINE=INNODB DEFAULT CHARSET=latin1;

CREATE TABLE `salesleadsource` (
  `salesleadsourcekey` int(11) unsigned NOT NULL auto_increment,
  `salesleadsourcecode` varchar(20) NOT NULL default '',
  `descr` varchar(200) NOT NULL default '',
  `inactive` enum('Y','N') NOT NULL default 'N',
  `done` enum('Y','N') NOT NULL default 'N',
  `lastmodified` timestamp NOT NULL default CURRENT_TIMESTAMP on update CURRENT_TIMESTAMP,
  PRIMARY KEY  (`salesleadsourcekey`),
  UNIQUE KEY `isfslscode` (`salesleadsourcecode`),
  KEY `isfslsinactive` (`inactive`)
) ENGINE=INNODB DEFAULT CHARSET=latin1;

CREATE TABLE `salesleadstatus` (
  `salesleadstatuskey` int(11) unsigned NOT NULL auto_increment,
  `salesleadstatuscode` varchar(20) NOT NULL default '',
  `descr` varchar(200) NOT NULL default '',
  `inactive` enum('Y','N') NOT NULL default 'N',
  `done` enum('Y','N') NOT NULL default 'N',
  `lastmodified` timestamp NOT NULL default CURRENT_TIMESTAMP on update CURRENT_TIMESTAMP,
  PRIMARY KEY  (`salesleadstatuskey`),
  UNIQUE KEY `isfslstcode` (`salesleadstatuscode`),
  KEY `isfslstinactive` (`inactive`)
) ENGINE=INNODB DEFAULT CHARSET=latin1;

CREATE TABLE `salesleadstatushistory` (
  `salesleadkey` int(11) unsigned NOT NULL default '0',
  `id` int(11) unsigned NOT NULL default '0',
  `salesleadstatuscode` varchar(20) NOT NULL default '',
  `startdate` date default NULL,
  `enddate` date default NULL,
  PRIMARY KEY  (`salesleadkey`,`id`),
  KEY `isfslshsalesleadstatuscode` (`salesleadstatuscode`)
) ENGINE=INNODB DEFAULT CHARSET=latin1;

CREATE TABLE `salesleadtype` (
  `salesleadtypekey` int(11) unsigned NOT NULL auto_increment,
  `salesleadtypecode` varchar(20) NOT NULL default '',
  `descr` varchar(200) NOT NULL default '',
  `inactive` enum('Y','N') NOT NULL default 'N',
  `done` enum('Y','N') NOT NULL default 'N',
  `lastmodified` timestamp NOT NULL default CURRENT_TIMESTAMP on update CURRENT_TIMESTAMP,
  PRIMARY KEY  (`salesleadtypekey`),
  UNIQUE KEY `isfsltcode` (`salesleadtypecode`),
  KEY `isfsltinactive` (`inactive`)
) ENGINE=INNODB DEFAULT CHARSET=latin1;

CREATE TABLE `salesmemo` (
  `salesmemokey` int(11) unsigned NOT NULL auto_increment,
  `salesmemocode` varchar(20) NOT NULL default '',
  `salesmemodate` date default NULL,
  `memotypecode` varchar(20) NOT NULL default '',
  `debtorcode` varchar(20) NOT NULL default '',
  `termcode` varchar(20) NOT NULL default '',
  `staffcode` varchar(20) NOT NULL default '',
  `areacode` varchar(20) NOT NULL default '',
  `descr` varchar(200) NOT NULL default '',
  `validity` varchar(100) NOT NULL default '',
  `deliveryterm` varchar(100) NOT NULL default '',
  `refno` varchar(20) NOT NULL default '',
  `address1` varchar(200) NOT NULL default '',
  `address2` varchar(200) NOT NULL default '',
  `address3` varchar(200) NOT NULL default '',
  `address4` varchar(200) NOT NULL default '',
  `city` varchar(50) NOT NULL default '',
  `postalcode` varchar(10) NOT NULL default '',
  `state` varchar(50) NOT NULL default '',
  `countrycode` varchar(50) NOT NULL default '',
  `attention` varchar(200) NOT NULL default '',
  `phone` varchar(30) NOT NULL default '',
  `fax` varchar(30) NOT NULL default '',
  `discountamount` decimal(20,2) NOT NULL,
  `amountbeforediscount` decimal(20,2) NOT NULL,
  `amount` decimal(20,2) NOT NULL default '0.00',
  `taxamount` decimal(20,2) NOT NULL default '0.00',
  `amountaftertax` decimal(20,2) NOT NULL default '0.00',
  `note` mediumtext,
  `remark1` varchar(100) NOT NULL,
  `remark2` varchar(100) NOT NULL,
  `remark3` varchar(100) NOT NULL,
  `remark4` varchar(100) NOT NULL,
  `remark5` varchar(100) NOT NULL,
  `remark6` varchar(100) NOT NULL,
  `remark7` varchar(100) NOT NULL,
  `remark8` varchar(100) NOT NULL,
  `globaldepartment` enum('Y','N') NOT NULL default 'Y',
  `departmentcode` varchar(20) NOT NULL default '',
  `globaljob` enum('Y','N') NOT NULL default 'N',
  `jobcode` varchar(20) NOT NULL default '',
  `globalstocklocation` enum('Y','N') NOT NULL default 'Y',
  `stocklocationcode` varchar(20) NOT NULL default '',
  `cancelled` enum('Y','N') NOT NULL default 'N',
  `poststockvalue` enum('Y','N') NOT NULL default 'Y',
  `itemformatkey` int(10) unsigned NOT NULL default '0',
  `created` datetime default NULL,
  `modified` datetime default NULL,
  `done` enum('Y','N') NOT NULL default 'N',
  `branchcode` varchar(20) NOT NULL default '',
  `branchname` varchar(200) NOT NULL default '',
  `docontactperson` varchar(200) NOT NULL default '',
  `dophone` varchar(30) NOT NULL default '',
  `dofax` varchar(30) NOT NULL default '',
  `doemail` varchar(200) NOT NULL default '',
  `doaddress1` varchar(200) NOT NULL default '',
  `doaddress2` varchar(200) NOT NULL default '',
  `doaddress3` varchar(200) NOT NULL default '',
  `doaddress4` varchar(200) NOT NULL default '',
  `docity` varchar(50) NOT NULL default '',
  `dopostalcode` varchar(10) NOT NULL default '',
  `dostate` varchar(50) NOT NULL default '',
  `docountrycode` varchar(50) NOT NULL default '',
  `curcode` varchar(20) NOT NULL,
  `currate` decimal(20,8) unsigned NOT NULL default '1.00000000',
  `localdiscountamount` decimal(20,2) NOT NULL,
  `localamountbeforediscount` decimal(20,2) NOT NULL,
  `localamount` decimal(20,2) NOT NULL default '0.00',
  `localtaxamount` decimal(20,2) NOT NULL default '0.00',
  `localamountaftertax` decimal(20,2) NOT NULL default '0.00',
  `ref1` varchar(30) NOT NULL,
  `ref2` varchar(30) NOT NULL,
  `ref3` varchar(30) NOT NULL,
  `ref4` varchar(30) NOT NULL,
  `lastmodified` timestamp NOT NULL default CURRENT_TIMESTAMP on update CURRENT_TIMESTAMP,
  `salesleadkey` int(10) unsigned NOT NULL default '0',
  `debtorname` varchar(200) NOT NULL default '',
  `fromoldversion` enum('Y','N') NOT NULL default 'N',
  PRIMARY KEY  (`salesmemokey`),
  UNIQUE KEY `ismcode` (`salesmemocode`),
  KEY `ismdate` (`salesmemodate`),
  KEY `ismmemotypecode` (`memotypecode`),
  KEY `ismdebtorcode` (`debtorcode`),
  KEY `ismtermcode` (`termcode`),
  KEY `ismstaffcode` (`staffcode`),
  KEY `ismrefno` (`refno`),
  KEY `ismdepartmentcode` (`departmentcode`),
  KEY `ismstocklocationcode` (`stocklocationcode`),
  KEY `ismcancelled` (`cancelled`),
  KEY `ismpoststockvalue` (`poststockvalue`),
  KEY `ismareacode` (`areacode`),
  KEY `ismcurcode` (`curcode`),
  KEY `ismjobcode` (`jobcode`),
  KEY `ismsalesleadkey` (`salesleadkey`),
  KEY `ismcountrycode` USING BTREE (`countrycode`),
  KEY `ismdocountrycode` USING BTREE (`docountrycode`)
) ENGINE=INNODB DEFAULT CHARSET=latin1;

CREATE TABLE `salesmemoid` (
  `salesmemokey` int(11) unsigned NOT NULL default '0',
  `id` int(11) unsigned NOT NULL default '0',
  PRIMARY KEY  (`salesmemokey`,`id`)
) ENGINE=INNODB DEFAULT CHARSET=latin1;

CREATE TABLE `salesmemoitem` (
  `salesmemokey` int(11) unsigned NOT NULL default '0',
  `salesmemocode` varchar(20) NOT NULL default '',
  `id` int(11) unsigned NOT NULL default '0',
  `pos` int(11) unsigned NOT NULL default '0',
  `itemno` varchar(10) NOT NULL default '',
  `stockcode` varchar(30) NOT NULL default '',
  `descr` varchar(200) NOT NULL default '',
  `moredescr` text,
  `qty` decimal(20,6) default NULL,
  `unitprice` decimal(20,6) default NULL,
  `uom` varchar(20) NOT NULL default '',
  `uomrate` double NOT NULL default '1',
  `qtybaseuom` decimal(20,6) NOT NULL default '0.000000',
  `unitpricebaseuom` double NOT NULL default '0',
  `discountformat` varchar(100) default NULL,
  `discountamount` decimal(20,2) default NULL,
  `amountbeforediscount` decimal(20,2) default NULL,
  `amount` decimal(20,2) default NULL,
  `gsttypecode` varchar(20) NOT NULL default '',
  `stockpackagegsttypecode` varchar(20) NOT NULL default '',
  `salestaxpercentage` decimal(20,2) default NULL,
  `salestaxamount` decimal(20,2) default NULL,
  `amountaftertax` decimal(20,2) default NULL,
  `departmentcode` varchar(20) NOT NULL default '',
  `jobcode` varchar(20) NOT NULL default '',
  `stocklocationcode` varchar(20) NOT NULL default '',
  `debtoritemcode` varchar(30) NOT NULL default '',
  `barcode` varchar(30) NOT NULL default '',
  `remark1` varchar(100) NOT NULL,
  `remark2` varchar(100) NOT NULL,
  `remark3` varchar(100) NOT NULL,
  `remark4` varchar(100) NOT NULL,
  `rowtype` enum('','TOTALUP','ITEMDISCOUNT','ITEMSERVICETAX','ITEMMISCCHARGES','FOOTERDISCOUNT','FOOTERSERVICETAX','FOOTERMISCCHARGES') NOT NULL,
  `foc` enum('Y','N') NOT NULL default 'N',
  `packingqty` decimal(20,6) default NULL,
  `packinguom` varchar(20) NOT NULL default '',
  `packingrate` decimal(20,6) default NULL,
  `stockpackagecode` varchar(20) NOT NULL,
  `stockpackageid` int(11) unsigned NOT NULL default '0',
  `stockpackagerate` double default NULL,
  `stockpackageqty` decimal(20,6) default NULL,
  `stockpackageunitprice` decimal(20,6) default NULL,
  `stockpackageamount` decimal(20,2) default NULL,
  `stockpackagesalestaxpercentage` decimal(20,2) default NULL,
  `stockpackagesalestaxamount` decimal(20,2) default NULL,
  `stockpackageamountaftertax` decimal(20,2) default NULL,
  `serialno` text,
  `batchno` varchar(30) NOT NULL default '',
  `curcode` varchar(20) NOT NULL default '',
  `curprice` decimal(20,6) default NULL,
  `currate` decimal(20,8) unsigned default NULL,
  `recommendpricebaseuom` decimal(20,6) unsigned NOT NULL default '0.000000',
  `weightrate` decimal(20,6) unsigned NOT NULL default '0.000000',
  `weightuom` varchar(20) NOT NULL default '',
  `weightqty` decimal(20,6) unsigned NOT NULL default '0.000000',
  `weightloosed` decimal(20,6) unsigned NOT NULL default '0.000000',
  `totalweight` decimal(20,6) unsigned NOT NULL default '0.000000',
  `volumerate` decimal(20,6) unsigned NOT NULL default '0.000000',
  `volumeuom` varchar(20) NOT NULL default '',
  `volumeqty` decimal(20,6) unsigned NOT NULL default '0.000000',
  `volumeloosed` decimal(20,6) unsigned NOT NULL default '0.000000',
  `totalvolume` decimal(20,6) unsigned NOT NULL default '0.000000',
  `supplypurchase` enum('None','Supply','Purchase') NOT NULL default 'None',
  `taxsubtract` enum('Y','N') NOT NULL default 'N',
  `taxableamount` decimal(20,2) NOT NULL default '0.00',
  `taxablelocalamount` decimal(20,2) NOT NULL default '0.00',
  `amountaftertaxsubtract` decimal(20,2) NOT NULL default '0.00',
  `localamountaftertaxsubtract` decimal(20,2) NOT NULL default '0.00',
  `salestaxlocalamount` decimal(20,2) NOT NULL default '0.00',
  `taxadjustment` decimal(20,2) NOT NULL default '0.00',
  `taxlocaladjustment` decimal(20,2) NOT NULL default '0.00',
  `taxtotalamount` decimal(20,2) NOT NULL default '0.00',
  `taxtotallocalamount` decimal(20,2) NOT NULL default '0.00',
  `stockpackagesupplypurchase` enum('None','Supply','Purchase') NOT NULL default 'None',
  `stockpackagetaxsubtract` enum('Y','N') NOT NULL default 'N',
  `stockpackagetaxableamount` decimal(20,2) NOT NULL default '0.00',
  `stockpackagetaxablelocalamount` decimal(20,2) NOT NULL default '0.00',
  `stockpackageamountaftertaxsubtract` decimal(20,2) NOT NULL default '0.00',
  `stockpackagelocalamountaftertaxsubtract` decimal(20,2) NOT NULL default '0.00',
  `stockpackagesalestaxlocalamount` decimal(20,2) NOT NULL default '0.00',
  `stockpackagetaxadjustment` decimal(20,2) NOT NULL default '0.00',
  `stockpackagetaxlocaladjustment` decimal(20,2) NOT NULL default '0.00',
  `stockpackagetaxtotalamount` decimal(20,2) NOT NULL default '0.00',
  `stockpackagetaxtotallocalamount` decimal(20,2) NOT NULL default '0.00',
  PRIMARY KEY  (`salesmemokey`,`pos`),
  UNIQUE KEY `ismikeyid` (`salesmemokey`,`id`),
  KEY `ismicode` (`salesmemocode`),
  KEY `ismistockcode` (`stockcode`),
  KEY `ismidepartmentcode` (`departmentcode`),
  KEY `ismistocklocationcode` (`stocklocationcode`),
  KEY `ismibarcode` (`barcode`),
  KEY `ismifoc` (`foc`),
  KEY `ismistockpackagecode` (`stockpackagecode`),
  KEY `ismistockpackageid` (`stockpackageid`),
  KEY `ismibatchno` (`batchno`),
  KEY `ismijobcode` (`jobcode`),
  KEY `ismigsttypecode` (`gsttypecode`),
  KEY `ismistockpackagegsttypecode` (`stockpackagegsttypecode`)
) ENGINE=INNODB DEFAULT CHARSET=latin1;

CREATE TABLE `salesorder` (
  `salesorderkey` int(11) unsigned NOT NULL auto_increment,
  `salesordercode` varchar(20) NOT NULL default '',
  `salesorderdate` date default NULL,
  `debtorcode` varchar(20) NOT NULL default '',
  `termcode` varchar(20) NOT NULL default '',
  `staffcode` varchar(20) NOT NULL default '',
  `areacode` varchar(20) NOT NULL default '',
  `descr` varchar(200) NOT NULL default '',
  `validity` varchar(100) NOT NULL default '',
  `deliveryterm` varchar(100) NOT NULL default '',
  `refno` varchar(20) NOT NULL default '',
  `address1` varchar(200) NOT NULL default '',
  `address2` varchar(200) NOT NULL default '',
  `address3` varchar(200) NOT NULL default '',
  `address4` varchar(200) NOT NULL default '',
  `city` varchar(50) NOT NULL default '',
  `postalcode` varchar(10) NOT NULL default '',
  `state` varchar(50) NOT NULL default '',
  `countrycode` varchar(50) NOT NULL default '',
  `attention` varchar(200) NOT NULL default '',
  `phone` varchar(30) NOT NULL default '',
  `fax` varchar(30) NOT NULL default '',
  `deliverydate` date default NULL,
  `discountamount` decimal(20,2) NOT NULL,
  `amountbeforediscount` decimal(20,2) NOT NULL,
  `amount` decimal(20,2) NOT NULL default '0.00',
  `taxamount` decimal(20,2) NOT NULL default '0.00',
  `amountaftertax` decimal(20,2) NOT NULL default '0.00',
  `totaldepositamount` decimal(20,2) NOT NULL default '0.00',
  `note` mediumtext,
  `remark1` varchar(100) NOT NULL,
  `remark2` varchar(100) NOT NULL,
  `remark3` varchar(100) NOT NULL,
  `remark4` varchar(100) NOT NULL,
  `remark5` varchar(100) NOT NULL,
  `remark6` varchar(100) NOT NULL,
  `remark7` varchar(100) NOT NULL,
  `remark8` varchar(100) NOT NULL,
  `globaldepartment` enum('Y','N') NOT NULL default 'Y',
  `departmentcode` varchar(20) NOT NULL default '',
  `globaljob` enum('Y','N') NOT NULL default 'N',
  `jobcode` varchar(20) NOT NULL default '',
  `globalstocklocation` enum('Y','N') NOT NULL default 'Y',
  `stocklocationcode` varchar(20) NOT NULL default '',
  `closed` enum('Y','N') NOT NULL default 'N',
  `cancelled` enum('Y','N') NOT NULL default 'N',
  `itemformatkey` int(10) unsigned NOT NULL default '0',
  `created` datetime default NULL,
  `modified` datetime default NULL,
  `done` enum('Y','N') NOT NULL default 'N',
  `branchcode` varchar(20) NOT NULL default '',
  `branchname` varchar(200) NOT NULL default '',
  `docontactperson` varchar(200) NOT NULL default '',
  `dophone` varchar(30) NOT NULL default '',
  `dofax` varchar(30) NOT NULL default '',
  `doemail` varchar(200) NOT NULL default '',
  `doaddress1` varchar(200) NOT NULL default '',
  `doaddress2` varchar(200) NOT NULL default '',
  `doaddress3` varchar(200) NOT NULL default '',
  `doaddress4` varchar(200) NOT NULL default '',
  `docity` varchar(50) NOT NULL default '',
  `dopostalcode` varchar(10) NOT NULL default '',
  `dostate` varchar(50) NOT NULL default '',
  `docountrycode` varchar(50) NOT NULL default '',
  `transactioncost` enum('Y','N') NOT NULL default 'N',
  `depositjournalkey` int(11) unsigned default NULL,
  `deposittype1` enum('','Cash','Credit Card','Cheque') NOT NULL default '',
  `depositrefno1` varchar(20) NOT NULL default '',
  `depositdesc1` varchar(200) NOT NULL default '',
  `depositamount1` decimal(20,2) NOT NULL default '0.00',
  `localdepositamount1` decimal(20,2) NOT NULL default '0.00',
  `depositcode1` varchar(20) NOT NULL default '',
  `deposittype2` enum('','Cash','Credit Card','Cheque') NOT NULL default '',
  `depositrefno2` varchar(20) NOT NULL default '',
  `depositdesc2` varchar(200) NOT NULL default '',
  `depositamount2` decimal(20,2) NOT NULL default '0.00',
  `localdepositamount2` decimal(20,2) NOT NULL default '0.00',
  `depositcode2` varchar(20) NOT NULL default '',
  `deposittype3` enum('','Cash','Credit Card','Cheque') NOT NULL default '',
  `depositrefno3` varchar(20) NOT NULL default '',
  `depositdesc3` varchar(200) NOT NULL default '',
  `depositamount3` decimal(20,2) NOT NULL default '0.00',
  `localdepositamount3` decimal(20,2) NOT NULL default '0.00',
  `depositcode3` varchar(20) NOT NULL default '',
  `curcode` varchar(20) NOT NULL,
  `currate` decimal(20,8) unsigned NOT NULL default '1.00000000',
  `localdiscountamount` decimal(20,2) NOT NULL,
  `localamountbeforediscount` decimal(20,2) NOT NULL,
  `localamount` decimal(20,2) NOT NULL default '0.00',
  `localtaxamount` decimal(20,2) NOT NULL default '0.00',
  `localamountaftertax` decimal(20,2) NOT NULL default '0.00',
  `localtotaldepositamount` decimal(20,2) NOT NULL default '0.00',
  `ref1` varchar(30) NOT NULL,
  `ref2` varchar(30) NOT NULL,
  `ref3` varchar(30) NOT NULL,
  `ref4` varchar(30) NOT NULL,
  `cashreceiptdepositkey` int(11) unsigned NOT NULL default '0',
  `lastmodified` timestamp NOT NULL default CURRENT_TIMESTAMP on update CURRENT_TIMESTAMP,
  `collectionplancode` varchar(20) NOT NULL default '',
  `salesleadkey` int(10) unsigned NOT NULL default '0',
  `approval` enum('Y','N') NOT NULL default 'N',
  `approvalby` varchar(20) NOT NULL,
  `approvaldatetime` datetime default NULL,
  `approvalremark` mediumtext,
  `debtorname` varchar(200) NOT NULL default '',
  `totaldeposittaxamount` decimal(20,2) NOT NULL default '0.00',
  `localtotaldeposittaxamount` decimal(20,2) NOT NULL default '0.00',
  `depositmaxtaxpercentage` decimal(20,2) default NULL,
  `fromoldversion` enum('Y','N') NOT NULL default 'N',
  PRIMARY KEY  (`salesorderkey`),
  UNIQUE KEY `isocode` (`salesordercode`),
  KEY `isodate` (`salesorderdate`),
  KEY `isodebtorcode` (`debtorcode`),
  KEY `isotermcode` (`termcode`),
  KEY `isostaffcode` (`staffcode`),
  KEY `isorefno` (`refno`),
  KEY `isodepartmentcode` (`departmentcode`),
  KEY `isostocklocationcode` (`stocklocationcode`),
  KEY `isoclosed` (`closed`),
  KEY `isoareacode` (`areacode`),
  KEY `isocurcode` (`curcode`),
  KEY `isodeliverydate` (`deliverydate`),
  KEY `isodepositcode1` (`depositcode1`),
  KEY `isodepositcode2` (`depositcode2`),
  KEY `isodepositcode3` (`depositcode3`),
  KEY `isocancelled` (`cancelled`),
  KEY `isojobcode` (`jobcode`),
  KEY `isocollectionplancode` (`collectionplancode`),
  KEY `isosalesleadkey` (`salesleadkey`),
  KEY `isoapproval` (`approval`),
  KEY `isocountrycode` (`countrycode`),
  KEY `isodocountrycode` (`docountrycode`)
) ENGINE=INNODB DEFAULT CHARSET=latin1;

CREATE TABLE `salesorderdeposit` (
	`salesorderdepositkey` int(11) unsigned NOT NULL auto_increment,
	`salesorderkey` int(11) unsigned NOT NULL default '0',
  `totaldepositamount` decimal(20,2) NOT NULL default '0.00',
  `totallocaldepositamount` decimal(20,2) NOT NULL default '0.00',
  `liabilityacccode` varchar(20) NOT NULL default '',
  `gsttypecode` varchar(20) NOT NULL default '',
  `supplypurchase` enum('None','Supply','Purchase') NOT NULL default 'None',
  `taxpercentage` decimal(20,2) default NULL,
  `taxacccode` varchar(20) NOT NULL default '',
  `taxsubtract` enum('Y','N') NOT NULL default 'N',
  `taxableamount` decimal(20,2) NOT NULL default '0.00',
  `taxablelocalamount` decimal(20,2) NOT NULL default '0.00',
  `taxamount` decimal(20,2) NOT NULL default '0.00',
  `taxlocalamount` decimal(20,2) NOT NULL default '0.00',
  `amountaftertaxsubtract` decimal(20,2) NOT NULL default '0.00',
  `localamountaftertaxsubtract` decimal(20,2) NOT NULL default '0.00',
  `refund` enum('Y','N') NOT NULL default 'N',
  `depositjournalkey` int(11) unsigned NOT NULL default '0',
  PRIMARY KEY (`salesorderdepositkey`),
  UNIQUE KEY `isodsalesorderjournalkey` (`salesorderkey`,`depositjournalkey`),
  KEY `isodliabilityacccode` (`liabilityacccode`),
  KEY `isodgsttypecode` (`gsttypecode`),
  KEY `isodtaxacccode` (`taxacccode`),
  KEY `isodrefund` (`refund`)
) ENGINE=INNODB DEFAULT CHARSET=latin1;

CREATE TABLE `salesorderdeposititem` (
	`salesorderdepositkey` int(11) unsigned NOT NULL default '0',
  `pos` int(11) unsigned NOT NULL default '0',
  `deposittype` enum('','Cash','Credit Card','Cheque','Nets Card') NOT NULL,
  `depositrefno` varchar(20) NOT NULL default '',
  `depositdesc` varchar(200) NOT NULL default '',
  `depositamount` decimal(20,2) NOT NULL default '0.00',
  `localdepositamount` decimal(20,2) NOT NULL default '0.00',
  `depositacccode` varchar(20) NOT NULL default '',
  PRIMARY KEY  (`salesorderdepositkey`,`pos`),
  KEY `isodidepositacccode` (`depositacccode`)
) ENGINE=INNODB DEFAULT CHARSET=latin1;

CREATE TABLE `salesorderid` (
  `salesorderkey` int(11) unsigned NOT NULL default '0',
  `id` int(11) unsigned NOT NULL default '0',
  PRIMARY KEY  (`salesorderkey`,`id`)
) ENGINE=INNODB DEFAULT CHARSET=latin1;

CREATE TABLE `salesorderitem` (
  `salesorderkey` int(11) unsigned NOT NULL default '0',
  `salesordercode` varchar(20) NOT NULL default '',
  `id` int(11) unsigned NOT NULL default '0',
  `pos` int(11) unsigned NOT NULL default '0',
  `itemno` varchar(10) NOT NULL default '',
  `stockcode` varchar(30) NOT NULL default '',
  `descr` varchar(200) NOT NULL default '',
  `moredescr` text,
  `qty` decimal(20,6) default NULL,
  `unitprice` decimal(20,6) default NULL,
  `uom` varchar(20) NOT NULL default '',
  `uomrate` double NOT NULL default '1',
  `qtybaseuom` decimal(20,6) NOT NULL default '0.000000',
  `unitpricebaseuom` double NOT NULL default '0',
  `discountformat` varchar(100) default NULL,
  `discountamount` decimal(20,2) default NULL,
  `amountbeforediscount` decimal(20,2) default NULL,
  `amount` decimal(20,2) default NULL,
  `gsttypecode` varchar(20) NOT NULL default '',
  `stockpackagegsttypecode` varchar(20) NOT NULL default '',
  `salestaxpercentage` decimal(20,2) default NULL,
  `salestaxamount` decimal(20,2) default NULL,
  `amountaftertax` decimal(20,2) default NULL,
  `departmentcode` varchar(20) NOT NULL default '',
  `jobcode` varchar(20) NOT NULL default '',
  `stocklocationcode` varchar(20) NOT NULL default '',
  `fromdoctype` varchar(5) NOT NULL default '',
  `fromdockey` int(11) unsigned default NULL,
  `fromdocid` int(11) unsigned default NULL,
  `fromdoccode` varchar(20) NOT NULL default '',
  `debtoritemcode` varchar(30) NOT NULL default '',
  `barcode` varchar(30) NOT NULL default '',
  `remark1` varchar(100) NOT NULL,
  `remark2` varchar(100) NOT NULL,
  `remark3` varchar(100) NOT NULL,
  `remark4` varchar(100) NOT NULL,
  `rowtype` enum('','TOTALUP','ITEMDISCOUNT','ITEMSERVICETAX','ITEMMISCCHARGES','FOOTERDISCOUNT','FOOTERSERVICETAX','FOOTERMISCCHARGES') NOT NULL,
  `foc` enum('Y','N') NOT NULL default 'N',
  `packingqty` decimal(20,6) default NULL,
  `packinguom` varchar(20) NOT NULL default '',
  `packingrate` decimal(20,6) default NULL,
  `costtype` enum('Costing Method','Manual') NOT NULL default 'Manual',
  `unitcost` decimal(20,2) NOT NULL default '0.00',
  `deliverydate` date default NULL,
  `stockpackagecode` varchar(20) NOT NULL,
  `stockpackageid` int(11) unsigned NOT NULL default '0',
  `stockpackagerate` double default NULL,
  `stockpackageqty` decimal(20,6) default NULL,
  `stockpackageunitprice` decimal(20,6) default NULL,
  `stockpackageamount` decimal(20,2) default NULL,
  `stockpackagesalestaxpercentage` decimal(20,2) default NULL,
  `stockpackagesalestaxamount` decimal(20,2) default NULL,
  `stockpackageamountaftertax` decimal(20,2) default NULL,
  `batchno` varchar(30) NOT NULL default '',
  `curcode` varchar(20) NOT NULL default '',
  `curprice` decimal(20,6) default NULL,
  `currate` decimal(20,8) unsigned default NULL,
  `recommendpricebaseuom` decimal(20,6) unsigned NOT NULL default '0.000000',
  `weightrate` decimal(20,6) unsigned NOT NULL default '0.000000',
  `weightuom` varchar(20) NOT NULL default '',
  `weightqty` decimal(20,6) unsigned NOT NULL default '0.000000',
  `weightloosed` decimal(20,6) unsigned NOT NULL default '0.000000',
  `totalweight` decimal(20,6) unsigned NOT NULL default '0.000000',
  `volumerate` decimal(20,6) unsigned NOT NULL default '0.000000',
  `volumeuom` varchar(20) NOT NULL default '',
  `volumeqty` decimal(20,6) unsigned NOT NULL default '0.000000',
  `volumeloosed` decimal(20,6) unsigned NOT NULL default '0.000000',
  `totalvolume` decimal(20,6) unsigned NOT NULL default '0.000000',
  `stockbomcode` varchar(20) NOT NULL default '',
  `supplypurchase` enum('None','Supply','Purchase') NOT NULL default 'None',
  `taxsubtract` enum('Y','N') NOT NULL default 'N',
  `taxableamount` decimal(20,2) NOT NULL default '0.00',
  `taxablelocalamount` decimal(20,2) NOT NULL default '0.00',
  `amountaftertaxsubtract` decimal(20,2) NOT NULL default '0.00',
  `localamountaftertaxsubtract` decimal(20,2) NOT NULL default '0.00',
  `salestaxlocalamount` decimal(20,2) NOT NULL default '0.00',
  `taxadjustment` decimal(20,2) NOT NULL default '0.00',
  `taxlocaladjustment` decimal(20,2) NOT NULL default '0.00',
  `taxtotalamount` decimal(20,2) NOT NULL default '0.00',
  `taxtotallocalamount` decimal(20,2) NOT NULL default '0.00',
  `stockpackagesupplypurchase` enum('None','Supply','Purchase') NOT NULL default 'None',
  `stockpackagetaxsubtract` enum('Y','N') NOT NULL default 'N',
  `stockpackagetaxableamount` decimal(20,2) NOT NULL default '0.00',
  `stockpackagetaxablelocalamount` decimal(20,2) NOT NULL default '0.00',
  `stockpackageamountaftertaxsubtract` decimal(20,2) NOT NULL default '0.00',
  `stockpackagelocalamountaftertaxsubtract` decimal(20,2) NOT NULL default '0.00',
  `stockpackagesalestaxlocalamount` decimal(20,2) NOT NULL default '0.00',
  `stockpackagetaxadjustment` decimal(20,2) NOT NULL default '0.00',
  `stockpackagetaxlocaladjustment` decimal(20,2) NOT NULL default '0.00',
  `stockpackagetaxtotalamount` decimal(20,2) NOT NULL default '0.00',
  `stockpackagetaxtotallocalamount` decimal(20,2) NOT NULL default '0.00',
  PRIMARY KEY  (`salesorderkey`,`pos`),
  UNIQUE KEY `isoikeyid` (`salesorderkey`,`id`),
  KEY `isoicode` (`salesordercode`),
  KEY `isoistockcode` (`stockcode`),
  KEY `isoidepartmentcode` (`departmentcode`),
  KEY `isoistocklocationcode` (`stocklocationcode`),
  KEY `isoibarcode` (`barcode`),
  KEY `isoifoc` (`foc`),
  KEY `isoideliverydate` (`deliverydate`),
  KEY `isoistockpackagecode` (`stockpackagecode`),
  KEY `isoistockpackageid` (`stockpackageid`),
  KEY `isoifromdoctypekeypos` (`fromdoctype`,`fromdockey`,`fromdocid`),
  KEY `isoistockbomcode` (`stockbomcode`),
  KEY `isoijobcode` (`jobcode`),
  KEY `isoigsttypecode` (`gsttypecode`),
  KEY `isoistockpackagegsttypecode` (`stockpackagegsttypecode`),
  KEY `isoibatchno` (`batchno`)
) ENGINE=INNODB DEFAULT CHARSET=latin1;

CREATE TABLE `salesteam` (
  `salesteamkey` int(11) unsigned NOT NULL auto_increment,
  `salesteamcode` varchar(20) NOT NULL default '',
  `descr` varchar(200) NOT NULL default '',
  `inactive` enum('Y','N') NOT NULL default 'N',
  `done` enum('Y','N') NOT NULL default 'N',
  `lastmodified` timestamp NOT NULL default CURRENT_TIMESTAMP on update CURRENT_TIMESTAMP,
  PRIMARY KEY  (`salesteamkey`),
  UNIQUE KEY `isteamcode` (`salesteamcode`),
  KEY `isteaminactive` (`inactive`)
) ENGINE=INNODB DEFAULT CHARSET=latin1;

CREATE TABLE `salestransferred` (
  `doctype` varchar(5) NOT NULL default '',
  `dockey` int(11) unsigned NOT NULL default '0',
  `docid` int(11) unsigned NOT NULL default '0',
  `totype` varchar(5) NOT NULL default '',
  `tokey` int(11) unsigned NOT NULL default '0',
  `toid` int(11) unsigned NOT NULL default '0',
  `touom` varchar(20) NOT NULL default '',
  `touomrate` double NOT NULL default '1',
  `toqty` decimal(20,6) NOT NULL default '0.000000',
  `toqtybaseuom` decimal(20,6) NOT NULL default '0.000000',
  PRIMARY KEY  (`doctype`,`dockey`,`docid`,`totype`,`tokey`,`toid`),
  KEY `istftotypekeyid` (`totype`,`tokey`,`toid`)
) ENGINE=INNODB DEFAULT CHARSET=latin1;

CREATE TABLE `segmentdbsetting` (
  `dbsegmentsettingkey` int(11) unsigned NOT NULL auto_increment,
  `dbdisplayname` varchar(20) NOT NULL default '',
  `dbservername` varchar(100) NOT NULL default '',
  `dbportno` int(11) unsigned NOT NULL default '0',
  `dbname` varchar(100) NOT NULL default '',
  `dbserveruser` varchar(100) NOT NULL default '',
  `dbserverpwd` blob NOT NULL,
  `done` enum('Y','N') NOT NULL default 'N',
  PRIMARY KEY  (`dbsegmentsettingkey`)
) ENGINE=INNODB DEFAULT CHARSET=latin1;

CREATE TABLE `servicecontract` (
  `servicecontractkey` int(11) unsigned NOT NULL auto_increment,
  `servicecontractcode` varchar(20) NOT NULL default '',
  `servicecontracttypecode` varchar(20) NOT NULL default '',
  `servicecontractdate` date default NULL,
  `servicecontractvalue` decimal(20,2) NOT NULL,
  `refno` varchar(20) NOT NULL default '',
  `descr` varchar(200) NOT NULL default '',
  `servicestartdate` date default NULL,
  `serviceexpirydate` date default NULL,
  `debtorcode` varchar(20) NOT NULL default '',
  `termcode` varchar(20) NOT NULL default '',
  `staffcode` varchar(20) NOT NULL default '',
  `areacode` varchar(20) NOT NULL default '',
  `address1` varchar(200) NOT NULL default '',
  `address2` varchar(200) NOT NULL default '',
  `address3` varchar(200) NOT NULL default '',
  `address4` varchar(200) NOT NULL default '',
  `city` varchar(50) NOT NULL default '',
  `postalcode` varchar(10) NOT NULL default '',
  `state` varchar(50) NOT NULL default '',
  `countrycode` varchar(50) NOT NULL default '',
  `attention` varchar(200) NOT NULL default '',
  `phone` varchar(30) NOT NULL default '',
  `fax` varchar(30) NOT NULL default '',
  `note` mediumtext,
  `remark1` varchar(100) NOT NULL,
  `remark2` varchar(100) NOT NULL,
  `remark3` varchar(100) NOT NULL,
  `remark4` varchar(100) NOT NULL,
  `remark5` varchar(100) NOT NULL,
  `remark6` varchar(100) NOT NULL,
  `remark7` varchar(100) NOT NULL,
  `remark8` varchar(100) NOT NULL,
  `inactive` enum('Y','N') NOT NULL default 'N',
  `created` datetime default NULL,
  `modified` datetime default NULL,
  `done` enum('Y','N') NOT NULL default 'N',
  `branchcode` varchar(20) NOT NULL default '',
  `branchname` varchar(200) NOT NULL default '',
  `docontactperson` varchar(200) NOT NULL default '',
  `dophone` varchar(30) NOT NULL default '',
  `dofax` varchar(30) NOT NULL default '',
  `doemail` varchar(200) NOT NULL default '',
  `doaddress1` varchar(200) NOT NULL default '',
  `doaddress2` varchar(200) NOT NULL default '',
  `doaddress3` varchar(200) NOT NULL default '',
  `doaddress4` varchar(200) NOT NULL default '',
  `docity` varchar(50) NOT NULL default '',
  `dopostalcode` varchar(10) NOT NULL default '',
  `dostate` varchar(50) NOT NULL default '',
  `docountrycode` varchar(50) NOT NULL default '',
  `curcode` varchar(20) NOT NULL,
  `currate` decimal(20,8) unsigned NOT NULL default '1.00000000',
  `ref1` varchar(30) NOT NULL,
  `ref2` varchar(30) NOT NULL,
  `ref3` varchar(30) NOT NULL,
  `ref4` varchar(30) NOT NULL,
  `itemformatkey` int(10) unsigned NOT NULL default '0',
  `lastmodified` timestamp NOT NULL default CURRENT_TIMESTAMP on update CURRENT_TIMESTAMP,
  PRIMARY KEY  (`servicecontractkey`),
  UNIQUE KEY `icssccode` (`servicecontractcode`),
  KEY `icsscdate` (`servicecontractdate`),
  KEY `icsscdebtorcode` (`debtorcode`),
  KEY `icsscservicecontracttypecode` (`servicecontracttypecode`),
  KEY `icssctermcode` (`termcode`),
  KEY `icsscstaffcode` (`staffcode`),
  KEY `icsscrefno` (`refno`),
  KEY `icsscareacode` (`areacode`),
  KEY `icssccurcode` (`curcode`),
  KEY `icsscinactive` (`inactive`),
  KEY `isccountrycode` (`countrycode`),
  KEY `iscdocountrycode` (`docountrycode`)
) ENGINE=INNODB DEFAULT CHARSET=latin1;

CREATE TABLE `servicecontractid` (
  `servicecontractkey` int(11) unsigned NOT NULL default '0',
  `id` int(11) unsigned NOT NULL default '0',
  PRIMARY KEY  (`servicecontractkey`,`id`)
) ENGINE=INNODB DEFAULT CHARSET=latin1;

CREATE TABLE `servicecontractserviceitem` (
  `servicecontractkey` int(11) unsigned NOT NULL,
  `servicecontractcode` varchar(20) NOT NULL default '',
  `pos` int(11) unsigned NOT NULL default '0',
  `serviceitemcode` varchar(20) NOT NULL default '',
  PRIMARY KEY (`servicecontractkey`,`pos`),
  KEY `scsiserviceitemcode` (`serviceitemcode`)
) ENGINE=INNODB DEFAULT CHARSET=latin1;

CREATE TABLE `servicecontractsparepart` (
  `servicecontractkey` int(11) unsigned NOT NULL,
  `servicecontractcode` varchar(20) NOT NULL default '',
  `pos` int(11) unsigned NOT NULL default '0',
  `itemno` varchar(10) NOT NULL default '',
  `itemstockcode` varchar(30) NOT NULL default '',
  `descr` varchar(200) NOT NULL default '',
  `moredescr` text,
  `unlimited` enum('Y','N') NOT NULL default 'N',
  `qty` decimal(20,6) default NULL,
  `unitprice` decimal(20,6) default NULL,
  `uom` varchar(20) NOT NULL default '',
  `uomrate` double NOT NULL default '1',
  `qtybaseuom` decimal(20,6) NOT NULL default '0.000000',
  `unitpricebaseuom` double NOT NULL default '0',
  `discountformat` varchar(100) NOT NULL,
  `discountamount` decimal(20,2) default NULL,
  `amountbeforediscount` decimal(20,2) default NULL,
  `amount` decimal(20,2) default NULL,
  `salestaxpercentage` decimal(20,2) default NULL,
  `salestaxamount` decimal(20,2) default NULL,
  `amountaftertax` decimal(20,2) default NULL,
  `id` int(11) unsigned NOT NULL default '0',
  PRIMARY KEY  (`servicecontractkey`,`pos`),
  UNIQUE KEY `iscspikeyid` USING BTREE (`servicecontractkey`,`id`),
  KEY `scspservicecontractcode` (`servicecontractcode`),
  KEY `scspitemstockcode` (`itemstockcode`)
) ENGINE=INNODB DEFAULT CHARSET=latin1;

CREATE TABLE `servicecontracttype` (
  `servicecontracttypekey` int(11) unsigned NOT NULL auto_increment,
  `servicecontracttypecode` varchar(20) NOT NULL default '',
  `descr` varchar(200) NOT NULL default '',
  `inactive` enum('Y','N') NOT NULL default 'N',
  `done` enum('Y','N') NOT NULL default 'N',
  `lastmodified` timestamp NOT NULL default CURRENT_TIMESTAMP on update CURRENT_TIMESTAMP,
  PRIMARY KEY  (`servicecontracttypekey`),
  UNIQUE KEY `icssctcode` (`servicecontracttypecode`),
  KEY `icssctinactive` (`inactive`)
) ENGINE=INNODB DEFAULT CHARSET=latin1;

CREATE TABLE `serviceitem` (
  `serviceitemkey` int(11) unsigned NOT NULL auto_increment,
  `serviceitemcode` varchar(20) NOT NULL default '',
  `stockcode` varchar(30) NOT NULL default '',
  `serviceitemgradecode` varchar(20) NOT NULL default '',
  `purchasedate` date default NULL,
  `unitprice` decimal(20,2) NOT NULL,
  `refno` varchar(20) NOT NULL default '',
  `descr` varchar(200) NOT NULL default '',
  `contractno` varchar(20) NOT NULL default '',
  `servicestartdate` date default NULL,
  `serviceexpirydate` date default NULL,
  `debtorcode` varchar(20) NOT NULL default '',
  `termcode` varchar(20) NOT NULL default '',
  `staffcode` varchar(20) NOT NULL default '',
  `areacode` varchar(20) NOT NULL default '',
  `address1` varchar(200) NOT NULL default '',
  `address2` varchar(200) NOT NULL default '',
  `address3` varchar(200) NOT NULL default '',
  `address4` varchar(200) NOT NULL default '',
  `city` varchar(50) NOT NULL default '',
  `postalcode` varchar(10) NOT NULL default '',
  `state` varchar(50) NOT NULL default '',
  `countrycode` varchar(50) NOT NULL default '',
  `attention` varchar(200) NOT NULL default '',
  `phone` varchar(30) NOT NULL default '',
  `fax` varchar(30) NOT NULL default '',
  `note` mediumtext,
  `remark1` varchar(100) NOT NULL,
  `remark2` varchar(100) NOT NULL,
  `remark3` varchar(100) NOT NULL,
  `remark4` varchar(100) NOT NULL,
  `remark5` varchar(100) NOT NULL,
  `remark6` varchar(100) NOT NULL,
  `remark7` varchar(100) NOT NULL,
  `remark8` varchar(100) NOT NULL,
  `inactive` enum('Y','N') NOT NULL default 'N',
  `created` datetime default NULL,
  `modified` datetime default NULL,
  `done` enum('Y','N') NOT NULL default 'N',
  `branchcode` varchar(20) NOT NULL default '',
  `branchname` varchar(200) NOT NULL default '',
  `docontactperson` varchar(200) NOT NULL default '',
  `dophone` varchar(30) NOT NULL default '',
  `dofax` varchar(30) NOT NULL default '',
  `doemail` varchar(200) NOT NULL default '',
  `doaddress1` varchar(200) NOT NULL default '',
  `doaddress2` varchar(200) NOT NULL default '',
  `doaddress3` varchar(200) NOT NULL default '',
  `doaddress4` varchar(200) NOT NULL default '',
  `docity` varchar(50) NOT NULL default '',
  `dopostalcode` varchar(10) NOT NULL default '',
  `dostate` varchar(50) NOT NULL default '',
  `docountrycode` varchar(50) NOT NULL default '',
  `curcode` varchar(20) NOT NULL,
  `currate` decimal(20,8) unsigned NOT NULL default '1.00000000',
  `ref1` varchar(30) NOT NULL,
  `ref2` varchar(30) NOT NULL,
  `ref3` varchar(30) NOT NULL,
  `ref4` varchar(30) NOT NULL,
  `pmintervaltype` enum('NONE','DAILY','WEEKLY','MONTHLY','YEARLY') NOT NULL default 'NONE',
  `pmintervalvalue` int(11) unsigned default '0',
  `pmstartdate` date default NULL,
  `pmlastservicedate` date default NULL,
  `pmactive` enum('Y','N') NOT NULL default 'N',
  `departmentcode` varchar(20) NOT NULL default '',
  `jobcode` varchar(20) NOT NULL default '',
  `stocklocationcode` varchar(20) NOT NULL default '',
  `lastmodified` timestamp NOT NULL default CURRENT_TIMESTAMP on update CURRENT_TIMESTAMP,
  PRIMARY KEY  (`serviceitemkey`),
  UNIQUE KEY `icssicode` (`serviceitemcode`),
  KEY `icssidate` (`purchasedate`),
  KEY `icssistockcode` (`stockcode`),
  KEY `icssidebtorcode` (`debtorcode`),
  KEY `icssicontractno` (`contractno`),
  KEY `icssiserviceitemgradecode` (`serviceitemgradecode`),
  KEY `icssitermcode` (`termcode`),
  KEY `icssistaffcode` (`staffcode`),
  KEY `icssirefno` (`refno`),
  KEY `icssiareacode` (`areacode`),
  KEY `icssicurcode` (`curcode`),
  KEY `icssiinactive` (`inactive`),
  KEY `icssipmactive` (`pmactive`),
  KEY `icssidepartmentcode` (`departmentcode`),
  KEY `icssistocklocationcode` (`stocklocationcode`),
  KEY `icssijobcode` (`jobcode`),
  KEY `isicountrycode` (`countrycode`),
  KEY `isidocountrycode` (`docountrycode`)
) ENGINE=INNODB DEFAULT CHARSET=latin1;

CREATE TABLE `serviceitemdebtorhistory` (
  `serviceitemdebtorhistorykey` int(11) unsigned NOT NULL auto_increment,
  `serviceitemcode` varchar(20) NOT NULL default '',
  `serviceitemgradecode` varchar(20) NOT NULL default '',
  `refno` varchar(20) NOT NULL default '',
  `descr` varchar(200) NOT NULL default '',
  `contractno` varchar(20) NOT NULL default '',
  `servicestartdate` date default NULL,
  `serviceexpirydate` date default NULL,
  `debtorcode` varchar(20) NOT NULL default '',
  `termcode` varchar(20) NOT NULL default '',
  `staffcode` varchar(20) NOT NULL default '',
  `areacode` varchar(20) NOT NULL default '',
  `address1` varchar(200) NOT NULL default '',
  `address2` varchar(200) NOT NULL default '',
  `address3` varchar(200) NOT NULL default '',
  `address4` varchar(200) NOT NULL default '',
  `city` varchar(50) NOT NULL default '',
  `postalcode` varchar(10) NOT NULL default '',
  `state` varchar(50) NOT NULL default '',
  `countrycode` varchar(50) NOT NULL default '',
  `attention` varchar(200) NOT NULL default '',
  `phone` varchar(30) NOT NULL default '',
  `fax` varchar(30) NOT NULL default '',
  `branchcode` varchar(20) NOT NULL default '',
  `branchname` varchar(200) NOT NULL default '',
  `docontactperson` varchar(200) NOT NULL default '',
  `dophone` varchar(30) NOT NULL default '',
  `dofax` varchar(30) NOT NULL default '',
  `doemail` varchar(200) NOT NULL default '',
  `doaddress1` varchar(200) NOT NULL default '',
  `doaddress2` varchar(200) NOT NULL default '',
  `doaddress3` varchar(200) NOT NULL default '',
  `doaddress4` varchar(200) NOT NULL default '',
  `docity` varchar(50) NOT NULL default '',
  `dopostalcode` varchar(10) NOT NULL default '',
  `dostate` varchar(50) NOT NULL default '',
  `docountrycode` varchar(50) NOT NULL default '',
  `curcode` varchar(20) NOT NULL,
  `currate` decimal(20,8) unsigned NOT NULL default '1.00000000',
  `ref1` varchar(30) NOT NULL,
  `ref2` varchar(30) NOT NULL,
  `ref3` varchar(30) NOT NULL,
  `ref4` varchar(30) NOT NULL,
  `pmintervaltype` enum('NONE','DAILY','WEEKLY','MONTHLY','YEARLY') NOT NULL default 'NONE',
  `pmintervalvalue` int(11) unsigned default '0',
  `pmstartdate` date default NULL,
  `pmlastservicedate` date default NULL,
  `pmactive` enum('Y','N') NOT NULL default 'N',
  `resetusercode` varchar(20) NOT NULL default '',
  `resetdate` date default NULL,
  `resetremark` varchar(200) NOT NULL default '',
  PRIMARY KEY  (`serviceitemdebtorhistorykey`),
  KEY `iocssidebtorcode` (`debtorcode`),
  KEY `iocssicontractno` (`contractno`),
  KEY `iocssiserviceitemgradecode` (`serviceitemgradecode`),
  KEY `iocssitermcode` (`termcode`),
  KEY `iocssistaffcode` (`staffcode`),
  KEY `iocssirefno` (`refno`),
  KEY `iocssiareacode` (`areacode`),
  KEY `iocssicurcode` (`curcode`),
  KEY `isidhcountrycode` (`countrycode`),
  KEY `isidhdocountrycode` (`docountrycode`)
) ENGINE=INNODB DEFAULT CHARSET=latin1;

CREATE TABLE `serviceitemgrade` (
  `serviceitemgradekey` int(11) unsigned NOT NULL auto_increment,
  `serviceitemgradecode` varchar(20) NOT NULL default '',
  `descr` varchar(200) NOT NULL default '',
  `inactive` enum('Y','N') NOT NULL default 'N',
  `done` enum('Y','N') NOT NULL default 'N',
  `lastmodified` timestamp NOT NULL default CURRENT_TIMESTAMP on update CURRENT_TIMESTAMP,
  PRIMARY KEY  (`serviceitemgradekey`),
  UNIQUE KEY `icssigcode` (`serviceitemgradecode`),
  KEY `icssiginactive` (`inactive`)
) ENGINE=INNODB DEFAULT CHARSET=latin1;

CREATE TABLE `serviceitemmetertype` (
  `serviceitemmetertypekey` int(11) unsigned NOT NULL auto_increment,
  `serviceitemkey` int(11) unsigned NOT NULL,
  `metertypecode` varchar(20) NOT NULL default '',
  `minimumcharges` decimal(20,2) NOT NULL default '0.00',
  `chargesrate` decimal(20,6) NOT NULL default '0.000000',
  `metermultipricecode` varchar(20) NOT NULL default '',
  `rebateqtyinpercent` decimal(20,2) NOT NULL default '0.00',
  `focqty` decimal(20,2) NOT NULL default '0.00',
  `initialreading` decimal(20,2) NOT NULL default '0.00',
  PRIMARY KEY  (`serviceitemmetertypekey`),
  UNIQUE KEY `isimtcode` (`serviceitemmetertypekey`,`serviceitemkey`,`metertypecode`),
  KEY `isimtmetertypecode` (`metertypecode`)
) ENGINE=INNODB DEFAULT CHARSET=latin1;

CREATE TABLE `serviceitemmetertrans` (
  `serviceitemmetertranskey` int(11) unsigned NOT NULL auto_increment,
  `serviceitemmetertypekey` int(11) unsigned NOT NULL,
  `metertransdate` datetime default NULL,
  `metertransreading` decimal(20,2) NOT NULL default '0.00',
  `salesinvoicekey` int(11) unsigned NOT NULL,
  PRIMARY KEY  (`serviceitemmetertranskey`),
  UNIQUE KEY `isimtcode` (`serviceitemmetertranskey`, `serviceitemmetertypekey`)
) ENGINE=INNODB DEFAULT CHARSET=latin1;

CREATE TABLE `servicenote` (
  `servicenotekey` int(11) unsigned NOT NULL auto_increment,
  `servicenotecode` varchar(20) NOT NULL default '',
  `servicenotedate` datetime default NULL,
  `servicestatuscode` varchar(20) NOT NULL default '',
  `serviceitemcode` varchar(20) NOT NULL default '',
  `servicestartdate` date default NULL,
  `serviceexpirydate` date default NULL,
  `contractno` varchar(20) NOT NULL default '',
  `servicetypecode` varchar(20) NOT NULL default '',
  `serviceseveritycode` varchar(20) NOT NULL default '',
  `serviceproblemcode` varchar(20) NOT NULL default '',
  `serviceproblemremark` mediumtext,
  `servicesolutioncode` varchar(20) NOT NULL default '',
  `servicesolutionremark` mediumtext,
  `attendedservicepersoncode` varchar(50) NOT NULL default '',
  `assigntoservicepersoncode` varchar(50) NOT NULL default '',
  `debtorcode` varchar(20) NOT NULL default '',
  `debtorname` varchar(200) NOT NULL default '',
  `termcode` varchar(20) NOT NULL default '',
  `staffcode` varchar(20) NOT NULL default '',
  `areacode` varchar(20) NOT NULL default '',
  `descr` varchar(200) NOT NULL default '',
  `validity` varchar(100) NOT NULL default '',
  `deliveryterm` varchar(100) NOT NULL default '',
  `refno` varchar(20) NOT NULL default '',
  `address1` varchar(200) NOT NULL default '',
  `address2` varchar(200) NOT NULL default '',
  `address3` varchar(200) NOT NULL default '',
  `address4` varchar(200) NOT NULL default '',
  `city` varchar(50) NOT NULL default '',
  `postalcode` varchar(10) NOT NULL default '',
  `state` varchar(50) NOT NULL default '',
  `countrycode` varchar(50) NOT NULL default '',
  `attention` varchar(200) NOT NULL default '',
  `phone` varchar(30) NOT NULL default '',
  `fax` varchar(30) NOT NULL default '',
  `discountamount` decimal(20,2) NOT NULL,
  `amountbeforediscount` decimal(20,2) NOT NULL,
  `amount` decimal(20,2) NOT NULL default '0.00',
  `taxamount` decimal(20,2) NOT NULL default '0.00',
  `amountaftertax` decimal(20,2) NOT NULL default '0.00',
  `note` mediumtext,
  `remark1` varchar(100) NOT NULL,
  `remark2` varchar(100) NOT NULL,
  `remark3` varchar(100) NOT NULL,
  `remark4` varchar(100) NOT NULL,
  `remark5` varchar(100) NOT NULL,
  `remark6` varchar(100) NOT NULL,
  `remark7` varchar(100) NOT NULL,
  `remark8` varchar(100) NOT NULL,
  `globaldepartment` enum('Y','N') NOT NULL default 'Y',
  `departmentcode` varchar(20) NOT NULL default '',
  `globaljob` enum('Y','N') NOT NULL default 'N',
  `jobcode` varchar(20) NOT NULL default '',
  `globalstocklocation` enum('Y','N') NOT NULL default 'Y',
  `stocklocationcode` varchar(20) NOT NULL default '',
  `appointmentdate` datetime default NULL,
  `actualservicedate` datetime default NULL,
  `collectiondate` datetime default NULL,
  `closed` enum('Y','N') NOT NULL default 'N',
  `closeddate` datetime default NULL,
  `itemformatkey` int(10) unsigned NOT NULL default '0',
  `created` datetime default NULL,
  `modified` datetime default NULL,
  `done` enum('Y','N') NOT NULL default 'N',
  `branchcode` varchar(20) NOT NULL default '',
  `branchname` varchar(200) NOT NULL default '',
  `docontactperson` varchar(200) NOT NULL default '',
  `dophone` varchar(30) NOT NULL default '',
  `dofax` varchar(30) NOT NULL default '',
  `doemail` varchar(200) NOT NULL default '',
  `doaddress1` varchar(200) NOT NULL default '',
  `doaddress2` varchar(200) NOT NULL default '',
  `doaddress3` varchar(200) NOT NULL default '',
  `doaddress4` varchar(200) NOT NULL default '',
  `docity` varchar(50) NOT NULL default '',
  `dopostalcode` varchar(10) NOT NULL default '',
  `dostate` varchar(50) NOT NULL default '',
  `docountrycode` varchar(50) NOT NULL default '',
  `curcode` varchar(20) NOT NULL,
  `currate` decimal(20,8) unsigned NOT NULL default '1.00000000',
  `localdiscountamount` decimal(20,2) NOT NULL,
  `localamountbeforediscount` decimal(20,2) NOT NULL,
  `localamount` decimal(20,2) NOT NULL default '0.00',
  `localtaxamount` decimal(20,2) NOT NULL default '0.00',
  `localamountaftertax` decimal(20,2) NOT NULL default '0.00',
  `ref1` varchar(30) NOT NULL,
  `ref2` varchar(30) NOT NULL,
  `ref3` varchar(30) NOT NULL,
  `ref4` varchar(30) NOT NULL,
  `stockcode` varchar(30) NOT NULL default '',
  `stockdescr` varchar(200) NOT NULL default '',
  `fromdoctype` varchar(5) NOT NULL default '',
  `fromdockey` int(11) unsigned default NULL,
  `fromdocid` int(11) unsigned default NULL,
  `fromdoccode` varchar(20) NOT NULL default '',
  `salesinvoicekey` int(11) unsigned default NULL,
  `salesleadkey` int(10) unsigned NOT NULL default '0',
  PRIMARY KEY  (`servicenotekey`),
  UNIQUE KEY `isncode` (`servicenotecode`),
  KEY `isndate` (`servicenotedate`),
  KEY `isndebtorcode` (`debtorcode`),
  KEY `isntermcode` (`termcode`),
  KEY `isnstaffcode` (`staffcode`),
  KEY `isnrefno` (`refno`),
  KEY `isndepartmentcode` (`departmentcode`),
  KEY `isnstocklocationcode` (`stocklocationcode`),
  KEY `isnareacode` (`areacode`),
  KEY `isncurcode` (`curcode`),
  KEY `isnclosed` (`closed`),
  KEY `isnservicestatuscode` (`servicestatuscode`),
  KEY `isnserviceitemcode` (`serviceitemcode`),
  KEY `isncontractno` (`contractno`),
  KEY `isnservicetypecode` (`servicetypecode`),
  KEY `isnserviceseveritycode` (`serviceseveritycode`),
  KEY `isnserviceproblemcode` (`serviceproblemcode`),
  KEY `isnservicesolutioncode` (`servicesolutioncode`),
  KEY `isnattendedservicepersoncode` (`attendedservicepersoncode`),
  KEY `isnassigntoservicepersoncode` (`assigntoservicepersoncode`),
  KEY `isnstockcode` (`stockcode`),
  KEY `isnjobcode` (`jobcode`),
  KEY `isnfromdoctypekeyid` (`fromdoctype`,`fromdockey`,`fromdocid`),
  KEY `isncountrycode` (`countrycode`),
  KEY `isndocountrycode` (`docountrycode`)
) ENGINE=INNODB DEFAULT CHARSET=latin1;

CREATE TABLE `servicenoteid` (
  `servicenotekey` int(11) unsigned NOT NULL default '0',
  `id` int(11) unsigned NOT NULL default '0',
  PRIMARY KEY  (`servicenotekey`,`id`)
) ENGINE=INNODB DEFAULT CHARSET=latin1;

CREATE TABLE `servicenoteitem` (
  `servicenotekey` int(11) unsigned NOT NULL default '0',
  `servicenotecode` varchar(20) NOT NULL default '',
  `id` int(11) unsigned NOT NULL default '0',
  `pos` int(11) unsigned NOT NULL default '0',
  `itemno` varchar(10) NOT NULL default '',
  `stockcode` varchar(30) NOT NULL default '',
  `descr` varchar(200) NOT NULL default '',
  `moredescr` text,
  `qty` decimal(20,6) default NULL,
  `unitprice` decimal(20,6) default NULL,
  `uom` varchar(20) NOT NULL default '',
  `uomrate` double NOT NULL default '1',
  `qtybaseuom` decimal(20,6) NOT NULL default '0.000000',
  `unitpricebaseuom` double NOT NULL default '0',
  `discountformat` varchar(100) NOT NULL,
  `discountamount` decimal(20,2) default NULL,
  `amountbeforediscount` decimal(20,2) default NULL,
  `amount` decimal(20,2) default NULL,
  `salestaxpercentage` decimal(20,2) default NULL,
  `salestaxamount` decimal(20,2) default NULL,
  `amountaftertax` decimal(20,2) default NULL,
  `departmentcode` varchar(20) NOT NULL default '',
  `jobcode` varchar(20) NOT NULL default '',
  `stocklocationcode` varchar(20) NOT NULL default '',
  `debtoritemcode` varchar(30) NOT NULL default '',
  `barcode` varchar(30) NOT NULL default '',
  `remark1` varchar(100) NOT NULL,
  `remark2` varchar(100) NOT NULL,
  `remark3` varchar(100) NOT NULL,
  `remark4` varchar(100) NOT NULL,
  `rowtype` enum('','TOTALUP','ITEMDISCOUNT','ITEMSERVICETAX','ITEMMISCCHARGES','FOOTERDISCOUNT','FOOTERSERVICETAX','FOOTERMISCCHARGES') NOT NULL,
  `foc` enum('Y','N') NOT NULL default 'N',
  `packingqty` decimal(20,6) default NULL,
  `packinguom` varchar(20) NOT NULL default '',
  `packingrate` decimal(20,6) default NULL,
  `curcode` varchar(20) NOT NULL default '',
  `curprice` decimal(20,6) default NULL,
  `currate` decimal(20,8) unsigned default NULL,
  `contractitemid` int(11) unsigned default NULL,
  `contract` enum('Y','N') NOT NULL default 'N',
  `gsttypecode` varchar(20) NOT NULL default '',
  `supplypurchase` enum('None','Supply','Purchase') NOT NULL default 'None',
  `taxsubtract` enum('Y','N') NOT NULL default 'N',
  `taxableamount` decimal(20,2) NOT NULL default '0.00',
  `taxablelocalamount` decimal(20,2) NOT NULL default '0.00',
  `amountaftertaxsubtract` decimal(20,2) NOT NULL default '0.00',
  `localamountaftertaxsubtract` decimal(20,2) NOT NULL default '0.00',
  `salestaxlocalamount` decimal(20,2) NOT NULL default '0.00',
  `taxadjustment` decimal(20,2) NOT NULL default '0.00',
  `taxlocaladjustment` decimal(20,2) NOT NULL default '0.00',
  `taxtotalamount` decimal(20,2) NOT NULL default '0.00',
  `taxtotallocalamount` decimal(20,2) NOT NULL default '0.00',
  PRIMARY KEY  (`servicenotekey`,`pos`),
  UNIQUE KEY `isnikeyid` (`servicenotekey`,`id`),
  KEY `isnicode` (`servicenotecode`),
  KEY `isnistockcode` (`stockcode`),
  KEY `isnidepartmentcode` (`departmentcode`),
  KEY `isnistocklocationcode` (`stocklocationcode`),
  KEY `isnibarcode` (`barcode`),
  KEY `isnifoc` (`foc`),
  KEY `isnicontractitemid` (`contractitemid`),
  KEY `isnijobcode` (`jobcode`),
  KEY `isnigsttypecode` (`gsttypecode`)
) ENGINE=INNODB DEFAULT CHARSET=latin1;

CREATE TABLE `serviceperson` (
  `servicepersonkey` int(11) unsigned NOT NULL auto_increment,
  `servicepersoncode` varchar(50) NOT NULL default '',
  `name` varchar(200) NOT NULL default '',
  `name2` varchar(200) NOT NULL default '',
  `gender` enum('MALE','FEMALE','UNKNOW') NOT NULL default 'UNKNOW',
  `dob` date default NULL,
  `photo` mediumblob,
  `address1` varchar(200) NOT NULL default '',
  `address2` varchar(200) NOT NULL default '',
  `address3` varchar(200) NOT NULL default '',
  `address4` varchar(200) NOT NULL default '',
  `phone` varchar(30) NOT NULL default '',
  `phone2` varchar(30) NOT NULL default '',
  `email` varchar(200) NOT NULL default '',
  `icno` varchar(30) NOT NULL default '',
  `occupation` varchar(30) NOT NULL default '',
  `datejoined` date default NULL,
  `dateleft` date default NULL,
  `note` mediumtext,
  `inactive` enum('Y','N') NOT NULL default 'N',
  `done` enum('Y','N') NOT NULL default 'N',
  `lastmodified` timestamp NOT NULL default CURRENT_TIMESTAMP on update CURRENT_TIMESTAMP,
  PRIMARY KEY  (`servicepersonkey`),
  UNIQUE KEY `ispcode` (`servicepersoncode`),
  KEY `ispicno` (`icno`),
  KEY `ispinactive` (`inactive`)
) ENGINE=INNODB DEFAULT CHARSET=latin1;

CREATE TABLE `serviceproblem` (
  `serviceproblemkey` int(11) unsigned NOT NULL auto_increment,
  `serviceproblemcode` varchar(20) NOT NULL default '',
  `descr` varchar(200) NOT NULL default '',
  `inactive` enum('Y','N') NOT NULL default 'N',
  `done` enum('Y','N') NOT NULL default 'N',
  `lastmodified` timestamp NOT NULL default CURRENT_TIMESTAMP on update CURRENT_TIMESTAMP,
  PRIMARY KEY  (`serviceproblemkey`),
  UNIQUE KEY `icsspcode` (`serviceproblemcode`),
  KEY `icsspinactive` (`inactive`)
) ENGINE=INNODB DEFAULT CHARSET=latin1;

CREATE TABLE `serviceseverity` (
  `serviceseveritykey` int(11) unsigned NOT NULL auto_increment,
  `serviceseveritycode` varchar(20) NOT NULL default '',
  `descr` varchar(200) NOT NULL default '',
  `inactive` enum('Y','N') NOT NULL default 'N',
  `done` enum('Y','N') NOT NULL default 'N',
  `lastmodified` timestamp NOT NULL default CURRENT_TIMESTAMP on update CURRENT_TIMESTAMP,
  PRIMARY KEY  (`serviceseveritykey`),
  UNIQUE KEY `icssscode` (`serviceseveritycode`),
  KEY `icsssinactive` (`inactive`)
) ENGINE=INNODB DEFAULT CHARSET=latin1;

CREATE TABLE `servicesolution` (
  `servicesolutionkey` int(11) unsigned NOT NULL auto_increment,
  `servicesolutioncode` varchar(20) NOT NULL default '',
  `descr` varchar(200) NOT NULL default '',
  `inactive` enum('Y','N') NOT NULL default 'N',
  `done` enum('Y','N') NOT NULL default 'N',
  `lastmodified` timestamp NOT NULL default CURRENT_TIMESTAMP on update CURRENT_TIMESTAMP,
  PRIMARY KEY  (`servicesolutionkey`),
  UNIQUE KEY `icssopcode` (`servicesolutioncode`),
  KEY `icssopinactive` (`inactive`)
) ENGINE=INNODB DEFAULT CHARSET=latin1;

CREATE TABLE `servicestatus` (
  `servicestatuskey` int(11) unsigned NOT NULL auto_increment,
  `servicestatuscode` varchar(20) NOT NULL default '',
  `servicestatustype` enum('New','In Progress','Closed') NOT NULL default 'New',
  `descr` varchar(200) NOT NULL default '',
  `inactive` enum('Y','N') NOT NULL default 'N',
  `done` enum('Y','N') NOT NULL default 'N',
  `lastmodified` timestamp NOT NULL default CURRENT_TIMESTAMP on update CURRENT_TIMESTAMP,
  PRIMARY KEY  (`servicestatuskey`),
  UNIQUE KEY `icssstcode` (`servicestatuscode`),
  KEY `icssstinactive` (`inactive`)
) ENGINE=INNODB DEFAULT CHARSET=latin1;

CREATE TABLE `servicetype` (
  `servicetypekey` int(11) unsigned NOT NULL auto_increment,
  `servicetypecode` varchar(20) NOT NULL default '',
  `descr` varchar(200) NOT NULL default '',
  `inactive` enum('Y','N') NOT NULL default 'N',
  `done` enum('Y','N') NOT NULL default 'N',
  `lastmodified` timestamp NOT NULL default CURRENT_TIMESTAMP on update CURRENT_TIMESTAMP,
  PRIMARY KEY  (`servicetypekey`),
  UNIQUE KEY `icstpcode` (`servicetypecode`),
  KEY `icstpinactive` (`inactive`)
) ENGINE=INNODB DEFAULT CHARSET=latin1;

CREATE TABLE `shipmenttype` (
  `shipmenttypekey` int(11) unsigned NOT NULL auto_increment,
  `shipmenttypecode` varchar(20) NOT NULL default '',
  `descr` varchar(200) NOT NULL default '',
  `inactive` enum('Y','N') NOT NULL default 'N',
  `done` enum('Y','N') NOT NULL default 'N',
  PRIMARY KEY  (`shipmenttypekey`),
  UNIQUE KEY `ishtscode` (`shipmenttypecode`),
  KEY `ishtinactive` (`inactive`)
) ENGINE=INNODB DEFAULT CHARSET=latin1;

CREATE TABLE `shipmentdeliveryorder` (
  `shipmentdeliveryorderkey` int(11) unsigned NOT NULL auto_increment,
  `shipmentdeliveryordercode` varchar(20) NOT NULL default '',
  `shipmentdeliveryorderdate` date default NULL,
  `shipmenttypecode` varchar(20) NOT NULL default '',
  `debtorcode` varchar(20) NOT NULL default '',
  `termcode` varchar(20) NOT NULL default '',
  `staffcode` varchar(20) NOT NULL default '',
  `areacode` varchar(20) NOT NULL default '',
  `descr` varchar(200) NOT NULL default '',
  `validity` varchar(100) NOT NULL default '',
  `deliveryterm` varchar(100) NOT NULL default '',
  `refno` varchar(20) NOT NULL default '',
  `address1` varchar(200) NOT NULL default '',
  `address2` varchar(200) NOT NULL default '',
  `address3` varchar(200) NOT NULL default '',
  `address4` varchar(200) NOT NULL default '',
  `city` varchar(50) NOT NULL default '',
  `postalcode` varchar(10) NOT NULL default '',
  `state` varchar(50) NOT NULL default '',
  `countrycode` varchar(50) NOT NULL default '',
  `attention` varchar(200) NOT NULL default '',
  `phone` varchar(30) NOT NULL default '',
  `fax` varchar(30) NOT NULL default '',
  `discountamount` decimal(20,2) NOT NULL,
  `amountbeforediscount` decimal(20,2) NOT NULL,
  `amount` decimal(20,2) NOT NULL default '0.00',
  `taxamount` decimal(20,2) NOT NULL default '0.00',
  `amountaftertax` decimal(20,2) NOT NULL default '0.00',
  `note` mediumtext,
  `remark1` varchar(100) NOT NULL,
  `remark2` varchar(100) NOT NULL,
  `remark3` varchar(100) NOT NULL,
  `remark4` varchar(100) NOT NULL,
  `remark5` varchar(100) NOT NULL,
  `remark6` varchar(100) NOT NULL,
  `remark7` varchar(100) NOT NULL,
  `remark8` varchar(100) NOT NULL,
  `globaldepartment` enum('Y','N') NOT NULL default 'Y',
  `departmentcode` varchar(20) NOT NULL default '',
  `globaljob` enum('Y','N') NOT NULL default 'N',
  `jobcode` varchar(20) NOT NULL default '',
  `globalstocklocation` enum('Y','N') NOT NULL default 'Y',
  `stocklocationcode` varchar(20) NOT NULL default '',
  `cancelled` enum('Y','N') NOT NULL default 'N',
  `itemformatkey` int(10) unsigned NOT NULL default '0',
  `created` datetime default NULL,
  `modified` datetime default NULL,
  `done` enum('Y','N') NOT NULL default 'N',
  `branchcode` varchar(20) NOT NULL default '',
  `branchname` varchar(200) NOT NULL default '',
  `docontactperson` varchar(200) NOT NULL default '',
  `dophone` varchar(30) NOT NULL default '',
  `dofax` varchar(30) NOT NULL default '',
  `doemail` varchar(200) NOT NULL default '',
  `doaddress1` varchar(200) NOT NULL default '',
  `doaddress2` varchar(200) NOT NULL default '',
  `doaddress3` varchar(200) NOT NULL default '',
  `doaddress4` varchar(200) NOT NULL default '',
  `docity` varchar(50) NOT NULL default '',
  `dopostalcode` varchar(10) NOT NULL default '',
  `dostate` varchar(50) NOT NULL default '',
  `docountrycode` varchar(50) NOT NULL default '',
  `curcode` varchar(20) NOT NULL,
  `currate` decimal(20,8) unsigned NOT NULL default '1.00000000',
  `localdiscountamount` decimal(20,2) NOT NULL,
  `localamountbeforediscount` decimal(20,2) NOT NULL,
  `localamount` decimal(20,2) NOT NULL default '0.00',
  `localtaxamount` decimal(20,2) NOT NULL default '0.00',
  `localamountaftertax` decimal(20,2) NOT NULL default '0.00',
  `ref1` varchar(30) NOT NULL,
  `ref2` varchar(30) NOT NULL,
  `ref3` varchar(30) NOT NULL,
  `ref4` varchar(30) NOT NULL,
  `lastmodified` timestamp NOT NULL default CURRENT_TIMESTAMP on update CURRENT_TIMESTAMP,
  `salesleadkey` int(10) unsigned NOT NULL default '0',
  `vehicleno` varchar(20) NOT NULL default '',
  `transporter` varchar(20) NOT NULL default '',
  `contenano` varchar(50) NOT NULL default '',
  `courierservicerefno` varchar(200) NOT NULL default '',
  `courierserviceprovider` varchar(200) NOT NULL default '',
  `courierservicecontactpersion` varchar(200) NOT NULL default '',
  `courierservicetelno` varchar(200) NOT NULL default '',
  `deliverydate` date default NULL,
  `customerreceived` enum('Y','N') NOT NULL default 'N',
  `customerreceiveddate` date default NULL,
  `debtorname` varchar(200) NOT NULL default '',
  `fromoldversion` enum('Y','N') NOT NULL default 'N',
  PRIMARY KEY  (`shipmentdeliveryorderkey`),
  UNIQUE KEY `isdocode` (`shipmentdeliveryordercode`),
  KEY `isdodate` (`shipmentdeliveryorderdate`),
  KEY `isdomemotypecode` (`shipmenttypecode`),
  KEY `isdodebtorcode` (`debtorcode`),
  KEY `isdotermcode` (`termcode`),
  KEY `isdostaffcode` (`staffcode`),
  KEY `isdorefno` (`refno`),
  KEY `isdodepartmentcode` (`departmentcode`),
  KEY `isdostocklocationcode` (`stocklocationcode`),
  KEY `isdocancelled` (`cancelled`),
  KEY `isdoareacode` (`areacode`),
  KEY `isdocurcode` (`curcode`),
  KEY `isdojobcode` (`jobcode`),
  KEY `isdosalesleadkey` (`salesleadkey`),
  KEY `isdocountrycode` (`countrycode`),
  KEY `isdodocountrycode` (`docountrycode`)
) ENGINE=INNODB DEFAULT CHARSET=latin1;

CREATE TABLE `shipmentdeliveryorderid` (
  `shipmentdeliveryorderkey` int(11) unsigned NOT NULL default '0',
  `id` int(11) unsigned NOT NULL default '0',
  PRIMARY KEY  (`shipmentdeliveryorderkey`,`id`)
) ENGINE=INNODB DEFAULT CHARSET=latin1;

CREATE TABLE `shipmentdeliveryorderitem` (
  `shipmentdeliveryorderkey` int(11) unsigned NOT NULL default '0',
  `shipmentdeliveryordercode` varchar(20) NOT NULL default '',
  `id` int(11) unsigned NOT NULL default '0',
  `pos` int(11) unsigned NOT NULL default '0',
  `itemno` varchar(10) NOT NULL default '',
  `stockcode` varchar(30) NOT NULL default '',
  `descr` varchar(200) NOT NULL default '',
  `moredescr` text,
  `qty` decimal(20,6) default NULL,
  `unitprice` decimal(20,6) default NULL,
  `uom` varchar(20) NOT NULL default '',
  `uomrate` double NOT NULL default '1',
  `qtybaseuom` decimal(20,6) NOT NULL default '0.000000',
  `unitpricebaseuom` double NOT NULL default '0',
  `discountformat` varchar(100) default NULL,
  `discountamount` decimal(20,2) default NULL,
  `amountbeforediscount` decimal(20,2) default NULL,
  `amount` decimal(20,2) default NULL,
  `gsttypecode` varchar(20) NOT NULL default '',
  `stockpackagegsttypecode` varchar(20) NOT NULL default '',
  `salestaxpercentage` decimal(20,2) default NULL,
  `salestaxamount` decimal(20,2) default NULL,
  `amountaftertax` decimal(20,2) default NULL,
  `departmentcode` varchar(20) NOT NULL default '',
  `jobcode` varchar(20) NOT NULL default '',
  `stocklocationcode` varchar(20) NOT NULL default '',
  `debtoritemcode` varchar(30) NOT NULL default '',
  `barcode` varchar(30) NOT NULL default '',
  `remark1` varchar(100) NOT NULL,
  `remark2` varchar(100) NOT NULL,
  `remark3` varchar(100) NOT NULL,
  `remark4` varchar(100) NOT NULL,
  `rowtype` enum('','TOTALUP','ITEMDISCOUNT','ITEMSERVICETAX','ITEMMISCCHARGES','FOOTERDISCOUNT','FOOTERSERVICETAX','FOOTERMISCCHARGES') NOT NULL,
  `foc` enum('Y','N') NOT NULL default 'N',
  `packingqty` decimal(20,6) default NULL,
  `packinguom` varchar(20) NOT NULL default '',
  `packingrate` decimal(20,6) default NULL,
  `stockpackagecode` varchar(20) NOT NULL,
  `stockpackageid` int(11) unsigned NOT NULL default '0',
  `stockpackagerate` double default NULL,
  `stockpackageqty` decimal(20,6) default NULL,
  `stockpackageunitprice` decimal(20,6) default NULL,
  `stockpackageamount` decimal(20,2) default NULL,
  `stockpackagesalestaxpercentage` decimal(20,2) default NULL,
  `stockpackagesalestaxamount` decimal(20,2) default NULL,
  `stockpackageamountaftertax` decimal(20,2) default NULL,
  `serialno` text,
  `batchno` varchar(30) NOT NULL default '',
  `curcode` varchar(20) NOT NULL default '',
  `curprice` decimal(20,6) default NULL,
  `currate` decimal(20,8) unsigned default NULL,
  `recommendpricebaseuom` decimal(20,6) unsigned NOT NULL default '0.000000',
  `weightrate` decimal(20,6) unsigned NOT NULL default '0.000000',
  `weightuom` varchar(20) NOT NULL default '',
  `weightqty` decimal(20,6) unsigned NOT NULL default '0.000000',
  `weightloosed` decimal(20,6) unsigned NOT NULL default '0.000000',
  `totalweight` decimal(20,6) unsigned NOT NULL default '0.000000',
  `volumerate` decimal(20,6) unsigned NOT NULL default '0.000000',
  `volumeuom` varchar(20) NOT NULL default '',
  `volumeqty` decimal(20,6) unsigned NOT NULL default '0.000000',
  `volumeloosed` decimal(20,6) unsigned NOT NULL default '0.000000',
  `totalvolume` decimal(20,6) unsigned NOT NULL default '0.000000',
  `fromdoctype` varchar(5) NOT NULL default '',
  `fromdockey` int(11) unsigned default NULL,
  `fromdocid` int(11) unsigned default NULL,
  `fromdoccode` varchar(20) NOT NULL default '',
  `supplypurchase` enum('None','Supply','Purchase') NOT NULL default 'None',
  `taxsubtract` enum('Y','N') NOT NULL default 'N',
  `taxableamount` decimal(20,2) NOT NULL default '0.00',
  `taxablelocalamount` decimal(20,2) NOT NULL default '0.00',
  `amountaftertaxsubtract` decimal(20,2) NOT NULL default '0.00',
  `localamountaftertaxsubtract` decimal(20,2) NOT NULL default '0.00',
  `salestaxlocalamount` decimal(20,2) NOT NULL default '0.00',
  `taxadjustment` decimal(20,2) NOT NULL default '0.00',
  `taxlocaladjustment` decimal(20,2) NOT NULL default '0.00',
  `taxtotalamount` decimal(20,2) NOT NULL default '0.00',
  `taxtotallocalamount` decimal(20,2) NOT NULL default '0.00',
  `stockpackagesupplypurchase` enum('None','Supply','Purchase') NOT NULL default 'None',
  `stockpackagetaxsubtract` enum('Y','N') NOT NULL default 'N',
  `stockpackagetaxableamount` decimal(20,2) NOT NULL default '0.00',
  `stockpackagetaxablelocalamount` decimal(20,2) NOT NULL default '0.00',
  `stockpackageamountaftertaxsubtract` decimal(20,2) NOT NULL default '0.00',
  `stockpackagelocalamountaftertaxsubtract` decimal(20,2) NOT NULL default '0.00',
  `stockpackagesalestaxlocalamount` decimal(20,2) NOT NULL default '0.00',
  `stockpackagetaxadjustment` decimal(20,2) NOT NULL default '0.00',
  `stockpackagetaxlocaladjustment` decimal(20,2) NOT NULL default '0.00',
  `stockpackagetaxtotalamount` decimal(20,2) NOT NULL default '0.00',
  `stockpackagetaxtotallocalamount` decimal(20,2) NOT NULL default '0.00',
  PRIMARY KEY  (`shipmentdeliveryorderkey`,`pos`),
  UNIQUE KEY `isdoikeyid` (`shipmentdeliveryorderkey`,`id`),
  KEY `isdoicode` (`shipmentdeliveryordercode`),
  KEY `isdoistockcode` (`stockcode`),
  KEY `isdoidepartmentcode` (`departmentcode`),
  KEY `isdoistocklocationcode` (`stocklocationcode`),
  KEY `isdoibarcode` (`barcode`),
  KEY `isdoifoc` (`foc`),
  KEY `isdoistockpackagecode` (`stockpackagecode`),
  KEY `isdoistockpackageid` (`stockpackageid`),
  KEY `isdoibatchno` (`batchno`),
  KEY `isdoijobcode` (`jobcode`),
  KEY `isdoigsttypecode` (`gsttypecode`),
  KEY `isdoistockpackagegsttypecode` (`stockpackagegsttypecode`),
  KEY `isdoifromdoctypekeypos` (`fromdoctype`,`fromdockey`,`fromdocid`)
) ENGINE=INNODB DEFAULT CHARSET=latin1;

CREATE TABLE `staff` (
  `staffkey` int(11) unsigned NOT NULL auto_increment,
  `staffcode` varchar(20) NOT NULL default '',
  `name` varchar(200) NOT NULL default '',
  `name2` varchar(200) NOT NULL default '',
  `gender` enum('MALE','FEMALE','UNKNOW') NOT NULL default 'UNKNOW',
  `dob` date default NULL,
  `photo` mediumblob,
  `address1` varchar(200) NOT NULL default '',
  `address2` varchar(200) NOT NULL default '',
  `address3` varchar(200) NOT NULL default '',
  `address4` varchar(200) NOT NULL default '',
  `phone` varchar(30) NOT NULL default '',
  `phone2` varchar(30) NOT NULL default '',
  `email` varchar(200) NOT NULL default '',
  `icno` varchar(30) NOT NULL default '',
  `epfno` varchar(30) NOT NULL default '',
  `sosocno` varchar(30) NOT NULL default '',
  `taxno` varchar(30) NOT NULL default '',
  `datejoined` date default NULL,
  `dateleft` date default NULL,
  `note` mediumtext,
  `inactive` enum('Y','N') NOT NULL default 'N',
  `done` enum('Y','N') NOT NULL default 'N',
  `iscommissionbyamount` enum('Y','N') NOT NULL default 'Y',
  `commissionbyamountcode` varchar(20) NOT NULL default '',
  `commissionbyperiodcode` varchar(20) NOT NULL default '',
  `iscommissionbyperiod` enum('Y','N') NOT NULL default 'N',
  `iscommissionbystockgroupandperiod` enum('Y','N') NOT NULL default 'N',
  `salesteamcode` varchar(20) NOT NULL default '',
  `agentrolecode` varchar(20) NOT NULL default '',
  `maxdiscount` decimal(20,2) NOT NULL default '0.00',
  `itemmaxdiscount` decimal(20,2) NOT NULL default '0.00',
  `lastmodified` timestamp NOT NULL default CURRENT_TIMESTAMP on update CURRENT_TIMESTAMP,
  `bankcode` varchar(20) NOT NULL default '',
  `accountno` varchar(30) NOT NULL default '',
  PRIMARY KEY  (`staffkey`),
  UNIQUE KEY `iscode` (`staffcode`),
  KEY `isicno` (`icno`),
  KEY `isinactive` (`inactive`),
  KEY `issalesteamcode` (`salesteamcode`),
  KEY `isagentrolecode` (`agentrolecode`),
  KEY `isbankcode` (`bankcode`),
  KEY `isaccountno` (`accountno`)
) ENGINE=INNODB DEFAULT CHARSET=latin1;

CREATE TABLE `status` (
  `statuskey` int(11) unsigned NOT NULL auto_increment,
  `statuscode` varchar(20) NOT NULL default '',
  `descr` varchar(200) NOT NULL default '',
  `inactive` enum('Y','N') NOT NULL default 'N',
  `done` enum('Y','N') NOT NULL default 'N',
  `lastmodified` timestamp NOT NULL default CURRENT_TIMESTAMP on update CURRENT_TIMESTAMP,
  PRIMARY KEY  (`statuskey`),
  UNIQUE KEY `isttscode` (`statuscode`),
  KEY `isttsinactive` (`inactive`)
) ENGINE=INNODB DEFAULT CHARSET=latin1;

CREATE TABLE `stock` (
  `stockkey` int(11) unsigned NOT NULL auto_increment,
  `stockcode` varchar(30) NOT NULL default '',
  `name` varchar(200) NOT NULL default '',
  `name2` varchar(200) NOT NULL default '',
  `service` enum('Y','N') NOT NULL default 'N',
  `baseuom` varchar(20) NOT NULL default '',
  `salesdescription` text,
  `purchasesdescription` text,
  `salespricebaseuom` decimal(20,6) unsigned NOT NULL default '0.000000',
  `discountformat` varchar(100) default '',
  `salespricebaseuom2` decimal(20,6) unsigned NOT NULL default '0.000000',
  `discountformat2` varchar(100) default '',
  `salespricebaseuom3` decimal(20,6) unsigned NOT NULL default '0.000000',
  `discountformat3` varchar(100) default '',
  `salespricebaseuom4` decimal(20,6) unsigned NOT NULL default '0.000000',
  `discountformat4` varchar(100) default '',
  `salespricebaseuom5` decimal(20,6) unsigned NOT NULL default '0.000000',
  `discountformat5` varchar(100) default '',
  `minimumpricebaseuom` decimal(20,6) unsigned NOT NULL default '0.000000',
  `purchasespricebaseuom` decimal(20,6) unsigned NOT NULL default '0.000000',
  `reorderlevel` decimal(20,6) unsigned NOT NULL default '0.000000',
  `reorderqty` decimal(20,6) unsigned NOT NULL default '0.000000',
  `reorderuom` varchar(20) NOT NULL default '',
  `defaultsalesqty` decimal(20,6) unsigned NOT NULL default '0.000000',
  `defaultsalesuom` varchar(20) NOT NULL default '',
  `defaultpurchasesqty` decimal(20,6) unsigned NOT NULL default '0.000000',
  `defaultpurchasesuom` varchar(20) NOT NULL default '',
  `salestaxpercentage` decimal(20,2) unsigned NOT NULL default '0.00',
  `stockcategorycode` varchar(20) NOT NULL default '',
  `stockgroupcode` varchar(20) NOT NULL default '',
  `stockclasscode` varchar(20) NOT NULL default '',
  `stockbrandcode` varchar(20) NOT NULL default '',
  `stockmodelcode` varchar(20) NOT NULL default '',
  `stocksize` varchar(20) NOT NULL default '',
  `stockcolor` varchar(20) NOT NULL default '',
  `stockweight` varchar(20) NOT NULL default '',
  `stockref1` varchar(20) NOT NULL default '',
  `stockref2` varchar(20) NOT NULL default '',
  `stockref3` varchar(20) NOT NULL default '',
  `stockref4` varchar(20) NOT NULL default '',
  `stockref5` varchar(20) NOT NULL default '',
  `stockref6` varchar(20) NOT NULL default '',
  `stockref7` varchar(20) NOT NULL default '',
  `stockref8` varchar(20) NOT NULL default '',
  `picture` mediumblob,
  `note` mediumtext,
  `recommendpricebaseuom` decimal(20,6) unsigned NOT NULL default '0.000000',
  `weight` decimal(20,6) unsigned NOT NULL default '0.000000',
  `weightuom` varchar(20) NOT NULL default '',
  `volume` decimal(20,6) unsigned NOT NULL default '0.000000',
  `volumeuom` varchar(20) NOT NULL default '',
  `inactive` enum('Y','N') NOT NULL default 'N',
  `barcode` varchar(30) NOT NULL default '',
  `serialnocontrol` enum('Y','N') NOT NULL default 'N',
  `salesacccode` varchar(20) NOT NULL,
  `salesreturnacccode` varchar(20) NOT NULL,
  `purchasesacccode` varchar(20) NOT NULL,
  `purchasesreturnacccode` varchar(20) NOT NULL,
  `pricecategorycode` varchar(20) NOT NULL default '',
  `matrixitemcode` varchar(20) NOT NULL default '',
  `matrixcolorcode` varchar(20) NOT NULL default '',
  `matrixsizecode` varchar(20) NOT NULL default '',
  `iswarranty` enum('Y','N') NOT NULL default 'N',
  `warrantyperiodindays` int(11) unsigned NOT NULL default '0',
  `batchnocontrol` enum('Y','N') NOT NULL default 'N',
  `unsalesableperiod` int(11) unsigned NOT NULL default '0',
  `validityperiod` int(11) unsigned NOT NULL default '0',
  `minimumqty` decimal(20,6) unsigned NOT NULL default '0.000000',
  `maximumqty` decimal(20,6) unsigned NOT NULL default '0.000000',
  `done` enum('Y','N') NOT NULL default 'N',
  `created` datetime default NULL,
  `modified` datetime default NULL,
  `stockshelf` varchar(100) NOT NULL default '',
  `stockadjustmentacccode` varchar(20) NOT NULL,
  `stockissueacccode` varchar(20) NOT NULL,
  `stockreceivedacccode` varchar(20) NOT NULL,
  `defaultsalesgsttypecode` varchar(20) NOT NULL default '',
  `defaultpurchasesgsttypecode` varchar(20) NOT NULL default '',
  `purchasestaxpercentage` decimal(20,2) unsigned NOT NULL default '0.00',
  `creditorcode` varchar(20) NOT NULL default '',
  `slowitemsalesqty` decimal(20,6) default NULL,
  `allowpointcollection` enum('Y','N') NOT NULL default 'N',
  `pointcollectionperqtybaseuom` decimal(20,2) default NULL,
  `allowpointredemption` enum('Y','N') NOT NULL default 'N',
  `pointredemptionperqtybaseuom` decimal(20,2) default NULL,
  `supplierconsignmentitem` enum('Y','N') NOT NULL default 'N',
  `lastmodified` timestamp NOT NULL default CURRENT_TIMESTAMP on update CURRENT_TIMESTAMP,
  `subtractgstsales` enum('Y','N') NOT NULL default 'N',
  `subtractgstpurchases` enum('Y','N') NOT NULL default 'N',
  `msiccode` varchar(20) NOT NULL default '',
  PRIMARY KEY  (`stockkey`),
  UNIQUE KEY `istcode` (`stockcode`),
  KEY `istservice` (`service`),
  KEY `istcategorycode` (`stockcategorycode`),
  KEY `istgroupcode` (`stockgroupcode`),
  KEY `istclasscode` (`stockclasscode`),
  KEY `istbrandcode` (`stockbrandcode`),
  KEY `istmodelcode` (`stockmodelcode`),
  KEY `istinactive` (`inactive`),
  KEY `istbarcode` (`barcode`),
  KEY `istserialnocontrol` (`serialnocontrol`),
  KEY `istsalesacccode` (`salesacccode`),
  KEY `istsalesreturnacccode` (`salesreturnacccode`),
  KEY `istpurchasesacccode` (`purchasesacccode`),
  KEY `istpurchasesreturnacccode` (`purchasesreturnacccode`),
  KEY `istpricecategorycode` (`pricecategorycode`),
  KEY `istmatrixitemcode` (`matrixitemcode`),
  KEY `istmatrixcolorcode` (`matrixcolorcode`),
  KEY `istmatrixsizecode` (`matrixsizecode`),
  KEY `istbatchnocontrol` (`batchnocontrol`),
  KEY `iststockadjustmentacccode` (`stockadjustmentacccode`),
  KEY `iststockissueacccode` (`stockissueacccode`),
  KEY `iststockreceivedacccode` (`stockreceivedacccode`),
  KEY `istdefaultsalesgsttypecode` (`defaultsalesgsttypecode`),
  KEY `istdefaultpurchasesgsttypecode` (`defaultpurchasesgsttypecode`),
  KEY `istcreditorcode` (`creditorcode`),
  KEY `isslowitemsalesqty` (`slowitemsalesqty`),
  KEY `issupplierconsignmentitem` (`supplierconsignmentitem`),
  KEY `isstockshelf` (`stockshelf`),
  KEY `istmsiccode` (`msiccode`)
) ENGINE=INNODB DEFAULT CHARSET=latin1;

CREATE TABLE `stockadjustment` (
  `stockadjustmentkey` int(11) unsigned NOT NULL auto_increment,
  `stockadjustmentcode` varchar(20) NOT NULL default '',
  `stockadjustmentdate` date default NULL,
  `descr` varchar(200) NOT NULL default '',
  `refno` varchar(20) NOT NULL default '',
  `amount` decimal(20,2) NOT NULL default '0.00',
  `note` mediumtext,
  `remark1` varchar(100) NOT NULL,
  `remark2` varchar(100) NOT NULL,
  `remark3` varchar(100) NOT NULL,
  `remark4` varchar(100) NOT NULL,
  `remark5` varchar(100) NOT NULL,
  `remark6` varchar(100) NOT NULL,
  `remark7` varchar(100) NOT NULL,
  `remark8` varchar(100) NOT NULL,
  `globaldepartment` enum('Y','N') NOT NULL default 'Y',
  `departmentcode` varchar(20) NOT NULL default '',
  `globaljob` enum('Y','N') NOT NULL default 'N',
  `jobcode` varchar(20) NOT NULL default '',
  `globalstocklocation` enum('Y','N') NOT NULL default 'Y',
  `stocklocationcode` varchar(20) NOT NULL default '',
  `cancelled` enum('Y','N') NOT NULL default 'N',
  `itemformatkey` int(11) unsigned NOT NULL default '0',
  `created` datetime default NULL,
  `modified` datetime default NULL,
  `done` enum('Y','N') NOT NULL default 'N',
  `stockadjustmenttypecode` varchar(20) NOT NULL default '',
  `refno1` varchar(50) NOT NULL default '',
  `refno2` varchar(50) NOT NULL default '',
  `debtorcode` varchar(20) NOT NULL default '',
  `creditorcode` varchar(20) NOT NULL default '',
  `postaccountvalue` enum('Y','N') NOT NULL default 'N',
  `accountjournalkey` int(11) unsigned default '0',
  `stockrefno` varchar(20) NOT NULL default '',
  `stockdescr` varchar(200) NOT NULL default '',
  `stockdepartmentcode` varchar(20) NOT NULL default '',
  `stockjobcode` varchar(20) NOT NULL default '',
  `stockacccode` varchar(20) NOT NULL default '',
  `expensesrefno` varchar(20) NOT NULL default '',
  `expensesdescr` varchar(200) NOT NULL default '',
  `expensesdepartmentcode` varchar(20) NOT NULL default '',
  `expensesjobcode` varchar(20) NOT NULL default '',
  `expensesacccode` varchar(20) NOT NULL default '',
  `adjustcostonly` enum('Y','N') NOT NULL default 'N',
  `fromdoctype` varchar(5) NOT NULL default '',
  `fromdockey` int(11) unsigned default NULL,
  PRIMARY KEY  (`stockadjustmentkey`),
  UNIQUE KEY `isadjcode` (`stockadjustmentcode`),
  KEY `isadjdate` (`stockadjustmentdate`),
  KEY `isadjrefno` (`refno`),
  KEY `isadjdepartmentcode` (`departmentcode`),
  KEY `isadjstocklocationcode` (`stocklocationcode`),
  KEY `isadjcancelled` (`cancelled`),
  KEY `isadjpostaccountvalue` (`postaccountvalue`),
  KEY `isadjstockdepartmentcode` (`stockdepartmentcode`),
  KEY `isadjstockacccode` (`stockacccode`),
  KEY `isadjexpensesdepartmentcode` (`expensesdepartmentcode`),
  KEY `isadjexpensesacccode` (`expensesacccode`),
  KEY `isadjjobcode` (`jobcode`),
  KEY `isadjstockjobcode` (`stockjobcode`),
  KEY `isadjexpensesjobcode` (`expensesjobcode`),
  KEY `isadjstockadjustmenttypecode` (`stockadjustmenttypecode`),
  KEY `isadjdebtorcode` (`debtorcode`),
  KEY `isadjcreditorcode` (`creditorcode`),
  KEY `isadjfromdoctypekey` (`fromdoctype`,`fromdockey`)
) ENGINE=INNODB DEFAULT CHARSET=latin1;

CREATE TABLE `stockadjustmentid` (
  `stockadjustmentkey` int(11) unsigned NOT NULL default '0',
  `id` int(11) unsigned NOT NULL default '0',
  PRIMARY KEY  (`stockadjustmentkey`,`id`)
) ENGINE=INNODB DEFAULT CHARSET=latin1;

CREATE TABLE `stockadjustmentitem` (
  `stockadjustmentkey` int(11) unsigned NOT NULL default '0',
  `stockadjustmentcode` varchar(20) NOT NULL default '',
  `id` int(11) unsigned NOT NULL default '0',
  `pos` int(11) unsigned NOT NULL default '0',
  `itemno` varchar(10) NOT NULL default '',
  `stockcode` varchar(30) NOT NULL default '',
  `descr` varchar(200) NOT NULL default '',
  `moredescr` text,
  `qty` decimal(20,6) default NULL,
  `unitprice` decimal(20,6) default NULL,
  `uom` varchar(20) NOT NULL default '',
  `uomrate` double NOT NULL default '1',
  `qtybaseuom` decimal(20,6) NOT NULL default '0.000000',
  `unitpricebaseuom` double NOT NULL default '0',
  `amount` decimal(20,2) default NULL,
  `departmentcode` varchar(20) NOT NULL default '',
  `jobcode` varchar(20) NOT NULL default '',
  `stocklocationcode` varchar(20) NOT NULL default '',
  `barcode` varchar(30) NOT NULL default '',
  `remark1` varchar(100) NOT NULL,
  `remark2` varchar(100) NOT NULL,
  `remark3` varchar(100) NOT NULL,
  `remark4` varchar(100) NOT NULL,
  `serialno` text,
  `foc` enum('Y','N') NOT NULL default 'N',
  `packingqty` decimal(20,6) default NULL,
  `packinguom` varchar(20) NOT NULL default '',
  `packingrate` decimal(20,6) default NULL,
  `batchno` varchar(30) NOT NULL default '',
  `acccode` varchar(20) NOT NULL default '',
  PRIMARY KEY  (`stockadjustmentkey`,`pos`),
  UNIQUE KEY `isadjikeyid` (`stockadjustmentkey`,`id`),
  KEY `isadjicode` (`stockadjustmentcode`),
  KEY `isadjistockcode` (`stockcode`),
  KEY `isadjidepartmentcode` (`departmentcode`),
  KEY `isadjistocklocationcode` (`stocklocationcode`),
  KEY `isadjibarcode` (`barcode`),
  KEY `isadjifoc` (`foc`),
  KEY `isadjiibatchno` (`batchno`),
  KEY `isadjiacccode` (`acccode`),
  KEY `isadjijobcode` (`jobcode`)
) ENGINE=INNODB DEFAULT CHARSET=latin1;

CREATE TABLE `stockadjustmenttype` (
  `stockadjustmenttypekey` int(11) unsigned NOT NULL auto_increment,
  `stockadjustmenttypecode` varchar(20) NOT NULL default '',
  `descr` varchar(200) NOT NULL default '',
  `inactive` enum('Y','N') NOT NULL default 'N',
  `done` enum('Y','N') NOT NULL default 'N',
  `lastmodified` timestamp NOT NULL default CURRENT_TIMESTAMP on update CURRENT_TIMESTAMP,
  PRIMARY KEY  (`stockadjustmenttypekey`),
  UNIQUE KEY `isadjtcode` (`stockadjustmenttypecode`),
  KEY `isadjtinactive` (`inactive`)
) ENGINE=INNODB DEFAULT CHARSET=latin1;

CREATE TABLE `stockassembly` (
  `stockassemblykey` int(11) unsigned NOT NULL auto_increment,
  `stockassemblycode` varchar(20) NOT NULL default '',
  `stockassemblydate` date default NULL,
  `descr` varchar(200) NOT NULL default '',
  `refno` varchar(20) NOT NULL default '',
  `jobordercode` varchar(20) NOT NULL,
  `stockbomcode` varchar(20) NOT NULL default '',
  `stockcode` varchar(30) NOT NULL default '',
  `qty` decimal(20,6) default NULL,
  `uom` varchar(20) NOT NULL default '',
  `uomrate` double NOT NULL default '1',
  `qtybaseuom` decimal(20,6) NOT NULL default '0.000000',
  `assemblycost` decimal(20,2) NOT NULL default '0.00',
  `amount` decimal(20,2) NOT NULL default '0.00',
  `labourcost` decimal(20,2) default '0.00',
  `overheadcost` decimal(20,2) default '0.00',
  `unitcostbaseuom` double NOT NULL default '0',
  `totalamount` decimal(20,2) NOT NULL default '0.00',
  `assemblydepartmentcode` varchar(20) NOT NULL default '',
  `assemblyjobcode` varchar(20) NOT NULL default '',
  `assemblystocklocationcode` varchar(20) NOT NULL default '',
  `serialno` text,
  `note` mediumtext,
  `remark1` varchar(100) NOT NULL,
  `remark2` varchar(100) NOT NULL,
  `remark3` varchar(100) NOT NULL,
  `remark4` varchar(100) NOT NULL,
  `remark5` varchar(100) NOT NULL,
  `remark6` varchar(100) NOT NULL,
  `remark7` varchar(100) NOT NULL,
  `remark8` varchar(100) NOT NULL,
  `globaldepartment` enum('Y','N') NOT NULL default 'Y',
  `departmentcode` varchar(20) NOT NULL default '',
  `globaljob` enum('Y','N') NOT NULL default 'N',
  `jobcode` varchar(20) NOT NULL default '',
  `globalstocklocation` enum('Y','N') NOT NULL default 'Y',
  `stocklocationcode` varchar(20) NOT NULL default '',
  `cancelled` enum('Y','N') NOT NULL default 'N',
  `itemformatkey` int(11) unsigned NOT NULL default '0',
  `created` datetime default NULL,
  `modified` datetime default NULL,
  `done` enum('Y','N') NOT NULL default 'N',
  `batchno` varchar(30) NOT NULL default '',
  `jobsheetid` int(11) unsigned NOT NULL default '0',
  `autosublevelproduction` enum('Y','N') NOT NULL default 'N',
  PRIMARY KEY  (`stockassemblykey`),
  UNIQUE KEY `istasbcode` (`stockassemblycode`),
  KEY `istasbdate` (`stockassemblydate`),
  KEY `istasbbomcode` (`stockbomcode`),
  KEY `istasbbomstockcode` (`stockcode`),
  KEY `istasbrefno` (`refno`),
  KEY `istasbassemblydepartmentcode` (`assemblydepartmentcode`),
  KEY `istasbassemblystocklocationcode` (`assemblystocklocationcode`),
  KEY `istasbdepartmentcode` (`departmentcode`),
  KEY `istasbstocklocationcode` (`stocklocationcode`),
  KEY `istasbcancelled` (`cancelled`),
  KEY `istasbjobordercode` (`jobordercode`),
  KEY `istasbbatchno` (`batchno`),
  KEY `istasjobordercodeid` (`jobordercode`,`jobsheetid`),
  KEY `istasbjobcode` (`jobcode`),
  KEY `istasbassemblyjobcode` (`assemblyjobcode`)
) ENGINE=INNODB DEFAULT CHARSET=latin1;

CREATE TABLE `stockassemblyid` (
  `stockassemblykey` int(11) unsigned NOT NULL default '0',
  `id` int(11) unsigned NOT NULL default '0',
  PRIMARY KEY  (`stockassemblykey`,`id`)
) ENGINE=INNODB DEFAULT CHARSET=latin1;

CREATE TABLE `stockassemblyitem` (
  `stockassemblykey` int(11) unsigned NOT NULL default '0',
  `stockassemblycode` varchar(20) NOT NULL default '',
  `id` int(11) unsigned NOT NULL default '0',
  `pos` int(11) unsigned NOT NULL default '0',
  `itemno` varchar(10) NOT NULL default '',
  `stockbomcode` varchar(20) NOT NULL default '',
  `stockcode` varchar(30) NOT NULL default '',
  `descr` varchar(200) NOT NULL default '',
  `moredescr` text,
  `qty` decimal(20,6) default NULL,
  `unitprice` decimal(20,6) default NULL,
  `uom` varchar(20) NOT NULL default '',
  `uomrate` double NOT NULL default '1',
  `qtybaseuom` decimal(20,6) NOT NULL default '0.000000',
  `unitpricebaseuom` double NOT NULL default '0',
  `amount` decimal(20,2) default NULL,
  `labourcost` decimal(20,2) default NULL,
  `overheadcost` decimal(20,2) default NULL,
  `departmentcode` varchar(20) NOT NULL default '',
  `jobcode` varchar(20) NOT NULL default '',
  `stocklocationcode` varchar(20) NOT NULL default '',
  `serialno` text,
  `bomrate` double NOT NULL default '1',
  `remark1` varchar(100) NOT NULL,
  `remark2` varchar(100) NOT NULL,
  `remark3` varchar(100) NOT NULL,
  `remark4` varchar(100) NOT NULL,
  `batchno` varchar(30) NOT NULL default '',
  `subbomid` int(11) unsigned NOT NULL default '0',
  PRIMARY KEY  (`stockassemblykey`,`pos`),
  UNIQUE KEY `istasbikeyid` (`stockassemblykey`,`id`),
  KEY `istasbicode` (`stockassemblycode`),
  KEY `istasbibomcode` (`stockbomcode`),
  KEY `istasbibomstockcode` (`stockcode`),
  KEY `istasbidepartmentcode` (`departmentcode`),
  KEY `istasbistocklocationcode` (`stocklocationcode`),
  KEY `istasbibatchno` (`batchno`),
  KEY `istasbijobcode` (`jobcode`),
  KEY `istasbisubbomid` (`subbomid`)
) ENGINE=INNODB DEFAULT CHARSET=latin1;

CREATE TABLE `stockbatchno` (
  `stockkey` int(11) unsigned NOT NULL auto_increment,
  `stockcode` varchar(30) NOT NULL default '',
  `pos` int(11) unsigned NOT NULL default '0',
  `batchno` varchar(30) NOT NULL default '',
  `descr` varchar(200) NOT NULL default '',
  `manufacturingdate` date default NULL,
  `expiredate` date default NULL,
  `inactive` enum('Y','N') NOT NULL default 'N',
  PRIMARY KEY  (`stockkey`,`batchno`),
  UNIQUE KEY `isbnstockbatchno` (`stockcode`,`batchno`),
  KEY `isbnbatchno` (`batchno`),
  KEY `isbnmanufacturingdate` (`manufacturingdate`),
  KEY `isbnexpiredate` (`expiredate`),
  KEY `isbninactive` (`inactive`)
) ENGINE=INNODB DEFAULT CHARSET=latin1;

CREATE TABLE `stockbom` (
  `stockbomkey` int(11) unsigned NOT NULL auto_increment,
  `stockbomcode` varchar(20) NOT NULL default '',
  `stockcode` varchar(30) NOT NULL default '',
  `assemblycost` decimal(20,2) NOT NULL default '0.00',
  `note` mediumtext,
  `inactive` enum('Y','N') NOT NULL default 'N',
  `itemformatkey` int(11) unsigned NOT NULL default '0',
  `created` datetime default NULL,
  `modified` datetime default NULL,
  `done` enum('Y','N') NOT NULL default 'N',
  `bomdepartmentcode` varchar(20) NOT NULL default '',
  `bomjobcode` varchar(20) NOT NULL default '',
  `bomstocklocationcode` varchar(20) NOT NULL default '',
  `globaldepartment` enum('Y','N') NOT NULL default 'Y',
  `departmentcode` varchar(20) NOT NULL default '',
  `globaljob` enum('Y','N') NOT NULL default 'N',
  `jobcode` varchar(20) NOT NULL default '',
  `globalstocklocation` enum('Y','N') NOT NULL default 'Y',
  `stocklocationcode` varchar(20) NOT NULL default '',
  `lastmodified` timestamp NOT NULL default CURRENT_TIMESTAMP on update CURRENT_TIMESTAMP,
  PRIMARY KEY  (`stockbomkey`),
  UNIQUE KEY `istbomcode` (`stockbomcode`),
  KEY `istbomstockcode` (`stockcode`),
  KEY `istbominactive` (`inactive`),
  KEY `istbombomdepartmentcode` (`bomdepartmentcode`),
  KEY `istbombomstocklocationcode` (`bomstocklocationcode`),
  KEY `istbomdepartmentcode` (`departmentcode`),
  KEY `istbomstocklocationcode` (`stocklocationcode`),
  KEY `istbomjobcode` (`jobcode`),
  KEY `istbombomjobcode` (`bomjobcode`)
) ENGINE=INNODB DEFAULT CHARSET=latin1;

CREATE TABLE `stockbomitem` (
  `stockbomkey` int(11) unsigned NOT NULL default '0',
  `stockbomcode` varchar(20) NOT NULL default '',
  `pos` int(11) unsigned NOT NULL default '0',
  `componentcode` varchar(30) NOT NULL default '',
  `componentbomcode` varchar(20) NOT NULL default '',
  `qty` decimal(20,6) default NULL,
  `unitprice` decimal(20,6) default NULL,
  `uom` varchar(20) NOT NULL default '',
  `uomrate` double NOT NULL default '1',
  `qtybaseuom` decimal(20,6) NOT NULL default '0.000000',
  `unitpricebaseuom` double NOT NULL default '0',
  `amount` decimal(20,2) default NULL,
  `labourcost` decimal(20,2) default NULL,
  `overheadcost` decimal(20,2) default NULL,
  `departmentcode` varchar(20) NOT NULL default '',
  `jobcode` varchar(20) NOT NULL default '',
  `stocklocationcode` varchar(20) NOT NULL default '',
  PRIMARY KEY  (`stockbomkey`,`pos`),
  KEY `istbomicode` (`stockbomcode`),
  KEY `istbomicomponentcode` (`componentcode`),
  KEY `istbomicomponentbomcode` (`componentbomcode`),
  KEY `istbomistocklocationcode` (`stocklocationcode`),
  KEY `istbomidepartmentcode` (`departmentcode`),
  KEY `istbomijobcode` (`jobcode`)
) ENGINE=INNODB DEFAULT CHARSET=latin1;

CREATE TABLE `stockbrand` (
  `stockbrandkey` int(11) unsigned NOT NULL auto_increment,
  `stockbrandcode` varchar(20) NOT NULL default '',
  `descr` varchar(200) NOT NULL default '',
  `inactive` enum('Y','N') NOT NULL default 'N',
  `done` enum('Y','N') NOT NULL default 'N',
  `lastmodified` timestamp NOT NULL default CURRENT_TIMESTAMP on update CURRENT_TIMESTAMP,
  PRIMARY KEY  (`stockbrandkey`),
  UNIQUE KEY `istbrabrandcode` (`stockbrandcode`),
  KEY `istbrainactive` (`inactive`)
) ENGINE=INNODB DEFAULT CHARSET=latin1;

CREATE TABLE `stockbylocation` (
  `stockbylocationkey` int(11) unsigned NOT NULL auto_increment,
  `stockcode` varchar(30) NOT NULL default '',
  `stocklocationcode` varchar(20) NOT NULL default '',
  `reorderlevel` decimal(20,6) unsigned NOT NULL default '0.000000',
  `reorderqty` decimal(20,6) unsigned NOT NULL default '0.000000',
  `reorderuom` varchar(20) NOT NULL default '',
  PRIMARY KEY  (`stockbylocationkey`),
  UNIQUE KEY `isblcode` (`stockcode`,`stocklocationcode`)
) ENGINE=INNODB DEFAULT CHARSET=latin1;

CREATE TABLE `stockcategory` (
  `stockcategorykey` int(11) unsigned NOT NULL auto_increment,
  `stockcategorycode` varchar(20) NOT NULL default '',
  `descr` varchar(200) NOT NULL default '',
  `inactive` enum('Y','N') NOT NULL default 'N',
  `done` enum('Y','N') NOT NULL default 'N',
  `lastmodified` timestamp NOT NULL default CURRENT_TIMESTAMP on update CURRENT_TIMESTAMP,
  PRIMARY KEY  (`stockcategorykey`),
  UNIQUE KEY `istcatcategorycode` (`stockcategorycode`),
  KEY `istcatinactive` (`inactive`)
) ENGINE=INNODB DEFAULT CHARSET=latin1;

CREATE TABLE `stockclass` (
  `stockclasskey` int(11) unsigned NOT NULL auto_increment,
  `stockclasscode` varchar(20) NOT NULL default '',
  `descr` varchar(200) NOT NULL default '',
  `inactive` enum('Y','N') NOT NULL default 'N',
  `done` enum('Y','N') NOT NULL default 'N',
  `lastmodified` timestamp NOT NULL default CURRENT_TIMESTAMP on update CURRENT_TIMESTAMP,
  PRIMARY KEY  (`stockclasskey`),
  UNIQUE KEY `istclaclasscode` (`stockclasscode`),
  KEY `istclainactive` (`inactive`)
) ENGINE=INNODB DEFAULT CHARSET=latin1;

CREATE TABLE `stockdisassembly` (
  `stockdisassemblykey` int(11) unsigned NOT NULL auto_increment,
  `stockdisassemblycode` varchar(20) NOT NULL default '',
  `stockdisassemblydate` date default NULL,
  `descr` varchar(200) NOT NULL default '',
  `refno` varchar(20) NOT NULL default '',
  `fromassemblycode` varchar(20) NOT NULL,
  `stockbomcode` varchar(20) NOT NULL default '',
  `stockcode` varchar(30) NOT NULL default '',
  `qty` decimal(20,6) default NULL,
  `uom` varchar(20) NOT NULL default '',
  `uomrate` double NOT NULL default '1',
  `qtybaseuom` decimal(20,6) NOT NULL default '0.000000',
  `disassemblycost` decimal(20,2) NOT NULL default '0.00',
  `amount` decimal(20,2) NOT NULL default '0.00',
  `labourcost` decimal(20,2) default '0.00',
  `overheadcost` decimal(20,2) default '0.00',
  `unitcostbaseuom` double NOT NULL default '0',
  `totalamount` decimal(20,2) NOT NULL default '0.00',
  `disassemblydepartmentcode` varchar(20) NOT NULL default '',
  `disassemblyjobcode` varchar(20) NOT NULL default '',
  `disassemblystocklocationcode` varchar(20) NOT NULL default '',
  `serialno` text,
  `note` mediumtext,
  `remark1` varchar(100) NOT NULL,
  `remark2` varchar(100) NOT NULL,
  `remark3` varchar(100) NOT NULL,
  `remark4` varchar(100) NOT NULL,
  `remark5` varchar(100) NOT NULL,
  `remark6` varchar(100) NOT NULL,
  `remark7` varchar(100) NOT NULL,
  `remark8` varchar(100) NOT NULL,
  `globaldepartment` enum('Y','N') NOT NULL default 'Y',
  `departmentcode` varchar(20) NOT NULL default '',
  `globaljob` enum('Y','N') NOT NULL default 'N',
  `jobcode` varchar(20) NOT NULL default '',
  `globalstocklocation` enum('Y','N') NOT NULL default 'Y',
  `stocklocationcode` varchar(20) NOT NULL default '',
  `cancelled` enum('Y','N') NOT NULL default 'N',
  `itemformatkey` int(11) unsigned NOT NULL default '0',
  `created` datetime default NULL,
  `modified` datetime default NULL,
  `done` enum('Y','N') NOT NULL default 'N',
  `batchno` varchar(30) NOT NULL default '',
  PRIMARY KEY  (`stockdisassemblykey`),
  UNIQUE KEY `istdasbcode` (`stockdisassemblycode`),
  KEY `istdasbdate` (`stockdisassemblydate`),
  KEY `istdasbbomcode` (`stockbomcode`),
  KEY `istdasbbomstockcode` (`stockcode`),
  KEY `istdasbrefno` (`refno`),
  KEY `istdasbdisassemblydepartmentcode` (`disassemblydepartmentcode`),
  KEY `istdasbdisassemblystocklocationcode` (`disassemblystocklocationcode`),
  KEY `istdasbdepartmentcode` (`departmentcode`),
  KEY `istdasbstocklocationcode` (`stocklocationcode`),
  KEY `istdasbcancelled` (`cancelled`),
  KEY `istdasbjobordercode` (`fromassemblycode`),
  KEY `istdasbbatchno` (`batchno`),
  KEY `istdasbjobcode` (`jobcode`),
  KEY `istdasbdisassemblyjobcode` (`disassemblyjobcode`)
) ENGINE=INNODB DEFAULT CHARSET=latin1;

CREATE TABLE `stockdisassemblyid` (
  `stockdisassemblykey` int(11) unsigned NOT NULL default '0',
  `id` int(11) unsigned NOT NULL default '0',
  PRIMARY KEY  (`stockdisassemblykey`,`id`)
) ENGINE=INNODB DEFAULT CHARSET=latin1;

CREATE TABLE `stockdisassemblyitem` (
  `stockdisassemblykey` int(11) unsigned NOT NULL default '0',
  `stockdisassemblycode` varchar(20) NOT NULL default '',
  `id` int(11) unsigned NOT NULL default '0',
  `pos` int(11) unsigned NOT NULL default '0',
  `itemno` varchar(10) NOT NULL default '',
  `stockbomcode` varchar(20) NOT NULL default '',
  `stockcode` varchar(30) NOT NULL default '',
  `descr` varchar(200) NOT NULL default '',
  `moredescr` text,
  `qty` decimal(20,6) default NULL,
  `unitprice` decimal(20,6) default NULL,
  `uom` varchar(20) NOT NULL default '',
  `uomrate` double NOT NULL default '1',
  `qtybaseuom` decimal(20,6) NOT NULL default '0.000000',
  `unitpricebaseuom` double NOT NULL default '0',
  `amount` decimal(20,2) default NULL,
  `labourcost` decimal(20,2) default NULL,
  `overheadcost` decimal(20,2) default NULL,
  `departmentcode` varchar(20) NOT NULL default '',
  `jobcode` varchar(20) NOT NULL default '',
  `stocklocationcode` varchar(20) NOT NULL default '',
  `serialno` text,
  `bomrate` double NOT NULL default '1',
  `remark1` varchar(100) NOT NULL,
  `remark2` varchar(100) NOT NULL,
  `remark3` varchar(100) NOT NULL,
  `remark4` varchar(100) NOT NULL,
  `batchno` varchar(30) NOT NULL default '',
  PRIMARY KEY  (`stockdisassemblykey`,`pos`),
  UNIQUE KEY `istdasbikeyid` (`stockdisassemblykey`,`id`),
  KEY `istdasbicode` (`stockdisassemblycode`),
  KEY `istdasbibomcode` (`stockbomcode`),
  KEY `istdasbibomstockcode` (`stockcode`),
  KEY `istdasbidepartmentcode` (`departmentcode`),
  KEY `istdasbistocklocationcode` (`stocklocationcode`),
  KEY `istdasbibatchno` (`batchno`),
  KEY `istdasbijobcode` (`jobcode`)
) ENGINE=INNODB DEFAULT CHARSET=latin1;

CREATE TABLE `stockexchange` (
  `stockexchangekey` int(11) unsigned NOT NULL auto_increment,
  `stockexchangecode` varchar(20) NOT NULL default '',
  `stockexchangedate` date default NULL,
  `stockexchangetypecode` varchar(20) NOT NULL default '',
  `debtorcode` varchar(20) NOT NULL default '',
  `creditorcode` varchar(20) NOT NULL default '',
  `descr` varchar(200) NOT NULL default '',
  `refno` varchar(20) NOT NULL default '',
  `refno1` varchar(50) NOT NULL default '',
  `refno2` varchar(50) NOT NULL default '',
  `note` mediumtext,
  `remark1` varchar(100) NOT NULL,
  `remark2` varchar(100) NOT NULL,
  `remark3` varchar(100) NOT NULL,
  `remark4` varchar(100) NOT NULL,
  `remark5` varchar(100) NOT NULL,
  `remark6` varchar(100) NOT NULL,
  `remark7` varchar(100) NOT NULL,
  `remark8` varchar(100) NOT NULL,
  `cancelled` enum('Y','N') NOT NULL default 'N',
  `instockcode` varchar(30) NOT NULL default '',
  `instockdescr` varchar(200) NOT NULL default '',
  `inqty` decimal(20,6) default NULL,
  `inunitprice` decimal(20,6) default NULL,
  `inuom` varchar(20) NOT NULL default '',
  `inuomrate` double NOT NULL default '1',
  `inqtybaseuom` decimal(20,6) NOT NULL default '0.000000',
  `inunitpricebaseuom` double NOT NULL default '0',
  `inamount` decimal(20,2) default NULL,
  `indepartmentcode` varchar(20) NOT NULL default '',
  `injobcode` varchar(20) NOT NULL default '',
  `instocklocationcode` varchar(20) NOT NULL default '',
  `inserialno` text,
  `infoc` enum('Y','N') NOT NULL default 'N',
  `inbatchno` varchar(30) NOT NULL default '',
  `outstockcode` varchar(30) NOT NULL default '',
  `outstockdescr` varchar(200) NOT NULL default '',
  `outqty` decimal(20,6) default NULL,
  `outunitprice` decimal(20,6) default NULL,
  `outuom` varchar(20) NOT NULL default '',
  `outuomrate` double NOT NULL default '1',
  `outqtybaseuom` decimal(20,6) NOT NULL default '0.000000',
  `outunitpricebaseuom` double NOT NULL default '0',
  `outamount` decimal(20,2) default NULL,
  `outdepartmentcode` varchar(20) NOT NULL default '',
  `outjobcode` varchar(20) NOT NULL default '',
  `outstocklocationcode` varchar(20) NOT NULL default '',
  `outserialno` text,
  `outfoc` enum('Y','N') NOT NULL default 'N',
  `outbatchno` varchar(30) NOT NULL default '',
  `stockadjustmentkey` int(10) unsigned NOT NULL default '0',
  `created` datetime default NULL,
  `modified` datetime default NULL,
  `done` enum('Y','N') NOT NULL default 'N',
  `outfromdoctype` varchar(5) NOT NULL default '',
  `outfromdockey` int(11) unsigned default NULL,
  `outfromdocid` int(11) unsigned default NULL,
  `outfromdoccode` varchar(20) NOT NULL default '',
  PRIMARY KEY  (`stockexchangekey`),
  UNIQUE KEY `isadjcode` (`stockexchangecode`),
  KEY `isedate` (`stockexchangedate`),
  KEY `iserefno` (`refno`),
  KEY `isecancelled` (`cancelled`),
  KEY `isedebtorcode` (`debtorcode`),
  KEY `isecreditorcode` (`creditorcode`),
  KEY `iseinstockcode` (`instockcode`),
  KEY `iseindepartmentcode` (`indepartmentcode`),
  KEY `iseinjobcode` (`injobcode`),
  KEY `iseinstocklocationcode` (`instocklocationcode`),
  KEY `iseoutstockcode` (`outstockcode`),
  KEY `iseoutdepartmentcode` (`outdepartmentcode`),
  KEY `iseoutjobcode` (`outjobcode`),
  KEY `iseoutstocklocationcode` (`outstocklocationcode`),
  KEY `iseoutfromdoctypekeypos` (`outfromdoctype`,`outfromdockey`,`outfromdocid`),
  KEY `isestockadjustmentkey` (`stockadjustmentkey`)
) ENGINE=INNODB DEFAULT CHARSET=latin1;

CREATE TABLE `stockexchangetype` (
  `stockexchangetypekey` int(11) unsigned NOT NULL auto_increment,
  `stockexchangetypecode` varchar(20) NOT NULL default '',
  `descr` varchar(200) NOT NULL default '',
  `inactive` enum('Y','N') NOT NULL default 'N',
  `done` enum('Y','N') NOT NULL default 'N',
  PRIMARY KEY  (`stockexchangetypekey`),
  UNIQUE KEY `isetcode` (`stockexchangetypecode`),
  KEY `isetinactive` (`inactive`)
) ENGINE=INNODB DEFAULT CHARSET=latin1;

CREATE TABLE `stockgroup` (
  `stockgroupkey` int(11) unsigned NOT NULL auto_increment,
  `stockgroupcode` varchar(20) NOT NULL default '',
  `descr` varchar(200) NOT NULL default '',
  `inactive` enum('Y','N') NOT NULL default 'N',
  `done` enum('Y','N') NOT NULL default 'N',
  `lastmodified` timestamp NOT NULL default CURRENT_TIMESTAMP on update CURRENT_TIMESTAMP,
  PRIMARY KEY  (`stockgroupkey`),
  UNIQUE KEY `istgrogroupcode` (`stockgroupcode`),
  KEY `istgroinactive` (`inactive`)
) ENGINE=INNODB DEFAULT CHARSET=latin1;

CREATE TABLE `stockissue` (
  `stockissuekey` int(11) unsigned NOT NULL auto_increment,
  `stockissuecode` varchar(20) NOT NULL default '',
  `stockissuedate` date default NULL,
  `descr` varchar(200) NOT NULL default '',
  `refno` varchar(20) NOT NULL default '',
  `amount` decimal(20,2) NOT NULL default '0.00',
  `note` mediumtext,
  `remark1` varchar(100) NOT NULL,
  `remark2` varchar(100) NOT NULL,
  `remark3` varchar(100) NOT NULL,
  `remark4` varchar(100) NOT NULL,
  `remark5` varchar(100) NOT NULL,
  `remark6` varchar(100) NOT NULL,
  `remark7` varchar(100) NOT NULL,
  `remark8` varchar(100) NOT NULL,
  `globaldepartment` enum('Y','N') NOT NULL default 'Y',
  `departmentcode` varchar(20) NOT NULL default '',
  `globaljob` enum('Y','N') NOT NULL default 'N',
  `jobcode` varchar(20) NOT NULL default '',
  `globalstocklocation` enum('Y','N') NOT NULL default 'Y',
  `stocklocationcode` varchar(20) NOT NULL default '',
  `cancelled` enum('Y','N') NOT NULL default 'N',
  `itemformatkey` int(11) unsigned NOT NULL default '0',
  `created` datetime default NULL,
  `modified` datetime default NULL,
  `done` enum('Y','N') NOT NULL default 'N',
  `closed` enum('Y','N') NOT NULL default 'N',
  `approval` enum('Y','N') NOT NULL default 'N',
  `approvalby` varchar(20) NOT NULL,
  `approvaldatetime` datetime default NULL,
  `approvalremark` mediumtext,
  `approval2` enum('Y','N') NOT NULL default 'N',
  `approvalby2` varchar(20) NOT NULL,
  `approvaldatetime2` datetime default NULL,
  `approvalremark2` mediumtext,
  `approval3` enum('Y','N') NOT NULL default 'N',
  `approvalby3` varchar(20) NOT NULL,
  `approvaldatetime3` datetime default NULL,
  `approvalremark3` mediumtext,
  `closedremark` varchar(200) default NULL,
  `poststockvalue` enum('Y','N') NOT NULL default 'Y',
  `postaccountvalue` enum('Y','N') NOT NULL default 'N',
  `accountjournalkey` int(10) unsigned default '0',
  `stockrefno` varchar(20) NOT NULL default '',
  `stockdescr` varchar(200) NOT NULL default '',
  `stockdepartmentcode` varchar(20) NOT NULL default '',
  `stockjobcode` varchar(20) NOT NULL default '',
  `stockacccode` varchar(20) NOT NULL default '',
  `expensesrefno` varchar(20) NOT NULL default '',
  `expensesdescr` varchar(200) NOT NULL default '',
  `expensesdepartmentcode` varchar(20) NOT NULL default '',
  `expensesjobcode` varchar(20) NOT NULL default '',
  `expensesacccode` varchar(20) NOT NULL default '',
  `fromdoctype` varchar(5) NOT NULL default '',
  `fromdockey` int(11) unsigned default '0',
  PRIMARY KEY  (`stockissuekey`),
  UNIQUE KEY `isticode` (`stockissuecode`),
  KEY `istidate` (`stockissuedate`),
  KEY `istirefno` (`refno`),
  KEY `istidepartmentcode` (`departmentcode`),
  KEY `ististocklocationcode` (`stocklocationcode`),
  KEY `isticancelled` (`cancelled`),
  KEY `isticlosed` (`closed`),
  KEY `istiapproval` (`approval`),
  KEY `istiapproval2` (`approval2`),
  KEY `istiapproval3` (`approval3`),
  KEY `istipoststockvalue` (`poststockvalue`),
  KEY `istipostaccountvalue` (`postaccountvalue`),
  KEY `ististockdepartmentcode` (`stockdepartmentcode`),
  KEY `ististockacccode` (`stockacccode`),
  KEY `istiexpensesdepartmentcode` (`expensesdepartmentcode`),
  KEY `istiexpensesacccode` (`expensesacccode`),
  KEY `istijobcode` (`jobcode`),
  KEY `ististockjobcode` (`stockjobcode`),
  KEY `istiexpensesjobcode` (`expensesjobcode`),
  KEY `istifromdoctypekey` (`fromdoctype`,`fromdockey`)
) ENGINE=INNODB DEFAULT CHARSET=latin1;

CREATE TABLE `stockissueid` (
  `stockissuekey` int(11) unsigned NOT NULL default '0',
  `id` int(11) unsigned NOT NULL default '0',
  PRIMARY KEY  (`stockissuekey`,`id`)
) ENGINE=INNODB DEFAULT CHARSET=latin1;

CREATE TABLE `stockissueitem` (
  `stockissuekey` int(11) unsigned NOT NULL default '0',
  `stockissuecode` varchar(20) NOT NULL default '',
  `id` int(11) unsigned NOT NULL default '0',
  `pos` int(11) unsigned NOT NULL default '0',
  `itemno` varchar(10) NOT NULL default '',
  `stockcode` varchar(30) NOT NULL default '',
  `descr` varchar(200) NOT NULL default '',
  `moredescr` text,
  `qty` decimal(20,6) default NULL,
  `unitprice` decimal(20,6) default NULL,
  `uom` varchar(20) NOT NULL default '',
  `uomrate` double NOT NULL default '1',
  `qtybaseuom` decimal(20,6) NOT NULL default '0.000000',
  `unitpricebaseuom` double NOT NULL default '0',
  `amount` decimal(20,2) default NULL,
  `departmentcode` varchar(20) NOT NULL default '',
  `jobcode` varchar(20) NOT NULL default '',
  `stocklocationcode` varchar(20) NOT NULL default '',
  `barcode` varchar(30) NOT NULL default '',
  `remark1` varchar(100) NOT NULL,
  `remark2` varchar(100) NOT NULL,
  `remark3` varchar(100) NOT NULL,
  `remark4` varchar(100) NOT NULL,
  `serialno` text,
  `batchno` varchar(30) NOT NULL default '',
  `acccode` varchar(20) NOT NULL default '',
  `fromdoctype` varchar(5) NOT NULL default '',
  `fromdockey` int(11) unsigned default NULL,
  `fromdocid` int(11) unsigned default NULL,
  `fromdoccode` varchar(20) NOT NULL default '',
  PRIMARY KEY  (`stockissuekey`,`pos`),
  UNIQUE KEY `istiikeyid` (`stockissuekey`,`id`),
  KEY `istiicode` (`stockissuecode`),
  KEY `istiistockcode` (`stockcode`),
  KEY `istiidepartmentcode` (`departmentcode`),
  KEY `istiistocklocationcode` (`stocklocationcode`),
  KEY `istiibarcode` (`barcode`),
  KEY `istiibatchno` (`batchno`),
  KEY `istiiacccode` (`acccode`),
  KEY `istiifromdoctypekeypos` USING BTREE (`fromdoctype`,`fromdockey`,`fromdocid`),
  KEY `istiijobcode` (`jobcode`)
) ENGINE=INNODB DEFAULT CHARSET=latin1;

CREATE TABLE `stocklink` (
  `stocklinkkey` int(11) unsigned NOT NULL auto_increment,
  `osacccode` varchar(20) NOT NULL default '',
  `csacccode` varchar(20) NOT NULL default '',
  `bsacccode` varchar(20) NOT NULL default '',
  PRIMARY KEY  (`stocklinkkey`),
  KEY `islosacccode` (`osacccode`),
  KEY `islcsacccode` (`csacccode`),
  KEY `islbsacccode` (`bsacccode`)
) ENGINE=INNODB DEFAULT CHARSET=latin1;

CREATE TABLE `stocklinkvalue` (
  `stocklinkkey` int(11) unsigned NOT NULL default '0',
  `stockyear` smallint(5) unsigned NOT NULL default '0',
  `stockmonth` enum('JAN','FEB','MAR','APR','MAY','JUN','JUL','AUG','SEP','OCT','NOV','DEC') NOT NULL default 'JAN',
  `departmentcode` varchar(20) NOT NULL default '',
  `jobcode` varchar(20) NOT NULL default '',
  `stockvalue` decimal(20,2) NOT NULL default '0.00',
  PRIMARY KEY  USING BTREE (`stocklinkkey`,`stockyear`,`stockmonth`,`departmentcode`,`jobcode`),
  KEY `islvstockyearmonth` (`stockyear`,`stockmonth`),
  KEY `islvdepartmentcode` (`departmentcode`),
  KEY `islvjobcode` (`jobcode`)
) ENGINE=INNODB DEFAULT CHARSET=latin1;

CREATE TABLE `stocklocation` (
  `stocklocationkey` int(11) unsigned NOT NULL auto_increment,
  `stocklocationcode` varchar(20) NOT NULL default '',
  `descr` varchar(200) NOT NULL default '',
  `address1` varchar(200) NOT NULL default '',
  `address2` varchar(200) NOT NULL default '',
  `address3` varchar(200) NOT NULL default '',
  `address4` varchar(200) NOT NULL default '',
  `contactperson` varchar(200) NOT NULL default '',
  `phone` varchar(30) NOT NULL default '',
  `phone2` varchar(30) NOT NULL default '',
  `fax` varchar(30) NOT NULL default '',
  `fax2` varchar(30) NOT NULL default '',
  `note` mediumtext,
  `locationmap` mediumblob,
  `level` tinyint(3) unsigned NOT NULL default '0',
  `rootkey` int(11) unsigned NOT NULL default '0',
  `parentkey` int(11) unsigned NOT NULL default '0',
  `linkkey` varchar(250) NOT NULL default '',
  `inactive` enum('Y','N') NOT NULL default 'N',
  `done` enum('Y','N') NOT NULL default 'N',
  `lastmodified` timestamp NOT NULL default CURRENT_TIMESTAMP on update CURRENT_TIMESTAMP,
  `city` varchar(50) NOT NULL default '',
  `postalcode` char(10) NOT NULL default '',
  `state` varchar(50) NOT NULL default '',
  `countrycode` varchar(50) NOT NULL default '',
  PRIMARY KEY  (`stocklocationkey`),
  UNIQUE KEY `istloccode` (`stocklocationcode`),
  KEY `istloclevel` (`level`),
  KEY `istlocrootkey` (`rootkey`),
  KEY `istlparentkey` (`parentkey`),
  KEY `istllinkkey` (`linkkey`),
  KEY `istlinactive` (`inactive`),
  KEY `islcity` (`city`),
  KEY `islstate` (`state`),
  KEY `islcountrycode` (`countrycode`)
) ENGINE=INNODB DEFAULT CHARSET=latin1;

CREATE TABLE `stockmodel` (
  `stockmodelkey` int(11) unsigned NOT NULL auto_increment,
  `stockmodelcode` varchar(20) NOT NULL default '',
  `descr` varchar(200) NOT NULL default '',
  `inactive` enum('Y','N') NOT NULL default 'N',
  `done` enum('Y','N') NOT NULL default 'N',
  `lastmodified` timestamp NOT NULL default CURRENT_TIMESTAMP on update CURRENT_TIMESTAMP,
  PRIMARY KEY  (`stockmodelkey`),
  UNIQUE KEY `istmodmodelcode` (`stockmodelcode`),
  KEY `istmodinactive` (`inactive`)
) ENGINE=INNODB DEFAULT CHARSET=latin1;

CREATE TABLE `stockob` (
  `stockobkey` int(11) unsigned NOT NULL auto_increment,
  `stockobcode` varchar(20) NOT NULL default '',
  `stockobdate` date default NULL,
  `descr` varchar(200) NOT NULL default '',
  `refno` varchar(20) NOT NULL default '',
  `amount` decimal(20,2) NOT NULL default '0.00',
  `note` mediumtext,
  `remark1` varchar(100) NOT NULL,
  `remark2` varchar(100) NOT NULL,
  `remark3` varchar(100) NOT NULL,
  `remark4` varchar(100) NOT NULL,
  `remark5` varchar(100) NOT NULL,
  `remark6` varchar(100) NOT NULL,
  `remark7` varchar(100) NOT NULL,
  `remark8` varchar(100) NOT NULL,
  `globaldepartment` enum('Y','N') NOT NULL default 'Y',
  `departmentcode` varchar(20) NOT NULL default '',
  `globaljob` enum('Y','N') NOT NULL default 'N',
  `jobcode` varchar(20) NOT NULL default '',
  `globalstocklocation` enum('Y','N') NOT NULL default 'Y',
  `stocklocationcode` varchar(20) NOT NULL default '',
  `itemformatkey` int(11) unsigned NOT NULL default '0',
  `created` datetime default NULL,
  `modified` datetime default NULL,
  `done` enum('Y','N') NOT NULL default 'N',
  PRIMARY KEY  (`stockobkey`),
  UNIQUE KEY `isobcode` (`stockobcode`),
  KEY `isobdate` (`stockobdate`),
  KEY `isobrefno` (`refno`),
  KEY `isobdepartmentcode` (`departmentcode`),
  KEY `isobstocklocationcode` (`stocklocationcode`),
  KEY `isobjobcode` (`jobcode`)
) ENGINE=INNODB DEFAULT CHARSET=latin1;

CREATE TABLE `stockobid` (
  `stockobkey` int(11) unsigned NOT NULL default '0',
  `id` int(11) unsigned NOT NULL default '0',
  PRIMARY KEY  (`stockobkey`,`id`)
) ENGINE=INNODB DEFAULT CHARSET=latin1;

CREATE TABLE `stockobitem` (
  `stockobkey` int(11) unsigned NOT NULL default '0',
  `stockobcode` varchar(20) NOT NULL default '',
  `id` int(11) unsigned NOT NULL default '0',
  `pos` int(11) unsigned NOT NULL default '0',
  `itemno` varchar(10) NOT NULL default '',
  `stockcode` varchar(30) NOT NULL default '',
  `descr` varchar(200) NOT NULL default '',
  `moredescr` text,
  `qty` decimal(20,6) default NULL,
  `unitprice` decimal(20,6) default NULL,
  `uom` varchar(20) NOT NULL default '',
  `uomrate` double NOT NULL default '1',
  `qtybaseuom` decimal(20,6) NOT NULL default '0.000000',
  `unitpricebaseuom` double NOT NULL default '0',
  `amount` decimal(20,2) default NULL,
  `departmentcode` varchar(20) NOT NULL default '',
  `jobcode` varchar(20) NOT NULL default '',
  `stocklocationcode` varchar(20) NOT NULL default '',
  `barcode` varchar(30) NOT NULL default '',
  `remark1` varchar(100) NOT NULL,
  `remark2` varchar(100) NOT NULL,
  `remark3` varchar(100) NOT NULL,
  `remark4` varchar(100) NOT NULL,
  `serialno` text,
  `foc` enum('Y','N') NOT NULL default 'N',
  `packingqty` decimal(20,6) default NULL,
  `packinguom` varchar(20) NOT NULL default '',
  `packingrate` decimal(20,6) default NULL,
  `batchno` varchar(30) NOT NULL default '',
  PRIMARY KEY  (`stockobkey`,`pos`),
  UNIQUE KEY `isobikeyid` (`stockobkey`,`id`),
  KEY `isobicode` (`stockobcode`),
  KEY `isobistockcode` (`stockcode`),
  KEY `isobidepartmentcode` (`departmentcode`),
  KEY `isobistocklocationcode` (`stocklocationcode`),
  KEY `isobibarcode` (`barcode`),
  KEY `isobifoc` (`foc`),
  KEY `isobibatchno` (`batchno`),
  KEY `isobijobcode` (`jobcode`)
) ENGINE=INNODB DEFAULT CHARSET=latin1;

CREATE TABLE `stockpackage` (
  `stockpackagekey` int(11) unsigned NOT NULL auto_increment,
  `stockpackagecode` varchar(20) NOT NULL default '',
  `descr` varchar(200) NOT NULL default '',
  `uom` varchar(20) NOT NULL default '',
  `validdatefrom` date default NULL,
  `validdateto` date default NULL,
  `alldebtor` enum('Y','N') NOT NULL default 'N',
  `debtorcode` varchar(20) NOT NULL default '',
  `pricecategorycode` varchar(20) NOT NULL default '',
  `unitprice` decimal(20,2) NOT NULL default '0.00',
  `note` mediumtext,
  `created` datetime default NULL,
  `modified` datetime default NULL,
  `done` enum('Y','N') NOT NULL default 'N',
  `defaultsalesgsttypecode` varchar(20) NOT NULL default '',
  `salestaxpercentage` decimal(20,2) unsigned NOT NULL default '0.00',
  `picture` mediumblob,
  `allowpointcollection` enum('Y','N') NOT NULL default 'N',
  `pointcollectionperqtybaseuom` decimal(20,2) default NULL,
  `allowpointredemption` enum('Y','N') NOT NULL default 'N',
  `pointredemptionperqtybaseuom` decimal(20,2) default NULL,
  `lastmodified` timestamp NOT NULL default CURRENT_TIMESTAMP on update CURRENT_TIMESTAMP,
  `subtractgstsales` enum('Y','N') NOT NULL default 'N',
  PRIMARY KEY  (`stockpackagekey`),
  UNIQUE KEY `istpkpackagecode` (`stockpackagecode`),
  KEY `istpkvaliddatefrom` (`validdatefrom`),
  KEY `istpkvaliddateto` (`validdateto`),
  KEY `istpkalldebtor` (`alldebtor`),
  KEY `istpkdebtorcode` (`debtorcode`),
  KEY `istpkpricecategorycode` (`pricecategorycode`),
  KEY `istpkdefaultsalesgsttypecode` (`defaultsalesgsttypecode`)
) ENGINE=INNODB DEFAULT CHARSET=latin1;

CREATE TABLE `stockpackageitem` (
  `stockpackagekey` int(11) unsigned NOT NULL default '0',
  `stockpackagecode` varchar(20) NOT NULL default '',
  `pos` int(11) unsigned NOT NULL default '0',
  `stockcode` varchar(30) NOT NULL default '',
  `descr` varchar(200) NOT NULL default '',
  `qty` decimal(20,6) default NULL,
  `unitprice` decimal(20,6) default NULL,
  `uom` varchar(20) NOT NULL default '',
  `uomrate` double NOT NULL default '1',
  `qtybaseuom` decimal(20,6) NOT NULL default '0.000000',
  `unitpricebaseuom` double NOT NULL default '0',
  `amount` decimal(20,2) default NULL,
  PRIMARY KEY  (`stockpackagekey`,`pos`),
  KEY `istpkpackagecode` (`stockpackagecode`),
  KEY `istpkstockcode` (`stockcode`)
) ENGINE=INNODB DEFAULT CHARSET=latin1;

CREATE TABLE `stockreceived` (
  `stockreceivedkey` int(11) unsigned NOT NULL auto_increment,
  `stockreceivedcode` varchar(20) NOT NULL default '',
  `stockreceiveddate` date default NULL,
  `descr` varchar(200) NOT NULL default '',
  `refno` varchar(20) NOT NULL default '',
  `amount` decimal(20,2) NOT NULL default '0.00',
  `note` mediumtext,
  `remark1` varchar(100) NOT NULL,
  `remark2` varchar(100) NOT NULL,
  `remark3` varchar(100) NOT NULL,
  `remark4` varchar(100) NOT NULL,
  `remark5` varchar(100) NOT NULL,
  `remark6` varchar(100) NOT NULL,
  `remark7` varchar(100) NOT NULL,
  `remark8` varchar(100) NOT NULL,
  `globaldepartment` enum('Y','N') NOT NULL default 'Y',
  `departmentcode` varchar(20) NOT NULL default '',
  `globaljob` enum('Y','N') NOT NULL default 'N',
  `jobcode` varchar(20) NOT NULL default '',
  `globalstocklocation` enum('Y','N') NOT NULL default 'Y',
  `stocklocationcode` varchar(20) NOT NULL default '',
  `cancelled` enum('Y','N') NOT NULL default 'N',
  `itemformatkey` int(11) unsigned NOT NULL default '0',
  `created` datetime default NULL,
  `modified` datetime default NULL,
  `done` enum('Y','N') NOT NULL default 'N',
  `postaccountvalue` enum('Y','N') NOT NULL default 'N',
  `accountjournalkey` int(11) unsigned default '0',
  `stockrefno` varchar(20) NOT NULL default '',
  `stockdescr` varchar(200) NOT NULL default '',
  `stockdepartmentcode` varchar(20) NOT NULL default '',
  `stockjobcode` varchar(20) NOT NULL default '',
  `stockacccode` varchar(20) NOT NULL default '',
  `expensesrefno` varchar(20) NOT NULL default '',
  `expensesdescr` varchar(200) NOT NULL default '',
  `expensesdepartmentcode` varchar(20) NOT NULL default '',
  `expensesjobcode` varchar(20) NOT NULL default '',
  `expensesacccode` varchar(20) NOT NULL default '',
  `fromdoctype` varchar(5) NOT NULL default '',
  `fromdockey` int(11) unsigned default '0',
  PRIMARY KEY  (`stockreceivedkey`),
  UNIQUE KEY `istrcode` (`stockreceivedcode`),
  KEY `istrdate` (`stockreceiveddate`),
  KEY `istrrefno` (`refno`),
  KEY `istrdepartmentcode` (`departmentcode`),
  KEY `istrstocklocationcode` (`stocklocationcode`),
  KEY `istrcancelled` (`cancelled`),
  KEY `istrpostaccountvalue` (`postaccountvalue`),
  KEY `istrstockdepartmentcode` (`stockdepartmentcode`),
  KEY `istrstockacccode` (`stockacccode`),
  KEY `istrexpensesdepartmentcode` (`expensesdepartmentcode`),
  KEY `istrexpensesacccode` (`expensesacccode`),
  KEY `istrjobcode` (`jobcode`),
  KEY `istrstockjobcode` (`stockjobcode`),
  KEY `istrexpensesjobcode` (`expensesjobcode`),
  KEY `istrfromdoctypekey` (`fromdoctype`,`fromdockey`)
) ENGINE=INNODB DEFAULT CHARSET=latin1;

CREATE TABLE `stockreceivedid` (
  `stockreceivedkey` int(11) unsigned NOT NULL default '0',
  `id` int(11) unsigned NOT NULL default '0',
  PRIMARY KEY  (`stockreceivedkey`,`id`)
) ENGINE=INNODB DEFAULT CHARSET=latin1;

CREATE TABLE `stockreceiveditem` (
  `stockreceivedkey` int(11) unsigned NOT NULL default '0',
  `stockreceivedcode` varchar(20) NOT NULL default '',
  `id` int(11) unsigned NOT NULL default '0',
  `pos` int(11) unsigned NOT NULL default '0',
  `itemno` varchar(10) NOT NULL default '',
  `stockcode` varchar(30) NOT NULL default '',
  `descr` varchar(200) NOT NULL default '',
  `moredescr` text,
  `qty` decimal(20,6) default NULL,
  `unitprice` decimal(20,6) default NULL,
  `uom` varchar(20) NOT NULL default '',
  `uomrate` double NOT NULL default '1',
  `qtybaseuom` decimal(20,6) NOT NULL default '0.000000',
  `unitpricebaseuom` double NOT NULL default '0',
  `amount` decimal(20,2) default NULL,
  `departmentcode` varchar(20) NOT NULL default '',
  `jobcode` varchar(20) NOT NULL default '',
  `stocklocationcode` varchar(20) NOT NULL default '',
  `barcode` varchar(30) NOT NULL default '',
  `remark1` varchar(100) NOT NULL,
  `remark2` varchar(100) NOT NULL,
  `remark3` varchar(100) NOT NULL,
  `remark4` varchar(100) NOT NULL,
  `serialno` text,
  `batchno` varchar(30) NOT NULL default '',
  `acccode` varchar(20) NOT NULL default '',
  PRIMARY KEY  (`stockreceivedkey`,`pos`),
  UNIQUE KEY `istrikeyid` (`stockreceivedkey`,`id`),
  KEY `istricode` (`stockreceivedcode`),
  KEY `istristockcode` (`stockcode`),
  KEY `istridepartmentcode` (`departmentcode`),
  KEY `istristocklocationcode` (`stocklocationcode`),
  KEY `istribarcode` (`barcode`),
  KEY `istribatchno` (`batchno`),
  KEY `istriacccode` (`acccode`),
  KEY `istrijobcode` (`jobcode`)
) ENGINE=INNODB DEFAULT CHARSET=latin1;

CREATE TABLE `stocksnin` (
  `stocksninkey` bigint(20) unsigned NOT NULL auto_increment,
  `stockcode` varchar(30) NOT NULL default '',
  `stockserialno` varchar(30) NOT NULL default '',
  `stocksnpos` int(11) unsigned NOT NULL default '0',
  `stockcodeserialno` varchar(70) NOT NULL default '',
  `doctype` varchar(5) NOT NULL default '',
  `dockey` int(11) unsigned NOT NULL default '0',
  `doccode` varchar(20) NOT NULL default '',
  `docdate` date default NULL,
  `docid` int(11) unsigned NOT NULL default '0',
  `docrefno` varchar(20) NOT NULL default '',
  `stocklocationcode` varchar(20) NOT NULL default '',
  `fromtransfered` enum('Y','N') NOT NULL default 'N',
  `fromdoctype` varchar(5) NOT NULL default '',
  `fromdockey` int(11) unsigned default NULL,
  `fromdocid` int(11) unsigned default NULL,
  `fromdoccode` varchar(20) NOT NULL default '',
  PRIMARY KEY  (`stocksninkey`),
  KEY `istsnistockcodesnpos` (`stockcode`,`stockserialno`,`stocksnpos`),
  KEY `istsnitypekeyidserialno` (`doctype`,`dockey`,`docid`,`stockserialno`),
  KEY `istsnistocklocationstockcode` (`stocklocationcode`,`stockcode`),
  KEY `istsnistockserialno` (`stockserialno`),
  KEY `istsnistockcodeserialnofromtransfered` (`stockcodeserialno`, `fromtransfered`),
  KEY `istsnitypefromtransfered` (`doctype`,`fromtransfered`),
  KEY `istsnifromtransfered` (`fromtransfered`),
  KEY `istsnifromdoctypekeypos` (`fromdoctype`,`fromdockey`,`fromdocid`),
  KEY `istsnidocdate` (`docdate`)
) ENGINE=INNODB DEFAULT CHARSET=latin1;

CREATE TABLE `stocksnout` (
  `stocksnoutkey` bigint(20) unsigned NOT NULL auto_increment,
  `stockcode` varchar(30) NOT NULL default '',
  `stockserialno` varchar(30) NOT NULL default '',
  `stocksnpos` int(11) unsigned NOT NULL default '0',
  `stockcodeserialno` varchar(70) NOT NULL default '',
  `doctype` varchar(5) NOT NULL default '',
  `dockey` int(11) unsigned NOT NULL default '0',
  `doccode` varchar(20) NOT NULL default '',
  `docdate` date default NULL,
  `docid` int(11) unsigned NOT NULL default '0',
  `docrefno` varchar(20) NOT NULL default '',
  `stocklocationcode` varchar(20) NOT NULL default '',
  `fromtransfered` enum('Y','N') NOT NULL default 'N',
  `fromdoctype` varchar(5) NOT NULL default '',
  `fromdockey` int(11) unsigned default NULL,
  `fromdocid` int(11) unsigned default NULL,
  `fromdoccode` varchar(20) NOT NULL default '',
  PRIMARY KEY  (`stocksnoutkey`),
  KEY `istsnostockcodesnpos` (`stockcode`,`stockserialno`,`stocksnpos`),
  KEY `istsnotypekeyidserialno` (`doctype`,`dockey`,`docid`,`stockserialno`),
  KEY `istsnostocklocationstockcode` (`stocklocationcode`,`stockcode`),
  KEY `istsnostockserialno` (`stockserialno`),
  KEY `istsnostockcodeserialnofromtransfered` (`stockcodeserialno`, `fromtransfered`),
  KEY `istsnotypefromtransfered` (`doctype`,`fromtransfered`),
  KEY `istsnofromtransfered` (`fromtransfered`),
  KEY `istsnofromdoctypekeypos` (`fromdoctype`,`fromdockey`,`fromdocid`),
  KEY `istsnodocdate` (`docdate`)
) ENGINE=INNODB DEFAULT CHARSET=latin1;

CREATE TABLE `stocktake` (
  `stocktakekey` int(11) unsigned NOT NULL auto_increment,
  `stocktakecode` varchar(20) NOT NULL default '',
  `stocktakedate` date default NULL,
  `descr` varchar(200) NOT NULL default '',
  `refno` varchar(20) NOT NULL default '',
  `note` mediumtext,
  `remark1` varchar(100) NOT NULL,
  `remark2` varchar(100) NOT NULL,
  `remark3` varchar(100) NOT NULL,
  `remark4` varchar(100) NOT NULL,
  `remark5` varchar(100) NOT NULL,
  `remark6` varchar(100) NOT NULL,
  `remark7` varchar(100) NOT NULL,
  `remark8` varchar(100) NOT NULL,
  `departmentcode` varchar(20) NOT NULL default '',
  `globaljob` enum('Y','N') NOT NULL default 'N',
  `jobcode` varchar(20) NOT NULL default '',
  `stocklocationcode` varchar(20) NOT NULL default '',
  `closed` enum('Y','N') NOT NULL default 'N',
  `itemformatkey` int(11) unsigned NOT NULL default '0',
  `created` datetime default NULL,
  `modified` datetime default NULL,
  `done` enum('Y','N') NOT NULL default 'N',
  `globaldepartment` enum('Y','N') NOT NULL default 'Y',
  `globalstocklocation` enum('Y','N') NOT NULL default 'Y',
  `usedatacollector` enum('Y','N') NOT NULL default 'N',
  `creditorcode` varchar(20) NOT NULL default '',
  PRIMARY KEY  (`stocktakekey`),
  UNIQUE KEY `istkcode` (`stocktakecode`),
  KEY `istkdate` (`stocktakedate`),
  KEY `istkrefno` (`refno`),
  KEY `istkdepartmentcode` (`departmentcode`),
  KEY `istkstocklocationcode` (`stocklocationcode`),
  KEY `istkclosed` (`closed`),
  KEY `istkjobcode` (`jobcode`),
  KEY `istkcreditorcode` (`creditorcode`)
) ENGINE=INNODB DEFAULT CHARSET=latin1;

CREATE TABLE `stocktakeid` (
  `stocktakekey` int(11) unsigned NOT NULL default '0',
  `id` int(11) unsigned NOT NULL default '0',
  PRIMARY KEY  (`stocktakekey`,`id`)
) ENGINE=INNODB DEFAULT CHARSET=latin1;

CREATE TABLE `stocktakeitem` (
  `stocktakekey` int(11) unsigned NOT NULL default '0',
  `stocktakecode` varchar(20) NOT NULL default '',
  `id` int(11) unsigned NOT NULL default '0',
  `pos` int(11) unsigned NOT NULL default '0',
  `itemno` varchar(10) NOT NULL default '',
  `stockcode` varchar(30) NOT NULL default '',
  `descr` varchar(200) NOT NULL default '',
  `moredescr` text,
  `sysqty` decimal(20,6) default NULL,
  `sysuom` varchar(20) NOT NULL default '',
  `sysuomrate` double NOT NULL default '1',
  `sysqtybaseuom` decimal(20,6) NOT NULL default '0.000000',
  `actualqty` decimal(20,6) default NULL,
  `actualuom` varchar(20) NOT NULL default '',
  `actualuomrate` double NOT NULL default '1',
  `actualqtybaseuom` decimal(20,6) NOT NULL default '0.000000',
  `barcode` varchar(30) NOT NULL default '',
  `remark1` varchar(100) NOT NULL,
  `remark2` varchar(100) NOT NULL,
  `remark3` varchar(100) NOT NULL,
  `remark4` varchar(100) NOT NULL,
  `beginstocktake` datetime default NULL,
  `endstocktake` datetime default NULL,
  `adjustsysqtybaseuom` decimal(20,6) default NULL,
  PRIMARY KEY  (`stocktakekey`,`pos`),
  UNIQUE KEY `istkikeyid` (`stocktakekey`,`id`),
  KEY `istkicode` (`stocktakecode`),
  KEY `istkistockcode` (`stockcode`),
  KEY `istkibarcode` (`barcode`)
) ENGINE=INNODB DEFAULT CHARSET=latin1;

CREATE TABLE `stocktrans` (
  `stocktranskey` bigint(20) unsigned NOT NULL auto_increment,
  `stocktransdate` date default NULL,
  `descr` varchar(200) NOT NULL default '',
  `stockcode` varchar(30) NOT NULL default '',
  `stocklocationcode` varchar(20) NOT NULL default '',
  `qtybaseuom` decimal(20,6) NOT NULL default '0.000000',
  `costbaseuom` double NOT NULL default '0',
  `uomrate` double NOT NULL default '0',
  `uomother` varchar(20) NOT NULL default '',
  `qtyotheruom` decimal(20,6) NOT NULL default '0.000000',
  `costotheruom` double NOT NULL default '0',
  `stockvalue` decimal(20,2) NOT NULL default '0.00',
  `doctype` varchar(5) NOT NULL default '',
  `dockey` int(11) unsigned NOT NULL default '0',
  `doccode` varchar(20) NOT NULL default '',
  `docpos` int(11) unsigned NOT NULL default '0',
  `docid` int(11) unsigned NOT NULL default '0',
  `docrefno` varchar(20) NOT NULL default '',
  `debtorcode` varchar(20) NOT NULL default '',
  `creditorcode` varchar(20) NOT NULL default '',
  `remark1` varchar(100) NOT NULL default '',
  `remark2` varchar(100) NOT NULL default '',
  `remark3` varchar(100) NOT NULL default '',
  `remark4` varchar(100) NOT NULL default '',
  `departmentcode` varchar(20) NOT NULL default '',
  `jobcode` varchar(20) NOT NULL default '',
  `fromtransfered` enum('Y','N') NOT NULL default 'N',
  `deleted` enum('Y','N') NOT NULL default 'N',
  `batchno` varchar(30) NOT NULL default '',
  `serverdatetime` datetime default NULL,
  PRIMARY KEY  (`stocktranskey`),
  KEY `istdate` (`stocktransdate`),
  KEY `iststockcode` (`stockcode`),
  KEY `iststocklocationcode` (`stocklocationcode`),
  KEY `istdoctypekeypos` (`doctype`,`dockey`,`docpos`),
  KEY `istdoctypecodepos` (`doctype`,`doccode`,`docpos`),
  KEY `istdoctypekeyid` (`doctype`,`dockey`,`docid`),
  KEY `istdoctypecodeid` (`doctype`,`doccode`,`docid`),
  KEY `istfromtransfered` (`fromtransfered`),
  KEY `istdepartmentcode` (`departmentcode`),
  KEY `istdeleted` (`deleted`),
  KEY `istbatchno` (`batchno`),
  KEY `istserverdatetime` (`serverdatetime`),
  KEY `istjobcode` (`jobcode`),
  KEY `istdebtorcode` (`debtorcode`),
  KEY `istcreditorcode` (`creditorcode`)
) ENGINE=INNODB DEFAULT CHARSET=latin1;

CREATE TABLE `stocktransfer` (
  `stocktransferkey` int(11) unsigned NOT NULL auto_increment,
  `stocktransfercode` varchar(20) NOT NULL default '',
  `stocktransferdate` date default NULL,
  `descr` varchar(200) NOT NULL default '',
  `refno` varchar(20) NOT NULL default '',
  `amount` decimal(20,2) NOT NULL default '0.00',
  `note` mediumtext,
  `remark1` varchar(100) NOT NULL,
  `remark2` varchar(100) NOT NULL,
  `remark3` varchar(100) NOT NULL,
  `remark4` varchar(100) NOT NULL,
  `remark5` varchar(100) NOT NULL,
  `remark6` varchar(100) NOT NULL,
  `remark7` varchar(100) NOT NULL,
  `remark8` varchar(100) NOT NULL,
  `fromdepartmentcode` varchar(20) NOT NULL default '',
  `todepartmentcode` varchar(20) NOT NULL default '',
  `fromjobcode` varchar(20) NOT NULL default '',
  `tojobcode` varchar(20) NOT NULL default '',
  `fromstocklocationcode` varchar(20) NOT NULL default '',
  `tostocklocationcode` varchar(20) NOT NULL default '',
  `cancelled` enum('Y','N') NOT NULL default 'N',
  `itemformatkey` int(11) unsigned NOT NULL default '0',
  `created` datetime default NULL,
  `modified` datetime default NULL,
  `done` enum('Y','N') NOT NULL default 'N',
  `postaccountvalue` enum('Y','N') NOT NULL default 'N',
  `accountjournalkey` int(11) unsigned default '0',
  `stockrefno` varchar(20) NOT NULL default '',
  `stockdescr` varchar(200) NOT NULL default '',
  `stockdepartmentcode` varchar(20) NOT NULL default '',
  `stockjobcode` varchar(20) NOT NULL default '',
  `stockacccode` varchar(20) NOT NULL default '',
  `expensesrefno` varchar(20) NOT NULL default '',
  `expensesdescr` varchar(200) NOT NULL default '',
  `expensesdepartmentcode` varchar(20) NOT NULL default '',
  `expensesjobcode` varchar(20) NOT NULL default '',
  `expensesacccode` varchar(20) NOT NULL default '',
  `fromdoctype` varchar(5) NOT NULL default '',
  `fromdockey` int(11) unsigned default NULL,
  `globaldepartment` enum('Y','N') NOT NULL default 'Y',
  `globalstocklocation` enum('Y','N') NOT NULL default 'Y',
  `globaljob` enum('Y','N') NOT NULL default 'Y',
  PRIMARY KEY  (`stocktransferkey`),
  UNIQUE KEY `istfcode` (`stocktransfercode`),
  KEY `istfdate` (`stocktransferdate`),
  KEY `istfrefno` (`refno`),
  KEY `istffromdepartmentcode` (`fromdepartmentcode`),
  KEY `istftodepartmentcode` (`todepartmentcode`),
  KEY `istffromstocklocationcode` (`fromstocklocationcode`),
  KEY `istftostocklocationcode` (`tostocklocationcode`),
  KEY `istfcancelled` (`cancelled`),
  KEY `istfpostaccountvalue` (`postaccountvalue`),
  KEY `istfstockdepartmentcode` (`stockdepartmentcode`),
  KEY `istfstockacccode` (`stockacccode`),
  KEY `istfexpensesdepartmentcode` (`expensesdepartmentcode`),
  KEY `istfexpensesacccode` (`expensesacccode`),
  KEY `istffromjobcode` (`fromjobcode`),
  KEY `istftojobcode` (`tojobcode`),
  KEY `istfstockjobcode` (`stockjobcode`),
  KEY `istfexpensesjobcode` (`expensesjobcode`),
  KEY `istffromdoctypekey` (`fromdoctype`,`fromdockey`)
) ENGINE=INNODB DEFAULT CHARSET=latin1;

CREATE TABLE `stocktransferid` (
  `stocktransferkey` int(11) unsigned NOT NULL default '0',
  `id` int(11) unsigned NOT NULL default '0',
  PRIMARY KEY  (`stocktransferkey`,`id`)
) ENGINE=INNODB DEFAULT CHARSET=latin1;

CREATE TABLE `stocktransferitem` (
  `stocktransferkey` int(11) unsigned NOT NULL default '0',
  `stocktransfercode` varchar(20) NOT NULL default '',
  `id` int(11) unsigned NOT NULL default '0',
  `pos` int(11) unsigned NOT NULL default '0',
  `itemno` varchar(10) NOT NULL default '',
  `stockcode` varchar(30) NOT NULL default '',
  `descr` varchar(200) NOT NULL default '',
  `moredescr` text,
  `qty` decimal(20,6) default NULL,
  `unitprice` decimal(20,6) default NULL,
  `uom` varchar(20) NOT NULL default '',
  `uomrate` double NOT NULL default '1',
  `qtybaseuom` decimal(20,6) NOT NULL default '0.000000',
  `unitpricebaseuom` double NOT NULL default '0',
  `amount` decimal(20,2) default NULL,
  `barcode` varchar(30) NOT NULL default '',
  `remark1` varchar(100) NOT NULL,
  `remark2` varchar(100) NOT NULL,
  `remark3` varchar(100) NOT NULL,
  `remark4` varchar(100) NOT NULL,
  `serialno` text,
  `packingqty` decimal(20,6) default NULL,
  `packinguom` varchar(20) NOT NULL default '',
  `packingrate` decimal(20,6) default NULL,
  `batchno` varchar(30) NOT NULL default '',
  `fromdepartmentcode` varchar(20) NOT NULL default '',
  `todepartmentcode` varchar(20) NOT NULL default '',
  `fromjobcode` varchar(20) NOT NULL default '',
  `tojobcode` varchar(20) NOT NULL default '',
  `fromstocklocationcode` varchar(20) NOT NULL default '',
  `tostocklocationcode` varchar(20) NOT NULL default '',
  PRIMARY KEY  (`stocktransferkey`,`pos`),
  UNIQUE KEY `istfikeyid` (`stocktransferkey`,`id`),
  KEY `istficode` (`stocktransfercode`),
  KEY `istfistockcode` (`stockcode`),
  KEY `istfibarcode` (`barcode`),
  KEY `istfiibatchno` (`batchno`),
  KEY `istifromdepartmentcode` (`fromdepartmentcode`),
  KEY `istitodepartmentcode` (`todepartmentcode`),
  KEY `istifromjobcode` (`fromjobcode`),
  KEY `istitojobcode` (`tojobcode`),
  KEY `istifromstocklocationcode` (`fromstocklocationcode`),
  KEY `istitostocklocationcode` (`tostocklocationcode`)
) ENGINE=INNODB DEFAULT CHARSET=latin1;

CREATE TABLE `stockuom` (
  `stockkey` int(11) unsigned NOT NULL,
  `stockcode` varchar(30) NOT NULL default '',
  `pos` int(11) unsigned NOT NULL default '0',
  `uom` varchar(20) NOT NULL default '',
  `rateperbaseuom` decimal(20,6) unsigned NOT NULL default '0.000000',
  `salesprice` decimal(20,6) unsigned NOT NULL default '0.000000',
  `minimumprice` decimal(20,6) unsigned NOT NULL default '0.000000',
  `purchasesprice` decimal(20,6) unsigned NOT NULL default '0.000000',
  `packing` enum('Y','N') NOT NULL default 'N',
  `name` varchar(200) NOT NULL,
  `barcode` varchar(30) NOT NULL,
  PRIMARY KEY  USING BTREE (`stockkey`,`pos`),
  KEY `istuombarcode` (`barcode`),
  KEY `istuomstockcodeuom` (`stockcode`,`uom`)
) ENGINE=INNODB DEFAULT CHARSET=latin1;

CREATE TABLE `supervisor` (
  `supervisorkey` int(11) unsigned NOT NULL auto_increment,
  `supervisorcode` varchar(20) NOT NULL default '',
  `descr` varchar(200) NOT NULL default '',
  `position` varchar(200) NOT NULL default '',
  `pwd` blob NOT NULL,
  `inactive` enum('Y','N') NOT NULL default 'N',
  `done` enum('Y','N') NOT NULL default 'N',
  `allowdiscount` enum('Y','N') NOT NULL default 'Y',
  `allowchangeunitprice` enum('Y','N') NOT NULL default 'Y',
  `allowchangeuom` enum('Y','N') NOT NULL default 'Y',
  `allowchangecustomer` enum('Y','N') NOT NULL default 'Y',
  `allowcancelreceipt` enum('Y','N') NOT NULL default 'Y',
  `allowdeleterow` enum('Y','N') NOT NULL default 'Y',
  `allowreprintreceipt` enum('Y','N') NOT NULL default 'Y',
  `allowvoidreceipt` enum('Y','N') NOT NULL default 'Y',
  `allowdepositrefund` enum('Y','N') NOT NULL default 'Y',
  `allowfreeitem` enum('Y','N') NOT NULL default 'Y',
  `addmemberdebitcardvalue` enum('Y','N') NOT NULL default 'Y',
  `addmemberdebitcardadjvalue` enum('Y','N') NOT NULL default 'Y',
  `allownegativeqty` enum('Y','N') NOT NULL default 'Y',
  `allownegativebalance` enum('Y','N') NOT NULL default 'Y',
  `allowcustomizeitemformat` enum('Y','N') NOT NULL default 'Y',
  `allowexceedmaxdiscount` enum('Y','N') NOT NULL default 'Y',
  `allowbelowcost` enum('Y','N') NOT NULL default 'Y',
  `allowbelowminprice` enum('Y','N') NOT NULL default 'Y',
  `allowopencashdrawer` enum('Y','N') NOT NULL default 'Y',
  `allowopensalescn` enum('Y','N') NOT NULL default 'Y',
  `allowaddmember` enum('Y','N') NOT NULL default 'Y',
  `lastmodified` timestamp NOT NULL default CURRENT_TIMESTAMP on update CURRENT_TIMESTAMP,
  `allowchangegst` enum('Y','N') NOT NULL default 'Y',
  PRIMARY KEY  (`supervisorkey`),
  UNIQUE KEY `ispvcode` (`supervisorcode`),
  KEY `ispvinactive` (`inactive`)
) ENGINE=INNODB DEFAULT CHARSET=latin1;

CREATE TABLE `supplierconsignmentreceived` (
  `supplierconsignmentreceivedkey` int(11) unsigned NOT NULL auto_increment,
  `supplierconsignmentreceivedcode` varchar(20) NOT NULL default '',
  `supplierconsignmentreceiveddate` date default NULL,
  `consignmenttypecode` varchar(20) NOT NULL default '',
  `reason` varchar(200) NOT NULL default '',
  `durationindays` int(11) unsigned NOT NULL default '0',
  `creditorcode` varchar(20) NOT NULL default '',
  `termcode` varchar(20) NOT NULL default '',
  `staffcode` varchar(20) NOT NULL default '',
  `areacode` varchar(20) NOT NULL default '',
  `descr` varchar(200) NOT NULL default '',
  `validity` varchar(100) NOT NULL default '',
  `deliveryterm` varchar(100) NOT NULL default '',
  `refno` varchar(20) NOT NULL default '',
  `address1` varchar(200) NOT NULL default '',
  `address2` varchar(200) NOT NULL default '',
  `address3` varchar(200) NOT NULL default '',
  `address4` varchar(200) NOT NULL default '',
  `attention` varchar(200) NOT NULL default '',
  `phone` varchar(30) NOT NULL default '',
  `fax` varchar(30) NOT NULL default '',
  `discountamount` decimal(20,2) NOT NULL,
  `amountbeforediscount` decimal(20,2) NOT NULL,
  `amount` decimal(20,2) NOT NULL default '0.00',
  `taxamount` decimal(20,2) NOT NULL default '0.00',
  `amountaftertax` decimal(20,2) NOT NULL default '0.00',
  `localtaxamount` decimal(20,2) NOT NULL default '0.00',
  `localamountaftertax` decimal(20,2) NOT NULL default '0.00',
  `note` mediumtext,
  `remark1` varchar(100) NOT NULL,
  `remark2` varchar(100) NOT NULL,
  `remark3` varchar(100) NOT NULL,
  `remark4` varchar(100) NOT NULL,
  `remark5` varchar(100) NOT NULL,
  `remark6` varchar(100) NOT NULL,
  `remark7` varchar(100) NOT NULL,
  `remark8` varchar(100) NOT NULL,
  `globaldepartment` enum('Y','N') NOT NULL default 'Y',
  `departmentcode` varchar(20) NOT NULL default '',
  `globaljob` enum('Y','N') NOT NULL default 'N',
  `jobcode` varchar(20) NOT NULL default '',
  `globalstocklocation` enum('Y','N') NOT NULL default 'Y',
  `stocklocationcode` varchar(20) NOT NULL default '',
  `cancelled` enum('Y','N') NOT NULL default 'N',
  `itemformatkey` int(11) unsigned NOT NULL default '0',
  `created` datetime default NULL,
  `modified` datetime default NULL,
  `done` enum('Y','N') NOT NULL default 'N',
  `lcost1` decimal(20,2) NOT NULL default '0.00',
  `lcost2` decimal(20,2) NOT NULL default '0.00',
  `lcost3` decimal(20,2) NOT NULL default '0.00',
  `curcode` varchar(20) NOT NULL,
  `currate` decimal(20,8) unsigned NOT NULL default '1.00000000',
  `localdiscountamount` decimal(20,2) NOT NULL,
  `localamountbeforediscount` decimal(20,2) NOT NULL,
  `localamount` decimal(20,2) NOT NULL default '0.00',
  `locallcost1` decimal(20,2) NOT NULL default '0.00',
  `locallcost2` decimal(20,2) NOT NULL default '0.00',
  `locallcost3` decimal(20,2) NOT NULL default '0.00',
  `ref1` varchar(30) NOT NULL,
  `ref2` varchar(30) NOT NULL,
  `ref3` varchar(30) NOT NULL,
  `ref4` varchar(30) NOT NULL,
  `lastmodified` timestamp NOT NULL default CURRENT_TIMESTAMP on update CURRENT_TIMESTAMP,
  `creditorname` varchar(200) NOT NULL default '',
  `city` varchar(50) NOT NULL default '',
  `postalcode` varchar(10) NOT NULL default '',
  `state` varchar(50) NOT NULL default '',
  `countrycode` varchar(50) NOT NULL default '',
  `branchcode` varchar(20) NOT NULL default '',
  `branchname` varchar(200) NOT NULL default '',
  `branchcontactperson` varchar(200) NOT NULL default '',
  `branchphone` varchar(30) NOT NULL default '',
  `branchfax` varchar(30) NOT NULL default '',
  `branchemail` varchar(200) NOT NULL default '',
  `branchaddress1` varchar(200) NOT NULL default '',
  `branchaddress2` varchar(200) NOT NULL default '',
  `branchaddress3` varchar(200) NOT NULL default '',
  `branchaddress4` varchar(200) NOT NULL default '',
  `branchcity` varchar(50) NOT NULL default '',
  `branchpostalcode` varchar(10) NOT NULL default '',
  `branchstate` varchar(50) NOT NULL default '',
  `branchcountrycode` varchar(50) NOT NULL default '',
  `fromoldversion` enum('Y','N') NOT NULL default 'N',
  PRIMARY KEY  (`supplierconsignmentreceivedkey`),
  UNIQUE KEY `iscrcode` (`supplierconsignmentreceivedcode`),
  KEY `iscrdate` (`supplierconsignmentreceiveddate`),
  KEY `iscrconsignmenttypecode` (`consignmenttypecode`),
  KEY `iscrcreditorcode` (`creditorcode`),
  KEY `iscrtermcode` (`termcode`),
  KEY `iscrstaffcode` (`staffcode`),
  KEY `iscrrefno` (`refno`),
  KEY `iscrdepartmentcode` (`departmentcode`),
  KEY `iscrstocklocationcode` (`stocklocationcode`),
  KEY `iscrcancelled` (`cancelled`),
  KEY `iscrareacode` (`areacode`),
  KEY `iscrcurcode` (`curcode`),
  KEY `iscrjobcode` (`jobcode`),
  KEY `iscrcountrycode` (`countrycode`),
  KEY `iscrbranchcountrycode` (`branchcountrycode`)
) ENGINE=INNODB DEFAULT CHARSET=latin1;

CREATE TABLE `supplierconsignmentreceivedid` (
  `supplierconsignmentreceivedkey` int(11) unsigned NOT NULL default '0',
  `id` int(11) unsigned NOT NULL default '0',
  PRIMARY KEY  (`supplierconsignmentreceivedkey`,`id`)
) ENGINE=INNODB DEFAULT CHARSET=latin1;

CREATE TABLE `supplierconsignmentreceiveditem` (
  `supplierconsignmentreceivedkey` int(11) unsigned NOT NULL default '0',
  `supplierconsignmentreceivedcode` varchar(20) NOT NULL default '',
  `id` int(11) unsigned NOT NULL default '0',
  `pos` int(11) unsigned NOT NULL default '0',
  `itemno` varchar(10) NOT NULL default '',
  `stockcode` varchar(30) NOT NULL default '',
  `descr` varchar(200) NOT NULL default '',
  `moredescr` text,
  `qty` decimal(20,6) default NULL,
  `unitprice` decimal(20,6) default NULL,
  `uom` varchar(20) NOT NULL default '',
  `uomrate` double NOT NULL default '1',
  `qtybaseuom` decimal(20,6) NOT NULL default '0.000000',
  `unitpricebaseuom` double NOT NULL default '0',
  `discountformat` varchar(100) default NULL,
  `discountamount` decimal(20,2) default NULL,
  `amountbeforediscount` decimal(20,2) default NULL,
  `amount` decimal(20,2) default NULL,
  `gsttypecode` varchar(20) NOT NULL default '',
  `purchasestaxpercentage` decimal(20,2) default NULL,
  `purchasestaxamount` decimal(20,2) default NULL,
  `amountaftertax` decimal(20,2) default NULL,
  `departmentcode` varchar(20) NOT NULL default '',
  `jobcode` varchar(20) NOT NULL default '',
  `stocklocationcode` varchar(20) NOT NULL default '',
  `creditoritemcode` varchar(30) NOT NULL default '',
  `barcode` varchar(30) NOT NULL default '',
  `remark1` varchar(100) NOT NULL,
  `remark2` varchar(100) NOT NULL,
  `remark3` varchar(100) NOT NULL,
  `remark4` varchar(100) NOT NULL,
  `rowtype` enum('','TOTALUP','ITEMDISCOUNT','ITEMSERVICETAX','ITEMMISCCHARGES','FOOTERDISCOUNT','FOOTERSERVICETAX','FOOTERMISCCHARGES') NOT NULL,
  `foc` enum('Y','N') NOT NULL default 'N',
  `packingqty` decimal(20,6) default NULL,
  `packinguom` varchar(20) NOT NULL default '',
  `packingrate` decimal(20,6) default NULL,
  `lcost1` decimal(20,2) default NULL,
  `lcost2` decimal(20,2) default NULL,
  `lcost3` decimal(20,2) default NULL,
  `batchno` varchar(30) NOT NULL default '',
  `curcode` varchar(20) NOT NULL default '',
  `curprice` decimal(20,6) default NULL,
  `currate` decimal(20,8) unsigned default NULL,
  `recommendpricebaseuom` decimal(20,6) unsigned NOT NULL default '0.000000',
  `weightrate` decimal(20,6) unsigned NOT NULL default '0.000000',
  `weightuom` varchar(20) NOT NULL default '',
  `weightqty` decimal(20,6) unsigned NOT NULL default '0.000000',
  `weightloosed` decimal(20,6) unsigned NOT NULL default '0.000000',
  `totalweight` decimal(20,6) unsigned NOT NULL default '0.000000',
  `volumerate` decimal(20,6) unsigned NOT NULL default '0.000000',
  `volumeuom` varchar(20) NOT NULL default '',
  `volumeqty` decimal(20,6) unsigned NOT NULL default '0.000000',
  `volumeloosed` decimal(20,6) unsigned NOT NULL default '0.000000',
  `totalvolume` decimal(20,6) unsigned NOT NULL default '0.000000',
  `lcosttype1` enum('Value','Quantity') NOT NULL default 'Value',
  `lcosttype2` enum('Value','Quantity') NOT NULL default 'Value',
  `lcosttype3` enum('Value','Quantity') NOT NULL default 'Value',
  `supplypurchase` enum('None','Supply','Purchase') NOT NULL default 'None',
  `taxsubtract` enum('Y','N') NOT NULL default 'N',
  `taxableamount` decimal(20,2) NOT NULL default '0.00',
  `taxablelocalamount` decimal(20,2) NOT NULL default '0.00',
  `amountaftertaxsubtract` decimal(20,2) NOT NULL default '0.00',
  `localamountaftertaxsubtract` decimal(20,2) NOT NULL default '0.00',
  `purchasestaxlocalamount` decimal(20,2) NOT NULL default '0.00',
  `taxadjustment` decimal(20,2) NOT NULL default '0.00',
  `taxlocaladjustment` decimal(20,2) NOT NULL default '0.00',
  `taxtotalamount` decimal(20,2) NOT NULL default '0.00',
  `taxtotallocalamount` decimal(20,2) NOT NULL default '0.00',
  PRIMARY KEY  (`supplierconsignmentreceivedkey`,`pos`),
  UNIQUE KEY `iscrikeyid` (`supplierconsignmentreceivedkey`,`id`),
  KEY `iscricode` (`supplierconsignmentreceivedcode`),
  KEY `iscristockcode` (`stockcode`),
  KEY `iscridepartmentcode` (`departmentcode`),
  KEY `iscristocklocationcode` (`stocklocationcode`),
  KEY `iscribarcode` (`barcode`),
  KEY `iscrifoc` (`foc`),
  KEY `iscribatchno` (`batchno`),
  KEY `iscrijobcode` (`jobcode`),
  KEY `iscrigsttypecode` (`gsttypecode`)
) ENGINE=INNODB DEFAULT CHARSET=latin1;

CREATE TABLE `supplierconsignmentreturn` (
  `supplierconsignmentreturnkey` int(11) unsigned NOT NULL auto_increment,
  `supplierconsignmentreturncode` varchar(20) NOT NULL default '',
  `supplierconsignmentreturndate` date default NULL,
  `consignmenttypecode` varchar(20) NOT NULL default '',
  `reason` varchar(200) NOT NULL default '',
  `inspection` varchar(200) NOT NULL default '',
  `creditorcode` varchar(20) NOT NULL default '',
  `termcode` varchar(20) NOT NULL default '',
  `staffcode` varchar(20) NOT NULL default '',
  `areacode` varchar(20) NOT NULL default '',
  `descr` varchar(200) NOT NULL default '',
  `validity` varchar(100) NOT NULL default '',
  `deliveryterm` varchar(100) NOT NULL default '',
  `refno` varchar(20) NOT NULL default '',
  `address1` varchar(200) NOT NULL default '',
  `address2` varchar(200) NOT NULL default '',
  `address3` varchar(200) NOT NULL default '',
  `address4` varchar(200) NOT NULL default '',
  `attention` varchar(200) NOT NULL default '',
  `phone` varchar(30) NOT NULL default '',
  `fax` varchar(30) NOT NULL default '',
  `discountamount` decimal(20,2) NOT NULL,
  `amountbeforediscount` decimal(20,2) NOT NULL,
  `amount` decimal(20,2) NOT NULL default '0.00',
  `taxamount` decimal(20,2) NOT NULL default '0.00',
  `amountaftertax` decimal(20,2) NOT NULL default '0.00',
  `localtaxamount` decimal(20,2) NOT NULL default '0.00',
  `localamountaftertax` decimal(20,2) NOT NULL default '0.00',
  `note` mediumtext,
  `remark1` varchar(100) NOT NULL,
  `remark2` varchar(100) NOT NULL,
  `remark3` varchar(100) NOT NULL,
  `remark4` varchar(100) NOT NULL,
  `remark5` varchar(100) NOT NULL,
  `remark6` varchar(100) NOT NULL,
  `remark7` varchar(100) NOT NULL,
  `remark8` varchar(100) NOT NULL,
  `globaldepartment` enum('Y','N') NOT NULL default 'Y',
  `departmentcode` varchar(20) NOT NULL default '',
  `globaljob` enum('Y','N') NOT NULL default 'N',
  `jobcode` varchar(20) NOT NULL default '',
  `globalstocklocation` enum('Y','N') NOT NULL default 'Y',
  `stocklocationcode` varchar(20) NOT NULL default '',
  `cancelled` enum('Y','N') NOT NULL default 'N',
  `itemformatkey` int(11) unsigned NOT NULL default '0',
  `created` datetime default NULL,
  `modified` datetime default NULL,
  `done` enum('Y','N') NOT NULL default 'N',
  `lcost1` decimal(20,2) NOT NULL default '0.00',
  `lcost2` decimal(20,2) NOT NULL default '0.00',
  `lcost3` decimal(20,2) NOT NULL default '0.00',
  `curcode` varchar(20) NOT NULL,
  `currate` decimal(20,8) unsigned NOT NULL default '1.00000000',
  `localdiscountamount` decimal(20,2) NOT NULL,
  `localamountbeforediscount` decimal(20,2) NOT NULL,
  `localamount` decimal(20,2) NOT NULL default '0.00',
  `locallcost1` decimal(20,2) NOT NULL default '0.00',
  `locallcost2` decimal(20,2) NOT NULL default '0.00',
  `locallcost3` decimal(20,2) NOT NULL default '0.00',
  `ref1` varchar(30) NOT NULL,
  `ref2` varchar(30) NOT NULL,
  `ref3` varchar(30) NOT NULL,
  `ref4` varchar(30) NOT NULL,
  `lastmodified` timestamp NOT NULL default CURRENT_TIMESTAMP on update CURRENT_TIMESTAMP,
  `creditorname` varchar(200) NOT NULL default '',
  `city` varchar(50) NOT NULL default '',
  `postalcode` varchar(10) NOT NULL default '',
  `state` varchar(50) NOT NULL default '',
  `countrycode` varchar(50) NOT NULL default '',
  `branchcode` varchar(20) NOT NULL default '',
  `branchname` varchar(200) NOT NULL default '',
  `branchcontactperson` varchar(200) NOT NULL default '',
  `branchphone` varchar(30) NOT NULL default '',
  `branchfax` varchar(30) NOT NULL default '',
  `branchemail` varchar(200) NOT NULL default '',
  `branchaddress1` varchar(200) NOT NULL default '',
  `branchaddress2` varchar(200) NOT NULL default '',
  `branchaddress3` varchar(200) NOT NULL default '',
  `branchaddress4` varchar(200) NOT NULL default '',
  `branchcity` varchar(50) NOT NULL default '',
  `branchpostalcode` varchar(10) NOT NULL default '',
  `branchstate` varchar(50) NOT NULL default '',
  `branchcountrycode` varchar(50) NOT NULL default '',
  `fromoldversion` enum('Y','N') NOT NULL default 'N',
  PRIMARY KEY  (`supplierconsignmentreturnkey`),
  UNIQUE KEY `iscrcode` (`supplierconsignmentreturncode`),
  KEY `isctdate` (`supplierconsignmentreturndate`),
  KEY `isctconsignmenttypecode` (`consignmenttypecode`),
  KEY `isctcreditorcode` (`creditorcode`),
  KEY `iscttermcode` (`termcode`),
  KEY `isctstaffcode` (`staffcode`),
  KEY `isctrefno` (`refno`),
  KEY `isctdepartmentcode` (`departmentcode`),
  KEY `isctstocklocationcode` (`stocklocationcode`),
  KEY `isctcancelled` (`cancelled`),
  KEY `isctareacode` (`areacode`),
  KEY `isctcurcode` (`curcode`),
  KEY `isctjobcode` (`jobcode`),
  KEY `iscrtcountrycode` (`countrycode`),
  KEY `iscrtbranchcountrycode` (`branchcountrycode`)
) ENGINE=INNODB DEFAULT CHARSET=latin1;

CREATE TABLE `supplierconsignmentreturnid` (
  `supplierconsignmentreturnkey` int(11) unsigned NOT NULL default '0',
  `id` int(11) unsigned NOT NULL default '0',
  PRIMARY KEY  (`supplierconsignmentreturnkey`,`id`)
) ENGINE=INNODB DEFAULT CHARSET=latin1;

CREATE TABLE `supplierconsignmentreturnitem` (
  `supplierconsignmentreturnkey` int(11) unsigned NOT NULL default '0',
  `supplierconsignmentreturncode` varchar(20) NOT NULL default '',
  `id` int(11) unsigned NOT NULL default '0',
  `pos` int(11) unsigned NOT NULL default '0',
  `itemno` varchar(10) NOT NULL default '',
  `stockcode` varchar(30) NOT NULL default '',
  `descr` varchar(200) NOT NULL default '',
  `moredescr` text,
  `qty` decimal(20,6) default NULL,
  `unitprice` decimal(20,6) default NULL,
  `uom` varchar(20) NOT NULL default '',
  `uomrate` double NOT NULL default '1',
  `qtybaseuom` decimal(20,6) NOT NULL default '0.000000',
  `unitpricebaseuom` double NOT NULL default '0',
  `discountformat` varchar(100) default NULL,
  `discountamount` decimal(20,2) default NULL,
  `amountbeforediscount` decimal(20,2) default NULL,
  `amount` decimal(20,2) default NULL,
  `gsttypecode` varchar(20) NOT NULL default '',
  `purchasestaxpercentage` decimal(20,2) default NULL,
  `purchasestaxamount` decimal(20,2) default NULL,
  `amountaftertax` decimal(20,2) default NULL,
  `departmentcode` varchar(20) NOT NULL default '',
  `jobcode` varchar(20) NOT NULL default '',
  `stocklocationcode` varchar(20) NOT NULL default '',
  `creditoritemcode` varchar(30) NOT NULL default '',
  `barcode` varchar(30) NOT NULL default '',
  `remark1` varchar(100) NOT NULL,
  `remark2` varchar(100) NOT NULL,
  `remark3` varchar(100) NOT NULL,
  `remark4` varchar(100) NOT NULL,
  `rowtype` enum('','TOTALUP','ITEMDISCOUNT','ITEMSERVICETAX','ITEMMISCCHARGES','FOOTERDISCOUNT','FOOTERSERVICETAX','FOOTERMISCCHARGES') NOT NULL,
  `foc` enum('Y','N') NOT NULL default 'N',
  `packingqty` decimal(20,6) default NULL,
  `packinguom` varchar(20) NOT NULL default '',
  `packingrate` decimal(20,6) default NULL,
  `lcost1` decimal(20,2) default NULL,
  `lcost2` decimal(20,2) default NULL,
  `lcost3` decimal(20,2) default NULL,
  `batchno` varchar(30) NOT NULL default '',
  `curcode` varchar(20) NOT NULL default '',
  `curprice` decimal(20,6) default NULL,
  `currate` decimal(20,8) unsigned default NULL,
  `recommendpricebaseuom` decimal(20,6) unsigned NOT NULL default '0.000000',
  `weightrate` decimal(20,6) unsigned NOT NULL default '0.000000',
  `weightuom` varchar(20) NOT NULL default '',
  `weightqty` decimal(20,6) unsigned NOT NULL default '0.000000',
  `weightloosed` decimal(20,6) unsigned NOT NULL default '0.000000',
  `totalweight` decimal(20,6) unsigned NOT NULL default '0.000000',
  `volumerate` decimal(20,6) unsigned NOT NULL default '0.000000',
  `volumeuom` varchar(20) NOT NULL default '',
  `volumeqty` decimal(20,6) unsigned NOT NULL default '0.000000',
  `volumeloosed` decimal(20,6) unsigned NOT NULL default '0.000000',
  `totalvolume` decimal(20,6) unsigned NOT NULL default '0.000000',
  `lcosttype1` enum('Value','Quantity') NOT NULL default 'Value',
  `lcosttype2` enum('Value','Quantity') NOT NULL default 'Value',
  `lcosttype3` enum('Value','Quantity') NOT NULL default 'Value',
  `supplypurchase` enum('None','Supply','Purchase') NOT NULL default 'None',
  `taxsubtract` enum('Y','N') NOT NULL default 'N',
  `taxableamount` decimal(20,2) NOT NULL default '0.00',
  `taxablelocalamount` decimal(20,2) NOT NULL default '0.00',
  `amountaftertaxsubtract` decimal(20,2) NOT NULL default '0.00',
  `localamountaftertaxsubtract` decimal(20,2) NOT NULL default '0.00',
  `purchasestaxlocalamount` decimal(20,2) NOT NULL default '0.00',
  `taxadjustment` decimal(20,2) NOT NULL default '0.00',
  `taxlocaladjustment` decimal(20,2) NOT NULL default '0.00',
  `taxtotalamount` decimal(20,2) NOT NULL default '0.00',
  `taxtotallocalamount` decimal(20,2) NOT NULL default '0.00',
  PRIMARY KEY  (`supplierconsignmentreturnkey`,`pos`),
  UNIQUE KEY `iscrikeyid` (`supplierconsignmentreturnkey`,`id`),
  KEY `iscticode` (`supplierconsignmentreturncode`),
  KEY `isctistockcode` (`stockcode`),
  KEY `isctidepartmentcode` (`departmentcode`),
  KEY `isctistocklocationcode` (`stocklocationcode`),
  KEY `isctibarcode` (`barcode`),
  KEY `isctifoc` (`foc`),
  KEY `isctibatchno` (`batchno`),
  KEY `isctijobcode` (`jobcode`),
  KEY `isctigsttypecode` (`gsttypecode`)
) ENGINE=INNODB DEFAULT CHARSET=latin1;

CREATE TABLE `sysuser` (
  `userkey` int(11) unsigned NOT NULL auto_increment,
  `usercode` varchar(20) NOT NULL default '',
  `username` varchar(250) NOT NULL default '',
  `position` varchar(200) NOT NULL default '',
  `pwd` blob NOT NULL,
  `accesstimefrom` time default NULL,
  `accesstimeto` time default NULL,
  `memo` mediumtext,
  `accept` enum('Y','N') NOT NULL default 'N',
  `validdatefrom` date default NULL,
  `validdateto` date default NULL,
  `usergroupcode` varchar(20) NOT NULL default '',
  `inactive` enum('Y','N') NOT NULL default 'N',
  `tourismpaymentaccept` enum('Y','N') NOT NULL default 'N',
  `tourismpaymentvaliddatefrom` date default NULL,
  `tourismpaymentvaliddateto` date default NULL,
  `creditorcode` varchar(20) NOT NULL default '',
  PRIMARY KEY  (`userkey`),
  UNIQUE KEY `isuusercode` (`usercode`),
  KEY `isuusergroupcode` (`usergroupcode`),
  KEY `isucreditorcode` (`creditorcode`)
) ENGINE=INNODB DEFAULT CHARSET=latin1;

CREATE TABLE `sysuserdocno` (
  `usercode` varchar(20) NOT NULL default '',
  `doctype` varchar(5) NOT NULL default '',
  `docnokey` int(11) unsigned NOT NULL default '0',
  PRIMARY KEY  (`usercode`,`doctype`)
) ENGINE=INNODB DEFAULT CHARSET=latin1;

CREATE TABLE `sysusergroup` (
  `usergroupkey` int(11) unsigned NOT NULL auto_increment,
  `usergroupcode` varchar(20) NOT NULL default '',
  `descr` varchar(200) NOT NULL default '',
  `editdepartment` enum('Y','N') NOT NULL default 'N',
  `defaultdepartmentcode` varchar(20) NOT NULL default '',
  `editjob` enum('Y','N') NOT NULL default 'Y',
  `defaultjobcode` varchar(20) NOT NULL default '',
  `editstaff` enum('Y','N') NOT NULL default 'N',
  `defaultstaffcode` varchar(20) NOT NULL default '',
  `editstocklocation` enum('Y','N') NOT NULL default 'N',
  `defaultstocklocation` varchar(20) NOT NULL default '',
  `editsalesteamcode` enum('Y','N') NOT NULL default 'N',
  `debtorcreditlimitcontrol` enum('Ask Approval','Block','Supervisor') NOT NULL default 'Supervisor',
  `creditorcreditlimitcontrol` enum('Ask Approval','Block','Supervisor') NOT NULL default 'Supervisor',
  `negativestockbalancecontrol` enum('Ask Approval','Block','Supervisor') NOT NULL default 'Supervisor',
  `stockreorderlevelcontrol` enum('Ask Approval','Block','Supervisor') NOT NULL default 'Supervisor',
  `sellingpricebelowminpricecontrol` enum('Ask Approval','Block','Supervisor') NOT NULL default 'Supervisor',
  `debtortermcontrol` enum('Ask Approval','Block','Supervisor') NOT NULL default 'Supervisor',
  `defaultsalesteamcode` varchar(20) NOT NULL default '',
  PRIMARY KEY  (`usergroupkey`),
  UNIQUE KEY `isugusergroupcode` (`usergroupcode`)
) ENGINE=INNODB DEFAULT CHARSET=latin1;

CREATE TABLE `sysuserprivilege` (
  `usercode` varchar(20) NOT NULL default '',
  `privcode` varchar(50) NOT NULL default '',
  `privvalue` blob,
  `myfavorites` enum('Y','N') NOT NULL default 'N',
  PRIMARY KEY  (`usercode`,`privcode`),
  KEY `indsupprivcode` (`privcode`)
) ENGINE=INNODB DEFAULT CHARSET=latin1;

CREATE TABLE `task` (
  `taskkey` int(11) unsigned NOT NULL auto_increment,
  `taskcode` varchar(20) NOT NULL default '',
  `stockcode` varchar(30) NOT NULL default '',
  `descr` varchar(200) NOT NULL default '',
  `inactive` enum('Y','N') NOT NULL default 'N',
  `setasdefault` enum('Y','N') NOT NULL default 'N',
  `stockmodelcode` varchar(20) NOT NULL default '',
  `lastmodified` timestamp NOT NULL default CURRENT_TIMESTAMP on update CURRENT_TIMESTAMP,
  PRIMARY KEY  (`taskkey`),
  UNIQUE KEY `itkcode` (`taskcode`),
  KEY `itkstockcode` (`stockcode`),
  KEY `itkstockmodelcode` (`stockmodelcode`)
) ENGINE=INNODB DEFAULT CHARSET=latin1;

CREATE TABLE `taskdetail` (
  `taskcode` varchar(20) NOT NULL default '',
  `taskitemcode` varchar(20) NOT NULL default '',
  `descr` varchar(200) NOT NULL default '',
  `labourcost` decimal(20,6) NOT NULL default '0.00',
  `pos` int(11) unsigned NOT NULL default '0',
  PRIMARY KEY  (`taskcode`,`taskitemcode`)
) ENGINE=INNODB DEFAULT CHARSET=latin1;

CREATE TABLE `taskitem` (
  `taskitemkey` int(11) unsigned NOT NULL auto_increment,
  `taskitemcode` varchar(20) NOT NULL default '',
  `descr` varchar(200) NOT NULL default '',
  `labourcost` decimal(20,6) NOT NULL default '0.00',
  `done` enum('Y','N') NOT NULL default 'N',
  `lastmodified` timestamp NOT NULL default CURRENT_TIMESTAMP on update CURRENT_TIMESTAMP,
  PRIMARY KEY  (`taskitemkey`),
  UNIQUE KEY `itiicode` (`taskitemcode`)
) ENGINE=INNODB DEFAULT CHARSET=latin1;

CREATE TABLE `term` (
  `termkey` int(11) unsigned NOT NULL auto_increment,
  `termcode` varchar(20) NOT NULL default '',
  `termtype` enum('Day','Month','Month End') NOT NULL default 'Day',
  `termvalue` int(11) unsigned NOT NULL default '0',
  `descr` varchar(200) NOT NULL default '',
  `inactive` enum('Y','N') NOT NULL default 'N',
  `done` enum('Y','N') NOT NULL default 'N',
  `lastmodified` timestamp NOT NULL default CURRENT_TIMESTAMP on update CURRENT_TIMESTAMP,
  PRIMARY KEY  (`termkey`),
  UNIQUE KEY `itcode` (`termcode`),
  KEY `itinactive` (`inactive`)
) ENGINE=INNODB DEFAULT CHARSET=latin1;

CREATE TABLE `todolist` (
  `userkey` int(10) unsigned NOT NULL default '0',
  `todolistdata` mediumblob,
  `viewtype` int(10) unsigned NOT NULL default '0',
  PRIMARY KEY  (`userkey`)
) ENGINE=INNODB DEFAULT CHARSET=latin1;

CREATE TABLE `touragency` (
  `touragencykey` int(11) unsigned NOT NULL auto_increment,
  `touragencycode` varchar(20) NOT NULL default '',
  `descr` varchar(200) NOT NULL default '',
  `touragencytypecode` varchar(20) NOT NULL default '',
  `address1` varchar(200) NOT NULL default '',
  `address2` varchar(200) NOT NULL default '',
  `address3` varchar(200) NOT NULL default '',
  `address4` varchar(200) NOT NULL default '',
  `phone` varchar(30) NOT NULL default '',
  `phone2` varchar(30) NOT NULL default '',
  `fax` varchar(30) NOT NULL default '',
  `contactperson` varchar(200) NOT NULL default '',
  `commission` decimal(20,2) default NULL,
  `agencycommissionbystockgroupcode` varchar(20) NOT NULL default '',
  `inactive` enum('Y','N') NOT NULL default 'N',
  `done` enum('Y','N') NOT NULL default 'N',
  `lastmodified` timestamp NOT NULL default CURRENT_TIMESTAMP on update CURRENT_TIMESTAMP,
  PRIMARY KEY  (`touragencykey`),
  UNIQUE KEY `itracode` (`touragencycode`),
  KEY `itratouragencytypecode` (`touragencytypecode`),
  KEY `itrainactive` (`inactive`),
  KEY `itaagencycommissionbystockgroupcode` (`agencycommissionbystockgroupcode`)
) ENGINE=INNODB DEFAULT CHARSET=latin1;

CREATE TABLE `touragencytype` (
  `touragencytypekey` int(11) unsigned NOT NULL auto_increment,
  `touragencytypecode` varchar(20) NOT NULL default '',
  `descr` varchar(200) NOT NULL default '',
  `inactive` enum('Y','N') NOT NULL default 'N',
  `done` enum('Y','N') NOT NULL default 'N',
  `lastmodified` timestamp NOT NULL default CURRENT_TIMESTAMP on update CURRENT_TIMESTAMP,
  PRIMARY KEY  (`touragencytypekey`),
  UNIQUE KEY `itatcode` (`touragencytypecode`),
  KEY `itatinactive` (`inactive`)
) ENGINE=INNODB DEFAULT CHARSET=latin1;

CREATE TABLE `tourgroup` (
  `tourgroupkey` int(11) unsigned NOT NULL auto_increment,
  `tourgroupcode` varchar(20) NOT NULL default '',
  `tourdate` date default NULL,
  `descr` varchar(200) NOT NULL default '',
  `touragencycode` varchar(20) NOT NULL default '',
  `tourguidecode` varchar(30) NOT NULL default '',
  `touristcode` varchar(20) NOT NULL default '',
  `tourleader` varchar(200) NOT NULL default '',
  `drivername` varchar(200) NOT NULL default '',
  `vehicleno` varchar(200) NOT NULL default '',
  `touragencycommission` decimal(20,2) default NULL,
  `tourguidecommission` decimal(20,2) default NULL,
  `tourleadercommission` decimal(20,2) default NULL,
  `tourdrivercommission` decimal(20,2) default NULL,
  `notourist` int(11) unsigned NOT NULL default '0',
  `noleader` int(11) unsigned NOT NULL default '0',
  `expenses` decimal(20,2) default NULL,
  `parking` decimal(20,2) default NULL,
  `inactive` enum('Y','N') NOT NULL default 'N',
  `vehicletypecode` varchar(20) NOT NULL,
  `paidexpenses` enum('Y','N') NOT NULL default 'N',
  `paidagency` enum('Y','N') NOT NULL default 'N',
  `paidguide` enum('Y','N') NOT NULL default 'N',
  `paidleader` enum('Y','N') NOT NULL default 'N',
  `paiddriver` enum('Y','N') NOT NULL default 'N',
  `paidexpensessalesamount` decimal(20,2) default '0.00',
  `paidagencysalesamount` decimal(20,2) default '0.00',
  `paidguidesalesamount` decimal(20,2) default '0.00',
  `paidleadersalesamount` decimal(20,2) default '0.00',
  `paiddriversalesamount` decimal(20,2) default '0.00',
  `paidexpensesamount` decimal(20,2) default '0.00',
  `paidagencyamount` decimal(20,2) default '0.00',
  `paidguideamount` decimal(20,2) default '0.00',
  `paidleaderamount` decimal(20,2) default '0.00',
  `paiddriveramount` decimal(20,2) default '0.00',
  `paidexpensesby` varchar(20) NOT NULL,
  `paidagencyby` varchar(20) NOT NULL,
  `paidguideby` varchar(20) NOT NULL,
  `paidleaderby` varchar(20) NOT NULL,
  `paiddriverby` varchar(20) NOT NULL,
  `paidexpensesdate` datetime default NULL,
  `paidagencydate` datetime default NULL,
  `paidguidedate` datetime default NULL,
  `paidleaderdate` datetime default NULL,
  `paiddriverdate` datetime default NULL,
  `paidexpensesdocno` varchar(20) NOT NULL,
  `paidagencydocno` varchar(20) NOT NULL,
  `paidguidedocno` varchar(20) NOT NULL,
  `paidleaderdocno` varchar(20) NOT NULL,
  `paiddriverdocno` varchar(20) NOT NULL,
  `agencycommissionbystockgroupcode` varchar(20) NOT NULL default '',
  `guidecommissionbystockgroupcode` varchar(20) NOT NULL default '',
  `leadercommissionbystockgroupcode` varchar(20) NOT NULL default '',
  `drivercommissionbystockgroupcode` varchar(20) NOT NULL default '',
  `done` enum('Y','N') NOT NULL default 'N',
  PRIMARY KEY  (`tourgroupkey`),
  UNIQUE KEY `itrgtourdategroupcode` (`tourdate`,`tourgroupcode`),
  KEY `itrgtouragencycode` (`touragencycode`),
  KEY `itrgtourguidecode` (`tourguidecode`),
  KEY `itrgtouristcode` (`touristcode`),
  KEY `itrginactive` (`inactive`),
  KEY `itrgvehicletypecode` (`vehicletypecode`),
  KEY `itrgpaidexpenses` (`paidexpenses`),
  KEY `itrgpaidagency` (`paidagency`),
  KEY `itrgpaidguide` (`paidguide`),
  KEY `itrgpaidleader` (`paidleader`),
  KEY `itrgpaiddriver` (`paiddriver`),
  KEY `itrgtourleader` (`tourleader`),
  KEY `itrgdrivername` (`drivername`),
  KEY `itgagencycommissionbystockgroupcode` (`agencycommissionbystockgroupcode`),
  KEY `itgguidecommissionbystockgroupcode` (`guidecommissionbystockgroupcode`),
  KEY `itgleadercommissionbystockgroupcode` (`leadercommissionbystockgroupcode`),
  KEY `itgdrivercommissionbystockgroupcode` (`drivercommissionbystockgroupcode`)
) ENGINE=INNODB DEFAULT CHARSET=latin1;

CREATE TABLE `tourguide` (
  `tourguidekey` int(11) unsigned NOT NULL auto_increment,
  `tourguidecode` varchar(20) NOT NULL default '',
  `name` varchar(200) NOT NULL default '',
  `icno` varchar(30) NOT NULL default '',
  `address1` varchar(200) NOT NULL default '',
  `address2` varchar(200) NOT NULL default '',
  `address3` varchar(200) NOT NULL default '',
  `address4` varchar(200) NOT NULL default '',
  `phone` varchar(30) NOT NULL default '',
  `phone2` varchar(30) NOT NULL default '',
  `commission` decimal(20,2) default NULL,
  `guidecommissionbystockgroupcode` varchar(20) NOT NULL default '',
  `inactive` enum('Y','N') NOT NULL default 'N',
  `done` enum('Y','N') NOT NULL default 'N',
  `lastmodified` timestamp NOT NULL default CURRENT_TIMESTAMP on update CURRENT_TIMESTAMP,
  PRIMARY KEY  (`tourguidekey`),
  UNIQUE KEY `itrgucode` (`tourguidecode`),
  KEY `itrguinactive` (`inactive`),
  KEY `itgguidecommissionbystockgroupcode` (`guidecommissionbystockgroupcode`)
) ENGINE=INNODB DEFAULT CHARSET=latin1;

CREATE TABLE `tourismcommissionbystockgroup` (
  `tourismcommissionbystockgroupkey` int(11) unsigned NOT NULL auto_increment,
  `tourismcommissionbystockgroupcode` varchar(20) NOT NULL default '',
  `descr` varchar(200) NOT NULL default '',
  PRIMARY KEY  (`tourismcommissionbystockgroupkey`),
  UNIQUE KEY `icmbaode` (`tourismcommissionbystockgroupcode`)
) ENGINE=INNODB DEFAULT CHARSET=latin1;

CREATE TABLE `tourismcommissionbystockgroupitem` (
  `tourismcommissionbystockgroupcode` varchar(20) NOT NULL default '',
  `stockgroupcode` varchar(20) NOT NULL default '',
  `commissionpercent` decimal(20,2) NOT NULL default '0.00',
  PRIMARY KEY  (`tourismcommissionbystockgroupcode`,`stockgroupcode`)
) ENGINE=INNODB DEFAULT CHARSET=latin1;

CREATE TABLE `tourist` (
  `touristkey` int(11) unsigned NOT NULL auto_increment,
  `touristcode` varchar(20) NOT NULL default '',
  `descr` varchar(200) NOT NULL default '',
  `inactive` enum('Y','N') NOT NULL default 'N',
  `done` enum('Y','N') NOT NULL default 'N',
  `lastmodified` timestamp NOT NULL default CURRENT_TIMESTAMP on update CURRENT_TIMESTAMP,
  PRIMARY KEY  (`touristkey`),
  UNIQUE KEY `itrcode` (`touristcode`),
  KEY `itrinactive` (`inactive`)
) ENGINE=INNODB DEFAULT CHARSET=latin1;

CREATE TABLE `varblob` (
  `vblcategory` varchar(30) NOT NULL default '',
  `vblcode` varchar(50) NOT NULL default '',
  `vblvalue` mediumblob,
  PRIMARY KEY  (`vblcategory`,`vblcode`)
) ENGINE=INNODB DEFAULT CHARSET=latin1;

CREATE TABLE `varbool` (
  `vbcategory` varchar(30) NOT NULL default '',
  `vbcode` varchar(50) NOT NULL default '',
  `vbvalue` enum('Y','N') NOT NULL default 'Y',
  PRIMARY KEY  (`vbcategory`,`vbcode`)
) ENGINE=INNODB DEFAULT CHARSET=latin1;

CREATE TABLE `varchr` (
  `vccategory` varchar(30) NOT NULL default '',
  `vccode` varchar(50) NOT NULL default '',
  `vcvalue` varchar(250) NOT NULL default '',
  PRIMARY KEY  (`vccategory`,`vccode`)
) ENGINE=INNODB DEFAULT CHARSET=latin1;

CREATE TABLE `vardbl` (
  `vdcategory` varchar(30) NOT NULL default '',
  `vdcode` varchar(50) NOT NULL default '',
  `vdvalue` double NOT NULL default '0',
  PRIMARY KEY  (`vdcategory`,`vdcode`)
) ENGINE=INNODB DEFAULT CHARSET=latin1;

CREATE TABLE `vardt` (
  `vdtcategory` varchar(30) NOT NULL default '',
  `vdtcode` varchar(50) NOT NULL default '',
  `vdtvalue` datetime default NULL,
  PRIMARY KEY  (`vdtcategory`,`vdtcode`)
) ENGINE=INNODB DEFAULT CHARSET=latin1;

CREATE TABLE `varint` (
  `vicategory` varchar(30) NOT NULL default '',
  `vicode` varchar(50) NOT NULL default '',
  `vivalue` bigint(20) NOT NULL default '0',
  PRIMARY KEY  (`vicategory`,`vicode`)
) ENGINE=INNODB DEFAULT CHARSET=latin1;

CREATE TABLE `vartext` (
  `vtcategory` varchar(30) NOT NULL default '',
  `vtcode` varchar(50) NOT NULL default '',
  `vtvalue` mediumtext,
  PRIMARY KEY  (`vtcategory`,`vtcode`)
) ENGINE=INNODB DEFAULT CHARSET=latin1;

CREATE TABLE `vehicletype` (
  `vehicletypekey` int(11) unsigned NOT NULL auto_increment,
  `vehicletypecode` varchar(20) NOT NULL default '',
  `descr` varchar(200) NOT NULL default '',
  `parking` decimal(20,2) default 0,
  `expenses` decimal(20,2) default 0,
  `inactive` enum('Y','N') NOT NULL default 'N',
  `done` enum('Y','N') NOT NULL default 'N',
  `lastmodified` timestamp NOT NULL default CURRENT_TIMESTAMP on update CURRENT_TIMESTAMP,
  PRIMARY KEY  (`vehicletypekey`),
  UNIQUE KEY `ivtvehicletypecode` (`vehicletypecode`),
  KEY `ivtinactive` (`inactive`)
) ENGINE=INNODB DEFAULT CHARSET=latin1;

CREATE TABLE `voucher` (
  `voucherkey` int(11) unsigned NOT NULL auto_increment,
  `vouchercode` varchar(20) NOT NULL default '',
  `descr` varchar(200) NOT NULL default '',
  `expiredate` date default NULL,
  `amount` decimal(20,2) default NULL,
  `note` mediumtext,
  `voucherissuecode` varchar(20) NOT NULL default '',
  `salesinvoicecode` varchar(20) NOT NULL default '',
  `inactive` enum('Y','N') NOT NULL default 'N',
  `done` enum('Y','N') NOT NULL default 'N',
  PRIMARY KEY  (`voucherkey`),
  UNIQUE KEY `ivcode` (`vouchercode`),
  KEY `ivexpiredate` (`expiredate`),
  KEY `ivinactive` (`inactive`),
  KEY `ivvoucherissuecode` (`voucherissuecode`),
  KEY `ivsalesinvoicecode` (`salesinvoicecode`)
) ENGINE=INNODB DEFAULT CHARSET=latin1;

CREATE TABLE `voucherissue` (
  `voucherissuekey` int(11) unsigned NOT NULL auto_increment,
  `voucherissuecode` varchar(20) NOT NULL default '',
  `voucherissuedate` date default NULL,
  `membercode` varchar(20) NOT NULL default '',
  `descr` varchar(200) NOT NULL default '',
  `refno` varchar(20) NOT NULL default '',
  `note` mediumtext,
  `remark1` varchar(100) NOT NULL,
  `remark2` varchar(100) NOT NULL,
  `remark3` varchar(100) NOT NULL,
  `remark4` varchar(100) NOT NULL,
  `remark5` varchar(100) NOT NULL,
  `remark6` varchar(100) NOT NULL,
  `remark7` varchar(100) NOT NULL,
  `remark8` varchar(100) NOT NULL,
  `cancelled` enum('Y','N') NOT NULL default 'N',
  `cancelledremark` varchar(200) NOT NULL,
  `created` datetime default NULL,
  `modified` datetime default NULL,
  `done` enum('Y','N') NOT NULL default 'N',
  `allowpointpayment` enum('Y','N') NOT NULL default 'N',
  `pointpayment` decimal(20,2) default NULL,
  `pointpaymentvalue` decimal(20,2) default NULL,
  PRIMARY KEY  (`voucherissuekey`),
  UNIQUE KEY `ivicode` (`voucherissuecode`),
  KEY `ividate` (`voucherissuedate`),
  KEY `ivirefno` (`refno`),
  KEY `ivicancelled` (`cancelled`)
) ENGINE=INNODB DEFAULT CHARSET=latin1;

CREATE TABLE `voucherissueid` (
  `voucherissuekey` int(11) unsigned NOT NULL default '0',
  `id` int(11) unsigned NOT NULL default '0',
  PRIMARY KEY  (`voucherissuekey`,`id`)
) ENGINE=INNODB DEFAULT CHARSET=latin1;

CREATE TABLE `voucherissueitem` (
  `voucherissuekey` int(11) unsigned NOT NULL default '0',
  `voucherissuecode` varchar(20) NOT NULL default '',
  `id` int(11) unsigned NOT NULL default '0',
  `pos` int(11) unsigned NOT NULL default '0',
  `vouchercode` varchar(20) NOT NULL default '',
  `descr` varchar(200) NOT NULL default '',
  `vouchertype` enum('Member Only','All Member', 'All') NOT NULL default 'All',
  PRIMARY KEY  (`voucherissuekey`,`pos`),
  UNIQUE KEY `istiikeyid` (`voucherissuekey`,`id`),
  KEY `iviicode` (`voucherissuecode`),
  KEY `iciivouchercode` (`vouchercode`),
  KEY `iciivouchertype` (`vouchertype`)
) ENGINE=INNODB DEFAULT CHARSET=latin1;

CREATE TABLE `warrantytransferred` (
  `doctype` varchar(5) NOT NULL default '',
  `dockey` int(11) unsigned NOT NULL default '0',
  `docid` int(11) unsigned NOT NULL default '0',
  `totype` varchar(5) NOT NULL default '',
  `tokey` int(11) unsigned NOT NULL default '0',
  `toid` int(11) unsigned NOT NULL default '0',
  `defaultqty` decimal(20,6) NOT NULL default '1.000000',
  PRIMARY KEY  (`doctype`,`dockey`,`docid`,`totype`,`tokey`,`toid`),
  KEY `irmatftotypekeyid` (`totype`,`tokey`,`toid`)
) ENGINE=INNODB DEFAULT CHARSET=latin1;

Select Now() as EndProcess;

Select TimeDiff(Now(), @mytime) as ProcessTotalTime;
