-- ABS-49216
----------- FLAG -------------
update flag f
   set f.prohibitdelivery = 'Y', f.systemuser_id = 1, f.timestamp = sysdate
 where exists (select 1
          from automaticflag a
         where a.flag_id = f.flag_id
           and a.event in
               ('Replacement requested using replacement button',
                'Substitute garment',
                'Decrease max inv. after return to stock items with this flag',
                'Flag for return to stock due to manual decrease of max inv'))
   and f.prohibitdelivery != 'Y';
commit;

--------- FLAGOPTIONS ---------
update flagoptions fo
   set fo.remove = 'N', fo.systemuser_id = 1, fo.timestamp = sysdate
 where fo.dialog_id in
       (select d.dialog_id
          from dialogs d
         where d.code in ('OutScan',
                          'OutScanSortBatch',
                          'DeliveryNote',
                          'OutscanBulkPutUpByRoute',
                          'BundleSortScan',
                          'UniqueBundle',
                          'OutscanMultiRead'))
   and exists (select 1
          from flag f, automaticflag a
         where fo.flag_id = f.flag_id
           and a.flag_id = f.flag_id
           and a.event in
               ('Replacement requested using replacement button',
                'Substitute garment',
                'Decrease max inv. after return to stock items with this flag',
                'Flag for return to stock due to manual decrease of max inv'))
   and fo.remove != 'N';
commit;