-- ABS-99756 / ABS-99758
--- VERTEXTRANSACTIONLOG ---
ALTER TABLE VERTEXTRANSACTIONLOG DROP CONSTRAINT CHK_VERTEXLOG_ISTAX;

ALTER TABLE VERTEXTRANSACTIONLOG RENAME COLUMN ISTAXONLYADJUSTMENT TO TAXONLYADJUSTMENTIND;
ALTER TABLE VERTEXTRANSACTIONLOG RENAME COLUMN PHYSICALORIGINSTREETADD1 TO PHYSICALORIGINSTREET;
ALTER TABLE VERTEXTRANSACTIONLOG RENAME COLUMN ADMINTAXAREAID TO ADMINDESTINATIONTAXAREAID;
ALTER TABLE VERTEXTRANSACTIONLOG RENAME COLUMN ADMINSTREETADDRESS1 TO ADMINDESTINATIONSTREET;
ALTER TABLE VERTEXTRANSACTIONLOG RENAME COLUMN ADMINCITY TO ADMINDESTINATIONCITY;
ALTER TABLE VERTEXTRANSACTIONLOG RENAME COLUMN ADMINMAINDIVISION TO ADMINDESTINATIONMAINDIVISION;
ALTER TABLE VERTEXTRANSACTIONLOG RENAME COLUMN ADMINSUBDIVISION TO ADMINDESTINATIONSUBDIVISION;
ALTER TABLE VERTEXTRANSACTIONLOG RENAME COLUMN ADMINPOSTALCODE TO ADMINDESTINATIONPOSTALCODE;
ALTER TABLE VERTEXTRANSACTIONLOG RENAME COLUMN ADMINCOUNTRY TO ADMINDESTINATIONCOUNTRY;
ALTER TABLE VERTEXTRANSACTIONLOG RENAME COLUMN DESTINATIONSTREETADD1 TO DESTINATIONSTREET;
ALTER TABLE VERTEXTRANSACTIONLOG RENAME COLUMN PRODUCT TO PRODUCTCODE;
ALTER TABLE VERTEXTRANSACTIONLOG RENAME COLUMN PRODUCTCLASS TO PRODUCTCLASSCODE;

ALTER TABLE VERTEXTRANSACTIONLOG ADD CONSTRAINT CHK_VERTEXLOG_ISTAX CHECK (TAXONLYADJUSTMENTIND IN (0,1));

--- INVOICEHEADEREXTRAINFO ---
UPDATE INVOICEHEADEREXTRAINFO IHE
   SET IHE.TAXSTATUS = 5
 WHERE IHE.INVOICEHEADER_ID IN
       (SELECT IH.INVOICEHEADER_ID
          FROM INVOICEHEADER IH
         WHERE IH.STATUS_ID = (SELECT S.STATUS_ID
                                 FROM STATUS S
                                WHERE S.STATUSTYPE = 'IN'
                                  AND S.CODE = 2));
COMMIT;

UPDATE INVOICEHEADEREXTRAINFO IHE
   SET IHE.TAXSTATUS = 2
 WHERE IHE.INVOICEHEADER_ID IN
       (SELECT IH.INVOICEHEADER_ID
          FROM INVOICEHEADER IH
         WHERE IH.STATUS_ID = (SELECT S.STATUS_ID
                                 FROM STATUS S
                                WHERE S.STATUSTYPE = 'IN'
                                  AND S.CODE = 1));
COMMIT;
