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