UPDATE VS4TARInvoice Set TIvoCountryOrigin ='Thailand'
GO
ALTER TABLE VS4TARInvoice ADD
	TIvoTransportDesc money NULL,
	TIvoDuty money NULL,
	TIvoBaseIncoType smallint  NULL,
	TIvoDiscountText nvarchar(30) NULL,
	TIvoDepositText nvarchar(30) NULL,
	TIvoWTAXBase money NULL,
	TIvoVATType smallint NULL,
	TIvoTotal money NULL,
	TIvoTotalInRate money NULL,
	TIvoNetTotal money NULL
GO
UPDATE VS4TARInvoice Set TIvoBaseIncoType =TIvoIncoType where TIvoBaseIncoType is null
GO
UPDATE VS4TARInvoice Set TIvoTransportDesc=0 where TIvoTransportDesc is null
GO
UPDATE VS4TARInvoice Set TIvoDuty=0 where TIvoDuty is null
GO

UPDATE VS4TARInvoice Set TIvoWTAXBase=TIvoTaxBase ,TIvoVATType=TIvoDepositVAT,TIvoTotal=TIvoGrandTotalVAT, TIvoTotalInRate=TIvoFirstPayment, TIvoNetTotal=TIvoWTAXRate
GO

UPDATE VS4TARInvoice SET TIvoDepositText=replace(''+convert(char(20),round(TIvoDepositRate,2)),' ','') where TIvoDepositRate > 0
GO
UPDATE VS4TARInvoice SET TIvoDepositText=TIvoDepositText+'%' WHERE TIvoDepositText<>''
GO

UPDATE VS4TARInvoice SET TIvoDiscountText=replace(''+convert(char(20),round(TIvoDiscountPC,2)),' ','') where TIvoDiscountPC > 0
GO
UPDATE VS4TARInvoice SET TIvoDiscountText=TIvoDiscountText+'%' WHERE TIvoDiscountText<>''
GO
UPDATE VS4TARInvoice SET TIvoDiscountText=TIvoDiscountText+'+'+replace(''+convert(char(20),round(TIvoDiscountFix,2)),' ','') where TIvoDiscountFix > 0
GO


UPDATE VS4TARInvoice Set TIvoFlag2=TIvoIncoType
GO
ALTER TABLE VS4TARInvoice
	DROP COLUMN TIvoIncoType,TIvoBaseIncoType
GO
ALTER TABLE VS4TARInvoice ADD
	TIvoIncoType nvarchar(3) NULL,
	TIvoBaseIncoType nvarchar(3) NULL
GO
UPDATE VS4TARInvoice Set TIvoIncoType='FOB' WHERE TIvoFlag2=0
GO
UPDATE VS4TARInvoice Set TIvoIncoType='CIF' WHERE TIvoFlag2=1
GO
UPDATE VS4TARInvoice Set TIvoIncoType='CFR' WHERE TIvoFlag2=2
GO
UPDATE VS4TARInvoice Set TIvoIncoType='EXW' WHERE TIvoFlag2=3
GO
UPDATE VS4TARInvoice Set TIvoBaseIncoType =TIvoIncoType where TIvoBaseIncoType is null
GO