CREATE OR REPLACE PROCEDURE V8_UPD_Voidinvoicerights
IS
   CURSOR wegr_cursor
   IS
      SELECT DISTINCT wusr_wegr_id
        FROM wusr
       WHERE wusr_wegr_id IS NOT NULL AND wusr_name NOT LIKE 'CashieringVoid Invoice';

   rwegr   wegr_cursor%ROWTYPE;
   VoidEnabled number;
BEGIN
   DELETE FROM wusr WHERE wusr_name LIKE 'CashieringVoid Invoice';
   
   SELECT wuss_value INTO VoidEnabled FROM wuss WHERE LOWER(wuss_name) = 'void invoice handling';
   
   IF VoidEnabled <> 1 THEN RETURN; 
   END IF;
   
   FOR rwegr IN wegr_cursor
   LOOP
      INSERT INTO wusr (wusr_id,
                        wusr_wegr_id,
                        wusr_name,
                        wusr_value)
           VALUES (SEQ_WUSR.NEXTVAL,
                   rwegr.wusr_wegr_id,
                   'CashieringVoid Invoice',
                   1);
   END LOOP;
EXCEPTION
   WHEN NO_DATA_FOUND
   THEN
      RAISE;
   WHEN OTHERS
   THEN
      RAISE;
END V8_UPD_Voidinvoicerights;
/


CREATE OR REPLACE PROCEDURE v8_UPD_yfordisplorder_type IS

cursor CURR is select t.data_type   from user_tab_columns t where t.TABLE_NAME = 'YFOR'   and t.COLUMN_NAME = 'YFOR_DISPLORDER';

datatype CURR%rowtype;

BEGIN  

open curr;
fetch curr into datatype;
close curr;

if (datatype.data_type <> 'NUMBER') then 
 
  execute immediate 'alter table YFOR rename column YFOR_DISPLORDER to YFOR_CHARORDER';
 
  execute immediate 'alter table YFOR add YFOR_DISPLORDER number(4)';
  
  execute immediate 'update yfor set yfor_displorder = to_number(yfor_charorder)';
  
  execute immediate 'alter table YFOR drop column  YFOR_CHARORDER';

end if;

   EXCEPTION
     WHEN NO_DATA_FOUND THEN
       NULL;
     WHEN OTHERS THEN
       NULL;
END;
/



