--ABS-103549 / ABS-103797
---- MENUITEM -----
UPDATE MENUITEM MI
SET MI.DIALOG_ID=(SELECT D.DIALOG_ID 
                  FROM DIALOGS D 
                  WHERE D.CODE='GarmentDeliveryNote'),
MI.TIMESTAMP=SYSDATE,
MI.SYSTEMUSER_ID=GETMINSYSTEMUSER()
WHERE MI.DIALOG_ID=(SELECT D.DIALOG_ID 
                    FROM DIALOGS D 
                    WHERE D.CODE='BatchDeliveryNote')
AND EXISTS (SELECT D.DIALOG_ID 
            FROM DIALOGS D 
            WHERE D.CODE='GarmentDeliveryNote');
COMMIT;

---- USERINSTRUCTIONPERSCREEN ------
UPDATE USERINSTRUCTIONPERSCREEN UPS
SET UPS.DIALOG_ID=(SELECT D.DIALOG_ID 
                   FROM DIALOGS D 
                   WHERE D.CODE='GarmentDeliveryNote'),
UPS.TIMESTAMP=SYSDATE,
UPS.SYSTEMUSER_ID=GETMINSYSTEMUSER()
WHERE UPS.DIALOG_ID=(SELECT D.DIALOG_ID 
                     FROM DIALOGS D 
                     WHERE D.CODE='BatchDeliveryNote')
AND NOT EXISTS
(SELECT 1 FROM USERINSTRUCTIONPERSCREEN UPS
WHERE NVL(UPS.CUSTOMERUSERINSTRUCTION_ID,-1)=NVL(UPS.CUSTOMERUSERINSTRUCTION_ID,-1)
AND NVL(UPS.GENERALUSERINSTRUCTION_ID,-1)=NVL(UPS.GENERALUSERINSTRUCTION_ID,-1)
AND UPS.DIALOG_ID=(SELECT D.DIALOG_ID 
                   FROM DIALOGS D 
                   WHERE D.CODE='GarmentDeliveryNote'))
AND EXISTS (SELECT D.DIALOG_ID 
            FROM DIALOGS D 
            WHERE D.CODE='GarmentDeliveryNote');
COMMIT;

--------- FORMPRINTCONFIGURATION ----------
DELETE FROM FORMPRINTCONFIGURATION FP
WHERE FP.PREDEFINEDREPORT_ID=(SELECT PR.PREDEFINEDREPORT_ID FROM PREDEFINEDREPORT PR
                                                            WHERE PR.DIALOG_ID=(SELECT D.DIALOG_ID FROM DIALOGS D 
                                                                                                   WHERE D.CODE='CorrectionTicket')
                                                            AND PR.RPTFILENAME='Correctiebon');
COMMIT;
DELETE FROM FORMPRINTCONFIGURATION FP
WHERE FP.PREDEFINEDREPORT_ID=(SELECT PR.PREDEFINEDREPORT_ID FROM PREDEFINEDREPORT PR
                                                            WHERE PR.DIALOG_ID=(SELECT D.DIALOG_ID FROM DIALOGS D 
                                                                                                   WHERE D.CODE='CorrectionTicket')
                                                            AND PR.RPTFILENAME='Correctie bon');
COMMIT;		
DELETE FROM FORMPRINTCONFIGURATION FP
WHERE FP.PREDEFINEDREPORT_ID=(SELECT PR.PREDEFINEDREPORT_ID FROM PREDEFINEDREPORT PR
                                                            WHERE PR.DIALOG_ID=(SELECT D.DIALOG_ID FROM DIALOGS D 
                                                                                                   WHERE D.CODE='DeliveryNote')
                                                            AND PR.RPTFILENAME='Afleverbon');
COMMIT;
DELETE FROM FORMPRINTCONFIGURATION FP
WHERE FP.PREDEFINEDREPORT_ID=(SELECT PR.PREDEFINEDREPORT_ID FROM PREDEFINEDREPORT PR
                                                            WHERE PR.DIALOG_ID=(SELECT D.DIALOG_ID FROM DIALOGS D 
                                                                                                   WHERE D.CODE='DeliveryNote')
                                                            AND PR.RPTFILENAME='Afleveringsbon');
COMMIT;
DELETE FROM FORMPRINTCONFIGURATION FP
WHERE FP.PREDEFINEDREPORT_ID=(SELECT PR.PREDEFINEDREPORT_ID FROM PREDEFINEDREPORT PR
                                                            WHERE PR.DIALOG_ID=(SELECT D.DIALOG_ID FROM DIALOGS D 
                                                                                                   WHERE D.CODE='DeliveryVariations')
                                                            AND PR.RPTFILENAME='Openstaande Mutaties');
COMMIT;
DELETE FROM FORMPRINTCONFIGURATION FP
WHERE FP.PREDEFINEDREPORT_ID=(SELECT PR.PREDEFINEDREPORT_ID FROM PREDEFINEDREPORT PR
                                                            WHERE PR.DIALOG_ID=(SELECT D.DIALOG_ID FROM DIALOGS D 
                                                                                                   WHERE D.CODE='WeighingTicket')
                                                            AND PR.RPTFILENAME='Weegbrief');
COMMIT;
DELETE FROM FORMPRINTCONFIGURATION FP
WHERE FP.PREDEFINEDREPORT_ID=(SELECT PR.PREDEFINEDREPORT_ID FROM PREDEFINEDREPORT PR
                                                            WHERE PR.DIALOG_ID=(SELECT D.DIALOG_ID FROM DIALOGS D 
                                                                                                   WHERE D.CODE='WorkOrder')
                                                            AND PR.RPTFILENAME='Inzetopdracht');
COMMIT;
DELETE FROM FORMPRINTCONFIGURATION FP
WHERE FP.PREDEFINEDREPORT_ID=(SELECT PR.PREDEFINEDREPORT_ID FROM PREDEFINEDREPORT PR
                                                            WHERE PR.DIALOG_ID=(SELECT D.DIALOG_ID FROM DIALOGS D 
                                                                                                   WHERE D.CODE='BatchDeliveryNote')
                                                            AND PR.RPTFILENAME='DeliveryNote');
COMMIT;
DELETE FROM FORMPRINTCONFIGURATION FP
WHERE FP.PREDEFINEDREPORT_ID=(SELECT PR.PREDEFINEDREPORT_ID FROM PREDEFINEDREPORT PR
                                                            WHERE PR.DIALOG_ID=(SELECT D.DIALOG_ID FROM DIALOGS D 
                                                                                                   WHERE D.CODE='BatchDeliveryNote')
                                                            AND PR.RPTFILENAME='ContainerStickersInAdvance');
COMMIT;
DELETE FROM FORMPRINTCONFIGURATION FP
WHERE FP.PREDEFINEDREPORT_ID=(SELECT PR.PREDEFINEDREPORT_ID FROM PREDEFINEDREPORT PR
                                                            WHERE PR.DIALOG_ID=(SELECT D.DIALOG_ID FROM DIALOGS D 
                                                                                                   WHERE D.CODE='TSRouteCollection')
                                                            AND PR.RPTFILENAME='ContainerSticker');
COMMIT;
DELETE FROM FORMPRINTCONFIGURATION FP
WHERE FP.PREDEFINEDREPORT_ID=(SELECT PR.PREDEFINEDREPORT_ID FROM PREDEFINEDREPORT PR
                                                            WHERE PR.DIALOG_ID=(SELECT D.DIALOG_ID FROM DIALOGS D 
                                                                                                   WHERE D.CODE='TSSorting')
                                                            AND PR.RPTFILENAME='DeliveryNote');
COMMIT;

------ PREDEFINEDREPORT ---------
INSERT INTO PREDEFINEDREPORT(PREDEFINEDREPORT_ID,
                             DIALOG_ID,
                             RPTFILENAME,
                             NLDESCRIPTION,
                             ENDESCRIPTION,
                             GEDESCRIPTION,
                             SYSTEMUSER_ID,
                             TIMESTAMP)
              SELECT SEQ_PREDEFINEDREPORT.NEXTVAL,
              (SELECT D.DIALOG_ID FROM DIALOGS D WHERE D.CODE='GarmentDeliveryNote'),
              PR.RPTFILENAME,
              PR.NLDESCRIPTION,
              PR.ENDESCRIPTION,
              PR.GEDESCRIPTION,
              PR.SYSTEMUSER_ID,
              PR.TIMESTAMP
              FROM PREDEFINEDREPORT PR
              WHERE PR.DIALOG_ID=(SELECT D.DIALOG_ID FROM DIALOGS D WHERE D.CODE='BatchDeliveryNote')
              AND NOT EXISTS
              (SELECT 1
              FROM PREDEFINEDREPORT PRP
              WHERE PRP.DIALOG_ID=(SELECT D.DIALOG_ID 
                                   FROM DIALOGS D 
                                   WHERE D.CODE='GarmentDeliveryNote')
              AND PRP.RPTFILENAME=PR.RPTFILENAME);
           COMMIT;
					 			 
DELETE FROM PREDEFINEDREPORT PR
WHERE PR.DIALOG_ID=(SELECT D.DIALOG_ID FROM DIALOGS D WHERE D.CODE='CorrectionTicket')
AND PR.RPTFILENAME='Correctiebon';
COMMIT;
DELETE FROM PREDEFINEDREPORT PR
WHERE PR.DIALOG_ID=(SELECT D.DIALOG_ID FROM DIALOGS D WHERE D.CODE='CorrectionTicket')
AND PR.RPTFILENAME='Correctie bon';
COMMIT;
DELETE FROM PREDEFINEDREPORT PR
WHERE PR.DIALOG_ID=(SELECT D.DIALOG_ID FROM DIALOGS D WHERE D.CODE='DeliveryNote')
AND PR.RPTFILENAME='Afleverbon';
COMMIT;
DELETE FROM PREDEFINEDREPORT PR
WHERE PR.DIALOG_ID=(SELECT D.DIALOG_ID FROM DIALOGS D WHERE D.CODE='DeliveryNote')
AND PR.RPTFILENAME='Afleveringsbon';
COMMIT;
DELETE FROM PREDEFINEDREPORT PR
WHERE PR.DIALOG_ID=(SELECT D.DIALOG_ID FROM DIALOGS D WHERE D.CODE='DeliveryVariations')
AND PR.RPTFILENAME='Openstaande Mutaties';
COMMIT;
DELETE FROM PREDEFINEDREPORT PR
WHERE PR.DIALOG_ID=(SELECT D.DIALOG_ID FROM DIALOGS D WHERE D.CODE='WeighingTicket')
AND PR.RPTFILENAME='Weegbrief';
COMMIT;
DELETE FROM PREDEFINEDREPORT PR
WHERE PR.DIALOG_ID=(SELECT D.DIALOG_ID FROM DIALOGS D WHERE D.CODE='WorkOrder')
AND PR.RPTFILENAME='Inzetopdracht';
COMMIT;
DELETE FROM PREDEFINEDREPORT PR
WHERE PR.DIALOG_ID=(SELECT D.DIALOG_ID FROM DIALOGS D WHERE D.CODE='BatchDeliveryNote')
AND PR.RPTFILENAME='DeliveryNote';
COMMIT;
DELETE FROM PREDEFINEDREPORT PR
WHERE PR.DIALOG_ID=(SELECT D.DIALOG_ID FROM DIALOGS D WHERE D.CODE='BatchDeliveryNote')
AND PR.RPTFILENAME='ContainerStickersInAdvance';
COMMIT;
DELETE FROM PREDEFINEDREPORT PR
WHERE PR.DIALOG_ID=(SELECT D.DIALOG_ID FROM DIALOGS D WHERE D.CODE='TSRouteCollection')
AND PR.RPTFILENAME='ContainerSticker';
COMMIT;
DELETE FROM PREDEFINEDREPORT PR
WHERE PR.DIALOG_ID=(SELECT D.DIALOG_ID FROM DIALOGS D WHERE D.CODE='TSSorting')
AND PR.RPTFILENAME='DeliveryNote';
COMMIT;