/**Begin C:\PDM_UPGRADE\PDM1\SRM_table.sql **/
IF NOT EXISTS (SELECT 1 FROM KSQL_USERCOLUMNS WHERE KSQL_COL_TABNAME = 'T_PUR_SCHEME' AND KSQL_COL_NAME IN ('FGROUPSCHEME')) 
 ALTER TABLE T_PUR_SCHEME ADD (FGROUPSCHEME CHAR(1) DEFAULT ' ' NOT NULL );
IF NOT EXISTS (SELECT 1 FROM KSQL_USERCOLUMNS WHERE KSQL_COL_TABNAME = 'T_PUR_EVAPLAN' AND KSQL_COL_NAME IN ('FGROUPEVAPLANNOID')) 
 ALTER TABLE T_PUR_EVAPLAN ADD (FGROUPEVAPLANNOID BIGINT DEFAULT 0 NOT NULL );
IF NOT EXISTS (SELECT 1 FROM KSQL_USERCOLUMNS WHERE KSQL_COL_TABNAME = 'T_PUR_EVAPLANENTRY' AND KSQL_COL_NAME IN ('FBIZBILLTYPEID')) 
 ALTER TABLE T_PUR_EVAPLANENTRY ADD (FBIZBILLTYPEID BIGINT DEFAULT 0 NOT NULL );
IF NOT EXISTS (SELECT 1 FROM KSQL_USERCOLUMNS WHERE KSQL_COL_TABNAME = 'T_PUR_EVAPLANENTRY' AND KSQL_COL_NAME IN ('FBIZBILLNO')) 
 ALTER TABLE T_PUR_EVAPLANENTRY ADD (FBIZBILLNO VARCHAR(80) DEFAULT ' ' NOT NULL );
IF NOT EXISTS (SELECT 1 FROM KSQL_USERCOLUMNS WHERE KSQL_COL_TABNAME = 'T_PUR_INDEXENTRY' AND KSQL_COL_NAME IN ('FACCORDANCE')) 
 ALTER TABLE T_PUR_INDEXENTRY ADD (FACCORDANCE VARCHAR(50) DEFAULT ' ' NOT NULL );
IF NOT EXISTS (SELECT 1 FROM KSQL_USERTABLES WHERE KSQL_TABNAME = 'T_SRM_GROUPEVAPLAN') 
 CREATE TABLE T_SRM_GROUPEVAPLAN (
FID BIGINT DEFAULT 0 NOT NULL,
FBILLNO NVARCHAR(80) DEFAULT ' ' NOT NULL,
FBILLTYPEID BIGINT DEFAULT 0 NOT NULL,
FBILLDATE DATETIME,
FFINISHDATE DATETIME,
FEVATYPEID BIGINT DEFAULT 0 NOT NULL,
FORGID BIGINT DEFAULT 0 NOT NULL,
FCATEGORYID BIGINT DEFAULT 0 NOT NULL,
FSCHEMEID BIGINT DEFAULT 0 NOT NULL,
FGRADEID BIGINT DEFAULT 0 NOT NULL,
FPERIOD CHAR(1) DEFAULT ' ' NOT NULL,
FDATEFROM DATETIME,
FDATETO DATETIME,
FBILLSTATUS CHAR(1) DEFAULT ' ' NOT NULL,
FBIZSTATUS CHAR(1) DEFAULT ' ' NOT NULL,
FCFMSTATUS CHAR(1) DEFAULT ' ' NOT NULL,
FBIZPARTNERID BIGINT DEFAULT 0 NOT NULL,
FBIZTYPE CHAR(1) DEFAULT ' ' NOT NULL,
FISTYPESCORER CHAR(1) DEFAULT ' ' NOT NULL,
FNAME NVARCHAR(100) DEFAULT ' ' NOT NULL,
FREMARK NVARCHAR(2000) DEFAULT ' ' NOT NULL,
FLASTUPDATEUSERID BIGINT DEFAULT 0 NOT NULL,
FLASTUPDATETIME DATETIME,
FDATETIMEFROM DATETIME,
FDATETIMETO DATETIME,
FEVAMETHOD CHAR(1) DEFAULT 'A' NOT NULL,
FTYPE CHAR(1) DEFAULT ' ' NOT NULL,
FCANSUMCALCULATE CHAR(1) DEFAULT ' ' NOT NULL,
FCOMPSUMCALCULATE CHAR(1) DEFAULT ' ' NOT NULL
);

IF NOT EXISTS (SELECT 1 FROM KSQL_USERTABLES WHERE KSQL_TABNAME = 'T_SRM_EVAORGENTRY') 
 CREATE TABLE T_SRM_EVAORGENTRY (
FID BIGINT DEFAULT 0 NOT NULL,
FENTRYID BIGINT DEFAULT 0 NOT NULL,
FSEQ BIGINT DEFAULT 0 NOT NULL,
FEVAORGID BIGINT DEFAULT 0 NOT NULL,
FEVAPERSONID BIGINT DEFAULT 0 NOT NULL,
FORGWEIGHT DECIMAL(23,10) DEFAULT 0 NOT NULL,
FORGNOTE NVARCHAR(255) DEFAULT ' ' NOT NULL
);

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


IF NOT EXISTS (SELECT 1 FROM KSQL_USERTABLES WHERE KSQL_TABNAME = 'T_SRM_GROUPEVAPLANENTRY') 
 CREATE TABLE T_SRM_GROUPEVAPLANENTRY (
FID BIGINT DEFAULT 0 NOT NULL,
FENTRYID BIGINT DEFAULT 0 NOT NULL,
FSEQ BIGINT DEFAULT 0 NOT NULL,
FSUPPLIERID BIGINT DEFAULT 0 NOT NULL,
FNOTE NVARCHAR(255) DEFAULT ' ' NOT NULL
);


IF NOT EXISTS (SELECT 1 FROM KSQL_USERTABLES WHERE KSQL_TABNAME = 'T_SRM_GROUPEVAPLANSCORER') 
 CREATE TABLE T_SRM_GROUPEVAPLANSCORER (
FENTRYID BIGINT DEFAULT 0 NOT NULL,
FID BIGINT DEFAULT 0 NOT NULL,
FSEQ BIGINT DEFAULT 0 NOT NULL,
FINDEXCLASSID BIGINT DEFAULT 0 NOT NULL,
FSCORERID BIGINT DEFAULT 0 NOT NULL,
FWEIGHT DECIMAL(19,6) DEFAULT 0 NOT NULL,
FNOTE NVARCHAR(255) DEFAULT ' ' NOT NULL
);


IF NOT EXISTS (SELECT 1 FROM KSQL_USERTABLES WHERE KSQL_TABNAME = 'T_SRM_GROUPEVAPLANINDEX') 
 CREATE TABLE T_SRM_GROUPEVAPLANINDEX (
FID BIGINT DEFAULT 0 NOT NULL,
FENTRYID BIGINT DEFAULT 0 NOT NULL,
FSEQ BIGINT DEFAULT 0 NOT NULL,
FINDEXID BIGINT DEFAULT 0 NOT NULL,
FWEIGHT DECIMAL(19,6) DEFAULT 0 NOT NULL
);


IF NOT EXISTS (SELECT 1 FROM KSQL_USERTABLES WHERE KSQL_TABNAME = 'T_SRM_GROUPEVAPLANDETAIL') 
 CREATE TABLE T_SRM_GROUPEVAPLANDETAIL (
FDETAILID BIGINT DEFAULT 0 NOT NULL,
FID BIGINT DEFAULT 0 NOT NULL,
FENTRYID BIGINT DEFAULT 0 NOT NULL,
FSEQ BIGINT DEFAULT 0 NOT NULL,
FSCORERID BIGINT DEFAULT 0 NOT NULL,
FWEIGHT DECIMAL(19,6) DEFAULT 0 NOT NULL
);


IF NOT EXISTS (SELECT 1 FROM KSQL_USERTABLES WHERE KSQL_TABNAME = 'T_SRM_GROUPEVAPLAN_A') 
 CREATE TABLE T_SRM_GROUPEVAPLAN_A (
FID BIGINT DEFAULT 0 NOT NULL,
FCREATORID BIGINT DEFAULT 0 NOT NULL,
FCREATETIME DATETIME,
FMODIFIERID BIGINT DEFAULT 0 NOT NULL,
FMODIFYTIME DATETIME,
FAUDITORID BIGINT DEFAULT 0 NOT NULL,
FAUDITDATE DATETIME,
FCFMID BIGINT DEFAULT 0 NOT NULL,
FCFMDATE DATETIME,
FTERMINATERID BIGINT DEFAULT 0 NOT NULL,
FTERMINATEDATE DATETIME,
FTERMINATION NVARCHAR(255) DEFAULT ' ' NOT NULL,
FREMARK NVARCHAR(2000) DEFAULT ' ' NOT NULL,
FCFMOPINION NVARCHAR(255) DEFAULT ' ' NOT NULL
);


IF NOT EXISTS (SELECT 1 FROM KSQL_USERTABLES WHERE KSQL_TABNAME = 'T_SRM_GROUPEVASUBENTRY') 
 CREATE TABLE T_SRM_GROUPEVASUBENTRY (
FDETAILID BIGINT DEFAULT 0 NOT NULL,
FENTRYID BIGINT DEFAULT 0 NOT NULL,
FSEQ BIGINT DEFAULT 0 NOT NULL,
FMATERIALID BIGINT DEFAULT 0 NOT NULL
);


IF NOT EXISTS (SELECT 1 FROM KSQL_USERTABLES WHERE KSQL_TABNAME = 'T_SRM_GROUPSCORERPT') 
 CREATE TABLE T_SRM_GROUPSCORERPT (
FID BIGINT DEFAULT 0 NOT NULL,
FBILLNO NVARCHAR(80) DEFAULT ' ' NOT NULL,
FGROUPEVAPLANNO VARCHAR(80) DEFAULT ' ' NOT NULL,
FBILLDATE DATETIME,
FPLANDATE DATETIME,
FORGID BIGINT DEFAULT 0 NOT NULL,
FSUPPLIERID BIGINT DEFAULT 0 NOT NULL,
FCATEGORYID BIGINT DEFAULT 0 NOT NULL,
FGROUPSUMSCORE DECIMAL(23,10) DEFAULT 0 NOT NULL,
FGROUPEVAGRADEID BIGINT DEFAULT 0 NOT NULL,
FBILLSTATUS CHAR(1) DEFAULT ' ' NOT NULL,
FBIZPARTNERID BIGINT DEFAULT 0 NOT NULL,
FNAME NVARCHAR(100) DEFAULT ' ' NOT NULL,
FLASTUPDATEUSERID BIGINT DEFAULT 0 NOT NULL,
FLASTUPDATETIME DATETIME,
FMATERIALID BIGINT DEFAULT 0 NOT NULL
);


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


IF NOT EXISTS (SELECT 1 FROM KSQL_USERTABLES WHERE KSQL_TABNAME = 'T_SRM_GROUPSCORERPT_A') 
 CREATE TABLE T_SRM_GROUPSCORERPT_A (
FID BIGINT DEFAULT 0 NOT NULL,
FCREATORID BIGINT DEFAULT 0 NOT NULL,
FCREATETIME DATETIME,
FMODIFIERID BIGINT DEFAULT 0 NOT NULL,
FMODIFYTIME DATETIME,
FAUDITORID BIGINT DEFAULT 0 NOT NULL,
FAUDITDATE DATETIME
);


IF NOT EXISTS (SELECT 1 FROM KSQL_USERTABLES WHERE KSQL_TABNAME = 'T_SRM_SUPOVERALLEVAENTRY') 
 CREATE TABLE T_SRM_SUPOVERALLEVAENTRY (
FSEQ BIGINT DEFAULT 0 NOT NULL,
FENTRYID BIGINT DEFAULT 0 NOT NULL,
FID BIGINT DEFAULT 0 NOT NULL,
FEVASCORERID BIGINT DEFAULT 0 NOT NULL,
FCFMOPINION NVARCHAR(255) DEFAULT ' ' NOT NULL
);


IF NOT EXISTS (SELECT 1 FROM KSQL_USERTABLES WHERE KSQL_TABNAME = 'T_SRM_SUPOVERALLEVAATT') 
 CREATE TABLE T_SRM_SUPOVERALLEVAATT (
FPKID BIGINT DEFAULT 0 NOT NULL,
FENTRYID BIGINT DEFAULT 0 NOT NULL,
FBASEDATAID BIGINT DEFAULT 0 NOT NULL
);

IF NOT EXISTS (SELECT 1 FROM KSQL_USERTABLES WHERE KSQL_TABNAME = 'T_SRM_GROUPSCORERPTENTRY') 
 CREATE TABLE T_SRM_GROUPSCORERPTENTRY (
FID BIGINT DEFAULT 0 NOT NULL,
FENTRYID BIGINT DEFAULT 0 NOT NULL,
FSEQ BIGINT DEFAULT 0 NOT NULL,
FSCORERPTNOID BIGINT DEFAULT 0 NOT NULL
);

/**End C:\PDM_UPGRADE\PDM1\SRM_table.sql **/
