/**Begin E:\NextERP_PDM\PDM_UPGRADE\PDMS\branch_lastest\pdm\TCTB_table.sql **/
IF NOT EXISTS (SELECT 1 FROM KSQL_USERTABLES WHERE KSQL_TABNAME = 'T_TCTB_XORGMAPBUSOBJECT') 
 CREATE TABLE T_TCTB_XORGMAPBUSOBJECT (
FENTRYID BIGINT DEFAULT 0 NOT NULL,
FDETAILID BIGINT DEFAULT 0 NOT NULL,
FSEQ INT DEFAULT 0 NOT NULL,
FBUSINESSNUMBER VARCHAR(80) DEFAULT ' ' NOT NULL,
FBUSINESSNAME NVARCHAR(150) DEFAULT ' ' NOT NULL,
FBUSINESSID VARCHAR(80) DEFAULT ' ' NOT NULL,
FSTARTDATE DATETIME,
FENDDATE DATETIME,
FTAXCATEGORY NVARCHAR(400) DEFAULT ' ' NOT NULL,
FISDEFAULT CHAR(1) DEFAULT '0' NOT NULL,
FENTRYCHANGETYPE VARCHAR(50) DEFAULT ' ' NOT NULL,
FENTRYSRCID BIGINT DEFAULT 0 NOT NULL
);


IF NOT EXISTS (SELECT 1 FROM KSQL_USERTABLES WHERE KSQL_TABNAME = 'T_TCTB_XORGMAPRELATION') 
 CREATE TABLE T_TCTB_XORGMAPRELATION (
FENTRYID BIGINT DEFAULT 0 NOT NULL,
FNUMBER VARCHAR(100) DEFAULT ' ' NOT NULL,
FNAME NVARCHAR(50) DEFAULT ' ' NOT NULL,
FSTATUS VARCHAR(50) DEFAULT ' ' NOT NULL,
FCREATORID BIGINT DEFAULT 0 NOT NULL,
FMODIFIERID BIGINT DEFAULT 0 NOT NULL,
FENABLE VARCHAR(50) DEFAULT ' ' NOT NULL,
FCREATETIME DATETIME,
FMODIFYTIME DATETIME,
FMASTERID BIGINT DEFAULT 0 NOT NULL,
FID BIGINT DEFAULT 0 NOT NULL,
FTAXORG BIGINT DEFAULT 0 NOT NULL,
FCHANGEBIZDATE DATETIME,
FREASON NVARCHAR(512) DEFAULT ' ' NOT NULL,
FSOURCEBILLID BIGINT DEFAULT 0 NOT NULL,
FVALIDDATE DATETIME,
FCHANGESTATUS VARCHAR(50) DEFAULT ' ' NOT NULL,
FCHANGERID BIGINT DEFAULT 0 NOT NULL,
FCHANGEDATE DATETIME,
FVERSION VARCHAR(30) DEFAULT ' ' NOT NULL,
FVALIDERID BIGINT DEFAULT 0 NOT NULL,
FVALIDSTATUS VARCHAR(50) DEFAULT ' ' NOT NULL,
FSOURCEBILLENTITY VARCHAR(50) DEFAULT ' ' NOT NULL,
FSOURCEBILLSTATUS VARCHAR(50) DEFAULT ' ' NOT NULL,
FSOURCEBILLNO VARCHAR(120) DEFAULT ' ' NOT NULL
);


IF NOT EXISTS (SELECT 1 FROM KSQL_USERTABLES WHERE KSQL_TABNAME = 'T_TCTB_XORGMAPRELATION_L') 
 CREATE TABLE T_TCTB_XORGMAPRELATION_L (
FPKID VARCHAR(36) DEFAULT ' ' NOT NULL,
FENTRYID BIGINT DEFAULT 0 NOT NULL,
FLOCALEID VARCHAR(10) DEFAULT ' ' NOT NULL,
FNAME NVARCHAR(50) DEFAULT ' ' NOT NULL
);


IF NOT EXISTS (SELECT 1 FROM KSQL_USERCOLUMNS WHERE KSQL_COL_TABNAME = 'T_TCTB_ORGMAP_TAXORG' AND KSQL_COL_NAME ='FCHANGESTATUS') 
 ALTER TABLE T_TCTB_ORGMAP_TAXORG ADD (FCHANGESTATUS VARCHAR(50) DEFAULT ' ' NOT NULL );
IF NOT EXISTS (SELECT 1 FROM KSQL_USERCOLUMNS WHERE KSQL_COL_TABNAME = 'T_TCTB_ORGMAP_TAXORG' AND KSQL_COL_NAME ='FCHANGERID') 
 ALTER TABLE T_TCTB_ORGMAP_TAXORG ADD (FCHANGERID BIGINT DEFAULT 0 NOT NULL );
IF NOT EXISTS (SELECT 1 FROM KSQL_USERCOLUMNS WHERE KSQL_COL_TABNAME = 'T_TCTB_ORGMAP_TAXORG' AND KSQL_COL_NAME ='FCHANGEDATE') 
 ALTER TABLE T_TCTB_ORGMAP_TAXORG ADD (FCHANGEDATE DATETIME );
IF NOT EXISTS (SELECT 1 FROM KSQL_USERCOLUMNS WHERE KSQL_COL_TABNAME = 'T_TCTB_ORGMAP_TAXORG' AND KSQL_COL_NAME ='FVERSION') 
 ALTER TABLE T_TCTB_ORGMAP_TAXORG ADD (FVERSION VARCHAR(30) DEFAULT ' ' NOT NULL );
IF NOT EXISTS (SELECT 1 FROM KSQL_USERCOLUMNS WHERE KSQL_COL_TABNAME = 'T_TCTB_ORGMAP_BUSOBJECT' AND KSQL_COL_NAME ='FENTRYCHANGETYPE') 
 ALTER TABLE T_TCTB_ORGMAP_BUSOBJECT ADD (FENTRYCHANGETYPE VARCHAR(50) DEFAULT ' ' NOT NULL );
IF NOT EXISTS (SELECT 1 FROM KSQL_USERTABLES WHERE KSQL_TABNAME = 'T_TCTB_XORG_GROUP') 
 CREATE TABLE T_TCTB_XORG_GROUP (
FID BIGINT DEFAULT 0 NOT NULL,
FMODIFIERID BIGINT DEFAULT 0 NOT NULL,
FCREATETIME DATETIME,
FMODIFYTIME DATETIME,
FNUMBER VARCHAR(30) DEFAULT ' ' NOT NULL,
FSTATUS VARCHAR(50) DEFAULT ' ' NOT NULL,
FENABLE VARCHAR(50) DEFAULT ' ' NOT NULL,
FMASTERID BIGINT DEFAULT 0 NOT NULL,
FEFFECTDATE DATETIME,
FINVALIDDATE DATETIME,
FCREATORID BIGINT DEFAULT 0 NOT NULL,
FTAXTYPE VARCHAR(50) DEFAULT ' ' NOT NULL,
FSUMMARYORGTYPE VARCHAR(50) DEFAULT ' ' NOT NULL,
FSUMMARYWAY VARCHAR(50) DEFAULT ' ' NOT NULL,
FFPXSSRFW VARCHAR(50) DEFAULT ' ' NOT NULL,
FYBTSEHFFS VARCHAR(50) DEFAULT ' ' NOT NULL,
FZFJGSEFPFS VARCHAR(50) DEFAULT ' ' NOT NULL,
FPARTICIPATION CHAR(1) DEFAULT '0' NOT NULL,
FPRELEVYRATE VARCHAR(50) DEFAULT ' ' NOT NULL,
FFIXEDRATIO DECIMAL(23,10) DEFAULT 0 NOT NULL,
FZJGGDBL DECIMAL(23,10) DEFAULT 0 NOT NULL,
FBILLSTATUS VARCHAR(50) DEFAULT ' ' NOT NULL,
FCHANGESTATUS VARCHAR(50) DEFAULT ' ' NOT NULL,
FCHANGERID BIGINT DEFAULT 0 NOT NULL,
FCHANGEDATE DATETIME,
FVERSION VARCHAR(30) DEFAULT ' ' NOT NULL,
FSOURCEBILLNO VARCHAR(100) DEFAULT ' ' NOT NULL,
FCHANGEBIZDATE DATETIME,
FREASON NVARCHAR(512) DEFAULT ' ' NOT NULL,
FVALIDDATE DATETIME,
FSOURCEBILLID BIGINT DEFAULT 0 NOT NULL,
FVALIDERID BIGINT DEFAULT 0 NOT NULL,
FVALIDSTATUS VARCHAR(50) DEFAULT ' ' NOT NULL,
FSOURCEBILLENTITY VARCHAR(50) DEFAULT ' ' NOT NULL,
FBLWCCL VARCHAR(50) DEFAULT ' ' NOT NULL,
FSOURCEBILLSTATUS VARCHAR(50) DEFAULT ' ' NOT NULL
);


IF NOT EXISTS (SELECT 1 FROM KSQL_USERTABLES WHERE KSQL_TABNAME = 'T_TCTB_XORG_GROUP_L') 
 CREATE TABLE T_TCTB_XORG_GROUP_L (
FPKID VARCHAR(36) DEFAULT ' ' NOT NULL,
FID BIGINT DEFAULT 0 NOT NULL,
FLOCALEID VARCHAR(10) DEFAULT ' ' NOT NULL,
FNAME NVARCHAR(50) DEFAULT ' ' NOT NULL
);


IF NOT EXISTS (SELECT 1 FROM KSQL_USERTABLES WHERE KSQL_TABNAME = 'T_TCTB_XORGGROUP_DETAIL') 
 CREATE TABLE T_TCTB_XORGGROUP_DETAIL (
FID BIGINT DEFAULT 0 NOT NULL,
FENTRYID BIGINT DEFAULT 0 NOT NULL,
FSEQ INT DEFAULT 0 NOT NULL,
PARENTENTRYID BIGINT DEFAULT 0 NOT NULL,
FORGCODE VARCHAR(50) DEFAULT ' ' NOT NULL,
FORGNAME NVARCHAR(50) DEFAULT ' ' NOT NULL,
FDECLARATION VARCHAR(50) DEFAULT ' ' NOT NULL,
FSHAREID CHAR(1) DEFAULT '0' NOT NULL,
FREMARK VARCHAR(50) DEFAULT ' ' NOT NULL,
FLEVEL BIGINT DEFAULT 0 NOT NULL,
FCOLLECTORG NVARCHAR(50) DEFAULT ' ' NOT NULL,
FORGID BIGINT DEFAULT 0 NOT NULL,
FPARENTID BIGINT DEFAULT 0 NOT NULL,
FKDQJYQYLX VARCHAR(50) DEFAULT ' ' NOT NULL,
FLEVELNAME NVARCHAR(50) DEFAULT ' ' NOT NULL,
FISSUESBB CHAR(1) DEFAULT '0' NOT NULL,
FENTRYCHANGETYPE VARCHAR(50) DEFAULT ' ' NOT NULL,
FENTRYSRCID BIGINT DEFAULT 0 NOT NULL
);


IF NOT EXISTS (SELECT 1 FROM KSQL_USERTABLES WHERE KSQL_TABNAME = 'T_TCTB_XORGGROUP_PARAM') 
 CREATE TABLE T_TCTB_XORGGROUP_PARAM (
FID BIGINT DEFAULT 0 NOT NULL,
FENTRYID BIGINT DEFAULT 0 NOT NULL,
FSEQ INT DEFAULT 0 NOT NULL,
FORG BIGINT DEFAULT 0 NOT NULL,
FDECLARE VARCHAR(50) DEFAULT ' ' NOT NULL,
FYBXMHWBL DECIMAL(23,10) DEFAULT 0 NOT NULL,
FJZJTHWBL DECIMAL(23,10) DEFAULT 0 NOT NULL,
FYBXMYSBL DECIMAL(23,10) DEFAULT 0 NOT NULL,
FJZJTYSBL DECIMAL(23,10) DEFAULT 0 NOT NULL,
FENTRYCHANGETYPE VARCHAR(50) DEFAULT ' ' NOT NULL,
FENTRYSRCID BIGINT DEFAULT 0 NOT NULL
);


IF NOT EXISTS (SELECT 1 FROM KSQL_USERCOLUMNS WHERE KSQL_COL_TABNAME = 'T_TCTB_ORG_GROUP_PARAM' AND KSQL_COL_NAME ='FENTRYCHANGETYPE') 
 ALTER TABLE T_TCTB_ORG_GROUP_PARAM ADD (FENTRYCHANGETYPE VARCHAR(50) DEFAULT ' ' NOT NULL );
IF NOT EXISTS (SELECT 1 FROM KSQL_USERCOLUMNS WHERE KSQL_COL_TABNAME = 'T_TCTB_ORG_GROUP_DETAIL' AND KSQL_COL_NAME ='FENTRYCHANGETYPE') 
 ALTER TABLE T_TCTB_ORG_GROUP_DETAIL ADD (FENTRYCHANGETYPE VARCHAR(50) DEFAULT ' ' NOT NULL );
IF NOT EXISTS (SELECT 1 FROM KSQL_USERCOLUMNS WHERE KSQL_COL_TABNAME = 'T_TCTB_ORG_GROUP' AND KSQL_COL_NAME ='FCHANGESTATUS') 
 ALTER TABLE T_TCTB_ORG_GROUP ADD (FCHANGESTATUS VARCHAR(50) DEFAULT ' ' NOT NULL );
IF NOT EXISTS (SELECT 1 FROM KSQL_USERCOLUMNS WHERE KSQL_COL_TABNAME = 'T_TCTB_ORG_GROUP' AND KSQL_COL_NAME ='FCHANGERID') 
 ALTER TABLE T_TCTB_ORG_GROUP ADD (FCHANGERID BIGINT DEFAULT 0 NOT NULL );
IF NOT EXISTS (SELECT 1 FROM KSQL_USERCOLUMNS WHERE KSQL_COL_TABNAME = 'T_TCTB_ORG_GROUP' AND KSQL_COL_NAME ='FCHANGEDATE') 
 ALTER TABLE T_TCTB_ORG_GROUP ADD (FCHANGEDATE DATETIME );
IF NOT EXISTS (SELECT 1 FROM KSQL_USERCOLUMNS WHERE KSQL_COL_TABNAME = 'T_TCTB_ORG_GROUP' AND KSQL_COL_NAME ='FVERSION') 
 ALTER TABLE T_TCTB_ORG_GROUP ADD (FVERSION VARCHAR(30) DEFAULT ' ' NOT NULL );
IF NOT EXISTS (SELECT 1 FROM KSQL_USERCOLUMNS WHERE KSQL_COL_TABNAME = 'T_TCTB_ORG_GROUP' AND KSQL_COL_NAME ='FBLWCCL') 
 ALTER TABLE T_TCTB_ORG_GROUP ADD (FBLWCCL VARCHAR(50) DEFAULT ' ' NOT NULL );

/**End E:\NextERP_PDM\PDM_UPGRADE\PDMS\branch_lastest\pdm\TCTB_table.sql **/
