Do not let any software impress you!

Only let it convince your intellect.
Slider img 1
Do not look for a business paradise!

It is a waste of time.
Slider img 2
Only yourself can push you uphill.

There is no easy road to prizes.
Slider img 3
Productivity is the name of the game.

And you have to conquer it.
Slider img 4
As long as you understand it,

you will start to build your know-how.
Slider img 5
We can help with that.

We have the tools and the method.
Slider img 6
Procedure : AU_BPM_EXPERT

AutoScript

start_agent_info
   AgentName = "AU_BPM_EXPERT"
   AgentDescr = "BPM Expert"
   AgentLanguage = ""
   __timer_interval = 0 {....define (in seconds) the timer interval for the wake up}
   __delete_on_termination = 0 {....1=the agent frees itself when terminates its task}
end_agent_info

start_action
                                                
    function = __params[1]            
    scode    = __params[2]
    scode    = strcat(scode,"%")        

    {........................................SUMMARY..................................}
    if (function = "SUMMARY") then

       id = 0

       {--------------------------------- Activity ----------------------------}
       id = id + 1
       lab_caption[id] = "Department"
       start_sql "*" "KOSMOS"
         SELECT AU_POS.POS_D
         FROM AU_POS
         WHERE (AU_POS.DCODE = :C)
       end_sql
       q = QueryByName()
       call TSetParam(q,"C",__params[2])
       call TExecute(q)
       val_caption[id] = TGetFld(q,"POS_D")
       val_unit[id] = ""
       call FreeEmbSQL(q)

       {--------------------------------- Count of Assosiates Participation ----------------------------}
       id = id + 1
       lab_caption[id] = "Count of Assosiates Participation"
       start_sql "*" "KOSMOS"
         SELECT AU_STEP.UNAME
         FROM AU_STEP INNER JOIN AU_POS ON AU_STEP.RNAME = AU_POS.POS_D
         WHERE (((AU_STEP.FINISHED)=1) AND ((AU_STEP.UNAME) Is Not Null Or (AU_STEP.UNAME)=''))
         AND ((AU_POS.DCODE) LIKE :C)
         GROUP BY AU_STEP.UNAME
       end_sql
       q = QueryByName()
       call TSetParam(q,"C",scode)
       call TExecute(q)
       val_caption[id] = TRecordCount(q)
       val_unit[id] = "Persons"
       call FreeEmbSQL(q)

       expand_collapse[id] = True
       expanded[id]        = False
       expand_height[id] = 0
       agent_function[id] = "GET_ASSOSIATES_PARTICIPATION"
       expand_to_window[id]= True

       {--------------------------------- Count of Roles Participation ----------------------------}
       id = id + 1
       lab_caption[id] = "Count of Roles Participation"
       start_sql "*" "KOSMOS"
         SELECT AU_STEP.RNAME
         FROM AU_STEP INNER JOIN AU_POS ON AU_STEP.RNAME = AU_POS.POS_D
         WHERE (((AU_STEP.FINISHED)=1) AND ((AU_STEP.RNAME) Is Not Null Or (AU_STEP.RNAME)=''))
         AND ((AU_POS.DCODE) LIKE :C)
         GROUP BY AU_STEP.RNAME
       end_sql
       q = QueryByName()
       call TSetParam(q,"C",scode)
       call TExecute(q)
       val_caption[id] = TRecordCount(q)
       val_unit[id] = "Roles"
       call FreeEmbSQL(q)

       expand_collapse[id] = True
       expanded[id]        = False
       expand_height[id] = 0
       agent_function[id] = "GET_ROLES_PARTICIPATION"
       expand_to_window[id]= True

       {--------------------------------- Assosiates Participation ratio ----------------------------}
       id = id + 1
       lab_caption[id] = "Assosiates Participation ratio"
       start_sql "*" "KOSMOS"
         SELECT AU_STEP.RNAME
         FROM AU_STEP INNER JOIN AU_POS ON AU_STEP.RNAME = AU_POS.POS_D
         WHERE (((AU_STEP.FINISHED)=1) AND ((AU_STEP.RNAME) Is Not Null Or (AU_STEP.RNAME)=''))
         AND ((AU_POS.DCODE) LIKE :C)
         GROUP BY AU_STEP.RNAME
       end_sql
       q = QueryByName()
       call TSetParam(q,"C",scode)
       call TExecute(q)
       cnt = TRecordCount(q)
       call FreeEmbSQL(q)

       start_sql "*" "KOSMOS"
         SELECT AU_USER.NUNAME
         FROM AU_USER
         WHERE (((AU_USER.NUNAME) Is Not Null And (AU_USER.NUNAME)<>''))
         GROUP BY AU_USER.NUNAME
       end_sql
       q = QueryByName()
       call TExecute(q)
       val_caption[id] = TRecordCount(q)
       val_caption[id] = cnt / val_caption[id] * 100
       val_caption[id] = format("%8.0f",val_caption[id])
       val_unit[id] = "%"
       call FreeEmbSQL(q)

       {--------------------------------- Count of Activities that issued -----------------------}
       id = id + 1
       lab_caption[id] = "Count of Activities that issued"
       start_sql "*" "KOSMOS"
         SELECT COUNT(AU_STEP.AU_STEP) AS CNT
         FROM AU_STEP INNER JOIN AU_POS ON AU_STEP.RNAME = AU_POS.POS_D
         WHERE
         (AU_STEP.ISTEP = 0) AND (AU_STEP.AU_PROCESS > 0)
         AND ((AU_POS.DCODE) LIKE :C)
       end_sql
       q = QueryByName()
       call TSetParam(q,"C",scode)
       call TExecute(q)
       val_caption[id] = TGetFld(q,"CNT")
       val_unit[id] = "Activities"
       call FreeEmbSQL(q)

       {--------------------------------- Count of Closed Activities ----------------------------}
       id = id + 1
       lab_caption[id] = "Count of Closed Activities"
       start_sql "*" "KOSMOS"
         SELECT COUNT(AU_STEP.AU_STEP) AS CNT
         FROM AU_STEP INNER JOIN AU_POS ON AU_STEP.RNAME = AU_POS.POS_D
         WHERE
         (AU_STEP.ISTEP = 0) AND (AU_STEP.AU_PROCESS > 0) AND (AU_STEP.FINISHED = 1)
         AND ((AU_POS.DCODE) LIKE :C)                                
       end_sql
       q = QueryByName()
       call TSetParam(q,"C",scode)
       call TExecute(q)
       val_caption[id] = TGetFld(q,"CNT")
       val_unit[id] = "Activities"
       call FreeEmbSQL(q)

       {--------------------------------- Count of Open Activities ----------------------------}
       id = id + 1
       lab_caption[id] = "Count of Open Activities"                            
       start_sql "*" "KOSMOS"
         SELECT COUNT(AU_STEP.AU_STEP) AS CNT
         FROM AU_STEP INNER JOIN AU_POS ON AU_STEP.RNAME = AU_POS.POS_D
         WHERE
         (AU_STEP.ISTEP = 0) AND (AU_STEP.AU_PROCESS > 0) AND (AU_STEP.FINISHED = 0)
         AND ((AU_POS.DCODE) LIKE :C)
       end_sql
       q = QueryByName()
       call TSetParam(q,"C",scode)
       call TExecute(q)
       val_caption[id] = TGetFld(q,"CNT")
       val_unit[id] = "Activities"
       call FreeEmbSQL(q)

       {-------------------------- Mean time of Closed Activities Waiting -------------------------}
       id = id + 1
       lab_caption[id] = "Mean time of Closed Activities Waiting"
       start_sql "*" "KOSMOS"
         SELECT Avg(AU_STEP.FTIME) AS AVER
         FROM AU_STEP INNER JOIN AU_POS ON AU_STEP.RNAME = AU_POS.POS_D
         WHERE (AU_STEP.FINISHED = 1) AND (FTIME > 0)
         AND ((AU_POS.DCODE) LIKE :C)                                
       end_sql
       q = QueryByName()
       call TSetParam(q,"C",scode)
       call TExecute(q)
       val_caption[id] = TGetFld(q,"AVER")
       val_caption[id] = val_caption[id] * 24
       val_caption[id] = format("%8.2f",val_caption[id])
       val_unit[id] = "Hours"
       call FreeEmbSQL(q)

       expand_collapse[id] = True
       expanded[id]        = False                     
       expand_height[id] = 0
       agent_function[id] = "GET_ASSIGNED_ACTIVITIES"
       expand_to_window[id]= True

       lab_count = id
       return
    endif

    {.......................................GET_ASSOSIATES_PARTICIPATION..........................}
    if (function = "GET_ASSOSIATES_PARTICIPATION") then     {keep}

       hbar_series = True                                                 
       title = "Count of Closed Activities per Assosiate"
       draw_type = "CHART"
       y_count = 1
       show_legend = False

       start_sql "*" "KOSMOS"
         SELECT AU_STEP.UNAME AS UN, Count(AU_STEP.UNAME) AS CNT
         FROM AU_STEP INNER JOIN AU_POS ON AU_STEP.RNAME = AU_POS.POS_D
         WHERE (((AU_STEP.FINISHED)=1) AND ((AU_STEP.UNAME) Is Not Null Or (AU_STEP.UNAME)=''))
         AND ((AU_POS.DCODE) LIKE :C)
         GROUP BY AU_STEP.UNAME
         ORDER BY AU_STEP.UNAME
       end_sql
       q = QueryByName()
       call TSetParam(q,"C",scode)
       call TExecute(q)
       msg = error_message(q)
       count = TRecordCount(q)
       call TFirst(q)
       for i = 1 to count
         x[i] = TGetFld(q,"UN")
         y1[i] = TGetFld(q,"CNT")
         call TNext(q)
       next
       call FreeEmbSQL(q)

       return
    endif

    {.......................................GET_ROLES_PARTICIPATION..........................}
    if (function = "GET_ROLES_PARTICIPATION") then         {keep}

       hbar_series = True
       title = "Count of Closed Activities per Role"
       draw_type = "CHART"
       y_count = 1
       show_legend = False

       start_sql "*" "KOSMOS"
         SELECT AU_STEP.RNAME AS RN, Count(AU_STEP.UNAME) AS CNT
         FROM AU_STEP INNER JOIN AU_POS ON AU_STEP.RNAME = AU_POS.POS_D
         WHERE (((AU_STEP.FINISHED)=1) AND ((AU_STEP.RNAME) Is Not Null Or (AU_STEP.RNAME)=''))
         AND ((AU_POS.DCODE) LIKE :C)
         GROUP BY AU_STEP.RNAME
         ORDER BY AU_STEP.RNAME
       end_sql
       q = QueryByName()
       call TSetParam(q,"C",scode)
       call TExecute(q)
       msg = error_message(q)
       count = TRecordCount(q)
       if (count = 0) then
         call FreeEmbSQL(q)
         return
       endif
       call TFirst(q)
       for i = 1 to count
         x[i] = TGetFld(q,"RN")
         y1[i] = TGetFld(q,"CNT")
         call TNext(q)
       next
       call FreeEmbSQL(q)

       return
    endif

    {.......................................GET_ASSIGNED_ACTIVITIES..........................}
    if (function = "GET_ASSIGNED_ACTIVITIES") then

       line_series = True
       title = "Assigned Activities / Closed Activities and Activities Acumulated"
       draw_type = "CHART"
       y_count = 3
       line1 = "Assinged"
       line2 = "Closed"
       line3 = "Acumulated"
       show_legend = True
       left_axis_title = "Count of Activities"
       bottom_axis_title = "Days since the begining"

       start_sql "*" "KOSMOS"
         SELECT AU_STEP.ASSIGNED_AT_DATE, Count(AU_STEP.AU_STEP) AS CNT
         FROM AU_STEP INNER JOIN AU_POS ON AU_STEP.RNAME = AU_POS.POS_D
         WHERE ((AU_POS.DCODE Like :C) AND (AU_STEP.AU_PROCESS > 0))
         GROUP BY AU_STEP.ASSIGNED_AT_DATE
         ORDER BY AU_STEP.ASSIGNED_AT_DATE
       end_sql
       q = QueryByName()
       call TSetParam(q,"C",scode)
       call TExecute(q)
       count = TRecordCount(q)
       if (count = 0) then
         call FreeEmbSQL(q)
         return
       endif
       call TFirst(q)
       date1 = TGetFld(q,"ASSIGNED_AT_DATE")
       date2 = crDate
       date1_num = DateToNum(date1)
       date2_num = DateToNum(date2)
       array_dim = date2_num - date1_num

       if (array_dim > 0) then

         for i = 1 to array_dim+1
         x[i] = i
         y1[i] = 0
         y2[i] = 0
         y3[i] = 0
         next

         for i = 1 to count
         d1 = TGetFld(q,"ASSIGNED_AT_DATE")
         d = DateToNum(d1)
         d = d - date1_num

         y1[d+1] = TGetFld(q,"CNT")
call trace("ass d1=",d1,", cnt=",y1[d+1])
         call TNext(q)
         next
         call FreeEmbSQL(q)

         start_sql "*" "KOSMOS"
         SELECT AU_STEP.FINISHED_AT_DATE, Count(AU_STEP.AU_STEP) AS CNT
         FROM AU_STEP INNER JOIN AU_POS ON AU_STEP.RNAME = AU_POS.POS_D
         WHERE ((AU_POS.DCODE Like :C) AND (AU_STEP.AU_PROCESS > 0) AND (AU_STEP.FINISHED=1))
         GROUP BY AU_STEP.FINISHED_AT_DATE
         ORDER BY AU_STEP.FINISHED_AT_DATE
         end_sql
         q1 = QueryByName()
         call TSetParam(q1,"C",scode)
         call TExecute(q1)
         count = TRecordCount(q1)
         call TFirst(q1)

         for i = 1 to count
         d1 = TGetFld(q1,"FINISHED_AT_DATE")
         d = DateToNum(d1)
         d = d - date1_num

         y2[d+1] = TGetFld(q1,"CNT")
call trace("fin d1=",d1,", cnt=",y1[d+1])

         call TNext(q1)
         next
         call FreeEmbSQL(q1)

         for i = 1 to array_dim+1
         if (i = 1) then
                 y3[i] = y1[i] - y2[i]
         elseif (i > 1) then
                 y3[i] = y3[i-1] + y1[i] - y2[i]
         endif
call trace("d=",i,", y1=",y1[i],", y2=",y2[i],", y3=",y3[i])
         next

         count = array_dim+1
       endif

       return
    endif

    {.......................................GANTT_STEP..........................}
    if (function = "GANTT_STEP") then

       gantt_series = True
       title = strcat("Activities for Process :",__params[2])
       bottom_axis_title = "Time"
       left_axis_title = "Associates/Roles"
       draw_type = "CHART"
       y_count = 1
       show_legend = True

       start_sql "*" "KOSMOS"
         SELECT AU_STEP.STEP_DESCR AS DESCR, AU_STEP.UNAME,
         AU_STEP.UNAME, AU_STEP.ACTIVITY, AU_STEP.FINISHED,
         AU_STEP.ASSIGNED_AT_DATE AS D1, AU_STEP.ASSIGNED_AT_TIME AS T1, AU_STEP.FINISHED_AT_DATE AS D2,
         AU_STEP.FINISHED_AT_TIME AS T2
         FROM AU_STEP
         WHERE (AU_STEP.AU_PROCESS =:P) AND (AU_STEP.ISTEP = 0) AND (AU_STEP.FINISHED = 1)
         ORDER BY AU_STEP.AU_STEP DESC
       end_sql
       q = QueryByName()
       call TSetParam(q,"P",__params[2])
       call TExecute(q)
       count = TRecordCount(q)

       call TFirst(q)
       dmin = TGetFld(q,"D1")
       dmin = DateToNum(dmin)
       dmin = dmin - 1

       yy = 0
       for i = 1 to count
         descr = TGetFld(q,"ACTIVITY")
         finished = TGetFld(q,"FINISHED")
         user = TGetFld(q,"UNAME")
         descr[i] = strcat(descr,"(",user,")")

         d1 = TGetFld(q,"D1")
         d2 = TGetFld(q,"D2")
         t1 = TGetFld(q,"T1")
         t2 = TGetFld(q,"T2")

         {........................the real time..............}
         if (finished = 1) then
         d1 = DateToNum(d1)
         d2 = DateToNum(d2)
         t1 = TimeToNum(t1)
         t2 = TimeToNum(t2)
         d1 = d1 + t1
         d2 = d2 + t2
         d1[i] = d1
         d2[i] = d2
         yy = yy + 1
         y[i] = yy
         color[i] = StringToColor("clLime")
         elseif (finished = 0) then
         d1 = DateToNum(d1)
         d2 = DateToNum(crDate)
         t1 = TimeToNum(t1)
         t2 = TimeToNum(crTime)
         d1 = d1 + t1
         d2 = d2 + t2
         d1[i] = d1
         d2[i] = d2
         yy = yy + 1
         y[i] = yy
         color[i] = StringToColor("clRed")
         if (d2+1-dmax > 0) then
                 dmax = d2 + 1
         endif
         endif

         {........................the standart time..............}
{ dd2 = d2 - (d2-d1)*0.3}
{ yy = yy + 1}
{ color[i] = StringToColor("clBlue")}
{ descr[i] = "Standard Time"}

{ if (d2+1-dmax > 0) then} }
{ dmax = d2 + 1 }
{ endif}
         call TNext(q)
       next
       call FreeEmbSQL(q)

       return
    endif

end_action