[Home] [Help]
PACKAGE BODY: APPS.AS_SALES_LEAD_AGING_WF_PUB
Source
1 PACKAGE BODY AS_SALES_LEAD_AGING_WF_PUB AS
2 /* $Header: asxslagb.pls 115.2 2002/11/06 00:49:47 appldev ship $ */
3
4 ------------------------
5 -- Constants Definition
6 ------------------------
7
8 -- Workflow status flags
9 C_WORKFLOW_APPROVED_SAVED CONSTANT VARCHAR2(1) := 'S';
10 C_WORKFLOW_APPROVED_REJECTED CONSTANT VARCHAR2(1) := 'R';
11
12 -- Start from process from abandon, reassign
13 C_START_FROM_REASSIGN CONSTANT VARCHAR2(40) := 'AS_REASSIGN';
14 C_START_FROM_ABANDON CONSTANT VARCHAR2(40) := 'AS_ABANDON';
15 C_START_FROM_PASS CONSTANT VARCHAR2(40) := 'AS_PASS';
16 C_START_FROM_ERROR CONSTANT VARCHAR2(40) := 'ERROR';
17
18
19 PROCEDURE StartSalesLeadAgingProcess(
20 p_request_id IN NUMBER,
21 p_sales_lead_id IN NUMBER,
22 p_assigned_resource_id IN NUMBER,
23 p_aging_days_noact IN NUMBER,
24 p_aging_days_abandon IN NUMBER,
25 p_aging_abandon_actions IN VARCHAR2,
26 p_aging_noact_actions IN VARCHAR2,
27 x_item_type OUT VARCHAR2,
28 x_item_key OUT VARCHAR2,
29 x_return_status OUT VARCHAR2 )
30 IS
31 l_item_type VARCHAR2(100) := 'ASXSLAG';
32 l_item_key VARCHAR2(100) := to_char(p_request_id);
33 l_status VARCHAR2(80);
34 l_result VARCHAR2(80);
35 l_debug_info VARCHAR2(200);
36 workflowprocess VARCHAR2(30) := 'AS_SALES_LEAD_AGING_PROCESS';
37
38 BEGIN
39
40 -- dbms_output.put_line ('Startprocess ');
41
42 WF_ENGINE.CreateProcess(
43 itemtype => l_item_type,
44 itemkey => l_item_key,
45 process => workflowprocess);
46
47
48 WF_ENGINE.SetItemAttrNumber(
49 itemtype => l_item_type,
50 itemkey => l_item_key,
51 aname => 'SALES_LEAD_ID',
52 avalue => p_sales_lead_id);
53
54 WF_ENGINE.SetItemAttrNumber(
55 itemtype => l_item_type,
56 itemkey => l_item_key,
57 aname =>'DAYS_TO_ACCEPT',
58 avalue => p_aging_days_noact);
59
60 WF_ENGINE.SetItemAttrNumber(
61 itemtype => l_item_type,
62 itemkey => l_item_key,
63 aname =>'DAYS_TO_ABANDON',
64 avalue => p_aging_days_abandon);
65
66 WF_ENGINE.SetItemAttrText(
67 itemtype => l_item_type,
68 itemkey => l_item_key,
69 aname =>'AGING_ABANDON_ACTIONS',
70 avalue => p_aging_abandon_actions);
71
72 WF_ENGINE.SetItemAttrText (
73 itemtype => l_item_type,
74 itemkey => l_item_key,
75 aname =>'AGING_NOACT_ACTIONS',
76 avalue => p_aging_noact_actions);
77
78 wf_engine.SetItemAttrNumber (
79 itemtype => l_item_type,
80 itemkey => l_item_key,
81 aname => 'ASSIGN_ID',
82 avalue => p_assigned_resource_id);
83
84 wf_engine.AddItemAttr(
85 itemtype => l_item_type,
86 itemkey => l_item_key,
87 aname => 'ORIG_RESOURCE_ID',
88 number_value => p_assigned_resource_id);
89
90 wf_engine.AddItemAttr(
91 itemtype => l_item_type,
92 itemkey => l_item_key,
93 aname => 'RESOURCE_ID',
94 number_value => p_assigned_resource_id);
95
96 wf_engine.AddItemAttr(
97 itemtype => l_item_type,
98 itemkey => l_item_key,
99 aname => 'BUSINESS_GROUP_ID',
100 number_value => 0);
101
102 WF_ENGINE.StartProcess (
103 itemtype => l_item_type,
104 itemkey => l_item_key );
105
106 -- Remove the Background() call when finished testing...
107 /*
108 wf_engine.Background (
109 itemtype => l_item_type,
110 minthreshold => null,
111 maxthreshold => null,
112 process_deferred => TRUE,
113 process_timeout => TRUE);
114
115 wf_engine.Background (
116 itemtype => 'ASXLABDW',
117 minthreshold => null,
118 maxthreshold => null,
119 process_deferred => TRUE,
120 process_timeout => TRUE);
121 */
122
123 WF_ENGINE.ItemStatus(
124 itemtype => l_item_type,
125 itemkey => l_item_key,
126 status => l_status,
127 result => l_result);
128
129 x_item_type := l_item_type;
130 x_item_key := l_item_key;
131 x_return_status := l_result ;
132
133 EXCEPTION
134 when others then
135 wf_core.context('AS_SALES_LEAD_AGING_WF_PUB',
136 'StartSalesLeadAgingProcess',
137 workflowprocess, l_item_key );
138 raise;
139
140 END StartSalesLeadAgingProcess;
141
142
143 PROCEDURE DetermineStartFromProcess(
144 itemtype in VARCHAR2,
145 itemkey in VARCHAR2,
146 actid in NUMBER,
147 funcmode in VARCHAR2,
148 result out VARCHAR2 )
149 IS
150 CURSOR c_sales_lead (x_sales_lead_id NUMBER) IS
151 SELECT sales_lead_id
152 ,creation_date
153 ,assign_date
154 ,accept_flag
155 ,status_code
156 FROM as_sales_leads
157 WHERE sales_lead_id = x_sales_lead_id;
158
159 l_start_from_process VARCHAR2(40);
160 l_debug_info VARCHAR2(200);
161 l_sales_lead_rec Sales_Lead_Rec_Type;
162
163 l_sales_lead_id NUMBER;
164 l_aging_days_noact NUMBER;
165 l_aging_days_abandon NUMBER;
166 l_aging_abandon_actions VARCHAR2(240);
167 l_aging_noact_actions VARCHAR2(240);
168
169 -- delete later
170 l_datediff NUMBER;
171 l_datedifftest BOOLEAN;
172 BEGIN
173 -- dbms_output.put_line('DetermineStartFromProcess: '|| funcmode);
174
175 IF (funcmode = 'RUN') THEN
176
177 l_sales_lead_id := WF_ENGINE.GetItemAttrNumber(itemtype, itemkey,
178 'SALES_LEAD_ID');
179
180 l_aging_days_noact := WF_ENGINE.GetItemAttrNumber(itemtype, itemkey,
181 'DAYS_TO_ACCEPT');
182
183 l_aging_days_abandon := WF_ENGINE.GetItemAttrNumber(itemtype, itemkey,
184 'DAYS_TO_ABANDON');
185 l_aging_abandon_actions := WF_ENGINE.GetItemAttrText(itemtype, itemkey,
186 'AGING_ABANDON_ACTIONS');
187
188 l_aging_noact_actions := WF_ENGINE.GetItemAttrText(itemtype, itemkey,
189 'AGING_NOACT_ACTIONS');
190
191 OPEN c_sales_lead(l_sales_lead_id);
192 FETCH c_sales_lead INTO
193 l_sales_lead_rec.sales_lead_id,
194 l_sales_lead_rec.creation_date,
195 l_sales_lead_rec.assign_date,
196 l_sales_lead_rec.accept_flag,
197 l_sales_lead_rec.status_code;
198
199 result := 'COMPLETE:'||C_START_FROM_PASS;
200
201 IF c_sales_lead%FOUND
202 THEN
203 l_datediff := sysdate - l_sales_lead_rec.assign_date ;
204 IF l_datediff > l_aging_days_noact
205 THEN
206 IF upper(l_aging_noact_actions) = 'ABANDON'
207 THEN
208 result := 'COMPLETE:' || C_START_FROM_ABANDON;
209 ELSIF upper(l_aging_noact_actions) = 'REASSIGN'
210 OR upper(l_aging_noact_actions) = 'RECYCLE'
211 THEN
212 result := 'COMPLETE:' || C_START_FROM_REASSIGN;
213 END IF;
214 END IF;
215
216 IF l_sales_lead_rec.assign_date IS NOT NULL AND result IS NULL
217 THEN
218 IF (l_datediff > l_aging_days_abandon)
219 AND (nvl(l_sales_lead_rec.accept_flag,'NULL') <> 'Y')
220 THEN
221 IF upper(l_aging_noact_actions) = 'ABANDON'
222 THEN
223 result := 'COMPLETE:' || C_START_FROM_ABANDON;
224 ELSIF upper(l_aging_noact_actions) = 'REASSIGN'
225 OR upper(l_aging_noact_actions) = 'RECYCLE'
226 THEN
227 result := 'COMPLETE:' || C_START_FROM_REASSIGN;
228 END IF;
229 END IF;
230 ELSE -- assign date IS null
231 l_datediff := sysdate - l_sales_lead_rec.creation_date ;
232 IF (l_datediff > l_aging_days_abandon)
233 AND (nvl(l_sales_lead_rec.accept_flag,'NULL') <> 'Y')
234 THEN
235 IF upper(l_aging_noact_actions) = 'ABANDON'
236 THEN
237 result := 'COMPLETE:' || C_START_FROM_ABANDON;
238 ELSIF upper(l_aging_noact_actions) = 'REASSIGN'
239 OR upper(l_aging_noact_actions) = 'RECYCLE'
240 THEN
241 result := 'COMPLETE:' || C_START_FROM_REASSIGN;
242 END IF;
243 END IF;
244 END IF;
245 ELSE
246 result := 'COMPLETE:'||C_START_FROM_ERROR;
247 END IF;
248 CLOSE c_sales_lead;
249
250 ELSIF (funcmode = 'CANCEL')
251 THEN
252 result := 'COMPLETE';
253 END IF;
254
255 -- dbms_output.put_line('Result: '||result);
256
257 EXCEPTION
258 when others then
259 result := 'COMPLETE:'||C_START_FROM_ERROR;
260 wf_core.context('AS_SALES_LEAD_AGING_WF_PUB',
261 'DetermineStartFromProcess',
262 itemtype, itemkey, to_char(actid), funcmode);
263 raise;
264
265 END DetermineStartFromProcess;
266
267 END AS_SALES_LEAD_AGING_WF_PUB;
268