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_EQUIPMENT_MAINT

AutoScript

start_agent_info
   AgentName = "AU_EQUIPMENT_MAINT"
   AgentDescr = "Equipment Maintenance Assignment"
   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_bpm_activity "Task"
start_bpm_subactivity "Task"
    
    rec = __params[1]
    fin = SelectFrom("SELECT FINISHED FROM AU_STEP WHERE (AU_STEP=",rec,")")
    
    if (fin = 1) then
       call OnOpenForm_DisableAllFields()
    else
       call OnOpenForm_DisableField("FINISHED")
    endif        
    
    expr = strcat(rec,"=AU_STEP")        
    call OpenFormTop("ptEdit","AU_NEWTASK_E.FM","WORK.AU_STEP",1,expr)
    
end_bpm_subactivity
start_bpm_subactivity "New Child Task"
                                
    rec = __params[1]
    fin = SelectFrom("SELECT FINISHED FROM AU_STEP WHERE (AU_STEP=",rec,")")
    fin = val(fin)
    
    if (fin = 0) then
       call OpenFormTop("ptAppend","AU_NEWTASK_E.FM","WORK.AU_STEP",1,"?=AU_STEP","NEW_CHILD",rec)
    endif
    
end_bpm_subactivity
start_bpm_subactivity "New Parallel Task"
    
    rec = __params[1]
    fin = SelectFrom("SELECT FINISHED FROM AU_STEP WHERE (AU_STEP=",rec,")")
    fin = val(fin)
    
    if (fin = 0) then
       call OpenFormTop("ptAppend","AU_NEWTASK_E.FM","WORK.AU_STEP",1,"?=AU_STEP","NEW_PARALLEL",rec)
    endif
    
end_bpm_subactivity
start_bpm_validation
                                
    flag = message_yes_no("Does this creates a new Task?")
    if (flag = 1) then
       user = GetUserName()
       call bpm_startfsm ( "AU_SMALLTASK", "NEW_NEXT", __params[1], user )
    endif    
        
    result = 1
    
end_bpm_validation
end_bpm_activity

start_bpm_activity "Maintenance Task"
start_bpm_subactivity "Form"
                        
    call OnOpenForm_DisableAllFields()
    call OnOpenForm_EnableField("UCOMM")
    
    rec = __params[1]
    expr = strcat(rec,"=AU_STEP")
    call OpenFormTop("ptEdit","AU_MAINT_E.FM","WORK.AU_STEP",1,expr)
    
end_bpm_subactivity
start_bpm_validation
    
    result = 1
    
end_bpm_validation
end_bpm_activity

start_action

     mode = __params[1]

     if (mode = "START") then

         __au_process = 0                 {process doen not exist yet}
         user = GetUserName()

         start_sql "*" "KOSMOS"
         SELECT * FROM AU_GOOD
         end_sql                                        
         q = QueryByName()
         call TExecute(q)
         count = TRecordCount(q)
         call TFirst(q)
         for j = 1 to count

         title = TGetFld(q, "TITLE")

         for i = 1 to 4
                 if (i = 1) then
                 date_var = "VISUAL_INSPECTION_DAYS"
                 endif
                 if (i = 2) then
                 date_var = "OIL_CHANGE_DAYS"
                 endif
                 if (i = 3) then
                 date_var = "BEARING_REPLACEMENT"
                 endif
                 if (i = 4) then
                 date_var = "ELECTRICAL_CONSUMPTION"
                 endif

                 id = TGetFld(q, "AU_GOOD")
                 sql = "SELECT AU_GDPROPERTY.AU_GDPROPERTY, AU_GOOD_PROP.PVALUE, AU_GDPROPERTY.AU_GDPROPERTY_D FROM AU_GOOD_PROP, AU_GDPROPERTY "
                 sql = strcat(sql,"WHERE (AU_GOOD_PROP.AU_GDPROPERTY = AU_GDPROPERTY.AU_GDPROPERTY) AND (AU_GOOD_PROP.AU_GOOD = ",id,") ")
                 sql = strcat(sql,"AND (AU_GDPROPERTY.PCODE = '", date_var, "')")
                 str = SelectFrom(sql)
call trace("first select = ", str)
                 var_id = GetSQLSelectItem(str,1)
                 days = GetSQLSelectItem(str,2)
                 days = val(days)
call trace("days=",days)
                 descr = GetSQLSelectItem(str,3)

                 if (var_id > 0) then
                 str = SelectFrom("SELECT AU_STEP, FINISHED, FINISHED_AT_DATE FROM AU_STEP WHERE (REL_CODE = '", date_var, "') AND (AU_GOOD = ",id,") ORDER BY AU_STEP DESC")
call trace("second select = ", str)
                 step_id = GetSQLSelectItem(str,1)
                 step_id = val(step_id) {if value is empty make it 0}
                 finished = GetSQLSelectItem(str,2)
                 fdate = GetSQLSelectItem(str,3)

                 if (step_id > 0) then [activity exists}

                 if (finished = 1) then
                         if ( __au_process = 0) then {if process does not exist create it}
                         __au_process = bpm_createprocess("AU_EQUIPMENT_MAINT","", user,1)
                         comm = "Maintenance Tasks"
                         call UpdateField("AU_PROCESS",__au_process,"COMM",comm,"ROLE_OWNER","TECHNICIAN","")
                         endif

                         comm = strcat(title, "/", descr)

                         start_sql "*" "KOSMOS"
                         INSERT INTO AU_STEP
                         end_sql
                         q1 = QueryByName()
                         call TSetFld(q1,"REL_CODE","String",date_var)
                         call TExecute(q1)
                         call FreeEmbSQL(q1)
                         step_id = SelectIdentity()

                         call bpm_setstepcomment(comm)
                         call bpm_setstepgood(id)
                         call bpm_setstepid(step_id)
                         call bpm_assign_job ( "Maintenance Task" ,"" ,"TECHNICIAN" , days , step_id )

                 endif

                 endif

                 if (step_id = 0) then         {no activity has been yet created}

                        if ( __au_process = 0) then {if process does not exist create it}
                         __au_process = bpm_createprocess("AU_EQUIPMENT_MAINT","", user,1)
                         comm = "Maintenance Tasks"
                         call UpdateField("AU_PROCESS",__au_process,"COMM",comm,"ROLE_OWNER","ΤΕΧΝΙΚΟΣ ΣΥΝΤΗΡΗΣΗΣ","")
                        endif

                        comm = strcat(title, "/", descr)

                        start_sql "*" "KOSMOS"
                         INSERT INTO AU_STEP
                        end_sql
                        q1 = QueryByName()
                        call TSetFld(q1,"REL_CODE","String",date_var)
                        call TExecute(q1)
                        call FreeEmbSQL(q1)
                        step_id = SelectIdentity()

                        call bpm_setstepcomment(comm)                                                                                                
                        call bpm_setstepgood(id)
                        call bpm_setstepid(step_id)
                        call bpm_assign_job ( "Maintenance Task" ,"" ,"TECHNICIAN" , days , step_id )

                 endif

                 endif

         next

         call TNext(q)
         next
         call FreeEmbSQL(q)

     endif

     return {....fsm must never reach end_action }

end_action