--ABS-90394/ ABS-92982
/*
CREATE TABLE CUSTOMER_BACKUP_TAX_VALUES AS
(SELECT C.CUSTOMER_ID, C.CUSTOMERNUMBER, C.TAXABLE, C.STATES_ID, C.COUNTYTAXAUTHORITY_ID,
       C.CITYTAXAUTHORITY_ID, C.TAXEXEMPTCODE, C.TAXEXEMPTCERTIFICATEDOCUMENT,
       C.TAXEXEMPTCERTIFICATERECEIVED, C.TIMESTAMP, C.SYSTEMUSER_ID
FROM   CUSTOMER C);

UPDATE CUSTOMER C
SET    C.TAXABLE = 'N', C.TIMESTAMP = SYSDATE
WHERE  C.TAXABLE = 'Y'
AND    C.STATES_ID IS NULL;
COMMIT;

UPDATE CUSTOMER C
SET    C.CITYTAXAUTHORITY_ID = NULL, C.COUNTYTAXAUTHORITY_ID = NULL, C.STATES_ID = NULL,
       C.TIMESTAMP = SYSDATE
WHERE  C.TAXABLE = 'N'
AND    (C.CITYTAXAUTHORITY_ID IS NOT NULL OR C.COUNTYTAXAUTHORITY_ID IS NOT NULL OR
      C.STATES_ID IS NOT NULL);
COMMIT;

UPDATE CUSTOMER C
SET    C.TAXEXEMPTCODE = NULL, C.TAXEXEMPTCERTIFICATEDOCUMENT = NULL,
       C.TAXEXEMPTCERTIFICATERECEIVED = NULL, C.TIMESTAMP = SYSDATE
WHERE  C.TAXABLE = 'Y'
AND    (C.TAXEXEMPTCODE IS NOT NULL OR C.TAXEXEMPTCERTIFICATEDOCUMENT IS NOT NULL OR
      C.TAXEXEMPTCERTIFICATERECEIVED IS NOT NULL);
COMMIT;

ALTER TABLE CUSTOMER ADD CONSTRAINT CHK_CUSTOMER_TAXABLE CHECK(
  (TAXABLE = 'Y' AND
   STATES_ID IS NOT NULL AND
   TAXEXEMPTCODE IS NULL AND
   TAXEXEMPTCERTIFICATEDOCUMENT IS NULL AND
   TAXEXEMPTCERTIFICATERECEIVED IS NULL) 
   OR
   (TAXABLE = 'N' AND
   COUNTYTAXAUTHORITY_ID IS NULL AND
   CITYTAXAUTHORITY_ID IS NULL AND
   STATES_ID IS NULL)
  );
*/