-- ABS-117952/ ABS-118551

COMMENT ON COLUMN CUSTOMERBILLINGINFO.SENDSTATEMENTBYFAX
  IS 'UNUSED COLUMN BUT KEPT FOR BI COMPATIBILITY';
COMMENT ON COLUMN CUSTOMERBILLINGINFO.SENDINVOICEBYFAX
  IS 'UNUSED COLUMN BUT KEPT FOR BI COMPATIBILITY';
COMMENT ON COLUMN CUSTOMERBILLINGINFO.SENDDIRECTINVOICEBYFAX
  IS 'UNUSED COLUMN BUT KEPT FOR BI COMPATIBILITY';

COMMENT ON COLUMN CUSTOMERBILLINGINFO.SENDINVOICEBY
  IS '0 = Send by Mail
2 = Send by E-mail
3 = Send by EDI';


ALTER TABLE INVOICEHEADER SET UNUSED COLUMN FAXSTATUS;

DELETE FROM PLANTPROCESS PP
WHERE PP.PROCESS_ID IN (26, 27, 28);
COMMIT;

DELETE FROM PROCESS P
WHERE P.PROCESS_ID IN (26, 27, 28);
COMMIT;

ALTER TABLE CONTRACTCOMPONENTBILLING DROP COLUMN SENDSTATEMENTBYFAX;

DELETE FROM COMPLIANCYGROUPATTRIBUTES CGA
WHERE CGA.CONTRACTATTRIBUTE_ID = 97;
COMMIT;

DELETE FROM COMPLIANCYTEMPLATELINE CTL
WHERE CTL.CONTRACTATTRIBUTE_ID = 97;
COMMIT;

DELETE FROM CONTRACTCOMPLIANCY CC
WHERE CC.CONTRACTATTRIBUTE_ID = 97;
COMMIT;

DELETE FROM CONTRACTATTRIBUTE CA
WHERE CA.CONTRACTATTRIBUTE_ID = 97;
COMMIT;

COMMENT ON COLUMN SUPPLIER.SENDPURCHASEORDER
  IS '0 = By regular mail 2 = By e-mail 3 = By mail 4 = By file 5 = Electronic data transfer only';

-- CREATE THE SYSTEM SETTING WHEN IT DOES NOT EXIST YET FOR ALL PLANTS, SETTING ITS INITIAL VALUE TO -1 (INSTEAD OF THE REGULAR DEFAULT 0)
CREATE OR REPLACE PROCEDURE TEMPCREATESS AS
BEGIN
CREATESYSTEMSETTING('Billing', 'ONLYEMAILADJUSTED', '-1', 'B', 'N', 'N', 'N', NULL, NULL, '', 'Y = only invoices with adjustments will be sent by e-mail after complete settlement.'|| CHR(10) ||'N = all invoices (adjusted or not) will be sent by e-mail after complete settlement.'|| CHR(10) ||'This setting replaces the ONLYEMAILFAXADJUSTED system setting as of 9.05.03.', 'N');
CREATESYSTEMSETTING('Billing', 'ONLYEMAILFAXADJUSTED', 'N', 'B', 'N', 'N', 'N', NULL, NULL, '', 'Y = only invoices with adjustments will be sent by e-mail after complete settlement.'|| CHR(10) ||'N = all invoices (adjusted or not) will be sent by e-mail after complete settlement.'|| CHR(10) ||'This setting is replaced by the ONLYEMAILADJUSTED system setting as of 9.05.03.', 'N');
END TEMPCREATESS;
/
EXECUTE TEMPCREATESS;

DROP PROCEDURE TEMPCREATESS;

-- ONLY UPDATE THOSE RECORDS THAT HAVE NOT BEEN UPDATED BEFORE, ONCE UPDATED, THE VALUE WILL NEVER BE -1 AGAIN
UPDATE SYSTEMSETTING SN
   SET SN.VALUE =
       (SELECT OV.VALUE
          FROM SYSTEMSETTING OV
         WHERE OV.PLANT_ID = SN.PLANT_ID
           AND OV.NAME = 'ONLYEMAILFAXADJUSTED')
 WHERE SN.NAME = 'ONLYEMAILADJUSTED'
   AND SN.VALUE = '-1';
COMMIT;

ALTER TABLE ERP_I_CONTRACTCOMPONENT DROP COLUMN SENDSTATEMENTBYFAX;
