[Home] [Help]
PACKAGE BODY: APPS.MSC_GANTT_UTILS
Source
1 PACKAGE BODY MSC_GANTT_UTILS AS
2 /* $Header: MSCGNTUB.pls 120.61.12010000.3 2008/07/31 12:50:55 skakani ship $ */
3
4 g_plan_cal varchar2(50);
5 g_plan_cal_inst_id number;
6 g_plan_cal_excp_id number;
7 g_plan_cal_from_profile varchar2(50);
8 g_plan_inst_id number;
9 g_plan_org_id number;
10
11 g_plan_id number;
12 g_plan_type number;
13
14 g_category_set_id number;
15 g_pref_id number;
16
17 --res act view - activity labels
18 g_gantt_act_label_1 number;
19 g_gantt_act_label_2 number;
20 g_gantt_act_label_3 number;
21
22 --res act view - batch activity labels
23 g_gantt_batches_label_1 number;
24 g_gantt_batches_label_2 number;
25 g_gantt_batches_label_3 number;
26
27 --order view - order labels
28 g_gantt_supply_orders_label_1 number;
29 g_gantt_supply_orders_label_2 number;
30 g_gantt_supply_orders_label_3 number;
31
32 --order view - operation labels
33 g_gantt_oper_label_1 number;
34 g_gantt_oper_label_2 number;
35 g_gantt_oper_label_3 number;
36
37 --order view - activity labels
38 g_gantt_res_act_label_1 number;
39 g_gantt_res_act_label_2 number;
40 g_gantt_res_act_label_3 number;
41
42 g_gantt_ra_toler_days_early number;
43 g_gantt_ra_toler_days_late number;
44
45 g_gantt_rh_toler_days_early number;
46 g_gantt_rh_toler_days_late number;
47
48 --job node labels
49 g_job_none_lbl constant number := 0;
50 g_job_item_lbl constant number := 1;
51 g_job_org_lbl constant number := 2;
52 g_job_order_number_lbl constant number := 3;
53 g_job_order_type_lbl constant number := 4;
54 g_job_qty_lbl constant number := 5;
55
56 -- op node lables
57 g_op_none_lbl constant number := 0;
58 g_op_seq_lbl constant number := 1;
59 g_op_dept_lbl constant number := 2;
60 g_op_desc_lbl constant number := 3;
61
62 -- res node labels - orders view
63 g_res_none_lbl constant number := 0;
64 g_res_seq_lbl constant number := 1;
65 g_res_dept_lbl constant number := 2;
66 g_res_lbl constant number := 3;
67 g_res_setup_lbl constant number := 4;
68 g_res_batch_lbl constant number := 5;
69 g_res_alt_flag_lbl constant number := 6;
70 g_res_units_lbl constant number := 7;
71
72 -- res node labels - res act view
73 g_res_act_none_lbl constant number := 0;
74 g_res_act_item_lbl constant number := 1;
75 g_res_act_setup_lbl constant number := 2;
76 g_res_act_org_lbl constant number := 3;
77 g_res_act_qty_lbl constant number := 4;
78 g_res_act_batch_lbl constant number := 5;
79 g_res_act_alt_flag_lbl constant number := 6;
80 g_res_act_units_lbl constant number := 7;
81 g_res_act_order_type_lbl constant number := 8;
82 g_res_act_op_sdesc_lbl constant number := 9;
83 g_res_act_op_seq_lbl constant number := 10;
84 g_res_act_req_comp_date_lbl constant number := 11;
85 g_res_act_order_number_lbl constant number := 12;
86
87 -- batched res node labels
88 g_batch_none_lbl constant number := 0;
89 g_batch_setup_lbl constant number := 1;
90 g_batch_org_lbl constant number := 2;
91 g_batch_qty_lbl constant number := 3;
92 g_batch_num_lbl constant number := 4;
93 g_batch_util_pct_lbl constant number := 5;
94
95 g_folder_res_field_name constant varchar2(50) := 'RESOURCE_ID';
96
97 -- cursors +
98 cursor active_res_rows_cur(p_query_id number) is
99 select mgq.row_index
100 from msc_gantt_query mgq
101 where query_id = p_query_id
102 and row_flag = sys_yes
103 order by 1;
104
105 cursor res_req_info (p_plan number, p_inst number, p_trx number) is
106 select mrr.firm_flag, mrr.firm_Start_date, mrr.firm_end_date, mrr.batch_number,
107 mrr.group_sequence_id, mrr.group_sequence_number
108 from msc_resource_requirements mrr
109 where mrr.plan_id = p_plan
110 and mrr.sr_instancE_id = p_inst
111 and mrr.transaction_id = p_trx
112 and nvl(mrr.parent_id, 2) = 2;
113
114 cursor res_inst_req_info (p_plan number, p_inst number, p_trx number) is
115 select mrir.batch_number
116 from msc_resource_instance_reqs mrir
117 where mrir.plan_id = p_plan
118 and mrir.sr_instancE_id = p_inst
119 and mrir.res_inst_transaction_id = p_trx
120 and nvl(mrir.parent_id, 2) = 2;
121
122 cursor simu_res_cur (p_plan number, p_inst number, p_trx number) is
123 select mrr2.transaction_id, mrr2.sr_instance_id
124 from msc_resource_requirements mrr1,
125 msc_resource_requirements mrr2
126 where mrr1.plan_id = p_plan
127 and mrr1.transaction_id = p_trx
128 and mrr1.sr_instance_id = p_inst
129 and mrr2.plan_id = mrr1.plan_id
130 and mrr2.sr_instance_id = mrr1.sr_instance_id
131 and mrr2.supply_id = mrr1.supply_id
132 and mrr2.operation_seq_num = mrr1.operation_seq_num
133 and mrr2.resource_seq_num = mrr1.resource_seq_num
134 and mrr2.alternate_num = mrr1.alternate_num
135 and mrr2.transaction_id <> mrr1.transaction_id
136 and mrr1.setup_id is null -- only non setup rows
137 and mrr1.schedule_flag = 1 -- only run req rows
138 and nvl(mrr2.parent_id,2) = 2;
139
140 cursor res_inst_cur (p_plan number, p_inst number, p_org number, p_dept number, p_res number)is
141 select mdr.owning_department_id department_id,
142 mdri.res_instance_id,
143 mdri.serial_number
144 from msc_dept_res_instances mdri,
145 msc_department_resources mdr
146 where mdr.plan_id = p_plan
147 and mdr.sr_instance_id = p_inst
148 and mdr.organization_id = p_org
149 and mdr.department_id = p_dept
150 and mdr.resource_id = p_res
151 and mdri.plan_id = mdr.plan_id
152 and mdri.sr_instance_id = mdr.sr_instance_id
153 and mdri.organization_id = mdr.organization_id
154 and mdri.department_id = nvl(mdr.owning_department_id, mdr.department_id)
155 and mdri.resource_id = mdr.resource_id;
156
157 cursor inst_res_cur (p_plan number, p_inst number, p_org number, p_dept number, p_res number,
158 p_res_instance number, p_serial_number varchar2 )is
159 select distinct mdr.department_id department_id
160 from msc_dept_res_instances mdri,
161 msc_department_resources mdr
162 where mdr.plan_id = p_plan
163 and mdr.sr_instance_id = p_inst
164 and mdr.organization_id = p_org
165 and mdr.department_id = p_dept
166 and mdr.resource_id = p_res;
167
168 cursor c_res_node_label (p_plan_id number, p_inst_id number, p_trx_id number) is
169 select msi.item_name,
170 nvl(decode(mrr.setup_id, to_number(null), null,
171 msc_gantt_utils.getSetupCode(mrr.plan_id,
172 mrr.sr_instance_id, mrr.resource_id, mrr.setup_id)), null) setup_type,
173 mtp.organization_code org_code,
174 ms.new_order_quantity qty,
175 mrr.batch_number,
176 msc_get_name.alternate_rtg(mrr.plan_id, mrr.sr_instance_id, mrr.routing_sequence_id) alt_rtg,
177 mrr.assigned_units,
178 msc_get_name.lookup_meaning('MRP_ORDER_TYPE', ms.order_type) order_type,
179 mro.operation_description op_sdesc,
180 mrr.operation_seq_num,
181 mrr.resource_seq_num,
182 ms.requested_completion_date req_comp_date,
183 msc_get_name.supply_order_number(ms.order_type, ms.order_number, ms.plan_id,
184 ms.sr_instance_id, ms.transaction_id, ms.disposition_id) order_number,
185 mdr.department_code,
186 mdr.resource_code
187 from msc_resource_requirements mrr,
188 msc_supplies ms,
189 msc_system_items msi,
190 msc_department_resources mdr,
191 msc_routing_operations mro,
192 msc_trading_partners mtp
193 where mrr.plan_id = ms.plan_id
194 and mrr.sr_instance_id = ms.sr_instance_id
195 and mrr.supply_id = ms.transaction_id
196 and ms.plan_id = msi.plan_id
197 and ms.sr_instance_id = msi.sr_instance_id
198 and ms.organization_id = msi.organization_id
199 and ms.inventory_item_id = msi.inventory_item_id
200 and ms.sr_instance_id = mtp.sr_instance_id
201 and ms.organization_id = mtp.sr_tp_id
202 and mtp.partner_type = 3
203 and mdr.plan_id = mrr.plan_id
204 and mdr.organization_id = mrr.organization_id
205 and mdr.sr_instance_id = mrr.sr_instance_id
206 and mdr.department_id = mrr.department_id
207 and mdr.resource_id = mrr.resource_id
208 and mrr.plan_id = mro.plan_id (+)
209 and mrr.sr_instance_id = mro.sr_instance_id (+)
210 and mrr.routing_sequence_id = mro.routing_sequence_id (+)
211 and mrr.operation_sequence_id = mro.operation_sequence_id (+)
212 and mrr.plan_id = p_plan_id
213 and mrr.sr_instance_id = p_inst_id
214 and mrr.transaction_id = p_trx_id;
215
216 -- cursors -
217
218 procedure put_line(p_string varchar2) is
219 begin
220 null;
221 --dbms_output.put_line(p_string);
222 end put_line;
223
224 function escapeSplChars(p_value varchar2) return varchar2 is
225 l_value varchar2(1000);
226 begin
227 l_value := p_value;
228 l_value := replace(l_value, FIELD_SEPERATOR, FIELD_SEPERATOR_ESC);
229 l_value := replace(l_value, RECORD_SEPERATOR, RECORD_SEPERATOR_ESC);
230 return l_value;
231 end escapeSplChars;
232
233 function get_child_res_trx_id(p_plan_id number, p_instance_id number,
234 p_res_trx_id number) return number is
235
236 cursor child_res_inst_info (p_plan number, p_inst number, p_trx number) is
237 select mrir.res_inst_transaction_id
238 from msc_resource_requirements mrr,
239 msc_resource_instance_reqs mrir
240 where mrr.plan_id = p_plan
241 and mrr.sr_instance_id = p_inst
242 and mrr.transaction_id = p_trx
243 and mrr.plan_id = mrir.plan_id
244 and mrr.sr_instance_id = mrir.sr_instance_id
245 and mrr.organization_id = mrir.organization_id
246 and mrr.department_id = mrir.department_id
247 and mrr.resource_id = mrir.resource_id
248 and mrr.supply_id = mrir.supply_id
249 and mrr.operation_seq_num = mrir.operation_seq_num
250 and mrr.resource_seq_num = mrir.resource_seq_num
251 and nvl(mrr.orig_resource_seq_num, mbp_null_value) = nvl(mrir.orig_resource_seq_num, mbp_null_value)
252 and nvl(mrr.parent_seq_num, mbp_null_value) = nvl(mrir.parent_seq_num, mbp_null_value)
253 and nvl(mrr.parent_id, mbp_null_value) = nvl(mrir.parent_id, mbp_null_value)
254 and nvl(mrr.firm_start_date, mrr.start_date) = mrir.start_date
255 and nvl(mrr.firm_end_date, mrr.end_date) = mrir.end_date
256 and nvl(mrir.parent_id,2) = 2;
257
258 l_trx_id number;
259 begin
260 put_line('get_child_res_trx_id p_plan_id p_instance_id p_res_trx_id '||
261 p_plan_id||' '||p_instance_id||' '||p_res_trx_id);
262 -- get the child_res_inst_info
263 open child_res_inst_info(p_plan_id, p_instance_id, p_res_trx_id);
264 fetch child_res_inst_info into l_trx_id;
265 close child_res_inst_info;
266 put_line('get_child_res_trx_id l_trx_id '||l_trx_id);
267 return l_trx_id;
268 end get_child_res_trx_id;
269
270
271 function get_parent_res_trx_id(p_plan_id number, p_instance_id number,
272 p_res_inst_trx_id number) return number is
273
274 cursor parent_res_info (p_plan number, p_inst number, p_trx number) is
275 select mrr.transaction_id
276 from msc_resource_requirements mrr,
277 msc_resource_instance_reqs mrir
278 where mrir.plan_id = p_plan
279 and mrir.sr_instance_id = p_inst
280 and mrir.res_inst_transaction_id = p_trx
281 and mrir.plan_id = mrr.plan_id
282 and mrir.sr_instance_id = mrr.sr_instance_id
283 and mrir.organization_id = mrr.organization_id
284 and mrir.department_id = mrr.department_id
285 and mrir.resource_id = mrr.resource_id
286 and mrir.supply_id = mrr.supply_id
287 and mrir.operation_seq_num = mrr.operation_seq_num
288 and mrir.resource_seq_num = mrr.resource_seq_num
289 and nvl(mrir.orig_resource_seq_num, mbp_null_value) = nvl(mrr.orig_resource_seq_num, mbp_null_value)
290 and nvl(mrir.parent_seq_num, mbp_null_value) = nvl(mrr.parent_seq_num, mbp_null_value)
291 and nvl(mrir.parent_id, mbp_null_value) = nvl(mrr.parent_id, mbp_null_value)
292 and mrir.start_date = nvl(mrr.firm_start_date, mrr.start_date)
293 and mrir.end_date = nvl(mrr.firm_end_date, mrr.end_date)
294 and nvl(mrr.parent_id,2) = 2;
295
296 l_trx_id number;
297 begin
298 open parent_res_info(p_plan_id, p_instance_id, p_res_inst_trx_id);
299 fetch parent_res_info into l_trx_id;
300 close parent_res_info;
301 return l_trx_id;
302 end get_parent_res_trx_id;
303
304 procedure populateRowKeysIntoGantt(p_query_id number,
305 p_index number, p_node_path varchar2, p_node_type number,
306 p_transaction_id number, p_inst_id number, p_org_id number,
307 p_dept_id number default null, p_res_id number default null,
308 p_op_seq_num varchar2 default null, p_op_seq_id number default null,
309 p_op_desc varchar2 default null, p_critical_flag number default null,
310 p_parent_link varchar2 default null, p_node_level number default null) is
311 begin
312
313 insert into msc_gantt_query (query_id,
314 last_update_date, last_updated_by, creation_date, created_by,
315 last_update_login, row_index, node_path, node_type, transaction_id,
316 sr_instance_id, organization_id, department_id, resource_id, critical_flag,
317 op_seq_id, op_seq_num, op_desc, parent_link, node_level )
318 values (p_query_id,
319 trunc(sysdate), -1, trunc(sysdate), -1, -1,
320 p_index, p_node_path, p_node_type, p_transaction_id, p_inst_id, p_org_id,
321 p_dept_id, p_res_id, p_critical_flag, p_op_seq_id, p_op_seq_num, p_op_desc,
322 p_parent_link, p_node_level);
323
324 end populateRowKeysIntoGantt;
325
326 procedure populateEndPegsMFQ(p_plan_id in number,
327 p_end_demand_id in number, p_query_id in number) is
328 begin
329
330 insert into msc_form_query (query_id,
331 last_update_date,
332 last_updated_by,
333 creation_date,
334 created_by,
335 last_update_login,
336 number1)
337 select
338 p_query_id,
339 sysdate, -1, sysdate, -1,-1,
340 mfp.end_pegging_id
341 from msc_full_pegging mfp
342 where mfp.plan_id = p_plan_id
343 and mfp.demand_id = p_end_demand_id;
344
345 end populateEndPegsMFQ;
346
347 procedure populateOrdersIntoGantt(p_plan_id number,
348 p_query_id number, p_mfq_query_id number) is
349
350 cursor c_mfq is
351 select distinct
352 ms.sr_instance_id,
353 ms.organization_id,
354 ms.transaction_id,
355 decode(ms.order_type,
356 14, COPROD_NODE,
357 15, COPROD_NODE,
358 16, COPROD_NODE,
359 17, COPROD_NODE,
360 28, COPROD_NODE,
361 JOB_NODE) nodetype
362 from msc_form_query mfq,
363 msc_supplies ms
364 where mfq.query_id = p_mfq_query_id
365 and mfq.NUMBER2 = ms.sr_instance_id
366 and mfq.NUMBER1 = ms.transaction_id
367 and ms.plan_id = p_plan_id
368 union all
369 select distinct
370 md.sr_instance_id,
371 md.organization_id,
372 md.demand_id,
373 END_DEMAND_NODE nodetype
374 from msc_form_query mfq,
375 msc_demands md
376 where mfq.query_id = p_mfq_query_id
377 and mfq.NUMBER2 = md.sr_instance_id
378 and mfq.NUMBER1 = md.demand_id
379 and md.plan_id = p_plan_id;
380
381 l_inst_id number;
382 l_org_id number;
383 l_trx_id number;
384 l_node_type number;
385 l_row_index number := 0;
386 BEGIN
387
388 open c_mfq;
389 loop
390 fetch c_mfq into l_inst_id, l_org_id, l_trx_id, l_node_type;
391 exit when c_mfq%notfound;
392
393 insert into msc_gantt_query (
394 query_id, last_update_date, last_updated_by, creation_date, created_by,
395 last_update_login, row_index, node_level, node_path, node_type,
396 sr_instance_id, organization_id, transaction_id )
397 values (
398 p_query_id, trunc(sysdate), -1, trunc(sysdate), -1, -1,
399 l_row_index, 0, l_row_index, l_node_type, l_inst_id, l_org_id, l_trx_id );
400 l_row_index := l_row_index + 1;
401 end loop;
402 close c_mfq;
403
404 END populateOrdersIntoGantt;
405
406 procedure populateOrdersIntoMFQ(p_inst_id in number,
407 p_trx_id in number, p_query_id in number,
408 p_one_record varchar2 default null) is
409 v_instance_id number;
410 v_transaction_id number;
411 begin
412
413 if ( p_one_record is not null ) then
414 v_instance_id := to_number(substr(p_one_record,1,instr(p_one_record,',')-1));
415 v_transaction_id := to_number(substr(p_one_record,instr(p_one_record,',')+1));
416 else
417 v_instance_id := p_inst_id;
418 v_transaction_id := p_trx_id;
419 end if;
420
421 insert into msc_form_query
422 (query_id, last_update_date, last_updated_by, creation_date, created_by,
423 last_update_login, number1, number2)
424 values
425 ( p_query_id, sysdate, -1, sysdate, -1, -1, v_transaction_id, v_instance_id);
426
427 end populateOrdersIntoMFQ;
428
429 procedure populateResIntoGanttFromGantt(p_query_id number, p_list varchar2, p_plan_id number) is
430 begin
431 insert into msc_gantt_query ( query_id,
432 last_update_date, last_updated_by, creation_date, created_by, last_update_login,
433 row_index, plan_id, sr_instance_id, organization_id, department_id, resource_id,
434 res_instance_id, serial_number, is_fetched )
435 select p_query_id,
436 sysdate, -1, sysdate, -1,-1,
437 row_index, plan_id, sr_instance_id, organization_id, department_id, resource_id,
438 res_instance_id, serial_number, sys_no
439 from msc_gantt_query
440 where query_id = to_number(p_list);
441 end populateResIntoGanttFromGantt;
442
443 procedure populateResIntoGantt(p_query_id number,
444 p_row_index in out nocopy number, p_one_record in out nocopy varchar2,
445 p_plan_id number, p_inst_id number default null, p_org_id number default null,
446 p_dept_id number default null, p_res_id number default null,
447 p_res_instance_id number default null, p_serial_number varchar2 default null,
448 p_add_nodes number default null) is
449
450 v_inst_id number;
451 v_org_id number;
452 v_dept_id number;
453 v_res_id number;
454 v_res_instance_id number;
455 v_serial_number varchar2(30);
456
457 l_row_found number;
458
459 begin
460
461 if (p_one_record is not null) then
462 parseResString(p_one_record, v_inst_id, v_org_id, v_dept_id, v_res_id,
463 v_res_instance_id, v_serial_number);
464 else
465 v_inst_id := p_inst_id;
466 v_org_id := p_org_id;
467 v_dept_id := p_dept_id;
468 v_res_id := p_res_id;
469 v_res_instance_id := p_res_instance_id;
470 v_serial_number := p_serial_number;
471 end if;
472
473 --insert if this is a resource first
474 if ( nvl(v_res_instance_id,mbp_null_value) = mbp_null_value ) then -- {
475 l_row_found := msc_gantt_utils.isResRowInGantt(p_query_id, p_plan_id,
476 v_inst_id, v_org_id, v_dept_id, v_res_id,
477 nvl(v_res_instance_id,mbp_null_value), nvl(v_serial_number,mbp_null_value_char));
478 if (l_row_found = sys_no) then -- {
479 p_row_index := p_row_index + 1;
480 insert into msc_gantt_query ( query_id,
481 last_update_date, last_updated_by, creation_date, created_by, last_update_login,
482 row_index, plan_id, sr_instance_id, organization_id, department_id, resource_id,
483 res_instance_id, serial_number, is_fetched )
484 values ( p_query_id,
485 sysdate, -1, sysdate, -1,-1,
486 p_row_index, p_plan_id, v_inst_id, v_org_id, v_dept_id, v_res_id,
487 nvl(v_res_instance_id,mbp_null_value), nvl(v_serial_number,mbp_null_value_char), sys_no );
488 end if; -- }
489 end if; -- }
490
491 if ( nvl(p_add_nodes, sys_yes) = sys_yes ) then -- {
492 if ( nvl(v_res_instance_id,mbp_null_value) = mbp_null_value ) then --{
493 -- find res instances
494 for c_res_inst in res_inst_cur(p_plan_id, v_inst_id, v_org_id, v_dept_id, v_res_id)
495 loop -- {
496 l_row_found := msc_gantt_utils.isResRowInGantt(p_query_id, p_plan_id,
497 v_inst_id, v_org_id, c_res_inst.department_id, v_res_id,
498 nvl(c_res_inst.res_instance_id,mbp_null_value),
499 nvl(c_res_inst.serial_number,mbp_null_value_char));
500
501 if (l_row_found = sys_no) then -- {
502 p_row_index := p_row_index + 1;
503 insert into msc_gantt_query ( query_id,
504 last_update_date, last_updated_by, creation_date, created_by, last_update_login,
505 row_index, plan_id, sr_instance_id, organization_id, department_id, resource_id,
506 res_instance_id, serial_number, is_fetched )
507 values ( p_query_id,
508 sysdate, -1, sysdate, -1,-1,
509 p_row_index, p_plan_id, v_inst_id, v_org_id, c_res_inst.department_id, v_res_id,
510 nvl(c_res_inst.res_instance_id,mbp_null_value),
511 nvl(c_res_inst.serial_number,mbp_null_value_char), sys_no );
512 end if; -- }
513 end loop; -- }
514 else
515 -- find res
516 for c_inst_res in inst_res_cur(p_plan_id, v_inst_id, v_org_id, v_dept_id, v_res_id,
517 v_res_instance_id, v_serial_number)
518 loop -- {
519 l_row_found := msc_gantt_utils.isResRowInGantt(p_query_id, p_plan_id,
520 v_inst_id, v_org_id, c_inst_res.department_id, v_res_id,
521 mbp_null_value, mbp_null_value_char);
522
523 if (l_row_found = sys_no) then -- {
524 p_row_index := p_row_index + 1;
525 insert into msc_gantt_query ( query_id,
526 last_update_date, last_updated_by, creation_date, created_by, last_update_login,
527 row_index, plan_id, sr_instance_id, organization_id, department_id, resource_id,
528 res_instance_id, serial_number, is_fetched )
529 values ( p_query_id,
530 sysdate, -1, sysdate, -1,-1,
531 p_row_index, p_plan_id, v_inst_id, v_org_id, c_inst_res.department_id, v_res_id,
532 mbp_null_value, mbp_null_value_char, sys_no );
533 end if; -- }
534 end loop; -- }
535 end if; -- }
536 end if; -- }
537
538 --insert if this is a res inst node last
539 if ( nvl(v_res_instance_id,mbp_null_value) <> mbp_null_value ) then --{
540 l_row_found := msc_gantt_utils.isResRowInGantt(p_query_id, p_plan_id,
541 v_inst_id, v_org_id, v_dept_id, v_res_id,
542 nvl(v_res_instance_id,mbp_null_value),
543 nvl(v_serial_number,mbp_null_value_char));
544
545 if (l_row_found = sys_no) then -- {
546 p_row_index := p_row_index + 1;
547 insert into msc_gantt_query ( query_id,
548 last_update_date, last_updated_by, creation_date, created_by, last_update_login,
549 row_index, plan_id, sr_instance_id, organization_id, department_id, resource_id,
550 res_instance_id, serial_number, is_fetched )
551 values ( p_query_id,
552 sysdate, -1, sysdate, -1,-1,
553 p_row_index, p_plan_id, v_inst_id, v_org_id, v_dept_id, v_res_id,
554 nvl(v_res_instance_id,mbp_null_value), nvl(v_serial_number,mbp_null_value_char), sys_no );
555 end if; -- }
556 end if; -- }
557
558 end populateResIntoGantt;
559
560 procedure populateResIntoGanttFromMfq(p_query_id number,
561 p_list varchar2, p_plan_id number) is
562
563 v_inst_id number_arr;
564 v_org_id number_arr;
565 v_dept_id number_arr;
566 v_res_id number_arr;
567 v_res_instance_id number_arr;
568 v_serial_number char_arr;
569
570 v_one_record varchar2(100) := null;
571 l_row_index number := 0;
572 begin
573
574 select number1, number2, number3, number4, number5, char1
575 bulk collect into v_inst_id, v_org_id, v_dept_id, v_res_id,
576 v_res_instance_id, v_serial_number
577 from msc_form_query
578 where query_id = to_number(p_list);
579
580 for i in 1.. v_inst_id.count loop
581 populateResIntoGantt(p_query_id, l_row_index, v_one_record,p_plan_id, v_inst_id(i),
582 v_org_id(i), v_dept_id(i), v_res_id(i), v_res_instance_id(i), v_serial_number(i));
583 end loop;
584
585 end populateResIntoGanttFromMfq;
586
587 procedure populateResIntoMfq(p_query_id number, p_res_id number,
588 p_res_instance_id number default null, p_serial_number varchar2 default null,
589 p_res_name varchar2 default null, p_alt_number varchar2 default null) is
590 begin
591
592 insert into msc_form_query ( query_id,
593 last_update_date, last_updated_by, creation_date, created_by, last_update_login,
594 number1, number2, char1, char9, number3)
595 values ( p_query_id,
596 sysdate, -1, sysdate, -1,-1,
597 p_res_id, p_res_instance_id, p_serial_number, p_res_name, p_alt_number);
598
599 end populateResIntoMfq;
600
601 procedure getItemBomType(p_plan_id number, p_item_id number,
602 p_bom_item_type out nocopy number, p_base_item_id out nocopy varchar2) is
603
604 cursor c_bom_item is
605 select bom_item_type, base_item_id
606 from msc_system_items
607 where plan_id = p_plan_id
608 and inventory_item_id = p_item_id;
609 begin
610 open c_bom_item;
611 fetch c_bom_item into p_bom_item_type, p_base_item_id;
612 close c_bom_item;
613 end getItemBomType;
614
615 procedure populateSuppIntoGantt(p_query_id number,
616 p_row_index number, p_one_record in out nocopy varchar2, p_plan_id number,
617 p_inst_id number default null, p_org_id number default null,
618 p_item_id number default null, p_supplier_id number default null,
619 p_supplier_site_id number default null) is
620
621 v_inst_id number;
622 v_org_id number;
623 v_item_id number;
624 v_supplier_id number;
625 v_supplier_site_id number;
626
627 v_bom_item_type number;
628 v_base_item_id number;
629 begin
630
631 if (p_one_record is not null) then
632 parseSuppString(p_one_record, v_inst_id, v_org_id,
633 v_item_id, v_supplier_id, v_supplier_site_id);
634 else
635 v_inst_id := p_inst_id;
636 v_org_id := p_org_id;
637 v_item_id := p_item_id;
638 v_supplier_id := p_supplier_id;
639 v_supplier_site_id := p_supplier_site_id;
640 end if;
641
642 getItemBomType(p_plan_id, v_item_id, v_bom_item_type, v_base_item_id);
643
644 insert into msc_gantt_query (
645 query_id,
646 last_update_date, last_updated_by, creation_date, created_by, last_update_login,
647 row_index, plan_id, inventory_item_id, supplier_id,
648 supplier_site_id, is_fetched, dependency_type, department_id)
649 values (
650 p_query_id,
651 sysdate, -1, sysdate, -1,-1,
652 p_row_index, p_plan_id, v_item_id, v_supplier_id,
653 nvl(v_supplier_site_id, -23453), sys_no, v_bom_item_type, v_base_item_id);
654
655 end populateSuppIntoGantt;
656
657 procedure populateSuppIntoGanttFromMfq(p_query_id number,
658 p_list varchar2, p_plan_id number) is
659 v_inst_id number_arr;
660 v_org_id number_arr;
661 v_item_id number_arr;
662 v_supplier_id number_arr;
663 v_supplier_site_id number_arr;
664 v_one_record varchar2(100) := null;
665 begin
666
667 select number1, number2, number3, number4, number5
668 bulk collect into v_inst_id, v_org_id, v_item_id, v_supplier_id, v_supplier_site_id
669 from msc_form_query
670 where query_id = to_number(p_list);
671
672 for i in 1.. v_inst_id.count loop
673 populateSuppIntoGantt(p_query_id, i, v_one_record,p_plan_id,
674 v_inst_id(i), v_org_id(i), v_item_id(i), v_supplier_id(i), v_supplier_site_id(i));
675 null;
676 end loop;
677
678 end populateSuppIntoGanttFromMfq;
679
680 procedure populateResDtlIntoGantt(p_query_id number,
681 p_row_type number, p_row_index number,
682 p_start_date date, p_end_date date,
683 p_resource_units number, p_resource_hours number,
684 p_schedule_flag number, p_detail_type number,
685 p_display_type number default null) is
686 begin
687
688 insert into msc_gantt_dtl_query ( query_id, row_type, row_index, parent_id,
689 last_update_date, last_updated_by, creation_date, created_by, last_update_login,
690 start_date, end_date, resource_units, resource_hours, schedule_flag, display_flag)
691 values ( p_query_id, p_row_type, p_row_index, p_detail_type,
692 sysdate, -1, sysdate, -1,-1,
693 p_start_date, p_end_date, p_resource_units, p_resource_hours, p_schedule_flag, p_display_type);
694
695 end populateResDtlIntoGantt;
696
697 procedure populateResDtlTabIntoGantt(p_query_id number,
698 p_row_type number, p_row_index number_arr,
699 p_start_date date_arr, p_end_date date_arr,
700 p_resource_units number_arr, p_resource_hours number_arr,
701 p_schedule_flag number_arr, p_detail_type number,
702 p_display_type number_arr default null,
703 p_from_batch_node number default null) is
704
705 l_display_type number;
706 l_res_hours number;
707 l_res_units number;
708 begin
709
710 for i in 1..p_start_date.count
711 loop -- {
712 if ( p_row_type = RES_REQ_ROW_TYPE ) then -- {
713 l_display_type := p_display_type(i);
714 end if; -- }
715
716 if ( nvl(p_from_batch_node, sys_no) = sys_yes) then
717 l_res_units := ceil(p_resource_units(i));
718 l_res_hours := l_res_units * p_resource_hours(i);
719 else
720 l_res_units := p_resource_units(i);
721 l_res_hours := p_resource_hours(i);
722 end if;
723
724 insert into msc_gantt_dtl_query (
725 query_id, row_type, row_index, parent_id,
726 last_update_date, last_updated_by, creation_date, created_by, last_update_login,
727 start_date, end_date, resource_units, resource_hours, schedule_flag,
728 display_flag)
729 values (
730 p_query_id, p_row_type, p_row_index(i), p_detail_type,
731 sysdate, -1, sysdate, -1,-1,
732 p_start_date(i), p_end_date(i), l_res_units, l_res_hours,
733 p_schedule_flag(i), l_display_type );
734 end loop; --}
735
736 end populateResDtlTabIntoGantt;
737
738 procedure populateSuppDtlIntoGantt(p_query_id number, p_row_type number,
739 p_row_index number, p_start_date date, p_avail_qty number, p_overload_qty number,
740 p_consume_qty number, p_detail_type number) is
741 begin
742
743 insert into msc_gantt_dtl_query ( query_id, row_type, row_index, parent_id,
744 last_update_date, last_updated_by, creation_date, created_by, last_update_login,
745 start_date, supp_avail_qty, supp_overload_qty, supp_consume_qty)
746 values ( p_query_id, p_row_type, p_row_index, p_detail_type,
747 sysdate, -1, sysdate, -1,-1,
748 p_start_date, p_avail_qty, p_overload_qty, p_consume_qty);
749
750 end populateSuppDtlIntoGantt;
751
752 procedure populateSuppDtlTabIntoGantt(p_query_id number,
753 p_row_type number, p_row_index number_arr,
754 p_start_date date_arr, p_units number_arr, p_number2 number_arr, p_detail_type number) is
755
756 l_consumed_qty number;
757 begin
758
759 for i in 1..p_start_date.count
760 loop
761 if ( p_row_type = SUPP_ALL_ROW_TYPE ) then
762 l_consumed_qty := p_number2(i);
763 else
764 l_consumed_qty := to_number(null);
765 end if;
766 insert into msc_gantt_dtl_query (
767 query_id, row_type, row_index, parent_id,
768 last_update_date, last_updated_by, creation_date, created_by, last_update_login,
769 start_date, resource_units, resource_hours)
770 values (
771 p_query_id, p_row_type, p_row_index(i), p_detail_type,
772 sysdate, -1, sysdate, -1,-1,
773 p_start_date(i), p_units(i), l_consumed_qty);
774 end loop;
775
776 end populateSuppDtlTabIntoGantt;
777
778 procedure populateResActIntoDtlGantt(p_query_id number,
779 p_row_type number, p_detail_type number,
780 p_row_index number_arr, p_sr_instance_id number_arr,
781 p_organization_id number_arr, p_supply_id number_arr, p_transaction_id number_arr,
782 p_status number_arr, p_applied number_arr, p_res_firm_flag number_arr,
783 p_sup_firm_flag number_arr, p_start_date date_arr, p_end_date date_arr,
784 p_schedule_flag number_arr, p_res_constraint number_arr, p_qty number_arr,
785 p_batch_number number_arr, p_resource_units number_arr,
786 p_group_sequence_id number_arr, p_group_sequence_number number_arr,
787 p_cepst date_arr, p_cepct date_arr, p_ulpst date_arr, p_ulpct date_arr,
788 p_uepst date_arr, p_uepct date_arr, p_eact date_arr, p_item_id number_arr,
789 p_bar_text char_arr, p_order_number char_arr,
790 p_op_seq number_arr, p_res_seq number_arr, p_res_desc char_arr, p_item_name char_arr,
791 p_assy_item_desc char_arr, p_schedule_qty number_arr,
792 p_from_setup_code char_arr, p_to_setup_code char_arr, p_std_op_code char_arr,
793 p_changeover_time char_arr, p_changeover_penalty char_arr,
794 p_overload_flag number_arr) is
795
796 begin
797
798 forall i in p_sr_instance_id.first .. p_sr_instance_id.last
799 --loop
800 insert into msc_gantt_dtl_query (
801 query_id, row_type, row_index, parent_id,
802 last_update_date, last_updated_by, creation_date, created_by, last_update_login,
803 sr_instance_id, organization_id, supply_id, transaction_id, status, applied,
804 res_firm_flag, sup_firm_flag, start_date, end_date, schedule_flag, late_flag,
805 supply_qty, batch_number, resource_units, group_sequence_id, group_sequence_number,
806 cepst, cepct, ulpst, ulpct, uepst, uepct, eact, inventory_item_id, bar_label,
807 order_number, op_seq_num, resource_seq_num, resource_description, item_name, assembly_item_desc, schedule_qty,
808 from_setup_code, to_setup_code, std_op_code, changeover_time, changeover_penalty, supp_avail_qty)
809 values (
810 p_query_id, p_row_type, p_row_index(i), p_detail_type,
811 sysdate, -1, sysdate, -1,-1,
812 p_sr_instance_id(i), p_organization_id(i), p_supply_id(i), p_transaction_id(i),
813 p_status(i), p_applied(i), p_res_firm_flag(i), p_sup_firm_flag(i),
814 p_start_date(i), p_end_date(i), p_schedule_flag(i), p_res_constraint(i),
815 p_qty(i), p_batch_number(i), p_resource_units(i), p_group_sequence_id(i),
816 p_group_sequence_number(i), p_cepst(i), p_cepct(i), p_ulpst(i), p_ulpct(i),
817 p_uepst(i), p_uepct(i), p_eact(i), p_item_id(i), p_bar_text(i),
818 p_order_number(i), p_op_seq(i), p_res_seq(i), p_res_desc(i), p_item_name(i),
819 p_assy_item_desc(i), p_schedule_qty(i),
820 p_from_setup_code(i), p_to_setup_code(i), p_std_op_code(i), p_changeover_time(i),
821 p_changeover_penalty(i), p_overload_flag(i));
822 --end loop;
823
824 end populateResActIntoDtlGantt;
825
826 procedure populateBtchResIntoDtlGantt(p_query_id number,
827 p_row_type number, p_detail_type number,
828 p_row_index number_arr, p_sr_instance_id number_arr,
829 p_organization_id number_arr, p_start_date date_arr, p_end_date date_arr,
830 p_schedule_flag number_arr, p_batch_number number_arr,
831 p_qty number_arr, p_bar_text char_arr, p_node_type number) is
832
833 l_min_capacity number;
834 l_max_capacity number;
835 l_capacity_used number;
836 l_res_desc varchar2(300);
837 begin
838
839 for i in 1..p_sr_instance_id.count
840 loop
841
842 msc_gantt_utils.getBatchValues(g_plan_id, p_sr_instance_id(i), p_batch_number(i),
843 l_res_desc, l_min_capacity, l_max_capacity, l_capacity_used);
844
845 insert into msc_gantt_dtl_query (
846 query_id, row_type, row_index, parent_id,
847 last_update_date, last_updated_by, creation_date, created_by, last_update_login,
848 sr_instance_id, organization_id, start_date, end_date, schedule_flag,
849 batch_number, supply_qty, bar_label,
850 resource_description, min_capacity, max_capacity, capacity_used)
851 values (
852 p_query_id, p_row_type, p_row_index(i), p_detail_type,
853 sysdate, -1, sysdate, -1,-1,
854 p_sr_instance_id(i), p_organization_id(i),
855 p_start_date(i), p_end_date(i), p_schedule_flag(i),
856 p_batch_number(i), p_qty(i), p_bar_text(i),
857 l_res_desc, l_min_capacity, l_max_capacity, l_capacity_used);
858 end loop;
859
860 end populateBtchResIntoDtlGantt;
861
862 function getResReqStartDate(p_firm_flag number,
863 p_start_date date, p_end_date date,
864 p_firm_start_date date, p_firm_end_date date, p_status number, p_applied number) return date is
865 p_return_date date;
866 begin
867 --5153956 bugfix
868 if ( nvl(p_status,-1) = 0 and nvl(p_applied,-1) = 2) then
869 p_return_date := nvl(p_firm_start_date, p_start_date);
870 return p_return_date;
871 else
872 p_return_date := p_start_date;
873 end if;
874 --5153956 bugfix ends
875
876 if ( p_firm_flag = NO_FIRM ) then
877 p_return_date := p_start_date;
878 elsif ( p_firm_flag = FIRM_RESOURCE ) then
879 p_return_date := p_start_date;
880 elsif ( p_firm_flag = FIRM_END ) then
881 p_return_date := nvl(p_firm_end_date, p_end_date) - (p_end_date - p_start_date);
882 elsif ( p_firm_flag = FIRM_END_RES ) then
883 p_return_date := nvl(p_firm_end_date, p_end_date) - (p_end_date - p_start_date);
884 else
885 p_return_date := nvl(p_firm_start_date, p_start_date);
886 end if;
887 return p_return_date;
888
889 end getResReqStartDate;
890
891 function getResReqEndDate(p_firm_flag number,
892 p_start_date date, p_end_date date,
893 p_firm_start_date date, p_firm_end_date date, p_status number, p_applied number) return date is
894 p_return_date date;
895 begin
896 --5153956 bugfix
897 if ( nvl(p_status,-1) = 0 and nvl(p_applied,-1) = 2) then
898 p_return_date := nvl(p_firm_end_date, p_end_date);
899 return p_return_date;
900 else
901 p_return_date := p_end_date;
902 end if;
903 --5153956 bugfix ends
904
905 if ( p_firm_flag = NO_FIRM ) then
906 p_return_date := p_end_date;
907 elsif ( p_firm_flag = FIRM_RESOURCE ) then
908 p_return_date := p_end_date;
909 elsif ( p_firm_flag = FIRM_START ) then
910 p_return_date := nvl(p_firm_start_date, p_start_date) + (p_end_date - p_start_date);
911 elsif ( p_firm_flag = FIRM_START_RES ) then
912 p_return_date := nvl(p_firm_start_date, p_start_date) + (p_end_date - p_start_date);
913 else
914 p_return_date := nvl(p_firm_end_date, p_end_date);
915 end if;
916 return p_return_date;
917
918 end getResReqEndDate;
919
920 function getResReqType(p_plan_id number,
921 p_schedule_flag number, p_parent_seq_num number, p_setup_id number) return number is
922 l_schedule_flag number;
923 begin
924
925 if ( p_setup_id is not null ) then -- sds row
926 if ( p_schedule_flag = SCHEDULE_FLAG_YES ) then
927 l_schedule_flag := RES_REQ_SDS_ROW_TYPE; -- SDS_RUN
928 else
929 l_schedule_flag := RES_SETUP_FIXED_ROW_TYPE; -- SDS_SETUP
930 end if;
931 else -- non-sds row
932 if ( p_schedule_flag = SCHEDULE_FLAG_YES ) then
933 l_schedule_flag := RES_REQ_ROW_TYPE; -- NORMAL_RUN
934 else
935 l_schedule_flag := RES_SETUP_ROW_TYPE; -- NORMAL_SETUP
936 end if;
937 end if ;
938 return l_schedule_flag;
939
940 /*
941 if ( p_parent_seq_num is not null ) then -- {
942 if ( p_schedule_flag = SCHEDULE_FLAG_YES ) then -- {
943 l_schedule_flag := RES_SETUP_ROW_TYPE; -- NORMAL_SETUP
944 elsif ( p_schedule_flag in (SCHEDULE_FLAG_PRIOR, SCHEDULE_FLAG_NEXT) ) then
945 l_schedule_flag := RES_SETUP_FIXED_ROW_TYPE; -- SDS_SETUP
946 end if; -- }
947 else
948 if ( p_schedule_flag = SCHEDULE_FLAG_YES ) then -- {
949 l_schedule_flag := RES_REQ_ROW_TYPE; -- NORMAL_RUN
950 elsif ( p_schedule_flag in (SCHEDULE_FLAG_PRIOR, SCHEDULE_FLAG_NEXT) ) then
951 l_schedule_flag := RES_REQ_SDS_ROW_TYPE; -- SDS_RUN
952 end if;
953 end if; -- }
954 */
955 return l_schedule_flag;
956 end getResReqType;
957
958 function getSetupCode(p_plan_id number, p_inst_id number,
959 p_resource_id number, p_setup_id number) return varchar2 is
960 l_setup_code varchar2(100);
961 begin
962
963 select setup_code
964 into l_setup_code
965 from msc_resource_setups
966 where plan_id = p_plan_id
967 and sr_instance_id = p_inst_id
968 and resource_id = p_resource_id
969 and setup_id = p_setup_id;
970 return l_setup_code;
971
972 exception
973 when others then
974 return null_space;
975
976 end getSetupCode;
977
978 function getMTQTime(p_transaction_id number,
979 p_plan_id number, p_instance_id number) return number IS
980
981 l_mtq number;
982 l_cumm_quan number;
983 l_order_quan number;
984 begin
985
986 select mro.MINIMUM_TRANSFER_QUANTITY,
987 mrr.cummulative_quantity, ms.new_order_quantity
988 into l_mtq,l_cumm_quan, l_order_quan
989 from msc_routing_operations mro,
990 msc_resource_requirements mrr,
991 msc_supplies ms
992 where mrr.plan_id = p_plan_id
993 and mrr.sr_instance_id = p_instance_id
994 and mrr.transaction_id = p_transaction_id
995 and mro.routing_sequence_id = mrr.routing_sequence_id
996 and mro.operation_sequence_id = mrr.operation_sequence_id
997 and mro.plan_id = p_plan_id
998 and mro.sr_instance_id = p_instance_id
999 and ms.plan_id = p_plan_id
1000 and ms.sr_instance_id = p_instance_id
1001 and ms.transaction_id = mrr.supply_id;
1002
1003 if l_mtq is null then
1004 return 1;
1005 end if;
1006
1007 if l_cumm_quan is null then
1008 if l_order_quan is null then
1009 return 1;
1010 end if;
1011 l_cumm_quan := l_order_quan;
1012 end if;
1013
1014 if l_mtq >= l_cumm_quan or l_mtq < 0 then
1015 return 1;
1016 else
1017 return l_mtq/l_cumm_quan;
1018 end if;
1019
1020 exception
1021 when no_data_found then
1022 return 1;
1023 end getMTQTime;
1024
1025 function isResOverload(p_plan_id number,
1026 p_instance_id number, p_organization_id number, p_inventory_item_id number,
1027 p_department_id number, p_resource_id number,
1028 p_transaction_id number) return number is
1029
1030 cursor c_53 is
1031 select 'EXISTS'
1032 from msc_exception_details
1033 where number1 = p_transaction_id
1034 and sr_instance_id = p_instance_id
1035 and plan_id = p_plan_id
1036 and exception_type = 53
1037 and organization_id = p_organization_id
1038 --and inventory_item_id = p_inventory_item_id
1039 and department_id = p_department_id
1040 and resource_id = p_resource_id;
1041
1042 retval number;
1043 l_temp varchar2(10);
1044
1045 begin
1046
1047 open c_53;
1048 fetch c_53 into l_temp;
1049 if c_53%found then
1050 retval := sys_yes;
1051 else
1052 retval := sys_no;
1053 end if;
1054 close c_53;
1055 return retval;
1056
1057 end isResOverload;
1058
1059 function isResConstraint(p_plan_id number,
1060 p_instance_id number, p_organization_id number, p_inventory_item_id number,
1061 p_department_id number, p_resource_id number,
1062 p_transaction_id number) return number is
1063
1064 -------------------------------------------------------
1065 -- bug 2116260: logic for late_flag changed
1066 -- old logic:
1067 -- late if need_by_date < new_schedule_date
1068 -- new logic:
1069 -- late if HLS generated resource constraint
1070 -- (exception type = 36) while scheduling this
1071 -- supply for this transaction (even if there is
1072 -- one exception in any date-range)
1073 --------------------------------------------------------
1074 cursor resource_constraint_cur is
1075 select 'EXISTS'
1076 from msc_exception_details
1077 where number1 = p_transaction_id
1078 and sr_instance_id = p_instance_id
1079 and plan_id = p_plan_id
1080 and exception_type =36
1081 and organization_id = p_organization_id
1082 --and inventory_item_id = p_inventory_item_id
1083 and department_id = p_department_id
1084 and resource_id = p_resource_id;
1085
1086 retval number;
1087 l_resource_constraint varchar2(10);
1088
1089 begin
1090
1091 open resource_constraint_cur;
1092 fetch resource_constraint_cur into l_resource_constraint;
1093 if resource_constraint_cur%found then
1094 retval := sys_yes;
1095 else
1096 retval := sys_no;
1097 end if;
1098 close resource_constraint_cur;
1099 return retval;
1100
1101 end isResConstraint;
1102
1103 function isExcpExists(p_plan_id number, p_instance_id number, p_organization_id number,
1104 p_department_id number, p_resource_id number, p_exception_type number) return number is
1105
1106 cursor c_excp is
1107 select 'EXISTS'
1108 from msc_exception_details
1109 where plan_id = p_plan_id
1110 and sr_instance_id = p_instance_id
1111 and organization_id = p_organization_id
1112 and department_id = p_department_id
1113 and resource_id = p_resource_id
1114 and exception_type = p_exception_type;
1115
1116 retval number;
1117 l_temp varchar2(10);
1118
1119 begin
1120
1121 open c_excp;
1122 fetch c_excp into l_temp;
1123 if c_excp%found then
1124 retval := sys_yes;
1125 else
1126 retval := sys_no;
1127 end if;
1128 close c_excp;
1129 return retval;
1130
1131 end isExcpExists;
1132
1133 function isTimeFenceCrossed(p_plan_id number,
1134 p_transaction_id number, p_instance_id number,
1135 p_start_date date) RETURN varchar2 IS
1136
1137 l_timefence_date DATE;
1138 l_prev_start_date DATE;
1139
1140 BEGIN
1141
1142 select getResReqStartDate(nvl(mrr.firm_flag,0),
1143 mrr.start_date, mrr.end_date, mrr.firm_start_date, mrr.firm_end_date, mrr.status, mrr.applied) start_date,
1144 msi.planning_time_fence_date
1145 into l_prev_start_date, l_timefence_date
1146 from msc_system_items msi,
1147 msc_resource_requirements mrr,
1148 msc_supplies ms
1149 where mrr.plan_id = p_plan_id
1150 and mrr.transaction_id = p_transaction_id
1151 and mrr.sr_instance_id = p_instance_id
1152 and ms.plan_id = mrr.plan_id
1153 and ms.transaction_id = mrr.supply_id
1154 and ms.sr_instance_id = mrr.sr_instance_id
1155 and msi.plan_id = ms.plan_id
1156 and msi.organization_id = ms.organization_id
1157 and msi.sr_instance_id = ms.sr_instance_id
1158 and msi.inventory_item_id = ms.inventory_item_id;
1159
1160 if ( l_timefence_date < l_prev_start_date
1161 and p_start_date < l_timefence_date )
1162 or (p_start_date > l_timefence_date
1163 and l_timefence_date > l_prev_start_date ) then
1164 return 'Y';
1165 else
1166 return 'N';
1167 end if;
1168
1169 end isTimeFenceCrossed;
1170
1171 function usingBatchableRes(p_plan_id number,
1172 p_transaction_id number, p_instance_id number) return boolean is
1173
1174 v_flag number :=2;
1175
1176 begin
1177
1178 select nvl(mdr.batchable_flag, 2)
1179 into v_flag
1180 from msc_resource_requirements mrr,
1181 msc_department_resources mdr
1182 where mrr.plan_id = p_plan_id
1183 and mrr.transaction_id = p_transaction_id
1184 and mrr.sr_instance_id = p_instance_id
1185 AND mdr.plan_id = mrr.plan_id
1186 AND mdr.organization_id = mrr.organization_id
1187 AND mdr.sr_instance_id = mrr.sr_instance_id
1188 AND mdr.department_id = mrr.department_id
1189 AND mdr.resource_id = mrr.resource_id;
1190
1191 if v_flag = 2 then
1192 return false;
1193 else
1194 return true;
1195 end if;
1196
1197 end usingBatchableRes;
1198
1199 function isBatchable(p_plan_id number, p_inst_id number, p_org_id number,
1200 p_dept_id number, p_res_id number ) return number is
1201
1202 l_flag number;
1203 begin
1204
1205 select nvl(batchable_flag, SYS_NO)
1206 into l_flag
1207 from msc_department_resources
1208 where plan_id = p_plan_id
1209 and sr_instance_id = p_inst_id
1210 and organization_id = p_org_id
1211 and department_id = p_dept_id
1212 and resource_id = p_res_id;
1213
1214 return l_flag;
1215
1216 end isBatchable;
1217
1218 function isBtchResWithoutBatch(p_plan_id number, p_instance_id number, p_organization_id number,
1219 p_department_id number, p_resource_id number, p_res_inst_id number) return number is
1220 cursor c_temp is
1221 select sys_yes
1222 from msc_resource_requirements mrr
1223 where mrr.plan_id = p_plan_id
1224 and mrr.sr_instance_id = p_instance_id
1225 and mrr.organization_id = p_organization_id
1226 and mrr.department_id = p_department_id
1227 and mrr.resource_id = p_resource_id
1228 and mrr.parent_id = 2
1229 and batch_number is null
1230 and rownum = 1;
1231 l_temp number;
1232 begin
1233 open c_temp;
1234 fetch c_temp into l_temp;
1235 close c_temp;
1236 return nvl(l_temp,sys_no);
1237 end isBtchResWithoutBatch;
1238
1239 /*
1240 function isResRowInGantt(p_query_id number,
1241 p_res_instance_id number, p_batchable number,
1242 p_ignore_batch_flag number default null) return number is
1243
1244 cursor c_check_res_row is
1245 select sys_yes
1246 from msc_gantt_query mgq,
1247 msc_department_resources mdr
1248 where mgq.query_id = p_query_id
1249 and mgq.row_flag = SYS_YES
1250 and g_plan_id = mdr.plan_id
1251 and mgq.sr_instance_id = mdr.sr_instance_id
1252 and mgq.organization_id = mdr.organization_id
1253 and mgq.department_id = mdr.department_id
1254 and mgq.resource_id = mdr.resource_id
1255 and ( ( p_res_instance_id = sys_yes and mgq.res_instance_id <> mbp_null_value )
1256 or ( p_res_instance_id = sys_no and mgq.res_instance_id = mbp_null_value ) )
1257 and ( nvl(mdr.batchable_flag, sys_no) = p_batchable or nvl(p_ignore_batch_flag,2) = sys_yes)
1258 and rownum = 1;
1259
1260 l_temp number;
1261 begin
1262 open c_check_res_row;
1263 fetch c_check_res_row into l_temp;
1264 if (c_check_res_row%notfound) then
1265 l_temp := sys_no;
1266 end if;
1267 close c_check_res_row;
1268 return l_temp;
1269 end isResRowInGantt;
1270 */
1271 --4997096 bugfix
1272 --commented the above fn isResRowInGantt as part of 4997096 bugfix
1273 --provided a new procedure for the same
1274
1275 procedure isResRowInGantt(p_query_id number,
1276 p_res_rows out nocopy number,
1277 p_res_inst_rows out nocopy number,
1278 p_res_batch_rows out nocopy number,
1279 p_res_inst_batch_rows out nocopy number,
1280 p_batch_flag number default null) is
1281
1282 l_temp number;
1283 begin
1284 --regular resource
1285 select count(*)
1286 into l_temp
1287 from msc_gantt_query mgq,
1288 msc_department_resources mdr
1289 where mgq.query_id = p_query_id
1290 and mgq.row_flag = sys_yes
1291 and g_plan_id = mdr.plan_id
1292 and mgq.sr_instance_id = mdr.sr_instance_id
1293 and mgq.organization_id = mdr.organization_id
1294 and mgq.department_id = mdr.department_id
1295 and mgq.resource_id = mdr.resource_id
1296 and mgq.res_instance_id = mbp_null_value
1297 and ( ( nvl(mdr.batchable_flag, sys_no) = sys_no and p_batch_flag is null)
1298 or (p_batch_flag = sys_no)
1299 or isBtchResWithoutBatch(mdr.plan_id, mdr.sr_instance_id, mdr.organization_id,
1300 mdr.department_id, mdr.resource_id, to_number(null)) = sys_yes );
1301
1302 if (l_temp = 0) then
1303 p_res_rows := sys_no;
1304 else
1305 p_res_rows := sys_yes;
1306 end if;
1307 --regular resource ends
1308
1309 --regular resource instance
1310 select count(*)
1311 into l_temp
1312 from msc_gantt_query mgq,
1313 msc_department_resources mdr
1314 where mgq.query_id = p_query_id
1315 and mgq.row_flag = sys_yes
1316 and g_plan_id = mdr.plan_id
1317 and mgq.sr_instance_id = mdr.sr_instance_id
1318 and mgq.organization_id = mdr.organization_id
1319 and mgq.department_id = mdr.department_id
1320 and mgq.resource_id = mdr.resource_id
1321 and mgq.res_instance_id <> mbp_null_value
1322 and ( ( nvl(mdr.batchable_flag, sys_no) = sys_no and p_batch_flag is null)
1323 or (p_batch_flag = sys_no)
1324 or isBtchResWithoutBatch(mdr.plan_id, mdr.sr_instance_id, mdr.organization_id,
1325 mdr.department_id, mdr.resource_id, to_number(null)) = sys_yes );
1326
1327 if (l_temp = 0) then
1328 p_res_inst_rows := sys_no;
1329 else
1330 p_res_inst_rows := sys_yes;
1331 end if;
1332 --regular resource instance ends
1333
1334 --regular batched resource
1335 select count(*)
1336 into l_temp
1337 from msc_gantt_query mgq,
1338 msc_department_resources mdr
1339 where mgq.query_id = p_query_id
1340 and mgq.row_flag = sys_yes
1341 and g_plan_id = mdr.plan_id
1342 and mgq.sr_instance_id = mdr.sr_instance_id
1343 and mgq.organization_id = mdr.organization_id
1344 and mgq.department_id = mdr.department_id
1345 and mgq.resource_id = mdr.resource_id
1346 and mgq.res_instance_id = mbp_null_value
1347 and nvl(mdr.batchable_flag, sys_no) = sys_yes;
1348
1349 if (l_temp = 0) then
1350 p_res_batch_rows := sys_no;
1351 else
1352 p_res_batch_rows := sys_yes;
1353 end if;
1354 --regular batched resource ends
1355
1356 --regular resource instance
1357 select count(*)
1358 into l_temp
1359 from msc_gantt_query mgq,
1360 msc_department_resources mdr
1361 where mgq.query_id = p_query_id
1362 and mgq.row_flag = sys_yes
1363 and g_plan_id = mdr.plan_id
1364 and mgq.sr_instance_id = mdr.sr_instance_id
1365 and mgq.organization_id = mdr.organization_id
1366 and mgq.department_id = mdr.department_id
1367 and mgq.resource_id = mdr.resource_id
1368 and mgq.res_instance_id <> mbp_null_value
1369 and nvl(mdr.batchable_flag, sys_no) = sys_yes;
1370
1371 if (l_temp = 0) then
1372 p_res_inst_batch_rows := sys_no;
1373 else
1374 p_res_inst_batch_rows := sys_yes;
1375 end if;
1376 --regular resource instance ends
1377 end isResRowInGantt;
1378
1379 function isResRowInGantt(p_query_id number, p_plan_id number,
1380 p_inst_id number, p_org_id number, p_dept_id number, p_res_id number,
1381 p_res_inst_id number, p_serial_number varchar2) return number is
1382
1383 cursor check_res_row_cur (p_query number,
1384 p_plan number, p_inst number, p_org number, p_dept number,
1385 p_res number, p_res_inst number, p_serial_num varchar2) is
1386 select count(*)
1387 from msc_gantt_query mgq
1388 where mgq.query_id = p_query
1389 and mgq.plan_id = p_plan
1390 and mgq.sr_instance_id = p_inst
1391 and mgq.organization_id = p_org
1392 and mgq.department_id = p_dept
1393 and mgq.resource_id = p_res
1394 and nvl(mgq.res_instance_id, MBP_NULL_VALUE) = nvl(p_res_inst, MBP_NULL_VALUE)
1395 and nvl(mgq.serial_number, MBP_NULL_VALUE_CHAR) = nvl(p_serial_num, MBP_NULL_VALUE_CHAR)
1396 and rownum = 1;
1397
1398 l_row_count number;
1399 begin
1400 open check_res_row_cur(p_query_id, p_plan_id, p_inst_id, p_org_id, p_dept_id,
1401 p_res_id, p_res_inst_id, p_serial_number);
1402 fetch check_res_row_cur into l_row_count;
1403 close check_res_row_cur;
1404
1405 if (l_row_count > 0) then
1406 return sys_yes;
1407 end if;
1408 return sys_no;
1409 end isResRowInGantt;
1410
1411
1412 function getOrderNumber(p_plan_id number, p_inst_id number, p_trx_id number, p_disposition_id number,
1413 p_order_type number, p_order_number varchar2) return varchar2 is
1414
1415 /*cursor c_order_number is
1416 select decode(p_order_type,
1417 5, decode(p_order_number, null, to_char(p_trx_id),
1418 p_order_number|| null_space ||to_char(p_trx_id)),
1419 14, decode(substr(msc_get_name.get_order_number(p_inst_id, p_plan_id,
1420 p_disposition_id, 1),1,240), null, to_char(p_disposition_id),
1421 substr(msc_get_name.get_order_number(p_inst_id, p_plan_id,
1422 p_disposition_id, 1),1,240)
1423 || null_space || to_char(p_disposition_id)),
1424 17, decode(substr(msc_get_name.get_order_number(p_inst_id, p_plan_id,
1425 p_disposition_id, 1),1,240), null, to_char(p_disposition_id),
1426 substr(msc_get_name.get_order_number(p_inst_id, p_plan_id,
1427 p_disposition_id, 1),1,240) || null_space || to_char(p_disposition_id)),
1428 51,to_char(p_trx_id),
1429 52,to_char(p_trx_id),
1430 15,to_char(p_trx_id),
1431 16,to_char(p_trx_id),
1432 28,to_char(p_trx_id),
1433 p_order_number)
1434 from dual;*/
1435
1436 l_order_number varchar2(300);
1437 l_temp varchar2(300);
1438 begin
1439 /*open c_order_number;
1440 fetch c_order_number into l_order_number;
1441 close c_order_number;*/
1442 If p_order_type In (15,16,28,51,52) Then
1443 l_order_number := To_Char(p_trx_id);
1444 Elsif p_order_type = 5 Then
1445 If p_order_number Is Null Then
1446 l_order_number := To_Char(p_trx_id);
1447 Else
1448 l_order_number := p_order_number|| null_space ||To_Char(p_trx_id);
1449 End If;
1450 Elsif p_order_type In (14, 17) Then
1451 l_temp := Substr(msc_get_name.get_order_number
1452 (p_inst_id, p_plan_id,
1453 p_disposition_id, 1),1,240);
1454 If l_temp Is Null Then
1455 l_order_number := To_Char(p_disposition_id);
1456 Else
1457 l_order_number := l_temp ||null_space || To_Char(p_disposition_id);
1458 End If;
1459 Else
1460 l_order_number := p_order_number;
1461 End If;
1462 return l_order_number;
1463
1464 end getOrderNumber;
1465
1466 function getDeptResInstCode(p_plan_id number, p_instance_id number,
1467 p_org_id number, p_dept_id number, p_res_id number, p_res_instance_id number,
1468 p_serial_number varchar2) return varchar2 is
1469
1470 cursor name is
1471 select mtp.organization_code
1472 ||':'||mdr.department_code || ':' || mdr.resource_code
1473 from msc_department_resources mdr,
1474 msc_trading_partners mtp
1475 where mdr.department_id = p_dept_id
1476 and mdr.resource_id = p_res_id
1477 and mdr.plan_id = p_plan_id
1478 and mdr.organization_id = p_org_id
1479 and mdr.sr_instance_id = p_instance_id
1480 and mtp.partner_type =3
1481 and mtp.sr_tp_id = mdr.organization_id
1482 and mtp.sr_instance_id = mdr.sr_instance_id;
1483
1484 cursor inst_name is
1485 select msc_get_name.item_name(mdri.equipment_item_id, null, null, null)
1486 ||decode(mdri.serial_number, null, null_space, COLON_SEPARATOR || mdri.serial_number)
1487 from msc_dept_res_instances mdri,
1488 msc_department_resources mdr,
1489 msc_trading_partners mtp
1490 where mdr.plan_id = p_plan_id
1491 and mdr.sr_instance_id = p_instance_id
1492 and mdr.organization_id = p_org_id
1493 and mdr.department_id = p_dept_id
1494 and mdr.resource_id = p_res_id
1495 and mdri.plan_id = mdr.plan_id
1496 and mdri.sr_instance_id = mdr.sr_instance_id
1497 and mdri.organization_id = mdr.organization_id
1498 and mdri.department_id = nvl(mdr.owning_department_id, mdr.department_id)
1499 and mdri.resource_id = mdr.resource_id
1500 and mdri.res_instance_id = p_res_instance_id
1501 and nvl(mdri.serial_number, MBP_NULL_VALUE_CHAR) = nvl(p_serial_number, MBP_NULL_VALUE_CHAR)
1502 and mtp.partner_type = 3
1503 and mtp.sr_tp_id = mdr.organization_id
1504 and mtp.sr_instance_id = mdr.sr_instance_id;
1505
1506 v_name varchar2(240);
1507 v_inst_name varchar2(240);
1508 begin
1509
1510 if (p_res_instance_id = mbp_null_value) then
1511 return '';
1512 elsif (p_res_instance_id is not null) then
1513 open inst_name;
1514 fetch inst_name into v_inst_name;
1515 close inst_name;
1516 return v_inst_name;
1517 else
1518 open name;
1519 fetch name into v_name;
1520 close name;
1521 return v_name;
1522 end if;
1523
1524 end getDeptResInstCode;
1525
1526 procedure getBatchValues(p_plan_id number, p_instance_id number, p_batch_number number,
1527 p_res_desc out nocopy varchar2, p_min_capacity out nocopy number, p_max_capacity out nocopy number,
1528 p_capacity_used out nocopy number) is
1529
1530 cursor c_batch is
1531 select mdr.resource_description,
1532 nvl(mrr.minimum_capacity, mdr.min_capacity),
1533 nvl(mrr.maximum_capacity, mdr.max_capacity),
1534 mrr.capacity_consumed_ratio * nvl(mrr.maximum_capacity, mdr.max_capacity) capacity_used
1535 from msc_resource_requirements mrr,
1536 msc_department_resources mdr
1537 where mrr.plan_id = p_plan_id
1538 and mrr.sr_instance_id = p_instance_id
1539 and mrr.batch_number = p_batch_number
1540 and mdr.plan_id = mrr.plan_id
1541 and mdr.organization_id = mrr.organization_id
1542 and mdr.sr_instance_id = mrr.sr_instance_id
1543 and mdr.department_id = mrr.department_id
1544 and mdr.resource_id = mrr.resource_id;
1545 begin
1546
1547 open c_batch;
1548 fetch c_batch into p_res_desc, p_min_capacity, p_max_capacity, p_capacity_used;
1549 close c_batch;
1550
1551 end getBatchValues;
1552
1553 function getTansitionValue(p_plan_id number, p_instance_id number,
1554 p_org_id number, p_dept_id number, p_res_id number, p_from_setup_id number,
1555 p_to_setup_id number, p_value_code varchar2) return varchar2 is
1556
1557 cursor c_mst is
1558 select
1559 mst.transition_time,
1560 mst.transition_uom,
1561 mst.transition_penalty,
1562 mst.standard_operation_code
1563 from
1564 msc_setup_transitions mst
1565 where mst.plan_id = p_plan_id
1566 and mst.sr_instance_id = p_instance_id
1567 and mst.resource_id = p_res_id
1568 and mst.organization_id = p_org_id
1569 and mst.from_setup_id = p_from_setup_id
1570 and mst.to_setup_id = p_to_setup_id;
1571
1572 l_transition_time number;
1573 l_transition_uom varchar2(10);
1574 l_transition_penalty number;
1575 l_std_op_code varchar2(10);
1576 begin
1577
1578 open c_mst;
1579 fetch c_mst into l_transition_time, l_transition_uom,
1580 l_transition_penalty, l_std_op_code;
1581 close c_mst;
1582
1583 if (p_value_code = 'TRANSITION_TIME') then
1584 return l_transition_time;
1585 elsif (p_value_code = 'TRANSITION_UOM') then
1586 return l_transition_uom;
1587 elsif (p_value_code = 'TRANSITION_PENALTY') then
1588 return l_transition_penalty;
1589 elsif (p_value_code = 'STANDARD_OPERATION_CODE') then
1590 return l_std_op_code;
1591 else
1592 return null_space;
1593 end if;
1594
1595 end getTansitionValue;
1596
1597 function getDmdPriority(p_plan_id number,
1598 p_instance_id number, p_transaction_id number) return number is
1599
1600 cursor dmd_cur is
1601 select min(md.demand_priority)
1602 from msc_demands md,
1603 msc_full_pegging mfp2,
1604 msc_full_pegging mfp1
1605 where mfp1.plan_id = p_plan_id
1606 and mfp1.transaction_id = p_transaction_id
1607 and mfp1.sr_instance_id = p_instance_id
1608 and mfp2.pegging_id = mfp1.end_pegging_id
1609 and mfp2.plan_id = mfp1.plan_id
1610 and mfp2.sr_instance_id = mfp1.sr_instance_id
1611 and md.plan_id = mfp2.plan_id
1612 and md.sr_instance_id = mfp2.sr_instance_id
1613 and md.demand_id = mfp2.demand_id
1614 and md.demand_priority is not null;
1615
1616 l_priority number;
1617
1618 begin
1619
1620 if p_transaction_id is null or p_plan_id is null or
1621 p_instance_id is null then
1622 return null;
1623 end if;
1624
1625 open dmd_cur;
1626 fetch dmd_cur into l_priority;
1627 close dmd_cur;
1628 return(l_priority);
1629
1630 end getDmdPriority;
1631
1632 function isResChargeable(p_plan_id number, p_instance_id number, p_org_id number,
1633 p_dept_id number, p_res_id number, p_res_instance_id number) RETURN number is
1634
1635 cursor c_charge is
1636 select chargeable_flag
1637 from msc_department_resources mdr
1638 where mdr.plan_id = p_plan_id
1639 and mdr.sr_instance_id = p_instance_id
1640 and mdr.organization_id = p_org_id
1641 and mdr.department_id = p_dept_id
1642 and mdr.resource_id = p_res_id;
1643
1644 l_chargeable_flag number;
1645 begin
1646
1647 open c_charge;
1648 fetch c_charge into l_chargeable_flag;
1649 close c_charge;
1650 return l_chargeable_flag;
1651
1652 end isResChargeable;
1653
1654 function isSupplyLate(p_plan_id number,
1655 p_instance_id number, p_organization_id number,
1656 p_inventory_item_id number, p_transaction_id number) return number is
1657
1658 cursor c is
1659 select 1
1660 from msc_exception_details
1661 where number1 = p_transaction_id
1662 and sr_instance_id = p_instance_id
1663 and plan_id = p_plan_id
1664 and exception_type =36
1665 and organization_id = p_organization_id
1666 and inventory_item_id = p_inventory_item_id;
1667
1668 v_isLate number := 0;
1669
1670 begin
1671
1672 open c;
1673 fetch c into v_islate;
1674 close c;
1675 return v_isLate;
1676
1677 end isSupplyLate;
1678
1679 function getActualStartDate(p_order_type number, p_make_buy_code number,
1680 p_org_id number,p_source_org_id number,
1681 p_dock_date date, p_wip_start_date date,
1682 p_ship_date date, p_schedule_date date,
1683 p_source_supp_id number) return varchar2 is
1684
1685 p_actual_start_date date;
1686 p_date varchar2(20);
1687 p_supply_type number;
1688
1689 begin
1690
1691 if p_order_type = 3 then --5165402 bugfix
1692 p_supply_type := MAKE_SUPPLY;
1693 elsif p_org_id <> nvl(p_source_org_id, mbp_null_value) then
1694 p_supply_type := TRANSFER_SUPPLY;
1695 elsif p_order_type in (1,2,8,11,12) then
1696 p_supply_type := BUY_SUPPLY;
1697 elsif p_order_type = 5 then
1698 if p_source_supp_id is not null then --5057260 bugfix
1699 p_supply_type := BUY_SUPPLY;
1700 else
1701 p_supply_type := MAKE_SUPPLY;
1702 end if;
1703 else
1704 p_supply_type := MAKE_SUPPLY;
1705 end if;
1706
1707 if p_supply_type = BUY_SUPPLY then
1708 p_actual_start_date := p_dock_date;
1709 elsif p_supply_type = MAKE_SUPPLY then
1710 p_actual_start_date := p_wip_start_date;
1711 elsif p_supply_type = TRANSFER_SUPPLY then
1712 p_actual_start_date := p_ship_date;
1713 else
1714 p_actual_start_date := p_schedule_date;
1715 end if;
1716 return to_char(nvl(p_actual_start_date,p_schedule_date),format_mask);
1717
1718 end getActualStartDate;
1719
1720 function isCriticalSupply(p_plan_id number, p_end_demand_id number,
1721 p_transaction_id number, p_inst_id number) Return number IS
1722
1723 cursor critical_cur is
1724 select nvl(path_number,1)
1725 from msc_critical_paths
1726 where plan_id = p_plan_id
1727 and sr_instance_id = p_inst_id
1728 and supply_id = p_transaction_id
1729 -- and routing_sequence_id is null
1730 and demand_id = p_end_demand_id;
1731
1732 isCritical number :=-1;
1733
1734 begin
1735
1736 open critical_cur;
1737 fetch critical_cur into iscritical;
1738 close critical_cur;
1739 return iscritical;
1740
1741 end isCriticalSupply;
1742
1743 function isCriticalRes(p_plan_id number,
1744 p_end_demand_id number, p_transaction_id number,
1745 p_inst_id number, p_operation_seq_id number,
1746 p_routing_seq_id number) return number is
1747
1748 cursor critical_cur is
1749 select nvl(path_number,1)
1750 from msc_critical_paths
1751 where plan_id = p_plan_id
1752 and supply_id = p_transaction_id
1753 and sr_instance_id = p_inst_id
1754 and demand_id = p_end_demand_id
1755 and nvl(routing_sequence_id,-1) = nvl(p_routing_seq_id,-1)
1756 and operation_sequence_id = p_operation_seq_id;
1757
1758 isCritical number;
1759
1760 begin
1761 isCritical := -1;
1762 open critical_cur;
1763 fetch critical_cur into iscritical;
1764 close critical_cur;
1765 return isCritical;
1766
1767 end isCriticalRes;
1768
1769 function getSupplyType(p_order_type number, p_make_buy_code number,
1770 p_org_id number,p_source_org_id number) return number is
1771
1772 p_supply_type number;
1773
1774 begin
1775
1776 if p_org_id <> p_source_org_id then
1777 p_supply_type := TRANSFER_SUPPLY;
1778 elsif p_order_type in (1,2,8,11,12) then
1779 p_supply_type := BUY_SUPPLY;
1780 elsif p_order_type = 5 and
1781 p_make_buy_code = 2 then
1782 p_supply_type := BUY_SUPPLY;
1783 else
1784 p_supply_type := MAKE_SUPPLY;
1785 end if;
1786 return p_supply_type;
1787
1788 end getSupplyType;
1789
1790 function getPlanInfo(p_plan_id number,
1791 p_first_date out nocopy date, p_last_date out nocopy date,
1792 p_hour_bkt_start_date out nocopy date, p_day_bkt_start_date out nocopy date,
1793 p_plan_start_date out nocopy date, p_plan_end_date out nocopy date,
1794 p_plan_type out nocopy number) return varchar2 IS
1795
1796 cursor cutoff_date_cur is
1797 select curr_start_date, curr_cutoff_date,
1798 nvl(min_cutoff_bucket,0)+nvl(hour_cutoff_bucket,0)+data_start_date daybkt_start,
1799 nvl(min_cutoff_bucket,0)+data_start_date hrbkt_start,
1800 decode(nvl(hour_cutoff_bucket,0),0, to_date(null),data_start_date) minbkt_start,
1801 sr_instance_id,
1802 organization_id
1803 from msc_plans
1804 where plan_id = p_plan_id;
1805
1806 cursor daylevel_date_cur is
1807 select min(mpb.bkt_start_date), max(mpb.bkt_end_date)
1808 from msc_plan_buckets mpb,
1809 msc_plans mp
1810 where mp.plan_id =p_plan_id
1811 and mpb.plan_id = mp.plan_id
1812 and mpb.organization_id = mp.organization_id
1813 and mpb.sr_instance_id = mp.sr_instance_id
1814 and mpb.bucket_type =1;
1815
1816 v_date date_arr;
1817 v_period varchar2(32000);
1818 p_bkt_type number;
1819 v_buckets varchar2(3200);
1820 v_min_day number;
1821 v_hour_day number;
1822 v_date_day number;
1823 v_bkt_date date;
1824
1825 cursor bkt_cur is
1826 select max(mpb.bkt_end_date)
1827 from msc_plan_buckets mpb,
1828 msc_plans mp
1829 where mp.plan_id =p_plan_id
1830 and mpb.plan_id = mp.plan_id
1831 and mpb.organization_id = mp.organization_id
1832 and mpb.sr_instance_id = mp.sr_instance_id
1833 and mpb.bucket_type = p_bkt_type;
1834
1835 cursor c_plan_cal is
1836 select mtp.calendar_code, mtp.sr_instance_id,
1837 mtp.calendar_exception_set_id, plan_type
1838 from msc_trading_partners mtp,
1839 msc_plans mp
1840 where mp.plan_id = p_plan_id
1841 and mp.sr_instance_id = mtp.sr_instance_id
1842 and mp.organization_id = mtp.sr_tp_id
1843 and mtp.partner_type = 3;
1844
1845 cursor c_ds_orgs is
1846 select organization_id,
1847 nvl(curr_frozen_horizon_days, frozen_horizon_days) frozen_days
1848 from msc_plan_organizations
1849 where plan_id = p_plan_id
1850 and nvl(curr_ds_enabled_flag, ds_enabled_flag) = 1;
1851
1852 v_org_id number_arr;
1853 v_frozen_days number_arr;
1854 v_ds_orgs_stream varchar2(200);
1855
1856 p_min_bkt_start_date date;
1857 begin
1858 open c_plan_cal;
1859 fetch c_plan_cal into g_plan_cal, g_plan_cal_inst_id,
1860 g_plan_cal_excp_id, p_plan_type;
1861 close c_plan_cal;
1862
1863 g_plan_type := p_plan_type;
1864 g_plan_id := p_plan_id;
1865
1866 open daylevel_date_cur;
1867 fetch daylevel_date_cur into p_first_date, p_last_date;
1868 close daylevel_date_cur;
1869
1870 open cutoff_date_cur;
1871 fetch cutoff_date_cur into p_plan_start_date, p_plan_end_date,
1872 p_day_bkt_start_date, p_hour_bkt_start_date, p_min_bkt_start_date,
1873 g_plan_inst_id, g_plan_org_id;
1874 close cutoff_date_cur;
1875
1876 -- fetch period start date
1877 select greatest(mpsd.period_start_date, mp.data_start_date)
1878 bulk collect into v_date
1879 from msc_trading_partners tp,
1880 msc_period_start_dates mpsd,
1881 msc_plans mp
1882 where mpsd.calendar_code = tp.calendar_code
1883 and mpsd.sr_instance_id = tp.sr_instance_id
1884 and mpsd.exception_set_id = tp.calendar_exception_set_id
1885 and tp.sr_instance_id = mp.sr_instance_id
1886 and tp.sr_tp_id = mp.organization_id
1887 and tp.partner_type =3
1888 and mp.plan_id = p_plan_id
1889 and (mpsd.period_start_date
1890 between mp.data_start_date and mp.curr_cutoff_date
1891 or mpsd.next_date between mp.data_start_date and mp.curr_cutoff_date)
1892 order by mpsd.period_start_date;
1893
1894 v_period := to_char(v_date.count);
1895 for a in 1 .. v_date.count loop
1896 v_period := v_period || field_seperator|| to_char(v_date(a), format_mask);
1897 end loop;
1898
1899 -- fetch bucket days
1900 select nvl(min_cutoff_bucket, 0),
1901 nvl(hour_cutoff_bucket, 0),
1902 nvl(daily_cutoff_bucket, 0)
1903 into v_min_day, v_hour_day, v_date_day
1904 from msc_plans
1905 where plan_id = p_plan_id;
1906
1907 if v_min_day <> 0 then
1908 v_buckets := to_char(p_first_date + v_min_day, format_mask);
1909 else
1910 v_buckets := v_buckets || field_seperator|| null_space;
1911 end if;
1912
1913 if v_hour_day <> 0 then
1914 v_buckets := v_buckets || field_seperator||
1915 to_char(p_first_date + v_min_day+v_hour_day, format_mask);
1916 else
1917 v_buckets := v_buckets || field_seperator|| null_space;
1918 end if;
1919 if v_min_day+v_hour_day <> v_date_day then
1920 v_buckets := v_buckets || field_seperator|| to_char(p_last_date, format_mask);
1921 else
1922 v_buckets := v_buckets || field_seperator|| null_space;
1923 end if;
1924
1925 p_bkt_type := 1;
1926 for a in 1..2 loop -- {
1927 v_bkt_date := null;
1928 p_bkt_type := p_bkt_type +1;
1929 open bkt_cur;
1930 fetch bkt_cur into v_bkt_date;
1931 close bkt_cur;
1932 if v_bkt_date is not null then
1933 v_buckets := v_buckets || field_seperator||to_char(v_bkt_date, format_mask);
1934 else
1935 v_buckets := v_buckets || field_seperator|| null_space;
1936 end if;
1937 end loop; -- }
1938
1939 open c_ds_orgs;
1940 fetch c_ds_orgs bulk collect into v_org_id, v_frozen_days;
1941 close c_ds_orgs;
1942
1943 if (v_org_id.count = 0) then
1944 v_ds_orgs_stream := record_seperator||'0';
1945 end if;
1946 for a in 1..v_org_id.count
1947 loop
1948 if ( v_ds_orgs_stream is null ) then
1949 v_ds_orgs_stream := record_seperator
1950 || v_org_id.count || field_seperator|| v_org_id(a)
1951 || field_seperator || nvl(to_char(v_frozen_days(a)), null_space);
1952 else
1953 v_ds_orgs_stream := v_ds_orgs_stream || field_seperator ||
1954 v_org_id(a) || field_seperator || nvl(to_char(v_frozen_days(a)), null_space);
1955 end if;
1956 end loop;
1957
1958 g_plan_cal_from_profile := fnd_profile.value('MSC_BKT_REFERENCE_CALENDAR');
1959
1960 return p_plan_type || field_seperator ||
1961 to_char(p_plan_start_date, format_mask) || field_seperator ||
1962 to_char(p_plan_end_date, format_mask) || field_seperator ||
1963 v_buckets || record_seperator || v_period || v_ds_orgs_stream;
1964
1965 end getPlanInfo;
1966
1967 procedure sendSegmentPegStream(p_row_type number, p_row_index number, p_from_index number,
1968 p_producer_trans_id number_arr, p_producer_sr_instance_id number_arr,
1969 p_producer_op_seq_id number_arr, p_producer_op_seq_num number_arr, p_producer_res_seq_num number_arr,
1970 p_consumer_trans_id number_arr, p_consumer_sr_instance_id number_arr,
1971 p_consumer_op_seq_id number_arr, p_consumer_op_seq_num number_arr, p_consumer_res_seq_num number_arr,
1972 p_segment_start_date date_arr, p_segment_end_date date_arr, p_segment_quantity number_arr,
1973 p_consumer_start_date date_arr, p_consumer_end_date date_arr, p_allocation_type number_arr,
1974 p_dependency_type number_arr, p_minimum_time_offset number_arr,
1975 p_maximum_time_offset number_arr, p_actual_time_offset number_arr,
1976 p_data_stream IN OUT NOCOPY msc_gantt_utils.maxCharTbl) is
1977
1978 oneBigRecord maxCharTbl := maxCharTbl(0);
1979 l_data_stream maxCharTbl := maxCharTbl(0);
1980 reccount number := 0;
1981 j number :=1;
1982 ctr number;
1983 v_one_record varchar2(1000);
1984 v_max_len number;
1985 l_temp_len number;
1986 begin
1987
1988 put_line(' sendSegmentPegStream in');
1989 oneBigRecord.delete;
1990 oneBigRecord.extend;
1991
1992 for b in 1 .. p_producer_trans_id.count loop -- {
1993 v_one_record := p_producer_trans_id(b)
1994 || field_seperator || p_producer_sr_instance_id(b)
1995 || field_seperator || nvl(to_char(p_producer_op_seq_id(b)), null_space)
1996 || field_seperator || nvl(to_char(p_producer_op_seq_num(b)), null_space)
1997 || field_seperator || nvl(to_char(p_producer_res_seq_num(b)), null_space)
1998 || field_seperator || p_consumer_trans_id(b)
1999 || field_seperator || p_consumer_sr_instance_id(b)
2000 || field_seperator || nvl(to_char(p_consumer_op_seq_id(b)), null_space)
2001 || field_seperator || nvl(to_char(p_consumer_op_seq_num(b)), null_space)
2002 || field_seperator || nvl(to_char(p_consumer_res_seq_num(b)), null_space)
2003 || field_seperator || nvl(to_char(p_segment_start_date(b),format_mask), null_space)
2004 || field_seperator || nvl(to_char(p_segment_end_date(b), format_mask), null_space)
2005 || field_seperator || fnd_number.number_to_canonical(nvl(p_segment_quantity(b),0))
2006 || field_seperator || nvl(to_char(p_consumer_start_date(b), format_mask), null_space)
2007 || field_seperator || nvl(to_char(p_consumer_end_date(b), format_mask), null_space)
2008 || field_seperator || nvl(to_char(p_allocation_type(b)), null_space)
2009 || field_seperator || nvl(to_char(p_dependency_type(b)), null_space)
2010 || field_seperator || nvl(to_char(p_minimum_time_offset(b)), null_space)
2011 || field_seperator || nvl(to_char(p_maximum_time_offset(b)), null_space)
2012 || field_seperator || nvl(to_char(p_actual_time_offset(b)), null_space);
2013
2014 v_max_len := nvl(length(oneBigRecord(j)),0) + nvl(length(v_one_record),0);
2015 if v_max_len > 30000 then
2016 j := j+1;
2017 oneBigRecord.extend;
2018 end if;
2019 oneBigRecord(j) := oneBigRecord(j) || record_seperator || v_one_record;
2020 recCount := recCount+1;
2021 end loop; -- }
2022
2023 if ( recCount > 0 ) then -- {
2024 ctr := p_data_stream.count;
2025 if ( nvl(length(p_data_stream(ctr)),0) = 1 ) then
2026 p_data_stream(ctr) := to_char(p_row_index) || field_seperator || recCount;
2027 elsif ( nvl(length(p_data_stream(ctr)),0) < 30000 ) then
2028 p_data_stream(ctr) := p_data_stream(ctr) || record_seperator
2029 || to_char(p_row_index) || field_seperator || recCount;
2030 else
2031 p_data_stream.extend;
2032 ctr := ctr + 1;
2033 p_data_stream(ctr) := p_data_stream(ctr) || record_seperator
2034 || to_char(p_row_index) || field_seperator || recCount;
2035 end if;
2036
2037 for j in 1 .. oneBigRecord.count loop -- {
2038 l_temp_len := nvl(length(p_data_stream(ctr)),0)+ nvl(length(oneBigRecord(j)),0);
2039 if ( j = 1 ) then
2040 if (l_temp_len < 30000 ) then
2041 p_data_stream(ctr) := p_data_stream(ctr) || oneBigRecord(j);
2042 else
2043 p_data_stream.extend;
2044 ctr := ctr + 1;
2045 p_data_stream(ctr) := p_data_stream(ctr) || oneBigRecord(j);
2046 end if;
2047 elsif ( l_temp_len < 30000 ) then
2048 p_data_stream(ctr) := p_data_stream(ctr) || oneBigRecord(j);
2049 else
2050 p_data_stream.extend;
2051 ctr := ctr + 1;
2052 p_data_stream(ctr) := oneBigRecord(j);
2053 end if;
2054 end loop; -- }
2055 end if; -- }
2056 put_line(' sendSegmentPegStream out');
2057
2058 end sendSegmentPegStream;
2059
2060 procedure sendResReqAvailSuppStream(p_row_type number, p_row_index number,
2061 p_from_index number, p_start date_arr, p_end date_arr,
2062 p_resource_hours number_arr, p_resource_units number_arr,
2063 p_schedule_flag number_arr,
2064 p_data_stream IN OUT NOCOPY msc_gantt_utils.maxCharTbl,
2065 p_avail_qty number_arr default null, p_overload_qty number_arr default null,
2066 p_consume_qty number_arr default null, p_cum_avail_qty number_arr default null) is
2067
2068 oneBigRecord maxCharTbl := maxCharTbl(0);
2069 l_data_stream maxCharTbl := maxCharTbl(0);
2070 reccount number := 0;
2071 j number :=1;
2072 ctr number;
2073 v_one_record varchar2(100);
2074 v_max_len number;
2075 l_temp_len number;
2076
2077 begin
2078
2079 oneBigRecord.delete;
2080 oneBigRecord.extend;
2081
2082 for b in 1 .. p_start.count loop -- {
2083 if ( p_row_type = RES_REQ_ROW_TYPE ) then
2084 v_one_record := to_char(p_start(b),format_mask) ||
2085 field_seperator || to_char(p_end(b),format_mask) ||
2086 field_seperator || nvl(to_char(fnd_number.number_to_canonical(p_resource_hours(b))), null_space) ||
2087 field_seperator || nvl(to_char(fnd_number.number_to_canonical(p_resource_units(b))), null_space) ||
2088 field_seperator || nvl(to_char(p_schedule_flag(b)), null_space) ||
2089 field_seperator || nvl(to_char(fnd_number.number_to_canonical(p_avail_qty(b))), null_space);
2090 elsif ( p_row_type = SUPP_ALL_ROW_TYPE ) then
2091 v_one_record := to_char(p_start(b),format_mask) ||
2092 field_seperator || nvl(to_char(fnd_number.number_to_canonical(p_consume_qty(b))), null_space)||
2093 field_seperator || nvl(to_char(fnd_number.number_to_canonical(p_overload_qty(b))), null_space)||
2094 field_seperator || nvl(to_char(fnd_number.number_to_canonical(p_avail_qty(b))), null_space);
2095 elsif ( p_row_type in (RES_CHARGES_ROW_TYPE, RES_AVAIL_ROW_TYPE) ) then
2096 v_one_record := to_char(p_start(b),format_mask) ||
2097 field_seperator || to_char(p_end(b),format_mask) ||
2098 field_seperator || nvl(to_char(fnd_number.number_to_canonical(p_resource_hours(b))), null_space)||
2099 field_seperator || nvl(to_char(fnd_number.number_to_canonical(p_resource_units(b))), null_space);
2100 elsif ( p_row_type = RES_REQ_DISPLAY_ROW_TYPE ) then
2101 v_one_record := to_char(p_start(b),format_mask) ||
2102 field_seperator || nvl(to_char(p_schedule_flag(b)), null_space)||
2103 field_seperator || nvl(to_char(fnd_number.number_to_canonical(p_avail_qty(b))), null_space)||
2104 field_seperator || nvl(to_char(fnd_number.number_to_canonical(p_resource_hours(b))), null_space);
2105 end if;
2106
2107 v_max_len := nvl(length(oneBigRecord(j)),0) + nvl(length(v_one_record),0);
2108 if v_max_len > 30000 then
2109 j := j+1;
2110 oneBigRecord.extend;
2111 end if;
2112 oneBigRecord(j) := oneBigRecord(j) || record_seperator || v_one_record;
2113 recCount := recCount+1;
2114 end loop; -- }
2115
2116 if ( recCount > 0 ) then -- {
2117 ctr := p_data_stream.count;
2118 if ( nvl(length(p_data_stream(ctr)),0) = 1 ) then
2119 p_data_stream(ctr) := to_char(p_row_index) || field_seperator || recCount;
2120 elsif ( nvl(length(p_data_stream(ctr)),0) < 30000 ) then
2121 p_data_stream(ctr) := p_data_stream(ctr) || record_seperator
2122 || to_char(p_row_index) || field_seperator || recCount;
2123 else
2124 p_data_stream.extend;
2125 ctr := ctr + 1;
2126 p_data_stream(ctr) := p_data_stream(ctr) || record_seperator
2127 || to_char(p_row_index) || field_seperator || recCount;
2128 end if;
2129
2130 put_line('sendResReqAvailSuppStream: row_index row_type rec_count: '
2131 ||to_char(p_row_index) || field_seperator || to_char(p_row_type)
2132 || field_seperator || to_char(recCount));
2133
2134 for j in 1 .. oneBigRecord.count loop -- {
2135 l_temp_len := nvl(length(p_data_stream(ctr)),0)+ nvl(length(oneBigRecord(j)),0);
2136 if ( j = 1 ) then
2137 if (l_temp_len < 30000 ) then
2138 p_data_stream(ctr) := p_data_stream(ctr) || oneBigRecord(j);
2139 else
2140 p_data_stream.extend;
2141 ctr := ctr + 1;
2142 p_data_stream(ctr) := p_data_stream(ctr) || oneBigRecord(j);
2143 end if;
2144 elsif ( l_temp_len < 30000 ) then
2145 p_data_stream(ctr) := p_data_stream(ctr) || oneBigRecord(j);
2146 else
2147 p_data_stream.extend;
2148 ctr := ctr + 1;
2149 p_data_stream(ctr) := oneBigRecord(j);
2150 end if;
2151 end loop; -- }
2152
2153 end if; -- }
2154
2155 end sendResReqAvailSuppStream;
2156
2157 procedure sendResActStream(p_row_index number, p_from_index number,
2158 p_inst_id number_arr, p_org_id number_arr,
2159 p_supply_id number_arr, p_trx_id number_arr, p_status number_arr,
2160 p_applied number_arr, p_res_firm_flag number_arr, p_sup_firm_flag number_arr,
2161 p_start_date date_arr, p_end_date date_arr, p_schedule_flag number_arr,
2162 p_res_constraint number_arr, p_qty number_arr, p_batch_number number_arr,
2163 p_resource_units number_arr, p_group_sequence_id number_arr,
2164 p_group_sequence_number number_arr, p_bar_text char_arr,
2165 p_display_type number_arr, p_cepst date_arr, p_cepct date_arr,
2166 p_ulpst date_arr, p_ulpct date_arr, p_uepst date_arr, p_uepct date_arr,
2167 p_eact date_arr, p_dept_id number_arr, p_res_id number_arr, p_item_id number_arr,
2168 p_order_number char_arr, p_op_seq number_arr, p_res_seq number_arr, p_res_desc char_arr,
2169 p_item_name char_arr, p_assy_item_desc char_arr, p_schedule_qty number_arr,
2170 p_from_setup_code char_arr, p_to_setup_code char_arr, p_std_op_code char_arr,
2171 p_changeover_time char_arr, p_changeover_penalty char_arr,
2172 p_min_capacity number_arr, p_max_capacity number_arr, p_capacity_used number_arr,
2173 p_overload_flag number_arr,
2174 p_data_stream IN OUT NOCOPY msc_gantt_utils.maxCharTbl) is
2175
2176 oneBigRecord maxCharTbl := maxCharTbl(0);
2177 l_data_stream maxCharTbl := maxCharTbl(0);
2178 reccount number := 0;
2179 j number :=1;
2180 ctr number;
2181 v_one_record varchar2(1500);
2182 v_max_len number;
2183 l_temp_len number;
2184
2185
2186 begin
2187 oneBigRecord.delete;
2188 oneBigRecord.extend;
2189
2190 for b in 1 .. p_start_date.count loop -- {
2191 v_one_record := p_row_index || FIELD_SEPERATOR || null_space
2192 || FIELD_SEPERATOR || null_space || FIELD_SEPERATOR || null_space
2193 || FIELD_SEPERATOR || null_space
2194 || FIELD_SEPERATOR || null_space || FIELD_SEPERATOR || null_space
2195 || FIELD_SEPERATOR || to_char(p_start_date(b), format_mask)
2196 || FIELD_SEPERATOR || to_char(p_end_date(b), format_mask)
2197 || FIELD_SEPERATOR || fnd_number.number_to_canonical(p_qty(b)) || FIELD_SEPERATOR || null_space
2198 || FIELD_SEPERATOR || p_batch_number(b) || FIELD_SEPERATOR || fnd_number.number_to_canonical(p_resource_units(b))
2199 || FIELD_SEPERATOR || null_space || FIELD_SEPERATOR || null_space
2200 || FIELD_SEPERATOR || p_sup_firm_flag(b) || FIELD_SEPERATOR || p_res_firm_flag(b)
2201 || FIELD_SEPERATOR || p_status(b) || FIELD_SEPERATOR || p_applied(b)
2202 || FIELD_SEPERATOR || p_schedule_flag(b) || FIELD_SEPERATOR || p_supply_id(b)
2203 || FIELD_SEPERATOR || p_trx_id(b) || FIELD_SEPERATOR || escapeSplChars(p_bar_text(b))
2204 || FIELD_SEPERATOR || nvl(to_char(p_display_type(b)), null_space)
2205 || FIELD_SEPERATOR || nvl(to_char(p_cepst(b),format_mask),null_space)
2206 || FIELD_SEPERATOR || nvl(to_char(p_cepct(b),format_mask),null_space)
2207 || FIELD_SEPERATOR || nvl(to_char(p_ulpst(b),format_mask),null_space)
2208 || FIELD_SEPERATOR || nvl(to_char(p_ulpct(b),format_mask),null_space)
2209 || FIELD_SEPERATOR || nvl(to_char(p_uepst(b),format_mask),null_space)
2210 || FIELD_SEPERATOR || nvl(to_char(p_uepct(b),format_mask),null_space)
2211 || FIELD_SEPERATOR || nvl(to_char(p_eact(b),format_mask),null_space)
2212 || FIELD_SEPERATOR || nvl(to_char(p_inst_id(b)), null_space)
2213 || FIELD_SEPERATOR || nvl(to_char(p_org_id(b)), null_space)
2214 || FIELD_SEPERATOR || nvl(to_char(p_dept_id(b)), null_space)
2215 || FIELD_SEPERATOR || nvl(to_char(p_res_id(b)), null_space)
2216 || FIELD_SEPERATOR || nvl(to_char(p_item_id(b)), null_space)
2217 || FIELD_SEPERATOR || nvl(to_char(p_res_seq(b)), null_space)
2218 || FIELD_SEPERATOR || nvl(escapeSplChars(p_order_number(b)), null_space)
2219 || FIELD_SEPERATOR || nvl(to_char(p_op_seq(b)), null_space)
2220 || FIELD_SEPERATOR || nvl(escapeSplChars(p_res_desc(b)), null_space)
2221 || FIELD_SEPERATOR || nvl(escapeSplChars(p_item_name(b)), null_space)
2222 || FIELD_SEPERATOR || nvl(escapeSplChars(p_assy_item_desc(b)), null_space)
2223 || FIELD_SEPERATOR || nvl(to_char(fnd_number.number_to_canonical(p_schedule_qty(b))), null_space)
2224 || FIELD_SEPERATOR || nvl(escapeSplChars(p_from_setup_code(b)), null_space)
2225 || FIELD_SEPERATOR || nvl(escapeSplChars(p_to_setup_code(b)), null_space)
2226 || FIELD_SEPERATOR || nvl(escapeSplChars(p_std_op_code(b)), null_space)
2227 || FIELD_SEPERATOR || nvl(to_char(p_changeover_time(b)), null_space)
2228 || FIELD_SEPERATOR || nvl(to_char(p_changeover_penalty(b)), null_space)
2229 || FIELD_SEPERATOR || nvl(to_char(fnd_number.number_to_canonical(p_min_capacity(b))), null_space)
2230 || FIELD_SEPERATOR || nvl(to_char(fnd_number.number_to_canonical(p_max_capacity(b))), null_space)
2231 || FIELD_SEPERATOR || nvl(to_char(fnd_number.number_to_canonical(p_capacity_used(b))), null_space)
2232 || FIELD_SEPERATOR || nvl(to_char(p_group_sequence_id(b)), null_space)
2233 || FIELD_SEPERATOR || nvl(to_char(p_group_sequence_number(b)), null_space)
2234 || FIELD_SEPERATOR || nvl(to_char(p_overload_flag(b)), null_space)
2235 || FIELD_SEPERATOR || null_space
2236 || FIELD_SEPERATOR || null_space
2237 || FIELD_SEPERATOR || null_space;
2238
2239 v_max_len := nvl(length(oneBigRecord(j)),0) + nvl(length(v_one_record),0);
2240 if v_max_len > 30000 then
2241 j := j+1;
2242 oneBigRecord.extend;
2243 end if;
2244 oneBigRecord(j) := oneBigRecord(j) || record_seperator || v_one_record;
2245 recCount := recCount+1;
2246 end loop; -- }
2247
2248 if ( recCount > 0 ) then -- {
2249
2250 ctr := p_data_stream.count;
2251 if ( nvl(length(p_data_stream(ctr)),0) = 1 ) then
2252 p_data_stream(ctr) := to_char(p_row_index) || field_seperator || recCount;
2253 elsif ( nvl(length(p_data_stream(ctr)),0) < 30000 ) then
2254 p_data_stream(ctr) := p_data_stream(ctr) || record_seperator
2255 || to_char(p_row_index) || field_seperator || recCount;
2256 else
2257 p_data_stream.extend;
2258 ctr := ctr + 1;
2259 p_data_stream(ctr) := p_data_stream(ctr) || record_seperator
2260 || to_char(p_row_index) || field_seperator || recCount;
2261 end if;
2262
2263 put_line(' sendResActStream: row_index rec_count: '|| to_char(p_row_index) || field_seperator || to_char(recCount));
2264
2265 for j in 1 .. oneBigRecord.count loop -- {
2266 l_temp_len := nvl(length(p_data_stream(ctr)),0)+ nvl(length(oneBigRecord(j)),0);
2267 if ( j = 1 ) then
2268 if (l_temp_len < 30000 ) then
2269 p_data_stream(ctr) := p_data_stream(ctr) || oneBigRecord(j);
2270 else
2271 p_data_stream.extend;
2272 ctr := ctr + 1;
2273 p_data_stream(ctr) := p_data_stream(ctr) || oneBigRecord(j);
2274 end if;
2275 elsif ( l_temp_len < 30000 ) then
2276 p_data_stream(ctr) := p_data_stream(ctr) || oneBigRecord(j);
2277 else
2278 p_data_stream.extend;
2279 ctr := ctr + 1;
2280 p_data_stream(ctr) := oneBigRecord(j);
2281 end if;
2282 end loop; -- }
2283 end if; -- }
2284
2285 end sendResActStream;
2286
2287 procedure populateResAvailGantt(p_query_id number,
2288 p_start_date date, p_end_date date) is
2289
2290 v_avail_start date_arr;
2291 v_avail_end date_arr;
2292 v_resource_hours number_arr;
2293 v_resource_units number_arr;
2294 v_row_index number_arr;
2295 v_schdule_flag number_arr;
2296
2297 l_res_rows number;
2298 l_res_inst_rows number;
2299 l_res_batch_rows number;
2300 l_res_inst_batch_rows number;
2301
2302 begin
2303
2304 --l_res_rows := msc_gantt_utils.isResRowInGantt(p_query_id, sys_no, sys_no, sys_yes);
2305 --l_res_inst_rows := msc_gantt_utils.isResRowInGantt(p_query_id, sys_yes, sys_no, sys_yes);
2306 --4997096 bugfix, instead calls the below procedure
2307 msc_gantt_utils.isResRowInGantt(p_query_id, l_res_rows, l_res_inst_rows, l_res_batch_rows, l_res_inst_batch_rows);
2308
2309 put_line('populateResAvailGantt: res - res inst - res batch - res inst batch : '
2310 ||l_res_rows ||' - '|| l_res_inst_rows ||' - '||l_res_batch_rows ||' - '||l_res_inst_batch_rows);
2311
2312 if ( l_res_rows = sys_yes or l_res_batch_rows = sys_yes ) then -- {
2313
2314 select mgq.row_index,
2315 mrr.shift_date + mrr.from_time/86400 start_date,
2316 decode(sign(mrr.to_time - mrr.from_time), 1,
2317 mrr.shift_date + mrr.to_time/86400,
2318 mrr.shift_date + 1 + mrr.to_time/86400) end_date,
2319 (decode(sign(to_time - from_time), 1,
2320 shift_date + to_time/86400,
2321 shift_date + 1 + to_time/86400) -
2322 (shift_date + from_time/86400)) * 24 * capacity_units res_hours,
2323 mrr.capacity_units,
2324 to_number(null) schdule_flag
2325 bulk collect into v_row_index, v_avail_start, v_avail_end,
2326 v_resource_hours, v_resource_units, v_schdule_flag
2327 from msc_net_resource_avail mrr,
2328 msc_gantt_query mgq
2329 where mgq.query_id = p_query_id
2330 and mgq.row_flag = SYS_YES
2331 and mgq.is_fetched = SYS_NO
2332 and mgq.res_instance_id = MBP_NULL_VALUE
2333 and mrr.plan_id = mgq.plan_id
2334 and mrr.sr_instance_id = mgq.sr_instance_id
2335 and mrr.organization_id = mgq.organization_id
2336 and mrr.department_id = mgq.department_id
2337 and mrr.resource_id = mgq.resource_id
2338 and nvl(mrr.parent_id,0) <> -1
2339 and mrr.capacity_units > 0
2340 and mrr.shift_date between p_start_date and p_end_date;
2341
2342 put_line('populateResAvailGantt: res rows: '||v_avail_start.count );
2343
2344 populateResDtlTabIntoGantt(p_query_id, RES_AVAIL_ROW_TYPE, v_row_index,
2345 v_avail_start, v_avail_end, v_resource_units, v_resource_hours,
2346 v_schdule_flag, SUMMARY_DATA);
2347
2348 end if; -- }
2349
2350 if ( l_res_inst_rows = sys_yes or l_res_inst_batch_rows = sys_yes ) then -- {
2351
2352 select mgq.row_index,
2353 mrr.shift_date + mrr.from_time/86400 start_date,
2354 decode(sign(mrr.to_time - mrr.from_time), 1,
2355 mrr.shift_date + mrr.to_time/86400,
2356 mrr.shift_date + 1 + mrr.to_time/86400) end_date,
2357 (decode(sign(to_time - from_time), 1,
2358 shift_date + to_time/86400,
2359 shift_date + 1 + to_time/86400) - (shift_date + from_time/86400)) * 24 res_hours,
2360 1 capacity_units,
2361 to_number(null) schdule_flag
2362 bulk collect into v_row_index, v_avail_start, v_avail_end,
2363 v_resource_hours, v_resource_units, v_schdule_flag
2364 from msc_net_res_inst_avail mrr,
2365 msc_gantt_query mgq
2366 where mgq.query_id = p_query_id
2367 and mgq.row_flag = SYS_YES
2368 and mgq.is_fetched = SYS_NO
2369 and mgq.res_instance_id <> MBP_NULL_VALUE
2370 and mrr.plan_id = mgq.plan_id
2371 and mrr.sr_instance_id = mgq.sr_instance_id
2372 and mrr.organization_id = mgq.organization_id
2373 and mrr.department_id = mgq.department_id
2374 and mrr.resource_id = mgq.resource_id
2375 and mrr.res_instance_id = mgq.res_instance_id
2376 and nvl(mrr.serial_number, MBP_NULL_VALUE_CHAR) = nvl(mgq.serial_number, MBP_NULL_VALUE_CHAR)
2377 and nvl(mrr.parent_id,0) <> -1
2378 and nvl(mrr.capacity_units,1) > 0
2379 and mrr.shift_date between p_start_date and p_end_date;
2380
2381 put_line('populateResAvailGantt: res inst rows: '||v_avail_start.count );
2382
2383 populateResDtlTabIntoGantt(p_query_id, RES_AVAIL_ROW_TYPE, v_row_index,
2384 v_avail_start, v_avail_end, v_resource_units, v_resource_hours,
2385 v_schdule_flag, SUMMARY_DATA);
2386
2387 end if; -- }
2388
2389 end populateResAvailGantt;
2390
2391 function getResReqUlpsd(p_plan number, p_inst number, p_org number, p_dept number,
2392 p_res number, p_supply number, p_op_seq number, p_res_seq number,
2393 p_orig_res_seq number, p_parent_seq number) return date is
2394
2395 cursor c_ulpsd is
2396 select mrr.ulpsd
2397 from msc_resource_requirements mrr
2398 where mrr.plan_id = p_plan
2399 and mrr.sr_instancE_id = p_inst
2400 and mrr.organization_id = p_org
2401 and mrr.department_id = p_dept
2402 and mrr.resource_id = p_res
2403 and mrr.supply_id = p_supply
2404 and mrr.operation_seq_num = p_op_seq
2405 and mrr.resource_seq_num = p_res_seq
2406 and nvl(mrr.orig_resource_seq_num, mbp_null_value) = nvl(p_orig_res_seq, mbp_null_value)
2407 and nvl(mrr.parent_seq_num, mbp_null_value) = nvl(p_parent_seq, mbp_null_value)
2408 and nvl(parent_id,2) = 2;
2409
2410 l_ulpsd date;
2411 begin
2412 open c_ulpsd;
2413 fetch c_ulpsd into l_ulpsd;
2414 close c_ulpsd;
2415
2416 return l_ulpsd;
2417 end getResReqUlpsd;
2418
2419 procedure populateResReqGanttNew(p_query_id number,
2420 p_start_date date, p_end_date date,
2421 p_display_type number default null) is
2422
2423 v_row_index number_arr;
2424 v_req_start date_arr;
2425 v_req_end date_arr;
2426 v_resource_units number_arr;
2427 v_resource_hours number_arr;
2428 v_batch number_arr;
2429 v_schedule_flag number_arr;
2430 v_res_firm_flag number_arr;
2431 v_res_const_flag number_arr;
2432 v_ulpsd_flag date_arr;
2433 v_display_type number_arr;
2434
2435 -- parent_id = 1 daily requirements
2436 -- parent_id = 2 aggregated requirements
2437
2438 cursor res_req_cur is
2439 select mgq.row_index,
2440 msc_gantt_utils.getResReqStartDate(nvl(mrr.firm_flag,0), mrr.start_date, mrr.end_date,
2441 mrr.firm_start_date, mrr.firm_end_date, mrr.status, mrr.applied) start_date,
2442 msc_gantt_utils.getResReqEndDate(nvl(mrr.firm_flag,0), mrr.start_date, mrr.end_date,
2443 mrr.firm_start_date, mrr.firm_end_date, mrr.status, mrr.applied) end_date,
2444 mrr.assigned_units,
2445 mrr.resource_hours,
2446 mrr.batch_number,
2447 msc_gantt_utils.getResReqType(mrr.plan_id, mrr.schedule_flag, mrr.parent_seq_num, mrr.setup_id) schedule_flag,
2448 msc_gantt_utils.getDisplayType(p_display_type,
2449 msc_gantt_utils.getResReqEndDate(nvl(mrr.firm_flag,0),
2450 mrr.start_date, mrr.end_date, mrr.firm_start_date, mrr.firm_end_date, mrr.status, mrr.applied),
2451 msc_gantt_utils.getResReqUlpsd(mrr.plan_id, mrr.sr_instancE_id, mrr.organization_id,
2452 mrr.department_id, mrr.resource_id, mrr.supply_id, mrr.operation_seq_num, mrr.resource_seq_num,
2453 mrr.orig_resource_seq_num, mrr.parent_seq_num),
2454 mrr.firm_flag,
2455 msc_gantt_utils.isResConstraint(mrr.plan_id,
2456 mrr.sr_instance_id, mrr.organization_id,
2457 ms.inventory_item_id, mrr.department_id, mrr.resource_id, mrr.supply_id),
2458 g_gantt_rh_toler_days_early,
2459 g_gantt_rh_toler_days_late) display_type
2460 from msc_gantt_query mgq,
2461 msc_resource_requirements mrr,
2462 msc_supplies ms
2463 where mgq.query_id = p_query_id
2464 and mgq.row_flag = SYS_YES
2465 and mgq.is_fetched = SYS_NO
2466 and mgq.res_instance_id = MBP_NULL_VALUE
2467 and mrr.plan_id = mgq.plan_id
2468 and mrr.sr_instance_id = mgq.sr_instance_id
2469 and mrr.organization_id = mgq.organization_id
2470 and mrr.department_id = mgq.department_id
2471 and mrr.resource_id = mgq.resource_id
2472 and mrr.plan_id = ms.plan_id
2473 and mrr.sr_instance_id = ms.sr_instance_id
2474 and mrr.supply_id = ms.transaction_id
2475 and mrr.batch_number is null and mrr.end_date is not null and mrr.resource_hours > 0
2476 and nvl(mrr.parent_id, 2) = 2
2477 and nvl(mrr.status,-1) = 0
2478 and nvl(mrr.applied,-1) = 2
2479 and ( ( msc_gantt_utils.getResReqStartDate(nvl(mrr.firm_flag,0),
2480 mrr.start_date, mrr.end_date, mrr.firm_start_date, mrr.firm_end_date, mrr.status, mrr.applied)
2481 between p_start_date and p_end_date
2482 )
2483 or ( msc_gantt_utils.getResReqEndDate(nvl(mrr.firm_flag,0),
2484 mrr.start_date, mrr.end_date, mrr.firm_start_date, mrr.firm_end_date, mrr.status, mrr.applied)
2485 between p_start_date and p_end_date )
2486 or ( msc_gantt_utils.getResReqStartDate(nvl(mrr.firm_flag,0),
2487 mrr.start_date, mrr.end_date, mrr.firm_start_date, mrr.firm_end_date, mrr.status, mrr.applied) <= p_start_date
2488 and msc_gantt_utils.getResReqEndDate(nvl(mrr.firm_flag,0),
2489 mrr.start_date, mrr.end_date, mrr.firm_start_date, mrr.firm_end_date, mrr.status, mrr.applied) >= p_end_date )
2490 )
2491 union all
2492 select mgq.row_index,
2493 msc_gantt_utils.getResReqStartDate(nvl(mrr.firm_flag,0), mrr.start_date, mrr.end_date,
2494 mrr.firm_start_date, mrr.firm_end_date, mrr.status, mrr.applied) start_date,
2495 msc_gantt_utils.getResReqEndDate(nvl(mrr.firm_flag,0), mrr.start_date, mrr.end_date,
2496 mrr.firm_start_date, mrr.firm_end_date, mrr.status, mrr.applied) end_date,
2497 mrr.assigned_units,
2498 mrr.resource_hours,
2499 mrr.batch_number,
2500 msc_gantt_utils.getResReqType(mrr.plan_id, mrr.schedule_flag, mrr.parent_seq_num, mrr.setup_id) schedule_flag,
2501 msc_gantt_utils.getDisplayType(p_display_type,
2502 msc_gantt_utils.getResReqEndDate(nvl(mrr.firm_flag,0),
2503 mrr.start_date, mrr.end_date, mrr.firm_start_date, mrr.firm_end_date, mrr.status, mrr.applied),
2504 msc_gantt_utils.getResReqUlpsd(mrr.plan_id, mrr.sr_instancE_id, mrr.organization_id,
2505 mrr.department_id, mrr.resource_id, mrr.supply_id, mrr.operation_seq_num, mrr.resource_seq_num,
2506 mrr.orig_resource_seq_num, mrr.parent_seq_num),
2507 mrr.firm_flag,
2508 msc_gantt_utils.isResConstraint(mrr.plan_id,
2509 mrr.sr_instance_id, mrr.organization_id,
2510 ms.inventory_item_id, mrr.department_id, mrr.resource_id, mrr.supply_id),
2511 g_gantt_rh_toler_days_early,
2512 g_gantt_rh_toler_days_late) display_type
2513 from msc_gantt_query mgq,
2514 msc_resource_requirements mrr,
2515 msc_resource_requirements mrr1,
2516 msc_supplies ms
2517 where mgq.query_id = p_query_id
2518 and mgq.row_flag = SYS_YES
2519 and mgq.is_fetched = SYS_NO
2520 and mgq.res_instance_id = MBP_NULL_VALUE
2521 and mrr.plan_id = mgq.plan_id
2522 and mrr.sr_instance_id = mgq.sr_instance_id
2523 and mrr.organization_id = mgq.organization_id
2524 and mrr.department_id = mgq.department_id
2525 and mrr.resource_id = mgq.resource_id
2526 and mrr.plan_id = ms.plan_id
2527 and mrr.sr_instance_id = ms.sr_instance_id
2528 and mrr.supply_id = ms.transaction_id
2529 and mrr.plan_id = mrr1.plan_id
2530 and mrr.sr_instancE_id = mrr1.sr_instancE_id
2531 and mrr.organization_id = mrr1.organization_id
2532 and mrr.department_id = mrr1.department_id
2533 and mrr.resource_id = mrr1.resource_id
2534 and mrr.supply_id = mrr1.supply_id
2535 and mrr.operation_seq_num = mrr1.operation_seq_num
2536 and mrr.resource_seq_num = mrr1.resource_seq_num
2537 and nvl(mrr.orig_resource_seq_num, mbp_null_value) = nvl(mrr1.orig_resource_seq_num, mbp_null_value)
2538 and nvl(mrr.parent_seq_num, mbp_null_value) = nvl(mrr1.parent_seq_num, mbp_null_value)
2539 and mrr.batch_number is null and mrr.end_date is not null and mrr.resource_hours > 0
2540 and mrr1.batch_number is null and mrr1.end_date is not null and mrr1.resource_hours > 0
2541 and nvl(mrr1.parent_id, 2) = 2
2542 and nvl(mrr1.status,-1) <> 0
2543 and nvl(mrr1.applied,-1) <> 2
2544 and nvl(mrr.parent_id,-1) = 1
2545 and ( ( msc_gantt_utils.getResReqStartDate(nvl(mrr.firm_flag,0),
2546 mrr.start_date, mrr.end_date, mrr.firm_start_date, mrr.firm_end_date, mrr.status, mrr.applied)
2547 between p_start_date and p_end_date
2548 )
2549 or ( msc_gantt_utils.getResReqEndDate(nvl(mrr.firm_flag,0),
2550 mrr.start_date, mrr.end_date, mrr.firm_start_date, mrr.firm_end_date, mrr.status, mrr.applied)
2551 between p_start_date and p_end_date )
2552 or ( msc_gantt_utils.getResReqStartDate(nvl(mrr.firm_flag,0),
2553 mrr.start_date, mrr.end_date, mrr.firm_start_date, mrr.firm_end_date, mrr.status, mrr.applied) <= p_start_date
2554 and msc_gantt_utils.getResReqEndDate(nvl(mrr.firm_flag,0),
2555 mrr.start_date, mrr.end_date, mrr.firm_start_date, mrr.firm_end_date, mrr.status, mrr.applied) >= p_end_date )
2556 ) ;
2557
2558 cursor res_inst_req_cur is
2559 select mgq.row_index,
2560 msc_gantt_utils.getResReqStartDate(nvl(mrr.firm_flag,0), mrir.start_date, mrir.end_date,
2561 mrr.firm_start_date, mrr.firm_end_date, mrr.status, mrr.applied) start_date,
2562 msc_gantt_utils.getResReqEndDate(nvl(mrr.firm_flag,0), mrir.start_date, mrir.end_date,
2563 mrr.firm_start_date, mrr.firm_end_date, mrr.status, mrr.applied) end_date,
2564 1 assigned_units,
2565 mrir.resource_instance_hours,
2566 mrr.batch_number,
2567 msc_gantt_utils.getResReqType(mrr.plan_id, mrr.schedule_flag, mrr.parent_seq_num, mrr.setup_id) schedule_flag,
2568 msc_gantt_utils.getDisplayType(p_display_type,
2569 msc_gantt_utils.getResReqEndDate(nvl(mrr.firm_flag,0),
2570 mrir.start_date, mrir.end_date, mrr.firm_start_date, mrr.firm_end_date, mrr.status, mrr.applied),
2571 msc_gantt_utils.getResReqUlpsd(mrr.plan_id, mrr.sr_instancE_id, mrr.organization_id,
2572 mrr.department_id, mrr.resource_id, mrr.supply_id, mrr.operation_seq_num, mrr.resource_seq_num,
2573 mrr.orig_resource_seq_num, mrr.parent_seq_num),
2574 mrr.firm_flag,
2575 msc_gantt_utils.isResConstraint(mrr.plan_id,
2576 mrr.sr_instance_id, mrr.organization_id,
2577 ms.inventory_item_id, mrr.department_id, mrr.resource_id, mrr.supply_id),
2578 g_gantt_rh_toler_days_early,
2579 g_gantt_rh_toler_days_late) display_type
2580 from msc_gantt_query mgq,
2581 msc_resource_requirements mrr,
2582 msc_resource_instance_reqs mrir,
2583 msc_supplies ms
2584 where mgq.query_id = p_query_id
2585 and mgq.row_flag = SYS_YES
2586 and mgq.is_fetched = SYS_NO
2587 and mgq.res_instance_id <> MBP_NULL_VALUE
2588 and mrir.plan_id = mgq.plan_id
2589 and mrir.sr_instance_id = mgq.sr_instance_id
2590 and mrir.organization_id = mgq.organization_id
2591 and mrir.department_id = mgq.department_id
2592 and mrir.resource_id = mgq.resource_id
2593 and mrir.res_instance_id = mgq.res_instance_id
2594 and nvl(mrir.serial_number, MBP_NULL_VALUE_CHAR) = nvl(mgq.serial_number, MBP_NULL_VALUE_CHAR)
2595 and mrir.end_date is not null
2596 and mrir.plan_id = mrr.plan_id
2597 and mrir.sr_instance_id = mrr.sr_instance_id
2598 and mrir.organization_id = mrr.organization_id
2599 and mrir.department_id = mrr.department_id
2600 and mrir.resource_id = mrr.resource_id
2601 and mrir.supply_id = mrr.supply_id
2602 and mrir.operation_seq_num = mrr.operation_seq_num
2603 and mrir.resource_seq_num = mrr.resource_seq_num
2604 and nvl(mrir.orig_resource_seq_num, mbp_null_value) = nvl(mrr.orig_resource_seq_num, mbp_null_value)
2605 and nvl(mrir.parent_seq_num, mbp_null_value) = nvl(mrr.parent_seq_num, mbp_null_value)
2606 and nvl(mrir.parent_id, mbp_null_value) = nvl(mrr.parent_id, mbp_null_value)
2607 and mrir.start_date = nvl(mrr.firm_start_date, mrr.start_date)
2608 and mrir.end_date = nvl(mrr.firm_end_date, mrr.end_date)
2609 and mrr.plan_id = ms.plan_id
2610 and mrr.sr_instance_id = ms.sr_instance_id
2611 and mrr.supply_id = ms.transaction_id
2612 and mrr.batch_number is null and mrr.end_date is not null and mrr.resource_hours > 0
2613 and nvl(mrr.parent_id, 2) = 2
2614 and nvl(mrr.status,-1) = 0
2615 and nvl(mrr.applied,-1) = 2
2616 and ( ( msc_gantt_utils.getResReqStartDate(nvl(mrr.firm_flag,0),
2617 mrir.start_date, mrir.end_date, mrr.firm_start_date, mrr.firm_end_date, mrr.status, mrr.applied)
2618 between p_start_date and p_end_date
2619 )
2620 or ( msc_gantt_utils.getResReqEndDate(nvl(mrr.firm_flag,0),
2621 mrir.start_date, mrir.end_date, mrr.firm_start_date, mrr.firm_end_date, mrr.status, mrr.applied)
2622 between p_start_date and p_end_date )
2623 or ( msc_gantt_utils.getResReqStartDate(nvl(mrr.firm_flag,0),
2624 mrir.start_date, mrir.end_date, mrr.firm_start_date, mrr.firm_end_date, mrr.status, mrr.applied) <= p_start_date
2625 and msc_gantt_utils.getResReqEndDate(nvl(mrr.firm_flag,0),
2626 mrir.start_date, mrir.end_date, mrr.firm_start_date, mrr.firm_end_date, mrr.status, mrr.applied) >= p_end_date )
2627 )
2628 union all
2629 select mgq.row_index,
2630 msc_gantt_utils.getResReqStartDate(nvl(mrr.firm_flag,0), mrir.start_date, mrir.end_date,
2631 mrr.firm_start_date, mrr.firm_end_date, mrr.status, mrr.applied) start_date,
2632 msc_gantt_utils.getResReqEndDate(nvl(mrr.firm_flag,0), mrir.start_date, mrir.end_date,
2633 mrr.firm_start_date, mrr.firm_end_date, mrr.status, mrr.applied) end_date,
2634 1 assigned_units,
2635 mrir.resource_instance_hours,
2636 mrr.batch_number,
2637 msc_gantt_utils.getResReqType(mrr.plan_id, mrr.schedule_flag, mrr.parent_seq_num, mrr.setup_id) schedule_flag,
2638 msc_gantt_utils.getDisplayType(p_display_type,
2639 msc_gantt_utils.getResReqEndDate(nvl(mrr.firm_flag,0),
2640 mrir.start_date, mrir.end_date, mrr.firm_start_date, mrr.firm_end_date, mrr.status, mrr.applied),
2641 msc_gantt_utils.getResReqUlpsd(mrr.plan_id, mrr.sr_instancE_id, mrr.organization_id,
2642 mrr.department_id, mrr.resource_id, mrr.supply_id, mrr.operation_seq_num, mrr.resource_seq_num,
2643 mrr.orig_resource_seq_num, mrr.parent_seq_num),
2644 mrr.firm_flag,
2645 msc_gantt_utils.isResConstraint(mrr.plan_id,
2646 mrr.sr_instance_id, mrr.organization_id,
2647 ms.inventory_item_id, mrr.department_id, mrr.resource_id, mrr.supply_id),
2648 g_gantt_rh_toler_days_early,
2649 g_gantt_rh_toler_days_late) display_type
2650 from msc_gantt_query mgq,
2651 msc_resource_requirements mrr,
2652 msc_resource_requirements mrr1,
2653 msc_resource_instance_reqs mrir,
2654 msc_supplies ms
2655 where mgq.query_id = p_query_id
2656 and mgq.row_flag = SYS_YES
2657 and mgq.is_fetched = SYS_NO
2658 and mgq.res_instance_id <> MBP_NULL_VALUE
2659 and mrir.plan_id = mgq.plan_id
2660 and mrir.sr_instance_id = mgq.sr_instance_id
2661 and mrir.organization_id = mgq.organization_id
2662 and mrir.department_id = mgq.department_id
2663 and mrir.resource_id = mgq.resource_id
2664 and mrir.res_instance_id = mgq.res_instance_id
2665 and nvl(mrir.serial_number, MBP_NULL_VALUE_CHAR) = nvl(mgq.serial_number, MBP_NULL_VALUE_CHAR)
2666 and mrir.end_date is not null
2667 and mrir.plan_id = mrr.plan_id
2668 and mrir.sr_instance_id = mrr.sr_instance_id
2669 and mrir.organization_id = mrr.organization_id
2670 and mrir.department_id = mrr.department_id
2671 and mrir.resource_id = mrr.resource_id
2672 and mrir.supply_id = mrr.supply_id
2673 and mrir.operation_seq_num = mrr.operation_seq_num
2674 and mrir.resource_seq_num = mrr.resource_seq_num
2675 and nvl(mrir.orig_resource_seq_num, mbp_null_value) = nvl(mrr.orig_resource_seq_num, mbp_null_value)
2676 and nvl(mrir.parent_seq_num, mbp_null_value) = nvl(mrr.parent_seq_num, mbp_null_value)
2677 and nvl(mrir.parent_id, mbp_null_value) = nvl(mrr.parent_id, mbp_null_value)
2678 and mrir.start_date = nvl(mrr.firm_start_date, mrr.start_date)
2679 and mrir.end_date = nvl(mrr.firm_end_date, mrr.end_date)
2680 and mrr.plan_id = ms.plan_id
2681 and mrr.sr_instance_id = ms.sr_instance_id
2682 and mrr.supply_id = ms.transaction_id
2683 and mrr.plan_id = mrr1.plan_id
2684 and mrr.sr_instancE_id = mrr1.sr_instancE_id
2685 and mrr.organization_id = mrr1.organization_id
2686 and mrr.department_id = mrr1.department_id
2687 and mrr.resource_id = mrr1.resource_id
2688 and mrr.supply_id = mrr1.supply_id
2689 and mrr.operation_seq_num = mrr1.operation_seq_num
2690 and mrr.resource_seq_num = mrr1.resource_seq_num
2691 and nvl(mrr.orig_resource_seq_num, mbp_null_value) = nvl(mrr1.orig_resource_seq_num, mbp_null_value)
2692 and nvl(mrr.parent_seq_num, mbp_null_value) = nvl(mrr1.parent_seq_num, mbp_null_value)
2693 and mrr.batch_number is null and mrr.end_date is not null and mrr.resource_hours > 0
2694 and mrr1.batch_number is null and mrr1.end_date is not null and mrr1.resource_hours > 0
2695 and nvl(mrr1.parent_id, 2) = 2
2696 and nvl(mrr1.status,-1) <> 0
2697 and nvl(mrr1.applied,-1) <> 2
2698 and nvl(mrr.parent_id,-1) = 1
2699 and ( ( msc_gantt_utils.getResReqStartDate(nvl(mrr.firm_flag,0),
2700 mrir.start_date, mrir.end_date, mrr.firm_start_date, mrr.firm_end_date, mrr.status, mrr.applied)
2701 between p_start_date and p_end_date
2702 )
2703 or ( msc_gantt_utils.getResReqEndDate(nvl(mrr.firm_flag,0),
2704 mrir.start_date, mrir.end_date, mrr.firm_start_date, mrr.firm_end_date, mrr.status, mrr.applied)
2705 between p_start_date and p_end_date )
2706 or ( msc_gantt_utils.getResReqStartDate(nvl(mrr.firm_flag,0),
2707 mrir.start_date, mrir.end_date, mrr.firm_start_date, mrr.firm_end_date, mrr.status, mrr.applied) <= p_start_date
2708 and msc_gantt_utils.getResReqEndDate(nvl(mrr.firm_flag,0),
2709 mrir.start_date, mrir.end_date, mrr.firm_start_date, mrr.firm_end_date, mrr.status, mrr.applied) >= p_end_date )
2710 );
2711
2712 cursor res_req_btch_cur is
2713 select mgq.row_index,
2714 min(msc_gantt_utils.getResReqStartDate(nvl(mrr.firm_flag,0), mrr.start_date, mrr.end_date,
2715 mrr.firm_start_date, mrr.firm_end_date, mrr.status, mrr.applied)) start_date,
2716 max(msc_gantt_utils.getResReqEndDate(nvl(mrr.firm_flag,0), mrr.start_date,
2717 mrr.end_date, mrr.firm_start_date, mrr.firm_end_date, mrr.status, mrr.applied)) end_date,
2718 sum(mrr.capacity_consumed_ratio) assigned_units,
2719 avg(mrr.resource_hours) resource_hours,
2720 mrr.batch_number,
2721 msc_gantt_utils.getResReqType(mrr.plan_id, mrr.schedule_flag, mrr.parent_seq_num, mrr.setup_id) schedule_flag,
2722 decode(p_display_type, DISPLAY_NONE, sys_no,
2723 msc_gantt_utils.getDisplayType(p_display_type,
2724 msc_gantt_utils.getResReqEndDate(nvl(mrr.firm_flag,0),
2725 mrr.start_date, mrr.end_date, mrr.firm_start_date, mrr.firm_end_date, mrr.status, mrr.applied),
2726 msc_gantt_utils.getResReqUlpsd(mrr.plan_id, mrr.sr_instancE_id, mrr.organization_id,
2727 mrr.department_id, mrr.resource_id, mrr.supply_id, mrr.operation_seq_num, mrr.resource_seq_num,
2728 mrr.orig_resource_seq_num, mrr.parent_seq_num),
2729 mrr.firm_flag,
2730 msc_gantt_utils.isResConstraint(mrr.plan_id,
2731 mrr.sr_instance_id, mrr.organization_id,
2732 ms.inventory_item_id, mrr.department_id, mrr.resource_id, mrr.supply_id),
2733 g_gantt_rh_toler_days_early,
2734 g_gantt_rh_toler_days_late)) display_type
2735 from msc_gantt_query mgq,
2736 msc_resource_requirements mrr,
2737 msc_resource_batches mrb,
2738 msc_supplies ms
2739 where mgq.query_id = p_query_id
2740 and mgq.row_flag = SYS_YES
2741 and mgq.is_fetched = SYS_NO
2742 and mgq.res_instance_id = MBP_NULL_VALUE
2743 and mrr.plan_id = mgq.plan_id
2744 and mrr.sr_instance_id = mgq.sr_instance_id
2745 and mrr.organization_id = mgq.organization_id
2746 and mrr.department_id = mgq.department_id
2747 and mrr.resource_id = mgq.resource_id
2748 and mrb.plan_id = mrr.plan_id
2749 and mrb.sr_instance_id = mrr.sr_instance_id
2750 and mrb.organization_id= mrr.organization_id
2751 and mrb.department_id = mrr.department_id
2752 and mrb.resource_id = mrr.resource_id
2753 and mrb.batch_number = mrr.batch_number
2754 and mrr.plan_id = ms.plan_id
2755 and mrr.sr_instance_id = ms.sr_instance_id
2756 and mrr.supply_id = ms.transaction_id
2757 and mrr.batch_number is not null and mrr.end_date is not null and mrr.resource_hours > 0
2758 and nvl(mrr.parent_id, 2) = 2
2759 and nvl(mrr.status,-1) = 0
2760 and nvl(mrr.applied,-1) = 2
2761 and ( ( msc_gantt_utils.getResReqStartDate(nvl(mrr.firm_flag,0),
2762 mrr.start_date, mrr.end_date, mrr.firm_start_date, mrr.firm_end_date, mrr.status, mrr.applied)
2763 between p_start_date and p_end_date
2764 )
2765 or ( msc_gantt_utils.getResReqEndDate(nvl(mrr.firm_flag,0),
2766 mrr.start_date, mrr.end_date, mrr.firm_start_date, mrr.firm_end_date, mrr.status, mrr.applied)
2767 between p_start_date and p_end_date )
2768 or ( msc_gantt_utils.getResReqStartDate(nvl(mrr.firm_flag,0),
2769 mrr.start_date, mrr.end_date, mrr.firm_start_date, mrr.firm_end_date, mrr.status, mrr.applied) <= p_start_date
2770 and msc_gantt_utils.getResReqEndDate(nvl(mrr.firm_flag,0),
2771 mrr.start_date, mrr.end_date, mrr.firm_start_date, mrr.firm_end_date, mrr.status, mrr.applied) >= p_end_date )
2772 )
2773 group by
2774 mgq.row_index,
2775 mrr.batch_number,
2776 msc_gantt_utils.getResReqType(mrr.plan_id, mrr.schedule_flag, mrr.parent_seq_num, mrr.setup_id),
2777 msc_gantt_utils.getDisplayType(p_display_type,
2778 msc_gantt_utils.getResReqEndDate(nvl(mrr.firm_flag,0),
2779 mrr.start_date, mrr.end_date, mrr.firm_start_date, mrr.firm_end_date, mrr.status, mrr.applied),
2780 msc_gantt_utils.getResReqUlpsd(mrr.plan_id, mrr.sr_instancE_id, mrr.organization_id,
2781 mrr.department_id, mrr.resource_id, mrr.supply_id, mrr.operation_seq_num, mrr.resource_seq_num,
2782 mrr.orig_resource_seq_num, mrr.parent_seq_num),
2783 mrr.firm_flag,
2784 msc_gantt_utils.isResConstraint(mrr.plan_id,
2785 mrr.sr_instance_id, mrr.organization_id,
2786 ms.inventory_item_id, mrr.department_id, mrr.resource_id, mrr.supply_id),
2787 g_gantt_rh_toler_days_early,
2788 g_gantt_rh_toler_days_late)
2789 union all
2790 select mgq.row_index,
2791 min(msc_gantt_utils.getResReqStartDate(nvl(mrr.firm_flag,0), mrr.start_date, mrr.end_date,
2792 mrr.firm_start_date, mrr.firm_end_date, mrr.status, mrr.applied)) start_date,
2793 max(msc_gantt_utils.getResReqEndDate(nvl(mrr.firm_flag,0), mrr.start_date,
2794 mrr.end_date, mrr.firm_start_date, mrr.firm_end_date, mrr.status, mrr.applied)) end_date,
2795 sum(mrr.capacity_consumed_ratio) assigned_units,
2796 avg(mrr.resource_hours) resource_hours,
2797 mrr.batch_number,
2798 msc_gantt_utils.getResReqType(mrr.plan_id, mrr.schedule_flag, mrr.parent_seq_num, mrr.setup_id) schedule_flag,
2799 decode(p_display_type, DISPLAY_NONE, sys_no,
2800 msc_gantt_utils.getDisplayType(p_display_type,
2801 msc_gantt_utils.getResReqEndDate(nvl(mrr.firm_flag,0),
2802 mrr.start_date, mrr.end_date, mrr.firm_start_date, mrr.firm_end_date, mrr.status, mrr.applied),
2803 msc_gantt_utils.getResReqUlpsd(mrr.plan_id, mrr.sr_instancE_id, mrr.organization_id,
2804 mrr.department_id, mrr.resource_id, mrr.supply_id, mrr.operation_seq_num, mrr.resource_seq_num,
2805 mrr.orig_resource_seq_num, mrr.parent_seq_num),
2806 mrr.firm_flag,
2807 msc_gantt_utils.isResConstraint(mrr.plan_id,
2808 mrr.sr_instance_id, mrr.organization_id,
2809 ms.inventory_item_id, mrr.department_id, mrr.resource_id, mrr.supply_id),
2810 g_gantt_rh_toler_days_early,
2811 g_gantt_rh_toler_days_late)) display_type
2812 from msc_gantt_query mgq,
2813 msc_resource_requirements mrr,
2814 msc_resource_requirements mrr1,
2815 msc_resource_batches mrb,
2816 msc_supplies ms
2817 where mgq.query_id = p_query_id
2818 and mgq.row_flag = SYS_YES
2819 and mgq.is_fetched = SYS_NO
2820 and mgq.res_instance_id = MBP_NULL_VALUE
2821 and mrr.plan_id = mgq.plan_id
2822 and mrr.sr_instance_id = mgq.sr_instance_id
2823 and mrr.organization_id = mgq.organization_id
2824 and mrr.department_id = mgq.department_id
2825 and mrr.resource_id = mgq.resource_id
2826 and mrb.plan_id = mrr.plan_id
2827 and mrb.sr_instance_id = mrr.sr_instance_id
2828 and mrb.organization_id= mrr.organization_id
2829 and mrb.department_id = mrr.department_id
2830 and mrb.resource_id = mrr.resource_id
2831 and mrb.batch_number = mrr.batch_number
2832 and mrr.plan_id = ms.plan_id
2833 and mrr.sr_instance_id = ms.sr_instance_id
2834 and mrr.supply_id = ms.transaction_id
2835 and mrr.plan_id = mrr1.plan_id
2836 and mrr.sr_instancE_id = mrr1.sr_instancE_id
2837 and mrr.organization_id = mrr1.organization_id
2838 and mrr.department_id = mrr1.department_id
2839 and mrr.resource_id = mrr1.resource_id
2840 and mrr.supply_id = mrr1.supply_id
2841 and mrr.operation_seq_num = mrr1.operation_seq_num
2842 and mrr.resource_seq_num = mrr1.resource_seq_num
2843 and nvl(mrr.orig_resource_seq_num, mbp_null_value) = nvl(mrr1.orig_resource_seq_num, mbp_null_value)
2844 and nvl(mrr.parent_seq_num, mbp_null_value) = nvl(mrr1.parent_seq_num, mbp_null_value)
2845 and mrr.batch_number is not null and mrr.end_date is not null and mrr.resource_hours > 0
2846 and mrr1.batch_number is not null and mrr1.end_date is not null and mrr1.resource_hours > 0
2847 and nvl(mrr1.parent_id, 2) = 2
2848 and nvl(mrr1.status,-1) <> 0
2849 and nvl(mrr1.applied,-1) <> 2
2850 and nvl(mrr.parent_id,-1) = 1
2851 and ( ( msc_gantt_utils.getResReqStartDate(nvl(mrr.firm_flag,0),
2852 mrr.start_date, mrr.end_date, mrr.firm_start_date, mrr.firm_end_date, mrr.status, mrr.applied)
2853 between p_start_date and p_end_date
2854 )
2855 or ( msc_gantt_utils.getResReqEndDate(nvl(mrr.firm_flag,0),
2856 mrr.start_date, mrr.end_date, mrr.firm_start_date, mrr.firm_end_date, mrr.status, mrr.applied)
2857 between p_start_date and p_end_date )
2858 or ( msc_gantt_utils.getResReqStartDate(nvl(mrr.firm_flag,0),
2859 mrr.start_date, mrr.end_date, mrr.firm_start_date, mrr.firm_end_date, mrr.status, mrr.applied) <= p_start_date
2860 and msc_gantt_utils.getResReqEndDate(nvl(mrr.firm_flag,0),
2861 mrr.start_date, mrr.end_date, mrr.firm_start_date, mrr.firm_end_date, mrr.status, mrr.applied) >= p_end_date )
2862 )
2863 group by
2864 mgq.row_index,
2865 mrr.batch_number,
2866 msc_gantt_utils.getResReqType(mrr.plan_id, mrr.schedule_flag, mrr.parent_seq_num, mrr.setup_id),
2867 msc_gantt_utils.getDisplayType(p_display_type,
2868 msc_gantt_utils.getResReqEndDate(nvl(mrr.firm_flag,0),
2869 mrr.start_date, mrr.end_date, mrr.firm_start_date, mrr.firm_end_date, mrr.status, mrr.applied),
2870 msc_gantt_utils.getResReqUlpsd(mrr.plan_id, mrr.sr_instancE_id, mrr.organization_id,
2871 mrr.department_id, mrr.resource_id, mrr.supply_id, mrr.operation_seq_num, mrr.resource_seq_num,
2872 mrr.orig_resource_seq_num, mrr.parent_seq_num),
2873 mrr.firm_flag,
2874 msc_gantt_utils.isResConstraint(mrr.plan_id,
2875 mrr.sr_instance_id, mrr.organization_id,
2876 ms.inventory_item_id, mrr.department_id, mrr.resource_id, mrr.supply_id),
2877 g_gantt_rh_toler_days_early,
2878 g_gantt_rh_toler_days_late);
2879
2880 cursor res_inst_req_btch_cur is
2881 select mgq.row_index,
2882 min(msc_gantt_utils.getResReqStartDate(nvl(mrr.firm_flag,0), mrir.start_date, mrir.end_date,
2883 mrr.firm_start_date, mrr.firm_end_date, mrr.status, mrr.applied)) start_date,
2884 max(msc_gantt_utils.getResReqEndDate(nvl(mrr.firm_flag,0), mrir.start_date,
2885 mrir.end_date, mrr.firm_start_date, mrr.firm_end_date, mrr.status, mrr.applied)) end_date,
2886 sum(mrir.capacity_consumed_ratio) assigned_units,
2887 avg(mrir.resource_instance_hours) resource_hours,
2888 mrir.batch_number,
2889 msc_gantt_utils.getResReqType(mrr.plan_id, mrr.schedule_flag, mrr.parent_seq_num, mrr.setup_id) schedule_flag,
2890 decode(p_display_type, DISPLAY_NONE, sys_no,
2891 msc_gantt_utils.getDisplayType(p_display_type,
2892 msc_gantt_utils.getResReqEndDate(nvl(mrr.firm_flag,0),
2893 mrir.start_date, mrir.end_date, mrr.firm_start_date, mrr.firm_end_date, mrr.status, mrr.applied),
2894 msc_gantt_utils.getResReqUlpsd(mrr.plan_id, mrr.sr_instancE_id, mrr.organization_id,
2895 mrr.department_id, mrr.resource_id, mrr.supply_id, mrr.operation_seq_num, mrr.resource_seq_num,
2896 mrr.orig_resource_seq_num, mrr.parent_seq_num),
2897 mrr.firm_flag,
2898 msc_gantt_utils.isResConstraint(mrr.plan_id,
2899 mrr.sr_instance_id, mrr.organization_id,
2900 ms.inventory_item_id, mrr.department_id, mrr.resource_id, mrr.supply_id),
2901 g_gantt_rh_toler_days_early,
2902 g_gantt_rh_toler_days_late)) display_type
2903 from msc_gantt_query mgq,
2904 msc_resource_requirements mrr,
2905 msc_resource_instance_reqs mrir,
2906 msc_resource_batches mrb,
2907 msc_supplies ms
2908 where mgq.query_id = p_query_id
2909 and mgq.row_flag = SYS_YES
2910 and mgq.is_fetched = SYS_NO
2911 and mgq.res_instance_id <> MBP_NULL_VALUE
2912 and mrir.plan_id = mgq.plan_id
2913 and mrir.sr_instance_id = mgq.sr_instance_id
2914 and mrir.organization_id = mgq.organization_id
2915 and mrir.department_id = mgq.department_id
2916 and mrir.resource_id = mgq.resource_id
2917 and mrir.res_instance_id = mgq.res_instance_id
2918 and nvl(mrir.serial_number, MBP_NULL_VALUE_CHAR) = nvl(mgq.serial_number, MBP_NULL_VALUE_CHAR)
2919 and mrir.end_date is not null
2920 and mrir.plan_id = mrr.plan_id
2921 and mrir.sr_instance_id = mrr.sr_instance_id
2922 and mrir.organization_id = mrr.organization_id
2923 and mrir.department_id = mrr.department_id
2924 and mrir.resource_id = mrr.resource_id
2925 and mrir.supply_id = mrr.supply_id
2926 and mrir.resource_seq_num = mrr.resource_seq_num
2927 and mrir.operation_seq_num = mrr.operation_seq_num
2928 and nvl(mrir.orig_resource_seq_num, mbp_null_value) = nvl(mrr.orig_resource_seq_num, mbp_null_value)
2929 and nvl(mrir.parent_seq_num, mbp_null_value) = nvl(mrr.parent_seq_num, mbp_null_value)
2930 and nvl(mrir.parent_id, mbp_null_value) = nvl(mrr.parent_id, mbp_null_value)
2931 and mrir.start_date = nvl(mrr.firm_start_date, mrr.start_date)
2932 and mrir.end_date = nvl(mrr.firm_end_date, mrr.end_date)
2933 and mrb.plan_id = mrr.plan_id
2934 and mrb.sr_instance_id = mrr.sr_instance_id
2935 and mrb.organization_id= mrr.organization_id
2936 and mrb.department_id = mrr.department_id
2937 and mrb.resource_id = mrr.resource_id
2938 and mrb.batch_number = mrr.batch_number
2939 and mrr.plan_id = ms.plan_id
2940 and mrr.sr_instance_id = ms.sr_instance_id
2941 and mrr.supply_id = ms.transaction_id
2942 and mrr.batch_number is not null and mrr.end_date is not null and mrr.resource_hours > 0
2943 and nvl(mrr.parent_id, 2) = 2
2944 and nvl(mrr.status,-1) = 0
2945 and nvl(mrr.applied,-1) = 2
2946 and ( ( msc_gantt_utils.getResReqStartDate(nvl(mrr.firm_flag,0),
2947 mrir.start_date, mrir.end_date, mrr.firm_start_date, mrr.firm_end_date, mrr.status, mrr.applied)
2948 between p_start_date and p_end_date
2949 )
2950 or ( msc_gantt_utils.getResReqEndDate(nvl(mrr.firm_flag,0),
2951 mrir.start_date, mrir.end_date, mrr.firm_start_date, mrr.firm_end_date, mrr.status, mrr.applied)
2952 between p_start_date and p_end_date )
2953 or ( msc_gantt_utils.getResReqStartDate(nvl(mrr.firm_flag,0),
2954 mrir.start_date, mrir.end_date, mrr.firm_start_date, mrr.firm_end_date, mrr.status, mrr.applied) <= p_start_date
2955 and msc_gantt_utils.getResReqEndDate(nvl(mrr.firm_flag,0),
2956 mrir.start_date, mrir.end_date, mrr.firm_start_date, mrr.firm_end_date, mrr.status, mrr.applied) >= p_end_date )
2957 )
2958 group by
2959 mgq.row_index,
2960 mrir.batch_number,
2961 msc_gantt_utils.getResReqType(mrr.plan_id, mrr.schedule_flag, mrr.parent_seq_num, mrr.setup_id),
2962 msc_gantt_utils.getDisplayType(p_display_type,
2963 msc_gantt_utils.getResReqEndDate(nvl(mrr.firm_flag,0),
2964 mrir.start_date, mrir.end_date, mrr.firm_start_date, mrr.firm_end_date, mrr.status, mrr.applied),
2965 msc_gantt_utils.getResReqUlpsd(mrr.plan_id, mrr.sr_instancE_id, mrr.organization_id,
2966 mrr.department_id, mrr.resource_id, mrr.supply_id, mrr.operation_seq_num, mrr.resource_seq_num,
2967 mrr.orig_resource_seq_num, mrr.parent_seq_num),
2968 mrr.firm_flag,
2969 msc_gantt_utils.isResConstraint(mrr.plan_id,
2970 mrr.sr_instance_id, mrr.organization_id,
2971 ms.inventory_item_id, mrr.department_id, mrr.resource_id, mrr.supply_id),
2972 g_gantt_rh_toler_days_early,
2973 g_gantt_rh_toler_days_late)
2974 union all
2975 select mgq.row_index,
2976 min(msc_gantt_utils.getResReqStartDate(nvl(mrr.firm_flag,0), mrir.start_date, mrir.end_date,
2977 mrr.firm_start_date, mrr.firm_end_date, mrr.status, mrr.applied)) start_date,
2978 max(msc_gantt_utils.getResReqEndDate(nvl(mrr.firm_flag,0), mrir.start_date,
2979 mrir.end_date, mrr.firm_start_date, mrr.firm_end_date, mrr.status, mrr.applied)) end_date,
2980 sum(mrir.capacity_consumed_ratio) assigned_units,
2981 avg(mrir.resource_instance_hours) resource_hours,
2982 mrir.batch_number,
2983 msc_gantt_utils.getResReqType(mrr.plan_id, mrr.schedule_flag, mrr.parent_seq_num, mrr.setup_id) schedule_flag,
2984 decode(p_display_type, DISPLAY_NONE, sys_no,
2985 msc_gantt_utils.getDisplayType(p_display_type,
2986 msc_gantt_utils.getResReqEndDate(nvl(mrr.firm_flag,0),
2987 mrir.start_date, mrir.end_date, mrr.firm_start_date, mrr.firm_end_date, mrr.status, mrr.applied),
2988 msc_gantt_utils.getResReqUlpsd(mrr.plan_id, mrr.sr_instancE_id, mrr.organization_id,
2989 mrr.department_id, mrr.resource_id, mrr.supply_id, mrr.operation_seq_num, mrr.resource_seq_num,
2990 mrr.orig_resource_seq_num, mrr.parent_seq_num),
2991 mrr.firm_flag,
2992 msc_gantt_utils.isResConstraint(mrr.plan_id,
2993 mrr.sr_instance_id, mrr.organization_id,
2994 ms.inventory_item_id, mrr.department_id, mrr.resource_id, mrr.supply_id),
2995 g_gantt_rh_toler_days_early,
2996 g_gantt_rh_toler_days_late)) display_type
2997 from msc_gantt_query mgq,
2998 msc_resource_requirements mrr,
2999 msc_resource_requirements mrr1,
3000 msc_resource_batches mrb,
3001 msc_resource_instance_reqs mrir,
3002 msc_supplies ms
3003 where mgq.query_id = p_query_id
3004 and mgq.row_flag = SYS_YES
3005 and mgq.is_fetched = SYS_NO
3006 and mgq.res_instance_id <> MBP_NULL_VALUE
3007 and mrir.plan_id = mgq.plan_id
3008 and mrir.sr_instance_id = mgq.sr_instance_id
3009 and mrir.organization_id = mgq.organization_id
3010 and mrir.department_id = mgq.department_id
3011 and mrir.resource_id = mgq.resource_id
3012 and mrir.res_instance_id = mgq.res_instance_id
3013 and nvl(mrir.serial_number, MBP_NULL_VALUE_CHAR) = nvl(mgq.serial_number, MBP_NULL_VALUE_CHAR)
3014 and mrir.end_date is not null
3015 and mrir.plan_id = mrr.plan_id
3016 and mrir.sr_instance_id = mrr.sr_instance_id
3017 and mrir.organization_id = mrr.organization_id
3018 and mrir.department_id = mrr.department_id
3019 and mrir.resource_id = mrr.resource_id
3020 and mrir.supply_id = mrr.supply_id
3021 and mrir.resource_seq_num = mrr.resource_seq_num
3022 and mrir.operation_seq_num = mrr.operation_seq_num
3023 and nvl(mrir.orig_resource_seq_num, mbp_null_value) = nvl(mrr.orig_resource_seq_num, mbp_null_value)
3024 and nvl(mrir.parent_seq_num, mbp_null_value) = nvl(mrr.parent_seq_num, mbp_null_value)
3025 and nvl(mrir.parent_id, mbp_null_value) = nvl(mrr.parent_id, mbp_null_value)
3026 and mrir.start_date = nvl(mrr.firm_start_date, mrr.start_date)
3027 and mrir.end_date = nvl(mrr.firm_end_date, mrr.end_date)
3028 and mrb.plan_id = mrr.plan_id
3029 and mrb.sr_instance_id = mrr.sr_instance_id
3030 and mrb.organization_id= mrr.organization_id
3031 and mrb.department_id = mrr.department_id
3032 and mrb.resource_id = mrr.resource_id
3033 and mrb.batch_number = mrr.batch_number
3034 and mrr.plan_id = ms.plan_id
3035 and mrr.sr_instance_id = ms.sr_instance_id
3036 and mrr.supply_id = ms.transaction_id
3037 and mrr.plan_id = mrr1.plan_id
3038 and mrr.sr_instancE_id = mrr1.sr_instancE_id
3039 and mrr.organization_id = mrr1.organization_id
3040 and mrr.department_id = mrr1.department_id
3041 and mrr.resource_id = mrr1.resource_id
3042 and mrr.supply_id = mrr1.supply_id
3043 and mrr.operation_seq_num = mrr1.operation_seq_num
3044 and mrr.resource_seq_num = mrr1.resource_seq_num
3045 and nvl(mrr.orig_resource_seq_num, mbp_null_value) = nvl(mrr1.orig_resource_seq_num, mbp_null_value)
3046 and nvl(mrr.parent_seq_num, mbp_null_value) = nvl(mrr1.parent_seq_num, mbp_null_value)
3047 and mrr.batch_number is not null and mrr.end_date is not null and mrr.resource_hours > 0
3048 and mrr1.batch_number is not null and mrr1.end_date is not null and mrr1.resource_hours > 0
3049 and nvl(mrr1.parent_id, 2) = 2
3050 and nvl(mrr1.status,-1) <> 0
3051 and nvl(mrr1.applied,-1) <> 2
3052 and nvl(mrr.parent_id,-1) = 1
3053 and ( ( msc_gantt_utils.getResReqStartDate(nvl(mrr.firm_flag,0),
3054 mrir.start_date, mrir.end_date, mrr.firm_start_date, mrr.firm_end_date, mrr.status, mrr.applied)
3055 between p_start_date and p_end_date
3056 )
3057 or ( msc_gantt_utils.getResReqEndDate(nvl(mrr.firm_flag,0),
3058 mrir.start_date, mrir.end_date, mrr.firm_start_date, mrr.firm_end_date, mrr.status, mrr.applied)
3059 between p_start_date and p_end_date )
3060 or ( msc_gantt_utils.getResReqStartDate(nvl(mrr.firm_flag,0),
3061 mrir.start_date, mrir.end_date, mrr.firm_start_date, mrr.firm_end_date, mrr.status, mrr.applied) <= p_start_date
3062 and msc_gantt_utils.getResReqEndDate(nvl(mrr.firm_flag,0),
3063 mrir.start_date, mrir.end_date, mrr.firm_start_date, mrr.firm_end_date, mrr.status, mrr.applied) >= p_end_date )
3064 )
3065 group by
3066 mgq.row_index,
3067 mrir.batch_number,
3068 msc_gantt_utils.getResReqType(mrr.plan_id, mrr.schedule_flag, mrr.parent_seq_num, mrr.setup_id),
3069 msc_gantt_utils.getDisplayType(p_display_type,
3070 msc_gantt_utils.getResReqEndDate(nvl(mrr.firm_flag,0),
3071 mrir.start_date, mrir.end_date, mrr.firm_start_date, mrr.firm_end_date, mrr.status, mrr.applied),
3072 msc_gantt_utils.getResReqUlpsd(mrr.plan_id, mrr.sr_instancE_id, mrr.organization_id,
3073 mrr.department_id, mrr.resource_id, mrr.supply_id, mrr.operation_seq_num, mrr.resource_seq_num,
3074 mrr.orig_resource_seq_num, mrr.parent_seq_num),
3075 mrr.firm_flag,
3076 msc_gantt_utils.isResConstraint(mrr.plan_id,
3077 mrr.sr_instance_id, mrr.organization_id,
3078 ms.inventory_item_id, mrr.department_id, mrr.resource_id, mrr.supply_id),
3079 g_gantt_rh_toler_days_early,
3080 g_gantt_rh_toler_days_late);
3081
3082 l_res_rows number;
3083 l_res_inst_rows number;
3084 l_res_batch_rows number;
3085 l_res_inst_batch_rows number;
3086
3087 begin
3088
3089 --l_res_rows := msc_gantt_utils.isResRowInGantt(p_query_id, sys_no, sys_no, sys_yes);
3090 --l_res_inst_rows := msc_gantt_utils.isResRowInGantt(p_query_id, sys_yes, sys_no, sys_yes);
3091 --l_res_batch_rows := msc_gantt_utils.isResRowInGantt(p_query_id, sys_no, sys_yes);
3092 --l_res_inst_batch_rows := msc_gantt_utils.isResRowInGantt(p_query_id, sys_yes, sys_yes);
3093 --4997096 bugfix, instead calls the below procedure
3094 msc_gantt_utils.isResRowInGantt(p_query_id, l_res_rows, l_res_inst_rows, l_res_batch_rows, l_res_inst_batch_rows);
3095
3096 put_line('populateResReqGanttNew: res - res inst - res batch - res inst batch: '||
3097 l_res_rows ||' - '|| l_res_inst_rows ||' - '|| l_res_batch_rows
3098 ||' - '|| l_res_inst_batch_rows);
3099
3100 if ( l_res_rows = sys_yes ) then
3101 open res_req_cur;
3102 fetch res_req_cur bulk collect into v_row_index, v_req_start,
3103 v_req_end, v_resource_units, v_resource_hours, v_batch, v_schedule_flag,
3104 v_display_type;
3105 close res_req_cur;
3106
3107 put_line('populateResReqGanttNew: NEW LOGIC res req rows: '||v_row_index.count);
3108
3109 populateResDtlTabIntoGantt(p_query_id, RES_REQ_ROW_TYPE, v_row_index,
3110 v_req_start, v_req_end, v_resource_units, v_resource_hours, v_schedule_flag, SUMMARY_DATA,
3111 v_display_type);
3112 end if;
3113
3114 if ( l_res_batch_rows = sys_yes ) then
3115 open res_req_btch_cur;
3116 fetch res_req_btch_cur bulk collect into v_row_index, v_req_start,
3117 v_req_end, v_resource_units, v_resource_hours, v_batch, v_schedule_flag,
3118 v_display_type;
3119 close res_req_btch_cur;
3120
3121 put_line('populateResReqGanttNew: NEW LOGIC batch res req rows: '||v_row_index.count);
3122
3123 populateResDtlTabIntoGantt(p_query_id, RES_REQ_ROW_TYPE, v_row_index,
3124 v_req_start, v_req_end, v_resource_units, v_resource_hours, v_schedule_flag, SUMMARY_DATA,
3125 v_display_type, sys_yes);
3126 end if;
3127
3128 if ( l_res_inst_rows = sys_yes ) then
3129 open res_inst_req_cur;
3130 fetch res_inst_req_cur bulk collect into v_row_index, v_req_start,
3131 v_req_end, v_resource_units, v_resource_hours, v_batch, v_schedule_flag,
3132 v_display_type;
3133 close res_inst_req_cur;
3134
3135 put_line('populateResReqGanttNew: NEW LOGIC res inst req rows: '||v_row_index.count);
3136
3137 populateResDtlTabIntoGantt(p_query_id, RES_REQ_ROW_TYPE, v_row_index,
3138 v_req_start, v_req_end, v_resource_units, v_resource_hours, v_schedule_flag, SUMMARY_DATA,
3139 v_display_type);
3140
3141 end if;
3142
3143 if ( l_res_inst_batch_rows = sys_yes ) then
3144 open res_inst_req_btch_cur;
3145 fetch res_inst_req_btch_cur bulk collect into v_row_index, v_req_start,
3146 v_req_end, v_resource_units, v_resource_hours, v_batch, v_schedule_flag,
3147 v_display_type;
3148 close res_inst_req_btch_cur;
3149
3150 put_line('populateResReqGanttNew: NEW LOGIC batch res inst req rows: '||v_row_index.count);
3151
3152 populateResDtlTabIntoGantt(p_query_id, RES_REQ_ROW_TYPE, v_row_index,
3153 v_req_start, v_req_end, v_resource_units, v_resource_hours, v_schedule_flag, SUMMARY_DATA,
3154 v_display_type, sys_yes);
3155
3156 end if;
3157
3158 end populateResReqGanttNew;
3159
3160 function isResRowValidforResActView(p_plan number, p_inst number, p_org number,
3161 p_dept number, p_res number, p_start_date date, p_end_date date) return number is
3162
3163 cursor c_res_row is
3164 select sys_yes
3165 from msc_plan_organizations mpo,
3166 msc_resource_requirements mrr,
3167 msc_department_resources mdr,
3168 msc_plans mp
3169 where mrr.plan_id = p_plan
3170 and mrr.sr_instance_id = p_inst
3171 and mrr.organization_id = p_org
3172 and mrr.department_id = p_dept
3173 and mrr.resource_id = p_res
3174 and mdr.plan_id = mrr.plan_id
3175 and mdr.organization_id = mrr.organization_id
3176 and mdr.sr_instance_id = mrr.sr_instance_id
3177 and mdr.department_id = mrr.department_id
3178 and mdr.resource_id = mrr.resource_id
3179 and mrr.plan_id = mpo.plan_id
3180 and mrr.sr_instance_id = mpo.sr_instance_id
3181 and mrr.organization_id = mpo.organization_id
3182 and mrr.plan_id = mp.plan_id
3183 and ( ( nvl(curr_ds_enabled_flag, ds_enabled_flag) = 2 or nvl(mdr.schedule_to_instance, sys_no) = sys_no )
3184 or ( nvl(curr_ds_enabled_flag, ds_enabled_flag) = 1
3185 and ( nvl(mdr.schedule_to_instance, sys_no) = sys_yes
3186 and p_start_date >= nvl(mp.min_cutoff_bucket,0)+mp.data_start_date )
3187 ));
3188
3189 l_temp varchar2(10);
3190 begin
3191 open c_res_row;
3192 fetch c_res_row into l_temp;
3193 close c_res_row;
3194 return l_temp;
3195 end isResRowValidforResActView;
3196
3197 procedure populateResActGantt(p_query_id number,
3198 p_start_date date, p_end_date date,
3199 p_batched_res_act number,
3200 p_require_data IN OUT NOCOPY msc_gantt_utils.maxCharTbl,
3201 p_display_type number) is
3202
3203 cursor res_act_cur is
3204 select mgq.row_index,
3205 mrr.sr_instance_id,
3206 mrr.organization_id,
3207 mrr.supply_id,
3208 mrr.transaction_id,
3209 nvl(mrr.status,0) status,
3210 nvl(mrr.applied,0) applied,
3211 nvl(mrr.firm_flag,0) res_firm_flag,
3212 ms.firm_planned_type sup_firm_flag,
3213 msc_gantt_utils.getResReqStartDate(nvl(mrr.firm_flag,0), mrr.start_date, mrr.end_date,
3214 mrr.firm_start_date, mrr.firm_end_date, mrr.status, mrr.applied) start_date,
3215 msc_gantt_utils.getResReqEndDate(nvl(mrr.firm_flag,0), mrr.start_date, mrr.end_date,
3216 mrr.firm_start_date, mrr.firm_end_date, mrr.status, mrr.applied) end_date,
3217 msc_gantt_utils.getResReqType(mrr.plan_id, mrr.schedule_flag, mrr.parent_seq_num, mrr.setup_id) schedule_flag,
3218 msc_gantt_utils.isResConstraint(mrr.plan_id, mrr.sr_instance_id,
3219 mrr.organization_id, ms.inventory_item_id,
3220 mrr.department_id, mrr.resource_id, mrr.supply_id) res_constraint,
3221 ms.new_order_quantity qty,
3222 nvl(mrr.batch_number, mbp_null_value),
3223 mrr.assigned_units,
3224 nvl(mrr.group_sequence_id, mbp_null_value),
3225 nvl(mrr.group_sequence_number, mbp_null_value),
3226 mrr.earliest_start_date,
3227 mrr.earliest_completion_date,
3228 mrr.ulpsd,
3229 mrr.ulpcd,
3230 mrr.uepsd,
3231 mrr.uepcd,
3232 mrr.eacd,
3233 msc_gantt_utils.getResActResNodeLabel(mrr.plan_id, mrr.sr_instance_id, mrr.transaction_id) bar_text,
3234 ms.inventory_item_id,
3235 msc_get_name.supply_order_number(ms.order_type, ms.order_number, ms.plan_id,
3236 ms.sr_instance_id, ms.transaction_id, ms.disposition_id) order_number,
3237 mrr.operation_seq_num,
3238 mrr.resource_seq_num,
3239 mdr.resource_description,
3240 mi.item_name item,
3241 mi2.description assembly_item_desc,
3242 decode(mrr.resource_hours, 0, to_number(null),
3243 nvl(mrr.cummulative_quantity,ms.new_order_quantity)) schedule_qty,
3244 decode(mrr.from_setup_id,
3245 to_number(null), null,
3246 msc_get_name.setup_code(mrr.plan_id, mrr.sr_instance_id, mrr.resource_id,
3247 mrr.organization_id, mrr.from_setup_id)) from_setup_code,
3248 decode(mrr.setup_id,
3249 to_number(null), null,
3250 msc_get_name.setup_code(mrr.plan_id, mrr.sr_instance_id, mrr.resource_id,
3251 mrr.organization_id, mrr.setup_id)) to_setup_code,
3252 decode(mrr.from_setup_id,
3253 to_number(null), null,
3254 msc_gantt_utils.getTansitionValue(mrr.plan_id, mrr.sr_instance_id,
3255 mrr.organization_id, mrr.department_id, mrr.resource_id, mrr.from_setup_id,
3256 mrr.setup_id, 'STANDARD_OPERATION_CODE')) std_op_code,
3257 decode(mrr.from_setup_id,
3258 to_number(null), null,
3259 msc_gantt_utils.getTansitionValue(mrr.plan_id, mrr.sr_instance_id, mrr.organization_id,
3260 mrr.department_id, mrr.resource_id, mrr.from_setup_id,
3261 mrr.setup_id, 'TRANSITION_TIME')) changeover_time,
3262 decode(mrr.from_setup_id,
3263 to_number(null), null,
3264 msc_gantt_utils.getTansitionValue(mrr.plan_id, mrr.sr_instance_id, mrr.organization_id,
3265 mrr.department_id, mrr.resource_id, mrr.from_setup_id,
3266 mrr.setup_id, 'TRANSITION_PENALTY')) changeover_penalty,
3267 msc_gantt_utils.isResOverload(mrr.plan_id, mrr.sr_instance_id,
3268 mrr.organization_id, ms.inventory_item_id,
3269 mrr.department_id, mrr.resource_id, mrr.supply_id) res_overload
3270 from msc_resource_requirements mrr,
3271 msc_department_resources mdr,
3272 msc_supplies ms,
3273 msc_items mi,
3274 msc_items mi2,
3275 msc_gantt_query mgq,
3276 msc_plan_organizations mpo,
3277 msc_plans mp
3278 where mgq.query_id = p_query_id
3279 and mgq.row_flag = SYS_YES
3280 and ( ( p_batched_res_act = RES_REQ_ROW_TYPE )
3281 or ( p_batched_res_act = RES_ACT_BATCHED_ROW_TYPE and ( nvl(mdr.batchable_flag,2) = 2 or mrr.batch_number is null) ) )
3282 and mgq.is_fetched = SYS_NO
3283 and mgq.res_instance_id = MBP_NULL_VALUE
3284 and mrr.plan_id = mgq.plan_id
3285 and mrr.sr_instance_id = mgq.sr_instance_id
3286 and mrr.organization_id = mgq.organization_id
3287 and mrr.department_id = mgq.department_id
3288 and mrr.resource_id = mgq.resource_id
3289 and mrr.end_date is not null
3290 and nvl(mrr.parent_id,2) =2
3291 and ( ( msc_gantt_utils.getResReqStartDate(nvl(mrr.firm_flag,0),
3292 mrr.start_date, mrr.end_date, mrr.firm_start_date, mrr.firm_end_date, mrr.status, mrr.applied)
3293 between p_start_date and p_end_date
3294 )
3295 or ( msc_gantt_utils.getResReqEndDate(nvl(mrr.firm_flag,0),
3296 mrr.start_date, mrr.end_date, mrr.firm_start_date, mrr.firm_end_date, mrr.status, mrr.applied)
3297 between p_start_date and p_end_date )
3298 or ( msc_gantt_utils.getResReqStartDate(nvl(mrr.firm_flag,0),
3299 mrr.start_date, mrr.end_date, mrr.firm_start_date, mrr.firm_end_date, mrr.status, mrr.applied) <= p_start_date
3300 and msc_gantt_utils.getResReqEndDate(nvl(mrr.firm_flag,0),
3301 mrr.start_date, mrr.end_date, mrr.firm_start_date, mrr.firm_end_date, mrr.status, mrr.applied) >= p_end_date )
3302 )
3303 and mrr.plan_id = mdr.plan_id
3304 and mrr.organization_id = mdr.organization_id
3305 and mrr.sr_instance_id = mdr.sr_instance_id
3306 and mrr.department_id = mdr.department_id
3307 and mrr.resource_id = mdr.resource_id
3308 and ms.plan_id = mrr.plan_id
3309 and ms.transaction_id = mrr.supply_id
3310 and ms.sr_instance_id = mrr.sr_instance_id
3311 and ms.inventory_item_id = mi.inventory_item_id
3312 and mrr.assembly_item_id = mi2.inventory_item_id
3313 and mrr.plan_id = mpo.plan_id
3314 and mrr.sr_instance_id = mpo.sr_instance_id
3315 and mrr.organization_id = mpo.organization_id
3316 and mrr.plan_id = mp.plan_id
3317 and ( ( nvl(mpo.curr_ds_enabled_flag, mpo.ds_enabled_flag) = 2 or nvl(mdr.schedule_to_instance, sys_no) = sys_no )
3318 or ( nvl(mpo.curr_ds_enabled_flag, mpo.ds_enabled_flag) = 1
3319 and ( nvl(mdr.schedule_to_instance, sys_no) = sys_yes
3320 and p_start_date >= nvl(mp.min_cutoff_bucket,0)+mp.data_start_date )
3321 ));
3322
3323 cursor res_inst_act_cur is
3324 select mgq.row_index,
3325 mrr.sr_instance_id,
3326 mrr.organization_id,
3327 mrr.supply_id,
3328 mrir.res_inst_transaction_id,
3329 nvl(mrr.status,0) status,
3330 nvl(mrr.applied,0) applied,
3331 nvl(mrr.firm_flag,0) res_firm_flag,
3332 ms.firm_planned_type sup_firm_flag,
3333 msc_gantt_utils.getResReqStartDate(nvl(mrr.firm_flag,0), mrir.start_date, mrir.end_date,
3334 mrr.firm_start_date, mrr.firm_end_date, mrr.status, mrr.applied) start_date,
3335 msc_gantt_utils.getResReqEndDate(nvl(mrr.firm_flag,0), mrir.start_date, mrir.end_date,
3336 mrr.firm_start_date, mrr.firm_end_date, mrr.status, mrr.applied) end_date,
3337 msc_gantt_utils.getResReqType(mrr.plan_id, mrr.schedule_flag, mrr.parent_seq_num, mrr.setup_id) schedule_flag,
3338 msc_gantt_utils.isResConstraint(mrr.plan_id, mrr.sr_instance_id,
3339 mrr.organization_id, ms.inventory_item_id,
3340 mrr.department_id, mrr.resource_id, mrr.supply_id) res_constraint,
3341 ms.new_order_quantity qty,
3342 nvl(mrir.batch_number, mbp_null_value),
3343 1 assigned_units,
3344 nvl(mrr.group_sequence_id, mbp_null_value),
3345 nvl(mrr.group_sequence_number, mbp_null_value),
3346 mrr.earliest_start_date,
3347 mrr.earliest_completion_date,
3348 mrr.ulpsd,
3349 mrr.ulpcd,
3350 mrr.uepsd,
3351 mrr.uepcd,
3352 mrr.eacd,
3353 msc_gantt_utils.getResActResNodeLabel(mrr.plan_id, mrr.sr_instance_id, mrr.transaction_id) bar_text,
3354 ms.inventory_item_id,
3355 msc_get_name.supply_order_number(ms.order_type, ms.order_number, ms.plan_id,
3356 ms.sr_instance_id, ms.transaction_id, ms.disposition_id) order_number,
3357 mrr.operation_seq_num,
3358 mrr.resource_seq_num,
3359 mdr.resource_description,
3360 mi.item_name item,
3361 mi2.description assembly_item_desc,
3362 decode(mrr.resource_hours, 0, to_number(null),
3363 nvl(mrr.cummulative_quantity,ms.new_order_quantity)) schedule_qty,
3364 decode(mrr.from_setup_id,
3365 to_number(null), null,
3366 msc_get_name.setup_code(mrr.plan_id, mrr.sr_instance_id, mrr.resource_id,
3367 mrr.organization_id, mrr.from_setup_id)) from_setup_code,
3368 decode(mrr.setup_id,
3369 to_number(null), null,
3370 msc_get_name.setup_code(mrr.plan_id, mrr.sr_instance_id, mrr.resource_id,
3371 mrr.organization_id, mrr.setup_id)) to_setup_code,
3372 decode(mrr.from_setup_id,
3373 to_number(null), null,
3374 msc_gantt_utils.getTansitionValue(mrr.plan_id, mrr.sr_instance_id,
3375 mrr.organization_id, mrr.department_id, mrr.resource_id, mrr.from_setup_id,
3376 mrr.setup_id, 'STANDARD_OPERATION_CODE')) std_op_code,
3377 decode(mrr.from_setup_id,
3378 to_number(null), null,
3379 msc_gantt_utils.getTansitionValue(mrr.plan_id, mrr.sr_instance_id, mrr.organization_id,
3380 mrr.department_id, mrr.resource_id, mrr.from_setup_id,
3381 mrr.setup_id, 'TRANSITION_TIME')) changeover_time,
3382 decode(mrr.from_setup_id,
3383 to_number(null), null,
3384 msc_gantt_utils.getTansitionValue(mrr.plan_id, mrr.sr_instance_id, mrr.organization_id,
3385 mrr.department_id, mrr.resource_id, mrr.from_setup_id,
3386 mrr.setup_id, 'TRANSITION_PENALTY')) changeover_penalty,
3387 msc_gantt_utils.isResOverload(mrr.plan_id, mrr.sr_instance_id,
3388 mrr.organization_id, ms.inventory_item_id,
3389 mrr.department_id, mrr.resource_id, mrr.supply_id) res_overload
3390 from msc_resource_instance_reqs mrir,
3391 msc_resource_requirements mrr,
3392 msc_department_resources mdr,
3393 msc_supplies ms,
3394 msc_items mi,
3395 msc_items mi2,
3396 msc_gantt_query mgq
3397 where mgq.query_id = p_query_id
3398 and mgq.row_flag = SYS_YES
3399 and ( ( p_batched_res_act = RES_REQ_ROW_TYPE )
3400 or ( p_batched_res_act = RES_ACT_BATCHED_ROW_TYPE and ( nvl(mdr.batchable_flag,2) = 2 or mrir.batch_number is null )) )
3401 and mgq.is_fetched = SYS_NO
3402 and mgq.res_instance_id <> MBP_NULL_VALUE
3403 and mrir.plan_id = mgq.plan_id
3404 and mrir.sr_instance_id = mgq.sr_instance_id
3405 and mrir.organization_id = mgq.organization_id
3406 and mrir.department_id = mgq.department_id
3407 and mrir.resource_id = mgq.resource_id
3408 and mrir.res_instance_id = mgq.res_instance_id
3409 and nvl(mrir.serial_number, MBP_NULL_VALUE_CHAR) = nvl(mgq.serial_number, MBP_NULL_VALUE_CHAR)
3410 and mrir.end_date is not null
3411 and nvl(mrir.parent_id,2) =2
3412 and mrir.plan_id = mrr.plan_id
3413 and mrir.sr_instance_id = mrr.sr_instance_id
3414 and mrir.organization_id = mrr.organization_id
3415 and mrir.department_id = mrr.department_id
3416 and mrir.resource_id = mrr.resource_id
3417 and mrir.supply_id = mrr.supply_id
3418 and mrir.operation_seq_num = mrr.operation_seq_num
3419 and mrir.resource_seq_num = mrr.resource_seq_num
3420 and nvl(mrir.orig_resource_seq_num, mbp_null_value) = nvl(mrr.orig_resource_seq_num, mbp_null_value)
3421 and nvl(mrir.parent_seq_num, mbp_null_value) = nvl(mrr.parent_seq_num, mbp_null_value)
3422 and nvl(mrir.parent_id, mbp_null_value) = nvl(mrr.parent_id, mbp_null_value)
3423 and mrir.start_date = nvl(mrr.firm_start_date, mrr.start_date)
3424 and mrir.end_date = nvl(mrr.firm_end_date, mrr.end_date)
3425 and nvl(mrr.parent_id, 2) = 2
3426 and ( ( msc_gantt_utils.getResReqStartDate(nvl(mrr.firm_flag,0),
3427 mrir.start_date, mrir.end_date, mrr.firm_start_date, mrr.firm_end_date, mrr.status, mrr.applied)
3428 between p_start_date and p_end_date
3429 )
3430 or ( msc_gantt_utils.getResReqEndDate(nvl(mrr.firm_flag,0),
3431 mrir.start_date, mrir.end_date, mrr.firm_start_date, mrr.firm_end_date, mrr.status, mrr.applied)
3432 between p_start_date and p_end_date )
3433 or ( msc_gantt_utils.getResReqStartDate(nvl(mrr.firm_flag,0),
3434 mrir.start_date, mrir.end_date, mrr.firm_start_date, mrr.firm_end_date, mrr.status, mrr.applied) <= p_start_date
3435 and msc_gantt_utils.getResReqEndDate(nvl(mrr.firm_flag,0),
3436 mrir.start_date, mrir.end_date, mrr.firm_start_date, mrr.firm_end_date, mrr.status, mrr.applied) >= p_end_date )
3437 )
3438 and ms.plan_id = mrr.plan_id
3439 and ms.transaction_id = mrr.supply_id
3440 and ms.sr_instance_id = mrr.sr_instance_id
3441 and mrr.plan_id = mdr.plan_id
3442 and mrr.organization_id = mdr.organization_id
3443 and mrr.sr_instance_id = mdr.sr_instance_id
3444 and mrr.department_id = mdr.department_id
3445 and mrr.resource_id = mdr.resource_id
3446 and ms.inventory_item_id = mi.inventory_item_id
3447 and mrr.assembly_item_id = mi2.inventory_item_id;
3448
3449 cursor res_act_batch_cur is
3450 select mgq.row_index,
3451 mrr.sr_instance_id,
3452 mrr.organization_id,
3453 msc_gantt_utils.getResReqStartDate(nvl(mrr.firm_flag,0), mrr.start_date, mrr.end_date,
3454 mrr.firm_start_date, mrr.firm_end_date, mrr.status, mrr.applied) start_date,
3455 msc_gantt_utils.getResReqEndDate(nvl(mrr.firm_flag,0), mrr.start_date, mrr.end_date,
3456 mrr.firm_start_date, mrr.firm_end_date, mrr.status, mrr.applied) end_date,
3457 msc_gantt_utils.getResReqType(mrr.plan_id, mrr.schedule_flag, mrr.parent_seq_num, mrr.setup_id) schedule_flag,
3458 sum(ms.new_order_quantity) qty,
3459 mrr.batch_number,
3460 msc_gantt_utils.getResBatchNodeLabel(
3461 nvl(decode(mrr.setup_id,
3462 to_number(null), null_space,
3463 msc_gantt_utils.getSetupCode(mrr.plan_id,
3464 mrr.sr_instance_id, mrr.resource_id, mrr.setup_id)),
3465 null_space),
3466 msc_get_name.org_code(mrr.organization_id, mrr.sr_instance_id),
3467 to_char(sum(ms.new_order_quantity)),
3468 to_char(mrr.batch_number),
3469 to_char(sum(mrr.capacity_consumed_ratio))) bar_text
3470 from msc_resource_requirements mrr,
3471 msc_supplies ms,
3472 msc_gantt_query mgq,
3473 msc_plan_organizations mpo,
3474 msc_department_resources mdr,
3475 msc_plans mp
3476 where mgq.query_id = p_query_id
3477 and mgq.row_flag = SYS_YES
3478 and mgq.is_fetched = SYS_NO
3479 and mgq.res_instance_id = MBP_NULL_VALUE
3480 and mrr.plan_id = mgq.plan_id
3481 and mrr.sr_instance_id = mgq.sr_instance_id
3482 and mrr.organization_id = mgq.organization_id
3483 and mrr.department_id = mgq.department_id
3484 and mrr.resource_id = mgq.resource_id
3485 and mrr.batch_number is not null
3486 and mrr.end_date is not null
3487 and nvl(mrr.parent_id,2) = 2
3488 and ( ( msc_gantt_utils.getResReqStartDate(nvl(mrr.firm_flag,0),
3489 mrr.start_date, mrr.end_date, mrr.firm_start_date, mrr.firm_end_date, mrr.status, mrr.applied)
3490 between p_start_date and p_end_date
3491 )
3492 or ( msc_gantt_utils.getResReqEndDate(nvl(mrr.firm_flag,0),
3493 mrr.start_date, mrr.end_date, mrr.firm_start_date, mrr.firm_end_date, mrr.status, mrr.applied)
3494 between p_start_date and p_end_date )
3495 or ( msc_gantt_utils.getResReqStartDate(nvl(mrr.firm_flag,0),
3496 mrr.start_date, mrr.end_date, mrr.firm_start_date, mrr.firm_end_date, mrr.status, mrr.applied) <= p_start_date
3497 and msc_gantt_utils.getResReqEndDate(nvl(mrr.firm_flag,0),
3498 mrr.start_date, mrr.end_date, mrr.firm_start_date, mrr.firm_end_date, mrr.status, mrr.applied) >= p_end_date )
3499 )
3500 and ms.plan_id = mrr.plan_id
3501 and ms.transaction_id = mrr.supply_id
3502 and ms.sr_instance_id = mrr.sr_instance_id
3503 and mdr.plan_id = mrr.plan_id
3504 and mdr.organization_id = mrr.organization_id
3505 and mdr.sr_instance_id = mrr.sr_instance_id
3506 and mdr.department_id = mrr.department_id
3507 and mdr.resource_id = mrr.resource_id
3508 and mrr.plan_id = mpo.plan_id
3509 and mrr.sr_instance_id = mpo.sr_instance_id
3510 and mrr.organization_id = mpo.organization_id
3511 and mrr.plan_id = mp.plan_id
3512 and ( ( nvl(mpo.curr_ds_enabled_flag, mpo.ds_enabled_flag) = 2 or nvl(mdr.schedule_to_instance, sys_no) = sys_no )
3513 or ( nvl(mpo.curr_ds_enabled_flag, mpo.ds_enabled_flag) = 1
3514 and ( nvl(mdr.schedule_to_instance, sys_no) = sys_yes
3515 and p_start_date >= nvl(mp.min_cutoff_bucket,0)+mp.data_start_date )
3516 ))
3517 group by mgq.row_index,
3518 mrr.plan_id,
3519 mrr.sr_instance_id,
3520 mrr.organization_id,
3521 msc_get_name.org_code(mrr.organization_id, mrr.sr_instance_id),
3522 mrr.resource_id,
3523 mrr.batch_number,
3524 msc_gantt_utils.getResReqStartDate(nvl(mrr.firm_flag,0), mrr.start_date, mrr.end_date,
3525 mrr.firm_start_date, mrr.firm_end_date, mrr.status, mrr.applied),
3526 msc_gantt_utils.getResReqEndDate(nvl(mrr.firm_flag,0), mrr.start_date, mrr.end_date,
3527 mrr.firm_start_date, mrr.firm_end_date, mrr.status, mrr.applied),
3528 msc_gantt_utils.getResReqType(mrr.plan_id, mrr.schedule_flag, mrr.parent_seq_num, mrr.setup_id),
3529 mrr.setup_id;
3530
3531 cursor res_inst_act_batch_cur is
3532 select mgq.row_index,
3533 mrr.sr_instance_id,
3534 mrr.organization_id,
3535 msc_gantt_utils.getResReqStartDate(nvl(mrr.firm_flag,0), mrir.start_date, mrir.end_date,
3536 mrr.firm_start_date, mrr.firm_end_date, mrr.status, mrr.applied) start_date,
3537 msc_gantt_utils.getResReqEndDate(nvl(mrr.firm_flag,0), mrir.start_date, mrir.end_date,
3538 mrr.firm_start_date, mrr.firm_end_date, mrr.status, mrr.applied) end_date,
3539 msc_gantt_utils.getResReqType(mrr.plan_id, mrr.schedule_flag, mrr.parent_seq_num, mrr.setup_id) schedule_flag,
3540 sum(ms.new_order_quantity) qty,
3541 mrir.batch_number,
3542 msc_gantt_utils.getResBatchNodeLabel(
3543 nvl(decode(mrr.setup_id,
3544 to_number(null), null_space,
3545 msc_gantt_utils.getSetupCode(mrr.plan_id,
3546 mrr.sr_instance_id, mrr.resource_id, mrr.setup_id)),
3547 null_space),
3548 msc_get_name.org_code(mrr.organization_id, mrr.sr_instance_id),
3549 to_char(sum(ms.new_order_quantity)),
3550 to_char(mrir.batch_number),
3551 to_char(sum(mrir.capacity_consumed_ratio))) bar_text
3552 from msc_resource_instance_reqs mrir,
3553 msc_resource_requirements mrr,
3554 msc_supplies ms,
3555 msc_gantt_query mgq
3556 where mgq.query_id = p_query_id
3557 and mgq.row_flag = SYS_YES
3558 and mgq.is_fetched = SYS_NO
3559 and mgq.res_instance_id <> MBP_NULL_VALUE
3560 and mrir.plan_id = mgq.plan_id
3561 and mrir.sr_instance_id = mgq.sr_instance_id
3562 and mrir.organization_id = mgq.organization_id
3563 and mrir.department_id = mgq.department_id
3564 and mrir.resource_id = mgq.resource_id
3565 and mrir.res_instance_id = mgq.res_instance_id
3566 and nvl(mrir.serial_number, MBP_NULL_VALUE_CHAR) = nvl(mgq.serial_number, MBP_NULL_VALUE_CHAR)
3567 and mrir.end_date is not null
3568 and mrir.batch_number is not null
3569 and nvl(mrir.parent_id,2) =2
3570 and mrir.plan_id = mrr.plan_id
3571 and mrir.sr_instance_id = mrr.sr_instance_id
3572 and mrir.organization_id = mrr.organization_id
3573 and mrir.department_id = mrr.department_id
3574 and mrir.resource_id = mrr.resource_id
3575 and mrir.supply_id = mrr.supply_id
3576 and mrir.operation_seq_num = mrr.operation_seq_num
3577 and mrir.resource_seq_num = mrr.resource_seq_num
3578 and nvl(mrir.orig_resource_seq_num, mbp_null_value) = nvl(mrr.orig_resource_seq_num, mbp_null_value)
3579 and nvl(mrir.parent_seq_num, mbp_null_value) = nvl(mrr.parent_seq_num, mbp_null_value)
3580 and nvl(mrir.parent_id, mbp_null_value) = nvl(mrr.parent_id, mbp_null_value)
3581 and mrir.start_date = nvl(mrr.firm_start_date, mrr.start_date)
3582 and mrir.end_date = nvl(mrr.firm_end_date, mrr.end_date)
3583 and nvl(mrr.parent_id, 2) = 2
3584 and ( ( msc_gantt_utils.getResReqStartDate(nvl(mrr.firm_flag,0),
3585 mrir.start_date, mrir.end_date, mrr.firm_start_date, mrr.firm_end_date, mrr.status, mrr.applied)
3586 between p_start_date and p_end_date
3587 )
3588 or ( msc_gantt_utils.getResReqEndDate(nvl(mrr.firm_flag,0),
3589 mrir.start_date, mrir.end_date, mrr.firm_start_date, mrr.firm_end_date, mrr.status, mrr.applied)
3590 between p_start_date and p_end_date )
3591 or ( msc_gantt_utils.getResReqStartDate(nvl(mrr.firm_flag,0),
3592 mrir.start_date, mrir.end_date, mrr.firm_start_date, mrr.firm_end_date, mrr.status, mrr.applied) <= p_start_date
3593 and msc_gantt_utils.getResReqEndDate(nvl(mrr.firm_flag,0),
3594 mrir.start_date, mrir.end_date, mrr.firm_start_date, mrr.firm_end_date, mrr.status, mrr.applied) >= p_end_date )
3595 )
3596 and ms.plan_id = mrr.plan_id
3597 and ms.transaction_id = mrr.supply_id
3598 and ms.sr_instance_id = mrr.sr_instance_id
3599 group by mgq.row_index,
3600 mrr.plan_id,
3601 mrr.sr_instance_id,
3602 mrr.organization_id,
3603 msc_get_name.org_code(mrr.organization_id, mrr.sr_instance_id),
3604 mrr.resource_id,
3605 mrir.batch_number,
3606 msc_gantt_utils.getResReqStartDate(nvl(mrr.firm_flag,0), mrir.start_date, mrir.end_date,
3607 mrr.firm_start_date, mrr.firm_end_date, mrr.status, mrr.applied),
3608 msc_gantt_utils.getResReqEndDate(nvl(mrr.firm_flag,0), mrir.start_date, mrir.end_date,
3609 mrr.firm_start_date, mrr.firm_end_date, mrr.status, mrr.applied),
3610 msc_gantt_utils.getResReqType(mrr.plan_id, mrr.schedule_flag, mrr.parent_seq_num, mrr.setup_id),
3611 mrr.setup_id;
3612
3613 l_op_seq number_arr;
3614 l_res_seq number_arr;
3615 l_res_desc char_arr;
3616 l_item_name char_arr;
3617 l_assy_item_desc char_arr;
3618 l_schedule_qty number_arr;
3619
3620 l_from_setup_code char_arr;
3621 l_to_setup_code char_arr;
3622 l_std_op_code char_arr;
3623 l_changeover_time char_arr;
3624 l_changeover_penalty char_arr;
3625
3626 l_min_capacity number_arr;
3627 l_max_capacity number_arr;
3628 l_capacity_used number_arr;
3629
3630 l_row_index number_arr;
3631 l_sr_instance_id number_arr;
3632 l_organization_id number_arr;
3633 l_inventory_item_id number_arr;
3634 l_dept_id number_arr;
3635 l_res_id number_arr;
3636 l_supply_id number_arr;
3637 l_transaction_id number_arr;
3638 l_status number_arr;
3639 l_applied number_arr;
3640 l_res_firm_flag number_arr;
3641 l_sup_firm_flag number_arr;
3642 l_start_date date_arr;
3643 l_end_date date_arr;
3644 l_schedule_flag number_arr;
3645 l_res_constraint number_arr;
3646 l_qty number_arr;
3647 l_batch_number number_arr;
3648 l_resource_units number_arr;
3649 l_group_sequence_id number_arr;
3650 l_group_sequence_number number_arr;
3651 l_cepst date_arr;
3652 l_cepct date_arr;
3653 l_ulpst date_arr;
3654 l_ulpct date_arr;
3655 l_uepst date_arr;
3656 l_uepct date_arr;
3657 l_eacd date_arr;
3658 l_bar_text char_arr;
3659 l_display_type number_arr;
3660 l_order_number char_arr;
3661 l_overload_flag number_arr;
3662
3663 l_res_rows number;
3664 l_res_inst_rows number;
3665 l_res_batch_rows number;
3666 l_res_inst_batch_rows number;
3667
3668 p_start_index number;
3669 l_batch_flag number;
3670 begin
3671
3672 p_start_index := mbp_null_value;
3673 if ( p_batched_res_act = RES_ACT_BATCHED_ROW_TYPE) then -- {
3674 l_batch_flag := sys_yes;
3675 else
3676 l_batch_flag := sys_no;
3677 end if; -- }
3678
3679 --l_res_rows := msc_gantt_utils.isResRowInGantt(p_query_id, sys_no, sys_no, sys_yes);
3680 --l_res_inst_rows := msc_gantt_utils.isResRowInGantt(p_query_id, sys_yes, sys_no, sys_yes);
3681 --l_res_batch_rows := msc_gantt_utils.isResRowInGantt(p_query_id, sys_no, sys_yes);
3682 --l_res_inst_batch_rows := msc_gantt_utils.isResRowInGantt(p_query_id, sys_yes, sys_yes);
3683 --4997096 bugfix, instead calls the below procedure
3684 msc_gantt_utils.isResRowInGantt(p_query_id, l_res_rows, l_res_inst_rows, l_res_batch_rows, l_res_inst_batch_rows, l_batch_flag);
3685
3686 put_line('populateResActGantt: res - inst- res batch - inst batch: '||l_res_rows ||' - '|| l_res_inst_rows ||' - '|| l_res_batch_rows ||' - '|| l_res_inst_batch_rows);
3687
3688 if ( l_res_rows = sys_yes ) then -- {
3689
3690 open res_act_cur;
3691 fetch res_act_cur bulk collect into l_row_index, l_sr_instance_id, l_organization_id,
3692 l_supply_id, l_transaction_id, l_status, l_applied, l_res_firm_flag,
3693 l_sup_firm_flag, l_start_date, l_end_date, l_schedule_flag, l_res_constraint,
3694 l_qty, l_batch_number, l_resource_units, l_group_sequence_id, l_group_sequence_number,
3695 l_cepst, l_cepct, l_ulpst, l_ulpct, l_uepst, l_uepct, l_eacd, l_bar_text, l_inventory_item_id,
3696 l_order_number, l_op_seq, l_res_seq, l_res_desc, l_item_name, l_assy_item_desc, l_schedule_qty,
3697 l_from_setup_code, l_to_setup_code, l_std_op_code, l_changeover_time, l_changeover_penalty, l_overload_flag;
3698 close res_act_cur;
3699
3700 put_line('populateResActGantt: res act rows: '||l_sr_instance_id.count);
3701
3702 populateResActIntoDtlGantt(p_query_id, RES_REQ_ROW_TYPE, SUMMARY_DATA,
3703 l_row_index, l_sr_instance_id, l_organization_id, l_supply_id,
3704 l_transaction_id, l_status, l_applied, l_res_firm_flag, l_sup_firm_flag,
3705 l_start_date, l_end_date, l_schedule_flag, l_res_constraint, l_qty, l_batch_number,
3706 l_resource_units, l_group_sequence_id, l_group_sequence_number,
3707 l_cepst, l_cepct, l_ulpst, l_ulpct, l_uepst, l_uepct, l_eacd, l_inventory_item_id, l_bar_text,
3708 l_order_number, l_op_seq, l_res_seq, l_res_desc, l_item_name, l_assy_item_desc, l_schedule_qty,
3709 l_from_setup_code, l_to_setup_code, l_std_op_code, l_changeover_time, l_changeover_penalty, l_overload_flag);
3710
3711 end if; -- }
3712
3713 if ( l_res_inst_rows = sys_yes ) then -- {
3714
3715 open res_inst_act_cur;
3716 fetch res_inst_act_cur bulk collect into l_row_index, l_sr_instance_id, l_organization_id,
3717 l_supply_id, l_transaction_id, l_status, l_applied, l_res_firm_flag,
3718 l_sup_firm_flag, l_start_date, l_end_date, l_schedule_flag, l_res_constraint,
3719 l_qty, l_batch_number, l_resource_units, l_group_sequence_id, l_group_sequence_number,
3720 l_cepst, l_cepct, l_ulpst, l_ulpct, l_uepst, l_uepct, l_eacd, l_bar_text, l_inventory_item_id,
3721 l_order_number, l_op_seq, l_res_seq, l_res_desc, l_item_name, l_assy_item_desc, l_schedule_qty,
3722 l_from_setup_code, l_to_setup_code, l_std_op_code, l_changeover_time, l_changeover_penalty, l_overload_flag;
3723 close res_inst_act_cur;
3724
3725 put_line('populateResActGantt: res inst act rows: '||l_sr_instance_id.count);
3726
3727 populateResActIntoDtlGantt(p_query_id, RES_REQ_ROW_TYPE, SUMMARY_DATA,
3728 l_row_index, l_sr_instance_id, l_organization_id, l_supply_id,
3729 l_transaction_id, l_status, l_applied, l_res_firm_flag, l_sup_firm_flag,
3730 l_start_date, l_end_date, l_schedule_flag, l_res_constraint, l_qty, l_batch_number,
3731 l_resource_units, l_group_sequence_id, l_group_sequence_number,
3732 l_cepst, l_cepct, l_ulpst, l_ulpct, l_uepst, l_uepct, l_eacd, l_inventory_item_id, l_bar_text,
3733 l_order_number, l_op_seq, l_res_seq, l_res_desc, l_item_name, l_assy_item_desc, l_schedule_qty,
3734 l_from_setup_code, l_to_setup_code, l_std_op_code, l_changeover_time, l_changeover_penalty, l_overload_flag);
3735
3736 end if; -- }
3737
3738 if ( p_batched_res_act = RES_ACT_BATCHED_ROW_TYPE) then -- {
3739 if ( l_res_batch_rows = sys_yes ) then -- {
3740
3741 open res_act_batch_cur;
3742 fetch res_act_batch_cur bulk collect into l_row_index, l_sr_instance_id, l_organization_id,
3743 l_start_date, l_end_date, l_schedule_flag, l_qty, l_batch_number, l_bar_text;
3744 close res_act_batch_cur;
3745
3746 put_line('populateResActGantt: batch res act rows: '||l_sr_instance_id.count);
3747
3748 populateBtchResIntoDtlGantt(p_query_id, RES_ACT_BATCHED_ROW_TYPE, SUMMARY_DATA,
3749 l_row_index, l_sr_instance_id, l_organization_id,
3750 l_start_date, l_end_date, l_schedule_flag, l_batch_number, l_qty, l_bar_text, RES_NODE);
3751
3752 end if; -- }
3753
3754 if ( l_res_inst_batch_rows = sys_yes ) then -- {
3755
3756 open res_inst_act_batch_cur;
3757 fetch res_inst_act_batch_cur bulk collect into l_row_index, l_sr_instance_id, l_organization_id,
3758 l_start_date, l_end_date, l_schedule_flag, l_qty, l_batch_number, l_bar_text;
3759 close res_inst_act_batch_cur;
3760
3761 put_line('populateResActGantt: batch res inst act rows: '||l_sr_instance_id.count);
3762
3763 populateBtchResIntoDtlGantt(p_query_id, RES_ACT_BATCHED_ROW_TYPE, SUMMARY_DATA,
3764 l_row_index, l_sr_instance_id, l_organization_id,
3765 l_start_date, l_end_date, l_schedule_flag, l_batch_number, l_qty, l_bar_text, RES_INST_NODE);
3766
3767 end if; -- }
3768 end if; -- }
3769
3770 for active_row in active_res_rows_cur(p_query_id) loop -- {
3771 if ( p_start_index = mbp_null_value) then
3772 p_start_index := active_row.row_index;
3773 end if;
3774
3775 select nvl(mgdq.sr_instance_id, mbp_null_value),
3776 nvl(mgdq.organization_id, mbp_null_value),
3777 nvl(mgdq.supply_id, mbp_null_value),
3778 nvl(mgdq.transaction_id, mbp_null_value),
3779 nvl(mgdq.status, mbp_null_value),
3780 nvl(mgdq.applied, mbp_null_value),
3781 nvl(mgdq.res_firm_flag, mbp_null_value),
3782 nvl(mgdq.sup_firm_flag, mbp_null_value),
3783 mgdq.start_date,
3784 mgdq.end_date,
3785 nvl(mgdq.schedule_flag, mbp_null_value),
3786 nvl(mgdq.late_flag, mbp_null_value),
3787 nvl(mgdq.supply_qty, mbp_null_value),
3788 nvl(mgdq.batch_number, mbp_null_value),
3789 nvl(mgdq.resource_units, mbp_null_value),
3790 nvl(mgdq.group_sequence_id, mbp_null_value),
3791 nvl(mgdq.group_sequence_number, mbp_null_value),
3792 nvl(mgdq.bar_label, null_space),
3793 msc_gantt_utils.getDisplayType(p_display_type, mgdq.end_date, mgdq.ulpst,
3794 mgdq.res_firm_flag, mgdq.late_flag, g_gantt_ra_toler_days_early,
3795 g_gantt_ra_toler_days_late) display_type,
3796 mgdq.cepst,
3797 mgdq.cepct,
3798 mgdq.ulpst,
3799 mgdq.ulpct,
3800 mgdq.uepst,
3801 mgdq.uepct,
3802 mgdq.eact,
3803 mgq.department_id,
3804 mgq.resource_id,
3805 mgdq.inventory_item_id,
3806 mgdq.order_number,
3807 mgdq.op_seq_num,
3808 mgdq.resource_seq_num,
3809 mgdq.resource_description,
3810 mgdq.item_name,
3811 mgdq.assembly_item_desc,
3812 mgdq.schedule_qty,
3813 mgdq.from_setup_code,
3814 mgdq.to_setup_code,
3815 mgdq.std_op_code,
3816 mgdq.changeover_time,
3817 mgdq.changeover_penalty,
3818 mgdq.min_capacity,
3819 mgdq.max_capacity,
3820 mgdq.capacity_used,
3821 mgdq.supp_avail_qty
3822 bulk collect into l_sr_instance_id, l_organization_id,
3823 l_supply_id, l_transaction_id, l_status, l_applied, l_res_firm_flag,
3824 l_sup_firm_flag, l_start_date, l_end_date, l_schedule_flag, l_res_constraint,
3825 l_qty, l_batch_number, l_resource_units,
3826 l_group_sequence_id, l_group_sequence_number, l_bar_text, l_display_type,
3827 l_cepst, l_cepct, l_ulpst, l_ulpct, l_uepst, l_uepct, l_eacd,
3828 l_dept_id, l_res_id, l_inventory_item_id, l_order_number,
3829 l_op_seq, l_res_seq, l_res_desc, l_item_name, l_assy_item_desc, l_schedule_qty,
3830 l_from_setup_code, l_to_setup_code, l_std_op_code, l_changeover_time,
3831 l_changeover_penalty, l_min_capacity, l_max_capacity, l_capacity_used,
3832 l_overload_flag
3833 from msc_gantt_dtl_query mgdq,
3834 msc_gantt_query mgq
3835 where mgq.query_id = p_query_id
3836 and mgq.row_index = active_row.row_index
3837 and mgq.query_id = mgdq.query_id
3838 and mgq.row_index = mgdq.row_index
3839 and mgdq.row_type in (RES_REQ_ROW_TYPE, RES_ACT_BATCHED_ROW_TYPE)
3840 and mgdq.parent_id = SUMMARY_DATA
3841 order by mgdq.start_date;
3842
3843 put_line('sending res act stream '||active_row.row_index);
3844
3845 sendResActStream(active_row.row_index, p_start_index, l_sr_instance_id,
3846 l_organization_id, l_supply_id, l_transaction_id, l_status, l_applied,
3847 l_res_firm_flag, l_sup_firm_flag, l_start_date, l_end_date, l_schedule_flag,
3848 l_res_constraint, l_qty, l_batch_number, l_resource_units, l_group_sequence_id,
3849 l_group_sequence_number, l_bar_text, l_display_type, l_cepst, l_cepct, l_ulpst,
3850 l_ulpct, l_uepst, l_uepct, l_eacd, l_dept_id, l_res_id, l_inventory_item_id,
3851 l_order_number, l_op_seq, l_res_seq, l_res_desc, l_item_name, l_assy_item_desc, l_schedule_qty,
3852 l_from_setup_code, l_to_setup_code, l_std_op_code, l_changeover_time, l_changeover_penalty,
3853 l_min_capacity, l_max_capacity, l_capacity_used, l_overload_flag, p_require_data);
3854 end loop; -- }
3855
3856 end populateResActGantt;
3857
3858 function getDisplayType(p_display_type number, p_end_date date,
3859 p_ulpsd date, p_res_firm_flag number, p_overload_flag number,
3860 p_days_early number, p_days_late number) return number is
3861
3862 retVal number := sys_no;
3863
3864 begin
3865 if ( p_display_type = DISPLAY_LATE ) then -- {
3866 if ( p_ulpsd + p_days_late > p_end_date ) then
3867 retVal := sys_yes;
3868 end if;
3869 elsif ( p_display_type = DISPLAY_EARLY ) then
3870 if ( p_ulpsd + p_days_early < p_end_date ) then
3871 retVal := sys_yes;
3872 end if;
3873 elsif ( p_display_type = DISPLAY_FIRM ) then
3874 if ( nvl(p_res_firm_flag,0) > 0 ) then
3875 retVal := sys_yes;
3876 end if;
3877 elsif ( p_display_type = DISPLAY_OVERLOAD ) then
3878 retVal := p_overload_flag;
3879 elsif ( p_display_type = DISPLAY_NONE ) then
3880 retVal := sys_no;
3881 end if; -- }
3882
3883 return retVal;
3884 end getDisplayType;
3885
3886 procedure populateSupplierGantt(p_query_id number, p_plan_id number,
3887 p_start_date date, p_end_date date) is
3888
3889 v_row_index number_arr := number_arr(0);
3890 v_start_date date_arr := date_arr(sysdate);
3891 v_qty number_arr:= number_arr(0);
3892 v_overload_qty number_arr:= number_arr(0);
3893 v_consumed_qty number_arr:= number_arr(0);
3894
3895 v_bkt_start date_arr;
3896 v_bkt_end date_arr;
3897
3898 l_mfg_cal_query_id number;
3899
3900 cursor c_mgq_rows is
3901 select row_index, inventory_item_id, supplier_id, supplier_site_id
3902 from msc_gantt_query
3903 where query_id = p_query_id;
3904
3905 cursor c_mis_inst_org (l_plan number, l_item number, l_supp number, l_supp_site number) is
3906 select sr_instance_id, organization_id
3907 from msc_item_suppliers
3908 where plan_id = l_plan
3909 and inventory_item_id = l_item
3910 and supplier_id = l_supp
3911 and supplier_site_id = l_supp_site;
3912
3913 l_row_index number;
3914 l_inventory_item_id number;
3915 l_supplier_id number;
3916 l_supplier_site_id number;
3917 l_org_id number;
3918 l_inst_id number;
3919
3920 begin
3921
3922 for cur_mgq_rows in c_mgq_rows
3923 loop -- {
3924
3925 l_row_index := cur_mgq_rows.row_index;
3926 l_inventory_item_id := cur_mgq_rows.inventory_item_id;
3927 l_supplier_id := cur_mgq_rows.supplier_id;
3928 l_supplier_site_id := cur_mgq_rows.supplier_site_id;
3929
3930 open c_mis_inst_org (g_plan_id, l_inventory_item_id, l_supplier_id, l_supplier_site_id);
3931 fetch c_mis_inst_org into l_inst_id, l_org_id;
3932 close c_mis_inst_org;
3933
3934 -- 1. available capacity for items with delivery calendar
3935 select mgq.row_index, mca.calendar_date, msc.capacity
3936 bulk collect into v_row_index, v_start_date, v_qty
3937 from msc_calendar_dates mca,
3938 msc_plans mp,
3939 msc_supplier_capacities msc,
3940 msc_item_suppliers mis,
3941 msc_gantt_query mgq
3942 where mgq.query_id = p_query_id
3943 and mgq.row_index = l_row_index
3944 and mgq.row_flag = SYS_YES
3945 and mgq.is_fetched = SYS_NO
3946 and msc.plan_id = mgq.plan_id
3947 and msc.sr_instance_id = l_inst_id
3948 and msc.organization_id = l_org_id
3949 and msc.inventory_item_id = mgq.inventory_item_id
3950 and msc.supplier_id = mgq.supplier_id
3951 and msc.supplier_site_id = mgq.supplier_site_id
3952 and msc.capacity >= 0 --4476899 bugfix
3953 and mp.plan_id = msc.plan_id
3954 and msc.plan_id = mis.plan_id
3955 and msc.sr_instance_id = mis.sr_instance_id
3956 and msc.organization_id = mis.organization_id
3957 and msc.inventory_item_id = mis.inventory_item_id
3958 and msc.supplier_id = mis.supplier_id
3959 and msc.supplier_site_id = mis.supplier_site_id
3960 and mca.calendar_date between p_start_date and p_end_date
3961 and mca.calendar_date between trunc(msc.from_date) and trunc(nvl(msc.to_date,p_end_date))
3962 and mca.calendar_date >= nvl(trunc(mis.supplier_lead_time_date+1),trunc(mp.plan_start_date+2))
3963 and mca.calendar_code = mis.delivery_calendar_code
3964 and mis.delivery_calendar_code is not null
3965 and mca.sr_instance_id = g_plan_cal_inst_id
3966 and mca.exception_set_id = g_plan_cal_excp_id
3967 and mca.seq_num is not null;
3968
3969 put_line('SUPP_AVAIL_ROW_TYPE rows items with delivery.cal: '|| v_row_index.count);
3970
3971 populateSuppDtlTabIntoGantt(p_query_id, SUPP_AVAIL_ROW_TYPE,
3972 v_row_index, v_start_date, v_qty, v_consumed_qty, SUMMARY_DATA);
3973
3974 l_mfg_cal_query_id := getMFQSequence(l_mfg_cal_query_id);
3975 msc_gantt_utils.getBucketDates(p_start_date, p_end_date, v_bkt_start, v_bkt_end, l_mfg_cal_query_id);
3976
3977 -- 2. available capacity for items with NO delivery calendar
3978 select mgq.row_index, mfq.date1, msc.capacity
3979 bulk collect into v_row_index, v_start_date, v_qty
3980 from msc_form_query mfq,
3981 msc_plans mp,
3982 msc_supplier_capacities msc,
3983 msc_item_suppliers mis,
3984 msc_gantt_query mgq
3985 where mgq.query_id = p_query_id
3986 and mgq.row_index = l_row_index
3987 and mgq.row_flag = SYS_YES
3988 and mgq.is_fetched = SYS_NO
3989 and msc.plan_id = mgq.plan_id
3990 and msc.sr_instance_id = l_inst_id
3991 and msc.organization_id = l_org_id
3992 and msc.inventory_item_id = mgq.inventory_item_id
3993 and msc.supplier_id = mgq.supplier_id
3994 and msc.supplier_site_id = mgq.supplier_site_id
3995 and msc.capacity >= 0 --4476899 bugfix
3996 and mp.plan_id = msc.plan_id
3997 and msc.plan_id = mis.plan_id
3998 and msc.sr_instance_id = mis.sr_instance_id
3999 and msc.organization_id = mis.organization_id
4000 and msc.inventory_item_id = mis.inventory_item_id
4001 and msc.supplier_id = mis.supplier_id
4002 and msc.supplier_site_id = mis.supplier_site_id
4003 and mis.delivery_calendar_code is null
4004 and mfq.query_id = l_mfg_cal_query_id
4005 and mfq.date1 between p_start_date and p_end_date
4006 and mfq.date1 between trunc(msc.from_date) and trunc(nvl(msc.to_date,p_end_date))
4007 and mfq.date1 >= nvl(trunc(mis.supplier_lead_time_date+1),trunc(mp.plan_start_date+2));
4008
4009 put_line('SUPP_AVAIL_ROW_TYPE rows items with NO delivery.cal: '|| v_row_index.count);
4010
4011 populateSuppDtlTabIntoGantt(p_query_id, SUPP_AVAIL_ROW_TYPE,
4012 v_row_index, v_start_date, v_qty, v_consumed_qty, SUMMARY_DATA);
4013
4014 end loop; -- }
4015
4016 -- 3. req/consumed capacity for all the items except MODELs
4017 select mgq.row_index,
4018 msr.consumption_date,
4019 sum(msr.overloaded_capacity) overload_qty,
4020 sum(msr.consumed_quantity) consumed_qty
4021 bulk collect into v_row_index, v_start_date, v_overload_qty, v_consumed_qty
4022 from msc_gantt_query mgq,
4023 msc_supplier_requirements msr
4024 where mgq.query_id = p_query_id
4025 and mgq.row_flag = SYS_YES
4026 and mgq.is_fetched = SYS_NO
4027 and mgq.dependency_type <> 1 -- bom_item_type, all the items except MODELs
4028 and msr.plan_id = mgq.plan_id
4029 --and msr.sr_instance_id = mgq.sr_instance_id
4030 --and msr.organization_id = mgq.organization_id
4031 and msr.inventory_item_id = mgq.inventory_item_id
4032 and msr.supplier_id = mgq.supplier_id
4033 and msr.supplier_site_id = mgq.supplier_site_id
4034 group by mgq.row_index, msr.consumption_date;
4035
4036 put_line('SUPP_ALL_ROW_TYPE rows for all the items except MODELs : '|| v_row_index.count);
4037 populateSuppDtlTabIntoGantt(p_query_id, SUPP_ALL_ROW_TYPE,
4038 v_row_index, v_start_date, v_overload_qty, v_consumed_qty, SUMMARY_DATA);
4039
4040 -- 3. req/consumed capacity for MODEL items only
4041 select mgq.row_index,
4042 msr.consumption_date,
4043 sum(msr.overloaded_capacity) overload_qty,
4044 sum(msr.consumed_quantity) consumed_qty
4045 bulk collect into v_row_index, v_start_date, v_overload_qty, v_consumed_qty
4046 from msc_gantt_query mgq,
4047 msc_supplier_requirements msr,
4048 msc_system_items msi
4049 where mgq.query_id = p_query_id
4050 and mgq.row_flag = SYS_YES
4051 and mgq.is_fetched = SYS_NO
4052 and mgq.dependency_type = 1 -- bom_item_type, MODELs
4053 and msi.plan_id = mgq.plan_id
4054 --and msi.sr_instance_id = mgq.sr_instance_id
4055 --and msi.organization_id = mgq.organization_id
4056 and ( msi.base_item_id = mgq.inventory_item_id or msi.inventory_item_id = mgq.inventory_item_id) --5220804 bugfix
4057 and msr.plan_id = mgq.plan_id
4058 and msr.sr_instance_id = msi.sr_instance_id
4059 and msr.organization_id = msi.organization_id
4060 and msr.inventory_item_id = msi.inventory_item_id
4061 and msr.supplier_id = mgq.supplier_id
4062 and msr.supplier_site_id = mgq.supplier_site_id
4063 group by mgq.row_index, msr.consumption_date;
4064
4065 put_line('SUPP_ALL_ROW_TYPE rows for MODEL items only : '|| v_row_index.count);
4066 populateSuppDtlTabIntoGantt(p_query_id, SUPP_ALL_ROW_TYPE,
4067 v_row_index, v_start_date, v_overload_qty, v_consumed_qty, SUMMARY_DATA);
4068
4069 end populateSupplierGantt;
4070
4071 procedure prepareSupplierGantt(p_query_id in number,
4072 p_plan_id number, p_start_date date, p_end_date date) is
4073
4074 v_bkt_start date_arr := date_arr(sysdate);
4075 v_bkt_end date_arr := date_arr(sysdate);
4076
4077 v_avail_start date_arr := date_arr(sysdate);
4078 v_avail_qty number_arr:= number_arr(0);
4079
4080 v_consume_start date_arr := date_arr(sysdate);
4081 v_overload_qty number_arr:= number_arr(0);
4082 v_consume_qty number_arr:= number_arr(0);
4083
4084 l_avail_qty number;
4085 l_overload_qty number;
4086 l_consume_qty number;
4087
4088 p_start_index number;
4089 l_bkt_query_id number := -1;
4090
4091 cursor c_supp_infinite_date(p_query number, p_row_index number, p_plan number,
4092 p_plan_end date) is
4093 select max(from_date) max_bkt_start_date,
4094 max(nvl(to_date,p_plan_end)) max_bkt_end_date
4095 from msc_gantt_query mgq,
4096 msc_supplier_capacities msc1
4097 where mgq.query_id = p_query
4098 and mgq.row_index = p_row_index
4099 and msc1.plan_id = p_plan
4100 and msc1.supplier_id = mgq.supplier_id
4101 and msc1.supplier_site_id = mgq.supplier_site_id
4102 --and msc1.organization_id = mgq.organization_id
4103 --and msc1.sr_instance_id = mgq.sr_instance_id
4104 and msc1.inventory_item_id = mgq.inventory_item_id;
4105
4106 l_supp_bkt_start_date date;
4107 l_supp_bkt_end_date date;
4108
4109 begin
4110 msc_gantt_utils.put_line('prepareSupplierGantt in ');
4111 p_start_index := mbp_null_value;
4112
4113 msc_gantt_utils.getBucketDates(p_start_date, p_end_date, v_bkt_start, v_bkt_end, l_bkt_query_id);
4114
4115 msc_gantt_utils.put_line('claendar rows ' || v_bkt_start.count);
4116
4117 for active_row in active_res_rows_cur(p_query_id) loop -- {
4118 if ( p_start_index = mbp_null_value) then
4119 p_start_index := active_row.row_index;
4120 end if;
4121
4122 --4476899 bugfix, send infinite capacity as -1 to client
4123 open c_supp_infinite_date(p_query_id, active_row.row_index, p_plan_id, p_end_date);
4124 fetch c_supp_infinite_date into l_supp_bkt_start_date, l_supp_bkt_end_date;
4125 close c_supp_infinite_date;
4126
4127 select trunc(start_date), nvl(resource_units,0)
4128 bulk collect into v_avail_start, v_avail_qty
4129 from msc_gantt_dtl_query
4130 where query_id = p_query_id
4131 and row_index = active_row.row_index
4132 and row_type = SUPP_AVAIL_ROW_TYPE
4133 and parent_id = SUMMARY_DATA;
4134
4135 put_line(' row index and SUPP_AVAIL_ROW_TYPE count '||active_row.row_index||' '||v_avail_start.count);
4136
4137 select trunc(start_date), nvl(resource_units,0), nvl(resource_hours,0)
4138 bulk collect into v_consume_start, v_overload_qty, v_consume_qty
4139 from msc_gantt_dtl_query
4140 where query_id = p_query_id
4141 and row_index = active_row.row_index
4142 and row_type = SUPP_ALL_ROW_TYPE
4143 and parent_id = SUMMARY_DATA
4144 order by start_date;
4145
4146 put_line(' row index and SUPP_ALL_ROW_TYPE count '||active_row.row_index||' '|| v_consume_start.count);
4147
4148 -- for daily, weekly, period buckets
4149 for a in 1 .. v_bkt_start.count
4150 loop -- {
4151 l_avail_qty := 0;
4152 l_overload_qty := 0;
4153 l_consume_qty := 0;
4154
4155 --4476899 bugfix, send infinite capacity as -1 to client
4156 if (l_supp_bkt_start_date is null and l_supp_bkt_end_date is null) then --capacity not defined, every thing is infinite
4157 l_avail_qty := -1;
4158 elsif (v_bkt_start(a) > l_supp_bkt_end_date) then --every thing is infinite from this date onwards
4159 l_avail_qty := -1;
4160 else
4161 for b in 1 .. v_avail_start.count loop -- {
4162 if ( v_avail_start(b) = v_bkt_start(a) ) then
4163 l_avail_qty := l_avail_qty + v_avail_qty(b);
4164 end if;
4165 end loop; -- }
4166 end if;
4167
4168
4169 for b in 1 .. v_consume_start.count loop -- {
4170 if ( v_consume_start(b) = v_bkt_start(a) ) then
4171 l_overload_qty := l_overload_qty + v_overload_qty(b);
4172 end if;
4173 end loop; -- }
4174
4175 for b in 1 .. v_consume_start.count loop -- {
4176 if ( v_consume_start(b) = v_bkt_start(a) ) then
4177 l_consume_qty := l_consume_qty + v_consume_qty(b);
4178 end if;
4179 end loop; -- }
4180
4181 --if ( nvl(l_avail_qty,0) <> 0 or nvl(l_overload_qty,0) <> 0 or nvl(l_consume_qty,0) <> 0 ) then
4182 populateSuppDtlIntoGantt(p_query_id, SUPP_ALL_ROW_TYPE,
4183 active_row.row_index, v_bkt_start(a), l_avail_qty, l_overload_qty,
4184 l_consume_qty, DETAIL_DATA);
4185 --end if;
4186 -- 4476899 bug fix, pass zero's also
4187
4188 end loop; -- }
4189 end loop; -- }
4190 msc_gantt_utils.put_line('prepareSupplierGantt out ');
4191
4192 end prepareSupplierGantt;
4193
4194 procedure sendSupplierGantt(p_query_id number,
4195 p_supp_data IN OUT NOCOPY msc_gantt_utils.maxCharTbl) is
4196
4197 v_start_date date_arr := date_arr(sysdate);
4198 v_avail_qty number_arr:= number_arr(0);
4199 v_overload_qty number_arr:= number_arr(0);
4200 v_consume_qty number_arr:= number_arr(0);
4201
4202 p_start_index number;
4203 begin
4204 p_start_index := mbp_null_value;
4205
4206 for active_row in active_res_rows_cur(p_query_id) loop -- {
4207 if ( p_start_index = mbp_null_value) then
4208 p_start_index := active_row.row_index;
4209 end if;
4210
4211 select trunc(start_date),
4212 round(supp_avail_qty, ROUND_FACTOR),
4213 round(supp_overload_qty, ROUND_FACTOR),
4214 round(supp_consume_qty, ROUND_FACTOR)
4215 bulk collect into v_start_date, v_avail_qty, v_overload_qty, v_consume_qty
4216 from msc_gantt_dtl_query
4217 where query_id = p_query_id
4218 and row_index = active_row.row_index
4219 and row_type = SUPP_ALL_ROW_TYPE
4220 and parent_id = DETAIL_DATA
4221 order by start_date;
4222
4223 put_line('sendSupplierGantt rows '||v_start_date.count||' '||v_avail_qty.count
4224 ||' '|| v_overload_qty.count ||' '|| v_consume_qty.count
4225 ||' '|| active_row.row_index);
4226
4227 sendResReqAvailSuppStream(SUPP_ALL_ROW_TYPE, active_row.row_index, p_start_index,
4228 v_start_date, null, null, null, null, p_supp_data,
4229 v_avail_qty, v_overload_qty, v_consume_qty);
4230 end loop; -- }
4231
4232 end sendSupplierGantt;
4233
4234 procedure sendResourceGantt(p_query_id number, p_view_type number,
4235 p_isBucketed number, p_require_data IN OUT NOCOPY msc_gantt_utils.maxCharTbl,
4236 p_avail_data IN OUT NOCOPY msc_gantt_utils.maxCharTbl,
4237 p_onlyAvailData boolean, p_display_type number) is
4238
4239 v_start date_arr:= date_arr(sysdate);
4240 v_end date_arr:= date_arr(sysdate);
4241 v_resource_hours number_arr:= number_arr(0);
4242 v_resource_units number_arr:= number_arr(0);
4243 v_schedule_flag number_arr:= number_arr(0);
4244 v_display_flag number_arr:= number_arr(0);
4245
4246 p_start_index number;
4247 begin
4248 put_line('sendResourceGantt in');
4249
4250 p_start_index := mbp_null_value;
4251
4252 for active_row in active_res_rows_cur(p_query_id) loop -- {
4253 if ( p_start_index = mbp_null_value) then
4254 p_start_index := active_row.row_index;
4255 end if;
4256
4257 if ( not(p_onlyAvailData) ) then -- {
4258
4259 if ( p_view_type = RES_HOURS_VIEW ) then
4260 -- and p_display_type <> DISPLAY_NONE ) then
4261 select start_date, end_date,
4262 round(resource_hours, ROUND_FACTOR) resource_hours,
4263 to_number(null) resource_units,
4264 schedule_flag,
4265 display_flag
4266 bulk collect into v_start, v_end, v_resource_hours, v_resource_units,
4267 v_schedule_flag, v_display_flag
4268 from msc_gantt_dtl_query
4269 where query_id = p_query_id
4270 and row_index = active_row.row_index
4271 and row_type = RES_REQ_ROW_TYPE
4272 and ( ( parent_id = SUMMARY_DATA and p_isBucketed = SYS_NO )
4273 or (parent_id = DETAIL_DATA and p_isBucketed = SYS_YES ) )
4274 --and display_flag = sys_yes
4275 order by start_date, end_date;
4276
4277 sendResReqAvailSuppStream(RES_REQ_DISPLAY_ROW_TYPE, active_row.row_index,
4278 p_start_index, v_start, v_end, v_resource_hours, v_resource_units,
4279 v_schedule_flag, p_require_data, v_display_flag);
4280 else
4281 select start_date, end_date,
4282 round(resource_hours, ROUND_FACTOR) resource_hours,
4283 round(resource_units, ROUND_FACTOR) resource_units,
4284 schedule_flag,
4285 display_flag
4286 bulk collect into v_start, v_end, v_resource_hours, v_resource_units,
4287 v_schedule_flag, v_display_flag
4288 from msc_gantt_dtl_query
4289 where query_id = p_query_id
4290 and row_index = active_row.row_index
4291 and row_type = RES_REQ_ROW_TYPE
4292 and ( ( parent_id = SUMMARY_DATA and p_isBucketed = SYS_NO )
4293 or (parent_id = DETAIL_DATA and p_isBucketed = SYS_YES ) )
4294 order by start_date, end_date;
4295
4296 sendResReqAvailSuppStream(RES_REQ_ROW_TYPE, active_row.row_index,
4297 p_start_index, v_start, v_end, v_resource_hours, v_resource_units,
4298 v_schedule_flag, p_require_data, v_display_flag);
4299 end if;
4300 end if; -- }
4301
4302 select start_date, end_date,
4303 round(resource_hours, ROUND_FACTOR) resource_hours,
4304 round(resource_units, ROUND_FACTOR) resource_units,
4305 schedule_flag
4306 bulk collect into v_start, v_end, v_resource_hours, v_resource_units, v_schedule_flag
4307 from msc_gantt_dtl_query
4308 where query_id = p_query_id
4309 and row_index = active_row.row_index
4310 and row_type = RES_AVAIL_ROW_TYPE
4311 and ( ( parent_id = SUMMARY_DATA and p_isBucketed = SYS_NO )
4312 or (parent_id = DETAIL_DATA and p_isBucketed = SYS_YES ) )
4313 order by start_date, end_date;
4314
4315 sendResReqAvailSuppStream(RES_AVAIL_ROW_TYPE, active_row.row_index, p_start_index,
4316 v_start, v_end, v_resource_hours, v_resource_units, v_schedule_flag, p_avail_data);
4317 end loop; -- }
4318 put_line('sendResourceGantt out');
4319
4320 end sendResourceGantt;
4321
4322 procedure calculateResHours(p_query_id number, p_row_index number, p_row_type number,
4323 p_bkt_start date, p_bkt_end date, p_line_rate number,
4324 p_start date_arr, p_end date_arr, p_hours number_arr,
4325 p_display_type number_arr) is
4326
4327 new_start_yes date;
4328 new_end_yes date;
4329 v_qty_yes number;
4330 bkt_qty_yes number;
4331
4332 new_start_no date;
4333 new_end_no date;
4334 v_qty_no number;
4335 bkt_qty_no number;
4336
4337 begin
4338 bkt_qty_yes := 0;
4339 v_qty_yes := 0;
4340 bkt_qty_no := 0;
4341 v_qty_no := 0;
4342
4343 for b in 1 .. p_start.count loop -- {
4344 if (p_start(b) > p_bkt_end or p_end(b) < p_bkt_start ) then
4345 v_qty_yes := 0;
4346 v_qty_no := 0;
4347 elsif (p_start(b) >= p_bkt_start and p_end(b) <= p_bkt_end ) then
4348 if ( p_display_type(b) = sys_yes ) then
4349 v_qty_yes := p_hours(b)* p_line_rate;
4350 bkt_qty_yes := bkt_qty_yes + v_qty_yes;
4351 else
4352 v_qty_no := p_hours(b)* p_line_rate;
4353 bkt_qty_no := bkt_qty_no + v_qty_no;
4354 end if;
4355 else
4356 if ( p_display_type(b) = sys_yes ) then
4357 new_start_yes := greatest(p_start(b), p_bkt_start);
4358 new_end_yes := least(p_end(b), p_bkt_end);
4359 v_qty_yes := p_hours(b)* p_line_rate;
4360 v_qty_yes := p_hours(b) / ((p_end(b)- p_start(b))*24);
4361 bkt_qty_yes := bkt_qty_yes + (((new_end_yes - new_start_yes) * v_qty_yes)*24);
4362 else
4363 new_start_no := greatest(p_start(b), p_bkt_start);
4364 new_end_no := least(p_end(b), p_bkt_end);
4365 v_qty_no := p_hours(b)* p_line_rate;
4366 v_qty_no := p_hours(b) / ((p_end(b)- p_start(b))*24);
4367 bkt_qty_no := bkt_qty_no + (((new_end_no - new_start_no) * v_qty_no)*24);
4368 end if;
4369 end if;
4370 end loop; -- }
4371
4372 if nvl(bkt_qty_yes,0) <> 0 then
4373 populateResDtlIntoGantt(p_query_id, RES_REQ_ROW_TYPE, p_row_index,
4374 p_bkt_start, p_bkt_end, null, bkt_qty_yes, p_row_type,
4375 DETAIL_DATA, sys_yes);
4376 end if;
4377
4378 if nvl(bkt_qty_no,0) <> 0 then
4379 populateResDtlIntoGantt(p_query_id, RES_REQ_ROW_TYPE, p_row_index,
4380 p_bkt_start, p_bkt_end, null, bkt_qty_no, p_row_type,
4381 DETAIL_DATA, sys_no);
4382 end if;
4383
4384 end calculateResHours;
4385
4386 procedure getBucketDates(p_start_date date, p_end_date date,
4387 v_bkt_start in out nocopy msc_gantt_utils.date_arr,
4388 v_bkt_end in out nocopy msc_gantt_utils.date_arr,
4389 p_query_id in out nocopy number) is
4390 p_temp_start date;
4391 i number;
4392 begin
4393 if (p_query_id = -1) then
4394 v_bkt_start := date_arr(sysdate);
4395 v_bkt_end := date_arr(sysdate);
4396 v_bkt_start.delete;
4397 v_bkt_end.delete;
4398
4399 p_temp_start := trunc(p_start_date);
4400 i := 1;
4401 loop
4402 if (p_temp_start>p_end_date) then
4403 exit;
4404 end if;
4405 v_bkt_start.extend;
4406 v_bkt_end.extend;
4407 v_bkt_start(i) := p_temp_start;
4408 v_bkt_end(i) := p_temp_start+1;
4409 i := i + 1;
4410 p_temp_start := p_temp_start+1;
4411 end loop;
4412 return;
4413 else
4414 p_temp_start := trunc(p_start_date);
4415 i := 1;
4416 loop
4417 if (p_temp_start>p_end_date) then
4418 exit;
4419 end if;
4420 i := i + 1;
4421
4422 insert into msc_form_query
4423 ( query_id, last_update_date, last_updated_by, creation_date, created_by, last_update_login,
4424 date1, date2)
4425 values
4426 ( p_query_id, sysdate, -1, sysdate, -1, -1, p_temp_start, p_temp_start+1);
4427
4428 p_temp_start := p_temp_start+1;
4429 end loop;
4430 return;
4431 end if;
4432
4433 end getBucketDates;
4434
4435 procedure prepareResHoursGantt(p_query_id in number, p_plan_id number,
4436 p_start_date date, p_end_date date, p_display_type number default null) is
4437
4438 v_setup_start date_arr;
4439 v_setup_end date_arr;
4440 v_setup_hours number_arr;
4441 v_setup_display_type number_arr;
4442
4443 v_req_start date_arr;
4444 v_req_end date_arr;
4445 v_req_hours number_arr;
4446 v_req_display_type number_arr;
4447
4448 v_avail_start date_arr;
4449 v_avail_end date_arr;
4450 v_avail_hours number_arr;
4451
4452 v_bkt_start date_arr;
4453 v_bkt_end date_arr;
4454
4455 cursor line_rate (l_query_id number, l_row_index number) is
4456 select mdr.max_rate
4457 from msc_department_resources mdr,
4458 msc_gantt_query mgq
4459 where mgq.query_id = l_query_id
4460 and mgq.row_index = l_row_index
4461 and mgq.organization_id = mdr.organization_id
4462 and mgq.sr_instance_id = mdr.sr_instance_id
4463 and mgq.department_id = mdr.department_id
4464 and mgq.resource_id = mdr.resource_id
4465 and mdr.plan_id = -1;
4466
4467 cursor finite_avail (l_query_id number, l_row_index number) is
4468 select 1
4469 from msc_net_resource_avail mnra,
4470 msc_gantt_query mgq
4471 where mgq.query_id = l_query_id
4472 and mgq.row_index = l_row_index
4473 and mgq.organization_id = mnra.organization_id
4474 and mgq.sr_instance_id = mnra.sr_instance_id
4475 and mgq.department_id = mnra.department_id
4476 and mgq.resource_id = mnra.resource_id
4477 and mgq.plan_id = mnra.plan_id
4478 and nvl(mnra.parent_id, 0) <> -1;
4479
4480 v_finite_avail number;
4481 v_line_rate number;
4482 max_cap number;
4483 eff_rate number;
4484
4485 v_qty_yes number;
4486 bkt_qty_yes number;
4487
4488 p_start_index number;
4489 l_bkt_query_id number := -1;
4490 begin
4491
4492 msc_gantt_utils.put_line('prepareResHoursGantt in ');
4493 p_start_index := mbp_null_value;
4494
4495 msc_gantt_utils.getBucketDates(p_start_date, p_end_date, v_bkt_start, v_bkt_end, l_bkt_query_id);
4496
4497 msc_gantt_utils.put_line('prepareResHoursGantt: claendar rows: ' || v_bkt_start.count);
4498
4499 for active_row in active_res_rows_cur(p_query_id) loop -- {
4500 if ( p_start_index = mbp_null_value) then
4501 p_start_index := active_row.row_index;
4502 end if;
4503
4504 select start_date, end_date, resource_hours, nvl(display_flag, sys_no)
4505 bulk collect into v_setup_start, v_setup_end, v_setup_hours, v_setup_display_type
4506 from msc_gantt_dtl_query
4507 where query_id = p_query_id
4508 and row_index = active_row.row_index
4509 and row_type = RES_REQ_ROW_TYPE
4510 and parent_id = SUMMARY_DATA
4511 and schedule_flag in (RES_SETUP_ROW_TYPE, RES_SETUP_FIXED_ROW_TYPE)
4512 order by start_date; --only setup time
4513
4514 msc_gantt_utils.put_line('prepareResHoursGantt: res seup rows: '||v_setup_start.count);
4515
4516
4517 select start_date, end_date, resource_hours, nvl(display_flag, sys_no)
4518 bulk collect into v_req_start, v_req_end, v_req_hours, v_req_display_type
4519 from msc_gantt_dtl_query
4520 where query_id = p_query_id
4521 and row_index = active_row.row_index
4522 and row_type = RES_REQ_ROW_TYPE
4523 and parent_id = SUMMARY_DATA
4524 and schedule_flag in (RES_REQ_ROW_TYPE, RES_REQ_SDS_ROW_TYPE)
4525 order by start_date; --only run time
4526
4527 msc_gantt_utils.put_line('prepareResHoursGantt: res req rows: '|| v_req_start.count);
4528
4529 select start_date, end_date, resource_hours
4530 bulk collect into v_avail_start, v_avail_end, v_avail_hours
4531 from msc_gantt_dtl_query
4532 where query_id = p_query_id
4533 and row_index = active_row.row_index
4534 and parent_id = SUMMARY_DATA
4535 and row_type = RES_AVAIL_ROW_TYPE
4536 order by start_date; --avail time
4537
4538 msc_gantt_utils.put_line('prepareResHoursGantt: res avail rows: '|| v_avail_start.count);
4539
4540 OPEN line_rate(p_query_id, active_row.row_index);
4541 FETCH line_rate INTO v_line_rate;
4542 CLOSE line_rate;
4543 v_line_rate := nvl(v_line_rate, 1);
4544
4545 v_finite_avail := null;
4546 OPEN finite_avail(p_query_id, active_row.row_index);
4547 FETCH finite_avail INTO v_finite_avail;
4548 CLOSE finite_avail;
4549
4550
4551 -- for daily, weekly, period buckets
4552 for a in 1 .. v_bkt_start.count loop -- {
4553 -- find all res avail in one bucket
4554 bkt_qty_yes := 0;
4555 v_qty_yes := 0;
4556 for b in 1 .. v_avail_start.count loop -- {
4557 v_qty_yes := 0;
4558 if ( trunc(v_bkt_start(a)) = trunc(v_avail_start(b)) ) then
4559 v_qty_yes := v_avail_hours(b);
4560 bkt_qty_yes := bkt_qty_yes + ( v_qty_yes / (v_bkt_end(a)- v_bkt_start(a)));
4561 end if;
4562 end loop; -- }
4563
4564 if (bkt_qty_yes <> 0) then
4565 populateResDtlIntoGantt(p_query_id, RES_AVAIL_ROW_TYPE, active_row.row_index,
4566 v_bkt_start(a), v_bkt_end(a), null, bkt_qty_yes, null, DETAIL_DATA);
4567 end if;
4568 -- find all res avail in one bucket
4569
4570 -- for run hours
4571 calculateResHours(p_query_id, active_row.row_index, SCHEDULE_FLAG_YES, v_bkt_start(a), v_bkt_end(a),
4572 v_line_rate, v_req_start, v_req_end, v_req_hours, v_req_display_type);
4573
4574 -- for setup hours
4575 calculateResHours(p_query_id, active_row.row_index, SCHEDULE_FLAG_NO, v_bkt_start(a), v_bkt_end(a),
4576 v_line_rate, v_setup_start, v_setup_end, v_setup_hours, v_setup_display_type);
4577
4578 end loop; -- }
4579 end loop; -- }
4580 msc_gantt_utils.put_line('prepareResHoursGantt out ');
4581
4582 end prepareResHoursGantt;
4583
4584
4585 procedure parseResString(p_one_record in varchar2,
4586 p_inst_id out nocopy number, p_org_id out nocopy number,
4587 p_dept_id out nocopy number, p_res_id out nocopy number,
4588 p_res_instance_id out nocopy number,
4589 p_serial_number out nocopy varchar2) is
4590
4591 begin
4592
4593 p_inst_id := to_number(substr(p_one_record,1,instr(p_one_record,',')-1));
4594 p_org_id := to_number(substr(p_one_record,instr(p_one_record,',',1,1)+1,
4595 instr(p_one_record,',',1,2)-instr(p_one_record,',',1,1)-1));
4596 p_dept_id := to_number(substr(p_one_record,instr(p_one_record,',',1,2)+1
4597 ,instr(p_one_record,',',1,3)-instr(p_one_record,',',1,2)-1));
4598 p_res_id := to_number(substr(p_one_record,instr(p_one_record,',',1,3)+1
4599 ,instr(p_one_record,',',1,4)-instr(p_one_record,',',1,3)-1));
4600 p_res_instance_id := to_number(substr(p_one_record,instr(p_one_record,',',1,4)+1
4601 ,instr(p_one_record,',',1,5)-instr(p_one_record,',',1,4)-1));
4602 p_serial_number := substr(p_one_record,instr(p_one_record,',',1,5)+1);
4603
4604 end parseResString;
4605
4606 procedure parseSuppString(p_one_record in varchar2,
4607 p_inst_id out nocopy number, p_org_id out nocopy number,
4608 p_item_id out nocopy number, p_supplier_id out nocopy number,
4609 p_supplier_site_id out nocopy number) is
4610
4611 begin
4612
4613 p_inst_id := to_number(substr(p_one_record,1,instr(p_one_record,',')-1));
4614 p_org_id := to_number(substr(p_one_record,instr(p_one_record,',',1,1)+1,
4615 instr(p_one_record,',',1,2)-instr(p_one_record,',',1,1)-1));
4616 p_item_id := to_number(substr(p_one_record,instr(p_one_record,',',1,2)+1
4617 ,instr(p_one_record,',',1,3)-instr(p_one_record,',',1,2)-1));
4618 p_supplier_id := to_number(substr(p_one_record,instr(p_one_record,',',1,3)+1
4619 ,instr(p_one_record,',',1,4)-instr(p_one_record,',',1,3)-1));
4620 p_supplier_site_id := to_number(substr(p_one_record,instr(p_one_record,',',1,4)+1));
4621
4622 end parseSuppString;
4623
4624 procedure populateListIntoGantt(p_query_id number,
4625 p_plan_id number, p_list varchar2,
4626 p_filter_type number, p_view_type number,
4627 p_folder_id number default null) is
4628
4629 i number:=1;
4630 v_len number;
4631 one_record varchar2(200);
4632 l_mfq_query_id number;
4633 l_row_index number := 0;
4634
4635 begin
4636
4637 l_mfq_query_id := getMFQSequence(l_mfq_query_id);
4638
4639 if ( p_filter_type = FILTER_TYPE_LIST ) then
4640
4641 v_len := length(p_list);
4642 while v_len > 1 loop
4643 if ( p_view_type = SUPPLIER_VIEW ) then
4644 one_record := substr(p_list,instr(p_list,'(',1,i)+1,
4645 instr(p_list,')',1,i)-instr(p_list,'(',1,i)-1);
4646 if ( ltrim(rtrim(one_record)) is not null) then
4647 populateSuppIntoGantt(p_query_id, i, one_record, p_plan_id);
4648 end if;
4649 elsif ( p_view_type = ORDER_VIEW ) then
4650 one_record := substr(p_list,instr(p_list,'(',1,i)+1,
4651 instr(p_list,')',1,i)-instr(p_list,'(',1,i)-1);
4652 if ( ltrim(rtrim(one_record)) is not null) then
4653 populateOrdersIntoMFQ(null, null, l_mfq_query_id, one_record);
4654 end if;
4655 elsif ( p_view_type in (RES_HOURS_VIEW, RES_UNITS_VIEW, RES_ACTIVITIES_VIEW) ) then
4656 one_record := substr(p_list,instr(p_list,'(',1,i)+1,
4657 instr(p_list,')',1,i)-instr(p_list,'(',1,i)-1);
4658 if ( ltrim(rtrim(one_record)) is not null) then
4659 populateResIntoGantt(p_query_id, l_row_index, one_record, p_plan_id);
4660 end if;
4661 end if;
4662 i := i+1;
4663 v_len := v_len - length(one_record)-3;
4664 end loop;
4665
4666 if ( p_view_type = ORDER_VIEW ) then
4667 populateOrdersIntoGantt(p_plan_id, p_query_id, l_mfq_query_id);
4668 end if;
4669
4670 elsif ( p_filter_type = FILTER_TYPE_MFQ ) then
4671 if ( p_view_type = SUPPLIER_VIEW ) then
4672 populateSuppIntoGanttFromMfq(p_query_id, p_list, p_plan_id);
4673 elsif ( p_view_type = ORDER_VIEW ) then
4674 populateOrdersIntoGantt(p_plan_id, p_query_id, p_list);
4675 elsif ( p_view_type in (RES_HOURS_VIEW, RES_UNITS_VIEW, RES_ACTIVITIES_VIEW) ) then
4676 populateResIntoGanttFromMfq(p_query_id, p_list, p_plan_id);
4677 end if;
4678 elsif ( p_filter_type = FILTER_TYPE_FOLDER_ID ) then
4679 null; --not supported currently..
4680 elsif ( p_filter_type = FILTER_TYPE_WHERE_STMT ) then
4681 msc_gantt_utils.findRequest(p_plan_id, p_list,
4682 p_query_id, p_view_type, FILTER_TYPE_WHERE_STMT, p_folder_id);
4683 elsif ( p_filter_type = FILTER_TYPE_AMONG ) then
4684 msc_gantt_utils.findRequest(p_plan_id, p_list,
4685 p_query_id, p_view_type, FILTER_TYPE_AMONG);
4686 elsif ( p_filter_type = FILTER_TYPE_QUERY_ID ) then
4687 populateResIntoGanttFromGantt(p_query_id, p_list, p_plan_id);
4688 end if; -- if ( p_filter_type = 1 ) then
4689
4690 end populateListIntoGantt;
4691
4692 procedure findRequest(p_plan_id number,
4693 p_where varchar2, p_query_id number,
4694 p_view_type varchar2 default null,
4695 p_filter_type number default null,
4696 p_folder_id number default null) is
4697
4698 TYPE GanttCurTyp IS REF CURSOR;
4699 theCursor GanttCurTyp;
4700 sql_statement varchar2(32000);
4701
4702 l_dept number;
4703 l_res number;
4704 l_res_instance_id number;
4705 l_serial_number varchar2(80);
4706 l_org number;
4707 l_instance number;
4708 l_item_id number;
4709 l_supp_id number;
4710 l_supp_site_id number;
4711 l_supply number;
4712 l_transaction number;
4713 exc_where_stat varchar2(32000);
4714 where_stat varchar2(32000);
4715
4716 l_one_record varchar2(100) := null;
4717 orders_where_stat varchar2(32000);
4718 supp_where_stat varchar2(32000);
4719 res_where_stat varchar2(32000);
4720
4721 i number;
4722
4723 l_mfq_query_id number;
4724 l_row_index number := 0;
4725
4726 cursor c_check_res_among (p_folder number, p_res_field varchar2) is
4727 select count(*)
4728 from msc_among_values
4729 where folder_id = p_folder
4730 and ltrim(rtrim(field_name)) = p_res_field;
4731 l_res_among_rows number;
4732 l_among_mfq_query_id number;
4733 begin
4734
4735 if ( p_where is null ) then
4736 return;
4737 end if;
4738
4739 if ( p_view_type = SUPPLIER_VIEW ) then
4740 if (p_filter_type = FILTER_TYPE_WHERE_STMT) then
4741 supp_where_stat := 'select distinct '
4742 ||' inventory_item_id, supplier_id, supplier_site_id '
4743 ||' from msc_item_supplier_v '
4744 ||' where plan_id = :1 '
4745 ||' and category_set_id = '|| g_category_set_id
4746 ||' and 1=1 '||p_where;
4747
4748 elsif (p_filter_type = FILTER_TYPE_AMONG) then
4749 null; --pabram need to check..
4750 end if;
4751 i := 1;
4752 open theCursor for supp_where_stat using p_plan_id;
4753 loop
4754 fetch theCursor into l_item_id, l_supp_id, l_supp_site_id;
4755 exit when theCursor%notfound;
4756
4757 populateSuppIntoGantt(p_query_id, i, l_one_record, p_plan_id,
4758 l_instance, l_org, l_item_id, l_supp_id, l_supp_site_id);
4759 i := i+1;
4760 end loop;
4761 close theCursor;
4762 elsif ( p_view_type in (DEMAND_VIEW, ORDER_VIEW) ) then
4763 l_mfq_query_id := getMFQSequence(l_mfq_query_id);
4764
4765 if (p_filter_type = FILTER_TYPE_WHERE_STMT) then
4766 orders_where_stat := 'select sr_instance_id, transaction_id '
4767 ||' from msc_orders_v '
4768 ||' where plan_id = :1 '
4769 ||' and category_set_id = '|| g_category_set_id
4770 ||' and source_table = ''MSC_SUPPLIES'' '
4771 ||' and 1=1 '||p_where;
4772
4773 elsif (p_filter_type = FILTER_TYPE_AMONG) then
4774 null; --pabram need to check..
4775 end if;
4776
4777 i := 1;
4778 open theCursor for orders_where_stat using p_plan_id;
4779 loop
4780 fetch theCursor into l_instance, l_transaction;
4781 exit when theCursor%notfound;
4782 populateOrdersIntoMFQ(l_instance, l_transaction, l_mfq_query_id, null);
4783 i := i+1;
4784 end loop;
4785 close theCursor;
4786 populateOrdersIntoGantt(p_plan_id, p_query_id, l_mfq_query_id);
4787
4788 elsif ( p_view_type in (RES_UNITS_VIEW, RES_HOURS_VIEW, RES_ACTIVITIES_VIEW) ) then
4789 if (p_filter_type = FILTER_TYPE_WHERE_STMT) then
4790
4791 open c_check_res_among(p_folder_id, g_folder_res_field_name);
4792 fetch c_check_res_among into l_res_among_rows;
4793 close c_check_res_among;
4794
4795 put_line('res among rows '||l_res_among_rows);
4796
4797 if ( l_res_among_rows = 0 ) then
4798 put_line(' regular res where ');
4799 res_where_stat := 'select sr_instance_id, organization_id, '
4800 ||' department_id, resource_id, res_instance_id, serial_number '
4801 ||' from msc_res_and_inst_v '
4802 ||' where plan_id = :1 '
4803 --||' and res_instance_id is null '
4804 ||' and 1=1 '||p_where;
4805 else
4806 put_line(' among res where ');
4807 l_among_mfq_query_id := getMFQSequence(l_among_mfq_query_id);
4808
4809 put_line(' l_among_mfq_query_id '||l_among_mfq_query_id);
4810 res_where_stat := 'insert into msc_form_query(query_id, number1, number2, '
4811 ||' number3, number4, number5, char1, '
4812 ||' last_update_date, last_updated_by, creation_date, created_by) '
4813 ||' select '||l_among_mfq_query_id
4814 ||' ,sr_instance_id, organization_id, '
4815 ||' department_id, resource_id, res_instance_id, serial_number, '
4816 ||' sysdate, -1, sysdate, -1 '
4817 ||' from msc_res_and_inst_v '
4818 ||' where plan_id = '||p_plan_id
4819 --||' and res_instance_id is null '
4820 ||' and 1=1 '||p_where;
4821
4822 msc_get_name.execute_dsql(res_where_stat);
4823
4824 res_where_stat := 'select number1, number2, number3, number4, number5, char1 '
4825 ||' from msc_form_query mfq, '
4826 ||' msc_among_values mav '
4827 ||' where mfq.query_id = :p_mfq_query '
4828 ||' and mav.folder_id = :p_folder '
4829 ||' and ltrim(rtrim(mav.field_name)) = :p_res_field '
4830 ||' and mfq.number4 = mav.hidden_values '
4831 ||' order by mav.order_by_sequence ';
4832
4833 end if;
4834
4835 elsif (p_filter_type = FILTER_TYPE_AMONG) then
4836 null; --pabram need to check..
4837 end if;
4838 --put_line('res stmt '||res_where_stat);
4839 i := 1;
4840 if ( l_res_among_rows = 0 ) then
4841 open theCursor for res_where_stat using p_plan_id;
4842 else
4843 open theCursor for res_where_stat using l_among_mfq_query_id, p_folder_id,g_folder_res_field_name;
4844 end if;
4845 loop
4846 fetch theCursor into l_instance, l_org, l_dept, l_res, l_res_instance_id, l_serial_number;
4847 exit when theCursor%notfound;
4848 populateResIntoGantt(p_query_id, l_row_index, l_one_record, p_plan_id,
4849 l_instance, l_org, l_dept, l_res, l_res_instance_id, l_serial_number, sys_yes);
4850 i := i+1;
4851 end loop;
4852 close theCursor;
4853 end if;
4854
4855 if ( p_view_type in (DEMAND_VIEW, ORDER_VIEW,
4856 RES_UNITS_VIEW, RES_HOURS_VIEW, RES_ACTIVITIES_VIEW, SUPPLIER_VIEW) ) then
4857 return;
4858 end if;
4859
4860 end findRequest;
4861
4862 procedure constructSupplyRequest(p_query_id number,
4863 p_from_block varchar2, p_plan_id number,
4864 p_plan_end_date date, p_where varchar2) is
4865
4866 TYPE GanttCurTyp IS REF CURSOR;
4867 the_cursor GanttCurTyp;
4868 l_instance number;
4869 l_supply number;
4870 l_exp_id number;
4871 sql_stat varchar2(32000);
4872 l_char varchar2(32000);
4873 BEGIN
4874
4875 if p_from_block = 'RESOURCE' then
4876 sql_stat := ' SELECT distinct mrr.sr_instance_id, ' ||
4877 ' mrr.supply_id ' ||
4878 ' FROM msc_resource_requirements mrr, ' ||
4879 ' msc_department_resources mdr ' ||
4880 ' WHERE mrr.plan_id = '||p_plan_id ||
4881 ' AND mdr.plan_id = mrr.plan_id '||
4882 ' AND mdr.organization_id = mrr.organization_id ' ||
4883 ' AND mdr.sr_instance_id = mrr.sr_instance_id'||
4884 ' AND mdr.department_id = mrr.department_id'||
4885 ' AND mdr.resource_id = mrr.resource_id '||
4886 ' AND mdr.aggregate_resource_flag =2 '||
4887 ' and mrr.end_date is not null '||
4888 ' and nvl(mrr.parent_id,2) =2 '||
4889 p_where;
4890 elsif p_from_block = 'EXCEPTION' then
4891 sql_stat := 'SELECT mrr.sr_instance_id, '||
4892 ' mrr.transaction_id '||
4893 ' FROM msc_supplies mrr, '||
4894 ' msc_exception_details med '||
4895 ' WHERE mrr.plan_id = '||p_plan_id ||
4896 ' and mrr.plan_id = med.plan_id '||
4897 ' and ( (mrr.transaction_id = med.number1 and '||
4898 ' med.exception_type in (6,7,8,9,10,32,34,53,54,58))'||
4899 ' or (mrr.transaction_id = med.number2 and '||
4900 ' med.exception_type = 37)) '|| p_where ||
4901 ' union select mrr.sr_instance_id, '||
4902 ' mrr.supply_id transaction_id '||
4903 ' FROM msc_resource_requirements mrr, '||
4904 ' msc_exception_details med '||
4905 ' where med.exception_type in (21,22,36,45,46) '||
4906 ' AND med.plan_id = mrr.plan_id ' ||
4907 ' AND med.organization_id = mrr.organization_id ' ||
4908 ' AND med.sr_instance_id = mrr.sr_instance_id ' ||
4909 ' AND med.department_id = mrr.department_id '||
4910 ' AND med.plan_id = '||p_plan_id ||
4911 ' AND med.resource_id = mrr.resource_id '||
4912 ' and mrr.end_date is not null '||
4913 p_where;
4914
4915 else
4916 sql_stat := 'SELECT mrr.sr_instance_id, '||
4917 ' mrr.transaction_id '||
4918 'FROM msc_supplies mrr '||
4919 ' WHERE mrr.plan_id = '||p_plan_id ||p_where;
4920 end if;
4921
4922 open the_cursor for sql_stat;
4923 loop
4924 fetch the_cursor into l_instance, l_supply;
4925 exit when the_cursor%notfound;
4926 populateOrdersIntoMFQ(l_instance, l_supply, p_query_id);
4927 end loop;
4928 close the_cursor;
4929
4930 end constructSupplyRequest;
4931
4932 procedure constructResourceRequest(p_query_id number,
4933 p_from_block varchar2, p_plan_id number,
4934 p_plan_end_date date, p_where varchar2) IS
4935
4936 TYPE GanttCurTyp IS REF CURSOR;
4937 the_cursor GanttCurTyp;
4938 l_dept number;
4939 l_res number;
4940 l_org number;
4941 l_instance number;
4942 sql_stat varchar2(32000);
4943 l_char varchar2(2000);
4944 v_one_record varchar2(100);
4945 i number := 1;
4946
4947 BEGIN
4948
4949 if p_from_block = 'EXCEPTION' then
4950 sql_stat := ' SELECT distinct mrr.sr_instance_id, ' ||
4951 ' mrr.organization_id, '||
4952 ' mrr.department_id, '||
4953 ' mrr.resource_id '||
4954 ' FROM msc_resource_requirements mrr, ' ||
4955 ' msc_department_resources mdr, ' ||
4956 ' msc_exception_details med ' ||
4957 ' WHERE mrr.plan_id = :1 '||
4958 ' AND mdr.plan_id = mrr.plan_id '||
4959 ' AND mdr.organization_id = mrr.organization_id ' ||
4960 ' AND mdr.sr_instance_id = mrr.sr_instance_id'||
4961 ' AND mdr.department_id = mrr.department_id'||
4962 ' AND mdr.resource_id = mrr.resource_id '||
4963 ' AND mdr.aggregate_resource_flag =2 '||
4964 ' AND med.plan_id = mrr.plan_id ' ||
4965 ' AND med.organization_id = mrr.organization_id ' ||
4966 ' AND med.sr_instance_id = mrr.sr_instance_id ' ||
4967 ' AND decode(med.department_id, -1, mrr.department_id,'||
4968 ' med.department_id) = mrr.department_id ' ||
4969 ' AND decode(med.resource_id, -1, mrr.resource_id, '||
4970 ' med.resource_id) = mrr.resource_id '||
4971 ' AND decode(med.inventory_item_id, -1, '||
4972 ' mrr.assembly_item_id, '||
4973 ' med.inventory_item_id) = mrr.assembly_item_id '||
4974 ' and ( (mrr.supply_id = med.number1 and '||
4975 ' med.exception_type in (6,7,8,9,10,32,34,53,54,58))'||
4976 ' or (mrr.supply_id = med.number2 and '||
4977 ' med.exception_type = 37) '||
4978 ' or (med.exception_type in (21,22,36,45,46)))'||
4979 ' and nvl(mrr.parent_id,2) =2 ' ||
4980 ' and mrr.end_date is not null '||
4981 ' and nvl(mrr.firm_end_date,mrr.end_date) <= :2 '||
4982 p_where;
4983 else
4984 sql_stat := ' SELECT distinct mrr.sr_instance_id, ' ||
4985 ' mrr.organization_id, '||
4986 ' mrr.department_id, '||
4987 ' mrr.resource_id '||
4988 ' FROM msc_resource_requirements mrr, ' ||
4989 ' msc_department_resources mdr ' ||
4990 ' WHERE mrr.plan_id = :1 '||
4991 ' AND mdr.plan_id = mrr.plan_id '||
4992 ' AND mdr.organization_id = mrr.organization_id ' ||
4993 ' AND mdr.sr_instance_id = mrr.sr_instance_id'||
4994 ' AND mdr.department_id = mrr.department_id'||
4995 ' AND mdr.resource_id = mrr.resource_id '||
4996 ' AND mdr.aggregate_resource_flag =2 '||
4997 ' and mrr.end_date is not null '||
4998 ' and nvl(mrr.parent_id,2) =2 ' ||
4999 ' and nvl(mrr.firm_end_date,mrr.end_date) <= :2 '||
5000 p_where;
5001 end if;
5002
5003 open the_cursor for sql_stat using p_plan_id, p_plan_end_date;
5004 loop
5005 fetch the_cursor into l_instance, l_org, l_dept, l_res;
5006 exit when the_cursor%notfound;
5007
5008 v_one_record := '('||l_instance ||','||l_org ||','||l_dept||','||l_res||','||MBP_NULL_VALUE||')';
5009 populateresintogantt(p_query_id, i, v_one_record, p_plan_id);
5010 i := i+1;
5011
5012 end loop;
5013 close the_cursor;
5014
5015 end constructResourceRequest;
5016
5017 procedure constructRequest(p_query_id number, p_type varchar2, p_plan_id number,
5018 p_plan_end_date date, p_where varchar2, p_from_block varchar2) is
5019
5020 begin
5021
5022 if p_from_block in ('LATE_DEMAND','ORDER') then
5023 null;
5024 else -- not from late demand and order view
5025 if p_type = 'RESOURCE' then
5026 constructResourceRequest(p_query_id, p_from_block,p_plan_id, p_plan_end_date, p_where);
5027 else
5028 constructSupplyRequest(p_query_id, p_from_block,p_plan_id, p_plan_end_date, p_where);
5029 end if;
5030 end if;
5031
5032 end constructRequest;
5033
5034 function getMFQSequence (p_query_id in number default null) Return number is
5035 l_query_id number;
5036 begin
5037
5038 if (p_query_id is not null) then
5039 delete from msc_form_query where query_id = p_query_id;
5040 return p_query_id;
5041 end if;
5042
5043 select msc_form_query_s.nextval
5044 into l_query_id
5045 from dual;
5046 return l_query_id;
5047
5048 end getMFQSequence;
5049
5050 function getGanttSequence (p_query_id in number default null) return number is
5051 l_query_id number;
5052 begin
5053 if (p_query_id is not null) then
5054 delete from msc_gantt_query where query_id = p_query_id;
5055 return p_query_id;
5056 end if;
5057 select msc_gantt_query_s.nextval
5058 into l_query_id
5059 from dual;
5060 return l_query_id;
5061
5062 end getGanttSequence;
5063
5064 procedure loadAltResourceBatch(p_plan_id number, p_transaction_id number,
5065 p_instance_id number, p_alt_resource number, p_alt_resource_inst number,
5066 p_serial_number varchar2, p_alt_num number,
5067 p_node_type number, p_to_node_type number, p_return_trx_id out nocopy number,
5068 p_return_status OUT NOCOPY varchar2,
5069 p_out OUT NOCOPY varchar2
5070 ) is
5071
5072 cursor c_res_batch_rows (p_plan number, p_inst number, p_trx number) is
5073 select mrrb.sr_instance_id, mrrb.transaction_id
5074 from msc_resource_requirements mrr,
5075 msc_resource_requirements mrrb
5076 where mrr.plan_id = p_plan
5077 and mrr.sr_instance_id = p_inst
5078 and mrr.transaction_id = p_trx
5079 and mrr.plan_id = mrrb.plan_id
5080 and mrr.sr_instance_id = mrrb.plan_id
5081 and mrr.batch_number = mrrb.batch_number;
5082
5083 l_inst_id number;
5084 l_trx_id number;
5085
5086 begin
5087
5088 open c_res_batch_rows(p_plan_id, p_instance_id, p_transaction_id);
5089 loop
5090 fetch c_res_batch_rows into l_inst_id, l_trx_id;
5091 exit when c_res_batch_rows%notfound;
5092
5093 msc_gantt_utils.loadAltResource(p_plan_id,
5094 l_inst_id, l_trx_id, p_alt_resource, p_alt_resource_inst, p_serial_number, p_alt_num,
5095 p_node_type, p_to_node_type, p_return_trx_id, p_return_status, p_out);
5096 end loop;
5097 close c_res_batch_rows;
5098
5099 end loadAltResourceBatch;
5100
5101 procedure loadAltResource(p_plan_id number, p_transaction_id number,
5102 p_instance_id number, p_alt_resource number, p_alt_resource_inst number,
5103 p_serial_number varchar2, p_alt_num number,
5104 p_node_type number, p_to_node_type number, p_return_trx_id out nocopy number,
5105 p_return_status OUT NOCOPY varchar2,
5106 p_out OUT NOCOPY varchar2
5107 ) is
5108
5109 l_firm_flag number;
5110 l_basis_type number;
5111 l_rout_seq number;
5112 l_op_seq number;
5113 l_op_seq_num number;
5114 l_res_seq number;
5115 l_supply_id number;
5116 l_act_group number;
5117 l_avail_res_seq number;
5118 l_resource_id number;
5119 l_assigned_units number;
5120
5121 cursor c_inst_req_for_same_req (p_plan number, p_res number, p_res_inst number, p_serial varchar2,
5122 p_supply number, p_op_seq_num number) is
5123 select count(*)
5124 from msc_resource_instance_reqs
5125 where plan_id = p_plan
5126 and resource_id = p_res
5127 and res_instance_id = p_res_inst
5128 and nvl(serial_number, mbp_null_value_char) = nvl(p_serial, mbp_null_value_char)
5129 and supply_id = p_supply
5130 and operation_seq_num = p_op_seq_num;
5131 l_temp_inst_rows number;
5132
5133 cursor c_res_trx_info(p_plan number, p_inst number, p_trx number) is
5134 select mrr.resource_id, mrr.routing_sequence_id,
5135 mrr.operation_sequence_id,
5136 mrr.operation_seq_num,
5137 mrr.resource_seq_num,
5138 mrr.supply_id,
5139 mrr.basis_type,
5140 mors.activity_group_id,
5141 ms.new_order_quantity qty,
5142 mrr.assigned_units,
5143 mrr.firm_flag
5144 from msc_resource_requirements mrr,
5145 msc_operation_resource_seqs mors,
5146 msc_supplies ms
5147 where mrr.plan_id = p_plan
5148 and mrr.transaction_id = p_trx
5149 and mrr.sr_instance_id = p_inst
5150 and mors.plan_id = mrr.plan_id
5151 and mors.sr_instance_id = mrr.sr_instance_id
5152 and mors.routing_sequence_id = mrr.routing_sequence_id
5153 and mors.operation_sequence_id = mrr.operation_sequence_id
5154 and mors.resource_seq_num = mrr.resource_seq_num
5155 and ms.plan_id = mrr.plan_id
5156 and ms.sr_instance_id = mrr.sr_instance_id
5157 and ms.transaction_id = mrr.supply_id
5158 union all --5478582 bugfix
5159 select mrr.resource_id, mrr.routing_sequence_id,
5160 mrr.operation_sequence_id,
5161 mrr.operation_seq_num,
5162 mrr.resource_seq_num,
5163 mrr.supply_id,
5164 mrr.basis_type,
5165 mjor.activity_group_id,
5166 ms.new_order_quantity qty,
5167 mrr.assigned_units,
5168 mrr.firm_flag
5169 from msc_resource_requirements mrr,
5170 msc_job_op_resources mjor,
5171 msc_supplies ms
5172 where mrr.plan_id = p_plan
5173 and mrr.transaction_id = p_trx
5174 and mrr.sr_instance_id = p_inst
5175 and mrr.routing_sequence_id is null
5176 and mjor.plan_id = mrr.plan_id
5177 and mjor.sr_instance_id = mrr.sr_instance_id
5178 and mjor.transaction_id = mrr.supply_id
5179 and mjor.resource_id = mrr.resource_id
5180 and mjor.operation_seq_num = mrr.operation_seq_num
5181 and mjor.resource_seq_num = mrr.resource_seq_num
5182 and ms.plan_id = mrr.plan_id
5183 and ms.sr_instance_id = mrr.sr_instance_id
5184 and ms.transaction_id = mrr.supply_id;
5185
5186 cursor c_avail_res_seq_count(p_plan number, p_inst number, p_op_seq number,
5187 p_rout_seq number, p_act_group number, p_alternate_num number) is
5188 select count(*)
5189 from (select distinct mors.resource_seq_num
5190 from msc_operation_resource_seqs mors,
5191 msc_operation_resources mor
5192 where mors.plan_id = p_plan
5193 and mors.sr_instance_id = p_inst
5194 and mors.operation_sequence_id = p_op_seq
5195 and mors.routing_sequence_id = p_rout_seq
5196 and mors.activity_group_id = p_act_group
5197 and mor.plan_id = mors.plan_id
5198 and mor.sr_instance_id = mors.sr_instance_id
5199 and mor.routing_sequence_id = mors.routing_sequence_id
5200 and mor.operation_sequence_id = mors.operation_sequence_id
5201 and mor.resource_seq_num = mors.resource_seq_num
5202 and mor.alternate_number = p_alternate_num);
5203
5204 cursor all_res_seq(p_plan number, p_inst number, p_op_seq number,
5205 p_rout_seq number, p_act_group number) is
5206 select
5207 distinct mors.resource_seq_num
5208 from msc_operation_resource_seqs mors
5209 where mors.plan_id = p_plan
5210 and mors.sr_instance_id = p_inst
5211 and mors.routing_sequence_id = p_rout_seq
5212 and mors.operation_sequence_id = p_op_seq
5213 and mors.activity_group_id = p_act_group;
5214
5215 cursor same_res_group(p_plan number, p_inst number, p_op_seq number,
5216 p_rout_seq number, p_act_group number, p_res_seq number,
5217 p_alternate_num number, p_supply_id number, p_op_seq_num number) is
5218 select distinct mrr.transaction_id,
5219 mor.principal_flag,
5220 mrr.resource_id
5221 from msc_resource_requirements mrr,
5222 msc_operation_resources mor
5223 where mrr.plan_id = p_plan
5224 and mrr.sr_instance_id = p_inst
5225 and mrr.routing_sequence_id = p_rout_seq
5226 and mrr.operation_sequence_id = p_op_seq
5227 and mrr.resource_seq_num = p_res_seq
5228 and mor.plan_id = mrr.plan_id
5229 and mor.sr_instance_id = mrr.sr_instance_id
5230 and mor.routing_sequence_id = mrr.routing_sequence_id
5231 and mor.operation_sequence_id = mrr.operation_sequence_id
5232 and mor.resource_seq_num = mrr.resource_seq_num
5233 and mor.resource_id = mrr.resource_id
5234 and mor.alternate_number <> p_alternate_num
5235 and mrr.parent_id = 2
5236 and mrr.supply_id = p_supply_id
5237 union all --5478582 bugfix
5238 select distinct mrr.transaction_id,
5239 mjor.principal_flag,
5240 mrr.resource_id
5241 from msc_resource_requirements mrr,
5242 msc_job_op_resources mjor
5243 where mrr.plan_id = p_plan
5244 and mrr.sr_instance_id = p_inst
5245 and mrr.routing_sequence_id is null
5246 and mrr.operation_seq_num = p_op_seq_num
5247 and mrr.resource_seq_num = p_res_seq
5248 and mjor.plan_id = mrr.plan_id
5249 and mjor.sr_instance_id = mrr.sr_instance_id
5250 and mjor.transaction_id = mrr.supply_id
5251 and mjor.operation_seq_num = mrr.operation_seq_num
5252 and mjor.resource_seq_num = mrr.resource_seq_num
5253 and mjor.resource_id = mrr.resource_id
5254 and mjor.alternate_num <> p_alternate_num
5255 and mrr.parent_id = 2
5256 and mrr.supply_id = p_supply_id
5257 order by 2;
5258
5259 cursor alt_res_group(p_plan number, p_inst number, p_op_seq number,
5260 p_rout_seq number, p_res_seq number, p_alternate_num number,
5261 p_supply_id number, p_op_seq_num number) is
5262 select mor.resource_usage,
5263 mor.resource_units,
5264 mor.resource_id,
5265 mor.alternate_number,
5266 mor.principal_flag,
5267 mor.basis_type,
5268 mor.orig_resource_seq_num
5269 from msc_operation_resources mor
5270 where mor.plan_id = p_plan
5271 and mor.sr_instance_id = p_inst
5272 and mor.routing_sequence_id = p_rout_seq
5273 and mor.operation_sequence_id = p_op_seq
5274 and mor.resource_seq_num = p_res_seq
5275 and mor.alternate_number = p_alternate_num
5276 union all --5478582 bugfix
5277 select mjor.usage_rate_or_amount resource_usage,
5278 mjor.assigned_units resource_units,
5279 mjor.resource_id,
5280 mjor.alternate_num,
5281 mjor.principal_flag,
5282 mjor.basis_type,
5283 mjor.orig_resource_seq_num
5284 from msc_job_op_resources mjor
5285 where mjor.plan_id = p_plan
5286 and mjor.sr_instance_id = p_inst
5287 and mjor.transaction_id = p_supply_id
5288 and mjor.operation_seq_num = p_op_seq_num
5289 and mjor.resource_seq_num = p_res_seq
5290 and mjor.alternate_num = p_alternate_num
5291 and p_rout_seq is null
5292 order by 5;
5293
5294 -- 4561112 bugfix
5295 cursor assembly_qty (p_plan number, p_supply number) is
5296 select nvl(assembly_quantity,1) assembly_quantity
5297 from msc_boms mb,
5298 msc_supplies ms,
5299 msc_process_effectivity mpe,
5300 msc_resource_requirements mrr
5301 where ms.plan_id = p_plan
5302 and ms.transaction_id = p_supply
5303 and ms.plan_id = mrr.plan_id
5304 and ms.sr_instance_id = mrr.sr_instance_id
5305 and ms.transaction_id = mrr.supply_id
5306 and nvl(mrr.parent_id,2) =2
5307 and ms.plan_id = mpe.plan_id
5308 and ms.sr_instance_id = mpe.sr_instance_id
5309 and ms.process_seq_id = mpe.process_sequence_id
5310 and mpe.plan_id = mb.plan_id
5311 and mpe.sr_instance_id = mb.sr_instance_id
5312 and mpe.bill_sequence_id = mb.bill_sequence_id
5313 and mrr.assembly_item_id = mb.assembly_item_id;
5314 v_assembly_quantity number;
5315 -- 4561112 bugfix
5316
5317 TYPE ResRecTyp IS RECORD (
5318 resource_usage number,
5319 resource_units number,
5320 resource_id number,
5321 alternate_number number,
5322 principal_flag number,
5323 basis_type number,
5324 orig_resource_seq_num number);
5325
5326 TYPE SimRecTyp IS RECORD (
5327 transaction_id number,
5328 principal_flag number,
5329 resource_id number);
5330
5331 TYPE numTabTyp IS TABLE OF NUMBER INDEX BY BINARY_INTEGER;
5332 TYPE FromTabTyp IS TABLE OF SimRecTyp INDEX BY BINARY_INTEGER;
5333 TYPE ToTabTyp IS TABLE OF ResRecTyp INDEX BY BINARY_INTEGER;
5334
5335 l_simu_res FromTabTyp;
5336 l_alt_res ToTabTyp;
5337 l_all_seq numTabTyp;
5338 i BINARY_INTEGER := 0;
5339 j BINARY_INTEGER := 0;
5340
5341 v_usage number;
5342 v_qty number;
5343 v_hours number;
5344
5345 ll_res_inst_trx_id number;
5346 ll_res_trx_id number;
5347 ll_temp_res_inst_trx_id number;
5348
5349 l_dummy_id number;
5350 l_temp_trx_id number;
5351
5352 l_dummy_name_data varchar2(10000);
5353 l_dummy_id_data varchar2(10000);
5354 l_alt_count number;
5355
5356 l_within_res number;
5357
5358 begin
5359 put_line('loadAltResource in');
5360 put_line('plan inst trx '||p_plan_id||' '||p_transaction_id||' '||p_instance_id);
5361
5362 if ( p_node_type = RES_INST_NODE ) then -- {
5363 ll_res_inst_trx_id := p_transaction_id;
5364 ll_res_trx_id := get_parent_res_trx_id(p_plan_id, p_instance_id, ll_res_inst_trx_id);
5365 put_line(' res-inst node res-trx res-inst-trx '||ll_res_trx_id||' '||ll_res_inst_trx_id);
5366 else
5367 ll_res_trx_id := p_transaction_id;
5368 ll_res_inst_trx_id := get_child_res_trx_id(p_plan_id, p_instance_id, ll_res_trx_id);
5369 put_line(' res node res-trx res-inst-trx '||ll_res_trx_id||' '||ll_res_inst_trx_id);
5370 end if; -- }
5371
5372 if ( p_to_node_type = RES_NODE ) then
5373 p_return_trx_id := ll_res_trx_id;
5374 else
5375 p_return_trx_id := ll_res_inst_trx_id;
5376 end if;
5377
5378 put_line(' res-trx inst-trx '||ll_res_trx_id||' '||ll_res_inst_trx_id);
5379
5380 --get corresponding info about this tranx
5381 open c_res_trx_info(p_plan_id, p_instance_id, ll_res_trx_id);
5382 fetch c_res_trx_info into l_resource_id, l_rout_seq, l_op_seq, l_op_seq_num, l_res_seq,
5383 l_supply_id,l_basis_type, l_act_group, v_qty, l_assigned_units, l_firm_flag;
5384 close c_res_trx_info;
5385
5386 --4931312 bufix
5387 if ( nvl(l_firm_flag,0) <> 0 ) then
5388 p_return_status := 'ERROR';
5389 p_out := 'REQ_IS_FIRMED';
5390 put_line('req_is_firmed 1');
5391 return;
5392 end if;
5393 --4931312 bufix ends
5394
5395 -- 4561112 bugfix
5396 open assembly_qty(p_plan_id, l_supply_id);
5397 fetch assembly_qty into v_assembly_quantity;
5398 close assembly_qty;
5399 if (v_assembly_quantity is null or v_assembly_quantity = 0) then
5400 v_assembly_quantity := 1;
5401 end if;
5402 -- 4561112 bugfix
5403
5404 -- 4569506 bugfix
5405 --trying to move within a resource
5406 l_within_res := sys_no;
5407 if ( p_node_type = RES_INST_NODE and p_to_node_type = RES_INST_NODE) then --{
5408 if (l_resource_id = p_alt_resource) then
5409 l_within_res := sys_yes;
5410 end if;
5411 end if; --}
5412 -- 4569506 bugfix ends
5413
5414 msc_gantt_utils.getAltResource(p_plan_id, p_transaction_id, p_instance_id,
5415 l_dummy_name_data, l_dummy_id_data, p_node_type, sys_yes);
5416
5417 select count(*)
5418 into l_alt_count
5419 from msc_form_query
5420 where query_id = to_number(l_dummy_id_data)
5421 and number1 = p_alt_resource
5422 and nvl(number2, mbp_null_value) = nvl(p_alt_resource_inst, mbp_null_value)
5423 and nvl(char1, mbp_null_value_char) = nvl(p_serial_number, mbp_null_value_char)
5424 and number3 = p_alt_num;
5425
5426 if (l_alt_count = 0 and l_within_res = sys_no) then
5427 p_return_status := 'ERROR';
5428 p_out := 'NOT_A_VALID_ALTERNATE';
5429 return;
5430 end if;
5431
5432 --let's do some validation of from and to
5433 if ( p_node_type = RES_NODE and p_to_node_type = RES_NODE ) then -- {
5434 null; -- this is okay;
5435 elsif ( p_node_type = RES_NODE and p_to_node_type = RES_INST_NODE ) then
5436 if ( l_assigned_units <> 1 ) then
5437 p_return_status := 'ERROR';
5438 p_out := 'CANNOT_OFFLOAD_1_ASGN_UNITS';
5439 return;
5440 end if;
5441 elsif ( p_node_type = RES_INST_NODE and p_to_node_type = RES_NODE ) then
5442 if ( l_resource_id = p_alt_resource) then
5443 p_return_status := 'ERROR';
5444 p_out := 'CANNOT_OFFLOAD_TO_PARENT_RESOURCE';
5445 return;
5446 elsif ( l_assigned_units <> 1 ) then
5447 p_return_status := 'ERROR';
5448 p_out := 'CANNOT_OFFLOAD_1_ASGN_UNITS';
5449 return;
5450 end if;
5451 elsif ( p_node_type = RES_INST_NODE and p_to_node_type = RES_INST_NODE ) then
5452 if ( l_resource_id = p_alt_resource) then
5453 open c_inst_req_for_same_req(p_plan_id, p_alt_resource, p_alt_resource_inst,
5454 p_serial_number, l_supply_id, l_op_seq_num);
5455 fetch c_inst_req_for_same_req into l_temp_inst_rows;
5456 close c_inst_req_for_same_req;
5457
5458 if (l_temp_inst_rows <> 0) then
5459 p_return_status := 'ERROR';
5460 p_out := 'CANNOT_OFFLOAD_TO_SAME_REQ';
5461 return;
5462 end if;
5463 elsif ( l_assigned_units <> 1 ) then
5464 p_return_status := 'ERROR';
5465 p_out := 'CANNOT_OFFLOAD_1_ASGN_UNITS';
5466 return;
5467 end if;
5468
5469 msc_gantt_utils.updateReqInstFromAlt(p_plan_id, p_instance_id,
5470 ll_res_inst_trx_id, p_alt_resource, p_alt_resource_inst, p_serial_number,
5471 null, p_alt_resource, null);
5472
5473 -- update requirement's supply
5474 msc_gantt_utils.updateSupplies(p_plan_id, l_supply_id, TOUCH_SUPPLY);
5475
5476 p_return_status := 'OK';
5477 p_out := '';
5478 return;
5479
5480 end if; -- }
5481 --validation ends
5482
5483 if l_act_group is null then -- {
5484 l_all_seq(1) := l_res_seq;
5485 else
5486 open all_res_seq(p_plan_id, p_instance_id, l_op_seq, l_rout_seq, l_act_group);
5487 fetch all_res_seq bulk collect into l_all_seq;
5488 close all_res_seq;
5489
5490 open c_avail_res_seq_count(p_plan_id, p_instance_id, l_op_seq, l_rout_seq, l_act_group, p_alt_num);
5491 fetch c_avail_res_seq_count into l_avail_res_seq;
5492 close c_avail_res_seq_count;
5493
5494 if l_avail_res_seq is null or l_avail_res_seq < l_all_seq.LAST then -- {
5495 p_return_status := 'ERROR';
5496 p_out := 'NO_ALT';
5497 return;
5498 end if; -- }
5499 end if; -- }
5500
5501 for j in 1..l_all_seq.last
5502 loop -- {
5503 l_res_seq := l_all_seq(j);
5504
5505 -- fetch the resources in the same resource group
5506 open same_res_group(p_plan_id, p_instance_id, l_op_seq, l_rout_seq,
5507 l_act_group, l_res_seq, p_alt_num, l_supply_id, l_op_seq_num);
5508 fetch same_res_group bulk collect into l_simu_res;
5509 close same_res_group;
5510
5511 -- fetch the resources in the alternate resource group
5512 open alt_res_group(p_plan_id, p_instance_id, l_op_seq,
5513 l_rout_seq, l_res_seq, p_alt_num, l_supply_id, l_op_seq_num);
5514 fetch alt_res_group bulk collect into l_alt_res;
5515 close alt_res_group;
5516
5517 put_line(' for loop : index all_seq same_res_group alt_res_group '||j
5518 || null_space || l_all_seq.count || null_space ||l_simu_res.count
5519 || null_space ||l_alt_res.count);
5520
5521 i:=1;
5522 while (l_simu_res.LAST >= i or l_alt_res.LAST >= i)
5523 loop -- {
5524
5525 put_line(' while loop : index '||i);
5526
5527 if ( l_simu_res.LAST >= i ) then
5528 put_line(' same_res_id '||l_simu_res(i).resource_id);
5529 end if;
5530
5531 if ( l_alt_res.LAST >= i ) then
5532 put_line(' alt_res_id '||l_alt_res(i).resource_id);
5533 end if;
5534
5535 -- add the res from alt res group
5536 if i > l_simu_res.last then -- {
5537
5538 put_line(' in i > l_simu_res.last - inserting alt res into mrr ');
5539
5540 if ( l_alt_res(i).basis_type = 1 ) then
5541 v_hours := v_qty * l_alt_res(i).resource_usage;
5542 v_hours := v_hours/v_assembly_quantity; --4561112 bugfix
5543 else
5544 v_hours := l_alt_res(i).resource_usage;
5545 end if;
5546
5547 ll_temp_res_inst_trx_id := get_child_res_trx_id(p_plan_id, p_instance_id, l_simu_res(1).transaction_id);
5548
5549 l_dummy_id := msc_gantt_utils.insertReqFromAlt(p_plan_id, p_instance_id,
5550 l_simu_res(1).transaction_id , l_alt_res(i).resource_id, v_hours,
5551 l_alt_res(i).alternate_number, l_alt_res(i).basis_type,
5552 l_alt_res(i).orig_resource_seq_num);
5553
5554 DeleteReqInstFromAlt(p_plan_id, p_instance_id, ll_temp_res_inst_trx_id);
5555 elsif i > l_alt_res.last then -- delete the extra res
5556
5557 put_line(' in i > l_alt_res.last - deleting alt res into mrr ');
5558 ll_temp_res_inst_trx_id := get_child_res_trx_id(p_plan_id, p_instance_id, l_simu_res(i).transaction_id);
5559 msc_gantt_utils.DeleteReqFromAlt(p_plan_id, p_instance_id, l_simu_res(i).transaction_id);
5560 DeleteReqInstFromAlt(p_plan_id, p_instance_id, ll_temp_res_inst_trx_id);
5561
5562 else -- update the res to alt_res
5563
5564 put_line(' in else simu trx id '||l_simu_res(i).transaction_id||' updating alt res into mrr ');
5565 if ( l_alt_res(i).basis_type = 1 ) then
5566 v_hours := v_qty * l_alt_res(i).resource_usage;
5567 v_hours := v_hours/v_assembly_quantity; --4561112 bugfix
5568 else
5569 v_hours := l_alt_res(i).resource_usage;
5570 end if;
5571
5572 ll_temp_res_inst_trx_id := get_child_res_trx_id(p_plan_id, p_instance_id, l_simu_res(i).transaction_id);
5573 put_line(' in else simu ll_temp_res_inst_trx_id '||ll_temp_res_inst_trx_id);
5574
5575 msc_gantt_utils.updateReqFromAlt(p_plan_id, p_instance_id,
5576 l_simu_res(i).transaction_id, l_alt_res(i).resource_id,
5577 v_hours, l_alt_res(i).alternate_number, l_alt_res(i).basis_type,
5578 l_alt_res(i).orig_resource_seq_num);
5579
5580 DeleteReqInstFromAlt(p_plan_id, p_instance_id, ll_temp_res_inst_trx_id);
5581
5582 if (l_simu_res(i).transaction_id = ll_res_trx_id ) then -- {
5583 put_line(' in res inst update insert');
5584 if ( p_node_type = RES_NODE and p_to_node_type = RES_INST_NODE ) then
5585 put_line(' res inst insert');
5586 l_temp_trx_id := msc_gantt_utils.insertReqInstFromAlt(p_plan_id,
5587 p_instance_id, ll_res_trx_id, p_alt_resource, p_alt_resource_inst,
5588 p_serial_number, v_hours, p_alt_num, RES_NODE,
5589 l_alt_res(i).orig_resource_seq_num);
5590 p_return_trx_id := l_temp_trx_id ;
5591 elsif ( p_node_type = RES_INST_NODE and p_to_node_type = RES_INST_NODE ) then
5592 put_line(' res inst update');
5593 msc_gantt_utils.updateReqInstFromAlt(p_plan_id, p_instance_id,
5594 ll_res_inst_trx_id, p_alt_resource, p_alt_resource_inst, p_serial_number,
5595 v_hours, l_alt_res(i).alternate_number,
5596 l_alt_res(i).orig_resource_seq_num);
5597 end if;
5598 end if; -- }
5599
5600 end if; -- }
5601 i := i+1;
5602 end loop; -- }
5603 end loop; -- }
5604
5605 -- update requirement's supply
5606 msc_gantt_utils.updateSupplies(p_plan_id, l_supply_id, TOUCH_SUPPLY);
5607
5608 p_return_status := 'OK';
5609 p_out := '';
5610 exception
5611 when app_exception.record_lock_exception then
5612 p_return_status := 'ERROR';
5613 p_out := 'RECORD_LOCK';
5614 end loadAltResource;
5615
5616 procedure lockReqInstNGetData(p_plan_id number, p_inst_id number, p_trx_id number,
5617 p_supply_id out nocopy number, p_start_date out nocopy date, p_end_date out nocopy date,
5618 p_return_status in OUT NOCOPY varchar2, p_out in OUT NOCOPY varchar2) is
5619
5620 begin
5621
5622 put_line(' lockReqInstNGetData in');
5623 -- lock the record first
5624 select mrir.supply_id, mrir.start_date, mrir.end_date
5625 into p_supply_id, p_start_date, p_end_date
5626 from msc_resource_instance_reqs mrir
5627 where mrir.plan_id = p_plan_id
5628 and mrir.sr_instance_id = p_inst_id
5629 and mrir.res_inst_transaction_id = p_trx_id
5630 for update of mrir.supply_id nowait;
5631
5632 put_line(' lockReqInstNGetData out');
5633 exception
5634 when no_data_found then
5635 null;
5636 when app_exception.record_lock_exception then
5637 p_return_status := 'ERROR';
5638 p_out := 'RECORD_LOCK';
5639 end lockReqInstNGetData;
5640
5641 procedure lockReqNGetData(p_plan_id number, p_inst_id number, p_trx_id number,
5642 p_firm_type out nocopy number, p_supply_id out nocopy number, p_start_date out nocopy date, p_end_date out nocopy date,
5643 p_firm_start_date out nocopy date, p_firm_end_date out nocopy date,
5644 p_return_status in OUT NOCOPY varchar2, p_out in OUT NOCOPY varchar2) is
5645
5646 begin
5647
5648 put_line(' lockReqNGetData in');
5649 -- lock the record first
5650 select mrr.firm_start_date, mrr.firm_end_date,
5651 mrr.start_date, mrr.end_date, mrr.supply_id, mrr.firm_flag
5652 into p_firm_start_date, p_firm_end_date,
5653 p_start_date, p_end_date, p_supply_id, p_firm_type
5654 from msc_resource_requirements mrr
5655 where mrr.plan_id = p_plan_id
5656 and mrr.sr_instance_id = p_inst_id
5657 and mrr.transaction_id = p_trx_id
5658 for update of mrr.firm_flag nowait;
5659
5660 --5153956 bugfix
5661 /*
5662 if p_firm_type in (NO_FIRM, FIRM_RESOURCE) then -- {
5663 p_firm_start_date := to_date(null);
5664 p_firm_end_date := to_date(null);
5665 elsif p_firm_type in (FIRM_END, FIRM_END_RES) then
5666 p_firm_start_date := to_date(null);
5667 p_firm_end_date := p_end_date;
5668 elsif p_firm_type in (FIRM_START, FIRM_START_RES) then
5669 p_firm_start_date := p_start_date;
5670 p_firm_end_date := to_date(null);
5671 elsif p_firm_type in (FIRM_START_END,FIRM_ALL) then
5672 p_firm_start_date := p_start_date;
5673 p_firm_end_date := p_end_date;
5674 end if; -- }
5675 */
5676 put_line(' lockReqNGetData out');
5677 exception
5678 when no_data_found then
5679 null;
5680 when app_exception.record_lock_exception then
5681 p_return_status := 'ERROR';
5682 p_out := 'RECORD_LOCK';
5683 end lockReqNGetData;
5684
5685 procedure updateBatchReq(p_plan_id number, p_inst_id number, p_batch_number number,
5686 p_start_date date, p_end_date date, p_firm_flag number, p_update_mode number,
5687 p_return_status in OUT NOCOPY varchar2, p_out in OUT NOCOPY varchar2) is
5688
5689 l_resource_id number_arr;
5690 l_temp number;
5691
5692 begin
5693
5694 -- lock MRR
5695 begin
5696 select mrr.resource_id
5697 bulk collect into l_resource_id
5698 from msc_resource_requirements mrr
5699 where mrr.plan_id = p_plan_id
5700 and mrr.sr_instance_id = p_inst_id
5701 and mrr.batch_number = p_batch_number
5702 for update of mrr.resource_id nowait;
5703
5704 select count(*)
5705 into l_temp
5706 from msc_resource_requirements mrr
5707 where mrr.plan_id = p_plan_id
5708 and mrr.sr_instance_id = p_inst_id
5709 and mrr.batch_number = p_batch_number
5710 and nvl(firm_flag,0) <> 0;
5711
5712 if ( l_temp > 0 ) then
5713 p_return_status := 'ERROR';
5714 p_out := 'REQ_IS_FIRMED';
5715 end if;
5716
5717 exception
5718 when app_exception.record_lock_exception then
5719 p_return_status := 'ERROR';
5720 p_out := 'RECORD_LOCK';
5721 return;
5722 end;
5723
5724 -- update MRR
5725 update msc_resource_requirements
5726 set status =0,
5727 applied=2,
5728 firm_flag = decode( p_update_mode, FIRM_MRR, p_firm_flag, firm_flag),
5729 start_date = decode( p_update_mode, MOVE_MRR, p_start_date, start_date),
5730 end_date = decode( p_update_mode, MOVE_MRR, p_end_date, end_date)
5731 where plan_id = p_plan_id
5732 and sr_instance_id = p_inst_id
5733 and batch_number = p_batch_number;
5734
5735 -- just update MS...we may need to lock in future..
5736 update msc_supplies
5737 set status = 0,
5738 applied = 2
5739 where plan_id = p_plan_id
5740 and sr_instance_id = p_inst_id
5741 and transaction_id in
5742 ( select distinct mrr.supply_id
5743 from msc_resource_requirements mrr
5744 where mrr.plan_id = p_plan_id
5745 and mrr.sr_instance_id = p_inst_id
5746 and mrr.batch_number = p_batch_number );
5747
5748 end updateBatchReq;
5749
5750 procedure updateBatchInstReq(p_plan_id number, p_inst_id number, p_batch_number number,
5751 p_start_date date, p_end_date date, p_firm_flag number, p_update_mode number,
5752 p_return_status in OUT NOCOPY varchar2, p_out in OUT NOCOPY varchar2) is
5753
5754 l_resource_id number_arr;
5755 l_temp number;
5756
5757 begin
5758
5759 -- lock MRIR
5760 begin
5761 select mrir.resource_id
5762 bulk collect into l_resource_id
5763 from msc_resource_instance_reqs mrir
5764 where mrir.plan_id = p_plan_id
5765 and mrir.sr_instance_id = p_inst_id
5766 and mrir.batch_number = p_batch_number
5767 for update of mrir.resource_id nowait;
5768
5769 select count(*)
5770 into l_temp
5771 from msc_resource_requirements mrr,
5772 msc_resource_instance_reqs mrir
5773 where mrir.plan_id = p_plan_id
5774 and mrir.sr_instance_id = p_inst_id
5775 and mrir.batch_number = p_batch_number
5776 and mrir.plan_id = mrr.plan_id
5777 and mrir.sr_instance_id = mrr.sr_instance_id
5778 and mrir.organization_id = mrr.organization_id
5779 and mrir.department_id = mrr.department_id
5780 and mrir.resource_id = mrr.resource_id
5781 and mrir.supply_id = mrr.supply_id
5782 and mrir.operation_seq_num = mrr.operation_seq_num
5783 and mrir.resource_seq_num = mrr.resource_seq_num
5784 and nvl(mrir.orig_resource_seq_num, mbp_null_value) = nvl(mrr.orig_resource_seq_num, mbp_null_value)
5785 and nvl(mrir.parent_seq_num, mbp_null_value) = nvl(mrr.parent_seq_num, mbp_null_value)
5786 and nvl(mrir.parent_id, mbp_null_value) = nvl(mrr.parent_id, mbp_null_value)
5787 and mrir.start_date = nvl(mrr.firm_start_date, mrr.start_date)
5788 and mrir.end_date = nvl(mrr.firm_end_date, mrr.end_date)
5789 and nvl(mrir.parent_id,2) = 2
5790 and nvl(mrr.firm_flag,0) <> 0;
5791
5792 if ( l_temp > 0 ) then
5793 p_return_status := 'ERROR';
5794 p_out := 'REQ_IS_FIRMED';
5795 end if;
5796
5797 exception
5798 when app_exception.record_lock_exception then
5799 p_return_status := 'ERROR';
5800 p_out := 'RECORD_LOCK';
5801 return;
5802 end;
5803
5804 -- update MRIR
5805 update msc_resource_instance_reqs
5806 set status =0,
5807 applied=2,
5808 start_date = p_start_date,
5809 end_date = p_end_date
5810 where plan_id = p_plan_id
5811 and sr_instance_id = p_inst_id
5812 and batch_number = p_batch_number;
5813
5814 -- just update MS...we may need to lock in future..
5815 update msc_supplies
5816 set status = 0,
5817 applied = 2
5818 where plan_id = p_plan_id
5819 and sr_instance_id = p_inst_id
5820 and transaction_id in
5821 ( select distinct mrir.supply_id
5822 from msc_resource_instance_reqs mrir
5823 where mrir.plan_id = p_plan_id
5824 and mrir.sr_instance_id = p_inst_id
5825 and mrir.batch_number = p_batch_number );
5826
5827 end updateBatchInstReq;
5828
5829 procedure updateResSeq(p_plan_id number, p_inst_id number,
5830 p_group_sequence_id number, p_duration varchar2,
5831 p_plan_start_date date, p_plan_end_date date,
5832 p_return_status in OUT NOCOPY varchar2, p_out in OUT NOCOPY varchar2,
5833 p_validate_flag boolean, p_node_type number ) is
5834
5835 l_resource_id number_arr;
5836
5837 cursor c_firm_seq_req_row (p_plan number, p_inst number, p_group_seq number) is
5838 select mrr.transaction_id, mrr.start_date, mrr.end_date,
5839 mrr.firm_flag, mrr.firm_start_date, mrr.firm_end_date
5840 from msc_resource_requirements mrr
5841 where mrr.plan_id = p_plan
5842 and mrr.sr_instance_id = p_inst
5843 and mrr.group_sequence_id = p_group_seq ;
5844
5845 l_trx_id number;
5846 l_start_date date;
5847 l_end_date date;
5848 l_firm_flag number;
5849 l_firm_start_date date;
5850 l_firm_end_date date;
5851
5852 begin
5853
5854 put_line(' updateResSeq in');
5855
5856 -- lock MRR
5857 begin
5858 select mrr.resource_id
5859 bulk collect into l_resource_id
5860 from msc_resource_requirements mrr
5861 where mrr.plan_id = p_plan_id
5862 and mrr.sr_instance_id = p_inst_id
5863 and mrr.group_sequence_id = p_group_sequence_id
5864 for update of mrr.resource_id nowait;
5865 exception
5866 when app_exception.record_lock_exception then
5867 p_return_status := 'ERROR';
5868 p_out := 'RECORD_LOCK';
5869 return;
5870 end;
5871
5872 open c_firm_seq_req_row(p_plan_id, p_inst_id, p_group_sequence_id);
5873 loop
5874 fetch c_firm_seq_req_row into l_trx_id, l_start_date, l_end_date,
5875 l_firm_flag, l_firm_start_date, l_firm_end_date;
5876 exit when c_firm_seq_req_row%notfound;
5877
5878 l_start_date := l_start_date + to_number(p_duration)/86400;
5879 l_end_date := l_end_date + to_number(p_duration)/86400;
5880 l_firm_start_date := l_firm_start_date + to_number(p_duration)/86400;
5881 l_firm_end_date := l_firm_end_date + to_number(p_duration)/86400;
5882
5883 if ( p_validate_flag ) then -- {
5884 validateTime(p_plan_id, l_trx_id, p_inst_id, l_start_date, l_end_date,
5885 p_plan_start_date, p_plan_end_date, p_return_status, p_out, p_node_type);
5886 if p_return_status = 'ERROR' then
5887 return ;
5888 end if;
5889 end if; -- }
5890
5891 moveOneResource(p_plan_id, l_trx_id, p_inst_id, l_start_date, l_end_date,
5892 p_return_status, p_out, RES_NODE);
5893
5894 if p_return_status = 'ERROR' then
5895 return;
5896 end if;
5897
5898 -- update the simultaneous resource for a given res trans id
5899 msc_gantt_utils.updateReqSimu(p_plan_id, p_inst_id, l_trx_id,
5900 l_firm_flag, l_start_date, l_end_date, l_firm_start_date, l_firm_end_date,
5901 MOVE_MRR, p_return_status, p_out);
5902
5903 if p_return_status = 'ERROR' then
5904 return;
5905 end if;
5906
5907 end loop;
5908 close c_firm_seq_req_row;
5909
5910 -- just update MS...we may need to lock in future..
5911 update msc_supplies
5912 set status = 0,
5913 applied = 2
5914 where plan_id = p_plan_id
5915 and sr_instance_id = p_inst_id
5916 and transaction_id in
5917 ( select distinct mrr.supply_id
5918 from msc_resource_requirements mrr
5919 where mrr.plan_id = p_plan_id
5920 and mrr.sr_instance_id = p_inst_id
5921 and mrr.group_sequence_id = p_group_sequence_id );
5922 put_line(' updateResSeq out');
5923
5924 end updateResSeq;
5925
5926 procedure updateReqFromAlt(p_plan_id number, p_inst_id number, p_simu_res_trx number,
5927 p_alt_res_id number, p_alt_res_hours number, p_alt_res_alt_num number, p_alt_res_basis_type number,
5928 p_alt_orig_res_seq_num number) is
5929 l_firm_flag number;
5930 begin
5931 select mrr.firm_flag
5932 into l_firm_flag
5933 from msc_resource_requirements mrr
5934 where mrr.plan_id = p_plan_id
5935 and mrr.transaction_id = p_simu_res_trx
5936 and mrr.sr_instance_id = p_inst_id
5937 for update of mrr.firm_flag nowait;
5938
5939 if l_firm_flag in (NO_FIRM, FIRM_RESOURCE) or l_firm_flag is null then -- {
5940 l_firm_flag := FIRM_RESOURCE;
5941 elsif l_firm_flag in (FIRM_START, FIRM_START_RES) THEN
5942 l_firm_flag := FIRM_START_RES;
5943 elsif l_firm_flag in (FIRM_END, FIRM_END_RES) THEN
5944 l_firm_flag := FIRM_END_RES;
5945 elsif l_firm_flag in (FIRM_ALL, FIRM_START_END) THEN
5946 l_firm_flag := FIRM_ALL;
5947 else
5948 l_firm_flag := FIRM_RESOURCE;
5949 end if; -- }
5950
5951 put_line(' updateReqFromAlt updating to alt_res_id '||p_alt_res_id);
5952
5953 update msc_resource_requirements
5954 set status = 0,
5955 applied=2,
5956 resource_id = p_alt_res_id,
5957 alternate_num = p_alt_res_alt_num,
5958 --firm_flag = l_firm_flag,
5959 resource_hours = p_alt_res_hours,
5960 orig_resource_seq_num = p_alt_orig_res_seq_num,
5961 basis_type = p_alt_res_basis_type
5962 where plan_id = p_plan_id
5963 and transaction_id = p_simu_res_trx
5964 and sr_instance_id = p_inst_id;
5965
5966 end updateReqFromAlt;
5967
5968 procedure updateReqInstFromAlt(p_plan_id number, p_inst_id number, p_simu_res_trx number,
5969 p_alt_res_id number, p_alt_res_instance_id number, p_serial_number varchar2,
5970 p_alt_res_hours number, p_alt_res_alt_num number,
5971 p_alt_orig_res_seq_num number) is
5972
5973 l_resource_id number;
5974 l_hours number;
5975 begin
5976 select mrir.resource_id, resource_instance_hours
5977 into l_resource_id, l_hours
5978 from msc_resource_instance_reqs mrir
5979 where mrir.plan_id = p_plan_id
5980 and mrir.sr_instance_id = p_inst_id
5981 and mrir.res_inst_transaction_id = p_simu_res_trx
5982 for update of mrir.resource_id nowait;
5983
5984 update msc_resource_instance_reqs
5985 set status = 0,
5986 applied=2,
5987 resource_id = p_alt_res_id,
5988 res_instance_id = p_alt_res_instance_id,
5989 serial_number = p_serial_number,
5990 orig_resource_seq_num = nvl(p_alt_orig_res_seq_num,orig_resource_seq_num),
5991 resource_instance_hours = nvl(p_alt_res_hours,resource_instance_hours)
5992 where plan_id = p_plan_id
5993 and res_inst_transaction_id = p_simu_res_trx
5994 and sr_instance_id = p_inst_id;
5995 end updateReqInstFromAlt;
5996
5997 procedure DeleteReqFromAlt(p_plan_id number, p_inst_id number, p_simu_res_trx number) is
5998 l_firm_flag number;
5999 begin
6000 select mrr.firm_flag
6001 into l_firm_flag
6002 from msc_resource_requirements mrr
6003 where mrr.plan_id = p_plan_id
6004 and mrr.sr_instance_id = p_inst_id
6005 and mrr.transaction_id = p_simu_res_trx
6006 for update of mrr.firm_flag nowait;
6007
6008 delete msc_resource_requirements mrr
6009 where mrr.plan_id = p_plan_id
6010 and mrr.sr_instance_id = p_inst_id
6011 and mrr.transaction_id = p_simu_res_trx;
6012 exception
6013 when no_data_found then
6014 null;
6015 end DeleteReqFromAlt;
6016
6017 procedure DeleteReqInstFromAlt(p_plan_id number,
6018 p_inst_id number, p_res_inst_trx number) is
6019 l_resource_id number;
6020 begin
6021 put_line('DeleteReqInstFromAlt in '||p_plan_id||' '||p_inst_id||' '||p_res_inst_trx);
6022 select mrir.resource_id
6023 into l_resource_id
6024 from msc_resource_instance_reqs mrir
6025 where mrir.plan_id = p_plan_id
6026 and mrir.sr_instance_id = p_inst_id
6027 and mrir.res_inst_transaction_id = p_res_inst_trx
6028 for update of mrir.resource_id nowait;
6029
6030 delete msc_resource_instance_reqs mrir
6031 where mrir.plan_id = p_plan_id
6032 and mrir.sr_instance_id = p_inst_id
6033 and mrir.res_inst_transaction_id = p_res_inst_trx;
6034
6035 exception
6036 when no_data_found then
6037 null;
6038 end DeleteReqInstFromAlt;
6039
6040 function insertReqInstFromAlt(p_plan_id number, p_inst_id number,
6041 p_simu_res_inst_trx number, p_alt_res_id number, p_alt_res_instance_id number,
6042 p_serial_number varchar2, p_alt_res_hours number, p_alt_res_alt_num number,
6043 p_from_node number,
6044 p_alt_orig_res_seq_num number) return number is
6045
6046 l_trx_id number;
6047
6048 cursor c_inst_row is
6049 select count(*)
6050 from msc_resource_instance_reqs
6051 where plan_id = p_plan_id
6052 and res_inst_transaction_id = l_trx_id;
6053
6054 cursor c_equipment is
6055 select equipment_item_id
6056 from msc_dept_res_instances
6057 where plan_id = p_plan_id
6058 and resource_id = p_alt_res_id
6059 and res_instance_id = p_alt_res_instance_id
6060 and nvl(serial_number,mbp_null_value_char) = nvl(p_serial_number,mbp_null_value_char);
6061
6062 l_equip_item_id number;
6063
6064 l_temp number;
6065 begin
6066 put_line(' insertReqInstFromAlt plan inst trx '|| p_plan_id ||' '|| p_inst_id||' '|| p_simu_res_inst_trx);
6067 select msc_resource_instance_reqs_s.nextval
6068 into l_trx_id
6069 from dual;
6070
6071 open c_equipment;
6072 fetch c_equipment into l_equip_item_id;
6073 close c_equipment;
6074
6075 -- p_node_type = RES_NODE and p_to_node_type = RES_INST_NODE
6076 if (p_from_node = RES_INST_NODE) then -- {
6077 put_line(' insertReqInstFromAlt : trying to insert a row in mrir from mrir l_trx_id '||l_trx_id);
6078
6079 insert into msc_resource_instance_reqs(
6080 RES_INST_TRANSACTION_ID, PLAN_ID, SR_INSTANCE_ID, ORGANIZATION_ID,
6081 SUPPLY_ID, DEPARTMENT_ID, RESOURCE_ID, RES_INSTANCE_ID, SERIAL_NUMBER, EQUIPMENT_ITEM_ID,
6082 PARENT_ID, PARENT_SEQ_NUM, OPERATION_SEQ_NUM, RESOURCE_SEQ_NUM, ORIG_RESOURCE_SEQ_NUM,
6083 SETUP_SEQUENCE_NUM, WIP_ENTITY_ID, START_DATE, END_DATE,
6084 RESOURCE_INSTANCE_HOURS, CAPACITY_CONSUMED, CAPACITY_CONSUMED_RATIO, BATCH_NUMBER,
6085 STATUS, APPLIED, UPDATED,
6086 LAST_UPDATE_DATE, LAST_UPDATED_BY, CREATION_DATE, CREATED_BY,LAST_UPDATE_LOGIN, REFRESH_NUMBER
6087 )
6088 select
6089 l_trx_id, PLAN_ID, SR_INSTANCE_ID, ORGANIZATION_ID,
6090 SUPPLY_ID, DEPARTMENT_ID, p_alt_res_id, p_alt_res_instance_id, p_serial_number, l_equip_item_id,
6091 PARENT_ID, PARENT_SEQ_NUM, OPERATION_SEQ_NUM, RESOURCE_SEQ_NUM, p_alt_orig_res_seq_num,
6092 SETUP_SEQUENCE_NUM, WIP_ENTITY_ID, START_DATE, END_DATE,
6093 p_alt_res_hours, CAPACITY_CONSUMED, CAPACITY_CONSUMED_RATIO, BATCH_NUMBER,
6094 STATUS, APPLIED, UPDATED,
6095 LAST_UPDATE_DATE, LAST_UPDATED_BY, CREATION_DATE, CREATED_BY,LAST_UPDATE_LOGIN, REFRESH_NUMBER
6096 from msc_resource_instance_reqs mrir
6097 where mrir.plan_id = p_plan_id
6098 and mrir.sr_instance_id = p_inst_id
6099 and mrir.res_inst_transaction_id = p_simu_res_inst_trx;
6100
6101 open c_inst_row;
6102 fetch c_inst_row into l_temp;
6103 close c_inst_row;
6104 put_line(' inserted '||l_temp||' rows ');
6105
6106 if (l_temp > 0) then
6107 return l_trx_id;
6108 end if;
6109 end if; -- }
6110
6111 if (p_from_node = RES_NODE) then -- {
6112
6113 put_line(' insertReqInstFromAlt : trying to insert a row in mrir from mrr l_trx_id '||l_trx_id);
6114
6115 insert into msc_resource_instance_reqs(
6116 RES_INST_TRANSACTION_ID, PLAN_ID, SR_INSTANCE_ID, ORGANIZATION_ID,
6117 SUPPLY_ID, DEPARTMENT_ID, RESOURCE_ID, RES_INSTANCE_ID, SERIAL_NUMBER, EQUIPMENT_ITEM_ID,
6118 PARENT_ID, PARENT_SEQ_NUM, OPERATION_SEQ_NUM, RESOURCE_SEQ_NUM, ORIG_RESOURCE_SEQ_NUM,
6119 --SETUP_SEQUENCE_NUM,
6120 WIP_ENTITY_ID, START_DATE, END_DATE,
6121 RESOURCE_INSTANCE_HOURS,
6122 --CAPACITY_CONSUMED, CAPACITY_CONSUMED_RATIO,
6123 BATCH_NUMBER, STATUS, APPLIED, UPDATED,
6124 LAST_UPDATE_DATE, LAST_UPDATED_BY, CREATION_DATE, CREATED_BY,LAST_UPDATE_LOGIN, REFRESH_NUMBER
6125 )
6126 select
6127 l_trx_id, PLAN_ID, SR_INSTANCE_ID, ORGANIZATION_ID,
6128 SUPPLY_ID, DEPARTMENT_ID, p_alt_res_id, p_alt_res_instance_id, p_serial_number, l_equip_item_id,
6129 PARENT_ID, PARENT_SEQ_NUM, OPERATION_SEQ_NUM, RESOURCE_SEQ_NUM, ORIG_RESOURCE_SEQ_NUM,
6130 --SETUP_SEQUENCE_NUM,
6131 WIP_ENTITY_ID, START_DATE, END_DATE, p_alt_res_hours,
6132 --CAPACITY_CONSUMED, CAPACITY_CONSUMED_RATIO,
6133 BATCH_NUMBER, STATUS, APPLIED, UPDATED,
6134 LAST_UPDATE_DATE, LAST_UPDATED_BY, CREATION_DATE, CREATED_BY,LAST_UPDATE_LOGIN, REFRESH_NUMBER
6135 from msc_resource_requirements mrr
6136 where mrr.plan_id = p_plan_id
6137 and mrr.sr_instance_id = p_inst_id
6138 and mrr.transaction_id = p_simu_res_inst_trx;
6139
6140 open c_inst_row;
6141 fetch c_inst_row into l_temp;
6142 close c_inst_row;
6143 put_line(' inserted '||l_temp||' rows ');
6144 end if; -- }
6145
6146 return l_trx_id;
6147 end insertReqInstFromAlt;
6148
6149 function insertReqFromAlt(p_plan_id number, p_inst_id number,
6150 p_simu_res_trx number,
6151 p_alt_res_id number,
6152 p_alt_res_hours number,
6153 p_alt_res_alt_num number,
6154 p_alt_res_basis_type number,
6155 p_alt_orig_res_seq_num number) return number is
6156 l_trx_id number;
6157 begin
6158 select msc_resource_instance_reqs_s.nextval
6159 into l_trx_id
6160 from dual;
6161
6162 insert into msc_resource_requirements(
6163 TRANSACTION_ID, PLAN_ID, SUPPLY_ID, ORGANIZATION_ID, SR_INSTANCE_ID,
6164 ROUTING_SEQUENCE_ID, OPERATION_SEQUENCE_ID, RESOURCE_SEQ_NUM, RESOURCE_ID,
6165 DEPARTMENT_ID, ALTERNATE_NUM, START_DATE, END_DATE, BKT_START_DATE,
6166 RESOURCE_HOURS, SET_UP, BKT_END_DATE, TEAR_DOWN, AGGREGATE_RESOURCE_ID,
6167 SCHEDULE_FLAG, PARENT_ID, STD_OP_CODE, WIP_ENTITY_ID, ASSIGNED_UNITS, BASIS_TYPE,
6168 OPERATION_SEQ_NUM, LOAD_RATE, DAILY_RESOURCE_HOURS, STATUS, APPLIED, UPDATED,
6169 SUBST_RES_FLAG, REFRESH_NUMBER,
6170 LAST_UPDATED_BY, LAST_UPDATE_DATE, CREATED_BY, CREATION_DATE, LAST_UPDATE_LOGIN,
6171 SOURCE_ITEM_ID, ASSEMBLY_ITEM_ID, SUPPLY_TYPE, FIRM_START_DATE, FIRM_END_DATE, FIRM_FLAG,
6172 ORIG_RESOURCE_SEQ_NUM
6173 )
6174 select l_trx_id, PLAN_ID, SUPPLY_ID, ORGANIZATION_ID, SR_INSTANCE_ID,
6175 ROUTING_SEQUENCE_ID, OPERATION_SEQUENCE_ID,
6176 RESOURCE_SEQ_NUM, p_alt_res_id, DEPARTMENT_ID, p_alt_res_alt_num,
6177 START_DATE, END_DATE, BKT_START_DATE, p_alt_res_hours, SET_UP, BKT_END_DATE, TEAR_DOWN,
6178 AGGREGATE_RESOURCE_ID, SCHEDULE_FLAG, PARENT_ID, STD_OP_CODE, WIP_ENTITY_ID, ASSIGNED_UNITS,
6179 p_alt_res_basis_type, OPERATION_SEQ_NUM, LOAD_RATE, DAILY_RESOURCE_HOURS, 0, 2, UPDATED,
6180 SUBST_RES_FLAG, REFRESH_NUMBER,
6181 LAST_UPDATED_BY, LAST_UPDATE_DATE, CREATED_BY, CREATION_DATE, LAST_UPDATE_LOGIN,
6182 SOURCE_ITEM_ID, ASSEMBLY_ITEM_ID, SUPPLY_TYPE, FIRM_START_DATE, FIRM_END_DATE, FIRM_RESOURCE,
6183 p_alt_orig_res_seq_num
6184 from msc_resource_requirements mrr
6185 where mrr.plan_id = p_plan_id
6186 and mrr.transaction_id = p_simu_res_trx
6187 and mrr.sr_instance_id = p_inst_id;
6188
6189 return l_trx_id;
6190 end insertReqFromAlt;
6191
6192 procedure updateReq(p_plan_id number, p_inst_id number, p_trx_id number,
6193 p_firm_type number, p_start_date date, p_end_date date,
6194 p_firm_start_date date, p_firm_end_date date,
6195 p_update_mode number) is
6196
6197 begin
6198 -- 5153956 bugfix, dont update start_date, end_date
6199
6200 -- 4673468 bugfix
6201 -- valid firm_type values
6202 -- 0 Un Firm
6203 -- 1 Firm Start Date
6204 -- 2 Firm End Date
6205 -- 3 Firm Resource
6206 -- 4 Firm Start Date and End Date
6207 -- 5 Firm Start Date and Resource
6208 -- 6 Firm End Date and Resource
6209 -- 7 Firm All
6210 update msc_resource_requirements
6211 set status =0,
6212 applied=2,
6213 firm_flag = decode(p_update_mode,
6214 MOVE_MRR, firm_flag,
6215 FIRM_MRR, p_firm_type,
6216 firm_flag),
6217 firm_start_date = decode(p_update_mode,
6218 FIRM_MRR, decode(p_firm_type,
6219 0, to_date(null),
6220 3, to_date(null),
6221 nvl(firm_start_date, start_date)),
6222 MOVE_MRR, p_start_date,
6223 firm_start_date),
6224 firm_end_date = decode(p_update_mode,
6225 FIRM_MRR, decode(p_firm_type,
6226 0, to_date(null),
6227 3, to_date(null),
6228 nvl(firm_end_date, end_date)),
6229 MOVE_MRR, p_end_date,
6230 firm_end_date),
6231 --start_date = p_start_date,
6232 --end_date = p_end_date,
6233 resource_hours = decode(p_update_mode,
6234 FIRM_MRR, resource_hours,
6235 MOVE_MRR, resource_hours + (assigned_units *
6236 (((p_end_date - p_start_date) * 24) - ((end_date - start_date) * 24))),
6237 resource_hours),
6238 batch_number = decode(p_update_mode, MOVE_MRR, to_number(null), batch_number)
6239 where plan_id = p_plan_id
6240 and transaction_id = p_trx_id
6241 and sr_instance_id = p_inst_id;
6242
6243 end updateReq;
6244
6245 -- update the simultaneous resource for a given res trans id
6246 procedure updateReqSimu(p_plan_id number, p_inst_id number, p_trx_id number,
6247 p_firm_type number, p_start_date in out nocopy date, p_end_date in out nocopy date,
6248 p_firm_start_date date, p_firm_end_date date,
6249 p_update_mode number,
6250 p_return_status in OUT NOCOPY varchar2,
6251 p_out in OUT NOCOPY varchar2) is
6252
6253 l_transaction_id number;
6254 l_instance_id number;
6255 l_count number :=0;
6256
6257 l_res_id number;
6258 begin
6259 open simu_res_cur(p_plan_id, p_inst_id, p_trx_id);
6260 loop -- {
6261 fetch simu_res_cur into l_transaction_id, l_instance_id;
6262 exit when simu_res_cur%notfound;
6263
6264 p_out := 'OK_WITH_SIMU_RES';
6265
6266 select mrr.resource_id
6267 into l_res_id
6268 from msc_resource_requirements mrr
6269 where mrr.plan_id = p_plan_id
6270 and mrr.transaction_id = l_transaction_id
6271 and mrr.sr_instance_id = l_instance_id
6272 for update of mrr.firm_flag nowait;
6273
6274 if ( p_update_mode = FIRM_MRR ) then
6275 -- update requirement
6276 msc_gantt_utils.updateReq(p_plan_id, l_instance_id, l_transaction_id,
6277 p_firm_type, p_start_date, p_end_date, p_firm_start_date, p_firm_end_date, p_update_mode);
6278 elsif ( p_update_mode = MOVE_MRR ) then
6279 moveOneResource(p_plan_id, l_transaction_id, l_instance_id,
6280 p_start_date, p_end_date, p_return_status, p_out, RES_NODE);
6281 end if;
6282
6283 if ( p_return_status = 'ERROR' ) then
6284 close simu_res_cur;
6285 return ;
6286 end if;
6287
6288 l_count := l_count + 1;
6289 end loop; -- }
6290 close simu_res_cur;
6291 end updateReqSimu;
6292
6293 procedure updateReqInst(p_plan_id number, p_inst_id number, p_trx_id number,
6294 p_start_date date, p_end_date date) is
6295 begin
6296 update msc_resource_instance_reqs
6297 set status =0,
6298 applied=2,
6299 start_date = p_start_date,
6300 end_date = p_end_date,
6301 batch_number = to_number(null),
6302 resource_instance_hours = resource_instance_hours
6303 + (((p_end_date - p_start_date) * 24) - ((end_date - start_date) * 24))
6304 where plan_id = p_plan_id
6305 and res_inst_transaction_id = p_trx_id
6306 and sr_instance_id = p_inst_id;
6307 end updateReqInst;
6308
6309 procedure firmReqInst(p_plan_id number, p_inst_id number, p_res_trx_id number, p_res_inst_trx_id number ) is
6310
6311 cursor c_res_req_dates is
6312 select nvl(mrr.firm_start_date, mrr.start_date),
6313 nvl(mrr.firm_end_date, mrr.end_date)
6314 from msc_resource_requirements mrr
6315 where mrr.plan_id = p_plan_id
6316 and mrr.sr_instance_id = p_inst_id
6317 and mrr.transaction_id = p_res_trx_id;
6318
6319 l_start_date date;
6320 l_end_date date;
6321 begin
6322 open c_res_req_dates;
6323 fetch c_res_req_dates into l_start_date, l_end_date;
6324 close c_res_req_dates;
6325
6326 update msc_resource_instance_reqs
6327 set status =0,
6328 applied=2,
6329 start_date = l_start_date,
6330 end_date = l_end_date
6331 where plan_id = p_plan_id
6332 and res_inst_transaction_id = p_res_inst_trx_id
6333 and sr_instance_id = p_inst_id;
6334 end firmReqInst;
6335
6336 procedure updateSupplies(p_plan_id number,
6337 p_trx_id number, p_update_type number,
6338 p_firm_type number default null,
6339 p_firm_date date default null,
6340 p_firm_qty number default null) is
6341 begin
6342 update msc_supplies
6343 set status = 0,
6344 applied = 2,
6345 firm_planned_type = decode(p_update_type,
6346 FIRM_SUPPLY, p_firm_type,
6347 FIRM_ALL_SUPPLY, p_firm_type,
6348 firm_planned_type),
6349 firm_date = decode(p_update_type,
6350 FIRM_ALL_SUPPLY, p_firm_date,
6351 firm_date),
6352 firm_quantity = decode(p_update_type,
6353 FIRM_ALL_SUPPLY, p_firm_qty,
6354 firm_quantity)
6355 where plan_id = p_plan_id
6356 and transaction_id = p_trx_id;
6357 end updateSupplies;
6358
6359 procedure validateTime(p_plan_id number,
6360 p_transaction_id number, p_instance_id number,
6361 p_start_date date, p_end_date date,
6362 p_plan_start_date date, p_plan_end_date date,
6363 p_return_status in OUT NOCOPY varchar2,
6364 p_out in OUT NOCOPY varchar2,
6365 p_node_type number) IS
6366
6367 cursor curr_res is
6368 select mrr.operation_seq_num,
6369 nvl(mrr.schedule_flag, 0) schedule_flag,
6370 decode(ms.order_type, 27, 1, ms.firm_planned_type) firm_planned_type,
6371 sysdate theDate,
6372 getMTQTime(p_transaction_id, p_plan_id, p_instance_id) mtq_time
6373 from msc_resource_requirements mrr,
6374 msc_supplies ms
6375 where mrr.plan_id = p_plan_id
6376 and mrr.sr_instance_id = p_instance_id
6377 and mrr.transaction_id = p_transaction_id
6378 and ms.plan_id = mrr.plan_id
6379 and ms.transaction_id = mrr.supply_id
6380 and ms.sr_instance_id = mrr.sr_instance_id;
6381
6382 cursor lower_bound is
6383 select mrr2.operation_seq_num,
6384 mrr2.resource_seq_num,
6385 mrr2.transaction_id,
6386 nvl(mrr2.schedule_flag, 0) schedule_flag,
6387 decode(nvl(mrr2.firm_flag,0),
6388 NO_FIRM, mrr2.start_date,
6389 FIRM_RESOURCE, mrr2.start_date,
6390 FIRM_END, mrr2.firm_end_date -
6391 (nvl(mrr2.end_date, mrr2.start_date+mrr2.resource_hours/24) - mrr2.start_date),
6392 FIRM_END_RES, mrr2.firm_end_date -
6393 (nvl(mrr2.end_date, mrr2.start_date+mrr2.resource_hours/24) - mrr2.start_date),
6394 nvl(mrr2.firm_start_date, mrr2.start_date)) start_date,
6395 decode(nvl(mrr2.firm_flag,0),
6396 NO_FIRM, nvl(mrr2.end_date, mrr2.start_date+mrr2.resource_hours/24),
6397 FIRM_RESOURCE, nvl(mrr2.end_date, mrr2.start_date+mrr2.resource_hours/24),
6398 FIRM_START, mrr2.firm_start_date +
6399 (nvl(mrr2.end_date, mrr2.start_date+mrr2.resource_hours/24) - mrr2.start_date),
6400 FIRM_START_RES, mrr2.firm_start_date +
6401 (nvl(mrr2.end_date, mrr2.start_date+mrr2.resource_hours/24) - mrr2.start_date),
6402 nvl(nvl(mrr2.firm_end_date, mrr2.end_date), mrr2.start_date+mrr2.resource_hours/24)) end_date,
6403 msc_gantt_utils.getMTQTime(mrr2.transaction_id, p_plan_id, p_instance_id) mtq_time
6404 from msc_resource_requirements mrr1,
6405 msc_resource_requirements mrr2,
6406 msc_routings mr
6407 where mrr1.plan_id = p_plan_id
6408 and mrr1.transaction_id = p_transaction_id
6409 and mrr1.sr_instance_id = p_instance_id
6410 and mrr2.plan_id = mrr1.plan_id
6411 and mrr2.supply_id = mrr1.supply_id
6412 and mrr2.sr_instance_id = mrr1.sr_instance_id
6413 and nvl(mrr2.parent_id,2) =2
6414 and mr.plan_id = mrr1.plan_id
6415 and mr.sr_instance_id = mrr1.sr_instance_id
6416 and mr.routing_sequence_id = mrr1.routing_sequence_id
6417 and (((nvl(mr.cfm_routing_flag,2) <> 3 and mrr2.operation_seq_num < mrr1.operation_seq_num)
6418 or ( nvl(mr.cfm_routing_flag,2) = 3
6419 and mrr2.operation_sequence_id in (
6420 select mon.from_op_seq_id
6421 from msc_operation_networks mon
6422 where mon.plan_id = mrr1.plan_id
6423 and mon.sr_instance_id = mrr1.sr_instance_id
6424 and mon.routing_sequence_id = mrr1.routing_sequence_id
6425 and mon.to_op_seq_id = mrr1.operation_sequence_id
6426 ))) or
6427 (mrr2.operation_seq_num = mrr1.operation_seq_num and
6428 mrr2.resource_seq_num < mrr1.resource_seq_num))
6429 and (mrr2.firm_start_date is not null or mrr2.firm_end_date is not null )
6430 and mrr2.firm_flag in (FIRM_START,FIRM_END,FIRM_START_END,FIRM_START_RES,FIRM_END_RES,FIRM_ALL)
6431 order by mrr2.operation_seq_num desc, mrr2.resource_seq_num desc;
6432
6433 cursor upper_bound is
6434 select mrr2.operation_seq_num,
6435 mrr2.resource_seq_num,
6436 mrr2.transaction_id,
6437 nvl(mrr2.schedule_flag, 0) schedule_flag,
6438 decode(nvl(mrr2.firm_flag,0),
6439 NO_FIRM, mrr2.start_date,
6440 FIRM_RESOURCE, mrr2.start_date,
6441 FIRM_END, mrr2.firm_end_date -
6442 (nvl(mrr2.end_date, mrr2.start_date+mrr2.resource_hours/24) - mrr2.start_date),
6443 FIRM_END_RES, mrr2.firm_end_date -
6444 (nvl(mrr2.end_date, mrr2.start_date+mrr2.resource_hours/24) - mrr2.start_date),
6445 nvl(mrr2.firm_start_date, mrr2.start_date)) start_date,
6446 decode(nvl(mrr2.firm_flag,0),
6447 NO_FIRM, nvl(mrr2.end_date, mrr2.start_date+mrr2.resource_hours/24),
6448 FIRM_RESOURCE, nvl(mrr2.end_date, mrr2.start_date+mrr2.resource_hours/24),
6449 FIRM_START, mrr2.firm_start_date +
6450 (nvl(mrr2.end_date, mrr2.start_date+mrr2.resource_hours/24) - mrr2.start_date),
6451 FIRM_START_RES, mrr2.firm_start_date +
6452 (nvl(mrr2.end_date, mrr2.start_date+mrr2.resource_hours/24) - mrr2.start_date),
6453 nvl(nvl(mrr2.firm_end_date, mrr2.end_date), mrr2.start_date+mrr2.resource_hours/24)) end_date
6454 from msc_resource_requirements mrr1,
6455 msc_resource_requirements mrr2,
6456 msc_routings mr
6457 where mrr1.plan_id = p_plan_id
6458 and mrr1.transaction_id = p_transaction_id
6459 and mrr1.sr_instance_id = p_instance_id
6460 and mrr2.plan_id = mrr1.plan_id
6461 and mrr2.supply_id = mrr1.supply_id
6462 and mrr2.sr_instance_id = mrr1.sr_instance_id
6463 and nvl(mrr2.parent_id,2) =2
6464 and mr.plan_id = mrr1.plan_id
6465 and mr.sr_instance_id = mrr1.sr_instance_id
6466 and mr.routing_sequence_id = mrr1.routing_sequence_id
6467 and (((nvl(mr.cfm_routing_flag,2) <> 3 and mrr2.operation_seq_num > mrr1.operation_seq_num)
6468 or ( nvl(mr.cfm_routing_flag,2) = 3 and mrr2.operation_sequence_id in (
6469 select mon.to_op_seq_id from msc_operation_networks mon
6470 where mon.plan_id = mrr1.plan_id
6471 and mon.sr_instance_id = mrr1.sr_instance_id
6472 and mon.routing_sequence_id = mrr1.routing_sequence_id
6473 and mon.from_op_seq_id = mrr1.operation_sequence_id
6474 ))) or
6475 (mrr2.operation_seq_num = mrr1.operation_seq_num and
6476 mrr2.resource_seq_num > mrr1.resource_seq_num))
6477 and (mrr2.firm_start_date is not null or
6478 mrr2.firm_end_date is not null )
6479 and mrr2.firm_flag in (FIRM_START,FIRM_END,FIRM_START_END,FIRM_START_RES,
6480 FIRM_END_RES,FIRM_ALL)
6481 order by mrr2.operation_seq_num, mrr2.resource_seq_num;
6482
6483
6484 cursor curr_res_inst is
6485 select mrr.operation_seq_num,
6486 nvl(mrr.schedule_flag, 0) schedule_flag,
6487 decode(ms.order_type, 27, 1, ms.firm_planned_type) firm_planned_type,
6488 sysdate theDate,
6489 getMTQTime(p_transaction_id, p_plan_id, p_instance_id) mtq_time
6490 from msc_resource_requirements mrr,
6491 msc_resource_instance_reqs mrir,
6492 msc_supplies ms
6493 where mrir.plan_id = p_plan_id
6494 and mrir.sr_instance_id = p_instance_id
6495 and mrir.res_inst_transaction_id = p_transaction_id
6496 and mrir.plan_id = mrr.plan_id
6497 and mrir.sr_instance_id = mrr.sr_instance_id
6498 and mrir.organization_id = mrr.organization_id
6499 and mrir.department_id = mrr.department_id
6500 and mrir.resource_id = mrr.resource_id
6501 and mrir.supply_id = mrr.supply_id
6502 and mrir.operation_seq_num = mrr.operation_seq_num
6503 and mrir.resource_seq_num = mrr.resource_seq_num
6504 and nvl(mrir.orig_resource_seq_num, mbp_null_value) = nvl(mrr.orig_resource_seq_num, mbp_null_value)
6505 and nvl(mrir.parent_seq_num, mbp_null_value) = nvl(mrr.parent_seq_num, mbp_null_value)
6506 and nvl(mrir.parent_id, mbp_null_value) = nvl(mrr.parent_id, mbp_null_value)
6507 and mrir.start_date = nvl(mrr.firm_start_date, mrr.start_date)
6508 and mrir.end_date = nvl(mrr.firm_end_date, mrr.end_date)
6509 and ms.plan_id = mrr.plan_id
6510 and ms.transaction_id = mrr.supply_id
6511 and ms.sr_instance_id = mrr.sr_instance_id;
6512
6513 cursor lower_bound_res_inst is
6514 select mrr2.operation_seq_num,
6515 mrr2.resource_seq_num,
6516 mrr2.transaction_id,
6517 nvl(mrr2.schedule_flag, 0) schedule_flag,
6518 decode(nvl(mrr2.firm_flag,0),
6519 NO_FIRM, mrir2.start_date,
6520 FIRM_RESOURCE, mrir2.start_date,
6521 FIRM_END, mrr2.firm_end_date -
6522 (nvl(mrir2.end_date, mrir2.start_date+mrir2.resource_instance_hours/24) - mrir2.start_date),
6523 FIRM_END_RES, mrr2.firm_end_date -
6524 (nvl(mrir2.end_date, mrir2.start_date+mrir2.resource_instance_hours/24) - mrir2.start_date),
6525 nvl(mrr2.firm_start_date, mrir2.start_date)) start_date,
6526 decode(nvl(mrr2.firm_flag,0),
6527 NO_FIRM, nvl(mrir2.end_date, mrir2.start_date+mrir2.resource_instance_hours/24),
6528 FIRM_RESOURCE, nvl(mrir2.end_date, mrir2.start_date+mrir2.resource_instance_hours/24),
6529 FIRM_START, mrr2.firm_start_date +
6530 (nvl(mrir2.end_date, mrir2.start_date+mrir2.resource_instance_hours/24) - mrir2.start_date),
6531 FIRM_START_RES, mrr2.firm_start_date +
6532 (nvl(mrir2.end_date, mrir2.start_date+mrir2.resource_instance_hours/24) - mrir2.start_date),
6533 nvl(nvl(mrr2.firm_end_date, mrir2.end_date), mrir2.start_date+mrir2.resource_instance_hours/24)) end_date,
6534 msc_gantt_utils.getMTQTime(mrr2.transaction_id, p_plan_id, p_instance_id) mtq_time
6535 from msc_resource_requirements mrr1,
6536 msc_resource_instance_reqs mrir1,
6537 msc_resource_requirements mrr2,
6538 msc_resource_instance_reqs mrir2,
6539 msc_routings mr
6540 where mrir1.plan_id = p_plan_id
6541 and mrir1.res_inst_transaction_id = p_transaction_id
6542 and mrir1.sr_instance_id = p_instance_id
6543 and mrir1.plan_id = mrr1.plan_id
6544 and mrir1.sr_instance_id = mrr1.sr_instance_id
6545 and mrir1.organization_id = mrr1.organization_id
6546 and mrir1.department_id = mrr1.department_id
6547 and mrir1.resource_id = mrr1.resource_id
6548 and mrir1.supply_id = mrr1.supply_id
6549 and mrir1.operation_seq_num = mrr1.operation_seq_num
6550 and mrir1.resource_seq_num = mrr1.resource_seq_num
6551 and nvl(mrir1.orig_resource_seq_num, mbp_null_value) = nvl(mrr1.orig_resource_seq_num, mbp_null_value)
6552 and nvl(mrir1.parent_seq_num, mbp_null_value) = nvl(mrr1.parent_seq_num, mbp_null_value)
6553 and nvl(mrir1.parent_id, mbp_null_value) = nvl(mrr1.parent_id, mbp_null_value)
6554 and mrir1.start_date = nvl(mrr1.firm_start_date, mrr1.start_date)
6555 and mrir1.end_date = nvl(mrr1.firm_end_date, mrr1.end_date)
6556 and mrr2.plan_id = mrr1.plan_id
6557 and mrr2.supply_id = mrr1.supply_id
6558 and mrr2.sr_instance_id = mrr1.sr_instance_id
6559 and nvl(mrr2.parent_id,2) =2
6560 and mrir2.plan_id = mrr2.plan_id
6561 and mrir2.sr_instance_id = mrr2.sr_instance_id
6562 and mrir2.organization_id = mrr2.organization_id
6563 and mrir2.department_id = mrr2.department_id
6564 and mrir2.resource_id = mrr2.resource_id
6565 and mrir2.supply_id = mrr2.supply_id
6566 and mrir2.operation_seq_num = mrr2.operation_seq_num
6567 and mrir2.resource_seq_num = mrr2.resource_seq_num
6568 and nvl(mrir2.orig_resource_seq_num, mbp_null_value) = nvl(mrr2.orig_resource_seq_num, mbp_null_value)
6569 and nvl(mrir2.parent_seq_num, mbp_null_value) = nvl(mrr2.parent_seq_num, mbp_null_value)
6570 and nvl(mrir2.parent_id, mbp_null_value) = nvl(mrr2.parent_id, mbp_null_value)
6571 and mrir2.start_date = nvl(mrr2.firm_start_date, mrr2.start_date)
6572 and mrir2.end_date = nvl(mrr2.firm_end_date, mrr2.end_date)
6573 and mr.plan_id = mrr1.plan_id
6574 and mr.sr_instance_id = mrr1.sr_instance_id
6575 and mr.routing_sequence_id = mrr1.routing_sequence_id
6576 and (((nvl(mr.cfm_routing_flag,2) <> 3 and mrr2.operation_seq_num < mrr1.operation_seq_num)
6577 or ( nvl(mr.cfm_routing_flag,2) = 3
6578 and mrr2.operation_sequence_id in (
6579 select mon.from_op_seq_id
6580 from msc_operation_networks mon
6581 where mon.plan_id = mrr1.plan_id
6582 and mon.sr_instance_id = mrr1.sr_instance_id
6583 and mon.routing_sequence_id = mrr1.routing_sequence_id
6584 and mon.to_op_seq_id = mrr1.operation_sequence_id
6585 ))) or
6586 (mrr2.operation_seq_num = mrr1.operation_seq_num and
6587 mrr2.resource_seq_num < mrr1.resource_seq_num))
6588 and (mrr2.firm_start_date is not null or mrr2.firm_end_date is not null )
6589 and mrr2.firm_flag in (FIRM_START,FIRM_END,FIRM_START_END,FIRM_START_RES,FIRM_END_RES,FIRM_ALL)
6590 order by mrr2.operation_seq_num desc, mrr2.resource_seq_num desc;
6591
6592 cursor upper_bound_res_inst is
6593 select mrr2.operation_seq_num,
6594 mrr2.resource_seq_num,
6595 mrr2.transaction_id,
6596 nvl(mrr2.schedule_flag, 0) schedule_flag,
6597 decode(nvl(mrr2.firm_flag,0),
6598 NO_FIRM, mrir2.start_date,
6599 FIRM_RESOURCE, mrir2.start_date,
6600 FIRM_END, mrr2.firm_end_date -
6601 (nvl(mrir2.end_date, mrir2.start_date+mrir2.resource_instance_hours/24) - mrir2.start_date),
6602 FIRM_END_RES, mrr2.firm_end_date -
6603 (nvl(mrir2.end_date, mrir2.start_date+mrir2.resource_instance_hours/24) - mrir2.start_date),
6604 nvl(mrr2.firm_start_date, mrir2.start_date)) start_date,
6605 decode(nvl(mrr2.firm_flag,0),
6606 NO_FIRM, nvl(mrir2.end_date, mrir2.start_date+mrir2.resource_instance_hours/24),
6607 FIRM_RESOURCE, nvl(mrir2.end_date, mrir2.start_date+mrir2.resource_instance_hours/24),
6608 FIRM_START, mrr2.firm_start_date +
6609 (nvl(mrir2.end_date, mrir2.start_date+mrir2.resource_instance_hours/24) - mrir2.start_date),
6610 FIRM_START_RES, mrr2.firm_start_date +
6611 (nvl(mrir2.end_date, mrir2.start_date+mrir2.resource_instance_hours/24) - mrir2.start_date),
6612 nvl(nvl(mrr2.firm_end_date, mrir2.end_date), mrir2.start_date+mrir2.resource_instance_hours/24)) end_date
6613 from msc_resource_requirements mrr1,
6614 msc_resource_instance_reqs mrir1,
6615 msc_resource_requirements mrr2,
6616 msc_resource_instance_reqs mrir2,
6617 msc_routings mr
6618 where mrir1.plan_id = p_plan_id
6619 and mrir1.res_inst_transaction_id = p_transaction_id
6620 and mrir1.sr_instance_id = p_instance_id
6621 and mrir1.plan_id = mrr1.plan_id
6622 and mrir1.sr_instance_id = mrr1.sr_instance_id
6623 and mrir1.organization_id = mrr1.organization_id
6624 and mrir1.department_id = mrr1.department_id
6625 and mrir1.resource_id = mrr1.resource_id
6626 and mrir1.supply_id = mrr1.supply_id
6627 and mrir1.resource_seq_num = mrr1.resource_seq_num
6628 and mrir1.operation_seq_num = mrr1.operation_seq_num
6629 and nvl(mrir1.orig_resource_seq_num, mbp_null_value) = nvl(mrr1.orig_resource_seq_num, mbp_null_value)
6630 and nvl(mrir1.parent_seq_num, mbp_null_value) = nvl(mrr1.parent_seq_num, mbp_null_value)
6631 and nvl(mrir1.parent_id, mbp_null_value) = nvl(mrr1.parent_id, mbp_null_value)
6632 and mrir1.start_date = nvl(mrr1.firm_start_date, mrr1.start_date)
6633 and mrir1.end_date = nvl(mrr1.firm_end_date, mrr1.end_date)
6634 and mrr2.plan_id = mrr1.plan_id
6635 and mrr2.supply_id = mrr1.supply_id
6636 and mrr2.sr_instance_id = mrr1.sr_instance_id
6637 and nvl(mrr2.parent_id,2) =2
6638 and mrir2.plan_id = mrr2.plan_id
6639 and mrir2.sr_instance_id = mrr2.sr_instance_id
6640 and mrir2.organization_id = mrr2.organization_id
6641 and mrir2.department_id = mrr2.department_id
6642 and mrir2.resource_id = mrr2.resource_id
6643 and mrir2.supply_id = mrr2.supply_id
6644 and mrir2.operation_seq_num = mrr2.operation_seq_num
6645 and mrir2.resource_seq_num = mrr2.resource_seq_num
6646 and nvl(mrir2.orig_resource_seq_num, mbp_null_value) = nvl(mrr2.orig_resource_seq_num, mbp_null_value)
6647 and nvl(mrir2.parent_seq_num, mbp_null_value) = nvl(mrr2.parent_seq_num, mbp_null_value)
6648 and nvl(mrir2.parent_id, mbp_null_value) = nvl(mrr2.parent_id, mbp_null_value)
6649 and mrir2.start_date = nvl(mrr2.firm_start_date, mrr2.start_date)
6650 and mrir2.end_date = nvl(mrr2.firm_end_date, mrr2.end_date)
6651 and mr.plan_id = mrr1.plan_id
6652 and mr.sr_instance_id = mrr1.sr_instance_id
6653 and mr.routing_sequence_id = mrr1.routing_sequence_id
6654 and (((nvl(mr.cfm_routing_flag,2) <> 3 and mrr2.operation_seq_num > mrr1.operation_seq_num)
6655 or ( nvl(mr.cfm_routing_flag,2) = 3 and mrr2.operation_sequence_id in (
6656 select mon.to_op_seq_id from msc_operation_networks mon
6657 where mon.plan_id = mrr1.plan_id
6658 and mon.sr_instance_id = mrr1.sr_instance_id
6659 and mon.routing_sequence_id = mrr1.routing_sequence_id
6660 and mon.from_op_seq_id = mrr1.operation_sequence_id
6661 ))) or
6662 (mrr2.operation_seq_num = mrr1.operation_seq_num and
6663 mrr2.resource_seq_num > mrr1.resource_seq_num))
6664 and (mrr2.firm_start_date is not null or
6665 mrr2.firm_end_date is not null )
6666 and mrr2.firm_flag in (FIRM_START,FIRM_END,FIRM_START_END,FIRM_START_RES,
6667 FIRM_END_RES,FIRM_ALL)
6668 order by mrr2.operation_seq_num, mrr2.resource_seq_num;
6669
6670 v_lower_start_id number;
6671 v_lower_start date;
6672 v_lower_end date;
6673 v_lower_end_id number;
6674 v_lower_mtq_id number;
6675
6676 v_upper_start Date;
6677 v_upper_start_id number;
6678 v_upper_end date;
6679 v_upper_end_id number;
6680 v_upper_mtq_id number;
6681
6682 v_prev_op number;
6683 v_next_op number;
6684
6685
6686 ll_operation_seq_num varchar2(80);
6687 ll_schedule_flag number;
6688 ll_firm_planned_type number;
6689 ll_theDate date;
6690 ll_mtq_time number;
6691
6692 lower_operation_seq_num varchar2(80);
6693 lower_resource_seq_num varchar2(80);
6694 lower_transaction_id number;
6695 lower_schedule_flag number;
6696 lower_start_date date;
6697 lower_end_date date;
6698 lower_mtq_time number;
6699
6700 upper_operation_seq_num varchar2(80);
6701 upper_resource_seq_num varchar2(80);
6702 upper_transaction_id number;
6703 upper_schedule_flag number;
6704 upper_start_date date;
6705 upper_end_date date;
6706 upper_mtq_time number;
6707
6708 begin
6709 p_return_status := 'OK';
6710
6711 -- end_date_greater_than_plan_end
6712 if p_end_date > p_plan_end_date then -- {
6713 p_return_status := 'ERROR';
6714 p_out := 'END_DATE_GREATER_THAN_PLAN_END';
6715 return;
6716 end if; -- }
6717
6718 -- start_date_less_than_plan_start
6719 if p_start_date < p_plan_start_date then -- {
6720 p_return_status := 'ERROR';
6721 p_out := 'START_DATE_LESS_THAN_PLAN_START';
6722 return;
6723 end if; -- }
6724
6725 -- start_date_greater_than_end_date
6726 if p_start_date > p_end_date then -- {
6727 p_return_status := 'ERROR';
6728 p_out := 'START_DATE_GREATER_THAN_END_DATE';
6729 return;
6730 end if; -- }
6731
6732 if ( p_node_type = RES_NODE ) then
6733 open curr_res;
6734 fetch curr_res into ll_operation_seq_num, ll_schedule_flag, ll_firm_planned_type, ll_theDate, ll_mtq_time;
6735 close curr_res;
6736 else
6737 open curr_res_inst;
6738 fetch curr_res_inst into ll_operation_seq_num, ll_schedule_flag, ll_firm_planned_type, ll_theDate, ll_mtq_time;
6739 close curr_res_inst;
6740 end if;
6741
6742 -- associated supply is firmed..cannot be firmed
6743 if ll_firm_planned_type = 1 then -- {
6744 p_return_status := 'ERROR';
6745 p_out := 'FIRM_SUPPLY';
6746 return;
6747 end if; -- }
6748
6749 -- start date is less than sysdate..cannot be firmed
6750 if p_start_date < ll_thedate then -- {
6751 p_return_status := 'ERROR';
6752 --p_out := to_char(ll_theDate,format_mask)|| field_seperator ||null_space||field_seperator||null_space ;
6753 --5728088, send translated message to pld
6754 fnd_message.set_name('MSC', 'MSC_GC_START_DT_LT_SYSDATE');
6755 fnd_message.set_token('START_DATE', to_char(p_start_date,format_mask));
6756 p_out := fnd_message.get;
6757 return;
6758 end if; -- }
6759
6760 if ( p_node_type = RES_NODE ) then
6761 open lower_bound;
6762 else
6763 open lower_bound_res_inst;
6764 end if;
6765
6766 loop -- {
6767 if ( p_node_type = RES_NODE ) then -- {
6768 fetch lower_bound into lower_operation_seq_num, lower_resource_seq_num,
6769 lower_transaction_id, lower_schedule_flag,
6770 lower_start_date, lower_end_date, lower_mtq_time;
6771 exit when lower_bound%notfound;
6772 else
6773 fetch lower_bound_res_inst into lower_operation_seq_num, lower_resource_seq_num,
6774 lower_transaction_id, lower_schedule_flag,
6775 lower_start_date, lower_end_date, lower_mtq_time;
6776 exit when lower_bound_res_inst%notfound;
6777 end if; -- }
6778
6779 if v_lower_start is not null and v_lower_end is not null then -- {
6780 exit;
6781 else
6782 if ( v_prev_op is null
6783 and lower_operation_seq_num < ll_operation_seq_num ) then -- {
6784 v_prev_op := lower_operation_seq_num;
6785 end if; -- }
6786 if v_lower_start is null then -- {
6787 v_lower_start := lower_start_date;
6788 v_lower_start_id := lower_transaction_id;
6789 end if; -- }
6790 if v_lower_end is null then -- {
6791 v_lower_end := lower_end_date;
6792 v_lower_end_id := lower_transaction_id;
6793 end if; -- }
6794 if v_lower_mtq_id is null then -- {
6795 if not (v_prev_op is not null and
6796 lower_operation_seq_num = v_prev_op and
6797 ll_schedule_flag = 3 and -- prior
6798 lower_schedule_flag = 4) then -- {
6799 if p_start_date <
6800 lower_start_date + lower_mtq_time*(lower_end_date - lower_start_date) then -- {
6801 v_lower_mtq_id := lower_transaction_id;
6802 end if; -- }
6803 end if; -- }
6804 end if; -- }
6805 end if; -- }
6806 end loop; -- }
6807 if ( p_node_type = RES_NODE ) then
6808 close lower_bound;
6809 else
6810 close lower_bound_res_inst;
6811 end if;
6812
6813 if ( p_node_type = RES_NODE ) then
6814 open upper_bound;
6815 else
6816 open upper_bound_res_inst;
6817 end if;
6818 loop -- {
6819 if ( p_node_type = RES_NODE ) then
6820 fetch upper_bound into upper_operation_seq_num, upper_resource_seq_num,
6821 upper_transaction_id, upper_schedule_flag,
6822 upper_start_date, upper_end_date;
6823 exit when upper_bound%notfound;
6824 else
6825 fetch upper_bound_res_inst into upper_operation_seq_num, upper_resource_seq_num,
6826 upper_transaction_id, upper_schedule_flag,
6827 upper_start_date, upper_end_date;
6828 exit when upper_bound_res_inst%notfound;
6829 end if;
6830
6831
6832 if v_upper_start is not null and v_upper_end is not null then -- {
6833 exit;
6834 else
6835 if v_next_op is null and
6836 upper_operation_seq_num > ll_operation_seq_num then -- {
6837 v_next_op := upper_operation_seq_num;
6838 end if; -- }
6839 if v_upper_start is null then -- {
6840 v_upper_start := upper_start_date;
6841 v_upper_start_id := upper_transaction_id;
6842 end if; -- }
6843 if v_upper_end is null then -- {
6844 v_upper_end := upper_end_date;
6845 v_upper_end_id := upper_transaction_id;
6846 end if; -- }
6847 if v_upper_mtq_id is null then -- {
6848 if not (v_next_op is not null and
6849 upper_operation_seq_num = v_next_op and
6850 ll_schedule_flag = 4 and --next
6851 upper_schedule_flag = 3) then -- {
6852 if upper_start_date < p_start_date +
6853 ll_mtq_time* (p_end_date - p_start_date) then -- {
6854 v_upper_mtq_id := upper_transaction_id;
6855 end if; -- }
6856 end if; -- }
6857 end if; --}
6858 end if; -- }
6859 end loop; -- }
6860 if ( p_node_type = RES_NODE ) then
6861 close upper_bound;
6862 else
6863 close upper_bound_res_inst;
6864 end if;
6865
6866 if v_lower_start is not null and p_start_date < v_lower_start then -- {
6867 --p_out := to_char(v_lower_start,format_mask) || field_seperator|| to_char(v_lower_start_id);
6868 --5728088, send translated message to pld
6869 fnd_message.set_name('MSC', 'MSC_GC_START_DT_LT_CONS_DATE');
6870 fnd_message.set_token('DATE1', to_char(v_lower_start,format_mask));
6871 fnd_message.set_token('TRX_ID', to_char(v_lower_start_id));
6872 p_out := fnd_message.get;
6873 p_return_status := 'ERROR';
6874 else
6875 p_out := null_space || field_seperator || null_space;
6876 end if; -- }
6877
6878 if v_upper_start is not null and p_start_date > v_upper_start then -- {
6879 p_out := p_out || field_seperator || to_char(v_upper_start,format_mask)
6880 || field_seperator || to_char(v_upper_start_id);
6881 p_return_status := 'ERROR';
6882 else
6883 p_out := p_out || field_seperator || null_space || field_seperator || null_space;
6884 end if; -- }
6885 if p_return_status = 'ERROR' then -- {
6886 p_out := p_out || field_seperator || null_space || field_seperator || null_space;
6887 p_out := p_out || field_seperator || null_space || field_seperator || null_space;
6888 return;
6889 end if; -- }
6890
6891 if v_lower_end is not null and p_end_date < v_lower_end then -- {
6892 --p_out := p_out || field_seperator|| to_char(v_lower_end,format_mask)|| field_seperator || to_char(v_lower_end_id);
6893 --5728088, send translated message to pld
6894 fnd_message.set_name('MSC', 'MSC_GC_END_DT_LT_CONS_DATE');
6895 fnd_message.set_token('DATE1', to_char(v_lower_end,format_mask));
6896 fnd_message.set_token('TRX_ID', to_char(v_lower_end_id));
6897 p_out := fnd_message.get;
6898 p_return_status := 'ERROR';
6899 end if; -- }
6900
6901 if v_upper_end is not null and p_end_date > v_upper_end then -- {
6902 --p_out := p_out || field_seperator || to_char(v_upper_end,format_mask)|| field_seperator || to_char(v_upper_end_id);
6903 --5728088, send translated message to pld
6904 fnd_message.set_name('MSC', 'MSC_GC_END_DT_LT_CONS_DATE');
6905 fnd_message.set_token('DATE1', to_char(v_upper_end,format_mask));
6906 fnd_message.set_token('TRX_ID', to_char(v_lower_end_id));
6907 p_out := fnd_message.get;
6908 p_return_status := 'ERROR';
6909 end if; -- }
6910
6911 if p_return_status = 'ERROR' then -- {
6912 return;
6913 end if; -- }
6914
6915 if v_lower_mtq_id is not null or v_upper_mtq_id is not null then -- {
6916 --p_return_status := 'WARNING';
6917 --p_out := nvl(to_char(v_lower_mtq_id), null_space) ||field_seperator || nvl(to_char(v_upper_mtq_id), null_space);
6918 --5728088 commented, since we dont need to show warnings
6919 return;
6920 end if; -- }
6921 end validateTime;
6922
6923 -- public API
6924 -- 1) if a res is firmed, firm the resource, firm the simu res, and firm ALL the res instances
6925 -- 2) if a res inst is firmed, firm the res inst and firm the res also..
6926
6927 procedure firmResourcePub (p_plan_id number, p_transaction_id number,
6928 p_instance_id number, p_firm_type number, p_return_status OUT NOCOPY varchar2,
6929 p_out OUT NOCOPY varchar2, p_node_type number) is
6930
6931 l_firm_type number;
6932 l_supply_id number;
6933 l_firm_start date;
6934 l_firm_end date;
6935 l_start date;
6936 l_end date;
6937
6938 ll_res_inst_trx_id number;
6939 ll_res_trx_id number;
6940
6941 vv_res_inst_inst_id number_arr;
6942 vv_res_inst_trx_id number_arr;
6943
6944 BEGIN
6945 put_line(' firmResourcePub in ');
6946 p_return_status := 'OK';
6947
6948 --firm the res instance..
6949 if ( p_node_type = RES_INST_NODE ) then -- {
6950 ll_res_inst_trx_id := p_transaction_id;
6951 ll_res_trx_id := get_parent_res_trx_id(p_plan_id, p_instance_id, ll_res_inst_trx_id);
6952 else
6953 ll_res_trx_id := p_transaction_id;
6954 end if; -- }
6955 put_line('ll_res_trx_id ll_res_inst_trx_id '||ll_res_trx_id||' - '||ll_res_inst_trx_id);
6956
6957 -- lock the mrr and getData
6958 msc_gantt_utils.lockReqNGetData(p_plan_id, p_instance_id, ll_res_trx_id,
6959 l_firm_type, l_supply_id, l_start, l_end, l_firm_start, l_firm_end,
6960 p_return_status, p_out);
6961
6962 if p_return_status = 'ERROR' then
6963 return ;
6964 end if;
6965
6966
6967 -- update requirement
6968 msc_gantt_utils.updateReq(p_plan_id, p_instance_id, ll_res_trx_id,
6969 p_firm_type, l_start, l_end, l_firm_start, l_firm_end, FIRM_MRR);
6970
6971 -- update requirement
6972 msc_gantt_utils.firmReqInst(p_plan_id, p_instance_id, ll_res_trx_id, ll_res_inst_trx_id);
6973
6974 -- update requirement's supply
6975 msc_gantt_utils.updateSupplies(p_plan_id, l_supply_id, TOUCH_SUPPLY);
6976
6977 -- update the simultaneous resource for a given res trans id
6978 msc_gantt_utils.updateReqSimu(p_plan_id, p_instance_id, ll_res_trx_id,
6979 p_firm_type, l_start, l_end, l_firm_start, l_firm_end, FIRM_MRR, p_return_status, p_out);
6980
6981 put_line(' firmResourcePub out ');
6982 end firmResourcePub;
6983
6984 procedure firmResourceSeqPub(p_plan_id number,
6985 p_trx_list varchar2, p_firm_type number,
6986 p_return_status OUT NOCOPY varchar2,
6987 p_out OUT NOCOPY varchar2,
6988 p_node_type number) is
6989
6990 l_start date;
6991 l_end date;
6992 l_supply_id number;
6993 l_firm_type number;
6994 l_firm_start date;
6995 l_firm_end date;
6996 l_batch_number number;
6997 l_group_sequence_id number;
6998 l_group_sequence_number number;
6999
7000 l_inst_id number;
7001 l_trx_id number;
7002 ll_res_trx_id number;
7003
7004 p_new_group_seq_id number;
7005 p_new_group_seq_number number;
7006
7007 v_len number;
7008 i number := 1;
7009 l_one_record varchar2(100);
7010
7011 begin
7012 put_line(' firmResourceSeqPub in ');
7013 p_return_status := 'OK';
7014
7015 v_len := length(p_trx_list);
7016 while v_len > 1 loop
7017 l_one_record := substr(p_trx_list,instr(p_trx_list,'(',1,i)+1,
7018 instr(p_trx_list,')',1,i)-instr(p_trx_list,'(',1,i)-1);
7019 l_inst_id := to_number(substr(l_one_record,1,instr(l_one_record,',')-1));
7020 l_trx_id := to_number(substr(l_one_record,instr(l_one_record,',')+1));
7021 ll_res_trx_id := l_trx_id;
7022
7023
7024 if ( p_node_type = RES_INST_NODE ) then -- {
7025 ll_res_trx_id := get_parent_res_trx_id(p_plan_id, l_inst_id, l_trx_id);
7026 end if; -- }
7027
7028 if ( p_new_group_seq_id is null ) then
7029 -- get the new group seq id and number
7030 select max(nvl(mrr.group_sequence_id,0))+1
7031 into p_new_group_seq_id
7032 from msc_resource_requirements mrr
7033 where mrr.plan_id = p_plan_id
7034 and mrr.sr_instance_id = l_inst_id;
7035 p_new_group_seq_number := 0;
7036 end if;
7037 p_new_group_seq_number := p_new_group_seq_number + 10;
7038
7039 -- lock the mrr and getNewData
7040 msc_gantt_utils.lockReqNGetData(p_plan_id, l_inst_id, ll_res_trx_id,
7041 l_firm_type, l_supply_id, l_start, l_end, l_firm_start, l_firm_end,
7042 p_return_status, p_out);
7043
7044 update msc_resource_requirements
7045 set group_sequence_id = decode(p_firm_type,
7046 0, to_number(null),
7047 p_new_group_seq_id),
7048 group_sequence_number = decode(p_firm_type,
7049 0, to_number(null),
7050 p_new_group_seq_number)
7051 where plan_id = p_plan_id
7052 and sr_instance_id = l_inst_id
7053 and transaction_id = ll_res_trx_id ;
7054
7055 if ( p_out is null ) then
7056 p_out := '('|| l_inst_id || COMMA_SEPARATOR
7057 || l_trx_id || COMMA_SEPARATOR
7058 || p_new_group_seq_id || COMMA_SEPARATOR
7059 || p_new_group_seq_number ||')';
7060 else
7061 p_out := p_out || COMMA_SEPARATOR ||
7062 '('||l_inst_id || COMMA_SEPARATOR
7063 || l_trx_id || COMMA_SEPARATOR
7064 || p_new_group_seq_id || COMMA_SEPARATOR
7065 || p_new_group_seq_number || ')';
7066 end if;
7067
7068 i := i+1;
7069 v_len := v_len - length(l_one_record)-3;
7070 end loop;
7071
7072 put_line(' firmResourceSeqPub out ');
7073 end firmResourceSeqPub;
7074
7075 procedure firmResourceBatchPub(p_plan_id number,
7076 p_transaction_id number, p_instance_id number, p_firm_type number,
7077 p_return_status OUT NOCOPY varchar2,
7078 p_out OUT NOCOPY varchar2,
7079 p_node_type number) is
7080
7081 l_start date;
7082 l_end date;
7083 l_supply_id number;
7084 l_firm_type number;
7085 l_firm_start date;
7086 l_firm_end date;
7087 l_batch_number number;
7088 l_group_sequence_id number;
7089 l_group_sequence_number number;
7090
7091 begin
7092 if ( p_node_type = RES_NODE ) then -- {
7093 -- in both the cases, res or res inst move, move the simultaneous res req
7094 open res_req_info(p_plan_id, p_instance_id, p_transaction_id);
7095 fetch res_req_info into l_firm_type, l_firm_start, l_firm_end,
7096 l_batch_number, l_group_sequence_id, l_group_sequence_number;
7097 close res_req_info;
7098
7099 msc_gantt_utils.updateBatchReq(p_plan_id, p_instance_id, l_batch_number,
7100 to_date(null), to_date(null), p_firm_type, FIRM_MRR, p_return_status, p_out);
7101 else
7102 open res_inst_req_info(p_plan_id, p_instance_id, p_instance_id);
7103 fetch res_inst_req_info into l_batch_number;
7104 close res_inst_req_info;
7105
7106 msc_gantt_utils.updateBatchInstReq(p_plan_id, p_instance_id, l_batch_number,
7107 to_date(null), to_date(null), p_firm_type, FIRM_MRR, p_return_status, p_out);
7108 end if; -- }
7109 end firmResourceBatchPub;
7110
7111
7112 procedure firmSupplyPub(p_plan_id number,
7113 p_transaction_id number, p_instance_id number,
7114 p_firm_type number,
7115 p_start_date date, p_end_date date,
7116 p_plan_start_date date, p_plan_end_date date,
7117 p_return_status OUT NOCOPY varchar2,
7118 p_out OUT NOCOPY varchar2,
7119 p_validate_flag boolean default true,
7120 p_node_type number) is
7121
7122 begin
7123 p_return_status := 'OK';
7124
7125 -- update requirement's supply
7126 msc_gantt_utils.updateSupplies(p_plan_id, p_transaction_id, FIRM_SUPPLY, p_firm_type);
7127
7128 --pabram ... need to verify
7129 end firmSupplyPub;
7130
7131 procedure getAltResource(p_plan_id number,
7132 p_transaction_id number, p_instance_id number,
7133 p_name OUT NOCOPY varchar2, p_id OUT NOCOPY varchar2,
7134 p_node_type number default null,
7135 p_from_form number default null) is
7136
7137 cursor c_alt_res_res (p_plan number, p_inst number, p_trx number)is
7138 select distinct mor.alternate_number || COLON_SEPARATOR ||
7139 msc_get_name.resource_code(mor.resource_id, mrr.department_id,
7140 mrr.organization_id, mrr.plan_id, mrr.sr_instance_id),
7141 mor.resource_id,
7142 mbp_null_value res_instance_id,
7143 mbp_null_value_char serial_number,
7144 mor.alternate_number
7145 from msc_operation_resources mor,
7146 msc_resource_requirements mrr
7147 where mrr.plan_id = p_plan
7148 and mrr.sr_instance_id = p_inst
7149 and mrr.transaction_id = p_trx
7150 and mor.plan_id = mrr.plan_id
7151 and mor.routing_sequence_id = mrr.routing_sequence_id
7152 and mor.sr_instance_id = mrr.sr_instance_id
7153 and mor.operation_sequence_id = mrr.operation_sequence_id
7154 and mor.resource_seq_num = mrr.resource_seq_num
7155 and mor.alternate_number <> mrr.alternate_num
7156 and mor.principal_flag <> 2
7157 union all --5478582 bugfix
7158 select distinct mjor.alternate_num || COLON_SEPARATOR ||
7159 msc_get_name.resource_code(mjor.resource_id, mrr.department_id,
7160 mrr.organization_id, mrr.plan_id, mrr.sr_instance_id),
7161 mjor.resource_id,
7162 mbp_null_value res_instance_id,
7163 mbp_null_value_char serial_number,
7164 mjor.alternate_num
7165 from msc_job_op_resources mjor,
7166 msc_resource_requirements mrr
7167 where mrr.plan_id = p_plan
7168 and mrr.sr_instance_id = p_inst
7169 and mrr.transaction_id = p_trx
7170 and mrr.routing_sequence_id is null
7171 and mjor.plan_id = mrr.plan_id
7172 and mjor.transaction_id = mrr.supply_id
7173 and mjor.sr_instance_id = mrr.sr_instance_id
7174 and mjor.operation_seq_num = mrr.operation_seq_num
7175 and mjor.resource_seq_num = mrr.resource_seq_num
7176 and mjor.alternate_num <> mrr.alternate_num
7177 and mjor.resource_id <> -1
7178 and mjor.principal_flag <> 2;
7179
7180 cursor c_alt_res_inst (p_plan number, p_inst number, p_trx number)is
7181 select distinct mor.alternate_number
7182 || COLON_SEPARATOR || msc_gantt_utils.getDeptResInstCode(mdri.plan_id,
7183 mdri.sr_instance_id, mdri.organization_id, mdri.department_id,
7184 mdri.resource_id, mdri.res_instance_id, mdri.serial_number),
7185 mdri.resource_id,
7186 mdri.res_instance_id,
7187 mdri.serial_number,
7188 mor.alternate_number
7189 from msc_operation_resources mor,
7190 msc_resource_requirements mrr,
7191 msc_dept_res_instances mdri
7192 where mrr.plan_id = p_plan
7193 and mrr.sr_instance_id = p_inst
7194 and mrr.transaction_id = p_trx
7195 and mrr.assigned_units = 1
7196 and mor.plan_id = mrr.plan_id
7197 and mor.routing_sequence_id = mrr.routing_sequence_id
7198 and mor.sr_instance_id = mrr.sr_instance_id
7199 and mor.operation_sequence_id = mrr.operation_sequence_id
7200 and mor.resource_seq_num = mrr.resource_seq_num
7201 and mor.alternate_number <> mrr.alternate_num
7202 and mor.principal_flag <> 2
7203 and mor.plan_id = mdri.plan_id
7204 and mor.sr_instance_id = mdri.sr_instance_id
7205 and mor.resource_id = mdri.resource_id
7206 union all --5478582 bugfix
7207 select distinct mjor.alternate_num
7208 || COLON_SEPARATOR || msc_gantt_utils.getDeptResInstCode(mdri.plan_id,
7209 mdri.sr_instance_id, mdri.organization_id, mdri.department_id,
7210 mdri.resource_id, mdri.res_instance_id, mdri.serial_number),
7211 mdri.resource_id,
7212 mdri.res_instance_id,
7213 mdri.serial_number,
7214 mjor.alternate_num
7215 from msc_job_op_resources mjor,
7216 msc_resource_requirements mrr,
7217 msc_dept_res_instances mdri
7218 where mrr.plan_id = p_plan
7219 and mrr.sr_instance_id = p_inst
7220 and mrr.transaction_id = p_trx
7221 and mrr.routing_sequence_id is null
7222 and mrr.assigned_units = 1
7223 and mjor.plan_id = mrr.plan_id
7224 and mjor.transaction_id = mrr.supply_id
7225 and mjor.sr_instance_id = mrr.sr_instance_id
7226 and mjor.operation_seq_num = mrr.operation_seq_num
7227 and mjor.resource_seq_num = mrr.resource_seq_num
7228 and mjor.alternate_num <> mrr.alternate_num
7229 and mjor.resource_id <> -1
7230 and mjor.principal_flag <> 2
7231 and mjor.plan_id = mdri.plan_id
7232 and mjor.sr_instance_id = mdri.sr_instance_id
7233 and mjor.resource_id = mdri.resource_id;
7234
7235
7236 cursor c_alt_inst_res (p_plan number, p_inst number, p_trx number)is
7237 select distinct mor.alternate_number
7238 || COLON_SEPARATOR ||msc_get_name.resource_code(mor.resource_id, mrr.department_id,
7239 mrr.organization_id, mrr.plan_id, mrr.sr_instance_id),
7240 mor.resource_id,
7241 mbp_null_value res_instance_id,
7242 mbp_null_value_char serial_number,
7243 mor.alternate_number
7244 from msc_operation_resources mor,
7245 msc_resource_requirements mrr
7246 where mrr.plan_id = p_plan
7247 and mrr.sr_instance_id = p_inst
7248 and mrr.transaction_id = p_trx
7249 and mor.plan_id = mrr.plan_id
7250 and mor.routing_sequence_id = mrr.routing_sequence_id
7251 and mor.sr_instance_id = mrr.sr_instance_id
7252 and mor.operation_sequence_id = mrr.operation_sequence_id
7253 and mor.resource_seq_num = mrr.resource_seq_num
7254 and mor.alternate_number <> mrr.alternate_num
7255 and mor.principal_flag <> 2
7256 union all --5478582 bugfix
7257 select distinct mjor.alternate_num
7258 || COLON_SEPARATOR ||msc_get_name.resource_code(mjor.resource_id, mrr.department_id,
7259 mrr.organization_id, mrr.plan_id, mrr.sr_instance_id),
7260 mjor.resource_id,
7261 mbp_null_value res_instance_id,
7262 mbp_null_value_char serial_number,
7263 mjor.alternate_num
7264 from msc_job_op_resources mjor,
7265 msc_resource_requirements mrr
7266 where mrr.plan_id = p_plan
7267 and mrr.sr_instance_id = p_inst
7268 and mrr.transaction_id = p_trx
7269 and mrr.routing_sequence_id is null
7270 and mjor.plan_id = mrr.plan_id
7271 and mjor.transaction_id = mrr.supply_id
7272 and mjor.sr_instance_id = mrr.sr_instance_id
7273 and mjor.operation_seq_num = mrr.operation_seq_num
7274 and mjor.resource_seq_num = mrr.resource_seq_num
7275 and mjor.alternate_num <> mrr.alternate_num
7276 and mjor.resource_id <> -1
7277 and mjor.principal_flag <> 2;
7278
7279 cursor c_alt_inst_inst (p_plan number, p_inst number, p_trx number,
7280 p_res_instance_id number, p_serial_number varchar2, p_equipment_item_id number )is
7281 select distinct mor.alternate_number ||':'||msc_gantt_utils.getDeptResInstCode(mdri.plan_id,
7282 mdri.sr_instance_id, mdri.organization_id, mdri.department_id,
7283 mdri.resource_id, mdri.res_instance_id, mdri.serial_number),
7284 mdri.resource_id,
7285 mdri.res_instance_id,
7286 mdri.serial_number,
7287 mor.alternate_number
7288 from msc_operation_resources mor,
7289 msc_resource_requirements mrr,
7290 msc_dept_res_instances mdri
7291 where mrr.plan_id = p_plan
7292 and mrr.sr_instance_id = p_inst
7293 and mrr.transaction_id = p_trx
7294 and mor.plan_id = mrr.plan_id
7295 and mor.routing_sequence_id = mrr.routing_sequence_id
7296 and mor.sr_instance_id = mrr.sr_instance_id
7297 and mor.operation_sequence_id = mrr.operation_sequence_id
7298 and mor.resource_seq_num = mrr.resource_seq_num
7299 and mor.alternate_number <> mrr.alternate_num
7300 and mor.principal_flag <> 2
7301 and mor.plan_id = mdri.plan_id
7302 and mor.sr_instance_id = mdri.sr_instance_id
7303 and mor.resource_id = mdri.resource_id
7304 union all --5513960 bugfix
7305 select distinct mrr.alternate_num ||':'||msc_gantt_utils.getDeptResInstCode(mdri.plan_id,
7306 mdri.sr_instance_id, mdri.organization_id, mdri.department_id,
7307 mdri.resource_id, mdri.res_instance_id, mdri.serial_number),
7308 mdri.resource_id,
7309 mdri.res_instance_id,
7310 mdri.serial_number,
7311 mrr.alternate_num
7312 from msc_resource_requirements mrr,
7313 msc_dept_res_instances mdri
7314 where mrr.plan_id = p_plan
7315 and mrr.sr_instance_id = p_inst
7316 and mrr.transaction_id = p_trx
7317 and mrr.plan_id = mdri.plan_id
7318 and mrr.sr_instance_id = mdri.sr_instance_id
7319 and mrr.organization_id = mdri.organization_id
7320 and mrr.department_id = mdri.department_id
7321 and mrr.resource_id = mdri.resource_id
7322 and nvl(mdri.serial_number,mbp_null_value_char) <> nvl(p_serial_number,mbp_null_value_char)
7323 --and nvl(mdri.equipment_item_id,mbp_null_value) <> nvl(p_equipment_item_id,mbp_null_value)
7324 union all --5478582 bugfix
7325 select distinct mjor.alternate_num ||':'||msc_gantt_utils.getDeptResInstCode(mdri.plan_id,
7326 mdri.sr_instance_id, mdri.organization_id, mdri.department_id,
7327 mdri.resource_id, mdri.res_instance_id, mdri.serial_number),
7328 mdri.resource_id,
7329 mdri.res_instance_id,
7330 mdri.serial_number,
7331 mjor.alternate_num
7332 from msc_job_op_resources mjor,
7333 msc_resource_requirements mrr,
7334 msc_dept_res_instances mdri
7335 where mrr.plan_id = p_plan
7336 and mrr.sr_instance_id = p_inst
7337 and mrr.transaction_id = p_trx
7338 and mrr.routing_sequence_id is null
7339 and mjor.plan_id = mrr.plan_id
7340 and mjor.transaction_id = mrr.supply_id
7341 and mjor.sr_instance_id = mrr.sr_instance_id
7342 and mjor.operation_seq_num = mrr.operation_seq_num
7343 and mjor.resource_seq_num = mrr.resource_seq_num
7344 and mjor.alternate_num <> mrr.alternate_num
7345 and mjor.resource_id <> -1
7346 and mjor.principal_flag <> 2
7347 and mjor.plan_id = mdri.plan_id
7348 and mjor.sr_instance_id = mdri.sr_instance_id
7349 and mjor.resource_id = mdri.resource_id;
7350
7351 cursor flag (p_plan number, p_inst number, p_trx number)is
7352 select nvl(mrr.firm_flag,no_firm)
7353 from msc_resource_requirements mrr
7354 where mrr.plan_id = p_plan
7355 and mrr.transaction_id = p_trx
7356 and mrr.sr_instance_id = p_inst;
7357
7358 cursor activity_c (p_plan number, p_inst number, p_trx number) is
7359 select mors.activity_group_id, mrr.routing_sequence_id,
7360 mrr.operation_sequence_id, mrr.resource_seq_num
7361 from msc_operation_resource_seqs mors,
7362 msc_resource_requirements mrr
7363 where mrr.plan_id = p_plan
7364 and mrr.transaction_id = p_trx
7365 and mrr.sr_instance_id = p_inst
7366 and mors.plan_id = mrr.plan_id
7367 and mors.routing_sequence_id = mrr.routing_sequence_id
7368 and mors.operation_sequence_id = mrr.operation_sequence_id
7369 and mors.resource_seq_num = mrr.resource_seq_num
7370 and mors.sr_instance_id = mrr.sr_instance_id;
7371
7372 --5513960 bugfix
7373 cursor c_res_inst_info (p_plan number, p_inst number, p_trx number)is
7374 select mrir.res_instance_id, mrir.serial_number, mrir.equipment_item_id
7375 from msc_resource_instance_reqs mrir
7376 where mrir.plan_id = p_plan
7377 and mrir.sr_instance_id = p_inst
7378 and mrir.res_inst_transaction_id = p_trx;
7379
7380 ll_res_instance_id number;
7381 ll_serial_number varchar2(30);
7382 ll_equipment_item_id number;
7383 --5513960 bugfix ends
7384
7385 temp_name varchar2(240);
7386 temp_id number;
7387 temp_inst_id number;
7388 temp_serial_number varchar2(40);
7389 temp_flag number;
7390 alt_number number;
7391 rowcount number := 0;
7392 l_rout_seq number;
7393 l_op_seq number;
7394 l_res_seq number;
7395 l_total_seqs number;
7396 l_avail_seqs number;
7397 l_act_group number;
7398 l_flag varchar2(5);
7399
7400 ll_res_inst_trx_id number;
7401 ll_res_trx_id number;
7402
7403 l_query_id number;
7404
7405 begin
7406 put_line('in getAltResource');
7407 --firm the res instance..
7408 if ( p_node_type = RES_INST_NODE ) then -- {
7409 ll_res_inst_trx_id := p_transaction_id;
7410 ll_res_trx_id := get_parent_res_trx_id(p_plan_id, p_instance_id, ll_res_inst_trx_id);
7411
7412 --5513960 bugfix
7413 open c_res_inst_info (p_plan_id, p_instance_id, ll_res_inst_trx_id);
7414 fetch c_res_inst_info into ll_res_instance_id, ll_serial_number, ll_equipment_item_id;
7415 close c_res_inst_info;
7416 --5513960 bugfix ends
7417
7418 else
7419 ll_res_trx_id := p_transaction_id;
7420 end if; -- }
7421
7422 if ( nvl(p_from_form,-1) = sys_yes ) then
7423 l_query_id := getMFQSequence();
7424 else
7425 l_query_id := mbp_null_value;
7426 end if;
7427
7428 --get corresponding info about this tranx
7429 open activity_c(p_plan_id, p_instance_id, ll_res_trx_id);
7430 fetch activity_c into l_act_group,l_rout_seq, l_op_seq, l_res_seq;
7431 close activity_c;
7432
7433 /*
7434 if l_act_group is not null then -- {
7435 select count(*)
7436 into l_total_seqs
7437 from (select distinct mors.resource_seq_num
7438 from msc_operation_resource_seqs mors
7439 where mors.plan_id = p_plan_id
7440 and mors.routing_sequence_id = l_rout_seq
7441 and mors.operation_sequence_id = l_op_seq
7442 and mors.sr_instance_id = p_instance_id
7443 and mors.activity_group_id = l_act_group);
7444
7445 select count(*)
7446 into l_avail_seqs
7447 from (select distinct mors.resource_seq_num
7448 from msc_operation_resource_seqs mors,
7449 msc_operation_resources mor
7450 where mors.plan_id = p_plan_id
7451 and mors.sr_instance_id = p_instance_id
7452 and mors.operation_sequence_id = l_op_seq
7453 and mors.routing_sequence_id = l_rout_seq
7454 and mors.activity_group_id = l_act_group
7455 and mor.plan_id = p_plan_id
7456 and mor.routing_sequence_id = mors.routing_sequence_id
7457 and mor.operation_sequence_id = mors.operation_sequence_id
7458 and mor.sr_instance_id = p_instance_id
7459 and mor.resource_seq_num = mors.resource_seq_num
7460 and mor.alternate_number = alt_number);
7461
7462 if l_avail_seqs = l_total_seqs then -- {
7463 l_flag := 'Y';
7464 else
7465 l_flag := 'N';
7466 end if; -- }
7467
7468 else
7469 l_flag := 'Y';
7470 end if; -- }
7471
7472 */
7473 l_flag := 'Y'; -- pabram need to check with emily the commented code , and this stmt
7474
7475 if ( nvl(p_node_type, RES_NODE) = RES_NODE ) then -- {
7476
7477 put_line(' finding alternates for a resource node ');
7478 -- res to res
7479 open c_alt_res_res(p_plan_id, p_instance_id, ll_res_trx_id);
7480 loop -- {
7481 fetch c_alt_res_res into temp_name, temp_id, temp_inst_id, temp_serial_number, alt_number;
7482 exit when c_alt_res_res%notfound;
7483 rowcount := rowcount +1;
7484 put_line(' c_alt_res_res '|| temp_name );
7485 if p_name is not null then -- {
7486 p_name := p_name || field_seperator || temp_name;
7487 p_id := p_id || field_seperator || temp_id || field_seperator
7488 || temp_inst_id || field_seperator || temp_serial_number
7489 || field_seperator || alt_number || field_seperator || l_flag;
7490 else
7491 p_name := temp_name;
7492 p_id := temp_id || field_seperator || temp_inst_id || field_seperator
7493 || temp_serial_number|| field_seperator || alt_number || field_seperator || l_flag;
7494 end if; -- }
7495
7496 if ( l_query_id <> mbp_null_value ) then
7497 populateResIntoMfq(l_query_id, temp_id, temp_inst_id, temp_serial_number, temp_name, alt_number);
7498 end if;
7499
7500 end loop; -- }
7501 close c_alt_res_res;
7502
7503 -- res to res inst
7504 open c_alt_res_inst(p_plan_id, p_instance_id, ll_res_trx_id);
7505 loop -- {
7506 fetch c_alt_res_inst into temp_name, temp_id, temp_inst_id, temp_serial_number, alt_number;
7507 exit when c_alt_res_inst%notfound;
7508 rowcount := rowcount +1;
7509 put_line(' c_alt_res_inst '|| temp_name );
7510 if p_name is not null then -- {
7511 p_name := p_name || field_seperator || temp_name;
7512 p_id := p_id || field_seperator || temp_id || field_seperator
7513 || temp_inst_id || field_seperator || temp_serial_number
7514 || field_seperator || alt_number || field_seperator || l_flag;
7515 else
7516 p_name := temp_name;
7517 p_id := temp_id || field_seperator || temp_inst_id || field_seperator
7518 || temp_serial_number|| field_seperator || alt_number || field_seperator || l_flag;
7519 end if; -- }
7520
7521 if ( l_query_id <> mbp_null_value ) then
7522 populateResIntoMfq(l_query_id, temp_id, temp_inst_id, temp_serial_number, temp_name, alt_number);
7523 end if;
7524
7525 end loop; -- }
7526 close c_alt_res_inst;
7527
7528 else
7529 put_line(' finding alternates for a resource instance node ');
7530 -- inst to res
7531 open c_alt_inst_res(p_plan_id, p_instance_id, ll_res_trx_id);
7532 loop -- {
7533 fetch c_alt_inst_res into temp_name, temp_id, temp_inst_id, temp_serial_number, alt_number;
7534 exit when c_alt_inst_res%notfound;
7535 rowcount := rowcount +1;
7536 put_line(' c_alt_inst_res '|| temp_name );
7537 if p_name is not null then -- {
7538 p_name := p_name || field_seperator || temp_name;
7539 p_id := p_id || field_seperator || temp_id || field_seperator
7540 || temp_inst_id || field_seperator || temp_serial_number
7541 || field_seperator || alt_number || field_seperator || l_flag;
7542 else
7543 p_name := temp_name;
7544 p_id := temp_id || field_seperator || temp_inst_id || field_seperator
7545 || temp_serial_number|| field_seperator || alt_number || field_seperator || l_flag;
7546 end if; -- }
7547
7548 if ( l_query_id <> mbp_null_value ) then
7549 populateResIntoMfq(l_query_id, temp_id, temp_inst_id, temp_serial_number, temp_name, alt_number);
7550 end if;
7551
7552 end loop; -- }
7553 close c_alt_inst_res;
7554
7555 -- inst to inst
7556 open c_alt_inst_inst(p_plan_id, p_instance_id, ll_res_trx_id,
7557 ll_res_instance_id, ll_serial_number, ll_equipment_item_id);
7558 loop -- {
7559 fetch c_alt_inst_inst into temp_name, temp_id, temp_inst_id, temp_serial_number, alt_number;
7560 exit when c_alt_inst_inst%notfound;
7561 rowcount := rowcount +1;
7562 put_line(' c_alt_inst_inst '|| temp_name );
7563 if p_name is not null then -- {
7564 p_name := p_name || field_seperator || temp_name;
7565 p_id := p_id || field_seperator || temp_id || field_seperator
7566 || temp_inst_id || field_seperator || temp_serial_number
7567 || field_seperator || alt_number || field_seperator || l_flag;
7568 else
7569 p_name := temp_name;
7570 p_id := temp_id || field_seperator || temp_inst_id || field_seperator
7571 || temp_serial_number|| field_seperator || alt_number || field_seperator || l_flag;
7572 end if; -- }
7573
7574 if ( l_query_id <> mbp_null_value ) then
7575 populateResIntoMfq(l_query_id, temp_id, temp_inst_id, temp_serial_number, temp_name, alt_number);
7576 end if;
7577
7578 end loop; -- }
7579 close c_alt_inst_inst;
7580
7581 end if; -- }
7582
7583 temp_flag := 0;
7584 open flag(p_plan_id, p_instance_id, ll_res_trx_id);
7585 fetch flag into temp_flag;
7586 close flag;
7587
7588 if temp_flag >= 8 then
7589 temp_flag := 0;
7590 end if;
7591
7592 p_name := temp_flag || field_seperator ||to_char(rowcount) || field_seperator || p_name;
7593 p_id := to_char(rowcount) || field_seperator || p_id;
7594
7595 if ( l_query_id <> mbp_null_value ) then
7596 p_id := l_query_id;
7597 end if;
7598
7599 put_line('out getAltResource');
7600 end getAltResource;
7601
7602 procedure getSimuResource(p_plan_id number,
7603 p_transaction_id number, p_instance_id number,
7604 p_name OUT NOCOPY varchar2, p_id OUT NOCOPY varchar2,
7605 p_node_type number default null) IS
7606
7607 cursor c_simu_res_res(p_plan_id number, p_inst_id number, p_trx_id number ) is
7608 select msc_get_name.resource_code(mor.resource_id, mrr.department_id,
7609 mrr.organization_id, mrr.plan_id, mrr.sr_instance_id) resource_code,
7610 mor.resource_id resource_id,
7611 mbp_null_value res_instance_id,
7612 mbp_null_value_char serial_number
7613 from msc_operation_resources mor,
7614 msc_resource_requirements mrr
7615 where mrr.plan_id = p_plan_id
7616 and mrr.transaction_id = p_trx_id
7617 and mrr.sr_instance_id = p_inst_id
7618 and mor.plan_id = mrr.plan_id
7619 and mor.sr_instance_id = mrr.sr_instance_id
7620 and mor.routing_sequence_id = mrr.routing_sequence_id
7621 and mor.operation_sequence_id = mrr.operation_sequence_id
7622 and mor.resource_seq_num = mrr.resource_seq_num
7623 and mor.alternate_number = mrr.alternate_num
7624 and mor.resource_id <> mrr.resource_id;
7625
7626 cursor c_simu_res_inst(p_plan number, p_inst number, p_trx number)is
7627 select mor.alternate_number ||':'||msc_gantt_utils.getDeptResInstCode(mdri.plan_id,
7628 mdri.sr_instance_id, mdri.organization_id, mdri.department_id,
7629 mdri.resource_id, mdri.res_instance_id, mdri.serial_number) resource_code,
7630 mdri.resource_id,
7631 mdri.res_instance_id,
7632 mdri.serial_number
7633 from msc_operation_resources mor,
7634 msc_resource_requirements mrr,
7635 msc_dept_res_instances mdri
7636 where mrr.plan_id = p_plan
7637 and mrr.sr_instance_id = p_inst
7638 and mrr.transaction_id = p_trx
7639 and mor.plan_id = mrr.plan_id
7640 and mor.sr_instance_id = mrr.sr_instance_id
7641 and mor.routing_sequence_id = mrr.routing_sequence_id
7642 and mor.operation_sequence_id = mrr.operation_sequence_id
7643 and mor.resource_seq_num = mrr.resource_seq_num
7644 and mor.alternate_number = mrr.alternate_num
7645 and mor.resource_id <> mrr.resource_id
7646 and mor.plan_id = mdri.plan_id
7647 and mor.sr_instance_id = mdri.sr_instance_id
7648 and mor.resource_id = mdri.resource_id;
7649
7650 cursor c_simu_inst_res (p_plan number, p_inst number, p_trx number)is
7651 select mor.alternate_number ||':'||msc_get_name.resource_code(mor.resource_id, mrr.department_id,
7652 mrr.organization_id, mrr.plan_id, mrr.sr_instance_id) resource_code,
7653 mor.resource_id,
7654 mbp_null_value res_instance_id,
7655 mbp_null_value_char serial_number
7656 from msc_operation_resources mor,
7657 msc_resource_requirements mrr
7658 where mrr.plan_id = p_plan
7659 and mrr.sr_instance_id = p_inst
7660 and mrr.transaction_id = p_trx
7661 and mor.plan_id = mrr.plan_id
7662 and mor.sr_instance_id = mrr.sr_instance_id
7663 and mor.routing_sequence_id = mrr.routing_sequence_id
7664 and mor.operation_sequence_id = mrr.operation_sequence_id
7665 and mor.resource_seq_num = mrr.resource_seq_num
7666 and mor.alternate_number = mrr.alternate_num
7667 and mor.resource_id <> mrr.resource_id;
7668
7669 cursor c_simu_inst_inst (p_plan number, p_inst number, p_trx number)is
7670 select mor.alternate_number ||':'||msc_gantt_utils.getDeptResInstCode(mdri.plan_id,
7671 mdri.sr_instance_id, mdri.organization_id,
7672 mdri.department_id, mdri.resource_id, mdri.res_instance_id, mdri.serial_number) resource_code,
7673 mdri.resource_id,
7674 mdri.res_instance_id,
7675 mdri.serial_number
7676 from msc_operation_resources mor,
7677 msc_resource_requirements mrr,
7678 msc_dept_res_instances mdri
7679 where mrr.plan_id = p_plan
7680 and mrr.sr_instance_id = p_inst
7681 and mrr.transaction_id = p_trx
7682 and mor.plan_id = mrr.plan_id
7683 and mor.routing_sequence_id = mrr.routing_sequence_id
7684 and mor.sr_instance_id = mrr.sr_instance_id
7685 and mor.operation_sequence_id = mrr.operation_sequence_id
7686 and mor.resource_seq_num = mrr.resource_seq_num
7687 and mor.alternate_number = mrr.alternate_num
7688 and mor.resource_id <> mrr.resource_id
7689 and mor.plan_id = mdri.plan_id
7690 and mor.sr_instance_id = mdri.sr_instance_id
7691 and mor.resource_id = mdri.resource_id;
7692
7693 rowcount number := 0;
7694
7695 ll_res_inst_trx_id number;
7696 ll_res_trx_id number;
7697
7698 begin
7699 --firm the res instance..
7700 if ( p_node_type = RES_INST_NODE ) then -- {
7701 ll_res_inst_trx_id := p_transaction_id;
7702 ll_res_trx_id := get_parent_res_trx_id(p_plan_id, p_instance_id, ll_res_inst_trx_id);
7703 else
7704 ll_res_trx_id := p_transaction_id;
7705 end if; -- }
7706
7707 if ( nvl(p_node_type, RES_NODE) = RES_NODE ) then -- {
7708
7709 for c_simu_res_res_row in c_simu_res_res(p_plan_id, p_instance_id, ll_res_trx_id)
7710 loop -- {
7711 rowcount := rowcount +1;
7712 if p_name is not null then -- {
7713 p_name := p_name || field_seperator || c_simu_res_res_row.resource_code;
7714 p_id := p_id || field_seperator || c_simu_res_res_row.resource_id;
7715 --|| field_seperator || c_simu_res_res_row.res_instance_id
7716 --|| field_seperator || c_simu_res_res_row.serial_number;
7717 --4710508, res_instance_id, serial_number is not required by client
7718 else
7719 p_name := c_simu_res_res_row.resource_code;
7720 p_id := c_simu_res_res_row.resource_id;
7721 --|| field_seperator || c_simu_res_res_row.res_instance_id
7722 --|| field_seperator || c_simu_res_res_row.serial_number;
7723 end if; -- }
7724 end loop; -- }
7725
7726 -- only resources need to be sent to client per pm
7727 /*
7728 for c_simu_res_inst_row in c_simu_res_inst(p_plan_id, p_instance_id, ll_res_trx_id)
7729 loop -- {
7730 rowcount := rowcount +1;
7731 if p_name is not null then -- {
7732 p_name := p_name || field_seperator || c_simu_res_inst_row.resource_code;
7733 p_id := p_id || field_seperator || c_simu_res_inst_row.resource_id
7734 || field_seperator || c_simu_res_inst_row.res_instance_id
7735 || field_seperator || c_simu_res_inst_row.serial_number;
7736 else
7737 p_name := c_simu_res_inst_row.resource_code;
7738 p_id := c_simu_res_inst_row.resource_id
7739 || field_seperator || c_simu_res_inst_row.res_instance_id
7740 || field_seperator || c_simu_res_inst_row.serial_number;
7741 end if; -- }
7742 end loop; -- }
7743 */
7744 else -- instance node
7745 null;
7746 -- only resources need to be sent to client per pm
7747 /*
7748 for c_simu_inst_res_row in c_simu_inst_res(p_plan_id, p_instance_id, ll_res_inst_trx_id)
7749 loop -- {
7750 rowcount := rowcount +1;
7751 if p_name is not null then -- {
7752 p_name := p_name || field_seperator || c_simu_inst_res_row.resource_code;
7753 p_id := p_id || field_seperator || c_simu_inst_res_row.resource_id
7754 || field_seperator || c_simu_inst_res_row.res_instance_id
7755 || field_seperator || c_simu_inst_res_row.serial_number;
7756 else
7757 p_name := c_simu_inst_res_row.resource_code;
7758 p_id := c_simu_inst_res_row.resource_id
7759 || field_seperator || c_simu_inst_res_row.res_instance_id
7760 || field_seperator || c_simu_inst_res_row.serial_number;
7761 end if; -- }
7762 end loop; -- }
7763
7764 for c_simu_inst_inst_row in c_simu_inst_inst(p_plan_id, p_instance_id, ll_res_inst_trx_id)
7765 loop -- {
7766 rowcount := rowcount +1;
7767 if p_name is not null then -- {
7768 p_name := p_name || field_seperator || c_simu_inst_inst_row.resource_code;
7769 p_id := p_id || field_seperator || c_simu_inst_inst_row.resource_id
7770 || field_seperator || c_simu_inst_inst_row.res_instance_id
7771 || field_seperator || c_simu_inst_inst_row.serial_number;
7772 else
7773 p_name := c_simu_inst_inst_row.resource_code;
7774 p_id := c_simu_inst_inst_row.resource_id
7775 || field_seperator || c_simu_inst_inst_row.res_instance_id
7776 || field_seperator || c_simu_inst_inst_row.serial_number;
7777 end if; -- }
7778 end loop; -- }
7779 */
7780 end if; -- }
7781
7782 p_name := to_char(rowcount) || field_seperator || p_name;
7783 p_id := to_char(rowcount) || field_seperator || p_id;
7784 end getSimuResource;
7785
7786 procedure moveSupplyPub (p_plan_id number,
7787 p_supply_id number, p_start_date date, p_end_date date,
7788 p_plan_start_date date, p_plan_end_date date,
7789 p_return_status OUT NOCOPY varchar2,
7790 p_out out NOCOPY varchar2 ) is
7791
7792 l_quan Number;
7793 begin
7794
7795 if p_start_date < p_plan_start_date then
7796 p_return_status := 'ERROR';
7797 p_out := 'START_DATE_LESS_THAN_PLAN_START';
7798 return;
7799 elsif p_end_date > p_plan_end_date then
7800 p_return_status := 'ERROR';
7801 p_out := 'END_DATE_GREATER_THAN_PLAN_END';
7802 return;
7803 end if;
7804
7805 begin
7806 select nvl(new_order_quantity,0)
7807 into l_quan
7808 from msc_supplies
7809 where plan_id = p_plan_id
7810 and transaction_id = p_supply_id
7811 for update of firm_date nowait;
7812 exception
7813 when app_exception.record_lock_exception then
7814 p_return_status := 'ERROR';
7815 return;
7816 end;
7817
7818 -- now update
7819 msc_gantt_utils.updateSupplies(p_plan_id, p_supply_id,
7820 FIRM_ALL_SUPPLY, SYS_YES, p_end_date, l_quan);
7821
7822 p_return_status := 'OK';
7823
7824 end moveSupplyPub;
7825
7826 procedure moveOneResource(p_plan_id number,
7827 p_transaction_id number, p_instance_id number,
7828 p_start_date date, p_end_date date,
7829 p_return_status in OUT NOCOPY varchar2,
7830 p_out in OUT NOCOPY varchar2,
7831 p_node_type number) is
7832
7833 l_firm_flag number;
7834 l_firm_start date;
7835 l_firm_end date;
7836 l_start date;
7837 l_end date;
7838 l_supply_id number;
7839
7840 ll_res_inst_trx_id number;
7841 ll_res_trx_id number;
7842 begin
7843 if ( p_node_type = RES_NODE ) then -- {
7844 ll_res_trx_id := p_transaction_id;
7845
7846 -- lock the mrr and getNewData
7847 msc_gantt_utils.lockReqNGetData(p_plan_id, p_instance_id, ll_res_trx_id,
7848 l_firm_flag, l_supply_id, l_start, l_end, l_firm_start, l_firm_end,
7849 p_return_status, p_out);
7850
7851 l_start := p_start_date;
7852 l_end := p_end_date;
7853
7854 -- update requirement
7855 msc_gantt_utils.updateReq(p_plan_id, p_instance_id, ll_res_trx_id,
7856 l_firm_flag, l_start, l_end, l_firm_start, l_firm_end, MOVE_MRR);
7857
7858 -- update requirement's supply
7859 msc_gantt_utils.updateSupplies(p_plan_id, l_supply_id, TOUCH_SUPPLY);
7860
7861 else
7862 ll_res_inst_trx_id := p_transaction_id;
7863
7864 -- lock the mrr and getNewData
7865 msc_gantt_utils.lockReqInstNGetData(p_plan_id, p_instance_id, ll_res_inst_trx_id,
7866 l_supply_id, l_start, l_end, p_return_status, p_out);
7867
7868 l_start := p_start_date;
7869 l_end := p_end_date;
7870
7871 -- update requirement
7872 msc_gantt_utils.updateReqInst(p_plan_id, p_instance_id, ll_res_inst_trx_id, l_start, l_end);
7873
7874 -- update requirement's supply
7875 msc_gantt_utils.updateSupplies(p_plan_id, l_supply_id, TOUCH_SUPPLY);
7876
7877 end if; -- }
7878
7879 -- when the move is made, no need to update the firm dates...
7880 /*
7881 if (l_end - l_start) = ( p_end_date - p_start_date ) then -- {
7882 if l_firm_flag in (NO_FIRM, FIRM_START) or l_firm_flag is null then -- {
7883 l_firm_flag := FIRM_START;
7884 elsif l_firm_flag in (FIRM_END, FIRM_START_END) THEN
7885 l_firm_flag := FIRM_START_END;
7886 elsif l_firm_flag in (FIRM_RESOURCE, FIRM_START_RES) THEN
7887 l_firm_flag := FIRM_START_RES;
7888 elsif l_firm_flag in (FIRM_END_RES,FIRM_ALL) THEN
7889 l_firm_flag := FIRM_ALL;
7890 else
7891 l_firm_flag := FIRM_START;
7892 end if; -- }
7893 else
7894 if l_firm_flag in (FIRM_RESOURCE,FIRM_START_RES,FIRM_END_RES,FIRM_ALL) THEN -- {
7895 l_firm_flag := FIRM_ALL;
7896 else
7897 l_firm_flag := FIRM_START_END;
7898 end if; -- }
7899 end if; -- }
7900
7901 if l_firm_flag in (NO_FIRM,FIRM_START,FIRM_RESOURCE,FIRM_START_RES) then -- {
7902 l_firm_end := to_date(null);
7903 else
7904 l_firm_end := p_end_date;
7905 end if; -- }
7906 l_firm_start := p_start_date;
7907 */
7908 end moveOneResource;
7909
7910 procedure moveResourceBatch(p_plan_id number,
7911 p_transaction_id number, p_instance_id number,
7912 p_start_date date, p_end_date date,
7913 p_plan_start_date date, p_plan_end_date date,
7914 p_return_status OUT NOCOPY varchar2, p_out OUT NOCOPY varchar2,
7915 p_validate_flag boolean, p_node_type number) is
7916
7917 l_start date;
7918 l_end date;
7919 l_firm_flag number;
7920 l_firm_start date;
7921 l_firm_end date;
7922 l_batch_number number;
7923 l_group_sequence_id number;
7924 l_group_sequence_number number;
7925
7926 ll_res_inst_trx_id number;
7927 ll_res_trx_id number;
7928 begin
7929 put_line(' moveResourceBatch in ');
7930
7931 /*
7932 if ( p_validate_flag ) then -- {
7933 validateTime(p_plan_id, p_transaction_id, p_instance_id, p_start_date, p_end_date,
7934 p_plan_start_date, p_plan_end_date, p_return_status, p_out, p_node_type);
7935
7936 if p_return_status = 'ERROR' then
7937 return ;
7938 end if;
7939 end if; -- }
7940 */
7941
7942 if ( p_node_type = RES_NODE ) then -- {
7943
7944 -- in both the cases, res or res inst move, move the simultaneous res req
7945 open res_req_info(p_plan_id, p_instance_id, p_transaction_id);
7946 fetch res_req_info into l_firm_flag, l_firm_start, l_firm_end,
7947 l_batch_number, l_group_sequence_id, l_group_sequence_number;
7948 close res_req_info;
7949
7950 msc_gantt_utils.updateBatchReq(p_plan_id, p_instance_id, l_batch_number,
7951 p_start_date, p_end_date, l_firm_flag, MOVE_MRR, p_return_status, p_out);
7952
7953 else
7954
7955 open res_inst_req_info(p_plan_id, p_instance_id, p_instance_id);
7956 fetch res_inst_req_info into l_batch_number;
7957 close res_inst_req_info;
7958
7959 msc_gantt_utils.updateBatchInstReq(p_plan_id, p_instance_id, l_batch_number,
7960 p_start_date, p_end_date, l_firm_flag, MOVE_MRR, p_return_status, p_out);
7961
7962 end if; -- }
7963
7964 put_line(' moveResourceBatch out ');
7965 end moveResourceBatch;
7966
7967 procedure moveResourceSeq(p_plan_id number,
7968 p_transaction_id number, p_instance_id number,
7969 p_duration varchar2, p_plan_start_date date, p_plan_end_date date,
7970 p_return_status OUT NOCOPY varchar2,
7971 p_out OUT NOCOPY varchar2,
7972 p_validate_flag boolean,
7973 p_node_type number) IS
7974
7975 l_start date;
7976 l_end date;
7977 l_firm_flag number;
7978 l_firm_start date;
7979 l_firm_end date;
7980 l_batch_number number;
7981 l_group_sequence_id number;
7982 l_group_sequence_number number;
7983
7984 ll_res_inst_trx_id number;
7985 ll_res_trx_id number;
7986
7987 begin
7988 put_line('moveResourceSeq in ');
7989 if ( p_node_type = RES_INST_NODE ) then -- {
7990 ll_res_inst_trx_id := p_transaction_id;
7991 ll_res_trx_id := get_parent_res_trx_id(p_plan_id, p_instance_id, ll_res_inst_trx_id);
7992 else
7993 ll_res_trx_id := p_transaction_id;
7994 end if; -- }
7995
7996 -- in both the cases, res or res inst move, move the simultaneous res req
7997 open res_req_info(p_plan_id, p_instance_id, ll_res_trx_id);
7998 fetch res_req_info into l_firm_flag, l_firm_start, l_firm_end,
7999 l_batch_number, l_group_sequence_id, l_group_sequence_number;
8000 close res_req_info;
8001
8002 if ( l_group_sequence_id is null or l_group_sequence_number is null ) then
8003 p_return_status := 'ERROR';
8004 p_out := 'RES_REQ_NOT_IN_FIRM_SEQ';
8005 return;
8006 end if;
8007
8008 if (p_duration is not null) then
8009 msc_gantt_utils.updateResSeq(p_plan_id, p_instance_id,
8010 l_group_sequence_id, p_duration, p_plan_start_date, p_plan_end_date,
8011 p_return_status, p_out, p_validate_flag, p_node_type);
8012 end if;
8013
8014 put_line('moveResourceSeq out ');
8015 end moveResourceSeq;
8016
8017
8018 procedure moveResourcePub(p_plan_id number,
8019 p_transaction_id number, p_instance_id number,
8020 p_start_date date, p_end_date date,
8021 p_duration varchar2,
8022 p_plan_start_date date, p_plan_end_date date,
8023 p_return_status OUT NOCOPY varchar2,
8024 p_out OUT NOCOPY varchar2,
8025 p_validate_flag boolean,
8026 p_res_firm_seq boolean,
8027 p_batched_res_act boolean,
8028 p_node_type number) IS
8029
8030 row_count number;
8031 v_transaction_id number;
8032 v_instance_id number;
8033
8034 l_start date;
8035 l_end date;
8036 l_firm_flag number;
8037 l_firm_start date;
8038 l_firm_end date;
8039 l_batch_number number;
8040 l_group_sequence_id number;
8041 l_group_sequence_number number;
8042
8043 ll_res_inst_trx_id number;
8044 ll_res_trx_id number;
8045
8046 begin
8047 put_line(' moveResourcePub in ');
8048 p_return_status := 'OK';
8049
8050 -- res/res inst firm seq move logic and batched res/res inst move logic
8051 if ( p_res_firm_seq ) then
8052 put_line(' before moveResourceSeq');
8053 msc_gantt_utils.moveResourceSeq(p_plan_id, p_transaction_id, p_instance_id,
8054 p_duration, p_plan_start_date, p_plan_end_date,
8055 p_return_status, p_out, p_validate_flag, p_node_type);
8056 return; --end this process here itself..
8057 elsif ( p_batched_res_act ) then
8058 put_line(' before moveResourceBatch');
8059 msc_gantt_utils.moveResourceBatch(p_plan_id, p_transaction_id, p_instance_id,
8060 p_start_date, p_end_date, p_plan_start_date, p_plan_end_date,
8061 p_return_status, p_out, p_validate_flag, p_node_type);
8062 return; --end this process here itself..
8063 end if; -- }
8064 -- res/res inst firm seq move logic and batched res/res inst move logic
8065
8066 -- res/res inst normal move ......
8067
8068 if ( p_validate_flag ) then -- {
8069 put_line(' before validateTime');
8070 validateTime(p_plan_id, p_transaction_id, p_instance_id, p_start_date, p_end_date,
8071 p_plan_start_date, p_plan_end_date, p_return_status, p_out, p_node_type);
8072 if p_return_status = 'ERROR' then
8073 return ;
8074 end if;
8075 end if; -- }
8076
8077 if ( p_node_type = RES_INST_NODE ) then -- {
8078 ll_res_inst_trx_id := p_transaction_id;
8079 ll_res_trx_id := get_parent_res_trx_id(p_plan_id, p_instance_id, ll_res_inst_trx_id);
8080 else
8081 ll_res_trx_id := p_transaction_id;
8082 ll_res_inst_trx_id := get_child_res_trx_id(p_plan_id, p_instance_id, ll_res_trx_id);
8083 end if; -- }
8084
8085 put_line('ll_res_trx_id ll_res_inst_trx_id '||ll_res_trx_id||' - '||ll_res_inst_trx_id);
8086
8087 -- in both the cases, res or res inst move, move the simultaneous res req
8088 open res_req_info(p_plan_id, p_instance_id, ll_res_trx_id);
8089 fetch res_req_info into l_firm_flag, l_firm_start, l_firm_end,
8090 l_batch_number, l_group_sequence_id, l_group_sequence_number;
8091 close res_req_info;
8092
8093 l_start := p_start_date;
8094 l_end := p_end_date;
8095
8096 if ( nvl(l_firm_flag,0) <> 0 ) then
8097 p_return_status := 'ERROR';
8098 p_out := 'REQ_IS_FIRMED';
8099 return;
8100 end if;
8101
8102 if ( p_node_type = RES_INST_NODE ) then -- {
8103 -- move res inst node
8104 msc_gantt_utils.moveOneResource(p_plan_id, ll_res_inst_trx_id, p_instance_id, p_start_date, p_end_date,
8105 p_return_status, p_out, RES_INST_NODE);
8106 if p_return_status = 'ERROR' then
8107 return;
8108 end if;
8109 -- move res node also
8110 msc_gantt_utils.moveOneResource(p_plan_id, ll_res_trx_id, p_instance_id, p_start_date, p_end_date,
8111 p_return_status, p_out, RES_NODE);
8112 if p_return_status = 'ERROR' then
8113 return;
8114 end if;
8115 else
8116 -- move res node only
8117 msc_gantt_utils.moveOneResource(p_plan_id, ll_res_trx_id, p_instance_id, p_start_date, p_end_date,
8118 p_return_status, p_out, RES_NODE);
8119 if p_return_status = 'ERROR' then
8120 return;
8121 end if;
8122 -- move all the res instance if the resource is moved.
8123 msc_gantt_utils.moveOneResource(p_plan_id, ll_res_inst_trx_id, p_instance_id,
8124 l_start, l_end, p_return_status, p_out, RES_INST_NODE);
8125 if p_return_status = 'ERROR' then
8126 return;
8127 end if;
8128 end if; -- }
8129
8130 -- update the simultaneous resource for a given res trans id
8131 msc_gantt_utils.updateReqSimu(p_plan_id, p_instance_id, ll_res_trx_id,
8132 l_firm_flag, l_start, l_end, l_firm_start, l_firm_end, MOVE_MRR, p_return_status, p_out);
8133 -- in both the cases, res or res inst move, move the simultaneous res req ends
8134
8135
8136 put_line(' moveResourcePub out');
8137 end moveResourcePub;
8138
8139 -- property +
8140 procedure getProperty(p_plan_id number, p_instance_id number,
8141 p_transaction_id number, p_type number, p_view_type number, p_end_demand_id number,
8142 v_pro out NOCOPY varchar2, v_demand out NOCOPY varchar2) is
8143
8144 l_buy_text varchar2(2000) := fnd_message.get_string('MSC','BUY_TEXT');
8145 l_make_text varchar2(2000) := fnd_message.get_string('MSC','MAKE_TEXT');
8146 l_transfer_text varchar2(2000) := fnd_message.get_string('MSC','TRANSFER_TEXT');
8147
8148 cursor job_cur is
8149 select msi.item_name item,
8150 ms.new_order_quantity qty,
8151 nvl(to_char(ms.firm_date,format_mask), null_space) firm_date,
8152 to_char(ms.new_schedule_date,format_mask) sugg_due_date,
8153 nvl(to_char(ms.need_by_date,format_mask), null_space) needby,
8154 nvl(ms.unit_number,null_space) unit_number,
8155 nvl(msc_get_name.project(ms.project_id,ms.organization_id,
8156 ms.plan_id, ms.sr_instance_id), null_space) project,
8157 nvl(msc_get_name.task(ms.task_id, ms.project_id, ms.organization_id,
8158 ms.plan_id, ms.sr_instance_id),null_space) task,
8159 msc_get_name.org_code(ms.organization_id, ms.sr_instance_id) org,
8160 decode(ms.order_type,
8161 5, decode(ms.order_number,
8162 null, to_char(ms.transaction_id),
8163 replace(ms.order_number,'~','^')||' '||to_char(ms.transaction_id)),
8164 nvl(replace(ms.order_number,'~','^'), to_char(ms.transaction_id))) job_name,
8165 ms.firm_planned_type,
8166 nvl(ms.alternate_bom_designator, null_space) alternate_bom_designator,
8167 nvl(ms.alternate_routing_designator, null_space) alternate_routing_designator,
8168 ms.organization_id org_id,
8169 nvl(to_char(msi.planning_time_fence_date, format_mask),null_space) time_fence,
8170 nvl(msc_get_name.supply_type(ms.transaction_id, p_plan_id), null_space) supply_type,
8171 decode(msc_gantt_utils.getSupplyType(ms.order_type, msi.planning_make_buy_code,
8172 ms.organization_id, ms.source_organization_id),
8173 BUY_SUPPLY, l_buy_text,
8174 TRANSFER_SUPPLY, l_transfer_text,
8175 MAKE_SUPPLY, l_make_text) item_type,
8176 msi.description,
8177 nvl(msc_get_name.supplier(nvl(ms.source_supplier_id, ms.supplier_id)), null_space) supplier,
8178 nvl(msc_get_name.org_code(ms.source_organization_id, ms.source_sr_instance_id),null_space) source_org,
8179 nvl(ms.ship_method, null_space) ship_method,
8180 msc_get_name.lookup_meaning('SYS_YES_NO', decode(ms.supply_is_shared,1,1,2)) share_supply,
8181 nvl(to_char(ms.EARLIEST_START_DATE,format_mask),null_space) EPSD,
8182 nvl(to_char(ms.EARLIEST_COMPLETION_DATE,format_mask),null_space) EPCD,
8183 nvl(to_char(ms.UEPSD,format_mask),null_space) UEPSD,
8184 nvl(to_char(ms.UEPCD,format_mask),null_space) UEPCD,
8185 nvl(to_char(ms.ULPSD,format_mask),null_space) ULPSD,
8186 nvl(to_char(ms.ULPCD,format_mask),null_space) ULPCD
8187 from msc_supplies ms,
8188 msc_system_items msi
8189 where ms.plan_id = p_plan_id
8190 and ms.transaction_id = p_transaction_id
8191 and ms.sr_instance_id = p_instance_id
8192 and msi.plan_id = ms.plan_id
8193 and msi.organization_id = ms.organization_id
8194 and msi.sr_instance_id = ms.sr_instance_id
8195 and msi.inventory_item_id = ms.inventory_item_id;
8196
8197 cursor res_cur is
8198 select msc_get_name.item_name(mrr.assembly_item_id,null,null,null) item,
8199 nvl(mrr.operation_seq_num,0) op_seq,
8200 msc_get_name.org_code(mrr.organization_id, mrr.sr_instance_id) org,
8201 msc_get_name.department_code(decode(mrr.resource_id, -1, 1,2),
8202 mrr.department_id, mrr.organization_id, mrr.plan_id, mrr.sr_instance_id) dept_code,
8203 nvl(msc_get_name.job_name(mrr.supply_id, p_plan_id), to_char(mrr.supply_id)) job_name,
8204 nvl(mrr.assigned_units,0) assigned_units,
8205 msc_get_name.lookup_meaning('RESOURCE_FIRM_TYPE', nvl(mrr.firm_flag,0)) firm_flag,
8206 nvl(mrr.alternate_num,0) alternate_num,
8207 nvl(mrr.resource_seq_num,0) res_seq_num,
8208 nvl(msc_get_name.resource_code(mrr.resource_id, mrr.department_id,
8209 mrr.organization_id, mrr.plan_id, mrr.sr_instance_id), null_space) res_code,
8210 nvl(mrr.resource_hours,0) resource_hours,
8211 ms.organization_id org_id,
8212 ms.transaction_id trans_id,
8213 0 mtq_time, -- getMTQTime(p_transaction_id, p_plan_id, p_instance_id) mtq_time,
8214 nvl(mdr.batchable_flag,2) batchable,
8215 nvl(to_char(mrr.batch_number), null_space) batch_number,
8216 nvl(mdr.unit_of_measure,null_space) uom,
8217 nvl(decode(mrr.basis_type,
8218 null, null_space,
8219 msc_get_name.lookup_meaning('MSC_RES_BASIS_TYPE',mrr.basis_type)),null_space) basis_type,
8220 nvl(decode(mrr.schedule_flag,
8221 null, null_space,
8222 msc_get_name.lookup_meaning('BOM_RESOURCE_SCHEDULE_TYPE',mrr.schedule_flag)),null_space) schedule_flag,
8223 nvl(to_char(mrr.EARLIEST_START_DATE,format_mask),null_space) EPSD,
8224 nvl(to_char(mrr.EARLIEST_COMPLETION_DATE,format_mask),null_space) EPCD,
8225 nvl(to_char(mrr.UEPSD,format_mask),null_space) UEPSD,
8226 nvl(to_char(mrr.UEPCD,format_mask),null_space) UEPCD,
8227 nvl(to_char(mrr.ULPSD,format_mask),null_space) ULPSD,
8228 nvl(to_char(mrr.ULPCD,format_mask),null_space) ULPCD
8229 from msc_resource_requirements mrr,
8230 msc_supplies ms,
8231 msc_department_resources mdr
8232 where mrr.plan_id = p_plan_id
8233 and mrr.transaction_id = p_transaction_id
8234 and mrr.sr_instance_id = p_instance_id
8235 and ms.sr_instance_id = mrr.sr_instance_id
8236 and ms.plan_id = p_plan_id
8237 and ms.transaction_id = mrr.supply_id
8238 and mdr.plan_id = mrr.plan_id
8239 and mdr.organization_id = mrr.organization_id
8240 and mdr.sr_instance_id = mrr.sr_instance_id
8241 and mdr.department_id = mrr.department_id
8242 and mdr.resource_id = mrr.resource_id;
8243
8244 job_cur_rec job_cur%ROWTYPE;
8245 res_cur_rec res_cur%ROWTYPE;
8246
8247 p_end_peg_id number;
8248
8249 cursor alloc_cur is
8250 select sum(decode(mfp.demand_id, -1, mfp.allocated_quantity, 0)),
8251 sum(mfp.allocated_quantity)
8252 from msc_full_pegging mfp
8253 where mfp.plan_id = p_plan_id
8254 AND mfp.transaction_id = p_transaction_id
8255 and mfp.end_pegging_id = p_end_peg_id;
8256
8257 v_end_peg_id number_arr;
8258 a number;
8259 v_qty1 number;
8260 v_qty2 number;
8261 v_excess_qty number :=0;
8262 v_alloc_qty number :=0;
8263
8264 begin
8265 if p_type in (JOB_NODE, COPROD_NODE) then -- {
8266
8267 -- calculate alloc_qty, excess_qty, and short_qty
8268 select mfp.end_pegging_id
8269 bulk collect into v_end_peg_id
8270 from msc_full_pegging mfp
8271 where mfp.plan_id = p_plan_id
8272 and mfp.demand_id = p_end_demand_id
8273 and mfp.pegging_id = mfp.end_pegging_id;
8274
8275 for a in 1..v_end_peg_id.count
8276 loop -- {
8277 p_end_peg_id := v_end_peg_id(a);
8278 v_qty1 :=0;
8279 v_qty2 :=0;
8280
8281 open alloc_cur;
8282 fetch alloc_cur into v_qty1,v_qty2;
8283 close alloc_cur;
8284
8285 v_excess_qty := v_excess_qty + nvl(v_qty1,0);
8286 v_alloc_qty := v_alloc_qty + nvl(v_qty2,0);
8287 end loop; -- }
8288
8289 open job_cur;
8290 fetch job_cur into job_cur_rec;
8291 close job_cur;
8292
8293 v_pro := job_cur_rec.item || field_seperator || job_cur_rec.qty
8294 || field_seperator || job_cur_rec.firm_date || field_seperator || job_cur_rec.sugg_due_date
8295 || field_seperator || job_cur_rec.needby || field_seperator || job_cur_rec.unit_number
8296 || field_seperator || job_cur_rec.project || field_seperator || job_cur_rec.task
8297 || field_seperator || job_cur_rec.org || field_seperator || job_cur_rec.job_name
8298 || field_seperator || job_cur_rec.firm_planned_type
8299 || field_seperator || job_cur_rec.alternate_bom_designator
8300 || field_seperator || job_cur_rec.alternate_routing_designator
8301 || field_seperator || job_cur_rec.time_fence || field_seperator || job_cur_rec.supply_type
8302 ||field_seperator || job_cur_rec.item_type || field_seperator || job_cur_rec.description
8303 || field_seperator || nvl(to_char(v_alloc_qty), null_space)
8304 || field_seperator || nvl(to_char(v_excess_qty), null_space)
8305 || field_seperator || job_cur_rec.supplier || field_seperator ||job_cur_rec.source_org
8306 || field_seperator || job_cur_rec.ship_method || field_seperator || job_cur_rec.share_supply
8307 || field_seperator || job_cur_rec.EPSD || field_seperator ||job_cur_rec.EPCD
8308 || field_seperator || job_cur_rec.UEPSD || field_seperator || job_cur_rec.UEPCD
8309 || field_seperator || job_cur_rec.ULPSD || field_seperator || job_cur_rec.ULPCD ;
8310
8311 demandPropertyData(p_plan_id, p_instance_id, p_transaction_id,
8312 job_cur_rec.org_id, p_end_demand_id, v_demand);
8313
8314 elsif p_type = RES_NODE then
8315
8316 open res_cur;
8317 fetch res_cur into res_cur_rec;
8318 close res_cur;
8319
8320 resPropertyData(p_plan_id, p_transaction_id, p_instance_id, p_end_demand_id, v_pro, v_demand);
8321
8322 demandPropertyData(p_plan_id, p_instance_id, res_cur_rec.trans_id,
8323 res_cur_rec.org_id, p_end_demand_id, v_demand);
8324
8325 elsif p_type = END_DEMAND_NODE then
8326 demandPropertyData(p_plan_id, p_instance_id, null,
8327 null, p_transaction_id, v_demand);
8328 end if; -- }
8329
8330 end getProperty;
8331
8332 procedure resPropertyData(p_plan_id number,
8333 p_transaction_id number, p_instance_id number, p_end_demand_id number,
8334 v_job OUT NOCOPY varchar2, v_demand OUT NOCOPY varchar2) IS
8335
8336 cursor property is
8337 select msc_get_name.item_name(ms.inventory_item_id,null,null,null) item,
8338 mrr.operation_seq_num,
8339 ms.new_order_quantity qty,
8340 nvl(to_char(ms.firm_date,format_mask),null_space) firm_date,
8341 to_char(ms.new_schedule_date,format_mask) sugg_due_date,
8342 nvl(to_char(ms.need_by_date,format_mask),null_space) needby,
8343 nvl(ms.unit_number,null_space) unit_number,
8344 nvl(msc_get_name.project(ms.project_id,ms.organization_id,
8345 ms.plan_id, ms.sr_instance_id), null_space) project,
8346 nvl(msc_get_name.task(ms.task_id, ms.project_id, ms.organization_id,
8347 ms.plan_id, ms.sr_instance_id),null_space) task,
8348 ms.transaction_id,
8349 ms.organization_id,
8350 msc_get_name.org_code(mdr.organization_id, mdr.sr_instance_id) org,
8351 mdr.department_code,
8352 decode(ms.order_type,
8353 5, decode(ms.order_number,
8354 null,to_char(ms.transaction_id),
8355 replace(ms.order_number,'~','^')||' '||to_char(ms.transaction_id)),
8356 nvl(replace(ms.order_number,'~','^'),to_char(ms.transaction_id))) job_name,
8357 mrr.assigned_units,
8358 nvl(msc_get_name.lookup_meaning('RESOURCE_FIRM_TYPE',nvl(mrr.firm_flag,NO_FIRM)),
8359 msc_get_name.lookup_meaning('RESOURCE_FIRM_TYPE',0))
8360 firm_flag,
8361 ms.firm_planned_type,
8362 nvl(mrr.alternate_num,0) alternate_num,
8363 mrr.resource_seq_num,
8364 nvl(mdr.resource_code, null_space) resource_code,
8365 mrr.resource_hours,
8366 nvl(msc_get_name.alternate_bom(pe.plan_id, pe.sr_instance_id,
8367 pe.bill_sequence_id),null_space) alternate_bom_designator,
8368 nvl(msc_get_name.alternate_bom(pe.plan_id, pe.sr_instance_id,
8369 pe.bill_sequence_id),null_space) alternate_routing_designator,
8370 nvl(to_char(msi.planning_time_fence_date, format_mask),null_space) time_fence,
8371 0 mtq_time, --getMTQTime(p_transaction_id, p_plan_id, p_instance_id) mtq_time,
8372 nvl(mdr.batchable_flag, 2) batchable,
8373 nvl(to_char(mrr.batch_number), null_space) batch_number,
8374 nvl(mdr.unit_of_measure,null_space) uom,
8375 nvl(decode(to_char(mrr.basis_type),
8376 null, null_space,
8377 msc_get_name.lookup_meaning('MSC_RES_BASIS_TYPE',mrr.basis_type)),null_space) basis_type,
8378 nvl(decode(to_char(mrr.schedule_flag),
8379 null, null_space,
8380 msc_get_name.lookup_meaning('BOM_RESOURCE_SCHEDULE_TYPE',mrr.schedule_flag)),null_space) schedule_flag,
8381 nvl(to_char(mrr.EARLIEST_START_DATE,format_mask),null_space) EPSD,
8382 nvl(to_char(mrr.EARLIEST_COMPLETION_DATE,format_mask),null_space) EPCD,
8383 nvl(to_char(mrr.UEPSD,format_mask),null_space) UEPSD,
8384 nvl(to_char(mrr.UEPCD,format_mask),null_space) UEPCD,
8385 nvl(to_char(mrr.ULPSD,format_mask),null_space) ULPSD,
8386 nvl(to_char(mrr.ULPCD,format_mask),null_space) ULPCD
8387 from msc_supplies ms,
8388 msc_resource_requirements mrr,
8389 msc_department_resources mdr,
8390 msc_system_items msi,
8391 msc_process_effectivity pe
8392 where pe.plan_id(+) = ms.plan_id
8393 and pe.sr_instance_id(+) = ms.sr_instance_id
8394 and pe.process_sequence_id(+) = ms.process_seq_id
8395 and mrr.plan_id = p_plan_id
8396 and mrr.transaction_id = p_transaction_id
8397 and mrr.sr_instance_id = p_instance_id
8398 and ms.plan_id = mrr.plan_id
8399 and ms.transaction_id = mrr.supply_id
8400 and ms.sr_instance_id = mrr.sr_instance_id
8401 and mdr.plan_id = mrr.plan_id
8402 and mdr.organization_id = mrr.organization_id
8403 and mdr.sr_instance_id = mrr.sr_instance_id
8404 and mdr.department_id = mrr.department_id
8405 and mdr.resource_id = mrr.resource_id
8406 and msi.plan_id = ms.plan_id
8407 and msi.organization_id = ms.organization_id
8408 and msi.sr_instance_id = ms.sr_instance_id
8409 and msi.inventory_item_id = ms.inventory_item_id;
8410
8411 pro_record property%ROWTYPE;
8412
8413 begin
8414
8415 open property;
8416 fetch property into pro_record;
8417 close property;
8418
8419 v_job := pro_record.item || field_seperator ||pro_record.operation_seq_num
8420 || field_seperator || pro_record.qty
8421 || field_seperator || pro_record.firm_date
8422 || field_seperator || pro_record.sugg_due_date || field_seperator || pro_record.needby
8423 || field_seperator || pro_record.unit_number || field_seperator || pro_record.project
8424 || field_seperator || pro_record.task || field_seperator || pro_record.department_code
8425 || field_seperator || pro_record.job_name || field_seperator || pro_record.org
8426 || field_seperator || pro_record.assigned_units
8427 || field_seperator || pro_record.firm_flag
8428 || field_seperator || pro_record.firm_planned_type || field_seperator || pro_record.alternate_num
8429 || field_seperator || pro_record.resource_seq_num || field_seperator || pro_record.resource_code
8430 || field_seperator || pro_record.resource_hours
8431 || field_seperator || pro_record.alternate_bom_designator
8432 || field_seperator || pro_record.alternate_routing_designator
8433 || field_seperator || pro_record.time_fence || field_seperator || pro_record.mtq_time
8434 || field_seperator || pro_record.batchable || field_seperator || pro_record.batch_number
8435 || field_seperator || pro_record.uom || field_seperator || pro_record.basis_type
8436 || field_seperator || pro_record.schedule_flag || field_seperator || pro_record.EPSD
8437 || field_seperator || pro_record.EPCD || field_seperator || pro_record.UEPSD
8438 || field_seperator || pro_record.UEPCD || field_seperator || pro_record.ULPSD
8439 || field_seperator || pro_record.ULPCD;
8440
8441 if pro_record.transaction_id is not null then -- {
8442 demandPropertyData(p_plan_id, p_instance_id, pro_record.transaction_id,
8443 pro_record.organization_id, p_end_demand_id, v_demand);
8444 end if; -- }
8445
8446 end resPropertyData;
8447
8448 procedure demandPropertyData( p_plan_id number,
8449 p_instance_id number, v_transaction_id number,
8450 v_org_id number, p_end_demand_id number,
8451 v_demand out NOCOPY varchar2) IS
8452
8453 v_instance_id number;
8454 v_demand_id number;
8455 v_pegging_id number;
8456 v_pegged_qty number;
8457 v_days_late varchar2(3000);
8458 v_demand_quantity number;
8459 v_item_id number;
8460 v_demand_date date;
8461
8462 cursor pegging is
8463 select mfp2.demand_id, mfp2.sr_instance_id,
8464 sum(nvl(mfp1.allocated_quantity,0)),
8465 mfp2.demand_quantity,
8466 mfp2.demand_date,
8467 mfp2.inventory_item_id
8468 from msc_full_pegging mfp1,
8469 msc_full_pegging mfp2
8470 where mfp1.plan_id = p_plan_id
8471 and mfp1.organization_id = v_org_id
8472 and mfp1.sr_instance_id = p_instance_id
8473 and mfp1.transaction_id = v_transaction_id
8474 and mfp2.plan_id = mfp1.plan_id
8475 and mfp2.sr_instance_id = mfp1.sr_instance_id
8476 and mfp2.pegging_id = mfp1.end_pegging_id
8477 group by mfp2.demand_id,
8478 mfp2.sr_instance_id,
8479 mfp2.demand_quantity,
8480 mfp2.demand_date,
8481 mfp2.inventory_item_id;
8482
8483 cursor other_demand is
8484 select nvl(v_demand_quantity,0) qty,
8485 nvl(to_char(v_demand_date,format_mask), null_space) demand_date,
8486 msc_get_name.lookup_meaning('MRP_FLP_SUPPLY_DEMAND_TYPE', v_demand_id) type,
8487 item_name item
8488 from msc_items
8489 where inventory_item_id = v_item_id;
8490
8491 cursor demand is
8492 select md.using_requirement_quantity qty,
8493 to_char(md.using_assembly_demand_date, format_mask) demand_date,
8494 msc_get_name.demand_order_number (md.plan_id,md.sr_instance_id,md.demand_id) name,
8495 msc_get_name.lookup_meaning('MRP_DEMAND_ORIGINATION', md.origination_type) type,
8496 msc_get_name.item_name(md.inventory_item_id, null,null,null) item,
8497 nvl(md.demand_priority,0) priority,
8498 nvl(replace(msc_get_name.customer(md.customer_id),'&','*'), null_space) customer,
8499 nvl(replace(msc_get_name.customer_site(md.customer_site_id),'&','*'), null_space) customer_site,
8500 nvl(to_char(md.dmd_satisfied_date,format_mask), null_space) satisfied_date,
8501 decode(sign(md.dmd_satisfied_date - md.using_assembly_demand_date),
8502 1, GREATEST(round(md.dmd_satisfied_date - md.using_assembly_demand_date,2), 0.01), 0) days_late,
8503 nvl(to_char(md.quantity_by_due_date),null_space) qty_by_due_date,
8504 msc_get_name.org_code(md.organization_id, md.sr_instance_id) org,
8505 nvl(md.demand_class,null_space) demand_class
8506 from msc_demands md
8507 where md.plan_id = p_plan_id
8508 and md.demand_id = v_demand_id
8509 and md.sr_instance_id = v_instance_id;
8510
8511 demand_rec demand%ROWTYPE;
8512 other_demand_rec other_demand%ROWTYPE;
8513 rowcount number;
8514
8515 begin
8516 --for demand node only
8517 rowcount :=0;
8518 if (p_end_demand_id is not null) then
8519 v_instance_id := p_instance_id;
8520 v_demand_id := p_end_demand_id;
8521
8522 open demand;
8523 fetch demand into demand_rec;
8524 close demand;
8525
8526 v_days_late := demand_rec.days_late;
8527 if v_days_late = 0 then -- {
8528 v_days_late := null_space;
8529 end if; -- }
8530
8531 v_demand := demand_rec.qty
8532 || field_seperator || demand_rec.demand_date
8533 || field_seperator || demand_rec.name || field_seperator || demand_rec.type
8534 || field_seperator || demand_rec.item || field_seperator || demand_rec.priority
8535 || field_seperator || demand_rec.customer || field_seperator || demand_rec.customer_site
8536 || field_seperator || demand_rec.satisfied_date || field_seperator || null_space
8537 || field_seperator || v_days_late || field_seperator || demand_rec.qty_by_due_date
8538 || field_seperator || demand_rec.org || field_seperator || demand_rec.demand_class ;
8539
8540 rowcount := rowcount +1;
8541 v_demand := to_char(rowcount) || record_seperator || v_demand;
8542 return;
8543 end if;
8544
8545 rowcount :=0;
8546
8547 open pegging;
8548 loop -- {
8549 fetch pegging into v_demand_id, v_instance_id, v_pegged_qty,
8550 v_demand_quantity, v_demand_date, v_item_id;
8551 exit when pegging%notfound or nvl(length(v_demand),0) > 31000;
8552
8553 rowcount := rowcount +1;
8554
8555 if v_demand_id not in (-1,-2,-3,18) then -- {
8556
8557 open demand;
8558 fetch demand into demand_rec;
8559 close demand;
8560
8561 v_days_late := demand_rec.days_late;
8562 if v_days_late = 0 then -- {
8563 v_days_late := null_space;
8564 end if; -- }
8565
8566 if v_demand is not null then -- {
8567 if v_demand_id = p_end_demand_id then -- {
8568 v_demand := demand_rec.qty
8569 || field_seperator || demand_rec.demand_date
8570 || field_seperator || demand_rec.name || field_seperator || demand_rec.type
8571 || field_seperator || demand_rec.item || field_seperator || demand_rec.priority
8572 || field_seperator || demand_rec.customer || field_seperator || demand_rec.customer_site
8573 || field_seperator || demand_rec.satisfied_date
8574 || field_seperator || v_pegged_qty
8575 || field_seperator || v_days_late
8576 || field_seperator || demand_rec.qty_by_due_date
8577 || field_seperator || demand_rec.org || field_seperator || demand_rec.demand_class
8578 || record_seperator ||v_demand;
8579 else
8580 v_demand := v_demand || record_seperator
8581 || demand_rec.qty
8582 || field_seperator || demand_rec.demand_date || field_seperator || demand_rec.name
8583 || field_seperator || demand_rec.type || field_seperator || demand_rec.item
8584 || field_seperator || demand_rec.priority || field_seperator || demand_rec.customer
8585 || field_seperator || demand_rec.customer_site || field_seperator || demand_rec.satisfied_date
8586 || field_seperator || v_pegged_qty
8587 || field_seperator || v_days_late
8588 || field_seperator || demand_rec.qty_by_due_date || field_seperator || demand_rec.org
8589 || field_seperator || demand_rec.demand_class;
8590 end if; -- }
8591 else
8592 v_demand := demand_rec.qty
8593 || field_seperator || demand_rec.demand_date
8594 || field_seperator || demand_rec.name || field_seperator || demand_rec.type
8595 || field_seperator || demand_rec.item || field_seperator || demand_rec.priority
8596 || field_seperator || demand_rec.customer || field_seperator || demand_rec.customer_site
8597 || field_seperator || demand_rec.satisfied_date
8598 || field_seperator || v_pegged_qty
8599 || field_seperator || v_days_late
8600 || field_seperator || demand_rec.qty_by_due_date
8601 || field_seperator || demand_rec.org || field_seperator || demand_rec.demand_class ;
8602 end if; -- }
8603 else
8604 open other_demand;
8605 fetch other_demand into other_demand_rec;
8606 close other_demand;
8607
8608 if v_demand is not null then -- {
8609 v_demand := v_demand
8610 || record_seperator || other_demand_rec.qty
8611 || field_seperator || other_demand_rec.demand_date || field_seperator || null_space
8612 || field_seperator || other_demand_rec.type || field_seperator || other_demand_rec.item
8613 || field_seperator || null_space || field_seperator || null_space
8614 || field_seperator || null_space || field_seperator || null_space
8615 || field_seperator || v_pegged_qty
8616 || field_seperator || null_space
8617 || field_seperator || null_space || field_seperator || null_space
8618 || field_seperator || null_space ;
8619 else
8620 v_demand := other_demand_rec.qty
8621 || field_seperator || other_demand_rec.demand_date
8622 || field_seperator || null_space || field_seperator || other_demand_rec.type
8623 || field_seperator || other_demand_rec.item || field_seperator || null_space
8624 || field_seperator || null_space || field_seperator || null_space
8625 || field_seperator || null_space
8626 || field_seperator || v_pegged_qty
8627 || field_seperator || null_space || field_seperator || null_space
8628 || field_seperator || null_space || field_seperator || null_space;
8629 end if; -- }
8630 end if; -- }
8631 end loop; -- }
8632 close pegging;
8633 v_demand := to_char(rowcount) || record_seperator || v_demand;
8634
8635 end demandPropertyData;
8636 -- property data -
8637
8638 procedure rescheduleData(p_plan_id number,
8639 p_instance_id number, p_org_id number,
8640 p_dept_id number, p_res_id number,
8641 p_time varchar2,
8642 p_plan_end_date date,
8643 v_require_data OUT NOCOPY varchar2) IS
8644
8645 oneRecord varchar2(32000);
8646 rowCount number;
8647
8648 cursor req is
8649 select
8650 to_char(msc_gantt_utils.getResReqStartDate(nvl(mrr.firm_flag,0),
8651 mrr.start_date, mrr.end_date,mrr.firm_start_date, mrr.firm_end_date, mrr.status, mrr.applied), format_mask) start_date,
8652 to_char(msc_gantt_utils.getResReqEndDate(nvl(mrr.firm_flag,0), mrr.start_date, mrr.end_date,
8653 mrr.firm_start_date, mrr.firm_end_date, mrr.status, mrr.applied), format_mask) end_date,
8654 nvl(msc_get_name.job_name(mrr.supply_id, p_plan_id), to_char(mrr.supply_id)) job_name,
8655 msc_get_name.supply_type(mrr.supply_id, mrr.plan_id) supply_type,
8656 mrr.assigned_units,
8657 mrr.transaction_id,
8658 mrr.sr_instance_id
8659 from msc_resource_requirements mrr
8660 where mrr.sr_instance_id = p_instance_id
8661 and mrr.plan_id = p_plan_id
8662 and mrr.organization_id = p_org_id
8663 and mrr.end_date is not null
8664 and nvl(mrr.parent_id,2) =2
8665 and nvl(mrr.firm_start_date,mrr.start_date) <= p_plan_end_date
8666 and mrr.department_id = p_dept_id
8667 and mrr.resource_id = p_res_id
8668 and to_date(p_time, format_mask)
8669 between msc_gantt_utils.getResReqStartDate(nvl(mrr.firm_flag,0),
8670 mrr.start_date, mrr.end_date, mrr.firm_start_date, mrr.firm_end_date, mrr.status, mrr.applied)
8671 and msc_gantt_utils.getResReqEndDate(nvl(mrr.firm_flag,0),
8672 mrr.start_date, mrr.end_date, mrr.firm_start_date, mrr.firm_end_date, mrr.status, mrr.applied)
8673 order by start_date;
8674
8675 l_req_data req%ROWTYPE;
8676
8677 begin
8678
8679 rowCount :=0;
8680 open req;
8681 loop -- {
8682 fetch req into l_req_data;
8683 exit when req%notfound;
8684
8685 if oneRecord is not null then -- {
8686 oneRecord := oneRecord || record_seperator || l_req_data.job_name
8687 || field_seperator || l_req_data.start_date || field_seperator || l_req_data.end_date
8688 || field_seperator || l_req_data.supply_type
8689 || field_seperator || l_req_data.assigned_units
8690 || field_seperator || l_req_data.transaction_id || field_seperator || l_req_data.sr_instance_id ;
8691 else
8692 oneRecord := l_req_data.job_name || field_seperator || l_req_data.start_date
8693 || field_seperator || l_req_data.end_date || field_seperator || l_req_data.supply_type
8694 || field_seperator || l_req_data.assigned_units
8695 || field_seperator || l_req_data.transaction_id
8696 || field_seperator || l_req_data.sr_instance_id ;
8697 end if; -- }
8698 rowCount := rowCount+1;
8699 end loop; -- }
8700 close req;
8701
8702 v_require_data := rowCount || record_seperator || oneRecord;
8703
8704 end rescheduleData;
8705
8706 procedure rescheduleData(p_plan_id number,
8707 p_instance_id number, p_transaction_id number,
8708 p_plan_end_date date,
8709 v_require_data OUT NOCOPY varchar2) IS
8710
8711 oneRecord varchar2(32000);
8712 rowCount number;
8713
8714 cursor req is
8715 select
8716 to_char(msc_gantt_utils.getResReqStartDate(nvl(mrr.firm_flag,0),
8717 mrr.start_date, mrr.end_date,mrr.firm_start_date, mrr.firm_end_date, mrr.status, mrr.applied), format_mask) start_date,
8718 to_char(msc_gantt_utils.getResReqEndDate(nvl(mrr.firm_flag,0), mrr.start_date, mrr.end_date,
8719 mrr.firm_start_date, mrr.firm_end_date, mrr.status, mrr.applied), format_mask) end_date,
8720 nvl(msc_get_name.job_name(mrr.supply_id, p_plan_id), to_char(mrr.supply_id)) job_name,
8721 msc_get_name.supply_type(mrr.supply_id, mrr.plan_id) supply_type,
8722 mrr.assigned_units,
8723 mrr.transaction_id,
8724 mrr.sr_instance_id
8725 from msc_resource_requirements mrr
8726 where mrr.sr_instance_id = p_instance_id
8727 and mrr.plan_id = p_plan_id
8728 and mrr.transaction_id = p_transaction_id
8729 and mrr.end_date is not null
8730 and mrr.department_id <> -1
8731 and nvl(mrr.parent_id,2) =2
8732 and nvl(mrr.firm_start_date,mrr.start_date) <= p_plan_end_date
8733 order by start_date;
8734
8735 l_req_data req%ROWTYPE;
8736
8737 begin
8738 rowCount :=0;
8739 open req;
8740 loop -- {
8741 fetch req into l_req_data;
8742 exit when req%notfound;
8743
8744 if oneRecord is not null then -- {
8745 oneRecord := oneRecord || record_seperator || l_req_data.job_name
8746 || field_seperator || l_req_data.start_date || field_seperator || l_req_data.end_date
8747 || field_seperator || l_req_data.supply_type
8748 || field_seperator || l_req_data.assigned_units
8749 || field_seperator || l_req_data.transaction_id || field_seperator || l_req_data.sr_instance_id ;
8750 else
8751 oneRecord := l_req_data.job_name || field_seperator || l_req_data.start_date
8752 || field_seperator || l_req_data.end_date || field_seperator || l_req_data.supply_type
8753 || field_seperator || l_req_data.assigned_units
8754 || field_seperator || l_req_data.transaction_id
8755 || field_seperator || l_req_data.sr_instance_id ;
8756 end if; -- }
8757 rowCount := rowCount+1;
8758 end loop; -- }
8759 close req;
8760
8761 v_require_data := rowCount || record_seperator ||oneRecord;
8762
8763 end rescheduleData;
8764
8765 function getDependencyType(p_plan_id number, p_trans_id number, p_inst_id number,
8766 p_op_seq_id number, p_op_seq_num number, p_res_seq_num number,
8767 c_trans_id number, c_inst_id number,
8768 c_op_seq_id number, c_op_seq_num number, c_res_seq_num number) return number is
8769
8770 cursor c_intra_rtg is
8771 select distinct mon.dependency_type
8772 from msc_resource_requirements mrr,
8773 msc_operation_networks mon
8774 where mrr.plan_id = p_plan_id
8775 and mrr.sr_instance_id = p_inst_id
8776 and mrr.supply_id = p_trans_id
8777 and mon.plan_id = mrr.plan_id
8778 and mon.sr_instance_id = mrr.sr_instance_id
8779 and mon.routing_sequence_id = mrr.routing_sequence_id
8780 and mon.transition_type = 1
8781 and nvl(mon.from_op_seq_id, MBP_NULL_VALUE) = nvl(p_op_seq_id, MBP_NULL_VALUE)
8782 and nvl(mon.to_op_seq_id, MBP_NULL_VALUE) = nvl(c_op_seq_id, MBP_NULL_VALUE);
8783
8784 cursor c_inter_rtg is
8785 select mjon.dependency_type
8786 from msc_job_operation_networks mjon
8787 where mjon.plan_id = p_plan_id
8788 and mjon.sr_instance_id = p_inst_id
8789 and mjon.transaction_id = p_trans_id
8790 and mjon.to_transaction_id = c_trans_id
8791 and mjon.transition_type = 1
8792 and nvl(mjon.from_op_seq_id, MBP_NULL_VALUE) = nvl(p_op_seq_id, MBP_NULL_VALUE)
8793 and nvl(mjon.to_op_seq_id, MBP_NULL_VALUE) = nvl(c_op_seq_id, MBP_NULL_VALUE);
8794
8795 l_dependency_type number;
8796
8797 begin
8798 if ( p_inst_id = c_inst_id and p_trans_id = c_trans_id ) then --{
8799 --intra-routing
8800 open c_intra_rtg;
8801 fetch c_intra_rtg into l_dependency_type;
8802 close c_intra_rtg;
8803
8804 return nvl(l_dependency_type,-1);
8805
8806 else
8807 --inter-routing
8808 open c_inter_rtg;
8809 fetch c_inter_rtg into l_dependency_type;
8810 close c_inter_rtg;
8811
8812 return nvl(l_dependency_type,-1);
8813 end if; -- }
8814
8815 return -1;
8816 exception
8817 when others then
8818 return -1;
8819 end getDependencyType;
8820
8821
8822 procedure segmentPegging(p_query_id number, p_plan_id number,
8823 p_trx_list varchar2, p_out_data IN OUT NOCOPY msc_gantt_utils.maxCharTbl) is
8824
8825 i number := 1;
8826
8827 l_len number;
8828 l_inst_id number;
8829 l_trx_id number;
8830 l_node_type number;
8831 l_one_record varchar2(100);
8832
8833 c_trans_id number_arr;
8834 c_inst_id number_arr;
8835 seg_start date_arr;
8836 seg_end date_arr;
8837 seg_qty number_arr;
8838 c_start date_arr;
8839 c_end date_arr;
8840
8841 v_one_record varchar2(300);
8842 oneBigRecord maxCharTbl := maxCharTbl(0);
8843 v_max_len number;
8844 reqCount number;
8845
8846 cursor c_seg_peg (p_plan number, p_inst number, p_trx number) is
8847 select producer_trans_id,
8848 producer_sr_instance_id,
8849 from_operation_seq_id,
8850 from_operation_sequence,
8851 from_resource_sequence,
8852 consumer_trans_id,
8853 consumer_sr_instance_id,
8854 to_operation_seq_id,
8855 to_operation_sequence,
8856 to_resource_sequence,
8857 from_start_date,
8858 from_end_date,
8859 from_quantity,
8860 to_start_date,
8861 to_end_date,
8862 -23453 allocation_type,
8863 nvl(dependency_type_id, -1) dependency_type,
8864 minimum_time_offset,
8865 maximum_time_offset,
8866 actual_time_offset
8867 from msc_material_flow_details_v
8868 where plan_id = p_plan
8869 and ( ( producer_sr_instance_id = p_inst and producer_trans_id = p_trx )
8870 or ( consumer_sr_instance_id = p_inst and consumer_trans_id = p_trx ) );
8871
8872 l_producer_trans_id msc_gantt_utils.number_arr;
8873 l_producer_sr_instance_id msc_gantt_utils.number_arr;
8874 l_producer_op_seq_id msc_gantt_utils.number_arr;
8875 l_producer_op_seq_num msc_gantt_utils.number_arr;
8876 l_producer_res_seq_num msc_gantt_utils.number_arr;
8877 l_consumer_trans_id msc_gantt_utils.number_arr;
8878 l_consumer_sr_instance_id msc_gantt_utils.number_arr;
8879 l_consumer_op_seq_id msc_gantt_utils.number_arr;
8880 l_consumer_op_seq_num msc_gantt_utils.number_arr;
8881 l_consumer_res_seq_num msc_gantt_utils.number_arr;
8882 l_segment_start_date msc_gantt_utils.date_arr;
8883 l_segment_end_date msc_gantt_utils.date_arr;
8884 l_segment_quantity msc_gantt_utils.number_arr;
8885 l_consumer_start_date msc_gantt_utils.date_arr;
8886 l_consumer_end_date msc_gantt_utils.date_arr;
8887 l_allocation_type msc_gantt_utils.number_arr;
8888 l_dependency_type msc_gantt_utils.number_arr;
8889 l_minimum_time_offset msc_gantt_utils.number_arr;
8890 l_maximum_time_offset msc_gantt_utils.number_arr;
8891 l_actual_time_offset msc_gantt_utils.number_arr;
8892
8893 begin
8894 l_len := length(p_trx_list);
8895 while l_len > 0 loop
8896 l_one_record := substr(p_trx_list,instr(p_trx_list,'(',1,i)+1,
8897 instr(p_trx_list,')',1,i)-instr(p_trx_list,'(',1,i)-1);
8898 l_inst_id := to_number(substr(l_one_record,1,instr(l_one_record,',')-1));
8899 l_node_type := to_number(substr(l_one_record,instr(l_one_record,',',1,1)+1,
8900 instr(l_one_record,',',1,2)-instr(l_one_record,',',1,1)-1));
8901 l_trx_id := to_number(substr(l_one_record,instr(l_one_record,',',1,2)+1));
8902
8903 if (l_node_type = res_node) then
8904 null;
8905 elsif (l_node_type in (JOB_NODE, COPROD_NODE) ) then
8906 open c_seg_peg(p_plan_id, l_inst_id, l_trx_id);
8907 fetch c_seg_peg bulk collect into l_producer_trans_id, l_producer_sr_instance_id,
8908 l_producer_op_seq_id, l_producer_op_seq_num, l_producer_res_seq_num,
8909 l_consumer_trans_id, l_consumer_sr_instance_id,
8910 l_consumer_op_seq_id, l_consumer_op_seq_num, l_consumer_res_seq_num,
8911 l_segment_start_date, l_segment_end_date, l_segment_quantity,
8912 l_consumer_start_date, l_consumer_end_date, l_allocation_type, l_dependency_type,
8913 l_minimum_time_offset, l_maximum_time_offset, l_actual_time_offset;
8914 close c_seg_peg;
8915
8916 sendSegmentPegStream(SEGMENT_PEG_ROW_TYPE, i, 1,
8917 l_producer_trans_id, l_producer_sr_instance_id,
8918 l_producer_op_seq_id, l_producer_op_seq_num, l_producer_res_seq_num,
8919 l_consumer_trans_id, l_consumer_sr_instance_id,
8920 l_consumer_op_seq_id, l_consumer_op_seq_num, l_consumer_res_seq_num,
8921 l_segment_start_date, l_segment_end_date, l_segment_quantity,
8922 l_consumer_start_date, l_consumer_end_date, l_allocation_type, l_dependency_type,
8923 l_minimum_time_offset, l_maximum_time_offset, l_actual_time_offset,
8924 p_out_data);
8925
8926 end if;
8927 i := i+1;
8928 l_len := l_len - length(l_one_record)-3;
8929 end loop;
8930 end segmentPegging;
8931
8932 procedure resCharges(p_query_id number, p_plan_id number,
8933 p_trx_list varchar2, p_out_data IN OUT NOCOPY msc_gantt_utils.maxCharTbl) is
8934
8935 v_start_date msc_gantt_utils.date_arr;
8936 v_end_date msc_gantt_utils.date_arr;
8937 v_qty msc_gantt_utils.number_arr;
8938
8939 i number := 1;
8940
8941 l_len number;
8942 l_inst_id number;
8943 l_trx_id number;
8944 l_one_record varchar2(100);
8945
8946 l_index number :=0;
8947 begin
8948 l_len := length(p_trx_list);
8949 while l_len > 0 loop -- {
8950 l_one_record := substr(p_trx_list,instr(p_trx_list,'(',1,i)+1,
8951 instr(p_trx_list,')',1,i)-instr(p_trx_list,'(',1,i)-1);
8952 l_inst_id := to_number(substr(l_one_record,1,instr(l_one_record,',')-1));
8953 l_trx_id := to_number(substr(l_one_record,instr(l_one_record,',',1,1)+1));
8954
8955 l_index := l_index + 1;
8956
8957 select charge_start_datetime, charge_end_datetime, charge_quantity
8958 bulk collect into v_start_date, v_end_date, v_qty
8959 from msc_resource_charges
8960 where plan_id = p_plan_id
8961 and sr_instance_id = l_inst_id
8962 and res_transaction_id = l_trx_id
8963 order by 1;
8964
8965 sendResReqAvailSuppStream(RES_CHARGES_ROW_TYPE, l_index, 1,
8966 v_start_date, v_end_date, v_qty, v_qty, v_qty, p_out_data);
8967
8968 i := i+1;
8969 l_len := l_len - length(l_one_record)-3;
8970
8971 end loop; -- }
8972 end resCharges;
8973
8974 procedure setRowFlag(p_query_id number, p_node_id number, p_row_flag number) is
8975 begin
8976 update msc_gantt_query
8977 set row_flag = p_row_flag
8978 where query_id = p_query_id
8979 and row_index = p_node_id;
8980 end setRowFlag;
8981
8982
8983 procedure sendSupplierNames(p_query_id number,
8984 p_from_index number, p_to_index number,
8985 p_name_data IN OUT NOCOPY msc_gantt_utils.maxCharTbl,
8986 p_sort_column varchar2 default null,
8987 p_sort_order varchar2 default null) is
8988
8989 l_node_id char_arr;
8990 l_supp char_arr;
8991 l_supp_site char_arr;
8992 l_org char_arr;
8993 l_item char_arr;
8994 l_buyer char_arr;
8995 l_planner char_arr;
8996
8997 l_inst_id number_arr;
8998 l_org_id number_arr;
8999 l_supp_id number_arr;
9000 l_supp_site_id number_arr;
9001 l_item_id number_arr;
9002
9003 i number := 1;
9004 j number := 0;
9005 k number := 0;
9006
9007 v_one_record varchar2(300);
9008 oneBigRecord maxCharTbl := maxCharTbl(0);
9009 v_max_len number;
9010 reqCount number;
9011
9012 TYPE GanttCurTyp IS REF CURSOR;
9013 the_cursor GanttCurTyp;
9014 sql_stmt varchar2(32000);
9015 begin
9016
9017 sql_stmt := ' select distinct mgq.row_index,
9018 mis.supplier_id,
9019 mis.supplier_site_id,
9020 mis.inventory_item_id,
9021 mtp.partner_name SUPPLIER,
9022 mtps.tp_site_code SUPPLIER_SITE,
9023 --mtp2.organization_code ORGANIZATION,
9024 null ORGANIZATION,
9025 msi.item_name ITEM,
9026 null BUYER,
9027 null PLANNER
9028 FROM msc_trading_partners mtp,
9029 --msc_trading_partners mtp2,
9030 msc_trading_partner_sites mtps,
9031 msc_system_items msi,
9032 msc_item_suppliers mis,
9033 msc_gantt_query mgq
9034 WHERE mgq.query_id = :p_query_id
9035 and mis.plan_id = mgq.plan_id
9036 and mis.supplier_id = mgq.supplier_id
9037 and mis.supplier_site_id = mgq.supplier_site_id
9038 and mis.inventory_item_id = mgq.inventory_item_id
9039 and mis.plan_id = msi.plan_id
9040 and mis.organization_id = msi.organization_id
9041 and mis.sr_instance_id = msi.sr_instance_id
9042 and mis.inventory_item_id = msi.inventory_item_id
9043 and mtp.partner_id = mis.supplier_id
9044 and mtp.partner_type = 1
9045 and mtps.partner_id(+) = mis.supplier_id
9046 and mtps.partner_site_id(+) = mis.supplier_site_id
9047 --and mtp2.sr_tp_id = mis.organization_id
9048 --and mtp2.sr_instance_id = mis.sr_instance_id
9049 --and mtp2.partner_type = 3
9050 ';
9051
9052 if ( p_sort_column is not null ) then
9053 sql_stmt := sql_stmt ||' order by '||p_sort_column||' '||p_sort_order;
9054 else
9055 sql_stmt := sql_stmt ||' order by mgq.row_index ';
9056 end if;
9057
9058 --put_line('sql-stmt' ||sql_stmt);
9059
9060 open the_cursor for sql_stmt using p_query_id;
9061 fetch the_cursor bulk collect into l_node_id, l_supp_id,
9062 l_supp_site_id, l_item_id, l_supp, l_supp_site, l_org, l_item, l_buyer, l_planner;
9063 close the_cursor;
9064
9065 put_line('sendSupplierNames: names: '||l_node_id.count);
9066
9067 j := 1;
9068 reqCount := 0;
9069 p_name_data.delete;
9070 oneBigRecord.delete;
9071 oneBigRecord.extend;
9072 for i in 1..l_node_id.count loop -- {
9073 if ( i >= p_from_index) then -- {
9074 put_line(' supList '||l_node_id(i)||null_space||l_supp(i));
9075
9076 v_one_record := l_node_id(i)
9077 || field_seperator || mbp_null_value_char
9078 || field_seperator || mbp_null_value_char
9079 || field_seperator || l_supp_id(i)
9080 || field_seperator || nvl(to_char(l_supp_site_id(i)), mbp_null_value_char)
9081 || field_seperator || l_item_id(i)
9082 || field_seperator || escapeSplChars(l_supp(i))
9083 || field_seperator || escapeSplChars(l_supp_site(i))
9084 || field_seperator || escapeSplChars(nvl(l_org(i),mbp_null_value_char))
9085 || field_seperator || escapeSplChars(l_item(i))
9086 || field_seperator || nvl(escapeSplChars(l_buyer(i)), null_space)
9087 || field_seperator || nvl(escapeSplChars(l_planner(i)), null_space);
9088
9089 reqCount := reqCount + 1;
9090 v_max_len := nvl(length(oneBigRecord(j)),0) + nvl(length(v_one_record),0);
9091 if v_max_len > 30000 then
9092 j := j+1;
9093 oneBigRecord.extend;
9094 end if;
9095 if ( oneBigRecord(j) is null ) then
9096 oneBigRecord(j) := record_seperator || v_one_record;
9097 else
9098 oneBigRecord(j) := oneBigRecord(j) || record_seperator ||v_one_record;
9099 end if;
9100 setRowFlag(p_query_id, l_node_id(i), SYS_YES);
9101 end if; -- }
9102 exit when i >= p_to_index;
9103 end loop; -- }
9104
9105 p_name_data.extend;
9106 k := k+1;
9107 j := 1;
9108 p_name_data(k) := reqCount || oneBigRecord(1);
9109
9110 for j in 2.. oneBigRecord.count loop -- {
9111 p_name_data.extend;
9112 k := k+1;
9113 p_name_data(k) := oneBigRecord(j);
9114 end loop; -- }
9115
9116 end sendSupplierNames;
9117
9118 procedure sendResourceNames(p_query_id number,
9119 p_from_index number, p_to_index number,
9120 p_name_data IN OUT NOCOPY msc_gantt_utils.maxCharTbl,
9121 p_sort_column varchar2 default null,
9122 p_sort_order varchar2 default null) is
9123
9124 l_node_id char_arr;
9125 l_org char_arr;
9126 l_dept char_arr;
9127 l_owning_dept char_arr;
9128 l_resource_code char_arr;
9129 l_resource_type char_arr;
9130 l_res_inst char_arr;
9131
9132 l_inst_id number_arr;
9133 l_org_id number_arr;
9134 l_dept_id number_arr;
9135 l_res_id number_arr;
9136 l_res_instance_id number_arr;
9137 l_serial_number char_arr;
9138
9139 i number := 1;
9140 j number := 0;
9141 k number := 0;
9142
9143 v_one_record varchar2(300);
9144 oneBigRecord maxCharTbl := maxCharTbl(0);
9145 v_max_len number;
9146 reqCount number;
9147
9148 TYPE GanttCurTyp IS REF CURSOR;
9149 the_cursor GanttCurTyp;
9150 sql_stmt varchar2(32000);
9151 begin
9152
9153 sql_stmt := ' select mgq.row_index,
9154 mgq.sr_instance_id,
9155 mgq.organization_id,
9156 mgq.department_id,
9157 mgq.resource_id,
9158 mgq.res_instance_id,
9159 mgq.serial_number,
9160 msc_get_name.org_code(res.organization_id, res.sr_instance_id) ORGANIZATION,
9161 res.department_code DEPARTMENT,
9162 decode(res.resource_id,-1, null,
9163 msc_get_name.department_code(2, res.owning_department_id,
9164 res.organization_id, res.plan_id,res.sr_instance_id)) OWN_DEPT,
9165 res.resource_code RESOURCE_CODE,
9166 msc_get_name.lookup_meaning(''BOM_RESOURCE_TYPE'',res.resource_type) RES_TYPE,
9167 msc_gantt_utils.getDeptResInstCode(res.plan_id, res.sr_instance_id, res.organization_id,
9168 res.department_id, res.resource_id, mgq.res_instance_id, mgq.serial_number) EQUIP_NUMBER
9169 from msc_department_resources res,
9170 msc_gantt_query mgq
9171 where mgq.query_id = :p_query_id
9172 and res.plan_id = mgq.plan_id
9173 and res.sr_instance_id = mgq.sr_instance_id
9174 and res.organization_id = mgq.organization_id
9175 and res.department_id = mgq.department_id
9176 and res.resource_id = mgq.resource_id ';
9177
9178 if ( p_sort_column is not null ) then
9179 sql_stmt := sql_stmt ||' order by '||p_sort_column||' '||p_sort_order;
9180 else
9181 sql_stmt := sql_stmt ||' order by mgq.row_index ';
9182 end if;
9183
9184 open the_cursor for sql_stmt using p_query_id;
9185 fetch the_cursor bulk collect into l_node_id, l_inst_id, l_org_id,
9186 l_dept_id, l_res_id, l_res_instance_id, l_serial_number, l_org, l_dept, l_owning_dept,
9187 l_resource_code, l_resource_type, l_res_inst;
9188 close the_cursor;
9189
9190 put_line('sendResourceNames: names: '||l_node_id.count);
9191
9192 j := 1;
9193 reqCount := 0;
9194 p_name_data.delete;
9195 oneBigRecord.delete;
9196 oneBigRecord.extend;
9197 for i in 1..l_node_id.count loop -- {
9198
9199 if ( i >= p_from_index) then -- {
9200 put_line(' resList '||l_node_id(i)||null_space||l_resource_code(i));
9201
9202 v_one_record := l_node_id(i)
9203 || field_seperator || l_inst_id(i)
9204 || field_seperator || l_org_id(i)
9205 || field_seperator || l_dept_id(i)
9206 || field_seperator || l_res_id(i)
9207 || field_seperator || nvl(l_res_instance_id(i), mbp_null_value_char)
9208 || field_seperator || nvl(l_serial_number(i), mbp_null_value_char)
9209 || field_seperator || escapeSplChars(l_org(i))
9210 || field_seperator || escapeSplChars(l_dept(i))
9211 || field_seperator || nvl(escapeSplChars(l_owning_dept(i)), null_space)
9212 || field_seperator || escapeSplChars(l_resource_code(i))
9213 || field_seperator || escapeSplChars(l_resource_type(i))
9214 || field_seperator || nvl(escapeSplChars(l_res_inst(i)), null_space);
9215
9216 reqCount := reqCount + 1;
9217 v_max_len := nvl(length(oneBigRecord(j)),0) + nvl(length(v_one_record),0);
9218 if v_max_len > 30000 then
9219 j := j+1;
9220 oneBigRecord.extend;
9221 end if;
9222 if ( oneBigRecord(j) is null ) then
9223 oneBigRecord(j) := record_seperator || v_one_record;
9224 else
9225 oneBigRecord(j) := oneBigRecord(j) || record_seperator ||v_one_record;
9226 end if;
9227 setRowFlag(p_query_id, l_node_id(i), SYS_YES);
9228 end if; -- }
9229 exit when i >= p_to_index;
9230 end loop; -- }
9231
9232 p_name_data.extend;
9233 k := k+1;
9234 j := 1;
9235 if (reqCount = 0) then
9236 p_name_data(k) := reqCount;
9237 return;
9238 end if;
9239
9240 p_name_data(k) := reqCount || oneBigRecord(1);
9241 for j in 2.. oneBigRecord.count loop
9242 p_name_data.extend;
9243 k := k+1;
9244 p_name_data(k) := oneBigRecord(j);
9245 end loop;
9246 end sendResourceNames;
9247
9248 function countStrOccurence (p_string_in in varchar2,
9249 p_substring_in in varchar2) return number is
9250 search_loc number := 1;
9251 substring_len number := length (p_substring_in);
9252 check_again boolean := true;
9253 return_value number := 1;
9254 begin
9255 if p_string_in is not null and p_substring_in is not null then
9256 while check_again
9257 loop
9258 search_loc := INSTR (p_string_in, p_substring_in, search_loc, 1);
9259 check_again := search_loc > 0;
9260 if check_again then
9261 return_value := return_value + 1;
9262 search_loc := search_loc + substring_len;
9263 end if;
9264 end loop;
9265 end if;
9266 return return_value;
9267 END countStrOccurence;
9268
9269 function getResBatchNodeLabel(p_res_req_type varchar2, p_org varchar2,
9270 p_batch_qty varchar2, p_batch_number varchar2, p_batch_util_pct varchar2) return varchar2 is
9271
9272 l_node_label1 varchar2(500);
9273 l_node_label2 varchar2(500);
9274 l_node_label3 varchar2(500);
9275
9276 begin
9277 if ( g_gantt_batches_label_1 = g_batch_none_lbl ) then -- {
9278 l_node_label1 := null;
9279 elsif ( g_gantt_batches_label_1 = g_batch_setup_lbl ) then
9280 l_node_label1 := p_res_req_type;
9281 elsif ( g_gantt_batches_label_1 = g_batch_org_lbl ) then
9282 l_node_label1 := p_org;
9283 elsif ( g_gantt_batches_label_1 = g_batch_qty_lbl ) then
9284 l_node_label1 := p_batch_qty;
9285 elsif ( g_gantt_batches_label_1 = g_batch_num_lbl ) then
9286 l_node_label1 := p_batch_number;
9287 elsif ( g_gantt_batches_label_1 = g_batch_util_pct_lbl ) then
9288 l_node_label1 := p_batch_util_pct * 100;
9289 end if; -- }
9290
9291 if ( g_gantt_batches_label_2 = g_batch_none_lbl ) then -- {
9292 l_node_label2 := null;
9293 elsif ( g_gantt_batches_label_2 = g_batch_setup_lbl ) then
9294 l_node_label2 := p_res_req_type;
9295 elsif ( g_gantt_batches_label_2 = g_batch_org_lbl ) then
9296 l_node_label2 := p_org;
9297 elsif ( g_gantt_batches_label_2 = g_batch_qty_lbl ) then
9298 l_node_label2 := p_batch_qty;
9299 elsif ( g_gantt_batches_label_2 = g_batch_num_lbl ) then
9300 l_node_label2 := p_batch_number;
9301 elsif ( g_gantt_batches_label_2 = g_batch_util_pct_lbl ) then
9302 l_node_label2 := p_batch_util_pct * 100;
9303 end if; -- }
9304
9305 if ( g_gantt_batches_label_3 = g_batch_none_lbl ) then -- {
9306 l_node_label3 := null;
9307 elsif ( g_gantt_batches_label_3 = g_batch_setup_lbl ) then
9308 l_node_label3 := p_res_req_type;
9309 elsif ( g_gantt_batches_label_3 = g_batch_org_lbl ) then
9310 l_node_label3 := p_org;
9311 elsif ( g_gantt_batches_label_3 = g_batch_qty_lbl ) then
9312 l_node_label3 := p_batch_qty;
9313 elsif ( g_gantt_batches_label_3 = g_batch_num_lbl ) then
9314 l_node_label3 := p_batch_number;
9315 elsif ( g_gantt_batches_label_3 = g_batch_util_pct_lbl ) then
9316 l_node_label3 := p_batch_util_pct * 100;
9317 end if; -- }
9318
9319 if ( l_node_label1 is null and l_node_label2 is null and l_node_label3 is null ) then
9320 return null_space;
9321 end if;
9322
9323 return substr(nvl(l_node_label1,null_space),1,80) || COLON_SEPARATOR ||
9324 substr(nvl(l_node_label2,null_space),1,80) || COLON_SEPARATOR ||
9325 substr(nvl(l_node_label3,null_space),1,80);
9326
9327 end getResBatchNodeLabel;
9328
9329 function getResActResNodeLabelLocal(p_label number,
9330 res_label_rec c_res_node_label%rowtype) return varchar2 is
9331 l_node_label1 varchar2(500);
9332 begin
9333 if ( p_label = g_res_none_lbl ) then -- {
9334 l_node_label1 := null;
9335 elsif ( p_label = g_res_act_item_lbl ) then
9336 l_node_label1 := res_label_rec.item_name;
9337 elsif ( p_label = g_res_act_setup_lbl ) then
9338 l_node_label1 := res_label_rec.setup_type;
9339 elsif ( p_label = g_res_act_org_lbl ) then
9340 l_node_label1 := res_label_rec.org_code;
9341 elsif ( p_label = g_res_act_qty_lbl ) then
9342 l_node_label1 := res_label_rec.qty;
9343 elsif ( p_label = g_res_act_batch_lbl ) then
9344 l_node_label1 := res_label_rec.batch_number;
9345 elsif ( p_label = g_res_act_alt_flag_lbl ) then
9346 l_node_label1 := res_label_rec.alt_rtg;
9347 elsif ( p_label = g_res_act_units_lbl ) then
9348 l_node_label1 := res_label_rec.assigned_units;
9349 elsif ( p_label = g_res_act_order_type_lbl ) then
9350 l_node_label1 := res_label_rec.order_type;
9351 elsif ( p_label = g_res_act_op_sdesc_lbl ) then
9352 l_node_label1 := res_label_rec.op_sdesc;
9353 elsif ( p_label = g_res_act_op_seq_lbl ) then
9354 l_node_label1 := res_label_rec.operation_seq_num;
9355 elsif ( p_label = g_res_act_req_comp_date_lbl ) then
9356 l_node_label1 := to_char(res_label_rec.req_comp_date, format_mask);
9357 elsif ( p_label = g_res_act_order_number_lbl ) then
9358 l_node_label1 := res_label_rec.order_number;
9359 end if; -- }
9360 return l_node_label1;
9361 end getResActResNodeLabelLocal;
9362
9363 function getResActResNodeLabel(p_plan_id number, p_inst_id number, p_trx_id number) return varchar2 is
9364
9365 res_label_rec c_res_node_label%rowtype;
9366 l_node_label1 varchar2(500);
9367 l_node_label2 varchar2(500);
9368 l_node_label3 varchar2(500);
9369 begin
9370 open c_res_node_label(p_plan_id, p_inst_id, p_trx_id);
9371 fetch c_res_node_label into res_label_rec;
9372 close c_res_node_label;
9373
9374 l_node_label1 := getResActResNodeLabelLocal(g_gantt_act_label_1, res_label_rec);
9375 l_node_label2 := getResActResNodeLabelLocal(g_gantt_act_label_2, res_label_rec);
9376 l_node_label3 := getResActResNodeLabelLocal(g_gantt_act_label_3, res_label_rec);
9377
9378 if ( l_node_label1 is null and l_node_label2 is null and l_node_label3 is null ) then
9379 return null_space;
9380 end if;
9381
9382 return substr(nvl(l_node_label1,null_space),1,80) || COLON_SEPARATOR ||
9383 substr(nvl(l_node_label2,null_space),1,80) || COLON_SEPARATOR ||
9384 substr(nvl(l_node_label3,null_space),1,80);
9385
9386 end getResActResNodeLabel;
9387
9388 function getOrderViewResNodeLabelLocal(p_label number,
9389 res_label_rec c_res_node_label%rowtype) return varchar2 is
9390 l_node_label1 varchar2(500);
9391 begin
9392 if ( p_label = g_res_none_lbl ) then -- {
9393 l_node_label1 := null;
9394 elsif ( p_label = g_res_seq_lbl ) then
9395 l_node_label1 := res_label_rec.resource_seq_num;
9396 elsif ( p_label = g_res_dept_lbl ) then
9397 l_node_label1 := res_label_rec.department_code;
9398 elsif ( p_label = g_res_lbl ) then
9399 l_node_label1 := res_label_rec.resource_code;
9400 elsif ( p_label = g_res_setup_lbl ) then
9401 l_node_label1 := res_label_rec.setup_type;
9402 elsif ( p_label = g_res_batch_lbl ) then
9403 l_node_label1 := res_label_rec.batch_number;
9404 elsif ( p_label = g_res_alt_flag_lbl ) then
9405 l_node_label1 := res_label_rec.alt_rtg;
9406 elsif ( p_label = g_res_units_lbl ) then
9407 l_node_label1 := res_label_rec.assigned_units;
9408 end if; -- }
9409 return l_node_label1;
9410 end getOrderViewResNodeLabelLocal;
9411
9412 function getOrderViewResNodeLabel(p_plan_id number, p_inst_id number,
9413 p_trx_id number) return varchar2 is
9414
9415 l_node_label1 varchar2(500);
9416 l_node_label2 varchar2(500);
9417 l_node_label3 varchar2(500);
9418
9419 res_label_rec c_res_node_label%rowtype;
9420 begin
9421 open c_res_node_label(p_plan_id, p_inst_id, p_trx_id);
9422 fetch c_res_node_label into res_label_rec;
9423 close c_res_node_label;
9424
9425 l_node_label1 := getOrderViewResNodeLabelLocal(g_gantt_res_act_label_1, res_label_rec);
9426 l_node_label2 := getOrderViewResNodeLabelLocal(g_gantt_res_act_label_2, res_label_rec);
9427 l_node_label3 := getOrderViewResNodeLabelLocal(g_gantt_res_act_label_3, res_label_rec);
9428
9429 if ( l_node_label1 is null and l_node_label2 is null and l_node_label3 is null ) then
9430 return null_space;
9431 end if;
9432
9433 return substr(nvl(l_node_label1,null_space),1,80) || COLON_SEPARATOR ||
9434 substr(nvl(l_node_label2,null_space),1,80) || COLON_SEPARATOR ||
9435 substr(nvl(l_node_label3,null_space),1,80);
9436
9437 end getOrderViewResNodeLabel;
9438
9439 function getOpNodeLabel(p_op_seq varchar2,
9440 p_dept varchar2, p_op_desc varchar2, p_plan_id number) return varchar2 is
9441
9442 l_node_label1 varchar2(500);
9443 l_node_label2 varchar2(500);
9444 l_node_label3 varchar2(500);
9445
9446 cursor c_dept (p_plan number, p_supply number) is
9447 select distinct department_line_code
9448 from msc_resource_requirements_v
9449 where plan_id = p_plan
9450 and source_transaction_id = p_supply;
9451
9452 l_dept varchar2(240);
9453 begin
9454 if ( g_gantt_oper_label_1 = g_op_dept_lbl or
9455 g_gantt_oper_label_2 = g_op_dept_lbl or
9456 g_gantt_oper_label_3 = g_op_dept_lbl) then
9457 open c_dept(p_plan_id, p_dept);
9458 fetch c_dept into l_dept;
9459 close c_dept;
9460 end if;
9461
9462 if ( g_gantt_oper_label_1 = g_op_none_lbl ) then -- {
9463 l_node_label1 := null;
9464 elsif ( g_gantt_oper_label_1 = g_op_seq_lbl ) then
9465 l_node_label1 := p_op_seq;
9466 elsif ( g_gantt_oper_label_1 = g_op_dept_lbl ) then
9467 l_node_label1 := l_dept;
9468 elsif ( g_gantt_oper_label_1 = g_op_desc_lbl ) then
9469 l_node_label1 := p_op_desc;
9470 end if; -- }
9471
9472 if ( g_gantt_oper_label_2 = g_op_none_lbl ) then -- {
9473 l_node_label2 := null;
9474 elsif ( g_gantt_oper_label_2 = g_op_seq_lbl ) then
9475 l_node_label2 := p_op_seq;
9476 elsif ( g_gantt_oper_label_2 = g_op_dept_lbl ) then
9477 l_node_label2 := l_dept;
9478 elsif ( g_gantt_oper_label_2 = g_op_desc_lbl ) then
9479 l_node_label2 := p_op_desc;
9480 end if; -- }
9481
9482 if ( g_gantt_oper_label_3 = g_op_none_lbl ) then -- {
9483 l_node_label3 := null;
9484 elsif ( g_gantt_oper_label_3 = g_op_seq_lbl ) then
9485 l_node_label3 := p_op_seq;
9486 elsif ( g_gantt_oper_label_3 = g_op_dept_lbl ) then
9487 l_node_label3 := l_dept;
9488 elsif ( g_gantt_oper_label_3 = g_op_desc_lbl ) then
9489 l_node_label3 := p_op_desc;
9490 end if; -- }
9491
9492 if ( l_node_label1 is null and l_node_label2 is null and l_node_label3 is null ) then
9493 return null_space;
9494 end if;
9495
9496 return substr(nvl(l_node_label1,null_space),1,80) || COLON_SEPARATOR ||
9497 substr(nvl(l_node_label2,null_space),1,80) || COLON_SEPARATOR ||
9498 substr(nvl(l_node_label3,null_space),1,80);
9499
9500 end getOpNodeLabel;
9501
9502 function getJobNodeLabel(p_item_name varchar2, p_org_code varchar2,
9503 p_order_number varchar2, p_order_type varchar2, p_qty number) return varchar2 is
9504 l_node_label1 varchar2(500);
9505 l_node_label2 varchar2(500);
9506 l_node_label3 varchar2(500);
9507 begin
9508 if ( g_gantt_supply_orders_label_1 = g_job_none_lbl ) then -- {
9509 l_node_label1 := null;
9510 elsif ( g_gantt_supply_orders_label_1 = g_job_item_lbl ) then
9511 l_node_label1 := p_item_name;
9512 elsif ( g_gantt_supply_orders_label_1 = g_job_org_lbl ) then
9513 l_node_label1 := p_org_code;
9514 elsif ( g_gantt_supply_orders_label_1 = g_job_order_number_lbl ) then
9515 l_node_label1 := p_order_number;
9516 elsif ( g_gantt_supply_orders_label_1 = g_job_order_type_lbl ) then
9517 l_node_label1 := p_order_type;
9518 elsif ( g_gantt_supply_orders_label_1 = g_job_qty_lbl ) then
9519 l_node_label1 := to_char(p_qty);
9520 end if; -- }
9521
9522 if ( g_gantt_supply_orders_label_2 = g_job_none_lbl ) then -- {
9523 l_node_label2 := null;
9524 elsif ( g_gantt_supply_orders_label_2 = g_job_item_lbl ) then
9525 l_node_label2 := p_item_name;
9526 elsif ( g_gantt_supply_orders_label_2 = g_job_org_lbl ) then
9527 l_node_label2 := p_org_code;
9528 elsif ( g_gantt_supply_orders_label_2 = g_job_order_number_lbl ) then
9529 l_node_label2 := p_order_number;
9530 elsif ( g_gantt_supply_orders_label_2 = g_job_order_type_lbl ) then
9531 l_node_label2 := p_order_type;
9532 elsif ( g_gantt_supply_orders_label_2 = g_job_qty_lbl ) then
9533 l_node_label2 := to_char(p_qty);
9534 end if; -- }
9535
9536 if ( g_gantt_supply_orders_label_3 = g_job_none_lbl ) then -- {
9537 l_node_label3 := null;
9538 elsif ( g_gantt_supply_orders_label_3 = g_job_item_lbl ) then
9539 l_node_label3 := p_item_name;
9540 elsif ( g_gantt_supply_orders_label_3 = g_job_org_lbl ) then
9541 l_node_label3 := p_org_code;
9542 elsif ( g_gantt_supply_orders_label_3 = g_job_order_number_lbl ) then
9543 l_node_label3 := p_order_number;
9544 elsif ( g_gantt_supply_orders_label_3 = g_job_order_type_lbl ) then
9545 l_node_label3 := p_order_type;
9546 elsif ( g_gantt_supply_orders_label_3 = g_job_qty_lbl ) then
9547 l_node_label3 := to_char(p_qty);
9548 end if; -- }
9549
9550 if ( l_node_label1 is null and l_node_label2 is null and l_node_label3 is null ) then
9551 return null_space;
9552 end if;
9553
9554 return substr(nvl(l_node_label1,null_space),1,80) || COLON_SEPARATOR ||
9555 substr(nvl(l_node_label2,null_space),1,80) || COLON_SEPARATOR ||
9556 substr(nvl(l_node_label3,null_space),1,80);
9557
9558 end getJobNodeLabel;
9559
9560 procedure getUserPref(p_pref_id number) is
9561
9562 cursor c_pref_values (p_user number, p_pref_id number, p_plan_type number, p_from_flag number)is
9563 select mupv.key pref_key, nvl(mupv.value, mupk.default_value) pref_value
9564 from msc_user_preferences mup,
9565 msc_user_preference_keys mupk,
9566 msc_user_preference_values mupv
9567 where p_from_flag <> 0
9568 and mup.user_id = p_user
9569 and mup.preference_id = p_pref_id
9570 and mup.preference_id = mupv.preference_id
9571 and mupv.key = mupk.preference_key
9572 and mupk.plan_type = 1 -- look at only p_plan_type 1, per emily
9573 and mupv.key in ('CATEGORY_SET_ID',
9574 'GANTT_RA_ACT_LBL_1', 'GANTT_RA_ACT_LBL_2', 'GANTT_RA_ACT_LBL_3',
9575 'GANTT_RA_BATCH_LBL_1', 'GANTT_RA_BATCH_LBL_2', 'GANTT_RA_BATCH_LBL_3',
9576 'GANTT_SUP_ORD_LBL_1', 'GANTT_SUP_ORD_LBL_2', 'GANTT_SUP_ORD_LBL_3',
9577 'GANTT_OPR_LBL_1', 'GANTT_OPR_LBL_2', 'GANTT_OPR_LBL_3',
9578 'GANTT_RES_ACT_LBL_1', 'GANTT_RES_ACT_LBL_2', 'GANTT_RES_ACT_LBL_3',
9579 'GANTT_RA_TOL_DAYS_EARLY', 'GANTT_RA_TOL_DAYS_LATE', 'SUMMARY_DECIMAL_PLACES',
9580 'GANTT_RH_TOL_DAYS_EARLY', 'GANTT_RH_TOL_DAYS_LATE')
9581 union all
9582 select mupk.preference_key pref_key,
9583 mupk.default_value pref_value
9584 from msc_user_preference_keys mupk
9585 where p_from_flag = 0
9586 and mupk.plan_type = 1 -- look at only p_plan_type 1, per emily
9587 and mupk.preference_key in ('CATEGORY_SET_ID',
9588 'GANTT_RA_ACT_LBL_1', 'GANTT_RA_ACT_LBL_2', 'GANTT_RA_ACT_LBL_3',
9589 'GANTT_RA_BATCH_LBL_1', 'GANTT_RA_BATCH_LBL_2', 'GANTT_RA_BATCH_LBL_3',
9590 'GANTT_SUP_ORD_LBL_1', 'GANTT_SUP_ORD_LBL_2', 'GANTT_SUP_ORD_LBL_3',
9591 'GANTT_OPR_LBL_1', 'GANTT_OPR_LBL_2', 'GANTT_OPR_LBL_3',
9592 'GANTT_RES_ACT_LBL_1', 'GANTT_RES_ACT_LBL_2', 'GANTT_RES_ACT_LBL_3',
9593 'GANTT_RA_TOL_DAYS_EARLY', 'GANTT_RA_TOL_DAYS_LATE', 'SUMMARY_DECIMAL_PLACES',
9594 'GANTT_RH_TOL_DAYS_EARLY', 'GANTT_RH_TOL_DAYS_LATE');
9595
9596 cursor c_rows (p_pref_id number) is
9597 select count(*)
9598 from msc_user_preference_values mupv
9599 where mupv.preference_id = p_pref_id;
9600
9601 l_from_flag number;
9602
9603 cursor c_default_cat is
9604 select category_set_id
9605 from msc_category_sets
9606 where default_flag = 1;
9607
9608 l_dflt_cat_set_id number;
9609
9610 begin
9611 -- order view
9612 -- supply bar : 0 none, 1 item, 2 org, 3 order number, 4 order type, 5 qty
9613 -- op bar : 0 none, 1 op seq, 2 dept, 3 op desc
9614 -- res bar : 0 none, 1 res seq, 2 dept, 3 res, 4 setup type, 5 batch no, 6 alt flag, 7 assgned units
9615
9616 -- res activities view
9617 -- res bar : same as above
9618 -- batch bar : 0 none, 1 setup type, 2 org, 3 batch qty, 4 batch no, 5 batch util %
9619
9620 if ( g_pref_id is null or g_pref_id <> p_pref_id ) then -- {
9621 if (p_pref_id is null) then
9622 g_pref_id := mbp_null_value;
9623 else
9624 g_pref_id := p_pref_id;
9625 end if;
9626
9627 open c_rows(g_pref_id);
9628 fetch c_rows into l_from_flag;
9629 close c_rows;
9630 for c_user_pref_row in c_pref_values(fnd_global.user_id, g_pref_id, g_plan_type, l_from_flag)
9631 loop -- {
9632 if ( c_user_pref_row.pref_key = 'CATEGORY_SET_ID' ) then -- {
9633 if ( rtrim(ltrim(c_user_pref_row.pref_value)) is null) then
9634 open c_default_cat;
9635 fetch c_default_cat into l_dflt_cat_set_id;
9636 close c_default_cat;
9637 if ( l_dflt_cat_set_id is null ) then
9638 l_dflt_cat_set_id := fnd_profile.value('MSC_SRA_CATEGORY_SET');
9639 end if;
9640 g_category_set_id := l_dflt_cat_set_id;
9641 else
9642 g_category_set_id := c_user_pref_row.pref_value;
9643 end if;
9644 elsif ( c_user_pref_row.pref_key = 'GANTT_RA_ACT_LBL_1' ) then
9645 g_gantt_act_label_1 := c_user_pref_row.pref_value;
9646 elsif ( c_user_pref_row.pref_key = 'GANTT_RA_ACT_LBL_2' ) then
9647 g_gantt_act_label_2 := c_user_pref_row.pref_value;
9648 elsif ( c_user_pref_row.pref_key = 'GANTT_RA_ACT_LBL_3' ) then
9649 g_gantt_act_label_3 := c_user_pref_row.pref_value;
9650 elsif ( c_user_pref_row.pref_key = 'GANTT_RA_BATCH_LBL_1' ) then
9651 g_gantt_batches_label_1 := c_user_pref_row.pref_value;
9652 elsif ( c_user_pref_row.pref_key = 'GANTT_RA_BATCH_LBL_2' ) then
9653 g_gantt_batches_label_2 := c_user_pref_row.pref_value;
9654 elsif ( c_user_pref_row.pref_key = 'GANTT_RA_BATCH_LBL_3' ) then
9655 g_gantt_batches_label_3 := c_user_pref_row.pref_value;
9656 elsif ( c_user_pref_row.pref_key = 'GANTT_SUP_ORD_LBL_1' ) then
9657 g_gantt_supply_orders_label_1 := c_user_pref_row.pref_value;
9658 elsif ( c_user_pref_row.pref_key = 'GANTT_SUP_ORD_LBL_2' ) then
9659 g_gantt_supply_orders_label_2 := c_user_pref_row.pref_value;
9660 elsif ( c_user_pref_row.pref_key = 'GANTT_SUP_ORD_LBL_3' ) then
9661 g_gantt_supply_orders_label_3 := c_user_pref_row.pref_value;
9662 elsif ( c_user_pref_row.pref_key = 'GANTT_OPR_LBL_1' ) then
9663 g_gantt_oper_label_1 := c_user_pref_row.pref_value;
9664 elsif ( c_user_pref_row.pref_key = 'GANTT_OPR_LBL_2' ) then
9665 g_gantt_oper_label_2 := c_user_pref_row.pref_value;
9666 elsif ( c_user_pref_row.pref_key = 'GANTT_OPR_LBL_3' ) then
9667 g_gantt_oper_label_3 := c_user_pref_row.pref_value;
9668 elsif ( c_user_pref_row.pref_key = 'GANTT_RES_ACT_LBL_1' ) then
9669 g_gantt_res_act_label_1 := c_user_pref_row.pref_value;
9670 elsif ( c_user_pref_row.pref_key = 'GANTT_RES_ACT_LBL_2' ) then
9671 g_gantt_res_act_label_2 := c_user_pref_row.pref_value;
9672 elsif ( c_user_pref_row.pref_key = 'GANTT_RES_ACT_LBL_3' ) then
9673 g_gantt_res_act_label_3 := c_user_pref_row.pref_value;
9674 elsif ( c_user_pref_row.pref_key = 'GANTT_RA_TOL_DAYS_EARLY' ) then
9675 g_gantt_ra_toler_days_early := c_user_pref_row.pref_value;
9676 elsif ( c_user_pref_row.pref_key = 'GANTT_RA_TOL_DAYS_LATE' ) then
9677 g_gantt_ra_toler_days_late := c_user_pref_row.pref_value;
9678 elsif ( c_user_pref_row.pref_key = 'GANTT_RH_TOL_DAYS_EARLY' ) then
9679 g_gantt_rh_toler_days_early := c_user_pref_row.pref_value;
9680 elsif ( c_user_pref_row.pref_key = 'GANTT_RH_TOL_DAYS_LATE' ) then
9681 g_gantt_rh_toler_days_late := c_user_pref_row.pref_value;
9682 elsif ( c_user_pref_row.pref_key = 'SUMMARY_DECIMAL_PLACES' ) then
9683 if ( c_user_pref_row.pref_value is null) then
9684 round_factor := 2;
9685 else
9686 round_factor := c_user_pref_row.pref_value;
9687 end if;
9688 end if; -- }
9689 end loop; -- }
9690 end if; -- }
9691 end getUserPref;
9692
9693 procedure addToOutStream(p_one_record varchar2,
9694 p_out_data_index in out nocopy number,
9695 p_out_data in out nocopy msc_gantt_utils.maxchartbl) is
9696 begin
9697 if (nvl(length(p_out_data(1)),0) = 1) then -- {
9698 p_out_data(1) := p_one_record;
9699 elsif ( nvl(length(p_out_data(p_out_data_index)),0) + length(p_one_record) < 31000 ) then
9700 p_out_data(p_out_data_index) := p_out_data(p_out_data_index) || RECORD_SEPERATOR || p_one_record;
9701 else
9702 p_out_data_index := p_out_data_index + 1;
9703 p_out_data.extend;
9704 p_out_data(p_out_data_index) := RECORD_SEPERATOR || p_one_record;
9705 end if; -- }
9706
9707 end addToOutStream;
9708
9709 procedure parseParentLink(p_list varchar2, pQueryId in number) is
9710 occurrence NUMBER := 1;
9711 stringstart NUMBER := 1;
9712 stringend NUMBER := 1;
9713 pos NUMBER;
9714 token NUMBER;
9715 begin
9716 loop
9717 pos := INSTR(p_list, ',', 1, occurrence);
9718 occurrence := occurrence + 1;
9719 IF pos = 0 THEN
9720 stringend := LENGTH(p_list);
9721 token := to_number(SUBSTR(p_list, stringstart, stringend - stringstart + 1));
9722 if token is not null then
9723 insert into msc_form_query(
9724 query_id, last_update_date, last_updated_by, creation_date, created_by,
9725 last_update_login, number1)
9726 values (
9727 pQueryId, trunc(sysdate), -1, trunc(sysdate), -1, -1, token );
9728 end if;
9729 exit;
9730 end if;
9731 stringend := pos - 1;
9732 token := to_number(substr(p_list, stringstart, stringend - stringstart + 1));
9733 if token is not null then
9734 insert into msc_form_query(
9735 query_id, last_update_date, last_updated_by, creation_date, created_by,
9736 last_update_login, number1)
9737 values (
9738 pQueryId, trunc(sysdate), -1, trunc(sysdate), -1, -1, token);
9739 end if;
9740 stringstart := stringend + 2;
9741 end loop;
9742 end parseParentLink;
9743
9744 function getParentLinkRec(p_query_id number, p_plan_id number,
9745 p_trx number, p_parent_link varchar2) return varchar2 is
9746
9747 cursor c_alloc_qty (p_plan number, p_trx number,
9748 p_mfq_query_id number, p_mgq_query_id number) is
9749 select mgq.row_index,
9750 sum(nvl(mfp1.allocated_quantity,0)) allocated_quantity
9751 from msc_full_pegging mfp1,
9752 msc_full_pegging mfp2,
9753 msc_gantt_query mgq,
9754 msc_form_query mfq
9755 where mfp1.plan_id = p_plan
9756 and mfp1.transaction_id = p_trx
9757 and mfq.query_id = p_mfq_query_id
9758 and mgq.query_id = p_mgq_query_id
9759 and mgq.row_index = mfq.number1
9760 and mfp2.plan_id = mfp1.plan_id
9761 and mfp2.end_pegging_id = mfp1.end_pegging_id
9762 and mfp2.transaction_id = mgq.transaction_id
9763 group by mgq.row_index
9764 union all
9765 select mgq.row_index,
9766 nvl(mfp1.allocated_quantity,0) allocated_quantity
9767 from msc_full_pegging mfp1,
9768 msc_gantt_query mgq,
9769 msc_form_query mfq
9770 where mfp1.plan_id = p_plan
9771 and mfp1.transaction_id = p_trx
9772 and mfq.query_id = p_mfq_query_id
9773 and mgq.query_id = p_mgq_query_id
9774 and mgq.row_index = mfq.number1
9775 and mfp1.demand_id = mgq.transaction_id ;
9776
9777 l_mfq_query_id number;
9778 l_row_count number := 0;
9779 l_parent_link_rec varchar2(2000);
9780 begin
9781
9782 l_mfq_query_id := getMFQSequence(l_mfq_query_id);
9783 l_parent_link_rec := null;
9784 parseParentLink(p_parent_link, l_mfq_query_id);
9785
9786 put_line(' getParentLinkRec '
9787 ||' p_plan_id '|| p_plan_id
9788 ||' p_trx '|| p_trx
9789 ||' l_mfq_query_id '|| l_mfq_query_id
9790 ||' p_query_id '||p_query_id);
9791
9792 for c_alloc_qty_cur in c_alloc_qty (p_plan_id, p_trx, l_mfq_query_id, p_query_id)
9793 loop
9794 if (l_parent_link_rec is null) then
9795 l_parent_link_rec := c_alloc_qty_cur.row_index
9796 || FIELD_SEPERATOR || nvl(to_char(fnd_number.number_to_canonical(c_alloc_qty_cur.allocated_quantity)), null_space);
9797 else
9798 l_parent_link_rec := l_parent_link_rec|| FIELD_SEPERATOR ||
9799 c_alloc_qty_cur.row_index
9800 || FIELD_SEPERATOR || nvl(to_char(fnd_number.number_to_canonical(c_alloc_qty_cur.allocated_quantity)), null_space);
9801 end if;
9802 l_row_count := l_row_count + 1;
9803 end loop;
9804 l_parent_link_rec := l_row_count || FIELD_SEPERATOR || l_parent_link_rec;
9805
9806 return l_parent_link_rec;
9807 end getParentLinkRec;
9808
9809 function getResult(p_query_id number,
9810 p_from_index number, p_to_index number, p_plan_id number,
9811 p_out_data in out nocopy msc_gantt_utils.maxchartbl,
9812 p_node_level number default null,
9813 p_sort_node number default null,
9814 p_sort_column varchar2 default null,
9815 p_sort_order varchar2 default null,
9816 p_res_nodes_only varchar2 default null) return number is
9817
9818 i number;
9819
9820 l_row_index msc_gantt_utils.number_arr;
9821 l_item_prompt msc_gantt_utils.char_arr;
9822 l_node_type msc_gantt_utils.number_arr;
9823 l_node_path msc_gantt_utils.char_arr;
9824 l_parent_link msc_gantt_utils.char_arr;
9825 l_start_date msc_gantt_utils.date_arr;
9826 l_start_date_char msc_gantt_utils.char_arr;
9827 l_end_date msc_gantt_utils.date_arr;
9828 l_priority msc_gantt_utils.number_arr;
9829
9830 l_from_setup_code char_arr;
9831 l_to_setup_code char_arr;
9832 l_std_op_code char_arr;
9833 l_changeover_time char_arr;
9834 l_changeover_penalty char_arr;
9835
9836 l_critical_flag msc_gantt_utils.number_arr;
9837 l_item_name msc_gantt_utils.char_arr;
9838 l_org_code msc_gantt_utils.char_arr;
9839 l_order_type msc_gantt_utils.char_arr;
9840 l_order_type_text msc_gantt_utils.char_arr;
9841 l_order_number msc_gantt_utils.char_arr;
9842 l_qty msc_gantt_utils.number_arr;
9843 l_cepst msc_gantt_utils.date_arr;
9844 l_cepct msc_gantt_utils.date_arr;
9845 l_ulpst msc_gantt_utils.date_arr;
9846 l_ulpct msc_gantt_utils.date_arr;
9847 l_uepst msc_gantt_utils.date_arr;
9848 l_uepct msc_gantt_utils.date_arr;
9849 l_min_start_time msc_gantt_utils.date_arr;
9850 l_eacd msc_gantt_utils.date_arr;
9851 l_req_start_date msc_gantt_utils.date_arr;
9852 l_req_end_date msc_gantt_utils.date_arr;
9853 l_req_due_date msc_gantt_utils.date_arr;
9854 l_item_type msc_gantt_utils.char_arr;
9855 l_res_req_type msc_gantt_utils.char_arr;
9856 l_supply_firm_type msc_gantt_utils.number_arr;
9857 l_res_firm_type msc_gantt_utils.number_arr;
9858 l_status msc_gantt_utils.number_arr;
9859 l_applied msc_gantt_utils.number_arr;
9860 l_supplier_id msc_gantt_utils.number_arr;
9861 l_supplier_site_id msc_gantt_utils.number_arr;
9862 l_item_desc msc_gantt_utils.char_arr;
9863 l_assy_item_desc msc_gantt_utils.char_arr;
9864 l_category_name msc_gantt_utils.char_arr;
9865 l_prod_family msc_gantt_utils.char_arr;
9866 l_planner_code msc_gantt_utils.char_arr;
9867 l_planning_group msc_gantt_utils.char_arr;
9868 l_project msc_gantt_utils.char_arr;
9869 l_task msc_gantt_utils.char_arr;
9870 l_sugg_ship_date msc_gantt_utils.date_arr;
9871 l_sugg_due_date msc_gantt_utils.date_arr;
9872 l_sugg_order_date msc_gantt_utils.date_arr;
9873 l_sugg_start_date msc_gantt_utils.date_arr;
9874 l_sugg_dock_date msc_gantt_utils.date_arr;
9875 l_ship_method msc_gantt_utils.char_arr;
9876 l_transaction_id msc_gantt_utils.number_arr;
9877 l_res_transaction_id msc_gantt_utils.number_arr;
9878 l_customer msc_gantt_utils.char_arr;
9879 l_customer_site msc_gantt_utils.char_arr;
9880 l_source_org msc_gantt_utils.char_arr;
9881 l_supplier msc_gantt_utils.char_arr;
9882 l_supplier_site msc_gantt_utils.char_arr;
9883 l_sched_group msc_gantt_utils.char_arr;
9884 l_actual_start_date msc_gantt_utils.date_arr;
9885
9886 l_sr_instance_id msc_gantt_utils.number_arr;
9887 l_organization_id msc_gantt_utils.number_arr;
9888 l_inventory_item_id msc_gantt_utils.number_arr;
9889 l_dept_id msc_gantt_utils.number_arr;
9890 l_res_id msc_gantt_utils.number_arr;
9891
9892 l_dept_code msc_gantt_utils.char_arr;
9893 l_res_code msc_gantt_utils.char_arr;
9894 l_res_desc msc_gantt_utils.char_arr;
9895 l_op_seq msc_gantt_utils.char_arr;
9896 l_op_desc msc_gantt_utils.char_arr;
9897 l_adjusted_res_hours msc_gantt_utils.number_arr;
9898 l_schedule_qty msc_gantt_utils.number_arr;
9899 l_batch_number msc_gantt_utils.char_arr;
9900 l_assigned_units msc_gantt_utils.number_arr;
9901 l_alternate_flag msc_gantt_utils.char_arr;
9902 l_res_seq msc_gantt_utils.char_arr;
9903 l_wip_status_text msc_gantt_utils.char_arr;
9904 l_setup_type_text msc_gantt_utils.char_arr;
9905 l_alternate_num msc_gantt_utils.char_arr;
9906
9907 l_demand_class msc_gantt_utils.char_arr;
9908 l_material_avail_date msc_gantt_utils.date_arr;
9909 l_bar_text msc_gantt_utils.char_arr;
9910
9911 l_one_record varchar2(4000);
9912 l_out_data_index number := 1;
9913
9914 l_mfq_query_id number;
9915
9916 TYPE GanttCurTyp IS REF CURSOR;
9917 the_cursor GanttCurTyp;
9918 sql_stmt varchar2(32000);
9919 sort_columns varchar2(1000);
9920 node_level_stmt varchar2(200);
9921
9922 l_parent_link_rec varchar2(2000);
9923
9924 begin
9925 put_line('getResult in ');
9926 sort_columns := ' ORDERS ITEM ITEM_CATEGORY ITEM_DESC PRODUCT_FAMILY PLANNER PLN_GROUP PROJECT TASK ';
9927 sort_columns := sort_columns ||' SUGG_ORDER_DATE SUGG_START_DATE SUGG_SHIP_DATE SUGG_DOCK_DATE SUGG_DUE_DATE ';
9928 sort_columns := sort_columns ||' ORGANIZATION DEPARTMENT RESOURCE LINE SR_ORG SUPPLIER SUPPLIER_SITE SHIP_METHOD ';
9929 sort_columns := sort_columns ||' ORDER_TYPE ORDER_NUMBER SCHEDULE_GROUP CUSTOMER CUSTOMER_SITE ';
9930 sort_columns := sort_columns ||' REQ_START_DATE REQ_COMPL_DATE QUANTITY ADJ_RESOURCE_HR ASSIGNED_UNITS ';
9931 sort_columns := sort_columns ||' BATCH ALTERNATE WIP_STATUS OPER_DESC OWN_DEPT RES_TYPE EQUIP_NUMBER BUYER ';
9932
9933 if ( p_sort_column is not null and ( instr(sort_columns, upper(p_sort_column)) <= 0) ) then
9934 put_line(' error in sort option');
9935 return SYS_NO;
9936 end if;
9937
9938 if ( p_node_level is not null ) then
9939 node_level_stmt := node_level_stmt ||' and mgq.node_level between '
9940 ||' (-1 * abs('||p_node_level||')) and abs('||p_node_level||') ';
9941 else
9942 node_level_stmt := null_space;
9943 end if;
9944
9945
9946 --Demand Node Info
9947 sql_stmt := ' select mgq.row_index,
9948 msc_get_name.demand_order_number ( md.plan_id, md.sr_instance_id, md.demand_id )
9949 ||'' for ''||msi.item_name ||'' in '' || mtp.organization_code ORDERS,
9950 mgq.node_type,
9951 mgq.node_path,
9952 mgq.parent_link,
9953 nvl(mgq.critical_flag,0) critical_flag,
9954 msi.item_name ITEM,
9955 mtp.organization_code ORGANIZATION,
9956 md.origination_type order_type_id,
9957 msc_get_name.lookup_meaning(''MRP_DEMAND_ORIGINATION'', md.origination_type) ORDER_TYPE,
9958 msc_get_name.demand_order_number ( md.plan_id, md.sr_instance_id, md.demand_id )
9959 ORDER_NUMBER,
9960 decode(md.customer_id, null,
9961 msc_get_name.get_other_customers(md.plan_id, md.schedule_designator_id),
9962 msc_get_name.customer(md.customer_id)) CUSTOMER,
9963 decode(md.customer_site_id, null,
9964 msc_get_name.get_other_customers(md.plan_id,md.schedule_designator_id),
9965 msc_get_name.customer_site(md.customer_site_id)) CUSTOMER_SITE,
9966 md.using_assembly_demand_date start_date,
9967 nvl(md.dmd_satisfied_date,md.using_assembly_demand_date) end_date,
9968 demand_priority,
9969 --md.quantity_by_due_date QUANTITY,
9970 md.using_requirement_quantity QUANTITY,
9971 msi.description ITEM_DESC,
9972 mic.category_name ITEM_CATEGORY,
9973 msc_get_name.item_name(msi.product_family_id,null,null,null) PRODUCT_FAMILY,
9974 msi.planner_code PLANNER,
9975 md.planning_group PLN_GROUP,
9976 decode(md.project_id, null, null, msc_get_name.project(md.project_id,
9977 md.organization_id, md.plan_id, md.sr_instance_id)) PROJECT,
9978 decode(md.task_id, null, null, msc_get_name.task(md.task_id,
9979 md.project_id,md.organization_id, md.plan_id, md.sr_instance_id)) TASK,
9980 md.planned_ship_date SUGG_SHIP_DATE,
9981 md.using_assembly_demand_date SUGG_DUE_DATE,
9982 md.ship_method SHIP_METHOD,
9983 md.demand_id transaction_id,
9984 md.sr_instance_id,
9985 md.organization_id,
9986 md.inventory_item_id,
9987 md.demand_class,
9988 md.dmd_satisfied_date material_avail_date
9989 from msc_demands md,
9990 msc_system_items msi,
9991 msc_item_categories mic,
9992 msc_trading_partners mtp,
9993 msc_gantt_query mgq
9994 where mgq.query_id = :p_query_id
9995 and mgq.node_type = :END_DEMAND_NODE
9996 and mgq.row_index between :p_from_index and :p_to_index
9997 and md.plan_id = :p_plan_id
9998 and md.sr_instance_id = mgq.sr_instance_id
9999 and md.demand_id = mgq.transaction_id
10000 and md.plan_id = msi.plan_id
10001 and md.sr_instance_id = msi.sr_instance_id
10002 and md.organization_id = msi.organization_id
10003 and md.inventory_item_id = msi.inventory_item_id
10004 and msi.sr_instance_id = mic.sr_instance_id
10005 and msi.organization_id = mic.organization_id
10006 and msi.inventory_item_id = mic.inventory_item_id
10007 and mic.category_set_id = :g_category_set_id
10008 and mtp.partner_type = 3
10009 and mtp.sr_tp_id = md.organization_id
10010 and mtp.sr_instance_id = md.sr_instance_id ';
10011
10012 sql_stmt := sql_stmt || node_level_stmt;
10013 --node level logic
10014
10015 put_line(' g_category_set_id '||g_category_set_id);
10016
10017 if ( p_sort_column is not null and nvl(p_sort_node, END_DEMAND_NODE) = END_DEMAND_NODE ) then
10018 sql_stmt := sql_stmt ||' order by '||p_sort_column||' '||p_sort_order;
10019 end if;
10020
10021 open the_cursor for sql_stmt
10022 using p_query_id, END_DEMAND_NODE, p_from_index, p_to_index, p_plan_id, g_category_set_id;
10023 fetch the_cursor bulk collect into l_row_index, l_item_prompt, l_node_type, l_node_path, l_parent_link,
10024 l_critical_flag, l_item_name, l_org_code, l_order_type, l_order_type_text,
10025 l_order_number, l_customer, l_customer_site, l_start_date, l_end_date, l_priority,
10026 l_qty, l_item_desc, l_category_name, l_prod_family, l_planner_code, l_planning_group,
10027 l_project, l_task, l_sugg_ship_date, l_sugg_due_date, l_ship_method, l_transaction_id,
10028 l_sr_instance_id, l_organization_id, l_inventory_item_id,
10029 l_demand_class, l_material_avail_date;
10030 close the_cursor;
10031
10032 put_line(' demands count '||l_row_index.count);
10033 for i in 1..l_row_index.count
10034 loop -- {
10035 l_one_record := l_row_index(i)
10036 || FIELD_SEPERATOR || escapeSplChars(l_item_prompt(i))
10037 || FIELD_SEPERATOR || l_node_type(i)
10038 || FIELD_SEPERATOR || l_node_path(i)
10039 || FIELD_SEPERATOR || nvl(l_parent_link(i), null_space)
10040 || FIELD_SEPERATOR || nvl(to_char(l_critical_flag(i)), 0)
10041 || FIELD_SEPERATOR || escapeSplChars(l_item_name(i))
10042 || FIELD_SEPERATOR || escapeSplChars(l_org_code(i))
10043 || FIELD_SEPERATOR || l_order_type(i)
10044 || FIELD_SEPERATOR || escapeSplChars(l_order_type_text(i))
10045 || FIELD_SEPERATOR || nvl(escapeSplChars(l_order_number(i)),null_space)
10046 || FIELD_SEPERATOR || nvl(escapeSplChars(l_customer(i)), null_space)
10047 || FIELD_SEPERATOR || nvl(escapeSplChars(l_customer_site(i)), null_space)
10048 || FIELD_SEPERATOR || nvl(to_char(l_start_date(i),format_mask), null_space)
10049 || FIELD_SEPERATOR || nvl(to_char(l_end_date(i),format_mask), null_space)
10050 || FIELD_SEPERATOR || nvl(to_char(l_priority(i)),null_space)
10051 || FIELD_SEPERATOR || to_char(round(nvl(fnd_number.number_to_canonical(l_qty(i)),0), round_factor))
10052 || FIELD_SEPERATOR || nvl(escapeSplChars(l_item_desc(i)),null_space)
10053 || FIELD_SEPERATOR || nvl(escapeSplChars(l_category_name(i)),null_space)
10054 || FIELD_SEPERATOR || nvl(escapeSplChars(l_prod_family(i)),null_space)
10055 || FIELD_SEPERATOR || nvl(escapeSplChars(l_planner_code(i)),null_space)
10056 || FIELD_SEPERATOR || nvl(escapeSplChars(l_planning_group(i)),null_space)
10057 || FIELD_SEPERATOR || nvl(escapeSplChars(l_project(i)),null_space)
10058 || FIELD_SEPERATOR || nvl(escapeSplChars(l_task(i)),null_space)
10059 || FIELD_SEPERATOR || nvl(to_char(l_sugg_ship_date(i),format_mask), null_space)
10060 || FIELD_SEPERATOR || nvl(to_char(l_sugg_due_date(i),format_mask), null_space)
10061 || FIELD_SEPERATOR || nvl(escapeSplChars(l_ship_method(i)), null_space)
10062 || FIELD_SEPERATOR || l_transaction_id(i)
10063 || FIELD_SEPERATOR || null_space
10064 || FIELD_SEPERATOR || l_sr_instance_id(i)
10065 || FIELD_SEPERATOR || l_organization_id(i)
10066 || FIELD_SEPERATOR || l_inventory_item_id(i)
10067 || FIELD_SEPERATOR || nvl(escapeSplChars(l_demand_class(i)), null_space)
10068 || FIELD_SEPERATOR || nvl(to_char(l_material_avail_date(i),format_mask), null_space);
10069
10070 addToOutStream(l_one_record, l_out_data_index, p_out_data);
10071
10072 put_line(l_row_index(i) || FIELD_SEPERATOR || l_item_prompt(i));
10073 end loop; -- }
10074
10075 --Supply/Co-prod Node Info
10076 sql_stmt := ' select mgq.row_index,
10077 decode(ms.order_type, 18, msc_get_name.lookup_meaning(''MRP_ORDER_TYPE'', 18),
10078 msc_get_name.supply_order_number(ms.order_type, ms.order_number, ms.plan_id,
10079 ms.sr_instance_id, ms.transaction_id, ms.disposition_id)) ||'' for ''||
10080 msi.item_name ||'' in '' || mtp.organization_code ||''(''|| round(ms.new_order_quantity,:round_factor)||'')'' ORDERS,
10081 mgq.node_type,
10082 mgq.node_path,
10083 mgq.parent_link,
10084 mgq.critical_flag,
10085 msi.item_name ITEM,
10086 mtp.organization_code ORGANIZATION,
10087 to_char(least(to_date(msc_gantt_utils.getActualStartDate(ms.order_type, msi.planning_make_buy_code,
10088 ms.organization_id, ms.source_organization_id, ms.new_dock_date,
10089 ms.new_wip_start_date, ms.new_ship_date,ms.new_schedule_date, ms.source_supplier_id), :format_mask),
10090 nvl(ms.firm_date, ms.new_schedule_date)),:format_mask) start_date,
10091 nvl(ms.firm_date, ms.new_schedule_date) end_date,
10092 ms.order_type order_type_id,
10093 mfg.meaning ORDER_TYPE,
10094 msc_get_name.supply_order_number(ms.order_type, ms.order_number, ms.plan_id,
10095 ms.sr_instance_id, ms.transaction_id, ms.disposition_id) order_number,
10096 ms.new_order_quantity QUANTITY,
10097 ms.earliest_start_date,
10098 ms.earliest_completion_date,
10099 ms.ulpsd,
10100 ms.ulpcd,
10101 ms.uepsd,
10102 ms.uepcd,
10103 ms.min_start_date,
10104 ms.requested_start_date REQ_START_DATE,
10105 ms.requested_completion_date REQ_COMPL_DATE,
10106 msi.planning_make_buy_code item_type,
10107 nvl(ms.firm_planned_type,2) supply_firm_type,
10108 nvl(ms.status, 0) status,
10109 nvl(ms.applied, 0) applied,
10110 nvl(ms.supplier_id, 0) supplier_id,
10111 nvl(ms.supplier_site_id, 0) supplier_site_id,
10112 msi.description ITEM_DESC,
10113 mic.category_name ITEM_CATEGORY,
10114 msc_get_name.item_name(msi.product_family_id,null,null,null) PRODUCT_FAMILY,
10115 msi.planner_code PLANNER,
10116 ms.planning_group PLN_GROUP,
10117 decode(ms.project_id, null, null, msc_get_name.project(ms.project_id,
10118 ms.organization_id, ms.plan_id, ms.sr_instance_id)) PROJECT,
10119 decode(ms.task_id, null, null, msc_get_name.task(ms.task_id,
10120 ms.project_id, ms.organization_id, ms.plan_id, ms.sr_instance_id)) TASK,
10121 ms.new_order_placement_date SUGG_ORDER_DATE,
10122 ms.new_wip_start_date SUGG_START_DATE,
10123 ms.new_ship_date SUGG_SHIP_DATE,
10124 ms.new_dock_date SUGG_DOCK_DATE,
10125 ms.new_schedule_date SUGG_DUE_DATE,
10126 msc_get_name.org_code(ms.source_organization_id, ms.source_sr_instance_id) SR_ORG,
10127 msc_get_name.supplier(ms.supplier_id) SUPPLIER,
10128 msc_get_name.supplier_site(ms.supplier_site_id) SUPPLIER_SITE,
10129 ms.ship_method SHIP_METHOD,
10130 ms.schedule_group_name SCHEDULE_GROUP,
10131 ms.transaction_id transaction_id,
10132 ms.sr_instance_id,
10133 ms.organization_id,
10134 ms.inventory_item_id,
10135 ms.schedule_priority,
10136 msi.description,
10137 msc_get_name.lookup_meaning(''WIP_JOB_STATUS'', ms.wip_status_code) wip_status_text,
10138 ms.new_schedule_date,
10139 ms.actual_start_date
10140 from msc_supplies ms,
10141 msc_system_items msi,
10142 msc_item_categories mic,
10143 msc_trading_partners mtp,
10144 mfg_lookups mfg,
10145 msc_gantt_query mgq
10146 where mgq.query_id = :p_query_id
10147 and mgq.node_type in (:JOB_NODE, :COPROD_NODE)
10148 and mgq.row_index between :p_from_index and :p_to_index
10149 and ms.plan_id = :p_plan_id
10150 and ms.sr_instance_id = mgq.sr_instance_id
10151 and ms.transaction_id = mgq.transaction_id
10152 and ms.plan_id = msi.plan_id
10153 and ms.organization_id = msi.organization_id
10154 and ms.sr_instance_id = msi.sr_instance_id
10155 and ms.inventory_item_id = msi.inventory_item_id
10156 and msi.sr_instance_id = mic.sr_instance_id
10157 and msi.organization_id = mic.organization_id
10158 and msi.inventory_item_id = mic.inventory_item_id
10159 and mic.category_set_id = :g_category_set_id
10160 and mfg.lookup_type = ''MRP_ORDER_TYPE''
10161 and mfg.lookup_code = ms.order_type
10162 and mtp.partner_type = 3
10163 and mtp.sr_tp_id = ms.organization_id
10164 and mtp.sr_instance_id = ms.sr_instance_id ';
10165
10166 sql_stmt := sql_stmt || node_level_stmt;
10167 --node level logic
10168
10169 if ( p_sort_column is not null and nvl(p_sort_node, JOB_NODE) in (JOB_NODE, COPROD_NODE) ) then
10170 sql_stmt := sql_stmt ||' order by '||p_sort_column||' '||p_sort_order;
10171 else
10172 sql_stmt := sql_stmt ||' order by mgq.row_index ';
10173 end if;
10174
10175 open the_cursor for sql_stmt
10176 using round_factor, format_mask, format_mask, p_query_id, JOB_NODE ,COPROD_NODE, p_from_index, p_to_index, p_plan_id, g_category_set_id;
10177 fetch the_cursor bulk collect into l_row_index, l_item_prompt, l_node_type, l_node_path, l_parent_link,
10178 l_critical_flag, l_item_name, l_org_code, l_start_date_char, l_end_date,
10179 l_order_type, l_order_type_text, l_order_number, l_qty,
10180 l_cepst, l_cepct, l_ulpst, l_ulpct, l_uepst, l_uepct, l_min_start_time,
10181 l_req_start_date, l_req_end_date, l_item_type,
10182 l_supply_firm_type, l_status, l_applied, l_supplier_id, l_supplier_site_id,
10183 l_item_desc, l_category_name, l_prod_family, l_planner_code, l_planning_group, l_project,
10184 l_task, l_sugg_order_date, l_sugg_start_date, l_sugg_ship_date, l_sugg_dock_date,
10185 l_sugg_due_date, l_source_org, l_supplier, l_supplier_site, l_ship_method,
10186 l_sched_group, l_transaction_id, l_sr_instance_id, l_organization_id, l_inventory_item_id,
10187 l_priority, l_item_desc, l_wip_status_text, l_req_end_date, l_actual_start_date;
10188 close the_cursor;
10189
10190 put_line(' supplies count '||l_row_index.count);
10191 for i in 1..l_row_index.count
10192 loop -- {
10193 l_parent_link_rec := null;
10194 -- find allocated quantity
10195 if (l_parent_link(i) is not null) then
10196 l_parent_link_rec := getParentLinkRec(p_query_id, p_plan_id, l_transaction_id(i), l_parent_link(i));
10197 put_line(' parent link for '||l_transaction_id(i)|| ' ' || l_parent_link_rec);
10198 end if;
10199
10200 l_one_record := l_row_index(i)
10201 || FIELD_SEPERATOR || escapeSplChars(l_item_prompt(i))
10202 || FIELD_SEPERATOR || l_node_type(i)
10203 || FIELD_SEPERATOR || l_node_path(i)
10204 || FIELD_SEPERATOR || nvl(to_char(l_parent_link_rec), null_space)
10205 || FIELD_SEPERATOR || nvl(to_char(l_critical_flag(i)), 0)
10206 || FIELD_SEPERATOR || escapeSplChars(l_item_name(i))
10207 || FIELD_SEPERATOR || nvl(l_start_date_char(i), null_space)
10208 || FIELD_SEPERATOR || nvl(to_char(l_end_date(i),format_mask),null_space)
10209 || FIELD_SEPERATOR || escapeSplChars(l_org_code(i))
10210 || FIELD_SEPERATOR || l_order_type(i)
10211 || FIELD_SEPERATOR || escapeSplChars(l_order_type_text(i))
10212 || FIELD_SEPERATOR || nvl(escapeSplChars(l_order_number(i)), null_space)
10213 || FIELD_SEPERATOR || to_char(round(nvl(fnd_number.number_to_canonical(l_qty(i)),0), round_factor))
10214 || FIELD_SEPERATOR || nvl(to_char(l_cepst(i),format_mask),null_space)
10215 || FIELD_SEPERATOR || nvl(to_char(l_cepct(i),format_mask),null_space)
10216 || FIELD_SEPERATOR || nvl(to_char(l_ulpst(i),format_mask),null_space)
10217 || FIELD_SEPERATOR || nvl(to_char(l_ulpct(i),format_mask),null_space)
10218 || FIELD_SEPERATOR || nvl(to_char(l_uepst(i),format_mask),null_space)
10219 || FIELD_SEPERATOR || nvl(to_char(l_uepct(i),format_mask),null_space)
10220 || FIELD_SEPERATOR || nvl(to_char(l_min_start_time(i),format_mask),null_space)
10221 || FIELD_SEPERATOR || escapeSplChars(l_item_type(i))
10222 || FIELD_SEPERATOR || l_supply_firm_type(i)
10223 || FIELD_SEPERATOR || l_status(i)
10224 || FIELD_SEPERATOR || l_applied(i)
10225 || FIELD_SEPERATOR || l_supplier_id(i)
10226 || FIELD_SEPERATOR || l_supplier_site_id(i)
10227 || FIELD_SEPERATOR || nvl(escapeSplChars(l_item_desc(i)),null_space)
10228 || FIELD_SEPERATOR || nvl(escapeSplChars(l_category_name(i)),null_space)
10229 || FIELD_SEPERATOR || nvl(escapeSplChars(l_prod_family(i)),null_space)
10230 || FIELD_SEPERATOR || nvl(escapeSplChars(l_planner_code(i)),null_space)
10231 || FIELD_SEPERATOR || nvl(escapeSplChars(l_planning_group(i)),null_space)
10232 || FIELD_SEPERATOR || nvl(escapeSplChars(l_project(i)),null_space)
10233 || FIELD_SEPERATOR || nvl(escapeSplChars(l_task(i)),null_space)
10234 || FIELD_SEPERATOR || nvl(to_char(l_sugg_order_date(i),format_mask),null_space)
10235 || FIELD_SEPERATOR || nvl(to_char(l_sugg_start_date(i),format_mask),null_space)
10236 || FIELD_SEPERATOR || nvl(to_char(l_sugg_ship_date(i),format_mask),null_space)
10237 || FIELD_SEPERATOR || nvl(to_char(l_sugg_dock_date(i),format_mask),null_space)
10238 || FIELD_SEPERATOR || nvl(to_char(l_sugg_due_date(i),format_mask),null_space)
10239 || FIELD_SEPERATOR || nvl(escapeSplChars(l_source_org(i)),null_space)
10240 || FIELD_SEPERATOR || nvl(escapeSplChars(l_supplier(i)),null_space)
10241 || FIELD_SEPERATOR || nvl(escapeSplChars(l_supplier_site(i)),null_space)
10242 || FIELD_SEPERATOR || nvl(escapeSplChars(l_ship_method(i)),null_space)
10243 || FIELD_SEPERATOR || nvl(escapeSplChars(l_sched_group(i)),null_space)
10244 || FIELD_SEPERATOR || l_transaction_id(i)
10245 || FIELD_SEPERATOR || nvl(to_char(l_req_start_date(i),format_mask),null_space)
10246 || FIELD_SEPERATOR || nvl(to_char(l_req_end_date(i),format_mask),null_space)
10247 || FIELD_SEPERATOR || escapeSplChars(msc_gantt_utils.getJobNodeLabel(l_item_name(i), l_org_code(i),
10248 l_order_number(i), l_order_type_text(i), l_qty(i)))
10249 || FIELD_SEPERATOR || l_sr_instance_id(i)
10250 || FIELD_SEPERATOR || l_organization_id(i)
10251 || FIELD_SEPERATOR || l_inventory_item_id(i)
10252 || FIELD_SEPERATOR || nvl(to_char(l_priority(i)), null_space)
10253 || FIELD_SEPERATOR || nvl(escapeSplChars(l_item_desc(i)), null_space)
10254 || FIELD_SEPERATOR || nvl(to_char(l_req_end_date(i),format_mask),null_space)
10255 || FIELD_SEPERATOR || nvl(to_char(l_wip_status_text(i)),null_space)
10256 || FIELD_SEPERATOR || nvl(to_char(l_actual_start_date(i),format_mask),null_space);
10257
10258 addToOutStream(l_one_record, l_out_data_index, p_out_data);
10259
10260 put_line(l_row_index(i) || FIELD_SEPERATOR || l_item_prompt(i));
10261 end loop; -- }
10262
10263 --Op Node Info
10264 sql_stmt := ' select mgq.row_index,
10265 mgq.op_seq_num,
10266 mgq.node_type,
10267 mgq.node_path,
10268 decode(mgq.dependency_type,
10269 null, null,
10270 mgq.dependency_type||:FIELD_SEPERATOR || mgq.parent_link),
10271 mgq.op_desc,
10272 mgq.transaction_id
10273 from msc_gantt_query mgq
10274 where mgq.query_id = :p_query_id
10275 and mgq.node_type = :OP_NODE
10276 and substr(mgq.node_path ,1, instr(mgq.node_path, :COLON_SEPARATOR)-1)
10277 between :p_from_index and :p_to_index '|| node_level_stmt || '
10278 order by to_number(substr(mgq.node_path ,1, instr(mgq.node_path, :COLON_SEPARATOR)-1)),
10279 to_number(substr(mgq.node_path , instr(mgq.node_path, :COLON_SEPARATOR)+1))';
10280
10281 open the_cursor for sql_stmt
10282 using FIELD_SEPERATOR, p_query_id, OP_NODE, COLON_SEPARATOR, p_from_index, p_to_index, COLON_SEPARATOR, COLON_SEPARATOR;
10283 fetch the_cursor bulk collect into l_row_index, l_item_prompt, l_node_type,
10284 l_node_path, l_parent_link, l_op_desc, l_transaction_id;
10285 close the_cursor;
10286
10287 put_line(' op count '||l_row_index.count);
10288 for i in 1..l_row_index.count
10289 loop -- {
10290 l_one_record := l_row_index(i)
10291 || FIELD_SEPERATOR || escapeSplChars(l_item_prompt(i))
10292 || FIELD_SEPERATOR || l_node_type(i)
10293 || FIELD_SEPERATOR || l_node_path(i)
10294 || FIELD_SEPERATOR || nvl(l_parent_link(i), null_space)
10295 || FIELD_SEPERATOR || nvl(escapeSplChars(l_op_desc(i)), null_space)
10296 || FIELD_SEPERATOR || escapeSplChars(msc_gantt_utils.getOpNodeLabel(l_item_prompt(i), l_transaction_id(i),
10297 l_op_desc(i), p_plan_id));
10298
10299 addToOutStream(l_one_record, l_out_data_index, p_out_data);
10300
10301 put_line(l_row_index(i) || FIELD_SEPERATOR || l_item_prompt(i));
10302 end loop; -- }
10303
10304 --Resource Node Info
10305 sql_stmt := ' select mgq.row_index,
10306 to_char(mrr.operation_seq_num)||''/''||to_char(mrr.resource_seq_num)||
10307 ''(''||msc_get_name.department_resource_code(mrr.resource_id,
10308 mrr.department_id, mrr.organization_id, mrr.plan_id, mrr.sr_instance_id)||'')'',
10309 mgq.node_type,
10310 mgq.node_path,
10311 mgq.parent_link,
10312 mdr.department_code,
10313 mdr.resource_code,
10314 msc_gantt_utils.getResReqStartDate(nvl(mrr.firm_flag,0),
10315 mrr.start_date, mrr.end_date,mrr.firm_start_date, mrr.firm_end_date, mrr.status, mrr.applied) start_date,
10316 msc_gantt_utils.getResReqEndDate(nvl(mrr.firm_flag,0), mrr.start_date, mrr.end_date,
10317 mrr.firm_start_date, mrr.firm_end_date, mrr.status, mrr.applied) end_date,
10318 ms.new_order_quantity QUANTITY,
10319 mrr.resource_hours adjusted_res_hours,
10320 mrr.batch_number,
10321 mrr.assigned_units,
10322 msc_get_name.alternate_rtg(mrr.plan_id, mrr.sr_instance_id, mrr.routing_sequence_id),
10323 msc_get_name.lookup_meaning(''WIP_JOB_STATUS'', ms.wip_status_code) wip_status_text,
10324 nvl(ms.firm_planned_type,2) supply_firm_type,
10325 nvl(mrr.firm_flag,0) res_firm_type,
10326 nvl(mrr.status, 0) status,
10327 nvl(mrr.applied, 0) applied,
10328 msc_gantt_utils.getResReqType(mrr.plan_id, mrr.schedule_flag, mrr.parent_seq_num, mrr.setup_id) res_req_type,
10329 mrr.supply_id transaction_id,
10330 mrr.transaction_id res_transaction_id,
10331 mrr.resource_seq_num,
10332 decode(mrr.setup_id, to_number(null), null,
10333 msc_gantt_utils.getSetupCode(mrr.plan_id, mrr.sr_instance_id, mrr.resource_id, mrr.setup_id)),
10334 mrr.earliest_start_date,
10335 mrr.earliest_completion_date,
10336 mrr.ulpsd,
10337 mrr.ulpcd,
10338 mrr.uepsd,
10339 mrr.uepcd,
10340 mrr.eacd,
10341 mrr.sr_instance_id,
10342 mrr.organization_id,
10343 mrr.department_id,
10344 mrr.resource_id,
10345 ms.inventory_item_id,
10346 msc_get_name.supply_order_number(ms.order_type, ms.order_number, ms.plan_id,
10347 ms.sr_instance_id, ms.transaction_id, ms.disposition_id) order_number,
10348 mrr.operation_seq_num,
10349 mdr.resource_description,
10350 mi.item_name item,
10351 mi2.description assembly_item_desc,
10352 decode(mrr.resource_hours, 0, to_number(null),
10353 nvl(mrr.cummulative_quantity,ms.new_order_quantity)) schedule_qty,
10354 msc_gantt_utils.getOrderViewResNodeLabel(mrr.plan_id, mrr.sr_instance_id,
10355 mrr.transaction_id) bar_text,
10356 mrr.alternate_num,
10357 mrr.actual_start_date,
10358 mgq.critical_flag
10359 from msc_resource_requirements mrr,
10360 msc_department_resources mdr,
10361 msc_supplies ms,
10362 msc_items mi,
10363 msc_items mi2,
10364 msc_trading_partners mtp,
10365 msc_gantt_query mgq
10366 where mgq.query_id = :p_query_id
10367 and mgq.node_type = :RES_NODE
10368 and ( ( nvl(:p_res_nodes_only,2) = 2
10369 and substr(mgq.node_path ,1, instr(mgq.node_path, :COLON_SEPARATOR)-1)
10370 between :p_from_index and :p_to_index)
10371 or ( nvl(:p_res_nodes_only,2) = 1
10372 and mgq.row_index between :p_from_index and :p_to_index)
10373 )
10374 and mrr.plan_id = :p_plan_id
10375 and mrr.sr_instance_id = mgq.sr_instance_id
10376 and mrr.organization_id = mgq.organization_id
10377 and mrr.transaction_id = mgq.transaction_id
10378 and mrr.parent_id = 2
10379 and mrr.end_date is not null
10380 and mrr.department_id <> -1
10381 and mrr.plan_id = mdr.plan_id
10382 and mrr.organization_id = mdr.organization_id
10383 and mrr.sr_instance_id = mdr.sr_instance_id
10384 and mrr.department_id = mdr.department_id
10385 and mrr.resource_id = mdr.resource_id
10386 and mrr.plan_id = ms.plan_id
10387 and mrr.supply_id = ms.transaction_id
10388 and mrr.sr_instance_id = ms.sr_instance_id
10389 and mtp.partner_type = 3
10390 and mtp.sr_tp_id = ms.organization_id
10391 and mtp.sr_instance_id = ms.sr_instance_id
10392 and ms.inventory_item_id = mi.inventory_item_id
10393 and mrr.assembly_item_id = mi2.inventory_item_id '|| node_level_stmt || '
10394 order by to_number(substr(mgq.node_path ,1, instr(mgq.node_path, :COLON_SEPARATOR)-1)),
10395 to_number(substr(mgq.node_path, instr(mgq.node_path, :COLON_SEPARATOR,1,1)+1,
10396 instr(mgq.node_path, :COLON_SEPARATOR,1,2)-instr(mgq.node_path, :COLON_SEPARATOR,1,1)-1)),
10397 to_number(substr(mgq.node_path , instr(mgq.node_path,:COLON_SEPARATOR,1,2)+1)) ';
10398
10399 open the_cursor for sql_stmt
10400 using p_query_id, RES_NODE, p_res_nodes_only, COLON_SEPARATOR, p_from_index, p_to_index,
10401 p_res_nodes_only, p_from_index, p_to_index,
10402 p_plan_id,
10403 COLON_SEPARATOR, COLON_SEPARATOR, COLON_SEPARATOR, COLON_SEPARATOR, COLON_SEPARATOR;
10404
10405 fetch the_cursor bulk collect into l_row_index, l_item_prompt, l_node_type,
10406 l_node_path, l_parent_link, l_dept_code, l_res_code, l_start_date, l_end_date,
10407 l_qty, l_adjusted_res_hours, l_batch_number, l_assigned_units, l_alternate_flag,
10408 l_wip_status_text, l_supply_firm_type, l_res_firm_type, l_status, l_applied,
10409 l_res_req_type, l_transaction_id, l_res_transaction_id, l_res_seq, l_setup_type_text,
10410 l_cepst, l_cepct, l_ulpst, l_ulpct, l_uepst, l_uepct, l_eacd, l_sr_instance_id,
10411 l_organization_id, l_dept_id, l_res_id, l_inventory_item_id, l_order_number,
10412 l_op_seq, l_res_desc, l_item_name, l_assy_item_desc, l_schedule_qty, l_bar_text,
10413 l_alternate_num, l_actual_start_date, l_critical_flag;
10414 close the_cursor;
10415
10416 put_line(' res count '||l_row_index.count);
10417 for i in 1..l_row_index.count
10418 loop -- {
10419 if( nvl(p_res_nodes_only,sys_no) = sys_yes) then
10420 l_one_record := l_row_index(i)
10421 || FIELD_SEPERATOR || nvl(to_char(l_start_date(i), format_mask), null_space)
10422 || FIELD_SEPERATOR || nvl(to_char(l_end_date(i), format_mask), null_space);
10423 else
10424 l_one_record := l_row_index(i)
10425 || FIELD_SEPERATOR || escapeSplChars(l_item_prompt(i))
10426 || FIELD_SEPERATOR || l_node_type(i)
10427 || FIELD_SEPERATOR || l_node_path(i)
10428 || FIELD_SEPERATOR || nvl(to_char(l_parent_link(i)), null_space)
10429 || FIELD_SEPERATOR || escapeSplChars(l_dept_code(i))
10430 || FIELD_SEPERATOR || escapeSplChars(l_res_code(i))
10431 || FIELD_SEPERATOR || nvl(to_char(l_start_date(i), format_mask), null_space)
10432 || FIELD_SEPERATOR || nvl(to_char(l_end_date(i), format_mask), null_space)
10433 || FIELD_SEPERATOR || nvl(to_char(round(nvl(fnd_number.number_to_canonical(l_qty(i)),0),round_factor)), null_space)
10434 || FIELD_SEPERATOR || nvl(to_char(fnd_number.number_to_canonical(l_adjusted_res_hours(i))), null_space)
10435 || FIELD_SEPERATOR || nvl(to_char(l_batch_number(i)), null_space)
10436 || FIELD_SEPERATOR || nvl(to_char(fnd_number.number_to_canonical(l_assigned_units(i))), null_space)
10437 || FIELD_SEPERATOR || nvl(escapeSplChars(to_char(l_alternate_flag(i))), null_space)
10438 || FIELD_SEPERATOR || nvl(escapeSplChars(l_wip_status_text(i)), null_space)
10439 || FIELD_SEPERATOR || l_supply_firm_type(i)
10440 || FIELD_SEPERATOR || l_res_firm_type(i)
10441 || FIELD_SEPERATOR || l_status(i)
10442 || FIELD_SEPERATOR || l_applied(i)
10443 || FIELD_SEPERATOR || l_res_req_type(i)
10444 || FIELD_SEPERATOR || l_transaction_id(i)
10445 || FIELD_SEPERATOR || l_res_transaction_id(i)
10446 || FIELD_SEPERATOR || escapeSplChars(l_bar_text(i))
10447 || FIELD_SEPERATOR || null_space
10448 || FIELD_SEPERATOR || nvl(to_char(l_cepst(i), format_mask), null_space)
10449 || FIELD_SEPERATOR || nvl(to_char(l_cepct(i), format_mask), null_space)
10450 || FIELD_SEPERATOR || nvl(to_char(l_ulpst(i), format_mask), null_space)
10451 || FIELD_SEPERATOR || nvl(to_char(l_ulpct(i), format_mask), null_space)
10452 || FIELD_SEPERATOR || nvl(to_char(l_uepst(i), format_mask), null_space)
10453 || FIELD_SEPERATOR || nvl(to_char(l_uepct(i), format_mask), null_space)
10454 || FIELD_SEPERATOR || nvl(to_char(l_eacd(i), format_mask), null_space)
10455 || FIELD_SEPERATOR || nvl(to_char(l_sr_instance_id(i)), null_space)
10456 || FIELD_SEPERATOR || nvl(to_char(l_organization_id(i)), null_space)
10457 || FIELD_SEPERATOR || nvl(to_char(l_dept_id(i)), null_space)
10458 || FIELD_SEPERATOR || nvl(to_char(l_res_id(i)), null_space)
10459 || FIELD_SEPERATOR || nvl(to_char(l_inventory_item_id(i)), null_space)
10460 || FIELD_SEPERATOR || nvl(to_char(l_res_seq(i)), null_space)
10461 || FIELD_SEPERATOR || nvl(escapeSplChars(l_order_number(i)), null_space)
10462 || FIELD_SEPERATOR || nvl(escapeSplChars(to_char(l_op_seq(i))), null_space)
10463 || FIELD_SEPERATOR || nvl(escapeSplChars(l_res_desc(i)), null_space)
10464 || FIELD_SEPERATOR || nvl(escapeSplChars(l_item_name(i)), null_space)
10465 || FIELD_SEPERATOR || nvl(escapeSplChars(l_assy_item_desc(i)), null_space)
10466 || FIELD_SEPERATOR || nvl(to_char(fnd_number.number_to_canonical(l_schedule_qty(i))), null_space)
10467 || FIELD_SEPERATOR || null_space
10468 || FIELD_SEPERATOR || null_space
10469 || FIELD_SEPERATOR || null_space
10470 || FIELD_SEPERATOR || null_space
10471 || FIELD_SEPERATOR || null_space
10472 || FIELD_SEPERATOR || null_space
10473 || FIELD_SEPERATOR || null_space
10474 || FIELD_SEPERATOR || null_space
10475 || FIELD_SEPERATOR || null_space
10476 || FIELD_SEPERATOR || null_space
10477 || FIELD_SEPERATOR || null_space
10478 || FIELD_SEPERATOR || nvl(to_char(l_alternate_num(i)), null_space)
10479 || FIELD_SEPERATOR || nvl(to_char(l_actual_start_date(i), format_mask), null_space)
10480 || FIELD_SEPERATOR || nvl(to_char(l_critical_flag(i)), null_space);
10481 end if;
10482
10483 addToOutStream(l_one_record, l_out_data_index, p_out_data);
10484
10485 put_line(l_row_index(i) || FIELD_SEPERATOR || l_item_prompt(i));
10486 end loop; -- }
10487 put_line('getResult out ');
10488
10489 return SYS_YES;
10490 End getResult;
10491
10492
10493 END MSC_GANTT_UTILS;