/**Begin E:\NextERP_PDM\PDM_UPGRADE\PDMS\branch_lastest\pdm\MAL_table.sql **/
IF NOT EXISTS (SELECT 1 FROM KSQL_USERTABLES WHERE KSQL_TABNAME = 'T_MAL_EMALPAYTYPE_L') 
 CREATE TABLE T_MAL_EMALPAYTYPE_L (
FPKID VARCHAR(36) DEFAULT ' '  NOT NULL,
FLOCALEID VARCHAR(10) DEFAULT ' ' NOT NULL,
FNAME VARCHAR(50) DEFAULT ' ' NOT NULL,
FID BIGINT DEFAULT 0 NOT NULL
);


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


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


IF NOT EXISTS (SELECT 1 FROM KSQL_USERTABLES WHERE KSQL_TABNAME = 'T_MAL_EMALPAYTYPE') 
 CREATE TABLE T_MAL_EMALPAYTYPE (
FID BIGINT DEFAULT 0 NOT NULL,
FNUMBER VARCHAR(80) DEFAULT ' ' NOT NULL,
FSTATUS CHAR(1) DEFAULT ' ' NOT NULL,
FCREATORID BIGINT DEFAULT 0 NOT NULL,
FMODIFIERID BIGINT DEFAULT 0 NOT NULL,
FENABLE CHAR(1) DEFAULT ' ' NOT NULL,
FCREATETIME DATETIME,
FMODIFYTIME DATETIME,
FMASTERID BIGINT DEFAULT 0 NOT NULL,
FAUDITORID BIGINT DEFAULT 0 NOT NULL,
FAUDITDATE DATETIME,
FEMALTYPE CHAR(1) DEFAULT ' ' NOT NULL,
FPAYTYPENUMBER VARCHAR(20) DEFAULT ' ' NOT NULL,
FPRESET CHAR(1) DEFAULT ' ' NOT NULL
);


IF NOT EXISTS (SELECT 1 FROM KSQL_USERTABLES WHERE KSQL_TABNAME = 'T_MAL_PAYTYPE') 
 CREATE TABLE T_MAL_PAYTYPE (
FID BIGINT DEFAULT 0 NOT NULL,
FNUMBER VARCHAR(80) DEFAULT ' ' NOT NULL,
FSTATUS CHAR(1) DEFAULT ' ' NOT NULL,
FCREATORID BIGINT DEFAULT 0 NOT NULL,
FMODIFIERID BIGINT DEFAULT 0 NOT NULL,
FENABLE CHAR(1) DEFAULT ' ' NOT NULL,
FCREATETIME DATETIME,
FMODIFYTIME DATETIME,
FMASTERID BIGINT DEFAULT 0 NOT NULL,
FAUDITORID BIGINT DEFAULT 0 NOT NULL,
FAUDITDATE DATETIME,
FSETTLETYPEID BIGINT DEFAULT 0 NOT NULL,
FPURMODE CHAR(1) DEFAULT ' ' NOT NULL,
FISPREPAID CHAR(1) DEFAULT ' ' NOT NULL,
FPRESET CHAR(1) DEFAULT ' ' NOT NULL,
FPURCONDITIONID BIGINT DEFAULT 0 NOT NULL
);


IF NOT EXISTS (SELECT 1 FROM KSQL_USERTABLES WHERE KSQL_TABNAME = 'T_MAL_INVOICETYPE') 
 CREATE TABLE T_MAL_INVOICETYPE (
FID BIGINT DEFAULT 0 NOT NULL,
FNUMBER VARCHAR(80) DEFAULT ' ' NOT NULL,
FSTATUS CHAR(1) DEFAULT ' ' NOT NULL,
FCREATORID BIGINT DEFAULT 0 NOT NULL,
FMODIFIERID BIGINT DEFAULT 0 NOT NULL,
FENABLE BIGINT DEFAULT 0 NOT NULL,
FCREATETIME DATETIME,
FMODIFYTIME DATETIME,
FMASTERID BIGINT DEFAULT 0 NOT NULL,
FMALINVOICETYPE VARCHAR(255) DEFAULT ' ' NOT NULL,
FEMALTYPE VARCHAR(255) DEFAULT ' ' NOT NULL,
FEMALINVOICENUMBER VARCHAR(255) DEFAULT ' ' NOT NULL,
FEMALINVOICETYPE VARCHAR(255) DEFAULT ' ' NOT NULL,
FAUDITORID BIGINT DEFAULT 0 NOT NULL,
FAUDITDATE DATETIME,
FPRESET CHAR(1) DEFAULT ' ' NOT NULL
);


IF NOT EXISTS (SELECT 1 FROM KSQL_USERCOLUMNS WHERE KSQL_COL_TABNAME = 'T_MAL_INVOICETYPE' AND KSQL_COL_NAME IN ('FSTATUS')) 
 ALTER TABLE T_MAL_INVOICETYPE ADD (FSTATUS CHAR(1) DEFAULT ' ' NOT NULL );

 

 
IF NOT EXISTS (SELECT 1 FROM KSQL_USERCOLUMNS WHERE KSQL_COL_TABNAME = 'T_MAL_INVOICETYPE' AND KSQL_COL_NAME IN ('FEMALINVOICENUMBER')) 
 ALTER TABLE T_MAL_INVOICETYPE ADD (FEMALINVOICENUMBER  VARCHAR(255) DEFAULT ' ' NOT NULL);


IF NOT EXISTS (SELECT 1 FROM KSQL_USERCOLUMNS WHERE KSQL_COL_TABNAME = 'T_MAL_PAYTYPE' AND KSQL_COL_NAME IN ('FPURCONDITIONID')) 
 ALTER TABLE T_MAL_PAYTYPE ADD (FPURCONDITIONID BIGINT DEFAULT 0 NOT NULL );

 

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

 EXEC p_AlterColumn 'T_MAL_PAYTYPE_L', 'FPKID', 'VARCHAR(36)', 'NOT NULL', '1111', ''' ''';

 EXEC p_AlterColumn 'T_MAL_INVOICETYPE_L', 'FPKID', 'VARCHAR(36)', 'NOT NULL', '1111', ''' ''';
 
/**End E:\NextERP_PDM\PDM_UPGRADE\PDMS\branch_lastest\pdm\MAL_table.sql **/
