Back to OIM Explorer

dbo.QER_ZITShopCheckDecision

Stored ProcedureSQL_STORED_PROCEDURESandbox DB

Stored Procedure. HOCallMethod -> personwantsorg.ESCALATE at line 22; HOCallMethod -> personwantsorg.ESCALATE at line 22; HOCallMethod -> personwantsorg.ESCALATE at line 37; HOCallMethod -> personwantsorg.ESCALATE at line 37

Source: sandbox-db sys.sql_modules

Source size: 26.726 characters

Interpretation

  • Database routine. Review parameters, called procedures, DBQueue inserts, and QBM_PJobCreate helper calls before assuming side effects.
  • Object-layer bridge detected through QBM_PJobCreate helper usage.
  • DBQueue relation detected. Follow the task procedure and referenced-by list for async processing.

Relations

  • HOCallMethod -> personwantsorg.ESCALATE at line 22
  • HOCallMethod -> personwantsorg.ESCALATE at line 22
  • HOCallMethod -> personwantsorg.ESCALATE at line 37
  • HOCallMethod -> personwantsorg.ESCALATE at line 37
  • HOCallMethod -> personwantsorg.ESCALATE at line 37
  • HOCallMethod -> personwantsorg.ESCALATE at line 37
  • HOCallMethod -> personwantsorg.ESCALATE at line 41
  • HOCallMethod -> personwantsorg.ESCALATE at line 41
  • HOCallMethod -> personwantsorg.ESCALATE at line 41
  • HOCallMethod -> personwantsorg.ESCALATE at line 54
  • HOCallMethod -> personwantsorg.ESCALATE at line 54
  • HOCallMethod -> personwantsorg.ESCALATE at line 58
  • HOCallMethod -> personwantsorg.@AbortMethod at line 75
  • HOCallMethod -> personwantsorg.@AbortMethod at line 91
  • HOCallMethod -> personwantsorg.MakeDecision at line 123
  • HOCallMethod -> personwantsorg.ESCALATE at line 123
  • HOCallMethod -> personwantsorg.@AbortMethod at line 123
  • HOCallMethod -> personwantsorg.ESCALATE at line 127
  • HOCallMethod -> personwantsorg.@AbortMethod at line 127
  • HOCallMethod -> personwantsorg.@AbortMethod at line 132
  • HOFireEvent -> PWOHelperPWO.Remind at line 165
  • Bulk DBQueue insert -> OrderProduct at line 22
  • Bulk DBQueue insert -> Zurücksetzen 3 at line 54
  • Bulk DBQueue insert -> Zurücksetzen 3 at line 58
  • Bulk DBQueue insert -> Zurücksetzen 3 at line 75
  • References QBM_PJobCreate*
  • References QBM_PJobCreate_HOCallMethod*
  • References QBM_PJobCreate_HOFireEvent*
  • References QBM_PDBQueueInsert_Bulk

Typed Edges

  • calls object method personwantsorg.ESCALATE HOCallMethod -> personwantsorg.ESCALATE at line 22
  • calls object method personwantsorg.MakeDecision HOCallMethod -> personwantsorg.MakeDecision at line 123
  • fires event PWOHelperPWO.Remind HOFireEvent -> PWOHelperPWO.Remind at line 165
  • queues DBQueue task OrderProduct at line 22 Bulk DBQueue insert -> OrderProduct at line 22
  • queues DBQueue task Zurücksetzen 3 at line 54 Bulk DBQueue insert -> Zurücksetzen 3 at line 54
  • queues DBQueue task Zurücksetzen 3 at line 58 Bulk DBQueue insert -> Zurücksetzen 3 at line 58
  • queues DBQueue task Zurücksetzen 3 at line 75 Bulk DBQueue insert -> Zurücksetzen 3 at line 75
  • references source dbo.QER_FTPWODecisionPossible source text reference
  • references source dbo.QBM_FCVIntToString source text reference
  • references source dbo.QBM_FCVStringToBit source text reference
  • references source dbo.QBM_FGIConfigparmValue source text reference
  • references source dbo.QBM_FGIJobCreatedExists source text reference
  • references source dbo.QBM_FGISessionContext source text reference
  • references source dbo.QER_FCVTimeToWorkTimePerson source text reference
  • references source dbo.QER_FGIGenProcIDForPWO source text reference
  • references source dbo.QER_FGIPWODecisionPossible source text reference
  • references source dbo.QER_FGIPWOStateFinalError source text reference
  • references source dbo.QBM_PDBQueueInsert_Bulk source text reference
  • references source dbo.QBM_PJobCreate source text reference
  • references source dbo.QBM_PJobCreate_HOCallMethod source text reference
  • references source dbo.QBM_PJobCreate_HOFireEvent source text reference
  • references source dbo.QBM_PJobCreate_HOFireEvent_L source text reference
  • references source dbo.QBM_PSessionContextSet source text reference
  • references source dbo.QBM_PSessionErrorAdd source text reference
  • references source dbo.QER_ZITShopCheck source text reference
  • queues DBQueue task OrderProduct -> unresolved procedure QBM_PDBQueueInsert_Bulk @Task36443, @DBQueueElements_36443 delete @DBQueueCurrent from @DBQueueCurrent cu join @DBQueueElements_36443 el on cu.UID_Parameter = el.Object end Declare @PWOOhneEntscheider QBM_YCursorBuffer insert into @PWOOhne…
  • queues DBQueue task Zurücksetzen 3 -> unresolved procedure QBM_PDBQueueInsert_Bulk @UID_Task, @DBQueueElements_spezial if @Debugswitch > 0 begin print 'Zurücksetzen 3' end select @ElementIndex += 1 end Declare @PWOZeit QBM_YCursorBuffer insert into @PWOZeit (UID1, UID2, ObjectKey1, Ident1) select …

Complete Source

SQL931 lines
1CREATE PROCEDURE QER_ZITShopCheckDecision(2  @SlotNumber int3)4AS5BEGIN6  DECLARE @SQLcmd nvarchar(1000)7  DECLARE @uid_personwantsorg varchar(38)8  DECLARE @GenProcID varchar(38)9  DECLARE @BasisObjectKey varchar(138)10  DECLARE @AbortMethod nvarchar(64)11  DECLARE @UID_PWOStateFinalError varchar(38) = NULL12  DECLARE @EscalateIfNoApprover BIT13  DECLARE @UID_PWOHelperPWO varchar(38)14  DECLARE @UID_PersonHead varchar(38)15  DECLARE @MinutesReminder int16  DECLARE @MailExists int17  DECLARE @ObjectkeyForMail varchar(138)18  DECLARE @ObjectkeySForMail QBM_YParameterList19  DECLARE @WhereclauseForMail nvarchar(1000)20  DECLARE @CurrentDecisionLevel int21  DECLARE @SubLevelNumberString varchar(16)22  DECLARE @UID_Task varchar(38)23  DECLARE @DBQueueElements_spezial QBM_YDBQueueRaw24  DECLARE @Dummystring nvarchar(100)25  DECLARE @MyName nvarchar(64) = object_name(@@procid)26  DECLARE @DecisionLevel int27  DECLARE @XUser nvarchar(64) = object_name(@@procid)28  DECLARE @Debugswitch int = 029  DECLARE @MaxDate2200 datetime = '2200-01-01'30  DECLARE @Mindate1899 datetime = '1899-12-30'31  DECLARE @GenProcID_R varchar(38) = dbo.QBM_FGISessionContext('')32  DECLARE @XUser_R nvarchar(64) = dbo.QBM_FGISessionContext('XUser')33  DECLARE @CfgUseGenProcID BIT = dbo.QBM_FCVStringToBit(dbo.QBM_FGIConfigparmValue('Common\ProcessState\UseGenProcIDFromPWO'))34  DECLARE @ElementLast int35  DECLARE @ElementCount int36  DECLARE @ElementIndex int37  DECLARE @DBQueueCurrent QBM_YDBQueueCurrent38  DECLARE @DaysToAbort QBM_YDBQueueCurrent39  DECLARE @Helper QER_YPWOHelperReminder40  BEGIN TRY41    INSERT INTO @DBQueueCurrent(UID_DialogDBQueue,42    UID_Parameter,43    UID_SubParameter,44    GenProcID)45    SELECT46      UID_DialogDBQueue,47      UID_Parameter,48      UID_SubParameter,49      GenProcID50    FROM QBMDBQueueCurrent cu51      WITH(readpast)52    WHERE53      cu.SlotNumber = @SlotNumber54    IF @@rowcount = 055    BEGIN56      GOTO EndLabel57    END58    DECLARE @DBQueueElements_36443 QBM_YDBQueueRaw59    DECLARE @Task36443 varchar(38) = 'QER-K-ITSHOPOrder-RESET'60    INSERT INTO @DBQueueElements_36443(Object,61    GenProcID)62    SELECT63      x.UID_PersonWantsOrg,64      x.GenProcID65    FROM(66    SELECT67      pwo.UID_PersonWantsOrg,68      pwo.OrderState,69      pwo.DecisionLevel,70      h.SubLevelNumber,71      sum(CASE h.Decision72      WHEN 'P' THEN73      174    ELSE 075    END) AS CountPositive,76    COUNT(*) AS CountDecider,77    max(ws.CountApprover) AS CountApprover,78    po.DecisionPossible,79    max(dbo.QER_FGIGenProcIDForPWO(pwo.GenProcID, cu.GenProcID, @CfgUseGenProcID)) AS GenProcID80    FROM @DBQueueCurrent cu81    JOIN PersonWantsOrg pwo82      WITH(readpast)83      ON cu.UID_Parameter = pwo.UID_PersonWantsOrg84    JOIN PWOHelperPWO h85      WITH(readpast)86      ON pwo.UID_PersonWantsOrg = h.UID_PersonWantsOrg AND pwo.DecisionLevel = h.LevelNumber87    JOIN QERWorkingStep ws88      ON ws.UID_QERWorkingMethod = pwo.UID_QERWorkingMethod AND ws.LevelNumber = pwo.DecisionLevel AND ws.SubLevelNumber = h.SubLevelNumber89    JOIN PWODecisionRule ru90      ON ws.UID_PWODecisionRule = ru.UID_PWODecisionRule AND ru.UID_Task IS NULL CROSS apply dbo.QER_FTPWODecisionPossible(pwo.UID_PersonWantsOrg,91    pwo.DecisionLevel, h.SubLevelNumber) po92    WHERE93      pwo.OrderState IN('OrderProduct', 'OrderProlongate', 'OrderUnsubscribe')94    GROUP BY pwo.UID_PersonWantsOrg,95    pwo.OrderState,96    pwo.DecisionLevel,97    h.SubLevelNumber,98    po.DecisionPossible) AS x99    WHERE100      x.CountApprover = -1 AND x.DecisionPossible = 0 AND x.CountPositive = x.CountDecider AND x.CountPositive > 0101    GROUP BY x.UID_PersonWantsOrg,102    x.GenProcID103    IF @@ROWCOUNT > 0104    BEGIN105      EXEC QBM_PDBQueueInsert_Bulk @Task36443,106        @DBQueueElements_36443107      DELETE @DBQueueCurrent108      FROM @DBQueueCurrent cu109      JOIN @DBQueueElements_36443 el110        ON cu.UID_Parameter = el.Object111    END112    DECLARE @PWOOhneEntscheider QBM_YCursorBuffer113    INSERT INTO @PWOOhneEntscheider(UID1,114    UID2,115    ObjectKey1,116    Ident1,117    Bit1,118    Int1)119    SELECT120      pwo.uid_personwantsorg,121      dbo.QER_FGIGenProcIDForPWO(pwo.GenProcID,122      p.GenProcID,123      @CfgUseGenProcID) AS GenProcID,124      pwo.XObjectKey,125    CASE pwo.Orderstate126      WHEN 'OrderProduct' THEN127    'Abort'128    ELSE 'AbortOrder'129    END,130    ws.EscalateIfNoApprover,131    pwo.DecisionLevel132    FROM @DBQueueCurrent p133    JOIN personwantsorg pwo134      WITH(readpast)135      ON p.uid_parameter = pwo.uid_personwantsorg136    JOIN QERWorkingStep ws137      ON pwo.UID_QERWorkingMethod = ws.UID_QERWorkingMethod AND pwo.DecisionLevel = ws.LevelNumber138    WHERE139      NOT EXISTS(140    SELECT TOP 1 1141    FROM PWOHelperPWO ph142      WITH(readpast)143    WHERE144      pwo.uid_personwantsorg = ph.uid_personwantsorg AND ws.LevelNumber = ph.LevelNumber AND ws.SubLevelNumber = ph.SubLevelNumber AND(ws.UID_PWODecisionRule145    = ph.UID_PWODecisionRule OR ph.UID_PWODecisionRule = 'QER-PWODecisionRule-QP') AND ph.RulerLevel IN(0,146    1)) AND pwo.OrderState IN('OrderProduct',147    'OrderProlongate',148    'OrderUnsubscribe')149    UNION150    SELECT151      pwo.uid_personwantsorg,152      dbo.QER_FGIGenProcIDForPWO(pwo.GenProcID,153      p.GenProcID,154      @CfgUseGenProcID) AS GenProcID,155      pwo.XObjectKey,156    CASE pwo.Orderstate157      WHEN 'OrderProduct' THEN158    'Abort'159    ELSE 'AbortOrder'160    END,161    0,162    pwo.DecisionLevel163    FROM @DBQueueCurrent p164    JOIN personwantsorg pwo165      WITH(readpast)166      ON p.uid_parameter = pwo.uid_personwantsorg167    WHERE168      NOT EXISTS(169    SELECT TOP 1 1170    FROM QERWorkingStep ws171    WHERE172      pwo.UID_QERWorkingMethod = ws.UID_QERWorkingMethod) AND pwo.UID_QERWorkingMethod > ' ' AND pwo.OrderState = 'OrderProduct'173    SELECT @ElementCount = @@ROWCOUNT174    SELECT @ElementIndex = @@IDENTITY - @ElementCount +1175    SELECT @ElementLast = @@IDENTITY176    WHILE @ElementIndex <= @ElementLast177    BEGIN178      SELECT179        TOP 1 @uid_personwantsorg = bu.UID1,180        @GenProcID = bu.UID2,181        @BasisObjectKey = bu.ObjectKey1,182        @AbortMethod = bu.Ident1,183        @EscalateIfNoApprover = bu.Bit1,184        @DecisionLevel = bu.Int1185      FROM @PWOOhneEntscheider bu186      WHERE187        bu.ElementIndex = @ElementIndex188      IF @EscalateIfNoApprover = 0189      BEGIN190        SELECT @SQLcmd = N 'uid_personwantsorg = ''' + rtrim(@uid_personwantsorg) + N ''''191        SELECT @UID_PWOStateFinalError = dbo.QER_FGIPWOStateFinalError(@UID_PersonWantsOrg)192        EXEC QBM_PJobCreate_HOCallMethod 'personwantsorg',193          @SQLcmd,194          @save = 1,195          @Methodname = @AbortMethod,196          @GenProcID = @GenProcID,197          @ObjectKeysAffected = DEFAULT,198          @Param1 = '#LDS#Automatic system approval: No approver available (in this shop).|',199          @Param2 = @UID_PWOStateFinalError,200          @Retries = 3,201          @checkForExisting = 1,202          @WhereClauseAdditional = ' OrderState in(''OrderProduct'', ''OrderProlongate'', ''OrderUnsubscribe'')',203          @BasisObjectKey = @BasisObjectKey204      END205      ELSE206      BEGIN207        SELECT208          @SQLcmd = N 'uid_personwantsorg = ''' + rtrim(@uid_personwantsorg) + N ''' and DecisionLevel = ' + STR(@DecisionLevel)209        EXEC QBM_PJobCreate_HOCallMethod 'personwantsorg',210          @SQLcmd,211          @save = 1,212          @Methodname = 'ESCALATE',213          @GenProcID = @GenProcID,214          @ObjectKeysAffected = DEFAULT,215          @Param1 = 'sa',216          @Param2 = '#LDS#Automatic system approval: Decision "escalate" due to no approver available.|',217          @Retries = 3,218          @checkForExisting = 1,219          @WhereClauseAdditional = ' OrderState in(''OrderProduct'', ''OrderProlongate'', ''OrderUnsubscribe'')',220          @BasisObjectKey = @BasisObjectKey,221          @isToFreezeOnError = 1222      END223      DELETE @DBQueueCurrent224      FROM @DBQueueCurrent cu225      WHERE226        cu.UID_Parameter = @uid_personwantsorg227      IF @Debugswitch > 0228      BEGIN229        print 'Zurücksetzen 1'230      END231      SELECT @ElementIndex += 1232    END233    DECLARE @PWOZuWenigEntscheider QBM_YCursorBuffer234    INSERT INTO @PWOZuWenigEntscheider(UID1,235    UID2,236    ObjectKey1,237    Ident1,238    Bit1,239    Int1)240    SELECT241      DISTINCT pwo.uid_personwantsorg,242      dbo.QER_FGIGenProcIDForPWO(pwo.GenProcID,243      p.GenProcID,244      @CfgUseGenProcID) AS GenProcID,245      pwo.XObjectKey,246    CASE pwo.Orderstate247      WHEN 'OrderProduct' THEN248    'Abort'249    ELSE 'AbortOrder'250    END,251    ws.EscalateIfNoApprover,252    pwo.DecisionLevel253    FROM @DBQueueCurrent p254    JOIN personwantsorg pwo255      WITH(readpast)256      ON p.uid_parameter = pwo.uid_personwantsorg257    JOIN QERWorkingStep ws258      ON pwo.UID_QERWorkingMethod = ws.UID_QERWorkingMethod AND pwo.decisionlevel = ws.levelnumber CROSS apply dbo.QER_FTPWODecisionPossible(pwo.uid_personwantsorg259    ,260    ws.LevelNumber,261    ws.SubLevelNumber) dp262    WHERE263      dp.DecisionPossible = -1 AND pwo.OrderState IN('OrderProduct',264    'OrderProlongate',265    'OrderUnsubscribe')266    SELECT @ElementCount = @@ROWCOUNT267    SELECT @ElementIndex = @@IDENTITY - @ElementCount +1268    SELECT @ElementLast = @@IDENTITY269    WHILE @ElementIndex <= @ElementLast270    BEGIN271      SELECT272        TOP 1 @uid_personwantsorg = bu.UID1,273        @GenProcID = bu.UID2,274        @BasisObjectKey = bu.ObjectKey1,275        @AbortMethod = bu.Ident1,276        @EscalateIfNoApprover = bu.Bit1,277        @DecisionLevel = bu.Int1278      FROM @PWOZuWenigEntscheider bu279      WHERE280        bu.ElementIndex = @ElementIndex281      IF @EscalateIfNoApprover = 0282      BEGIN283        SELECT @SQLcmd = N 'uid_personwantsorg = ''' + rtrim(@uid_personwantsorg) + N ''''284        SELECT @UID_PWOStateFinalError = dbo.QER_FGIPWOStateFinalError(@UID_PersonWantsOrg)285        EXEC QBM_PJobCreate_HOCallMethod 'personwantsorg',286          @SQLcmd,287          @save = 1,288          @Methodname = @AbortMethod,289          @GenProcID = @GenProcID,290          @ObjectKeysAffected = DEFAULT,291          @Param1 = '#LDS#Automatic system approval: Not enough approvers available.|',292          @Param2 = @UID_PWOStateFinalError,293          @Retries = 3,294          @checkForExisting = 1,295          @WhereClauseAdditional = ' OrderState in(''OrderProduct'', ''OrderProlongate'', ''OrderUnsubscribe'')',296          @BasisObjectKey = @BasisObjectKey297      END298      ELSE299      BEGIN300        SELECT301          @SQLcmd = N 'uid_personwantsorg = ''' + rtrim(@uid_personwantsorg) + N ''' and DecisionLevel = ' + STR(@DecisionLevel)302        EXEC QBM_PJobCreate_HOCallMethod 'personwantsorg',303          @SQLcmd,304          @save = 1,305          @Methodname = 'ESCALATE',306          @GenProcID = @GenProcID,307          @ObjectKeysAffected = DEFAULT,308          @Param1 = 'sa',309          @Param2 = '#LDS#Automatic system approval: Decision "escalate" due to not enough approvers available.|',310          @Retries = 3,311          @checkForExisting = 1,312          @WhereClauseAdditional = ' OrderState in(''OrderProduct'', ''OrderProlongate'', ''OrderUnsubscribe'')',313          @BasisObjectKey = @BasisObjectKey,314          @isToFreezeOnError = 1315      END316      DELETE @DBQueueCurrent317      FROM @DBQueueCurrent cu318      WHERE319        cu.UID_Parameter = @uid_personwantsorg320      IF @Debugswitch > 0321      BEGIN322        print 'Zurücksetzen 2'323      END324      SELECT @ElementIndex += 1325    END326    INSERT INTO @DaysToAbort(UID_DialogDBQueue,327    UID_Parameter,328    UID_SubParameter,329    GenProcID)330    SELECT331      UID_DialogDBQueue,332      UID_Parameter,333      UID_SubParameter,334      GenProcID335    FROM @DBQueueCurrent336    DECLARE @PWOPositiv QBM_YCursorBuffer337    INSERT INTO @PWOPositiv(UID1)338    SELECT339      DISTINCT dr.UID_Task340    FROM @DBQueueCurrent p341    JOIN personwantsorg pwo342      WITH(readpast)343      ON p.uid_parameter = pwo.uid_personwantsorg344    JOIN PWOHelperPWO ph345      WITH(readpast)346      ON pwo.uid_personwantsorg = ph.uid_personwantsorg AND pwo.decisionlevel = ph.levelnumber347    JOIN pwodecisionrule dr348      ON ph.UID_PWODecisionRule = dr.UID_PWODecisionRule349    WHERE350      dr.UID_Task > ' ' AND OrderState IN('OrderProduct',351    'OrderProlongate',352    'OrderUnsubscribe')353    SELECT @ElementCount = @@ROWCOUNT354    SELECT @ElementIndex = @@IDENTITY - @ElementCount +1355    SELECT @ElementLast = @@IDENTITY356    WHILE @ElementIndex <= @ElementLast357    BEGIN358      SELECT TOP 1 @UID_Task = bu.UID1359      FROM @PWOPositiv bu360      WHERE361        bu.ElementIndex = @ElementIndex362      DELETE @DBQueueElements_spezial363      INSERT INTO @DBQueueElements_spezial(object,364      subobject,365      genprocid)366      SELECT367        x.uid,368        NULL,369        x.GenProcID370      FROM(371      SELECT372        pwo.uid_personwantsorg AS uid,373        dbo.QER_FGIGenProcIDForPWO(pwo.GenProcID, p.GenProcID, @CfgUseGenProcID) AS GenProcID374      FROM @DBQueueCurrent p375      JOIN personwantsorg pwo376        WITH(readpast)377        ON p.uid_parameter = pwo.uid_personwantsorg378      JOIN PWOHelperPWO ph379        WITH(readpast)380        ON pwo.uid_personwantsorg = ph.uid_personwantsorg AND pwo.decisionlevel = ph.levelnumber381      JOIN pwodecisionrule dr382        ON ph.UID_PWODecisionRule = dr.UID_PWODecisionRule AND OrderState IN('OrderProduct', 'OrderProlongate',383      'OrderUnsubscribe') AND dr.UID_Task = @UID_Task) AS x384      DELETE @DBQueueCurrent385      FROM @DBQueueCurrent cu386      WHERE387        cu.UID_Parameter IN(388      SELECT object389      FROM @DBQueueElements_spezial)390      DELETE @DBQueueElements_spezial391      FROM @DBQueueElements_spezial e392      JOIN PersonWantsOrg pwo393        WITH(readpast)394        ON e.Object = pwo.UID_PersonWantsOrg395      WHERE396        @UID_Task = 'QER-K-ShoppingRackMakeDecisionEX' AND(pwo.DecisionLevel > 0 OR(pwo.DecisionLevel = 0 AND dbo.QBM_FGIConfigparmValue('QER\ITShop\DecisionOnInsert'397      ) > ' '))398      EXEC QBM_PDBQueueInsert_Bulk @UID_Task,399        @DBQueueElements_spezial400      IF @Debugswitch > 0401      BEGIN402        print 'Zurücksetzen 3'403      END404      SELECT @ElementIndex += 1405    END406    DECLARE @PWOZeit QBM_YCursorBuffer407    INSERT INTO @PWOZeit(UID1,408    UID2,409    ObjectKey1,410    Ident1)411    SELECT412      DISTINCT p.uid_parameter,413      dbo.QER_FGIGenProcIDForPWO(pwo.GenProcID,414      p.GenProcID,415      @CfgUseGenProcID) AS GenProcID,416      pwo.XObjectKey,417    CASE pwo.Orderstate418      WHEN 'OrderProduct' THEN419    'Abort'420    ELSE 'AbortOrder'421    END422    FROM personwantsorg pwo423      WITH(readpast)424    JOIN @DaysToAbort p425      ON pwo.uid_personwantsorg = p.uid_parameter426    JOIN PWOHelperPWO h427      WITH(readpast)428      ON pwo.uid_personwantsorg = h.uid_personwantsorg429    JOIN QERWorkingMethod wm430      ON pwo.UID_QERWorkingMethod = wm.UID_QERWorkingMethod431    LEFT432    OUTER433    JOIN(434    SELECT435      h1.UID_PersonWantsOrg,436      MAX(h1.XDateInserted) AS OrderDate437    FROM @DaysToAbort p1438    JOIN PWODecisionHistory h1439      ON p1.UID_Parameter = h1.UID_PersonWantsOrg440    WHERE441      h1.DecisionType = 'Prolongate' AND h1.OrderState = 'OrderProlongate'442    GROUP BY h1.UID_PersonWantsOrg) AS hu443      ON pwo.uid_PersonwantsOrg = hu.uid_PersonwantsOrg444    LEFT445    OUTER446    JOIN(447    SELECT448      h1.UID_PersonWantsOrg,449      MAX(h1.XDateInserted) AS OrderDate450    FROM @DaysToAbort p1451    JOIN PWODecisionHistory h1452      ON p1.UID_Parameter = h1.UID_PersonWantsOrg453    WHERE454      h1.DecisionType = 'Unsubscribe' AND h1.OrderState = 'OrderUnsubscribe'455    GROUP BY h1.UID_PersonWantsOrg) AS un456      ON pwo.uid_PersonwantsOrg = un.uid_PersonwantsOrg457    WHERE458      dateadd(dd,459    wm.DaysToAbort,460    CASE pwo.Orderstate461      WHEN 'OrderProduct' THEN462    pwo.OrderDate463      WHEN 'OrderProlongate' THEN464    isnull(hu.OrderDate, @Mindate1899)465      WHEN 'OrderUnsubscribe' THEN466    isnull(un.OrderDate, @Mindate1899)467    ELSE pwo.Orderdate468    END) < getutcdate() AND isnull(wm.DaysToAbort,469    0) > 0 AND pwo.OrderState IN('OrderProduct',470    'OrderProlongate',471    'OrderUnsubscribe') AND NOT EXISTS(472    SELECT TOP 1 1473    FROM JobQueue q474    JOIN QBMElementAffectedByJob ebj475      ON q.UID_Job = ebj.UID_Job476    WHERE477      q.ComponentAssembly = 'HandleObjectComponent' AND q.TaskName = 'CallMethod' AND ebj.ObjectKeyAffected = pwo.XObjectKey AND q.Ready2EXE LIKE478    '[^DH][^I] % ')479    SELECT @ElementCount = @@ROWCOUNT480    SELECT @ElementIndex = @@IDENTITY - @ElementCount +1481    SELECT @ElementLast = @@IDENTITY482    WHILE @ElementIndex <= @ElementLast483    BEGIN484      SELECT485        TOP 1 @uid_personwantsorg = bu.UID1,486        @GenProcID = bu.UID2,487        @BasisObjectKey = bu.ObjectKey1,488        @AbortMethod = bu.Ident1489      FROM @PWOZeit bu490      WHERE491        bu.ElementIndex = @ElementIndex492      SELECT @SQLcmd = N 'uid_personwantsorg = ''' + rtrim(@uid_personwantsorg) + N ''''493      SELECT @UID_PWOStateFinalError = dbo.QER_FGIPWOStateFinalError(@UID_PersonWantsOrg)494      EXEC QBM_PJobCreate_HOCallMethod 'personwantsorg',495        @SQLcmd,496        @save = 1,497        @Methodname = @AbortMethod,498        @GenProcID = @GenProcID,499        @ObjectKeysAffected = DEFAULT,500        @Param1 = '#LDS#Automatic system approval: Number of days has been exceeded, as specified in decision method.|',501        @Param2 = @UID_PWOStateFinalError,502        @Retries = 3,503        @checkForExisting = 1,504        @WhereClauseAdditional = ' OrderState in(''OrderProduct'', ''OrderProlongate'', ''OrderUnsubscribe'')',505        @BasisObjectKey = @BasisObjectKey506      DELETE @DBQueueCurrent507      FROM @DBQueueCurrent cu508      WHERE509        cu.UID_Parameter = @uid_personwantsorg510      IF @Debugswitch > 0511      BEGIN512        print 'Zurücksetzen 4'513      END514      SELECT @ElementIndex += 1515    END516    SELECT @GenProcID = NULL517    SELECT TOP 1 @GenProcID = GenProcID518    FROM @DBQueueCurrent p519    IF @GenProcID IS NULL520    BEGIN521      IF @Debugswitch > 0522      BEGIN523        print 'ausstieg 4'524      END525      GOTO EndLabel526    END527    EXEC QBM_PSessionContextSet 'GenProcID',528      @GenProcID529    EXEC QBM_PSessionContextSet 'XUser',530      @XUser531    INSERT INTO @Helper(UID_HelperKey,532    NextReminder,533    NextAutomaticDecision,534    UID_ElementKey,535    UID_PersonHead,536    UID_QERWorkingStep,537    Decision,538    LevelNumber,539    UID_PWODecisionRule,540    XObjectKey,541    RulerLevel)542    SELECT543      h.UID_PWOHelperPWO,544      h.NextReminder,545      h.NextAutomaticDecision,546      h.UID_PersonWantsOrg,547      h.UID_PersonHead,548      h.UID_QERWorkingStep,549      h.Decision,550      h.LevelNumber,551      h.UID_PWODecisionRule,552      h.XObjectKey,553      h.RulerLevel554    FROM @DBQueueCurrent cu555    JOIN PWOHelperPWO h556      WITH(readpast)557      ON cu.UID_Parameter = h.UID_PersonWantsOrg558    UPDATE @Helper559    SET NextAutomaticDecision = dbo.QER_FCVTimeToWorkTimePerson(getutcdate(),560    ws.MinutesAutomaticDecision,561    h.UID_PersonHead),562    IsToUpdateNextAutomaticDec = 1563    FROM @Helper h564    JOIN @DBQueueCurrent p565      ON h.UID_ElementKey = p.UID_Parameter566    JOIN QERWorkingStep ws567      ON h.uid_QERWorkingStep = ws.UID_QERWorkingStep568    JOIN PersonWantsOrg pwo569      WITH(readpast)570      ON h.UID_ElementKey = pwo.UID_PersonWantsOrg571    JOIN PWODecisionRule r572      ON ws.UID_PWODecisionRule = r.UID_PWODecisionRule573    WHERE574      ws.MinutesAutomaticDecision > 0 AND h.NextAutomaticDecision = @MaxDate2200 AND isnull(h.Decision,575    '') = '' AND r.UID_Task IS NULL AND h.levelnumber = pwo.DecisionLevel576    SELECT TOP 1 @GenProcID = GenProcID577    FROM @DBQueueCurrent p578    EXEC QBM_PSessionContextSet 'GenProcID',579      @GenProcID580    EXEC QBM_PSessionContextSet 'XUser',581      @XUser582    UPDATE @Helper583    SET NextAutomaticDecision = @MaxDate2200,584    IsToUpdateNextAutomaticDec = 1585    FROM @Helper h586    JOIN @DBQueueCurrent p587      ON h.UID_ElementKey = p.UID_Parameter588    JOIN QERWorkingStep ws589      ON h.uid_QERWorkingStep = ws.UID_QERWorkingStep590    JOIN PersonWantsOrg pwo591      WITH(readpast)592      ON h.UID_ElementKey = pwo.UID_PersonWantsOrg593    JOIN PWODecisionRule r594      ON ws.UID_PWODecisionRule = r.UID_PWODecisionRule595    WHERE596      h.NextAutomaticDecision < @MaxDate2200 AND(ws.MinutesAutomaticDecision = 0 OR isnull(h.Decision,597    '') > '' OR h.levelnumber <> pwo.DecisionLevel OR r.UID_Task > ' ')598    DECLARE @PWOAutomatic QBM_YCursorBuffer599    INSERT INTO @PWOAutomatic(UID1,600    UID2,601    ObjectKey1,602    Ident1,603    Int1,604    Ident2)605    SELECT606      DISTINCT p.UID_Parameter,607      dbo.QER_FGIGenProcIDForPWO(pwo.GenProcID,608      p.GenProcID,609      @CfgUseGenProcID) AS GenProcID,610      pwo.XObjectKey,611      ws.AutomaticDecision,612      pwo.DecisionLevel,613      min(dbo.QBM_FCVIntToString(hp.SubLevelNumber))614    FROM @DBQueueCurrent p615    JOIN(616    SELECT617      h.UID_ElementKey AS uid_personwantsorg,618      h.uid_QERWorkingStep619    FROM @Helper h620    JOIN @DBQueueCurrent p621      ON h.UID_ElementKey = p.uid_parameter622    JOIN PersonWantsOrg pwo623      WITH(readpast)624      ON h.UID_ElementKey = pwo.UID_PersonWantsOrg AND h.levelnumber = pwo.DecisionLevel625    JOIN QERWorkingStep ws626      ON ws.UID_QERWorkingStep = h.UID_QERWorkingStep627    WHERE628      h.NextAutomaticDecision < @MaxDate2200 AND h.RulerLevel <> 2629    GROUP BY h.UID_ElementKey,630    h.uid_QERWorkingStep631    HAVING max(NextAutomaticDecision) < getutcdate()) AS x632      ON p.uid_parameter = x.uid_personwantsorg633    JOIN PersonWantsOrg pwo634      ON p.UID_Parameter = pwo.UID_PersonWantsOrg AND pwo.OrderState IN('OrderProduct',635    'OrderProlongate',636    'OrderUnsubscribe')637    JOIN QERWorkingStep ws638      ON ws.uid_QERWorkingStep = x.uid_QERWorkingStep639    JOIN PWOHelperPWO hp640      ON hp.UID_PersonWantsOrg = pwo.UID_PersonWantsOrg AND hp.UID_QERWorkingStep = ws.UID_QERWorkingStep641    WHERE642      dbo.QBM_FGIJobCreatedExists(pwo.XObjectKey) = 0 AND dbo.QER_FGIPWODecisionPossible(pwo.UID_PersonWantsOrg,643    hp.LevelNumber,644    hp.SubLevelNumber) = 1645    GROUP BY p.UID_Parameter,646    dbo.QER_FGIGenProcIDForPWO(pwo.GenProcID,647    p.GenProcID,648    @CfgUseGenProcID),649    pwo.XObjectKey,650    ws.AutomaticDecision,651    pwo.DecisionLevel652    SELECT @ElementCount = @@ROWCOUNT653    SELECT @ElementIndex = @@IDENTITY - @ElementCount +1654    SELECT @ElementLast = @@IDENTITY655    WHILE @ElementIndex <= @ElementLast656    BEGIN657      SELECT658        TOP 1 @uid_personwantsorg = bu.UID1,659        @GenProcID = bu.UID2,660        @BasisObjectKey = bu.ObjectKey1,661        @AbortMethod = bu.Ident1,662        @DecisionLevel = bu.Int1,663        @SubLevelNumberString = bu.Ident2664      FROM @PWOAutomatic bu665      WHERE666        bu.ElementIndex = @ElementIndex667      SELECT668        @SQLcmd = N 'uid_personwantsorg = ''' + rtrim(@uid_personwantsorg) + N ''' and DecisionLevel = ' + STR(@DecisionLevel)669      SELECT @UID_PWOStateFinalError = dbo.QER_FGIPWOStateFinalError(@UID_PersonWantsOrg)670      IF @AbortMethod IN('TRUE',671      'FALSE')672      BEGIN673        EXEC QBM_PJobCreate_HOCallMethod 'personwantsorg',674          @SQLcmd,675          @save = 1,676          @Methodname = 'MakeDecision',677          @ObjectKeysAffected = DEFAULT,678          @GenProcID = @GenProcID,679          @Param1 = 'sa',680          @Param2 = @AbortMethod,681          @Param3 = '#LDS#Automatic system approval: Decision due to timeout.|',682          @Param5 = @SubLevelNumberString,683          @Retries = 3,684          @checkForExisting = 1,685          @WhereClauseAdditional = ' OrderState in(''OrderProduct'', ''OrderProlongate'', ''OrderUnsubscribe'')',686          @BasisObjectKey = @BasisObjectKey,687          @isToFreezeOnError = 1688      END689      IF @AbortMethod IN('ESCALATE') AND NOT EXISTS(690        SELECT TOP 1 1691        FROM @PWOAutomatic bu692        WHERE693          bu.ElementIndex < @ElementIndex AND bu.UID1 = @uid_personwantsorg)694      BEGIN695        EXEC QBM_PJobCreate_HOCallMethod 'personwantsorg',696          @SQLcmd,697          @save = 1,698          @Methodname = 'ESCALATE',699          @GenProcID = @GenProcID,700          @ObjectKeysAffected = DEFAULT,701          @Param1 = 'sa',702          @Param2 = '#LDS#Automatic system approval: Decision "escalate" due to timeout.|',703          @Retries = 3,704          @checkForExisting = 1,705          @WhereClauseAdditional = ' OrderState in(''OrderProduct'', ''OrderProlongate'', ''OrderUnsubscribe'')',706          @BasisObjectKey = @BasisObjectKey,707          @isToFreezeOnError = 1708      END709      IF @AbortMethod IN('Abort') AND NOT EXISTS(710        SELECT TOP 1 1711        FROM @PWOAutomatic bu712        WHERE713          bu.ElementIndex < @ElementIndex AND bu.UID1 = @uid_personwantsorg)714      BEGIN715        IF NOT EXISTS(716          SELECT TOP 1 1717          FROM personwantsorg718          WITH(readpast)719        WHERE720          uid_personwantsorg = @uid_personwantsorg AND orderstate = 'OrderProduct')721        BEGIN722          SELECT @AbortMethod = 'AbortOrder'723        END724        EXEC QBM_PJobCreate_HOCallMethod 'personwantsorg',725          @SQLcmd,726          @save = 1,727          @Methodname = @AbortMethod,728          @GenProcID = @GenProcID,729          @ObjectKeysAffected = DEFAULT,730          @Param1 = '#LDS#Automatic system approval: "Abort" due to timeout.|',731          @Param2 = @UID_PWOStateFinalError,732          @Retries = 3,733          @checkForExisting = 1,734          @WhereClauseAdditional = ' OrderState in (''Assigned'', ''Granted'', ''New'', ''OrderProduct'', ''OrderProlongate'', ''OrderUnsubscribe'', ''Waiting'')'735        ,736        @BasisObjectKey = @BasisObjectKey,737        @isToFreezeOnError = 1738      END739      DELETE @DBQueueCurrent740      FROM @DBQueueCurrent cu741      WHERE742        cu.UID_Parameter = @uid_personwantsorg743      IF @Debugswitch > 0744      BEGIN745        print 'Zurücksetzen 5'746      END747      SELECT @ElementIndex += 1748    END749    SELECT @GenProcID = NULL750    SELECT TOP 1 @GenProcID = GenProcID751    FROM @DBQueueCurrent p752    IF @GenProcID IS NULL753    BEGIN754      IF @Debugswitch > 0755      BEGIN756        print 'ausstieg 5'757      END758      GOTO EndLabel759    END760    EXEC QBM_PSessionContextSet 'GenProcID',761      @GenProcID762    EXEC QBM_PSessionContextSet 'XUser',763      @XUser764    UPDATE @Helper765    SET NextReminder = dbo.QER_FCVTimeToWorkTimePerson(getutcdate(),766    ws.MinutesReminder,767    h.UID_PersonHead),768    IsToUpdateNextReminder = 1769    FROM @Helper h770    JOIN @DBQueueCurrent p771      ON h.UID_ElementKey = p.UID_Parameter772    JOIN QERWorkingStep ws773      ON h.uid_QERWorkingStep = ws.uid_QERWorkingStep774    JOIN PersonWantsOrg pwo775      WITH(readpast)776      ON h.UID_ElementKey = pwo.UID_PersonWantsOrg777    JOIN PWODecisionRule r778      ON h.UID_PWODecisionRule = r.UID_PWODecisionRule779    WHERE780      ws.MinutesReminder > 0 AND isnull(h.NextReminder,781    @MaxDate2200) = @MaxDate2200 AND isnull(h.Decision,782    '') IN('',783    'Q') AND r.UID_Task IS NULL AND h.levelnumber = pwo.DecisionLevel784    UPDATE @Helper785    SET NextReminder = @MaxDate2200,786    IsToUpdateNextReminder = 1787    FROM @Helper h788    JOIN @DBQueueCurrent p789      ON h.UID_ElementKey = p.UID_Parameter790    JOIN QERWorkingStep ws791      ON h.uid_QERWorkingStep = ws.UID_QERWorkingStep792    JOIN PersonWantsOrg pwo793      WITH(readpast)794      ON h.UID_ElementKey = pwo.UID_PersonWantsOrg795    JOIN pwodecisionrule r796      ON h.UID_PWODecisionRule = r.UID_PWODecisionRule797    WHERE798      h.NextReminder < @MaxDate2200 AND(ws.MinutesReminder = 0 OR isnull(h.Decision, '') NOT IN('', 'Q') OR h.levelnumber <> pwo.DecisionLevel OR799    r.UID_Task > ' ')800    UPDATE @Helper801    SET NextReminder = @MaxDate2200,802    IsToUpdateNextReminder = 1803    FROM @Helper h804    JOIN @DBQueueCurrent p805      ON h.UID_ElementKey = p.UID_Parameter806    JOIN PersonWantsOrg pwo807      WITH(readpast)808      ON h.UID_ElementKey = pwo.UID_PersonWantsOrg809    WHERE810      h.NextReminder < @MaxDate2200 AND isnull(h.Decision,811    '') = '' AND h.levelnumber = pwo.DecisionLevel AND EXISTS(812    SELECT TOP 1 1813    FROM @Helper hq814    WHERE815      hq.UID_ElementKey = h.UID_ElementKey AND hq.Decision = 'Q' AND hq.LevelNumber = h.LevelNumber)816    DECLARE @PWOSenden QBM_YCursorBuffer817    INSERT INTO @PWOSenden(UID1,818    UID2,819    UID3,820    Int1,821    Bit1,822    ObjectKey1,823    Int2,824    UID4)825    SELECT826      h.UID_HelperKey AS UID_PWOHelperPWO,827      dbo.QER_FGIGenProcIDForPWO(pwo.GenProcID,828      p.GenProcID,829      @CfgUseGenProcID) AS GenProcID,830      pe.UID_Person,831      ws.MinutesReminder,832      sign(len(isnull(ws.UID_DialogRichMailReminder, ''))),833      h.XObjectKey,834      pwo.DecisionLevel,835      pwo.UID_PersonWantsOrg836    FROM @Helper h837    JOIN @DBQueueCurrent p838      ON h.UID_ElementKey = p.UID_Parameter839    JOIN PersonWantsOrg pwo840      WITH(readpast)841      ON h.UID_ElementKey = pwo.UID_PersonWantsOrg AND h.levelnumber = pwo.DecisionLevel842    JOIN Person pe843      WITH(readpast)844      ON pe.UID_Person = h.UID_PersonHead845    JOIN QERWorkingStep ws846      ON h.uid_QERWorkingStep = ws.uid_QERWorkingStep847    WHERE848      h.NextReminder < getutcdate() AND dbo.QBM_FGIJobCreatedExists(h.XObjectKey) = 0 AND h.RulerLevel < 2849    SELECT @ElementCount = @@ROWCOUNT850    SELECT @ElementIndex = @@IDENTITY - @ElementCount +1851    SELECT @ElementLast = @@IDENTITY852    WHILE @ElementIndex <= @ElementLast853    BEGIN854      SELECT855        TOP 1 @UID_PWOHelperPWO = bu.UID1,856        @GenProcID = bu.UID2,857        @UID_PersonHead = bu.UID3,858        @MinutesReminder = bu.Int1,859        @MailExists = bu.Bit1,860        @ObjectkeyForMail = bu.ObjectKey1,861        @CurrentDecisionLevel = bu.Int2,862        @uid_Personwantsorg = bu.UID4863      FROM @PWOSenden bu864      WHERE865        bu.ElementIndex = @ElementIndex866      EXEC QBM_PSessionContextSet 'GenProcID',867        @GenProcID868      EXEC QBM_PSessionContextSet 'XUser',869        @XUser870      UPDATE @Helper871      SET NextReminder = dbo.QER_FCVTimeToWorkTimePerson(getutcdate(),872      @MinutesReminder,873      @UID_PersonHead),874      IsToUpdateNextReminder = 1875      WHERE876        UID_HelperKey = @UID_PWOHelperPWO877      IF @MailExists > 0878      BEGIN879        DELETE @ObjectkeySForMail880        INSERT INTO @ObjectkeySForMail(Parameter1)881        SELECT @ObjectkeyForMail882        SELECT883          @WhereclauseForMail = ' exists(select top 1 1 884												from personwantsorg pwo 885												where pwo.uid_personwantsorg  = ''' + @uid_Personwantsorg886          + ''' 887												and pwo.decisionlevel = ' + str(@CurrentDecisionLevel) + ' 888												)'889        EXEC QBM_PJobCreate_HOFireEvent_L 'PWOHelperPWO',890          @ObjectkeySForMail,891        'Remind',892          @GenProcID,893          @priority = 10,894          @BasisObjectKey = @ObjectkeyForMail,895          @CheckForExisting = 1,896          @whereclauseAdditional = @WhereclauseForMail,897          @AdditionalObjectKeysAffected = DEFAULT898      END899      SELECT @ElementIndex += 1900    END901    UPDATE PWOHelperPWO902    SET NextReminder = CASE h.IsToUpdateNextReminder903    WHEN 1 THEN904    h.NextReminder905    ELSE t.NextReminder906    END,907    NextAutomaticDecision = CASE h.IsToUpdateNextAutomaticDec908    WHEN 1 THEN909    h.NextAutomaticDecision910    ELSE t.NextAutomaticDecision911    END912    FROM PWOHelperPWO t913    JOIN @Helper h914      ON t.UID_PWOHelperPWO = h.UID_HelperKey915    WHERE916      h.IsToUpdateNextReminder = 1 OR h.IsToUpdateNextAutomaticDec = 1917  END TRY918  BEGIN CATCH919    EXEC QBM_PSessionErrorAdd DEFAULT920    RAISERROR('',921    18,922    1)923      WITH NOWAIT924  END CATCH925  EndLabel:926  EXEC QBM_PSessionContextSet 'GenProcID',927    @GenProcID_R928  EXEC QBM_PSessionContextSet 'XUser',929    @XUser_R930  RETURN931END
Open raw exported source
SQL · Raw172 lines
1      create   procedure QER_ZITShopCheckDecision (@SlotNumber int) as begin  declare @SQLcmd nvarchar(1000) declare @uid_personwantsorg varchar2(38) declare @GenProcID varchar(38) declare @BasisObjectKey varchar(138)  declare @AbortMethod nvarchar(64) declare @UID_PWOStateFinalError varchar(38)3 = null declare @EscalateIfNoApprover bit declare @UID_PWOHelperPWO varchar(38) declare @UID_PersonHead varchar(38) declare @MinutesReminder int declare4 @MailExists int declare @ObjectkeyForMail varchar(138) declare @ObjectkeySForMail QBM_YParameterList  declare @WhereclauseForMail nvarchar(1000) declare5 @CurrentDecisionLevel int declare @SubLevelNumberString varchar(16) declare @UID_Task varchar(38) declare @DBQueueElements_spezial QBM_YDBQueueRaw declare6 @Dummystring nvarchar(100) declare @MyName nvarchar(64) = object_name(@@procid) declare @DecisionLevel int declare @XUser nvarchar(64) = object_name(@@procid7) declare @Debugswitch int = 0 declare @MaxDate2200 datetime = '2200-01-01' declare @Mindate1899 datetime = '1899-12-30' declare @GenProcID_R varchar(388) = dbo.QBM_FGISessionContext('') declare @XUser_R nvarchar(64) = dbo.QBM_FGISessionContext('XUser') declare @CfgUseGenProcID bit = dbo.QBM_FCVStringToBit9(dbo.QBM_FGIConfigparmValue('Common\ProcessState\UseGenProcIDFromPWO')) declare @ElementLast int declare @ElementCount int declare @ElementIndex int declare10 @DBQueueCurrent QBM_YDBQueueCurrent declare @DaysToAbort QBM_YDBQueueCurrent declare @Helper QER_YPWOHelperReminder BEGIN TRY insert into @DBQueueCurrent11(UID_DialogDBQueue, UID_Parameter, UID_SubParameter, GenProcID) select UID_DialogDBQueue, UID_Parameter, UID_SubParameter, GenProcID from QBMDBQueueCurrent12 cu with (readpast) where cu.SlotNumber = @SlotNumber if @@rowcount = 0 begin goto EndLabel end  declare @DBQueueElements_36443 QBM_YDBQueueRaw declare13 @Task36443 varchar(38) = 'QER-K-ITSHOPOrder-RESET' insert into @DBQueueElements_36443(Object, GenProcID) select x.UID_PersonWantsOrg, x.GenProcID from14 ( select pwo.UID_PersonWantsOrg, pwo.OrderState, pwo.DecisionLevel, h.SubLevelNumber , sum( case h.Decision when 'P' then 1 else 0 end ) as CountPositive15 , COUNT(*) as CountDecider , max(ws.CountApprover) as CountApprover   , po.DecisionPossible  , max(dbo.QER_FGIGenProcIDForPWO(pwo.GenProcID, cu.GenProcID16, @CfgUseGenProcID)) as GenProcID  from @DBQueueCurrent cu join PersonWantsOrg pwo with (readpast) on cu.UID_Parameter = pwo.UID_PersonWantsOrg join PWOHelperPWO17 h with (readpast) on pwo.UID_PersonWantsOrg = h.UID_PersonWantsOrg and pwo.DecisionLevel = h.LevelNumber join QERWorkingStep ws on ws.UID_QERWorkingMethod18 = pwo.UID_QERWorkingMethod and ws.LevelNumber = pwo.DecisionLevel and ws.SubLevelNumber = h.SubLevelNumber join PWODecisionRule ru on ws.UID_PWODecisionRule19 = ru.UID_PWODecisionRule and ru.UID_Task is null  cross apply dbo.QER_FTPWODecisionPossible(pwo.UID_PersonWantsOrg, pwo.DecisionLevel, h.SubLevelNumber20) po where pwo.OrderState in ('OrderProduct', 'OrderProlongate', 'OrderUnsubscribe') group by pwo.UID_PersonWantsOrg, pwo.OrderState, pwo.DecisionLevel21, h.SubLevelNumber, po.DecisionPossible ) as x where x.CountApprover = -1 and x.DecisionPossible = 0 and x.CountPositive = x.CountDecider and x.CountPositive22 > 0 group by x.UID_PersonWantsOrg, x.GenProcID if @@ROWCOUNT > 0 begin exec QBM_PDBQueueInsert_Bulk @Task36443, @DBQueueElements_36443 delete  @DBQueueCurrent23 from @DBQueueCurrent cu join @DBQueueElements_36443 el on cu.UID_Parameter = el.Object end   Declare @PWOOhneEntscheider QBM_YCursorBuffer insert into24 @PWOOhneEntscheider (UID1, UID2, ObjectKey1, Ident1, Bit1, Int1) select pwo.uid_personwantsorg , dbo.QER_FGIGenProcIDForPWO(pwo.GenProcID, p.GenProcID25, @CfgUseGenProcID) as GenProcID , pwo.XObjectKey, case pwo.Orderstate when 'OrderProduct' then 'Abort' else 'AbortOrder' end , ws.EscalateIfNoApprover26 , pwo.DecisionLevel   from @DBQueueCurrent p join personwantsorg pwo with (readpast) on p.uid_parameter = pwo.uid_personwantsorg join QERWorkingStep ws27 on pwo.UID_QERWorkingMethod = ws.UID_QERWorkingMethod and pwo.DecisionLevel = ws.LevelNumber where not exists ( select top 1 1 from PWOHelperPWO ph with28 (readpast) where pwo.uid_personwantsorg = ph.uid_personwantsorg and ws.LevelNumber = ph.LevelNumber and ws.SubLevelNumber = ph.SubLevelNumber and (ws.UID_PWODecisionRule29 = ph.UID_PWODecisionRule or ph.UID_PWODecisionRule = 'QER-PWODecisionRule-QP' )  and ph.RulerLevel in (0, 1) )    and pwo.OrderState in ('OrderProduct'30, 'OrderProlongate', 'OrderUnsubscribe')  union select pwo.uid_personwantsorg , dbo.QER_FGIGenProcIDForPWO(pwo.GenProcID, p.GenProcID, @CfgUseGenProcID31) as GenProcID , pwo.XObjectKey, case pwo.Orderstate when 'OrderProduct' then 'Abort' else 'AbortOrder' end , 0  , pwo.DecisionLevel   from @DBQueueCurrent32 p join personwantsorg pwo with (readpast) on p.uid_parameter = pwo.uid_personwantsorg where not exists (select top 1 1 from QERWorkingStep ws where pwo.UID_QERWorkingMethod33 = ws.UID_QERWorkingMethod ) and pwo.UID_QERWorkingMethod > ' ' and pwo.OrderState = 'OrderProduct'  select @ElementCount = @@ROWCOUNT select @ElementIndex34 = @@IDENTITY - @ElementCount +1 select @ElementLast = @@IDENTITY while @ElementIndex <= @ElementLast begin select top 1 @uid_personwantsorg = bu.UID1 35, @GenProcID = bu.UID2 , @BasisObjectKey = bu.ObjectKey1 , @AbortMethod = bu.Ident1 , @EscalateIfNoApprover = bu.Bit1 , @DecisionLevel = bu.Int1 from @PWOOhneEntscheider36 bu where bu.ElementIndex = @ElementIndex  if @EscalateIfNoApprover = 0 begin select @SQLcmd = N'uid_personwantsorg = ''' + rtrim(@uid_personwantsorg) 37+ N'''' select @UID_PWOStateFinalError = dbo.QER_FGIPWOStateFinalError(@UID_PersonWantsOrg) exec QBM_PJobCreate_HOCallMethod 'personwantsorg', @SQLcmd,38 @save = 1 , @Methodname = @AbortMethod , @GenProcID = @GenProcID  , @ObjectKeysAffected = DEFAULT , @Param1 = '#LDS#Automatic system approval: No approver available (in this shop).|'39 , @Param2 = @UID_PWOStateFinalError , @Retries = 3 , @checkForExisting = 1  , @WhereClauseAdditional = ' OrderState in(''OrderProduct'', ''OrderProlongate'', ''OrderUnsubscribe'')'40  , @BasisObjectKey = @BasisObjectKey end else begin select @SQLcmd = N'uid_personwantsorg = ''' + rtrim(@uid_personwantsorg) + N''' and DecisionLevel = '41 + STR(@DecisionLevel) exec QBM_PJobCreate_HOCallMethod 'personwantsorg', @SQLcmd, @save = 1 , @Methodname = 'ESCALATE' , @GenProcID = @GenProcID  , @ObjectKeysAffected42 = DEFAULT , @Param1 = 'sa' , @Param2 = '#LDS#Automatic system approval: Decision "escalate" due to no approver available.|' , @Retries = 3 , @checkForExisting43 = 1  , @WhereClauseAdditional = ' OrderState in(''OrderProduct'', ''OrderProlongate'', ''OrderUnsubscribe'')'  , @BasisObjectKey = @BasisObjectKey , @isToFreezeOnError44 = 1 end  delete  @DBQueueCurrent from @DBQueueCurrent cu where cu.UID_Parameter = @uid_personwantsorg if @Debugswitch > 0 begin print 'Zurücksetzen 1'45 end select @ElementIndex += 1 end    Declare @PWOZuWenigEntscheider QBM_YCursorBuffer insert into @PWOZuWenigEntscheider (UID1, UID2, ObjectKey1, Ident146, Bit1, Int1) select distinct pwo.uid_personwantsorg , dbo.QER_FGIGenProcIDForPWO(pwo.GenProcID, p.GenProcID, @CfgUseGenProcID) as GenProcID , pwo.XObjectKey47, case pwo.Orderstate when 'OrderProduct' then 'Abort' else 'AbortOrder' end , ws.EscalateIfNoApprover , pwo.DecisionLevel from @DBQueueCurrent p join 48personwantsorg pwo with (readpast) on p.uid_parameter = pwo.uid_personwantsorg join QERWorkingStep ws on pwo.UID_QERWorkingMethod = ws.UID_QERWorkingMethod49 and pwo.decisionlevel = ws.levelnumber cross apply dbo.QER_FTPWODecisionPossible(pwo.uid_personwantsorg, ws.LevelNumber, ws.SubLevelNumber) dp where dp.DecisionPossible50 = -1   and pwo.OrderState in ('OrderProduct', 'OrderProlongate', 'OrderUnsubscribe') select @ElementCount = @@ROWCOUNT select @ElementIndex = @@IDENTITY51 - @ElementCount +1 select @ElementLast = @@IDENTITY while @ElementIndex <= @ElementLast begin select top 1 @uid_personwantsorg = bu.UID1 , @GenProcID 52= bu.UID2 , @BasisObjectKey = bu.ObjectKey1 , @AbortMethod = bu.Ident1 , @EscalateIfNoApprover = bu.Bit1 , @DecisionLevel = bu.Int1 from @PWOZuWenigEntscheider53 bu where bu.ElementIndex = @ElementIndex  if @EscalateIfNoApprover = 0 begin select @SQLcmd = N'uid_personwantsorg = ''' + rtrim(@uid_personwantsorg) 54+ N'''' select @UID_PWOStateFinalError = dbo.QER_FGIPWOStateFinalError(@UID_PersonWantsOrg) exec QBM_PJobCreate_HOCallMethod 'personwantsorg', @SQLcmd,55 @save = 1 , @Methodname = @AbortMethod , @GenProcID = @GenProcID  , @ObjectKeysAffected = DEFAULT , @Param1 = '#LDS#Automatic system approval: Not enough approvers available.|'56 , @Param2 = @UID_PWOStateFinalError , @Retries = 3 , @checkForExisting = 1  , @WhereClauseAdditional = ' OrderState in(''OrderProduct'', ''OrderProlongate'', ''OrderUnsubscribe'')'57  , @BasisObjectKey = @BasisObjectKey end else begin select @SQLcmd = N'uid_personwantsorg = ''' + rtrim(@uid_personwantsorg) + N''' and DecisionLevel = '58 + STR(@DecisionLevel) exec QBM_PJobCreate_HOCallMethod 'personwantsorg', @SQLcmd, @save = 1 , @Methodname = 'ESCALATE' , @GenProcID = @GenProcID  , @ObjectKeysAffected59 = DEFAULT , @Param1 = 'sa' , @Param2 = '#LDS#Automatic system approval: Decision "escalate" due to not enough approvers available.|' , @Retries = 3 , 60@checkForExisting = 1  , @WhereClauseAdditional = ' OrderState in(''OrderProduct'', ''OrderProlongate'', ''OrderUnsubscribe'')'  , @BasisObjectKey = @BasisObjectKey61 , @isToFreezeOnError = 1 end  delete  @DBQueueCurrent from @DBQueueCurrent cu where cu.UID_Parameter = @uid_personwantsorg if @Debugswitch > 0 begin print62 'Zurücksetzen 2' end select @ElementIndex += 1 end   insert into @DaysToAbort(UID_DialogDBQueue, UID_Parameter, UID_SubParameter, GenProcID) select UID_DialogDBQueue63, UID_Parameter, UID_SubParameter, GenProcID from @DBQueueCurrent Declare @PWOPositiv QBM_YCursorBuffer insert into @PWOPositiv (UID1) select distinct 64dr.UID_Task from @DBQueueCurrent p join personwantsorg pwo with (readpast) on p.uid_parameter = pwo.uid_personwantsorg join PWOHelperPWO ph with (readpast65) on pwo.uid_personwantsorg = ph.uid_personwantsorg and pwo.decisionlevel = ph.levelnumber join pwodecisionrule dr on ph.UID_PWODecisionRule = dr.UID_PWODecisionRule66 where dr.UID_Task > ' '   and OrderState in ('OrderProduct', 'OrderProlongate', 'OrderUnsubscribe') select @ElementCount = @@ROWCOUNT select @ElementIndex67 = @@IDENTITY - @ElementCount +1 select @ElementLast = @@IDENTITY while @ElementIndex <= @ElementLast begin select top 1 @UID_Task = bu.UID1 from @PWOPositiv68 bu where bu.ElementIndex = @ElementIndex delete  @DBQueueElements_spezial insert into @DBQueueElements_spezial (object, subobject, genprocid) select x.uid69, null, x.GenProcID from ( select pwo.uid_personwantsorg as uid , dbo.QER_FGIGenProcIDForPWO(pwo.GenProcID, p.GenProcID, @CfgUseGenProcID) as GenProcID70 from @DBQueueCurrent p join personwantsorg pwo with (readpast) on p.uid_parameter = pwo.uid_personwantsorg join PWOHelperPWO ph with (readpast) on pwo.uid_personwantsorg71 = ph.uid_personwantsorg and pwo.decisionlevel = ph.levelnumber join pwodecisionrule dr on ph.UID_PWODecisionRule = dr.UID_PWODecisionRule   and OrderState72 in ('OrderProduct', 'OrderProlongate', 'OrderUnsubscribe') and dr.UID_Task = @UID_Task ) as x  delete  @DBQueueCurrent from @DBQueueCurrent cu where cu.UID_Parameter73 in (select object from @DBQueueElements_spezial)  delete  @DBQueueElements_spezial  from @DBQueueElements_spezial e join PersonWantsOrg pwo with (readpast74) on e.Object = pwo.UID_PersonWantsOrg where @UID_Task = 'QER-K-ShoppingRackMakeDecisionEX' and (pwo.DecisionLevel > 0 or (pwo.DecisionLevel = 0 and dbo.QBM_FGIConfigparmValue75('QER\ITShop\DecisionOnInsert') > ' ' ) )   exec QBM_PDBQueueInsert_Bulk @UID_Task, @DBQueueElements_spezial  if @Debugswitch > 0 begin print 'Zurücksetzen 3'76 end select @ElementIndex += 1 end   Declare @PWOZeit QBM_YCursorBuffer insert into @PWOZeit (UID1, UID2, ObjectKey1, Ident1) select distinct p.uid_parameter77 , dbo.QER_FGIGenProcIDForPWO(pwo.GenProcID, p.GenProcID, @CfgUseGenProcID) as GenProcID , pwo.XObjectKey, case pwo.Orderstate when 'OrderProduct' then78 'Abort' else 'AbortOrder' end from personwantsorg pwo with (readpast) join @DaysToAbort p on pwo.uid_personwantsorg = p.uid_parameter join PWOHelperPWO79 h with (readpast) on pwo.uid_personwantsorg = h.uid_personwantsorg join QERWorkingMethod wm on pwo.UID_QERWorkingMethod = wm.UID_QERWorkingMethod left80 outer join  ( select h1.UID_PersonWantsOrg, MAX(h1.XDateInserted) as OrderDate from @DaysToAbort p1 join PWODecisionHistory h1 on p1.UID_Parameter = h1.UID_PersonWantsOrg81 where h1.DecisionType = 'Prolongate' and h1.OrderState = 'OrderProlongate' group by h1.UID_PersonWantsOrg ) as hu on pwo.uid_PersonwantsOrg = hu.uid_PersonwantsOrg82  left outer join ( select h1.UID_PersonWantsOrg, MAX(h1.XDateInserted) as OrderDate from @DaysToAbort p1 join PWODecisionHistory h1 on p1.UID_Parameter83 = h1.UID_PersonWantsOrg where h1.DecisionType = 'Unsubscribe' and h1.OrderState = 'OrderUnsubscribe' group by h1.UID_PersonWantsOrg ) as un on pwo.uid_PersonwantsOrg84 = un.uid_PersonwantsOrg where dateadd(dd, wm.DaysToAbort, case pwo.Orderstate when 'OrderProduct' then pwo.OrderDate when 'OrderProlongate' then isnull85(hu.OrderDate, @Mindate1899) when 'OrderUnsubscribe' then isnull(un.OrderDate, @Mindate1899) else pwo.Orderdate end ) < getutcdate() and isnull(wm.DaysToAbort86, 0) > 0   and pwo.OrderState in ('OrderProduct', 'OrderProlongate', 'OrderUnsubscribe')   and not exists (select top 1 1 from JobQueue q join QBMElementAffectedByJob87 ebj on q.UID_Job = ebj.UID_Job where q.ComponentAssembly = 'HandleObjectComponent' and q.TaskName = 'CallMethod'  and ebj.ObjectKeyAffected = pwo.XObjectKey88 and q.Ready2EXE like '[^DH][^I] % '  ) select @ElementCount = @@ROWCOUNT select @ElementIndex = @@IDENTITY - @ElementCount +1 select @ElementLast = @@IDENTITY89 while @ElementIndex <= @ElementLast begin select top 1 @uid_personwantsorg = bu.UID1 , @GenProcID = bu.UID2 , @BasisObjectKey = bu.ObjectKey1 , @AbortMethod90 = bu.Ident1 from @PWOZeit bu where bu.ElementIndex = @ElementIndex select @SQLcmd = N'uid_personwantsorg = ''' + rtrim(@uid_personwantsorg) + N'''' select91 @UID_PWOStateFinalError = dbo.QER_FGIPWOStateFinalError(@UID_PersonWantsOrg) exec QBM_PJobCreate_HOCallMethod 'personwantsorg', @SQLcmd, @save = 1 , @Methodname92 = @AbortMethod , @GenProcID = @GenProcID  , @ObjectKeysAffected = DEFAULT , @Param1 = '#LDS#Automatic system approval: Number of days has been exceeded, as specified in decision method.|'93 , @Param2 = @UID_PWOStateFinalError , @Retries = 3 , @checkForExisting = 1  , @WhereClauseAdditional = ' OrderState in(''OrderProduct'', ''OrderProlongate'', ''OrderUnsubscribe'')'94  , @BasisObjectKey = @BasisObjectKey  delete  @DBQueueCurrent from @DBQueueCurrent cu where cu.UID_Parameter = @uid_personwantsorg if @Debugswitch > 095 begin print 'Zurücksetzen 4' end select @ElementIndex += 1 end    select @GenProcID = null select top 1 @GenProcID = GenProcID from @DBQueueCurrent p 96if @GenProcID is null begin  if @Debugswitch > 0 begin print 'ausstieg 4' end goto EndLabel end exec QBM_PSessionContextSet 'GenProcID', @GenProcID exec97 QBM_PSessionContextSet 'XUser', @XUser  insert into @Helper(UID_HelperKey, NextReminder, NextAutomaticDecision, UID_ElementKey, UID_PersonHead, UID_QERWorkingStep98, Decision, LevelNumber, UID_PWODecisionRule, XObjectKey, RulerLevel) select h.UID_PWOHelperPWO, h.NextReminder, h.NextAutomaticDecision, h.UID_PersonWantsOrg99, h.UID_PersonHead, h.UID_QERWorkingStep, h.Decision, h.LevelNumber, h.UID_PWODecisionRule, h.XObjectKey, h.RulerLevel from @DBQueueCurrent cu join PWOHelperPWO100 h with (readpast) on cu.UID_Parameter = h.UID_PersonWantsOrg  update @Helper set NextAutomaticDecision = dbo.QER_FCVTimeToWorkTimePerson(getutcdate(),101 ws.MinutesAutomaticDecision, h.UID_PersonHead) , IsToUpdateNextAutomaticDec = 1 from @Helper h join @DBQueueCurrent p on h.UID_ElementKey = p.UID_Parameter102 join QERWorkingStep ws on h.uid_QERWorkingStep = ws.UID_QERWorkingStep join PersonWantsOrg pwo with (readpast) on h.UID_ElementKey = pwo.UID_PersonWantsOrg103 join PWODecisionRule r on ws.UID_PWODecisionRule = r.UID_PWODecisionRule where ws.MinutesAutomaticDecision > 0 and h.NextAutomaticDecision = @MaxDate2200104 and isnull(h.Decision, '') = '' and r.UID_Task is null and h.levelnumber = pwo.DecisionLevel  select top 1 @GenProcID = GenProcID from @DBQueueCurrent105 p exec QBM_PSessionContextSet 'GenProcID', @GenProcID exec QBM_PSessionContextSet 'XUser', @XUser update @Helper set NextAutomaticDecision = @MaxDate2200106 , IsToUpdateNextAutomaticDec = 1 from @Helper h join @DBQueueCurrent p on h.UID_ElementKey = p.UID_Parameter join QERWorkingStep ws on h.uid_QERWorkingStep107 = ws.UID_QERWorkingStep join PersonWantsOrg pwo with (readpast) on h.UID_ElementKey = pwo.UID_PersonWantsOrg join PWODecisionRule r on ws.UID_PWODecisionRule108 = r.UID_PWODecisionRule where h.NextAutomaticDecision < @MaxDate2200 and ( ws.MinutesAutomaticDecision = 0 or isnull(h.Decision, '') > '' or h.levelnumber109 <> pwo.DecisionLevel or r.UID_Task > ' ' )  Declare @PWOAutomatic QBM_YCursorBuffer insert into @PWOAutomatic (UID1, UID2, ObjectKey1, Ident1, Int1, Ident2110) select distinct p.UID_Parameter , dbo.QER_FGIGenProcIDForPWO(pwo.GenProcID, p.GenProcID, @CfgUseGenProcID) as GenProcID , pwo.XObjectKey, ws.AutomaticDecision111 , pwo.DecisionLevel , min(dbo.QBM_FCVIntToString(hp.SubLevelNumber)) from @DBQueueCurrent p join ( select h.UID_ElementKey as uid_personwantsorg, h.uid_QERWorkingStep112  from @Helper h join @DBQueueCurrent p on h.UID_ElementKey = p.uid_parameter join PersonWantsOrg pwo with (readpast) on h.UID_ElementKey = pwo.UID_PersonWantsOrg113 and h.levelnumber = pwo.DecisionLevel join QERWorkingStep ws on ws.UID_QERWorkingStep = h.UID_QERWorkingStep where h.NextAutomaticDecision < @MaxDate2200114     and h.RulerLevel <> 2 group by h.UID_ElementKey, h.uid_QERWorkingStep having max(NextAutomaticDecision) < getutcdate() ) as x on p.uid_parameter =115 x.uid_personwantsorg join PersonWantsOrg pwo on p.UID_Parameter = pwo.UID_PersonWantsOrg   and pwo.OrderState in ('OrderProduct', 'OrderProlongate', 'OrderUnsubscribe'116) join QERWorkingStep ws on ws.uid_QERWorkingStep = x.uid_QERWorkingStep join PWOHelperPWO hp on hp.UID_PersonWantsOrg = pwo.UID_PersonWantsOrg and hp.UID_QERWorkingStep117 = ws.UID_QERWorkingStep where dbo.QBM_FGIJobCreatedExists(pwo.XObjectKey) = 0  and dbo.QER_FGIPWODecisionPossible(pwo.UID_PersonWantsOrg, hp.LevelNumber118, hp.SubLevelNumber) = 1 group by p.UID_Parameter , dbo.QER_FGIGenProcIDForPWO(pwo.GenProcID, p.GenProcID, @CfgUseGenProcID) , pwo.XObjectKey, ws.AutomaticDecision119 , pwo.DecisionLevel select @ElementCount = @@ROWCOUNT select @ElementIndex = @@IDENTITY - @ElementCount +1 select @ElementLast = @@IDENTITY while @ElementIndex120 <= @ElementLast begin select top 1 @uid_personwantsorg = bu.UID1 , @GenProcID = bu.UID2 , @BasisObjectKey = bu.ObjectKey1 , @AbortMethod = bu.Ident1 ,121 @DecisionLevel = bu.Int1 , @SubLevelNumberString = bu.Ident2 from @PWOAutomatic bu where bu.ElementIndex = @ElementIndex select @SQLcmd = N'uid_personwantsorg = '''122 + rtrim(@uid_personwantsorg) + N''' and DecisionLevel = ' + STR(@DecisionLevel) select @UID_PWOStateFinalError = dbo.QER_FGIPWOStateFinalError(@UID_PersonWantsOrg123)  if @AbortMethod in ('TRUE', 'FALSE') begin exec QBM_PJobCreate_HOCallMethod 'personwantsorg', @SQLcmd, @save = 1 , @Methodname = 'MakeDecision' , @ObjectKeysAffected124 = DEFAULT , @GenProcID = @GenProcID  , @Param1 = 'sa'  , @Param2 = @AbortMethod , @Param3 = '#LDS#Automatic system approval: Decision due to timeout.|'125  , @Param5 = @SubLevelNumberString , @Retries = 3 , @checkForExisting = 1  , @WhereClauseAdditional = ' OrderState in(''OrderProduct'', ''OrderProlongate'', ''OrderUnsubscribe'')'126  , @BasisObjectKey = @BasisObjectKey , @isToFreezeOnError = 1 end if @AbortMethod in ('ESCALATE')  and not exists (select top 1 1 from @PWOAutomatic bu127 where bu.ElementIndex < @ElementIndex and bu.UID1 = @uid_personwantsorg ) begin  exec QBM_PJobCreate_HOCallMethod 'personwantsorg', @SQLcmd, @save = 1128 , @Methodname = 'ESCALATE' , @GenProcID = @GenProcID  , @ObjectKeysAffected = DEFAULT , @Param1 = 'sa' , @Param2 = '#LDS#Automatic system approval: Decision "escalate" due to timeout.|'129 , @Retries = 3 , @checkForExisting = 1  , @WhereClauseAdditional = ' OrderState in(''OrderProduct'', ''OrderProlongate'', ''OrderUnsubscribe'')'  , @BasisObjectKey130 = @BasisObjectKey , @isToFreezeOnError = 1 end if @AbortMethod in ('Abort')  and not exists (select top 1 1 from @PWOAutomatic bu where bu.ElementIndex131 < @ElementIndex and bu.UID1 = @uid_personwantsorg ) begin  if not exists (select top 1 1 from personwantsorg with (readpast) where uid_personwantsorg 132= @uid_personwantsorg and orderstate = 'OrderProduct' ) begin select @AbortMethod = 'AbortOrder' end exec QBM_PJobCreate_HOCallMethod 'personwantsorg',133 @SQLcmd, @save = 1 , @Methodname = @AbortMethod , @GenProcID = @GenProcID  , @ObjectKeysAffected = DEFAULT , @Param1 = '#LDS#Automatic system approval: "Abort" due to timeout.|'134 , @Param2 = @UID_PWOStateFinalError , @Retries = 3 , @checkForExisting = 1  , @WhereClauseAdditional = ' OrderState in (''Assigned'', ''Granted'', ''New'', ''OrderProduct'', ''OrderProlongate'', ''OrderUnsubscribe'', ''Waiting'')'135  , @BasisObjectKey = @BasisObjectKey , @isToFreezeOnError = 1 end   delete  @DBQueueCurrent from @DBQueueCurrent cu where cu.UID_Parameter = @uid_personwantsorg136 if @Debugswitch > 0 begin print 'Zurücksetzen 5' end select @ElementIndex += 1 end   select @GenProcID = null select top 1 @GenProcID = GenProcID from137 @DBQueueCurrent p if @GenProcID is null begin  if @Debugswitch > 0 begin print 'ausstieg 5' end goto EndLabel end exec QBM_PSessionContextSet 'GenProcID'138, @GenProcID exec QBM_PSessionContextSet 'XUser', @XUser update @Helper set NextReminder = dbo.QER_FCVTimeToWorkTimePerson(getutcdate(), ws.MinutesReminder139, h.UID_PersonHead     ) , IsToUpdateNextReminder = 1 from @Helper h join @DBQueueCurrent p on h.UID_ElementKey = p.UID_Parameter join QERWorkingStep ws140 on h.uid_QERWorkingStep = ws.uid_QERWorkingStep join PersonWantsOrg pwo with (readpast)on h.UID_ElementKey = pwo.UID_PersonWantsOrg join PWODecisionRule141 r on h.UID_PWODecisionRule = r.UID_PWODecisionRule where ws.MinutesReminder > 0 and isnull(h.NextReminder, @MaxDate2200) = @MaxDate2200 and isnull(h.Decision142, '') in ('', 'Q') and r.UID_Task is null and h.levelnumber = pwo.DecisionLevel   update @Helper set NextReminder = @MaxDate2200 , IsToUpdateNextReminder143 = 1 from @Helper h join @DBQueueCurrent p on h.UID_ElementKey = p.UID_Parameter join QERWorkingStep ws on h.uid_QERWorkingStep = ws.UID_QERWorkingStep144 join PersonWantsOrg pwo with (readpast) on h.UID_ElementKey = pwo.UID_PersonWantsOrg join pwodecisionrule r on h.UID_PWODecisionRule = r.UID_PWODecisionRule145 where h.NextReminder < @MaxDate2200 and ( ws.MinutesReminder = 0 or isnull(h.Decision, '') not in ( '', 'Q') or h.levelnumber <> pwo.DecisionLevel or 146r.UID_Task > ' ' )  update @Helper set NextReminder = @MaxDate2200 , IsToUpdateNextReminder = 1 from @Helper h join @DBQueueCurrent p on h.UID_ElementKey147 = p.UID_Parameter join PersonWantsOrg pwo with (readpast) on h.UID_ElementKey = pwo.UID_PersonWantsOrg where h.NextReminder < @MaxDate2200 and isnull(h.Decision148, '') = '' and h.levelnumber = pwo.DecisionLevel and exists (select top 1 1 from @Helper hq where hq.UID_ElementKey = h.UID_ElementKey and hq.Decision 149= 'Q' and hq.LevelNumber = h.LevelNumber )  Declare @PWOSenden QBM_YCursorBuffer insert into @PWOSenden (UID1, UID2, UID3, Int1, Bit1, ObjectKey1, Int2150, UID4) select h.UID_HelperKey as UID_PWOHelperPWO , dbo.QER_FGIGenProcIDForPWO(pwo.GenProcID, p.GenProcID, @CfgUseGenProcID) as GenProcID , pe.UID_Person151, ws.MinutesReminder, sign(len(isnull(ws.UID_DialogRichMailReminder, ''))), h.XObjectKey , pwo.DecisionLevel , pwo.UID_PersonWantsOrg from @Helper h join152 @DBQueueCurrent p on h.UID_ElementKey = p.UID_Parameter join PersonWantsOrg pwo with (readpast) on h.UID_ElementKey = pwo.UID_PersonWantsOrg and h.levelnumber153 = pwo.DecisionLevel join Person pe with (readpast) on pe.UID_Person = h.UID_PersonHead     join QERWorkingStep ws on h.uid_QERWorkingStep = ws.uid_QERWorkingStep154 where h.NextReminder < getutcdate() and dbo.QBM_FGIJobCreatedExists(h.XObjectKey) = 0  and h.RulerLevel < 2 select @ElementCount = @@ROWCOUNT select @ElementIndex155 = @@IDENTITY - @ElementCount +1 select @ElementLast = @@IDENTITY while @ElementIndex <= @ElementLast begin select top 1 @UID_PWOHelperPWO = bu.UID1 , 156@GenProcID = bu.UID2 , @UID_PersonHead = bu.UID3 , @MinutesReminder = bu.Int1 , @MailExists = bu.Bit1 , @ObjectkeyForMail = bu.ObjectKey1 , @CurrentDecisionLevel157 = bu.Int2 , @uid_Personwantsorg = bu.UID4 from @PWOSenden bu where bu.ElementIndex = @ElementIndex exec QBM_PSessionContextSet 'GenProcID', @GenProcID158 exec QBM_PSessionContextSet 'XUser', @XUser update @Helper set NextReminder = dbo.QER_FCVTimeToWorkTimePerson(getutcdate(), @MinutesReminder, @UID_PersonHead159) , IsToUpdateNextReminder = 1 where UID_HelperKey = @UID_PWOHelperPWO if @MailExists > 0 begin  delete  @ObjectkeySForMail  insert into @ObjectkeySForMail160(Parameter1) select @ObjectkeyForMail select @WhereclauseForMail = ' exists(select top 1 1 161												from personwantsorg pwo 162												where pwo.uid_personwantsorg  = '''163 + @uid_Personwantsorg + ''' 164												and pwo.decisionlevel = ' + str(@CurrentDecisionLevel) + ' 165												)' exec QBM_PJobCreate_HOFireEvent_L166 'PWOHelperPWO', @ObjectkeySForMail, 'Remind' , @GenProcID  , @priority = 10  , @BasisObjectKey = @ObjectkeyForMail , @CheckForExisting = 1 , @whereclauseAdditional167 = @WhereclauseForMail , @AdditionalObjectKeysAffected = DEFAULT end select @ElementIndex += 1 end    update PWOHelperPWO set NextReminder = case h.IsToUpdateNextReminder168 when 1 then h.NextReminder else t.NextReminder end , NextAutomaticDecision = case h.IsToUpdateNextAutomaticDec when 1 then h.NextAutomaticDecision else169 t.NextAutomaticDecision end from PWOHelperPWO t join @Helper h on t.UID_PWOHelperPWO = h.UID_HelperKey where h.IsToUpdateNextReminder = 1 or h.IsToUpdateNextAutomaticDec170 = 1   END TRY BEGIN CATCH exec QBM_PSessionErrorAdd default RAISERROR ('', 18, 1) WITH NOWAIT END CATCH EndLabel: exec QBM_PSessionContextSet 'GenProcID'171, @GenProcID_R exec QBM_PSessionContextSet 'XUser', @XUser_R return end 172