-- ABS-73444/ ABS-93321

-- Disable trigger  IMPORTANT !!
ALTER TRIGGER AFTER_INSERT_DIALOGS DISABLE;

BEGIN
  EXECUTE IMMEDIATE 'INSERT INTO DIALOGS
										(DIALOG_ID,
										 NLDESCRIPTION,
										 CODE,
										 ENDESCRIPTION,
										 GEDESCRIPTION,
										 SYSTEMUSER_ID,
										 ACTIVE,
										 TIMESTAMP,
										 DIALOGONLY,
										 GRIDONLY,
										 CONFPRINTPREVIEW,
										 CONTAINERSCAN,
										 ORPACKSCAN,
										 GARMENTSCAN,
										 RESIDENTIALITEMSCAN,
										 FRDESCRIPTION,
										 DKDESCRIPTION,
										 DIALOGTYPE,
										 REPORTTYPE,
										 REPORTSERVERCLUSTER_ID,
										 DEFINEUSERINSTRUCTIONS,
										 SPDESCRIPTION,
										 FLEXFIELDS
										)											 
      SELECT SEQ_DIALOGS.NEXTVAL,
             ''Kleding afleverbon'',
             ''GarmentDeliveryNote'',
             ''Garment Delivery Notes'',
             ''Bekleidungslieferschein'',
             getminsystemuser(),
             ''Y'',
             SYSDATE,
             ''N'',
             ''N'',
             ''Y'',
             ''N'',
             ''N'',
             ''N'',
             ''N'',
             ''Bulletin livraison VT'',
             ''Beklædnings følgesedle`r'',
             1,
             0,
             null,
             1,
             ''-'',
             ''N''
        FROM DUAL';
EXCEPTION
  WHEN OTHERS THEN
    NULL;
END;
/
COMMIT;

-- Enable trigger  IMPORTANT !!
ALTER TRIGGER AFTER_INSERT_DIALOGS ENABLE;

UPDATE MENUITEM MI
SET MI.DIALOG_ID = (SELECT D.DIALOG_ID FROM DIALOGS D WHERE D.CODE = 'GarmentDeliveryNote')
WHERE MI.DIALOG_ID = (SELECT D.DIALOG_ID FROM DIALOGS D WHERE D.CODE = 'BatchDeliveryNote');
COMMIT;

DELETE FROM MENUITEM_DESC MID
WHERE MID.MENUITEM_ID IN (SELECT MI.MENUITEM_ID FROM MENUITEM MI JOIN DIALOGS D ON MI.DIALOG_ID = D.DIALOG_ID WHERE D.CODE = 'BatchDeliveryNote');
COMMIT;