 --order 502742
      /*
      CHANGE REPORT for Table NONUNIQUEITEM
          - Adding column CHARGEDFORLOSS
      ACTION is ALTER or modify Table NONUNIQUEITEM
      */

ALTER TABLE NONUNIQUEITEM ADD (CHARGEDFORLOSS       VARCHAR2(1) DEFAULT 'N' NOT 
    NULL
                                   CONSTRAINT YN_ValidationField6
                                          CHECK (CHARGEDFORLOSS IN ('Y', 'N')));

      
      /*
      CHANGE REPORT for Table UNIQUEITEMNONPOOL
          - Adding column CHARGEDFORLOSS
      ACTION is ALTER or modify Table UNIQUEITEMNONPOOL
      */

ALTER TABLE UNIQUEITEMNONPOOL ADD (CHARGEDFORLOSS       VARCHAR2(1) DEFAULT 'N' 
    NOT NULL
                                   CONSTRAINT YN_ValidationField5
                                          CHECK (CHARGEDFORLOSS IN ('Y', 'N')));

UPDATE uniqueitemnonpool uinp
   SET uinp.ChargedForLoss = 'Y'
 where uinp.wearerinventory_id in
       (SELECT winv.wearerinventory_id
          FROM wearerinventory winv
         WHERE winv.losschargeinvoiceline_id <> 0
           AND winv.dateinactive < trunc(SYSDATE));

commit;

UPDATE uniqueitemnonpool uinp
   SET uinp.ChargedForLoss = 'Y'
 where uinp.uniqueitem_id in
       (select uifi.uniqueitem_id
          FROM Uniqueitemfixedinfo uifi
         WHERE uifi.losschargeinvoiceline_id <> 0);

commit;