start_agent_info
AgentName = "AU_PURCHASE_COORDINATOR2"
AgentDescr = "Purchase Coordinator"
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 "New Purchase Order"
start_bpm_subactivity "Purchase Form"
rec = __params[1]
expr = strcat
(rec
,"=AU_EVENT"
)
call OpenFormTop
("ptEdit"
,"
AU_EVENT_GOODSIN2_E.FM"
,"WORK.AU_EVENT"
,1
,expr
)
end_bpm_subactivity
end_bpm_activity
start_bpm_activity "Purchase Approval 1"
start_bpm_subactivity "Purchase Form"
rec = __params[1]
call OnOpenForm_DisableAllFields
()
call OnOpenForm_EnableField
("APPROVER1_YES"
)
call OnOpenForm_EnableField
("APPROVER1_NO"
)
expr = strcat
(rec
,"=AU_EVENT"
)
call OpenFormTop
("ptEdit"
,"
AU_EVENT_GOODSIN2_E.FM"
,"WORK.AU_EVENT"
,1
,expr
)
end_bpm_subactivity
start_bpm_validation
result = 1
yes = LookUpId
("AU_EVENT"
,__params[1]
,"APPROVER1_YES"
)
no = LookUpId
("AU_EVENT"
,__params[1]
,"APPROVER1_NO"
)
yes = val
(yes
)
no = val
(no
)
if (no = 0
) and
(yes = 0
) then
result = 0
call message
("Approve or disapprove purchase !"
)
endif
if (no = 1
) and
(yes = 1
) then
result = 0
call message
("Approve or disapprove purchase !"
)
endif
if (no = 1
) then
flag = message_yes_no
("You selected
to disapprove the purchase ?"
)
if (flag = 0
) then
result = 0
endif
endif
end_bpm_validation
end_bpm_activity
start_bpm_activity "Purchase Approval 2"
start_bpm_subactivity "Purchase Form"
prom_type = __params[1]
rec = __params[2]
form = __params[3]
call OnOpenForm_DisableAllFields
()
call OnOpenForm_EnableField
("APPROVER2_YES"
)
call OnOpenForm_EnableField
("APPROVER2_NO"
)
call OnOpenForm_EnableField
("F_APPROVER3_POS_D"
)
expr = strcat
(rec
,"=AU_EVENT"
)
call OpenFormTop
("ptEdit"
,form
,"WORK.AU_EVENT"
,1
,expr
)
end_bpm_subactivity
start_bpm_validation
result = 1
yes = LookUpId
("AU_EVENT"
,__params[2]
,"APPROVER2_YES"
)
no = LookUpId
("AU_EVENT"
,__params[2]
,"APPROVER2_NO"
)
yes = val
(yes
)
no = val
(no
)
if (no = 0
) and
(yes = 0
) then
result = 0
call message
("Approve or disapprove purchase !"
)
endif
if (no = 1
) and
(yes = 1
) then
result = 0
call message
("Approve or disapprove purchase !"
)
endif
if (no = 1
) then
flag = message_yes_no
("You selected
to disapprove the purchase ?"
)
if (flag = 0
) then
result = 0
endif
endif
end_bpm_validation
end_bpm_activity
start_bpm_activity "Purchase Approval 3"
start_bpm_subactivity "Purchase Form"
prom_type = __params[1]
rec = __params[2]
form = __params[3]
call OnOpenForm_DisableAllFields
()
call OnOpenForm_EnableField
("APPROVER3_YES"
)
call OnOpenForm_EnableField
("APPROVER3_NO"
)
expr = strcat
(rec
,"=AU_EVENT"
)
call OpenFormTop
("ptEdit"
,form
,"WORK.AU_EVENT"
,1
,expr
)
end_bpm_subactivity
start_bpm_validation
result = 1
yes = LookUpId
("AU_EVENT"
,__params[2]
,"APPROVER3_YES"
)
no = LookUpId
("AU_EVENT"
,__params[2]
,"APPROVER3_NO"
)
yes = val
(yes
)
no = val
(no
)
if (no = 0
) and
(yes = 0
) then
result = 0
call message
("Approve or disapprove purchase !"
)
endif
if (no = 1
) and
(yes = 1
) then
result = 0
call message
("Approve or disapprove purchase !"
)
endif
if (no = 1
) then
flag = message_yes_no
("You selected
to disapprove the purchase ?"
)
if (flag = 0
) then
result = 0
endif
endif
end_bpm_validation
end_bpm_activity
start_bpm_activity "S
end Order
to supplier"
start_bpm_subactivity "View Mailed Order"
rec = __params[1]
flag = __contact_form_processing
flag = val
(flag
)
if (__contact_form_processing = 1
) then
{ __s
ending_email = "" }
start_sql "*" "KOSMOS"
SELECT AU_GOOD_CODE.CODE
, AU_GOOD_CODE.DESCR
, AU_KE_GOOD.QUANT
, AU_UNITMEAS.CODE
AS UCODE
,
AU_KE_GOOD.AU_KE_GOOD
, AU_KE_GOOD.AU_GOOD_CODE
, AU_KE_GOOD.COMMENT
FROM (AU_KE_GOOD INNER
JOIN AU_UNITMEAS
ON AU_KE_GOOD.AU_UNITMEAS = AU_UNITMEAS.AU_UNITMEAS
)
INNER
JOIN AU_GOOD_CODE
ON AU_KE_GOOD.AU_GOOD_CODE = AU_GOOD_CODE.AU_GOOD_CODE
WHERE (AU_EVENT=:E
)
ORDER BY AU_KE_GOOD
end_sql
q = QueryByName
()
call TSetParam
(q
,"E"
,rec
)
call TExecute
(q
)
count = TRecordCount
(q
)
col = dcol_start
("Order From"
,__au_contact
,__au_step
,__au_process
)
call TFirst
(q
)
for i = 1
to count
ke_id = TGetFld
(q
,"AU_KE_GOOD"
)
gd_id = TGetFld
(q
,"AU_GOOD_CODE"
)
code = TGetFld
(q
,"CODE"
)
title = TGetFld
(q
,"DESCR"
)
meas = TGetFld
(q
,"UCODE"
)
quant = TGetFld
(q
,"QUANT"
)
comm = TGetFld
(q
,"COMMENT"
)
call dcol_item
(col
,"Product ID"
,"AU_GOOD_CODE"
,"CODE"
,code
,gd_id
,i
,1
,2
)
call dcol_item
(col
,"Description"
,"AU_GOOD_CODE"
,"DESCR"
,title
,gd_id
,i
,1
,6
)
call dcol_item
(col
,"UoM"
,"AU_UNITMEAS"
,"CODE"
,meas
,ke_id
,i
,1
,1
)
call dcol_item
(col
,"Quantity"
,"AU_KE_GOOD"
,"QUANT"
,quant
,ke_id
,i
,1
,1
)
call dcol_item
(col
,"Delivery"
,"AU_KE_GOOD"
,"COMMENT"
,comm
,ke_id
,i
,0
,2
)
call TNext
(q
)
next
call FreeEmbSQL
(q
)
call html_processfile
("AU_PURCHORDER_EN.HTM"
, col
, __au_step
, __postforward
, rec
)
endif
if (flag = 0
) then
if (__params[2] > 0
) then
call OpenContactForm
()
else
call message
("There is no mailed Form
for this Purchase!"
)
endif
endif
end_bpm_subactivity
start_bpm_subactivity "Purchase Form"
rec = __params[1]
call OnOpenForm_DisablePost
()
expr = strcat
(rec
,"=AU_EVENT"
)
call OpenFormTop
("ptEdit"
,"
AU_EVENT_GOODSIN2_E.FM"
,"WORK.AU_EVENT"
,1
,expr
)
end_bpm_subactivity
end_bpm_activity
start_bpm_activity "Purchase Order"
start_bpm_subactivity "Purchase Form"
rec = __params[1]
call OnOpenForm_DisablePost
()
expr = strcat
(rec
,"=AU_EVENT"
)
call OpenFormTop
("ptEdit"
,"
AU_EVENT_GOODSIN2_E.FM"
,"WORK.AU_EVENT"
,1
,expr
)
end_bpm_subactivity
end_bpm_activity
start_bpm_activity "Goods Receipt"
start_bpm_subactivity "New Supplier Invoice"
rec = __params[1]
call OpenForm
("ptApp
end"
,"
AU_PURCHASE_GOODRECEIPT_E.FM"
,"WORK.AU_EVENT"
,1
,"?=AU_EVENT"
,rec
)
end_bpm_subactivity
start_bpm_subactivity "Delivered Goods"
rec = __params[1]
call OpenFormTop
("ptBrowse"
,"
AU_PURCHASE_GOODRECEIPT_B.FM"
,"QRY.DATA"
,"PORDER_MODE"
,rec
)
end_bpm_subactivity
start_bpm_subactivity "Purchase Form"
rec = __params[1]
call OnOpenForm_DisablePost
()
expr = strcat
(rec
,"=AU_EVENT"
)
call OpenFormTop
("ptEdit"
,"
AU_EVENT_GOODSIN2_E.FM"
,"WORK.AU_EVENT"
,1
,expr
)
end_bpm_subactivity
end_bpm_activity
start_bpm_activity "Approved Purchase"
start_bpm_subactivity "Purchase Form"
rec = __params[1]
call OnOpenForm_DisablePost
()
expr = strcat
(rec
,"=AU_EVENT"
)
call OpenFormTop
("ptEdit"
,"
AU_EVENT_GOODSIN2_E.FM"
,"WORK.AU_EVENT"
,1
,expr
)
end_bpm_subactivity
start_bpm_subactivity "Delivered Goods"
rec = __params[1]
call OpenFormTop
("ptBrowse"
,"
AU_PURCHASE_GOODRECEIPT_B.FM"
,"QRY.DATA"
,"PORDER_MODE"
,rec
)
end_bpm_subactivity
start_bpm_subactivity "Purchase Cover"
rec = __params[1]
call OpenFormTop
("ptBrowse"
,"
AU_PURCHASE_COVER_B.FM"
,"QRY.DATA"
,"PORDER_MODE"
,rec
)
end_bpm_subactivity
end_bpm_activity
start_bpm_activity "Purchase Approval 1"
start_bpm_subactivity "Form"
prom_type = __params[1]
rec = __params[2]
form = __params[3]
call OnOpenForm_DisableAllFields
()
expr = strcat
(rec
,"=AU_EVENT"
)
call OpenFormTop
("ptEdit"
,form
,"WORK.AU_EVENT"
,1
,expr
)
end_bpm_subactivity
start_bpm_validation
result = 1
yes = LookUpId
("AU_EVENT"
,__params[2]
,"APPROVER1_YES"
)
no = LookUpId
("AU_EVENT"
,__params[2]
,"APPROVER1_NO"
)
yes = val
(yes
)
no = val
(no
)
if (no = 0
) and
(yes = 0
) then
result = 0
call message
("Approve or disapprove purchase !"
)
endif
if (no = 1
) and
(yes = 1
) then
result = 0
call message
("Approve or disapprove purchase !"
)
endif
if (no = 1
) then
flag = message_yes_no
("You selected
to disapprove the purchase ?"
)
if (flag = 0
) then
result = 0
endif
endif
end_bpm_validation
end_bpm_activity
start_bpm_activity "Prices Control"
start_bpm_subactivity "Purchase Form"
prom_type = __params[1]
rec = __params[2]
form = __params[3]
call OnOpenForm_DisablePost
()
expr = strcat
(rec
,"=AU_EVENT"
)
call OpenFormTop
("ptEdit"
,form
,"WORK.AU_EVENT"
,1
,expr
)
end_bpm_subactivity
start_bpm_subactivity "Prices Comments"
call message
("Add Notes or attach a
document with prices commenting!"
)
end_bpm_subactivity
end_bpm_activity
start_bpm_activity "Purchase Cover"
start_bpm_subactivity "Purchase Form"
rec = __params[1]
call OnOpenForm_DisablePost
()
expr = strcat
(rec
,"=AU_EVENT"
)
call OpenFormTop
("ptEdit"
,"
AU_EVENT_GOODSIN2_E.FM"
,"WORK.AU_EVENT"
,1
,expr
)
end_bpm_subactivity
start_bpm_subactivity "Purchase Cover"
rec = __params[1]
call OpenFormTop
("ptBrowse"
,"
AU_PURCHASE_COVER_B.FM"
,"QRY.DATA"
,"PORDER_MODE"
,rec
)
end_bpm_subactivity
end_bpm_activity
start_bpm_activity "Wait
for Products"
start_bpm_subactivity "Purchase Form"
rec = __params[1]
call OnOpenForm_DisablePost
()
expr = strcat
(rec
,"=AU_EVENT"
)
call OpenFormTop
("ptEdit"
,"
AU_EVENT_GOODSIN2_E.FM"
,"WORK.AU_EVENT"
,1
,expr
)
end_bpm_subactivity
end_bpm_activity
start_action
{...........purchase coordinator....}
rec_id = __params[1]
call bpm_setprocedureowner
(__activation_user
) {.....set the procedure owner}
call bpm_setprocedurecomment
("Purchase Order"
) {.....set the procedures comment}
call bpm_addcheckpoint
( "Edit Purchase Order"
, 1
)
call bpm_addcheckpoint
( "Approved Purchase Order"
, 1
)
call bpm_addcheckpoint
( "S
end Purchase Order"
, 1
)
call bpm_addcheckpoint
( "Wait
for Products"
, 1
)
call bpm_addcheckpoint
( "Wait
for Remaining Products"
, 1
)
call bpm_addcheckpoint
( "Goods Receipt"
, 1
)
user_id = SelectFrom
("
SELECT AU_USER
FROM AU_USER
WHERE (UNAME=''''"
,__activation_user
,"''''
)"
)
call UpdateTable
("AU_EVENT"
, rec_id
, "AU_PROCESS"
, __au_process
, "REQUESTER"
, user_id
)
start_sql "*" "KOSMOS"
SELECT CR_ID
FROM AU_KE_GOOD
WHERE (CR_NAME='AU_EVENT_PURCH'
) AND (AU_EVENT = :EV
)
end_sql
q = QueryByName
()
call TSetParam
(q
,"EV"
,rec_id
)
call TExecute
(q
)
count = TRecordCount
(q
)
call TFirst
(q
)
for i = 1
to count
id = TGetFld
(q
,"CR_ID"
)
call UpdateTable
("AU_EVENT_PURCH"
, id
, "AU_PROCESS"
, __au_process
)
call bpm_statusenroll
( id
, "AU_EVENT_PURCH"
, "STAT"
)
call TNext
(q
)
next
call FreeEmbSQL
(q
)
call bpm_setcheckpoint
( "Edit Purchase Order"
, 1
)
str = SelectFrom
("
SELECT SUBJECT
, BUSINESS_FROM
, APPROVER1
, CONTACT_FROM
, APPROVER1_YES
, APPROVER1_NO
FROM AU_EVENT
WHERE (AU_EVENT="
,rec_id
,"
)"
)
comm = GetSQLSelectItem
(str
,1
)
business_id = GetSQLSelectItem
(str
,2
)
appr_id = GetSQLSelectItem
(str
,3
)
supl_cont_id = GetSQLSelectItem
(str
,4
)
yes1 = GetSQLSelectItem
(str
,5
)
no1 = GetSQLSelectItem
(str
,6
)
appr_name = LookUpId
("AU_POS"
,appr_id
,"POS_D"
)
simple_flag = GetParameter
("AU_PURCHASE_COORDINATOR2_SIMPLEFLAG"
)
call bpm_setprocedurecomment
(comm
) {.....set the procedures comment}
call bpm_setprocedurebusiness
(business_id
)
{.....................First approval....................}
if (yes1 <> 1
) then
callwait bpm_assign_job
( "Purchase Approval 1"
, ""
, appr_name
, 0
, rec_id
)
str = SelectFrom
("
SELECT SUBJECT
, BUSINESS_FROM
, APPROVER1
, CONTACT_FROM
, APPROVER1_YES
, APPROVER1_NO
FROM AU_EVENT
WHERE (AU_EVENT="
,rec_id
,"
)"
)
comm = GetSQLSelectItem
(str
,1
)
business_id = GetSQLSelectItem
(str
,2
)
appr_id = GetSQLSelectItem
(str
,3
)
supl_cont_id = GetSQLSelectItem
(str
,4
)
yes1 = GetSQLSelectItem
(str
,5
)
no1 = GetSQLSelectItem
(str
,6
)
endif
call bpm_setcheckpoint
( "Approved Purchase Order"
, 1
)
approved_flag = True {....suppose its approved}
if (no1 = 1
) then
approved_flag = False
endif
if (approved_flag = True
) then
{.................S
end order
to the supplier............................}
if (supl_cont_id > 0
) then
call bpm_setactivitycontact
(supl_cont_id
)
call bpm_setsteppostforward
()
endif
callwait bpm_assign_job
( "S
end Order
to supplier"
, __activation_user
, ""
, 0
, rec_id
, supl_cont_id
)
if (simple_flag = 0
) then
call bpm_setcheckpoint
( "S
end Purchase Order"
, 1
)
{.................cashier involvement..................}
cashier_comm = LookUpId
("AU_EVENT"
,rec_id
,"COMM_CASHIER_INFO"
)
if (cashier_comm <> ""
) then
call bpm_assign_job
( "Purchase Order"
, ""
, "Cashier"
, 0
, pr_type
, rec_id
, form
)
endif
{...................receipt of goods and invoice............................}
receipt_pos = LookUpId
("AU_EVENT"
,rec_id
,"DELIVERED_TO"
)
receipt_pos = LookUpId
("AU_POS"
,receipt_pos
,"POS_D"
)
for i = 1
to 100
if (i = 1
) then
call bpm_setcheckpoint
( "Wait
for Products"
, 1
)
else
call bpm_setcheckpoint
( "Wait
for Remaining Products"
, 1
)
endif
callwait bpm_assign_job
( "Wait
for Products"
, ""
, receipt_pos
, 0
, rec_id
)
if (i = 1
) then
call bpm_assign_job
( "Approved Purchase"
, ""
, "Accounting_Department"
, 0
, rec_id
)
endif
call bpm_setcheckpoint
( "Goods Receipt"
, 1
)
callwait bpm_assign_job
( "Goods Receipt"
, ""
, "Procurement_Department"
, 0
, rec_id
)
sql = "
SELECT COUNT
(AU_EVENT_PURCH.DONE_FLAG
) AS CNT
FROM AU_EVENT_PURCH "
sql = strcat
(sql
,"
WHERE (AU_EVENT_PURCH.DONE_FLAG='0'
) AND (AU_EVENT_PURCH.ORDER_EVENT="
,rec_id
,"
)"
)
flag = SelectFrom
(sql
)
flag = val
(flag
)
if (flag = 0
) then
i = 100
endif
next
endif
if (simple_flag = 1
) then
call bpm_setcheckpoint
( "Goods Receipt"
, 1
)
callwait bpm_assign_job
( "Goods Receipt"
, ""
, "Procurement_Department"
, 0
, rec_id
)
endif
endif
end_action