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_PURCH_ORDER_SCHEDULER

AutoScript

start_agent_info
   AgentName = "AU_PURCH_ORDER_SCHEDULER"
   AgentDescr = ""
   AgentLanguage = ""
   __timer_interval = 600 {....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

   call trace("AU_PURCH_ORDER_SCHEDULER - out - _TraversingHour=",_TraversingHour)
   call trace("_CurrentDate_Num=",_CurrentDate_Num," fired_date=",fired_date)

   {..................Check for products reordering ..........}

   when ( _TraversingHour = 8 ) and ((_CurrentDate_Num > fired_date) or (fired_date = 0)) do
                                                        
       start_sql "*" "KOSMOS"
         SELECT AU_GOOD_SUM.QUANT, AU_GOOD_SUM.QUANT_P, AU_GOOD_SUM.YA_POS,
         AU_GOOD_SUM.AU_UNITMEAS, AU_GOOD_SUM.AU_GOOD, AU_GOOD_SUM.AU_GOOD_SUM,
         AU_GOOD.POS_ANAPAR_PROM , AU_GOOD.SUPPLIER , AU_GOOD.MIN_STOCK
         FROM AU_GOOD_SUM, AU_GOOD
         WHERE (AU_GOOD.AU_GOOD = AU_GOOD_SUM.AU_GOOD) AND
         (AU_GOOD_SUM.REC_TYPE = "0") AND (AU_GOOD_SUM.AU_WAREHOUSE = :W)
       end_sql
       q0 = QueryByName()
       whouse_id = GetParameter("AU_MAINWAREHOUSE")              
       call TSetParam(q0,"W",whouse_id)
       call TExecute(q0)
       count0 = TRecordCount(q0)

       call TFirst(q0)
       for j = 1 to count0
         q_min = TGetFld(q0,"MIN_STOCK")
         qu1 = TGetFld(q0,"QUANT")                        
         qu2 = TGetFld(q0,"QUANT_P")
         qu3 = TGetFld(q0,"YA_POS")
         quant = qu1 + qu2 + qu3

         q_reorder = TGetFld(q0,"POS_ANAPAR_PROM")
         business_id = TGetFld(q0,"SUPPLIER")
         good_id = TGetFld(q0,"AU_GOOD")
         qood_code_id = 0 {TGetFld(q0,"")}
         umeas        = TGetFld(q0,"AU_UNITMEAS")
         diff         = q_min - quant

descr = SelectFrom("SELECT TITLE FROM AU_GOOD WHERE (AU_GOOD=",good_id,")")
call trace(descr,", q_min=",q_min," qu1=",qu1," qu2=",qu2," qu3=",qu3," quant=",quant," q_reorder=",q_reorder," diff=",diff)
         if (diff > 0) and (q_reorder > 0) then

         {quant = ConvertGoodUnits ( quant, good_id, from_un, to_un ) }

         t = OpenTable("AU_EVENT_PURCH")

         call TAppend(t)
         call TSetFld(t,"AU_BUSINESS",business_id)                                
         call TSetFld(t,"AU_GOOD_CODE",good_code_id)
         call TSetFld(t,"QUANT",q_reorder)
         call TSetFld(t,"AU_UNITMEAS",umeas)
         call TSetFld(t,"SDATE1",crDate)
         call TSetFld(t,"AU_GOOD",good_id)
         call TSetFld(t,"DONE_FLAG","0")
         call TSetFld(t,"RSOURCE","SCH-TIMER")
         call TPost(t)
   call trace("AU_BUSINESS=",business_id," QUANT=",q_reorder," AU_UNITMEAS=",umeas," AU_GOOD=",good_id)

         call CloseTable(t)

         endif
                                
         call TNext(q0)
       next
       call FreeEmbSQL(q0)

   endwhen

end_action