ALTER TABLE VS4TAPInvoice ADD
	TIAPDestination nvarchar(50) NULL,
	TIAPTransportDesc money NULL,
	TIAPDuty money NULL,
	TIAPBaseIncoType smallint NULL,
	TIAPDiscountText nvarchar(30) NULL,
	TIAPDepositText nvarchar(30) NULL,
	TIAPWTAXBase money NULL,
	TIAPVATType smallint NULL,
	TIAPTotal money NULL,
	TIAPTotalInRate money NULL,
	TIAPNetTotal money NULL
GO
UPDATE VS4TAPInvoice Set TIAPCountryOrigin = (Select TCouName2 FROM VS4TCountry WHERE TCouCode=(select tapntcouCode from vs4tap where tapncode=TIAPtapncode))
GO
UPDATE VS4TAPInvoice Set TIAPDestination ='Thailand'
GO
UPDATE VS4TAPInvoice Set TIAPBaseIncoType =TIAPIncoType where TIAPBaseIncoType is null
GO
UPDATE VS4TAPInvoice Set TIAPTransportDesc=0 where TIAPTransportDesc is null
GO
UPDATE VS4TAPInvoice Set TIAPDuty=0 where TIAPDuty is null
GO
UPDATE VS4TAPInvoice Set TIAPWTAXBase=TIAPTaxBase ,TIAPVATType=TIAPDepositVAT,TIAPTotal=TIAPGrandTotalVAT, TIAPTotalInRate=TIAPFirstPayment, TIAPNetTotal=TIAPWTAXRate
GO

UPDATE VS4TAPInvoice SET TIAPDepositText=replace(''+convert(char(20),round(TIAPDepositRate,2)),' ','') where TIAPDepositRate > 0
GO
UPDATE VS4TAPInvoice SET TIAPDepositText=TIAPDepositText+'%' WHERE TIAPDepositText<>''
GO

UPDATE VS4TAPInvoice SET TIAPDiscountText=replace(''+convert(char(20),round(TIAPDiscountPC,2)),' ','') where TIAPDiscountPC > 0
GO
UPDATE VS4TAPInvoice SET TIAPDiscountText=TIAPDiscountText+'%' WHERE TIAPDiscountText<>''
GO
UPDATE VS4TAPInvoice SET TIAPDiscountText=TIAPDiscountText+'+'+replace(''+convert(char(20),round(TIAPDiscountFix,2)),' ','') where TIAPDiscountFix > 0
GO


UPDATE VS4TAPInvoice Set TIAPFlag2=TIAPIncoType
GO
ALTER TABLE VS4TAPInvoice
	DROP COLUMN TIAPIncoType,TIAPBaseIncoType
GO
ALTER TABLE VS4TAPInvoice ADD
	TIAPIncoType nvarchar(3) NULL,
	TIAPBaseIncoType nvarchar(3) NULL
GO
UPDATE VS4TAPInvoice Set TIAPIncoType='FOB' WHERE TIAPFlag2=0
GO
UPDATE VS4TAPInvoice Set TIAPIncoType='CIF' WHERE TIAPFlag2=1
GO
UPDATE VS4TAPInvoice Set TIAPIncoType='CFR' WHERE TIAPFlag2=2
GO
UPDATE VS4TAPInvoice Set TIAPIncoType='EXW' WHERE TIAPFlag2=3
GO
UPDATE VS4TAPInvoice Set TIAPBaseIncoType =TIAPIncoType where TIAPBaseIncoType is null
GO