-- ABS-49216
-------  PLANTFLAGOPTIONS  -----------
update plantflagoptions pfo
   set pfo.remove = 'N', pfo.systemuser_id = 1, pfo.timestamp = sysdate
 where pfo.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 pfo.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 pfo.remove != 'N';
commit;