IF NOT EXISTS(SELECT * FROM INFORMATION_SCHEMA.COLUMNS WHERE TABLE_NAME = 'mnrBillIntegration' AND COLUMN_NAME = 'bCoreFlag')
BEGIN
    EXEC('ALTER TABLE [mnrBillIntegration] ADD [bCoreFlag] bit');
    
    EXEC('
    ALTER VIEW [dbo].[mnrVWBillIntegration]
    AS
    SELECT 
        CASE SystemFlag
            WHEN 1 THEN ''Vertex''
            WHEN 2 THEN ''DTTS'' 
            WHEN 3 THEN ''E-Invoice-EGP'' 
            WHEN 4 THEN ''E-Invoice-SY''
            WHEN 5 THEN ''E-Invoice-SAR'' 
            WHEN 6 THEN ''E-Fatura-TRY'' 
        END AS SystemName,
        bint.*  
    FROM [dbo].[mnrBillIntegration] bint
    ');
END
ELSE
BEGIN
    EXEC('
    ALTER VIEW [dbo].[mnrVWBillIntegration]
    AS
    SELECT 
        CASE SystemFlag
            WHEN 1 THEN ''Vertex''
            WHEN 2 THEN ''DTTS'' 
            WHEN 3 THEN ''E-Invoice-EGP'' 
            WHEN 4 THEN ''E-Invoice-SY''
            WHEN 5 THEN ''E-Invoice-SAR'' 
            WHEN 6 THEN ''E-Fatura-TRY'' 
        END AS SystemName,
        bint.*  
    FROM [dbo].[mnrBillIntegration] bint
    ');
END
GO


UPDATE MNRBILLINTEGRATION SET bCoreFlag=1


		if( not exists( select * from syscolumns c inner join sysobjects t on c.id = t.id where t.xtype = 'U' and t.Name = 'mnrHotResItem' and c.Name = 'BillNumber'))
		exec( 'ALTER TABLE [mnrHotResItem] ADD [BillNumber] [float] NULL')

		if( not exists( select * from syscolumns c inner join sysobjects t on c.id = t.id where t.xtype = 'U' and t.Name = 'mnrBillIntegration' and c.Name = 'WarnCause'))
      exec( 'ALTER TABLE [mnrBillIntegration] ADD  [WarnCause]  [NVARCHAR] (4000) COLLATE Arabic_CI_AI NULL')

